summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt/Eclipse SWT
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Path.java700
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Pattern.java205
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Transform.java387
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Color.java266
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Cursor.java645
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Device.java794
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/DeviceData.java23
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Font.java427
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/FontData.java447
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/FontMetrics.java133
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/GC.java3674
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/GCData.java79
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Image.java1013
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Path.java813
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Pattern.java298
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Region.java597
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/TextLayout.java2204
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Transform.java380
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Button.java865
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Canvas.java403
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Caret.java566
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ColorDialog.java166
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Combo.java1902
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Composite.java1082
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Control.java4366
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/DateTime.java949
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Decorations.java687
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/DirectoryDialog.java237
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java4176
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java561
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FontDialog.java359
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Group.java209
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/IME.java441
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Label.java395
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Link.java735
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/List.java1573
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Menu.java1173
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java976
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MessageBox.java287
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ProgressBar.java269
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Sash.java427
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Scale.java387
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ScrollBar.java795
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Scrollable.java427
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Shell.java2037
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Slider.java523
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Spinner.java1298
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TabFolder.java702
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TabItem.java370
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Table.java3553
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TableColumn.java616
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TableItem.java1081
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Text.java2524
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolBar.java515
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolItem.java1378
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolTip.java669
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tracker.java1051
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TrayItem.java479
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tree.java3735
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TreeColumn.java634
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TreeItem.java1435
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Widget.java2112
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Color.java266
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Cursor.java467
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java748
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/DeviceData.java23
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Font.java370
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/FontData.java447
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/FontMetrics.java133
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java3918
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GCData.java63
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java1192
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Path.java759
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Pattern.java217
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Region.java839
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/TextLayout.java1980
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Transform.java477
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java846
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Canvas.java512
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Caret.java505
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ColorDialog.java165
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Combo.java1617
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java1005
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java4114
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/DateTime.java591
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Decorations.java682
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/DirectoryDialog.java182
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java4900
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/FileDialog.java461
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/FontDialog.java223
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Group.java241
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/IME.java510
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java521
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Link.java532
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/List.java1429
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Menu.java926
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MenuItem.java850
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MessageBox.java331
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ProgressBar.java330
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Sash.java478
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Scale.java362
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ScrollBar.java685
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Scrollable.java335
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java1829
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Slider.java527
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Spinner.java1064
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TabFolder.java652
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TabItem.java373
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java3087
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TableColumn.java677
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TableItem.java1031
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java1983
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolBar.java536
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java992
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tracker.java1113
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TrayItem.java537
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java2974
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TreeColumn.java675
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TreeItem.java1456
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java1767
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/library/callback.c753
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/library/callback.h64
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/library/make_common.mak14
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.c28
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.h150
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java3952
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTError.java146
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTException.java139
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmEvent.java38
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmListener.java38
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlAdapter.java47
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlEvent.java40
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlListener.java48
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeEvent.java39
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeListener.java39
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DragDetectEvent.java38
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DragDetectListener.java40
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandAdapter.java48
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandEvent.java40
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandListener.java49
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusAdapter.java46
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusEvent.java39
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusListener.java48
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpEvent.java39
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpListener.java40
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyAdapter.java46
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyEvent.java107
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyListener.java47
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuAdapter.java46
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuDetectEvent.java75
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuDetectListener.java42
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuEvent.java39
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuListener.java46
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyEvent.java39
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyListener.java38
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseAdapter.java59
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseEvent.java102
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseListener.java57
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseMoveListener.java38
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackAdapter.java60
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackListener.java59
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseWheelListener.java41
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintEvent.java102
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintListener.java39
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionAdapter.java46
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionEvent.java142
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionListener.java62
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellAdapter.java73
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellEvent.java58
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellListener.java67
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseEvent.java137
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseListener.java46
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeAdapter.java46
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeEvent.java39
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeListener.java47
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TypedEvent.java104
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyEvent.java68
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyListener.java45
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/package.html23
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Drawable.java63
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/GlyphMetrics.java114
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java3673
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataLoader.java29
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoader.java323
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderEvent.java87
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderListener.java45
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/LineAttributes.java122
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PaletteData.java214
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PathData.java33
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java108
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/RGB.java226
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java346
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java100
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/TextStyle.java395
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/package.html18
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/Callback.java243
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java129
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/GIFFileFormat.java612
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGAppn.java28
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGArithmeticConditioningTable.java23
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGComment.java27
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGDecoder.java6355
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGEndOfImage.java31
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFileFormat.java1882
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFixedSizeSegment.java44
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFrameHeader.java214
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGHuffmanTable.java264
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGQuantizationTable.java165
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGRestartInterval.java31
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGScanHeader.java123
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGSegment.java58
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGStartOfImage.java35
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGVariableSizeSegment.java38
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LEDataInputStream.java186
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LEDataOutputStream.java58
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LZWCodec.java477
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LZWNode.java17
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/OS2BMPFileFormat.java294
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PNGFileFormat.java574
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunk.java381
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunkReader.java72
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDecodingDataStream.java134
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDeflater.java618
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngEncoder.java364
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngFileReadState.java25
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTable.java125
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTables.java160
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIdatChunk.java62
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIendChunk.java55
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIhdrChunk.java408
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngInputStream.java61
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngLzBlockReader.java172
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngPlteChunk.java123
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngTrnsChunk.java154
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFDirectory.java625
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFFileFormat.java79
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFModifiedHuffmanCodec.java217
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFRandomFileAccess.java96
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinBMPFileFormat.java690
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java325
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/package.html19
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/package.html21
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillData.java45
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java238
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormAttachment.java316
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormData.java344
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormLayout.java385
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridData.java566
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridLayout.java745
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowData.java125
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowLayout.java506
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/package.html15
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/package.html16
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Dialog.java272
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Event.java223
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/EventTable.java154
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Item.java186
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Layout.java104
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Listener.java52
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Monitor.java87
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/RunnableLock.java39
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Synchronizer.java200
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Tray.java149
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/TypedListener.java257
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/package.html16
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/version.txt1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/CloneableCompatibility.java31
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/Compatibility.java444
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SWTEventListener.java27
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SWTEventObject.java61
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SerializableCompatibility.java32
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/CloneableCompatibility.java27
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/Compatibility.java362
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTEventListener.java29
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTEventObject.java40
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages.properties75
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ar._properties25
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_cs._properties29
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_da._properties25
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_de._properties65
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_el._properties25
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_es._properties57
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_fi._properties25
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_fr._properties65
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_hu._properties25
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_it._properties63
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_iw._properties21
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ja._properties65
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ko._properties65
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_mn._properties2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_nl._properties25
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_no._properties25
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_pl._properties42
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_pt._properties64
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_pt_BR._properties25
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ro._properties5
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ru._properties30
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_sv._properties25
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_tr._properties25
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_uk._properties65
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_zh._properties65
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_zh_TW._properties64
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SerializableCompatibility.java30
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/bidi/org/eclipse/swt/internal/BidiUtil.java114
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/coolbar/org/eclipse/swt/widgets/CoolBar.java1193
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/coolbar/org/eclipse/swt/widgets/CoolItem.java657
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/datetime/org/eclipse/swt/widgets/DateTime.java1180
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/expand/org/eclipse/swt/widgets/ExpandBar.java575
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/expand/org/eclipse/swt/widgets/ExpandItem.java391
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/graphics/org/eclipse/swt/graphics/Path.java463
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/graphics/org/eclipse/swt/graphics/Pattern.java192
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/graphics/org/eclipse/swt/graphics/Transform.java357
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/ime/org/eclipse/swt/widgets/IME.java268
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/tabfolder/org/eclipse/swt/widgets/TabFolder.java1230
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/tabfolder/org/eclipse/swt/widgets/TabItem.java452
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/textlayout/org/eclipse/swt/graphics/TextLayout.java1759
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/tooltip/org/eclipse/swt/widgets/ToolTip.java644
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/tray/org/eclipse/swt/widgets/TrayItem.java350
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Table.java4166
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TableColumn.java762
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TableItem.java2032
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Tree.java4295
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeColumn.java738
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeItem.java2959
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Color.java289
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Cursor.java527
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java902
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/DeviceData.java36
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java288
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontData.java446
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java133
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java4036
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GCData.java64
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java1165
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Region.java594
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java2201
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/Converter.java72
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java836
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java407
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java515
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java182
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java2241
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java1438
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java4588
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java1103
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java752
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java339
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java4212
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java728
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java631
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java731
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java243
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java292
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/IME.java443
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ImageList.java154
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java589
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java740
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java1594
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java981
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java883
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MessageBox.java238
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ProgressBar.java302
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java441
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java377
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java768
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java384
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java2195
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java614
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java1203
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java733
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java390
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java3543
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java702
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java1324
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java2152
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java551
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java1091
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java818
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java996
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java591
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java3385
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java697
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java1769
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java1617
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java339
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Cursor.java441
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java1021
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/DeviceData.java30
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Font.java536
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java669
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontMetrics.java123
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java4568
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GCData.java67
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java1429
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java561
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/TextLayout.java1935
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java405
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java859
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java329
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java480
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java466
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java1726
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java1565
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java3761
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java797
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java347
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java3830
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java650
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java1176
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java348
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java643
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Link.java660
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java1567
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java913
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java984
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java436
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java422
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java446
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java385
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java728
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java363
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java2093
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java553
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Spinner.java1039
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java1739
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java517
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java1164
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java983
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java1260
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Color.java238
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Cursor.java464
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Device.java627
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/DeviceData.java23
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Font.java265
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/FontData.java456
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/FontMetrics.java174
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/GC.java3655
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/GCData.java46
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Image.java1046
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Region.java638
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/internal/Converter.java67
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Button.java662
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Canvas.java310
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Caret.java515
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ColorDialog.java151
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Combo.java1400
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Composite.java1165
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Control.java3286
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Decorations.java634
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/DirectoryDialog.java177
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java2737
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/FileDialog.java369
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/FontDialog.java211
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Group.java223
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Label.java464
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Link.java680
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/List.java1259
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Menu.java844
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MenuItem.java921
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MessageBox.java221
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ProgressBar.java292
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Sash.java422
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Scale.java378
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ScrollBar.java725
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Scrollable.java245
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Shell.java1426
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Slider.java559
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Spinner.java824
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/TabFolder.java756
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/TabItem.java344
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Text.java1615
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolBar.java490
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolItem.java967
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Tracker.java1057
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Widget.java1274
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/WidgetTable.java113
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Color.java325
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java460
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java972
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/DeviceData.java23
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Font.java258
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontData.java669
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontMetrics.java183
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java4979
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GCData.java64
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java2129
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Path.java602
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Pattern.java250
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Region.java597
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java3328
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Transform.java369
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/BidiUtil.java642
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ImageList.java459
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java1388
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Canvas.java490
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java600
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ColorDialog.java281
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java2489
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java1760
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java4894
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolBar.java1195
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolItem.java717
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DateTime.java1048
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java1798
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DirectoryDialog.java310
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java4653
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandBar.java824
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandItem.java489
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FileDialog.java618
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java325
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Group.java569
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/IME.java566
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java686
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Link.java1010
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/List.java1716
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java1566
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java1174
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MessageBox.java265
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java458
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Sash.java421
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scale.java561
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ScrollBar.java952
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scrollable.java495
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java2518
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Slider.java788
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Spinner.java1460
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabFolder.java1010
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabItem.java372
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java6966
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableColumn.java893
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java1235
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java2543
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java1514
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java1006
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolTip.java555
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tracker.java1188
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TrayItem.java537
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java7809
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java758
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java1819
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java2517
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Color.java275
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Cursor.java466
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Device.java650
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/DeviceData.java23
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Font.java291
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/FontData.java540
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/FontMetrics.java133
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/GC.java3112
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/GCData.java59
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Image.java1127
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Path.java695
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Pattern.java217
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Region.java712
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/TextLayout.java1877
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Transform.java408
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Button.java652
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Canvas.java313
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Caret.java530
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ColorDialog.java158
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Combo.java1424
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Composite.java1157
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Control.java3621
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/CoolBar.java709
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/CoolItem.java665
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Decorations.java895
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/DirectoryDialog.java171
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Display.java3018
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ExpandBar.java459
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ExpandItem.java397
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/FileDialog.java374
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/FontDialog.java243
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Group.java240
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Label.java320
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Link.java461
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/List.java1186
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Menu.java916
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/MenuItem.java739
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/MessageBox.java197
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ProgressBar.java262
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Sash.java305
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Scale.java361
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ScrollBar.java693
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Scrollable.java313
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Shell.java1536
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Slider.java492
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Spinner.java991
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TabFolder.java731
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TabItem.java406
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Table.java2417
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TableColumn.java644
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TableItem.java1208
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Text.java1510
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ToolBar.java471
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ToolItem.java849
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Tracker.java892
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TrayItem.java447
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Tree.java2406
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TreeColumn.java613
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TreeItem.java1638
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Widget.java1478
601 files changed, 0 insertions, 460777 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Path.java b/bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Path.java
deleted file mode 100644
index f7d2e8a6c7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Path.java
+++ /dev/null
@@ -1,700 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.cairo.*;
-
-/**
- * Instances of this class represent paths through the two-dimensional
- * coordinate system. Paths do not have to be continuous, and can be
- * described using lines, rectangles, arcs, cubic or quadratic bezier curves,
- * glyphs, or other paths.
- * <p>
- * Application code must explicitly invoke the <code>Path.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#path">Path, Pattern snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Path extends Resource {
-
- /**
- * the OS resource for the Path
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
-
- boolean moved, closed = true;
-
-/**
- * Constructs a new empty Path.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the path
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Path (Device device) {
- super(device);
- this.device.checkCairo();
- int /*long*/ surface = Cairo.cairo_image_surface_create(Cairo.CAIRO_FORMAT_ARGB32, 1, 1);
- if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- handle = Cairo.cairo_create(surface);
- Cairo.cairo_surface_destroy(surface);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new Path that is a copy of <code>path</code>. If
- * <code>flatness</code> is less than or equal to zero, an unflatten
- * copy of the path is created. Otherwise, it specifies the maximum
- * error between the path and its flatten copy. Smaller numbers give
- * better approximation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the path
- * @param path the path to make a copy
- * @param flatness the flatness value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the path is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the path has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- * @since 3.4
- */
-public Path (Device device, Path path, float flatness) {
- super(device);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int /*long*/ surface = Cairo.cairo_image_surface_create(Cairo.CAIRO_FORMAT_ARGB32, 1, 1);
- if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- handle = Cairo.cairo_create(surface);
- Cairo.cairo_surface_destroy(surface);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ copy;
- flatness = Math.max(0, flatness);
- if (flatness == 0) {
- copy = Cairo.cairo_copy_path(path.handle);
- } else {
- double tolerance = Cairo.cairo_get_tolerance(path.handle);
- Cairo.cairo_set_tolerance(path.handle, flatness);
- copy = Cairo.cairo_copy_path_flat(path.handle);
- Cairo.cairo_set_tolerance(path.handle, tolerance);
- }
- if (copy == 0) {
- Cairo.cairo_destroy(handle);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- Cairo.cairo_append_path(handle, copy);
- Cairo.cairo_path_destroy(copy);
- init();
-}
-
-/**
- * Constructs a new Path with the specifed PathData.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the path
- * @param data the data for the path
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the data is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- * @since 3.4
- */
-public Path (Device device, PathData data) {
- this(device);
- if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(data);
-}
-
-/**
- * Adds to the receiver a circular or elliptical arc that lies within
- * the specified rectangular area.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc
- * @param y the y coordinate of the upper-left corner of the arc
- * @param width the width of the arc
- * @param height the height of the arc
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addArc(float x, float y, float width, float height, float startAngle, float arcAngle) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- moved = true;
- if (width == height) {
- float angle = -startAngle * (float)Compatibility.PI / 180;
- if (closed) Cairo.cairo_move_to(handle, (x + width / 2f) + width / 2f * Math.cos(angle), (y + height / 2f) + height / 2f * Math.sin(angle));
- if (arcAngle >= 0) {
- Cairo.cairo_arc_negative(handle, x + width / 2f, y + height / 2f, width / 2f, angle, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- } else {
- Cairo.cairo_arc(handle, x + width / 2f, y + height / 2f, width / 2f, angle, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- }
- } else {
- Cairo.cairo_save(handle);
- Cairo.cairo_translate(handle, x + width / 2f, y + height / 2f);
- Cairo.cairo_scale(handle, width / 2f, height / 2f);
- float angle = -startAngle * (float)Compatibility.PI / 180;
- if (closed) Cairo.cairo_move_to(handle, Math.cos(angle), Math.sin(angle));
- if (arcAngle >= 0) {
- Cairo.cairo_arc_negative(handle, 0, 0, 1, angle, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- } else {
- Cairo.cairo_arc(handle, 0, 0, 1, angle, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- }
- Cairo.cairo_restore(handle);
- }
- closed = false;
- if (Math.abs(arcAngle) >= 360) close();
-}
-
-/**
- * Adds to the receiver the path described by the parameter.
- *
- * @param path the path to add to the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addPath(Path path) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- moved = false;
- int /*long*/ copy = Cairo.cairo_copy_path(path.handle);
- if (copy == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Cairo.cairo_append_path(handle, copy);
- Cairo.cairo_path_destroy(copy);
- closed = path.closed;
-}
-
-/**
- * Adds to the receiver the rectangle specified by x, y, width and height.
- *
- * @param x the x coordinate of the rectangle to add
- * @param y the y coordinate of the rectangle to add
- * @param width the width of the rectangle to add
- * @param height the height of the rectangle to add
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addRectangle(float x, float y, float width, float height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- moved = false;
- Cairo.cairo_rectangle(handle, x, y, width, height);
- closed = true;
-}
-
-/**
- * Adds to the receiver the pattern of glyphs generated by drawing
- * the given string using the given font starting at the point (x, y).
- *
- * @param string the text to use
- * @param x the x coordinate of the starting point
- * @param y the y coordinate of the starting point
- * @param font the font to use
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the font is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addString(String string, float x, float y, Font font) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (font == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- moved = false;
- GC.addCairoString(handle, string, x, y, font);
- closed = true;
-}
-
-/**
- * Closes the current sub path by adding to the receiver a line
- * from the current point of the path back to the starting point
- * of the sub path.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void close() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Cairo.cairo_close_path(handle);
- moved = false;
- closed = true;
-}
-
-/**
- * Returns <code>true</code> if the specified point is contained by
- * the receiver and false otherwise.
- * <p>
- * If outline is <code>true</code>, the point (x, y) checked for containment in
- * the receiver's outline. If outline is <code>false</code>, the point is
- * checked to see if it is contained within the bounds of the (closed) area
- * covered by the receiver.
- *
- * @param x the x coordinate of the point to test for containment
- * @param y the y coordinate of the point to test for containment
- * @param gc the GC to use when testing for containment
- * @param outline controls whether to check the outline or contained area of the path
- * @return <code>true</code> if the path contains the point and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains(float x, float y, GC gc, boolean outline) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- //TODO - see Windows
- gc.initCairo();
- gc.checkGC(GC.LINE_CAP | GC.LINE_JOIN | GC.LINE_STYLE | GC.LINE_WIDTH);
- boolean result = false;
- int /*long*/ cairo = gc.data.cairo;
- int /*long*/ copy = Cairo.cairo_copy_path(handle);
- if (copy == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Cairo.cairo_append_path(cairo, copy);
- Cairo.cairo_path_destroy(copy);
- if (outline) {
- result = Cairo.cairo_in_stroke(cairo, x, y) != 0;
- } else {
- result = Cairo.cairo_in_fill(cairo, x, y) != 0;
- }
- Cairo.cairo_new_path(cairo);
- return result;
-}
-
-/**
- * Adds to the receiver a cubic bezier curve based on the parameters.
- *
- * @param cx1 the x coordinate of the first control point of the spline
- * @param cy1 the y coordinate of the first control of the spline
- * @param cx2 the x coordinate of the second control of the spline
- * @param cy2 the y coordinate of the second control of the spline
- * @param x the x coordinate of the end point of the spline
- * @param y the y coordinate of the end point of the spline
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (!moved) {
- double[] currentX = new double[1], currentY = new double[1];
- Cairo.cairo_get_current_point(handle, currentX, currentY);
- Cairo.cairo_move_to(handle, currentX[0], currentY[0]);
- moved = true;
- }
- Cairo.cairo_curve_to(handle, cx1, cy1, cx2, cy2, x, y);
- closed = false;
-}
-
-/**
- * Replaces the first four elements in the parameter with values that
- * describe the smallest rectangle that will completely contain the
- * receiver (i.e. the bounding box).
- *
- * @param bounds the array to hold the result
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the bounding box</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getBounds(float[] bounds) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (bounds.length < 4) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int /*long*/ copy = Cairo.cairo_copy_path(handle);
- if (copy == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- cairo_path_t path = new cairo_path_t();
- Cairo.memmove(path, copy, cairo_path_t.sizeof);
- double minX = 0, minY = 0, maxX = 0, maxY = 0;
- if (path.num_data > 0) {
- minX = minY = Double.POSITIVE_INFINITY;
- maxX = maxY = Double.NEGATIVE_INFINITY;
- int i = 0;
- double[] points = new double[6];
- cairo_path_data_t data = new cairo_path_data_t();
- while (i < path.num_data) {
- int /*long*/ offset = path.data + i * cairo_path_data_t.sizeof;
- Cairo.memmove(data, offset, cairo_path_data_t.sizeof);
- switch (data.type) {
- case Cairo.CAIRO_PATH_MOVE_TO:
- Cairo.memmove(points, offset + cairo_path_data_t.sizeof, cairo_path_data_t.sizeof);
- minX = Math.min(minX, points[0]);
- minY = Math.min(minY, points[1]);
- maxX = Math.max(maxX, points[0]);
- maxY = Math.max(maxY, points[1]);
- break;
- case Cairo.CAIRO_PATH_LINE_TO:
- Cairo.memmove(points, offset + cairo_path_data_t.sizeof, cairo_path_data_t.sizeof);
- minX = Math.min(minX, points[0]);
- minY = Math.min(minY, points[1]);
- maxX = Math.max(maxX, points[0]);
- maxY = Math.max(maxY, points[1]);
- break;
- case Cairo.CAIRO_PATH_CURVE_TO:
- Cairo.memmove(points, offset + cairo_path_data_t.sizeof, cairo_path_data_t.sizeof * 3);
- minX = Math.min(minX, points[0]);
- minY = Math.min(minY, points[1]);
- maxX = Math.max(maxX, points[0]);
- maxY = Math.max(maxY, points[1]);
- minX = Math.min(minX, points[2]);
- minY = Math.min(minY, points[3]);
- maxX = Math.max(maxX, points[2]);
- maxY = Math.max(maxY, points[3]);
- minX = Math.min(minX, points[4]);
- minY = Math.min(minY, points[5]);
- maxX = Math.max(maxX, points[4]);
- maxY = Math.max(maxY, points[5]);
- break;
- case Cairo.CAIRO_PATH_CLOSE_PATH: break;
- }
- i += data.length;
- }
- }
- bounds[0] = (float)minX;
- bounds[1] = (float)minY;
- bounds[2] = (float)(maxX - minX);
- bounds[3] = (float)(maxY - minY);
- Cairo.cairo_path_destroy(copy);
-}
-
-/**
- * Replaces the first two elements in the parameter with values that
- * describe the current point of the path.
- *
- * @param point the array to hold the result
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the end point</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getCurrentPoint(float[] point) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (point == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (point.length < 2) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- double[] x = new double[1], y = new double[1];
- Cairo.cairo_get_current_point(handle, x, y);
- point[0] = (float)x[0];
- point[1] = (float)y[0];
-}
-
-/**
- * Returns a device independent representation of the receiver.
- *
- * @return the PathData for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see PathData
- */
-public PathData getPathData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int /*long*/ copy = Cairo.cairo_copy_path(handle);
- if (copy == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- cairo_path_t path = new cairo_path_t();
- Cairo.memmove(path, copy, cairo_path_t.sizeof);
- byte[] types = new byte[path.num_data];
- float[] pts = new float[path.num_data * 6];
- int typeIndex = 0, ptsIndex = 0;
- if (path.num_data > 0) {
- int i = 0;
- double[] points = new double[6];
- cairo_path_data_t data = new cairo_path_data_t();
- while (i < path.num_data) {
- int /*long*/ offset = path.data + i * cairo_path_data_t.sizeof;
- Cairo.memmove(data, offset, cairo_path_data_t.sizeof);
- switch (data.type) {
- case Cairo.CAIRO_PATH_MOVE_TO:
- types[typeIndex++] = SWT.PATH_MOVE_TO;
- Cairo.memmove(points, offset + cairo_path_data_t.sizeof, cairo_path_data_t.sizeof);
- pts[ptsIndex++] = (float)points[0];
- pts[ptsIndex++] = (float)points[1];
- break;
- case Cairo.CAIRO_PATH_LINE_TO:
- types[typeIndex++] = SWT.PATH_LINE_TO;
- Cairo.memmove(points, offset + cairo_path_data_t.sizeof, cairo_path_data_t.sizeof);
- pts[ptsIndex++] = (float)points[0];
- pts[ptsIndex++] = (float)points[1];
- break;
- case Cairo.CAIRO_PATH_CURVE_TO:
- types[typeIndex++] = SWT.PATH_CUBIC_TO;
- Cairo.memmove(points, offset + cairo_path_data_t.sizeof, cairo_path_data_t.sizeof * 3);
- pts[ptsIndex++] = (float)points[0];
- pts[ptsIndex++] = (float)points[1];
- pts[ptsIndex++] = (float)points[2];
- pts[ptsIndex++] = (float)points[3];
- pts[ptsIndex++] = (float)points[4];
- pts[ptsIndex++] = (float)points[5];
- break;
- case Cairo.CAIRO_PATH_CLOSE_PATH:
- types[typeIndex++] = SWT.PATH_CLOSE;
- break;
- }
- i += data.length;
- }
- }
- if (typeIndex != types.length) {
- byte[] newTypes = new byte[typeIndex];
- System.arraycopy(types, 0, newTypes, 0, typeIndex);
- types = newTypes;
- }
- if (ptsIndex != pts.length) {
- float[] newPts = new float[ptsIndex];
- System.arraycopy(pts, 0, newPts, 0, ptsIndex);
- pts = newPts;
- }
- Cairo.cairo_path_destroy(copy);
- PathData result = new PathData();
- result.types = types;
- result.points = pts;
- return result;
-}
-
-/**
- * Adds to the receiver a line from the current point to
- * the point specified by (x, y).
- *
- * @param x the x coordinate of the end of the line to add
- * @param y the y coordinate of the end of the line to add
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void lineTo(float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (!moved) {
- double[] currentX = new double[1], currentY = new double[1];
- Cairo.cairo_get_current_point(handle, currentX, currentY);
- Cairo.cairo_move_to(handle, currentX[0], currentY[0]);
- moved = true;
- }
- Cairo.cairo_line_to(handle, x, y);
- closed = false;
-}
-
-/**
- * Sets the current point of the receiver to the point
- * specified by (x, y). Note that this starts a new
- * sub path.
- *
- * @param x the x coordinate of the new end point
- * @param y the y coordinate of the new end point
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void moveTo(float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- /*
- * Bug in Cairo. If cairo_move_to() is not called at the
- * begining of a subpath, the first cairo_line_to() or
- * cairo_curve_to() segment do not output anything. The fix
- * is to detect that the app did not call cairo_move_to()
- * before those calls and call it explicitly.
- */
- moved = true;
- Cairo.cairo_move_to(handle, x, y);
- closed = true;
-}
-
-/**
- * Adds to the receiver a quadratic curve based on the parameters.
- *
- * @param cx the x coordinate of the control point of the spline
- * @param cy the y coordinate of the control point of the spline
- * @param x the x coordinate of the end point of the spline
- * @param y the y coordinate of the end point of the spline
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void quadTo(float cx, float cy, float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- double[] currentX = new double[1], currentY = new double[1];
- Cairo.cairo_get_current_point(handle, currentX, currentY);
- if (!moved) {
- Cairo.cairo_move_to(handle, currentX[0], currentY[0]);
- moved = true;
- }
- float x0 = (float)currentX[0];
- float y0 = (float)currentY[0];
- float cx1 = x0 + 2 * (cx - x0) / 3;
- float cy1 = y0 + 2 * (cy - y0) / 3;
- float cx2 = cx1 + (x - x0) / 3;
- float cy2 = cy1 + (y - y0) / 3;
- Cairo.cairo_curve_to(handle, cx1, cy1, cx2, cy2, x, y);
- closed = false;
-}
-
-void destroy() {
- Cairo.cairo_destroy(handle);
- handle = 0;
-}
-
-void init(PathData data) {
- byte[] types = data.types;
- float[] points = data.points;
- for (int i = 0, j = 0; i < types.length; i++) {
- switch (types[i]) {
- case SWT.PATH_MOVE_TO:
- moveTo(points[j++], points[j++]);
- break;
- case SWT.PATH_LINE_TO:
- lineTo(points[j++], points[j++]);
- break;
- case SWT.PATH_CUBIC_TO:
- cubicTo(points[j++], points[j++], points[j++], points[j++], points[j++], points[j++]);
- break;
- case SWT.PATH_QUAD_TO:
- quadTo(points[j++], points[j++], points[j++], points[j++]);
- break;
- case SWT.PATH_CLOSE:
- close();
- break;
- default:
- dispose();
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
-}
-
-/**
- * Returns <code>true</code> if the Path has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Path.
- * When a Path has been disposed, it is an error to
- * invoke any other method using the Path.
- *
- * @return <code>true</code> when the Path is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString() {
- if (isDisposed()) return "Path {*DISPOSED*}";
- return "Path {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Pattern.java b/bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Pattern.java
deleted file mode 100644
index 0711132953..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Pattern.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.cairo.*;
-
-/**
- * Instances of this class represent patterns to use while drawing. Patterns
- * can be specified either as bitmaps or gradients.
- * <p>
- * Application code must explicitly invoke the <code>Pattern.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#path">Path, Pattern snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Pattern extends Resource {
-
- /**
- * the OS resource for the Pattern
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
-
- int /*long*/ surface;
-
-/**
- * Constructs a new Pattern given an image. Drawing with the resulting
- * pattern will cause the image to be tiled over the resulting area.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the pattern
- * @param image the image that the pattern will draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device, or the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Pattern(Device device, Image image) {
- super(device);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.device.checkCairo();
- image.createSurface();
- handle = Cairo.cairo_pattern_create_for_surface(image.surface);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Cairo.cairo_pattern_set_extend(handle, Cairo.CAIRO_EXTEND_REPEAT);
- surface = image.surface;
- init();
-}
-
-/**
- * Constructs a new Pattern that represents a linear, two color
- * gradient. Drawing with the pattern will cause the resulting area to be
- * tiled with the gradient specified by the arguments.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the pattern
- * @param x1 the x coordinate of the starting corner of the gradient
- * @param y1 the y coordinate of the starting corner of the gradient
- * @param x2 the x coordinate of the ending corner of the gradient
- * @param y2 the y coordinate of the ending corner of the gradient
- * @param color1 the starting color of the gradient
- * @param color2 the ending color of the gradient
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device,
- * or if either color1 or color2 is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either color1 or color2 has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Pattern(Device device, float x1, float y1, float x2, float y2, Color color1, Color color2) {
- this(device, x1, y1, x2, y2, color1, 0xFF, color2, 0xFF);
-}
-/**
- * Constructs a new Pattern that represents a linear, two color
- * gradient. Drawing with the pattern will cause the resulting area to be
- * tiled with the gradient specified by the arguments.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the pattern
- * @param x1 the x coordinate of the starting corner of the gradient
- * @param y1 the y coordinate of the starting corner of the gradient
- * @param x2 the x coordinate of the ending corner of the gradient
- * @param y2 the y coordinate of the ending corner of the gradient
- * @param color1 the starting color of the gradient
- * @param alpha1 the starting alpha value of the gradient
- * @param color2 the ending color of the gradient
- * @param alpha2 the ending alpha value of the gradient
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device,
- * or if either color1 or color2 is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either color1 or color2 has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- *
- * @since 3.2
- */
-public Pattern(Device device, float x1, float y1, float x2, float y2, Color color1, int alpha1, Color color2, int alpha2) {
- super(device);
- if (color1 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color1.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (color2 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color2.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.device.checkCairo();
- handle = Cairo.cairo_pattern_create_linear(x1, y1, x2, y2);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- GC.setCairoPatternColor(handle, 0, color1, alpha1);
- GC.setCairoPatternColor(handle, 1, color2, alpha2);
- Cairo.cairo_pattern_set_extend(handle, Cairo.CAIRO_EXTEND_REPEAT);
- init();
-}
-
-void destroy() {
- Cairo.cairo_pattern_destroy(handle);
- handle = surface = 0;
-}
-
-/**
- * Returns <code>true</code> if the Pattern has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Pattern.
- * When a Pattern has been disposed, it is an error to
- * invoke any other method using the Pattern.
- *
- * @return <code>true</code> when the Pattern is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString() {
- if (isDisposed()) return "Pattern {*DISPOSED*}";
- return "Pattern {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Transform.java b/bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Transform.java
deleted file mode 100644
index b755f16571..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Transform.java
+++ /dev/null
@@ -1,387 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.cairo.*;
-
-/**
- * Instances of this class represent transformation matrices for
- * points expressed as (x, y) pairs of floating point numbers.
- * <p>
- * Application code must explicitly invoke the <code>Transform.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Transform extends Resource {
- /**
- * the OS resource for the Transform
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public double[] handle;
-
-/**
- * Constructs a new identity Transform.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform (Device device) {
- this(device, 1, 0, 0, 1, 0, 0);
-}
-
-/**
- * Constructs a new Transform given an array of elements that represent the
- * matrix that describes the transformation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- * @param elements an array of floats that describe the transformation matrix
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device, or the elements array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the elements array is too small to hold the matrix values</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform(Device device, float[] elements) {
- this (device, checkTransform(elements)[0], elements[1], elements[2], elements[3], elements[4], elements[5]);
-}
-
-/**
- * Constructs a new Transform given all of the elements that represent the
- * matrix that describes the transformation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- * @param m11 the first element of the first row of the matrix
- * @param m12 the second element of the first row of the matrix
- * @param m21 the first element of the second row of the matrix
- * @param m22 the second element of the second row of the matrix
- * @param dx the third element of the first row of the matrix
- * @param dy the third element of the second row of the matrix
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform (Device device, float m11, float m12, float m21, float m22, float dx, float dy) {
- super(device);
- this.device.checkCairo();
- handle = new double[6];
- if (handle == null) SWT.error(SWT.ERROR_NO_HANDLES);
- Cairo.cairo_matrix_init(handle, m11, m12, m21, m22, dx, dy);
- init();
-}
-
-static float[] checkTransform(float[] elements) {
- if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return elements;
-}
-
-void destroy() {
- handle = null;
-}
-
-/**
- * Fills the parameter with the values of the transformation matrix
- * that the receiver represents, in the order {m11, m12, m21, m22, dx, dy}.
- *
- * @param elements array to hold the matrix values
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the matrix values</li>
- * </ul>
- */
-public void getElements(float[] elements) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- elements[0] = (float)handle[0];
- elements[1] = (float)handle[1];
- elements[2] = (float)handle[2];
- elements[3] = (float)handle[3];
- elements[4] = (float)handle[4];
- elements[5] = (float)handle[5];
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes the
- * identity matrix.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public void identity() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Cairo.cairo_matrix_init(handle, 1, 0, 0, 1, 0, 0);
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes
- * the mathematical inverse of the matrix it previously represented.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_CANNOT_INVERT_MATRIX - if the matrix is not invertible</li>
- * </ul>
- */
-public void invert() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (Cairo.cairo_matrix_invert(handle) != 0) {
- SWT.error(SWT.ERROR_CANNOT_INVERT_MATRIX);
- }
-}
-
-/**
- * Returns <code>true</code> if the Transform has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Transform.
- * When a Transform has been disposed, it is an error to
- * invoke any other method using the Transform.
- *
- * @return <code>true</code> when the Transform is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == null;
-}
-
-/**
- * Returns <code>true</code> if the Transform represents the identity matrix
- * and false otherwise.
- *
- * @return <code>true</code> if the receiver is an identity Transform, and <code>false</code> otherwise
- */
-public boolean isIdentity() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float[] m = new float[6];
- getElements(m);
- return m[0] == 1 && m[1] == 0 && m[2] == 0 && m[3] == 1 && m[4] == 0 && m[5] == 0;
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes the
- * the result of multiplying the matrix it previously represented by the
- * argument.
- *
- * @param matrix the matrix to multiply the receiver by
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- */
-public void multiply(Transform matrix) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (matrix == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (matrix.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Cairo.cairo_matrix_multiply(handle, matrix.handle, handle);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation rotated by the specified angle.
- * The angle is specified in degrees and for the identity transform 0 degrees
- * is at the 3 o'clock position. A positive value indicates a clockwise rotation
- * while a negative value indicates a counter-clockwise rotation.
- *
- * @param angle the angle to rotate the transformation by
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void rotate(float angle) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Cairo.cairo_matrix_rotate(handle, angle * (float)Compatibility.PI / 180);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation scaled by (scaleX, scaleY).
- *
- * @param scaleX the amount to scale in the X direction
- * @param scaleY the amount to scale in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void scale(float scaleX, float scaleY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Cairo.cairo_matrix_scale(handle, scaleX, scaleY);
-}
-
-/**
- * Modifies the receiver to represent a new transformation given all of
- * the elements that represent the matrix that describes that transformation.
- *
- * @param m11 the first element of the first row of the matrix
- * @param m12 the second element of the first row of the matrix
- * @param m21 the first element of the second row of the matrix
- * @param m22 the second element of the second row of the matrix
- * @param dx the third element of the first row of the matrix
- * @param dy the third element of the second row of the matrix
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setElements(float m11, float m12, float m21, float m22, float dx, float dy) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Cairo.cairo_matrix_init(handle, m11, m12, m21, m22, dx, dy);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation sheared by (shearX, shearY).
- *
- * @param shearX the shear factor in the X direction
- * @param shearY the shear factor in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public void shear(float shearX, float shearY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- double[] matrix = {1, shearX, shearY, 1, 0, 0};
- Cairo.cairo_matrix_multiply(handle, matrix, handle);
-}
-
-/**
- * Given an array containing points described by alternating x and y values,
- * modify that array such that each point has been replaced with the result of
- * applying the transformation represented by the receiver to that point.
- *
- * @param pointArray an array of alternating x and y values to be transformed
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void transform(float[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- double[] dx = new double[1], dy = new double[1];
- int length = pointArray.length / 2;
- for (int i = 0, j = 0; i < length; i++, j += 2) {
- dx[0] = pointArray[j];
- dy[0] = pointArray[j + 1];
- Cairo.cairo_matrix_transform_point(handle, dx, dy);
- pointArray[j] = (float)dx[0];
- pointArray[j + 1] = (float)dy[0];
- }
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation translated by (offsetX, offsetY).
- *
- * @param offsetX the distance to translate in the X direction
- * @param offsetY the distance to translate in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void translate(float offsetX, float offsetY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Cairo.cairo_matrix_translate(handle, offsetX, offsetY);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString() {
- if (isDisposed()) return "Transform {*DISPOSED*}";
- float[] elements = new float[6];
- getElements(elements);
- return "Transform {" + elements [0] + "," + elements [1] + "," +elements [2] + "," +elements [3] + "," +elements [4] + "," +elements [5] + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Color.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Color.java
deleted file mode 100644
index ee344c9666..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Color.java
+++ /dev/null
@@ -1,266 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage the operating system resources that
- * implement SWT's RGB color model. To create a color you can either
- * specify the individual color components as integers in the range
- * 0 to 255 or provide an instance of an <code>RGB</code>.
- * <p>
- * Application code must explicitly invoke the <code>Color.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see RGB
- * @see Device#getSystemColor
- * @see <a href="http://www.eclipse.org/swt/snippets/#color">Color and RGB snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Color extends Resource {
- /**
- * the handle to the OS color resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public float[] handle;
-
-Color(Device device) {
- super(device);
-}
-
-/**
- * Constructs a new instance of this class given a device and the
- * desired red, green and blue values expressed as ints in the range
- * 0 to 255 (where 0 is black and 255 is full brightness). On limited
- * color devices, the color instance created by this call may not have
- * the same RGB values as the ones specified by the arguments. The
- * RGB values on the returned instance will be the color values of
- * the operating system color.
- * <p>
- * You must dispose the color when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param red the amount of red in the color
- * @param green the amount of green in the color
- * @param blue the amount of blue in the color
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255</li>
- * </ul>
- *
- * @see #dispose
- */
-public Color(Device device, int red, int green, int blue) {
- super(device);
- init(red, green, blue);
- init();
-}
-
-/**
- * Constructs a new instance of this class given a device and an
- * <code>RGB</code> describing the desired red, green and blue values.
- * On limited color devices, the color instance created by this call
- * may not have the same RGB values as the ones specified by the
- * argument. The RGB values on the returned instance will be the color
- * values of the operating system color.
- * <p>
- * You must dispose the color when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param rgb the RGB values of the desired color
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the rgb argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue components of the argument are not between 0 and 255</li>
- * </ul>
- *
- * @see #dispose
- */
-public Color(Device device, RGB rgb) {
- super(device);
- if (rgb == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(rgb.red, rgb.green, rgb.blue);
- init();
-}
-
-void destroy() {
- handle = null;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals(Object object) {
- if (object == this) return true;
- if (!(object instanceof Color)) return false;
- Color color = (Color)object;
- float[] rgbColor = color.handle;
- if (handle == rgbColor) return true;
- return device == color.device &&
- (int)(handle[0] * 255) == (int)(rgbColor[0] * 255) &&
- (int)(handle[1] * 255) == (int)(rgbColor[1] * 255) &&
- (int)(handle[2] * 255) == (int)(rgbColor[2] * 255);
-}
-
-/**
- * Returns the amount of blue in the color, from 0 to 255.
- *
- * @return the blue component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getBlue() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (int)(handle[2] * 255);
-}
-
-/**
- * Returns the amount of green in the color, from 0 to 255.
- *
- * @return the green component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getGreen() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (int)(handle[1] * 255);
-}
-
-/**
- * Returns the amount of red in the color, from 0 to 255.
- *
- * @return the red component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getRed() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (int)(handle[0] * 255);
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode() {
- if (isDisposed()) return 0;
- return (int)(handle[0] * 255) ^ (int)(handle[1] * 255) ^ (int)(handle[2] * 255);
-}
-
-/**
- * Returns an <code>RGB</code> representing the receiver.
- *
- * @return the RGB for the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public RGB getRGB () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return new RGB(getRed(), getGreen(), getBlue());
-}
-
-/**
- * Invokes platform specific functionality to allocate a new color.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Color</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param handle the handle for the color
- *
- * @private
- */
-public static Color carbon_new(Device device, float[] rgbColor) {
- Color color = new Color(device);
- color.handle = rgbColor;
- return color;
-}
-
-void init( int red, int green, int blue) {
- if ((red > 255) || (red < 0) ||
- (green > 255) || (green < 0) ||
- (blue > 255) || (blue < 0)) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- float[] rgbColor = new float[4];
- rgbColor[0] = red / 255f;
- rgbColor[1] = green / 255f;
- rgbColor[2] = blue / 255f;
- rgbColor[3] = 1;
- handle = rgbColor;
-}
-
-/**
- * Returns <code>true</code> if the color has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the color.
- * When a color has been disposed, it is an error to
- * invoke any other method using the color.
- *
- * @return <code>true</code> when the color is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == null;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Color {*DISPOSED*}";
- return "Color {" + getRed() + ", " + getGreen() + ", " + getBlue() + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Cursor.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Cursor.java
deleted file mode 100644
index 1652463be0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Cursor.java
+++ /dev/null
@@ -1,645 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.carbon.*;
-import org.eclipse.swt.internal.cocoa.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage operating system resources that
- * specify the appearance of the on-screen pointer. To create a
- * cursor you specify the device and either a simple cursor style
- * describing one of the standard operating system provided cursors
- * or the image and mask data for the desired appearance.
- * <p>
- * Application code must explicitly invoke the <code>Cursor.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>
- * CURSOR_ARROW, CURSOR_WAIT, CURSOR_CROSS, CURSOR_APPSTARTING, CURSOR_HELP,
- * CURSOR_SIZEALL, CURSOR_SIZENESW, CURSOR_SIZENS, CURSOR_SIZENWSE, CURSOR_SIZEWE,
- * CURSOR_SIZEN, CURSOR_SIZES, CURSOR_SIZEE, CURSOR_SIZEW, CURSOR_SIZENE, CURSOR_SIZESE,
- * CURSOR_SIZESW, CURSOR_SIZENW, CURSOR_UPARROW, CURSOR_IBEAM, CURSOR_NO, CURSOR_HAND
- * </dd>
- * </dl>
- * <p>
- * Note: Only one of the above styles may be specified.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#cursor">Cursor snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class Cursor extends Resource {
-
- /**
- * the handle to the OS cursor resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
- static boolean initialized;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Cursor(Device device) {
- super(device);
-}
-
-/**
- * Constructs a new cursor given a device and a style
- * constant describing the desired cursor appearance.
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param style the style of cursor to allocate
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - when an unknown style is specified</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- *
- * @see SWT#CURSOR_ARROW
- * @see SWT#CURSOR_WAIT
- * @see SWT#CURSOR_CROSS
- * @see SWT#CURSOR_APPSTARTING
- * @see SWT#CURSOR_HELP
- * @see SWT#CURSOR_SIZEALL
- * @see SWT#CURSOR_SIZENESW
- * @see SWT#CURSOR_SIZENS
- * @see SWT#CURSOR_SIZENWSE
- * @see SWT#CURSOR_SIZEWE
- * @see SWT#CURSOR_SIZEN
- * @see SWT#CURSOR_SIZES
- * @see SWT#CURSOR_SIZEE
- * @see SWT#CURSOR_SIZEW
- * @see SWT#CURSOR_SIZENE
- * @see SWT#CURSOR_SIZESE
- * @see SWT#CURSOR_SIZESW
- * @see SWT#CURSOR_SIZENW
- * @see SWT#CURSOR_UPARROW
- * @see SWT#CURSOR_IBEAM
- * @see SWT#CURSOR_NO
- * @see SWT#CURSOR_HAND
- */
-public Cursor(Device device, int style) {
- super(device);
- switch (style) {
- case SWT.CURSOR_HAND: handle = OS.kThemePointingHandCursor; break;
- case SWT.CURSOR_ARROW: handle = OS.kThemeArrowCursor; break;
- case SWT.CURSOR_WAIT: handle = OS.kThemeSpinningCursor; break;
- case SWT.CURSOR_CROSS: handle = OS.kThemeCrossCursor; break;
- case SWT.CURSOR_APPSTARTING: handle = OS.kThemeArrowCursor; break;
- case SWT.CURSOR_HELP: handle = OS.kThemeCrossCursor; break;
- case SWT.CURSOR_SIZEALL: handle = OS.kThemeCrossCursor; break;
- case SWT.CURSOR_SIZENESW: handle = OS.kThemeCrossCursor; break;
- case SWT.CURSOR_SIZENS: handle = OS.kThemeResizeUpDownCursor; break;
- case SWT.CURSOR_SIZENWSE: handle = OS.kThemeCrossCursor; break;
- case SWT.CURSOR_SIZEWE: handle = OS.kThemeResizeLeftRightCursor; break;
- case SWT.CURSOR_SIZEN: handle = OS.kThemeResizeUpCursor; break;
- case SWT.CURSOR_SIZES: handle = OS.kThemeResizeDownCursor; break;
- case SWT.CURSOR_SIZEE: handle = OS.kThemeResizeRightCursor; break;
- case SWT.CURSOR_SIZEW: handle = OS.kThemeResizeLeftCursor; break;
- case SWT.CURSOR_SIZENE: handle = OS.kThemeCrossCursor; break;
- case SWT.CURSOR_SIZESE: handle = OS.kThemeCrossCursor; break;
- case SWT.CURSOR_SIZESW: handle = OS.kThemeCrossCursor; break;
- case SWT.CURSOR_SIZENW: handle = OS.kThemeCrossCursor; break;
- case SWT.CURSOR_UPARROW: handle = OS.kThemeCrossCursor; break;
- case SWT.CURSOR_IBEAM: handle = OS.kThemeIBeamCursor; break;
- case SWT.CURSOR_NO: handle = OS.kThemeNotAllowedCursor; break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- init();
-}
-
-/**
- * Constructs a new cursor given a device, image and mask
- * data describing the desired cursor appearance, and the x
- * and y coordinates of the <em>hotspot</em> (that is, the point
- * within the area covered by the cursor which is considered
- * to be where the on-screen pointer is "pointing").
- * <p>
- * The mask data is allowed to be null, but in this case the source
- * must be an ImageData representing an icon that specifies both
- * color data and mask data.
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param source the color data for the cursor
- * @param mask the mask data for the cursor (or null)
- * @param hotspotX the x coordinate of the cursor's hotspot
- * @param hotspotY the y coordinate of the cursor's hotspot
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the source is null</li>
- * <li>ERROR_NULL_ARGUMENT - if the mask is null and the source does not have a mask</li>
- * <li>ERROR_INVALID_ARGUMENT - if the source and the mask are not the same
- * size, or if the hotspot is outside the bounds of the image</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- */
-public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (mask == null) {
- if (source.getTransparencyType() != SWT.TRANSPARENCY_MASK) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- mask = source.getTransparencyMask();
- }
- /* Check the bounds. Mask must be the same size as source */
- if (mask.width != source.width || mask.height != source.height) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- /* Check the hotspots */
- if (hotspotX >= source.width || hotspotX < 0 ||
- hotspotY >= source.height || hotspotY < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (OS.VERSION >= 0x1040) {
- byte[] data = new byte[source.width * source.height * 4];
- for (int y = 0; y < source.height; y++) {
- int offset = y * source.width * 4;
- for (int x = 0; x < source.width; x++) {
- int pixel = source.getPixel(x, y);
- int maskPixel = mask.getPixel(x, y);
- if (pixel == 0 && maskPixel == 0) {
- // BLACK
- data[offset] = (byte)0xFF;
- } else if (pixel == 0 && maskPixel == 1) {
- // WHITE - cursor color
- data[offset] = data[offset + 1] = data[offset + 2] = data[offset + 3] = (byte)0xFF;
- } else if (pixel == 1 && maskPixel == 0) {
- // SCREEN
- } else {
- /*
- * Feature in the Macintosh. It is not possible to have
- * the reverse screen case using NSCursor.
- * Reverse screen will be the same as screen.
- */
- // REVERSE SCREEN -> SCREEN
- }
- offset += 4;
- }
- }
- createNSCursor(hotspotX, hotspotY, data, source.width, source.height);
- return;
- }
- /* Convert depth to 1 */
- mask = ImageData.convertMask(mask);
- source = ImageData.convertMask(source);
-
- /* Find the first non transparent pixel if cursor bigger than 16x16. */
- int width = source.width;
- int height = source.height;
- int minX = 0, minY = 0;
- if (width > 16 || height > 16) {
- minX = width;
- minY = height;
- int maxX = 0, maxY = 0;
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- if (!(source.getPixel(x, y) == 1 && mask.getPixel(x, y) == 0)) {
- minX = Math.min(minX, x);
- minY = Math.min(minY, y);
- maxX = Math.max(maxX, x);
- maxY = Math.max(maxY, y);
- }
- }
- }
- width = maxX - minX + 1;
- height = maxY - minY + 1;
-
- /* Stretch cursor if still bigger than 16x16. */
- if (width > 16 || height > 16) {
- int newWidth = Math.min(width, 16);
- int newHeight = Math.min(height, 16);
- ImageData newSource =
- new ImageData(newWidth, newHeight, source.depth, source.palette,
- 1, null, 0, null, null, -1, -1, source.type,
- source.x, source.y, source.disposalMethod, source.delayTime);
- ImageData newMask = new ImageData(newWidth, newHeight, mask.depth,
- mask.palette, 1, null, 0, null, null, -1, -1, mask.type,
- mask.x, mask.y, mask.disposalMethod, mask.delayTime);
- ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), minX, minY, width, height, null, null, null,
- ImageData.ALPHA_OPAQUE, null, 0, minX, minY,
- newSource.data, newSource.depth, newSource.bytesPerLine, newSource.getByteOrder(), 0, 0, newWidth, newHeight, null, null, null,
- false, false);
- ImageData.blit(ImageData.BLIT_SRC,
- mask.data, mask.depth, mask.bytesPerLine, mask.getByteOrder(), minX, minY, width, height, null, null, null,
- ImageData.ALPHA_OPAQUE, null, 0, minX, minY,
- newMask.data, newMask.depth, newMask.bytesPerLine, newMask.getByteOrder(), 0, 0, newWidth, newHeight, null, null, null,
- false, false);
- width = newWidth;
- height = newHeight;
- minX = minY = 0;
- source = newSource;
- mask = newMask;
- }
- }
-
- /* Create the cursor */
- org.eclipse.swt.internal.carbon.Cursor cursor = new org.eclipse.swt.internal.carbon.Cursor();
- byte[] srcData = cursor.data;
- byte[] maskData = cursor.mask;
- for (int y = 0; y < height; y++) {
- short d = 0, m = 0;
- for (int x = 0; x < width; x++) {
- int bit = 1 << (width - 1 - x);
- if (source.getPixel(minX + x, minY + y) == 0) {
- m |= bit;
- if (mask.getPixel(minX + x, minY + y) == 0) d |= bit;
- } else if (mask.getPixel(minX + x, minY + y) != 0) {
- d |= bit;
- }
- }
- srcData[y * 2] = (byte)(d >> 8);
- srcData[y * 2 + 1] = (byte)(d & 0xFF);
- maskData[y * 2] = (byte)(m >> 8);
- maskData[y * 2 + 1] = (byte)(m & 0xFF);
- }
- cursor.hotSpot_h = (short)Math.max(0, Math.min(15, hotspotX - minX));
- cursor.hotSpot_v = (short)Math.max(0, Math.min(15, hotspotY - minY));
- handle = OS.NewPtr(org.eclipse.swt.internal.carbon.Cursor.sizeof);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.memmove(handle, cursor, org.eclipse.swt.internal.carbon.Cursor.sizeof);
- init();
-}
-
-void createNSCursor(int hotspotX, int hotspotY, byte[] buffer, int width, int height) {
- if (!initialized) {
- initialized = true;
- int window = Cocoa.objc_msgSend(Cocoa.objc_msgSend(Cocoa.C_NSWindow, Cocoa.S_alloc), Cocoa.S_init);
- Cocoa.objc_msgSend(window, Cocoa.S_release);
- }
- int nsImage = Cocoa.objc_msgSend(Cocoa.C_NSImage, Cocoa.S_alloc);
- if (nsImage == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int nsImageRep = Cocoa.objc_msgSend(Cocoa.C_NSBitmapImageRep, Cocoa.S_alloc);
- if (nsImageRep == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- this.handle = Cocoa.objc_msgSend(Cocoa.C_NSCursor, Cocoa.S_alloc);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- NSSize size = new NSSize();
- size.width = width;
- size.height = height;
- nsImage = Cocoa.objc_msgSend(nsImage, Cocoa.S_initWithSize, size);
- nsImageRep = Cocoa.objc_msgSend(nsImageRep, Cocoa.S_initWithBitmapDataPlanes, null, width, height,
- 8, 4, 1, 0, Cocoa.NSDeviceRGBColorSpace(),
- Cocoa.NSAlphaFirstBitmapFormat | Cocoa.NSAlphaNonpremultipliedBitmapFormat, width * 4, 32);
- int bitmapData = Cocoa.objc_msgSend(nsImageRep, Cocoa.S_bitmapData);
- OS.memmove(bitmapData, buffer, buffer.length);
- Cocoa.objc_msgSend(nsImage, Cocoa.S_addRepresentation, nsImageRep);
- NSPoint point = new NSPoint();
- point.x = hotspotX;
- point.y = hotspotY;
- handle = Cocoa.objc_msgSend(handle, Cocoa.S_initWithImage_hotSpot, nsImage, point);
- Cocoa.objc_msgSend(nsImage, Cocoa.S_release);
- Cocoa.objc_msgSend(nsImageRep, Cocoa.S_release);
-}
-
-/**
- * Constructs a new cursor given a device, image data describing
- * the desired cursor appearance, and the x and y coordinates of
- * the <em>hotspot</em> (that is, the point within the area
- * covered by the cursor which is considered to be where the
- * on-screen pointer is "pointing").
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param source the image data for the cursor
- * @param hotspotX the x coordinate of the cursor's hotspot
- * @param hotspotY the y coordinate of the cursor's hotspot
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the hotspot is outside the bounds of the
- * image</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- *
- * @since 3.0
- */
-public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (hotspotX >= source.width || hotspotX < 0 ||
- hotspotY >= source.height || hotspotY < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- if (OS.VERSION >= 0x1040) {
- byte[] data = new byte[source.width * source.height * 4];
- PaletteData palette = source.palette;
- if (palette.isDirect) {
- ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, palette.redMask, palette.greenMask, palette.blueMask,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- data, 32, source.width * 4, ImageData.MSB_FIRST, 0, 0, source.width, source.height, 0xFF0000, 0xFF00, 0xFF,
- false, false);
- } else {
- RGB[] rgbs = palette.getRGBs();
- int length = rgbs.length;
- byte[] srcReds = new byte[length];
- byte[] srcGreens = new byte[length];
- byte[] srcBlues = new byte[length];
- for (int i = 0; i < rgbs.length; i++) {
- RGB rgb = rgbs[i];
- if (rgb == null) continue;
- srcReds[i] = (byte)rgb.red;
- srcGreens[i] = (byte)rgb.green;
- srcBlues[i] = (byte)rgb.blue;
- }
- ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, srcReds, srcGreens, srcBlues,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- data, 32, source.width * 4, ImageData.MSB_FIRST, 0, 0, source.width, source.height, 0xFF0000, 0xFF00, 0xFF,
- false, false);
- }
- if (source.maskData != null || source.transparentPixel != -1) {
- ImageData mask = source.getTransparencyMask();
- byte[] maskData = mask.data;
- int maskBpl = mask.bytesPerLine;
- int offset = 0, maskOffset = 0;
- for (int y = 0; y<source.height; y++) {
- for (int x = 0; x<source.width; x++) {
- data[offset] = ((maskData[maskOffset + (x >> 3)]) & (1 << (7 - (x & 0x7)))) != 0 ? (byte)0xff : 0;
- offset += 4;
- }
- maskOffset += maskBpl;
- }
- } else if (source.alpha != -1) {
- byte alpha = (byte)source.alpha;
- for (int i=0; i<data.length; i+=4) {
- data[i] = alpha;
- }
- } else if (source.alphaData != null) {
- byte[] alphaData = source.alphaData;
- for (int i=0; i<data.length; i+=4) {
- data[i] = alphaData[i/4];
- }
- }
- createNSCursor(hotspotX, hotspotY, data, source.width, source.height);
- } else {
-
- ImageData mask = source.getTransparencyMask();
-
- /* Ensure depth is equal to 1 */
- if (source.depth > 1) {
- /* Create a destination image with no data */
- ImageData newSource = new ImageData(
- source.width, source.height, 1, ImageData.bwPalette(),
- 1, null, 0, null, null, -1, -1, 0, 0, 0, 0, 0);
-
- byte[] newReds = new byte[]{0, (byte)255}, newGreens = newReds, newBlues = newReds;
-
- /* Convert the source to a black and white image of depth 1 */
- PaletteData palette = source.palette;
- if (palette.isDirect) {
- ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, palette.redMask, palette.greenMask, palette.blueMask,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- newSource.data, newSource.depth, newSource.bytesPerLine, newSource.getByteOrder(), 0, 0, newSource.width, newSource.height, newReds, newGreens, newBlues,
- false, false);
- } else {
- RGB[] rgbs = palette.getRGBs();
- int length = rgbs.length;
- byte[] srcReds = new byte[length];
- byte[] srcGreens = new byte[length];
- byte[] srcBlues = new byte[length];
- for (int i = 0; i < rgbs.length; i++) {
- RGB rgb = rgbs[i];
- if (rgb == null) continue;
- srcReds[i] = (byte)rgb.red;
- srcGreens[i] = (byte)rgb.green;
- srcBlues[i] = (byte)rgb.blue;
- }
- ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, srcReds, srcGreens, srcBlues,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- newSource.data, newSource.depth, newSource.bytesPerLine, newSource.getByteOrder(), 0, 0, newSource.width, newSource.height, newReds, newGreens, newBlues,
- false, false);
- }
- source = newSource;
- }
-
- /* Find the first non transparent pixel if cursor bigger than 16x16. */
- int width = source.width;
- int height = source.height;
- int minX = 0, minY = 0;
- if (width > 16 || height > 16) {
- minX = width;
- minY = height;
- int maxX = 0, maxY = 0;
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- if (!(source.getPixel(x, y) == 1 && mask.getPixel(x, y) == 0)) {
- minX = Math.min(minX, x);
- minY = Math.min(minY, y);
- maxX = Math.max(maxX, x);
- maxY = Math.max(maxY, y);
- }
- }
- }
- width = maxX - minX + 1;
- height = maxY - minY + 1;
-
- /* Stretch cursor if still bigger than 16x16. */
- if (width > 16 || height > 16) {
- int newWidth = Math.min(width, 16);
- int newHeight = Math.min(height, 16);
- ImageData newSource =
- new ImageData(newWidth, newHeight, source.depth, source.palette,
- 1, null, 0, null, null, -1, -1, source.type,
- source.x, source.y, source.disposalMethod, source.delayTime);
- ImageData newMask = new ImageData(newWidth, newHeight, mask.depth,
- mask.palette, 1, null, 0, null, null, -1, -1, mask.type,
- mask.x, mask.y, mask.disposalMethod, mask.delayTime);
- ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), minX, minY, width, height, null, null, null,
- ImageData.ALPHA_OPAQUE, null, 0, minX, minY,
- newSource.data, newSource.depth, newSource.bytesPerLine, newSource.getByteOrder(), 0, 0, newWidth, newHeight, null, null, null,
- false, false);
- ImageData.blit(ImageData.BLIT_SRC,
- mask.data, mask.depth, mask.bytesPerLine, mask.getByteOrder(), minX, minY, width, height, null, null, null,
- ImageData.ALPHA_OPAQUE, null, 0, minX, minY,
- newMask.data, newMask.depth, newMask.bytesPerLine, newMask.getByteOrder(), 0, 0, newWidth, newHeight, null, null, null,
- false, false);
- width = newWidth;
- height = newHeight;
- minX = minY = 0;
- source = newSource;
- mask = newMask;
- }
- }
-
- /* Create the cursor */
- org.eclipse.swt.internal.carbon.Cursor cursor = new org.eclipse.swt.internal.carbon.Cursor();
- byte[] srcData = cursor.data;
- byte[] maskData = cursor.mask;
- for (int y= 0; y < height; y++) {
- short d = 0, m = 0;
- for (int x = 0; x < width; x++) {
- int bit = 1 << (width - 1 - x);
- if (source.getPixel(x + minX, y + minY) == 0) {
- if (mask.getPixel(x + minX, y + minY) != 0) {
- d |= bit;
- m |= bit;
- }
- } else {
- if (mask.getPixel(x + minX, y + minY) != 0) m |= bit;
- }
- }
- srcData[y * 2] = (byte)(d >> 8);
- srcData[y * 2 + 1] = (byte)(d & 0xFF);
- maskData[y * 2] = (byte)(m >> 8);
- maskData[y * 2 + 1] = (byte)(m & 0xFF);
- }
- cursor.hotSpot_h = (short)Math.max(0, Math.min(15, hotspotX - minX));
- cursor.hotSpot_v = (short)Math.max(0, Math.min(15, hotspotY - minY));
- handle = OS.NewPtr(org.eclipse.swt.internal.carbon.Cursor.sizeof);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.memmove(handle, cursor, org.eclipse.swt.internal.carbon.Cursor.sizeof);
- }
- init();
-}
-
-void destroy() {
- switch (handle) {
- case OS.kThemePointingHandCursor:
- case OS.kThemeArrowCursor:
- case OS.kThemeSpinningCursor:
- case OS.kThemeCrossCursor:
- case OS.kThemeWatchCursor:
- case OS.kThemeIBeamCursor:
- case OS.kThemeNotAllowedCursor:
- case OS.kThemeResizeLeftRightCursor:
- case OS.kThemeResizeLeftCursor:
- case OS.kThemeResizeRightCursor:
- case OS.kThemeResizeUpDownCursor:
- case OS.kThemeResizeUpCursor:
- case OS.kThemeResizeDownCursor:
- break;
- default:
- if (OS.VERSION >= 0x1040) {
- Cocoa.objc_msgSend(handle, Cocoa.S_release);
- } else {
- OS.DisposePtr(handle);
- }
- }
- handle = -1;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Cursor)) return false;
- Cursor cursor = (Cursor) object;
- return device == cursor.device && handle == cursor.handle;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return handle;
-}
-
-/**
- * Returns <code>true</code> if the cursor has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the cursor.
- * When a cursor has been disposed, it is an error to
- * invoke any other method using the cursor.
- *
- * @return <code>true</code> when the cursor is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == -1;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Cursor {*DISPOSED*}";
- return "Cursor {" + handle + "}";
-}
-
-/**
- * Invokes platform specific functionality to allocate a new cursor.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Cursor</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param handle the handle for the cursor
- *
- * @private
- */
-public static Cursor carbon_new(Device device, int handle) {
- Cursor cursor = new Cursor(device);
- cursor.handle = handle;
- return cursor;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Device.java
deleted file mode 100644
index 270a1ca841..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Device.java
+++ /dev/null
@@ -1,794 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.internal.carbon.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.*;
-
-/**
- * This class is the abstract superclass of all device objects,
- * such as the Display device and the Printer device. Devices
- * can have a graphics context (GC) created for them, and they
- * can be drawn on by sending messages to the associated GC.
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class Device implements Drawable {
-
- /* Debugging */
- public static boolean DEBUG;
- boolean debug = DEBUG;
- boolean tracking = DEBUG;
- Error [] errors;
- Object [] objects;
- Object trackingLock;
-
- /* Disposed flag */
- boolean disposed, warnings;
-
- int colorspace;
-
- /*
- * The following colors are listed in the Windows
- * Programmer's Reference as the colors in the default
- * palette.
- */
- Color COLOR_BLACK, COLOR_DARK_RED, COLOR_DARK_GREEN, COLOR_DARK_YELLOW, COLOR_DARK_BLUE;
- Color COLOR_DARK_MAGENTA, COLOR_DARK_CYAN, COLOR_GRAY, COLOR_DARK_GRAY, COLOR_RED;
- Color COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE;
-
- /* System Font */
- Font systemFont;
-
- /* Device DPI */
- Point dpi;
-
- /* Callbacks */
- Callback drawPatternCallback, axialShadingCallback, releaseCallback;
- int drawPatternProc, axialShadingProc, releaseProc;
-
- /*
- * TEMPORARY CODE. When a graphics object is
- * created and the device parameter is null,
- * the current Display is used. This presents
- * a problem because SWT graphics does not
- * reference classes in SWT widgets. The correct
- * fix is to remove this feature. Unfortunately,
- * too many application programs rely on this
- * feature.
- */
- protected static Device CurrentDevice;
- protected static Runnable DeviceFinder;
- static {
- try {
- Class.forName ("org.eclipse.swt.widgets.Display");
- } catch (ClassNotFoundException e) {}
- }
-
-/*
-* TEMPORARY CODE.
-*/
-static synchronized Device getDevice () {
- if (DeviceFinder != null) DeviceFinder.run();
- Device device = CurrentDevice;
- CurrentDevice = null;
- return device;
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * You must dispose the device when it is no longer required.
- * </p>
- *
- * @see #create
- * @see #init
- *
- * @since 3.1
- */
-public Device() {
- this(null);
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * You must dispose the device when it is no longer required.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #create
- * @see #init
- * @see DeviceData
- */
-public Device(DeviceData data) {
- synchronized (Device.class) {
- if (data != null) {
- debug = data.debug;
- tracking = data.tracking;
- }
- if (tracking) {
- errors = new Error [128];
- objects = new Object [128];
- trackingLock = new Object ();
- }
- create (data);
- init ();
- }
-}
-
-int axialShadingProc (int ref, int in, int out) {
- Object object = OS.JNIGetObject (ref);
- if (object instanceof Pattern) {
- return ((Pattern) object).axialShadingProc (ref, in, out);
- }
- return 0;
-}
-
-/**
- * Throws an <code>SWTException</code> if the receiver can not
- * be accessed by the caller. This may include both checks on
- * the state of the receiver and more generally on the entire
- * execution context. This method <em>should</em> be called by
- * device implementors to enforce the standard SWT invariants.
- * <p>
- * Currently, it is an error to invoke any method (other than
- * <code>isDisposed()</code> and <code>dispose()</code>) on a
- * device that has had its <code>dispose()</code> method called.
- * </p><p>
- * In future releases of SWT, there may be more or fewer error
- * checks and exceptions may be thrown for different reasons.
- * <p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-protected void checkDevice () {
- if (disposed) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
-}
-
-/**
- * Creates the device in the operating system. If the device
- * does not have a handle, this method may do nothing depending
- * on the device.
- * <p>
- * This method is called before <code>init</code>.
- * </p><p>
- * Subclasses are supposed to reimplement this method and not
- * call the <code>super</code> implementation.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #init
- */
-protected void create (DeviceData data) {
-}
-
-void createPatternCallbacks () {
- if (drawPatternCallback == null) {
- drawPatternCallback = new Callback(this, "drawPatternProc", 2);
- drawPatternProc = drawPatternCallback.getAddress();
- if (drawPatternProc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- }
- if (axialShadingCallback == null) {
- axialShadingCallback = new Callback(this, "axialShadingProc", 3);
- axialShadingProc = axialShadingCallback.getAddress();
- if (axialShadingProc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- }
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the receiver. After this method has been invoked, the receiver
- * will answer <code>true</code> when sent the message
- * <code>isDisposed()</code>.
- *
- * @see #release
- * @see #destroy
- * @see #checkDevice
- */
-public void dispose () {
- synchronized (Device.class) {
- if (isDisposed()) return;
- checkDevice ();
- release ();
- destroy ();
- disposed = true;
- if (tracking) {
- synchronized (trackingLock) {
- objects = null;
- errors = null;
- trackingLock = null;
- }
- }
- }
-}
-
-void dispose_Object (Object object) {
- synchronized (trackingLock) {
- for (int i=0; i<objects.length; i++) {
- if (objects [i] == object) {
- objects [i] = null;
- errors [i] = null;
- return;
- }
- }
- }
-}
-
-/**
- * Destroys the device in the operating system and releases
- * the device's handle. If the device does not have a handle,
- * this method may do nothing depending on the device.
- * <p>
- * This method is called after <code>release</code>.
- * </p><p>
- * Subclasses are supposed to reimplement this method and not
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #dispose
- * @see #release
- */
-protected void destroy () {
-}
-
-int drawPatternProc (int ref, int context) {
- Object object = OS.JNIGetObject (ref);
- if (object instanceof Pattern) {
- return ((Pattern) object).drawPatternProc (ref, context);
- }
- return 0;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location.
- *
- * @return the bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkDevice ();
- int gdevice = OS.GetMainDevice();
- int[] ptr = new int[1];
- OS.memmove(ptr, gdevice, 4);
- GDevice device = new GDevice();
- OS.memmove(device, ptr[0], GDevice.sizeof);
- return new Rectangle(device.left, device.top, device.right - device.left, device.bottom - device.top);
-}
-
-/**
- * Returns a <code>DeviceData</code> based on the receiver.
- * Modifications made to this <code>DeviceData</code> will not
- * affect the receiver.
- *
- * @return a <code>DeviceData</code> containing the device's data and attributes
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see DeviceData
- */
-public DeviceData getDeviceData () {
- checkDevice();
- DeviceData data = new DeviceData ();
- data.debug = debug;
- data.tracking = tracking;
- if (tracking) {
- synchronized (trackingLock) {
- int count = 0, length = objects.length;
- for (int i=0; i<length; i++) {
- if (objects [i] != null) count++;
- }
- int index = 0;
- data.objects = new Object [count];
- data.errors = new Error [count];
- for (int i=0; i<length; i++) {
- if (objects [i] != null) {
- data.objects [index] = objects [i];
- data.errors [index] = errors [i];
- index++;
- }
- }
- }
- } else {
- data.objects = new Object [0];
- data.errors = new Error [0];
- }
- return data;
-}
-
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data.
- *
- * @return the client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getBounds
- */
-public Rectangle getClientArea () {
- checkDevice ();
- int gdevice = OS.GetMainDevice();
- Rect rect = new Rect();
- OS.GetAvailableWindowPositioningBounds(gdevice, rect);
- return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
-}
-
-/**
- * Returns the bit depth of the screen, which is the number of
- * bits it takes to represent the number of unique colors that
- * the screen is currently capable of displaying. This number
- * will typically be one of 1, 8, 15, 16, 24 or 32.
- *
- * @return the depth of the screen
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getDepth () {
- checkDevice ();
- int gdevice = OS.GetMainDevice();
- int[] ptr = new int[1];
- OS.memmove(ptr, gdevice, 4);
- GDevice device = new GDevice();
- OS.memmove(device, ptr[0], GDevice.sizeof);
- return OS.GetPixDepth(device.gdPMap);
-}
-
-/**
- * Returns a point whose x coordinate is the horizontal
- * dots per inch of the display, and whose y coordinate
- * is the vertical dots per inch of the display.
- *
- * @return the horizontal and vertical DPI
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point getDPI () {
- checkDevice ();
- int gdevice = OS.GetMainDevice();
- int[] ptr = new int[1];
- OS.memmove(ptr, gdevice, 4);
- GDevice device = new GDevice();
- OS.memmove(device, ptr[0], GDevice.sizeof);
- OS.memmove(ptr, device.gdPMap, 4);
- PixMap pixmap = new PixMap();
- OS.memmove(pixmap, ptr[0], PixMap.sizeof);
- return new Point (OS.Fix2Long (pixmap.hRes), OS.Fix2Long (pixmap.vRes));
-}
-
-/**
- * Returns <code>FontData</code> objects which describe
- * the fonts that match the given arguments. If the
- * <code>faceName</code> is null, all fonts will be returned.
- *
- * @param faceName the name of the font to look for, or null
- * @param scalable if true only scalable fonts are returned, otherwise only non-scalable fonts are returned.
- * @return the matching font data
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontData[] getFontList (String faceName, boolean scalable) {
- checkDevice ();
- if (!scalable) return new FontData[0];
- int count = 0;
- int[] buffer = new int[1];
- CFRange range = new CFRange ();
- OS.ATSUGetFontIDs(null, 0, buffer);
- FontData[] fds = new FontData[buffer[0]];
- int status = OS.ATSFontIteratorCreate (OS.kATSFontContextLocal, 0, 0, OS.kATSOptionFlagsDefaultScope, buffer);
- int iter = buffer[0];
- while (status == OS.noErr) {
- status = OS.ATSFontIteratorNext(iter, buffer);
- if (status == OS.noErr) {
- int font = buffer[0];
- if (OS.ATSFontGetName(font, 0, buffer) == OS.noErr) {
- range.length = OS.CFStringGetLength(buffer[0]);
- char [] chars = new char[range.length];
- OS.CFStringGetCharacters(buffer[0], range, chars);
- OS.CFRelease(buffer[0]);
- String atsName = new String(chars);
- int platformCode = OS.kFontUnicodePlatform, encoding = OS.kCFStringEncodingUnicode;
- if (OS.ATSUFindFontName(font, OS.kFontFamilyName, platformCode, OS.kFontNoScriptCode, OS.kFontNoLanguageCode, 0, null, buffer, null) != OS.noErr) {
- platformCode = OS.kFontNoPlatformCode;
- encoding = OS.kCFStringEncodingMacRoman;
- if (OS.ATSUFindFontName(font, OS.kFontFamilyName, platformCode, OS.kFontNoScriptCode, OS.kFontNoLanguageCode, 0, null, buffer, null) != OS.noErr) {
- continue;
- }
- }
- byte[] bytes = new byte[buffer[0]];
- OS.ATSUFindFontName(font, OS.kFontFamilyName, platformCode, OS.kFontNoScriptCode, OS.kFontNoLanguageCode, bytes.length, bytes, buffer, null);
- int ptr = OS.CFStringCreateWithBytes(0, bytes, bytes.length, encoding, false);
- if (ptr != 0) {
- range.length = OS.CFStringGetLength(ptr);
- if (range.length != 0) {
- chars = new char[range.length];
- OS.CFStringGetCharacters(ptr, range, chars);
- String name = new String(chars);
- if (!name.startsWith(".")) {
- if (faceName == null || Compatibility.equalsIgnoreCase(faceName, name)) {
- int s = SWT.NORMAL;
- if (atsName.indexOf("Italic") != -1) s |= SWT.ITALIC;
- if (atsName.indexOf("Bold") != -1) s |= SWT.BOLD;
- FontData data = new FontData(name, 0, s);
- data.atsName = atsName;
- if (count == fds.length) {
- FontData[] newFDs = new FontData[count + 4];
- System.arraycopy(fds, 0, newFDs, 0, count);
- fds = newFDs;
- }
- fds[count++] = data;
- }
- }
- }
- OS.CFRelease(ptr);
- }
- }
- }
- }
- if (iter != 0) {
- buffer [0] = iter;
- OS.ATSFontIteratorRelease (buffer);
- }
- if (count == fds.length) return fds;
- FontData[] result = new FontData[count];
- System.arraycopy(fds, 0, result, 0, count);
- return result;
-}
-
-Point getScreenDPI() {
- int gdevice = OS.GetMainDevice();
- int[] ptr = new int[1];
- OS.memmove(ptr, gdevice, 4);
- GDevice device = new GDevice();
- OS.memmove(device, ptr[0], GDevice.sizeof);
- OS.memmove(ptr, device.gdPMap, 4);
- PixMap pixmap = new PixMap();
- OS.memmove(pixmap, ptr[0], PixMap.sizeof);
- return new Point (OS.Fix2Long (pixmap.hRes), OS.Fix2Long (pixmap.vRes));
-}
-
-/**
- * Returns the matching standard color for the given
- * constant, which should be one of the color constants
- * specified in class <code>SWT</code>. Any value other
- * than one of the SWT color constants which is passed
- * in will result in the color black. This color should
- * not be freed because it was allocated by the system,
- * not the application.
- *
- * @param id the color constant
- * @return the matching color
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT
- */
-public Color getSystemColor (int id) {
- checkDevice ();
- switch (id) {
- case SWT.COLOR_BLACK: return COLOR_BLACK;
- case SWT.COLOR_DARK_RED: return COLOR_DARK_RED;
- case SWT.COLOR_DARK_GREEN: return COLOR_DARK_GREEN;
- case SWT.COLOR_DARK_YELLOW: return COLOR_DARK_YELLOW;
- case SWT.COLOR_DARK_BLUE: return COLOR_DARK_BLUE;
- case SWT.COLOR_DARK_MAGENTA: return COLOR_DARK_MAGENTA;
- case SWT.COLOR_DARK_CYAN: return COLOR_DARK_CYAN;
- case SWT.COLOR_GRAY: return COLOR_GRAY;
- case SWT.COLOR_DARK_GRAY: return COLOR_DARK_GRAY;
- case SWT.COLOR_RED: return COLOR_RED;
- case SWT.COLOR_GREEN: return COLOR_GREEN;
- case SWT.COLOR_YELLOW: return COLOR_YELLOW;
- case SWT.COLOR_BLUE: return COLOR_BLUE;
- case SWT.COLOR_MAGENTA: return COLOR_MAGENTA;
- case SWT.COLOR_CYAN: return COLOR_CYAN;
- case SWT.COLOR_WHITE: return COLOR_WHITE;
- }
- return COLOR_BLACK;
-}
-
-/**
- * Returns a reasonable font for applications to use.
- * On some platforms, this will match the "default font"
- * or "system font" if such can be found. This font
- * should not be freed because it was allocated by the
- * system, not the application.
- * <p>
- * Typically, applications which want the default look
- * should simply not set the font on the widgets they
- * create. Widgets are always created with the correct
- * default font for the class of user-interface component
- * they represent.
- * </p>
- *
- * @return a font
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getSystemFont () {
- checkDevice ();
- return systemFont;
-}
-
-/**
- * Returns <code>true</code> if the underlying window system prints out
- * warning messages on the console, and <code>setWarnings</code>
- * had previously been called with <code>true</code>.
- *
- * @return <code>true</code>if warnings are being handled, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean getWarnings () {
- checkDevice ();
- return warnings;
-}
-
-/**
- * Initializes any internal resources needed by the
- * device.
- * <p>
- * This method is called after <code>create</code>.
- * </p><p>
- * If subclasses reimplement this method, they must
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #create
- */
-protected void init () {
- colorspace = OS.CGColorSpaceCreateDeviceRGB();
- if (colorspace == 0) SWT.error(SWT.ERROR_NO_HANDLES);
-
- releaseCallback = new Callback (this, "releaseProc", 3);
- releaseProc = releaseCallback.getAddress ();
- if (releaseProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- /* Create the standard colors */
- COLOR_BLACK = new Color (this, 0,0,0);
- COLOR_DARK_RED = new Color (this, 0x80,0,0);
- COLOR_DARK_GREEN = new Color (this, 0,0x80,0);
- COLOR_DARK_YELLOW = new Color (this, 0x80,0x80,0);
- COLOR_DARK_BLUE = new Color (this, 0,0,0x80);
- COLOR_DARK_MAGENTA = new Color (this, 0x80,0,0x80);
- COLOR_DARK_CYAN = new Color (this, 0,0x80,0x80);
- COLOR_GRAY = new Color (this, 0xC0,0xC0,0xC0);
- COLOR_DARK_GRAY = new Color (this, 0x80,0x80,0x80);
- COLOR_RED = new Color (this, 0xFF,0,0);
- COLOR_GREEN = new Color (this, 0,0xFF,0);
- COLOR_YELLOW = new Color (this, 0xFF,0xFF,0);
- COLOR_BLUE = new Color (this, 0,0,0xFF);
- COLOR_MAGENTA = new Color (this, 0xFF,0,0xFF);
- COLOR_CYAN = new Color (this, 0,0xFF,0xFF);
- COLOR_WHITE = new Color (this, 0xFF,0xFF,0xFF);
-
- /* Initialize the system font slot */
- //TEMPORARY CODE
- boolean smallFonts = System.getProperty("org.eclipse.swt.internal.carbon.smallFonts") != null;
- byte [] family = new byte [256];
- short [] size = new short [1];
- byte [] style = new byte [1];
- int themeFont = smallFonts ? OS.kThemeSmallSystemFont : OS.kThemeSystemFont;
- OS.GetThemeFont ((short) themeFont, (short) OS.smSystemScript, family, size, style);
- short id = OS.FMGetFontFamilyFromName (family);
- int [] font = new int [1];
- OS.FMGetFontFromFontFamilyInstance (id, style [0], font, null);
- Point dpi = this.dpi = getDPI(), screenDPI = getScreenDPI();
- systemFont = Font.carbon_new (this, OS.FMGetATSFontRefFromFont (font [0]), style [0], size [0] * dpi.y / screenDPI.y);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Device</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public abstract int internal_new_GC (GCData data);
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Device</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public abstract void internal_dispose_GC (int handle, GCData data);
-
-/**
- * Returns <code>true</code> if the device has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the device.
- * When a device has been disposed, it is an error to
- * invoke any other method using the device.
- *
- * @return <code>true</code> when the device is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- synchronized (Device.class) {
- return disposed;
- }
-}
-
-/**
- * Loads the font specified by a file. The font will be
- * present in the list of fonts available to the application.
- *
- * @param path the font file path
- * @return whether the font was successfully loaded
- *
- * @exception SWTException <ul>
- * <li>ERROR_NULL_ARGUMENT - if path is null</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Font
- *
- * @since 3.3
- */
-public boolean loadFont (String path) {
- checkDevice();
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- boolean result = false;
- char [] chars = new char [path.length ()];
- path.getChars (0, chars.length, chars, 0);
- int str = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, chars, chars.length);
- if (str != 0) {
- int url = OS.CFURLCreateWithFileSystemPath (OS.kCFAllocatorDefault, str, OS.kCFURLPOSIXPathStyle, false);
- if (url != 0) {
- byte [] fsRef = new byte [80];
- if (OS.CFURLGetFSRef (url, fsRef)) {
- byte [] fsSpec = new byte [70];
- if (OS.FSGetCatalogInfo (fsRef, 0, null, null, fsSpec, null) == OS.noErr) {
- int [] container = new int [1];
- result = OS.ATSFontActivateFromFileSpecification (fsSpec, OS.kATSFontContextLocal, OS.kATSFontFormatUnspecified, 0, OS.kATSOptionFlagsDefault, container) == OS.noErr;
- }
- }
- OS.CFRelease (url);
- }
- OS.CFRelease (str);
- }
- return result;
-}
-
-void new_Object (Object object) {
- synchronized (trackingLock) {
- for (int i=0; i<objects.length; i++) {
- if (objects [i] == null) {
- objects [i] = object;
- errors [i] = new Error ();
- return;
- }
- }
- Object [] newObjects = new Object [objects.length + 128];
- System.arraycopy (objects, 0, newObjects, 0, objects.length);
- newObjects [objects.length] = object;
- objects = newObjects;
- Error [] newErrors = new Error [errors.length + 128];
- System.arraycopy (errors, 0, newErrors, 0, errors.length);
- newErrors [errors.length] = new Error ();
- errors = newErrors;
- }
-}
-
-/**
- * Releases any internal resources back to the operating
- * system and clears all fields except the device handle.
- * <p>
- * When a device is destroyed, resources that were acquired
- * on behalf of the programmer need to be returned to the
- * operating system. For example, if the device allocated a
- * font to be used as the system font, this font would be
- * freed in <code>release</code>. Also,to assist the garbage
- * collector and minimize the amount of memory that is not
- * reclaimed when the programmer keeps a reference to a
- * disposed device, all fields except the handle are zero'd.
- * The handle is needed by <code>destroy</code>.
- * </p>
- * This method is called before <code>destroy</code>.
- * </p><p>
- * If subclasses reimplement this method, they must
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #dispose
- * @see #destroy
- */
-protected void release () {
- if (releaseCallback != null) releaseCallback.dispose ();
- if (drawPatternCallback != null) drawPatternCallback.dispose();
- if (axialShadingCallback != null) axialShadingCallback.dispose();
- releaseCallback = axialShadingCallback = drawPatternCallback = null;
- releaseProc = axialShadingProc = drawPatternProc = 0;
-
- OS.CGColorSpaceRelease(colorspace);
- colorspace = 0;
-
- if (COLOR_BLACK != null) COLOR_BLACK.dispose();
- if (COLOR_DARK_RED != null) COLOR_DARK_RED.dispose();
- if (COLOR_DARK_GREEN != null) COLOR_DARK_GREEN.dispose();
- if (COLOR_DARK_YELLOW != null) COLOR_DARK_YELLOW.dispose();
- if (COLOR_DARK_BLUE != null) COLOR_DARK_BLUE.dispose();
- if (COLOR_DARK_MAGENTA != null) COLOR_DARK_MAGENTA.dispose();
- if (COLOR_DARK_CYAN != null) COLOR_DARK_CYAN.dispose();
- if (COLOR_GRAY != null) COLOR_GRAY.dispose();
- if (COLOR_DARK_GRAY != null) COLOR_DARK_GRAY.dispose();
- if (COLOR_RED != null) COLOR_RED.dispose();
- if (COLOR_GREEN != null) COLOR_GREEN.dispose();
- if (COLOR_YELLOW != null) COLOR_YELLOW.dispose();
- if (COLOR_BLUE != null) COLOR_BLUE.dispose();
- if (COLOR_MAGENTA != null) COLOR_MAGENTA.dispose();
- if (COLOR_CYAN != null) COLOR_CYAN.dispose();
- if (COLOR_WHITE != null) COLOR_WHITE.dispose();
- COLOR_BLACK = COLOR_DARK_RED = COLOR_DARK_GREEN = COLOR_DARK_YELLOW = COLOR_DARK_BLUE =
- COLOR_DARK_MAGENTA = COLOR_DARK_CYAN = COLOR_GRAY = COLOR_DARK_GRAY = COLOR_RED =
- COLOR_GREEN = COLOR_YELLOW = COLOR_BLUE = COLOR_MAGENTA = COLOR_CYAN = COLOR_WHITE = null;
-}
-
-int releaseProc (int info, int data, int size) {
- OS.DisposePtr(data);
- return 0;
-}
-
-/**
- * If the underlying window system supports printing warning messages
- * to the console, setting warnings to <code>false</code> prevents these
- * messages from being printed. If the argument is <code>true</code> then
- * message printing is not blocked.
- *
- * @param warnings <code>true</code>if warnings should be printed, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setWarnings (boolean warnings) {
- checkDevice ();
- this.warnings = warnings;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/DeviceData.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/DeviceData.java
deleted file mode 100644
index 9b95c99718..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/DeviceData.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-public class DeviceData {
- /*
- * Debug fields - may not be honoured
- * on some SWT platforms.
- */
- public boolean debug;
- public boolean tracking;
- public Error [] errors;
- public Object [] objects;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Font.java
deleted file mode 100644
index b9bb11f18d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Font.java
+++ /dev/null
@@ -1,427 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.carbon.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage operating system resources that
- * define how text looks when it is displayed. Fonts may be constructed
- * by providing a device and either name, size and style information
- * or a <code>FontData</code> object which encapsulates this data.
- * <p>
- * Application code must explicitly invoke the <code>Font.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see FontData
- * @see <a href="http://www.eclipse.org/swt/snippets/#font">Font snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Font extends Resource {
-
- /**
- * the handle to the OS font resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
- /**
- * the style to the OS font (a FMFontStyle)
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public short style;
-
- /**
- * the size to the OS font
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public float size;
-
- /**
- * the ATSUI style for the OS font
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int atsuiStyle;
-
-Font(Device device) {
- super(device);
-}
-
-/**
- * Constructs a new font given a device and font data
- * which describes the desired font's appearance.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param fd the FontData that describes the desired font (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the fd argument is null</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li>
- * </ul>
- */
-public Font(Device device, FontData fd) {
- super(device);
- if (fd == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(fd.getName(), fd.getHeightF(), fd.getStyle(), fd.atsName);
- init();
-}
-
-/**
- * Constructs a new font given a device and an array
- * of font data which describes the desired font's
- * appearance.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param fds the array of FontData that describes the desired font (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the fds argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the length of fds is zero</li>
- * <li>ERROR_NULL_ARGUMENT - if any fd in the array is null</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li>
- * </ul>
- *
- * @since 2.1
- */
-public Font(Device device, FontData[] fds) {
- super(device);
- if (fds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (fds.length == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<fds.length; i++) {
- if (fds[i] == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- FontData fd = fds[0];
- init(fd.getName(), fd.getHeightF(), fd.getStyle(), fd.atsName);
- init();
-}
-
-/**
- * Constructs a new font given a device, a font name,
- * the height of the desired font in points, and a font
- * style.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param name the name of the font (must not be null)
- * @param height the font height in points
- * @param style a bit or combination of NORMAL, BOLD, ITALIC
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the name argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given arguments</li>
- * </ul>
- */
-public Font(Device device, String name, int height, int style) {
- super(device);
- init(name, height, style, null);
- init();
-}
-
-/*public*/ Font(Device device, String name, float height, int style) {
- super(device);
- init(name, height, style, null);
- init();
-}
-
-int createStyle () {
- int[] buffer = new int[1];
- OS.ATSUCreateStyle(buffer);
- if (buffer[0] == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int atsuStyle = buffer[0];
-
- boolean synthesize = style != 0;
- int ptr = OS.NewPtr(8 + (synthesize ? 8 : 0));
- OS.memmove(ptr, new int[]{OS.FMGetFontFromATSFontRef(handle)}, 4);
- OS.memmove(ptr + 4, new int[]{OS.X2Fix(size)}, 4);
- int[] tags, sizes, values;
- if (synthesize) {
- OS.memmove(ptr + 8, new byte[]{(style & OS.bold) != 0 ? (byte)1 : 0}, 1);
- OS.memmove(ptr + 9, new byte[]{(style & OS.italic) != 0 ? (byte)1 : 0}, 1);
- tags = new int[]{OS.kATSUFontTag, OS.kATSUSizeTag, OS.kATSUQDBoldfaceTag, OS.kATSUQDItalicTag};
- sizes = new int[]{4, 4, 1, 1};
- values = new int[]{ptr, ptr + 4, ptr + 8, ptr + 9};
- } else {
- tags = new int[]{OS.kATSUFontTag, OS.kATSUSizeTag};
- sizes = new int[]{4, 4};
- values = new int[]{ptr, ptr + 4};
- }
- OS.ATSUSetAttributes(atsuStyle, tags.length, tags, sizes, values);
- OS.DisposePtr(ptr);
-
- short[] types = {
- (short)OS.kLigaturesType,
- (short)OS.kLigaturesType,
- (short)OS.kLigaturesType,
- (short)OS.kLigaturesType,
- (short)OS.kLigaturesType,
- (short)OS.kLigaturesType,
- (short)OS.kLigaturesType,
- (short)OS.kLigaturesType,
- };
- short[] selectors = {
- (short)OS.kRequiredLigaturesOffSelector,
- (short)OS.kCommonLigaturesOffSelector,
- (short)OS.kRareLigaturesOffSelector,
- (short)OS.kLogosOffSelector,
- (short)OS.kRebusPicturesOffSelector,
- (short)OS.kDiphthongLigaturesOffSelector,
- (short)OS.kSquaredLigaturesOffSelector,
- (short)OS.kAbbrevSquaredLigaturesOffSelector,
- (short)OS.kSymbolLigaturesOffSelector,
- };
- OS.ATSUSetFontFeatures(atsuStyle, types.length, types, selectors);
- return atsuStyle;
-}
-
-void destroy() {
- if (handle == 0) return;
- handle = 0;
- if (atsuiStyle != 0) OS.ATSUDisposeStyle(atsuiStyle);
- atsuiStyle = 0;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals(Object object) {
- if (object == this) return true;
- if (!(object instanceof Font)) return false;
- Font font = (Font)object;
- return handle == font.handle && size == font.size;
-}
-
-/**
- * Returns an array of <code>FontData</code>s representing the receiver.
- * On Windows, only one FontData will be returned per font. On X however,
- * a <code>Font</code> object <em>may</em> be composed of multiple X
- * fonts. To support this case, we return an array of font data objects.
- *
- * @return an array of font data objects describing the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontData[] getFontData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int[] buffer = new int[1];
- OS.ATSFontGetName(handle, 0, buffer);
- CFRange range = new CFRange();
- range.length = OS.CFStringGetLength(buffer[0]);
- char [] chars = new char[range.length];
- OS.CFStringGetCharacters(buffer[0], range, chars);
- OS.CFRelease(buffer[0]);
- String atsName = new String(chars);
- int platformCode = OS.kFontUnicodePlatform, encoding = OS.kCFStringEncodingUnicode;
- if (OS.ATSUFindFontName(handle, OS.kFontFamilyName, platformCode, OS.kFontNoScriptCode, OS.kFontNoLanguageCode, 0, null, buffer, null) != OS.noErr) {
- platformCode = OS.kFontNoPlatformCode;
- encoding = OS.kCFStringEncodingMacRoman;
- OS.ATSUFindFontName (handle, OS.kFontFamilyName, platformCode, OS.kFontNoScriptCode, OS.kFontNoLanguageCode, 0, null, buffer, null);
- }
- byte[] bytes = new byte[buffer[0]];
- OS.ATSUFindFontName(handle, OS.kFontFamilyName, platformCode, OS.kFontNoScriptCode, OS.kFontNoLanguageCode, bytes.length, bytes, buffer, null);
- String name = "";
- int ptr = OS.CFStringCreateWithBytes(0, bytes, bytes.length, encoding, false);
- if (ptr != 0) {
- range.length = OS.CFStringGetLength(ptr);
- if (range.length != 0) {
- chars = new char[range.length];
- OS.CFStringGetCharacters(ptr, range, chars);
- name = new String(chars);
- }
- OS.CFRelease(ptr);
- }
- int style = 0;
- if ((this.style & OS.italic) != 0) style |= SWT.ITALIC;
- if ((this.style & OS.bold) != 0) style |= SWT.BOLD;
- if (atsName.indexOf("Italic") != -1) style |= SWT.ITALIC;
- if (atsName.indexOf("Bold") != -1) style |= SWT.BOLD;
- Point dpi = device.dpi, screenDPI = device.getScreenDPI();
- FontData data = new FontData(name, size * screenDPI.y / dpi.y, style);
- data.atsName = atsName;
- return new FontData[]{data};
-}
-
-/**
- * Invokes platform specific functionality to allocate a new font.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Font</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param handle the handle for the font
- * @param style the style for the font
- * @param size the size for the font
- *
- * @private
- */
-public static Font carbon_new(Device device, int handle, short style, float size) {
- Font font = new Font(device);
- font.handle = handle;
- font.style = style;
- font.size = size;
- return font;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode() {
- return handle;
-}
-
-void init(String name, float height, int style, String atsName) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int font = 0;
- if (atsName != null) {
- int ptr = createCFString(atsName);
- if (ptr != 0) {
- font = OS.ATSFontFindFromName(ptr, OS.kATSOptionFlagsDefault);
- OS.CFRelease(ptr);
- }
- } else {
- atsName = name;
- if ((style & SWT.BOLD) != 0) atsName += " Bold";
- if ((style & SWT.ITALIC) != 0) atsName += " Italic";
- int ptr = createCFString(atsName);
- if (ptr != 0) {
- font = OS.ATSFontFindFromName(ptr, OS.kATSOptionFlagsDefault);
- OS.CFRelease(ptr);
- }
- if (font == 0 && (style & SWT.ITALIC) != 0) {
- this.style |= OS.italic;
- atsName = name;
- if ((style & SWT.BOLD) != 0) atsName += " Bold";
- ptr = createCFString(atsName);
- if (ptr != 0) {
- font = OS.ATSFontFindFromName(ptr, OS.kATSOptionFlagsDefault);
- OS.CFRelease(ptr);
- }
- }
- if (font == 0 && (style & SWT.BOLD) != 0) {
- this.style |= OS.bold;
- atsName = name;
- ptr = createCFString(atsName);
- if (ptr != 0) {
- font = OS.ATSFontFindFromName(ptr, OS.kATSOptionFlagsDefault);
- OS.CFRelease(ptr);
- }
- }
- }
- Point dpi = device.dpi, screenDPI = device.getScreenDPI();
- this.size = height * dpi.y / screenDPI.y;
- if (font == 0) {
- Font systemFont = device.systemFont;
- this.handle = systemFont.handle;
- } else {
- this.handle = font;
- }
- this.atsuiStyle = createStyle();
-}
-
-int createCFString(String str) {
- char[] chars = new char[str.length()];
- str.getChars(0, chars.length, chars, 0);
- return OS.CFStringCreateWithCharacters(OS.kCFAllocatorDefault, chars, chars.length);
-}
-
-/**
- * Returns <code>true</code> if the font has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the font.
- * When a font has been disposed, it is an error to
- * invoke any other method using the font.
- *
- * @return <code>true</code> when the font is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Font {*DISPOSED*}";
- return "Font {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/FontData.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/FontData.java
deleted file mode 100644
index 67d8aa9c60..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/FontData.java
+++ /dev/null
@@ -1,447 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class describe operating system fonts.
- * <p>
- * For platform-independent behaviour, use the get and set methods
- * corresponding to the following properties:
- * <dl>
- * <dt>height</dt><dd>the height of the font in points</dd>
- * <dt>name</dt><dd>the face name of the font, which may include the foundry</dd>
- * <dt>style</dt><dd>A bitwise combination of NORMAL, ITALIC and BOLD</dd>
- * </dl>
- * If extra, platform-dependent functionality is required:
- * <ul>
- * <li>On <em>Windows</em>, the data member of the <code>FontData</code>
- * corresponds to a Windows <code>LOGFONT</code> structure whose fields
- * may be retrieved and modified.</li>
- * <li>On <em>X</em>, the fields of the <code>FontData</code> correspond
- * to the entries in the font's XLFD name and may be retrieved and modified.
- * </ul>
- * Application code does <em>not</em> need to explicitly release the
- * resources managed by each instance when those instances are no longer
- * required, and thus no <code>dispose()</code> method is provided.
- *
- * @see Font
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class FontData {
- /**
- * the font name
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public String name;
-
- /**
- * The height of the font data in points
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public float height;
-
- /**
- * the font style
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int style;
-
- /**
- * the ATS font name
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public String atsName;
-
- /**
- * The locales of the font
- */
- String lang, country, variant;
-
-/**
- * Constructs a new uninitialized font data.
- */
-public FontData () {
- this("", 12, SWT.NORMAL);
-}
-
-/**
- * Constructs a new FontData given a string representation
- * in the form generated by the <code>FontData.toString</code>
- * method.
- * <p>
- * Note that the representation varies between platforms,
- * and a FontData can only be created from a string that was
- * generated on the same platform.
- * </p>
- *
- * @param string the string representation of a <code>FontData</code> (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument does not represent a valid description</li>
- * </ul>
- *
- * @see #toString
- */
-public FontData(String string) {
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int start = 0;
- int end = string.indexOf('|');
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- String version1 = string.substring(start, end);
- try {
- if (Integer.parseInt(version1) != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- String name = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- float height = 0;
- try {
- height = Float.parseFloat(string.substring(start, end));
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int style = 0;
- try {
- style = Integer.parseInt(string.substring(start, end));
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- setName(name);
- setHeight(height);
- setStyle(style);
- if (end == -1) return;
- String platform = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- String version2 = string.substring(start, end);
-
- if (platform.equals("CARBON") && version2.equals("1")) {
- start = end + 1;
- end = string.length();
- if (start < end) atsName = string.substring(start, end);
- }
-}
-
-/**
- * Constructs a new font data given a font name,
- * the height of the desired font in points,
- * and a font style.
- *
- * @param name the name of the font (must not be null)
- * @param height the font height in points
- * @param style a bit or combination of NORMAL, BOLD, ITALIC
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - when the font name is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- */
-public FontData(String name, int height, int style) {
- setName(name);
- setHeight(height);
- setStyle(style);
-}
-
-/*public*/ FontData(String name, float height, int style) {
- setName(name);
- setHeight(height);
- setStyle(style);
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof FontData)) return false;
- FontData data = (FontData)object;
- return name.equals(data.name) && height == data.height && style == data.style;
-}
-
-/**
- * Returns the height of the receiver in points.
- *
- * @return the height of this FontData
- *
- * @see #setHeight(int)
- */
-public int getHeight() {
- return (int)height;
-}
-
-/*public*/ float getHeightF() {
- return height;
-}
-
-/**
- * Returns the locale of the receiver.
- * <p>
- * The locale determines which platform character set this
- * font is going to use. Widgets and graphics operations that
- * use this font will convert UNICODE strings to the platform
- * character set of the specified locale.
- * </p>
- * <p>
- * On platforms where there are multiple character sets for a
- * given language/country locale, the variant portion of the
- * locale will determine the character set.
- * </p>
- *
- * @return the <code>String</code> representing a Locale object
- * @since 3.0
- */
-public String getLocale () {
- StringBuffer buffer = new StringBuffer ();
- char sep = '_';
- if (lang != null) {
- buffer.append (lang);
- buffer.append (sep);
- }
- if (country != null) {
- buffer.append (country);
- buffer.append (sep);
- }
- if (variant != null) {
- buffer.append (variant);
- }
-
- String result = buffer.toString ();
- int length = result.length ();
- if (length > 0) {
- if (result.charAt (length - 1) == sep) {
- result = result.substring (0, length - 1);
- }
- }
- return result;
-}
-
-/**
- * Returns the name of the receiver.
- * On platforms that support font foundries, the return value will
- * be the foundry followed by a dash ("-") followed by the face name.
- *
- * @return the name of this <code>FontData</code>
- *
- * @see #setName
- */
-public String getName() {
- return name;
-}
-
-/**
- * Returns the style of the receiver which is a bitwise OR of
- * one or more of the <code>SWT</code> constants NORMAL, BOLD
- * and ITALIC.
- *
- * @return the style of this <code>FontData</code>
- *
- * @see #setStyle
- */
-public int getStyle() {
- return style;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return name.hashCode() ^ getHeight() ^ style;
-}
-
-/**
- * Sets the height of the receiver. The parameter is
- * specified in terms of points, where a point is one
- * seventy-second of an inch.
- *
- * @param height the height of the <code>FontData</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- *
- * @see #getHeight
- */
-public void setHeight(int height) {
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.height = height;
-}
-
-/*public*/ void setHeight(float height) {
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.height = height;
-}
-
-/**
- * Sets the locale of the receiver.
- * <p>
- * The locale determines which platform character set this
- * font is going to use. Widgets and graphics operations that
- * use this font will convert UNICODE strings to the platform
- * character set of the specified locale.
- * </p>
- * <p>
- * On platforms where there are multiple character sets for a
- * given language/country locale, the variant portion of the
- * locale will determine the character set.
- * </p>
- *
- * @param locale the <code>String</code> representing a Locale object
- * @see java.util.Locale#toString
- */
-public void setLocale(String locale) {
- lang = country = variant = null;
- if (locale != null) {
- char sep = '_';
- int length = locale.length();
- int firstSep, secondSep;
-
- firstSep = locale.indexOf(sep);
- if (firstSep == -1) {
- firstSep = secondSep = length;
- } else {
- secondSep = locale.indexOf(sep, firstSep + 1);
- if (secondSep == -1) secondSep = length;
- }
- if (firstSep > 0) lang = locale.substring(0, firstSep);
- if (secondSep > firstSep + 1) country = locale.substring(firstSep + 1, secondSep);
- if (length > secondSep + 1) variant = locale.substring(secondSep + 1);
- }
-}
-
-/**
- * Sets the name of the receiver.
- * <p>
- * Some platforms support font foundries. On these platforms, the name
- * of the font specified in setName() may have one of the following forms:
- * <ol>
- * <li>a face name (for example, "courier")</li>
- * <li>a foundry followed by a dash ("-") followed by a face name (for example, "adobe-courier")</li>
- * </ol>
- * In either case, the name returned from getName() will include the
- * foundry.
- * </p>
- * <p>
- * On platforms that do not support font foundries, only the face name
- * (for example, "courier") is used in <code>setName()</code> and
- * <code>getName()</code>.
- * </p>
- *
- * @param name the name of the font data (must not be null)
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - when the font name is null</li>
- * </ul>
- *
- * @see #getName
- */
-public void setName(String name) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.name = name;
- atsName = null;
-}
-
-/**
- * Sets the style of the receiver to the argument which must
- * be a bitwise OR of one or more of the <code>SWT</code>
- * constants NORMAL, BOLD and ITALIC. All other style bits are
- * ignored.
- *
- * @param style the new style for this <code>FontData</code>
- *
- * @see #getStyle
- */
-public void setStyle(int style) {
- this.style = style;
- atsName = null;
-}
-
-/**
- * Returns a string representation of the receiver which is suitable
- * for constructing an equivalent instance using the
- * <code>FontData(String)</code> constructor.
- *
- * @return a string representation of the FontData
- *
- * @see FontData
- */
-public String toString() {
- StringBuffer buffer = new StringBuffer(128);
- buffer.append("1|");
- buffer.append(getName());
- buffer.append("|");
- buffer.append(getHeightF());
- buffer.append("|");
- buffer.append(getStyle());
- buffer.append("|");
- buffer.append("CARBON|1|");
- if (atsName != null) buffer.append(atsName);
- return buffer.toString();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/FontMetrics.java
deleted file mode 100644
index f3fc1ca48e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/FontMetrics.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-/**
- * Instances of this class provide measurement information
- * about fonts including ascent, descent, height, leading
- * space between rows, and average character width.
- * <code>FontMetrics</code> are obtained from <code>GC</code>s
- * using the <code>getFontMetrics()</code> method.
- *
- * @see GC#getFontMetrics
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class FontMetrics {
- int ascent, descent, averageCharWidth, leading, height;
-
-FontMetrics() {
-}
-
-public static FontMetrics carbon_new(int ascent, int descent, int averageCharWidth, int leading, int height) {
- FontMetrics fontMetrics = new FontMetrics();
- fontMetrics.ascent = ascent;
- fontMetrics.descent = descent;
- fontMetrics.averageCharWidth = averageCharWidth;
- fontMetrics.leading = leading;
- fontMetrics.height = height;
- return fontMetrics;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof FontMetrics)) return false;
- FontMetrics metrics = (FontMetrics)object;
- return ascent == metrics.ascent && descent == metrics.descent &&
- averageCharWidth == metrics.averageCharWidth && leading == metrics.leading &&
- height == metrics.height;
-}
-
-/**
- * Returns the ascent of the font described by the receiver. A
- * font's <em>ascent</em> is the distance from the baseline to the
- * top of actual characters, not including any of the leading area,
- * measured in pixels.
- *
- * @return the ascent of the font
- */
-public int getAscent() {
- return ascent;
-}
-
-/**
- * Returns the average character width, measured in pixels,
- * of the font described by the receiver.
- *
- * @return the average character width of the font
- */
-public int getAverageCharWidth() {
- return averageCharWidth;
-}
-
-/**
- * Returns the descent of the font described by the receiver. A
- * font's <em>descent</em> is the distance from the baseline to the
- * bottom of actual characters, not including any of the leading area,
- * measured in pixels.
- *
- * @return the descent of the font
- */
-public int getDescent() {
- return descent;
-}
-
-/**
- * Returns the height of the font described by the receiver,
- * measured in pixels. A font's <em>height</em> is the sum of
- * its ascent, descent and leading area.
- *
- * @return the height of the font
- *
- * @see #getAscent
- * @see #getDescent
- * @see #getLeading
- */
-public int getHeight() {
- return height;
-}
-
-/**
- * Returns the leading area of the font described by the
- * receiver. A font's <em>leading area</em> is the space
- * above its ascent which may include accents or other marks.
- *
- * @return the leading space of the font
- */
-public int getLeading() {
- return leading;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode() {
- return ascent ^ descent ^ averageCharWidth ^ leading ^ height;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/GC.java
deleted file mode 100644
index 58e49e9731..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/GC.java
+++ /dev/null
@@ -1,3674 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.carbon.*;
-import org.eclipse.swt.*;
-
-/**
- * Class <code>GC</code> is where all of the drawing capabilities that are
- * supported by SWT are located. Instances are used to draw on either an
- * <code>Image</code>, a <code>Control</code>, or directly on a <code>Display</code>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * </dl>
- *
- * <p>
- * The SWT drawing coordinate system is the two-dimensional space with the origin
- * (0,0) at the top left corner of the drawing area and with (x,y) values increasing
- * to the right and downward respectively.
- * </p>
- *
- * <p>
- * The result of drawing on an image that was created with an indexed
- * palette using a color that is not in the palette is platform specific.
- * Some platforms will match to the nearest color while other will draw
- * the color itself. This happens because the allocated image might use
- * a direct palette on platforms that do not support indexed palette.
- * </p>
- *
- * <p>
- * Application code must explicitly invoke the <code>GC.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required. This is <em>particularly</em>
- * important on Windows95 and Windows98 where the operating system has a limited
- * number of device contexts available.
- * </p>
- *
- * <p>
- * Note: Only one of LEFT_TO_RIGHT and RIGHT_TO_LEFT may be specified.
- * </p>
- *
- * @see org.eclipse.swt.events.PaintEvent
- * @see <a href="http://www.eclipse.org/swt/snippets/#gc">GC snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class GC extends Resource {
- /**
- * the handle to the OS device context
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
- Drawable drawable;
- GCData data;
-
- static final int TAB_COUNT = 32;
-
- final static int FOREGROUND = 1 << 0;
- final static int BACKGROUND = 1 << 1;
- final static int FONT = 1 << 2;
- final static int LINE_STYLE = 1 << 3;
- final static int LINE_CAP = 1 << 4;
- final static int LINE_JOIN = 1 << 5;
- final static int LINE_WIDTH = 1 << 6;
- final static int LINE_MITERLIMIT = 1 << 7;
- final static int FOREGROUND_FILL = 1 << 8;
- final static int DRAW_OFFSET = 1 << 9;
- final static int DRAW = FOREGROUND | LINE_WIDTH | LINE_STYLE | LINE_CAP | LINE_JOIN | LINE_MITERLIMIT | DRAW_OFFSET;
- final static int FILL = BACKGROUND;
-
- static final float[] LINE_DOT = new float[]{1, 1};
- static final float[] LINE_DASH = new float[]{3, 1};
- static final float[] LINE_DASHDOT = new float[]{3, 1, 1, 1};
- static final float[] LINE_DASHDOTDOT = new float[]{3, 1, 1, 1, 1, 1};
- static final float[] LINE_DOT_ZERO = new float[]{3, 3};
- static final float[] LINE_DASH_ZERO = new float[]{18, 6};
- static final float[] LINE_DASHDOT_ZERO = new float[]{9, 6, 3, 6};
- static final float[] LINE_DASHDOTDOT_ZERO = new float[]{9, 3, 3, 3, 3, 3};
-
-GC() {
-}
-
-/**
- * Constructs a new instance of this class which has been
- * configured to draw on the specified drawable. Sets the
- * foreground color, background color and font in the GC
- * to match those in the drawable.
- * <p>
- * You must dispose the graphics context when it is no longer required.
- * </p>
- * @param drawable the drawable to draw on
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li>
- * <li>ERROR_NULL_ARGUMENT - if there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT
- * - if the drawable is an image that is not a bitmap or an icon
- * - if the drawable is an image or printer that is already selected
- * into another graphics context</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li>
- * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li>
- * </ul>
- */
-public GC(Drawable drawable) {
- this(drawable, 0);
-}
-
-/**
- * Constructs a new instance of this class which has been
- * configured to draw on the specified drawable. Sets the
- * foreground color, background color and font in the GC
- * to match those in the drawable.
- * <p>
- * You must dispose the graphics context when it is no longer required.
- * </p>
- *
- * @param drawable the drawable to draw on
- * @param style the style of GC to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li>
- * <li>ERROR_NULL_ARGUMENT - if there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT
- * - if the drawable is an image that is not a bitmap or an icon
- * - if the drawable is an image or printer that is already selected
- * into another graphics context</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li>
- * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public GC(Drawable drawable, int style) {
- if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- GCData data = new GCData();
- data.style = checkStyle(style);
- int gdkGC = drawable.internal_new_GC(data);
- Device device = data.device;
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = data.device = device;
- init(drawable, data, gdkGC);
- init();
-}
-
-static int checkStyle (int style) {
- if ((style & SWT.LEFT_TO_RIGHT) != 0) style &= ~SWT.RIGHT_TO_LEFT;
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new graphics context.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>GC</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param drawable the Drawable for the receiver.
- * @param data the data for the receiver.
- *
- * @return a new <code>GC</code>
- *
- * @private
- */
-public static GC carbon_new(Drawable drawable, GCData data) {
- GC gc = new GC();
- int context = drawable.internal_new_GC(data);
- gc.device = data.device;
- gc.init(drawable, data, context);
- return gc;
-}
-
-/**
- * Invokes platform specific functionality to wrap a graphics context.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>GC</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param context the Quartz context.
- * @param data the data for the receiver.
- *
- * @return a new <code>GC</code>
- */
-public static GC carbon_new(int context, GCData data) {
- GC gc = new GC();
- gc.device = data.device;
- gc.init(null, data, context);
- return gc;
-}
-
-void checkGC (int mask) {
- int state = data.state;
- if ((state & mask) == mask) return;
- state = (state ^ mask) & mask;
- data.state |= mask;
- if ((state & FOREGROUND) != 0) {
- Pattern pattern = data.foregroundPattern;
- if (pattern != null) {
- int colorspace = OS.CGColorSpaceCreatePattern(data.device.colorspace);
- OS.CGContextSetStrokeColorSpace(handle, colorspace);
- OS.CGColorSpaceRelease(colorspace);
- if (data.forePattern == 0) data.forePattern = pattern.createPattern(handle);
- OS.CGContextSetStrokePattern(handle, data.forePattern, data.foreground);
- } else {
- OS.CGContextSetStrokeColorSpace(handle, data.device.colorspace);
- OS.CGContextSetStrokeColor(handle, data.foreground);
- }
- }
- if ((state & FOREGROUND_FILL) != 0) {
- Pattern pattern = data.foregroundPattern;
- if (pattern != null) {
- int colorspace = OS.CGColorSpaceCreatePattern(data.device.colorspace);
- OS.CGContextSetFillColorSpace(handle, colorspace);
- OS.CGColorSpaceRelease(colorspace);
- if (data.forePattern == 0) data.forePattern = pattern.createPattern(handle);
- OS.CGContextSetFillPattern(handle, data.forePattern, data.foreground);
- } else {
- OS.CGContextSetFillColorSpace(handle, data.device.colorspace);
- OS.CGContextSetFillColor(handle, data.foreground);
- }
- data.state &= ~BACKGROUND;
- }
- if ((state & BACKGROUND) != 0) {
- Pattern pattern = data.backgroundPattern;
- if (pattern != null) {
- int colorspace = OS.CGColorSpaceCreatePattern(data.device.colorspace);
- OS.CGContextSetFillColorSpace(handle, colorspace);
- OS.CGColorSpaceRelease(colorspace);
- if (data.backPattern == 0) data.backPattern = pattern.createPattern(handle);
- OS.CGContextSetFillPattern(handle, data.backPattern, data.background);
- } else {
- OS.CGContextSetFillColorSpace(handle, data.device.colorspace);
- OS.CGContextSetFillColor(handle, data.background);
- }
- data.state &= ~FOREGROUND_FILL;
- }
- if ((state & FONT) != 0) {
- setCGFont();
- }
- if ((state & LINE_WIDTH) != 0) {
- OS.CGContextSetLineWidth(handle, data.lineWidth == 0 ? 1 : data.lineWidth);
- switch (data.lineStyle) {
- case SWT.LINE_DOT:
- case SWT.LINE_DASH:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- state |= LINE_STYLE;
- }
- }
- if ((state & LINE_STYLE) != 0) {
- float[] dashes = null;
- float width = data.lineWidth;
- switch (data.lineStyle) {
- case SWT.LINE_SOLID: break;
- case SWT.LINE_DASH: dashes = width != 0 ? LINE_DASH : LINE_DASH_ZERO; break;
- case SWT.LINE_DOT: dashes = width != 0 ? LINE_DOT : LINE_DOT_ZERO; break;
- case SWT.LINE_DASHDOT: dashes = width != 0 ? LINE_DASHDOT : LINE_DASHDOT_ZERO; break;
- case SWT.LINE_DASHDOTDOT: dashes = width != 0 ? LINE_DASHDOTDOT : LINE_DASHDOTDOT_ZERO; break;
- case SWT.LINE_CUSTOM: dashes = data.lineDashes; break;
- }
- if (dashes != null) {
- float[] lengths = new float[dashes.length];
- for (int i = 0; i < lengths.length; i++) {
- lengths[i] = width == 0 || data.lineStyle == SWT.LINE_CUSTOM ? dashes[i] : dashes[i] * width;
- }
- OS.CGContextSetLineDash(handle, data.lineDashesOffset, lengths, lengths.length);
- } else {
- OS.CGContextSetLineDash(handle, 0, null, 0);
- }
- }
- if ((state & LINE_MITERLIMIT) != 0) {
- OS.CGContextSetMiterLimit(handle, data.lineMiterLimit);
- }
- if ((state & LINE_JOIN) != 0) {
- int joinStyle = 0;
- switch (data.lineJoin) {
- case SWT.JOIN_MITER: joinStyle = OS.kCGLineJoinMiter; break;
- case SWT.JOIN_ROUND: joinStyle = OS.kCGLineJoinRound; break;
- case SWT.JOIN_BEVEL: joinStyle = OS.kCGLineJoinBevel; break;
- }
- OS.CGContextSetLineJoin(handle, joinStyle);
- }
- if ((state & LINE_CAP) != 0) {
- int capStyle = 0;
- switch (data.lineCap) {
- case SWT.CAP_ROUND: capStyle = OS.kCGLineCapRound; break;
- case SWT.CAP_FLAT: capStyle = OS.kCGLineCapButt; break;
- case SWT.CAP_SQUARE: capStyle = OS.kCGLineCapSquare; break;
- }
- OS.CGContextSetLineCap(handle, capStyle);
- }
- if ((state & DRAW_OFFSET) != 0) {
- data.drawXOffset = data.drawYOffset = 0;
- CGSize size = new CGSize();
- size.width = size.height = 1;
- if (data.transform != null) {
- OS.CGSizeApplyAffineTransform(size, data.transform, size);
- }
- float scaling = size.width;
- if (scaling < 0) scaling = -scaling;
- float strokeWidth = data.lineWidth * scaling;
- if (strokeWidth == 0 || ((int)strokeWidth % 2) == 1) {
- data.drawXOffset = 0.5f / scaling;
- }
- scaling = size.height;
- if (scaling < 0) scaling = -scaling;
- strokeWidth = data.lineWidth * scaling;
- if (strokeWidth == 0 || ((int)strokeWidth % 2) == 1) {
- data.drawYOffset = 0.5f / scaling;
- }
- }
-}
-
-int convertRgn(int rgn, float[] transform) {
- int newRgn = OS.NewRgn();
- Callback callback = new Callback(this, "convertRgn", 4);
- int proc = callback.getAddress();
- if (proc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- float[] clippingTranform = data.clippingTransform;
- data.clippingTransform = transform;
- OS.QDRegionToRects(rgn, OS.kQDParseRegionFromTopLeft, proc, newRgn);
- data.clippingTransform = clippingTranform;
- callback.dispose();
- return newRgn;
-}
-
-int convertRgn(int message, int rgn, int r, int newRgn) {
- if (message == OS.kQDRegionToRectsMsgParse) {
- Rect rect = new Rect();
- OS.memmove(rect, r, Rect.sizeof);
- CGPoint point = new CGPoint();
- int polyRgn = OS.NewRgn();
- OS.OpenRgn();
- point.x = rect.left;
- point.y = rect.top;
- float[] transform = data.clippingTransform;
- OS.CGPointApplyAffineTransform(point, transform, point);
- short startX, startY;
- OS.MoveTo(startX = (short)point.x, startY = (short)point.y);
- point.x = rect.right;
- point.y = rect.top;
- OS.CGPointApplyAffineTransform(point, transform, point);
- OS.LineTo((short)Math.round(point.x), (short)point.y);
- point.x = rect.right;
- point.y = rect.bottom;
- OS.CGPointApplyAffineTransform(point, transform, point);
- OS.LineTo((short)Math.round(point.x), (short)Math.round(point.y));
- point.x = rect.left;
- point.y = rect.bottom;
- OS.CGPointApplyAffineTransform(point, transform, point);
- OS.LineTo((short)point.x, (short)Math.round(point.y));
- OS.LineTo(startX, startY);
- OS.CloseRgn(polyRgn);
- OS.UnionRgn(newRgn, polyRgn, newRgn);
- OS.DisposeRgn(polyRgn);
- }
- return 0;
-}
-
-/**
- * Copies a rectangular area of the receiver at the specified
- * position into the image, which must be of type <code>SWT.BITMAP</code>.
- *
- * @param image the image to copy into
- * @param x the x coordinate in the receiver of the area to be copied
- * @param y the y coordinate in the receiver of the area to be copied
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image is not a bitmap or has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void copyArea(Image image, int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.image != null) {
- copyArea(image, x, y, data.image.handle);
- } else if (data.control != 0) {
- int imageHandle = image.handle;
- int width = OS.CGImageGetWidth(imageHandle);
- int height = OS.CGImageGetHeight(imageHandle);
- int window = OS.GetControlOwner(data.control);
- Rect srcRect = new Rect ();
- CGPoint pt = new CGPoint ();
- int[] contentView = new int[1];
- OS.HIViewFindByID(OS.HIViewGetRoot(window), OS.kHIViewWindowContentID(), contentView);
- OS.HIViewConvertPoint (pt, data.control, contentView[0]);
- x += (int) pt.x;
- y += (int) pt.y;
- Rect inset = data.insetRect;
- x -= inset.left;
- y -= inset.top;
- srcRect.left = (short)x;
- srcRect.top = (short)y;
- srcRect.right = (short)(x + width);
- srcRect.bottom = (short)(y + height);
- Rect destRect = new Rect();
- destRect.right = (short)width;
- destRect.bottom = (short)height;
- int bpl = width * 4;
- int[] gWorld = new int[1];
- int port = OS.GetWindowPort(window);
- OS.NewGWorldFromPtr(gWorld, OS.k32ARGBPixelFormat, destRect, 0, 0, 0, image.data, bpl);
- OS.CopyBits(OS.GetPortBitMapForCopyBits(port), OS.GetPortBitMapForCopyBits(gWorld[0]), srcRect, destRect, (short)OS.srcCopy, 0);
- OS.DisposeGWorld(gWorld [0]);
- } else if (data.window != 0) {
- int imageHandle = image.handle;
- CGRect rect = new CGRect();
- rect.x = x;
- rect.y = y;
- rect.width = OS.CGImageGetWidth(imageHandle);
- rect.height = OS.CGImageGetHeight(imageHandle);
- int[] displays = new int[16];
- int[] count = new int[1];
- if (OS.CGGetDisplaysWithRect(rect, displays.length, displays, count) != 0) return;
- for (int i = 0; i < count[0]; i++) {
- int display = displays[i];
- OS.CGDisplayBounds(display, rect);
- int address = OS.CGDisplayBaseAddress(display);
- if (address != 0) {
- int width = OS.CGDisplayPixelsWide(display);
- int height = OS.CGDisplayPixelsHigh(display);
- int bpr = OS.CGDisplayBytesPerRow(display);
- int bpp = OS.CGDisplayBitsPerPixel(display);
- int bps = OS.CGDisplayBitsPerSample(display);
- int bitmapInfo = OS.kCGImageAlphaNoneSkipFirst;
- switch (bpp) {
- case 16: bitmapInfo |= OS.kCGBitmapByteOrder16Host; break;
- case 32: bitmapInfo |= OS.kCGBitmapByteOrder32Host; break;
- }
- int srcImage = 0;
- if (OS.__BIG_ENDIAN__() && OS.VERSION >= 0x1040) {
- int context = OS.CGBitmapContextCreate(address, width, height, bps, bpr, data.device.colorspace, bitmapInfo);
- srcImage = OS.CGBitmapContextCreateImage(context);
- OS.CGContextRelease(context);
- } else {
- int provider = OS.CGDataProviderCreateWithData(0, address, bpr * height, 0);
- srcImage = OS.CGImageCreate(width, height, bps, bpp, bpr, data.device.colorspace, bitmapInfo, provider, null, true, 0);
- OS.CGDataProviderRelease(provider);
- }
- copyArea(image, x - (int)rect.x, y - (int)rect.y, srcImage);
- if (srcImage != 0) OS.CGImageRelease(srcImage);
- }
- }
- }
-}
-
-void copyArea (Image image, int x, int y, int srcImage) {
- if (srcImage == 0) return;
- int imageHandle = image.handle;
- int bpc = OS.CGImageGetBitsPerComponent(imageHandle);
- int width = OS.CGImageGetWidth(imageHandle);
- int height = OS.CGImageGetHeight(imageHandle);
- int bpr = OS.CGImageGetBytesPerRow(imageHandle);
- int alphaInfo = OS.CGImageGetAlphaInfo(imageHandle);
- int context = OS.CGBitmapContextCreate(image.data, width, height, bpc, bpr, data.device.colorspace, alphaInfo);
- if (context != 0) {
- CGRect rect = new CGRect();
- rect.x = -x;
- rect.y = y;
- rect.width = OS.CGImageGetWidth(srcImage);
- rect.height = OS.CGImageGetHeight(srcImage);
- OS.CGContextTranslateCTM(context, 0, -(rect.height - height));
- OS.CGContextDrawImage(context, rect, srcImage);
- OS.CGContextRelease(context);
- }
-}
-
-/**
- * Copies a rectangular area of the receiver at the source
- * position onto the receiver at the destination position.
- *
- * @param srcX the x coordinate in the receiver of the area to be copied
- * @param srcY the y coordinate in the receiver of the area to be copied
- * @param width the width of the area to copy
- * @param height the height of the area to copy
- * @param destX the x coordinate in the receiver of the area to copy to
- * @param destY the y coordinate in the receiver of the area to copy to
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY) {
- copyArea(srcX, srcY, width, height, destX, destY, true);
-}
-/**
- * Copies a rectangular area of the receiver at the source
- * position onto the receiver at the destination position.
- *
- * @param srcX the x coordinate in the receiver of the area to be copied
- * @param srcY the y coordinate in the receiver of the area to be copied
- * @param width the width of the area to copy
- * @param height the height of the area to copy
- * @param destX the x coordinate in the receiver of the area to copy to
- * @param destY the y coordinate in the receiver of the area to copy to
- * @param paint if <code>true</code> paint events will be generated for old and obscured areas
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.updateClip) setCGClipping();
- if (width <= 0 || height <= 0) return;
- int deltaX = destX - srcX, deltaY = destY - srcY;
- if (deltaX == 0 && deltaY == 0) return;
- if (data.image != null) {
- OS.CGContextSaveGState(handle);
- OS.CGContextScaleCTM(handle, 1, -1);
- OS.CGContextTranslateCTM(handle, 0, -(height + 2 * destY));
- CGRect rect = new CGRect();
- rect.x = destX;
- rect.y = destY;
- rect.width = width;
- rect.height = height;
- int h = OS.CGImageGetHeight(data.image.handle);
- int bpr = OS.CGImageGetBytesPerRow(data.image.handle);
- int provider = OS.CGDataProviderCreateWithData(0, data.image.data, bpr * h, 0);
- if (provider != 0) {
- int colorspace = device.colorspace;
- int img = OS.CGImageCreate(width, height, 8, 32, bpr, colorspace, OS.kCGImageAlphaNoneSkipFirst, provider, null, true, 0);
- OS.CGDataProviderRelease(provider);
- OS.CGContextDrawImage(handle, rect, img);
- OS.CGImageRelease(img);
- }
- OS.CGContextRestoreGState(handle);
- return;
- }
- if (data.control != 0) {
- int port = data.port;
- int window = OS.GetControlOwner(data.control);
- if (port == 0) port = OS.GetWindowPort(window);
-
- /* Calculate src and dest rectangles/regions */
- Rect rect = new Rect();
- OS.GetControlBounds(data.control, rect);
- int convertX = 0, convertY = 0;
- CGPoint pt = new CGPoint ();
- int[] contentView = new int[1];
- OS.HIViewFindByID(OS.HIViewGetRoot(window), OS.kHIViewWindowContentID(), contentView);
- OS.HIViewConvertPoint(pt, OS.HIViewGetSuperview(data.control), contentView[0]);
- convertX = rect.left + (int) pt.x;
- convertY = rect.top + (int) pt.y;
- rect.left += (int) pt.x;
- rect.top += (int) pt.y;
- rect.right += (int) pt.x;
- rect.bottom += (int) pt.y;
- Rect srcRect = new Rect();
- int left = rect.left + srcX;
- int top = rect.top + srcY;
- OS.SetRect(srcRect, (short)left, (short)top, (short)(left + width), (short)(top + height));
- int srcRgn = OS.NewRgn();
- OS.RectRgn(srcRgn, srcRect);
- OS.SectRect(rect, srcRect, srcRect);
- Rect destRect = new Rect ();
- OS.SetRect(destRect, srcRect.left, srcRect.top, srcRect.right, srcRect.bottom);
- OS.OffsetRect(destRect, (short)deltaX, (short)deltaY);
- int destRgn = OS.NewRgn();
- OS.RectRgn(destRgn, destRect);
-
- /* Copy bits with appropriated clipping region */
- if (!OS.EmptyRect(srcRect)) {
- if (data.visibleRgn == 0 || OS.RectInRgn(srcRect, data.visibleRgn)) {
- int clipRgn = data.visibleRgn;
- if (data.clipRgn != 0) {
- clipRgn = OS.NewRgn();
- OS.SectRgn(data.clipRgn, data.visibleRgn, clipRgn);
- }
-
- /*
- * Feature in the Macintosh. ScrollRect() only copies bits
- * that are inside the specified rectangle. This means that
- * it is not possible to copy non overlaping bits without
- * copying the bits in between the source and destination
- * rectangles. The fix is to check if the source and
- * destination rectangles are disjoint and use CopyBits()
- * instead.
- */
- if (!OS.EmptyRgn(clipRgn)) {
- boolean disjoint = (destX + width < srcX) || (srcX + width < destX) || (destY + height < srcY) || (srcY + height < destY);
- if (!disjoint && (deltaX == 0 || deltaY == 0)) {
- int[] currentPort = new int[1];
- OS.GetPort(currentPort);
- OS.SetPort(port);
- int oldClip = OS.NewRgn();
- OS.GetClip(oldClip);
- OS.SetClip(clipRgn);
- OS.UnionRect(srcRect, destRect, rect);
- OS.ScrollRect(rect, (short)deltaX, (short)deltaY, 0);
- OS.SetClip(oldClip);
- OS.DisposeRgn(oldClip);
- OS.SetPort(currentPort[0]);
- } else {
- int portBitMap = OS.GetPortBitMapForCopyBits (port);
- OS.CopyBits(portBitMap, portBitMap, srcRect, destRect, (short)OS.srcCopy, clipRgn);
- OS.QDFlushPortBuffer(port, destRgn);
- }
- }
-
- if (clipRgn != data.visibleRgn) OS.DisposeRgn(clipRgn);
- }
- }
-
- /* Invalidate src and obscured areas */
- if (paint) {
- int invalRgn = OS.NewRgn();
- OS.DiffRgn(srcRgn, data.visibleRgn, invalRgn);
- OS.OffsetRgn(invalRgn, (short)deltaX, (short)deltaY);
- OS.DiffRgn(srcRgn, destRgn, srcRgn);
- OS.UnionRgn(srcRgn, invalRgn, invalRgn);
- OS.SectRgn(data.visibleRgn, invalRgn, invalRgn);
- OS.OffsetRgn(invalRgn, (short)-convertX, (short)-convertY);
- OS.HIViewSetNeedsDisplayInRegion(data.control, invalRgn, true);
- OS.DisposeRgn(invalRgn);
- }
-
- /* Dispose src and dest regions */
- OS.DisposeRgn(destRgn);
- OS.DisposeRgn(srcRgn);
- }
-}
-
-void createLayout () {
- int[] buffer = new int[1];
- OS.ATSUCreateTextLayout(buffer);
- if (buffer[0] == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- data.layout = buffer[0];
- int ptr1 = OS.NewPtr(4);
- buffer[0] = handle;
- OS.memmove(ptr1, buffer, 4);
- int ptr2 = OS.NewPtr(4);
- buffer[0] = OS.kATSLineUseDeviceMetrics;
- OS.memmove(ptr2, buffer, 4);
- int lineDir = OS.kATSULeftToRightBaseDirection;
- if ((data.style & SWT.RIGHT_TO_LEFT) != 0) lineDir = OS.kATSURightToLeftBaseDirection;
- int ptr3 = OS.NewPtr(1);
- OS.memmove(ptr3, new byte[] {(byte)lineDir}, 1);
- int[] tags = new int[]{OS.kATSUCGContextTag, OS.kATSULineLayoutOptionsTag, OS.kATSULineDirectionTag};
- int[] sizes = new int[]{4, 4, 1};
- int[] values = new int[]{ptr1, ptr2, ptr3};
- OS.ATSUSetLayoutControls(data.layout, tags.length, tags, sizes, values);
- OS.DisposePtr(ptr1);
- OS.DisposePtr(ptr2);
- OS.DisposePtr(ptr3);
-}
-
-void createTabs () {
- ATSUTab tabs = new ATSUTab();
- int tabWidth = getCharWidth(' ') * 8;
- int ptr = OS.NewPtr(ATSUTab.sizeof * TAB_COUNT);
- for (int i=0, offset=ptr; i<TAB_COUNT; i++, offset += ATSUTab.sizeof) {
- tabs.tabPosition += OS.Long2Fix(tabWidth);
- OS.memmove(offset, tabs, ATSUTab.sizeof);
- }
- data.tabs = ptr;
-}
-
-void destroy() {
- /* Free resources */
- int clipRgn = data.clipRgn;
- if (clipRgn != 0) OS.DisposeRgn(clipRgn);
- Image image = data.image;
- if (image != null) {
- image.memGC = null;
- image.createAlpha();
- }
- int layout = data.layout;
- if (layout != 0) OS.ATSUDisposeTextLayout(layout);
- int atsuiStyle = data.atsuiStyle;
- if (atsuiStyle != 0) OS.ATSUDisposeStyle(atsuiStyle);
- int stringPtr = data.stringPtr;
- if (stringPtr != 0) OS.DisposePtr(stringPtr);
- int tabs = data.tabs;
- if (tabs != 0) OS.DisposePtr(tabs);
- int forePattern = data.forePattern;
- if (forePattern != 0) OS.CGPatternRelease(forePattern);
- int backPattern = data.backPattern;
- if (backPattern != 0) OS.CGPatternRelease(backPattern);
-
- /* Dispose the GC */
- if (drawable != null) drawable.internal_dispose_GC(handle, data);
-
- data.clipRgn = data.atsuiStyle = data.stringPtr = data.layout = data.tabs = data.forePattern = data.backPattern = 0;
- drawable = null;
- data.image = null;
- data.string = null;
- data = null;
- handle = 0;
-}
-
-/**
- * Draws the outline of a circular or elliptical arc
- * within the specified rectangular area.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees, using the current color.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc to be drawn
- * @param y the y coordinate of the upper-left corner of the arc to be drawn
- * @param width the width of the arc to be drawn
- * @param height the height of the arc to be drawn
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (data.updateClip) setCGClipping();
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- OS.CGContextBeginPath(handle);
- OS.CGContextSaveGState(handle);
- float xOffset = data.drawXOffset, yOffset = data.drawYOffset;
- OS.CGContextTranslateCTM(handle, x + xOffset + width / 2f, y + yOffset + height / 2f);
- OS.CGContextScaleCTM(handle, width / 2f, height / 2f);
- if (arcAngle < 0) {
- OS.CGContextAddArc(handle, 0, 0, 1, -(startAngle + arcAngle) * (float)Compatibility.PI / 180, -startAngle * (float)Compatibility.PI / 180, true);
- } else {
- OS.CGContextAddArc(handle, 0, 0, 1, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180, true);
- }
- OS.CGContextRestoreGState(handle);
- OS.CGContextStrokePath(handle);
- flush();
-}
-
-/**
- * Draws a rectangle, based on the specified arguments, which has
- * the appearance of the platform's <em>focus rectangle</em> if the
- * platform supports such a notion, and otherwise draws a simple
- * rectangle in the receiver's foreground color.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width of the rectangle
- * @param height the height of the rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void drawFocus(int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.updateClip) setCGClipping();
- int[] metric = new int[1];
- OS.GetThemeMetric(OS.kThemeMetricFocusRectOutset, metric);
- CGRect rect = new CGRect ();
- rect.x = x + metric[0];
- rect.y = y + metric[0];
- rect.width = width - metric[0] * 2;
- rect.height = height - metric[0] * 2;
- OS.HIThemeDrawFocusRect(rect, true, handle, OS.kHIThemeOrientationNormal);
- flush();
-}
-
-/**
- * Draws the given image in the receiver at the specified
- * coordinates.
- *
- * @param image the image to draw
- * @param x the x coordinate of where to draw
- * @param y the y coordinate of where to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if the given coordinates are outside the bounds of the image</li>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- */
-public void drawImage(Image image, int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- drawImage(image, 0, 0, -1, -1, x, y, -1, -1, true);
-}
-
-/**
- * Copies a rectangular area from the source image into a (potentially
- * different sized) rectangular area in the receiver. If the source
- * and destination areas are of differing sizes, then the source
- * area will be stretched or shrunk to fit the destination area
- * as it is copied. The copy fails if any part of the source rectangle
- * lies outside the bounds of the source image, or if any of the width
- * or height arguments are negative.
- *
- * @param image the source image
- * @param srcX the x coordinate in the source image to copy from
- * @param srcY the y coordinate in the source image to copy from
- * @param srcWidth the width in pixels to copy from the source
- * @param srcHeight the height in pixels to copy from the source
- * @param destX the x coordinate in the destination to copy to
- * @param destY the y coordinate in the destination to copy to
- * @param destWidth the width in pixels of the destination rectangle
- * @param destHeight the height in pixels of the destination rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if any of the width or height arguments are negative.
- * <li>ERROR_INVALID_ARGUMENT - if the source rectangle is not contained within the bounds of the source image</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- */
-public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (srcWidth == 0 || srcHeight == 0 || destWidth == 0 || destHeight == 0) return;
- if (srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 || destWidth < 0 || destHeight < 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- drawImage(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false);
-}
-
-void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
- if (data.updateClip) setCGClipping();
- int imageHandle = srcImage.handle;
- int imgWidth = OS.CGImageGetWidth(imageHandle);
- int imgHeight = OS.CGImageGetHeight(imageHandle);
- if (simple) {
- srcWidth = destWidth = imgWidth;
- srcHeight = destHeight = imgHeight;
- } else {
- simple = srcX == 0 && srcY == 0 &&
- srcWidth == destWidth && destWidth == imgWidth &&
- srcHeight == destHeight && destHeight == imgHeight;
- if (srcX + srcWidth > imgWidth || srcY + srcHeight > imgHeight) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- if (srcImage.memGC != null) srcImage.createAlpha();
- OS.CGContextSaveGState(handle);
- OS.CGContextScaleCTM(handle, 1, -1);
- OS.CGContextTranslateCTM(handle, 0, -(destHeight + 2 * destY));
- CGRect rect = new CGRect();
- rect.x = destX;
- rect.y = destY;
- rect.width = destWidth;
- rect.height = destHeight;
- if (simple) {
- OS.CGContextDrawImage(handle, rect, imageHandle);
- } else {
- int bpc = OS.CGImageGetBitsPerComponent(imageHandle);
- int bpp = OS.CGImageGetBitsPerPixel(imageHandle);
- int bpr = OS.CGImageGetBytesPerRow(imageHandle);
- int colorspace = OS.CGImageGetColorSpace(imageHandle);
- int alphaInfo = OS.CGImageGetAlphaInfo(imageHandle);
- int data = srcImage.data + (srcY * bpr) + srcX * 4;
- int provider = OS.CGDataProviderCreateWithData(0, data, srcHeight * bpr, 0);
- if (provider != 0) {
- int subImage = OS.CGImageCreate(srcWidth, srcHeight, bpc, bpp, bpr, colorspace, alphaInfo, provider, null, true, 0);
- OS.CGDataProviderRelease(provider);
- if (subImage != 0) {
- OS.CGContextDrawImage(handle, rect, subImage);
- OS.CGImageRelease(subImage);
- }
- }
- }
- OS.CGContextRestoreGState(handle);
- flush();
-}
-
-/**
- * Draws a line, using the foreground color, between the points
- * (<code>x1</code>, <code>y1</code>) and (<code>x2</code>, <code>y2</code>).
- *
- * @param x1 the first point's x coordinate
- * @param y1 the first point's y coordinate
- * @param x2 the second point's x coordinate
- * @param y2 the second point's y coordinate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawLine(int x1, int y1, int x2, int y2) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (data.updateClip) setCGClipping();
- if (x1 == x2 && y1 == y2 && data.lineWidth <= 1) {
- drawPoint(x1, y1);
- return;
- }
- OS.CGContextBeginPath(handle);
- float xOffset = data.drawXOffset, yOffset = data.drawYOffset;
- OS.CGContextMoveToPoint(handle, x1 + xOffset, y1 + yOffset);
- OS.CGContextAddLineToPoint(handle, x2 + xOffset, y2 + yOffset);
- OS.CGContextStrokePath(handle);
- flush();
-}
-
-/**
- * Draws the outline of an oval, using the foreground color,
- * within the specified rectangular area.
- * <p>
- * The result is a circle or ellipse that fits within the
- * rectangle specified by the <code>x</code>, <code>y</code>,
- * <code>width</code>, and <code>height</code> arguments.
- * </p><p>
- * The oval covers an area that is <code>width + 1</code>
- * pixels wide and <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper left corner of the oval to be drawn
- * @param y the y coordinate of the upper left corner of the oval to be drawn
- * @param width the width of the oval to be drawn
- * @param height the height of the oval to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawOval(int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (data.updateClip) setCGClipping();
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- OS.CGContextBeginPath(handle);
- OS.CGContextSaveGState(handle);
- float xOffset = data.drawXOffset, yOffset = data.drawYOffset;
- OS.CGContextTranslateCTM(handle, x + xOffset + width / 2f, y + yOffset + height / 2f);
- OS.CGContextScaleCTM(handle, width / 2f, height / 2f);
- OS.CGContextMoveToPoint(handle, 1, 0);
- OS.CGContextAddArc(handle, 0, 0, 1, 0, (float)(2 *Compatibility.PI), true);
- OS.CGContextRestoreGState(handle);
- OS.CGContextStrokePath(handle);
- flush();
-}
-
-/**
- * Draws the path described by the parameter.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the path to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- *
- * @since 3.1
- */
-public void drawPath(Path path) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- checkGC(DRAW);
- if (data.updateClip) setCGClipping();
- OS.CGContextBeginPath(handle);
- OS.CGContextSaveGState(handle);
- float xOffset = data.drawXOffset, yOffset = data.drawYOffset;
- OS.CGContextTranslateCTM(handle, xOffset, yOffset);
- OS.CGContextAddPath(handle, path.handle);
- OS.CGContextRestoreGState(handle);
- OS.CGContextStrokePath(handle);
- flush();
-}
-
-/**
- * Draws a pixel, using the foreground color, at the specified
- * point (<code>x</code>, <code>y</code>).
- * <p>
- * Note that the receiver's line attributes do not affect this
- * operation.
- * </p>
- *
- * @param x the point's x coordinate
- * @param y the point's y coordinate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void drawPoint(int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FOREGROUND_FILL);
- if (data.updateClip) setCGClipping();
- CGRect rect = new CGRect();
- rect.x = x;
- rect.y = y;
- rect.width = 1;
- rect.height = 1;
- OS.CGContextFillRect(handle, rect);
- flush();
-}
-
-/**
- * Draws the closed polygon which is defined by the specified array
- * of integer coordinates, using the receiver's foreground color. The array
- * contains alternating x and y values which are considered to represent
- * points which are the vertices of the polygon. Lines are drawn between
- * each consecutive pair, and between the first pair and last pair in the
- * array.
- *
- * @param pointArray an array of alternating x and y values which are the vertices of the polygon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT if pointArray is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawPolygon(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(DRAW);
- if (data.updateClip) setCGClipping();
- float xOffset = data.drawXOffset, yOffset = data.drawYOffset;
- float[] points = new float[(pointArray.length / 2) * 2];
- for (int i=0; i<points.length; i+=2) {
- points[i] = pointArray[i] + xOffset;
- points[i+1] = pointArray[i+1] + yOffset;
- }
- OS.CGContextBeginPath(handle);
- OS.CGContextAddLines(handle, points, points.length / 2);
- OS.CGContextClosePath(handle);
- OS.CGContextStrokePath(handle);
- flush();
-}
-
-/**
- * Draws the polyline which is defined by the specified array
- * of integer coordinates, using the receiver's foreground color. The array
- * contains alternating x and y values which are considered to represent
- * points which are the corners of the polyline. Lines are drawn between
- * each consecutive pair, but not between the first pair and last pair in
- * the array.
- *
- * @param pointArray an array of alternating x and y values which are the corners of the polyline
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawPolyline(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(DRAW);
- if (data.updateClip) setCGClipping();
- float xOffset = data.drawXOffset, yOffset = data.drawYOffset;
- float[] points = new float[(pointArray.length / 2) * 2];
- for (int i=0; i<points.length; i+=2) {
- points[i] = pointArray[i] + xOffset;
- points[i+1] = pointArray[i+1] + yOffset;
- }
- OS.CGContextBeginPath(handle);
- OS.CGContextAddLines(handle, points, points.length / 2);
- OS.CGContextStrokePath(handle);
- flush();
-}
-
-/**
- * Draws the outline of the rectangle specified by the arguments,
- * using the receiver's foreground color. The left and right edges
- * of the rectangle are at <code>x</code> and <code>x + width</code>.
- * The top and bottom edges are at <code>y</code> and <code>y + height</code>.
- *
- * @param x the x coordinate of the rectangle to be drawn
- * @param y the y coordinate of the rectangle to be drawn
- * @param width the width of the rectangle to be drawn
- * @param height the height of the rectangle to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRectangle(int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (data.updateClip) setCGClipping();
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- CGRect rect = new CGRect();
- float xOffset = data.drawXOffset, yOffset = data.drawYOffset;
- rect.x = x + xOffset;
- rect.y = y + yOffset;
- rect.width = width;
- rect.height = height;
- OS.CGContextStrokeRect(handle, rect);
- flush();
-}
-
-/**
- * Draws the outline of the specified rectangle, using the receiver's
- * foreground color. The left and right edges of the rectangle are at
- * <code>rect.x</code> and <code>rect.x + rect.width</code>. The top
- * and bottom edges are at <code>rect.y</code> and
- * <code>rect.y + rect.height</code>.
- *
- * @param rect the rectangle to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRectangle(Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- drawRectangle (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Draws the outline of the round-cornered rectangle specified by
- * the arguments, using the receiver's foreground color. The left and
- * right edges of the rectangle are at <code>x</code> and <code>x + width</code>.
- * The top and bottom edges are at <code>y</code> and <code>y + height</code>.
- * The <em>roundness</em> of the corners is specified by the
- * <code>arcWidth</code> and <code>arcHeight</code> arguments, which
- * are respectively the width and height of the ellipse used to draw
- * the corners.
- *
- * @param x the x coordinate of the rectangle to be drawn
- * @param y the y coordinate of the rectangle to be drawn
- * @param width the width of the rectangle to be drawn
- * @param height the height of the rectangle to be drawn
- * @param arcWidth the width of the arc
- * @param arcHeight the height of the arc
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (data.updateClip) setCGClipping();
- if (arcWidth == 0 || arcHeight == 0) {
- drawRectangle(x, y, width, height);
- return;
- }
- int nx = x;
- int ny = y;
- int nw = width;
- int nh = height;
- int naw = arcWidth;
- int nah = arcHeight;
- if (nw < 0) {
- nw = 0 - nw;
- nx = nx - nw;
- }
- if (nh < 0) {
- nh = 0 - nh;
- ny = ny - nh;
- }
- if (naw < 0) naw = 0 - naw;
- if (nah < 0) nah = 0 - nah;
- if (naw > nw) naw = nw;
- if (nah > nh) nah = nh;
- float naw2 = naw / 2f;
- float nah2 = nah / 2f;
- float fw = nw / naw2;
- float fh = nh / nah2;
- OS.CGContextBeginPath(handle);
- OS.CGContextSaveGState(handle);
- float xOffset = data.drawXOffset, yOffset = data.drawYOffset;
- OS.CGContextTranslateCTM(handle, nx + xOffset, ny + yOffset);
- OS.CGContextScaleCTM(handle, naw2, nah2);
- OS.CGContextMoveToPoint(handle, fw - 1, 0);
- OS.CGContextAddArcToPoint(handle, 0, 0, 0, 1, 1);
- OS.CGContextAddArcToPoint(handle, 0, fh, 1, fh, 1);
- OS.CGContextAddArcToPoint(handle, fw, fh, fw, fh - 1, 1);
- OS.CGContextAddArcToPoint(handle, fw, 0, fw - 1, 0, 1);
- OS.CGContextClosePath(handle);
- OS.CGContextRestoreGState(handle);
- OS.CGContextStrokePath(handle);
- flush();
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. No tab expansion or carriage return processing
- * will be performed. The background of the rectangular area where
- * the string is being drawn will be filled with the receiver's
- * background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawString (String string, int x, int y) {
- drawString(string, x, y, false);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. No tab expansion or carriage return processing
- * will be performed. If <code>isTransparent</code> is <code>true</code>,
- * then the background of the rectangular area where the string is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawString(String string, int x, int y, boolean isTransparent) {
- drawText(string, x, y, isTransparent ? SWT.DRAW_TRANSPARENT : 0);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion and carriage return processing
- * are performed. The background of the rectangular area where
- * the text is being drawn will be filled with the receiver's
- * background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText(String string, int x, int y) {
- drawText(string, x, y, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion and carriage return processing
- * are performed. If <code>isTransparent</code> is <code>true</code>,
- * then the background of the rectangular area where the text is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText(String string, int x, int y, boolean isTransparent) {
- int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB;
- if (isTransparent) flags |= SWT.DRAW_TRANSPARENT;
- drawText(string, x, y, flags);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion, line delimiter and mnemonic
- * processing are performed according to the specified flags. If
- * <code>flags</code> includes <code>DRAW_TRANSPARENT</code>,
- * then the background of the rectangular area where the text is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- * <p>
- * The parameter <code>flags</code> may be a combination of:
- * <dl>
- * <dt><b>DRAW_DELIMITER</b></dt>
- * <dd>draw multiple lines</dd>
- * <dt><b>DRAW_TAB</b></dt>
- * <dd>expand tabs</dd>
- * <dt><b>DRAW_MNEMONIC</b></dt>
- * <dd>underline the mnemonic character</dd>
- * <dt><b>DRAW_TRANSPARENT</b></dt>
- * <dd>transparent background</dd>
- * </dl>
- * </p>
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param flags the flags specifying how to process the text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText (String string, int x, int y, int flags) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(FONT | FOREGROUND_FILL);
- if (data.updateClip) setCGClipping();
- int length = string.length();
- if (length == 0) return;
- OS.CGContextSaveGState(handle);
- OS.CGContextScaleCTM(handle, 1, -1);
- boolean mode = true;
- switch (data.textAntialias) {
- case SWT.DEFAULT:
- /* Printer is off by default */
- if (data.window == 0 && data.control == 0 && data.image == null) mode = false;
- break;
- case SWT.OFF: mode = false; break;
- }
- OS.CGContextSetShouldAntialias(handle, mode);
- length = setString(string, flags);
- if ((flags & SWT.DRAW_DELIMITER) != 0) {
- int layout = data.layout;
- int[] breakCount = new int[1];
- OS.ATSUGetSoftLineBreaks(layout, 0, length, 0, null, breakCount);
- int[] breaks = new int[breakCount[0] + 1];
- OS.ATSUGetSoftLineBreaks(layout, 0, length, breakCount[0], breaks, breakCount);
- breaks[breakCount[0]] = length;
- for (int i=0, start=0; i<breaks.length; i++) {
- int lineBreak = breaks[i];
- drawText(x, y, start, lineBreak - start, flags);
- y += data.fontAscent + data.fontDescent;
- start = lineBreak;
- }
- } else {
- drawText(x, y, 0, length, flags);
- }
- OS.CGContextRestoreGState(handle);
- flush();
-}
-
-void drawText(int x, int y, int start, int length, int flags) {
- int layout = data.layout;
- if ((flags & SWT.DRAW_TRANSPARENT) == 0) {
- ATSTrapezoid trapezoid = new ATSTrapezoid();
- OS.ATSUGetGlyphBounds(layout, 0, 0, start, length, (short)OS.kATSUseDeviceOrigins, 1, trapezoid, null);
- int width = OS.Fix2Long(trapezoid.lowerRight_x) - OS.Fix2Long(trapezoid.lowerLeft_x);
- int height = OS.Fix2Long(trapezoid.lowerRight_y) - OS.Fix2Long(trapezoid.upperRight_y);
- CGRect rect = new CGRect();
- rect.x = x;
- rect.y = -(y + height);
- rect.width = width;
- rect.height = height;
- OS.CGContextSaveGState(handle);
- Pattern pattern = data.backgroundPattern;
- if (pattern != null) {
- int colorspace = OS.CGColorSpaceCreatePattern(data.device.colorspace);
- OS.CGContextSetFillColorSpace(handle, colorspace);
- OS.CGColorSpaceRelease(colorspace);
- if (data.backPattern == 0) data.backPattern = pattern.createPattern(handle);
- OS.CGContextSetFillPattern(handle, data.backPattern, data.background);
- } else {
- OS.CGContextSetFillColorSpace(handle, data.device.colorspace);
- OS.CGContextSetFillColor(handle, data.background);
- }
- OS.CGContextFillRect(handle, rect);
- OS.CGContextRestoreGState(handle);
- }
- OS.ATSUDrawText(layout, start, length, OS.Long2Fix(x), OS.Long2Fix(-(y + data.fontAscent)));
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals(Object object) {
- if (object == this) return true;
- if (!(object instanceof GC)) return false;
- return handle == ((GC)object).handle;
-}
-
-/**
- * Fills the interior of a circular or elliptical arc within
- * the specified rectangular area, with the receiver's background
- * color.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees, using the current color.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc to be filled
- * @param y the y coordinate of the upper-left corner of the arc to be filled
- * @param width the width of the arc to be filled
- * @param height the height of the arc to be filled
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawArc
- */
-public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (data.updateClip) setCGClipping();
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- OS.CGContextBeginPath(handle);
- OS.CGContextSaveGState(handle);
- OS.CGContextTranslateCTM(handle, x + width / 2f, y + height / 2f);
- OS.CGContextScaleCTM(handle, width / 2f, height / 2f);
- OS.CGContextMoveToPoint(handle, 0, 0);
- if (arcAngle < 0) {
- OS.CGContextAddArc(handle, 0, 0, 1, -(startAngle + arcAngle) * (float)Compatibility.PI / 180, -startAngle * (float)Compatibility.PI / 180, true);
- } else {
- OS.CGContextAddArc(handle, 0, 0, 1, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180, true);
- }
- OS.CGContextClosePath(handle);
- OS.CGContextRestoreGState(handle);
- OS.CGContextFillPath(handle);
- flush();
-}
-
-/**
- * Fills the interior of the specified rectangle with a gradient
- * sweeping from left to right or top to bottom progressing
- * from the receiver's foreground color to its background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled, may be negative
- * (inverts direction of gradient if horizontal)
- * @param height the height of the rectangle to be filled, may be negative
- * (inverts direction of gradient if vertical)
- * @param vertical if true sweeps from top to bottom, else
- * sweeps from left to right
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if ((width == 0) || (height == 0)) return;
-
- /* Rewrite this to use GdkPixbuf */
-
- RGB backgroundRGB, foregroundRGB;
- backgroundRGB = getBackground().getRGB();
- foregroundRGB = getForeground().getRGB();
-
- RGB fromRGB, toRGB;
- fromRGB = foregroundRGB;
- toRGB = backgroundRGB;
- boolean swapColors = false;
- if (width < 0) {
- x += width; width = -width;
- if (! vertical) swapColors = true;
- }
- if (height < 0) {
- y += height; height = -height;
- if (vertical) swapColors = true;
- }
- if (swapColors) {
- fromRGB = backgroundRGB;
- toRGB = foregroundRGB;
- }
- if (fromRGB.equals(toRGB)) {
- fillRectangle(x, y, width, height);
- return;
- }
- ImageData.fillGradientRectangle(this, data.device,
- x, y, width, height, vertical, fromRGB, toRGB,
- 8, 8, 8);
-}
-
-/**
- * Fills the interior of an oval, within the specified
- * rectangular area, with the receiver's background
- * color.
- *
- * @param x the x coordinate of the upper left corner of the oval to be filled
- * @param y the y coordinate of the upper left corner of the oval to be filled
- * @param width the width of the oval to be filled
- * @param height the height of the oval to be filled
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawOval
- */
-public void fillOval(int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (data.updateClip) setCGClipping();
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- OS.CGContextBeginPath(handle);
- OS.CGContextSaveGState(handle);
- OS.CGContextTranslateCTM(handle, x + width / 2f, y + height / 2f);
- OS.CGContextScaleCTM(handle, width / 2f, height / 2f);
- OS.CGContextMoveToPoint(handle, 1, 0);
- OS.CGContextAddArc(handle, 0, 0, 1, 0, (float)(Compatibility.PI * 2), false);
- OS.CGContextClosePath(handle);
- OS.CGContextRestoreGState(handle);
- OS.CGContextFillPath(handle);
- flush();
-}
-
-/**
- * Fills the path described by the parameter.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the path to fill
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- *
- * @since 3.1
- */
-public void fillPath(Path path) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- checkGC(FILL);
- if (data.updateClip) setCGClipping();
- OS.CGContextBeginPath(handle);
- OS.CGContextAddPath(handle, path.handle);
- if (data.fillRule == SWT.FILL_WINDING) {
- OS.CGContextFillPath(handle);
- } else {
- OS.CGContextEOFillPath(handle);
- }
- flush();
-}
-
-/**
- * Fills the interior of the closed polygon which is defined by the
- * specified array of integer coordinates, using the receiver's
- * background color. The array contains alternating x and y values
- * which are considered to represent points which are the vertices of
- * the polygon. Lines are drawn between each consecutive pair, and
- * between the first pair and last pair in the array.
- *
- * @param pointArray an array of alternating x and y values which are the vertices of the polygon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT if pointArray is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawPolygon
- */
-public void fillPolygon(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(FILL);
- if (data.updateClip) setCGClipping();
- float[] points = new float[pointArray.length];
- for (int i=0; i<points.length; i++) {
- points[i] = pointArray[i];
- }
- OS.CGContextBeginPath(handle);
- OS.CGContextAddLines(handle, points, points.length / 2);
- OS.CGContextClosePath(handle);
- if (data.fillRule == SWT.FILL_WINDING) {
- OS.CGContextFillPath(handle);
- } else {
- OS.CGContextEOFillPath(handle);
- }
- flush();
-}
-
-/**
- * Fills the interior of the rectangle specified by the arguments,
- * using the receiver's background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillRectangle(int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (data.updateClip) setCGClipping();
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- CGRect rect = new CGRect();
- rect.x = x;
- rect.y = y;
- rect.width = width;
- rect.height = height;
- Pattern pattern = data.backgroundPattern;
- if (pattern != null) pattern.drawRect = rect;
- OS.CGContextFillRect(handle, rect);
- if (pattern != null) pattern.drawRect = null;
- flush();
-}
-
-/**
- * Fills the interior of the specified rectangle, using the receiver's
- * background color.
- *
- * @param rect the rectangle to be filled
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillRectangle(Rectangle rect) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- fillRectangle(rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Fills the interior of the round-cornered rectangle specified by
- * the arguments, using the receiver's background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- * @param arcWidth the width of the arc
- * @param arcHeight the height of the arc
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRoundRectangle
- */
-public void fillRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (data.updateClip) setCGClipping();
- if (arcWidth == 0 || arcHeight == 0) {
- fillRectangle(x, y, width, height);
- return;
- }
- int nx = x;
- int ny = y;
- int nw = width;
- int nh = height;
- int naw = arcWidth;
- int nah = arcHeight;
- if (nw < 0) {
- nw = 0 - nw;
- nx = nx - nw;
- }
- if (nh < 0) {
- nh = 0 - nh;
- ny = ny - nh;
- }
- if (naw < 0) naw = 0 - naw;
- if (nah < 0) nah = 0 - nah;
- if (naw > nw) naw = nw;
- if (nah > nh) nah = nh;
- float naw2 = naw / 2f;
- float nah2 = nah / 2f;
- float fw = nw / naw2;
- float fh = nh / nah2;
- OS.CGContextBeginPath(handle);
- OS.CGContextSaveGState(handle);
- OS.CGContextTranslateCTM(handle, nx, ny);
- OS.CGContextScaleCTM(handle, naw2, nah2);
- OS.CGContextMoveToPoint(handle, fw - 1, 0);
- OS.CGContextAddArcToPoint(handle, 0, 0, 0, 1, 1);
- OS.CGContextAddArcToPoint(handle, 0, fh, 1, fh, 1);
- OS.CGContextAddArcToPoint(handle, fw, fh, fw, fh - 1, 1);
- OS.CGContextAddArcToPoint(handle, fw, 0, fw - 1, 0, 1);
- OS.CGContextClosePath(handle);
- OS.CGContextRestoreGState(handle);
- OS.CGContextFillPath(handle);
- flush();
-}
-
-void flush () {
- if (data.control != 0 && data.paintEvent == 0) {
- if (data.thread != Thread.currentThread()) {
- OS.CGContextFlush(handle);
- } else {
- OS.CGContextSynchronize(handle);
- }
- }
- if (data.control == 0 && data.window != 0) OS.CGContextSynchronize(handle);
-}
-
-/**
- * Returns the <em>advance width</em> of the specified character in
- * the font which is currently selected into the receiver.
- * <p>
- * The advance width is defined as the horizontal distance the cursor
- * should move after printing the character in the selected font.
- * </p>
- *
- * @param ch the character to measure
- * @return the distance in the x direction to move past the character before painting the next
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getAdvanceWidth(char ch) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- //NOT DONE
- return stringExtent(new String(new char[]{ch})).x;
-}
-
-/**
- * Returns the background color.
- *
- * @return the receiver's background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getBackground() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return Color.carbon_new (data.device, data.background);
-}
-
-/**
- * Returns the background pattern. The default value is
- * <code>null</code>.
- *
- * @return the receiver's background pattern
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Pattern
- *
- * @since 3.1
- */
-public Pattern getBackgroundPattern() {
- if (handle == 0) SWT.error(SWT.ERROR_WIDGET_DISPOSED);
- return data.backgroundPattern;
-}
-
-/**
- * Returns <code>true</code> if receiver is using the operating system's
- * advanced graphics subsystem. Otherwise, <code>false</code> is returned
- * to indicate that normal graphics are in use.
- * <p>
- * Advanced graphics may not be installed for the operating system. In this
- * case, <code>false</code> is always returned. Some operating system have
- * only one graphics subsystem. If this subsystem supports advanced graphics,
- * then <code>true</code> is always returned. If any graphics operation such
- * as alpha, antialias, patterns, interpolation, paths, clipping or transformation
- * has caused the receiver to switch from regular to advanced graphics mode,
- * <code>true</code> is returned. If the receiver has been explicitly switched
- * to advanced mode and this mode is supported, <code>true</code> is returned.
- * </p>
- *
- * @return the advanced value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public boolean getAdvanced() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return true;
-}
-
-/**
- * Returns the receiver's alpha value. The alpha value
- * is between 0 (transparent) and 255 (opaque).
- *
- * @return the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getAlpha() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.alpha;
-}
-
-/**
- * Returns the receiver's anti-aliasing setting value, which will be
- * one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code>. Note that this controls anti-aliasing for all
- * <em>non-text drawing</em> operations.
- *
- * @return the anti-aliasing setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getTextAntialias
- *
- * @since 3.1
- */
-public int getAntialias() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.antialias;
-}
-
-/**
- * Returns the width of the specified character in the font
- * selected into the receiver.
- * <p>
- * The width is defined as the space taken up by the actual
- * character, not including the leading and tailing whitespace
- * or overhang.
- * </p>
- *
- * @param ch the character to measure
- * @return the width of the character
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getCharWidth(char ch) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- //NOT DONE
- return stringExtent(new String(new char[]{ch})).x;
-}
-
-/**
- * Returns the bounding rectangle of the receiver's clipping
- * region. If no clipping region is set, the return value
- * will be a rectangle which covers the entire bounds of the
- * object the receiver is drawing on.
- *
- * @return the bounding rectangle of the clipping region
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getClipping() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- /* Calculate visible bounds in device space*/
- Rect rect = null;
- int x = 0, y = 0, width = 0, height = 0;
- if (data.control != 0) {
- if (rect == null) rect = new Rect();
- OS.GetControlBounds(data.control, rect);
- width = rect.right - rect.left;
- height = rect.bottom - rect.top;
- } else {
- if (data.image != null) {
- int image = data.image.handle;
- width = OS.CGImageGetWidth(image);
- height = OS.CGImageGetHeight(image);
- } else if (data.portRect != null) {
- width = data.portRect.right - data.portRect.left;
- height = data.portRect.bottom - data.portRect.top;
- }
- }
- /* Intersect visible bounds with clipping in device space and then convert the user space */
- int clipRgn = data.clipRgn;
- int visibleRgn = data.visibleRgn;
- if (clipRgn != 0 || visibleRgn != 0 || data.inverseTransform != null) {
- int rgn = OS.NewRgn();
- OS.SetRectRgn(rgn, (short)x, (short)y, (short)(x + width), (short)(y + height));
- if (visibleRgn != 0) {
- OS.SectRgn(rgn, visibleRgn, rgn);
- }
- /* Intersect visible bounds with clipping */
- if (clipRgn != 0) {
- /* Convert clipping to device space if needed */
- if (data.clippingTransform != null) {
- clipRgn = convertRgn(clipRgn, data.clippingTransform);
- OS.SectRgn(rgn, clipRgn, rgn);
- OS.DisposeRgn(clipRgn);
- } else {
- OS.SectRgn(rgn, clipRgn, rgn);
- }
- }
- /* Convert to user space */
- if (data.inverseTransform != null) {
- clipRgn = convertRgn(rgn, data.inverseTransform);
- OS.DisposeRgn(rgn);
- rgn = clipRgn;
- }
- if (rect == null) rect = new Rect();
- OS.GetRegionBounds(rgn, rect);
- OS.DisposeRgn(rgn);
- x = rect.left;
- y = rect.top;
- width = rect.right - rect.left;
- height = rect.bottom - rect.top;
- }
- return new Rectangle(x, y, width, height);
-}
-
-/**
- * Sets the region managed by the argument to the current
- * clipping region of the receiver.
- *
- * @param region the region to fill with the clipping region
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the region is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the region is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getClipping(Region region) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Rect bounds = null;
- int clipping = region.handle;
- if (data.clipRgn == 0) {
- int width = 0, height = 0;
- if (data.control != 0) {
- if (bounds == null) bounds = new Rect();
- OS.GetControlBounds(data.control, bounds);
- width = bounds.right - bounds.left;
- height = bounds.bottom - bounds.top;
- } else {
- if (data.image != null) {
- int image = data.image.handle;
- width = OS.CGImageGetWidth(image);
- height = OS.CGImageGetHeight(image);
- } else if (data.portRect != null) {
- width = data.portRect.right - data.portRect.left;
- height = data.portRect.bottom - data.portRect.top;
- }
- }
- OS.SetRectRgn(clipping, (short)0, (short)0, (short)width, (short)height);
- } else {
- /* Convert clipping to device space if needed */
- if (data.clippingTransform != null) {
- int rgn = convertRgn(data.clipRgn, data.clippingTransform);
- OS.CopyRgn(rgn, clipping);
- OS.DisposeRgn(rgn);
- } else {
- OS.CopyRgn(data.clipRgn, clipping);
- }
- }
- if (data.paintEvent != 0 && data.visibleRgn != 0) {
- if (bounds == null) bounds = new Rect();
- OS.GetControlBounds(data.control, bounds);
- if (data.paintEvent == 0) OS.OffsetRgn(data.visibleRgn, (short)-bounds.left, (short)-bounds.top);
- OS.SectRgn(data.visibleRgn, clipping, clipping);
- if (data.paintEvent == 0) OS.OffsetRgn(data.visibleRgn, bounds.left, bounds.top);
- }
- /* Convert to user space */
- if (data.inverseTransform != null) {
- int rgn = convertRgn(clipping, data.inverseTransform);
- OS.CopyRgn(rgn, clipping);
- OS.DisposeRgn(rgn);
- }
-}
-
-/**
- * Returns the receiver's fill rule, which will be one of
- * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>.
- *
- * @return the receiver's fill rule
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getFillRule() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.fillRule;
-}
-
-/**
- * Returns the font currently being used by the receiver
- * to draw and measure text.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getFont() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.font;
-}
-
-/**
- * Returns a FontMetrics which contains information
- * about the font currently being used by the receiver
- * to draw and measure text.
- *
- * @return font metrics for the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontMetrics getFontMetrics() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FONT);
- Font font = data.font;
- ATSFontMetrics metrics = new ATSFontMetrics();
- OS.ATSFontGetVerticalMetrics(font.handle, OS.kATSOptionFlagsDefault, metrics);
- OS.ATSFontGetHorizontalMetrics(font.handle, OS.kATSOptionFlagsDefault, metrics);
- int ascent = (int)(0.5f + metrics.ascent * font.size);
- int descent = (int)(0.5f + (-metrics.descent + metrics.leading) * font.size);
- String s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- int averageCharWidth = stringExtent(s).x / s.length();
- return FontMetrics.carbon_new(ascent, descent, averageCharWidth, 0, ascent + descent);
-}
-
-/**
- * Returns the receiver's foreground color.
- *
- * @return the color used for drawing foreground things
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getForeground() {
- if (handle == 0) SWT.error(SWT.ERROR_WIDGET_DISPOSED);
- return Color.carbon_new(data.device, data.foreground);
-}
-
-/**
- * Returns the foreground pattern. The default value is
- * <code>null</code>.
- *
- * @return the receiver's foreground pattern
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Pattern
- *
- * @since 3.1
- */
-public Pattern getForegroundPattern() {
- if (handle == 0) SWT.error(SWT.ERROR_WIDGET_DISPOSED);
- return data.foregroundPattern;
-}
-
-/**
- * Returns the GCData.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>GC</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @return the receiver's GCData
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see GCData
- *
- * @since 3.2
- * @noreference This method is not intended to be referenced by clients.
- */
-public GCData getGCData() {
- if (handle == 0) SWT.error(SWT.ERROR_WIDGET_DISPOSED);
- return data;
-}
-
-/**
- * Returns the receiver's interpolation setting, which will be one of
- * <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>,
- * <code>SWT.LOW</code> or <code>SWT.HIGH</code>.
- *
- * @return the receiver's interpolation setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getInterpolation() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int interpolation = OS.CGContextGetInterpolationQuality(handle);
- switch (interpolation) {
- case OS.kCGInterpolationDefault: return SWT.DEFAULT;
- case OS.kCGInterpolationNone: return SWT.NONE;
- case OS.kCGInterpolationLow: return SWT.LOW;
- case OS.kCGInterpolationHigh: return SWT.HIGH;
- }
- return SWT.DEFAULT;
-}
-
-/**
- * Returns the receiver's line attributes.
- *
- * @return the line attributes used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.3
- */
-public LineAttributes getLineAttributes() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float[] dashes = null;
- if (data.lineDashes != null) {
- dashes = new float[data.lineDashes.length];
- System.arraycopy(data.lineDashes, 0, dashes, 0, dashes.length);
- }
- return new LineAttributes(data.lineWidth, data.lineCap, data.lineJoin, data.lineStyle, dashes, data.lineDashesOffset, data.lineMiterLimit);
-}
-
-/**
- * Returns the receiver's line cap style, which will be one
- * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>,
- * or <code>SWT.CAP_SQUARE</code>.
- *
- * @return the cap style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getLineCap() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineCap;
-}
-
-/**
- * Returns the receiver's line dash style. The default value is
- * <code>null</code>.
- *
- * @return the line dash style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int[] getLineDash() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineDashes == null) return null;
- int[] lineDashes = new int[data.lineDashes.length];
- for (int i = 0; i < lineDashes.length; i++) {
- lineDashes[i] = (int)data.lineDashes[i];
- }
- return lineDashes;
-}
-
-/**
- * Returns the receiver's line join style, which will be one
- * of the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>,
- * or <code>SWT.JOIN_BEVEL</code>.
- *
- * @return the join style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getLineJoin() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineJoin;
-}
-
-/**
- * Returns the receiver's line style, which will be one
- * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
- * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or
- * <code>SWT.LINE_DASHDOTDOT</code>.
- *
- * @return the style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineStyle() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineStyle;
-}
-
-/**
- * Returns the width that will be used when drawing lines
- * for all of the figure drawing operations (that is,
- * <code>drawLine</code>, <code>drawRectangle</code>,
- * <code>drawPolyline</code>, and so forth.
- *
- * @return the receiver's line width
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineWidth() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (int)data.lineWidth;
-}
-
-/**
- * Returns the receiver's style information.
- * <p>
- * Note that the value which is returned by this method <em>may
- * not match</em> the value which was provided to the constructor
- * when the receiver was created. This can occur when the underlying
- * operating system does not support a particular combination of
- * requested styles.
- * </p>
- *
- * @return the style bits
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getStyle () {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.style;
-}
-
-/**
- * Returns the receiver's text drawing anti-aliasing setting value,
- * which will be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code>. Note that this controls anti-aliasing
- * <em>only</em> for text drawing operations.
- *
- * @return the anti-aliasing setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getAntialias
- *
- * @since 3.1
- */
-public int getTextAntialias() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.textAntialias;
-}
-
-/**
- * Sets the parameter to the transform that is currently being
- * used by the receiver.
- *
- * @param transform the destination to copy the transform into
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Transform
- *
- * @since 3.1
- */
-public void getTransform (Transform transform) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transform == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- float[] cmt = data.transform;
- if (cmt != null) {
- transform.setElements(cmt[0], cmt[1], cmt[2], cmt[3], cmt[4], cmt[5]);
- } else {
- transform.setElements(1, 0, 0, 1, 0, 0);
- }
-}
-
-/**
- * Returns <code>true</code> if this GC is drawing in the mode
- * where the resulting color in the destination is the
- * <em>exclusive or</em> of the color values in the source
- * and the destination, and <code>false</code> if it is
- * drawing in the mode where the destination color is being
- * replaced with the source color value.
- *
- * @return <code>true</code> true if the receiver is in XOR mode, and false otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean getXORMode() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.xorMode;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #equals
- */
-public int hashCode() {
- return handle;
-}
-
-void init(Drawable drawable, GCData data, int context) {
- if (data.foreground != null) data.state &= ~(FOREGROUND | FOREGROUND_FILL);
- if (data.background != null) data.state &= ~BACKGROUND;
- if (data.font != null) data.state &= ~FONT;
- data.state &= ~DRAW_OFFSET;
-
- Image image = data.image;
- if (image != null) image.memGC = this;
- this.drawable = drawable;
- this.data = data;
- handle = context;
-
-}
-
-/**
- * Returns <code>true</code> if the receiver has a clipping
- * region set into it, and <code>false</code> otherwise.
- * If this method returns false, the receiver will draw on all
- * available space in the destination. If it returns true,
- * it will draw only in the area that is covered by the region
- * that can be accessed with <code>getClipping(region)</code>.
- *
- * @return <code>true</code> if the GC has a clipping region, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean isClipped() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.clipRgn != 0;
-}
-
-/**
- * Returns <code>true</code> if the GC has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the GC.
- * When a GC has been disposed, it is an error to
- * invoke any other method using the GC.
- *
- * @return <code>true</code> when the GC is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-boolean isIdentity(float[] transform) {
- return transform[0] == 1 && transform[1] == 0 && transform[2] == 0
- && transform[3] == 1 && transform[4] == 0 && transform[5] == 0;
-}
-
-/**
- * Sets the receiver to always use the operating system's advanced graphics
- * subsystem for all graphics operations if the argument is <code>true</code>.
- * If the argument is <code>false</code>, the advanced graphics subsystem is
- * no longer used, advanced graphics state is cleared and the normal graphics
- * subsystem is used from now on.
- * <p>
- * Normally, the advanced graphics subsystem is invoked automatically when
- * any one of the alpha, antialias, patterns, interpolation, paths, clipping
- * or transformation operations in the receiver is requested. When the receiver
- * is switched into advanced mode, the advanced graphics subsystem performs both
- * advanced and normal graphics operations. Because the two subsystems are
- * different, their output may differ. Switching to advanced graphics before
- * any graphics operations are performed ensures that the output is consistent.
- * </p><p>
- * Advanced graphics may not be installed for the operating system. In this
- * case, this operation does nothing. Some operating system have only one
- * graphics subsystem, so switching from normal to advanced graphics does
- * nothing. However, switching from advanced to normal graphics will always
- * clear the advanced graphics state, even for operating systems that have
- * only one graphics subsystem.
- * </p>
- *
- * @param advanced the new advanced graphics state
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAlpha
- * @see #setAntialias
- * @see #setBackgroundPattern
- * @see #setClipping(Path)
- * @see #setForegroundPattern
- * @see #setLineAttributes
- * @see #setInterpolation
- * @see #setTextAntialias
- * @see #setTransform
- * @see #getAdvanced
- *
- * @since 3.1
- */
-public void setAdvanced(boolean advanced) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (!advanced) {
- setAlpha(0xFF);
- setAntialias(SWT.DEFAULT);
- setBackgroundPattern(null);
- setClipping(0);
- setForegroundPattern(null);
- setInterpolation(SWT.DEFAULT);
- setTextAntialias(SWT.DEFAULT);
- setTransform(null);
- }
-}
-
-/**
- * Sets the receiver's alpha value which must be
- * between 0 (transparent) and 255 (opaque).
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param alpha the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setAlpha(int alpha) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- data.alpha = alpha & 0xFF;
- OS.CGContextSetAlpha(handle, data.alpha / 255f);
-}
-
-/**
- * Sets the receiver's anti-aliasing value to the parameter,
- * which must be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code>
- * or <code>SWT.ON</code>. Note that this controls anti-aliasing for all
- * <em>non-text drawing</em> operations.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param antialias the anti-aliasing setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.OFF</code> or <code>SWT.ON</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- * @see #setTextAntialias
- *
- * @since 3.1
- */
-public void setAntialias(int antialias) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- boolean mode = true;
- switch (antialias) {
- case SWT.DEFAULT:
- /* Printer is off by default */
- if (data.window == 0 && data.control == 0 && data.image == null) mode = false;
- break;
- case SWT.OFF: mode = false; break;
- case SWT.ON: mode = true; break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.antialias = antialias;
- OS.CGContextSetShouldAntialias(handle, mode);
-}
-
-/**
- * Sets the background color. The background color is used
- * for fill operations and as the background color when text
- * is drawn.
- *
- * @param color the new background color for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setBackground(Color color) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.background = color.handle;
- if (data.backPattern != 0) OS.CGPatternRelease(data.backPattern);
- data.backPattern = 0;
- data.backgroundPattern = null;
- data.state &= ~BACKGROUND;
-}
-
-/**
- * Sets the background pattern. The default value is <code>null</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param pattern the new background pattern
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Pattern
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setBackgroundPattern(Pattern pattern) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.backgroundPattern == pattern) return;
- if (data.backPattern != 0) OS.CGPatternRelease(data.backPattern);
- data.backPattern = 0;
- data.backgroundPattern = pattern;
- data.state &= ~BACKGROUND;
-}
-
-void setClipping(int clipRgn) {
- if (clipRgn == 0) {
- if (data.clipRgn != 0) {
- OS.DisposeRgn(data.clipRgn);
- data.clipRgn = 0;
- }
- data.clippingTransform = null;
- } else {
- if (data.clipRgn == 0) data.clipRgn = OS.NewRgn();
- OS.CopyRgn(clipRgn, data.clipRgn);
- if (data.transform != null) {
- if (data.clippingTransform == null) data.clippingTransform = new float[6];
- System.arraycopy(data.transform, 0, data.clippingTransform, 0, data.transform.length);
- }
- }
- data.updateClip = true;
- setCGClipping();
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the rectangular area specified
- * by the arguments.
- *
- * @param x the x coordinate of the clipping rectangle
- * @param y the y coordinate of the clipping rectangle
- * @param width the width of the clipping rectangle
- * @param height the height of the clipping rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping(int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int clipRgn = OS.NewRgn();
- OS.SetRectRgn(clipRgn, (short)x, (short)y, (short)(x + width), (short)(y + height));
- setClipping(clipRgn);
- OS.DisposeRgn(clipRgn);
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the path specified
- * by the argument.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the clipping path.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the path has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setClipping(Path path) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path != null && path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- setClipping(0);
- if (path != null) {
- OS.CGContextAddPath(handle, path.handle);
- OS.CGContextEOClip(handle);
- }
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the rectangular area specified
- * by the argument. Specifying <code>null</code> for the
- * rectangle reverts the receiver's clipping area to its
- * original value.
- *
- * @param rect the clipping rectangle or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping(Rectangle rect) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) {
- setClipping(0);
- } else {
- setClipping(rect.x, rect.y, rect.width, rect.height);
- }
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the region specified
- * by the argument. Specifying <code>null</code> for the
- * region reverts the receiver's clipping area to its
- * original value.
- *
- * @param region the clipping region or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping(Region region) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region != null && region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- setClipping(region != null ? region.handle : 0);
-}
-
-void setCGClipping () {
- data.updateClip = false;
- if (data.control == 0) {
- if (data.window != 0 && ! OS.IsWindowVisible(data.window)) OS.ShowWindow (data.window);
- OS.CGContextScaleCTM(handle, 1, -1);
- if (data.clipRgn != 0) {
- OS.ClipCGContextToRegion(handle, new Rect(), data.clipRgn);
- } else {
- int rgn = OS.NewRgn();
- OS.SetRectRgn(rgn, (short)-32768, (short)-32768, (short)32767, (short)32767);
- OS.ClipCGContextToRegion(handle, new Rect(), rgn);
- OS.DisposeRgn(rgn);
- }
- OS.CGContextScaleCTM(handle, 1, -1);
- return;
- }
- int port = data.port;
- int window = OS.GetControlOwner(data.control);
- if (port == 0) {
- port = OS.GetWindowPort(window);
- }
- Rect portRect = data.portRect;
- Rect rect = data.controlRect;
- OS.CGContextTranslateCTM(handle, -rect.left, (portRect.bottom - portRect.top) - rect.top);
- OS.CGContextScaleCTM(handle, 1, -1);
- OS.GetPortBounds(port, portRect);
- OS.GetControlBounds(data.control, rect);
- boolean isPaint = data.paintEvent != 0;
- if (isPaint) {
- rect.right += rect.left;
- rect.bottom += rect.top;
- rect.left = rect.top = 0;
- } else {
- int [] contentView = new int [1];
- OS.HIViewFindByID (OS.HIViewGetRoot (window), OS.kHIViewWindowContentID (), contentView);
- CGPoint pt = new CGPoint ();
- OS.HIViewConvertPoint (pt, OS.HIViewGetSuperview (data.control), contentView [0]);
- rect.left += (int) pt.x;
- rect.top += (int) pt.y;
- rect.right += (int) pt.x;
- rect.bottom += (int) pt.y;
- }
- if (data.clipRgn != 0) {
- int rgn = OS.NewRgn();
- OS.CopyRgn(data.clipRgn, rgn);
- OS.OffsetRgn(rgn, rect.left, rect.top);
- OS.SectRgn(data.visibleRgn, rgn, rgn);
- OS.ClipCGContextToRegion(handle, portRect, rgn);
- OS.DisposeRgn(rgn);
- } else {
- OS.ClipCGContextToRegion(handle, portRect, data.visibleRgn);
- }
- OS.CGContextScaleCTM(handle, 1, -1);
- OS.CGContextTranslateCTM(handle, rect.left, -(portRect.bottom - portRect.top) + rect.top);
-}
-
-void setCGFont() {
- int tabs = data.tabs;
- if (tabs != 0) OS.DisposePtr(tabs);
- data.tabs = 0;
- Font font = data.font;
- ATSFontMetrics metrics = new ATSFontMetrics();
- OS.ATSFontGetVerticalMetrics(font.handle, OS.kATSOptionFlagsDefault, metrics);
- OS.ATSFontGetHorizontalMetrics(font.handle, OS.kATSOptionFlagsDefault, metrics);
- data.fontAscent = (int)(0.5f + metrics.ascent * font.size);
- data.fontDescent = (int)(0.5f + (-metrics.descent + metrics.leading) * font.size);
- if (font.atsuiStyle == 0) {
- if (data.atsuiStyle != 0) OS.ATSUDisposeStyle(data.atsuiStyle);
- data.atsuiStyle = font.createStyle();
- }
- data.string = null;
- data.stringWidth = data.stringHeight = -1;
-}
-
-/**
- * Sets the receiver's fill rule to the parameter, which must be one of
- * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>.
- *
- * @param rule the new fill rule
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of <code>SWT.FILL_EVEN_ODD</code>
- * or <code>SWT.FILL_WINDING</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setFillRule(int rule) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (rule) {
- case SWT.FILL_WINDING:
- case SWT.FILL_EVEN_ODD: break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.fillRule = rule;
-}
-
-/**
- * Sets the font which will be used by the receiver
- * to draw and measure text to the argument. If the
- * argument is null, then a default font appropriate
- * for the platform will be used instead.
- *
- * @param font the new font for the receiver, or null to indicate a default font
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setFont(Font font) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.font = font != null ? font : data.device.systemFont;
- data.state &= ~FONT;
-}
-
-/**
- * Sets the foreground color. The foreground color is used
- * for drawing operations including when text is drawn.
- *
- * @param color the new foreground color for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setForeground(Color color) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.foreground = color.handle;
- if (data.forePattern != 0) OS.CGPatternRelease(data.forePattern);
- data.forePattern = 0;
- data.foregroundPattern = null;
- data.state &= ~(FOREGROUND | FOREGROUND_FILL);
-}
-
-/**
- * Sets the foreground pattern. The default value is <code>null</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param pattern the new foreground pattern
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Pattern
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setForegroundPattern(Pattern pattern) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.foregroundPattern == pattern) return;
- if (data.forePattern != 0) OS.CGPatternRelease(data.forePattern);
- data.forePattern = 0;
- data.foregroundPattern = pattern;
- data.state &= ~(FOREGROUND | FOREGROUND_FILL);
-}
-
-/**
- * Sets the receiver's interpolation setting to the parameter, which
- * must be one of <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>,
- * <code>SWT.LOW</code> or <code>SWT.HIGH</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param interpolation the new interpolation setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.NONE</code>, <code>SWT.LOW</code> or <code>SWT.HIGH</code>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setInterpolation(int interpolation) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int quality = 0;
- switch (interpolation) {
- case SWT.DEFAULT: quality = OS.kCGInterpolationDefault; break;
- case SWT.NONE: quality = OS.kCGInterpolationNone; break;
- case SWT.LOW: quality = OS.kCGInterpolationLow; break;
- case SWT.HIGH: quality = OS.kCGInterpolationHigh; break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- OS.CGContextSetInterpolationQuality(handle, quality);
-}
-
-/**
- * Sets the receiver's line attributes.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param attributes the line attributes
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the attributes is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if any of the line attributes is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see LineAttributes
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.3
- */
-public void setLineAttributes(LineAttributes attributes) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (attributes == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int mask = 0;
- float lineWidth = attributes.width;
- if (lineWidth != data.lineWidth) {
- mask |= LINE_WIDTH | DRAW_OFFSET;
- }
- int lineStyle = attributes.style;
- if (lineStyle != data.lineStyle) {
- mask |= LINE_STYLE;
- switch (lineStyle) {
- case SWT.LINE_SOLID:
- case SWT.LINE_DASH:
- case SWT.LINE_DOT:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- break;
- case SWT.LINE_CUSTOM:
- if (attributes.dash == null) lineStyle = SWT.LINE_SOLID;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- int join = attributes.join;
- if (join != data.lineJoin) {
- mask |= LINE_JOIN;
- switch (join) {
- case SWT.CAP_ROUND:
- case SWT.CAP_FLAT:
- case SWT.CAP_SQUARE:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- int cap = attributes.cap;
- if (cap != data.lineCap) {
- mask |= LINE_CAP;
- switch (cap) {
- case SWT.JOIN_MITER:
- case SWT.JOIN_ROUND:
- case SWT.JOIN_BEVEL:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- float[] dashes = attributes.dash;
- float[] lineDashes = data.lineDashes;
- if (dashes != null && dashes.length > 0) {
- boolean changed = lineDashes == null || lineDashes.length != dashes.length;
- for (int i = 0; i < dashes.length; i++) {
- float dash = dashes[i];
- if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (!changed && lineDashes[i] != dash) changed = true;
- }
- if (changed) {
- float[] newDashes = new float[dashes.length];
- System.arraycopy(dashes, 0, newDashes, 0, dashes.length);
- dashes = newDashes;
- mask |= LINE_STYLE;
- } else {
- dashes = lineDashes;
- }
- } else {
- if (lineDashes != null && lineDashes.length > 0) {
- mask |= LINE_STYLE;
- } else {
- dashes = lineDashes;
- }
- }
- float dashOffset = attributes.dashOffset;
- if (dashOffset != data.lineDashesOffset) {
- mask |= LINE_STYLE;
- }
- float miterLimit = attributes.miterLimit;
- if (miterLimit != data.lineMiterLimit) {
- mask |= LINE_MITERLIMIT;
- }
- if (mask == 0) return;
- data.lineWidth = lineWidth;
- data.lineStyle = lineStyle;
- data.lineCap = cap;
- data.lineJoin = join;
- data.lineDashes = dashes;
- data.lineDashesOffset = dashOffset;
- data.lineMiterLimit = miterLimit;
- data.state &= ~mask;
-}
-
-/**
- * Sets the receiver's line cap style to the argument, which must be one
- * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>,
- * or <code>SWT.CAP_SQUARE</code>.
- *
- * @param cap the cap style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineCap(int cap) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineCap == cap) return;
- switch (cap) {
- case SWT.CAP_ROUND:
- case SWT.CAP_FLAT:
- case SWT.CAP_SQUARE:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineCap = cap;
- data.state &= ~LINE_CAP;
-}
-
-/**
- * Sets the receiver's line dash style to the argument. The default
- * value is <code>null</code>. If the argument is not <code>null</code>,
- * the receiver's line style is set to <code>SWT.LINE_CUSTOM</code>, otherwise
- * it is set to <code>SWT.LINE_SOLID</code>.
- *
- * @param dashes the dash style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if any of the values in the array is less than or equal 0</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineDash(int[] dashes) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float[] lineDashes = data.lineDashes;
- if (dashes != null && dashes.length > 0) {
- boolean changed = data.lineStyle != SWT.LINE_CUSTOM || lineDashes == null || lineDashes.length != dashes.length;
- for (int i = 0; i < dashes.length; i++) {
- int dash = dashes[i];
- if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (!changed && lineDashes[i] != dash) changed = true;
- }
- if (!changed) return;
- data.lineDashes = new float[dashes.length];
- for (int i = 0; i < dashes.length; i++) {
- data.lineDashes[i] = dashes[i];
- }
- data.lineStyle = SWT.LINE_CUSTOM;
- } else {
- if (data.lineStyle == SWT.LINE_SOLID && (lineDashes == null || lineDashes.length == 0)) return;
- data.lineDashes = null;
- data.lineStyle = SWT.LINE_SOLID;
- }
- data.state &= ~LINE_STYLE;
-}
-
-/**
- * Sets the receiver's line join style to the argument, which must be one
- * of the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>,
- * or <code>SWT.JOIN_BEVEL</code>.
- *
- * @param join the join style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineJoin(int join) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineJoin == join) return;
- switch (join) {
- case SWT.JOIN_MITER:
- case SWT.JOIN_ROUND:
- case SWT.JOIN_BEVEL:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineJoin = join;
- data.state &= ~LINE_JOIN;
-}
-
-/**
- * Sets the receiver's line style to the argument, which must be one
- * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
- * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or
- * <code>SWT.LINE_DASHDOTDOT</code>.
- *
- * @param lineStyle the style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setLineStyle(int lineStyle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineStyle == lineStyle) return;
- switch (lineStyle) {
- case SWT.LINE_SOLID:
- case SWT.LINE_DASH:
- case SWT.LINE_DOT:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- break;
- case SWT.LINE_CUSTOM:
- if (data.lineDashes == null) lineStyle = SWT.LINE_SOLID;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineStyle = lineStyle;
- data.state &= ~LINE_STYLE;
-}
-
-/**
- * Sets the width that will be used when drawing lines
- * for all of the figure drawing operations (that is,
- * <code>drawLine</code>, <code>drawRectangle</code>,
- * <code>drawPolyline</code>, and so forth.
- * <p>
- * Note that line width of zero is used as a hint to
- * indicate that the fastest possible line drawing
- * algorithms should be used. This means that the
- * output may be different from line width one.
- * </p>
- *
- * @param lineWidth the width of a line
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setLineWidth(int lineWidth) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineWidth == lineWidth) return;
- data.lineWidth = lineWidth;
- data.state &= ~(LINE_WIDTH | DRAW_OFFSET);
-}
-
-int setString(String string, int flags) {
- if (data.layout == 0) createLayout ();
- if (string == data.string && (flags & ~SWT.DRAW_TRANSPARENT) == (data.drawFlags & ~SWT.DRAW_TRANSPARENT)) {
- return data.stringLength;
- }
- int layout = data.layout;
- int length = string.length();
- char[] chars = new char[length];
- string.getChars(0, length, chars, 0);
- int breakCount = 0;
- int[] breaks = null;
- if ((flags & (SWT.DRAW_MNEMONIC | SWT.DRAW_DELIMITER)) != 0) {
- int i=0, j=0;
- while (i < chars.length) {
- char c = chars [j++] = chars [i++];
- switch (c) {
- case '&': {
- if ((flags & SWT.DRAW_MNEMONIC) != 0) {
- if (i == chars.length) {continue;}
- if (chars [i] == '&') {i++; continue;}
- j--;
- }
- break;
- }
- case '\r':
- case '\n': {
- if ((flags & SWT.DRAW_DELIMITER) != 0) {
- if (c == '\r' && i != chars.length && chars[i] == '\n') i++;
- j--;
- if (breaks == null) {
- breaks = new int[4];
- } else if (breakCount == breaks.length) {
- int[] newBreaks = new int[breaks.length + 4];
- System.arraycopy(breaks, 0, newBreaks, 0, breaks.length);
- breaks = newBreaks;
- }
- breaks[breakCount++] = j;
- }
- break;
- }
- }
- }
- length = j;
- }
- if ((flags & SWT.DRAW_TAB) != 0) {
- if (data.tabs == 0) createTabs();
- OS.ATSUSetTabArray(layout, data.tabs, TAB_COUNT);
- } else {
- OS.ATSUSetTabArray(layout, 0, 0);
- }
- int ptr = OS.NewPtr(length * 2);
- OS.memmove(ptr, chars, length * 2);
- OS.ATSUSetTextPointerLocation(layout, ptr, 0, length, length);
- if ((flags & SWT.DRAW_DELIMITER) != 0 && breaks != null) {
- for (int i=0; i<breakCount; i++) {
- OS.ATSUSetSoftLineBreak(layout, breaks[i]);
- }
- }
- Font font = data.font;
- int atsuiStyle = font.atsuiStyle != 0 ? font.atsuiStyle : data.atsuiStyle;
- OS.ATSUSetRunStyle(layout, atsuiStyle, 0, length);
- OS.ATSUSetTransientFontMatching(layout, true);
- if (data.stringPtr != 0) OS.DisposePtr(data.stringPtr);
- data.stringPtr = ptr;
- data.string = string;
- data.stringLength = length;
- data.stringWidth = data.stringHeight = -1;
- data.drawFlags = flags;
- return length;
-}
-
-/**
- * If the argument is <code>true</code>, puts the receiver
- * in a drawing mode where the resulting color in the destination
- * is the <em>exclusive or</em> of the color values in the source
- * and the destination, and if the argument is <code>false</code>,
- * puts the receiver in a drawing mode where the destination color
- * is replaced with the source color value.
- * <p>
- * Note that this mode in fundamentally unsupportable on certain
- * platforms, notably Carbon (Mac OS X). Clients that want their
- * code to run on all platforms need to avoid this method.
- * </p>
- *
- * @param xor if <code>true</code>, then <em>xor</em> mode is used, otherwise <em>source copy</em> mode is used
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @deprecated this functionality is not supported on some platforms
- */
-public void setXORMode(boolean xor) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- data.xorMode = xor;
- if (OS.VERSION >= 0x1040) {
- OS.CGContextSetBlendMode(handle, xor ? OS.kCGBlendModeDifference : OS.kCGBlendModeNormal);
- }
-}
-
-/**
- * Sets the receiver's text anti-aliasing value to the parameter,
- * which must be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code>
- * or <code>SWT.ON</code>. Note that this controls anti-aliasing only
- * for all <em>text drawing</em> operations.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param antialias the anti-aliasing setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.OFF</code> or <code>SWT.ON</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- * @see #setAntialias
- *
- * @since 3.1
- */
-public void setTextAntialias(int antialias) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (antialias) {
- case SWT.DEFAULT:
- case SWT.OFF:
- case SWT.ON:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.textAntialias = antialias;
-}
-
-/**
- * Sets the transform that is currently being used by the receiver. If
- * the argument is <code>null</code>, the current transform is set to
- * the identity transform.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param transform the transform to set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Transform
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setTransform(Transform transform) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transform != null && transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.inverseTransform != null) OS.CGContextConcatCTM(handle, data.inverseTransform);
- if (transform != null) {
- OS.CGContextConcatCTM(handle, transform.handle);
- if (data.transform == null) data.transform = new float[6];
- if (data.inverseTransform == null) data.inverseTransform = new float[6];
- System.arraycopy(transform.handle, 0, data.transform, 0, data.transform.length);
- System.arraycopy(transform.handle, 0, data.inverseTransform, 0, data.inverseTransform.length);
- OS.CGAffineTransformInvert(data.inverseTransform, data.inverseTransform);
- } else {
- data.transform = data.inverseTransform = null;
- }
- if (data.forePattern != 0) {
- OS.CGPatternRelease(data.forePattern);
- data.forePattern = 0;
- data.state &= ~(FOREGROUND | FOREGROUND_FILL);
- }
- if (data.backPattern != 0) {
- OS.CGPatternRelease(data.backPattern);
- data.backPattern = 0;
- data.state &= ~BACKGROUND;
- }
- data.state &= ~DRAW_OFFSET;
-}
-
-/**
- * Returns the extent of the given string. No tab
- * expansion or carriage return processing will be performed.
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point stringExtent(String string) {
- return textExtent(string, 0);
-}
-
-/**
- * Returns the extent of the given string. Tab expansion and
- * carriage return processing are performed.
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point textExtent(String string) {
- return textExtent(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
-}
-
-/**
- * Returns the extent of the given string. Tab expansion, line
- * delimiter and mnemonic processing are performed according to
- * the specified flags, which can be a combination of:
- * <dl>
- * <dt><b>DRAW_DELIMITER</b></dt>
- * <dd>draw multiple lines</dd>
- * <dt><b>DRAW_TAB</b></dt>
- * <dd>expand tabs</dd>
- * <dt><b>DRAW_MNEMONIC</b></dt>
- * <dd>underline the mnemonic character</dd>
- * <dt><b>DRAW_TRANSPARENT</b></dt>
- * <dd>transparent background</dd>
- * </dl>
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @param flags the flags specifying how to process the text
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point textExtent(String string, int flags) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(FONT);
- int length = setString(string, flags);
- if (data.stringWidth != -1) return new Point(data.stringWidth, data.stringHeight);
- int width = 0, height;
- if (length == 0) {
- height = data.fontAscent + data.fontDescent;
- } else {
- ATSTrapezoid trapezoid = new ATSTrapezoid();
- if ((flags & SWT.DRAW_DELIMITER) != 0) {
- height = 0;
- int layout = data.layout;
- int[] breakCount = new int[1];
- OS.ATSUGetSoftLineBreaks(layout, 0, length, 0, null, breakCount);
- int[] breaks = new int[breakCount[0] + 1];
- OS.ATSUGetSoftLineBreaks(layout, 0, length, breakCount[0], breaks, breakCount);
- breaks[breakCount[0]] = length;
- for (int i=0, start=0; i<breaks.length; i++) {
- int lineBreak = breaks[i];
- OS.ATSUGetGlyphBounds(layout, 0, 0, start, lineBreak - start, (short)OS.kATSUseDeviceOrigins, 1, trapezoid, null);
- width = Math.max(width, OS.Fix2Long(trapezoid.lowerRight_x) - OS.Fix2Long(trapezoid.lowerLeft_x));
- height += OS.Fix2Long(trapezoid.lowerRight_y) - OS.Fix2Long(trapezoid.upperRight_y);
- start = lineBreak;
- }
- } else {
- OS.ATSUGetGlyphBounds(data.layout, 0, 0, 0, length, (short)OS.kATSUseDeviceOrigins, 1, trapezoid, null);
- width = OS.Fix2Long(trapezoid.lowerRight_x) - OS.Fix2Long(trapezoid.lowerLeft_x);
- height = OS.Fix2Long(trapezoid.lowerRight_y) - OS.Fix2Long(trapezoid.upperRight_y);
- }
- }
- return new Point(data.stringWidth = width, data.stringHeight = height);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "GC {*DISPOSED*}";
- return "GC {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/GCData.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/GCData.java
deleted file mode 100644
index 44ea8d6990..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/GCData.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.carbon.Rect;
-
-/**
- * Instances of this class are descriptions of GCs in terms
- * of unallocated platform-specific data fields.
- * <p>
- * <b>IMPORTANT:</b> This class is <em>not</em> part of the public
- * API for SWT. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms, and should never be called from application code.
- * </p>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noinstantiate This class is not intended to be instantiated by clients.
- */
-public final class GCData {
- public Device device;
- public int style, state = -1;
- public float[] foreground;
- public float[] background;
- public Pattern foregroundPattern;
- public Pattern backgroundPattern;
- public Font font;
- public int alpha = 0xFF;
- public float[] transform;
- public float[] inverseTransform;
- public float[] clippingTransform;
- public int clipRgn;
- public float lineWidth;
- public int lineStyle = SWT.LINE_SOLID;
- public int lineCap = SWT.CAP_FLAT;
- public int lineJoin = SWT.JOIN_MITER;
- public float lineDashesOffset;
- public float[] lineDashes;
- public float lineMiterLimit = 10;
- public boolean xorMode;
- public int antialias = SWT.DEFAULT;
- public int textAntialias = SWT.DEFAULT;
- public int fillRule = SWT.FILL_EVEN_ODD;
-
- public float drawXOffset, drawYOffset;
- public int forePattern;
- public int backPattern;
- public Image image;
- public int fontAscent;
- public int fontDescent;
- public int layout;
- public int atsuiStyle;
- public int tabs;
- public String string;
- public int stringLength;
- public int stringWidth = -1;
- public int stringHeight = -1;
- public int drawFlags;
- public int stringPtr;
- public Thread thread;
- public int window;
- public int paintEvent;
- public int visibleRgn;
- public int control;
- public int port;
- public Rect portRect;
- public Rect controlRect;
- public Rect insetRect;
- public boolean updateClip;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Image.java
deleted file mode 100644
index 0bac8c3694..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Image.java
+++ /dev/null
@@ -1,1013 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.carbon.*;
-import org.eclipse.swt.*;
-import java.io.*;
-
-/**
- * Instances of this class are graphics which have been prepared
- * for display on a specific device. That is, they are ready
- * to paint using methods such as <code>GC.drawImage()</code>
- * and display on widgets with, for example, <code>Button.setImage()</code>.
- * <p>
- * If loaded from a file format that supports it, an
- * <code>Image</code> may have transparency, meaning that certain
- * pixels are specified as being transparent when drawn. Examples
- * of file formats that support transparency are GIF and PNG.
- * </p><p>
- * There are two primary ways to use <code>Images</code>.
- * The first is to load a graphic file from disk and create an
- * <code>Image</code> from it. This is done using an <code>Image</code>
- * constructor, for example:
- * <pre>
- * Image i = new Image(device, "C:\\graphic.bmp");
- * </pre>
- * A graphic file may contain a color table specifying which
- * colors the image was intended to possess. In the above example,
- * these colors will be mapped to the closest available color in
- * SWT. It is possible to get more control over the mapping of
- * colors as the image is being created, using code of the form:
- * <pre>
- * ImageData data = new ImageData("C:\\graphic.bmp");
- * RGB[] rgbs = data.getRGBs();
- * // At this point, rgbs contains specifications of all
- * // the colors contained within this image. You may
- * // allocate as many of these colors as you wish by
- * // using the Color constructor Color(RGB), then
- * // create the image:
- * Image i = new Image(device, data);
- * </pre>
- * <p>
- * Applications which require even greater control over the image
- * loading process should use the support provided in class
- * <code>ImageLoader</code>.
- * </p><p>
- * Application code must explicitly invoke the <code>Image.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see Color
- * @see ImageData
- * @see ImageLoader
- * @see <a href="http://www.eclipse.org/swt/snippets/#image">Image snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, ImageAnalyzer</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Image extends Resource implements Drawable {
-
- /**
- * specifies whether the receiver is a bitmap or an icon
- * (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int type;
-
- /**
- * the handle to the OS image resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
- /**
- * The data to the OS image resource.
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int data;
-
- /**
- * specifies the transparent pixel
- */
- int transparentPixel = -1;
-
- /**
- * The GC the image is currently selected in.
- */
- GC memGC;
-
- /**
- * The alpha data of the image.
- */
- byte[] alphaData;
-
- /**
- * The global alpha value to be used for every pixel.
- */
- int alpha = -1;
-
- /**
- * The width of the image.
- */
- int width = -1;
-
- /**
- * The height of the image.
- */
- int height = -1;
-
- /**
- * Specifies the default scanline padding.
- */
- static final int DEFAULT_SCANLINE_PAD = 4;
-
-Image(Device device) {
- super(device);
-}
-
-/**
- * Constructs an empty instance of this class with the
- * specified width and height. The result may be drawn upon
- * by creating a GC and using any of its drawing operations,
- * as shown in the following example:
- * <pre>
- * Image i = new Image(device, width, height);
- * GC gc = new GC(i);
- * gc.drawRectangle(0, 0, 50, 50);
- * gc.dispose();
- * </pre>
- * <p>
- * Note: Some platforms may have a limitation on the size
- * of image that can be created (size depends on width, height,
- * and depth). For example, Windows 95, 98, and ME do not allow
- * images larger than 16M.
- * </p>
- *
- * @param device the device on which to create the image
- * @param width the width of the new image
- * @param height the height of the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - if either the width or height is negative or zero</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, int width, int height) {
- super(device);
- init(width, height);
- init();
-}
-
-/**
- * Constructs a new instance of this class based on the
- * provided image, with an appearance that varies depending
- * on the value of the flag. The possible flag values are:
- * <dl>
- * <dt><b>{@link SWT#IMAGE_COPY}</b></dt>
- * <dd>the result is an identical copy of srcImage</dd>
- * <dt><b>{@link SWT#IMAGE_DISABLE}</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>disabled</em> look</dd>
- * <dt><b>{@link SWT#IMAGE_GRAY}</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>gray scale</em> look</dd>
- * </dl>
- *
- * @param device the device on which to create the image
- * @param srcImage the image to use as the source
- * @param flag the style, either <code>IMAGE_COPY</code>, <code>IMAGE_DISABLE</code> or <code>IMAGE_GRAY</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if srcImage is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the flag is not one of <code>IMAGE_COPY</code>, <code>IMAGE_DISABLE</code> or <code>IMAGE_GRAY</code></li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon, or is otherwise in an invalid state</li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the image is not supported</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, Image srcImage, int flag) {
- super(device);
- if (srcImage == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (srcImage.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- switch (flag) {
- case SWT.IMAGE_COPY:
- case SWT.IMAGE_DISABLE:
- case SWT.IMAGE_GRAY:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- device = this.device;
- this.type = srcImage.type;
-
- /* Get source image size */
- int width = OS.CGImageGetWidth(srcImage.handle);
- int height = OS.CGImageGetHeight(srcImage.handle);
- int bpr = OS.CGImageGetBytesPerRow(srcImage.handle);
- int bpc = OS.CGImageGetBitsPerComponent(srcImage.handle);
- int bpp = OS.CGImageGetBitsPerPixel(srcImage.handle);
- int colorspace = OS.CGImageGetColorSpace(srcImage.handle);
- int alphaInfo = OS.kCGImageAlphaNoneSkipFirst;
-
- /* Copy transparent pixel and alpha data when necessary */
- alphaInfo = OS.CGImageGetAlphaInfo(srcImage.handle);
- transparentPixel = srcImage.transparentPixel;
- alpha = srcImage.alpha;
- if (srcImage.alphaData != null) {
- alphaData = new byte[srcImage.alphaData.length];
- System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length);
- }
-
- /* Create the image */
- int dataSize = height * bpr;
- data = OS.NewPtr(dataSize);
- if (data == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int provider = OS.CGDataProviderCreateWithData(0, data, dataSize, device.releaseProc);
- if (provider == 0) {
- OS.DisposePtr(data);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- handle = OS.CGImageCreate(width, height, bpc, bpp, bpr, colorspace, alphaInfo, provider, null, true, 0);
- OS.CGDataProviderRelease(provider);
- if (handle == 0) {
- OS.DisposePtr(data);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
-
- OS.memmove(data, srcImage.data, dataSize);
- if (flag != SWT.IMAGE_COPY) {
-
- /* Apply transformation */
- switch (flag) {
- case SWT.IMAGE_DISABLE: {
- Color zeroColor = device.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
- RGB zeroRGB = zeroColor.getRGB();
- byte zeroRed = (byte)zeroRGB.red;
- byte zeroGreen = (byte)zeroRGB.green;
- byte zeroBlue = (byte)zeroRGB.blue;
- Color oneColor = device.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
- RGB oneRGB = oneColor.getRGB();
- byte oneRed = (byte)oneRGB.red;
- byte oneGreen = (byte)oneRGB.green;
- byte oneBlue = (byte)oneRGB.blue;
- byte[] line = new byte[bpr];
- for (int y=0; y<height; y++) {
- OS.memmove(line, data + (y * bpr), bpr);
- int offset = 0;
- for (int x=0; x<width; x++) {
- int red = line[offset+1] & 0xFF;
- int green = line[offset+2] & 0xFF;
- int blue = line[offset+3] & 0xFF;
- int intensity = red * red + green * green + blue * blue;
- if (intensity < 98304) {
- line[offset+1] = zeroRed;
- line[offset+2] = zeroGreen;
- line[offset+3] = zeroBlue;
- } else {
- line[offset+1] = oneRed;
- line[offset+2] = oneGreen;
- line[offset+3] = oneBlue;
- }
- offset += 4;
- }
- OS.memmove(data + (y * bpr), line, bpr);
- }
- break;
- }
- case SWT.IMAGE_GRAY: {
- byte[] line = new byte[bpr];
- for (int y=0; y<height; y++) {
- OS.memmove(line, data + (y * bpr), bpr);
- int offset = 0;
- for (int x=0; x<width; x++) {
- int red = line[offset+1] & 0xFF;
- int green = line[offset+2] & 0xFF;
- int blue = line[offset+3] & 0xFF;
- byte intensity = (byte)((red+red+green+green+green+green+green+blue) >> 3);
- line[offset+1] = line[offset+2] = line[offset+3] = intensity;
- offset += 4;
- }
- OS.memmove(data + (y * bpr), line, bpr);
- }
- break;
- }
- }
- }
- init();
-}
-
-/**
- * Constructs an empty instance of this class with the
- * width and height of the specified rectangle. The result
- * may be drawn upon by creating a GC and using any of its
- * drawing operations, as shown in the following example:
- * <pre>
- * Image i = new Image(device, boundsRectangle);
- * GC gc = new GC(i);
- * gc.drawRectangle(0, 0, 50, 50);
- * gc.dispose();
- * </pre>
- * <p>
- * Note: Some platforms may have a limitation on the size
- * of image that can be created (size depends on width, height,
- * and depth). For example, Windows 95, 98, and ME do not allow
- * images larger than 16M.
- * </p>
- *
- * @param device the device on which to create the image
- * @param bounds a rectangle specifying the image's width and height (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the bounds rectangle is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, Rectangle bounds) {
- super(device);
- if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(bounds.width, bounds.height);
- init();
-}
-
-/**
- * Constructs an instance of this class from the given
- * <code>ImageData</code>.
- *
- * @param device the device on which to create the image
- * @param data the image data to create the image from (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the image data is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the ImageData is not supported</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, ImageData data) {
- super(device);
- init(data);
- init();
-}
-
-/**
- * Constructs an instance of this class, whose type is
- * <code>SWT.ICON</code>, from the two given <code>ImageData</code>
- * objects. The two images must be the same size. Pixel transparency
- * in either image will be ignored.
- * <p>
- * The mask image should contain white wherever the icon is to be visible,
- * and black wherever the icon is to be transparent. In addition,
- * the source image should contain black wherever the icon is to be
- * transparent.
- * </p>
- *
- * @param device the device on which to create the icon
- * @param source the color data for the icon
- * @param mask the mask data for the icon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if either the source or mask is null </li>
- * <li>ERROR_INVALID_ARGUMENT - if source and mask are different sizes</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, ImageData source, ImageData mask) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (mask == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (source.width != mask.width || source.height != mask.height) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- mask = ImageData.convertMask(mask);
- ImageData image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad, source.data);
- image.maskPad = mask.scanlinePad;
- image.maskData = mask.data;
- init(image);
- init();
-}
-
-/**
- * Constructs an instance of this class by loading its representation
- * from the specified input stream. Throws an error if an error
- * occurs while loading the image, or if the result is an image
- * of an unsupported type. Application code is still responsible
- * for closing the input stream.
- * <p>
- * This constructor is provided for convenience when loading a single
- * image only. If the stream contains multiple images, only the first
- * one will be loaded. To load multiple images, use
- * <code>ImageLoader.load()</code>.
- * </p><p>
- * This constructor may be used to load a resource as follows:
- * </p>
- * <pre>
- * static Image loadImage (Display display, Class clazz, String string) {
- * InputStream stream = clazz.getResourceAsStream (string);
- * if (stream == null) return null;
- * Image image = null;
- * try {
- * image = new Image (display, stream);
- * } catch (SWTException ex) {
- * } finally {
- * try {
- * stream.close ();
- * } catch (IOException ex) {}
- * }
- * return image;
- * }
- * </pre>
- *
- * @param device the device on which to create the image
- * @param stream the input stream to load the image from
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the stream is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from the stream</li>
- * <li>ERROR_INVALID_IMAGE - if the image stream contains invalid data </li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the image stream describes an image with an unsupported depth</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, InputStream stream) {
- super(device);
- init(new ImageData(stream));
- init();
-}
-
-/**
- * Constructs an instance of this class by loading its representation
- * from the file with the specified name. Throws an error if an error
- * occurs while loading the image, or if the result is an image
- * of an unsupported type.
- * <p>
- * This constructor is provided for convenience when loading
- * a single image only. If the specified file contains
- * multiple images, only the first one will be used.
- *
- * @param device the device on which to create the image
- * @param filename the name of the file to load the image from
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the file name is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from the file</li>
- * <li>ERROR_INVALID_IMAGE - if the image file contains invalid data </li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the image file describes an image with an unsupported depth</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, String filename) {
- super(device);
- init(new ImageData(filename));
- init();
-}
-
-void createAlpha () {
- if (transparentPixel == -1 && alpha == -1 && alphaData == null) return;
- int height = OS.CGImageGetHeight(handle);
- int bpr = OS.CGImageGetBytesPerRow(handle);
- int dataSize = height * bpr;
- byte[] srcData = new byte[dataSize];
- OS.memmove(srcData, data, dataSize);
- if (transparentPixel != -1) {
- for (int i=0; i<dataSize; i+=4) {
- int pixel = ((srcData[i+1] & 0xFF) << 16) | ((srcData[i+2] & 0xFF) << 8) | (srcData[i+3] & 0xFF);
- srcData[i] = (byte)(pixel == transparentPixel ? 0 : 0xFF);
- }
- } else if (alpha != -1) {
- byte a = (byte)this.alpha;
- for (int i=0; i<dataSize; i+=4) {
- srcData[i] = a;
- }
- } else {
- int width = OS.CGImageGetWidth(handle);
- int offset = 0, alphaOffset = 0;
- for (int y = 0; y<height; y++) {
- for (int x = 0; x<width; x++) {
- srcData[offset] = alphaData[alphaOffset];
- offset += 4;
- alphaOffset += 1;
- }
- }
- }
- OS.memmove(data, srcData, dataSize);
-}
-
-void destroy () {
- if (memGC != null) memGC.dispose();
- OS.CGImageRelease(handle);
- data = handle = 0;
- memGC = null;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Image)) return false;
- Image image = (Image)object;
- return device == image.device && handle == image.handle &&
- transparentPixel == image.transparentPixel;
-}
-
-/**
- * Returns the color to which to map the transparent pixel, or null if
- * the receiver has no transparent pixel.
- * <p>
- * There are certain uses of Images that do not support transparency
- * (for example, setting an image into a button or label). In these cases,
- * it may be desired to simulate transparency by using the background
- * color of the widget to paint the transparent pixels of the image.
- * Use this method to check which color will be used in these cases
- * in place of transparency. This value may be set with setBackground().
- * <p>
- *
- * @return the background color of the image, or null if there is no transparency in the image
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getBackground() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transparentPixel == -1) return null;
- int red = (transparentPixel >> 16) & 0xFF;
- int green = (transparentPixel >> 8) & 0xFF;
- int blue = (transparentPixel >> 0) & 0xFF;
- return Color.carbon_new(device, new float[]{red / 255f, green / 255f, blue / 255f, 1});
-}
-
-/**
- * Returns the bounds of the receiver. The rectangle will always
- * have x and y values of 0, and the width and height of the
- * image.
- *
- * @return a rectangle specifying the image's bounds
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li>
- * </ul>
- */
-public Rectangle getBounds() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width != -1 && height != -1) {
- return new Rectangle(0, 0, width, height);
- }
- return new Rectangle(0, 0, width = OS.CGImageGetWidth(handle), height = OS.CGImageGetHeight(handle));
-}
-
-/**
- * Returns an <code>ImageData</code> based on the receiver
- * Modifications made to this <code>ImageData</code> will not
- * affect the Image.
- *
- * @return an <code>ImageData</code> containing the image's data and attributes
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li>
- * </ul>
- *
- * @see ImageData
- */
-public ImageData getImageData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-
- int width = OS.CGImageGetWidth(handle);
- int height = OS.CGImageGetHeight(handle);
- int bpr = OS.CGImageGetBytesPerRow(handle);
- int bpp = OS.CGImageGetBitsPerPixel(handle);
- int dataSize = height * bpr;
- byte[] srcData = new byte[dataSize];
- OS.memmove(srcData, data, dataSize);
-
- PaletteData palette = new PaletteData(0xFF0000, 0xFF00, 0xFF);
- ImageData data = new ImageData(width, height, bpp, palette, 4, srcData);
- data.bytesPerLine = bpr;
-
- data.transparentPixel = transparentPixel;
- if (transparentPixel == -1 && type == SWT.ICON) {
- /* Get the icon mask data */
- int maskPad = 2;
- int maskBpl = (((width + 7) / 8) + (maskPad - 1)) / maskPad * maskPad;
- byte[] maskData = new byte[height * maskBpl];
- int offset = 0, maskOffset = 0;
- for (int y = 0; y<height; y++) {
- for (int x = 0; x<width; x++) {
- if (srcData[offset] != 0) {
- maskData[maskOffset + (x >> 3)] |= (1 << (7 - (x & 0x7)));
- } else {
- maskData[maskOffset + (x >> 3)] &= ~(1 << (7 - (x & 0x7)));
- }
- offset += 4;
- }
- maskOffset += maskBpl;
- }
- data.maskData = maskData;
- data.maskPad = maskPad;
- }
- for (int i = 0; i < srcData.length; i+= 4) {
- srcData[i] = 0;
- }
- data.alpha = alpha;
- if (alpha == -1 && alphaData != null) {
- data.alphaData = new byte[alphaData.length];
- System.arraycopy(alphaData, 0, data.alphaData, 0, alphaData.length);
- }
- return data;
-}
-
-/**
- * Invokes platform specific functionality to allocate a new image.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param type the type of the image (<code>SWT.BITMAP</code> or <code>SWT.ICON</code>)
- * @param handle the OS handle for the image
- * @param data the OS data for the image
- *
- * @private
- */
-public static Image carbon_new(Device device, int type, int handle, int data) {
- Image image = new Image(device);
- image.type = type;
- image.handle = handle;
- image.data = data;
- return image;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return handle;
-}
-
-void init(int width, int height) {
- if (width <= 0 || height <= 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.type = SWT.BITMAP;
-
- /* Create the image */
- int bpr = width * 4;
- int dataSize = height * bpr;
- data = OS.NewPtr(dataSize);
- if (data == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int provider = OS.CGDataProviderCreateWithData(0, data, dataSize, device.releaseProc);
- if (provider == 0) {
- OS.DisposePtr(data);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- int colorspace = device.colorspace;
- handle = OS.CGImageCreate(width, height, 8, 32, bpr, colorspace, OS.kCGImageAlphaNoneSkipFirst, provider, null, true, 0);
- OS.CGDataProviderRelease(provider);
- if (handle == 0) {
- OS.DisposePtr(data);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
-
- /* Fill the image with white */
- int bpc = OS.CGImageGetBitsPerComponent(handle);
- int context = OS.CGBitmapContextCreate(this.data, width, height, bpc, bpr, colorspace, OS.kCGImageAlphaNoneSkipFirst);
- if (context == 0) {
- OS.CGImageRelease(handle);
- OS.DisposePtr(data);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- CGRect rect = new CGRect();
- rect.width = width; rect.height = height;
- OS.CGContextSetRGBFillColor(context, 1, 1, 1, 1);
- OS.CGContextFillRect(context, rect);
- OS.CGContextRelease(context);
-}
-
-void init(ImageData image) {
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int width = image.width;
- int height = image.height;
- PaletteData palette = image.palette;
- if (!(((image.depth == 1 || image.depth == 2 || image.depth == 4 || image.depth == 8) && !palette.isDirect) ||
- ((image.depth == 8) || (image.depth == 16 || image.depth == 24 || image.depth == 32) && palette.isDirect)))
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
-
-
- /* Create the image */
- int dataSize = width * height * 4;
- data = OS.NewPtr(dataSize);
- if (data == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int provider = OS.CGDataProviderCreateWithData(0, data, dataSize, device.releaseProc);
- if (provider == 0) {
- OS.DisposePtr(data);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- int colorspace = device.colorspace;
- int transparency = image.getTransparencyType();
- int alphaInfo = transparency == SWT.TRANSPARENCY_NONE && image.alpha == -1 ? OS.kCGImageAlphaNoneSkipFirst : OS.kCGImageAlphaFirst;
- handle = OS.CGImageCreate(width, height, 8, 32, width * 4, colorspace, alphaInfo, provider, null, true, 0);
- OS.CGDataProviderRelease(provider);
- if (handle == 0) {
- OS.DisposePtr(data);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
-
- /* Initialize data */
- int bpr = width * 4;
- byte[] buffer = new byte[dataSize];
- if (palette.isDirect) {
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, image.getByteOrder(), 0, 0, width, height, palette.redMask, palette.greenMask, palette.blueMask,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- buffer, 32, bpr, ImageData.MSB_FIRST, 0, 0, width, height, 0xFF0000, 0xFF00, 0xFF,
- false, false);
- } else {
- RGB[] rgbs = palette.getRGBs();
- int length = rgbs.length;
- byte[] srcReds = new byte[length];
- byte[] srcGreens = new byte[length];
- byte[] srcBlues = new byte[length];
- for (int i = 0; i < rgbs.length; i++) {
- RGB rgb = rgbs[i];
- if (rgb == null) continue;
- srcReds[i] = (byte)rgb.red;
- srcGreens[i] = (byte)rgb.green;
- srcBlues[i] = (byte)rgb.blue;
- }
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, image.getByteOrder(), 0, 0, width, height, srcReds, srcGreens, srcBlues,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- buffer, 32, bpr, ImageData.MSB_FIRST, 0, 0, width, height, 0xFF0000, 0xFF00, 0xFF,
- false, false);
- }
-
- /* Initialize transparency */
- if (transparency == SWT.TRANSPARENCY_MASK || image.transparentPixel != -1) {
- this.type = image.transparentPixel != -1 ? SWT.BITMAP : SWT.ICON;
- if (image.transparentPixel != -1) {
- int transRed = 0, transGreen = 0, transBlue = 0;
- if (palette.isDirect) {
- RGB rgb = palette.getRGB(image.transparentPixel);
- transRed = rgb.red;
- transGreen = rgb.green;
- transBlue = rgb.blue;
- } else {
- RGB[] rgbs = palette.getRGBs();
- if (image.transparentPixel < rgbs.length) {
- RGB rgb = rgbs[image.transparentPixel];
- transRed = rgb.red;
- transGreen = rgb.green;
- transBlue = rgb.blue;
- }
- }
- transparentPixel = transRed << 16 | transGreen << 8 | transBlue;
- }
- ImageData maskImage = image.getTransparencyMask();
- byte[] maskData = maskImage.data;
- int maskBpl = maskImage.bytesPerLine;
- int offset = 0, maskOffset = 0;
- for (int y = 0; y<height; y++) {
- for (int x = 0; x<width; x++) {
- buffer[offset] = ((maskData[maskOffset + (x >> 3)]) & (1 << (7 - (x & 0x7)))) != 0 ? (byte)0xff : 0;
- offset += 4;
- }
- maskOffset += maskBpl;
- }
- } else {
- this.type = SWT.BITMAP;
- if (image.alpha != -1) {
- this.alpha = image.alpha;
- byte a = (byte)this.alpha;
- for (int dataIndex=0; dataIndex<buffer.length; dataIndex+=4) {
- buffer[dataIndex] = a;
- }
- } else if (image.alphaData != null) {
- this.alphaData = new byte[image.alphaData.length];
- System.arraycopy(image.alphaData, 0, this.alphaData, 0, alphaData.length);
- int offset = 0, alphaOffset = 0;
- for (int y = 0; y<height; y++) {
- for (int x = 0; x<width; x++) {
- buffer[offset] = alphaData[alphaOffset];
- offset += 4;
- alphaOffset += 1;
- }
- }
- }
- }
-
- OS.memmove(data, buffer, dataSize);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public int internal_new_GC (GCData data) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (type != SWT.BITMAP || memGC != null) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int width = OS.CGImageGetWidth(handle);
- int height = OS.CGImageGetHeight(handle);
- int bpc = OS.CGImageGetBitsPerComponent(handle);
- int bpr = OS.CGImageGetBytesPerRow(handle);
- int colorspace = OS.CGImageGetColorSpace(handle);
- int context = OS.CGBitmapContextCreate(this.data, width, height, bpc, bpr, colorspace, OS.kCGImageAlphaNoneSkipFirst);
- if (context == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.CGContextScaleCTM(context, 1, -1);
- OS.CGContextTranslateCTM(context, 0, -height);
- if (data != null) {
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) == 0) {
- data.style |= SWT.LEFT_TO_RIGHT;
- }
- data.device = device;
- data.background = device.COLOR_WHITE.handle;
- data.foreground = device.COLOR_BLACK.handle;
- data.font = device.systemFont;
- data.image = this;
- }
- return context;
-}
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int context, GCData data) {
- OS.CGContextRelease(context);
-}
-
-/**
- * Returns <code>true</code> if the image has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the image.
- * When an image has been disposed, it is an error to
- * invoke any other method using the image.
- *
- * @return <code>true</code> when the image is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Sets the color to which to map the transparent pixel.
- * <p>
- * There are certain uses of <code>Images</code> that do not support
- * transparency (for example, setting an image into a button or label).
- * In these cases, it may be desired to simulate transparency by using
- * the background color of the widget to paint the transparent pixels
- * of the image. This method specifies the color that will be used in
- * these cases. For example:
- * <pre>
- * Button b = new Button();
- * image.setBackground(b.getBackground());
- * b.setImage(image);
- * </pre>
- * </p><p>
- * The image may be modified by this operation (in effect, the
- * transparent regions may be filled with the supplied color). Hence
- * this operation is not reversible and it is not legal to call
- * this function twice or with a null argument.
- * </p><p>
- * This method has no effect if the receiver does not have a transparent
- * pixel value.
- * </p>
- *
- * @param color the color to use when a transparent pixel is specified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setBackground(Color color) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (transparentPixel == -1) return;
- byte red = (byte)((transparentPixel >> 16) & 0xFF);
- byte green = (byte)((transparentPixel >> 8) & 0xFF);
- byte blue = (byte)((transparentPixel >> 0) & 0xFF);
- byte newRed = (byte)((int)(color.handle[0] * 255) & 0xFF);
- byte newGreen = (byte)((int)(color.handle[1] * 255) & 0xFF);
- byte newBlue = (byte)((int)(color.handle[2] * 255) & 0xFF);
- int height = OS.CGImageGetHeight(handle);
- int bpl = OS.CGImageGetBytesPerRow(handle);
- byte[] line = new byte[bpl];
- for (int i = 0, offset = 0; i < height; i++, offset += bpl) {
- OS.memmove(line, data + offset, bpl);
- for (int j = 0; j < line.length; j += 4) {
- if (line[j+ 1] == red && line[j + 2] == green && line[j + 3] == blue) {
- line[j + 1] = newRed;
- line[j + 2] = newGreen;
- line[j + 3] = newBlue;
- }
- }
- OS.memmove(data + offset, line, bpl);
- }
- transparentPixel = (newRed & 0xFF) << 16 | (newGreen & 0xFF) << 8 | (newBlue & 0xFF);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Image {*DISPOSED*}";
- return "Image {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Path.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Path.java
deleted file mode 100644
index a07137b8ca..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Path.java
+++ /dev/null
@@ -1,813 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.carbon.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class represent paths through the two-dimensional
- * coordinate system. Paths do not have to be continuous, and can be
- * described using lines, rectangles, arcs, cubic or quadratic bezier curves,
- * glyphs, or other paths.
- * <p>
- * Application code must explicitly invoke the <code>Path.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#path">Path, Pattern snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Path extends Resource {
-
- /**
- * the OS resource for the Path
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
- boolean moved, closed = true;
-
-/**
- * Constructs a new empty Path.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the path
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Path (Device device) {
- super(device);
- handle = OS.CGPathCreateMutable();
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new Path that is a copy of <code>path</code>. If
- * <code>flatness</code> is less than or equal to zero, an unflatten
- * copy of the path is created. Otherwise, it specifies the maximum
- * error between the path and its flatten copy. Smaller numbers give
- * better approximation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the path
- * @param path the path to make a copy
- * @param flatness the flatness value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the path is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the path has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- * @since 3.4
- */
-public Path (Device device, Path path, float flatness) {
- super(device);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- flatness = Math.max(0, flatness);
- if (flatness == 0) {
- handle = OS.CGPathCreateMutableCopy(path.handle);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- } else {
- handle = OS.CGPathCreateMutable();
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- PathData data = path.getPathData();
- int bezierPath = Cocoa.objc_msgSend(Cocoa.C_NSBezierPath, Cocoa.S_bezierPath);
- byte[] types = data.types;
- float[] points = data.points;
- NSPoint point = new NSPoint(), point2 = new NSPoint(), point3 = new NSPoint();
- for (int i = 0, j = 0; i < types.length; i++) {
- switch (types[i]) {
- case SWT.PATH_MOVE_TO:
- point.x = points[j++];
- point.y = points[j++];
- Cocoa.objc_msgSend(bezierPath, Cocoa.S_moveToPoint, point);
- break;
- case SWT.PATH_LINE_TO:
- point.x = points[j++];
- point.y = points[j++];
- Cocoa.objc_msgSend(bezierPath, Cocoa.S_lineToPoint, point);
- break;
- case SWT.PATH_CUBIC_TO:
- point2.x = points[j++];
- point2.y = points[j++];
- point3.x = points[j++];
- point3.y = points[j++];
- point.x = points[j++];
- point.y = points[j++];
- Cocoa.objc_msgSend(bezierPath, Cocoa.S_curveToPoint, point, point2, point3);
- break;
- case SWT.PATH_QUAD_TO:
- float currentX = point.x;
- float currentY = point.y;
- point2.x = points[j++];
- point2.y = points[j++];
- point.x = points[j++];
- point.y = points[j++];
- float x0 = currentX;
- float y0 = currentY;
- float cx1 = x0 + 2 * (point2.x - x0) / 3;
- float cy1 = y0 + 2 * (point2.y - y0) / 3;
- float cx2 = cx1 + (point.x - x0) / 3;
- float cy2 = cy1 + (point.y - y0) / 3;
- point2.x = cx1;
- point2.y = cy1;
- point3.x = cx2;
- point3.y = cy2;
- Cocoa.objc_msgSend(bezierPath, Cocoa.S_curveToPoint, point, point2, point3);
- break;
- case SWT.PATH_CLOSE:
- Cocoa.objc_msgSend(bezierPath, Cocoa.S_closePath);
- break;
- default:
- dispose();
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- Cocoa.objc_msgSend(Cocoa.C_NSBezierPath, Cocoa.S_setDefaultFlatness, flatness);
- bezierPath = Cocoa.objc_msgSend(bezierPath, Cocoa.S_bezierPathByFlatteningPath);
- int count = Cocoa.objc_msgSend(bezierPath, Cocoa.S_elementCount);
- int pointsPtr = OS.malloc(NSPoint.sizeof * 3);
- if (pointsPtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- for (int i = 0; i < count; i++) {
- int element = Cocoa.objc_msgSend(bezierPath, Cocoa.S_elementAtIndex_associatedPoints, i, pointsPtr);
- switch (element) {
- case Cocoa.NSMoveToBezierPathElement:
- Cocoa.memmove(point, pointsPtr, NSPoint.sizeof);
- moveTo(point.x, point.y);
- break;
- case Cocoa.NSLineToBezierPathElement:
- Cocoa.memmove(point, pointsPtr, NSPoint.sizeof);
- lineTo(point.x, point.y);
- break;
- case Cocoa.NSCurveToBezierPathElement:
- Cocoa.memmove(point, pointsPtr, NSPoint.sizeof);
- Cocoa.memmove(point2, pointsPtr + NSPoint.sizeof, NSPoint.sizeof);
- Cocoa.memmove(point3, pointsPtr + NSPoint.sizeof + NSPoint.sizeof, NSPoint.sizeof);
- cubicTo(point2.x, point2.y, point3.x, point3.y, point.x, point.y);
- break;
- case Cocoa.NSClosePathBezierPathElement:
- close();
- break;
- }
- }
- OS.free(pointsPtr);
- }
- init();
-}
-
-/**
- * Constructs a new Path with the specifed PathData.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the path
- * @param data the data for the path
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the data is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- * @since 3.4
- */
-public Path (Device device, PathData data) {
- this(device);
- if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(data);
-}
-
-/**
- * Adds to the receiver a circular or elliptical arc that lies within
- * the specified rectangular area.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc
- * @param y the y coordinate of the upper-left corner of the arc
- * @param width the width of the arc
- * @param height the height of the arc
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addArc(float x, float y, float width, float height, float startAngle, float arcAngle) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float[] cmt = new float[6];
- OS.CGAffineTransformMake(width / 2f, 0, 0, height / 2f, x + width / 2f, y + height / 2f, cmt);
- float angle = -startAngle * (float)Compatibility.PI / 180;
- if (closed) OS.CGPathMoveToPoint(handle, cmt, (float)Math.cos(angle), (float)Math.sin(angle));
- OS.CGPathAddArc(handle, cmt, 0, 0, 1, angle, -(startAngle + arcAngle) * (float)Compatibility.PI / 180, arcAngle >= 0);
- moved = true;
- closed = false;
- if (Math.abs(arcAngle) >= 360) close();
-}
-
-/**
- * Adds to the receiver the path described by the parameter.
- *
- * @param path the path to add to the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addPath(Path path) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.CGPathAddPath(handle, null, path.handle);
- moved = false;
- closed = path.closed;
-}
-
-/**
- * Adds to the receiver the rectangle specified by x, y, width and height.
- *
- * @param x the x coordinate of the rectangle to add
- * @param y the y coordinate of the rectangle to add
- * @param width the width of the rectangle to add
- * @param height the height of the rectangle to add
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addRectangle(float x, float y, float width, float height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- CGRect rect = new CGRect();
- rect.x = x;
- rect.y = y;
- rect.width = width;
- rect.height = height;
- OS.CGPathAddRect(handle, null, rect);
- moved = false;
- closed = true;
-}
-
-int newPathProc(int data) {
- first = true;
- return 0;
-}
-
-int closePathProc(int data) {
- first = true;
- return 0;
-}
-
-int lineProc(int pt1, int pt2, int data) {
- if (first) {
- first = false;
- OS.memmove(point, pt1, 8);
- OS.CGPathMoveToPoint(handle, null, originX + point[0], originY + point[1]);
- }
- OS.memmove(point, pt2, 8);
- OS.CGPathAddLineToPoint(handle, null, originX + point[0], originY + point[1]);
- return 0;
-}
-
-int curveProc(int pt1, int controlPt, int pt2, int data) {
- if (first) {
- first = false;
- OS.memmove(point, pt1, 8);
- OS.CGPathMoveToPoint(handle, null, originX + point[0], originY + point[1]);
- }
- OS.memmove(point, pt2, 8);
- float x2 = point[0], y2 = point[1];
- OS.memmove(point, controlPt, 8);
- OS.CGPathAddQuadCurveToPoint(handle, null, originX + point[0], originY + point[1], originX + x2, originY + y2);
- return 0;
-}
-
-float originX, originY;
-float[] point = new float[2];
-boolean first;
-/**
- * Adds to the receiver the pattern of glyphs generated by drawing
- * the given string using the given font starting at the point (x, y).
- *
- * @param string the text to use
- * @param x the x coordinate of the starting point
- * @param y the y coordinate of the starting point
- * @param font the font to use
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the font is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addString(String string, float x, float y, Font font) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (font == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int length = string.length();
- if (length == 0) return;
- moved = false;
- closed = true;
-
- Callback newPathCallback = new Callback(this, "newPathProc", 1);
- int newPathProc = newPathCallback.getAddress();
- if (newPathProc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- Callback lineCallback = new Callback(this, "lineProc", 3);
- int lineProc = lineCallback.getAddress();
- if (lineProc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- Callback curveCallback = new Callback(this, "curveProc", 4);
- int curveProc = curveCallback.getAddress();
- if (curveProc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- Callback closePathCallback = new Callback(this, "closePathProc", 1);
- int closePathProc = closePathCallback.getAddress();
- if (closePathProc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
-
- int style = font.atsuiStyle;
- if (style == 0) style = font.createStyle();
- if (style == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int[] buffer = new int[1];
- OS.ATSUCreateTextLayout(buffer);
- if (buffer[0] == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int layout = buffer[0];
- char[] chars = new char[length];
- string.getChars(0, length, chars, 0);
- int textPtr = OS.NewPtr(length * 2);
- if (textPtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.memmove(textPtr, chars, length * 2);
- OS.ATSUSetTextPointerLocation(layout, textPtr, 0, length, length);
- OS.ATSUSetRunStyle(layout, style, 0, length);
- OS.ATSUSetTransientFontMatching(layout, true);
- int[] ascent = new int[1], descent = new int[1];
- OS.ATSUGetUnjustifiedBounds(layout, 0, length, null, null, ascent, descent);
- y += OS.Fix2X(ascent[0]);
-
- int[] layoutRecords = new int[1], numRecords = new int[1], deltaYs = new int[1], numDeltaYs = new int[1];
- OS.ATSUDirectGetLayoutDataArrayPtrFromTextLayout (layout, 0, OS.kATSUDirectDataLayoutRecordATSLayoutRecordCurrent, layoutRecords, numRecords);
- OS.ATSUDirectGetLayoutDataArrayPtrFromTextLayout (layout, 0, OS.kATSUDirectDataBaselineDeltaFixedArray, deltaYs, numDeltaYs);
- int[] deltaY = new int[1], status = new int[1];
- ATSLayoutRecord record = new ATSLayoutRecord();
- for (int i = 0; i < numRecords[0]; i++) {
- OS.memmove(record, layoutRecords[0] + (i * ATSLayoutRecord.sizeof), ATSLayoutRecord.sizeof);
- originX = x + (float)OS.Fix2X(record.realPos);
- if (deltaYs[0] == 0) {
- originY = y;
- } else {
- OS.memmove(deltaY, deltaYs[0] + (i * 4), 4);
- originY = y - (float)OS.Fix2X(deltaY[0]);
- }
- first = true;
- if (record.glyphID != OS.kATSDeletedGlyphcode) {
- OS.ATSUGlyphGetQuadraticPaths (style, record.glyphID, newPathProc, lineProc, curveProc, closePathProc, 0, status);
- }
- }
- OS.CGPathCloseSubpath(handle);
- if (deltaYs[0] != 0) {
- OS.ATSUDirectReleaseLayoutDataArrayPtr(0, OS.kATSUDirectDataBaselineDeltaFixedArray, deltaYs[0]);
- }
- OS.ATSUDirectReleaseLayoutDataArrayPtr(0, OS.kATSUDirectDataLayoutRecordATSLayoutRecordCurrent, layoutRecords[0]);
-
- if (style != font.atsuiStyle) OS.ATSUDisposeStyle(style);
- if (layout != 0) OS.ATSUDisposeTextLayout(layout);
- if (textPtr != 0) OS.DisposePtr(textPtr);
-
- newPathCallback.dispose();
- lineCallback.dispose();
- curveCallback.dispose();
- closePathCallback.dispose();
-}
-
-CGPathElement element;
-int count, typeCount;
-byte[] types;
-float[] points;
-int applierFunc(int info, int elementPtr) {
- OS.memmove(element, elementPtr, CGPathElement.sizeof);
- int type = 0, length = 1;
- switch (element.type) {
- case OS.kCGPathElementMoveToPoint: type = SWT.PATH_MOVE_TO; break;
- case OS.kCGPathElementAddLineToPoint: type = SWT.PATH_LINE_TO; break;
- case OS.kCGPathElementAddQuadCurveToPoint: type = SWT.PATH_QUAD_TO; length = 2; break;
- case OS.kCGPathElementAddCurveToPoint: type = SWT.PATH_CUBIC_TO; length = 3; break;
- case OS.kCGPathElementCloseSubpath: type = SWT.PATH_CLOSE; length = 0; break;
- }
- if (types != null) {
- types[typeCount] = (byte)type;
- if (length > 0) {
- OS.memmove(point, element.points, length * 8);
- System.arraycopy(point, 0, points, count, length * 2);
- }
- }
- typeCount++;
- count += length * 2;
- return 0;
-}
-
-/**
- * Closes the current sub path by adding to the receiver a line
- * from the current point of the path back to the starting point
- * of the sub path.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void close() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.CGPathCloseSubpath(handle);
- moved = false;
- closed = true;
-}
-
-/**
- * Returns <code>true</code> if the specified point is contained by
- * the receiver and false otherwise.
- * <p>
- * If outline is <code>true</code>, the point (x, y) checked for containment in
- * the receiver's outline. If outline is <code>false</code>, the point is
- * checked to see if it is contained within the bounds of the (closed) area
- * covered by the receiver.
- *
- * @param x the x coordinate of the point to test for containment
- * @param y the y coordinate of the point to test for containment
- * @param gc the GC to use when testing for containment
- * @param outline controls whether to check the outline or contained area of the path
- * @return <code>true</code> if the path contains the point and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains(float x, float y, GC gc, boolean outline) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- gc.checkGC(GC.LINE_CAP | GC.LINE_JOIN | GC.LINE_STYLE | GC.LINE_WIDTH);
- //TODO - see windows
- int pixel = OS.NewPtr(4);
- if (pixel == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int[] buffer = new int[]{0xFFFFFFFF};
- OS.memmove(pixel, buffer, 4);
- int context = OS.CGBitmapContextCreate(pixel, 1, 1, 8, 4, device.colorspace, OS.kCGImageAlphaNoneSkipFirst);
- if (context == 0) {
- OS.DisposePtr(pixel);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- GCData data = gc.data;
- int capStyle = 0;
- switch (data.lineCap) {
- case SWT.CAP_ROUND: capStyle = OS.kCGLineCapRound; break;
- case SWT.CAP_FLAT: capStyle = OS.kCGLineCapButt; break;
- case SWT.CAP_SQUARE: capStyle = OS.kCGLineCapSquare; break;
- }
- OS.CGContextSetLineCap(context, capStyle);
- int joinStyle = 0;
- switch (data.lineJoin) {
- case SWT.JOIN_MITER: joinStyle = OS.kCGLineJoinMiter; break;
- case SWT.JOIN_ROUND: joinStyle = OS.kCGLineJoinRound; break;
- case SWT.JOIN_BEVEL: joinStyle = OS.kCGLineJoinBevel; break;
- }
- OS.CGContextSetLineJoin(context, joinStyle);
- OS.CGContextSetLineWidth(context, data.lineWidth);
- OS.CGContextTranslateCTM(context, -x + 0.5f, -y + 0.5f);
- OS.CGContextAddPath(context, handle);
- if (outline) {
- OS.CGContextStrokePath(context);
- } else {
- if (data.fillRule == SWT.FILL_WINDING) {
- OS.CGContextFillPath(context);
- } else {
- OS.CGContextEOFillPath(context);
- }
- }
- OS.CGContextRelease(context);
- OS.memmove(buffer, pixel, 4);
- OS.DisposePtr(pixel);
- return buffer[0] != 0xFFFFFFFF;
-}
-
-/**
- * Adds to the receiver a cubic bezier curve based on the parameters.
- *
- * @param cx1 the x coordinate of the first control point of the spline
- * @param cy1 the y coordinate of the first control of the spline
- * @param cx2 the x coordinate of the second control of the spline
- * @param cy2 the y coordinate of the second control of the spline
- * @param x the x coordinate of the end point of the spline
- * @param y the y coordinate of the end point of the spline
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (!moved) {
- CGPoint pt = new CGPoint();
- if (!OS.CGPathIsEmpty(handle)) OS.CGPathGetCurrentPoint(handle, pt);
- OS.CGPathMoveToPoint(handle, null, pt.x, pt.y);
- moved = true;
- }
- closed = false;
- OS.CGPathAddCurveToPoint(handle, null, cx1, cy1, cx2, cy2, x, y);
-}
-
-void destroy() {
- OS.CGPathRelease(handle);
- handle = 0;
-}
-
-/**
- * Replaces the first four elements in the parameter with values that
- * describe the smallest rectangle that will completely contain the
- * receiver (i.e. the bounding box).
- *
- * @param bounds the array to hold the result
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the bounding box</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getBounds(float[] bounds) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (bounds.length < 4) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- CGRect rect = new CGRect();
- OS.CGPathGetBoundingBox(handle, rect);
- bounds[0] = rect.x;
- bounds[1] = rect.y;
- bounds[2] = rect.width;
- bounds[3] = rect.height;
-}
-
-/**
- * Replaces the first two elements in the parameter with values that
- * describe the current point of the path.
- *
- * @param point the array to hold the result
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the end point</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getCurrentPoint(float[] point) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (point == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (point.length < 2) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- CGPoint pt = new CGPoint();
- if (!OS.CGPathIsEmpty(handle)) OS.CGPathGetCurrentPoint(handle, pt);
- point[0] = pt.x;
- point[1] = pt.y;
-}
-
-/**
- * Returns a device independent representation of the receiver.
- *
- * @return the PathData for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see PathData
- */
-public PathData getPathData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Callback callback = new Callback(this, "applierFunc", 2);
- int proc = callback.getAddress();
- if (proc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- count = typeCount = 0;
- element = new CGPathElement();
- OS.CGPathApply(handle, 0, proc);
- types = new byte[typeCount];
- points = new float[count];
- point = new float[6];
- count = typeCount = 0;
- OS.CGPathApply(handle, 0, proc);
- callback.dispose();
- PathData result = new PathData();
- result.types = types;
- result.points = points;
- element = null;
- types = null;
- points = null;
- point = null;
- return result;
-}
-
-void init(PathData data) {
- byte[] types = data.types;
- float[] points = data.points;
- for (int i = 0, j = 0; i < types.length; i++) {
- switch (types[i]) {
- case SWT.PATH_MOVE_TO:
- moveTo(points[j++], points[j++]);
- break;
- case SWT.PATH_LINE_TO:
- lineTo(points[j++], points[j++]);
- break;
- case SWT.PATH_CUBIC_TO:
- cubicTo(points[j++], points[j++], points[j++], points[j++], points[j++], points[j++]);
- break;
- case SWT.PATH_QUAD_TO:
- quadTo(points[j++], points[j++], points[j++], points[j++]);
- break;
- case SWT.PATH_CLOSE:
- close();
- break;
- default:
- dispose();
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
-}
-
-/**
- * Returns <code>true</code> if the Path has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Path.
- * When a Path has been disposed, it is an error to
- * invoke any other method using the Path.
- *
- * @return <code>true</code> when the Path is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Adds to the receiver a line from the current point to
- * the point specified by (x, y).
- *
- * @param x the x coordinate of the end of the line to add
- * @param y the y coordinate of the end of the line to add
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void lineTo(float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (!moved) {
- CGPoint pt = new CGPoint();
- if (!OS.CGPathIsEmpty(handle)) OS.CGPathGetCurrentPoint(handle, pt);
- OS.CGPathMoveToPoint(handle, null, pt.x, pt.y);
- moved = true;
- }
- closed = false;
- OS.CGPathAddLineToPoint(handle, null, x, y);
-}
-
-/**
- * Sets the current point of the receiver to the point
- * specified by (x, y). Note that this starts a new
- * sub path.
- *
- * @param x the x coordinate of the new end point
- * @param y the y coordinate of the new end point
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void moveTo(float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.CGPathMoveToPoint(handle, null, x, y);
- /*
- * Bug in Quartz. If CGPathMoveToPoint() is not called at the
- * begining of a subpath, the following segments do not output
- * anything. The fix is to detect that the app did not call
- * CGPathMoveToPoint() and call it explicitly.
- */
- closed = true;
- moved = true;
-}
-
-/**
- * Adds to the receiver a quadratic curve based on the parameters.
- *
- * @param cx the x coordinate of the control point of the spline
- * @param cy the y coordinate of the control point of the spline
- * @param x the x coordinate of the end point of the spline
- * @param y the y coordinate of the end point of the spline
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void quadTo(float cx, float cy, float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (!moved) {
- CGPoint pt = new CGPoint();
- if (!OS.CGPathIsEmpty(handle)) OS.CGPathGetCurrentPoint(handle, pt);
- OS.CGPathMoveToPoint(handle, null, pt.x, pt.y);
- moved = true;
- }
- closed = false;
- OS.CGPathAddQuadCurveToPoint(handle, null, cx, cy, x, y);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Path {*DISPOSED*}";
- return "Path {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Pattern.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Pattern.java
deleted file mode 100644
index 94fb2fcef7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Pattern.java
+++ /dev/null
@@ -1,298 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.carbon.*;
-
-/**
- * Instances of this class represent patterns to use while drawing. Patterns
- * can be specified either as bitmaps or gradients.
- * <p>
- * Application code must explicitly invoke the <code>Pattern.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#path">Path, Pattern snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Pattern extends Resource {
- int jniRef;
- Image image;
- float[] color1, color2;
- int alpha1, alpha2;
- float x1, y1, x2, y2;
- int shading;
- CGRect drawRect;
-
-/**
- * Constructs a new Pattern given an image. Drawing with the resulting
- * pattern will cause the image to be tiled over the resulting area.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the pattern
- * @param image the image that the pattern will draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device, or the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Pattern(Device device, Image image) {
- super(device);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- device = this.device;
- this.image = image;
- device.createPatternCallbacks();
- jniRef = OS.NewGlobalRef(this);
- if (jniRef == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new Pattern that represents a linear, two color
- * gradient. Drawing with the pattern will cause the resulting area to be
- * tiled with the gradient specified by the arguments.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the pattern
- * @param x1 the x coordinate of the starting corner of the gradient
- * @param y1 the y coordinate of the starting corner of the gradient
- * @param x2 the x coordinate of the ending corner of the gradient
- * @param y2 the y coordinate of the ending corner of the gradient
- * @param color1 the starting color of the gradient
- * @param color2 the ending color of the gradient
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device,
- * or if either color1 or color2 is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either color1 or color2 has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Pattern(Device device, float x1, float y1, float x2, float y2, Color color1, Color color2) {
- this(device, x1, y1, x2, y2, color1, 0xFF, color2, 0xFF);
-}
-/**
- * Constructs a new Pattern that represents a linear, two color
- * gradient. Drawing with the pattern will cause the resulting area to be
- * tiled with the gradient specified by the arguments.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the pattern
- * @param x1 the x coordinate of the starting corner of the gradient
- * @param y1 the y coordinate of the starting corner of the gradient
- * @param x2 the x coordinate of the ending corner of the gradient
- * @param y2 the y coordinate of the ending corner of the gradient
- * @param color1 the starting color of the gradient
- * @param alpha1 the starting alpha value of the gradient
- * @param color2 the ending color of the gradient
- * @param alpha2 the ending alpha value of the gradient
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device,
- * or if either color1 or color2 is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either color1 or color2 has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- *
- * @since 3.2
- */
-public Pattern(Device device, float x1, float y1, float x2, float y2, Color color1, int alpha1, Color color2, int alpha2) {
- super(device);
- if (color1 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color1.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (color2 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color2.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- device = this.device;
- this.x1 = x1;
- this.y1 = y1;
- this.x2 = x2;
- this.y2 = y2;
- this.color1 = color1.handle;
- this.color2 = color2.handle;
- this.alpha1 = alpha1;
- this.alpha2 = alpha2;
- device.createPatternCallbacks();
- jniRef = OS.NewGlobalRef(this);
- if (jniRef == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- CGPoint start = new CGPoint();
- start.x = x1;
- start.y = y1;
- CGPoint end = new CGPoint();
- end.x = x2;
- end.y = y2;
- CGFunctionCallbacks fCallbacks = new CGFunctionCallbacks();
- fCallbacks.evaluate = device.axialShadingProc;
- int function = OS.CGFunctionCreate(jniRef, 1, new float[]{0, 1}, 4, new float[]{0, 1, 0, 1, 0, 1, 0, 1}, fCallbacks);
- if (function == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- shading = OS.CGShadingCreateAxial(device.colorspace, start, end, function, true, true);
- OS.CGFunctionRelease(function);
- if (shading == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-int axialShadingProc (int ref, int in, int out) {
- float[] buffer = new float[4];
- OS.memmove(buffer, in, 4);
- float factor2 = buffer[0], factor1 = 1 - factor2;
- float[] c1 = color1;
- float[] c2 = color2;
- float a1 = ((alpha1 & 0xFF) / (float)0xFF);
- float a2 = ((alpha2 & 0xFF) / (float)0xFF);
- buffer[0] = (c2[0] * factor2) + (c1[0] * factor1);
- buffer[1] = (c2[1] * factor2) + (c1[1] * factor1);
- buffer[2] = (c2[2] * factor2) + (c1[2] * factor1);
- buffer[3] = (a2 * factor2) + (a1 * factor1);
- OS.memmove(out, buffer, buffer.length * 4);
- return 0;
-}
-
-int createPattern(int context) {
- float[] transform = new float[6];
- OS.CGContextGetCTM(context, transform);
- CGRect rect = new CGRect();
- if (image != null) {
- int imageHandle = image.handle;
- rect.width = OS.CGImageGetWidth(imageHandle);
- rect.height = OS.CGImageGetHeight(imageHandle);
- } else {
- rect.x = x1 - 0.5f;
- rect.y = y1 - 0.5f;
- rect.width = x2 - x1 + 1;
- rect.height = y2 - y1 + 1;
- }
- CGPatternCallbacks callbacks = new CGPatternCallbacks();
- callbacks.drawPattern = device.drawPatternProc;
- int pattern = OS.CGPatternCreate(jniRef, rect, transform, rect.width, rect.height, OS.kCGPatternTilingNoDistortion, 0, callbacks);
- if (pattern == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- return pattern;
-}
-
-void destroy() {
- if (jniRef != 0) OS.DeleteGlobalRef(jniRef);
- if (shading != 0) OS.CGShadingRelease(shading);
- jniRef = shading = 0;
- image = null;
- color1 = color2 = null;
-}
-
-int drawPatternProc (int ref, int context) {
- if (image != null) {
- if (image.isDisposed()) return 0;
- int imageHandle = image.handle;
- int imageWidth = OS.CGImageGetWidth(imageHandle);
- int imageHeight = OS.CGImageGetHeight(imageHandle);
- CGRect rect = new CGRect();
- rect.width = imageWidth;
- rect.height = imageHeight;
- OS.CGContextScaleCTM(context, 1, -1);
- if (drawRect != null && (drawRect.x % imageWidth) + drawRect.width < imageWidth && (drawRect.y % imageHeight) + drawRect.height < imageHeight) {
- rect.x = drawRect.x % imageWidth;
- rect.y = drawRect.y % imageHeight;
- rect.width = drawRect.width;
- rect.height = drawRect.height;
- if (OS.VERSION >= 0x1040) {
- imageHandle = OS.CGImageCreateWithImageInRect(imageHandle, rect);
- } else {
- int srcX = (int)drawRect.x, srcY = (int)drawRect.y;
- int srcWidth = (int)drawRect.width, srcHeight = (int)drawRect.height;
- int bpc = OS.CGImageGetBitsPerComponent(imageHandle);
- int bpp = OS.CGImageGetBitsPerPixel(imageHandle);
- int bpr = OS.CGImageGetBytesPerRow(imageHandle);
- int colorspace = OS.CGImageGetColorSpace(imageHandle);
- int alphaInfo = OS.CGImageGetAlphaInfo(imageHandle);
- int data = image.data + (srcY * bpr) + srcX * 4;
- int provider = OS.CGDataProviderCreateWithData(0, data, srcHeight * bpr, 0);
- if (provider != 0) {
- imageHandle = OS.CGImageCreate(srcWidth, srcHeight, bpc, bpp, bpr, colorspace, alphaInfo, provider, null, true, 0);
- OS.CGDataProviderRelease(provider);
- }
- }
- }
- OS.CGContextTranslateCTM(context, 0, -(rect.height + 2 * rect.y));
- OS.CGContextDrawImage(context, rect, imageHandle);
- if (imageHandle != 0 && imageHandle != image.handle) OS.CGImageRelease(imageHandle);
- } else {
- OS.CGContextDrawShading(context, shading);
- }
- return 0;
-}
-
-/**
- * Returns <code>true</code> if the Pattern has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Pattern.
- * When a Pattern has been disposed, it is an error to
- * invoke any other method using the Pattern.
- *
- * @return <code>true</code> when the Pattern is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return jniRef == 0;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString() {
- if (isDisposed()) return "Pattern {*DISPOSED*}";
- return "Pattern {" + jniRef + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Region.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Region.java
deleted file mode 100644
index 033dd07fc7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Region.java
+++ /dev/null
@@ -1,597 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.carbon.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class represent areas of an x-y coordinate
- * system that are aggregates of the areas covered by a number
- * of polygons.
- * <p>
- * Application code must explicitly invoke the <code>Region.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Region extends Resource {
- /**
- * the OS resource for the region
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
-/**
- * Constructs a new empty region.
- *
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
- * </ul>
- */
-public Region() {
- this(null);
-}
-
-/**
- * Constructs a new empty region.
- * <p>
- * You must dispose the region when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the region
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
- * </ul>
- *
- * @see #dispose
- *
- * @since 3.0
- */
-public Region(Device device) {
- super(device);
- handle = OS.NewRgn();
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-Region(Device device, int handle) {
- super(device);
- this.handle = handle;
-}
-
-/**
- * Adds the given polygon to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param pointArray points that describe the polygon to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
-*
- */
-public void add (int[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (pointArray.length < 2) return;
- int polyRgn = OS.NewRgn();
- OS.OpenRgn();
- OS.MoveTo((short)pointArray[0], (short)pointArray[1]);
- for (int i = 1; i < pointArray.length / 2; i++) {
- OS.LineTo((short)pointArray[2 * i], (short)pointArray[2 * i + 1]);
- }
- OS.LineTo((short)pointArray[0], (short)pointArray[1]);
- OS.CloseRgn(polyRgn);
- OS.UnionRgn(handle, polyRgn, handle);
- OS.DisposeRgn(polyRgn);
-}
-
-/**
- * Adds the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void add(Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (rect.width < 0 || rect.height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- add (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Adds the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void add(int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int rectRgn = OS.NewRgn();
- Rect r = new Rect();
- OS.SetRect(r, (short)x, (short)y, (short)(x + width),(short)(y + height));
- OS.RectRgn(rectRgn, r);
- OS.UnionRgn(handle, rectRgn, handle);
- OS.DisposeRgn(rectRgn);
-}
-
-/**
- * Adds all of the polygons which make up the area covered
- * by the argument to the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to merge
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void add(Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.UnionRgn(handle, region.handle, handle);
-}
-
-/**
- * Returns <code>true</code> if the point specified by the
- * arguments is inside the area specified by the receiver,
- * and <code>false</code> otherwise.
- *
- * @param x the x coordinate of the point to test for containment
- * @param y the y coordinate of the point to test for containment
- * @return <code>true</code> if the region contains the point and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains(int x, int y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- org.eclipse.swt.internal.carbon.Point point = new org.eclipse.swt.internal.carbon.Point();
- OS.SetPt(point, (short)x, (short)y);
- return OS.PtInRgn(point, handle);
-}
-
-/**
- * Returns <code>true</code> if the given point is inside the
- * area specified by the receiver, and <code>false</code>
- * otherwise.
- *
- * @param pt the point to test for containment
- * @return <code>true</code> if the region contains the point and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains(Point pt) {
- if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return contains(pt.x, pt.y);
-}
-
-void destroy() {
- OS.DisposeRgn(handle);
- handle = 0;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals(Object object) {
- if (this == object) return true;
- if (!(object instanceof Region)) return false;
- Region region = (Region)object;
- return handle == region.handle;
-}
-
-/**
- * Returns a rectangle which represents the rectangular
- * union of the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @return a bounding rectangle for the region
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#union
- */
-public Rectangle getBounds() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Rect bounds = new Rect();
- OS.GetRegionBounds(handle, bounds);
- int width = bounds.right - bounds.left;
- int height = bounds.bottom - bounds.top;
- return new Rectangle(bounds.left, bounds.top, width, height);
-}
-
-public static Region carbon_new(Device device, int handle) {
- return new Region(device, handle);
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode() {
- return handle;
-}
-
-/**
- * Intersects the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to intersect with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void intersect(Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- intersect (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Intersects the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void intersect(int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int rectRgn = OS.NewRgn();
- Rect r = new Rect();
- OS.SetRect(r, (short)x, (short)y, (short)(x + width),(short)(y + height));
- OS.RectRgn(rectRgn, r);
- OS.SectRgn(handle, rectRgn, handle);
- OS.DisposeRgn(rectRgn);
-}
-
-/**
- * Intersects all of the polygons which make up the area covered
- * by the argument to the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to intersect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void intersect(Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.SectRgn(handle, region.handle, handle);
-}
-
-/**
- * Returns <code>true</code> if the rectangle described by the
- * arguments intersects with any of the polygons the receiver
- * maintains to describe its area, and <code>false</code> otherwise.
- *
- * @param x the x coordinate of the origin of the rectangle
- * @param y the y coordinate of the origin of the rectangle
- * @param width the width of the rectangle
- * @param height the height of the rectangle
- * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#intersects(Rectangle)
- */
-public boolean intersects (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Rect rect = new Rect();
- OS.SetRect(rect, (short)x, (short)y, (short)(x + width),(short)(y + height));
- return OS.RectInRgn(rect, handle);
-}
-
-/**
- * Returns <code>true</code> if the given rectangle intersects
- * with any of the polygons the receiver maintains to describe
- * its area and <code>false</code> otherwise.
- *
- * @param rect the rectangle to test for intersection
- * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#intersects(Rectangle)
- */
-public boolean intersects(Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return intersects(rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Returns <code>true</code> if the region has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the region.
- * When a region has been disposed, it is an error to
- * invoke any other method using the region.
- *
- * @return <code>true</code> when the region is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns <code>true</code> if the receiver does not cover any
- * area in the (x, y) coordinate plane, and <code>false</code> if
- * the receiver does cover some area in the plane.
- *
- * @return <code>true</code> if the receiver is empty, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean isEmpty() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return OS.EmptyRgn(handle);
-}
-
-/**
- * Subtracts the given polygon from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param pointArray points that describe the polygon to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract (int[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (pointArray.length < 2) return;
- int polyRgn = OS.NewRgn();
- OS.OpenRgn();
- OS.MoveTo((short)pointArray[0], (short)pointArray[1]);
- for (int i = 1; i < pointArray.length / 2; i++) {
- OS.LineTo((short)pointArray[2 * i], (short)pointArray[2 * i + 1]);
- }
- OS.LineTo((short)pointArray[0], (short)pointArray[1]);
- OS.CloseRgn(polyRgn);
- OS.DiffRgn(handle, polyRgn, handle);
- OS.DisposeRgn(polyRgn);
-}
-
-/**
- * Subtracts the given rectangle from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to subtract from the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract(Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- subtract (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Subtracts the given rectangle from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void subtract(int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int rectRgn = OS.NewRgn();
- Rect r = new Rect();
- OS.SetRect(r, (short)x, (short)y, (short)(x + width),(short)(y + height));
- OS.RectRgn(rectRgn, r);
- OS.DiffRgn(handle, rectRgn, handle);
- OS.DisposeRgn(rectRgn);
-}
-
-/**
- * Subtracts all of the polygons which make up the area covered
- * by the argument from the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to subtract
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract(Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.DiffRgn(handle, region.handle, handle);
-}
-
-/**
- * Translate all of the polygons the receiver maintains to describe
- * its area by the specified point.
- *
- * @param x the x coordinate of the point to translate
- * @param y the y coordinate of the point to translate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void translate (int x, int y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.OffsetRgn (handle, (short)x, (short)y);
-}
-
-/**
- * Translate all of the polygons the receiver maintains to describe
- * its area by the specified point.
- *
- * @param pt the point to translate
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void translate (Point pt) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- translate (pt.x, pt.y);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Region {*DISPOSED*}";
- return "Region {" + handle + "}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/TextLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/TextLayout.java
deleted file mode 100644
index 9e12f9642b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/TextLayout.java
+++ /dev/null
@@ -1,2204 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.carbon.*;
-import org.eclipse.swt.*;
-
-/**
- * <code>TextLayout</code> is a graphic object that represents
- * styled text.
- * <p>
- * Instances of this class provide support for drawing, cursor
- * navigation, hit testing, text wrapping, alignment, tab expansion
- * line breaking, etc. These are aspects required for rendering internationalized text.
- * </p><p>
- * Application code must explicitly invoke the <code>TextLayout#dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#textlayout">TextLayout, TextStyle snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: CustomControlExample, StyledText tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.0
- */
-public final class TextLayout extends Resource {
-
- static class StyleItem {
- TextStyle style;
- int start;
- int atsuStyle;
-
- void createStyle(Device device, Font defaultFont) {
- if (atsuStyle != 0) return;
- int[] buffer = new int[1];
- OS.ATSUCreateStyle(buffer);
- atsuStyle = buffer[0];
- if (atsuStyle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int length = 0, ptrLength = 0, index = 0;
- Font font = null;
- RGBColor foreground = null;
- GlyphMetrics metrics = null;
- if (style != null) {
- font = style.font;
- if (style.foreground != null) {
- float[] color = style.foreground.handle;
- foreground = new RGBColor ();
- foreground.red = (short) (color [0] * 0xffff);
- foreground.green = (short) (color [1] * 0xffff);
- foreground.blue = (short) (color [2] * 0xffff);
- } else {
- if (style.underline && style.underlineStyle == SWT.UNDERLINE_LINK) {
- foreground = new RGBColor ();
- foreground.red = (short) 0;
- foreground.green = (short) 0x3333;
- foreground.blue = (short) 0x9999;
- }
- }
- metrics = style.metrics;
- if (isUnderlineSupported(style)) {
- length += 1;
- ptrLength += 1;
- if (style.underlineStyle == SWT.UNDERLINE_DOUBLE) {
- length += 1;
- ptrLength += 2;
- }
- if (style.underlineColor != null) {
- length += 1;
- ptrLength += 4;
- }
- }
- if (style.strikeout) {
- length += 1;
- ptrLength += 1;
- if (style.strikeoutColor != null) {
- length += 1;
- ptrLength += 4;
- }
- }
- if (metrics != null) {
- length += 4;
- ptrLength += 28;
- }
- if (style.rise != 0) {
- length += 1;
- ptrLength += 4;
- }
- }
- if (font == null) font = defaultFont;
- boolean synthesize = false;
- if (font != null) {
- length += 2;
- ptrLength += 8;
- synthesize = font.style != 0;
- if (synthesize) {
- length += 2;
- ptrLength += 2;
- }
- }
- if (foreground != null && metrics == null) {
- length += 1;
- ptrLength += RGBColor.sizeof;
- }
- byte[] buffer1 = new byte[1];
- int[] tags = new int[length];
- int[] sizes = new int[length];
- int[] values = new int[length];
- int ptr = OS.NewPtr(ptrLength), ptr1 = ptr;
- if (font != null) {
- buffer[0] = font.handle;
- tags[index] = OS.kATSUFontTag;
- sizes[index] = 4;
- values[index] = ptr1;
- OS.memmove(values[index], buffer, sizes[index]);
- ptr1 += sizes[index];
- index++;
-
- buffer[0] = OS.X2Fix(font.size);
- tags[index] = OS.kATSUSizeTag;
- sizes[index] = 4;
- values[index] = ptr1;
- OS.memmove(values[index], buffer, sizes[index]);
- ptr1 += sizes[index];
- index++;
-
- if (synthesize) {
- buffer1[0] = (font.style & OS.italic) != 0 ? (byte)1 : 0;
- tags[index] = OS.kATSUQDItalicTag;
- sizes[index] = 1;
- values[index] = ptr1;
- OS.memmove(values[index], buffer1, sizes[index]);
- ptr1 += sizes[index];
- index++;
-
- buffer1[0] = (font.style & OS.bold) != 0 ? (byte)1 : 0;
- tags[index] = OS.kATSUQDBoldfaceTag;
- sizes[index] = 1;
- values[index] = ptr1;
- OS.memmove(values[index], buffer1, sizes[index]);
- ptr1 += sizes[index];
- index++;
- }
- }
- int underlineColor = 0, strikeoutColor = 0;;
- if (isUnderlineSupported(style)) {
- buffer1[0] = (byte)1;
- tags[index] = OS.kATSUQDUnderlineTag;
- sizes[index] = 1;
- values[index] = ptr1;
- OS.memmove(values[index], buffer1, sizes[index]);
- ptr1 += sizes[index];
- index++;
- if (style.underlineStyle == SWT.UNDERLINE_DOUBLE) {
- short buffer2[] = {OS.kATSUStyleDoubleLineCount};
- tags[index] = OS.kATSUStyleUnderlineCountOptionTag;
- sizes[index] = 2;
- values[index] = ptr1;
- OS.memmove(values[index], buffer2, sizes[index]);
- ptr1 += sizes[index];
- index++;
- }
- if (style.underlineColor != null) {
- buffer[0] = underlineColor = OS.CGColorCreate(device.colorspace, style.underlineColor.handle);
- tags[index] = OS.kATSUStyleUnderlineColorOptionTag;
- sizes[index] = 4;
- values[index] = ptr1;
- OS.memmove(values[index], buffer, sizes[index]);
- ptr1 += sizes[index];
- index++;
- }
- }
- if (style != null && style.strikeout) {
- buffer1[0] = (byte)1;
- tags[index] = OS.kATSUStyleStrikeThroughTag;
- sizes[index] = 1;
- values[index] = ptr1;
- OS.memmove(values[index], buffer1, sizes[index]);
- ptr1 += sizes[index];
- index++;
- if (style.strikeoutColor != null) {
- buffer[0] = strikeoutColor = OS.CGColorCreate(device.colorspace, style.strikeoutColor.handle);
- tags[index] = OS.kATSUStyleStrikeThroughColorOptionTag;
- sizes[index] = 4;
- values[index] = ptr1;
- OS.memmove(values[index], buffer, sizes[index]);
- ptr1 += sizes[index];
- index++;
- }
- }
- if (metrics != null) {
- buffer[0] = OS.Long2Fix(metrics.ascent);
- tags[index] = OS.kATSUAscentTag;
- sizes[index] = 4;
- values[index] = ptr1;
- OS.memmove(values[index], buffer, sizes[index]);
- ptr1 += sizes[index];
- index++;
-
- buffer[0] = OS.Long2Fix(metrics.descent);
- tags[index] = OS.kATSUDescentTag;
- sizes[index] = 4;
- values[index] = ptr1;
- OS.memmove(values[index], buffer, sizes[index]);
- ptr1 += sizes[index];
- index++;
-
- buffer[0] = OS.Long2Fix(metrics.width);
- tags[index] = OS.kATSUImposeWidthTag;
- sizes[index] = 4;
- values[index] = ptr1;
- OS.memmove(values[index], buffer, sizes[index]);
- ptr1 += sizes[index];
- index++;
-
- float[] ATSURGBAlphaColor = {0, 0, 0, 0};
- tags[index] = OS.kATSURGBAlphaColorTag;
- sizes[index] = 16;
- values[index] = ptr1;
- OS.memmove(values[index], ATSURGBAlphaColor, sizes[index]);
- ptr1 += sizes[index];
- index++;
- }
- if (style != null && style.rise != 0) {
- buffer[0] = OS.Long2Fix(style.rise);
- tags[index] = OS.kATSUCrossStreamShiftTag;
- sizes[index] = 4;
- values[index] = ptr1;
- OS.memmove(values[index], buffer, sizes[index]);
- ptr1 += sizes[index];
- index++;
- }
- if (foreground != null && metrics == null) {
- tags[index] = OS.kATSUColorTag;
- sizes[index] = RGBColor.sizeof;
- values[index] = ptr1;
- OS.memmove(values[index], foreground, sizes[index]);
- ptr1 += sizes[index];
- index++;
- }
- OS.ATSUSetAttributes(atsuStyle, tags.length, tags, sizes, values);
- OS.DisposePtr(ptr);
- if (underlineColor != 0) OS.CGColorRelease (underlineColor);
- if (strikeoutColor != 0) OS.CGColorRelease (strikeoutColor);
- }
-
- void freeStyle() {
- if (atsuStyle == 0) return;
- OS.ATSUDisposeStyle(atsuStyle);
- atsuStyle = 0;
- }
-
- public String toString () {
- return "StyleItem {" + start + ", " + style + "}";
- }
- }
-
- Font font;
- String text;
- int textPtr;
- StyleItem[] styles;
- int layout;
- int spacing, ascent, descent, indent;
- int indentStyle;
- int[] tabs;
- int[] segments;
- int tabsPtr;
- int[] breaks, hardBreaks, lineX, lineWidth, lineHeight, lineAscent;
-
- static final int TAB_COUNT = 32;
- int[] invalidOffsets;
- static final char LTR_MARK = '\u200E', RTL_MARK = '\u200F', ZWS = '\u200B';
-
- static final int UNDERLINE_IME_INPUT = 1 << 16;
- static final int UNDERLINE_IME_TARGET_CONVERTED = 2 << 16;
- static final int UNDERLINE_IME_CONVERTED = 3 << 16;
-
-/**
- * Constructs a new instance of this class on the given device.
- * <p>
- * You must dispose the text layout when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the text layout
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- *
- * @see #dispose()
- */
-public TextLayout (Device device) {
- super(device);
- int[] buffer = new int[1];
- OS.ATSUCreateTextLayout(buffer);
- if (buffer[0] == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- layout = buffer[0];
- setLayoutControl(OS.kATSULineDirectionTag, OS.kATSULeftToRightBaseDirection, 1);
- int lineOptions = OS.kATSLineLastNoJustification | OS.kATSLineUseDeviceMetrics | OS.kATSLineKeepSpacesOutOfMargin;
- setLayoutControl(OS.kATSULineLayoutOptionsTag, lineOptions, 4);
- OS.ATSUSetHighlightingMethod(layout, OS.kRedrawHighlighting, new ATSUUnhighlightData());
- ascent = descent = -1;
- text = "";
- styles = new StyleItem[2];
- styles[0] = new StyleItem();
- styles[1] = new StyleItem();
- init();
-}
-
-void checkLayout() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-void computeRuns() {
- if (breaks != null) return;
- String segmentsText = getSegmentsText();
- int textLength = segmentsText.length();
- char[] chars = new char[textLength + 1];
- segmentsText.getChars(0, textLength, chars, 1);
- chars[0] = ZWS;
- int breakCount = 1;
- for (int i = 0; i < chars.length; i++) {
- char c = chars[i];
- if (c == '\n' || c == '\r') {
- breakCount++;
- }
- }
- hardBreaks = new int [breakCount];
- breakCount = 0;
- for (int i = 0; i < chars.length; i++) {
- char c = chars[i];
- if (c == '\n' || c == '\r') {
- chars[i] = ZWS;
- hardBreaks[breakCount++] = i;
- }
- }
- if (invalidOffsets != null) {
- for (int i = 0; i < invalidOffsets.length; i++) {
- invalidOffsets[i]++;
- }
- } else {
- invalidOffsets = new int[0];
- }
-
- hardBreaks[breakCount] = chars.length;
- int newTextPtr = OS.NewPtr(chars.length * 2);
- OS.memmove(newTextPtr, chars, chars.length * 2);
- OS.ATSUSetTextPointerLocation(layout, newTextPtr, 0, chars.length, chars.length);
- OS.ATSUSetTransientFontMatching(layout, true);
- if (textPtr != 0) OS.DisposePtr(textPtr);
- textPtr = newTextPtr;
-
- int[] buffer = new int[1];
- Font font = this.font != null ? this.font : device.systemFont;
- for (int i = 0; i < styles.length - 1; i++) {
- StyleItem run = styles[i];
- run.createStyle(device, font);
- //set the default font in the ZWS when text is empty fixes text metrics
- int start = textLength != 0 ? translateOffset(run.start) : 0;
- int runLength = translateOffset(styles[i + 1].start) - start;
- OS.ATSUSetRunStyle(layout, run.atsuStyle, start, runLength);
- }
- int ptr = OS.NewPtr(12);
- buffer = new int[]{OS.Long2Fix(indent), 0, 0};
- OS.memmove(ptr, buffer, 12);
- int[] tags = new int[]{OS.kATSUImposeWidthTag, OS.kATSUAscentTag, OS.kATSUDescentTag};
- int[] sizes = new int[]{4, 4, 4};
- int[] values = new int[]{ptr, ptr + 4, ptr + 8};
- OS.ATSUCreateStyle(buffer);
- indentStyle = buffer[0];
- OS.ATSUSetAttributes(indentStyle, tags.length, tags, sizes, values);
- OS.DisposePtr(ptr);
- OS.ATSUSetRunStyle(layout, indentStyle, 0, 1);
- for (int i = 0; i < hardBreaks.length-1; i++) {
- int offset = hardBreaks[i];
- OS.ATSUSetRunStyle(layout, indentStyle, offset, 1);
- }
- OS.ATSUGetLayoutControl(layout, OS.kATSULineWidthTag, 4, buffer, null);
- int wrapWidth = buffer[0];
- for (int i=0, start=0; i<hardBreaks.length; i++) {
- int hardBreak = hardBreaks[i];
- buffer[0] = 0;
- if (wrapWidth != 0) OS.ATSUBatchBreakLines(layout, start, hardBreak - start, wrapWidth, buffer);
- OS.ATSUSetSoftLineBreak(layout, hardBreak);
- start = hardBreak;
- }
- OS.ATSUGetSoftLineBreaks(layout, 0, OS.kATSUToTextEnd, 0, null, buffer);
- int count = buffer[0];
- breaks = new int[count];
- OS.ATSUGetSoftLineBreaks(layout, 0, OS.kATSUToTextEnd, count, breaks, null);
- int lineCount = breaks.length;
- lineX = new int[lineCount];
- lineWidth = new int[lineCount];
- lineHeight = new int[lineCount];
- lineAscent = new int[lineCount];
- ATSTrapezoid trapezoid = new ATSTrapezoid();
- for (int i=0, start=0; i<lineCount; i++) {
- if (ascent != -1) {
- ptr = OS.NewPtr(4);
- buffer[0] = OS.kATSUseLineHeight;
- OS.memmove(ptr, buffer, 4);
- tags = new int[]{OS.kATSULineAscentTag};
- sizes = new int[]{4};
- values = new int[]{ptr};
- OS.ATSUSetLineControls(layout, start, tags.length, tags, sizes, values);
- OS.ATSUGetLineControl(layout, start, OS.kATSULineAscentTag, 4, buffer, null);
- buffer[0] = OS.Long2Fix(Math.max(ascent, OS.Fix2Long(buffer[0])));
- OS.memmove(ptr, buffer, 4);
- OS.ATSUSetLineControls(layout, start, tags.length, tags, sizes, values);
- OS.DisposePtr(ptr);
- }
- if (descent != -1) {
- ptr = OS.NewPtr(4);
- buffer[0] = OS.kATSUseLineHeight;
- OS.memmove(ptr, buffer, 4);
- tags = new int[]{OS.kATSULineDescentTag};
- sizes = new int[]{4};
- values = new int[]{ptr};
- OS.ATSUSetLineControls(layout, start, tags.length, tags, sizes, values);
- OS.ATSUGetLineControl(layout, start, OS.kATSULineDescentTag, 4, buffer, null);
- buffer[0] = OS.Long2Fix(Math.max(descent, OS.Fix2Long(buffer[0])));
- OS.memmove(ptr, buffer, 4);
- OS.ATSUSetLineControls(layout, start, tags.length, tags, sizes, values);
- OS.DisposePtr(ptr);
- }
- int lineBreak = breaks[i];
- int lineLength = lineBreak - start;
- OS.ATSUGetGlyphBounds(layout, 0, 0, start, lineLength, (short)OS.kATSUseDeviceOrigins, 1, trapezoid, null);
- lineX[i] = OS.Fix2Long(trapezoid.lowerLeft_x);
- lineAscent[i] = -OS.Fix2Long(trapezoid.upperRight_y);
- if (lineLength != 0) {
- lineWidth[i] = OS.Fix2Long(trapezoid.lowerRight_x) - OS.Fix2Long(trapezoid.lowerLeft_x);
- }
- lineHeight[i] = OS.Fix2Long(trapezoid.lowerRight_y) + lineAscent[i] + spacing;
- start = lineBreak;
- }
-}
-
-float[] computePolyline(int left, int top, int right, int bottom) {
- int height = bottom - top; // can be any number
- int width = 2 * height; // must be even
- int peaks = Compatibility.ceil(right - left, width);
- if (peaks == 0 && right - left > 2) {
- peaks = 1;
- }
- int length = ((2 * peaks) + 1) * 2;
- if (length < 0) return new float[0];
-
- float[] coordinates = new float[length];
- for (int i = 0; i < peaks; i++) {
- int index = 4 * i;
- coordinates[index] = left + (width * i);
- coordinates[index+1] = bottom;
- coordinates[index+2] = coordinates[index] + width / 2;
- coordinates[index+3] = top;
- }
- coordinates[length-2] = left + (width * peaks);
- coordinates[length-1] = bottom;
- return coordinates;
-}
-
-void destroy() {
- freeRuns();
- font = null;
- text = null;
- styles = null;
- if (layout != 0) OS.ATSUDisposeTextLayout(layout);
- layout = 0;
- if (textPtr != 0) OS.DisposePtr(textPtr);
- textPtr = 0;
- if (tabsPtr != 0) OS.DisposePtr(tabsPtr);
- tabsPtr = 0;
- if (indentStyle != 0) OS.ATSUDisposeStyle(indentStyle);
- indentStyle = 0;
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- *
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- */
-public void draw(GC gc, int x, int y) {
- draw(gc, x, y, -1, -1, null, null);
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- *
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param selectionStart the offset where the selections starts, or -1 indicating no selection
- * @param selectionEnd the offset where the selections ends, or -1 indicating no selection
- * @param selectionForeground selection foreground, or NULL to use the system default color
- * @param selectionBackground selection background, or NULL to use the system default color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- */
-public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground) {
- draw(gc, x, y, selectionStart, selectionEnd, selectionForeground, selectionBackground, 0);
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- * <p>
- * The parameter <code>flags</code> can include one of <code>SWT.DELIMITER_SELECTION</code>
- * or <code>SWT.FULL_SELECTION</code> to specify the selection behavior on all lines except
- * for the last line, and can also include <code>SWT.LAST_LINE_SELECTION</code> to extend
- * the specified selection behavior to the last line.
- * </p>
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param selectionStart the offset where the selections starts, or -1 indicating no selection
- * @param selectionEnd the offset where the selections ends, or -1 indicating no selection
- * @param selectionForeground selection foreground, or NULL to use the system default color
- * @param selectionBackground selection background, or NULL to use the system default color
- * @param flags drawing options
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- *
- * @since 3.3
- */
-public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags) {
- checkLayout ();
- computeRuns();
- if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (selectionForeground != null && selectionForeground.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (selectionBackground != null && selectionBackground.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int length = translateOffset(text.length());
- if (length == 0 && flags == 0) return;
- gc.checkGC(GC.FOREGROUND_FILL);
- if (gc.data.updateClip) gc.setCGClipping();
- OS.CGContextSaveGState(gc.handle);
- setLayoutControl(OS.kATSUCGContextTag, gc.handle, 4);
- boolean hasSelection = selectionStart <= selectionEnd && selectionStart != -1 && selectionEnd != -1;
- boolean restoreColor = false;
- if (hasSelection || (flags & SWT.LAST_LINE_SELECTION) != 0) {
- if (selectionBackground != null) {
- restoreColor = true;
- int color = OS.CGColorCreate(device.colorspace, selectionBackground.handle);
- setLayoutControl(OS.kATSULineHighlightCGColorTag, color, 4);
- OS.CGColorRelease(color);
- } else {
- selectionBackground = device.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
- }
- }
- /*
- * Feature in ATSU. There is no API to set a background attribute
- * of an ATSU style. Draw the background of styles ourselfs.
- */
- int rgn = 0;
- CGRect rect = null;
- for (int j = 0; j < styles.length; j++) {
- StyleItem run = styles[j];
- TextStyle style = run.style;
- if (style == null || style.background == null) continue;
- int start = translateOffset(run.start);
- int end = j + 1 < styles.length ? translateOffset(styles[j + 1].start - 1) : length;
- for (int i=0, lineStart=0, lineY = 0; i<breaks.length; i++) {
- int lineBreak = breaks[i];
- int lineEnd = lineBreak - 1;
- if (!(start > lineEnd || end < lineStart)) {
- int highStart = Math.max(lineStart, start);
- int highEnd = Math.min(lineEnd, end);
- int highLen = highEnd - highStart + 1;
- if (highLen > 0) {
- OS.CGContextSaveGState(gc.handle);
- if (rgn == 0) rgn = OS.NewRgn();
- OS.ATSUGetTextHighlight(layout, OS.Long2Fix(x), OS.Long2Fix(y + lineY + lineAscent[i]), highStart, highLen, rgn);
- int shape = OS.HIShapeCreateWithQDRgn(rgn);
- OS.HIShapeReplacePathInCGContext(shape, gc.handle);
- if (rect == null) rect = new CGRect();
- OS.CGContextGetPathBoundingBox(gc.handle, rect);
- OS.CGContextEOClip(gc.handle);
- OS.CGContextSetFillColorSpace(gc.handle, device.colorspace);
- OS.CGContextSetFillColor(gc.handle, style.background.handle);
- OS.CGContextFillRect(gc.handle, rect);
- OS.DisposeControl(shape);
- OS.CGContextRestoreGState(gc.handle);
- }
- }
- if (lineEnd > end) break;
- lineY += lineHeight[i];
- lineStart = lineBreak;
- }
- }
-
- selectionStart = translateOffset(selectionStart);
- selectionEnd = translateOffset(selectionEnd);
- OS.CGContextScaleCTM(gc.handle, 1, -1);
- int drawX = OS.Long2Fix(x);
- int drawY = y;
- for (int i=0, start=0; i<breaks.length; i++) {
- int lineBreak = breaks[i];
- int lineLength = lineBreak - start;
- if (lineLength > 0) {
- int fixYDraw = OS.Long2Fix(-(drawY + lineAscent[i]));
- OS.ATSUDrawText(layout, start, lineLength, drawX, fixYDraw);
- int end = start + lineLength - 1;
- if (flags != 0 && (hasSelection || (flags & SWT.LAST_LINE_SELECTION) != 0)) {
- boolean extent = false;
- if (i == breaks.length - 1 && (flags & SWT.LAST_LINE_SELECTION) != 0) {
- extent = true;
- } else {
- boolean hardBreak = false;
- for (int j = 0; j < hardBreaks.length; j++) {
- if (end + 1 == hardBreaks[j]) {
- hardBreak = true;
- break;
- }
- }
- if (hardBreak) {
- if (selectionStart <= end + 1 && end + 1 <= selectionEnd) extent = true;
- } else {
- if (selectionStart <= end + 1 && end + 1 < selectionEnd && (flags & SWT.FULL_SELECTION) != 0) {
- extent = true;
- }
- }
- }
- if (extent) {
- if (rect == null) rect = new CGRect();
- rect.x = x + lineWidth[i];
- rect.y = drawY;
- rect.width = (flags & SWT.FULL_SELECTION) != 0 ? 0x7fffffff : lineHeight[i] / 3;
- rect.height = lineHeight[i];
- OS.CGContextSaveGState(gc.handle);
- OS.CGContextTranslateCTM(gc.handle, 0, -(lineHeight[i] + 2 * drawY));
- OS.CGContextSetFillColorSpace(gc.handle, device.colorspace);
- OS.CGContextSetFillColor(gc.handle, selectionBackground.handle);
- OS.CGContextFillRect(gc.handle, rect);
- OS.CGContextRestoreGState(gc.handle);
- }
- }
- if (hasSelection && !(selectionStart > end || start > selectionEnd)) {
- int selStart = Math.max(selectionStart, start);
- int selEnd = Math.min(selectionEnd, end);
- OS.ATSUHighlightText(layout, drawX, fixYDraw, selStart, selEnd - selStart + 1);
- }
- }
- drawY += lineHeight[i];
- start = lineBreak;
- }
- if (restoreColor) setLayoutControl(OS.kATSULineHighlightCGColorTag, 0, 4);
- OS.CGContextRestoreGState(gc.handle);
-
- for (int j = 0; j < styles.length; j++) {
- StyleItem run = styles[j];
- TextStyle style = run.style;
- if (style == null) continue;
- boolean drawUnderline = style.underline && !isUnderlineSupported(style);
- drawUnderline = drawUnderline && (j + 1 == styles.length || !style.isAdherentUnderline(styles[j + 1].style));
- boolean drawBorder = style.borderStyle != SWT.NONE;
- drawBorder = drawBorder && (j + 1 == styles.length || !style.isAdherentBorder(styles[j + 1].style));
- if (!drawUnderline && !drawBorder) continue;
- int end = j + 1 < styles.length ? translateOffset(styles[j + 1].start - 1) : length;
- for (int i=0, lineStart=0, lineY = 0; i<breaks.length; i++) {
- int lineBreak = breaks[i];
- int lineEnd = lineBreak - 1;
- if (drawUnderline) {
- int start = run.start;
- for (int k = j; k > 0 && style.isAdherentUnderline(styles[k - 1].style); k--) {
- start = styles[k - 1].start;
- }
- start = translateOffset(start);
- if (!(start > lineEnd || end < lineStart)) {
- int highStart = Math.max(lineStart, start);
- int highEnd = Math.min(lineEnd, end);
- int highLen = highEnd - highStart + 1;
- if (highLen > 0) {
- OS.CGContextSaveGState(gc.handle);
- float underlineY = y + lineY;
- float[] foreground = gc.data.foreground;
- float lineWidth = 1;
- float[] dashes = null;
- int lineCap = OS.kCGLineCapButt;
- int lineJoin = OS.kCGLineJoinMiter;
- switch (style.underlineStyle) {
- case SWT.UNDERLINE_ERROR:
- lineWidth = 2;
- dashes = new float[]{1, 3};
- lineCap = OS.kCGLineCapRound;
- lineJoin = OS.kCGLineJoinRound;
- //FALLTHROUGH
- case SWT.UNDERLINE_SQUIGGLE:
- if (style.underlineColor != null) {
- foreground = style.underlineColor.handle;
- } else {
- if (style.foreground != null) {
- foreground = style.foreground.handle;
- }
- }
- underlineY += 2 * lineAscent [i] + lineWidth;
- break;
- case UNDERLINE_IME_INPUT:
- case UNDERLINE_IME_TARGET_CONVERTED:
- case UNDERLINE_IME_CONVERTED:
- lineWidth = 1.5f;
- foreground = style.underlineStyle == UNDERLINE_IME_CONVERTED ? new float[]{0.5f, 0.5f, 0.5f, 1} : new float[]{0, 0, 0, 1};
- Font font = style.font;
- if (font == null) font = this.font != null ? this.font : device.systemFont;
- ATSFontMetrics metrics = new ATSFontMetrics();
- OS.ATSFontGetHorizontalMetrics(font.handle, OS.kATSOptionFlagsDefault, metrics);
- underlineY += lineAscent [i] + lineHeight [i] + (metrics.descent * font.size);
- break;
- }
- OS.CGContextSetStrokeColorSpace(gc.handle, device.colorspace);
- OS.CGContextSetStrokeColor(gc.handle, foreground);
- OS.CGContextSetLineWidth(gc.handle, lineWidth);
- OS.CGContextSetLineCap(gc.handle, lineCap);
- OS.CGContextSetLineJoin(gc.handle, lineJoin);
- OS.CGContextSetLineDash(gc.handle, 0, dashes, dashes != null ? dashes.length : 0);
- OS.CGContextTranslateCTM(gc.handle, 0.5f, 0.5f);
-
- int[] count = new int[1];
- OS.ATSUGetGlyphBounds(layout, OS.Long2Fix(x), OS.X2Fix(underlineY), highStart, highLen, (short)OS.kATSUseDeviceOrigins, 0, 0, count);
- int trapezoidsPtr = OS.malloc(count[0] * ATSTrapezoid.sizeof);
- OS.ATSUGetGlyphBounds(layout, OS.Long2Fix(x), OS.X2Fix(underlineY), highStart, highLen, (short)OS.kATSUseDeviceOrigins, count[0], trapezoidsPtr, count);
- ATSTrapezoid trapezoid = new ATSTrapezoid();
- for (int k = 0; k < count[0]; k++) {
- OS.memmove(trapezoid, trapezoidsPtr + (k * ATSTrapezoid.sizeof), ATSTrapezoid.sizeof);
- float left, right;
- if (trapezoid.upperLeft_x != trapezoid.lowerLeft_x) {
- float ux = OS.Fix2Long(trapezoid.upperLeft_x);
- float uy = OS.Fix2Long(trapezoid.upperLeft_y);
- float lx = OS.Fix2Long(trapezoid.lowerLeft_x);
- float ly = OS.Fix2Long(trapezoid.lowerLeft_y);
- float a = (uy - ly) / (ux - lx);
- float b = uy - ux * a;
- left = (underlineY - b) / a;
- } else {
- left = OS.Fix2Long(trapezoid.upperLeft_x);
- }
- if (trapezoid.upperRight_x != trapezoid.lowerRight_x) {
- float ux = OS.Fix2Long(trapezoid.upperRight_x);
- float uy = OS.Fix2Long(trapezoid.upperRight_y);
- float lx = OS.Fix2Long(trapezoid.lowerRight_x);
- float ly = OS.Fix2Long(trapezoid.lowerRight_y);
- float a = (uy - ly) / (ux - lx);
- float b = uy - ux * a;
- right = (underlineY - b) / a;
- } else {
- right = OS.Fix2Long(trapezoid.upperRight_x);
- }
- switch (style.underlineStyle) {
- case UNDERLINE_IME_TARGET_CONVERTED:
- case UNDERLINE_IME_CONVERTED:
- left += 1;
- right -= 1;
- }
- if (style.underlineStyle == SWT.UNDERLINE_SQUIGGLE) {
- int lineBottom = y + lineY + lineHeight[i];
- int squigglyThickness = 1;
- int squigglyHeight = 2 * squigglyThickness;
- float squigglyY = Math.min(OS.Fix2Long(trapezoid.upperLeft_y) - squigglyHeight / 2, lineBottom - squigglyHeight - 1);
- float[] points = computePolyline((int)left, (int)squigglyY, (int)right, (int)(squigglyY + squigglyHeight));
- OS.CGContextBeginPath(gc.handle);
- OS.CGContextAddLines(gc.handle, points, points.length / 2);
- } else {
- OS.CGContextMoveToPoint(gc.handle, left, OS.Fix2Long(trapezoid.upperLeft_y));
- OS.CGContextAddLineToPoint(gc.handle, right, OS.Fix2Long(trapezoid.upperRight_y));
- }
- }
- OS.free(trapezoidsPtr);
- OS.CGContextStrokePath(gc.handle);
- OS.CGContextRestoreGState(gc.handle);
- }
- }
- }
-
- if (drawBorder) {
- int start = run.start;
- for (int k = j; k > 0 && style.isAdherentBorder(styles[k - 1].style); k--) {
- start = styles[k - 1].start;
- }
- start = translateOffset(start);
- if (!(start > lineEnd || end < lineStart)) {
- int highStart = Math.max(lineStart, start);
- int highEnd = Math.min(lineEnd, end);
- int highLen = highEnd - highStart + 1;
- if (highLen > 0) {
- OS.CGContextSaveGState(gc.handle);
- int[] count = new int[1];
- OS.ATSUGetGlyphBounds(layout, OS.Long2Fix(x), OS.Long2Fix(y + lineY + lineAscent[i]), highStart, highLen, (short)OS.kATSUseDeviceOrigins, 0, 0, count);
- int trapezoidsPtr = OS.malloc(count[0] * ATSTrapezoid.sizeof);
- OS.ATSUGetGlyphBounds(layout, OS.Long2Fix(x), OS.Long2Fix(y + lineY + lineAscent[i]), highStart, highLen, (short)OS.kATSUseDeviceOrigins, count[0], trapezoidsPtr, count);
- ATSTrapezoid trapezoid = new ATSTrapezoid();
- for (int k = 0; k < count[0]; k++) {
- OS.memmove(trapezoid, trapezoidsPtr + (k * ATSTrapezoid.sizeof), ATSTrapezoid.sizeof);
- int upperY = y + lineY + 1;
- int lowerY = y + lineY + lineHeight[i];
- OS.CGContextMoveToPoint(gc.handle, OS.Fix2Long(trapezoid.lowerLeft_x), lowerY);
- OS.CGContextAddLineToPoint(gc.handle, OS.Fix2Long(trapezoid.upperLeft_x), upperY);
- OS.CGContextAddLineToPoint(gc.handle, OS.Fix2Long(trapezoid.upperRight_x) - 1, upperY);
- OS.CGContextAddLineToPoint(gc.handle, OS.Fix2Long(trapezoid.lowerRight_x) - 1, lowerY);
- OS.CGContextClosePath(gc.handle);
- }
- OS.free(trapezoidsPtr);
- int width = 1;
- OS.CGContextSetShouldAntialias(gc.handle, false);
- OS.CGContextSetLineCap(gc.handle, OS.kCGLineCapButt);
- OS.CGContextSetLineJoin(gc.handle, OS.kCGLineJoinMiter);
- OS.CGContextSetLineWidth(gc.handle, width);
- float[] dashes = null;
- switch (style.borderStyle) {
- case SWT.BORDER_SOLID: break;
- case SWT.BORDER_DASH: dashes = width != 0 ? GC.LINE_DASH : GC.LINE_DASH_ZERO; break;
- case SWT.BORDER_DOT: dashes = width != 0 ? GC.LINE_DOT : GC.LINE_DOT_ZERO; break;
- }
- OS.CGContextSetLineDash(gc.handle, 0, dashes, dashes != null ? dashes.length : 0);
- float[] color = null;
- if (style.borderColor != null) color = style.borderColor.handle;
- if (color == null && style.foreground != null) color = style.foreground.handle;
- if (color != null) {
- OS.CGContextSetStrokeColorSpace(gc.handle, device.colorspace);
- OS.CGContextSetStrokeColor(gc.handle, color);
- }
- OS.CGContextTranslateCTM (gc.handle, 0.5f, 0.5f);
- OS.CGContextStrokePath(gc.handle);
- OS.CGContextRestoreGState(gc.handle);
- }
- }
- }
- if (lineEnd > end) break;
- lineY += lineHeight[i];
- lineStart = lineBreak;
- }
- }
- if (rgn != 0) OS.DisposeRgn(rgn);
-}
-
-void freeRuns() {
- if (breaks == null) return;
- for (int i = 0; i < styles.length; i++) {
- StyleItem run = styles[i];
- run.freeStyle();
- }
- if (indentStyle != 0) OS.ATSUDisposeStyle(indentStyle);
- indentStyle = 0;
- breaks = lineX = lineWidth = lineHeight = lineAscent = null;
- invalidOffsets = null;
-}
-
-/**
- * Returns the receiver's horizontal text alignment, which will be one
- * of <code>SWT.LEFT</code>, <code>SWT.CENTER</code> or
- * <code>SWT.RIGHT</code>.
- *
- * @return the alignment used to positioned text horizontally
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getAlignment() {
- checkLayout();
- int[] buffer = new int[1];
- OS.ATSUGetLayoutControl(layout, OS.kATSULineFlushFactorTag, 4, buffer, null);
- switch (buffer[0]) {
- case OS.kATSUCenterAlignment: return SWT.CENTER;
- case OS.kATSUEndAlignment: return SWT.RIGHT;
- }
- return SWT.LEFT;
-}
-
-/**
- * Returns the ascent of the receiver.
- *
- * @return the ascent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getDescent()
- * @see #setDescent(int)
- * @see #setAscent(int)
- * @see #getLineMetrics(int)
- */
-public int getAscent () {
- checkLayout();
- return ascent;
-}
-
-/**
- * Returns the bounds of the receiver. The width returned is either the
- * width of the longest line or the width set using {@link TextLayout#setWidth(int)}.
- * To obtain the text bounds of a line use {@link TextLayout#getLineBounds(int)}.
- *
- * @return the bounds of the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setWidth(int)
- * @see #getLineBounds(int)
- */
-public Rectangle getBounds() {
- checkLayout();
- computeRuns();
- int width = 0, height = 0;
- int length = text.length();
- if (length == 0) {
- Font font = this.font != null ? this.font : device.systemFont;
- ATSFontMetrics metrics = new ATSFontMetrics();
- OS.ATSFontGetVerticalMetrics(font.handle, OS.kATSOptionFlagsDefault, metrics);
- OS.ATSFontGetHorizontalMetrics(font.handle, OS.kATSOptionFlagsDefault, metrics);
- int ascent = (int)(0.5f + metrics.ascent * font.size);
- int descent = (int)(0.5f + (-metrics.descent + metrics.leading) * font.size);
- ascent = Math.max(ascent, this.ascent);
- descent = Math.max(descent, this.descent);
- height = ascent + descent;
- } else {
- for (int i=0; i<breaks.length; i++) {
- width = Math.max(width, lineWidth[i]);
- height += lineHeight[i];
- }
- }
- int[] buffer = new int[1];
- OS.ATSUGetLayoutControl(layout, OS.kATSULineWidthTag, 4, buffer, null);
- int wrapWidth = OS.Fix2Long(buffer[0]);
- if (wrapWidth != 0) width = Math.max(width, wrapWidth);
- return new Rectangle(0, 0, width, height);
-}
-
-/**
- * Returns the bounds for the specified range of characters. The
- * bounds is the smallest rectangle that encompasses all characters
- * in the range. The start and end offsets are inclusive and will be
- * clamped if out of range.
- *
- * @param start the start offset
- * @param end the end offset
- * @return the bounds of the character range
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds(int start, int end) {
- checkLayout();
- computeRuns();
- int length = text.length();
- if (length == 0) return new Rectangle(0, 0, 0, 0);
- if (start > end) return new Rectangle(0, 0, 0, 0);
- start = Math.min(Math.max(0, start), length - 1);
- end = Math.min(Math.max(0, end), length - 1);
- start = translateOffset(start);
- end = translateOffset(end);
- for (int i = 0; i < hardBreaks.length; i++) {
- if (start == hardBreaks[i]) {
- if (start > 0) start--;
- }
- if (end == hardBreaks[i]) {
- if (end > 0) end--;
- }
- }
- int rgn = OS.NewRgn();
- Rect rect = new Rect();
- Rect rect1 = new Rect();
- for (int i=0, lineStart=0, lineY = 0; i<breaks.length; i++) {
- int lineBreak = breaks[i];
- int lineEnd = lineBreak - 1;
- if (!(start > lineEnd || end < lineStart)) {
- int highStart = Math.max(lineStart, start);
- int highEnd = Math.min(lineEnd, end);
- int highLen = highEnd - highStart + 1;
- if (highLen > 0) {
- OS.ATSUGetTextHighlight(layout, 0, OS.Long2Fix(lineY + lineAscent[i]), highStart, highLen, rgn);
- OS.GetRegionBounds(rgn, rect1);
- OS.UnionRect(rect, rect1, rect);
- }
- }
- if (lineEnd > end) break;
- lineY += lineHeight[i];
- lineStart = lineBreak;
- }
- OS.DisposeRgn(rgn);
- return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
-}
-
-/**
- * Returns the descent of the receiver.
- *
- * @return the descent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getAscent()
- * @see #setAscent(int)
- * @see #setDescent(int)
- * @see #getLineMetrics(int)
- */
-public int getDescent () {
- checkLayout();
- return descent;
-}
-
-/**
- * Returns the default font currently being used by the receiver
- * to draw and measure text.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getFont () {
- checkLayout();
- return font;
-}
-
-/**
-* Returns the receiver's indent.
-*
-* @return the receiver's indent
-*
-* @exception SWTException <ul>
-* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
-* </ul>
-*
-* @since 3.2
-*/
-public int getIndent () {
- checkLayout();
- return indent;
-}
-
-/**
-* Returns the receiver's justification.
-*
-* @return the receiver's justification
-*
-* @exception SWTException <ul>
-* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
-* </ul>
-*
-* @since 3.2
-*/
-public boolean getJustify () {
- checkLayout();
- int[] buffer = new int[1];
- OS.ATSUGetLayoutControl(layout, OS.kATSULineJustificationFactorTag, 4, buffer, null);
- return buffer[0] == OS.kATSUFullJustification;
-}
-
-/**
- * Returns the embedding level for the specified character offset. The
- * embedding level is usually used to determine the directionality of a
- * character in bidirectional text.
- *
- * @param offset the character offset
- * @return the embedding level
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- */
-public int getLevel(int offset) {
- checkLayout();
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- offset = translateOffset(offset);
- int level = 0;
- //TODO
- return level;
-}
-
-/**
- * Returns the line offsets. Each value in the array is the
- * offset for the first character in a line except for the last
- * value, which contains the length of the text.
- *
- * @return the line offsets
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getLineOffsets() {
- checkLayout ();
- computeRuns();
- int[] offsets = new int[breaks.length + 1];
- for (int i = 1; i < offsets.length; i++) {
- offsets[i] = untranslateOffset(breaks[i - 1]);
- }
- return offsets;
-}
-
-/**
- * Returns the index of the line that contains the specified
- * character offset.
- *
- * @param offset the character offset
- * @return the line index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineIndex(int offset) {
- checkLayout ();
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- offset = translateOffset(offset);
- for (int i=0; i<breaks.length-1; i++) {
- int lineBreak = breaks[i];
- if (lineBreak > offset) return i;
- }
- return breaks.length - 1;
-}
-
-/**
- * Returns the bounds of the line for the specified line index.
- *
- * @param lineIndex the line index
- * @return the line bounds
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getLineBounds(int lineIndex) {
- checkLayout();
- computeRuns();
- int lineCount = breaks.length;
- if (!(0 <= lineIndex && lineIndex < lineCount)) SWT.error(SWT.ERROR_INVALID_RANGE);
- int lineY = 0;
- for (int i=0; i<lineIndex; i++) {
- lineY += lineHeight[i];
- }
- int lineX = this.lineX[lineIndex];
- int lineWidth = this.lineWidth[lineIndex];
- int lineHeight = this.lineHeight[lineIndex] - spacing;
- return new Rectangle(lineX, lineY, lineWidth, lineHeight);
-}
-
-/**
- * Returns the receiver's line count. This includes lines caused
- * by wrapping.
- *
- * @return the line count
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineCount() {
- checkLayout ();
- computeRuns();
- return breaks.length;
-}
-
-/**
- * Returns the font metrics for the specified line index.
- *
- * @param lineIndex the line index
- * @return the font metrics
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontMetrics getLineMetrics (int lineIndex) {
- checkLayout ();
- computeRuns();
- int lineCount = breaks.length;
- if (!(0 <= lineIndex && lineIndex < lineCount)) SWT.error(SWT.ERROR_INVALID_RANGE);
- int length = text.length();
- if (length == 0) {
- Font font = this.font != null ? this.font : device.systemFont;
- ATSFontMetrics metrics = new ATSFontMetrics();
- OS.ATSFontGetVerticalMetrics(font.handle, OS.kATSOptionFlagsDefault, metrics);
- OS.ATSFontGetHorizontalMetrics(font.handle, OS.kATSOptionFlagsDefault, metrics);
- int ascent = (int)(0.5f + metrics.ascent * font.size);
- int descent = (int)(0.5f + (-metrics.descent + metrics.leading) * font.size);
- ascent = Math.max(ascent, this.ascent);
- descent = Math.max(descent, this.descent);
- return FontMetrics.carbon_new(ascent, descent, 0, 0, ascent + descent);
- }
- int start = lineIndex == 0 ? 0 : breaks[lineIndex - 1];
- int lineLength = breaks[lineIndex] - start;
- int[] ascent = new int[1], descent = new int[1];
- OS.ATSUGetUnjustifiedBounds(layout, start, lineLength, null, null, ascent, descent);
- int height = OS.Fix2Long(ascent[0]) + OS.Fix2Long(descent[0]);
- return FontMetrics.carbon_new(OS.Fix2Long(ascent[0]), OS.Fix2Long(descent[0]), 0, 0, height);
-}
-
-/**
- * Returns the location for the specified character offset. The
- * <code>trailing</code> argument indicates whether the offset
- * corresponds to the leading or trailing edge of the cluster.
- *
- * @param offset the character offset
- * @param trailing the trailing flag
- * @return the location of the character offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getOffset(Point, int[])
- * @see #getOffset(int, int, int[])
- */
-public Point getLocation(int offset, boolean trailing) {
- checkLayout();
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- if (length == 0) return new Point(0, 0);
- offset = translateOffset(offset);
- for (int i = 0; i < hardBreaks.length; i++) {
- if (offset == hardBreaks[i]) {
- trailing = true;
- if (offset > 0) offset--;
- break;
- }
- }
- int lineY = 0;
- for (int i=0; i<breaks.length-1; i++) {
- int lineBreak = breaks[i];
- if (lineBreak > offset) break;
- lineY += lineHeight[i];
- }
- if (trailing) offset++;
- ATSUCaret caret = new ATSUCaret();
- OS.ATSUOffsetToPosition(layout, offset, !trailing, caret, null, null);
- return new Point(Math.min(OS.Fix2Long(caret.fX), OS.Fix2Long(caret.fDeltaX)), lineY);
-}
-
-/**
- * Returns the next offset for the specified offset and movement
- * type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>,
- * <code>SWT.MOVEMENT_CLUSTER</code>, <code>SWT.MOVEMENT_WORD</code>,
- * <code>SWT.MOVEMENT_WORD_END</code> or <code>SWT.MOVEMENT_WORD_START</code>.
- *
- * @param offset the start offset
- * @param movement the movement type
- * @return the next offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getPreviousOffset(int, int)
- */
-public int getNextOffset (int offset, int movement) {
- return _getOffset(offset, movement, true);
-}
-
-int _getOffset (int offset, int movement, boolean forward) {
- checkLayout();
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- if (length == 0) return 0;
- offset = translateOffset(offset);
- int newOffset;
- int type = OS.kATSUByCharacter;
- switch (movement) {
- case SWT.MOVEMENT_CLUSTER: type = OS.kATSUByCharacterCluster; break;
- case SWT.MOVEMENT_WORD: type = OS.kATSUByWord; break;
- }
- if (forward) {
- offset = _getNativeOffset(offset, type, forward);
- newOffset = untranslateOffset(offset);
- if (movement == SWT.MOVEMENT_WORD || movement == SWT.MOVEMENT_WORD_END) {
- while (newOffset < length &&
- (!(!Compatibility.isLetterOrDigit(text.charAt(newOffset)) &&
- Compatibility.isLetterOrDigit(text.charAt(newOffset - 1))))) {
- offset = _getNativeOffset(offset, type, forward);
- newOffset = untranslateOffset(offset);
- }
- }
- if (movement == SWT.MOVEMENT_WORD_START) {
- while (newOffset < length &&
- (!(Compatibility.isLetterOrDigit(text.charAt(newOffset)) &&
- !Compatibility.isLetterOrDigit(text.charAt(newOffset - 1))))) {
- offset = _getNativeOffset(offset, type, forward);
- newOffset = untranslateOffset(offset);
- }
- }
- } else {
- offset = _getNativeOffset(offset, type, forward);
- newOffset = untranslateOffset(offset);
- if (movement == SWT.MOVEMENT_WORD || movement == SWT.MOVEMENT_WORD_START) {
- while (newOffset > 0 &&
- (!(Compatibility.isLetterOrDigit(text.charAt(newOffset)) &&
- !Compatibility.isLetterOrDigit(text.charAt(newOffset - 1))))) {
- offset = _getNativeOffset(offset, type, forward);
- newOffset = untranslateOffset(offset);
- }
- }
- if (movement == SWT.MOVEMENT_WORD_END) {
- while (newOffset > 0 &&
- (!(!Compatibility.isLetterOrDigit(text.charAt(newOffset)) &&
- Compatibility.isLetterOrDigit(text.charAt(newOffset - 1))))) {
- offset = _getNativeOffset(offset, type, forward);
- newOffset = untranslateOffset(offset);
- }
- }
- }
- return newOffset;
-}
-
-int _getNativeOffset(int offset, int movement, boolean forward) {
- int[] buffer = new int [1];
- boolean invalid = false;
- do {
- if (forward) {
- OS.ATSUNextCursorPosition(layout, offset, movement, buffer);
- } else {
- OS.ATSUPreviousCursorPosition(layout, offset, movement, buffer);
- }
- if (buffer[0] == offset) return offset;
- offset = buffer[0];
- invalid = false;
- for (int i = 0; i < invalidOffsets.length; i++) {
- if (offset == invalidOffsets[i]) {
- invalid = true;
- break;
- }
- }
- } while (invalid);
- return offset;
-}
-
-/**
- * Returns the character offset for the specified point.
- * For a typical character, the trailing argument will be filled in to
- * indicate whether the point is closer to the leading edge (0) or
- * the trailing edge (1). When the point is over a cluster composed
- * of multiple characters, the trailing argument will be filled with the
- * position of the character in the cluster that is closest to
- * the point.
- *
- * @param point the point
- * @param trailing the trailing buffer
- * @return the character offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getLocation(int, boolean)
- */
-public int getOffset(Point point, int[] trailing) {
- checkLayout();
- computeRuns();
- if (point == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return getOffset(point.x, point.y, trailing);
-}
-
-/**
- * Returns the character offset for the specified point.
- * For a typical character, the trailing argument will be filled in to
- * indicate whether the point is closer to the leading edge (0) or
- * the trailing edge (1). When the point is over a cluster composed
- * of multiple characters, the trailing argument will be filled with the
- * position of the character in the cluster that is closest to
- * the point.
- *
- * @param x the x coordinate of the point
- * @param y the y coordinate of the point
- * @param trailing the trailing buffer
- * @return the character offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getLocation(int, boolean)
- */
-public int getOffset(int x, int y, int[] trailing) {
- checkLayout();
- computeRuns();
- if (trailing != null && trailing.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int length = text.length();
- if (length == 0) return 0;
- int lineY = 0, start = 0, lineIndex;
- for (lineIndex=0; lineIndex<breaks.length-1; lineIndex++) {
- int lineBreak = breaks[lineIndex];
- int height = lineHeight[lineIndex];
- if (lineY + height > y) break;
- lineY += height;
- start = lineBreak;
- }
- int[] offset = new int[]{start};
- boolean[] leading = new boolean[1];
- OS.ATSUPositionToOffset(layout, OS.Long2Fix(x), OS.Long2Fix(y - lineY), offset, leading, null);
- if (trailing != null) trailing[0] = (leading[0] ? 0 : 1);
- if (!leading[0]) offset[0]--;
- for (int i = 0; i < hardBreaks.length; i++) {
- if (offset[0] == hardBreaks[i]) {
- offset[0]++;
- break;
- }
- }
- offset[0] = untranslateOffset(offset[0]);
- if (offset[0] > length - 1) {
- offset[0] = length - 1;
- if (trailing != null) trailing[0] = 1;
- }
- return offset[0];
-}
-
-/**
- * Returns the orientation of the receiver.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getOrientation() {
- checkLayout();
- int[] lineDir = new int[1];
- OS.ATSUGetLayoutControl(layout, OS.kATSULineDirectionTag, 1, lineDir, null);
- return lineDir[0] == OS.kATSURightToLeftBaseDirection ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT;
-}
-
-/**
- * Returns the previous offset for the specified offset and movement
- * type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>,
- * <code>SWT.MOVEMENT_CLUSTER</code> or <code>SWT.MOVEMENT_WORD</code>,
- * <code>SWT.MOVEMENT_WORD_END</code> or <code>SWT.MOVEMENT_WORD_START</code>.
- *
- * @param offset the start offset
- * @param movement the movement type
- * @return the previous offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getNextOffset(int, int)
- */
-public int getPreviousOffset (int index, int movement) {
- return _getOffset(index, movement, false);
-}
-
-/**
- * Gets the ranges of text that are associated with a <code>TextStyle</code>.
- *
- * @return the ranges, an array of offsets representing the start and end of each
- * text style.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getStyles()
- *
- * @since 3.2
- */
-public int[] getRanges () {
- checkLayout();
- int[] result = new int[styles.length * 2];
- int count = 0;
- for (int i=0; i<styles.length - 1; i++) {
- if (styles[i].style != null) {
- result[count++] = styles[i].start;
- result[count++] = styles[i + 1].start - 1;
- }
- }
- if (count != result.length) {
- int[] newResult = new int[count];
- System.arraycopy(result, 0, newResult, 0, count);
- result = newResult;
- }
- return result;
-}
-
-/**
- * Returns the text segments offsets of the receiver.
- *
- * @return the text segments offsets
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getSegments() {
- checkLayout();
- return segments;
-}
-
-String getSegmentsText() {
- if (segments == null) return text;
- int nSegments = segments.length;
- if (nSegments <= 1) return text;
- int length = text.length();
- if (length == 0) return text;
- if (nSegments == 2) {
- if (segments[0] == 0 && segments[1] == length) return text;
- }
- invalidOffsets = new int[nSegments];
- char[] oldChars = new char[length];
- text.getChars(0, length, oldChars, 0);
- char[] newChars = new char[length + nSegments];
- int charCount = 0, segmentCount = 0;
- char separator = getOrientation() == SWT.RIGHT_TO_LEFT ? RTL_MARK : LTR_MARK;
- while (charCount < length) {
- if (segmentCount < nSegments && charCount == segments[segmentCount]) {
- invalidOffsets[segmentCount] = charCount + segmentCount;
- newChars[charCount + segmentCount++] = separator;
- } else {
- newChars[charCount + segmentCount] = oldChars[charCount++];
- }
- }
- if (segmentCount < nSegments) {
- invalidOffsets[segmentCount] = charCount + segmentCount;
- segments[segmentCount] = charCount;
- newChars[charCount + segmentCount++] = separator;
- }
- if (segmentCount != nSegments) {
- int[] tmp = new int [segmentCount];
- System.arraycopy(invalidOffsets, 0, tmp, 0, segmentCount);
- invalidOffsets = tmp;
- }
- return new String(newChars, 0, Math.min(charCount + segmentCount, newChars.length));
-}
-
-/**
- * Returns the line spacing of the receiver.
- *
- * @return the line spacing
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getSpacing () {
- checkLayout();
- return spacing;
-}
-
-/**
- * Gets the style of the receiver at the specified character offset.
- *
- * @param offset the text offset
- * @return the style or <code>null</code> if not set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public TextStyle getStyle (int offset) {
- checkLayout();
- int length = text.length();
- if (!(0 <= offset && offset < length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- for (int i=1; i<styles.length; i++) {
- StyleItem item = styles[i];
- if (item.start > offset) {
- return styles[i - 1].style;
- }
- }
- return null;
-}
-
-/**
- * Gets all styles of the receiver.
- *
- * @return the styles
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getRanges()
- *
- * @since 3.2
- */
-public TextStyle[] getStyles () {
- checkLayout();
- TextStyle[] result = new TextStyle[styles.length];
- int count = 0;
- for (int i=0; i<styles.length; i++) {
- if (styles[i].style != null) {
- result[count++] = styles[i].style;
- }
- }
- if (count != result.length) {
- TextStyle[] newResult = new TextStyle[count];
- System.arraycopy(result, 0, newResult, 0, count);
- result = newResult;
- }
- return result;
-}
-
-/**
- * Returns the tab list of the receiver.
- *
- * @return the tab list
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getTabs() {
- checkLayout();
- return tabs;
-}
-
-/**
- * Gets the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public String getText () {
- checkLayout ();
- return text;
-}
-
-/**
- * Returns the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getWidth () {
- checkLayout ();
- int[] buffer = new int[1];
- OS.ATSUGetLayoutControl(layout, OS.kATSULineWidthTag, 4, buffer, null);
- int wrapWidth = OS.Fix2Long(buffer[0]);
- return wrapWidth == 0 ? -1 : wrapWidth;
-}
-
-/*
- * Returns true if the underline style is supported natively by ATSUI
- */
-static boolean isUnderlineSupported (TextStyle style) {
- if (style != null && style.underline) {
- int uStyle = style.underlineStyle;
- return uStyle == SWT.UNDERLINE_SINGLE || uStyle == SWT.UNDERLINE_DOUBLE || uStyle == SWT.UNDERLINE_LINK;
- }
- return false;
-}
-
-/**
- * Returns <code>true</code> if the text layout has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the text layout.
- * When a text layout has been disposed, it is an error to
- * invoke any other method using the text layout.
- * </p>
- *
- * @return <code>true</code> when the text layout is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- return layout == 0;
-}
-
-/**
- * Sets the text alignment for the receiver. The alignment controls
- * how a line of text is positioned horizontally. The argument should
- * be one of <code>SWT.LEFT</code>, <code>SWT.RIGHT</code> or <code>SWT.CENTER</code>.
- * <p>
- * The default alignment is <code>SWT.LEFT</code>. Note that the receiver's
- * width must be set in order to use <code>SWT.RIGHT</code> or <code>SWT.CENTER</code>
- * alignment.
- * </p>
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setWidth(int)
- */
-public void setAlignment (int alignment) {
- checkLayout();
- int mask = SWT.LEFT | SWT.CENTER | SWT.RIGHT;
- alignment &= mask;
- if (alignment == 0) return;
- if (alignment == getAlignment()) return;
- freeRuns();
- if ((alignment & SWT.LEFT) != 0) alignment = SWT.LEFT;
- if ((alignment & SWT.RIGHT) != 0) alignment = SWT.RIGHT;
- int align = OS.kATSUStartAlignment;
- switch (alignment) {
- case SWT.CENTER: align = OS.kATSUCenterAlignment; break;
- case SWT.RIGHT: align = OS.kATSUEndAlignment; break;
- }
- setLayoutControl(OS.kATSULineFlushFactorTag, align, 4);
-}
-
-/**
- * Sets the ascent of the receiver. The ascent is distance in pixels
- * from the baseline to the top of the line and it is applied to all
- * lines. The default value is <code>-1</code> which means that the
- * ascent is calculated from the line fonts.
- *
- * @param ascent the new ascent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the ascent is less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setDescent(int)
- * @see #getLineMetrics(int)
- */
-public void setAscent (int ascent) {
- checkLayout ();
- if (ascent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.ascent == ascent) return;
- freeRuns();
- this.ascent = ascent;
-}
-
-/**
- * Sets the descent of the receiver. The descent is distance in pixels
- * from the baseline to the bottom of the line and it is applied to all
- * lines. The default value is <code>-1</code> which means that the
- * descent is calculated from the line fonts.
- *
- * @param descent the new descent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the descent is less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAscent(int)
- * @see #getLineMetrics(int)
- */
-public void setDescent (int descent) {
- checkLayout ();
- if (descent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.descent == descent) return;
- freeRuns();
- this.descent = descent;
-}
-
-void setLayoutControl(int tag, int value, int size) {
- int ptr1 = OS.NewPtr(size);
- if (size == 1) {
- byte[] buffer = new byte[1];
- buffer[0] = (byte) value;
- OS.memmove(ptr1, buffer, size);
- } else {
- int[] buffer = new int[1];
- buffer[0] = value;
- OS.memmove(ptr1, buffer, size);
- }
- int[] tags = new int[]{tag};
- int[] sizes = new int[]{size};
- int[] values = new int[]{ptr1};
- OS.ATSUSetLayoutControls(layout, tags.length, tags, sizes, values);
- OS.DisposePtr(ptr1);
-}
-
-/**
- * Sets the default font which will be used by the receiver
- * to draw and measure text. If the
- * argument is null, then a default font appropriate
- * for the platform will be used instead. Note that a text
- * style can override the default font.
- *
- * @param font the new font for the receiver, or null to indicate a default font
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkLayout ();
- if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Font oldFont = this.font;
- if (oldFont == font) return;
- this.font = font;
- if (oldFont != null && oldFont.equals(font)) return;
- freeRuns();
-}
-
-/**
- * Sets the indent of the receiver. This indent it applied of the first line of
- * each paragraph.
- *
- * @param indent new indent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setIndent (int indent) {
- checkLayout ();
- if (indent < 0) return;
- if (this.indent == indent) return;
- freeRuns();
- this.indent = indent;
-}
-
-/**
- * Sets the justification of the receiver. Note that the receiver's
- * width must be set in order to use justification.
- *
- * @param justify new justify
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setJustify (boolean justify) {
- checkLayout ();
- if (justify == getJustify()) return;
- freeRuns();
- setLayoutControl(OS.kATSULineJustificationFactorTag, justify ? OS.kATSUFullJustification : OS.kATSUNoJustification, 4);
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setOrientation(int orientation) {
- checkLayout();
- int mask = SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT;
- orientation &= mask;
- if (orientation == 0) return;
- if ((orientation & SWT.LEFT_TO_RIGHT) != 0) orientation = SWT.LEFT_TO_RIGHT;
- if (orientation == getOrientation()) return;
- freeRuns();
- int lineDir = OS.kATSULeftToRightBaseDirection;
- if (orientation == SWT.RIGHT_TO_LEFT) lineDir = OS.kATSURightToLeftBaseDirection;
- setLayoutControl(OS.kATSULineDirectionTag, lineDir, 1);
-}
-
-/**
- * Sets the offsets of the receiver's text segments. Text segments are used to
- * override the default behaviour of the bidirectional algorithm.
- * Bidirectional reordering can happen within a text segment but not
- * between two adjacent segments.
- * <p>
- * Each text segment is determined by two consecutive offsets in the
- * <code>segments</code> arrays. The first element of the array should
- * always be zero and the last one should always be equals to length of
- * the text.
- * </p>
- *
- * @param segments the text segments offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setSegments(int[] segments) {
- checkLayout();
- if (this.segments == null && segments == null) return;
- if (this.segments != null && segments !=null) {
- if (this.segments.length == segments.length) {
- int i;
- for (i = 0; i <segments.length; i++) {
- if (this.segments[i] != segments[i]) break;
- }
- if (i == segments.length) return;
- }
- }
- freeRuns();
- this.segments = segments;
-}
-
-/**
- * Sets the line spacing of the receiver. The line spacing
- * is the space left between lines.
- *
- * @param spacing the new line spacing
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the spacing is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setSpacing (int spacing) {
- checkLayout();
- if (spacing < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.spacing == spacing) return;
- freeRuns();
- this.spacing = spacing;
-}
-
-/**
- * Sets the style of the receiver for the specified range. Styles previously
- * set for that range will be overwritten. The start and end offsets are
- * inclusive and will be clamped if out of range.
- *
- * @param style the style
- * @param start the start offset
- * @param end the end offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setStyle (TextStyle style, int start, int end) {
- checkLayout();
- int length = text.length();
- if (length == 0) return;
- if (start > end) return;
- start = Math.min(Math.max(0, start), length - 1);
- end = Math.min(Math.max(0, end), length - 1);
- int low = -1;
- int high = styles.length;
- while (high - low > 1) {
- int index = (high + low) / 2;
- if (styles[index + 1].start > start) {
- high = index;
- } else {
- low = index;
- }
- }
- if (0 <= high && high < styles.length) {
- StyleItem item = styles[high];
- if (item.start == start && styles[high + 1].start - 1 == end) {
- if (style == null) {
- if (item.style == null) return;
- } else {
- if (style.equals(item.style)) return;
- }
- }
- }
- freeRuns();
- int modifyStart = high;
- int modifyEnd = modifyStart;
- while (modifyEnd < styles.length) {
- if (styles[modifyEnd + 1].start > end) break;
- modifyEnd++;
- }
- if (modifyStart == modifyEnd) {
- int styleStart = styles[modifyStart].start;
- int styleEnd = styles[modifyEnd + 1].start - 1;
- if (styleStart == start && styleEnd == end) {
- styles[modifyStart].style = style;
- return;
- }
- if (styleStart != start && styleEnd != end) {
- StyleItem[] newStyles = new StyleItem[styles.length + 2];
- System.arraycopy(styles, 0, newStyles, 0, modifyStart + 1);
- StyleItem item = new StyleItem();
- item.start = start;
- item.style = style;
- newStyles[modifyStart + 1] = item;
- item = new StyleItem();
- item.start = end + 1;
- item.style = styles[modifyStart].style;
- newStyles[modifyStart + 2] = item;
- System.arraycopy(styles, modifyEnd + 1, newStyles, modifyEnd + 3, styles.length - modifyEnd - 1);
- styles = newStyles;
- return;
- }
- }
- if (start == styles[modifyStart].start) modifyStart--;
- if (end == styles[modifyEnd + 1].start - 1) modifyEnd++;
- int newLength = styles.length + 1 - (modifyEnd - modifyStart - 1);
- StyleItem[] newStyles = new StyleItem[newLength];
- System.arraycopy(styles, 0, newStyles, 0, modifyStart + 1);
- StyleItem item = new StyleItem();
- item.start = start;
- item.style = style;
- newStyles[modifyStart + 1] = item;
- styles[modifyEnd].start = end + 1;
- System.arraycopy(styles, modifyEnd, newStyles, modifyStart + 2, styles.length - modifyEnd);
- styles = newStyles;
-}
-
-/**
- * Sets the receiver's tab list. Each value in the tab list specifies
- * the space in pixels from the origin of the text layout to the respective
- * tab stop. The last tab stop width is repeated continuously.
- *
- * @param tabs the new tab list
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setTabs(int[] tabs) {
- checkLayout();
- if (this.tabs == null && tabs == null) return;
- if (this.tabs != null && tabs !=null) {
- if (this.tabs.length == tabs.length) {
- int i;
- for (i = 0; i <tabs.length; i++) {
- if (this.tabs[i] != tabs[i]) break;
- }
- if (i == tabs.length) return;
- }
- }
- freeRuns();
- this.tabs = tabs;
- if (tabsPtr != 0) OS.DisposePtr(tabsPtr);
- tabsPtr = 0;
- if (tabs == null) {
- OS.ATSUSetTabArray(layout, 0, 0);
- } else {
- ATSUTab tab = new ATSUTab();
- tab.tabPosition = OS.Long2Fix(0);
- int length = Math.max(TAB_COUNT, tabs.length);
- int ptr = tabsPtr = OS.NewPtr(ATSUTab.sizeof * length), i, offset;
- for (i=0, offset=ptr; i<tabs.length; i++, offset += ATSUTab.sizeof) {
- tab.tabType = (short)OS.kATSULeftTab;
- tab.tabPosition = OS.Long2Fix(tabs[i]);
- OS.memmove(offset, tab, ATSUTab.sizeof);
- }
- int width = i - 2 >= 0 ? tabs[i - 1] - tabs[i - 2] : tabs[i - 1];
- if (width > 0) {
- for (; i<length; i++, offset += ATSUTab.sizeof) {
- tab.tabType = (short)OS.kATSULeftTab;
- tab.tabPosition += OS.Long2Fix(width);
- OS.memmove(offset, tab, ATSUTab.sizeof);
- }
- }
- OS.ATSUSetTabArray(layout, ptr, i);
- }
-}
-
-/**
- * Sets the receiver's text.
- *<p>
- * Note: Setting the text also clears all the styles. This method
- * returns without doing anything if the new text is the same as
- * the current text.
- * </p>
- *
- * @param text the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setText (String text) {
- checkLayout ();
- if (text == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (text.equals(this.text)) return;
- freeRuns();
- this.text = text;
- styles = new StyleItem[2];
- styles[0] = new StyleItem();
- styles[1] = new StyleItem();
- styles[styles.length - 1].start = text.length();
-}
-
-/**
- * Sets the line width of the receiver, which determines how
- * text should be wrapped and aligned. The default value is
- * <code>-1</code> which means wrapping is disabled.
- *
- * @param width the new width
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the width is <code>0</code> or less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAlignment(int)
- */
-public void setWidth (int width) {
- checkLayout ();
- if (width < -1 || width == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (width == getWidth()) return;
- freeRuns();
- setLayoutControl(OS.kATSULineWidthTag, OS.Long2Fix(Math.max(0, width)), 4);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "TextLayout {*DISPOSED*}";
- return "TextLayout {" + layout + "}";
-}
-
-/*
- * Translate a client offset to an internal offset
- */
-int translateOffset(int offset) {
- offset++;
- for (int i = 0; i < invalidOffsets.length; i++) {
- if (offset < invalidOffsets[i]) break;
- offset++;
- }
- return offset;
-}
-
-/*
- * Translate an internal offset to a client offset
- */
-int untranslateOffset(int offset) {
- for (int i = 0; i < invalidOffsets.length; i++) {
- if (offset == invalidOffsets[i]) {
- offset++;
- continue;
- }
- if (offset < invalidOffsets[i]) {
- return Math.max(0, offset - i - 1);
- }
- }
- return Math.max(0, offset - invalidOffsets.length - 1);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Transform.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Transform.java
deleted file mode 100644
index 05cda4af95..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/Transform.java
+++ /dev/null
@@ -1,380 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.Compatibility;
-import org.eclipse.swt.internal.carbon.*;
-
-/**
- * Instances of this class represent transformation matrices for
- * points expressed as (x, y) pairs of floating point numbers.
- * <p>
- * Application code must explicitly invoke the <code>Transform.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Transform extends Resource {
- /**
- * the OS resource for the Transform
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public float[] handle;
-
-/**
- * Constructs a new identity Transform.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform (Device device) {
- this(device, 1, 0, 0, 1, 0, 0);
-}
-
-/**
- * Constructs a new Transform given an array of elements that represent the
- * matrix that describes the transformation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- * @param elements an array of floats that describe the transformation matrix
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device, or the elements array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the elements array is too small to hold the matrix values</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform(Device device, float[] elements) {
- this (device, checkTransform(elements)[0], elements[1], elements[2], elements[3], elements[4], elements[5]);
-}
-
-/**
- * Constructs a new Transform given all of the elements that represent the
- * matrix that describes the transformation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- * @param m11 the first element of the first row of the matrix
- * @param m12 the second element of the first row of the matrix
- * @param m21 the first element of the second row of the matrix
- * @param m22 the second element of the second row of the matrix
- * @param dx the third element of the first row of the matrix
- * @param dy the third element of the second row of the matrix
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform (Device device, float m11, float m12, float m21, float m22, float dx, float dy) {
- super(device);
- handle = new float[6];
- OS.CGAffineTransformMake(m11, m12, m21, m22, dx, dy, handle);
- if (handle == null) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-static float[] checkTransform(float[] elements) {
- if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return elements;
-}
-
-void destroy() {
- handle = null;
-}
-
-/**
- * Fills the parameter with the values of the transformation matrix
- * that the receiver represents, in the order {m11, m12, m21, m22, dx, dy}.
- *
- * @param elements array to hold the matrix values
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the matrix values</li>
- * </ul>
- */
-public void getElements(float[] elements) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- System.arraycopy(handle, 0, elements, 0, handle.length);
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes the
- * identity matrix.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public void identity() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.CGAffineTransformMake(1, 0, 0, 1, 0, 0, handle);
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes
- * the mathematical inverse of the matrix it previously represented.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_CANNOT_INVERT_MATRIX - if the matrix is not invertible</li>
- * </ul>
- */
-public void invert() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if ((handle [0] * handle [3] - handle [1] * handle [2]) == 0) {
- SWT.error(SWT.ERROR_CANNOT_INVERT_MATRIX);
- }
- OS.CGAffineTransformInvert(handle, handle);
-}
-
-/**
- * Returns <code>true</code> if the Transform has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Transform.
- * When a Transform has been disposed, it is an error to
- * invoke any other method using the Transform.
- *
- * @return <code>true</code> when the Transform is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == null;
-}
-
-/**
- * Returns <code>true</code> if the Transform represents the identity matrix
- * and false otherwise.
- *
- * @return <code>true</code> if the receiver is an identity Transform, and <code>false</code> otherwise
- */
-public boolean isIdentity() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return handle[0] == 1 && handle[1] == 0 && handle[2] == 0 && handle[3] == 1 && handle[4] == 0 && handle[5] == 0;
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes the
- * the result of multiplying the matrix it previously represented by the
- * argument.
- *
- * @param matrix the matrix to multiply the receiver by
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- */
-public void multiply(Transform matrix) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (matrix == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (matrix.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.CGAffineTransformConcat(matrix.handle, handle, handle);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation rotated by the specified angle.
- * The angle is specified in degrees and for the identity transform 0 degrees
- * is at the 3 o'clock position. A positive value indicates a clockwise rotation
- * while a negative value indicates a counter-clockwise rotation.
- *
- * @param angle the angle to rotate the transformation by
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void rotate(float angle) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.CGAffineTransformRotate(handle, angle * (float)Compatibility.PI / 180, handle);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation scaled by (scaleX, scaleY).
- *
- * @param scaleX the amount to scale in the X direction
- * @param scaleY the amount to scale in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void scale(float scaleX, float scaleY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.CGAffineTransformScale(handle, scaleX, scaleY, handle);
-}
-
-/**
- * Modifies the receiver to represent a new transformation given all of
- * the elements that represent the matrix that describes that transformation.
- *
- * @param m11 the first element of the first row of the matrix
- * @param m12 the second element of the first row of the matrix
- * @param m21 the first element of the second row of the matrix
- * @param m22 the second element of the second row of the matrix
- * @param dx the third element of the first row of the matrix
- * @param dy the third element of the second row of the matrix
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setElements(float m11, float m12, float m21, float m22, float dx, float dy) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.CGAffineTransformMake(m11, m12, m21, m22, dx, dy, handle);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation sheared by (shearX, shearY).
- *
- * @param shearX the shear factor in the X direction
- * @param shearY the shear factor in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public void shear(float shearX, float shearY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float[] matrix = {1, shearX, shearY, 1, 0, 0};
- OS.CGAffineTransformConcat(matrix, handle, handle);
-}
-
-/**
- * Given an array containing points described by alternating x and y values,
- * modify that array such that each point has been replaced with the result of
- * applying the transformation represented by the receiver to that point.
- *
- * @param pointArray an array of alternating x and y values to be transformed
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void transform(float[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- CGPoint point = new CGPoint();
- int length = pointArray.length / 2;
- for (int i = 0, j = 0; i < length; i++, j += 2) {
- point.x = pointArray[j];
- point.y = pointArray[j + 1];
- OS.CGPointApplyAffineTransform(point, handle, point);
- pointArray[j] = point.x;
- pointArray[j + 1] = point.y;
- }
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation translated by (offsetX, offsetY).
- *
- * @param offsetX the distance to translate in the X direction
- * @param offsetY the distance to translate in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void translate(float offsetX, float offsetY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.CGAffineTransformTranslate(handle, offsetX, offsetY, handle);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString() {
- if (isDisposed()) return "Transform {*DISPOSED*}";
- float[] elements = new float[6];
- getElements(elements);
- return "Transform {" + elements [0] + ", " + elements [1] + ", " +elements [2] + ", " +elements [3] + ", " +elements [4] + ", " +elements [5] + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Button.java
deleted file mode 100644
index be1bd010ee..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Button.java
+++ /dev/null
@@ -1,865 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.internal.Compatibility;
-import org.eclipse.swt.internal.carbon.*;
-
-/**
- * Instances of this class represent a selectable user interface object that
- * issues notification when pressed and released.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>ARROW, CHECK, PUSH, RADIO, TOGGLE, FLAT</dd>
- * <dd>UP, DOWN, LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles ARROW, CHECK, PUSH, RADIO, and TOGGLE
- * may be specified.
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT, and CENTER may be specified.
- * </p><p>
- * Note: Only one of the styles UP, DOWN, LEFT, and RIGHT may be specified
- * when the ARROW style is specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#button">Button snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Button extends Control {
- String text = "";
- Image image;
- int cIcon;
- boolean isImage, grayed;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#ARROW
- * @see SWT#CHECK
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#TOGGLE
- * @see SWT#FLAT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Button (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected by the user.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- style = checkBits (style, SWT.PUSH, SWT.ARROW, SWT.CHECK, SWT.RADIO, SWT.TOGGLE, 0);
- if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) {
- return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0);
- }
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0);
- }
- if ((style & SWT.ARROW) != 0) {
- style |= SWT.NO_FOCUS;
- return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0);
- }
- return style;
-}
-
-void click () {
- postEvent (SWT.Selection);
-}
-
-int callPaintEventHandler (int control, int damageRgn, int visibleRgn, int theEvent, int nextHandler) {
- int [] context = null;
- if ((style & SWT.ARROW) != 0) {
- boolean invert = false;
- if (OS.VERSION < 0x1050) {
- invert = (style & SWT.UP) != 0;
- } else {
- invert = (style & SWT.UP) != 0 || (style & SWT.LEFT) != 0;
- }
- if (invert) {
- context = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamCGContextRef, OS.typeCGContextRef, null, 4, null, context);
- OS.CGContextSaveGState (context[0]);
- CGRect rect = new CGRect();
- OS.HIViewGetBounds (handle, rect);
- OS.CGContextRotateCTM (context[0], (float)Compatibility.PI);
- OS.CGContextTranslateCTM (context[0], -rect.width, -rect.height);
- }
- }
- int result = super.callPaintEventHandler (control, damageRgn, visibleRgn, theEvent, nextHandler);
- if (context != null) OS.CGContextRestoreGState (context[0]);
- return result;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- // NEEDS WORK - empty string
- if ((style & SWT.ARROW) != 0) {
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricDisclosureTriangleHeight, outMetric);
- int width = outMetric [0], height = outMetric [0];
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- return new Point (width, height);
- }
-
- int width = 0, height = 0;
-
- if (isImage && image != null) {
- Rectangle bounds = image.getBounds ();
- width = bounds.width;
- height = bounds.height;
- }
- int [] ptr = new int [1];
- OS.CopyControlTitleAsCFString (handle, ptr);
- if (ptr [0] != 0) {
- Point size = textExtent (ptr [0], 0);
- width += size.x;
- height = Math.max (height, size.y);
- OS.CFRelease (ptr [0]);
- if (image != null && isImage) width += 3;
- } else {
- if (image == null) {
- width = DEFAULT_WIDTH;
- height = DEFAULT_HEIGHT;
- }
- }
-
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- int [] outMetric = new int [1];
- int metric = ((style & SWT.CHECK) != 0) ? OS.kThemeMetricCheckBoxWidth : OS.kThemeMetricRadioButtonWidth;
- OS.GetThemeMetric (metric, outMetric);
- width += outMetric [0] + 3; // +3 for gap between button and text/image
- height = Math.max (outMetric [0], height);
- } else {
- if ((style & SWT.FLAT) != 0 || (style & SWT.TOGGLE) != 0) {
- width += 8;
- height += 8;
- } else {
- width += 28;
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricPushButtonHeight, outMetric);
- height = Math.max (height, outMetric [0]);
- }
- }
-
- Rect inset = getInset ();
- width += inset.left + inset.right;
- height += inset.top + inset.bottom;
-
- /*
- * Feature in Mac OS X. Setting the width of a bevel button
- * widget to less than 20 will fail. This means you can not
- * make a button very small. By forcing the width to be greater
- * than or equal to 20, the height of the button can be made
- * very small, even 0.
- */
- width = Math.max(20, width);
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- return new Point (width, height);
-}
-
-void createHandle () {
- if ((style & SWT.PUSH) == 0) state |= THEME_BACKGROUND;
- int [] outControl = new int [1];
- int window = OS.GetControlOwner (parent.handle);
-
- if ((style & SWT.ARROW) != 0) {
- int orientation = OS.kThemeDisclosureRight;
- if ((style & SWT.UP) != 0) orientation = OS.kThemeDisclosureDown;
- if ((style & SWT.DOWN) != 0) orientation = OS.kThemeDisclosureDown;
- if ((style & SWT.LEFT) != 0) orientation = OS.kThemeDisclosureLeft;
- OS.CreateBevelButtonControl(window, null, 0, (short)0, (short)OS.kControlBehaviorPushbutton, 0, (short)0, (short)0, (short)0, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlBevelButtonKindTag, 2, new short [] {(short)(OS.kThemeDisclosureButton)});
- OS.SetControl32BitMaximum (handle, 2);
- OS.SetControl32BitValue (handle, orientation);
- }
-
- if ((style & SWT.CHECK) != 0) {
- //OS.CreateCheckBoxControl (window, null, 0, 0 /*initially off*/, true, outControl);
- OS.CreateBevelButtonControl(window, null, 0, (short)0, (short)OS.kControlBehaviorToggles, 0, (short)0, (short)0, (short)0, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlBevelButtonKindTag, 2, new short [] {(short)OS.kThemeCheckBox});
- }
-
- if ((style & SWT.RADIO) != 0) {
- //OS.CreateRadioButtonControl(window, null, 0, 0 /*initially off*/, true, outControl);
- OS.CreateBevelButtonControl(window, null, 0, (short)0, (short)OS.kControlBehaviorToggles, 0, (short)0, (short)0, (short)0, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlBevelButtonKindTag, 2, new short [] {(short)OS.kThemeRadioButton});
- }
-
- if ((style & SWT.TOGGLE) != 0) {
- OS.CreateBevelButtonControl(window, null, 0, (short)OS.kControlBevelButtonNormalBevel, (short)OS.kControlBehaviorToggles, 0, (short)0, (short)0, (short)0, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
- if ((style & SWT.FLAT) == 0 ) {
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlBevelButtonKindTag, 2, new short [] {(short)OS.kThemeRoundedBevelButton});
- }
- }
-
- if ((style & SWT.PUSH) != 0) {
- if ((style & SWT.FLAT) != 0) {
- OS.CreateBevelButtonControl(window, null, 0, (short)2, (short)OS.kControlBehaviorPushbutton, 0, (short)0, (short)0, (short)0, outControl);
- } else {
- OS.CreatePushButtonControl (window, null, 0, outControl);
- //OS.CreateBevelButtonControl(window, null, 0, (short)2, (short)OS.kControlBehaviorPushbutton, 0, (short)0, (short)0, (short)0, outControl);
- }
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
- if ((style & SWT.FLAT) == 0 ) {
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlBevelButtonKindTag, 2, new short [] {(short)OS.kThemePushButton});
- }
- }
-
- ControlFontStyleRec fontRec = new ControlFontStyleRec();
- fontRec.flags = (short) OS.kControlUseThemeFontIDMask;
- fontRec.font = (short) defaultThemeFont ();
- OS.SetControlFontStyle (handle, fontRec);
-
- if ((style & SWT.ARROW) != 0) return;
- _setAlignment (style & (SWT.LEFT | SWT.RIGHT | SWT.CENTER));
-}
-
-int defaultThemeFont () {
- if (display.smallFonts) return OS.kThemeSmallSystemFont;
- return OS.kThemePushButtonFont;
-}
-
-void drawWidget (int control, int context, int damageRgn, int visibleRgn, int theEvent) {
- if (OS.VERSION < 0x1040 && isImage && image != null && (style & SWT.PUSH) != 0 && (style & SWT.FLAT) == 0) {
- Rect bounds = new Rect(), content = new Rect();
- OS.GetControlBounds (handle, bounds);
- ThemeButtonDrawInfo drawInfo = new ThemeButtonDrawInfo();
- if (OS.IsControlEnabled (handle)) {
- drawInfo.state = OS.IsControlActive (handle) ? OS.kThemeStateActive : OS.kThemeStateInactive;
- } else {
- drawInfo.state = OS.IsControlActive (handle) ? OS.kThemeStateUnavailable : OS.kThemeStateUnavailableInactive;
- }
- drawInfo.adornment = OS.kThemeAdornmentDefault;
- OS.GetThemeButtonContentBounds (bounds, OS.kThemePushButton, drawInfo, content);
- int width = image == null ? 0 : OS.CGImageGetWidth (image.handle);
- int height = image == null ? 0 : OS.CGImageGetHeight (image.handle);
- int x = (bounds.right - bounds.left - width) / 2;
- int y = (content.bottom - content.top - height) / 2;
- GCData data = new GCData ();
- data.paintEvent = theEvent;
- data.visibleRgn = visibleRgn;
- GC gc = GC.carbon_new (this, data);
- gc.drawImage (image, x, y);
- gc.dispose ();
- }
- super.drawWidget (control, context, damageRgn, visibleRgn, theEvent);
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is an <code>ARROW</code> button, in
- * which case, the alignment will indicate the direction of
- * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>,
- * <code>UP</code> or <code>DOWN</code>).
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget ();
- if ((style & SWT.ARROW) != 0) {
- if ((style & SWT.UP) != 0) return SWT.UP;
- if ((style & SWT.DOWN) != 0) return SWT.DOWN;
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.UP;
- }
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the widget does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getGrayed () {
- checkWidget();
- if ((style & SWT.CHECK) == 0) return false;
- return grayed;
-}
-
-/**
- * Returns the receiver's image if it has one, or null
- * if it does not.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked. When it is of type <code>TOGGLE</code>,
- * it is selected when it is pushed in. If the receiver is of any other type,
- * this method returns false.
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget ();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false;
- return OS.GetControl32BitValue(handle) != 0;
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set or if the receiver is
- * an <code>ARROW</code> button.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-Rect getInset () {
- if ((style & SWT.PUSH) == 0) return super.getInset();
- return display.buttonInset;
-}
-
-boolean isDescribedByLabel () {
- return false;
-}
-
-int kEventAccessibleGetNamedAttribute (int nextHandler, int theEvent, int userData) {
- int code = OS.eventNotHandledErr;
- if ((style & SWT.RADIO) != 0) {
- int [] stringRef = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamAccessibleAttributeName, OS.typeCFStringRef, null, 4, null, stringRef);
- int length = 0;
- if (stringRef [0] != 0) length = OS.CFStringGetLength (stringRef [0]);
- char [] buffer = new char [length];
- CFRange range = new CFRange ();
- range.length = length;
- OS.CFStringGetCharacters (stringRef [0], range, buffer);
- String attributeName = new String(buffer);
- if (attributeName.equals (OS.kAXRoleAttribute) || attributeName.equals (OS.kAXRoleDescriptionAttribute)) {
- String roleText = OS.kAXRadioButtonRole;
- buffer = new char [roleText.length ()];
- roleText.getChars (0, buffer.length, buffer, 0);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- if (attributeName.equals (OS.kAXRoleAttribute)) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- } else { // kAXRoleDescriptionAttribute
- int stringRef2 = OS.HICopyAccessibilityRoleDescription (stringRef [0], 0);
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, new int [] {stringRef2});
- OS.CFRelease(stringRef2);
- }
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- }
- }
- if (accessible != null) {
- code = accessible.internal_kEventAccessibleGetNamedAttribute (nextHandler, theEvent, code);
- }
- return code;
-}
-
-int kEventControlHit (int nextHandler, int theEvent, int userData) {
- int result = super.kEventControlHit (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) {
- selectRadio ();
- }
- } else {
- if ((style & SWT.CHECK) != 0) {
- if (grayed) {
- switch (OS.GetControl32BitValue (handle)) {
- case 0:
- OS.SetControl32BitMaximum (handle, 2);
- OS.SetControl32BitValue (handle, 2);
- break;
- case 1:
- case 2:
- OS.SetControl32BitMaximum (handle, 0);
- OS.SetControl32BitValue (handle, 0);
- break;
- }
- }
- }
- }
- postEvent (SWT.Selection);
- return OS.eventNotHandledErr;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (cIcon != 0) {
- destroyCIcon (cIcon);
- cIcon = 0;
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-
-void selectRadio () {
- /*
- * This code is intentionally commented. When two groups
- * of radio buttons with the same parent are separated by
- * another control, the correct behavior should be that
- * the two groups act independently. This is consistent
- * with radio tool and menu items. The commented code
- * implements this behavior.
- */
-// int index = 0;
-// Control [] children = parent._getChildren ();
-// while (index < children.length && children [index] != this) index++;
-// int i = index - 1;
-// while (i >= 0 && children [i].setRadioSelection (false)) --i;
-// int j = index + 1;
-// while (j < children.length && children [j].setRadioSelection (false)) j++;
-// setSelection (true);
- Control [] children = parent._getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (this != child) child.setRadioSelection (false);
- }
- setSelection (true);
-}
-
-/**
- * Controls how text, images and arrows will be displayed
- * in the receiver. The argument should be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is an <code>ARROW</code> button, in
- * which case, the argument indicates the direction of
- * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>,
- * <code>UP</code> or <code>DOWN</code>).
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget ();
- _setAlignment (alignment);
- redraw ();
-}
-
-void _setAlignment (int alignment) {
- if ((style & SWT.ARROW) != 0) {
- if ((style & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT)) == 0) return;
- style &= ~(SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT);
- style |= alignment & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT);
- int orientation = OS.kThemeDisclosureRight;
- if ((style & SWT.UP) != 0) orientation = OS.kThemeDisclosureDown;
- if ((style & SWT.DOWN) != 0) orientation = OS.kThemeDisclosureDown;
- if ((style & SWT.LEFT) != 0) orientation = OS.kThemeDisclosureLeft;
- OS.SetControl32BitValue (handle, orientation);
- return;
- }
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- /* Alignment not honoured when image and text is visible */
- boolean bothVisible = text != null && text.length () > 0 && image != null;
- if (bothVisible) {
- if ((style & (SWT.RADIO | SWT.CHECK)) != 0) alignment = SWT.LEFT;
- if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) alignment = SWT.CENTER;
- }
- int textAlignment = 0;
- int graphicAlignment = 0;
- if ((alignment & SWT.LEFT) != 0) {
- textAlignment = OS.kControlBevelButtonAlignTextFlushLeft;
- graphicAlignment = OS.kControlBevelButtonAlignLeft;
- }
- if ((alignment & SWT.CENTER) != 0) {
- textAlignment = OS.kControlBevelButtonAlignTextCenter;
- graphicAlignment = OS.kControlBevelButtonAlignCenter;
- }
- if ((alignment & SWT.RIGHT) != 0) {
- textAlignment = OS.kControlBevelButtonAlignTextFlushRight;
- graphicAlignment = OS.kControlBevelButtonAlignRight;
- }
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlBevelButtonTextAlignTag, 2, new short [] {(short)textAlignment});
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlBevelButtonGraphicAlignTag, 2, new short [] {(short)graphicAlignment});
- if (bothVisible) {
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlBevelButtonTextPlaceTag, 2, new short [] {(short)OS.kControlBevelButtonPlaceToRightOfGraphic});
- }
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- /*
- * Bug in MacOS X. When setting the height of a bevel button
- * to a value less than 20, the button is drawn incorrectly.
- * The fix is to force the height to be greater than or equal to 20.
- */
- if (resize && (style & SWT.ARROW) == 0) {
- height = Math.max (20, height);
- }
- return super.setBounds (x, y, width, height, move, resize, events);
-}
-
-void setDefault (boolean value) {
- if ((style & SWT.PUSH) == 0) return;
- int window = OS.GetControlOwner (handle);
- OS.SetWindowDefaultButton (window, value ? handle : 0);
-}
-
-/**
- * Sets the grayed state of the receiver. This state change
- * only applies if the control was created with the SWT.CHECK
- * style.
- *
- * @param grayed the new grayed state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setGrayed (boolean grayed) {
- checkWidget();
- if ((style & SWT.CHECK) == 0) return;
- this.grayed = grayed;
- if (grayed) {
- if (OS.GetControl32BitValue (handle) != 0) {
- OS.SetControl32BitMaximum (handle, 2);
- OS.SetControl32BitValue (handle, 2);
- } else {
- OS.SetControl32BitMaximum (handle, 0);
- OS.SetControl32BitValue (handle, 0);
- }
- } else {
- if (OS.GetControl32BitValue (handle) != 0) {
- OS.SetControl32BitValue (handle, 1);
- }
- OS.SetControl32BitMaximum (handle, 1);
- }
-}
-
-/**
- * Sets the receiver's image to the argument, which may be
- * <code>null</code> indicating that no image should be displayed.
- * <p>
- * Note that a Button can display an image and text simultaneously
- * on Windows (starting with XP), GTK+ and OSX. On other platforms,
- * a Button that has an image and text set into it will display the
- * image or text that was set most recently.
- * </p>
- * @param image the image to display on the receiver (may be <code>null</code>)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if ((style & SWT.ARROW) != 0) return;
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (cIcon != 0) {
- destroyCIcon(cIcon);
- cIcon = 0;
- }
- this.image = image;
- isImage = true;
- if (OS.VERSION < 0x1040) {
- if ((style & SWT.PUSH) != 0 && (style & SWT.FLAT) == 0) {
- if (image == null) {
- setText (text);
- return;
- }
- if (text.length () > 0) {
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, null, 0);
- if (ptr == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- OS.SetControlTitleWithCFString (handle, ptr);
- OS.CFRelease (ptr);
- }
- }
- }
- ControlButtonContentInfo inContent = new ControlButtonContentInfo ();
- if (image != null) {
- if (OS.VERSION < 0x1040) {
- cIcon = createCIcon (image);
- inContent.contentType = (short)OS.kControlContentCIconHandle;
- inContent.iconRef = cIcon;
- } else {
- inContent.contentType = (short)OS.kControlContentCGImageRef;
- inContent.iconRef = image.handle;
- }
- } else {
- inContent.contentType = (short)OS.kControlContentTextOnly;
- }
- OS.SetBevelButtonContentInfo (handle, inContent);
- _setAlignment (style);
- redraw ();
-}
-
-boolean setRadioSelection (boolean value){
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-
-/**
- * Sets the selection state of the receiver, if it is of type <code>CHECK</code>,
- * <code>RADIO</code>, or <code>TOGGLE</code>.
- *
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked. When it is of type <code>TOGGLE</code>,
- * it is selected when it is pushed in.
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return;
- if ((style & SWT.CHECK) != 0) {
- if (grayed) {
- if (selected) {
- OS.SetControl32BitMaximum (handle, 2);
- OS.SetControl32BitValue (handle, 2);
- } else {
- OS.SetControl32BitMaximum (handle, 0);
- OS.SetControl32BitValue (handle, 0);
- }
- return;
- }
- OS.SetControl32BitMaximum (handle, 1);
- }
- OS.SetControl32BitValue (handle, selected ? 1 : 0);
-}
-
-/**
- * Sets the receiver's text.
- * <p>
- * This method sets the button label. The label may include
- * the mnemonic character but must not contain line delimiters.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasized in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p><p>
- * Note that a Button can display an image and text simultaneously
- * on Windows (starting with XP), GTK+ and OSX. On other platforms,
- * a Button that has an image and text set into it will display the
- * image or text that was set most recently.
- * </p>
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.ARROW) != 0) return;
- text = string;
- if (OS.VERSION < 0x1040) {
- if ((style & SWT.PUSH) != 0 && (style & SWT.FLAT) == 0) {
- if (isImage) {
- ControlButtonContentInfo inContent = new ControlButtonContentInfo();
- inContent.contentType = (short)OS.kControlContentTextOnly;
- OS.SetBevelButtonContentInfo(handle, inContent);
- }
- isImage = false;
- }
- }
- char [] buffer = new char [text.length ()];
- text.getChars (0, buffer.length, buffer, 0);
- int length = fixMnemonic (buffer);
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, length);
- if (ptr == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- OS.SetControlTitleWithCFString (handle, ptr);
- OS.CFRelease (ptr);
- _setAlignment (style);
- redraw ();
-}
-
-int traversalCode (int key, int theEvent) {
- int code = super.traversalCode (key, theEvent);
- if ((style & SWT.ARROW) != 0) code &= ~(SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS);
- if ((style & SWT.RADIO) != 0) code |= SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS;
- return code;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Canvas.java
deleted file mode 100644
index f233332c5d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Canvas.java
+++ /dev/null
@@ -1,403 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide a surface for drawing
- * arbitrary graphics.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * This class may be subclassed by custom control implementors
- * who are building controls that are <em>not</em> constructed
- * from aggregates of other controls. That is, they are either
- * painted using SWT graphics calls or are handled by native
- * methods.
- * </p>
- *
- * @see Composite
- * @see <a href="http://www.eclipse.org/swt/snippets/#canvas">Canvas snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class Canvas extends Composite {
- Caret caret;
- IME ime;
-
-Canvas () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Canvas (Composite parent, int style) {
- super (parent, style);
-}
-
-/**
- * Fills the interior of the rectangle specified by the arguments,
- * with the receiver's background.
- *
- * @param gc the gc where the rectangle is to be filled
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void drawBackground (GC gc, int x, int y, int width, int height) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- Control control = findBackgroundControl ();
- if (control != null) {
- control.fillBackground (handle, gc.handle, new Rectangle (x, y, width, height));
- } else {
- gc.fillRectangle (x, y, width, height);
- }
-}
-
-void drawWidget (int control, int context, int damageRgn, int visibleRgn, int theEvent) {
- super.drawWidget (control, context, damageRgn, visibleRgn, theEvent);
- if (OS.VERSION >= 0x1040) {
- if (control != handle) return;
- if (caret == null) return;
- if (caret.isShowing) {
- OS.CGContextSaveGState (context);
- CGRect rect = new CGRect ();
- rect.x = caret.x;
- rect.y = caret.y;
- Image image = caret.image;
- OS.CGContextSetBlendMode (context, OS.kCGBlendModeDifference);
- if (image != null) {
- rect.width = OS.CGImageGetWidth (image.handle);
- rect.height = OS.CGImageGetHeight (image.handle);
- OS.CGContextScaleCTM (context, 1, -1);
- OS.CGContextTranslateCTM (context, 0, -(rect.height + 2 * rect.y));
- OS.CGContextDrawImage (context, rect, image.handle);
- } else {
- rect.width = caret.width != 0 ? caret.width : Caret.DEFAULT_WIDTH;
- rect.height = caret.height;
- OS.CGContextSetShouldAntialias (context, false);
- int colorspace = OS.CGColorSpaceCreateDeviceRGB ();
- OS.CGContextSetFillColorSpace (context, colorspace);
- OS.CGContextSetFillColor (context, new float[]{1, 1, 1, 1});
- OS.CGColorSpaceRelease (colorspace);
- OS.CGContextFillRect (context, rect);
- }
- OS.CGContextRestoreGState (context);
- }
- }
-}
-
-/**
- * Returns the caret.
- * <p>
- * The caret for the control is automatically hidden
- * and shown when the control is painted or resized,
- * when focus is gained or lost and when an the control
- * is scrolled. To avoid drawing on top of the caret,
- * the programmer must hide and show the caret when
- * drawing in the window any other time.
- * </p>
- *
- * @return the caret for the receiver, may be null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Caret getCaret () {
- checkWidget();
- return caret;
-}
-
-/**
- * Returns the IME.
- *
- * @return the IME
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public IME getIME () {
- checkWidget();
- return ime;
-}
-
-int kEventControlDraw (int nextHandler, int theEvent, int userData) {
- int [] theControl = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamDirectObject, OS.typeControlRef, null, 4, null, theControl);
- boolean isFocus = OS.VERSION < 0x1040 && theControl [0] == handle && caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- int result = super.kEventControlDraw (nextHandler, theEvent, userData);
- if (isFocus) caret.setFocus ();
- return result;
-}
-
-int kEventControlSetFocusPart (int nextHandler, int theEvent, int userData) {
- int result = super.kEventControlSetFocusPart (nextHandler, theEvent, userData);
- if (result == OS.noErr) {
- if (!isDisposed ()) {
- Shell shell = getShell ();
- short [] part = new short [1];
- OS.GetEventParameter (theEvent, OS.kEventParamControlPart, OS.typeControlPartCode, null, 2, null, part);
- if (part [0] != OS.kControlFocusNoPart) {
- if (caret != null) caret.setFocus ();
- OS.ActivateTSMDocument (shell.imHandle);
- } else {
- if (caret != null) caret.killFocus ();
- OS.DeactivateTSMDocument (shell.imHandle);
- }
- }
- }
- return result;
-}
-
-int kEventTextInputOffsetToPos (int nextHandler, int theEvent, int userData) {
- if (ime != null) {
- int result = ime.kEventTextInputOffsetToPos (nextHandler, theEvent, userData);
- if (result != OS.eventNotHandledErr) return result;
- }
- return super.kEventTextInputOffsetToPos (nextHandler, theEvent, userData);
-}
-
-int kEventTextInputPosToOffset (int nextHandler, int theEvent, int userData) {
- if (ime != null) {
- int result = ime.kEventTextInputPosToOffset (nextHandler, theEvent, userData);
- if (result != OS.eventNotHandledErr) return result;
- }
- return super.kEventTextInputPosToOffset (nextHandler, theEvent, userData);
-}
-
-int kEventTextInputUnicodeForKeyEvent (int nextHandler, int theEvent, int userData) {
- int result = super.kEventTextInputUnicodeForKeyEvent(nextHandler, theEvent, userData);
- if (result != OS.noErr) {
- if (caret != null) {
- if (OS.CGCursorIsVisible ()) OS.CGDisplayHideCursor (OS.CGMainDisplayID ());
- }
- }
- return result;
-}
-
-int kEventTextInputUpdateActiveInputArea (int nextHandler, int theEvent, int userData) {
- if (ime != null) {
- int result = ime.kEventTextInputUpdateActiveInputArea (nextHandler, theEvent, userData);
- if (result != OS.eventNotHandledErr) return result;
- }
- return super.kEventTextInputUpdateActiveInputArea (nextHandler, theEvent, userData);
-}
-
-int kEventTextInputGetSelectedText (int nextHandler, int theEvent, int userData) {
- if (ime != null) {
- int result = ime.kEventTextInputGetSelectedText (nextHandler, theEvent, userData);
- if (result != OS.eventNotHandledErr) return result;
- }
- return super.kEventTextInputGetSelectedText (nextHandler, theEvent, userData);
-}
-
-void redrawWidget (int control, boolean children) {
- boolean isFocus = OS.VERSION < 0x1040 && caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- super.redrawWidget (control, children);
- if (isFocus) caret.setFocus ();
-}
-
-void redrawWidget (int control, int x, int y, int width, int height, boolean all) {
- boolean isFocus = OS.VERSION < 0x1040 && caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- super.redrawWidget (control, x, y, width, height, all);
- if (isFocus) caret.setFocus ();
-}
-
-void releaseChildren (boolean destroy) {
- if (caret != null) {
- caret.release (false);
- caret = null;
- }
- if (ime != null) {
- ime.release (false);
- ime = null;
- }
- super.releaseChildren (destroy);
-}
-
-/**
- * Scrolls a rectangular area of the receiver by first copying
- * the source area to the destination and then causing the area
- * of the source which is not covered by the destination to
- * be repainted. Children that intersect the rectangle are
- * optionally moved during the operation. In addition, outstanding
- * paint events are flushed before the source area is copied to
- * ensure that the contents of the canvas are drawn correctly.
- *
- * @param destX the x coordinate of the destination
- * @param destY the y coordinate of the destination
- * @param x the x coordinate of the source
- * @param y the y coordinate of the source
- * @param width the width of the area
- * @param height the height of the area
- * @param all <code>true</code>if children should be scrolled, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) {
- checkWidget();
- if (width <= 0 || height <= 0) return;
- int deltaX = destX - x, deltaY = destY - y;
- if (deltaX == 0 && deltaY == 0) return;
- if (!isDrawing ()) return;
- if (!OS.IsControlVisible (handle)) return;
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- Rectangle clientRect = getClientArea ();
- Rectangle sourceRect = new Rectangle (x, y, width, height);
- if (sourceRect.intersects (clientRect)) {
- update (all);
- }
- Control control = findBackgroundControl ();
- if (control != null && control.backgroundImage != null) {
- redrawWidget (handle, x, y, width, height, false);
- redrawWidget (handle, destX, destY, width, height, false);
- } else {
- GC gc = new GC (this);
- gc.copyArea (x, y, width, height, destX, destY);
- gc.dispose ();
- }
- if (all) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- Rectangle rect = child.getBounds ();
- if (Math.min(x + width, rect.x + rect.width) >= Math.max (x, rect.x) &&
- Math.min(y + height, rect.y + rect.height) >= Math.max (y, rect.y)) {
- child.setLocation (rect.x + deltaX, rect.y + deltaY);
- }
- }
- }
- if (isFocus) caret.setFocus ();
-}
-
-/**
- * Sets the receiver's caret.
- * <p>
- * The caret for the control is automatically hidden
- * and shown when the control is painted or resized,
- * when focus is gained or lost and when an the control
- * is scrolled. To avoid drawing on top of the caret,
- * the programmer must hide and show the caret when
- * drawing in the window any other time.
- * </p>
- * @param caret the new caret for the receiver, may be null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the caret has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCaret (Caret caret) {
- checkWidget();
- Caret newCaret = caret;
- Caret oldCaret = this.caret;
- this.caret = newCaret;
- if (hasFocus ()) {
- if (oldCaret != null) oldCaret.killFocus ();
- if (newCaret != null) {
- if (newCaret.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- newCaret.setFocus ();
- }
- }
-}
-
-public void setFont (Font font) {
- checkWidget ();
- if (caret != null) caret.setFont (font);
- super.setFont (font);
-}
-
-/**
- * Sets the receiver's IME.
- *
- * @param ime the new IME for the receiver, may be null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the IME has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setIME (IME ime) {
- checkWidget ();
- if (ime != null && ime.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- this.ime = ime;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Caret.java
deleted file mode 100644
index dda581cf3d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Caret.java
+++ /dev/null
@@ -1,566 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.RGBColor;
-import org.eclipse.swt.internal.carbon.Rect;
-import org.eclipse.swt.internal.carbon.CGPoint;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide an i-beam that is typically used
- * as the insertion point for text.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#caret">Caret snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Canvas tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Caret extends Widget {
- Canvas parent;
- int x, y, width, height;
- boolean isVisible, isShowing;
- int blinkRate;
- Image image;
- Font font;
-
- static final int DEFAULT_WIDTH = 1;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Caret (Canvas parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget ();
-}
-
-boolean blinkCaret () {
- if (!isVisible) return true;
- if (!isShowing) return showCaret ();
- if (blinkRate == 0) return true;
- return hideCaret ();
-}
-
-void createWidget () {
- super.createWidget ();
- blinkRate = display.getCaretBlinkTime ();
- isVisible = true;
- if (parent.getCaret () == null) {
- parent.setCaret (this);
- }
-}
-
-boolean drawCaret () {
- if (parent == null) return false;
- if (parent.isDisposed ()) return false;
- int parentHandle = parent.handle;
- if (!parent.isDrawing ()) return false;
- if (!OS.IsControlVisible (parentHandle)) return false;
- int nWidth = width, nHeight = height;
- if (nWidth <= 0) nWidth = DEFAULT_WIDTH;
- if (OS.VERSION >= 0x1040) {
- if (image != null) {
- nWidth = OS.CGImageGetWidth (image.handle);
- nHeight = OS.CGImageGetHeight (image.handle);
- }
- parent.redrawWidget (parent.handle, x, y, nWidth, nHeight, false);
- return true;
- }
- int window = OS.GetControlOwner (parentHandle);
- int port = OS.GetWindowPort (window);
- int [] currentPort = new int [1];
- OS.GetPort (currentPort);
- OS.SetPort (port);
- int oldClip = OS.NewRgn ();
- int visibleRgn = parent.getVisibleRegion (parentHandle, true);
- OS.GetClip (oldClip);
- OS.SetClip (visibleRgn);
- Rect rect = new Rect ();
- OS.GetControlBounds (parentHandle, rect);
- CGPoint pt = new CGPoint ();
- int [] contentView = new int [1];
- OS.HIViewFindByID (OS.HIViewGetRoot (window), OS.kHIViewWindowContentID (), contentView);
- OS.HIViewConvertPoint (pt, OS.HIViewGetSuperview (parentHandle), contentView [0]);
- rect.left += (int) pt.x;
- rect.top += (int) pt.y;
- int left = rect.left + x;
- int top = rect.top + y;
- if (image == null) {
- OS.SetRect(rect, (short) left, (short) top, (short) (left + nWidth), (short) (top + nHeight));
- RGBColor color = new RGBColor ();
- color.red = (short) 0xFFFF;
- color.green = (short) 0xFFFF;
- color.blue = (short) 0xFFFF;
- OS.RGBBackColor (color);
- OS.InvertRect (rect);
- } else {
- int imageHandle = image.handle;
- nWidth = OS.CGImageGetWidth (imageHandle);
- nHeight = OS.CGImageGetHeight (imageHandle);
- int bpl = OS.CGImageGetBytesPerRow (imageHandle);
- Rect bounds = new Rect ();
- bounds.right = (short) nWidth;
- bounds.bottom = (short) nHeight;
- Rect portRect = new Rect ();
- OS.GetWindowBounds (window, (short) OS.kWindowContentRgn, portRect);
- left += portRect.left;
- top += portRect.top;
- OS.SetRect(rect, (short) left, (short) top, (short) (left + nWidth), (short) (top + nHeight));
- int [] gWorld = new int [1];
- OS.NewGWorldFromPtr (gWorld, OS.k32ARGBPixelFormat, bounds, 0, 0, 0, image.data, bpl);
- int [] curPort = new int [1];
- int [] curGWorld = new int [1];
- OS.GetGWorld (curPort, curGWorld);
- OS.SetGWorld (gWorld [0], curGWorld [0]);
- int portBitMap = OS.GetPortBitMapForCopyBits (port);
- int gworldBitMap = OS.GetPortBitMapForCopyBits (gWorld [0]);
- OS.OffsetRgn(visibleRgn, portRect.left, portRect.top);
- OS.CopyBits (gworldBitMap, portBitMap, bounds, rect, (short) OS.notSrcXor, visibleRgn);
- OS.OffsetRgn(visibleRgn, (short) -portRect.left, (short) -portRect.top);
- OS.SetGWorld (curPort [0], curGWorld [0]);
- OS.DisposeGWorld (gWorld [0]);
- }
- OS.SetClip (oldClip);
- OS.DisposeRgn (visibleRgn);
- OS.DisposeRgn (oldClip);
- OS.SetPort (currentPort [0]);
- return true;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null).
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- if (image != null) {
- Rectangle rect = image.getBounds ();
- return new Rectangle (x, y, rect.width, rect.height);
- } else {
- if (width == 0) {
- return new Rectangle (x, y, DEFAULT_WIDTH, height);
- }
- }
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Font getFont () {
- checkWidget();
- if (font != null) return font;
- return parent.getFont ();
-}
-
-/**
- * Returns the image that the receiver will use to paint the caret.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null).
- *
- * @return the receiver's location
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getLocation () {
- checkWidget();
- return new Point (x, y);
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Canvas</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Canvas getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns a point describing the receiver's size.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- if (image != null) {
- Rectangle rect = image.getBounds ();
- return new Point (rect.width, rect.height);
- } else {
- if (width == 0) {
- return new Point (DEFAULT_WIDTH, height);
- }
- }
- return new Point (width, height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- return isVisible;
-}
-
-boolean hideCaret () {
- if (!isShowing) return true;
- isShowing = false;
- return drawCaret ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return isVisible && parent.isVisible () && parent.hasFocus ();
-}
-
-boolean isFocusCaret () {
- return this == display.currentCaret;
-}
-
-void killFocus () {
- if (display.currentCaret != this) return;
- display.setCurrentCaret (null);
- if (isVisible) hideCaret ();
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (this == parent.getCaret ()) parent.setCaret (null);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (display.currentCaret == this) {
- hideCaret ();
- display.setCurrentCaret (null);
- }
- parent = null;
- image = null;
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the arguments. The <code>x</code> and
- * <code>y</code> arguments are relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (int x, int y, int width, int height) {
- checkWidget();
- if (this.x == x && this.y == y && this.width == width && this.height == height) return;
- boolean isFocus = isFocusCaret ();
- if (isFocus && isVisible) hideCaret ();
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- if (isFocus && isVisible) showCaret ();
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the argument. The <code>x</code> and
- * <code>y</code> fields of the rectangle are relative to
- * the receiver's parent (or its display if its parent is null).
- *
- * @param rect the new bounds for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (Rectangle rect) {
- checkWidget();
- if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (rect.x, rect.y, rect.width, rect.height);
-}
-
-void setFocus () {
- if (display.currentCaret == this) return;
- display.setCurrentCaret (this);
- if (isVisible) showCaret ();
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * to the font specified by the argument, or to the default font for that
- * kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkWidget();
- if (font != null && font.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.font = font;
-}
-
-/**
- * Sets the image that the receiver will use to paint the caret
- * to the image specified by the argument, or to the default
- * which is a filled rectangle if the argument is null
- *
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- boolean isFocus = isFocusCaret ();
- if (isFocus && isVisible) hideCaret ();
- this.image = image;
- if (isFocus && isVisible) showCaret ();
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget();
- setBounds (x, y, width, height);
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the argument which is relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param location the new location for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (Point location) {
- checkWidget();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-/**
- * Sets the receiver's size to the point specified by the arguments.
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (int width, int height) {
- checkWidget();
- setBounds (x, y, width, height);
-}
-
-/**
- * Sets the receiver's size to the point specified by the argument.
- *
- * @param size the new extent for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (Point size) {
- checkWidget();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSize (size.x, size.y);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget();
- if (visible == isVisible) return;
- isVisible = visible;
- if (!isFocusCaret ()) return;
- if (isVisible) {
- showCaret ();
- } else {
- hideCaret ();
- }
-}
-
-boolean showCaret () {
- if (isShowing) return true;
- isShowing = true;
- return drawCaret ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ColorDialog.java
deleted file mode 100644
index a19553c849..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ColorDialog.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.carbon.*;
-import org.eclipse.swt.graphics.RGB;
-
-/**
- * Instances of this class allow the user to select a color
- * from a predefined set of available colors.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ColorDialog extends Dialog {
- RGB rgb;
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a composite control which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ColorDialog(Shell parent) {
- this(parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ColorDialog(Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-/**
- * Returns the currently selected color in the receiver.
- *
- * @return the RGB value for the selected color, may be null
- *
- * @see PaletteData#getRGBs
- */
-public RGB getRGB() {
- return rgb;
-}
-
-/**
- * Makes the receiver visible and brings it to the front
- * of the display.
- *
- * @return the selected color, or null if the dialog was
- * cancelled, no color was selected, or an error
- * occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public RGB open() {
- ColorPickerInfo info = new ColorPickerInfo ();
- if (rgb != null) {
- info.red = (short)(rgb.red * 257);
- info.green = (short)(rgb.green * 257);
- info.blue = (short)(rgb.blue * 257);
- } else {
- info.red = (short)(255 * 257);
- info.green = (short)(255 * 257);
- info.blue = (short)(255 * 257);
- }
- info.flags = OS.kColorPickerDialogIsMoveable | OS.kColorPickerDialogIsModal;
- // NEEDS WORK - shouldn't be at mouse location
- info.placeWhere = (short)OS.kAtSpecifiedOrigin;
- org.eclipse.swt.internal.carbon.Point mp = new org.eclipse.swt.internal.carbon.Point ();
- OS.GetGlobalMouse (mp);
- info.v = mp.v;
- info.h = mp.h;
- if (title != null) {
- // NEEDS WORK - no title displayed
- info.prompt = new byte[256];
- int length = title.length();
- if (length > 255) length = 255;
- info.prompt [0] = (byte)length;
- for (int i=0; i<length; i++) {
- info.prompt [i+1] = (byte)title.charAt (i);
- }
- }
- rgb = null;
- if (OS.PickColor (info) == OS.noErr && info.newColorChosen) {
- int red = (info.red >> 8) & 0xFF;
- int green = (info.green >> 8) & 0xFF;
- int blue = (info.blue >> 8) & 0xFF;
- rgb = new RGB(red, green, blue);
- }
- return rgb;
-}
-
-/**
- * Sets the receiver's selected color to be the argument.
- *
- * @param rgb the new RGB value for the selected color, may be
- * null to let the platform select a default when
- * open() is called
- * @see PaletteData#getRGBs
- */
-public void setRGB(RGB rgb) {
- this.rgb = rgb;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Combo.java
deleted file mode 100644
index 17ae143f01..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Combo.java
+++ /dev/null
@@ -1,1902 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.carbon.ControlEditTextSelectionRec;
-import org.eclipse.swt.internal.carbon.MenuTrackingData;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.CFRange;
-import org.eclipse.swt.internal.carbon.CGRect;
-import org.eclipse.swt.internal.carbon.Rect;
-
-/**
- * Instances of this class are controls that allow the user
- * to choose an item from a list of items, or optionally
- * enter a new value by typing it into an editable text
- * field. Often, <code>Combo</code>s are used in the same place
- * where a single selection <code>List</code> widget could
- * be used but space is limited. A <code>Combo</code> takes
- * less space than a <code>List</code> widget and shows
- * similar information.
- * <p>
- * Note: Since <code>Combo</code>s can contain both a list
- * and an editable text field, it is possible to confuse methods
- * which access one versus the other (compare for example,
- * <code>clearSelection()</code> and <code>deselectAll()</code>).
- * The API documentation is careful to indicate either "the
- * receiver's list" or the "the receiver's text field" to
- * distinguish between the two cases.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>DROP_DOWN, READ_ONLY, SIMPLE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Modify, Selection, Verify</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles DROP_DOWN and SIMPLE may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see List
- * @see <a href="http://www.eclipse.org/swt/snippets/#combo">Combo snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Combo extends Composite {
- int menuHandle;
- int textLimit = LIMIT;
- String lastText = "";
- ControlEditTextSelectionRec selection;
-
- /**
- * the operating system limit for the number of characters
- * that the text field in an instance of this class can hold
- */
- public static final int LIMIT;
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0x7FFFFFFF;
- }
-
- static final String [] AX_ATTRIBUTES = {
- OS.kAXValueAttribute,
- OS.kAXNumberOfCharactersAttribute,
- OS.kAXSelectedTextAttribute,
- OS.kAXSelectedTextRangeAttribute,
- OS.kAXStringForRangeParameterizedAttribute,
- };
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see SWT#READ_ONLY
- * @see SWT#SIMPLE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Combo (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the argument to the end of the receiver's list.
- *
- * @param string the new item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String,int)
- */
-public void add (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- char [] buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (ptr == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- int result;
- if ((style & SWT.READ_ONLY) != 0) {
- result = OS.AppendMenuItemTextWithCFString (menuHandle, ptr, 0, 0, null);
- /*
- * Feature in the Macintosh. Setting text that starts with "-" makes the
- * menu item a separator. The fix is to clear the separator attribute.
- */
- if (string.startsWith ("-")) {
- OS.ChangeMenuItemAttributes (menuHandle, (short)OS.CountMenuItems (menuHandle), 0, OS.kMenuItemAttrSeparator);
- }
- } else {
- result = OS.HIComboBoxAppendTextItem (handle, ptr, null);
- }
- OS.CFRelease (ptr);
- if (result != OS.noErr) error (SWT.ERROR_ITEM_NOT_ADDED);
-}
-
-/**
- * Adds the argument to the receiver's list at the given
- * zero-relative index.
- * <p>
- * Note: To add an item at the end of the list, use the
- * result of calling <code>getItemCount()</code> as the
- * index or use <code>add(String)</code>.
- * </p>
- *
- * @param string the new item
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String)
- */
-public void add (String string, int index) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = getItemCount ();
- if (0 > index || index > count) error (SWT.ERROR_INVALID_RANGE);
- char [] buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (ptr == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- int result;
- int selectionIndex = -1;
- if ((style & SWT.READ_ONLY) != 0) {
- selectionIndex = OS.GetControlValue (handle) - 1;
- result = OS.InsertMenuItemTextWithCFString (menuHandle, ptr, (short)index, 0, 0);
- /*
- * Feature in the Macintosh. Setting text that starts with "-" makes the
- * menu item a separator. The fix is to clear the separator attribute.
- */
- if (string.startsWith ("-")) {
- OS.ChangeMenuItemAttributes (menuHandle, (short)(index + 1), 0, OS.kMenuItemAttrSeparator);
- }
- } else {
- result = OS.HIComboBoxInsertTextItemAtIndex (handle, index, ptr);
- }
- OS.CFRelease (ptr);
- if (result != OS.noErr) error (SWT.ERROR_ITEM_NOT_ADDED);
- /*
- * When inserting an item into a READ_ONLY combo at or above the selected
- * index neither the selection index nor the text get updated. Fix is to
- * update the selection index to be sure the displayed item matches the
- * selected index.
- */
- if (selectionIndex >= index) OS.SetControl32BitValue (handle, selectionIndex + 2);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the combo's list selection.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed the combo's text area.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- *
- * @since 3.1
- */
-public void addVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-
-int callFocusEventHandler (int nextHandler, int theEvent) {
- short [] part = new short [1];
- if ((style & SWT.READ_ONLY) == 0) {
- OS.GetEventParameter (theEvent, OS.kEventParamControlPart, OS.typeControlPartCode, null, 2, null, part);
- if (part [0] == OS.kControlFocusNoPart) {
- selection = new ControlEditTextSelectionRec ();
- OS.GetControlData (handle, (short) OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection, null);
- }
- }
- int result = super.callFocusEventHandler (nextHandler, theEvent);
- if ((style & SWT.READ_ONLY) == 0) {
- if (part [0] != OS.kControlFocusNoPart && selection != null) {
- OS.SetControlData (handle, (short) OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection);
- selection = null;
- }
- }
- return result;
-}
-
-
-static int checkStyle (int style) {
- /*
- * Feature in Windows. It is not possible to create
- * a combo box that has a border using Windows style
- * bits. All combo boxes draw their own border and
- * do not use the standard Windows border styles.
- * Therefore, no matter what style bits are specified,
- * clear the BORDER bits so that the SWT style will
- * match the Windows widget.
- *
- * The Windows behavior is currently implemented on
- * all platforms.
- */
- style &= ~SWT.BORDER;
-
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- style &= ~(SWT.H_SCROLL | SWT.V_SCROLL);
- style = checkBits (style, SWT.DROP_DOWN, SWT.SIMPLE, 0, 0, 0, 0);
- if ((style & SWT.SIMPLE) != 0) return style & ~SWT.READ_ONLY;
- return style;
-}
-
-void checkSelection () {
- if ((style & SWT.READ_ONLY) != 0) return;
- String newText = getText ();
- if (newText.equals (lastText)) return;
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- setText (lastText, false);
- newText = verifyText (newText, 0, lastText.length (), null);
- if (newText == null) return;
- setText (newText, false);
- } else {
- lastText = newText;
- }
- sendEvent (SWT.Modify);
- if (isDisposed ()) return;
- int index = indexOf (newText);
- if (index != -1) postEvent (SWT.Selection);
-
- /* Send value changed notification to accessible client. */
- String string = OS.kAXFocusedWindowChangedNotification;
- char [] buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- int stringRef = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- OS.AXNotificationHIObjectNotify(stringRef, handle, 0);
- OS.CFRelease(stringRef);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Sets the selection in the receiver's text field to an empty
- * selection starting just before the first character. If the
- * text field is editable, this has the effect of placing the
- * i-beam at the start of the text.
- * <p>
- * Note: To clear the selected items in the receiver's list,
- * use <code>deselectAll()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #deselectAll
- */
-public void clearSelection () {
- checkWidget();
- if ((style & SWT.READ_ONLY) == 0) {
- Point selection = getSelection ();
- selection.y = selection.x;
- setSelection (selection);
- }
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0;
- int [] ptr = new int [1];
- if ((style & SWT.READ_ONLY) != 0) {
- int index = OS.GetControlValue (handle) - 1;
- OS.CopyMenuItemTextAsCFString (menuHandle, (short)(index+1), ptr);
- } else {
- OS.GetControlData (handle, (short)OS.kHIComboBoxEditTextPart, OS.kControlEditTextCFStringTag, 4, ptr, null);
- }
- Point size = textExtent (ptr [0], 0);
- if (ptr [0] != 0) OS.CFRelease (ptr [0]);
- width = Math.max (width, size.x);
- height = Math.max (height, size.y);
- int count;
- if ((style & SWT.READ_ONLY) != 0) {
- count = OS.CountMenuItems (menuHandle);
- } else {
- count = OS.HIComboBoxGetItemCount (handle);
- }
- for (int i=0; i<count; i++) {
- int result;
- if ((style & SWT.READ_ONLY) != 0) {
- result = OS.CopyMenuItemTextAsCFString(menuHandle, (short)(i+1), ptr);
- } else {
- result = OS.HIComboBoxCopyTextItemAtIndex (handle, i, ptr);
- }
- if (result == OS.noErr) {
- size = textExtent (ptr [0], 0);
- width = Math.max (width, size.x);
- OS.CFRelease (ptr [0]);
- }
- }
- int [] metric = new int [1];
- if ((style & SWT.READ_ONLY) != 0) {
- OS.GetThemeMetric (OS.kThemeMetricDisclosureButtonWidth, metric);
- width += metric [0];
- //TODO
- width += 13;
- } else {
- OS.GetThemeMetric (OS.kThemeMetricComboBoxLargeDisclosureWidth, metric);
- width += metric [0];
- }
- OS.GetThemeMetric (OS.kThemeMetricEditTextWhitespace, metric);
- width += metric [0] * 2;
- height += metric [0] * 2;
- Rect inset = getInset ();
- width += inset.left + inset.right;
- height += inset.top + inset.bottom;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- return new Point (width, height);
-}
-
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void copy () {
- checkWidget ();
- Point selection = getSelection ();
- if (selection.x == selection.y) return;
- copyToClipboard (getText (selection.x, selection.y));
-}
-
-void createHandle () {
- if ((style & SWT.READ_ONLY) != 0) {
- int [] outControl = new int [1];
- int window = OS.GetControlOwner (parent.handle);
- /*
- * From ControlDefinitions.h:
- *
- * Passing in a menu ID of -12345 causes the popup not to try and get the menu from a
- * resource. Instead, you can build the menu and later stuff the MenuRef field in
- * the popup data information.
- */
- OS.CreatePopupButtonControl(window, null, 0, (short)-12345, false, (short)0, (short)0, 0, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
- int[] menuRef= new int [1];
- OS.CreateNewMenu ((short) 0, 0, menuRef);
- if (menuRef [0] == 0) error (SWT.ERROR_NO_HANDLES);
- menuHandle = menuRef[0];
- OS.SetControlPopupMenuHandle (handle, menuHandle);
- OS.SetControl32BitMaximum (handle, 0x7FFF);
- } else {
- int [] outControl = new int [1];
- CGRect rect = new CGRect ();
- int inAttributes = OS.kHIComboBoxAutoSizeListAttribute;
- /*
- * The following code is intentionally commented.
- * Auto completion does not allow the user to change
- * case of the text in a combo box.
- */
-// inAttributes |= OS.kHIComboBoxAutoCompletionAttribute;
- OS.HIComboBoxCreate(rect, 0, null, 0, inAttributes, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
- OS.SetControlData (handle, (short)OS.kHIComboBoxEditTextPart, OS.kTXNDrawCaretWhenInactiveTag, 4, new byte [ ]{0});
- OS.HIViewSetVisible (handle, true);
- }
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void cut () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- Point selection = getSelection ();
- if (selection.x == selection.y) return;
- int start = selection.x, end = selection.y;
- String text = getText ();
- String leftText = text.substring (0, start);
- String rightText = text.substring (end, text.length ());
- String oldText = text.substring (start, end);
- String newText = "";
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- newText = verifyText (newText, start, end, null);
- if (newText == null) return;
- }
- char [] buffer = new char [oldText.length ()];
- oldText.getChars (0, buffer.length, buffer, 0);
- copyToClipboard (buffer);
- setText (leftText + newText + rightText, false);
- start += newText.length ();
- setSelection (new Point (start, start));
- sendEvent (SWT.Modify);
-}
-
-Color defaultBackground () {
- return display.getSystemColor (SWT.COLOR_LIST_BACKGROUND);
-}
-
-Color defaultForeground () {
- return display.getSystemColor (SWT.COLOR_LIST_FOREGROUND);
-}
-
-/**
- * Deselects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget ();
- if (index == -1) return;
- if (index == getSelectionIndex ()) {
- if ((style & SWT.READ_ONLY) != 0) {
- OS.SetControl32BitValue (handle, 0);
- sendEvent (SWT.Modify);
- } else {
- setText ("");
- }
- }
-}
-
-/**
- * Deselects all selected items in the receiver's list.
- * <p>
- * Note: To clear the selection in the receiver's text field,
- * use <code>clearSelection()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #clearSelection
- */
-public void deselectAll () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) {
- OS.SetControl32BitValue (handle, 0);
- sendEvent (SWT.Modify);
- } else {
- setText ("");
- }
-}
-
-void destroyWidget () {
- /*
- * Bug in the Macintosh. Carbon segments fault if the combo box has
- * keyboard focus and it is disposed or its parent is disposed because
- * there is an outstanding timer that runs after the widget is dispoed.
- * The fix is to remove the combo box from its parent and dispose it when
- * the display is idle.
- *
- * NOTE: The problem does not happen when the window is disposed.
- */
- if ((getShell ().state & DISPOSE_SENT) != 0) {
- super.destroyWidget ();
- } else {
- releaseHandle ();
- }
-}
-
-String [] getAxAttributes () {
- return AX_ATTRIBUTES;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver's list. Throws an exception if the index is out
- * of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getItem (int index) {
- checkWidget ();
- int count = getItemCount ();
- if (0 > index || index >= count) error (SWT.ERROR_INVALID_RANGE);
- int[] ptr = new int[1];
- int result;
- if ((style & SWT.READ_ONLY) != 0) {
- result = OS.CopyMenuItemTextAsCFString(menuHandle, (short)(index+1), ptr);
- } else {
- result = OS.HIComboBoxCopyTextItemAtIndex (handle, index, ptr);
- }
- if (result != OS.noErr) error(SWT.ERROR_CANNOT_GET_ITEM);
- int length = OS.CFStringGetLength (ptr [0]);
- char [] buffer= new char [length];
- CFRange range = new CFRange ();
- range.length = length;
- OS.CFStringGetCharacters (ptr [0], range, buffer);
- OS.CFRelease (ptr [0]);
- return new String (buffer);
-}
-
-/**
- * Returns the number of items contained in the receiver's list.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) {
- return OS.CountMenuItems (menuHandle);
- } else {
- return OS.HIComboBoxGetItemCount (handle);
- }
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the receiver's list.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- //TODO - not supported by the OS
- return 26;
-}
-
-/**
- * Returns a (possibly empty) array of <code>String</code>s which are
- * the items in the receiver's list.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver's list
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getItems () {
- checkWidget ();
- int count = getItemCount ();
- String [] result = new String [count];
- for (int i=0; i<count; i++) result [i] = getItem (i);
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver's list is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's list's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getListVisible () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) {
- MenuTrackingData outData = new MenuTrackingData ();
- return OS.GetMenuTrackingData (menuHandle, outData) == OS.noErr;
- } else {
- if (OS.VERSION >= 0x1040) {
- return OS.HIComboBoxIsListVisible (handle);
- }
- return false;
- }
-}
-
-int getMininumHeight () {
- return getTextHeight ();
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the orientation of the receiver.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getOrientation () {
- checkWidget();
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-/**
- * Returns a <code>Point</code> whose x coordinate is the
- * character position representing the start of the selection
- * in the receiver's text field, and whose y coordinate is the
- * character position representing the end of the selection.
- * An "empty" selection is indicated by the x and y coordinates
- * having the same value.
- * <p>
- * Indexing is zero based. The range of a selection is from
- * 0..N where N is the number of characters in the widget.
- * </p>
- *
- * @return a point representing the selection start and end
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSelection () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) {
- return new Point (0, getCharCount ());
- } else {
- ControlEditTextSelectionRec selection;
- if (this.selection != null) {
- selection = this.selection;
- } else {
- selection = new ControlEditTextSelectionRec ();
- OS.GetControlData (handle, (short) OS.kHIComboBoxEditTextPart, OS.kControlEditTextSelectionTag, 4, selection, null);
- }
- return new Point (selection.selStart, selection.selEnd);
- }
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver's list, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) {
- return OS.GetControlValue (handle) - 1;
- } else {
- return indexOf (getText ());
- }
-}
-
-/**
- * Returns a string containing a copy of the contents of the
- * receiver's text field, or an empty string if there are no
- * contents.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return new String (getText (0, -1));
-}
-
-char [] getText (int start, int end) {
- int result;
- int [] ptr = new int [1];
- if ((style & SWT.READ_ONLY) != 0) {
- int index = OS.GetControlValue (handle) - 1;
- result = OS.CopyMenuItemTextAsCFString (menuHandle, (short)(index+1), ptr);
- } else {
- int [] actualSize = new int [1];
- result = OS.GetControlData (handle, (short)OS.kHIComboBoxEditTextPart, OS.kControlEditTextCFStringTag, 4, ptr, actualSize);
- }
- if (result != OS.noErr) return new char [0];
- CFRange range = new CFRange ();
- range.location = start;
- if (end == -1) {
- int length = OS.CFStringGetLength (ptr [0]);
- range.length = length - start;
- } else {
- range.length = end - start;
- }
- char [] buffer= new char [range.length];
- OS.CFStringGetCharacters (ptr [0], range, buffer);
- OS.CFRelease (ptr [0]);
- return buffer;
-}
-
-/**
- * Returns the height of the receivers's text field.
- *
- * @return the text height
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTextHeight () {
- checkWidget();
- //TODO - not supported by the OS
- return 26;
-}
-
-/**
- * Returns the maximum number of characters that the receiver's
- * text field is capable of holding. If this has not been changed
- * by <code>setTextLimit()</code>, it will be the constant
- * <code>Combo.LIMIT</code>.
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public int getTextLimit () {
- checkWidget();
- return textLimit;
-}
-
-/**
- * Gets the number of items that are visible in the drop
- * down portion of the receiver's list.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @return the number of items that are visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public int getVisibleItemCount () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) {
- return getItemCount ();
- } else {
- int [] buffer = new int [1];
- OS.GetControlData (handle, (short) OS.kControlEntireControl, OS.kHIComboBoxNumVisibleItemsTag, 4, buffer, null);
- return buffer [0];
- }
-}
-
-void hookEvents () {
- super.hookEvents ();
- if ((style & SWT.READ_ONLY) != 0) {
- int commandProc = display.commandProc;
- int [] mask = new int [] {
- OS.kEventClassCommand, OS.kEventProcessCommand,
- };
- int menuTarget = OS.GetMenuEventTarget (menuHandle);
- OS.InstallEventHandler (menuTarget, commandProc, mask.length / 2, mask, handle, null);
- }
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param string the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string) {
- return indexOf (string, 0);
-}
-
-/**
- * Searches the receiver's list starting at the given,
- * zero-relative index until an item is found that is equal
- * to the argument, and returns the index of that item. If
- * no item is found or the starting index is out of range,
- * returns -1.
- *
- * @param string the search item
- * @param start the zero-relative index at which to begin the search
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string, int start) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = getItemCount ();
- if (!(0 <= start && start < count)) return -1;
- for (int i=start; i<count; i++) {
- if (string.equals (getItem (i))) {
- return i;
- }
- }
- return -1;
-}
-
-int getCharCount () {
-// checkWidget ();
- int [] ptr = new int [1];
- int result;
- if ((style & SWT.READ_ONLY) != 0) {
- int index = OS.GetControlValue (handle) - 1;
- result = OS.CopyMenuItemTextAsCFString(menuHandle, (short)(index+1), ptr);
- } else {
- int [] actualSize = new int [1];
- result = OS.GetControlData (handle, (short)OS.kHIComboBoxEditTextPart, OS.kControlEditTextCFStringTag, 4, ptr, actualSize);
- }
- if (result != OS.noErr) return 0;
- int length = OS.CFStringGetLength (ptr [0]);
- OS.CFRelease (ptr [0]);
- return length;
-}
-
-Rect getInset () {
- return display.comboInset;
-}
-
-int kEventAccessibleGetNamedAttribute (int nextHandler, int theEvent, int userData) {
- int code = OS.eventNotHandledErr;
- if ((style & SWT.READ_ONLY) == 0) {
- int [] stringRef = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamAccessibleAttributeName, OS.typeCFStringRef, null, 4, null, stringRef);
- int length = 0;
- if (stringRef [0] != 0) length = OS.CFStringGetLength (stringRef [0]);
- char [] buffer = new char [length];
- CFRange range = new CFRange ();
- range.length = length;
- OS.CFStringGetCharacters (stringRef [0], range, buffer);
- String attributeName = new String(buffer);
- if (attributeName.equals (OS.kAXValueAttribute)) {
- buffer = getText(0, -1);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- } else if (attributeName.equals (OS.kAXNumberOfCharactersAttribute)) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeSInt32, 4, new int [] {getCharCount()});
- code = OS.noErr;
- } else if (attributeName.equals (OS.kAXSelectedTextAttribute)) {
- Point sel = getSelection ();
- buffer = getText(sel.x, sel.y);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- } else if (attributeName.equals (OS.kAXSelectedTextRangeAttribute)) {
- Point sel = getSelection ();
- range = new CFRange();
- range.location = sel.x;
- range.length = sel.y - sel.x;
- int valueRef = OS.AXValueCreate(OS.kAXValueCFRangeType, range);
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFTypeRef, 4, new int [] {valueRef});
- OS.CFRelease(valueRef);
- code = OS.noErr;
- } else if (attributeName.equals (OS.kAXStringForRangeParameterizedAttribute)) {
- int valueRef [] = new int [1];
- int status = OS.GetEventParameter (theEvent, OS.kEventParamAccessibleAttributeParameter, OS.typeCFTypeRef, null, 4, null, valueRef);
- if (status == OS.noErr) {
- range = new CFRange();
- boolean ok = OS.AXValueGetValue(valueRef[0], OS.kAXValueCFRangeType, range);
- if (ok) {
- buffer = getText (range.location, range.location + range.length);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- }
- }
- }
- }
- if (accessible != null) {
- code = accessible.internal_kEventAccessibleGetNamedAttribute (nextHandler, theEvent, code);
- }
- return code;
-}
-
-int kEventControlActivate (int nextHandler, int theEvent, int userData) {
- int result = super.kEventControlActivate (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- /*
- * Feature in the Macintosh. When a combo box gets
- * kEventControlActivate, it starts the caret blinking.
- * Because there is no clipping on the Macintosh, the
- * caret may blink through a widget that is obscured.
- * The fix is to avoid running the default handler.
- */
- return OS.noErr;
-}
-
-int kEventProcessCommand (int nextHandler, int theEvent, int userData) {
- int result = super.kEventProcessCommand (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the modify
- * event. If this happens, end the processing of the
- * Windows message by returning zero as the result of
- * the window proc.
- *
- * Note: this should be a send event, but selection is updated
- * right way.
- */
- postEvent (SWT.Modify);
- if (isDisposed ()) return OS.eventNotHandledErr;
- postEvent (SWT.Selection);
- return OS.eventNotHandledErr;
-}
-
-int kEventRawKeyPressed (int nextHandler, int theEvent, int userData) {
- /*
- * Feature in the Macintosh. The combo box widget consumes the
- * kEventRawKeyDown event when the up and down arrow keys are
- * pressed, causing kEventTextInputUnicodeForKeyEvent not
- * to be sent. The fix is to handle these keys in kEventRawKeyDown.
- *
- * NOTE: This was fixed in OS X 10.4.
- */
- if (OS.VERSION < 0x1040) {
- int [] keyCode = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyCode, OS.typeUInt32, null, keyCode.length * 4, null, keyCode);
- switch (keyCode [0]) {
- case 126: /* Up arrow */
- case 125: /* Down arrow */
- if (!sendKeyEvent (SWT.KeyDown, theEvent)) return OS.noErr;
- break;
- }
- }
- return OS.eventNotHandledErr;
-}
-
-int kEventControlSetFocusPart (int nextHandler, int theEvent, int userData) {
- int result = super.kEventControlSetFocusPart (nextHandler, theEvent, userData);
- if (result == OS.noErr) {
- if ((style & SWT.READ_ONLY) == 0) {
- short [] part = new short [1];
- OS.GetEventParameter (theEvent, OS.kEventParamControlPart, OS.typeControlPartCode, null, 2, null, part);
- if (part [0] != OS.kControlFocusNoPart) display.focusCombo = this;
- }
- }
- return result;
-}
-
-int kEventUnicodeKeyPressed (int nextHandler, int theEvent, int userData) {
- int result = super.kEventUnicodeKeyPressed (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- int [] keyboardEvent = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendKeyboardEvent, OS.typeEventRef, null, keyboardEvent.length * 4, null, keyboardEvent);
- int [] keyCode = new int [1];
- OS.GetEventParameter (keyboardEvent [0], OS.kEventParamKeyCode, OS.typeUInt32, null, keyCode.length * 4, null, keyCode);
-
- String string = OS.kAXValueChangedNotification;
- char [] buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- int stringRef = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- OS.AXNotificationHIObjectNotify(stringRef, handle, 0);
- OS.CFRelease(stringRef);
- string = OS.kAXSelectedTextChangedNotification;
- buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- stringRef = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- OS.AXNotificationHIObjectNotify(stringRef, handle, 0);
- OS.CFRelease(stringRef);
-
- if (hooks (SWT.Verify) || filters (SWT.Verify)
- || hooks (SWT.Modify) || filters (SWT.Modify)) {
- int [] modifiers = new int [1];
- OS.GetEventParameter (keyboardEvent [0], OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
- if (modifiers [0] == OS.cmdKey) {
- switch (keyCode [0]) {
- case 7: /* X */
- cut ();
- return OS.noErr;
- case 9: /* V */
- paste ();
- return OS.noErr;
- }
- }
- }
- switch (keyCode [0]) {
- case 76: /* KP Enter */
- case 36: { /* Return */
- postEvent (SWT.DefaultSelection);
- break;
- }
- }
- result = OS.CallNextEventHandler (nextHandler, theEvent);
- lastText = getText ();
- return result;
-}
-
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void paste () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- Point selection = getSelection ();
- int start = selection.x, end = selection.y;
- String text = getText ();
- String leftText = text.substring (0, start);
- String rightText = text.substring (end, text.length ());
- String newText = getClipboardText ();
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- newText = verifyText (newText, start, end, null);
- if (newText == null) return;
- }
- if (textLimit != LIMIT) {
- int charCount = text.length ();
- if (charCount - (end - start) + newText.length() > textLimit) {
- newText = newText.substring(0, textLimit - charCount + (end - start));
- }
- }
- setText (leftText + newText + rightText, false);
- start += newText.length ();
- setSelection (new Point (start, start));
- sendEvent (SWT.Modify);
-}
-
-boolean pollTrackEvent() {
- return true;
-}
-
-void releaseHandle () {
- /*
- * Bug in the Macintosh. Carbon segments fault if the combo box has
- * keyboard focus and it is disposed or its parent is disposed because
- * there is an outstanding timer that runs after the widget is dispoed.
- * The fix is to remove the combo box from its parent and dispose it when
- * the display is idle.
- *
- * NOTE: The problem does not happen when the window is disposed.
- */
- if ((getShell ().state & DISPOSE_SENT) == 0) {
- display.addToDisposeWindow (handle);
- }
- super.releaseHandle ();
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (display.focusCombo == this) display.focusCombo = null;
- if (menuHandle != 0) {
- OS.DisposeMenu (menuHandle);
- }
- menuHandle = 0;
-}
-
-/**
- * Removes the item from the receiver's list at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget ();
- if (index == -1) error (SWT.ERROR_INVALID_RANGE);
- int count = getItemCount ();
- if (0 > index || index >= count) error (SWT.ERROR_INVALID_RANGE);
- if ((style & SWT.READ_ONLY) != 0) {
- OS.DeleteMenuItems (menuHandle, (short)(index+1), 1);
- if (index == OS.GetControlValue (handle) - 1) {
- OS.SetControl32BitValue (handle, 0);
- }
- } else {
- OS.HIComboBoxRemoveItemAtIndex (handle, index);
- }
-}
-
-/**
- * Removes the items from the receiver's list which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget();
- if (start > end) return;
- int count = getItemCount ();
- if (!(0 <= start && start <= end && end < count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int newEnd = Math.min (end, count - 1);
- if ((style & SWT.READ_ONLY) != 0) {
- OS.DeleteMenuItems (menuHandle, (short)(start+1), newEnd-start+1);
- int index = OS.GetControlValue (handle) - 1;
- if (start <= index && index <= end) {
- OS.SetControl32BitValue (handle, 0);
- }
- } else {
- for (int i=newEnd; i>=start; i--) {
- OS.HIComboBoxRemoveItemAtIndex (handle, i);
- }
- }
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * until an item is found that is equal to the argument,
- * and removes that item from the list.
- *
- * @param string the item to remove
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = indexOf (string, 0);
- if (index == -1) error (SWT.ERROR_INVALID_ARGUMENT);
- remove (index);
-}
-
-/**
- * Removes all of the items from the receiver's list and clear the
- * contents of receiver's text field.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget ();
- int count = getItemCount ();
- if ((style & SWT.READ_ONLY) != 0) {
- OS.DeleteMenuItems (menuHandle, (short)1, count);
- OS.SetControl32BitValue (handle, 0);
- } else {
- setText ("", true);
- if (count > 0) {
- for (int i=count-1; i>=0; i--) {
- OS.HIComboBoxRemoveItemAtIndex (handle, i);
- }
- }
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- *
- * @since 3.1
- */
-public void removeVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget ();
- int count = getItemCount ();
- if (0 <= index && index < count) {
- if ((style & SWT.READ_ONLY) != 0) {
- OS.SetControl32BitValue (handle, index + 1);
- sendEvent (SWT.Modify);
- } else {
- setText (getItem (index), true);
- }
- }
-}
-
-boolean sendKeyEvent (int type, Event event) {
- if (!super.sendKeyEvent (type, event)) {
- return false;
- }
- if (type != SWT.KeyDown) return true;
- if ((style & SWT.READ_ONLY) != 0) return true;
- if (event.character == 0) return true;
- if ((event.stateMask & SWT.COMMAND) != 0) return true;
- String oldText = "", newText = "";
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- int charCount = getCharCount ();
- Point selection = getSelection ();
- int start = selection.x, end = selection.y;
- switch (event.character) {
- case SWT.BS:
- if (start == end) {
- if (start == 0) return true;
- start = Math.max (0, start - 1);
- }
- break;
- case SWT.DEL:
- if (start == end) {
- if (start == charCount) return true;
- end = Math.min (end + 1, charCount);
- }
- break;
- case SWT.CR:
- return true;
- default:
- if (event.character != '\t' && event.character < 0x20) return true;
- oldText = new String (new char [] {event.character});
- }
- newText = verifyText (oldText, start, end, event);
- if (newText == null) return false;
- if (charCount - (end - start) + newText.length () > textLimit) {
- return false;
- }
- if (newText != oldText) {
- String text = getText ();
- String leftText = text.substring (0, start);
- String rightText = text.substring (end, text.length ());
- setText (leftText + newText + rightText, false);
- start += newText.length ();
- setSelection (new Point (start, start));
- }
- }
- /*
- * Post the modify event so that the character will be inserted
- * into the widget when the modify event is delivered. Normally,
- * modify events are sent but it is safe to post the event here
- * because this method is called from the event loop.
- */
- postEvent (SWT.Modify);
- return newText == oldText;
-}
-
-void setBackground (int control, float [] color) {
- if ((style & SWT.READ_ONLY) == 0) {
- if (color == null) color = defaultBackground ().handle;
- }
- super.setBackground (control, color);
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- if ((style & SWT.READ_ONLY) != 0) {
- return super.setBounds (x, y, width, height, move, resize, events);
- }
- /*
- * Bug in the Macintosh. When the caret is moved,
- * the combo widget scrolls to show the new location.
- * This means that the combo widget may be scrolled
- * to the left in order to show the caret when the
- * widget is not large enough to show both the caret
- * location and all the text. Unfortunately, when
- * the widget is resized such that all the text and
- * the caret could be visible, the Macintosh does not
- * scroll the widget back. The fix is to save the
- * current selection, reset the text and then restore
- * the selection. This will cause the widget
- * to recompute the left scroll position.
- */
- Rect inset = getInset ();
- Rectangle rect = getBounds ();
- int oldWidth = rect.width - inset.left - inset.right;
- int result = super.setBounds (x, y, width, height, move, resize, events);
- if (oldWidth == 0 && width > 0) {
- Point selection = getSelection ();
- setText (getText (), false);
- setSelection (selection);
- }
- return result;
-}
-
-/**
- * Sets the text of the item in the receiver's list at the given
- * zero-relative index to the string argument.
- *
- * @param index the index for the item
- * @param string the new text for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItem (int index, String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = getItemCount ();
- if (0 > index || index >= count) error (SWT.ERROR_INVALID_RANGE);
- char [] buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (ptr == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- int result;
- if ((style & SWT.READ_ONLY) != 0) {
- result = OS.SetMenuItemTextWithCFString (menuHandle, (short)(index+1), ptr);
- /*
- * Feature in the Macintosh. Setting text that starts with "-" makes the
- * menu item a separator. The fix is to clear the separator attribute.
- */
- if (string.startsWith ("-")) {
- OS.ChangeMenuItemAttributes (menuHandle, (short)(index+1), 0, OS.kMenuItemAttrSeparator);
- }
- } else {
- result = OS.HIComboBoxInsertTextItemAtIndex (handle, index, ptr);
- OS.HIComboBoxRemoveItemAtIndex (handle, index+1);
- }
- OS.CFRelease(ptr);
- if (result != OS.noErr) error (SWT.ERROR_ITEM_NOT_ADDED);
-}
-
-/**
- * Sets the receiver's list to be the given array of items.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItems (String [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<items.length; i++) {
- if (items [i] == null) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- removeAll();
- if (items.length == 0) return;
- for (int i= 0; i < items.length; i++) {
- String string = items[i];
- char [] buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (ptr == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- int result;
- if ((style & SWT.READ_ONLY) != 0) {
- result = OS.AppendMenuItemTextWithCFString (menuHandle, ptr, 0, 0, null);
- /*
- * Feature in the Macintosh. Setting text that starts with "-" makes the
- * menu item a separator. The fix is to clear the separator attribute.
- */
- if (string.startsWith ("-")) {
- OS.ChangeMenuItemAttributes (menuHandle, (short)(i + 1), 0, OS.kMenuItemAttrSeparator);
- }
- } else {
- int [] outIndex = new int[1];
- result = OS.HIComboBoxAppendTextItem (handle, ptr, outIndex);
- }
- OS.CFRelease(ptr);
- if (result != OS.noErr) error (SWT.ERROR_ITEM_NOT_ADDED);
- }
-}
-
-/**
- * Marks the receiver's list as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setListVisible (boolean visible) {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) {
- if (visible) {
- OS.HIViewSimulateClick (handle, (short) 0, 0, null);
- } else {
- OS.CancelMenuTracking (menuHandle, true, 0);
- }
- } else {
- if (OS.VERSION >= 0x1040) {
- OS.HIComboBoxSetListVisible (handle, visible);
- }
- }
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- * <p>
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public void setOrientation (int orientation) {
- checkWidget();
-}
-
-/**
- * Sets the selection in the receiver's text field to the
- * range specified by the argument whose x coordinate is the
- * start of the selection and whose y coordinate is the end
- * of the selection.
- *
- * @param selection a point representing the new selection start and end
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (Point selection) {
- checkWidget ();
- if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.READ_ONLY) == 0) {
- int length = getCharCount ();
- int start = selection.x, end = selection.y;
- ControlEditTextSelectionRec sel = new ControlEditTextSelectionRec ();
- sel.selStart = (short) Math.min (Math.max (Math.min (start, end), 0), length);
- sel.selEnd = (short) Math.min (Math.max (Math.max (start, end), 0), length);
- if (hasFocus ()) {
- OS.SetControlData (handle, OS.kHIComboBoxEditTextPart, OS.kControlEditTextSelectionTag, 4, sel);
- } else {
- this.selection = sel;
- }
- }
-}
-
-/**
- * Sets the contents of the receiver's text field to the
- * given string.
- * <p>
- * This call is ignored when the receiver is read only and
- * the given string is not in the receiver's list.
- * </p>
- * <p>
- * Note: The text field in a <code>Combo</code> is typically
- * only capable of displaying a single line of text. Thus,
- * setting the text to a string containing line breaks or
- * other special characters will probably cause it to
- * display incorrectly.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- setText (string, true);
-}
-
-void setText (String string, boolean notify) {
- if (notify) {
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- string = verifyText (string, 0, getCharCount (), null);
- if (string == null) return;
- }
- }
- if ((style & SWT.READ_ONLY) != 0) {
- int index = indexOf (string);
- if (index != -1 && index != getSelectionIndex ()) {
- select (index);
- if (notify) sendEvent (SWT.Modify);
- }
- } else {
- char [] buffer = new char [Math.min(string.length (), textLimit)];
- string.getChars (0, buffer.length, buffer, 0);
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (ptr == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- lastText = string;
- OS.SetControlData (handle, OS.kHIComboBoxEditTextPart, OS.kControlEditTextCFStringTag, 4, new int[] {ptr});
- OS.CFRelease (ptr);
- selection = null;
- if (notify) sendEvent (SWT.Modify);
- }
-}
-
-/**
- * Sets the maximum number of characters that the receiver's
- * text field is capable of holding to be the argument.
- * <p>
- * To reset this value to the default, use <code>setTextLimit(Combo.LIMIT)</code>.
- * Specifying a limit value larger than <code>Combo.LIMIT</code> sets the
- * receiver's limit to <code>Combo.LIMIT</code>.
- * </p>
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public void setTextLimit (int limit) {
- checkWidget ();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- textLimit = limit;
-}
-
-/**
- * Sets the number of items that are visible in the drop
- * down portion of the receiver's list.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param count the new number of items to be visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setVisibleItemCount (int count) {
- checkWidget ();
- if (count < 0) return;
- if ((style & SWT.READ_ONLY) != 0) {
- //TODO
- } else {
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kHIComboBoxNumVisibleItemsTag, 4, new int[] {count});
- }
-}
-
-String verifyText (String string, int start, int end, Event keyEvent) {
- Event event = new Event ();
- event.text = string;
- event.start = start;
- event.end = end;
- if (keyEvent != null) {
- event.character = keyEvent.character;
- event.keyCode = keyEvent.keyCode;
- event.stateMask = keyEvent.stateMask;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the verify
- * event. If this happens, answer null to cancel
- * the operation.
- */
- sendEvent (SWT.Verify, event);
- if (!event.doit || isDisposed ()) return null;
- return event.text;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Composite.java
deleted file mode 100644
index 18f0e3d27f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Composite.java
+++ /dev/null
@@ -1,1082 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.OS;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are controls which are capable
- * of containing other controls.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>NO_BACKGROUND, NO_FOCUS, NO_MERGE_PAINTS, NO_REDRAW_RESIZE, NO_RADIO_GROUP, EMBEDDED, DOUBLE_BUFFERED</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: The <code>NO_BACKGROUND</code>, <code>NO_FOCUS</code>, <code>NO_MERGE_PAINTS</code>,
- * and <code>NO_REDRAW_RESIZE</code> styles are intended for use with <code>Canvas</code>.
- * They can be used with <code>Composite</code> if you are drawing your own, but their
- * behavior is undefined if they are used with subclasses of <code>Composite</code> other
- * than <code>Canvas</code>.
- * </p><p>
- * Note: The <code>CENTER</code> style, although undefined for composites, has the
- * same value as <code>EMBEDDED</code> which is used to embed widgets from other
- * widget toolkits into SWT. On some operating systems (GTK, Motif), this may cause
- * the children of this composite to be obscured.
- * </p><p>
- * This class may be subclassed by custom control implementors
- * who are building controls that are constructed from aggregates
- * of other controls.
- * </p>
- *
- * @see Canvas
- * @see <a href="http://www.eclipse.org/swt/snippets/#composite">Composite snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class Composite extends Scrollable {
- Layout layout;
- Control[] tabList;
- int scrolledVisibleRgn, siblingsVisibleRgn;
- int layoutCount, backgroundMode;
-
-Composite () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- *
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_FOCUS
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_RADIO_GROUP
- * @see SWT#EMBEDDED
- * @see SWT#DOUBLE_BUFFERED
- * @see Widget#getStyle
- */
-public Composite (Composite parent, int style) {
- super (parent, style);
-}
-
-Control [] _getChildren () {
- short [] buffer = new short [1];
- OS.CountSubControls (handle, buffer);
- int count = buffer [0];
- Control [] children = new Control [count];
- int i = 0, j = 0;
- int child = OS.HIViewGetFirstSubview (handle);
- while (i < count) {
- if (child != 0) {
- Widget widget = display.getWidget (child);
- if (widget != null && widget != this) {
- if (widget instanceof Control) {
- children [j++] = (Control) widget;
- }
- }
- }
- child = OS.HIViewGetNextView (child);
- i++;
- }
- if (j == count) return children;
- Control [] newChildren = new Control [j];
- System.arraycopy (children, 0, newChildren, 0, j);
- return newChildren;
-}
-
-Control [] _getTabList () {
- if (tabList == null) return null;
- int count = 0;
- for (int i=0; i<tabList.length; i++) {
- if (!tabList [i].isDisposed ()) count++;
- }
- if (count == tabList.length) return tabList;
- Control [] newList = new Control [count];
- int index = 0;
- for (int i=0; i<tabList.length; i++) {
- if (!tabList [i].isDisposed ()) {
- newList [index++] = tabList [i];
- }
- }
- tabList = newList;
- return tabList;
-}
-
-int callFocusEventHandler (int nextHandler, int theEvent) {
- if ((state & CANVAS) != 0) return OS.noErr;
- return super.callFocusEventHandler (nextHandler, theEvent);
-}
-
-/**
- * Clears any data that has been cached by a Layout for all widgets that
- * are in the parent hierarchy of the changed control up to and including the
- * receiver. If an ancestor does not have a layout, it is skipped.
- *
- * @param changed an array of controls that changed state and require a recalculation of size
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li>
- * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void changed (Control[] changed) {
- checkWidget ();
- if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<changed.length; i++) {
- Control control = changed [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean ancestor = false;
- Composite composite = control.parent;
- while (composite != null) {
- ancestor = composite == this;
- if (ancestor) break;
- composite = composite.parent;
- }
- if (!ancestor) error (SWT.ERROR_INVALID_PARENT);
- }
- for (int i=0; i<changed.length; i++) {
- Control child = changed [i];
- Composite composite = child.parent;
- while (child != this) {
- if (composite.layout == null || !composite.layout.flushCache (child)) {
- composite.state |= LAYOUT_CHANGED;
- }
- child = composite;
- composite = child.parent;
- }
- }
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- Point size;
- if (layout != null) {
- if ((wHint == SWT.DEFAULT) || (hHint == SWT.DEFAULT)) {
- changed |= (state & LAYOUT_CHANGED) != 0;
- size = layout.computeSize (this, wHint, hHint, changed);
- state &= ~LAYOUT_CHANGED;
- } else {
- size = new Point (wHint, hHint);
- }
- } else {
- size = minimumSize (wHint, hHint, changed);
- }
- if (size.x == 0) size.x = DEFAULT_WIDTH;
- if (size.y == 0) size.y = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) size.x = wHint;
- if (hHint != SWT.DEFAULT) size.y = hHint;
- Rectangle trim = computeTrim (0, 0, size.x, size.y);
- return new Point (trim.width, trim.height);
-}
-
-protected void checkSubclass () {
- /* Do nothing - Subclassing is allowed */
-}
-
-Control [] computeTabList () {
- Control result [] = super.computeTabList ();
- if (result.length == 0) return result;
- Control [] list = tabList != null ? _getTabList () : _getChildren ();
- for (int i=0; i<list.length; i++) {
- Control child = list [i];
- Control [] childList = child.computeTabList ();
- if (childList.length != 0) {
- Control [] newResult = new Control [result.length + childList.length];
- System.arraycopy (result, 0, newResult, 0, result.length);
- System.arraycopy (childList, 0, newResult, result.length, childList.length);
- result = newResult;
- }
- }
- return result;
-}
-
-void createHandle () {
- state |= CANVAS | GRAB;
- boolean scrolled = (style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0;
- if (!scrolled) state |= THEME_BACKGROUND;
- if (scrolled || (style & SWT.BORDER) != 0) {
- createScrolledHandle (parent.handle);
- } else {
- createHandle (parent.handle);
- }
-}
-
-void createHandle (int parentHandle) {
- int features = OS.kControlSupportsEmbedding | OS.kControlSupportsFocus;
- int [] outControl = new int [1];
- int window = OS.GetControlOwner (parentHandle);
- OS.CreateUserPaneControl (window, null, features, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
- OS.HIObjectSetAccessibilityIgnored (handle, true);
-}
-
-void createScrolledHandle (int parentHandle) {
- int features = OS.kControlSupportsEmbedding;
- int [] outControl = new int [1];
- int window = OS.GetControlOwner (parentHandle);
- OS.CreateUserPaneControl (window, null, features, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- scrolledHandle = outControl [0];
- outControl [0] = 0;
- features |= OS.kControlSupportsFocus;
- OS.CreateUserPaneControl (window, null, features, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
- OS.HIObjectSetAccessibilityIgnored (scrolledHandle, true);
- OS.HIObjectSetAccessibilityIgnored (handle, true);
-}
-
-void drawBackground (int control, int context) {
- if (control == scrolledHandle) {
- Composite parent = this;
- Shell shell = getShell ();
- if (shell != this) parent = this.parent;
- boolean drawBackground = (style & SWT.TRANSPARENT) == 0;
- if ((style & SWT.NO_FOCUS) == 0 && hooksKeys ()) {
- parent.drawFocus (control, context, hasFocus () && drawFocusRing (), hasBorder (), drawBackground, inset ());
- } else {
- if (hasBorder ()) {
- parent.drawFocus (control, context, false, hasBorder (), drawBackground, inset ());
- } else {
- parent.fillBackground (control, context, null);
- }
- }
- } else {
- if ((state & CANVAS) != 0) {
- if ((style & (SWT.NO_BACKGROUND | SWT.TRANSPARENT)) == 0) {
- fillBackground (control, context, null);
- }
- }
- }
-}
-
-void enableWidget (boolean enabled) {
- //NOT DONE - take into account current scroll bar state
- if ((state & CANVAS) != 0) {
- if (horizontalBar != null) horizontalBar.enableWidget (enabled);
- if (verticalBar != null) verticalBar.enableWidget (enabled);
- return;
- }
- super.enableWidget (enabled);
-}
-
-Composite findDeferredControl () {
- return layoutCount > 0 ? this : parent.findDeferredControl ();
-}
-
-Menu [] findMenus (Control control) {
- if (control == this) return new Menu [0];
- Menu result [] = super.findMenus (control);
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- Menu [] menuList = child.findMenus (control);
- if (menuList.length != 0) {
- Menu [] newResult = new Menu [result.length + menuList.length];
- System.arraycopy (result, 0, newResult, 0, result.length);
- System.arraycopy (menuList, 0, newResult, result.length, menuList.length);
- result = newResult;
- }
- }
- return result;
-}
-
-void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) {
- super.fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
- }
-}
-
-void fixTabList (Control control) {
- if (tabList == null) return;
- int count = 0;
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == control) count++;
- }
- if (count == 0) return;
- Control [] newList = null;
- int length = tabList.length - count;
- if (length != 0) {
- newList = new Control [length];
- int index = 0;
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] != control) {
- newList [index++] = tabList [i];
- }
- }
- }
- tabList = newList;
-}
-
-/**
- * Returns the receiver's background drawing mode. This
- * will be one of the following constants defined in class
- * <code>SWT</code>:
- * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>,
- * <code>INHERTIT_FORCE</code>.
- *
- * @return the background mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- *
- * @since 3.2
- */
-public int getBackgroundMode () {
- checkWidget ();
- return backgroundMode;
-}
-
-/**
- * Returns a (possibly empty) array containing the receiver's children.
- * Children are returned in the order that they are drawn. The topmost
- * control appears at the beginning of the array. Subsequent controls
- * draw beneath this control and appear later in the array.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of children, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return an array of children
- *
- * @see Control#moveAbove
- * @see Control#moveBelow
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control [] getChildren () {
- checkWidget();
- return _getChildren ();
-}
-
-int getChildrenCount () {
- /*
- * NOTE: The current implementation will count
- * non-registered children.
- */
- short [] count = new short [1];
- OS.CountSubControls (handle, count);
- return count [0];
-}
-
-/**
- * Returns layout which is associated with the receiver, or
- * null if one has not been set.
- *
- * @return the receiver's layout or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Layout getLayout () {
- checkWidget();
- return layout;
-}
-
-/**
- * Returns <code>true</code> if the receiver has deferred
- * the performing of layout, and <code>false</code> otherwise.
- *
- * @return the receiver's deferred layout state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setLayoutDeferred(boolean)
- * @see #isLayoutDeferred()
- *
- * @since 3.1
- */
-public boolean getLayoutDeferred () {
- checkWidget ();
- return layoutCount > 0 ;
-}
-
-/**
- * Gets the (possibly empty) tabbing order for the control.
- *
- * @return tabList the ordered list of controls representing the tab order
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setTabList
- */
-public Control [] getTabList () {
- checkWidget ();
- Control [] tabList = _getTabList ();
- if (tabList == null) {
- int count = 0;
- Control [] list =_getChildren ();
- for (int i=0; i<list.length; i++) {
- if (list [i].isTabGroup ()) count++;
- }
- tabList = new Control [count];
- int index = 0;
- for (int i=0; i<list.length; i++) {
- if (list [i].isTabGroup ()) {
- tabList [index++] = list [i];
- }
- }
- }
- return tabList;
-}
-
-int getVisibleRegion (int control, boolean clipChildren) {
- if (!clipChildren && control == handle) {
- if (siblingsVisibleRgn == 0) {
- siblingsVisibleRgn = OS.NewRgn ();
- calculateVisibleRegion (control, siblingsVisibleRgn, clipChildren);
- }
- int result = OS.NewRgn ();
- OS.CopyRgn (siblingsVisibleRgn, result);
- return result;
- }
- if (control == scrolledHandle) {
- if (!clipChildren) return super.getVisibleRegion (control, clipChildren);
- if (scrolledVisibleRgn == 0) {
- scrolledVisibleRgn = OS.NewRgn ();
- calculateVisibleRegion (control, scrolledVisibleRgn, clipChildren);
- }
- int result = OS.NewRgn ();
- OS.CopyRgn (scrolledVisibleRgn, result);
- return result;
- }
- return super.getVisibleRegion (control, clipChildren);
-}
-
-int kEventControlClick (int nextHandler, int theEvent, int userData) {
- int result = super.kEventControlClick (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- if ((state & CANVAS) != 0) {
- if (!isEnabled ()) return result;
- if ((style & SWT.NO_FOCUS) == 0 && hooksKeys ()) {
- int [] theControl = new int [1];
- int window = OS.GetControlOwner (handle);
- OS.GetKeyboardFocus (window, theControl);
- if (handle != theControl [0]) {
- short [] count = new short [1];
- OS.CountSubControls (handle, count);
- if (count [0] == 0) {
- if (OS.SetKeyboardFocus (window, handle, (short) focusPart ()) == OS.noErr) {
- return OS.noErr;
- }
- }
- }
- }
- }
- return result;
-}
-
-int kEventControlGetFocusPart (int nextHandler, int theEvent, int userData) {
- if ((state & CANVAS) != 0) return OS.noErr;
- return super.kEventControlGetFocusPart (nextHandler, theEvent, userData);
-}
-
-int kEventControlSetFocusPart (int nextHandler, int theEvent, int userData) {
- int result = super.kEventControlSetFocusPart (nextHandler, theEvent, userData);
- if (result == OS.noErr) {
- if ((state & CANVAS) != 0) {
- if (scrolledHandle != 0) {
- if ((style & SWT.NO_FOCUS) == 0 && hooksKeys ()) {
- short [] part = new short [1];
- OS.GetEventParameter (theEvent, OS.kEventParamControlPart, OS.typeControlPartCode, null, 2, null, part);
- redrawWidget (scrolledHandle, false);
- }
- }
- }
- }
- return result;
-}
-
-int kEventMouseDown (int nextHandler, int theEvent, int userData) {
- int result = super.kEventMouseDown (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_FOCUS) != 0) {
- Shell shell = getShell ();
- int bits = SWT.ON_TOP | SWT.NO_FOCUS;
- if ((shell.style & bits) == bits) return OS.noErr;
- }
- }
- return result;
-}
-
-int kEventRawKeyPressed (int nextHandler, int theEvent, int userData) {
- /*
- * For some reason the next event handler for embedded controls
- * stops the event chain and does not let the default handler
- * process the raw key event into unicode. The fix to send
- * the key from kEventRawKeyDown instead.
- *
- * Note: should the embedded control no longer stop the event
- * chain, there will be two key events issued for one key press.
- */
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) {
- int [] theControl = new int[1];
- OS.GetKeyboardFocus (OS.GetControlOwner(handle), theControl);
- if (theControl[0] != handle) {
- if (!sendKeyEvent (SWT.KeyDown, theEvent)) return OS.noErr;
- return OS.eventNotHandledErr;
- }
- }
-
- /*
- * Feature in the Macintosh. For some reason, the default handler
- * does not issue kEventTextInputUnicodeForKeyEvent when the user
- * types Command+Space. The fix is to look for this case and
- * send the key from kEventRawKeyDown instead.
- *
- * NOTE: This code relies on Command+Space being consumed and
- * will deliver two events if this ever changes.
- */
- if ((state & CANVAS) != 0) {
- int [] keyCode = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyCode, OS.typeUInt32, null, keyCode.length * 4, null, keyCode);
- if (keyCode [0] == 49 /* Space */) {
- int [] modifiers = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
- if (modifiers [0] == OS.cmdKey) {
- if (!sendKeyEvent (SWT.KeyDown, theEvent)) return OS.noErr;
- }
- }
- }
- return OS.eventNotHandledErr;
-}
-
-int kEventUnicodeKeyPressed (int nextHandler, int theEvent, int userData) {
- int result = super.kEventUnicodeKeyPressed (nextHandler, theEvent, userData);
- if ((state & CANVAS) != 0) {
- int [] keyboardEvent = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendKeyboardEvent, OS.typeEventRef, null, keyboardEvent.length * 4, null, keyboardEvent);
- int [] keyCode = new int [1];
- OS.GetEventParameter (keyboardEvent [0], OS.kEventParamKeyCode, OS.typeUInt32, null, keyCode.length * 4, null, keyCode);
- switch (keyCode [0]) {
- case 76: /* KP Enter */
- case 36: /* Return */
- /*
- * Feature in the Macintosh. The default behaviour when the return key is pressed is
- * to select the default button. This is not the expected behaviour for Composite and
- * its subclasses. The fix is to avoid calling the default handler.
- */
- return OS.noErr;
- }
- }
- return result;
-}
-
-boolean hooksKeys () {
- return hooks (SWT.KeyDown) || hooks (SWT.KeyUp);
-}
-
-void invalidateChildrenVisibleRegion (int control) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- child.resetVisibleRegion (control);
- child.invalidateChildrenVisibleRegion (control);
- }
-}
-
-/**
- * Returns <code>true</code> if the receiver or any ancestor
- * up to and including the receiver's nearest ancestor shell
- * has deferred the performing of layouts. Otherwise, <code>false</code>
- * is returned.
- *
- * @return the receiver's deferred layout state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setLayoutDeferred(boolean)
- * @see #getLayoutDeferred()
- *
- * @since 3.1
- */
-public boolean isLayoutDeferred () {
- checkWidget ();
- return findDeferredControl () != null;
-}
-
-boolean isTabGroup () {
- if ((state & CANVAS) != 0) return true;
- return super.isTabGroup ();
-}
-
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the receiver does not have a layout, do nothing.
- * <p>
- * This is equivalent to calling <code>layout(true)</code>.
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void layout () {
- checkWidget ();
- layout (true);
-}
-
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the argument is <code>true</code> the layout must not rely
- * on any information it has cached about the immediate children. If it
- * is <code>false</code> the layout may (potentially) optimize the
- * work it is doing by assuming that none of the receiver's
- * children has changed state since the last layout.
- * If the receiver does not have a layout, do nothing.
- * <p>
- * If a child is resized as a result of a call to layout, the
- * resize event will invoke the layout of the child. The layout
- * will cascade down through all child widgets in the receiver's widget
- * tree until a child is encountered that does not resize. Note that
- * a layout due to a resize will not flush any cached information
- * (same as <code>layout(false)</code>).
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void layout (boolean changed) {
- checkWidget ();
- if (layout == null) return;
- layout (changed, false);
-}
-
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the changed argument is <code>true</code> the layout must not rely
- * on any information it has cached about its children. If it
- * is <code>false</code> the layout may (potentially) optimize the
- * work it is doing by assuming that none of the receiver's
- * children has changed state since the last layout.
- * If the all argument is <code>true</code> the layout will cascade down
- * through all child widgets in the receiver's widget tree, regardless of
- * whether the child has changed size. The changed argument is applied to
- * all layouts. If the all argument is <code>false</code>, the layout will
- * <em>not</em> cascade down through all child widgets in the receiver's widget
- * tree. However, if a child is resized as a result of a call to layout, the
- * resize event will invoke the layout of the child. Note that
- * a layout due to a resize will not flush any cached information
- * (same as <code>layout(false)</code>).
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise
- * @param all <code>true</code> if all children in the receiver's widget tree should be laid out, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void layout (boolean changed, boolean all) {
- checkWidget ();
- if (layout == null && !all) return;
- markLayout (changed, all);
- updateLayout (all);
-}
-
-/**
- * Forces a lay out (that is, sets the size and location) of all widgets that
- * are in the parent hierarchy of the changed control up to and including the
- * receiver. The layouts in the hierarchy must not rely on any information
- * cached about the changed control or any of its ancestors. The layout may
- * (potentially) optimize the work it is doing by assuming that none of the
- * peers of the changed control have changed state since the last layout.
- * If an ancestor does not have a layout, skip it.
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed a control that has had a state change which requires a recalculation of its size
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li>
- * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void layout (Control [] changed) {
- checkWidget ();
- if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<changed.length; i++) {
- Control control = changed [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean ancestor = false;
- Composite composite = control.parent;
- while (composite != null) {
- ancestor = composite == this;
- if (ancestor) break;
- composite = composite.parent;
- }
- if (!ancestor) error (SWT.ERROR_INVALID_PARENT);
- }
- int updateCount = 0;
- Composite [] update = new Composite [16];
- for (int i=0; i<changed.length; i++) {
- Control child = changed [i];
- Composite composite = child.parent;
- while (child != this) {
- if (composite.layout != null) {
- composite.state |= LAYOUT_NEEDED;
- if (!composite.layout.flushCache (child)) {
- composite.state |= LAYOUT_CHANGED;
- }
- }
- if (updateCount == update.length) {
- Composite [] newUpdate = new Composite [update.length + 16];
- System.arraycopy (update, 0, newUpdate, 0, update.length);
- update = newUpdate;
- }
- child = update [updateCount++] = composite;
- composite = child.parent;
- }
- }
- for (int i=updateCount-1; i>=0; i--) {
- update [i].updateLayout (false);
- }
-}
-
-void markLayout (boolean changed, boolean all) {
- if (layout != null) {
- state |= LAYOUT_NEEDED;
- if (changed) state |= LAYOUT_CHANGED;
- }
- if (all) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].markLayout (changed, all);
- }
- }
-}
-
-Point minimumSize (int wHint, int Hint, boolean changed) {
- Control [] children = _getChildren ();
- int width = 0, height = 0;
- for (int i=0; i<children.length; i++) {
- Rectangle rect = children [i].getBounds ();
- width = Math.max (width, rect.x + rect.width);
- height = Math.max (height, rect.y + rect.height);
- }
- return new Point (width, height);
-}
-
-void releaseChildren (boolean destroy) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child != null && !child.isDisposed ()) {
- child.release (false);
- }
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (scrolledVisibleRgn != 0) OS.DisposeRgn (scrolledVisibleRgn);
- if (siblingsVisibleRgn != 0) OS.DisposeRgn (siblingsVisibleRgn);
- siblingsVisibleRgn = scrolledVisibleRgn = 0;
- layout = null;
- tabList = null;
-}
-
-void removeControl (Control control) {
- fixTabList (control);
-}
-
-void resetVisibleRegion (int control) {
- if (scrolledVisibleRgn != 0) {
- OS.DisposeRgn (scrolledVisibleRgn);
- scrolledVisibleRgn = 0;
- }
- if (siblingsVisibleRgn != 0) {
- OS.DisposeRgn (siblingsVisibleRgn);
- siblingsVisibleRgn = 0;
- }
- super.resetVisibleRegion (control);
-}
-
-/**
- * Sets the background drawing mode to the argument which should
- * be one of the following constants defined in class <code>SWT</code>:
- * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>,
- * <code>INHERIT_FORCE</code>.
- *
- * @param mode the new background mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- *
- * @since 3.2
- */
-public void setBackgroundMode (int mode) {
- checkWidget ();
- backgroundMode = mode;
- Control [] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- children [i].updateBackgroundMode ();
- }
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- int result = super.setBounds (x, y, width, height, move, resize, events);
- if (layout != null && (result & RESIZED) != 0) {
- markLayout (false, false);
- updateLayout (false);
- }
- return result;
-}
-
-public boolean setFocus () {
- checkWidget ();
- Control [] children = _getChildren ();
- for (int i= 0; i < children.length; i++) {
- if (children [i].setFocus ()) return true;
- }
- return super.setFocus ();
-}
-
-/**
- * Sets the layout which is associated with the receiver to be
- * the argument which may be null.
- *
- * @param layout the receiver's new layout or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLayout (Layout layout) {
- checkWidget();
- this.layout = layout;
-}
-
-/**
- * If the argument is <code>true</code>, causes subsequent layout
- * operations in the receiver or any of its children to be ignored.
- * No layout of any kind can occur in the receiver or any of its
- * children until the flag is set to false.
- * Layout operations that occurred while the flag was
- * <code>true</code> are remembered and when the flag is set to
- * <code>false</code>, the layout operations are performed in an
- * optimized manner. Nested calls to this method are stacked.
- *
- * @param defer the new defer state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #layout(boolean)
- * @see #layout(Control[])
- *
- * @since 3.1
- */
-public void setLayoutDeferred (boolean defer) {
- if (!defer) {
- if (--layoutCount == 0) {
- if ((state & LAYOUT_CHILD) != 0 || (state & LAYOUT_NEEDED) != 0) {
- updateLayout (true);
- }
- }
- } else {
- layoutCount++;
- }
-}
-
-boolean setScrollBarVisible (ScrollBar bar, boolean visible) {
- boolean changed = super.setScrollBarVisible (bar, visible);
- if (changed && layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
- return changed;
-}
-
-boolean setTabGroupFocus () {
- if (isTabItem ()) return setTabItemFocus ();
- boolean takeFocus = (style & SWT.NO_FOCUS) == 0;
- if ((state & CANVAS) != 0) takeFocus = hooksKeys ();
- if (takeFocus && setTabItemFocus ()) return true;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.isTabItem () && child.setTabItemFocus ()) return true;
- }
- return false;
-}
-
-/**
- * Sets the tabbing order for the specified controls to
- * match the order that they occur in the argument list.
- *
- * @param tabList the ordered list of controls representing the tab order or null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if a widget in the tabList is null or has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if widget in the tabList is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTabList (Control [] tabList) {
- checkWidget ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- Control control = tabList [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
- Control [] newList = new Control [tabList.length];
- System.arraycopy (tabList, 0, newList, 0, tabList.length);
- tabList = newList;
- }
- this.tabList = tabList;
-}
-
-int traversalCode (int key, int theEvent) {
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_FOCUS) != 0) return 0;
- if (hooksKeys ()) return 0;
- }
- return super.traversalCode (key, theEvent);
-}
-
-void updateBackgroundMode () {
- super.updateBackgroundMode ();
- Control [] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- children [i].updateBackgroundMode ();
- }
-}
-
-void updateLayout (boolean all) {
- Composite parent = findDeferredControl ();
- if (parent != null) {
- parent.state |= LAYOUT_CHILD;
- return;
- }
- if ((state & LAYOUT_NEEDED) != 0) {
- boolean changed = (state & LAYOUT_CHANGED) != 0;
- state &= ~(LAYOUT_NEEDED | LAYOUT_CHANGED);
- layout.layout (this, changed);
- }
- if (all) {
- state &= ~LAYOUT_CHILD;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].updateLayout (all);
- }
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Control.java
deleted file mode 100644
index edf366edfd..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Control.java
+++ /dev/null
@@ -1,4366 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.ATSFontMetrics;
-import org.eclipse.swt.internal.carbon.CFRange;
-import org.eclipse.swt.internal.carbon.HIThemeTextInfo;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.CGRect;
-import org.eclipse.swt.internal.carbon.CGPoint;
-import org.eclipse.swt.internal.carbon.ControlFontStyleRec;
-import org.eclipse.swt.internal.carbon.HMHelpContentRec;
-import org.eclipse.swt.internal.carbon.HIThemeFrameDrawInfo;
-import org.eclipse.swt.internal.carbon.Rect;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.accessibility.Accessible;
-
-/**
- * Control is the abstract superclass of all windowed user interface classes.
- * <p>
- * <dl>
- * <dt><b>Styles:</b>
- * <dd>BORDER</dd>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * <dt><b>Events:</b>
- * <dd>DragDetect, FocusIn, FocusOut, Help, KeyDown, KeyUp, MenuDetect, MouseDoubleClick, MouseDown, MouseEnter,
- * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize, Traverse</dd>
- * </dl>
- * </p><p>
- * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#control">Control snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public abstract class Control extends Widget implements Drawable {
- /**
- * the handle to the OS resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
- Composite parent;
- String toolTipText;
- Object layoutData;
- int drawCount, visibleRgn;
- Menu menu;
- float [] foreground, background;
- Image backgroundImage;
- Font font;
- Cursor cursor;
- Region region;
- GCData gcs[];
- Accessible accessible;
-
- static final String RESET_VISIBLE_REGION = "org.eclipse.swt.internal.resetVisibleRegion"; //$NON-NLS-1$
-
-
-Control () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#LEFT_TO_RIGHT
- * @see SWT#RIGHT_TO_LEFT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Control (Composite parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget ();
-}
-
-int actionProc (int theControl, int partCode) {
- int result = super.actionProc (theControl, partCode);
- if (result == OS.noErr) return result;
- if (isDisposed ()) return OS.noErr;
- sendTrackEvents ();
- return result;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize,typedListener);
- addListener (SWT.Move,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when a drag gesture occurs, by sending it
- * one of the messages defined in the <code>DragDetectListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #removeDragDetectListener
- *
- * @since 3.3
- */
-public void addDragDetectListener (DragDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.DragDetect,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control gains or loses focus, by sending
- * it one of the messages defined in the <code>FocusListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see FocusListener
- * @see #removeFocusListener
- */
-public void addFocusListener(FocusListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.FocusIn,typedListener);
- addListener(SWT.FocusOut,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when help events are generated for the control,
- * by sending it one of the messages defined in the
- * <code>HelpListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard, by sending
- * it one of the messages defined in the <code>KeyListener</code>
- * interface.
- * <p>
- * When a key listener is added to a control, the control
- * will take part in widget traversal. By default, all
- * traversal keys (such as the tab key and so on) are
- * delivered to the control. In order for a control to take
- * part in traversal, it should listen for traversal events.
- * Otherwise, the user can traverse into a control but not
- * out. Note that native controls such as table and tree
- * implement key traversal in the operating system. It is
- * not necessary to add traversal listeners for these controls,
- * unless you want to override the default traversal.
- * </p>
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #removeKeyListener
- */
-public void addKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.KeyUp,typedListener);
- addListener(SWT.KeyDown,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the platform-specific context menu trigger
- * has occurred, by sending it one of the messages defined in
- * the <code>MenuDetectListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #removeMenuDetectListener
- *
- * @since 3.3
- */
-public void addMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MenuDetect, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when mouse buttons are pressed and released, by sending
- * it one of the messages defined in the <code>MouseListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseListener
- * @see #removeMouseListener
- */
-public void addMouseListener(MouseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.MouseDown,typedListener);
- addListener(SWT.MouseUp,typedListener);
- addListener(SWT.MouseDoubleClick,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse passes or hovers over controls, by sending
- * it one of the messages defined in the <code>MouseTrackListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseTrackListener
- * @see #removeMouseTrackListener
- */
-public void addMouseTrackListener (MouseTrackListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseEnter,typedListener);
- addListener (SWT.MouseExit,typedListener);
- addListener (SWT.MouseHover,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse moves, by sending it one of the
- * messages defined in the <code>MouseMoveListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseMoveListener
- * @see #removeMouseMoveListener
- */
-public void addMouseMoveListener(MouseMoveListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.MouseMove,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse wheel is scrolled, by sending
- * it one of the messages defined in the
- * <code>MouseWheelListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseWheelListener
- * @see #removeMouseWheelListener
- *
- * @since 3.3
- */
-public void addMouseWheelListener (MouseWheelListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseWheel, typedListener);
-}
-
-void addRelation (Control control) {
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver needs to be painted, by sending it
- * one of the messages defined in the <code>PaintListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see PaintListener
- * @see #removePaintListener
- */
-public void addPaintListener(PaintListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.Paint,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when traversal events occur, by sending it
- * one of the messages defined in the <code>TraverseListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TraverseListener
- * @see #removeTraverseListener
- */
-public void addTraverseListener (TraverseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Traverse,typedListener);
-}
-
-int colorProc (int inControl, int inMessage, int inDrawDepth, int inDrawInColor) {
- switch (inMessage) {
- case OS.kControlMsgApplyTextColor: {
- if (foreground != null) {
- OS.RGBForeColor (toRGBColor (foreground));
- } else {
- OS.SetThemeTextColor ((short) OS.kThemeTextColorDialogActive, (short) inDrawDepth, inDrawInColor != 0);
- }
- return OS.noErr;
- }
- case OS.kControlMsgSetUpBackground: {
- float [] background = this.background != null ? this.background : getParentBackground ();
- if (background != null) {
- OS.RGBBackColor (toRGBColor (background));
- } else {
- OS.SetThemeBackground ((short) OS.kThemeBrushDialogBackgroundActive, (short) inDrawDepth, inDrawInColor != 0);
- }
- return OS.noErr;
- }
- }
- return OS.eventNotHandledErr;
-}
-
-int callFocusEventHandler (int nextHandler, int theEvent) {
- return OS.CallNextEventHandler (nextHandler, theEvent);
-}
-
-void checkBackground () {
- Shell shell = getShell ();
- if (this == shell) return;
- state &= ~PARENT_BACKGROUND;
- Composite composite = parent;
- do {
- int mode = composite.backgroundMode;
- if (mode != 0) {
- if (mode == SWT.INHERIT_DEFAULT) {
- Control control = this;
- do {
- if ((control.state & THEME_BACKGROUND) == 0) {
- return;
- }
- control = control.parent;
- } while (control != composite);
- }
- state |= PARENT_BACKGROUND;
- return;
- }
- if (composite == shell) break;
- composite = composite.parent;
- } while (true);
-}
-
-void checkBuffered () {
- style |= SWT.DOUBLE_BUFFERED;
-}
-
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>preferred size</em> of a control is the size that it would
- * best be displayed at. The width hint and height hint arguments
- * allow the caller to ask a control questions such as "Given a particular
- * width, how high does the control need to be to show all of the contents?"
- * To indicate that the caller does not wish to constrain a particular
- * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
- * </p>
- *
- * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
- * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
- * @return the preferred size of the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Layout
- * @see #getBorderWidth
- * @see #getBounds
- * @see #getSize
- * @see #pack(boolean)
- * @see "computeTrim, getClientArea for controls that implement them"
- */
-public Point computeSize (int wHint, int hHint) {
- return computeSize (wHint, hHint, true);
-}
-
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>preferred size</em> of a control is the size that it would
- * best be displayed at. The width hint and height hint arguments
- * allow the caller to ask a control questions such as "Given a particular
- * width, how high does the control need to be to show all of the contents?"
- * To indicate that the caller does not wish to constrain a particular
- * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
- * </p><p>
- * If the changed flag is <code>true</code>, it indicates that the receiver's
- * <em>contents</em> have changed, therefore any caches that a layout manager
- * containing the control may have been keeping need to be flushed. When the
- * control is resized, the changed flag will be <code>false</code>, so layout
- * manager caches can be retained.
- * </p>
- *
- * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
- * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
- * @param changed <code>true</code> if the control's contents have changed, and <code>false</code> otherwise
- * @return the preferred size of the control.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Layout
- * @see #getBorderWidth
- * @see #getBounds
- * @see #getSize
- * @see #pack(boolean)
- * @see "computeTrim, getClientArea for controls that implement them"
- */
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = DEFAULT_WIDTH;
- int height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2;
- height += border * 2;
- return new Point (width, height);
-}
-
-Control computeTabGroup () {
- if (isTabGroup()) return this;
- return parent.computeTabGroup ();
-}
-
-Control[] computeTabList() {
- if (isTabGroup()) {
- if (getVisible() && getEnabled()) {
- return new Control[] {this};
- }
- }
- return new Control[0];
-}
-
-Control computeTabRoot () {
- Control[] tabList = parent._getTabList();
- if (tabList != null) {
- int index = 0;
- while (index < tabList.length) {
- if (tabList [index] == this) break;
- index++;
- }
- if (index == tabList.length) {
- if (isTabGroup ()) return this;
- }
- }
- return parent.computeTabRoot ();
-}
-
-boolean contains (String [] array, String element) {
- for (int i = 0; i < array.length; i++) {
- if (array [i].equals (element)) {
- return true;
- }
- }
- return false;
-}
-
-void createWidget () {
- state |= DRAG_DETECT;
- checkOrientation (parent);
- super.createWidget ();
- checkBackground ();
- checkBuffered ();
- setDefaultFont ();
- setZOrder ();
- setRelations ();
-}
-
-Color defaultBackground () {
- return display.getSystemColor (SWT.COLOR_WIDGET_BACKGROUND);
-}
-
-Font defaultFont () {
- byte [] family = new byte [256];
- short [] size = new short [1];
- byte [] style = new byte [1];
- OS.GetThemeFont ((short) defaultThemeFont (), (short) OS.smSystemScript, family, size, style);
- short id = OS.FMGetFontFamilyFromName (family);
- int [] font = new int [1];
- OS.FMGetFontFromFontFamilyInstance (id, style [0], font, null);
- return Font.carbon_new (display, OS.FMGetATSFontRefFromFont (font [0]), style [0], size [0]);
-}
-
-Color defaultForeground () {
- return display.getSystemColor (SWT.COLOR_WIDGET_FOREGROUND);
-}
-
-int defaultThemeFont () {
- if (display.smallFonts) return OS.kThemeSmallSystemFont;
- return OS.kThemeSystemFont;
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (handle);
-}
-
-void destroyWidget () {
- Display display = this.display;
- int theControl = topHandle ();
- releaseHandle ();
- if (theControl != 0) {
- if (display.delayDispose) {
- display.addToDisposeWindow (theControl);
- } else {
- OS.DisposeControl (theControl);
- }
- }
-}
-
-/**
- * Detects a drag and drop gesture. This method is used
- * to detect a drag gesture when called from within a mouse
- * down listener.
- *
- * <p>By default, a drag is detected when the gesture
- * occurs anywhere within the client area of a control.
- * Some controls, such as tables and trees, override this
- * behavior. In addition to the operating system specific
- * drag gesture, they require the mouse to be inside an
- * item. Custom widget writers can use <code>setDragDetect</code>
- * to disable the default detection, listen for mouse down,
- * and then call <code>dragDetect()</code> from within the
- * listener to conditionally detect a drag.
- * </p>
- *
- * @param event the mouse down event
- *
- * @return <code>true</code> if the gesture occurred, and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT when the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @see #getDragDetect
- * @see #setDragDetect
- *
- * @since 3.3
- */
-public boolean dragDetect (Event event) {
- checkWidget ();
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- return dragDetect (event.button, event.count, event.stateMask, event.x, event.y);
-}
-
-/**
- * Detects a drag and drop gesture. This method is used
- * to detect a drag gesture when called from within a mouse
- * down listener.
- *
- * <p>By default, a drag is detected when the gesture
- * occurs anywhere within the client area of a control.
- * Some controls, such as tables and trees, override this
- * behavior. In addition to the operating system specific
- * drag gesture, they require the mouse to be inside an
- * item. Custom widget writers can use <code>setDragDetect</code>
- * to disable the default detection, listen for mouse down,
- * and then call <code>dragDetect()</code> from within the
- * listener to conditionally detect a drag.
- * </p>
- *
- * @param event the mouse down event
- *
- * @return <code>true</code> if the gesture occurred, and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT when the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @see #getDragDetect
- * @see #setDragDetect
- *
- * @since 3.3
- */
-public boolean dragDetect (MouseEvent event) {
- checkWidget ();
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- return dragDetect (event.button, event.count, event.stateMask, event.x, event.y);
-}
-
-boolean dragDetect (int button, int count, int stateMask, int x, int y) {
- if (button != 1 || count != 1) return false;
- if (!dragDetect (x, y, false, null)) return false;
- return sendDragEvent (button, stateMask, x, y);
-}
-
-boolean dragDetect (int x, int y, boolean filter, boolean [] consume) {
- Rect rect = new Rect ();
- int window = OS.GetControlOwner (handle);
- CGPoint pt = new CGPoint ();
- OS.HIViewConvertPoint (pt, handle, 0);
- x += (int) pt.x;
- y += (int) pt.y;
- OS.GetWindowBounds (window, (short) OS.kWindowStructureRgn, rect);
- x += rect.left;
- y += rect.top;
- org.eclipse.swt.internal.carbon.Point pt1 = new org.eclipse.swt.internal.carbon.Point ();
- pt1.h = (short) x;
- pt1.v = (short) y;
- return OS.WaitMouseMoved (pt1);
-}
-
-void drawFocus (int control, int context, boolean hasFocus, boolean hasBorder, boolean drawBackground, Rect inset) {
- if (drawBackground) fillBackground (control, context, null);
- CGRect rect = new CGRect ();
- OS.HIViewGetBounds (control, rect);
- rect.x += inset.left;
- rect.y += inset.top;
- rect.width -= inset.right + inset.left;
- rect.height -= inset.bottom + inset.top;
- int state;
- if (OS.IsControlEnabled (control)) {
- state = OS.IsControlActive (control) ? OS.kThemeStateActive : OS.kThemeStateInactive;
- } else {
- state = OS.IsControlActive (control) ? OS.kThemeStateUnavailable : OS.kThemeStateUnavailableInactive;
- }
- if (hasBorder) {
- HIThemeFrameDrawInfo info = new HIThemeFrameDrawInfo ();
- info.state = state;
- info.kind = OS.kHIThemeFrameTextFieldSquare;
- info.isFocused = hasFocus;
- OS.HIThemeDrawFrame (rect, info, context, OS.kHIThemeOrientationNormal);
- } else {
- OS.HIThemeDrawFocusRect (rect, hasFocus, context, OS.kHIThemeOrientationNormal);
- }
-}
-
-boolean drawFocusRing () {
- return hasBorder ();
-}
-
-boolean drawGripper (int x, int y, int width, int height, boolean vertical) {
- return false;
-}
-
-void drawWidget (int control, int context, int damageRgn, int visibleRgn, int theEvent) {
- if (control != handle) return;
- if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return;
-
- /* Retrieve the damage rect */
- Rect rect = new Rect ();
- OS.GetRegionBounds (visibleRgn, rect);
-
- /* Send paint event */
- int [] port = new int [1];
- OS.GetPort (port);
- GCData data = new GCData ();
- data.port = port [0];
- data.paintEvent = theEvent;
- data.visibleRgn = visibleRgn;
- GC gc = GC.carbon_new (this, data);
- Event event = new Event ();
- event.gc = gc;
- event.x = rect.left;
- event.y = rect.top;
- event.width = rect.right - rect.left;
- event.height = rect.bottom - rect.top;
- sendEvent (SWT.Paint, event);
- event.gc = null;
- gc.dispose ();
-}
-
-void enableWidget (boolean enabled) {
- int topHandle = topHandle ();
- if (enabled) {
- OS.EnableControl (topHandle);
- } else {
- OS.DisableControl (topHandle);
- }
-}
-
-boolean equals(float[] color1, float[] color2) {
- if (color1 == color2) return true;
- if (color1 == null) return color2 == null;
- if (color2 == null) return color1 == null;
- for (int i = 0; i < color1.length; i++) {
- if (color1 [i] != color2 [i]) return false;
- }
- return true;
-}
-
-void fillBackground (int control, int context, Rectangle bounds) {
- OS.CGContextSaveGState (context);
- CGRect rect = new CGRect ();
- if (bounds != null) {
- rect.x = bounds.x;
- rect.y = bounds.y;
- rect.width = bounds.width;
- rect.height = bounds.height;
- } else {
- OS.HIViewGetBounds (control, rect);
- }
- Control widget = findBackgroundControl ();
- if (widget != null && widget.backgroundImage != null) {
- CGPoint pt = new CGPoint();
- OS.HIViewConvertPoint (pt, control, widget.handle);
- OS.CGContextTranslateCTM (context, -pt.x, -pt.y);
- Pattern pattern = new Pattern (display, widget.backgroundImage);
- GCData data = new GCData ();
- data.device = display;
- data.background = widget.getBackgroundColor ().handle;
- GC gc = GC.carbon_new (context, data);
- gc.setBackgroundPattern (pattern);
- gc.fillRectangle ((int) (rect.x + pt.x), (int) (rect.y + pt.y), (int) rect.width, (int) rect.height);
- gc.dispose ();
- pattern.dispose();
- } else if (widget != null && widget.background != null) {
- int colorspace = OS.CGColorSpaceCreateDeviceRGB ();
- OS.CGContextSetFillColorSpace (context, colorspace);
- OS.CGContextSetFillColor (context, widget.background);
- OS.CGColorSpaceRelease (colorspace);
- OS.CGContextSetAlpha (context, getThemeAlpha ());
- OS.CGContextFillRect (context, rect);
- } else {
- if (OS.VERSION >= 0x1040) {
- OS.HIThemeSetFill (OS.kThemeBrushDialogBackgroundActive, 0, context, OS.kHIThemeOrientationNormal);
- OS.CGContextSetAlpha (context, getThemeAlpha ());
- OS.CGContextFillRect (context, rect);
- } else {
- Rect rect1 = new Rect ();
- rect1.left = (short) rect.x;
- rect1.top = (short) rect.y;
- rect1.right = (short) (rect.x + rect.width);
- rect1.bottom = (short) (rect.y + rect.height);
- OS.SetThemeBackground ((short) OS.kThemeBrushDialogBackgroundActive, (short) 0, true);
- OS.EraseRect (rect1);
- }
- }
- OS.CGContextRestoreGState (context);
-}
-
-Cursor findCursor () {
- if (cursor != null) return cursor;
- return parent.findCursor ();
-}
-
-Control findBackgroundControl () {
- if (backgroundImage != null || background != null) return this;
- return (state & PARENT_BACKGROUND) != 0 ? parent.findBackgroundControl () : null;
-}
-
-Menu [] findMenus (Control control) {
- if (menu != null && this != control) return new Menu [] {menu};
- return new Menu [0];
-}
-
-void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) {
- oldShell.fixShell (newShell, this);
- oldDecorations.fixDecorations (newDecorations, this, menus);
-}
-
-void fixFocus (Control focusControl) {
- Shell shell = getShell ();
- Control control = this;
- while (control != shell && (control = control.parent) != null) {
- if (control.setFocus ()) return;
- }
- shell.setSavedFocus (focusControl);
- int window = OS.GetControlOwner (handle);
- OS.ClearKeyboardFocus (window);
-}
-
-int focusHandle () {
- return handle;
-}
-
-int focusPart () {
- return OS.kControlFocusNextPart;
-}
-
-/**
- * Forces the receiver to have the <em>keyboard focus</em>, causing
- * all keyboard events to be delivered to it.
- *
- * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setFocus
- */
-public boolean forceFocus () {
- checkWidget();
- if (display.focusEvent == SWT.FocusOut) return false;
- Decorations shell = menuShell ();
- shell.setSavedFocus (this);
- if (!isEnabled () || !isVisible ()/* || !isActive ()*/) return false;
- if (isFocusControl ()) return true;
- shell.setSavedFocus (null);
- shell.bringToTop (false);
- if (isDisposed ()) return false;
- /*
- * Feature in the Macintosh. SetKeyboardFocus() sends kEventControlSetFocusPart
- * with the part code equal to kControlFocusNoPart to the control that is about
- * to lose focus and then sends kEventControlSetFocusPart with part code equal
- * to kControlFocusNextPart to this control (the one that is about to get focus).
- * If the control does not accept focus because of the full keyboard access mode,
- * kEventControlSetFocusPart is sent again to the control in focus causing multiple
- * focus events to happen. The fix is to ignore focus events and issue them only
- * if the focus control changed.
- */
- int focusHandle = focusHandle ();
- int window = OS.GetControlOwner (focusHandle);
- Control oldFocus = display.getFocusControl (window, true);
- if (oldFocus == this) return true;
- display.ignoreFocus = true;
- OS.SetKeyboardFocus (window, focusHandle, (short) focusPart ());
- display.ignoreFocus = false;
- Control newFocus = display.getFocusControl ();
- if (oldFocus != newFocus) {
- if (oldFocus != null && !oldFocus.isDisposed ()) oldFocus.sendFocusEvent (SWT.FocusOut, false);
- if (newFocus != null && !newFocus.isDisposed () && newFocus.isEnabled ()) newFocus.sendFocusEvent (SWT.FocusIn, false);
- }
- if (isDisposed ()) return false;
- shell.setSavedFocus (this);
- return hasFocus ();
-}
-
-/**
- * Returns the accessible object for the receiver.
- * If this is the first time this object is requested,
- * then the object is created and returned.
- *
- * @return the accessible object
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Accessible#addAccessibleListener
- * @see Accessible#addAccessibleControlListener
- *
- * @since 2.0
- */
-public Accessible getAccessible () {
- checkWidget ();
- if (accessible == null) accessible = new_Accessible (this);
- return accessible;
-}
-
-String [] getAxAttributes () {
- return null;
-}
-
-/**
- * Returns the receiver's background color.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on some versions of Windows the background of a TabFolder,
- * is a gradient rather than a solid color.
- * </p>
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Color getBackground () {
- checkWidget();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- return control.getBackgroundColor ();
-}
-
-Color getBackgroundColor () {
- return background != null ? Color.carbon_new (display, background) : defaultBackground ();
-}
-
-/**
- * Returns the receiver's background image.
- *
- * @return the background image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Image getBackgroundImage () {
- checkWidget();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- return control.backgroundImage;
-}
-
-/**
- * Returns the receiver's border width.
- *
- * @return the border width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getBorderWidth () {
- checkWidget();
- return 0;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null),
- * unless the receiver is a shell. In this case, the location is
- * relative to the display.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- return getControlBounds (topHandle ());
-}
-
-/**
- * Returns <code>true</code> if the receiver is detecting
- * drag gestures, and <code>false</code> otherwise.
- *
- * @return the receiver's drag detect state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public boolean getDragDetect () {
- checkWidget ();
- return (state & DRAG_DETECT) != 0;
-}
-
-boolean getDrawing () {
- return drawCount <= 0;
-}
-
-/**
- * Returns the receiver's cursor, or null if it has not been set.
- * <p>
- * When the mouse pointer passes over a control its appearance
- * is changed to match the control's cursor.
- * </p>
- *
- * @return the receiver's cursor or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Cursor getCursor () {
- checkWidget();
- return cursor;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- return (state & DISABLED) == 0;
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Font getFont () {
- checkWidget();
- return font != null ? font : defaultFont ();
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Color getForeground () {
- checkWidget();
- return getForegroundColor ();
-}
-
-Color getForegroundColor () {
- return foreground != null ? Color.carbon_new (display, foreground) : defaultForeground ();
-}
-
-/**
- * Returns layout data which is associated with the receiver.
- *
- * @return the receiver's layout data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Object getLayoutData () {
- checkWidget();
- return layoutData;
-}
-
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @return the receiver's location
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getLocation () {
- checkWidget();
- Rectangle rect = getControlBounds (topHandle ());
- return new Point (rect.x, rect.y);
-}
-
-/**
- * Returns the receiver's pop up menu if it has one, or null
- * if it does not. All controls may optionally have a pop up
- * menu that is displayed when the user requests one for
- * the control. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pop up
- * menu is platform specific.
- *
- * @return the receiver's menu
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenu () {
- checkWidget();
- return menu;
-}
-
-int getMininumHeight () {
- return 0;
-}
-
-/**
- * Returns the receiver's monitor.
- *
- * @return the receiver's monitor
- *
- * @since 3.0
- */
-public Monitor getMonitor () {
- checkWidget();
- Monitor [] monitors = display.getMonitors ();
- if (monitors.length == 1) return monitors [0];
- int index = -1, value = -1;
- Rectangle bounds = getBounds ();
- if (this != getShell ()) {
- bounds = display.map (this.parent, null, bounds);
- }
- for (int i=0; i<monitors.length; i++) {
- Rectangle rect = bounds.intersection (monitors [i].getBounds ());
- int area = rect.width * rect.height;
- if (area > 0 && area > value) {
- index = i;
- value = area;
- }
- }
- if (index >= 0) return monitors [index];
- int centerX = bounds.x + bounds.width / 2, centerY = bounds.y + bounds.height / 2;
- for (int i=0; i<monitors.length; i++) {
- Rectangle rect = monitors [i].getBounds ();
- int x = centerX < rect.x ? rect.x - centerX : centerX > rect.x + rect.width ? centerX - rect.x - rect.width : 0;
- int y = centerY < rect.y ? rect.y - centerY : centerY > rect.y + rect.height ? centerY - rect.y - rect.height : 0;
- int distance = x * x + y * y;
- if (index == -1 || distance < value) {
- index = i;
- value = distance;
- }
- }
- return monitors [index];
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Composite</code>
- * or null when the receiver is a shell that was created with null or
- * a display for a parent.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Composite getParent () {
- checkWidget();
- return parent;
-}
-
-float [] getParentBackground () {
- return parent.background;
-}
-
-Control [] getPath () {
- int count = 0;
- Shell shell = getShell ();
- Control control = this;
- while (control != shell) {
- count++;
- control = control.parent;
- }
- control = this;
- Control [] result = new Control [count];
- while (control != shell) {
- result [--count] = control;
- control = control.parent;
- }
- return result;
-}
-
-/**
- * Returns the region that defines the shape of the control,
- * or null if the control has the default shape.
- *
- * @return the region that defines the shape of the shell (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public Region getRegion () {
- checkWidget ();
- return region;
-}
-
-/**
- * Returns the receiver's shell. For all controls other than
- * shells, this simply returns the control's nearest ancestor
- * shell. Shells return themselves, even if they are children
- * of other shells.
- *
- * @return the receiver's shell
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getParent
- */
-public Shell getShell () {
- checkWidget();
- return parent.getShell ();
-}
-
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- return getControlSize (topHandle ());
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-
-float getThemeAlpha () {
- return 1 * parent.getThemeAlpha ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- return (state & HIDDEN) == 0;
-}
-
-int getVisibleRegion (int control, boolean clipChildren) {
- if (!clipChildren) return super.getVisibleRegion (control, clipChildren);
- if (visibleRgn == 0) {
- visibleRgn = OS.NewRgn ();
- calculateVisibleRegion (control, visibleRgn, clipChildren);
- }
- int result = OS.NewRgn ();
- OS.CopyRgn (visibleRgn, result);
- return result;
-}
-
-boolean hasBorder () {
- return (style & SWT.BORDER) != 0;
-}
-
-boolean hasFocus () {
- return this == display.getFocusControl ();
-}
-
-int helpProc (int inControl, int inGlobalMouse, int inRequest, int outContentProvided, int ioHelpContent) {
- switch (inRequest) {
- case OS.kHMSupplyContent: {
- short [] contentProvided = {OS.kHMContentNotProvidedDontPropagate};
- if (toolTipText != null && toolTipText.length () != 0) {
- char [] buffer = new char [toolTipText.length ()];
- toolTipText.getChars (0, buffer.length, buffer, 0);
- int length = fixMnemonic (buffer);
- if (display.helpString != 0) OS.CFRelease (display.helpString);
- display.helpString = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, length);
- HMHelpContentRec helpContent = new HMHelpContentRec ();
- OS.memmove (helpContent, ioHelpContent, HMHelpContentRec.sizeof);
- helpContent.version = OS.kMacHelpVersion;
-
- /*
- * Feature in the Macintosh. Despite the fact that the Mac
- * provides 23 different types of alignment for the help text,
- * it does not allow the text to be positioned at the current
- * mouse position. The fix is to center the text in a rectangle
- * that surrounds the original position of the mouse. As the
- * mouse is moved, this rectangle is grown to include the new
- * location of the mouse. The help text is then centered by
- * the Mac in the new rectangle that was carefully constructed
- * such that the help text will stay in the same position.
- */
- int cursorHeight = 16;
- helpContent.tagSide = (short) OS.kHMAbsoluteCenterAligned;
- org.eclipse.swt.internal.carbon.Point pt = new org.eclipse.swt.internal.carbon.Point ();
- OS.memmove(pt, new int[] {inGlobalMouse}, 4);
- int x = pt.h;
- int y = pt.v;
- if (display.helpWidget != this) {
- display.lastHelpX = x + cursorHeight / 2;
- display.lastHelpY = y + cursorHeight + cursorHeight / 2;
- }
- int jitter = 4;
- int deltaX = Math.abs (display.lastHelpX - x) + jitter;
- int deltaY = Math.abs (display.lastHelpY - y) + jitter;
- x = display.lastHelpX - deltaX;
- y = display.lastHelpY - deltaY;
- int width = deltaX * 2;
- int height = deltaY * 2;
- display.helpWidget = this;
- helpContent.absHotRect_left = (short) x;
- helpContent.absHotRect_top = (short) y;
- helpContent.absHotRect_right = (short) (x + width);
- helpContent.absHotRect_bottom = (short) (y + height);
-
- helpContent.content0_contentType = OS.kHMCFStringContent;
- helpContent.content0_tagCFString = display.helpString;
- helpContent.content1_contentType = OS.kHMCFStringContent;
- helpContent.content1_tagCFString = display.helpString;
- OS.memmove (ioHelpContent, helpContent, HMHelpContentRec.sizeof);
- contentProvided [0] = OS.kHMContentProvided;
- }
- OS.memmove (outContentProvided, contentProvided, 2);
- break;
- }
- case OS.kHMDisposeContent: {
- if (display.helpString != 0) OS.CFRelease (display.helpString);
- display.helpWidget = null;
- display.helpString = 0;
- break;
- }
- }
- return OS.noErr;
-}
-
-void hookEvents () {
- super.hookEvents ();
- int controlProc = display.controlProc;
- int [] mask = new int [] {
- OS.kEventClassControl, OS.kEventControlActivate,
- OS.kEventClassControl, OS.kEventControlApplyBackground,
- OS.kEventClassControl, OS.kEventControlBoundsChanged,
- OS.kEventClassControl, OS.kEventControlClick,
- OS.kEventClassControl, OS.kEventControlContextualMenuClick,
- OS.kEventClassControl, OS.kEventControlDeactivate,
- OS.kEventClassControl, OS.kEventControlDraw,
- OS.kEventClassControl, OS.kEventControlGetClickActivation,
- OS.kEventClassControl, OS.kEventControlGetFocusPart,
- OS.kEventClassControl, OS.kEventControlGetPartRegion,
- OS.kEventClassControl, OS.kEventControlHit,
- OS.kEventClassControl, OS.kEventControlHitTest,
- OS.kEventClassControl, OS.kEventControlSetCursor,
- OS.kEventClassControl, OS.kEventControlSetFocusPart,
- OS.kEventClassControl, OS.kEventControlTrack,
- };
- int controlTarget = OS.GetControlEventTarget (handle);
- OS.InstallEventHandler (controlTarget, controlProc, mask.length / 2, mask, handle, null);
- int accessibilityProc = display.accessibilityProc;
- mask = new int [] {
- OS.kEventClassAccessibility, OS.kEventAccessibleGetChildAtPoint,
- OS.kEventClassAccessibility, OS.kEventAccessibleGetFocusedChild,
- OS.kEventClassAccessibility, OS.kEventAccessibleGetAllAttributeNames,
- OS.kEventClassAccessibility, OS.kEventAccessibleGetNamedAttribute,
- };
- OS.InstallEventHandler (controlTarget, accessibilityProc, mask.length / 2, mask, handle, null);
- int helpProc = display.helpProc;
- OS.HMInstallControlContentCallback (handle, helpProc);
- int colorProc = display.colorProc;
- OS.SetControlColorProc (handle, colorProc);
- if (OS.GetControlAction (handle) == 0) {
- OS.SetControlAction (handle, display.actionProc);
- }
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Control</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public int internal_new_GC (GCData data) {
- checkWidget();
- int window = OS.GetControlOwner (handle);
- int port = data != null ? data.port : 0;
- if (port == 0) port = OS.GetWindowPort (window);
- int context;
- int [] buffer = new int [1];
- boolean isPaint = data != null && data.paintEvent != 0;
- if (isPaint) {
- OS.GetEventParameter (data.paintEvent, OS.kEventParamCGContextRef, OS.typeCGContextRef, null, 4, null, buffer);
- } else {
- OS.CreateCGContextForPort (port, buffer);
- }
- context = buffer [0];
- if (context == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- int visibleRgn = 0;
- if (data != null && data.paintEvent != 0) {
- visibleRgn = data.visibleRgn;
- } else {
- if (isDrawing()) {
- visibleRgn = getVisibleRegion (handle, true);
- } else {
- visibleRgn = OS.NewRgn ();
- }
- }
- Rect rect = new Rect ();
- Rect portRect = new Rect ();
- OS.GetControlBounds (handle, rect);
- OS.GetPortBounds (port, portRect);
- if (isPaint) {
- rect.right += rect.left;
- rect.bottom += rect.top;
- rect.left = rect.top = 0;
- } else {
- int [] contentView = new int [1];
- OS.HIViewFindByID (OS.HIViewGetRoot (window), OS.kHIViewWindowContentID (), contentView);
- CGPoint pt = new CGPoint ();
- OS.HIViewConvertPoint (pt, OS.HIViewGetSuperview (handle), contentView [0]);
- rect.left += (int) pt.x;
- rect.top += (int) pt.y;
- rect.right += (int) pt.x;
- rect.bottom += (int) pt.y;
- OS.ClipCGContextToRegion (context, portRect, visibleRgn);
- int portHeight = portRect.bottom - portRect.top;
- OS.CGContextScaleCTM (context, 1, -1);
- OS.CGContextTranslateCTM (context, rect.left, -portHeight + rect.top);
- }
- if (data != null) {
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) == 0) {
- data.style |= style & (mask | SWT.MIRRORED);
- }
- data.device = display;
- data.thread = display.thread;
- data.foreground = getForegroundColor ().handle;
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- data.background = control.getBackgroundColor ().handle;
- data.font = font != null ? font : defaultFont ();
- data.visibleRgn = visibleRgn;
- data.control = handle;
- data.portRect = portRect;
- data.controlRect = rect;
- data.insetRect = getInset ();
-
- if (data.paintEvent == 0) {
- if (gcs == null) gcs = new GCData [4];
- int index = 0;
- while (index < gcs.length && gcs [index] != null) index++;
- if (index == gcs.length) {
- GCData [] newGCs = new GCData [gcs.length + 4];
- System.arraycopy (gcs, 0, newGCs, 0, gcs.length);
- gcs = newGCs;
- }
- gcs [index] = data;
- }
- }
- return context;
-}
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Control</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int context, GCData data) {
- checkWidget ();
- if (data != null) {
- if (data.paintEvent == 0) {
- if (data.visibleRgn != 0) {
- OS.DisposeRgn (data.visibleRgn);
- data.visibleRgn = 0;
- }
-
- int index = 0;
- while (index < gcs.length && gcs [index] != data) index++;
- if (index < gcs.length) {
- gcs [index] = null;
- index = 0;
- while (index < gcs.length && gcs [index] == null) index++;
- if (index == gcs.length) gcs = null;
- }
- } else {
- return;
- }
- }
-
- /*
- * This code is intentionally commented. Use CGContextSynchronize
- * instead of CGContextFlush to improve performance.
- */
-// OS.CGContextFlush (context);
- OS.CGContextSynchronize (context);
- OS.CGContextRelease (context);
-}
-
-void invalidateChildrenVisibleRegion (int control) {
-}
-
-void invalidateVisibleRegion (int control) {
- int index = 0;
- Control[] siblings = parent._getChildren ();
- while (index < siblings.length && siblings [index] != this) index++;
- for (int i=index; i<siblings.length; i++) {
- Control sibling = siblings [i];
- sibling.resetVisibleRegion (control);
- sibling.invalidateChildrenVisibleRegion (control);
- }
- parent.resetVisibleRegion (control);
-}
-
-void invalWindowRgn (int window, int rgn) {
- parent.invalWindowRgn (window, rgn);
-}
-
-/*
- * Answers a boolean indicating whether a Label that precedes the receiver in
- * a layout should be read by screen readers as the recevier's label.
- */
-boolean isDescribedByLabel () {
- return true;
-}
-
-boolean isDrawing () {
- return getDrawing() && parent.isDrawing();
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * ancestors up to and including the receiver's nearest ancestor
- * shell are enabled. Otherwise, <code>false</code> is returned.
- * A disabled control is typically not selectable from the user
- * interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-
-boolean isEnabledCursor () {
- return isEnabled ();
-}
-
-boolean isEnabledModal () {
- //NOT DONE - fails for multiple APP MODAL shells
- Shell [] shells = display.getShells ();
- for (int i = 0; i < shells.length; i++) {
- Shell modal = shells [i];
- if (modal != this && modal.isVisible ()) {
- if ((modal.style & SWT.PRIMARY_MODAL) != 0) {
- Shell shell = getShell ();
- if (modal.parent == shell) {
- return false;
- }
- }
- int bits = SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- if ((modal.style & bits) != 0) {
- Control control = this;
- while (control != null) {
- if (control == modal) break;
- control = control.parent;
- }
- if (control != modal) return false;
- }
- }
- }
- return true;
-}
-
-boolean isFocusAncestor (Control control) {
- while (control != null && control != this && !(control instanceof Shell)) {
- control = control.parent;
- }
- return control == this;
-}
-
-/**
- * Returns <code>true</code> if the receiver has the user-interface
- * focus, and <code>false</code> otherwise.
- *
- * @return the receiver's focus state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isFocusControl () {
- checkWidget();
- Control focusControl = display.focusControl;
- if (focusControl != null && !focusControl.isDisposed ()) {
- return this == focusControl;
- }
- return hasFocus ();
-}
-
-/**
- * Returns <code>true</code> if the underlying operating
- * system supports this reparenting, otherwise <code>false</code>
- *
- * @return <code>true</code> if the widget can be reparented, otherwise <code>false</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isReparentable () {
- checkWidget();
- return true;
-}
-
-boolean isShowing () {
- /*
- * This is not complete. Need to check if the
- * widget is obscurred by a parent or sibling.
- */
- if (!isVisible ()) return false;
- Control control = this;
- while (control != null) {
- Point size = control.getSize ();
- if (size.x == 0 || size.y == 0) {
- return false;
- }
- control = control.parent;
- }
- return true;
-}
-
-boolean isTabGroup () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == this) return true;
- }
- }
- int code = traversalCode (0, 0);
- if ((code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) != 0) return false;
- return (code & (SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_TAB_NEXT)) != 0;
-}
-
-boolean isTabItem () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == this) return false;
- }
- }
- int code = traversalCode (0, 0);
- return (code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) != 0;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * ancestors up to and including the receiver's nearest ancestor
- * shell are visible. Otherwise, <code>false</code> is returned.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return getVisible () && parent.isVisible ();
-}
-
-Decorations menuShell () {
- return parent.menuShell ();
-}
-
-int kEventAccessibleGetChildAtPoint (int nextHandler, int theEvent, int userData) {
- if (accessible != null) {
- return accessible.internal_kEventAccessibleGetChildAtPoint (nextHandler, theEvent, userData);
- }
- return OS.eventNotHandledErr;
-}
-
-int kEventAccessibleGetFocusedChild (int nextHandler, int theEvent, int userData) {
- if (accessible != null) {
- return accessible.internal_kEventAccessibleGetFocusedChild (nextHandler, theEvent, userData);
- }
- return OS.eventNotHandledErr;
-}
-
-int kEventAccessibleGetAllAttributeNames (int nextHandler, int theEvent, int userData) {
- int code = OS.eventNotHandledErr;
- String [] attributes = getAxAttributes ();
- if (attributes != null) {
- OS.CallNextEventHandler (nextHandler, theEvent);
- int [] arrayRef = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamAccessibleAttributeNames, OS.typeCFMutableArrayRef, null, 4, null, arrayRef);
- int attributesArrayRef = arrayRef [0];
- int length = OS.CFArrayGetCount (attributesArrayRef);
- String[] osAttributes = new String [length];
- for (int i = 0; i < length; i++) {
- int stringRef = OS.CFArrayGetValueAtIndex (attributesArrayRef, i);
- int strLength = OS.CFStringGetLength (stringRef);
- char [] buffer = new char [strLength];
- CFRange range = new CFRange ();
- range.length = strLength;
- OS.CFStringGetCharacters (stringRef, range, buffer);
- osAttributes [i] = new String (buffer);
- }
- for (int i = 0; i < attributes.length; i++) {
- if (!contains (osAttributes, attributes [i])) {
- String string = attributes [i];
- char [] buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- int stringRef = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- OS.CFArrayAppendValue (attributesArrayRef, stringRef);
- OS.CFRelease (stringRef);
- }
- }
- code = OS.noErr;
- }
- if (accessible != null) {
- code = accessible.internal_kEventAccessibleGetAllAttributeNames (nextHandler, theEvent, code);
- }
- return code;
-}
-
-int kEventAccessibleGetNamedAttribute (int nextHandler, int theEvent, int userData) {
- if (accessible != null) {
- return accessible.internal_kEventAccessibleGetNamedAttribute (nextHandler, theEvent, OS.eventNotHandledErr);
- }
- return OS.eventNotHandledErr;
-}
-
-int kEventControlContextualMenuClick (int nextHandler, int theEvent, int userData) {
- int [] theControl = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamDirectObject, OS.typeControlRef, null, 4, null, theControl);
- Widget widget = display.getWidget (theControl [0]);
- while (widget != null && !(widget instanceof Control)) {
- OS.GetSuperControl (theControl [0], theControl);
- widget = display.getWidget (theControl [0]);
- }
- if (widget == this && isEnabled ()) {
- int x, y;
- Rect rect = new Rect ();
- int window = OS.GetControlOwner (handle);
- CGPoint pt = new CGPoint ();
- OS.GetEventParameter (theEvent, OS.kEventParamWindowMouseLocation, OS.typeHIPoint, null, CGPoint.sizeof, null, pt);
- x = (int) pt.x;
- y = (int) pt.y;
- OS.GetWindowBounds (window, (short) OS.kWindowStructureRgn, rect);
- x += rect.left;
- y += rect.top;
- Event event = new Event ();
- event.x = x;
- event.y = y;
- sendEvent (SWT.MenuDetect, event);
- // widget could be disposed at this point
- if (isDisposed ()) return OS.noErr;
- if (event.doit) {
- if (menu != null && !menu.isDisposed ()) {
- if (event.x != x || event.y != y) {
- menu.setLocation (event.x, event.y);
- }
- menu.setVisible (true);
- }
- }
- }
- return OS.eventNotHandledErr;
-}
-
-int kEventControlGetClickActivation (int nextHandler, int theEvent, int userData) {
- if ((getShell ().style & SWT.ON_TOP) != 0) {
- OS.SetEventParameter (theEvent, OS.kEventParamClickActivation, OS.typeClickActivationResult, 4, new int [] {OS.kActivateAndHandleClick});
- return OS.noErr;
- }
- return super.kEventControlGetClickActivation (nextHandler, theEvent, userData);
-}
-
-int kEventControlGetPartRegion (int nextHandler, int theEvent, int userData) {
- int result = super.kEventControlGetPartRegion (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- if (region != null && this != getShell ()) {
- short [] part = new short [1];
- OS.GetEventParameter (theEvent, OS.kEventParamControlPart, OS.typeControlPartCode , null, 2, null, part);
- if (part [0] == OS.kControlStructureMetaPart || part [0] == OS.kControlClickableMetaPart) {
- int [] rgn = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamControlRegion, OS.typeQDRgnHandle , null, 4, null, rgn);
- OS.CopyRgn (region.handle, rgn[0]);
- Rect rect = getInset ();
- OS.OffsetRgn (rgn [0], (short)-rect.left, (short)-rect.top);
- return OS.noErr;
- }
- }
- return result;
-}
-
-int kEventControlHitTest (int nextHandler, int theEvent, int userData) {
- int result = super.kEventControlHitTest (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- if (region != null && this != getShell ()) {
- result = OS.CallNextEventHandler (nextHandler, theEvent);
- CGPoint pt = new CGPoint ();
- OS.GetEventParameter (theEvent, OS.kEventParamMouseLocation, OS.typeHIPoint, null, CGPoint.sizeof, null, pt);
- if (!region.contains ((int) pt.x, (int) pt.y)) {
- OS.SetEventParameter (theEvent, OS.kEventParamControlPart, OS.typeControlPartCode, 2, new short []{0});
- return result;
- }
- }
- if ((state & GRAB) != 0) {
- CGRect rect = new CGRect ();
- OS.HIViewGetBounds (handle, rect);
- CGPoint pt = new CGPoint ();
- OS.GetEventParameter (theEvent, OS.kEventParamMouseLocation, OS.typeHIPoint, null, CGPoint.sizeof, null, pt);
- if (OS.CGRectContainsPoint (rect, pt) != 0) {
- OS.SetEventParameter (theEvent, OS.kEventParamControlPart, OS.typeControlPartCode, 2, new short[]{1});
- }
- return OS.noErr;
- }
- return result;
-}
-
-int kEventControlSetCursor (int nextHandler, int theEvent, int userData) {
- if (!isEnabledCursor ()) return OS.noErr;
- Cursor cursor = null;
- if (isEnabledModal ()) {
- if ((cursor = findCursor ()) != null) display.setCursor (cursor.handle);
- }
- return cursor != null ? OS.noErr : OS.eventNotHandledErr;
-}
-
-int kEventControlSetFocusPart (int nextHandler, int theEvent, int userData) {
- display.focusCombo = null;
- int result = callFocusEventHandler (nextHandler, theEvent);
- if (!display.ignoreFocus) {
- if (result == OS.noErr) {
- int window = OS.GetControlOwner (handle);
- if (window == OS.GetUserFocusWindow ()) {
- int focusHandle = focusHandle ();
- int [] focusControl = new int [1];
- OS.GetKeyboardFocus (window, focusControl);
- short [] part = new short [1];
- OS.GetEventParameter (theEvent, OS.kEventParamControlPart, OS.typeControlPartCode, null, 2, null, part);
- Display display = this.display;
- display.delayDispose = true;
- if (part [0] == OS.kControlFocusNoPart) {
- if (focusControl [0] == focusHandle) sendFocusEvent (SWT.FocusOut, false);
- } else {
- if (focusControl [0] != focusHandle) sendFocusEvent (SWT.FocusIn, false);
- }
- display.delayDispose = false;
- }
- // widget could be disposed at this point
- if (isDisposed ()) return OS.noErr;
- }
- }
- return result;
-}
-
-int kEventControlTrack (int nextHandler, int theEvent, int userData) {
- /*
- * Feature in the Macintosh. The default handler of kEventControlTrack
- * calls TrackControl() which consumes key and mouse events until the
- * tracking is canceled. The fix is to send those events from the
- * action proc of the widget by diffing the mouse and modifier keys
- * state.
- */
- Display display = this.display;
-// display.runDeferredEvents ();
- if (isDisposed ()) return OS.noErr;
- if (display.runPopups ()) return OS.noErr;
- if (isDisposed ()) return OS.noErr;
- display.lastState = OS.GetCurrentEventButtonState ();
- display.lastModifiers = OS.GetCurrentEventKeyModifiers ();
- display.grabControl = this;
- int timer = 0;
- if (pollTrackEvent ()) {
- if (display.pollingTimer == 0) {
- int [] id = new int [1];
- int eventLoop = OS.GetCurrentEventLoop ();
- OS.InstallEventLoopTimer (eventLoop, Display.POLLING_TIMEOUT / 1000.0, Display.POLLING_TIMEOUT / 1000.0, display.pollingProc, 0, id);
- display.pollingTimer = timer = id [0];
- }
- }
- int result = super.kEventControlTrack (nextHandler, theEvent, userData);
- if (timer != 0) {
- OS.RemoveEventLoopTimer (timer);
- display.pollingTimer = 0;
- }
- display.grabControl = null;
- if (isDisposed ()) return OS.noErr;
- sendTrackEvents ();
- return result;
-}
-
-int kEventMouseDown (int nextHandler, int theEvent, int userData) {
- Shell shell = getShell ();
- display.dragging = false;
- boolean [] consume = new boolean [1];
- short [] button = new short [1];
- OS.GetEventParameter (theEvent, OS.kEventParamMouseButton, OS.typeMouseButton, null, 2, null, button);
- int [] clickCount = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamClickCount, OS.typeUInt32, null, 4, null, clickCount);
- if (button [0] == 1 && clickCount [0] == 1 && (state & DRAG_DETECT) != 0 && hooks (SWT.DragDetect)) {
- CGPoint pt = new CGPoint ();
- OS.GetEventParameter (theEvent, OS.kEventParamWindowMouseLocation, OS.typeHIPoint, null, CGPoint.sizeof, null, pt);
- OS.HIViewConvertPoint (pt, 0, handle);
- int x = (int) pt.x;
- int y = (int) pt.y;
- if (dragDetect (x, y, true, consume)) {
- display.dragging = true;
- display.dragButton = button [0];
- display.dragX = x;
- display.dragY = y;
- int [] chord = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamMouseChord, OS.typeUInt32, null, 4, null, chord);
- display.dragState = chord [0];
- int [] modifiers = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
- display.dragModifiers = modifiers [0];
- }
- if (isDisposed ()) return OS.noErr;
- }
- if (!sendMouseEvent (SWT.MouseDown, button [0], display.clickCount, 0, false, theEvent)) consume [0] = true;
- if (isDisposed ()) return OS.noErr;
- if (display.clickCount == 2) {
- if (!sendMouseEvent (SWT.MouseDoubleClick, button [0], display.clickCount, 0, false, theEvent)) consume [0] = true;
- if (isDisposed ()) return OS.noErr;
- }
- if (!shell.isDisposed ()) shell.setActiveControl (this);
- return consume [0] ? OS.noErr : OS.eventNotHandledErr;
-}
-
-int kEventMouseDragged (int nextHandler, int theEvent, int userData) {
- if (isEnabledModal ()) {
- if (display.dragging) {
- display.dragging = false;
- sendDragEvent (display.dragButton, display.dragState, display.dragModifiers, display.dragX, display.dragY);
- if (isDisposed ()) return OS.noErr;
- }
- int result = sendMouseEvent (SWT.MouseMove, (short) 0, 0, 0, false, theEvent) ? OS.eventNotHandledErr : OS.noErr;
- if (isDisposed ()) return OS.noErr;
- return result;
- }
- return OS.eventNotHandledErr;
-}
-
-int kEventMouseMoved (int nextHandler, int theEvent, int userData) {
- if (isEnabledModal ()) {
- return sendMouseEvent (SWT.MouseMove, (short) 0, 0, 0, false, theEvent) ? OS.eventNotHandledErr : OS.noErr;
- }
- return OS.eventNotHandledErr;
-}
-
-int kEventMouseUp (int nextHandler, int theEvent, int userData) {
- short [] button = new short [1];
- OS.GetEventParameter (theEvent, OS.kEventParamMouseButton, OS.typeMouseButton, null, 2, null, button);
- return sendMouseEvent (SWT.MouseUp, button [0], display.clickCount, 0, false, theEvent) ? OS.eventNotHandledErr : OS.noErr;
-}
-
-int kEventMouseWheelMoved (int nextHandler, int theEvent, int userData) {
- if ((state & IGNORE_WHEEL) != 0) return OS.eventNotHandledErr;
-
- /*
- * Bug in the Macintosh. Mouse Wheel events are still processed when the
- * window is not enabled due to a modal dialog. The fix is to not let the
- * default handlers run when window is modal disabled.
- */
- int window = OS.GetControlOwner (handle);
- if (OS.HIWindowIsDocumentModalTarget (window, null)) {
- return OS.noErr;
- }
- int[] event = new int[1];
- OS.CreateEvent (0, OS.kEventClassWindow, OS.kEventWindowGetClickModality, 0.0, 0, event);
- if (event [0] != 0) {
- short [] part = new short [1];
- OS.GetEventParameter (theEvent, OS.kEventParamWindowPartCode, OS.typeWindowPartCode, null, 2, null, part);
- int [] modifiers = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, modifiers.length * 4, null, modifiers);
- OS.SetEventParameter (event [0], OS.kEventParamDirectObject, OS.typeWindowRef, 4, new int[]{window});
- OS.SetEventParameter (event [0], OS.kEventParamWindowPartCode, OS.typeWindowPartCode, 2, part);
- OS.SetEventParameter (event [0], OS.kEventParamKeyModifiers, OS.typeUInt32, 4, modifiers);
- OS.SetEventParameter (event [0], OS.kEventParamEventRef, OS.typeEventRef, 4, new int[]{theEvent});
- OS.SendEventToEventTarget (event [0], OS.GetApplicationEventTarget ());
- int [] clickResult = new int [1];
- OS.GetEventParameter (event [0], OS.kEventParamModalClickResult, OS.typeModalClickResult, null, 4, null, clickResult);
- OS.ReleaseEvent (event [0]);
- if ((clickResult [0] & OS.kHIModalClickIsModal) != 0) {
- if ((clickResult [0] & OS.kHIModalClickAllowEvent) == 0) {
- return OS.noErr;
- }
- }
- }
-
- short [] wheelAxis = new short [1];
- OS.GetEventParameter (theEvent, OS.kEventParamMouseWheelAxis, OS.typeMouseWheelAxis, null, 2, null, wheelAxis);
- int [] wheelDelta = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamMouseWheelDelta, OS.typeSInt32, null, 4, null, wheelDelta);
- Shell shell = getShell ();
- Control control = this;
- while (control != null) {
- if (!control.sendMouseEvent (SWT.MouseWheel, (short) 0, wheelDelta [0], SWT.SCROLL_LINE, true, theEvent)) {
- break;
- }
- if (control.sendMouseWheel (wheelAxis [0], wheelDelta [0])) break;
- if (control == this) {
- /*
- * Feature in the Macintosh. For some reason, the kEventMouseWheelMoved
- * event is sent twice to each application handler with the same mouse wheel
- * data. The fix is to set an ignore flag before calling the next handler
- * in the handler chain.
- */
- state |= IGNORE_WHEEL;
- int result = OS.CallNextEventHandler (nextHandler, theEvent);
- state &= ~IGNORE_WHEEL;
- if (result == OS.noErr) break;
- }
- if (control == shell) break;
- control = control.parent;
- }
- return OS.noErr;
-}
-
-int kEventTextInputUnicodeForKeyEvent (int nextHandler, int theEvent, int userData) {
- int [] keyboardEvent = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendKeyboardEvent, OS.typeEventRef, null, keyboardEvent.length * 4, null, keyboardEvent);
- int [] keyCode = new int [1];
- OS.GetEventParameter (keyboardEvent [0], OS.kEventParamKeyCode, OS.typeUInt32, null, keyCode.length * 4, null, keyCode);
- boolean [] consume = new boolean [1];
- if (translateTraversal (keyCode [0], keyboardEvent [0], consume)) return OS.noErr;
- if (isDisposed ()) return OS.noErr;
- if (keyCode [0] == 114) { /* Help */
- Control control = this;
- while (control != null) {
- if (control.hooks (SWT.Help)) {
- control.postEvent (SWT.Help);
- break;
- }
- control = control.parent;
- }
- }
- int result = kEventUnicodeKeyPressed (nextHandler, theEvent, userData);
- if (result == OS.noErr || consume [0]) return OS.noErr;
- /*
- * Feature in the Macintosh. If the focus target is changed
- * before the default handler for the widget has run, the key
- * goes to the new focus widget. The fix is to explicitly
- * send the event to the original focus widget and stop
- * the chain of handlers.
- */
- if (!isDisposed ()) {
- Control focusControl = display.getFocusControl ();
- if (focusControl != this) {
- int window = OS.GetControlOwner (handle), newWindow = 0;
- if (focusControl != null) {
- newWindow = OS.GetControlOwner (focusControl.handle);
- }
- display.ignoreFocus = true;
- if (window != newWindow) OS.SetUserFocusWindow (window);
- OS.SetKeyboardFocus (window, focusHandle (), (short) focusPart ());
- display.ignoreFocus = false;
- result = OS.CallNextEventHandler (nextHandler, theEvent);
- display.ignoreFocus = true;
- if (window != newWindow && newWindow != 0) OS.SetUserFocusWindow (newWindow);
- if (window == newWindow && focusControl != null) {
- OS.SetKeyboardFocus (window, focusControl.focusHandle (), (short) focusControl.focusPart ());
- } else {
- OS.ClearKeyboardFocus (window);
- }
- display.ignoreFocus = false;
- return OS.noErr;
- }
- }
- return result;
-}
-
-int kEventUnicodeKeyPressed (int nextHandler, int theEvent, int userData) {
- int [] keyboardEvent = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendKeyboardEvent, OS.typeEventRef, null, keyboardEvent.length * 4, null, keyboardEvent);
- if (!sendKeyEvent (SWT.KeyDown, keyboardEvent [0])) return OS.noErr;
- return OS.eventNotHandledErr;
-}
-
-void markLayout (boolean changed, boolean all) {
- /* Do nothing */
-}
-
-/**
- * Moves the receiver above the specified control in the
- * drawing order. If the argument is null, then the receiver
- * is moved to the top of the drawing order. The control at
- * the top of the drawing order will not be covered by other
- * controls even if they occupy intersecting areas.
- *
- * @param control the sibling control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveBelow
- * @see Composite#getChildren
- */
-public void moveAbove (Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- }
- setZOrder (control, true);
-}
-
-/**
- * Moves the receiver below the specified control in the
- * drawing order. If the argument is null, then the receiver
- * is moved to the bottom of the drawing order. The control at
- * the bottom of the drawing order will be covered by all other
- * controls which occupy intersecting areas.
- *
- * @param control the sibling control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveAbove
- * @see Composite#getChildren
- */
-public void moveBelow (Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- }
- setZOrder (control, false);
-}
-
-Accessible new_Accessible (Control control) {
- return Accessible.internal_new_Accessible (this);
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeSize(int, int, boolean)
- */
-public void pack () {
- checkWidget();
- pack (true);
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- * <p>
- * If the changed flag is <code>true</code>, it indicates that the receiver's
- * <em>contents</em> have changed, therefore any caches that a layout manager
- * containing the control may have been keeping need to be flushed. When the
- * control is resized, the changed flag will be <code>false</code>, so layout
- * manager caches can be retained.
- * </p>
- *
- * @param changed whether or not the receiver's contents have changed
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeSize(int, int, boolean)
- */
-public void pack (boolean changed) {
- checkWidget();
- setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed));
-}
-
-/**
- * Prints the receiver and all children.
- *
- * @param gc the gc where the drawing occurs
- * @return <code>true</code> if the operation was successful and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean print (GC gc) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- int [] outImage = new int [1];
- CGRect outFrame = new CGRect ();
- if (OS.HIViewCreateOffscreenImage (handle, 0, outFrame, outImage) == OS.noErr) {
- int width = OS.CGImageGetWidth (outImage [0]);
- int height = OS.CGImageGetHeight (outImage [0]);
- CGRect rect = new CGRect();
- rect.width = width;
- rect.height = height;
- //TODO - does not draw the browser (cocoa widgets?)
- OS.HIViewDrawCGImage (gc.handle, rect, outImage [0]);
- OS.CGImageRelease (outImage [0]);
- }
- return true;
-}
-
-boolean pollTrackEvent() {
- return false;
-}
-
-/**
- * Causes the entire bounds of the receiver to be marked
- * as needing to be redrawn. The next time a paint request
- * is processed, the control will be completely painted,
- * including the background.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #update()
- * @see PaintListener
- * @see SWT#Paint
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#DOUBLE_BUFFERED
- */
-public void redraw () {
- checkWidget();
- redrawWidget (handle, false);
-}
-
-void redraw (boolean children) {
-// checkWidget();
- redrawWidget (handle, children);
-}
-
-/**
- * Causes the rectangular area of the receiver specified by
- * the arguments to be marked as needing to be redrawn.
- * The next time a paint request is processed, that area of
- * the receiver will be painted, including the background.
- * If the <code>all</code> flag is <code>true</code>, any
- * children of the receiver which intersect with the specified
- * area will also paint their intersecting areas. If the
- * <code>all</code> flag is <code>false</code>, the children
- * will not be painted.
- *
- * @param x the x coordinate of the area to draw
- * @param y the y coordinate of the area to draw
- * @param width the width of the area to draw
- * @param height the height of the area to draw
- * @param all <code>true</code> if children should redraw, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #update()
- * @see PaintListener
- * @see SWT#Paint
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#DOUBLE_BUFFERED
- */
-public void redraw (int x, int y, int width, int height, boolean all) {
- checkWidget ();
- redrawWidget (handle, x, y, width, height, all);
-}
-
-void register () {
- super.register ();
- display.addWidget (handle, this);
-}
-
-void release (boolean destroy) {
- Control next = null, previous = null;
- if (destroy && parent != null) {
- Control[] children = parent._getChildren ();
- int index = 0;
- while (index < children.length) {
- if (children [index] == this) break;
- index++;
- }
- if (0 < index && (index + 1) < children.length) {
- next = children [index + 1];
- previous = children [index - 1];
- }
- }
- super.release (destroy);
- if (destroy) {
- if (previous != null) previous.addRelation (next);
- }
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- handle = 0;
- parent = null;
-}
-
-void releaseParent () {
- setVisible (topHandle (), false);
- parent.removeControl (this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- if (visibleRgn != 0) OS.DisposeRgn (visibleRgn);
- visibleRgn = 0;
- menu = null;
- layoutData = null;
- if (accessible != null) {
- accessible.internal_dispose_Accessible ();
- }
- accessible = null;
- region = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when a drag gesture occurs.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @since 3.3
- */
-public void removeDragDetectListener(DragDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.DragDetect, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control gains or loses focus.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see FocusListener
- * @see #addFocusListener
- */
-public void removeFocusListener(FocusListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.FocusIn, listener);
- eventTable.unhook(SWT.FocusOut, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #addKeyListener
- */
-public void removeKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.KeyUp, listener);
- eventTable.unhook(SWT.KeyDown, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the platform-specific context menu trigger has
- * occurred.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #addMenuDetectListener
- *
- * @since 3.3
- */
-public void removeMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MenuDetect, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when mouse buttons are pressed and released.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseListener
- * @see #addMouseListener
- */
-public void removeMouseListener(MouseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.MouseDown, listener);
- eventTable.unhook(SWT.MouseUp, listener);
- eventTable.unhook(SWT.MouseDoubleClick, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse moves.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseMoveListener
- * @see #addMouseMoveListener
- */
-public void removeMouseMoveListener(MouseMoveListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.MouseMove, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse passes or hovers over controls.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseTrackListener
- * @see #addMouseTrackListener
- */
-public void removeMouseTrackListener(MouseTrackListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseEnter, listener);
- eventTable.unhook (SWT.MouseExit, listener);
- eventTable.unhook (SWT.MouseHover, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse wheel is scrolled.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseWheelListener
- * @see #addMouseWheelListener
- *
- * @since 3.3
- */
-public void removeMouseWheelListener (MouseWheelListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseWheel, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver needs to be painted.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see PaintListener
- * @see #addPaintListener
- */
-public void removePaintListener(PaintListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Paint, listener);
-}
-
-/*
- * Remove "Labeled by" relations from the receiver.
- */
-void removeRelation () {
- if (!isDescribedByLabel ()) return; /* there will not be any */
- String string = OS.kAXTitleUIElementAttribute;
- char [] buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- int stringRef = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- OS.HIObjectSetAuxiliaryAccessibilityAttribute(handle, 0, stringRef, 0);
- OS.CFRelease(stringRef);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when traversal events occur.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TraverseListener
- * @see #addTraverseListener
- */
-public void removeTraverseListener(TraverseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Traverse, listener);
-}
-
-void resetVisibleRegion (int control) {
- if (visibleRgn != 0) {
- OS.DisposeRgn (visibleRgn);
- visibleRgn = 0;
- }
- if (gcs != null) {
- int visibleRgn = getVisibleRegion (handle, true);
- for (int i=0; i<gcs.length; i++) {
- GCData data = gcs [i];
- if (data != null) {
- data.updateClip = true;
- OS.CopyRgn (visibleRgn, data.visibleRgn);
- }
- }
- OS.DisposeRgn (visibleRgn);
- }
- Object runnable = getData (RESET_VISIBLE_REGION);
- if (runnable != null && runnable instanceof Runnable) {
- ((Runnable) runnable).run ();
- }
-}
-
-boolean sendDragEvent (int button, int stateMask, int x, int y) {
- Event event = new Event ();
- event.button = button;
- event.x = x;
- event.y = y;
- event.stateMask = stateMask;
- postEvent (SWT.DragDetect, event);
- return event.doit;
-}
-
-boolean sendDragEvent (int button, int chord, int modifiers, int x, int y) {
- Event event = new Event ();
- switch (button) {
- case 1: event.button = 1; break;
- case 2: event.button = 3; break;
- case 3: event.button = 2; break;
- case 4: event.button = 4; break;
- case 5: event.button = 5; break;
- }
- event.x = x;
- event.y = y;
- setInputState (event, SWT.DragDetect, chord, modifiers);
- postEvent (SWT.DragDetect, event);
- return event.doit;
-}
-
-void sendFocusEvent (int type, boolean post) {
- Display display = this.display;
- Shell shell = getShell ();
- /*
- * Feature in the Macintosh. GetKeyboardFocus() returns NULL during
- * kEventControlSetFocusPart if the focus part is not kControlFocusNoPart.
- * The fix is to remember the focus control and return it during
- * kEventControlSetFocusPart.
- */
- display.focusControl = this;
- display.focusEvent = type;
- if (post) {
- postEvent (type);
- } else {
- sendEvent (type);
- }
- /*
- * It is possible that the shell may be
- * disposed at this point. If this happens
- * don't send the activate and deactivate
- * events.
- */
- if (!shell.isDisposed ()) {
- switch (type) {
- case SWT.FocusIn:
- shell.setActiveControl (this);
- break;
- case SWT.FocusOut:
- if (shell != display.getActiveShell ()) {
- shell.setActiveControl (null);
- }
- break;
- }
- }
- display.focusEvent = SWT.None;
- display.focusControl = null;
-}
-
-boolean sendMouseEvent (int type, short button, int count, int detail, boolean send, int theEvent) {
- CGPoint pt = new CGPoint ();
- OS.GetEventParameter (theEvent, OS.kEventParamWindowMouseLocation, OS.typeHIPoint, null, CGPoint.sizeof, null, pt);
- OS.HIViewConvertPoint (pt, 0, handle);
- int x = (int) pt.x;
- int y = (int) pt.y;
- display.lastX = x;
- display.lastY = y;
- int [] chord = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamMouseChord, OS.typeUInt32, null, 4, null, chord);
- int [] modifiers = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
- return sendMouseEvent (type, button, count, detail, send, chord [0], (short) x, (short) y, modifiers [0]);
-}
-
-boolean sendMouseEvent (int type, short button, int count, boolean send, int chord, short x, short y, int modifiers) {
- return sendMouseEvent (type, button, count, 0, send, chord, x, y, modifiers);
-}
-
-boolean sendMouseEvent (int type, short button, int count, int detail, boolean send, int chord, short x, short y, int modifiers) {
- if (!hooks (type) && !filters (type)) return true;
- if ((state & SAFARI_EVENTS_FIX) != 0) {
- switch (type) {
- case SWT.MouseUp:
- case SWT.MouseMove:
- case SWT.MouseDoubleClick: {
- return true;
- }
- case SWT.MouseDown: {
- if (button == 1) return true;
- break;
- }
- }
- }
- Event event = new Event ();
- switch (button) {
- case 1: event.button = 1; break;
- case 2: event.button = 3; break;
- case 3: event.button = 2; break;
- case 4: event.button = 4; break;
- case 5: event.button = 5; break;
- }
- event.x = x;
- event.y = y;
- event.count = count;
- event.detail = detail;
- setInputState (event, type, chord, modifiers);
- if (send) {
- sendEvent (type, event);
- if (isDisposed ()) return false;
- } else {
- postEvent (type, event);
- }
- return event.doit;
-}
-
-boolean sendMouseWheel (short wheelAxis, int wheelDelta) {
- return false;
-}
-
-void sendTrackEvents () {
- Display display = this.display;
- display.runDeferredEvents ();
- if (isDisposed ()) return;
- boolean events = false;
- if (display.dragging) {
- display.dragging = false;
- sendDragEvent (display.dragButton, display.dragState, display.dragModifiers, display.dragX, display.dragY);
- if (isDisposed ()) return;
- events = true;
- }
- org.eclipse.swt.internal.carbon.Point outPt = new org.eclipse.swt.internal.carbon.Point ();
- OS.GetGlobalMouse (outPt);
- Rect rect = new Rect ();
- int window = OS.GetControlOwner (handle);
- int newX, newY;
- CGPoint pt = new CGPoint ();
- pt.x = outPt.h;
- pt.y = outPt.v;
- OS.HIViewConvertPoint (pt, 0, handle);
- newX = (int) pt.x;
- newY = (int) pt.y;
- OS.GetWindowBounds (window, (short) OS.kWindowStructureRgn, rect);
- newX -= rect.left;
- newY -= rect.top;
- int newModifiers = OS.GetCurrentEventKeyModifiers ();
- int newState = OS.GetCurrentEventButtonState ();
- int oldX = display.lastX;
- int oldY = display.lastY;
- int oldState = display.lastState;
- int oldModifiers = display.lastModifiers;
- display.lastX = newX;
- display.lastY = newY;
- display.lastModifiers = newModifiers;
- display.lastState = newState;
- if (newState != oldState) {
- int button = 0, type = SWT.MouseDown;
- if ((oldState & 0x1) == 0 && (newState & 0x1) != 0) button = 1;
- if ((oldState & 0x2) == 0 && (newState & 0x2) != 0) button = 2;
- if ((oldState & 0x4) == 0 && (newState & 0x4) != 0) button = 3;
- if ((oldState & 0x8) == 0 && (newState & 0x8) != 0) button = 4;
- if ((oldState & 0x10) == 0 && (newState & 0x10) != 0) button = 5;
- if (button == 0) {
- type = SWT.MouseUp;
- if ((oldState & 0x1) != 0 && (newState & 0x1) == 0) button = 1;
- if ((oldState & 0x2) != 0 && (newState & 0x2) == 0) button = 2;
- if ((oldState & 0x4) != 0 && (newState & 0x4) == 0) button = 3;
- if ((oldState & 0x8) != 0 && (newState & 0x8) == 0) button = 4;
- if ((oldState & 0x10) != 0 && (newState & 0x10) == 0) button = 5;
- }
- if (button != 0) {
- sendMouseEvent (type, (short)button, 1, false, newState, (short)newX, (short)newY, newModifiers);
- events = true;
- }
- }
- if (newModifiers != oldModifiers && !isDisposed ()) {
- int key = 0, type = SWT.KeyDown;
- if ((newModifiers & OS.alphaLock) != 0 && (oldModifiers & OS.alphaLock) == 0) key = SWT.CAPS_LOCK;
- if ((newModifiers & OS.shiftKey) != 0 && (oldModifiers & OS.shiftKey) == 0) key = SWT.SHIFT;
- if ((newModifiers & OS.controlKey) != 0 && (oldModifiers & OS.controlKey) == 0) key = SWT.CONTROL;
- if ((newModifiers & OS.cmdKey) != 0 && (oldModifiers & OS.cmdKey) == 0) key = SWT.COMMAND;
- if ((newModifiers & OS.optionKey) != 0 && (oldModifiers & OS.optionKey) == 0) key = SWT.ALT;
- if (key == 0) {
- type = SWT.KeyUp;
- if ((newModifiers & OS.alphaLock) == 0 && (oldModifiers & OS.alphaLock) != 0) key = SWT.CAPS_LOCK;
- if ((newModifiers & OS.shiftKey) == 0 && (oldModifiers & OS.shiftKey) != 0) key = SWT.SHIFT;
- if ((newModifiers & OS.controlKey) == 0 && (oldModifiers & OS.controlKey) != 0) key = SWT.CONTROL;
- if ((newModifiers & OS.cmdKey) == 0 && (oldModifiers & OS.cmdKey) != 0) key = SWT.COMMAND;
- if ((newModifiers & OS.optionKey) == 0 && (oldModifiers & OS.optionKey) != 0) key = SWT.ALT;
- }
- if (key != 0) {
- Event event = new Event ();
- event.keyCode = key;
- setInputState (event, type, newState, newModifiers);
- sendKeyEvent (type, event);
- events = true;
- }
- }
- if (newX != oldX || newY != oldY && !isDisposed ()) {
- display.mouseMoved = true;
- sendMouseEvent (SWT.MouseMove, (short)0, 0, false, newState, (short)newX, (short)newY, newModifiers);
- events = true;
- }
- if (events) display.runDeferredEvents ();
-}
-
-void setBackground () {
- redrawWidget (handle, false);
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the control
- * if the argument is null.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on Windows the background of a Button cannot be changed.
- * </p>
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBackground (Color color) {
- checkWidget();
- if (color != null) {
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- float[] background = color != null ? color.handle : null;
- if (equals (background, this.background)) return;
- this.background = background;
- setBackground (background);
- redrawWidget (handle, false);
-}
-
-/**
- * Sets the receiver's background image to the image specified
- * by the argument, or to the default system color for the control
- * if the argument is null. The background image is tiled to fill
- * the available space.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on Windows the background of a Button cannot be changed.
- * </p>
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument is not a bitmap</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setBackgroundImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (image == backgroundImage) return;
- backgroundImage = image;
- redrawWidget (handle, false);
-}
-
-void setBackground (float [] color) {
- setBackground (handle, color);
-}
-
-void setBackground (int control, float [] color) {
- ControlFontStyleRec fontStyle = new ControlFontStyleRec ();
- OS.GetControlData (control, (short) OS.kControlEntireControl, OS.kControlFontStyleTag, ControlFontStyleRec.sizeof, fontStyle, null);
- if (color != null) {
- fontStyle.backColor_red = (short) (color [0] * 0xffff);
- fontStyle.backColor_green = (short) (color [1] * 0xffff);
- fontStyle.backColor_blue = (short) (color [2] * 0xffff);
- fontStyle.flags |= OS.kControlUseBackColorMask;
- } else {
- fontStyle.flags &= ~OS.kControlUseBackColorMask;
- }
- OS.SetControlFontStyle (control, fontStyle);
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the arguments. The <code>x</code> and
- * <code>y</code> arguments are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the <code>x</code>
- * and <code>y</code> arguments are relative to the display.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (int x, int y, int width, int height) {
- checkWidget();
- setBounds (x, y, Math.max (0, width), Math.max (0, height), true, true, true);
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- return setBounds (topHandle (), x, y, width, height, move, resize, events);
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the argument. The <code>x</code> and
- * <code>y</code> fields of the rectangle are relative to
- * the receiver's parent (or its display if its parent is null).
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param rect the new bounds for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (Rectangle rect) {
- checkWidget ();
- if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (rect.x, rect.y, Math.max (0, rect.width), Math.max (0, rect.height), true, true, true);
-}
-
-/**
- * If the argument is <code>true</code>, causes the receiver to have
- * all mouse events delivered to it until the method is called with
- * <code>false</code> as the argument. Note that on some platforms,
- * a mouse button must currently be down for capture to be assigned.
- *
- * @param capture <code>true</code> to capture the mouse, and <code>false</code> to release it
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCapture (boolean capture) {
- checkWidget();
-}
-
-/**
- * Sets the receiver's cursor to the cursor specified by the
- * argument, or to the default cursor for that kind of control
- * if the argument is null.
- * <p>
- * When the mouse pointer passes over a control its appearance
- * is changed to match the control's cursor.
- * </p>
- *
- * @param cursor the new cursor (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCursor (Cursor cursor) {
- checkWidget();
- if (cursor != null && cursor.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- this.cursor = cursor;
- if (!isEnabled ()) return;
- org.eclipse.swt.internal.carbon.Point where = new org.eclipse.swt.internal.carbon.Point ();
- OS.GetGlobalMouse (where);
- int [] theWindow = new int [1];
- if (display.grabControl == this) {
- theWindow [0] = OS.GetControlOwner (handle);
- } else {
- if (OS.FindWindow (where, theWindow) != OS.inContent) return;
- if (theWindow [0] == 0) return;
- }
- Rect rect = new Rect ();
- OS.GetWindowBounds (theWindow [0], (short) OS.kWindowStructureRgn, rect);
- int [] theControl = new int [1];
- if (display.grabControl == this) {
- theControl [0] = handle;
- } else {
- CGPoint inPoint = new CGPoint ();
- inPoint.x = where.h - rect.left;
- inPoint.y = where.v - rect.top;
- int [] theRoot = new int [1];
- OS.GetRootControl (theWindow [0], theRoot);
- int[] event = new int[1];
- OS.CreateEvent (0, OS.kEventClassMouse, OS.kEventMouseDown, 0.0, 0, event);
- OS.SetEventParameter (event[0], OS.kEventParamWindowMouseLocation, OS.typeHIPoint, CGPoint.sizeof, inPoint);
- OS.HIViewGetViewForMouseEvent (theRoot [0], event [0], theControl);
- OS.ReleaseEvent(event[0]);
- int cursorControl = theControl [0];
- while (theControl [0] != 0 && theControl [0] != handle) {
- OS.GetSuperControl (theControl [0], theControl);
- }
- if (theControl [0] == 0) return;
- theControl [0] = cursorControl;
- do {
- Widget widget = display.getWidget (theControl [0]);
- if (widget != null) {
- if (widget instanceof Control) {
- Control control = (Control) widget;
- if (control.isEnabled ()) break;
- }
- }
- OS.GetSuperControl (theControl [0], theControl);
- } while (theControl [0] != 0);
- if (theControl [0] == 0) {
- theControl [0] = theRoot [0];
- Widget widget = display.getWidget (theControl [0]);
- if (widget != null && widget instanceof Control) {
- Control control = (Control) widget;
- theControl [0] = control.handle;
- }
- }
- }
- CGPoint pt = new CGPoint ();
- OS.HIViewConvertPoint (pt, theControl [0], 0);
- where.h -= (int) pt.x;
- where.v -= (int) pt.y;
- where.h -= rect.left;
- where.v -= rect.top;
- int modifiers = OS.GetCurrentEventKeyModifiers ();
- boolean [] cursorWasSet = new boolean [1];
- OS.HandleControlSetCursor (theControl [0], where, (short) modifiers, cursorWasSet);
- if (!cursorWasSet [0]) OS.SetThemeCursor (OS.kThemeArrowCursor);
-}
-
-void setDefaultFont () {
- if (display.smallFonts) setFontStyle (defaultFont ());
-}
-
-/**
- * Sets the receiver's drag detect state. If the argument is
- * <code>true</code>, the receiver will detect drag gestures,
- * otherwise these gestures will be ignored.
- *
- * @param dragDetect the new drag detect state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public void setDragDetect (boolean dragDetect) {
- checkWidget ();
- if (dragDetect) {
- state |= DRAG_DETECT;
- } else {
- state &= ~DRAG_DETECT;
- }
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- if (((state & DISABLED) == 0) == enabled) return;
- Control control = null;
- boolean fixFocus = false;
- if (!enabled) {
- if (display.focusEvent != SWT.FocusOut) {
- control = display.getFocusControl ();
- fixFocus = isFocusAncestor (control);
- }
- }
- if (enabled) {
- state &= ~DISABLED;
- } else {
- state |= DISABLED;
- }
- enableWidget (enabled);
- if (fixFocus) fixFocus (control);
-}
-
-/**
- * Causes the receiver to have the <em>keyboard focus</em>,
- * such that all keyboard events will be delivered to it. Focus
- * reassignment will respect applicable platform constraints.
- *
- * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #forceFocus
- */
-public boolean setFocus () {
- checkWidget();
- if ((style & SWT.NO_FOCUS) != 0) return false;
- return forceFocus ();
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * to the font specified by the argument, or to the default font for that
- * kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkWidget();
- if (font != null) {
- if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- this.font = font;
- setFontStyle (display.smallFonts ? (font != null ? font : defaultFont ()) : font);
- redrawWidget (handle, false);
-}
-
-void setFontStyle (Font font) {
- setFontStyle (handle, font);
-}
-
-void setFontStyle (int control, Font font) {
- ControlFontStyleRec fontStyle = new ControlFontStyleRec ();
- OS.GetControlData (control, (short) OS.kControlEntireControl, OS.kControlFontStyleTag, ControlFontStyleRec.sizeof, fontStyle, null);
- fontStyle.flags &= ~(OS.kControlUseFontMask | OS.kControlUseSizeMask | OS.kControlUseFaceMask | OS.kControlUseThemeFontIDMask);
- if (font != null) {
- short [] family = new short [1], style = new short [1];
- OS.FMGetFontFamilyInstanceFromFont (font.handle, family, style);
- fontStyle.flags |= OS.kControlUseFontMask | OS.kControlUseSizeMask | OS.kControlUseFaceMask;
- fontStyle.font = family [0];
- fontStyle.style = (short) (style [0] | font.style);
- fontStyle.size = (short) font.size;
- }
- OS.SetControlFontStyle (control, fontStyle);
-}
-
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the control
- * if the argument is null.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * </p>
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setForeground (Color color) {
- checkWidget();
- if (color != null) {
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- float[] foreground = color != null ? color.handle : null;
- if (equals (foreground, this.foreground)) return;
- this.foreground = foreground;
- setForeground (foreground);
- redrawWidget (handle, false);
-}
-
-void setForeground (float [] color) {
- setForeground (handle, color);
-}
-
-void setForeground (int control, float [] color) {
- ControlFontStyleRec fontStyle = new ControlFontStyleRec ();
- OS.GetControlData (control, (short) OS.kControlEntireControl, OS.kControlFontStyleTag, ControlFontStyleRec.sizeof, fontStyle, null);
- if (color != null) {
- fontStyle.foreColor_red = (short) (color [0] * 0xffff);
- fontStyle.foreColor_green = (short) (color [1] * 0xffff);
- fontStyle.foreColor_blue = (short) (color [2] * 0xffff);
- fontStyle.flags |= OS.kControlUseForeColorMask;
- } else {
- fontStyle.flags &= ~OS.kControlUseForeColorMask;
- }
- OS.SetControlFontStyle (control, fontStyle);
-}
-
-/**
- * Sets the layout data associated with the receiver to the argument.
- *
- * @param layoutData the new layout data for the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLayoutData (Object layoutData) {
- checkWidget();
- this.layoutData = layoutData;
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget();
- setBounds (x, y, 0, 0, true, false, true);
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @param location the new location for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (Point location) {
- checkWidget();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (location.x, location.y, 0, 0, true, false, true);
-}
-
-/**
- * Sets the receiver's pop up menu to the argument.
- * All controls may optionally have a pop up
- * menu that is displayed when the user requests one for
- * the control. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pop up
- * menu is platform specific.
- * <p>
- * Note: Disposing of a control that has a pop up menu will
- * dispose of the menu. To avoid this behavior, set the
- * menu to null before the control is disposed.
- * </p>
- *
- * @param menu the new pop up menu
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenu (Menu menu) {
- checkWidget();
- if (menu != null) {
- if (menu.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.POP_UP) == 0) {
- error (SWT.ERROR_MENU_NOT_POP_UP);
- }
- if (menu.parent != menuShell ()) {
- error (SWT.ERROR_INVALID_PARENT);
- }
- }
- this.menu = menu;
-}
-
-/**
- * Changes the parent of the widget to be the one provided if
- * the underlying operating system supports this feature.
- * Returns <code>true</code> if the parent is successfully changed.
- *
- * @param parent the new parent for the control.
- * @return <code>true</code> if the parent is changed and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * <li>ERROR_NULL_ARGUMENT - if the parent is <code>null</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean setParent (Composite parent) {
- checkWidget();
- if (parent == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (parent.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.parent == parent) return true;
- if (!isReparentable ()) return false;
- releaseParent ();
- Shell newShell = parent.getShell (), oldShell = getShell ();
- Decorations newDecorations = parent.menuShell (), oldDecorations = menuShell ();
- if (oldShell != newShell || oldDecorations != newDecorations) {
- Menu [] menus = oldShell.findMenus (this);
- fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
- }
- int topHandle = topHandle ();
- OS.HIViewAddSubview (parent.handle, topHandle);
- OS.HIViewSetVisible (topHandle, (state & HIDDEN) == 0);
- OS.HIViewSetZOrder (topHandle, OS.kHIViewZOrderBelow, 0);
- this.parent = parent;
- return true;
-}
-
-/**
- * If the argument is <code>false</code>, causes subsequent drawing
- * operations in the receiver to be ignored. No drawing of any kind
- * can occur in the receiver until the flag is set to true.
- * Graphics operations that occurred while the flag was
- * <code>false</code> are lost. When the flag is set to <code>true</code>,
- * the entire widget is marked as needing to be redrawn. Nested calls
- * to this method are stacked.
- * <p>
- * Note: This operation is a hint and may not be supported on some
- * platforms or for some widgets.
- * </p>
- *
- * @param redraw the new redraw state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #redraw(int, int, int, int, boolean)
- * @see #update()
- */
-public void setRedraw (boolean redraw) {
- checkWidget();
- if (redraw) {
- if (--drawCount == 0) {
- int topHandle = topHandle ();
- OS.HIViewSetDrawingEnabled (topHandle, true);
- invalidateVisibleRegion (topHandle);
- redrawWidget (topHandle, true);
- }
- } else {
- if (drawCount == 0) {
- int topHandle = topHandle ();
- OS.HIViewSetDrawingEnabled (topHandle, false);
- invalidateVisibleRegion (topHandle);
- }
- drawCount++;
- }
-}
-
-/**
- * Sets the shape of the control to the region specified
- * by the argument. When the argument is null, the
- * default shape of the control is restored.
- *
- * @param region the region that defines the shape of the control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setRegion (Region region) {
- checkWidget ();
- if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- this.region = region;
- OS.HIViewRegionChanged (handle, OS.kControlStructureMetaPart);
- redrawWidget (handle, true);
-}
-
-boolean setRadioSelection (boolean value){
- return false;
-}
-
-void setRelations () {
- if (parent == null) return;
- Control [] children = parent._getChildren ();
- int count = children.length;
- if (count > 1) {
- /*
- * the receiver is the last item in the list, so its predecessor will
- * be the second-last item in the list
- */
- Control child = children [count - 2];
- if (child != this) {
- child.addRelation (this);
- }
- }
-}
-
-/**
- * Sets the receiver's size to the point specified by the arguments.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (int width, int height) {
- checkWidget();
- setBounds (0, 0, Math.max (0, width), Math.max (0, height), false, true, true);
-}
-
-/**
- * Sets the receiver's size to the point specified by the argument.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause them to be
- * set to zero instead.
- * </p>
- *
- * @param size the new size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (Point size) {
- checkWidget ();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (0, 0, Math.max (0, size.x), Math.max (0, size.y), false, true, true);
-}
-
-boolean setTabGroupFocus () {
- return setTabItemFocus ();
-}
-
-boolean setTabItemFocus () {
- if (!isShowing ()) return false;
- return forceFocus ();
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
- if (display.helpWidget == this) {
- display.helpWidget = null;
- OS.HMInstallControlContentCallback (handle, 0);
- OS.HMInstallControlContentCallback (handle, display.helpProc);
- }
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget();
- if (visible) {
- if ((state & HIDDEN) == 0) return;
- state &= ~HIDDEN;
- } else {
- if ((state & HIDDEN) != 0) return;
- state |= HIDDEN;
- }
- if (visible) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the show
- * event. If this happens, just return.
- */
- sendEvent (SWT.Show);
- if (isDisposed ()) return;
- }
-
- /*
- * Feature in the Macintosh. If the receiver has focus, hiding
- * the receiver causes no control to have focus. Also, the focus
- * needs to be cleared from any TXNObject so that it stops blinking
- * the caret. The fix is to assign focus to the first ancestor
- * control that takes focus. If no control will take focus, clear
- * the focus control.
- */
- Control control = null;
- boolean fixFocus = false;
- if (!visible) {
- if (display.focusEvent != SWT.FocusOut) {
- control = display.getFocusControl ();
- fixFocus = isFocusAncestor (control);
- }
- }
- setVisible (topHandle (), visible);
- if (!visible) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the show
- * event. If this happens, just return.
- */
- sendEvent (SWT.Hide);
- if (isDisposed ()) return;
- }
- if (fixFocus) fixFocus (control);
-}
-
-void setZOrder () {
- int topHandle = topHandle ();
- int parentHandle = parent.handle;
- OS.HIViewAddSubview (parentHandle, topHandle);
- OS.HIViewSetZOrder (topHandle, OS.kHIViewZOrderBelow, 0);
- Rect inset = getInset ();
- Rect rect = new Rect ();
- rect.left = rect.right = inset.left;
- rect.top = rect.bottom = inset.top;
- OS.SetControlBounds (topHandle, rect);
-}
-
-void setZOrder (Control sibling, boolean above) {
- int siblingHandle = sibling == null ? 0 : sibling.topHandle ();
- int index = 0, siblingIndex = 0, oldNextIndex = -1;
- Control[] children = null;
- /* determine the receiver's and sibling's indexes in the parent */
- children = parent._getChildren ();
- while (index < children.length) {
- if (children [index] == this) break;
- index++;
- }
- if (sibling != null) {
- while (siblingIndex < children.length) {
- if (children [siblingIndex] == sibling) break;
- siblingIndex++;
- }
- }
- /* remove "Labeled by" relationships that will no longer be valid */
- removeRelation ();
- if (index + 1 < children.length) {
- oldNextIndex = index + 1;
- children [oldNextIndex].removeRelation ();
- }
- if (sibling != null) {
- if (above) {
- sibling.removeRelation ();
- } else {
- if (siblingIndex + 1 < children.length) {
- children [siblingIndex + 1].removeRelation ();
- }
- }
- }
- setZOrder (topHandle (), siblingHandle, above);
- /* determine the receiver's new index in the parent */
- if (sibling != null) {
- if (above) {
- index = siblingIndex - (index < siblingIndex ? 1 : 0);
- } else {
- index = siblingIndex + (siblingIndex < index ? 1 : 0);
- }
- } else {
- if (above) {
- index = 0;
- } else {
- index = children.length - 1;
- }
- }
-
- /* add new "Labeled by" relations as needed */
- children = parent._getChildren ();
- if (0 < index) {
- children [index - 1].addRelation (this);
- }
- if (index + 1 < children.length) {
- addRelation (children [index + 1]);
- }
- if (oldNextIndex != -1) {
- if (oldNextIndex <= index) oldNextIndex--;
- /* the last two conditions below ensure that duplicate relations are not hooked */
- if (0 < oldNextIndex && oldNextIndex != index && oldNextIndex != index + 1) {
- children [oldNextIndex - 1].addRelation (children [oldNextIndex]);
- }
- }
-}
-
-void sort (int [] items) {
- /* Shell Sort from K&R, pg 108 */
- int length = items.length;
- for (int gap=length/2; gap>0; gap/=2) {
- for (int i=gap; i<length; i++) {
- for (int j=i-gap; j>=0; j-=gap) {
- if (items [j] <= items [j + gap]) {
- int swap = items [j];
- items [j] = items [j + gap];
- items [j + gap] = swap;
- }
- }
- }
- }
-}
-
-Point textExtent (int ptr, int wHint) {
- if (ptr != 0 && OS.CFStringGetLength (ptr) > 0) {
- float [] w = new float [1], h = new float [1];
- HIThemeTextInfo info = new HIThemeTextInfo ();
- info.state = OS.kThemeStateActive;
- if (font != null) {
- short [] family = new short [1], style = new short [1];
- OS.FMGetFontFamilyInstanceFromFont (font.handle, family, style);
- OS.TextFont (family [0]);
- OS.TextFace ((short) (style [0] | font.style));
- OS.TextSize ((short) font.size);
- info.fontID = (short) OS.kThemeCurrentPortFont;
- } else {
- info.fontID = (short) defaultThemeFont ();
- }
- OS.HIThemeGetTextDimensions (ptr, wHint == SWT.DEFAULT ? 0 : wHint, info, w, h, null);
- return new Point((int) w [0], (int) h [0]);
- } else {
- Font font = getFont ();
- ATSFontMetrics metrics = new ATSFontMetrics();
- OS.ATSFontGetVerticalMetrics(font.handle, OS.kATSOptionFlagsDefault, metrics);
- OS.ATSFontGetHorizontalMetrics(font.handle, OS.kATSOptionFlagsDefault, metrics);
- return new Point(0, (int)(0.5f + (metrics.ascent -metrics.descent + metrics.leading) * font.size));
- }
-}
-
-Point textExtent(char[] chars, int wHint) {
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, chars, chars.length);
- Point result = textExtent (ptr, wHint);
- if (ptr != 0) OS.CFRelease (ptr);
- return result;
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in display relative coordinates,
- * to coordinates relative to the receiver.
- * <p>
- * @param x the x coordinate to be translated
- * @param y the y coordinate to be translated
- * @return the translated coordinates
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public Point toControl (int x, int y) {
- checkWidget();
- Rect rect = new Rect ();
- int window = OS.GetControlOwner (handle);
- CGPoint pt = new CGPoint ();
- OS.HIViewConvertPoint (pt, handle, 0);
- x -= (int) pt.x;
- y -= (int) pt.y;
- OS.GetWindowBounds (window, (short) OS.kWindowStructureRgn, rect);
- x -= rect.left;
- y -= rect.top;
- Rect inset = getInset ();
- x += inset.left;
- y += inset.top;
- return new Point (x, y);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in display relative coordinates,
- * to coordinates relative to the receiver.
- * <p>
- * @param point the point to be translated (must not be null)
- * @return the translated coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point toControl (Point point) {
- checkWidget();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return toControl (point.x, point.y);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in coordinates relative to
- * the receiver, to display relative coordinates.
- * <p>
- * @param x the x coordinate to be translated
- * @param y the y coordinate to be translated
- * @return the translated coordinates
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public Point toDisplay (int x, int y) {
- checkWidget();
- Rect rect = new Rect ();
- int window = OS.GetControlOwner (handle);
- CGPoint pt = new CGPoint ();
- OS.HIViewConvertPoint (pt, handle, 0);
- x += (int) pt.x;
- y += (int) pt.y;
- OS.GetWindowBounds (window, (short) OS.kWindowStructureRgn, rect);
- x += rect.left;
- y += rect.top;
- Rect inset = getInset ();
- x -= inset.left;
- y -= inset.top;
- return new Point (x, y);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in coordinates relative to
- * the receiver, to display relative coordinates.
- * <p>
- * @param point the point to be translated (must not be null)
- * @return the translated coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point toDisplay (Point point) {
- checkWidget();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return toDisplay (point.x, point.y);
-}
-
-int topHandle () {
- return handle;
-}
-
-boolean translateTraversal (int key, int theEvent, boolean [] consume) {
- int detail = SWT.TRAVERSE_NONE;
- int code = traversalCode (key, theEvent);
- boolean all = false;
- switch (key) {
- case 53: /* Esc */ {
- all = true;
- detail = SWT.TRAVERSE_ESCAPE;
- break;
- }
- case 76: /* KP Enter */
- case 36: /* Return */ {
- all = true;
- detail = SWT.TRAVERSE_RETURN;
- break;
- }
- case 48: /* Tab */ {
- int [] modifiers = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
- boolean next = (modifiers [0] & OS.shiftKey) == 0;
- detail = next ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS;
- break;
- }
- case 126: /* Up arrow */
- case 123: /* Left arrow */
- case 125: /* Down arrow */
- case 124: /* Right arrow */ {
- boolean next = key == 125 /* Down arrow */ || key == 124 /* Right arrow */;
- detail = next ? SWT.TRAVERSE_ARROW_NEXT : SWT.TRAVERSE_ARROW_PREVIOUS;
- break;
- }
- case 116: /* Page up */
- case 121: /* Page down */ {
- all = true;
- int [] modifiers = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
- if ((modifiers [0] & OS.controlKey) == 0) return false;
- detail = key == 121 /* Page down */ ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS;
- break;
- }
- default:
- return false;
- }
- Event event = new Event ();
- event.doit = consume [0] = (code & detail) != 0;
- event.detail = detail;
- if (!setKeyState (event, SWT.Traverse, theEvent)) return false;
- Shell shell = getShell ();
- Control control = this;
- do {
- if (control.traverse (event)) return true;
- if (!event.doit && control.hooks (SWT.Traverse)) {
- return false;
- }
- if (control == shell) return false;
- control = control.parent;
- } while (all && control != null);
- return false;
-}
-
-int traversalCode (int key, int theEvent) {
- int code = SWT.TRAVERSE_RETURN | SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS;
- Shell shell = getShell ();
- if (shell.parent != null) code |= SWT.TRAVERSE_ESCAPE;
- return code;
-}
-
-boolean traverseMnemonic (char key) {
- return false;
-}
-
-/**
- * Based on the argument, perform one of the expected platform
- * traversal action. The argument should be one of the constants:
- * <code>SWT.TRAVERSE_ESCAPE</code>, <code>SWT.TRAVERSE_RETURN</code>,
- * <code>SWT.TRAVERSE_TAB_NEXT</code>, <code>SWT.TRAVERSE_TAB_PREVIOUS</code>,
- * <code>SWT.TRAVERSE_ARROW_NEXT</code> and <code>SWT.TRAVERSE_ARROW_PREVIOUS</code>.
- *
- * @param traversal the type of traversal
- * @return true if the traversal succeeded
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean traverse (int traversal) {
- checkWidget();
- Event event = new Event ();
- event.doit = true;
- event.detail = traversal;
- return traverse (event);
-}
-
-boolean traverse (Event event) {
- sendEvent (SWT.Traverse, event);
- if (isDisposed ()) return true;
- if (!event.doit) return false;
- switch (event.detail) {
- case SWT.TRAVERSE_NONE: return true;
- case SWT.TRAVERSE_ESCAPE: return traverseEscape ();
- case SWT.TRAVERSE_RETURN: return traverseReturn ();
- case SWT.TRAVERSE_TAB_NEXT: return traverseGroup (true);
- case SWT.TRAVERSE_TAB_PREVIOUS: return traverseGroup (false);
- case SWT.TRAVERSE_ARROW_NEXT: return traverseItem (true);
- case SWT.TRAVERSE_ARROW_PREVIOUS: return traverseItem (false);
- case SWT.TRAVERSE_MNEMONIC: return traverseMnemonic (event);
- case SWT.TRAVERSE_PAGE_NEXT: return traversePage (true);
- case SWT.TRAVERSE_PAGE_PREVIOUS: return traversePage (false);
- }
- return false;
-}
-
-boolean traverseEscape () {
- return false;
-}
-
-boolean traverseGroup (boolean next) {
- Control root = computeTabRoot ();
- Control group = computeTabGroup ();
- Control [] list = root.computeTabList ();
- int length = list.length;
- int index = 0;
- while (index < length) {
- if (list [index] == group) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- if (index == length) return false;
- int start = index, offset = (next) ? 1 : -1;
- while ((index = ((index + offset + length) % length)) != start) {
- Control control = list [index];
- if (!control.isDisposed () && control.setTabGroupFocus ()) {
- return true;
- }
- }
- if (group.isDisposed ()) return false;
- return group.setTabGroupFocus ();
-}
-
-boolean traverseItem (boolean next) {
- Control [] children = parent._getChildren ();
- int length = children.length;
- int index = 0;
- while (index < length) {
- if (children [index] == this) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- if (index == length) return false;
- int start = index, offset = (next) ? 1 : -1;
- while ((index = (index + offset + length) % length) != start) {
- Control child = children [index];
- if (!child.isDisposed () && child.isTabItem ()) {
- if (child.setTabItemFocus ()) return true;
- }
- }
- return false;
-}
-
-boolean traverseReturn () {
- return false;
-}
-
-boolean traversePage (boolean next) {
- return false;
-}
-
-boolean traverseMnemonic (Event event) {
- return false;
-}
-
-/**
- * Forces all outstanding paint requests for the widget
- * to be processed before this method returns. If there
- * are no outstanding paint request, this method does
- * nothing.
- * <p>
- * Note: This method does not cause a redraw.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #redraw()
- * @see #redraw(int, int, int, int, boolean)
- * @see PaintListener
- * @see SWT#Paint
- */
-public void update () {
- checkWidget();
- update (false);
-}
-
-void update (boolean all) {
-// checkWidget();
- //TODO - not all
- if (display.inPaint) return;
- OS.HIViewRender (handle);
- if (isDisposed()) return;
- OS.HIWindowFlush (OS.GetControlOwner (handle));
-}
-
-void updateBackgroundMode () {
- int oldState = state & PARENT_BACKGROUND;
- checkBackground ();
- if (oldState != (state & PARENT_BACKGROUND)) {
- setBackground ();
- }
-}
-
-void updateLayout (boolean all) {
- /* Do nothing */
-}
-
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/DateTime.java
deleted file mode 100644
index cc34412220..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/DateTime.java
+++ /dev/null
@@ -1,949 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import java.text.DateFormatSymbols;
-import java.util.Calendar;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.carbon.LongDateRec;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.Rect;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify date
- * or time values.
- * <p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>DATE, TIME, CALENDAR, SHORT, MEDIUM, LONG, DROP_DOWN</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles DATE, TIME, or CALENDAR may be specified,
- * and only one of the styles SHORT, MEDIUM, or LONG may be specified.
- * The DROP_DOWN style is a <em>HINT</em>, and it is only valid with the DATE style.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#datetime">DateTime snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.3
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class DateTime extends Composite {
- LongDateRec dateRec;
- LongDateRec dateAndTime = new LongDateRec (); // copy of date for a kControlClockTypeHourMinuteSecond or time for a kControlClockTypeMonthDayYear
-
- static final int MIN_YEAR = 1752; // Gregorian switchover in North America: September 19, 1752
- static final int MAX_YEAR = 9999;
-
- /* Emulated Calendar variables */
- Color fg, bg;
- Calendar calendar;
- DateFormatSymbols formatSymbols;
- Button monthDown, monthUp, yearDown, yearUp;
- static final int MARGIN_WIDTH = 2;
- static final int MARGIN_HEIGHT = 1;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DATE
- * @see SWT#TIME
- * @see SWT#CALENDAR
- * @see SWT#SHORT
- * @see SWT#MEDIUM
- * @see SWT#LONG
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public DateTime (Composite parent, int style) {
- super (parent, checkStyle (style) | ((style & SWT.CALENDAR) != 0 ? SWT.NO_REDRAW_RESIZE : 0));
- if ((this.style & SWT.CALENDAR) != 0) {
- calendar = Calendar.getInstance();
- formatSymbols = new DateFormatSymbols();
-
- Listener listener = new Listener() {
- public void handleEvent(Event event) {
- switch(event.type) {
- case SWT.Paint: handlePaint(event); break;
- case SWT.Resize: handleResize(event); break;
- case SWT.MouseDown: handleMouseDown(event); break;
- case SWT.KeyDown: handleKeyDown(event); break;
- case SWT.Traverse: handleTraverse(event); break;
- }
- }
- };
- addListener(SWT.Paint, listener);
- addListener(SWT.Resize, listener);
- addListener(SWT.MouseDown, listener);
- addListener(SWT.KeyDown, listener);
- addListener(SWT.Traverse, listener);
- yearDown = new Button(this, SWT.ARROW | SWT.LEFT);
- //yearDown.setToolTipText(SWT.getMessage ("SWT_Last_Year")); //$NON-NLS-1$
- monthDown = new Button(this, SWT.ARROW | SWT.LEFT);
- //monthDown.setToolTipText(SWT.getMessage ("SWT_Last_Month")); //$NON-NLS-1$
- monthUp = new Button(this, SWT.ARROW | SWT.RIGHT);
- //monthUp.setToolTipText(SWT.getMessage ("SWT_Next_Month")); //$NON-NLS-1$
- yearUp = new Button(this, SWT.ARROW | SWT.RIGHT);
- //yearUp.setToolTipText(SWT.getMessage ("SWT_Next_Year")); //$NON-NLS-1$
- listener = new Listener() {
- public void handleEvent(Event event) {
- handleSelection(event);
- }
- };
- yearDown.addListener(SWT.Selection, listener);
- monthDown.addListener(SWT.Selection, listener);
- monthUp.addListener(SWT.Selection, listener);
- yearUp.addListener(SWT.Selection, listener);
- }
-}
-
-static int checkStyle (int style) {
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- style &= ~(SWT.H_SCROLL | SWT.V_SCROLL);
- style = checkBits (style, SWT.MEDIUM, SWT.SHORT, SWT.LONG, 0, 0, 0);
- return checkBits (style, SWT.DATE, SWT.TIME, SWT.CALENDAR, 0, 0, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the control's value.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0;
- if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
- if ((style & SWT.CALENDAR) != 0) {
- Point cellSize = getCellSize(null);
- Point buttonSize = monthDown.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
- width = cellSize.x * 7;
- height = cellSize.y * 7 + Math.max(cellSize.y, buttonSize.y);
- } else {
- Rect rect = new Rect ();
- OS.GetBestControlRect (handle, rect, null);
- width = rect.right - rect.left;
- height = rect.bottom - rect.top;
- }
- }
- if (width == 0) width = DEFAULT_WIDTH;
- if (height == 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2; height += border * 2;
- return new Point (width, height);
-}
-
-void createHandle () {
- int clockType = -1;
- if ((style & SWT.TIME) != 0) clockType = (style & SWT.SHORT) != 0 ? OS.kControlClockTypeHourMinute : OS.kControlClockTypeHourMinuteSecond;
- if ((style & SWT.DATE) != 0) clockType = (style & SWT.SHORT) != 0 ? OS.kControlClockTypeMonthYear : OS.kControlClockTypeMonthDayYear;
- if (clockType != -1) { /* SWT.DATE and SWT.TIME */
- int clockFlags = OS.kControlClockFlagStandard;
- int [] outControl = new int [1];
- int window = OS.GetControlOwner (parent.handle);
- OS.CreateClockControl(window, null, clockType, clockFlags, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
- } else { /* SWT.CALENDAR */
- super.createHandle();
- }
-}
-
-void createWidget() {
- super.createWidget ();
- getDate();
-}
-
-void drawDay(GC gc, Point cellSize, int day) {
- int cell = getCell(day);
- Point location = getCellLocation(cell, cellSize);
- String str = String.valueOf(day);
- Point extent = gc.stringExtent(str);
- int date = calendar.get(Calendar.DAY_OF_MONTH);
- if (day == date) {
- Display display = getDisplay();
- gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_SELECTION));
- gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
- gc.fillRectangle(location.x, location.y, cellSize.x, cellSize.y);
- }
- gc.drawString(str, location.x + (cellSize.x - extent.x) / 2, location.y + (cellSize.y - extent.y) / 2, true);
- if (day == date) {
- gc.setBackground(getBackground());
- gc.setForeground(getForeground());
- }
-}
-
-void drawDays(GC gc, Point cellSize, Rectangle client) {
- gc.setBackground(getBackground());
- gc.setForeground(getForeground());
- gc.fillRectangle(0, cellSize.y, client.width, cellSize.y * 7);
- int firstDay = calendar.getActualMinimum(Calendar.DAY_OF_MONTH);
- int lastDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
- for (int day = firstDay; day <= lastDay; day++) {
- drawDay(gc, cellSize, day);
- }
-}
-
-void drawDaysOfWeek(GC gc, Point cellSize, Rectangle client) {
- Display display = getDisplay();
- gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
- gc.fillRectangle(0, 0, client.width, cellSize.y);
- String[] days = formatSymbols.getShortWeekdays();
- int x = 0, y = 0;
- for (int i = 1; i < days.length; i++) {
- String day = days[i];
- Point extent = gc.stringExtent(day);
- gc.drawString(day, x + (cellSize.x - extent.x) / 2, y + (cellSize.y - extent.y) / 2, true);
- x += cellSize.x;
- }
- gc.drawLine(0, cellSize.y - 1, client.width, cellSize.y - 1);
-}
-
-void drawMonth(GC gc, Point cellSize, Rectangle client) {
- Display display = getDisplay();
- gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
- int y = cellSize.y * 7;
- gc.fillRectangle(0, y, client.width, cellSize.y);
- gc.drawLine(0, y - 1, client.width, y - 1);
- String str = formatSymbols.getShortMonths()[calendar.get(Calendar.MONTH)] + ", " + calendar.get(Calendar.YEAR);
- Point extent = gc.stringExtent(str);
- gc.drawString(str, (cellSize.x * 7 - extent.x) / 2, y + (cellSize.y - extent.y) / 2, true);
-}
-
-void handleKeyDown(Event event) {
- int newDay = calendar.get(Calendar.DAY_OF_MONTH);
- switch (event.keyCode) {
- case SWT.ARROW_DOWN: newDay += 7; break;
- case SWT.ARROW_UP: newDay -= 7; break;
- case SWT.ARROW_RIGHT: newDay += 1; break;
- case SWT.ARROW_LEFT: newDay -= 1; break;
- }
- setDay(newDay, true);
-}
-
-void handleMouseDown(Event event) {
- setFocus();
- Point cellSize = getCellSize(null);
- int column = event.x / cellSize.x;
- int row = event.y / cellSize.y;
- int cell = row * 7 + column;
- int newDay = getDate(cell);
- setDay(newDay, true);
-}
-
-void handlePaint(Event event) {
- GC gc = event.gc;
- Rectangle client = getClientArea();
- Point cellSize = getCellSize(gc);
- drawDaysOfWeek(gc, cellSize, client);
- drawDays(gc, cellSize, client);
- drawMonth(gc, cellSize, client);
-}
-
-void handleResize(Event event) {
- yearDown.pack();
- monthDown.pack();
- monthUp.pack();
- yearUp.pack();
- Point cellSize = getCellSize(null);
- Point size = monthDown.getSize();
- int height = Math.max(cellSize.y, size.y);
- int y = cellSize.y * 7 + (height - size.y) / 2;
- yearDown.setLocation(0, y);
- monthDown.setLocation(size.x, y);
- int x = cellSize.x * 7 - size.x;
- monthUp.setLocation(x - size.x, y);
- yearUp.setLocation(x, y);
-}
-
-void handleSelection(Event event) {
- if (event.widget == monthDown) {
- calendar.add(Calendar.MONTH, -1);
- } else if (event.widget == monthUp) {
- calendar.add(Calendar.MONTH, 1);
- } else if (event.widget == yearDown) {
- calendar.add(Calendar.YEAR, -1);
- } else if (event.widget == yearUp) {
- calendar.add(Calendar.YEAR, 1);
- } else {
- return;
- }
- redraw();
- postEvent(SWT.Selection);
-}
-
-void handleTraverse(Event event) {
- switch (event.detail) {
- case SWT.TRAVERSE_ESCAPE:
- case SWT.TRAVERSE_PAGE_NEXT:
- case SWT.TRAVERSE_PAGE_PREVIOUS:
- case SWT.TRAVERSE_RETURN:
- case SWT.TRAVERSE_TAB_NEXT:
- case SWT.TRAVERSE_TAB_PREVIOUS:
- event.doit = true;
- break;
- }
-}
-
-Point getCellSize(GC gc) {
- boolean dispose = gc == null;
- if (gc == null) gc = new GC(this);
- int width = 0, height = 0;
- String[] days = formatSymbols.getShortWeekdays();
- for (int i = 0; i < days.length; i++) {
- Point extent = gc.stringExtent(days[i]);
- width = Math.max(width, extent.x);
- height = Math.max(height, extent.y);
- }
- int firstDay = calendar.getMinimum(Calendar.DAY_OF_MONTH);
- int lastDay = calendar.getMaximum(Calendar.DAY_OF_MONTH);
- for (int day = firstDay; day <= lastDay; day++) {
- Point extent = gc.stringExtent(String.valueOf(day));
- width = Math.max(width, extent.x);
- height = Math.max(height, extent.y);
- }
- if (dispose) gc.dispose();
- return new Point(width + MARGIN_WIDTH * 2, height + MARGIN_HEIGHT * 2);
-}
-
-Point getCellLocation(int cell, Point cellSize) {
- return new Point(cell % 7 * cellSize.x, cell / 7 * cellSize.y);
-}
-
-int getCell(int date) {
- int day = calendar.get(Calendar.DAY_OF_MONTH);
- calendar.set(Calendar.DAY_OF_MONTH, 1);
- int result = date + calendar.get(Calendar.DAY_OF_WEEK) + 5;
- calendar.set(Calendar.DAY_OF_MONTH, day);
- return result;
-}
-
-void getDate() {
- dateRec = new LongDateRec ();
- OS.GetControlData (handle, (short)OS.kControlEntireControl, OS.kControlClockLongDateTag, LongDateRec.sizeof, dateRec, null);
-}
-
-int getDate(int cell) {
- int day = calendar.get(Calendar.DAY_OF_MONTH);
- calendar.set(Calendar.DAY_OF_MONTH, 1);
- int result = cell - calendar.get(Calendar.DAY_OF_WEEK) - 5;
- calendar.set(Calendar.DAY_OF_MONTH, day);
- return result;
-}
-
-public Color getBackground() {
- checkWidget();
- if (bg == null) {
- return getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
- }
- return bg;
-}
-
-public Color getForeground() {
- checkWidget();
- if (fg == null) {
- return getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
- }
- return fg;
-}
-
-/**
- * Returns the receiver's date, or day of the month.
- * <p>
- * The first day of the month is 1, and the last day depends on the month and year.
- * </p>
- *
- * @return a positive integer beginning with 1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getDay () {
- checkWidget ();
- if ((style & SWT.TIME) != 0) return dateAndTime.day;
- if ((style & SWT.CALENDAR) != 0) {
- return calendar.get(Calendar.DAY_OF_MONTH);
- }
- getDate();
- return dateRec.day;
-}
-
-/**
- * Returns the receiver's hours.
- * <p>
- * Hours is an integer between 0 and 23.
- * </p>
- *
- * @return an integer between 0 and 23
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getHours () {
- checkWidget ();
- if ((style & SWT.DATE) != 0) return dateAndTime.hour;
- if ((style & SWT.CALENDAR) != 0) {
- return calendar.get(Calendar.HOUR_OF_DAY);
- }
- getDate();
- return dateRec.hour;
-}
-
-/**
- * Returns the receiver's minutes.
- * <p>
- * Minutes is an integer between 0 and 59.
- * </p>
- *
- * @return an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinutes () {
- checkWidget ();
- if ((style & SWT.DATE) != 0) return dateAndTime.minute;
- if ((style & SWT.CALENDAR) != 0) {
- return calendar.get(Calendar.MINUTE);
- }
- getDate();
- return dateRec.minute;
-}
-
-/**
- * Returns the receiver's month.
- * <p>
- * The first month of the year is 0, and the last month is 11.
- * </p>
- *
- * @return an integer between 0 and 11
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMonth () {
- checkWidget ();
- if ((style & SWT.TIME) != 0) return dateAndTime.month - 1;
- if ((style & SWT.CALENDAR) != 0) {
- return calendar.get(Calendar.MONTH);
- }
- getDate();
- return dateRec.month - 1;
-}
-
-String getNameText() {
- return (style & SWT.TIME) != 0 ? getHours() + ":" + getMinutes() + ":" + getSeconds()
- : (getMonth() + 1) + "/" + getDay() + "/" + getYear();
-}
-
-/**
- * Returns the receiver's seconds.
- * <p>
- * Seconds is an integer between 0 and 59.
- * </p>
- *
- * @return an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSeconds () {
- checkWidget ();
- if ((style & SWT.DATE) != 0) return dateAndTime.second;
- if ((style & SWT.CALENDAR) != 0) {
- return calendar.get(Calendar.SECOND);
- }
- getDate();
- return dateRec.second;
-}
-
-/**
- * Returns the receiver's year.
- * <p>
- * The first year is 1752 and the last year is 9999.
- * </p>
- *
- * @return an integer between 1752 and 9999
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getYear () {
- checkWidget ();
- if ((style & SWT.TIME) != 0) return dateAndTime.year;
- if ((style & SWT.CALENDAR) != 0) {
- return calendar.get(Calendar.YEAR);
- }
- getDate();
- return dateRec.year;
-}
-
-void hookEvents () {
- super.hookEvents ();
- if (OS.VERSION >= 0x1040) {
- int clockProc = display.clockProc;
- int [] mask = new int [] {
- OS.kEventClassClockView, OS.kEventClockDateOrTimeChanged,
- };
- int controlTarget = OS.GetControlEventTarget (handle);
- OS.InstallEventHandler (controlTarget, clockProc, mask.length / 2, mask, handle, null);
- }
-}
-
-boolean isValidTime(int fieldName, int value) {
- Calendar calendar = Calendar.getInstance();
- int min = calendar.getActualMinimum(fieldName);
- int max = calendar.getActualMaximum(fieldName);
- return value >= min && value <= max;
-}
-
-boolean isValidDate(int year, int month, int day) {
- if (year < MIN_YEAR || year > MAX_YEAR) return false;
- Calendar calendar = Calendar.getInstance();
- calendar.set(year, month, day);
- return calendar.get(Calendar.YEAR) == year
- && calendar.get(Calendar.MONTH) == month
- && calendar.get(Calendar.DAY_OF_MONTH) == day;
-}
-
-int kEventClockDateOrTimeChanged (int nextHandler, int theEvent, int userData) {
- sendSelectionEvent ();
- return OS.noErr;
-}
-
-int kEventControlHit (int nextHandler, int theEvent, int userData) {
- int result = super.kEventControlHit (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- if (OS.VERSION < 0x1040) sendSelectionEvent ();
- return result;
-}
-
-int kEventTextInputUnicodeForKeyEvent (int nextHandler, int theEvent, int userData) {
- int result = super.kEventTextInputUnicodeForKeyEvent (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- if (OS.VERSION < 0x1040) sendSelectionEvent ();
- return result;
-}
-
-boolean pollTrackEvent() {
- return ((style & SWT.DATE) != 0) || ((style & SWT.TIME) != 0);
-}
-
-void redraw(int cell, Point cellSize) {
- Point location = getCellLocation(cell, cellSize);
- redraw(location.x, location.y, cellSize.x, cellSize.y, false);
-}
-
-void releaseWidget () {
- super.releaseWidget();
- dateRec = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection, listener);
-}
-
-void sendSelectionEvent () {
- LongDateRec rec = new LongDateRec ();
- OS.GetControlData (handle, (short)OS.kControlEntireControl, OS.kControlClockLongDateTag, LongDateRec.sizeof, rec, null);
- if (rec.second != dateRec.second ||
- rec.minute != dateRec.minute ||
- rec.hour != dateRec.hour ||
- rec.day != dateRec.day ||
- rec.month != dateRec.month ||
- rec.year != dateRec.year) {
- dateRec = rec;
- postEvent (SWT.Selection);
- }
-}
-
-public void setBackground(Color color) {
- checkWidget();
- super.setBackground(color);
- bg = color;
-}
-
-public void setForeground(Color color) {
- checkWidget();
- super.setForeground(color);
- fg = color;
-}
-
-void setDay(int newDay, boolean notify) {
- int firstDay = calendar.getActualMinimum(Calendar.DAY_OF_MONTH);
- int lastDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
- if (!(firstDay <= newDay && newDay <= lastDay)) return;
- Point cellSize = getCellSize(null);
- redraw(getCell(calendar.get(Calendar.DAY_OF_MONTH)), cellSize);
- calendar.set(Calendar.DAY_OF_MONTH, newDay);
- redraw(getCell(calendar.get(Calendar.DAY_OF_MONTH)), cellSize);
- if (notify) postEvent(SWT.Selection);
-}
-
-/**
- * Sets the receiver's year, month, and day in a single operation.
- * <p>
- * This is the recommended way to set the date, because setting the year,
- * month, and day separately may result in invalid intermediate dates.
- * </p>
- *
- * @param year an integer between 1752 and 9999
- * @param month an integer between 0 and 11
- * @param day a positive integer beginning with 1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setDate (int year, int month, int day) {
- checkWidget ();
- if (!isValidDate(year, month, day)) return;
- if ((style & SWT.CALENDAR) != 0) {
- calendar.set(Calendar.YEAR, year);
- calendar.set(Calendar.DAY_OF_MONTH, 1);
- calendar.set(Calendar.MONTH, month);
- redraw();
- setDay(day, false);
- } else {
- dateRec.year = (short)year;
- dateRec.month = (short)(month + 1);
- dateRec.day = (short)day;
- OS.SetControlData (handle, (short)OS.kControlEntireControl, OS.kControlClockLongDateTag, LongDateRec.sizeof, dateRec);
- OS.GetControlData (handle, (short)OS.kControlEntireControl, OS.kControlClockLongDateTag, LongDateRec.sizeof, dateRec, null);
- redraw();
- if ((style & SWT.TIME) != 0) {
- dateAndTime.year = (short)year;
- dateAndTime.month = (short)(month + 1);
- dateAndTime.day = (short)day;
- }
- }
-}
-
-/**
- * Sets the receiver's date, or day of the month, to the specified day.
- * <p>
- * The first day of the month is 1, and the last day depends on the month and year.
- * If the specified day is not valid for the receiver's month and year, then it is ignored.
- * </p>
- *
- * @param day a positive integer beginning with 1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDate
- */
-public void setDay (int day) {
- checkWidget ();
- if (!isValidDate(getYear(), getMonth(), day)) return;
- if ((style & SWT.CALENDAR) != 0) {
- setDay(day, false);
- } else {
- dateRec.day = (short)day;
- OS.SetControlData (handle, (short)OS.kControlEntireControl, OS.kControlClockLongDateTag, LongDateRec.sizeof, dateRec);
- OS.GetControlData (handle, (short)OS.kControlEntireControl, OS.kControlClockLongDateTag, LongDateRec.sizeof, dateRec, null);
- if ((style & SWT.TIME) != 0) dateAndTime.day = (short)day;
- redraw();
- }
-}
-
-/**
- * Sets the receiver's hours.
- * <p>
- * Hours is an integer between 0 and 23.
- * </p>
- *
- * @param hours an integer between 0 and 23
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHours (int hours) {
- checkWidget ();
- if (!isValidTime(Calendar.HOUR_OF_DAY, hours)) return;
- if ((style & SWT.CALENDAR) != 0) {
- calendar.set(Calendar.HOUR_OF_DAY, hours);
- } else {
- dateRec.hour = (short)hours;
- OS.SetControlData (handle, (short)OS.kControlEntireControl, OS.kControlClockLongDateTag, LongDateRec.sizeof, dateRec);
- OS.GetControlData (handle, (short)OS.kControlEntireControl, OS.kControlClockLongDateTag, LongDateRec.sizeof, dateRec, null);
- if ((style & SWT.DATE) != 0) dateAndTime.hour = (short)hours;
- }
- redraw();
-}
-
-/**
- * Sets the receiver's minutes.
- * <p>
- * Minutes is an integer between 0 and 59.
- * </p>
- *
- * @param minutes an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinutes (int minutes) {
- checkWidget ();
- if (!isValidTime(Calendar.MINUTE, minutes)) return;
- if ((style & SWT.CALENDAR) != 0) {
- calendar.set(Calendar.MINUTE, minutes);
- } else {
- dateRec.minute = (short)minutes;
- OS.SetControlData (handle, (short)OS.kControlEntireControl, OS.kControlClockLongDateTag, LongDateRec.sizeof, dateRec);
- OS.GetControlData (handle, (short)OS.kControlEntireControl, OS.kControlClockLongDateTag, LongDateRec.sizeof, dateRec, null);
- if ((style & SWT.DATE) != 0) dateAndTime.minute = (short)minutes;
- }
- redraw();
-}
-
-/**
- * Sets the receiver's month.
- * <p>
- * The first month of the year is 0, and the last month is 11.
- * If the specified month is not valid for the receiver's day and year, then it is ignored.
- * </p>
- *
- * @param month an integer between 0 and 11
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDate
- */
-public void setMonth (int month) {
- checkWidget ();
- if (!isValidDate(getYear(), month, getDay())) return;
- if ((style & SWT.CALENDAR) != 0) {
- calendar.set(Calendar.MONTH, month);
- } else {
- dateRec.month = (short)(month + 1);
- OS.SetControlData (handle, (short)OS.kControlEntireControl, OS.kControlClockLongDateTag, LongDateRec.sizeof, dateRec);
- OS.GetControlData (handle, (short)OS.kControlEntireControl, OS.kControlClockLongDateTag, LongDateRec.sizeof, dateRec, null);
- if ((style & SWT.TIME) != 0) dateAndTime.month = (short)(month + 1);
- }
- redraw();
-}
-
-/**
- * Sets the receiver's seconds.
- * <p>
- * Seconds is an integer between 0 and 59.
- * </p>
- *
- * @param seconds an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSeconds (int seconds) {
- checkWidget ();
- if (!isValidTime(Calendar.SECOND, seconds)) return;
- if ((style & SWT.CALENDAR) != 0) {
- calendar.set(Calendar.SECOND, seconds);
- } else {
- dateRec.second = (short)seconds;
- OS.SetControlData (handle, (short)OS.kControlEntireControl, OS.kControlClockLongDateTag, LongDateRec.sizeof, dateRec);
- OS.GetControlData (handle, (short)OS.kControlEntireControl, OS.kControlClockLongDateTag, LongDateRec.sizeof, dateRec, null);
- if ((style & SWT.DATE) != 0) dateAndTime.second = (short)seconds;
- }
- redraw();
-}
-
-/**
- * Sets the receiver's hours, minutes, and seconds in a single operation.
- *
- * @param hours an integer between 0 and 23
- * @param minutes an integer between 0 and 59
- * @param seconds an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setTime (int hours, int minutes, int seconds) {
- checkWidget ();
- if (!isValidTime(Calendar.HOUR_OF_DAY, hours)) return;
- if (!isValidTime(Calendar.MINUTE, minutes)) return;
- if (!isValidTime(Calendar.SECOND, seconds)) return;
- if ((style & SWT.CALENDAR) != 0) {
- calendar.set(Calendar.HOUR_OF_DAY, hours);
- calendar.set(Calendar.MINUTE, minutes);
- calendar.set(Calendar.SECOND, seconds);
- } else {
- dateRec.hour = (short)hours;
- dateRec.minute = (short)minutes;
- dateRec.second = (short)seconds;
- OS.SetControlData (handle, (short)OS.kControlEntireControl, OS.kControlClockLongDateTag, LongDateRec.sizeof, dateRec);
- OS.GetControlData (handle, (short)OS.kControlEntireControl, OS.kControlClockLongDateTag, LongDateRec.sizeof, dateRec, null);
- if ((style & SWT.DATE) != 0) {
- dateAndTime.hour = (short)hours;
- dateAndTime.minute = (short)minutes;
- dateAndTime.second = (short)seconds;
- }
- }
- redraw();
-}
-
-/**
- * Sets the receiver's year.
- * <p>
- * The first year is 1752 and the last year is 9999.
- * If the specified year is not valid for the receiver's day and month, then it is ignored.
- * </p>
- *
- * @param year an integer between 1752 and 9999
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDate
- */
-public void setYear (int year) {
- checkWidget ();
- if (!isValidDate(year, getMonth(), getDay())) return;
- if ((style & SWT.CALENDAR) != 0) {
- calendar.set(Calendar.YEAR, year);
- } else {
- dateRec.year = (short)year;
- OS.SetControlData (handle, (short)OS.kControlEntireControl, OS.kControlClockLongDateTag, LongDateRec.sizeof, dateRec);
- OS.GetControlData (handle, (short)OS.kControlEntireControl, OS.kControlClockLongDateTag, LongDateRec.sizeof, dateRec, null);
- if ((style & SWT.TIME) != 0) dateAndTime.year = (short)year;
- }
- redraw();
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Decorations.java
deleted file mode 100644
index 185f0dc80b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Decorations.java
+++ /dev/null
@@ -1,687 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.OS;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide the appearance and
- * behavior of <code>Shells</code>, but are not top
- * level shells or dialogs. Class <code>Shell</code>
- * shares a significant amount of code with this class,
- * and is a subclass.
- * <p>
- * IMPORTANT: This class was intended to be abstract and
- * should <em>never</em> be referenced or instantiated.
- * Instead, the class <code>Shell</code> should be used.
- * </p>
- * <p>
- * Instances are always displayed in one of the maximized,
- * minimized or normal states:
- * <ul>
- * <li>
- * When an instance is marked as <em>maximized</em>, the
- * window manager will typically resize it to fill the
- * entire visible area of the display, and the instance
- * is usually put in a state where it can not be resized
- * (even if it has style <code>RESIZE</code>) until it is
- * no longer maximized.
- * </li><li>
- * When an instance is in the <em>normal</em> state (neither
- * maximized or minimized), its appearance is controlled by
- * the style constants which were specified when it was created
- * and the restrictions of the window manager (see below).
- * </li><li>
- * When an instance has been marked as <em>minimized</em>,
- * its contents (client area) will usually not be visible,
- * and depending on the window manager, it may be
- * "iconified" (that is, replaced on the desktop by a small
- * simplified representation of itself), relocated to a
- * distinguished area of the screen, or hidden. Combinations
- * of these changes are also possible.
- * </li>
- * </ul>
- * </p>
- * Note: The styles supported by this class must be treated
- * as <em>HINT</em>s, since the window manager for the
- * desktop on which the instance is visible has ultimate
- * control over the appearance and behavior of decorations.
- * For example, some window managers only support resizable
- * windows and will always assume the RESIZE style, even if
- * it is not set.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * Class <code>SWT</code> provides two "convenience constants"
- * for the most commonly required style combinations:
- * <dl>
- * <dt><code>SHELL_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application top level shell: (that
- * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>)
- * </dd>
- * <dt><code>DIALOG_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application dialog shell: (that
- * is, <code>TITLE | CLOSE | BORDER</code>)
- * </dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see #getMinimized
- * @see #getMaximized
- * @see Shell
- * @see SWT
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Decorations extends Canvas {
- Image image;
- Image [] images = new Image [0];
- Menu menuBar;
- String text = "";
- boolean minimized, maximized;
- Control savedFocus;
- Button defaultButton;
-
-Decorations () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#TOOL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Decorations (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- if ((style & SWT.NO_TRIM) != 0) {
- style &= ~(SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX | SWT.RESIZE | SWT.BORDER);
- }
- if ((style & (SWT.MENU | SWT.MIN | SWT.MAX | SWT.CLOSE)) != 0) {
- style |= SWT.TITLE;
- }
- return style;
-}
-
-void bringToTop (boolean force) {
- moveAbove (null);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-int compare (ImageData data1, ImageData data2) {
- if (data1.width == data2.width && data1.height == data2.height) {
- int transparent1 = data1.getTransparencyType ();
- int transparent2 = data2.getTransparencyType ();
- if (transparent1 == SWT.TRANSPARENCY_ALPHA) return -1;
- if (transparent2 == SWT.TRANSPARENCY_ALPHA) return 1;
- if (transparent1 == SWT.TRANSPARENCY_MASK) return -1;
- if (transparent2 == SWT.TRANSPARENCY_MASK) return 1;
- if (transparent1 == SWT.TRANSPARENCY_PIXEL) return -1;
- if (transparent2 == SWT.TRANSPARENCY_PIXEL) return 1;
- return 0;
- }
- return data1.width > data2.width || data1.height > data2.height ? -1 : 1;
-}
-
-Control computeTabGroup () {
- return this;
-}
-
-Control computeTabRoot () {
- return this;
-}
-
-void fixDecorations (Decorations newDecorations, Control control, Menu [] menus) {
- if (this == newDecorations) return;
- if (control == savedFocus) savedFocus = null;
- if (control == defaultButton) defaultButton = null;
- if (menus == null) return;
- Menu menu = control.menu;
- if (menu != null) {
- int index = 0;
- while (index < menus.length) {
- if (menus [index] == menu) {
- control.setMenu (null);
- return;
- }
- index++;
- }
- menu.fixMenus (newDecorations);
- }
-}
-
-/**
- * Returns the receiver's default button if one had
- * previously been set, otherwise returns null.
- *
- * @return the default button or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDefaultButton(Button)
- */
-public Button getDefaultButton () {
- checkWidget();
- return defaultButton;
-}
-
-/**
- * Returns the receiver's image if it had previously been
- * set using <code>setImage()</code>. The image is typically
- * displayed by the window manager when the instance is
- * marked as iconified, and may also be displayed somewhere
- * in the trim when the instance is in normal or maximized
- * states.
- * <p>
- * Note: This method will return null if called before
- * <code>setImage()</code> is called. It does not provide
- * access to a window manager provided, "default" image
- * even if one exists.
- * </p>
- *
- * @return the image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-
-/**
- * Returns the receiver's images if they had previously been
- * set using <code>setImages()</code>. Images are typically
- * displayed by the window manager when the instance is
- * marked as iconified, and may also be displayed somewhere
- * in the trim when the instance is in normal or maximized
- * states. Depending where the icon is displayed, the platform
- * chooses the icon with the "best" attributes. It is expected
- * that the array will contain the same icon rendered at different
- * sizes, with different depth and transparency attributes.
- *
- * <p>
- * Note: This method will return an empty array if called before
- * <code>setImages()</code> is called. It does not provide
- * access to a window manager provided, "default" image
- * even if one exists.
- * </p>
- *
- * @return the images
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Image [] getImages () {
- checkWidget ();
- if (images == null) return new Image [0];
- Image [] result = new Image [images.length];
- System.arraycopy (images, 0, result, 0, images.length);
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver is currently
- * maximized, and false otherwise.
- * <p>
- *
- * @return the maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMaximized
- */
-public boolean getMaximized () {
- checkWidget();
- return maximized;
-}
-
-/**
- * Returns the receiver's menu bar if one had previously
- * been set, otherwise returns null.
- *
- * @return the menu bar or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenuBar () {
- checkWidget();
- return menuBar;
-}
-
-/**
- * Returns <code>true</code> if the receiver is currently
- * minimized, and false otherwise.
- * <p>
- *
- * @return the minimized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMinimized
- */
-public boolean getMinimized () {
- checkWidget();
- return minimized;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which is the string that the
- * window manager will typically display as the receiver's
- * <em>title</em>. If the text has not previously been set,
- * returns an empty string.
- *
- * @return the text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- return text;
-}
-
-public boolean isReparentable () {
- checkWidget();
- return false;
-}
-
-boolean isTabGroup () {
- return true;
-}
-
-boolean isTabItem () {
- return false;
-}
-
-Decorations menuShell () {
- return this;
-}
-
-void releaseChildren (boolean destroy) {
- if (menuBar != null) {
- menuBar.dispose ();
- menuBar = null;
- }
- Display display = this.display;
- super.releaseChildren (destroy);
- Menu [] menus = display.getMenus (this);
- if (menus != null) {
- for (int i=0; i<menus.length; i++) {
- Menu menu = menus [i];
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- }
- menus = null;
- }
-}
-void releaseWidget () {
- super.releaseWidget ();
- image = null;
- images = null;
- savedFocus = null;
- defaultButton = null;
-}
-
-boolean restoreFocus () {
- if (savedFocus != null && savedFocus.isDisposed ()) savedFocus = null;
- if (savedFocus == null) return false;
- return savedFocus.forceFocus ();
-}
-
-void saveFocus () {
- int window = OS.GetControlOwner (handle);
- Control control = display.getFocusControl (window, false);
- if (control != null && control != this && this == control.menuShell ()) {
- setSavedFocus (control);
- }
-}
-
-/**
- * If the argument is not null, sets the receiver's default
- * button to the argument, and if the argument is null, sets
- * the receiver's default button to the first button which
- * was set as the receiver's default button (called the
- * <em>saved default button</em>). If no default button had
- * previously been set, or the saved default button was
- * disposed, the receiver's default button will be set to
- * null.
- * <p>
- * The default button is the button that is selected when
- * the receiver is active and the user presses ENTER.
- * </p>
- *
- * @param button the new default button
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the button has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDefaultButton (Button button) {
- checkWidget();
- if (button != null) {
- if (button.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (button.menuShell () != this) error (SWT.ERROR_INVALID_PARENT);
- if ((button.style & SWT.PUSH) == 0) return;
- }
- if (button == defaultButton) return;
- if (defaultButton != null) {
- if (!defaultButton.isDisposed ()) defaultButton.setDefault (false);
- }
- defaultButton = button;
- if (defaultButton != null) {
- if (!defaultButton.isDisposed ()) defaultButton.setDefault (true);
- }
-}
-
-/**
- * Sets the receiver's image to the argument, which may
- * be null. The image is typically displayed by the window
- * manager when the instance is marked as iconified, and
- * may also be displayed somewhere in the trim when the
- * instance is in normal or maximized states.
- *
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- this.image = image;
- if (parent != null) return;
- if (display.dockImage == 0) {
- if (image != null) {
- OS.SetApplicationDockTileImage (image.handle);
- } else {
- OS.RestoreApplicationDockTileImage ();
- }
- }
-}
-
-/**
- * Sets the receiver's images to the argument, which may
- * be an empty array. Images are typically displayed by the
- * window manager when the instance is marked as iconified,
- * and may also be displayed somewhere in the trim when the
- * instance is in normal or maximized states. Depending where
- * the icon is displayed, the platform chooses the icon with
- * the "best" attributes. It is expected that the array will
- * contain the same icon rendered at different sizes, with
- * different depth and transparency attributes.
- *
- * @param images the new image array
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images is null or has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setImages (Image [] images) {
- checkWidget();
- if (images == null) error(SWT.ERROR_INVALID_ARGUMENT);
- for (int i = 0; i < images.length; i++) {
- if (images [i] == null || images [i].isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.images = images;
- if (parent != null) return;
- if (display.dockImage == 0) {
- if (images != null && images.length > 1) {
- Image [] bestImages = new Image [images.length];
- System.arraycopy (images, 0, bestImages, 0, images.length);
- sort (bestImages);
- images = bestImages;
- }
- if (images != null && images.length > 0) {
- OS.SetApplicationDockTileImage (images [0].handle);
- } else {
- OS.RestoreApplicationDockTileImage ();
- }
- }
-}
-
-/**
- * Sets the maximized state of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the maximized state, and if the argument is
- * <code>false</code> and the receiver was previously maximized,
- * causes the receiver to switch back to either the minimized
- * or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setMaximized(true)</code>
- * and <code>setMinimized(true)</code> will vary by platform. Typically,
- * the behavior will match the platform user's expectations, but not
- * always. This should be avoided if possible.
- * </p>
- *
- * @param maximized the new maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMinimized
- */
-public void setMaximized (boolean maximized) {
- checkWidget();
- this.maximized = maximized;
-}
-
-/**
- * Sets the receiver's menu bar to the argument, which
- * may be null.
- *
- * @param menu the new menu bar
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenuBar (Menu menu) {
- checkWidget();
- if (menuBar == menu) return;
- if (menu != null) {
- if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR);
- if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
- menuBar = menu;
-}
-
-/**
- * Sets the minimized stated of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the minimized state, and if the argument is
- * <code>false</code> and the receiver was previously minimized,
- * causes the receiver to switch back to either the maximized
- * or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setMaximized(true)</code>
- * and <code>setMinimized(true)</code> will vary by platform. Typically,
- * the behavior will match the platform user's expectations, but not
- * always. This should be avoided if possible.
- * </p>
- *
- * @param minimized the new maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMaximized
- */
-public void setMinimized (boolean minimized) {
- checkWidget();
- this.minimized = minimized;
-}
-
-void setSavedFocus (Control control) {
- savedFocus = control;
-}
-
-/**
- * Sets the receiver's text, which is the string that the
- * window manager will typically display as the receiver's
- * <em>title</em>, to the argument, which must not be null.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- text = string;
-}
-
-void sort (Image [] images) {
- /* Shell Sort from K&R, pg 108 */
- int length = images.length;
- if (length <= 1) return;
- ImageData [] datas = new ImageData [length];
- for (int i = 0; i < length; i++) {
- datas [i] = images [i].getImageData ();
- }
- for (int gap=length/2; gap>0; gap/=2) {
- for (int i=gap; i<length; i++) {
- for (int j=i-gap; j>=0; j-=gap) {
- if (compare (datas [j], datas [j + gap]) >= 0) {
- Image swap = images [j];
- images [j] = images [j + gap];
- images [j + gap] = swap;
- ImageData swapData = datas [j];
- datas [j] = datas [j + gap];
- datas [j + gap] = swapData;
- }
- }
- }
- }
-}
-
-boolean traverseItem (boolean next) {
- return false;
-}
-
-boolean traverseReturn () {
- if (defaultButton == null || defaultButton.isDisposed ()) return false;
- if (!defaultButton.isVisible () || !defaultButton.isEnabled ()) return false;
- defaultButton.click ();
- return true;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/DirectoryDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/DirectoryDialog.java
deleted file mode 100644
index c9c94de142..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/DirectoryDialog.java
+++ /dev/null
@@ -1,237 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.*;
-import org.eclipse.swt.*;
-
-
-/**
- * Instances of this class allow the user to navigate
- * the file system and select a directory.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#directorydialog">DirectoryDialog snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class DirectoryDialog extends Dialog {
- String message = "", filterPath = "";
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public DirectoryDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public DirectoryDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-/**
- * Returns the path which the dialog will use to filter
- * the directories it shows.
- *
- * @return the filter path
- *
- * @see #setFilterPath
- */
-public String getFilterPath () {
- return filterPath;
-}
-
-/**
- * Returns the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @return the message
- */
-public String getMessage () {
- return message;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a string describing the absolute path of the selected directory,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public String open () {
- String directoryPath = null;
- int titlePtr = 0;
- int messagePtr = 0;
- if (title != null) {
- char [] buffer = new char [title.length ()];
- title.getChars (0, buffer.length, buffer, 0);
- titlePtr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- }
- char [] buffer = new char [message.length ()];
- message.getChars (0, buffer.length, buffer, 0);
- messagePtr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
-
- NavDialogCreationOptions options = new NavDialogCreationOptions ();
- options.parentWindow = OS.GetControlOwner (parent.handle);
- // NEEDS WORK - no title displayed
- options.windowTitle = options.clientName = titlePtr;
- options.optionFlags = OS.kNavSupportPackages | OS.kNavAllowOpenPackages | OS.kNavAllowInvisibleFiles;
- options.message = messagePtr;
- options.location_h = -1;
- options.location_v = -1;
- int [] outDialog = new int [1];
- // NEEDS WORK - use inFilterProc to handle filtering
- if (OS.NavCreateChooseFolderDialog (options, 0, 0, 0, outDialog) == OS.noErr) {
- if (filterPath != null && filterPath.length () > 0) {
- char [] chars = new char [filterPath.length ()];
- filterPath.getChars (0, chars.length, chars, 0);
- int str = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, chars, chars.length);
- if (str != 0) {
- int url = OS.CFURLCreateWithFileSystemPath (OS.kCFAllocatorDefault, str, OS.kCFURLPOSIXPathStyle, false);
- if (url != 0) {
- byte [] fsRef = new byte [80];
- if (OS.CFURLGetFSRef (url, fsRef)) {
- AEDesc params = new AEDesc ();
- if (OS.AECreateDesc (OS.typeFSRef, fsRef, fsRef.length, params) == OS.noErr) {
- OS.NavCustomControl (outDialog [0], OS.kNavCtlSetLocation, params);
- OS.AEDisposeDesc (params);
- }
- }
- OS.CFRelease (url);
- }
- OS.CFRelease (str);
- }
- }
- OS.NavDialogRun (outDialog [0]);
- if (OS.NavDialogGetUserAction (outDialog [0]) == OS.kNavUserActionChoose) {
- NavReplyRecord record = new NavReplyRecord ();
- OS.NavDialogGetReply (outDialog [0], record);
- AEDesc selection = new AEDesc ();
- selection.descriptorType = record.selection_descriptorType;
- selection.dataHandle = record.selection_dataHandle;
- int [] count = new int [1];
- OS.AECountItems (selection, count);
- if (count [0] > 0) {
- int [] theAEKeyword = new int [1];
- int [] typeCode = new int [1];
- int maximumSize = 80; // size of FSRef
- int dataPtr = OS.NewPtr (maximumSize);
- int [] actualSize = new int [1];
- int status = OS.AEGetNthPtr (selection, 1, OS.typeFSRef, theAEKeyword, typeCode, dataPtr, maximumSize, actualSize);
- if (status == OS.noErr && typeCode [0] == OS.typeFSRef) {
- byte [] fsRef = new byte [actualSize [0]];
- OS.memmove (fsRef, dataPtr, actualSize [0]);
- int dirUrl = OS.CFURLCreateFromFSRef (OS.kCFAllocatorDefault, fsRef);
- int dirString = OS.CFURLCopyFileSystemPath(dirUrl, OS.kCFURLPOSIXPathStyle);
- OS.CFRelease (dirUrl);
- int length = OS.CFStringGetLength (dirString);
- buffer= new char [length];
- CFRange range = new CFRange ();
- range.length = length;
- OS.CFStringGetCharacters (dirString, range, buffer);
- OS.CFRelease (dirString);
- filterPath = directoryPath = new String (buffer);
- }
- OS.DisposePtr (dataPtr);
- }
- }
- }
- if (titlePtr != 0) OS.CFRelease (titlePtr);
- if (messagePtr != 0) OS.CFRelease (messagePtr);
- if (outDialog [0] != 0) OS.NavDialogDispose (outDialog [0]);
- return directoryPath;
-}
-
-/**
- * Sets the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @param string the message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- */
-public void setMessage (String string) {
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- message = string;
-}
-
-/**
- * Sets the path that the dialog will use to filter
- * the directories it shows to the argument, which may
- * be null. If the string is null, then the operating
- * system's default filter path will be used.
- * <p>
- * Note that the path string is platform dependent.
- * For convenience, either '/' or '\' can be used
- * as a path separator.
- * </p>
- *
- * @param string the filter path
- */
-public void setFilterPath (String string) {
- filterPath = string;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java
deleted file mode 100644
index f3a5834a26..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java
+++ /dev/null
@@ -1,4176 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.carbon.CFRange;
-import org.eclipse.swt.internal.carbon.CFRunLoopSourceContext;
-import org.eclipse.swt.internal.carbon.EventRecord;
-import org.eclipse.swt.internal.carbon.MenuTrackingData;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.CGPoint;
-import org.eclipse.swt.internal.carbon.CGRect;
-import org.eclipse.swt.internal.carbon.GDevice;
-import org.eclipse.swt.internal.carbon.HICommand;
-import org.eclipse.swt.internal.carbon.Rect;
-import org.eclipse.swt.internal.carbon.RGBColor;
-import org.eclipse.swt.internal.cocoa.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are responsible for managing the
- * connection between SWT and the underlying operating
- * system. Their most important function is to implement
- * the SWT event loop in terms of the platform event model.
- * They also provide various methods for accessing information
- * about the operating system, and have overall control over
- * the operating system resources which SWT allocates.
- * <p>
- * Applications which are built with SWT will <em>almost always</em>
- * require only a single display. In particular, some platforms
- * which SWT supports will not allow more than one <em>active</em>
- * display. In other words, some platforms do not support
- * creating a new display if one already exists that has not been
- * sent the <code>dispose()</code> message.
- * <p>
- * In SWT, the thread which creates a <code>Display</code>
- * instance is distinguished as the <em>user-interface thread</em>
- * for that display.
- * </p>
- * The user-interface thread for a particular display has the
- * following special attributes:
- * <ul>
- * <li>
- * The event loop for that display must be run from the thread.
- * </li>
- * <li>
- * Some SWT API methods (notably, most of the public methods in
- * <code>Widget</code> and its subclasses), may only be called
- * from the thread. (To support multi-threaded user-interface
- * applications, class <code>Display</code> provides inter-thread
- * communication methods which allow threads other than the
- * user-interface thread to request that it perform operations
- * on their behalf.)
- * </li>
- * <li>
- * The thread is not allowed to construct other
- * <code>Display</code>s until that display has been disposed.
- * (Note that, this is in addition to the restriction mentioned
- * above concerning platform support for multiple displays. Thus,
- * the only way to have multiple simultaneously active displays,
- * even on platforms which support it, is to have multiple threads.)
- * </li>
- * </ul>
- * Enforcing these attributes allows SWT to be implemented directly
- * on the underlying operating system's event model. This has
- * numerous benefits including smaller footprint, better use of
- * resources, safer memory management, clearer program logic,
- * better performance, and fewer overall operating system threads
- * required. The down side however, is that care must be taken
- * (only) when constructing multi-threaded applications to use the
- * inter-thread communication mechanisms which this class provides
- * when required.
- * </p><p>
- * All SWT API methods which may only be called from the user-interface
- * thread are distinguished in their documentation by indicating that
- * they throw the "<code>ERROR_THREAD_INVALID_ACCESS</code>"
- * SWT exception.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Close, Dispose, Settings</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- * @see #syncExec
- * @see #asyncExec
- * @see #wake
- * @see #readAndDispatch
- * @see #sleep
- * @see Device#dispose
- * @see <a href="http://www.eclipse.org/swt/snippets/#display">Display snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Display extends Device {
-
- /* Windows and Events */
- Event [] eventQueue;
- Callback actionCallback, appleEventCallback, clockCallback, commandCallback, controlCallback, accessibilityCallback, appearanceCallback;
- Callback drawItemCallback, itemDataCallback, itemNotificationCallback, itemCompareCallback, searchCallback, trayItemCallback;
- Callback hitTestCallback, keyboardCallback, menuCallback, mouseHoverCallback, helpCallback, observerCallback, sourceCallback;
- Callback mouseCallback, trackingCallback, windowCallback, colorCallback, textInputCallback, releaseCallback, coreEventCallback, pollingCallback;
- int actionProc, appleEventProc, clockProc, commandProc, controlProc, appearanceProc, accessibilityProc;
- int drawItemProc, itemDataProc, itemNotificationProc, itemCompareProc, helpProc, searchProc, trayItemProc;
- int hitTestProc, keyboardProc, menuProc, mouseHoverProc, observerProc, sourceProc;
- int mouseProc, trackingProc, windowProc, colorProc, textInputProc, releaseProc, coreEventProc, pollingProc;
- EventTable eventTable, filterTable;
- int queue, runLoop, runLoopSource, runLoopObserver, lastModifiers, lastState, lastX, lastY;
- boolean disposing;
-
- boolean inPaint, needsPaint;
-
- /* GC */
- int gcWindow;
-
- /* Deferred dispose window */
- int disposeWindow;
- int [] disposeWindowList;
-
- /* Sync/Async Widget Communication */
- Synchronizer synchronizer = new Synchronizer (this);
- Thread thread;
- boolean runAsyncMessages = true;
-
- /* Widget Table */
- int freeSlot;
- int [] indexTable, property;
- Widget [] widgetTable;
- static final int GROW_SIZE = 1024;
- static final int SWT0 = ('s'<<24) + ('w'<<16) + ('t'<<8) + '0';
-
- /* Focus and Activation */
- Shell activeShell;
- int focusEvent;
- Control focusControl;
- Combo focusCombo;
- boolean ignoreFocus, delayDispose;
-
- /* Modality */
- Shell [] modalShells;
-
- /* Menus */
- Menu menuBar;
- Menu [] menus, popups;
- static final int ID_TEMPORARY = 1000;
- static final int ID_START = 1001;
-
- /* Display Shutdown */
- Runnable [] disposeList;
-
- /* System Tray */
- Tray tray;
-
- /* Timers */
- int [] timerIds;
- Runnable [] timerList;
- Callback timerCallback;
- int timerProc;
- boolean allowTimers = true;
- int pollingTimer;
- static final int POLLING_TIMEOUT = 10;
-
- /* Current caret */
- Caret currentCaret;
- Callback caretCallback;
- int caretID, caretProc;
-
- /* Grabs */
- Control grabControl;
-
- /* Hover Help */
- int helpString;
- Widget helpWidget;
- int lastHelpX, lastHelpY;
-
- /* Mouse DoubleClick */
- int clickCount, clickCountButton;
-
- /* Mouse Enter/Exit/Hover */
- Control currentControl;
- int mouseHoverID;
- boolean mouseMoved;
-
- /* Drag Detect */
- int dragButton, dragX, dragY, dragState, dragModifiers;
- boolean dragging;
-
- /* Insets */
- Rect buttonInset, tabFolderNorthInset, tabFolderSouthInset, comboInset, editTextInset, searchTextInset;
-
- /* Fonts */
- boolean smallFonts;
-
- /* Keyboard */
- int kchrPtr;
- int [] kchrState = new int [1];
-
- /* System Resources */
- Image errorImage, infoImage, warningImage;
- Cursor [] cursors = new Cursor [SWT.CURSOR_HAND + 1];
-
- /* System Settings */
- boolean runSettings;
- RGBColor highlightColor;
-
- /* Dock icon */
- int dockImage;
-
- /* Key Mappings. */
- static int [] [] KeyTable = {
-
- /* Keyboard and Mouse Masks */
- {58, SWT.ALT},
- {56, SWT.SHIFT},
- {59, SWT.CONTROL},
- {55, SWT.COMMAND},
-
- /* Non-Numeric Keypad Keys */
- {126, SWT.ARROW_UP},
- {125, SWT.ARROW_DOWN},
- {123, SWT.ARROW_LEFT},
- {124, SWT.ARROW_RIGHT},
- {116, SWT.PAGE_UP},
- {121, SWT.PAGE_DOWN},
- {115, SWT.HOME},
- {119, SWT.END},
-// {??, SWT.INSERT},
-
- /* Virtual and Ascii Keys */
- {51, SWT.BS},
- {36, SWT.CR},
- {117, SWT.DEL},
- {53, SWT.ESC},
- {76, SWT.LF},
- {48, SWT.TAB},
-
- /* Functions Keys */
- {122, SWT.F1},
- {120, SWT.F2},
- {99, SWT.F3},
- {118, SWT.F4},
- {96, SWT.F5},
- {97, SWT.F6},
- {98, SWT.F7},
- {100, SWT.F8},
- {101, SWT.F9},
- {109, SWT.F10},
- {103, SWT.F11},
- {111, SWT.F12},
- {105, SWT.F13},
- {107, SWT.F14},
- {113, SWT.F15},
-
- /* Numeric Keypad Keys */
- {67, SWT.KEYPAD_MULTIPLY},
- {69, SWT.KEYPAD_ADD},
- {76, SWT.KEYPAD_CR},
- {78, SWT.KEYPAD_SUBTRACT},
- {65, SWT.KEYPAD_DECIMAL},
- {75, SWT.KEYPAD_DIVIDE},
- {82, SWT.KEYPAD_0},
- {83, SWT.KEYPAD_1},
- {84, SWT.KEYPAD_2},
- {85, SWT.KEYPAD_3},
- {86, SWT.KEYPAD_4},
- {87, SWT.KEYPAD_5},
- {88, SWT.KEYPAD_6},
- {89, SWT.KEYPAD_7},
- {91, SWT.KEYPAD_8},
- {92, SWT.KEYPAD_9},
- {81, SWT.KEYPAD_EQUAL},
-
- /* Other keys */
-// {57, SWT.CAPS_LOCK},
- {71, SWT.NUM_LOCK},
-// {??, SWT.SCROLL_LOCK},
-// {??, SWT.PAUSE},
-// {??, SWT.BREAK},
-// {??, SWT.PRINT_SCREEN},
- {114, SWT.HELP},
-
- };
-
- static String APP_NAME = "SWT"; //$NON-NLS-1$
- static final String ADD_WIDGET_KEY = "org.eclipse.swt.internal.addWidget"; //$NON-NLS-1$
-
- /* Multiple Displays. */
- static Display Default;
- static Display [] Displays = new Display [4];
-
- /* Package Name */
- static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets."; //$NON-NLS-1$
-
- /* Display Data */
- Object data;
- String [] keys;
- Object [] values;
-
- /*
- * TEMPORARY CODE. Install the runnable that
- * gets the current display. This code will
- * be removed in the future.
- */
- static {
- DeviceFinder = new Runnable () {
- public void run () {
- Device device = getCurrent ();
- if (device == null) {
- device = getDefault ();
- }
- setDevice (device);
- }
- };
- }
-
-/*
-* TEMPORARY CODE.
-*/
-static void setDevice (Device device) {
- CurrentDevice = device;
-}
-
-static byte [] ascii (String name) {
- int length = name.length ();
- char [] chars = new char [length];
- name.getChars (0, length, chars, 0);
- byte [] buffer = new byte [length + 1];
- for (int i=0; i<length; i++) {
- buffer [i] = (byte) chars [i];
- }
- return buffer;
-}
-
-static int translateKey (int key) {
- for (int i=0; i<KeyTable.length; i++) {
- if (KeyTable [i] [0] == key) return KeyTable [i] [1];
- }
- return 0;
-}
-
-static int untranslateKey (int key) {
- for (int i=0; i<KeyTable.length; i++) {
- if (KeyTable [i] [1] == key) return KeyTable [i] [0];
- }
- return 0;
-}
-
-int actionProc (int theControl, int partCode) {
- Widget widget = getWidget (theControl);
- if (widget != null) return widget.actionProc (theControl, partCode);
- return OS.noErr;
-}
-
-int appearanceProc (int theAppleEvent, int reply, int handlerRefcon) {
- runSettings = true;
- wakeThread ();
- return OS.eventNotHandledErr;
-}
-
-int appleEventProc (int nextHandler, int theEvent, int userData) {
- int eventClass = OS.GetEventClass (theEvent);
- int eventKind = OS.GetEventKind (theEvent);
- switch (eventClass) {
- case OS.kEventClassApplication:
- switch (eventKind) {
- case OS.kEventAppAvailableWindowBoundsChanged: {
- /* Reset the dock image in case the dock has been restarted */
- if (dockImage != 0) {
- int [] reason = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamReason, OS.typeUInt32, null, 4, null, reason);
- if (reason [0] == OS.kAvailBoundsChangedForDock) {
- OS.SetApplicationDockTileImage (dockImage);
- }
- }
- break;
- }
- }
- break;
- case OS.kEventClassAppleEvent:
- EventRecord eventRecord = new EventRecord ();
- boolean release = false;
- if (OS.IsEventInQueue (queue, theEvent)) {
- OS.RetainEvent (theEvent);
- release = true;
- OS.RemoveEventFromQueue (queue, theEvent);
- }
- OS.ConvertEventRefToEventRecord (theEvent, eventRecord);
- OS.AEProcessAppleEvent (eventRecord);
- if (release) OS.ReleaseEvent (theEvent);
- }
- return OS.eventNotHandledErr;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs anywhere
- * in a widget. The event type is one of the event constants
- * defined in class <code>SWT</code>. When the event does occur,
- * the listener is notified by sending it the <code>handleEvent()</code>
- * message.
- * <p>
- * Setting the type of an event to <code>SWT.None</code> from
- * within the <code>handleEvent()</code> method can be used to
- * change the event type and stop subsequent Java listeners
- * from running. Because event filters run before other listeners,
- * event filters can both block other listeners and set arbitrary
- * fields within an event. For this reason, event filters are both
- * powerful and dangerous. They should generally be avoided for
- * performance, debugging and code maintenance reasons.
- * </p>
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #removeFilter
- * @see #removeListener
- *
- * @since 3.0
- */
-public void addFilter (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (filterTable == null) filterTable = new EventTable ();
- filterTable.hook (eventType, listener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- * When the event does occur in the display, the listener is notified by
- * sending it the <code>handleEvent()</code> message.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #removeListener
- *
- * @since 2.0
- */
-public void addListener (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) eventTable = new EventTable ();
- eventTable.hook (eventType, listener);
-}
-
-void addMenu (Menu menu) {
- if (menus == null) menus = new Menu [12];
- for (int i=0; i<menus.length; i++) {
- if (menus [i] == null) {
- menu.id = (short)(ID_START + i);
- menus [i] = menu;
- return;
- }
- }
- Menu [] newMenus = new Menu [menus.length + 12];
- menu.id = (short)(ID_START + menus.length);
- newMenus [menus.length] = menu;
- System.arraycopy (menus, 0, newMenus, 0, menus.length);
- menus = newMenus;
-}
-
-void addPopup (Menu menu) {
- if (popups == null) popups = new Menu [4];
- int length = popups.length;
- for (int i=0; i<length; i++) {
- if (popups [i] == menu) return;
- }
- int index = 0;
- while (index < length) {
- if (popups [index] == null) break;
- index++;
- }
- if (index == length) {
- Menu [] newPopups = new Menu [length + 4];
- System.arraycopy (popups, 0, newPopups, 0, length);
- popups = newPopups;
- }
- popups [index] = menu;
-}
-
-void addToDisposeWindow (int control) {
- int [] root = new int [1];
- if (disposeWindow == 0) {
- int [] outWindow = new int [1];
- OS.CreateNewWindow (OS.kOverlayWindowClass, 0, new Rect(), outWindow);
- disposeWindow = outWindow [0];
- OS.CreateRootControl (disposeWindow, root);
- } else {
- OS.GetRootControl (disposeWindow, root);
- }
- OS.EmbedControl (control, root [0]);
-}
-
-void addWidget (int handle, Widget widget) {
- if (handle == 0) return;
- if (freeSlot == -1) {
- int length = (freeSlot = indexTable.length) + GROW_SIZE;
- int [] newIndexTable = new int [length];
- Widget [] newWidgetTable = new Widget [length];
- System.arraycopy (indexTable, 0, newIndexTable, 0, freeSlot);
- System.arraycopy (widgetTable, 0, newWidgetTable, 0, freeSlot);
- for (int i=freeSlot; i<length-1; i++) {
- newIndexTable [i] = i + 1;
- }
- newIndexTable [length - 1] = -1;
- indexTable = newIndexTable;
- widgetTable = newWidgetTable;
- }
- property [0] = freeSlot + 1;
- OS.SetControlProperty (handle, SWT0, SWT0, 4, property);
- int oldSlot = freeSlot;
- freeSlot = indexTable [oldSlot];
- indexTable [oldSlot] = -2;
- widgetTable [oldSlot] = widget;
-}
-
-void addDisposeWindow (int window) {
- if (disposeWindowList == null) disposeWindowList = new int [4];
- int length = disposeWindowList.length;
- for (int i=0; i<length; i++) {
- if (disposeWindowList [i] == window) return;
- }
- int index = 0;
- while (index < length) {
- if (disposeWindowList [index] == 0) break;
- index++;
- }
- if (index == length) {
- int [] newList = new int [length + 4];
- System.arraycopy (disposeWindowList, 0, newList, 0, length);
- disposeWindowList = newList;
- }
- disposeWindowList [index] = window;
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread at the next
- * reasonable opportunity. The caller of this method continues
- * to run in parallel, and is not notified when the
- * runnable has completed. Specifying <code>null</code> as the
- * runnable simply wakes the user-interface thread when run.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param runnable code to run on the user-interface thread or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #syncExec
- */
-public void asyncExec (Runnable runnable) {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- synchronizer.asyncExec (runnable);
- }
-}
-
-/**
- * Causes the system hardware to emit a short sound
- * (if it supports this capability).
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void beep () {
- checkDevice ();
- OS.SysBeep ((short) 100);
-}
-
-int caretProc (int id, int clientData) {
- if (currentCaret == null || currentCaret.isDisposed()) return 0;
- if (currentCaret.blinkCaret ()) {
- int blinkRate = currentCaret.blinkRate;
- if (blinkRate == 0) return 0;
- OS.SetEventLoopTimerNextFireTime (id, blinkRate / 1000.0);
- } else {
- currentCaret = null;
- }
- return 0;
-}
-
-protected void checkDevice () {
- if (thread == null) error (SWT.ERROR_WIDGET_DISPOSED);
- if (thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
-}
-
-/**
- * Checks that this class can be subclassed.
- * <p>
- * IMPORTANT: See the comment in <code>Widget.checkSubclass()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- */
-protected void checkSubclass () {
- if (!Display.isValidClass (getClass ())) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void clearModal (Shell shell) {
- if (modalShells == null) return;
- int index = 0, length = modalShells.length;
- while (index < length) {
- if (modalShells [index] == shell) break;
- if (modalShells [index] == null) return;
- index++;
- }
- if (index == length) return;
- System.arraycopy (modalShells, index + 1, modalShells, index, --length - index);
- modalShells [length] = null;
- if (index == 0 && modalShells [0] == null) modalShells = null;
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) shells [i].updateModal ();
-}
-
-int[] createImage (int type) {
- int[] ref = new int [1];
- int result = OS.GetIconRef (OS.kOnSystemDisk, OS.kSystemIconsCreator, type, ref);
- if (result != OS.noErr) return null;
- int[] family = new int [1];
- result = OS.IconRefToIconFamily (ref [0], OS.kSelectorAlLAvailableData, family);
- OS.ReleaseIconRef (ref [0]);
- if (result != OS.noErr) return null;
- int[] image = createImageFromFamily (family [0], OS.kLarge32BitData, OS.kLarge8BitMask, 32, 32);
- OS.DisposeHandle (family [0]);
- return image;
-}
-
-int[] createImageFromFamily (int family, int type, int maskType, int width, int height) {
- int dataHandle = OS.NewHandle (0);
- int result = OS.GetIconFamilyData (family, type, dataHandle);
- if (result != OS.noErr) {
- OS.DisposeHandle (dataHandle);
- return null;
- }
- int maskHandle = OS.NewHandle (0);
- result = OS.GetIconFamilyData (family, maskType, maskHandle);
- if (result != OS.noErr) {
- OS.DisposeHandle (maskHandle);
- OS.DisposeHandle (dataHandle);
- return null;
- }
- int bpr = width * 4;
- int dataSize = OS.GetHandleSize (dataHandle);
- int data = OS.NewPtrClear (dataSize);
- if (data == 0) {
- OS.DisposeHandle (maskHandle);
- OS.DisposeHandle (dataHandle);
- return null;
- }
- OS.HLock (dataHandle);
- OS.HLock (maskHandle);
- int[] iconPtr = new int [1];
- int[] maskPtr = new int [1];
- OS.memmove (iconPtr, dataHandle, 4);
- OS.memmove (maskPtr, maskHandle, 4);
- OS.memmove (data, iconPtr [0], dataSize);
- int pixelCount = dataSize / 4;
- for (int i = 0; i < pixelCount; i++) {
- OS.memmove (data + (i * 4), maskPtr [0] + i, 1);
- }
- OS.HUnlock (maskHandle);
- OS.HUnlock (dataHandle);
- OS.DisposeHandle (maskHandle);
- OS.DisposeHandle (dataHandle);
-
- int provider = OS.CGDataProviderCreateWithData (0, data, dataSize, releaseProc);
- if (provider == 0) {
- OS.DisposePtr (data);
- return null;
- }
- int colorspace = OS.CGColorSpaceCreateDeviceRGB ();
- if (colorspace == 0) {
- OS.CGDataProviderRelease (provider);
- return null;
- }
- int cgImage = OS.CGImageCreate (width, height, 8, 32, bpr, colorspace, OS.kCGImageAlphaFirst, provider, null, true, 0);
- OS.CGColorSpaceRelease (colorspace);
- OS.CGDataProviderRelease (provider);
-
- return new int[] {cgImage, data};
-}
-
-int createOverlayWindow () {
- int gdevice = OS.GetMainDevice ();
- int [] ptr = new int [1];
- OS.memmove (ptr, gdevice, 4);
- GDevice device = new GDevice ();
- OS.memmove (device, ptr [0], GDevice.sizeof);
- Rect rect = new Rect ();
- OS.SetRect (rect, device.left, device.top, device.right, device.bottom);
- int [] outWindow = new int [1];
- OS.CreateNewWindow (OS.kOverlayWindowClass, 0, rect, outWindow);
- if (outWindow [0] == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- return outWindow [0];
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * Note: The resulting display is marked as the <em>current</em>
- * display. If this is the first display which has been
- * constructed since the application started, it is also
- * marked as the <em>default</em> display.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if called from a thread that already created an existing display</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see #getCurrent
- * @see #getDefault
- * @see Widget#checkSubclass
- * @see Shell
- */
-public Display () {
- this (null);
-}
-
-/**
- * Constructs a new instance of this class using the parameter.
- *
- * @param data the device data
- */
-public Display (DeviceData data) {
- super (data);
-}
-
-static void checkDisplay (Thread thread, boolean multiple) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] != null) {
- if (!multiple) SWT.error (SWT.ERROR_NOT_IMPLEMENTED, null, " [multiple displays]"); //$NON-NLS-1$
- if (Displays [i].thread == thread) SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- }
- }
-}
-
-int colorProc (int inControl, int inMessage, int inDrawDepth, int inDrawInColor) {
- Widget widget = getWidget (inControl);
- if (widget != null) return widget.colorProc (inControl, inMessage, inDrawDepth, inDrawInColor);
- return OS.eventNotHandledErr;
-}
-
-int commandProc (int nextHandler, int theEvent, int userData) {
- int eventKind = OS.GetEventKind (theEvent);
- HICommand command = new HICommand ();
- OS.GetEventParameter (theEvent, OS.kEventParamDirectObject, OS.typeHICommand, null, HICommand.sizeof, null, command);
- switch (eventKind) {
- case OS.kEventProcessCommand: {
- if ((command.attributes & OS.kHICommandFromMenu) != 0) {
- if (userData != 0) {
- Widget widget = getWidget (userData);
- if (widget != null) return widget.commandProc (nextHandler, theEvent, userData);
- } else {
- int result = OS.eventNotHandledErr;
- int menuRef = command.menu_menuRef;
- short menuID = OS.GetMenuID (menuRef);
- Menu menu = getMenu (menuID);
- if (menu != null) {
- /*
- * Feature in the Macintosh. When a menu item is selected by the
- * user, the Macintosh sends kEventMenuOpening, remembers the index
- * of the item the user selected, sends kEventMenuClosed and then
- * sends kEventProcessCommand. If application code modifies the menu
- * inside of kEventMenuClosed by adding or removing items, the index
- * of the item that the user selected is invalid. The fix is to detect
- * that a menu has been modified during kEventMenuClosed and use the
- * last target item remembered kEventMenuTargetItem.
- */
- MenuItem item = null;
- if (menu.closed && menu.modified) {
- item = menu.lastTarget;
- } else {
- item = menu.getItem (command.menu_menuItemIndex - 1);
- }
- if (item != null) {
- result = item.kEventProcessCommand (nextHandler, theEvent, userData);
- }
- }
- OS.HiliteMenu ((short) 0);
- return result;
- }
- }
- }
- }
- return OS.eventNotHandledErr;
-}
-
-Rect computeInset (int control) {
- int tempRgn = OS.NewRgn ();
- Rect rect = new Rect ();
- OS.GetControlRegion (control, (short) OS.kControlStructureMetaPart, tempRgn);
- OS.GetControlBounds (control, rect);
- Rect rgnRect = new Rect ();
- OS.GetRegionBounds (tempRgn, rgnRect);
- OS.DisposeRgn (tempRgn);
- rect.left -= rgnRect.left;
- rect.top -= rgnRect.top;
- rect.right = (short) (rgnRect.right - rect.right);
- rect.bottom = (short) (rgnRect.bottom - rect.bottom);
- return rect;
-}
-
-int clockProc (int nextHandler, int theEvent, int userData) {
- Widget widget = getWidget (userData);
- if (widget != null) return widget.clockProc (nextHandler, theEvent, userData);
- return OS.eventNotHandledErr;
-}
-
-int controlProc (int nextHandler, int theEvent, int userData) {
- Widget widget = getWidget (userData);
- if (widget != null) return widget.controlProc (nextHandler, theEvent, userData);
- return OS.eventNotHandledErr;
-}
-
-int coreEventProc (int theAppleEvent, int reply, int handlerRefcon) {
- if (!disposing) {
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- if (event.doit) {
- dispose ();
- /*
- * When the application is closing, no SWT program can continue
- * to run. In order to avoid running code after the display has
- * been disposed, exit from Java.
- */
- /* This code is intentionally commented */
-// System.exit (0);
- } else {
- return OS.userCanceledErr;
- }
- }
- return OS.noErr;
-}
-
-int accessibilityProc (int nextHandler, int theEvent, int userData) {
- Widget widget = getWidget (userData);
- if (widget != null) return widget.accessibilityProc (nextHandler, theEvent, userData);
- return OS.eventNotHandledErr;
-}
-
-static String convertToLf(String text) {
- char Cr = '\r';
- char Lf = '\n';
- int length = text.length ();
- if (length == 0) return text;
-
- /* Check for an LF or CR/LF. Assume the rest of the string
- * is formated that way. This will not work if the string
- * contains mixed delimiters. */
- int i = text.indexOf (Lf, 0);
- if (i == -1 || i == 0) return text;
- if (text.charAt (i - 1) != Cr) return text;
-
- /* The string is formatted with CR/LF.
- * Create a new string with the LF line delimiter. */
- i = 0;
- StringBuffer result = new StringBuffer ();
- while (i < length) {
- int j = text.indexOf (Cr, i);
- if (j == -1) j = length;
- String s = text.substring (i, j);
- result.append (s);
- i = j + 2;
- result.append (Lf);
- }
- return result.toString ();
-}
-
-void clearMenuFlags () {
- if (menus == null) return;
- for (int i=0; i<menus.length; i++) {
- Menu menu = menus [i];
- if (menu != null) {
- menu.modified = menu.closed = false;
- menu.lastTarget = null;
- }
- }
-}
-
-/**
- * Requests that the connection between SWT and the underlying
- * operating system be closed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Device#dispose
- *
- * @since 2.0
- */
-public void close () {
- checkDevice ();
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- if (event.doit) dispose ();
-}
-
-/**
- * Creates the device in the operating system. If the device
- * does not have a handle, this method may do nothing depending
- * on the device.
- * <p>
- * This method is called before <code>init</code>.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #init
- */
-protected void create (DeviceData data) {
- checkSubclass ();
- checkDisplay (thread = Thread.currentThread (), false);
- createDisplay (data);
- register (this);
- if (Default == null) Default = this;
-}
-
-void createDisplay (DeviceData data) {
- if (OS.VERSION < 0x1030) {
- System.out.println ("***WARNING: SWT requires MacOS X version " + 10 + "." + 3 + " or greater"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- System.out.println ("***WARNING: Detected: " + Integer.toHexString((OS.VERSION & 0xFF00) >> 8) + "." + Integer.toHexString((OS.VERSION & 0xF0) >> 4) + "." + Integer.toHexString(OS.VERSION & 0xF)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- /*
- * Feature in the Macintosh. On OS 10.2, it is necessary
- * to explicitly check in with the Process Manager and set
- * the current process to be the front process in order for
- * windows to come to the front by default. The fix is call
- * both GetCurrentProcess() and SetFrontProcess().
- *
- * NOTE: It is not actually necessary to use the process
- * serial number returned by GetCurrentProcess() in the
- * call to SetFrontProcess() (ie. kCurrentProcess can be
- * used) but both functions must be called in order for
- * windows to come to the front.
- */
- int [] psn = new int [2];
- if (OS.GetCurrentProcess (psn) == OS.noErr) {
- int pid = OS.getpid ();
- byte [] buffer = null;
- int ptr = OS.getenv (ascii ("APP_NAME_" + pid)); //$NON-NLS-1$
- if (ptr != 0) {
- buffer = new byte [OS.strlen (ptr) + 1];
- OS.memmove (buffer, ptr, buffer.length);
- } else {
- if (APP_NAME != null) {
- char [] chars = new char [APP_NAME.length ()];
- APP_NAME.getChars (0, chars.length, chars, 0);
- int cfstring = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, chars, chars.length);
- if (cfstring != 0) {
- CFRange range = new CFRange ();
- range.length = chars.length;
- int encoding = OS.CFStringGetSystemEncoding ();
- int [] size = new int [1];
- int numChars = OS.CFStringGetBytes (cfstring, range, encoding, (byte) '?', true, null, 0, size);
- if (numChars != 0) {
- buffer = new byte [size [0] + 1];
- numChars = OS.CFStringGetBytes (cfstring, range, encoding, (byte) '?', true, buffer, size [0], size);
- }
- OS.CFRelease (cfstring);
- }
- }
- }
- if (buffer != null) OS.CPSSetProcessName (psn, buffer);
- OS.CPSEnableForegroundOperation (psn, 0x03, 0x3C, 0x2C, 0x1103);
- OS.SetFrontProcess (psn);
- ptr = OS.getenv (ascii ("APP_ICON_" + pid)); //$NON-NLS-1$
- if (ptr != 0) {
- int image = readImageRef (ptr);
- if (image != 0) {
- dockImage = image;
- OS.SetApplicationDockTileImage (dockImage);
- }
- }
- }
- /*
- * Feature in the Macintosh. In order to get the standard
- * application menu to appear on the menu bar, an application
- * must manipulate the menu bar. If the application does not
- * install a menu bar, the application menu will not appear.
- * The fix is to use ClearMenuBar() to manipulate the menu
- * bar before any application has had a chance install a menu
- * bar.
- */
- OS.ClearMenuBar ();
- queue = OS.GetCurrentEventQueue ();
- runLoop = OS.GetCFRunLoopFromEventLoop (OS.GetCurrentEventLoop ());
- OS.TXNInitTextension (0, 0, 0);
-
- /* Save the current highlight color */
- OS.RegisterAppearanceClient ();
- highlightColor = new RGBColor ();
- OS.GetThemeBrushAsColor ((short) OS.kThemeBrushPrimaryHighlightColor, (short) getDepth(), true, highlightColor);
-}
-
-static void deregister (Display display) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (display == Displays [i]) Displays [i] = null;
- }
- }
-}
-
-/**
- * Destroys the device in the operating system and releases
- * the device's handle. If the device does not have a handle,
- * this method may do nothing depending on the device.
- * <p>
- * This method is called after <code>release</code>.
- * </p>
- * @see Device#dispose
- * @see #release
- */
-protected void destroy () {
- if (this == Default) Default = null;
- deregister (this);
- destroyDisplay ();
-}
-
-void destroyDisplay () {
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread just before the
- * receiver is disposed. Specifying a <code>null</code> runnable
- * is ignored.
- *
- * @param runnable code to run at dispose time.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void disposeExec (Runnable runnable) {
- checkDevice ();
- if (disposeList == null) disposeList = new Runnable [4];
- for (int i=0; i<disposeList.length; i++) {
- if (disposeList [i] == null) {
- disposeList [i] = runnable;
- return;
- }
- }
- Runnable [] newDisposeList = new Runnable [disposeList.length + 4];
- System.arraycopy (disposeList, 0, newDisposeList, 0, disposeList.length);
- newDisposeList [disposeList.length] = runnable;
- disposeList = newDisposeList;
-}
-
-int drawItemProc (int browser, int item, int property, int itemState, int theRect, int gdDepth, int colorDevice) {
- Widget widget = getWidget (browser);
- if (widget != null) return widget.drawItemProc (browser, item, property, itemState, theRect, gdDepth, colorDevice);
- return OS.noErr;
-}
-
-void disposeWindows () {
- if (disposeWindow != 0) {
- OS.DisposeWindow (disposeWindow);
- disposeWindow = 0;
- }
- if (disposeWindowList != null) {
- for (int i = 0; i < disposeWindowList.length; i++) {
- if (disposeWindowList [i] != 0) {
- OS.DisposeWindow (disposeWindowList [i]);
- }
- }
- disposeWindowList = null;
- }
-}
-
-void error (int code) {
- SWT.error(code);
-}
-
-boolean filterEvent (Event event) {
- if (filterTable != null) filterTable.sendEvent (event);
- return false;
-}
-
-boolean filters (int eventType) {
- if (filterTable == null) return false;
- return filterTable.hooks (eventType);
-}
-
-/**
- * Given the operating system handle for a widget, returns
- * the instance of the <code>Widget</code> subclass which
- * represents it in the currently running application, if
- * such exists, or null if no matching widget can be found.
- * <p>
- * <b>IMPORTANT:</b> This method should not be called from
- * application code. The arguments are platform-specific.
- * </p>
- *
- * @param handle the handle for the widget
- * @return the SWT widget that the handle represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Widget findWidget (int handle) {
- checkDevice ();
- return getWidget (handle);
-}
-
-/**
- * Given the operating system handle for a widget,
- * and widget-specific id, returns the instance of
- * the <code>Widget</code> subclass which represents
- * the handle/id pair in the currently running application,
- * if such exists, or null if no matching widget can be found.
- * <p>
- * <b>IMPORTANT:</b> This method should not be called from
- * application code. The arguments are platform-specific.
- * </p>
- *
- * @param handle the handle for the widget
- * @param id the id for the subwidget (usually an item)
- * @return the SWT widget that the handle/id pair represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public Widget findWidget (int handle, int id) {
- checkDevice ();
- return null;
-}
-
-/**
- * Given a widget and a widget-specific id, returns the
- * instance of the <code>Widget</code> subclass which represents
- * the widget/id pair in the currently running application,
- * if such exists, or null if no matching widget can be found.
- *
- * @param widget the widget
- * @param id the id for the subwidget (usually an item)
- * @return the SWT subwidget (usually an item) that the widget/id pair represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.3
- */
-public Widget findWidget (Widget widget, int id) {
- checkDevice ();
- return null;
-}
-
-/**
- * Returns the display which the given thread is the
- * user-interface thread for, or null if the given thread
- * is not a user-interface thread for any display. Specifying
- * <code>null</code> as the thread will return <code>null</code>
- * for the display.
- *
- * @param thread the user-interface thread
- * @return the display for the given thread
- */
-public static Display findDisplay (Thread thread) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- Display display = Displays [i];
- if (display != null && display.thread == thread) {
- return display;
- }
- }
- return null;
- }
-}
-
-/**
- * Returns the currently active <code>Shell</code>, or null
- * if no shell belonging to the currently running application
- * is active.
- *
- * @return the active shell or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Shell getActiveShell () {
- checkDevice ();
- /*
- * Feature in the Macintosh. When SetWindowActivationScope()
- * is used with kWindowActivationScopeNone to stop a window from
- * becoming active and taking focus when shown, for some reason,
- * when focus is lost to the desktop or another application,
- * the window becomes active. Specifically, IsWindowActive()
- * starts to return true for the window, even though is has
- * never been made active. The fix is to check that the current
- * and front process are the same before calling IsWindowActive().
- */
- int [] psn1 = new int [2];
- if (OS.GetCurrentProcess (psn1) == OS.noErr) {
- int [] psn2 = new int [2];
- if (OS.GetFrontProcess (psn2) == OS.noErr) {
- boolean [] result = new boolean [1];
- if (OS.SameProcess (psn1, psn2, result) == OS.noErr) {
- if (!result [0]) return null;
- }
- }
- }
- if (activeShell != null && !activeShell.isDisposed ()) {
- return activeShell;
- }
- for (int i=0; i<widgetTable.length; i++) {
- Widget widget = widgetTable [i];
- if (widget != null && widget instanceof Shell) {
- Shell shell = (Shell) widget;
- if (OS.IsWindowActive (shell.shellHandle)) return shell;
- }
- }
- return null;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location. Note that
- * on multi-monitor systems the origin can be negative.
- *
- * @return the bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkDevice ();
- int gdevice = OS.GetDeviceList();
- if (gdevice == 0 || OS.GetNextDevice (gdevice) == 0) {
- return super.getBounds ();
- }
- Monitor [] monitors = getMonitors ();
- Rectangle rect = monitors [0].getBounds ();
- for (int i=1; i<monitors.length; i++) {
- rect = rect.union (monitors [i].getBounds ());
- }
- return rect;
-}
-
-/**
- * Returns the display which the currently running thread is
- * the user-interface thread for, or null if the currently
- * running thread is not a user-interface thread for any display.
- *
- * @return the current display
- */
-public static Display getCurrent () {
- return findDisplay (Thread.currentThread ());
-}
-
-int getCaretBlinkTime () {
-// checkDevice ();
- return OS.GetCaretTime () * 1000 / 60;
-}
-
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data.
- *
- * @return the client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getBounds
- */
-public Rectangle getClientArea () {
- checkDevice ();
- int gdevice = OS.GetDeviceList();
- if (gdevice == 0 || OS.GetNextDevice (gdevice) == 0) {
- return super.getClientArea ();
- }
- Monitor [] monitors = getMonitors ();
- Rectangle rect = monitors [0].getBounds ();
- for (int i=1; i<monitors.length; i++) {
- rect = rect.union (monitors [i].getBounds ());
- }
- return rect;
-}
-
-/**
- * Returns the control which the on-screen pointer is currently
- * over top of, or null if it is not currently over one of the
- * controls built by the currently running application.
- *
- * @return the control under the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Control getCursorControl () {
- checkDevice ();
- org.eclipse.swt.internal.carbon.Point where = new org.eclipse.swt.internal.carbon.Point ();
- OS.GetGlobalMouse (where);
- int [] theWindow = new int [1];
- if (OS.FindWindow (where, theWindow) != OS.inContent) return null;
- if (theWindow [0] == 0) return null;
- Rect rect = new Rect ();
- OS.GetWindowBounds (theWindow [0], (short) OS.kWindowStructureRgn, rect);
- CGPoint inPoint = new CGPoint ();
- inPoint.x = where.h - rect.left;
- inPoint.y = where.v - rect.top;
- int [] theRoot = new int [1];
- OS.GetRootControl (theWindow [0], theRoot);
- int [] theControl = new int [1];
- int[] event = new int[1];
- OS.CreateEvent (0, OS.kEventClassMouse, OS.kEventMouseDown, 0.0, 0, event);
- OS.SetEventParameter (event[0], OS.kEventParamWindowMouseLocation, OS.typeHIPoint, CGPoint.sizeof, inPoint);
- OS.HIViewGetViewForMouseEvent (theRoot [0], event [0], theControl);
- OS.ReleaseEvent(event[0]);
- while (theControl [0] != 0 && !OS.IsControlEnabled (theControl [0])) {
- OS.GetSuperControl (theControl [0], theControl);
- }
- if (theControl [0] != 0) {
- do {
- Widget widget = getWidget (theControl [0]);
- if (widget != null) {
- if (widget instanceof Control) {
- Control control = (Control) widget;
- if (control.isEnabled ()) {
- return control.isEnabledModal () ? control : null;
- }
- }
- }
- OS.GetSuperControl (theControl [0], theControl);
- } while (theControl [0] != 0);
- }
- Widget widget = getWidget (theRoot [0]);
- if (widget != null && widget instanceof Control) return (Control) widget;
- return null;
-}
-
-/**
- * Returns the location of the on-screen pointer relative
- * to the top left corner of the screen.
- *
- * @return the cursor location
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point getCursorLocation () {
- checkDevice ();
- org.eclipse.swt.internal.carbon.Point pt = new org.eclipse.swt.internal.carbon.Point ();
- OS.GetGlobalMouse (pt);
- return new Point (pt.h, pt.v);
-}
-
-/**
- * Returns an array containing the recommended cursor sizes.
- *
- * @return the array of cursor sizes
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public Point [] getCursorSizes () {
- checkDevice ();
- return new Point [] {new Point (16, 16)};
-}
-
-/**
- * Returns the default display. One is created (making the
- * thread that invokes this method its user-interface thread)
- * if it did not already exist.
- *
- * @return the default display
- */
-public static Display getDefault () {
- synchronized (Device.class) {
- if (Default == null) Default = new Display ();
- return Default;
- }
-}
-
-/**
- * Returns the application defined property of the receiver
- * with the specified name, or null if it has not been set.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the display is disposed
- * of, it is the application's responsibility to provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param key the name of the property
- * @return the value of the property or null if it has not been set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setData(String, Object)
- * @see #disposeExec(Runnable)
- */
-public Object getData (String key) {
- checkDevice ();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (keys == null) return null;
- for (int i=0; i<keys.length; i++) {
- if (keys [i].equals (key)) return values [i];
- }
- return null;
-}
-
-/**
- * Returns the application defined, display specific data
- * associated with the receiver, or null if it has not been
- * set. The <em>display specific data</em> is a single,
- * unnamed field that is stored with every display.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the display specific data needs to
- * be notified when the display is disposed of, it is the
- * application's responsibility to provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @return the display specific data
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setData(Object)
- * @see #disposeExec(Runnable)
- */
-public Object getData () {
- checkDevice ();
- return data;
-}
-
-/**
- * Returns the button dismissal alignment, one of <code>LEFT</code> or <code>RIGHT</code>.
- * The button dismissal alignment is the ordering that should be used when positioning the
- * default dismissal button for a dialog. For example, in a dialog that contains an OK and
- * CANCEL button, on platforms where the button dismissal alignment is <code>LEFT</code>, the
- * button ordering should be OK/CANCEL. When button dismissal alignment is <code>RIGHT</code>,
- * the button ordering should be CANCEL/OK.
- *
- * @return the button dismissal order
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1
- */
-public int getDismissalAlignment () {
- checkDevice ();
- return SWT.RIGHT;
-}
-
-/**
- * Returns the longest duration, in milliseconds, between
- * two mouse button clicks that will be considered a
- * <em>double click</em> by the underlying operating system.
- *
- * @return the double click time
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getDoubleClickTime () {
- checkDevice ();
- return OS.GetDblTime () * 1000 / 60;
-}
-
-/**
- * Returns the control which currently has keyboard focus,
- * or null if keyboard events are not currently going to
- * any of the controls built by the currently running
- * application.
- *
- * @return the control under the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Control getFocusControl () {
- checkDevice ();
- if (focusControl != null && !focusControl.isDisposed ()) {
- return focusControl;
- }
- int theWindow = OS.GetUserFocusWindow ();
- if (theWindow == 0) return null;
- return getFocusControl (theWindow, false);
-}
-
-Control getFocusControl (int window, boolean disabled) {
- int [] theControl = new int [1];
- OS.GetKeyboardFocus (window, theControl);
- if (theControl [0] == 0) return null;
- do {
- Widget widget = getWidget (theControl [0]);
- if (widget != null && widget instanceof Control) {
- Control control = (Control) widget;
- if (disabled) return control;
- return control.isEnabled () ? control : null;
- }
- OS.GetSuperControl (theControl [0], theControl);
- } while (theControl [0] != 0);
- return null;
-}
-
-/**
- * Returns true when the high contrast mode is enabled.
- * Otherwise, false is returned.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @return the high contrast mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public boolean getHighContrast () {
- checkDevice ();
- return false;
-}
-
-/**
- * Returns the maximum allowed depth of icons on this display, in bits per pixel.
- * On some platforms, this may be different than the actual depth of the display.
- *
- * @return the maximum icon depth
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Device#getDepth
- */
-public int getIconDepth () {
- return getDepth ();
-}
-
-/**
- * Returns an array containing the recommended icon sizes.
- *
- * @return the array of icon sizes
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Decorations#setImages(Image[])
- *
- * @since 3.0
- */
-public Point [] getIconSizes () {
- checkDevice ();
- return new Point [] {
- new Point (16, 16), new Point (32, 32),
- new Point (64, 64), new Point (128, 128)};
-}
-
-int getLastEventTime () {
- return (int) (OS.GetLastUserEventTime () * 1000.0);
-}
-
-Menu [] getMenus (Decorations shell) {
- if (menus == null) return new Menu [0];
- int count = 0;
- for (int i = 0; i < menus.length; i++) {
- Menu menu = menus[i];
- if (menu != null && menu.parent == shell) count++;
- }
- int index = 0;
- Menu[] result = new Menu[count];
- for (int i = 0; i < menus.length; i++) {
- Menu menu = menus[i];
- if (menu != null && menu.parent == shell) {
- result[index++] = menu;
- }
- }
- return result;
-}
-
-Menu getMenu (int id) {
- if (menus == null) return null;
- int index = id - ID_START;
- if (0 <= index && index < menus.length) return menus [index];
- return null;
-}
-
-Menu getMenuBar () {
- return menuBar;
-}
-
-int getMessageCount () {
- return synchronizer.getMessageCount ();
-}
-
-/**
- * Returns an array of monitors attached to the device.
- *
- * @return the array of monitors
- *
- * @since 3.0
- */
-public Monitor [] getMonitors () {
- checkDevice ();
- int count = 0;
- Monitor [] monitors = new Monitor [1];
- Rect rect = new Rect ();
- GDevice device = new GDevice ();
- int gdevice = OS.GetDeviceList ();
- while (gdevice != 0) {
- if (count >= monitors.length) {
- Monitor [] newMonitors = new Monitor [monitors.length + 4];
- System.arraycopy (monitors, 0, newMonitors, 0, monitors.length);
- monitors = newMonitors;
- }
- Monitor monitor = new Monitor ();
- monitor.handle = gdevice;
- int [] ptr = new int [1];
- OS.memmove (ptr, gdevice, 4);
- OS.memmove (device, ptr [0], GDevice.sizeof);
- monitor.x = device.left;
- monitor.y = device.top;
- monitor.width = device.right - device.left;
- monitor.height = device.bottom - device.top;
- OS.GetAvailableWindowPositioningBounds (gdevice, rect);
- monitor.clientX = rect.left;
- monitor.clientY = rect.top;
- monitor.clientWidth = rect.right - rect.left;
- monitor.clientHeight = rect.bottom - rect.top;
- monitors [count++] = monitor;
- gdevice = OS.GetNextDevice (gdevice);
- }
- if (count < monitors.length) {
- Monitor [] newMonitors = new Monitor [count];
- System.arraycopy (monitors, 0, newMonitors, 0, count);
- monitors = newMonitors;
- }
- return monitors;
-}
-
-/**
- * Returns the primary monitor for that device.
- *
- * @return the primary monitor
- *
- * @since 3.0
- */
-public Monitor getPrimaryMonitor () {
- checkDevice ();
- int gdevice = OS.GetMainDevice ();
- Monitor monitor = new Monitor ();
- monitor.handle = gdevice;
- int [] ptr = new int [1];
- OS.memmove (ptr, gdevice, 4);
- GDevice device = new GDevice ();
- OS.memmove (device, ptr [0], GDevice.sizeof);
- monitor.x = device.left;
- monitor.y = device.top;
- monitor.width = device.right - device.left;
- monitor.height = device.bottom - device.top;
- Rect rect = new Rect ();
- OS.GetAvailableWindowPositioningBounds (gdevice, rect);
- monitor.clientX = rect.left;
- monitor.clientY = rect.top;
- monitor.clientWidth = rect.right - rect.left;
- monitor.clientHeight = rect.bottom - rect.top;
- return monitor;
-}
-
-/**
- * Returns a (possibly empty) array containing all shells which have
- * not been disposed and have the receiver as their display.
- *
- * @return the receiver's shells
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Shell [] getShells () {
- checkDevice ();
- int index = 0;
- Shell [] result = new Shell [16];
- for (int i = 0; i < widgetTable.length; i++) {
- Widget widget = widgetTable [i];
- if (widget != null && widget instanceof Shell) {
- int j = 0;
- while (j < index) {
- if (result [j] == widget) break;
- j++;
- }
- if (j == index) {
- if (index == result.length) {
- Shell [] newResult = new Shell [index + 16];
- System.arraycopy (result, 0, newResult, 0, index);
- result = newResult;
- }
- result [index++] = (Shell) widget;
- }
- }
- }
- if (index == result.length) return result;
- Shell [] newResult = new Shell [index];
- System.arraycopy (result, 0, newResult, 0, index);
- return newResult;
-}
-
-/**
- * Gets the synchronizer used by the display.
- *
- * @return the receiver's synchronizer
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public Synchronizer getSynchronizer () {
- checkDevice ();
- return synchronizer;
-}
-
-/**
- * Returns the thread that has invoked <code>syncExec</code>
- * or null if no such runnable is currently being invoked by
- * the user-interface thread.
- * <p>
- * Note: If a runnable invoked by asyncExec is currently
- * running, this method will return null.
- * </p>
- *
- * @return the receiver's sync-interface thread
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Thread getSyncThread () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- return synchronizer.syncThread;
- }
-}
-
-/**
- * Returns the matching standard color for the given
- * constant, which should be one of the color constants
- * specified in class <code>SWT</code>. Any value other
- * than one of the SWT color constants which is passed
- * in will result in the color black. This color should
- * not be free'd because it was allocated by the system,
- * not the application.
- *
- * @param id the color constant
- * @return the matching color
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT
- */
-public Color getSystemColor (int id) {
- checkDevice ();
- RGBColor rgb = new RGBColor ();
- switch (id) {
- case SWT.COLOR_INFO_FOREGROUND: return super.getSystemColor (SWT.COLOR_BLACK);
- case SWT.COLOR_INFO_BACKGROUND: return Color.carbon_new (this, new float [] {0xFF / 255f, 0xFF / 255f, 0xE1 / 255f, 1});
- case SWT.COLOR_TITLE_FOREGROUND: OS.GetThemeTextColor((short)OS.kThemeTextColorDocumentWindowTitleActive, (short)getDepth(), true, rgb); break;
- case SWT.COLOR_TITLE_BACKGROUND: OS.GetThemeBrushAsColor((short)-5/*undocumented darker highlight color*/, (short)getDepth(), true, rgb); break;
- case SWT.COLOR_TITLE_BACKGROUND_GRADIENT: OS.GetThemeBrushAsColor((short)OS.kThemeBrushPrimaryHighlightColor, (short)getDepth(), true, rgb) ; break;
- case SWT.COLOR_TITLE_INACTIVE_FOREGROUND: OS.GetThemeTextColor((short)OS.kThemeTextColorDocumentWindowTitleInactive, (short)getDepth(), true, rgb); break;
- case SWT.COLOR_TITLE_INACTIVE_BACKGROUND: OS.GetThemeBrushAsColor((short)OS.kThemeBrushSecondaryHighlightColor, (short)getDepth(), true, rgb); break;
- case SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT: OS.GetThemeBrushAsColor((short)OS.kThemeBrushSecondaryHighlightColor, (short)getDepth(), true, rgb); break;
- case SWT.COLOR_WIDGET_DARK_SHADOW: return Color.carbon_new (this, new float [] {0x33 / 255f, 0x33 / 255f, 0x33 / 255f, 1});
- case SWT.COLOR_WIDGET_NORMAL_SHADOW: return Color.carbon_new (this, new float [] {0x66 / 255f, 0x66 / 255f, 0x66 / 255f, 1});
- case SWT.COLOR_WIDGET_LIGHT_SHADOW: return Color.carbon_new (this, new float [] {0x99 / 255f, 0x99 / 255f, 0x99 / 255f, 1});
- case SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: return Color.carbon_new (this, new float [] {0xCC / 255f, 0xCC / 255f, 0xCC / 255f, 1});
- case SWT.COLOR_WIDGET_BACKGROUND:
- OS.GetThemeBrushAsColor((short)(OS.VERSION < 0x1050 ? OS.kThemeBrushButtonFaceActive : OS.kThemeBrushButtonInactiveDarkShadow), (short)getDepth(), true, rgb);
- break;
- case SWT.COLOR_WIDGET_FOREGROUND: OS.GetThemeTextColor((short)OS.kThemeTextColorPushButtonActive, (short)getDepth(), true, rgb); break;
- case SWT.COLOR_WIDGET_BORDER: return super.getSystemColor (SWT.COLOR_BLACK);
- case SWT.COLOR_LIST_FOREGROUND: OS.GetThemeTextColor((short)OS.kThemeTextColorListView, (short)getDepth(), true, rgb); break;
- case SWT.COLOR_LIST_BACKGROUND: OS.GetThemeBrushAsColor((short)OS.kThemeBrushListViewBackground, (short)getDepth(), true, rgb); break;
- case SWT.COLOR_LIST_SELECTION_TEXT: OS.GetThemeTextColor((short)OS.kThemeTextColorListView, (short)getDepth(), true, rgb); break;
- case SWT.COLOR_LIST_SELECTION: OS.GetThemeBrushAsColor((short)OS.kThemeBrushPrimaryHighlightColor, (short)getDepth(), true, rgb); break;
- default:
- return super.getSystemColor (id);
- }
- float red = ((rgb.red >> 8) & 0xFF) / 255f;
- float green = ((rgb.green >> 8) & 0xFF) / 255f;
- float blue = ((rgb.blue >> 8) & 0xFF) / 255f;
- return Color.carbon_new (this, new float[]{red, green, blue, 1});
-}
-
-/**
- * Returns the matching standard platform cursor for the given
- * constant, which should be one of the cursor constants
- * specified in class <code>SWT</code>. This cursor should
- * not be free'd because it was allocated by the system,
- * not the application. A value of <code>null</code> will
- * be returned if the supplied constant is not an SWT cursor
- * constant.
- *
- * @param id the SWT cursor constant
- * @return the corresponding cursor or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT#CURSOR_ARROW
- * @see SWT#CURSOR_WAIT
- * @see SWT#CURSOR_CROSS
- * @see SWT#CURSOR_APPSTARTING
- * @see SWT#CURSOR_HELP
- * @see SWT#CURSOR_SIZEALL
- * @see SWT#CURSOR_SIZENESW
- * @see SWT#CURSOR_SIZENS
- * @see SWT#CURSOR_SIZENWSE
- * @see SWT#CURSOR_SIZEWE
- * @see SWT#CURSOR_SIZEN
- * @see SWT#CURSOR_SIZES
- * @see SWT#CURSOR_SIZEE
- * @see SWT#CURSOR_SIZEW
- * @see SWT#CURSOR_SIZENE
- * @see SWT#CURSOR_SIZESE
- * @see SWT#CURSOR_SIZESW
- * @see SWT#CURSOR_SIZENW
- * @see SWT#CURSOR_UPARROW
- * @see SWT#CURSOR_IBEAM
- * @see SWT#CURSOR_NO
- * @see SWT#CURSOR_HAND
- *
- * @since 3.0
- */
-public Cursor getSystemCursor (int id) {
- checkDevice ();
- if (!(0 <= id && id < cursors.length)) return null;
- if (cursors [id] == null) {
- cursors [id] = new Cursor (this, id);
- }
- return cursors [id];
-}
-
-/**
- * Returns the matching standard platform image for the given
- * constant, which should be one of the icon constants
- * specified in class <code>SWT</code>. This image should
- * not be free'd because it was allocated by the system,
- * not the application. A value of <code>null</code> will
- * be returned either if the supplied constant is not an
- * SWT icon constant or if the platform does not define an
- * image that corresponds to the constant.
- *
- * @param id the SWT icon constant
- * @return the corresponding image or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_QUESTION
- * @see SWT#ICON_WARNING
- * @see SWT#ICON_WORKING
- *
- * @since 3.0
- */
-public Image getSystemImage (int id) {
- checkDevice ();
- switch (id) {
- case SWT.ICON_ERROR: {
- if (errorImage != null) return errorImage;
- int [] image = createImage (OS.kAlertStopIcon);
- if (image == null) break;
- return errorImage = Image.carbon_new (this, SWT.ICON, image [0], image [1]);
- }
- case SWT.ICON_INFORMATION:
- case SWT.ICON_QUESTION:
- case SWT.ICON_WORKING: {
- if (infoImage != null) return infoImage;
- int [] image = createImage (OS.kAlertNoteIcon);
- if (image == null) break;
- return infoImage = Image.carbon_new (this, SWT.ICON, image [0], image [1]);
- }
- case SWT.ICON_WARNING: {
- if (warningImage != null) return warningImage;
- int [] image = createImage (OS.kAlertCautionIcon);
- if (image == null) break;
- return warningImage = Image.carbon_new (this, SWT.ICON, image [0], image [1]);
- }
- }
- return null;
-}
-
-/**
- * Returns the single instance of the system tray or null
- * when there is no system tray available for the platform.
- *
- * @return the system tray or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public Tray getSystemTray () {
- checkDevice ();
- if (tray != null) return tray;
- return tray = new Tray (this, SWT.NONE);
-}
-
-/**
- * Returns the user-interface thread for the receiver.
- *
- * @return the receiver's user-interface thread
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Thread getThread () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- return thread;
- }
-}
-
-Widget getWidget (int handle) {
- if (handle == 0) return null;
- property [0] = 0;
- OS.GetControlProperty (handle, SWT0, SWT0, 4, null, property);
- int index = property [0] - 1;
- if (0 <= index && index < widgetTable.length) return widgetTable [index];
- return null;
-}
-
-int helpProc (int inControl, int inGlobalMouse, int inRequest, int outContentProvided, int ioHelpContent) {
- Widget widget = getWidget (inControl);
- if (widget != null) return widget.helpProc (inControl, inGlobalMouse, inRequest, outContentProvided, ioHelpContent);
- return OS.eventNotHandledErr;
-}
-
-int hitTestProc (int browser, int item, int property, int theRect, int mouseRect) {
- Widget widget = getWidget (browser);
- if (widget != null) return widget.hitTestProc (browser, item, property, theRect, mouseRect);
- return OS.noErr;
-}
-
-/**
- * Initializes any internal resources needed by the
- * device.
- * <p>
- * This method is called after <code>create</code>.
- * </p>
- *
- * @see #create
- */
-protected void init () {
- super.init ();
- initializeCallbacks ();
- initializeInsets ();
- initializeWidgetTable ();
- initializeFonts ();
-}
-
-void initializeCallbacks () {
- /* Create Callbacks */
- actionCallback = new Callback (this, "actionProc", 2); //$NON-NLS-1$
- actionProc = actionCallback.getAddress ();
- if (actionProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- appleEventCallback = new Callback (this, "appleEventProc", 3); //$NON-NLS-1$
- appleEventProc = appleEventCallback.getAddress ();
- if (appleEventProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- caretCallback = new Callback(this, "caretProc", 2); //$NON-NLS-1$
- caretProc = caretCallback.getAddress();
- if (caretProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- clockCallback = new Callback (this, "clockProc", 3); //$NON-NLS-1$
- clockProc = clockCallback.getAddress ();
- if (clockProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- commandCallback = new Callback (this, "commandProc", 3); //$NON-NLS-1$
- commandProc = commandCallback.getAddress ();
- if (commandProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- controlCallback = new Callback (this, "controlProc", 3); //$NON-NLS-1$
- controlProc = controlCallback.getAddress ();
- if (controlProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- accessibilityCallback = new Callback (this, "accessibilityProc", 3); //$NON-NLS-1$
- accessibilityProc = accessibilityCallback.getAddress ();
- if (accessibilityProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- drawItemCallback = new Callback (this, "drawItemProc", 7); //$NON-NLS-1$
- drawItemProc = drawItemCallback.getAddress ();
- if (drawItemProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- itemCompareCallback = new Callback (this, "itemCompareProc", 4); //$NON-NLS-1$
- itemCompareProc = itemCompareCallback.getAddress ();
- if (itemCompareProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- itemDataCallback = new Callback (this, "itemDataProc", 5); //$NON-NLS-1$
- itemDataProc = itemDataCallback.getAddress ();
- if (itemDataProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- itemNotificationCallback = new Callback (this, "itemNotificationProc", 3); //$NON-NLS-1$
- itemNotificationProc = itemNotificationCallback.getAddress ();
- if (itemNotificationProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- helpCallback = new Callback (this, "helpProc", 5); //$NON-NLS-1$
- helpProc = helpCallback.getAddress ();
- if (helpProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- hitTestCallback = new Callback (this, "hitTestProc", 5); //$NON-NLS-1$
- hitTestProc = hitTestCallback.getAddress ();
- if (hitTestProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- keyboardCallback = new Callback (this, "keyboardProc", 3); //$NON-NLS-1$
- keyboardProc = keyboardCallback.getAddress ();
- if (keyboardProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- menuCallback = new Callback (this, "menuProc", 3); //$NON-NLS-1$
- menuProc = menuCallback.getAddress ();
- if (menuProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- mouseHoverCallback = new Callback (this, "mouseHoverProc", 2); //$NON-NLS-1$
- mouseHoverProc = mouseHoverCallback.getAddress ();
- if (mouseHoverProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- mouseCallback = new Callback (this, "mouseProc", 3); //$NON-NLS-1$
- mouseProc = mouseCallback.getAddress ();
- if (mouseProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- timerCallback = new Callback (this, "timerProc", 2); //$NON-NLS-1$
- timerProc = timerCallback.getAddress ();
- if (timerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- trackingCallback = new Callback (this, "trackingProc", 6); //$NON-NLS-1$
- trackingProc = trackingCallback.getAddress ();
- if (trackingProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- windowCallback = new Callback (this, "windowProc", 3); //$NON-NLS-1$
- windowProc = windowCallback.getAddress ();
- if (windowProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- colorCallback = new Callback (this, "colorProc", 4); //$NON-NLS-1$
- colorProc = colorCallback.getAddress ();
- if (colorProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- textInputCallback = new Callback (this, "textInputProc", 3); //$NON-NLS-1$
- textInputProc = textInputCallback.getAddress ();
- if (textInputProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- appearanceCallback = new Callback (this, "appearanceProc", 3); //$NON-NLS-1$
- appearanceProc = appearanceCallback.getAddress ();
- if (appearanceProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- trayItemCallback = new Callback (this, "trayItemProc", 4); //$NON-NLS-1$
- trayItemProc = trayItemCallback.getAddress ();
- if (trayItemProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- observerCallback = new Callback (this, "observerProc", 3); //$NON-NLS-1$
- observerProc = observerCallback.getAddress ();
- if (observerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- sourceCallback = new Callback (this, "sourceProc", 1); //$NON-NLS-1$
- sourceProc = sourceCallback.getAddress ();
- if (sourceProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- searchCallback = new Callback (this, "searchProc", 3); //$NON-NLS-1$
- searchProc = searchCallback.getAddress ();
- if (searchProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- releaseCallback = new Callback (this, "releaseDataProc", 3); //$NON-NLS-1$
- releaseProc = releaseCallback.getAddress ();
- if (releaseProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- coreEventCallback = new Callback (this, "coreEventProc", 3); //$NON-NLS-1$
- coreEventProc = coreEventCallback.getAddress ();
- if (coreEventProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- pollingCallback = new Callback (this, "pollingProc", 2);
- pollingProc = pollingCallback.getAddress ();
- if (pollingProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- /* Install Event Handlers */
- int[] mask1 = new int[] {
- OS.kEventClassCommand, OS.kEventProcessCommand,
- };
- int appTarget = OS.GetApplicationEventTarget ();
- OS.InstallEventHandler (appTarget, commandProc, mask1.length / 2, mask1, 0, null);
- int[] mask2 = new int[] {
- OS.kEventClassMouse, OS.kEventMouseDown,
- OS.kEventClassMouse, OS.kEventMouseDragged,
-// OS.kEventClassMouse, OS.kEventMouseEntered,
-// OS.kEventClassMouse, OS.kEventMouseExited,
- OS.kEventClassMouse, OS.kEventMouseMoved,
- OS.kEventClassMouse, OS.kEventMouseUp,
- OS.kEventClassMouse, OS.kEventMouseWheelMoved,
- };
- OS.InstallEventHandler (appTarget, mouseProc, mask2.length / 2, mask2, 0, null);
- int [] mask3 = new int[] {
- OS.kEventClassApplication, OS.kEventAppAvailableWindowBoundsChanged,
- OS.kEventClassAppleEvent, OS.kEventAppleEvent,
- };
- OS.InstallEventHandler (appTarget, appleEventProc, mask3.length / 2, mask3, 0, null);
- OS.AEInstallEventHandler(OS.kCoreEventClass, OS.kAEQuitApplication, coreEventProc, 0, false);
-
- int [] mask4 = new int[] {
- OS.kEventClassKeyboard, OS.kEventRawKeyDown,
- OS.kEventClassKeyboard, OS.kEventRawKeyModifiersChanged,
- OS.kEventClassKeyboard, OS.kEventRawKeyRepeat,
- OS.kEventClassKeyboard, OS.kEventRawKeyUp,
- };
- int focusTarget = OS.GetUserFocusEventTarget ();
- OS.InstallEventHandler (focusTarget, keyboardProc, mask4.length / 2, mask4, 0, null);
- int [] mask5 = new int[] {
- OS.kEventClassTextInput, OS.kEventTextInputUnicodeForKeyEvent,
- OS.kEventClassTextInput, OS.kEventTextInputUpdateActiveInputArea,
- OS.kEventClassTextInput, OS.kEventTextInputOffsetToPos,
- OS.kEventClassTextInput, OS.kEventTextInputPosToOffset,
- OS.kEventClassTextInput, OS.kEventTextInputGetSelectedText,
- };
- OS.InstallEventHandler (focusTarget, textInputProc, mask5.length / 2, mask5, 0, null);
- OS.AEInstallEventHandler (OS.kAppearanceEventClass, OS.kAEAppearanceChanged, appearanceProc, 0, false);
- OS.AEInstallEventHandler (OS.kAppearanceEventClass, OS.kAESmallSystemFontChanged, appearanceProc, 0, false);
- OS.AEInstallEventHandler (OS.kAppearanceEventClass, OS.kAESystemFontChanged, appearanceProc, 0, false);
- OS.AEInstallEventHandler (OS.kAppearanceEventClass, OS.kAEViewsFontChanged, appearanceProc, 0, false);
-
- int mode = OS.kCFRunLoopCommonModes ();
- int activities = OS.kCFRunLoopBeforeWaiting;
- runLoopObserver = OS.CFRunLoopObserverCreate (OS.kCFAllocatorDefault, activities, true, 0, observerProc, 0);
- if (runLoopObserver == 0) error (SWT.ERROR_NO_HANDLES);
- OS.CFRunLoopAddObserver (runLoop, runLoopObserver, mode);
- CFRunLoopSourceContext context = new CFRunLoopSourceContext ();
- context.version = 0;
- context.perform = sourceProc;
- runLoopSource = OS.CFRunLoopSourceCreate (OS.kCFAllocatorDefault, 0, context);
- if (runLoopSource == 0) error (SWT.ERROR_NO_HANDLES);
- OS.CFRunLoopAddSource (runLoop, runLoopSource, mode);
-}
-
-void initializeFonts () {
- //TEMPORARY CODE
- smallFonts = System.getProperty("org.eclipse.swt.internal.carbon.smallFonts") != null; //$NON-NLS-1$
-}
-
-void initializeInsets () {
- int [] outControl = new int [1];
- Rect rect = new Rect ();
- rect.right = rect.bottom = (short) 200;
-
- OS.CreatePushButtonControl (0, rect, 0, outControl);
- buttonInset = computeInset (outControl [0]);
- OS.DisposeControl (outControl [0]);
-
- OS.CreateTabsControl (0, rect, (short)OS.kControlTabSizeLarge, (short)OS.kControlTabDirectionNorth, (short) 0, 0, outControl);
- tabFolderNorthInset = computeInset (outControl [0]);
- OS.DisposeControl (outControl [0]);
-
- OS.CreateTabsControl (0, rect, (short)OS.kControlTabSizeLarge, (short)OS.kControlTabDirectionSouth, (short) 0, 0, outControl);
- tabFolderSouthInset = computeInset (outControl [0]);
- OS.DisposeControl (outControl [0]);
-
- OS.CreateEditUnicodeTextControl (0, rect, 0, false, null, outControl);
- editTextInset = computeInset (outControl [0]);
- OS.DisposeControl (outControl [0]);
-
- int attributes = OS.kHISearchFieldAttributesSearchIcon | OS.kHISearchFieldAttributesCancel;
- OS.HISearchFieldCreate (null, attributes, 0, 0, outControl);
- if (smallFonts) {
- OS.SetControlData (outControl[0], OS.kControlEntireControl, OS.kControlSizeTag, 2, new short [] {OS.kControlSizeSmall});
- }
- searchTextInset = computeInset (outControl [0]);
- //FIXME -
- searchTextInset.bottom = searchTextInset.top;
- OS.DisposeControl (outControl [0]);
-
- CGRect cgRect = new CGRect ();
- cgRect.width = cgRect.height = 200;
- int inAttributes = OS.kHIComboBoxAutoCompletionAttribute | OS.kHIComboBoxAutoSizeListAttribute;
- OS.HIComboBoxCreate (cgRect, 0, null, 0, inAttributes, outControl);
- comboInset = computeInset (outControl [0]);
- //FIXME -
- comboInset.bottom = comboInset.top;
- OS.DisposeControl (outControl [0]);
-}
-
-void initializeWidgetTable () {
- property = new int [1];
- indexTable = new int [GROW_SIZE];
- widgetTable = new Widget [GROW_SIZE];
- for (int i=0; i<GROW_SIZE-1; i++) indexTable [i] = i + 1;
- indexTable [GROW_SIZE - 1] = -1;
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Display</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for gc creation</li>
- * </ul>
- */
-public int internal_new_GC (GCData data) {
- if (isDisposed()) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
- //TODO - multiple monitors
- int window = gcWindow;
- if (window == 0) {
- window = gcWindow = createOverlayWindow ();
- } else {
- int gdevice = OS.GetMainDevice ();
- int [] ptr = new int [1];
- OS.memmove (ptr, gdevice, 4);
- GDevice device = new GDevice ();
- OS.memmove (device, ptr [0], GDevice.sizeof);
- Rect rect = new Rect ();
- OS.SetRect (rect, device.left, device.top, device.right, device.bottom);
- OS.SetWindowBounds (window, (short) OS.kWindowStructureRgn, rect);
- }
- int port = OS.GetWindowPort (window);
- int [] buffer = new int [1];
- OS.CreateCGContextForPort (port, buffer);
- int context = buffer [0];
- if (context == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- Rect portRect = new Rect ();
- OS.GetPortBounds (port, portRect);
- OS.CGContextScaleCTM (context, 1, -1);
- OS.CGContextTranslateCTM (context, 0, portRect.top - portRect.bottom);
- if (data != null) {
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) == 0) {
- data.style |= SWT.LEFT_TO_RIGHT;
- }
- data.device = this;
- data.window = window;
- data.background = getSystemColor (SWT.COLOR_WHITE).handle;
- data.foreground = getSystemColor (SWT.COLOR_BLACK).handle;
- data.font = getSystemFont ();
- data.updateClip = true;
- data.portRect = portRect;
- } else {
- OS.ShowWindow (window);
- }
- return context;
-}
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Display</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int context, GCData data) {
- if (isDisposed()) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
- if (data != null) {
- int window = data.window;
- if (gcWindow == window) {
- OS.HideWindow (window);
- } else {
- OS.DisposeWindow (window);
- }
- data.window = 0;
- }
-
- /*
- * This code is intentionaly commented. Use CGContextSynchronize
- * instead of CGContextFlush to improve performance.
- */
-// OS.CGContextFlush (context);
- OS.CGContextSynchronize (context);
- OS.CGContextRelease (context);
-}
-
-static boolean isValidClass (Class clazz) {
- String name = clazz.getName ();
- int index = name.lastIndexOf ('.');
- return name.substring (0, index + 1).equals (PACKAGE_PREFIX);
-}
-
-boolean isValidThread () {
- return thread == Thread.currentThread ();
-}
-
-int itemCompareProc (int browser, int itemOne, int itemTwo, int sortProperty) {
- Widget widget = getWidget (browser);
- if (widget != null) return widget.itemCompareProc (browser, itemOne, itemTwo, sortProperty);
- return OS.noErr;
-}
-
-int itemDataProc (int browser, int item, int property, int itemData, int setValue) {
- Widget widget = getWidget (browser);
- if (widget != null) return widget.itemDataProc (browser, item, property, itemData, setValue);
- return OS.noErr;
-}
-
-int itemNotificationProc (int browser, int item, int message) {
- Widget widget = getWidget (browser);
- if (widget != null) return widget.itemNotificationProc (browser, item, message);
- return OS.noErr;
-}
-
-int keyboardProc (int nextHandler, int theEvent, int userData) {
- int theWindow = OS.GetUserFocusWindow ();
- if (theWindow != 0) {
- Widget widget = getFocusControl (theWindow, false);
- if (widget != null) {
- MenuTrackingData outData = new MenuTrackingData ();
- if (OS.GetMenuTrackingData (0, outData) != OS.noErr) {
- return widget.keyboardProc (nextHandler, theEvent, userData);
- }
- }
- }
- return OS.eventNotHandledErr;
-}
-
-int pollingProc (int inTimer, int inUserData) {
- if (grabControl == null || grabControl.isDisposed ()) return 0;
- grabControl.sendTrackEvents ();
- return 0;
-}
-
-/**
- * Generate a low level system event.
- *
- * <code>post</code> is used to generate low level keyboard
- * and mouse events. The intent is to enable automated UI
- * testing by simulating the input from the user. Most
- * SWT applications should never need to call this method.
- * <p>
- * Note that this operation can fail when the operating system
- * fails to generate the event for any reason. For example,
- * this can happen when there is no such key or mouse button
- * or when the system event queue is full.
- * </p>
- * <p>
- * <b>Event Types:</b>
- * <p>KeyDown, KeyUp
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type KeyDown or KeyUp</li>
- * <p> Either one of:
- * <li>(in) character a character that corresponds to a keyboard key</li>
- * <li>(in) keyCode the key code of the key that was typed,
- * as defined by the key code constants in class <code>SWT</code></li>
- * </ul>
- * <p>MouseDown, MouseUp</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseDown or MouseUp
- * <li>(in) button the button that is pressed or released
- * </ul>
- * <p>MouseMove</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseMove
- * <li>(in) x the x coordinate to move the mouse pointer to in screen coordinates
- * <li>(in) y the y coordinate to move the mouse pointer to in screen coordinates
- * </ul>
- * <p>MouseWheel</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseWheel
- * <li>(in) detail either SWT.SCROLL_LINE or SWT.SCROLL_PAGE
- * <li>(in) count the number of lines or pages to scroll
- * </ul>
- * </dl>
- *
- * @param event the event to be generated
- *
- * @return true if the event was generated or false otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public boolean post(Event event) {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- int type = event.type;
- switch (type) {
- case SWT.KeyDown:
- case SWT.KeyUp: {
- int vKey = Display.untranslateKey (event.keyCode);
- if (vKey != 0) {
- return OS.CGPostKeyboardEvent (0, vKey, type == SWT.KeyDown) == 0;
- } else {
- int kchrPtr = OS.GetScriptManagerVariable ((short) OS.smKCHRCache);
- int key = -1;
- int [] encoding = new int [1];
- short keyScript = (short) OS.GetScriptManagerVariable ((short) OS.smKeyScript);
- short regionCode = (short) OS.GetScriptManagerVariable ((short) OS.smRegionCode);
- if (OS.UpgradeScriptInfoToTextEncoding (keyScript, (short) OS.kTextLanguageDontCare, regionCode, null, encoding) == OS.paramErr) {
- if (OS.UpgradeScriptInfoToTextEncoding (keyScript, (short) OS.kTextLanguageDontCare, (short) OS.kTextRegionDontCare, null, encoding) == OS.paramErr) {
- encoding [0] = OS.kTextEncodingMacRoman;
- }
- }
- int [] encodingInfo = new int [1];
- OS.CreateUnicodeToTextInfoByEncoding (encoding [0], encodingInfo);
- if (encodingInfo [0] != 0) {
- char [] input = {event.character};
- byte [] buffer = new byte [2];
- OS.ConvertFromUnicodeToPString (encodingInfo [0], 2, input, buffer);
- OS.DisposeUnicodeToTextInfo (encodingInfo);
- key = buffer [1] & 0x7f;
- }
- if (key == -1) return false;
- int [] state = new int [1];
- vKey = -1;
- for (int i = 0 ; i <= 0x7F ; i++) {
- int result = OS.KeyTranslate (kchrPtr, (short) i, state);
- if ((result & 0x7F) == key) {
- vKey = i;
- break;
- }
- }
- if (vKey == -1) {
- for (int i = 0 ; i <= 0x7F ; i++) {
- int result = OS.KeyTranslate (kchrPtr, (short) (i | OS.shiftKey), state);
- if ((result & 0x7F) == key) {
- vKey = i;
- break;
- }
- }
- }
- if (vKey == -1) return false;
- return OS.CGPostKeyboardEvent (key, vKey, type == SWT.KeyDown) == 0;
- }
- }
- case SWT.MouseDown:
- case SWT.MouseMove:
- case SWT.MouseUp: {
- CGPoint mouseCursorPosition = new CGPoint ();
- int chord = OS.GetCurrentEventButtonState ();
- if (type == SWT.MouseMove) {
- mouseCursorPosition.x = event.x;
- mouseCursorPosition.y = event.y;
- return OS.CGPostMouseEvent (mouseCursorPosition, true, 5, (chord & 0x1) != 0, (chord & 0x2) != 0, (chord & 0x4) != 0, (chord & 0x8) != 0, (chord & 0x10) != 0) == 0;
- } else {
- int button = event.button;
- if (button < 1 || button > 5) return false;
- boolean button1 = false, button2 = false, button3 = false, button4 = false, button5 = false;
- switch (button) {
- case 1: {
- button1 = type == SWT.MouseDown;
- button2 = (chord & 0x4) != 0;
- button3 = (chord & 0x2) != 0;
- button4 = (chord & 0x8) != 0;
- button5 = (chord & 0x10) != 0;
- break;
- }
- case 2: {
- button1 = (chord & 0x1) != 0;
- button2 = type == SWT.MouseDown;
- button3 = (chord & 0x2) != 0;
- button4 = (chord & 0x8) != 0;
- button5 = (chord & 0x10) != 0;
- break;
- }
- case 3: {
- button1 = (chord & 0x1) != 0;
- button2 = (chord & 0x4) != 0;
- button3 = type == SWT.MouseDown;
- button4 = (chord & 0x8) != 0;
- button5 = (chord & 0x10) != 0;
- break;
- }
- case 4: {
- button1 = (chord & 0x1) != 0;
- button2 = (chord & 0x4) != 0;
- button3 = (chord & 0x2) != 0;
- button4 = type == SWT.MouseDown;
- button5 = (chord & 0x10) != 0;
- break;
- }
- case 5: {
- button1 = (chord & 0x1) != 0;
- button2 = (chord & 0x4) != 0;
- button3 = (chord & 0x2) != 0;
- button4 = (chord & 0x8) != 0;
- button5 = type == SWT.MouseDown;
- break;
- }
- }
- org.eclipse.swt.internal.carbon.Point pt = new org.eclipse.swt.internal.carbon.Point ();
- OS.GetGlobalMouse (pt);
- mouseCursorPosition.x = pt.h;
- mouseCursorPosition.y = pt.v;
- return OS.CGPostMouseEvent (mouseCursorPosition, true, 5, button1, button3, button2, button4, button5) == 0;
- }
- }
- case SWT.MouseWheel: {
- return OS.CGPostScrollWheelEvent (1, event.count) == 0;
- }
- }
- return false;
- }
-}
-
-void postEvent (Event event) {
- /*
- * Place the event at the end of the event queue.
- * This code is always called in the Display's
- * thread so it must be re-enterant but does not
- * need to be synchronized.
- */
- if (eventQueue == null) eventQueue = new Event [4];
- int index = 0;
- int length = eventQueue.length;
- while (index < length) {
- if (eventQueue [index] == null) break;
- index++;
- }
- if (index == length) {
- Event [] newQueue = new Event [length + 4];
- System.arraycopy (eventQueue, 0, newQueue, 0, length);
- eventQueue = newQueue;
- }
- eventQueue [index] = event;
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param point to be mapped
- * @return point with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Point map (Control from, Control to, Point point) {
- checkDevice ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return map (from, to, point.x, point.y);
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param x coordinates to be mapped
- * @param y coordinates to be mapped
- * @return point with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Point map (Control from, Control to, int x, int y) {
- checkDevice ();
- if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- Point point = new Point (x, y);
- if (from == to) return point;
- Rect rect = new Rect ();
- if (from != null) {
- int window = OS.GetControlOwner (from.handle);
- CGPoint pt = new CGPoint ();
- OS.HIViewConvertPoint (pt, from.handle, 0);
- point.x += (int) pt.x;
- point.y += (int) pt.y;
- OS.GetWindowBounds (window, (short) OS.kWindowStructureRgn, rect);
- point.x += rect.left;
- point.y += rect.top;
- Rect inset = from.getInset ();
- point.x -= inset.left;
- point.y -= inset.top;
- }
- if (to != null) {
- int window = OS.GetControlOwner (to.handle);
- CGPoint pt = new CGPoint ();
- OS.HIViewConvertPoint (pt, to.handle, 0);
- point.x -= (int) pt.x;
- point.y -= (int) pt.y;
- OS.GetWindowBounds (window, (short) OS.kWindowStructureRgn, rect);
- point.x -= rect.left;
- point.y -= rect.top;
- Rect inset = to.getInset ();
- point.x += inset.left;
- point.y += inset.top;
- }
- return point;
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param rectangle to be mapped
- * @return rectangle with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Rectangle map (Control from, Control to, Rectangle rectangle) {
- checkDevice ();
- if (rectangle == null) error (SWT.ERROR_NULL_ARGUMENT);
- return map (from, to, rectangle.x, rectangle.y, rectangle.width, rectangle.height);
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param x coordinates to be mapped
- * @param y coordinates to be mapped
- * @param width coordinates to be mapped
- * @param height coordinates to be mapped
- * @return rectangle with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Rectangle map (Control from, Control to, int x, int y, int width, int height) {
- checkDevice ();
- if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- Rectangle rectangle = new Rectangle (x, y, width, height);
- if (from == to) return rectangle;
- Rect rect = new Rect ();
- if (from != null) {
- int window = OS.GetControlOwner (from.handle);
- CGPoint pt = new CGPoint ();
- OS.HIViewConvertPoint (pt, from.handle, 0);
- rectangle.x += (int) pt.x;
- rectangle.y += (int) pt.y;
- OS.GetWindowBounds (window, (short) OS.kWindowStructureRgn, rect);
- rectangle.x += rect.left;
- rectangle.y += rect.top;
- Rect inset = from.getInset ();
- rectangle.x -= inset.left;
- rectangle.y -= inset.top;
- }
- if (to != null) {
- int window = OS.GetControlOwner (to.handle);
- CGPoint pt = new CGPoint ();
- OS.HIViewConvertPoint (pt, to.handle, 0);
- rectangle.x -= (int) pt.x;
- rectangle.y -= (int) pt.y;
- OS.GetWindowBounds (window, (short) OS.kWindowStructureRgn, rect);
- rectangle.x -= rect.left;
- rectangle.y -= rect.top;
- Rect inset = to.getInset ();
- rectangle.x += inset.left;
- rectangle.y += inset.top;
- }
- return rectangle;
-}
-
-int menuProc (int nextHandler, int theEvent, int userData) {
- short menuID = 0;
- if (userData != 0) {
- menuID = OS.GetMenuID (userData);
- } else {
- int [] theMenu = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamDirectObject, OS.typeMenuRef, null, 4, null, theMenu);
- menuID = OS.GetMenuID (theMenu [0]);
- }
- Menu menu = getMenu (menuID);
- if (menu != null) return menu.menuProc (nextHandler, theEvent, userData);
- return OS.eventNotHandledErr;
-}
-
-int mouseProc (int nextHandler, int theEvent, int userData) {
- int eventKind = OS.GetEventKind (theEvent);
- switch (eventKind) {
- case OS.kEventMouseDown:
- short [] buttonData = new short [1];
- OS.GetEventParameter (theEvent, OS.kEventParamMouseButton, OS.typeMouseButton, null, 2, null, buttonData);
- int [] clickCountData = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamClickCount, OS.typeUInt32, null, 4, null, clickCountData);
- clickCount = clickCountButton == buttonData [0] ? clickCountData [0] : 1;
- clickCountButton = buttonData [0];
- break;
- case OS.kEventMouseDragged:
- case OS.kEventMouseMoved:
- mouseMoved = true;
- if (!OS.CGCursorIsVisible ()) OS.CGDisplayShowCursor (OS.CGMainDisplayID ());
- }
- int sizeof = org.eclipse.swt.internal.carbon.Point.sizeof;
- org.eclipse.swt.internal.carbon.Point where = new org.eclipse.swt.internal.carbon.Point ();
- OS.GetEventParameter (theEvent, OS.kEventParamMouseLocation, OS.typeQDPoint, null, sizeof, null, where);
- int [] theWindow = new int [1];
- int part = OS.FindWindow (where, theWindow);
- switch (part) {
- case OS.inMenuBar: {
- if (eventKind == OS.kEventMouseDown) {
- clearMenuFlags ();
- if (menuBar == null || menuBar.isEnabled ()) {
- OS.MenuSelect (where);
- }
- clearMenuFlags ();
- return OS.noErr;
- }
- break;
- }
- case OS.inContent: {
- Rect windowRect = new Rect ();
- OS.GetWindowBounds (theWindow [0], (short) OS.kWindowContentRgn, windowRect);
- CGPoint inPoint = new CGPoint ();
- inPoint.x = where.h - windowRect.left;
- inPoint.y = where.v - windowRect.top;
- int root = OS.HIViewGetRoot (theWindow [0]);
- int [] buffer = new int [1];
- OS.HIViewGetViewForMouseEvent (root, theEvent, buffer);
- int view = buffer [0];
- OS.HIViewFindByID (root, OS.kHIViewWindowContentID (), buffer);
- int contentView = buffer [0];
- while (view != 0 && view != contentView && !OS.IsControlEnabled (view)) {
- view = OS.HIViewGetSuperview (view);
- }
- Widget widget = null;
- boolean consume = false;
- do {
- widget = getWidget (view);
- if (widget != null) {
- if (widget.isEnabled ()) break;
- consume = true;
- }
- view = OS.HIViewGetSuperview (view);
- } while (view != 0 && view != contentView);
- if (widget != null) {
- if (widget.contains ((int) inPoint.x, (int) inPoint.y)) {
- int result = userData != 0 ? widget.mouseProc (nextHandler, theEvent, userData) : OS.eventNotHandledErr;
- return consume ? OS.noErr : result;
- }
- }
- break;
- }
- }
- switch (eventKind) {
- case OS.kEventMouseDragged:
- case OS.kEventMouseMoved: OS.InitCursor ();
- }
- return OS.eventNotHandledErr;
-}
-
-int mouseHoverProc (int id, int handle) {
- OS.RemoveEventLoopTimer (id);
- mouseHoverID = 0;
- mouseMoved = false;
- if (currentControl != null && !currentControl.isDisposed ()) {
- //OPTIMIZE - use OS calls
- int chord = OS.GetCurrentEventButtonState ();
- int modifiers = OS.GetCurrentEventKeyModifiers ();
- Point pt = currentControl.toControl (getCursorLocation ());
- currentControl.sendMouseEvent (SWT.MouseHover, (short)0, 0, true, chord, (short)pt.x, (short)pt.y, modifiers);
- }
- return 0;
-}
-
-int observerProc (int observer, int activity, int info) {
- switch (activity) {
- case OS.kCFRunLoopBeforeWaiting:
- if (runAsyncMessages) {
- if (runAsyncMessages (false)) wakeThread ();
- }
- break;
- }
- return 0;
-}
-
-int readImageRef(int path) {
- int image = 0;
- int url = OS.CFURLCreateFromFileSystemRepresentation(OS.kCFAllocatorDefault, path, OS.strlen(path), false);
- if (url != 0) {
- int extention = OS.CFURLCopyPathExtension(url);
- if (extention != 0) {
- int length = OS.CFStringGetLength(extention);
- char[] buffer = new char[length];
- CFRange range = new CFRange();
- range.length = length;
- OS.CFStringGetCharacters(extention, range, buffer);
- String ext = new String(buffer);
- if (ext.equalsIgnoreCase("png")) { //$NON-NLS-1$
- int provider = OS.CGDataProviderCreateWithURL(url);
- if (provider != 0) {
- image = OS.CGImageCreateWithPNGDataProvider(provider, null, true, OS.kCGRenderingIntentDefault);
- OS.CGDataProviderRelease(provider);
- }
- } else if (ext.equalsIgnoreCase("jpeg") || ext.equals("jpg")) { //$NON-NLS-1$ //$NON-NLS-2$
- int provider = OS.CGDataProviderCreateWithURL(url);
- if (provider != 0) {
- image = OS.CGImageCreateWithJPEGDataProvider(provider, null, true, OS.kCGRenderingIntentDefault);
- OS.CGDataProviderRelease(provider);
- }
- } else if (ext.equalsIgnoreCase("icns")) { //$NON-NLS-1$
- byte[] fsRef = new byte[80];
- if (OS.CFURLGetFSRef(url, fsRef)) {
- byte[] fsSpec = new byte[70];
- if (OS.FSGetCatalogInfo(fsRef, 0, null, null, fsSpec, null) == OS.noErr) {
- int[] iconFamily = new int[1];
- OS.ReadIconFile(fsSpec, iconFamily);
- if (iconFamily[0] != 0) {
- int[] icon = createImageFromFamily(iconFamily[0], OS.kThumbnail32BitData, OS.kThumbnail8BitMask, 128, 128);
- if (icon == null) icon = createImageFromFamily(iconFamily[0], OS.kHuge32BitData, OS.kHuge8BitMask, 64, 64);
- if (icon == null) icon = createImageFromFamily(iconFamily[0], OS.kLarge32BitData, OS.kLarge8BitMask, 32, 32);
- if (icon != null) image = icon[0];
- OS.DisposeHandle(iconFamily[0]);
- }
- }
- }
- }
- OS.CFRelease(extention);
- }
- OS.CFRelease(url);
- }
- return image;
-}
-
-/**
- * Reads an event from the operating system's event queue,
- * dispatches it appropriately, and returns <code>true</code>
- * if there is potentially more work to do, or <code>false</code>
- * if the caller can sleep until another event is placed on
- * the event queue.
- * <p>
- * In addition to checking the system event queue, this method also
- * checks if any inter-thread messages (created by <code>syncExec()</code>
- * or <code>asyncExec()</code>) are waiting to be processed, and if
- * so handles them before returning.
- * </p>
- *
- * @return <code>false</code> if the caller can sleep upon return from this method
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li>
- * </ul>
- *
- * @see #sleep
- * @see #wake
- */
-public boolean readAndDispatch () {
- checkDevice ();
- boolean events = false;
- events |= runSettings ();
- events |= runTimers ();
- events |= runPopups ();
- int [] outEvent = new int [1];
- int status = OS.ReceiveNextEvent (0, null, OS.kEventDurationNoWait, true, outEvent);
- if (status == OS.noErr) {
- events = true;
- OS.SendEventToEventTarget (outEvent [0], OS.GetEventDispatcherTarget ());
- OS.ReleaseEvent (outEvent [0]);
-
- /*
- * Feature in the Macintosh. HIComboBox does not send any
- * notification when the selection changes. The fix is to
- * detect if the combo text has changed after every event
- * has been dispatched. This is only necessary when the
- * combo has focus.
- */
- if (focusCombo != null && !focusCombo.isDisposed ()) {
- focusCombo.checkSelection ();
- }
- }
- events |= runPaint ();
- if (events) {
- runEnterExit ();
- runDeferredEvents ();
- return true;
- }
- return isDisposed () || runAsyncMessages (false);
-}
-
-static void register (Display display) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] == null) {
- Displays [i] = display;
- return;
- }
- }
- Display [] newDisplays = new Display [Displays.length + 4];
- System.arraycopy (Displays, 0, newDisplays, 0, Displays.length);
- newDisplays [Displays.length] = display;
- Displays = newDisplays;
- }
-}
-
-/**
- * Releases any internal resources back to the operating
- * system and clears all fields except the device handle.
- * <p>
- * Disposes all shells which are currently open on the display.
- * After this method has been invoked, all related related shells
- * will answer <code>true</code> when sent the message
- * <code>isDisposed()</code>.
- * </p><p>
- * When a device is destroyed, resources that were acquired
- * on behalf of the programmer need to be returned to the
- * operating system. For example, if the device allocated a
- * font to be used as the system font, this font would be
- * freed in <code>release</code>. Also,to assist the garbage
- * collector and minimize the amount of memory that is not
- * reclaimed when the programmer keeps a reference to a
- * disposed device, all fields except the handle are zero'd.
- * The handle is needed by <code>destroy</code>.
- * </p>
- * This method is called before <code>destroy</code>.
- *
- * @see Device#dispose
- * @see #destroy
- */
-protected void release () {
- disposing = true;
- sendEvent (SWT.Dispose, new Event ());
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) shell.dispose ();
- }
- if (tray != null) tray.dispose ();
- tray = null;
- while (readAndDispatch ()) {}
- if (disposeList != null) {
- for (int i=0; i<disposeList.length; i++) {
- if (disposeList [i] != null) disposeList [i].run ();
- }
- }
- disposeList = null;
- synchronizer.releaseSynchronizer ();
- synchronizer = null;
- releaseDisplay ();
- super.release ();
-}
-
-void releaseDisplay () {
- disposeWindows ();
-
- if (gcWindow != 0) OS.DisposeWindow (gcWindow);
- gcWindow = 0;
-
- /* Release Timers */
- if (caretID != 0) OS.RemoveEventLoopTimer (caretID);
- if (mouseHoverID != 0) OS.RemoveEventLoopTimer (mouseHoverID);
- caretID = mouseHoverID = 0;
- if (timerIds != null) {
- for (int i=0; i<timerIds.length; i++) {
- if (timerIds [i] != 0 && timerIds [i] != -1) {
- OS.RemoveEventLoopTimer (timerIds [i]);
- }
- }
- }
- timerIds = null;
-
- /* Release the System Images */
- if (errorImage != null) errorImage.dispose ();
- if (infoImage != null) infoImage.dispose ();
- if (warningImage != null) warningImage.dispose ();
- errorImage = infoImage = warningImage = null;
-
- /* Release the System Cursors */
- for (int i = 0; i < cursors.length; i++) {
- if (cursors [i] != null) cursors [i].dispose ();
- }
- cursors = null;
-
- /* Release Dock image */
- if (dockImage != 0) OS.CGImageRelease (dockImage);
- dockImage = 0;
-
- if (runLoopObserver != 0) {
- OS.CFRunLoopObserverInvalidate (runLoopObserver);
- OS.CFRelease (runLoopObserver);
- }
- if (runLoopSource != 0) {
- OS.CFRunLoopSourceInvalidate (runLoopSource);
- OS.CFRelease (runLoopSource);
- }
- runLoop = runLoopSource = runLoopObserver = 0;
-
- releaseCallback.dispose ();
- actionCallback.dispose ();
- appleEventCallback.dispose ();
- caretCallback.dispose ();
- clockCallback.dispose ();
- commandCallback.dispose ();
- controlCallback.dispose ();
- accessibilityCallback.dispose ();
- drawItemCallback.dispose ();
- itemCompareCallback.dispose ();
- itemDataCallback.dispose ();
- itemNotificationCallback.dispose ();
- helpCallback.dispose ();
- hitTestCallback.dispose ();
- keyboardCallback.dispose ();
- menuCallback.dispose ();
- mouseHoverCallback.dispose ();
- mouseCallback.dispose ();
- trackingCallback.dispose ();
- windowCallback.dispose ();
- colorCallback.dispose ();
- textInputCallback.dispose ();
- appearanceCallback.dispose ();
- trayItemCallback.dispose ();
- observerCallback.dispose ();
- sourceCallback.dispose ();
- searchCallback.dispose ();
- coreEventCallback.dispose ();
- pollingCallback.dispose ();
- actionCallback = appleEventCallback = caretCallback = commandCallback = appearanceCallback = null;
- accessibilityCallback = clockCallback = controlCallback = drawItemCallback = itemDataCallback = itemNotificationCallback = null;
- helpCallback = hitTestCallback = keyboardCallback = menuCallback = itemCompareCallback = searchCallback = trayItemCallback = null;
- mouseHoverCallback = mouseCallback = trackingCallback = windowCallback = colorCallback = observerCallback = sourceCallback = null;
- textInputCallback = coreEventCallback = releaseCallback = pollingCallback = null;
- actionProc = appleEventProc = caretProc = commandProc = appearanceProc = searchProc = trayItemProc = 0;
- accessibilityProc = clockProc = controlProc = drawItemProc = itemDataProc = itemNotificationProc = itemCompareProc = 0;
- helpProc = hitTestProc = keyboardProc = menuProc = observerProc = sourceProc = releaseProc = 0;
- mouseHoverProc = mouseProc = trackingProc = windowProc = colorProc = coreEventProc = 0;
- textInputProc = pollingProc = 0;
- timerCallback.dispose ();
- timerCallback = null;
- timerList = null;
- timerProc = 0;
- currentControl = focusControl = focusCombo = null;
- activeShell = null;
- helpWidget = null;
- if (helpString != 0) OS.CFRelease (helpString);
- helpString = 0;
- widgetTable = menus = popups = null;
- modalShells = null;
- menuBar = null;
- eventTable = filterTable = null;
- thread = null;
- indexTable = property = kchrState = null;
- buttonInset = tabFolderNorthInset = tabFolderSouthInset = comboInset = editTextInset = searchTextInset = null;
- data = highlightColor = null;
- values = keys = null;
-
- //NOT DONE - call terminate TXN if this is the last display
- //NOTE: - display create and dispose needs to be synchronized on all platforms
-// TXNTerminateTextension ();
-}
-
-int releaseDataProc (int info, int data, int size) {
- OS.DisposePtr(data);
- return 0;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs anywhere in
- * a widget. The event type is one of the event constants defined
- * in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addFilter
- * @see #addListener
- *
- * @since 3.0
- */
-public void removeFilter (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (filterTable == null) return;
- filterTable.unhook (eventType, listener);
- if (filterTable.size () == 0) filterTable = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs. The event type
- * is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener
- *
- * @since 2.0
- */
-public void removeListener (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, listener);
-}
-
-void removeMenu (Menu menu) {
- if (menus == null) return;
- menus [menu.id - ID_START] = null;
-}
-
-void removePopup (Menu menu) {
- if (popups == null) return;
- for (int i=0; i<popups.length; i++) {
- if (popups [i] == menu) {
- popups [i] = null;
- return;
- }
- }
-}
-
-Widget removeWidget (int handle) {
- if (handle == 0) return null;
- Widget widget = null;
- property [0] = 0;
- OS.GetControlProperty (handle, SWT0, SWT0, 4, null, property);
- int index = property [0] - 1;
- if (0 <= index && index < widgetTable.length) {
- widget = widgetTable [index];
- widgetTable [index] = null;
- indexTable [index] = freeSlot;
- freeSlot = index;
- OS.RemoveControlProperty (handle, SWT0, SWT0);
-
- }
- return widget;
-}
-
-boolean runAsyncMessages (boolean all) {
- return synchronizer.runAsyncMessages (all);
-}
-
-boolean runEnterExit () {
- //OPTIMIZE - no garbage, widget hit tested again in mouse move
- boolean eventSent = false;
- Control control = null;
- int [] theControl = new int [1];
- org.eclipse.swt.internal.carbon.Point where = new org.eclipse.swt.internal.carbon.Point ();
- OS.GetGlobalMouse (where);
- int [] theWindow = new int [1];
- if (OS.FindWindow (where, theWindow) == OS.inContent) {
- if (theWindow [0] != 0) {
- Rect rect = new Rect ();
- OS.GetWindowBounds (theWindow [0], (short) OS.kWindowStructureRgn, rect);
- CGPoint inPoint = new CGPoint ();
- inPoint.x = where.h - rect.left;
- inPoint.y = where.v - rect.top;
- int [] theRoot = new int [1];
- OS.GetRootControl (theWindow [0], theRoot);
- int[] event = new int[1];
- OS.CreateEvent (0, OS.kEventClassMouse, OS.kEventMouseDown, 0.0, 0, event);
- OS.SetEventParameter (event[0], OS.kEventParamWindowMouseLocation, OS.typeHIPoint, CGPoint.sizeof, inPoint);
- OS.HIViewGetViewForMouseEvent (theRoot [0], event [0], theControl);
- OS.ReleaseEvent(event[0]);
- while (theControl [0] != 0 && !OS.IsControlEnabled (theControl [0])) {
- OS.GetSuperControl (theControl [0], theControl);
- }
- boolean propagate = true;
- if (theControl [0] != 0) {
- do {
- Widget widget = getWidget (theControl [0]);
- if (widget != null) {
- if (widget instanceof Control) {
- Control cursorControl = (Control) widget;
- if (cursorControl.isEnabled ()) {
- if (cursorControl.isEnabledModal ()) {
- if (widget.isTrimHandle (theControl [0])) {
- propagate = false;
- break;
- }
- control = cursorControl;
- }
- break;
- }
- }
- }
- OS.GetSuperControl (theControl [0], theControl);
- } while (theControl [0] != 0);
- }
- if (control == null && propagate) {
- theControl [0] = theRoot [0];
- Widget widget = getWidget (theControl [0]);
- if (widget != null && widget instanceof Control) {
- Control cursorControl = (Control) widget;
- if (cursorControl.isEnabled ()) {
- if (cursorControl.isEnabledModal ()) {
- control = cursorControl;
- theControl[0] = control.handle;
- }
- }
- }
- }
- if (control != null && !control.contains ((int) inPoint.x, (int) inPoint.y)) {
- control = null;
- }
- }
- }
- if (control != currentControl) {
- if (currentControl != null && !currentControl.isDisposed ()) {
- eventSent = true;
- int chord = OS.GetCurrentEventButtonState ();
- int modifiers = OS.GetCurrentEventKeyModifiers ();
- Point pt = currentControl.toControl (where.h, where.v);
- currentControl.sendMouseEvent (SWT.MouseExit, (short)0, 0, true, chord, (short)pt.x, (short)pt.y, modifiers);
- if (mouseHoverID != 0) OS.RemoveEventLoopTimer (mouseHoverID);
- mouseHoverID = 0;
- mouseMoved = false;
- }
- // widget could be disposed at this point
- if (control != null && control.isDisposed()) control = null;
- if ((currentControl = control) != null) {
- eventSent = true;
- int chord = OS.GetCurrentEventButtonState ();
- int modifiers = OS.GetCurrentEventKeyModifiers ();
- Point pt = currentControl.toControl (where.h, where.v);
- currentControl.sendMouseEvent (SWT.MouseEnter, (short)0, 0, true, chord, (short)pt.x, (short)pt.y, modifiers);
- }
- }
- if (control != null && mouseMoved) {
- int [] outDelay = new int [1];
- OS.HMGetTagDelay (outDelay);
- if (mouseHoverID != 0) {
- OS.SetEventLoopTimerNextFireTime (mouseHoverID, outDelay [0] / 1000.0);
- } else {
- int eventLoop = OS.GetCurrentEventLoop ();
- int [] id = new int [1];
- OS.InstallEventLoopTimer (eventLoop, outDelay [0] / 1000.0, 0.0, mouseHoverProc, 0, id);
- mouseHoverID = id [0];
- }
- mouseMoved = false;
- }
- if (!OS.StillDown () && theWindow [0] != 0 && theControl [0] != 0) {
- Rect rect = new Rect ();
- OS.GetWindowBounds (theWindow [0], (short) OS.kWindowContentRgn, rect);
- CGPoint pt = new CGPoint ();
- OS.HIViewConvertPoint (pt, theControl [0], 0);
- where.h -= (int) pt.x;
- where.v -= (int) pt.y;
- OS.GetWindowBounds (theWindow [0], (short) OS.kWindowStructureRgn, rect);
- where.h -= rect.left;
- where.v -= rect.top;
- int modifiers = OS.GetCurrentEventKeyModifiers ();
- boolean [] cursorWasSet = new boolean [1];
- OS.HandleControlSetCursor (theControl [0], where, (short) modifiers, cursorWasSet);
- if (!cursorWasSet [0]) OS.SetThemeCursor (OS.kThemeArrowCursor);
- }
- return eventSent;
-}
-
-boolean runDeferredEvents () {
- boolean run = false;
- /*
- * Run deferred events. This code is always
- * called in the Display's thread so it must
- * be re-enterant need not be synchronized.
- */
- while (eventQueue != null) {
-
- /* Take an event off the queue */
- Event event = eventQueue [0];
- if (event == null) break;
- int length = eventQueue.length;
- System.arraycopy (eventQueue, 1, eventQueue, 0, --length);
- eventQueue [length] = null;
-
- /* Run the event */
- Widget widget = event.widget;
- if (widget != null && !widget.isDisposed ()) {
- Widget item = event.item;
- if (item == null || !item.isDisposed ()) {
- run = true;
- widget.notifyListeners (event.type, event);
- }
- }
-
- /*
- * At this point, the event queue could
- * be null due to a recursive invokation
- * when running the event.
- */
- }
-
- /* Clear the queue */
- eventQueue = null;
- return run;
-}
-
-boolean runEventLoopTimers () {
- allowTimers = false;
- boolean result = OS.ReceiveNextEvent (0, null, OS.kEventDurationNoWait, false, null) == OS.noErr;
- allowTimers = true;
- return result;
-}
-
-boolean runPaint () {
- if (!needsPaint) return false;
- needsPaint = false;
- for (int i = 0; i < widgetTable.length; i++) {
- Widget widget = widgetTable [i];
- if (widget != null && widget instanceof Shell) {
- Shell shell = (Shell) widget;
- if (shell.invalRgn != 0) {
- int invalRgn = shell.invalRgn;
- shell.invalRgn = 0;
- shell.redrawChildren (OS.HIViewGetRoot (shell.shellHandle), invalRgn);
- OS.DisposeRgn (invalRgn);
- }
- }
- }
- return true;
-}
-
-boolean runPopups () {
- if (popups == null) return false;
- boolean result = false;
- while (popups != null) {
- Menu menu = popups [0];
- if (menu == null) break;
- int length = popups.length;
- System.arraycopy (popups, 1, popups, 0, --length);
- popups [length] = null;
- clearMenuFlags ();
- runDeferredEvents ();
- if (!menu.isDisposed ()) menu._setVisible (true);
- clearMenuFlags ();
- result = true;
- }
- popups = null;
- return result;
-}
-
-boolean runSettings () {
- if (!runSettings) return false;
- runSettings = false;
- initializeInsets ();
- sendEvent (SWT.Settings, null);
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) {
- shell.redraw (true);
- shell.layout (true, true);
- }
- }
- return true;
-}
-
-boolean runTimers () {
- if (timerList == null) return false;
- boolean result = false;
- for (int i=0; i<timerList.length; i++) {
- if (timerIds [i] == -1) {
- Runnable runnable = timerList [i];
- timerList [i] = null;
- timerIds [i] = 0;
- if (runnable != null) {
- result = true;
- runnable.run ();
- }
- }
- }
- return result;
-}
-
-int searchProc (int nextHandler, int theEvent, int userData) {
- Widget widget = getWidget (userData);
- if (widget != null) return widget.searchProc (nextHandler, theEvent, userData);
- return OS.eventNotHandledErr;
-}
-
-void sendEvent (int eventType, Event event) {
- if (eventTable == null && filterTable == null) {
- return;
- }
- if (event == null) event = new Event ();
- event.display = this;
- event.type = eventType;
- if (event.time == 0) event.time = getLastEventTime ();
- if (!filterEvent (event)) {
- if (eventTable != null) eventTable.sendEvent (event);
- }
-}
-
-/**
- * On platforms which support it, sets the application name
- * to be the argument. On Motif, for example, this can be used
- * to set the name used for resource lookup. Specifying
- * <code>null</code> for the name clears it.
- *
- * @param name the new app name or <code>null</code>
- */
-public static void setAppName (String name) {
- APP_NAME = name;
-}
-
-void setCurrentCaret (Caret caret) {
- if (caretID != 0) OS.RemoveEventLoopTimer (caretID);
- caretID = 0;
- currentCaret = caret;
- if (currentCaret != null) {
- int blinkRate = currentCaret.blinkRate;
- int [] timerId = new int [1];
- double time = blinkRate / 1000.0;
- int eventLoop = OS.GetCurrentEventLoop ();
- OS.InstallEventLoopTimer (eventLoop, time, time, caretProc, 0, timerId);
- caretID = timerId [0];
- }
-}
-
-void setCursor (int cursor) {
- switch (cursor) {
- case OS.kThemePointingHandCursor:
- case OS.kThemeArrowCursor:
- case OS.kThemeSpinningCursor:
- case OS.kThemeCrossCursor:
- case OS.kThemeWatchCursor:
- case OS.kThemeIBeamCursor:
- case OS.kThemeNotAllowedCursor:
- case OS.kThemeResizeLeftRightCursor:
- case OS.kThemeResizeLeftCursor:
- case OS.kThemeResizeRightCursor:
- case OS.kThemeResizeUpDownCursor:
- case OS.kThemeResizeUpCursor:
- case OS.kThemeResizeDownCursor:
- OS.SetThemeCursor (cursor);
- break;
- default:
- if (OS.VERSION >= 0x1040) {
- Cocoa.objc_msgSend (cursor, Cocoa.S_set);
- } else {
- OS.SetCursor (cursor);
- }
- }
-}
-
-/**
- * Sets the location of the on-screen pointer relative to the top left corner
- * of the screen. <b>Note: It is typically considered bad practice for a
- * program to move the on-screen pointer location.</b>
- *
- * @param x the new x coordinate for the cursor
- * @param y the new y coordinate for the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1
- */
-public void setCursorLocation (int x, int y) {
- checkDevice ();
- CGPoint pt = new CGPoint ();
- pt.x = x; pt.y = y;
- OS.CGWarpMouseCursorPosition (pt);
-}
-
-/**
- * Sets the location of the on-screen pointer relative to the top left corner
- * of the screen. <b>Note: It is typically considered bad practice for a
- * program to move the on-screen pointer location.</b>
- *
- * @param point new position
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_NULL_ARGUMENT - if the point is null
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setCursorLocation (Point point) {
- checkDevice ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- setCursorLocation (point.x, point.y);
-}
-
-/**
- * Sets the application defined property of the receiver
- * with the specified name to the given argument.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the display is disposed
- * of, it is the application's responsibility provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param key the name of the property
- * @param value the new value for the property
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getData(String)
- * @see #disposeExec(Runnable)
- */
-public void setData (String key, Object value) {
- checkDevice ();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
-
- if (key.equals (ADD_WIDGET_KEY)) {
- Object [] data = (Object [])value;
- int handle = ((Integer)data [0]).intValue ();
- Widget widget = (Widget)data [1];
- if (widget == null) {
- removeWidget (handle);
- } else {
- addWidget (handle, widget);
- }
- }
-
- /* Remove the key/value pair */
- if (value == null) {
- if (keys == null) return;
- int index = 0;
- while (index < keys.length && !keys [index].equals (key)) index++;
- if (index == keys.length) return;
- if (keys.length == 1) {
- keys = null;
- values = null;
- } else {
- String [] newKeys = new String [keys.length - 1];
- Object [] newValues = new Object [values.length - 1];
- System.arraycopy (keys, 0, newKeys, 0, index);
- System.arraycopy (keys, index + 1, newKeys, index, newKeys.length - index);
- System.arraycopy (values, 0, newValues, 0, index);
- System.arraycopy (values, index + 1, newValues, index, newValues.length - index);
- keys = newKeys;
- values = newValues;
- }
- return;
- }
-
- /* Add the key/value pair */
- if (keys == null) {
- keys = new String [] {key};
- values = new Object [] {value};
- return;
- }
- for (int i=0; i<keys.length; i++) {
- if (keys [i].equals (key)) {
- values [i] = value;
- return;
- }
- }
- String [] newKeys = new String [keys.length + 1];
- Object [] newValues = new Object [values.length + 1];
- System.arraycopy (keys, 0, newKeys, 0, keys.length);
- System.arraycopy (values, 0, newValues, 0, values.length);
- newKeys [keys.length] = key;
- newValues [values.length] = value;
- keys = newKeys;
- values = newValues;
-}
-
-/**
- * Sets the application defined, display specific data
- * associated with the receiver, to the argument.
- * The <em>display specific data</em> is a single,
- * unnamed field that is stored with every display.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the display specific data needs to
- * be notified when the display is disposed of, it is the
- * application's responsibility provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param data the new display specific data
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getData()
- * @see #disposeExec(Runnable)
- */
-public void setData (Object data) {
- checkDevice ();
- this.data = data;
-}
-
-/**
- * Sets the synchronizer used by the display to be
- * the argument, which can not be null.
- *
- * @param synchronizer the new synchronizer for the display (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the synchronizer is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li>
- * </ul>
- */
-public void setSynchronizer (Synchronizer synchronizer) {
- checkDevice ();
- if (synchronizer == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (synchronizer == this.synchronizer) return;
- Synchronizer oldSynchronizer;
- synchronized (Device.class) {
- oldSynchronizer = this.synchronizer;
- this.synchronizer = synchronizer;
- }
- if (oldSynchronizer != null) {
- oldSynchronizer.runAsyncMessages(true);
- }
-}
-
-void setMenuBar (Menu menu) {
- /*
- * Feature in the Macintosh. SetRootMenu() does not
- * accept NULL to indicate that their should be no
- * menu bar. The fix is to create a temporary empty
- * menu, set that to be the menu bar, clear the menu
- * bar and then delete the temporary menu.
- */
- if (menu == menuBar) return;
- int theMenu = 0;
- if (menu == null) {
- int outMenuRef [] = new int [1];
- OS.CreateNewMenu ((short) ID_TEMPORARY, 0, outMenuRef);
- theMenu = outMenuRef [0];
- } else {
- theMenu = menu.handle;
- }
- OS.SetRootMenu (theMenu);
- if (menu == null) {
- OS.ClearMenuBar ();
- OS.DisposeMenu (theMenu);
- }
- menuBar = menu;
-}
-
-void setModalShell (Shell shell) {
- if (modalShells == null) modalShells = new Shell [4];
- int index = 0, length = modalShells.length;
- while (index < length) {
- if (modalShells [index] == shell) return;
- if (modalShells [index] == null) break;
- index++;
- }
- if (index == length) {
- Shell [] newModalShells = new Shell [length + 4];
- System.arraycopy (modalShells, 0, newModalShells, 0, length);
- modalShells = newModalShells;
- }
- modalShells [index] = shell;
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) shells [i].updateModal ();
-}
-
-/**
- * Causes the user-interface thread to <em>sleep</em> (that is,
- * to be put in a state where it does not consume CPU cycles)
- * until an event is received or it is otherwise awakened.
- *
- * @return <code>true</code> if an event requiring dispatching was placed on the queue.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #wake
- */
-public boolean sleep () {
- checkDevice ();
- if (getMessageCount () != 0) return true;
- disposeWindows ();
-
- /*
- * Feature in the Macintosh. No kAppearanceEventClass event exists
- * for a change of the Highlight Color. The fix is to poll for the
- * change while waiting for an event.
- */
- if (eventTable != null && eventTable.hooks (SWT.Settings)) {
- RGBColor color = new RGBColor ();
- int result = 0, depth = getDepth ();
- do {
- allowTimers = runAsyncMessages = false;
- result = OS.CFRunLoopRunInMode (OS.kCFRunLoopDefaultMode (), 0.5, true);
- allowTimers = runAsyncMessages = true;
- if (result == OS.kCFRunLoopRunTimedOut) {
- OS.GetThemeBrushAsColor ((short) OS.kThemeBrushPrimaryHighlightColor, (short) depth, true, color);
- if (highlightColor.red != color.red || highlightColor.green != color.green || highlightColor.blue != color.blue) {
- highlightColor = color;
- runSettings = true;
- return true;
- }
- }
- } while (result == OS.kCFRunLoopRunTimedOut);
- return result == OS.kCFRunLoopRunHandledSource;
- }
-
- /* Wait for an event and timeout after a day */
- allowTimers = runAsyncMessages = false;
- int result = OS.CFRunLoopRunInMode (OS.kCFRunLoopDefaultMode (), 60 * 60 * 24, true);
- allowTimers = runAsyncMessages = true;
- return result == OS.kCFRunLoopRunHandledSource;
-}
-
-int sourceProc (int info) {
- return 0;
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread at the next
- * reasonable opportunity. The thread which calls this method
- * is suspended until the runnable completes. Specifying <code>null</code>
- * as the runnable simply wakes the user-interface thread.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param runnable code to run on the user-interface thread or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_FAILED_EXEC - if an exception occurred when executing the runnable</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #asyncExec
- */
-public void syncExec (Runnable runnable) {
- Synchronizer synchronizer;
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- synchronizer = this.synchronizer;
- }
- synchronizer.syncExec (runnable);
-}
-
-int textInputProc (int nextHandler, int theEvent, int userData) {
- int theWindow = OS.GetUserFocusWindow ();
- if (theWindow != 0) {
- Widget widget = getFocusControl (theWindow, false);
- if (widget != null) {
- MenuTrackingData outData = new MenuTrackingData ();
- if (OS.GetMenuTrackingData (0, outData) != OS.noErr) {
- /* Stop the default event handler from activating the default button */
- int [] theControl = new int [1];
- OS.GetWindowDefaultButton (theWindow, theControl);
- OS.SetWindowDefaultButton (theWindow, 0);
- int result = widget.textInputProc (nextHandler, theEvent, userData);
- if (result == OS.eventNotHandledErr) {
- result = OS.CallNextEventHandler (nextHandler, theEvent);
- }
- OS.SetWindowDefaultButton (theWindow, theControl [0]);
- return result;
- }
- }
- }
- return OS.eventNotHandledErr;
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread after the specified
- * number of milliseconds have elapsed. If milliseconds is less
- * than zero, the runnable is not executed.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param milliseconds the delay before running the runnable
- * @param runnable code to run on the user-interface thread
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #asyncExec
- */
-public void timerExec (int milliseconds, Runnable runnable) {
- checkDevice ();
- if (runnable == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (timerList == null) timerList = new Runnable [4];
- if (timerIds == null) timerIds = new int [4];
- int index = 0;
- while (index < timerList.length) {
- if (timerList [index] == runnable) break;
- index++;
- }
- if (index != timerList.length) {
- int timerId = timerIds [index];
- if (milliseconds < 0) {
- OS.RemoveEventLoopTimer (timerId);
- timerList [index] = null;
- timerIds [index] = 0;
- } else {
- OS.SetEventLoopTimerNextFireTime (timerId, milliseconds / 1000.0);
- }
- return;
- }
- if (milliseconds < 0) return;
- index = 0;
- while (index < timerList.length) {
- if (timerList [index] == null) break;
- index++;
- }
- if (index == timerList.length) {
- Runnable [] newTimerList = new Runnable [timerList.length + 4];
- System.arraycopy (timerList, 0, newTimerList, 0, timerList.length);
- timerList = newTimerList;
- int [] newTimerIds = new int [timerIds.length + 4];
- System.arraycopy (timerIds, 0, newTimerIds, 0, timerIds.length);
- timerIds = newTimerIds;
- }
- int [] timerId = new int [1];
- int eventLoop = OS.GetCurrentEventLoop ();
- OS.InstallEventLoopTimer (eventLoop, milliseconds / 1000.0, 0.0, timerProc, index, timerId);
- if (timerId [0] != 0) {
- timerIds [index] = timerId [0];
- timerList [index] = runnable;
- }
-}
-
-int timerProc (int id, int index) {
- OS.RemoveEventLoopTimer (id);
- if (timerList == null) return 0;
- if (0 <= index && index < timerList.length) {
- if (allowTimers) {
- Runnable runnable = timerList [index];
- timerList [index] = null;
- timerIds [index] = 0;
- if (runnable != null) runnable.run ();
- } else {
- timerIds [index] = -1;
- wakeThread ();
- }
- }
- return 0;
-}
-
-int trackingProc (int browser, int itemID, int property, int theRect, int startPt, int modifiers) {
- Widget widget = getWidget (browser);
- if (widget != null) return widget.trackingProc (browser, itemID, property, theRect, startPt, modifiers);
- return OS.noErr;
-}
-
-int trayItemProc (int target, int userData, int selector, int event) {
- TrayItem item = (TrayItem) OS.JNIGetObject (userData);
- if (item != null) return item.trayItemProc (target, userData, selector, event);
- return 0;
-}
-
-/**
- * Forces all outstanding paint requests for the display
- * to be processed before this method returns.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Control#update()
- */
-public void update () {
- checkDevice ();
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) shell.update (true);
- }
- /*
- * This code is intentionally commented.
- */
-// int [] outEvent = new int [1];
-// int [] mask = new int [] {OS.kEventClassWindow, OS.kEventWindowUpdate};
-// while (OS.ReceiveNextEvent (mask.length / 2, mask, OS.kEventDurationNoWait, true, outEvent) == OS.noErr) {
-// /*
-// * Bug in the Macintosh. For some reason, when a hierarchy of
-// * windows is disposed from kEventWindowClose, despite the fact
-// * that DisposeWindow() has been called, the window is not
-// * disposed and there are outstandings kEventWindowUpdate events
-// * in the event queue. Dispatching these events will cause a
-// * segment fault. The fix is to dispatch events to visible
-// * windows only.
-// */
-// int [] theWindow = new int [1];
-// OS.GetEventParameter (outEvent [0], OS.kEventParamDirectObject, OS.typeWindowRef, null, 4, null, theWindow);
-// if (OS.IsWindowVisible (theWindow [0])) OS.SendEventToEventTarget (outEvent [0], OS.GetEventDispatcherTarget ());
-// OS.ReleaseEvent (outEvent [0]);
-// }
-}
-
-void updateQuitMenu () {
- boolean enabled = true;
- Shell [] shells = getShells ();
- int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if ((shell.style & mask) != 0 && shell.isVisible ()) {
- enabled = false;
- break;
- }
- }
- if (enabled) {
- OS.EnableMenuCommand (0, OS.kHICommandQuit);
- } else {
- OS.DisableMenuCommand (0, OS.kHICommandQuit);
- }
-}
-
-/**
- * If the receiver's user-interface thread was <code>sleep</code>ing,
- * causes it to be awakened and start running again. Note that this
- * method may be called from any thread.
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #sleep
- */
-public void wake () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- if (thread == Thread.currentThread ()) return;
- wakeThread ();
- }
-}
-
-void wakeThread () {
- OS.CFRunLoopSourceSignal (runLoopSource);
- OS.CFRunLoopWakeUp (runLoop);
-}
-
-int windowProc (int nextHandler, int theEvent, int userData) {
- Widget widget = getWidget (userData);
- if (widget == null) {
- int [] theWindow = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamDirectObject, OS.typeWindowRef, null, 4, null, theWindow);
- int [] theRoot = new int [1];
- OS.GetRootControl (theWindow [0], theRoot);
- widget = getWidget (theRoot [0]);
- }
- if (widget != null) return widget.windowProc (nextHandler, theEvent, userData);
- return OS.eventNotHandledErr;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java
deleted file mode 100644
index 532f14a233..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java
+++ /dev/null
@@ -1,561 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.carbon.*;
-
-/**
- * Instances of this class allow the user to navigate
- * the file system and select or enter a file name.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SAVE, OPEN, MULTI</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles SAVE and OPEN may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#filedialog">FileDialog snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class FileDialog extends Dialog {
- String [] filterNames = new String [0];
- String [] filterExtensions = new String [0];
- String [] fileNames = new String[0];
- String filterPath = "", fileName = "";
- int filterIndex = 0;
- boolean overwrite = false;
- static final char EXTENSION_SEPARATOR = ';';
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FileDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SAVE
- * @see SWT#OPEN
- * @see SWT#MULTI
- */
-public FileDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-/**
- * Returns the path of the first file that was
- * selected in the dialog relative to the filter path, or an
- * empty string if no such file has been selected.
- *
- * @return the relative path of the file
- */
-public String getFileName () {
- return fileName;
-}
-
-/**
- * Returns a (possibly empty) array with the paths of all files
- * that were selected in the dialog relative to the filter path.
- *
- * @return the relative paths of the files
- */
-public String [] getFileNames () {
- return fileNames;
-}
-
-/**
- * Returns the file extensions which the dialog will
- * use to filter the files it shows.
- *
- * @return the file extensions filter
- */
-public String [] getFilterExtensions () {
- return filterExtensions;
-}
-
-/**
- * Get the 0-based index of the file extension filter
- * which was selected by the user, or -1 if no filter
- * was selected.
- * <p>
- * This is an index into the FilterExtensions array and
- * the FilterNames array.
- * </p>
- *
- * @return index the file extension filter index
- *
- * @see #getFilterExtensions
- * @see #getFilterNames
- *
- * @since 3.4
- */
-public int getFilterIndex () {
- return filterIndex;
-}
-
-/**
- * Returns the names that describe the filter extensions
- * which the dialog will use to filter the files it shows.
- *
- * @return the list of filter names
- */
-public String [] getFilterNames () {
- return filterNames;
-}
-
-/**
- * Returns the directory path that the dialog will use, or an empty
- * string if this is not set. File names in this path will appear
- * in the dialog, filtered according to the filter extensions.
- *
- * @return the directory path string
- *
- * @see #setFilterExtensions
- */
-public String getFilterPath () {
- return filterPath;
-}
-
-/**
- * Returns the flag that the dialog will use to
- * determine whether to prompt the user for file
- * overwrite if the selected file already exists.
- *
- * @return true if the dialog will prompt for file overwrite, false otherwise
- *
- * @since 3.4
- */
-public boolean getOverwrite () {
- return overwrite;
-}
-
-int eventProc (int callBackSelector, int callBackParms, int callBackUD) {
- switch (callBackSelector) {
- case OS.kNavCBPopupMenuSelect:
- NavCBRec cbRec = new NavCBRec ();
- OS.memmove (cbRec, callBackParms, NavCBRec.sizeof);
- if (cbRec.eventData.eventDataParms.param != 0) {
- NavMenuItemSpec spec = new NavMenuItemSpec ();
- OS.memmove (spec, cbRec.eventData.eventDataParms.param, NavMenuItemSpec.sizeof);
- int index = spec.menuType;
- if (0 <= index && index < filterExtensions.length) {
- filterIndex = index;
- }
- }
- break;
- }
- return 0;
-}
-
-int filterProc (int theItem, int infoPtr, int callBackUD, int filterMode) {
- if (filterMode == OS.kNavFilteringBrowserList) {
- if (filterExtensions != null && 0 <= filterIndex && filterIndex < filterExtensions.length) {
- NavFileOrFolderInfo info = new NavFileOrFolderInfo();
- OS.memmove (info, infoPtr, NavFileOrFolderInfo.sizeof);
- if (!info.isFolder) {
- OS.AECoerceDesc (theItem, OS.typeFSRef, theItem);
- byte [] fsRef = new byte [80];
- if (OS.AEGetDescData (theItem, fsRef, fsRef.length) == OS.noErr) {
- int url = OS.CFURLCreateFromFSRef (OS.kCFAllocatorDefault, fsRef);
- if (url != 0) {
- int ext = OS.CFURLCopyPathExtension (url);
- OS.CFRelease (url);
- if (ext != 0) {
- char [] buffer= new char [OS.CFStringGetLength (ext)];
- if (buffer.length > 0) {
- CFRange range = new CFRange ();
- range.length = buffer.length;
- OS.CFStringGetCharacters (ext, range, buffer);
- }
- OS.CFRelease (ext);
- String extension = new String (buffer);
- String extensions = filterExtensions [filterIndex];
- int start = 0, length = extensions.length ();
- while (start < length) {
- int index = extensions.indexOf (EXTENSION_SEPARATOR, start);
- if (index == -1) index = length;
- String filter = extensions.substring (start, index).trim ();
- if (filter.equals ("*") || filter.equals ("*.*")) return 1;
- if (filter.startsWith ("*.")) filter = filter.substring (2);
- if (filter.toLowerCase ().equals(extension.toLowerCase ())) return 1;
- start = index + 1;
- }
- return 0;
- }
- }
- }
- return 0;
- }
- }
- }
- return 1;
-}
-
-String getString (int cfString) {
- if (cfString == 0) return "";
- int length = OS.CFStringGetLength (cfString);
- char [] buffer= new char [length];
- CFRange range = new CFRange ();
- range.length = length;
- OS.CFStringGetCharacters (cfString, range, buffer);
- return new String (buffer);
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a string describing the absolute path of the first selected file,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public String open () {
- String fullPath = null;
- fileNames = new String [0];
-
- int titlePtr = 0;
- if (title != null) {
- char [] buffer = new char [title.length ()];
- title.getChars (0, buffer.length, buffer, 0);
- titlePtr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- }
- int fileNamePtr = 0;
- if (fileName != null) {
- char [] buffer = new char [fileName.length ()];
- fileName.getChars (0, buffer.length, buffer, 0);
- fileNamePtr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- }
-
- NavDialogCreationOptions options = new NavDialogCreationOptions ();
- options.windowTitle = options.clientName = titlePtr;
- options.parentWindow = OS.GetControlOwner (parent.handle);
- options.optionFlags = OS.kNavSupportPackages | OS.kNavAllowInvisibleFiles;
- options.location_h = -1;
- options.location_v = -1;
- options.saveFileName = fileNamePtr;
- options.modality = OS.kWindowModalityAppModal;
-
- int extensions = 0;
- Callback filterCallback = null, eventCallback = null;
- int [] outDialog = new int [1];
- if ((style & SWT.SAVE) != 0) {
- if (!overwrite) options.optionFlags |= OS.kNavDontConfirmReplacement;
- OS.NavCreatePutFileDialog (options, 0, 0, 0, 0, outDialog);
- } else {
- if ((style & SWT.MULTI) != 0) options.optionFlags |= OS.kNavAllowMultipleFiles;
- int filterProc = 0, eventProc = 0;
- if (filterExtensions != null && filterExtensions.length != 0) {
- extensions = options.popupExtension = OS.CFArrayCreateMutable (OS.kCFAllocatorDefault, filterExtensions.length, 0);
- for (int i = 0; i < filterExtensions.length; i++) {
- String str = filterExtensions [i];
- if (filterNames != null && filterNames.length > i) {
- str = filterNames [i];
- }
- char [] chars = new char [str.length ()];
- str.getChars (0, chars.length, chars, 0);
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, chars, chars.length);
- if (ptr != 0) OS.CFArrayAppendValue (extensions, ptr);
- }
- filterCallback = new Callback (this, "filterProc", 4);
- filterProc = filterCallback.getAddress();
- if (filterProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- eventCallback = new Callback (this, "eventProc", 3);
- eventProc = eventCallback.getAddress();
- if (eventProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- }
- OS.NavCreateGetFileDialog(options, 0, eventProc, 0, filterProc, 0, outDialog);
- }
- if (outDialog [0] != 0) {
- if (filterPath != null && filterPath.length () > 0) {
- char [] chars = new char [filterPath.length ()];
- filterPath.getChars (0, chars.length, chars, 0);
- int str = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, chars, chars.length);
- if (str != 0) {
- int url = OS.CFURLCreateWithFileSystemPath (OS.kCFAllocatorDefault, str, OS.kCFURLPOSIXPathStyle, false);
- if (url != 0) {
- byte [] fsRef = new byte [80];
- if (OS.CFURLGetFSRef (url, fsRef)) {
- AEDesc params = new AEDesc ();
- if (OS.AECreateDesc (OS.typeFSRef, fsRef, fsRef.length, params) == OS.noErr) {
- OS.NavCustomControl (outDialog [0], OS.kNavCtlSetLocation, params);
- OS.AEDisposeDesc (params);
- }
- }
- OS.CFRelease (url);
- }
- OS.CFRelease (str);
- }
- }
- if (filterExtensions != null && 0 <= filterIndex && filterIndex < filterExtensions.length) {
- NavMenuItemSpec spec = new NavMenuItemSpec ();
- spec.menuType = filterIndex;
- OS.NavCustomControl (outDialog [0], OS.kNavCtlSelectCustomType, spec);
- }
- OS.NavDialogRun (outDialog [0]);
- int action = OS.NavDialogGetUserAction (outDialog [0]);
- switch (action) {
- case OS.kNavUserActionOpen:
- case OS.kNavUserActionChoose:
- case OS.kNavUserActionSaveAs: {
- NavReplyRecord record = new NavReplyRecord ();
- OS.NavDialogGetReply (outDialog [0], record);
- AEDesc selection = new AEDesc ();
- selection.descriptorType = record.selection_descriptorType;
- selection.dataHandle = record.selection_dataHandle;
- int [] count = new int [1];
- OS.AECountItems (selection, count);
- if (count [0] > 0) {
- fileNames = new String [count [0]];
- int maximumSize = 80; // size of FSRef
- int dataPtr = OS.NewPtr (maximumSize);
- int[] aeKeyword = new int [1];
- int[] typeCode = new int [1];
- int[] actualSize = new int [1];
-
- if ((style & SWT.SAVE) != 0) {
- if (OS.AEGetNthPtr (selection, 1, OS.typeFSRef, aeKeyword, typeCode, dataPtr, maximumSize, actualSize) == OS.noErr) {
- byte[] fsRef = new byte[actualSize[0]];
- OS.memmove (fsRef, dataPtr, actualSize [0]);
- int pathUrl = OS.CFURLCreateFromFSRef (OS.kCFAllocatorDefault, fsRef);
-
- /* Filter path */
- int pathString = OS.CFURLCopyFileSystemPath (pathUrl, OS.kCFURLPOSIXPathStyle);
- filterPath = getString (pathString);
- OS.CFRelease (pathString);
-
- /* Full path */
- int fullUrl = OS.CFURLCreateCopyAppendingPathComponent (OS.kCFAllocatorDefault, pathUrl, record.saveFileName, false);
- int fullString = OS.CFURLCopyFileSystemPath (fullUrl, OS.kCFURLPOSIXPathStyle);
- fullPath = getString (fullString);
- OS.CFRelease (fullString);
- OS.CFRelease (fullUrl);
-
- /* File name */
- fileName = fileNames [0] = getString (record.saveFileName);
-
- OS.CFRelease (pathUrl);
- }
- } else {
- for (int i = 0; i < count [0]; i++) {
- if (OS.AEGetNthPtr (selection, i+1, OS.typeFSRef, aeKeyword, typeCode, dataPtr, maximumSize, actualSize) == OS.noErr) {
- byte[] fsRef = new byte[actualSize[0]];
- OS.memmove (fsRef, dataPtr, actualSize [0]);
- int url = OS.CFURLCreateFromFSRef (OS.kCFAllocatorDefault, fsRef);
- int fullString = OS.CFURLCopyFileSystemPath (url, OS.kCFURLPOSIXPathStyle);
-
- /* File path */
- int pathUrl = OS.CFURLCreateCopyDeletingLastPathComponent (OS.kCFAllocatorDefault, url);
- int pathString = OS.CFURLCopyFileSystemPath (pathUrl, OS.kCFURLPOSIXPathStyle);
- String path = getString (pathString);
- OS.CFRelease (pathString);
- OS.CFRelease (pathUrl);
-
- if (i == 0) {
- /* Full path */
- fullPath = getString (fullString);
-
- /* Filter path */
- filterPath = path;
-
- /* File name */
- int fileString = OS.CFURLCopyLastPathComponent (url);
- fileName = fileNames [0] = getString (fileString);
- OS.CFRelease (fileString);
- } else {
- if (path.equals (filterPath)) {
- int fileString = OS.CFURLCopyLastPathComponent (url);
- fileNames [i] = getString (fileString);
- OS.CFRelease (fileString);
- } else {
- fileNames [i] = getString (fullString);
- }
- }
- OS.CFRelease (fullString);
- OS.CFRelease (url);
- }
- }
- }
- OS.DisposePtr (dataPtr);
- }
- OS.NavDisposeReply (record);
- }
- }
- }
-
- if (titlePtr != 0) OS.CFRelease (titlePtr);
- if (fileNamePtr != 0) OS.CFRelease (fileNamePtr);
- if (outDialog [0] != 0) OS.NavDialogDispose (outDialog [0]);
- if (extensions != 0) {
- int count = OS.CFArrayGetCount (extensions);
- for (int i = 0; i < count; i++) {
- OS.CFRelease (OS.CFArrayGetValueAtIndex (extensions, i));
- }
- OS.CFRelease (extensions);
- }
- if (filterCallback != null) filterCallback.dispose();
- if (eventCallback != null) eventCallback.dispose();
- return fullPath;
-}
-
-/**
- * Set the initial filename which the dialog will
- * select by default when opened to the argument,
- * which may be null. The name will be prefixed with
- * the filter path when one is supplied.
- *
- * @param string the file name
- */
-public void setFileName (String string) {
- fileName = string;
-}
-
-/**
- * Set the file extensions which the dialog will
- * use to filter the files it shows to the argument,
- * which may be null.
- * <p>
- * The strings are platform specific. For example, on
- * some platforms, an extension filter string is typically
- * of the form "*.extension", where "*.*" matches all files.
- * For filters with multiple extensions, use semicolon as
- * a separator, e.g. "*.jpg;*.png".
- * </p>
- *
- * @param extensions the file extension filter
- *
- * @see #setFilterNames to specify the user-friendly
- * names corresponding to the extensions
- */
-public void setFilterExtensions (String [] extensions) {
- filterExtensions = extensions;
-}
-
-/**
- * Set the 0-based index of the file extension filter
- * which the dialog will use initially to filter the files
- * it shows to the argument.
- * <p>
- * This is an index into the FilterExtensions array and
- * the FilterNames array.
- * </p>
- *
- * @param index the file extension filter index
- *
- * @see #setFilterExtensions
- * @see #setFilterNames
- *
- * @since 3.4
- */
-public void setFilterIndex (int index) {
- filterIndex = index;
-}
-
-/**
- * Sets the names that describe the filter extensions
- * which the dialog will use to filter the files it shows
- * to the argument, which may be null.
- * <p>
- * Each name is a user-friendly short description shown for
- * its corresponding filter. The <code>names</code> array must
- * be the same length as the <code>extensions</code> array.
- * </p>
- *
- * @param names the list of filter names, or null for no filter names
- *
- * @see #setFilterExtensions
- */
-public void setFilterNames (String [] names) {
- filterNames = names;
-}
-
-/**
- * Sets the directory path that the dialog will use
- * to the argument, which may be null. File names in this
- * path will appear in the dialog, filtered according
- * to the filter extensions. If the string is null,
- * then the operating system's default filter path
- * will be used.
- * <p>
- * Note that the path string is platform dependent.
- * For convenience, either '/' or '\' can be used
- * as a path separator.
- * </p>
- *
- * @param string the directory path
- *
- * @see #setFilterExtensions
- */
-public void setFilterPath (String string) {
- filterPath = string;
-}
-
-/**
- * Sets the flag that the dialog will use to
- * determine whether to prompt the user for file
- * overwrite if the selected file already exists.
- *
- * @param overwrite true if the dialog will prompt for file overwrite, false otherwise
- *
- * @since 3.4
- */
-public void setOverwrite (boolean overwrite) {
- this.overwrite = overwrite;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FontDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FontDialog.java
deleted file mode 100644
index bf5c06be3c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FontDialog.java
+++ /dev/null
@@ -1,359 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.carbon.*;
-import org.eclipse.swt.internal.Callback;
-import org.eclipse.swt.internal.carbon.RGBColor;
-
-/**
- * Instances of this class allow the user to select a font
- * from all available fonts in the system.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class FontDialog extends Dialog {
- FontData fontData;
- RGB rgb;
- boolean open;
- int fontID, fontSize;
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FontDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FontDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-/**
- * Returns a FontData object describing the font that was
- * selected in the dialog, or null if none is available.
- *
- * @return the FontData for the selected font, or null
- * @deprecated use #getFontList ()
- */
-public FontData getFontData () {
- return fontData;
-}
-
-/**
- * Returns a FontData set describing the font that was
- * selected in the dialog, or null if none is available.
- *
- * @return the FontData for the selected font, or null
- * @since 2.1.1
- */
-public FontData [] getFontList () {
- if (fontData == null) return null;
- FontData [] result = new FontData [1];
- result [0] = fontData;
- return result;
-}
-
-/**
- * Returns an RGB describing the color that was selected
- * in the dialog, or null if none is available.
- *
- * @return the RGB value for the selected color, or null
- *
- * @see PaletteData#getRGBs
- *
- * @since 2.1
- */
-public RGB getRGB () {
- return rgb;
-}
-
-int fontProc (int nextHandler, int theEvent, int userData) {
- int kind = OS.GetEventKind (theEvent);
- switch (kind) {
- case OS.kEventFontPanelClosed:
- open = false;
- break;
- case OS.kEventFontSelection:
- int [] fontID = new int [1];
- if (OS.GetEventParameter (theEvent, OS.kEventParamATSUFontID, OS.typeUInt32, null, 4, null, fontID) == OS.noErr) {
- this.fontID = fontID [0];
- }
- int [] fontSize = new int [1];
- if (OS.GetEventParameter (theEvent, OS.kEventParamATSUFontSize, OS.typeFixed, null, 4, null, fontSize) == OS.noErr) {
- this.fontSize = fontSize [0];
- }
- RGBColor color = new RGBColor ();
- int [] actualSize = new int [1];
- if (OS.GetEventParameter (theEvent, OS.kEventParamFontColor, OS.typeRGBColor, null, RGBColor.sizeof, actualSize, color) == OS.noErr) {
- int red = (color.red >> 8) & 0xFF;
- int green = (color.green >> 8) & 0xFF;
- int blue = (color.blue >> 8) & 0xFF;
- rgb = new RGB (red, green, blue);
- } else {
- int [] dict = new int [1];
- if (OS.GetEventParameter (theEvent, OS.kEventParamDictionary, OS.typeCFDictionaryRef, null, 4, actualSize, dict) == OS.noErr) {
- int [] attrib = new int [1];
- if (OS.CFDictionaryGetValueIfPresent (dict [0], OS.kFontPanelAttributesKey (), attrib)) {
- int [] tags = new int [1];
- int [] sizes = new int [1];
- int [] values = new int [1];
- if (OS.CFDictionaryGetValueIfPresent (attrib [0], OS.kFontPanelAttributeTagsKey (), tags) &&
- OS.CFDictionaryGetValueIfPresent (attrib [0], OS.kFontPanelAttributeSizesKey (), sizes) &&
- OS.CFDictionaryGetValueIfPresent (attrib [0], OS.kFontPanelAttributeValuesKey (), values)
- ) {
- int count = OS.CFDataGetLength (tags [0]) / 4;
- int tagPtr = OS.CFDataGetBytePtr (tags[0]);
- int sizePtr = OS.CFDataGetBytePtr (sizes [0]);
- int [] tag = new int [1];
- int [] size = new int [1];
- int valueOffset = 0;
- for (int i = 0 ; i < count ; i++) {
- OS.memmove (tag, tagPtr + (i * 4), 4);
- OS.memmove (size, sizePtr + (i * 4), 4);
- if (tag [0] == OS.kATSUColorTag && size[0] == RGBColor.sizeof) {
- int valuePtr = OS.CFDataGetBytePtr (values [0]);
- OS.memmove (color, valuePtr + valueOffset, RGBColor.sizeof);
- int red = (color.red >> 8) & 0xFF;
- int green = (color.green >> 8) & 0xFF;
- int blue = (color.blue >> 8) & 0xFF;
- rgb = new RGB (red, green, blue);
- break ;
- }
- valueOffset = size[0];
- }
- }
- }
- }
- }
- break;
- }
- return OS.noErr;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a FontData object describing the font that was selected,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public FontData open () {
- Display display = parent != null ? parent.display : Display.getCurrent ();
- if (fontData != null) {
- Font font = new Font (display, fontData);
- int ptr = OS.NewPtr (4);
- OS.memmove (ptr, new int []{font.atsuiStyle}, 4);
- //TODO - not sure how to set initial color in font panel
-// if (rgb != null) {
-// RGBColor color = new RGBColor ();
-// rgb.red = (short) (rgb.red * 0xffff);
-// rgb.green = (short) (rgb.green * 0xffff);
-// rgb.blue = (short) (rgb.blue * 0xffff);
-// int ptr1 = OS.NewPtr (RGBColor.sizeof);
-// OS.memcpy(ptr, color, RGBColor.sizeof);
-// int [] tags = new int []{OS.kATSUColorTag};
-// int [] sizes = new int []{RGBColor.sizeof};
-// int [] values = new int []{ptr1};
-// OS.ATSUSetAttributes (font.atsuiStyle, tags.length, tags, sizes, values);
-// OS.DisposePtr(ptr1);
-// }
- OS.SetFontInfoForSelection (OS.kFontSelectionATSUIType, 1, ptr, 0);
- OS.DisposePtr (ptr);
- font.dispose ();
- }
- int[] mask = new int[] {
- OS.kEventClassFont, OS.kEventFontSelection,
- OS.kEventClassFont, OS.kEventFontPanelClosed,
- };
- Callback fontPanelCallback = new Callback (this, "fontProc", 3);
- int fontPanelCallbackAddress = fontPanelCallback.getAddress ();
- if (fontPanelCallbackAddress == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- int appTarget = OS.GetApplicationEventTarget ();
- int [] outRef = new int [1];
- OS.InstallEventHandler (appTarget, fontPanelCallbackAddress, mask.length / 2, mask, 0, outRef);
- fontSize = fontID = 0;
- fontData = null;
- rgb = null;
- open = true;
- /*
- * Feature in the Macintosh. The Fonts window is not modal and it cannot
- * be accessed through direct API. The fix is to figure out the Fonts
- * window by checking all available windows and set its modality
- * explicitily.
- */
- int count = 0;
- int window = OS.GetPreviousWindow (0);
- while (window != 0) {
- count++;
- window = OS.GetPreviousWindow (window);
- }
- int [] windows = new int [count];
- boolean[] visible = new boolean [count];
- count = 0;
- window = OS.GetPreviousWindow (0);
- while (window != 0) {
- windows [count] = window;
- visible [count] = OS.IsWindowVisible (window);
- count++;
- window = OS.GetPreviousWindow (window);
- }
- OS.FPShowHideFontPanel ();
- int fontsWindow = 0;
- window = OS.GetPreviousWindow (0);
- while (window != 0 && fontsWindow == 0) {
- if (OS.IsWindowVisible (window)) {
- boolean found = false;
- for (int i = 0; i < windows.length; i++) {
- if (windows [i] == window) {
- found = true;
- if (!visible [i]) {
- fontsWindow = window;
- break;
- }
- }
- }
- if (!found) {
- fontsWindow = window;
- break;
- }
- }
- window = OS.GetPreviousWindow (window);
- }
- if (fontsWindow != 0) {
- int inModalKind = OS.kWindowModalityNone;
- if ((style & SWT.PRIMARY_MODAL) != 0) inModalKind = OS.kWindowModalityWindowModal;
- if ((style & SWT.APPLICATION_MODAL) != 0) inModalKind = OS.kWindowModalityAppModal;
- if ((style & SWT.SYSTEM_MODAL) != 0) inModalKind = OS.kWindowModalitySystemModal;
- if (inModalKind != OS.kWindowModalityNone) {
- int inUnavailableWindow = 0;
- if (parent != null) inUnavailableWindow = OS.GetControlOwner (parent.handle);
- OS.SetWindowModality (fontsWindow, inModalKind, inUnavailableWindow);
- OS.SelectWindow (fontsWindow);
- }
- }
- while (!parent.isDisposed() && open) {
- if (!display.readAndDispatch ()) display.sleep ();
- }
- OS.RemoveEventHandler (outRef [0]);
- fontPanelCallback.dispose ();
- if (fontID != 0 && fontSize != 0) {
- int atsFont = OS.FMGetATSFontRefFromFont (fontID);
- Font font = Font.carbon_new (display, atsFont, (short) 0, (float) OS.Fix2X (fontSize));
- fontData = font.getFontData ()[0];
- font.dispose();
- }
- return fontData;
-}
-
-/**
- * Sets a FontData object describing the font to be
- * selected by default in the dialog, or null to let
- * the platform choose one.
- *
- * @param fontData the FontData to use initially, or null
- * @deprecated use #setFontList (FontData [])
- */
-public void setFontData (FontData fontData) {
- this.fontData = fontData;
-}
-
-/**
- * Sets the set of FontData objects describing the font to
- * be selected by default in the dialog, or null to let
- * the platform choose one.
- *
- * @param fontData the set of FontData objects to use initially, or null
- * to let the platform select a default when open() is called
- *
- * @see Font#getFontData
- *
- * @since 2.1.1
- */
-public void setFontList (FontData [] fontData) {
- if (fontData != null && fontData.length > 0) {
- this.fontData = fontData [0];
- } else {
- this.fontData = null;
- }
-}
-
-/**
- * Sets the RGB describing the color to be selected by default
- * in the dialog, or null to let the platform choose one.
- *
- * @param rgb the RGB value to use initially, or null to let
- * the platform select a default when open() is called
- *
- * @see PaletteData#getRGBs
- *
- * @since 2.1
- */
-public void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Group.java
deleted file mode 100644
index b73b440cf7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Group.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.CGRect;
-import org.eclipse.swt.internal.carbon.Rect;
-
-/**
- * Instances of this class provide an etched border
- * with an optional title.
- * <p>
- * Shadow styles are hints and may not be honoured
- * by the platform. To create a group with the
- * default shadow style for the platform, do not
- * specify a shadow style.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SHADOW_ETCHED_IN, SHADOW_ETCHED_OUT, SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the above styles may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Group extends Composite {
- String text = "";
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SHADOW_ETCHED_IN
- * @see SWT#SHADOW_ETCHED_OUT
- * @see SWT#SHADOW_IN
- * @see SWT#SHADOW_OUT
- * @see SWT#SHADOW_NONE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Group (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
- CGRect oldBounds = new CGRect (), bounds = oldBounds;
- OS.HIViewGetFrame (handle, oldBounds);
- int MIN_SIZE = 100;
- if (oldBounds.width < MIN_SIZE || oldBounds.height < MIN_SIZE) {
- OS.HIViewSetDrawingEnabled (handle, false);
- bounds = new CGRect ();
- bounds.width = bounds.height = 100;
- OS.HIViewSetFrame (handle, bounds);
- }
- int rgnHandle = OS.NewRgn ();
- OS.GetControlRegion (handle, (short)OS.kControlContentMetaPart, rgnHandle);
- Rect client = new Rect ();
- OS.GetRegionBounds (rgnHandle, client);
- OS.DisposeRgn (rgnHandle);
- width += (int) bounds.width - (client.right - client.left);
- height += (int) bounds.height - (client.bottom - client.top);
- if (oldBounds.width < MIN_SIZE || oldBounds.height < MIN_SIZE) {
- OS.HIViewSetFrame (handle, oldBounds);
- OS.HIViewSetDrawingEnabled (handle, getDrawing ());
- }
- return new Rectangle (-client.left, -client.top, width, height);
-}
-
-void createHandle () {
- state |= THEME_BACKGROUND;
- int [] outControl = new int [1];
- int window = OS.GetControlOwner (parent.handle);
- OS.CreateGroupBoxControl (window, null, 0, true, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
-}
-
-void drawBackground (int control, int context) {
- fillBackground (control, context, null);
-}
-
-public Rectangle getClientArea () {
- checkWidget();
- int rgnHandle = OS.NewRgn ();
- OS.GetControlRegion (handle, (short)OS.kControlContentMetaPart, rgnHandle);
- Rect client = new Rect ();
- OS.GetRegionBounds (rgnHandle, client);
- OS.DisposeRgn (rgnHandle);
- return new Rectangle (client.left, client.top, client.right - client.left, client.bottom - client.top);
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which is the string that the
- * is used as the <em>title</em>. If the text has not previously
- * been set, returns an empty string.
- *
- * @return the text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-float getThemeAlpha () {
- return (background != null ? 1 : 0.25f) * parent.getThemeAlpha ();
-}
-
-/**
- * Sets the receiver's text, which is the string that will
- * be displayed as the receiver's <em>title</em>, to the argument,
- * which may not be null. The string may include the mnemonic character.
- * </p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, focus is assigned
- * to the first child of the group. On most platforms, the
- * mnemonic appears underlined but may be emphasised in a
- * platform specific manner. The mnemonic indicator character
- * '&amp;' can be escaped by doubling it in the string, causing
- * a single '&amp;' to be displayed.
- * </p>
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- text = string;
- char [] buffer = new char [text.length ()];
- text.getChars (0, buffer.length, buffer, 0);
- int length = fixMnemonic (buffer);
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, length);
- if (ptr == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- OS.SetControlTitleWithCFString (handle, ptr);
- OS.CFRelease (ptr);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/IME.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/IME.java
deleted file mode 100644
index ac213ae9ca..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/IME.java
+++ /dev/null
@@ -1,441 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.TextRange;
-
-
-/**
- * Instances of this class represent input method editors.
- * These are typically in-line pre-edit text areas that allow
- * the user to compose characters from Far Eastern languages
- * such as Japanese, Chinese or Korean.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>ImeComposition</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.4
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class IME extends Widget {
- Canvas parent;
- int caretOffset;
- int startOffset;
- int commitCount;
- String text;
- int [] ranges;
- TextStyle [] styles;
-
- static final int UNDERLINE_IME_INPUT = 1 << 16;
- static final int UNDERLINE_IME_TARGET_CONVERTED = 2 << 16;
- static final int UNDERLINE_IME_CONVERTED = 3 << 16;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-IME () {
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a canvas control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public IME (Canvas parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget ();
-}
-
-void createWidget () {
- text = "";
- startOffset = -1;
- if (parent.getIME () == null) {
- parent.setIME (this);
- }
-}
-
-/**
- * Returns the offset of the caret from the start of the document.
- * The caret is within the current composition.
- *
- * @return the caret offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretOffset () {
- checkWidget ();
- return startOffset + caretOffset;
-}
-
-/**
- * Returns the commit count of the composition. This is the
- * number of characters that have been composed. When the
- * commit count is equal to the length of the composition
- * text, then the in-line edit operation is complete.
- *
- * @return the commit count
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see IME#getText
- */
-public int getCommitCount () {
- checkWidget ();
- return commitCount;
-}
-
-/**
- * Returns the offset of the composition from the start of the document.
- * This is the start offset of the composition within the document and
- * in not changed by the input method editor itself during the in-line edit
- * session.
- *
- * @return the offset of the composition
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCompositionOffset () {
- checkWidget ();
- return startOffset;
-}
-
-/**
- * Returns the ranges for the style that should be applied during the
- * in-line edit session.
- * <p>
- * The ranges array contains start and end pairs. Each pair refers to
- * the corresponding style in the styles array. For example, the pair
- * that starts at ranges[n] and ends at ranges[n+1] uses the style
- * at styles[n/2] returned by <code>getStyles()</code>.
- * </p>
- * @return the ranges for the styles
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see IME#getStyles
- */
-public int [] getRanges () {
- checkWidget ();
- if (ranges == null) return new int [0];
- int [] result = new int [ranges.length];
- for (int i = 0; i < result.length; i++) {
- result [i] = ranges [i] + startOffset;
- }
- return result;
-}
-
-/**
- * Returns the styles for the ranges.
- * <p>
- * The ranges array contains start and end pairs. Each pair refers to
- * the corresponding style in the styles array. For example, the pair
- * that starts at ranges[n] and ends at ranges[n+1] uses the style
- * at styles[n/2].
- * </p>
- *
- * @return the ranges for the styles
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see IME#getRanges
- */
-public TextStyle [] getStyles () {
- checkWidget ();
- if (styles == null) return new TextStyle [0];
- TextStyle [] result = new TextStyle [styles.length];
- System.arraycopy (styles, 0, result, 0, styles.length);
- return result;
-}
-
-/**
- * Returns the composition text.
- * <p>
- * The text for an IME is the characters in the widget that
- * are in the current composition. When the commit count is
- * equal to the length of the composition text, then the
- * in-line edit operation is complete.
- * </p>
- *
- * @return the widget text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-/**
- * Returns <code>true</code> if the caret should be wide, and
- * <code>false</code> otherwise. In some languages, for example
- * Korean, the caret is typically widened to the width of the
- * current character in the in-line edit session.
- *
- * @return the wide caret state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getWideCaret() {
- checkWidget ();
- return false;
-}
-
-boolean isInlineEnabled () {
- return hooks (SWT.ImeComposition);
-}
-
-int kEventTextInputOffsetToPos (int nextHandler, int theEvent, int userData) {
- if (!isInlineEnabled ()) return OS.eventNotHandledErr;
- Caret caret = parent.caret;
- if (caret == null) return OS.eventNotHandledErr;
- org.eclipse.swt.internal.carbon.Point pt = new org.eclipse.swt.internal.carbon.Point ();
- int sizeof = org.eclipse.swt.internal.carbon.Point.sizeof;
- org.eclipse.swt.graphics.Point point = parent.toDisplay (caret.x, caret.y + caret.height);
- pt.h = (short)point.x;
- pt.v = (short)point.y;
- OS.SetEventParameter (theEvent, OS.kEventParamTextInputReplyPoint, OS.typeQDPoint, sizeof, pt);
- return OS.noErr;
-}
-
-int kEventTextInputPosToOffset (int nextHandler, int theEvent, int userData) {
- if (!isInlineEnabled ()) return OS.eventNotHandledErr;
- if (startOffset == -1) return OS.eventNotHandledErr;
- org.eclipse.swt.internal.carbon.Point pt = new org.eclipse.swt.internal.carbon.Point ();
- int sizeof = org.eclipse.swt.internal.carbon.Point.sizeof;
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendCurrentPoint, OS.typeQDPoint, null, sizeof, null, pt);
- org.eclipse.swt.graphics.Point point = parent.toControl (pt.h, pt.v);
- Event event = new Event ();
- event.detail = SWT.COMPOSITION_OFFSET;
- event.x = point.x;
- event.y = point.y;
- sendEvent (SWT.ImeComposition, event);
- int hitTest;
- int offset = event.index + event.count;
- if (offset == -1) {
- hitTest = OS.kTSMOutsideOfBody;
- } else {
- if (startOffset <= offset && offset < startOffset + text.length()) {
- hitTest = OS.kTSMInsideOfActiveInputArea;
- offset -= startOffset;
- } else {
- hitTest = OS.kTSMInsideOfBody;
- }
- }
- OS.SetEventParameter (theEvent, OS.kEventParamTextInputReplyTextOffset, OS.typeLongInteger, 4, new int [] {offset * 2});
- OS.SetEventParameter (theEvent, OS.kEventParamTextInputReplyRegionClass, OS.typeLongInteger, 4, new int [] {hitTest});
- OS.SetEventParameter (theEvent, OS.kEventParamTextInputReplyLeadingEdge, OS.typeBoolean, 4, new boolean [] {event.count == 0});
- return OS.noErr;
-}
-
-int kEventTextInputGetSelectedText (int nextHandler, int theEvent, int userData) {
- Event event = new Event ();
- event.detail = SWT.COMPOSITION_SELECTION;
- sendEvent (SWT.ImeComposition, event);
- String text = event.text;
- if (text.length () > 0) {
- char [] buffer = new char [text.length ()];
- text.getChars (0, buffer.length, buffer, 0);
- OS.SetEventParameter (theEvent, OS.kEventParamTextInputReplyText, OS.typeUnicodeText, buffer.length * 2, buffer);
- return OS.noErr;
- }
- return OS.eventNotHandledErr;
-}
-
-int kEventTextInputUpdateActiveInputArea (int nextHandler, int theEvent, int userData) {
- if (!isInlineEnabled ()) return OS.eventNotHandledErr;
- ranges = null;
- styles = null;
- caretOffset = commitCount = 0;
- int [] length = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendText, OS.typeUnicodeText, null, 0, length, (char [])null);
- char [] chars = new char [length [0]];
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendText, OS.typeUnicodeText, null, length [0], null, chars);
- int [] fixed_length = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendFixLen, OS.typeLongInteger, null, 4, null, fixed_length);
- int [] rangeSize = new int [1];
- int rc = OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendHiliteRng, OS.typeTextRangeArray, null, 0, rangeSize, (byte [])null);
- if (rc == OS.noErr) {
- int firstSelectedConverted = -1;
- boolean hasConvertedText = false;
- int textRanges = OS.NewPtr (rangeSize [0]);
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendHiliteRng, OS.typeTextRangeArray, null, rangeSize [0], null, textRanges);
- short [] nRanges = new short [1];
- OS.memmove (nRanges, textRanges, 2);
- int count = nRanges [0];
- if (count > 0) {
- TextRange range = new TextRange ();
- ranges = new int [(count - 1) * 2];
- styles = new TextStyle [count - 1];
- for (int i = 0, j = 0; i < count; i++) {
- OS.memmove (range, textRanges + 2 + (i * TextRange.sizeof), TextRange.sizeof);
- switch (range.fHiliteStyle) {
- case OS.kCaretPosition:
- caretOffset = range.fStart / 2;
- break;
- case OS.kConvertedText:
- case OS.kSelectedConvertedText:
- case OS.kSelectedRawText:
- case OS.kRawText:
- ranges [j * 2] = range.fStart / 2;
- ranges [j * 2 + 1] = range.fEnd / 2 - 1;
- styles [j] = new TextStyle ();
- styles [j].underline = true;
- styles [j].underlineStyle = UNDERLINE_IME_INPUT;
- if (range.fHiliteStyle == OS.kConvertedText) {
- styles [j].underlineStyle = UNDERLINE_IME_CONVERTED;
- hasConvertedText = true;
- }
- if (range.fHiliteStyle == OS.kSelectedConvertedText) {
- styles [j].underlineStyle = UNDERLINE_IME_TARGET_CONVERTED;
- if (firstSelectedConverted == -1) {
- firstSelectedConverted = range.fStart;
- }
- }
- j++;
- break;
- }
- }
- }
- OS.DisposePtr (textRanges);
- if (hasConvertedText && firstSelectedConverted != -1) {
- caretOffset = firstSelectedConverted / 2;
- }
- }
- int end = startOffset + text.length();
- if (startOffset == -1) {
- Event event = new Event ();
- event.detail = SWT.COMPOSITION_SELECTION;
- sendEvent (SWT.ImeComposition, event);
- startOffset = event.start;
- end = event.end;
- }
- Event event = new Event ();
- event.detail = SWT.COMPOSITION_CHANGED;
- event.start = startOffset;
- event.end = end;
- event.text = text = new String(chars, 0, length [0] / 2);
- commitCount = fixed_length [0] != -1 ? fixed_length [0] / 2: length [0] / 2;
- sendEvent (SWT.ImeComposition, event);
- if (commitCount == text.length ()) {
- text = "";
- caretOffset = commitCount = 0;
- startOffset = -1;
- ranges = null;
- styles = null;
- }
- if (event.doit) {
- if (fixed_length [0] == -1 || fixed_length [0] == length [0]) {
- for (int i=0; i<chars.length; i++) {
- if (chars [i] == 0) break;
- event = new Event ();
- event.character = chars [i];
- parent.sendKeyEvent (SWT.KeyDown, event);
- }
- }
- }
- return OS.noErr;
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (this == parent.getIME ()) parent.setIME (null);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
- text = null;
- styles = null;
- ranges = null;
-}
-
-/**
- * Sets the offset of the composition from the start of the document.
- * This is the start offset of the composition within the document and
- * in not changed by the input method editor itself during the in-line edit
- * session but may need to be changed by clients of the IME. For example,
- * if during an in-line edit operation, a text editor inserts characters
- * above the IME, then the IME must be informed that the composition
- * offset has changed.
- *
- * @param offset the offset of the composition
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCompositionOffset (int offset) {
- checkWidget ();
- if (offset < 0) return;
- if (startOffset != -1) {
- startOffset = offset;
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Label.java
deleted file mode 100644
index 5a475f7e4b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Label.java
+++ /dev/null
@@ -1,395 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.ControlFontStyleRec;
-import org.eclipse.swt.internal.carbon.OS;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a non-selectable
- * user interface object that displays a string or image.
- * When SEPARATOR is specified, displays a single
- * vertical or horizontal line.
- * <p>
- * Shadow styles are hints and may not be honored
- * by the platform. To create a separator label
- * with the default shadow style for the platform,
- * do not specify a shadow style.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SEPARATOR, HORIZONTAL, VERTICAL</dd>
- * <dd>SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd>
- * <dd>CENTER, LEFT, RIGHT, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of SHADOW_IN, SHADOW_OUT and SHADOW_NONE may be specified.
- * SHADOW_NONE is a HINT. Only one of HORIZONTAL and VERTICAL may be specified.
- * Only one of CENTER, LEFT and RIGHT may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#label">Label snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Label extends Control {
- String text = "";
- Image image;
- boolean isImage;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SEPARATOR
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#SHADOW_IN
- * @see SWT#SHADOW_OUT
- * @see SWT#SHADOW_NONE
- * @see SWT#CENTER
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#WRAP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Label (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-void addRelation (Control control) {
- if (!control.isDescribedByLabel ()) return;
-
- int labelElement = OS.AXUIElementCreateWithHIObjectAndIdentifier (handle, 0);
- String string = OS.kAXTitleUIElementAttribute; // control LabeledBy this
- char [] buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- int stringRef = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- OS.HIObjectSetAuxiliaryAccessibilityAttribute(control.focusHandle (), 0, stringRef, labelElement);
- OS.CFRelease(labelElement);
- OS.CFRelease(stringRef);
-
- int relatedElement = OS.AXUIElementCreateWithHIObjectAndIdentifier (control.focusHandle (), 0);
- int array = OS.CFArrayCreateMutable(OS.kCFAllocatorDefault, 1, 0);
- OS.CFArrayAppendValue(array, relatedElement);
- string = OS.kAXServesAsTitleForUIElementsAttribute; // this LabelFor control
- buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- stringRef = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- OS.HIObjectSetAuxiliaryAccessibilityAttribute(handle, 0, stringRef, array);
- OS.CFRelease(relatedElement);
- OS.CFRelease(stringRef);
- OS.CFRelease(array);
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- if ((style & SWT.SEPARATOR) != 0) {
- style = checkBits (style, SWT.VERTICAL, SWT.HORIZONTAL, 0, 0, 0, 0);
- return checkBits (style, SWT.SHADOW_OUT, SWT.SHADOW_IN, SWT.SHADOW_NONE, 0, 0, 0);
- }
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = 0, height = 0;
- if ((style & SWT.SEPARATOR) != 0) {
- if ((style & SWT.HORIZONTAL) != 0) {
- width = DEFAULT_WIDTH;
- height = 3;
- } else {
- width = 3;
- height = DEFAULT_HEIGHT;
- }
- } else {
- if (isImage && image != null) {
- Rectangle r = image.getBounds ();
- width = r.width;
- height = r.height;
- } else {
- int [] ptr = new int [1];
- OS.GetControlData (handle, (short) 0 , OS.kControlStaticTextCFStringTag, 4, ptr, null);
- Point size = textExtent (ptr [0], (style & SWT.WRAP) != 0 && wHint != SWT.DEFAULT ? wHint : 0);
- if (ptr [0] != 0) OS.CFRelease (ptr [0]);
- width = size.x;
- height = size.y;
- }
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- return new Point (width, height);
-}
-
-void createHandle () {
- state |= GRAB | THEME_BACKGROUND;
- int [] outControl = new int [1];
- int window = OS.GetControlOwner (parent.handle);
- if ((style & SWT.SEPARATOR) != 0) {
- OS.CreateSeparatorControl (window, null, outControl);
- } else {
- int just = OS.teFlushLeft;
- if ((style & SWT.CENTER) != 0) just = OS.teCenter;
- if ((style & SWT.RIGHT) != 0) just = OS.teFlushRight;
- ControlFontStyleRec fontStyle = new ControlFontStyleRec ();
- fontStyle.flags |= OS.kControlUseJustMask;
- fontStyle.just = (short) just;
- OS.CreateStaticTextControl (window, null, 0, fontStyle, outControl);
- }
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
- if ((style & SWT.WRAP) == 0) {
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlStaticTextIsMultilineTag, 1, new byte[] {0});
- }
-}
-
-int defaultThemeFont () {
- if (display.smallFonts) return OS.kThemeSmallSystemFont;
- return OS.kThemePushButtonFont;
-}
-
-void drawBackground (int control, int context) {
- fillBackground (control, context, null);
-}
-
-void drawWidget (int control, int context, int damageRgn, int visibleRgn, int theEvent) {
- if (isImage && image != null) {
- GCData data = new GCData ();
- data.paintEvent = theEvent;
- data.visibleRgn = visibleRgn;
- GC gc = GC.carbon_new (this, data);
- int x = 0;
- Point size = getSize ();
- Rectangle bounds = image.getBounds ();
- if ((style & SWT.CENTER) != 0) x = (size.x - bounds.width) / 2;
- if ((style & SWT.RIGHT) != 0) x = size.x - bounds.width;
- gc.drawImage (image, x, 0);
- gc.dispose ();
- }
- super.drawWidget (control, context, damageRgn, visibleRgn, theEvent);
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is a <code>SEPARATOR</code> label, in
- * which case, <code>NONE</code> is returned.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-/**
- * Returns the receiver's image if it has one, or null
- * if it does not.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set or if the receiver is
- * a <code>SEPARATOR</code> label.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return "";
- return text;
-}
-
-boolean isDescribedByLabel () {
- return false;
-}
-
-/*
- * Remove "Label for" relations from the receiver.
- */
-void removeRelation () {
- String string = OS.kAXServesAsTitleForUIElementsAttribute;
- char [] buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- int stringRef = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- OS.HIObjectSetAuxiliaryAccessibilityAttribute(handle, 0, stringRef, 0);
- OS.CFRelease(stringRef);
-}
-
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>. If the receiver is a <code>SEPARATOR</code>
- * label, the argument is ignored and the alignment is not changed.
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return;
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- int just = OS.teFlushLeft;
- if ((alignment & SWT.CENTER) != 0) just = OS.teCenter;
- if ((alignment & SWT.RIGHT) != 0) just = OS.teFlushRight;
- ControlFontStyleRec fontStyle = new ControlFontStyleRec ();
- OS.GetControlData (handle, (short) OS.kControlEntireControl, OS.kControlFontStyleTag, ControlFontStyleRec.sizeof, fontStyle, null);
- fontStyle.flags |= OS.kControlUseJustMask;
- fontStyle.just = (short) just;
- OS.SetControlFontStyle (handle, fontStyle);
- redraw ();
-}
-
-/**
- * Sets the receiver's image to the argument, which may be
- * null indicating that no image should be displayed.
- *
- * @param image the image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return;
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.image = image;
- isImage = true;
- if (image == null) {
- setText (text);
- return;
- }
- if (text.length () > 0) {
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, null, 0);
- if (ptr == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- OS.SetControlData (handle, 0 , OS.kControlStaticTextCFStringTag, 4, new int[]{ptr});
- OS.CFRelease (ptr);
- }
- redraw ();
-}
-
-/**
- * Sets the receiver's text.
- * <p>
- * This method sets the widget label. The label may include
- * the mnemonic character and line delimiters.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, focus is assigned
- * to the control that follows the label. On most platforms,
- * the mnemonic appears underlined but may be emphasised in a
- * platform specific manner. The mnemonic indicator character
- * '&amp;' can be escaped by doubling it in the string, causing
- * a single '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- isImage = false;
- text = string;
- char [] buffer = new char [text.length ()];
- text.getChars (0, buffer.length, buffer, 0);
- int length = fixMnemonic (buffer);
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, length);
- if (ptr == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- OS.SetControlData (handle, 0 , OS.kControlStaticTextCFStringTag, 4, new int[]{ptr});
- OS.CFRelease (ptr);
- redraw ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Link.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Link.java
deleted file mode 100644
index 0d0fb58396..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Link.java
+++ /dev/null
@@ -1,735 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.carbon.CFRange;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.Rect;
-import org.eclipse.swt.internal.carbon.CGPoint;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable
- * user interface object that displays a text with
- * links.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#link">Link snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Link extends Control {
- String text;
- TextLayout layout;
- Color linkColor, disabledColor;
- Point [] offsets;
- Point selection;
- String [] ids;
- int [] mnemonics;
- int focusIndex;
-
- static final RGB LINK_FOREGROUND = new RGB (0, 51, 153);
- static final RGB LINK_DISABLED_FOREGROUND = new RGB (172, 168, 153);
- static final String [] AX_ATTRIBUTES = {
- OS.kAXTitleAttribute,
- };
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Link (Composite parent, int style) {
- super (parent, style);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected by the user.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-int callFocusEventHandler (int nextHandler, int theEvent) {
- return OS.noErr;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- int width, height;
- int layoutWidth = layout.getWidth ();
- //TEMPORARY CODE
- if (wHint == 0) {
- layout.setWidth (1);
- Rectangle rect = layout.getBounds ();
- width = 0;
- height = rect.height;
- } else {
- layout.setWidth (wHint);
- Rectangle rect = layout.getBounds ();
- width = rect.width;
- height = rect.height;
- }
- layout.setWidth (layoutWidth);
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2;
- height += border * 2;
- return new Point (width, height);
-}
-
-void createHandle () {
- state |= GRAB | THEME_BACKGROUND;
- int features = OS.kControlSupportsFocus;
- int [] outControl = new int [1];
- int window = OS.GetControlOwner (parent.handle);
- OS.CreateUserPaneControl (window, null, features, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
- layout = new TextLayout (display);
- linkColor = new Color (display, LINK_FOREGROUND);
- disabledColor = new Color (display, LINK_DISABLED_FOREGROUND);
- offsets = new Point [0];
- ids = new String [0];
- mnemonics = new int [0];
- selection = new Point (-1, -1);
- focusIndex = -1;
-}
-
-void createWidget () {
- super.createWidget ();
- layout.setFont (getFont ());
- text = "";
-}
-
-void drawBackground (int control, int context) {
- fillBackground (control, context, null);
- if (!hasFocus () || !drawFocusRing () || focusIndex == -1) return;
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricFocusRectOutset, outMetric);
- outMetric[0]--;
- Rect r = new Rect ();
- Rectangle [] rects = getRectangles (focusIndex);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rect = rects [i];
- r.left = (short) (rect.x + outMetric[0]);
- r.top = (short) (rect.y + outMetric[0]);
- r.right = (short) (r.left + rect.width - (outMetric[0] * 2));
- r.bottom = (short) (r.top + rect.height - (outMetric[0] * 2));
- OS.DrawThemeFocusRect (r, true);
- }
-}
-
-void drawWidget (int control, int context, int damageRgn, int visibleRgn, int theEvent) {
- GCData data = new GCData ();
- data.paintEvent = theEvent;
- data.visibleRgn = visibleRgn;
- GC gc = GC.carbon_new (this, data);
- int selStart = selection.x;
- int selEnd = selection.y;
- if (selStart > selEnd) {
- selStart = selection.y;
- selEnd = selection.x;
- }
- // temporary code to disable text selection
- selStart = selEnd = -1;
- if ((state & DISABLED) != 0) gc.setForeground (disabledColor);
- layout.draw (gc, 0, 0, selStart, selEnd, null, null);
- gc.dispose ();
- super.drawWidget (control, context, damageRgn, visibleRgn, theEvent);
-}
-
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- TextStyle linkStyle = new TextStyle (null, enabled ? linkColor : disabledColor, null);
- linkStyle.underline = true;
- for (int i = 0; i < offsets.length; i++) {
- Point point = offsets [i];
- layout.setStyle (linkStyle, point.x, point.y);
- }
- redraw ();
-}
-
-String [] getAxAttributes () {
- return AX_ATTRIBUTES;
-}
-
-String getNameText () {
- return getText ();
-}
-
-Rectangle [] getRectangles (int linkIndex) {
- int lineCount = layout.getLineCount ();
- Rectangle [] rects = new Rectangle [lineCount];
- int [] lineOffsets = layout.getLineOffsets ();
- Point point = offsets [linkIndex];
- int lineStart = 1;
- while (point.x > lineOffsets [lineStart]) lineStart++;
- int lineEnd = 1;
- while (point.y > lineOffsets [lineEnd]) lineEnd++;
- int index = 0;
- if (lineStart == lineEnd) {
- rects [index++] = layout.getBounds (point.x, point.y);
- } else {
- rects [index++] = layout.getBounds (point.x, lineOffsets [lineStart]-1);
- rects [index++] = layout.getBounds (lineOffsets [lineEnd-1], point.y);
- if (lineEnd - lineStart > 1) {
- for (int i = lineStart; i < lineEnd - 1; i++) {
- rects [index++] = layout.getLineBounds (i);
- }
- }
- }
- if (rects.length != index) {
- Rectangle [] tmp = new Rectangle [index];
- System.arraycopy (rects, 0, tmp, 0, index);
- rects = tmp;
- }
- return rects;
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-int kEventAccessibleGetNamedAttribute (int nextHandler, int theEvent, int userData) {
- int code = OS.eventNotHandledErr;
- int [] stringRef = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamAccessibleAttributeName, OS.typeCFStringRef, null, 4, null, stringRef);
- int length = 0;
- if (stringRef [0] != 0) length = OS.CFStringGetLength (stringRef [0]);
- char [] buffer = new char [length];
- CFRange range = new CFRange ();
- range.length = length;
- OS.CFStringGetCharacters (stringRef [0], range, buffer);
- String attributeName = new String(buffer);
- if (attributeName.equals (OS.kAXRoleAttribute) || attributeName.equals (OS.kAXRoleDescriptionAttribute)) {
- String roleText = OS.kAXLinkRole;
- buffer = new char [roleText.length ()];
- roleText.getChars (0, buffer.length, buffer, 0);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- if (attributeName.equals (OS.kAXRoleAttribute)) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- } else { // kAXRoleDescriptionAttribute
- int stringRef2 = OS.HICopyAccessibilityRoleDescription (stringRef [0], 0);
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, new int [] {stringRef2});
- OS.CFRelease(stringRef2);
- }
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- } else if (attributeName.equals (OS.kAXTitleAttribute) || attributeName.equals (OS.kAXDescriptionAttribute)) {
- String text = parse (getText ());
- if (text != null) {
- buffer = new char [text.length ()];
- text.getChars (0, buffer.length, buffer, 0);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- }
- }
- if (accessible != null) {
- code = accessible.internal_kEventAccessibleGetNamedAttribute (nextHandler, theEvent, code);
- }
- return code;
-}
-
-int kEventControlGetFocusPart (int nextHandler, int theEvent, int userData) {
- return OS.noErr;
-}
-
-int kEventControlSetFocusPart (int nextHandler, int theEvent, int userData) {
- int result = super.kEventControlSetFocusPart (nextHandler, theEvent, userData);
- if (result == OS.noErr) redraw ();
- return result;
-}
-
-int kEventMouseMoved (int nextHandler, int theEvent, int userData) {
- int result = super.kEventMouseMoved (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- CGPoint pt = new CGPoint ();
- OS.GetEventParameter (theEvent, OS.kEventParamWindowMouseLocation, OS.typeHIPoint, null, CGPoint.sizeof, null, pt);
- OS.HIViewConvertPoint (pt, 0, handle);
- int x = (int) pt.x;
- int y = (int) pt.y;
- for (int j = 0; j < offsets.length; j++) {
- Rectangle [] rects = getRectangles (j);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rectangle = rects [i];
- if (rectangle.contains (x, y)) {
- setCursor (display.getSystemCursor (SWT.CURSOR_HAND));
- return result;
- }
- }
- }
- setCursor (null);
- return result;
-}
-
-int kEventUnicodeKeyPressed (int nextHandler, int theEvent, int userData) {
- int result = super.kEventUnicodeKeyPressed (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- if (focusIndex == -1) return result;
- int [] keyboardEvent = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendKeyboardEvent, OS.typeEventRef, null, keyboardEvent.length * 4, null, keyboardEvent);
- int [] keyCode = new int [1];
- OS.GetEventParameter (keyboardEvent [0], OS.kEventParamKeyCode, OS.typeUInt32, null, keyCode.length * 4, null, keyCode);
- switch (keyCode [0]) {
- case 36: /* Return */
- case 49: /* Space */
- case 76: /* Enter */
- Event event = new Event ();
- event.text = ids [focusIndex];
- sendEvent (SWT.Selection, event);
- break;
- case 48: /* Tab */
- int [] modifiers = new int [1];
- OS.GetEventParameter (keyboardEvent [0], OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
- boolean next = (modifiers [0] & OS.shiftKey) == 0;
- if (next) {
- if (focusIndex < offsets.length - 1) {
- focusIndex++;
- redraw ();
- }
- } else {
- if (focusIndex > 0) {
- focusIndex--;
- redraw ();
- }
- }
- break;
-
- }
- return result;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (layout != null) layout.dispose ();
- layout = null;
- if (linkColor != null) linkColor.dispose ();
- linkColor = null;
- if (disabledColor != null) disabledColor.dispose ();
- disabledColor = null;
- offsets = null;
- ids = null;
- mnemonics = null;
- text = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection, listener);
-}
-
-String parse (String string) {
- int length = string.length ();
- offsets = new Point [length / 4];
- ids = new String [length / 4];
- mnemonics = new int [length / 4 + 1];
- StringBuffer result = new StringBuffer ();
- char [] buffer = new char [length];
- string.getChars (0, string.length (), buffer, 0);
- int index = 0, state = 0, linkIndex = 0;
- int start = 0, tagStart = 0, linkStart = 0, endtagStart = 0, refStart = 0;
- while (index < length) {
- char c = Character.toLowerCase (buffer [index]);
- switch (state) {
- case 0:
- if (c == '<') {
- tagStart = index;
- state++;
- }
- break;
- case 1:
- if (c == 'a') state++;
- break;
- case 2:
- switch (c) {
- case 'h':
- state = 7;
- break;
- case '>':
- linkStart = index + 1;
- state++;
- break;
- default:
- if (Character.isWhitespace(c)) break;
- else state = 13;
- }
- break;
- case 3:
- if (c == '<') {
- endtagStart = index;
- state++;
- }
- break;
- case 4:
- state = c == '/' ? state + 1 : 3;
- break;
- case 5:
- state = c == 'a' ? state + 1 : 3;
- break;
- case 6:
- if (c == '>') {
- mnemonics [linkIndex] = parseMnemonics (buffer, start, tagStart, result);
- int offset = result.length ();
- parseMnemonics (buffer, linkStart, endtagStart, result);
- offsets [linkIndex] = new Point (offset, result.length () - 1);
- if (ids [linkIndex] == null) {
- ids [linkIndex] = new String (buffer, linkStart, endtagStart - linkStart);
- }
- linkIndex++;
- start = tagStart = linkStart = endtagStart = refStart = index + 1;
- state = 0;
- } else {
- state = 3;
- }
- break;
- case 7:
- state = c == 'r' ? state + 1 : 0;
- break;
- case 8:
- state = c == 'e' ? state + 1 : 0;
- break;
- case 9:
- state = c == 'f' ? state + 1 : 0;
- break;
- case 10:
- state = c == '=' ? state + 1 : 0;
- break;
- case 11:
- if (c == '"') {
- state++;
- refStart = index + 1;
- } else {
- state = 0;
- }
- break;
- case 12:
- if (c == '"') {
- ids[linkIndex] = new String (buffer, refStart, index - refStart);
- state = 2;
- }
- break;
- case 13:
- if (Character.isWhitespace (c)) {
- state = 0;
- } else if (c == '='){
- state++;
- }
- break;
- case 14:
- state = c == '"' ? state + 1 : 0;
- break;
- case 15:
- if (c == '"') state = 2;
- break;
- default:
- state = 0;
- break;
- }
- index++;
- }
- if (start < length) {
- int tmp = parseMnemonics (buffer, start, tagStart, result);
- int mnemonic = parseMnemonics (buffer, Math.max (tagStart, linkStart), length, result);
- if (mnemonic == -1) mnemonic = tmp;
- mnemonics [linkIndex] = mnemonic;
- } else {
- mnemonics [linkIndex] = -1;
- }
- if (offsets.length != linkIndex) {
- Point [] newOffsets = new Point [linkIndex];
- System.arraycopy (offsets, 0, newOffsets, 0, linkIndex);
- offsets = newOffsets;
- String [] newIDs = new String [linkIndex];
- System.arraycopy (ids, 0, newIDs, 0, linkIndex);
- ids = newIDs;
- int [] newMnemonics = new int [linkIndex + 1];
- System.arraycopy (mnemonics, 0, newMnemonics, 0, linkIndex + 1);
- mnemonics = newMnemonics;
- }
- return result.toString ();
-}
-
-int parseMnemonics (char[] buffer, int start, int end, StringBuffer result) {
- int mnemonic = -1, index = start;
- while (index < end) {
- if (buffer [index] == '&') {
- if (index + 1 < end && buffer [index + 1] == '&') {
- result.append (buffer [index]);
- index++;
- } else {
- mnemonic = result.length();
- }
- } else {
- result.append (buffer [index]);
- }
- index++;
- }
- return mnemonic;
-}
-
-boolean sendMouseEvent (int type, short button, int count, int detail, boolean send, int chord, short x, short y, int modifiers) {
- boolean result = super.sendMouseEvent (type, button, count, detail, send, chord, x, y, modifiers);
- switch (type) {
- case SWT.MouseDown:
- if (button == 1 && count == 1) {
- int offset = layout.getOffset (x, y, null);
- int oldSelectionX = selection.x;
- int oldSelectionY = selection.y;
- selection.x = offset;
- selection.y = -1;
- if (oldSelectionX != -1 && oldSelectionY != -1) {
- if (oldSelectionX > oldSelectionY) {
- int temp = oldSelectionX;
- oldSelectionX = oldSelectionY;
- oldSelectionY = temp;
- }
- Rectangle rectangle = layout.getBounds (oldSelectionX, oldSelectionY);
- redraw (rectangle.x, rectangle.y, rectangle.width, rectangle.height, false);
- }
- for (int j = 0; j < offsets.length; j++) {
- Rectangle [] rects = getRectangles (j);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rectangle = rects [i];
- if (rectangle.contains (x, y)) {
- focusIndex = j;
- redraw ();
- setFocus ();
- return result;
- }
- }
- }
- }
- break;
- case SWT.MouseMove:
- if ((chord & 0x01) != 0) {
- int oldSelection = selection.y;
- selection.y = layout.getOffset (x, y, null);
- if (selection.y != oldSelection) {
- int newSelection = selection.y;
- if (oldSelection > newSelection) {
- int temp = oldSelection;
- oldSelection = newSelection;
- newSelection = temp;
- }
- Rectangle rectangle = layout.getBounds (oldSelection, newSelection);
- redraw (rectangle.x, rectangle.y, rectangle.width, rectangle.height, false);
- }
- }
- break;
- case SWT.MouseUp:
- if (focusIndex == -1) break;
- if (button == 1) {
- Rectangle [] rects = getRectangles (focusIndex);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rectangle = rects [i];
- if (rectangle.contains (x, y)) {
- Event event = new Event ();
- event.text = ids [focusIndex];
- notifyListeners (SWT.Selection, event);
- return result;
- }
- }
- }
- break;
- }
-
- return result;
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- int result = super.setBounds(x, y, width, height, move, resize, events);
- if ((result & RESIZED) != 0) {
- layout.setWidth (width > 0 ? width : -1);
- }
- return result;
-}
-
-void setFontStyle (Font font) {
- super.setFontStyle (font);
- layout.setFont (getFont ());
-}
-
-/**
- * Sets the receiver's text.
- * <p>
- * The string can contain both regular text and hyperlinks. A hyperlink
- * is delimited by an anchor tag, &lt;A&gt; and &lt;/A&gt;. Within an
- * anchor, a single HREF attribute is supported. When a hyperlink is
- * selected, the text field of the selection event contains either the
- * text of the hyperlink or the value of its HREF, if one was specified.
- * In the rare case of identical hyperlinks within the same string, the
- * HREF attribute can be used to distinguish between them. The string may
- * include the mnemonic character and line delimiters. The only delimiter
- * the HREF attribute supports is the quotation mark (").
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (string.equals (text)) return;
- text = string;
- layout.setText (parse (string));
- focusIndex = offsets.length > 0 ? 0 : -1 ;
- selection.x = selection.y = -1;
- boolean enabled = (state & DISABLED) == 0;
- TextStyle linkStyle = new TextStyle (null, enabled ? linkColor : disabledColor, null);
- linkStyle.underline = true;
- for (int i = 0; i < offsets.length; i++) {
- Point point = offsets [i];
- layout.setStyle (linkStyle, point.x, point.y);
- }
- /*
- * This code is intentionally commented. Mnemonics are
- * not drawn on the Macintosh.
- */
-// TextStyle mnemonicStyle = new TextStyle (null, null, null);
-// mnemonicStyle.underline = true;
-// for (int i = 0; i < mnemonics.length; i++) {
-// int mnemonic = mnemonics [i];
-// if (mnemonic != -1) {
-// layout.setStyle (mnemonicStyle, mnemonic, mnemonic);
-// }
-// }
- redraw ();
-}
-
-int traversalCode (int key, int theEvent) {
- if (offsets.length == 0) return 0;
- int bits = super.traversalCode (key, theEvent);
- if (key == 48 /* Tab */ && theEvent != 0) {
- int [] modifiers = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
- boolean next = (modifiers [0] & OS.shiftKey) == 0;
- if (next && focusIndex < offsets.length - 1) {
- return bits & ~ SWT.TRAVERSE_TAB_NEXT;
- }
- if (!next && focusIndex > 0) {
- return bits & ~ SWT.TRAVERSE_TAB_PREVIOUS;
- }
- }
- return bits;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/List.java
deleted file mode 100644
index bc1d21442c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/List.java
+++ /dev/null
@@ -1,1573 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.CFRange;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.DataBrowserCallbacks;
-import org.eclipse.swt.internal.carbon.DataBrowserListViewColumnDesc;
-import org.eclipse.swt.internal.carbon.Rect;
-import org.eclipse.swt.internal.carbon.CGPoint;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface
- * object that displays a list of strings and issues notification
- * when a string is selected. A list may be single or multi select.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection</dd>
- * </dl>
- * <p>
- * Note: Only one of SINGLE and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#list">List snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class List extends Scrollable {
- String [] items;
- int itemCount, anchorFirst, anchorLast;
- boolean ignoreSelect;
- static final int COLUMN_ID = 1024;
- static final int EXTRA_WIDTH = 25;
- static final int BORDER_INSET = 1;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public List (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the argument to the end of the receiver's list.
- *
- * @param string the new item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String,int)
- */
-public void add (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int [] id = new int [] {itemCount + 1};
- if (OS.AddDataBrowserItems (handle, OS.kDataBrowserNoItem, 1, id, OS.kDataBrowserItemNoProperty) != OS.noErr) {
- error (SWT.ERROR_ITEM_NOT_ADDED);
- }
- if (itemCount == items.length) {
- String [] newItems = new String [itemCount + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- items [itemCount++] = string;
-}
-
-/**
- * Adds the argument to the receiver's list at the given
- * zero-relative index.
- * <p>
- * Note: To add an item at the end of the list, use the
- * result of calling <code>getItemCount()</code> as the
- * index or use <code>add(String)</code>.
- * </p>
- *
- * @param string the new item
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String)
- */
-public void add (String string, int index) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- int [] id = new int [] {itemCount + 1};
- if (OS.AddDataBrowserItems (handle, OS.kDataBrowserNoItem, 1, id, OS.kDataBrowserItemNoProperty) != OS.noErr) {
- error (SWT.ERROR_ITEM_NOT_ADDED);
- }
- if (index != itemCount) fixSelection (index, true);
- if (itemCount == items.length) {
- String [] newItems = new String [itemCount + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- System.arraycopy (items, index, items, index + 1, itemCount++ - index);
- items [index] = string;
- OS.UpdateDataBrowserItems (handle, 0, 0, null, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the selection changes.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = 0;
- if (wHint == SWT.DEFAULT) {
- GC gc = new GC (this);
- for (int i=0; i<itemCount; i++) {
- Point extent = gc.stringExtent (items [i]);
- width = Math.max (width, extent.x);
- }
- gc.dispose ();
- width += EXTRA_WIDTH;
- } else {
- width = wHint;
- }
- if (width <= 0) width = DEFAULT_WIDTH;
- int height = 0;
- if (hHint == SWT.DEFAULT) {
- height = itemCount * getItemHeight ();
- } else {
- height = hHint;
- }
- if (height <= 0) height = DEFAULT_HEIGHT;
- Rectangle rect = computeTrim (0, 0, width, height);
- return new Point (rect.width, rect.height);
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- int border = getBorderWidth ();
- Rect rect = new Rect ();
- OS.GetDataBrowserScrollBarInset (handle, rect);
- x -= rect.left + border;
- y -= rect.top + border;
- width += rect.left + rect.right + border + border;
- height += rect.top + rect.bottom + border + border;
- return new Rectangle (x, y, width, height);
-}
-
-boolean contains (int shellX, int shellY) {
- CGPoint pt = new CGPoint ();
- int [] contentView = new int [1];
- OS.HIViewFindByID (OS.HIViewGetRoot (OS.GetControlOwner (handle)), OS.kHIViewWindowContentID (), contentView);
- OS.HIViewConvertPoint (pt, handle, contentView [0]);
- int x = shellX - (int) pt.x;
- int y = shellY - (int) pt.y;
- return getClientArea ().contains (x, y);
-}
-
-void createHandle () {
- int [] outControl = new int [1];
- int window = OS.GetControlOwner (parent.handle);
- OS.CreateDataBrowserControl (window, null, OS.kDataBrowserListView, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
- if (!drawFocusRing ()) {
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlDataBrowserIncludesFrameAndFocusTag, 1, new byte[] {0});
- }
- int selectionFlags = (style & SWT.SINGLE) != 0 ? OS.kDataBrowserSelectOnlyOne | OS.kDataBrowserNeverEmptySelectionSet : OS.kDataBrowserCmdTogglesSelection;
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags);
- OS.SetDataBrowserListViewHeaderBtnHeight (handle, (short) 0);
- OS.SetDataBrowserTableViewHiliteStyle (handle, OS.kDataBrowserTableViewFillHilite);
- OS.SetDataBrowserHasScrollBars (handle, (style & SWT.H_SCROLL) != 0, (style & SWT.V_SCROLL) != 0);
- DataBrowserListViewColumnDesc column = new DataBrowserListViewColumnDesc ();
- column.headerBtnDesc_version = OS.kDataBrowserListViewLatestHeaderDesc;
- column.propertyDesc_propertyID = COLUMN_ID;
- column.propertyDesc_propertyType = OS.kDataBrowserTextType;
- column.propertyDesc_propertyFlags = OS.kDataBrowserListViewSelectionColumn | OS.kDataBrowserDefaultPropertyFlags;
- //NOT DONE
- column.headerBtnDesc_maximumWidth= 0x7FFF;
- column.headerBtnDesc_initialOrder= (short) OS.kDataBrowserOrderIncreasing;
- OS.AddDataBrowserListViewColumn (handle, column, 0);
-
- /*
- * Feature in the Macintosh. Scroll bars are not created until
- * the data browser needs to draw them. The fix is to force the scroll
- * bars to be created by temporarily giving the widget a size, drawing
- * it on a offscreen buffer to avoid flashes and then restoring it to
- * size zero.
- */
- if (OS.VERSION < 0x1040) {
- OS.HIViewSetDrawingEnabled (handle, false);
- int size = 50;
- Rect rect = new Rect ();
- rect.right = rect.bottom = (short) size;
- OS.SetControlBounds (handle, rect);
- int bpl = size * 4;
- int [] gWorld = new int [1];
- int data = OS.NewPtr (bpl * size);
- OS.NewGWorldFromPtr (gWorld, OS.k32ARGBPixelFormat, rect, 0, 0, 0, data, bpl);
- int [] curPort = new int [1];
- int [] curGWorld = new int [1];
- OS.GetGWorld (curPort, curGWorld);
- OS.SetGWorld (gWorld [0], curGWorld [0]);
- OS.DrawControlInCurrentPort (handle);
- OS.SetGWorld (curPort [0], curGWorld [0]);
- OS.DisposeGWorld (gWorld [0]);
- OS.DisposePtr (data);
- rect.right = rect.bottom = (short) 0;
- OS.SetControlBounds (handle, rect);
- OS.HIViewSetDrawingEnabled (handle, true);
- }
-}
-
-void createWidget () {
- super.createWidget ();
- items = new String [4];
- if (OS.VERSION >= 0x1050) {
- OS.DataBrowserChangeAttributes (handle, OS.kDataBrowserAttributeAutoHideScrollBars, 0);
- }
-}
-
-ScrollBar createScrollBar (int style) {
- return createStandardBar (style);
-}
-
-Color defaultBackground () {
- return display.getSystemColor (SWT.COLOR_LIST_BACKGROUND);
-}
-
-Color defaultForeground () {
- return display.getSystemColor (SWT.COLOR_LIST_FOREGROUND);
-}
-
-int defaultThemeFont () {
- if (display.smallFonts) return OS.kThemeSmallSystemFont;
- return OS.kThemeViewsFont;
-}
-
-/**
- * Deselects the item at the given zero-relative index in the receiver.
- * If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget();
- if (0 <= index && index < itemCount) {
- int [] ids = new int [] {index + 1};
- deselect (ids, ids.length);
- }
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. The range of the
- * indices is inclusive. Indices that are out of range are ignored.
- *
- * @param start the start index of the items to deselect
- * @param end the end index of the items to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int start, int end) {
- checkWidget();
- if (start > end) return;
- if (end < 0 || start >= itemCount) return;
- start = Math.max (0, start);
- end = Math.min (itemCount - 1, end);
- int length = end - start + 1;
- if (length <= 0) return;
- int [] ids = new int [length];
- for (int i=0; i<length; i++) ids [i] = end - i + 1;
- deselect (ids, length);
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. Indices that are out
- * of range and duplicate indices are ignored.
- *
- * @param indices the array of indices for the items to deselect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int [] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- //NOT DONE - range check
- int length = indices.length;
- int [] ids = new int [length];
- for (int i=0; i<length; i++) ids [i] = indices [length - i - 1] + 1;
- deselect (ids, length);
-}
-
-void deselect (int [] ids, int count) {
- ignoreSelect = true;
- /*
- * Bug in the Macintosh. When the DataBroswer selection flags includes
- * both kDataBrowserNeverEmptySelectionSet and kDataBrowserSelectOnlyOne,
- * two items are selected when SetDataBrowserSelectedItems() is called
- * with kDataBrowserItemsAssign to assign a new seletion despite the fact
- * that kDataBrowserSelectOnlyOne was specified. The fix is to save and
- * restore kDataBrowserNeverEmptySelectionSet around each call to
- * SetDataBrowserSelectedItems().
- */
- int [] selectionFlags = null;
- if ((style & SWT.SINGLE) != 0) {
- selectionFlags = new int [1];
- OS.GetDataBrowserSelectionFlags (handle, selectionFlags);
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0] & ~OS.kDataBrowserNeverEmptySelectionSet);
- }
- OS.SetDataBrowserSelectedItems (handle, count, ids, OS.kDataBrowserItemsRemove);
- if ((style & SWT.SINGLE) != 0) {
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0]);
- }
- ignoreSelect = false;
-}
-
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll () {
- checkWidget ();
- deselect (null, 0);
-}
-
-void destroyScrollBar (ScrollBar bar) {
- if ((bar.style & SWT.H_SCROLL) != 0) style &= ~SWT.H_SCROLL;
- if ((bar.style & SWT.V_SCROLL) != 0) style &= ~SWT.V_SCROLL;
- OS.SetDataBrowserHasScrollBars (handle, (style & SWT.H_SCROLL) != 0, (style & SWT.V_SCROLL) != 0);
-}
-
-void fixSelection (int index, boolean add) {
- int [] selection = getSelectionIndices ();
- if (selection.length == 0) return;
- int newCount = 0;
- boolean fix = false;
- for (int i = 0; i < selection.length; i++) {
- if (!add && selection [i] == index) {
- fix = true;
- } else {
- int newIndex = newCount++;
- selection [newIndex] = selection [i] + 1;
- if (selection [newIndex] - 1 >= index) {
- selection [newIndex] += add ? 1 : -1;
- fix = true;
- }
- }
- }
- if (fix) select (selection, newCount, true);
-}
-
-public int getBorderWidth () {
- checkWidget ();
- int border = 0;
- byte [] hasBorder = new byte [1];
- OS.GetControlData (handle, (short) OS.kControlEntireControl, OS.kControlDataBrowserIncludesFrameAndFocusTag, 1, hasBorder, null);
- if (hasBorder [0] != 0) {
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricFocusRectOutset, outMetric);
- border += outMetric [0] - BORDER_INSET;
- }
- return border;
-}
-
-public Rectangle getClientArea () {
- checkWidget();
- int border = getBorderWidth ();
- Rect rect = new Rect (), inset = new Rect ();
- OS.GetControlBounds (handle, rect);
- OS.GetDataBrowserScrollBarInset (handle, inset);
- int width = Math.max (0, rect.right - rect.left - inset.right - border - border);
- int height = Math.max (0, rect.bottom - rect.top - inset.bottom - border - border);
- return new Rectangle (inset.left + border, inset.top + border, width, height);
-}
-
-/**
- * Returns the zero-relative index of the item which currently
- * has the focus in the receiver, or -1 if no item has focus.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getFocusIndex () {
- checkWidget();
- int [] first = new int [1], last = new int [1];
- if (OS.GetDataBrowserSelectionAnchor (handle, first, last) != OS.noErr) return -1;
- return first [0] - 1;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getItem (int index) {
- checkWidget();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- return itemCount;
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the list.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- short [] height = new short [1];
- if (OS.GetDataBrowserTableViewRowHeight (handle, height) != OS.noErr) {
- error (SWT.ERROR_CANNOT_GET_ITEM_HEIGHT);
- }
- return height [0];
-}
-
-/**
- * Returns a (possibly empty) array of <code>String</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver's list
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getItems () {
- checkWidget();
- String [] result = new String [itemCount];
- System.arraycopy (items, 0, result, 0, itemCount);
- return result;
-}
-
-/**
- * Returns an array of <code>String</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getSelection () {
- checkWidget ();
- int ptr = OS.NewHandle (0);
- if (OS.GetDataBrowserItems (handle, OS.kDataBrowserNoItem, true, OS.kDataBrowserItemIsSelected, ptr) != OS.noErr) {
- error (SWT.ERROR_CANNOT_GET_SELECTION);
- }
- int count = OS.GetHandleSize (ptr) / 4;
- String [] result = new String [count];
- if (count > 0) {
- OS.HLock (ptr);
- int [] id = new int [1];
- OS.memmove (id, ptr, 4);
- int offset = id [0] + (count - 1) * 4;
- for (int i=0; i<count; i++, offset -= 4) {
- OS.memmove (id, offset, 4);
- result [i] = items [id [0] - 1];
- }
- OS.HUnlock (ptr);
- }
- OS.DisposeHandle (ptr);
- return result;
-}
-
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget ();
- int [] count = new int [1];
- if (OS.GetDataBrowserItemCount (handle, OS.kDataBrowserNoItem, true, OS.kDataBrowserItemIsSelected, count) != OS.noErr) {
- error (SWT.ERROR_CANNOT_GET_COUNT);
- }
- return count [0];
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item or -1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget();
- int [] first = new int [1], last = new int [1];
- if (OS.GetDataBrowserSelectionAnchor (handle, first, last) != OS.noErr) return -1;
- return first [0] - 1;
-}
-
-/**
- * Returns the zero-relative indices of the items which are currently
- * selected in the receiver. The order of the indices is unspecified.
- * The array is empty if no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return the array of indices of the selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int [] getSelectionIndices () {
- checkWidget ();
- int ptr = OS.NewHandle (0);
- if (OS.GetDataBrowserItems (handle, OS.kDataBrowserNoItem, true, OS.kDataBrowserItemIsSelected, ptr) != OS.noErr) {
- error (SWT.ERROR_CANNOT_GET_SELECTION);
- }
- int count = OS.GetHandleSize (ptr) / 4;
- int [] result = new int [count];
- if (count > 0) {
- OS.HLock (ptr);
- OS.memmove (result, ptr, 4);
- OS.memmove (result, result [0], count * 4);
- OS.HUnlock (ptr);
- for (int start=0, end=count - 1; start<=end; start++, end--) {
- int temp = result [start];
- result [start] = result [end] - 1;
- result [end] = temp - 1;
- }
- }
- OS.DisposeHandle (ptr);
- return result;
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items are
- * scrolled or new items are added or removed.
- *
- * @return the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget();
- int[] top = new int [1], left = new int [1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- return top [0] / getItemHeight ();
-}
-
-void hookEvents () {
- super.hookEvents ();
- DataBrowserCallbacks callbacks = new DataBrowserCallbacks ();
- callbacks.version = OS.kDataBrowserLatestCallbacks;
- OS.InitDataBrowserCallbacks (callbacks);
- callbacks.v1_itemDataCallback = display.itemDataProc;
- callbacks.v1_itemNotificationCallback = display.itemNotificationProc;
- OS.SetDataBrowserCallbacks (handle, callbacks);
-}
-
-int itemDataProc (int browser, int id, int property, int itemData, int setValue) {
- int index = id - 1;
- switch (property) {
- case COLUMN_ID: {
- String text = items [index];
- char [] buffer = new char [text.length ()];
- text.getChars (0, buffer.length, buffer, 0);
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (ptr == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- OS.SetDataBrowserItemDataText (itemData, ptr);
- OS.CFRelease (ptr);
- break;
- }
- }
- return OS.noErr;
-}
-
-int kEventAccessibleGetNamedAttribute (int nextHandler, int theEvent, int userData) {
- int code = OS.eventNotHandledErr;
- int [] stringRef = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamAccessibleAttributeName, OS.typeCFStringRef, null, 4, null, stringRef);
- int length = 0;
- if (stringRef [0] != 0) length = OS.CFStringGetLength (stringRef [0]);
- char [] buffer = new char [length];
- CFRange range = new CFRange ();
- range.length = length;
- OS.CFStringGetCharacters (stringRef [0], range, buffer);
- String attributeName = new String(buffer);
- if (attributeName.equals(OS.kAXHeaderAttribute)) {
- /*
- * Bug in the Macintosh. Even when the header is not visible,
- * VoiceOver still reports each column header's role for every row.
- * This is confusing and overly verbose. The fix is to return
- * "no header" when the screen reader asks for the header, by
- * returning noErr without setting the event parameter.
- */
- code = OS.noErr;
- }
- if (accessible != null) {
- code = accessible.internal_kEventAccessibleGetNamedAttribute (nextHandler, theEvent, code);
- }
- return code;
-}
-
-int kEventControlGetClickActivation (int nextHandler, int theEvent, int userData) {
- OS.SetEventParameter (theEvent, OS.kEventParamClickActivation, OS.typeClickActivationResult, 4, new int [] {OS.kActivateAndHandleClick});
- return OS.noErr;
-}
-
-int kEventControlSetCursor (int nextHandler, int theEvent, int userData) {
- if (!isEnabledCursor ()) return OS.noErr;
- if (isEnabledModal ()) {
- org.eclipse.swt.internal.carbon.Point pt = new org.eclipse.swt.internal.carbon.Point ();
- int sizeof = org.eclipse.swt.internal.carbon.Point.sizeof;
- OS.GetEventParameter (theEvent, OS.kEventParamMouseLocation, OS.typeQDPoint, null, sizeof, null, pt);
- if (!contains (pt.h, pt.v)) return OS.eventNotHandledErr;
- }
- return super.kEventControlSetCursor (nextHandler, theEvent, userData);
-}
-
-int kEventUnicodeKeyPressed (int nextHandler, int theEvent, int userData) {
- int result = super.kEventUnicodeKeyPressed (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- int [] keyboardEvent = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendKeyboardEvent, OS.typeEventRef, null, keyboardEvent.length * 4, null, keyboardEvent);
- int [] keyCode = new int [1];
- OS.GetEventParameter (keyboardEvent [0], OS.kEventParamKeyCode, OS.typeUInt32, null, keyCode.length * 4, null, keyCode);
- switch (keyCode [0]) {
- case 76: /* KP Enter */
- case 36: { /* Return */
- postEvent (SWT.DefaultSelection);
- break;
- }
- /*
- * Feature in the Macintosh. For some reason, when the user hits an
- * up or down arrow to traverse the items in a Data Browser, the item
- * scrolls to the left such that the white space that is normally
- * visible to the right of the every item is scrolled out of view.
- * The fix is to save and restore the horizontal scroll position.
- */
- case 125: /* Down */
- case 126: /* Up*/
- int [] top = new int [1], left = new int [1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- result = OS.CallNextEventHandler (nextHandler, theEvent);
- OS.GetDataBrowserScrollPosition (handle, top, null);
- OS.SetDataBrowserScrollPosition (handle, top [0], left [0]);
- }
- return result;
-}
-
-int itemNotificationProc (int browser, int id, int message) {
- switch (message) {
- case OS.kDataBrowserItemSelected:
- case OS.kDataBrowserItemDeselected: {
- if (ignoreSelect) break;
- int [] first = new int [1], last = new int [1];
- OS.GetDataBrowserSelectionAnchor (handle, first, last);
- boolean selected = false;
- if ((style & SWT.MULTI) != 0) {
- int modifiers = OS.GetCurrentEventKeyModifiers ();
- if ((modifiers & OS.shiftKey) != 0) {
- if (message == OS.kDataBrowserItemSelected) {
- selected = first [0] == id || last [0] == id;
- } else {
- selected = id == anchorFirst || id == anchorLast;
- }
- } else {
- if ((modifiers & OS.cmdKey) != 0) {
- selected = true;
- } else {
- selected = first [0] == last [0];
- }
- }
- } else {
- selected = message == OS.kDataBrowserItemSelected;
- }
- if (selected) {
- anchorFirst = first [0];
- anchorLast = last [0];
- postEvent (SWT.Selection);
- }
- break;
- }
- case OS.kDataBrowserItemDoubleClicked: {
- if (display.clickCount == 2) {
- postEvent (SWT.DefaultSelection);
- }
- break;
- }
- }
- return OS.noErr;
-}
-
-/**
- * Gets the index of an item.
- * <p>
- * The list is searched starting at 0 until an
- * item is found that is equal to the search item.
- * If no item is found, -1 is returned. Indexing
- * is zero based.
- *
- * @param string the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<itemCount; i++) {
- if (items [i].equals (item)) return i;
- }
- return -1;
-}
-
-/**
- * Searches the receiver's list starting at the given,
- * zero-relative index until an item is found that is equal
- * to the argument, and returns the index of that item. If
- * no item is found or the starting index is out of range,
- * returns -1.
- *
- * @param string the search item
- * @param start the zero-relative index at which to start the search
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string, int start) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=start; i<itemCount; i++) {
- if (items [i].equals (string)) return i;
- }
- return -1;
-}
-
-/**
- * Returns <code>true</code> if the item is selected,
- * and <code>false</code> otherwise. Indices out of
- * range are ignored.
- *
- * @param index the index of the item
- * @return the selection state of the item at the index
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isSelected (int index) {
- checkWidget();
- if (!(0 <= index && index < itemCount)) return false;
- return OS.IsDataBrowserItemSelected (handle, index + 1);
-}
-
-/**
- * Removes the item from the receiver at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (index != itemCount - 1) fixSelection (index, false);
- int [] id = new int [] {itemCount};
- if (OS.RemoveDataBrowserItems (handle, OS.kDataBrowserNoItem, id.length, id, 0) != OS.noErr) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- OS.UpdateDataBrowserItems (handle, 0, 0, null, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem);
-}
-
-/**
- * Removes the items from the receiver which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget();
- if (start > end) return;
- if (!(0 <= start && start <= end && end < itemCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int length = end - start + 1;
- int [] indices = new int [length];
- for (int i=0; i<length; i++) indices [i] = i + start;
- remove(indices);
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * until an item is found that is equal to the argument,
- * and removes that item from the list.
- *
- * @param string the item to remove
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = indexOf (string, 0);
- if (index == -1) error (SWT.ERROR_INVALID_ARGUMENT);
- remove (index);
-}
-
-/**
- * Removes the items from the receiver at the given
- * zero-relative indices.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- int [] newIndices = new int [indices.length];
- System.arraycopy (indices, 0, newIndices, 0, indices.length);
- sort (newIndices);
- int start = newIndices [newIndices.length - 1], end = newIndices [0];
- int count = getItemCount ();
- if (!(0 <= start && start <= end && end < count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int duplicates = 0;
- int last = -1;
- for (int i = 0; i < newIndices.length; i++) {
- if (newIndices [i] == last) duplicates++;
- last = newIndices [i];
- }
- int [] id = new int [newIndices.length - duplicates];
- int idIndex = id.length - 1;
- last = -1;
- for (int i = 0; i < newIndices.length; i++) {
- int index = newIndices [i];
- if (index != last) {
- if (index != itemCount - 1) fixSelection (index, false);
- id [idIndex--] = itemCount;
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- last = index;
- }
- }
- if (OS.RemoveDataBrowserItems (handle, OS.kDataBrowserNoItem, id.length, id, 0) != OS.noErr) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- OS.UpdateDataBrowserItems (handle, 0, 0, null, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem);
-}
-
-/**
- * Removes all of the items from the receiver.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget();
- OS.RemoveDataBrowserItems (handle, OS.kDataBrowserNoItem, 0, null, 0);
- OS.SetDataBrowserScrollPosition (handle, 0, 0);
- items = new String [4];
- itemCount = anchorFirst = anchorLast = 0;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget();
- if (0 <= index && index < itemCount) {
- int [] ids = new int [] {index + 1};
- select (ids, ids.length, false);
- }
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If an item in the given range is not selected, it is selected.
- * If an item in the given range was already selected, it remains selected.
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#setSelection(int,int)
- */
-public void select (int start, int end) {
- checkWidget ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- if (itemCount == 0 || start >= itemCount) return;
- start = Math.max (0, start);
- end = Math.min (end, itemCount - 1);
- int length = end - start + 1;
- int [] ids = new int [length];
- for (int i=0; i<length; i++) ids [i] = end - i + 1;
- select (ids, length, false);
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If the item at a given index is not selected, it is selected.
- * If the item at a given index was already selected, it remains selected.
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- *
- * @param indices the array of indices for the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#setSelection(int[])
- */
-public void select (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- int [] ids = new int [length];
- int count = 0;
- for (int i=0; i<length; i++) {
- int index = indices [length - i - 1];
- if (index >= 0 && index < itemCount) {
- ids [count++] = index + 1;
- }
- }
- if (count > 0) select (ids, count, false);
-}
-
-void select (int [] ids, int count, boolean clear) {
- ignoreSelect = true;
- /*
- * Bug in the Macintosh. When the DataBroswer selection flags includes
- * both kDataBrowserNeverEmptySelectionSet and kDataBrowserSelectOnlyOne,
- * two items are selected when SetDataBrowserSelectedItems() is called
- * with kDataBrowserItemsAssign to assign a new seletion despite the fact
- * that kDataBrowserSelectOnlyOne was specified. The fix is to save and
- * restore kDataBrowserNeverEmptySelectionSet around each call to
- * SetDataBrowserSelectedItems().
- */
- int [] selectionFlags = null;
- if ((style & SWT.SINGLE) != 0) {
- selectionFlags = new int [1];
- OS.GetDataBrowserSelectionFlags (handle, selectionFlags);
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0] & ~OS.kDataBrowserNeverEmptySelectionSet);
- }
- int operation = OS.kDataBrowserItemsAssign;
- if ((style & SWT.MULTI) != 0 && !clear) operation = OS.kDataBrowserItemsAdd;
- OS.SetDataBrowserSelectedItems (handle, count, ids, operation);
- if ((style & SWT.SINGLE) != 0) {
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0]);
- }
- ignoreSelect = false;
-}
-
-void select (String [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- //NOT DONE - range check
- int length = items.length;
- int [] ids = new int [length];
- for (int i=0; i<length; i++) ids [i] = indexOf (items [length - i - 1]) + 1;
- select (ids, length, false);
-}
-
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- select (null, 0, false);
-}
-
-void setBackground (float [] color) {
- /*
- * Bug in the Macintosh. The default background of a window changes when
- * the background of a data browser is set using SetControlFontStyle(). This
- * also affects the background of any TNXObject created on that window. The
- * fix is to avoid calling SetControlFontStyle() which has no effect
- * in a data browser anyways.
- */
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- /*
- * Ensure that the top item is visible when the tree is resized
- * from a zero size to a size that can show the selection.
- */
- //TODO - optimize
- int index = -1;
- if (resize) {
- Rectangle rect = getClientArea ();
- if (rect.height < getItemHeight ()) index = getTopIndex ();
- }
- int result = super.setBounds (x, y, width, height, move, resize, events);
- if (index != -1) showIndex (index);
- return result;
-}
-
-/**
- * Sets the text of the item in the receiver's list at the given
- * zero-relative index to the string argument.
- *
- * @param index the index for the item
- * @param string the new text for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItem (int index, String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- int [] id = new int [] {index + 1};
- items [index] = string;
- OS.UpdateDataBrowserItems (handle, OS.kDataBrowserNoItem, id.length, id, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem);
-}
-
-/**
- * Sets the receiver's items to be the given array of items.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItems (String [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<items.length; i++) {
- if (items [i] == null) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- OS.RemoveDataBrowserItems (handle, OS.kDataBrowserNoItem, 0, null, 0);
- if (OS.AddDataBrowserItems(handle, OS.kDataBrowserNoItem, items.length, null, OS.kDataBrowserItemNoProperty) != OS.noErr) {
- error (SWT.ERROR_ITEM_NOT_ADDED);
- }
- this.items = new String [items.length];
- System.arraycopy (items, 0, this.items, 0, items.length);
- itemCount = items.length;
-}
-
-boolean setScrollBarVisible (ScrollBar bar, boolean visible) {
- boolean [] horiz = new boolean [1], vert = new boolean [1];
- OS.GetDataBrowserHasScrollBars (handle, horiz, vert);
- if ((bar.style & SWT.H_SCROLL) != 0) horiz [0] = visible;
- if ((bar.style & SWT.V_SCROLL) != 0) vert [0] = visible;
- if (!visible) {
- bar.redraw ();
- bar.deregister ();
- }
- if (OS.SetDataBrowserHasScrollBars (handle, horiz [0], vert [0]) == OS.noErr) {
- if (visible) {
- bar.handle = findStandardBar (bar.style);
- bar.register ();
- bar.hookEvents ();
- bar.redraw ();
- } else {
- bar.handle = 0;
- }
- return true;
- } else {
- if (!visible) {
- bar.register ();
- }
- }
- return false;
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains selected.
- * The current selection is first cleared, then the new item is selected.
- * Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @see List#deselectAll()
- * @see List#select(int)
- */
-public void setSelection (int index) {
- checkWidget();
- deselectAll ();
- setSelection (index, false);
-}
-
-void setSelection (int index, boolean notify) {
-// checkWidget();
- if (0 <= index && index < itemCount) {
- int [] ids = new int [] {index + 1};
- select (ids, ids.length, true);
- showIndex (index);
- if (notify) postEvent (SWT.Selection);
- }
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- *
- * @param start the start index of the items to select
- * @param end the end index of the items to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int,int)
- */
-public void setSelection (int start, int end) {
- checkWidget ();
- deselectAll ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- if (itemCount == 0 || start >= itemCount) return;
- start = Math.max (0, start);
- end = Math.min (end, itemCount - 1);
- int length = end - start + 1;
- int [] ids = new int [length];
- for (int i=0; i<length; i++) ids [i] = end - i + 1;
- select (ids, length, true);
- if (ids.length > 0) showIndex (ids [0] - 1);
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- *
- * @param indices the indices of the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int[])
- */
-public void setSelection (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- int [] ids = new int [length];
- int count = 0;
- for (int i=0; i<length; i++) {
- int index = indices [length - i - 1];
- if (index >= 0 && index < itemCount) {
- ids [count++] = index + 1;
- }
- }
- if (count > 0) {
- select (ids, count, true);
- showIndex (ids [0] - 1);
- }
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int[])
- * @see List#setSelection(int[])
- */
-public void setSelection (String [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = items.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- int count = 0;
- int [] ids = new int [length];
- for (int i=0; i<length; i++) {
- String string = items [length - i - 1];
- if ((style & SWT.SINGLE) != 0) {
- int index = indexOf (string, 0);
- if (index != -1) {
- count = 1;
- ids = new int [] {index + 1};
- }
- } else {
- int index = 0;
- while ((index = indexOf (string, index)) != -1) {
- if (count == ids.length) {
- int [] newIds = new int [ids.length + 4];
- System.arraycopy (ids, 0, newIds, 0, ids.length);
- ids = newIds;
- }
- ids [count++] = index + 1;
- index++;
- }
- }
- }
- if (count > 0) {
- select (ids, count, true);
- showIndex (ids [0] - 1);
- }
-}
-
-/**
- * Sets the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items
- * are scrolled or new items are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget();
- int itemHeight = getItemHeight ();
- int [] top = new int [1], left = new int [1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- top [0] = Math.max (0, Math.min (itemHeight * itemCount - getClientArea ().height, index * itemHeight));
- OS.SetDataBrowserScrollPosition (handle, top [0], left [0]);
-}
-
-void showIndex (int index) {
- if (0 <= index && index < itemCount) {
- short [] width = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (handle, COLUMN_ID, width);
- Rect rect = new Rect (), inset = new Rect ();
- OS.GetControlBounds (handle, rect);
- OS.GetDataBrowserScrollBarInset (handle, inset);
- OS.SetDataBrowserTableViewNamedColumnWidth (handle, COLUMN_ID, (short)(rect.right - rect.left - inset.left - inset.right));
- OS.RevealDataBrowserItem (handle, index + 1, COLUMN_ID, (byte) (OS.kDataBrowserRevealWithoutSelecting | OS.kDataBrowserRevealAndCenterInView));
- OS.SetDataBrowserTableViewNamedColumnWidth (handle, COLUMN_ID, width [0]);
- }
-}
-
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void showSelection () {
- checkWidget();
- int index = getSelectionIndex ();
- if (index >= 0) showIndex (index);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Menu.java
deleted file mode 100644
index 13a2f739e1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Menu.java
+++ /dev/null
@@ -1,1173 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.ATSFontMetrics;
-import org.eclipse.swt.internal.carbon.GDevice;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.MenuTrackingData;
-import org.eclipse.swt.internal.carbon.Rect;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are user interface objects that contain
- * menu items.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BAR, DROP_DOWN, POP_UP, NO_RADIO_GROUP</dd>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Help, Hide, Show </dd>
- * </dl>
- * <p>
- * Note: Only one of BAR, DROP_DOWN and POP_UP may be specified.
- * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#menu">Menu snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Menu extends Widget {
- /**
- * the handle to the OS resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- int handle;
- short id;
- int x, y, itemCount;
-// int width, height;
- boolean hasLocation, modified, closed, ignoreMatch;
- MenuItem [] items;
- MenuItem cascade, defaultItem, lastTarget;
- Decorations parent;
-
-/**
- * Constructs a new instance of this class given its parent,
- * and sets the style for the instance so that the instance
- * will be a popup menu on the given parent's shell.
- * <p>
- * After constructing a menu, it can be set into its parent
- * using <code>parent.setMenu(menu)</code>. In this case, the parent may
- * be any control in the same widget tree as the parent.
- * </p>
- *
- * @param parent a control which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#POP_UP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Control parent) {
- this (checkNull (parent).menuShell (), SWT.POP_UP);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Decorations</code>) and a style value
- * describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * After constructing a menu or menuBar, it can be set into its parent
- * using <code>parent.setMenu(menu)</code> or <code>parent.setMenuBar(menuBar)</code>.
- * </p>
- *
- * @param parent a decorations control which will be the parent of the new instance (cannot be null)
- * @param style the style of menu to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BAR
- * @see SWT#DROP_DOWN
- * @see SWT#POP_UP
- * @see SWT#NO_RADIO_GROUP
- * @see SWT#LEFT_TO_RIGHT
- * @see SWT#RIGHT_TO_LEFT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Decorations parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget ();
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>) and sets the style
- * for the instance so that the instance will be a drop-down
- * menu on the given parent's parent.
- * <p>
- * After constructing a drop-down menu, it can be set into its parentMenu
- * using <code>parentMenu.setMenu(menu)</code>.
- * </p>
- *
- * @param parentMenu a menu which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Menu parentMenu) {
- this (checkNull (parentMenu).parent, SWT.DROP_DOWN);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>MenuItem</code>) and sets the style
- * for the instance so that the instance will be a drop-down
- * menu on the given parent's parent menu.
- * <p>
- * After constructing a drop-down menu, it can be set into its parentItem
- * using <code>parentItem.setMenu(menu)</code>.
- * </p>
- *
- * @param parentItem a menu item which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (MenuItem parentItem) {
- this (checkNull (parentItem).parent);
-}
-
-static Control checkNull (Control control) {
- if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return control;
-}
-
-static Menu checkNull (Menu menu) {
- if (menu == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return menu;
-}
-
-static MenuItem checkNull (MenuItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0);
-}
-
-void _setVisible (boolean visible) {
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- if (visible) {
- org.eclipse.swt.internal.carbon.Point where = new org.eclipse.swt.internal.carbon.Point ();
- if (hasLocation) {
- where.h = (short) x;
- where.v = (short) y;
- } else {
- OS.GetGlobalMouse (where);
- }
- /*
- * Bug in the Macintosh. When a menu is open with ContextualMenuSelect() the
- * system will add other items before displaying it and remove the items before
- * returning from the function. If the menu is changed in kEventMenuOpening, the
- * system will fail to remove those items. The fix is to send SWT.Show before
- * calling ContextualMenuSelect() instead of in kEventMenuOpening.
- */
- sendEvent (SWT.Show);
- modified = false;
- /*
- * Feature in the Macintosh. When the application FruitMenu is installed,
- * the output parameters cannot be NULL or ContextualMenuSelect() crashes.
- * The fix is to ensure they are not NULL.
- */
- OS.ContextualMenuSelect (handle, where, false, OS.kCMHelpItemRemoveHelp, null, null, new int [1], new short [1], new short [1]);
- } else {
- OS.CancelMenuTracking (handle, true, 0);
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when help events are generated for the control,
- * by sending it one of the messages defined in the
- * <code>HelpListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when menus are hidden or shown, by sending it
- * one of the messages defined in the <code>MenuListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuListener
- * @see #removeMenuListener
- */
-public void addMenuListener (MenuListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Hide,typedListener);
- addListener (SWT.Show,typedListener);
-}
-
-void createHandle () {
- display.addMenu (this);
- int outMenuRef [] = new int [1];
- OS.CreateNewMenu (id, 0, outMenuRef);
- if (outMenuRef [0] == 0) {
- display.removeMenu (this);
- error (SWT.ERROR_NO_HANDLES);
- }
- handle = outMenuRef [0];
-}
-
-void createItem (MenuItem item, int index) {
- checkWidget ();
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- int attributes = OS.kMenuItemAttrAutoRepeat | OS.kMenuItemAttrCustomDraw;
- if ((item.style & SWT.SEPARATOR) != 0) attributes = OS.kMenuItemAttrSeparator;
- int result = OS.InsertMenuItemTextWithCFString (handle, 0, (short) index, attributes, 0);
- if (result != OS.noErr) {
- error (SWT.ERROR_ITEM_NOT_ADDED);
- }
- if (itemCount == items.length) {
- MenuItem [] newItems = new MenuItem [items.length + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- System.arraycopy (items, index, items, index + 1, itemCount++ - index);
- items [index] = item;
- modified = true;
- int emptyMenu = item.createEmptyMenu ();
- if (emptyMenu != 0) {
- OS.SetMenuItemHierarchicalMenu (handle, (short) (index + 1), emptyMenu);
- OS.ReleaseMenu (emptyMenu);
- }
-}
-
-void createWidget () {
- checkOrientation (parent);
- super.createWidget ();
- items = new MenuItem [4];
-}
-
-void destroyItem (MenuItem item) {
- int index = 0;
- while (index < itemCount) {
- if (items [index] == item) break;
- index++;
- }
- if (index == itemCount) return;
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- if (itemCount == 0) items = new MenuItem [4];
- modified = true;
- OS.DeleteMenuItem (handle, (short) (index + 1));
-}
-
-void destroyWidget () {
- int theMenu = handle;
- releaseHandle ();
- if (theMenu != 0) {
- OS.DisposeMenu (theMenu);
- }
-}
-
-void fixMenus (Decorations newParent) {
- this.parent = newParent;
-}
-
-/*public*/ Rectangle getBounds () {
- checkWidget ();
- if ((style & SWT.BAR) != 0) {
- Menu menu = display.getMenuBar ();
- if (this != menu) return new Rectangle (0, 0, 0, 0);
- int height = OS.GetMBarHeight ();
- int gdevice = OS.GetMainDevice ();
- int [] ptr = new int [1];
- OS.memmove (ptr, gdevice, 4);
- GDevice device = new GDevice ();
- OS.memmove (device, ptr [0], GDevice.sizeof);
- return new Rectangle (0, 0, device.right - device.left, height);
- }
- OS.CalcMenuSize (handle);
- return new Rectangle (x, y, 0, 0);
-// return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the default menu item or null if none has
- * been previously set.
- *
- * @return the default menu item.
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getDefaultItem () {
- checkWidget();
- return defaultItem;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled menu is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- return (state & DISABLED) == 0;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getItem (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return itemCount;
-}
-
-/**
- * Returns a (possibly empty) array of <code>MenuItem</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem [] getItems () {
- checkWidget ();
- MenuItem [] result = new MenuItem [itemCount];
- int index = 0;
- if (items != null) {
- for (int i = 0; i < itemCount; i++) {
- MenuItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- result [index++] = item;
- }
- }
- }
- if (index != result.length) {
- MenuItem [] newItems = new MenuItem[index];
- System.arraycopy(result, 0, newItems, 0, index);
- result = newItems;
- }
- return result;
-}
-
-String getNameText () {
- String result = "";
- MenuItem [] items = getItems ();
- int length = items.length;
- if (length > 0) {
- for (int i=0; i<length-1; i++) {
- result = result + items [i].getNameText() + ", ";
- }
- result = result + items [length-1].getNameText ();
- }
- return result;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Decorations</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Decorations getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>MenuItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getParentItem () {
- checkWidget ();
- return cascade;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>Menu</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getParentMenu () {
- checkWidget ();
- if (cascade != null) return cascade.parent;
- return null;
-}
-
-/**
- * Returns the receiver's shell. For all controls other than
- * shells, this simply returns the control's nearest ancestor
- * shell. Shells return themselves, even if they are children
- * of other shells.
- *
- * @return the receiver's shell
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getParent
- */
-public Shell getShell () {
- checkWidget ();
- return parent.getShell ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- if ((style & SWT.BAR) != 0) {
- return this == parent.menuShell ().menuBar;
- }
- if ((style & SWT.POP_UP) != 0) {
- Menu [] popups = display.popups;
- if (popups == null) return false;
- for (int i=0; i<popups.length; i++) {
- if (popups [i] == this) return true;
- }
- }
- MenuTrackingData outData = new MenuTrackingData ();
- return OS.GetMenuTrackingData (handle, outData) == OS.noErr;
-}
-
-void hookEvents () {
- super.hookEvents ();
- int menuProc = display.menuProc;
- int [] mask = new int [] {
- OS.kEventClassMenu, OS.kEventMenuCalculateSize,
- OS.kEventClassMenu, OS.kEventMenuClosed,
- OS.kEventClassMenu, OS.kEventMenuCreateFrameView,
- OS.kEventClassMenu, OS.kEventMenuDrawItem,
- OS.kEventClassMenu, OS.kEventMenuDrawItemContent,
- OS.kEventClassMenu, OS.kEventMenuMeasureItemWidth,
- OS.kEventClassMenu, OS.kEventMenuOpening,
- OS.kEventClassMenu, OS.kEventMenuTargetItem,
- OS.kEventClassMenu, OS.kEventMenuMatchKey,
- };
- int menuTarget = OS.GetMenuEventTarget (handle);
- OS.InstallEventHandler (menuTarget, menuProc, mask.length / 2, mask, handle, null);
-}
-
-int kEventMenuCalculateSize (int nextHandler, int theEvent, int userData) {
- int result = super.kEventMenuCalculateSize (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- int [] theControl = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamControlRef, OS.typeControlRef, null, 4, null, theControl);
- int menuProc = display.menuProc;
- int [] mask = new int [] {
- OS.kEventClassMenu, OS.kEventMenuGetFrameBounds,
- };
- int controlTarget = OS.GetControlEventTarget (theControl [0]);
- //TODO - installed multi-times, does this matter?
- OS.InstallEventHandler (controlTarget, menuProc, mask.length / 2, mask, handle, null);
- return result;
-}
-
-int kEventMenuClosed (int nextHandler, int theEvent, int userData) {
- int result = super.kEventMenuClosed (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- closed = true;
-// width = height = 0;
-// int count = OS.CountMenuItems (handle);
-// for (int i=0; i<count; i++) {
-// MenuItem item = items [i];
-// item.x = item.y = item.width = item.height = 0;
-// }
- /*
- * Feature in the Macintosh. In order to populate the search field of
- * the help menu, the events kEventMenuOpening, kEventMenuClosed and
- * others are sent to sub menus even when the cascade item of the submenu
- * is disabled. Normally, the user can never get to these submenus.
- * This means that application code does not expect SWT.Show and SWT.Hide
- * events. The fix is to avoid the events when the cascade item is
- * disabled.
- */
- boolean send = true;
- if (cascade != null && !cascade.getEnabled ()) send = false;
- if (send) sendEvent (SWT.Hide);
- return OS.eventNotHandledErr;
-}
-
-int kEventMenuCreateFrameView (int nextHandler, int theEvent, int userData) {
- int result = super.kEventMenuCreateFrameView (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- int [] theControl = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamControlRef, OS.typeControlRef, null, 4, null, theControl);
- int menuProc = display.menuProc;
- int [] mask = new int [] {
- OS.kEventClassMenu, OS.kEventMenuGetFrameBounds,
- };
- int controlTarget = OS.GetControlEventTarget (theControl [0]);
- OS.InstallEventHandler (controlTarget, menuProc, mask.length / 2, mask, handle, null);
- return OS.eventNotHandledErr;
-}
-
-int kEventMenuDrawItem (int nextHandler, int theEvent, int userData) {
- int result = super.kEventMenuDrawItem (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
-// short [] index = new short [1];
-// OS.GetEventParameter (theEvent, OS.kEventParamMenuItemIndex, OS.typeMenuItemIndex, null, 2, null, index);
-// MenuItem item = items [index [0] - 1];
-// Rect rect = new Rect ();
-// OS.GetEventParameter (theEvent, OS.kEventParamMenuItemBounds, OS.typeQDRectangle, null, Rect.sizeof, null, rect);
-// item.x = rect.left - x;
-// item.y = rect.top - y;
-// item.width = rect.right - rect.left;
-// item.height = rect.bottom - rect.top;
- return OS.eventNotHandledErr;
-}
-
-int kEventMenuDrawItemContent (int nextHandler, int theEvent, int userData) {
- int result = super.kEventMenuDrawItemContent (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- short [] index = new short [1];
- OS.GetEventParameter (theEvent, OS.kEventParamMenuItemIndex, OS.typeMenuItemIndex, null, 2, null, index);
- if (!(0 < index [0] && index [0] <= itemCount)) return result;
- MenuItem item = items [index [0] - 1];
- if (item.accelerator == 0 && !item.acceleratorSet) {
- int accelIndex = item.text.indexOf ('\t');
- if (accelIndex != -1) {
- String accelText = item.text.substring (accelIndex + 1);
- int length = accelText.length ();
- if (length != 0) {
- result = OS.CallNextEventHandler (nextHandler, theEvent);
- Rect rect = new Rect ();
- OS.GetEventParameter (theEvent, OS.kEventParamMenuItemBounds, OS.typeQDRectangle, null, Rect.sizeof, null, rect);
- int [] context = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamCGContextRef, OS.typeCGContextRef, null, 4, null, context);
-
- /* Draw the key */
- int modifierIndex = modifierIndex (accelText);
- char [] buffer = new char [length - modifierIndex - 1];
- accelText.getChars (modifierIndex + 1, length, buffer, 0);
- int themeFont = OS.kThemeMenuItemFont;
- if (buffer.length > 1) themeFont = OS.kThemeMenuItemCmdKeyFont;
- byte [] family = new byte [256];
- short [] size = new short [1];
- byte [] style = new byte [1];
- OS.GetThemeFont ((short) themeFont, (short) OS.smSystemScript, family, size, style);
- short id = OS.FMGetFontFamilyFromName (family);
- int [] font = new int [1];
- OS.FMGetFontFromFontFamilyInstance (id, style [0], font, null);
- int atsFont = OS.FMGetATSFontRefFromFont (font [0]);
- ATSFontMetrics fontMetrics = new ATSFontMetrics ();
- OS.ATSFontGetVerticalMetrics (atsFont, OS.kATSOptionFlagsDefault, fontMetrics);
- OS.ATSFontGetHorizontalMetrics (atsFont, OS.kATSOptionFlagsDefault, fontMetrics);
- int [] metric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricMenuIconTrailingEdgeMargin, metric);
- int str = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- org.eclipse.swt.internal.carbon.Point size1 = new org.eclipse.swt.internal.carbon.Point ();
- OS.GetThemeTextDimensions (str, (short) themeFont, 0, false, size1, null);
- rect.left = (short) (rect.right - Math.max ((int)(fontMetrics.maxAdvanceWidth * size[0]), size1.h) - metric [0]);
- OS.DrawThemeTextBox (str, (short) themeFont, OS.kThemeStateActive, false, rect, (short) OS.teFlushLeft, context [0]);
- OS.CFRelease (str);
-
- /* Draw the modifiers */
- if (modifierIndex != -1) {
- buffer = new char [modifierIndex + 1];
- accelText.getChars (0, buffer.length, buffer, 0);
- str = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- OS.GetThemeTextDimensions (str, (short) OS.kThemeMenuItemCmdKeyFont, 0, false, size1, null);
- rect.right = rect.left;
- rect.left = (short) (rect.right - size1.h);
- OS.DrawThemeTextBox (str, (short) OS.kThemeMenuItemCmdKeyFont, OS.kThemeStateActive, false, rect, (short) OS.teFlushLeft, context [0]);
- OS.CFRelease (str);
- }
- return result;
- }
- }
- }
- return OS.eventNotHandledErr;
-}
-
-int kEventMenuGetFrameBounds (int nextHandler, int theEvent, int userData) {
- int result = super.kEventMenuGetFrameBounds (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- result = OS.CallNextEventHandler (nextHandler, theEvent);
-// CGRect rect = new CGRect ();
-// OS.GetEventParameter (theEvent, OS.kEventParamBounds, OS.typeHIRect, null, CGRect.sizeof, null, rect);
-// x = (int) rect.x;
-// y = (int) rect.y;
-// width = (int) rect.width;
-// height = (int) rect.height;
-// if (cascade != null) {
-// OS.GetEventParameter (theEvent, OS.kEventParamMenuItemBounds, OS.typeHIRect, null, CGRect.sizeof, null, rect);
-// cascade.x = (int) rect.x - x;
-// cascade.y = (int) rect.y - y;
-// cascade.width = (int) rect.width;
-// cascade.height = (int) rect.height;
-// }
- return result;
-}
-
-int kEventMenuMatchKey (int nextHandler, int theEvent, int userData) {
- if (ignoreMatch) return OS.eventNotHandledErr;
- int [] menuIndex = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamDirectObject, OS.typeMenuRef, null, 4, null, menuIndex);
- int [] eventRef = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamEventRef, OS.typeEventRef, null, 4, null, eventRef);
- int options = OS.kMenuEventDontCheckSubmenus | OS.kMenuEventIncludeDisabledItems | OS.kMenuEventQueryOnly;
- short [] index = new short [1];
- ignoreMatch = true;
- boolean isMenuKeyEvent = OS.IsMenuKeyEvent(menuIndex[0], eventRef[0], options, null, index);
- ignoreMatch = false;
- if (isMenuKeyEvent && 0 <= index [0] && index [0] < items.length) {
- MenuItem item = items [index [0] - 1];
- if (item.accelerator == 0) {
- /* Tell Menu Manager we don't want command key matching */
- return OS.menuItemNotFoundError;
- }
- }
- /* Tell Menu Manager to use default command key matching algorithm */
- return OS.eventNotHandledErr;
-}
-
-int kEventMenuMeasureItemWidth (int nextHandler, int theEvent, int userData) {
- int result = super.kEventMenuMeasureItemWidth (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- short [] index = new short [1];
- OS.GetEventParameter (theEvent, OS.kEventParamMenuItemIndex, OS.typeMenuItemIndex, null, 2, null, index);
- if (!(0 < index [0] && index [0] <= itemCount)) return result;
- MenuItem item = items [index [0] - 1];
- if (item.accelerator == 0 && !item.acceleratorSet) {
- int accelIndex = item.text.indexOf ('\t');
- if (accelIndex != -1) {
- String accelText = item.text.substring (accelIndex + 1);
- if (accelText.length () != 0) {
- result = OS.CallNextEventHandler (nextHandler, theEvent);
- char [] buffer = new char [accelText.length ()];
- accelText.getChars (0, buffer.length, buffer, 0);
- int str = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- org.eclipse.swt.internal.carbon.Point size = new org.eclipse.swt.internal.carbon.Point ();
- OS.GetThemeTextDimensions (str, (short) OS.kThemeMenuItemCmdKeyFont, 0, false, size, null);
- OS.CFRelease (str);
- short [] width = new short [1];
- OS.GetEventParameter (theEvent, OS.kEventParamMenuItemWidth, OS.typeSInt16, null, 2, null, width);
- int [] metric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricMenuTextTrailingEdgeMargin, metric);
- width [0] += metric [0] + size.h;
- OS.SetEventParameter (theEvent, OS.kEventParamMenuItemWidth, OS.typeSInt16, 2, width);
- return result;
- }
- }
- }
- return OS.eventNotHandledErr;
-}
-
-int kEventMenuOpening (int nextHandler, int theEvent, int userData) {
- int result = super.kEventMenuOpening (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- closed = false;
- /*
- * Bug in the Macintosh. When a menu is open with ContextualMenuSelect() the
- * system will add other items before displaying it and remove the items before
- * returning from the function. If the menu is changed in kEventMenuOpening, the
- * system will fail to remove those items. The fix is to send SWT.Show before
- * calling ContextualMenuSelect() instead of in kEventMenuOpening.
- */
- if ((style & SWT.POP_UP) == 0) {
- /*
- * Feature in the Macintosh. In order to populate the search field of
- * the help menu, the events kEventMenuOpening, kEventMenuClosed and
- * others are sent to sub menus even when the cascade item of the submenu
- * is disabled. Normally, the user can never get to these submenus.
- * This means that application code does not expect SWT.Show and SWT.Hide
- * events. The fix is to avoid the events when the cascade item is
- * disabled.
- */
- boolean send = true;
- if (cascade != null && !cascade.getEnabled ()) send = false;
- if (send) {
- sendEvent (SWT.Show);
- modified = false;
- }
- }
- return OS.eventNotHandledErr;
-}
-
-int kEventMenuTargetItem (int nextHandler, int theEvent, int userData) {
- int result = super.kEventMenuTargetItem (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- lastTarget = null;
- short [] index = new short [1];
- if (OS.GetEventParameter (theEvent, OS.kEventParamMenuItemIndex, OS.typeMenuItemIndex, null, 2, null, index) == OS.noErr) {
- if (0 < index [0] && index [0] <= itemCount) lastTarget = items [index [0] - 1];
- if (lastTarget != null) {
- lastTarget.sendEvent (SWT.Arm);
- }
- }
- return OS.eventNotHandledErr;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (MenuItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<itemCount; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled menu is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget ();
- Menu parentMenu = getParentMenu ();
- if (parentMenu == null) {
- return getEnabled () && parent.isEnabled ();
- }
- return getEnabled () && parentMenu.isEnabled ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget ();
- return getVisible ();
-}
-
-int modifierIndex (String accelText) {
- int start = accelText.length () - 1;
- int index = start;
- while (index >= 0) {
- char c = accelText.charAt (index);
- switch (c) {
- case ' ':
- if (index != start) return index;
- break;
- case '\u2303':
- case '\u2325':
- case '\u21E7':
- case '\u2318':
- return index;
- }
- index--;
- }
- return -1;
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- handle = 0;
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (cascade != null) cascade.setMenu (null);
- if ((style & SWT.BAR) != 0 && this == parent.menuBar) {
- parent.setMenuBar (null);
- }
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- display.removeMenu (this);
- parent = null;
- cascade = defaultItem = lastTarget = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the menu events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuListener
- * @see #addMenuListener
- */
-public void removeMenuListener (MenuListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Hide, listener);
- eventTable.unhook (SWT.Show, listener);
-}
-
-/**
- * Sets the default menu item to the argument or removes
- * the default emphasis when the argument is <code>null</code>.
- *
- * @param item the default menu item or null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the menu item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDefaultItem (MenuItem item) {
- checkWidget();
- if (item != null && item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- defaultItem = item;
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled menu is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- if (enabled) {
- state &= ~DISABLED;
- OS.EnableMenuItem (handle, (short)0);
- } else {
- state |= DISABLED;
- OS.DisableMenuItem (handle, (short)0);
- }
-}
-
-/**
- * Sets the location of the receiver, which must be a popup,
- * to the point specified by the arguments which are relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p><p>
- * Note that the platform window manager ultimately has control
- * over the location of popup menus.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget ();
- this.x = x;
- this.y = y;
- hasLocation = true;
-}
-
-/**
- * Sets the location of the receiver, which must be a popup,
- * to the point specified by the argument which is relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p><p>
- * Note that the platform window manager ultimately has control
- * over the location of popup menus.
- * </p>
- *
- * @param location the new location for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void setLocation (Point location) {
- checkWidget ();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- if (visible) {
- display.addPopup (this);
- } else {
- display.removePopup (this);
- _setVisible (false);
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java
deleted file mode 100644
index 2c653b6414..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MenuItem.java
+++ /dev/null
@@ -1,976 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.internal.carbon.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that issues notification when pressed and released.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>CHECK, CASCADE, PUSH, RADIO, SEPARATOR</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Arm, Help, Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR
- * may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class MenuItem extends Item {
- Menu parent, menu;
- int accelerator;
- boolean acceleratorSet;
-// int x, y, width, height;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a menu control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#CHECK
- * @see SWT#CASCADE
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public MenuItem (Menu parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a menu control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#CHECK
- * @see SWT#CASCADE
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public MenuItem (Menu parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the arm events are generated for the control, by sending
- * it one of the messages defined in the <code>ArmListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ArmListener
- * @see #removeArmListener
- */
-public void addArmListener (ArmListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Arm, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the help events are generated for the control, by sending
- * it one of the messages defined in the <code>HelpListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the menu item is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the stateMask field of the event object is valid.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the menu item is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.CASCADE, 0);
-}
-
-int createEmptyMenu () {
- /*
- * Bug in the Macintosh. When a menu bar item does not have
- * an associated pull down menu, the Macintosh segment faults.
- * The fix is to temporarily attach an empty menu.
- */
- if ((parent.style & SWT.BAR) != 0) {
- int outMenuRef [] = new int [1];
- if (OS.CreateNewMenu ((short) 0, 0, outMenuRef) != OS.noErr) {
- error (SWT.ERROR_NO_HANDLES);
- }
- return outMenuRef [0];
- }
- return 0;
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns the widget accelerator. An accelerator is the bit-wise
- * OR of zero or more modifier masks and a key. Examples:
- * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
- * The default value is zero, indicating that the menu item does
- * not have an accelerator.
- *
- * @return the accelerator or 0
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAccelerator () {
- checkWidget ();
- return accelerator;
-}
-
-/*public*/ Rectangle getBounds () {
- checkWidget ();
- if ((parent.style & SWT.BAR) != 0) {
- int index = parent.indexOf (this);
- if (index == -1) return new Rectangle (0 ,0, 0, 0);
- Menu menu = display.getMenuBar ();
- if (parent != menu) return new Rectangle (0 ,0, 0, 0);
- int outMenuRef [] = new int [1];
- if (OS.GetMenuItemHierarchicalMenu (menu.handle, (short)(index + 1), outMenuRef) != OS.noErr) {
- return new Rectangle (0 ,0, 0, 0);
- }
- Rect rect = new Rect ();
- //TODO - get the bounds of the menu item from the menu title
-// if (... code needed to do this ... != OS.noErr) {
-// return new Rectangle (0 ,0, 0, 0);
-// }
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- return new Rectangle (rect.left, rect.top, width, height);
- }
- return new Rectangle (0 ,0, 0, 0);
-// return new Rectangle (x, y, width, height);
-
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled menu item is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- return (state & DISABLED) == 0;
-}
-
-/**
- * Returns the receiver's cascade menu if it has one or null
- * if it does not. Only <code>CASCADE</code> menu items can have
- * a pull down menu. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pull down
- * menu is platform specific.
- *
- * @return the receiver's menu
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenu () {
- checkWidget ();
- return menu;
-}
-
-String getNameText () {
- if ((style & SWT.SEPARATOR) != 0) return "|";
- return super.getNameText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Menu</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked.
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget ();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
- int index = parent.indexOf (this);
- if (index == -1) return false;
- short [] outMark = new short [1];
- OS.GetItemMark (parent.handle, (short) (index + 1), outMark);
- return outMark [0] != 0;
-}
-
-int kEventProcessCommand (int nextHandler, int theEvent, int userData) {
- //TEMPORARY CODE
- if (!isEnabled ()) return OS.noErr;
-
- if ((style & SWT.CHECK) != 0) {
- setSelection (!getSelection ());
- } else {
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) != 0) {
- setSelection (!getSelection ());
- } else {
- selectRadio ();
- }
- }
- }
- int [] modifiers = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
- Event event = new Event ();
- setInputState (event, (short) 0, OS.GetCurrentEventButtonState (), modifiers [0]);
- postEvent (SWT.Selection, event);
- return OS.noErr;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled menu item is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- return getEnabled () && parent.isEnabled ();
-}
-
-int keyGlyph (int key) {
- switch (key) {
- case SWT.BS: return OS.kMenuDeleteLeftGlyph;
- case SWT.CR: return OS.kMenuReturnGlyph;
- case SWT.DEL: return OS.kMenuDeleteRightGlyph;
- case SWT.ESC: return OS.kMenuEscapeGlyph;
- case SWT.LF: return OS.kMenuReturnGlyph;
- case SWT.TAB: return OS.kMenuTabRightGlyph;
- case ' ': return OS.kMenuBlankGlyph;
-// case ' ': return OS.kMenuSpaceGlyph;
- case SWT.ALT: return OS.kMenuOptionGlyph;
- case SWT.SHIFT: return OS.kMenuShiftGlyph;
- case SWT.CONTROL: return OS.kMenuControlISOGlyph;
- case SWT.COMMAND: return OS.kMenuCommandGlyph;
- case SWT.ARROW_UP: return OS.kMenuUpArrowGlyph;
- case SWT.ARROW_DOWN: return OS.kMenuDownArrowGlyph;
- case SWT.ARROW_LEFT: return OS.kMenuLeftArrowGlyph;
- case SWT.ARROW_RIGHT: return OS.kMenuRightArrowGlyph;
- case SWT.PAGE_UP: return OS.kMenuPageUpGlyph;
- case SWT.PAGE_DOWN: return OS.kMenuPageDownGlyph;
- case SWT.KEYPAD_CR: return OS.kMenuEnterGlyph;
- case SWT.HELP: return OS.kMenuHelpGlyph;
-// case SWT.CAPS_LOCK: return OS.kMenuCapsLockGlyph;
- case SWT.F1: return OS.kMenuF1Glyph;
- case SWT.F2: return OS.kMenuF2Glyph;
- case SWT.F3: return OS.kMenuF3Glyph;
- case SWT.F4: return OS.kMenuF4Glyph;
- case SWT.F5: return OS.kMenuF5Glyph;
- case SWT.F6: return OS.kMenuF6Glyph;
- case SWT.F7: return OS.kMenuF7Glyph;
- case SWT.F8: return OS.kMenuF8Glyph;
- case SWT.F9: return OS.kMenuF9Glyph;
- case SWT.F10: return OS.kMenuF10Glyph;
- case SWT.F11: return OS.kMenuF11Glyph;
- case SWT.F12: return OS.kMenuF12Glyph;
- case SWT.F13: return OS.kMenuF13Glyph;
- case SWT.F14: return OS.kMenuF14Glyph;
- case SWT.F15: return OS.kMenuF15Glyph;
- case SWT.HOME: return OS.kMenuNorthwestArrowGlyph;
- case SWT.END: return OS.kMenuSoutheastArrowGlyph;
- /*
- * The following lines are intentionally commented.
- * The Mac does not (currently) have glyphs for these keys.
- */
-// case SWT.INSERT: return OS.kMenuNullGlyph;
- }
- return OS.kMenuNullGlyph;
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
-}
-
-void releaseChildren (boolean destroy) {
- if (menu != null) {
- menu.release (false);
- menu = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- accelerator = 0;
- if (this == parent.defaultItem) parent.defaultItem = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the arm events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ArmListener
- * @see #addArmListener
- */
-public void removeArmListener (ArmListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Arm, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/*public*/ void select () {
- checkWidget ();
- Menu menu = parent, menuParent;
- while (menu.cascade != null && (menuParent = menu.cascade.parent) != null) {
- if ((menuParent.style & SWT.BAR) != 0) break;
- menu = menuParent;
- }
- if (menu == null) return;
- OS.HiliteMenu (OS.GetMenuID (menu.handle));
- int[] event = new int[1];
- OS.CreateEvent (0, OS.kEventClassCommand, OS.kEventProcessCommand, 0.0, 0, event);
- if (event [0] != 0) {
- int parentHandle = parent.handle;
- HICommand command = new HICommand ();
- command.attributes = OS.kHICommandFromMenu;
- command.menu_menuRef = parentHandle;
- command.menu_menuItemIndex = (short) (parent.indexOf (this) + 1);
- OS.SetEventParameter (event [0], OS.kEventParamDirectObject, OS.typeHICommand, HICommand.sizeof, command);
- OS.SendEventToEventTarget (event [0], OS.GetApplicationEventTarget ());
- OS.ReleaseEvent (event [0]);
- }
-}
-
-void selectRadio () {
- int index = 0;
- MenuItem [] items = parent.getItems ();
- while (index < items.length && items [index] != this) index++;
- int i = index - 1;
- while (i >= 0 && items [i].setRadioSelection (false)) --i;
- int j = index + 1;
- while (j < items.length && items [j].setRadioSelection (false)) j++;
- setSelection (true);
-}
-
-/**
- * Sets the widget accelerator. An accelerator is the bit-wise
- * OR of zero or more modifier masks and a key. Examples:
- * <code>SWT.MOD1 | SWT.MOD2 | 'T', SWT.MOD3 | SWT.F2</code>.
- * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
- * The default value is zero, indicating that the menu item does
- * not have an accelerator.
- *
- * @param accelerator an integer that is the bit-wise OR of masks and a key
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAccelerator (int accelerator) {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) return;
- if (this.accelerator == accelerator) return;
- boolean update = (this.accelerator == 0 && accelerator != 0) || (this.accelerator != 0 && accelerator == 0);
- this.accelerator = accelerator;
- boolean inSetVirtualKey = false;
- int inModifiers = OS.kMenuNoModifiers, inGlyph = OS.kMenuNullGlyph, inKey = 0;
- if (accelerator != 0) {
- inKey = accelerator & SWT.KEY_MASK;
- inGlyph = keyGlyph (inKey);
- int virtualKey = Display.untranslateKey (inKey);
- if (inKey == ' ') virtualKey = 49;
- if (virtualKey != 0) {
- inSetVirtualKey = true;
- inKey = virtualKey;
- } else {
- inKey = Character.toUpperCase ((char)inKey);
- }
- inModifiers = (byte) OS.kMenuNoCommandModifier;
- if ((accelerator & SWT.SHIFT) != 0) inModifiers |= OS.kMenuShiftModifier;
- if ((accelerator & SWT.CONTROL) != 0) inModifiers |= OS.kMenuControlModifier;
- if ((accelerator & SWT.COMMAND) != 0) inModifiers &= ~OS.kMenuNoCommandModifier;
- if ((accelerator & SWT.ALT) != 0) inModifiers |= OS.kMenuOptionModifier;
- }
- short menuIndex = (short) (index + 1);
- OS.SetMenuItemModifiers (parent.handle, menuIndex, (byte)inModifiers);
- OS.SetMenuItemCommandKey (parent.handle, menuIndex, inSetVirtualKey, (char)inKey);
- OS.SetMenuItemKeyGlyph (parent.handle, menuIndex, (short)inGlyph);
- if (update) updateText (menuIndex);
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled menu item is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) return;
- int outMenuRef [] = new int [1];
- short menuIndex = (short) (index + 1);
- OS.GetMenuItemHierarchicalMenu (parent.handle, menuIndex, outMenuRef);
- if (enabled) {
- state &= ~DISABLED;
- if (outMenuRef [0] != 0) OS.EnableMenuItem (outMenuRef [0], (short) 0);
- OS.EnableMenuItem (parent.handle, menuIndex);
- } else {
- state |= DISABLED;
- if (outMenuRef [0] != 0) OS.DisableMenuItem (outMenuRef [0], (short) 0);
- OS.DisableMenuItem (parent.handle, menuIndex);
- }
-}
-
-/**
- * Sets the image the receiver will display to the argument.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept (for example, Windows NT).
- * Furthermore, some platforms (such as GTK), cannot display both
- * a check box and an image at the same time. Instead, they hide
- * the image and display the check box.
- * </p>
- *
- * @param image the image to display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return;
- int index = parent.indexOf (this);
- if (index == -1) return;
- super.setImage (image);
- int imageHandle = image != null ? image.handle : 0;
- byte type = image != null ? (byte)OS.kMenuCGImageRefType : (byte)OS.kMenuNoIcon;
- OS.SetMenuItemIconHandle (parent.handle, (short) (index + 1), type, imageHandle);
-}
-
-/**
- * Sets the receiver's pull down menu to the argument.
- * Only <code>CASCADE</code> menu items can have a
- * pull down menu. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pull down
- * menu is platform specific.
- * <p>
- * Note: Disposing of a menu item that has a pull down menu
- * will dispose of the menu. To avoid this behavior, set the
- * menu to null before the menu item is disposed.
- * </p>
- *
- * @param menu the new pull down menu
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_MENU_NOT_DROP_DOWN - if the menu is not a drop down menu</li>
- * <li>ERROR_MENUITEM_NOT_CASCADE - if the menu item is not a <code>CASCADE</code></li>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenu (Menu menu) {
- checkWidget ();
-
- /* Check to make sure the new menu is valid */
- if ((style & SWT.CASCADE) == 0) {
- error (SWT.ERROR_MENUITEM_NOT_CASCADE);
- }
- if (menu != null) {
- if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.DROP_DOWN) == 0) {
- error (SWT.ERROR_MENU_NOT_DROP_DOWN);
- }
- if (menu.parent != parent.parent) {
- error (SWT.ERROR_INVALID_PARENT);
- }
- }
-
- /* Assign the new menu */
- Menu oldMenu = this.menu;
- if (oldMenu == menu) return;
- if (oldMenu != null) oldMenu.cascade = null;
- this.menu = menu;
-
- /* Update the menu in the OS */
- int index = parent.indexOf (this);
- if (index == -1) return;
- int menuHandle = 0;
- if (menu == null) {
- menuHandle = createEmptyMenu ();
- } else {
- menu.cascade = this;
- menuHandle = menu.handle;
- }
- short menuIndex = (short) (index + 1);
- if (menuHandle != 0) {
- int [] outString = new int [1];
- if (OS.CopyMenuItemTextAsCFString (parent.handle, menuIndex, outString) != OS.noErr) {
- error (SWT.ERROR_CANNOT_SET_MENU);
- }
- OS.SetMenuTitleWithCFString (menuHandle, outString [0]);
- OS.CFRelease (outString [0]);
- }
- if (oldMenu != null) OS.RetainMenu (oldMenu.handle);
- if (OS.SetMenuItemHierarchicalMenu (parent.handle, menuIndex, menuHandle) != OS.noErr) {
- error (SWT.ERROR_CANNOT_SET_MENU);
- }
- if (menuHandle != 0) OS.ReleaseMenu (menuHandle);
-}
-
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-
-/**
- * Sets the selection state of the receiver.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked.
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget ();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
- int index = parent.indexOf (this);
- if (index == -1) return;
- int inMark = selected ? ((style & SWT.RADIO) != 0) ? OS.diamondMark : OS.checkMark : 0;
- OS.SetItemMark (parent.handle, (short) (index + 1), (short) inMark);
-}
-
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character and accelerator text.
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- * <p>
- * Accelerator text is indicated by the '\t' character.
- * On platforms that support accelerator text, the text
- * that follows the '\t' character is displayed to the user,
- * typically indicating the key stroke that will cause
- * the item to become selected. On most platforms, the
- * accelerator text appears right aligned in the menu.
- * Setting the accelerator text does not install the
- * accelerator key sequence. The accelerator key sequence
- * is installed using #setAccelerator.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setAccelerator
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- if (text.equals (string)) return;
- int index = parent.indexOf (this);
- if (index == -1) return;
- super.setText (string);
- updateText ((short) (index + 1));
-}
-
-void updateText (short menuIndex) {
- if ((style & SWT.SEPARATOR) != 0) return;
- char [] buffer = new char [text.length ()];
- text.getChars (0, buffer.length, buffer, 0);
- int i=0, j=0;
- while (i < buffer.length) {
- if (buffer [i] == '\t') break;
- if ((buffer [j++] = buffer [i++]) == '&') {
- if (i == buffer.length) {continue;}
- if (buffer [i] == '&') {i++; continue;}
- j--;
- }
- }
- int str = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, j);
- if (str == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- OS.SetMenuItemTextWithCFString (parent.handle, menuIndex, str);
- int [] outHierMenu = new int [1];
- OS.GetMenuItemHierarchicalMenu (parent.handle, menuIndex, outHierMenu);
- if (outHierMenu [0] != 0) OS.SetMenuTitleWithCFString (outHierMenu [0], str);
- /*
- * Feature in the Macintosh. Setting text that starts with "-" makes the
- * menu item a separator. The fix is to clear the separator attribute.
- */
- if (text.startsWith ("-")) {
- OS.ChangeMenuItemAttributes (parent.handle, menuIndex, 0, OS.kMenuItemAttrSeparator);
- }
- OS.CFRelease (str);
-
- acceleratorSet = accelerator != 0;
- if (!acceleratorSet) {
- int inModifiers = OS.kMenuNoCommandModifier, inGlyph = OS.kMenuNullGlyph, inKey = 0, swtKey = 0;
- boolean inSetVirtualKey = false;
- if (i + 1 < buffer.length && buffer [i] == '\t') {
- for (j = i + 1; j < buffer.length; j++) {
- switch (buffer [j]) {
- case '\u2303': inModifiers |= OS.kMenuControlModifier; i++; break;
- case '\u2325': inModifiers |= OS.kMenuOptionModifier; i++; break;
- case '\u21E7': inModifiers |= OS.kMenuShiftModifier; i++; break;
- case '\u2318': inModifiers &= ~OS.kMenuNoCommandModifier; i++; break;
- default:
- j = buffer.length;
- break;
- }
- }
- switch (buffer.length - i - 1) {
- case 1:
- inKey = buffer [i + 1];
- switch (inKey) {
- case '\u232B': swtKey = SWT.BS; break;
- case '\u21A9': swtKey = SWT.CR; break;
- case '\u2326': swtKey = SWT.DEL; break;
- case '\u238B': swtKey = SWT.ESC; break;
- case '\u21E5': swtKey = SWT.TAB; break;
- case ' ': swtKey = ' '; break;
- case '\u2423': swtKey = ' '; break;
- case '\u2191': swtKey = SWT.ARROW_UP; break;
- case '\u2193': swtKey = SWT.ARROW_DOWN; break;
- case '\u2190': swtKey = SWT.ARROW_LEFT; break;
- case '\u2192': swtKey = SWT.ARROW_RIGHT; break;
- case '\u21DE': swtKey = SWT.PAGE_UP; break;
- case '\u21DF': swtKey = SWT.PAGE_DOWN; break;
- case '\u0003': swtKey = SWT.KEYPAD_CR; break;
- case '\uF746': swtKey = SWT.HELP; break;
- case '\uF729': swtKey = SWT.HOME; break;
- case '\uF72B': swtKey = SWT.END; break;
-// case '\u21EA': swtKey = SWT.CAPS_LOCK; break;
- case '\uF704': swtKey = SWT.F1; break;
- case '\uF705': swtKey = SWT.F2; break;
- case '\uF706': swtKey = SWT.F3; break;
- case '\uF707': swtKey = SWT.F4; break;
- case '\uF708': swtKey = SWT.F5; break;
- case '\uF709': swtKey = SWT.F6; break;
- case '\uF70A': swtKey = SWT.F7; break;
- case '\uF70B': swtKey = SWT.F8; break;
- case '\uF70C': swtKey = SWT.F9; break;
- case '\uF70D': swtKey = SWT.F10; break;
- case '\uF70E': swtKey = SWT.F11; break;
- case '\uF70F': swtKey = SWT.F12; break;
- case '\uF710': swtKey = SWT.F13; break;
- case '\uF711': swtKey = SWT.F14; break;
- case '\uF712': swtKey = SWT.F15; break;
- }
- break;
- case 2:
- if (buffer [i + 1] == 'F') {
- switch (buffer [i + 2]) {
- case '1': swtKey = SWT.F1; break;
- case '2': swtKey = SWT.F2; break;
- case '3': swtKey = SWT.F3; break;
- case '4': swtKey = SWT.F4; break;
- case '5': swtKey = SWT.F5; break;
- case '6': swtKey = SWT.F6; break;
- case '7': swtKey = SWT.F7; break;
- case '8': swtKey = SWT.F8; break;
- case '9': swtKey = SWT.F9; break;
- }
- }
- break;
- case 3:
- if (buffer [i + 1] == 'F' && buffer [i + 2] == '1') {
- switch (buffer [i + 3]) {
- case '0': swtKey = SWT.F10; break;
- case '1': swtKey = SWT.F11; break;
- case '2': swtKey = SWT.F12; break;
- case '3': swtKey = SWT.F13; break;
- case '4': swtKey = SWT.F14; break;
- case '5': swtKey = SWT.F15; break;
- }
- }
- break;
- }
-
- inGlyph = keyGlyph (swtKey);
- int virtualKey = Display.untranslateKey (swtKey);
- if (swtKey == ' ') {
- virtualKey = 49;
- inGlyph = OS.kMenuSpaceGlyph;
- }
- if (virtualKey != 0) {
- inSetVirtualKey = true;
- inKey = virtualKey;
- } else {
- inKey = Character.toUpperCase ((char)inKey);
- }
- }
- acceleratorSet = inKey != 0 || inGlyph != OS.kMenuNullGlyph;
- OS.SetMenuItemModifiers (parent.handle, menuIndex, (byte)inModifiers);
- OS.SetMenuItemCommandKey (parent.handle, menuIndex, inSetVirtualKey, (char)inKey);
- OS.SetMenuItemKeyGlyph (parent.handle, menuIndex, (short)inGlyph);
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MessageBox.java
deleted file mode 100644
index 58ed9c4472..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/MessageBox.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.carbon.*;
-
-/**
- * Instances of this class are used to inform or warn the user.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, ICON_WARNING, ICON_WORKING</dd>
- * <dd>OK, OK | CANCEL</dd>
- * <dd>YES | NO, YES | NO | CANCEL</dd>
- * <dd>RETRY | CANCEL</dd>
- * <dd>ABORT | RETRY | IGNORE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION, ICON_QUESTION,
- * ICON_WARNING and ICON_WORKING may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class MessageBox extends Dialog {
- String message = "";
-
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public MessageBox (Shell parent) {
- this (parent, SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_QUESTION
- * @see SWT#ICON_WARNING
- * @see SWT#ICON_WORKING
- * @see SWT#OK
- * @see SWT#CANCEL
- * @see SWT#YES
- * @see SWT#NO
- * @see SWT#ABORT
- * @see SWT#RETRY
- * @see SWT#IGNORE
- */
-public MessageBox (Shell parent, int style) {
- super (parent, checkStyle (parent, checkStyle (style)));
- checkSubclass ();
-}
-
-static int checkStyle (int style) {
- int mask = (SWT.YES | SWT.NO | SWT.OK | SWT.CANCEL | SWT.ABORT | SWT.RETRY | SWT.IGNORE);
- int bits = style & mask;
- if (bits == SWT.OK || bits == SWT.CANCEL || bits == (SWT.OK | SWT.CANCEL)) return style;
- if (bits == SWT.YES || bits == SWT.NO || bits == (SWT.YES | SWT.NO) || bits == (SWT.YES | SWT.NO | SWT.CANCEL)) return style;
- if (bits == (SWT.RETRY | SWT.CANCEL) || bits == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) return style;
- style = (style & ~mask) | SWT.OK;
- return style;
-}
-
-int createCFString (String id) {
- String string = SWT.getMessage(id);
- char [] buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- return OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
-}
-
-/**
- * Returns the dialog's message, or an empty string if it does not have one.
- * The message is a description of the purpose for which the dialog was opened.
- * This message will be visible in the dialog while it is open.
- *
- * @return the message
- */
-public String getMessage () {
- return message;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return the ID of the button that was selected to dismiss the
- * message box (e.g. SWT.OK, SWT.CANCEL, etc.)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public int open () {
- int alertType = OS.kAlertPlainAlert;
- if ((style & SWT.ICON_ERROR) != 0) alertType = OS.kAlertStopAlert;
- if ((style & SWT.ICON_INFORMATION) != 0) alertType = OS.kAlertNoteAlert;
- if ((style & SWT.ICON_QUESTION) != 0) alertType = OS.kAlertNoteAlert;
- if ((style & SWT.ICON_WARNING) != 0) alertType = OS.kAlertCautionAlert;
- if ((style & SWT.ICON_WORKING) != 0) alertType = OS.kAlertNoteAlert;
-
- int error = 0;
- int explanation = 0;
- String errorString = title;
- String explanationString = message;
- if (errorString != null) {
- char [] buffer = new char [errorString.length ()];
- errorString.getChars (0, buffer.length, buffer, 0);
- error = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- }
- if (explanationString != null) {
- char [] buffer = new char [explanationString.length ()];
- explanationString.getChars (0, buffer.length, buffer, 0);
- explanation = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- }
-
- AlertStdCFStringAlertParamRec param = new AlertStdCFStringAlertParamRec ();
- param.version = OS.kStdCFStringAlertVersionOne;
- param.position = (short)OS.kWindowAlertPositionParentWindowScreen;
- int defaultStr = 0, cancelStr = 0, otherStr = 0;
- int mask = (SWT.YES | SWT.NO | SWT.OK | SWT.CANCEL | SWT.ABORT | SWT.RETRY | SWT.IGNORE);
- int bits = style & mask;
- switch (bits) {
- case SWT.OK:
- param.defaultButton = (short)OS.kAlertStdAlertOKButton;
- param.defaultText = OS.kAlertDefaultOKText;
- break;
- case SWT.CANCEL:
- param.defaultButton = (short)OS.kAlertStdAlertOKButton;
- param.defaultText = defaultStr = createCFString ("SWT_Cancel");
- break;
- case SWT.OK | SWT.CANCEL:
- param.defaultButton = (short)OS.kAlertStdAlertOKButton;
- param.defaultText = OS.kAlertDefaultOKText;
- param.cancelButton = (short)OS.kAlertStdAlertCancelButton;
- param.cancelText = OS.kAlertDefaultCancelText;
- break;
- case SWT.YES:
- param.defaultButton = (short)OS.kAlertStdAlertOKButton;
- param.defaultText = defaultStr = createCFString ("SWT_Yes");
- break;
- case SWT.NO:
- param.cancelButton = (short)OS.kAlertStdAlertOKButton;
- param.cancelText = defaultStr = createCFString ("SWT_No");
- break;
- case SWT.YES | SWT.NO:
- param.defaultButton = (short)OS.kAlertStdAlertOKButton;
- param.defaultText = defaultStr = createCFString ("SWT_Yes");
- param.cancelButton = (short)OS.kAlertStdAlertCancelButton;
- param.cancelText = cancelStr = createCFString ("SWT_No");
- break;
- case SWT.YES | SWT.NO | SWT.CANCEL:
- param.defaultButton = (short)OS.kAlertStdAlertOKButton;
- param.defaultText = defaultStr = createCFString ("SWT_Yes");
- param.otherText = cancelStr = createCFString ("SWT_No");
- param.cancelButton = (short)OS.kAlertStdAlertCancelButton;
- param.cancelText = OS.kAlertDefaultCancelText;
- break;
- case SWT.RETRY | SWT.CANCEL:
- param.defaultButton = (short)OS.kAlertStdAlertOKButton;
- param.defaultText = defaultStr = createCFString ("SWT_Retry");
- param.cancelButton = (short)OS.kAlertStdAlertCancelButton;
- param.cancelText = OS.kAlertDefaultCancelText;
- break;
- case SWT.ABORT | SWT.RETRY | SWT.IGNORE:
- param.defaultButton = (short)OS.kAlertStdAlertOKButton;
- param.defaultText = defaultStr = createCFString ("SWT_Abort");
- param.otherText = cancelStr = createCFString ("SWT_Retry");
- param.cancelButton = (short)OS.kAlertStdAlertCancelButton;
- param.cancelText = otherStr = createCFString ("SWT_Ignore");
- break;
- }
-
- int [] dialogRef= new int [1];
- OS.CreateStandardAlert ((short) alertType, error, explanation, param, dialogRef);
- if (error != 0) OS.CFRelease(error);
- if (explanation != 0) OS.CFRelease(explanation);
- if (defaultStr != 0) OS.CFRelease(defaultStr);
- if (cancelStr != 0) OS.CFRelease(cancelStr);
- if (otherStr != 0) OS.CFRelease(otherStr);
-
- if (dialogRef[0] != 0) {
- /* Force a system modal message box to the front */
- if ((style & SWT.SYSTEM_MODAL) != 0) {
- OS.SetFrontProcessWithOptions (new int [] {0, OS.kCurrentProcess}, OS.kSetFrontProcessFrontWindowOnly);
- }
- short [] outItemHit = new short [1];
- OS.RunStandardAlert(dialogRef[0], 0, outItemHit);
- if (outItemHit [0] != 0) {
- switch (bits) {
- case SWT.OK:
- return SWT.OK;
- case SWT.CANCEL:
- return SWT.CANCEL;
- case SWT.OK | SWT.CANCEL:
- if (outItemHit [0] == OS.kAlertStdAlertOKButton) return SWT.OK;
- return SWT.CANCEL;
- case SWT.YES:
- return SWT.YES;
- case SWT.NO:
- return SWT.NO;
- case SWT.YES | SWT.NO:
- if (outItemHit [0] == OS.kAlertStdAlertOKButton) return SWT.YES;
- return SWT.NO;
- case SWT.YES | SWT.NO | SWT.CANCEL:
- if (outItemHit [0] == OS.kAlertStdAlertOKButton) return SWT.YES;
- if (outItemHit [0] == OS.kAlertStdAlertOtherButton) return SWT.NO;
- return SWT.CANCEL;
- case SWT.RETRY | SWT.CANCEL:
- if (outItemHit [0] == OS.kAlertStdAlertOKButton) return SWT.RETRY;
- return SWT.CANCEL;
- case SWT.ABORT | SWT.RETRY | SWT.IGNORE:
- if (outItemHit [0] == OS.kAlertStdAlertOKButton) return SWT.ABORT;
- if (outItemHit [0] == OS.kAlertStdAlertOtherButton) return SWT.RETRY;
- return SWT.IGNORE;
- }
- }
- }
- return SWT.CANCEL;
-}
-
-/**
- * Sets the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @param string the message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- */
-public void setMessage (String string) {
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- message = string;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ProgressBar.java
deleted file mode 100644
index 83e0d247b0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ProgressBar.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.internal.carbon.OS;
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of the receiver represent an unselectable
- * user interface object that is used to display progress,
- * typically in the form of a bar.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SMOOTH, HORIZONTAL, VERTICAL, INDETERMINATE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#progressbar">ProgressBar snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ProgressBar extends Control {
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SMOOTH
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#INDETERMINATE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ProgressBar (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricNormalProgressBarThickness, outMetric);
- int width = 0, height = 0;
- if ((style & SWT.HORIZONTAL) != 0) {
- height = outMetric [0];
- width = height * 10;
- } else {
- width = outMetric [0];
- height = width * 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- return new Point (width, height);
-}
-
-void createHandle () {
- int [] outControl = new int [1];
- int window = OS.GetControlOwner (parent.handle);
- OS.CreateProgressBarControl (window, null, 0, 0, 100, (style & SWT.INDETERMINATE) != 0, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
-}
-
-void drawBackground (int control, int context) {
- fillBackground (control, context, null);
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget();
- return OS.GetControl32BitMaximum (handle);
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget();
- return OS.GetControl32BitMinimum (handle);
-}
-
-/**
- * Returns the single 'selection' that is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget();
- return OS.GetControl32BitValue (handle);
-}
-
-/**
- * Returns the state of the receiver. The value will be one of:
- * <ul>
- * <li>{@link SWT#NORMAL}</li>
- * <li>{@link SWT#ERROR}</li>
- * <li>{@link SWT#PAUSED}</li>
- * </ul>
- *
- * @return the state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public int getState () {
- checkWidget ();
- return SWT.NORMAL;
-}
-
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget();
- if (value < 0) return;
- int minimum = OS.GetControl32BitMinimum (handle);
- if (value > minimum) {
- OS.SetControl32BitMaximum (handle, value);
- }
-}
-
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is negative or is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be nonnegative and less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget();
- if (value < 0) return;
- int maximum = OS.GetControl32BitMaximum (handle);
- if (value < maximum) {
- OS.SetControl32BitMinimum (handle, value);
- }
-}
-
-/**
- * Sets the single 'selection' that is the receiver's
- * position to the argument which must be greater than or equal
- * to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget();
- OS.SetControl32BitValue (handle, value);
- /*
- * Feature in the Macintosh. Progress bars are always updated
- * using an event loop timer, even when they are not indeterminate.
- * This means that nothing is drawn until the event loop. The
- * fix is to allow operating system timers to run without dispatching
- * any other events.
- */
- display.runEventLoopTimers ();
-}
-
-/**
- * Sets the state of the receiver. The state must be one of these values:
- * <ul>
- * <li>{@link SWT#NORMAL}</li>
- * <li>{@link SWT#ERROR}</li>
- * <li>{@link SWT#PAUSED}</li>
- * </ul>
- *
- * @param state the new state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setState (int state) {
- checkWidget ();
- //NOT IMPLEMENTED
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Sash.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Sash.java
deleted file mode 100644
index e7c44b5edf..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Sash.java
+++ /dev/null
@@ -1,427 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.CFRange;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.Rect;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of the receiver represent a selectable user interface object
- * that allows the user to drag a rubber banded outline of the sash within
- * the parent control.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL, SMOOTH</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#sash">Sash snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Sash extends Control {
- Cursor sizeCursor;
- boolean dragging;
- int lastX, lastY, startX, startY;
- static final int INCREMENT = 1;
- static final int PAGE_INCREMENT = 9;
- static final String [] AX_ATTRIBUTES = {
- OS.kAXOrientationAttribute,
- OS.kAXValueAttribute,
- OS.kAXMaxValueAttribute,
- OS.kAXMinValueAttribute,
- };
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#SMOOTH
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Sash (Composite parent, int style) {
- super (parent, checkStyle (style));
- int cursorStyle = (style & SWT.VERTICAL) != 0 ? SWT.CURSOR_SIZEWE : SWT.CURSOR_SIZENS;
- sizeCursor = new Cursor (display, cursorStyle);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the x, y, width, and height fields of the event object are valid.
- * If the receiver is being dragged, the event object detail field contains the value <code>SWT.DRAG</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- /*
- * Macintosh only supports smooth dragging.
- */
- style |= SWT.SMOOTH;
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-int callFocusEventHandler (int nextHandler, int theEvent) {
- return OS.noErr;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = 0, height = 0;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += DEFAULT_WIDTH; height += 5;
- } else {
- width += 5; height += DEFAULT_HEIGHT;
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- return new Point (width, height);
-}
-
-void createHandle () {
- state |= GRAB | THEME_BACKGROUND;
- int features = OS.kControlSupportsFocus;
- int [] outControl = new int [1];
- int window = OS.GetControlOwner (parent.handle);
- OS.CreateUserPaneControl (window, null, features, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
-}
-
-void drawBackground (int control, int context) {
- fillBackground (control, context, null);
-}
-
-String [] getAxAttributes () {
- return AX_ATTRIBUTES;
-}
-
-int kEventAccessibleGetNamedAttribute (int nextHandler, int theEvent, int userData) {
- int code = OS.eventNotHandledErr;
- int [] stringRef = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamAccessibleAttributeName, OS.typeCFStringRef, null, 4, null, stringRef);
- int length = 0;
- if (stringRef [0] != 0) length = OS.CFStringGetLength (stringRef [0]);
- char [] buffer = new char [length];
- CFRange range = new CFRange ();
- range.length = length;
- OS.CFStringGetCharacters (stringRef [0], range, buffer);
- String attributeName = new String(buffer);
- if (attributeName.equals (OS.kAXRoleAttribute) || attributeName.equals (OS.kAXRoleDescriptionAttribute)) {
- String roleText = OS.kAXSplitterRole;
- buffer = new char [roleText.length ()];
- roleText.getChars (0, buffer.length, buffer, 0);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- if (attributeName.equals (OS.kAXRoleAttribute)) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- } else { // kAXRoleDescriptionAttribute
- int stringRef2 = OS.HICopyAccessibilityRoleDescription (stringRef [0], 0);
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, new int [] {stringRef2});
- OS.CFRelease(stringRef2);
- }
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- } else if (attributeName.equals (OS.kAXOrientationAttribute)) {
- String orientation = (style & SWT.VERTICAL) != 0 ? OS.kAXVerticalOrientationValue : OS.kAXHorizontalOrientationValue;
- buffer = new char [orientation.length ()];
- orientation.getChars (0, buffer.length, buffer, 0);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- } else if (attributeName.equals (OS.kAXValueAttribute)) {
- Point location = getLocation();
- int value = (style & SWT.VERTICAL) != 0 ? location.x : location.y;
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeSInt32, 4, new int [] {value});
- code = OS.noErr;
- } else if (attributeName.equals (OS.kAXMaxValueAttribute)) {
- Rect parentBounds = new Rect ();
- OS.GetControlBounds (parent.handle, parentBounds);
- int maxValue = (style & SWT.VERTICAL) != 0 ?
- parentBounds.right - parentBounds.left :
- parentBounds.bottom - parentBounds.top;
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeSInt32, 4, new int [] {maxValue});
- code = OS.noErr;
- } else if (attributeName.equals (OS.kAXMinValueAttribute)) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeSInt32, 4, new int [] {0});
- code = OS.noErr;
- }
- if (accessible != null) {
- code = accessible.internal_kEventAccessibleGetNamedAttribute (nextHandler, theEvent, code);
- }
- return code;
-}
-
-int kEventControlClick (int nextHandler, int theEvent, int userData) {
- int result = super.kEventControlClick (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- if (!isEnabled ()) return OS.noErr;
- return result;
-}
-
-int kEventControlGetFocusPart (int nextHandler, int theEvent, int userData) {
- return OS.noErr;
-}
-
-int kEventControlSetCursor (int nextHandler, int theEvent, int userData) {
- int result = super.kEventControlSetCursor (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- display.setCursor (sizeCursor.handle);
- return OS.noErr;
-}
-
-int kEventControlSetFocusPart (int nextHandler, int theEvent, int userData) {
- int result = super.kEventControlSetFocusPart (nextHandler, theEvent, userData);
- if (result == OS.noErr) {
- Point location = getLocation();
- lastX = location.x;
- lastY = location.y;
- }
- return result;
-}
-
-int kEventUnicodeKeyPressed (int nextHandler, int theEvent, int userData) {
- int result = super.kEventUnicodeKeyPressed (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- int [] keyboardEvent = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendKeyboardEvent, OS.typeEventRef, null, keyboardEvent.length * 4, null, keyboardEvent);
- int [] keyCode = new int [1];
- OS.GetEventParameter (keyboardEvent [0], OS.kEventParamKeyCode, OS.typeUInt32, null, keyCode.length * 4, null, keyCode);
- switch (keyCode [0]) {
- case 126: /* Up arrow */
- case 123: /* Left arrow */
- case 125: /* Down arrow */
- case 124: /* Right arrow */ {
- int xChange = 0, yChange = 0;
- int stepSize = PAGE_INCREMENT;
- int [] modifiers = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
- if ((modifiers [0] & OS.controlKey) != 0) stepSize = INCREMENT;
- if ((style & SWT.VERTICAL) != 0) {
- if (keyCode [0] == 126 || keyCode [0] == 125) break;
- xChange = keyCode [0] == 123 ? -stepSize : stepSize;
- } else {
- if (keyCode [0] == 123 || keyCode [0] == 124) break;
- yChange = keyCode [0] == 126 ? -stepSize : stepSize;
- }
-
- Rectangle bounds = getBounds ();
- int width = bounds.width, height = bounds.height;
- Rectangle parentBounds = parent.getBounds ();
- int parentWidth = parentBounds.width;
- int parentHeight = parentBounds.height;
- int newX = lastX, newY = lastY;
- if ((style & SWT.VERTICAL) != 0) {
- newX = Math.min (Math.max (0, lastX + xChange), parentWidth - width);
- } else {
- newY = Math.min (Math.max (0, lastY + yChange), parentHeight - height);
- }
- if (newX == lastX && newY == lastY) return result;
- Event event = new Event ();
- event.x = newX;
- event.y = newY;
- event.width = width;
- event.height = height;
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) break;
- if (event.doit) {
- setBounds (event.x, event.y, width, height);
- if (isDisposed ()) break;
- lastX = event.x;
- lastY = event.y;
- if (isDisposed ()) return result;
- int cursorX = event.x, cursorY = event.y;
- if ((style & SWT.VERTICAL) != 0) {
- cursorY += height / 2;
- } else {
- cursorX += width / 2;
- }
- display.setCursorLocation (parent.toDisplay (cursorX, cursorY));
- }
- break;
- }
- }
-
- return result;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (sizeCursor != null) sizeCursor.dispose ();
- sizeCursor = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-
-boolean sendMouseEvent (int type, short button, int count, int detail, boolean send, int chord, short x, short y, int modifiers) {
- boolean result = super.sendMouseEvent (type, button, count, detail, send, chord, x, y, modifiers);
- Rect rect = new Rect ();
- OS.GetControlBounds (handle, rect);
- int controlX = rect.left;
- int controlY = rect.top;
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- OS.GetControlBounds (parent.handle, rect);
- int parentWidth = rect.right - rect.left;
- int parentHeight = rect.bottom - rect.top;
- switch (type) {
- case SWT.MouseDown:
- if (button != 1 || count != 1) break;
- startX = x;
- startY = y;
- Event event = new Event ();
- event.x = controlX;
- event.y = controlY;
- event.width = width;
- event.height = height;
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return result;
- if (event.doit) {
- lastX = event.x;
- lastY = event.y;
- dragging = true;
- setBounds (event.x, event.y, width, height);
- }
- break;
- case SWT.MouseUp:
- if (!dragging) break;
- dragging = false;
- event = new Event ();
- event.x = lastX;
- event.y = lastY;
- event.width = width;
- event.height = height;
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return result;
- if (event.doit) {
- setBounds (event.x, event.y, width, height);
- }
- break;
- case SWT.MouseMove:
- if (!dragging) break;
- int newX = lastX, newY = lastY;
- if ((style & SWT.VERTICAL) != 0) {
- newX = Math.min (Math.max (0, x + controlX - startX), parentWidth - width);
- } else {
- newY = Math.min (Math.max (0, y + controlY - startY), parentHeight - height);
- }
- if (newX == lastX && newY == lastY) return result;
- event = new Event ();
- event.x = newX;
- event.y = newY;
- event.width = width;
- event.height = height;
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return result;
- if (event.doit) {
- lastX = event.x;
- lastY = event.y;
- setBounds (event.x, event.y, width, height);
- }
- break;
- }
- return result;
-}
-
-int traversalCode (int key, int theEvent) {
- return 0;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Scale.java
deleted file mode 100644
index 957ba478bd..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Scale.java
+++ /dev/null
@@ -1,387 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.OS;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of the receiver represent a selectable user
- * interface object that present a range of continuous
- * numeric values.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#scale">Scale snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Scale extends Control {
- int increment = 1;
- int pageIncrement = 10;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Scale (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-int actionProc (int theControl, int partCode) {
- int result = super.actionProc (theControl, partCode);
- if (result == OS.noErr) return result;
- sendEvent (SWT.Selection);
- return result;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the receiver's value.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = 0, height = 0;
- if ((style & SWT.HORIZONTAL) != 0) {
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricHSliderHeight, outMetric);
- height = outMetric [0];
- width = height * 10;
- } else {
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricVSliderWidth, outMetric);
- width = outMetric [0];
- height = width * 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- return new Point (width, height);
-}
-
-void createHandle () {
- state |= THEME_BACKGROUND;
- int actionProc = display.actionProc;
- int [] outControl = new int [1];
- int window = OS.GetControlOwner (parent.handle);
- int value = (style & SWT.VERTICAL) != 0 ? 100 : 0;
- OS.CreateSliderControl (window, null, value, 0, 100, OS.kControlSliderDoesNotPoint, (short)0, true, actionProc, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget();
- return increment;
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget();
- return OS.GetControl32BitMaximum (handle);
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget();
- return OS.GetControl32BitMinimum (handle);
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget();
- return pageIncrement;
-}
-
-/**
- * Returns the 'selection', which is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget();
- int value = OS.GetControl32BitValue (handle);
- if ((style & SWT.VERTICAL) != 0) {
- int minimum = OS.GetControl32BitMinimum (handle);
- int maximum = OS.GetControl32BitMaximum (handle);
- value = maximum - value + minimum;
- }
- return value;
-}
-
-int kEventMouseDown (int nextHandler, int theEvent, int userData) {
- int result = super.kEventMouseDown (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- /*
- * Bug in the Macintosh. For some reason, when the slider
- * is not ghosted, if the slider has keyboard focus, the
- * user will not be able to drag the thumb to the maximum value
- * of the slider. The fix is to clear the focus temporarily
- * and restore it after the thumb tracking is complety.
- */
- if (!hasFocus ()) return result;
- display.ignoreFocus = true;
- int window = OS.GetControlOwner (handle);
- OS.ClearKeyboardFocus (window);
- result = OS.CallNextEventHandler (nextHandler, theEvent);
- if (!isDisposed ()) {
- OS.SetKeyboardFocus (window, handle, (short) focusPart ());
- }
- display.ignoreFocus = false;
- return result;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param increment the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- increment = value;
-}
-
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget();
- if (value < 0) return;
- int minimum = OS.GetControl32BitMinimum (handle);
- if (value > minimum) {
- OS.SetControl32BitMaximum (handle, value);
- }
-}
-
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is negative or is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be nonnegative and less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget();
- if (value < 0) return;
- int maximum = OS.GetControl32BitMaximum (handle);
- if (value < maximum) {
- OS.SetControl32BitMinimum (handle, value);
- }
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param pageIncrement the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- pageIncrement = value;
-}
-
-/**
- * Sets the 'selection', which is the receiver's value,
- * to the argument which must be greater than or equal to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget();
- if ((style & SWT.VERTICAL) != 0) {
- int minimum = OS.GetControl32BitMinimum (handle);
- int maximum = OS.GetControl32BitMaximum (handle);
- value = Math.min (maximum, Math.max (minimum, maximum - value + minimum));
- }
- OS.SetControl32BitValue (handle, value);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ScrollBar.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ScrollBar.java
deleted file mode 100644
index 8313c229d8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ScrollBar.java
+++ /dev/null
@@ -1,795 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.OS;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that represent a range of positive, numeric values.
- * <p>
- * At any given moment, a given scroll bar will have a
- * single 'selection' that is considered to be its
- * value, which is constrained to be within the range of
- * values the scroll bar represents (that is, between its
- * <em>minimum</em> and <em>maximum</em> values).
- * </p><p>
- * Typically, scroll bars will be made up of five areas:
- * <ol>
- * <li>an arrow button for decrementing the value</li>
- * <li>a page decrement area for decrementing the value by a larger amount</li>
- * <li>a <em>thumb</em> for modifying the value by mouse dragging</li>
- * <li>a page increment area for incrementing the value by a larger amount</li>
- * <li>an arrow button for incrementing the value</li>
- * </ol>
- * Based on their style, scroll bars are either <code>HORIZONTAL</code>
- * (which have a left facing button for decrementing the value and a
- * right facing button for incrementing it) or <code>VERTICAL</code>
- * (which have an upward facing button for decrementing the value
- * and a downward facing buttons for incrementing it).
- * </p><p>
- * On some platforms, the size of the scroll bar's thumb can be
- * varied relative to the magnitude of the range of values it
- * represents (that is, relative to the difference between its
- * maximum and minimum values). Typically, this is used to
- * indicate some proportional value such as the ratio of the
- * visible area of a document to the total amount of space that
- * it would take to display it. SWT supports setting the thumb
- * size even if the underlying platform does not, but in this
- * case the appearance of the scroll bar will not change.
- * </p><p>
- * Scroll bars are created by specifying either <code>H_SCROLL</code>,
- * <code>V_SCROLL</code> or both when creating a <code>Scrollable</code>.
- * They are accessed from the <code>Scrollable</code> using
- * <code>getHorizontalBar</code> and <code>getVerticalBar</code>.
- * </p><p>
- * Note: Scroll bars are not Controls. On some platforms, scroll bars
- * that appear as part of some standard controls such as a text or list
- * have no operating system resources and are not children of the control.
- * For this reason, scroll bars are treated specially. To create a control
- * that looks like a scroll bar but has operating system resources, use
- * <code>Slider</code>.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see Slider
- * @see Scrollable
- * @see Scrollable#getHorizontalBar
- * @see Scrollable#getVerticalBar
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ScrollBar extends Widget {
- int handle;
- int visibleRgn, oldActionProc;
- Scrollable parent;
- boolean dragging;
- int increment = 1;
- int pageIncrement = 10;
-
-ScrollBar () {
- /* Do nothing */
-}
-
-ScrollBar (Scrollable parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget ();
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values:
- * <code>SWT.NONE</code> - for the end of a drag.
- * <code>SWT.DRAG</code>.
- * <code>SWT.HOME</code>.
- * <code>SWT.END</code>.
- * <code>SWT.ARROW_DOWN</code>.
- * <code>SWT.ARROW_UP</code>.
- * <code>SWT.PAGE_DOWN</code>.
- * <code>SWT.PAGE_UP</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-int actionProc (int theControl, int partCode) {
- int result = super.actionProc (theControl, partCode);
- if (result == OS.noErr) return result;
- Event event = new Event ();
- int inc = 0;
- switch (partCode) {
- case OS.kControlUpButtonPart:
- inc -= increment;
- event.detail = SWT.ARROW_UP;
- break;
- case OS.kControlPageUpPart:
- inc -= pageIncrement;
- event.detail = SWT.PAGE_UP;
- break;
- case OS.kControlPageDownPart:
- inc += pageIncrement;
- event.detail = SWT.PAGE_DOWN;
- break;
- case OS.kControlDownButtonPart:
- inc += increment;
- event.detail = SWT.ARROW_DOWN;
- break;
- case OS.kControlIndicatorPart:
- dragging = true;
- event.detail = SWT.DRAG;
- break;
- default:
- return result;
- }
- if (oldActionProc != 0) {
- OS.Call (oldActionProc, theControl, partCode);
- parent.redrawBackgroundImage ();
- } else {
- int value = OS.GetControl32BitValue (handle) + inc;
- OS.SetControl32BitValue (handle, value);
- }
- sendEvent (SWT.Selection, event);
- return result;
-}
-
-void destroyHandle () {
- int theControl = handle;
- releaseHandle ();
- if (theControl != 0) {
- OS.DisposeControl (theControl);
- }
-}
-
-void destroyWidget () {
- parent.destroyScrollBar (this);
- releaseHandle ();
- //parent.sendEvent (SWT.Resize);
-}
-
-void enableWidget (boolean enabled) {
- if (enabled) {
- OS.EnableControl (handle);
- } else {
- OS.DisableControl (handle);
- }
-}
-
-void createHandle () {
- int actionProc = display.actionProc;
- int [] outControl = new int [1];
- int window = OS.GetControlOwner (parent.scrolledHandle);
- OS.CreateScrollBarControl (window, null, 0, 0, 90, 10, true, actionProc, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
-}
-
-void createWidget () {
- super.createWidget ();
- setZOrder ();
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (handle);
-}
-
-boolean getDrawing () {
- return parent.getDrawing ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- return (state & DISABLED) == 0;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget();
- return increment;
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget();
- int maximum = OS.GetControl32BitMaximum (handle) & 0x7FFFFFFF;
- int viewSize = OS.GetControlViewSize (handle);
- return maximum + viewSize;
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget();
- return OS.GetControl32BitMinimum (handle) & 0x7FFFFFFF;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget();
- return pageIncrement;
-}
-
-/**
- * Returns the receiver's parent, which must be a Scrollable.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Scrollable getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the single 'selection' that is the receiver's value.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget();
- return OS.GetControl32BitValue (handle) & 0x7FFFFFFF;
-}
-
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- return getControlSize (handle);
-}
-
-/**
- * Returns the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values.
- *
- * @return the thumb value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ScrollBar
- */
-public int getThumb () {
- checkWidget();
- return OS.GetControlViewSize (handle);
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- return (state & HIDDEN) == 0;
-}
-
-int getVisibleRegion (int control, boolean clipChildren) {
- if (visibleRgn == 0) {
- visibleRgn = OS.NewRgn ();
- calculateVisibleRegion (control, visibleRgn, clipChildren);
- }
- int result = OS.NewRgn ();
- OS.CopyRgn (visibleRgn, result);
- return result;
-}
-
-void hookEvents () {
- super.hookEvents ();
- int controlProc = display.controlProc;
- int [] mask = new int [] {
- OS.kEventClassControl, OS.kEventControlTrack,
- };
- int controlTarget = OS.GetControlEventTarget (handle);
- OS.InstallEventHandler (controlTarget, controlProc, mask.length / 2, mask, handle, null);
- if ((parent.state & CANVAS) == 0) {
- oldActionProc = OS.GetControlAction (handle);
- OS.SetControlAction (handle, display.actionProc);
- }
-}
-
-
-void invalidateVisibleRegion (int control) {
- resetVisibleRegion (control);
- parent.resetVisibleRegion (control);
-}
-
-void invalWindowRgn (int window, int rgn) {
- parent.invalWindowRgn (window, rgn);
-}
-
-boolean isDrawing () {
- return getDrawing() && parent.isDrawing();
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-
-boolean isTrimHandle (int trimHandle) {
- return handle == trimHandle;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return getVisible () && parent.isVisible ();
-}
-
-int kEventMouseDown (int nextHandler, int theEvent, int userData) {
- int status = super.kEventMouseDown (nextHandler, theEvent, userData);
- if (status == OS.noErr) return status;
- dragging = false;
- status = OS.CallNextEventHandler (nextHandler, theEvent);
- if (dragging) {
- Event event = new Event ();
- sendEvent (SWT.Selection, event);
- }
- dragging = false;
- return status;
-}
-
-int kEventMouseWheelMoved (int nextHandler, int theEvent, int userData) {
- return parent.kEventMouseWheelMoved (nextHandler, theEvent, userData);
-}
-
-void redraw () {
- redrawWidget (handle, false);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-
-void register () {
- super.register ();
- display.addWidget (handle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- handle = 0;
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (parent.horizontalBar == this) parent.horizontalBar = null;
- if (parent.verticalBar == this) parent.verticalBar = null;
- parent.resizeClientArea ();
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (visibleRgn != 0) OS.DisposeRgn (visibleRgn);
- visibleRgn = 0;
-}
-
-void resetVisibleRegion (int control) {
- if (visibleRgn != 0) {
- OS.DisposeRgn (visibleRgn);
- visibleRgn = 0;
- }
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- increment = value;
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- if (enabled) {
- if ((state & DISABLED) == 0) return;
- state &= ~DISABLED;
- OS.EnableControl (handle);
- } else {
- if ((state & DISABLED) != 0) return;
- state |= DISABLED;
- OS.DisableControl (handle);
- }
-}
-
-/**
- * Sets the maximum. If this value is negative or less than or
- * equal to the minimum, the value is ignored. If necessary, first
- * the thumb and then the selection are adjusted to fit within the
- * new range.
- *
- * @param value the new maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget();
- if (value < 0) return;
- int minimum = OS.GetControl32BitMinimum (handle);
- if (value <= minimum) return;
- int viewSize = OS.GetControlViewSize (handle);
- if (value - minimum < viewSize) {
- viewSize = value - minimum;
- OS.SetControlViewSize (handle, viewSize);
- }
- OS.SetControl32BitMaximum (handle, value - viewSize);
-}
-
-/**
- * Sets the minimum value. If this value is negative or greater
- * than or equal to the maximum, the value is ignored. If necessary,
- * first the thumb and then the selection are adjusted to fit within
- * the new range.
- *
- * @param value the new minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget();
- if (value < 0) return;
- int viewSize = OS.GetControlViewSize (handle);
- int maximum = OS.GetControl32BitMaximum (handle) + viewSize;
- if (value >= maximum) return;
- if (maximum - value < viewSize) {
- viewSize = maximum - value;
- OS.SetControl32BitMaximum (handle, maximum - viewSize);
- OS.SetControlViewSize (handle, viewSize);
- }
- OS.SetControl32BitMinimum (handle, value);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- pageIncrement = value;
-}
-
-/**
- * Sets the single <em>selection</em> that is the receiver's
- * value to the argument which must be greater than or equal
- * to zero.
- *
- * @param selection the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget();
- OS.SetControl32BitValue (handle, value);
-}
-
-/**
- * Sets the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values. This new
- * value will be ignored if it is less than one, and will be
- * clamped if it exceeds the receiver's current range.
- *
- * @param value the new thumb value, which must be at least one and not
- * larger than the size of the current range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setThumb (int value) {
- checkWidget();
- if (value < 1) return;
- int minimum = OS.GetControl32BitMinimum (handle);
- int viewSize = OS.GetControlViewSize (handle);
- int maximum = OS.GetControl32BitMaximum (handle) + viewSize;
- value = Math.min (value, maximum - minimum);
- OS.SetControl32BitMaximum (handle, maximum - value);
- OS.SetControlViewSize (handle, value);
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, thumb, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param thumb the new thumb value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- checkWidget();
- if (minimum < 0) return;
- if (maximum < 0) return;
- if (thumb < 1) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- thumb = Math.min (thumb, maximum - minimum);
- OS.SetControl32BitMinimum (handle, minimum);
- OS.SetControl32BitMaximum (handle, maximum - thumb);
- OS.SetControlViewSize (handle, thumb);
- OS.SetControl32BitValue (handle, selection);
- this.increment = increment;
- this.pageIncrement = pageIncrement;
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget();
- if (visible) {
- if ((state & HIDDEN) == 0) return;
- state &= ~HIDDEN;
- } else {
- if ((state & HIDDEN) != 0) return;
- state |= HIDDEN;
- }
- if (parent.setScrollBarVisible (this, visible)) {
- sendEvent (visible ? SWT.Show : SWT.Hide);
- parent.sendEvent (SWT.Resize);
- }
-}
-
-void setZOrder () {
- OS.HIViewAddSubview (parent.scrolledHandle, handle);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Scrollable.java
deleted file mode 100644
index 482e71323a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Scrollable.java
+++ /dev/null
@@ -1,427 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.CGRect;
-import org.eclipse.swt.internal.carbon.Rect;
-import org.eclipse.swt.internal.carbon.ControlKind;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * This class is the abstract superclass of all classes which
- * represent controls that have standard scroll bars.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>H_SCROLL, V_SCROLL</dd>
- * <dt><b>Events:</b>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public abstract class Scrollable extends Control {
- int scrolledHandle;
- ScrollBar horizontalBar, verticalBar;
-
-Scrollable () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#H_SCROLL
- * @see SWT#V_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Scrollable (Composite parent, int style) {
- super (parent, style);
-}
-
-/**
- * Given a desired <em>client area</em> for the receiver
- * (as described by the arguments), returns the bounding
- * rectangle which would be required to produce that client
- * area.
- * <p>
- * In other words, it returns a rectangle such that, if the
- * receiver's bounds were set to that rectangle, the area
- * of the receiver which is capable of displaying data
- * (that is, not covered by the "trimmings") would be the
- * rectangle described by the arguments (relative to the
- * receiver's parent).
- * </p>
- *
- * @param x the desired x coordinate of the client area
- * @param y the desired y coordinate of the client area
- * @param width the desired width of the client area
- * @param height the desired height of the client area
- * @return the required bounds to produce the given client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getClientArea
- */
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricScrollBarWidth, outMetric);
- if (horizontalBar != null) height += outMetric [0];
- if (verticalBar != null) width += outMetric [0];
- Rect inset = inset ();
- x -= inset.left;
- y -= inset.top;
- width += inset.left + inset.right;
- height += inset.top + inset.bottom;
- return new Rectangle (x, y, width, height);
-}
-
-ScrollBar createScrollBar (int style) {
- return new ScrollBar (this, style);
-}
-
-ScrollBar createStandardBar (int style) {
- int barHandle = findStandardBar (style);
- if (barHandle == 0) return null;
- ScrollBar bar = new ScrollBar ();
- bar.parent = this;
- bar.style = style;
- bar.display = display;
- bar.handle = barHandle;
- bar.register ();
- bar.hookEvents ();
- return bar;
-}
-
-void createWidget () {
- super.createWidget ();
- if ((style & SWT.H_SCROLL) != 0) horizontalBar = createScrollBar (SWT.H_SCROLL);
- if ((style & SWT.V_SCROLL) != 0) verticalBar = createScrollBar (SWT.V_SCROLL);
-}
-
-void deregister () {
- super.deregister ();
- if (scrolledHandle != 0) display.removeWidget (scrolledHandle);
-}
-
-void destroyScrollBar (ScrollBar bar) {
- setScrollBarVisible (bar, false);
- bar.destroyHandle ();
-}
-
-int findStandardBar (int style) {
- int parentHandle = scrolledHandle != 0 ? scrolledHandle : handle;
- short [] count = new short [1];
- OS.CountSubControls (parentHandle, count);
- if (count [0] == 0) return 0;
- int barHandle = 0;
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricScrollBarWidth, outMetric);
- int [] outControl = new int [1];
- ControlKind kind = new ControlKind ();
- int [] property = new int [1];
- for (int i = 0; i < count [0]; i++) {
- OS.GetIndexedSubControl (parentHandle, (short) (i + 1), outControl);
- OS.GetControlKind (outControl [0], kind);
- if (kind.kind == OS.kControlKindScrollBar) {
- property [0] = 0;
- OS.GetControlProperty (outControl [0], Display.SWT0, Display.SWT0, 4, null, property);
- if (property [0] == 0) {
- Point point = getControlSize (outControl [0]);
- if ((style & SWT.H_SCROLL) != 0) {
- if (point.y == outMetric [0]) barHandle = outControl [0];
- } else {
- if (point.x == outMetric [0]) barHandle = outControl [0];
- }
- }
- }
- }
- return barHandle;
-}
-
-public int getBorderWidth () {
- checkWidget();
- if ((state & CANVAS) != 0 && hasBorder ()) {
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricEditTextFrameOutset, outMetric);
- return outMetric [0];
- }
- return 0;
-}
-
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data (that is,
- * not covered by the "trimmings").
- *
- * @return the client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeTrim
- */
-public Rectangle getClientArea () {
- checkWidget();
- Rect rect = new Rect ();
- OS.GetControlBounds (handle, rect);
- return new Rectangle (0, 0, rect.right - rect.left, rect.bottom - rect.top);
-}
-
-/**
- * Returns the receiver's horizontal scroll bar if it has
- * one, and null if it does not.
- *
- * @return the horizontal scroll bar (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ScrollBar getHorizontalBar () {
- checkWidget();
- return horizontalBar;
-}
-
-/**
- * Returns the receiver's vertical scroll bar if it has
- * one, and null if it does not.
- *
- * @return the vertical scroll bar (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ScrollBar getVerticalBar () {
- checkWidget();
- return verticalBar;
-}
-
-void hookEvents () {
- super.hookEvents ();
- if ((state & CANVAS) != 0 && scrolledHandle != 0) {
- int controlProc = display.controlProc;
- int [] mask = new int [] {
- OS.kEventClassControl, OS.kEventControlDraw,
- };
- int controlTarget = OS.GetControlEventTarget (scrolledHandle);
- OS.InstallEventHandler (controlTarget, controlProc, mask.length / 2, mask, scrolledHandle, null);
- }
-}
-
-boolean hooksKeys () {
- return hooks (SWT.KeyDown) || hooks (SWT.KeyUp) || hooks (SWT.Traverse);
-}
-
-Rect inset () {
- if ((state & CANVAS) != 0) {
- Rect rect = new Rect ();
- int [] outMetric = new int [1];
- if (drawFocusRing () && (style & SWT.NO_FOCUS) == 0 && hooksKeys ()) {
- OS.GetThemeMetric (OS.kThemeMetricFocusRectOutset, outMetric);
- rect.left += outMetric [0];
- rect.top += outMetric [0];
- rect.right += outMetric [0];
- rect.bottom += outMetric [0];
- }
- if (hasBorder ()) {
- OS.GetThemeMetric (OS.kThemeMetricEditTextFrameOutset, outMetric);
- rect.left += outMetric [0];
- rect.top += outMetric [0];
- rect.right += outMetric [0];
- rect.bottom += outMetric [0];
- }
- return rect;
- }
- return EMPTY_RECT;
-}
-
-boolean isTrimHandle (int trimHandle) {
- if (horizontalBar != null && horizontalBar.handle == trimHandle) return true;
- if (verticalBar != null && verticalBar.handle == trimHandle) return true;
- return trimHandle == scrolledHandle;
-}
-
-int kEventMouseWheelMoved (int nextHandler, int theEvent, int userData) {
- int vPosition = verticalBar == null ? 0 : verticalBar.getSelection ();
- int hPosition = horizontalBar == null ? 0 : horizontalBar.getSelection ();
- int result = super.kEventMouseWheelMoved (nextHandler, theEvent, userData);
- boolean redraw = false;
- if (verticalBar != null) {
- int position = verticalBar.getSelection ();
- if (position != vPosition) {
- Event event = new Event ();
- event.detail = position < vPosition ? SWT.PAGE_UP : SWT.PAGE_DOWN;
- verticalBar.sendEvent (SWT.Selection, event);
- redraw = true;
- }
- }
- if (horizontalBar != null) {
- int position = horizontalBar.getSelection ();
- if (position != hPosition) {
- Event event = new Event ();
- event.detail = position < hPosition ? SWT.PAGE_UP : SWT.PAGE_DOWN;
- horizontalBar.sendEvent (SWT.Selection, event);
- redraw = true;
- }
- }
- if (redraw) redrawBackgroundImage ();
- return result;
-}
-
-void redrawBackgroundImage () {
- if (scrolledHandle == 0) {
- Control control = findBackgroundControl();
- if (control != null && control.backgroundImage != null) {
- redrawWidget (handle, false);
- }
- }
-}
-
-void register () {
- super.register ();
- if (scrolledHandle != 0) display.addWidget (scrolledHandle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- scrolledHandle = 0;
-}
-
-void releaseChildren (boolean destroy) {
- if (horizontalBar != null) {
- horizontalBar.release (false);
- horizontalBar = null;
- }
- if (verticalBar != null) {
- verticalBar.release (false);
- verticalBar = null;
- }
- super.releaseChildren (destroy);
-}
-
-void resetVisibleRegion (int control) {
- if (verticalBar != null) verticalBar.resetVisibleRegion (control);
- if (horizontalBar != null) horizontalBar.resetVisibleRegion (control);
- super.resetVisibleRegion (control);
-}
-
-void resizeClientArea () {
- if (scrolledHandle == 0) return;
- if ((state & CANVAS) == 0) return;
- int vWidth = 0, hHeight = 0;
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricScrollBarWidth, outMetric);
- boolean isVisibleHBar = horizontalBar != null && horizontalBar.getVisible ();
- boolean isVisibleVBar = verticalBar != null && verticalBar.getVisible ();
- if (isVisibleHBar) hHeight = outMetric [0];
- if (isVisibleVBar) vWidth = outMetric [0];
- int width, height;
- CGRect rect = new CGRect ();
- OS.HIViewGetBounds (scrolledHandle, rect);
- width = (int) rect.width;
- height = (int) rect.height;
- Rect inset = inset ();
- width = Math.max (0, width - vWidth - inset.left - inset.right);
- height = Math.max (0, height - hHeight - inset.top - inset.bottom);
- setBounds (handle, inset.left, inset.top, width, height, true, true, false);
- if (isVisibleHBar) {
- setBounds (horizontalBar.handle, inset.left, inset.top + height, width, hHeight, true, true, false);
- }
- if (isVisibleVBar) {
- setBounds (verticalBar.handle, inset.left + width, inset.top, vWidth, height, true, true, false);
- }
-}
-
-boolean sendMouseWheel (short wheelAxis, int wheelDelta) {
- if ((state & CANVAS) != 0) {
- ScrollBar bar = wheelAxis == OS.kEventMouseWheelAxisX ? horizontalBar : verticalBar;
- if (bar != null && bar.getEnabled ()) {
- bar.setSelection (Math.max (0, bar.getSelection () - bar.getIncrement () * wheelDelta));
- Event event = new Event ();
- event.detail = wheelDelta > 0 ? SWT.PAGE_UP : SWT.PAGE_DOWN;
- bar.sendEvent (SWT.Selection, event);
- return true;
- }
- }
- return false;
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- int result = super.setBounds(x, y, width, height, move, resize, false);
- if ((result & MOVED) != 0) {
- if (events) sendEvent (SWT.Move);
- }
- if ((result & RESIZED) != 0) {
- resizeClientArea ();
- if (events) sendEvent (SWT.Resize);
- }
- return result;
-}
-
-boolean setScrollBarVisible (ScrollBar bar, boolean visible) {
- if (scrolledHandle == 0) return false;
- if ((state & CANVAS) == 0) return false;
- resizeClientArea ();
- setVisible (bar.handle, visible);
- return true;
-}
-
-void setZOrder () {
- super.setZOrder ();
- if (scrolledHandle != 0) OS.HIViewAddSubview (scrolledHandle, handle);
-}
-
-int topHandle () {
- if (scrolledHandle != 0) return scrolledHandle;
- return handle;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Shell.java
deleted file mode 100644
index e81ceaa735..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Shell.java
+++ /dev/null
@@ -1,2037 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.Rect;
-import org.eclipse.swt.internal.carbon.CGPoint;
-import org.eclipse.swt.internal.carbon.CGRect;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent the "windows"
- * which the desktop or "window manager" is managing.
- * Instances that do not have a parent (that is, they
- * are built using the constructor, which takes a
- * <code>Display</code> as the argument) are described
- * as <em>top level</em> shells. Instances that do have
- * a parent are described as <em>secondary</em> or
- * <em>dialog</em> shells.
- * <p>
- * Instances are always displayed in one of the maximized,
- * minimized or normal states:
- * <ul>
- * <li>
- * When an instance is marked as <em>maximized</em>, the
- * window manager will typically resize it to fill the
- * entire visible area of the display, and the instance
- * is usually put in a state where it can not be resized
- * (even if it has style <code>RESIZE</code>) until it is
- * no longer maximized.
- * </li><li>
- * When an instance is in the <em>normal</em> state (neither
- * maximized or minimized), its appearance is controlled by
- * the style constants which were specified when it was created
- * and the restrictions of the window manager (see below).
- * </li><li>
- * When an instance has been marked as <em>minimized</em>,
- * its contents (client area) will usually not be visible,
- * and depending on the window manager, it may be
- * "iconified" (that is, replaced on the desktop by a small
- * simplified representation of itself), relocated to a
- * distinguished area of the screen, or hidden. Combinations
- * of these changes are also possible.
- * </li>
- * </ul>
- * </p><p>
- * The <em>modality</em> of an instance may be specified using
- * style bits. The modality style bits are used to determine
- * whether input is blocked for other shells on the display.
- * The <code>PRIMARY_MODAL</code> style allows an instance to block
- * input to its parent. The <code>APPLICATION_MODAL</code> style
- * allows an instance to block input to every other shell in the
- * display. The <code>SYSTEM_MODAL</code> style allows an instance
- * to block input to all shells, including shells belonging to
- * different applications.
- * </p><p>
- * Note: The styles supported by this class are treated
- * as <em>HINT</em>s, since the window manager for the
- * desktop on which the instance is visible has ultimate
- * control over the appearance and behavior of decorations
- * and modality. For example, some window managers only
- * support resizable windows and will always assume the
- * RESIZE style, even if it is not set. In addition, if a
- * modality style is not supported, it is "upgraded" to a
- * more restrictive modality style that is supported. For
- * example, if <code>PRIMARY_MODAL</code> is not supported,
- * it would be upgraded to <code>APPLICATION_MODAL</code>.
- * A modality style may also be "downgraded" to a less
- * restrictive style. For example, most operating systems
- * no longer support <code>SYSTEM_MODAL</code> because
- * it can freeze up the desktop, so this is typically
- * downgraded to <code>APPLICATION_MODAL</code>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL, SHEET</dd>
- * <dd>APPLICATION_MODAL, MODELESS, PRIMARY_MODAL, SYSTEM_MODAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Activate, Close, Deactivate, Deiconify, Iconify</dd>
- * </dl>
- * Class <code>SWT</code> provides two "convenience constants"
- * for the most commonly required style combinations:
- * <dl>
- * <dt><code>SHELL_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application top level shell: (that
- * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>)
- * </dd>
- * <dt><code>DIALOG_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application dialog shell: (that
- * is, <code>TITLE | CLOSE | BORDER</code>)
- * </dd>
- * </dl>
- * </p>
- * <p>
- * Note: Only one of the styles APPLICATION_MODAL, MODELESS,
- * PRIMARY_MODAL and SYSTEM_MODAL may be specified.
- * </p><p>
- * IMPORTANT: This class is not intended to be subclassed.
- * </p>
- *
- * @see Decorations
- * @see SWT
- * @see <a href="http://www.eclipse.org/swt/snippets/#shell">Shell snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class Shell extends Decorations {
- int shellHandle, windowGroup;
- boolean resized, moved, drawing, reshape, update, deferDispose, active, disposed, opened, fullScreen, center;
- boolean showWithParent, ignoreBounds;
- int invalRgn;
- Control lastActive;
- Rect rgnRect;
- Rectangle normalBounds;
- int imHandle;
- ToolTip [] toolTips;
-
- static int DEFAULT_CLIENT_WIDTH = -1;
- static int DEFAULT_CLIENT_HEIGHT = -1;
-
-/**
- * Constructs a new instance of this class. This is equivalent
- * to calling <code>Shell((Display) null)</code>.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell () {
- this ((Display) null);
-}
-
-/**
- * Constructs a new instance of this class given only the style
- * value describing its behavior and appearance. This is equivalent
- * to calling <code>Shell((Display) null, style)</code>.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#TOOL
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (int style) {
- this ((Display) null, style);
-}
-
-/**
- * Constructs a new instance of this class given only the display
- * to create it on. It is created with style <code>SWT.SHELL_TRIM</code>.
- * <p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the shell on
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell (Display display) {
- this (display, SWT.SHELL_TRIM);
-}
-
-/**
- * Constructs a new instance of this class given the display
- * to create it on and a style value describing its behavior
- * and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the shell on
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#TOOL
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (Display display, int style) {
- this (display, null, style, 0, false);
-}
-
-Shell (Display display, Shell parent, int style, int handle, boolean embedded) {
- super ();
- checkSubclass ();
- if (display == null) display = Display.getCurrent ();
- if (display == null) display = Display.getDefault ();
- if (!display.isValidThread ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- if (parent != null && parent.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.center = parent != null && (style & SWT.SHEET) != 0;
- this.style = checkStyle (parent, style);
- this.parent = parent;
- this.display = display;
- if (handle != 0) {
- if (embedded) {
- this.handle = handle;
- } else {
- shellHandle = handle;
- state |= FOREIGN_HANDLE;
- }
- }
- createWidget ();
-}
-
-/**
- * Constructs a new instance of this class given only its
- * parent. It is created with style <code>SWT.DIALOG_TRIM</code>.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the parent is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell (Shell parent) {
- this (parent, SWT.DIALOG_TRIM);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the parent is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#TOOL
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (Shell parent, int style) {
- this (parent != null ? parent.display : null, parent, style, 0, false);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new shell
- * that is not embedded.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Shell</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param display the display for the shell
- * @param handle the handle for the shell
- * @return a new shell object containing the specified display and handle
- *
- * @since 3.3
- */
-public static Shell internal_new (Display display, int handle) {
- return new Shell (display, null, SWT.NO_TRIM, handle, false);
-}
-
-static int checkStyle (Shell parent, int style) {
- style = Decorations.checkStyle (style);
- style &= ~SWT.TRANSPARENT;
- int mask = SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.PRIMARY_MODAL;
- if ((style & SWT.SHEET) != 0) {
- style &= ~SWT.SHEET;
- style |= parent == null ? SWT.SHELL_TRIM : SWT.DIALOG_TRIM;
- if ((style & mask) == 0) {
- style |= parent == null ? SWT.APPLICATION_MODAL : SWT.PRIMARY_MODAL;
- }
- }
- int bits = style & ~mask;
- if ((style & SWT.SYSTEM_MODAL) != 0) return bits | SWT.SYSTEM_MODAL;
- if ((style & SWT.APPLICATION_MODAL) != 0) return bits | SWT.APPLICATION_MODAL;
- if ((style & SWT.PRIMARY_MODAL) != 0) return bits | SWT.PRIMARY_MODAL;
- return bits;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when operations are performed on the receiver,
- * by sending the listener one of the messages defined in the
- * <code>ShellListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ShellListener
- * @see #removeShellListener
- */
-public void addShellListener(ShellListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.Activate,typedListener);
- addListener(SWT.Close,typedListener);
- addListener(SWT.Deactivate,typedListener);
- addListener(SWT.Iconify,typedListener);
- addListener(SWT.Deiconify,typedListener);
-}
-
-void addToolTip (ToolTip toolTip) {
- if (toolTips == null) toolTips = new ToolTip [4];
- for (int i=0; i<toolTips.length; i++) {
- if (toolTips [i] == null) {
- toolTips [i] = toolTip;
- return;
- }
- }
- ToolTip [] newToolTips = new ToolTip [toolTips.length + 4];
- newToolTips [toolTips.length] = toolTip;
- System.arraycopy (toolTips, 0, newToolTips, 0, toolTips.length);
- toolTips = newToolTips;
-}
-
-void bringToTop (boolean force) {
- if (getMinimized ()) return;
- if (force) {
- forceActive ();
- } else {
- setActive ();
- }
-}
-
-void center () {
- if (parent == null) return;
- Rectangle rect = getBounds ();
- Rectangle parentRect = display.map (parent, null, parent.getClientArea());
- int x = Math.max (parentRect.x, parentRect.x + (parentRect.width - rect.width) / 2);
- int y = Math.max (parentRect.y, parentRect.y + (parentRect.height - rect.height) / 2);
- Rectangle monitorRect = parent.getMonitor ().getClientArea();
- if (x + rect.width > monitorRect.x + monitorRect.width) {
- x = Math.max (monitorRect.x, monitorRect.x + monitorRect.width - rect.width);
- } else {
- x = Math.max (x, monitorRect.x);
- }
- if (y + rect.height > monitorRect.y + monitorRect.height) {
- y = Math.max (monitorRect.y, monitorRect.y + monitorRect.height - rect.height);
- } else {
- y = Math.max (y, monitorRect.y);
- }
- setLocation (x, y);
-}
-
-void checkOpen () {
- if (!opened) resized = false;
-}
-
-/**
- * Requests that the window manager close the receiver in
- * the same way it would be closed when the user clicks on
- * the "close box" or performs some other platform specific
- * key or mouse combination that indicates the window
- * should be removed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#Close
- * @see #dispose
- */
-public void close () {
- checkWidget();
- closeWidget ();
-}
-
-void closeWidget () {
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- if (event.doit && !isDisposed ()) dispose ();
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- Rectangle trim = super.computeTrim (x, y, width, height);
- Rect rect = new Rect ();
- OS.GetWindowStructureWidths (shellHandle, rect);
- trim.x -= rect.left;
- trim.y -= rect.top;
- trim.width += rect.left + rect.right;
- trim.height += rect.top + rect.bottom;
- return trim;
-}
-
-void createHandle () {
- state |= CANVAS | GRAB | HIDDEN;
- int attributes = OS.kWindowStandardHandlerAttribute;
- attributes |= OS.kWindowCompositingAttribute;
- if ((style & SWT.NO_TRIM) == 0) {
- if ((style & SWT.CLOSE) != 0) attributes |= OS.kWindowCloseBoxAttribute;
- if ((style & SWT.MIN) != 0) attributes |= OS.kWindowCollapseBoxAttribute;
- if ((style & SWT.MAX) != 0) attributes |= OS.kWindowFullZoomAttribute;
- if ((style & SWT.RESIZE) != 0) {
- attributes |= OS.kWindowResizableAttribute;
- /*
- * Bug in the Macintosh. For some reason, a window has no title bar
- * and the kWindowResizableAttribute, no rubber banding feedback is
- * given while the window is resizing. The fix is to create the window
- * with kWindowLiveResizeAttribute in this case. This is inconsistent
- * with other windows, but the user will get feedback when resizing.
- */
- if ((style & SWT.TITLE) == 0) attributes |= OS.kWindowLiveResizeAttribute;
- if (!OS.__BIG_ENDIAN__()) attributes |= OS.kWindowLiveResizeAttribute;
- }
- } else {
- if ((style & SWT.TOOL) == 0) attributes |= OS.kWindowNoShadowAttribute;
- }
- int windowClass = OS.kDocumentWindowClass;
- if ((style & (SWT.CLOSE | SWT.TITLE)) == 0) windowClass = OS.kSheetWindowClass;
- if ((style & (SWT.APPLICATION_MODAL | SWT.PRIMARY_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- if ((style & (SWT.CLOSE | SWT.MAX | SWT.MIN)) == 0) {
- windowClass = (style & SWT.TITLE) != 0 ? OS.kMovableModalWindowClass : OS.kModalWindowClass;
- }
- }
- if (shellHandle == 0) {
- Monitor monitor = getMonitor ();
- Rectangle rect = monitor.getClientArea ();
- int width = rect.width * 5 / 8;
- int height = rect.height * 5 / 8;
- Rect bounds = new Rect ();
- OS.SetRect (bounds, (short) 0, (short) 0, (short) width, (short) height);
- int [] outWindow = new int [1];
- attributes &= OS.GetAvailableWindowAttributes (windowClass);
- OS.CreateNewWindow (windowClass, attributes, bounds, outWindow);
- if (outWindow [0] == 0) error (SWT.ERROR_NO_HANDLES);
- shellHandle = outWindow [0];
- OS.RepositionWindow (shellHandle, 0, OS.kWindowCascadeOnMainScreen);
-// OS.SetThemeWindowBackground (shellHandle, (short) OS.kThemeBrushDialogBackgroundActive, false);
- int [] theRoot = new int [1];
- OS.HIViewFindByID (OS.HIViewGetRoot (shellHandle), OS.kHIViewWindowContentID (), theRoot);
- /*
- * Bug in the Macintosh. When the window class is kMovableModalWindowClass or
- * kModalWindowClass, HIViewFindByID() fails to find the control identified by
- * kHIViewWindowContentID. The fix is to call GetRootControl() if the call
- * failed.
- */
- if (theRoot [0] == 0) OS.GetRootControl (shellHandle, theRoot);
- if (theRoot [0] == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) {
- createScrolledHandle (theRoot [0]);
- } else {
- createHandle (theRoot [0]);
- }
- OS.SetControlVisibility (topHandle (), false, false);
- } else {
- int [] theRoot = new int [1];
- OS.HIViewFindByID (shellHandle, OS.kHIViewWindowContentID (), theRoot);
- if (theRoot [0] == 0) OS.GetRootControl (shellHandle, theRoot);
- handle = OS.HIViewGetFirstSubview (theRoot [0]);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if (OS.IsWindowVisible (shellHandle)) state &= ~HIDDEN;
- }
- int [] outGroup = new int [1];
- OS.CreateWindowGroup (OS.kWindowGroupAttrHideOnCollapse, outGroup);
- if (outGroup [0] == 0) error (SWT.ERROR_NO_HANDLES);
- windowGroup = outGroup [0];
- int parentGroup;
- if ((style & SWT.ON_TOP) != 0) {
- parentGroup = OS.GetWindowGroupOfClass (OS.kFloatingWindowClass);
- } else {
- if (parent != null) {
- parentGroup = parent.getShell ().windowGroup;
- } else {
- parentGroup = OS.GetWindowGroupOfClass (OS.kDocumentWindowClass);
- }
- }
- OS.SetWindowGroup (shellHandle, parentGroup);
- OS.SetWindowGroupParent (windowGroup, parentGroup);
- OS.SetWindowGroupOwner (windowGroup, shellHandle);
- CGPoint inMinLimits = new CGPoint (), inMaxLimits = new CGPoint ();
- OS.GetWindowResizeLimits (shellHandle, inMinLimits, inMaxLimits);
- if (DEFAULT_CLIENT_WIDTH == -1) DEFAULT_CLIENT_WIDTH = (int) inMinLimits.x;
- if (DEFAULT_CLIENT_HEIGHT == -1) DEFAULT_CLIENT_HEIGHT = 0;
- inMinLimits.y = (int) 0;
- int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX;
- if ((style & SWT.NO_TRIM) != 0 || (style & trim) == 0) {
- inMinLimits.x = (int) 0;
- }
- OS.SetWindowResizeLimits (shellHandle, inMinLimits, inMaxLimits);
- int [] docID = new int [1];
- OS.NewTSMDocument ((short)1, new int [] {OS.kUnicodeDocument}, docID, 0);
- if (docID [0] == 0) error (SWT.ERROR_NO_HANDLES);
- imHandle = docID [0];
-}
-
-void createWidget () {
- super.createWidget ();
- resizeBounds ();
-}
-
-void deregister () {
- super.deregister ();
- int [] theRoot = new int [1];
- OS.GetRootControl (shellHandle, theRoot);
- display.removeWidget (theRoot [0]);
-}
-
-void destroyWidget () {
- int theWindow = shellHandle;
- /*
- * Bug in the Macintosh. Under certain circumstances, yet to
- * be determined, calling HideWindow() and then DisposeWindow()
- * causes a segment fault when an application is exiting. This
- * seems to happen to large applications. The fix is to avoid
- * calling HideWindow() when a shell is about to be disposed.
- *
- * Bug in the Macintosh. Disposing a window from kEventWindowDeactivated
- * causes a segment fault. The fix is to defer disposing the window until
- * the event loop becomes idle.
- */
- Display display = this.display;
- Composite parent = this.parent;
- while (!deferDispose && parent != null) {
- Shell shell = parent.getShell ();
- deferDispose = shell.deferDispose;
- parent = shell.parent;
- }
- if (deferDispose) OS.HideWindow (shellHandle);
- releaseHandle ();
- if (theWindow != 0) {
- if (deferDispose) {
- display.addDisposeWindow (theWindow);
- } else {
- OS.DisposeWindow (theWindow);
- }
- }
-}
-
-void drawWidget (int control, int context, int damageRgn, int visibleRgn, int theEvent) {
- super.drawWidget (control, context, damageRgn, visibleRgn, theEvent);
-
- /*
- * Bug in the Macintosh. In kEventWindowGetRegion,
- * Carbon assumes the origin of the Region is (0, 0)
- * and ignores the actual origin. This causes the
- * window to be shifted for a non zero origin. Also,
- * the size of the window is the size of the region
- * which may be less then the size specified in
- * setSize or setBounds.
- * The fix is to include (0, 0) and the bottom
- * right corner of the size in the region and to
- * make these points transparent.
- */
- if (region == null || region.isDisposed ()) return;
- boolean origin = region.contains (0, 0);
- boolean limit = region.contains(rgnRect.right - 1, rgnRect.bottom - 1);
- if (origin && limit) return;
-
- CGRect cgRect = new CGRect ();
- cgRect.width = 1;
- cgRect.height = 1;
- if (!origin) {
- OS.CGContextClearRect (context, cgRect);
- }
- if (!limit) {
- cgRect.x = rgnRect.right - 1;
- cgRect.y = rgnRect.bottom - 1;
- OS.CGContextClearRect (context, cgRect);
- }
- OS.CGContextSynchronize (context);
-}
-
-Control findBackgroundControl () {
- return background != null || backgroundImage != null ? this : null;
-}
-
-Composite findDeferredControl () {
- return layoutCount > 0 ? this : null;
-}
-
-Cursor findCursor () {
- return cursor;
-}
-
-void fixShell (Shell newShell, Control control) {
- if (this == newShell) return;
- if (control == lastActive) setActiveControl (null);
-}
-
-/**
- * If the receiver is visible, moves it to the top of the
- * drawing order for the display on which it was created
- * (so that all other shells on that display, which are not
- * the receiver's children will be drawn behind it) and forces
- * the window manager to make the shell active.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#open
- * @see Shell#setActive
- */
-public void forceActive () {
- checkWidget ();
- if (!isVisible ()) return;
- OS.SelectWindow (shellHandle);
- OS.SetUserFocusWindow (shellHandle);
- OS.SetFrontProcessWithOptions (new int [] {0, OS.kCurrentProcess}, OS.kSetFrontProcessFrontWindowOnly);
-}
-
-/**
- * Returns the receiver's alpha value. The alpha value
- * is between 0 (transparent) and 255 (opaque).
- *
- * @return the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public int getAlpha () {
- checkWidget ();
- float [] alpha = new float [1];
- if (OS.GetWindowAlpha (shellHandle, alpha) == OS.noErr) {
- return (int)(alpha [0] * 255);
- }
- return 0xFF;
-}
-
-public Rectangle getBounds () {
- checkWidget();
- Rect rect = new Rect ();
- OS.GetWindowBounds (shellHandle, (short) OS.kWindowStructureRgn, rect);
- return new Rectangle (rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
-}
-
-/**
- * Returns <code>true</code> if the receiver is currently
- * in fullscreen state, and false otherwise.
- * <p>
- *
- * @return the fullscreen state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getFullScreen () {
- checkWidget();
- return fullScreen;
-}
-
-/**
- * Returns the receiver's input method editor mode. This
- * will be the result of bitwise OR'ing together one or
- * more of the following constants defined in class
- * <code>SWT</code>:
- * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>,
- * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>.
- *
- * @return the IME mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public int getImeInputMode () {
- checkWidget();
- return SWT.NONE;
-}
-
-public Point getLocation () {
- checkWidget();
- Rect rect = new Rect ();
- OS.GetWindowBounds (shellHandle, (short) OS.kWindowStructureRgn, rect);
- return new Point (rect.left, rect.top);
-}
-
-public boolean getMaximized () {
- checkWidget();
- //NOT DONE
- return !fullScreen && super.getMaximized ();
-}
-
-public boolean getMinimized () {
- checkWidget();
- if (!getVisible ()) return super.getMinimized ();
- return OS.IsWindowCollapsed (shellHandle);
-}
-
-/**
- * Returns a point describing the minimum receiver's size. The
- * x coordinate of the result is the minimum width of the receiver.
- * The y coordinate of the result is the minimum height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Point getMinimumSize () {
- checkWidget();
- Rect rect = new Rect ();
- OS.GetWindowStructureWidths (shellHandle, rect);
- CGPoint inMinLimits = new CGPoint (), inMaxLimits = new CGPoint ();
- OS.GetWindowResizeLimits (shellHandle, inMinLimits, inMaxLimits);
- int width = Math.max (1, (int) inMinLimits.x + (rect.left + rect.right));
- int height = Math.max (1, (int) inMinLimits.y + (rect.top + rect.bottom));
- return new Point (width, height);
-}
-
-Shell getModalShell () {
- Shell shell = null;
- Shell [] modalShells = display.modalShells;
- if (modalShells != null) {
- int bits = SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- int index = modalShells.length;
- while (--index >= 0) {
- Shell modal = modalShells [index];
- if (modal != null) {
- if ((modal.style & bits) != 0) {
- Control control = this;
- while (control != null) {
- if (control == modal) break;
- control = control.parent;
- }
- if (control != modal) return modal;
- break;
- }
- if ((modal.style & SWT.PRIMARY_MODAL) != 0) {
- if (shell == null) shell = getShell ();
- if (modal.parent == shell) return modal;
- }
- }
- }
- }
- return null;
-}
-
-/**
- * Gets the receiver's modified state.
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.5
- */
-public boolean getModified () {
- checkWidget ();
- return OS.IsWindowModified (shellHandle);
-}
-
-
-float [] getParentBackground () {
- return null;
-}
-
-/**
- * Returns the region that defines the shape of the shell,
- * or null if the shell has the default shape.
- *
- * @return the region that defines the shape of the shell (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public Region getRegion () {
- /* This method is needed for the @since 3.0 Javadoc */
- checkWidget ();
- return region;
-}
-
-public Shell getShell () {
- checkWidget();
- return this;
-}
-
-/**
- * Returns an array containing all shells which are
- * descendants of the receiver.
- * <p>
- * @return the dialog shells
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Shell [] getShells () {
- checkWidget();
- int count = 0;
- Shell [] shells = display.getShells ();
- for (int i=0; i<shells.length; i++) {
- Control shell = shells [i];
- do {
- shell = shell.parent;
- } while (shell != null && shell != this);
- if (shell == this) count++;
- }
- int index = 0;
- Shell [] result = new Shell [count];
- for (int i=0; i<shells.length; i++) {
- Control shell = shells [i];
- do {
- shell = shell.parent;
- } while (shell != null && shell != this);
- if (shell == this) {
- result [index++] = shells [i];
- }
- }
- return result;
-}
-
-public Point getSize () {
- checkWidget();
- Rect rect = new Rect ();
- OS.GetWindowBounds (shellHandle, (short) OS.kWindowStructureRgn, rect);
- return new Point (rect.right - rect.left, rect.bottom - rect.top);
-}
-
-float getThemeAlpha () {
- return 1;
-}
-
-boolean hasBorder () {
- return false;
-}
-
-void hookEvents () {
- super.hookEvents ();
- int mouseProc = display.mouseProc;
- int windowProc = display.windowProc;
- int[] mask1 = new int [] {
- OS.kEventClassWindow, OS.kEventWindowActivated,
- OS.kEventClassWindow, OS.kEventWindowBoundsChanged,
- OS.kEventClassWindow, OS.kEventWindowClose,
- OS.kEventClassWindow, OS.kEventWindowCollapsing,
- OS.kEventClassWindow, OS.kEventWindowCollapsed,
- OS.kEventClassWindow, OS.kEventWindowDeactivated,
- OS.kEventClassWindow, OS.kEventWindowDrawContent,
- OS.kEventClassWindow, OS.kEventWindowExpanded,
- OS.kEventClassWindow, OS.kEventWindowGetRegion,
- OS.kEventClassWindow, OS.kEventWindowHidden,
- OS.kEventClassWindow, OS.kEventWindowHitTest,
- OS.kEventClassWindow, OS.kEventWindowShown,
- OS.kEventClassWindow, OS.kEventWindowUpdate,
- OS.kEventClassWindow, OS.kEventWindowGetClickModality,
- };
- int windowTarget = OS.GetWindowEventTarget (shellHandle);
- OS.InstallEventHandler (windowTarget, windowProc, mask1.length / 2, mask1, shellHandle, null);
- int [] mask2 = new int [] {
- OS.kEventClassMouse, OS.kEventMouseDown,
- OS.kEventClassMouse, OS.kEventMouseDragged,
-// OS.kEventClassMouse, OS.kEventMouseEntered,
-// OS.kEventClassMouse, OS.kEventMouseExited,
- OS.kEventClassMouse, OS.kEventMouseMoved,
- OS.kEventClassMouse, OS.kEventMouseUp,
- OS.kEventClassMouse, OS.kEventMouseWheelMoved,
- };
- OS.InstallEventHandler (windowTarget, mouseProc, mask2.length / 2, mask2, shellHandle, null);
-}
-
-void invalidateVisibleRegion (int control) {
- resetVisibleRegion (control);
- invalidateChildrenVisibleRegion (control);
-}
-
-void invalWindowRgn (int window, int rgn) {
- display.needsPaint = true;
- if (invalRgn == 0) invalRgn = OS.NewRgn();
- OS.UnionRgn (rgn, invalRgn, invalRgn);
-}
-
-boolean isDrawing () {
- return getDrawing ();
-}
-
-public boolean isEnabled () {
- checkWidget();
- return getEnabled ();
-}
-
-boolean isEnabledCursor () {
- return true;
-}
-
-public boolean isVisible () {
- checkWidget();
- return getVisible ();
-}
-
-int kEventWindowActivated (int nextHandler, int theEvent, int userData) {
- int result = super.kEventWindowActivated (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- /*
- * Bug in the Macintosh. Despite the that a window has scope
- * kWindowActivationScopeNone, it gets kEventWindowActivated
- * events but does not get kEventWindowDeactivated events. The
- * fix is to ignore kEventWindowActivated events.
- */
- int [] outScope = new int [1];
- OS.GetWindowActivationScope (shellHandle, outScope);
- if (outScope [0] == OS.kWindowActivationScopeNone) return result;
- if (!active) {
- active = true;
- deferDispose = true;
- Display display = this.display;
- display.activeShell = this;
- display.setMenuBar (menuBar);
- if (menuBar != null) OS.DrawMenuBar ();
- sendEvent (SWT.Activate);
- if (isDisposed ()) return result;
- if (!restoreFocus () && !traverseGroup (true)) setFocus ();
- if (isDisposed ()) return result;
- display.activeShell = null;
- Shell parentShell = this;
- while (parentShell.parent != null) {
- parentShell = (Shell) parentShell.parent;
- if (parentShell.fullScreen) {
- break;
- }
- }
- if (!parentShell.fullScreen || menuBar != null) {
- updateSystemUIMode ();
- } else {
- parentShell.updateSystemUIMode ();
- }
- deferDispose = false;
- }
- return result;
-}
-
-int kEventWindowBoundsChanged (int nextHandler, int theEvent, int userData) {
- int result = super.kEventWindowBoundsChanged (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- int [] attributes = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamAttributes, OS.typeUInt32, null, attributes.length * 4, null, attributes);
- if ((attributes [0] & OS.kWindowBoundsChangeOriginChanged) != 0) {
- if (!ignoreBounds) {
- moved = true;
- sendEvent (SWT.Move);
- if (isDisposed ()) return OS.noErr;
- }
- }
- if ((attributes [0] & OS.kWindowBoundsChangeSizeChanged) != 0) {
- resizeBounds ();
- if (!ignoreBounds) {
- resized = true;
- sendEvent (SWT.Resize);
- if (isDisposed ()) return OS.noErr;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
- }
- if (region != null && !region.isDisposed()) {
- OS.GetEventParameter (theEvent, OS.kEventParamCurrentBounds, OS.typeQDRectangle, null, Rect.sizeof, null, rgnRect);
- OS.SetRect (rgnRect, (short) 0, (short) 0, (short) (rgnRect.right - rgnRect.left), (short) (rgnRect.bottom - rgnRect.top));
- OS.ReshapeCustomWindow (shellHandle);
- }
- }
- return result;
-}
-
-int kEventWindowClose (int nextHandler, int theEvent, int userData) {
- int result = super.kEventWindowClose (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- if (isEnabled ()) closeWidget ();
- return OS.noErr;
-}
-
-int kEventWindowCollapsed (int nextHandler, int theEvent, int userData) {
- int result = super.kEventWindowCollapsed (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- minimized = true;
- sendEvent (SWT.Iconify);
- return result;
-}
-
-int kEventWindowCollapsing (int nextHandler, int theEvent, int userData) {
- int result = super.kEventWindowCollapsing (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- updateMinimized (true);
- return result;
-}
-
-int kEventWindowDeactivated (int nextHandler, int theEvent, int userData) {
- int result = super.kEventWindowDeactivated (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- if (active) {
- active = false;
- deferDispose = true;
- Display display = this.display;
- display.activeShell = this;
- sendEvent (SWT.Deactivate);
- if (isDisposed ()) return result;
- setActiveControl (null);
- if (isDisposed ()) return result;
- display.activeShell = null;
- saveFocus ();
- if (savedFocus != null) {
- /*
- * Bug in the Macintosh. When ClearKeyboardFocus() is called,
- * the control that has focus gets two kEventControlSetFocus
- * events indicating that focus was lost. The fix is to ignore
- * both of these and send the focus lost event explicitly.
- */
- display.ignoreFocus = true;
- OS.ClearKeyboardFocus (shellHandle);
- display.ignoreFocus = false;
- if (!savedFocus.isDisposed ()) savedFocus.sendFocusEvent (SWT.FocusOut, false);
- }
- display.setMenuBar (null);
- deferDispose = false;
- }
- return result;
-}
-
-int kEventWindowDrawContent (int nextHandler, int theEvent, int userData) {
- drawing = true;
- int result = OS.CallNextEventHandler (nextHandler, theEvent);
- drawing = false;
- if (reshape) {
- reshape = false;
- OS.ReshapeCustomWindow (shellHandle);
- }
- return result;
-}
-
-int kEventWindowExpanded (int nextHandler, int theEvent, int userData) {
- int result = super.kEventWindowExpanded (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- minimized = false;
- updateMinimized (false);
- sendEvent (SWT.Deiconify);
- return result;
-}
-
-int kEventWindowGetClickModality (int nextHandler, int theEvent, int userData) {
- /*
- * Bug in the Macintosh. When the user clicks in an Expose window that is
- * disabled because of a modal dialog, the modal dialog does not come to
- * front and is obscured by the Expose window. The fix is to select the
- * modal dialog.
- */
- int result = OS.CallNextEventHandler (nextHandler, theEvent);
- int [] modal = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamModalWindow, OS.typeWindowRef, null, 4, null, modal);
- if (modal [0] != 0) OS.SelectWindow (modal [0]);
-
- /*
- * Feature in the Macintosh. ON_TOP shells are in the kFloatingWindowClass window
- * group and are not modal disabled by default. The fix is to detect that it should
- * be disabled and update the event parameters.
- *
- * Bug in Macintosh. When a kWindowModalityWindowModal window is active the
- * default handler of kEventWindowGetClickModality does not properly set the
- * kEventParamModalClickResult. The fix is to set it ourselves.
- */
- Shell modalShell = getModalShell ();
- if (modalShell != null) {
- int [] modality = new int [1];
- OS.GetWindowModality (modalShell.shellHandle, modality, null);
- if ((style & SWT.ON_TOP) != 0 || modality [0] == OS.kWindowModalityWindowModal) {
- int clickResult = OS.kHIModalClickIsModal | OS.kHIModalClickAnnounce;
- OS.SetEventParameter (theEvent, OS.kEventParamWindowModality, OS.typeWindowModality, 4, modality);
- OS.SetEventParameter (theEvent, OS.kEventParamModalClickResult, OS.typeModalClickResult, 4, new int[]{clickResult});
- OS.SetEventParameter (theEvent, OS.kEventParamModalWindow, OS.typeWindowRef, 4, new int[]{modalShell.shellHandle});
- }
- }
- return result;
-}
-
-int kEventWindowGetRegion (int nextHandler, int theEvent, int userData) {
- int result = super.kEventWindowGetRegion (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- if (region == null || region.isDisposed ()) return OS.eventNotHandledErr;
- short [] regionCode = new short [1];
- OS.GetEventParameter (theEvent, OS.kEventParamWindowRegionCode, OS.typeWindowRegionCode , null, 2, null, regionCode);
- int [] temp = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamRgnHandle, OS.typeQDRgnHandle , null, 4, null, temp);
- int hRegion = temp [0];
- switch (regionCode [0]) {
- case OS.kWindowContentRgn:
- case OS.kWindowStructureRgn:
- OS.RectRgn (hRegion, rgnRect);
- OS.SectRgn (hRegion, region.handle, hRegion);
- /*
- * Bug in the Macintosh. In kEventWindowGetRegion,
- * Carbon assumes the origin of the Region is (0, 0)
- * and ignores the actual origin. This causes the
- * window to be shifted for a non zero origin. Also,
- * the size of the window is the size of the region
- * which may be less then the size specified in
- * setSize or setBounds.
- * The fix is to include (0, 0) and the bottom
- * right corner of the size in the region and to
- * make these points transparent.
- */
- if (!region.contains (0, 0)) {
- Rect r = new Rect ();
- OS.SetRect (r, (short)0, (short)0, (short)1, (short)1);
- int rectRgn = OS.NewRgn ();
- OS.RectRgn (rectRgn, r);
- OS.UnionRgn (rectRgn, hRegion, hRegion);
- OS.DisposeRgn (rectRgn);
- }
- if (!region.contains (rgnRect.right - 1, rgnRect.bottom - 1)) {
- Rect r = new Rect ();
- OS.SetRect (r, (short) (rgnRect.right - 1), (short) (rgnRect.bottom - 1), rgnRect.right, rgnRect.bottom);
- int rectRgn = OS.NewRgn ();
- OS.RectRgn (rectRgn, r);
- OS.UnionRgn (rectRgn, hRegion, hRegion);
- OS.DisposeRgn (rectRgn);
- }
- return OS.noErr;
- default:
- OS.DiffRgn (hRegion, hRegion, hRegion);
- return OS.noErr;
- }
-}
-
-int kEventWindowHidden (int nextHandler, int theEvent, int userData) {
- int result = super.kEventWindowHidden (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) shell.setWindowVisible (false);
- }
- return OS.eventNotHandledErr;
-}
-
-int kEventWindowHitTest (int nextHandler, int theEvent, int userData) {
- int result = super.kEventWindowHitTest (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- if (region == null || region.isDisposed ()) return OS.eventNotHandledErr;
- org.eclipse.swt.internal.carbon.Point pt = new org.eclipse.swt.internal.carbon.Point ();
- int sizeof = org.eclipse.swt.internal.carbon.Point.sizeof;
- OS.GetEventParameter (theEvent, OS.kEventParamMouseLocation, OS.typeQDPoint, null, sizeof, null, pt);
- Rect rect = new Rect ();
- OS.GetWindowBounds (shellHandle, (short) OS.kWindowContentRgn, rect);
- OS.SetPt (pt, (short) (pt.h - rect.left), (short) (pt.v - rect.top));
- int rgn = OS.NewRgn ();
- OS.RectRgn (rgn, rgnRect);
- OS.SectRgn (rgn, region.handle, rgn);
- short inData = OS.PtInRgn (pt, rgn) ? OS.wInContent: OS.wNoHit;
- OS.DisposeRgn (rgn);
- OS.SetEventParameter (theEvent, OS.kEventParamWindowDefPart, OS.typeWindowDefPartCode, 2, new short [] {inData});
- return OS.noErr;
-}
-
-int kEventWindowShown (int nextHandler, int theEvent, int userData) {
- int result = super.kEventWindowShown (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- invalidateVisibleRegion (topHandle ());
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed () && shell.getVisible ()) {
- shell.setWindowVisible (true);
- }
- }
- return OS.eventNotHandledErr;
-}
-
-int kEventWindowUpdate (int nextHandler, int theEvent, int userData) {
- update = true;
- int result = OS.CallNextEventHandler (nextHandler, theEvent);
- update = false;
- if (invalRgn != 0) {
- OS.InvalWindowRgn (shellHandle, invalRgn);
- OS.DisposeRgn (invalRgn);
- invalRgn = 0;
- }
- return result;
-}
-
-void resizeBounds () {
- Rect rect = new Rect ();
- OS.GetWindowBounds (shellHandle, (short) OS.kWindowContentRgn, rect);
- int control = scrolledHandle != 0 ? scrolledHandle : handle;
- setBounds (control, 0, 0, rect.right - rect.left, rect.bottom - rect.top, false, true, false);
- resizeClientArea ();
-}
-
-/**
- * Moves the receiver to the top of the drawing order for
- * the display on which it was created (so that all other
- * shells on that display, which are not the receiver's
- * children will be drawn behind it), marks it visible,
- * sets the focus and asks the window manager to make the
- * shell active.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#setActive
- * @see Shell#forceActive
- */
-public void open () {
- checkWidget();
- bringToTop (false);
- setVisible (true);
- if (isDisposed ()) return;
- if (active) {
- if (!restoreFocus () && !traverseGroup (true)) setFocus ();
- }
-}
-
-public boolean print (GC gc) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- return false;
-}
-
-void register () {
- super.register ();
- int [] theRoot = new int [1];
- OS.GetRootControl (shellHandle, theRoot);
- display.addWidget (theRoot [0], this);
-}
-
-void releaseChildren (boolean destroy) {
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (shell != null && !shell.isDisposed ()) {
- shell.dispose ();
- }
- }
- if (toolTips != null) {
- for (int i=0; i<toolTips.length; i++) {
- ToolTip toolTip = toolTips [i];
- if (toolTip != null && !toolTip.isDisposed ()) {
- toolTip.dispose ();
- }
- }
- toolTips = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- shellHandle = 0;
-}
-
-void releaseParent () {
- /* Do nothing */
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- display.clearModal (this);
- disposed = true;
- if (windowGroup != 0) OS.ReleaseWindowGroup (windowGroup);
- display.updateQuitMenu ();
- if (invalRgn != 0) OS.DisposeRgn (invalRgn);
- if (imHandle != 0) OS.DeleteTSMDocument (imHandle);
- imHandle = invalRgn = windowGroup = 0;
- lastActive = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when operations are performed on the receiver.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ShellListener
- * @see #addShellListener
- */
-public void removeShellListener(ShellListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Activate, listener);
- eventTable.unhook(SWT.Close, listener);
- eventTable.unhook(SWT.Deactivate, listener);
- eventTable.unhook(SWT.Iconify,listener);
- eventTable.unhook(SWT.Deiconify,listener);
-}
-
-void removeTooTip (ToolTip toolTip) {
- if (toolTips == null) return;
- for (int i=0; i<toolTips.length; i++) {
- if (toolTips [i] == toolTip) {
- toolTips [i] = null;
- return;
- }
- }
-}
-
-/**
- * If the receiver is visible, moves it to the top of the
- * drawing order for the display on which it was created
- * (so that all other shells on that display, which are not
- * the receiver's children will be drawn behind it) and asks
- * the window manager to make the shell active
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#open
- * @see Shell#setActive
- */
-public void setActive () {
- checkWidget ();
- if (!isVisible ()) return;
- OS.SelectWindow (shellHandle);
- OS.SetUserFocusWindow (shellHandle);
-}
-
-void setActiveControl (Control control) {
- if (control != null && control.isDisposed ()) control = null;
- if (lastActive != null && lastActive.isDisposed ()) lastActive = null;
- if (lastActive == control) return;
-
- /*
- * Compute the list of controls to be activated and
- * deactivated by finding the first common parent
- * control.
- */
- Control [] activate = (control == null) ? new Control[0] : control.getPath ();
- Control [] deactivate = (lastActive == null) ? new Control[0] : lastActive.getPath ();
- lastActive = control;
- int index = 0, length = Math.min (activate.length, deactivate.length);
- while (index < length) {
- if (activate [index] != deactivate [index]) break;
- index++;
- }
-
- /*
- * It is possible (but unlikely), that application
- * code could have destroyed some of the widgets. If
- * this happens, keep processing those widgets that
- * are not disposed.
- */
- for (int i=deactivate.length-1; i>=index; --i) {
- if (!deactivate [i].isDisposed ()) {
- deactivate [i].sendEvent (SWT.Deactivate);
- }
- }
- for (int i=activate.length-1; i>=index; --i) {
- if (!activate [i].isDisposed ()) {
- activate [i].sendEvent (SWT.Activate);
- }
- }
-}
-
-/**
- * Sets the receiver's alpha value which must be
- * between 0 (transparent) and 255 (opaque).
- * <p>
- * This operation requires the operating system's advanced
- * widgets subsystem which may not be available on some
- * platforms.
- * </p>
- * @param alpha the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setAlpha (int alpha) {
- checkWidget ();
- alpha &= 0xFF;
- OS.SetWindowAlpha (shellHandle, alpha / 255f);
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- if (fullScreen) setFullScreen (false);
- Rect rect = new Rect ();
- if (!move) {
- OS.GetWindowBounds (shellHandle, (short) OS.kWindowStructureRgn, rect);
- x = rect.left;
- y = rect.top;
- }
- if (!resize) {
- OS.GetWindowBounds (shellHandle, (short) OS.kWindowStructureRgn, rect);
- width = rect.right - rect.left;
- height = rect.bottom - rect.top;
- } else {
- OS.GetWindowStructureWidths (shellHandle, rect);
- CGPoint inMinLimits = new CGPoint (), inMaxLimits = new CGPoint ();
- OS.GetWindowResizeLimits (shellHandle, inMinLimits, inMaxLimits);
- width = Math.max (1, Math.max (width, (int) inMinLimits.x + (rect.left + rect.right)));
- height = Math.max (1, Math.max (height, (int) inMinLimits.y + (rect.top + rect.bottom)));
- }
- if (rgnRect != null) {
- OS.SetRect (rgnRect, (short) 0, (short) 0, (short) width, (short) height);
- }
- OS.SetRect (rect, (short) x, (short) y, (short) (x + width), (short) (y + height));
- OS.SetWindowBounds (shellHandle, (short) OS.kWindowStructureRgn, rect);
- return 0;
-}
-
-public void setEnabled (boolean enabled) {
- checkWidget();
- if (((state & DISABLED) == 0) == enabled) return;
- super.setEnabled (enabled);
- if (enabled && OS.IsWindowActive (shellHandle)) {
- if (!restoreFocus ()) traverseGroup (false);
- }
-}
-
-/**
- * Sets the full screen state of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the full screen state, and if the argument is
- * <code>false</code> and the receiver was previously switched
- * into full screen state, causes the receiver to switch back
- * to either the maximized or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setFullScreen(true)</code>,
- * <code>setMaximized(true)</code> and <code>setMinimized(true)</code> will
- * vary by platform. Typically, the behavior will match the platform user's
- * expectations, but not always. This should be avoided if possible.
- * </p>
- *
- * @param fullScreen the new fullscreen state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setFullScreen (boolean fullScreen) {
- checkWidget ();
- this.fullScreen = fullScreen;
- if (fullScreen) {
- normalBounds = getBounds ();
- OS.ChangeWindowAttributes (shellHandle, OS.kWindowNoTitleBarAttribute, OS.kWindowResizableAttribute | OS.kWindowLiveResizeAttribute);
- updateSystemUIMode ();
- Rectangle screen = getMonitor ().getBounds ();
- if (menuBar != null && getMonitor ().equals(display.getPrimaryMonitor ())) {
- Rect rect = new Rect ();
- int gdevice = OS.GetMainDevice ();
- OS.GetAvailableWindowPositioningBounds (gdevice, rect);
- screen.height -= rect.top;
- screen.y += rect.top;
- }
- Rect rect = new Rect ();
- OS.SetRect (rect, (short) screen.x, (short) screen.y, (short) (screen.x + screen.width), (short) (screen.y + screen.height));
- OS.SetWindowBounds (shellHandle, (short) OS.kWindowStructureRgn, rect);
- } else {
- int attributes = 0;
- if ((style & SWT.RESIZE) != 0) {
- attributes |= OS.kWindowResizableAttribute;
- /*
- * Bug in the Macintosh. For some reason, a window has no title bar
- * and the kWindowResizableAttribute, no rubber banding feedback is
- * given while the window is resizing. The fix is to create the window
- * with kWindowLiveResizeAttribute in this case. This is inconsistent
- * with other windows, but the user will get feedback when resizing.
- */
- if ((style & SWT.TITLE) == 0) attributes |= OS.kWindowLiveResizeAttribute;
- if (!OS.__BIG_ENDIAN__()) attributes |= OS.kWindowLiveResizeAttribute;
- }
- OS.ChangeWindowAttributes (shellHandle, attributes, OS.kWindowNoTitleBarAttribute);
- OS.SetSystemUIMode (OS.kUIModeNormal, 0);
- if (maximized) {
- setMaximized (true);
- } else {
- Rect rect = new Rect ();
- if (normalBounds != null) OS.SetRect (rect, (short) normalBounds.x, (short) normalBounds.y, (short) (normalBounds.x + normalBounds.width), (short) (normalBounds.y + normalBounds.height));
- OS.SetWindowBounds (shellHandle, (short) OS.kWindowStructureRgn, rect);
- }
- normalBounds = null;
- }
-}
-
-public void setMenuBar (Menu menu) {
- checkWidget();
- super.setMenuBar (menu);
- if (display.getActiveShell () == this) {
- display.setMenuBar (menuBar);
- }
-}
-
-/**
- * Sets the input method editor mode to the argument which
- * should be the result of bitwise OR'ing together one or more
- * of the following constants defined in class <code>SWT</code>:
- * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>,
- * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>.
- *
- * @param mode the new IME mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public void setImeInputMode (int mode) {
- checkWidget();
-}
-
-public void setMaximized (boolean maximized) {
- checkWidget();
- super.setMaximized (maximized);
- org.eclipse.swt.internal.carbon.Point pt = new org.eclipse.swt.internal.carbon.Point ();
- if (maximized) {
- Rect rect = new Rect ();
- int gdevice = OS.GetMainDevice ();
- OS.GetAvailableWindowPositioningBounds (gdevice, rect);
- pt.h = (short) (rect.right - rect.left);
- pt.v = (short) (rect.bottom - rect.top);
- }
- short inPartCode = (short) (maximized ? OS.inZoomOut : OS.inZoomIn);
- if (!opened) ignoreBounds = true;
- OS.ZoomWindowIdeal (shellHandle, inPartCode, pt);
- if (!opened) ignoreBounds = false;
-}
-
-public void setMinimized (boolean minimized) {
- checkWidget();
- if (this.minimized == minimized) return;
- super.setMinimized (minimized);
- if (!minimized && OS.IsWindowCollapsed (shellHandle)) {
- OS.SelectWindow (shellHandle);
- }
- OS.CollapseWindow (shellHandle, minimized);
-}
-
-/**
- * Sets the receiver's minimum size to the size specified by the arguments.
- * If the new minimum size is larger than the current size of the receiver,
- * the receiver is resized to the new minimum size.
- *
- * @param width the new minimum width for the receiver
- * @param height the new minimum height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setMinimumSize (int width, int height) {
- checkWidget();
- int clientWidth = 0, clientHeight = 0;
- int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX;
- if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) {
- clientWidth = DEFAULT_CLIENT_WIDTH;
- clientHeight = DEFAULT_CLIENT_HEIGHT;
- }
- Rect rect = new Rect ();
- OS.GetWindowStructureWidths (shellHandle, rect);
- CGPoint inMinLimits = new CGPoint (), inMaxLimits = new CGPoint ();
- OS.GetWindowResizeLimits (shellHandle, inMinLimits, inMaxLimits);
- width = Math.max (width, clientWidth + rect.left + rect.right);
- height = Math.max (height, clientHeight + rect.top + rect.bottom);
- inMinLimits.x = width - (rect.left + rect.right);
- inMinLimits.y = height - (rect.top + rect.bottom);
- OS.SetWindowResizeLimits (shellHandle, inMinLimits, inMaxLimits);
- Point size = getSize ();
- int newWidth = Math.max (size.x, width), newHeight = Math.max (size.y, height);
- if (newWidth != size.x || newHeight != size.y) setSize (newWidth, newHeight);
-}
-
-/**
- * Sets the receiver's minimum size to the size specified by the argument.
- * If the new minimum size is larger than the current size of the receiver,
- * the receiver is resized to the new minimum size.
- *
- * @param size the new minimum size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setMinimumSize (Point size) {
- checkWidget();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setMinimumSize (size.x, size.y);
-}
-
-/**
- * Sets the receiver's modified state as specified by the argument.
- *
- * @param modified the new modified state for the receiver
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.5
- */
-public void setModified (boolean modified) {
- checkWidget ();
- OS.SetWindowModified (shellHandle, modified);
-}
-
-/**
- * Sets the shape of the shell to the region specified
- * by the argument. When the argument is null, the
- * default shape of the shell is restored. The shell
- * must be created with the style SWT.NO_TRIM in order
- * to specify a region.
- *
- * @param region the region that defines the shape of the shell (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public void setRegion (Region region) {
- checkWidget ();
- if ((style & SWT.NO_TRIM) == 0) return;
- if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (region == null) {
- rgnRect = null;
- } else {
- if (rgnRect == null) {
- rgnRect = new Rect ();
- OS.GetWindowBounds (shellHandle, (short) OS.kWindowStructureRgn, rgnRect);
- OS.SetRect (rgnRect, (short) 0, (short) 0, (short) (rgnRect.right - rgnRect.left), (short) (rgnRect.bottom - rgnRect.top));
- }
- }
- this.region = region;
- /*
- * Bug in the Macintosh. Calling ReshapeCustomWindow() from a
- * kEventWindowDrawContent handler originating from ShowWindow()
- * will deadlock. The fix is to detected this case and only call
- * ReshapeCustomWindow() after the default handler is done.
- */
- if (drawing) {
- reshape = true;
- } else {
- OS.ReshapeCustomWindow (shellHandle);
- redrawWidget (handle, true);
- }
-}
-
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- char [] buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (ptr == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- OS.SetWindowTitleWithCFString (shellHandle, ptr);
- OS.CFRelease (ptr);
-}
-
-public void setVisible (boolean visible) {
- checkWidget();
- int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- if ((style & mask) != 0) {
- if (visible) {
- display.setModalShell (this);
- } else {
- display.clearModal (this);
- }
- } else {
- updateModal ();
- }
- if (visible) {
- if ((state & HIDDEN) == 0) return;
- state &= ~HIDDEN;
- } else {
- if ((state & HIDDEN) != 0) return;
- state |= HIDDEN;
- }
- showWithParent = visible;
- setWindowVisible (visible);
-}
-
-void setWindowVisible (boolean visible) {
- if (OS.IsWindowVisible (shellHandle) == visible) return;
- if (visible) {
- if (center && !moved) {
- if (isDisposed ()) return;
- center ();
- }
- sendEvent (SWT.Show);
- if (isDisposed ()) return;
- int inModalKind = OS.kWindowModalityNone;
- if ((style & SWT.PRIMARY_MODAL) != 0) inModalKind = OS.kWindowModalityWindowModal;
- if ((style & SWT.APPLICATION_MODAL) != 0) inModalKind = OS.kWindowModalityAppModal;
- if ((style & SWT.SYSTEM_MODAL) != 0) inModalKind = OS.kWindowModalitySystemModal;
- if (inModalKind != OS.kWindowModalityNone) {
- int inUnavailableWindow = 0;
- if (parent != null) inUnavailableWindow = OS.GetControlOwner (parent.handle);
- OS.SetWindowModality (shellHandle, inModalKind, inUnavailableWindow);
- if (inUnavailableWindow != 0) OS.CollapseWindow (inUnavailableWindow, false);
- }
- int topHandle = topHandle ();
- OS.SetControlVisibility (topHandle, true, false);
- int [] scope = new int [1];
- if ((style & SWT.ON_TOP) != 0) {
- OS.GetWindowActivationScope (shellHandle, scope);
- OS.SetWindowActivationScope (shellHandle, OS.kWindowActivationScopeNone);
- }
-
- int shellHandle = this.shellHandle;
- OS.RetainWindow (shellHandle);
- OS.ShowWindow (shellHandle);
- OS.ReleaseWindow (shellHandle);
- if (isDisposed()) return;
- if (minimized != OS.IsWindowCollapsed (shellHandle)) {
- OS.CollapseWindow (shellHandle, minimized);
- }
- if ((style & SWT.ON_TOP) != 0) {
- OS.SetWindowActivationScope (shellHandle, scope [0]);
- OS.BringToFront (shellHandle);
- } else {
- /*
- * Bug in the Macintosh. ShowWindow() does not activate the shell when an ON_TOP
- * shell is visible. The fix is to detect that the shell was not activated and
- * activate it.
- */
- if (display.getActiveShell () != this) {
- Shell[] shells = display.getShells();
- for (int i = 0; i < shells.length; i++) {
- Shell shell = shells [i];
- if ((shell.style & SWT.ON_TOP) != 0 && shell.isVisible ()) {
- bringToTop(false);
- break;
- }
- }
- }
- }
- opened = true;
- if (!moved) {
- moved = true;
- sendEvent (SWT.Move);
- if (isDisposed ()) return;
- }
- if (!resized) {
- resized = true;
- sendEvent (SWT.Resize);
- if (isDisposed ()) return;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
- }
- } else {
- /*
- * Bug in the Macintosh. Under certain circumstances, yet to
- * be determined, calling HideWindow() and then DisposeWindow()
- * causes a segment fault when an application is exiting. This
- * seems to happen to large applications. The fix is to avoid
- * calling HideWindow() when a shell is about to be disposed.
- */
- if (!disposed) OS.HideWindow (shellHandle);
- if (isDisposed ()) return;
- int topHandle = topHandle ();
- OS.SetControlVisibility (topHandle, false, false);
- invalidateVisibleRegion (topHandle);
- sendEvent (SWT.Hide);
- }
- display.updateQuitMenu ();
-}
-
-void setZOrder () {
- if (scrolledHandle != 0) OS.HIViewAddSubview (scrolledHandle, handle);
-}
-
-void setZOrder (Control control, boolean above) {
- if (above) {
- //NOT DONE - move one window above another
- OS.BringToFront (shellHandle);
- } else {
- int window = control == null ? 0 : OS.GetControlOwner (control.handle);
- OS.SendBehind (shellHandle, window);
- }
-}
-
-boolean traverseEscape () {
- if (parent == null) return false;
- if (!isVisible () || !isEnabled ()) return false;
- close ();
- return true;
-}
-
-void updateMinimized (boolean minimized) {
- /*
- * Need to handle ON_TOP child shells ourselves, since they
- * are not in the same group hierarchy of this shell.
- */
- Shell [] shells = getShells ();
- for (int i = 0; i < shells.length; i++) {
- Shell shell = shells [i];
- if (this == shell.parent && (shell.style & SWT.ON_TOP) != 0) {
- if (minimized) {
- if (shells[i].isVisible ()) {
- shells[i].showWithParent = true;
- OS.HideWindow (shell.shellHandle);
- }
- } else {
- if (shells[i].showWithParent) {
- shells[i].showWithParent = false;
- OS.ShowWindow (shell.shellHandle);
- }
- }
- }
- }
-}
-
-void updateModal () {
- // do nothing
-}
-
-void updateSystemUIMode () {
- if (!getMonitor ().equals (display.getPrimaryMonitor ())) return;
- boolean isActive = false;
- Shell activeShell = display.getActiveShell ();
- Shell current = this;
- while (current != null) {
- if (current.equals (activeShell)) {
- isActive = true;
- break;
- }
- current = (Shell) current.parent;
- }
- if (!isActive) return;
- if (fullScreen) {
- int mode = OS.kUIModeAllHidden;
- if (menuBar != null) {
- mode = OS.kUIModeContentHidden;
- }
- OS.SetSystemUIMode (mode, 0);
- } else {
- OS.SetSystemUIMode (OS.kUIModeNormal, 0);
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Slider.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Slider.java
deleted file mode 100644
index d696c0d429..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Slider.java
+++ /dev/null
@@ -1,523 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.OS;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that represent a range of positive, numeric values.
- * <p>
- * At any given moment, a given slider will have a
- * single 'selection' that is considered to be its
- * value, which is constrained to be within the range of
- * values the slider represents (that is, between its
- * <em>minimum</em> and <em>maximum</em> values).
- * </p><p>
- * Typically, sliders will be made up of five areas:
- * <ol>
- * <li>an arrow button for decrementing the value</li>
- * <li>a page decrement area for decrementing the value by a larger amount</li>
- * <li>a <em>thumb</em> for modifying the value by mouse dragging</li>
- * <li>a page increment area for incrementing the value by a larger amount</li>
- * <li>an arrow button for incrementing the value</li>
- * </ol>
- * Based on their style, sliders are either <code>HORIZONTAL</code>
- * (which have a left facing button for decrementing the value and a
- * right facing button for incrementing it) or <code>VERTICAL</code>
- * (which have an upward facing button for decrementing the value
- * and a downward facing buttons for incrementing it).
- * </p><p>
- * On some platforms, the size of the slider's thumb can be
- * varied relative to the magnitude of the range of values it
- * represents (that is, relative to the difference between its
- * maximum and minimum values). Typically, this is used to
- * indicate some proportional value such as the ratio of the
- * visible area of a document to the total amount of space that
- * it would take to display it. SWT supports setting the thumb
- * size even if the underlying platform does not, but in this
- * case the appearance of the slider will not change.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see ScrollBar
- * @see <a href="http://www.eclipse.org/swt/snippets/#slider">Slider snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Slider extends Control {
- boolean dragging;
- int increment = 1;
- int pageIncrement = 10;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Slider (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values:
- * <code>SWT.NONE</code> - for the end of a drag.
- * <code>SWT.DRAG</code>.
- * <code>SWT.HOME</code>.
- * <code>SWT.END</code>.
- * <code>SWT.ARROW_DOWN</code>.
- * <code>SWT.ARROW_UP</code>.
- * <code>SWT.PAGE_DOWN</code>.
- * <code>SWT.PAGE_UP</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-int actionProc (int theControl, int partCode) {
- int result = super.actionProc (theControl, partCode);
- if (result == OS.noErr) return result;
- Event event = new Event ();
- int value = OS.GetControl32BitValue (handle);
- switch (partCode) {
- case OS.kControlUpButtonPart:
- value -= increment;
- event.detail = SWT.ARROW_UP;
- break;
- case OS.kControlPageUpPart:
- value -= pageIncrement;
- event.detail = SWT.PAGE_UP;
- break;
- case OS.kControlPageDownPart:
- value += pageIncrement;
- event.detail = SWT.PAGE_DOWN;
- break;
- case OS.kControlDownButtonPart:
- value += increment;
- event.detail = SWT.ARROW_DOWN;
- break;
- case OS.kControlIndicatorPart:
- dragging = true;
- event.detail = SWT.DRAG;
- break;
- default:
- return result;
- }
- OS.SetControl32BitValue (handle, value);
- sendEvent (SWT.Selection, event);
- return result;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricScrollBarWidth, outMetric);
- int width = 0, height = 0;
- if ((style & SWT.HORIZONTAL) != 0) {
- height = outMetric [0];
- width = height * 10;
- } else {
- width = outMetric [0];
- height = width * 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- return new Point (width, height);
-}
-
-void createHandle () {
- int actionProc = display.actionProc;
- int [] outControl = new int [1];
- int window = OS.GetControlOwner (parent.handle);
- OS.CreateScrollBarControl (window, null, 0, 0, 90, 10, true, actionProc, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
-}
-
-void drawBackground (int control, int context) {
- fillBackground (control, context, null);
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget();
- return increment;
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget();
- int maximum = OS.GetControl32BitMaximum (handle);
- int viewSize = OS.GetControlViewSize (handle);
- return maximum + viewSize;
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget();
- return OS.GetControl32BitMinimum (handle);
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget();
- return pageIncrement;
-}
-
-/**
- * Returns the 'selection', which is the receiver's value.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget();
- return OS.GetControl32BitValue (handle);
-}
-
-/**
- * Returns the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values.
- *
- * @return the thumb value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getThumb () {
- checkWidget();
- return OS.GetControlViewSize (handle);
-}
-
-int kEventMouseDown (int nextHandler, int theEvent, int userData) {
- int status = super.kEventMouseDown (nextHandler, theEvent, userData);
- if (status == OS.noErr) return status;
- dragging = false;
- status = OS.CallNextEventHandler (nextHandler, theEvent);
- if (dragging) {
- Event event = new Event ();
- sendEvent (SWT.Selection, event);
- }
- dragging = false;
- return status;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- increment = value;
-}
-
-/**
- * Sets the maximum. If this value is negative or less than or
- * equal to the minimum, the value is ignored. If necessary, first
- * the thumb and then the selection are adjusted to fit within the
- * new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget();
- if (value < 0) return;
- int minimum = OS.GetControl32BitMinimum (handle);
- if (value <= minimum) return;
- int viewSize = OS.GetControlViewSize (handle);
- if (value - minimum < viewSize) {
- viewSize = value - minimum;
- OS.SetControlViewSize (handle, viewSize);
- }
- OS.SetControl32BitMaximum (handle, value - viewSize);
-}
-
-/**
- * Sets the minimum value. If this value is negative or greater
- * than or equal to the maximum, the value is ignored. If necessary,
- * first the thumb and then the selection are adjusted to fit within
- * the new range.
- *
- * @param value the new minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget();
- if (value < 0) return;
- int viewSize = OS.GetControlViewSize (handle);
- int maximum = OS.GetControl32BitMaximum (handle) + viewSize;
- if (value >= maximum) return;
- if (maximum - value < viewSize) {
- viewSize = maximum - value;
- OS.SetControl32BitMaximum (handle, maximum - viewSize);
- OS.SetControlViewSize (handle, viewSize);
- }
- OS.SetControl32BitMinimum (handle, value);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- pageIncrement = value;
-}
-
-/**
- * Sets the 'selection', which is the receiver's
- * value, to the argument which must be greater than or equal
- * to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget();
- OS.SetControl32BitValue (handle, value);
-}
-
-/**
- * Sets the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values. This new
- * value will be ignored if it is less than one, and will be
- * clamped if it exceeds the receiver's current range.
- *
- * @param value the new thumb value, which must be at least one and not
- * larger than the size of the current range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setThumb (int value) {
- checkWidget();
- if (value < 1) return;
- int minimum = OS.GetControl32BitMinimum (handle);
- int viewSize = OS.GetControlViewSize (handle);
- int maximum = OS.GetControl32BitMaximum (handle) + viewSize;
- value = Math.min (value, maximum - minimum);
- OS.SetControl32BitMaximum (handle, maximum - value);
- OS.SetControlViewSize (handle, value);
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, thumb, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param thumb the new thumb value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- checkWidget();
- if (minimum < 0) return;
- if (maximum < 0) return;
- if (thumb < 1) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- thumb = Math.min (thumb, maximum - minimum);
- OS.SetControl32BitMinimum (handle, minimum);
- OS.SetControl32BitMaximum (handle, maximum - thumb);
- OS.SetControlViewSize (handle, thumb);
- OS.SetControl32BitValue (handle, selection);
- this.increment = increment;
- this.pageIncrement = pageIncrement;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Spinner.java
deleted file mode 100644
index 3fe8bf2af6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Spinner.java
+++ /dev/null
@@ -1,1298 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.CFRange;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.Rect;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify numeric
- * values.
- * <p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, Modify, Verify</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#spinner">Spinner snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Spinner extends Composite {
- int textHandle, buttonHandle;
- int textVisibleRgn, buttonVisibleRgn;
- int increment = 1;
- int pageIncrement = 10;
- int digits = 0;
- int textLimit = LIMIT;
- static int GAP = 3;
-
- /**
- * the operating system limit for the number of characters
- * that the text field in an instance of this class can hold
- *
- * @since 3.4
- */
- public static final int LIMIT;
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0x7FFFFFFF;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#READ_ONLY
- * @see SWT#WRAP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Spinner (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-int actionProc (int theControl, int partCode) {
- int result = super.actionProc (theControl, partCode);
- if (result == OS.noErr) return result;
- if (theControl == buttonHandle) {
- boolean [] parseFail = new boolean [1];
- int value = getSelectionText (parseFail);
- if (parseFail [0]) {
- value = OS.GetControl32BitValue (buttonHandle);
- }
- int newValue = value;
- switch (partCode) {
- case OS.kControlUpButtonPart:
- newValue += increment;
- break;
- case OS.kControlDownButtonPart:
- newValue -= increment;
- break;
- }
- int max = OS.GetControl32BitMaximum (buttonHandle);
- int min = OS.GetControl32BitMinimum (buttonHandle);
- if ((style & SWT.WRAP) != 0) {
- if (newValue > max) newValue = min;
- if (newValue < min) newValue = max;
- }
- newValue = Math.min (Math.max (min, newValue), max);
- if (value != newValue) setSelection (newValue, true, true, true);
- }
- return result;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is not called for texts.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- */
-void addVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-
-static int checkStyle (int style) {
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0;
- int max = OS.GetControl32BitMaximum (buttonHandle);
- String string = String.valueOf (max);
- if (digits > 0) {
- StringBuffer buffer = new StringBuffer ();
- buffer.append (string);
- buffer.append (getDecimalSeparator ());
- int count = digits - string.length ();
- while (count >= 0) {
- buffer.append ("0");
- count--;
- }
- string = buffer.toString ();
- }
- char [] buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- Point size = textExtent (ptr, 0);
- if (ptr != 0) OS.CFRelease (ptr);
- width = Math.max (width, size.x);
- height = Math.max (height, size.y);
- int [] metric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricEditTextWhitespace, metric);
- width += metric [0] * 2;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- Rectangle trim = computeTrim (0, 0, width, height);
- OS.GetThemeMetric (OS.kThemeMetricLittleArrowsHeight, metric);
- trim.height = Math.max (trim.height, metric [0]);
- return new Point (trim.width, trim.height);
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
- Rect inset = inset ();
- width += inset.left + inset.right;
- height += inset.top + inset.bottom;
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricLittleArrowsWidth, outMetric);
- width += outMetric [0] + GAP;
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void copy () {
- checkWidget ();
- short [] selection = new short [2];
- if (OS.GetControlData (textHandle, (short)OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection, null) != OS.noErr) return;
- if (selection [0] == selection [1]) return;
- int [] actualSize = new int [1];
- int [] ptr = new int [1];
- if (OS.GetControlData (textHandle, (short)OS.kControlEntireControl, OS.kControlEditTextCFStringTag, 4, ptr, actualSize) != OS.noErr) return;
- CFRange range = new CFRange ();
- range.location = selection [0];
- range.length = selection [1] - selection [0];
- char [] buffer= new char [range.length];
- OS.CFStringGetCharacters (ptr [0], range, buffer);
- OS.CFRelease (ptr [0]);
- copyToClipboard (buffer);
-}
-
-void createHandle () {
- int window = OS.GetControlOwner (parent.handle);
- int actionProc = display.actionProc;
- int features = OS.kControlSupportsEmbedding | OS.kControlSupportsFocus;
- int [] outControl = new int [1];
- OS.CreateUserPaneControl (window, null, features, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
-
- OS.CreateLittleArrowsControl (window, null, 0, 0, 100, 1, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- buttonHandle = outControl [0];
- OS.SetControlAction (buttonHandle, actionProc);
-
- OS.CreateEditUnicodeTextControl (window, null, 0, false, null, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- textHandle = outControl [0];
- OS.SetControlData (textHandle, OS.kControlEntireControl, OS.kControlEditTextSingleLineTag, 1, new byte [] {1});
- if ((style & SWT.READ_ONLY) != 0) {
- OS.SetControlData (textHandle, OS.kControlEntireControl, OS.kControlEditTextLockedTag, 1, new byte [] {1});
- }
- setSelection (0, false, true, false);
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void cut () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- short [] selection = new short [2];
- if (OS.GetControlData (textHandle, (short)OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection, null) != OS.noErr) return;
- if (selection [0] == selection [1]) return;
- char [] buffer = setText ("", selection [0], selection [1], true);
- if (buffer != null) {
- copyToClipboard (buffer);
- }
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget(textHandle);
- display.removeWidget(buttonHandle);
-}
-
-void drawBackground (int control, int context) {
- if (control == textHandle) {
- fillBackground (control, context, null);
- } else {
- parent.fillBackground (control, context, null);
- }
-}
-
-int focusHandle () {
- return textHandle;
-}
-
-/**
- * Returns the number of decimal places used by the receiver.
- *
- * @return the digits
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getDigits () {
- checkWidget ();
- return digits;
-}
-
-String getDecimalSeparator () {
- int locale = OS.CFLocaleCopyCurrent ();
- int formatter = OS.CFNumberFormatterCreate (OS.kCFAllocatorDefault, locale, OS.kCFNumberFormatterDecimalStyle);
- int key = OS.kCFNumberFormatterDecimalSeparator ();
- int result = OS.CFNumberFormatterCopyProperty (formatter, key);
- CFRange range = new CFRange ();
- range.location = 0;
- range.length = OS.CFStringGetLength (result);
- char [] buffer= new char [range.length];
- OS.CFStringGetCharacters (result, range, buffer);
- OS.CFRelease (result);
- OS.CFRelease (formatter);
- OS.CFRelease (locale);
- return new String (buffer);
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down arrows are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget ();
- return increment;
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget ();
- return OS.GetControl32BitMaximum (buttonHandle);
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget ();
- return OS.GetControl32BitMinimum (buttonHandle);
-}
-
-/**
- * Returns the amount that the receiver's position will be
- * modified by when the page up/down keys are pressed.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget ();
- return pageIncrement;
-}
-
-/**
- * Returns the <em>selection</em>, which is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget ();
- return OS.GetControl32BitValue (buttonHandle);
-}
-
-int getSelectionText (boolean [] parseFail) {
- int [] actualSize = new int [1];
- int [] ptr = new int [1];
- if (OS.GetControlData (textHandle, (short)OS.kControlEntireControl, OS.kControlEditTextCFStringTag, 4, ptr, actualSize) == OS.noErr) {
- CFRange range = new CFRange ();
- range.location = 0;
- range.length = OS.CFStringGetLength (ptr [0]);
- char [] buffer= new char [range.length];
- OS.CFStringGetCharacters (ptr [0], range, buffer);
- OS.CFRelease (ptr [0]);
- String string = new String (buffer);
- try {
- int value;
- if (digits > 0) {
- String decimalSeparator = getDecimalSeparator ();
- int index = string.indexOf (decimalSeparator);
- if (index != -1) {
- int startIndex = string.startsWith ("+") || string.startsWith ("-") ? 1 : 0;
- String wholePart = startIndex != index ? string.substring (startIndex, index) : "0";
- String decimalPart = string.substring (index + 1);
- if (decimalPart.length () > digits) {
- decimalPart = decimalPart.substring (0, digits);
- } else {
- int i = digits - decimalPart.length ();
- for (int j = 0; j < i; j++) {
- decimalPart = decimalPart + "0";
- }
- }
- int wholeValue = Integer.parseInt (wholePart);
- int decimalValue = Integer.parseInt (decimalPart);
- for (int i = 0; i < digits; i++) wholeValue *= 10;
- value = wholeValue + decimalValue;
- if (string.startsWith ("-")) value = -value;
- } else {
- value = Integer.parseInt (string);
- for (int i = 0; i < digits; i++) value *= 10;
- }
- } else {
- value = Integer.parseInt (string);
- }
- int max = OS.GetControl32BitMaximum (buttonHandle);
- int min = OS.GetControl32BitMinimum (buttonHandle);
- if (min <= value && value <= max) return value;
- } catch (NumberFormatException e) {
- }
- }
- parseFail [0] = true;
- return -1;
-}
-
-/**
- * Returns a string containing a copy of the contents of the
- * receiver's text field, or an empty string if there are no
- * contents.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public String getText() {
- int [] ptr = new int [1];
- int [] actualSize = new int [1];
- int result = OS.GetControlData (textHandle, (short)OS.kControlEntireControl, OS.kControlEditTextCFStringTag, 4, ptr, actualSize);
- if (result != OS.noErr) return "";
- CFRange range = new CFRange ();
- range.length = OS.CFStringGetLength (ptr [0]);
- char [] buffer= new char [range.length];
- OS.CFStringGetCharacters (ptr [0], range, buffer);
- OS.CFRelease (ptr [0]);
- return new String (buffer);
-}
-
-/**
- * Returns the maximum number of characters that the receiver's
- * text field is capable of holding. If this has not been changed
- * by <code>setTextLimit()</code>, it will be the constant
- * <code>Spinner.LIMIT</code>.
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- *
- * @since 3.4
- */
-public int getTextLimit () {
- checkWidget();
- return textLimit;
-}
-
-int getVisibleRegion (int control, boolean clipChildren) {
- if (control == textHandle) {
- if (!clipChildren) return super.getVisibleRegion (control, clipChildren);
- if (textVisibleRgn == 0) {
- textVisibleRgn = OS.NewRgn ();
- calculateVisibleRegion (control, textVisibleRgn, clipChildren);
- }
- int result = OS.NewRgn ();
- OS.CopyRgn (textVisibleRgn, result);
- return result;
- }
- if (control == buttonHandle) {
- if (!clipChildren) return super.getVisibleRegion (control, clipChildren);
- if (buttonVisibleRgn == 0) {
- buttonVisibleRgn = OS.NewRgn ();
- calculateVisibleRegion (control, buttonVisibleRgn, clipChildren);
- }
- int result = OS.NewRgn ();
- OS.CopyRgn (buttonVisibleRgn, result);
- return result;
- }
- return super.getVisibleRegion (control, clipChildren);
-}
-
-void hookEvents () {
- super.hookEvents ();
- int controlProc = display.controlProc;
- int [] mask = new int [] {
- OS.kEventClassControl, OS.kEventControlDraw,
- OS.kEventClassControl, OS.kEventControlSetFocusPart,
- OS.kEventClassControl, OS.kEventControlTrack,
- OS.kEventClassControl, OS.kEventControlGetClickActivation,
- };
- int controlTarget = OS.GetControlEventTarget (textHandle);
- OS.InstallEventHandler (controlTarget, controlProc, mask.length / 2, mask, handle, null);
- controlTarget = OS.GetControlEventTarget (buttonHandle);
- OS.InstallEventHandler (controlTarget, controlProc, mask.length / 2, mask, handle, null);
-}
-
-Rect inset () {
- return display.editTextInset;
-}
-
-int kEventAccessibleGetNamedAttribute (int nextHandler, int theEvent, int userData) {
- int code = OS.eventNotHandledErr;
- int [] stringRef = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamAccessibleAttributeName, OS.typeCFStringRef, null, 4, null, stringRef);
- int length = 0;
- if (stringRef [0] != 0) length = OS.CFStringGetLength (stringRef [0]);
- char [] buffer = new char [length];
- CFRange range = new CFRange ();
- range.length = length;
- OS.CFStringGetCharacters (stringRef [0], range, buffer);
- String attributeName = new String(buffer);
- if (attributeName.equals (OS.kAXRoleAttribute) || attributeName.equals (OS.kAXRoleDescriptionAttribute)) {
- String roleText = OS.kAXGroupRole;
- buffer = new char [roleText.length ()];
- roleText.getChars (0, buffer.length, buffer, 0);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- if (attributeName.equals (OS.kAXRoleAttribute)) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- } else { // kAXRoleDescriptionAttribute
- int stringRef2 = OS.HICopyAccessibilityRoleDescription (stringRef [0], 0);
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, new int [] {stringRef2});
- OS.CFRelease(stringRef2);
- }
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- }
- if (accessible != null) {
- code = accessible.internal_kEventAccessibleGetNamedAttribute (nextHandler, theEvent, code);
- }
- return code;
-}
-
-int kEventControlSetFocusPart (int nextHandler, int theEvent, int userData) {
- int result = super.kEventControlSetFocusPart (nextHandler, theEvent, userData);
- if (result == OS.noErr) {
- short [] part = new short [1];
- OS.GetEventParameter (theEvent, OS.kEventParamControlPart, OS.typeControlPartCode, null, 2, null, part);
- if (part [0] == OS.kControlFocusNoPart) {
- boolean [] parseFail = new boolean [1];
- int value = getSelectionText (parseFail);
- if (parseFail [0]) {
- value = OS.GetControl32BitValue (buttonHandle);
- setSelection (value, false, true, false);
- }
- }
- }
- return result;
-}
-
-int kEventUnicodeKeyPressed (int nextHandler, int theEvent, int userData) {
- int result = super.kEventUnicodeKeyPressed (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- int [] keyboardEvent = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendKeyboardEvent, OS.typeEventRef, null, keyboardEvent.length * 4, null, keyboardEvent);
- int [] keyCode = new int [1];
- OS.GetEventParameter (keyboardEvent [0], OS.kEventParamKeyCode, OS.typeUInt32, null, keyCode.length * 4, null, keyCode);
- int [] modifiers = new int [1];
- OS.GetEventParameter (keyboardEvent [0], OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
- if (modifiers [0] == OS.cmdKey) {
- switch (keyCode [0]) {
- case 7: /* X */
- cut ();
- return OS.noErr;
- case 8: /* C */
- copy ();
- return OS.noErr;
- case 9: /* V */
- paste ();
- return OS.noErr;
- }
- }
- int delta = 0;
- switch (keyCode [0]) {
- case 76: /* KP Enter */
- case 36: /* Return */
- postEvent (SWT.DefaultSelection);
- return OS.noErr;
- case 116: /* Page Up */ delta = pageIncrement; break;
- case 121: /* Page Down */ delta = -pageIncrement; break;
- case 125: /* Down */ delta = -increment; break;
- case 126: /* Up */ delta = increment; break;
- }
- if (delta != 0) {
- boolean [] parseFail = new boolean [1];
- int value = getSelectionText (parseFail);
- if (parseFail [0]) {
- value = OS.GetControl32BitValue (buttonHandle);
- }
- int newValue = value + delta;
- int max = OS.GetControl32BitMaximum (buttonHandle);
- int min = OS.GetControl32BitMinimum (buttonHandle);
- if ((style & SWT.WRAP) != 0) {
- if (newValue > max) newValue = min;
- if (newValue < min) newValue = max;
- }
- newValue = Math.min (Math.max (min, newValue), max);
- if (value != newValue) setSelection (newValue, true, true, true);
- return OS.noErr;
- } else {
- result = OS.CallNextEventHandler (nextHandler, theEvent);
- boolean [] parseFail = new boolean [1];
- int value = getSelectionText (parseFail);
- if (!parseFail [0]) {
- int pos = OS.GetControl32BitValue (buttonHandle);
- if (pos != value) setSelection (value, true, false, true);
- }
- }
- return result;
-}
-
-int kEventTextInputUpdateActiveInputArea (int nextHandler, int theEvent, int userData) {
- int [] length = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendText, OS.typeUnicodeText, null, 0, length, (char [])null);
- int [] fixed_length = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendFixLen, OS.typeLongInteger, null, 4, null, fixed_length);
- if (fixed_length [0] == -1 || fixed_length [0] == length [0]) {
- postEvent (SWT.Modify);
- }
- return OS.eventNotHandledErr;
-}
-
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void paste () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- String text = getClipboardText ();
- short [] selection = new short [2];
- if (OS.GetControlData (textHandle, (short)OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection, null) != OS.noErr) return;
- setText (text, selection [0], selection [1], true);
-}
-
-boolean pollTrackEvent() {
- return true;
-}
-
-public void redraw () {
- checkWidget();
- super.redraw ();
- redrawWidget (textHandle, false);
- redrawWidget (buttonHandle, false);
-}
-
-void register () {
- super.register ();
- display.addWidget (textHandle, this);
- display.addWidget (buttonHandle, this);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- */
-void removeVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-
-void resetVisibleRegion (int control) {
- if (textVisibleRgn != 0) {
- OS.DisposeRgn (textVisibleRgn);
- textVisibleRgn = 0;
- }
- if (buttonVisibleRgn != 0) {
- OS.DisposeRgn (buttonVisibleRgn);
- buttonVisibleRgn = 0;
- }
- super.resetVisibleRegion (control);
-}
-
-void resizeClientArea () {
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricLittleArrowsWidth, outMetric);
- int buttonWidth = outMetric [0] + GAP;
- OS.GetThemeMetric (OS.kThemeMetricLittleArrowsHeight, outMetric);
- int buttonHeight = outMetric [0];
- Rect rect = new Rect ();
- OS.GetControlBounds (handle, rect);
- Rect inset = inset ();
- int width = Math.max (0, rect.right - rect.left - inset.left - inset.right - buttonWidth);
- int height = Math.max (0, rect.bottom - rect.top - inset.top - inset.bottom);
- buttonHeight = Math.min (buttonHeight, rect.bottom - rect.top);
- setBounds (textHandle, inset.left, inset.top, width, height, true, true, false);
- setBounds (buttonHandle, inset.left + inset.right + width + GAP, inset.top + (height - buttonHeight) / 2, buttonWidth, buttonHeight, true, true, false);
-}
-
-boolean sendKeyEvent (int type, Event event) {
- if (!super.sendKeyEvent (type, event)) {
- return false;
- }
- if (type != SWT.KeyDown) return true;
- if ((style & SWT.READ_ONLY) != 0) return true;
- if (event.character == 0) return true;
- if ((event.stateMask & SWT.COMMAND) != 0) return true;
-// if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return true;
- String oldText = "", newText = "";
- int [] actualSize = new int [1];
- int [] ptr = new int [1];
- int charCount = 0;
- if (OS.GetControlData (textHandle, (short)OS.kControlEntireControl, OS.kControlEditTextCFStringTag, 4, ptr, actualSize) == OS.noErr) {
- charCount = OS.CFStringGetLength (ptr [0]);
- OS.CFRelease (ptr [0]);
- }
- short [] selection = new short [2];
- OS.GetControlData (textHandle, (short)OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection, null);
- int start = selection [0], end = selection [1];
- switch (event.character) {
- case SWT.BS:
- if (start == end) {
- if (start == 0) return true;
- start = Math.max (0, start - 1);
- }
- break;
- case SWT.DEL:
- if (start == end) {
- if (start == charCount) return true;
- end = Math.min (end + 1, charCount);
- }
- break;
- case SWT.CR:
- return true;
- default:
- if (event.character != '\t' && event.character < 0x20) return true;
- oldText = new String (new char [] {event.character});
- }
- newText = verifyText (oldText, start, end, event);
- if (newText == null) return false;
- if (charCount - (end - start) + newText.length () > textLimit) {
- return false;
- }
- if (newText != oldText) {
- setText (newText, start, end, false);
- start += newText.length ();
- selection = new short [] {(short)start, (short)start};
- OS.SetControlData (textHandle, (short)OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection);
- }
- /*
- * Post the modify event so that the character will be inserted
- * into the widget when the modify event is delivered. Normally,
- * modify events are sent but it is safe to post the event here
- * because this method is called from the event loop.
- */
- postEvent (SWT.Modify);
- return newText == oldText;
-}
-
-void setBackground (float [] color) {
- super.setBackground (color);
- setBackground (textHandle, color);
-}
-
-/**
- * Sets the number of decimal places used by the receiver.
- * <p>
- * The digit setting is used to allow for floating point values in the receiver.
- * For example, to set the selection to a floating point value of 1.37 call setDigits() with
- * a value of 2 and setSelection() with a value of 137. Similarly, if getDigits() has a value
- * of 2 and getSelection() returns 137 this should be interpreted as 1.37. This applies to all
- * numeric APIs.
- * </p>
- *
- * @param value the new digits (must be greater than or equal to zero)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the value is less than zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDigits (int value) {
- checkWidget ();
- if (value < 0) error (SWT.ERROR_INVALID_ARGUMENT);
- if (value == digits) return;
- digits = value;
- int pos = OS.GetControl32BitValue (buttonHandle);
- setSelection (pos, false, true, false);
-}
-
-void setFontStyle (Font font) {
- super.setFontStyle (font);
- setFontStyle (textHandle, font);
-}
-
-void setForeground (float [] color) {
- super.setForeground (color);
- setForeground (textHandle, color);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down arrows are pressed to
- * the argument, which must be at least one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- increment = value;
-}
-
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget ();
- int min = OS.GetControl32BitMinimum (buttonHandle);
- if (value <= min) return;
- int pos = OS.GetControl32BitValue (buttonHandle);
- OS.SetControl32BitMaximum (buttonHandle, value);
- if (pos > value) setSelection (value, true, true, false);
-}
-
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget ();
- int max = OS.GetControl32BitMaximum (buttonHandle);
- if (value >= max) return;
- int pos = OS.GetControl32BitValue (buttonHandle);
- OS.SetControl32BitMinimum (buttonHandle, value);
- if (pos < value) setSelection (value, true, true, false);
-}
-
-/**
- * Sets the amount that the receiver's position will be
- * modified by when the page up/down keys are pressed
- * to the argument, which must be at least one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- pageIncrement = value;
-}
-
-/**
- * Sets the <em>selection</em>, which is the receiver's
- * position, to the argument. If the argument is not within
- * the range specified by minimum and maximum, it will be
- * adjusted to fall within this range.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget ();
- int min = OS.GetControl32BitMinimum (buttonHandle);
- int max = OS.GetControl32BitMaximum (buttonHandle);
- value = Math.min (Math.max (min, value), max);
- setSelection (value, true, true, false);
-}
-
-void setSelection (int value, boolean setPos, boolean setText, boolean notify) {
- if (setPos) {
- OS.SetControl32BitValue (buttonHandle, value);
- }
- if (setText) {
- String string;
- if (digits == 0) {
- string = String.valueOf (value);
- } else {
- string = String.valueOf (Math.abs (value));
- String decimalSeparator = getDecimalSeparator ();
- int index = string.length () - digits;
- StringBuffer buffer = new StringBuffer ();
- if (value < 0) buffer.append ("-");
- if (index > 0) {
- buffer.append (string.substring (0, index));
- buffer.append (decimalSeparator);
- buffer.append (string.substring (index));
- } else {
- buffer.append ("0");
- buffer.append (decimalSeparator);
- while (index++ < 0) buffer.append ("0");
- buffer.append (string);
- }
- string = buffer.toString ();
- }
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- int [] actualSize = new int [1];
- int [] ptr = new int [1];
- int length = 0;
- if (OS.GetControlData (textHandle, (short)OS.kControlEntireControl, OS.kControlEditTextCFStringTag, 4, ptr, actualSize) == OS.noErr) {
- length = OS.CFStringGetLength (ptr [0]);
- OS.CFRelease (ptr [0]);
- }
- string = verifyText (string, 0, length, null);
- if (string == null) return;
- }
- char [] buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (ptr == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- OS.SetControlData (textHandle, OS.kControlEntireControl, OS.kControlEditTextCFStringTag, 4, new int[] {ptr});
- OS.CFRelease (ptr);
- short [] selection = new short [] {0, (short)string.length ()};
- OS.SetControlData (textHandle, (short)OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection);
- sendEvent (SWT.Modify);
- }
- if (notify) postEvent (SWT.Selection);
-}
-
-char [] setText (String string, int start, int end, boolean notify) {
- if (notify) {
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- string = verifyText (string, start, end, null);
- if (string == null) return null;
- }
- }
- int [] actualSize = new int [1];
- int [] ptr = new int [1];
- if (OS.GetControlData (textHandle, (short)OS.kControlEntireControl, OS.kControlEditTextCFStringTag, 4, ptr, actualSize) != OS.noErr) return null;
- int charCount = OS.CFStringGetLength (ptr [0]);
- int length = string.length ();
- if (textLimit != LIMIT) {
- if (charCount - (end - start) + length > textLimit) {
- length = textLimit - charCount + (end - start);
- }
- }
- char [] text = new char [charCount - (end - start) + length];
- CFRange range = new CFRange ();
- range.location = 0;
- range.length = start;
- char [] buffer = new char [range.length];
- OS.CFStringGetCharacters (ptr [0], range, buffer);
- System.arraycopy (buffer, 0, text, 0, range.length);
- string.getChars (0, length, text, start);
- range.location = end;
- range.length = charCount - end;
- buffer = new char [range.length];
- OS.CFStringGetCharacters (ptr [0], range, buffer);
- System.arraycopy (buffer, 0, text, start + length, range.length);
-
- /* Copying the return value to buffer */
- range.location = start;
- range.length = end - start;
- buffer = new char [range.length];
- OS.CFStringGetCharacters (ptr [0], range, buffer);
- OS.CFRelease (ptr [0]);
-
- ptr [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, text, text.length);
- if (ptr [0] == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- OS.SetControlData (textHandle, OS.kControlEntireControl, OS.kControlEditTextCFStringTag, 4, ptr);
- OS.CFRelease (ptr [0]);
- if (notify) sendEvent (SWT.Modify);
- return buffer;
-}
-
-/**
- * Sets the maximum number of characters that the receiver's
- * text field is capable of holding to be the argument.
- * <p>
- * To reset this value to the default, use <code>setTextLimit(Spinner.LIMIT)</code>.
- * Specifying a limit value larger than <code>Spinner.LIMIT</code> sets the
- * receiver's limit to <code>Spinner.LIMIT</code>.
- * </p>
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- *
- * @since 3.4
- */
-public void setTextLimit (int limit) {
- checkWidget();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- textLimit = limit;
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, digits, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param digits the new digits value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setValues (int selection, int minimum, int maximum, int digits, int increment, int pageIncrement) {
- checkWidget ();
- if (maximum <= minimum) return;
- if (digits < 0) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- selection = Math.min (Math.max (minimum, selection), maximum);
- this.increment = increment;
- this.pageIncrement = pageIncrement;
- this.digits = digits;
- OS.SetControl32BitMaximum (buttonHandle, maximum);
- OS.SetControl32BitMinimum (buttonHandle, minimum);
- setSelection (selection, true, true, false);
-}
-
-void setZOrder () {
- super.setZOrder ();
- if (textHandle != 0) OS.HIViewAddSubview (handle, textHandle);
- if (buttonHandle != 0) OS.HIViewAddSubview (handle, buttonHandle);
-}
-
-String verifyText (String string, int start, int end, Event keyEvent) {
- Event event = new Event ();
- event.text = string;
- event.start = start;
- event.end = end;
- if (keyEvent != null) {
- event.character = keyEvent.character;
- event.keyCode = keyEvent.keyCode;
- event.stateMask = keyEvent.stateMask;
- }
- int index = 0;
- if (digits > 0) {
- String decimalSeparator = getDecimalSeparator ();
- index = string.indexOf (decimalSeparator);
- if (index != -1) {
- string = string.substring (0, index) + string.substring (index + 1);
- }
- index = 0;
- }
- if (string.length() > 0) {
- int minimum = OS.GetControl32BitMinimum (buttonHandle);
- if (minimum < 0 && string.charAt (0) == '-') index++;
- }
- while (index < string.length ()) {
- if (!Character.isDigit (string.charAt (index))) break;
- index++;
- }
- event.doit = index == string.length ();
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the verify
- * event. If this happens, answer null to cancel
- * the operation.
- */
- sendEvent (SWT.Verify, event);
- if (!event.doit || isDisposed ()) return null;
- return event.text;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TabFolder.java
deleted file mode 100644
index a09914cfc4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TabFolder.java
+++ /dev/null
@@ -1,702 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.Rect;
-import org.eclipse.swt.internal.carbon.CGRect;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class implement the notebook user interface
- * metaphor. It allows the user to select a notebook page from
- * set of pages.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TabItem</code>.
- * <code>Control</code> children are created and then set into a
- * tab item using <code>TabItem#setControl</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>TOP, BOTTOM</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles TOP and BOTTOM may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tabfolder">TabFolder, TabItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TabFolder extends Composite {
- TabItem [] items;
- int lastSelected = -1;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see SWT#TOP
- * @see SWT#BOTTOM
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabFolder (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- style = checkBits (style, SWT.TOP, SWT.BOTTOM, 0, 0, 0, 0);
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-int callPaintEventHandler (int control, int damageRgn, int visibleRgn, int theEvent, int nextHandler) {
- /*
- * Bug in the Macintosh. The tab folder tabs draw outside the widget
- * bounds when they do not fit. The fix is to clip the output to the
- * widget bounds.
- */
- int [] context = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamCGContextRef, OS.typeCGContextRef, null, 4, null, context);
- OS.CGContextSaveGState (context[0]);
- CGRect rect = new CGRect ();
- OS.HIViewGetBounds (handle, rect);
- OS.CGContextAddRect (context[0], rect);
- OS.CGContextClip (context [0]);
- int result = super.callPaintEventHandler (control, damageRgn, visibleRgn, theEvent, nextHandler);
- OS.CGContextRestoreGState (context[0]);
- return result;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- Point size = super.computeSize (wHint, hHint, changed);
- if (wHint == SWT.DEFAULT && items.length > 0) {
- int width = 0;
- GC gc = new GC (this);
- for (int i = 0; i < items.length; i++) {
- if (items [i] != null) {
- width += items [i].calculateWidth (gc);
- }
- }
- gc.dispose ();
- Rectangle trim = computeTrim (0, 0, width, 0);
- size.x = Math.max (trim.width, size.x);
- }
- return size;
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
- CGRect oldBounds = new CGRect (), bounds = oldBounds;
- OS.HIViewGetFrame (handle, oldBounds);
- int MIN_SIZE = 100;
- if (oldBounds.width < MIN_SIZE || oldBounds.height < MIN_SIZE) {
- OS.HIViewSetDrawingEnabled (handle, false);
- bounds = new CGRect ();
- bounds.width = bounds.height = 100;
- OS.HIViewSetFrame (handle, bounds);
- }
- Rect client = new Rect ();
- OS.GetTabContentRect (handle, client);
- if (oldBounds.width < MIN_SIZE || oldBounds.height < MIN_SIZE) {
- OS.HIViewSetFrame (handle, oldBounds);
- OS.HIViewSetDrawingEnabled (handle, getDrawing ());
- }
- x -= client.left;
- y -= client.top;
- width += (int) bounds.width - (client.right - client.left);
- height += (int) bounds.height - (client.bottom - client.top);
- Rect inset = getInset ();
- x -= inset.left;
- y -= inset.top;
- width += inset.left + inset.right;
- height += inset.top + inset.bottom;
- return new Rectangle (-client.left, -client.top, width, height);
-}
-
-void createHandle () {
- int [] outControl = new int [1];
- int window = OS.GetControlOwner (parent.handle);
- short direction = (style & SWT.BOTTOM) != 0 ? (short)OS.kControlTabDirectionSouth : (short)OS.kControlTabDirectionNorth;
- OS.CreateTabsControl (window, new Rect (), (short)OS.kControlTabSizeLarge, direction, (short) 0, 0, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
-}
-
-void createItem (TabItem item, int index) {
- int count = OS.GetControl32BitMaximum (handle);
- if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
- OS.SetControl32BitMaximum (handle, count+1);
- if (count == items.length) {
- TabItem [] newItems = new TabItem [items.length + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- System.arraycopy (items, index, items, index + 1, count - index);
- items [index] = item;
-
- /*
- * Send a selection event when the item that is added becomes
- * the new selection. This only happens when the first item
- * is added.
- */
- if (count == 0) {
- OS.SetControl32BitValue (handle, 1);
- lastSelected = 0;
- Event event = new Event ();
- event.item = items [0];
- sendEvent (SWT.Selection, event);
- // the widget could be destroyed at this point
- }
-}
-
-void createWidget () {
- super.createWidget ();
- items = new TabItem [4];
-}
-
-void destroyItem (TabItem item) {
- int count = OS.GetControl32BitMaximum (handle);
- int index = 0;
- while (index < count) {
- if (items [index] == item) break;
- index++;
- }
- if (index == count) return;
- redrawWidget (handle, false);
- int selectionIndex = OS.GetControl32BitValue (handle) - 1;
- --count;
- OS.SetControl32BitMaximum (handle, count);
- System.arraycopy (items, index + 1, items, index, count - index);
- items [count] = null;
- if (count == 0) {
- items = new TabItem [4];
- }
- for (int i = index; i < count; i++) {
- items [i].update ();
- }
- if (count > 0 && index == selectionIndex) {
- setSelection (Math.max (0, selectionIndex - 1), true, true);
- }
- invalidateVisibleRegion (handle);
-}
-
-public Rectangle getClientArea () {
- checkWidget ();
- Rect client = new Rect ();
- if (OS.GetControlData (handle, (short)OS.kControlEntireControl, OS.kControlTabContentRectTag, Rect.sizeof, client, null) != OS.noErr) {
- return new Rectangle(0, 0, 0, 0);
- }
- int x = Math.max (0, client.left);
- int y = Math.max (0, client.top);
- int width = Math.max (0, client.right - client.left);
- int height = Math.max (0, client.bottom - client.top);
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem getItem (int index) {
- checkWidget ();
- int count = OS.GetControl32BitMaximum (handle);
- if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-
-/**
- * Returns the tab item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- *
- * @param point the point used to locate the item
- * @return the tab item at the given point, or null if the point is not in a tab item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public TabItem getItem(Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = OS.GetControl32BitMaximum (handle);
- for (int index = 0; index < count; index++) {
- TabItem item = items[index];
- Rectangle bounds = item.getBounds();
- if (bounds.contains(point)) return item;
- }
- return null;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return OS.GetControl32BitMaximum (handle);
-}
-
-/**
- * Returns an array of <code>TabItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem [] getItems () {
- checkWidget ();
- int count = OS.GetControl32BitMaximum (handle);
- TabItem [] result = new TabItem [count];
- System.arraycopy (items, 0, result, 0, count);
- return result;
-}
-
-/**
- * Returns an array of <code>TabItem</code>s that are currently
- * selected in the receiver. An empty array indicates that no
- * items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem [] getSelection () {
- checkWidget ();
- int index = OS.GetControl32BitValue(handle) - 1;
- if (index == -1) return new TabItem [0];
- return new TabItem [] {items [index]};
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget ();
- return OS.GetControl32BitValue (handle) - 1;
-}
-
-float getThemeAlpha () {
- return (background != null ? 1 : 0.25f) * parent.getThemeAlpha ();
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (TabItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = OS.GetControl32BitMaximum (handle);
- for (int i=0; i<count; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-
-Point minimumSize (int wHint, int hHint, boolean flushCache) {
- Control [] children = _getChildren ();
- int width = 0, height = 0;
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- int index = 0;
- int count = OS.GetControl32BitMaximum (handle);
- while (index < count) {
- if (items [index].control == child) break;
- index++;
- }
- if (index == count) {
- Rectangle rect = child.getBounds ();
- width = Math.max (width, rect.x + rect.width);
- height = Math.max (height, rect.y + rect.height);
- } else {
- Point size = child.computeSize (wHint, hHint, flushCache);
- width = Math.max (width, size.x);
- height = Math.max (height, size.y);
- }
- }
- return new Point (width, height);
-}
-
-Rect getInset () {
- if (OS.VERSION >= 0x1020) return super.getInset();
- return (style & SWT.BOTTOM) != 0 ? display.tabFolderSouthInset : display.tabFolderNorthInset;
-}
-
-int kEventControlApplyBackground (int nextHandler, int theEvent, int userData) {
- /*
- * Feature in the Macintosh. For some reason, the tab folder applies the
- * theme background when drawing even though a theme has not been set for
- * the window. The fix is to avoid running the default handler.
- */
- return OS.noErr;
-}
-
-int kEventControlHit (int nextHandler, int theEvent, int userData) {
- int result = super.kEventControlHit (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- int index = OS.GetControl32BitValue (handle) - 1;
- if (index == lastSelected) return result;
- lastSelected = index;
- int count = OS.GetControl32BitMaximum (handle);
- for (int i = 0; i < count; i++) {
- if (i != index) {
- Control control = items [i].control;
- if (control != null && !control.isDisposed ())
- control.setVisible (false);
- }
- }
- TabItem item = null;
- if (index != -1) item = items [index];
- if (item != null) {
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setBounds (getClientArea ());
- control.setVisible (true);
- }
- }
- Event event = new Event ();
- event.item = item;
- postEvent (SWT.Selection, event);
- return OS.noErr;
-}
-
-int kEventControlSetFocusPart (int nextHandler, int theEvent, int userData) {
- short [] part = new short [1];
- OS.GetEventParameter (theEvent, OS.kEventParamControlPart, OS.typeControlPartCode, null, 2, null, part);
- if (part [0] == OS.kControlFocusNoPart || part [0] == OS.kControlFocusNextPart) {
- return super.kEventControlSetFocusPart (nextHandler, theEvent, userData);
- }
- return OS.eventNotHandledErr;
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<items.length; i++) {
- TabItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- }
- super.releaseChildren (destroy);
-}
-
-void removeControl (Control control) {
- super.removeControl (control);
- int count = OS.GetControl32BitMaximum (handle);
- for (int i=0; i<count; i++) {
- TabItem item = items [i];
- if (item.control == control) item.setControl (null);
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- int result = super.setBounds(x, y, width, height, move, resize, events);
- if ((result & RESIZED) != 0) {
- int index = OS.GetControl32BitValue (handle) - 1;
- if (index != -1) {
- TabItem item = items [index];
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setBounds (getClientArea ());
- }
- }
- }
- return result;
-}
-
-/**
- * Sets the receiver's selection to the given item.
- * The current selected is first cleared, then the new item is
- * selected.
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection (TabItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (new TabItem [] {item});
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selected is first cleared, then the new items are
- * selected.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (TabItem [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (items.length == 0) {
- setSelection (-1, false, false);
- } else {
- for (int i=items.length - 1; i>=0; --i) {
- int index = indexOf (items [i]);
- if (index != -1) setSelection (index, false, false);
- }
- }
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains selected.
- * The current selection is first cleared, then the new items are
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int index) {
- checkWidget ();
- int count = OS.GetControl32BitMaximum (handle);
- if (!(0 <= index && index < count)) return;
- setSelection (index, false, false);
-}
-
-void setSelection (int index, boolean notify, boolean force) {
- if (index >= OS.GetControl32BitMaximum (handle)) return;
- int currentIndex = OS.GetControl32BitValue (handle) - 1;
- if (!force && currentIndex == index) return;
- if (currentIndex != -1) {
- TabItem item = items [currentIndex];
- if (item != null) {
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setVisible (false);
- }
- }
- }
- OS.SetControl32BitValue (handle, index+1);
- index = OS.GetControl32BitValue (handle) - 1;
- if (hasFocus ()) {
- int window = OS.GetControlOwner (handle);
- OS.SetKeyboardFocus (window, handle, (short) (index + 1));
- }
- lastSelected = index;
- if (index != -1) {
- TabItem item = items [index];
- if (item != null) {
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setBounds (getClientArea ());
- control.setVisible (true);
- }
- if (notify) {
- Event event = new Event ();
- event.item = item;
- sendEvent (SWT.Selection, event);
- }
- }
- }
-}
-
-boolean traversePage (boolean next) {
- int count = getItemCount ();
- if (count == 0) return false;
- int index = getSelectionIndex ();
- if (index == -1) {
- index = 0;
- } else {
- int offset = (next) ? 1 : -1;
- index = (index + offset + count) % count;
- }
- setSelection (index, true, false);
- return index == getSelectionIndex ();
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TabItem.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TabItem.java
deleted file mode 100644
index 6b6ffb0dca..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TabItem.java
+++ /dev/null
@@ -1,370 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.ControlTabInfoRecV1;
-import org.eclipse.swt.internal.carbon.ControlButtonContentInfo;
-import org.eclipse.swt.internal.carbon.Rect;
-
-/**
- * Instances of this class represent a selectable user interface object
- * corresponding to a tab for a page in a tab folder.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tabfolder">TabFolder, TabItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TabItem extends Item {
- TabFolder parent;
- Control control;
- String toolTipText;
-
- static final int EXTRA_WIDTH = 25;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>TabFolder</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabItem (TabFolder parent, int style) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>TabFolder</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabItem (TabFolder parent, int style, int index) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-int calculateWidth (GC gc) {
- int width = 0;
- Image image = getImage ();
- String text = getText ();
- if (image != null) width = image.getBounds ().width + 2;
- if (text != null && text.length () > 0) width += gc.stringExtent (text).x;
- return width + EXTRA_WIDTH;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public Rectangle getBounds() {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) return new Rectangle (0, 0, 0, 0);
- int rgnHandle = OS.NewRgn ();
- OS.GetControlRegion (parent.handle, (short) (index + 1), rgnHandle);
- Rect rect = new Rect ();
- OS.GetRegionBounds (rgnHandle, rect);
- OS.DisposeRgn (rgnHandle);
- return new Rectangle (rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
-}
-
-/**
- * Returns the control that is used to fill the client area of
- * the tab folder when the user selects the tab item. If no
- * control has been set, return <code>null</code>.
- * <p>
- * @return the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget ();
- return control;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>TabFolder</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabFolder getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- int index = parent.indexOf (this);
- if (index == parent.getSelectionIndex ()) {
- if (control != null) control.setVisible (false);
- }
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- control = null;
-}
-
-/**
- * Sets the control that is used to fill the client area of
- * the tab folder when the user selects the tab item.
- * <p>
- * @param control the new control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget ();
- if (control != null) {
- if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- if (this.control != null && this.control.isDisposed ()) {
- this.control = null;
- }
- Control oldControl = this.control, newControl = control;
- this.control = control;
- int index = parent.indexOf (this), selectionIndex = parent.getSelectionIndex();
- if (index != selectionIndex) {
- if (newControl != null) {
- if (selectionIndex != -1) {
- Control selectedControl = parent.getItem(selectionIndex).getControl();
- if (selectedControl == newControl) return;
- }
- newControl.setVisible(false);
- return;
- }
- }
- if (newControl != null) {
- newControl.setBounds (parent.getClientArea ());
- newControl.setVisible (true);
- }
- if (oldControl != null) oldControl.setVisible (false);
-}
-
-public void setImage (Image image) {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) return;
- super.setImage (image);
- ControlButtonContentInfo inContent = new ControlButtonContentInfo ();
- if (image == null) {
- inContent.contentType = (short)OS.kControlContentTextOnly;
- } else {
- inContent.contentType = (short)OS.kControlContentCGImageRef;
- inContent.iconRef = image.handle;
- }
- OS.SetControlData (parent.handle, index+1, OS.kControlTabImageContentTag, ControlButtonContentInfo.sizeof, inContent);
- parent.redraw ();
-}
-
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = parent.indexOf (this);
- if (index == -1) return;
- super.setText (string);
- char [] buffer = new char [text.length ()];
- text.getChars (0, buffer.length, buffer, 0);
- int length = fixMnemonic (buffer);
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, length);
- if (ptr == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- ControlTabInfoRecV1 tab = new ControlTabInfoRecV1 ();
- tab.version= (short) OS.kControlTabInfoVersionOne;
- tab.iconSuiteID = 0;
- tab.name = ptr;
- OS.SetControlData (parent.handle, index+1, OS.kControlTabInfoTag, ControlTabInfoRecV1.sizeof, tab);
- OS.CFRelease (ptr);
- if (image != null) {
- ControlButtonContentInfo inContent = new ControlButtonContentInfo ();
- inContent.contentType = (short)OS.kControlContentCGImageRef;
- inContent.iconRef = image.handle;
- OS.SetControlData (parent.handle, index+1, OS.kControlTabImageContentTag, ControlButtonContentInfo.sizeof, inContent);
- }
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
-}
-
-void update () {
- setText (text);
- setImage (image);
- setToolTipText (toolTipText);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Table.java
deleted file mode 100644
index 9420b27657..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Table.java
+++ /dev/null
@@ -1,3553 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.CFRange;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.DataBrowserCallbacks;
-import org.eclipse.swt.internal.carbon.DataBrowserCustomCallbacks;
-import org.eclipse.swt.internal.carbon.DataBrowserListViewColumnDesc;
-import org.eclipse.swt.internal.carbon.DataBrowserListViewHeaderDesc;
-import org.eclipse.swt.internal.carbon.DataBrowserAccessibilityItemInfo;
-import org.eclipse.swt.internal.carbon.HMHelpContentRec;
-import org.eclipse.swt.internal.carbon.Rect;
-import org.eclipse.swt.internal.carbon.CGPoint;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class implement a selectable user interface
- * object that displays a list of images and strings and issues
- * notification when selected.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TableItem</code>.
- * </p><p>
- * Style <code>VIRTUAL</code> is used to create a <code>Table</code> whose
- * <code>TableItem</code>s are to be populated by the client on an on-demand basis
- * instead of up-front. This can provide significant performance improvements for
- * tables that are very large or for which <code>TableItem</code> population is
- * expensive (for example, retrieving values from an external source).
- * </p><p>
- * Here is an example of using a <code>Table</code> with style <code>VIRTUAL</code>:
- * <code><pre>
- * final Table table = new Table (parent, SWT.VIRTUAL | SWT.BORDER);
- * table.setItemCount (1000000);
- * table.addListener (SWT.SetData, new Listener () {
- * public void handleEvent (Event event) {
- * TableItem item = (TableItem) event.item;
- * int index = table.indexOf (item);
- * item.setText ("Item " + index);
- * System.out.println (item.getText ());
- * }
- * });
- * </pre></code>
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not normally make sense to add <code>Control</code> children to
- * it, or set a layout on it, unless implementing something like a cell
- * editor.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, HIDE_SELECTION, VIRTUAL, NO_SCROLL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection, SetData, MeasureItem, EraseItem, PaintItem</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles SINGLE, and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Table extends Composite {
- TableItem [] items;
- TableColumn [] columns;
- TableItem currentItem;
- TableColumn sortColumn;
- GC paintGC;
- int sortDirection;
- int itemCount, columnCount, column_id, idCount, anchorFirst, anchorLast, savedAnchor, headerHeight, lastIndexOf;
- boolean ignoreSelect, wasSelected, fixScrollWidth, drawBackground;
- Rectangle imageBounds;
- int showIndex, lastHittest, lastHittestColumn;
- static final int CHECK_COLUMN_ID = 1024;
- static final int COLUMN_ID = 1025;
- static final int GRID_WIDTH = 1;
- static final int ICON_AND_TEXT_GAP = 4;
- static final int CELL_CONTENT_INSET = 12;
- static final int BORDER_INSET = 1;
- static final String [] AX_ATTRIBUTES = {
- OS.kAXChildrenAttribute,
- OS.kAXTitleAttribute,
- };
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#CHECK
- * @see SWT#FULL_SELECTION
- * @see SWT#HIDE_SELECTION
- * @see SWT#VIRTUAL
- * @see SWT#NO_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Table (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * If the receiver has the <code>SWT.CHECK</code> style and the check selection changes,
- * the event object detail field contains the value <code>SWT.CHECK</code>.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * The item field of the event object is valid for default selection, but the detail field is not used.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-void _addListener (int eventType, Listener listener) {
- super._addListener (eventType, listener);
- for (int i = 0; i < items.length; i++) {
- if (items [i] != null) items [i].width = -1;
- }
-}
-
-TableItem _getItem (int index) {
- if ((style & SWT.VIRTUAL) == 0) return items [index];
- if (items [index] != null) return items [index];
- return items [index] = new TableItem (this, SWT.NULL, -1, false);
-}
-
-int callPaintEventHandler (int control, int damageRgn, int visibleRgn, int theEvent, int nextHandler) {
- /*
- * Feature in the Macintosh. The draw item proc is not called if the column width
- * is zero. This means that the SWT.MeasureItem listener is not called and the column
- * does not get wider ever. The fix is to change the column width to one.
- */
- if (columnCount == 0 && (hooks (SWT.MeasureItem) || hooks (SWT.EraseItem) || hooks (SWT.PaintItem))) {
- short [] width = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (handle, column_id, width);
- if (width [0] == 0) {
- OS.SetDataBrowserTableViewNamedColumnWidth (handle, column_id, (short) 1);
- }
- }
- GC currentGC = paintGC;
- if (currentGC == null) {
- GCData data = new GCData ();
- data.paintEvent = theEvent;
- data.visibleRgn = visibleRgn;
- paintGC = GC.carbon_new (this, data);
- }
- fixScrollWidth = false;
- drawBackground = findBackgroundControl () != null;
- int result = super.callPaintEventHandler (control, damageRgn, visibleRgn, theEvent, nextHandler);
- if (itemCount == 0 && drawBackground) {
- drawBackground = false;
- Rectangle rect = getClientArea ();
- int headerHeight = getHeaderHeight ();
- rect.y += headerHeight;
- rect.height -= headerHeight;
- fillBackground (handle, paintGC.handle, rect);
- }
- if (fixScrollWidth) {
- fixScrollWidth = false;
- if (setScrollWidth (items, true)) redraw ();
- }
- if (currentGC == null) {
- paintGC.dispose ();
- paintGC = null;
- }
- return result;
-}
-
-boolean checkData (TableItem item, boolean redraw) {
- if (item.cached) return true;
- if ((style & SWT.VIRTUAL) != 0) {
- item.cached = true;
- Event event = new Event ();
- event.item = item;
- event.index = indexOf (item);
- currentItem = item;
- sendEvent (SWT.SetData, event);
- //widget could be disposed at this point
- currentItem = null;
- if (isDisposed () || item.isDisposed ()) return false;
- if (redraw) {
- if (!setScrollWidth (item)) item.redraw (OS.kDataBrowserNoItem);
- }
- }
- return true;
-}
-
-void checkItems (boolean setScrollWidth) {
- int [] count = new int [1];
- if (OS.GetDataBrowserItemCount (handle, OS.kDataBrowserNoItem, true, OS.kDataBrowserItemAnyState, count) != OS.noErr) {
- error (SWT.ERROR_CANNOT_GET_COUNT);
- }
- if (itemCount != count [0]) {
- /*
- * Feature in the Mac. When AddDataBrowserItems() is used
- * to add items, item notification callbacks are issued with
- * the message kDataBrowserItemAdded. When many items are
- * added, this is slow. The fix is to temporarily remove
- * the item notification callback.
- */
- DataBrowserCallbacks callbacks = new DataBrowserCallbacks ();
- OS.GetDataBrowserCallbacks (handle, callbacks);
- callbacks.v1_itemNotificationCallback = 0;
- OS.SetDataBrowserCallbacks (handle, callbacks);
- int delta = itemCount - count [0];
- if (delta < 1024) {
- int [] ids = new int [delta];
- for (int i=0; i<ids.length; i++) {
- ids [i] = count [0] + i + 1;
- }
- if (OS.AddDataBrowserItems (handle, OS.kDataBrowserNoItem, ids.length, ids, OS.kDataBrowserItemNoProperty) != OS.noErr) {
- error (SWT.ERROR_ITEM_NOT_ADDED);
- }
- OS.UpdateDataBrowserItems (handle, 0, 0, null, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem);
- } else {
- if (OS.AddDataBrowserItems (handle, 0, itemCount, null, OS.kDataBrowserItemNoProperty) != OS.noErr) {
- error (SWT.ERROR_ITEM_NOT_ADDED);
- }
- }
- callbacks.v1_itemNotificationCallback = display.itemNotificationProc;
- OS.SetDataBrowserCallbacks (handle, callbacks);
- }
- if (setScrollWidth) setScrollWidth (items, true);
-}
-
-static int checkStyle (int style) {
- /*
- * Feature in Windows. Even when WS_HSCROLL or
- * WS_VSCROLL is not specified, Windows creates
- * trees and tables with scroll bars. The fix
- * is to set H_SCROLL and V_SCROLL.
- *
- * NOTE: This code appears on all platforms so that
- * applications have consistent scroll bar behavior.
- */
- if ((style & SWT.NO_SCROLL) == 0) {
- style |= SWT.H_SCROLL | SWT.V_SCROLL;
- }
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Clears the item at the given zero-relative index in the receiver.
- * The text, icon and other attributes of the item are set to the default
- * value. If the table was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param index the index of the item to clear
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clear (int index) {
- checkWidget();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- TableItem item = items [index];
- if (item != null) {
- if (currentItem != item) item.clear ();
- if (currentItem == null && getDrawing ()) {
- int [] id = new int [] {getId (index)};
- OS.UpdateDataBrowserItems (handle, 0, id.length, id, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem);
- }
- setScrollWidth (item);
- }
-}
-
-/**
- * Removes the items from the receiver which are between the given
- * zero-relative start and end indices (inclusive). The text, icon
- * and other attributes of the items are set to their default values.
- * If the table was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param start the start index of the item to clear
- * @param end the end index of the item to clear
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clear (int start, int end) {
- checkWidget();
- if (start > end) return;
- if (!(0 <= start && start <= end && end < itemCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- if (start == 0 && end == itemCount - 1) {
- clearAll ();
- } else {
- for (int i=start; i<=end; i++) {
- clear (i);
- }
- }
-}
-
-/**
- * Clears the items at the given zero-relative indices in the receiver.
- * The text, icon and other attributes of the items are set to their default
- * values. If the table was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clear (int [] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- for (int i=0; i<indices.length; i++) {
- if (!(0 <= indices [i] && indices [i] < itemCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- }
- for (int i=0; i<indices.length; i++) {
- clear (indices [i]);
- }
-}
-
-/**
- * Clears all the items in the receiver. The text, icon and other
- * attributes of the items are set to their default values. If the
- * table was created with the <code>SWT.VIRTUAL</code> style, these
- * attributes are requested again as needed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clearAll () {
- checkWidget();
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (item != null) item.clear ();
- }
- if (currentItem == null && getDrawing ()) {
- OS.UpdateDataBrowserItems (handle, 0, 0, null, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem);
- }
- setScrollWidth (items, true);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = 0;
- if (wHint == SWT.DEFAULT) {
- if (columnCount != 0) {
- for (int i=0; i<columnCount; i++) {
- width += columns [i].getWidth ();
- }
- } else {
- int columnWidth = 0;
- GC gc = new GC (this);
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (item != null) {
- columnWidth = Math.max (columnWidth, item.calculateWidth (0, gc));
- }
- }
- gc.dispose ();
- width += columnWidth + getInsetWidth ();
- }
- if ((style & SWT.CHECK) != 0) width += getCheckColumnWidth ();
- } else {
- width = wHint;
- }
- if (width <= 0) width = DEFAULT_WIDTH;
- int height = 0;
- if (hHint == SWT.DEFAULT) {
- height = itemCount * getItemHeight () + getHeaderHeight();
- } else {
- height = hHint;
- }
- if (height <= 0) height = DEFAULT_HEIGHT;
- Rectangle rect = computeTrim (0, 0, width, height);
- return new Point (rect.width, rect.height);
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- int border = getBorderWidth ();
- Rect rect = new Rect ();
- OS.GetDataBrowserScrollBarInset (handle, rect);
- x -= rect.left + border;
- y -= rect.top + border;
- width += rect.left + rect.right + border + border;
- height += rect.top + rect.bottom + border + border;
- return new Rectangle (x, y, width, height);
-}
-
-boolean contains(int shellX, int shellY) {
- CGPoint pt = new CGPoint ();
- int [] contentView = new int [1];
- OS.HIViewFindByID (OS.HIViewGetRoot (OS.GetControlOwner (handle)), OS.kHIViewWindowContentID (), contentView);
- OS.HIViewConvertPoint (pt, handle, contentView [0]);
- int x = shellX - (int) pt.x;
- int y = shellY - (int) pt.y;
- if (y < getHeaderHeight ()) return false;
- return getClientArea ().contains (x, y);
-}
-
-void createHandle () {
- column_id = COLUMN_ID;
- int [] outControl = new int [1];
- int window = OS.GetControlOwner (parent.handle);
- OS.CreateDataBrowserControl (window, null, OS.kDataBrowserListView, outControl);
- OS.SetAutomaticControlDragTrackingEnabledForWindow (window, true);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
- if (!drawFocusRing ()) {
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlDataBrowserIncludesFrameAndFocusTag, 1, new byte[] {0});
- }
- int selectionFlags = (style & SWT.SINGLE) != 0 ? OS.kDataBrowserSelectOnlyOne | OS.kDataBrowserNeverEmptySelectionSet : OS.kDataBrowserCmdTogglesSelection;
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags);
- short [] height = new short [1];
- OS.GetDataBrowserListViewHeaderBtnHeight (handle, height);
- headerHeight = height [0];
- OS.SetDataBrowserListViewHeaderBtnHeight (handle, (short) 0);
- OS.SetDataBrowserHasScrollBars (handle, (style & SWT.H_SCROLL) != 0, (style & SWT.V_SCROLL) != 0);
- if (OS.VERSION >= 0x1040) {
- OS.DataBrowserSetMetric (handle, OS.kDataBrowserMetricCellContentInset, false, 4);
- }
- int position = 0;
- if ((style & SWT.CHECK) != 0) {
- DataBrowserListViewColumnDesc checkColumn = new DataBrowserListViewColumnDesc ();
- checkColumn.headerBtnDesc_version = OS.kDataBrowserListViewLatestHeaderDesc;
- checkColumn.propertyDesc_propertyID = CHECK_COLUMN_ID;
- checkColumn.propertyDesc_propertyType = OS.kDataBrowserCheckboxType;
- checkColumn.propertyDesc_propertyFlags = OS.kDataBrowserPropertyIsMutable;
- int checkWidth = getCheckColumnWidth ();
- checkColumn.headerBtnDesc_minimumWidth = (short) checkWidth;
- checkColumn.headerBtnDesc_maximumWidth = (short) checkWidth;
- checkColumn.headerBtnDesc_initialOrder = (short) OS.kDataBrowserOrderIncreasing;
- OS.AddDataBrowserListViewColumn (handle, checkColumn, position++);
- }
- DataBrowserListViewColumnDesc column = new DataBrowserListViewColumnDesc ();
- column.headerBtnDesc_version = OS.kDataBrowserListViewLatestHeaderDesc;
- column.propertyDesc_propertyID = column_id;
- column.propertyDesc_propertyType = OS.kDataBrowserCustomType;
- column.propertyDesc_propertyFlags = OS.kDataBrowserListViewSelectionColumn | OS.kDataBrowserDefaultPropertyFlags | OS.kDataBrowserListViewSortableColumn;
- column.headerBtnDesc_maximumWidth = 0x7fff;
- column.headerBtnDesc_initialOrder = (short) OS.kDataBrowserOrderIncreasing;
- OS.AddDataBrowserListViewColumn (handle, column, position);
- OS.SetDataBrowserTableViewNamedColumnWidth (handle, column_id, (short) 0);
-
- /*
- * Feature in the Macintosh. Scroll bars are not created until
- * the data browser needs to draw them. The fix is to force the scroll
- * bars to be created by temporarily giving the widget a size, drawing
- * it on a offscreen buffer to avoid flashes and then restoring it to
- * size zero.
- */
- if (OS.VERSION < 0x1040) {
- OS.HIViewSetDrawingEnabled (handle, false);
- int size = 50;
- Rect rect = new Rect ();
- rect.right = rect.bottom = (short) size;
- OS.SetControlBounds (handle, rect);
- int bpl = size * 4;
- int [] gWorld = new int [1];
- int data = OS.NewPtr (bpl * size);
- OS.NewGWorldFromPtr (gWorld, OS.k32ARGBPixelFormat, rect, 0, 0, 0, data, bpl);
- int [] curPort = new int [1];
- int [] curGWorld = new int [1];
- OS.GetGWorld (curPort, curGWorld);
- OS.SetGWorld (gWorld [0], curGWorld [0]);
- OS.DrawControlInCurrentPort (handle);
- OS.SetGWorld (curPort [0], curGWorld [0]);
- OS.DisposeGWorld (gWorld [0]);
- OS.DisposePtr (data);
- rect.right = rect.bottom = (short) 0;
- OS.SetControlBounds (handle, rect);
- OS.HIViewSetDrawingEnabled (handle, true);
- }
-}
-
-void createItem (TableColumn column, int index) {
- if (!(0 <= index && index <= columnCount)) error (SWT.ERROR_INVALID_RANGE);
- column.id = column_id + idCount++;
- int position = index + ((style & SWT.CHECK) != 0 ? 1 : 0);
- if (columnCount != 0) {
- DataBrowserListViewColumnDesc desc = new DataBrowserListViewColumnDesc ();
- desc.headerBtnDesc_version = OS.kDataBrowserListViewLatestHeaderDesc;
- desc.propertyDesc_propertyID = column.id;
- desc.propertyDesc_propertyType = OS.kDataBrowserCustomType;
- desc.propertyDesc_propertyFlags = OS.kDataBrowserListViewSelectionColumn | OS.kDataBrowserDefaultPropertyFlags | OS.kDataBrowserListViewSortableColumn;
- desc.headerBtnDesc_maximumWidth = 0x7fff;
- desc.headerBtnDesc_initialOrder = OS.kDataBrowserOrderIncreasing;
- desc.headerBtnDesc_btnFontStyle_just = OS.teFlushLeft;
- if ((style & SWT.CENTER) != 0) desc.headerBtnDesc_btnFontStyle_just = OS.teCenter;
- if ((style & SWT.RIGHT) != 0) desc.headerBtnDesc_btnFontStyle_just = OS.teFlushRight;
- desc.headerBtnDesc_btnFontStyle_flags |= OS.kControlUseJustMask;
- OS.AddDataBrowserListViewColumn (handle, desc, position);
- OS.SetDataBrowserTableViewNamedColumnWidth (handle, column.id, (short)0);
- }
- if (columnCount == columns.length) {
- TableColumn [] newColumns = new TableColumn [columnCount + 4];
- System.arraycopy (columns, 0, newColumns, 0, columns.length);
- columns = newColumns;
- }
- System.arraycopy (columns, index, columns, index + 1, columnCount++ - index);
- columns [index] = column;
- if (columnCount > 1) {
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (item != null) {
- String [] strings = item.strings;
- if (strings != null) {
- String [] temp = new String [columnCount];
- System.arraycopy (strings, 0, temp, 0, index);
- System.arraycopy (strings, index, temp, index+1, columnCount-index-1);
- temp [index] = "";
- item.strings = temp;
- }
- if (index == 0) item.text = "";
- Image [] images = item.images;
- if (images != null) {
- Image [] temp = new Image [columnCount];
- System.arraycopy (images, 0, temp, 0, index);
- System.arraycopy (images, index, temp, index+1, columnCount-index-1);
- item.images = temp;
- }
- if (index == 0) item.image = null;
- Color [] cellBackground = item.cellBackground;
- if (cellBackground != null) {
- Color [] temp = new Color [columnCount];
- System.arraycopy (cellBackground, 0, temp, 0, index);
- System.arraycopy (cellBackground, index, temp, index+1, columnCount-index-1);
- item.cellBackground = temp;
- }
- Color [] cellForeground = item.cellForeground;
- if (cellForeground != null) {
- Color [] temp = new Color [columnCount];
- System.arraycopy (cellForeground, 0, temp, 0, index);
- System.arraycopy (cellForeground, index, temp, index+1, columnCount-index-1);
- item.cellForeground = temp;
- }
- Font [] cellFont = item.cellFont;
- if (cellFont != null) {
- Font [] temp = new Font [columnCount];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index, temp, index+1, columnCount-index-1);
- item.cellFont = temp;
- }
- }
- }
- }
- int [] lastPosition = new int [1];
- for (int i=0; i<columnCount; i++) {
- TableColumn c = columns [i];
- OS.GetDataBrowserTableViewColumnPosition (handle, c.id, lastPosition);
- c.lastPosition = lastPosition [0];
- }
-}
-
-void createItem (TableItem item, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (savedAnchor != 0) {
- int savedIndex = getIndex (savedAnchor);
- if (index <= savedIndex) {
- savedAnchor = getId (Math.min (itemCount - 1, savedIndex + 1));
- }
- }
- boolean add = getDrawing () || index != itemCount;
- if (add) {
- checkItems (false);
- int [] id = new int [] {itemCount + 1};
- if (OS.AddDataBrowserItems (handle, OS.kDataBrowserNoItem, 1, id, OS.kDataBrowserItemNoProperty) != OS.noErr) {
- error (SWT.ERROR_ITEM_NOT_ADDED);
- }
- if (index != itemCount) fixSelection (index, true);
- }
- if (itemCount == items.length) {
- /* Grow the array faster when redraw is off */
- int length = getDrawing () ? items.length + 4 : Math.max (4, items.length * 3 / 2);
- TableItem [] newItems = new TableItem [length];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- System.arraycopy (items, index, items, index + 1, itemCount++ - index);
- items [index] = item;
- if (add) OS.UpdateDataBrowserItems (handle, 0, 0, null, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem);
-}
-
-ScrollBar createScrollBar (int style) {
- return createStandardBar (style);
-}
-
-void createWidget () {
- super.createWidget ();
- items = new TableItem [4];
- columns = new TableColumn [4];
- showIndex = -1;
- if (OS.VERSION >= 0x1050) {
- OS.DataBrowserChangeAttributes (handle, OS.kDataBrowserAttributeAutoHideScrollBars, 0);
- }
-}
-
-Color defaultBackground () {
- return display.getSystemColor (SWT.COLOR_LIST_BACKGROUND);
-}
-
-Color defaultForeground () {
- return display.getSystemColor (SWT.COLOR_LIST_FOREGROUND);
-}
-
-int defaultThemeFont () {
- if (display.smallFonts) return OS.kThemeSmallSystemFont;
- return OS.kThemeViewsFont;
-}
-
-/**
- * Deselects the item at the given zero-relative index in the receiver.
- * If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget();
- if (0 <= index && index < itemCount) {
- int [] ids = new int [] {getId (index)};
- deselect (ids, ids.length);
- }
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. The range of the
- * indices is inclusive. Indices that are out of range are ignored.
- *
- * @param start the start index of the items to deselect
- * @param end the end index of the items to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int start, int end) {
- checkWidget();
- //TODO - check range
- if (start == 0 && end == itemCount - 1) {
- deselectAll ();
- } else {
- int length = end - start + 1;
- if (length <= 0) return;
- int [] ids = new int [length];
- for (int i=0; i<length; i++) ids [i] = getId (end - i);
- deselect (ids, length);
- }
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. Indices that are out
- * of range and duplicate indices are ignored.
- *
- * @param indices the array of indices for the items to deselect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int [] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- //TODO - check range
- int length = indices.length;
- int [] ids = new int [length];
- for (int i=0; i<length; i++) ids [i] = getId (indices [length - i - 1]);
- deselect (ids, length);
-}
-
-void deselect (int [] ids, int count) {
- ignoreSelect = true;
- /*
- * Bug in the Macintosh. When the DataBroswer selection flags includes
- * both kDataBrowserNeverEmptySelectionSet and kDataBrowserSelectOnlyOne,
- * two items are selected when SetDataBrowserSelectedItems() is called
- * with kDataBrowserItemsAssign to assign a new seletion despite the fact
- * that kDataBrowserSelectOnlyOne was specified. The fix is to save and
- * restore kDataBrowserNeverEmptySelectionSet around each call to
- * SetDataBrowserSelectedItems().
- */
- int [] selectionFlags = null;
- if ((style & SWT.SINGLE) != 0) {
- selectionFlags = new int [1];
- OS.GetDataBrowserSelectionFlags (handle, selectionFlags);
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0] & ~OS.kDataBrowserNeverEmptySelectionSet);
- }
- OS.SetDataBrowserSelectedItems (handle, count, ids, OS.kDataBrowserItemsRemove);
- if ((style & SWT.SINGLE) != 0) {
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0]);
- }
- ignoreSelect = false;
-}
-
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll () {
- checkWidget ();
- deselect (null, 0);
-}
-
-void destroyItem (TableColumn column) {
- int index = 0;
- while (index < columnCount) {
- if (columns [index] == column) break;
- index++;
- }
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (item != null) {
- if (columnCount <= 1) {
- item.strings = null;
- item.images = null;
- item.cellBackground = null;
- item.cellForeground = null;
- item.cellFont = null;
- } else {
- if (item.strings != null) {
- String [] strings = item.strings;
- if (index == 0) {
- item.text = strings [1] != null ? strings [1] : "";
- }
- String [] temp = new String [columnCount - 1];
- System.arraycopy (strings, 0, temp, 0, index);
- System.arraycopy (strings, index + 1, temp, index, columnCount - 1 - index);
- item.strings = temp;
- } else {
- if (index == 0) item.text = "";
- }
- if (item.images != null) {
- Image [] images = item.images;
- if (index == 0) item.image = images [1];
- Image [] temp = new Image [columnCount - 1];
- System.arraycopy (images, 0, temp, 0, index);
- System.arraycopy (images, index + 1, temp, index, columnCount - 1 - index);
- item.images = temp;
- } else {
- if (index == 0) item.image = null;
- }
- if (item.cellBackground != null) {
- Color [] cellBackground = item.cellBackground;
- Color [] temp = new Color [columnCount - 1];
- System.arraycopy (cellBackground, 0, temp, 0, index);
- System.arraycopy (cellBackground, index + 1, temp, index, columnCount - 1 - index);
- item.cellBackground = temp;
- }
- if (item.cellForeground != null) {
- Color [] cellForeground = item.cellForeground;
- Color [] temp = new Color [columnCount - 1];
- System.arraycopy (cellForeground, 0, temp, 0, index);
- System.arraycopy (cellForeground, index + 1, temp, index, columnCount - 1 - index);
- item.cellForeground = temp;
- }
- if (item.cellFont != null) {
- Font [] cellFont = item.cellFont;
- Font [] temp = new Font [columnCount - 1];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index + 1, temp, index, columnCount - 1 - index);
- item.cellFont = temp;
- }
- }
- }
- }
- if (columnCount == 1) {
- column_id = column.id; idCount = 0;
- DataBrowserListViewHeaderDesc desc = new DataBrowserListViewHeaderDesc ();
- desc.version = OS.kDataBrowserListViewLatestHeaderDesc;
- short [] width = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (handle, column_id, width);
- desc.minimumWidth = desc.maximumWidth = width [0];
- int str = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, null, 0);
- desc.titleString = str;
- OS.SetDataBrowserListViewHeaderDesc (handle, column_id, desc);
- OS.CFRelease (str);
- } else {
- if (OS.RemoveDataBrowserTableViewColumn (handle, column.id) != OS.noErr) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- }
- System.arraycopy (columns, index + 1, columns, index, --columnCount - index);
- columns [columnCount] = null;
- for (int i=index; i<columnCount; i++) {
- columns [i].sendEvent (SWT.Move);
- }
-}
-
-void destroyItem (TableItem item) {
- int index = 0;
- while (index < itemCount) {
- if (items [index] == item) break;
- index++;
- }
- if (savedAnchor != 0) {
- int savedIndex = getIndex (savedAnchor);
- if (index < savedIndex) {
- savedAnchor = getId (Math.max (0, savedIndex - 1));
- }
- }
- if (index != itemCount - 1) fixSelection (index, false);
- int [] id = new int [] {itemCount};
- if (OS.RemoveDataBrowserItems (handle, OS.kDataBrowserNoItem, id.length, id, 0) != OS.noErr) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- OS.UpdateDataBrowserItems (handle, 0, 0, null, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem);
- if (itemCount == 0) {
- setTableEmpty ();
- } else {
- fixScrollBar ();
- }
-}
-
-void destroyScrollBar (ScrollBar bar) {
- if ((bar.style & SWT.H_SCROLL) != 0) style &= ~SWT.H_SCROLL;
- if ((bar.style & SWT.V_SCROLL) != 0) style &= ~SWT.V_SCROLL;
- OS.SetDataBrowserHasScrollBars (handle, (style & SWT.H_SCROLL) != 0, (style & SWT.V_SCROLL) != 0);
-}
-
-int drawItemProc (int browser, int id, int property, int itemState, int theRect, int gdDepth, int colorDevice) {
- int index = getIndex (id);
- if (!(0 <= index && index < itemCount)) return OS.noErr;
- int columnIndex = 0;
- if (columnCount > 0) {
- for (columnIndex=0; columnIndex<columnCount; columnIndex++) {
- if (columns [columnIndex].id == property) break;
- }
- if (columnIndex == columnCount) return OS.noErr;
- }
- Rect rect = new Rect ();
- lastIndexOf = index;
- TableItem item = _getItem (index);
- if ((style & SWT.VIRTUAL) != 0) {
- if (!item.cached) {
- if (!checkData (item, false)) return OS.noErr;
- if (setScrollWidth (item)) {
- if (OS.GetDataBrowserItemPartBounds (handle, id, property, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- int x = rect.left;
- int y = rect.top;
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- redrawWidget (handle, x, y, width, height, false);
- }
- return OS.noErr;
- }
- }
- }
- OS.memmove (rect, theRect, Rect.sizeof);
- int x = rect.left;
- int y = rect.top;
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- GC gc = paintGC;
- if (gc == null) {
- GCData data = new GCData ();
- int [] port = new int [1];
- OS.GetPort (port);
- data.port = port [0];
- gc = GC.carbon_new (this, data);
- }
- OS.GetDataBrowserItemPartBounds (handle, id, property, OS.kDataBrowserPropertyEnclosingPart, rect);
- int gridWidth = getLinesVisible () ? GRID_WIDTH : 0;
- int itemX = rect.left + gridWidth;
- int itemY = rect.top;
- int itemWidth = rect.right - rect.left - gridWidth;
- int itemHeight = rect.bottom - rect.top + 1;
- if (drawBackground) {
- drawBackground = false;
- Region region = new Region (display);
- Rectangle clientArea = getClientArea ();
- int headerHeight = getHeaderHeight ();
- clientArea.y += headerHeight;
- clientArea.height -= headerHeight;
- if (clientArea.height < 0) clientArea.height = 0;
- region.add (clientArea);
- if ((style & SWT.CHECK) != 0 || gridWidth != 0) {
- int rgn = OS.NewRgn();
- if ((style & SWT.CHECK) != 0) {
- if (OS.GetDataBrowserItemPartBounds (handle, id, Table.CHECK_COLUMN_ID, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- OS.SetRectRgn (rgn, (short)rect.left, (short)clientArea.y, (short)(rect.right + gridWidth), (short)(clientArea.y + clientArea.height));
- OS.DiffRgn (region.handle, rgn, region.handle);
- }
- }
- if (gridWidth != 0) {
- if (columnCount == 0) {
- if (OS.GetDataBrowserItemPartBounds (handle, id, Table.COLUMN_ID, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- OS.SetRectRgn (rgn, (short)rect.right, (short)clientArea.y, (short)(rect.right + gridWidth), (short)(clientArea.y + clientArea.height));
- OS.DiffRgn (region.handle, rgn, region.handle);
- }
- } else {
- for (int i = 0; i < columnCount; i++) {
- if (OS.GetDataBrowserItemPartBounds (handle, id, columns[i].id, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- OS.SetRectRgn (rgn, (short)rect.right, (short)clientArea.y, (short)(rect.right + gridWidth), (short)(clientArea.y + clientArea.height));
- OS.DiffRgn (region.handle, rgn, region.handle);
- }
- }
- }
- }
- OS.DisposeRgn (rgn);
- }
- if (region != null) gc.setClipping (region);
- fillBackground (handle, gc.handle, null);
- if (region != null) {
- gc.setClipping ((Rectangle)null);
- region.dispose ();
- }
- }
- OS.CGContextSaveGState (gc.handle);
- int itemRgn = OS.NewRgn ();
- OS.SetRectRgn (itemRgn, (short) itemX, (short) itemY, (short) (itemX + itemWidth), (short) (itemY + itemHeight));
- int clip = OS.NewRgn ();
- OS.GetClip (clip);
- OS.SectRgn (clip, itemRgn, itemRgn);
- OS.DisposeRgn (clip);
- Region region = Region.carbon_new (display, itemRgn);
- Font font = item.getFont (columnIndex);
- Color background = item.getBackground (columnIndex);
- Color foreground = item.getForeground (columnIndex);
- Image image = item.getImage (columnIndex);
- String text = item.getText (columnIndex);
- gc.setClipping (region);
- gc.setFont (font);
- Point extent = gc.stringExtent (text);
- int contentWidth = extent.x;
- Rectangle imageBounds = null;
- int gap = 0;
- if (image != null) {
- gap = getGap ();
- imageBounds = image.getBounds ();
- contentWidth += this.imageBounds.width + gap;
- }
- int paintWidth = contentWidth;
- if (hooks (SWT.MeasureItem)) {
- Event event = new Event ();
- event.item = item;
- event.index = columnIndex;
- event.gc = gc;
- event.width = contentWidth;
- event.height = itemHeight;
- sendEvent (SWT.MeasureItem, event);
- if (itemHeight < event.height) {
- itemHeight = event.height;
- OS.SetDataBrowserTableViewRowHeight (handle, (short) event.height);
- redrawWidget (handle, false);
- }
- if (setScrollWidth (item)) {
- redrawWidget (handle, false);
- }
- contentWidth = event.width;
- gc.setClipping (region);
- gc.setFont (font);
- }
- int drawState = SWT.FOREGROUND;
- if (item.background != null || (item.cellBackground != null && item.cellBackground [columnIndex] != null)) drawState |= SWT.BACKGROUND;
- if ((itemState & (OS.kDataBrowserItemIsSelected | OS.kDataBrowserItemIsDragTarget)) != 0) drawState |= SWT.SELECTED;
- boolean wasSelected = (drawState & SWT.SELECTED) != 0;
- if ((drawState & SWT.SELECTED) != 0 && ((style & SWT.FULL_SELECTION) != 0 || columnIndex == 0)) {
- gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION));
- gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT));
- } else {
- gc.setBackground (background);
- gc.setForeground (foreground);
- }
- if (hooks (SWT.EraseItem)) {
- Event event = new Event ();
- event.item = item;
- event.index = columnIndex;
- event.gc = gc;
- event.x = itemX;
- event.y = itemY;
- event.width = itemWidth;
- event.height = itemHeight;
- event.detail = drawState;
- sendEvent (SWT.EraseItem, event);
- drawState = event.doit ? event.detail : 0;
- gc.setClipping (region);
- gc.setFont (font);
- if ((drawState & SWT.SELECTED) != 0 && ((style & SWT.FULL_SELECTION) != 0 || columnIndex == 0)) {
- gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION));
- gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT));
- } else {
- gc.setBackground (background);
- if (!wasSelected) gc.setForeground (foreground);
- }
- }
- if (columnCount != 0 && columnIndex != 0) {
- TableColumn column = columns [columnIndex];
- if ((column.style & SWT.CENTER) != 0) x += (width - contentWidth) / 2;
- if ((column.style & SWT.RIGHT) != 0) x += width - contentWidth;
- }
- int stringX = x, imageWidth = 0;
- if (image != null) stringX += imageWidth = this.imageBounds.width + gap;
- if ((drawState & SWT.SELECTED) != 0 && ((style & SWT.FULL_SELECTION) != 0 || columnIndex == 0)) {
- if ((style & SWT.HIDE_SELECTION) == 0 || hasFocus ()) {
- if ((style & SWT.FULL_SELECTION) != 0) {
- gc.fillRectangle (itemX, itemY, itemWidth, itemHeight - 1);
- drawState &= ~SWT.BACKGROUND;
- } else if (columnIndex == 0) {
- gc.fillRectangle (stringX - 1, y, (contentWidth - imageWidth) + 2, itemHeight - 1);
- drawState &= ~SWT.BACKGROUND;
- }
- } else {
- if ((drawState & SWT.BACKGROUND) != 0) gc.setBackground (background);
- }
- }
- if ((drawState & SWT.BACKGROUND) != 0) {
- if (columnCount == 0) {
- gc.fillRectangle (stringX - 1, y, (contentWidth - imageWidth) + 2, itemHeight - 1);
- } else {
- gc.fillRectangle (itemX, itemY, itemWidth, itemHeight);
- }
- }
- if ((drawState & SWT.FOREGROUND) != 0) {
- if (image != null) {
- int imageX = x, imageY = y + (height - this.imageBounds.height) / 2;
- gc.drawImage (image, 0, 0, imageBounds.width, imageBounds.height, imageX, imageY, this.imageBounds.width, this.imageBounds.height);
- }
- gc.drawString (text, stringX, y + (height - extent.y) / 2, true);
- }
- if (hooks (SWT.PaintItem)) {
- Event event = new Event ();
- event.item = item;
- event.index = columnIndex;
- event.gc = gc;
- event.x = x;
- event.y = y;
- event.width = paintWidth;
- event.height = itemHeight;
- event.detail = drawState;
- sendEvent (SWT.PaintItem, event);
- }
- OS.CGContextRestoreGState (gc.handle);
- OS.DisposeRgn (itemRgn);
- if (gc != paintGC) gc.dispose ();
- return OS.noErr;
-}
-
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- /*
- * Bug in the Macintosh. For some reason, the data browser does not
- * redraw the checkboxes when the enable state changes. The fix is
- * to force a redraw.
- */
- redrawWidget (handle, false);
-}
-
-void fixScrollBar () {
- /*
- * Bug in the Macintosh. For some reason, the data browser does not update
- * the vertical scrollbar when it is scrolled to the bottom and items are
- * removed. The fix is to check if the scrollbar value is bigger the
- * maximum number of visible items and clamp it when needed.
- */
- int [] top = new int [1], left = new int [1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- int maximum = Math.max (0, getItemHeight () * itemCount - getClientArea ().height);
- if (top [0] > maximum) {
- OS.SetDataBrowserScrollPosition (handle, maximum, left [0]);
- }
-}
-
-void fixSelection (int index, boolean add) {
- int [] selection = getSelectionIndices ();
- if (selection.length == 0) return;
- int newCount = 0, offset = add ? 1 : -1;
- boolean fix = false, down = sortDirection == SWT.DOWN && sortColumn != null;
- for (int i = 0; i < selection.length; i++) {
- if (!add && selection [i] == index) {
- fix = true;
- } else {
- int newIndex = newCount++;
- int sel = selection [i];
- selection [newIndex] = getId (sel);
- if ((down && sel < index) || (!down && sel >= index)) {
- selection [newIndex] += offset;
- fix = true;
- }
- }
- }
- if (fix) select (selection, newCount, true);
-}
-
-String [] getAxAttributes () {
- return AX_ATTRIBUTES;
-}
-
-public int getBorderWidth () {
- checkWidget ();
- int border = 0;
- byte [] hasBorder = new byte [1];
- OS.GetControlData (handle, (short) OS.kControlEntireControl, OS.kControlDataBrowserIncludesFrameAndFocusTag, 1, hasBorder, null);
- if (hasBorder [0] != 0) {
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricFocusRectOutset, outMetric);
- border += outMetric [0] - BORDER_INSET;
- }
- return border;
-}
-
-int getCheckColumnWidth () {
- int inset = 0;
- if (OS.VERSION >= 0x1040) {
- float [] metric = new float [1];
- OS.DataBrowserGetMetric (handle, OS.kDataBrowserMetricCellContentInset, null, metric);
- inset = (int) metric [0];
- } else {
- inset = CELL_CONTENT_INSET;
- }
- int [] checkWidth = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricCheckBoxWidth, checkWidth);
- return checkWidth [0] + inset * 2;
-}
-
-public Rectangle getClientArea () {
- checkWidget();
- int border = getBorderWidth ();
- Rect rect = new Rect (), inset = new Rect ();
- OS.GetControlBounds (handle, rect);
- OS.GetDataBrowserScrollBarInset (handle, inset);
- int width = Math.max (0, rect.right - rect.left - inset.right - border - border);
- int height = Math.max (0, rect.bottom - rect.top - inset.bottom - border - border);
- return new Rectangle (inset.left + border, inset.top + border, width, height);
-}
-
-/**
- * Returns the column at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- * Columns are returned in the order that they were created.
- * If no <code>TableColumn</code>s were created by the programmer,
- * this method will throw <code>ERROR_INVALID_RANGE</code> despite
- * the fact that a single column of data may be visible in the table.
- * This occurs when the programmer uses the table like a list, adding
- * items but never creating a column.
- *
- * @param index the index of the column to return
- * @return the column at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- */
-public TableColumn getColumn (int index) {
- checkWidget ();
- if (!(0 <=index && index < columnCount)) error (SWT.ERROR_INVALID_RANGE);
- return columns [index];
-}
-
-/**
- * Returns the number of columns contained in the receiver.
- * If no <code>TableColumn</code>s were created by the programmer,
- * this value is zero, despite the fact that visually, one column
- * of items may be visible. This occurs when the programmer uses
- * the table like a list, adding items but never creating a column.
- *
- * @return the number of columns
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getColumnCount () {
- checkWidget ();
- return columnCount;
-}
-
-/**
- * Returns an array of zero-relative integers that map
- * the creation order of the receiver's items to the
- * order in which they are currently being displayed.
- * <p>
- * Specifically, the indices of the returned array represent
- * the current visual order of the items, and the contents
- * of the array represent the creation order of the items.
- * </p><p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the current visual order of the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public int [] getColumnOrder () {
- checkWidget ();
- int [] order = new int [columnCount];
- int [] position = new int [1];
- for (int i=0; i<columnCount; i++) {
- TableColumn column = columns [i];
- OS.GetDataBrowserTableViewColumnPosition (handle, column.id, position);
- if ((style & SWT.CHECK) != 0) position [0] -= 1;
- order [position [0]] = i;
- }
- return order;
-}
-
-/**
- * Returns an array of <code>TableColumn</code>s which are the
- * columns in the receiver. Columns are returned in the order
- * that they were created. If no <code>TableColumn</code>s were
- * created by the programmer, the array is empty, despite the fact
- * that visually, one column of items may be visible. This occurs
- * when the programmer uses the table like a list, adding items but
- * never creating a column.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- */
-public TableColumn [] getColumns () {
- checkWidget ();
- TableColumn [] result = new TableColumn [columnCount];
- System.arraycopy (columns, 0, result, 0, columnCount);
- return result;
-}
-
-int getGap () {
- if (OS.VERSION >= 0x1040) {
- float [] metric = new float [1];
- OS.DataBrowserGetMetric (handle, OS.kDataBrowserMetricIconAndTextGap, null, metric);
- return (int) metric [0];
- }
- return ICON_AND_TEXT_GAP;
-}
-
-/**
- * Returns the width in pixels of a grid line.
- *
- * @return the width of a grid line in pixels
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getGridLineWidth () {
- checkWidget ();
- return 0;
-}
-
-/**
- * Returns the height of the receiver's header
- *
- * @return the height of the header or zero if the header is not visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public int getHeaderHeight () {
- checkWidget ();
- short [] height = new short [1];
- OS.GetDataBrowserListViewHeaderBtnHeight (handle, height);
- return height [0];
-}
-
-/**
- * Returns <code>true</code> if the receiver's header is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's header's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getHeaderVisible () {
- checkWidget ();
- short [] height = new short [1];
- OS.GetDataBrowserListViewHeaderBtnHeight (handle, height);
- return height [0] != 0;
-}
-
-int getId (int index) {
- if (sortDirection == SWT.DOWN && sortColumn != null) {
- return itemCount - index;
- }
- return index + 1;
-}
-
-int getIndex (int id) {
- if (sortDirection == SWT.DOWN && sortColumn != null) {
- return itemCount - id;
- }
- return id - 1;
-}
-
-int getInsetWidth () {
- if (OS.VERSION >= 0x1040) {
- float [] metric = new float [1];
- OS.DataBrowserGetMetric (handle, OS.kDataBrowserMetricCellContentInset, null, metric);
- return (int) metric [0] * 2;
- }
- return CELL_CONTENT_INSET * 2;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem getItem (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- return _getItem (index);
-}
-
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- * <p>
- * The item that is returned represents an item that could be selected by the user.
- * For example, if selection only occurs in items in the first column, then null is
- * returned if the point is outside of the item.
- * Note that the SWT.FULL_SELECTION style hint, which specifies the selection policy,
- * determines the extent of the selection.
- * </p>
- *
- * @param point the point used to locate the item
- * @return the item at the given point, or null if the point is not in a selectable item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem getItem (Point point) {
- checkWidget ();
- checkItems (true);
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- short [] height = new short [1];
- OS.GetDataBrowserTableViewRowHeight (handle, height);
- Rect rect = new Rect ();
- org.eclipse.swt.internal.carbon.Point pt = new org.eclipse.swt.internal.carbon.Point ();
- OS.SetPt (pt, (short) point.x, (short) point.y);
- int lastHittestIndex = getIndex (lastHittest);
- if (0 <= lastHittestIndex && lastHittestIndex < itemCount && lastHittestColumn != 0) {
- if (OS.GetDataBrowserItemPartBounds (handle, lastHittest, lastHittestColumn, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- rect.bottom = (short)(rect.top + height [0]);
- if (OS.PtInRect (pt, rect)) return _getItem (lastHittestIndex);
- if (rect.top <= pt.v && pt.v < rect.bottom) {
- for (int j = 0; j < columnCount; j++) {
- if (OS.GetDataBrowserItemPartBounds (handle, lastHittest, columns [j].id, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- rect.bottom = (short)(rect.top + height [0]);
- if (OS.PtInRect (pt, rect)) return _getItem (lastHittestIndex);
- }
- }
- return null;
- }
- }
- }
- int [] top = new int [1], left = new int [1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- short [] header = new short [1];
- OS.GetDataBrowserListViewHeaderBtnHeight (handle, header);
- int [] offsets = new int [] {0, 1, -1};
- for (int i = 0; i < offsets.length; i++) {
- int index = (top[0] - header [0] + point.y) / height [0] + offsets [i];
- if (0 <= index && index < itemCount) {
- int columnId = columnCount == 0 ? column_id : columns [0].id;
- if (OS.GetDataBrowserItemPartBounds (handle, getId (index), columnId, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- rect.bottom = (short)(rect.top + height [0]);
- if (rect.top <= pt.v && pt.v < rect.bottom) {
- if (columnCount == 0) {
- if (OS.PtInRect (pt, rect)) return _getItem (index);
- } else {
- for (int j = 0; j < columnCount; j++) {
- if (OS.GetDataBrowserItemPartBounds (handle, getId (index), columns [j].id, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- rect.bottom = (short)(rect.top + height [0]);
- if (OS.PtInRect (pt, rect)) return _getItem (index);
- }
- }
- }
- return null;
- }
- }
- }
- }
- return null;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return itemCount;
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the receiver.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- short [] height = new short [1];
- if (OS.GetDataBrowserTableViewRowHeight (handle, height) != OS.noErr) {
- error (SWT.ERROR_CANNOT_GET_ITEM_HEIGHT);
- }
- return height [0];
-}
-
-/**
- * Returns a (possibly empty) array of <code>TableItem</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem [] getItems () {
- checkWidget ();
- TableItem [] result = new TableItem [itemCount];
- if ((style & SWT.VIRTUAL) != 0) {
- for (int i=0; i<itemCount; i++) {
- result [i] = _getItem (i);
- }
- } else {
- System.arraycopy (items, 0, result, 0, itemCount);
- }
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver's lines are visible,
- * and <code>false</code> otherwise. Note that some platforms draw
- * grid lines while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the visibility state of the lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getLinesVisible () {
- checkWidget ();
- if (OS.VERSION >= 0x1040) {
- int [] attrib = new int [1];
- OS.DataBrowserGetAttributes (handle, attrib);
- return (attrib [0] & (OS.kDataBrowserAttributeListViewAlternatingRowColors | OS.kDataBrowserAttributeListViewDrawColumnDividers)) != 0;
- }
- return false;
-}
-
-/**
- * Returns an array of <code>TableItem</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem [] getSelection () {
- checkWidget ();
- int ptr = OS.NewHandle (0);
- if (OS.GetDataBrowserItems (handle, OS.kDataBrowserNoItem, true, OS.kDataBrowserItemIsSelected, ptr) != OS.noErr) {
- error (SWT.ERROR_CANNOT_GET_SELECTION);
- }
- int count = OS.GetHandleSize (ptr) / 4;
- TableItem [] result = new TableItem [count];
- if (count > 0) {
- OS.HLock (ptr);
- int [] id = new int [1];
- OS.memmove (id, ptr, 4);
- if (sortDirection == SWT.DOWN && sortColumn != null) {
- int offset = id [0];
- for (int i=0; i<count; i++, offset += 4) {
- OS.memmove (id, offset, 4);
- result [i] = _getItem (getIndex (id [0]));
- }
- } else {
- int offset = id [0] + (count - 1) * 4;
- for (int i=0; i<count; i++, offset -= 4) {
- OS.memmove (id, offset, 4);
- result [i] = _getItem (getIndex (id [0]));
- }
- }
- OS.HUnlock (ptr);
- }
- return result;
-}
-
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget ();
- int [] count = new int [1];
- if (OS.GetDataBrowserItemCount (handle, OS.kDataBrowserNoItem, true, OS.kDataBrowserItemIsSelected, count) != OS.noErr) {
- error (SWT.ERROR_CANNOT_GET_COUNT);
- }
- return count [0];
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget();
- int [] first = new int [1], last = new int [1];
- if (OS.GetDataBrowserSelectionAnchor (handle, first, last) != OS.noErr) return -1;
- return getIndex (first [0]);
-}
-
-/**
- * Returns the zero-relative indices of the items which are currently
- * selected in the receiver. The order of the indices is unspecified.
- * The array is empty if no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return the array of indices of the selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int [] getSelectionIndices () {
- checkWidget ();
- int ptr = OS.NewHandle (0);
- if (OS.GetDataBrowserItems (handle, OS.kDataBrowserNoItem, true, OS.kDataBrowserItemIsSelected, ptr) != OS.noErr) {
- error (SWT.ERROR_CANNOT_GET_SELECTION);
- }
- int count = OS.GetHandleSize (ptr) / 4;
- int [] result = new int [count];
- if (count > 0) {
- OS.HLock (ptr);
- OS.memmove (result, ptr, 4);
- OS.memmove (result, result [0], count * 4);
- OS.HUnlock (ptr);
- if (sortDirection == SWT.DOWN && sortColumn != null) {
- for (int i=0; i<count; i++) {
- result [i] = getIndex (result [i]);
- }
- } else {
- for (int start=0, end=count - 1; start<=end; start++, end--) {
- int temp = result [start];
- result [start] = getIndex (result [end]);
- result [end] = getIndex (temp);
- }
- }
- }
- OS.DisposeHandle (ptr);
- return result;
-}
-
-/**
- * Returns the column which shows the sort indicator for
- * the receiver. The value may be null if no column shows
- * the sort indicator.
- *
- * @return the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortColumn(TableColumn)
- *
- * @since 3.2
- */
-public TableColumn getSortColumn () {
- checkWidget ();
- return sortColumn;
-}
-
-/**
- * Returns the direction of the sort indicator for the receiver.
- * The value will be one of <code>UP</code>, <code>DOWN</code>
- * or <code>NONE</code>.
- *
- * @return the sort direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortDirection(int)
- *
- * @since 3.2
- */
-public int getSortDirection () {
- checkWidget ();
- return sortDirection;
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items are
- * scrolled or new items are added or removed.
- *
- * @return the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget();
- int[] top = new int [1], left = new int [1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- return top [0] / getItemHeight ();
-}
-
-int helpProc (int inControl, int inGlobalMouse, int inRequest, int outContentProvided, int ioHelpContent) {
- if (toolTipText == null) {
- switch (inRequest) {
- case OS.kHMSupplyContent: {
- if (!(toolTipText != null && toolTipText.length () != 0)) {
- Rect rect = new Rect ();
- int window = OS.GetControlOwner (handle);
- OS.GetWindowBounds (window, (short) OS.kWindowContentRgn, rect);
- short windowLeft = rect.left, windowTop = rect.top;
- org.eclipse.swt.internal.carbon.Point pt = new org.eclipse.swt.internal.carbon.Point ();
- OS.memmove(pt, new int[] {inGlobalMouse}, 4);
- pt.h -= windowLeft;
- pt.v -= windowTop;
- String toolTipText = null;
- int tagSide = OS.kHMAbsoluteCenterAligned;
- CGPoint inPt = new CGPoint ();
- int [] contentView = new int [1];
- OS.HIViewFindByID (OS.HIViewGetRoot (OS.GetControlOwner (handle)), OS.kHIViewWindowContentID (), contentView);
- OS.HIViewConvertPoint (inPt, handle, contentView [0]);
- pt.h -= (int) inPt.x;
- pt.v -= (int) inPt.y;
- windowLeft += (int) inPt.x;
- windowTop += (int) inPt.y;
- int x = pt.h;
- int y = pt.v;
- int headerHeight = getHeaderHeight ();
- if (headerHeight != 0 && (0 <= y && y < headerHeight) ) {
- int startX = 0;
- for (int i = 0; i < columnCount; i++) {
- TableColumn column = columns [i];
- int width = column.lastWidth;
- if (startX <= x && x < startX + width) {
- toolTipText = column.toolTipText;
- rect.left = (short) startX;
- rect.top = (short) 0;
- rect.right = (short) (rect.left + width);
- rect.bottom = (short) (rect.top + headerHeight);
- tagSide = OS.kHMOutsideBottomRightAligned;
- break;
- }
- startX += width;
- }
- } else {
- TableItem item = null;
- int index = getIndex (lastHittest);
- if (0 <= index && index < itemCount) {
- if (OS.GetDataBrowserItemPartBounds (handle, lastHittest, lastHittestColumn, OS.kDataBrowserPropertyContentPart, rect) == OS.noErr) {
- item = _getItem (index);
- }
- }
- if (item != null) {
- int columnIndex = 0;
- TableColumn column = null;
- if (columnCount > 0) {
- for (int i = 0; i < columnCount; i++) {
- if (columns[i].id == lastHittestColumn) {
- column = columns[i];
- columnIndex = i;
- break;
- }
- }
- }
- int columnId = lastHittestColumn;
- GC gc = new GC (this);
- int inset = getInsetWidth ();
- int width = item.calculateWidth (columnIndex, gc) + inset;
- gc.dispose ();
- int columnWidth;
- if (columnCount == 0) {
- columnWidth = getClientArea ().width;
- } else {
- short [] w = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (handle, columnId, w);
- columnWidth = w[0];
- }
- if (width > columnWidth) {
- toolTipText = item.getText (columnIndex);
- Image image = item.getImage (columnIndex);
- int imageWidth = image != null ? image.getBounds ().width + getGap () : 0;
- int style = column == null ? SWT.LEFT : column.style;
- if ((style & SWT.LEFT) != 0) {
- rect.left += imageWidth;
- rect.right = (short) (rect.left + width - imageWidth - inset);
- }
- if ((style & SWT.RIGHT) != 0) {
- rect.left = (short) (rect.right - width + imageWidth + inset);
- }
- if ((style & SWT.CENTER) != 0) {
- rect.left += imageWidth;
- }
- }
- }
- }
- if (toolTipText != null && toolTipText.length () != 0) {
- char [] buffer = new char [toolTipText.length ()];
- toolTipText.getChars (0, buffer.length, buffer, 0);
- int length = fixMnemonic (buffer);
- if (display.helpString != 0) OS.CFRelease (display.helpString);
- display.helpString = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, length);
- HMHelpContentRec helpContent = new HMHelpContentRec ();
- OS.memmove (helpContent, ioHelpContent, HMHelpContentRec.sizeof);
- display.helpWidget = this;
- helpContent.version = OS.kMacHelpVersion;
- helpContent.tagSide = (short) tagSide;
- helpContent.absHotRect_left = (short) (rect.left + windowLeft);
- helpContent.absHotRect_top = (short) (rect.top + windowTop);
- helpContent.absHotRect_right = (short) (rect.right + windowLeft);
- helpContent.absHotRect_bottom = (short) (rect.bottom + windowTop);
- helpContent.content0_contentType = OS.kHMCFStringContent;
- helpContent.content0_tagCFString = display.helpString;
- helpContent.content1_contentType = OS.kHMCFStringContent;
- helpContent.content1_tagCFString = display.helpString;
- OS.memmove (ioHelpContent, helpContent, HMHelpContentRec.sizeof);
- OS.memmove (outContentProvided, new short[]{OS.kHMContentProvided}, 2);
- return OS.noErr;
- }
- }
- break;
- }
- }
- }
- return super.helpProc (inControl, inGlobalMouse, inRequest, outContentProvided, ioHelpContent);
-}
-
-int hitTestProc (int browser, int id, int property, int theRect, int mouseRect) {
- lastHittest = id;
- lastHittestColumn = property;
- return 1;
-}
-
-void hookEvents () {
- super.hookEvents ();
- DataBrowserCallbacks callbacks = new DataBrowserCallbacks ();
- callbacks.version = OS.kDataBrowserLatestCallbacks;
- OS.InitDataBrowserCallbacks (callbacks);
- callbacks.v1_itemDataCallback = display.itemDataProc;
- callbacks.v1_itemNotificationCallback = display.itemNotificationProc;
- OS.SetDataBrowserCallbacks (handle, callbacks);
- DataBrowserCustomCallbacks custom = new DataBrowserCustomCallbacks ();
- custom.version = OS.kDataBrowserLatestCustomCallbacks;
- OS.InitDataBrowserCustomCallbacks (custom);
- custom.v1_drawItemCallback = display.drawItemProc;
- custom.v1_hitTestCallback = display.hitTestProc;
- custom.v1_trackingCallback = display.trackingProc;
- OS.SetDataBrowserCustomCallbacks (handle, custom);
-}
-
-/**
- * Searches the receiver's list starting at the first column
- * (index 0) until a column is found that is equal to the
- * argument, and returns the index of that column. If no column
- * is found, returns -1.
- *
- * @param column the search column
- * @return the index of the column
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the column is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (TableColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<columnCount; i++) {
- if (columns [i] == column) return i;
- }
- return -1;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (TableItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (1 <= lastIndexOf && lastIndexOf < itemCount - 1) {
- if (items [lastIndexOf] == item) return lastIndexOf;
- if (items [lastIndexOf + 1] == item) return ++lastIndexOf;
- if (items [lastIndexOf - 1] == item) return --lastIndexOf;
- }
- if (lastIndexOf < itemCount / 2) {
- for (int i=0; i<itemCount; i++) {
- if (items [i] == item) return lastIndexOf = i;
- }
- } else {
- for (int i=itemCount - 1; i>=0; --i) {
- if (items [i] == item) return lastIndexOf = i;
- }
- }
- return -1;
-}
-
-/**
- * Returns <code>true</code> if the item is selected,
- * and <code>false</code> otherwise. Indices out of
- * range are ignored.
- *
- * @param index the index of the item
- * @return the selection state of the item at the index
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isSelected (int index) {
- checkWidget();
- return OS.IsDataBrowserItemSelected (handle, getId (index));
-}
-
-int itemDataProc (int browser, int id, int property, int itemData, int setValue) {
- int index = getIndex (id);
- if (!(0 <= index && index < items.length)) return OS.noErr;
- switch (property) {
- case CHECK_COLUMN_ID: {
- TableItem item = _getItem (index);
- if (!checkData (item, false)) return OS.noErr;
- if (setValue != 0) {
- item.checked = !item.checked;
- if (item.checked && item.grayed) {
- OS.SetDataBrowserItemDataButtonValue (itemData, (short) OS.kThemeButtonMixed);
- } else {
- int theData = item.checked ? OS.kThemeButtonOn : OS.kThemeButtonOff;
- OS.SetDataBrowserItemDataButtonValue (itemData, (short) theData);
- }
- Event event = new Event ();
- event.item = item;
- event.detail = SWT.CHECK;
- postEvent (SWT.Selection, event);
- /*
- * Bug in the Macintosh. When the height of the row is smaller than the
- * check box, the tail of the check mark draws outside of the item part
- * bounds. This means it will not be redrawn when the item is unckeched.
- * The fix is to redraw the area.
- */
- if (!item.checked) item.redraw(Table.CHECK_COLUMN_ID);
- } else {
- int theData = OS.kThemeButtonOff;
- if (item.checked) theData = item.grayed ? OS.kThemeButtonMixed : OS.kThemeButtonOn;
- OS.SetDataBrowserItemDataButtonValue (itemData, (short) theData);
- }
- break;
- }
- }
- return OS.noErr;
-}
-
-int itemNotificationProc (int browser, int id, int message) {
- if (message == OS.kDataBrowserUserStateChanged) {
- boolean resized = false;
- short [] width = new short [1];
- int [] position = new int [1];
- TableColumn [] columns = getColumns ();
- for (int i = 0; i < columnCount; i++) {
- TableColumn column = columns [i];
- if (!column.isDisposed ()) {
- OS.GetDataBrowserTableViewNamedColumnWidth (handle, column.id, width);
- if (width [0] != column.lastWidth) {
- column.resized (width [0]);
- resized = true;
- }
- }
- if (!column.isDisposed ()) {
- OS.GetDataBrowserTableViewColumnPosition (handle, column.id, position);
- if (position [0] != column.lastPosition) {
- column.lastPosition = position [0];
- column.sendEvent (SWT.Move);
- resized = true;
- }
- }
- }
- int [] property = new int [1];
- OS.GetDataBrowserSortProperty (handle, property);
- if (property [0] != 0) {
- if (!resized) {
- for (int i = 0; i < columnCount; i++) {
- TableColumn column = columns [i];
- if (property [0] == column.id) {
- column.postEvent (display.clickCount == 2 ? SWT.DefaultSelection : SWT.Selection);
- break;
- }
- }
- }
- OS.SetDataBrowserSortProperty (handle, 0);
- if (sortColumn != null && !sortColumn.isDisposed () && sortDirection != SWT.NONE) {
- OS.SetDataBrowserSortProperty (handle, sortColumn.id);
- int order = sortDirection == SWT.DOWN ? OS.kDataBrowserOrderDecreasing : OS.kDataBrowserOrderIncreasing;
- OS.SetDataBrowserSortOrder (handle, (short) order);
- }
- }
- return OS.noErr;
- }
- int index = getIndex (id);
- if (!(0 <= index && index < items.length)) return OS.noErr;
- switch (message) {
- case OS.kDataBrowserItemSelected:
- savedAnchor = 0;
- break;
- case OS.kDataBrowserItemDeselected: {
- int [] selectionCount = new int [1];
- if (OS.GetDataBrowserItemCount (handle, OS.kDataBrowserNoItem, true, OS.kDataBrowserItemIsSelected, selectionCount) == OS.noErr) {
- if (selectionCount [0] == 0) savedAnchor = id;
- }
- break;
- }
- }
- switch (message) {
- case OS.kDataBrowserItemSelected:
- case OS.kDataBrowserItemDeselected: {
- TableItem item = _getItem (index);
- wasSelected = true;
- if (ignoreSelect) break;
- int [] first = new int [1], last = new int [1];
- OS.GetDataBrowserSelectionAnchor (handle, first, last);
- boolean selected = false;
- if ((style & SWT.MULTI) != 0) {
- int modifiers = OS.GetCurrentEventKeyModifiers ();
- if ((modifiers & OS.shiftKey) != 0) {
- if (message == OS.kDataBrowserItemSelected) {
- selected = first [0] == id || last [0] == id;
- } else {
- selected = id == anchorFirst || id == anchorLast;
- }
- } else {
- if ((modifiers & OS.cmdKey) != 0) {
- selected = true;
- } else {
- selected = first [0] == last [0];
- }
- }
- } else {
- selected = message == OS.kDataBrowserItemSelected;
- }
- if (selected) {
- anchorFirst = first [0];
- anchorLast = last [0];
- Event event = new Event ();
- event.item = item;
- postEvent (SWT.Selection, event);
- }
- break;
- }
- case OS.kDataBrowserItemDoubleClicked: {
- wasSelected = true;
- if (display.clickCount == 2) {
- Event event = new Event ();
- event.item = _getItem (index);
- postEvent (SWT.DefaultSelection, event);
- }
- break;
- }
- }
- return OS.noErr;
-}
-
-int kEventAccessibleGetNamedAttribute (int nextHandler, int theEvent, int userData) {
- int code = OS.eventNotHandledErr;
- int [] stringRef = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamAccessibleAttributeName, OS.typeCFStringRef, null, 4, null, stringRef);
- int length = 0;
- if (stringRef [0] != 0) length = OS.CFStringGetLength (stringRef [0]);
- char [] buffer = new char [length];
- CFRange range = new CFRange ();
- range.length = length;
- OS.CFStringGetCharacters (stringRef [0], range, buffer);
- String attributeName = new String(buffer);
- if (attributeName.equals(OS.kAXHeaderAttribute)) {
- short [] height = new short [1];
- OS.GetDataBrowserListViewHeaderBtnHeight (handle, height);
- if (height [0] == 0) {
- /*
- * Bug in the Macintosh. Even when the header is not visible,
- * VoiceOver still reports each column header's role for every row.
- * This is confusing and overly verbose. The fix is to return
- * "no header" when the screen reader asks for the header, by
- * returning noErr without setting the event parameter.
- */
- code = OS.noErr;
- }
- } else {
- int [] ref = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamAccessibleObject, OS.typeCFTypeRef, null, 4, null, ref);
- int axuielementref = ref [0];
- DataBrowserAccessibilityItemInfo itemInfo = new DataBrowserAccessibilityItemInfo ();
- int err = OS.AXUIElementGetDataBrowserItemInfo (axuielementref, handle, 0, itemInfo);
- if (err == OS.noErr && itemInfo.v0_columnProperty != OS.kDataBrowserItemNoProperty && itemInfo.v0_item != OS.kDataBrowserNoItem && itemInfo.v0_propertyPart == OS.kDataBrowserPropertyEnclosingPart) {
- int columnIndex = 0;
- for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {
- if (columns [columnIndex].id == itemInfo.v0_columnProperty) break;
- }
- if (columnIndex != columnCount || columnCount == 0) {
- int index = getIndex (itemInfo.v0_item);
- if (0 <= index && index < itemCount) {
- TableItem tableItem = _getItem (index);
- if (attributeName.equals (OS.kAXRoleAttribute) || attributeName.equals (OS.kAXRoleDescriptionAttribute)) {
- String roleText = OS.kAXStaticTextRole;
- buffer = new char [roleText.length ()];
- roleText.getChars (0, buffer.length, buffer, 0);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- if (attributeName.equals (OS.kAXRoleAttribute)) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- } else { // kAXRoleDescriptionAttribute
- int stringRef2 = OS.HICopyAccessibilityRoleDescription (stringRef [0], 0);
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, new int [] {stringRef2});
- OS.CFRelease(stringRef2);
- }
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- } else if (attributeName.equals(OS.kAXChildrenAttribute)) {
- int children = OS.CFArrayCreateMutable (OS.kCFAllocatorDefault, 0, 0);
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFMutableArrayRef, 4, new int [] {children});
- OS.CFRelease(children);
- code = OS.noErr;
- } else if (attributeName.equals (OS.kAXTitleAttribute) || attributeName.equals (OS.kAXDescriptionAttribute)) {
- String text = tableItem.getText (columnIndex);
- buffer = new char [text.length ()];
- text.getChars (0, buffer.length, buffer, 0);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- }
- }
- }
- }
- }
- if (accessible != null) {
- code = accessible.internal_kEventAccessibleGetNamedAttribute (nextHandler, theEvent, code);
- }
- return code;
-}
-
-int kEventMouseDown (int nextHandler, int theEvent, int userData) {
- int result = super.kEventMouseDown (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- wasSelected = false;
- result = OS.CallNextEventHandler (nextHandler, theEvent);
- if (isDisposed ()) return OS.noErr;
- if (!wasSelected) {
- if (OS.IsDataBrowserItemSelected (handle, lastHittest)) {
- int index = getIndex (lastHittest);
- if (0 <= index && index < itemCount) {
- Event event = new Event ();
- event.item = _getItem (index);
- postEvent (SWT.Selection, event);
- }
- }
- }
- return result;
-}
-
-int kEventControlGetClickActivation (int nextHandler, int theEvent, int userData) {
- OS.SetEventParameter (theEvent, OS.kEventParamClickActivation, OS.typeClickActivationResult, 4, new int [] {OS.kActivateAndHandleClick});
- return OS.noErr;
-}
-
-int kEventControlSetCursor (int nextHandler, int theEvent, int userData) {
- if (!isEnabledCursor ()) return OS.noErr;
- if (isEnabledModal ()) {
- org.eclipse.swt.internal.carbon.Point pt = new org.eclipse.swt.internal.carbon.Point ();
- int sizeof = org.eclipse.swt.internal.carbon.Point.sizeof;
- OS.GetEventParameter (theEvent, OS.kEventParamMouseLocation, OS.typeQDPoint, null, sizeof, null, pt);
- if (!contains (pt.h, pt.v)) return OS.eventNotHandledErr;
- }
- return super.kEventControlSetCursor (nextHandler, theEvent, userData);
-}
-
-int kEventUnicodeKeyPressed (int nextHandler, int theEvent, int userData) {
- int result = super.kEventUnicodeKeyPressed (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- int [] keyboardEvent = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendKeyboardEvent, OS.typeEventRef, null, keyboardEvent.length * 4, null, keyboardEvent);
- int [] keyCode = new int [1];
- OS.GetEventParameter (keyboardEvent [0], OS.kEventParamKeyCode, OS.typeUInt32, null, keyCode.length * 4, null, keyCode);
- switch (keyCode [0]) {
- case 49: { /* Space */
- int [] first = new int [1], last = new int [1];
- if (OS.GetDataBrowserSelectionAnchor (handle, first, last) == OS.noErr) {
- if (first [0] != 0) {
- TableItem item = _getItem (getIndex (first [0]));
- if ((style & SWT.CHECK) != 0) {
- item.setChecked (!item.getChecked (), true);
- }
- }
- }
- break;
- }
- case 76: /* KP Enter */
- case 36: { /* Return */
- postEvent (SWT.DefaultSelection);
- break;
- }
- /*
- * Feature in the Macintosh. For some reason, when the user hits an
- * up or down arrow to traverse the items in a Data Browser, the item
- * scrolls to the left such that the white space that is normally
- * visible to the right of the every item is scrolled out of view.
- * The fix is to save and restore the horizontal scroll position.
- */
- case 125: /* Down */
- case 126: /* Up*/ {
- if (itemCount == 0) break;
- int [] top = new int [1], left = new int [1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- boolean selectItem = false;
- int [] selectionCount = new int [1];
- if (OS.GetDataBrowserItemCount (handle, OS.kDataBrowserNoItem, true, OS.kDataBrowserItemIsSelected, selectionCount) == OS.noErr) {
- selectItem = savedAnchor != 0 && selectionCount [0] == 0;
- }
- if (selectItem) {
- int index = getIndex (savedAnchor) + (keyCode [0] == 125 ? 1 : -1);
- index = Math.max (0, Math.min (itemCount - 1, index));
- int [] itemId = new int [] {getId (index)};
- OS.SetDataBrowserSelectedItems (handle, 1, itemId, OS.kDataBrowserItemsAssign);
- result = OS.noErr;
- } else {
- result = OS.CallNextEventHandler (nextHandler, theEvent);
- }
- OS.GetDataBrowserScrollPosition (handle, top, null);
- OS.SetDataBrowserScrollPosition (handle, top [0], left [0]);
- redrawBackgroundImage ();
- break;
- }
- }
- return result;
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- }
- if (columns != null) {
- for (int i=0; i<columnCount; i++) {
- TableColumn column = columns [i];
- if (column != null && !column.isDisposed ()) {
- column.release (false);
- }
- }
- columns = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- currentItem = null;
- sortColumn = null;
- paintGC = null;
- imageBounds = null;
- /*
- * Feature in the Mac. When RemoveDataBrowserItems() is used
- * to remove items, item notification callbacks are issued with
- * the message kDataBrowserItemRemoved When many items are
- * removed, this is slow. The fix is to temporarily remove
- * the item notification callback.
- */
- DataBrowserCallbacks callbacks = new DataBrowserCallbacks ();
- OS.GetDataBrowserCallbacks (handle, callbacks);
- callbacks.v1_itemNotificationCallback = 0;
- OS.SetDataBrowserCallbacks (handle, callbacks);
-}
-
-/**
- * Removes the item from the receiver at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget();
- checkItems (true);
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- TableItem item = items [index];
- if (item != null) item.release (false);
- if (savedAnchor != 0) {
- int savedIndex = getIndex (savedAnchor);
- if (index < savedIndex) {
- savedAnchor = getId (Math.max (0, savedIndex - 1));
- }
- }
- if (index != itemCount - 1) fixSelection (index, false);
- int [] id = new int [] {itemCount};
- if (OS.RemoveDataBrowserItems (handle, OS.kDataBrowserNoItem, id.length, id, 0) != OS.noErr) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- OS.UpdateDataBrowserItems (handle, 0, 0, null, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem);
- if (itemCount == 0) {
- setTableEmpty ();
- } else {
- fixScrollBar ();
- }
-}
-
-/**
- * Removes the items from the receiver which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget();
- checkItems (true);
- if (start > end) return;
- if (!(0 <= start && start <= end && end < itemCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- if (start == 0 && end == itemCount - 1) {
- removeAll ();
- } else {
- int length = end - start + 1;
- int [] indices = new int [length];
- for (int i=0; i<length; i++) indices [i] = i + start;
- remove(indices);
- }
-}
-
-/**
- * Removes the items from the receiver's list at the given
- * zero-relative indices.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int [] indices) {
- checkWidget ();
- checkItems (true);
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- int [] newIndices = new int [indices.length];
- System.arraycopy (indices, 0, newIndices, 0, indices.length);
- sort (newIndices);
- int start = newIndices [newIndices.length - 1], end = newIndices [0];
- if (!(0 <= start && start <= end && end < itemCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int duplicates = 0;
- int last = -1;
- for (int i = 0; i < newIndices.length; i++) {
- if (newIndices [i] == last) duplicates++;
- last = newIndices [i];
- }
- int [] id = new int [newIndices.length - duplicates];
- int idIndex = id.length - 1;
- last = -1;
- for (int i = 0; i < newIndices.length; i++) {
- int index = newIndices [i];
- if (index != last) {
- TableItem item = items [index];
- if (item != null && !item.isDisposed ()) item.release (false);
- if (savedAnchor != 0) {
- int savedIndex = getIndex (savedAnchor);
- if (index < savedIndex) {
- savedAnchor = getId (Math.max (0, savedIndex - 1));
- }
- }
- if (index != itemCount - 1) fixSelection (index, false);
- id [idIndex--] = itemCount;
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- last = index;
- }
- }
- if (OS.RemoveDataBrowserItems (handle, OS.kDataBrowserNoItem, id.length, id, 0) != OS.noErr) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- OS.UpdateDataBrowserItems (handle, 0, 0, null, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem);
- if (itemCount == 0) {
- setTableEmpty ();
- } else {
- fixScrollBar ();
- }
-}
-
-/**
- * Removes all of the items from the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget();
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (item != null && !item.isDisposed ()) item.release (false);
- }
- /*
- * Feature in the Mac. When RemoveDataBrowserItems() is used
- * to remove items, item notification callbacks are issued with
- * the message kDataBrowserItemRemoved When many items are
- * removed, this is slow. The fix is to temporarily remove
- * the item notification callback.
- */
- DataBrowserCallbacks callbacks = new DataBrowserCallbacks ();
- OS.GetDataBrowserCallbacks (handle, callbacks);
- callbacks.v1_itemNotificationCallback = 0;
- OS.SetDataBrowserCallbacks (handle, callbacks);
- OS.RemoveDataBrowserItems (handle, OS.kDataBrowserNoItem, 0, null, 0);
- callbacks.v1_itemNotificationCallback = display.itemNotificationProc;
- OS.SetDataBrowserCallbacks (handle, callbacks);
- setTableEmpty ();
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener(SelectionListener)
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-void resetVisibleRegion (int control) {
- super.resetVisibleRegion (control);
- if (showIndex != -1) {
- showIndex (showIndex);
- }
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget();
- checkItems (false);
- if (0 <= index && index < itemCount) {
- int [] ids = new int [] {getId (index)};
- select (ids, ids.length, false);
- }
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If an item in the given range is not selected, it is selected.
- * If an item in the given range was already selected, it remains selected.
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setSelection(int,int)
- */
-public void select (int start, int end) {
- checkWidget ();
- checkItems (false);
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- if (itemCount == 0 || start >= itemCount) return;
- if (start == 0 && end == itemCount - 1) {
- selectAll ();
- } else {
- start = Math.max (0, start);
- end = Math.min (end, itemCount - 1);
- int length = end - start + 1;
- int [] ids = new int [length];
- for (int i=0; i<length; i++) ids [i] = getId (end - i);
- select (ids, length, false);
- }
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If the item at a given index is not selected, it is selected.
- * If the item at a given index was already selected, it remains selected.
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- * </p>
- *
- * @param indices the array of indices for the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setSelection(int[])
- */
-public void select (int [] indices) {
- checkWidget ();
- checkItems (false);
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- int [] ids = new int [length];
- int count = 0;
- for (int i=0; i<length; i++) {
- int index = indices [length - i - 1];
- if (index >= 0 && index < itemCount) {
- ids [count++] = getId (index);
- }
- }
- if (count > 0) select (ids, count, false);
-}
-
-void selectIndices (int [] indices, int count, boolean clear) {
- for (int i = 0; i < count; i++) {
- indices [i] = getId (indices [i]);
- }
- select(indices, count, clear);
-}
-
-void select (int [] ids, int count, boolean clear) {
- ignoreSelect = true;
- /*
- * Bug in the Macintosh. When the DataBroswer selection flags includes
- * both kDataBrowserNeverEmptySelectionSet and kDataBrowserSelectOnlyOne,
- * two items are selected when SetDataBrowserSelectedItems() is called
- * with kDataBrowserItemsAssign to assign a new seletion despite the fact
- * that kDataBrowserSelectOnlyOne was specified. The fix is to save and
- * restore kDataBrowserNeverEmptySelectionSet around each call to
- * SetDataBrowserSelectedItems().
- */
- int [] selectionFlags = null;
- if ((style & SWT.SINGLE) != 0) {
- selectionFlags = new int [1];
- OS.GetDataBrowserSelectionFlags (handle, selectionFlags);
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0] & ~OS.kDataBrowserNeverEmptySelectionSet);
- }
- int operation = OS.kDataBrowserItemsAssign;
- if ((style & SWT.MULTI) != 0 && !clear) operation = OS.kDataBrowserItemsAdd;
- OS.SetDataBrowserSelectedItems (handle, count, ids, operation);
- if ((style & SWT.SINGLE) != 0) {
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0]);
- }
- ignoreSelect = false;
-}
-
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget ();
- checkItems (false);
- if ((style & SWT.SINGLE) != 0) return;
- select (null, 0, false);
-}
-
-void setBackground (float [] color) {
- /*
- * Bug in the Macintosh. The default background of a window changes when
- * the background of a data browser is set using SetControlFontStyle(). This
- * also affects the background of any TNXObject created on that window. The
- * fix is to avoid calling SetControlFontStyle() which has no effect
- * in a data browser anyways.
- */
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- /*
- * Ensure that the top item is visible when the tree is resized
- * from a zero size to a size that can show the selection.
- */
- int result = super.setBounds (x, y, width, height, move, resize, events);
- if (showIndex != -1) {
- showIndex (showIndex);
- }
- return result;
-}
-
-/**
- * Sets the order that the items in the receiver should
- * be displayed in to the given argument which is described
- * in terms of the zero-relative ordering of when the items
- * were added.
- *
- * @param order the new order to display the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item order is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public void setColumnOrder (int [] order) {
- checkWidget ();
- if (order == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (columnCount == 0) {
- if (order.length != 0) error (SWT.ERROR_INVALID_ARGUMENT);
- return;
- }
- if (order.length != columnCount) error (SWT.ERROR_INVALID_ARGUMENT);
- int [] oldOrder = getColumnOrder ();
- boolean reorder = false;
- boolean [] seen = new boolean [columnCount];
- for (int i=0; i<order.length; i++) {
- int index = order [i];
- if (index < 0 || index >= columnCount) error (SWT.ERROR_INVALID_ARGUMENT);
- if (seen [index]) error (SWT.ERROR_INVALID_ARGUMENT);
- seen [index] = true;
- if (order [i] != oldOrder [i]) reorder = true;
- }
- if (reorder) {
- int x = 0;
- short [] width = new short [1];
- int [] oldX = new int [oldOrder.length];
- for (int i=0; i<oldOrder.length; i++) {
- int index = oldOrder [i];
- TableColumn column = columns [index];
- oldX [index] = x;
- OS.GetDataBrowserTableViewNamedColumnWidth(handle, column.id, width);
- x += width [0];
- }
- x = 0;
- int [] newX = new int [order.length];
- for (int i=0; i<order.length; i++) {
- int index = order [i];
- TableColumn column = columns [index];
- int position = (style & SWT.CHECK) != 0 ? i + 1 : i;
- OS.SetDataBrowserTableViewColumnPosition(handle, column.id, position);
- column.lastPosition = position;
- newX [index] = x;
- OS.GetDataBrowserTableViewNamedColumnWidth(handle, column.id, width);
- x += width [0];
- }
- TableColumn[] newColumns = new TableColumn [columnCount];
- System.arraycopy (columns, 0, newColumns, 0, columnCount);
- for (int i=0; i<columnCount; i++) {
- TableColumn column = newColumns [i];
- if (!column.isDisposed ()) {
- if (newX [i] != oldX [i]) {
- column.sendEvent (SWT.Move);
- }
- }
- }
- }
-}
-
-void setFontStyle (Font font) {
- super.setFontStyle (font);
- if (items == null) return;
- for (int i = 0; i < items.length; i++) {
- TableItem item = items [i];
- if (item != null) item.width = -1;
- }
- setScrollWidth (items, true);
- setItemHeight (null);
-}
-
-/**
- * Marks the receiver's header as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHeaderVisible (boolean show) {
- checkWidget ();
- short [] height = new short [1];
- OS.GetDataBrowserListViewHeaderBtnHeight (handle, height);
- if ((height [0] != 0) != show) {
- OS.SetDataBrowserListViewHeaderBtnHeight (handle, (short) (show ? headerHeight : 0));
- invalidateVisibleRegion (handle);
- }
-}
-
-/**
- * Sets the number of items contained in the receiver.
- *
- * @param count the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setItemCount (int count) {
- checkWidget ();
- checkItems (true);
- count = Math.max (0, count);
- if (count == itemCount) return;
- setRedraw (false);
- int[] top = new int [1], left = new int [1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- DataBrowserCallbacks callbacks = new DataBrowserCallbacks ();
- OS.GetDataBrowserCallbacks (handle, callbacks);
- callbacks.v1_itemNotificationCallback = 0;
- OS.SetDataBrowserCallbacks (handle, callbacks);
- if (count < itemCount) {
- int oldAnchor = savedAnchor;
- int selectionCount = getSelectionCount ();
- int index = count;
- int[] id = new int [itemCount - count];
- while (index < itemCount) {
- TableItem item = items [index];
- if (item != null) item.release (false);
- id [index-count] = index + 1;
- index++;
- }
- if (OS.RemoveDataBrowserItems (handle, OS.kDataBrowserNoItem, id.length, id, 0) != OS.noErr) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- boolean fixAnchor = selectionCount != 0 && getSelectionCount () == 0;
- if (fixAnchor || (savedAnchor != 0 && savedAnchor != oldAnchor)) {
- savedAnchor = getId (Math.max (0, count - 1));
- }
- }
- int length = Math.max (4, (count + 3) / 4 * 4);
- TableItem [] newItems = new TableItem [length];
- System.arraycopy (items, 0, newItems, 0, Math.min (count, itemCount));
- items = newItems;
- if ((style & SWT.VIRTUAL) == 0) {
- for (int i=itemCount; i<count; i++) {
- items [i] = new TableItem (this, SWT.NONE, i, false);
- }
- }
- itemCount = count;
- OS.AddDataBrowserItems (handle, 0, itemCount, null, OS.kDataBrowserItemNoProperty);
- callbacks.v1_itemNotificationCallback = display.itemNotificationProc;
- OS.SetDataBrowserCallbacks (handle, callbacks);
- fixScrollBar ();
- if (sortColumn != null && !sortColumn.isDisposed () && sortDirection == SWT.DOWN) {
- OS.UpdateDataBrowserItems (handle, 0, 0, null, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem);
- }
- setRedraw (true);
-}
-
-/*public*/ void setItemHeight (int itemHeight) {
- checkWidget ();
- if (itemHeight < -1) error (SWT.ERROR_INVALID_ARGUMENT);
- if (itemHeight == -1) {
- //TODO - reset item height, ensure other API's such as setFont don't do this
- } else {
- OS.SetDataBrowserTableViewRowHeight (handle, (short) itemHeight);
- }
-}
-
-void setItemHeight (Image image) {
- Rectangle bounds = image != null ? image.getBounds () : imageBounds;
- if (bounds == null) return;
- imageBounds = bounds;
- short [] height = new short [1];
- if (OS.GetDataBrowserTableViewRowHeight (handle, height) == OS.noErr) {
- if (height [0] < bounds.height) {
- OS.SetDataBrowserTableViewRowHeight (handle, (short) bounds.height);
- }
- }
-}
-
-/**
- * Marks the receiver's lines as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise. Note that some platforms draw grid lines
- * while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLinesVisible (boolean show) {
- checkWidget ();
- if (OS.VERSION >= 0x1040) {
- int attrib = OS.kDataBrowserAttributeListViewAlternatingRowColors | OS.kDataBrowserAttributeListViewDrawColumnDividers;
- OS.DataBrowserChangeAttributes (handle, show ? attrib : 0, !show ? attrib : 0);
- redraw ();
- }
-}
-
-public void setRedraw (boolean redraw) {
- checkWidget();
- super.setRedraw (redraw);
- if (redraw && drawCount == 0) {
- /* Resize the item array to match the item count */
- if (items.length > 4 && items.length - itemCount > 3) {
- int length = Math.max (4, (itemCount + 3) / 4 * 4);
- TableItem [] newItems = new TableItem [length];
- System.arraycopy (items, 0, newItems, 0, itemCount);
- items = newItems;
- }
- checkItems (true);
- }
-}
-
-boolean setScrollBarVisible (ScrollBar bar, boolean visible) {
- boolean [] horiz = new boolean [1], vert = new boolean [1];
- OS.GetDataBrowserHasScrollBars (handle, horiz, vert);
- if ((bar.style & SWT.H_SCROLL) != 0) horiz [0] = visible;
- if ((bar.style & SWT.V_SCROLL) != 0) vert [0] = visible;
- if (!visible) {
- bar.redraw ();
- bar.deregister ();
- }
- if (OS.SetDataBrowserHasScrollBars (handle, horiz [0], vert [0]) == OS.noErr) {
- if (visible) {
- bar.handle = findStandardBar (bar.style);
- bar.register ();
- bar.hookEvents ();
- bar.redraw ();
- } else {
- bar.handle = 0;
- }
- return true;
- } else {
- if (!visible) {
- bar.register ();
- }
- }
- return false;
-}
-
-boolean setScrollWidth (TableItem item) {
- if (columnCount != 0) return false;
- if (currentItem != null) {
- if (currentItem != item) fixScrollWidth = true;
- return false;
- }
- if (!getDrawing ()) return false;
- GC gc = new GC (this);
- int newWidth = item.calculateWidth (0, gc);
- gc.dispose ();
- newWidth += getInsetWidth ();
- short [] width = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (handle, column_id, width);
- if (width [0] < newWidth) {
- OS.SetDataBrowserTableViewNamedColumnWidth (handle, column_id, (short) newWidth);
- return true;
- }
- return false;
-}
-
-boolean setScrollWidth (TableItem [] items, boolean set) {
- if (columnCount != 0) return false;
- if (currentItem != null) {
- fixScrollWidth = true;
- return false;
- }
- if (!getDrawing ()) return false;
- GC gc = new GC (this);
- int newWidth = 0;
- for (int i = 0; i < items.length; i++) {
- TableItem item = items [i];
- if (item != null) {
- newWidth = Math.max (newWidth, item.calculateWidth (0, gc));
- }
- }
- gc.dispose ();
- newWidth += getInsetWidth ();
- if (!set) {
- short [] width = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (handle, column_id, width);
- if (width [0] >= newWidth) return false;
- }
- OS.SetDataBrowserTableViewNamedColumnWidth (handle, column_id, (short) newWidth);
- return true;
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * The current selection is first cleared, then the new item is selected.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int)
- */
-public void setSelection (int index) {
- checkWidget();
- checkItems (false);
- deselectAll ();
- setSelection (index, false);
-}
-
-void setSelection (int index, boolean notify) {
-// checkWidget();
- if (0 <= index && index < itemCount) {
- int [] ids = new int [] {getId (index)};
- select (ids, ids.length, true);
- showIndex (index);
- if (notify) {
- Event event = new Event ();
- event.item = _getItem (index);
- postEvent (SWT.Selection, event);
- }
- }
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- * </p>
- *
- * @param start the start index of the items to select
- * @param end the end index of the items to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int,int)
- */
-public void setSelection (int start, int end) {
- checkWidget ();
- checkItems (false);
- deselectAll ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- if (itemCount == 0 || start >= itemCount) return;
- start = Math.max (0, start);
- end = Math.min (end, itemCount - 1);
- int length = end - start + 1;
- int [] ids = new int [length];
- for (int i=0; i<length; i++) ids [i] = getId (end - i);
- select (ids, length, true);
- showIndex (getIndex (ids [0]));
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- * </p>
- *
- * @param indices the indices of the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int[])
- */
-public void setSelection (int [] indices) {
- checkWidget ();
- checkItems (false);
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- int [] ids = new int [length];
- int count = 0;
- for (int i=0; i<length; i++) {
- int index = indices [length - i - 1];
- if (index >= 0 && index < itemCount) {
- ids [count++] = getId (index);
- }
- }
- if (count > 0) {
- select (ids, count, true);
- showIndex (getIndex (ids [0]));
- }
-}
-
-/**
- * Sets the receiver's selection to the given item.
- * The current selection is cleared before the new item is selected.
- * <p>
- * If the item is not in the receiver, then it is ignored.
- * </p>
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection (TableItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (new TableItem [] {item});
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- * </p>
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the items has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int[])
- * @see Table#setSelection(int[])
- */
-public void setSelection (TableItem [] items) {
- checkWidget ();
- checkItems (false);
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = items.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- int [] ids = new int [length];
- int count = 0;
- for (int i=0; i<length; i++) {
- int index = indexOf (items [length - i - 1]);
- if (index != -1) {
- ids [count++] = getId (index);
- }
- }
- if (count > 0) {
- select (ids, count, true);
- showIndex (getIndex (ids [0]));
- }
-}
-
-/**
- * Sets the column used by the sort indicator for the receiver. A null
- * value will clear the sort indicator. The current sort column is cleared
- * before the new column is set.
- *
- * @param column the column used by the sort indicator or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the column is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortColumn (TableColumn column) {
- checkWidget ();
- if (column != null && column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (column == sortColumn) return;
- int [] indices = getSelectionIndices ();
- sortColumn = column;
- int id = 0, order = OS.kDataBrowserOrderIncreasing;
- if (sortColumn != null && !sortColumn.isDisposed () && sortDirection != SWT.NONE) {
- id = sortColumn.id;
- if (sortDirection == SWT.DOWN) order = OS.kDataBrowserOrderDecreasing;
- }
- OS.SetDataBrowserSortProperty (handle, id);
- OS.SetDataBrowserSortOrder (handle, (short) order);
- selectIndices (indices, indices.length, true);
-}
-
-/**
- * Sets the direction of the sort indicator for the receiver. The value
- * can be one of <code>UP</code>, <code>DOWN</code> or <code>NONE</code>.
- *
- * @param direction the direction of the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortDirection (int direction) {
- checkWidget ();
- if (direction != SWT.UP && direction != SWT.DOWN && direction != SWT.NONE) return;
- if (direction == sortDirection) return;
- int [] indices = getSelectionIndices ();
- sortDirection = direction;
- int id = 0, order = OS.kDataBrowserOrderIncreasing;
- if (sortColumn != null && !sortColumn.isDisposed () && sortDirection != SWT.NONE) {
- id = sortColumn.id;
- if (sortDirection == SWT.DOWN) order = OS.kDataBrowserOrderDecreasing;
- }
- OS.SetDataBrowserSortProperty (handle, id);
- OS.SetDataBrowserSortOrder (handle, (short) order);
- selectIndices (indices, indices.length, true);
-}
-
-void setTableEmpty () {
- OS.SetDataBrowserScrollPosition (handle, 0, 0);
- itemCount = anchorFirst = anchorLast = savedAnchor = 0;
- items = new TableItem [4];
- if (imageBounds != null) {
- /* Reset the item height to the font height */
- imageBounds = null;
- setFontStyle (font);
- }
-}
-
-/**
- * Sets the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items
- * are scrolled or new items are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget();
- checkItems (false);
- int itemHeight = getItemHeight ();
- int [] top = new int [1], left = new int [1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- top [0] = Math.max (0, Math.min (itemHeight * itemCount + getHeaderHeight () - getClientArea ().height, index * itemHeight));
- OS.SetDataBrowserScrollPosition (handle, top [0], left [0]);
-}
-
-/**
- * Shows the column. If the column is already showing in the receiver,
- * this method simply returns. Otherwise, the columns are scrolled until
- * the column is visible.
- *
- * @param column the column to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the column is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the column has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void showColumn (TableColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (column.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (column.parent != this) return;
- int index = indexOf (column);
- if (columnCount <= 1 || !(0 <= index && index < columnCount)) return;
- // Get width and horizontal position of column
- short [] w = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (handle, column.id, w);
- int width = w [0];
- int x = 0;
- for (int i = 0; i < index; i++) {
- w = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (handle, columns[i].id, w);
- x += w [0];
- }
- // Get current scroll position
- int [] top = new int [1], left = new int [1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- // Scroll column into view
- if (x < left[0]) {
- OS.SetDataBrowserScrollPosition(handle, top [0], x);
- } else {
- Rectangle rect = getClientArea ();
- int maxWidth = rect.width;
- width = Math.min(width, maxWidth);
- if (x + width > left [0] + maxWidth) {
- left [0] = x + width - maxWidth;
- OS.SetDataBrowserScrollPosition(handle, top [0], left [0]);
- }
- }
-}
-
-void showIndex (int index) {
- if (0 <= index && index < itemCount) {
- /*
- * Bug in the Macintosh. When there is not room to show a
- * single item in the data browser, RevealDataBrowserItem()
- * scrolls the item such that it is above the top of the data
- * browser. The fix is to remember the index and scroll when
- * the data browser is resized.
- *
- * Bug in the Macintosh. When items are added to the data
- * browser after is has been hidden, RevealDataBrowserItem()
- * when called before the controls behind the data browser
- * are repainted causes a redraw. This redraw happens right
- * away causing pixel corruption. The fix is to remember the
- * index and scroll when the data browser is shown.
- */
- Rectangle rect = getClientArea ();
- if (rect.height < getItemHeight () || !OS.IsControlVisible (handle)) {
- showIndex = index;
- return;
- }
- showIndex = -1;
- TableItem item = _getItem (index);
- Rectangle itemRect = item.getBounds (0);
- if (!itemRect.isEmpty()) {
- if (rect.contains (itemRect.x, itemRect.y)
- && rect.contains (itemRect.x, itemRect.y + itemRect.height)) return;
- }
- int [] top = new int [1], left = new int [1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- OS.RevealDataBrowserItem (handle, getId (index), OS.kDataBrowserNoItem, (byte) OS.kDataBrowserRevealWithoutSelecting);
-
- /*
- * Bug in the Macintosh. For some reason, when the DataBrowser is scrolled
- * by RevealDataBrowserItem(), the scrollbars are not redrawn. The fix is to
- * force a redraw.
- */
- int [] newTop = new int [1], newLeft = new int [1];
- OS.GetDataBrowserScrollPosition (handle, newTop, newLeft);
- if (horizontalBar != null && newLeft [0] != left [0]) horizontalBar.redraw ();
- if (verticalBar != null && newTop [0] != top [0]) verticalBar.redraw ();
- }
-}
-
-/**
- * Shows the item. If the item is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the item is visible.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#showSelection()
- */
-public void showItem (TableItem item) {
- checkWidget ();
- checkItems (false);
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- int index = indexOf (item);
- if (index != -1) showIndex (index);
-}
-
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#showItem(TableItem)
- */
-public void showSelection () {
- checkWidget();
- checkItems (false);
- int index = getSelectionIndex ();
- if (index >= 0) showIndex (index);
-}
-
-int trackingProc (int browser, int id, int property, int theRect, int startPt, int modifiers) {
- return 1;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TableColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TableColumn.java
deleted file mode 100644
index 9d3572b51c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TableColumn.java
+++ /dev/null
@@ -1,616 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.DataBrowserListViewHeaderDesc;
-import org.eclipse.swt.internal.carbon.OS;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a column in a table widget.
- * <p><dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd> Move, Resize, Selection</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT and CENTER may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TableColumn extends Item {
- Table parent;
- int id, lastWidth, lastPosition, iconRef;
- boolean resizable;
- String toolTipText;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableColumn (Table parent, int style) {
- super (parent, checkStyle (style));
- resizable = true;
- this.parent = parent;
- parent.createItem (this, parent.getColumnCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableColumn (Table parent, int style, int index) {
- super (parent, checkStyle (style));
- resizable = true;
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize,typedListener);
- addListener (SWT.Move,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the column header is selected.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget ();
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Table</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Table getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Gets the moveable attribute. A column that is
- * not moveable cannot be reordered by the user
- * by dragging the header but may be reordered
- * by the programmer.
- *
- * @return the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public boolean getMoveable () {
- checkWidget ();
- int [] flags = new int [1];
- OS.GetDataBrowserPropertyFlags (parent.handle, id, flags);
- return (flags [0] & OS.kDataBrowserListViewMovableColumn) != 0;
-}
-
-/**
- * Gets the resizable attribute. A column that is
- * not resizable cannot be dragged by the user but
- * may be resized by the programmer.
- *
- * @return the resizable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getResizable () {
- checkWidget ();
- return resizable;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget ();
- short [] width = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (parent.handle, id, width);
- return Math.max (0, width [0]);
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void pack () {
- checkWidget ();
- GC gc = new GC (parent);
- int width = gc.stringExtent (text).x;
- if (iconRef != 0 || (image != null && OS.VERSION >= 0x1040)) {
- /* Note that the image is stretched to the header height */
- width += parent.headerHeight;
- if (text.length () != 0) width += parent.getGap ();
- }
- int index = parent.indexOf (this);
- for (int i=0; i<parent.itemCount; i++) {
- TableItem item = parent.items [i];
- if (item != null && item.cached) {
- width = Math.max (width, item.calculateWidth (index, gc));
- }
- }
- gc.dispose ();
- setWidth (width + parent.getInsetWidth ());
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- id = -1;
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (parent.sortColumn == this) {
- parent.sortColumn = null;
- }
- if (iconRef != 0) OS.ReleaseIconRef (iconRef);
- iconRef = 0;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-void resized (int newWidth) {
- lastWidth = newWidth;
- sendEvent (SWT.Resize);
- if (isDisposed ()) return;
- boolean moved = false;
- int [] order = parent.getColumnOrder ();
- TableColumn [] columns = parent.getColumns ();
- for (int i=0; i<order.length; i++) {
- TableColumn column = columns [order [i]];
- if (moved && !column.isDisposed ()) {
- column.sendEvent (SWT.Move);
- }
- if (column == this) moved = true;
- }
-}
-
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>.
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget ();
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- int index = parent.indexOf (this);
- if (index == -1 || index == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- updateHeader ();
-}
-
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int index = parent.indexOf (this);
- if (index == -1) return;
- if (iconRef != 0) {
- OS.ReleaseIconRef (iconRef);
- iconRef = 0;
- }
- super.setImage (image);
- if (image != null) {
- if (OS.VERSION < 0x1040) {
- iconRef = createIconRef (image);
- }
- }
- updateHeader ();
-}
-
-/**
- * Sets the moveable attribute. A column that is
- * moveable can be reordered by the user by dragging
- * the header. A column that is not moveable cannot be
- * dragged by the user but may be reordered
- * by the programmer.
- *
- * @param moveable the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setColumnOrder(int[])
- * @see Table#getColumnOrder()
- * @see TableColumn#getMoveable()
- * @see SWT#Move
- *
- * @since 3.1
- */
-public void setMoveable (boolean moveable) {
- checkWidget ();
- int [] flags = new int [1];
- OS.GetDataBrowserPropertyFlags (parent.handle, id, flags);
- if (moveable) {
- flags [0] |= OS.kDataBrowserListViewMovableColumn;
- } else {
- flags [0] &= ~OS.kDataBrowserListViewMovableColumn;
- }
- OS.SetDataBrowserPropertyFlags (parent.handle, id, flags [0]);
-}
-
-/**
- * Sets the resizable attribute. A column that is
- * resizable can be resized by the user dragging the
- * edge of the header. A column that is not resizable
- * cannot be dragged by the user but may be resized
- * by the programmer.
- *
- * @param resizable the resize attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setResizable (boolean resizable) {
- checkWidget ();
- this.resizable = resizable;
- updateHeader ();
-}
-
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- updateHeader ();
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
-}
-
-/**
- * Sets the width of the receiver.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int width) {
- checkWidget ();
- if (width < 0) return;
- OS.SetDataBrowserTableViewNamedColumnWidth (parent.handle, id, (short) width);
- updateHeader ();
- if (width != lastWidth) resized (width);
-}
-
-void updateHeader () {
- char [] buffer = new char [text.length ()];
- text.getChars (0, buffer.length, buffer, 0);
- int length = fixMnemonic (buffer);
- int str = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, length);
- if (str == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- DataBrowserListViewHeaderDesc desc = new DataBrowserListViewHeaderDesc ();
- desc.version = OS.kDataBrowserListViewLatestHeaderDesc;
- desc.btnFontStyle_just = OS.teFlushLeft;
- if (parent.indexOf (this) != 0) {
- if ((style & SWT.CENTER) != 0) desc.btnFontStyle_just = OS.teCenter;
- if ((style & SWT.RIGHT) != 0) desc.btnFontStyle_just = OS.teFlushRight;
- }
- desc.btnFontStyle_flags |= OS.kControlUseJustMask;
- if (resizable) {
- desc.minimumWidth = 0;
- desc.maximumWidth = 0x7fff;
- } else {
- short [] width = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (parent.handle, id, width);
- desc.minimumWidth = desc.maximumWidth = width [0];
- }
- desc.titleString = str;
- if (OS.VERSION < 0x1040) {
- desc.btnContentInfo_contentType = (short) (iconRef != 0 ? OS.kControlContentIconRef : OS.kControlContentTextOnly);
- desc.btnContentInfo_iconRef = iconRef;
- } else {
- if (image != null) {
- desc.btnContentInfo_contentType = OS.kControlContentCGImageRef;
- desc.btnContentInfo_iconRef = image.handle;
- }
- }
- OS.SetDataBrowserListViewHeaderDesc (parent.handle, id, desc);
- OS.CFRelease (str);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TableItem.java
deleted file mode 100644
index 8077adf9d4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TableItem.java
+++ /dev/null
@@ -1,1081 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.Rect;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents an item in a table.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TableItem extends Item {
- Table parent;
- String [] strings;
- Image [] images;
- boolean checked, grayed, cached;
- Color foreground, background;
- Color[] cellForeground, cellBackground;
- Font font;
- Font[] cellFont;
- int width = -1;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableItem (Table parent, int style) {
- this (parent, style, checkNull (parent).getItemCount (), true);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableItem (Table parent, int style, int index) {
- this (parent, style, index, true);
-}
-
-TableItem (Table parent, int style, int index, boolean create) {
- super (parent, style);
- this.parent = parent;
- if (create) parent.createItem (this, index);
-}
-
-static Table checkNull (Table control) {
- if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return control;
-}
-
-int calculateWidth (int index, GC gc) {
- if (index == 0 && width != -1) return width;
- int width = 0;
- Image image = index == 0 ? this.image : (images == null ? null : images [index]);
- String text = index == 0 ? this.text : (strings == null ? "" : strings [index]);
- Font font = null;
- if (cellFont != null) font = cellFont[index];
- if (font == null) font = this.font;
- if (font == null) font = parent.getFont();
- gc.setFont (font);
- if (image != null) width += image.getBounds ().width + parent.getGap ();
- if (text != null && text.length () > 0) width += gc.stringExtent (text).x;
- boolean sendMeasure = true;
- if ((parent.style & SWT.VIRTUAL) != 0) {
- sendMeasure = cached;
- }
- if (sendMeasure && parent.hooks (SWT.MeasureItem)) {
- Event event = new Event ();
- event.item = this;
- event.index = index;
- event.gc = gc;
- short [] height = new short [1];
- OS.GetDataBrowserTableViewRowHeight (parent.handle, height);
- event.width = width;
- event.height = height[0];
- parent.sendEvent (SWT.MeasureItem, event);
- if (height[0] < event.height) {
- OS.SetDataBrowserTableViewRowHeight (parent.handle, (short) event.height);
- redrawWidget (parent.handle, false);
- }
- width = event.width;
- }
- if (index == 0) this.width = width;
- return width;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void clear () {
- text = "";
- image = null;
- strings = null;
- images = null;
- checked = grayed = cached = false;
- foreground = background = null;
- cellForeground = cellBackground = null;
- font = null;
- cellFont = null;
- width = -1;
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns the receiver's background color.
- *
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public Color getBackground () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return background != null ? background : parent.getBackground ();
-}
-
-/**
- * Returns the background color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Color getBackground (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count -1) return getBackground ();
- if (cellBackground == null || cellBackground [index] == null) return getBackground ();
- return cellBackground [index];
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Rectangle getBounds () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- Rect rect = new Rect();
- int itemIndex = parent.indexOf (this);
- if (itemIndex == -1) return new Rectangle (0, 0, 0, 0);
- int id = parent.getId (itemIndex);
- int columnId = parent.columnCount == 0 ? parent.column_id : parent.columns [0].id;
- if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyContentPart, rect) != OS.noErr) {
- return new Rectangle (0, 0, 0, 0);
- }
- int x = rect.left, y = rect.top;
- int width = 0;
- if (image != null) {
- Rectangle bounds = image.getBounds ();
- x += bounds.width + parent.getGap ();
- }
- GC gc = new GC (parent);
- Point extent = gc.stringExtent (text);
- gc.dispose ();
- width += extent.x;
- if (parent.columnCount > 0) {
- width = Math.min (width, rect.right - x);
- }
- int height = rect.bottom - rect.top;
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent at a column in the table.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding column rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- parent.checkItems (true);
- if (index != 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0);
- Rect rect = new Rect();
- int itemIndex = parent.indexOf (this);
- if (itemIndex == -1) return new Rectangle (0, 0, 0, 0);
- int id = parent.getId (itemIndex);
- int columnId = parent.columnCount == 0 ? parent.column_id : parent.columns [index].id;
- if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyEnclosingPart, rect) != OS.noErr) {
- return new Rectangle (0, 0, 0, 0);
- }
- int x, y, width, height;
- if (OS.VERSION >= 0x1040) {
- if (parent.getLinesVisible ()) {
- rect.left += Table.GRID_WIDTH;
- rect.top += Table.GRID_WIDTH;
- }
- x = rect.left;
- y = rect.top;
- width = rect.right - rect.left;
- height = rect.bottom - rect.top;
- } else {
- Rect rect2 = new Rect();
- if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyContentPart, rect2) != OS.noErr) {
- return new Rectangle (0, 0, 0, 0);
- }
- x = rect2.left;
- y = rect2.top;
- width = rect.right - rect2.left + 1;
- height = rect2.bottom - rect2.top + 1;
- }
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is checked,
- * and false otherwise. When the parent does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the checked state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getChecked () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return checked;
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information for this item.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return font != null ? font : parent.getFont ();
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information
- * for the specified cell in this item.
- *
- * @param index the column index
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count -1) return getFont ();
- if (cellFont == null || cellFont [index] == null) return getFont ();
- return cellFont [index];
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public Color getForeground () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return foreground != null ? foreground : parent.getForeground ();
-}
-
-/**
- *
- * Returns the foreground color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Color getForeground (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count -1) return getForeground ();
- if (cellForeground == null || cellForeground [index] == null) return getForeground ();
- return cellForeground [index];
-}
-
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the parent does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getGrayed () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return grayed;
-}
-
-public Image getImage () {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return super.getImage ();
-}
-
-/**
- * Returns the image stored at the given column index in the receiver,
- * or null if the image has not been set or if the column does not exist.
- *
- * @param index the column index
- * @return the image stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage (int index) {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index == 0) return getImage ();
- if (images != null) {
- if (0 <= index && index < images.length) return images [index];
- }
- return null;
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of an image at a column in the
- * table. An empty rectangle is returned if index exceeds
- * the index of the table's last column.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding image rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getImageBounds (int index) {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- parent.checkItems (true);
- if (index != 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0);
- Rect rect = new Rect();
- int itemIndex = parent.indexOf (this);
- if (itemIndex == -1) return new Rectangle (0, 0, 0, 0);
- int id = parent.getId (itemIndex);
- int columnId = parent.columnCount == 0 ? parent.column_id : parent.columns [index].id;
- if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyContentPart, rect) != OS.noErr) {
- return new Rectangle (0, 0, 0, 0);
- }
- int x = rect.left, y = rect.top;
- int width = 0;
- if (index == 0 && image != null) {
- Rectangle bounds = image.getBounds ();
- width += bounds.width;
- }
- if (index != 0 && images != null && images[index] != null) {
- Rectangle bounds = images [index].getBounds ();
- width += bounds.width;
- }
- int height = rect.bottom - rect.top + 1;
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Gets the image indent.
- *
- * @return the indent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getImageIndent () {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return 0;
-}
-
-String getNameText () {
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (!cached) return "*virtual*"; //$NON-NLS-1$
- }
- return super.getNameText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Table</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Table getParent () {
- checkWidget ();
- return parent;
-}
-
-public String getText () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return super.getText ();
-}
-
-/**
- * Returns the text stored at the given column index in the receiver,
- * or empty string if the text has not been set.
- *
- * @param index the column index
- * @return the text stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index == 0) return getText ();
- if (strings != null) {
- if (0 <= index && index < strings.length) {
- String string = strings [index];
- return string != null ? string : "";
- }
- }
- return "";
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of the text at a column in the
- * table. An empty rectangle is returned if index exceeds
- * the index of the table's last column.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding text rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Rectangle getTextBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- parent.checkItems (true);
- if (index != 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0);
- Rect rect = new Rect();
- int itemIndex = parent.indexOf (this);
- if (itemIndex == -1) return new Rectangle (0, 0, 0, 0);
- int id = parent.getId (itemIndex);
- int columnId = parent.columnCount == 0 ? parent.column_id : parent.columns [index].id;
- if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyEnclosingPart, rect) != OS.noErr) {
- return new Rectangle (0, 0, 0, 0);
- }
- int imageWidth = 0;
- int margin = parent.getInsetWidth () / 2;
- Image image = getImage (index);
- if (image != null) {
- Rectangle bounds = image.getBounds ();
- imageWidth = bounds.width + parent.getGap ();
- }
- int x, y, width, height;
- if (OS.VERSION >= 0x1040) {
- if (parent.getLinesVisible ()) {
- rect.left += Table.GRID_WIDTH;
- rect.top += Table.GRID_WIDTH;
- }
- x = rect.left + imageWidth + margin;
- y = rect.top;
- width = Math.max (0, rect.right - rect.left - imageWidth - margin * 2);
- height = rect.bottom - rect.top;
- } else {
- Rect rect2 = new Rect();
- if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyContentPart, rect2) != OS.noErr) {
- return new Rectangle (0, 0, 0, 0);
- }
- x = rect2.left + imageWidth + margin;
- y = rect2.top;
- width = Math.max (0, rect.right - rect2.left + 1 - imageWidth - margin * 2);
- height = rect2.bottom - rect2.top + 1;
- }
- return new Rectangle (x, y, width, height);
-}
-
-void redraw (int propertyID) {
- if (parent.currentItem == this) return;
- if (!getDrawing () && propertyID != Table.CHECK_COLUMN_ID) return;
- int itemIndex = parent.indexOf (this);
- if (itemIndex == -1) return;
- int [] id = new int [] {parent.getId (itemIndex)};
- OS.UpdateDataBrowserItems (parent.handle, OS.kDataBrowserNoItem, id.length, id, OS.kDataBrowserItemNoProperty, propertyID);
- /*
- * Bug in the Macintosh. When the height of the row is smaller than the
- * check box, the tail of the check mark draws outside of the item part
- * bounds. This means it will not be redrawn when the item is unckeched.
- * The fix is to redraw the area.
- */
- if (propertyID == Table.CHECK_COLUMN_ID) {
- Rect rect = new Rect();
- if (OS.GetDataBrowserItemPartBounds (parent.handle, parent.getId (itemIndex), propertyID, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- int x = rect.left;
- int y = rect.top - 1;
- int width = rect.right - rect.left;
- int height = 1;
- redrawWidget (parent.handle, x, y, width, height, false);
- }
- }
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- parent.checkItems (true);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- strings = null;
- images = null;
- background = foreground = null;
- font = null;
- cellBackground = cellForeground = null;
- cellFont = null;
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setBackground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Color oldColor = background;
- if (oldColor == color) return;
- background = color;
- if (oldColor != null && oldColor.equals (color)) return;
- cached = true;
- redraw (OS.kDataBrowserNoItem);
-}
-
-/**
- * Sets the background color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setBackground (int index, Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count - 1) return;
- if (cellBackground == null) {
- if (color == null) return;
- cellBackground = new Color [count];
- }
- Color oldColor = cellBackground [index];
- if (oldColor == color) return;
- cellBackground [index] = color;
- if (oldColor != null && oldColor.equals (color)) return;
- cached = true;
- redraw (OS.kDataBrowserNoItem);
-}
-
-/**
- * Sets the checked state of the checkbox for this item. This state change
- * only applies if the Table was created with the SWT.CHECK style.
- *
- * @param checked the new checked state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setChecked (boolean checked) {
- checkWidget ();
- if ((parent.style & SWT.CHECK) == 0) return;
- if (this.checked == checked) return;
- setChecked (checked, false);
-}
-
-void setChecked (boolean checked, boolean notify) {
- this.checked = checked;
- cached = true;
- redraw (Table.CHECK_COLUMN_ID);
- if (notify) {
- Event event = new Event ();
- event.item = this;
- event.detail = SWT.CHECK;
- parent.postEvent (SWT.Selection, event);
- }
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for this item to the font specified by the argument, or to the default font
- * for that kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (Font font) {
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Font oldFont = this.font;
- if (oldFont == font) return;
- this.font = font;
- if (oldFont != null && oldFont.equals (font)) return;
- cached = true;
- redraw (OS.kDataBrowserNoItem);
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for the specified cell in this item to the font specified by the
- * argument, or to the default font for that kind of control if the
- * argument is null.
- *
- * @param index the column index
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (int index, Font font) {
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count - 1) return;
- if (cellFont == null) {
- if (font == null) return;
- cellFont = new Font [count];
- }
- Font oldFont = cellFont [index];
- if (oldFont == font) return;
- cellFont [index] = font;
- if (oldFont != null && oldFont.equals (font)) return;
- cached = true;
- redraw (OS.kDataBrowserNoItem);
-}
-
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setForeground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Color oldColor = foreground;
- if (oldColor == color) return;
- foreground = color;
- if (oldColor != null && oldColor.equals (color)) return;
- cached = true;
- redraw (OS.kDataBrowserNoItem);
-}
-
-/**
- * Sets the foreground color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setForeground (int index, Color color){
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count - 1) return;
- if (cellForeground == null) {
- if (color == null) return;
- cellForeground = new Color [count];
- }
- Color oldColor = cellForeground [index];
- if (oldColor == color) return;
- cellForeground [index] = color;
- if (oldColor != null && oldColor.equals (color)) return;
- cached = true;
- redraw (OS.kDataBrowserNoItem);
-}
-
-/**
- * Sets the grayed state of the checkbox for this item. This state change
- * only applies if the Table was created with the SWT.CHECK style.
- *
- * @param grayed the new grayed state of the checkbox;
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setGrayed (boolean grayed) {
- checkWidget ();
- if ((parent.style & SWT.CHECK) == 0) return;
- if (this.grayed == grayed) return;
- this.grayed = grayed;
- cached = true;
- redraw (Table.CHECK_COLUMN_ID);
-}
-
-/**
- * Sets the image for multiple columns in the table.
- *
- * @param images the array of new images
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image [] images) {
- checkWidget();
- if (images == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<images.length; i++) {
- setImage (i, images [i]);
- }
-}
-
-/**
- * Sets the receiver's image at a column.
- *
- * @param index the column index
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (int index, Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int itemIndex = parent.indexOf (this);
- if (itemIndex == -1) return;
- if (parent.imageBounds == null && image != null) {
- parent.setItemHeight (image);
- }
- if (index == 0) {
- if (image != null && image.type == SWT.ICON) {
- if (image.equals (this.image)) return;
- }
- width = -1;
- super.setImage (image);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 <= index && index < count) {
- if (images == null) images = new Image [count];
- if (image != null && image.type == SWT.ICON) {
- if (image.equals (images [index])) return;
- }
- images [index] = image;
- }
- cached = true;
- if (index == 0) parent.setScrollWidth (this);
- redraw (OS.kDataBrowserNoItem);
-}
-
-public void setImage (Image image) {
- checkWidget ();
- setImage (0, image);
-}
-
-/**
- * Sets the indent of the first column's image, expressed in terms of the image's width.
- *
- * @param indent the new indent
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @deprecated this functionality is not supported on most platforms
- */
-public void setImageIndent (int indent) {
- checkWidget();
- if (indent < 0) return;
- cached = true;
- /* Image indent is not supported on the Macintosh */
-}
-
-/**
- * Sets the text for multiple columns in the table.
- *
- * @param strings the array of new strings
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String [] strings) {
- checkWidget();
- if (strings == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<strings.length; i++) {
- String string = strings [i];
- if (string != null) setText (i, string);
- }
-}
-
-/**
- * Sets the receiver's text at a column
- *
- * @param index the column index
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (int index, String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (index == 0) {
- if (string.equals (text)) return;
- width = -1;
- super.setText (string);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 <= index && index < count) {
- if (strings == null) strings = new String [count];
- if (string.equals (strings [index])) return;
- strings [index] = string;
- }
- cached = true;
- if (index == 0) parent.setScrollWidth (this);
- redraw (OS.kDataBrowserNoItem);
-}
-
-public void setText (String string) {
- checkWidget();
- setText (0, string);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Text.java
deleted file mode 100644
index 4c204f0be3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Text.java
+++ /dev/null
@@ -1,2524 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.carbon.HILayoutInfo;
-import org.eclipse.swt.internal.carbon.HISideBinding;
-import org.eclipse.swt.internal.carbon.HIThemeFrameDrawInfo;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.RGBColor;
-import org.eclipse.swt.internal.carbon.Rect;
-import org.eclipse.swt.internal.carbon.ControlEditTextSelectionRec;
-import org.eclipse.swt.internal.carbon.ControlFontStyleRec;
-import org.eclipse.swt.internal.carbon.CFRange;
-import org.eclipse.swt.internal.carbon.CGRect;
-import org.eclipse.swt.internal.carbon.TXNTab;
-import org.eclipse.swt.internal.carbon.CGPoint;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify text.
- * Text controls can be either single or multi-line.
- * When a text control is created with a border, the
- * operating system includes a platform specific inset
- * around the contents of the control. When created
- * without a border, an effort is made to remove the
- * inset such that the preferred size of the control
- * is the same size as the contents.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>CENTER, ICON_CANCEL, ICON_SEARCH, LEFT, MULTI, PASSWORD, SEARCH, SINGLE, RIGHT, READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Modify, Verify</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles MULTI and SINGLE may be specified,
- * and only one of the styles LEFT, CENTER, and RIGHT may be specified.
- * </p>
- * <p>
- * Note: The styles ICON_CANCEL and ICON_SEARCH are hints used in combination with SEARCH.
- * When the platform supports the hint, the text control shows these icons. When an icon
- * is selected, a default selection event is sent with the detail field set to one of
- * ICON_CANCEL or ICON_SEARCH. Normally, application code does not need to check the
- * detail. In the case of ICON_CANCEL, the text is cleared before the default selection
- * event is sent causing the application to search for an empty string.
- * </p>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#text">Text snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Text extends Scrollable {
- int txnObject, frameHandle;
- int textLimit = LIMIT, tabs = 8;
- ControlEditTextSelectionRec selection;
- char echoCharacter;
- boolean doubleClick;
- String hiddenText, message;
-
- /**
- * The maximum number of characters that can be entered
- * into a text widget.
- * <p>
- * Note that this value is platform dependent, based upon
- * the native widget implementation.
- * </p>
- */
- public static final int LIMIT;
-
- /**
- * The delimiter used by multi-line text widgets. When text
- * is queried and from the widget, it will be delimited using
- * this delimiter.
- */
- public static final String DELIMITER;
- static final char PASSWORD = '\u2022';
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0x7FFFFFFF;
- DELIMITER = "\r";
- }
-
- static final String [] AX_ATTRIBUTES = {
- OS.kAXTitleAttribute,
- OS.kAXValueAttribute,
- OS.kAXNumberOfCharactersAttribute,
- OS.kAXSelectedTextAttribute,
- OS.kAXSelectedTextRangeAttribute,
- OS.kAXStringForRangeParameterizedAttribute,
- };
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#READ_ONLY
- * @see SWT#WRAP
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see SWT#PASSWORD
- * @see SWT#SEARCH
- * @see SWT#ICON_SEARCH
- * @see SWT#ICON_CANCEL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Text (Composite parent, int style) {
- super (parent, checkStyle (style));
- if ((style & SWT.SEARCH) != 0) {
- /*
- * Ensure that SWT.ICON_CANCEL and ICON_SEARCH are set.
- * NOTE: ICON_CANCEL has the same value as H_SCROLL and
- * ICON_SEARCH has the same value as V_SCROLL so it is
- * necessary to first clear these bits to avoid a scroll
- * bar and then reset the bit using the original style
- * supplied by the programmer.
- */
- int attributes = OS.kHISearchFieldNoAttributes;
- if ((style & SWT.ICON_CANCEL) != 0) {
- this.style |= SWT.ICON_CANCEL;
- attributes |= OS.kHISearchFieldAttributesCancel;
- }
- if ((style & SWT.ICON_SEARCH) != 0) {
- this.style |= SWT.ICON_SEARCH;
- attributes |= OS.kHISearchFieldAttributesSearchIcon;
- }
- if (attributes != OS.kHISearchFieldNoAttributes) {
- OS.HISearchFieldChangeAttributes (handle, attributes, 0);
- }
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is not called for texts.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text,
- * or when ENTER is pressed in a search text. If the receiver has the <code>SWT.SEARCH | SWT.CANCEL</code> style
- * and the user cancels the search, the event object detail field contains the value <code>SWT.CANCEL</code>.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- */
-public void addVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-
-/**
- * Appends a string.
- * <p>
- * The new text is appended to the text at
- * the end of the widget.
- * </p>
- *
- * @param string the string to be appended
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void append (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- int charCount = getCharCount ();
- string = verifyText (string, charCount, charCount, null);
- if (string == null) return;
- }
- if (txnObject == 0) {
- setSelection (getCharCount ());
- insertEditText (string);
- } else {
- setTXNText (OS.kTXNEndOffset, OS.kTXNEndOffset, string);
- OS.TXNSetSelection (txnObject, OS.kTXNEndOffset, OS.kTXNEndOffset);
- OS.TXNShowSelection (txnObject, false);
- }
- if (string.length () != 0) sendModifyEvent (true);
-}
-
-static int checkStyle (int style) {
- if ((style & SWT.SEARCH) != 0) {
- style |= SWT.SINGLE | SWT.BORDER;
- style &= ~SWT.PASSWORD;
- /*
- * NOTE: ICON_CANCEL has the same value as H_SCROLL and
- * ICON_SEARCH has the same value as V_SCROLL so they are
- * cleared because SWT.SINGLE is set.
- */
- }
- if ((style & SWT.SINGLE) != 0 && (style & SWT.MULTI) != 0) {
- style &= ~SWT.MULTI;
- }
- style = checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
- if ((style & SWT.SINGLE) != 0) style &= ~(SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP);
- if ((style & SWT.WRAP) != 0) {
- style |= SWT.MULTI;
- style &= ~SWT.H_SCROLL;
- }
- if ((style & SWT.MULTI) != 0) style &= ~SWT.PASSWORD;
- if ((style & (SWT.SINGLE | SWT.MULTI)) != 0) return style;
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) return style | SWT.MULTI;
- return style | SWT.SINGLE;
-}
-
-int callPaintEventHandler (int control, int damageRgn, int visibleRgn, int theEvent, int nextHandler) {
- int result = super.callPaintEventHandler (control, damageRgn, visibleRgn, theEvent, nextHandler);
- if (frameHandle == control) {
- int [] context = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamCGContextRef, OS.typeCGContextRef, null, 4, null, context);
- OS.CGContextSaveGState (context[0]);
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricFocusRectOutset, outMetric);
- CGRect rect = new CGRect ();
- OS.HIViewGetBounds (frameHandle, rect);
- rect.x += outMetric [0];
- rect.y += outMetric [0];
- rect.width -= outMetric [0] * 2;
- rect.height -= outMetric [0] * 2;
- int state;
- if (OS.IsControlEnabled (control)) {
- state = OS.IsControlActive (control) ? OS.kThemeStateActive : OS.kThemeStateInactive;
- } else {
- state = OS.IsControlActive (control) ? OS.kThemeStateUnavailable : OS.kThemeStateUnavailableInactive;
- }
- HIThemeFrameDrawInfo info = new HIThemeFrameDrawInfo ();
- info.state = state;
- info.isFocused = hasFocus ();
- info.kind = OS.kHIThemeFrameTextFieldSquare;
- OS.HIThemeDrawFrame (rect, info, context [0], OS.kHIThemeOrientationNormal);
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == (SWT.V_SCROLL | SWT.H_SCROLL)) {
- OS.HIViewGetBounds (frameHandle, rect);
- rect.x = rect.width - outMetric [0];
- rect.y = rect.height - outMetric [0];
- OS.GetThemeMetric (OS.kThemeMetricEditTextFrameOutset, outMetric);
- rect.x -= outMetric [0];
- rect.y -= outMetric [0];
- OS.GetThemeMetric (OS.kThemeMetricScrollBarWidth, outMetric);
- rect.x -= outMetric [0];
- rect.y -= outMetric [0];
- rect.width = rect.height = outMetric [0];
- OS.CGContextSetFillColor (context [0], new float[]{1, 1, 1, 1});
- OS.CGContextFillRect (context [0], rect);
- }
- OS.CGContextRestoreGState (context[0]);
- }
- return result;
-}
-
-int callFocusEventHandler (int nextHandler, int theEvent) {
- short [] part = new short [1];
- if (txnObject == 0) {
- OS.GetEventParameter (theEvent, OS.kEventParamControlPart, OS.typeControlPartCode, null, 2, null, part);
- if (part [0] == OS.kControlFocusNoPart) {
- selection = new ControlEditTextSelectionRec ();
- OS.GetControlData (handle, (short) OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection, null);
- }
- }
- int result = super.callFocusEventHandler (nextHandler, theEvent);
- if (isDisposed () ) return result;
- if (frameHandle != 0) {
- OS.HIViewSetNeedsDisplay (frameHandle, true);
- }
- if (txnObject == 0) {
- if (part [0] != OS.kControlFocusNoPart && selection != null) {
- OS.SetControlData (handle, (short) OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection);
- selection = null;
- }
- }
- return result;
-}
-
-/**
- * Clears the selection.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void clearSelection () {
- checkWidget();
- if (txnObject == 0) {
- Point selection = getSelection ();
- setSelection (selection.x);
- } else {
- int [] oStartOffset = new int [1], oEndOffset = new int [1];
- OS.TXNGetSelection (txnObject, oStartOffset, oEndOffset);
- OS.TXNSetSelection (txnObject, oStartOffset [0], oStartOffset [0]);
- }
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = 0, height = 0;
- if (txnObject == 0) {
- if ((style & SWT.SEARCH) != 0) {
- int [] ptr1 = new int [1];
- OS.GetControlData (handle, (short)OS.kControlEntireControl, OS.kControlEditTextCFStringTag, 4, ptr1, null);
- Point size1 = textExtent (ptr1 [0], 0);
- if (ptr1 [0] != 0) OS.CFRelease (ptr1 [0]);
- width = size1.x;
- height = size1.y;
- int [] metric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricEditTextWhitespace, metric);
- height += metric [0] * 2;
- OS.GetThemeMetric (OS.kThemeMetricEditTextFrameOutset, metric);
- height += metric [0] * 2;
- } else {
- if ((style & SWT.RIGHT) != 0) {
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlEditTextSingleLineTag, 1, new byte [] {1});
- }
- Rect rect = new Rect ();
- OS.GetBestControlRect (handle, rect, null);
- if ((style & SWT.RIGHT) != 0) {
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlEditTextSingleLineTag, 1, new byte [] {0});
- }
- width = rect.right - rect.left;
- height = rect.bottom - rect.top;
- }
- } else {
- int [] oDataHandle = new int [1];
- OS.TXNGetData (txnObject, OS.kTXNStartOffset, OS.kTXNEndOffset, oDataHandle);
- if (oDataHandle [0] != 0) {
- int length = OS.GetHandleSize (oDataHandle [0]), str = 0;
- if (length != 0) {
- int [] ptr = new int [1];
- OS.HLock (oDataHandle [0]);
- OS.memmove (ptr, oDataHandle [0], 4);
- str = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, ptr [0], length / 2);
- OS.HUnlock (oDataHandle[0]);
- }
- OS.DisposeHandle (oDataHandle[0]);
- Point size = textExtent (str, wHint != SWT.DEFAULT && (style & SWT.WRAP) != 0 ? wHint : 0);
- if (str != 0) OS.CFRelease(str);
- width = size.x;
- height = size.y;
- }
- }
- int length = message.length ();
- if ((style & SWT.SINGLE) != 0 && length > 0) {
- char [] buffer = new char [length];
- message.getChars (0, length, buffer, 0);
- Point size = textExtent (buffer, 0);
- width = Math.max (width, size.x);
- }
- if (width <= 0) width = DEFAULT_WIDTH;
- if (height <= 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- Rectangle trim = computeTrim (0, 0, width, height);
- width = trim.width;
- height = trim.height;
- return new Point (width, height);
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
- int [] size = new int [1];
- OS.GetThemeMetric(OS.kThemeMetricScrollBarWidth, size);
- if (horizontalBar != null) height += size [0];
- if (verticalBar != null) width += size [0];
- Rect inset = inset ();
- x -= inset.left;
- y -= inset.top;
- width += inset.left + inset.right;
- height += inset.top + inset.bottom;
- if (txnObject == 0) {
- inset = getInset ();
- x -= inset.left;
- y -= inset.top;
- width += inset.left + inset.right;
- height += inset.top + inset.bottom;
- }
- if ((style & SWT.SEARCH) != 0) {
- int [] left = new int [1], right = new int [1];
- int [] outAttributes = new int [1];
- OS.HISearchFieldGetAttributes (handle, outAttributes);
- if ((outAttributes [0] & OS.kHISearchFieldAttributesSearchIcon) != 0) {
- OS.GetThemeMetric (display.smallFonts ? OS.kThemeMetricRoundTextFieldSmallContentInsetWithIconLeft : OS.kThemeMetricRoundTextFieldContentInsetWithIconLeft, left);
- } else {
- OS.GetThemeMetric (display.smallFonts ? OS.kThemeMetricRoundTextFieldSmallContentInsetLeft : OS.kThemeMetricRoundTextFieldContentInsetLeft, left);
- }
- if ((outAttributes [0] & OS.kHISearchFieldAttributesCancel) != 0) {
- OS.GetThemeMetric (display.smallFonts ? OS.kThemeMetricRoundTextFieldSmallContentInsetWithIconRight : OS.kThemeMetricRoundTextFieldContentInsetWithIconRight, right);
- } else {
- OS.GetThemeMetric (display.smallFonts ? OS.kThemeMetricRoundTextFieldSmallContentInsetRight : OS.kThemeMetricRoundTextFieldContentInsetRight, right);
- }
- width += left [0] + right [0];
- }
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void copy () {
- checkWidget ();
- if ((style & SWT.PASSWORD) != 0 || echoCharacter != '\0') return;
- if (txnObject == 0) {
- Point selection = getSelection ();
- if (selection.x == selection.y) return;
- copyToClipboard (getEditText (selection.x, selection.y - 1));
- } else {
- OS.TXNCopy (txnObject);
- }
-}
-
-void createHandle () {
- if ((style & SWT.READ_ONLY) != 0) {
- if ((style & (SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
- state |= THEME_BACKGROUND;
- }
- }
- int [] outControl = new int [1];
- if ((style & SWT.MULTI) != 0 || (style & (SWT.BORDER | SWT.SEARCH)) == 0) {
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0 || OS.VERSION >= 0x1050) {
- int options = 0;
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == (SWT.H_SCROLL | SWT.V_SCROLL)) options |= OS.kHIScrollViewOptionsAllowGrow;
- if ((style & SWT.H_SCROLL) != 0) options |= OS.kHIScrollViewOptionsHorizScroll;
- if ((style & SWT.V_SCROLL) != 0) options |= OS.kHIScrollViewOptionsVertScroll;
- /*
- * Bug in the Macintosh. HIScrollViewCreate() fails if no scroll bit is
- * specified. In order to get horizontal scrolling in a single line text, a
- * scroll view is created with the vertical bit set and the scroll bars
- * are set to auto hide. But calling HIScrollViewSetScrollBarAutoHide()
- * before the view has been resized still leaves space for the vertical
- * scroll bar. The fix is to call HIScrollViewSetScrollBarAutoHide()
- * once the widget has been resized.
- */
- if (options == 0) options |= OS.kHIScrollViewOptionsVertScroll;
- OS.HIScrollViewCreate (options, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- scrolledHandle = outControl [0];
- OS.HIViewSetVisible (scrolledHandle, true);
- }
- int iFrameOptions = OS.kTXNDontDrawCaretWhenInactiveMask | OS.kTXNMonostyledTextMask;
- /*
- * Bug in the Macintosh. For some reason a single line text does not
- * display properly when it is right aligned. The fix is to use a
- * multi line text when right aligned.
- */
- if ((style & SWT.RIGHT) == 0) {
- if ((style & SWT.SINGLE) != 0) iFrameOptions |= OS.kTXNSingleLineOnlyMask;
- }
- if ((style & SWT.WRAP) != 0) iFrameOptions |= OS.kTXNAlwaysWrapAtViewEdgeMask;
- OS.HITextViewCreate (null, 0, iFrameOptions, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
- OS.HIViewSetVisible (handle, true);
- if ((state & THEME_BACKGROUND) != 0) OS.HITextViewSetBackgroundColor (handle, 0);
- if ((style & SWT.MULTI) != 0 && (style & SWT.BORDER) != 0) {
- int features = OS.kControlSupportsEmbedding;
- OS.CreateUserPaneControl (0, null, features, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- frameHandle = outControl [0];
- }
- txnObject = OS.HITextViewGetTXNObject (handle);
- int ptr = OS.NewPtr (Rect.sizeof);
- Rect rect = (style & SWT.SINGLE) != 0 ? inset () : new Rect ();
- OS.memmove (ptr, rect, Rect.sizeof);
- int [] tags = new int [] {
- OS.kTXNDisableDragAndDropTag,
- OS.kTXNDoFontSubstitution,
- OS.kTXNIOPrivilegesTag,
- OS.kTXNMarginsTag,
- OS.kTXNJustificationTag,
- };
- int just = OS.kTXNFlushLeft;
- if ((style & SWT.CENTER) != 0) just = OS.kTXNCenter;
- if ((style & SWT.RIGHT) != 0) just = OS.kTXNFlushRight;
- int [] datas = new int [] {
- 1,
- 1,
- (style & SWT.READ_ONLY) != 0 ? 1 : 0,
- ptr,
- just,
- };
- OS.TXNSetTXNObjectControls (txnObject, false, tags.length, tags, datas);
- OS.DisposePtr (ptr);
- } else {
- if ((style & SWT.SEARCH) != 0) {
- OS.HISearchFieldCreate (null, OS.kHISearchFieldNoAttributes, 0, 0, outControl);
- } else {
- int window = OS.GetControlOwner (parent.handle);
- OS.CreateEditUnicodeTextControl (window, null, 0, (style & SWT.PASSWORD) != 0, null, outControl);
- }
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
- if ((style & SWT.SEARCH) != 0 && display.smallFonts) {
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlSizeTag, 2, new short [] {OS.kControlSizeSmall});
- }
- /*
- * Bug in the Macintosh. For some reason a single line text does not
- * display selection properly when it is right aligned. The fix is to use a
- * multi line text when right aligned.
- */
- if ((style & SWT.RIGHT) == 0) {
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlEditTextSingleLineTag, 1, new byte [] {1});
- }
- if ((style & SWT.READ_ONLY) != 0) {
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlEditTextLockedTag, 1, new byte [] {1});
- }
- if ((style & (SWT.RIGHT | SWT.CENTER)) != 0) {
- ControlFontStyleRec fontStyle = new ControlFontStyleRec ();
- fontStyle.flags |= OS.kControlUseJustMask;
- if ((style & SWT.CENTER) != 0) fontStyle.just = OS.teJustCenter;
- if ((style & SWT.RIGHT) != 0) fontStyle.just = OS.teJustRight;
- OS.SetControlFontStyle (handle, fontStyle);
- }
- if ((style & SWT.SEARCH) != 0) {
- OS.HIViewSetVisible (handle, true);
- }
- }
-}
-
-ScrollBar createScrollBar (int style) {
- return createStandardBar (style);
-}
-
-void createWidget () {
- super.createWidget ();
- doubleClick = true;
- if ((style & SWT.PASSWORD) != 0) setEchoChar (PASSWORD);
- message = "";
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void cut () {
- checkWidget();
- if ((style & SWT.READ_ONLY) != 0) return;
- boolean cut = true;
- char [] oldText = null;
- Point oldSelection = getSelection ();
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- if (oldSelection.x != oldSelection.y) {
- oldText = getEditText (oldSelection.x, oldSelection.y - 1);
- String newText = verifyText ("", oldSelection.x, oldSelection.y, null);
- if (newText == null) return;
- if (newText.length () != 0) {
- copyToClipboard (oldText);
- if (txnObject == 0) {
- insertEditText (newText);
- } else {
- setTXNText (OS.kTXNUseCurrentSelection, OS.kTXNUseCurrentSelection, newText);
- OS.TXNShowSelection (txnObject, false);
- }
- cut = false;
- }
- }
- }
- if (cut) {
- if (txnObject == 0) {
- if (oldText == null) oldText = getEditText (oldSelection.x, oldSelection.y - 1);
- copyToClipboard (oldText);
- insertEditText ("");
- } else {
- OS.TXNCut (txnObject);
-
- /*
- * Feature in the Macintosh. When an empty string is set in the TXNObject,
- * the font attributes are cleared. The fix is to reset them.
- */
- if (OS.TXNDataSize (txnObject) / 2 == 0) setFontStyle (font);
- }
- }
- Point newSelection = getSelection ();
- if (!cut || !oldSelection.equals (newSelection)) sendModifyEvent (true);
-}
-
-Color defaultBackground () {
- return display.getSystemColor (SWT.COLOR_LIST_BACKGROUND);
-}
-
-Color defaultForeground () {
- return display.getSystemColor (SWT.COLOR_LIST_FOREGROUND);
-}
-
-void deregister () {
- super.deregister ();
- if (frameHandle != 0) display.removeWidget (frameHandle);
-}
-
-boolean dragDetect (int x, int y, boolean filter, boolean [] consume) {
- if (filter) {
- Point selection = getSelection ();
- if (selection.x != selection.y) {
- int position = getPosition (x, y);
- if (selection.x <= position && position < selection.y) {
- if (super.dragDetect (x, y, filter, consume)) {
- if (consume != null) consume [0] = true;
- return true;
- }
- }
- }
- return false;
- }
- return super.dragDetect (x, y, filter, consume);
-}
-
-void drawWidget (int control, int context, int damageRgn, int visibleRgn, int theEvent) {
- if ((style & SWT.SEARCH) == 0 && (style & SWT.SINGLE) != 0 && message.length () > 0) {
- if (!hasFocus () && getCharCount () == 0) {
- GCData data = new GCData ();
- data.paintEvent = theEvent;
- data.visibleRgn = visibleRgn;
- GC gc = GC.carbon_new (this, data);
- Display display = getDisplay ();
- short depth = (short)display.getDepth ();
- RGBColor rgb = new RGBColor ();
- OS.GetThemeTextColor ((short)OS.kThemeTextColorPushButtonInactive, depth, true, rgb);
- float red = ((rgb.red >> 8) & 0xFF) / 255f;
- float green = ((rgb.green >> 8) & 0xFF) / 255f;
- float blue = ((rgb.blue >> 8) & 0xFF) / 255f;
- Color color = Color.carbon_new (display, new float[]{red, green, blue, 1});
- gc.setForeground (color);
- Rect rect = inset ();
- gc.drawText (message, rect.left, rect.top);
- gc.dispose ();
- }
- }
- super.drawWidget(control, context, damageRgn, visibleRgn, theEvent);
-}
-
-int focusPart () {
- if ((style & SWT.SEARCH) != 0) return OS.kControlEditTextPart;
- return super.focusPart ();
-}
-
-String [] getAxAttributes () {
- return AX_ATTRIBUTES;
-}
-
-public int getBorderWidth () {
- checkWidget();
- if (hasBorder ()) {
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricEditTextFrameOutset, outMetric);
- return outMetric [0];
- }
- return 0;
-}
-
-/**
- * Returns the line number of the caret.
- * <p>
- * The line number of the caret is returned.
- * </p>
- *
- * @return the line number
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretLineNumber () {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return 0;
- return (getTopPixel () + getCaretLocation ().y) / getLineHeight ();
-}
-
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null).
- * <p>
- * The location of the caret is returned.
- * </p>
- *
- * @return a point, the location of the caret
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getCaretLocation () {
- checkWidget();
- if (txnObject == 0) {
- //TODO - caret location for unicode text
- return new Point (0, 0);
- }
- CGPoint oPoint = new CGPoint ();
- int [] oStartOffset = new int [1], oEndOffset = new int [1];
- OS.TXNGetSelection (txnObject, oStartOffset, oEndOffset);
- OS.TXNOffsetToHIPoint (txnObject, oStartOffset [0], oPoint);
- Rect oViewRect = new Rect ();
- OS.TXNGetViewRect (txnObject, oViewRect);
- return new Point ((int) oPoint.x - oViewRect.left, (int) oPoint.y - oViewRect.top);
-}
-
-/**
- * Returns the character position of the caret.
- * <p>
- * Indexing is zero based.
- * </p>
- *
- * @return the position of the caret
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretPosition () {
- checkWidget();
- if (txnObject == 0) {
- return getSelection ().x;
- }
- int [] oStartOffset = new int [1], oEndOffset = new int [1];
- OS.TXNGetSelection (txnObject, oStartOffset, oEndOffset);
- return oStartOffset [0];
-}
-
-/**
- * Returns the number of characters.
- *
- * @return number of characters in the widget
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCharCount () {
- checkWidget ();
- if (txnObject == 0) {
- int [] ptr = new int [1];
- int result = OS.GetControlData (handle, (short)OS.kControlEntireControl, OS.kControlEditTextCFStringTag, 4, ptr, null);
- if (result != OS.noErr) return 0;
- int length = OS.CFStringGetLength (ptr [0]);
- OS.CFRelease (ptr[0]);
- return length;
- }
- return OS.TXNDataSize (txnObject) / 2;
-}
-
-/**
- * Returns the double click enabled flag.
- * <p>
- * The double click flag enables or disables the
- * default action of the text widget when the user
- * double clicks.
- * </p>
- *
- * @return whether or not double click is enabled
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getDoubleClickEnabled () {
- checkWidget();
- return doubleClick;
-}
-
-/**
- * Returns the echo character.
- * <p>
- * The echo character is the character that is
- * displayed when the user enters text or the
- * text is changed by the programmer.
- * </p>
- *
- * @return the echo character
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setEchoChar
- */
-public char getEchoChar () {
- checkWidget();
- return echoCharacter;
-}
-
-/**
- * Returns the editable state.
- *
- * @return whether or not the receiver is editable
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getEditable () {
- checkWidget();
- return (style & SWT.READ_ONLY) == 0;
-}
-
-Rect getInset () {
- if ((style & SWT.SEARCH) != 0) return display.searchTextInset;
- if (txnObject != 0) return super.getInset ();
- return display.editTextInset;
-}
-
-/**
- * Returns the number of lines.
- *
- * @return the number of lines in the widget
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getLineCount () {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return 1;
- int [] oLineTotal = new int [1];
- OS.TXNGetLineCount (txnObject, oLineTotal);
- return oLineTotal [0];
-}
-
-/**
- * Returns the line delimiter.
- *
- * @return a string that is the line delimiter
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #DELIMITER
- */
-public String getLineDelimiter () {
- checkWidget();
- return DELIMITER;
-}
-
-/**
- * Returns the height of a line.
- *
- * @return the height of a row of text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getLineHeight () {
- checkWidget();
- if (txnObject == 0) {
- return textExtent (new char[]{' '}, 0).y;
- }
- int [] oLineWidth = new int [1], oLineHeight = new int [1];
- OS.TXNGetLineMetrics (txnObject, 0, oLineWidth, oLineHeight);
- return OS.Fix2Long (oLineHeight [0]);
-}
-
-/**
- * Returns the orientation of the receiver, which will be one of the
- * constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getOrientation () {
- checkWidget();
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-/**
- * Returns the widget message. The message text is displayed
- * as a hint for the user, indicating the purpose of the field.
- * <p>
- * Typically this is used in conjunction with <code>SWT.SEARCH</code>.
- * </p>
- *
- * @return the widget message
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public String getMessage () {
- checkWidget ();
- return message;
-}
-
-int getPosition (int x, int y) {
-// checkWidget ();
- if (txnObject == 0) return -1;
- int [] oOffset = new int [1];
- Rect oViewRect = new Rect ();
- OS.TXNGetViewRect (txnObject, oViewRect);
- CGPoint iPoint = new CGPoint ();
- iPoint.x = x + oViewRect.left;
- iPoint.y = y + oViewRect.top;
- return OS.TXNHIPointToOffset (txnObject, iPoint, oOffset) == OS.noErr ? oOffset [0] : -1;
-}
-
-/*public*/ int getPosition (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return getPosition (point.x, point.y);
-}
-
-/**
- * Returns a <code>Point</code> whose x coordinate is the
- * character position representing the start of the selected
- * text, and whose y coordinate is the character position
- * representing the end of the selection. An "empty" selection
- * is indicated by the x and y coordinates having the same value.
- * <p>
- * Indexing is zero based. The range of a selection is from
- * 0..N where N is the number of characters in the widget.
- * </p>
- *
- * @return a point representing the selection start and end
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSelection () {
- checkWidget();
- if (txnObject == 0) {
- ControlEditTextSelectionRec selection;
- if (this.selection != null) {
- selection = this.selection;
- } else {
- selection = new ControlEditTextSelectionRec ();
- OS.GetControlData (handle, (short) OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection, null);
- }
- return new Point (selection.selStart, selection.selEnd);
- } else {
- int [] oStartOffset = new int [1], oEndOffset = new int [1];
- OS.TXNGetSelection (txnObject, oStartOffset, oEndOffset);
- return new Point (oStartOffset [0], oEndOffset [0]);
- }
-}
-
-/**
- * Returns the number of selected characters.
- *
- * @return the number of selected characters.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget();
- if (txnObject == 0) {
- Point selection = getSelection ();
- return selection.y - selection.x;
- } else {
- int [] oStartOffset = new int [1], oEndOffset = new int [1];
- OS.TXNGetSelection (txnObject, oStartOffset, oEndOffset);
- return oEndOffset [0] - oStartOffset [0];
- }
-}
-
-/**
- * Gets the selected text, or an empty string if there is no current selection.
- *
- * @return the selected text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getSelectionText () {
- checkWidget();
- if (txnObject == 0) {
- Point selection = getSelection ();
- if (selection.x == selection.y) return "";
- return new String (getEditText (selection.x, selection.y - 1));
- } else {
- return getTXNText (OS.kTXNUseCurrentSelection, OS.kTXNUseCurrentSelection);
- }
-}
-
-/**
- * Returns the number of tabs.
- * <p>
- * Tab stop spacing is specified in terms of the
- * space (' ') character. The width of a single
- * tab stop is the pixel width of the spaces.
- * </p>
- *
- * @return the number of tab characters
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTabs () {
- checkWidget();
- return tabs;
-}
-
-/**
- * Returns the widget text.
- * <p>
- * The text for a text widget is the characters in the widget, or
- * an empty string if this has never been set.
- * </p>
- *
- * @return the widget text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- if (txnObject == 0) {
- return new String (getEditText ());
- } else {
- return getTXNText (OS.kTXNStartOffset, OS.kTXNEndOffset);
- }
-}
-
-/**
- * Returns a range of text. Returns an empty string if the
- * start of the range is greater than the end.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N-1 where N is
- * the number of characters in the widget.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- * @return the range of text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText (int start, int end) {
- checkWidget ();
- if (!(start <= end && 0 <= end)) return "";
- if (txnObject == 0) {
- return new String (getEditText (start, end));
- } else {
- int length = OS.TXNDataSize (txnObject) / 2;
- end = Math.min (end, length - 1);
- if (start > end) return "";
- start = Math.max (0, start);
- return getTXNText (start, end + 1);
- }
-}
-
-char [] getEditText () {
- int [] ptr = new int [1];
- int [] actualSize = new int [1];
- int result = OS.GetControlData (handle, (short)OS.kControlEntireControl, OS.kControlEditTextCFStringTag, 4, ptr, actualSize);
- if (result != OS.noErr) return new char [0];
- int length = OS.CFStringGetLength (ptr [0]);
- CFRange range = new CFRange ();
- range.length = length;
- char [] buffer = new char [range.length];
- if (hiddenText != null) {
- hiddenText.getChars (0, range.length, buffer, 0);
- } else {
- OS.CFStringGetCharacters (ptr [0], range, buffer);
- }
- OS.CFRelease (ptr [0]);
- return buffer;
-}
-
-char [] getEditText (int start, int end) {
- int [] ptr = new int [1];
- int [] actualSize = new int [1];
- int result = OS.GetControlData (handle, (short)OS.kControlEntireControl, OS.kControlEditTextCFStringTag, 4, ptr, actualSize);
- if (result != OS.noErr) return new char [0];
- int length = OS.CFStringGetLength (ptr [0]);
- end = Math.min (end, length - 1);
- if (start > end) return new char [0];
- start = Math.max (0, start);
- CFRange range = new CFRange ();
- range.location = start;
- range.length = Math.max (0, end - start + 1);
- char [] buffer = new char [range.length];
- if (hiddenText != null) {
- hiddenText.getChars (range.location, range.location + range.length, buffer, 0);
- } else {
- OS.CFStringGetCharacters (ptr [0], range, buffer);
- }
- OS.CFRelease (ptr [0]);
- return buffer;
-}
-
-/**
- * Returns the maximum number of characters that the receiver is capable of holding.
- * <p>
- * If this has not been changed by <code>setTextLimit()</code>,
- * it will be the constant <code>Text.LIMIT</code>.
- * </p>
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public int getTextLimit () {
- checkWidget();
- return textLimit;
-}
-
-/**
- * Returns the zero-relative index of the line which is currently
- * at the top of the receiver.
- * <p>
- * This index can change when lines are scrolled or new lines are added or removed.
- * </p>
- *
- * @return the index of the top line
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return 0;
- return getTopPixel () / getLineHeight ();
-}
-
-/**
- * Returns the top pixel.
- * <p>
- * The top pixel is the pixel position of the line
- * that is currently at the top of the widget. On
- * some platforms, a text widget can be scrolled by
- * pixels instead of lines so that a partial line
- * is displayed at the top of the widget.
- * </p><p>
- * The top pixel changes when the widget is scrolled.
- * The top pixel does not include the widget trimming.
- * </p>
- *
- * @return the pixel position of the top line
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopPixel () {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return 0;
- CGRect rect = new CGRect ();
- OS.TXNGetHIRect (txnObject, OS.kTXNDestinationRectKey, rect);
- int destY = (int) rect.y;
- OS.TXNGetHIRect (txnObject, OS.kTXNTextRectKey, rect);
- return destY - (int) rect.y;
-}
-
-char [] getTXNChars (int iStartOffset, int iEndOffset) {
- int [] oDataHandle = new int [1];
- OS.TXNGetData (txnObject, iStartOffset, iEndOffset, oDataHandle);
- if (oDataHandle [0] == 0) return new char [0];
- int length = OS.GetHandleSize (oDataHandle [0]);
- if (length == 0) return new char [0];
- int [] ptr = new int [1];
- OS.HLock (oDataHandle [0]);
- OS.memmove (ptr, oDataHandle [0], 4);
- char [] buffer = new char [length / 2];
- OS.memmove (buffer, ptr [0], length);
- OS.HUnlock (oDataHandle[0]);
- OS.DisposeHandle (oDataHandle[0]);
- return buffer;
-}
-
-String getTXNText (int iStartOffset, int iEndOffset) {
- return new String (getTXNChars (iStartOffset, iEndOffset));
-}
-
-void hookEvents () {
- super.hookEvents ();
- if ((style & SWT.SEARCH) != 0) {
- int searchProc = display.searchProc;
- int [] mask = new int [] {
- OS.kEventClassSearchField, OS.kEventSearchFieldCancelClicked,
- OS.kEventClassSearchField, OS.kEventSearchFieldSearchClicked,
- };
- int controlTarget = OS.GetControlEventTarget (handle);
- OS.InstallEventHandler (controlTarget, searchProc, mask.length / 2, mask, handle, null);
- }
- if (frameHandle != 0) {
- int controlProc = display.controlProc;
- int [] mask = new int [] {
- OS.kEventClassControl, OS.kEventControlDraw,
- };
- int controlTarget = OS.GetControlEventTarget (frameHandle);
- OS.InstallEventHandler (controlTarget, controlProc, mask.length / 2, mask, frameHandle, null);
- }
-}
-
-Rect inset () {
- if ((style & SWT.SEARCH) != 0) return super.inset ();
- if ((style & SWT.SINGLE) != 0 && (style & SWT.BORDER) == 0) {
- Rect rect = new Rect ();
- rect.left = rect.top = rect.right = rect.bottom = 1;
- return rect;
- }
- if ((style & SWT.MULTI) != 0 && (style & SWT.BORDER) != 0) {
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricFocusRectOutset, outMetric);
- Rect rect = new Rect ();
- rect.left += outMetric [0];
- rect.top += outMetric [0];
- rect.right += outMetric [0];
- rect.bottom += outMetric [0];
- OS.GetThemeMetric (OS.kThemeMetricEditTextFrameOutset, outMetric);
- rect.left += outMetric [0];
- rect.top += outMetric [0];
- rect.right += outMetric [0];
- rect.bottom += outMetric [0];
- return rect;
- }
- return new Rect ();
-}
-
-/**
- * Inserts a string.
- * <p>
- * The old selection is replaced with the new text.
- * </p>
- *
- * @param string the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is <code>null</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void insert (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- Point selection = getSelection ();
- string = verifyText (string, selection.x, selection.y, null);
- if (string == null) return;
- }
- if (txnObject == 0) {
- insertEditText (string);
- } else {
- setTXNText (OS.kTXNUseCurrentSelection, OS.kTXNUseCurrentSelection, string);
- OS.TXNShowSelection (txnObject, false);
- }
- if (string.length () != 0) sendModifyEvent (true);
-}
-
-void insertEditText (String string) {
- int length = string.length ();
- Point selection = getSelection ();
- if (hasFocus () && hiddenText == null) {
- if (textLimit != LIMIT) {
- int charCount = getCharCount();
- if (charCount - (selection.y - selection.x) + length > textLimit) {
- length = textLimit - charCount + (selection.y - selection.x);
- }
- }
- char [] buffer = new char [length];
- string.getChars (0, buffer.length, buffer, 0);
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (ptr == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlEditTextInsertCFStringRefTag, 4, new int[] {ptr});
- OS.CFRelease (ptr);
- } else {
- String oldText = getText ();
- if (textLimit != LIMIT) {
- int charCount = oldText.length ();
- if (charCount - (selection.y - selection.x) + length > textLimit) {
- string = string.substring(0, textLimit - charCount + (selection.y - selection.x));
- }
- }
- String newText = oldText.substring (0, selection.x) + string + oldText.substring (selection.y);
- setEditText (newText);
- setSelection (selection.x + string.length ());
- }
-}
-
-int kEventAccessibleGetNamedAttribute (int nextHandler, int theEvent, int userData) {
- int code = OS.eventNotHandledErr;
- if (txnObject != 0) {
- int [] stringRef = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamAccessibleAttributeName, OS.typeCFStringRef, null, 4, null, stringRef);
- int length = 0;
- if (stringRef [0] != 0) length = OS.CFStringGetLength (stringRef [0]);
- char [] buffer = new char [length];
- CFRange range = new CFRange ();
- range.length = length;
- OS.CFStringGetCharacters (stringRef [0], range, buffer);
- String attributeName = new String(buffer);
- if (attributeName.equals (OS.kAXRoleAttribute) || attributeName.equals (OS.kAXRoleDescriptionAttribute)) {
- String roleText = (style & SWT.MULTI) != 0 ? OS.kAXTextAreaRole : OS.kAXTextFieldRole;
- buffer = new char [roleText.length ()];
- roleText.getChars (0, buffer.length, buffer, 0);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- if (attributeName.equals (OS.kAXRoleAttribute)) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- } else { // kAXRoleDescriptionAttribute
- int stringRef2 = OS.HICopyAccessibilityRoleDescription (stringRef [0], 0);
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, new int [] {stringRef2});
- OS.CFRelease(stringRef2);
- }
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- } else if (OS.VERSION < 0x1050 && attributeName.equals (OS.kAXFocusedAttribute)) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeBoolean, 4, new boolean [] {hasFocus ()});
- code = OS.noErr;
- } else if (attributeName.equals (OS.kAXTitleAttribute)) {
- /*
- * Feature of the Macintosh. For some reason, AXTextFields return their text contents
- * when they are asked for their title. Since they also return their text contents
- * when they are asked for their value, this causes screen readers to speak the text
- * twice. The fix is to return nothing when asked for a title.
- */
- code = OS.noErr;
- } else if (attributeName.equals (OS.kAXValueAttribute)) {
- buffer = getTXNChars (OS.kTXNStartOffset, OS.kTXNEndOffset);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- } else if (attributeName.equals (OS.kAXNumberOfCharactersAttribute)) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeSInt32, 4, new int [] {getCharCount()});
- code = OS.noErr;
- } else if (attributeName.equals (OS.kAXSelectedTextAttribute)) {
- Point sel = getSelection ();
- buffer = getTXNChars (sel.x, sel.y);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- } else if (attributeName.equals (OS.kAXSelectedTextRangeAttribute)) {
- Point sel = getSelection ();
- range = new CFRange();
- range.location = sel.x;
- range.length = sel.y - sel.x;
- int valueRef = OS.AXValueCreate(OS.kAXValueCFRangeType, range);
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFTypeRef, 4, new int [] {valueRef});
- OS.CFRelease(valueRef);
- code = OS.noErr;
- } else if (attributeName.equals (OS.kAXStringForRangeParameterizedAttribute)) {
- int valueRef [] = new int [1];
- int status = OS.GetEventParameter (theEvent, OS.kEventParamAccessibleAttributeParameter, OS.typeCFTypeRef, null, 4, null, valueRef);
- if (status == OS.noErr) {
- range = new CFRange();
- boolean ok = OS.AXValueGetValue(valueRef[0], OS.kAXValueCFRangeType, range);
- if (ok) {
- buffer = getTXNChars (range.location, range.location + range.length);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- }
- }
- }
- }
- if (accessible != null) {
- code = accessible.internal_kEventAccessibleGetNamedAttribute (nextHandler, theEvent, code);
- }
- return code;
-}
-
-int kEventMouseDown (int nextHandler, int theEvent, int userData) {
- int result = super.kEventMouseDown (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- if (!doubleClick) {
- int [] clickCount = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamClickCount, OS.typeUInt32, null, 4, null, clickCount);
- if (clickCount [0] > 1) return OS.noErr;
- }
- return result;
-}
-
-int kEventSearchFieldCancelClicked (int nextHandler, int theEvent, int userData) {
- int result = super.kEventSearchFieldCancelClicked (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- setText ("");
- Event event = new Event ();
- event.detail = SWT.ICON_CANCEL;
- postEvent (SWT.DefaultSelection, event);
- return result;
-}
-
-int kEventSearchFieldSearchClicked (int nextHandler, int theEvent, int userData) {
- int result = super.kEventSearchFieldSearchClicked (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- Event event = new Event ();
- event.detail = SWT.ICON_SEARCH;
- postEvent (SWT.DefaultSelection, event);
- return result;
-}
-
-int kEventUnicodeKeyPressed (int nextHandler, int theEvent, int userData) {
- int result = super.kEventUnicodeKeyPressed (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- int [] keyboardEvent = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendKeyboardEvent, OS.typeEventRef, null, keyboardEvent.length * 4, null, keyboardEvent);
- int [] modifiers = new int [1];
- OS.GetEventParameter (keyboardEvent [0], OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
- if (modifiers [0] == OS.cmdKey) {
- int [] keyCode = new int [1];
- OS.GetEventParameter (keyboardEvent [0], OS.kEventParamKeyCode, OS.typeUInt32, null, keyCode.length * 4, null, keyCode);
- switch (keyCode [0]) {
- case 7: /* X */
- cut ();
- return OS.noErr;
- case 8: /* C */
- copy ();
- return OS.noErr;
- case 9: /* V */
- paste ();
- return OS.noErr;
- }
- }
- if ((style & SWT.SINGLE) != 0) {
- int [] keyCode = new int [1];
- OS.GetEventParameter (keyboardEvent [0], OS.kEventParamKeyCode, OS.typeUInt32, null, keyCode.length * 4, null, keyCode);
- switch (keyCode [0]) {
- /*
- * Feature in the Macintosh. Tab and Return characters are inserted into a
- * single line TXN Object. While this may be correct platform behavior, it is
- * unexpected. The fix is to avoid calling the default handler.
- */
- case 76: /* KP Enter */
- case 36: { /* Return */
- postEvent (SWT.DefaultSelection);
- return OS.noErr;
- }
- case 48: { /* Tab */
- return OS.noErr;
- }
- }
- }
- return result;
-}
-
-int kEventTextInputUpdateActiveInputArea (int nextHandler, int theEvent, int userData) {
- int [] length = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendText, OS.typeUnicodeText, null, 0, length, (char [])null);
- int [] fixed_length = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendFixLen, OS.typeLongInteger, null, 4, null, fixed_length);
- if (fixed_length [0] == -1 || fixed_length [0] == length [0]) {
- sendModifyEvent (false);
- }
- return OS.eventNotHandledErr;
-}
-
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void paste () {
- checkWidget();
- if ((style & SWT.READ_ONLY) != 0) return;
- boolean paste = true;
- String oldText = null;
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- oldText = getClipboardText ();
- if (oldText != null) {
- Point selection = getSelection ();
- String newText = verifyText (oldText, selection.x, selection.y, null);
- if (newText == null) return;
- if (!newText.equals (oldText)) {
- if (txnObject == 0) {
- insertEditText (newText);
- } else {
- setTXNText (OS.kTXNUseCurrentSelection, OS.kTXNUseCurrentSelection, newText);
- OS.TXNShowSelection (txnObject, false);
- }
- paste = false;
- }
- }
- }
- if (paste) {
- if (txnObject == 0) {
- if (oldText == null) oldText = getClipboardText ();
- insertEditText (oldText);
- } else {
- if (textLimit != LIMIT) {
- if (oldText == null) oldText = getClipboardText ();
- setTXNText (OS.kTXNUseCurrentSelection, OS.kTXNUseCurrentSelection, oldText);
- OS.TXNShowSelection (txnObject, false);
- } else {
- OS.TXNPaste (txnObject);
- }
- }
- }
- sendModifyEvent (true);
-}
-
-boolean pollTrackEvent() {
- return true;
-}
-
-void register () {
- super.register ();
- if (frameHandle != 0) display.addWidget (frameHandle, this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- txnObject = 0;
- hiddenText = message = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- */
-public void removeVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-
-/**
- * Selects all the text in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget();
- if (txnObject == 0) {
- setSelection (0, getCharCount ());
- } else {
- OS.TXNSelectAll (txnObject);
- }
-}
-
-boolean sendKeyEvent (int type, Event event) {
- if (!super.sendKeyEvent (type, event)) {
- return false;
- }
- if (type != SWT.KeyDown) return true;
- if ((style & SWT.READ_ONLY) != 0) return true;
- if (event.character == 0) return true;
- if ((event.stateMask & SWT.COMMAND) != 0) return true;
- String oldText = "";
- int charCount = getCharCount ();
- Point selection = getSelection ();
- int start = selection.x, end = selection.y;
- switch (event.character) {
- case SWT.BS:
- if (start == end) {
- if (start == 0) return true;
- start = Math.max (0, start - 1);
- }
- break;
- case SWT.DEL:
- if (start == end) {
- if (start == charCount) return true;
- end = Math.min (end + 1, charCount);
- }
- break;
- case SWT.CR:
- if ((style & SWT.SINGLE) != 0) return true;
- oldText = DELIMITER;
- break;
- default:
- if (event.character != '\t' && event.character < 0x20) return true;
- oldText = new String (new char [] {event.character});
- }
- String newText = verifyText (oldText, start, end, event);
- if (newText == null) return false;
- if (charCount - (end - start) + newText.length () > textLimit) {
- return false;
- }
- boolean result = newText == oldText;
- if (newText != oldText || hiddenText != null) {
- if (txnObject == 0) {
- String text = new String (getEditText ());
- String leftText = text.substring (0, start);
- String rightText = text.substring (end, text.length ());
- setEditText (leftText + newText + rightText);
- start += newText.length ();
- setSelection (new Point (start, start));
- result = false;
- } else {
- setTXNText (start, end, newText);
- }
- }
- /*
- * Post the modify event so that the character will be inserted
- * into the widget when the modify event is delivered. Normally,
- * modify events are sent but it is safe to post the event here
- * because this method is called from the event loop.
- */
- sendModifyEvent (false);
- return result;
-}
-
-void sendModifyEvent (boolean send) {
- String string = OS.kAXSelectedTextChangedNotification;
- char [] buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- int stringRef = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- OS.AXNotificationHIObjectNotify(stringRef, handle, 0);
- OS.CFRelease(stringRef);
- string = OS.kAXValueChangedNotification;
- buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- stringRef = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- OS.AXNotificationHIObjectNotify(stringRef, handle, 0);
- OS.CFRelease(stringRef);
-
- if (send) {
- sendEvent (SWT.Modify);
- } else {
- postEvent (SWT.Modify);
- }
-}
-
-void setBackground (float [] color) {
- if (txnObject == 0) {
- super.setBackground (color);
- } else {
- int colorspace = OS.CGColorSpaceCreateDeviceRGB ();
- int colorRef = OS.CGColorCreate (colorspace, color);
- OS.HITextViewSetBackgroundColor (handle, colorRef);
- OS.CGColorRelease (colorRef);
- OS.CGColorSpaceRelease (colorspace);
- }
-}
-
-void setBackground (int control, float [] color) {
- /*
- * Bug in the Macintosh. For some reason, when the same background
- * color is set in two instances of an EditUnicodeTextControl, the
- * color is not set in the second instance. It seems that the edit
- * control is checking globally that the last color that was set is the
- * same. The fix is to ensure the that the color that is about to
- * be set is not the same as the last globally remembered color by
- * first setting it to black, then white and finally the color.
- */
- if (handle == control) {
- ControlFontStyleRec fontStyle = new ControlFontStyleRec ();
- OS.GetControlData (control, (short) OS.kControlEntireControl, OS.kControlFontStyleTag, ControlFontStyleRec.sizeof, fontStyle, null);
- fontStyle.flags |= OS.kControlUseBackColorMask;
- OS.SetControlFontStyle (control, fontStyle);
- fontStyle.backColor_red = fontStyle.backColor_green = fontStyle.backColor_blue = (short) 0xffff;
- OS.SetControlFontStyle (control, fontStyle);
- }
- super.setBackground (control, color);
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- Rectangle bounds = null;
- if (txnObject == 0 && resize) bounds = getBounds ();
- int result = super.setBounds(x, y, width, height, move, resize, events);
- if (bounds != null && (result & RESIZED) != 0) {
- /*
- * Feature in the Macintosh. When the caret is moved,
- * the text widget scrolls to show the new location.
- * This means that the text widget may be scrolled
- * to the right in order to show the caret when the
- * widget is not large enough to show both the caret
- * location and all the text. Unfortunately, when
- * the text widget is resized such that all the text
- * and the caret could be visible, Macintosh does not
- * scroll the widget back. The fix is to reset the
- * selection or the text depend on if the widget
- * is on focus or not.
- */
- Rect inset = getInset ();
- int minWidth = inset.left + inset.right;
- if (bounds.width <= minWidth && width > minWidth) {
- if (hasFocus ()) {
- ControlEditTextSelectionRec selection = new ControlEditTextSelectionRec ();
- if (OS.GetControlData (handle, (short) OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection, null) == OS.noErr) {
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection);
- }
- } else {
- int [] ptr = new int [1];
- if (OS.GetControlData (handle, (short)OS.kControlEntireControl, OS.kControlEditTextCFStringTag, 4, ptr, null) == OS.noErr) {
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlEditTextCFStringTag, 4, ptr);
- }
- if (ptr [0] != 0) OS.CFRelease (ptr [0]);
- }
- }
- }
- /*
- * Bug in the Macintosh. HIScrollViewCreate() fails if no scroll bit is
- * specified. In order to get horizontal scrolling in a single line text, a
- * scroll view is created with the vertical bit set and the scroll bars
- * are set to auto hide. But calling HIScrollViewSetScrollBarAutoHide()
- * before the view has been resized still leaves space for the vertical
- * scroll bar. The fix is to call HIScrollViewSetScrollBarAutoHide()
- * once the widget has been resized.
- */
- if (scrolledHandle != 0 && (style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
- OS.HIScrollViewSetScrollBarAutoHide (scrolledHandle, true);
- }
- return result;
-}
-
-/**
- * Sets the double click enabled flag.
- * <p>
- * The double click flag enables or disables the
- * default action of the text widget when the user
- * double clicks.
- * </p><p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param doubleClick the new double click flag
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDoubleClickEnabled (boolean doubleClick) {
- checkWidget();
- this.doubleClick = doubleClick;
-}
-
-/**
- * Sets the echo character.
- * <p>
- * The echo character is the character that is
- * displayed when the user enters text or the
- * text is changed by the programmer. Setting
- * the echo character to '\0' clears the echo
- * character and redraws the original text.
- * If for any reason the echo character is invalid,
- * or if the platform does not allow modification
- * of the echo character, the default echo character
- * for the platform is used.
- * </p>
- *
- * @param echo the new echo character
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEchoChar (char echo) {
- checkWidget();
- if ((style & SWT.MULTI) != 0) return;
- if (txnObject == 0) {
- if ((style & SWT.PASSWORD) == 0) {
- Point selection = getSelection ();
- String text = getText ();
- echoCharacter = echo;
- setEditText (text);
- setSelection (selection);
- }
- } else {
- OS.TXNEchoMode (txnObject, echo, OS.kTextEncodingMacUnicode, echo != '\0');
- }
- echoCharacter = echo;
-}
-
-/**
- * Sets the editable state.
- *
- * @param editable the new editable state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEditable (boolean editable) {
- checkWidget();
- if (editable) {
- style &= ~SWT.READ_ONLY;
- } else {
- style |= SWT.READ_ONLY;
- }
- if (txnObject == 0) {
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlEditTextLockedTag, 1, new byte [] {(byte) ((style & SWT.READ_ONLY) != 0 ? 1 : 0)});
- } else {
- OS.TXNSetTXNObjectControls (txnObject, false, 1, new int [] {OS.kTXNIOPrivilegesTag}, new int [] {((style & SWT.READ_ONLY) != 0) ? 1 : 0});
- }
-}
-
-void setForeground (float [] color) {
- if (txnObject == 0) {
- super.setForeground (color);
- } else {
- int ptr2 = OS.NewPtr (OS.kTXNQDFontColorAttributeSize);
- RGBColor rgb;
- if (color == null) {
- rgb = new RGBColor ();
- } else {
- rgb = toRGBColor (color);
- }
- OS.memmove (ptr2, rgb, RGBColor.sizeof);
- int [] attribs = new int [] {
- OS.kTXNQDFontColorAttribute,
- OS.kTXNQDFontColorAttributeSize,
- ptr2,
- };
- int ptr1 = OS.NewPtr (attribs.length * 4);
- OS.memmove (ptr1, attribs, attribs.length * 4);
- boolean readOnly = (style & SWT.READ_ONLY) != 0;
- int [] tag = new int [] {OS.kTXNIOPrivilegesTag};
- if (readOnly) OS.TXNSetTXNObjectControls (txnObject, false, 1, tag, new int [] {0});
- OS.TXNSetTypeAttributes (txnObject, attribs.length / 3, ptr1, 0, 0);
- if (readOnly) OS.TXNSetTXNObjectControls (txnObject, false, 1, tag, new int [] {1});
- OS.DisposePtr (ptr1);
- OS.DisposePtr (ptr2);
- }
-}
-
-void setFontStyle (Font font) {
- if (txnObject == 0) {
- super.setFontStyle (font);
- } else {
- int family = OS.kTXNDefaultFontName, fontStyle = OS.kTXNDefaultFontStyle, size = OS.kTXNDefaultFontSize;
- if (font != null) {
- short [] id = new short [1], s = new short [1];
- OS.FMGetFontFamilyInstanceFromFont (font.handle, id, s);
- family = id [0];
- fontStyle = s [0] | font.style;
- size = OS.X2Fix (font.size);
- }
- int [] attribs = new int [] {
- OS.kTXNQDFontSizeAttribute,
- OS.kTXNQDFontSizeAttributeSize,
- size,
- OS.kTXNQDFontStyleAttribute,
- OS.kTXNQDFontStyleAttributeSize,
- fontStyle,
- OS.kTXNQDFontFamilyIDAttribute,
- OS.kTXNQDFontFamilyIDAttributeSize,
- family,
- };
- int ptr = OS.NewPtr (attribs.length * 4);
- OS.memmove (ptr, attribs, attribs.length * 4);
- boolean readOnly = (style & SWT.READ_ONLY) != 0;
- int [] tag = new int [] {OS.kTXNIOPrivilegesTag};
- if (readOnly) OS.TXNSetTXNObjectControls (txnObject, false, 1, tag, new int [] {0});
- OS.TXNSetTypeAttributes (txnObject, attribs.length / 3, ptr, 0, 0);
- if (readOnly) OS.TXNSetTXNObjectControls (txnObject, false, 1, tag, new int [] {1});
- OS.DisposePtr (ptr);
- }
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public void setOrientation (int orientation) {
- checkWidget();
-}
-
-/**
- * Sets the widget message. The message text is displayed
- * as a hint for the user, indicating the purpose of the field.
- * <p>
- * Typically this is used in conjunction with <code>SWT.SEARCH</code>.
- * </p>
- *
- * @param message the new message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the message is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public void setMessage (String message) {
- checkWidget ();
- if (message == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.message = message;
- if ((style & SWT.SEARCH) != 0) {
- char [] buffer = new char [message.length ()];
- message.getChars (0, buffer.length, buffer, 0);
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (ptr == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- OS.HISearchFieldSetDescriptiveText (handle, ptr);
- OS.CFRelease (ptr);
- } else {
- redraw (false);
- }
-}
-
-/**
- * Sets the selection.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * regular array indexing rules.
- * </p>
- *
- * @param start new caret position
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int start) {
- checkWidget();
- setSelection (start, start);
-}
-
-/**
- * Sets the selection to the range specified
- * by the given start and end indices.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * usual array indexing rules.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int start, int end) {
- checkWidget();
- if (txnObject == 0) {
- int length = getCharCount ();
- ControlEditTextSelectionRec selection = new ControlEditTextSelectionRec ();
- selection.selStart = (short) Math.min (Math.max (Math.min (start, end), 0), length);
- selection.selEnd = (short) Math.min (Math.max (Math.max (start, end), 0), length);
- if (hasFocus ()) {
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection);
- } else {
- this.selection = selection;
- }
- } else {
- int length = OS.TXNDataSize (txnObject) / 2;
- int nStart = Math.min (Math.max (Math.min (start, end), 0), length);
- int nEnd = Math.min (Math.max (Math.max (start, end), 0), length);
- OS.TXNSetSelection (txnObject, nStart, nEnd);
- OS.TXNShowSelection (txnObject, false);
- }
-}
-
-/**
- * Sets the selection to the range specified
- * by the given point, where the x coordinate
- * represents the start index and the y coordinate
- * represents the end index.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * usual array indexing rules.
- * </p>
- *
- * @param selection the point
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (Point selection) {
- checkWidget();
- if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (selection.x, selection.y);
-}
-
-/**
- * Sets the number of tabs.
- * <p>
- * Tab stop spacing is specified in terms of the
- * space (' ') character. The width of a single
- * tab stop is the pixel width of the spaces.
- * </p>
- *
- * @param tabs the number of tabs
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTabs (int tabs) {
- checkWidget();
- if (this.tabs == tabs) return;
- if (txnObject == 0) return;
- this.tabs = tabs;
- TXNTab tab = new TXNTab ();
- tab.value = (short) (textExtent (new char[]{' '}, 0).x * tabs);
- int [] tags = new int [] {OS.kTXNTabSettingsTag};
- int [] datas = new int [1];
- OS.memmove (datas, tab, TXNTab.sizeof);
- OS.TXNSetTXNObjectControls (txnObject, false, tags.length, tags, datas);
-}
-
-/**
- * Sets the contents of the receiver to the given string. If the receiver has style
- * SINGLE and the argument contains multiple lines of text, the result of this
- * operation is undefined and may vary from platform to platform.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- string = verifyText (string, 0, getCharCount (), null);
- if (string == null) return;
- }
- if (txnObject == 0) {
- setEditText (string);
- } else {
- setTXNText (OS.kTXNStartOffset, OS.kTXNEndOffset, string);
- OS.TXNSetSelection (txnObject, OS.kTXNStartOffset, OS.kTXNStartOffset);
- OS.TXNShowSelection (txnObject, false);
- }
- sendModifyEvent (true);
-}
-
-void setEditText (String string) {
- char [] buffer;
- if ((style & SWT.PASSWORD) == 0 && echoCharacter != '\0') {
- hiddenText = string;
- buffer = new char [Math.min(hiddenText.length (), textLimit)];
- for (int i = 0; i < buffer.length; i++) buffer [i] = echoCharacter;
- } else {
- hiddenText = null;
- buffer = new char [Math.min(string.length (), textLimit)];
- string.getChars (0, buffer.length, buffer, 0);
- }
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (ptr == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlEditTextCFStringTag, 4, new int[] {ptr});
- OS.CFRelease (ptr);
- if (selection != null) selection = null;
-}
-
-void setTXNText (int iStartOffset, int iEndOffset, String string) {
- int length = string.length ();
- if (textLimit != LIMIT) {
- int charCount = OS.TXNDataSize (txnObject) / 2;
- int start = iStartOffset, end = iEndOffset;
- if (iStartOffset == OS.kTXNUseCurrentSelection || iEndOffset == OS.kTXNUseCurrentSelection) {
- int [] oStartOffset = new int [1], oEndOffset = new int [1];
- OS.TXNGetSelection (txnObject, oStartOffset, oEndOffset);
- start = oStartOffset [0];
- end = oEndOffset [0];
- } else {
- if (iStartOffset == OS.kTXNEndOffset) start = charCount;
- if (iEndOffset == OS.kTXNEndOffset) end = charCount;
- }
- if (charCount - (end - start) + length > textLimit) length = textLimit - charCount + (end - start);
- }
- char [] buffer = new char [length];
- string.getChars (0, buffer.length, buffer, 0);
- boolean readOnly = (style & SWT.READ_ONLY) != 0;
- int [] tag = new int [] {OS.kTXNIOPrivilegesTag};
- if (readOnly) OS.TXNSetTXNObjectControls (txnObject, false, 1, tag, new int [] {0});
- OS.TXNSetData (txnObject, OS.kTXNUnicodeTextData, buffer, buffer.length * 2, iStartOffset, iEndOffset);
- if (readOnly) OS.TXNSetTXNObjectControls (txnObject, false, 1, tag, new int [] {1});
-
- /*
- * Feature in the Macintosh. When an empty string is set in the TXNObject,
- * the font attributes are cleared. The fix is to reset them.
- */
- if (OS.TXNDataSize (txnObject) / 2 == 0) setFontStyle (font);
-}
-
-void setZOrder () {
- if (frameHandle != 0) {
- int child = scrolledHandle != 0 ? scrolledHandle : handle;
- OS.HIViewAddSubview (frameHandle, child);
- HILayoutInfo layout = new HILayoutInfo ();
- layout.version = 0;
- OS.HIViewGetLayoutInfo (child, layout);
- HISideBinding biding = layout.binding.top;
- biding.toView = 0;
- biding.kind = OS.kHILayoutBindMin;
- biding.offset = 0;
- biding = layout.binding.left;
- biding.toView = 0;
- biding.kind = OS.kHILayoutBindMin;
- biding.offset = 0;
- biding = layout.binding.bottom;
- biding.toView = 0;
- biding.kind = OS.kHILayoutBindMax;
- biding.offset = 0;
- biding = layout.binding.right;
- biding.toView = 0;
- biding.kind = OS.kHILayoutBindMax;
- biding.offset = 0;
- CGRect r = new CGRect();
- r.width = r.height = 100;
- OS.HIViewSetFrame (frameHandle, r);
- Rect inset = inset ();
- r.x += inset.left;
- r.y += inset.top;
- r.width -= inset.left + inset.right;
- r.height -= inset.top + inset.bottom;
- OS.HIViewSetFrame (child, r);
- OS.HIViewSetLayoutInfo (child, layout);
- }
- super.setZOrder ();
-}
-
-/**
- * Sets the maximum number of characters that the receiver
- * is capable of holding to be the argument.
- * <p>
- * Instead of trying to set the text limit to zero, consider
- * creating a read-only text widget.
- * </p><p>
- * To reset this value to the default, use <code>setTextLimit(Text.LIMIT)</code>.
- * Specifying a limit value larger than <code>Text.LIMIT</code> sets the
- * receiver's limit to <code>Text.LIMIT</code>.
- * </p>
- *
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public void setTextLimit (int limit) {
- checkWidget();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- textLimit = limit;
-}
-
-/**
- * Sets the zero-relative index of the line which is currently
- * at the top of the receiver. This index can change when lines
- * are scrolled or new lines are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return;
- int[] event = new int[1];
- OS.CreateEvent (0, OS.kEventClassScrollable, OS.kEventScrollableScrollTo, 0.0, 0, event);
- if (event [0] != 0) {
- int lineHeight = getLineHeight ();
- CGPoint pt = new CGPoint ();
- pt.y = lineHeight * Math.min(getLineCount (), index);
- OS.SetEventParameter (event[0], OS.kEventParamOrigin, OS.typeHIPoint, CGPoint.sizeof, pt);
- OS.SendEventToEventTarget (event[0], OS.GetControlEventTarget (handle));
- OS.ReleaseEvent (event[0]);
- }
-}
-/**
- * Shows the selection.
- * <p>
- * If the selection is already showing
- * in the receiver, this method simply returns. Otherwise,
- * lines are scrolled until the selection is visible.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void showSelection () {
- checkWidget();
- if (txnObject == 0) {
- setSelection (getSelection());
- } else {
- OS.TXNShowSelection (txnObject, false);
- }
-}
-
-int topHandle () {
- if (frameHandle != 0) return frameHandle;
- return super.topHandle ();
-}
-
-int traversalCode (int key, int theEvent) {
- int bits = super.traversalCode (key, theEvent);
- if ((style & SWT.READ_ONLY) != 0) return bits;
- if ((style & SWT.MULTI) != 0) {
- bits &= ~SWT.TRAVERSE_RETURN;
- if (key == 48 /* Tab */ && theEvent != 0) {
- int [] modifiers = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
- boolean next = (modifiers [0] & OS.shiftKey) == 0;
- if (next && (modifiers [0] & OS.controlKey) == 0) {
- bits &= ~(SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS);
- }
- }
- }
- return bits;
-}
-
-String verifyText (String string, int start, int end, Event keyEvent) {
- Event event = new Event ();
- event.text = string;
- event.start = start;
- event.end = end;
- if (keyEvent != null) {
- event.character = keyEvent.character;
- event.keyCode = keyEvent.keyCode;
- event.stateMask = keyEvent.stateMask;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the verify
- * event. If this happens, answer null to cancel
- * the operation.
- */
- sendEvent (SWT.Verify, event);
- if (!event.doit || isDisposed ()) return null;
- return event.text;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolBar.java
deleted file mode 100644
index acf56b0800..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolBar.java
+++ /dev/null
@@ -1,515 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.CFRange;
-import org.eclipse.swt.internal.carbon.OS;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class support the layout of selectable
- * tool bar items.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>ToolItem</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add <code>Control</code> children to it,
- * or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>FLAT, WRAP, RIGHT, HORIZONTAL, VERTICAL, SHADOW_OUT</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#toolbar">ToolBar, ToolItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolBar extends Composite {
- int itemCount;
- ToolItem [] items;
-
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#FLAT
- * @see SWT#WRAP
- * @see SWT#RIGHT
- * @see SWT#HORIZONTAL
- * @see SWT#SHADOW_OUT
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass()
- * @see Widget#getStyle()
- */
-public ToolBar (Composite parent, int style) {
- super (parent, checkStyle (style));
-
- /*
- * Ensure that either of HORIZONTAL or VERTICAL is set.
- * NOTE: HORIZONTAL and VERTICAL have the same values
- * as H_SCROLL and V_SCROLL so it is necessary to first
- * clear these bits to avoid scroll bars and then reset
- * the bits using the original style supplied by the
- * programmer.
- */
- if ((style & SWT.VERTICAL) != 0) {
- this.style |= SWT.VERTICAL;
- } else {
- this.style |= SWT.HORIZONTAL;
- }
-}
-
-static int checkStyle (int style) {
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = wHint, height = hHint;
- if (wHint == SWT.DEFAULT) width = 0x7FFFFFFF;
- if (hHint == SWT.DEFAULT) height = 0x7FFFFFFF;
- int [] result = layout (width, height, false);
- Point extent = new Point (result [1], result [2]);
- if (wHint != SWT.DEFAULT) extent.x = wHint;
- if (hHint != SWT.DEFAULT) extent.y = hHint;
- return extent;
-}
-
-void createHandle () {
- state |= GRAB | THEME_BACKGROUND;
- super.createHandle (parent.handle);
- OS.HIObjectSetAccessibilityIgnored (handle, false);
-}
-
-void createItem (ToolItem item, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (itemCount == items.length) {
- ToolItem [] newItems = new ToolItem [itemCount + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- item.createWidget ();
- System.arraycopy (items, index, items, index + 1, itemCount++ - index);
- items [index] = item;
- relayout ();
-}
-
-void createWidget () {
- super.createWidget ();
- items = new ToolItem [4];
- itemCount = 0;
-}
-
-int defaultThemeFont () {
- if (display.smallFonts) return OS.kThemeToolbarFont;
- return OS.kThemeSystemFont;
-}
-
-void destroyItem (ToolItem item) {
- int index = 0;
- while (index < itemCount) {
- if (items [index] == item) break;
- index++;
- }
- if (index == itemCount) return;
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- relayout ();
-}
-
-void drawBackground (int control, int context) {
- fillBackground (control, context, null);
-}
-
-void enableWidget (boolean enabled) {
- /* Do nothing - A tool bar does not disable items when it is disabled */
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem getItem (int index) {
- checkWidget();
- if (0 <= index && index < itemCount) return items [index];
- error (SWT.ERROR_INVALID_RANGE);
- return null;
-}
-
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- *
- * @param point the point used to locate the item
- * @return the item at the given point
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem getItem (Point pt) {
- checkWidget();
- if (pt == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<itemCount; i++) {
- Rectangle rect = items [i].getBounds ();
- if (rect.contains (pt)) return items [i];
- }
- return null;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- return itemCount;
-}
-
-/**
- * Returns an array of <code>ToolItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem [] getItems () {
- checkWidget();
- ToolItem [] result = new ToolItem [itemCount];
- System.arraycopy (items, 0, result, 0, itemCount);
- return result;
-}
-
-/**
- * Returns the number of rows in the receiver. When
- * the receiver has the <code>WRAP</code> style, the
- * number of rows can be greater than one. Otherwise,
- * the number of rows is always one.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getRowCount () {
- checkWidget();
- Rectangle rect = getClientArea ();
- return layout (rect.width, rect.height, false) [0];
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the tool item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the tool item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (ToolItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<itemCount; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-
-void invalidateChildrenVisibleRegion (int control) {
- super.invalidateChildrenVisibleRegion (control);
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- item.resetVisibleRegion (control);
- }
-}
-
-int kEventAccessibleGetNamedAttribute (int nextHandler, int theEvent, int userData) {
- int code = OS.eventNotHandledErr;
- int [] stringRef = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamAccessibleAttributeName, OS.typeCFStringRef, null, 4, null, stringRef);
- int length = 0;
- if (stringRef [0] != 0) length = OS.CFStringGetLength (stringRef [0]);
- char [] buffer = new char [length];
- CFRange range = new CFRange ();
- range.length = length;
- OS.CFStringGetCharacters (stringRef [0], range, buffer);
- String attributeName = new String(buffer);
- if (attributeName.equals (OS.kAXRoleAttribute) || attributeName.equals (OS.kAXRoleDescriptionAttribute)) {
- String roleText = OS.kAXToolbarRole;
- buffer = new char [roleText.length ()];
- roleText.getChars (0, buffer.length, buffer, 0);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- if (attributeName.equals (OS.kAXRoleAttribute)) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- } else { // kAXRoleDescriptionAttribute
- int stringRef2 = OS.HICopyAccessibilityRoleDescription (stringRef [0], 0);
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, new int [] {stringRef2});
- OS.CFRelease(stringRef2);
- }
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- }
- if (accessible != null) {
- code = accessible.internal_kEventAccessibleGetNamedAttribute (nextHandler, theEvent, code);
- }
- return code;
-}
-
-int [] layoutHorizontal (int width, int height, boolean resize) {
- int xSpacing = 0, ySpacing = 2;
- int marginWidth = 0, marginHeight = 0;
- int x = marginWidth, y = marginHeight;
- int maxX = 0, rows = 1;
- boolean wrap = (style & SWT.WRAP) != 0;
- int itemHeight = 0;
- Point [] sizes = new Point [itemCount];
- for (int i=0; i<itemCount; i++) {
- Point size = sizes [i] = items [i].computeSize ();
- itemHeight = Math.max (itemHeight, size.y);
- }
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- Point size = sizes [i];
- if (wrap && i != 0 && x + size.x > width) {
- rows++;
- x = marginWidth;
- y += ySpacing + itemHeight;
- }
- if (resize) {
- item.setBounds (x, y, size.x, itemHeight);
- boolean visible = x + size.x <= width && y + itemHeight <= height;
- item.setVisible (visible);
- Control control = item.control;
- if (control != null) {
- int controlY = y + (itemHeight - size.y) / 2;
- control.setBounds (x, controlY, size.x, itemHeight - (controlY - y));
- }
- }
- x += xSpacing + size.x;
- maxX = Math.max (maxX, x);
- }
-
- //TODO - tempporary code
- if (resize) invalidateVisibleRegion (handle);
-
- return new int [] {rows, maxX, y + itemHeight};
-}
-
-int [] layoutVertical (int width, int height, boolean resize) {
- int xSpacing = 2, ySpacing = 0;
- int marginWidth = 0, marginHeight = 0;
- int x = marginWidth, y = marginHeight;
- int maxY = 0, cols = 1;
- boolean wrap = (style & SWT.WRAP) != 0;
- int itemWidth = 0;
- Point [] sizes = new Point [itemCount];
- for (int i=0; i<itemCount; i++) {
- Point size = sizes [i] = items [i].computeSize ();
- itemWidth = Math.max (itemWidth, size.x);
- }
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- Point size = sizes [i];
- if (wrap && i != 0 && y + size.y > height) {
- cols++;
- x += xSpacing + itemWidth;
- y = marginHeight;
- }
- if (resize) {
- item.setBounds (x, y, itemWidth, size.y);
- boolean visible = x + itemWidth <= width && y + size.y <= height;
- item.setVisible (visible);
- Control control = item.control;
- if (control != null) {
- int controlX = x + (itemWidth - size.x) / 2;
- control.setBounds (controlX, y, itemWidth - (controlX - x), size.y);
- }
- }
- y += ySpacing + size.y;
- maxY = Math.max (maxY, y);
- }
-
- //TODO - tempporary code
- if (resize) invalidateVisibleRegion (handle);
-
- return new int [] {cols, x + itemWidth, maxY};
-}
-
-int [] layout (int nWidth, int nHeight, boolean resize) {
- if ((style & SWT.VERTICAL) != 0) {
- return layoutVertical (nWidth, nHeight, resize);
- } else {
- return layoutHorizontal (nWidth, nHeight, resize);
- }
-}
-
-void relayout () {
- if (!getDrawing ()) return;
- Rectangle rect = getClientArea ();
- layout (rect.width, rect.height, true);
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- itemCount = 0;
- items = null;
- }
- super.releaseChildren (destroy);
-}
-
-void removeControl (Control control) {
- super.removeControl (control);
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- if (item.control == control) item.setControl (null);
- }
-}
-
-void setBackground (float [] color) {
- super.setBackground (color);
- if (items == null) return;
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- item.setBackground (color);
- }
- redrawWidget (handle, true);
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- int result = super.setBounds (x, y, width, height, move, resize, events);
- if ((result & RESIZED) != 0) relayout ();
- return result;
-}
-
-void setFontStyle (Font font) {
- super.setFontStyle (font);
- if (items == null) return;
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- item.setFontStyle (font);
- }
- redrawWidget (handle, true);
- relayout ();
-}
-
-void setForeground (float [] color) {
- super.setForeground (color);
- if (items == null) return;
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- item.setForeground (color);
- }
- redrawWidget (handle, true);
-}
-
-public void setRedraw (boolean redraw) {
- checkWidget();
- super.setRedraw (redraw);
- if (redraw && drawCount == 0) relayout();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolItem.java
deleted file mode 100644
index 8388ac95bc..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolItem.java
+++ /dev/null
@@ -1,1378 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.CFRange;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.ControlButtonContentInfo;
-import org.eclipse.swt.internal.carbon.ControlFontStyleRec;
-import org.eclipse.swt.internal.carbon.HMHelpContentRec;
-import org.eclipse.swt.internal.carbon.CGRect;
-import org.eclipse.swt.internal.carbon.CGPoint;
-import org.eclipse.swt.internal.carbon.HIThemeSeparatorDrawInfo;
-import org.eclipse.swt.internal.carbon.HIThemePopupArrowDrawInfo;
-import org.eclipse.swt.internal.carbon.HIThemeTextInfo;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a button in a tool bar.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>PUSH, CHECK, RADIO, SEPARATOR, DROP_DOWN</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles CHECK, PUSH, RADIO, SEPARATOR and DROP_DOWN
- * may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#toolbar">ToolBar, ToolItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolItem extends Item {
- int handle, iconHandle, labelHandle;
- int cIcon;
- int visibleRgn, partCode;
- int width = DEFAULT_SEPARATOR_WIDTH;
- ToolBar parent;
- Image hotImage, disabledImage;
- String toolTipText;
- Control control;
- boolean selection;
-
- static final int DEFAULT_WIDTH = 24;
- static final int DEFAULT_HEIGHT = 22;
- static final int DEFAULT_SEPARATOR_WIDTH = 6;
- static final int ARROW_WIDTH = 9;
- static final int INSET = 3;
- static final String [] AX_ATTRIBUTES = {
- OS.kAXDescriptionAttribute,
- OS.kAXTitleAttribute,
- OS.kAXValueAttribute,
- };
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>ToolBar</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#PUSH
- * @see SWT#CHECK
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ToolItem (ToolBar parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>ToolBar</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#PUSH
- * @see SWT#CHECK
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ToolItem (ToolBar parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-int actionProc (int theControl, int partCode) {
- int result = parent.actionProc (theControl, partCode);
- if (result == OS.noErr) return result;
- if (isDisposed ()) return OS.noErr;
- this.partCode = partCode;
- if (text.length () > 0 && theControl == labelHandle) {
- if (image != null && iconHandle != 0) {
- int transform = partCode != 0 ? OS.kTransformSelected : 0;
- OS.SetControlData (iconHandle, OS.kControlEntireControl, OS.kControlIconTransformTag, 2, new short [] {(short)transform});
- redrawWidget (iconHandle, false);
- }
- redrawWidget (labelHandle, false);
- }
- if (image != null && theControl == iconHandle) {
- redrawWidget (labelHandle, false);
- }
- if (theControl == handle) {
- if (image != null && iconHandle != 0) {
- int transform = partCode != 0 ? OS.kTransformSelected : 0;
- OS.SetControlData (iconHandle, OS.kControlEntireControl, OS.kControlIconTransformTag, 2, new short [] {(short)transform});
- redrawWidget (iconHandle, false);
- }
- if (labelHandle != 0) redrawWidget (labelHandle, false);
- }
- return result;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called when the mouse is over the arrow portion of a drop-down tool,
- * the event object detail field contains the value <code>SWT.ARROW</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user,
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-int callPaintEventHandler (int control, int damageRgn, int visibleRgn, int theEvent, int nextHandler) {
- if (control == labelHandle && (partCode != 0 || ((state & DISABLED) != 0 && OS.VERSION >= 0x1040))) {
- HIThemeTextInfo info = new HIThemeTextInfo ();
- if (partCode != 0) {
- info.state = OS.kThemeStatePressed;
- } else {
- if (OS.IsControlActive (labelHandle)) {
- info.state = (state & DISABLED) == 0 ? OS.kThemeStateActive : OS.kThemeStateUnavailable;
- } else {
- info.state = (state & DISABLED) == 0 ? OS.kThemeStateInactive : OS.kThemeStateUnavailableInactive;
- }
- }
- Font font = parent.font;
- if (font != null) {
- short [] family = new short [1], style = new short [1];
- OS.FMGetFontFamilyInstanceFromFont (font.handle, family, style);
- OS.TextFont (family [0]);
- OS.TextFace ((short) (style [0] | font.style));
- OS.TextSize ((short) font.size);
- info.fontID = (short) OS.kThemeCurrentPortFont;
- } else {
- info.fontID = (short) parent.defaultThemeFont ();
- }
- CGRect rect = new CGRect ();
- OS.HIViewGetBounds (labelHandle, rect);
- int [] context = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamCGContextRef, OS.typeCGContextRef, null, 4, null, context);
- if ((state & DISABLED) != 0 && OS.VERSION >= 0x1040) {
- OS.HIThemeSetTextFill (OS.kThemeTextColorMenuItemDisabled, 0, context [0], OS.kHIThemeOrientationNormal);
- } else {
- int colorspace = OS.CGColorSpaceCreateDeviceRGB ();
- OS.CGContextSetFillColorSpace (context [0], colorspace);
- OS.CGColorSpaceRelease (colorspace);
- OS.CGContextSetFillColor (context [0], parent.getForegroundColor ().handle);
- }
- int [] ptr = new int [1];
- OS.GetControlData (labelHandle, (short) 0, OS.kControlStaticTextCFStringTag, 4, ptr, null);
- OS.HIThemeDrawTextBox (ptr [0], rect, info, context [0], OS.kHIThemeOrientationNormal);
- OS.CFRelease (ptr [0]);
- return OS.noErr;
- }
- if (control == iconHandle && OS.VERSION >= 0x1040) {
- Image image = null;
- if (hotImage != null) {
- image = hotImage;
- } else {
- if (this.image != null) {
- image = this.image;
- } else {
- image = disabledImage;
- }
- }
- if (image != null) {
- int imageHandle = image.handle;
- int alphaInfo = OS.CGImageGetAlphaInfo (imageHandle);
- if (alphaInfo == OS.kCGImageAlphaFirst) {
- int [] buffer = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamCGContextRef, OS.typeCGContextRef, null, 4, null, buffer);
- int context = buffer [0];
- CGRect rect = new CGRect ();
- OS.HIViewGetBounds (iconHandle, rect);
- if (partCode != 0) {
- OS.HICreateTransformedCGImage (imageHandle, OS.kHITransformSelected, buffer);
- imageHandle = buffer [0];
- } else if ((state & DISABLED) != 0) {
- OS.HICreateTransformedCGImage (imageHandle, OS.kHITransformDisabled, buffer);
- imageHandle = buffer [0];
- }
- OS.HIViewDrawCGImage (context, rect, imageHandle);
- if (imageHandle != image.handle) OS.CGImageRelease (imageHandle);
- return OS.noErr;
- }
- }
- }
- return super.callPaintEventHandler (control, damageRgn, visibleRgn, theEvent, nextHandler);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.DROP_DOWN, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-int colorProc (int inControl, int inMessage, int inDrawDepth, int inDrawInColor) {
- switch (inMessage) {
- case OS.kControlMsgApplyTextColor: {
- if (parent.foreground != null) {
- OS.RGBForeColor (toRGBColor (parent.foreground));
- } else {
- OS.SetThemeTextColor ((short) OS.kThemeTextColorDialogActive, (short) inDrawDepth, inDrawInColor != 0);
- }
- return OS.noErr;
- }
- case OS.kControlMsgSetUpBackground: {
- float [] background = parent.background != null ? parent.background : parent.getParentBackground ();
- if (background != null) {
- OS.RGBBackColor (toRGBColor (background));
- } else {
- OS.SetThemeBackground ((short) OS.kThemeBrushDialogBackgroundActive, (short) inDrawDepth, inDrawInColor != 0);
- }
- return OS.noErr;
- }
- }
- return OS.eventNotHandledErr;
-}
-
-Point computeSize () {
-// checkWidget();
- int width = 0, height = 0;
- if ((style & SWT.SEPARATOR) != 0) {
- if ((parent.style & SWT.HORIZONTAL) != 0) {
- width = getWidth ();
- height = DEFAULT_HEIGHT;
- } else {
- width = DEFAULT_WIDTH;
- height = getWidth ();
- }
- if (control != null) {
- height = Math.max (height, control.getMininumHeight ());
- }
- } else {
- int space = 0;
- if (text.length () != 0 || image != null) {
- int stringWidth = 0, stringHeight = 0;
- if (text.length () != 0) {
- Point size = textExtent ();
- stringWidth = size.x;
- stringHeight = size.y;
- }
- int imageWidth = 0, imageHeight = 0;
- if (image != null) {
- if (text.length () != 0) space = 2;
- Rectangle rect = image.getBounds ();
- imageWidth = rect.width;
- imageHeight = rect.height;
- }
- if ((parent.style & SWT.RIGHT) != 0) {
- width = stringWidth + imageWidth + space;
- height = Math.max (stringHeight, imageHeight);
- } else {
- width = Math.max (stringWidth, imageWidth);
- height = stringHeight + imageHeight + space;
- }
- } else {
- width = DEFAULT_WIDTH;
- height = DEFAULT_HEIGHT;
- }
- if ((style & SWT.DROP_DOWN) != 0) {
- width += ARROW_WIDTH;
- }
- width += INSET * 2;
- height += INSET * 2;
- }
- return new Point (width, height);
-}
-
-boolean contains (String [] array, String element) {
- for (int i = 0; i < array.length; i++) {
- if (array [i].equals (element)) {
- return true;
- }
- }
- return false;
-}
-
-void createHandle () {
- int [] outControl = new int [1];
- int window = OS.GetControlOwner (parent.handle);
- int features = OS.kControlSupportsEmbedding | OS.kControlWantsActivate;
- OS.CreateUserPaneControl (window, null, features, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
- OS.HIObjectSetAccessibilityIgnored (handle, true);
- if ((style & SWT.SEPARATOR) == 0) {
- ControlButtonContentInfo inContent = new ControlButtonContentInfo ();
- OS.CreateIconControl(window, null, inContent, false, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- iconHandle = outControl [0];
- OS.HIObjectSetAccessibilityIgnored (iconHandle, true);
- ControlFontStyleRec fontStyle = new ControlFontStyleRec ();
- Font font = parent.font;
- if (font != null) {
- short [] family = new short [1], style = new short [1];
- OS.FMGetFontFamilyInstanceFromFont (font.handle, family, style);
- fontStyle.flags |= OS.kControlUseFontMask | OS.kControlUseSizeMask | OS.kControlUseFaceMask;
- fontStyle.font = family [0];
- fontStyle.style = (short) (style [0] | font.style);
- fontStyle.size = (short) font.size;
- } else {
- fontStyle.flags = (short) OS.kControlUseThemeFontIDMask;
- fontStyle.font = (short) parent.defaultThemeFont ();
- }
- OS.CreateStaticTextControl (window, null, 0, fontStyle, outControl);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- labelHandle = outControl [0];
- OS.HIObjectSetAccessibilityIgnored (labelHandle, true);
- }
-}
-
-void createWidget () {
- super.createWidget ();
- setZOrder ();
- toolTipText = "";
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (handle);
- if (iconHandle != 0) display.removeWidget (iconHandle);
- if (labelHandle != 0) display.removeWidget (labelHandle);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- int theControl = handle;
- releaseHandle ();
- if (theControl != 0) {
- OS.DisposeControl (theControl);
- }
-}
-
-void drawBackground (int control, int context) {
- if (control == handle && getSelection ()) {
- CGRect rect = new CGRect();
- OS.HIViewGetBounds (handle, rect);
- OS.CGContextSaveGState (context);
- OS.CGContextSetFillColor (context, new float[]{0.1f, 0.1f, 0.1f, 0.1f});
- OS.CGContextFillRect (context, rect);
- OS.CGContextSetStrokeColor (context, new float[]{0.2f, 0.2f, 0.2f, 0.2f});
- rect.x += 0.5f;
- rect.y += 0.5f;
- rect.width -= 1;
- rect.height -= 1;
- OS.CGContextStrokeRect (context, rect);
- OS.CGContextRestoreGState (context);
- }
-}
-
-void drawWidget (int control, int context, int damageRgn, int visibleRgn, int theEvent) {
- if (control == handle && (style & (SWT.DROP_DOWN | SWT.SEPARATOR)) != 0) {
- int state;
- if (OS.IsControlEnabled (control)) {
- state = OS.IsControlActive (control) ? OS.kThemeStateActive : OS.kThemeStateInactive;
- } else {
- state = OS.IsControlActive (control) ? OS.kThemeStateUnavailable : OS.kThemeStateUnavailableInactive;
- }
- CGRect rect = new CGRect ();
- OS.HIViewGetBounds (handle, rect);
- if ((style & SWT.SEPARATOR) != 0 && this.control == null) {
- rect.y += 2;
- rect.height -= 4;
- HIThemeSeparatorDrawInfo info = new HIThemeSeparatorDrawInfo ();
- info.state = state;
- OS.HIThemeDrawSeparator (rect, info, context, OS.kHIThemeOrientationNormal);
- }
- if ((style & SWT.DROP_DOWN) != 0) {
- rect.y = rect.height / 2 - 1;
- rect.x = rect.width - ARROW_WIDTH;
- HIThemePopupArrowDrawInfo info = new HIThemePopupArrowDrawInfo ();
- info.state = state;
- info.orientation = (short) OS.kThemeArrowDown;
- info.size = (short) OS.kThemeArrow5pt;
- OS.HIThemeDrawPopupArrow (rect, info, context, OS.kHIThemeOrientationNormal);
- }
- }
-}
-
-String [] getAxAttributes () {
- return AX_ATTRIBUTES;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- return getControlBounds (handle);
-}
-
-/**
- * Returns the control that is used to fill the bounds of
- * the item when the item is a <code>SEPARATOR</code>.
- *
- * @return the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget();
- return control;
-}
-
-/**
- * Returns the receiver's disabled image if it has one, or null
- * if it does not.
- * <p>
- * The disabled image is displayed when the receiver is disabled.
- * </p>
- *
- * @return the receiver's disabled image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getDisabledImage () {
- checkWidget();
- return disabledImage;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- return (state & DISABLED) == 0;
-}
-
-boolean getDrawing () {
- return parent.getDrawing ();
-}
-
-/**
- * Returns the receiver's hot image if it has one, or null
- * if it does not.
- * <p>
- * The hot image is displayed when the mouse enters the receiver.
- * </p>
- *
- * @return the receiver's hot image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getHotImage () {
- checkWidget();
- return hotImage;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>ToolBar</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolBar getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked (which some platforms draw as a
- * pushed in button). If the receiver is of any other type, this method
- * returns false.
- * </p>
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
- return selection;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget();
- return width;
-}
-
-int getVisibleRegion (int control, boolean clipChildren) {
- if (visibleRgn == 0) {
- visibleRgn = OS.NewRgn ();
- calculateVisibleRegion (control, visibleRgn, false);
- }
- int result = OS.NewRgn ();
- OS.CopyRgn (visibleRgn, result);
- return result;
-}
-
-int helpProc (int inControl, int inGlobalMouse, int inRequest, int outContentProvided, int ioHelpContent) {
- if (parent.toolTipText == null) {
- switch (inRequest) {
- case OS.kHMSupplyContent: {
- short [] contentProvided = { OS.kHMContentNotProvided };
- if (toolTipText != null && toolTipText.length () != 0) {
- char [] buffer = new char [toolTipText.length ()];
- toolTipText.getChars (0, buffer.length, buffer, 0);
- int length = fixMnemonic (buffer);
- if (display.helpString != 0) OS.CFRelease (display.helpString);
- display.helpString = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, length);
- HMHelpContentRec helpContent = new HMHelpContentRec ();
- OS.memmove (helpContent, ioHelpContent, HMHelpContentRec.sizeof);
- helpContent.version = OS.kMacHelpVersion;
- helpContent.tagSide = (short) OS.kHMDefaultSide;
- display.helpWidget = null;
- helpContent.absHotRect_left = (short) 0;
- helpContent.absHotRect_top = (short) 0;
- helpContent.absHotRect_right = (short) 0;
- helpContent.absHotRect_bottom = (short) 0;
- helpContent.content0_contentType = OS.kHMCFStringContent;
- helpContent.content0_tagCFString = display.helpString;
- helpContent.content1_contentType = OS.kHMCFStringContent;
- helpContent.content1_tagCFString = display.helpString;
- OS.memmove (ioHelpContent, helpContent, HMHelpContentRec.sizeof);
- contentProvided [0] = OS.kHMContentProvided;
- }
- OS.memmove (outContentProvided, contentProvided, 2);
- break;
- }
- case OS.kHMDisposeContent: {
- if (display.helpString != 0) OS.CFRelease (display.helpString);
- display.helpWidget = null;
- display.helpString = 0;
- break;
- }
- }
- return OS.noErr;
- }
- return parent.helpProc (inControl, inGlobalMouse, inRequest, outContentProvided, ioHelpContent);
-}
-
-void hookEvents () {
- super.hookEvents ();
- int controlProc = display.controlProc;
- int colorProc = display.colorProc;
- int [] mask1 = new int [] {
- OS.kEventClassControl, OS.kEventControlDraw,
- OS.kEventClassControl, OS.kEventControlHit,
- OS.kEventClassControl, OS.kEventControlHitTest,
- OS.kEventClassControl, OS.kEventControlTrack,
- };
- int controlTarget = OS.GetControlEventTarget (handle);
- OS.InstallEventHandler (controlTarget, controlProc, mask1.length / 2, mask1, handle, null);
- int [] mask2 = new int [] {
- OS.kEventClassControl, OS.kEventControlDraw,
- OS.kEventClassControl, OS.kEventControlHitTest,
- OS.kEventClassControl, OS.kEventControlTrack,
- OS.kEventClassControl, OS.kEventControlGetClickActivation,
- };
- int accessibilityProc = display.accessibilityProc;
- int [] mask3 = new int [] {
- OS.kEventClassAccessibility, OS.kEventAccessibleGetAllAttributeNames,
- OS.kEventClassAccessibility, OS.kEventAccessibleGetNamedAttribute,
- };
- if (iconHandle != 0) {
- controlTarget = OS.GetControlEventTarget (iconHandle);
- OS.InstallEventHandler (controlTarget, controlProc, mask2.length / 2, mask2, iconHandle, null);
- OS.SetControlColorProc (iconHandle, colorProc);
- OS.SetControlAction (iconHandle, display.actionProc);
- OS.InstallEventHandler (controlTarget, accessibilityProc, mask3.length / 2, mask3, iconHandle, null);
- }
- if (labelHandle != 0) {
- controlTarget = OS.GetControlEventTarget (labelHandle);
- OS.InstallEventHandler (controlTarget, controlProc, mask2.length / 2, mask2, labelHandle, null);
- OS.SetControlColorProc (labelHandle, colorProc);
- OS.SetControlAction (labelHandle, display.actionProc);
- }
- if ((style & SWT.SEPARATOR) == 0) {
- OS.SetControlAction (handle, display.actionProc);
- }
- int helpProc = display.helpProc;
- OS.HMInstallControlContentCallback (handle, helpProc);
- OS.SetControlColorProc (handle, colorProc);
-}
-
-void invalidateVisibleRegion (int control) {
- resetVisibleRegion (control);
- parent.resetVisibleRegion (control);
-}
-
-void invalWindowRgn (int window, int rgn) {
- parent.invalWindowRgn (window, rgn);
-}
-
-boolean isDrawing () {
- return getDrawing() && parent.isDrawing();
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-
-int kEventAccessibleGetAllAttributeNames (int nextHandler, int theEvent, int userData) {
- int code = OS.eventNotHandledErr;
- String [] attributes = getAxAttributes ();
- if (attributes != null) {
- OS.CallNextEventHandler (nextHandler, theEvent);
- int [] arrayRef = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamAccessibleAttributeNames, OS.typeCFMutableArrayRef, null, 4, null, arrayRef);
- int attributesArrayRef = arrayRef [0];
- int length = OS.CFArrayGetCount (attributesArrayRef);
- String[] osAttributes = new String [length];
- for (int i = 0; i < length; i++) {
- int stringRef = OS.CFArrayGetValueAtIndex (attributesArrayRef, i);
- int strLength = OS.CFStringGetLength (stringRef);
- char [] buffer = new char [strLength];
- CFRange range = new CFRange ();
- range.length = strLength;
- OS.CFStringGetCharacters (stringRef, range, buffer);
- osAttributes [i] = new String (buffer);
- }
- for (int i = 0; i < attributes.length; i++) {
- if (!contains (osAttributes, attributes [i])) {
- String string = attributes [i];
- char [] buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- int stringRef = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- OS.CFArrayAppendValue (attributesArrayRef, stringRef);
- OS.CFRelease (stringRef);
- }
- }
- code = OS.noErr;
- }
- if (parent.accessible != null) {
- code = parent.accessible.internal_kEventAccessibleGetAllAttributeNames (nextHandler, theEvent, code);
- }
- return code;
-}
-
-int kEventAccessibleGetNamedAttribute (int nextHandler, int theEvent, int userData) {
- int code = OS.eventNotHandledErr;
- int [] stringRef = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamAccessibleAttributeName, OS.typeCFStringRef, null, 4, null, stringRef);
- int length = 0;
- if (stringRef [0] != 0) length = OS.CFStringGetLength (stringRef [0]);
- char [] buffer = new char [length];
- CFRange range = new CFRange ();
- range.length = length;
- OS.CFStringGetCharacters (stringRef [0], range, buffer);
- String attributeName = new String(buffer);
- if (attributeName.equals (OS.kAXRoleAttribute) || attributeName.equals (OS.kAXRoleDescriptionAttribute)) {
- String roleText = ((style & SWT.PUSH) != 0) ? OS.kAXButtonRole
- : ((style & SWT.RADIO) != 0) ? OS.kAXRadioButtonRole
- : ((style & SWT.CHECK) != 0) ? OS.kAXCheckBoxRole
- : ((style & SWT.DROP_DOWN) != 0) ? OS.kAXMenuButtonRole
- : null; // SEPARATOR
- if (roleText != null) {
- buffer = new char [roleText.length ()];
- roleText.getChars (0, buffer.length, buffer, 0);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- if (attributeName.equals (OS.kAXRoleAttribute)) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- } else { // kAXRoleDescriptionAttribute
- int stringRef2 = OS.HICopyAccessibilityRoleDescription (stringRef [0], 0);
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, new int [] {stringRef2});
- OS.CFRelease(stringRef2);
- }
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- }
- } else if (attributeName.equals (OS.kAXTitleAttribute) || attributeName.equals (OS.kAXDescriptionAttribute)) {
- String accessibleText = toolTipText;
- if (accessibleText == null || accessibleText.equals("")) accessibleText = text;
- if (!(accessibleText == null || accessibleText.equals(""))) {
- buffer = new char [accessibleText.length ()];
- accessibleText.getChars (0, buffer.length, buffer, 0);
- int ref = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, new int [] {ref});
- OS.CFRelease(ref);
- code = OS.noErr;
- }
- } else if (attributeName.equals (OS.kAXValueAttribute) && (style & (SWT.CHECK | SWT.RADIO)) != 0) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeSInt32, 4, new int [] {selection ? 1 : 0});
- code = OS.noErr;
- }
- if (parent.accessible != null) {
- code = parent.accessible.internal_kEventAccessibleGetNamedAttribute (nextHandler, theEvent, code);
- }
- return code;
-}
-
-int kEventControlGetClickActivation (int nextHandler, int theEvent, int userData) {
- return parent.kEventControlGetClickActivation (nextHandler, theEvent, userData);
-}
-
-int kEventControlHit (int nextHandler, int theEvent, int userData) {
- int result = super.kEventControlHit (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) {
- selectRadio ();
- }
- }
- if ((style & SWT.CHECK) != 0) setSelection (!getSelection ());
- postEvent (SWT.Selection);
- return OS.eventNotHandledErr;
-}
-
-int kEventControlHitTest (int nextHandler, int theEvent, int userData) {
- /*
- * Feature in the Macintosh. When kWindowCompositingAttribute is
- * set in the window, controls within the window are selected when
- * any button is pressed, not just the left one. When the control
- * has a menu, this causes both selection and a menu to be displayed.
- * The fix is to check for button two and avoid setting the part
- * code, which stops the selection from happening.
- */
- if (display.clickCountButton == 2) return OS.noErr;
- int [] theControl = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamDirectObject, OS.typeControlRef, null, 4, null, theControl);
- if (theControl [0] == labelHandle || (theControl [0] == handle && (style & SWT.SEPARATOR) == 0)) {
- CGRect rect = new CGRect ();
- OS.HIViewGetBounds (theControl [0], rect);
- CGPoint pt = new CGPoint ();
- OS.GetEventParameter (theEvent, OS.kEventParamMouseLocation, OS.typeHIPoint, null, CGPoint.sizeof, null, pt);
- if (OS.CGRectContainsPoint (rect, pt) != 0 && (theControl [0] != handle || (style & SWT.DROP_DOWN) == 0 || rect.width - pt.x >= ARROW_WIDTH + INSET)) {
- OS.SetEventParameter (theEvent, OS.kEventParamControlPart, OS.typeControlPartCode, 2, new short[]{(short)1});
- return OS.noErr;
- }
- }
- return OS.eventNotHandledErr;
-}
-
-int kEventControlTrack (int nextHandler, int theEvent, int userData) {
- int result = parent.kEventControlTrack (nextHandler, theEvent, userData);
- if (isDisposed ()) return OS.noErr;
- partCode = 0;
- if (text.length () > 0 && labelHandle != 0) {
- redrawWidget (labelHandle, false);
- }
- if (image != null && iconHandle != 0) {
- OS.SetControlData (iconHandle, OS.kControlEntireControl, OS.kControlIconTransformTag, 2, new short [] {(short) 0});
- redrawWidget (iconHandle, false);
- }
- return result;
-}
-
-int kEventMouseDown (int nextHandler, int theEvent, int userData) {
- int result = parent.kEventMouseDown (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
-
- if ((style & SWT.DROP_DOWN) != 0) {
- CGPoint pt = new CGPoint ();
- OS.GetEventParameter (theEvent, OS.kEventParamWindowMouseLocation, OS.typeHIPoint, null, CGPoint.sizeof, null, pt);
- OS.HIViewConvertPoint (pt, 0, handle);
- CGRect rect = new CGRect ();
- OS.HIViewGetFrame (handle, rect);
- int x = (int) pt.x;
- int width = (int) rect.width;
- if (width - x < ARROW_WIDTH + INSET) {
- OS.HIViewConvertPoint (pt, handle, parent.handle);
- Event event = new Event ();
- event.detail = SWT.ARROW;
- event.x = (int) rect.x;
- event.y = (int) (rect.y + rect.height);
- postEvent (SWT.Selection, event);
- }
- }
- return result;
-}
-
-int kEventMouseDragged (int nextHandler, int theEvent, int userData) {
- return parent.kEventMouseDragged (nextHandler, theEvent, userData);
-}
-
-int kEventMouseMoved (int nextHandler, int theEvent, int userData) {
- return parent.kEventMouseMoved (nextHandler, theEvent, userData);
-}
-
-int kEventMouseUp (int nextHandler, int theEvent, int userData) {
- return parent.kEventMouseUp (nextHandler, theEvent, userData);
-}
-
-void register () {
- super.register ();
- display.addWidget (handle, this);
- if (iconHandle != 0) display.addWidget (iconHandle, this);
- if (labelHandle != 0) display.addWidget (labelHandle, this);
-}
-
-
-void releaseParent () {
- super.releaseParent ();
- setVisible (false);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- handle = iconHandle = labelHandle = 0;
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (cIcon != 0) destroyCIcon (cIcon);
- cIcon = 0;
- if (visibleRgn != 0) OS.DisposeRgn (visibleRgn);
- visibleRgn = 0;
- control = null;
- toolTipText = null;
- image = disabledImage = hotImage = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-
-void resetVisibleRegion (int control) {
- if (visibleRgn != 0) {
- OS.DisposeRgn (visibleRgn);
- visibleRgn = 0;
- }
-}
-
-void selectRadio () {
- int index = 0;
- ToolItem [] items = parent.getItems ();
- while (index < items.length && items [index] != this) index++;
- int i = index - 1;
- while (i >= 0 && items [i].setRadioSelection (false)) --i;
- int j = index + 1;
- while (j < items.length && items [j].setRadioSelection (false)) j++;
- setSelection (true);
-}
-
-void setBackground (float [] color) {
- parent.setBackground (handle, color);
- if (labelHandle != 0) {
- parent.setBackground (labelHandle, color);
- }
- if (iconHandle != 0) parent.setBackground (iconHandle, color);
-}
-
-void setBounds (int x, int y, int width, int height) {
- setBounds (handle, x, y, width, height, true, true, false);
- if ((style & SWT.SEPARATOR) != 0) return;
- int space = 0;
- int stringWidth = 0, stringHeight = 0;
- if (text.length () != 0) {
- Point size = textExtent ();
- stringWidth = size.x;
- stringHeight = size.y;
- }
- int imageWidth = 0, imageHeight = 0;
- if (image != null) {
- if (text.length () != 0) space = 2;
- Rectangle rect = image.getBounds ();
- imageWidth = rect.width;
- imageHeight = rect.height;
- }
- int arrowWidth = 0;
- if ((style & SWT.DROP_DOWN) != 0) {
- arrowWidth = ARROW_WIDTH;
- }
- if ((parent.style & SWT.RIGHT) != 0) {
- int imageX = INSET;
- int imageY = INSET + (height - (INSET * 2) - imageHeight) / 2;
- setBounds (iconHandle, imageX, imageY, imageWidth, imageHeight, true, true, false);
- int labelX = imageX + imageWidth + space;
- int labelY = INSET + (height - (INSET * 2) - stringHeight) / 2;
- setBounds (labelHandle, labelX, labelY, stringWidth, stringHeight, true, true, false);
- } else {
- int imageX = INSET + (width - (INSET * 2) - arrowWidth - imageWidth) / 2;
- int imageY = INSET + (height - imageHeight - stringHeight - INSET * 2) / 2;
- setBounds (iconHandle, imageX, imageY, imageWidth, imageHeight, true, true, false);
- int labelX = INSET + (width - (INSET * 2) - arrowWidth - stringWidth) / 2;
- int labelY = imageY + imageHeight + space;
- setBounds (labelHandle, labelX, labelY, stringWidth, stringHeight, true, true, false);
- }
-}
-
-/**
- * Sets the control that is used to fill the bounds of
- * the item when the item is a <code>SEPARATOR</code>.
- *
- * @param control the new control
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- if ((style & SWT.SEPARATOR) == 0) return;
- if (this.control == control) return;
- this.control = control;
- redrawWidget (handle, false);
- if (control != null && !control.isDisposed ()) {
- control.moveAbove (null);
- }
- parent.relayout ();
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise.
- * <p>
- * A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- * </p>
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- if ((state & DISABLED) == 0 && enabled) return;
- if (enabled) {
- state &= ~DISABLED;
- OS.EnableControl (handle);
- } else {
- state |= DISABLED;
- OS.DisableControl (handle);
- }
-}
-
-void setFontStyle (Font font) {
- parent.setFontStyle (labelHandle, font);
-}
-
-void setForeground (float [] color) {
- parent.setForeground (handle, color);
- if (labelHandle != 0) {
- parent.setForeground (labelHandle, color);
- }
- if (iconHandle != 0) parent.setForeground (iconHandle, color);
-}
-
-/**
- * Sets the receiver's disabled image to the argument, which may be
- * null indicating that no disabled image should be displayed.
- * <p>
- * The disabled image is displayed when the receiver is disabled.
- * </p>
- *
- * @param image the disabled image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDisabledImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- disabledImage = image;
- updateImage (true);
-}
-
-/**
- * Sets the receiver's hot image to the argument, which may be
- * null indicating that no hot image should be displayed.
- * <p>
- * The hot image is displayed when the mouse enters the receiver.
- * </p>
- *
- * @param image the hot image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHotImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- hotImage = image;
- updateImage (true);
-}
-
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- super.setImage (image);
- updateImage (true);
- OS.HIObjectSetAccessibilityIgnored (iconHandle, image == null);
-}
-
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-
-/**
- * Sets the selection state of the receiver.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked (which some platforms draw as a
- * pushed in button).
- * </p>
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
- this.selection = selected;
- redrawWidget (handle, true);
-}
-
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- super.setText (string);
- char [] buffer = new char [text.length ()];
- text.getChars (0, buffer.length, buffer, 0);
- int length = fixMnemonic (buffer);
- int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, length);
- if (ptr == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- OS.SetControlData (labelHandle, 0 , OS.kControlStaticTextCFStringTag, 4, new int[]{ptr});
- OS.CFRelease (ptr);
- redrawWidget (labelHandle, false);
- parent.relayout ();
- OS.HIObjectSetAccessibilityIgnored (labelHandle, string.equals(""));
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
-}
-
-void setVisible (boolean visible) {
- if (visible) {
- if ((state & HIDDEN) == 0) return;
- state &= ~HIDDEN;
- } else {
- if ((state & HIDDEN) != 0) return;
- state |= HIDDEN;
- }
- setVisible (handle, visible);
-}
-
-/**
- * Sets the width of the receiver, for <code>SEPARATOR</code> ToolItems.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int width) {
- checkWidget();
- if ((style & SWT.SEPARATOR) == 0) return;
- if (width < 0 || this.width == width) return;
- this.width = width;
- redrawWidget (handle, false);
- parent.relayout();
-}
-
-void setZOrder () {
- OS.HIViewAddSubview (parent.handle, handle);
- if (iconHandle != 0) OS.HIViewAddSubview (handle, iconHandle);
- if (labelHandle != 0) OS.HIViewAddSubview (handle, labelHandle);
-}
-
-void updateImage (boolean layout) {
- if ((style & SWT.SEPARATOR) != 0) return;
- if (cIcon != 0) destroyCIcon (cIcon);
- cIcon = 0;
- Image image = null;
- if (hotImage != null) {
- image = hotImage;
- } else {
- if (this.image != null) {
- image = this.image;
- } else {
- image = disabledImage;
- }
- }
- ControlButtonContentInfo inContent = new ControlButtonContentInfo ();
- if (image != null) {
- cIcon = createCIcon (image);
- inContent.contentType = (short) OS.kControlContentCIconHandle;
- inContent.iconRef = cIcon;
- }
- OS.SetBevelButtonContentInfo (iconHandle, inContent);
- if (layout) {
- redrawWidget (iconHandle, false);
- parent.relayout();
- }
-}
-
-Point textExtent () {
- int [] ptr = new int [1];
- OS.GetControlData (labelHandle, (short) 0, OS.kControlStaticTextCFStringTag, 4, ptr, null);
- Point result = parent.textExtent (ptr [0], 0);
- if (ptr [0] != 0) OS.CFRelease (ptr [0]);
- return result;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolTip.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolTip.java
deleted file mode 100644
index 56911de381..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolTip.java
+++ /dev/null
@@ -1,669 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.carbon.HMHelpContentRec;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent popup windows that are used
- * to inform or warn the user.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BALLOON, ICON_ERROR, ICON_INFORMATION, ICON_WARNING</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION,
- * and ICON_WARNING may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tooltips">Tool Tips snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.2
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolTip extends Widget {
- Shell parent, tip;
- int x, y;
- boolean spikeAbove, autohide;
- TextLayout layoutText, layoutMessage;
- String text, message;
- TrayItem item;
- Region region;
- Font boldFont;
- Runnable runnable;
-
- int helpString;
- static final int BORDER = 5;
- static final int PADDING = 5;
- static final int INSET = 4;
- static final int TIP_HEIGHT = 20;
- static final int IMAGE_SIZE = 16;
- static final int DELAY = 10000;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BALLOON
- * @see SWT#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_WARNING
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ToolTip (Shell parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget ();
- parent.addToolTip (this);
-}
-
-static int checkStyle (int style) {
- int mask = SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING;
- if ((style & mask) == 0) return style;
- return checkBits (style, SWT.ICON_INFORMATION, SWT.ICON_WARNING, SWT.ICON_ERROR, 0, 0, 0);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the receiver is selected.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the receiver is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-void configure () {
- Display display = parent.getDisplay ();
- int x = this.x;
- int y = this.y;
- if (x == -1 || y == -1) {
- Point point;
- if (item != null) {
- point = item.getLocation ();
- } else {
- point = display.getCursorLocation ();
- }
- x = point.x;
- y = point.y;
- }
- Monitor monitor = parent.getMonitor ();
- Rectangle dest = monitor.getBounds ();
- Point size = getSize (dest.width / 4);
- int w = size.x;
- int h = size.y;
- int t = (style & SWT.BALLOON) != 0 ? TIP_HEIGHT : 0;
- int i = (style & SWT.BALLOON) != 0 ? 17 : 0;
- tip.setSize (w, h + t);
- int [] polyline;
- spikeAbove = dest.height >= y + size.y + t;
- if (dest.width >= x + size.x) {
- if (dest.height >= y + size.y + t) {
- polyline = new int [] {
- 0, 5+t, 1, 5+t, 1, 3+t, 3, 1+t, 5, 1+t, 5, t,
- 16, t, 16, 0, 35, t,
- w-5, t, w-5, 1+t, w-3, 1+t, w-1, 3+t, w-1, 5+t, w, 5+t,
- w, h-5+t, w-1, h-5+t, w-1, h-3+t, w-2, h-3+t, w-2, h-2+t, w-3, h-2+t, w-3, h-1+t, w-5, h-1+t, w-5, h+t,
- 5, h+t, 5, h-1+t, 3, h-1+t, 3, h-2+t, 2, h-2+t, 2, h-3+t, 1, h-3+t, 1, h-5+t, 0, h-5+t,
- 0, 5+t};
- tip.setLocation (Math.max (0, x - i), y);
- } else {
- polyline = new int [] {
- 0, 5, 1, 5, 1, 3, 3, 1, 5, 1, 5, 0,
- w-5, 0, w-5, 1, w-3, 1, w-1, 3, w-1, 5, w, 5,
- w, h-5, w-1, h-5, w-1, h-3, w-2, h-3, w-2, h-2, w-3, h-2, w-3, h-1, w-5, h-1, w-5, h,
- 35, h, 16, h+t, 16, h,
- 5, h, 5, h-1, 3, h-1, 3, h-2, 2, h-2, 2, h-3, 1, h-3, 1, h-5, 0, h-5,
- 0, 5};
- tip.setLocation (Math.max (0, x - i), y - size.y - t);
- }
- } else {
- if (dest.height >= y + size.y + t) {
- polyline = new int [] {
- 0, 5+t, 1, 5+t, 1, 3+t, 3, 1+t, 5, 1+t, 5, t,
- w-35, t, w-16, 0, w-16, t,
- w-5, t, w-5, 1+t, w-3, 1+t, w-1, 3+t, w-1, 5+t, w, 5+t,
- w, h-5+t, w-1, h-5+t, w-1, h-3+t, w-2, h-3+t, w-2, h-2+t, w-3, h-2+t, w-3, h-1+t, w-5, h-1+t, w-5, h+t,
- 5, h+t, 5, h-1+t, 3, h-1+t, 3, h-2+t, 2, h-2+t, 2, h-3+t, 1, h-3+t, 1, h-5+t, 0, h-5+t,
- 0, 5+t};
- tip.setLocation (Math.min (dest.width - size.x, x - size.x + i), y);
- } else {
- polyline = new int [] {
- 0, 5, 1, 5, 1, 3, 3, 1, 5, 1, 5, 0,
- w-5, 0, w-5, 1, w-3, 1, w-1, 3, w-1, 5, w, 5,
- w, h-5, w-1, h-5, w-1, h-3, w-2, h-3, w-2, h-2, w-3, h-2, w-3, h-1, w-5, h-1, w-5, h,
- w-16, h, w-16, h+t, w-35, h,
- 5, h, 5, h-1, 3, h-1, 3, h-2, 2, h-2, 2, h-3, 1, h-3, 1, h-5, 0, h-5,
- 0, 5};
- tip.setLocation (Math.min (dest.width - size.x, x - size.x + i), y - size.y - t);
- }
- }
- if ((style & SWT.BALLOON) != 0) {
- if (region != null) region.dispose ();
- region = new Region (display);
- region.add (polyline);
- tip.setRegion (region);
- }
-}
-
-void createWidget () {
- super.createWidget ();
- this.autohide = true;
- x = y = -1;
- text = "";
- message = "";
-}
-
-
-void disposeTip () {
- if (tip != null) tip.dispose ();
- tip = null;
- if (region != null) region.dispose ();
- region = null;
- if (layoutText != null) layoutText.dispose ();
- layoutText = null;
- if (layoutMessage != null) layoutMessage.dispose ();
- layoutMessage = null;
- if (boldFont != null) boldFont.dispose ();
- boldFont = null;
-}
-
-/**
- * Returns <code>true</code> if the receiver is automatically
- * hidden by the platform, and <code>false</code> otherwise.
- *
- * @return the receiver's auto hide state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public boolean getAutoHide () {
- checkWidget ();
- return autohide;
-}
-
-/**
- * Returns the receiver's message, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's message
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getMessage () {
- checkWidget ();
- return message;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Shell</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Shell getParent () {
- checkWidget ();
- return parent;
-}
-
-Point getSize (int maxWidth) {
- int textWidth = 0, messageWidth = 0;
- if (layoutText != null) {
- layoutText.setWidth (-1);
- textWidth = layoutText.getBounds ().width;
- }
- if (layoutMessage != null) {
- layoutMessage.setWidth (-1);
- messageWidth = layoutMessage.getBounds ().width;
- }
- int messageTrim = 2 * INSET + 2 * BORDER + 2 * PADDING;
- boolean hasImage = layoutText != null && (style & SWT.BALLOON) != 0 && (style & (SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING)) != 0;
- int textTrim = messageTrim + (hasImage ? IMAGE_SIZE : 0);
- int width = Math.min (maxWidth, Math.max (textWidth + textTrim, messageWidth + messageTrim));
- int textHeight = 0, messageHeight = 0;
- if (layoutText != null) {
- layoutText.setWidth (maxWidth - textTrim);
- textHeight = layoutText.getBounds ().height;
- }
- if (layoutMessage != null) {
- layoutMessage.setWidth (maxWidth - messageTrim);
- messageHeight = layoutMessage.getBounds ().height;
- }
- int height = 2 * BORDER + 2 * PADDING + messageHeight;
- if (layoutText != null) height += Math.max (IMAGE_SIZE, textHeight) + 2 * PADDING;
- return new Point (width, height);
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- if (tip != null) return tip.getVisible ();
- if (display.helpWidget == this) {
- int window = OS.FrontWindow ();
- int [] windowClass = new int [1];
- OS.GetWindowClass (window, windowClass);
- return windowClass [0] == OS.kHelpWindowClass;
- }
- return false;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget ();
- return getVisible ();
-}
-
-void onMouseDown (Event event) {
- notifyListeners (SWT.Selection, new Event ());
- setVisible (false);
-}
-
-void onPaint (Event event) {
- GC gc = event.gc;
- int x = BORDER + PADDING;
- int y = BORDER + PADDING;
- if ((style & SWT.BALLOON) != 0 && spikeAbove) y += TIP_HEIGHT;
- if (layoutText != null) {
- int id = style & (SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING);
- if ((style & SWT.BALLOON) != 0 && id != 0) {
- Display display = getDisplay ();
- Image image = display.getSystemImage (id);
- Rectangle rect = image.getBounds ();
- gc.drawImage (image, 0, 0, rect.width, rect.height, x, y, IMAGE_SIZE, IMAGE_SIZE);
- x += IMAGE_SIZE;
- }
- x += INSET;
- layoutText.draw (gc, x, y);
- y += 2 * PADDING + Math.max (IMAGE_SIZE, layoutText.getBounds ().height);
- }
- if (layoutMessage != null) {
- x = BORDER + PADDING + INSET;
- layoutMessage.draw (gc, x, y);
- }
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (parent != null) parent.removeTooTip (this);
- if (runnable != null) {
- Display display = getDisplay ();
- display.timerExec (-1, runnable);
- }
- runnable = null;
- disposeTip ();
- if (helpString != 0) OS.CFRelease (helpString);
- helpString = 0;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Makes the receiver hide automatically when <code>true</code>,
- * and remain visible when <code>false</code>.
- *
- * @param autoHide the auto hide state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- * @see #setVisible
- */
-public void setAutoHide (boolean autohide) {
- checkWidget ();
- this.autohide = autohide;
- //TODO - update when visible
-}
-
-/**
- * Sets the location of the receiver, which must be a tooltip,
- * to the point specified by the arguments which are relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget ();
- if (this.x == x && this.y == y) return;
- this.x = x;
- this.y = y;
- if (tip != null && tip.getVisible ()) configure ();
-}
-
-/**
- * Sets the location of the receiver, which must be a tooltip,
- * to the point specified by the argument which is relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p><p>
- * Note that the platform window manager ultimately has control
- * over the location of tooltips.
- * </p>
- *
- * @param location the new location for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (Point location) {
- checkWidget ();
- if (location == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-/**
- * Sets the receiver's message.
- *
- * @param string the new message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMessage (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- message = string;
- if (tip != null) {
- layoutMessage.setText (string);
- if (tip.getVisible ()) configure ();
- }
-}
-
-/**
- * Sets the receiver's text.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- text = string;
- if (tip != null) {
- layoutText.setText (string);
- TextStyle style = new TextStyle (boldFont, null, null);
- layoutText.setStyle (style, 0, string.length ());
- if (tip.getVisible ()) configure ();
- }
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- if (helpString != 0) OS.CFRelease (helpString);
- helpString = 0;
- if (runnable != null) display.timerExec (-1, runnable);
- runnable = null;
- if (visible) {
- OS.HMHideTag ();
- display.helpWidget = this;
- if (!autohide || (style & SWT.BALLOON) != 0) {
- // Show tip
- if (tip == null) {
- tip = new Shell (parent, SWT.ON_TOP | SWT.NO_TRIM | SWT.TOOL);
- Color background = display.getSystemColor (SWT.COLOR_INFO_BACKGROUND);
- tip.setBackground (background);
- Listener listener = new Listener () {
- public void handleEvent (Event event) {
- switch (event.type) {
- case SWT.Paint: onPaint (event); break;
- case SWT.MouseDown: onMouseDown (event); break;
- }
- }
- };
- tip.addListener (SWT.Paint, listener);
- tip.addListener (SWT.MouseDown, listener);
-
- layoutText = new TextLayout (display);
- layoutText.setText (text);
- Font font = display.getSystemFont ();
- FontData data = font.getFontData () [0];
- boldFont = new Font (display, data.getName (), data.getHeight (), SWT.BOLD);
- TextStyle style = new TextStyle (boldFont, null, null);
- layoutText.setStyle (style, 0, text.length ());
- layoutMessage = new TextLayout (display);
- layoutMessage.setText(message);
- }
-
- configure ();
- tip.setVisible (true);
- if (autohide) {
- runnable = new Runnable () {
- public void run () {
- if (!isDisposed ()) setVisible (false);
- }
- };
- display.timerExec(DELAY, runnable);
- }
- } else {
- // Show HMTag
- if (tip != null) disposeTip ();
- if (x == -1 || y == -1) {
- Point point;
- if (item != null) {
- point = item.getLocation ();
- x = point.x;
- y = point.y;
- } else {
- org.eclipse.swt.internal.carbon.Point pt = new org.eclipse.swt.internal.carbon.Point ();
- OS.GetGlobalMouse (pt);
- x = pt.h;
- y = pt.v;
- }
- }
- StringBuffer string = new StringBuffer (text);
- if (text.length () > 0) string.append ("\n\n");
- string.append (message);
- char [] buffer = new char [string.length ()];
- string.getChars (0, buffer.length, buffer, 0);
- helpString = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- HMHelpContentRec helpContent = new HMHelpContentRec ();
- helpContent.tagSide = (short) OS.kHMAbsoluteCenterAligned;
- helpContent.absHotRect_left = (short)x;
- helpContent.absHotRect_top = (short)y;
- helpContent.absHotRect_right = (short)(x + 1);
- helpContent.absHotRect_bottom = (short) (y + 1);
- helpContent.content0_contentType = OS.kHMCFStringContent;
- helpContent.content0_tagCFString = helpString;
- helpContent.content1_contentType = OS.kHMCFStringContent;
- helpContent.content1_tagCFString = helpString;
- OS.HMDisplayTag(helpContent);
- }
- } else {
- if (display.helpWidget == this) {
- display.helpWidget = null;
- OS.HMHideTag ();
- if (tip != null) tip.setVisible (false);
- }
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tracker.java
deleted file mode 100644
index 91d93f3b18..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tracker.java
+++ /dev/null
@@ -1,1051 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.CGPoint;
-import org.eclipse.swt.internal.carbon.CGRect;
-import org.eclipse.swt.internal.carbon.Rect;
-
-/**
- * Instances of this class implement rubber banding rectangles that are
- * drawn onto a parent <code>Composite</code> or <code>Display</code>.
- * These rectangles can be specified to respond to mouse and key events
- * by either moving or resizing themselves accordingly. Trackers are
- * typically used to represent window geometries in a lightweight manner.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, UP, DOWN, RESIZE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Move, Resize</dd>
- * </dl>
- * <p>
- * Note: Rectangle move behavior is assumed unless RESIZE is specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tracker">Tracker snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Tracker extends Widget {
- Control parent;
- boolean tracking, cancelled, stippled;
- Cursor clientCursor, resizeCursor;
- Rectangle [] rectangles = new Rectangle [0], proportions = rectangles;
- Rectangle bounds;
- int cursorOrientation = SWT.NONE;
- boolean inEvent = false;
- int window, oldX, oldY;
-
- /*
- * The following values mirror step sizes on Windows
- */
- final static int STEPSIZE_SMALL = 1;
- final static int STEPSIZE_LARGE = 9;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#RESIZE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Tracker (Composite parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
-}
-
-/**
- * Constructs a new instance of this class given the display
- * to create it on and a style value describing its behavior
- * and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the tracker on the currently active
- * display if there is one. If there is no current display, the
- * tracker is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the tracker on
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#RESIZE
- */
-public Tracker (Display display, int style) {
- if (display == null) display = Display.getCurrent ();
- if (display == null) display = Display.getDefault ();
- if (!display.isValidThread ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- this.style = checkStyle (style);
- this.display = display;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize, typedListener);
- addListener (SWT.Move, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard, by sending
- * it one of the messages defined in the <code>KeyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #removeKeyListener
- */
-public void addKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.KeyUp,typedListener);
- addListener(SWT.KeyDown,typedListener);
-}
-
-Point adjustMoveCursor () {
- if (bounds == null) return null;
- int newX = bounds.x + bounds.width / 2;
- int newY = bounds.y;
- /*
- * Convert to screen coordinates if needed
- */
- if (parent != null) {
- Point pt = parent.toDisplay (newX, newY);
- newX = pt.x;
- newY = pt.y;
- }
- CGPoint pt = new CGPoint ();
- pt.x = newX;
- pt.y = newY;
- OS.CGWarpMouseCursorPosition (pt);
- return new Point ((int) pt.x, (int) pt.y);
-}
-
-Point adjustResizeCursor (boolean movePointer) {
- if (bounds == null) return null;
- int newX, newY;
-
- if ((cursorOrientation & SWT.LEFT) != 0) {
- newX = bounds.x;
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- newX = bounds.x + bounds.width;
- } else {
- newX = bounds.x + bounds.width / 2;
- }
-
- if ((cursorOrientation & SWT.UP) != 0) {
- newY = bounds.y;
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- newY = bounds.y + bounds.height;
- } else {
- newY = bounds.y + bounds.height / 2;
- }
-
- /*
- * Convert to screen coordinates if needed
- */
- if (parent != null) {
- Point pt = parent.toDisplay (newX, newY);
- newX = pt.x;
- newY = pt.y;
- }
- if (movePointer) {
- CGPoint pt = new CGPoint ();
- pt.x = newX;
- pt.y = newY;
- OS.CGWarpMouseCursorPosition (pt);
- }
-
- /*
- * If the client has not provided a custom cursor then determine
- * the appropriate resize cursor.
- */
- if (clientCursor == null) {
- Cursor newCursor = null;
- switch (cursorOrientation) {
- case SWT.UP:
- newCursor = new Cursor(display, SWT.CURSOR_SIZENS);
- break;
- case SWT.DOWN:
- newCursor = new Cursor(display, SWT.CURSOR_SIZENS);
- break;
- case SWT.LEFT:
- newCursor = new Cursor(display, SWT.CURSOR_SIZEWE);
- break;
- case SWT.RIGHT:
- newCursor = new Cursor(display, SWT.CURSOR_SIZEWE);
- break;
- case SWT.LEFT | SWT.UP:
- newCursor = new Cursor(display, SWT.CURSOR_SIZENWSE);
- break;
- case SWT.RIGHT | SWT.DOWN:
- newCursor = new Cursor(display, SWT.CURSOR_SIZENWSE);
- break;
- case SWT.LEFT | SWT.DOWN:
- newCursor = new Cursor(display, SWT.CURSOR_SIZENESW);
- break;
- case SWT.RIGHT | SWT.UP:
- newCursor = new Cursor(display, SWT.CURSOR_SIZENESW);
- break;
- default:
- newCursor = new Cursor(display, SWT.CURSOR_SIZEALL);
- break;
- }
- display.setCursor (newCursor.handle);
- if (resizeCursor != null) {
- resizeCursor.dispose ();
- }
- resizeCursor = newCursor;
- }
-
- return new Point (newX, newY);
-}
-
-static int checkStyle (int style) {
- if ((style & (SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN)) == 0) {
- style |= SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN;
- }
- return style;
-}
-
-/**
- * Stops displaying the tracker rectangles. Note that this is not considered
- * to be a cancelation by the user.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void close () {
- checkWidget ();
- tracking = false;
-}
-Rectangle computeBounds () {
- if (rectangles.length == 0) return null;
- int xMin = rectangles [0].x;
- int yMin = rectangles [0].y;
- int xMax = rectangles [0].x + rectangles [0].width;
- int yMax = rectangles [0].y + rectangles [0].height;
-
- for (int i = 1; i < rectangles.length; i++) {
- if (rectangles [i].x < xMin) xMin = rectangles [i].x;
- if (rectangles [i].y < yMin) yMin = rectangles [i].y;
- int rectRight = rectangles [i].x + rectangles [i].width;
- if (rectRight > xMax) xMax = rectRight;
- int rectBottom = rectangles [i].y + rectangles [i].height;
- if (rectBottom > yMax) yMax = rectBottom;
- }
-
- return new Rectangle (xMin, yMin, xMax - xMin, yMax - yMin);
-}
-
-Rectangle [] computeProportions (Rectangle [] rects) {
- Rectangle [] result = new Rectangle [rects.length];
- bounds = computeBounds ();
- if (bounds != null) {
- for (int i = 0; i < rects.length; i++) {
- int x = 0, y = 0, width = 0, height = 0;
- if (bounds.width != 0) {
- x = (rects [i].x - bounds.x) * 100 / bounds.width;
- width = rects [i].width * 100 / bounds.width;
- } else {
- width = 100;
- }
- if (bounds.height != 0) {
- y = (rects [i].y - bounds.y) * 100 / bounds.height;
- height = rects [i].height * 100 / bounds.height;
- } else {
- height = 100;
- }
- result [i] = new Rectangle (x, y, width, height);
- }
- }
- return result;
-}
-
-void drawRectangles (int window, Rectangle [] rects, boolean erase) {
- int[] context = new int [1];
- int port = OS.GetWindowPort (window);
- Rect portRect = new Rect ();
- OS.GetPortBounds (port, portRect);
- OS.QDBeginCGContext (port, context);
- OS.CGContextScaleCTM (context [0], 1, -1);
- OS.CGContextTranslateCTM (context [0], 0, portRect.top - portRect.bottom);
- CGRect cgRect = new CGRect ();
- Point parentOrigin;
- if (parent != null) {
- parentOrigin = display.map (parent, null, 0, 0);
- } else {
- parentOrigin = new Point (0, 0);
- }
- for (int i=0; i<rects.length; i++) {
- Rectangle rect = rects [i];
- cgRect.x = rect.x + parentOrigin.x;
- cgRect.y = rect.y + parentOrigin.y;
- cgRect.width = rect.width;
- cgRect.height = rect.height;
- if (erase) {
- cgRect.width++;
- cgRect.height++;
- OS.CGContextClearRect (context [0], cgRect);
- } else {
- cgRect.x += 0.5f;
- cgRect.y += 0.5f;
- OS.CGContextStrokeRect (context [0], cgRect);
- }
- }
- OS.CGContextSynchronize (context [0]);
- OS.QDEndCGContext (port, context);
-}
-
-/**
- * Returns the bounds that are being drawn, expressed relative to the parent
- * widget. If the parent is a <code>Display</code> then these are screen
- * coordinates.
- *
- * @return the bounds of the Rectangles being drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle [] getRectangles () {
- checkWidget();
- Rectangle [] result = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- result [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- return result;
-}
-
-/**
- * Returns <code>true</code> if the rectangles are drawn with a stippled line, <code>false</code> otherwise.
- *
- * @return the stippled effect of the rectangles
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getStippled () {
- checkWidget ();
- return stippled;
-}
-
-int kEventMouse (int eventKind, int nextHandler, int theEvent, int userData) {
- int sizeof = org.eclipse.swt.internal.carbon.Point.sizeof;
- org.eclipse.swt.internal.carbon.Point where = new org.eclipse.swt.internal.carbon.Point ();
- OS.GetEventParameter (theEvent, OS.kEventParamMouseLocation, OS.typeQDPoint, null, sizeof, null, where);
- int newX = where.h, newY = where.v;
- if (newX != oldX || newY != oldY) {
- Rectangle [] oldRectangles = rectangles;
- Rectangle [] rectsToErase = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- rectsToErase [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- Event event = new Event ();
- event.x = newX;
- event.y = newY;
- if ((style & SWT.RESIZE) != 0) {
- boolean orientationInit = resizeRectangles (newX - oldX, newY - oldY);
- inEvent = true;
- sendEvent (SWT.Resize, event);
- inEvent = false;
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the move
- * event. If this happens, return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return OS.noErr;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the resize event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- }
- else {
- draw = true;
- }
- if (draw) {
- drawRectangles (window, rectsToErase, true);
- drawRectangles (window, rectangles, false);
- }
- Point cursorPos = adjustResizeCursor (orientationInit);
- if (cursorPos != null) {
- newX = cursorPos.x;
- newY = cursorPos.y;
- }
- } else {
- moveRectangles (newX - oldX, newY - oldY);
- inEvent = true;
- sendEvent (SWT.Move, event);
- inEvent = false;
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the move
- * event. If this happens, return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return OS.noErr;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the move event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (window, rectsToErase, true);
- drawRectangles (window, rectangles, false);
- }
- }
- oldX = newX; oldY = newY;
- }
- tracking = eventKind != OS.kEventMouseUp;
- return 0;
-}
-
-int kEventMouseDragged (int nextHandler, int theEvent, int userData) {
- return kEventMouse (OS.kEventMouseDragged, nextHandler, theEvent, userData);
-}
-
-int kEventRawKeyPressed (int nextHandler, int theEvent, int userData) {
- if (!sendKeyEvent (SWT.KeyDown, theEvent)) return OS.noErr;
- int [] keyCode = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyCode, OS.typeUInt32, null, keyCode.length * 4, null, keyCode);
- int [] modifiers = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
- int stepSize = (modifiers [0] & OS.controlKey) != 0 ? STEPSIZE_SMALL : STEPSIZE_LARGE;
- int xChange = 0, yChange = 0;
- switch (keyCode [0]) {
- case 53: /* Esc */
- cancelled = true;
- tracking = false;
- break;
- case 76: /* KP Enter */
- case 36: /* Return */
- tracking = false;
- break;
- case 123: /* Left arrow */
- xChange = -stepSize;
- break;
- case 124: /* Right arrow */
- xChange = stepSize;
- break;
- case 126: /* Up arrow */
- yChange = -stepSize;
- break;
- case 125: /* Down arrow */
- yChange = stepSize;
- break;
- }
- if (xChange != 0 || yChange != 0) {
- Rectangle [] oldRectangles = rectangles;
- Rectangle [] rectsToErase = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- rectsToErase [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- Event event = new Event ();
- int newX = oldX + xChange;
- int newY = oldY + yChange;
- event.x = newX;
- event.y = newY;
- Point cursorPos;
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (xChange, yChange);
- inEvent = true;
- sendEvent (SWT.Resize, event);
- inEvent = false;
- /*
- * It is possible (but unlikely) that application
- * code could have disposed the widget in the move
- * event. If this happens return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return OS.noErr;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the resize event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (window, rectsToErase, true);
- drawRectangles (window, rectangles, false);
- }
- cursorPos = adjustResizeCursor (true);
- } else {
- moveRectangles (xChange, yChange);
- inEvent = true;
- sendEvent (SWT.Move, event);
- inEvent = false;
- /*
- * It is possible (but unlikely) that application
- * code could have disposed the widget in the move
- * event. If this happens return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return OS.noErr;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the move event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (window, rectsToErase, true);
- drawRectangles (window, rectangles, false);
- }
- cursorPos = adjustMoveCursor ();
- }
- if (cursorPos != null) {
- oldX = cursorPos.x;
- oldY = cursorPos.y;
- }
- }
- return 0;
-}
-
-int kEventMouseMoved (int nextHandler, int theEvent, int userData) {
- return kEventMouse (OS.kEventMouseMoved, nextHandler, theEvent, userData);
-}
-
-int kEventMouseUp (int nextHandler, int theEvent, int userData) {
- return kEventMouse (OS.kEventMouseUp, nextHandler, theEvent, userData);
-}
-
-void moveRectangles (int xChange, int yChange) {
- if (bounds == null) return;
- if (xChange < 0 && ((style & SWT.LEFT) == 0)) xChange = 0;
- if (xChange > 0 && ((style & SWT.RIGHT) == 0)) xChange = 0;
- if (yChange < 0 && ((style & SWT.UP) == 0)) yChange = 0;
- if (yChange > 0 && ((style & SWT.DOWN) == 0)) yChange = 0;
- if (xChange == 0 && yChange == 0) return;
- bounds.x += xChange; bounds.y += yChange;
- for (int i = 0; i < rectangles.length; i++) {
- rectangles [i].x += xChange;
- rectangles [i].y += yChange;
- }
-}
-
-/**
- * Displays the Tracker rectangles for manipulation by the user. Returns when
- * the user has either finished manipulating the rectangles or has cancelled the
- * Tracker.
- *
- * @return <code>true</code> if the user did not cancel the Tracker, <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean open () {
- checkWidget ();
- cancelled = false;
- tracking = true;
- window = display.createOverlayWindow ();
- OS.ShowWindow (window);
- drawRectangles (window, rectangles, false);
-
- /*
- * If exactly one of UP/DOWN is specified as a style then set the cursor
- * orientation accordingly (the same is done for LEFT/RIGHT styles below).
- */
- int vStyle = style & (SWT.UP | SWT.DOWN);
- if (vStyle == SWT.UP || vStyle == SWT.DOWN) {
- cursorOrientation |= vStyle;
- }
- int hStyle = style & (SWT.LEFT | SWT.RIGHT);
- if (hStyle == SWT.LEFT || hStyle == SWT.RIGHT) {
- cursorOrientation |= hStyle;
- }
-
- Point cursorPos;
- if (OS.StillDown ()) {
- org.eclipse.swt.internal.carbon.Point pt = new org.eclipse.swt.internal.carbon.Point ();
- OS.GetGlobalMouse (pt);
- cursorPos = new Point (pt.h, pt.v);
- } else {
- if ((style & SWT.RESIZE) != 0) {
- cursorPos = adjustResizeCursor (true);
- } else {
- cursorPos = adjustMoveCursor ();
- }
- }
- if (cursorPos != null) {
- oldX = cursorPos.x;
- oldY = cursorPos.y;
- }
-
- /* Tracker behaves like a Dialog with its own OS event loop. */
- int [] outEvent = new int [1];
- while (tracking && !cancelled) {
- int status = OS.ReceiveNextEvent (0, null, OS.kEventDurationNoWait, true, outEvent);
- if (status != OS.noErr) continue;
- int event = outEvent [0];
- int eventClass = OS.GetEventClass (event);
- int eventKind = OS.GetEventKind (event);
- int nextHandler = 0;
- switch (eventClass) {
- case OS.kEventClassMouse:
- switch (eventKind) {
- case OS.kEventMouseUp: kEventMouseUp (nextHandler, event, 0); break;
- case OS.kEventMouseMoved: kEventMouseMoved (nextHandler, event, 0); break;
- case OS.kEventMouseDragged: kEventMouseDragged (nextHandler, event, 0); break;
- }
- break;
- case OS.kEventClassKeyboard:
- switch (eventKind) {
- case OS.kEventRawKeyDown: kEventRawKeyDown (nextHandler, event, 0); break;
- case OS.kEventRawKeyModifiersChanged: kEventRawKeyModifiersChanged (nextHandler, event, 0); break;
- case OS.kEventRawKeyRepeat: kEventRawKeyRepeat (nextHandler, event, 0); break;
- case OS.kEventRawKeyUp: kEventRawKeyUp (nextHandler, event, 0); break;
- }
- break;
- }
- /*
- * Don't dispatch mouse and key events in general, EXCEPT once this
- * tracker has finished its work.
- */
- boolean dispatch = true;
- if (tracking && !cancelled) {
- if (eventClass == OS.kEventClassMouse) dispatch = false;
- if (eventClass == OS.kEventClassKeyboard) dispatch = false;
- }
- if (dispatch) OS.SendEventToEventTarget (event, OS.GetEventDispatcherTarget ());
- OS.ReleaseEvent (event);
- if (clientCursor != null && resizeCursor == null) {
- display.setCursor (clientCursor.handle);
- }
- }
- if (!isDisposed()) {
- drawRectangles (window, rectangles, true);
- }
- OS.DisposeWindow (window);
- tracking = false;
- window = 0;
- return !cancelled;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
- rectangles = proportions = null;
- bounds = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Resize, listener);
- eventTable.unhook (SWT.Move, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #addKeyListener
- */
-public void removeKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.KeyUp, listener);
- eventTable.unhook(SWT.KeyDown, listener);
-}
-
-/*
- * Returns true if the pointer's orientation was initialized in some dimension,
- * and false otherwise.
- */
-boolean resizeRectangles (int xChange, int yChange) {
- if (bounds == null) return false;
- boolean orientationInit = false;
- /*
- * If the cursor orientation has not been set in the orientation of
- * this change then try to set it here.
- */
- if (xChange < 0 && ((style & SWT.LEFT) != 0) && ((cursorOrientation & SWT.RIGHT) == 0)) {
- if ((cursorOrientation & SWT.LEFT) == 0) {
- cursorOrientation |= SWT.LEFT;
- orientationInit = true;
- }
- }
- if (xChange > 0 && ((style & SWT.RIGHT) != 0) && ((cursorOrientation & SWT.LEFT) == 0)) {
- if ((cursorOrientation & SWT.RIGHT) == 0) {
- cursorOrientation |= SWT.RIGHT;
- orientationInit = true;
- }
- }
- if (yChange < 0 && ((style & SWT.UP) != 0) && ((cursorOrientation & SWT.DOWN) == 0)) {
- if ((cursorOrientation & SWT.UP) == 0) {
- cursorOrientation |= SWT.UP;
- orientationInit = true;
- }
- }
- if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) {
- if ((cursorOrientation & SWT.DOWN) == 0) {
- cursorOrientation |= SWT.DOWN;
- orientationInit = true;
- }
- }
-
- /*
- * If the bounds will flip about the x or y axis then apply the adjustment
- * up to the axis (ie.- where bounds width/height becomes 0), change the
- * cursor's orientation accordingly, and flip each Rectangle's origin (only
- * necessary for > 1 Rectangles)
- */
- if ((cursorOrientation & SWT.LEFT) != 0) {
- if (xChange > bounds.width) {
- if ((style & SWT.RIGHT) == 0) return orientationInit;
- cursorOrientation |= SWT.RIGHT;
- cursorOrientation &= ~SWT.LEFT;
- bounds.x += bounds.width;
- xChange -= bounds.width;
- bounds.width = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.x = 100 - proportion.x - proportion.width;
- }
- }
- }
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- if (bounds.width < -xChange) {
- if ((style & SWT.LEFT) == 0) return orientationInit;
- cursorOrientation |= SWT.LEFT;
- cursorOrientation &= ~SWT.RIGHT;
- xChange += bounds.width;
- bounds.width = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.x = 100 - proportion.x - proportion.width;
- }
- }
- }
- }
- if ((cursorOrientation & SWT.UP) != 0) {
- if (yChange > bounds.height) {
- if ((style & SWT.DOWN) == 0) return orientationInit;
- cursorOrientation |= SWT.DOWN;
- cursorOrientation &= ~SWT.UP;
- bounds.y += bounds.height;
- yChange -= bounds.height;
- bounds.height = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.y = 100 - proportion.y - proportion.height;
- }
- }
- }
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- if (bounds.height < -yChange) {
- if ((style & SWT.UP) == 0) return orientationInit;
- cursorOrientation |= SWT.UP;
- cursorOrientation &= ~SWT.DOWN;
- yChange += bounds.height;
- bounds.height = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.y = 100 - proportion.y - proportion.height;
- }
- }
- }
- }
-
- // apply the bounds adjustment
- if ((cursorOrientation & SWT.LEFT) != 0) {
- bounds.x += xChange;
- bounds.width -= xChange;
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- bounds.width += xChange;
- }
- if ((cursorOrientation & SWT.UP) != 0) {
- bounds.y += yChange;
- bounds.height -= yChange;
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- bounds.height += yChange;
- }
-
- Rectangle [] newRects = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle proportion = proportions[i];
- newRects[i] = new Rectangle (
- proportion.x * bounds.width / 100 + bounds.x,
- proportion.y * bounds.height / 100 + bounds.y,
- proportion.width * bounds.width / 100,
- proportion.height * bounds.height / 100);
- }
- rectangles = newRects;
- return orientationInit;
-}
-
-/**
- * Sets the <code>Cursor</code> of the Tracker. If this cursor is <code>null</code>
- * then the cursor reverts to the default.
- *
- * @param newCursor the new <code>Cursor</code> to display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCursor (Cursor newCursor) {
- checkWidget ();
- clientCursor = newCursor;
- if (newCursor != null) {
- if (inEvent) display.setCursor (newCursor.handle);
- }
-}
-
-/**
- * Specifies the rectangles that should be drawn, expressed relative to the parent
- * widget. If the parent is a Display then these are screen coordinates.
- *
- * @param rectangles the bounds of the rectangles to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of rectangles is null or contains a null rectangle</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setRectangles (Rectangle [] rectangles) {
- checkWidget ();
- if (rectangles == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = rectangles.length;
- this.rectangles = new Rectangle [length];
- for (int i = 0; i < length; i++) {
- Rectangle current = rectangles [i];
- if (current == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.rectangles [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- proportions = computeProportions (rectangles);
-}
-
-/**
- * Changes the appearance of the line used to draw the rectangles.
- *
- * @param stippled <code>true</code> if rectangle should appear stippled
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setStippled (boolean stippled) {
- checkWidget ();
- this.stippled = stippled;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TrayItem.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TrayItem.java
deleted file mode 100755
index 4366007404..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TrayItem.java
+++ /dev/null
@@ -1,479 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.carbon.CGRect;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class represent icons that can be placed on the
- * system tray or task bar status area.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, MenuDetect, Selection</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tray">Tray, TrayItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.0
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TrayItem extends Item {
- Tray parent;
- ToolTip toolTip;
- String toolTipText;
- boolean visible = true, highlight;
- int handle, nsImage, view, jniRef;
-
- static final float BORDER = 8f;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tray</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TrayItem (Tray parent, int style) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
- createWidget ();
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the platform-specific context menu trigger
- * has occurred, by sending it one of the messages defined in
- * the <code>MenuDetectListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #removeMenuDetectListener
- *
- * @since 3.3
- */
-public void addMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MenuDetect, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the receiver is selected
- * <code>widgetDefaultSelected</code> is called when the receiver is double-clicked
- * </p>
- *
- * @param listener the listener which should be notified when the receiver is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createWidget () {
- int statusBar = Cocoa.objc_msgSend (Cocoa.C_NSStatusBar, Cocoa.S_systemStatusBar);
- handle = Cocoa.objc_msgSend (statusBar, Cocoa.S_statusItemWithLength, 0f);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- Cocoa.objc_msgSend (handle, Cocoa.S_retain);
- Cocoa.objc_msgSend (handle, Cocoa.S_setHighlightMode, 1);
- jniRef = OS.NewGlobalRef (this);
- if (jniRef == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- NSRect rect = new NSRect();
- view = Cocoa.objc_msgSend (Cocoa.C_NSStatusItemImageView, Cocoa.S_alloc);
- if (view == 0) error (SWT.ERROR_NO_HANDLES);
- view = Cocoa.objc_msgSend (view, Cocoa.S_initWithProc_frame_user_data, display.trayItemProc, rect, jniRef);
- Cocoa.objc_msgSend (handle, Cocoa.S_setView, view);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-Point getLocation () {
- NSRect rect = new NSRect();
- Cocoa.objc_msgSend_stret(rect, view, Cocoa.S_frame);
- NSRect windowRect = new NSRect();
- Cocoa.objc_msgSend_stret(windowRect, Cocoa.objc_msgSend(view, Cocoa.S_window), Cocoa.S_frame);
- rect.x += rect.width / 2;
- rect.y += rect.height;
- Cocoa.objc_msgSend_stret(rect, view, Cocoa.S_convertRect_toView, rect, 0);
- rect.x += windowRect.x;
- return new Point ((int)rect.x, (int)rect.y);
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Tray</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Tray getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's tool tip, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public ToolTip getToolTip () {
- checkWidget ();
- return toolTip;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and
- * <code>false</code> otherwise.
- *
- * @return the receiver's visibility
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- return visible;
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
- handle = 0;
-}
-
-void releaseWidget () {
- int statusBar = Cocoa.objc_msgSend (Cocoa.C_NSStatusBar, Cocoa.S_systemStatusBar);
- Cocoa.objc_msgSend (statusBar, Cocoa.S_removeStatusItem, handle);
- Cocoa.objc_msgSend (handle, Cocoa.S_release);
- if (nsImage != 0) Cocoa.objc_msgSend (nsImage, Cocoa.S_release);
- if (view != 0) Cocoa.objc_msgSend (view, Cocoa.S_release);
- if (jniRef != 0) OS.DeleteGlobalRef (jniRef);
- handle = nsImage = view = jniRef = 0;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the platform-specific context menu trigger has
- * occurred.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #addMenuDetectListener
- *
- * @since 3.3
- */
-public void removeMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MenuDetect, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Sets the receiver's image.
- *
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- super.setImage (image);
- if (nsImage != 0) Cocoa.objc_msgSend (nsImage, Cocoa.S_release, nsImage);
- nsImage = 0;
- if (image != null) {
- CGRect rect = new CGRect ();
- rect.width = OS.CGImageGetWidth (image.handle);
- rect.height = OS.CGImageGetHeight (image.handle);
- NSSize size = new NSSize ();
- size.width = rect.width;
- size.height = rect.height;
- nsImage = Cocoa.objc_msgSend (Cocoa.C_NSImage, Cocoa.S_alloc);
- nsImage = Cocoa.objc_msgSend (nsImage, Cocoa.S_initWithSize, size);
- Cocoa.objc_msgSend (nsImage, Cocoa.S_lockFocus);
- int imageContext = Cocoa.objc_msgSend (Cocoa.C_NSGraphicsContext, Cocoa.S_currentContext);
- imageContext = Cocoa.objc_msgSend (imageContext, Cocoa.S_graphicsPort);
- OS.CGContextDrawImage (imageContext, rect, image.handle);
- Cocoa.objc_msgSend (nsImage, Cocoa.S_unlockFocus);
- }
- Cocoa.objc_msgSend (view, Cocoa.S_setImage, nsImage);
- float width = image != null && visible ? OS.CGImageGetWidth (image.handle) + BORDER : 0;
- Cocoa.objc_msgSend (handle, Cocoa.S_setLength, width);
-}
-
-/**
- * Sets the receiver's tool tip to the argument, which
- * may be null indicating that no tool tip should be shown.
- *
- * @param toolTip the new tool tip (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setToolTip (ToolTip toolTip) {
- checkWidget ();
- ToolTip oldTip = this.toolTip, newTip = toolTip;
- if (oldTip != null) oldTip.item = null;
- this.toolTip = newTip;
- if (newTip != null) newTip.item = this;
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget ();
- toolTipText = string;
- _setToolTipText (string);
-}
-
-void _setToolTipText (String string) {
- int ptr = 0;
- if (string != null) {
- char[] chars = new char [string.length ()];
- string.getChars(0, chars.length, chars, 0);
- ptr = OS.CFStringCreateWithCharacters (0, chars, chars.length);
- }
- Cocoa.objc_msgSend (view, Cocoa.S_setToolTip, ptr);
- if (ptr != 0) OS.CFRelease (ptr);
-}
-
-/**
- * Makes the receiver visible if the argument is <code>true</code>,
- * and makes it invisible otherwise.
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- if (this.visible == visible) return;
- if (visible) {
- sendEvent (SWT.Show);
- if (isDisposed ()) return;
- }
- this.visible = visible;
- float width = image != null && visible ? OS.CGImageGetWidth (image.handle) + BORDER : 0;
- Cocoa.objc_msgSend (handle, Cocoa.S_setLength, width);
- if (!visible) sendEvent (SWT.Hide);
-}
-
-void showMenu () {
- _setToolTipText (null);
- sendEvent (SWT.MenuDetect);
- if (isDisposed ()) return;
- display.runPopups ();
- if (isDisposed ()) return;
- _setToolTipText (toolTipText);
-}
-
-int trayItemProc (int target, int userData, int selector, int arg0) {
- switch (selector) {
- case 0: {
- int mask = Cocoa.objc_msgSend (arg0, Cocoa.S_modifierFlags) & Cocoa.NSDeviceIndependentModifierFlagsMask;
- if (mask == Cocoa.NSControlKeyMask) {
- showMenu ();
- } else {
- highlight = true;
- Cocoa.objc_msgSend (view, Cocoa.S_setNeedsDisplay, 1);
- int clickCount = Cocoa.objc_msgSend (arg0, Cocoa.S_clickCount);
- postEvent (clickCount == 2 ? SWT.DefaultSelection : SWT.Selection);
- }
- break;
- }
- case 1: {
- highlight = false;
- Cocoa.objc_msgSend (view, Cocoa.S_setNeedsDisplay, 1);
- break;
- }
- case 2: {
- showMenu ();
- break;
- }
- case 3: {
- NSRect rect = new NSRect ();
- Cocoa.memcpy (rect, arg0, NSRect.sizeof);
- Cocoa.objc_msgSend (handle, Cocoa.S_drawStatusBarBackgroundInRect_withHighlight, rect, highlight ? 1 : 0);
- }
- }
- return 0;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tree.java
deleted file mode 100644
index a893167279..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tree.java
+++ /dev/null
@@ -1,3735 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.CFRange;
-import org.eclipse.swt.internal.carbon.DataBrowserAccessibilityItemInfo;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.DataBrowserCallbacks;
-import org.eclipse.swt.internal.carbon.DataBrowserCustomCallbacks;
-import org.eclipse.swt.internal.carbon.DataBrowserListViewColumnDesc;
-import org.eclipse.swt.internal.carbon.DataBrowserListViewHeaderDesc;
-import org.eclipse.swt.internal.carbon.HMHelpContentRec;
-import org.eclipse.swt.internal.carbon.Rect;
-import org.eclipse.swt.internal.carbon.CGPoint;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide a selectable user interface object
- * that displays a hierarchy of items and issues notification when an
- * item in the hierarchy is selected.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TreeItem</code>.
- * </p><p>
- * Style <code>VIRTUAL</code> is used to create a <code>Tree</code> whose
- * <code>TreeItem</code>s are to be populated by the client on an on-demand basis
- * instead of up-front. This can provide significant performance improvements for
- * trees that are very large or for which <code>TreeItem</code> population is
- * expensive (for example, retrieving values from an external source).
- * </p><p>
- * Here is an example of using a <code>Tree</code> with style <code>VIRTUAL</code>:
- * <code><pre>
- * final Tree tree = new Tree(parent, SWT.VIRTUAL | SWT.BORDER);
- * tree.setItemCount(20);
- * tree.addListener(SWT.SetData, new Listener() {
- * public void handleEvent(Event event) {
- * TreeItem item = (TreeItem)event.item;
- * TreeItem parentItem = item.getParentItem();
- * String text = null;
- * if (parentItem == null) {
- * text = "node " + tree.indexOf(item);
- * } else {
- * text = parentItem.getText() + " - " + parentItem.indexOf(item);
- * }
- * item.setText(text);
- * System.out.println(text);
- * item.setItemCount(10);
- * }
- * });
- * </pre></code>
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not normally make sense to add <code>Control</code> children to
- * it, or set a layout on it, unless implementing something like a cell
- * editor.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, VIRTUAL, NO_SCROLL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection, Collapse, Expand, SetData, MeasureItem, EraseItem, PaintItem</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles SINGLE and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Tree extends Composite {
- TreeItem [] items;
- TreeColumn [] columns;
- TreeColumn sortColumn;
- int [] childIds;
- GC paintGC;
- int sortDirection;
- int columnCount, column_id, idCount, anchorFirst, anchorLast, savedAnchor, headerHeight;
- boolean ignoreRedraw, ignoreSelect, wasSelected, ignoreExpand, wasExpanded, inClearAll, drawBackground;
- Rectangle imageBounds;
- TreeItem showItem;
- TreeItem insertItem;
- boolean insertBefore;
- int lastHittest, lastHittestColumn, visibleCount;
- static final int CHECK_COLUMN_ID = 1024;
- static final int COLUMN_ID = 1025;
- static final int GRID_WIDTH = 1;
- static final int ICON_AND_TEXT_GAP = 4;
- static final int CELL_CONTENT_INSET = 12;
- static final int BORDER_INSET = 1;
- static final int DISCLOSURE_COLUMN_EDGE_INSET = 8;
- static final int DISCLOSURE_COLUMN_LEVEL_INDENT = 24;
- static final int DISCLOSURE_TRIANGLE_AND_CONTENT_GAP = 8;
- static final String [] AX_ATTRIBUTES = {
- OS.kAXTitleAttribute,
- };
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#CHECK
- * @see SWT#FULL_SELECTION
- * @see SWT#VIRTUAL
- * @see SWT#NO_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Tree (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-void _addListener (int eventType, Listener listener) {
- super._addListener (eventType, listener);
- for (int i = 0; i < items.length; i++) {
- if (items [i] != null) items [i].width = -1;
- }
-}
-
-int _getId () {
- return _getIds (1) [0];
-}
-
-int [] _getIds (int count) {
- int [] newIds = new int [count];
- int index = 0;
- if ((style & SWT.VIRTUAL) == 0) {
- for (int i=0; i<items.length; i++) {
- if (items [i] == null) {
- newIds [index++] = i + 1;
- if (index == count) return newIds;
- }
- }
- int next = items.length;
- while (index < count) {
- newIds [index++] = next + 1;
- next++;
- }
- return newIds;
- }
-
- boolean [] reserved = new boolean [items.length];
- if (childIds != null) {
- for (int i=0; i<childIds.length; i++) {
- int usedId = childIds [i];
- if (usedId != 0) {
- if (usedId > reserved.length) {
- boolean [] newReserved = new boolean [usedId + 4];
- System.arraycopy (reserved, 0, newReserved, 0, reserved.length);
- reserved = newReserved;
- }
- reserved [usedId - 1] = true;
- }
- }
- }
- for (int i=0; i<items.length; i++) {
- if (items [i] != null) {
- reserved [i] = true;
- int [] ids = items [i].childIds;
- if (ids != null) {
- for (int j=0; j<ids.length; j++) {
- int usedId = ids [j];
- if (usedId != 0) {
- if (usedId > reserved.length) {
- boolean [] newReserved = new boolean [usedId + 4];
- System.arraycopy (reserved, 0, newReserved, 0, reserved.length);
- reserved = newReserved;
- }
- reserved [usedId - 1] = true;
- }
- }
- }
- }
- }
- for (int i=0; i<reserved.length; i++) {
- if (!reserved [i]) {
- newIds [index++] = i + 1;
- if (index == count) return newIds;
- }
- }
- int next = reserved.length;
- while (index < count) {
- newIds [index++] = next + 1;
- next++;
- }
- return newIds;
-}
-
-TreeItem _getItem (int id, boolean create) {
- if (id < 1) return null;
- TreeItem item = id - 1 < items.length ? items [id - 1] : null;
- if (item != null || (style & SWT.VIRTUAL) == 0 || !create) return item;
- if (childIds != null) {
- for (int i=0; i<childIds.length; i++) {
- if (childIds [i] == id) {
- return _getItem (null, i);
- }
- }
- }
- for (int i=0; i<items.length; i++) {
- TreeItem parentItem = items [i];
- if (parentItem != null && parentItem.childIds != null) {
- int [] ids = parentItem.childIds;
- for (int j=0; j<ids.length; j++) {
- if (ids [j] == id) {
- return _getItem (parentItem, j);
- }
- }
- }
- }
- return null;
-}
-
-TreeItem _getItem (TreeItem parentItem, int index) {
- int count = getItemCount (parentItem);
- if (index < 0 || index >= count) return null;
- int [] ids = parentItem == null ? childIds : parentItem.childIds;
- int id = ids [index];
- if (id == 0) {
- id = _getId ();
- ids [index] = id;
- }
- if (id > items.length) {
- TreeItem [] newItems = new TreeItem [id + 4];
- System.arraycopy(items, 0, newItems, 0, items.length);
- items = newItems;
- }
- TreeItem item = items [id - 1];
- if (item != null || (style & SWT.VIRTUAL) == 0) return item;
- item = new TreeItem (this, parentItem, SWT.NONE, index, false);
- item.id = id;
- items [id - 1] = item;
- return item;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * If the receiver has the <code>SWT.CHECK</code> style and the check selection changes,
- * the event object detail field contains the value <code>SWT.CHECK</code>.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * The item field of the event object is valid for default selection, but the detail field is not used.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an item in the receiver is expanded or collapsed
- * by sending it one of the messages defined in the <code>TreeListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TreeListener
- * @see #removeTreeListener
- */
-public void addTreeListener(TreeListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Expand, typedListener);
- addListener (SWT.Collapse, typedListener);
-}
-
-int calculateWidth (int [] ids, GC gc, boolean recurse, int level, int levelIndent) {
- if (ids == null) return 0;
- int width = 0;
- for (int i=0; i<ids.length; i++) {
- TreeItem item = _getItem (ids [i], false);
- if (item != null) {
- int itemWidth = item.calculateWidth (0, gc);
- itemWidth += level * levelIndent;
- width = Math.max (width, itemWidth);
- if (recurse && item._getExpanded ()) {
- width = Math.max (width, calculateWidth (item.childIds, gc, recurse, level + 1, levelIndent));
- }
- }
- }
- return width;
-}
-
-int callPaintEventHandler (int control, int damageRgn, int visibleRgn, int theEvent, int nextHandler) {
- /*
- * Feature in the Macintosh. The draw item proc is not called if the column width
- * is zero. This means that the SWT.MeasureItem listener is not called and the column
- * does not get wider ever. The fix is to change the column width to one.
- */
- if (columnCount == 0 && (hooks (SWT.MeasureItem) || hooks (SWT.EraseItem) || hooks (SWT.PaintItem))) {
- short [] width = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (handle, column_id, width);
- if (width [0] == 0) {
- OS.SetDataBrowserTableViewNamedColumnWidth (handle, column_id, (short) 1);
- }
- }
- GC currentGC = paintGC;
- if (currentGC == null) {
- GCData data = new GCData ();
- data.paintEvent = theEvent;
- data.visibleRgn = visibleRgn;
- paintGC = GC.carbon_new (this, data);
- }
- drawBackground = findBackgroundControl () != null;
- int result = super.callPaintEventHandler (control, damageRgn, visibleRgn, theEvent, nextHandler);
- if (getItemCount () == 0 && drawBackground) {
- drawBackground = false;
- Rectangle rect = getClientArea ();
- int headerHeight = getHeaderHeight ();
- rect.y += headerHeight;
- rect.height -= headerHeight;
- fillBackground (handle, paintGC.handle, rect);
- }
- if (insertItem != null && !insertItem.isDisposed()) {
- Rectangle itemRect = insertItem.getImageBounds(0).union(insertItem.getBounds());
- Rectangle clientRect = getClientArea();
- int x = clientRect.x + clientRect.width;
- int posY = insertBefore ? itemRect.y : itemRect.y + itemRect.height - 1;
- paintGC.drawLine(itemRect.x, posY, x, posY);
- }
- if (currentGC == null) {
- paintGC.dispose ();
- paintGC = null;
- }
- return result;
-}
-
-boolean checkData (TreeItem item, boolean redraw) {
- if (item.cached) return true;
- if ((style & SWT.VIRTUAL) != 0) {
- item.cached = true;
- Event event = new Event ();
- TreeItem parentItem = item.getParentItem ();
- event.item = item;
- event.index = parentItem == null ? indexOf (item) : parentItem.indexOf (item);
- ignoreRedraw = true;
- sendEvent (SWT.SetData, event);
- //widget could be disposed at this point
- ignoreRedraw = false;
- if (isDisposed () || item.isDisposed ()) return false;
- if (redraw) {
- if (!setScrollWidth (item)) item.redraw (OS.kDataBrowserNoItem);
- }
- }
- return true;
-}
-
-static int checkStyle (int style) {
- /*
- * Feature in Windows. Even when WS_HSCROLL or
- * WS_VSCROLL is not specified, Windows creates
- * trees and tables with scroll bars. The fix
- * is to set H_SCROLL and V_SCROLL.
- *
- * NOTE: This code appears on all platforms so that
- * applications have consistent scroll bar behavior.
- */
- if ((style & SWT.NO_SCROLL) == 0) {
- style |= SWT.H_SCROLL | SWT.V_SCROLL;
- }
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void clear (TreeItem parentItem, int index, boolean all) {
- int [] ids = parentItem == null ? childIds : parentItem.childIds;
- TreeItem item = _getItem (ids [index], false);
- if (item != null) {
- item.clear();
- if (all) {
- clearAll (item, true);
- } else {
- int container = parentItem == null ? OS.kDataBrowserNoItem : parentItem.id;
- OS.UpdateDataBrowserItems (handle, container, 1, new int[] {item.id}, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem);
- }
- }
-}
-
-void clearAll (TreeItem parentItem, boolean all) {
- boolean update = !inClearAll;
- int count = getItemCount (parentItem);
- if (count == 0) return;
- inClearAll = true;
- int [] ids = parentItem == null ? childIds : parentItem.childIds;
- for (int i=0; i<count; i++) {
- TreeItem item = _getItem (ids [i], false);
- if (item != null) {
- item.clear ();
- if (all) clearAll (item, true);
- }
- }
- if (update) {
- OS.UpdateDataBrowserItems (handle, 0, 0, null, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem);
- inClearAll = false;
- }
-}
-
-/**
- * Clears the item at the given zero-relative index in the receiver.
- * The text, icon and other attributes of the item are set to the default
- * value. If the tree was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param index the index of the item to clear
- * @param all <code>true</code> if all child items of the indexed item should be
- * cleared recursively, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clear (int index, boolean all) {
- checkWidget ();
- int count = getItemCount (null);
- if (index < 0 || index >= count) error (SWT.ERROR_INVALID_RANGE);
- clear (null, index, all);
-}
-
-/**
- * Clears all the items in the receiver. The text, icon and other
- * attributes of the items are set to their default values. If the
- * tree was created with the <code>SWT.VIRTUAL</code> style, these
- * attributes are requested again as needed.
- *
- * @param all <code>true</code> if all child items should be cleared
- * recursively, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clearAll (boolean all) {
- checkWidget ();
- clearAll (null, all);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0;
- if (wHint == SWT.DEFAULT) {
- if (columnCount != 0) {
- for (int i=0; i<columnCount; i++) {
- width += columns [i].getWidth ();
- }
- } else {
- int levelIndent = DISCLOSURE_COLUMN_LEVEL_INDENT;
- if (OS.VERSION >= 0x1040) {
- float [] metric = new float [1];
- OS.DataBrowserGetMetric (handle, OS.kDataBrowserMetricDisclosureColumnPerDepthGap, null, metric);
- levelIndent = (int) metric [0];
- }
- GC gc = new GC (this);
- width = calculateWidth (childIds, gc, true, 0, levelIndent);
- gc.dispose ();
- width += getInsetWidth (column_id, true);
- }
- if ((style & SWT.CHECK) != 0) width += getCheckColumnWidth ();
- } else {
- width = wHint;
- }
- if (width <= 0) width = DEFAULT_WIDTH;
- int height = 0;
- if (hHint == SWT.DEFAULT) {
- height = visibleCount * getItemHeight () + getHeaderHeight();
- } else {
- height = hHint;
- }
- if (height <= 0) height = DEFAULT_HEIGHT;
- Rectangle rect = computeTrim (0, 0, width, height);
- return new Point (rect.width, rect.height);
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- int border = getBorderWidth ();
- Rect rect = new Rect ();
- OS.GetDataBrowserScrollBarInset (handle, rect);
- x -= rect.left + border;
- y -= rect.top + border;
- width += rect.left + rect.right + border + border;
- height += rect.top + rect.bottom + border + border;
- return new Rectangle (x, y, width, height);
-}
-
-boolean contains(int shellX, int shellY) {
- CGPoint pt = new CGPoint ();
- int [] contentView = new int [1];
- OS.HIViewFindByID (OS.HIViewGetRoot (OS.GetControlOwner (handle)), OS.kHIViewWindowContentID (), contentView);
- OS.HIViewConvertPoint (pt, handle, contentView [0]);
- int x = shellX - (int) pt.x;
- int y = shellY - (int) pt.y;
- if (y < getHeaderHeight ()) return false;
- return getClientArea ().contains (x, y);
-}
-
-void createHandle () {
- column_id = COLUMN_ID;
- int [] outControl = new int [1];
- int window = OS.GetControlOwner (parent.handle);
- OS.CreateDataBrowserControl (window, null, OS.kDataBrowserListView, outControl);
- OS.SetAutomaticControlDragTrackingEnabledForWindow (window, true);
- if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
- handle = outControl [0];
- if (!drawFocusRing ()) {
- OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlDataBrowserIncludesFrameAndFocusTag, 1, new byte[] {0});
- }
- int selectionFlags = (style & SWT.SINGLE) != 0 ? OS.kDataBrowserSelectOnlyOne | OS.kDataBrowserNeverEmptySelectionSet : OS.kDataBrowserCmdTogglesSelection;
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags);
- short [] height = new short [1];
- OS.GetDataBrowserListViewHeaderBtnHeight (handle, height);
- headerHeight = height [0];
- OS.SetDataBrowserListViewHeaderBtnHeight (handle, (short) 0);
- OS.SetDataBrowserHasScrollBars (handle, (style & SWT.H_SCROLL) != 0, (style & SWT.V_SCROLL) != 0);
- if (OS.VERSION >= 0x1040) {
- int inset = 4;
- OS.DataBrowserSetMetric (handle, OS.kDataBrowserMetricCellContentInset, false, inset);
- OS.DataBrowserSetMetric (handle, OS.kDataBrowserMetricDisclosureColumnEdgeInset, false, inset);
- OS.DataBrowserSetMetric (handle, OS.kDataBrowserMetricDisclosureTriangleAndContentGap, false, inset);
- OS.DataBrowserSetMetric (handle, OS.kDataBrowserMetricIconAndTextGap, false, inset);
- }
- int position = 0;
- if ((style & SWT.CHECK) != 0) {
- DataBrowserListViewColumnDesc checkColumn = new DataBrowserListViewColumnDesc ();
- checkColumn.headerBtnDesc_version = OS.kDataBrowserListViewLatestHeaderDesc;
- checkColumn.propertyDesc_propertyID = CHECK_COLUMN_ID;
- checkColumn.propertyDesc_propertyType = OS.kDataBrowserCheckboxType;
- checkColumn.propertyDesc_propertyFlags = OS.kDataBrowserPropertyIsMutable;
- int checkWidth = getCheckColumnWidth ();
- checkColumn.headerBtnDesc_minimumWidth = (short) checkWidth;
- checkColumn.headerBtnDesc_maximumWidth = (short) checkWidth;
- checkColumn.headerBtnDesc_initialOrder = (short) OS.kDataBrowserOrderIncreasing;
- OS.AddDataBrowserListViewColumn (handle, checkColumn, position++);
- }
- DataBrowserListViewColumnDesc column = new DataBrowserListViewColumnDesc ();
- column.headerBtnDesc_version = OS.kDataBrowserListViewLatestHeaderDesc;
- column.propertyDesc_propertyID = column_id;
- column.propertyDesc_propertyType = OS.kDataBrowserCustomType;
- column.propertyDesc_propertyFlags = OS.kDataBrowserListViewSelectionColumn | OS.kDataBrowserDefaultPropertyFlags | OS.kDataBrowserListViewSortableColumn;
- column.headerBtnDesc_maximumWidth = 0x7fff;
- column.headerBtnDesc_initialOrder = (short) OS.kDataBrowserOrderIncreasing;
- OS.AddDataBrowserListViewColumn (handle, column, position);
- OS.SetDataBrowserListViewDisclosureColumn (handle, column_id, false);
- OS.SetDataBrowserTableViewNamedColumnWidth (handle, column_id, (short) 0);
-
- /*
- * Feature in the Macintosh. Scroll bars are not created until
- * the data browser needs to draw them. The fix is to force the scroll
- * bars to be created by temporarily giving the widget a size, drawing
- * it on a offscreen buffer to avoid flashes and then restoring it to
- * size zero.
- */
- if (OS.VERSION < 0x1040) {
- OS.HIViewSetDrawingEnabled (handle, false);
- int size = 50;
- Rect rect = new Rect ();
- rect.right = rect.bottom = (short) size;
- OS.SetControlBounds (handle, rect);
- int bpl = size * 4;
- int [] gWorld = new int [1];
- int data = OS.NewPtr (bpl * size);
- OS.NewGWorldFromPtr (gWorld, OS.k32ARGBPixelFormat, rect, 0, 0, 0, data, bpl);
- int [] curPort = new int [1];
- int [] curGWorld = new int [1];
- OS.GetGWorld (curPort, curGWorld);
- OS.SetGWorld (gWorld [0], curGWorld [0]);
- OS.DrawControlInCurrentPort (handle);
- OS.SetGWorld (curPort [0], curGWorld [0]);
- OS.DisposeGWorld (gWorld [0]);
- OS.DisposePtr (data);
- rect.right = rect.bottom = (short) 0;
- OS.SetControlBounds (handle, rect);
- OS.HIViewSetDrawingEnabled (handle, true);
- }
-}
-
-void createItem (TreeColumn column, int index) {
- if (!(0 <= index && index <= columnCount)) error (SWT.ERROR_INVALID_RANGE);
- if (index == 0) {
- // first column must be left aligned
- column.style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- column.style |= SWT.LEFT;
- }
- column.id = column_id + idCount++;
- int position = index + ((style & SWT.CHECK) != 0 ? 1 : 0);
- if (columnCount != 0) {
- DataBrowserListViewColumnDesc desc = new DataBrowserListViewColumnDesc ();
- desc.headerBtnDesc_version = OS.kDataBrowserListViewLatestHeaderDesc;
- desc.propertyDesc_propertyID = column.id;
- desc.propertyDesc_propertyType = OS.kDataBrowserCustomType;
- desc.propertyDesc_propertyFlags = OS.kDataBrowserListViewSelectionColumn | OS.kDataBrowserDefaultPropertyFlags | OS.kDataBrowserListViewSortableColumn;
- desc.headerBtnDesc_maximumWidth = 0x7fff;
- desc.headerBtnDesc_initialOrder = OS.kDataBrowserOrderIncreasing;
- desc.headerBtnDesc_btnFontStyle_just = OS.teFlushLeft;
- if ((style & SWT.CENTER) != 0) desc.headerBtnDesc_btnFontStyle_just = OS.teCenter;
- if ((style & SWT.RIGHT) != 0) desc.headerBtnDesc_btnFontStyle_just = OS.teFlushRight;
- desc.headerBtnDesc_btnFontStyle_flags |= OS.kControlUseJustMask;
- OS.AddDataBrowserListViewColumn (handle, desc, position);
- OS.SetDataBrowserTableViewNamedColumnWidth (handle, column.id, (short)0);
-
- if (index == 0) {
- int [] disclosure = new int [1];
- boolean [] expandableRows = new boolean [1];
- OS.GetDataBrowserListViewDisclosureColumn (handle, disclosure, expandableRows);
- OS.SetDataBrowserListViewDisclosureColumn (handle, column.id, expandableRows [0]);
- }
- }
- if (columnCount == columns.length) {
- TreeColumn [] newColumns = new TreeColumn [columnCount + 4];
- System.arraycopy (columns, 0, newColumns, 0, columns.length);
- columns = newColumns;
- }
- System.arraycopy (columns, index, columns, index + 1, columnCount++ - index);
- columns [index] = column;
- if (columnCount > 1) {
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null) {
- String [] strings = item.strings;
- if (strings != null) {
- String [] temp = new String [columnCount];
- System.arraycopy (strings, 0, temp, 0, index);
- System.arraycopy (strings, index, temp, index+1, columnCount-index-1);
- temp [index] = "";
- item.strings = temp;
- }
- if (index == 0) item.text = "";
- Image [] images = item.images;
- if (images != null) {
- Image [] temp = new Image [columnCount];
- System.arraycopy (images, 0, temp, 0, index);
- System.arraycopy (images, index, temp, index+1, columnCount-index-1);
- item.images = temp;
- }
- if (index == 0) item.image = null;
- Color [] cellBackground = item.cellBackground;
- if (cellBackground != null) {
- Color [] temp = new Color [columnCount];
- System.arraycopy (cellBackground, 0, temp, 0, index);
- System.arraycopy (cellBackground, index, temp, index+1, columnCount-index-1);
- item.cellBackground = temp;
- }
- Color [] cellForeground = item.cellForeground;
- if (cellForeground != null) {
- Color [] temp = new Color [columnCount];
- System.arraycopy (cellForeground, 0, temp, 0, index);
- System.arraycopy (cellForeground, index, temp, index+1, columnCount-index-1);
- item.cellForeground = temp;
- }
- Font [] cellFont = item.cellFont;
- if (cellFont != null) {
- Font [] temp = new Font [columnCount];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index, temp, index+1, columnCount-index-1);
- item.cellFont = temp;
- }
- }
- }
- }
-}
-
-void createItem (TreeItem item, TreeItem parentItem, int index) {
- int count = getItemCount (parentItem);
- if (index == -1) index = count;
- if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
- int id = _getId ();
- if (id > items.length) {
- TreeItem [] newItems = new TreeItem [id + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- item.id = id;
- items [id - 1] = item;
- int [] ids = parentItem == null ? childIds : parentItem.childIds;
- if (ids == null || count + 1 > ids.length) {
- int [] newIds = new int [count + 4];
- if (ids != null) System.arraycopy (ids, 0, newIds, 0, ids.length);
- ids = newIds;
- if (parentItem == null) {
- childIds = ids;
- } else {
- parentItem.childIds = ids;
- }
- }
- System.arraycopy (ids, index, ids, index + 1, ids.length - index - 1);
- ids [index] = id;
- if (parentItem != null) parentItem.itemCount++;
- if (parentItem == null || (parentItem.getExpanded ())) {
- int parentID = parentItem == null ? OS.kDataBrowserNoItem : parentItem.id;
- if (OS.AddDataBrowserItems (handle, parentID, 1, new int [] {item.id}, OS.kDataBrowserItemNoProperty) != OS.noErr) {
- items [id - 1] = null;
- System.arraycopy (ids, index+1, ids, index, ids.length - index - 1);
- error (SWT.ERROR_ITEM_NOT_ADDED);
- }
- visibleCount++;
- } else {
- /*
- * Bug in the Macintosh. When the first child of a tree item is
- * added and the parent is not expanded, the parent does not
- * redraw to show the expander. The fix is to force a redraw.
- */
- if (parentItem != null && parentItem.itemCount == 1) parentItem.redraw (OS.kDataBrowserNoItem);
- }
-}
-
-ScrollBar createScrollBar (int style) {
- return createStandardBar (style);
-}
-
-void createWidget () {
- super.createWidget ();
- items = new TreeItem [4];
- columns = new TreeColumn [4];
- if (OS.VERSION >= 0x1050) {
- OS.DataBrowserChangeAttributes (handle, OS.kDataBrowserAttributeAutoHideScrollBars, 0);
- }
-}
-
-Color defaultBackground () {
- return display.getSystemColor (SWT.COLOR_LIST_BACKGROUND);
-}
-
-Color defaultForeground () {
- return display.getSystemColor (SWT.COLOR_LIST_FOREGROUND);
-}
-
-int defaultThemeFont () {
- if (display.smallFonts) return OS.kThemeSmallSystemFont;
- return OS.kThemeViewsFont;
-}
-
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll () {
- checkWidget ();
- ignoreSelect = true;
- /*
- * Bug in the Macintosh. When the DataBroswer selection flags includes
- * both kDataBrowserNeverEmptySelectionSet and kDataBrowserSelectOnlyOne,
- * two items are selected when SetDataBrowserSelectedItems() is called
- * with kDataBrowserItemsAssign to assign a new seletion despite the fact
- * that kDataBrowserSelectOnlyOne was specified. The fix is to save and
- * restore kDataBrowserNeverEmptySelectionSet around each call to
- * SetDataBrowserSelectedItems().
- */
- int [] selectionFlags = null;
- if ((style & SWT.SINGLE) != 0) {
- selectionFlags = new int [1];
- OS.GetDataBrowserSelectionFlags (handle, selectionFlags);
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0] & ~OS.kDataBrowserNeverEmptySelectionSet);
- }
- OS.SetDataBrowserSelectedItems (handle, 0, null, OS.kDataBrowserItemsRemove);
- if ((style & SWT.SINGLE) != 0) {
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0]);
- }
- ignoreSelect = false;
-}
-
-/**
- * Deselects an item in the receiver. If the item was already
- * deselected, it remains deselected.
- *
- * @param item the item to be deselected
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void deselect (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- ignoreSelect = true;
- /*
- * Bug in the Macintosh. When the DataBroswer selection flags includes
- * both kDataBrowserNeverEmptySelectionSet and kDataBrowserSelectOnlyOne,
- * two items are selected when SetDataBrowserSelectedItems() is called
- * with kDataBrowserItemsAssign to assign a new seletion despite the fact
- * that kDataBrowserSelectOnlyOne was specified. The fix is to save and
- * restore kDataBrowserNeverEmptySelectionSet around each call to
- * SetDataBrowserSelectedItems().
- */
- int [] selectionFlags = null;
- if ((style & SWT.SINGLE) != 0) {
- selectionFlags = new int [1];
- OS.GetDataBrowserSelectionFlags (handle, selectionFlags);
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0] & ~OS.kDataBrowserNeverEmptySelectionSet);
- }
- OS.SetDataBrowserSelectedItems (handle, 1, new int [] {item.id}, OS.kDataBrowserItemsRemove);
- if ((style & SWT.SINGLE) != 0) {
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0]);
- }
- ignoreSelect = false;
-}
-
-
-void destroyItem (TreeColumn column) {
- int index = 0;
- while (index < columnCount) {
- if (columns [index] == column) break;
- index++;
- }
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null) {
- if (columnCount <= 1) {
- item.strings = null;
- item.images = null;
- item.cellBackground = null;
- item.cellForeground = null;
- item.cellFont = null;
- } else {
- if (item.strings != null) {
- String [] strings = item.strings;
- if (index == 0) {
- item.text = strings [1] != null ? strings [1] : "";
- }
- String [] temp = new String [columnCount - 1];
- System.arraycopy (strings, 0, temp, 0, index);
- System.arraycopy (strings, index + 1, temp, index, columnCount - 1 - index);
- item.strings = temp;
- } else {
- if (index == 0) item.text = "";
- }
- if (item.images != null) {
- Image [] images = item.images;
- if (index == 0) item.image = images [1];
- Image [] temp = new Image [columnCount - 1];
- System.arraycopy (images, 0, temp, 0, index);
- System.arraycopy (images, index + 1, temp, index, columnCount - 1 - index);
- item.images = temp;
- } else {
- if (index == 0) item.image = null;
- }
- if (item.cellBackground != null) {
- Color [] cellBackground = item.cellBackground;
- Color [] temp = new Color [columnCount - 1];
- System.arraycopy (cellBackground, 0, temp, 0, index);
- System.arraycopy (cellBackground, index + 1, temp, index, columnCount - 1 - index);
- item.cellBackground = temp;
- }
- if (item.cellForeground != null) {
- Color [] cellForeground = item.cellForeground;
- Color [] temp = new Color [columnCount - 1];
- System.arraycopy (cellForeground, 0, temp, 0, index);
- System.arraycopy (cellForeground, index + 1, temp, index, columnCount - 1 - index);
- item.cellForeground = temp;
- }
- if (item.cellFont != null) {
- Font [] cellFont = item.cellFont;
- Font [] temp = new Font [columnCount - 1];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index + 1, temp, index, columnCount - 1 - index);
- item.cellFont = temp;
- }
- }
- }
- }
- if (columnCount == 1) {
- column_id = column.id; idCount = 0;
- DataBrowserListViewHeaderDesc desc = new DataBrowserListViewHeaderDesc ();
- desc.version = OS.kDataBrowserListViewLatestHeaderDesc;
- short [] width = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (handle, column_id, width);
- desc.minimumWidth = desc.maximumWidth = width [0];
- int str = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, null, 0);
- desc.titleString = str;
- OS.SetDataBrowserListViewHeaderDesc (handle, column_id, desc);
- OS.CFRelease (str);
- } else {
- int [] disclosure = new int [1];
- boolean [] expandableRows = new boolean [1];
- OS.GetDataBrowserListViewDisclosureColumn (handle, disclosure, expandableRows);
- if (disclosure [0] == column.id) {
- TreeColumn firstColumn = columns [1];
- firstColumn.style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- firstColumn.style |= SWT.LEFT;
- firstColumn.updateHeader();
- OS.SetDataBrowserListViewDisclosureColumn (handle, firstColumn.id, expandableRows [0]);
- }
- if (OS.RemoveDataBrowserTableViewColumn (handle, column.id) != OS.noErr) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- }
- System.arraycopy (columns, index + 1, columns, index, --columnCount - index);
- columns [columnCount] = null;
- for (int i=index; i<columnCount; i++) {
- columns [i].sendEvent (SWT.Move);
- }
-}
-
-void destroyItem (TreeItem item) {
- TreeItem parentItem = item.parentItem;
- if (parentItem == null || parentItem.getExpanded ()) {
- int oldAnchor = savedAnchor;
- int [] index = new int [1];
- if (OS.GetDataBrowserTableViewItemRow (handle, item.id, index) != OS.noErr) {
- index = null;
- }
- int parentID = parentItem == null ? OS.kDataBrowserNoItem : parentItem.id;
- ignoreExpand = true;
- if (OS.RemoveDataBrowserItems (handle, parentID, 1, new int [] {item.id}, 0) != OS.noErr) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- visibleCount--;
- ignoreExpand = false;
- if (savedAnchor != 0 && savedAnchor != oldAnchor) {
- if (index != null) {
- int [] itemId = new int [1];
- if (OS.GetDataBrowserTableViewItemID (handle, index [0], itemId) == OS.noErr) {
- savedAnchor = itemId [0];
- }
- }
- }
- }
- /*
- * Bug in the Macintosh. When the last child of a tree item is
- * removed and the parent is not expanded, the parent does not
- * redraw to remove the expander. The fix is to force a redraw.
- */
- if (parentItem != null && !parentItem.getExpanded () && parentItem.itemCount > 0) {
- parentItem.redraw (OS.kDataBrowserNoItem);
- }
- //TEMPORARY CODE
- releaseItem (item, false);
- setScrollWidth (true);
- fixScrollBar ();
-}
-
-void destroyScrollBar (ScrollBar bar) {
- if ((bar.style & SWT.H_SCROLL) != 0) style &= ~SWT.H_SCROLL;
- if ((bar.style & SWT.V_SCROLL) != 0) style &= ~SWT.V_SCROLL;
- OS.SetDataBrowserHasScrollBars (handle, (style & SWT.H_SCROLL) != 0, (style & SWT.V_SCROLL) != 0);
-}
-
-int drawItemProc (int browser, int id, int property, int itemState, int theRect, int gdDepth, int colorDevice) {
- if (id < 0) return OS.noErr;
- int columnIndex = 0;
- if (columnCount > 0) {
- for (columnIndex=0; columnIndex<columnCount; columnIndex++) {
- if (columns [columnIndex].id == property) break;
- }
- if (columnIndex == columnCount) return OS.noErr;
- }
- Rect rect = new Rect ();
- TreeItem item = _getItem (id, true);
- if ((style & SWT.VIRTUAL) != 0) {
- if (!item.cached) {
- if (!checkData (item, false)) return OS.noErr;
- if (setScrollWidth (item)) {
- if (OS.GetDataBrowserItemPartBounds (handle, id, property, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- int x = rect.left;
- int y = rect.top;
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- redrawWidget (handle, x, y, width, height, false);
- }
- return OS.noErr;
- }
- }
- }
- OS.memmove (rect, theRect, Rect.sizeof);
- int x = rect.left;
- int y = rect.top;
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- GC gc = paintGC;
- if (gc == null) {
- GCData data = new GCData ();
- int [] port = new int [1];
- OS.GetPort (port);
- data.port = port [0];
- gc = GC.carbon_new (this, data);
- }
- OS.GetDataBrowserItemPartBounds (handle, id, property, OS.kDataBrowserPropertyEnclosingPart, rect);
- int gridWidth = getLinesVisible () ? GRID_WIDTH : 0;
- int itemX = rect.left + gridWidth;
- int itemY = rect.top;
- int itemWidth = rect.right - rect.left - gridWidth;
- int itemHeight = rect.bottom - rect.top + 1;
- if (drawBackground) {
- drawBackground = false;
- Region region = new Region (display);
- Rectangle clientArea = getClientArea ();
- int headerHeight = getHeaderHeight ();
- clientArea.y += headerHeight;
- clientArea.height -= headerHeight;
- if (clientArea.height < 0) clientArea.height = 0;
- region.add (clientArea);
- if ((style & SWT.CHECK) != 0 || gridWidth != 0) {
- int rgn = OS.NewRgn();
- if ((style & SWT.CHECK) != 0) {
- if (OS.GetDataBrowserItemPartBounds (handle, id, Table.CHECK_COLUMN_ID, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- OS.SetRectRgn (rgn, (short)rect.left, (short)clientArea.y, (short)(rect.right + gridWidth), (short)(clientArea.y + clientArea.height));
- OS.DiffRgn (region.handle, rgn, region.handle);
- }
- }
- if (gridWidth != 0) {
- if (columnCount == 0) {
- if (OS.GetDataBrowserItemPartBounds (handle, id, Table.COLUMN_ID, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- OS.SetRectRgn (rgn, (short)rect.right, (short)clientArea.y, (short)(rect.right + gridWidth), (short)(clientArea.y + clientArea.height));
- OS.DiffRgn (region.handle, rgn, region.handle);
- }
- } else {
- for (int i = 0; i < columnCount; i++) {
- if (OS.GetDataBrowserItemPartBounds (handle, id, columns[i].id, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- OS.SetRectRgn (rgn, (short)rect.right, (short)clientArea.y, (short)(rect.right + gridWidth), (short)(clientArea.y + clientArea.height));
- OS.DiffRgn (region.handle, rgn, region.handle);
- }
- }
- }
- }
- OS.DisposeRgn (rgn);
- }
- if (region != null) gc.setClipping (region);
- fillBackground (handle, gc.handle, null);
- if (region != null) {
- gc.setClipping ((Rectangle)null);
- region.dispose ();
- }
- }
- OS.CGContextSaveGState (gc.handle);
- int itemRgn = OS.NewRgn ();
- OS.SetRectRgn (itemRgn, (short) itemX, (short) itemY, (short) (itemX + itemWidth), (short) (itemY + itemHeight));
- int clip = OS.NewRgn ();
- OS.GetClip (clip);
- OS.SectRgn (clip, itemRgn, itemRgn);
- OS.DisposeRgn (clip);
- Region region = Region.carbon_new (display, itemRgn);
- Font font = item.getFont (columnIndex);
- Color background = item.getBackground (columnIndex);
- Color foreground = item.getForeground (columnIndex);
- Image image = item.getImage (columnIndex);
- String text = item.getText (columnIndex);
- gc.setClipping (region);
- gc.setFont (font);
- Point extent = gc.stringExtent (text);
- int contentWidth = extent.x;
- Rectangle imageBounds = null;
- int gap = 0;
- if (image != null) {
- gap = getGap ();
- imageBounds = image.getBounds ();
- contentWidth += this.imageBounds.width + gap;
- }
- int paintWidth = contentWidth;
- if (hooks (SWT.MeasureItem)) {
- Event event = new Event ();
- event.item = item;
- event.index = columnIndex;
- event.gc = gc;
- event.width = contentWidth;
- event.height = itemHeight;
- sendEvent (SWT.MeasureItem, event);
- if (itemHeight < event.height) {
- itemHeight = event.height;
- OS.SetDataBrowserTableViewRowHeight (handle, (short) event.height);
- redrawWidget (handle, false);
- }
- if (setScrollWidth (item)) {
- redrawWidget (handle, false);
- }
- contentWidth = event.width;
- gc.setClipping (region);
- gc.setFont (font);
- }
- int drawState = SWT.FOREGROUND;
- if (item.background != null || (item.cellBackground != null && item.cellBackground [columnIndex] != null)) drawState |= SWT.BACKGROUND;
- if ((itemState & (OS.kDataBrowserItemIsSelected | OS.kDataBrowserItemIsDragTarget)) != 0) drawState |= SWT.SELECTED;
- boolean wasSelected = (drawState & SWT.SELECTED) != 0;
- if ((drawState & SWT.SELECTED) != 0 && ((style & SWT.FULL_SELECTION) != 0 || columnIndex == 0)) {
- gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION));
- gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT));
- } else {
- gc.setBackground (background);
- gc.setForeground (foreground);
- }
- if (hooks (SWT.EraseItem)) {
- Event event = new Event ();
- event.item = item;
- event.index = columnIndex;
- event.gc = gc;
- event.x = itemX;
- event.y = itemY;
- event.width = itemWidth;
- event.height = itemHeight;
- event.detail = drawState;
- sendEvent (SWT.EraseItem, event);
- drawState = event.doit ? event.detail : 0;
- gc.setClipping (region);
- gc.setFont (font);
- if ((drawState & SWT.SELECTED) != 0 && ((style & SWT.FULL_SELECTION) != 0 || columnIndex == 0)) {
- gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION));
- gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT));
- } else {
- gc.setBackground (background);
- if (!wasSelected) gc.setForeground (foreground);
- }
- }
- if (columnCount != 0 && columnIndex != 0) {
- TreeColumn column = columns [columnIndex];
- if ((column.style & SWT.CENTER) != 0) x += (width - contentWidth) / 2;
- if ((column.style & SWT.RIGHT) != 0) x += width - contentWidth;
- }
- int stringX = x, imageWidth = 0;
- if (image != null) stringX += imageWidth = this.imageBounds.width + gap;
- if ((drawState & SWT.SELECTED) != 0 && ((style & SWT.FULL_SELECTION) != 0 || columnIndex == 0)) {
- if ((style & SWT.HIDE_SELECTION) == 0 || hasFocus ()) {
- if ((style & SWT.FULL_SELECTION) != 0) {
- gc.fillRectangle (itemX, itemY, itemWidth, itemHeight - 1);
- drawState &= ~SWT.BACKGROUND;
- } else if (columnIndex == 0) {
- gc.fillRectangle (stringX - 1, y, (contentWidth - imageWidth) + 2, itemHeight - 1);
- drawState &= ~SWT.BACKGROUND;
- }
- } else {
- if ((drawState & SWT.BACKGROUND) != 0) gc.setBackground (background);
- }
- }
- if ((drawState & SWT.BACKGROUND) != 0) {
- if (columnCount == 0) {
- gc.fillRectangle (stringX - 1, y, (contentWidth - imageWidth) + 2, itemHeight - 1);
- } else {
- gc.fillRectangle (itemX, itemY, itemWidth, itemHeight);
- }
- }
- if ((drawState & SWT.FOREGROUND) != 0) {
- if (image != null) {
- int imageX = x, imageY = y + (height - this.imageBounds.height) / 2;
- gc.drawImage (image, 0, 0, imageBounds.width, imageBounds.height, imageX, imageY, this.imageBounds.width, this.imageBounds.height);
- }
- gc.drawString (text, stringX, y + (height - extent.y) / 2, true);
- }
- if (hooks (SWT.PaintItem)) {
- Event event = new Event ();
- event.item = item;
- event.index = columnIndex;
- event.gc = gc;
- event.x = x;
- event.y = y;
- event.width = paintWidth;
- event.height = itemHeight;
- event.detail = drawState;
- sendEvent (SWT.PaintItem, event);
- }
- OS.CGContextRestoreGState (gc.handle);
- OS.DisposeRgn (itemRgn);
- if (gc != paintGC) gc.dispose ();
- return OS.noErr;
-}
-
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- /*
- * Bug in the Macintosh. For some reason, the data browser does not
- * redraw the checkboxes when the enable state changes. The fix is
- * to force a redraw.
- */
- redrawWidget (handle, false);
-}
-
-void fixScrollBar () {
- /*
- * Bug in the Macintosh. For some reason, the data browser does not update
- * the vertical scrollbar when it is scrolled to the bottom and items are
- * removed. The fix is to check if the scrollbar value is bigger the
- * maximum number of visible items and clamp it when needed.
- */
- int [] top = new int [1], left = new int [1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- int maximum = Math.max (0, getItemHeight () * visibleCount - getClientArea ().height);
- if (top [0] > maximum) {
- OS.SetDataBrowserScrollPosition (handle, maximum, left [0]);
- }
-}
-
-String [] getAxAttributes () {
- return AX_ATTRIBUTES;
-}
-
-public int getBorderWidth () {
- checkWidget ();
- int border = 0;
- byte [] hasBorder = new byte [1];
- OS.GetControlData (handle, (short) OS.kControlEntireControl, OS.kControlDataBrowserIncludesFrameAndFocusTag, 1, hasBorder, null);
- if (hasBorder [0] != 0) {
- int [] outMetric = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricFocusRectOutset, outMetric);
- border += outMetric [0] - BORDER_INSET;
- }
- return border;
-}
-
-int getCheckColumnWidth () {
- int inset = 0;
- if (OS.VERSION >= 0x1040) {
- float [] metric = new float [1];
- OS.DataBrowserGetMetric (handle, OS.kDataBrowserMetricCellContentInset, null, metric);
- inset = (int) metric [0];
- } else {
- inset = CELL_CONTENT_INSET;
- }
- int [] checkWidth = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricCheckBoxWidth, checkWidth);
- return checkWidth [0] + inset * 2;
-}
-
-public Rectangle getClientArea () {
- checkWidget();
- int border = getBorderWidth ();
- Rect rect = new Rect (), inset = new Rect ();
- OS.GetControlBounds (handle, rect);
- OS.GetDataBrowserScrollBarInset (handle, inset);
- int width = Math.max (0, rect.right - rect.left - inset.right - border - border);
- int height = Math.max (0, rect.bottom - rect.top - inset.bottom - border - border);
- return new Rectangle (inset.left + border, inset.top + border, width, height);
-}
-
-/**
- * Returns the column at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- * Columns are returned in the order that they were created.
- * If no <code>TreeColumn</code>s were created by the programmer,
- * this method will throw <code>ERROR_INVALID_RANGE</code> despite
- * the fact that a single column of data may be visible in the tree.
- * This occurs when the programmer uses the tree like a list, adding
- * items but never creating a column.
- *
- * @param index the index of the column to return
- * @return the column at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public TreeColumn getColumn (int index) {
- checkWidget ();
- if (!(0 <=index && index < columnCount)) error (SWT.ERROR_INVALID_RANGE);
- return columns [index];
-}
-
-/**
- * Returns the number of columns contained in the receiver.
- * If no <code>TreeColumn</code>s were created by the programmer,
- * this value is zero, despite the fact that visually, one column
- * of items may be visible. This occurs when the programmer uses
- * the tree like a list, adding items but never creating a column.
- *
- * @return the number of columns
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getColumnCount () {
- checkWidget ();
- return columnCount;
-}
-
-/**
- * Returns an array of zero-relative integers that map
- * the creation order of the receiver's items to the
- * order in which they are currently being displayed.
- * <p>
- * Specifically, the indices of the returned array represent
- * the current visual order of the items, and the contents
- * of the array represent the creation order of the items.
- * </p><p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the current visual order of the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
-public int [] getColumnOrder () {
- checkWidget ();
- int [] order = new int [columnCount];
- int [] position = new int [1];
- for (int i=0; i<columnCount; i++) {
- TreeColumn column = columns [i];
- OS.GetDataBrowserTableViewColumnPosition (handle, column.id, position);
- if ((style & SWT.CHECK) != 0) position [0] -= 1;
- order [position [0]] = i;
- }
- return order;
-}
-
-/**
- * Returns an array of <code>TreeColumn</code>s which are the
- * columns in the receiver. Columns are returned in the order
- * that they were created. If no <code>TreeColumn</code>s were
- * created by the programmer, the array is empty, despite the fact
- * that visually, one column of items may be visible. This occurs
- * when the programmer uses the tree like a list, adding items but
- * never creating a column.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public TreeColumn [] getColumns () {
- checkWidget ();
- TreeColumn [] result = new TreeColumn [columnCount];
- System.arraycopy (columns, 0, result, 0, columnCount);
- return result;
-}
-
-int getGap () {
- if (OS.VERSION >= 0x1040) {
- float [] metric = new float [1];
- OS.DataBrowserGetMetric (handle, OS.kDataBrowserMetricIconAndTextGap, null, metric);
- return (int) metric [0];
- }
- return ICON_AND_TEXT_GAP;
-}
-
-/**
- * Returns the width in pixels of a grid line.
- *
- * @return the width of a grid line in pixels
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getGridLineWidth () {
- checkWidget ();
- return 0;
-}
-
-/**
- * Returns the height of the receiver's header
- *
- * @return the height of the header or zero if the header is not visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getHeaderHeight () {
- checkWidget ();
- short [] height = new short [1];
- OS.GetDataBrowserListViewHeaderBtnHeight (handle, height);
- return height [0];
-}
-
-/**
- * Returns <code>true</code> if the receiver's header is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's header's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public boolean getHeaderVisible () {
- checkWidget ();
- short [] height = new short [1];
- OS.GetDataBrowserListViewHeaderBtnHeight (handle, height);
- return height [0] != 0;
-}
-
-int getLeftDisclosureInset (int column_id) {
- int [] disclosure = new int [1];
- OS.GetDataBrowserListViewDisclosureColumn (handle, disclosure, new boolean [1]);
- if (disclosure [0] == column_id) {
- int width = 0;
- int [] metric1 = new int [1];
- OS.GetThemeMetric (OS.kThemeMetricDisclosureTriangleWidth, metric1);
- width += metric1 [0];
- if (OS.VERSION >= 0x1040) {
- float [] metric = new float [1];
- OS.DataBrowserGetMetric (handle, OS.kDataBrowserMetricDisclosureColumnEdgeInset, null, metric);
- width += (int) metric [0];
- OS.DataBrowserGetMetric (handle, OS.kDataBrowserMetricDisclosureTriangleAndContentGap, null, metric);
- width += (int) metric [0];
- } else {
- width += DISCLOSURE_COLUMN_EDGE_INSET + DISCLOSURE_TRIANGLE_AND_CONTENT_GAP;
- }
- return width;
- }
- return 0;
-}
-
-int getInsetWidth (int column_id, boolean leftInset) {
- int inset = 0;
- if (OS.VERSION >= 0x1040) {
- float [] metric = new float [1];
- OS.DataBrowserGetMetric (handle, OS.kDataBrowserMetricCellContentInset, null, metric);
- inset = (int) metric [0];
- } else {
- inset = CELL_CONTENT_INSET;
- }
- int width = 0;
- int [] disclosure = new int [1];
- OS.GetDataBrowserListViewDisclosureColumn (handle, disclosure, new boolean [1]);
- if (disclosure [0] != column_id) {
- width += inset * 2;
- } else {
- width += inset;
- if (leftInset) width += getLeftDisclosureInset (column_id);
- }
- return width;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public TreeItem getItem (int index) {
- checkWidget ();
- int count = getItemCount (null);
- if (index < 0 || index >= count) error (SWT.ERROR_INVALID_RANGE);
- return _getItem (null, index);
-}
-
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- * <p>
- * The item that is returned represents an item that could be selected by the user.
- * For example, if selection only occurs in items in the first column, then null is
- * returned if the point is outside of the item.
- * Note that the SWT.FULL_SELECTION style hint, which specifies the selection policy,
- * determines the extent of the selection.
- * </p>
- *
- * @param point the point used to locate the item
- * @return the item at the given point, or null if the point is not in a selectable item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem getItem (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- int [] disclosure = new int [1];
- OS.GetDataBrowserListViewDisclosureColumn (handle, disclosure, new boolean [1]);
- short [] height = new short [1];
- if (OS.GetDataBrowserTableViewRowHeight (handle, height) != OS.noErr) {
- error (SWT.ERROR_CANNOT_GET_ITEM_HEIGHT);
- }
- Rect rect = new Rect ();
- org.eclipse.swt.internal.carbon.Point pt = new org.eclipse.swt.internal.carbon.Point ();
- OS.SetPt (pt, (short) point.x, (short) point.y);
- if (0 < lastHittest && lastHittest <= items.length && lastHittestColumn != 0) {
- TreeItem item = _getItem (lastHittest, false);
- if (item != null) {
- int lastPosColumnId = column_id;
- for (int i=0; i<columnCount; i++) {
- TreeColumn column = columns [i];
- int [] position = new int [1];
- OS.GetDataBrowserTableViewColumnPosition (handle, column.id, position);
- if ((style & SWT.CHECK) != 0) position [0] -= 1;
- if (position [0] == columnCount - 1) {
- lastPosColumnId = column.id;
- break;
- }
- }
- if (OS.GetDataBrowserItemPartBounds (handle, item.id, lastPosColumnId, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- if (pt.h > rect.right) return null;
- }
- if (OS.GetDataBrowserItemPartBounds (handle, item.id, disclosure[0], OS.kDataBrowserPropertyDisclosurePart, rect) == OS.noErr) {
- if (OS.PtInRect (pt, rect)) return null;
- }
- if (OS.GetDataBrowserItemPartBounds (handle, item.id, lastHittestColumn, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- rect.bottom = (short)(rect.top + height [0]);
- if (OS.PtInRect (pt, rect)) return item;
- if (rect.top <= pt.v && pt.v < rect.bottom) {
- for (int j = 0; j < columnCount; j++) {
- if (OS.GetDataBrowserItemPartBounds (handle, item.id, columns [j].id, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- rect.bottom = (short)(rect.top + height [0]);
- if (OS.PtInRect (pt, rect)) return item;
- }
- }
- return null;
- }
- }
- }
- }
- /* Find the item by approximating its row position */
- int[] top = new int[1];
- int[] left = new int[1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- short [] header = new short [1];
- OS.GetDataBrowserListViewHeaderBtnHeight (handle, header);
- int [] offsets = new int [] {0, 1, -1};
- for (int i = 0; i < offsets.length; i++) {
- int row = (top[0] - header [0] + point.y) / height [0] + offsets [i];
- if (row >= 0) {
- int [] itemId = new int[1];
- int result = OS.GetDataBrowserTableViewItemID (handle, row, itemId);
- if (result != OS.noErr) return null;
- TreeItem item = _getItem(itemId[0], false);
- if (item == null) return null;
- if (OS.GetDataBrowserItemPartBounds (handle, item.id, disclosure [0], OS.kDataBrowserPropertyDisclosurePart, rect) == OS.noErr) {
- if (OS.PtInRect (pt, rect)) return null;
- }
- int columnId = columnCount == 0 ? column_id : columns [0].id;
- if (OS.GetDataBrowserItemPartBounds (handle, item.id, columnId, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- rect.bottom = (short)(rect.top + height [0]);
- if (rect.top <= pt.v && pt.v < rect.bottom) {
- if (columnCount == 0) {
- if (OS.PtInRect (pt, rect)) return item;
- } else {
- for (int j = 0; j < columnCount; j++) {
- if (OS.GetDataBrowserItemPartBounds (handle, item.id, columns [j].id, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- rect.bottom = (short)(rect.top + height [0]);
- if (OS.PtInRect (pt, rect)) return item;
- }
- }
- }
- return null;
- }
- }
- }
- }
- return null;
-}
-
-/**
- * Returns the number of items contained in the receiver
- * that are direct item children of the receiver. The
- * number that is returned is the number of roots in the
- * tree.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return getItemCount (null);
-}
-
-int getItemCount (TreeItem parentItem) {
- if (parentItem == null) {
- int [] count = new int [1];
- if (OS.GetDataBrowserItemCount (handle, OS.kDataBrowserNoItem, false, OS.kDataBrowserItemAnyState, count) == OS.noErr) {
- return count [0];
- }
- return 0;
- }
- return parentItem.itemCount;
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the tree.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- short [] height = new short [1];
- if (OS.GetDataBrowserTableViewRowHeight (handle, height) != OS.noErr) {
- error (SWT.ERROR_CANNOT_GET_ITEM_HEIGHT);
- }
- return height [0];
-}
-
-/**
- * Returns a (possibly empty) array of items contained in the
- * receiver that are direct item children of the receiver. These
- * are the roots of the tree.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem [] getItems () {
- checkWidget ();
- return getItems (null);
-}
-
-TreeItem [] getItems (TreeItem parentItem) {
- if (items == null) return new TreeItem [0];
- int count = getItemCount (parentItem);
- TreeItem [] result = new TreeItem [count];
- for (int i=0; i<count; i++) {
- result [i] = _getItem (parentItem, i);
- }
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver's lines are visible,
- * and <code>false</code> otherwise. Note that some platforms draw
- * grid lines while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the visibility state of the lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public boolean getLinesVisible () {
- checkWidget ();
- if (OS.VERSION >= 0x1040) {
- int [] attrib = new int [1];
- OS.DataBrowserGetAttributes (handle, attrib);
- return (attrib [0] & (OS.kDataBrowserAttributeListViewAlternatingRowColors | OS.kDataBrowserAttributeListViewDrawColumnDividers)) != 0;
- }
- return false;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>TreeItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem getParentItem () {
- checkWidget ();
- return null;
-}
-
-/**
- * Returns an array of <code>TreeItem</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem [] getSelection () {
- checkWidget ();
- int [] count = new int [1];
- if (OS.GetDataBrowserItemCount (handle, OS.kDataBrowserNoItem, true, OS.kDataBrowserItemIsSelected, count) != OS.noErr) {
- error (SWT.ERROR_CANNOT_GET_COUNT);
- }
- TreeItem [] result = new TreeItem [count[0]];
- if (count[0] > 0) {
- int ptr = OS.NewHandle (0);
- if (count[0] == 1) {
- if (OS.GetDataBrowserItems (handle, OS.kDataBrowserNoItem, true, OS.kDataBrowserItemIsSelected, ptr) != OS.noErr) {
- error (SWT.ERROR_CANNOT_GET_SELECTION);
- }
- OS.HLock (ptr);
- int [] id = new int [1];
- OS.memmove (id, ptr, 4);
- OS.memmove (id, id [0], 4);
- result [0] = _getItem (id [0], true);
- OS.HUnlock (ptr);
- } else {
- getSelection (result, OS.kDataBrowserNoItem, ptr, 0);
- }
- OS.DisposeHandle (ptr);
- }
- return result;
-}
-
-int getSelection(TreeItem[] result, int item, int ptr, int index) {
- OS.SetHandleSize (ptr, 0);
- if (OS.GetDataBrowserItems (handle, item, false, OS.kDataBrowserItemIsSelected, ptr) != OS.noErr) {
- error (SWT.ERROR_CANNOT_GET_SELECTION);
- }
- int count = OS.GetHandleSize (ptr) / 4;
- if (count > 0) {
- OS.HLock (ptr);
- int [] id = new int [count];
- OS.memmove (id, ptr, 4);
- OS.memmove (id, id [0], count * 4);
- for (int i=0; i<count; i++) {
- result [index++] = _getItem (id [count - i - 1], true);
- }
- OS.HUnlock (ptr);
- if (index == result.length) return index;
- }
- OS.SetHandleSize (ptr, 0);
- if (OS.GetDataBrowserItems (handle, item, false, OS.kDataBrowserContainerIsOpen, ptr) != OS.noErr) {
- error (SWT.ERROR_CANNOT_GET_SELECTION);
- }
- count = OS.GetHandleSize (ptr) / 4;
- if (count > 0) {
- OS.HLock (ptr);
- int [] id = new int [count];
- OS.memmove (id, ptr, 4);
- OS.memmove (id, id [0], count * 4);
- for (int i=0; i<count; i++) {
- index = getSelection(result, id [count - i - 1], ptr, index);
- if (index == result.length) return index;
- }
- OS.HUnlock (ptr);
- }
- return index;
-}
-
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget ();
- int [] count = new int [1];
- if (OS.GetDataBrowserItemCount (handle, OS.kDataBrowserNoItem, true, OS.kDataBrowserItemIsSelected, count) != OS.noErr) {
- error (SWT.ERROR_CANNOT_GET_COUNT);
- }
- return count [0];
-}
-
-/**
- * Returns the column which shows the sort indicator for
- * the receiver. The value may be null if no column shows
- * the sort indicator.
- *
- * @return the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortColumn(TreeColumn)
- *
- * @since 3.2
- */
-public TreeColumn getSortColumn () {
- checkWidget ();
- return sortColumn;
-}
-
-/**
- * Returns the direction of the sort indicator for the receiver.
- * The value will be one of <code>UP</code>, <code>DOWN</code>
- * or <code>NONE</code>.
- *
- * @return the sort direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortDirection(int)
- *
- * @since 3.2
- */
-public int getSortDirection () {
- checkWidget ();
- return sortDirection;
-}
-
-/**
- * Returns the item which is currently at the top of the receiver.
- * This item can change when items are expanded, collapsed, scrolled
- * or new items are added or removed.
- *
- * @return the item at the top of the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public TreeItem getTopItem () {
- checkWidget ();
- /* Find the topItem by calculating its row position */
- int[] top = new int[1], left = new int[1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- int row = top[0] / getItemHeight ();;
- int [] itemId = new int[1];
- int result = OS.GetDataBrowserTableViewItemID (handle, row, itemId);
- if (result == OS.noErr) return _getItem (itemId[0], false);
- return null;
-}
-
-int helpProc (int inControl, int inGlobalMouse, int inRequest, int outContentProvided, int ioHelpContent) {
- if (toolTipText == null) {
- switch (inRequest) {
- case OS.kHMSupplyContent: {
- if (!(toolTipText != null && toolTipText.length () != 0)) {
- Rect rect = new Rect ();
- int window = OS.GetControlOwner (handle);
- OS.GetWindowBounds (window, (short) OS.kWindowContentRgn, rect);
- short windowLeft = rect.left, windowTop = rect.top;
- org.eclipse.swt.internal.carbon.Point pt = new org.eclipse.swt.internal.carbon.Point ();
- OS.memmove(pt, new int[] {inGlobalMouse}, 4);
- pt.h -= windowLeft;
- pt.v -= windowTop;
- String toolTipText = null;
- int tagSide = OS.kHMAbsoluteCenterAligned;
- CGPoint inPt = new CGPoint ();
- int [] contentView = new int [1];
- OS.HIViewFindByID (OS.HIViewGetRoot (OS.GetControlOwner (handle)), OS.kHIViewWindowContentID (), contentView);
- OS.HIViewConvertPoint (inPt, handle, contentView [0]);
- pt.h -= (int) inPt.x;
- pt.v -= (int) inPt.y;
- windowLeft += (int) inPt.x;
- windowTop += (int) inPt.y;
- int x = pt.h;
- int y = pt.v;
- int headerHeight = getHeaderHeight ();
- if (headerHeight != 0 && (0 <= y && y < headerHeight) ) {
- int startX = 0;
- for (int i = 0; i < columnCount; i++) {
- TreeColumn column = columns [i];
- int width = column.lastWidth + getLeftDisclosureInset (column.id);
- if (startX <= x && x < startX + width) {
- toolTipText = column.toolTipText;
- rect.left = (short) startX;
- rect.top = (short) 0;
- rect.right = (short) (rect.left + width);
- rect.bottom = (short) (rect.top + headerHeight);
- tagSide = OS.kHMOutsideBottomRightAligned;
- break;
- }
- startX += width;
- }
- } else {
- TreeItem item = null;
- if (0 < lastHittest && lastHittest <= items.length && lastHittestColumn != 0) {
- if (OS.GetDataBrowserItemPartBounds (handle, lastHittest, lastHittestColumn, OS.kDataBrowserPropertyContentPart, rect) == OS.noErr) {
- item = _getItem (lastHittest, false);
- }
- }
- if (item != null) {
- int columnIndex = 0;
- TreeColumn column = null;
- if (columnCount > 0) {
- for (int i = 0; i < columnCount; i++) {
- if (columns[i].id == lastHittestColumn) {
- column = columns[i];
- columnIndex = i;
- break;
- }
- }
- }
- int columnId = lastHittestColumn;
- GC gc = new GC (this);
- int inset = getInsetWidth (columnId, false);
- int width = item.calculateWidth (columnIndex, gc) + inset;
- gc.dispose ();
- int columnWidth;
- if (columnCount == 0) {
- columnWidth = getClientArea ().width;
- } else {
- short [] w = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (handle, columnId, w);
- columnWidth = w[0];
- }
- if (width > columnWidth) {
- toolTipText = item.getText (columnIndex);
- Image image = item.getImage (columnIndex);
- int imageWidth = image != null ? image.getBounds ().width + getGap () : 0;
- int style = column == null ? SWT.LEFT : column.style;
- if ((style & SWT.LEFT) != 0) {
- rect.left += imageWidth;
- rect.right = (short) (rect.left + width - imageWidth - inset);
- }
- if ((style & SWT.RIGHT) != 0) {
- rect.left = (short) (rect.right - width + imageWidth + inset);
- }
- if ((style & SWT.CENTER) != 0) {
- rect.left += imageWidth;
- }
- }
- }
- }
- if (toolTipText != null && toolTipText.length () != 0) {
- char [] buffer = new char [toolTipText.length ()];
- toolTipText.getChars (0, buffer.length, buffer, 0);
- int length = fixMnemonic (buffer);
- if (display.helpString != 0) OS.CFRelease (display.helpString);
- display.helpString = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, length);
- HMHelpContentRec helpContent = new HMHelpContentRec ();
- OS.memmove (helpContent, ioHelpContent, HMHelpContentRec.sizeof);
- display.helpWidget = this;
- helpContent.version = OS.kMacHelpVersion;
- helpContent.tagSide = (short) tagSide;
- helpContent.absHotRect_left = (short) (rect.left + windowLeft);
- helpContent.absHotRect_top = (short) (rect.top + windowTop);
- helpContent.absHotRect_right = (short) (rect.right + windowLeft);
- helpContent.absHotRect_bottom = (short) (rect.bottom + windowTop);
- helpContent.content0_contentType = OS.kHMCFStringContent;
- helpContent.content0_tagCFString = display.helpString;
- helpContent.content1_contentType = OS.kHMCFStringContent;
- helpContent.content1_tagCFString = display.helpString;
- OS.memmove (ioHelpContent, helpContent, HMHelpContentRec.sizeof);
- OS.memmove (outContentProvided, new short[]{OS.kHMContentProvided}, 2);
- return OS.noErr;
- }
- }
- break;
- }
- }
- }
- return super.helpProc (inControl, inGlobalMouse, inRequest, outContentProvided, ioHelpContent);
-}
-
-int hitTestProc (int browser, int id, int property, int theRect, int mouseRect) {
- lastHittest = id;
- lastHittestColumn = property;
- return 1;
-}
-
-void hookEvents () {
- super.hookEvents ();
- DataBrowserCallbacks callbacks = new DataBrowserCallbacks ();
- callbacks.version = OS.kDataBrowserLatestCallbacks;
- OS.InitDataBrowserCallbacks (callbacks);
- callbacks.v1_itemDataCallback = display.itemDataProc;
- callbacks.v1_itemNotificationCallback = display.itemNotificationProc;
- callbacks.v1_itemCompareCallback = display.itemCompareProc;
- OS.SetDataBrowserCallbacks (handle, callbacks);
- DataBrowserCustomCallbacks custom = new DataBrowserCustomCallbacks ();
- custom.version = OS.kDataBrowserLatestCustomCallbacks;
- OS.InitDataBrowserCustomCallbacks (custom);
- custom.v1_drawItemCallback = display.drawItemProc;
- custom.v1_hitTestCallback = display.hitTestProc;
- custom.v1_trackingCallback = display.trackingProc;
- OS.SetDataBrowserCustomCallbacks (handle, custom);
-}
-
-/**
- * Searches the receiver's list starting at the first column
- * (index 0) until a column is found that is equal to the
- * argument, and returns the index of that column. If no column
- * is found, returns -1.
- *
- * @param column the search column
- * @return the index of the column
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the column is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int indexOf (TreeColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<columnCount; i++) {
- if (columns [i] == column) return i;
- }
- return -1;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int indexOf (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (item.parentItem != null) return -1;
- return _indexOf (null, item);
-}
-
-int _indexOf (TreeItem parentItem, TreeItem item) {
- int [] ids = parentItem == null ? childIds : parentItem.childIds;
- if (ids != null) {
- for (int i=0; i<ids.length; i++) {
- if (ids [i] == item.id) return i;
- }
- }
- return -1;
-}
-
-int itemCompareProc (int browser, int itemOne, int itemTwo, int sortProperty) {
- boolean create = (style & SWT.VIRTUAL) != 0 && sortColumn != null
- && !sortColumn.isDisposed () && sortDirection == SWT.DOWN;
- TreeItem item1 = _getItem (itemOne, create);
- TreeItem item2 = _getItem (itemTwo, create);
- if (item1 == null || item2 == null) return OS.noErr;
- int index1 = _indexOf (item1.parentItem, item1);
- int index2 = _indexOf (item2.parentItem , item2);
- if (sortDirection == SWT.DOWN && sortColumn != null) {
- return index1 > index2 ? 1 : 0;
- }
- return index1 < index2 ? 1 : 0;
-}
-
-int itemDataProc (int browser, int id, int property, int itemData, int setValue) {
- switch (property) {
- case CHECK_COLUMN_ID: {
- TreeItem item = _getItem (id, true);
- if (setValue != 0) {
- item.checked = !item.checked;
- if (item.checked && item.grayed) {
- OS.SetDataBrowserItemDataButtonValue (itemData, (short) OS.kThemeButtonMixed);
- } else {
- int theData = item.checked ? OS.kThemeButtonOn : OS.kThemeButtonOff;
- OS.SetDataBrowserItemDataButtonValue (itemData, (short) theData);
- }
- Event event = new Event ();
- event.item = item;
- event.detail = SWT.CHECK;
- postEvent (SWT.Selection, event);
- /*
- * Bug in the Macintosh. When the height of the row is smaller than the
- * check box, the tail of the check mark draws outside of the item part
- * bounds. This means it will not be redrawn when the item is unckeched.
- * The fix is to redraw the area.
- */
- if (!item.checked) item.redraw(Tree.CHECK_COLUMN_ID);
- } else {
- int theData = OS.kThemeButtonOff;
- if (item.checked) theData = item.grayed ? OS.kThemeButtonMixed : OS.kThemeButtonOn;
- OS.SetDataBrowserItemDataButtonValue (itemData, (short) theData);
- }
- break;
- }
- case OS.kDataBrowserItemIsContainerProperty: {
- TreeItem item = _getItem (id, true);
- if (item.itemCount > 0) {
- OS.SetDataBrowserItemDataBooleanValue (itemData, true);
- }
- break;
- }
- }
- return OS.noErr;
-}
-
-int itemNotificationProc (int browser, int id, int message) {
- if (message == OS.kDataBrowserUserStateChanged) {
- boolean resized = false;
- short [] width = new short [1];
- TreeColumn [] newColumns = getColumns ();
- for (int i = 0; i < columnCount; i++) {
- TreeColumn column = newColumns [i];
- if (!column.isDisposed ()) {
- OS.GetDataBrowserTableViewNamedColumnWidth (handle, column.id, width);
- if (width [0] != column.lastWidth) {
- column.resized (width [0]);
- resized = true;
- }
- }
- if (!column.isDisposed ()) {
- int [] position = new int[1];
- OS.GetDataBrowserTableViewColumnPosition (handle, column.id, position);
- if (position [0] != column.lastPosition) {
- column.lastPosition = position [0];
- int order = (style & SWT.CHECK) != 0 ? position [0] - 1 : position [0];
- if (order == 0) {
- int [] disclosure = new int [1];
- boolean [] expandableRows = new boolean [1];
- OS.GetDataBrowserListViewDisclosureColumn (handle, disclosure, expandableRows);
- if (disclosure [0] != column.id) {
- OS.SetDataBrowserListViewDisclosureColumn (handle, column.id, expandableRows [0]);
- }
- }
- column.sendEvent (SWT.Move);
- resized = true;
- }
- }
- }
- int [] property = new int [1];
- OS.GetDataBrowserSortProperty (handle, property);
- if (property [0] != 0) {
- if (!resized) {
- for (int i = 0; i < columnCount; i++) {
- TreeColumn column = columns [i];
- if (property [0] == column.id) {
- column.postEvent (display.clickCount == 2 ? SWT.DefaultSelection : SWT.Selection);
- break;
- }
- }
- }
- OS.SetDataBrowserSortProperty (handle, 0);
- if (sortColumn != null && !sortColumn.isDisposed () && sortDirection != SWT.NONE) {
- OS.SetDataBrowserSortProperty (handle, sortColumn.id);
- int order = sortDirection == SWT.DOWN ? OS.kDataBrowserOrderDecreasing : OS.kDataBrowserOrderIncreasing;
- OS.SetDataBrowserSortOrder (handle, (short) order);
- }
- }
- return OS.noErr;
- }
- switch (message) {
- case OS.kDataBrowserItemSelected:
- savedAnchor = 0;
- break;
- case OS.kDataBrowserItemDeselected: {
- int [] selectionCount = new int [1];
- if (OS.GetDataBrowserItemCount (handle, OS.kDataBrowserNoItem, true, OS.kDataBrowserItemIsSelected, selectionCount) == OS.noErr) {
- if (selectionCount [0] == 0) savedAnchor = id;
- }
- break;
- }
- }
- switch (message) {
- case OS.kDataBrowserItemSelected:
- case OS.kDataBrowserItemDeselected: {
- wasSelected = true;
- if (ignoreSelect) break;
- int [] first = new int [1], last = new int [1];
- OS.GetDataBrowserSelectionAnchor (handle, first, last);
- boolean selected = false;
- if ((style & SWT.MULTI) != 0) {
- int modifiers = OS.GetCurrentEventKeyModifiers ();
- if ((modifiers & OS.shiftKey) != 0) {
- if (message == OS.kDataBrowserItemSelected) {
- selected = first [0] == id || last [0] == id;
- } else {
- selected = id == anchorFirst || id == anchorLast;
- }
- } else {
- if ((modifiers & OS.cmdKey) != 0) {
- selected = true;
- } else {
- selected = first [0] == last [0];
- }
- }
- } else {
- selected = message == OS.kDataBrowserItemSelected;
- }
- if (selected) {
- anchorFirst = first [0];
- anchorLast = last [0];
- Event event = new Event ();
- event.item = _getItem (id, true);
- postEvent (SWT.Selection, event);
- }
- break;
- }
- case OS.kDataBrowserItemDoubleClicked: {
- wasSelected = true;
- if (display.clickCount == 2) {
- Event event = new Event ();
- event.item = _getItem (id, true);
- postEvent (SWT.DefaultSelection, event);
- }
- break;
- }
- case OS.kDataBrowserContainerClosing: {
- int ptr = OS.NewHandle (0);
- if (OS.GetDataBrowserItems (handle, id, false, OS.kDataBrowserItemAnyState, ptr) == OS.noErr) {
- int count = OS.GetHandleSize (ptr) / 4;
- visibleCount -= count;
- }
- OS.DisposeHandle (ptr);
-
- /*
- * Bug in the Macintosh. For some reason, if the selected sub items of an item
- * get a kDataBrowserItemDeselected notificaton when the item is collapsed, a
- * call to GetDataBrowserSelectionAnchor () will cause a segment fault. The
- * fix is to deselect these items ignoring kDataBrowserItemDeselected and then
- * issue a selection event.
- */
- ptr = OS.NewHandle (0);
- if (OS.GetDataBrowserItems (handle, id, true, OS.kDataBrowserItemIsSelected, ptr) == OS.noErr) {
- int count = OS.GetHandleSize (ptr) / 4;
- if (count > 0) {
- int [] ids = new int [count];
- OS.HLock (ptr);
- int [] start = new int [1];
- OS.memmove (start, ptr, 4);
- OS.memmove (ids, start [0], count * 4);
- OS.HUnlock (ptr);
- boolean oldIgnore = ignoreSelect;
- ignoreSelect = true;
- /*
- * Bug in the Macintosh. When the DataBrowser selection flags includes
- * both kDataBrowserNeverEmptySelectionSet and kDataBrowserSelectOnlyOne,
- * two items are selected when SetDataBrowserSelectedItems() is called
- * with kDataBrowserItemsAssign to assign a new seletion despite the fact
- * that kDataBrowserSelectOnlyOne was specified. The fix is to save and
- * restore kDataBrowserNeverEmptySelectionSet around each call to
- * SetDataBrowserSelectedItems().
- */
- int [] selectionFlags = null;
- if ((style & SWT.SINGLE) != 0) {
- selectionFlags = new int [1];
- OS.GetDataBrowserSelectionFlags (handle, selectionFlags);
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0] & ~OS.kDataBrowserNeverEmptySelectionSet);
- }
- OS.SetDataBrowserSelectedItems (handle, ids.length, ids, OS.kDataBrowserItemsRemove);
- if ((style & SWT.SINGLE) != 0) {
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0]);
- }
- ignoreSelect = oldIgnore;
- if (!ignoreSelect) {
- Event event = new Event ();
- event.item = _getItem (id, true);
- sendEvent (SWT.Selection, event);
- }
- }
- }
- OS.DisposeHandle (ptr);
- break;
- }
- case OS.kDataBrowserContainerClosed: {
- TreeItem parentItem = _getItem (id, true);
- if (parentItem == null) break; // can happen when removing all items
- int [] ids = parentItem.childIds;
- if (ids != null) {
- for (int i=0; i<parentItem.itemCount; i++) {
- TreeItem item = _getItem (ids [i], false);
- if (item == null) ids [i] = 0;
- }
- }
- wasExpanded = true;
- if (!ignoreExpand) {
- Event event = new Event ();
- event.item = parentItem;
- sendEvent (SWT.Collapse, event);
- if (isDisposed ()) break;
- setScrollWidth (true);
- fixScrollBar ();
- }
- break;
- }
- case OS.kDataBrowserContainerOpened: {
- TreeItem item = _getItem (id, true);
- wasExpanded = true;
- if (!ignoreExpand) {
- Event event = new Event ();
- event.item = item;
- try {
- item.state |= EXPANDING;
- sendEvent (SWT.Expand, event);
- if (isDisposed ()) break;
- } finally {
- item.state &= ~EXPANDING;
- }
- }
- int newIdCount = 0;
- for (int i=0; i<item.itemCount; i++) {
- if (item.childIds [i] == 0) newIdCount++;
- }
- if (newIdCount > 0) {
- int [] newIds = _getIds (newIdCount);
- int index = 0;
- for (int i=0; i<item.itemCount; i++) {
- if (item.childIds [i] == 0) item.childIds [i] = newIds [index++];
- }
- }
- OS.AddDataBrowserItems (handle, id, item.itemCount, item.childIds, OS.kDataBrowserItemNoProperty);
- visibleCount += item.itemCount;
- if (!ignoreExpand) {
- setScrollWidth (false, item.childIds, false);
- }
- break;
- }
- }
- return OS.noErr;
-}
-
-int kEventAccessibleGetNamedAttribute (int nextHandler, int theEvent, int userData) {
- int code = OS.eventNotHandledErr;
- int [] stringRef = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamAccessibleAttributeName, OS.typeCFStringRef, null, 4, null, stringRef);
- int length = 0;
- if (stringRef [0] != 0) length = OS.CFStringGetLength (stringRef [0]);
- char [] buffer = new char [length];
- CFRange range = new CFRange ();
- range.length = length;
- OS.CFStringGetCharacters (stringRef [0], range, buffer);
- String attributeName = new String(buffer);
- if (attributeName.equals(OS.kAXHeaderAttribute)) {
- short [] height = new short [1];
- OS.GetDataBrowserListViewHeaderBtnHeight (handle, height);
- if (height [0] == 0) {
- /*
- * Bug in the Macintosh. Even when the header is not visible,
- * VoiceOver still reports each column header's role for every row.
- * This is confusing and overly verbose. The fix is to return
- * "no header" when the screen reader asks for the header, by
- * returning noErr without setting the event parameter.
- */
- code = OS.noErr;
- }
- } else {
- int [] ref = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamAccessibleObject, OS.typeCFTypeRef, null, 4, null, ref);
- int axuielementref = ref [0];
- DataBrowserAccessibilityItemInfo itemInfo = new DataBrowserAccessibilityItemInfo ();
- int err = OS.AXUIElementGetDataBrowserItemInfo (axuielementref, handle, 0, itemInfo);
- if (err == OS.noErr && itemInfo.v0_columnProperty != OS.kDataBrowserItemNoProperty && itemInfo.v0_item != OS.kDataBrowserNoItem && itemInfo.v0_propertyPart == OS.kDataBrowserPropertyEnclosingPart) {
- int columnIndex = 0;
- for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {
- if (columns [columnIndex].id == itemInfo.v0_columnProperty) break;
- }
- if (columnIndex != columnCount || columnCount == 0) {
- int id = itemInfo.v0_item;
- TreeItem treeItem = _getItem (id, false);
- if (attributeName.equals (OS.kAXRoleAttribute) || attributeName.equals (OS.kAXRoleDescriptionAttribute)) {
- String roleText = OS.kAXStaticTextRole;
- buffer = new char [roleText.length ()];
- roleText.getChars (0, buffer.length, buffer, 0);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- if (attributeName.equals (OS.kAXRoleAttribute)) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- } else { // kAXRoleDescriptionAttribute
- int stringRef2 = OS.HICopyAccessibilityRoleDescription (stringRef [0], 0);
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, new int [] {stringRef2});
- OS.CFRelease(stringRef2);
- }
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- } else if (attributeName.equals(OS.kAXChildrenAttribute)) {
- int children = OS.CFArrayCreateMutable (OS.kCFAllocatorDefault, 0, 0);
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFMutableArrayRef, 4, new int [] {children});
- OS.CFRelease(children);
- code = OS.noErr;
- } else if (attributeName.equals (OS.kAXTitleAttribute) || attributeName.equals (OS.kAXDescriptionAttribute)) {
- String text = treeItem.getText (columnIndex);
- buffer = new char [text.length ()];
- text.getChars (0, buffer.length, buffer, 0);
- stringRef [0] = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
- if (stringRef [0] != 0) {
- OS.SetEventParameter (theEvent, OS.kEventParamAccessibleAttributeValue, OS.typeCFStringRef, 4, stringRef);
- OS.CFRelease(stringRef [0]);
- code = OS.noErr;
- }
- }
- }
- }
- }
- if (accessible != null) {
- code = accessible.internal_kEventAccessibleGetNamedAttribute (nextHandler, theEvent, code);
- }
- return code;
-}
-
-int kEventControlGetClickActivation (int nextHandler, int theEvent, int userData) {
- OS.SetEventParameter (theEvent, OS.kEventParamClickActivation, OS.typeClickActivationResult, 4, new int [] {OS.kActivateAndHandleClick});
- return OS.noErr;
-}
-
-int kEventControlSetCursor (int nextHandler, int theEvent, int userData) {
- if (!isEnabledCursor ()) return OS.noErr;
- if (isEnabledModal ()) {
- org.eclipse.swt.internal.carbon.Point pt = new org.eclipse.swt.internal.carbon.Point ();
- int sizeof = org.eclipse.swt.internal.carbon.Point.sizeof;
- OS.GetEventParameter (theEvent, OS.kEventParamMouseLocation, OS.typeQDPoint, null, sizeof, null, pt);
- if (!contains (pt.h, pt.v)) return OS.eventNotHandledErr;
- }
- return super.kEventControlSetCursor (nextHandler, theEvent, userData);
-}
-
-int kEventUnicodeKeyPressed (int nextHandler, int theEvent, int userData) {
- int result = super.kEventUnicodeKeyPressed (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- int [] keyboardEvent = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamTextInputSendKeyboardEvent, OS.typeEventRef, null, keyboardEvent.length * 4, null, keyboardEvent);
- int [] keyCode = new int [1];
- OS.GetEventParameter (keyboardEvent [0], OS.kEventParamKeyCode, OS.typeUInt32, null, keyCode.length * 4, null, keyCode);
- switch (keyCode [0]) {
- case 49: { /* Space */
- int [] first = new int [1], last = new int [1];
- if (OS.GetDataBrowserSelectionAnchor (handle, first, last) == OS.noErr) {
- if (first [0] != 0) {
- TreeItem item = _getItem (first [0], true);
- if ((style & SWT.CHECK) != 0) {
- item.setChecked (!item.getChecked (), true);
- }
- }
- }
- break;
- }
- case 76: /* KP Enter */
- case 36: { /* Return */
- postEvent (SWT.DefaultSelection);
- break;
- }
- /*
- * Feature in the Macintosh. For some reason, when the user hits an
- * up or down arrow to traverse the items in a Data Browser, the item
- * scrolls to the left such that the white space that is normally
- * visible to the right of the every item is scrolled out of view.
- * The fix is to save and restore the horizontal scroll position.
- */
- case 125: /* Down */
- case 126: /* Up*/ {
- int [] itemCount = new int [1];
- if (OS.GetDataBrowserItemCount (handle, OS.kDataBrowserNoItem, false, OS.kDataBrowserItemAnyState, itemCount) == OS.noErr) {
- if (itemCount [0] == 0) break;
- }
- int [] top = new int [1], left = new int [1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- int [] itemId = null;
- int [] selectionCount = new int [1];
- if (OS.GetDataBrowserItemCount (handle, OS.kDataBrowserNoItem, true, OS.kDataBrowserItemIsSelected, selectionCount) == OS.noErr) {
- if (savedAnchor != 0 && selectionCount [0] == 0) {
- int [] index = new int [1];
- if (OS.GetDataBrowserTableViewItemRow (handle, savedAnchor, index) == OS.noErr) {
- index [0] = index [0] + (keyCode [0] == 125 ? 1 : -1);
- itemId = new int [1];
- if (OS.GetDataBrowserTableViewItemID (handle, index [0], itemId) != OS.noErr) {
- itemId [0] = savedAnchor;
- }
- }
- }
- }
- if (itemId != null) {
- OS.SetDataBrowserSelectedItems (handle, 1, itemId, OS.kDataBrowserItemsAssign);
- result = OS.noErr;
- } else {
- result = OS.CallNextEventHandler (nextHandler, theEvent);
- }
- OS.GetDataBrowserScrollPosition (handle, top, null);
- OS.SetDataBrowserScrollPosition (handle, top [0], left [0]);
- redrawBackgroundImage ();
- break;
- }
- }
- return result;
-}
-
-int kEventMouseDown (int nextHandler, int theEvent, int userData) {
- int result = super.kEventMouseDown (nextHandler, theEvent, userData);
- if (result == OS.noErr) return result;
- wasSelected = wasExpanded = false;
- result = OS.CallNextEventHandler (nextHandler, theEvent);
- if (isDisposed ()) return OS.noErr;
- if (!wasSelected && !wasExpanded) {
- if (OS.IsDataBrowserItemSelected (handle, lastHittest)) {
- if (0 < lastHittest && lastHittest <= items.length) {
- Event event = new Event ();
- event.item = _getItem (lastHittest, true);
- postEvent (SWT.Selection, event);
- }
- }
- }
- wasSelected = wasExpanded = false;
- return result;
-}
-
-void releaseItem (TreeItem item, boolean release) {
- int id = item.id;
- if (release) item.release (false);
- if (savedAnchor == id) savedAnchor = 0;
- items [id - 1] = null;
- TreeItem parentItem = item.parentItem;
- int [] ids = parentItem == null ? childIds : parentItem.childIds;
- int index = -1;
- for (int i = 0; i < ids.length; i++) {
- if (ids [i] == id) {
- index = i; break;
- }
- }
- if (index != -1) {
- System.arraycopy(ids, 0, ids, 0, index);
- System.arraycopy(ids, index+1, ids, index, ids.length - index - 1);
- ids [ids.length - 1] = 0;
- }
- if (parentItem != null) {
- parentItem.itemCount--;
- if (parentItem.itemCount == 0) parentItem.childIds = null;
- }
-}
-
-void releaseItems (int [] ids) {
- if (ids == null) return;
- for (int i=ids.length-1; i>= 0; i--) {
- TreeItem item = _getItem (ids [i], false);
- if (item != null) {
- releaseItems (item.childIds);
- if (!isDisposed ()) {
- releaseItem (item, true);
- }
- }
- }
-}
-
-void releaseChildren (boolean destroy) {
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- childIds = null;
- if (columns != null) {
- for (int i=0; i<columnCount; i++) {
- TreeColumn column = columns [i];
- if (column != null && !column.isDisposed ()) {
- column.release (false);
- }
- }
- columns = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- sortColumn = null;
- paintGC = null;
- imageBounds = null;
- showItem = null;
- /*
- * Feature in the Mac. When RemoveDataBrowserItems() is used
- * to remove items, item notification callbacks are issued with
- * the message kDataBrowserItemRemoved When many items are
- * removed, this is slow. The fix is to temporarily remove
- * the item notification callback.
- */
- DataBrowserCallbacks callbacks = new DataBrowserCallbacks ();
- OS.GetDataBrowserCallbacks (handle, callbacks);
- callbacks.v1_itemNotificationCallback = 0;
- callbacks.v1_itemCompareCallback = 0;
- OS.SetDataBrowserCallbacks (handle, callbacks);
-}
-
-/**
- * Removes all of the items from the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget ();
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null && !item.isDisposed ()) item.release (false);
- }
- items = new TreeItem [4];
- childIds = null;
- /*
- * Feature in the Mac. When RemoveDataBrowserItems() is used
- * to remove items, item notification callbacks are issued with
- * the message kDataBrowserItemRemoved When many items are
- * removed, this is slow. The fix is to temporarily remove
- * the item notification callback.
- */
- DataBrowserCallbacks callbacks = new DataBrowserCallbacks ();
- OS.GetDataBrowserCallbacks (handle, callbacks);
- callbacks.v1_itemNotificationCallback = 0;
- callbacks.v1_itemCompareCallback = 0;
- OS.SetDataBrowserCallbacks (handle, callbacks);
- ignoreExpand = ignoreSelect = true;
- int result = OS.RemoveDataBrowserItems (handle, OS.kDataBrowserNoItem, 0, null, 0);
- ignoreExpand = ignoreSelect = false;
- callbacks.v1_itemNotificationCallback = display.itemNotificationProc;
- callbacks.v1_itemCompareCallback = display.itemCompareProc;
- OS.SetDataBrowserCallbacks (handle, callbacks);
- if (result != OS.noErr) error (SWT.ERROR_ITEM_NOT_REMOVED);
- OS.SetDataBrowserScrollPosition (handle, 0, 0);
- savedAnchor = anchorFirst = anchorLast = 0;
- visibleCount = 0;
- setScrollWidth (true);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when items in the receiver are expanded or collapsed.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TreeListener
- * @see #addTreeListener
- */
-public void removeTreeListener(TreeListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Expand, listener);
- eventTable.unhook (SWT.Collapse, listener);
-}
-
-void resetVisibleRegion (int control) {
- super.resetVisibleRegion (control);
- if (showItem != null && !showItem.isDisposed ()) {
- showItem (showItem , true);
- }
-}
-
-/**
- * Display a mark indicating the point at which an item will be inserted.
- * The drop insert item has a visual hint to show where a dragged item
- * will be inserted when dropped on the tree.
- *
- * @param item the insert item. Null will clear the insertion mark.
- * @param before true places the insert mark above 'item'. false places
- * the insert mark below 'item'.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setInsertMark (TreeItem item, boolean before) {
- checkWidget ();
- if (item != null && item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- TreeItem oldMark = insertItem;
- insertItem = item;
- insertBefore = before;
- if (oldMark != null && !oldMark.isDisposed()) oldMark.redraw (OS.kDataBrowserNoItem);
- if (item != null) item.redraw (OS.kDataBrowserNoItem);
-}
-
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- ignoreSelect = true;
- OS.SetDataBrowserSelectedItems (handle, 0, null, OS.kDataBrowserItemsAssign);
- ignoreSelect = false;
-}
-
-/**
- * Selects an item in the receiver. If the item was already
- * selected, it remains selected.
- *
- * @param item the item to be selected
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void select (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- showItem (item, false);
- ignoreSelect = true;
- /*
- * Bug in the Macintosh. When the DataBroswer selection flags includes
- * both kDataBrowserNeverEmptySelectionSet and kDataBrowserSelectOnlyOne,
- * two items are selected when SetDataBrowserSelectedItems() is called
- * with kDataBrowserItemsAssign to assign a new seletion despite the fact
- * that kDataBrowserSelectOnlyOne was specified. The fix is to save and
- * restore kDataBrowserNeverEmptySelectionSet around each call to
- * SetDataBrowserSelectedItems().
- */
- int [] selectionFlags = null;
- if ((style & SWT.SINGLE) != 0) {
- selectionFlags = new int [1];
- OS.GetDataBrowserSelectionFlags (handle, selectionFlags);
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0] & ~OS.kDataBrowserNeverEmptySelectionSet);
- }
- OS.SetDataBrowserSelectedItems (handle, 1, new int [] {item.id}, OS.kDataBrowserItemsAssign);
- if ((style & SWT.SINGLE) != 0) {
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0]);
- }
- ignoreSelect = false;
-}
-
-void setBackground (float [] color) {
- /*
- * Bug in the Macintosh. The default background of a window changes when
- * the background of a data browser is set using SetControlFontStyle(). This
- * also affects the background of any TNXObject created on that window. The
- * fix is to avoid calling SetControlFontStyle() which has no effect
- * in a data browser anyways.
- */
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- /*
- * Ensure that the selection is visible when the tree is resized
- * from a zero size to a size that can show the selection.
- */
- int result = super.setBounds (x, y, width, height, move, resize, events);
- if (showItem != null && !showItem.isDisposed ()) {
- showItem (showItem , true);
- }
- return result;
-}
-
-/**
- * Sets the order that the items in the receiver should
- * be displayed in to the given argument which is described
- * in terms of the zero-relative ordering of when the items
- * were added.
- *
- * @param order the new order to display the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item order is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
-public void setColumnOrder (int [] order) {
- checkWidget ();
- if (order == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (columnCount == 0) {
- if (order.length != 0) error (SWT.ERROR_INVALID_ARGUMENT);
- return;
- }
- if (order.length != columnCount) error (SWT.ERROR_INVALID_ARGUMENT);
- int [] oldOrder = getColumnOrder ();
- boolean reorder = false;
- boolean [] seen = new boolean [columnCount];
- for (int i=0; i<order.length; i++) {
- int index = order [i];
- if (index < 0 || index >= columnCount) error (SWT.ERROR_INVALID_ARGUMENT);
- if (seen [index]) error (SWT.ERROR_INVALID_ARGUMENT);
- seen [index] = true;
- if (order [i] != oldOrder [i]) reorder = true;
- }
- if (reorder) {
- int [] disclosure = new int [1];
- boolean [] expandableRows = new boolean [1];
- OS.GetDataBrowserListViewDisclosureColumn (handle, disclosure, expandableRows);
- TreeColumn firstColumn = columns [order [0]];
- if (disclosure [0] != firstColumn.id) {
- OS.SetDataBrowserListViewDisclosureColumn (handle, firstColumn.id, expandableRows [0]);
- }
- int x = 0;
- short [] width = new short [1];
- int [] oldX = new int [oldOrder.length];
- for (int i=0; i<oldOrder.length; i++) {
- int index = oldOrder [i];
- TreeColumn column = columns [index];
- oldX [index] = x;
- OS.GetDataBrowserTableViewNamedColumnWidth(handle, column.id, width);
- x += width [0];
- }
- x = 0;
- int [] newX = new int [order.length];
- for (int i=0; i<order.length; i++) {
- int index = order [i];
- TreeColumn column = columns [index];
- int position = (style & SWT.CHECK) != 0 ? i + 1 : i;
- OS.SetDataBrowserTableViewColumnPosition(handle, column.id, position);
- column.lastPosition = position;
- newX [index] = x;
- OS.GetDataBrowserTableViewNamedColumnWidth(handle, column.id, width);
- x += width [0];
- }
- TreeColumn[] newColumns = new TreeColumn [columnCount];
- System.arraycopy (columns, 0, newColumns, 0, columnCount);
- for (int i=0; i<columnCount; i++) {
- TreeColumn column = newColumns [i];
- if (!column.isDisposed ()) {
- if (newX [i] != oldX [i]) {
- column.sendEvent (SWT.Move);
- }
- }
- }
- }
-}
-
-void setFontStyle (Font font) {
- super.setFontStyle (font);
- if (items == null) return;
- for (int i = 0; i < items.length; i++) {
- TreeItem item = items [i];
- if (item != null) item.width = -1;
- }
- setScrollWidth (true);
-}
-
-/**
- * Marks the receiver's header as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setHeaderVisible (boolean show) {
- checkWidget ();
- short [] height = new short [1];
- OS.GetDataBrowserListViewHeaderBtnHeight (handle, height);
- if ((height [0] != 0) != show) {
- OS.SetDataBrowserListViewHeaderBtnHeight (handle, (short) (show ? headerHeight : 0));
- invalidateVisibleRegion (handle);
- }
-}
-
-/**
- * Sets the number of root-level items contained in the receiver.
- *
- * @param count the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setItemCount (int count) {
- checkWidget ();
- count = Math.max (0, count);
- setItemCount (null, count);
-}
-
-void setItemCount (TreeItem parentItem, int count) {
- int itemCount = getItemCount (parentItem);
- if (count == itemCount) return;
- setRedraw (false);
- int [] top = new int [1], left = new int [1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- DataBrowserCallbacks callbacks = new DataBrowserCallbacks ();
- OS.GetDataBrowserCallbacks (handle, callbacks);
- callbacks.v1_itemNotificationCallback = 0;
- callbacks.v1_itemCompareCallback = 0;
- OS.SetDataBrowserCallbacks (handle, callbacks);
- int [] ids = parentItem == null ? childIds : parentItem.childIds;
- int removeCount = 0;
- if (count < itemCount) {
- int oldAnchor = savedAnchor;
- int selectionCount = getSelectionCount ();
- int [] removeIds = new int [itemCount - count];
- for (int index = ids.length - 1; index >= count; index--) {
- int id = ids [index];
- if (id != 0) {
- TreeItem item = _getItem (id, false);
- if (item != null && !item.isDisposed ()) {
- item.dispose ();
- } else {
- if (parentItem == null || parentItem.getExpanded ()) {
- removeIds [removeIds.length - removeCount - 1] = id;
- removeCount++;
- visibleCount--;
- }
- }
- }
- }
- if (removeCount != 0 && removeCount != removeIds.length) {
- int [] tmp = new int [removeCount];
- System.arraycopy(removeIds, removeIds.length - removeCount, tmp, 0, removeCount);
- removeIds = tmp;
- }
- if (removeCount != 0 && OS.RemoveDataBrowserItems (handle, OS.kDataBrowserNoItem, removeCount, removeIds, 0) != OS.noErr) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- boolean fixAnchor = selectionCount != 0 && getSelectionCount () == 0;
- if (fixAnchor || (savedAnchor != 0 && savedAnchor != oldAnchor)) {
- savedAnchor = 0;
- if (count == 0) {
- savedAnchor = parentItem == null ? 0 : parentItem.id;
- } else {
- int index = count - 1;
- if (0 <= index && index < ids.length) {
- savedAnchor = ids [index];
- }
- }
- }
-
- //TODO - move shrink to paint event
- // shrink items array
- int lastIndex = items.length;
- for (int i=items.length; i>0; i--) {
- if (items [i-1] != null) {
- lastIndex = i;
- break;
- }
- }
- if (lastIndex < items.length - 4) {
- int length = Math.max (4, (lastIndex + 3) / 4 * 4);
- TreeItem [] newItems = new TreeItem [length];
- System.arraycopy(items, 0, newItems, 0, Math.min(items.length, lastIndex));
- items = newItems;
- }
- }
-
- if (parentItem != null) parentItem.itemCount = count;
- int length = Math.max (4, (count + 3) / 4 * 4);
- int [] newIds = new int [length];
- if (ids != null) {
- System.arraycopy (ids, 0, newIds, 0, Math.min (count, itemCount));
- }
- ids = newIds;
- if (parentItem == null) {
- childIds = newIds;
- } else {
- parentItem.childIds = newIds;
- }
-
- if (count > itemCount) {
- if ((getStyle() & SWT.VIRTUAL) == 0) {
- int delta = Math.max (4, (count - itemCount + 3) / 4 * 4);
- TreeItem [] newItems = new TreeItem [items.length + delta];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- for (int i=itemCount; i<count; i++) {
- items [i] = new TreeItem (this, parentItem, SWT.NONE, i, true);
- }
- } else {
- if (parentItem == null || parentItem.getExpanded ()) {
- int parentID = parentItem == null ? OS.kDataBrowserNoItem : parentItem.id;
- int [] addIds = _getIds (count - itemCount);
- if (OS.AddDataBrowserItems (handle, parentID, addIds.length, addIds, OS.kDataBrowserItemNoProperty) != OS.noErr) {
- error (SWT.ERROR_ITEM_NOT_ADDED);
- }
- visibleCount += (count - itemCount);
- System.arraycopy (addIds, 0, ids, itemCount, addIds.length);
- }
- }
- }
-
- callbacks.v1_itemNotificationCallback = display.itemNotificationProc;
- callbacks.v1_itemCompareCallback = display.itemCompareProc;
- OS.SetDataBrowserCallbacks (handle, callbacks);
- if ((style & SWT.VIRTUAL) != 0 && sortColumn != null
- && !sortColumn.isDisposed () && sortDirection == SWT.DOWN) {
- OS.UpdateDataBrowserItems (handle, 0, 0, null, OS.kDataBrowserItemNoProperty, OS.kDataBrowserNoItem);
- }
- setRedraw (true);
- if (itemCount == 0 && parentItem != null) parentItem.redraw (OS.kDataBrowserNoItem);
- if (removeCount != 0) fixScrollBar ();
-}
-
-/*public*/ void setItemHeight (int itemHeight) {
- checkWidget ();
- if (itemHeight < -1) error (SWT.ERROR_INVALID_ARGUMENT);
- if (itemHeight == -1) {
- //TODO - reset item height, ensure other API's such as setFont don't do this
- } else {
- OS.SetDataBrowserTableViewRowHeight (handle, (short) itemHeight);
- }
-}
-
-void setItemHeight (Image image) {
- Rectangle bounds = image != null ? image.getBounds () : imageBounds;
- if (bounds == null) return;
- imageBounds = bounds;
- short [] height = new short [1];
- if (OS.GetDataBrowserTableViewRowHeight (handle, height) == OS.noErr) {
- if (height [0] < bounds.height) {
- OS.SetDataBrowserTableViewRowHeight (handle, (short) bounds.height);
- }
- }
-}
-
-/**
- * Marks the receiver's lines as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise. Note that some platforms draw
- * grid lines while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLinesVisible (boolean show) {
- checkWidget ();
- if (OS.VERSION >= 0x1040) {
- int attrib = OS.kDataBrowserAttributeListViewAlternatingRowColors | OS.kDataBrowserAttributeListViewDrawColumnDividers;
- OS.DataBrowserChangeAttributes (handle, show ? attrib : 0, !show ? attrib : 0);
- redraw ();
- }
-}
-
-public void setRedraw (boolean redraw) {
- checkWidget();
- super.setRedraw (redraw);
- if (redraw && drawCount == 0) {
- setScrollWidth (true);
- }
-}
-
-boolean setScrollWidth (TreeItem item) {
- if (ignoreRedraw || !getDrawing ()) return false;
- if (columnCount != 0) return false;
- TreeItem parentItem = item.parentItem;
- if (parentItem != null && !parentItem._getExpanded ()) return false;
- GC gc = new GC (this);
- int newWidth = item.calculateWidth (0, gc);
- gc.dispose ();
- newWidth += getInsetWidth (column_id, false);
- short [] width = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (handle, column_id, width);
- if (width [0] < newWidth) {
- OS.SetDataBrowserTableViewNamedColumnWidth (handle, column_id, (short) newWidth);
- return true;
- }
- return false;
-}
-
-boolean setScrollBarVisible (ScrollBar bar, boolean visible) {
- boolean [] horiz = new boolean [1], vert = new boolean [1];
- OS.GetDataBrowserHasScrollBars (handle, horiz, vert);
- if ((bar.style & SWT.H_SCROLL) != 0) horiz [0] = visible;
- if ((bar.style & SWT.V_SCROLL) != 0) vert [0] = visible;
- if (!visible) {
- bar.redraw ();
- bar.deregister ();
- }
- if (OS.SetDataBrowserHasScrollBars (handle, horiz [0], vert [0]) == OS.noErr) {
- if (visible) {
- bar.handle = findStandardBar (bar.style);
- bar.register ();
- bar.hookEvents ();
- bar.redraw ();
- } else {
- bar.handle = 0;
- }
- return true;
- } else {
- if (!visible) {
- bar.register ();
- }
- }
- return false;
-}
-
-boolean setScrollWidth (boolean set) {
- return setScrollWidth(set, childIds, true);
-}
-
-boolean setScrollWidth (boolean set, int[] childIds, boolean recurse) {
- if (ignoreRedraw || !getDrawing ()) return false;
- if (columnCount != 0 || childIds == null) return false;
- GC gc = new GC (this);
- int newWidth = calculateWidth (childIds, gc, recurse, 0, 0);
- gc.dispose ();
- newWidth += getInsetWidth (column_id, false);
- if (!set) {
- short [] width = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (handle, column_id, width);
- if (width [0] >= newWidth) return false;
- }
- OS.SetDataBrowserTableViewNamedColumnWidth (handle, column_id, (short) newWidth);
- return true;
-}
-
-/**
- * Sets the receiver's selection to the given item.
- * The current selection is cleared before the new item is selected.
- * <p>
- * If the item is not in the receiver, then it is ignored.
- * </p>
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (new TreeItem [] {item});
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- * </p>
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the items has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#deselectAll()
- */
-public void setSelection (TreeItem [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = items.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- int count = 0;
- int[] ids = new int [length];
- for (int i=0; i<length; i++) {
- if (items [i] != null) {
- if (items [i].isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- ids [count++] = items [i].id;
- showItem (items [i], false);
- }
- }
- ignoreSelect = true;
- /*
- * Bug in the Macintosh. When the DataBroswer selection flags includes
- * both kDataBrowserNeverEmptySelectionSet and kDataBrowserSelectOnlyOne,
- * two items are selected when SetDataBrowserSelectedItems() is called
- * with kDataBrowserItemsAssign to assign a new seletion despite the fact
- * that kDataBrowserSelectOnlyOne was specified. The fix is to save and
- * restore kDataBrowserNeverEmptySelectionSet around each call to
- * SetDataBrowserSelectedItems().
- */
- int [] selectionFlags = null;
- if ((style & SWT.SINGLE) != 0) {
- selectionFlags = new int [1];
- OS.GetDataBrowserSelectionFlags (handle, selectionFlags);
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0] & ~OS.kDataBrowserNeverEmptySelectionSet);
- }
- OS.SetDataBrowserSelectedItems (handle, count, ids, OS.kDataBrowserItemsAssign);
- if ((style & SWT.SINGLE) != 0) {
- OS.SetDataBrowserSelectionFlags (handle, selectionFlags [0]);
- }
- ignoreSelect = false;
- if (length > 0) {
- int index = -1;
- for (int i=0; i<items.length; i++) {
- if (items [i] != null) {
- index = i;
- break;
- }
- }
- if (index != -1) showItem (items [index], true);
- }
-}
-
-/**
- * Sets the column used by the sort indicator for the receiver. A null
- * value will clear the sort indicator. The current sort column is cleared
- * before the new column is set.
- *
- * @param column the column used by the sort indicator or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the column is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortColumn (TreeColumn column) {
- checkWidget ();
- if (column != null && column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (column == sortColumn) return;
- if (column == null) {
- if (sortColumn != null && !sortColumn.isDisposed () && sortDirection != SWT.NONE) {
- OS.SetDataBrowserSortOrder (handle, (short) OS.kDataBrowserOrderIncreasing);
- sortColumn = null;
- OS.SetDataBrowserSortProperty (handle, 0);
- }
- }
- sortColumn = column;
- if (sortColumn != null && !sortColumn.isDisposed () && sortDirection != SWT.NONE) {
- OS.SetDataBrowserSortProperty (handle, sortColumn.id);
- int order = sortDirection == SWT.DOWN ? OS.kDataBrowserOrderDecreasing : OS.kDataBrowserOrderIncreasing;
- OS.SetDataBrowserSortOrder (handle, (short) order);
- }
-}
-
-/**
- * Sets the direction of the sort indicator for the receiver. The value
- * can be one of <code>UP</code>, <code>DOWN</code> or <code>NONE</code>.
- *
- * @param direction the direction of the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortDirection (int direction) {
- checkWidget ();
- if (direction != SWT.UP && direction != SWT.DOWN && direction != SWT.NONE) return;
- if (direction == sortDirection) return;
- sortDirection = direction;
- if (sortColumn != null && !sortColumn.isDisposed ()) {
- if (sortDirection == SWT.NONE) {
- OS.SetDataBrowserSortOrder (handle, (short) OS.kDataBrowserOrderIncreasing);
- TreeColumn column = sortColumn;
- sortColumn = null;
- OS.SetDataBrowserSortProperty (handle, 0);
- sortColumn = column;
- } else {
- OS.SetDataBrowserSortProperty (handle, 0);
- OS.SetDataBrowserSortProperty (handle, sortColumn.id);
- int order = sortDirection == SWT.DOWN ? OS.kDataBrowserOrderDecreasing : OS.kDataBrowserOrderIncreasing;
- OS.SetDataBrowserSortOrder (handle, (short) order);
- }
- }
-}
-
-/**
- * Sets the item which is currently at the top of the receiver.
- * This item can change when items are expanded, collapsed, scrolled
- * or new items are added or removed.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getTopItem()
- *
- * @since 2.1
- */
-public void setTopItem (TreeItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- showItem (item, false);
- int itemHeight = getItemHeight ();
- int [] top = new int [1], left = new int [1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- int [] index = new int [1];
- OS.GetDataBrowserTableViewItemRow (handle, item.id, index);
- top [0] = Math.max (0, Math.min (itemHeight * visibleCount + getHeaderHeight () - getClientArea ().height, index [0] * itemHeight));
- OS.SetDataBrowserScrollPosition (handle, top [0], item.parentItem != null ? left [0] : 0);
-}
-
-/**
- * Shows the column. If the column is already showing in the receiver,
- * this method simply returns. Otherwise, the columns are scrolled until
- * the column is visible.
- *
- * @param column the column to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void showColumn (TreeColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (column.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (column.parent != this) return;
- int index = indexOf (column);
- if (columnCount <= 1 || !(0 <= index && index < columnCount)) return;
- // Get width and horizontal position of column
- short [] w = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (handle, column.id, w);
- int width = w [0];
- int x = 0;
- for (int i = 0; i < index; i++) {
- w = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (handle, columns[i].id, w);
- x += w [0];
- }
- // Get current scroll position
- int [] top = new int [1], left = new int [1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- // Scroll column into view
- if (x < left[0]) {
- OS.SetDataBrowserScrollPosition(handle, top [0], x);
- } else {
- Rectangle rect = getClientArea ();
- int maxWidth = rect.width;
- width = Math.min(width, maxWidth);
- if (x + width > left [0] + maxWidth) {
- left [0] = x + width - maxWidth;
- OS.SetDataBrowserScrollPosition(handle, top [0], left [0]);
- }
- }
-}
-
-/**
- * Shows the item. If the item is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled
- * and expanded until the item is visible.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#showSelection()
- */
-public void showItem (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- showItem (item, true);
-}
-
-void showItem (TreeItem item, boolean scroll) {
- int count = 0;
- TreeItem parentItem = item.parentItem;
- while (parentItem != null && !parentItem._getExpanded ()) {
- count++;
- parentItem = parentItem.parentItem;
- }
- int index = 0;
- parentItem = item.parentItem;
- TreeItem [] path = new TreeItem [count];
- while (parentItem != null && !parentItem._getExpanded ()) {
- path [index++] = parentItem;
- parentItem = parentItem.parentItem;
- }
- for (int i=path.length-1; i>=0; --i) {
- path [i].setExpanded (true);
- }
- if (scroll) {
- /*
- * Bug in the Macintosh. When there is not room to show a
- * single item in the data browser, RevealDataBrowserItem()
- * scrolls the item such that it is above the top of the data
- * browser. The fix is to remember the index and scroll when
- * the data browser is resized.
- *
- * Bug in the Macintosh. When items are added to the data
- * browser after is has been hidden, RevealDataBrowserItem()
- * when called before the controls behind the data browser
- * are repainted causes a redraw. This redraw happens right
- * away causing pixel corruption. The fix is to remember the
- * index and scroll when the data browser is shown.
- */
- Rectangle rect = getClientArea ();
- if (rect.height < getItemHeight () || !OS.IsControlVisible (handle)) {
- showItem = item;
- return;
- }
- showItem = null;
- Rectangle itemRect = item.getBounds ();
- if (!itemRect.isEmpty()) {
- if (rect.contains (itemRect.x, itemRect.y)
- && rect.contains (itemRect.x, itemRect.y + itemRect.height)) return;
- }
- int [] top = new int [1], left = new int [1];
- OS.GetDataBrowserScrollPosition (handle, top, left);
- int columnId = (style & SWT.CHECK) != 0 ? CHECK_COLUMN_ID : columnCount == 0 ? column_id : columns [0].id;
- int options = OS.kDataBrowserRevealWithoutSelecting;
- /*
- * This code is intentionally commented, since kDataBrowserRevealAndCenterInView
- * does not scroll the item to the center always (it seems to scroll to the
- * end in some cases).
- */
- //options |= OS.kDataBrowserRevealAndCenterInView;
- OS.RevealDataBrowserItem (handle, item.id, columnId, (byte) options);
- int [] newTop = new int [1], newLeft = new int [1];
- if (columnCount == 0) {
- boolean fixScroll = false;
- Rect content = new Rect ();
- if (OS.GetDataBrowserItemPartBounds (handle, item.id, columnId, OS.kDataBrowserPropertyContentPart, content) == OS.noErr) {
- fixScroll = content.left < rect.x || content.left >= rect.x + rect.width;
- if (!fixScroll) {
- GC gc = new GC (this);
- int contentWidth = calculateWidth (new int[]{item.id}, gc, false, 0, 0);
- gc.dispose ();
- fixScroll = content.left + contentWidth > rect.x + rect.width;
- }
- }
- if (fixScroll) {
- int leftScroll = getLeftDisclosureInset (columnId);
- int levelIndent = DISCLOSURE_COLUMN_LEVEL_INDENT;
- if (OS.VERSION >= 0x1040) {
- float [] metric = new float [1];
- OS.DataBrowserGetMetric (handle, OS.kDataBrowserMetricDisclosureColumnPerDepthGap, null, metric);
- levelIndent = (int) metric [0];
- }
- TreeItem temp = item;
- while (temp.parentItem != null) {
- leftScroll += levelIndent;
- temp = temp.parentItem;
- }
- OS.GetDataBrowserScrollPosition (handle, newTop, newLeft);
- OS.SetDataBrowserScrollPosition (handle, newTop [0], leftScroll);
- }
- }
-
- /*
- * Bug in the Macintosh. For some reason, when the DataBrowser is scrolled
- * by RevealDataBrowserItem(), the scrollbars are not redrawn. The fix is to
- * force a redraw.
- */
- OS.GetDataBrowserScrollPosition (handle, newTop, newLeft);
- if (horizontalBar != null && newLeft [0] != left [0]) horizontalBar.redraw ();
- if (verticalBar != null && newTop [0] != top [0]) verticalBar.redraw ();
- }
-}
-
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#showItem(TreeItem)
- */
-public void showSelection () {
- checkWidget ();
- //checkItems (false);
- //TODO - optimize
- TreeItem [] selection = getSelection ();
- if (selection.length > 0) showItem (selection [0], true);
-}
-
-int trackingProc (int browser, int id, int property, int theRect, int startPt, int modifiers) {
- return 1;
-}
-
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TreeColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TreeColumn.java
deleted file mode 100644
index 69fd5c4ad5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TreeColumn.java
+++ /dev/null
@@ -1,634 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.DataBrowserListViewHeaderDesc;
-import org.eclipse.swt.internal.carbon.OS;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a column in a tree widget.
- * <p><dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd> Move, Resize, Selection</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT and CENTER may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TreeColumn extends Item {
- Tree parent;
- int id, lastWidth, lastPosition, iconRef;
- boolean resizable;
- String toolTipText;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeColumn (Tree parent, int style) {
- super (parent, checkStyle (style));
- resizable = true;
- this.parent = parent;
- parent.createItem (this, parent.getColumnCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeColumn (Tree parent, int style, int index) {
- super (parent, checkStyle (style));
- resizable = true;
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize,typedListener);
- addListener (SWT.Move,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the column header is selected.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget ();
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Tree</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Tree getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Gets the moveable attribute. A column that is
- * not moveable cannot be reordered by the user
- * by dragging the header but may be reordered
- * by the programmer.
- *
- * @return the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
-public boolean getMoveable () {
- checkWidget ();
- int [] flags = new int [1];
- OS.GetDataBrowserPropertyFlags (parent.handle, id, flags);
- return (flags [0] & OS.kDataBrowserListViewMovableColumn) != 0;
-}
-
-/**
- * Gets the resizable attribute. A column that is
- * not resizable cannot be dragged by the user but
- * may be resized by the programmer.
- *
- * @return the resizable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getResizable () {
- checkWidget ();
- return resizable;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget ();
- short [] width = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (parent.handle, id, width);
- return Math.max (0, width [0] + parent.getLeftDisclosureInset (id));
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void pack () {
- checkWidget ();
- GC gc = new GC (parent);
- int width = gc.stringExtent (text).x;
- if (iconRef != 0 || (image != null && OS.VERSION >= 0x1040)) {
- /* Note that the image is stretched to the header height */
- width += parent.headerHeight;
- if (text.length () != 0) width += parent.getGap ();
- }
- int index = parent.indexOf (this);
- width = Math.max (width, calculateWidth (parent.childIds, index, gc, width));
-
- gc.dispose ();
- setWidth (width + parent.getInsetWidth (id, true));
-}
-
-int calculateWidth (int[] ids, int index, GC gc, int width) {
- int max = width;
- if (ids == null) return max;
- for (int i=0; i<ids.length; i++) {
- TreeItem item = parent._getItem (ids [i], false);
- if (item != null && item.cached) {
- max = Math.max (max, item.calculateWidth (index, gc));
- if (item.getExpanded ()) {
- max = Math.max (max, calculateWidth (item.childIds, index, gc, max));
- }
- }
- }
- return max;
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- id = -1;
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (parent.sortColumn == this) {
- parent.sortColumn = null;
- }
- if (iconRef != 0) OS.ReleaseIconRef (iconRef);
- iconRef = 0;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-void resized (int newWidth) {
- lastWidth = newWidth;
- sendEvent (SWT.Resize);
- if (isDisposed ()) return;
- boolean moved = false;
- int [] order = parent.getColumnOrder ();
- TreeColumn [] columns = parent.getColumns ();
- for (int i=0; i<order.length; i++) {
- TreeColumn column = columns [order [i]];
- if (moved && !column.isDisposed ()) {
- column.sendEvent (SWT.Move);
- }
- if (column == this) moved = true;
- }
-}
-
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>.
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget ();
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- int index = parent.indexOf (this);
- if (index == -1 || index == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- updateHeader ();
-}
-
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int index = parent.indexOf (this);
- if (index == -1) return;
- if (iconRef != 0) {
- OS.ReleaseIconRef (iconRef);
- iconRef = 0;
- }
- super.setImage (image);
- if (image != null) {
- if (OS.VERSION < 0x1040) {
- iconRef = createIconRef (image);
- }
- }
- updateHeader ();
-}
-
-/**
- * Sets the moveable attribute. A column that is
- * moveable can be reordered by the user by dragging
- * the header. A column that is not moveable cannot be
- * dragged by the user but may be reordered
- * by the programmer.
- *
- * @param moveable the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#setColumnOrder(int[])
- * @see Tree#getColumnOrder()
- * @see TreeColumn#getMoveable()
- * @see SWT#Move
- *
- * @since 3.2
- */
-public void setMoveable (boolean moveable) {
- checkWidget ();
- int [] flags = new int [1];
- OS.GetDataBrowserPropertyFlags (parent.handle, id, flags);
- if (moveable) {
- flags [0] |= OS.kDataBrowserListViewMovableColumn;
- } else {
- flags [0] &= ~OS.kDataBrowserListViewMovableColumn;
- }
- OS.SetDataBrowserPropertyFlags (parent.handle, id, flags [0]);
-}
-
-/**
- * Sets the resizable attribute. A column that is
- * not resizable cannot be dragged by the user but
- * may be resized by the programmer.
- *
- * @param resizable the resize attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setResizable (boolean resizable) {
- checkWidget ();
- this.resizable = resizable;
- updateHeader ();
-}
-
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- updateHeader ();
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
-}
-
-/**
- * Sets the width of the receiver.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int width) {
- checkWidget ();
- if (width < 0) return;
- /*
- * Feature in the Macintosh. The data browser widget adds the left inset
- * of the disclosure column to the specified width making the column too
- * wide. The fix is to subtract this value from the column width.
- */
- width -= parent.getLeftDisclosureInset (id);
- if (width < 0) width = 0;
- OS.SetDataBrowserTableViewNamedColumnWidth (parent.handle, id, (short) width);
- updateHeader ();
- if (width != lastWidth) resized (width);
-}
-
-void updateHeader () {
- char [] buffer = new char [text.length ()];
- text.getChars (0, buffer.length, buffer, 0);
- int length = fixMnemonic (buffer);
- int str = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, length);
- if (str == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- DataBrowserListViewHeaderDesc desc = new DataBrowserListViewHeaderDesc ();
- desc.version = OS.kDataBrowserListViewLatestHeaderDesc;
- desc.btnFontStyle_just = OS.teFlushLeft;
- if (parent.indexOf (this) != 0) {
- if ((style & SWT.CENTER) != 0) desc.btnFontStyle_just = OS.teCenter;
- if ((style & SWT.RIGHT) != 0) desc.btnFontStyle_just = OS.teFlushRight;
- }
- desc.btnFontStyle_flags |= OS.kControlUseJustMask;
- if (resizable) {
- desc.minimumWidth = 0;
- desc.maximumWidth = 0x7fff;
- } else {
- short [] width = new short [1];
- OS.GetDataBrowserTableViewNamedColumnWidth (parent.handle, id, width);
- desc.minimumWidth = desc.maximumWidth = width [0];
- }
- desc.titleString = str;
- if (OS.VERSION < 0x1040) {
- desc.btnContentInfo_contentType = (short) (iconRef != 0 ? OS.kControlContentIconRef : OS.kControlContentTextOnly);
- desc.btnContentInfo_iconRef = iconRef;
- } else {
- if (image != null) {
- desc.btnContentInfo_contentType = OS.kControlContentCGImageRef;
- desc.btnContentInfo_iconRef = image.handle;
- }
- }
- OS.SetDataBrowserListViewHeaderDesc (parent.handle, id, desc);
- OS.CFRelease (str);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TreeItem.java
deleted file mode 100644
index 2027e55e11..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TreeItem.java
+++ /dev/null
@@ -1,1435 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.carbon.DataBrowserCallbacks;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.Rect;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a hierarchy of tree items in a tree widget.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TreeItem extends Item {
- Tree parent;
- TreeItem parentItem;
- String [] strings;
- Image [] images;
- boolean checked, grayed, cached;
- Color foreground, background;
- Color[] cellForeground, cellBackground;
- Font font;
- Font[] cellFont;
- int id, width = -1;
- int itemCount = 0;
- int [] childIds;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>)
- * and a style value describing its behavior and appearance.
- * The item is added to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (Tree parent, int style) {
- this (checkNull (parent), null, style, -1, true);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>),
- * a style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (Tree parent, int style, int index) {
- this (checkNull (parent), null, style, checkIndex (index), true);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>)
- * and a style value describing its behavior and appearance.
- * The item is added to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parentItem a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (TreeItem parentItem, int style) {
- this (checkNull (parentItem).parent, parentItem, style, -1, true);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>),
- * a style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parentItem a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (TreeItem parentItem, int style, int index) {
- this (checkNull (parentItem).parent, parentItem, style, checkIndex (index), true);
-}
-
-TreeItem (Tree parent, TreeItem parentItem, int style, int index, boolean create) {
- super (parent, style);
- this.parent = parent;
- this.parentItem = parentItem;
- if (create) parent.createItem (this, parentItem, index);
-}
-
-boolean _getExpanded () {
- int [] state = new int [1];
- OS.GetDataBrowserItemState (parent.handle, id, state);
- return (state [0] & OS.kDataBrowserContainerIsOpen) != 0;
-}
-
-static TreeItem checkNull (TreeItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-
-static Tree checkNull (Tree parent) {
- if (parent == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return parent;
-}
-
-static int checkIndex (int index) {
- if (index < 0) SWT.error (SWT.ERROR_INVALID_RANGE);
- return index;
-}
-
-int calculateWidth (int index, GC gc) {
- if (index == 0 && width != -1) return width;
- int width = 0;
- Image image = index == 0 ? this.image : (images == null ? null : images [index]);
- String text = index == 0 ? this.text : (strings == null ? "" : strings [index]);
- Font font = null;
- if (cellFont != null) font = cellFont[index];
- if (font == null) font = this.font;
- if (font == null) font = parent.getFont();
- gc.setFont (font);
- if (image != null) width += image.getBounds ().width + parent.getGap ();
- if (text != null && text.length () > 0) width += gc.stringExtent (text).x;
- boolean sendMeasure = true;
- if ((parent.style & SWT.VIRTUAL) != 0) {
- sendMeasure = cached;
- }
- if (sendMeasure && parent.hooks (SWT.MeasureItem)) {
- Event event = new Event ();
- event.item = this;
- event.index = index;
- event.gc = gc;
- short [] height = new short [1];
- OS.GetDataBrowserTableViewRowHeight (parent.handle, height);
- event.width = width;
- event.height = height [0];
- parent.sendEvent (SWT.MeasureItem, event);
- if (height [0] < event.height) {
- OS.SetDataBrowserTableViewRowHeight (parent.handle, (short) event.height);
- redrawWidget (parent.handle, false);
- }
- width = event.width;
- }
- if (index == 0) this.width = width;
- return width;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void clear () {
- cached = false;
- text = "";
- image = null;
- strings = null;
- images = null;
- checked = grayed = false;
- foreground = background = null;
- cellForeground = cellBackground = null;
- font = null;
- cellFont = null;
-}
-
-/**
- * Clears the item at the given zero-relative index in the receiver.
- * The text, icon and other attributes of the item are set to the default
- * value. If the tree was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param index the index of the item to clear
- * @param all <code>true</code> if all child items of the indexed item should be
- * cleared recursively, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clear (int index, boolean all) {
- checkWidget ();
- int count = parent.getItemCount (this);
- if (index < 0 || index >= count) SWT.error (SWT.ERROR_INVALID_RANGE);
- parent.clear (this, index, all);
-}
-
-
-/**
- * Clears all the items in the receiver. The text, icon and other
- * attributes of the items are set to their default values. If the
- * tree was created with the <code>SWT.VIRTUAL</code> style, these
- * attributes are requested again as needed.
- *
- * @param all <code>true</code> if all child items should be cleared
- * recursively, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clearAll (boolean all) {
- checkWidget ();
- parent.clearAll (this, all);
-}
-
-void destroyWidget () {
- //TEMPORARY CODE
-// parent.releaseItem (this, false);
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns the receiver's background color.
- *
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public Color getBackground () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return background != null ? background : parent.getBackground ();
-}
-
-/**
- * Returns the background color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Color getBackground (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count -1) return getBackground ();
- if (cellBackground == null || cellBackground [index] == null) return getBackground ();
- return cellBackground [index];
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- Rect rect = new Rect();
- int columnId = parent.columnCount == 0 ? parent.column_id : parent.columns [0].id;
- if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyContentPart, rect) != OS.noErr) {
- return new Rectangle (0, 0, 0, 0);
- }
- int x = rect.left, y = rect.top;
- int width = 0;
- if (image != null) {
- Rectangle bounds = image.getBounds ();
- x += bounds.width + parent.getGap ();
- }
- GC gc = new GC (parent);
- Point extent = gc.stringExtent (text);
- gc.dispose ();
- width += extent.x;
- if (parent.columnCount > 0) {
- width = Math.min (width, rect.right - x);
- }
- int height = rect.bottom - rect.top;
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent at a column in the tree.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding column rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Rectangle getBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index != 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0);
- Rect rect = new Rect();
- int columnId = parent.columnCount == 0 ? parent.column_id : parent.columns [index].id;
- if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyEnclosingPart, rect) != OS.noErr) {
- return new Rectangle (0, 0, 0, 0);
- }
- int[] disclosure = new int [1];
- OS.GetDataBrowserListViewDisclosureColumn (parent.handle, disclosure, new boolean [1]);
- int x, y, width, height;
- if (OS.VERSION >= 0x1040 && disclosure [0] != columnId) {
- if (parent.getLinesVisible ()) {
- rect.left += Tree.GRID_WIDTH;
- rect.top += Tree.GRID_WIDTH;
- }
- x = rect.left;
- y = rect.top;
- width = rect.right - rect.left;
- height = rect.bottom - rect.top;
- } else {
- Rect rect2 = new Rect();
- if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyContentPart, rect2) != OS.noErr) {
- return new Rectangle (0, 0, 0, 0);
- }
- x = rect2.left;
- y = rect2.top;
- width = rect.right - rect2.left + 1;
- height = rect2.bottom - rect2.top + 1;
- }
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is checked,
- * and false otherwise. When the parent does not have
- * the <code>CHECK style, return false.
- * <p>
- *
- * @return the checked state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getChecked () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return checked;
-}
-
-/**
- * Returns <code>true</code> if the receiver is expanded,
- * and false otherwise.
- * <p>
- *
- * @return the expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getExpanded () {
- checkWidget ();
- return (state & EXPANDING) != 0 ? false : _getExpanded ();
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information for this item.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return font != null ? font : parent.getFont ();
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information
- * for the specified cell in this item.
- *
- * @param index the column index
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Font getFont (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count -1) return getFont ();
- if (cellFont == null || cellFont [index] == null) return getFont ();
- return cellFont [index];
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public Color getForeground () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return foreground != null ? foreground : parent.getForeground ();
-}
-
-/**
- *
- * Returns the foreground color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Color getForeground (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count -1) return getForeground ();
- if (cellForeground == null || cellForeground [index] == null) return getForeground ();
- return cellForeground [index];
-}
-
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the parent does not have
- * the <code>CHECK style, return false.
- * <p>
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getGrayed () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return grayed;
-}
-
-public Image getImage () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return super.getImage ();
-}
-
-/**
- * Returns the image stored at the given column index in the receiver,
- * or null if the image has not been set or if the column does not exist.
- *
- * @param index the column index
- * @return the image stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Image getImage (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index == 0) return getImage ();
- if (images != null) {
- if (0 <= index && index < images.length) return images [index];
- }
- return null;
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of an image at a column in the
- * tree.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding image rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Rectangle getImageBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index != 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0);
- Rect rect = new Rect();
- int columnId = parent.columnCount == 0 ? parent.column_id : parent.columns [index].id;
- if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyContentPart, rect) != OS.noErr) {
- return new Rectangle (0, 0, 0, 0);
- }
- int x = rect.left, y = rect.top;
- int width = 0;
- if (index == 0 && image != null) {
- Rectangle bounds = image.getBounds ();
- width += bounds.width;
- }
- if (index != 0 && images != null && images[index] != null) {
- Rectangle bounds = images [index].getBounds ();
- width += bounds.width;
- }
- int height = rect.bottom - rect.top + 1;
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public TreeItem getItem (int index) {
- checkWidget ();
- if (index < 0) error (SWT.ERROR_INVALID_RANGE);
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index >= itemCount) error (SWT.ERROR_INVALID_RANGE);
- return parent._getItem (this, index);
-}
-
-/**
- * Returns the number of items contained in the receiver
- * that are direct item children of the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getItemCount (this);
-}
-
-/**
- * Returns a (possibly empty) array of <code>TreeItem</code>s which
- * are the direct item children of the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem [] getItems () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getItems (this);
-}
-
-String getNameText () {
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (!cached) return "*virtual*"; //$NON-NLS-1$
- }
- return super.getNameText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Tree</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Tree getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>TreeItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem getParentItem () {
- checkWidget ();
- return parentItem;
-}
-
-public String getText () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return super.getText ();
-}
-
-/**
- * Returns the text stored at the given column index in the receiver,
- * or empty string if the text has not been set.
- *
- * @param index the column index
- * @return the text stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public String getText (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index == 0) return getText ();
- if (strings != null) {
- if (0 <= index && index < strings.length) {
- String string = strings [index];
- return string != null ? string : "";
- }
- }
- return "";
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of the text at a column in the
- * tree.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding text rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Rectangle getTextBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index != 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0);
- Rect rect = new Rect();
- int columnId = parent.columnCount == 0 ? parent.column_id : parent.columns [index].id;
- if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyEnclosingPart, rect) != OS.noErr) {
- return new Rectangle (0, 0, 0, 0);
- }
- int[] disclosure = new int [1];
- OS.GetDataBrowserListViewDisclosureColumn (parent.handle, disclosure, new boolean [1]);
- int imageWidth = 0;
- int margin = index == 0 ? 0 : parent.getInsetWidth (columnId, false) / 2;
- Image image = getImage (index);
- if (image != null) {
- Rectangle bounds = image.getBounds ();
- imageWidth = bounds.width + parent.getGap ();
- }
- int x, y, width, height;
- if (OS.VERSION >= 0x1040 && disclosure [0] != columnId) {
- if (parent.getLinesVisible ()) {
- rect.left += Tree.GRID_WIDTH;
- rect.top += Tree.GRID_WIDTH;
- }
- x = rect.left + imageWidth + margin;
- y = rect.top;
- width = Math.max (0, rect.right - rect.left - imageWidth - margin * 2);;
- height = rect.bottom - rect.top;
- } else {
- Rect rect2 = new Rect();
- if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyContentPart, rect2) != OS.noErr) {
- return new Rectangle (0, 0, 0, 0);
- }
- x = rect2.left + imageWidth + margin;
- y = rect2.top;
- width = Math.max (0, rect.right - rect2.left + 1 - imageWidth - margin * 2);
- height = rect2.bottom - rect2.top + 1;
- }
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int indexOf (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (item.parentItem != this) return -1;
- return parent._indexOf (this, item);
-}
-
-void redraw (int propertyID) {
- if (parent.ignoreRedraw) return;
- if (!getDrawing () && propertyID != Tree.CHECK_COLUMN_ID) return;
- int parentHandle = parent.handle;
- int parentID = parentItem == null ? OS.kDataBrowserNoItem : parentItem.id;
- /*
- * Feature in Carbon. Calling UpdateDataBrowserItems with kDataBrowserNoItem
- * updates all columns associated with the items in the items array. This is
- * much slower than updating the items array for a specific column. The fix
- * is to give the specific column ids instead.
- */
- DataBrowserCallbacks callbacks = new DataBrowserCallbacks ();
- OS.GetDataBrowserCallbacks (parent.handle, callbacks);
- callbacks.v1_itemCompareCallback = 0;
- OS.SetDataBrowserCallbacks (parent.handle, callbacks);
- int [] ids = new int [] {id};
- if (propertyID == OS.kDataBrowserNoItem) {
- if ((parent.style & SWT.CHECK) != 0) {
- OS.UpdateDataBrowserItems (parentHandle, parentID, ids.length, ids, OS.kDataBrowserItemNoProperty, Tree.CHECK_COLUMN_ID);
- }
- if (parent.columnCount == 0) {
- OS.UpdateDataBrowserItems (parentHandle, parentID, ids.length, ids, OS.kDataBrowserItemNoProperty, parent.column_id);
- } else {
- for (int i=0; i<parent.columnCount; i++) {
- OS.UpdateDataBrowserItems (parentHandle, parentID, ids.length, ids, OS.kDataBrowserItemNoProperty, parent.columns[i].id);
- }
- }
- } else {
- OS.UpdateDataBrowserItems (parentHandle, parentID, ids.length, ids, OS.kDataBrowserItemNoProperty, propertyID);
- }
- callbacks.v1_itemCompareCallback = display.itemCompareProc;
- OS.SetDataBrowserCallbacks (parent.handle, callbacks);
- /*
- * Bug in the Macintosh. When the height of the row is smaller than the
- * check box, the tail of the check mark draws outside of the item part
- * bounds. This means it will not be redrawn when the item is unckeched.
- * The fix is to redraw the area.
- */
- if (propertyID == Tree.CHECK_COLUMN_ID) {
- Rect rect = new Rect();
- if (OS.GetDataBrowserItemPartBounds (parentHandle, id, propertyID, OS.kDataBrowserPropertyEnclosingPart, rect) == OS.noErr) {
- int x = rect.left;
- int y = rect.top - 1;
- int width = rect.right - rect.left;
- int height = 1;
- redrawWidget (parentHandle, x, y, width, height, false);
- }
- }
-}
-
-void releaseChildren (boolean destroy) {
- if (destroy) {
- parent.releaseItems (childIds);
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parentItem = null;
- id = 0;
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- strings = null;
- images = null;
- background = foreground = null;
- font = null;
- cellBackground = cellForeground = null;
- cellFont = null;
-}
-
-/**
- * Removes all of the items from the receiver.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void removeAll () {
- checkWidget ();
- for (int i=itemCount - 1; i >= 0; i--) {
- TreeItem item = parent._getItem (childIds [i], false);
- if (item != null && !item.isDisposed ()) {
- item.dispose ();
- }
- }
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public void setBackground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Color oldColor = background;
- if (oldColor == color) return;
- background = color;
- if (oldColor != null && oldColor.equals (color)) return;
- cached = true;
- redraw (OS.kDataBrowserNoItem);
-}
-
-/**
- * Sets the background color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- *
- */
-public void setBackground (int index, Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count - 1) return;
- if (cellBackground == null) {
- if (color == null) return;
- cellBackground = new Color [count];
- }
- Color oldColor = cellBackground [index];
- if (oldColor == color) return;
- cellBackground [index] = color;
- if (oldColor != null && oldColor.equals (color)) return;
- cached = true;
- int columnId = parent.columnCount == 0 ? parent.column_id : parent.columns [index].id;
- redraw (columnId);
-}
-
-/**
- * Sets the checked state of the receiver.
- * <p>
- *
- * @param checked the new checked state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setChecked (boolean checked) {
- checkWidget ();
- if ((parent.style & SWT.CHECK) == 0) return;
- if (this.checked == checked) return;
- setChecked (checked, false);
-}
-
-void setChecked (boolean checked, boolean notify) {
- this.checked = checked;
- cached = true;
- redraw (Tree.CHECK_COLUMN_ID);
- if (notify) {
- Event event = new Event ();
- event.item = this;
- event.detail = SWT.CHECK;
- parent.postEvent (SWT.Selection, event);
- }
-}
-
-/**
- * Sets the expanded state of the receiver.
- * <p>
- *
- * @param expanded the new expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setExpanded (boolean expanded) {
- checkWidget ();
- if (expanded == getExpanded ()) return;
- parent.ignoreExpand = true;
- if (expanded) {
- OS.OpenDataBrowserContainer (parent.handle, id);
- } else {
- OS.CloseDataBrowserContainer (parent.handle, id);
- }
- parent.ignoreExpand = false;
- cached = true;
- if (expanded) {
- parent.setScrollWidth (false, childIds, false);
- } else {
- parent.setScrollWidth (true);
- parent.fixScrollBar ();
- }
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for this item to the font specified by the argument, or to the default font
- * for that kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (Font font) {
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Font oldFont = this.font;
- if (oldFont == font) return;
- this.font = font;
- if (oldFont != null && oldFont.equals (font)) return;
- cached = true;
- redraw (OS.kDataBrowserNoItem);
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for the specified cell in this item to the font specified by the
- * argument, or to the default font for that kind of control if the
- * argument is null.
- *
- * @param index the column index
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setFont (int index, Font font) {
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count - 1) return;
- if (cellFont == null) {
- if (font == null) return;
- cellFont = new Font [count];
- }
- Font oldFont = cellFont [index];
- if (oldFont == font) return;
- cellFont [index] = font;
- if (oldFont != null && oldFont.equals (font)) return;
- cached = true;
- int columnId = parent.columnCount == 0 ? parent.column_id : parent.columns [index].id;
- redraw (columnId);
-}
-
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @since 2.0
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public void setForeground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Color oldColor = this.foreground;
- if (oldColor == color) return;
- foreground = color;
- if (oldColor != null && oldColor.equals (color)) return;
- cached = true;
- redraw (OS.kDataBrowserNoItem);
-}
-
-/**
- * Sets the foreground color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- *
- */
-public void setForeground (int index, Color color){
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count - 1) return;
- if (cellForeground == null) {
- if (color == null) return;
- cellForeground = new Color [count];
- }
- Color oldColor = cellForeground [index];
- if (oldColor == color) return;
- cellForeground [index] = color;
- if (oldColor != null && oldColor.equals (color)) return;
- cached = true;
- int columnId = parent.columnCount == 0 ? parent.column_id : parent.columns [index].id;
- redraw (columnId);
-}
-
-/**
- * Sets the grayed state of the checkbox for this item. This state change
- * only applies if the Tree was created with the SWT.CHECK style.
- *
- * @param grayed the new grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setGrayed (boolean grayed) {
- checkWidget ();
- if ((parent.style & SWT.CHECK) == 0) return;
- if (this.grayed == grayed) return;
- this.grayed = grayed;
- cached = true;
- redraw (Tree.CHECK_COLUMN_ID);
-}
-
-/**
- * Sets the image for multiple columns in the tree.
- *
- * @param images the array of new images
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setImage (Image [] images) {
- checkWidget ();
- if (images == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<images.length; i++) {
- setImage (i, images [i]);
- }
-}
-
-/**
- * Sets the receiver's image at a column.
- *
- * @param index the column index
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setImage (int index, Image image) {
- checkWidget ();
- if (image != null && image.isDisposed ()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (parent.imageBounds == null && image != null) {
- parent.setItemHeight (image);
- }
- if (index == 0) {
- if (image != null && image.type == SWT.ICON) {
- if (image.equals (this.image)) return;
- }
- width = -1;
- super.setImage (image);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 <= index && index < count) {
- if (images == null) images = new Image [count];
- if (image != null && image.type == SWT.ICON) {
- if (image.equals (images [index])) return;
- }
- images [index] = image;
- }
- cached = true;
- if (index == 0) parent.setScrollWidth (this);
- if (0 <= index && index < count) {
- int columnId = parent.columnCount == 0 ? parent.column_id : parent.columns [index].id;
- redraw (columnId);
- }
-}
-
-public void setImage (Image image) {
- checkWidget ();
- setImage (0, image);
-}
-
-/**
- * Sets the number of child items contained in the receiver.
- *
- * @param count the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setItemCount (int count) {
- checkWidget ();
- count = Math.max (0, count);
- parent.setItemCount (this, count);
-}
-
-/**
- * Sets the text for multiple columns in the tree.
- *
- * @param strings the array of new strings
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setText (String [] strings) {
- checkWidget ();
- if (strings == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<strings.length; i++) {
- String string = strings [i];
- if (string != null) setText (i, string);
- }
-}
-
-/**
- * Sets the receiver's text at a column
- *
- * @param index the column index
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setText (int index, String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (index == 0) {
- if (string.equals (text)) return;
- width = -1;
- super.setText (string);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 <= index && index < count) {
- if (strings == null) strings = new String [count];
- if (string.equals (strings [index])) return;
- strings [index] = string;
- }
- cached = true;
- if (index == 0) parent.setScrollWidth (this);
- if (0 <= index && index < count) {
- int columnId = parent.columnCount == 0 ? parent.column_id : parent.columns [index].id;
- redraw (columnId);
- }
-}
-
-public void setText (String string) {
- checkWidget ();
- setText (0, string);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Widget.java
deleted file mode 100644
index f570e5f952..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Widget.java
+++ /dev/null
@@ -1,2112 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.carbon.CFRange;
-import org.eclipse.swt.internal.carbon.CGRect;
-import org.eclipse.swt.internal.carbon.OS;
-import org.eclipse.swt.internal.carbon.RGBColor;
-import org.eclipse.swt.internal.carbon.Rect;
-import org.eclipse.swt.internal.carbon.PixMap;
-import org.eclipse.swt.internal.carbon.BitMap;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * This class is the abstract superclass of all user interface objects.
- * Widgets are created, disposed and issue notification to listeners
- * when events occur which affect them.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Dispose</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation. However, it has not been marked
- * final to allow those outside of the SWT development team to implement
- * patched versions of the class in order to get around specific
- * limitations in advance of when those limitations can be addressed
- * by the team. Any class built using subclassing to access the internals
- * of this class will likely fail to compile or run between releases and
- * may be strongly platform specific. Subclassing should not be attempted
- * without an intimate and detailed understanding of the workings of the
- * hierarchy. No support is provided for user-written classes which are
- * implemented as subclasses of this class.
- * </p>
- *
- * @see #checkSubclass
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class Widget {
- int style, state;
- Display display;
- EventTable eventTable;
- Object data;
-
- /* Global state flags */
- static final int DISPOSED = 1 << 0;
- static final int CANVAS = 1 << 1;
- static final int KEYED_DATA = 1 << 2;
- static final int DISABLED = 1 << 3;
- static final int HIDDEN = 1 << 4;
- static final int GRAB = 1 << 5;
- static final int MOVED = 1 << 6;
- static final int RESIZED = 1 << 7;
- static final int EXPANDING = 1 << 8;
- static final int IGNORE_WHEEL = 1 << 9;
- static final int PARENT_BACKGROUND = 1 << 10;
- static final int THEME_BACKGROUND = 1 << 11;
-
- /* A layout was requested on this widget */
- static final int LAYOUT_NEEDED = 1<<12;
-
- /* The preferred size of a child has changed */
- static final int LAYOUT_CHANGED = 1<<13;
-
- /* A layout was requested in this widget hierachy */
- static final int LAYOUT_CHILD = 1<<14;
-
- /* More global state flags */
- static final int RELEASED = 1<<15;
- static final int DISPOSE_SENT = 1<<16;
- static final int FOREIGN_HANDLE = 1<<17;
- static final int DRAG_DETECT = 1<<18;
-
- /* Safari fixes */
- static final int SAFARI_EVENTS_FIX = 1<<19;
- static final String SAFARI_EVENTS_FIX_KEY = "org.eclipse.swt.internal.safariEventsFix"; //$NON-NLS-1$
-
- /* Default size for widgets */
- static final int DEFAULT_WIDTH = 64;
- static final int DEFAULT_HEIGHT = 64;
-
- static final Rect EMPTY_RECT = new Rect ();
-
-
-Widget () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see #checkSubclass
- * @see #getStyle
- */
-public Widget (Widget parent, int style) {
- checkSubclass ();
- checkParent (parent);
- this.style = style;
- display = parent.display;
-}
-
-int actionProc (int theControl, int partCode) {
- return OS.eventNotHandledErr;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs. When the
- * event does occur in the widget, the listener is notified by
- * sending it the <code>handleEvent()</code> message. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #getListeners(int)
- * @see #removeListener(int, Listener)
- * @see #notifyListeners
- */
-public void addListener (int eventType, Listener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- _addListener (eventType, listener);
-}
-
-void _addListener (int eventType, Listener listener) {
- if (eventTable == null) eventTable = new EventTable ();
- eventTable.hook (eventType, listener);
-}
-
-int callPaintEventHandler (int control, int damageRgn, int visibleRgn, int theEvent, int nextHandler) {
- return OS.CallNextEventHandler (nextHandler, theEvent);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the widget is disposed. When the widget is
- * disposed, the listener is notified by sending it the
- * <code>widgetDisposed()</code> message.
- *
- * @param listener the listener which should be notified when the receiver is disposed
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DisposeListener
- * @see #removeDisposeListener
- */
-public void addDisposeListener (DisposeListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Dispose, typedListener);
-}
-
-static int checkBits (int style, int int0, int int1, int int2, int int3, int int4, int int5) {
- int mask = int0 | int1 | int2 | int3 | int4 | int5;
- if ((style & mask) == 0) style |= int0;
- if ((style & int0) != 0) style = (style & ~mask) | int0;
- if ((style & int1) != 0) style = (style & ~mask) | int1;
- if ((style & int2) != 0) style = (style & ~mask) | int2;
- if ((style & int3) != 0) style = (style & ~mask) | int3;
- if ((style & int4) != 0) style = (style & ~mask) | int4;
- if ((style & int5) != 0) style = (style & ~mask) | int5;
- return style;
-}
-
-void calculateVisibleRegion (int control, int visibleRgn, boolean clipChildren) {
- int tempRgn = OS.NewRgn ();
- if (OS.IsControlVisible (control)) {
- int childRgn = OS.NewRgn ();
- int window = OS.GetControlOwner (control);
- short [] count = new short [1];
- int [] outControl = new int [1];
- OS.GetRootControl (window, outControl);
- int root = outControl [0];
- OS.GetControlRegion (root, (short) OS.kControlStructureMetaPart, visibleRgn);
- int tempControl = control, lastControl = 0;
- while (tempControl != root) {
- OS.GetControlRegion (tempControl, (short) OS.kControlStructureMetaPart, tempRgn);
- OS.HIViewConvertRegion (tempRgn, tempControl, root);
- OS.SectRgn (tempRgn, visibleRgn, visibleRgn);
- if (OS.EmptyRgn (visibleRgn)) break;
- if (clipChildren || tempControl != control) {
- OS.CountSubControls (tempControl, count);
- for (int i = 0; i < count [0]; i++) {
- OS.GetIndexedSubControl (tempControl, (short)(count [0] - i), outControl);
- int child = outControl [0];
- if (child == lastControl) break;
- if (!OS.IsControlVisible (child)) continue;
- OS.GetControlRegion (child, (short) OS.kControlStructureMetaPart, tempRgn);
- OS.HIViewConvertRegion (tempRgn, child, root);
- OS.UnionRgn (tempRgn, childRgn, childRgn);
- }
- }
- lastControl = tempControl;
- OS.GetSuperControl (tempControl, outControl);
- tempControl = outControl [0];
- }
- OS.DiffRgn (visibleRgn, childRgn, visibleRgn);
- OS.DisposeRgn (childRgn);
- } else {
- OS.CopyRgn (tempRgn, visibleRgn);
- }
- OS.DisposeRgn (tempRgn);
-}
-
-void checkOpen () {
- /* Do nothing */
-}
-
-void checkOrientation (Widget parent) {
- style &= ~SWT.MIRRORED;
- if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) {
- if (parent != null) {
- if ((parent.style & SWT.LEFT_TO_RIGHT) != 0) style |= SWT.LEFT_TO_RIGHT;
- if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) style |= SWT.RIGHT_TO_LEFT;
- }
- }
- style = checkBits (style, SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT, 0, 0, 0, 0);
-}
-
-void checkParent (Widget parent) {
- if (parent == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (parent.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- parent.checkWidget ();
- parent.checkOpen ();
-}
-
-/**
- * Checks that this class can be subclassed.
- * <p>
- * The SWT class library is intended to be subclassed
- * only at specific, controlled points (most notably,
- * <code>Composite</code> and <code>Canvas</code> when
- * implementing new widgets). This method enforces this
- * rule unless it is overridden.
- * </p><p>
- * <em>IMPORTANT:</em> By providing an implementation of this
- * method that allows a subclass of a class which does not
- * normally allow subclassing to be created, the implementer
- * agrees to be fully responsible for the fact that any such
- * subclass will likely fail between SWT releases and will be
- * strongly platform specific. No support is provided for
- * user-written classes which are implemented in this fashion.
- * </p><p>
- * The ability to subclass outside of the allowed SWT classes
- * is intended purely to enable those not on the SWT development
- * team to implement patches in order to get around specific
- * limitations in advance of when those limitations can be
- * addressed by the team. Subclassing should not be attempted
- * without an intimate and detailed understanding of the hierarchy.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Throws an <code>SWTException</code> if the receiver can not
- * be accessed by the caller. This may include both checks on
- * the state of the receiver and more generally on the entire
- * execution context. This method <em>should</em> be called by
- * widget implementors to enforce the standard SWT invariants.
- * <p>
- * Currently, it is an error to invoke any method (other than
- * <code>isDisposed()</code>) on a widget that has had its
- * <code>dispose()</code> method called. It is also an error
- * to call widget methods from any thread that is different
- * from the thread that created the widget.
- * </p><p>
- * In future releases of SWT, there may be more or fewer error
- * checks and exceptions may be thrown for different reasons.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-protected void checkWidget () {
- Display display = this.display;
- if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
- if (display.thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if ((state & DISPOSED) != 0) error (SWT.ERROR_WIDGET_DISPOSED);
-}
-
-int colorProc (int inControl, int inMessage, int inDrawDepth, int inDrawInColor) {
- return OS.eventNotHandledErr;
-}
-
-boolean contains (int shellX, int shellY) {
- return true;
-}
-
-int clockProc (int nextHandler, int theEvent, int userData) {
- int kind = OS.GetEventKind (theEvent);
- switch (kind) {
- case OS.kEventClockDateOrTimeChanged: return kEventClockDateOrTimeChanged (nextHandler, theEvent, userData);
- }
- return OS.eventNotHandledErr;
-}
-
-int controlProc (int nextHandler, int theEvent, int userData) {
- int eventKind = OS.GetEventKind (theEvent);
- switch (eventKind) {
- case OS.kEventControlActivate: return kEventControlActivate (nextHandler, theEvent, userData);
- case OS.kEventControlApplyBackground: return kEventControlApplyBackground (nextHandler, theEvent, userData);
- case OS.kEventControlBoundsChanged: return kEventControlBoundsChanged (nextHandler, theEvent, userData);
- case OS.kEventControlClick: return kEventControlClick (nextHandler, theEvent, userData);
- case OS.kEventControlContextualMenuClick: return kEventControlContextualMenuClick (nextHandler, theEvent, userData);
- case OS.kEventControlDeactivate: return kEventControlDeactivate (nextHandler, theEvent, userData);
- case OS.kEventControlDraw: return kEventControlDraw (nextHandler, theEvent, userData);
- case OS.kEventControlGetPartRegion: return kEventControlGetPartRegion (nextHandler, theEvent, userData);
- case OS.kEventControlHit: return kEventControlHit (nextHandler, theEvent, userData);
- case OS.kEventControlSetCursor: return kEventControlSetCursor (nextHandler, theEvent, userData);
- case OS.kEventControlSetFocusPart: return kEventControlSetFocusPart (nextHandler, theEvent, userData);
- case OS.kEventControlTrack: return kEventControlTrack (nextHandler, theEvent, userData);
- case OS.kEventControlGetFocusPart: return kEventControlGetFocusPart (nextHandler, theEvent, userData);
- case OS.kEventControlHitTest: return kEventControlHitTest (nextHandler, theEvent, userData);
- case OS.kEventControlGetClickActivation: return kEventControlGetClickActivation (nextHandler, theEvent, userData);
- }
- return OS.eventNotHandledErr;
-}
-
-int accessibilityProc (int nextHandler, int theEvent, int userData) {
- int eventKind = OS.GetEventKind (theEvent);
- switch (eventKind) {
- case OS.kEventAccessibleGetChildAtPoint: return kEventAccessibleGetChildAtPoint (nextHandler, theEvent, userData);
- case OS.kEventAccessibleGetFocusedChild: return kEventAccessibleGetFocusedChild (nextHandler, theEvent, userData);
- case OS.kEventAccessibleGetAllAttributeNames: return kEventAccessibleGetAllAttributeNames (nextHandler, theEvent, userData);
- case OS.kEventAccessibleGetNamedAttribute: return kEventAccessibleGetNamedAttribute (nextHandler, theEvent, userData);
- }
- return OS.eventNotHandledErr;
-}
-
-void copyToClipboard (char [] chars) {
- if (chars.length == 0) return;
- OS.ClearCurrentScrap ();
- int [] scrap = new int [1];
- OS.GetCurrentScrap (scrap);
- int cfstring = OS.CFStringCreateWithCharacters(OS.kCFAllocatorDefault, chars, chars.length);
- if (cfstring == 0) return;
- byte[] buffer = null;
- try {
- CFRange range = new CFRange();
- range.length = chars.length;
- int[] size = new int[1];
- int numChars = OS.CFStringGetBytes(cfstring, range, OS.kCFStringEncodingUnicode, (byte)'?', true, null, 0, size);
- if (numChars == 0) return;
- buffer = new byte[size[0]];
- numChars = OS.CFStringGetBytes(cfstring, range, OS.kCFStringEncodingUnicode, (byte)'?', true, buffer, size [0], size);
- if (numChars == 0) return;
- } finally {
- OS.CFRelease(cfstring);
- }
- OS.PutScrapFlavor (scrap [0], OS.kScrapFlavorTypeUTF16External, 0, buffer.length, buffer);
-}
-
-int createCIcon (Image image) {
- int imageHandle = image.handle;
- int width = OS.CGImageGetWidth(imageHandle);
- int height = OS.CGImageGetHeight(imageHandle);
- int bpr = OS.CGImageGetBytesPerRow(imageHandle);
- int bpp = OS.CGImageGetBitsPerPixel(imageHandle);
- int bpc = OS.CGImageGetBitsPerComponent(imageHandle);
- int alphaInfo = OS.CGImageGetAlphaInfo(imageHandle);
-
- int maskBpl = (((width + 7) / 8) + 3) / 4 * 4;
- int maskSize = height * maskBpl;
- int pixmapSize = height * bpr;
-
- /* Create the icon */
- int iconSize = PixMap.sizeof + BitMap.sizeof * 2 + 4 + maskSize;
- int iconHandle = OS.NewHandle(iconSize);
- if (iconHandle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.HLock(iconHandle);
- int[] iconPtr = new int[1];
- OS.memmove(iconPtr, iconHandle, 4);
-
- /* Initialize the pixmap */
- PixMap iconPMap = new PixMap();
- iconPMap.rowBytes = (short)(bpr | 0x8000);
- iconPMap.right = (short)width;
- iconPMap.bottom = (short)height;
- iconPMap.cmpCount = 3;
- iconPMap.cmpSize = (short)bpc;
- iconPMap.pmTable = OS.NewHandle(0);
- iconPMap.hRes = 72 << 16;
- iconPMap.vRes = 72 << 16;
- iconPMap.pixelType = (short)OS.RGBDirect;
- iconPMap.pixelSize = (short)bpp;
- iconPMap.pixelFormat = (short)bpp;
- OS.memmove(iconPtr[0], iconPMap, PixMap.sizeof);
-
- /* Initialize the mask */
- BitMap iconMask = new BitMap();
- iconMask.rowBytes = (short)maskBpl;
- iconMask.right = (short)width;
- iconMask.bottom = (short)height;
- OS.memmove(iconPtr[0] + PixMap.sizeof, iconMask, BitMap.sizeof);
-
- /* Initialize the icon data */
- int iconData = OS.NewHandle(pixmapSize);
- OS.HLock(iconData);
- int[] iconDataPtr = new int[1];
- OS.memmove(iconDataPtr, iconData, 4);
- OS.memmove(iconDataPtr[0], image.data, pixmapSize);
- OS.HUnlock(iconData);
- OS.memmove(iconPtr[0] + PixMap.sizeof + 2 * BitMap.sizeof, new int[]{iconData}, 4);
-
- /* Initialize the mask data */
- if (alphaInfo != OS.kCGImageAlphaFirst) {
- OS.memset(iconPtr[0] + PixMap.sizeof + 2 * BitMap.sizeof + 4, -1, maskSize);
- } else {
- byte[] srcData = new byte[pixmapSize];
- OS.memmove(srcData, image.data, pixmapSize);
- byte[] maskData = new byte[maskSize];
- int offset = 0, maskOffset = 0;
- for (int y = 0; y<height; y++) {
- for (int x = 0; x<width; x++) {
- if ((srcData[offset] & 0xFF) > 128) {
- maskData[maskOffset + (x >> 3)] |= (1 << (7 - (x & 0x7)));
- } else {
- maskData[maskOffset + (x >> 3)] &= ~(1 << (7 - (x & 0x7)));
- }
- offset += 4;
- }
- maskOffset += maskBpl;
- }
- OS.memmove(iconPtr[0] + PixMap.sizeof + 2 * BitMap.sizeof + 4, maskData, maskData.length);
- }
-
- OS.HUnlock(iconHandle);
- return iconHandle;
-}
-
-void createHandle () {
-}
-
-int createIconRef (Image image) {
- int imageHandle = image.handle;
- int imageData = image.data;
- int width = OS.CGImageGetWidth(imageHandle);
- int height = OS.CGImageGetHeight(imageHandle);
- int bpr = OS.CGImageGetBytesPerRow(imageHandle);
- int alphaInfo = OS.CGImageGetAlphaInfo(imageHandle);
-
- int type = 0, maskType = 0;
- if (width == 16 && height == 16) {
- type = OS.kSmall32BitData;
- maskType = OS.kSmall8BitMask;
- } else if (width == 32 && height == 32) {
- type = OS.kLarge32BitData;
- maskType = OS.kLarge8BitMask;
- } else if (width == 48 && height == 48) {
- type = OS.kHuge32BitData;
- maskType = OS.kHuge8BitMask;
- } else if (width == 128 && height == 128) {
- type = OS.kThumbnail32BitData;
- maskType = OS.kThumbnail8BitMask;
- } else {
- type = OS.kSmall32BitData;
- maskType = OS.kSmall8BitMask;
- int size = 16;
- if (width > 16 || height > 16) {
- type = OS.kHuge32BitData;
- maskType = OS.kHuge8BitMask;
- size = 32;
- }
- if (width > 32 || height > 32) {
- type = OS.kHuge32BitData;
- maskType = OS.kHuge8BitMask;
- size = 48;
- }
- if (width > 48 || height > 48) {
- type = OS.kThumbnail32BitData;
- maskType = OS.kThumbnail8BitMask;
- size = 128;
- }
- width = height = size;
- bpr = width * 4;
- int dataSize = height * bpr;
- imageData = OS.NewPtr(dataSize);
- if (imageData == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int colorspace = OS.CGColorSpaceCreateDeviceRGB();
- if (colorspace == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int context = OS.CGBitmapContextCreate(imageData, width, height, 8, bpr, colorspace, OS.kCGImageAlphaNoneSkipFirst);
- OS.CGColorSpaceRelease(colorspace);
- if (context == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- CGRect rect = new CGRect();
- rect.width = width;
- rect.height = height;
- OS.CGContextDrawImage(context, rect, imageHandle);
- OS.CGContextRelease(context);
- }
- if (type == 0) return 0;
-
- int iconFamily = OS.NewHandle(0);
- if (iconFamily == 0) SWT.error(SWT.ERROR_NO_HANDLES);
-
- int dataSize = height * bpr;
- int dataHandle = OS.NewHandle(dataSize);
- if (dataHandle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int[] dataPtr = new int[1];
- OS.HLock(dataHandle);
- OS.memmove(dataPtr, dataHandle, 4);
- OS.memmove(dataPtr[0], imageData, dataSize);
- OS.HUnlock(dataHandle);
- OS.SetIconFamilyData(iconFamily, type, dataHandle);
- OS.DisposeHandle(dataHandle);
-
- /* Initialize the mask data */
- int maskSize = width * height;
- int maskHandle = OS.NewHandle (maskSize);
- if (maskHandle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.HLock(maskHandle);
- int[] maskPtr = new int[1];
- OS.memmove(maskPtr, maskHandle, 4);
- if (alphaInfo != OS.kCGImageAlphaFirst) {
- OS.memset(maskPtr[0], 0xFF, maskSize);
- } else {
- byte[] srcData = new byte[dataSize];
- OS.memmove(srcData, imageData, dataSize);
- byte[] maskData = new byte[maskSize];
- int offset = 0, maskOffset = 0;
- for (int y = 0; y<height; y++) {
- for (int x = 0; x<width; x++) {
- maskData[maskOffset++] = srcData[offset];
- offset += 4;
- }
- }
- OS.memmove(maskPtr[0], maskData, maskData.length);
- }
- OS.HUnlock(maskHandle);
- OS.SetIconFamilyData(iconFamily, maskType, maskHandle);
- OS.DisposeHandle(maskHandle);
-
- if (imageData != image.data) OS.DisposePtr(imageData);
-
- /* Create the icon ref */
- int[] iconRef = new int[1];
- OS.HLock(iconFamily);
- int[] iconPtr = new int[1];
- OS.memmove(iconPtr, iconFamily, 4);
- OS.GetIconRefFromIconFamilyPtr(iconPtr[0], OS.GetHandleSize(iconFamily), iconRef);
- OS.HUnlock(iconFamily);
- OS.DisposeHandle(iconFamily);
- return iconRef[0];
-}
-
-void createWidget () {
- createHandle ();
- register ();
- hookEvents ();
-}
-
-int commandProc (int nextHandler, int theEvent, int userData) {
- int eventKind = OS.GetEventKind (theEvent);
- switch (eventKind) {
- case OS.kEventProcessCommand: return kEventProcessCommand (nextHandler, theEvent, userData);
- }
- return OS.eventNotHandledErr;
-}
-
-void deregister () {
-}
-
-void destroyWidget () {
- releaseHandle ();
-}
-
-void destroyCIcon (int iconHandle) {
- OS.HLock(iconHandle);
-
- /* Dispose the ColorTable */
- int[] iconPtr = new int[1];
- OS.memmove(iconPtr, iconHandle, 4);
- PixMap iconPMap = new PixMap();
- OS.memmove(iconPMap, iconPtr[0], PixMap.sizeof);
- if (iconPMap.pmTable != 0) OS.DisposeHandle(iconPMap.pmTable);
-
- /* Dispose the icon data */
- int[] iconData = new int[1];
- OS.memmove(iconData, iconPtr[0] + PixMap.sizeof + 2 * BitMap.sizeof, 4);
- if (iconData[0] != 0) OS.DisposeHandle(iconData[0]);
-
- OS.HUnlock(iconHandle);
-
- /* Dispose the icon */
- OS.DisposeHandle(iconHandle);
-}
-
-int drawItemProc (int browser, int item, int property, int itemState, int theRect, int gdDepth, int colorDevice) {
- return OS.noErr;
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the receiver and all its descendants. After this method has
- * been invoked, the receiver and all descendants will answer
- * <code>true</code> when sent the message <code>isDisposed()</code>.
- * Any internal connections between the widgets in the tree will
- * have been removed to facilitate garbage collection.
- * <p>
- * NOTE: This method is not called recursively on the descendants
- * of the receiver. This means that, widget implementers can not
- * detect when a widget is being disposed of by re-implementing
- * this method, but should instead listen for the <code>Dispose</code>
- * event.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #addDisposeListener
- * @see #removeDisposeListener
- * @see #checkWidget
- */
-public void dispose () {
- /*
- * Note: It is valid to attempt to dispose a widget
- * more than once. If this happens, fail silently.
- */
- if (isDisposed ()) return;
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- release (true);
-}
-
-void drawBackground (int control, int context) {
- /* Do nothing */
-}
-
-void drawWidget (int control, int context, int damageRgn, int visibleRgn, int theEvent) {
-}
-
-void error (int code) {
- SWT.error(code);
-}
-
-boolean filters (int eventType) {
- return display.filters (eventType);
-}
-
-int fixMnemonic (char [] buffer) {
- int i=0, j=0;
- while (i < buffer.length) {
- if ((buffer [j++] = buffer [i++]) == '&') {
- if (i == buffer.length) {continue;}
- if (buffer [i] == '&') {i++; continue;}
- j--;
- }
- }
- return j;
-}
-
-String getClipboardText () {
- String result = "";
- int [] scrap = new int [1];
- OS.GetCurrentScrap (scrap);
- int [] size = new int [1];
- if (OS.GetScrapFlavorSize (scrap [0], OS.kScrapFlavorTypeUTF16External, size) == OS.noErr) {
- if (size [0] != 0) {
- byte [] buffer = new byte [size [0]];
- if (OS.GetScrapFlavorData (scrap [0], OS.kScrapFlavorTypeUTF16External, size, buffer) == OS.noErr) {
- int encoding = OS.kCFStringEncodingUnicode;
- int cfstring = OS.CFStringCreateWithBytes(OS.kCFAllocatorDefault, buffer, buffer.length, encoding, true);
- if (cfstring != 0) {
- int length = OS.CFStringGetLength(cfstring);
- if (length != 0) {
- char[] chars = new char[length];
- CFRange range = new CFRange();
- range.length = length;
- OS.CFStringGetCharacters(cfstring, range, chars);
- result = new String(chars);
- }
- OS.CFRelease(cfstring);
- }
- }
- }
- } else if (OS.GetScrapFlavorSize (scrap [0], OS.kScrapFlavorTypeText, size) == OS.noErr) {
- if (size [0] != 0) {
- byte [] buffer = new byte [size [0]];
- if (OS.GetScrapFlavorData (scrap [0], OS.kScrapFlavorTypeText, size, buffer) == OS.noErr) {
- int encoding = OS.CFStringGetSystemEncoding();
- int cfstring = OS.CFStringCreateWithBytes(OS.kCFAllocatorDefault, buffer, buffer.length, encoding, true);
- if (cfstring != 0) {
- int length = OS.CFStringGetLength(cfstring);
- if (length != 0) {
- char[] chars = new char[length];
- CFRange range = new CFRange();
- range.length = length;
- OS.CFStringGetCharacters(cfstring, range, chars);
- result = new String(chars);
- }
- OS.CFRelease(cfstring);
- }
- }
- }
- }
- return result;
-}
-
-Rectangle getControlBounds (int control) {
- CGRect rect = new CGRect ();
- OS.HIViewGetFrame (control, rect);
- Rect inset = getInset ();
- rect.x -= inset.left;
- rect.y -= inset.top;
- rect.width += inset.right + inset.left;
- rect.height += inset.bottom + inset.top;
- return new Rectangle ((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height);
-}
-
-Point getControlSize (int control) {
- CGRect rect = new CGRect ();
- OS.HIViewGetFrame (control, rect);
- Rect inset = getInset ();
- int width = (int) rect.width + inset.left + inset.right;
- int height = (int) rect.height + inset.top + inset.bottom;
- return new Point (width, height);
-}
-
-/**
- * Returns the application defined widget data associated
- * with the receiver, or null if it has not been set. The
- * <em>widget data</em> is a single, unnamed field that is
- * stored with every widget.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the widget data needs to be notified
- * when the widget is disposed of, it is the application's
- * responsibility to hook the Dispose event on the widget and
- * do so.
- * </p>
- *
- * @return the widget data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
- * </ul>
- *
- * @see #setData(Object)
- */
-public Object getData () {
- checkWidget();
- return (state & KEYED_DATA) != 0 ? ((Object []) data) [0] : data;
-}
-
-/**
- * Returns the application defined property of the receiver
- * with the specified name, or null if it has not been set.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the widget is disposed
- * of, it is the application's responsibility to hook the
- * Dispose event on the widget and do so.
- * </p>
- *
- * @param key the name of the property
- * @return the value of the property or null if it has not been set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setData(String, Object)
- */
-public Object getData (String key) {
- checkWidget();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((state & KEYED_DATA) != 0) {
- Object [] table = (Object []) data;
- for (int i=1; i<table.length; i+=2) {
- if (key.equals (table [i])) return table [i+1];
- }
- }
- return null;
-}
-
-/**
- * Returns the <code>Display</code> that is associated with
- * the receiver.
- * <p>
- * A widget's display is either provided when it is created
- * (for example, top level <code>Shell</code>s) or is the
- * same as its parent's display.
- * </p>
- *
- * @return the receiver's display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Display getDisplay () {
- Display display = this.display;
- if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return display;
-}
-
-boolean getDrawing () {
- return true;
-}
-
-Rect getInset () {
- return EMPTY_RECT;
-}
-
-/**
- * Returns an array of listeners who will be notified when an event
- * of the given type occurs. The event type is one of the event constants
- * defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @return an array of listeners that will be notified when the event occurs
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener(int, Listener)
- * @see #removeListener(int, Listener)
- * @see #notifyListeners
- *
- * @since 3.4
- */
-public Listener[] getListeners (int eventType) {
- checkWidget();
- if (eventTable == null) return new Listener[0];
- return eventTable.getListeners(eventType);
-}
-
-String getName () {
- String string = getClass ().getName ();
- int index = string.lastIndexOf ('.');
- if (index == -1) return string;
- return string.substring (index + 1, string.length ());
-}
-
-String getNameText () {
- return "";
-}
-
-/**
- * Returns the receiver's style information.
- * <p>
- * Note that the value which is returned by this method <em>may
- * not match</em> the value which was provided to the constructor
- * when the receiver was created. This can occur when the underlying
- * operating system does not support a particular combination of
- * requested styles. For example, if the platform widget used to
- * implement a particular SWT widget always has scroll bars, the
- * result of calling this method would always have the
- * <code>SWT.H_SCROLL</code> and <code>SWT.V_SCROLL</code> bits set.
- * </p>
- *
- * @return the style bits
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getStyle () {
- checkWidget();
- return style;
-}
-
-int getVisibleRegion (int control, boolean clipChildren) {
- int visibleRgn = OS.NewRgn ();
- calculateVisibleRegion (control, visibleRgn, clipChildren);
- return visibleRgn;
-}
-
-int helpProc (int inControl, int inGlobalMouse, int inRequest, int outContentProvided, int ioHelpContent) {
- return OS.eventNotHandledErr;
-}
-
-int hitTestProc (int browser, int item, int property, int theRect, int mouseRect) {
- /* Return true to indicate that the item can be selected */
- return 1;
-}
-
-void hookEvents () {
-}
-
-boolean hooks (int eventType) {
- if (eventTable == null) return false;
- return eventTable.hooks (eventType);
-}
-
-void invalidateVisibleRegion (int control) {
-}
-
-void invalWindowRgn (int window, int rgn) {
- OS.InvalWindowRgn (window, rgn);
-}
-
-/**
- * Returns <code>true</code> if the widget has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the widget.
- * When a widget has been disposed, it is an error to
- * invoke any other method using the widget.
- * </p>
- *
- * @return <code>true</code> when the widget is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- return (state & DISPOSED) != 0;
-}
-
-boolean isDrawing () {
- return true;
-}
-
-boolean isEnabled () {
- return true;
-}
-
-/**
- * Returns <code>true</code> if there are any listeners
- * for the specified event type associated with the receiver,
- * and <code>false</code> otherwise. The event type is one of
- * the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event
- * @return true if the event is hooked
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public boolean isListening (int eventType) {
- checkWidget();
- return hooks (eventType);
-}
-
-boolean isTrimHandle (int trimHandle) {
- return false;
-}
-
-boolean isValidSubclass () {
- return Display.isValidClass (getClass ());
-}
-
-boolean isValidThread () {
- return getDisplay ().isValidThread ();
-}
-
-int itemCompareProc (int browser, int itemOne, int itemTwo, int sortProperty) {
- return OS.noErr;
-}
-
-int itemDataProc (int browser, int item, int property, int itemData, int setValue) {
- return OS.noErr;
-}
-
-int itemNotificationProc (int browser, int item, int message) {
- return OS.noErr;
-}
-
-int kEventAccessibleGetChildAtPoint (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventAccessibleGetFocusedChild (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventAccessibleGetAllAttributeNames (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventAccessibleGetNamedAttribute (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventProcessCommand (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventClockDateOrTimeChanged (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventControlApplyBackground (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventControlActivate (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventControlBoundsChanged (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventControlClick (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventControlContextualMenuClick (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventControlDeactivate (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventControlDraw (int nextHandler, int theEvent, int userData) {
- int [] theControl = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamDirectObject, OS.typeControlRef, null, 4, null, theControl);
- int [] region = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamRgnHandle, OS.typeQDRgnHandle, null, 4, null, region);
- Display display = this.display;
- boolean oldInPaint = display.inPaint;
- display.inPaint = true;
- int[] context = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamCGContextRef, OS.typeCGContextRef, null, 4, null, context);
- int visibleRgn = region [0];
- drawBackground (theControl [0], context [0]);
- callPaintEventHandler (theControl [0], region [0], visibleRgn, theEvent, nextHandler);
- drawWidget (theControl [0], context [0], region [0], visibleRgn, theEvent);
- display.inPaint = oldInPaint;
- return OS.noErr;
-}
-
-int kEventControlGetClickActivation (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventControlGetFocusPart (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventControlGetPartRegion (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventControlHit (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventControlHitTest (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventControlSetCursor (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventControlSetFocusPart (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventControlTrack (int nextHandler, int theEvent, int userData) {
- int [] theControl = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamDirectObject, OS.typeControlRef, null, 4, null, theControl);
- OS.CFRetain (theControl[0]);
- int result = OS.CallNextEventHandler (nextHandler, theEvent);
- OS.CFRelease (theControl[0]);
- return result;
-}
-
-int kEventMenuCalculateSize (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventMenuClosed (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventMenuCreateFrameView (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventMenuDrawItem (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventMenuDrawItemContent (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventMenuGetFrameBounds (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventMenuMatchKey (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventMenuMeasureItemWidth (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventMenuOpening (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventMenuTargetItem (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventMouseDown (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventMouseDragged (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventMouseMoved (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventMouseUp (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventMouseWheelMoved (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventSearchFieldCancelClicked (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventSearchFieldSearchClicked (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventRawKeyDown (int nextHandler, int theEvent, int userData) {
- return kEventRawKeyPressed (nextHandler, theEvent, userData);
-}
-
-int kEventRawKeyModifiersChanged (int nextHandler, int theEvent, int userData) {
- Display display = this.display;
- int [] modifiers = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, modifiers.length * 4, null, modifiers);
- int lastModifiers = display.lastModifiers;
- int chord = OS.GetCurrentEventButtonState ();
- int type = SWT.KeyUp;
- if ((modifiers [0] & OS.alphaLock) != 0 && (lastModifiers & OS.alphaLock) == 0) type = SWT.KeyDown;
- if ((modifiers [0] & OS.shiftKey) != 0 && (lastModifiers & OS.shiftKey) == 0) type = SWT.KeyDown;
- if ((modifiers [0] & OS.controlKey) != 0 && (lastModifiers & OS.controlKey) == 0) type = SWT.KeyDown;
- if ((modifiers [0] & OS.cmdKey) != 0 && (lastModifiers & OS.cmdKey) == 0) type = SWT.KeyDown;
- if ((modifiers [0] & OS.optionKey) != 0 && (lastModifiers & OS.optionKey) == 0) type = SWT.KeyDown;
- if (type == SWT.KeyUp && (modifiers [0] & OS.alphaLock) == 0 && (lastModifiers & OS.alphaLock) != 0) {
- Event event = new Event ();
- event.keyCode = SWT.CAPS_LOCK;
- setInputState (event, SWT.KeyDown, chord, modifiers [0]);
- sendKeyEvent (SWT.KeyDown, event);
- }
- Event event = new Event ();
- setInputState (event, type, chord, modifiers [0]);
- if (event.keyCode == 0 && event.character == 0) return OS.eventNotHandledErr;
- boolean result = sendKeyEvent (type, event);
- if (type == SWT.KeyDown && (modifiers [0] & OS.alphaLock) != 0 && (lastModifiers & OS.alphaLock) == 0) {
- event = new Event ();
- event.keyCode = SWT.CAPS_LOCK;
- setInputState (event, SWT.KeyUp, chord, modifiers [0]);
- sendKeyEvent (SWT.KeyUp, event);
- }
- display.lastModifiers = modifiers [0];
- return result ? OS.eventNotHandledErr : OS.noErr;
-}
-
-int kEventRawKeyPressed (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventRawKeyRepeat (int nextHandler, int theEvent, int userData) {
- return kEventRawKeyPressed (nextHandler, theEvent, userData);
-}
-
-int kEventRawKeyUp (int nextHandler, int theEvent, int userData) {
- if (!sendKeyEvent (SWT.KeyUp, theEvent)) return OS.noErr;
- return OS.eventNotHandledErr;
-}
-
-int kEventTextInputUnicodeForKeyEvent (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventTextInputUpdateActiveInputArea (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventTextInputOffsetToPos (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventTextInputPosToOffset (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventTextInputGetSelectedText (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventWindowActivated (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventWindowBoundsChanged (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventWindowClose (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventWindowCollapsed (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventWindowCollapsing (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventWindowDeactivated (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventWindowDrawContent (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventWindowExpanded (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventWindowGetClickModality (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventWindowGetRegion (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventWindowHidden (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventWindowHitTest (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventWindowShown (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int kEventWindowUpdate (int nextHandler, int theEvent, int userData) {
- return OS.eventNotHandledErr;
-}
-
-int keyboardProc (int nextHandler, int theEvent, int userData) {
- int eventKind = OS.GetEventKind (theEvent);
- switch (eventKind) {
- case OS.kEventRawKeyDown: return kEventRawKeyDown (nextHandler, theEvent, userData);
- case OS.kEventRawKeyModifiersChanged: return kEventRawKeyModifiersChanged (nextHandler, theEvent, userData);
- case OS.kEventRawKeyRepeat: return kEventRawKeyRepeat (nextHandler, theEvent, userData);
- case OS.kEventRawKeyUp: return kEventRawKeyUp (nextHandler, theEvent, userData);
- }
- return OS.eventNotHandledErr;
-}
-
-int menuProc (int nextHandler, int theEvent, int userData) {
- int eventKind = OS.GetEventKind (theEvent);
- switch (eventKind) {
- case OS.kEventMenuCalculateSize: return kEventMenuCalculateSize (nextHandler, theEvent, userData);
- case OS.kEventMenuClosed: return kEventMenuClosed (nextHandler, theEvent, userData);
- case OS.kEventMenuCreateFrameView: return kEventMenuCreateFrameView (nextHandler, theEvent, userData);
- case OS.kEventMenuDrawItem: return kEventMenuDrawItem (nextHandler, theEvent, userData);
- case OS.kEventMenuDrawItemContent: return kEventMenuDrawItemContent (nextHandler, theEvent, userData);
- case OS.kEventMenuGetFrameBounds: return kEventMenuGetFrameBounds (nextHandler, theEvent, userData);
- case OS.kEventMenuMatchKey: return kEventMenuMatchKey (nextHandler, theEvent, userData);
- case OS.kEventMenuMeasureItemWidth: return kEventMenuMeasureItemWidth (nextHandler, theEvent, userData);
- case OS.kEventMenuOpening: return kEventMenuOpening (nextHandler, theEvent, userData);
- case OS.kEventMenuTargetItem: return kEventMenuTargetItem (nextHandler, theEvent, userData);
- }
- return OS.eventNotHandledErr;
-}
-
-int mouseProc (int nextHandler, int theEvent, int userData) {
- int eventKind = OS.GetEventKind (theEvent);
- switch (eventKind) {
- case OS.kEventMouseDown: return kEventMouseDown (nextHandler, theEvent, userData);
- case OS.kEventMouseUp: return kEventMouseUp (nextHandler, theEvent, userData);
- case OS.kEventMouseDragged: return kEventMouseDragged (nextHandler, theEvent, userData);
-// case OS.kEventMouseEntered: return kEventMouseEntered (nextHandler, theEvent, userData);
-// case OS.kEventMouseExited: return kEventMouseExited (nextHandler, theEvent, userData);
- case OS.kEventMouseMoved: return kEventMouseMoved (nextHandler, theEvent, userData);
- case OS.kEventMouseWheelMoved: return kEventMouseWheelMoved (nextHandler, theEvent, userData);
- }
- return OS.eventNotHandledErr;
-}
-
-/**
- * Notifies all of the receiver's listeners for events
- * of the given type that one such event has occurred by
- * invoking their <code>handleEvent()</code> method. The
- * event type is one of the event constants defined in class
- * <code>SWT</code>.
- *
- * @param eventType the type of event which has occurred
- * @param event the event data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- * @see #addListener
- * @see #getListeners(int)
- * @see #removeListener(int, Listener)
- */
-public void notifyListeners (int eventType, Event event) {
- checkWidget();
- if (event == null) event = new Event ();
- sendEvent (eventType, event);
-}
-
-void postEvent (int eventType) {
- sendEvent (eventType, null, false);
-}
-
-void postEvent (int eventType, Event event) {
- sendEvent (eventType, event, false);
-}
-
-void redrawChildren (int control) {
- int child = OS.HIViewGetFirstSubview (control);
- while (child != 0) {
- OS.HIViewSetNeedsDisplay (child, true);
- redrawChildren (child);
- child = OS.HIViewGetNextView (child);
- }
-}
-
-void redrawChildren (int control, int rgn) {
- int child = OS.HIViewGetFirstSubview (control);
- while (child != 0) {
- OS.HIViewConvertRegion(rgn, control, child);
- OS.HIViewSetNeedsDisplayInRegion (child, rgn, true);
- redrawChildren (child, rgn);
- OS.HIViewConvertRegion(rgn, child, control);
- child = OS.HIViewGetNextView (child);
- }
-}
-
-void redrawWidget (int control, boolean children) {
- if (display.inPaint) {
- int rgn = OS.NewRgn ();
- Rect rect = new Rect ();
- OS.GetControlBounds (control, rect);
- rect.right += rect.left;
- rect.bottom += rect.top;
- rect.top = rect.left = 0;
- OS.RectRgn (rgn, rect);
- OS.HIViewConvertRegion (rgn, control, 0);
- invalWindowRgn (0, rgn);
- OS.DisposeRgn (rgn);
- } else {
- OS.HIViewSetNeedsDisplay (control, true);
- if (children) redrawChildren (control);
- }
-}
-
-void redrawWidget (int control, int x, int y, int width, int height, boolean children) {
- int rgn = OS.NewRgn ();
- Rect rect = new Rect ();
- OS.SetRect (rect, (short) x, (short) y, (short) (x + width), (short) (y + height));
- OS.RectRgn (rgn, rect);
- if (display.inPaint) {
- OS.HIViewConvertRegion (rgn, control, 0);
- invalWindowRgn (0, rgn);
- } else {
- OS.HIViewSetNeedsDisplayInRegion (control, rgn, true);
- if (children) redrawChildren (control, rgn);
- }
- OS.DisposeRgn (rgn);
-}
-
-void register () {
-}
-
-void release (boolean destroy) {
- if ((state & DISPOSE_SENT) == 0) {
- state |= DISPOSE_SENT;
- sendEvent (SWT.Dispose);
- }
- if ((state & DISPOSED) == 0) {
- releaseChildren (destroy);
- }
- if ((state & RELEASED) == 0) {
- state |= RELEASED;
- if (destroy) {
- releaseParent ();
- releaseWidget ();
- destroyWidget ();
- } else {
- releaseWidget ();
- releaseHandle ();
- }
- }
-}
-
-void releaseChildren (boolean destroy) {
-}
-
-void releaseHandle () {
- state |= DISPOSED;
- display = null;
-}
-
-void releaseParent () {
- /* Do nothing */
-}
-
-void releaseWidget () {
- deregister ();
- eventTable = null;
- data = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener
- * @see #getListeners(int)
- * @see #notifyListeners
- */
-public void removeListener (int eventType, Listener handler) {
- checkWidget();
- if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, handler);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It should never be
- * referenced from application code.
- * </p>
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see #addListener
- */
-protected void removeListener (int eventType, SWTEventListener handler) {
- checkWidget();
- if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, handler);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the widget is disposed.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DisposeListener
- * @see #addDisposeListener
- */
-public void removeDisposeListener (DisposeListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Dispose, listener);
-}
-
-int searchProc (int nextHandler, int theEvent, int userData) {
- int kind = OS.GetEventKind (theEvent);
- switch (kind) {
- case OS.kEventSearchFieldCancelClicked: return kEventSearchFieldCancelClicked (nextHandler, theEvent, userData);
- case OS.kEventSearchFieldSearchClicked: return kEventSearchFieldSearchClicked (nextHandler, theEvent, userData);
- }
- return OS.eventNotHandledErr;
-}
-
-void sendEvent (Event event) {
- Display display = event.display;
- if (!display.filterEvent (event)) {
- if (eventTable != null) eventTable.sendEvent (event);
- }
-}
-
-void sendEvent (int eventType) {
- sendEvent (eventType, null, true);
-}
-
-void sendEvent (int eventType, Event event) {
- sendEvent (eventType, event, true);
-}
-
-void sendEvent (int eventType, Event event, boolean send) {
- if (eventTable == null && !display.filters (eventType)) {
- return;
- }
- if (event == null) event = new Event ();
- event.type = eventType;
- event.display = display;
- event.widget = this;
- if (event.time == 0) {
- event.time = display.getLastEventTime ();
- }
- if (send) {
- sendEvent (event);
- } else {
- display.postEvent (event);
- }
-}
-
-boolean sendKeyEvent (int type, int theEvent) {
- if ((state & SAFARI_EVENTS_FIX) != 0) return true;
- int [] length = new int [1];
- int status = OS.GetEventParameter (theEvent, OS.kEventParamKeyUnicodes, OS.typeUnicodeText, null, 4, length, (char[])null);
- if (status == OS.noErr && length [0] > 2) {
- int count = 0;
- int [] chord = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamMouseChord, OS.typeUInt32, null, 4, null, chord);
- int [] modifiers = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
- char [] chars = new char [length [0] / 2];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyUnicodes, OS.typeUnicodeText, null, chars.length * 2, null, chars);
- for (int i=0; i<chars.length; i++) {
- Event event = new Event ();
- event.character = chars [i];
- setInputState (event, type, chord [0], modifiers [0]);
- if (sendKeyEvent (type, event)) chars [count++] = chars [i];
- }
- if (count == 0) return false;
- if (count != chars.length - 1) {
- OS.SetEventParameter (theEvent, OS.kEventParamKeyUnicodes, OS.typeUnicodeText, count * 2, chars);
- }
- return true;
- } else {
- Event event = new Event ();
- if (!setKeyState (event, type, theEvent)) return true;
- return sendKeyEvent (type, event);
- }
-}
-
-boolean sendKeyEvent (int type, Event event) {
- sendEvent (type, event);
- // widget could be disposed at this point
-
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the key
- * events. If this happens, end the processing of
- * the key by returning false.
- */
- if (isDisposed ()) return false;
- return event.doit;
-}
-
-int setBounds (int control, int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- boolean sameOrigin = true, sameExtent = true;
- CGRect oldBounds = new CGRect ();
- OS.HIViewGetFrame (control, oldBounds);
- Rect inset = getInset ();
- oldBounds.x -= inset.left;
- oldBounds.y -= inset.top;
- oldBounds.width += inset.left + inset.right;
- oldBounds.height += inset.top + inset.bottom;
- if (!move) {
- x = (int) oldBounds.x;
- y = (int) oldBounds.y;
- }
- if (!resize) {
- width = (int) oldBounds.width;
- height = (int) oldBounds.height;
- }
- CGRect newBounds = new CGRect ();
- newBounds.x = x + inset.left;
- newBounds.y = y + inset.top;
- newBounds.width = width - inset.right - inset.left;
- newBounds.height = height - inset.bottom - inset.top;
- sameOrigin = newBounds.x == oldBounds.x && newBounds.y == oldBounds.y;
- sameExtent = newBounds.width == oldBounds.width && newBounds.height == oldBounds.height;
- if (sameOrigin && sameExtent) return 0;
- OS.HIViewSetFrame (control, newBounds);
- invalidateVisibleRegion (control);
-
- /*
- * Bug in the Macintosh. When HIViewSetDrawingEnabled() is used to
- * turn off drawing for a control and the control is moved or resized,
- * the Mac does not redraw the area where the control once was in the
- * parent. The fix is to detect this case and redraw the area.
- */
- if (!OS.HIViewIsDrawingEnabled (control)) {
- int parent = OS.HIViewGetSuperview (control);
- if (parent != 0 && OS.HIViewIsDrawingEnabled (parent)) {
- int rgn = OS.NewRgn ();
- Rect rect = new Rect ();
- OS.SetRect (rect, (short) oldBounds.x, (short) oldBounds.y, (short) (oldBounds.x + oldBounds.width), (short) (oldBounds.y + oldBounds.height));
- OS.RectRgn (rgn, rect);
- if (display.inPaint) {
- OS.HIViewConvertRegion (rgn, parent, 0);
- invalWindowRgn (0, rgn);
- } else {
- OS.HIViewSetNeedsDisplayInRegion (parent, rgn, true);
- }
- OS.DisposeRgn (rgn);
- }
- }
-
- /* Send events */
- int result = 0;
- if (move && !sameOrigin) {
- if (events) sendEvent (SWT.Move);
- result |= MOVED;
- }
- if (resize && !sameExtent) {
- if (events) sendEvent (SWT.Resize);
- result |= RESIZED;
- }
- return result;
-}
-
-/**
- * Sets the application defined widget data associated
- * with the receiver to be the argument. The <em>widget
- * data</em> is a single, unnamed field that is stored
- * with every widget.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the widget data needs to be notified
- * when the widget is disposed of, it is the application's
- * responsibility to hook the Dispose event on the widget and
- * do so.
- * </p>
- *
- * @param data the widget data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
- * </ul>
- *
- * @see #getData()
- */
-public void setData (Object data) {
- checkWidget();
- if (SAFARI_EVENTS_FIX_KEY.equals(data)) {
- state |= SAFARI_EVENTS_FIX;
- return;
- }
- if ((state & KEYED_DATA) != 0) {
- ((Object []) this.data) [0] = data;
- } else {
- this.data = data;
- }
-}
-
-/**
- * Sets the application defined property of the receiver
- * with the specified name to the given value.
- * <p>
- * Applications may associate arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the widget is disposed
- * of, it is the application's responsibility to hook the
- * Dispose event on the widget and do so.
- * </p>
- *
- * @param key the name of the property
- * @param value the new value for the property
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getData(String)
- */
-public void setData (String key, Object value) {
- checkWidget();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = 1;
- Object [] table = null;
- if ((state & KEYED_DATA) != 0) {
- table = (Object []) data;
- while (index < table.length) {
- if (key.equals (table [index])) break;
- index += 2;
- }
- }
- if (value != null) {
- if ((state & KEYED_DATA) != 0) {
- if (index == table.length) {
- Object [] newTable = new Object [table.length + 2];
- System.arraycopy (table, 0, newTable, 0, table.length);
- data = table = newTable;
- }
- } else {
- table = new Object [3];
- table [0] = data;
- data = table;
- state |= KEYED_DATA;
- }
- table [index] = key;
- table [index + 1] = value;
- } else {
- if ((state & KEYED_DATA) != 0) {
- if (index != table.length) {
- int length = table.length - 2;
- if (length == 1) {
- data = table [0];
- state &= ~KEYED_DATA;
- } else {
- Object [] newTable = new Object [length];
- System.arraycopy (table, 0, newTable, 0, index);
- System.arraycopy (table, index + 2, newTable, index, length - index);
- data = newTable;
- }
- }
- }
- }
-}
-
-boolean setInputState (Event event, int type, int chord, int modifiers) {
- if ((chord & 0x01) != 0) event.stateMask |= SWT.BUTTON1;
- if ((chord & 0x02) != 0) event.stateMask |= SWT.BUTTON3;
- if ((chord & 0x04) != 0) event.stateMask |= SWT.BUTTON2;
- if ((chord & 0x08) != 0) event.stateMask |= SWT.BUTTON4;
- if ((chord & 0x10) != 0) event.stateMask |= SWT.BUTTON5;
-
- if ((modifiers & OS.optionKey) != 0) event.stateMask |= SWT.ALT;
- if ((modifiers & OS.shiftKey) != 0) event.stateMask |= SWT.SHIFT;
- if ((modifiers & OS.controlKey) != 0) event.stateMask |= SWT.CONTROL;
- if ((modifiers & OS.cmdKey) != 0) event.stateMask |= SWT.COMMAND;
- switch (type) {
- case SWT.MouseDown:
- case SWT.MouseDoubleClick:
- if (event.button == 1) event.stateMask &= ~SWT.BUTTON1;
- if (event.button == 2) event.stateMask &= ~SWT.BUTTON2;
- if (event.button == 3) event.stateMask &= ~SWT.BUTTON3;
- if (event.button == 4) event.stateMask &= ~SWT.BUTTON4;
- if (event.button == 5) event.stateMask &= ~SWT.BUTTON5;
- break;
- case SWT.MouseUp:
- if (event.button == 1) event.stateMask |= SWT.BUTTON1;
- if (event.button == 2) event.stateMask |= SWT.BUTTON2;
- if (event.button == 3) event.stateMask |= SWT.BUTTON3;
- if (event.button == 4) event.stateMask |= SWT.BUTTON4;
- if (event.button == 5) event.stateMask |= SWT.BUTTON5;
- break;
- case SWT.KeyDown:
- case SWT.Traverse: {
- if (event.keyCode != 0 || event.character != 0) return true;
- int lastModifiers = display.lastModifiers;
- if ((modifiers & OS.alphaLock) != 0 && (lastModifiers & OS.alphaLock) == 0) {
- event.keyCode = SWT.CAPS_LOCK;
- return true;
- }
- if ((modifiers & OS.shiftKey) != 0 && (lastModifiers & OS.shiftKey) == 0) {
- event.stateMask &= ~SWT.SHIFT;
- event.keyCode = SWT.SHIFT;
- return true;
- }
- if ((modifiers & OS.controlKey) != 0 && (lastModifiers & OS.controlKey) == 0) {
- event.stateMask &= ~SWT.CONTROL;
- event.keyCode = SWT.CONTROL;
- return true;
- }
- if ((modifiers & OS.cmdKey) != 0 && (lastModifiers & OS.cmdKey) == 0) {
- event.stateMask &= ~SWT.COMMAND;
- event.keyCode = SWT.COMMAND;
- return true;
- }
- if ((modifiers & OS.optionKey) != 0 && (lastModifiers & OS.optionKey) == 0) {
- event.stateMask &= ~SWT.ALT;
- event.keyCode = SWT.ALT;
- return true;
- }
- break;
- }
- case SWT.KeyUp: {
- if (event.keyCode != 0 || event.character != 0) return true;
- int lastModifiers = display.lastModifiers;
- if ((modifiers & OS.alphaLock) == 0 && (lastModifiers & OS.alphaLock) != 0) {
- event.keyCode = SWT.CAPS_LOCK;
- return true;
- }
- if ((modifiers & OS.shiftKey) == 0 && (lastModifiers & OS.shiftKey) != 0) {
- event.stateMask |= SWT.SHIFT;
- event.keyCode = SWT.SHIFT;
- return true;
- }
- if ((modifiers & OS.controlKey) == 0 && (lastModifiers & OS.controlKey) != 0) {
- event.stateMask |= SWT.CONTROL;
- event.keyCode = SWT.CONTROL;
- return true;
- }
- if ((modifiers & OS.cmdKey) == 0 && (lastModifiers & OS.cmdKey) != 0) {
- event.stateMask |= SWT.COMMAND;
- event.keyCode = SWT.COMMAND;
- return true;
- }
- if ((modifiers & OS.optionKey) == 0 && (lastModifiers & OS.optionKey) != 0) {
- event.stateMask |= SWT.ALT;
- event.keyCode = SWT.ALT;
- return true;
- }
- break;
- }
- }
- return true;
-}
-
-boolean setKeyState (Event event, int type, int theEvent) {
- boolean isNull = false;
- int [] keyCode = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyCode, OS.typeUInt32, null, keyCode.length * 4, null, keyCode);
- event.keyCode = Display.translateKey (keyCode [0]);
- switch (event.keyCode) {
- case SWT.LF: {
- /*
- * Feature in the Macintosh. When the numeric key pad
- * Enter key is pressed, it generates '\n'. This is the
- * correct platform behavior but is not portable. The
- * fix is to convert the '\n' into '\r'.
- */
- event.keyCode = SWT.KEYPAD_CR;
- event.character = '\r';
- break;
- }
- case SWT.BS: event.character = '\b'; break;
- case SWT.CR: event.character = '\r'; break;
- case SWT.DEL: event.character = 0x7F; break;
- case SWT.ESC: event.character = 0x1B; break;
- case SWT.TAB: event.character = '\t'; break;
- default: {
- if (event.keyCode == 0 || (SWT.KEYPAD_MULTIPLY <= event.keyCode && event.keyCode <= SWT.KEYPAD_CR)) {
- int [] length = new int [1];
- int status = OS.GetEventParameter (theEvent, OS.kEventParamKeyUnicodes, OS.typeUnicodeText, null, 4, length, (char[])null);
- if (status == OS.noErr && length [0] != 0) {
- char [] chars = new char [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyUnicodes, OS.typeUnicodeText, null, 2, null, chars);
- event.character = chars [0];
- }
- /*
- * Bug in the Macintosh. For some reason, Ctrl+Shift+'2' and Ctrl+Shift+'6'
- * fail to give 0x0 (^@ or ASCII NUL) and 0x1e (^^). Other control character
- * key sequences such as ^A or even Ctrl+Shift+'-' (^_ or 0x1f) are correctly
- * translated to control characters. Since it is not possible to know which
- * key combination gives '@' on an international keyboard, there is no way to
- * test for either character and convert it to a control character (Shift+'2'
- * gives '@' only on an English keyboard) to work around the problem.
- *
- * There is no fix at this time.
- */
- }
- if (event.keyCode == 0) {
- int kchrPtr = OS.GetScriptManagerVariable ((short) OS.smKCHRCache);
- if (display.kchrPtr != kchrPtr) {
- display.kchrPtr = kchrPtr;
- display.kchrState [0] = 0;
- }
- int [] layoutRef = new int [1];
- int layoutKind = OS.kKLKCHRKind;
- if (OS.KLGetCurrentKeyboardLayout (layoutRef) == OS.noErr) {
- int [] layoutKindRef = new int [1];
- OS.KLGetKeyboardLayoutProperty (layoutRef[0], OS.kKLKind, layoutKindRef);
- layoutKind = layoutKindRef [0];
- }
- if (layoutKind == OS.kKLuchrKind) {
- int [] layoutPtr = new int [1];
- OS.KLGetKeyboardLayoutProperty (layoutRef[0], OS.kKLuchrData, layoutPtr);
- int maxStringLength = 256;
- char [] output = new char [maxStringLength];
- int [] actualStringLength = new int [1];
- OS.UCKeyTranslate (layoutPtr[0], (short)keyCode[0], (short)OS.kUCKeyActionDown, 0, OS.LMGetKbdType (), 0, display.kchrState, maxStringLength, actualStringLength, output);
- if (actualStringLength[0] < 1) {
- // part of a multi-key key
- event.keyCode = 0;
- } else {
- event.keyCode = output[0];
- }
- } else {
- int result = OS.KeyTranslate (display.kchrPtr, (short)keyCode [0], display.kchrState);
- if (result <= 0x7f) {
- event.keyCode = result & 0x7f;
- } else {
- int [] encoding = new int [1];
- short keyScript = (short) OS.GetScriptManagerVariable ((short) OS.smKeyScript);
- short regionCode = (short) OS.GetScriptManagerVariable ((short) OS.smRegionCode);
- if (OS.UpgradeScriptInfoToTextEncoding (keyScript, (short) OS.kTextLanguageDontCare, regionCode, null, encoding) == OS.paramErr) {
- if (OS.UpgradeScriptInfoToTextEncoding (keyScript, (short) OS.kTextLanguageDontCare, (short) OS.kTextRegionDontCare, null, encoding) == OS.paramErr) {
- encoding [0] = OS.kTextEncodingMacRoman;
- }
- }
- int [] encodingInfo = new int [1];
- OS.CreateTextToUnicodeInfoByEncoding (encoding [0], encodingInfo);
- if (encodingInfo [0] != 0) {
- char [] chars = new char [1];
- int [] nchars = new int [1];
- byte [] buffer = new byte [2];
- buffer [0] = 1;
- buffer [1] = (byte) (result & 0xFF);
- OS.ConvertFromPStringToUnicode (encodingInfo [0], buffer, chars.length * 2, nchars, chars);
- OS.DisposeTextToUnicodeInfo (encodingInfo);
- event.keyCode = chars [0];
- }
- }
- }
- }
- break;
- }
- }
- if (event.keyCode == 0 && event.character == 0) {
- if (!isNull) return false;
- }
- int [] chord = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamMouseChord, OS.typeUInt32, null, 4, null, chord);
- int [] modifiers = new int [1];
- OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
- return setInputState (event, type, chord [0], modifiers [0]);
-}
-
-void setVisible (int control, boolean visible) {
- OS.HIViewSetVisible (control, visible);
- invalidateVisibleRegion (control);
-}
-
-void setZOrder (int control, int otheControl, boolean above) {
- int inOp = above ? OS.kHIViewZOrderAbove : OS.kHIViewZOrderBelow;
- OS.HIViewSetZOrder (control, inOp, otheControl);
- invalidateVisibleRegion (control);
-}
-
-int textInputProc (int nextHandler, int theEvent, int userData) {
- int eventKind = OS.GetEventKind (theEvent);
- switch (eventKind) {
- case OS.kEventTextInputUnicodeForKeyEvent: return kEventTextInputUnicodeForKeyEvent (nextHandler, theEvent, userData);
- case OS.kEventTextInputUpdateActiveInputArea: return kEventTextInputUpdateActiveInputArea (nextHandler, theEvent, userData);
- case OS.kEventTextInputOffsetToPos: return kEventTextInputOffsetToPos (nextHandler, theEvent, userData);
- case OS.kEventTextInputPosToOffset: return kEventTextInputPosToOffset (nextHandler, theEvent, userData);
- case OS.kEventTextInputGetSelectedText: return kEventTextInputGetSelectedText (nextHandler, theEvent, userData);
- }
- return OS.eventNotHandledErr;
-}
-
-RGBColor toRGBColor (float [] color) {
- RGBColor rgb = new RGBColor ();
- rgb.red = (short) (color [0] * 0xffff);
- rgb.green = (short) (color [1] * 0xffff);
- rgb.blue = (short) (color [2] * 0xffff);
- return rgb;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- String string = "*Disposed*";
- if (!isDisposed ()) {
- string = "*Wrong Thread*";
- if (isValidThread ()) string = getNameText ();
- }
- return getName () + " {" + string + "}";
-}
-
-int trackingProc (int browser, int itemID, int property, int theRect, int startPt, int modifiers) {
- /* Return one to indicate that the data browser should process the click */
- return 1;
-}
-
-int windowProc (int nextHandler, int theEvent, int userData) {
- int eventKind = OS.GetEventKind (theEvent);
- switch (eventKind) {
- case OS.kEventWindowActivated: return kEventWindowActivated (nextHandler, theEvent, userData);
- case OS.kEventWindowBoundsChanged: return kEventWindowBoundsChanged (nextHandler, theEvent, userData);
- case OS.kEventWindowClose: return kEventWindowClose (nextHandler, theEvent, userData);
- case OS.kEventWindowCollapsed: return kEventWindowCollapsed (nextHandler, theEvent, userData);
- case OS.kEventWindowCollapsing: return kEventWindowCollapsing (nextHandler, theEvent, userData);
- case OS.kEventWindowDeactivated: return kEventWindowDeactivated (nextHandler, theEvent, userData);
- case OS.kEventWindowDrawContent: return kEventWindowDrawContent (nextHandler, theEvent, userData);
- case OS.kEventWindowExpanded: return kEventWindowExpanded (nextHandler, theEvent, userData);
- case OS.kEventWindowGetRegion: return kEventWindowGetRegion (nextHandler, theEvent, userData);
- case OS.kEventWindowHidden: return kEventWindowHidden (nextHandler, theEvent, userData);
- case OS.kEventWindowHitTest: return kEventWindowHitTest (nextHandler, theEvent, userData);
- case OS.kEventWindowShown: return kEventWindowShown (nextHandler, theEvent, userData);
- case OS.kEventWindowUpdate: return kEventWindowUpdate (nextHandler, theEvent, userData);
- case OS.kEventWindowGetClickModality: return kEventWindowGetClickModality (nextHandler, theEvent, userData);
- }
- return OS.eventNotHandledErr;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Color.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Color.java
deleted file mode 100755
index dc1823530d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Color.java
+++ /dev/null
@@ -1,266 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage the operating system resources that
- * implement SWT's RGB color model. To create a color you can either
- * specify the individual color components as integers in the range
- * 0 to 255 or provide an instance of an <code>RGB</code>.
- * <p>
- * Application code must explicitly invoke the <code>Color.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see RGB
- * @see Device#getSystemColor
- * @see <a href="http://www.eclipse.org/swt/snippets/#color">Color and RGB snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Color extends Resource {
- /**
- * the handle to the OS color resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public float /*double*/ [] handle;
-
-Color(Device device) {
- super(device);
-}
-
-/**
- * Constructs a new instance of this class given a device and the
- * desired red, green and blue values expressed as ints in the range
- * 0 to 255 (where 0 is black and 255 is full brightness). On limited
- * color devices, the color instance created by this call may not have
- * the same RGB values as the ones specified by the arguments. The
- * RGB values on the returned instance will be the color values of
- * the operating system color.
- * <p>
- * You must dispose the color when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param red the amount of red in the color
- * @param green the amount of green in the color
- * @param blue the amount of blue in the color
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255</li>
- * </ul>
- *
- * @see #dispose
- */
-public Color(Device device, int red, int green, int blue) {
- super(device);
- init(red, green, blue);
- init();
-}
-
-/**
- * Constructs a new instance of this class given a device and an
- * <code>RGB</code> describing the desired red, green and blue values.
- * On limited color devices, the color instance created by this call
- * may not have the same RGB values as the ones specified by the
- * argument. The RGB values on the returned instance will be the color
- * values of the operating system color.
- * <p>
- * You must dispose the color when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param rgb the RGB values of the desired color
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the rgb argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue components of the argument are not between 0 and 255</li>
- * </ul>
- *
- * @see #dispose
- */
-public Color(Device device, RGB rgb) {
- super(device);
- if (rgb == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(rgb.red, rgb.green, rgb.blue);
- init();
-}
-
-void destroy() {
- handle = null;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals(Object object) {
- if (object == this) return true;
- if (!(object instanceof Color)) return false;
- Color color = (Color)object;
- float /*double*/ [] rgbColor = color.handle;
- if (handle == rgbColor) return true;
- return device == color.device &&
- (int)(handle[0] * 255) == (int)(rgbColor[0] * 255) &&
- (int)(handle[1] * 255) == (int)(rgbColor[1] * 255) &&
- (int)(handle[2] * 255) == (int)(rgbColor[2] * 255);
-}
-
-/**
- * Returns the amount of blue in the color, from 0 to 255.
- *
- * @return the blue component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getBlue() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (int)(handle[2] * 255);
-}
-
-/**
- * Returns the amount of green in the color, from 0 to 255.
- *
- * @return the green component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getGreen() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (int)(handle[1] * 255);
-}
-
-/**
- * Returns the amount of red in the color, from 0 to 255.
- *
- * @return the red component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getRed() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (int)(handle[0] * 255);
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode() {
- if (isDisposed()) return 0;
- return (int)(handle[0] * 255) ^ (int)(handle[1] * 255) ^ (int)(handle[2] * 255);
-}
-
-/**
- * Returns an <code>RGB</code> representing the receiver.
- *
- * @return the RGB for the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public RGB getRGB () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return new RGB(getRed(), getGreen(), getBlue());
-}
-
-/**
- * Invokes platform specific functionality to allocate a new color.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Color</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param handle the handle for the color
- *
- * @private
- */
-public static Color cocoa_new(Device device, float /*double*/ [] rgbColor) {
- Color color = new Color(device);
- color.handle = rgbColor;
- return color;
-}
-
-void init(int red, int green, int blue) {
- if ((red > 255) || (red < 0) ||
- (green > 255) || (green < 0) ||
- (blue > 255) || (blue < 0)) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- float /*double*/ [] rgbColor = new float /*double*/ [4];
- rgbColor[0] = red / 255f;
- rgbColor[1] = green / 255f;
- rgbColor[2] = blue / 255f;
- rgbColor[3] = 1;
- handle = rgbColor;
-}
-
-/**
- * Returns <code>true</code> if the color has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the color.
- * When a color has been disposed, it is an error to
- * invoke any other method using the color.
- *
- * @return <code>true</code> when the color is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == null;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Color {*DISPOSED*}";
- return "Color {" + getRed() + ", " + getGreen() + ", " + getBlue() + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Cursor.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Cursor.java
deleted file mode 100755
index 64e4531750..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Cursor.java
+++ /dev/null
@@ -1,467 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.cocoa.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage operating system resources that
- * specify the appearance of the on-screen pointer. To create a
- * cursor you specify the device and either a simple cursor style
- * describing one of the standard operating system provided cursors
- * or the image and mask data for the desired appearance.
- * <p>
- * Application code must explicitly invoke the <code>Cursor.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>
- * CURSOR_ARROW, CURSOR_WAIT, CURSOR_CROSS, CURSOR_APPSTARTING, CURSOR_HELP,
- * CURSOR_SIZEALL, CURSOR_SIZENESW, CURSOR_SIZENS, CURSOR_SIZENWSE, CURSOR_SIZEWE,
- * CURSOR_SIZEN, CURSOR_SIZES, CURSOR_SIZEE, CURSOR_SIZEW, CURSOR_SIZENE, CURSOR_SIZESE,
- * CURSOR_SIZESW, CURSOR_SIZENW, CURSOR_UPARROW, CURSOR_IBEAM, CURSOR_NO, CURSOR_HAND
- * </dd>
- * </dl>
- * <p>
- * Note: Only one of the above styles may be specified.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#cursor">Cursor snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class Cursor extends Resource {
-
- static final byte[] WAIT_SOURCE = new byte[] {
- (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- };
-
- /**
- * the handle to the OS cursor resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public NSCursor handle;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Cursor(Device device) {
- super(device);
-}
-
-/**
- * Constructs a new cursor given a device and a style
- * constant describing the desired cursor appearance.
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param style the style of cursor to allocate
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - when an unknown style is specified</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- *
- * @see SWT#CURSOR_ARROW
- * @see SWT#CURSOR_WAIT
- * @see SWT#CURSOR_CROSS
- * @see SWT#CURSOR_APPSTARTING
- * @see SWT#CURSOR_HELP
- * @see SWT#CURSOR_SIZEALL
- * @see SWT#CURSOR_SIZENESW
- * @see SWT#CURSOR_SIZENS
- * @see SWT#CURSOR_SIZENWSE
- * @see SWT#CURSOR_SIZEWE
- * @see SWT#CURSOR_SIZEN
- * @see SWT#CURSOR_SIZES
- * @see SWT#CURSOR_SIZEE
- * @see SWT#CURSOR_SIZEW
- * @see SWT#CURSOR_SIZENE
- * @see SWT#CURSOR_SIZESE
- * @see SWT#CURSOR_SIZESW
- * @see SWT#CURSOR_SIZENW
- * @see SWT#CURSOR_UPARROW
- * @see SWT#CURSOR_IBEAM
- * @see SWT#CURSOR_NO
- * @see SWT#CURSOR_HAND
- */
-public Cursor(Device device, int style) {
- super(device);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- switch (style) {
- case SWT.CURSOR_HAND: handle = NSCursor.pointingHandCursor(); break;
- case SWT.CURSOR_ARROW: handle = NSCursor.arrowCursor(); break;
- case SWT.CURSOR_WAIT: break;
- case SWT.CURSOR_CROSS: handle = NSCursor.crosshairCursor(); break;
- case SWT.CURSOR_APPSTARTING: handle = NSCursor.arrowCursor(); break;
- case SWT.CURSOR_HELP: handle = NSCursor.crosshairCursor(); break;
- case SWT.CURSOR_SIZEALL: handle = NSCursor.crosshairCursor(); break;
- case SWT.CURSOR_SIZENESW: handle = NSCursor.crosshairCursor(); break;
- case SWT.CURSOR_SIZENS: handle = NSCursor.resizeUpDownCursor(); break;
- case SWT.CURSOR_SIZENWSE: handle = NSCursor.crosshairCursor(); break;
- case SWT.CURSOR_SIZEWE: handle = NSCursor.resizeLeftRightCursor(); break;
- case SWT.CURSOR_SIZEN: handle = NSCursor.resizeUpCursor(); break;
- case SWT.CURSOR_SIZES: handle = NSCursor.resizeDownCursor(); break;
- case SWT.CURSOR_SIZEE: handle = NSCursor.resizeRightCursor(); break;
- case SWT.CURSOR_SIZEW: handle = NSCursor.resizeLeftCursor(); break;
- case SWT.CURSOR_SIZENE: handle = NSCursor.crosshairCursor(); break;
- case SWT.CURSOR_SIZESE: handle = NSCursor.crosshairCursor(); break;
- case SWT.CURSOR_SIZESW: handle = NSCursor.crosshairCursor(); break;
- case SWT.CURSOR_SIZENW: handle = NSCursor.crosshairCursor(); break;
- case SWT.CURSOR_UPARROW: handle = NSCursor.crosshairCursor(); break;
- case SWT.CURSOR_IBEAM: handle = NSCursor.IBeamCursor(); break;
- case SWT.CURSOR_NO: handle = NSCursor.crosshairCursor(); break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (handle == null && style == SWT.CURSOR_WAIT) {
- NSImage nsImage = (NSImage)new NSImage().alloc();
- NSBitmapImageRep nsImageRep = (NSBitmapImageRep)new NSBitmapImageRep().alloc();
- handle = (NSCursor)new NSCursor().alloc();
- int width = 16, height = 16;
- NSSize size = new NSSize();
- size.width = width;
- size.height = height;
- nsImage = nsImage.initWithSize(size);
- nsImageRep = nsImageRep.initWithBitmapDataPlanes(0, width, height, 8, 4, true, false, OS.NSDeviceRGBColorSpace,
- OS.NSAlphaFirstBitmapFormat | OS.NSAlphaNonpremultipliedBitmapFormat, width*4, 32);
- OS.memmove(nsImageRep.bitmapData(), WAIT_SOURCE, WAIT_SOURCE.length);
- nsImage.addRepresentation(nsImageRep);
- NSPoint point = new NSPoint();
- point.x = 0;
- point.y = 0;
- handle = handle.initWithImage(nsImage, point);
- nsImageRep.release();
- nsImage.release();
- } else {
- handle.retain();
- }
- handle.setOnMouseEntered(true);
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Constructs a new cursor given a device, image and mask
- * data describing the desired cursor appearance, and the x
- * and y coordinates of the <em>hotspot</em> (that is, the point
- * within the area covered by the cursor which is considered
- * to be where the on-screen pointer is "pointing").
- * <p>
- * The mask data is allowed to be null, but in this case the source
- * must be an ImageData representing an icon that specifies both
- * color data and mask data.
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param source the color data for the cursor
- * @param mask the mask data for the cursor (or null)
- * @param hotspotX the x coordinate of the cursor's hotspot
- * @param hotspotY the y coordinate of the cursor's hotspot
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the source is null</li>
- * <li>ERROR_NULL_ARGUMENT - if the mask is null and the source does not have a mask</li>
- * <li>ERROR_INVALID_ARGUMENT - if the source and the mask are not the same
- * size, or if the hotspot is outside the bounds of the image</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- */
-public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (mask == null) {
- if (source.getTransparencyType() != SWT.TRANSPARENCY_MASK) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- mask = source.getTransparencyMask();
- }
- /* Check the bounds. Mask must be the same size as source */
- if (mask.width != source.width || mask.height != source.height) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- /* Check the hotspots */
- if (hotspotX >= source.width || hotspotX < 0 ||
- hotspotY >= source.height || hotspotY < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- byte[] data = new byte[source.width * source.height * 4];
- for (int y = 0; y < source.height; y++) {
- int offset = y * source.width * 4;
- for (int x = 0; x < source.width; x++) {
- int pixel = source.getPixel(x, y);
- int maskPixel = mask.getPixel(x, y);
- if (pixel == 0 && maskPixel == 0) {
- // BLACK
- data[offset] = (byte)0xFF;
- } else if (pixel == 0 && maskPixel == 1) {
- // WHITE - cursor color
- data[offset] = data[offset + 1] = data[offset + 2] = data[offset + 3] = (byte)0xFF;
- } else if (pixel == 1 && maskPixel == 0) {
- // SCREEN
- } else {
- /*
- * Feature in the Macintosh. It is not possible to have
- * the reverse screen case using NSCursor.
- * Reverse screen will be the same as screen.
- */
- // REVERSE SCREEN -> SCREEN
- }
- offset += 4;
- }
- }
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- createNSCursor(hotspotX, hotspotY, data, source.width, source.height);
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-void createNSCursor(int hotspotX, int hotspotY, byte[] buffer, int width, int height) {
- NSImage nsImage = (NSImage)new NSImage().alloc();
- NSBitmapImageRep nsImageRep = (NSBitmapImageRep)new NSBitmapImageRep().alloc();
- handle = (NSCursor)new NSCursor().alloc();
- NSSize size = new NSSize();
- size.width = width;
- size.height = height;
- nsImage = nsImage.initWithSize(size);
- nsImageRep = nsImageRep.initWithBitmapDataPlanes(0, width, height,
- 8, 4, true, false, new NSString(OS.NSDeviceRGBColorSpace()),
- OS.NSAlphaFirstBitmapFormat | OS.NSAlphaNonpremultipliedBitmapFormat, width * 4, 32);
- OS.memmove(nsImageRep.bitmapData(), buffer, buffer.length);
- nsImage.addRepresentation(nsImageRep);
- NSPoint point = new NSPoint();
- point.x = hotspotX;
- point.y = hotspotY;
- handle = handle.initWithImage(nsImage, point);
- nsImageRep.release();
- nsImage.release();
-}
-
-/**
- * Constructs a new cursor given a device, image data describing
- * the desired cursor appearance, and the x and y coordinates of
- * the <em>hotspot</em> (that is, the point within the area
- * covered by the cursor which is considered to be where the
- * on-screen pointer is "pointing").
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param source the image data for the cursor
- * @param hotspotX the x coordinate of the cursor's hotspot
- * @param hotspotY the y coordinate of the cursor's hotspot
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the hotspot is outside the bounds of the
- * image</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- *
- * @since 3.0
- */
-public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (hotspotX >= source.width || hotspotX < 0 ||
- hotspotY >= source.height || hotspotY < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- byte[] data = new byte[source.width * source.height * 4];
- PaletteData palette = source.palette;
- if (palette.isDirect) {
- ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, palette.redMask, palette.greenMask, palette.blueMask,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- data, 32, source.width * 4, ImageData.MSB_FIRST, 0, 0, source.width, source.height, 0xFF0000, 0xFF00, 0xFF,
- false, false);
- } else {
- RGB[] rgbs = palette.getRGBs();
- int length = rgbs.length;
- byte[] srcReds = new byte[length];
- byte[] srcGreens = new byte[length];
- byte[] srcBlues = new byte[length];
- for (int i = 0; i < rgbs.length; i++) {
- RGB rgb = rgbs[i];
- if (rgb == null) continue;
- srcReds[i] = (byte)rgb.red;
- srcGreens[i] = (byte)rgb.green;
- srcBlues[i] = (byte)rgb.blue;
- }
- ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, srcReds, srcGreens, srcBlues,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- data, 32, source.width * 4, ImageData.MSB_FIRST, 0, 0, source.width, source.height, 0xFF0000, 0xFF00, 0xFF,
- false, false);
- }
- if (source.maskData != null || source.transparentPixel != -1) {
- ImageData mask = source.getTransparencyMask();
- byte[] maskData = mask.data;
- int maskBpl = mask.bytesPerLine;
- int offset = 0, maskOffset = 0;
- for (int y = 0; y<source.height; y++) {
- for (int x = 0; x<source.width; x++) {
- data[offset] = ((maskData[maskOffset + (x >> 3)]) & (1 << (7 - (x & 0x7)))) != 0 ? (byte)0xff : 0;
- offset += 4;
- }
- maskOffset += maskBpl;
- }
- } else if (source.alpha != -1) {
- byte alpha = (byte)source.alpha;
- for (int i=0; i<data.length; i+=4) {
- data[i] = alpha;
- }
- } else if (source.alphaData != null) {
- byte[] alphaData = source.alphaData;
- for (int i=0; i<data.length; i+=4) {
- data[i] = alphaData[i/4];
- }
- }
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- createNSCursor(hotspotX, hotspotY, data, source.width, source.height);
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-void destroy() {
- handle.release();
- handle = null;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Cursor)) return false;
- Cursor cursor = (Cursor) object;
- return device == cursor.device && handle == cursor.handle;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return handle != null ? (int)/*64*/handle.id : 0;
-}
-
-/**
- * Returns <code>true</code> if the cursor has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the cursor.
- * When a cursor has been disposed, it is an error to
- * invoke any other method using the cursor.
- *
- * @return <code>true</code> when the cursor is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == null;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Cursor {*DISPOSED*}";
- return "Cursor {" + handle + "}";
-}
-
-/**
- * Invokes platform specific functionality to allocate a new cursor.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Cursor</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param handle the handle for the cursor
- *
- * @private
- */
-public static Cursor cocoa_new(Device device, NSCursor handle) {
- Cursor cursor = new Cursor(device);
- cursor.handle = handle;
- return cursor;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java
deleted file mode 100755
index 932e1d49f6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java
+++ /dev/null
@@ -1,748 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.Compatibility;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * This class is the abstract superclass of all device objects,
- * such as the Display device and the Printer device. Devices
- * can have a graphics context (GC) created for them, and they
- * can be drawn on by sending messages to the associated GC.
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class Device implements Drawable {
-
- /* Debugging */
- public static boolean DEBUG;
- boolean debug = DEBUG;
- boolean tracking = DEBUG;
- Error [] errors;
- Object [] objects;
- Object trackingLock;
-
- /* Disposed flag */
- boolean disposed, warnings;
-
- Color COLOR_BLACK, COLOR_DARK_RED, COLOR_DARK_GREEN, COLOR_DARK_YELLOW, COLOR_DARK_BLUE;
- Color COLOR_DARK_MAGENTA, COLOR_DARK_CYAN, COLOR_GRAY, COLOR_DARK_GRAY, COLOR_RED;
- Color COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE;
-
- /* System Font */
- Font systemFont;
-
- NSMutableParagraphStyle paragraphStyle;
-
- /* Device DPI */
- Point dpi;
-
- /*
- * TEMPORARY CODE. When a graphics object is
- * created and the device parameter is null,
- * the current Display is used. This presents
- * a problem because SWT graphics does not
- * reference classes in SWT widgets. The correct
- * fix is to remove this feature. Unfortunately,
- * too many application programs rely on this
- * feature.
- */
- protected static Device CurrentDevice;
- protected static Runnable DeviceFinder;
- static {
- try {
- Class.forName ("org.eclipse.swt.widgets.Display");
- } catch (ClassNotFoundException e) {}
- }
-
-/*
-* TEMPORARY CODE.
-*/
-static synchronized Device getDevice () {
- if (DeviceFinder != null) DeviceFinder.run();
- Device device = CurrentDevice;
- CurrentDevice = null;
- return device;
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * You must dispose the device when it is no longer required.
- * </p>
- *
- * @see #create
- * @see #init
- *
- * @since 3.1
- */
-public Device() {
- this(null);
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * You must dispose the device when it is no longer required.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #create
- * @see #init
- * @see DeviceData
- */
-public Device(DeviceData data) {
- synchronized (Device.class) {
- if (data != null) {
- debug = data.debug;
- tracking = data.tracking;
- }
- if (tracking) {
- errors = new Error [128];
- objects = new Object [128];
- trackingLock = new Object ();
- }
- if (NSThread.isMainThread()) {
- NSAutoreleasePool pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- NSThread nsthread = NSThread.currentThread();
- NSMutableDictionary dictionary = nsthread.threadDictionary();
- NSString key = NSString.stringWith("SWT_NSAutoreleasePool");
- id obj = dictionary.objectForKey(key);
- if (obj == null) {
- NSNumber nsnumber = NSNumber.numberWithInteger(pool.id);
- dictionary.setObject(nsnumber, key);
- } else {
- pool.release();
- }
- }
- //check and create pool
- create (data);
- init ();
- }
-}
-
-/**
- * Throws an <code>SWTException</code> if the receiver can not
- * be accessed by the caller. This may include both checks on
- * the state of the receiver and more generally on the entire
- * execution context. This method <em>should</em> be called by
- * device implementors to enforce the standard SWT invariants.
- * <p>
- * Currently, it is an error to invoke any method (other than
- * <code>isDisposed()</code> and <code>dispose()</code>) on a
- * device that has had its <code>dispose()</code> method called.
- * </p><p>
- * In future releases of SWT, there may be more or fewer error
- * checks and exceptions may be thrown for different reasons.
- * <p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-protected void checkDevice () {
- if (disposed) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
-}
-
-/**
- * Creates the device in the operating system. If the device
- * does not have a handle, this method may do nothing depending
- * on the device.
- * <p>
- * This method is called before <code>init</code>.
- * </p><p>
- * Subclasses are supposed to reimplement this method and not
- * call the <code>super</code> implementation.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #init
- */
-protected void create (DeviceData data) {
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the receiver. After this method has been invoked, the receiver
- * will answer <code>true</code> when sent the message
- * <code>isDisposed()</code>.
- *
- * @see #release
- * @see #destroy
- * @see #checkDevice
- */
-public void dispose () {
- synchronized (Device.class) {
- if (isDisposed()) return;
- checkDevice ();
- release ();
- destroy ();
- disposed = true;
- if (tracking) {
- synchronized (trackingLock) {
- printErrors ();
- objects = null;
- errors = null;
- trackingLock = null;
- }
- }
- }
-}
-
-void dispose_Object (Object object) {
- synchronized (trackingLock) {
- for (int i=0; i<objects.length; i++) {
- if (objects [i] == object) {
- objects [i] = null;
- errors [i] = null;
- return;
- }
- }
- }
-}
-
-/**
- * Destroys the device in the operating system and releases
- * the device's handle. If the device does not have a handle,
- * this method may do nothing depending on the device.
- * <p>
- * This method is called after <code>release</code>.
- * </p><p>
- * Subclasses are supposed to reimplement this method and not
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #dispose
- * @see #release
- */
-protected void destroy () {
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location.
- *
- * @return the bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkDevice ();
- NSRect frame = getPrimaryScreen().frame();
- return new Rectangle((int)frame.x, (int)frame.y, (int)frame.width, (int)frame.height);
-}
-
-/**
- * Returns a <code>DeviceData</code> based on the receiver.
- * Modifications made to this <code>DeviceData</code> will not
- * affect the receiver.
- *
- * @return a <code>DeviceData</code> containing the device's data and attributes
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see DeviceData
- */
-public DeviceData getDeviceData () {
- checkDevice();
- DeviceData data = new DeviceData ();
- data.debug = debug;
- data.tracking = tracking;
- if (tracking) {
- synchronized (trackingLock) {
- int count = 0, length = objects.length;
- for (int i=0; i<length; i++) {
- if (objects [i] != null) count++;
- }
- int index = 0;
- data.objects = new Object [count];
- data.errors = new Error [count];
- for (int i=0; i<length; i++) {
- if (objects [i] != null) {
- data.objects [index] = objects [i];
- data.errors [index] = errors [i];
- index++;
- }
- }
- }
- } else {
- data.objects = new Object [0];
- data.errors = new Error [0];
- }
- return data;
-}
-
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data.
- *
- * @return the client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getBounds
- */
-public Rectangle getClientArea () {
- checkDevice ();
- return getBounds ();
-}
-
-/**
- * Returns the bit depth of the screen, which is the number of
- * bits it takes to represent the number of unique colors that
- * the screen is currently capable of displaying. This number
- * will typically be one of 1, 8, 15, 16, 24 or 32.
- *
- * @return the depth of the screen
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getDepth () {
- checkDevice ();
- return (int)/*64*/OS.NSBitsPerPixelFromDepth(getPrimaryScreen().depth());
-}
-
-/**
- * Returns a point whose x coordinate is the horizontal
- * dots per inch of the display, and whose y coordinate
- * is the vertical dots per inch of the display.
- *
- * @return the horizontal and vertical DPI
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point getDPI () {
- checkDevice ();
- return getScreenDPI();
-}
-
-NSScreen getPrimaryScreen () {
- NSArray screens = NSScreen.screens();
- return new NSScreen(screens.objectAtIndex(0));
-}
-
-/**
- * Returns <code>FontData</code> objects which describe
- * the fonts that match the given arguments. If the
- * <code>faceName</code> is null, all fonts will be returned.
- *
- * @param faceName the name of the font to look for, or null
- * @param scalable if true only scalable fonts are returned, otherwise only non-scalable fonts are returned.
- * @return the matching font data
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontData[] getFontList (String faceName, boolean scalable) {
- checkDevice ();
- if (!scalable) return new FontData[0];
- int count = 0;
- NSArray families = NSFontManager.sharedFontManager().availableFontFamilies();
- int /*long*/ familyCount = families.count();
- FontData[] fds = new FontData[100];
- for (int i = 0; i < familyCount; i++) {
- NSString nsFamily = new NSString(families.objectAtIndex(i));
- String name = nsFamily.getString();
- NSArray fonts = NSFontManager.sharedFontManager().availableMembersOfFontFamily(nsFamily);
- int fontCount = (int)/*64*/fonts.count();
- for (int j = 0; j < fontCount; j++) {
- NSArray fontDetails = new NSArray(fonts.objectAtIndex(j));
- String nsName = new NSString(fontDetails.objectAtIndex(0)).getString();
- int /*long*/ weight = new NSNumber(fontDetails.objectAtIndex(2)).integerValue();
- int /*long*/ traits = new NSNumber(fontDetails.objectAtIndex(3)).integerValue();
- int style = SWT.NORMAL;
- if ((traits & OS.NSItalicFontMask) != 0) style |= SWT.ITALIC;
- if (weight == 9) style |= SWT.BOLD;
- if (faceName == null || Compatibility.equalsIgnoreCase(faceName, name)) {
- FontData data = new FontData(name, 0, style);
- data.nsName = nsName;
- if (count == fds.length) {
- FontData[] newFds = new FontData[fds.length + 100];
- System.arraycopy(fds, 0, newFds, 0, fds.length);
- fds = newFds;
- }
- fds[count++] = data;
- }
- }
- }
- if (count == fds.length) return fds;
- FontData[] result = new FontData[count];
- System.arraycopy(fds, 0, result, 0, count);
- return result;
-}
-
-Point getScreenDPI () {
- NSDictionary dictionary = getPrimaryScreen().deviceDescription();
- NSValue value = new NSValue(dictionary.objectForKey(new id(OS.NSDeviceResolution())).id);
- NSSize size = value.sizeValue();
- return new Point((int)size.width, (int)size.height);
-}
-
-/**
- * Returns the matching standard color for the given
- * constant, which should be one of the color constants
- * specified in class <code>SWT</code>. Any value other
- * than one of the SWT color constants which is passed
- * in will result in the color black. This color should
- * not be freed because it was allocated by the system,
- * not the application.
- *
- * @param id the color constant
- * @return the matching color
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT
- */
-public Color getSystemColor (int id) {
- checkDevice ();
- switch (id) {
- case SWT.COLOR_BLACK: return COLOR_BLACK;
- case SWT.COLOR_DARK_RED: return COLOR_DARK_RED;
- case SWT.COLOR_DARK_GREEN: return COLOR_DARK_GREEN;
- case SWT.COLOR_DARK_YELLOW: return COLOR_DARK_YELLOW;
- case SWT.COLOR_DARK_BLUE: return COLOR_DARK_BLUE;
- case SWT.COLOR_DARK_MAGENTA: return COLOR_DARK_MAGENTA;
- case SWT.COLOR_DARK_CYAN: return COLOR_DARK_CYAN;
- case SWT.COLOR_GRAY: return COLOR_GRAY;
- case SWT.COLOR_DARK_GRAY: return COLOR_DARK_GRAY;
- case SWT.COLOR_RED: return COLOR_RED;
- case SWT.COLOR_GREEN: return COLOR_GREEN;
- case SWT.COLOR_YELLOW: return COLOR_YELLOW;
- case SWT.COLOR_BLUE: return COLOR_BLUE;
- case SWT.COLOR_MAGENTA: return COLOR_MAGENTA;
- case SWT.COLOR_CYAN: return COLOR_CYAN;
- case SWT.COLOR_WHITE: return COLOR_WHITE;
- }
- return COLOR_BLACK;
-}
-
-/**
- * Returns a reasonable font for applications to use.
- * On some platforms, this will match the "default font"
- * or "system font" if such can be found. This font
- * should not be freed because it was allocated by the
- * system, not the application.
- * <p>
- * Typically, applications which want the default look
- * should simply not set the font on the widgets they
- * create. Widgets are always created with the correct
- * default font for the class of user-interface component
- * they represent.
- * </p>
- *
- * @return a font
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getSystemFont () {
- checkDevice ();
- return systemFont;
-}
-
-/**
- * Returns <code>true</code> if the underlying window system prints out
- * warning messages on the console, and <code>setWarnings</code>
- * had previously been called with <code>true</code>.
- *
- * @return <code>true</code>if warnings are being handled, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean getWarnings () {
- checkDevice ();
- return warnings;
-}
-
-/**
- * Initializes any internal resources needed by the
- * device.
- * <p>
- * This method is called after <code>create</code>.
- * </p><p>
- * If subclasses reimplement this method, they must
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #create
- */
-protected void init () {
- /* Create the standard colors */
- COLOR_BLACK = new Color (this, 0,0,0);
- COLOR_DARK_RED = new Color (this, 0x80,0,0);
- COLOR_DARK_GREEN = new Color (this, 0,0x80,0);
- COLOR_DARK_YELLOW = new Color (this, 0x80,0x80,0);
- COLOR_DARK_BLUE = new Color (this, 0,0,0x80);
- COLOR_DARK_MAGENTA = new Color (this, 0x80,0,0x80);
- COLOR_DARK_CYAN = new Color (this, 0,0x80,0x80);
- COLOR_GRAY = new Color (this, 0xC0,0xC0,0xC0);
- COLOR_DARK_GRAY = new Color (this, 0x80,0x80,0x80);
- COLOR_RED = new Color (this, 0xFF,0,0);
- COLOR_GREEN = new Color (this, 0,0xFF,0);
- COLOR_YELLOW = new Color (this, 0xFF,0xFF,0);
- COLOR_BLUE = new Color (this, 0,0,0xFF);
- COLOR_MAGENTA = new Color (this, 0xFF,0,0xFF);
- COLOR_CYAN = new Color (this, 0,0xFF,0xFF);
- COLOR_WHITE = new Color (this, 0xFF,0xFF,0xFF);
-
- paragraphStyle = (NSMutableParagraphStyle)new NSMutableParagraphStyle().alloc().init();
- paragraphStyle.setAlignment(OS.NSLeftTextAlignment);
- paragraphStyle.setLineBreakMode(OS.NSLineBreakByClipping);
- NSArray tabs = new NSArray(new NSArray().alloc().init());
- paragraphStyle.setTabStops(tabs);
- tabs.release();
-
- /* Initialize the system font slot */
- boolean smallFonts = System.getProperty("org.eclipse.swt.internal.carbon.smallFonts") != null;
- float /*double*/ systemFontSize = smallFonts ? NSFont.smallSystemFontSize() : NSFont.systemFontSize();
- Point dpi = this.dpi = getDPI(), screenDPI = getScreenDPI();
- NSFont font = NSFont.systemFontOfSize(systemFontSize * dpi.y / screenDPI.y);
- font.retain();
- systemFont = Font.cocoa_new(this, font);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Device</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public abstract int /*long*/ internal_new_GC (GCData data);
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Device</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public abstract void internal_dispose_GC (int /*long*/ handle, GCData data);
-
-/**
- * Returns <code>true</code> if the device has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the device.
- * When a device has been disposed, it is an error to
- * invoke any other method using the device.
- *
- * @return <code>true</code> when the device is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- synchronized (Device.class) {
- return disposed;
- }
-}
-
-/**
- * Loads the font specified by a file. The font will be
- * present in the list of fonts available to the application.
- *
- * @param path the font file path
- * @return whether the font was successfully loaded
- *
- * @exception SWTException <ul>
- * <li>ERROR_NULL_ARGUMENT - if path is null</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Font
- *
- * @since 3.3
- */
-public boolean loadFont (String path) {
- checkDevice();
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- boolean result = false;
- NSString nsPath = NSString.stringWith(path);
- int /*long*/ fsRepresentation = nsPath.fileSystemRepresentation();
-
- if (fsRepresentation != 0) {
- byte [] fsRef = new byte [80];
- boolean [] isDirectory = new boolean[1];
- if (OS.FSPathMakeRef (fsRepresentation, fsRef, isDirectory) == OS.noErr) {
- result = OS.ATSFontActivateFromFileReference (fsRef, OS.kATSFontContextLocal, OS.kATSFontFormatUnspecified, 0, OS.kATSOptionFlagsDefault, null) == OS.noErr;
- }
- }
-
- return result;
-}
-
-void new_Object (Object object) {
- synchronized (trackingLock) {
- for (int i=0; i<objects.length; i++) {
- if (objects [i] == null) {
- objects [i] = object;
- errors [i] = new Error ();
- return;
- }
- }
- Object [] newObjects = new Object [objects.length + 128];
- System.arraycopy (objects, 0, newObjects, 0, objects.length);
- newObjects [objects.length] = object;
- objects = newObjects;
- Error [] newErrors = new Error [errors.length + 128];
- System.arraycopy (errors, 0, newErrors, 0, errors.length);
- newErrors [errors.length] = new Error ();
- errors = newErrors;
- }
-}
-
-void printErrors () {
- if (!DEBUG) return;
- if (tracking) {
- synchronized (trackingLock) {
- if (objects == null || errors == null) return;
- int objectCount = 0;
- int colors = 0, cursors = 0, fonts = 0, gcs = 0, images = 0;
- int paths = 0, patterns = 0, regions = 0, textLayouts = 0, transforms = 0;
- for (int i=0; i<objects.length; i++) {
- Object object = objects [i];
- if (object != null) {
- objectCount++;
- if (object instanceof Color) colors++;
- if (object instanceof Cursor) cursors++;
- if (object instanceof Font) fonts++;
- if (object instanceof GC) gcs++;
- if (object instanceof Image) images++;
- if (object instanceof Path) paths++;
- if (object instanceof Pattern) patterns++;
- if (object instanceof Region) regions++;
- if (object instanceof TextLayout) textLayouts++;
- if (object instanceof Transform) transforms++;
- }
- }
- if (objectCount != 0) {
- String string = "Summary: ";
- if (colors != 0) string += colors + " Color(s), ";
- if (cursors != 0) string += cursors + " Cursor(s), ";
- if (fonts != 0) string += fonts + " Font(s), ";
- if (gcs != 0) string += gcs + " GC(s), ";
- if (images != 0) string += images + " Image(s), ";
- if (paths != 0) string += paths + " Path(s), ";
- if (patterns != 0) string += patterns + " Pattern(s), ";
- if (regions != 0) string += regions + " Region(s), ";
- if (textLayouts != 0) string += textLayouts + " TextLayout(s), ";
- if (transforms != 0) string += transforms + " Transforms(s), ";
- if (string.length () != 0) {
- string = string.substring (0, string.length () - 2);
- System.out.println (string);
- }
- for (int i=0; i<errors.length; i++) {
- if (errors [i] != null) errors [i].printStackTrace (System.out);
- }
- }
- }
- }
-}
-
-/**
- * Releases any internal resources back to the operating
- * system and clears all fields except the device handle.
- * <p>
- * When a device is destroyed, resources that were acquired
- * on behalf of the programmer need to be returned to the
- * operating system. For example, if the device allocated a
- * font to be used as the system font, this font would be
- * freed in <code>release</code>. Also,to assist the garbage
- * collector and minimize the amount of memory that is not
- * reclaimed when the programmer keeps a reference to a
- * disposed device, all fields except the handle are zero'd.
- * The handle is needed by <code>destroy</code>.
- * </p>
- * This method is called before <code>destroy</code>.
- * </p><p>
- * If subclasses reimplement this method, they must
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #dispose
- * @see #destroy
- */
-protected void release () {
- if (paragraphStyle != null) paragraphStyle.release();
- paragraphStyle = null;
-
- if (systemFont != null) systemFont.dispose();
- systemFont = null;
-
- if (COLOR_BLACK != null) COLOR_BLACK.dispose();
- if (COLOR_DARK_RED != null) COLOR_DARK_RED.dispose();
- if (COLOR_DARK_GREEN != null) COLOR_DARK_GREEN.dispose();
- if (COLOR_DARK_YELLOW != null) COLOR_DARK_YELLOW.dispose();
- if (COLOR_DARK_BLUE != null) COLOR_DARK_BLUE.dispose();
- if (COLOR_DARK_MAGENTA != null) COLOR_DARK_MAGENTA.dispose();
- if (COLOR_DARK_CYAN != null) COLOR_DARK_CYAN.dispose();
- if (COLOR_GRAY != null) COLOR_GRAY.dispose();
- if (COLOR_DARK_GRAY != null) COLOR_DARK_GRAY.dispose();
- if (COLOR_RED != null) COLOR_RED.dispose();
- if (COLOR_GREEN != null) COLOR_GREEN.dispose();
- if (COLOR_YELLOW != null) COLOR_YELLOW.dispose();
- if (COLOR_BLUE != null) COLOR_BLUE.dispose();
- if (COLOR_MAGENTA != null) COLOR_MAGENTA.dispose();
- if (COLOR_CYAN != null) COLOR_CYAN.dispose();
- if (COLOR_WHITE != null) COLOR_WHITE.dispose();
- COLOR_BLACK = COLOR_DARK_RED = COLOR_DARK_GREEN = COLOR_DARK_YELLOW = COLOR_DARK_BLUE =
- COLOR_DARK_MAGENTA = COLOR_DARK_CYAN = COLOR_GRAY = COLOR_DARK_GRAY = COLOR_RED =
- COLOR_GREEN = COLOR_YELLOW = COLOR_BLUE = COLOR_MAGENTA = COLOR_CYAN = COLOR_WHITE = null;
-}
-
-/**
- * If the underlying window system supports printing warning messages
- * to the console, setting warnings to <code>false</code> prevents these
- * messages from being printed. If the argument is <code>true</code> then
- * message printing is not blocked.
- *
- * @param warnings <code>true</code>if warnings should be printed, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setWarnings (boolean warnings) {
- checkDevice ();
- this.warnings = warnings;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/DeviceData.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/DeviceData.java
deleted file mode 100755
index ad0c2b2afe..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/DeviceData.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-public class DeviceData {
- /*
- * Debug fields - may not be honoured
- * on some SWT platforms.
- */
- public boolean debug;
- public boolean tracking;
- public Error [] errors;
- public Object [] objects;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Font.java
deleted file mode 100755
index b30ab417f2..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Font.java
+++ /dev/null
@@ -1,370 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.cocoa.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage operating system resources that
- * define how text looks when it is displayed. Fonts may be constructed
- * by providing a device and either name, size and style information
- * or a <code>FontData</code> object which encapsulates this data.
- * <p>
- * Application code must explicitly invoke the <code>Font.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see FontData
- * @see <a href="http://www.eclipse.org/swt/snippets/#font">Font snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Font extends Resource {
-
- /**
- * the handle to the OS font resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public NSFont handle;
-
- /**
- * the traits not supported to the OS font resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int extraTraits;
-
- static final double SYNTHETIC_BOLD = -2.5;
- static final double SYNTHETIC_ITALIC = 0.2;
-
-Font(Device device) {
- super(device);
-}
-
-/**
- * Constructs a new font given a device and font data
- * which describes the desired font's appearance.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param fd the FontData that describes the desired font (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the fd argument is null</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li>
- * </ul>
- */
-public Font(Device device, FontData fd) {
- super(device);
- if (fd == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- init(fd.getName(), fd.getHeightF(), fd.getStyle(), fd.nsName);
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Constructs a new font given a device and an array
- * of font data which describes the desired font's
- * appearance.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param fds the array of FontData that describes the desired font (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the fds argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the length of fds is zero</li>
- * <li>ERROR_NULL_ARGUMENT - if any fd in the array is null</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li>
- * </ul>
- *
- * @since 2.1
- */
-public Font(Device device, FontData[] fds) {
- super(device);
- if (fds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (fds.length == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<fds.length; i++) {
- if (fds[i] == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- FontData fd = fds[0];
- init(fd.getName(), fd.getHeightF(), fd.getStyle(), fd.nsName);
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Constructs a new font given a device, a font name,
- * the height of the desired font in points, and a font
- * style.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param name the name of the font (must not be null)
- * @param height the font height in points
- * @param style a bit or combination of NORMAL, BOLD, ITALIC
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the name argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given arguments</li>
- * </ul>
- */
-public Font(Device device, String name, int height, int style) {
- super(device);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- init(name, height, style, null);
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/*public*/ Font(Device device, String name, float height, int style) {
- super(device);
- init(name, height, style, null);
- init();
-}
-
-void addTraits(NSMutableAttributedString attrStr, NSRange range) {
- if ((extraTraits & OS.NSBoldFontMask) != 0) {
- attrStr.addAttribute(OS.NSStrokeWidthAttributeName, NSNumber.numberWithDouble(SYNTHETIC_BOLD), range);
- }
- if ((extraTraits & OS.NSItalicFontMask) != 0) {
- attrStr.addAttribute(OS.NSObliquenessAttributeName, NSNumber.numberWithDouble(SYNTHETIC_ITALIC), range);
- }
-}
-
-void addTraits(NSMutableDictionary dict) {
- if ((extraTraits & OS.NSBoldFontMask) != 0) {
- dict.setObject(NSNumber.numberWithDouble(SYNTHETIC_BOLD), OS.NSStrokeWidthAttributeName);
- }
- if ((extraTraits & OS.NSItalicFontMask) != 0) {
- dict.setObject(NSNumber.numberWithDouble(SYNTHETIC_ITALIC), OS.NSObliquenessAttributeName);
- }
-}
-
-void destroy() {
- handle.release();
- handle = null;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals(Object object) {
- if (object == this) return true;
- if (!(object instanceof Font)) return false;
- Font font = (Font)object;
- return handle == font.handle;
-}
-
-/**
- * Returns an array of <code>FontData</code>s representing the receiver.
- * On Windows, only one FontData will be returned per font. On X however,
- * a <code>Font</code> object <em>may</em> be composed of multiple X
- * fonts. To support this case, we return an array of font data objects.
- *
- * @return an array of font data objects describing the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontData[] getFontData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSString family = handle.familyName();
- String name = family.getString();
- NSString str = handle.fontName();
- String nsName = str.getString();
- NSFontManager manager = NSFontManager.sharedFontManager();
- int /*long*/ traits = manager.traitsOfFont(handle);
- int style = SWT.NORMAL;
- if ((traits & OS.NSItalicFontMask) != 0) style |= SWT.ITALIC;
- if ((traits & OS.NSBoldFontMask) != 0) style |= SWT.BOLD;
- if ((extraTraits & OS.NSItalicFontMask) != 0) style |= SWT.ITALIC;
- if ((extraTraits & OS.NSBoldFontMask) != 0) style |= SWT.BOLD;
- Point dpi = device.dpi, screenDPI = device.getScreenDPI();
- FontData data = new FontData(name, (float)/*64*/handle.pointSize() * screenDPI.y / dpi.y, style);
- data.nsName = nsName;
- return new FontData[]{data};
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Invokes platform specific functionality to allocate a new font.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Font</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param handle the handle for the font
- * @param style the style for the font
- * @param size the size for the font
- *
- * @private
- */
-public static Font cocoa_new(Device device, NSFont handle) {
- Font font = new Font(device);
- font.handle = handle;
- return font;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode() {
- return handle != null ? (int)/*64*/handle.id : 0;
-}
-
-void init(String name, float height, int style, String nsName) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Point dpi = device.dpi, screenDPI = device.getScreenDPI();
- float size = height * dpi.y / screenDPI.y;
- if (nsName != null) {
- handle = NSFont.fontWithName(NSString.stringWith(nsName), size);
- } else {
- NSString family = NSString.stringWith(name);
- NSFont nsFont = NSFont.fontWithName(family, size);
- if (nsFont == null) nsFont = NSFont.systemFontOfSize(size);
- NSFontManager manager = NSFontManager.sharedFontManager();
- if (nsFont != null) {
- if ((style & (SWT.BOLD | SWT.ITALIC)) == 0) {
- handle = nsFont;
- } else {
- int traits = 0;
- if ((style & SWT.ITALIC) != 0) traits |= OS.NSItalicFontMask;
- if ((style & SWT.BOLD) != 0) traits |= OS.NSBoldFontMask;
- handle = manager.convertFont(nsFont, traits);
- if ((style & SWT.ITALIC) != 0 && (handle == null || (manager.traitsOfFont(handle) & OS.NSItalicFontMask) == 0)) {
- traits &= ~OS.NSItalicFontMask;
- handle = null;
- if ((style & SWT.BOLD) != 0) {
- handle = manager.convertFont(nsFont, traits);
- }
- }
- if ((style & SWT.BOLD) != 0 && handle == null) {
- traits &= ~OS.NSBoldFontMask;
- if ((style & SWT.ITALIC) != 0) {
- traits |= OS.NSItalicFontMask;
- handle = manager.convertFont(nsFont, traits);
- }
- }
- if (handle == null) handle = nsFont;
- }
- }
- if (handle == null) {
- handle = NSFont.systemFontOfSize(size);
- }
- if ((style & SWT.ITALIC) != 0 && (manager.traitsOfFont(handle) & OS.NSItalicFontMask) == 0) {
- extraTraits |= OS.NSItalicFontMask;
- }
- if ((style & SWT.BOLD) != 0 && (manager.traitsOfFont(handle) & OS.NSBoldFontMask) == 0) {
- extraTraits |= OS.NSBoldFontMask;
- }
- }
- if (handle == null) {
- handle = device.systemFont.handle;
- }
- handle.retain();
-}
-
-/**
- * Returns <code>true</code> if the font has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the font.
- * When a font has been disposed, it is an error to
- * invoke any other method using the font.
- *
- * @return <code>true</code> when the font is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == null;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Font {*DISPOSED*}";
- return "Font {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/FontData.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/FontData.java
deleted file mode 100755
index 589f151ebe..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/FontData.java
+++ /dev/null
@@ -1,447 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class describe operating system fonts.
- * <p>
- * For platform-independent behaviour, use the get and set methods
- * corresponding to the following properties:
- * <dl>
- * <dt>height</dt><dd>the height of the font in points</dd>
- * <dt>name</dt><dd>the face name of the font, which may include the foundry</dd>
- * <dt>style</dt><dd>A bitwise combination of NORMAL, ITALIC and BOLD</dd>
- * </dl>
- * If extra, platform-dependent functionality is required:
- * <ul>
- * <li>On <em>Windows</em>, the data member of the <code>FontData</code>
- * corresponds to a Windows <code>LOGFONT</code> structure whose fields
- * may be retrieved and modified.</li>
- * <li>On <em>X</em>, the fields of the <code>FontData</code> correspond
- * to the entries in the font's XLFD name and may be retrieved and modified.
- * </ul>
- * Application code does <em>not</em> need to explicitly release the
- * resources managed by each instance when those instances are no longer
- * required, and thus no <code>dispose()</code> method is provided.
- *
- * @see Font
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class FontData {
- /**
- * the font name
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public String name;
-
- /**
- * The height of the font data in points
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public float height;
-
- /**
- * the font style
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int style;
-
- /**
- * the NSFont font name
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public String nsName;
-
- /**
- * The locales of the font
- */
- String lang, country, variant;
-
-/**
- * Constructs a new uninitialized font data.
- */
-public FontData () {
- this("", 12, SWT.NORMAL);
-}
-
-/**
- * Constructs a new FontData given a string representation
- * in the form generated by the <code>FontData.toString</code>
- * method.
- * <p>
- * Note that the representation varies between platforms,
- * and a FontData can only be created from a string that was
- * generated on the same platform.
- * </p>
- *
- * @param string the string representation of a <code>FontData</code> (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument does not represent a valid description</li>
- * </ul>
- *
- * @see #toString
- */
-public FontData(String string) {
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int start = 0;
- int end = string.indexOf('|');
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- String version1 = string.substring(start, end);
- try {
- if (Integer.parseInt(version1) != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- String name = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- float height = 0;
- try {
- height = Float.parseFloat(string.substring(start, end));
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int style = 0;
- try {
- style = Integer.parseInt(string.substring(start, end));
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- setName(name);
- setHeight(height);
- setStyle(style);
- if (end == -1) return;
- String platform = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- String version2 = string.substring(start, end);
-
- if (platform.equals("COCOA") && version2.equals("1")) {
- start = end + 1;
- end = string.length();
- if (start < end) nsName = string.substring(start, end);
- }
-}
-
-/**
- * Constructs a new font data given a font name,
- * the height of the desired font in points,
- * and a font style.
- *
- * @param name the name of the font (must not be null)
- * @param height the font height in points
- * @param style a bit or combination of NORMAL, BOLD, ITALIC
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - when the font name is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- */
-public FontData(String name, int height, int style) {
- setName(name);
- setHeight(height);
- setStyle(style);
-}
-
-/*public*/ FontData(String name, float height, int style) {
- setName(name);
- setHeight(height);
- setStyle(style);
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof FontData)) return false;
- FontData data = (FontData)object;
- return name.equals(data.name) && height == data.height && style == data.style;
-}
-
-/**
- * Returns the height of the receiver in points.
- *
- * @return the height of this FontData
- *
- * @see #setHeight(int)
- */
-public int getHeight() {
- return (int)height;
-}
-
-/*public*/ float getHeightF() {
- return height;
-}
-
-/**
- * Returns the locale of the receiver.
- * <p>
- * The locale determines which platform character set this
- * font is going to use. Widgets and graphics operations that
- * use this font will convert UNICODE strings to the platform
- * character set of the specified locale.
- * </p>
- * <p>
- * On platforms where there are multiple character sets for a
- * given language/country locale, the variant portion of the
- * locale will determine the character set.
- * </p>
- *
- * @return the <code>String</code> representing a Locale object
- * @since 3.0
- */
-public String getLocale () {
- StringBuffer buffer = new StringBuffer ();
- char sep = '_';
- if (lang != null) {
- buffer.append (lang);
- buffer.append (sep);
- }
- if (country != null) {
- buffer.append (country);
- buffer.append (sep);
- }
- if (variant != null) {
- buffer.append (variant);
- }
-
- String result = buffer.toString ();
- int length = result.length ();
- if (length > 0) {
- if (result.charAt (length - 1) == sep) {
- result = result.substring (0, length - 1);
- }
- }
- return result;
-}
-
-/**
- * Returns the name of the receiver.
- * On platforms that support font foundries, the return value will
- * be the foundry followed by a dash ("-") followed by the face name.
- *
- * @return the name of this <code>FontData</code>
- *
- * @see #setName
- */
-public String getName() {
- return name;
-}
-
-/**
- * Returns the style of the receiver which is a bitwise OR of
- * one or more of the <code>SWT</code> constants NORMAL, BOLD
- * and ITALIC.
- *
- * @return the style of this <code>FontData</code>
- *
- * @see #setStyle
- */
-public int getStyle() {
- return style;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return name.hashCode() ^ getHeight() ^ style;
-}
-
-/**
- * Sets the height of the receiver. The parameter is
- * specified in terms of points, where a point is one
- * seventy-second of an inch.
- *
- * @param height the height of the <code>FontData</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- *
- * @see #getHeight
- */
-public void setHeight(int height) {
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.height = height;
-}
-
-/*public*/ void setHeight(float height) {
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.height = height;
-}
-
-/**
- * Sets the locale of the receiver.
- * <p>
- * The locale determines which platform character set this
- * font is going to use. Widgets and graphics operations that
- * use this font will convert UNICODE strings to the platform
- * character set of the specified locale.
- * </p>
- * <p>
- * On platforms where there are multiple character sets for a
- * given language/country locale, the variant portion of the
- * locale will determine the character set.
- * </p>
- *
- * @param locale the <code>String</code> representing a Locale object
- * @see java.util.Locale#toString
- */
-public void setLocale(String locale) {
- lang = country = variant = null;
- if (locale != null) {
- char sep = '_';
- int length = locale.length();
- int firstSep, secondSep;
-
- firstSep = locale.indexOf(sep);
- if (firstSep == -1) {
- firstSep = secondSep = length;
- } else {
- secondSep = locale.indexOf(sep, firstSep + 1);
- if (secondSep == -1) secondSep = length;
- }
- if (firstSep > 0) lang = locale.substring(0, firstSep);
- if (secondSep > firstSep + 1) country = locale.substring(firstSep + 1, secondSep);
- if (length > secondSep + 1) variant = locale.substring(secondSep + 1);
- }
-}
-
-/**
- * Sets the name of the receiver.
- * <p>
- * Some platforms support font foundries. On these platforms, the name
- * of the font specified in setName() may have one of the following forms:
- * <ol>
- * <li>a face name (for example, "courier")</li>
- * <li>a foundry followed by a dash ("-") followed by a face name (for example, "adobe-courier")</li>
- * </ol>
- * In either case, the name returned from getName() will include the
- * foundry.
- * </p>
- * <p>
- * On platforms that do not support font foundries, only the face name
- * (for example, "courier") is used in <code>setName()</code> and
- * <code>getName()</code>.
- * </p>
- *
- * @param name the name of the font data (must not be null)
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - when the font name is null</li>
- * </ul>
- *
- * @see #getName
- */
-public void setName(String name) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.name = name;
- nsName = null;
-}
-
-/**
- * Sets the style of the receiver to the argument which must
- * be a bitwise OR of one or more of the <code>SWT</code>
- * constants NORMAL, BOLD and ITALIC. All other style bits are
- * ignored.
- *
- * @param style the new style for this <code>FontData</code>
- *
- * @see #getStyle
- */
-public void setStyle(int style) {
- this.style = style;
- nsName = null;
-}
-
-/**
- * Returns a string representation of the receiver which is suitable
- * for constructing an equivalent instance using the
- * <code>FontData(String)</code> constructor.
- *
- * @return a string representation of the FontData
- *
- * @see FontData
- */
-public String toString() {
- StringBuffer buffer = new StringBuffer(128);
- buffer.append("1|");
- buffer.append(getName());
- buffer.append("|");
- buffer.append(getHeightF());
- buffer.append("|");
- buffer.append(getStyle());
- buffer.append("|");
- buffer.append("COCOA|1|");
- if (nsName != null) buffer.append(nsName);
- return buffer.toString();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/FontMetrics.java
deleted file mode 100755
index 2c0d6a7a3f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/FontMetrics.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-/**
- * Instances of this class provide measurement information
- * about fonts including ascent, descent, height, leading
- * space between rows, and average character width.
- * <code>FontMetrics</code> are obtained from <code>GC</code>s
- * using the <code>getFontMetrics()</code> method.
- *
- * @see GC#getFontMetrics
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class FontMetrics {
- int ascent, descent, averageCharWidth, leading, height;
-
-FontMetrics() {
-}
-
-public static FontMetrics cocoa_new(int ascent, int descent, int averageCharWidth, int leading, int height) {
- FontMetrics fontMetrics = new FontMetrics();
- fontMetrics.ascent = ascent;
- fontMetrics.descent = descent;
- fontMetrics.averageCharWidth = averageCharWidth;
- fontMetrics.leading = leading;
- fontMetrics.height = height;
- return fontMetrics;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof FontMetrics)) return false;
- FontMetrics metrics = (FontMetrics)object;
- return ascent == metrics.ascent && descent == metrics.descent &&
- averageCharWidth == metrics.averageCharWidth && leading == metrics.leading &&
- height == metrics.height;
-}
-
-/**
- * Returns the ascent of the font described by the receiver. A
- * font's <em>ascent</em> is the distance from the baseline to the
- * top of actual characters, not including any of the leading area,
- * measured in pixels.
- *
- * @return the ascent of the font
- */
-public int getAscent() {
- return ascent;
-}
-
-/**
- * Returns the average character width, measured in pixels,
- * of the font described by the receiver.
- *
- * @return the average character width of the font
- */
-public int getAverageCharWidth() {
- return averageCharWidth;
-}
-
-/**
- * Returns the descent of the font described by the receiver. A
- * font's <em>descent</em> is the distance from the baseline to the
- * bottom of actual characters, not including any of the leading area,
- * measured in pixels.
- *
- * @return the descent of the font
- */
-public int getDescent() {
- return descent;
-}
-
-/**
- * Returns the height of the font described by the receiver,
- * measured in pixels. A font's <em>height</em> is the sum of
- * its ascent, descent and leading area.
- *
- * @return the height of the font
- *
- * @see #getAscent
- * @see #getDescent
- * @see #getLeading
- */
-public int getHeight() {
- return height;
-}
-
-/**
- * Returns the leading area of the font described by the
- * receiver. A font's <em>leading area</em> is the space
- * above its ascent which may include accents or other marks.
- *
- * @return the leading space of the font
- */
-public int getLeading() {
- return leading;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode() {
- return ascent ^ descent ^ averageCharWidth ^ leading ^ height;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java
deleted file mode 100755
index 0d34639929..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java
+++ /dev/null
@@ -1,3918 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Class <code>GC</code> is where all of the drawing capabilities that are
- * supported by SWT are located. Instances are used to draw on either an
- * <code>Image</code>, a <code>Control</code>, or directly on a <code>Display</code>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * </dl>
- *
- * <p>
- * The SWT drawing coordinate system is the two-dimensional space with the origin
- * (0,0) at the top left corner of the drawing area and with (x,y) values increasing
- * to the right and downward respectively.
- * </p>
- *
- * <p>
- * The result of drawing on an image that was created with an indexed
- * palette using a color that is not in the palette is platform specific.
- * Some platforms will match to the nearest color while other will draw
- * the color itself. This happens because the allocated image might use
- * a direct palette on platforms that do not support indexed palette.
- * </p>
- *
- * <p>
- * Application code must explicitly invoke the <code>GC.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required. This is <em>particularly</em>
- * important on Windows95 and Windows98 where the operating system has a limited
- * number of device contexts available.
- * </p>
- *
- * <p>
- * Note: Only one of LEFT_TO_RIGHT and RIGHT_TO_LEFT may be specified.
- * </p>
- *
- * @see org.eclipse.swt.events.PaintEvent
- * @see <a href="http://www.eclipse.org/swt/snippets/#gc">GC snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class GC extends Resource {
- /**
- * the handle to the OS device context
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public NSGraphicsContext handle;
-
- Drawable drawable;
- GCData data;
-
- CGPathElement element;
- int count, typeCount;
- byte[] types;
- float /*double*/[] points;
- float /*double*/ [] point;
-
- static final int TAB_COUNT = 32;
-
- final static int FOREGROUND = 1 << 0;
- final static int BACKGROUND = 1 << 1;
- final static int FONT = 1 << 2;
- final static int LINE_STYLE = 1 << 3;
- final static int LINE_CAP = 1 << 4;
- final static int LINE_JOIN = 1 << 5;
- final static int LINE_WIDTH = 1 << 6;
- final static int LINE_MITERLIMIT = 1 << 7;
- final static int FOREGROUND_FILL = 1 << 8;
- final static int DRAW_OFFSET = 1 << 9;
- final static int CLIPPING = 1 << 10;
- final static int TRANSFORM = 1 << 11;
- final static int VISIBLE_REGION = 1 << 12;
- final static int DRAW = CLIPPING | TRANSFORM | FOREGROUND | LINE_WIDTH | LINE_STYLE | LINE_CAP | LINE_JOIN | LINE_MITERLIMIT | DRAW_OFFSET;
- final static int FILL = CLIPPING | TRANSFORM | BACKGROUND;
-
- static final float[] LINE_DOT = new float[]{1, 1};
- static final float[] LINE_DASH = new float[]{3, 1};
- static final float[] LINE_DASHDOT = new float[]{3, 1, 1, 1};
- static final float[] LINE_DASHDOTDOT = new float[]{3, 1, 1, 1, 1, 1};
- static final float[] LINE_DOT_ZERO = new float[]{3, 3};
- static final float[] LINE_DASH_ZERO = new float[]{18, 6};
- static final float[] LINE_DASHDOT_ZERO = new float[]{9, 6, 3, 6};
- static final float[] LINE_DASHDOTDOT_ZERO = new float[]{9, 3, 3, 3, 3, 3};
-
-GC() {
-}
-
-/**
- * Constructs a new instance of this class which has been
- * configured to draw on the specified drawable. Sets the
- * foreground color, background color and font in the GC
- * to match those in the drawable.
- * <p>
- * You must dispose the graphics context when it is no longer required.
- * </p>
- * @param drawable the drawable to draw on
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li>
- * <li>ERROR_NULL_ARGUMENT - if there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT
- * - if the drawable is an image that is not a bitmap or an icon
- * - if the drawable is an image or printer that is already selected
- * into another graphics context</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li>
- * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li>
- * </ul>
- */
-public GC(Drawable drawable) {
- this(drawable, 0);
-}
-
-/**
- * Constructs a new instance of this class which has been
- * configured to draw on the specified drawable. Sets the
- * foreground color, background color and font in the GC
- * to match those in the drawable.
- * <p>
- * You must dispose the graphics context when it is no longer required.
- * </p>
- *
- * @param drawable the drawable to draw on
- * @param style the style of GC to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li>
- * <li>ERROR_NULL_ARGUMENT - if there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT
- * - if the drawable is an image that is not a bitmap or an icon
- * - if the drawable is an image or printer that is already selected
- * into another graphics context</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li>
- * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public GC(Drawable drawable, int style) {
- if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- GCData data = new GCData();
- data.style = checkStyle(style);
- int /*long*/ contextId = drawable.internal_new_GC(data);
- Device device = data.device;
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = data.device = device;
- init(drawable, data, contextId);
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-static int checkStyle (int style) {
- if ((style & SWT.LEFT_TO_RIGHT) != 0) style &= ~SWT.RIGHT_TO_LEFT;
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new graphics context.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>GC</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param drawable the Drawable for the receiver.
- * @param data the data for the receiver.
- *
- * @return a new <code>GC</code>
- *
- * @private
- */
-public static GC cocoa_new(Drawable drawable, GCData data) {
- GC gc = new GC();
- int /*long*/ context = drawable.internal_new_GC(data);
- gc.device = data.device;
- gc.init(drawable, data, context);
- return gc;
-}
-
-int /*long*/ applierFunc(int /*long*/ info, int /*long*/ elementPtr) {
- OS.memmove(element, elementPtr, CGPathElement.sizeof);
- int type = 0, length = 1;
- switch (element.type) {
- case OS.kCGPathElementMoveToPoint: type = SWT.PATH_MOVE_TO; break;
- case OS.kCGPathElementAddLineToPoint: type = SWT.PATH_LINE_TO; break;
- case OS.kCGPathElementAddQuadCurveToPoint: type = SWT.PATH_QUAD_TO; length = 2; break;
- case OS.kCGPathElementAddCurveToPoint: type = SWT.PATH_CUBIC_TO; length = 3; break;
- case OS.kCGPathElementCloseSubpath: type = SWT.PATH_CLOSE; length = 0; break;
- }
- if (types != null) {
- types[typeCount] = (byte)type;
- if (length > 0) {
- OS.memmove(point, element.points, length * CGPoint.sizeof);
- System.arraycopy(point, 0, points, count, length * 2);
- }
- }
- typeCount++;
- count += length * 2;
- return 0;
-}
-
-NSAutoreleasePool checkGC (int mask) {
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- if (data.flippedContext != null && !handle.isEqual(NSGraphicsContext.currentContext())) {
- data.restoreContext = true;
- NSGraphicsContext.static_saveGraphicsState();
- NSGraphicsContext.setCurrentContext(handle);
- }
- if ((mask & (CLIPPING | TRANSFORM)) != 0) {
- NSView view = data.view;
- if ((data.state & CLIPPING) == 0 || (data.state & TRANSFORM) == 0 || (data.state & VISIBLE_REGION) == 0) {
- boolean antialias = handle.shouldAntialias();
- handle.restoreGraphicsState();
- handle.saveGraphicsState();
- handle.setShouldAntialias(antialias);
- if (view != null && (data.paintRect == null || !view.isFlipped())) {
- NSAffineTransform transform = NSAffineTransform.transform();
- NSRect rect = view.convertRect_toView_(view.bounds(), null);
- if (data.paintRect == null) {
- transform.translateXBy(rect.x, rect.y + rect.height);
- } else {
- transform.translateXBy(0, rect.height);
- }
- transform.scaleXBy(1, -1);
- transform.concat();
- if (data.visibleRgn != 0) {
- if (data.visiblePath == null || (data.state & VISIBLE_REGION) == 0) {
- if (data.visiblePath != null) data.visiblePath.release();
- data.visiblePath = Region.cocoa_new(device, data.visibleRgn).getPath();
- }
- data.visiblePath.addClip();
- data.state |= VISIBLE_REGION;
- }
- }
- if (data.clipPath != null) data.clipPath.addClip();
- if (data.transform != null) data.transform.concat();
- mask &= ~(TRANSFORM | CLIPPING);
- data.state |= TRANSFORM | CLIPPING;
- data.state &= ~(BACKGROUND | FOREGROUND);
- }
- }
-
- int state = data.state;
- if ((state & mask) == mask) return pool;
- state = (state ^ mask) & mask;
- data.state |= mask;
-
- if ((state & FOREGROUND) != 0) {
- Pattern pattern = data.foregroundPattern;
- if (pattern != null) {
- if (pattern.color != null) pattern.color.setStroke();
- } else {
- float /*double*/ [] color = data.foreground;
- if (data.fg != null) data.fg.release();
- NSColor fg = data.fg = NSColor.colorWithDeviceRed(color[0], color[1], color[2], data.alpha / 255f);
- fg.retain();
- fg.setStroke();
- }
- }
- if ((state & FOREGROUND_FILL) != 0) {
- Pattern pattern = data.foregroundPattern;
- if (pattern != null) {
- if (pattern.color != null) pattern.color.setFill();
- } else {
- float /*double*/ [] color = data.foreground;
- if (data.fg != null) data.fg.release();
- NSColor fg = data.fg = NSColor.colorWithDeviceRed(color[0], color[1], color[2], data.alpha / 255f);
- fg.retain();
- fg.setFill();
- }
- data.state &= ~BACKGROUND;
- }
- if ((state & BACKGROUND) != 0) {
- Pattern pattern = data.backgroundPattern;
- if (pattern != null) {
- if (pattern.color != null) pattern.color.setFill();
- } else {
- float /*double*/ [] color = data.background;
- if (data.bg != null) data.bg.release();
- NSColor bg = data.bg = NSColor.colorWithDeviceRed(color[0], color[1], color[2], data.alpha / 255f);
- bg.retain();
- bg.setFill();
- }
- data.state &= ~FOREGROUND_FILL;
- }
- NSBezierPath path = data.path;
- if ((state & LINE_WIDTH) != 0) {
- path.setLineWidth(data.lineWidth == 0 ? 1 : data.lineWidth);
- switch (data.lineStyle) {
- case SWT.LINE_DOT:
- case SWT.LINE_DASH:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- state |= LINE_STYLE;
- }
- }
- if ((state & LINE_STYLE) != 0) {
- float[] dashes = null;
- float width = data.lineWidth;
- switch (data.lineStyle) {
- case SWT.LINE_SOLID: break;
- case SWT.LINE_DASH: dashes = width != 0 ? LINE_DASH : LINE_DASH_ZERO; break;
- case SWT.LINE_DOT: dashes = width != 0 ? LINE_DOT : LINE_DOT_ZERO; break;
- case SWT.LINE_DASHDOT: dashes = width != 0 ? LINE_DASHDOT : LINE_DASHDOT_ZERO; break;
- case SWT.LINE_DASHDOTDOT: dashes = width != 0 ? LINE_DASHDOTDOT : LINE_DASHDOTDOT_ZERO; break;
- case SWT.LINE_CUSTOM: dashes = data.lineDashes; break;
- }
- if (dashes != null) {
- float /*double*/[] lengths = new float /*double*/[dashes.length];
- for (int i = 0; i < lengths.length; i++) {
- lengths[i] = width == 0 || data.lineStyle == SWT.LINE_CUSTOM ? dashes[i] : dashes[i] * width;
- }
- path.setLineDash(lengths, lengths.length, data.lineDashesOffset);
- } else {
- path.setLineDash(null, 0, 0);
- }
- }
- if ((state & LINE_MITERLIMIT) != 0) {
- path.setMiterLimit(data.lineMiterLimit);
- }
- if ((state & LINE_JOIN) != 0) {
- int joinStyle = 0;
- switch (data.lineJoin) {
- case SWT.JOIN_MITER: joinStyle = OS.NSMiterLineJoinStyle; break;
- case SWT.JOIN_ROUND: joinStyle = OS.NSRoundLineJoinStyle; break;
- case SWT.JOIN_BEVEL: joinStyle = OS.NSBevelLineJoinStyle; break;
- }
- path.setLineJoinStyle(joinStyle);
- }
- if ((state & LINE_CAP) != 0) {
- int capStyle = 0;
- switch (data.lineCap) {
- case SWT.CAP_ROUND: capStyle = OS.NSRoundLineCapStyle; break;
- case SWT.CAP_FLAT: capStyle = OS.NSButtLineCapStyle; break;
- case SWT.CAP_SQUARE: capStyle = OS.NSSquareLineCapStyle; break;
- }
- path.setLineCapStyle(capStyle);
- }
- if ((state & DRAW_OFFSET) != 0) {
- data.drawXOffset = data.drawYOffset = 0;
- NSSize size = new NSSize();
- size.width = size.height = 1;
- if (data.transform != null) {
- size = data.transform.transformSize(size);
- }
- float /*double*/ scaling = size.width;
- if (scaling < 0) scaling = -scaling;
- float /*double*/ strokeWidth = data.lineWidth * scaling;
- if (strokeWidth == 0 || ((int)strokeWidth % 2) == 1) {
- data.drawXOffset = 0.5f / scaling;
- }
- scaling = size.height;
- if (scaling < 0) scaling = -scaling;
- strokeWidth = data.lineWidth * scaling;
- if (strokeWidth == 0 || ((int)strokeWidth % 2) == 1) {
- data.drawYOffset = 0.5f / scaling;
- }
- }
- return pool;
-}
-
-/**
- * Copies a rectangular area of the receiver at the specified
- * position into the image, which must be of type <code>SWT.BITMAP</code>.
- *
- * @param image the image to copy into
- * @param x the x coordinate in the receiver of the area to be copied
- * @param y the y coordinate in the receiver of the area to be copied
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image is not a bitmap or has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void copyArea(Image image, int x, int y) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = checkGC(TRANSFORM | CLIPPING);
- try {
- if (data.image != null) {
- int srcX = x, srcY = y, destX = 0, destY = 0;
- NSSize srcSize = data.image.handle.size();
- int imgHeight = (int)srcSize.height;
- int destWidth = (int)srcSize.width - x, destHeight = (int)srcSize.height - y;
- int srcWidth = destWidth, srcHeight = destHeight;
- NSGraphicsContext context = NSGraphicsContext.graphicsContextWithBitmapImageRep(image.getRepresentation());
- NSGraphicsContext.static_saveGraphicsState();
- NSGraphicsContext.setCurrentContext(context);
- NSAffineTransform transform = NSAffineTransform.transform();
- NSSize size = image.handle.size();
- transform.translateXBy(0, size.height-(destHeight + 2 * destY));
- transform.concat();
- NSRect srcRect = new NSRect();
- srcRect.x = srcX;
- srcRect.y = imgHeight - (srcY + srcHeight);
- srcRect.width = srcWidth;
- srcRect.height = srcHeight;
- NSRect destRect = new NSRect();
- destRect.x = destX;
- destRect.y = destY;
- destRect.width = destWidth;
- destRect.height = destHeight;
- data.image.handle.drawInRect(destRect, srcRect, OS.NSCompositeCopy, 1);
- NSGraphicsContext.static_restoreGraphicsState();
- return;
- }
- if (data.view != null) {
- NSPoint pt = new NSPoint();
- pt.x = x;
- pt.y = y;
- NSWindow window = data.view.window();
- pt = data.view.convertPoint_toView_(pt, window.contentView().superview());
- NSRect frame = window.frame();
- pt.y = frame.height - pt.y;
- NSSize size = image.handle.size();
- CGRect destRect = new CGRect();
- destRect.size.width = size.width;
- destRect.size.height = size.height;
- CGRect srcRect = new CGRect();
- srcRect.origin.x = pt.x;
- srcRect.origin.y = pt.y;
- srcRect.size.width = size.width;
- srcRect.size.height = size.height;
- NSBitmapImageRep imageRep = image.getRepresentation();
- NSGraphicsContext context = NSGraphicsContext.graphicsContextWithBitmapImageRep(imageRep);
- NSGraphicsContext.static_saveGraphicsState();
- NSGraphicsContext.setCurrentContext(context);
- int /*long*/ contextID = OS.objc_msgSend(NSApplication.sharedApplication().id, OS.sel_contextID);
- OS.CGContextCopyWindowContentsToRect(context.graphicsPort(), destRect, contextID, window.windowNumber(), srcRect);
- NSGraphicsContext.static_restoreGraphicsState();
- return;
- }
- if (handle.isDrawingToScreen()) {
- NSImage imageHandle = image.handle;
- NSSize size = imageHandle.size();
- CGRect rect = new CGRect();
- rect.origin.x = x;
- rect.origin.y = y;
- rect.size.width = size.width;
- rect.size.height = size.height;
- int displayCount = 16;
- int /*long*/ displays = OS.malloc(4 * displayCount), countPtr = OS.malloc(4);
- if (OS.CGGetDisplaysWithRect(rect, displayCount, displays, countPtr) != 0) return;
- int[] count = new int[1], display = new int[1];
- OS.memmove(count, countPtr, OS.PTR_SIZEOF);
- for (int i = 0; i < count[0]; i++) {
- OS.memmove(display, displays + (i * 4), 4);
- OS.CGDisplayBounds(display[0], rect);
- int /*long*/ address = OS.CGDisplayBaseAddress(display[0]);
- if (address != 0) {
- int /*long*/ width = OS.CGDisplayPixelsWide(display[0]);
- int /*long*/ height = OS.CGDisplayPixelsHigh(display[0]);
- int /*long*/ bpr = OS.CGDisplayBytesPerRow(display[0]);
- int /*long*/ bpp = OS.CGDisplayBitsPerPixel(display[0]);
- int /*long*/ bps = OS.CGDisplayBitsPerSample(display[0]);
- int bitmapInfo = OS.kCGImageAlphaNoneSkipFirst;
- switch ((int)/*63*/bpp) {
- case 16: bitmapInfo |= OS.kCGBitmapByteOrder16Host; break;
- case 32: bitmapInfo |= OS.kCGBitmapByteOrder32Host; break;
- }
- int /*long*/ srcImage = 0;
- if (OS.__BIG_ENDIAN__() && OS.VERSION >= 0x1040) {
- int /*long*/ colorspace = OS.CGColorSpaceCreateDeviceRGB();
- int /*long*/ context = OS.CGBitmapContextCreate(address, width, height, bps, bpr, colorspace, bitmapInfo);
- OS.CGColorSpaceRelease(colorspace);
- srcImage = OS.CGBitmapContextCreateImage(context);
- OS.CGContextRelease(context);
- } else {
- int /*long*/ provider = OS.CGDataProviderCreateWithData(0, address, bpr * height, 0);
- int /*long*/ colorspace = OS.CGColorSpaceCreateDeviceRGB();
- srcImage = OS.CGImageCreate(width, height, bps, bpp, bpr, colorspace, bitmapInfo, provider, 0, true, 0);
- OS.CGColorSpaceRelease(colorspace);
- OS.CGDataProviderRelease(provider);
- }
- copyArea(image, x - (int)rect.origin.x, y - (int)rect.origin.y, srcImage);
- if (srcImage != 0) OS.CGImageRelease(srcImage);
- }
- }
- OS.free(displays);
- OS.free(countPtr);
- }
- } finally {
- uncheckGC(pool);
- }
-}
-
-void copyArea (Image image, int x, int y, int /*long*/ srcImage) {
- if (srcImage == 0) return;
- NSBitmapImageRep rep = image.getRepresentation();
- int /*long*/ bpc = rep.bitsPerSample();
- int /*long*/ width = rep.pixelsWide();
- int /*long*/ height = rep.pixelsHigh();
- int /*long*/ bpr = rep.bytesPerRow();
- int alphaInfo = rep.hasAlpha() ? OS.kCGImageAlphaFirst : OS.kCGImageAlphaNoneSkipFirst;
- int /*long*/ colorspace = OS.CGColorSpaceCreateDeviceRGB();
- int /*long*/ context = OS.CGBitmapContextCreate(rep.bitmapData(), width, height, bpc, bpr, colorspace, alphaInfo);
- OS.CGColorSpaceRelease(colorspace);
- if (context != 0) {
- CGRect rect = new CGRect();
- rect.origin.x = -x;
- rect.origin.y = y;
- rect.size.width = OS.CGImageGetWidth(srcImage);
- rect.size.height = OS.CGImageGetHeight(srcImage);
- OS.CGContextTranslateCTM(context, 0, -(rect.size.height - height));
- OS.CGContextDrawImage(context, rect, srcImage);
- OS.CGContextRelease(context);
- }
-}
-
-/**
- * Copies a rectangular area of the receiver at the source
- * position onto the receiver at the destination position.
- *
- * @param srcX the x coordinate in the receiver of the area to be copied
- * @param srcY the y coordinate in the receiver of the area to be copied
- * @param width the width of the area to copy
- * @param height the height of the area to copy
- * @param destX the x coordinate in the receiver of the area to copy to
- * @param destY the y coordinate in the receiver of the area to copy to
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY) {
- copyArea(srcX, srcY, width, height, destX, destY, true);
-}
-/**
- * Copies a rectangular area of the receiver at the source
- * position onto the receiver at the destination position.
- *
- * @param srcX the x coordinate in the receiver of the area to be copied
- * @param srcY the y coordinate in the receiver of the area to be copied
- * @param width the width of the area to copy
- * @param height the height of the area to copy
- * @param destX the x coordinate in the receiver of the area to copy to
- * @param destY the y coordinate in the receiver of the area to copy to
- * @param paint if <code>true</code> paint events will be generated for old and obscured areas
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width <= 0 || height <= 0) return;
- int deltaX = destX - srcX, deltaY = destY - srcY;
- if (deltaX == 0 && deltaY == 0) return;
- NSAutoreleasePool pool = checkGC(TRANSFORM | CLIPPING);
- try {
- Image image = data.image;
- if (image != null) {
- NSImage imageHandle = image.handle;
- NSSize size = imageHandle.size();
- int imgHeight = (int)size.height;
- handle.saveGraphicsState();
- NSAffineTransform transform = NSAffineTransform.transform();
- transform.scaleXBy(1, -1);
- transform.translateXBy(0, -(height + 2 * destY));
- transform.concat();
- NSRect srcRect = new NSRect();
- srcRect.x = srcX;
- srcRect.y = imgHeight - (srcY + height);
- srcRect.width = width;
- srcRect.height = height;
- NSRect destRect = new NSRect();
- destRect.x = destX;
- destRect.y = destY;
- destRect.width = width;
- destRect.height = height;
- imageHandle.drawInRect(destRect, srcRect, OS.NSCompositeCopy, 1);
- handle.restoreGraphicsState();
- return;
- }
- if (data.view != null) {
- NSView view = data.view;
- NSRect visibleRect = view.visibleRect();
- if (visibleRect.width <= 0 || visibleRect.height <= 0) return;
- NSRect damage = new NSRect();
- damage.x = srcX;
- damage.y = srcY;
- damage.width = width;
- damage.height = height;
- NSPoint dest = new NSPoint();
- dest.x = destX;
- dest.y = destY;
-
- view.lockFocus();
- OS.NSCopyBits(0, damage , dest);
- view.unlockFocus();
-
- if (paint) {
- boolean disjoint = (destX + width < srcX) || (srcX + width < destX) || (destY + height < srcY) || (srcY + height < destY);
- if (disjoint) {
- view.setNeedsDisplayInRect(damage);
- } else {
- if (deltaX != 0) {
- int newX = destX - deltaX;
- if (deltaX < 0) newX = destX + width;
- damage.x = newX;
- damage.width = Math.abs(deltaX);
- view.setNeedsDisplayInRect(damage);
- }
- if (deltaY != 0) {
- int newY = destY - deltaY;
- if (deltaY < 0) newY = destY + height;
- damage.x = srcX;
- damage.y = newY;
- damage.width = width;
- damage.height = Math.abs (deltaY);
- view.setNeedsDisplayInRect(damage);
- }
- }
-
- NSRect srcRect = new NSRect();
- srcRect.x = srcX;
- srcRect.y = srcY;
- srcRect.width = width;
- srcRect.height = height;
- OS.NSIntersectionRect(visibleRect, visibleRect, srcRect);
-
- if (!OS.NSEqualRects(visibleRect, srcRect)) {
- if (srcRect.x != visibleRect.x) {
- damage.x = srcRect.x + deltaX;
- damage.y = srcRect.y + deltaY;
- damage.width = visibleRect.x - srcRect.x;
- damage.height = srcRect.height;
- view.setNeedsDisplayInRect(damage);
- }
- if (visibleRect.x + visibleRect.width != srcRect.x + srcRect.width) {
- damage.x = srcRect.x + visibleRect.width + deltaX;
- damage.y = srcRect.y + deltaY;
- damage.width = srcRect.width - visibleRect.width;
- damage.height = srcRect.height;
- view.setNeedsDisplayInRect(damage);
- }
- if (visibleRect.y != srcRect.y) {
- damage.x = visibleRect.x + deltaX;
- damage.y = srcRect.y + deltaY;
- damage.width = visibleRect.width;
- damage.height = visibleRect.y - srcRect.y;
- view.setNeedsDisplayInRect(damage);
- }
- if (visibleRect.y + visibleRect.height != srcRect.y + srcRect.height) {
- damage.x = visibleRect.x + deltaX;
- damage.y = visibleRect.y + visibleRect.height + deltaY;
- damage.width = visibleRect.width;
- damage.height = srcRect.y + srcRect.height - (visibleRect.y + visibleRect.height);
- view.setNeedsDisplayInRect(damage);
- }
- }
- }
- return;
- }
- } finally {
- uncheckGC(pool);
- }
-}
-
-static int /*long*/ createCGPathRef(NSBezierPath nsPath) {
- int /*long*/ count = nsPath.elementCount();
- if (count > 0) {
- int /*long*/ cgPath = OS.CGPathCreateMutable();
- if (cgPath == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ points = OS.malloc(NSPoint.sizeof * 3);
- if (points == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- float /*double*/ [] pt = new float /*double*/ [6];
- for (int i = 0; i < count; i++) {
- int element = (int)/*64*/nsPath.elementAtIndex(i, points);
- switch (element) {
- case OS.NSMoveToBezierPathElement:
- OS.memmove(pt, points, NSPoint.sizeof);
- OS.CGPathMoveToPoint(cgPath, 0, pt[0], pt[1]);
- break;
- case OS.NSLineToBezierPathElement:
- OS.memmove(pt, points, NSPoint.sizeof);
- OS.CGPathAddLineToPoint(cgPath, 0, pt[0], pt[1]);
- break;
- case OS.NSCurveToBezierPathElement:
- OS.memmove(pt, points, NSPoint.sizeof * 3);
- OS.CGPathAddCurveToPoint(cgPath, 0, pt[0], pt[1], pt[2], pt[3], pt[4], pt[5]);
- break;
- case OS.NSClosePathBezierPathElement:
- OS.CGPathCloseSubpath(cgPath);
- break;
- }
- }
- OS.free(points);
- return cgPath;
- }
- return 0;
-}
-
-
-
-NSBezierPath createNSBezierPath (int /*long*/ cgPath) {
- Callback callback = new Callback(this, "applierFunc", 2);
- int /*long*/ proc = callback.getAddress();
- if (proc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- count = typeCount = 0;
- element = new CGPathElement();
- OS.CGPathApply(cgPath, 0, proc);
- types = new byte[typeCount];
- points = new float /*double*/ [count];
- point = new float /*double*/ [6];
- count = typeCount = 0;
- OS.CGPathApply(cgPath, 0, proc);
- callback.dispose();
-
- NSBezierPath bezierPath = NSBezierPath.bezierPath();
- NSPoint nsPoint = new NSPoint(), nsPoint2 = new NSPoint(), nsPoint3 = new NSPoint();
- for (int i = 0, j = 0; i < types.length; i++) {
- switch (types[i]) {
- case SWT.PATH_MOVE_TO:
- nsPoint.x = points[j++];
- nsPoint.y = points[j++];
- bezierPath.moveToPoint(nsPoint);
- break;
- case SWT.PATH_LINE_TO:
- nsPoint.x = points[j++];
- nsPoint.y = points[j++];
- bezierPath.lineToPoint(nsPoint);
- break;
- case SWT.PATH_CUBIC_TO:
- nsPoint2.x = points[j++];
- nsPoint2.y = points[j++];
- nsPoint3.x = points[j++];
- nsPoint3.y = points[j++];
- nsPoint.x = points[j++];
- nsPoint.y = points[j++];
- bezierPath.curveToPoint(nsPoint, nsPoint2, nsPoint3);
- break;
- case SWT.PATH_QUAD_TO:
- float /*double*/ currentX = nsPoint.x;
- float /*double*/ currentY = nsPoint.y;
- nsPoint2.x = points[j++];
- nsPoint2.y = points[j++];
- nsPoint.x = points[j++];
- nsPoint.y = points[j++];
- float /*double*/ x0 = currentX;
- float /*double*/ y0 = currentY;
- float /*double*/ cx1 = x0 + 2 * (nsPoint2.x - x0) / 3;
- float /*double*/ cy1 = y0 + 2 * (nsPoint2.y - y0) / 3;
- float /*double*/ cx2 = cx1 + (nsPoint.x - x0) / 3;
- float /*double*/ cy2 = cy1 + (nsPoint.y - y0) / 3;
- nsPoint2.x = cx1;
- nsPoint2.y = cy1;
- nsPoint3.x = cx2;
- nsPoint3.y = cy2;
- bezierPath.curveToPoint(nsPoint, nsPoint2, nsPoint3);
- break;
- case SWT.PATH_CLOSE:
- bezierPath.closePath();
- break;
- default:
- dispose();
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- element = null;
- types = null;
- points = null;
- nsPoint = null;
- return bezierPath;
-}
-
-NSAttributedString createString(String string, int flags, boolean draw) {
- NSMutableDictionary dict = ((NSMutableDictionary)new NSMutableDictionary().alloc()).initWithCapacity(5);
- Font font = data.font;
- dict.setObject(font.handle, OS.NSFontAttributeName);
- font.addTraits(dict);
- if (draw) {
- Pattern pattern = data.foregroundPattern;
- if (pattern != null) {
- if (pattern.color != null) dict.setObject(pattern.color, OS.NSForegroundColorAttributeName);
- } else {
- NSColor fg = data.fg;
- if (fg == null) {
- float /*double*/ [] color = data.foreground;
- fg = data.fg = NSColor.colorWithDeviceRed(color[0], color[1], color[2], data.alpha / 255f);
- fg.retain();
- }
- dict.setObject(fg, OS.NSForegroundColorAttributeName);
- }
- }
- if ((flags & SWT.DRAW_TAB) == 0) {
- dict.setObject(device.paragraphStyle, OS.NSParagraphStyleAttributeName);
- }
- int length = string.length();
- char[] chars = new char[length];
- string.getChars(0, length, chars, 0);
- int breakCount = 0;
- int[] breaks = null;
- if ((flags & SWT.DRAW_MNEMONIC) !=0 || (flags & SWT.DRAW_DELIMITER) == 0) {
- int i=0, j=0;
- while (i < chars.length) {
- char c = chars [j++] = chars [i++];
- switch (c) {
- case '&': {
- if ((flags & SWT.DRAW_MNEMONIC) != 0) {
- if (i == chars.length) {continue;}
- if (chars [i] == '&') {i++; continue;}
- j--;
- }
- break;
- }
- case '\r':
- case '\n': {
- if ((flags & SWT.DRAW_DELIMITER) == 0) {
- if (c == '\r' && i != chars.length && chars[i] == '\n') i++;
- j--;
- if (breaks == null) {
- breaks = new int[4];
- } else if (breakCount == breaks.length) {
- int[] newBreaks = new int[breaks.length + 4];
- System.arraycopy(breaks, 0, newBreaks, 0, breaks.length);
- breaks = newBreaks;
- }
- breaks[breakCount++] = j;
- }
- break;
- }
- }
- }
- length = j;
- }
- NSString str = ((NSString)new NSString().alloc()).initWithCharacters(chars, length);
- NSAttributedString attribStr = ((NSAttributedString)new NSAttributedString().alloc()).initWithString(str, dict);
- dict.release();
- str.release();
- return attribStr;
-}
-
-void destroy() {
- /* Free resources */
- Image image = data.image;
- if (image != null) {
- image.memGC = null;
- image.createAlpha();
- }
- if (data.fg != null) data.fg.release();
- if (data.bg != null) data.bg.release();
- if (data.path != null) data.path.release();
- if (data.clipPath != null) data.clipPath.release();
- if (data.visiblePath != null) data.visiblePath.release();
- if (data.transform != null) data.transform.release();
- if (data.inverseTransform != null) data.inverseTransform.release();
- data.path = data.clipPath = data.visiblePath = null;
- data.transform = data.inverseTransform = null;
- data.fg = data.bg = null;
-
- /* Dispose the GC */
- if (drawable != null) drawable.internal_dispose_GC(handle.id, data);
- handle.restoreGraphicsState();
- handle.release();
-
- drawable = null;
- data.image = null;
- data = null;
- handle = null;
-}
-
-/**
- * Draws the outline of a circular or elliptical arc
- * within the specified rectangular area.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees, using the current color.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc to be drawn
- * @param y the y coordinate of the upper-left corner of the arc to be drawn
- * @param width the width of the arc to be drawn
- * @param height the height of the arc to be drawn
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- NSAutoreleasePool pool = checkGC(DRAW);
- try {
- handle.saveGraphicsState();
- NSAffineTransform transform = NSAffineTransform.transform();
- float /*double*/ xOffset = data.drawXOffset, yOffset = data.drawYOffset;
- transform.translateXBy(x + xOffset + width / 2f, y + yOffset + height / 2f);
- transform.scaleXBy(width / 2f, height / 2f);
- NSBezierPath path = data.path;
- NSPoint center = new NSPoint();
- float sAngle = -startAngle;
- float eAngle = -(startAngle + arcAngle);
- path.appendBezierPathWithArcWithCenter(center, 1, sAngle, eAngle, arcAngle>0);
- path.transformUsingAffineTransform(transform);
- Pattern pattern = data.foregroundPattern;
- if (pattern != null && pattern.gradient != null) {
- strokePattern(path, pattern);
- } else {
- path.stroke();
- }
- path.removeAllPoints();
- handle.restoreGraphicsState();
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Draws a rectangle, based on the specified arguments, which has
- * the appearance of the platform's <em>focus rectangle</em> if the
- * platform supports such a notion, and otherwise draws a simple
- * rectangle in the receiver's foreground color.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width of the rectangle
- * @param height the height of the rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void drawFocus(int x, int y, int width, int height) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = checkGC(CLIPPING | TRANSFORM);
- try {
- int[] metric = new int[1];
- OS.GetThemeMetric(OS.kThemeMetricFocusRectOutset, metric);
- CGRect rect = new CGRect();
- rect.origin.x = x + metric[0];
- rect.origin.y = y + metric[0];
- rect.size.width = width - metric[0] * 2;
- rect.size.height = height - metric[0] * 2;
- OS.HIThemeDrawFocusRect(rect, true, handle.graphicsPort(), OS.kHIThemeOrientationNormal);
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Draws the given image in the receiver at the specified
- * coordinates.
- *
- * @param image the image to draw
- * @param x the x coordinate of where to draw
- * @param y the y coordinate of where to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if the given coordinates are outside the bounds of the image</li>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- */
-public void drawImage(Image image, int x, int y) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- drawImage(image, 0, 0, -1, -1, x, y, -1, -1, true);
-}
-
-/**
- * Copies a rectangular area from the source image into a (potentially
- * different sized) rectangular area in the receiver. If the source
- * and destination areas are of differing sizes, then the source
- * area will be stretched or shrunk to fit the destination area
- * as it is copied. The copy fails if any part of the source rectangle
- * lies outside the bounds of the source image, or if any of the width
- * or height arguments are negative.
- *
- * @param image the source image
- * @param srcX the x coordinate in the source image to copy from
- * @param srcY the y coordinate in the source image to copy from
- * @param srcWidth the width in pixels to copy from the source
- * @param srcHeight the height in pixels to copy from the source
- * @param destX the x coordinate in the destination to copy to
- * @param destY the y coordinate in the destination to copy to
- * @param destWidth the width in pixels of the destination rectangle
- * @param destHeight the height in pixels of the destination rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if any of the width or height arguments are negative.
- * <li>ERROR_INVALID_ARGUMENT - if the source rectangle is not contained within the bounds of the source image</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- */
-public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (srcWidth == 0 || srcHeight == 0 || destWidth == 0 || destHeight == 0) return;
- if (srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 || destWidth < 0 || destHeight < 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- drawImage(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false);
-}
-
-void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
- NSImage imageHandle = srcImage.handle;
- NSSize size = imageHandle.size();
- int imgWidth = (int)size.width;
- int imgHeight = (int)size.height;
- if (simple) {
- srcWidth = destWidth = imgWidth;
- srcHeight = destHeight = imgHeight;
- } else {
- simple = srcX == 0 && srcY == 0 &&
- srcWidth == destWidth && destWidth == imgWidth &&
- srcHeight == destHeight && destHeight == imgHeight;
- if (srcX + srcWidth > imgWidth || srcY + srcHeight > imgHeight) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- NSAutoreleasePool pool = checkGC(CLIPPING | TRANSFORM);
- try {
- if (srcImage.memGC != null) {
- srcImage.createAlpha();
- }
- handle.saveGraphicsState();
- NSAffineTransform transform = NSAffineTransform.transform();
- transform.scaleXBy(1, -1);
- transform.translateXBy(0, -(destHeight + 2 * destY));
- transform.concat();
- NSRect srcRect = new NSRect();
- srcRect.x = srcX;
- srcRect.y = imgHeight - (srcY + srcHeight);
- srcRect.width = srcWidth;
- srcRect.height = srcHeight;
- NSRect destRect = new NSRect();
- destRect.x = destX;
- destRect.y = destY;
- destRect.width = destWidth;
- destRect.height = destHeight;
- imageHandle.drawInRect(destRect, srcRect, OS.NSCompositeSourceOver, 1);
- handle.restoreGraphicsState();
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Draws a line, using the foreground color, between the points
- * (<code>x1</code>, <code>y1</code>) and (<code>x2</code>, <code>y2</code>).
- *
- * @param x1 the first point's x coordinate
- * @param y1 the first point's y coordinate
- * @param x2 the second point's x coordinate
- * @param y2 the second point's y coordinate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawLine(int x1, int y1, int x2, int y2) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = checkGC(DRAW);
- try {
- NSBezierPath path = data.path;
- NSPoint pt = new NSPoint();
- pt.x = x1 + data.drawXOffset;
- pt.y = y1 + data.drawYOffset;
- path.moveToPoint(pt);
- pt.x = x2 + data.drawXOffset;
- pt.y = y2 + data.drawYOffset;
- path.lineToPoint(pt);
- Pattern pattern = data.foregroundPattern;
- if (pattern != null && pattern.gradient != null) {
- strokePattern(path, pattern);
- } else {
- path.stroke();
- }
- path.removeAllPoints();
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Draws the outline of an oval, using the foreground color,
- * within the specified rectangular area.
- * <p>
- * The result is a circle or ellipse that fits within the
- * rectangle specified by the <code>x</code>, <code>y</code>,
- * <code>width</code>, and <code>height</code> arguments.
- * </p><p>
- * The oval covers an area that is <code>width + 1</code>
- * pixels wide and <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper left corner of the oval to be drawn
- * @param y the y coordinate of the upper left corner of the oval to be drawn
- * @param width the width of the oval to be drawn
- * @param height the height of the oval to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawOval(int x, int y, int width, int height) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = checkGC(DRAW);
- try {
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- NSBezierPath path = data.path;
- NSRect rect = new NSRect();
- rect.x = x + data.drawXOffset;
- rect.y = y + data.drawXOffset;
- rect.width = width;
- rect.height = height;
- path.appendBezierPathWithOvalInRect(rect);
- Pattern pattern = data.foregroundPattern;
- if (pattern != null && pattern.gradient != null) {
- strokePattern(path, pattern);
- } else {
- path.stroke();
- }
- path.removeAllPoints();
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Draws the path described by the parameter.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the path to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- *
- * @since 3.1
- */
-public void drawPath(Path path) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.handle == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = checkGC(DRAW);
- try {
- handle.saveGraphicsState();
- NSAffineTransform transform = NSAffineTransform.transform();
- transform.translateXBy(data.drawXOffset, data.drawYOffset);
- transform.concat();
- NSBezierPath drawPath = data.path;
- drawPath.appendBezierPath(path.handle);
- Pattern pattern = data.foregroundPattern;
- if (pattern != null && pattern.gradient != null) {
- strokePattern(drawPath, pattern);
- } else {
- drawPath.stroke();
- }
- drawPath.removeAllPoints();
- handle.restoreGraphicsState();
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Draws a pixel, using the foreground color, at the specified
- * point (<code>x</code>, <code>y</code>).
- * <p>
- * Note that the receiver's line attributes do not affect this
- * operation.
- * </p>
- *
- * @param x the point's x coordinate
- * @param y the point's y coordinate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void drawPoint(int x, int y) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = checkGC(FOREGROUND_FILL | CLIPPING | TRANSFORM);
- try {
- NSRect rect = new NSRect();
- rect.x = x;
- rect.y = y;
- rect.width = 1;
- rect.height = 1;
- NSBezierPath path = data.path;
- path.appendBezierPathWithRect(rect);
- path.fill();
- path.removeAllPoints();
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Draws the closed polygon which is defined by the specified array
- * of integer coordinates, using the receiver's foreground color. The array
- * contains alternating x and y values which are considered to represent
- * points which are the vertices of the polygon. Lines are drawn between
- * each consecutive pair, and between the first pair and last pair in the
- * array.
- *
- * @param pointArray an array of alternating x and y values which are the vertices of the polygon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT if pointArray is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawPolygon(int[] pointArray) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (pointArray.length < 4) return;
- NSAutoreleasePool pool = checkGC(DRAW);
- try {
- float /*double*/ xOffset = data.drawXOffset, yOffset = data.drawYOffset;
- NSBezierPath path = data.path;
- NSPoint pt = new NSPoint();
- pt.x = pointArray[0] + xOffset;
- pt.y = pointArray[1] + yOffset;
- path.moveToPoint(pt);
- int end = pointArray.length / 2 * 2;
- for (int i = 2; i < end; i+=2) {
- pt.x = pointArray[i] + xOffset;
- pt.y = pointArray[i+1] + yOffset;
- path.lineToPoint(pt);
- }
- path.closePath();
- Pattern pattern = data.foregroundPattern;
- if (pattern != null && pattern.gradient != null) {
- strokePattern(path, pattern);
- } else {
- path.stroke();
- }
- path.removeAllPoints();
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Draws the polyline which is defined by the specified array
- * of integer coordinates, using the receiver's foreground color. The array
- * contains alternating x and y values which are considered to represent
- * points which are the corners of the polyline. Lines are drawn between
- * each consecutive pair, but not between the first pair and last pair in
- * the array.
- *
- * @param pointArray an array of alternating x and y values which are the corners of the polyline
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawPolyline(int[] pointArray) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (pointArray.length < 4) return;
- NSAutoreleasePool pool = checkGC(DRAW);
- try {
- float /*double*/ xOffset = data.drawXOffset, yOffset = data.drawYOffset;
- NSBezierPath path = data.path;
- NSPoint pt = new NSPoint();
- pt.x = pointArray[0] + xOffset;
- pt.y = pointArray[1] + yOffset;
- path.moveToPoint(pt);
- int end = pointArray.length / 2 * 2;
- for (int i = 2; i < end; i+=2) {
- pt.x = pointArray[i] + xOffset;
- pt.y = pointArray[i+1] + yOffset;
- path.lineToPoint(pt);
- }
- Pattern pattern = data.foregroundPattern;
- if (pattern != null && pattern.gradient != null) {
- strokePattern(path, pattern);
- } else {
- path.stroke();
- }
- path.removeAllPoints();
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Draws the outline of the rectangle specified by the arguments,
- * using the receiver's foreground color. The left and right edges
- * of the rectangle are at <code>x</code> and <code>x + width</code>.
- * The top and bottom edges are at <code>y</code> and <code>y + height</code>.
- *
- * @param x the x coordinate of the rectangle to be drawn
- * @param y the y coordinate of the rectangle to be drawn
- * @param width the width of the rectangle to be drawn
- * @param height the height of the rectangle to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRectangle(int x, int y, int width, int height) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = checkGC(DRAW);
- try {
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- NSRect rect = new NSRect();
- rect.x = x + data.drawXOffset;
- rect.y = y + data.drawYOffset;
- rect.width = width;
- rect.height = height;
- NSBezierPath path = data.path;
- path.appendBezierPathWithRect(rect);
- Pattern pattern = data.foregroundPattern;
- if (pattern != null && pattern.gradient != null) {
- strokePattern(path, pattern);
- } else {
- path.stroke();
- }
- path.removeAllPoints();
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Draws the outline of the specified rectangle, using the receiver's
- * foreground color. The left and right edges of the rectangle are at
- * <code>rect.x</code> and <code>rect.x + rect.width</code>. The top
- * and bottom edges are at <code>rect.y</code> and
- * <code>rect.y + rect.height</code>.
- *
- * @param rect the rectangle to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRectangle(Rectangle rect) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- drawRectangle (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Draws the outline of the round-cornered rectangle specified by
- * the arguments, using the receiver's foreground color. The left and
- * right edges of the rectangle are at <code>x</code> and <code>x + width</code>.
- * The top and bottom edges are at <code>y</code> and <code>y + height</code>.
- * The <em>roundness</em> of the corners is specified by the
- * <code>arcWidth</code> and <code>arcHeight</code> arguments, which
- * are respectively the width and height of the ellipse used to draw
- * the corners.
- *
- * @param x the x coordinate of the rectangle to be drawn
- * @param y the y coordinate of the rectangle to be drawn
- * @param width the width of the rectangle to be drawn
- * @param height the height of the rectangle to be drawn
- * @param arcWidth the width of the arc
- * @param arcHeight the height of the arc
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (arcWidth == 0 || arcHeight == 0) {
- drawRectangle(x, y, width, height);
- return;
- }
- NSAutoreleasePool pool = checkGC(DRAW);
- try {
- NSBezierPath path = data.path;
- NSRect rect = new NSRect();
- rect.x = x + data.drawXOffset;
- rect.y = y + data.drawYOffset;
- rect.width = width;
- rect.height = height;
- path.appendBezierPathWithRoundedRect(rect, arcWidth / 2f, arcHeight / 2f);
- Pattern pattern = data.foregroundPattern;
- if (pattern != null && pattern.gradient != null) {
- strokePattern(path, pattern);
- } else {
- path.stroke();
- }
- path.removeAllPoints();
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. No tab expansion or carriage return processing
- * will be performed. The background of the rectangular area where
- * the string is being drawn will be filled with the receiver's
- * background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawString (String string, int x, int y) {
- drawString(string, x, y, false);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. No tab expansion or carriage return processing
- * will be performed. If <code>isTransparent</code> is <code>true</code>,
- * then the background of the rectangular area where the string is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawString(String string, int x, int y, boolean isTransparent) {
- drawText(string, x, y, isTransparent ? SWT.DRAW_TRANSPARENT : 0);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion and carriage return processing
- * are performed. The background of the rectangular area where
- * the text is being drawn will be filled with the receiver's
- * background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText(String string, int x, int y) {
- drawText(string, x, y, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion and carriage return processing
- * are performed. If <code>isTransparent</code> is <code>true</code>,
- * then the background of the rectangular area where the text is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText(String string, int x, int y, boolean isTransparent) {
- int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB;
- if (isTransparent) flags |= SWT.DRAW_TRANSPARENT;
- drawText(string, x, y, flags);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion, line delimiter and mnemonic
- * processing are performed according to the specified flags. If
- * <code>flags</code> includes <code>DRAW_TRANSPARENT</code>,
- * then the background of the rectangular area where the text is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- * <p>
- * The parameter <code>flags</code> may be a combination of:
- * <dl>
- * <dt><b>DRAW_DELIMITER</b></dt>
- * <dd>draw multiple lines</dd>
- * <dt><b>DRAW_TAB</b></dt>
- * <dd>expand tabs</dd>
- * <dt><b>DRAW_MNEMONIC</b></dt>
- * <dd>underline the mnemonic character</dd>
- * <dt><b>DRAW_TRANSPARENT</b></dt>
- * <dd>transparent background</dd>
- * </dl>
- * </p>
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param flags the flags specifying how to process the text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText (String string, int x, int y, int flags) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- NSAutoreleasePool pool = checkGC(CLIPPING | TRANSFORM | FONT);
- try {
- handle.saveGraphicsState();
- boolean mode = true;
- switch (data.textAntialias) {
- case SWT.DEFAULT:
- /* Printer is off by default */
- if (!handle.isDrawingToScreen()) mode = false;
- break;
- case SWT.OFF: mode = false; break;
- case SWT.ON: mode = true; break;
- }
- handle.setShouldAntialias(mode);
- NSAttributedString str = createString(string, flags, true);
- if ((flags & SWT.DRAW_TRANSPARENT) == 0) {
- NSSize size = str.size();
- NSRect rect = new NSRect();
- rect.x = x;
- rect.y = y;
- rect.width = size.width;
- rect.height = size.height;
- NSColor bg = data.bg;
- if (bg == null) {
- float /*double*/ [] color = data.background;
- bg = data.bg = NSColor.colorWithDeviceRed(color[0], color[1], color[2], data.alpha / 255f);
- bg.retain();
- }
- bg.setFill();
- NSBezierPath.fillRect(rect);
- str.drawInRect(rect);
- } else {
- NSPoint pt = new NSPoint();
- pt.x = x;
- pt.y = y;
- str.drawAtPoint(pt);
- }
- str.release();
- handle.restoreGraphicsState();
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals(Object object) {
- if (object == this) return true;
- if (!(object instanceof GC)) return false;
- return handle == ((GC)object).handle;
-}
-
-/**
- * Fills the interior of a circular or elliptical arc within
- * the specified rectangular area, with the receiver's background
- * color.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees, using the current color.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc to be filled
- * @param y the y coordinate of the upper-left corner of the arc to be filled
- * @param width the width of the arc to be filled
- * @param height the height of the arc to be filled
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawArc
- */
-public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- NSAutoreleasePool pool = checkGC(FILL);
- try {
- handle.saveGraphicsState();
- NSAffineTransform transform = NSAffineTransform.transform();
- float /*double*/ xOffset = data.drawXOffset, yOffset = data.drawYOffset;
- transform.translateXBy(x + xOffset + width / 2f, y + yOffset + height / 2f);
- transform.scaleXBy(width / 2f, height / 2f);
- NSBezierPath path = data.path;
- NSPoint center = new NSPoint();
- path.moveToPoint(center);
- float sAngle = -startAngle;
- float eAngle = -(startAngle + arcAngle);
- path.appendBezierPathWithArcWithCenter(center, 1, sAngle, eAngle, arcAngle>0);
- path.closePath();
- path.transformUsingAffineTransform(transform);
- Pattern pattern = data.backgroundPattern;
- if (pattern != null && pattern.gradient != null) {
- fillPattern(path, pattern);
- } else {
- path.fill();
- }
- path.removeAllPoints();
- handle.restoreGraphicsState();
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Fills the interior of the specified rectangle with a gradient
- * sweeping from left to right or top to bottom progressing
- * from the receiver's foreground color to its background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled, may be negative
- * (inverts direction of gradient if horizontal)
- * @param height the height of the rectangle to be filled, may be negative
- * (inverts direction of gradient if vertical)
- * @param vertical if true sweeps from top to bottom, else
- * sweeps from left to right
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if ((width == 0) || (height == 0)) return;
- NSAutoreleasePool pool = checkGC(CLIPPING | TRANSFORM);
- try {
- RGB backgroundRGB, foregroundRGB;
- backgroundRGB = getBackground().getRGB();
- foregroundRGB = getForeground().getRGB();
-
- RGB fromRGB, toRGB;
- fromRGB = foregroundRGB;
- toRGB = backgroundRGB;
- boolean swapColors = false;
- if (width < 0) {
- x += width; width = -width;
- if (! vertical) swapColors = true;
- }
- if (height < 0) {
- y += height; height = -height;
- if (vertical) swapColors = true;
- }
- if (swapColors) {
- fromRGB = backgroundRGB;
- toRGB = foregroundRGB;
- }
- if (fromRGB.equals(toRGB)) {
- fillRectangle(x, y, width, height);
- } else {
- NSColor startingColor = NSColor.colorWithDeviceRed(fromRGB.red / 255f, fromRGB.green / 255f, fromRGB.blue / 255f, data.alpha / 255f);
- NSColor endingColor = NSColor.colorWithDeviceRed(toRGB.red / 255f, toRGB.green / 255f, toRGB.blue / 255f, data.alpha / 255f);
- NSGradient gradient = ((NSGradient)new NSGradient().alloc()).initWithStartingColor(startingColor, endingColor);
- NSRect rect = new NSRect();
- rect.x = x;
- rect.y = y;
- rect.width = width;
- rect.height = height;
- gradient.drawInRect(rect, vertical ? 90 : 0);
- gradient.release();
- }
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Fills the interior of an oval, within the specified
- * rectangular area, with the receiver's background
- * color.
- *
- * @param x the x coordinate of the upper left corner of the oval to be filled
- * @param y the y coordinate of the upper left corner of the oval to be filled
- * @param width the width of the oval to be filled
- * @param height the height of the oval to be filled
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawOval
- */
-public void fillOval(int x, int y, int width, int height) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = checkGC(FILL);
- try {
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- NSBezierPath path = data.path;
- NSRect rect = new NSRect();
- rect.x = x;
- rect.y = y;
- rect.width = width;
- rect.height = height;
- path.appendBezierPathWithOvalInRect(rect);
- Pattern pattern = data.backgroundPattern;
- if (pattern != null && pattern.gradient != null) {
- fillPattern(path, pattern);
- } else {
- path.fill();
- }
- path.removeAllPoints();
- } finally {
- uncheckGC(pool);
- }
-}
-
-void fillPattern(NSBezierPath path, Pattern pattern) {
- handle.saveGraphicsState();
- path.addClip();
- NSRect bounds = path.bounds();
- NSPoint start = new NSPoint();
- start.x = pattern.pt1.x;
- start.y = pattern.pt1.y;
- NSPoint end = new NSPoint();
- end.x = pattern.pt2.x;
- end.y = pattern.pt2.y;
- float /*double*/ difx = end.x - start.x;
- float /*double*/ dify = end.y - start.y;
- if (difx == 0 && dify == 0) {
- float /*double*/ [] color = pattern.color1;
- NSColor.colorWithDeviceRed(color[0], color[1], color[2], data.alpha / 255f).setFill();
- path.fill();
- handle.restoreGraphicsState();
- return;
- }
- float /*double*/ startx, starty, endx, endy;
- if (difx == 0 || dify == 0) {
- startx = bounds.x;
- starty = bounds.y;
- endx = bounds.x + bounds.width;
- endy = bounds.y + bounds.height;
- if (difx < 0 || dify < 0) {
- startx = endx;
- starty = endy;
- endx = bounds.x;
- endy = bounds.y;
- }
- } else {
- float /*double*/ m = (end.y-start.y)/(end.x - start.x);
- float /*double*/ b = end.y - (m * end.x);
- float /*double*/ m2 = -1/m; //perpendicular slope
- float /*double*/ b2 = bounds.y - (m2 * bounds.x);
- startx = endx = (b - b2) / (m2 - m);
- b2 = (bounds.y + bounds.height) - (m2 * bounds.x);
- float /*double*/ x2 = (b - b2) / (m2 - m);
- startx = difx > 0 ? Math.min(startx, x2) : Math.max(startx, x2);
- endx = difx < 0 ? Math.min(endx, x2) : Math.max(endx, x2);
- b2 = bounds.y - (m2 * (bounds.x + bounds.width));
- x2 = (b - b2) / (m2 - m);
- startx = difx > 0 ? Math.min(startx, x2) : Math.max(startx, x2);
- endx = difx < 0 ? Math.min(endx, x2) : Math.max(endx, x2);
- b2 = (bounds.y + bounds.height) - (m2 * (bounds.x + bounds.width));
- x2 = (b - b2) / (m2 - m);
- startx = difx > 0 ? Math.min(startx, x2) : Math.max(startx, x2);
- endx = difx < 0 ? Math.min(endx, x2) : Math.max(endx, x2);
- starty = (m * startx) + b;
- endy = (m * endx) + b;
- }
- if (difx != 0) {
- while ((difx > 0 && start.x >= startx) || (difx < 0 && start.x <= startx)) {
- start.x -= difx;
- start.y -= dify;
- }
- } else {
- while ((dify > 0 && start.y >= starty) || (dify < 0 && start.y <= starty)) {
- start.x -= difx;
- start.y -= dify;
- }
- }
- end.x = start.x;
- end.y = start.y;
- do {
- end.x += difx;
- end.y += dify;
- pattern.gradient.drawFromPoint(start, end, 0);
- start.x = end.x;
- start.y = end.y;
- } while (
- (difx > 0 && end.x <= endx) ||
- (difx < 0 && end.x >= endx) ||
- (difx == 0 && ((dify > 0 && end.y <= endy) || (dify < 0 && end.y >= endy)))
- );
- handle.restoreGraphicsState();
-}
-
-/**
- * Fills the path described by the parameter.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the path to fill
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- *
- * @since 3.1
- */
-public void fillPath(Path path) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.handle == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = checkGC(FILL);
- try {
- NSBezierPath drawPath = data.path;
- drawPath.appendBezierPath(path.handle);
- Pattern pattern = data.backgroundPattern;
- if (pattern != null && pattern.gradient != null) {
- fillPattern(drawPath, pattern);
- } else {
- drawPath.fill();
- }
- drawPath.removeAllPoints();
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Fills the interior of the closed polygon which is defined by the
- * specified array of integer coordinates, using the receiver's
- * background color. The array contains alternating x and y values
- * which are considered to represent points which are the vertices of
- * the polygon. Lines are drawn between each consecutive pair, and
- * between the first pair and last pair in the array.
- *
- * @param pointArray an array of alternating x and y values which are the vertices of the polygon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT if pointArray is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawPolygon
- */
-public void fillPolygon(int[] pointArray) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (pointArray.length < 4) return;
- NSAutoreleasePool pool = checkGC(FILL);
- try {
- NSBezierPath path = data.path;
- NSPoint pt = new NSPoint();
- pt.x = pointArray[0];
- pt.y = pointArray[1];
- path.moveToPoint(pt);
- int end = pointArray.length / 2 * 2;
- for (int i = 2; i < end; i+=2) {
- pt.x = pointArray[i];
- pt.y = pointArray[i+1];
- path.lineToPoint(pt);
- }
- path.closePath();
- Pattern pattern = data.backgroundPattern;
- if (pattern != null && pattern.gradient != null) {
- fillPattern(path, pattern);
- } else {
- path.fill();
- }
- path.removeAllPoints();
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Fills the interior of the rectangle specified by the arguments,
- * using the receiver's background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillRectangle(int x, int y, int width, int height) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = checkGC(FILL);
- try {
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- NSRect rect = new NSRect();
- rect.x = x;
- rect.y = y;
- rect.width = width;
- rect.height = height;
- NSBezierPath path = data.path;
- path.appendBezierPathWithRect(rect);
- Pattern pattern = data.backgroundPattern;
- if (pattern != null && pattern.gradient != null) {
- fillPattern(path, pattern);
- } else {
- path.fill();
- }
- path.removeAllPoints();
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Fills the interior of the specified rectangle, using the receiver's
- * background color.
- *
- * @param rect the rectangle to be filled
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillRectangle(Rectangle rect) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- fillRectangle(rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Fills the interior of the round-cornered rectangle specified by
- * the arguments, using the receiver's background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- * @param arcWidth the width of the arc
- * @param arcHeight the height of the arc
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRoundRectangle
- */
-public void fillRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (arcWidth == 0 || arcHeight == 0) {
- fillRectangle(x, y, width, height);
- return;
- }
- NSAutoreleasePool pool = checkGC(FILL);
- try {
- NSBezierPath path = data.path;
- NSRect rect = new NSRect();
- rect.x = x;
- rect.y = y;
- rect.width = width;
- rect.height = height;
- path.appendBezierPathWithRoundedRect(rect, arcWidth / 2f, arcHeight / 2f);
- Pattern pattern = data.backgroundPattern;
- if (pattern != null && pattern.gradient != null) {
- fillPattern(path, pattern);
- } else {
- path.fill();
- }
- path.removeAllPoints();
- } finally {
- uncheckGC(pool);
- }
-}
-
-void strokePattern(NSBezierPath path, Pattern pattern) {
- handle.saveGraphicsState();
- int /*long*/ cgPath = createCGPathRef(path);
- int /*long*/ cgContext = handle.graphicsPort();
- OS.CGContextSaveGState(cgContext);
- initCGContext(cgContext);
- OS.CGContextAddPath(cgContext, cgPath);
- OS.CGContextReplacePathWithStrokedPath(cgContext);
- OS.CGPathRelease(cgPath);
- cgPath = 0;
- cgPath = OS.CGContextCopyPath(cgContext);
- if (cgPath == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.CGContextRestoreGState(cgContext);
- NSBezierPath strokePath = createNSBezierPath(cgPath);
- OS.CGPathRelease(cgPath);
- fillPattern(strokePath, pattern);
- handle.restoreGraphicsState();
-}
-
-void flush () {
- handle.flushGraphics();
-}
-
-/**
- * Returns the <em>advance width</em> of the specified character in
- * the font which is currently selected into the receiver.
- * <p>
- * The advance width is defined as the horizontal distance the cursor
- * should move after printing the character in the selected font.
- * </p>
- *
- * @param ch the character to measure
- * @return the distance in the x direction to move past the character before painting the next
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getAdvanceWidth(char ch) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- //NOT DONE
- return stringExtent(new String(new char[]{ch})).x;
-}
-
-/**
- * Returns the background color.
- *
- * @return the receiver's background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getBackground() {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return Color.cocoa_new (data.device, data.background);
-}
-
-/**
- * Returns the background pattern. The default value is
- * <code>null</code>.
- *
- * @return the receiver's background pattern
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Pattern
- *
- * @since 3.1
- */
-public Pattern getBackgroundPattern() {
- if (handle == null) SWT.error(SWT.ERROR_WIDGET_DISPOSED);
- return data.backgroundPattern;
-}
-
-/**
- * Returns <code>true</code> if receiver is using the operating system's
- * advanced graphics subsystem. Otherwise, <code>false</code> is returned
- * to indicate that normal graphics are in use.
- * <p>
- * Advanced graphics may not be installed for the operating system. In this
- * case, <code>false</code> is always returned. Some operating system have
- * only one graphics subsystem. If this subsystem supports advanced graphics,
- * then <code>true</code> is always returned. If any graphics operation such
- * as alpha, antialias, patterns, interpolation, paths, clipping or transformation
- * has caused the receiver to switch from regular to advanced graphics mode,
- * <code>true</code> is returned. If the receiver has been explicitly switched
- * to advanced mode and this mode is supported, <code>true</code> is returned.
- * </p>
- *
- * @return the advanced value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public boolean getAdvanced() {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return true;
-}
-
-/**
- * Returns the receiver's alpha value. The alpha value
- * is between 0 (transparent) and 255 (opaque).
- *
- * @return the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getAlpha() {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.alpha;
-}
-
-/**
- * Returns the receiver's anti-aliasing setting value, which will be
- * one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code>. Note that this controls anti-aliasing for all
- * <em>non-text drawing</em> operations.
- *
- * @return the anti-aliasing setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getTextAntialias
- *
- * @since 3.1
- */
-public int getAntialias() {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.antialias;
-}
-
-/**
- * Returns the width of the specified character in the font
- * selected into the receiver.
- * <p>
- * The width is defined as the space taken up by the actual
- * character, not including the leading and tailing whitespace
- * or overhang.
- * </p>
- *
- * @param ch the character to measure
- * @return the width of the character
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getCharWidth(char ch) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- //NOT DONE
- return stringExtent(new String(new char[]{ch})).x;
-}
-
-/**
- * Returns the bounding rectangle of the receiver's clipping
- * region. If no clipping region is set, the return value
- * will be a rectangle which covers the entire bounds of the
- * object the receiver is drawing on.
- *
- * @return the bounding rectangle of the clipping region
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getClipping() {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSRect rect = null;
- if (data.view != null) {
- rect = data.view.visibleRect();
- } else {
- rect = new NSRect();
- if (data.image != null) {
- NSSize size = data.image.handle.size();
- rect.width = size.width;
- rect.height = size.height;
- } else if (data.size != null) {
- rect.width = data.size.width;
- rect.height = data.size.height;
- }
- }
- if (data.paintRect != null || data.clipPath != null || data.inverseTransform != null) {
- if (data.paintRect != null) {
- OS.NSIntersectionRect(rect, rect, data.paintRect);
- }
- if (data.clipPath != null) {
- NSRect clip = data.clipPath.bounds();
- OS.NSIntersectionRect(rect, rect, clip);
- }
- if (data.inverseTransform != null && rect.width > 0 && rect.height > 0) {
- NSPoint pt = new NSPoint();
- pt.x = rect.x;
- pt.y = rect.y;
- NSSize size = new NSSize();
- size.width = rect.width;
- size.height = rect.height;
- pt = data.inverseTransform.transformPoint(pt);
- size = data.inverseTransform.transformSize(size);
- rect.x = pt.x;
- rect.y = pt.y;
- rect.width = size.width;
- rect.height = size.height;
- }
- }
- return new Rectangle((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Sets the region managed by the argument to the current
- * clipping region of the receiver.
- *
- * @param region the region to fill with the clipping region
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the region is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the region is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getClipping(Region region) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- region.subtract(region);
- NSRect rect = null;
- if (data.view != null) {
- rect = data.view.visibleRect();
- } else {
- rect = new NSRect();
- if (data.image != null) {
- NSSize size = data.image.handle.size();
- rect.width = size.width;
- rect.height = size.height;
- } else if (data.size != null) {
- rect.width = data.size.width;
- rect.height = data.size.height;
- }
- }
- region.add((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
- NSRect paintRect = data.paintRect;
- if (paintRect != null) {
- region.intersect((int)paintRect.x, (int)paintRect.y, (int)paintRect.width, (int)paintRect.height);
- }
- if (data.clipPath != null) {
- NSBezierPath clip = data.clipPath.bezierPathByFlatteningPath();
- int count = (int)/*64*/clip.elementCount();
- int pointCount = 0;
- Region clipRgn = new Region(device);
- int[] pointArray = new int[count * 2];
- int /*long*/ points = OS.malloc(NSPoint.sizeof);
- if (points == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- NSPoint pt = new NSPoint();
- for (int i = 0; i < count; i++) {
- int element = (int)/*64*/clip.elementAtIndex(i, points);
- switch (element) {
- case OS.NSMoveToBezierPathElement:
- if (pointCount != 0) clipRgn.add(pointArray, pointCount);
- pointCount = 0;
- OS.memmove(pt, points, NSPoint.sizeof);
- pointArray[pointCount++] = (int)pt.x;
- pointArray[pointCount++] = (int)pt.y;
- break;
- case OS.NSLineToBezierPathElement:
- OS.memmove(pt, points, NSPoint.sizeof);
- pointArray[pointCount++] = (int)pt.x;
- pointArray[pointCount++] = (int)pt.y;
- break;
- case OS.NSClosePathBezierPathElement:
- if (pointCount != 0) clipRgn.add(pointArray, pointCount);
- pointCount = 0;
- break;
- }
- }
- if (pointCount != 0) clipRgn.add(pointArray, pointCount);
- OS.free(points);
- region.intersect(clipRgn);
- clipRgn.dispose();
- }
- if (data.inverseTransform != null) {
- region.convertRgn(data.inverseTransform);
- }
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns the receiver's fill rule, which will be one of
- * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>.
- *
- * @return the receiver's fill rule
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getFillRule() {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.fillRule;
-}
-
-/**
- * Returns the font currently being used by the receiver
- * to draw and measure text.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getFont() {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.font;
-}
-
-/**
- * Returns a FontMetrics which contains information
- * about the font currently being used by the receiver
- * to draw and measure text.
- *
- * @return font metrics for the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontMetrics getFontMetrics() {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = checkGC(FONT);
- try {
- NSFont font = data.font.handle;
- int ascent = (int)(0.5f + font.ascender());
- int descent = (int)(0.5f + (-font.descender() + font.leading()));
- String s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- int averageCharWidth = stringExtent(s).x / s.length();
- return FontMetrics.cocoa_new(ascent, descent, averageCharWidth, 0, ascent + descent);
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Returns the receiver's foreground color.
- *
- * @return the color used for drawing foreground things
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getForeground() {
- if (handle == null) SWT.error(SWT.ERROR_WIDGET_DISPOSED);
- return Color.cocoa_new(data.device, data.foreground);
-}
-
-/**
- * Returns the foreground pattern. The default value is
- * <code>null</code>.
- *
- * @return the receiver's foreground pattern
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Pattern
- *
- * @since 3.1
- */
-public Pattern getForegroundPattern() {
- if (handle == null) SWT.error(SWT.ERROR_WIDGET_DISPOSED);
- return data.foregroundPattern;
-}
-
-/**
- * Returns the GCData.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>GC</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @return the receiver's GCData
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see GCData
- *
- * @since 3.2
- * @noreference This method is not intended to be referenced by clients.
- */
-public GCData getGCData() {
- if (handle == null) SWT.error(SWT.ERROR_WIDGET_DISPOSED);
- return data;
-}
-
-/**
- * Returns the receiver's interpolation setting, which will be one of
- * <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>,
- * <code>SWT.LOW</code> or <code>SWT.HIGH</code>.
- *
- * @return the receiver's interpolation setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getInterpolation() {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int interpolation = (int)/*64*/handle.imageInterpolation();
- switch (interpolation) {
- case OS.NSImageInterpolationDefault: return SWT.DEFAULT;
- case OS.NSImageInterpolationNone: return SWT.NONE;
- case OS.NSImageInterpolationLow: return SWT.LOW;
- case OS.NSImageInterpolationHigh: return SWT.HIGH;
- }
- return SWT.DEFAULT;
-}
-
-/**
- * Returns the receiver's line attributes.
- *
- * @return the line attributes used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.3
- */
-public LineAttributes getLineAttributes() {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float[] dashes = null;
- if (data.lineDashes != null) {
- dashes = new float[data.lineDashes.length];
- System.arraycopy(data.lineDashes, 0, dashes, 0, dashes.length);
- }
- return new LineAttributes(data.lineWidth, data.lineCap, data.lineJoin, data.lineStyle, dashes, data.lineDashesOffset, data.lineMiterLimit);
-}
-
-/**
- * Returns the receiver's line cap style, which will be one
- * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>,
- * or <code>SWT.CAP_SQUARE</code>.
- *
- * @return the cap style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getLineCap() {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineCap;
-}
-
-/**
- * Returns the receiver's line dash style. The default value is
- * <code>null</code>.
- *
- * @return the line dash style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int[] getLineDash() {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineDashes == null) return null;
- int[] lineDashes = new int[data.lineDashes.length];
- for (int i = 0; i < lineDashes.length; i++) {
- lineDashes[i] = (int)data.lineDashes[i];
- }
- return lineDashes;
-}
-
-/**
- * Returns the receiver's line join style, which will be one
- * of the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>,
- * or <code>SWT.JOIN_BEVEL</code>.
- *
- * @return the join style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getLineJoin() {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineJoin;
-}
-
-/**
- * Returns the receiver's line style, which will be one
- * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
- * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or
- * <code>SWT.LINE_DASHDOTDOT</code>.
- *
- * @return the style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineStyle() {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineStyle;
-}
-
-/**
- * Returns the width that will be used when drawing lines
- * for all of the figure drawing operations (that is,
- * <code>drawLine</code>, <code>drawRectangle</code>,
- * <code>drawPolyline</code>, and so forth.
- *
- * @return the receiver's line width
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineWidth() {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (int)data.lineWidth;
-}
-
-/**
- * Returns the receiver's style information.
- * <p>
- * Note that the value which is returned by this method <em>may
- * not match</em> the value which was provided to the constructor
- * when the receiver was created. This can occur when the underlying
- * operating system does not support a particular combination of
- * requested styles.
- * </p>
- *
- * @return the style bits
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getStyle () {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.style;
-}
-
-/**
- * Returns the receiver's text drawing anti-aliasing setting value,
- * which will be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code>. Note that this controls anti-aliasing
- * <em>only</em> for text drawing operations.
- *
- * @return the anti-aliasing setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getAntialias
- *
- * @since 3.1
- */
-public int getTextAntialias() {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.textAntialias;
-}
-
-/**
- * Sets the parameter to the transform that is currently being
- * used by the receiver.
- *
- * @param transform the destination to copy the transform into
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Transform
- *
- * @since 3.1
- */
-public void getTransform (Transform transform) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transform == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAffineTransform cmt = data.transform;
- if (cmt != null) {
- NSAffineTransformStruct struct = cmt.transformStruct();
- transform.handle.setTransformStruct(struct);
- } else {
- transform.setElements(1, 0, 0, 1, 0, 0);
- }
-}
-
-/**
- * Returns <code>true</code> if this GC is drawing in the mode
- * where the resulting color in the destination is the
- * <em>exclusive or</em> of the color values in the source
- * and the destination, and <code>false</code> if it is
- * drawing in the mode where the destination color is being
- * replaced with the source color value.
- *
- * @return <code>true</code> true if the receiver is in XOR mode, and false otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean getXORMode() {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.xorMode;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #equals
- */
-public int hashCode() {
- return handle != null ? (int)/*64*/handle.id : 0;
-}
-
-void init(Drawable drawable, GCData data, int /*long*/ context) {
- if (data.foreground != null) data.state &= ~(FOREGROUND | FOREGROUND_FILL);
- if (data.background != null) data.state &= ~BACKGROUND;
- if (data.font != null) data.state &= ~FONT;
- data.state &= ~DRAW_OFFSET;
-
- Image image = data.image;
- if (image != null) image.memGC = this;
- this.drawable = drawable;
- this.data = data;
- handle = new NSGraphicsContext(context);
- handle.retain();
- handle.saveGraphicsState();
- data.path = NSBezierPath.bezierPath();
- data.path.setWindingRule(data.fillRule == SWT.FILL_WINDING ? OS.NSNonZeroWindingRule : OS.NSEvenOddWindingRule);
- data.path.retain();
-}
-
-void initCGContext(int /*long*/ cgContext) {
- int state = data.state;
- if ((state & LINE_WIDTH) != 0) {
- OS.CGContextSetLineWidth(cgContext, data.lineWidth == 0 ? 1 : data.lineWidth);
- switch (data.lineStyle) {
- case SWT.LINE_DOT:
- case SWT.LINE_DASH:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- state |= LINE_STYLE;
- }
- }
- if ((state & LINE_STYLE) != 0) {
- float[] dashes = null;
- float width = data.lineWidth;
- switch (data.lineStyle) {
- case SWT.LINE_SOLID: break;
- case SWT.LINE_DASH: dashes = width != 0 ? LINE_DASH : LINE_DASH_ZERO; break;
- case SWT.LINE_DOT: dashes = width != 0 ? LINE_DOT : LINE_DOT_ZERO; break;
- case SWT.LINE_DASHDOT: dashes = width != 0 ? LINE_DASHDOT : LINE_DASHDOT_ZERO; break;
- case SWT.LINE_DASHDOTDOT: dashes = width != 0 ? LINE_DASHDOTDOT : LINE_DASHDOTDOT_ZERO; break;
- case SWT.LINE_CUSTOM: dashes = data.lineDashes; break;
- }
- if (dashes != null) {
- float[] lengths = new float[dashes.length];
- for (int i = 0; i < lengths.length; i++) {
- lengths[i] = width == 0 || data.lineStyle == SWT.LINE_CUSTOM ? dashes[i] : dashes[i] * width;
- }
- OS.CGContextSetLineDash(cgContext, data.lineDashesOffset, lengths, lengths.length);
- } else {
- OS.CGContextSetLineDash(cgContext, 0, null, 0);
- }
- }
- if ((state & LINE_MITERLIMIT) != 0) {
- OS.CGContextSetMiterLimit(cgContext, data.lineMiterLimit);
- }
- if ((state & LINE_JOIN) != 0) {
- int joinStyle = 0;
- switch (data.lineJoin) {
- case SWT.JOIN_MITER: joinStyle = OS.kCGLineJoinMiter; break;
- case SWT.JOIN_ROUND: joinStyle = OS.kCGLineJoinRound; break;
- case SWT.JOIN_BEVEL: joinStyle = OS.kCGLineJoinBevel; break;
- }
- OS.CGContextSetLineJoin(cgContext, joinStyle);
- }
- if ((state & LINE_CAP) != 0) {
- int capStyle = 0;
- switch (data.lineCap) {
- case SWT.CAP_ROUND: capStyle = OS.kCGLineCapRound; break;
- case SWT.CAP_FLAT: capStyle = OS.kCGLineCapButt; break;
- case SWT.CAP_SQUARE: capStyle = OS.kCGLineCapSquare; break;
- }
- OS.CGContextSetLineCap(cgContext, capStyle);
- }
-}
-
-/**
- * Returns <code>true</code> if the receiver has a clipping
- * region set into it, and <code>false</code> otherwise.
- * If this method returns false, the receiver will draw on all
- * available space in the destination. If it returns true,
- * it will draw only in the area that is covered by the region
- * that can be accessed with <code>getClipping(region)</code>.
- *
- * @return <code>true</code> if the GC has a clipping region, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean isClipped() {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.clipPath != null;
-}
-
-/**
- * Returns <code>true</code> if the GC has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the GC.
- * When a GC has been disposed, it is an error to
- * invoke any other method using the GC.
- *
- * @return <code>true</code> when the GC is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == null;
-}
-
-boolean isIdentity(float[] transform) {
- return transform[0] == 1 && transform[1] == 0 && transform[2] == 0
- && transform[3] == 1 && transform[4] == 0 && transform[5] == 0;
-}
-
-/**
- * Sets the receiver to always use the operating system's advanced graphics
- * subsystem for all graphics operations if the argument is <code>true</code>.
- * If the argument is <code>false</code>, the advanced graphics subsystem is
- * no longer used, advanced graphics state is cleared and the normal graphics
- * subsystem is used from now on.
- * <p>
- * Normally, the advanced graphics subsystem is invoked automatically when
- * any one of the alpha, antialias, patterns, interpolation, paths, clipping
- * or transformation operations in the receiver is requested. When the receiver
- * is switched into advanced mode, the advanced graphics subsystem performs both
- * advanced and normal graphics operations. Because the two subsystems are
- * different, their output may differ. Switching to advanced graphics before
- * any graphics operations are performed ensures that the output is consistent.
- * </p><p>
- * Advanced graphics may not be installed for the operating system. In this
- * case, this operation does nothing. Some operating system have only one
- * graphics subsystem, so switching from normal to advanced graphics does
- * nothing. However, switching from advanced to normal graphics will always
- * clear the advanced graphics state, even for operating systems that have
- * only one graphics subsystem.
- * </p>
- *
- * @param advanced the new advanced graphics state
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAlpha
- * @see #setAntialias
- * @see #setBackgroundPattern
- * @see #setClipping(Path)
- * @see #setForegroundPattern
- * @see #setLineAttributes
- * @see #setInterpolation
- * @see #setTextAntialias
- * @see #setTransform
- * @see #getAdvanced
- *
- * @since 3.1
- */
-public void setAdvanced(boolean advanced) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (!advanced) {
- setAlpha(0xFF);
- setAntialias(SWT.DEFAULT);
- setBackgroundPattern(null);
- setClipping((Rectangle)null);
- setForegroundPattern(null);
- setInterpolation(SWT.DEFAULT);
- setTextAntialias(SWT.DEFAULT);
- setTransform(null);
- }
-}
-
-/**
- * Sets the receiver's alpha value which must be
- * between 0 (transparent) and 255 (opaque).
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param alpha the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setAlpha(int alpha) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- data.alpha = alpha & 0xFF;
- data.state &= ~(BACKGROUND | FOREGROUND | FOREGROUND_FILL);
-
-}
-
-/**
- * Sets the receiver's anti-aliasing value to the parameter,
- * which must be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code>
- * or <code>SWT.ON</code>. Note that this controls anti-aliasing for all
- * <em>non-text drawing</em> operations.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param antialias the anti-aliasing setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.OFF</code> or <code>SWT.ON</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- * @see #setTextAntialias
- *
- * @since 3.1
- */
-public void setAntialias(int antialias) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- boolean mode = true;
- switch (antialias) {
- case SWT.DEFAULT:
- /* Printer is off by default */
- if (!handle.isDrawingToScreen()) mode = false;
- break;
- case SWT.OFF: mode = false; break;
- case SWT.ON: mode = true; break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.antialias = antialias;
- handle.setShouldAntialias(mode);
-}
-
-/**
- * Sets the background color. The background color is used
- * for fill operations and as the background color when text
- * is drawn.
- *
- * @param color the new background color for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setBackground(Color color) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.background = color.handle;
- data.backgroundPattern = null;
- if (data.bg != null) data.bg.release();
- data.bg = null;
- data.state &= ~BACKGROUND;
-}
-
-/**
- * Sets the background pattern. The default value is <code>null</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param pattern the new background pattern
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Pattern
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setBackgroundPattern(Pattern pattern) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.backgroundPattern == pattern) return;
- data.backgroundPattern = pattern;
- data.state &= ~BACKGROUND;
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the rectangular area specified
- * by the arguments.
- *
- * @param x the x coordinate of the clipping rectangle
- * @param y the y coordinate of the clipping rectangle
- * @param width the width of the clipping rectangle
- * @param height the height of the clipping rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping(int x, int y, int width, int height) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- NSRect rect = new NSRect();
- rect.x = x;
- rect.y = y;
- rect.width = width;
- rect.height = height;
- NSBezierPath path = NSBezierPath.bezierPathWithRect(rect);
- path.retain();
- setClipping(path);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the path specified
- * by the argument.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the clipping path.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the path has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setClipping(Path path) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path != null && path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- setClipping(new NSBezierPath(path.handle.copy().id));
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the rectangular area specified
- * by the argument. Specifying <code>null</code> for the
- * rectangle reverts the receiver's clipping area to its
- * original value.
- *
- * @param rect the clipping rectangle or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping(Rectangle rect) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) {
- setClipping((NSBezierPath)null);
- } else {
- setClipping(rect.x, rect.y, rect.width, rect.height);
- }
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the region specified
- * by the argument. Specifying <code>null</code> for the
- * region reverts the receiver's clipping area to its
- * original value.
- *
- * @param region the clipping region or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping(Region region) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region != null && region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- setClipping(region != null ? region.getPath() : null);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-void setClipping(NSBezierPath path) {
- if (data.clipPath != null) {
- data.clipPath.release();
- data.clipPath = null;
- }
- if (path != null) {
- data.clipPath = path;
- if (data.transform != null) {
- data.clipPath.transformUsingAffineTransform(data.transform);
- }
- }
- data.state &= ~CLIPPING;
-}
-
-/**
- * Sets the receiver's fill rule to the parameter, which must be one of
- * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>.
- *
- * @param rule the new fill rule
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of <code>SWT.FILL_EVEN_ODD</code>
- * or <code>SWT.FILL_WINDING</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setFillRule(int rule) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (rule) {
- case SWT.FILL_WINDING:
- case SWT.FILL_EVEN_ODD: break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.fillRule = rule;
- data.path.setWindingRule(rule == SWT.FILL_WINDING ? OS.NSNonZeroWindingRule : OS.NSEvenOddWindingRule);
-}
-
-/**
- * Sets the font which will be used by the receiver
- * to draw and measure text to the argument. If the
- * argument is null, then a default font appropriate
- * for the platform will be used instead.
- *
- * @param font the new font for the receiver, or null to indicate a default font
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setFont(Font font) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.font = font != null ? font : data.device.systemFont;
- data.state &= ~FONT;
-}
-
-/**
- * Sets the foreground color. The foreground color is used
- * for drawing operations including when text is drawn.
- *
- * @param color the new foreground color for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setForeground(Color color) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.foreground = color.handle;
- data.foregroundPattern = null;
- if (data.fg != null) data.fg.release();
- data.fg = null;
- data.state &= ~(FOREGROUND | FOREGROUND_FILL);
-}
-
-/**
- * Sets the foreground pattern. The default value is <code>null</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param pattern the new foreground pattern
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Pattern
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setForegroundPattern(Pattern pattern) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.foregroundPattern == pattern) return;
- data.foregroundPattern = pattern;
- data.state &= ~(FOREGROUND | FOREGROUND_FILL);
-}
-
-/**
- * Sets the receiver's interpolation setting to the parameter, which
- * must be one of <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>,
- * <code>SWT.LOW</code> or <code>SWT.HIGH</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param interpolation the new interpolation setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.NONE</code>, <code>SWT.LOW</code> or <code>SWT.HIGH</code>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setInterpolation(int interpolation) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int quality = 0;
- switch (interpolation) {
- case SWT.DEFAULT: quality = OS.NSImageInterpolationDefault; break;
- case SWT.NONE: quality = OS.NSImageInterpolationNone; break;
- case SWT.LOW: quality = OS.NSImageInterpolationLow; break;
- case SWT.HIGH: quality = OS.NSImageInterpolationHigh; break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- handle.setImageInterpolation(quality);
-}
-
-/**
- * Sets the receiver's line attributes.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param attributes the line attributes
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the attributes is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if any of the line attributes is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see LineAttributes
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.3
- */
-public void setLineAttributes(LineAttributes attributes) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (attributes == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int mask = 0;
- float lineWidth = attributes.width;
- if (lineWidth != data.lineWidth) {
- mask |= LINE_WIDTH | DRAW_OFFSET;
- }
- int lineStyle = attributes.style;
- if (lineStyle != data.lineStyle) {
- mask |= LINE_STYLE;
- switch (lineStyle) {
- case SWT.LINE_SOLID:
- case SWT.LINE_DASH:
- case SWT.LINE_DOT:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- break;
- case SWT.LINE_CUSTOM:
- if (attributes.dash == null) lineStyle = SWT.LINE_SOLID;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- int join = attributes.join;
- if (join != data.lineJoin) {
- mask |= LINE_JOIN;
- switch (join) {
- case SWT.CAP_ROUND:
- case SWT.CAP_FLAT:
- case SWT.CAP_SQUARE:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- int cap = attributes.cap;
- if (cap != data.lineCap) {
- mask |= LINE_CAP;
- switch (cap) {
- case SWT.JOIN_MITER:
- case SWT.JOIN_ROUND:
- case SWT.JOIN_BEVEL:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- float[] dashes = attributes.dash;
- float[] lineDashes = data.lineDashes;
- if (dashes != null && dashes.length > 0) {
- boolean changed = lineDashes == null || lineDashes.length != dashes.length;
- for (int i = 0; i < dashes.length; i++) {
- float dash = dashes[i];
- if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (!changed && lineDashes[i] != dash) changed = true;
- }
- if (changed) {
- float[] newDashes = new float[dashes.length];
- System.arraycopy(dashes, 0, newDashes, 0, dashes.length);
- dashes = newDashes;
- mask |= LINE_STYLE;
- } else {
- dashes = lineDashes;
- }
- } else {
- if (lineDashes != null && lineDashes.length > 0) {
- mask |= LINE_STYLE;
- } else {
- dashes = lineDashes;
- }
- }
- float dashOffset = attributes.dashOffset;
- if (dashOffset != data.lineDashesOffset) {
- mask |= LINE_STYLE;
- }
- float miterLimit = attributes.miterLimit;
- if (miterLimit != data.lineMiterLimit) {
- mask |= LINE_MITERLIMIT;
- }
- if (mask == 0) return;
- data.lineWidth = lineWidth;
- data.lineStyle = lineStyle;
- data.lineCap = cap;
- data.lineJoin = join;
- data.lineDashes = dashes;
- data.lineDashesOffset = dashOffset;
- data.lineMiterLimit = miterLimit;
- data.state &= ~mask;
-}
-
-/**
- * Sets the receiver's line cap style to the argument, which must be one
- * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>,
- * or <code>SWT.CAP_SQUARE</code>.
- *
- * @param cap the cap style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineCap(int cap) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineCap == cap) return;
- switch (cap) {
- case SWT.CAP_ROUND:
- case SWT.CAP_FLAT:
- case SWT.CAP_SQUARE:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineCap = cap;
- data.state &= ~LINE_CAP;
-}
-
-/**
- * Sets the receiver's line dash style to the argument. The default
- * value is <code>null</code>. If the argument is not <code>null</code>,
- * the receiver's line style is set to <code>SWT.LINE_CUSTOM</code>, otherwise
- * it is set to <code>SWT.LINE_SOLID</code>.
- *
- * @param dashes the dash style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if any of the values in the array is less than or equal 0</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineDash(int[] dashes) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float[] lineDashes = data.lineDashes;
- if (dashes != null && dashes.length > 0) {
- boolean changed = data.lineStyle != SWT.LINE_CUSTOM || lineDashes == null || lineDashes.length != dashes.length;
- for (int i = 0; i < dashes.length; i++) {
- int dash = dashes[i];
- if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (!changed && lineDashes[i] != dash) changed = true;
- }
- if (!changed) return;
- data.lineDashes = new float[dashes.length];
- for (int i = 0; i < dashes.length; i++) {
- data.lineDashes[i] = dashes[i];
- }
- data.lineStyle = SWT.LINE_CUSTOM;
- } else {
- if (data.lineStyle == SWT.LINE_SOLID && (lineDashes == null || lineDashes.length == 0)) return;
- data.lineDashes = null;
- data.lineStyle = SWT.LINE_SOLID;
- }
- data.state &= ~LINE_STYLE;
-}
-
-/**
- * Sets the receiver's line join style to the argument, which must be one
- * of the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>,
- * or <code>SWT.JOIN_BEVEL</code>.
- *
- * @param join the join style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineJoin(int join) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineJoin == join) return;
- switch (join) {
- case SWT.JOIN_MITER:
- case SWT.JOIN_ROUND:
- case SWT.JOIN_BEVEL:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineJoin = join;
- data.state &= ~LINE_JOIN;
-}
-
-/**
- * Sets the receiver's line style to the argument, which must be one
- * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
- * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or
- * <code>SWT.LINE_DASHDOTDOT</code>.
- *
- * @param lineStyle the style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setLineStyle(int lineStyle) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineStyle == lineStyle) return;
- switch (lineStyle) {
- case SWT.LINE_SOLID:
- case SWT.LINE_DASH:
- case SWT.LINE_DOT:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- break;
- case SWT.LINE_CUSTOM:
- if (data.lineDashes == null) lineStyle = SWT.LINE_SOLID;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineStyle = lineStyle;
- data.state &= ~LINE_STYLE;
-}
-
-/**
- * Sets the width that will be used when drawing lines
- * for all of the figure drawing operations (that is,
- * <code>drawLine</code>, <code>drawRectangle</code>,
- * <code>drawPolyline</code>, and so forth.
- * <p>
- * Note that line width of zero is used as a hint to
- * indicate that the fastest possible line drawing
- * algorithms should be used. This means that the
- * output may be different from line width one.
- * </p>
- *
- * @param lineWidth the width of a line
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setLineWidth(int lineWidth) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineWidth == lineWidth) return;
- data.lineWidth = lineWidth;
- data.state &= ~(LINE_WIDTH | DRAW_OFFSET);
-}
-
-/**
- * If the argument is <code>true</code>, puts the receiver
- * in a drawing mode where the resulting color in the destination
- * is the <em>exclusive or</em> of the color values in the source
- * and the destination, and if the argument is <code>false</code>,
- * puts the receiver in a drawing mode where the destination color
- * is replaced with the source color value.
- * <p>
- * Note that this mode in fundamentally unsupportable on certain
- * platforms, notably Carbon (Mac OS X). Clients that want their
- * code to run on all platforms need to avoid this method.
- * </p>
- *
- * @param xor if <code>true</code>, then <em>xor</em> mode is used, otherwise <em>source copy</em> mode is used
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @deprecated this functionality is not supported on some platforms
- */
-public void setXORMode(boolean xor) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- data.xorMode = xor;
-}
-
-/**
- * Sets the receiver's text anti-aliasing value to the parameter,
- * which must be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code>
- * or <code>SWT.ON</code>. Note that this controls anti-aliasing only
- * for all <em>text drawing</em> operations.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param antialias the anti-aliasing setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.OFF</code> or <code>SWT.ON</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- * @see #setAntialias
- *
- * @since 3.1
- */
-public void setTextAntialias(int antialias) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (antialias) {
- case SWT.DEFAULT:
- case SWT.OFF:
- case SWT.ON:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.textAntialias = antialias;
-}
-
-/**
- * Sets the transform that is currently being used by the receiver. If
- * the argument is <code>null</code>, the current transform is set to
- * the identity transform.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param transform the transform to set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Transform
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setTransform(Transform transform) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transform != null && transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (transform != null) {
- if (data.transform != null) data.transform.release();
- if (data.inverseTransform != null) data.inverseTransform.release();
- data.transform = ((NSAffineTransform)new NSAffineTransform().alloc()).initWithTransform(transform.handle);
- data.inverseTransform = ((NSAffineTransform)new NSAffineTransform().alloc()).initWithTransform(transform.handle);
- NSAffineTransformStruct struct = data.inverseTransform.transformStruct();
- if ((struct.m11 * struct.m22 - struct.m12 * struct.m21) != 0) {
- data.inverseTransform.invert();
- }
- } else {
- data.transform = data.inverseTransform = null;
- }
- data.state &= ~(TRANSFORM | DRAW_OFFSET);
-}
-
-/**
- * Returns the extent of the given string. No tab
- * expansion or carriage return processing will be performed.
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point stringExtent(String string) {
- return textExtent(string, 0);
-}
-
-/**
- * Returns the extent of the given string. Tab expansion and
- * carriage return processing are performed.
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point textExtent(String string) {
- return textExtent(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
-}
-
-/**
- * Returns the extent of the given string. Tab expansion, line
- * delimiter and mnemonic processing are performed according to
- * the specified flags, which can be a combination of:
- * <dl>
- * <dt><b>DRAW_DELIMITER</b></dt>
- * <dd>draw multiple lines</dd>
- * <dt><b>DRAW_TAB</b></dt>
- * <dd>expand tabs</dd>
- * <dt><b>DRAW_MNEMONIC</b></dt>
- * <dd>underline the mnemonic character</dd>
- * <dt><b>DRAW_TRANSPARENT</b></dt>
- * <dd>transparent background</dd>
- * </dl>
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @param flags the flags specifying how to process the text
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point textExtent(String string, int flags) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- NSAutoreleasePool pool = checkGC(FONT);
- try {
- NSAttributedString str = createString(string, flags, false);
- NSSize size = str.size();
- str.release();
- return new Point((int)size.width, (int)size.height);
- } finally {
- uncheckGC(pool);
- }
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "GC {*DISPOSED*}";
- return "GC {" + handle + "}";
-}
-
-void uncheckGC(NSAutoreleasePool pool) {
- if (data.flippedContext != null && data.restoreContext) {
- NSGraphicsContext.static_restoreGraphicsState();
- data.restoreContext = false;
- }
- NSView view = data.view;
- if (view != null && data.paintRect == null) {
- if (data.thread != Thread.currentThread()) flush();
- }
- if (pool != null) pool.release();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GCData.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GCData.java
deleted file mode 100755
index 9e44658e63..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GCData.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class are descriptions of GCs in terms
- * of unallocated platform-specific data fields.
- * <p>
- * <b>IMPORTANT:</b> This class is <em>not</em> part of the public
- * API for SWT. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms, and should never be called from application code.
- * </p>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noinstantiate This class is not intended to be instantiated by clients.
- */
-public final class GCData {
- public Device device;
- public int style, state = -1;
- public float /*double*/ [] foreground;
- public float /*double*/ [] background;
- public Pattern foregroundPattern;
- public Pattern backgroundPattern;
- public Font font;
- public int alpha = 0xFF;
- public float lineWidth;
- public int lineStyle = SWT.LINE_SOLID;
- public int lineCap = SWT.CAP_FLAT;
- public int lineJoin = SWT.JOIN_MITER;
- public float lineDashesOffset;
- public float[] lineDashes;
- public float lineMiterLimit = 10;
- public boolean xorMode;
- public int antialias = SWT.DEFAULT;
- public int textAntialias = SWT.DEFAULT;
- public int fillRule = SWT.FILL_EVEN_ODD;
- public Image image;
-
- public NSColor fg, bg;
- public float /*double*/ drawXOffset, drawYOffset;
- public NSRect paintRect;
- public NSBezierPath path;
- public NSAffineTransform transform, inverseTransform;
- public NSBezierPath clipPath, visiblePath;
- public int /*long*/ visibleRgn;
- public NSView view;
- public NSSize size;
- public Thread thread;
- public NSGraphicsContext flippedContext;
- public boolean restoreContext;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java
deleted file mode 100755
index 646c5de74b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java
+++ /dev/null
@@ -1,1192 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.cocoa.*;
-import org.eclipse.swt.*;
-import java.io.*;
-
-/**
- * Instances of this class are graphics which have been prepared
- * for display on a specific device. That is, they are ready
- * to paint using methods such as <code>GC.drawImage()</code>
- * and display on widgets with, for example, <code>Button.setImage()</code>.
- * <p>
- * If loaded from a file format that supports it, an
- * <code>Image</code> may have transparency, meaning that certain
- * pixels are specified as being transparent when drawn. Examples
- * of file formats that support transparency are GIF and PNG.
- * </p><p>
- * There are two primary ways to use <code>Images</code>.
- * The first is to load a graphic file from disk and create an
- * <code>Image</code> from it. This is done using an <code>Image</code>
- * constructor, for example:
- * <pre>
- * Image i = new Image(device, "C:\\graphic.bmp");
- * </pre>
- * A graphic file may contain a color table specifying which
- * colors the image was intended to possess. In the above example,
- * these colors will be mapped to the closest available color in
- * SWT. It is possible to get more control over the mapping of
- * colors as the image is being created, using code of the form:
- * <pre>
- * ImageData data = new ImageData("C:\\graphic.bmp");
- * RGB[] rgbs = data.getRGBs();
- * // At this point, rgbs contains specifications of all
- * // the colors contained within this image. You may
- * // allocate as many of these colors as you wish by
- * // using the Color constructor Color(RGB), then
- * // create the image:
- * Image i = new Image(device, data);
- * </pre>
- * <p>
- * Applications which require even greater control over the image
- * loading process should use the support provided in class
- * <code>ImageLoader</code>.
- * </p><p>
- * Application code must explicitly invoke the <code>Image.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see Color
- * @see ImageData
- * @see ImageLoader
- * @see <a href="http://www.eclipse.org/swt/snippets/#image">Image snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, ImageAnalyzer</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Image extends Resource implements Drawable {
-
- /**
- * specifies whether the receiver is a bitmap or an icon
- * (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int type;
-
- /**
- * the handle to the OS image resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public NSImage handle;
-
- /**
- * specifies the transparent pixel
- */
- int transparentPixel = -1;
-
- /**
- * The GC the image is currently selected in.
- */
- GC memGC;
-
- /**
- * The alpha data of the image.
- */
- byte[] alphaData;
-
- /**
- * The global alpha value to be used for every pixel.
- */
- int alpha = -1;
-
- /**
- * The width of the image.
- */
- int width = -1;
-
- /**
- * The height of the image.
- */
- int height = -1;
-
- /**
- * Specifies the default scanline padding.
- */
- static final int DEFAULT_SCANLINE_PAD = 4;
-
-Image(Device device) {
- super(device);
-}
-
-/**
- * Constructs an empty instance of this class with the
- * specified width and height. The result may be drawn upon
- * by creating a GC and using any of its drawing operations,
- * as shown in the following example:
- * <pre>
- * Image i = new Image(device, width, height);
- * GC gc = new GC(i);
- * gc.drawRectangle(0, 0, 50, 50);
- * gc.dispose();
- * </pre>
- * <p>
- * Note: Some platforms may have a limitation on the size
- * of image that can be created (size depends on width, height,
- * and depth). For example, Windows 95, 98, and ME do not allow
- * images larger than 16M.
- * </p>
- *
- * @param device the device on which to create the image
- * @param width the width of the new image
- * @param height the height of the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - if either the width or height is negative or zero</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, int width, int height) {
- super(device);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- init(width, height);
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Constructs a new instance of this class based on the
- * provided image, with an appearance that varies depending
- * on the value of the flag. The possible flag values are:
- * <dl>
- * <dt><b>{@link SWT#IMAGE_COPY}</b></dt>
- * <dd>the result is an identical copy of srcImage</dd>
- * <dt><b>{@link SWT#IMAGE_DISABLE}</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>disabled</em> look</dd>
- * <dt><b>{@link SWT#IMAGE_GRAY}</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>gray scale</em> look</dd>
- * </dl>
- *
- * @param device the device on which to create the image
- * @param srcImage the image to use as the source
- * @param flag the style, either <code>IMAGE_COPY</code>, <code>IMAGE_DISABLE</code> or <code>IMAGE_GRAY</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if srcImage is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the flag is not one of <code>IMAGE_COPY</code>, <code>IMAGE_DISABLE</code> or <code>IMAGE_GRAY</code></li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon, or is otherwise in an invalid state</li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the image is not supported</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, Image srcImage, int flag) {
- super(device);
- if (srcImage == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (srcImage.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- switch (flag) {
- case SWT.IMAGE_COPY:
- case SWT.IMAGE_DISABLE:
- case SWT.IMAGE_GRAY:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- device = this.device;
- this.type = srcImage.type;
- /* Get source image size */
- NSSize size = srcImage.handle.size();
- int width = (int)size.width;
- int height = (int)size.height;
- NSBitmapImageRep srcRep = srcImage.getRepresentation();
- int /*long*/ bpr = srcRep.bytesPerRow();
-
- /* Copy transparent pixel and alpha data when necessary */
- transparentPixel = srcImage.transparentPixel;
- alpha = srcImage.alpha;
- if (srcImage.alphaData != null) {
- alphaData = new byte[srcImage.alphaData.length];
- System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length);
- }
-
- /* Create the image */
- handle = (NSImage)new NSImage().alloc();
- handle = handle.initWithSize(size);
- NSBitmapImageRep rep = (NSBitmapImageRep)new NSBitmapImageRep().alloc();
- rep = rep.initWithBitmapDataPlanes(0, width, height, srcRep.bitsPerSample(), srcRep.samplesPerPixel(), srcRep.samplesPerPixel() == 4, srcRep.isPlanar(), OS.NSDeviceRGBColorSpace, OS.NSAlphaFirstBitmapFormat | OS.NSAlphaNonpremultipliedBitmapFormat, srcRep.bytesPerRow(), srcRep.bitsPerPixel());
- handle.addRepresentation(rep);
- rep.release();
- handle.setCacheMode(OS.NSImageCacheNever);
-
- int /*long*/ data = rep.bitmapData();
- OS.memmove(data, srcRep.bitmapData(), width * height * 4);
- if (flag != SWT.IMAGE_COPY) {
-
- /* Apply transformation */
- switch (flag) {
- case SWT.IMAGE_DISABLE: {
- Color zeroColor = device.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
- RGB zeroRGB = zeroColor.getRGB();
- byte zeroRed = (byte)zeroRGB.red;
- byte zeroGreen = (byte)zeroRGB.green;
- byte zeroBlue = (byte)zeroRGB.blue;
- Color oneColor = device.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
- RGB oneRGB = oneColor.getRGB();
- byte oneRed = (byte)oneRGB.red;
- byte oneGreen = (byte)oneRGB.green;
- byte oneBlue = (byte)oneRGB.blue;
- byte[] line = new byte[(int)/*64*/bpr];
- for (int y=0; y<height; y++) {
- OS.memmove(line, data + (y * bpr), bpr);
- int offset = 0;
- for (int x=0; x<width; x++) {
- int red = line[offset+1] & 0xFF;
- int green = line[offset+2] & 0xFF;
- int blue = line[offset+3] & 0xFF;
- int intensity = red * red + green * green + blue * blue;
- if (intensity < 98304) {
- line[offset+1] = zeroRed;
- line[offset+2] = zeroGreen;
- line[offset+3] = zeroBlue;
- } else {
- line[offset+1] = oneRed;
- line[offset+2] = oneGreen;
- line[offset+3] = oneBlue;
- }
- offset += 4;
- }
- OS.memmove(data + (y * bpr), line, bpr);
- }
- break;
- }
- case SWT.IMAGE_GRAY: {
- byte[] line = new byte[(int)/*64*/bpr];
- for (int y=0; y<height; y++) {
- OS.memmove(line, data + (y * bpr), bpr);
- int offset = 0;
- for (int x=0; x<width; x++) {
- int red = line[offset+1] & 0xFF;
- int green = line[offset+2] & 0xFF;
- int blue = line[offset+3] & 0xFF;
- byte intensity = (byte)((red+red+green+green+green+green+green+blue) >> 3);
- line[offset+1] = line[offset+2] = line[offset+3] = intensity;
- offset += 4;
- }
- OS.memmove(data + (y * bpr), line, bpr);
- }
- break;
- }
- }
- }
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Constructs an empty instance of this class with the
- * width and height of the specified rectangle. The result
- * may be drawn upon by creating a GC and using any of its
- * drawing operations, as shown in the following example:
- * <pre>
- * Image i = new Image(device, boundsRectangle);
- * GC gc = new GC(i);
- * gc.drawRectangle(0, 0, 50, 50);
- * gc.dispose();
- * </pre>
- * <p>
- * Note: Some platforms may have a limitation on the size
- * of image that can be created (size depends on width, height,
- * and depth). For example, Windows 95, 98, and ME do not allow
- * images larger than 16M.
- * </p>
- *
- * @param device the device on which to create the image
- * @param bounds a rectangle specifying the image's width and height (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the bounds rectangle is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, Rectangle bounds) {
- super(device);
- if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- init(bounds.width, bounds.height);
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Constructs an instance of this class from the given
- * <code>ImageData</code>.
- *
- * @param device the device on which to create the image
- * @param data the image data to create the image from (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the image data is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the ImageData is not supported</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, ImageData data) {
- super(device);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- init(data);
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Constructs an instance of this class, whose type is
- * <code>SWT.ICON</code>, from the two given <code>ImageData</code>
- * objects. The two images must be the same size. Pixel transparency
- * in either image will be ignored.
- * <p>
- * The mask image should contain white wherever the icon is to be visible,
- * and black wherever the icon is to be transparent. In addition,
- * the source image should contain black wherever the icon is to be
- * transparent.
- * </p>
- *
- * @param device the device on which to create the icon
- * @param source the color data for the icon
- * @param mask the mask data for the icon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if either the source or mask is null </li>
- * <li>ERROR_INVALID_ARGUMENT - if source and mask are different sizes</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, ImageData source, ImageData mask) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (mask == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (source.width != mask.width || source.height != mask.height) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- mask = ImageData.convertMask(mask);
- ImageData image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad, source.data);
- image.maskPad = mask.scanlinePad;
- image.maskData = mask.data;
- init(image);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Constructs an instance of this class by loading its representation
- * from the specified input stream. Throws an error if an error
- * occurs while loading the image, or if the result is an image
- * of an unsupported type. Application code is still responsible
- * for closing the input stream.
- * <p>
- * This constructor is provided for convenience when loading a single
- * image only. If the stream contains multiple images, only the first
- * one will be loaded. To load multiple images, use
- * <code>ImageLoader.load()</code>.
- * </p><p>
- * This constructor may be used to load a resource as follows:
- * </p>
- * <pre>
- * static Image loadImage (Display display, Class clazz, String string) {
- * InputStream stream = clazz.getResourceAsStream (string);
- * if (stream == null) return null;
- * Image image = null;
- * try {
- * image = new Image (display, stream);
- * } catch (SWTException ex) {
- * } finally {
- * try {
- * stream.close ();
- * } catch (IOException ex) {}
- * }
- * return image;
- * }
- * </pre>
- *
- * @param device the device on which to create the image
- * @param stream the input stream to load the image from
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the stream is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from the stream</li>
- * <li>ERROR_INVALID_IMAGE - if the image stream contains invalid data </li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the image stream describes an image with an unsupported depth</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, InputStream stream) {
- super(device);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- init(new ImageData(stream));
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Constructs an instance of this class by loading its representation
- * from the file with the specified name. Throws an error if an error
- * occurs while loading the image, or if the result is an image
- * of an unsupported type.
- * <p>
- * This constructor is provided for convenience when loading
- * a single image only. If the specified file contains
- * multiple images, only the first one will be used.
- *
- * @param device the device on which to create the image
- * @param filename the name of the file to load the image from
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the file name is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from the file</li>
- * <li>ERROR_INVALID_IMAGE - if the image file contains invalid data </li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the image file describes an image with an unsupported depth</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, String filename) {
- super(device);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- initNative(filename);
- if (this.handle == null) init(new ImageData(filename));
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-void createAlpha () {
- if (transparentPixel == -1 && alpha == -1 && alphaData == null) return;
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSBitmapImageRep imageRep = getRepresentation();
- int /*long*/ height = imageRep.pixelsHigh();
- int /*long*/ bpr = imageRep.bytesPerRow();
- int /*long*/ dataSize = height * bpr;
- byte[] srcData = new byte[(int)/*64*/dataSize];
- OS.memmove(srcData, imageRep.bitmapData(), dataSize);
- if (transparentPixel != -1) {
- for (int i=0; i<dataSize; i+=4) {
- int pixel = ((srcData[i+1] & 0xFF) << 16) | ((srcData[i+2] & 0xFF) << 8) | (srcData[i+3] & 0xFF);
- srcData[i] = (byte)(pixel == transparentPixel ? 0 : 0xFF);
- }
- } else if (alpha != -1) {
- byte a = (byte)this.alpha;
- for (int i=0; i<dataSize; i+=4) {
- srcData[i] = a;
- }
- } else {
- int /*long*/ width = imageRep.pixelsWide();
- int offset = 0, alphaOffset = 0;
- for (int y = 0; y<height; y++) {
- for (int x = 0; x<width; x++) {
- srcData[offset] = alphaData[alphaOffset];
- offset += 4;
- alphaOffset += 1;
- }
- }
- }
-
- // Since we just calculated alpha for the image rep, tell it that it now has an alpha component.
- imageRep.setAlpha(true);
-
- OS.memmove(imageRep.bitmapData(), srcData, dataSize);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-void destroy() {
- if (memGC != null) memGC.dispose();
- handle.release();
- handle = null;
- memGC = null;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Image)) return false;
- Image image = (Image)object;
- return device == image.device && handle == image.handle &&
- transparentPixel == image.transparentPixel;
-}
-
-/**
- * Returns the color to which to map the transparent pixel, or null if
- * the receiver has no transparent pixel.
- * <p>
- * There are certain uses of Images that do not support transparency
- * (for example, setting an image into a button or label). In these cases,
- * it may be desired to simulate transparency by using the background
- * color of the widget to paint the transparent pixels of the image.
- * Use this method to check which color will be used in these cases
- * in place of transparency. This value may be set with setBackground().
- * <p>
- *
- * @return the background color of the image, or null if there is no transparency in the image
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getBackground() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transparentPixel == -1) return null;
- int red = (transparentPixel >> 16) & 0xFF;
- int green = (transparentPixel >> 8) & 0xFF;
- int blue = (transparentPixel >> 0) & 0xFF;
- return Color.cocoa_new(device, new float /*double*/ []{red / 255f, green / 255f, blue / 255f, 1});
-}
-
-/**
- * Returns the bounds of the receiver. The rectangle will always
- * have x and y values of 0, and the width and height of the
- * image.
- *
- * @return a rectangle specifying the image's bounds
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li>
- * </ul>
- */
-public Rectangle getBounds() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- if (width != -1 && height != -1) {
- return new Rectangle(0, 0, width, height);
- }
- NSSize size = handle.size();
- return new Rectangle(0, 0, width = (int)size.width, height = (int)size.height);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns an <code>ImageData</code> based on the receiver
- * Modifications made to this <code>ImageData</code> will not
- * affect the Image.
- *
- * @return an <code>ImageData</code> containing the image's data and attributes
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li>
- * </ul>
- *
- * @see ImageData
- */
-public ImageData getImageData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSBitmapImageRep imageRep = getRepresentation();
- int /*long*/ width = imageRep.pixelsWide();
- int /*long*/ height = imageRep.pixelsHigh();
- int /*long*/ bpr = imageRep.bytesPerRow();
- int /*long*/ bpp = imageRep.bitsPerPixel();
- int /*long*/ dataSize = height * bpr;
-
- byte[] srcData = new byte[(int)/*64*/dataSize];
- OS.memmove(srcData, imageRep.bitmapData(), dataSize);
-
- PaletteData palette = new PaletteData(0xFF0000, 0xFF00, 0xFF);
- ImageData data = new ImageData((int)/*64*/width, (int)/*64*/height, (int)/*64*/bpp, palette, 4, srcData);
- data.bytesPerLine = (int)/*64*/bpr;
-
- data.transparentPixel = transparentPixel;
- if (transparentPixel == -1 && type == SWT.ICON) {
- /* Get the icon mask data */
- int maskPad = 2;
- int /*long*/ maskBpl = (((width + 7) / 8) + (maskPad - 1)) / maskPad * maskPad;
- byte[] maskData = new byte[(int)/*64*/(height * maskBpl)];
- int offset = 0, maskOffset = 0;
- for (int y = 0; y<height; y++) {
- for (int x = 0; x<width; x++) {
- if (srcData[offset] != 0) {
- maskData[maskOffset + (x >> 3)] |= (1 << (7 - (x & 0x7)));
- } else {
- maskData[maskOffset + (x >> 3)] &= ~(1 << (7 - (x & 0x7)));
- }
- offset += 4;
- }
- maskOffset += maskBpl;
- }
- data.maskData = maskData;
- data.maskPad = maskPad;
- }
- for (int i = 0; i < srcData.length; i+= 4) {
- srcData[i] = 0;
- }
- data.alpha = alpha;
- if (alpha == -1 && alphaData != null) {
- data.alphaData = new byte[alphaData.length];
- System.arraycopy(alphaData, 0, data.alphaData, 0, alphaData.length);
- }
- return data;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Invokes platform specific functionality to allocate a new image.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param type the type of the image (<code>SWT.BITMAP</code> or <code>SWT.ICON</code>)
- * @param handle the OS handle for the image
- * @param data the OS data for the image
- *
- * @private
- */
-public static Image cocoa_new(Device device, int type, NSImage nsImage) {
- Image image = new Image(device);
- image.type = type;
- image.handle = nsImage;
- return image;
-}
-
-NSBitmapImageRep getRepresentation () {
- NSImageRep rep = handle.bestRepresentationForDevice(null);
- if (!rep.isKindOfClass(OS.class_NSBitmapImageRep)) {
- SWT.error(SWT.ERROR_UNSPECIFIED);
- }
- return new NSBitmapImageRep(rep);
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return handle != null ? (int)/*64*/handle.id : 0;
-}
-
-void init(int width, int height) {
- if (width <= 0 || height <= 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.type = SWT.BITMAP;
- this.width = width;
- this.height = height;
-
- handle = (NSImage)new NSImage().alloc();
- NSSize size = new NSSize();
- size.width = width;
- size.height = height;
- handle = handle.initWithSize(size);
- NSBitmapImageRep rep = (NSBitmapImageRep)new NSBitmapImageRep().alloc();
- rep = rep.initWithBitmapDataPlanes(0, width, height, 8, 3, false, false, OS.NSDeviceRGBColorSpace, OS.NSAlphaFirstBitmapFormat | OS.NSAlphaNonpremultipliedBitmapFormat, width * 4, 32);
- OS.memset(rep.bitmapData(), 0xFF, width * height * 4);
- handle.addRepresentation(rep);
- rep.release();
- handle.setCacheMode(OS.NSImageCacheNever);
-}
-
-void init(ImageData image) {
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.width = image.width;
- this.height = image.height;
- PaletteData palette = image.palette;
- if (!(((image.depth == 1 || image.depth == 2 || image.depth == 4 || image.depth == 8) && !palette.isDirect) ||
- ((image.depth == 8) || (image.depth == 16 || image.depth == 24 || image.depth == 32) && palette.isDirect)))
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
-
- /* Create the image */
- int dataSize = width * height * 4;
-
- /* Initialize data */
- int bpr = width * 4;
- byte[] buffer = new byte[dataSize];
- if (palette.isDirect) {
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, image.getByteOrder(), 0, 0, width, height, palette.redMask, palette.greenMask, palette.blueMask,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- buffer, 32, bpr, ImageData.MSB_FIRST, 0, 0, width, height, 0xFF0000, 0xFF00, 0xFF,
- false, false);
- } else {
- RGB[] rgbs = palette.getRGBs();
- int length = rgbs.length;
- byte[] srcReds = new byte[length];
- byte[] srcGreens = new byte[length];
- byte[] srcBlues = new byte[length];
- for (int i = 0; i < rgbs.length; i++) {
- RGB rgb = rgbs[i];
- if (rgb == null) continue;
- srcReds[i] = (byte)rgb.red;
- srcGreens[i] = (byte)rgb.green;
- srcBlues[i] = (byte)rgb.blue;
- }
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, image.getByteOrder(), 0, 0, width, height, srcReds, srcGreens, srcBlues,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- buffer, 32, bpr, ImageData.MSB_FIRST, 0, 0, width, height, 0xFF0000, 0xFF00, 0xFF,
- false, false);
- }
-
- /* Initialize transparency */
- int transparency = image.getTransparencyType();
- boolean hasAlpha = transparency != SWT.TRANSPARENCY_NONE;
- if (transparency == SWT.TRANSPARENCY_MASK || image.transparentPixel != -1) {
- this.type = image.transparentPixel != -1 ? SWT.BITMAP : SWT.ICON;
- if (image.transparentPixel != -1) {
- int transRed = 0, transGreen = 0, transBlue = 0;
- if (palette.isDirect) {
- RGB rgb = palette.getRGB(image.transparentPixel);
- transRed = rgb.red;
- transGreen = rgb.green;
- transBlue = rgb.blue;
- } else {
- RGB[] rgbs = palette.getRGBs();
- if (image.transparentPixel < rgbs.length) {
- RGB rgb = rgbs[image.transparentPixel];
- transRed = rgb.red;
- transGreen = rgb.green;
- transBlue = rgb.blue;
- }
- }
- transparentPixel = transRed << 16 | transGreen << 8 | transBlue;
- }
- ImageData maskImage = image.getTransparencyMask();
- byte[] maskData = maskImage.data;
- int maskBpl = maskImage.bytesPerLine;
- int offset = 0, maskOffset = 0;
- for (int y = 0; y<height; y++) {
- for (int x = 0; x<width; x++) {
- buffer[offset] = ((maskData[maskOffset + (x >> 3)]) & (1 << (7 - (x & 0x7)))) != 0 ? (byte)0xff : 0;
- offset += 4;
- }
- maskOffset += maskBpl;
- }
- } else {
- this.type = SWT.BITMAP;
- if (image.alpha != -1) {
- hasAlpha = true;
- this.alpha = image.alpha;
- byte a = (byte)this.alpha;
- for (int dataIndex=0; dataIndex<buffer.length; dataIndex+=4) {
- buffer[dataIndex] = a;
- }
- } else if (image.alphaData != null) {
- hasAlpha = true;
- this.alphaData = new byte[image.alphaData.length];
- System.arraycopy(image.alphaData, 0, this.alphaData, 0, alphaData.length);
- int offset = 0, alphaOffset = 0;
- for (int y = 0; y<height; y++) {
- for (int x = 0; x<width; x++) {
- buffer[offset] = alphaData[alphaOffset];
- offset += 4;
- alphaOffset += 1;
- }
- }
- }
- }
-
- if (handle != null) handle.release();
-
- handle = (NSImage)new NSImage().alloc();
- NSSize size = new NSSize();
- size.width = width;
- size.height = height;
- handle = handle.initWithSize(size);
- NSBitmapImageRep rep = (NSBitmapImageRep)new NSBitmapImageRep().alloc();
- rep = rep.initWithBitmapDataPlanes(0, width, height, 8, hasAlpha ? 4 : 3, hasAlpha, false, OS.NSDeviceRGBColorSpace, OS.NSAlphaFirstBitmapFormat | OS.NSAlphaNonpremultipliedBitmapFormat, bpr, 32);
- OS.memmove(rep.bitmapData(), buffer, dataSize);
- handle.addRepresentation(rep);
- rep.release();
- handle.setCacheMode(OS.NSImageCacheNever);
-}
-
-void initNative(String filename) {
- NSAutoreleasePool pool = null;
- NSImage nativeImage = null;
-
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- nativeImage = new NSImage();
- nativeImage.alloc();
-
- // initByReferencingFile returns null if the file can't be found or is
- // not an image.
- nativeImage = nativeImage.initWithContentsOfFile(NSString.stringWith(filename));
- if (nativeImage == null) {
- // In order to get the same kind of exception, let the file format try to load and throw
- // the appropriate exception. It is possible file format supports some image formats
- // that is not natively supported as well.
- return;
- }
-
- NSImageRep nativeRep = nativeImage.bestRepresentationForDevice(null);
- if (!nativeRep.isKindOfClass(OS.class_NSBitmapImageRep)) {
- return;
- }
-
- width = (int)/*64*/nativeRep.pixelsWide();
- height = (int)/*64*/nativeRep.pixelsHigh();
-
- boolean hasAlpha = nativeRep.hasAlpha();
- int bpr = width * 4;
- handle = (NSImage)new NSImage().alloc();
- NSSize size = new NSSize();
- size.width = width;
- size.height = height;
- handle = handle.initWithSize(size);
- NSBitmapImageRep rep = (NSBitmapImageRep)new NSBitmapImageRep().alloc();
- rep = rep.initWithBitmapDataPlanes(0, width, height, 8, hasAlpha ? 4 : 3, hasAlpha, false, OS.NSDeviceRGBColorSpace, OS.NSAlphaFirstBitmapFormat | OS.NSAlphaNonpremultipliedBitmapFormat, bpr, 32);
- handle.addRepresentation(rep);
- rep.release();
- handle.setCacheMode(OS.NSImageCacheNever);
- NSRect rect = new NSRect();
- rect.width = width;
- rect.height = height;
-
- /* Compute the pixels */
- int /*long*/ colorspace = OS.CGColorSpaceCreateDeviceRGB();
- int /*long*/ ctx = OS.CGBitmapContextCreate(rep.bitmapData(), width, height, 8, bpr, colorspace, OS.kCGImageAlphaNoneSkipFirst);
- OS.CGColorSpaceRelease(colorspace);
- NSGraphicsContext.static_saveGraphicsState();
- NSGraphicsContext.setCurrentContext(NSGraphicsContext.graphicsContextWithGraphicsPort(ctx, false));
- if (hasAlpha) OS.objc_msgSend(nativeRep.id, OS.sel_setAlpha_, 0);
- nativeRep.drawInRect(rect);
- if (hasAlpha) OS.objc_msgSend(nativeRep.id, OS.sel_setAlpha_, 1);
- NSGraphicsContext.static_restoreGraphicsState();
- OS.CGContextRelease(ctx);
-
- if (hasAlpha) {
- /* Compute the alpha values */
- int /*long*/ bitmapBytesPerRow = width;
- int /*long*/ bitmapByteCount = bitmapBytesPerRow * height;
- int /*long*/ alphaBitmapData = OS.malloc(bitmapByteCount);
- int /*long*/ alphaBitmapCtx = OS.CGBitmapContextCreate(alphaBitmapData, width, height, 8, bitmapBytesPerRow, 0, OS.kCGImageAlphaOnly);
- NSGraphicsContext.static_saveGraphicsState();
- NSGraphicsContext.setCurrentContext(NSGraphicsContext.graphicsContextWithGraphicsPort(alphaBitmapCtx, false));
- nativeRep.drawInRect(rect);
- NSGraphicsContext.static_restoreGraphicsState();
- byte[] alphaData = new byte[(int)/*64*/bitmapByteCount];
- OS.memmove(alphaData, alphaBitmapData, bitmapByteCount);
- OS.free(alphaBitmapData);
- OS.CGContextRelease(alphaBitmapCtx);
-
- /* Merge the alpha values with the pixels */
- byte[] srcData = new byte[height * bpr];
- OS.memmove(srcData, rep.bitmapData(), srcData.length);
- for (int a = 0, p = 0; a < alphaData.length; a++, p += 4) {
- srcData[p] = alphaData[a];
- }
- OS.memmove(rep.bitmapData(), srcData, srcData.length);
-
- // If the alpha has only 0 or 255 (-1) for alpha values, compute the transparent pixel color instead
- // of a continuous alpha range.
- int transparentOffset = -1, i = 0;
- for (i = 0; i < alphaData.length; i++) {
- int alpha = alphaData[i];
- if (transparentOffset == -1 && alpha == 0) transparentOffset = i;
- if (!(alpha == 0 || alpha == -1)) break;
- }
- this.alpha = -1;
- if (i == alphaData.length && transparentOffset != -1) {
- NSColor color = rep.colorAtX(transparentOffset % width, transparentOffset / width);
- int red = (int) (color.redComponent() * 255);
- int green = (int) (color.greenComponent() * 255);
- int blue = (int) (color.blueComponent() * 255);
- this.transparentPixel = (red << 16) + (green << 8) + blue;
- } else {
- this.alphaData = alphaData;
- }
- }
-
- // For compatibility, images created from .ico files are treated as SWT.ICON format, even though
- // they are no different than other bitmaps in Cocoa.
- if (filename.toLowerCase().endsWith(".ico")) {
- this.type = SWT.ICON;
- } else {
- this.type = SWT.BITMAP;
- }
- } finally {
- if (nativeImage != null) nativeImage.release();
- if (pool != null) pool.release();
- }
-
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public int /*long*/ internal_new_GC (GCData data) {
- if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (type != SWT.BITMAP || memGC != null) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSBitmapImageRep imageRep = getRepresentation();
-
- // Can't perform transforms on image reps with alpha.
- imageRep.setAlpha(false);
-
- NSGraphicsContext context = NSGraphicsContext.graphicsContextWithBitmapImageRep(imageRep);
- NSGraphicsContext flippedContext = NSGraphicsContext.graphicsContextWithGraphicsPort(context.graphicsPort(), true);
- context = flippedContext;
- context.retain();
- if (data != null) data.flippedContext = flippedContext;
- NSGraphicsContext.static_saveGraphicsState();
- NSGraphicsContext.setCurrentContext(context);
- NSAffineTransform transform = NSAffineTransform.transform();
- NSSize size = handle.size();
- transform.translateXBy(0, size.height);
- transform.scaleXBy(1, -1);
- transform.set();
- NSGraphicsContext.static_restoreGraphicsState();
- if (data != null) {
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) == 0) {
- data.style |= SWT.LEFT_TO_RIGHT;
- }
- data.device = device;
- data.background = device.COLOR_WHITE.handle;
- data.foreground = device.COLOR_BLACK.handle;
- data.font = device.systemFont;
- data.image = this;
- }
- return context.id;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int /*long*/ context, GCData data) {
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- if (context != 0) {
- NSGraphicsContext contextObj = new NSGraphicsContext(context);
- contextObj.release();
- }
-// handle.setCacheMode(OS.NSImageCacheDefault);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns <code>true</code> if the image has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the image.
- * When an image has been disposed, it is an error to
- * invoke any other method using the image.
- *
- * @return <code>true</code> when the image is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == null;
-}
-
-/**
- * Sets the color to which to map the transparent pixel.
- * <p>
- * There are certain uses of <code>Images</code> that do not support
- * transparency (for example, setting an image into a button or label).
- * In these cases, it may be desired to simulate transparency by using
- * the background color of the widget to paint the transparent pixels
- * of the image. This method specifies the color that will be used in
- * these cases. For example:
- * <pre>
- * Button b = new Button();
- * image.setBackground(b.getBackground());
- * b.setImage(image);
- * </pre>
- * </p><p>
- * The image may be modified by this operation (in effect, the
- * transparent regions may be filled with the supplied color). Hence
- * this operation is not reversible and it is not legal to call
- * this function twice or with a null argument.
- * </p><p>
- * This method has no effect if the receiver does not have a transparent
- * pixel value.
- * </p>
- *
- * @param color the color to use when a transparent pixel is specified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setBackground(Color color) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (transparentPixel == -1) return;
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- byte red = (byte)((transparentPixel >> 16) & 0xFF);
- byte green = (byte)((transparentPixel >> 8) & 0xFF);
- byte blue = (byte)((transparentPixel >> 0) & 0xFF);
- byte newRed = (byte)((int)(color.handle[0] * 255) & 0xFF);
- byte newGreen = (byte)((int)(color.handle[1] * 255) & 0xFF);
- byte newBlue = (byte)((int)(color.handle[2] * 255) & 0xFF);
- NSBitmapImageRep imageRep = getRepresentation();
- int /*long*/ bpr = imageRep.bytesPerRow();
- int /*long*/ data = imageRep.bitmapData();
- byte[] line = new byte[(int)bpr];
- for (int i = 0, offset = 0; i < height; i++, offset += bpr) {
- OS.memmove(line, data + offset, bpr);
- for (int j = 0; j < line.length; j += 4) {
- if (line[j+ 1] == red && line[j + 2] == green && line[j + 3] == blue) {
- line[j + 1] = newRed;
- line[j + 2] = newGreen;
- line[j + 3] = newBlue;
- }
- }
- OS.memmove(data + offset, line, bpr);
- }
- transparentPixel = (newRed & 0xFF) << 16 | (newGreen & 0xFF) << 8 | (newBlue & 0xFF);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Image {*DISPOSED*}";
- return "Image {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Path.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Path.java
deleted file mode 100755
index 7ab8a8b4ea..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Path.java
+++ /dev/null
@@ -1,759 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class represent paths through the two-dimensional
- * coordinate system. Paths do not have to be continuous, and can be
- * described using lines, rectangles, arcs, cubic or quadratic bezier curves,
- * glyphs, or other paths.
- * <p>
- * Application code must explicitly invoke the <code>Path.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#path">Path, Pattern snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Path extends Resource {
-
- /**
- * the OS resource for the Path
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public NSBezierPath handle;
-
-/**
- * Constructs a new empty Path.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the path
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Path (Device device) {
- super(device);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- handle = NSBezierPath.bezierPath();
- if (handle == null) SWT.error(SWT.ERROR_NO_HANDLES);
- handle.retain();
- handle.moveToPoint(new NSPoint());
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Constructs a new Path that is a copy of <code>path</code>. If
- * <code>flatness</code> is less than or equal to zero, an unflatten
- * copy of the path is created. Otherwise, it specifies the maximum
- * error between the path and its flatten copy. Smaller numbers give
- * better approximation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the path
- * @param path the path to make a copy
- * @param flatness the flatness value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the path is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the path has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- * @since 3.4
- */
-public Path (Device device, Path path, float flatness) {
- super(device);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- flatness = Math.max(0, flatness);
- if (flatness == 0) {
- handle = new NSBezierPath(path.handle.copy().id);
- } else {
- float /*double*/ defaultFlatness = NSBezierPath.defaultFlatness();
- NSBezierPath.setDefaultFlatness(flatness);
- handle = path.handle.bezierPathByFlatteningPath();
- handle.retain();
- NSBezierPath.setDefaultFlatness(defaultFlatness);
- }
- if (handle == null) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Constructs a new Path with the specifed PathData.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the path
- * @param data the data for the path
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the data is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- * @since 3.4
- */
-public Path (Device device, PathData data) {
- this(device);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(data);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Adds to the receiver a circular or elliptical arc that lies within
- * the specified rectangular area.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc
- * @param y the y coordinate of the upper-left corner of the arc
- * @param width the width of the arc
- * @param height the height of the arc
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addArc(float x, float y, float width, float height, float startAngle, float arcAngle) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSAffineTransform transform = NSAffineTransform.transform();
- transform.translateXBy(x + width / 2f, y + height / 2f);
- transform.scaleXBy(width / 2f, height / 2f);
- NSBezierPath path = NSBezierPath.bezierPath();
- NSPoint center = new NSPoint();
- float sAngle = -startAngle;
- float eAngle = -(startAngle + arcAngle);
- path.appendBezierPathWithArcWithCenter(center, 1, sAngle, eAngle, arcAngle>0);
- path.transformUsingAffineTransform(transform);
- handle.appendBezierPath(path);
- if (Math.abs(arcAngle) >= 360) handle.closePath();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Adds to the receiver the path described by the parameter.
- *
- * @param path the path to add to the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addPath(Path path) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- handle.appendBezierPath(path.handle);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Adds to the receiver the rectangle specified by x, y, width and height.
- *
- * @param x the x coordinate of the rectangle to add
- * @param y the y coordinate of the rectangle to add
- * @param width the width of the rectangle to add
- * @param height the height of the rectangle to add
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addRectangle(float x, float y, float width, float height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSRect rect = new NSRect();
- rect.x = x;
- rect.y = y;
- rect.width = width;
- rect.height = height;
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- handle.appendBezierPathWithRect(rect);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Adds to the receiver the pattern of glyphs generated by drawing
- * the given string using the given font starting at the point (x, y).
- *
- * @param string the text to use
- * @param x the x coordinate of the starting point
- * @param y the y coordinate of the starting point
- * @param font the font to use
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the font is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addString(String string, float x, float y, Font font) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (font == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSString str = NSString.stringWith(string);
- NSTextStorage textStorage = (NSTextStorage)new NSTextStorage().alloc().init();
- NSLayoutManager layoutManager = (NSLayoutManager)new NSLayoutManager().alloc().init();
- NSTextContainer textContainer = (NSTextContainer)new NSTextContainer().alloc();
- NSSize size = new NSSize();
- size.width = Float.MAX_VALUE;
- size.height = Float.MAX_VALUE;
- textContainer.initWithContainerSize(size);
- textStorage.addLayoutManager(layoutManager);
- layoutManager.addTextContainer(textContainer);
- NSRange range = new NSRange();
- range.length = str.length();
- /*
- * Feature in Cocoa. Adding attributes directly to a NSTextStorage causes
- * output to the console and eventually a segmentation fault when printing
- * on a thread other than the main thread. The fix is to add attributes to
- * a separate NSMutableAttributedString and add it to text storage when done.
- */
- NSMutableAttributedString attrStr = (NSMutableAttributedString)new NSMutableAttributedString().alloc();
- attrStr.id = attrStr.initWithString(str).id;
- attrStr.beginEditing();
- attrStr.addAttribute(OS.NSFontAttributeName, font.handle, range);
- font.addTraits(attrStr, range);
- attrStr.endEditing();
- textStorage.setAttributedString(attrStr);
- attrStr.release();
- range = layoutManager.glyphRangeForTextContainer(textContainer);
- if (range.length != 0) {
- int /*long*/ glyphs = OS.malloc(4 * range.length * 2);
- layoutManager.getGlyphs(glyphs, range);
- NSBezierPath path = NSBezierPath.bezierPath();
- NSPoint point = new NSPoint();
- path.moveToPoint(point);
- path.appendBezierPathWithGlyphs(glyphs, range.length, font.handle);
- NSAffineTransform transform = NSAffineTransform.transform();
- transform.scaleXBy(1, -1);
- float /*double*/ baseline = layoutManager.defaultBaselineOffsetForFont(font.handle);
- transform.translateXBy(x, -(y + baseline));
- path.transformUsingAffineTransform(transform);
- OS.free(glyphs);
- handle.appendBezierPath(path);
- }
- textContainer.release();
- layoutManager.release();
- textStorage.release();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Closes the current sub path by adding to the receiver a line
- * from the current point of the path back to the starting point
- * of the sub path.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void close() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- handle.closePath();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns <code>true</code> if the specified point is contained by
- * the receiver and false otherwise.
- * <p>
- * If outline is <code>true</code>, the point (x, y) checked for containment in
- * the receiver's outline. If outline is <code>false</code>, the point is
- * checked to see if it is contained within the bounds of the (closed) area
- * covered by the receiver.
- *
- * @param x the x coordinate of the point to test for containment
- * @param y the y coordinate of the point to test for containment
- * @param gc the GC to use when testing for containment
- * @param outline controls whether to check the outline or contained area of the path
- * @return <code>true</code> if the path contains the point and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains(float x, float y, GC gc, boolean outline) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- //TODO - see windows
- if (outline) {
- int /*long*/ pixel = OS.malloc(4);
- if (pixel == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int[] buffer = new int[]{0xFFFFFFFF};
- OS.memmove(pixel, buffer, 4);
- int /*long*/ colorspace = OS.CGColorSpaceCreateDeviceRGB();
- int /*long*/ context = OS.CGBitmapContextCreate(pixel, 1, 1, 8, 4, colorspace, OS.kCGImageAlphaNoneSkipFirst);
- OS.CGColorSpaceRelease(colorspace);
- if (context == 0) {
- OS.free(pixel);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- GCData data = gc.data;
- int capStyle = 0;
- switch (data.lineCap) {
- case SWT.CAP_ROUND: capStyle = OS.kCGLineCapRound; break;
- case SWT.CAP_FLAT: capStyle = OS.kCGLineCapButt; break;
- case SWT.CAP_SQUARE: capStyle = OS.kCGLineCapSquare; break;
- }
- OS.CGContextSetLineCap(context, capStyle);
- int joinStyle = 0;
- switch (data.lineJoin) {
- case SWT.JOIN_MITER: joinStyle = OS.kCGLineJoinMiter; break;
- case SWT.JOIN_ROUND: joinStyle = OS.kCGLineJoinRound; break;
- case SWT.JOIN_BEVEL: joinStyle = OS.kCGLineJoinBevel; break;
- }
- OS.CGContextSetLineJoin(context, joinStyle);
- OS.CGContextSetLineWidth(context, data.lineWidth);
- OS.CGContextTranslateCTM(context, -x + 0.5f, -y + 0.5f);
- int /*long*/ path = GC.createCGPathRef(handle);
- OS.CGContextAddPath(context, path);
- OS.CGPathRelease(path);
- OS.CGContextStrokePath(context);
- OS.CGContextRelease(context);
- OS.memmove(buffer, pixel, 4);
- OS.free(pixel);
- return buffer[0] != 0xFFFFFFFF;
- } else {
- NSPoint point = new NSPoint();
- point.x = x;
- point.y = y;
- return handle.containsPoint(point);
- }
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Adds to the receiver a cubic bezier curve based on the parameters.
- *
- * @param cx1 the x coordinate of the first control point of the spline
- * @param cy1 the y coordinate of the first control of the spline
- * @param cx2 the x coordinate of the second control of the spline
- * @param cy2 the y coordinate of the second control of the spline
- * @param x the x coordinate of the end point of the spline
- * @param y the y coordinate of the end point of the spline
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSPoint pt = new NSPoint();
- pt.x = x;
- pt.y = y;
- NSPoint ct1 = new NSPoint();
- ct1.x = cx1;
- ct1.y = cy1;
- NSPoint ct2 = new NSPoint();
- ct2.x = cx2;
- ct2.y = cy2;
- handle.curveToPoint(pt, ct1, ct2);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-void destroy() {
- handle.release();
- handle = null;
-}
-
-/**
- * Replaces the first four elements in the parameter with values that
- * describe the smallest rectangle that will completely contain the
- * receiver (i.e. the bounding box).
- *
- * @param bounds the array to hold the result
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the bounding box</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getBounds(float[] bounds) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (bounds.length < 4) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSRect rect = handle.controlPointBounds();
- bounds[0] = (float)/*64*/rect.x;
- bounds[1] = (float)/*64*/rect.y;
- bounds[2] = (float)/*64*/rect.width;
- bounds[3] = (float)/*64*/rect.height;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Replaces the first two elements in the parameter with values that
- * describe the current point of the path.
- *
- * @param point the array to hold the result
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the end point</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getCurrentPoint(float[] point) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (point == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (point.length < 2) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSPoint pt = handle.currentPoint();
- point[0] = (float)/*64*/pt.x;
- point[1] = (float)/*64*/pt.y;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns a device independent representation of the receiver.
- *
- * @return the PathData for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see PathData
- */
-public PathData getPathData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- int count = (int)/*64*/handle.elementCount();
- int pointCount = 0, typeCount = 0;
- byte[] types = new byte[count];
- float[] pointArray = new float[count * 6];
- int /*long*/ points = OS.malloc(3 * NSPoint.sizeof);
- if (points == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- NSPoint pt = new NSPoint();
- for (int i = 0; i < count; i++) {
- int element = (int)/*64*/handle.elementAtIndex(i, points);
- switch (element) {
- case OS.NSMoveToBezierPathElement:
- types[typeCount++] = SWT.PATH_MOVE_TO;
- OS.memmove(pt, points, NSPoint.sizeof);
- pointArray[pointCount++] = (int)pt.x;
- pointArray[pointCount++] = (int)pt.y;
- break;
- case OS.NSLineToBezierPathElement:
- types[typeCount++] = SWT.PATH_LINE_TO;
- OS.memmove(pt, points, NSPoint.sizeof);
- pointArray[pointCount++] = (int)pt.x;
- pointArray[pointCount++] = (int)pt.y;
- break;
- case OS.NSCurveToBezierPathElement:
- types[typeCount++] = SWT.PATH_CUBIC_TO;
- OS.memmove(pt, points, NSPoint.sizeof);
- pointArray[pointCount++] = (int)pt.x;
- pointArray[pointCount++] = (int)pt.y;
- OS.memmove(pt, points + NSPoint.sizeof, NSPoint.sizeof);
- pointArray[pointCount++] = (int)pt.x;
- pointArray[pointCount++] = (int)pt.y;
- OS.memmove(pt, points + NSPoint.sizeof + NSPoint.sizeof, NSPoint.sizeof);
- pointArray[pointCount++] = (int)pt.x;
- pointArray[pointCount++] = (int)pt.y;
- break;
- case OS.NSClosePathBezierPathElement:
- types[typeCount++] = SWT.PATH_CLOSE;
- break;
- }
- }
- OS.free(points);
- if (pointCount != pointArray.length) {
- float[] temp = new float[pointCount];
- System.arraycopy(pointArray, 0, temp, 0, pointCount);
- pointArray = temp;
- }
- PathData data = new PathData();
- data.types = types;
- data.points = pointArray;
- return data;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-void init(PathData data) {
- byte[] types = data.types;
- float[] points = data.points;
- for (int i = 0, j = 0; i < types.length; i++) {
- switch (types[i]) {
- case SWT.PATH_MOVE_TO:
- moveTo(points[j++], points[j++]);
- break;
- case SWT.PATH_LINE_TO:
- lineTo(points[j++], points[j++]);
- break;
- case SWT.PATH_CUBIC_TO:
- cubicTo(points[j++], points[j++], points[j++], points[j++], points[j++], points[j++]);
- break;
- case SWT.PATH_QUAD_TO:
- quadTo(points[j++], points[j++], points[j++], points[j++]);
- break;
- case SWT.PATH_CLOSE:
- close();
- break;
- default:
- dispose();
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
-}
-
-/**
- * Returns <code>true</code> if the Path has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Path.
- * When a Path has been disposed, it is an error to
- * invoke any other method using the Path.
- *
- * @return <code>true</code> when the Path is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == null;
-}
-
-/**
- * Adds to the receiver a line from the current point to
- * the point specified by (x, y).
- *
- * @param x the x coordinate of the end of the line to add
- * @param y the y coordinate of the end of the line to add
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void lineTo(float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSPoint pt = new NSPoint();
- pt.x = x;
- pt.y = y;
- handle.lineToPoint(pt);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Sets the current point of the receiver to the point
- * specified by (x, y). Note that this starts a new
- * sub path.
- *
- * @param x the x coordinate of the new end point
- * @param y the y coordinate of the new end point
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void moveTo(float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSPoint pt = new NSPoint();
- pt.x = x;
- pt.y = y;
- handle.moveToPoint(pt);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Adds to the receiver a quadratic curve based on the parameters.
- *
- * @param cx the x coordinate of the control point of the spline
- * @param cy the y coordinate of the control point of the spline
- * @param x the x coordinate of the end point of the spline
- * @param y the y coordinate of the end point of the spline
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void quadTo(float cx, float cy, float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSPoint pt = new NSPoint();
- pt.x = x;
- pt.y = y;
- NSPoint ct = new NSPoint();
- ct.x = cx;
- ct.y = cy;
- handle.curveToPoint(pt, ct, ct);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Path {*DISPOSED*}";
- return "Path {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Pattern.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Pattern.java
deleted file mode 100755
index 1670e9ab87..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Pattern.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class represent patterns to use while drawing. Patterns
- * can be specified either as bitmaps or gradients.
- * <p>
- * Application code must explicitly invoke the <code>Pattern.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#path">Path, Pattern snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Pattern extends Resource {
- NSColor color;
- NSGradient gradient;
- NSPoint pt1, pt2;
- Image image;
- float /*double*/ [] color1, color2;
- int alpha1, alpha2;
-
-/**
- * Constructs a new Pattern given an image. Drawing with the resulting
- * pattern will cause the image to be tiled over the resulting area.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the pattern
- * @param image the image that the pattern will draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device, or the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Pattern(Device device, Image image) {
- super(device);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- this.image = image;
- color = NSColor.colorWithPatternImage(image.handle);
- color.retain();
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Constructs a new Pattern that represents a linear, two color
- * gradient. Drawing with the pattern will cause the resulting area to be
- * tiled with the gradient specified by the arguments.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the pattern
- * @param x1 the x coordinate of the starting corner of the gradient
- * @param y1 the y coordinate of the starting corner of the gradient
- * @param x2 the x coordinate of the ending corner of the gradient
- * @param y2 the y coordinate of the ending corner of the gradient
- * @param color1 the starting color of the gradient
- * @param color2 the ending color of the gradient
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device,
- * or if either color1 or color2 is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either color1 or color2 has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Pattern(Device device, float x1, float y1, float x2, float y2, Color color1, Color color2) {
- this(device, x1, y1, x2, y2, color1, 0xFF, color2, 0xFF);
-}
-/**
- * Constructs a new Pattern that represents a linear, two color
- * gradient. Drawing with the pattern will cause the resulting area to be
- * tiled with the gradient specified by the arguments.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the pattern
- * @param x1 the x coordinate of the starting corner of the gradient
- * @param y1 the y coordinate of the starting corner of the gradient
- * @param x2 the x coordinate of the ending corner of the gradient
- * @param y2 the y coordinate of the ending corner of the gradient
- * @param color1 the starting color of the gradient
- * @param alpha1 the starting alpha value of the gradient
- * @param color2 the ending color of the gradient
- * @param alpha2 the ending alpha value of the gradient
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device,
- * or if either color1 or color2 is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either color1 or color2 has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- *
- * @since 3.2
- */
-public Pattern(Device device, float x1, float y1, float x2, float y2, Color color1, int alpha1, Color color2, int alpha2) {
- super(device);
- if (color1 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color1.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (color2 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color2.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- pt1 = new NSPoint();
- pt2 = new NSPoint();
- pt1.x = x1;
- pt1.y = y1;
- pt2.x = x2;
- pt2.y = y2;
- this.color1 = color1.handle;
- this.color2 = color2.handle;
- this.alpha1 = alpha1;
- this.alpha2 = alpha2;
- NSColor start = NSColor.colorWithDeviceRed(color1.handle[0], color1.handle[1], color1.handle[2], alpha1 / 255f);
- NSColor end = NSColor.colorWithDeviceRed(color2.handle[0], color2.handle[1], color2.handle[2], alpha2 / 255f);
- gradient = ((NSGradient)new NSGradient().alloc()).initWithStartingColor(start, end);
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-void destroy() {
- if (color != null) color.release();
- color = null;
- if (gradient != null) gradient.release();
- gradient = null;
- image = null;
- color1 = color2 = null;
-}
-
-/**
- * Returns <code>true</code> if the Pattern has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Pattern.
- * When a Pattern has been disposed, it is an error to
- * invoke any other method using the Pattern.
- *
- * @return <code>true</code> when the Pattern is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return device == null;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString() {
- if (isDisposed()) return "Pattern {*DISPOSED*}";
- return "Pattern {" + (color != null ? color.id : gradient.id) + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Region.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Region.java
deleted file mode 100755
index c8de98bb3a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Region.java
+++ /dev/null
@@ -1,839 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.cocoa.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class represent areas of an x-y coordinate
- * system that are aggregates of the areas covered by a number
- * of polygons.
- * <p>
- * Application code must explicitly invoke the <code>Region.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Region extends Resource {
- /**
- * the OS resource for the region
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
-
-/**
- * Constructs a new empty region.
- *
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
- * </ul>
- */
-public Region() {
- this(null);
-}
-
-/**
- * Constructs a new empty region.
- * <p>
- * You must dispose the region when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the region
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
- * </ul>
- *
- * @see #dispose
- *
- * @since 3.0
- */
-public Region(Device device) {
- super(device);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- handle = OS.NewRgn();
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-Region(Device device, int /*long*/ handle) {
- super(device);
- this.handle = handle;
-}
-
-public static Region cocoa_new(Device device, int /*long*/ handle) {
- return new Region(device, handle);
-}
-
-static int /*long*/ polyToRgn(int[] poly, int length) {
- short[] r = new short[4];
- int /*long*/ polyRgn = OS.NewRgn(), rectRgn = OS.NewRgn();
- int minY = poly[1], maxY = poly[1];
- for (int y = 3; y < length; y += 2) {
- if (poly[y] < minY) minY = poly[y];
- if (poly[y] > maxY) maxY = poly[y];
- }
- int[] inter = new int[length + 1];
- for (int y = minY; y <= maxY; y++) {
- int count = 0;
- int x1 = poly[0], y1 = poly[1];
- for (int p = 2; p < length; p += 2) {
- int x2 = poly[p], y2 = poly[p + 1];
- if (y1 != y2 && ((y1 <= y && y < y2) || (y2 <= y && y < y1))) {
- inter[count++] = (int)((((y - y1) / (float)(y2 - y1)) * (x2 - x1)) + x1 + 0.5f);
- }
- x1 = x2;
- y1 = y2;
- }
- int x2 = poly[0], y2 = poly[1];
- if (y1 != y2 && ((y1 <= y && y < y2) || (y2 <= y && y < y1))) {
- inter[count++] = (int)((((y - y1) / (float)(y2 - y1)) * (x2 - x1)) + x1 + 0.5f);
- }
- for (int gap=count/2; gap>0; gap/=2) {
- for (int i=gap; i<count; i++) {
- for (int j=i-gap; j>=0; j-=gap) {
- if ((inter[j] - inter[j + gap]) <= 0)
- break;
- int temp = inter[j];
- inter[j] = inter[j + gap];
- inter[j + gap] = temp;
- }
- }
- }
- for (int i = 0; i < count; i += 2) {
- OS.SetRect(r, (short)inter[i], (short)y, (short)(inter[i + 1]),(short)(y + 1));
- OS.RectRgn(rectRgn, r);
- OS.UnionRgn(polyRgn, rectRgn, polyRgn);
- }
- }
- OS.DisposeRgn(rectRgn);
- return polyRgn;
-}
-
-static int /*long*/ polyRgn(int[] pointArray, int count) {
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- int /*long*/ polyRgn;
- if (C.PTR_SIZEOF == 4) {
- polyRgn = OS.NewRgn();
- OS.OpenRgn();
- OS.MoveTo((short)pointArray[0], (short)pointArray[1]);
- for (int i = 1; i < count / 2; i++) {
- OS.LineTo((short)pointArray[2 * i], (short)pointArray[2 * i + 1]);
- }
- OS.LineTo((short)pointArray[0], (short)pointArray[1]);
- OS.CloseRgn(polyRgn);
- } else {
- polyRgn = polyToRgn(pointArray, count);
- }
- return polyRgn;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Adds the given polygon to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param pointArray points that describe the polygon to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
-*
- */
-public void add (int[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- add(pointArray, pointArray.length);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-void add(int[] pointArray, int count) {
- if (count <= 2) return;
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- int /*long*/ polyRgn = polyRgn(pointArray, count);
- OS.UnionRgn(handle, polyRgn, handle);
- OS.DisposeRgn(polyRgn);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Adds the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void add(Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (rect.width < 0 || rect.height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- add (rect.x, rect.y, rect.width, rect.height);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Adds the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void add(int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- int /*long*/ rectRgn = OS.NewRgn();
- short[] r = new short[4];
- OS.SetRect(r, (short)x, (short)y, (short)(x + width),(short)(y + height));
- OS.RectRgn(rectRgn, r);
- OS.UnionRgn(handle, rectRgn, handle);
- OS.DisposeRgn(rectRgn);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Adds all of the polygons which make up the area covered
- * by the argument to the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to merge
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void add(Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- OS.UnionRgn(handle, region.handle, handle);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns <code>true</code> if the point specified by the
- * arguments is inside the area specified by the receiver,
- * and <code>false</code> otherwise.
- *
- * @param x the x coordinate of the point to test for containment
- * @param y the y coordinate of the point to test for containment
- * @return <code>true</code> if the region contains the point and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains(int x, int y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- short[] point = new short[]{(short)y, (short)x};
- return OS.PtInRgn(point, handle);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns <code>true</code> if the given point is inside the
- * area specified by the receiver, and <code>false</code>
- * otherwise.
- *
- * @param pt the point to test for containment
- * @return <code>true</code> if the region contains the point and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains(Point pt) {
- if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return contains(pt.x, pt.y);
-}
-
-NSAffineTransform transform;
-void convertRgn(NSAffineTransform transform) {
- int /*long*/ newRgn = OS.NewRgn();
- Callback callback = new Callback(this, "convertRgn", 4);
- int /*long*/ proc = callback.getAddress();
- if (proc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- this.transform = transform;
- OS.QDRegionToRects(handle, OS.kQDParseRegionFromTopLeft, proc, newRgn);
- this.transform = null;
- callback.dispose();
- OS.CopyRgn(newRgn, handle);
- OS.DisposeRgn(newRgn);
-}
-
-int /*long*/ convertRgn(int /*long*/ message, int /*long*/ rgn, int /*long*/ r, int /*long*/ newRgn) {
- if (message == OS.kQDRegionToRectsMsgParse) {
- short[] rect = new short[4];
- OS.memmove(rect, r, rect.length * 2);
- int i = 0;
- NSPoint point = new NSPoint();
- int[] points = new int[10];
- point.x = rect[1];
- point.y = rect[0];
- point = transform.transformPoint(point);
- short startX, startY;
- points[i++] = startX = (short)point.x;
- points[i++] = startY = (short)point.y;
- point.x = rect[3];
- point.y = rect[0];
- point = transform.transformPoint(point);
- points[i++] = (short)Math.round(point.x);
- points[i++] = (short)point.y;
- point.x = rect[3];
- point.y = rect[2];
- point = transform.transformPoint(point);
- points[i++] = (short)Math.round(point.x);
- points[i++] = (short)Math.round(point.y);
- point.x = rect[1];
- point.y = rect[2];
- point = transform.transformPoint(point);
- points[i++] = (short)point.x;
- points[i++] = (short)Math.round(point.y);
- points[i++] = startX;
- points[i++] = startY;
- int /*long*/ polyRgn = polyRgn(points, points.length);
- OS.UnionRgn(newRgn, polyRgn, newRgn);
- OS.DisposeRgn(polyRgn);
- }
- return 0;
-}
-
-void destroy() {
- OS.DisposeRgn(handle);
- handle = 0;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals(Object object) {
- if (this == object) return true;
- if (!(object instanceof Region)) return false;
- Region region = (Region)object;
- return handle == region.handle;
-}
-
-/**
- * Returns a rectangle which represents the rectangular
- * union of the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @return a bounding rectangle for the region
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#union
- */
-public Rectangle getBounds() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- short[] bounds = new short[4];
- OS.GetRegionBounds(handle, bounds);
- int width = bounds[3] - bounds[1];
- int height = bounds[2] - bounds[0];
- return new Rectangle(bounds[1], bounds[0], width, height);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-NSBezierPath getPath() {
- Callback callback = new Callback(this, "regionToRects", 4);
- if (callback.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- NSBezierPath path = NSBezierPath.bezierPath();
- path.retain();
- OS.QDRegionToRects(handle, OS.kQDParseRegionFromTopLeft, callback.getAddress(), path.id);
- callback.dispose();
- if (path.isEmpty()) path.appendBezierPathWithRect(new NSRect());
- return path;
-}
-
-NSPoint pt = new NSPoint();
-short[] rect = new short[4];
-int /*long*/ regionToRects(int /*long*/ message, int /*long*/ rgn, int /*long*/ r, int /*long*/ path) {
- if (message == OS.kQDRegionToRectsMsgParse) {
- OS.memmove(rect, r, rect.length * 2);
- pt.x = rect[1];
- pt.y = rect[0];
- OS.objc_msgSend(path, OS.sel_moveToPoint_, pt);
- pt.x = rect[3];
- OS.objc_msgSend(path, OS.sel_lineToPoint_, pt);
- pt.x = rect[3];
- pt.y = rect[2];
- OS.objc_msgSend(path, OS.sel_lineToPoint_, pt);
- pt.x = rect[1];
- OS.objc_msgSend(path, OS.sel_lineToPoint_, pt);
- OS.objc_msgSend(path, OS.sel_closePath);
- }
- return 0;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode() {
- return (int)/*64*/handle;
-}
-
-/**
- * Intersects the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to intersect with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void intersect(Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- intersect (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Intersects the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void intersect(int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- int /*long*/ rectRgn = OS.NewRgn();
- short[] r = new short[4];
- OS.SetRect(r, (short)x, (short)y, (short)(x + width),(short)(y + height));
- OS.RectRgn(rectRgn, r);
- OS.SectRgn(handle, rectRgn, handle);
- OS.DisposeRgn(rectRgn);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Intersects all of the polygons which make up the area covered
- * by the argument to the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to intersect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void intersect(Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- OS.SectRgn(handle, region.handle, handle);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns <code>true</code> if the rectangle described by the
- * arguments intersects with any of the polygons the receiver
- * maintains to describe its area, and <code>false</code> otherwise.
- *
- * @param x the x coordinate of the origin of the rectangle
- * @param y the y coordinate of the origin of the rectangle
- * @param width the width of the rectangle
- * @param height the height of the rectangle
- * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#intersects(Rectangle)
- */
-public boolean intersects (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- short[] r = new short[4];
- OS.SetRect(r, (short)x, (short)y, (short)(x + width),(short)(y + height));
- return OS.RectInRgn(r, handle);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns <code>true</code> if the given rectangle intersects
- * with any of the polygons the receiver maintains to describe
- * its area and <code>false</code> otherwise.
- *
- * @param rect the rectangle to test for intersection
- * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#intersects(Rectangle)
- */
-public boolean intersects(Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return intersects(rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Returns <code>true</code> if the region has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the region.
- * When a region has been disposed, it is an error to
- * invoke any other method using the region.
- *
- * @return <code>true</code> when the region is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns <code>true</code> if the receiver does not cover any
- * area in the (x, y) coordinate plane, and <code>false</code> if
- * the receiver does cover some area in the plane.
- *
- * @return <code>true</code> if the receiver is empty, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean isEmpty() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- return OS.EmptyRgn(handle);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Subtracts the given polygon from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param pointArray points that describe the polygon to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract (int[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (pointArray.length < 2) return;
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- int /*long*/ polyRgn = polyRgn(pointArray, pointArray.length);
- OS.DiffRgn(handle, polyRgn, handle);
- OS.DisposeRgn(polyRgn);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Subtracts the given rectangle from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to subtract from the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract(Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- subtract (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Subtracts the given rectangle from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void subtract(int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- int /*long*/ rectRgn = OS.NewRgn();
- short[] r = new short[4];
- OS.SetRect(r, (short)x, (short)y, (short)(x + width),(short)(y + height));
- OS.RectRgn(rectRgn, r);
- OS.DiffRgn(handle, rectRgn, handle);
- OS.DisposeRgn(rectRgn);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Subtracts all of the polygons which make up the area covered
- * by the argument from the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to subtract
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract(Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- OS.DiffRgn(handle, region.handle, handle);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Translate all of the polygons the receiver maintains to describe
- * its area by the specified point.
- *
- * @param x the x coordinate of the point to translate
- * @param y the y coordinate of the point to translate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void translate (int x, int y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- OS.OffsetRgn (handle, (short)x, (short)y);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Translate all of the polygons the receiver maintains to describe
- * its area by the specified point.
- *
- * @param pt the point to translate
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void translate (Point pt) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- translate (pt.x, pt.y);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Region {*DISPOSED*}";
- return "Region {" + handle + "}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/TextLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/TextLayout.java
deleted file mode 100755
index 1d8b96f356..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/TextLayout.java
+++ /dev/null
@@ -1,1980 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.internal.C;
-import org.eclipse.swt.internal.Compatibility;
-import org.eclipse.swt.internal.cocoa.*;
-import org.eclipse.swt.*;
-
-/**
- * <code>TextLayout</code> is a graphic object that represents
- * styled text.
- * <p>
- * Instances of this class provide support for drawing, cursor
- * navigation, hit testing, text wrapping, alignment, tab expansion
- * line breaking, etc. These are aspects required for rendering internationalized text.
- * </p><p>
- * Application code must explicitly invoke the <code>TextLayout#dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#textlayout">TextLayout, TextStyle snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: CustomControlExample, StyledText tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.0
- */
-public final class TextLayout extends Resource {
-
- NSTextStorage textStorage;
- NSLayoutManager layoutManager;
- NSTextContainer textContainer;
- Font font;
- String text;
- StyleItem[] styles;
- int spacing, ascent, descent, indent;
- boolean justify;
- int alignment;
- int[] tabs;
- int[] segments;
- int wrapWidth;
- int orientation;
-
- int[] lineOffsets;
- NSRect[] lineBounds;
-
- static final int UNDERLINE_THICK = 1 << 16;
- static final RGB LINK_FOREGROUND = new RGB (0, 51, 153);
- int[] invalidOffsets;
- static final char LTR_MARK = '\u200E', RTL_MARK = '\u200F', ZWS = '\u200B';
-
- static class StyleItem {
- TextStyle style;
- int start;
-
- public String toString () {
- return "StyleItem {" + start + ", " + style + "}";
- }
- }
-
-/**
- * Constructs a new instance of this class on the given device.
- * <p>
- * You must dispose the text layout when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the text layout
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- *
- * @see #dispose()
- */
-public TextLayout (Device device) {
- super(device);
- wrapWidth = ascent = descent = -1;
- alignment = SWT.LEFT;
- orientation = SWT.LEFT_TO_RIGHT;
- text = "";
- styles = new StyleItem[2];
- styles[0] = new StyleItem();
- styles[1] = new StyleItem();
- init();
-}
-
-void checkLayout() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-float[] computePolyline(int left, int top, int right, int bottom) {
- int height = bottom - top; // can be any number
- int width = 2 * height; // must be even
- int peaks = Compatibility.ceil(right - left, width);
- if (peaks == 0 && right - left > 2) {
- peaks = 1;
- }
- int length = ((2 * peaks) + 1) * 2;
- if (length < 0) return new float[0];
-
- float[] coordinates = new float[length];
- for (int i = 0; i < peaks; i++) {
- int index = 4 * i;
- coordinates[index] = left + (width * i);
- coordinates[index+1] = bottom;
- coordinates[index+2] = coordinates[index] + width / 2;
- coordinates[index+3] = top;
- }
- coordinates[length-2] = left + (width * peaks);
- coordinates[length-1] = bottom;
- return coordinates;
-}
-
-
-void computeRuns() {
- if (textStorage != null) return;
- String segmentsText = getSegmentsText();
- NSString str = NSString.stringWith(segmentsText);
- textStorage = (NSTextStorage)new NSTextStorage().alloc().init();
- layoutManager = (NSLayoutManager)new NSLayoutManager().alloc().init();
- layoutManager.setBackgroundLayoutEnabled(NSThread.isMainThread());
- textContainer = (NSTextContainer)new NSTextContainer().alloc();
- NSSize size = new NSSize();
- size.width = wrapWidth != -1 ? wrapWidth : Float.MAX_VALUE;
- size.height = Float.MAX_VALUE;
- textContainer.initWithContainerSize(size);
- textStorage.addLayoutManager(layoutManager);
- layoutManager.addTextContainer(textContainer);
-
- /*
- * Bug in Cocoa. Adding attributes directly to a NSTextStorage causes
- * output to the console and eventually a segmentation fault when printing
- * on a thread other than the main thread. The fix is to add attributes to
- * a separate NSMutableAttributedString and add it to text storage when done.
- */
- NSMutableAttributedString attrStr = (NSMutableAttributedString)new NSMutableAttributedString().alloc();
- attrStr.id = attrStr.initWithString(str).id;
- attrStr.beginEditing();
- Font defaultFont = font != null ? font : device.systemFont;
- NSRange range = new NSRange();
- range.length = str.length();
- attrStr.addAttribute(OS.NSFontAttributeName, defaultFont.handle, range);
- defaultFont.addTraits(attrStr, range);
- //TODO ascend descent wrap
- NSMutableParagraphStyle paragraph = (NSMutableParagraphStyle)new NSMutableParagraphStyle().alloc().init();
- int align = OS.NSLeftTextAlignment;
- if (justify) {
- align = OS.NSJustifiedTextAlignment;
- } else {
- switch (alignment) {
- case SWT.CENTER:
- align = OS.NSCenterTextAlignment;
- break;
- case SWT.RIGHT:
- align = OS.NSRightTextAlignment;
- }
- }
- paragraph.setAlignment(align);
- paragraph.setLineSpacing(spacing);
- paragraph.setFirstLineHeadIndent(indent);
- paragraph.setLineBreakMode(wrapWidth != -1 ? OS.NSLineBreakByWordWrapping : OS.NSLineBreakByClipping);
- paragraph.setTabStops(NSArray.array());
- if (tabs != null) {
- int count = tabs.length;
- for (int i = 0, pos = 0; i < count; i++) {
- pos += tabs[i];
- NSTextTab tab = (NSTextTab)new NSTextTab().alloc();
- tab = tab.initWithType(OS.NSLeftTabStopType, pos);
- paragraph.addTabStop(tab);
- tab.release();
- }
- int width = count - 2 >= 0 ? tabs[count - 1] - tabs[count - 2] : tabs[count - 1];
- paragraph.setDefaultTabInterval(width);
- }
- attrStr.addAttribute(OS.NSParagraphStyleAttributeName, paragraph, range);
- paragraph.release();
- int /*long*/ textLength = str.length();
- for (int i = 0; i < styles.length - 1; i++) {
- StyleItem run = styles[i];
- if (run.style == null) continue;
- TextStyle style = run.style;
- range.location = textLength != 0 ? translateOffset(run.start) : 0;
- range.length = translateOffset(styles[i + 1].start) - range.location;
- Font font = style.font;
- if (font != null) {
- attrStr.addAttribute(OS.NSFontAttributeName, font.handle, range);
- font.addTraits(attrStr, range);
- }
- Color foreground = style.foreground;
- if (foreground != null) {
- NSColor color = NSColor.colorWithDeviceRed(foreground.handle[0], foreground.handle[1], foreground.handle[2], 1);
- attrStr.addAttribute(OS.NSForegroundColorAttributeName, color, range);
- }
- Color background = style.background;
- if (background != null) {
- NSColor color = NSColor.colorWithDeviceRed(background.handle[0], background.handle[1], background.handle[2], 1);
- attrStr.addAttribute(OS.NSBackgroundColorAttributeName, color, range);
- }
- if (style.strikeout) {
- attrStr.addAttribute(OS.NSStrikethroughStyleAttributeName, NSNumber.numberWithInt(OS.NSUnderlineStyleSingle), range);
- Color strikeColor = style.strikeoutColor;
- if (strikeColor != null) {
- NSColor color = NSColor.colorWithDeviceRed(strikeColor.handle[0], strikeColor.handle[1], strikeColor.handle[2], 1);
- attrStr.addAttribute(OS.NSStrikethroughColorAttributeName, color, range);
- }
- }
- if (isUnderlineSupported(style)) {
- int underlineStyle = 0;
- switch (style.underlineStyle) {
- case SWT.UNDERLINE_SINGLE:
- underlineStyle = OS.NSUnderlineStyleSingle;
- break;
- case SWT.UNDERLINE_DOUBLE:
- underlineStyle = OS.NSUnderlineStyleDouble;
- break;
- case UNDERLINE_THICK:
- underlineStyle = OS.NSUnderlineStyleThick;
- break;
- case SWT.UNDERLINE_LINK: {
- underlineStyle = OS.NSUnderlineStyleSingle;
- if (foreground == null) {
- NSColor color = NSColor.colorWithDeviceRed(LINK_FOREGROUND.red / 255f, LINK_FOREGROUND.green / 255f, LINK_FOREGROUND.blue / 255f, 1);
- attrStr.addAttribute(OS.NSForegroundColorAttributeName, color, range);
- }
- break;
- }
- }
- if (underlineStyle != 0) {
- attrStr.addAttribute(OS.NSUnderlineStyleAttributeName, NSNumber.numberWithInt(underlineStyle), range);
- Color underlineColor = style.underlineColor;
- if (underlineColor != null) {
- NSColor color = NSColor.colorWithDeviceRed(underlineColor.handle[0], underlineColor.handle[1], underlineColor.handle[2], 1);
- attrStr.addAttribute(OS.NSUnderlineColorAttributeName, color, range);
- }
- }
- }
- if (style.rise != 0) {
- attrStr.addAttribute(OS.NSBaselineOffsetAttributeName, NSNumber.numberWithInt(style.rise), range);
- }
- if (style.metrics != null) {
- //TODO implement metrics
- }
- }
- attrStr.endEditing();
- textStorage.setAttributedString(attrStr);
- attrStr.release();
-
- textContainer.setLineFragmentPadding(0);
- layoutManager.glyphRangeForTextContainer(textContainer);
-
- int numberOfLines;
- int /*long*/ numberOfGlyphs = layoutManager.numberOfGlyphs(), index;
- int /*long*/ rangePtr = OS.malloc(NSRange.sizeof);
- NSRange lineRange = new NSRange();
- for (numberOfLines = 0, index = 0; index < numberOfGlyphs; numberOfLines++){
- layoutManager.lineFragmentUsedRectForGlyphAtIndex(index, rangePtr, true);
- OS.memmove(lineRange, rangePtr, NSRange.sizeof);
- index = lineRange.location + lineRange.length;
- }
- if (numberOfLines == 0) numberOfLines++;
- int[] offsets = new int[numberOfLines + 1];
- NSRect[] bounds = new NSRect[numberOfLines];
- for (numberOfLines = 0, index = 0; index < numberOfGlyphs; numberOfLines++){
- bounds[numberOfLines] = layoutManager.lineFragmentUsedRectForGlyphAtIndex(index, rangePtr, true);
- if (numberOfLines < bounds.length - 1) bounds[numberOfLines].height -= spacing;
- OS.memmove(lineRange, rangePtr, NSRange.sizeof);
- offsets[numberOfLines] = (int)/*64*/lineRange.location;
- index = lineRange.location + lineRange.length;
- }
- if (numberOfLines == 0) {
- Font font = this.font != null ? this.font : device.systemFont;
- NSFont nsFont = font.handle;
- bounds[0] = new NSRect();
- bounds[0].height = Math.max(layoutManager.defaultLineHeightForFont(nsFont), ascent + descent);
- }
- OS.free(rangePtr);
- offsets[numberOfLines] = (int)/*64*/textStorage.length();
- this.lineOffsets = offsets;
- this.lineBounds = bounds;
-}
-
-void destroy() {
- freeRuns();
- font = null;
- text = null;
- styles = null;
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- *
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- */
-public void draw(GC gc, int x, int y) {
- draw(gc, x, y, -1, -1, null, null);
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- *
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param selectionStart the offset where the selections starts, or -1 indicating no selection
- * @param selectionEnd the offset where the selections ends, or -1 indicating no selection
- * @param selectionForeground selection foreground, or NULL to use the system default color
- * @param selectionBackground selection background, or NULL to use the system default color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- */
-public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground) {
- draw(gc, x, y, selectionStart, selectionEnd, selectionForeground, selectionBackground, 0);
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- * <p>
- * The parameter <code>flags</code> can include one of <code>SWT.DELIMITER_SELECTION</code>
- * or <code>SWT.FULL_SELECTION</code> to specify the selection behavior on all lines except
- * for the last line, and can also include <code>SWT.LAST_LINE_SELECTION</code> to extend
- * the specified selection behavior to the last line.
- * </p>
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param selectionStart the offset where the selections starts, or -1 indicating no selection
- * @param selectionEnd the offset where the selections ends, or -1 indicating no selection
- * @param selectionForeground selection foreground, or NULL to use the system default color
- * @param selectionBackground selection background, or NULL to use the system default color
- * @param flags drawing options
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- *
- * @since 3.3
- */
-public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags) {
- checkLayout ();
- if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (selectionForeground != null && selectionForeground.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (selectionBackground != null && selectionBackground.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = gc.checkGC(GC.CLIPPING | GC.TRANSFORM | GC.FOREGROUND);
- try {
- computeRuns();
- int length = translateOffset(text.length());
- if (length == 0 && flags == 0) return;
- gc.handle.saveGraphicsState();
- NSPoint pt = new NSPoint();
- pt.x = x;
- pt.y = y;
- NSRange range = new NSRange();
- int /*long*/ numberOfGlyphs = layoutManager.numberOfGlyphs();
- if (numberOfGlyphs > 0) {
- range.location = 0;
- range.length = numberOfGlyphs;
- layoutManager.drawBackgroundForGlyphRange(range, pt);
- }
- boolean hasSelection = selectionStart <= selectionEnd && selectionStart != -1 && selectionEnd != -1;
- if (hasSelection || (flags & SWT.LAST_LINE_SELECTION) != 0) {
- if (selectionBackground == null) selectionBackground = device.getSystemColor(SWT.COLOR_LIST_SELECTION);
- NSColor selectionColor = NSColor.colorWithDeviceRed(selectionBackground.handle[0], selectionBackground.handle[1], selectionBackground.handle[2], selectionBackground.handle[3]);
- NSBezierPath path = NSBezierPath.bezierPath();
- NSRect rect = new NSRect();
- if (hasSelection) {
- int /*long*/ pRectCount = OS.malloc(C.PTR_SIZEOF);
- range.location = translateOffset(selectionStart);
- range.length = translateOffset(selectionEnd - selectionStart + 1);
- int /*long*/ pArray = layoutManager.rectArrayForCharacterRange(range, range, textContainer, pRectCount);
- int /*long*/ [] rectCount = new int /*long*/ [1];
- OS.memmove(rectCount, pRectCount, C.PTR_SIZEOF);
- OS.free(pRectCount);
- for (int k = 0; k < rectCount[0]; k++, pArray += NSRect.sizeof) {
- OS.memmove(rect, pArray, NSRect.sizeof);
- fixRect(rect);
- rect.x += pt.x;
- rect.y += pt.y;
- rect.height = Math.max(rect.height, ascent + descent);
- path.appendBezierPathWithRect(rect);
- }
- }
- //TODO draw full selection for wrapped text
- if ((flags & SWT.LAST_LINE_SELECTION) != 0) {
- NSRect bounds = lineBounds[lineBounds.length - 1];
- rect.x = pt.x + bounds.x + bounds.width;
- rect.y = y + bounds.y;
- rect.width = (flags & SWT.FULL_SELECTION) != 0 ? 0x7fffffff : bounds.height / 3;
- rect.height = Math.max(bounds.height, ascent + descent);
- path.appendBezierPathWithRect(rect);
- }
- selectionColor.setFill();
- path.fill();
- }
- if (numberOfGlyphs > 0) {
- range.location = 0;
- range.length = numberOfGlyphs;
- float /*double*/ [] fg = gc.data.foreground;
- boolean defaultFg = fg[0] == 0 && fg[1] == 0 && fg[2] == 0 && fg[3] == 1;
- if (!defaultFg) {
- for (int i = 0; i < styles.length - 1; i++) {
- StyleItem run = styles[i];
- if (run.style != null && run.style.foreground != null) continue;
- if (run.style != null && run.style.underline && run.style.underlineStyle == SWT.UNDERLINE_LINK) continue;
- range.location = length != 0 ? translateOffset(run.start) : 0;
- range.length = translateOffset(styles[i + 1].start) - range.location;
- layoutManager.addTemporaryAttribute(OS.NSForegroundColorAttributeName, gc.data.fg, range);
- }
- }
- range.location = 0;
- range.length = numberOfGlyphs;
- layoutManager.drawGlyphsForGlyphRange(range, pt);
- if (!defaultFg) {
- range.location = 0;
- range.length = length;
- layoutManager.removeTemporaryAttribute(OS.NSForegroundColorAttributeName, range);
- }
- NSPoint point = new NSPoint();
- for (int j = 0; j < styles.length; j++) {
- StyleItem run = styles[j];
- TextStyle style = run.style;
- if (style == null) continue;
- boolean drawUnderline = style.underline && !isUnderlineSupported(style);
- drawUnderline = drawUnderline && (j + 1 == styles.length || !style.isAdherentUnderline(styles[j + 1].style));
- boolean drawBorder = style.borderStyle != SWT.NONE;
- drawBorder = drawBorder && (j + 1 == styles.length || !style.isAdherentBorder(styles[j + 1].style));
- if (!drawUnderline && !drawBorder) continue;
- int end = j + 1 < styles.length ? translateOffset(styles[j + 1].start - 1) : length;
- for (int i = 0; i < lineOffsets.length - 1; i++) {
- int lineStart = untranslateOffset(lineOffsets[i]);
- int lineEnd = untranslateOffset(lineOffsets[i + 1] - 1);
- if (drawUnderline) {
- int start = run.start;
- for (int k = j; k > 0 && style.isAdherentUnderline(styles[k - 1].style); k--) {
- start = styles[k - 1].start;
- }
- start = translateOffset(start);
- if (!(start > lineEnd || end < lineStart)) {
- range.location = Math.max(lineStart, start);
- range.length = Math.min(lineEnd, end) + 1 - range.location;
- if (range.length > 0) {
- int /*long*/ pRectCount = OS.malloc(C.PTR_SIZEOF);
- int /*long*/ pArray = layoutManager.rectArrayForCharacterRange(range, range, textContainer, pRectCount);
- int /*long*/ [] rectCount = new int /*long*/ [1];
- OS.memmove(rectCount, pRectCount, C.PTR_SIZEOF);
- OS.free(pRectCount);
- NSRect rect = new NSRect();
- gc.handle.saveGraphicsState();
- float /*double*/ baseline = layoutManager.typesetter().baselineOffsetInLayoutManager(layoutManager, lineStart);
- float /*double*/ [] color = null;
- if (style.underlineColor != null) color = style.underlineColor.handle;
- if (color == null && style.foreground != null) color = style.foreground.handle;
- if (color != null) {
- NSColor.colorWithDeviceRed(color[0], color[1], color[2], color[3]).setStroke();
- }
- for (int k = 0; k < rectCount[0]; k++, pArray += NSRect.sizeof) {
- OS.memmove(rect, pArray, NSRect.sizeof);
- fixRect(rect);
- float /*double*/ underlineX = pt.x + rect.x;
- float /*double*/ underlineY = pt.y + rect.y + rect.height - baseline + 1;
- NSBezierPath path = NSBezierPath.bezierPath();
- switch (style.underlineStyle) {
- case SWT.UNDERLINE_ERROR: {
- path.setLineWidth(2f);
- path.setLineCapStyle(OS.NSRoundLineCapStyle);
- path.setLineJoinStyle(OS.NSRoundLineJoinStyle);
- path.setLineDash(new float /*double*/ []{1, 3f}, 2, 0);
- point.x = underlineX;
- point.y = underlineY + 0.5f;
- path.moveToPoint(point);
- point.x = underlineX + rect.width;
- point.y = underlineY + 0.5f;
- path.lineToPoint(point);
- break;
- }
- case SWT.UNDERLINE_SQUIGGLE: {
- gc.handle.setShouldAntialias(false);
- path.setLineWidth(1.0f);
- path.setLineCapStyle(OS.NSButtLineCapStyle);
- path.setLineJoinStyle(OS.NSMiterLineJoinStyle);
- float /*double*/ lineBottom = pt.y + rect.y + rect.height;
- float squigglyThickness = 1;
- float squigglyHeight = 2 * squigglyThickness;
- float /*double*/ squigglyY = Math.min(underlineY - squigglyHeight / 2, lineBottom - squigglyHeight - 1);
- float[] points = computePolyline((int)underlineX, (int)squigglyY, (int)(underlineX + rect.width), (int)(squigglyY + squigglyHeight));
- point.x = points[0] + 0.5f;
- point.y = points[1] + 0.5f;
- path.moveToPoint(point);
- for (int p = 2; p < points.length; p+=2) {
- point.x = points[p] + 0.5f;
- point.y = points[p+1] + 0.5f;
- path.lineToPoint(point);
- }
- break;
- }
- }
- path.stroke();
- }
- gc.handle.restoreGraphicsState();
- }
- }
- }
- if (drawBorder) {
- int start = run.start;
- for (int k = j; k > 0 && style.isAdherentBorder(styles[k - 1].style); k--) {
- start = styles[k - 1].start;
- }
- start = translateOffset(start);
- if (!(start > lineEnd || end < lineStart)) {
- range.location = Math.max(lineStart, start);
- range.length = Math.min(lineEnd, end) + 1 - range.location;
- if (range.length > 0) {
- int /*long*/ pRectCount = OS.malloc(C.PTR_SIZEOF);
- int /*long*/ pArray = layoutManager.rectArrayForCharacterRange(range, range, textContainer, pRectCount);
- int /*long*/ [] rectCount = new int /*long*/ [1];
- OS.memmove(rectCount, pRectCount, C.PTR_SIZEOF);
- OS.free(pRectCount);
- NSRect rect = new NSRect();
- gc.handle.saveGraphicsState();
- float /*double*/ [] color = null;
- if (style.borderColor != null) color = style.borderColor.handle;
- if (color == null && style.foreground != null) color = style.foreground.handle;
- if (color != null) {
- NSColor.colorWithDeviceRed(color[0], color[1], color[2], color[3]).setStroke();
- }
- int width = 1;
- float[] dashes = null;
- switch (style.borderStyle) {
- case SWT.BORDER_SOLID: break;
- case SWT.BORDER_DASH: dashes = width != 0 ? GC.LINE_DASH : GC.LINE_DASH_ZERO; break;
- case SWT.BORDER_DOT: dashes = width != 0 ? GC.LINE_DOT : GC.LINE_DOT_ZERO; break;
- }
- float /*double*/ [] lengths = null;
- if (dashes != null) {
- lengths = new float /*double*/[dashes.length];
- for (int k = 0; k < lengths.length; k++) {
- lengths[k] = width == 0 ? dashes[k] : dashes[k] * width;
- }
- }
- for (int k = 0; k < rectCount[0]; k++, pArray += NSRect.sizeof) {
- OS.memmove(rect, pArray, NSRect.sizeof);
- fixRect(rect);
- rect.x += pt.x + 0.5f;
- rect.y += pt.y + 0.5f;
- rect.width -= 0.5f;
- rect.height -= 0.5f;
- NSBezierPath path = NSBezierPath.bezierPath();
- path.setLineDash(lengths, lengths != null ? lengths.length : 0, 0);
- path.appendBezierPathWithRect(rect);
- path.stroke();
- }
- gc.handle.restoreGraphicsState();
- }
- }
- }
- }
- }
- }
- gc.handle.restoreGraphicsState();
- } finally {
- gc.uncheckGC(pool);
- }
-}
-
-void fixRect(NSRect rect) {
- for (int j = 0; j < lineBounds.length; j++) {
- NSRect line = lineBounds[j];
- if (line.y <= rect.y && rect.y < line.y + line.height) {
- if (rect.x + rect.width > line.x + line.width) {
- rect.width = line.x + line.width - rect.x;
- }
- }
- }
-}
-
-void freeRuns() {
- if (textStorage == null) return;
- if (textStorage != null) {
- textStorage.release();
- }
- if (layoutManager != null) {
- layoutManager.release();
- }
- if (textContainer != null) {
- textContainer.release();
- }
- textStorage = null;
- layoutManager = null;
- textContainer = null;
-}
-
-/**
- * Returns the receiver's horizontal text alignment, which will be one
- * of <code>SWT.LEFT</code>, <code>SWT.CENTER</code> or
- * <code>SWT.RIGHT</code>.
- *
- * @return the alignment used to positioned text horizontally
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getAlignment() {
- checkLayout();
- return alignment;
-}
-
-/**
- * Returns the ascent of the receiver.
- *
- * @return the ascent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getDescent()
- * @see #setDescent(int)
- * @see #setAscent(int)
- * @see #getLineMetrics(int)
- */
-public int getAscent () {
- checkLayout();
- return ascent;
-}
-
-/**
- * Returns the bounds of the receiver. The width returned is either the
- * width of the longest line or the width set using {@link TextLayout#setWidth(int)}.
- * To obtain the text bounds of a line use {@link TextLayout#getLineBounds(int)}.
- *
- * @return the bounds of the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setWidth(int)
- * @see #getLineBounds(int)
- */
-public Rectangle getBounds() {
- checkLayout();
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- computeRuns();
- NSRect rect = layoutManager.usedRectForTextContainer(textContainer);
- if (wrapWidth != -1) rect.width = wrapWidth;
- if (text.length() == 0) {
- Font font = this.font != null ? this.font : device.systemFont;
- NSFont nsFont = font.handle;
- rect.height = layoutManager.defaultLineHeightForFont(nsFont);
- }
- rect.height = Math.max(rect.height, ascent + descent) + spacing;
- return new Rectangle(0, 0, (int)Math.ceil(rect.width), (int)Math.ceil(rect.height));
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns the bounds for the specified range of characters. The
- * bounds is the smallest rectangle that encompasses all characters
- * in the range. The start and end offsets are inclusive and will be
- * clamped if out of range.
- *
- * @param start the start offset
- * @param end the end offset
- * @return the bounds of the character range
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds(int start, int end) {
- checkLayout();
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- computeRuns();
- int length = text.length();
- if (length == 0) return new Rectangle(0, 0, 0, 0);
- if (start > end) return new Rectangle(0, 0, 0, 0);
- start = Math.min(Math.max(0, start), length - 1);
- end = Math.min(Math.max(0, end), length - 1);
- start = translateOffset(start);
- end = translateOffset(end);
- NSRange range = new NSRange();
- range.location = start;
- range.length = end - start + 1;
- int /*long*/ pRectCount = OS.malloc(C.PTR_SIZEOF);
- int /*long*/ pArray = layoutManager.rectArrayForCharacterRange(range, range, textContainer, pRectCount);
- int /*long*/ [] rectCount = new int /*long*/ [1];
- OS.memmove(rectCount, pRectCount, C.PTR_SIZEOF);
- OS.free(pRectCount);
- NSRect rect = new NSRect();
- int left = 0x7FFFFFFF, right = 0;
- int top = 0x7FFFFFFF, bottom = 0;
- for (int i = 0; i < rectCount[0]; i++, pArray += NSRect.sizeof) {
- OS.memmove(rect, pArray, NSRect.sizeof);
- fixRect(rect);
- left = Math.min(left, (int)rect.x);
- right = Math.max(right, (int)Math.ceil(rect.x + rect.width));
- top = Math.min(top, (int)rect.y);
- bottom = Math.max(bottom, (int)Math.ceil(rect.y + rect.height));
- }
- return new Rectangle(left, top, right - left, bottom - top);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns the descent of the receiver.
- *
- * @return the descent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getAscent()
- * @see #setAscent(int)
- * @see #setDescent(int)
- * @see #getLineMetrics(int)
- */
-public int getDescent () {
- checkLayout();
- return descent;
-}
-
-/**
- * Returns the default font currently being used by the receiver
- * to draw and measure text.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getFont () {
- checkLayout();
- return font;
-}
-
-/**
-* Returns the receiver's indent.
-*
-* @return the receiver's indent
-*
-* @exception SWTException <ul>
-* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
-* </ul>
-*
-* @since 3.2
-*/
-public int getIndent () {
- checkLayout();
- return indent;
-}
-
-/**
-* Returns the receiver's justification.
-*
-* @return the receiver's justification
-*
-* @exception SWTException <ul>
-* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
-* </ul>
-*
-* @since 3.2
-*/
-public boolean getJustify () {
- checkLayout();
- return justify;
-}
-
-/**
- * Returns the embedding level for the specified character offset. The
- * embedding level is usually used to determine the directionality of a
- * character in bidirectional text.
- *
- * @param offset the character offset
- * @return the embedding level
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- */
-public int getLevel(int offset) {
- checkLayout();
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- offset = translateOffset(offset);
- int /*long*/ glyphOffset = layoutManager.glyphIndexForCharacterAtIndex(offset);
- NSRange range = new NSRange();
- range.location = glyphOffset;
- range.length = 1;
- int /*long*/ pBidiLevels = OS.malloc(1);
- byte[] bidiLevels = new byte[1];
- int /*long*/ result = layoutManager.getGlyphsInRange(range, 0, 0, 0, 0, pBidiLevels);
- if (result > 0) {
- OS.memmove(bidiLevels, pBidiLevels, 1);
- }
- OS.free(pBidiLevels);
- return bidiLevels[0];
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns the line offsets. Each value in the array is the
- * offset for the first character in a line except for the last
- * value, which contains the length of the text.
- *
- * @return the line offsets
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getLineOffsets() {
- checkLayout ();
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- computeRuns();
- int[] offsets = new int[lineOffsets.length];
- for (int i = 0; i < offsets.length; i++) {
- offsets[i] = untranslateOffset(lineOffsets[i]);
- }
- return offsets;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns the index of the line that contains the specified
- * character offset.
- *
- * @param offset the character offset
- * @return the line index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineIndex(int offset) {
- checkLayout ();
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- offset = translateOffset(offset);
- for (int line=0; line<lineOffsets.length - 1; line++) {
- if (lineOffsets[line + 1] > offset) {
- return line;
- }
- }
- return lineBounds.length - 1;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns the bounds of the line for the specified line index.
- *
- * @param lineIndex the line index
- * @return the line bounds
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getLineBounds(int lineIndex) {
- checkLayout();
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- computeRuns();
- if (!(0 <= lineIndex && lineIndex < lineBounds.length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- NSRect rect = lineBounds[lineIndex];
- int height = Math.max((int)Math.ceil(rect.height), ascent + descent);
- return new Rectangle((int)rect.x, (int)rect.y, (int)Math.ceil(rect.width), height);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns the receiver's line count. This includes lines caused
- * by wrapping.
- *
- * @return the line count
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineCount() {
- checkLayout ();
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- computeRuns();
- return lineOffsets.length - 1;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns the font metrics for the specified line index.
- *
- * @param lineIndex the line index
- * @return the font metrics
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontMetrics getLineMetrics (int lineIndex) {
- checkLayout ();
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- computeRuns();
- int lineCount = getLineCount();
- if (!(0 <= lineIndex && lineIndex < lineCount)) SWT.error(SWT.ERROR_INVALID_RANGE);
- int length = text.length();
- if (length == 0) {
- Font font = this.font != null ? this.font : device.systemFont;
- NSFont nsFont = font.handle;
- int ascent = (int)(0.5f + nsFont.ascender());
- int descent = (int)(0.5f + (-nsFont.descender() + nsFont.leading()));
- ascent = Math.max(ascent, this.ascent);
- descent = Math.max(descent, this.descent);
- return FontMetrics.cocoa_new(ascent, descent, 0, 0, ascent + descent);
- }
- Rectangle rect = getLineBounds(lineIndex);
- int baseline = (int)layoutManager.typesetter().baselineOffsetInLayoutManager(layoutManager, getLineOffsets()[lineIndex]);
- return FontMetrics.cocoa_new(rect.height - baseline, baseline, 0, 0, rect.height);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns the location for the specified character offset. The
- * <code>trailing</code> argument indicates whether the offset
- * corresponds to the leading or trailing edge of the cluster.
- *
- * @param offset the character offset
- * @param trailing the trailing flag
- * @return the location of the character offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getOffset(Point, int[])
- * @see #getOffset(int, int, int[])
- */
-public Point getLocation(int offset, boolean trailing) {
- checkLayout();
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- if (length == 0) return new Point(0, 0);
- offset = translateOffset(offset);
- int /*long*/ glyphIndex = layoutManager.glyphIndexForCharacterAtIndex(offset);
- NSRect rect = layoutManager.lineFragmentUsedRectForGlyphAtIndex(glyphIndex, 0);
- NSPoint point = layoutManager.locationForGlyphAtIndex(glyphIndex);
- if (trailing) {
- NSRange range = new NSRange();
- range.location = offset;
- range.length = 1;
- int /*long*/ pRectCount = OS.malloc(C.PTR_SIZEOF);
- int /*long*/ pArray = layoutManager.rectArrayForCharacterRange(range, range, textContainer, pRectCount);
- int /*long*/ [] rectCount = new int /*long*/ [1];
- OS.memmove(rectCount, pRectCount, C.PTR_SIZEOF);
- OS.free(pRectCount);
- if (rectCount[0] > 0) {
- NSRect bounds = new NSRect();
- OS.memmove(bounds, pArray, NSRect.sizeof);
- fixRect(bounds);
- point.x += bounds.width;
- }
- }
- return new Point((int)point.x, (int)rect.y);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns the next offset for the specified offset and movement
- * type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>,
- * <code>SWT.MOVEMENT_CLUSTER</code>, <code>SWT.MOVEMENT_WORD</code>,
- * <code>SWT.MOVEMENT_WORD_END</code> or <code>SWT.MOVEMENT_WORD_START</code>.
- *
- * @param offset the start offset
- * @param movement the movement type
- * @return the next offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getPreviousOffset(int, int)
- */
-public int getNextOffset (int offset, int movement) {
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- return _getOffset(offset, movement, true);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-int _getOffset (int offset, int movement, boolean forward) {
- checkLayout();
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- if (length == 0) return 0;
- offset = translateOffset(offset);
- length = translateOffset(length);
- switch (movement) {
- case SWT.MOVEMENT_CLUSTER://TODO cluster
- case SWT.MOVEMENT_CHAR: {
- boolean invalid = false;
- do {
- int newOffset = offset;
- if (forward) {
- if (newOffset < length) newOffset++;
- } else {
- if (newOffset > 0) newOffset--;
- }
- if (newOffset == offset) break;
- offset = newOffset;
- invalid = false;
- if (invalidOffsets != null) {
- for (int i = 0; i < invalidOffsets.length; i++) {
- if (offset == invalidOffsets[i]) {
- invalid = true;
- break;
- }
- }
- }
- } while (invalid);
- return untranslateOffset(offset);
- }
- case SWT.MOVEMENT_WORD: {
- return untranslateOffset((int)/*64*/textStorage.nextWordFromIndex(offset, forward));
- }
- case SWT.MOVEMENT_WORD_END: {
- NSRange range = textStorage.doubleClickAtIndex(length == offset ? length - 1 : offset);
- return untranslateOffset((int)/*64*/(range.location + range.length));
- }
- case SWT.MOVEMENT_WORD_START: {
- NSRange range = textStorage.doubleClickAtIndex(length == offset ? length - 1 : offset);
- return untranslateOffset((int)/*64*/range.location);
- }
- }
- return untranslateOffset(offset);
-}
-
-/**
- * Returns the character offset for the specified point.
- * For a typical character, the trailing argument will be filled in to
- * indicate whether the point is closer to the leading edge (0) or
- * the trailing edge (1). When the point is over a cluster composed
- * of multiple characters, the trailing argument will be filled with the
- * position of the character in the cluster that is closest to
- * the point.
- *
- * @param point the point
- * @param trailing the trailing buffer
- * @return the character offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getLocation(int, boolean)
- */
-public int getOffset(Point point, int[] trailing) {
- checkLayout();
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- computeRuns();
- if (point == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return getOffset(point.x, point.y, trailing);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns the character offset for the specified point.
- * For a typical character, the trailing argument will be filled in to
- * indicate whether the point is closer to the leading edge (0) or
- * the trailing edge (1). When the point is over a cluster composed
- * of multiple characters, the trailing argument will be filled with the
- * position of the character in the cluster that is closest to
- * the point.
- *
- * @param x the x coordinate of the point
- * @param y the y coordinate of the point
- * @param trailing the trailing buffer
- * @return the character offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getLocation(int, boolean)
- */
-public int getOffset(int x, int y, int[] trailing) {
- checkLayout();
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- computeRuns();
- if (trailing != null && trailing.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int length = text.length();
- if (length == 0) return 0;
- NSPoint pt = new NSPoint();
- pt.x = x;
- pt.y = y;
- float /*double*/[] partialFration = new float /*double*/[1];
- int /*long*/ glyphIndex = layoutManager.glyphIndexForPoint(pt, textContainer, partialFration);
- int /*long*/ offset = layoutManager.characterIndexForGlyphAtIndex(glyphIndex);
- if (trailing != null) trailing[0] = Math.round((float)/*64*/partialFration[0]);
- return Math.min(untranslateOffset((int)/*64*/offset), length - 1);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns the orientation of the receiver.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getOrientation() {
- checkLayout();
- return orientation;
-}
-
-/**
- * Returns the previous offset for the specified offset and movement
- * type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>,
- * <code>SWT.MOVEMENT_CLUSTER</code> or <code>SWT.MOVEMENT_WORD</code>,
- * <code>SWT.MOVEMENT_WORD_END</code> or <code>SWT.MOVEMENT_WORD_START</code>.
- *
- * @param offset the start offset
- * @param movement the movement type
- * @return the previous offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getNextOffset(int, int)
- */
-public int getPreviousOffset (int index, int movement) {
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- return _getOffset(index, movement, false);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Gets the ranges of text that are associated with a <code>TextStyle</code>.
- *
- * @return the ranges, an array of offsets representing the start and end of each
- * text style.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getStyles()
- *
- * @since 3.2
- */
-public int[] getRanges () {
- checkLayout();
- int[] result = new int[styles.length * 2];
- int count = 0;
- for (int i=0; i<styles.length - 1; i++) {
- if (styles[i].style != null) {
- result[count++] = styles[i].start;
- result[count++] = styles[i + 1].start - 1;
- }
- }
- if (count != result.length) {
- int[] newResult = new int[count];
- System.arraycopy(result, 0, newResult, 0, count);
- result = newResult;
- }
- return result;
-}
-
-/**
- * Returns the text segments offsets of the receiver.
- *
- * @return the text segments offsets
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getSegments() {
- checkLayout();
- return segments;
-}
-
-String getSegmentsText() {
- if (segments == null) return text;
- int nSegments = segments.length;
- if (nSegments <= 1) return text;
- int length = text.length();
- if (length == 0) return text;
- if (nSegments == 2) {
- if (segments[0] == 0 && segments[1] == length) return text;
- }
- invalidOffsets = new int[nSegments];
- char[] oldChars = new char[length];
- text.getChars(0, length, oldChars, 0);
- char[] newChars = new char[length + nSegments];
- int charCount = 0, segmentCount = 0;
- char separator = getOrientation() == SWT.RIGHT_TO_LEFT ? RTL_MARK : LTR_MARK;
- while (charCount < length) {
- if (segmentCount < nSegments && charCount == segments[segmentCount]) {
- invalidOffsets[segmentCount] = charCount + segmentCount;
- newChars[charCount + segmentCount++] = separator;
- } else {
- newChars[charCount + segmentCount] = oldChars[charCount++];
- }
- }
- if (segmentCount < nSegments) {
- invalidOffsets[segmentCount] = charCount + segmentCount;
- segments[segmentCount] = charCount;
- newChars[charCount + segmentCount++] = separator;
- }
- if (segmentCount != nSegments) {
- int[] tmp = new int [segmentCount];
- System.arraycopy(invalidOffsets, 0, tmp, 0, segmentCount);
- invalidOffsets = tmp;
- }
- return new String(newChars, 0, Math.min(charCount + segmentCount, newChars.length));
-}
-
-/**
- * Returns the line spacing of the receiver.
- *
- * @return the line spacing
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getSpacing () {
- checkLayout();
- return spacing;
-}
-
-/**
- * Gets the style of the receiver at the specified character offset.
- *
- * @param offset the text offset
- * @return the style or <code>null</code> if not set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public TextStyle getStyle (int offset) {
- checkLayout();
- int length = text.length();
- if (!(0 <= offset && offset < length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- for (int i=1; i<styles.length; i++) {
- StyleItem item = styles[i];
- if (item.start > offset) {
- return styles[i - 1].style;
- }
- }
- return null;
-}
-
-/**
- * Gets all styles of the receiver.
- *
- * @return the styles
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getRanges()
- *
- * @since 3.2
- */
-public TextStyle[] getStyles () {
- checkLayout();
- TextStyle[] result = new TextStyle[styles.length];
- int count = 0;
- for (int i=0; i<styles.length; i++) {
- if (styles[i].style != null) {
- result[count++] = styles[i].style;
- }
- }
- if (count != result.length) {
- TextStyle[] newResult = new TextStyle[count];
- System.arraycopy(result, 0, newResult, 0, count);
- result = newResult;
- }
- return result;
-}
-
-/**
- * Returns the tab list of the receiver.
- *
- * @return the tab list
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getTabs() {
- checkLayout();
- return tabs;
-}
-
-/**
- * Gets the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public String getText () {
- checkLayout ();
- return text;
-}
-
-/**
- * Returns the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getWidth () {
- checkLayout();
- return wrapWidth;
-}
-
-/**
- * Returns <code>true</code> if the text layout has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the text layout.
- * When a text layout has been disposed, it is an error to
- * invoke any other method using the text layout.
- * </p>
- *
- * @return <code>true</code> when the text layout is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- return device == null;
-}
-
-/*
- * Returns true if the underline style is supported natively
- */
-boolean isUnderlineSupported (TextStyle style) {
- if (style != null && style.underline) {
- int uStyle = style.underlineStyle;
- return uStyle == SWT.UNDERLINE_SINGLE || uStyle == SWT.UNDERLINE_DOUBLE || uStyle == SWT.UNDERLINE_LINK || uStyle == UNDERLINE_THICK;
- }
- return false;
-}
-
-/**
- * Sets the text alignment for the receiver. The alignment controls
- * how a line of text is positioned horizontally. The argument should
- * be one of <code>SWT.LEFT</code>, <code>SWT.RIGHT</code> or <code>SWT.CENTER</code>.
- * <p>
- * The default alignment is <code>SWT.LEFT</code>. Note that the receiver's
- * width must be set in order to use <code>SWT.RIGHT</code> or <code>SWT.CENTER</code>
- * alignment.
- * </p>
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setWidth(int)
- */
-public void setAlignment (int alignment) {
- checkLayout();
- int mask = SWT.LEFT | SWT.CENTER | SWT.RIGHT;
- alignment &= mask;
- if (alignment == 0) return;
- if ((alignment & SWT.LEFT) != 0) alignment = SWT.LEFT;
- if ((alignment & SWT.RIGHT) != 0) alignment = SWT.RIGHT;
- if (this.alignment == alignment) return;
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- freeRuns();
- this.alignment = alignment;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Sets the ascent of the receiver. The ascent is distance in pixels
- * from the baseline to the top of the line and it is applied to all
- * lines. The default value is <code>-1</code> which means that the
- * ascent is calculated from the line fonts.
- *
- * @param ascent the new ascent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the ascent is less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setDescent(int)
- * @see #getLineMetrics(int)
- */
-public void setAscent (int ascent) {
- checkLayout ();
- if (ascent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.ascent == ascent) return;
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- freeRuns();
- this.ascent = ascent;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Sets the descent of the receiver. The descent is distance in pixels
- * from the baseline to the bottom of the line and it is applied to all
- * lines. The default value is <code>-1</code> which means that the
- * descent is calculated from the line fonts.
- *
- * @param descent the new descent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the descent is less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAscent(int)
- * @see #getLineMetrics(int)
- */
-public void setDescent (int descent) {
- checkLayout ();
- if (descent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.descent == descent) return;
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- freeRuns();
- this.descent = descent;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Sets the default font which will be used by the receiver
- * to draw and measure text. If the
- * argument is null, then a default font appropriate
- * for the platform will be used instead. Note that a text
- * style can override the default font.
- *
- * @param font the new font for the receiver, or null to indicate a default font
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkLayout ();
- if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Font oldFont = this.font;
- if (oldFont == font) return;
- this.font = font;
- if (oldFont != null && oldFont.equals(font)) return;
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- freeRuns();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Sets the indent of the receiver. This indent it applied of the first line of
- * each paragraph.
- *
- * @param indent new indent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setIndent (int indent) {
- checkLayout ();
- if (indent < 0) return;
- if (this.indent == indent) return;
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- freeRuns();
- this.indent = indent;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Sets the justification of the receiver. Note that the receiver's
- * width must be set in order to use justification.
- *
- * @param justify new justify
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setJustify (boolean justify) {
- checkLayout ();
- if (justify == this.justify) return;
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- freeRuns();
- this.justify = justify;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setOrientation(int orientation) {
- checkLayout();
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- orientation &= mask;
- if (orientation == 0) return;
- if ((orientation & SWT.LEFT_TO_RIGHT) != 0) orientation = SWT.LEFT_TO_RIGHT;
- if (this.orientation == orientation) return;
- this.orientation = orientation;
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- freeRuns();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Sets the offsets of the receiver's text segments. Text segments are used to
- * override the default behaviour of the bidirectional algorithm.
- * Bidirectional reordering can happen within a text segment but not
- * between two adjacent segments.
- * <p>
- * Each text segment is determined by two consecutive offsets in the
- * <code>segments</code> arrays. The first element of the array should
- * always be zero and the last one should always be equals to length of
- * the text.
- * </p>
- *
- * @param segments the text segments offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setSegments(int[] segments) {
- checkLayout();
- if (this.segments == null && segments == null) return;
- if (this.segments != null && segments !=null) {
- if (this.segments.length == segments.length) {
- int i;
- for (i = 0; i <segments.length; i++) {
- if (this.segments[i] != segments[i]) break;
- }
- if (i == segments.length) return;
- }
- }
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- freeRuns();
- this.segments = segments;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Sets the line spacing of the receiver. The line spacing
- * is the space left between lines.
- *
- * @param spacing the new line spacing
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the spacing is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setSpacing (int spacing) {
- checkLayout();
- if (spacing < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.spacing == spacing) return;
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- freeRuns();
- this.spacing = spacing;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Sets the style of the receiver for the specified range. Styles previously
- * set for that range will be overwritten. The start and end offsets are
- * inclusive and will be clamped if out of range.
- *
- * @param style the style
- * @param start the start offset
- * @param end the end offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setStyle (TextStyle style, int start, int end) {
- checkLayout();
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- int length = text.length();
- if (length == 0) return;
- if (start > end) return;
- start = Math.min(Math.max(0, start), length - 1);
- end = Math.min(Math.max(0, end), length - 1);
- int low = -1;
- int high = styles.length;
- while (high - low > 1) {
- int index = (high + low) / 2;
- if (styles[index + 1].start > start) {
- high = index;
- } else {
- low = index;
- }
- }
- if (0 <= high && high < styles.length) {
- StyleItem item = styles[high];
- if (item.start == start && styles[high + 1].start - 1 == end) {
- if (style == null) {
- if (item.style == null) return;
- } else {
- if (style.equals(item.style)) return;
- }
- }
- }
- freeRuns();
- int modifyStart = high;
- int modifyEnd = modifyStart;
- while (modifyEnd < styles.length) {
- if (styles[modifyEnd + 1].start > end) break;
- modifyEnd++;
- }
- if (modifyStart == modifyEnd) {
- int styleStart = styles[modifyStart].start;
- int styleEnd = styles[modifyEnd + 1].start - 1;
- if (styleStart == start && styleEnd == end) {
- styles[modifyStart].style = style;
- return;
- }
- if (styleStart != start && styleEnd != end) {
- StyleItem[] newStyles = new StyleItem[styles.length + 2];
- System.arraycopy(styles, 0, newStyles, 0, modifyStart + 1);
- StyleItem item = new StyleItem();
- item.start = start;
- item.style = style;
- newStyles[modifyStart + 1] = item;
- item = new StyleItem();
- item.start = end + 1;
- item.style = styles[modifyStart].style;
- newStyles[modifyStart + 2] = item;
- System.arraycopy(styles, modifyEnd + 1, newStyles, modifyEnd + 3, styles.length - modifyEnd - 1);
- styles = newStyles;
- return;
- }
- }
- if (start == styles[modifyStart].start) modifyStart--;
- if (end == styles[modifyEnd + 1].start - 1) modifyEnd++;
- int newLength = styles.length + 1 - (modifyEnd - modifyStart - 1);
- StyleItem[] newStyles = new StyleItem[newLength];
- System.arraycopy(styles, 0, newStyles, 0, modifyStart + 1);
- StyleItem item = new StyleItem();
- item.start = start;
- item.style = style;
- newStyles[modifyStart + 1] = item;
- styles[modifyEnd].start = end + 1;
- System.arraycopy(styles, modifyEnd, newStyles, modifyStart + 2, styles.length - modifyEnd);
- styles = newStyles;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Sets the receiver's tab list. Each value in the tab list specifies
- * the space in pixels from the origin of the text layout to the respective
- * tab stop. The last tab stop width is repeated continuously.
- *
- * @param tabs the new tab list
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setTabs(int[] tabs) {
- checkLayout();
- if (this.tabs == null && tabs == null) return;
- if (this.tabs != null && tabs !=null) {
- if (this.tabs.length == tabs.length) {
- int i;
- for (i = 0; i < tabs.length; i++) {
- if (this.tabs[i] != tabs[i]) break;
- }
- if (i == tabs.length) return;
- }
- }
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- freeRuns();
- this.tabs = tabs;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Sets the receiver's text.
- *<p>
- * Note: Setting the text also clears all the styles. This method
- * returns without doing anything if the new text is the same as
- * the current text.
- * </p>
- *
- * @param text the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setText (String text) {
- checkLayout ();
- if (text == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (text.equals(this.text)) return;
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- freeRuns();
- this.text = text;
- styles = new StyleItem[2];
- styles[0] = new StyleItem();
- styles[1] = new StyleItem();
- styles[styles.length - 1].start = text.length();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Sets the line width of the receiver, which determines how
- * text should be wrapped and aligned. The default value is
- * <code>-1</code> which means wrapping is disabled.
- *
- * @param width the new width
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the width is <code>0</code> or less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAlignment(int)
- */
-public void setWidth (int width) {
- checkLayout();
- if (width < -1 || width == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.wrapWidth == width) return;
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- freeRuns();
- this.wrapWidth = width;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "TextLayout {*DISPOSED*}";
- return "TextLayout {" + text + "}";
-}
-
-/*
- * Translate a client offset to an internal offset
- */
-int translateOffset (int offset) {
- int length = text.length();
- if (length == 0) return offset;
- if (invalidOffsets == null) return offset;
- for (int i = 0; i < invalidOffsets.length; i++) {
- if (offset < invalidOffsets[i]) break;
- offset++;
- }
- return offset;
-}
-
-/*
- * Translate an internal offset to a client offset
- */
-int untranslateOffset (int offset) {
- int length = text.length();
- if (length == 0) return offset;
- if (invalidOffsets == null) return offset;
- for (int i = 0; i < invalidOffsets.length; i++) {
- if (offset == invalidOffsets[i]) {
- offset++;
- continue;
- }
- if (offset < invalidOffsets[i]) {
- return offset - i;
- }
- }
- return offset - invalidOffsets.length;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Transform.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Transform.java
deleted file mode 100755
index b4eee32e72..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Transform.java
+++ /dev/null
@@ -1,477 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class represent transformation matrices for
- * points expressed as (x, y) pairs of floating point numbers.
- * <p>
- * Application code must explicitly invoke the <code>Transform.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Transform extends Resource {
- /**
- * the OS resource for the Transform
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public NSAffineTransform handle;
-
-/**
- * Constructs a new identity Transform.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform (Device device) {
- this(device, 1, 0, 0, 1, 0, 0);
-}
-
-/**
- * Constructs a new Transform given an array of elements that represent the
- * matrix that describes the transformation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- * @param elements an array of floats that describe the transformation matrix
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device, or the elements array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the elements array is too small to hold the matrix values</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform(Device device, float[] elements) {
- this (device, checkTransform(elements)[0], elements[1], elements[2], elements[3], elements[4], elements[5]);
-}
-
-/**
- * Constructs a new Transform given all of the elements that represent the
- * matrix that describes the transformation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- * @param m11 the first element of the first row of the matrix
- * @param m12 the second element of the first row of the matrix
- * @param m21 the first element of the second row of the matrix
- * @param m22 the second element of the second row of the matrix
- * @param dx the third element of the first row of the matrix
- * @param dy the third element of the second row of the matrix
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform (Device device, float m11, float m12, float m21, float m22, float dx, float dy) {
- super(device);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- handle = NSAffineTransform.transform();
- if (handle == null) SWT.error(SWT.ERROR_NO_HANDLES);
- handle.retain();
- setElements(m11, m12, m21, m22, dx, dy);
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-static float[] checkTransform(float[] elements) {
- if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return elements;
-}
-
-void destroy() {
- handle.release();
- handle = null;
-}
-
-/**
- * Fills the parameter with the values of the transformation matrix
- * that the receiver represents, in the order {m11, m12, m21, m22, dx, dy}.
- *
- * @param elements array to hold the matrix values
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the matrix values</li>
- * </ul>
- */
-public void getElements(float[] elements) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSAffineTransformStruct struct = handle.transformStruct();
- elements[0] = (float)/*64*/struct.m11;
- elements[1] = (float)/*64*/struct.m12;
- elements[2] = (float)/*64*/struct.m21;
- elements[3] = (float)/*64*/struct.m22;
- elements[4] = (float)/*64*/struct.tX;
- elements[5] = (float)/*64*/struct.tY;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes the
- * identity matrix.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public void identity() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSAffineTransformStruct struct = new NSAffineTransformStruct();
- struct.m11 = 1;
- struct.m22 = 1;
- handle.setTransformStruct(struct);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes
- * the mathematical inverse of the matrix it previously represented.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_CANNOT_INVERT_MATRIX - if the matrix is not invertible</li>
- * </ul>
- */
-public void invert() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSAffineTransformStruct struct = handle.transformStruct();
- if ((struct.m11 * struct.m22 - struct.m12 * struct.m21) == 0) {
- SWT.error(SWT.ERROR_CANNOT_INVERT_MATRIX);
- }
- handle.invert();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns <code>true</code> if the Transform has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Transform.
- * When a Transform has been disposed, it is an error to
- * invoke any other method using the Transform.
- *
- * @return <code>true</code> when the Transform is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == null;
-}
-
-/**
- * Returns <code>true</code> if the Transform represents the identity matrix
- * and false otherwise.
- *
- * @return <code>true</code> if the receiver is an identity Transform, and <code>false</code> otherwise
- */
-public boolean isIdentity() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSAffineTransformStruct struct = handle.transformStruct();
- return struct.m11 == 1 && struct.m12 == 0 && struct.m21 == 0 && struct.m22 == 1 && struct.tX == 0 && struct.tY == 0;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes the
- * the result of multiplying the matrix it previously represented by the
- * argument.
- *
- * @param matrix the matrix to multiply the receiver by
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- */
-public void multiply(Transform matrix) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (matrix == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (matrix.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- handle.prependTransform(matrix.handle);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation rotated by the specified angle.
- * The angle is specified in degrees and for the identity transform 0 degrees
- * is at the 3 o'clock position. A positive value indicates a clockwise rotation
- * while a negative value indicates a counter-clockwise rotation.
- *
- * @param angle the angle to rotate the transformation by
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void rotate(float angle) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- handle.rotateByDegrees(angle);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation scaled by (scaleX, scaleY).
- *
- * @param scaleX the amount to scale in the X direction
- * @param scaleY the amount to scale in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void scale(float scaleX, float scaleY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- handle.scaleXBy(scaleX, scaleY);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Modifies the receiver to represent a new transformation given all of
- * the elements that represent the matrix that describes that transformation.
- *
- * @param m11 the first element of the first row of the matrix
- * @param m12 the second element of the first row of the matrix
- * @param m21 the first element of the second row of the matrix
- * @param m22 the second element of the second row of the matrix
- * @param dx the third element of the first row of the matrix
- * @param dy the third element of the second row of the matrix
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setElements(float m11, float m12, float m21, float m22, float dx, float dy) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSAffineTransformStruct struct = new NSAffineTransformStruct();
- struct.m11 = m11;
- struct.m12 = m12;
- struct.m21 = m21;
- struct.m22 = m22;
- struct.tX = dx;
- struct.tY = dy;
- handle.setTransformStruct(struct);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation sheared by (shearX, shearY).
- *
- * @param shearX the shear factor in the X direction
- * @param shearY the shear factor in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public void shear(float shearX, float shearY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSAffineTransformStruct struct = new NSAffineTransformStruct();
- struct.m11 = 1;
- struct.m12 = shearX;
- struct.m21 = shearY;
- struct.m22 = 1;
- NSAffineTransform matrix = NSAffineTransform.transform();
- matrix.setTransformStruct(struct);
- handle.prependTransform(matrix);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Given an array containing points described by alternating x and y values,
- * modify that array such that each point has been replaced with the result of
- * applying the transformation represented by the receiver to that point.
- *
- * @param pointArray an array of alternating x and y values to be transformed
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void transform(float[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSPoint point = new NSPoint();
- int length = pointArray.length / 2;
- for (int i = 0, j = 0; i < length; i++, j += 2) {
- point.x = pointArray[j];
- point.y = pointArray[j + 1];
- point = handle.transformPoint(point);
- pointArray[j] = (float)/*64*/point.x;
- pointArray[j + 1] = (float)/*64*/point.y;
- }
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation translated by (offsetX, offsetY).
- *
- * @param offsetX the distance to translate in the X direction
- * @param offsetY the distance to translate in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void translate(float offsetX, float offsetY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- handle.translateXBy(offsetX, offsetY);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString() {
- if (isDisposed()) return "Transform {*DISPOSED*}";
- float[] elements = new float[6];
- getElements(elements);
- return "Transform {" + elements [0] + ", " + elements [1] + ", " +elements [2] + ", " +elements [3] + ", " +elements [4] + ", " +elements [5] + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java
deleted file mode 100755
index c6386e25a4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java
+++ /dev/null
@@ -1,846 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.accessibility.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class represent a selectable user interface object that
- * issues notification when pressed and released.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>ARROW, CHECK, PUSH, RADIO, TOGGLE, FLAT</dd>
- * <dd>UP, DOWN, LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles ARROW, CHECK, PUSH, RADIO, and TOGGLE
- * may be specified.
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT, and CENTER may be specified.
- * </p><p>
- * Note: Only one of the styles UP, DOWN, LEFT, and RIGHT may be specified
- * when the ARROW style is specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#button">Button snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Button extends Control {
- String text;
- Image image;
- boolean grayed;
-
- static final int EXTRA_HEIGHT = 2;
- static final int EXTRA_WIDTH = 6;
- static final int IMAGE_GAP = 2;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#ARROW
- * @see SWT#CHECK
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#TOGGLE
- * @see SWT#FLAT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Button (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-int /*long*/ accessibilityAttributeValue (int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- NSString nsAttributeName = new NSString(arg0);
-
- if (accessible != null) {
- id returnObject = accessible.internal_accessibilityAttributeValue(nsAttributeName, ACC.CHILDID_SELF);
- if (returnObject != null) return returnObject.id;
- }
-
- if (nsAttributeName.isEqualToString (OS.NSAccessibilityRoleAttribute) || nsAttributeName.isEqualToString (OS.NSAccessibilityRoleDescriptionAttribute)) {
- NSString role = null;
-
- if ((style & SWT.RADIO) != 0) {
- role = OS.NSAccessibilityRadioButtonRole;
- } else if ((style & SWT.ARROW) != 0) {
- role = OS.NSAccessibilityButtonRole;
- }
-
- if (role != null) {
- if (nsAttributeName.isEqualToString (OS.NSAccessibilityRoleAttribute))
- return role.id;
- else {
- return OS.NSAccessibilityRoleDescription(role.id, 0);
- }
- }
- }
-
- return super.accessibilityAttributeValue(id, sel, arg0);
-}
-
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected by the user.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-NSSize cellSize (int /*long*/ id, int /*long*/ sel) {
- NSSize size = super.cellSize(id, sel);
- if (image != null && ((style & (SWT.CHECK|SWT.RADIO)) !=0)) {
- NSSize imageSize = image.handle.size();
- size.width += imageSize.width + IMAGE_GAP;
- size.height = Math.max(size.height, imageSize.height);
- }
- return size;
-}
-
-static int checkStyle (int style) {
- style = checkBits (style, SWT.PUSH, SWT.ARROW, SWT.CHECK, SWT.RADIO, SWT.TOGGLE, 0);
- if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) {
- return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0);
- }
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0);
- }
- if ((style & SWT.ARROW) != 0) {
- style |= SWT.NO_FOCUS;
- return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0);
- }
- return style;
-}
-
-void click () {
- postEvent (SWT.Selection);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- if ((style & SWT.ARROW) != 0) {
- // TODO use some OS metric instead of hardcoded values
- int width = wHint != SWT.DEFAULT ? wHint : 14;
- int height = hHint != SWT.DEFAULT ? hHint : 14;
- return new Point (width, height);
- }
- NSSize size = ((NSButton)view).cell ().cellSize ();
- int width = (int)Math.ceil (size.width);
- int height = (int)Math.ceil (size.height);
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0 && (style & SWT.FLAT) == 0) {
- if (display.smallFonts) height += EXTRA_HEIGHT;
- width += EXTRA_WIDTH;
- }
- return new Point (width, height);
-}
-
-NSAttributedString createString() {
- NSAttributedString attribStr = createString(text, null, foreground, style, true, true);
- attribStr.autorelease();
- return attribStr;
-}
-
-void createHandle () {
- if ((style & SWT.PUSH) == 0) state |= THEME_BACKGROUND;
- NSButton widget = (NSButton)new SWTButton().alloc();
- widget.init();
- /*
- * Feature in Cocoa. Images touch the edge of rounded buttons
- * when set to small size. The fix to subclass the button cell
- * and offset the image drawing.
- */
-// if (display.smallFonts && (style & (SWT.PUSH | SWT.TOGGLE)) != 0 && (style & SWT.FLAT) == 0) {
- NSButtonCell cell = (NSButtonCell)new SWTButtonCell ().alloc ().init ();
- widget.setCell (cell);
- cell.release ();
-// }
- int type = OS.NSMomentaryLightButton;
- if ((style & SWT.PUSH) != 0) {
- if ((style & SWT.FLAT) != 0) {
- widget.setBezelStyle(OS.NSShadowlessSquareBezelStyle);
-// if ((style & SWT.BORDER) == 0) widget.setShowsBorderOnlyWhileMouseInside(true);
- } else {
- widget.setBezelStyle(OS.NSRoundedBezelStyle);
- }
- } else if ((style & SWT.CHECK) != 0) {
- type = OS.NSSwitchButton;
- } else if ((style & SWT.RADIO) != 0) {
- type = OS.NSRadioButton;
- } else if ((style & SWT.TOGGLE) != 0) {
- type = OS.NSPushOnPushOffButton;
- if ((style & SWT.FLAT) != 0) {
- widget.setBezelStyle(OS.NSShadowlessSquareBezelStyle);
-// if ((style & SWT.BORDER) == 0) widget.setShowsBorderOnlyWhileMouseInside(true);
- } else {
- widget.setBezelStyle(OS.NSRoundedBezelStyle);
- }
- } else if ((style & SWT.ARROW) != 0) {
- widget.setBezelStyle(OS.NSShadowlessSquareBezelStyle);
- }
- widget.setButtonType(type);
- widget.setTitle(NSString.stringWith(""));
- widget.setImagePosition(OS.NSImageLeft);
- widget.setTarget(widget);
- widget.setAction(OS.sel_sendSelection);
- view = widget;
- _setAlignment(style);
-}
-
-void createWidget() {
- text = "";
- super.createWidget ();
-}
-
-NSFont defaultNSFont() {
- return display.buttonFont;
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget(((NSControl)view).cell());
-}
-
-boolean dragDetect(int x, int y, boolean filter, boolean[] consume) {
- boolean dragging = super.dragDetect(x, y, filter, consume);
- consume[0] = dragging;
- return dragging;
-}
-
-void drawImageWithFrameInView (int /*long*/ id, int /*long*/ sel, int /*long*/ image, NSRect rect, int /*long*/ view) {
- /*
- * Feature in Cocoa. Images touch the edge of rounded buttons
- * when set to small size. The fix to subclass the button cell
- * and offset the image drawing.
- */
- if (display.smallFonts && (style & (SWT.PUSH | SWT.TOGGLE)) != 0 && (style & SWT.FLAT) == 0) {
- rect.y += EXTRA_HEIGHT / 2;
- rect.height += EXTRA_HEIGHT;
- }
- callSuper (id, sel, image, rect, view);
-}
-
-void drawInteriorWithFrame_inView (int /*long*/ id, int /*long*/ sel, NSRect cellRect, int /*long*/ viewid) {
- super.drawInteriorWithFrame_inView(id, sel, cellRect, viewid);
- if (image != null && ((style & (SWT.CHECK|SWT.RADIO)) !=0)) {
- NSSize imageSize = image.handle.size();
- NSCell nsCell = new NSCell(id);
- float /*double*/ x = 0;
- float /*double*/ y = (imageSize.height - cellRect.height)/2f;
- NSRect imageRect = nsCell.imageRectForBounds(cellRect);
- NSSize stringSize = ((NSButton)view).attributedTitle().size();
- switch (style & (SWT.LEFT|SWT.RIGHT|SWT.CENTER)) {
- case SWT.LEFT:
- x = imageRect.x + imageRect.width + IMAGE_GAP;
- break;
- case SWT.CENTER:
- x = cellRect.x + imageRect.x + imageRect.width + ((cellRect.width-stringSize.width)/2f) - imageSize.width - IMAGE_GAP;
- break;
- case SWT.RIGHT:
- x = cellRect.x + cellRect.width - stringSize.width - imageSize.width - IMAGE_GAP;
- break;
- }
- NSRect destRect = new NSRect();
- destRect.x = x;
- destRect.y = y;
- destRect.width = imageSize.width;
- destRect.height = imageSize.height;
- NSGraphicsContext.static_saveGraphicsState();
- NSAffineTransform transform = NSAffineTransform.transform();
- transform.scaleXBy(1, -1);
- transform.translateXBy(0, -imageSize.height);
- transform.concat();
- image.handle.drawInRect(destRect, new NSRect(), OS.NSCompositeSourceOver, 1);
- NSGraphicsContext.static_restoreGraphicsState();
- }
-
-}
-
-void drawWidget (int /*long*/ id, NSGraphicsContext context, NSRect rect) {
- if ((style & SWT.ARROW) != 0) {
- NSRect frame = view.frame();
- int arrowSize = Math.min((int)frame.height, (int)frame.width) / 2;
- context.saveGraphicsState();
- NSPoint p1 = new NSPoint();
- p1.x = -arrowSize / 2;
- p1.y = -arrowSize / 2;
- NSPoint p2 = new NSPoint();
- p2.x = arrowSize / 2;
- p2.y = p1.y;
- NSPoint p3 = new NSPoint();
- p3.y = arrowSize / 2;
-
- NSBezierPath path = NSBezierPath.bezierPath();
- path.moveToPoint(p1);
- path.lineToPoint(p2);
- path.lineToPoint(p3);
- path.closePath();
-
- NSAffineTransform transform = NSAffineTransform.transform();
- if ((style & SWT.LEFT) != 0) {
- transform.rotateByDegrees(90);
- } else if ((style & SWT.UP) != 0) {
- transform.rotateByDegrees(180);
- } else if ((style & SWT.RIGHT) != 0) {
- transform.rotateByDegrees(-90);
- }
- path.transformUsingAffineTransform(transform);
- transform = NSAffineTransform.transform();
- transform.translateXBy(frame.width / 2, frame.height / 2);
- path.transformUsingAffineTransform(transform);
-
- NSColor color = isEnabled() ? NSColor.blackColor() : NSColor.disabledControlTextColor();
- color.set();
- path.fill();
- context.restoreGraphicsState();
- }
- super.drawWidget (id, context, rect);
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is an <code>ARROW</code> button, in
- * which case, the alignment will indicate the direction of
- * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>,
- * <code>UP</code> or <code>DOWN</code>).
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget ();
- if ((style & SWT.ARROW) != 0) {
- if ((style & SWT.UP) != 0) return SWT.UP;
- if ((style & SWT.DOWN) != 0) return SWT.DOWN;
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.UP;
- }
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the widget does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getGrayed() {
- checkWidget ();
- if ((style & SWT.CHECK) == 0) return false;
- return grayed;
-}
-
-/**
- * Returns the receiver's image if it has one, or null
- * if it does not.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked. When it is of type <code>TOGGLE</code>,
- * it is selected when it is pushed in. If the receiver is of any other type,
- * this method returns false.
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget ();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false;
- if ((style & SWT.CHECK) != 0 && grayed) return ((NSButton)view).state() == OS.NSMixedState;
- return ((NSButton)view).state() == OS.NSOnState;
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set or if the receiver is
- * an <code>ARROW</code> button.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-boolean isDescribedByLabel () {
- return false;
-}
-
-/*
- * Feature in Cocoa. If a checkbox is in multi-state mode, nextState cycles from off to mixed to on and back to off again.
- * This will cause the on state to momentarily appear while clicking on the checkbox. To avoid this, we override [NSCell nextState]
- * to go directly to the desired state if we have a grayed checkbox.
- */
-int /*long*/ nextState(int /*long*/ id, int /*long*/ sel) {
- if ((style & SWT.CHECK) != 0 && grayed) {
- return ((NSButton)view).state() == OS.NSMixedState ? OS.NSOffState : OS.NSMixedState;
- }
-
- return super.nextState(id, sel);
-}
-
-void register() {
- super.register();
- display.addWidget(((NSControl)view).cell(), this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- image = null;
- text = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-
-void selectRadio () {
- /*
- * This code is intentionally commented. When two groups
- * of radio buttons with the same parent are separated by
- * another control, the correct behavior should be that
- * the two groups act independently. This is consistent
- * with radio tool and menu items. The commented code
- * implements this behavior.
- */
-// int index = 0;
-// Control [] children = parent._getChildren ();
-// while (index < children.length && children [index] != this) index++;
-// int i = index - 1;
-// while (i >= 0 && children [i].setRadioSelection (false)) --i;
-// int j = index + 1;
-// while (j < children.length && children [j].setRadioSelection (false)) j++;
-// setSelection (true);
- Control [] children = parent._getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (this != child) child.setRadioSelection (false);
- }
- setSelection (true);
-}
-
-void sendSelection () {
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) {
- selectRadio ();
- }
- }
- if ((style & SWT.CHECK) != 0) {
- if (grayed && ((NSButton)view).state() == OS.NSOnState) {
- ((NSButton)view).setState(OS.NSOffState);
- }
- if (!grayed && ((NSButton)view).state() == OS.NSMixedState) {
- ((NSButton)view).setState(OS.NSOnState);
- }
- }
- postEvent (SWT.Selection);
-}
-
-
-/**
- * Controls how text, images and arrows will be displayed
- * in the receiver. The argument should be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is an <code>ARROW</code> button, in
- * which case, the argument indicates the direction of
- * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>,
- * <code>UP</code> or <code>DOWN</code>).
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget ();
- _setAlignment (alignment);
- redraw ();
-}
-
-void _setAlignment (int alignment) {
- if ((style & SWT.ARROW) != 0) {
- if ((style & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT)) == 0) return;
- style &= ~(SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT);
- style |= alignment & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT);
-// int orientation = OS.kThemeDisclosureRight;
-// if ((style & SWT.UP) != 0) orientation = OS.kThemeDisclosureUp;
-// if ((style & SWT.DOWN) != 0) orientation = OS.kThemeDisclosureDown;
-// if ((style & SWT.LEFT) != 0) orientation = OS.kThemeDisclosureLeft;
-// OS.SetControl32BitValue (handle, orientation);
- return;
- }
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- /* text is still null when this is called from createHandle() */
- if (text != null) {
- ((NSButton)view).setAttributedTitle(createString());
- }
-// /* Alignment not honoured when image and text is visible */
-// boolean bothVisible = text != null && text.length () > 0 && image != null;
-// if (bothVisible) {
-// if ((style & (SWT.RADIO | SWT.CHECK)) != 0) alignment = SWT.LEFT;
-// if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) alignment = SWT.CENTER;
-// }
-// int textAlignment = 0;
-// int graphicAlignment = 0;
-// if ((alignment & SWT.LEFT) != 0) {
-// textAlignment = OS.kControlBevelButtonAlignTextFlushLeft;
-// graphicAlignment = OS.kControlBevelButtonAlignLeft;
-// }
-// if ((alignment & SWT.CENTER) != 0) {
-// textAlignment = OS.kControlBevelButtonAlignTextCenter;
-// graphicAlignment = OS.kControlBevelButtonAlignCenter;
-// }
-// if ((alignment & SWT.RIGHT) != 0) {
-// textAlignment = OS.kControlBevelButtonAlignTextFlushRight;
-// graphicAlignment = OS.kControlBevelButtonAlignRight;
-// }
-// OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlBevelButtonTextAlignTag, 2, new short [] {(short)textAlignment});
-// OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlBevelButtonGraphicAlignTag, 2, new short [] {(short)graphicAlignment});
-// if (bothVisible) {
-// OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlBevelButtonTextPlaceTag, 2, new short [] {(short)OS.kControlBevelButtonPlaceToRightOfGraphic});
-// }
-}
-
-void updateBackground () {
- NSColor nsColor = null;
- if (backgroundImage != null) {
- nsColor = NSColor.colorWithPatternImage(backgroundImage.handle);
- } else if (background != null) {
- nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]);
- } else {
- return; // TODO set to OS default
- }
- NSButtonCell cell = new NSButtonCell(((NSButton)view).cell());
- cell.setBackgroundColor(nsColor);
-}
-
-void setFont (NSFont font) {
- if (text != null) {
- ((NSButton)view).setAttributedTitle(createString());
- }
-}
-
-void setForeground (float /*double*/ [] color) {
- ((NSButton)view).setAttributedTitle(createString());
-}
-
-/**
- * Sets the grayed state of the receiver. This state change
- * only applies if the control was created with the SWT.CHECK
- * style.
- *
- * @param grayed the new grayed state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setGrayed(boolean grayed) {
- checkWidget ();
- if ((style & SWT.CHECK) == 0) return;
- boolean checked = getSelection ();
- this.grayed = grayed;
- ((NSButton) view).setAllowsMixedState(grayed);
-
- if (checked) {
- if (grayed) {
- ((NSButton) view).setState (OS.NSMixedState);
- } else {
- ((NSButton) view).setState (OS.NSOnState);
- }
- }
-}
-
-/**
- * Sets the receiver's image to the argument, which may be
- * <code>null</code> indicating that no image should be displayed.
- * <p>
- * Note that a Button can display an image and text simultaneously
- * on Windows (starting with XP), GTK+ and OSX. On other platforms,
- * a Button that has an image and text set into it will display the
- * image or text that was set most recently.
- * </p>
- * @param image the image to display on the receiver (may be <code>null</code>)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if ((style & SWT.ARROW) != 0) return;
- this.image = image;
- if ((style & (SWT.RADIO|SWT.CHECK)) == 0) {
- /*
- * Feature in Cocoa. If the NSImage object being set into the button is
- * the same NSImage object that is already there then the button does not
- * redraw itself. This results in the button's image not visually updating
- * if the NSImage object's content has changed since it was last set
- * into the button. The workaround is to explicitly redraw the button.
- */
- ((NSButton)view).setImage(image != null ? image.handle : null);
- view.setNeedsDisplay(true);
- } else {
- ((NSButton)view).setAttributedTitle(createString());
- }
- updateAlignment ();
-}
-
-boolean setRadioSelection (boolean value){
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-
-/**
- * Sets the selection state of the receiver, if it is of type <code>CHECK</code>,
- * <code>RADIO</code>, or <code>TOGGLE</code>.
- *
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked. When it is of type <code>TOGGLE</code>,
- * it is selected when it is pushed in.
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return;
- if (grayed) {
- ((NSButton)view).setState (selected ? OS.NSMixedState : OS.NSOffState);
- } else {
- ((NSButton)view).setState (selected ? OS.NSOnState : OS.NSOffState);
- }
-}
-
-/**
- * Sets the receiver's text.
- * <p>
- * This method sets the button label. The label may include
- * the mnemonic character but must not contain line delimiters.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasized in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p><p>
- * Note that a Button can display an image and text simultaneously
- * on Windows (starting with XP), GTK+ and OSX. On other platforms,
- * a Button that has an image and text set into it will display the
- * image or text that was set most recently.
- * </p>
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.ARROW) != 0) return;
- text = string;
- ((NSButton)view).setAttributedTitle(createString());
- updateAlignment ();
-}
-
-NSRect titleRectForBounds (int /*long*/ id, int /*long*/ sel, NSRect cellFrame) {
- NSRect rect = super.titleRectForBounds(id, sel, cellFrame);
- if (image != null && ((style & (SWT.CHECK|SWT.RADIO)) !=0)) {
- NSSize imageSize = image.handle.size();
- rect.x += imageSize.width + IMAGE_GAP;
- rect.width -= (imageSize.width + IMAGE_GAP);
- rect.width = Math.max(0f, rect.width);
- }
- return rect;
-}
-
-int traversalCode (int key, NSEvent theEvent) {
- int code = super.traversalCode (key, theEvent);
- if ((style & SWT.ARROW) != 0) code &= ~(SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS);
- if ((style & SWT.RADIO) != 0) code |= SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS;
- return code;
-}
-
-void updateAlignment () {
- NSButton widget = (NSButton)view;
- if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) {
- if (text.length() != 0 && image != null) {
- widget.setImagePosition(OS.NSImageLeft);
- } else {
- widget.setImagePosition(text.length() != 0 ? OS.NSNoImage : OS.NSImageOnly);
- }
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Canvas.java
deleted file mode 100755
index 97a2300553..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Canvas.java
+++ /dev/null
@@ -1,512 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class provide a surface for drawing
- * arbitrary graphics.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * This class may be subclassed by custom control implementors
- * who are building controls that are <em>not</em> constructed
- * from aggregates of other controls. That is, they are either
- * painted using SWT graphics calls or are handled by native
- * methods.
- * </p>
- *
- * @see Composite
- * @see <a href="http://www.eclipse.org/swt/snippets/#canvas">Canvas snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class Canvas extends Composite {
- Caret caret;
- IME ime;
- NSOpenGLContext context;
-
-Canvas () {
- /* Do nothing */
-}
-
-int /*long*/ attributedSubstringFromRange (int /*long*/ id, int /*long*/ sel, int /*long*/ range) {
- if (ime != null) return ime.attributedSubstringFromRange (id, sel, range);
- return super.attributedSubstringFromRange(id, sel, range);
-}
-
-void sendFocusEvent(int type) {
- if (caret != null) {
- if (type == SWT.FocusIn) {
- caret.setFocus();
- } else {
- caret.killFocus();
- }
- }
- super.sendFocusEvent(type);
-}
-
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Canvas (Composite parent, int style) {
- super (parent, style);
-}
-
-int /*long*/ characterIndexForPoint (int /*long*/ id, int /*long*/ sel, int /*long*/ point) {
- if (ime != null) return ime.characterIndexForPoint (id, sel, point);
- return super.characterIndexForPoint (id, sel, point);
-}
-
-/**
- * Fills the interior of the rectangle specified by the arguments,
- * with the receiver's background.
- *
- * @param gc the gc where the rectangle is to be filled
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void drawBackground (GC gc, int x, int y, int width, int height) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- Control control = findBackgroundControl ();
- if (control != null) {
- NSRect rect = new NSRect();
- rect.x = x;
- rect.y = y;
- rect.width = width;
- rect.height = height;
- int imgHeight = -1;
- GCData data = gc.getGCData();
- if (data.image != null) imgHeight = data.image.getBounds().height;
- NSGraphicsContext context = gc.handle;
- if (data.flippedContext != null) {
- NSGraphicsContext.static_saveGraphicsState();
- NSGraphicsContext.setCurrentContext(context);
- }
- control.fillBackground (view, context, rect, imgHeight);
- if (data.flippedContext != null) {
- NSGraphicsContext.static_restoreGraphicsState();
- }
- } else {
- gc.fillRectangle (x, y, width, height);
- }
-}
-
-void drawRect (int /*long*/ id, int /*long*/ sel, NSRect rect) {
- if (context != null && context.view() == null) context.setView(view);
- super.drawRect(id, sel, rect);
-}
-
-void drawWidget (int /*long*/ id, NSGraphicsContext context, NSRect rect) {
- if (id != view.id) return;
- super.drawWidget (id, context, rect);
- if (caret == null) return;
- if (caret.isShowing) {
- Image image = caret.image;
- if (image != null) {
- NSImage imageHandle = image.handle;
- NSImageRep imageRep = imageHandle.bestRepresentationForDevice(null);
- if (!imageRep.isKindOfClass(OS.class_NSBitmapImageRep)) return;
- NSBitmapImageRep rep = new NSBitmapImageRep(imageRep);
- CGRect destRect = new CGRect ();
- destRect.origin.x = caret.x;
- destRect.origin.y = caret.y;
- NSSize size = imageHandle.size();
- destRect.size.width = size.width;
- destRect.size.height = size.height;
- int /*long*/ data = rep.bitmapData();
- int /*long*/ bpr = rep.bytesPerRow();
- int alphaInfo = rep.hasAlpha() ? OS.kCGImageAlphaFirst : OS.kCGImageAlphaNoneSkipFirst;
- int /*long*/ provider = OS.CGDataProviderCreateWithData(0, data, bpr * (int)size.height, 0);
- int /*long*/ colorspace = OS.CGColorSpaceCreateDeviceRGB();
- int /*long*/ cgImage = OS.CGImageCreate((int)size.width, (int)size.height, rep.bitsPerSample(), rep.bitsPerPixel(), bpr, colorspace, alphaInfo, provider, 0, true, 0);
- OS.CGColorSpaceRelease(colorspace);
- OS.CGDataProviderRelease(provider);
- int /*long*/ ctx = context.graphicsPort();
- OS.CGContextSaveGState(ctx);
- OS.CGContextScaleCTM (ctx, 1, -1);
- OS.CGContextTranslateCTM (ctx, 0, -(size.height + 2 * destRect.origin.y));
- OS.CGContextSetBlendMode (ctx, OS.kCGBlendModeDifference);
- OS.CGContextDrawImage (ctx, destRect, cgImage);
- OS.CGContextRestoreGState(ctx);
- OS.CGImageRelease(cgImage);
- } else {
- context.saveGraphicsState();
- context.setCompositingOperation(OS.NSCompositeXOR);
- NSRect drawRect = new NSRect();
- drawRect.x = caret.x;
- drawRect.y = caret.y;
- drawRect.width = caret.width != 0 ? caret.width : Caret.DEFAULT_WIDTH;
- drawRect.height = caret.height;
- context.setShouldAntialias(false);
- NSColor color = NSColor.colorWithDeviceRed(1, 1, 1, 1);
- color.set();
- NSBezierPath.fillRect(drawRect);
- context.restoreGraphicsState();
- }
- }
-}
-
-NSRect firstRectForCharacterRange (int /*long*/ id, int /*long*/ sel, int /*long*/ range) {
- if (ime != null) return ime.firstRectForCharacterRange (id, sel, range);
- return super.firstRectForCharacterRange (id, sel, range);
-}
-
-/**
- * Returns the caret.
- * <p>
- * The caret for the control is automatically hidden
- * and shown when the control is painted or resized,
- * when focus is gained or lost and when an the control
- * is scrolled. To avoid drawing on top of the caret,
- * the programmer must hide and show the caret when
- * drawing in the window any other time.
- * </p>
- *
- * @return the caret for the receiver, may be null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Caret getCaret () {
- checkWidget();
- return caret;
-}
-
-/**
- * Returns the IME.
- *
- * @return the IME
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public IME getIME () {
- checkWidget();
- return ime;
-}
-
-boolean hasMarkedText (int /*long*/ id, int /*long*/ sel) {
- if (ime != null) return ime.hasMarkedText (id, sel);
- return super.hasMarkedText (id, sel);
-}
-
-boolean imeInComposition () {
- return ime != null && ime.isInlineEnabled () && ime.startOffset != -1;
-}
-
-boolean insertText (int /*long*/ id, int /*long*/ sel, int /*long*/ string) {
- if (ime != null) {
- if (!ime.insertText (id, sel, string)) return false;
- }
- return super.insertText (id, sel, string);
-}
-
-boolean isOpaque (int /*long*/ id, int /*long*/ sel) {
- if (context != null) return true;
- return super.isOpaque(id, sel);
-}
-
-NSRange markedRange (int /*long*/ id, int /*long*/ sel) {
- if (ime != null) return ime.markedRange (id, sel);
- return super.markedRange (id, sel);
-}
-
-void releaseChildren (boolean destroy) {
- if (caret != null) {
- caret.release (false);
- caret = null;
- }
- if (ime != null) {
- ime.release (false);
- ime = null;
- }
- super.releaseChildren (destroy);
-}
-
-/**
- * Scrolls a rectangular area of the receiver by first copying
- * the source area to the destination and then causing the area
- * of the source which is not covered by the destination to
- * be repainted. Children that intersect the rectangle are
- * optionally moved during the operation. In addition, outstanding
- * paint events are flushed before the source area is copied to
- * ensure that the contents of the canvas are drawn correctly.
- *
- * @param destX the x coordinate of the destination
- * @param destY the y coordinate of the destination
- * @param x the x coordinate of the source
- * @param y the y coordinate of the source
- * @param width the width of the area
- * @param height the height of the area
- * @param all <code>true</code>if children should be scrolled, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) {
- checkWidget();
- if (width <= 0 || height <= 0) return;
- int deltaX = destX - x, deltaY = destY - y;
- if (deltaX == 0 && deltaY == 0) return;
- if (!isDrawing ()) return;
- NSRect visibleRect = view.visibleRect();
- if (visibleRect.width <= 0 || visibleRect.height <= 0) return;
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- Rectangle clientRect = getClientArea ();
- Rectangle sourceRect = new Rectangle (x, y, width, height);
- if (sourceRect.intersects (clientRect)) {
- update (all);
- }
- Control control = findBackgroundControl ();
- boolean redraw = control != null && control.backgroundImage != null;
- if (!redraw) redraw = isObscured ();
- if (redraw) {
- redrawWidget (view, x, y, width, height, false);
- redrawWidget (view, destX, destY, width, height, false);
- } else {
- NSRect damage = new NSRect();
- damage.x = x;
- damage.y = y;
- damage.width = width;
- damage.height = height;
- NSPoint dest = new NSPoint();
- dest.x = destX;
- dest.y = destY;
-
- view.lockFocus();
- OS.NSCopyBits(0, damage , dest);
- view.unlockFocus();
-
- boolean disjoint = (destX + width < x) || (x + width < destX) || (destY + height < y) || (y + height < destY);
- if (disjoint) {
- view.setNeedsDisplayInRect(damage);
- } else {
- if (deltaX != 0) {
- int newX = destX - deltaX;
- if (deltaX < 0) newX = destX + width;
- damage.x = newX;
- damage.width = Math.abs(deltaX);
- view.setNeedsDisplayInRect(damage);
- }
- if (deltaY != 0) {
- int newY = destY - deltaY;
- if (deltaY < 0) newY = destY + height;
- damage.x = x;
- damage.y = newY;
- damage.width = width;
- damage.height = Math.abs (deltaY);
- view.setNeedsDisplayInRect(damage);
- }
- }
-
- NSRect srcRect = new NSRect();
- srcRect.x = sourceRect.x;
- srcRect.y = sourceRect.y;
- srcRect.width = sourceRect.width;
- srcRect.height = sourceRect.height;
- OS.NSIntersectionRect(visibleRect, visibleRect, srcRect);
-
- if (!OS.NSEqualRects(visibleRect, srcRect)) {
- if (srcRect.x != visibleRect.x) {
- damage.x = srcRect.x + deltaX;
- damage.y = srcRect.y + deltaY;
- damage.width = visibleRect.x - srcRect.x;
- damage.height = srcRect.height;
- view.setNeedsDisplayInRect(damage);
- }
- if (visibleRect.x + visibleRect.width != srcRect.x + srcRect.width) {
- damage.x = srcRect.x + visibleRect.width + deltaX;
- damage.y = srcRect.y + deltaY;
- damage.width = srcRect.width - visibleRect.width;
- damage.height = srcRect.height;
- view.setNeedsDisplayInRect(damage);
- }
- if (visibleRect.y != srcRect.y) {
- damage.x = visibleRect.x + deltaX;
- damage.y = srcRect.y + deltaY;
- damage.width = visibleRect.width;
- damage.height = visibleRect.y - srcRect.y;
- view.setNeedsDisplayInRect(damage);
- }
- if (visibleRect.y + visibleRect.height != srcRect.y + srcRect.height) {
- damage.x = visibleRect.x + deltaX;
- damage.y = visibleRect.y + visibleRect.height + deltaY;
- damage.width = visibleRect.width;
- damage.height = srcRect.y + srcRect.height - (visibleRect.y + visibleRect.height);
- view.setNeedsDisplayInRect(damage);
- }
- }
- }
-
- if (all) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- Rectangle rect = child.getBounds ();
- if (Math.min(x + width, rect.x + rect.width) >= Math.max (x, rect.x) &&
- Math.min(y + height, rect.y + rect.height) >= Math.max (y, rect.y)) {
- child.setLocation (rect.x + deltaX, rect.y + deltaY);
- }
- }
- }
- if (isFocus) caret.setFocus ();
-}
-
-NSRange selectedRange (int /*long*/ id, int /*long*/ sel) {
- if (ime != null) return ime.selectedRange (id, sel);
- return super.selectedRange (id, sel);
-}
-
-boolean sendKeyEvent (NSEvent nsEvent, int type) {
- if (caret != null) NSCursor.setHiddenUntilMouseMoves (true);
- return super.sendKeyEvent (nsEvent, type);
-}
-
-/**
- * Sets the receiver's caret.
- * <p>
- * The caret for the control is automatically hidden
- * and shown when the control is painted or resized,
- * when focus is gained or lost and when an the control
- * is scrolled. To avoid drawing on top of the caret,
- * the programmer must hide and show the caret when
- * drawing in the window any other time.
- * </p>
- * @param caret the new caret for the receiver, may be null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the caret has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCaret (Caret caret) {
- checkWidget();
- Caret newCaret = caret;
- Caret oldCaret = this.caret;
- this.caret = newCaret;
- if (hasFocus ()) {
- if (oldCaret != null) oldCaret.killFocus ();
- if (newCaret != null) {
- if (newCaret.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- newCaret.setFocus ();
- }
- }
-}
-
-public void setFont (Font font) {
- checkWidget ();
- if (caret != null) caret.setFont (font);
- super.setFont (font);
-}
-
-void setOpenGLContext(Object value) {
- context = (NSOpenGLContext)value;
-}
-
-/**
- * Sets the receiver's IME.
- *
- * @param ime the new IME for the receiver, may be null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the IME has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setIME (IME ime) {
- checkWidget ();
- if (ime != null && ime.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- this.ime = ime;
-}
-
-boolean setMarkedText_selectedRange (int /*long*/ id, int /*long*/ sel, int /*long*/ string, int /*long*/ range) {
- if (ime != null) {
- if (!ime.setMarkedText_selectedRange (id, sel, string, range)) return false;
- }
- return super.setMarkedText_selectedRange (id, sel, string, range);
-}
-
-int /*long*/ validAttributesForMarkedText (int /*long*/ id, int /*long*/ sel) {
- if (ime != null) return ime.validAttributesForMarkedText (id, sel);
- return super.validAttributesForMarkedText(id, sel);
-}
-
-void updateOpenGLContext(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
- if (context != null) ((NSOpenGLContext)context).update();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Caret.java
deleted file mode 100755
index 410caaa566..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Caret.java
+++ /dev/null
@@ -1,505 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.cocoa.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide an i-beam that is typically used
- * as the insertion point for text.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#caret">Caret snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Canvas tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Caret extends Widget {
- Canvas parent;
- int x, y, width, height;
- boolean isVisible, isShowing;
- int blinkRate;
- Image image;
- Font font;
-
- static final int DEFAULT_WIDTH = 1;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Caret (Canvas parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget ();
-}
-
-boolean blinkCaret () {
- if (!isVisible) return true;
- if (!isShowing) return showCaret ();
- if (blinkRate == 0) return true;
- return hideCaret ();
-}
-
-void createWidget () {
- super.createWidget ();
- blinkRate = display.getCaretBlinkTime ();
- isVisible = true;
- if (parent.getCaret () == null) {
- parent.setCaret (this);
- }
-}
-
-boolean drawCaret () {
- if (parent == null) return false;
- if (parent.isDisposed ()) return false;
- int nWidth = width, nHeight = height;
- if (nWidth <= 0) nWidth = DEFAULT_WIDTH;
- if (image != null) {
- NSSize size = image.handle.size();
- nWidth = (int)size.width;
- nHeight = (int)size.height;
- }
- NSRect rect = new NSRect();
- rect.x = x;
- rect.y = y;
- rect.width = nWidth;
- rect.height = nHeight;
- parent.view.setNeedsDisplayInRect(rect);
- return true;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null).
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- if (image != null) {
- Rectangle rect = image.getBounds ();
- return new Rectangle (x, y, rect.width, rect.height);
- } else {
- if (width == 0) {
- return new Rectangle (x, y, DEFAULT_WIDTH, height);
- }
- }
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Font getFont () {
- checkWidget();
- if (font != null) return font;
- return parent.getFont ();
-}
-
-/**
- * Returns the image that the receiver will use to paint the caret.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null).
- *
- * @return the receiver's location
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getLocation () {
- checkWidget();
- return new Point (x, y);
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Canvas</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Canvas getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns a point describing the receiver's size.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- if (image != null) {
- Rectangle rect = image.getBounds ();
- return new Point (rect.width, rect.height);
- } else {
- if (width == 0) {
- return new Point (DEFAULT_WIDTH, height);
- }
- }
- return new Point (width, height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- return isVisible;
-}
-
-boolean hideCaret () {
- if (!isShowing) return true;
- isShowing = false;
- return drawCaret ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return isVisible && parent.isVisible () && parent.hasFocus ();
-}
-
-boolean isFocusCaret () {
- return this == display.currentCaret;
-}
-
-void killFocus () {
- if (display.currentCaret != this) return;
- display.setCurrentCaret (null);
- if (isVisible) hideCaret ();
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (this == parent.getCaret ()) parent.setCaret (null);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (display.currentCaret == this) {
- hideCaret ();
- display.setCurrentCaret (null);
- }
- parent = null;
- image = null;
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the arguments. The <code>x</code> and
- * <code>y</code> arguments are relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (int x, int y, int width, int height) {
- checkWidget();
- if (this.x == x && this.y == y && this.width == width && this.height == height) return;
- boolean isFocus = isFocusCaret ();
- if (isFocus && isVisible) hideCaret ();
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- if (isFocus && isVisible) showCaret ();
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the argument. The <code>x</code> and
- * <code>y</code> fields of the rectangle are relative to
- * the receiver's parent (or its display if its parent is null).
- *
- * @param rect the new bounds for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (Rectangle rect) {
- checkWidget();
- if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (rect.x, rect.y, rect.width, rect.height);
-}
-
-void setFocus () {
- if (display.currentCaret == this) return;
- display.setCurrentCaret (this);
- if (isVisible) showCaret ();
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * to the font specified by the argument, or to the default font for that
- * kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkWidget();
- if (font != null && font.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.font = font;
-}
-
-/**
- * Sets the image that the receiver will use to paint the caret
- * to the image specified by the argument, or to the default
- * which is a filled rectangle if the argument is null
- *
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- boolean isFocus = isFocusCaret ();
- if (isFocus && isVisible) hideCaret ();
- this.image = image;
- if (isFocus && isVisible) showCaret ();
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget();
- setBounds (x, y, width, height);
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the argument which is relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param location the new location for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (Point location) {
- checkWidget();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-/**
- * Sets the receiver's size to the point specified by the arguments.
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (int width, int height) {
- checkWidget();
- setBounds (x, y, width, height);
-}
-
-/**
- * Sets the receiver's size to the point specified by the argument.
- *
- * @param size the new extent for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (Point size) {
- checkWidget();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSize (size.x, size.y);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget();
- if (visible == isVisible) return;
- isVisible = visible;
- if (!isFocusCaret ()) return;
- if (isVisible) {
- showCaret ();
- } else {
- hideCaret ();
- }
-}
-
-boolean showCaret () {
- if (isShowing) return true;
- isShowing = true;
- return drawCaret ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ColorDialog.java
deleted file mode 100755
index 6ae406f67f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ColorDialog.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class allow the user to select a color
- * from a predefined set of available colors.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ColorDialog extends Dialog {
- RGB rgb;
- boolean selected;
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a composite control which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ColorDialog(Shell parent) {
- this(parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ColorDialog(Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-void changeColor(int /*long*/ id, int /*long*/ sel, int /*long*/ sender) {
- selected = true;
-}
-
-/**
- * Returns the currently selected color in the receiver.
- *
- * @return the RGB value for the selected color, may be null
- *
- * @see PaletteData#getRGBs
- */
-public RGB getRGB() {
- return rgb;
-}
-
-/**
- * Makes the receiver visible and brings it to the front
- * of the display.
- *
- * @return the selected color, or null if the dialog was
- * cancelled, no color was selected, or an error
- * occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public RGB open() {
- NSColorPanel panel = NSColorPanel.sharedColorPanel();
- if (rgb != null) {
- NSColor color = NSColor.colorWithDeviceRed(rgb.red / 255f, rgb.green / 255f, rgb.blue / 255f, 1);
- panel.setColor(color);
- }
- SWTPanelDelegate delegate = (SWTPanelDelegate)new SWTPanelDelegate().alloc().init();
- int /*long*/ jniRef = OS.NewGlobalRef(this);
- if (jniRef == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.object_setInstanceVariable(delegate.id, Display.SWT_OBJECT, jniRef);
- panel.setDelegate(delegate);
- rgb = null;
- selected = false;
- panel.orderFront(null);
- NSApplication.sharedApplication().runModalForWindow(panel);
- panel.setDelegate(null);
- delegate.release();
- OS.DeleteGlobalRef(jniRef);
- if (selected) {
- NSColor color = panel.color();
- if (color != null) {
- color = color.colorUsingColorSpaceName(OS.NSCalibratedRGBColorSpace);
- rgb = new RGB((int)(color.redComponent() * 255), (int)(color.greenComponent() * 255), (int)(color.blueComponent() * 255));
- }
- }
- return rgb;
-}
-
-/**
- * Sets the receiver's selected color to be the argument.
- *
- * @param rgb the new RGB value for the selected color, may be
- * null to let the platform select a default when
- * open() is called
- * @see PaletteData#getRGBs
- */
-public void setRGB(RGB rgb) {
- this.rgb = rgb;
-}
-
-void windowWillClose(int /*long*/ id, int /*long*/ sel, int /*long*/ sender) {
- NSApplication.sharedApplication().stop(null);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Combo.java
deleted file mode 100755
index 2773e1b3c3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Combo.java
+++ /dev/null
@@ -1,1617 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class are controls that allow the user
- * to choose an item from a list of items, or optionally
- * enter a new value by typing it into an editable text
- * field. Often, <code>Combo</code>s are used in the same place
- * where a single selection <code>List</code> widget could
- * be used but space is limited. A <code>Combo</code> takes
- * less space than a <code>List</code> widget and shows
- * similar information.
- * <p>
- * Note: Since <code>Combo</code>s can contain both a list
- * and an editable text field, it is possible to confuse methods
- * which access one versus the other (compare for example,
- * <code>clearSelection()</code> and <code>deselectAll()</code>).
- * The API documentation is careful to indicate either "the
- * receiver's list" or the "the receiver's text field" to
- * distinguish between the two cases.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>DROP_DOWN, READ_ONLY, SIMPLE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Modify, Selection, Verify</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles DROP_DOWN and SIMPLE may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see List
- * @see <a href="http://www.eclipse.org/swt/snippets/#combo">Combo snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Combo extends Composite {
- int textLimit = LIMIT;
- boolean receivingFocus;
- boolean ignoreVerify, ignoreSelection;
- NSRange selectionRange;
-
- /**
- * the operating system limit for the number of characters
- * that the text field in an instance of this class can hold
- */
- public static final int LIMIT;
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0x7FFFFFFF;
- }
-
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see SWT#READ_ONLY
- * @see SWT#SIMPLE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Combo (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the argument to the end of the receiver's list.
- *
- * @param string the new item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String,int)
- */
-public void add (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- NSString str = NSString.stringWith(string);
- if ((style & SWT.READ_ONLY) != 0) {
- NSPopUpButton widget = (NSPopUpButton)view;
- int /*long*/ selection = widget.indexOfSelectedItem();
- NSMenu nsMenu = widget.menu();
- NSMenuItem nsItem = (NSMenuItem)new NSMenuItem().alloc();
- nsItem.initWithTitle(str, 0, NSString.stringWith(""));
- nsMenu.addItem(nsItem);
- nsItem.release();
- if (selection == -1) widget.selectItemAtIndex(-1);
- } else {
- ((NSComboBox)view).addItemWithObjectValue(str);
- }
-}
-
-/**
- * Adds the argument to the receiver's list at the given
- * zero-relative index.
- * <p>
- * Note: To add an item at the end of the list, use the
- * result of calling <code>getItemCount()</code> as the
- * index or use <code>add(String)</code>.
- * </p>
- *
- * @param string the new item
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String)
- */
-public void add (String string, int index) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = getItemCount ();
- if (0 > index || index > count) error (SWT.ERROR_INVALID_RANGE);
- NSString str = NSString.stringWith(string);
- if ((style & SWT.READ_ONLY) != 0) {
- NSPopUpButton widget = (NSPopUpButton)view;
- int /*long*/ selection = widget.indexOfSelectedItem();
- NSMenu nsMenu = widget.menu();
- NSMenuItem nsItem = (NSMenuItem)new NSMenuItem().alloc();
- nsItem.initWithTitle(str, 0, NSString.stringWith(""));
- nsMenu.insertItem(nsItem, index);
- nsItem.release();
- if (selection == -1) widget.selectItemAtIndex(-1);
- } else {
- ((NSComboBox)view).insertItemWithObjectValue(str, index);
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the combo's list selection.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed the combo's text area.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- *
- * @since 3.1
- */
-public void addVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-
-boolean becomeFirstResponder (int /*long*/ id, int /*long*/ sel) {
- receivingFocus = true;
- boolean result = super.becomeFirstResponder (id, sel);
- receivingFocus = false;
- return result;
-}
-
-static int checkStyle (int style) {
- /*
- * Feature in Windows. It is not possible to create
- * a combo box that has a border using Windows style
- * bits. All combo boxes draw their own border and
- * do not use the standard Windows border styles.
- * Therefore, no matter what style bits are specified,
- * clear the BORDER bits so that the SWT style will
- * match the Windows widget.
- *
- * The Windows behavior is currently implemented on
- * all platforms.
- */
- style &= ~SWT.BORDER;
-
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- style &= ~(SWT.H_SCROLL | SWT.V_SCROLL);
- style = checkBits (style, SWT.DROP_DOWN, SWT.SIMPLE, 0, 0, 0, 0);
- if ((style & SWT.SIMPLE) != 0) return style & ~SWT.READ_ONLY;
- return style;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Sets the selection in the receiver's text field to an empty
- * selection starting just before the first character. If the
- * text field is editable, this has the effect of placing the
- * i-beam at the start of the text.
- * <p>
- * Note: To clear the selected items in the receiver's list,
- * use <code>deselectAll()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #deselectAll
- */
-public void clearSelection () {
- checkWidget();
- if ((style & SWT.READ_ONLY) == 0) {
- Point selection = getSelection ();
- selection.y = selection.x;
- setSelection (selection);
- }
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0;
- NSControl widget = (NSControl)view;
- NSCell viewCell = widget.cell ();
- NSSize size = viewCell.cellSize ();
- width = (int)Math.ceil (size.width);
- height = (int)Math.ceil (size.height);
-
- if ((style & SWT.READ_ONLY) == 0) {
- ignoreVerify = true;
- NSComboBoxCell cell = new NSComboBoxCell (viewCell.id);
- NSArray array = cell.objectValues ();
- int length = (int)/*64*/array.count ();
- if (length > 0) {
- cell = new NSComboBoxCell (cell.copy ());
- for (int i = 0; i < length; i++) {
- id object = array.objectAtIndex (i);
- cell.setTitle (new NSString (object));
- size = cell.cellSize ();
- width = Math.max (width, (int)Math.ceil (size.width));
- }
- cell.release ();
- }
- ignoreVerify = false;
- }
-
- /*
- * Feature in Cocoa. Attempting to create an NSComboBox with a
- * height > 27 spews a very long warning message to stdout and
- * often draws the combo incorrectly. The workaround is to limit
- * the returned height of editable Combos to the height that is
- * required to display their text, even if a larger hHint is specified.
- */
- if (hHint != SWT.DEFAULT) {
- if ((style & SWT.READ_ONLY) != 0 || hHint < height) height = hHint;
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- return new Point (width, height);
-}
-
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void copy () {
- checkWidget ();
- Point selection = getSelection ();
- if (selection.x == selection.y) return;
- copyToClipboard (getText (selection.x, selection.y));
-}
-
-void createHandle () {
- if ((style & SWT.READ_ONLY) != 0) {
- NSPopUpButton widget = (NSPopUpButton)new SWTPopUpButton().alloc();
- widget.initWithFrame(new NSRect(), false);
- widget.menu().setAutoenablesItems(false);
- widget.setTarget(widget);
- widget.setAction(OS.sel_sendSelection);
- view = widget;
- } else {
- NSComboBox widget = (NSComboBox)new SWTComboBox().alloc();
- widget.init();
- widget.setDelegate(widget);
- widget.setTarget(widget);
- widget.setAction(OS.sel_sendSelection);
- view = widget;
- }
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void cut () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- Point selection = getSelection ();
- if (selection.x == selection.y) return;
- int start = selection.x, end = selection.y;
- String text = getText ();
- String leftText = text.substring (0, start);
- String rightText = text.substring (end, text.length ());
- String oldText = text.substring (start, end);
- String newText = "";
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- newText = verifyText (newText, start, end, null);
- if (newText == null) return;
- }
- char [] buffer = new char [oldText.length ()];
- oldText.getChars (0, buffer.length, buffer, 0);
- copyToClipboard (buffer);
- setText (leftText + newText + rightText, false);
- start += newText.length ();
- setSelection (new Point (start, start));
- sendEvent (SWT.Modify);
-}
-
-Color defaultBackground () {
- return display.getWidgetColor (SWT.COLOR_LIST_BACKGROUND);
-}
-
-NSFont defaultNSFont() {
- if ((style & SWT.READ_ONLY) != 0) return display.popUpButtonFont;
- return display.comboBoxFont;
-}
-
-Color defaultForeground () {
- return display.getWidgetColor (SWT.COLOR_LIST_FOREGROUND);
-}
-
-void deregister() {
- super.deregister();
- display.removeWidget(((NSControl)view).cell());
-}
-
-/**
- * Deselects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget ();
- if (index == -1) return;
- if (index == getSelectionIndex ()) {
- if ((style & SWT.READ_ONLY) != 0) {
- ((NSPopUpButton)view).selectItem(null);
- sendEvent (SWT.Modify);
- } else {
- ((NSComboBox)view).deselectItemAtIndex(index);
- }
- }
-}
-
-/**
- * Deselects all selected items in the receiver's list.
- * <p>
- * Note: To clear the selection in the receiver's text field,
- * use <code>clearSelection()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #clearSelection
- */
-public void deselectAll () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) {
- ((NSPopUpButton)view).selectItem(null);
- sendEvent (SWT.Modify);
- } else {
- NSComboBox widget = (NSComboBox)view;
- int /*long*/ index = widget.indexOfSelectedItem();
- if (index != -1) widget.deselectItemAtIndex(index);
- }
-}
-
-boolean dragDetect(int x, int y, boolean filter, boolean[] consume) {
- if ((style & SWT.READ_ONLY) == 0) {
- NSText fieldEditor = ((NSControl)view).currentEditor();
- if (fieldEditor != null) {
- NSRange selectedRange = fieldEditor.selectedRange();
- if (selectedRange.length > 0) {
- NSPoint mouseLocation = NSEvent.mouseLocation();
- NSTextView feAsTextView = new NSTextView(fieldEditor);
- int /*long*/ charPosition = feAsTextView.characterIndexForInsertionAtPoint(mouseLocation);
- if (charPosition != OS.NSNotFound && charPosition >= selectedRange.location && charPosition < (selectedRange.location + selectedRange.length)) {
- if (super.dragDetect(x, y, filter, consume)) {
- if (consume != null) consume[0] = true;
- return true;
- }
- }
- }
- }
- return false;
- }
-
- return super.dragDetect(x, y, filter, consume);
-}
-
-int getCharCount() {
- NSString str;
- if ((style & SWT.READ_ONLY) != 0) {
- str = ((NSPopUpButton)view).titleOfSelectedItem();
- } else {
- str = new NSCell(((NSComboBox)view).cell()).title();
- }
- if (str == null) return 0;
- return (int)/*64*/str.length();
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver's list. Throws an exception if the index is out
- * of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getItem (int index) {
- checkWidget ();
- int count = getItemCount ();
- if (0 > index || index >= count) error (SWT.ERROR_INVALID_RANGE);
- NSString str;
- if ((style & SWT.READ_ONLY) != 0) {
- str = ((NSPopUpButton)view).itemTitleAtIndex(index);
- } else {
- str = new NSString(((NSComboBox)view).itemObjectValueAtIndex(index));
- }
- if (str == null) error(SWT.ERROR_CANNOT_GET_ITEM);
- return str.getString();
-}
-
-/**
- * Returns the number of items contained in the receiver's list.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) {
- return (int)/*64*/((NSPopUpButton)view).numberOfItems();
- } else {
- return (int)/*64*/((NSComboBox)view).numberOfItems();
- }
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the receiver's list.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- //TODO - not supported by the OS
- return 26;
-}
-
-/**
- * Returns a (possibly empty) array of <code>String</code>s which are
- * the items in the receiver's list.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver's list
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getItems () {
- checkWidget ();
- int count = getItemCount ();
- String [] result = new String [count];
- for (int i=0; i<count; i++) result [i] = getItem (i);
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver's list is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's list's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getListVisible () {
- //TODO
- return false;
-}
-
-int getMininumHeight () {
- return getTextHeight ();
-}
-
-/**
- * Returns the orientation of the receiver.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getOrientation () {
- checkWidget();
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-/**
- * Returns a <code>Point</code> whose x coordinate is the
- * character position representing the start of the selection
- * in the receiver's text field, and whose y coordinate is the
- * character position representing the end of the selection.
- * An "empty" selection is indicated by the x and y coordinates
- * having the same value.
- * <p>
- * Indexing is zero based. The range of a selection is from
- * 0..N where N is the number of characters in the widget.
- * </p>
- *
- * @return a point representing the selection start and end
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSelection () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) {
- return new Point (0, getCharCount ());
- } else {
- if (selectionRange == null) {
- NSString str = new NSTextFieldCell (((NSTextField) view).cell ()).title ();
- return new Point((int)/*64*/str.length (), (int)/*64*/str.length ());
- }
- return new Point((int)/*64*/selectionRange.location, (int)/*64*/(selectionRange.location + selectionRange.length));
- }
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver's list, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) {
- return (int)/*64*/((NSPopUpButton)view).indexOfSelectedItem();
- } else {
- return (int)/*64*/((NSComboBox)view).indexOfSelectedItem();
- }
-}
-
-/**
- * Returns a string containing a copy of the contents of the
- * receiver's text field, or an empty string if there are no
- * contents.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return new String (getText(0, -1));
-}
-
-char [] getText (int start, int end) {
- NSString str;
- if ((style & SWT.READ_ONLY) != 0) {
- str = ((NSPopUpButton)view).titleOfSelectedItem();
- } else {
- str = new NSCell(((NSComboBox)view).cell()).title();
- }
- if (str == null) return new char[0];
- NSRange range = new NSRange ();
- range.location = start;
- if (end == -1) {
- int /*long*/ length = str.length();
- range.length = length - start;
- } else {
- range.length = end - start;
- }
- char [] buffer= new char [(int)/*64*/range.length];
- str.getCharacters(buffer, range);
- return buffer;
-}
-
-/**
- * Returns the height of the receivers's text field.
- *
- * @return the text height
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTextHeight () {
- checkWidget();
- NSCell cell;
- if ((style & SWT.READ_ONLY) != 0) {
- cell = ((NSPopUpButton)view).cell();
- } else {
- cell = ((NSComboBox)view).cell();
- }
- return (int)cell.cellSize().height;
-}
-
-/**
- * Returns the maximum number of characters that the receiver's
- * text field is capable of holding. If this has not been changed
- * by <code>setTextLimit()</code>, it will be the constant
- * <code>Combo.LIMIT</code>.
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public int getTextLimit () {
- checkWidget();
- return textLimit;
-}
-
-/**
- * Gets the number of items that are visible in the drop
- * down portion of the receiver's list.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @return the number of items that are visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public int getVisibleItemCount () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) {
- return getItemCount ();
- } else {
- return (int)/*64*/((NSComboBox)view).numberOfVisibleItems();
- }
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param string the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string) {
- return indexOf (string, 0);
-}
-
-/**
- * Searches the receiver's list starting at the given,
- * zero-relative index until an item is found that is equal
- * to the argument, and returns the index of that item. If
- * no item is found or the starting index is out of range,
- * returns -1.
- *
- * @param string the search item
- * @param start the zero-relative index at which to begin the search
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string, int start) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = getItemCount ();
- if (!(0 <= start && start < count)) return -1;
- for (int i=start; i<count; i++) {
- if (string.equals (getItem (i))) {
- return i;
- }
- }
- return -1;
-}
-
-void insertEditText (String string) {
- ignoreVerify = true;
- int length = string.length ();
- Point selection = getSelection ();
- if (hasFocus ()) {
- if (textLimit != LIMIT) {
- int charCount = getCharCount();
- if (charCount - (selection.y - selection.x) + length > textLimit) {
- length = textLimit - charCount + (selection.y - selection.x);
- }
- }
- char [] buffer = new char [length];
- string.getChars (0, buffer.length, buffer, 0);
- NSString nsstring = NSString.stringWithCharacters (buffer, buffer.length);
- NSText fieldEditor = ((NSTextField) view).currentEditor ();
- fieldEditor.replaceCharactersInRange (fieldEditor.selectedRange (), nsstring);
- selectionRange = null;
- } else {
- String oldText = getText ();
- if (textLimit != LIMIT) {
- int charCount = oldText.length ();
- if (charCount - (selection.y - selection.x) + length > textLimit) {
- string = string.substring(0, textLimit - charCount + (selection.y - selection.x));
- }
- }
- String newText = oldText.substring (0, selection.x) + string + oldText.substring (selection.y);
- NSString nsstring = NSString.stringWith(newText);
- new NSCell (((NSTextField) view).cell ()).setTitle (nsstring);
- selectionRange = null;
- setSelection (new Point(selection.x + string.length (), 0));
- }
- ignoreVerify = false;
-}
-
-boolean isEventView (int /*long*/ id) {
- return true;
-}
-
-void mouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- // If this is a combo box with an editor field and the control is disposed
- // while the view's cell editor is open we crash while tearing down the
- // popup window. Fix is to retain the view before letting Cocoa track
- // the mouse events.
-
- // 'view' will be cleared if disposed during the mouseDown so cache it.
- NSView viewCopy = view;
- viewCopy.retain();
- super.mouseDown(id, sel, theEvent);
- viewCopy.release();
-}
-
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void paste () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- Point selection = getSelection ();
- int start = selection.x, end = selection.y;
- String text = getText ();
- String leftText = text.substring (0, start);
- String rightText = text.substring (end, text.length ());
- String newText = getClipboardText ();
- if (newText == null) return;
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- newText = verifyText (newText, start, end, null);
- if (newText == null) return;
- }
- if (textLimit != LIMIT) {
- int charCount = text.length ();
- if (charCount - (end - start) + newText.length() > textLimit) {
- newText = newText.substring(0, textLimit - charCount + (end - start));
- }
- }
- setText (leftText + newText + rightText, false);
- start += newText.length ();
- setSelection (new Point (start, start));
- sendEvent (SWT.Modify);
-}
-
-void register() {
- super.register();
- display.addWidget(((NSControl)view).cell(), this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if ((style & SWT.READ_ONLY) == 0) {
- ((NSControl)view).abortEditing();
- }
- selectionRange = null;
-}
-
-/**
- * Removes the item from the receiver's list at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget ();
- if (index == -1) error (SWT.ERROR_INVALID_RANGE);
- int count = getItemCount ();
- if (0 > index || index >= count) error (SWT.ERROR_INVALID_RANGE);
- if ((style & SWT.READ_ONLY) != 0) {
- ((NSPopUpButton)view).removeItemAtIndex(index);
- } else {
- ((NSComboBox)view).removeItemAtIndex(index);
- }
-}
-
-/**
- * Removes the items from the receiver's list which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget();
- if (start > end) return;
- int count = getItemCount ();
- if (!(0 <= start && start <= end && end < count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int newEnd = Math.min (end, count - 1);
- for (int i=newEnd; i>=start; i--) {
- remove(i);
- }
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * until an item is found that is equal to the argument,
- * and removes that item from the list.
- *
- * @param string the item to remove
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = indexOf (string, 0);
- if (index == -1) error (SWT.ERROR_INVALID_ARGUMENT);
- remove (index);
-}
-
-/**
- * Removes all of the items from the receiver's list and clear the
- * contents of receiver's text field.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) {
- ((NSPopUpButton)view).removeAllItems();
- } else {
- setText ("", true);
- ((NSComboBox)view).removeAllItems();
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- *
- * @since 3.1
- */
-public void removeVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget ();
- int count = getItemCount ();
- ignoreSelection = true;
- if (0 <= index && index < count) {
- if ((style & SWT.READ_ONLY) != 0) {
- ((NSPopUpButton)view).selectItemAtIndex(index);
- } else {
- ((NSComboBox)view).selectItemAtIndex(index);
- }
- }
- ignoreSelection = false;
- sendEvent (SWT.Modify);
-}
-
-void sendSelection () {
- sendEvent(SWT.Modify);
- if (!ignoreSelection) postEvent(SWT.Selection);
-}
-
-boolean sendKeyEvent (NSEvent nsEvent, int type) {
- boolean result = super.sendKeyEvent (nsEvent, type);
- if (!result) return result;
- int stateMask = 0;
- int /*long*/ modifierFlags = nsEvent.modifierFlags();
- if ((modifierFlags & OS.NSAlternateKeyMask) != 0) stateMask |= SWT.ALT;
- if ((modifierFlags & OS.NSShiftKeyMask) != 0) stateMask |= SWT.SHIFT;
- if ((modifierFlags & OS.NSControlKeyMask) != 0) stateMask |= SWT.CONTROL;
- if ((modifierFlags & OS.NSCommandKeyMask) != 0) stateMask |= SWT.COMMAND;
- if (type != SWT.KeyDown) return result;
- short keyCode = nsEvent.keyCode ();
- if (stateMask == SWT.COMMAND) {
- switch (keyCode) {
- case 7: /* X */
- cut ();
- return false;
- case 8: /* C */
- copy ();
- return false;
- case 9: /* V */
- paste ();
- return false;
- case 0: /* A */
- if ((style & SWT.READ_ONLY) == 0) {
- ((NSComboBox)view).selectText(null);
- return false;
- }
- }
- }
- switch (keyCode) {
- case 76: /* KP Enter */
- case 36: /* Return */
- postEvent (SWT.DefaultSelection);
- }
- return result;
-}
-
-void updateBackground () {
- NSColor nsColor = null;
- if (backgroundImage != null) {
- nsColor = NSColor.colorWithPatternImage(backgroundImage.handle);
- } else if (background != null) {
- nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]);
- } else {
- nsColor = NSColor.textBackgroundColor ();
- }
-
- if ((style & SWT.READ_ONLY) != 0) {
- //TODO
- } else {
- ((NSTextField)view).setBackgroundColor(nsColor);
- }
-}
-
-void setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- /*
- * Feature in Cocoa. Attempting to create an NSComboBox with a
- * height > 27 spews a very long warning message to stdout and
- * often draws the combo incorrectly. The workaround is to limit
- * the height of editable Combos to the height that is required
- * to display their text.
- */
- if ((style & SWT.READ_ONLY) == 0) {
- NSControl widget = (NSControl)view;
- NSSize size = widget.cell ().cellSize ();
- height = Math.min (height, (int)Math.ceil (size.height));
- }
- super.setBounds (x, y, width, height, move, resize);
-}
-
-void setForeground (float /*double*/ [] color) {
- NSColor nsColor;
- if (color == null) {
- nsColor = NSColor.textColor ();
- } else {
- nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1);
- }
- if ((style & SWT.READ_ONLY) != 0) {
- //TODO
- } else {
- ((NSTextField)view).setTextColor(nsColor);
- }
-}
-
-/**
- * Sets the text of the item in the receiver's list at the given
- * zero-relative index to the string argument.
- *
- * @param index the index for the item
- * @param string the new text for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItem (int index, String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = getItemCount ();
- if (0 > index || index >= count) error (SWT.ERROR_INVALID_RANGE);
- NSString str = NSString.stringWith(string);
- if ((style & SWT.READ_ONLY) != 0) {
- NSMenuItem nsItem = ((NSPopUpButton)view).itemAtIndex(index);
- nsItem.setTitle(str);
- } else {
- NSComboBox widget = (NSComboBox)view;
- widget.insertItemWithObjectValue(str, index);
- widget.removeItemAtIndex(index + 1);
- }
-}
-
-/**
- * Sets the receiver's list to be the given array of items.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItems (String [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<items.length; i++) {
- if (items [i] == null) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- removeAll();
- if (items.length == 0) return;
- for (int i= 0; i < items.length; i++) {
- NSString str = NSString.stringWith(items[i]);
- if ((style & SWT.READ_ONLY) != 0) {
- NSMenu nsMenu = ((NSPopUpButton)view).menu();
- NSMenuItem nsItem = (NSMenuItem)new NSMenuItem().alloc();
- nsItem.initWithTitle(str, 0, NSString.stringWith(""));
- nsMenu.addItem(nsItem);
- nsItem.release();
- //clear the selection
- ((NSPopUpButton)view).selectItemAtIndex(-1);
- } else {
- ((NSComboBox)view).addItemWithObjectValue(str);
- }
- }
-}
-
-/**
- * Marks the receiver's list as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setListVisible (boolean visible) {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) {
- ((NSPopUpButton)view).setPullsDown(visible);
- } else {
- }
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- * <p>
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public void setOrientation (int orientation) {
- checkWidget();
-}
-
-/**
- * Sets the selection in the receiver's text field to the
- * range specified by the argument whose x coordinate is the
- * start of the selection and whose y coordinate is the end
- * of the selection.
- *
- * @param selection a point representing the new selection start and end
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (Point selection) {
- checkWidget ();
- if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.READ_ONLY) == 0) {
- NSComboBox widget = (NSComboBox)view;
- NSString str = new NSCell(widget.cell()).title();
- int length = (int)/*64*/str.length();
- int start = Math.min (Math.max (Math.min (selection.x, selection.y), 0), length);
- int end = Math.min (Math.max (Math.max (selection.x, selection.y), 0), length);
- selectionRange = new NSRange();
- selectionRange.location = start;
- selectionRange.length = end - start;
- NSText fieldEditor = widget.currentEditor();
- if (fieldEditor != null) fieldEditor.setSelectedRange(selectionRange);
- }
-}
-
-/**
- * Sets the contents of the receiver's text field to the
- * given string.
- * <p>
- * This call is ignored when the receiver is read only and
- * the given string is not in the receiver's list.
- * </p>
- * <p>
- * Note: The text field in a <code>Combo</code> is typically
- * only capable of displaying a single line of text. Thus,
- * setting the text to a string containing line breaks or
- * other special characters will probably cause it to
- * display incorrectly.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- setText (string, true);
-}
-
-void setText (String string, boolean notify) {
- ignoreVerify = true;
- if (notify) {
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- string = verifyText (string, 0, getCharCount (), null);
- if (string == null) return;
- }
- }
- if ((style & SWT.READ_ONLY) != 0) {
- int index = indexOf (string);
- if (index != -1 && index != getSelectionIndex ()) {
- select (index);
- if (notify) sendEvent (SWT.Modify);
- }
- } else {
- char[] buffer = new char [Math.min(string.length (), textLimit)];
- string.getChars (0, buffer.length, buffer, 0);
- NSString nsstring = NSString.stringWithCharacters (buffer, buffer.length);
- new NSCell(((NSComboBox)view).cell()).setTitle(nsstring);
- if (notify) sendEvent (SWT.Modify);
- }
- selectionRange = null;
- ignoreVerify = false;
-}
-
-/**
- * Sets the maximum number of characters that the receiver's
- * text field is capable of holding to be the argument.
- * <p>
- * To reset this value to the default, use <code>setTextLimit(Combo.LIMIT)</code>.
- * Specifying a limit value larger than <code>Combo.LIMIT</code> sets the
- * receiver's limit to <code>Combo.LIMIT</code>.
- * </p>
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public void setTextLimit (int limit) {
- checkWidget ();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- textLimit = limit;
-}
-
-/**
- * Sets the number of items that are visible in the drop
- * down portion of the receiver's list.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param count the new number of items to be visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setVisibleItemCount (int count) {
- checkWidget ();
- if (count < 0) return;
- if ((style & SWT.READ_ONLY) != 0) {
- //TODO
- } else {
- ((NSComboBox)view).setNumberOfVisibleItems(count);
- }
-}
-
-boolean shouldChangeTextInRange_replacementString(int /*long*/ id, int /*long*/ sel, int /*long*/ affectedCharRange, int /*long*/ replacementString) {
- NSRange range = new NSRange();
- OS.memmove(range, affectedCharRange, NSRange.sizeof);
- boolean result = callSuperBoolean(id, sel, range, replacementString);
- if (hooks (SWT.Verify)) {
- String text = new NSString(replacementString).getString();
- NSEvent currentEvent = display.application.currentEvent();
- int /*long*/ type = currentEvent.type();
- if (type != OS.NSKeyDown && type != OS.NSKeyUp) currentEvent = null;
- String newText = verifyText(text, (int)/*64*/range.location, (int)/*64*/(range.location+range.length), currentEvent);
- if (newText == null) return false;
- if (text != newText) {
- insertEditText(newText);
- result = false;
- }
- if (!result) sendEvent (SWT.Modify);
- }
- return result;
-}
-
-void textViewDidChangeSelection(int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
- NSNotification notification = new NSNotification(aNotification);
- NSText editor = new NSText(notification.object().id);
- selectionRange = editor.selectedRange();
-}
-
-void textDidChange (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
- super.textDidChange (id, sel, aNotification);
- postEvent (SWT.Modify);
-}
-
-NSRange textView_willChangeSelectionFromCharacterRange_toCharacterRange(int /*long*/ id, int /*long*/ sel, int /*long*/ aTextView, int /*long*/ oldSelectedCharRange, int /*long*/ newSelectedCharRange) {
- /*
- * If the selection is changing as a result of the receiver getting focus
- * then return the receiver's last selection range, otherwise the full
- * text will be automatically selected.
- */
- if (receivingFocus && selectionRange != null) return selectionRange;
-
- /* allow the selection change to proceed */
- NSRange result = new NSRange();
- OS.memmove(result, newSelectedCharRange, NSRange.sizeof);
- return result;
-}
-
-String verifyText (String string, int start, int end, NSEvent keyEvent) {
- Event event = new Event ();
- if (keyEvent != null) setKeyState(event, SWT.MouseDown, keyEvent);
- event.text = string;
- event.start = start;
- event.end = end;
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the verify
- * event. If this happens, answer null to cancel
- * the operation.
- */
- sendEvent (SWT.Verify, event);
- if (!event.doit || isDisposed ()) return null;
- return event.text;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java
deleted file mode 100755
index 2929e285bd..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java
+++ /dev/null
@@ -1,1005 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.accessibility.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class are controls which are capable
- * of containing other controls.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>NO_BACKGROUND, NO_FOCUS, NO_MERGE_PAINTS, NO_REDRAW_RESIZE, NO_RADIO_GROUP, EMBEDDED, DOUBLE_BUFFERED</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: The <code>NO_BACKGROUND</code>, <code>NO_FOCUS</code>, <code>NO_MERGE_PAINTS</code>,
- * and <code>NO_REDRAW_RESIZE</code> styles are intended for use with <code>Canvas</code>.
- * They can be used with <code>Composite</code> if you are drawing your own, but their
- * behavior is undefined if they are used with subclasses of <code>Composite</code> other
- * than <code>Canvas</code>.
- * </p><p>
- * Note: The <code>CENTER</code> style, although undefined for composites, has the
- * same value as <code>EMBEDDED</code> which is used to embed widgets from other
- * widget toolkits into SWT. On some operating systems (GTK, Motif), this may cause
- * the children of this composite to be obscured.
- * </p><p>
- * This class may be subclassed by custom control implementors
- * who are building controls that are constructed from aggregates
- * of other controls.
- * </p>
- *
- * @see Canvas
- * @see <a href="http://www.eclipse.org/swt/snippets/#composite">Composite snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class Composite extends Scrollable {
- Layout layout;
- Control[] tabList;
- int layoutCount, backgroundMode;
-
-Composite () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- *
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_FOCUS
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_RADIO_GROUP
- * @see SWT#EMBEDDED
- * @see SWT#DOUBLE_BUFFERED
- * @see Widget#getStyle
- */
-public Composite (Composite parent, int style) {
- super (parent, style);
-}
-
-Control [] _getChildren () {
- NSArray views = contentView().subviews();
- int count = (int)/*64*/views.count();
- Control [] children = new Control [count];
- if (count == 0) return children;
- int j = 0;
- for (int i=0; i<count; i++){
- Widget widget = display.getWidget (views.objectAtIndex (count - i - 1).id);
- if (widget != null && widget != this && widget instanceof Control) {
- children [j++] = (Control) widget;
- }
- }
- if (j == count) return children;
- Control [] newChildren = new Control [j];
- System.arraycopy (children, 0, newChildren, 0, j);
- return newChildren;
-}
-
-Control [] _getTabList () {
- if (tabList == null) return null;
- int count = 0;
- for (int i=0; i<tabList.length; i++) {
- if (!tabList [i].isDisposed ()) count++;
- }
- if (count == tabList.length) return tabList;
- Control [] newList = new Control [count];
- int index = 0;
- for (int i=0; i<tabList.length; i++) {
- if (!tabList [i].isDisposed ()) {
- newList [index++] = tabList [i];
- }
- }
- tabList = newList;
- return tabList;
-}
-
-boolean acceptsFirstResponder (int /*long*/ id, int /*long*/ sel) {
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_FOCUS) == 0 && hooksKeys ()) {
- if (contentView().subviews().count() == 0) return true;
- }
- return false;
- }
- return super.acceptsFirstResponder (id, sel);
-}
-
-int /*long*/ accessibilityAttributeNames(int /*long*/ id, int /*long*/ sel) {
-
- if (id == view.id) {
- if (accessible != null) {
- // If there is an accessible, it may provide its own list of attributes if it's a lightweight control.
- // If not, let Cocoa handle it for this view.
- id returnObject = accessible.internal_accessibilityAttributeNames(ACC.CHILDID_SELF);
- if (returnObject != null) return returnObject.id;
- }
- }
-
- return super.accessibilityAttributeNames(id, sel);
-}
-
-boolean accessibilityIsIgnored(int /*long*/ id, int /*long*/ sel) {
- // If we have an accessible and it represents a valid accessible role, this view is not ignored.
- if (view != null && id == view.id) {
- if (accessible != null) {
- id role = accessible.internal_accessibilityAttributeValue(OS.NSAccessibilityRoleAttribute, ACC.CHILDID_SELF);
- if (role != null) return false;
- }
- }
-
- return super.accessibilityIsIgnored(id, sel);
-}
-
-/**
- * Clears any data that has been cached by a Layout for all widgets that
- * are in the parent hierarchy of the changed control up to and including the
- * receiver. If an ancestor does not have a layout, it is skipped.
- *
- * @param changed an array of controls that changed state and require a recalculation of size
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li>
- * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void changed (Control[] changed) {
- checkWidget ();
- if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<changed.length; i++) {
- Control control = changed [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean ancestor = false;
- Composite composite = control.parent;
- while (composite != null) {
- ancestor = composite == this;
- if (ancestor) break;
- composite = composite.parent;
- }
- if (!ancestor) error (SWT.ERROR_INVALID_PARENT);
- }
- for (int i=0; i<changed.length; i++) {
- Control child = changed [i];
- Composite composite = child.parent;
- while (child != this) {
- if (composite.layout == null || !composite.layout.flushCache (child)) {
- composite.state |= LAYOUT_CHANGED;
- }
- child = composite;
- composite = child.parent;
- }
- }
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- Point size;
- if (layout != null) {
- if ((wHint == SWT.DEFAULT) || (hHint == SWT.DEFAULT)) {
- changed |= (state & LAYOUT_CHANGED) != 0;
- size = layout.computeSize (this, wHint, hHint, changed);
- state &= ~LAYOUT_CHANGED;
- } else {
- size = new Point (wHint, hHint);
- }
- } else {
- size = minimumSize (wHint, hHint, changed);
- }
- if (size.x == 0) size.x = DEFAULT_WIDTH;
- if (size.y == 0) size.y = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) size.x = wHint;
- if (hHint != SWT.DEFAULT) size.y = hHint;
- Rectangle trim = computeTrim (0, 0, size.x, size.y);
- return new Point (trim.width, trim.height);
-}
-
-protected void checkSubclass () {
- /* Do nothing - Subclassing is allowed */
-}
-
-Widget [] computeTabList () {
- Widget result [] = super.computeTabList ();
- if (result.length == 0) return result;
- Control [] list = tabList != null ? _getTabList () : _getChildren ();
- for (int i=0; i<list.length; i++) {
- Control child = list [i];
- Widget [] childList = child.computeTabList ();
- if (childList.length != 0) {
- Widget [] newResult = new Widget [result.length + childList.length];
- System.arraycopy (result, 0, newResult, 0, result.length);
- System.arraycopy (childList, 0, newResult, result.length, childList.length);
- result = newResult;
- }
- }
- return result;
-}
-
-void createHandle () {
- state |= CANVAS;
- boolean scrolled = (style & (SWT.V_SCROLL | SWT.H_SCROLL)) != 0;
- if (!scrolled) state |= THEME_BACKGROUND;
- NSRect rect = new NSRect();
- if (scrolled || hasBorder ()) {
- NSScrollView scrollWidget = (NSScrollView)new SWTScrollView().alloc();
- scrollWidget.initWithFrame (rect);
- scrollWidget.setDrawsBackground(false);
- if ((style & SWT.H_SCROLL) != 0) scrollWidget.setHasHorizontalScroller(true);
- if ((style & SWT.V_SCROLL) != 0) scrollWidget.setHasVerticalScroller(true);
- scrollWidget.setBorderType(hasBorder() ? OS.NSBezelBorder : OS.NSNoBorder);
- scrollView = scrollWidget;
- }
- NSView widget = (NSView)new SWTCanvasView().alloc();
- widget.initWithFrame (rect);
-// widget.setFocusRingType(OS.NSFocusRingTypeExterior);
- view = widget;
- if (scrollView != null) {
- NSClipView contentView = scrollView.contentView();
- contentView.setAutoresizesSubviews(true);
- view.setAutoresizingMask(OS.NSViewWidthSizable | OS.NSViewHeightSizable);
- }
-}
-
-void drawBackground (int /*long*/ id, NSGraphicsContext context, NSRect rect) {
- if (id != view.id) return;
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_BACKGROUND) == 0) {
- fillBackground (view, context, rect, -1);
- }
- }
-}
-
-Composite findDeferredControl () {
- return layoutCount > 0 ? this : parent.findDeferredControl ();
-}
-
-Menu [] findMenus (Control control) {
- if (control == this) return new Menu [0];
- Menu result [] = super.findMenus (control);
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- Menu [] menuList = child.findMenus (control);
- if (menuList.length != 0) {
- Menu [] newResult = new Menu [result.length + menuList.length];
- System.arraycopy (result, 0, newResult, 0, result.length);
- System.arraycopy (menuList, 0, newResult, result.length, menuList.length);
- result = newResult;
- }
- }
- return result;
-}
-
-void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) {
- super.fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
- }
-}
-
-void fixTabList (Control control) {
- if (tabList == null) return;
- int count = 0;
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == control) count++;
- }
- if (count == 0) return;
- Control [] newList = null;
- int length = tabList.length - count;
- if (length != 0) {
- newList = new Control [length];
- int index = 0;
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] != control) {
- newList [index++] = tabList [i];
- }
- }
- }
- tabList = newList;
-}
-
-/**
- * Returns the receiver's background drawing mode. This
- * will be one of the following constants defined in class
- * <code>SWT</code>:
- * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>,
- * <code>INHERTIT_FORCE</code>.
- *
- * @return the background mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- *
- * @since 3.2
- */
-public int getBackgroundMode () {
- checkWidget ();
- return backgroundMode;
-}
-
-/**
- * Returns a (possibly empty) array containing the receiver's children.
- * Children are returned in the order that they are drawn. The topmost
- * control appears at the beginning of the array. Subsequent controls
- * draw beneath this control and appear later in the array.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of children, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return an array of children
- *
- * @see Control#moveAbove
- * @see Control#moveBelow
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control [] getChildren () {
- checkWidget();
- return _getChildren ();
-}
-
-/**
- * Returns layout which is associated with the receiver, or
- * null if one has not been set.
- *
- * @return the receiver's layout or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Layout getLayout () {
- checkWidget();
- return layout;
-}
-
-/**
- * Returns <code>true</code> if the receiver has deferred
- * the performing of layout, and <code>false</code> otherwise.
- *
- * @return the receiver's deferred layout state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setLayoutDeferred(boolean)
- * @see #isLayoutDeferred()
- *
- * @since 3.1
- */
-public boolean getLayoutDeferred () {
- checkWidget ();
- return layoutCount > 0 ;
-}
-
-/**
- * Gets the (possibly empty) tabbing order for the control.
- *
- * @return tabList the ordered list of controls representing the tab order
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setTabList
- */
-public Control [] getTabList () {
- checkWidget ();
- Control [] tabList = _getTabList ();
- if (tabList == null) {
- int count = 0;
- Control [] list =_getChildren ();
- for (int i=0; i<list.length; i++) {
- if (list [i].isTabGroup ()) count++;
- }
- tabList = new Control [count];
- int index = 0;
- for (int i=0; i<list.length; i++) {
- if (list [i].isTabGroup ()) {
- tabList [index++] = list [i];
- }
- }
- }
- return tabList;
-}
-
-boolean hooksKeys () {
- return hooks (SWT.KeyDown) || hooks (SWT.KeyUp);
-}
-
-void invalidateChildrenVisibleRegion () {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- child.resetVisibleRegion ();
- child.invalidateChildrenVisibleRegion ();
- }
-}
-
-/**
- * Returns <code>true</code> if the receiver or any ancestor
- * up to and including the receiver's nearest ancestor shell
- * has deferred the performing of layouts. Otherwise, <code>false</code>
- * is returned.
- *
- * @return the receiver's deferred layout state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setLayoutDeferred(boolean)
- * @see #getLayoutDeferred()
- *
- * @since 3.1
- */
-public boolean isLayoutDeferred () {
- checkWidget ();
- return findDeferredControl () != null;
-}
-
-boolean isOpaque (int /*long*/ id, int /*long*/ sel) {
- if ((state & CANVAS) != 0) {
- if (id == view.id) {
- if (region == null && background != null && background[3] == 1) {
- return true;
- }
- }
- }
- return super.isOpaque (id, sel);
-}
-
-boolean isTabGroup () {
- if ((state & CANVAS) != 0) return true;
- return super.isTabGroup ();
-}
-
-void keyDown (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (view.window ().firstResponder ().id == id) {
- if ((state & CANVAS) != 0) {
- Shell s = this.getShell();
- NSArray array = NSArray.arrayWithObject (new NSEvent (theEvent));
- s.keyInputHappened = false;
- view.interpretKeyEvents (array);
- if (imeInComposition ()) return;
- if (!s.keyInputHappened) {
- NSEvent nsEvent = new NSEvent (theEvent);
- boolean [] consume = new boolean [1];
- if (translateTraversal (nsEvent.keyCode (), nsEvent, consume)) return;
- if (isDisposed ()) return;
- if (!sendKeyEvent (nsEvent, SWT.KeyDown)) return;
- if (consume [0]) return;
- }
- return;
- }
- }
- super.keyDown (id, sel, theEvent);
-}
-
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the receiver does not have a layout, do nothing.
- * <p>
- * This is equivalent to calling <code>layout(true)</code>.
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void layout () {
- checkWidget ();
- layout (true);
-}
-
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the argument is <code>true</code> the layout must not rely
- * on any information it has cached about the immediate children. If it
- * is <code>false</code> the layout may (potentially) optimize the
- * work it is doing by assuming that none of the receiver's
- * children has changed state since the last layout.
- * If the receiver does not have a layout, do nothing.
- * <p>
- * If a child is resized as a result of a call to layout, the
- * resize event will invoke the layout of the child. The layout
- * will cascade down through all child widgets in the receiver's widget
- * tree until a child is encountered that does not resize. Note that
- * a layout due to a resize will not flush any cached information
- * (same as <code>layout(false)</code>).
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void layout (boolean changed) {
- checkWidget ();
- if (layout == null) return;
- layout (changed, false);
-}
-
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the changed argument is <code>true</code> the layout must not rely
- * on any information it has cached about its children. If it
- * is <code>false</code> the layout may (potentially) optimize the
- * work it is doing by assuming that none of the receiver's
- * children has changed state since the last layout.
- * If the all argument is <code>true</code> the layout will cascade down
- * through all child widgets in the receiver's widget tree, regardless of
- * whether the child has changed size. The changed argument is applied to
- * all layouts. If the all argument is <code>false</code>, the layout will
- * <em>not</em> cascade down through all child widgets in the receiver's widget
- * tree. However, if a child is resized as a result of a call to layout, the
- * resize event will invoke the layout of the child. Note that
- * a layout due to a resize will not flush any cached information
- * (same as <code>layout(false)</code>).
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise
- * @param all <code>true</code> if all children in the receiver's widget tree should be laid out, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void layout (boolean changed, boolean all) {
- checkWidget ();
- if (layout == null && !all) return;
- markLayout (changed, all);
- updateLayout (all);
-}
-
-/**
- * Forces a lay out (that is, sets the size and location) of all widgets that
- * are in the parent hierarchy of the changed control up to and including the
- * receiver. The layouts in the hierarchy must not rely on any information
- * cached about the changed control or any of its ancestors. The layout may
- * (potentially) optimize the work it is doing by assuming that none of the
- * peers of the changed control have changed state since the last layout.
- * If an ancestor does not have a layout, skip it.
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed a control that has had a state change which requires a recalculation of its size
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li>
- * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void layout (Control [] changed) {
- checkWidget ();
- if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<changed.length; i++) {
- Control control = changed [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean ancestor = false;
- Composite composite = control.parent;
- while (composite != null) {
- ancestor = composite == this;
- if (ancestor) break;
- composite = composite.parent;
- }
- if (!ancestor) error (SWT.ERROR_INVALID_PARENT);
- }
- int updateCount = 0;
- Composite [] update = new Composite [16];
- for (int i=0; i<changed.length; i++) {
- Control child = changed [i];
- Composite composite = child.parent;
- while (child != this) {
- if (composite.layout != null) {
- composite.state |= LAYOUT_NEEDED;
- if (!composite.layout.flushCache (child)) {
- composite.state |= LAYOUT_CHANGED;
- }
- }
- if (updateCount == update.length) {
- Composite [] newUpdate = new Composite [update.length + 16];
- System.arraycopy (update, 0, newUpdate, 0, update.length);
- update = newUpdate;
- }
- child = update [updateCount++] = composite;
- composite = child.parent;
- }
- }
- for (int i=updateCount-1; i>=0; i--) {
- update [i].updateLayout (false);
- }
-}
-
-void markLayout (boolean changed, boolean all) {
- if (layout != null) {
- state |= LAYOUT_NEEDED;
- if (changed) state |= LAYOUT_CHANGED;
- }
- if (all) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].markLayout (changed, all);
- }
- }
-}
-
-Point minimumSize (int wHint, int Hint, boolean changed) {
- Control [] children = _getChildren ();
- int width = 0, height = 0;
- for (int i=0; i<children.length; i++) {
- Rectangle rect = children [i].getBounds ();
- width = Math.max (width, rect.x + rect.width);
- height = Math.max (height, rect.y + rect.height);
- }
- return new Point (width, height);
-}
-
-boolean mouseEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent, int type) {
- boolean result = super.mouseEvent (id, sel, theEvent, type);
- return (state & CANVAS) == 0 ? result : new NSEvent (theEvent).type () != OS.NSLeftMouseDown;
-}
-
-void pageDown(int /*long*/ id, int /*long*/ sel, int /*long*/ sender) {
- if ((state & CANVAS) != 0) return;
- super.pageDown(id, sel, sender);
-}
-
-void pageUp(int /*long*/ id, int /*long*/ sel, int /*long*/ sender) {
- if ((state & CANVAS) != 0) return;
- super.pageUp(id, sel, sender);
-}
-
-void reflectScrolledClipView (int /*long*/ id, int /*long*/ sel, int /*long*/ aClipView) {
- if ((state & CANVAS) != 0) return;
- super.reflectScrolledClipView (id, sel, aClipView);
-}
-
-void releaseChildren (boolean destroy) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child != null && !child.isDisposed ()) {
- child.release (false);
- }
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- layout = null;
- tabList = null;
-}
-
-void removeControl (Control control) {
- fixTabList (control);
-}
-
-void resized () {
- super.resized ();
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
-}
-
-void scrollWheel (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if ((state & CANVAS) != 0) {
- NSView view = scrollView != null ? scrollView : this.view;
- if (id == view.id) {
- NSEvent nsEvent = new NSEvent(theEvent);
- float /*double*/ delta = nsEvent.deltaY();
- if (delta != 0) {
- if (hooks (SWT.MouseWheel) || filters (SWT.MouseWheel)) {
- if (!sendMouseEvent(nsEvent, SWT.MouseWheel, true)) {
- return;
- }
- }
- }
- boolean handled = false;
- ScrollBar bar = verticalBar;
- if (delta != 0 && bar != null && bar.getEnabled ()) {
- if (-1 < delta && delta < 0) delta = -1;
- if (0 < delta && delta < 1) delta = 1;
- int selection = Math.max (0, (int)(0.5f + bar.getSelection () - bar.getIncrement () * delta));
- bar.setSelection (selection);
- Event event = new Event ();
- event.detail = delta > 0 ? SWT.PAGE_UP : SWT.PAGE_DOWN;
- bar.sendEvent (SWT.Selection, event);
- handled = true;
- }
- bar = horizontalBar;
- delta = nsEvent.deltaX ();
- if (delta != 0 && bar != null && bar.getEnabled ()) {
- int selection = Math.max (0, (int)(0.5f + bar.getSelection () - bar.getIncrement () * delta));
- bar.setSelection (selection);
- Event event = new Event ();
- event.detail = delta > 0 ? SWT.PAGE_UP : SWT.PAGE_DOWN;
- bar.sendEvent (SWT.Selection, event);
- handled = true;
- }
- if (!handled) view.superview().scrollWheel(nsEvent);
- return;
- }
- callSuper(id, sel, theEvent);
- return;
- }
- super.scrollWheel (id, sel, theEvent);
-}
-
-/**
- * Sets the background drawing mode to the argument which should
- * be one of the following constants defined in class <code>SWT</code>:
- * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>,
- * <code>INHERIT_FORCE</code>.
- *
- * @param mode the new background mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- *
- * @since 3.2
- */
-public void setBackgroundMode (int mode) {
- checkWidget ();
- backgroundMode = mode;
- Control [] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- children [i].updateBackgroundMode ();
- }
-}
-
-public boolean setFocus () {
- checkWidget ();
- Control [] children = _getChildren ();
- for (int i= 0; i < children.length; i++) {
- if (children [i].setFocus ()) return true;
- }
- return super.setFocus ();
-}
-
-/**
- * Sets the layout which is associated with the receiver to be
- * the argument which may be null.
- *
- * @param layout the receiver's new layout or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLayout (Layout layout) {
- checkWidget();
- this.layout = layout;
-}
-
-/**
- * If the argument is <code>true</code>, causes subsequent layout
- * operations in the receiver or any of its children to be ignored.
- * No layout of any kind can occur in the receiver or any of its
- * children until the flag is set to false.
- * Layout operations that occurred while the flag was
- * <code>true</code> are remembered and when the flag is set to
- * <code>false</code>, the layout operations are performed in an
- * optimized manner. Nested calls to this method are stacked.
- *
- * @param defer the new defer state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #layout(boolean)
- * @see #layout(Control[])
- *
- * @since 3.1
- */
-public void setLayoutDeferred (boolean defer) {
- if (!defer) {
- if (--layoutCount == 0) {
- if ((state & LAYOUT_CHILD) != 0 || (state & LAYOUT_NEEDED) != 0) {
- updateLayout (true);
- }
- }
- } else {
- layoutCount++;
- }
-}
-
-boolean setScrollBarVisible (ScrollBar bar, boolean visible) {
- boolean changed = super.setScrollBarVisible (bar, visible);
- if (changed && layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
- return changed;
-}
-
-boolean setTabGroupFocus () {
- if (isTabItem ()) return setTabItemFocus ();
- boolean takeFocus = (style & SWT.NO_FOCUS) == 0;
- if ((state & CANVAS) != 0) takeFocus = hooksKeys ();
- if (takeFocus && setTabItemFocus ()) return true;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.isTabItem () && child.setTabItemFocus ()) return true;
- }
- return false;
-}
-
-/**
- * Sets the tabbing order for the specified controls to
- * match the order that they occur in the argument list.
- *
- * @param tabList the ordered list of controls representing the tab order or null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if a widget in the tabList is null or has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if widget in the tabList is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTabList (Control [] tabList) {
- checkWidget ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- Control control = tabList [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
- Control [] newList = new Control [tabList.length];
- System.arraycopy (tabList, 0, newList, 0, tabList.length);
- tabList = newList;
- }
- this.tabList = tabList;
-}
-
-int traversalCode (int key, NSEvent theEvent) {
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_FOCUS) != 0) return 0;
- if (hooksKeys ()) return 0;
- }
- return super.traversalCode (key, theEvent);
-}
-
-void updateBackgroundMode () {
- super.updateBackgroundMode ();
- Control [] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- children [i].updateBackgroundMode ();
- }
-}
-
-void updateCursorRects (boolean enabled) {
- super.updateCursorRects (enabled);
- Control [] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- Control control = children [i];
- control.updateCursorRects (enabled && control.isEnabled ());
- }
-}
-
-void updateLayout (boolean all) {
- Composite parent = findDeferredControl ();
- if (parent != null) {
- parent.state |= LAYOUT_CHILD;
- return;
- }
- if ((state & LAYOUT_NEEDED) != 0) {
- boolean changed = (state & LAYOUT_CHANGED) != 0;
- state &= ~(LAYOUT_NEEDED | LAYOUT_CHANGED);
- layout.layout (this, changed);
- }
- if (all) {
- state &= ~LAYOUT_CHILD;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].updateLayout (all);
- }
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java
deleted file mode 100755
index c3666bc092..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java
+++ /dev/null
@@ -1,4114 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.accessibility.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Control is the abstract superclass of all windowed user interface classes.
- * <p>
- * <dl>
- * <dt><b>Styles:</b>
- * <dd>BORDER</dd>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * <dt><b>Events:</b>
- * <dd>DragDetect, FocusIn, FocusOut, Help, KeyDown, KeyUp, MenuDetect, MouseDoubleClick, MouseDown, MouseEnter,
- * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize, Traverse</dd>
- * </dl>
- * </p><p>
- * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#control">Control snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public abstract class Control extends Widget implements Drawable {
- /**
- * the handle to the OS resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public NSView view;
- Composite parent;
- String toolTipText;
- Object layoutData;
- int drawCount;
- Menu menu;
- float /*double*/ [] foreground, background;
- Image backgroundImage;
- Font font;
- Cursor cursor;
- Region region;
- NSBezierPath regionPath;
- int /*long*/ visibleRgn;
- Accessible accessible;
-
- final static int CLIPPING = 1 << 10;
- final static int VISIBLE_REGION = 1 << 12;
-
- /**
- * Magic number comes from experience. There's no API for this value in Cocoa or Carbon.
- */
- static final int DEFAULT_DRAG_HYSTERESIS = 5;
-
-Control () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#LEFT_TO_RIGHT
- * @see SWT#RIGHT_TO_LEFT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Control (Composite parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget ();
-}
-
-boolean acceptsFirstMouse (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- Shell shell = getShell ();
- if ((shell.style & SWT.ON_TOP) != 0) return true;
- return super.acceptsFirstMouse (id, sel, theEvent);
-}
-
-int /*long*/ accessibilityActionNames(int /*long*/ id, int /*long*/ sel) {
- if (accessible != null) {
- NSArray returnValue = accessible.internal_accessibilityActionNames(ACC.CHILDID_SELF);
- if (returnValue != null) return returnValue.id;
- }
-
- return super.accessibilityActionNames(id, sel);
-}
-
-int /*long*/ accessibilityAttributeNames(int /*long*/ id, int /*long*/ sel) {
-
- if (id == view.id || (view instanceof NSControl && ((NSControl)view).cell() != null && ((NSControl)view).cell().id == id)) {
- if (accessible != null) {
-
- // First, see if the accessible is going to define a set of attributes for the control.
- // If it does, return that.
- NSArray returnValue = accessible.internal_accessibilityAttributeNames(ACC.CHILDID_SELF);
- if (returnValue != null) return returnValue.id;
-
- // If not, see if it will override or augment the standard list.
- // Help, title, and description can be overridden.
- NSMutableArray extraAttributes = NSMutableArray.arrayWithCapacity(3);
- extraAttributes.addObject(OS.NSAccessibilityHelpAttribute);
- extraAttributes.addObject(OS.NSAccessibilityDescriptionAttribute);
- extraAttributes.addObject(OS.NSAccessibilityTitleAttribute);
-
- for (int i = (int)/*64*/extraAttributes.count() - 1; i >= 0; i--) {
- NSString attribute = new NSString(extraAttributes.objectAtIndex(i).id);
- if (accessible.internal_accessibilityAttributeValue(attribute, ACC.CHILDID_SELF) == null) {
- extraAttributes.removeObjectAtIndex(i);
- }
- }
-
- if (extraAttributes.count() > 0) {
- int /*long*/ superResult = super.accessibilityAttributeNames(id, sel);
- NSArray baseAttributes = new NSArray(superResult);
- NSMutableArray mutableAttributes = NSMutableArray.arrayWithCapacity(baseAttributes.count() + 1);
- mutableAttributes.addObjectsFromArray(baseAttributes);
-
- for (int i = 0; i < extraAttributes.count(); i++) {
- id currAttribute = extraAttributes.objectAtIndex(i);
- if (!mutableAttributes.containsObject(currAttribute)) {
- mutableAttributes.addObject(currAttribute);
- }
- }
-
- return mutableAttributes.id;
- }
- }
- }
-
- return super.accessibilityAttributeNames(id, sel);
-}
-
-int /*long*/ accessibilityParameterizedAttributeNames(int /*long*/ id, int /*long*/ sel) {
-
- if (id == view.id || (view instanceof NSControl && ((NSControl)view).cell() != null && ((NSControl)view).cell().id == id)) {
- if (accessible != null) {
- NSArray returnValue = accessible.internal_accessibilityParameterizedAttributeNames(ACC.CHILDID_SELF);
- if (returnValue != null) return returnValue.id;
- }
- }
-
- return super.accessibilityParameterizedAttributeNames(id, sel);
-}
-
-int /*long*/ accessibilityFocusedUIElement(int /*long*/ id, int /*long*/ sel) {
- id returnValue = null;
-
- if (id == view.id || (view instanceof NSControl && ((NSControl)view).cell() != null && ((NSControl)view).cell().id == id)) {
- if (accessible != null) {
- returnValue = accessible.internal_accessibilityFocusedUIElement(ACC.CHILDID_SELF);
- }
- }
-
- // If we had an accessible and it didn't handle the attribute request, let the
- // superclass handle it.
- if (returnValue == null)
- return super.accessibilityFocusedUIElement(id, sel);
- else
- return returnValue.id;
-}
-
-int /*long*/ accessibilityHitTest(int /*long*/ id, int /*long*/ sel, NSPoint point) {
- id returnValue = null;
-
- if (id == view.id || (view instanceof NSControl && ((NSControl)view).cell() != null && ((NSControl)view).cell().id == id)) {
- if (accessible != null) {
- returnValue = accessible.internal_accessibilityHitTest(point, ACC.CHILDID_SELF);
- }
- }
-
- // If we had an accessible and it didn't handle the attribute request, let the
- // superclass handle it.
- if (returnValue == null)
- return super.accessibilityHitTest(id, sel, point);
- else
- return returnValue.id;
-}
-
-int /*long*/ accessibilityAttributeValue(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- NSString attribute = new NSString(arg0);
- int /*long*/ returnValue = 0;
- id returnObject = null;
-
- if (accessible != null) {
- returnObject = accessible.internal_accessibilityAttributeValue(attribute, ACC.CHILDID_SELF);
- }
-
- // If we had an accessible and it didn't handle the attribute request, let the
- // superclass handle it.
- if (returnObject == null) {
- returnValue = super.accessibilityAttributeValue(id, sel, arg0);
- } else {
- returnValue = returnObject.id;
- }
-
- return returnValue;
-}
-
-int /*long*/ accessibilityAttributeValue_forParameter(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1) {
- NSString attribute = new NSString(arg0);
-
- id returnValue = null;
-
- if (accessible != null) {
- id parameter = new id(arg1);
- returnValue = accessible.internal_accessibilityAttributeValue_forParameter(attribute, parameter, ACC.CHILDID_SELF);
- }
-
- // If we had an accessible and it didn't handle the attribute request, let the
- // superclass handle it.
- if (returnValue == null)
- return super.accessibilityAttributeValue_forParameter(id, sel, arg0, arg1);
- else
- return returnValue.id;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize,typedListener);
- addListener (SWT.Move,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when a drag gesture occurs, by sending it
- * one of the messages defined in the <code>DragDetectListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #removeDragDetectListener
- *
- * @since 3.3
- */
-public void addDragDetectListener (DragDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.DragDetect,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control gains or loses focus, by sending
- * it one of the messages defined in the <code>FocusListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see FocusListener
- * @see #removeFocusListener
- */
-public void addFocusListener(FocusListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.FocusIn,typedListener);
- addListener(SWT.FocusOut,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when help events are generated for the control,
- * by sending it one of the messages defined in the
- * <code>HelpListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard, by sending
- * it one of the messages defined in the <code>KeyListener</code>
- * interface.
- * <p>
- * When a key listener is added to a control, the control
- * will take part in widget traversal. By default, all
- * traversal keys (such as the tab key and so on) are
- * delivered to the control. In order for a control to take
- * part in traversal, it should listen for traversal events.
- * Otherwise, the user can traverse into a control but not
- * out. Note that native controls such as table and tree
- * implement key traversal in the operating system. It is
- * not necessary to add traversal listeners for these controls,
- * unless you want to override the default traversal.
- * </p>
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #removeKeyListener
- */
-public void addKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.KeyUp,typedListener);
- addListener(SWT.KeyDown,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the platform-specific context menu trigger
- * has occurred, by sending it one of the messages defined in
- * the <code>MenuDetectListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #removeMenuDetectListener
- *
- * @since 3.3
- */
-public void addMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MenuDetect, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when mouse buttons are pressed and released, by sending
- * it one of the messages defined in the <code>MouseListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseListener
- * @see #removeMouseListener
- */
-public void addMouseListener(MouseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.MouseDown,typedListener);
- addListener(SWT.MouseUp,typedListener);
- addListener(SWT.MouseDoubleClick,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse passes or hovers over controls, by sending
- * it one of the messages defined in the <code>MouseTrackListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseTrackListener
- * @see #removeMouseTrackListener
- */
-public void addMouseTrackListener (MouseTrackListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseEnter,typedListener);
- addListener (SWT.MouseExit,typedListener);
- addListener (SWT.MouseHover,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse moves, by sending it one of the
- * messages defined in the <code>MouseMoveListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseMoveListener
- * @see #removeMouseMoveListener
- */
-public void addMouseMoveListener(MouseMoveListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.MouseMove,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse wheel is scrolled, by sending
- * it one of the messages defined in the
- * <code>MouseWheelListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseWheelListener
- * @see #removeMouseWheelListener
- *
- * @since 3.3
- */
-public void addMouseWheelListener (MouseWheelListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseWheel, typedListener);
-}
-
-void addRelation (Control control) {
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver needs to be painted, by sending it
- * one of the messages defined in the <code>PaintListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see PaintListener
- * @see #removePaintListener
- */
-public void addPaintListener(PaintListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.Paint,typedListener);
-}
-
-static final double SYNTHETIC_BOLD = -2.5;
-static final double SYNTHETIC_ITALIC = 0.2;
-
-void addTraits(NSMutableDictionary dict, Font font) {
- if ((font.extraTraits & OS.NSBoldFontMask) != 0) {
- dict.setObject(NSNumber.numberWithDouble(SYNTHETIC_BOLD), OS.NSStrokeWidthAttributeName);
- }
- if ((font.extraTraits & OS.NSItalicFontMask) != 0) {
- dict.setObject(NSNumber.numberWithDouble(SYNTHETIC_ITALIC), OS.NSObliquenessAttributeName);
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when traversal events occur, by sending it
- * one of the messages defined in the <code>TraverseListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TraverseListener
- * @see #removeTraverseListener
- */
-public void addTraverseListener (TraverseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Traverse,typedListener);
-}
-
-boolean becomeFirstResponder (int /*long*/ id, int /*long*/ sel) {
- if ((state & DISABLED) != 0) return false;
- return super.becomeFirstResponder (id, sel);
-}
-
-void calculateVisibleRegion (NSView view, int /*long*/ visibleRgn, boolean clipChildren) {
- int /*long*/ tempRgn = OS.NewRgn ();
- if (!view.isHiddenOrHasHiddenAncestor() && isDrawing()) {
- int /*long*/ childRgn = OS.NewRgn ();
- NSWindow window = view.window ();
- NSView contentView = window.contentView();
- NSView frameView = contentView.superview();
- NSRect bounds = contentView.visibleRect();
- bounds = contentView.convertRect_toView_(bounds, view);
- short[] rect = new short[4];
- OS.SetRect(rect, (short)bounds.x, (short)bounds.y, (short)(bounds.x + bounds.width), (short)(bounds.y + bounds.height));
- OS.RectRgn(visibleRgn, rect);
- NSView tempView = view, lastControl = null;
- while (tempView.id != frameView.id) {
- bounds = tempView.visibleRect();
- bounds = tempView.convertRect_toView_(bounds, view);
- OS.SetRect(rect, (short)bounds.x, (short)bounds.y, (short)(bounds.x + bounds.width), (short)(bounds.y + bounds.height));
- OS.RectRgn(tempRgn, rect);
- OS.SectRgn (tempRgn, visibleRgn, visibleRgn);
- if (OS.EmptyRgn (visibleRgn)) break;
- if (clipChildren || tempView.id != view.id) {
- NSArray subviews = tempView.subviews();
- int /*long*/ count = subviews.count();
- for (int i = 0; i < count; i++) {
- NSView child = new NSView (subviews.objectAtIndex(count - i - 1));
- if (lastControl != null && child.id == lastControl.id) break;
- if (child.isHidden()) continue;
- bounds = child.visibleRect();
- bounds = child.convertRect_toView_(bounds, view);
- OS.SetRect(rect, (short)bounds.x, (short)bounds.y, (short)(bounds.x + bounds.width), (short)(bounds.y + bounds.height));
- OS.RectRgn(tempRgn, rect);
- OS.UnionRgn (tempRgn, childRgn, childRgn);
- }
- }
- lastControl = tempView;
- tempView = tempView.superview();
- }
- OS.DiffRgn (visibleRgn, childRgn, visibleRgn);
- OS.DisposeRgn (childRgn);
- } else {
- OS.CopyRgn (tempRgn, visibleRgn);
- }
- OS.DisposeRgn (tempRgn);
-}
-
-void checkBackground () {
- Shell shell = getShell ();
- if (this == shell) return;
- state &= ~PARENT_BACKGROUND;
- Composite composite = parent;
- do {
- int mode = composite.backgroundMode;
- if (mode != 0) {
- if (mode == SWT.INHERIT_DEFAULT) {
- Control control = this;
- do {
- if ((control.state & THEME_BACKGROUND) == 0) {
- return;
- }
- control = control.parent;
- } while (control != composite);
- }
- state |= PARENT_BACKGROUND;
- return;
- }
- if (composite == shell) break;
- composite = composite.parent;
- } while (true);
-}
-
-void checkBuffered () {
- style |= SWT.DOUBLE_BUFFERED;
-}
-
-void checkToolTip (Widget target) {
- if (isVisible () && display.tooltipControl == this && (target == null || display.tooltipTarget == target)) {
- Shell shell = getShell ();
- shell.sendToolTipEvent (false);
- shell.sendToolTipEvent (true);
- }
-}
-
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>preferred size</em> of a control is the size that it would
- * best be displayed at. The width hint and height hint arguments
- * allow the caller to ask a control questions such as "Given a particular
- * width, how high does the control need to be to show all of the contents?"
- * To indicate that the caller does not wish to constrain a particular
- * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
- * </p>
- *
- * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
- * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
- * @return the preferred size of the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Layout
- * @see #getBorderWidth
- * @see #getBounds
- * @see #getSize
- * @see #pack(boolean)
- * @see "computeTrim, getClientArea for controls that implement them"
- */
-public Point computeSize (int wHint, int hHint) {
- return computeSize (wHint, hHint, true);
-}
-
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>preferred size</em> of a control is the size that it would
- * best be displayed at. The width hint and height hint arguments
- * allow the caller to ask a control questions such as "Given a particular
- * width, how high does the control need to be to show all of the contents?"
- * To indicate that the caller does not wish to constrain a particular
- * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
- * </p><p>
- * If the changed flag is <code>true</code>, it indicates that the receiver's
- * <em>contents</em> have changed, therefore any caches that a layout manager
- * containing the control may have been keeping need to be flushed. When the
- * control is resized, the changed flag will be <code>false</code>, so layout
- * manager caches can be retained.
- * </p>
- *
- * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
- * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
- * @param changed <code>true</code> if the control's contents have changed, and <code>false</code> otherwise
- * @return the preferred size of the control.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Layout
- * @see #getBorderWidth
- * @see #getBounds
- * @see #getSize
- * @see #pack(boolean)
- * @see "computeTrim, getClientArea for controls that implement them"
- */
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = DEFAULT_WIDTH;
- int height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2;
- height += border * 2;
- return new Point (width, height);
-}
-
-Widget computeTabGroup () {
- if (isTabGroup()) return this;
- return parent.computeTabGroup ();
-}
-
-Widget[] computeTabList() {
- if (isTabGroup()) {
- if (getVisible() && getEnabled()) {
- return new Widget[] {this};
- }
- }
- return new Widget[0];
-}
-
-Control computeTabRoot () {
- Control[] tabList = parent._getTabList();
- if (tabList != null) {
- int index = 0;
- while (index < tabList.length) {
- if (tabList [index] == this) break;
- index++;
- }
- if (index == tabList.length) {
- if (isTabGroup ()) return this;
- }
- }
- return parent.computeTabRoot ();
-}
-
-NSView contentView () {
- return view;
-}
-
-NSAttributedString createString (String string, Font font, float /*double*/ [] foreground, int style, boolean enabled, boolean mnemonics) {
- NSMutableDictionary dict = ((NSMutableDictionary)new NSMutableDictionary().alloc()).initWithCapacity(5);
- if (font == null) font = this.font != null ? this.font : defaultFont();
- dict.setObject (font.handle, OS.NSFontAttributeName);
- addTraits(dict, font);
- if (enabled) {
- if (foreground != null) {
- NSColor color = NSColor.colorWithDeviceRed(foreground[0], foreground[1], foreground[2], foreground[3]);
- dict.setObject (color, OS.NSForegroundColorAttributeName);
- }
- } else {
- dict.setObject (NSColor.disabledControlTextColor (), OS.NSForegroundColorAttributeName);
- }
- if (style != 0) {
- NSMutableParagraphStyle paragraphStyle = (NSMutableParagraphStyle)new NSMutableParagraphStyle ().alloc ().init ();
- paragraphStyle.setLineBreakMode (OS.NSLineBreakByClipping);
- int alignment = SWT.LEFT;
- if ((style & SWT.CENTER) != 0) {
- alignment = OS.NSCenterTextAlignment;
- } else if ((style & SWT.RIGHT) != 0) {
- alignment = OS.NSRightTextAlignment;
- }
- paragraphStyle.setAlignment (alignment);
- dict.setObject (paragraphStyle, OS.NSParagraphStyleAttributeName);
- paragraphStyle.release ();
- }
- int length = string.length ();
- char [] chars = new char [length];
- string.getChars (0, chars.length, chars, 0);
- if (mnemonics) length = fixMnemonic (chars);
- NSString str = ((NSString)new NSString().alloc()).initWithCharacters(chars, length);
- NSAttributedString attribStr = ((NSAttributedString) new NSAttributedString ().alloc ()).initWithString (str, dict);
- str.release();
- dict.release();
- return attribStr;
-}
-
-void createWidget () {
- state |= DRAG_DETECT;
- checkOrientation (parent);
- super.createWidget ();
- checkBackground ();
- checkBuffered ();
- setDefaultFont ();
- setZOrder ();
- setRelations ();
- display.clearPool ();
-}
-
-Color defaultBackground () {
- return display.getWidgetColor (SWT.COLOR_WIDGET_BACKGROUND);
-}
-
-Font defaultFont () {
- if (display.smallFonts) return display.getSystemFont ();
- return Font.cocoa_new (display, defaultNSFont ());
-}
-
-Color defaultForeground () {
- return display.getWidgetColor (SWT.COLOR_WIDGET_FOREGROUND);
-}
-
-NSFont defaultNSFont () {
- return display.getSystemFont().handle;
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (view);
-}
-
-void destroyWidget () {
- NSView view = topView ();
- view.removeFromSuperview ();
- releaseHandle ();
-}
-
-void doCommandBySelector (int /*long*/ id, int /*long*/ sel, int /*long*/ selector) {
- if (view.window ().firstResponder ().id == id) {
- if (imeInComposition ()) return;
- Shell s = this.getShell();
- NSEvent nsEvent = NSApplication.sharedApplication ().currentEvent ();
- if (nsEvent != null && nsEvent.type () == OS.NSKeyDown) {
- /*
- * Feature in Cocoa. Pressing Alt+UpArrow invokes doCommandBySelector
- * twice, with selectors moveBackward and moveToBeginningOfParagraph
- * (Alt+DownArrow behaves similarly). In order to avoid sending
- * multiple events for these keys, do not send a KeyDown if we already sent one
- * during this keystroke. This rule does not apply if the command key
- * is down, because we likely triggered the current key sequence via flagsChanged.
- */
- int /*long*/ modifiers = nsEvent.modifierFlags();
- if (s.keyInputHappened == false || (modifiers & OS.NSCommandKeyMask) != 0) {
- s.keyInputHappened = true;
- boolean [] consume = new boolean [1];
- if (translateTraversal (nsEvent.keyCode (), nsEvent, consume)) return;
- if (isDisposed ()) return;
- if (!sendKeyEvent (nsEvent, SWT.KeyDown)) return;
- if (consume [0]) return;
- }
- }
- if ((state & CANVAS) != 0) return;
- }
- super.doCommandBySelector (id, sel, selector);
-}
-
-/**
- * Detects a drag and drop gesture. This method is used
- * to detect a drag gesture when called from within a mouse
- * down listener.
- *
- * <p>By default, a drag is detected when the gesture
- * occurs anywhere within the client area of a control.
- * Some controls, such as tables and trees, override this
- * behavior. In addition to the operating system specific
- * drag gesture, they require the mouse to be inside an
- * item. Custom widget writers can use <code>setDragDetect</code>
- * to disable the default detection, listen for mouse down,
- * and then call <code>dragDetect()</code> from within the
- * listener to conditionally detect a drag.
- * </p>
- *
- * @param event the mouse down event
- *
- * @return <code>true</code> if the gesture occurred, and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT when the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @see #getDragDetect
- * @see #setDragDetect
- *
- * @since 3.3
- */
-public boolean dragDetect (Event event) {
- checkWidget ();
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- return dragDetect (event.button, event.count, event.stateMask, event.x, event.y);
-}
-
-/**
- * Detects a drag and drop gesture. This method is used
- * to detect a drag gesture when called from within a mouse
- * down listener.
- *
- * <p>By default, a drag is detected when the gesture
- * occurs anywhere within the client area of a control.
- * Some controls, such as tables and trees, override this
- * behavior. In addition to the operating system specific
- * drag gesture, they require the mouse to be inside an
- * item. Custom widget writers can use <code>setDragDetect</code>
- * to disable the default detection, listen for mouse down,
- * and then call <code>dragDetect()</code> from within the
- * listener to conditionally detect a drag.
- * </p>
- *
- * @param event the mouse down event
- *
- * @return <code>true</code> if the gesture occurred, and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT when the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @see #getDragDetect
- * @see #setDragDetect
- *
- * @since 3.3
- */
-public boolean dragDetect (MouseEvent event) {
- checkWidget ();
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- return dragDetect (event.button, event.count, event.stateMask, event.x, event.y);
-}
-
-boolean dragDetect (int button, int count, int stateMask, int x, int y) {
- if (button != 1 || count != 1) return false;
- if (!dragDetect (x, y, false, null)) return false;
- return sendDragEvent (button, stateMask, x, y);
-}
-
-boolean dragDetect (int x, int y, boolean filter, boolean [] consume) {
- /**
- * Feature in Cocoa. Mouse drag events do not account for hysteresis.
- * As soon as the mouse drags a mouse dragged event is fired. Fix is to
- * check for another mouse drag event that is at least 5 pixels away
- * from the start of the drag.
- */
- NSApplication application = NSApplication.sharedApplication();
- boolean dragging = false;
- int /*long*/ eventType = OS.NSLeftMouseDown;
- float /*double*/ dragX = x;
- float /*double*/ dragY = y;
-
- /**
- * To check for an actual drag we need to pull off mouse moved and mouse up events
- * to detect if the user dragged outside of a 10 x 10 box centered on the mouse down location.
- * We still want the view to see the events, so save them and re-post when done checking.
- */
- NSEvent mouseUpEvent = null;
- NSMutableArray dragEvents = NSMutableArray.arrayWithCapacity(10);
-
- while (eventType != OS.NSLeftMouseUp) {
- NSEvent event = application.nextEventMatchingMask((OS.NSLeftMouseUpMask | OS.NSLeftMouseDraggedMask),
- NSDate.distantFuture(), OS.NSEventTrackingRunLoopMode, true);
- eventType = event.type();
-
- if (eventType == OS.NSLeftMouseDragged) {
- dragEvents.addObject(event);
- NSPoint windowLoc = event.locationInWindow();
- NSPoint viewLoc = view.convertPoint_fromView_(windowLoc, null);
- if (!view.isFlipped ()) {
- viewLoc.y = view.bounds().height - viewLoc.y;
- }
- if ((Math.abs(viewLoc.x - dragX) > DEFAULT_DRAG_HYSTERESIS) || (Math.abs(viewLoc.y - dragY) > DEFAULT_DRAG_HYSTERESIS)) {
- dragging = true;
- break;
- }
- } else if (eventType == OS.NSLeftMouseUp) {
- mouseUpEvent = event;
- }
- }
-
- // Push back any events we took out of the queue so the control can receive them.
- if (mouseUpEvent != null) application.postEvent(mouseUpEvent, true);
-
- if (dragEvents.count() > 0) {
- while (dragEvents.count() > 0) {
- NSEvent currEvent = new NSEvent(dragEvents.objectAtIndex(dragEvents.count() - 1).id);
- dragEvents.removeLastObject();
- application.postEvent(currEvent, true);
- }
- }
-
- return dragging;
-}
-
-boolean drawGripper (int x, int y, int width, int height, boolean vertical) {
- return false;
-}
-
-void drawWidget (int /*long*/ id, NSGraphicsContext context, NSRect rect) {
- if (id != paintView().id) return;
- if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return;
-
- /* Send paint event */
- GCData data = new GCData ();
- data.paintRect = rect;
- GC gc = GC.cocoa_new (this, data);
- Event event = new Event ();
- event.gc = gc;
- event.x = (int)rect.x;
- event.y = (int)rect.y;
- event.width = (int)rect.width;
- event.height = (int)rect.height;
- sendEvent (SWT.Paint, event);
- event.gc = null;
- gc.dispose ();
-}
-
-void enableWidget (boolean enabled) {
- if (view instanceof NSControl) {
- ((NSControl)view).setEnabled(enabled);
- }
- updateCursorRects (isEnabled ());
-}
-
-boolean equals(float /*double*/ [] color1, float /*double*/ [] color2) {
- if (color1 == color2) return true;
- if (color1 == null) return color2 == null;
- if (color2 == null) return color1 == null;
- for (int i = 0; i < color1.length; i++) {
- if (color1 [i] != color2 [i]) return false;
- }
- return true;
-}
-
-NSView eventView () {
- return view;
-}
-
-void fillBackground (NSView view, NSGraphicsContext context, NSRect rect, int imgHeight) {
- Control control = findBackgroundControl();
- if (control == null) control = this;
- Image image = control.backgroundImage;
- if (image != null && !image.isDisposed()) {
- context.saveGraphicsState();
- NSColor.colorWithPatternImage(image.handle).setFill();
- NSPoint phase = new NSPoint();
- NSView controlView = control.view;
- if (imgHeight == -1) {
- NSView contentView = controlView.window().contentView();
- phase = controlView.convertPoint_toView_(phase, contentView);
- phase.y = contentView.bounds().height - phase.y;
- } else {
- phase = view.convertPoint_toView_(phase, controlView);
- phase.y += imgHeight - backgroundImage.getBounds().height;
- }
- context.setPatternPhase(phase);
- NSBezierPath.fillRect(rect);
- context.restoreGraphicsState();
- return;
- }
-
- float /*double*/ [] background = control.background;
- float /*double*/ alpha;
- if (background == null) {
- background = control.defaultBackground ().handle;
- alpha = getThemeAlpha ();
- } else {
- alpha = background[3];
- }
- context.saveGraphicsState ();
- NSColor.colorWithDeviceRed (background [0], background [1], background [2], alpha).setFill ();
- NSBezierPath.fillRect (rect);
- context.restoreGraphicsState ();
-}
-
-Cursor findCursor () {
- if (cursor != null) return cursor;
- return parent.findCursor ();
-}
-
-Control findBackgroundControl () {
- if (backgroundImage != null || background != null) return this;
- return (state & PARENT_BACKGROUND) != 0 ? parent.findBackgroundControl () : null;
-}
-
-Menu [] findMenus (Control control) {
- if (menu != null && this != control) return new Menu [] {menu};
- return new Menu [0];
-}
-
-Widget findTooltip (NSPoint pt) {
- return this;
-}
-
-void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) {
- oldShell.fixShell (newShell, this);
- oldDecorations.fixDecorations (newDecorations, this, menus);
-}
-
-void fixFocus (Control focusControl) {
- Shell shell = getShell ();
- Control control = this;
- while (control != shell && (control = control.parent) != null) {
- if (control.setFocus ()) return;
- }
- shell.setSavedFocus (focusControl);
-// int window = OS.GetControlOwner (handle);
-// OS.ClearKeyboardFocus (window);
-}
-
-void flagsChanged (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (view.window ().firstResponder ().id == id) {
- if ((state & SAFARI_EVENTS_FIX) == 0) {
- Shell s = this.getShell();
- s.keyInputHappened = false;
- int mask = 0;
- NSEvent nsEvent = new NSEvent (theEvent);
- int /*long*/ modifiers = nsEvent.modifierFlags ();
- int keyCode = Display.translateKey (nsEvent.keyCode ());
- switch (keyCode) {
- case SWT.ALT: mask = OS.NSAlternateKeyMask; break;
- case SWT.CONTROL: mask = OS.NSControlKeyMask; break;
- case SWT.COMMAND: mask = OS.NSCommandKeyMask; break;
- case SWT.SHIFT: mask = OS.NSShiftKeyMask; break;
- case SWT.CAPS_LOCK:
- Event event = new Event();
- event.keyCode = keyCode;
- setInputState (event, nsEvent, SWT.KeyDown);
- sendKeyEvent (SWT.KeyDown, event);
- setInputState (event, nsEvent, SWT.KeyUp);
- sendKeyEvent (SWT.KeyUp, event);
- break;
- }
- if (mask != 0) {
- s.keyInputHappened = true;
- int type = (mask & modifiers) != 0 ? SWT.KeyDown : SWT.KeyUp;
- if (type == SWT.KeyDown) s.keyInputHappened = true;
- Event event = new Event();
- event.keyCode = keyCode;
- setInputState (event, nsEvent, type);
- if (!sendKeyEvent (type, event)) return;
- }
- }
- }
- super.flagsChanged (id, sel, theEvent);
-}
-
-NSView focusView () {
- return view;
-}
-
-/**
- * Forces the receiver to have the <em>keyboard focus</em>, causing
- * all keyboard events to be delivered to it.
- *
- * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setFocus
- */
-public boolean forceFocus () {
- checkWidget();
- if (display.focusEvent == SWT.FocusOut) return false;
- Decorations shell = menuShell ();
- shell.setSavedFocus (this);
- if (!isEnabled () || !isVisible () || !isActive ()) return false;
- if (isFocusControl ()) return true;
- shell.setSavedFocus (null);
- NSView focusView = focusView ();
- if (!focusView.canBecomeKeyView()) return false;
- boolean result = view.window ().makeFirstResponder (focusView);
- if (isDisposed ()) return false;
- shell.bringToTop (false);
- if (isDisposed ()) return false;
- shell.setSavedFocus (this);
- return result;
-}
-
-/**
- * Returns the accessible object for the receiver.
- * If this is the first time this object is requested,
- * then the object is created and returned.
- *
- * @return the accessible object
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Accessible#addAccessibleListener
- * @see Accessible#addAccessibleControlListener
- *
- * @since 2.0
- */
-public Accessible getAccessible () {
- checkWidget ();
- if (accessible == null) accessible = new_Accessible (this);
- return accessible;
-}
-
-/**
- * Returns the receiver's background color.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on some versions of Windows the background of a TabFolder,
- * is a gradient rather than a solid color.
- * </p>
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Color getBackground () {
- checkWidget();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- return control.getBackgroundColor ();
-}
-
-Color getBackgroundColor () {
- return background != null ? Color.cocoa_new (display, background) : defaultBackground ();
-}
-
-/**
- * Returns the receiver's background image.
- *
- * @return the background image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Image getBackgroundImage () {
- checkWidget();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- return control.backgroundImage;
-}
-
-/**
- * Returns the receiver's border width.
- *
- * @return the border width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getBorderWidth () {
- checkWidget();
- return 0;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null),
- * unless the receiver is a shell. In this case, the location is
- * relative to the display.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- NSRect rect = topView().frame();
- return new Rectangle((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is detecting
- * drag gestures, and <code>false</code> otherwise.
- *
- * @return the receiver's drag detect state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public boolean getDragDetect () {
- checkWidget ();
- return (state & DRAG_DETECT) != 0;
-}
-
-boolean getDrawing () {
- return drawCount <= 0;
-}
-
-/**
- * Returns the receiver's cursor, or null if it has not been set.
- * <p>
- * When the mouse pointer passes over a control its appearance
- * is changed to match the control's cursor.
- * </p>
- *
- * @return the receiver's cursor or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Cursor getCursor () {
- checkWidget();
- return cursor;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- return (state & DISABLED) == 0;
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Font getFont () {
- checkWidget();
- return font != null ? font : defaultFont ();
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Color getForeground () {
- checkWidget();
- return getForegroundColor ();
-}
-
-Color getForegroundColor () {
- return foreground != null ? Color.cocoa_new (display, foreground) : defaultForeground ();
-}
-
-/**
- * Returns layout data which is associated with the receiver.
- *
- * @return the receiver's layout data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Object getLayoutData () {
- checkWidget();
- return layoutData;
-}
-
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @return the receiver's location
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getLocation () {
- checkWidget();
- NSRect rect = topView().frame();
- return new Point((int)rect.x, (int)rect.y);
-}
-
-/**
- * Returns the receiver's pop up menu if it has one, or null
- * if it does not. All controls may optionally have a pop up
- * menu that is displayed when the user requests one for
- * the control. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pop up
- * menu is platform specific.
- *
- * @return the receiver's menu
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenu () {
- checkWidget();
- return menu;
-}
-
-int getMininumHeight () {
- return 0;
-}
-
-/**
- * Returns the receiver's monitor.
- *
- * @return the receiver's monitor
- *
- * @since 3.0
- */
-public Monitor getMonitor () {
- checkWidget();
- Monitor [] monitors = display.getMonitors ();
- if (monitors.length == 1) return monitors [0];
- int index = -1, value = -1;
- Rectangle bounds = getBounds ();
- if (this != getShell ()) {
- bounds = display.map (this.parent, null, bounds);
- }
- for (int i=0; i<monitors.length; i++) {
- Rectangle rect = bounds.intersection (monitors [i].getBounds ());
- int area = rect.width * rect.height;
- if (area > 0 && area > value) {
- index = i;
- value = area;
- }
- }
- if (index >= 0) return monitors [index];
- int centerX = bounds.x + bounds.width / 2, centerY = bounds.y + bounds.height / 2;
- for (int i=0; i<monitors.length; i++) {
- Rectangle rect = monitors [i].getBounds ();
- int x = centerX < rect.x ? rect.x - centerX : centerX > rect.x + rect.width ? centerX - rect.x - rect.width : 0;
- int y = centerY < rect.y ? rect.y - centerY : centerY > rect.y + rect.height ? centerY - rect.y - rect.height : 0;
- int distance = x * x + y * y;
- if (index == -1 || distance < value) {
- index = i;
- value = distance;
- }
- }
- return monitors [index];
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Composite</code>
- * or null when the receiver is a shell that was created with null or
- * a display for a parent.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Composite getParent () {
- checkWidget();
- return parent;
-}
-
-Control [] getPath () {
- int count = 0;
- Shell shell = getShell ();
- Control control = this;
- while (control != shell) {
- count++;
- control = control.parent;
- }
- control = this;
- Control [] result = new Control [count];
- while (control != shell) {
- result [--count] = control;
- control = control.parent;
- }
- return result;
-}
-
-NSBezierPath getPath(Region region) {
- if (region == null) return null;
- return getPath(region.handle);
-}
-
-NSBezierPath getPath(int /*long*/ region) {
- Callback callback = new Callback(this, "regionToRects", 4);
- if (callback.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- NSBezierPath path = NSBezierPath.bezierPath();
- path.retain();
- OS.QDRegionToRects(region, OS.kQDParseRegionFromTopLeft, callback.getAddress(), path.id);
- callback.dispose();
- if (path.isEmpty()) path.appendBezierPathWithRect(new NSRect());
- return path;
-}
-
-/**
- * Returns the region that defines the shape of the control,
- * or null if the control has the default shape.
- *
- * @return the region that defines the shape of the shell (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public Region getRegion () {
- checkWidget ();
- return region;
-}
-
-/**
- * Returns the receiver's shell. For all controls other than
- * shells, this simply returns the control's nearest ancestor
- * shell. Shells return themselves, even if they are children
- * of other shells.
- *
- * @return the receiver's shell
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getParent
- */
-public Shell getShell () {
- checkWidget();
- return parent.getShell ();
-}
-
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- NSRect rect = topView().frame();
- return new Point((int)rect.width, (int)rect.height);
-}
-
-float getThemeAlpha () {
- return 1 * parent.getThemeAlpha ();
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- return (state & HIDDEN) == 0;
-}
-
-int /*long*/ getVisibleRegion () {
- if (visibleRgn == 0) {
- visibleRgn = OS.NewRgn ();
- calculateVisibleRegion (view, visibleRgn, true);
- }
- int /*long*/ result = OS.NewRgn ();
- OS.CopyRgn (visibleRgn, result);
- return result;
-}
-
-boolean hasBorder () {
- return (style & SWT.BORDER) != 0;
-}
-
-boolean hasFocus () {
- return display.getFocusControl() == this;
-}
-
-int /*long*/ hitTest (int /*long*/ id, int /*long*/ sel, NSPoint point) {
- if ((state & DISABLED) != 0) return 0;
- if (!isActive ()) return 0;
- if (regionPath != null) {
- NSView superview = new NSView(id).superview();
- if (superview != null) {
- NSPoint pt = superview.convertPoint_toView_(point, view);
- if (!view.isFlipped ()) {
- pt.y = view.bounds().height - pt.y;
- }
- if (!regionPath.containsPoint(pt)) return 0;
- }
- }
- return super.hitTest(id, sel, point);
-}
-
-boolean imeInComposition () {
- return false;
-}
-
-boolean insertText (int /*long*/ id, int /*long*/ sel, int /*long*/ string) {
- if (view.window ().firstResponder ().id == id) {
- Shell s = this.getShell();
- NSEvent nsEvent = NSApplication.sharedApplication ().currentEvent ();
- if (nsEvent != null) {
- int /*long*/ type = nsEvent.type ();
- if ((!s.keyInputHappened && type == OS.NSKeyDown) || type == OS.NSSystemDefined) {
- NSString str = new NSString (string);
- if (str.isKindOfClass (OS.objc_getClass ("NSAttributedString"))) {
- str = new NSAttributedString (string).string ();
- }
- int length = (int)/*64*/str.length ();
- char[] buffer = new char [length];
- str.getCharacters(buffer);
- for (int i = 0; i < buffer.length; i++) {
- s.keyInputHappened = true;
- Event event = new Event ();
- if (i == 0 && type == OS.NSKeyDown) setKeyState (event, SWT.KeyDown, nsEvent);
- event.character = buffer [i];
- if (!sendKeyEvent (SWT.KeyDown, event)) return false;
- }
- }
- }
- if ((state & CANVAS) != 0) return true;
- }
- return super.insertText (id, sel, string);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Control</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public int /*long*/ internal_new_GC (GCData data) {
- checkWidget();
- NSView view = paintView();
- int /*long*/ context = 0;
- if (data != null && data.paintRect != null) {
- NSGraphicsContext graphicsContext = NSGraphicsContext.currentContext();
- context = graphicsContext.id;
- if (!view.isFlipped()) data.state &= ~VISIBLE_REGION;
- } else {
- NSGraphicsContext graphicsContext = NSGraphicsContext.graphicsContextWithWindow (view.window ());
- NSGraphicsContext flippedContext = NSGraphicsContext.graphicsContextWithGraphicsPort(graphicsContext.graphicsPort(), true);
- graphicsContext = flippedContext;
- context = graphicsContext.id;
- if (data != null) {
- data.flippedContext = flippedContext;
- data.state &= ~VISIBLE_REGION;
- data.visibleRgn = getVisibleRegion();
- display.addContext (data);
- }
- }
- if (data != null) {
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) == 0) {
- data.style |= style & (mask | SWT.MIRRORED);
- }
- data.device = display;
- data.thread = display.thread;
- data.view = view;
- data.foreground = getForegroundColor ().handle;
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- data.background = control.getBackgroundColor ().handle;
- data.font = font != null ? font : defaultFont ();
- }
- return context;
-}
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Control</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int /*long*/ context, GCData data) {
- checkWidget ();
- NSGraphicsContext graphicsContext = new NSGraphicsContext (context);
- display.removeContext (data);
- if (data != null) {
- if (data.paintRect == null) graphicsContext.flushGraphics ();
- if (data.visibleRgn != 0) OS.DisposeRgn(data.visibleRgn);
- data.visibleRgn = 0;
- }
-}
-
-void invalidateChildrenVisibleRegion () {
-}
-
-void invalidateVisibleRegion () {
- int index = 0;
- Control[] siblings = parent._getChildren ();
- while (index < siblings.length && siblings [index] != this) index++;
- for (int i=index; i<siblings.length; i++) {
- Control sibling = siblings [i];
- sibling.resetVisibleRegion ();
- sibling.invalidateChildrenVisibleRegion ();
- }
- parent.resetVisibleRegion ();
-}
-
-boolean isActive () {
- return getShell().getModalShell() == null;
-}
-
-/*
- * Answers a boolean indicating whether a Label that precedes the receiver in
- * a layout should be read by screen readers as the recevier's label.
- */
-boolean isDescribedByLabel () {
- return true;
-}
-
-boolean isDrawing () {
- return getDrawing() && parent.isDrawing();
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * ancestors up to and including the receiver's nearest ancestor
- * shell are enabled. Otherwise, <code>false</code> is returned.
- * A disabled control is typically not selectable from the user
- * interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-
-boolean isEnabledCursor () {
- return isEnabled ();
-}
-
-boolean isFocusAncestor (Control control) {
- while (control != null && control != this && !(control instanceof Shell)) {
- control = control.parent;
- }
- return control == this;
-}
-
-/**
- * Returns <code>true</code> if the receiver has the user-interface
- * focus, and <code>false</code> otherwise.
- *
- * @return the receiver's focus state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isFocusControl () {
- checkWidget();
- Control focusControl = display.focusControl;
- if (focusControl != null && !focusControl.isDisposed ()) {
- return this == focusControl;
- }
- return hasFocus ();
-}
-
-boolean isObscured () {
- int /*long*/ visibleRgn = getVisibleRegion(), boundsRgn = OS.NewRgn();
- short[] rect = new short[4];
- NSRect bounds = view.visibleRect();
- OS.SetRect(rect, (short)bounds.x, (short)bounds.y, (short)(bounds.x + bounds.width), (short)(bounds.y + bounds.height));
- OS.RectRgn(boundsRgn, rect);
- OS.DiffRgn(boundsRgn, visibleRgn, boundsRgn);
- boolean obscured = !OS.EmptyRgn (boundsRgn);
- OS.DisposeRgn(boundsRgn);
- OS.DisposeRgn(visibleRgn);
- return obscured;
-}
-
-/**
- * Returns <code>true</code> if the underlying operating
- * system supports this reparenting, otherwise <code>false</code>
- *
- * @return <code>true</code> if the widget can be reparented, otherwise <code>false</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isReparentable () {
- checkWidget();
- return true;
-}
-
-boolean isShowing () {
- /*
- * This is not complete. Need to check if the
- * widget is obscurred by a parent or sibling.
- */
- if (!isVisible ()) return false;
- Control control = this;
- while (control != null) {
- Point size = control.getSize ();
- if (size.x == 0 || size.y == 0) {
- return false;
- }
- control = control.parent;
- }
- return true;
-}
-
-boolean isTabGroup () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == this) return true;
- }
- }
- int code = traversalCode (0, null);
- if ((code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) != 0) return false;
- return (code & (SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_TAB_NEXT)) != 0;
-}
-
-boolean isTabItem () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == this) return false;
- }
- }
- int code = traversalCode (0, null);
- return (code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) != 0;
-}
-
-boolean isTrim (NSView view) {
- return false;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * ancestors up to and including the receiver's nearest ancestor
- * shell are visible. Otherwise, <code>false</code> is returned.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return getVisible () && parent.isVisible ();
-}
-
-void keyDown (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (view.window ().firstResponder ().id == id) {
- Shell s = this.getShell();
- s.keyInputHappened = false;
- boolean textInput = OS.objc_msgSend (id, OS.sel_conformsToProtocol_, OS.objc_getProtocol ("NSTextInput")) != 0;
- if (!textInput) {
- // Not a text field, so send a key event here.
- NSEvent nsEvent = new NSEvent (theEvent);
- boolean [] consume = new boolean [1];
- if (translateTraversal (nsEvent.keyCode (), nsEvent, consume)) return;
- if (isDisposed ()) return;
- if (!sendKeyEvent (nsEvent, SWT.KeyDown)) return;
- if (consume [0]) return;
- } else {
- // Control is some kind of text field, so the key event will be sent from insertText: or doCommandBySelector:
- super.keyDown (id, sel, theEvent);
-
- if (imeInComposition ()) return;
- // If none of those methods triggered a key event send one now.
- if (!s.keyInputHappened) {
- NSEvent nsEvent = new NSEvent (theEvent);
- boolean [] consume = new boolean [1];
- if (translateTraversal (nsEvent.keyCode (), nsEvent, consume)) return;
- if (isDisposed ()) return;
- if (!sendKeyEvent (nsEvent, SWT.KeyDown)) return;
- if (consume [0]) return;
- }
-
- return;
- }
- }
- super.keyDown (id, sel, theEvent);
-}
-
-void keyUp (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (view.window ().firstResponder ().id == id) {
- NSEvent nsEvent = new NSEvent (theEvent);
- if (!sendKeyEvent (nsEvent, SWT.KeyUp)) return;
- }
- super.keyUp (id, sel, theEvent);
-}
-
-void markLayout (boolean changed, boolean all) {
- /* Do nothing */
-}
-
-int /*long*/ menuForEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!isEnabled ()) return 0;
-
- NSPoint pt = NSEvent.mouseLocation();
- pt.y = (int) (display.getPrimaryFrame().height - pt.y);
- int x = (int) pt.x;
- int y = (int) pt.y;
- Event event = new Event ();
- event.x = x;
- event.y = y;
- sendEvent (SWT.MenuDetect, event);
- //widget could be disposed at this point
- if (isDisposed ()) return 0;
- if (!event.doit) return 0;
- Menu menu = getMenu ();
- if (menu != null && !menu.isDisposed ()) {
- if (x != event.x || y != event.y) {
- menu.setLocation (event.x, event.y);
- }
- menu.setVisible(true);
- return 0;
- }
- return super.menuForEvent (id, sel, theEvent);
-}
-
-Decorations menuShell () {
- return parent.menuShell ();
-}
-
-void scrollWheel (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (id == view.id) {
- if (hooks (SWT.MouseWheel) || filters (SWT.MouseWheel)) {
- NSEvent nsEvent = new NSEvent(theEvent);
- if (nsEvent.deltaY() != 0) {
- if (!sendMouseEvent(nsEvent, SWT.MouseWheel, true)) {
- return;
- }
- }
- }
- }
- super.scrollWheel(id, sel, theEvent);
-}
-
-boolean isEventView (int /*long*/ id) {
- return true;
-}
-
-boolean mouseEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent, int type) {
- if (!display.sendEvent) return true;
- display.sendEvent = false;
- if (!isEventView (id)) return true;
- boolean dragging = false;
- boolean[] consume = null;
- NSEvent nsEvent = new NSEvent(theEvent);
- int nsType = (int)/*64*/nsEvent.type();
- NSInputManager manager = NSInputManager.currentInputManager ();
- if (manager != null && manager.wantsToHandleMouseEvents ()) {
- if (manager.handleMouseEvent (nsEvent)) {
- return true;
- }
- }
- switch (nsType) {
- case OS.NSLeftMouseDown:
- if (nsEvent.clickCount() == 1 && (state & DRAG_DETECT) != 0 && hooks (SWT.DragDetect)) {
- consume = new boolean[1];
- NSPoint location = view.convertPoint_fromView_(nsEvent.locationInWindow(), null);
- if (!view.isFlipped ()) {
- location.y = view.bounds().height - location.y;
- }
- dragging = dragDetect((int)location.x, (int)location.y, false, consume);
- }
- break;
- case OS.NSLeftMouseDragged:
- case OS.NSRightMouseDragged:
- case OS.NSOtherMouseDragged:
- display.checkEnterExit (this, nsEvent, false);
- break;
- case OS.NSLeftMouseUp:
- case OS.NSRightMouseUp:
- case OS.NSOtherMouseUp:
- display.checkEnterExit (display.findControl(true), nsEvent, false);
- break;
- }
- sendMouseEvent (nsEvent, type, false);
- if (type == SWT.MouseDown && nsEvent.clickCount() == 2) {
- sendMouseEvent (nsEvent, SWT.MouseDoubleClick, false);
- }
- if (dragging) sendMouseEvent(nsEvent, SWT.DragDetect, false);
- if (consume != null && consume[0]) return false;
- return true;
-}
-
-void mouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!mouseEvent(id, sel, theEvent, SWT.MouseDown)) return;
- boolean tracking = isEventView (id);
- Display display = this.display;
- if (tracking) display.trackingControl = this;
- super.mouseDown(id, sel, theEvent);
- if (tracking) display.trackingControl = null;
-}
-
-void mouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!mouseEvent(id, sel, theEvent, SWT.MouseUp)) return;
- super.mouseUp(id, sel, theEvent);
-}
-
-void mouseDragged(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!mouseEvent(id, sel, theEvent, SWT.MouseMove)) return;
- super.mouseDragged(id, sel, theEvent);
-}
-
-void rightMouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!mouseEvent(id, sel, theEvent, SWT.MouseDown)) return;
- super.rightMouseDown(id, sel, theEvent);
-}
-
-void rightMouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!mouseEvent(id, sel, theEvent, SWT.MouseUp)) return;
- super.rightMouseUp(id, sel, theEvent);
-}
-
-void rightMouseDragged(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!mouseEvent(id, sel, theEvent, SWT.MouseMove)) return;
- super.rightMouseDragged(id, sel, theEvent);
-}
-
-void otherMouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!mouseEvent(id, sel, theEvent, SWT.MouseDown)) return;
- super.otherMouseDown(id, sel, theEvent);
-}
-
-void otherMouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!mouseEvent(id, sel, theEvent, SWT.MouseUp)) return;
- super.otherMouseUp(id, sel, theEvent);
-}
-
-void otherMouseDragged(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!mouseEvent(id, sel, theEvent, SWT.MouseMove)) return;
- super.otherMouseDragged(id, sel, theEvent);
-}
-
-void moved () {
- sendEvent (SWT.Move);
-}
-
-/**
- * Moves the receiver above the specified control in the
- * drawing order. If the argument is null, then the receiver
- * is moved to the top of the drawing order. The control at
- * the top of the drawing order will not be covered by other
- * controls even if they occupy intersecting areas.
- *
- * @param control the sibling control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveBelow
- * @see Composite#getChildren
- */
-public void moveAbove (Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- }
- setZOrder (control, true);
-}
-
-/**
- * Moves the receiver below the specified control in the
- * drawing order. If the argument is null, then the receiver
- * is moved to the bottom of the drawing order. The control at
- * the bottom of the drawing order will be covered by all other
- * controls which occupy intersecting areas.
- *
- * @param control the sibling control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveAbove
- * @see Composite#getChildren
- */
-public void moveBelow (Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- }
- setZOrder (control, false);
-}
-
-Accessible new_Accessible (Control control) {
- return Accessible.internal_new_Accessible (this);
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeSize(int, int, boolean)
- */
-public void pack () {
- checkWidget();
- pack (true);
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- * <p>
- * If the changed flag is <code>true</code>, it indicates that the receiver's
- * <em>contents</em> have changed, therefore any caches that a layout manager
- * containing the control may have been keeping need to be flushed. When the
- * control is resized, the changed flag will be <code>false</code>, so layout
- * manager caches can be retained.
- * </p>
- *
- * @param changed whether or not the receiver's contents have changed
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeSize(int, int, boolean)
- */
-public void pack (boolean changed) {
- checkWidget();
- setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed));
-}
-
-NSView paintView () {
- return eventView ();
-}
-
-/**
- * Prints the receiver and all children.
- *
- * @param gc the gc where the drawing occurs
- * @return <code>true</code> if the operation was successful and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean print (GC gc) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
-
- gc.handle.saveGraphicsState();
- NSGraphicsContext.setCurrentContext(gc.handle);
- NSAffineTransform transform = NSAffineTransform.transform ();
- transform.translateXBy (0, view.bounds().height);
- transform.scaleXBy (1, -1);
- transform.concat ();
- view.displayRectIgnoringOpacity(view.bounds(), gc.handle);
- gc.handle.restoreGraphicsState();
- return true;
-}
-
-/**
- * Causes the entire bounds of the receiver to be marked
- * as needing to be redrawn. The next time a paint request
- * is processed, the control will be completely painted,
- * including the background.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #update()
- * @see PaintListener
- * @see SWT#Paint
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#DOUBLE_BUFFERED
- */
-public void redraw () {
- checkWidget();
- view.setNeedsDisplay(true);
-}
-
-void redraw (boolean children) {
-// checkWidget();
- view.setNeedsDisplay(true);
-}
-
-/**
- * Causes the rectangular area of the receiver specified by
- * the arguments to be marked as needing to be redrawn.
- * The next time a paint request is processed, that area of
- * the receiver will be painted, including the background.
- * If the <code>all</code> flag is <code>true</code>, any
- * children of the receiver which intersect with the specified
- * area will also paint their intersecting areas. If the
- * <code>all</code> flag is <code>false</code>, the children
- * will not be painted.
- *
- * @param x the x coordinate of the area to draw
- * @param y the y coordinate of the area to draw
- * @param width the width of the area to draw
- * @param height the height of the area to draw
- * @param all <code>true</code> if children should redraw, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #update()
- * @see PaintListener
- * @see SWT#Paint
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#DOUBLE_BUFFERED
- */
-public void redraw (int x, int y, int width, int height, boolean all) {
- checkWidget ();
- NSRect rect = new NSRect();
- rect.x = x;
- rect.y = y;
- rect.width = width;
- rect.height = height;
- view.setNeedsDisplayInRect(rect);
-}
-
-int /*long*/ regionToRects(int /*long*/ message, int /*long*/ rgn, int /*long*/ r, int /*long*/ path) {
- NSPoint pt = new NSPoint();
- short[] rect = new short[4];
- if (message == OS.kQDRegionToRectsMsgParse) {
- OS.memmove(rect, r, rect.length * 2);
- pt.x = rect[1];
- pt.y = rect[0];
- OS.objc_msgSend(path, OS.sel_moveToPoint_, pt);
- pt.x = rect[3];
- OS.objc_msgSend(path, OS.sel_lineToPoint_, pt);
- pt.x = rect[3];
- pt.y = rect[2];
- OS.objc_msgSend(path, OS.sel_lineToPoint_, pt);
- pt.x = rect[1];
- OS.objc_msgSend(path, OS.sel_lineToPoint_, pt);
- OS.objc_msgSend(path, OS.sel_closePath);
- }
- return 0;
-}
-
-void register () {
- super.register ();
- display.addWidget (view, this);
-}
-
-void release (boolean destroy) {
- Control next = null, previous = null;
- if (destroy && parent != null) {
- Control[] children = parent._getChildren ();
- int index = 0;
- while (index < children.length) {
- if (children [index] == this) break;
- index++;
- }
- if (0 < index && (index + 1) < children.length) {
- next = children [index + 1];
- previous = children [index - 1];
- }
- }
- super.release (destroy);
- if (destroy) {
- if (previous != null) previous.addRelation (next);
- }
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (view != null) view.release();
- view = null;
- parent = null;
-}
-
-void releaseParent () {
- invalidateVisibleRegion ();
- parent.removeControl (this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (display.currentControl == this) {
- display.currentControl = null;
- display.timerExec(-1, display.hoverTimer);
- }
- if (display.trackingControl == this) display.trackingControl = null;
- if (display.tooltipControl == this) display.tooltipControl = null;
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- menu = null;
- if (visibleRgn != 0) OS.DisposeRgn (visibleRgn);
- visibleRgn = 0;
- layoutData = null;
- if (accessible != null) {
- accessible.internal_dispose_Accessible ();
- }
- accessible = null;
- region = null;
- if (regionPath != null) regionPath.release();
- regionPath = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when a drag gesture occurs.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @since 3.3
- */
-public void removeDragDetectListener(DragDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.DragDetect, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control gains or loses focus.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see FocusListener
- * @see #addFocusListener
- */
-public void removeFocusListener(FocusListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.FocusIn, listener);
- eventTable.unhook(SWT.FocusOut, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #addKeyListener
- */
-public void removeKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.KeyUp, listener);
- eventTable.unhook(SWT.KeyDown, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the platform-specific context menu trigger has
- * occurred.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #addMenuDetectListener
- *
- * @since 3.3
- */
-public void removeMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MenuDetect, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when mouse buttons are pressed and released.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseListener
- * @see #addMouseListener
- */
-public void removeMouseListener(MouseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.MouseDown, listener);
- eventTable.unhook(SWT.MouseUp, listener);
- eventTable.unhook(SWT.MouseDoubleClick, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse moves.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseMoveListener
- * @see #addMouseMoveListener
- */
-public void removeMouseMoveListener(MouseMoveListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.MouseMove, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse passes or hovers over controls.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseTrackListener
- * @see #addMouseTrackListener
- */
-public void removeMouseTrackListener(MouseTrackListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseEnter, listener);
- eventTable.unhook (SWT.MouseExit, listener);
- eventTable.unhook (SWT.MouseHover, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse wheel is scrolled.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseWheelListener
- * @see #addMouseWheelListener
- *
- * @since 3.3
- */
-public void removeMouseWheelListener (MouseWheelListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseWheel, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver needs to be painted.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see PaintListener
- * @see #addPaintListener
- */
-public void removePaintListener(PaintListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Paint, listener);
-}
-
-/*
- * Remove "Labeled by" relations from the receiver.
- */
-void removeRelation () {
- if (!isDescribedByLabel()) return;
- NSObject accessibleElement = focusView();
-
- if (accessibleElement instanceof NSControl) {
- NSControl viewAsControl = (NSControl) accessibleElement;
- if (viewAsControl.cell() != null) accessibleElement = viewAsControl.cell();
- }
-
- accessibleElement.accessibilitySetOverrideValue(accessibleElement, OS.NSAccessibilityTitleUIElementAttribute);
-}
-
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when traversal events occur.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TraverseListener
- * @see #addTraverseListener
- */
-public void removeTraverseListener(TraverseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Traverse, listener);
-}
-
-void resetVisibleRegion () {
- if (visibleRgn != 0) {
- OS.DisposeRgn (visibleRgn);
- visibleRgn = 0;
- }
- GCData[] gcs = display.contexts;
- if (gcs != null) {
- int /*long*/ visibleRgn = 0;
- for (int i=0; i<gcs.length; i++) {
- GCData data = gcs [i];
- if (data != null) {
- if (data.view == view) {
- if (visibleRgn == 0) visibleRgn = getVisibleRegion ();
- data.state &= ~VISIBLE_REGION;
- OS.CopyRgn (visibleRgn, data.visibleRgn);
- }
- }
- }
- if (visibleRgn != 0) OS.DisposeRgn (visibleRgn);
- }
-}
-
-void resized () {
- sendEvent (SWT.Resize);
-}
-
-boolean sendDragEvent (int button, int stateMask, int x, int y) {
- Event event = new Event ();
- event.button = button;
- event.x = x;
- event.y = y;
- event.stateMask = stateMask;
- postEvent (SWT.DragDetect, event);
- return event.doit;
-}
-
-void sendFocusEvent (int type) {
- Display display = this.display;
- Shell shell = getShell ();
-
- display.focusEvent = type;
- display.focusControl = this;
- sendEvent (type);
- // widget could be disposed at this point
- display.focusEvent = SWT.None;
- display.focusControl = null;
-
- /*
- * It is possible that the shell may be
- * disposed at this point. If this happens
- * don't send the activate and deactivate
- * events.
- */
- if (!shell.isDisposed ()) {
- switch (type) {
- case SWT.FocusIn:
- shell.setActiveControl (this);
- break;
- case SWT.FocusOut:
- if (shell != display.getActiveShell ()) {
- shell.setActiveControl (null);
- }
- break;
- }
- }
-}
-
-boolean sendMouseEvent (NSEvent nsEvent, int type, boolean send) {
- Shell shell = null;
- Event event = new Event ();
- switch (type) {
- case SWT.MouseDown:
- shell = getShell ();
- //FALL THROUGH
- case SWT.MouseUp:
- case SWT.MouseDoubleClick:
- case SWT.DragDetect:
- int button = (int)/*64*/nsEvent.buttonNumber();
- switch (button) {
- case 0: event.button = 1; break;
- case 1: event.button = 3; break;
- case 2: event.button = 2; break;
- case 3: event.button = 4; break;
- case 4: event.button = 5; break;
- }
- break;
- case SWT.MouseWheel:
- event.detail = SWT.SCROLL_LINE;
- float /*double*/ delta = nsEvent.deltaY();
- event.count = delta > 0 ? Math.max (1, (int)delta) : Math.min (-1, (int)delta);
- break;
- }
- if (event.button != 0) event.count = (int)/*64*/nsEvent.clickCount();
- NSPoint windowPoint;
- NSView view = eventView ();
- if (nsEvent == null || nsEvent.type() == OS.NSMouseMoved) {
- NSWindow window = view.window();
- windowPoint = window.convertScreenToBase(NSEvent.mouseLocation());
- } else {
- windowPoint = nsEvent.locationInWindow();
- }
- NSPoint point = view.convertPoint_fromView_(windowPoint, null);
- if (!view.isFlipped ()) {
- point.y = view.bounds().height - point.y;
- }
- event.x = (int) point.x;
- event.y = (int) point.y;
- setInputState (event, nsEvent, type);
- if (send) {
- sendEvent (type, event);
- if (isDisposed ()) return false;
- } else {
- postEvent (type, event);
- }
- if (shell != null) shell.setActiveControl(this);
- return event.doit;
-}
-
-void setBackground () {
-// redrawWidget (handle, false);
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the control
- * if the argument is null.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on Windows the background of a Button cannot be changed.
- * </p>
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBackground (Color color) {
- checkWidget();
- if (color != null) {
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- float /*double*/ [] background = color != null ? color.handle : null;
- if (equals (background, this.background)) return;
- this.background = background;
- updateBackground ();
- redrawWidget(view, true);
-}
-
-/**
- * Sets the receiver's background image to the image specified
- * by the argument, or to the default system color for the control
- * if the argument is null. The background image is tiled to fill
- * the available space.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on Windows the background of a Button cannot be changed.
- * </p>
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument is not a bitmap</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setBackgroundImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (image == backgroundImage) return;
- backgroundImage = image;
- updateBackground();
- redrawWidget(view, false);
-}
-
-void updateBackground () {
-}
-
-void setBackground (NSColor nsColor) {
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the arguments. The <code>x</code> and
- * <code>y</code> arguments are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the <code>x</code>
- * and <code>y</code> arguments are relative to the display.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (int x, int y, int width, int height) {
- checkWidget();
- setBounds (x, y, Math.max (0, width), Math.max (0, height), true, true);
-}
-
-void setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- NSView topView = topView();
- if (move && resize) {
- NSRect rect = new NSRect();
- rect.x = x;
- rect.y = y;
- rect.width = width;
- rect.height = height;
- topView.setFrame (rect);
- } else if (move) {
- NSPoint point = new NSPoint();
- point.x = x;
- point.y = y;
- topView.setFrameOrigin(point);
- } else if (resize) {
- NSSize size = new NSSize();
- size.width = width;
- size.height = height;
- topView.setFrameSize(size);
- }
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the argument. The <code>x</code> and
- * <code>y</code> fields of the rectangle are relative to
- * the receiver's parent (or its display if its parent is null).
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param rect the new bounds for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (Rectangle rect) {
- checkWidget ();
- if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (rect.x, rect.y, Math.max (0, rect.width), Math.max (0, rect.height), true, true);
-}
-
-/**
- * If the argument is <code>true</code>, causes the receiver to have
- * all mouse events delivered to it until the method is called with
- * <code>false</code> as the argument. Note that on some platforms,
- * a mouse button must currently be down for capture to be assigned.
- *
- * @param capture <code>true</code> to capture the mouse, and <code>false</code> to release it
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCapture (boolean capture) {
- checkWidget();
-}
-
-void setClipRegion (float /*double*/ x, float /*double*/ y) {
- if (regionPath != null) {
- NSAffineTransform transform = NSAffineTransform.transform();
- transform.translateXBy(-x, -y);
- regionPath.transformUsingAffineTransform(transform);
- regionPath.addClip();
- transform.translateXBy(2*x, 2*y);
- regionPath.transformUsingAffineTransform(transform);
- }
- NSRect frame = topView().frame();
- parent.setClipRegion(frame.x + x, frame.y + y);
-}
-
-/**
- * Sets the receiver's cursor to the cursor specified by the
- * argument, or to the default cursor for that kind of control
- * if the argument is null.
- * <p>
- * When the mouse pointer passes over a control its appearance
- * is changed to match the control's cursor.
- * </p>
- *
- * @param cursor the new cursor (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCursor (Cursor cursor) {
- checkWidget();
- if (cursor != null && cursor.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- this.cursor = cursor;
- if (!isEnabled()) return;
- if (!view.window().areCursorRectsEnabled()) return;
- display.setCursor (display.currentControl);
-}
-
-void setDefaultFont () {
- if (display.smallFonts) {
- setFont (defaultFont ().handle);
- setSmallSize ();
- }
-}
-
-/**
- * Sets the receiver's drag detect state. If the argument is
- * <code>true</code>, the receiver will detect drag gestures,
- * otherwise these gestures will be ignored.
- *
- * @param dragDetect the new drag detect state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public void setDragDetect (boolean dragDetect) {
- checkWidget ();
- if (dragDetect) {
- state |= DRAG_DETECT;
- } else {
- state &= ~DRAG_DETECT;
- }
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- if (((state & DISABLED) == 0) == enabled) return;
- Control control = null;
- boolean fixFocus = false;
- if (!enabled) {
- if (display.focusEvent != SWT.FocusOut) {
- control = display.getFocusControl ();
- fixFocus = isFocusAncestor (control);
- }
- }
- if (enabled) {
- state &= ~DISABLED;
- } else {
- state |= DISABLED;
- }
- enableWidget (enabled);
- if (fixFocus) fixFocus (control);
-}
-
-/**
- * Causes the receiver to have the <em>keyboard focus</em>,
- * such that all keyboard events will be delivered to it. Focus
- * reassignment will respect applicable platform constraints.
- *
- * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #forceFocus
- */
-public boolean setFocus () {
- checkWidget();
- if ((style & SWT.NO_FOCUS) != 0) return false;
- return forceFocus ();
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * to the font specified by the argument, or to the default font for that
- * kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkWidget();
- if (font != null) {
- if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- this.font = font;
- setFont (font != null ? font.handle : defaultFont().handle);
-}
-
-void setFont (NSFont font) {
- if (view instanceof NSControl) {
- ((NSControl)view).setFont(font);
- }
-}
-
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the control
- * if the argument is null.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * </p>
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setForeground (Color color) {
- checkWidget();
- if (color != null) {
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- float /*double*/ [] foreground = color != null ? color.handle : null;
- if (equals (foreground, this.foreground)) return;
- this.foreground = foreground;
- setForeground (foreground);
- redrawWidget (view, false);
-}
-
-void setForeground (float /*double*/ [] color) {
-}
-
-void setFrameOrigin (int /*long*/ id, int /*long*/ sel, NSPoint point) {
- NSView topView = topView ();
- if (topView.id != id) {
- super.setFrameOrigin(id, sel, point);
- return;
- }
- NSRect frame = topView.frame();
- super.setFrameOrigin(id, sel, point);
- if (frame.x != point.x || frame.y != point.y) {
- invalidateVisibleRegion();
- moved ();
- }
-}
-
-void setFrameSize (int /*long*/ id, int /*long*/ sel, NSSize size) {
- NSView topView = topView ();
- if (topView.id != id) {
- super.setFrameSize(id, sel, size);
- return;
- }
- NSRect frame = topView.frame();
- super.setFrameSize(id, sel, size);
- if (frame.width != size.width || frame.height != size.height) {
- invalidateVisibleRegion();
- resized ();
- }
-}
-
-/**
- * Sets the layout data associated with the receiver to the argument.
- *
- * @param layoutData the new layout data for the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLayoutData (Object layoutData) {
- checkWidget();
- this.layoutData = layoutData;
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget();
- setBounds (x, y, 0, 0, true, false);
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @param location the new location for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (Point location) {
- checkWidget();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (location.x, location.y, 0, 0, true, false);
-}
-
-/**
- * Sets the receiver's pop up menu to the argument.
- * All controls may optionally have a pop up
- * menu that is displayed when the user requests one for
- * the control. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pop up
- * menu is platform specific.
- * <p>
- * Note: Disposing of a control that has a pop up menu will
- * dispose of the menu. To avoid this behavior, set the
- * menu to null before the control is disposed.
- * </p>
- *
- * @param menu the new pop up menu
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenu (Menu menu) {
- checkWidget();
- if (menu != null) {
- if (menu.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.POP_UP) == 0) {
- error (SWT.ERROR_MENU_NOT_POP_UP);
- }
- if (menu.parent != menuShell ()) {
- error (SWT.ERROR_INVALID_PARENT);
- }
- }
- this.menu = menu;
-}
-
-/**
- * Changes the parent of the widget to be the one provided if
- * the underlying operating system supports this feature.
- * Returns <code>true</code> if the parent is successfully changed.
- *
- * @param parent the new parent for the control.
- * @return <code>true</code> if the parent is changed and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * <li>ERROR_NULL_ARGUMENT - if the parent is <code>null</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean setParent (Composite parent) {
- checkWidget();
- if (parent == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (parent.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.parent == parent) return true;
- if (!isReparentable ()) return false;
- releaseParent ();
- Shell newShell = parent.getShell (), oldShell = getShell ();
- Decorations newDecorations = parent.menuShell (), oldDecorations = menuShell ();
- if (oldShell != newShell || oldDecorations != newDecorations) {
- Menu [] menus = oldShell.findMenus (this);
- fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
- }
- NSView topView = topView ();
- topView.retain();
- topView.removeFromSuperview();
- parent.contentView().addSubview(topView, OS.NSWindowBelow, null);
- topView.release();
- this.parent = parent;
- return true;
-}
-
-/**
- * If the argument is <code>false</code>, causes subsequent drawing
- * operations in the receiver to be ignored. No drawing of any kind
- * can occur in the receiver until the flag is set to true.
- * Graphics operations that occurred while the flag was
- * <code>false</code> are lost. When the flag is set to <code>true</code>,
- * the entire widget is marked as needing to be redrawn. Nested calls
- * to this method are stacked.
- * <p>
- * Note: This operation is a hint and may not be supported on some
- * platforms or for some widgets.
- * </p>
- *
- * @param redraw the new redraw state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #redraw(int, int, int, int, boolean)
- * @see #update()
- */
-public void setRedraw (boolean redraw) {
- checkWidget();
- if (redraw) {
- if (--drawCount == 0) {
- invalidateVisibleRegion ();
- redrawWidget(topView (), true);
- }
- } else {
- if (drawCount == 0) {
- invalidateVisibleRegion ();
- }
- drawCount++;
- }
-}
-
-/**
- * Sets the shape of the control to the region specified
- * by the argument. When the argument is null, the
- * default shape of the control is restored.
- *
- * @param region the region that defines the shape of the control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setRegion (Region region) {
- checkWidget ();
- if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- this.region = region;
- if (regionPath != null) regionPath.release();
- regionPath = getPath(region);
- redrawWidget(view, true);
-}
-
-void setRelations () {
- if (parent == null) return;
- Control [] children = parent._getChildren ();
- int count = children.length;
- if (count > 1) {
- /*
- * the receiver is the last item in the list, so its predecessor will
- * be the second-last item in the list
- */
- Control child = children [count - 2];
- if (child != this) {
- child.addRelation (this);
- }
- }
-}
-
-boolean setRadioSelection (boolean value){
- return false;
-}
-
-/**
- * Sets the receiver's size to the point specified by the arguments.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (int width, int height) {
- checkWidget();
- setBounds (0, 0, Math.max (0, width), Math.max (0, height), false, true);
-}
-
-/**
- * Sets the receiver's size to the point specified by the argument.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause them to be
- * set to zero instead.
- * </p>
- *
- * @param size the new size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (Point size) {
- checkWidget ();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (0, 0, Math.max (0, size.x), Math.max (0, size.y), false, true);
-}
-
-void setSmallSize () {
- if (view instanceof NSControl) {
- NSCell cell = ((NSControl)view).cell();
- if (cell != null) cell.setControlSize (OS.NSSmallControlSize);
- }
-}
-
-boolean setTabItemFocus () {
- if (!isShowing ()) return false;
- return forceFocus ();
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
- checkToolTip (null);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget();
- if (visible) {
- if ((state & HIDDEN) == 0) return;
- state &= ~HIDDEN;
- } else {
- if ((state & HIDDEN) != 0) return;
- state |= HIDDEN;
- }
- if (visible) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the show
- * event. If this happens, just return.
- */
- sendEvent (SWT.Show);
- if (isDisposed ()) return;
- }
-
- /*
- * Feature in the Macintosh. If the receiver has focus, hiding
- * the receiver causes no control to have focus. Also, the focus
- * needs to be cleared from any TXNObject so that it stops blinking
- * the caret. The fix is to assign focus to the first ancestor
- * control that takes focus. If no control will take focus, clear
- * the focus control.
- */
- Control control = null;
- boolean fixFocus = false;
- if (!visible) {
- if (display.focusEvent != SWT.FocusOut) {
- control = display.getFocusControl ();
- fixFocus = isFocusAncestor (control);
- }
- }
- topView().setHidden(!visible);
- invalidateVisibleRegion();
- if (!visible) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the show
- * event. If this happens, just return.
- */
- sendEvent (SWT.Hide);
- if (isDisposed ()) return;
- }
- if (fixFocus) fixFocus (control);
-}
-
-void setZOrder () {
- NSView topView = topView ();
- parent.contentView().addSubview(topView, OS.NSWindowBelow, null);
-}
-
-boolean shouldDelayWindowOrderingForEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- Shell shell = getShell ();
- if ((shell.style & SWT.ON_TOP) != 0) return false;
- return super.shouldDelayWindowOrderingForEvent (id, sel, theEvent);
-}
-
-void setZOrder (Control sibling, boolean above) {
- int index = 0, siblingIndex = 0, oldNextIndex = -1;
- Control[] children = null;
- /* determine the receiver's and sibling's indexes in the parent */
- children = parent._getChildren ();
- while (index < children.length) {
- if (children [index] == this) break;
- index++;
- }
- if (sibling != null) {
- while (siblingIndex < children.length) {
- if (children [siblingIndex] == sibling) break;
- siblingIndex++;
- }
- }
- /* remove "Labeled by" relationships that will no longer be valid */
- removeRelation ();
- if (index + 1 < children.length) {
- oldNextIndex = index + 1;
- children [oldNextIndex].removeRelation ();
- }
- if (sibling != null) {
- if (above) {
- sibling.removeRelation ();
- } else {
- if (siblingIndex + 1 < children.length) {
- children [siblingIndex + 1].removeRelation ();
- }
- }
- }
-
- NSView otherView = sibling == null ? null : sibling.topView ();
- view.retain();
- view.removeFromSuperview();
- parent.contentView().addSubview(view, above ? OS.NSWindowAbove : OS.NSWindowBelow, otherView);
- view.release();
- invalidateVisibleRegion();
-
- /* determine the receiver's new index in the parent */
- if (sibling != null) {
- if (above) {
- index = siblingIndex - (index < siblingIndex ? 1 : 0);
- } else {
- index = siblingIndex + (siblingIndex < index ? 1 : 0);
- }
- } else {
- if (above) {
- index = 0;
- } else {
- index = children.length - 1;
- }
- }
-
- /* add new "Labeled by" relations as needed */
- children = parent._getChildren ();
- if (0 < index) {
- children [index - 1].addRelation (this);
- }
- if (index + 1 < children.length) {
- addRelation (children [index + 1]);
- }
- if (oldNextIndex != -1) {
- if (oldNextIndex <= index) oldNextIndex--;
- /* the last two conditions below ensure that duplicate relations are not hooked */
- if (0 < oldNextIndex && oldNextIndex != index && oldNextIndex != index + 1) {
- children [oldNextIndex - 1].addRelation (children [oldNextIndex]);
- }
- }
-}
-
-void sort (int [] items) {
- /* Shell Sort from K&R, pg 108 */
- int length = items.length;
- for (int gap=length/2; gap>0; gap/=2) {
- for (int i=gap; i<length; i++) {
- for (int j=i-gap; j>=0; j-=gap) {
- if (items [j] <= items [j + gap]) {
- int swap = items [j];
- items [j] = items [j + gap];
- items [j + gap] = swap;
- }
- }
- }
- }
-}
-
-NSSize textExtent (String string) {
- NSAttributedString attribStr = createString(string, null, null, 0, true, false);
- NSSize size = attribStr.size();
- attribStr.release();
- return size;
-}
-
-String tooltipText () {
- return toolTipText;
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in display relative coordinates,
- * to coordinates relative to the receiver.
- * <p>
- * @param x the x coordinate to be translated
- * @param y the y coordinate to be translated
- * @return the translated coordinates
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public Point toControl (int x, int y) {
- checkWidget();
- return display.map (null, this, x, y);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in display relative coordinates,
- * to coordinates relative to the receiver.
- * <p>
- * @param point the point to be translated (must not be null)
- * @return the translated coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point toControl (Point point) {
- checkWidget();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return toControl (point.x, point.y);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in coordinates relative to
- * the receiver, to display relative coordinates.
- * <p>
- * @param x the x coordinate to be translated
- * @param y the y coordinate to be translated
- * @return the translated coordinates
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public Point toDisplay (int x, int y) {
- checkWidget();
- return display.map (this, null, x, y);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in coordinates relative to
- * the receiver, to display relative coordinates.
- * <p>
- * @param point the point to be translated (must not be null)
- * @return the translated coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point toDisplay (Point point) {
- checkWidget();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return toDisplay (point.x, point.y);
-}
-
-NSView topView () {
- return view;
-}
-
-boolean translateTraversal (int key, NSEvent theEvent, boolean [] consume) {
- int detail = SWT.TRAVERSE_NONE;
- int code = traversalCode (key, theEvent);
- boolean all = false;
- switch (key) {
- case 53: /* Esc */ {
- all = true;
- detail = SWT.TRAVERSE_ESCAPE;
- break;
- }
- case 76: /* KP Enter */
- case 36: /* Return */ {
- all = true;
- detail = SWT.TRAVERSE_RETURN;
- break;
- }
- case 48: /* Tab */ {
- int /*long*/ modifiers = theEvent.modifierFlags ();
- boolean next = (modifiers & OS.NSShiftKeyMask) == 0;
- detail = next ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS;
- break;
- }
- case 126: /* Up arrow */
- case 123: /* Left arrow */
- case 125: /* Down arrow */
- case 124: /* Right arrow */ {
- boolean next = key == 125 /* Down arrow */ || key == 124 /* Right arrow */;
- detail = next ? SWT.TRAVERSE_ARROW_NEXT : SWT.TRAVERSE_ARROW_PREVIOUS;
- break;
- }
- case 116: /* Page up */
- case 121: /* Page down */ {
- all = true;
- int /*long*/ modifiers = theEvent.modifierFlags ();
- if ((modifiers & OS.NSControlKeyMask) == 0) return false;
- detail = key == 121 /* Page down */ ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS;
- break;
- }
- default:
- return false;
- }
- Event event = new Event ();
- event.doit = consume [0] = (code & detail) != 0;
- event.detail = detail;
- if (!setKeyState (event, SWT.Traverse, theEvent)) return false;
- Shell shell = getShell ();
- Control control = this;
- do {
- if (control.traverse (event)) return true;
- if (!event.doit && control.hooks (SWT.Traverse)) {
- return false;
- }
- if (control == shell) return false;
- control = control.parent;
- } while (all && control != null);
- return false;
-}
-
-int traversalCode (int key, NSEvent theEvent) {
- int code = SWT.TRAVERSE_RETURN | SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_PAGE_NEXT | SWT.TRAVERSE_PAGE_PREVIOUS;
- Shell shell = getShell ();
- if (shell.parent != null) code |= SWT.TRAVERSE_ESCAPE;
- return code;
-}
-
-boolean traverseMnemonic (char key) {
- return false;
-}
-
-/**
- * Based on the argument, perform one of the expected platform
- * traversal action. The argument should be one of the constants:
- * <code>SWT.TRAVERSE_ESCAPE</code>, <code>SWT.TRAVERSE_RETURN</code>,
- * <code>SWT.TRAVERSE_TAB_NEXT</code>, <code>SWT.TRAVERSE_TAB_PREVIOUS</code>,
- * <code>SWT.TRAVERSE_ARROW_NEXT</code> and <code>SWT.TRAVERSE_ARROW_PREVIOUS</code>.
- *
- * @param traversal the type of traversal
- * @return true if the traversal succeeded
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean traverse (int traversal) {
- checkWidget();
- Event event = new Event ();
- event.doit = true;
- event.detail = traversal;
- return traverse (event);
-}
-
-boolean traverse (Event event) {
- sendEvent (SWT.Traverse, event);
- if (isDisposed ()) return true;
- if (!event.doit) return false;
- switch (event.detail) {
- case SWT.TRAVERSE_NONE: return true;
- case SWT.TRAVERSE_ESCAPE: return traverseEscape ();
- case SWT.TRAVERSE_RETURN: return traverseReturn ();
- case SWT.TRAVERSE_TAB_NEXT: return traverseGroup (true);
- case SWT.TRAVERSE_TAB_PREVIOUS: return traverseGroup (false);
- case SWT.TRAVERSE_ARROW_NEXT: return traverseItem (true);
- case SWT.TRAVERSE_ARROW_PREVIOUS: return traverseItem (false);
- case SWT.TRAVERSE_MNEMONIC: return traverseMnemonic (event);
- case SWT.TRAVERSE_PAGE_NEXT: return traversePage (true);
- case SWT.TRAVERSE_PAGE_PREVIOUS: return traversePage (false);
- }
- return false;
-}
-
-boolean traverseEscape () {
- return false;
-}
-
-boolean traverseGroup (boolean next) {
- Control root = computeTabRoot ();
- Widget group = computeTabGroup ();
- Widget [] list = root.computeTabList ();
- int length = list.length;
- int index = 0;
- while (index < length) {
- if (list [index] == group) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- if (index == length) return false;
- int start = index, offset = (next) ? 1 : -1;
- while ((index = ((index + offset + length) % length)) != start) {
- Widget widget = list [index];
- if (!widget.isDisposed () && widget.setTabGroupFocus ()) {
- return true;
- }
- }
- if (group.isDisposed ()) return false;
- return group.setTabGroupFocus ();
-}
-
-boolean traverseItem (boolean next) {
- Control [] children = parent._getChildren ();
- int length = children.length;
- int index = 0;
- while (index < length) {
- if (children [index] == this) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- if (index == length) return false;
- int start = index, offset = (next) ? 1 : -1;
- while ((index = (index + offset + length) % length) != start) {
- Control child = children [index];
- if (!child.isDisposed () && child.isTabItem ()) {
- if (child.setTabItemFocus ()) return true;
- }
- }
- return false;
-}
-
-boolean traverseReturn () {
- return false;
-}
-
-boolean traversePage (boolean next) {
- return false;
-}
-
-boolean traverseMnemonic (Event event) {
- return false;
-}
-
-/**
- * Forces all outstanding paint requests for the widget
- * to be processed before this method returns. If there
- * are no outstanding paint request, this method does
- * nothing.
- * <p>
- * Note: This method does not cause a redraw.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #redraw()
- * @see #redraw(int, int, int, int, boolean)
- * @see PaintListener
- * @see SWT#Paint
- */
-public void update () {
- checkWidget();
- update (false);
-}
-
-void update (boolean all) {
-// checkWidget();
- if (display.isPainting.containsObject(view)) return;
- //TODO - not all
- view.displayIfNeeded ();
-}
-
-void updateBackgroundMode () {
- int oldState = state & PARENT_BACKGROUND;
- checkBackground ();
- if (oldState != (state & PARENT_BACKGROUND)) {
- setBackground ();
- }
-}
-
-void resetCursorRects (int /*long*/ id, int /*long*/ sel) {
- if (isEnabled ()) callSuper (id, sel);
-}
-
-void updateTrackingAreas (int /*long*/ id, int /*long*/ sel) {
- if (isEnabled ()) callSuper (id, sel);
-}
-
-void updateCursorRects (boolean enabled) {
- updateCursorRects (enabled, view);
-}
-
-void updateCursorRects (boolean enabled, NSView widget) {
- if (enabled) {
- widget.resetCursorRects ();
- widget.updateTrackingAreas ();
- } else {
- widget.discardCursorRects ();
- NSArray areas = widget.trackingAreas ();
- for (int i = 0; i < areas.count(); i++) {
- widget.removeTrackingArea (new NSTrackingArea (areas.objectAtIndex (i)));
- }
- }
-}
-
-void updateLayout (boolean all) {
- /* Do nothing */
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/DateTime.java
deleted file mode 100755
index 5604b200af..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/DateTime.java
+++ /dev/null
@@ -1,591 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify date
- * or time values.
- * <p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>DATE, TIME, CALENDAR, SHORT, MEDIUM, LONG, DROP_DOWN</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles DATE, TIME, or CALENDAR may be specified,
- * and only one of the styles SHORT, MEDIUM, or LONG may be specified.
- * The DROP_DOWN style is a <em>HINT</em>, and it is only valid with the DATE style.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#datetime">DateTime snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.3
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class DateTime extends Composite {
- static final int MIN_YEAR = 1752; // Gregorian switchover in North America: September 19, 1752
- static final int MAX_YEAR = 9999;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DATE
- * @see SWT#TIME
- * @see SWT#CALENDAR
- * @see SWT#SHORT
- * @see SWT#MEDIUM
- * @see SWT#LONG
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public DateTime (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- style &= ~(SWT.H_SCROLL | SWT.V_SCROLL);
- style = checkBits (style, SWT.MEDIUM, SWT.SHORT, SWT.LONG, 0, 0, 0);
- return checkBits (style, SWT.DATE, SWT.TIME, SWT.CALENDAR, 0, 0, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the control's value.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0;
- NSControl widget = (NSControl)view;
- NSSize size = widget.cell ().cellSize ();
- width = (int)Math.ceil (size.width);
- height = (int)Math.ceil (size.height);
- if (width == 0) width = DEFAULT_WIDTH;
- if (height == 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2; height += border * 2;
- return new Point (width, height);
-}
-
-void createHandle () {
- NSDatePicker widget = (NSDatePicker)new SWTDatePicker().alloc();
- widget.init();
- int pickerStyle = OS.NSTextFieldAndStepperDatePickerStyle;
- int elementFlags = 0;
- if ((style & SWT.CALENDAR) != 0) {
- pickerStyle = OS.NSClockAndCalendarDatePickerStyle;
- elementFlags = OS.NSYearMonthDayDatePickerElementFlag;
- } else {
- if ((style & SWT.TIME) != 0) {
- elementFlags = (style & SWT.SHORT) != 0 ? OS.NSHourMinuteDatePickerElementFlag : OS.NSHourMinuteSecondDatePickerElementFlag;
- }
- if ((style & SWT.DATE) != 0) {
- elementFlags = (style & SWT.SHORT) != 0 ? OS.NSYearMonthDatePickerElementFlag : OS.NSYearMonthDayDatePickerElementFlag;
- }
- }
- widget.setDrawsBackground(true);
- widget.setDatePickerStyle(pickerStyle);
- widget.setDatePickerElements(elementFlags);
- NSDate date = NSCalendarDate.calendarDate();
- widget.setDateValue(date);
- widget.setTarget(widget);
- widget.setAction(OS.sel_sendSelection);
- view = widget;
-}
-
-NSFont defaultNSFont() {
- return display.datePickerFont;
-}
-
-NSCalendarDate getCalendarDate () {
- NSDate date = ((NSDatePicker)view).dateValue();
- return date.dateWithCalendarFormat(null, null);
-}
-
-/**
- * Returns the receiver's date, or day of the month.
- * <p>
- * The first day of the month is 1, and the last day depends on the month and year.
- * </p>
- *
- * @return a positive integer beginning with 1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getDay () {
- checkWidget ();
- return (int)/*64*/getCalendarDate().dayOfMonth();
-}
-
-/**
- * Returns the receiver's hours.
- * <p>
- * Hours is an integer between 0 and 23.
- * </p>
- *
- * @return an integer between 0 and 23
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getHours () {
- checkWidget ();
- return (int)/*64*/getCalendarDate().hourOfDay();
-}
-
-/**
- * Returns the receiver's minutes.
- * <p>
- * Minutes is an integer between 0 and 59.
- * </p>
- *
- * @return an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinutes () {
- checkWidget ();
- return (int)/*64*/getCalendarDate().minuteOfHour();
-}
-
-/**
- * Returns the receiver's month.
- * <p>
- * The first month of the year is 0, and the last month is 11.
- * </p>
- *
- * @return an integer between 0 and 11
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMonth () {
- checkWidget ();
- return (int)/*64*/getCalendarDate().monthOfYear() - 1;
-}
-
-String getNameText() {
- return (style & SWT.TIME) != 0 ? getHours() + ":" + getMinutes() + ":" + getSeconds()
- : (getMonth() + 1) + "/" + getDay() + "/" + getYear();
-}
-
-/**
- * Returns the receiver's seconds.
- * <p>
- * Seconds is an integer between 0 and 59.
- * </p>
- *
- * @return an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSeconds () {
- checkWidget ();
- return (int)/*64*/getCalendarDate().secondOfMinute();
-}
-
-/**
- * Returns the receiver's year.
- * <p>
- * The first year is 1752 and the last year is 9999.
- * </p>
- *
- * @return an integer between 1752 and 9999
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getYear () {
- checkWidget ();
- return (int)/*64*/getCalendarDate().yearOfCommonEra();
-}
-
-boolean isEventView (int /*long*/ id) {
- return true;
-}
-
-boolean isFlipped (int /*long*/ id, int /*long*/ sel) {
- if ((style & SWT.CALENDAR) != 0) return super.isFlipped (id, sel);
- return true;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection, listener);
-}
-
-boolean sendKeyEvent (NSEvent nsEvent, int type) {
- boolean result = super.sendKeyEvent (nsEvent, type);
- if (!result) return result;
- if (type != SWT.KeyDown) return result;
- if ((style & SWT.CALENDAR) == 0) {
- short keyCode = nsEvent.keyCode ();
- switch (keyCode) {
- case 76: /* KP Enter */
- case 36: /* Return */
- postEvent (SWT.DefaultSelection);
- }
- }
- return result;
-}
-
-void sendSelection () {
- NSEvent event = NSApplication.sharedApplication().currentEvent();
- if (event != null && (style & SWT.CALENDAR) != 0) {
- if (event.clickCount() == 2) {
- postEvent (SWT.DefaultSelection);
- } else if (event.type() == OS.NSLeftMouseUp) {
- postEvent (SWT.Selection);
- }
- } else { // SWT.DATE or SWT.TIME
- postEvent (SWT.Selection);
- }
-}
-
-void updateBackground () {
- NSColor nsColor = null;
- if (backgroundImage != null) {
- nsColor = NSColor.colorWithPatternImage(backgroundImage.handle);
- } else if (background != null) {
- nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]);
- } else {
- if ((style & SWT.CALENDAR) != 0) {
- nsColor = NSColor.controlBackgroundColor ();
- } else {
- nsColor = NSColor.textBackgroundColor ();
- }
-
- }
- ((NSDatePicker)view).setBackgroundColor(nsColor);
-}
-
-/**
- * Sets the receiver's year, month, and day in a single operation.
- * <p>
- * This is the recommended way to set the date, because setting the year,
- * month, and day separately may result in invalid intermediate dates.
- * </p>
- *
- * @param year an integer between 1752 and 9999
- * @param month an integer between 0 and 11
- * @param day a positive integer beginning with 1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setDate (int year, int month, int day) {
- checkWidget ();
- if (year < MIN_YEAR || year > MAX_YEAR) return;
- NSCalendarDate date = getCalendarDate();
- NSCalendarDate newDate = NSCalendarDate.dateWithYear(year, month + 1, day,
- date.hourOfDay(), date.minuteOfHour(), date.secondOfMinute(), date.timeZone());
- if (newDate.yearOfCommonEra() == year && newDate.monthOfYear() == month + 1 && newDate.dayOfMonth() == day) {
- ((NSDatePicker)view).setDateValue(newDate);
- }
-}
-
-/**
- * Sets the receiver's date, or day of the month, to the specified day.
- * <p>
- * The first day of the month is 1, and the last day depends on the month and year.
- * If the specified day is not valid for the receiver's month and year, then it is ignored.
- * </p>
- *
- * @param day a positive integer beginning with 1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDate
- */
-public void setDay (int day) {
- checkWidget ();
- NSCalendarDate date = getCalendarDate();
- NSCalendarDate newDate = NSCalendarDate.dateWithYear(date.yearOfCommonEra(), date.monthOfYear(), day,
- date.hourOfDay(), date.minuteOfHour(), date.secondOfMinute(), date.timeZone());
- if (newDate.yearOfCommonEra() == date.yearOfCommonEra() && newDate.monthOfYear() == date.monthOfYear() && newDate.dayOfMonth() == day) {
- ((NSDatePicker)view).setDateValue(newDate);
- }
-}
-
-void setForeground (float /*double*/ [] color) {
- NSColor nsColor;
- if (color == null) {
- if ((style & SWT.CALENDAR) != 0) {
- nsColor = NSColor.controlTextColor ();
- } else {
- nsColor = NSColor.textColor ();
- }
- } else {
- nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1);
- }
- ((NSDatePicker)view).setTextColor(nsColor);
-}
-
-/**
- * Sets the receiver's hours.
- * <p>
- * Hours is an integer between 0 and 23.
- * </p>
- *
- * @param hours an integer between 0 and 23
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHours (int hours) {
- checkWidget ();
- if (hours < 0 || hours > 23) return;
- NSCalendarDate date = getCalendarDate();
- NSCalendarDate newDate = NSCalendarDate.dateWithYear(date.yearOfCommonEra(), date.monthOfYear(), date.dayOfMonth(),
- hours, date.minuteOfHour(), date.secondOfMinute(), date.timeZone());
- ((NSDatePicker)view).setDateValue(newDate);
-}
-
-/**
- * Sets the receiver's minutes.
- * <p>
- * Minutes is an integer between 0 and 59.
- * </p>
- *
- * @param minutes an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinutes (int minutes) {
- checkWidget ();
- if (minutes < 0 || minutes > 59) return;
- NSCalendarDate date = getCalendarDate();
- NSCalendarDate newDate = NSCalendarDate.dateWithYear(date.yearOfCommonEra(), date.monthOfYear(), date.dayOfMonth(),
- date.hourOfDay(), minutes, date.secondOfMinute(), date.timeZone());
- ((NSDatePicker)view).setDateValue(newDate);
-}
-
-/**
- * Sets the receiver's month.
- * <p>
- * The first month of the year is 0, and the last month is 11.
- * If the specified month is not valid for the receiver's day and year, then it is ignored.
- * </p>
- *
- * @param month an integer between 0 and 11
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDate
- */
-public void setMonth (int month) {
- checkWidget ();
- NSCalendarDate date = getCalendarDate();
- NSCalendarDate newDate = NSCalendarDate.dateWithYear(date.yearOfCommonEra(), month + 1, date.dayOfMonth(),
- date.hourOfDay(), date.minuteOfHour(), date.secondOfMinute(), date.timeZone());
- if (newDate.yearOfCommonEra() == date.yearOfCommonEra() && newDate.monthOfYear() == month + 1 && newDate.dayOfMonth() == date.dayOfMonth()) {
- ((NSDatePicker)view).setDateValue(newDate);
- }
-}
-
-/**
- * Sets the receiver's seconds.
- * <p>
- * Seconds is an integer between 0 and 59.
- * </p>
- *
- * @param seconds an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSeconds (int seconds) {
- checkWidget ();
- if (seconds < 0 || seconds > 59) return;
- NSCalendarDate date = getCalendarDate();
- NSCalendarDate newDate = NSCalendarDate.dateWithYear(date.yearOfCommonEra(), date.monthOfYear(), date.dayOfMonth(),
- date.hourOfDay(), date.minuteOfHour(), seconds, date.timeZone());
- ((NSDatePicker)view).setDateValue(newDate);
-}
-
-/**
- * Sets the receiver's hours, minutes, and seconds in a single operation.
- *
- * @param hours an integer between 0 and 23
- * @param minutes an integer between 0 and 59
- * @param seconds an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setTime (int hours, int minutes, int seconds) {
- checkWidget ();
- if (hours < 0 || hours > 23 || minutes < 0 || minutes > 59 || seconds < 0 || seconds > 59) return;
- NSCalendarDate date = getCalendarDate();
- NSCalendarDate newDate = NSCalendarDate.dateWithYear(date.yearOfCommonEra(), date.monthOfYear(), date.dayOfMonth(),
- hours, minutes, seconds, date.timeZone());
- ((NSDatePicker)view).setDateValue(newDate);
-}
-
-/**
- * Sets the receiver's year.
- * <p>
- * The first year is 1752 and the last year is 9999.
- * If the specified year is not valid for the receiver's day and month, then it is ignored.
- * </p>
- *
- * @param year an integer between 1752 and 9999
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDate
- */
-public void setYear (int year) {
- checkWidget ();
- if (year < MIN_YEAR || year > MAX_YEAR) return;
- NSCalendarDate date = getCalendarDate();
- NSCalendarDate newDate = NSCalendarDate.dateWithYear(year, date.monthOfYear(), date.dayOfMonth(),
- date.hourOfDay(), date.minuteOfHour(), date.secondOfMinute(), date.timeZone());
- if (newDate.yearOfCommonEra() == year && newDate.monthOfYear() == date.monthOfYear() && newDate.dayOfMonth() == date.dayOfMonth()) {
- ((NSDatePicker)view).setDateValue(newDate);
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Decorations.java
deleted file mode 100755
index e0c6c74c29..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Decorations.java
+++ /dev/null
@@ -1,682 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class provide the appearance and
- * behavior of <code>Shells</code>, but are not top
- * level shells or dialogs. Class <code>Shell</code>
- * shares a significant amount of code with this class,
- * and is a subclass.
- * <p>
- * IMPORTANT: This class was intended to be abstract and
- * should <em>never</em> be referenced or instantiated.
- * Instead, the class <code>Shell</code> should be used.
- * </p>
- * <p>
- * Instances are always displayed in one of the maximized,
- * minimized or normal states:
- * <ul>
- * <li>
- * When an instance is marked as <em>maximized</em>, the
- * window manager will typically resize it to fill the
- * entire visible area of the display, and the instance
- * is usually put in a state where it can not be resized
- * (even if it has style <code>RESIZE</code>) until it is
- * no longer maximized.
- * </li><li>
- * When an instance is in the <em>normal</em> state (neither
- * maximized or minimized), its appearance is controlled by
- * the style constants which were specified when it was created
- * and the restrictions of the window manager (see below).
- * </li><li>
- * When an instance has been marked as <em>minimized</em>,
- * its contents (client area) will usually not be visible,
- * and depending on the window manager, it may be
- * "iconified" (that is, replaced on the desktop by a small
- * simplified representation of itself), relocated to a
- * distinguished area of the screen, or hidden. Combinations
- * of these changes are also possible.
- * </li>
- * </ul>
- * </p>
- * Note: The styles supported by this class must be treated
- * as <em>HINT</em>s, since the window manager for the
- * desktop on which the instance is visible has ultimate
- * control over the appearance and behavior of decorations.
- * For example, some window managers only support resizable
- * windows and will always assume the RESIZE style, even if
- * it is not set.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * Class <code>SWT</code> provides two "convenience constants"
- * for the most commonly required style combinations:
- * <dl>
- * <dt><code>SHELL_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application top level shell: (that
- * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>)
- * </dd>
- * <dt><code>DIALOG_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application dialog shell: (that
- * is, <code>TITLE | CLOSE | BORDER</code>)
- * </dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see #getMinimized
- * @see #getMaximized
- * @see Shell
- * @see SWT
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Decorations extends Canvas {
- Image image;
- Image [] images = new Image [0];
- Menu menuBar;
- String text = "";
- boolean minimized, maximized;
- Control savedFocus;
- Button defaultButton;
-
-Decorations () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#TOOL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Decorations (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- if ((style & SWT.NO_TRIM) != 0) {
- style &= ~(SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX | SWT.RESIZE | SWT.BORDER);
- }
- if ((style & (SWT.MENU | SWT.MIN | SWT.MAX | SWT.CLOSE)) != 0) {
- style |= SWT.TITLE;
- }
- return style;
-}
-
-void bringToTop (boolean force) {
- moveAbove (null);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-int compare (ImageData data1, ImageData data2) {
- if (data1.width == data2.width && data1.height == data2.height) {
- int transparent1 = data1.getTransparencyType ();
- int transparent2 = data2.getTransparencyType ();
- if (transparent1 == SWT.TRANSPARENCY_ALPHA) return -1;
- if (transparent2 == SWT.TRANSPARENCY_ALPHA) return 1;
- if (transparent1 == SWT.TRANSPARENCY_MASK) return -1;
- if (transparent2 == SWT.TRANSPARENCY_MASK) return 1;
- if (transparent1 == SWT.TRANSPARENCY_PIXEL) return -1;
- if (transparent2 == SWT.TRANSPARENCY_PIXEL) return 1;
- return 0;
- }
- return data1.width > data2.width || data1.height > data2.height ? -1 : 1;
-}
-
-Widget computeTabGroup () {
- return this;
-}
-
-Control computeTabRoot () {
- return this;
-}
-
-void fixDecorations (Decorations newDecorations, Control control, Menu [] menus) {
- if (this == newDecorations) return;
- if (control == savedFocus) savedFocus = null;
- if (control == defaultButton) defaultButton = null;
- if (menus == null) return;
- Menu menu = control.menu;
- if (menu != null) {
- int index = 0;
- while (index < menus.length) {
- if (menus [index] == menu) {
- control.setMenu (null);
- return;
- }
- index++;
- }
- menu.fixMenus (newDecorations);
- }
-}
-
-/**
- * Returns the receiver's default button if one had
- * previously been set, otherwise returns null.
- *
- * @return the default button or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDefaultButton(Button)
- */
-public Button getDefaultButton () {
- checkWidget();
- return defaultButton;
-}
-
-/**
- * Returns the receiver's image if it had previously been
- * set using <code>setImage()</code>. The image is typically
- * displayed by the window manager when the instance is
- * marked as iconified, and may also be displayed somewhere
- * in the trim when the instance is in normal or maximized
- * states.
- * <p>
- * Note: This method will return null if called before
- * <code>setImage()</code> is called. It does not provide
- * access to a window manager provided, "default" image
- * even if one exists.
- * </p>
- *
- * @return the image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-
-/**
- * Returns the receiver's images if they had previously been
- * set using <code>setImages()</code>. Images are typically
- * displayed by the window manager when the instance is
- * marked as iconified, and may also be displayed somewhere
- * in the trim when the instance is in normal or maximized
- * states. Depending where the icon is displayed, the platform
- * chooses the icon with the "best" attributes. It is expected
- * that the array will contain the same icon rendered at different
- * sizes, with different depth and transparency attributes.
- *
- * <p>
- * Note: This method will return an empty array if called before
- * <code>setImages()</code> is called. It does not provide
- * access to a window manager provided, "default" image
- * even if one exists.
- * </p>
- *
- * @return the images
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Image [] getImages () {
- checkWidget ();
- if (images == null) return new Image [0];
- Image [] result = new Image [images.length];
- System.arraycopy (images, 0, result, 0, images.length);
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver is currently
- * maximized, and false otherwise.
- * <p>
- *
- * @return the maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMaximized
- */
-public boolean getMaximized () {
- checkWidget();
- return maximized;
-}
-
-/**
- * Returns the receiver's menu bar if one had previously
- * been set, otherwise returns null.
- *
- * @return the menu bar or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenuBar () {
- checkWidget();
- return menuBar;
-}
-
-/**
- * Returns <code>true</code> if the receiver is currently
- * minimized, and false otherwise.
- * <p>
- *
- * @return the minimized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMinimized
- */
-public boolean getMinimized () {
- checkWidget();
- return minimized;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which is the string that the
- * window manager will typically display as the receiver's
- * <em>title</em>. If the text has not previously been set,
- * returns an empty string.
- *
- * @return the text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- return text;
-}
-
-public boolean isReparentable () {
- checkWidget();
- return false;
-}
-
-boolean isTabGroup () {
- return true;
-}
-
-boolean isTabItem () {
- return false;
-}
-
-Decorations menuShell () {
- return this;
-}
-
-void releaseChildren (boolean destroy) {
- if (menuBar != null) {
- menuBar.dispose ();
- menuBar = null;
- }
- Display display = this.display;
- super.releaseChildren (destroy);
- Menu [] menus = display.getMenus (this);
- if (menus != null) {
- for (int i=0; i<menus.length; i++) {
- Menu menu = menus [i];
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- }
- menus = null;
- }
-}
-void releaseWidget () {
- super.releaseWidget ();
- image = null;
- images = null;
- savedFocus = null;
- defaultButton = null;
-}
-
-boolean restoreFocus () {
- if (savedFocus != null && savedFocus.isDisposed ()) savedFocus = null;
- if (savedFocus == null) return false;
- return savedFocus.forceFocus ();
-}
-
-void saveFocus () {
-// int window = OS.GetControlOwner (handle);
-// Control control = display.getFocusControl (window, false);
-// if (control != null && control != this && this == control.menuShell ()) {
-// setSavedFocus (control);
-// }
-}
-
-/**
- * If the argument is not null, sets the receiver's default
- * button to the argument, and if the argument is null, sets
- * the receiver's default button to the first button which
- * was set as the receiver's default button (called the
- * <em>saved default button</em>). If no default button had
- * previously been set, or the saved default button was
- * disposed, the receiver's default button will be set to
- * null.
- * <p>
- * The default button is the button that is selected when
- * the receiver is active and the user presses ENTER.
- * </p>
- *
- * @param button the new default button
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the button has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDefaultButton (Button button) {
- checkWidget();
- if (button != null) {
- if (button.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (button.menuShell () != this) error (SWT.ERROR_INVALID_PARENT);
- if ((button.style & SWT.PUSH) == 0) return;
- }
- if (button == defaultButton) return;
- defaultButton = button;
- NSButtonCell cell = null;
- if (defaultButton != null && (defaultButton.style & SWT.PUSH) != 0) {
- cell = new NSButtonCell (((NSButton)defaultButton.view).cell ());
- }
- view.window().setDefaultButtonCell (cell);
- display.updateDefaultButton();
-}
-
-/**
- * Sets the receiver's image to the argument, which may
- * be null. The image is typically displayed by the window
- * manager when the instance is marked as iconified, and
- * may also be displayed somewhere in the trim when the
- * instance is in normal or maximized states.
- *
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- this.image = image;
- if (parent != null) return;
- if (display.dockImage == null) {
- display.application.setApplicationIconImage (image != null ? image.handle : null);
- }
-}
-
-/**
- * Sets the receiver's images to the argument, which may
- * be an empty array. Images are typically displayed by the
- * window manager when the instance is marked as iconified,
- * and may also be displayed somewhere in the trim when the
- * instance is in normal or maximized states. Depending where
- * the icon is displayed, the platform chooses the icon with
- * the "best" attributes. It is expected that the array will
- * contain the same icon rendered at different sizes, with
- * different depth and transparency attributes.
- *
- * @param images the new image array
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images is null or has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setImages (Image [] images) {
- checkWidget();
- if (images == null) error(SWT.ERROR_INVALID_ARGUMENT);
- for (int i = 0; i < images.length; i++) {
- if (images [i] == null || images [i].isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.images = images;
- if (parent != null) return;
- if (display.dockImage == null) {
- if (images != null && images.length > 1) {
- Image [] bestImages = new Image [images.length];
- System.arraycopy (images, 0, bestImages, 0, images.length);
- sort (bestImages);
- images = bestImages;
- }
- if (images != null && images.length > 0) {
- display.application.setApplicationIconImage (images [0].handle);
- } else {
- display.application.setApplicationIconImage (null);
- }
- }
-}
-
-/**
- * Sets the maximized state of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the maximized state, and if the argument is
- * <code>false</code> and the receiver was previously maximized,
- * causes the receiver to switch back to either the minimized
- * or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setMaximized(true)</code>
- * and <code>setMinimized(true)</code> will vary by platform. Typically,
- * the behavior will match the platform user's expectations, but not
- * always. This should be avoided if possible.
- * </p>
- *
- * @param maximized the new maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMinimized
- */
-public void setMaximized (boolean maximized) {
- checkWidget();
- this.maximized = maximized;
-}
-
-/**
- * Sets the receiver's menu bar to the argument, which
- * may be null.
- *
- * @param menu the new menu bar
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenuBar (Menu menu) {
- checkWidget();
- if (menuBar == menu) return;
- if (menu != null) {
- if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR);
- if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
- menuBar = menu;
-}
-
-/**
- * Sets the minimized stated of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the minimized state, and if the argument is
- * <code>false</code> and the receiver was previously minimized,
- * causes the receiver to switch back to either the maximized
- * or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setMaximized(true)</code>
- * and <code>setMinimized(true)</code> will vary by platform. Typically,
- * the behavior will match the platform user's expectations, but not
- * always. This should be avoided if possible.
- * </p>
- *
- * @param minimized the new maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMaximized
- */
-public void setMinimized (boolean minimized) {
- checkWidget();
- this.minimized = minimized;
-}
-
-void setSavedFocus (Control control) {
- savedFocus = control;
-}
-
-/**
- * Sets the receiver's text, which is the string that the
- * window manager will typically display as the receiver's
- * <em>title</em>, to the argument, which must not be null.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- text = string;
-}
-
-void sort (Image [] images) {
- /* Shell Sort from K&R, pg 108 */
- int length = images.length;
- if (length <= 1) return;
- ImageData [] datas = new ImageData [length];
- for (int i = 0; i < length; i++) {
- datas [i] = images [i].getImageData ();
- }
- for (int gap=length/2; gap>0; gap/=2) {
- for (int i=gap; i<length; i++) {
- for (int j=i-gap; j>=0; j-=gap) {
- if (compare (datas [j], datas [j + gap]) >= 0) {
- Image swap = images [j];
- images [j] = images [j + gap];
- images [j + gap] = swap;
- ImageData swapData = datas [j];
- datas [j] = datas [j + gap];
- datas [j + gap] = swapData;
- }
- }
- }
- }
-}
-
-boolean traverseItem (boolean next) {
- return false;
-}
-
-boolean traverseReturn () {
- if (defaultButton == null || defaultButton.isDisposed ()) return false;
- if (!defaultButton.isVisible () || !defaultButton.isEnabled ()) return false;
- defaultButton.click ();
- return true;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/DirectoryDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/DirectoryDialog.java
deleted file mode 100755
index e12f40c639..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/DirectoryDialog.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.cocoa.*;
-import org.eclipse.swt.*;
-
-
-/**
- * Instances of this class allow the user to navigate
- * the file system and select a directory.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#directorydialog">DirectoryDialog snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class DirectoryDialog extends Dialog {
- String message = "", filterPath = "";
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public DirectoryDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public DirectoryDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- if (Display.getSheetEnabled ()) {
- if (parent != null && (style & SWT.SHEET) != 0) this.style |= SWT.SHEET;
- }
- checkSubclass ();
-}
-
-/**
- * Returns the path which the dialog will use to filter
- * the directories it shows.
- *
- * @return the filter path
- *
- * @see #setFilterPath
- */
-public String getFilterPath () {
- return filterPath;
-}
-
-/**
- * Returns the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @return the message
- */
-public String getMessage () {
- return message;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a string describing the absolute path of the selected directory,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public String open () {
- String directoryPath = null;
- NSOpenPanel panel = NSOpenPanel.openPanel();
- panel.setCanCreateDirectories(true);
- panel.setAllowsMultipleSelection((style & SWT.MULTI) != 0);
- panel.setTitle(NSString.stringWith(title != null ? title : ""));
- panel.setMessage(NSString.stringWith(message != null ? message : ""));
- panel.setCanChooseFiles(false);
- panel.setCanChooseDirectories(true);
- NSApplication application = NSApplication.sharedApplication();
- if (parent != null && (style & SWT.SHEET) != 0) {
- application.beginSheet(panel, parent.window, null, 0, 0);
- }
- NSString dir = filterPath != null ? NSString.stringWith(filterPath) : null;
- int /*long*/ response = panel.runModalForDirectory(dir, null);
- if (parent != null && (style & SWT.SHEET) != 0) {
- application.endSheet(panel, 0);
- }
- if (response == OS.NSFileHandlingPanelOKButton) {
- NSString filename = panel.filename();
- directoryPath = filterPath = filename.getString();
- }
-// options.optionFlags = OS.kNavSupportPackages | OS.kNavAllowOpenPackages | OS.kNavAllowInvisibleFiles;
- return directoryPath;
-}
-
-/**
- * Sets the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @param string the message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- */
-public void setMessage (String string) {
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- message = string;
-}
-
-/**
- * Sets the path that the dialog will use to filter
- * the directories it shows to the argument, which may
- * be null. If the string is null, then the operating
- * system's default filter path will be used.
- * <p>
- * Note that the path string is platform dependent.
- * For convenience, either '/' or '\' can be used
- * as a path separator.
- * </p>
- *
- * @param string the filter path
- */
-public void setFilterPath (String string) {
- filterPath = string;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java
deleted file mode 100755
index 5c82734c1c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java
+++ /dev/null
@@ -1,4900 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class are responsible for managing the
- * connection between SWT and the underlying operating
- * system. Their most important function is to implement
- * the SWT event loop in terms of the platform event model.
- * They also provide various methods for accessing information
- * about the operating system, and have overall control over
- * the operating system resources which SWT allocates.
- * <p>
- * Applications which are built with SWT will <em>almost always</em>
- * require only a single display. In particular, some platforms
- * which SWT supports will not allow more than one <em>active</em>
- * display. In other words, some platforms do not support
- * creating a new display if one already exists that has not been
- * sent the <code>dispose()</code> message.
- * <p>
- * In SWT, the thread which creates a <code>Display</code>
- * instance is distinguished as the <em>user-interface thread</em>
- * for that display.
- * </p>
- * The user-interface thread for a particular display has the
- * following special attributes:
- * <ul>
- * <li>
- * The event loop for that display must be run from the thread.
- * </li>
- * <li>
- * Some SWT API methods (notably, most of the public methods in
- * <code>Widget</code> and its subclasses), may only be called
- * from the thread. (To support multi-threaded user-interface
- * applications, class <code>Display</code> provides inter-thread
- * communication methods which allow threads other than the
- * user-interface thread to request that it perform operations
- * on their behalf.)
- * </li>
- * <li>
- * The thread is not allowed to construct other
- * <code>Display</code>s until that display has been disposed.
- * (Note that, this is in addition to the restriction mentioned
- * above concerning platform support for multiple displays. Thus,
- * the only way to have multiple simultaneously active displays,
- * even on platforms which support it, is to have multiple threads.)
- * </li>
- * </ul>
- * Enforcing these attributes allows SWT to be implemented directly
- * on the underlying operating system's event model. This has
- * numerous benefits including smaller footprint, better use of
- * resources, safer memory management, clearer program logic,
- * better performance, and fewer overall operating system threads
- * required. The down side however, is that care must be taken
- * (only) when constructing multi-threaded applications to use the
- * inter-thread communication mechanisms which this class provides
- * when required.
- * </p><p>
- * All SWT API methods which may only be called from the user-interface
- * thread are distinguished in their documentation by indicating that
- * they throw the "<code>ERROR_THREAD_INVALID_ACCESS</code>"
- * SWT exception.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Close, Dispose, Settings</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- * @see #syncExec
- * @see #asyncExec
- * @see #wake
- * @see #readAndDispatch
- * @see #sleep
- * @see Device#dispose
- * @see <a href="http://www.eclipse.org/swt/snippets/#display">Display snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Display extends Device {
-
- /* Windows and Events */
- Event [] eventQueue;
- EventTable eventTable, filterTable;
- boolean disposing;
- int sendEventCount;
-
- /* Key event management */
- int [] deadKeyState = new int[1];
- int currentKeyboardUCHRdata;
- boolean eventSourceDelaySet;
-
- /* Sync/Async Widget Communication */
- Synchronizer synchronizer;
- Thread thread;
- boolean allowTimers, runAsyncMessages;
-
- GCData[] contexts;
-
- Caret currentCaret;
-
- boolean sendEvent;
- Control currentControl, trackingControl, tooltipControl;
- Widget tooltipTarget;
-
- NSMutableArray isPainting, needsDisplay, needsDisplayInRect;
-
- NSDictionary markedAttributes;
-
- /* Fonts */
- boolean smallFonts;
- NSFont buttonFont, popUpButtonFont, textFieldFont, secureTextFieldFont;
- NSFont searchFieldFont, comboBoxFont, sliderFont, scrollerFont;
- NSFont textViewFont, tableViewFont, outlineViewFont, datePickerFont;
- NSFont boxFont, tabViewFont, progressIndicatorFont;
-
- Shell [] modalShells;
-
- Menu menuBar;
- Menu[] menus, popups;
-
- NSApplication application;
- int /*long*/ applicationClass;
- NSImage dockImage;
- boolean isEmbedded;
- static boolean launched = false;
-
- /* Focus */
- Control focusControl, currentFocusControl;
- int focusEvent;
-
- NSWindow screenWindow, keyWindow;
-
- NSAutoreleasePool[] pools;
- int poolCount, loopCount;
-
- int[] screenID = new int[32];
- NSPoint[] screenCascade = new NSPoint[32];
-
- int /*long*/ runLoopObserver;
- Callback observerCallback;
-
- boolean lockCursor = true;
- int /*long*/ oldCursorSetProc;
- Callback cursorSetCallback;
-
- // the following Callbacks are never freed
- static Callback windowCallback2, windowCallback3, windowCallback4, windowCallback5, windowCallback6;
- static Callback dialogCallback3, dialogCallback4, dialogCallback5;
- static Callback applicationCallback2, applicationCallback3, applicationCallback6;
- static Callback fieldEditorCallback3, fieldEditorCallback4;
-
- /* Display Shutdown */
- Runnable [] disposeList;
-
- /* System Tray */
- Tray tray;
- TrayItem currentTrayItem;
- Menu trayItemMenu;
-
- /* System Resources */
- Image errorImage, infoImage, warningImage;
- Cursor [] cursors = new Cursor [SWT.CURSOR_HAND + 1];
-
- /* System Colors */
- float /*double*/ [][] colors;
- float /*double*/ [] alternateSelectedControlTextColor, selectedControlTextColor;
- float /*double*/ [] alternateSelectedControlColor, secondarySelectedControlColor;
-
- /* Key Mappings. */
- static int [] [] KeyTable = {
-
- /* Keyboard and Mouse Masks */
- {58, SWT.ALT},
- {56, SWT.SHIFT},
- {59, SWT.CONTROL},
- {55, SWT.COMMAND},
- {61, SWT.ALT},
- {62, SWT.CONTROL},
- {60, SWT.SHIFT},
- {54, SWT.COMMAND},
-
- /* Non-Numeric Keypad Keys */
- {126, SWT.ARROW_UP},
- {125, SWT.ARROW_DOWN},
- {123, SWT.ARROW_LEFT},
- {124, SWT.ARROW_RIGHT},
- {116, SWT.PAGE_UP},
- {121, SWT.PAGE_DOWN},
- {115, SWT.HOME},
- {119, SWT.END},
-// {??, SWT.INSERT},
-
- /* Virtual and Ascii Keys */
- {51, SWT.BS},
- {36, SWT.CR},
- {117, SWT.DEL},
- {53, SWT.ESC},
- {76, SWT.LF},
- {48, SWT.TAB},
-
- /* Functions Keys */
- {122, SWT.F1},
- {120, SWT.F2},
- {99, SWT.F3},
- {118, SWT.F4},
- {96, SWT.F5},
- {97, SWT.F6},
- {98, SWT.F7},
- {100, SWT.F8},
- {101, SWT.F9},
- {109, SWT.F10},
- {103, SWT.F11},
- {111, SWT.F12},
- {105, SWT.F13},
- {107, SWT.F14},
- {113, SWT.F15},
-
- /* Numeric Keypad Keys */
- {67, SWT.KEYPAD_MULTIPLY},
- {69, SWT.KEYPAD_ADD},
- {76, SWT.KEYPAD_CR},
- {78, SWT.KEYPAD_SUBTRACT},
- {65, SWT.KEYPAD_DECIMAL},
- {75, SWT.KEYPAD_DIVIDE},
- {82, SWT.KEYPAD_0},
- {83, SWT.KEYPAD_1},
- {84, SWT.KEYPAD_2},
- {85, SWT.KEYPAD_3},
- {86, SWT.KEYPAD_4},
- {87, SWT.KEYPAD_5},
- {88, SWT.KEYPAD_6},
- {89, SWT.KEYPAD_7},
- {91, SWT.KEYPAD_8},
- {92, SWT.KEYPAD_9},
- {81, SWT.KEYPAD_EQUAL},
-
- /* Other keys */
- {57, SWT.CAPS_LOCK},
- {71, SWT.NUM_LOCK},
-// {??, SWT.SCROLL_LOCK},
-// {??, SWT.PAUSE},
-// {??, SWT.BREAK},
-// {??, SWT.PRINT_SCREEN},
- {114, SWT.HELP},
-
- };
-
- static String APP_NAME;
- static final String ADD_WIDGET_KEY = "org.eclipse.swt.internal.addWidget"; //$NON-NLS-1$
- static final byte[] SWT_OBJECT = {'S', 'W', 'T', '_', 'O', 'B', 'J', 'E', 'C', 'T', '\0'};
- static final byte[] SWT_IMAGE = {'S', 'W', 'T', '_', 'I', 'M', 'A', 'G', 'E', '\0'};
- static final byte[] SWT_ROW = {'S', 'W', 'T', '_', 'R', 'O', 'W', '\0'};
- static final byte[] SWT_COLUMN = {'S', 'W', 'T', '_', 'C', 'O', 'L', 'U', 'M', 'N', '\0'};
-
- /* Multiple Displays. */
- static Display Default;
- static Display [] Displays = new Display [4];
-
- /* Package Name */
- static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets.";
-
- /* Timer */
- Runnable timerList [];
- NSTimer nsTimers [];
- SWTWindowDelegate timerDelegate;
- static SWTApplicationDelegate applicationDelegate;
-
- /* Settings */
- boolean runSettings;
- SWTWindowDelegate settingsDelegate;
-
- static final int DEFAULT_BUTTON_INTERVAL = 30;
-
- /* Display Data */
- Object data;
- String [] keys;
- Object [] values;
-
- /*
- * TEMPORARY CODE. Install the runnable that
- * gets the current display. This code will
- * be removed in the future.
- */
- static {
- DeviceFinder = new Runnable () {
- public void run () {
- Device device = getCurrent ();
- if (device == null) {
- device = getDefault ();
- }
- setDevice (device);
- }
- };
- }
-
-/*
-* TEMPORARY CODE.
-*/
-static void setDevice (Device device) {
- CurrentDevice = device;
-}
-
-static byte [] ascii (String name) {
- int length = name.length ();
- char [] chars = new char [length];
- name.getChars (0, length, chars, 0);
- byte [] buffer = new byte [length + 1];
- for (int i=0; i<length; i++) {
- buffer [i] = (byte) chars [i];
- }
- return buffer;
-}
-
-static int translateKey (int key) {
- for (int i=0; i<KeyTable.length; i++) {
- if (KeyTable [i] [0] == key) return KeyTable [i] [1];
- }
- return 0;
-}
-
-static int untranslateKey (int key) {
- for (int i=0; i<KeyTable.length; i++) {
- if (KeyTable [i] [1] == key) return KeyTable [i] [0];
- }
- return 0;
-}
-
-void addContext (GCData context) {
- if (contexts == null) contexts = new GCData [12];
- for (int i=0; i<contexts.length; i++) {
- if (contexts[i] != null && contexts [i] == context) {
- contexts [i] = context;
- return;
- }
- }
- GCData [] newContexts = new GCData [contexts.length + 12];
- newContexts [contexts.length] = context;
- System.arraycopy (contexts, 0, newContexts, 0, contexts.length);
- contexts = newContexts;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs anywhere
- * in a widget. The event type is one of the event constants
- * defined in class <code>SWT</code>. When the event does occur,
- * the listener is notified by sending it the <code>handleEvent()</code>
- * message.
- * <p>
- * Setting the type of an event to <code>SWT.None</code> from
- * within the <code>handleEvent()</code> method can be used to
- * change the event type and stop subsequent Java listeners
- * from running. Because event filters run before other listeners,
- * event filters can both block other listeners and set arbitrary
- * fields within an event. For this reason, event filters are both
- * powerful and dangerous. They should generally be avoided for
- * performance, debugging and code maintenance reasons.
- * </p>
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #removeFilter
- * @see #removeListener
- *
- * @since 3.0
- */
-public void addFilter (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (filterTable == null) filterTable = new EventTable ();
- filterTable.hook (eventType, listener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- * When the event does occur in the display, the listener is notified by
- * sending it the <code>handleEvent()</code> message.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #removeListener
- *
- * @since 2.0
- */
-public void addListener (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) eventTable = new EventTable ();
- eventTable.hook (eventType, listener);
-}
-
-void addMenu (Menu menu) {
- if (menus == null) menus = new Menu [12];
- for (int i=0; i<menus.length; i++) {
- if (menus [i] == null) {
- menus [i] = menu;
- return;
- }
- }
- Menu [] newMenus = new Menu [menus.length + 12];
- newMenus [menus.length] = menu;
- System.arraycopy (menus, 0, newMenus, 0, menus.length);
- menus = newMenus;
-}
-
-void addPool () {
- addPool ((NSAutoreleasePool)new NSAutoreleasePool().alloc().init());
-}
-
-void addPool (NSAutoreleasePool pool) {
- if (pools == null) pools = new NSAutoreleasePool [4];
- if (poolCount == pools.length) {
- NSAutoreleasePool[] temp = new NSAutoreleasePool [poolCount + 4];
- System.arraycopy (pools, 0, temp, 0, poolCount);
- pools = temp;
- }
- if (poolCount == 0) {
- NSMutableDictionary dictionary = NSThread.currentThread().threadDictionary();
- dictionary.setObject(NSNumber.numberWithInteger(pool.id), NSString.stringWith("SWT_NSAutoreleasePool"));
- }
- pools [poolCount++] = pool;
-}
-
-void addPopup (Menu menu) {
- if (popups == null) popups = new Menu [4];
- int length = popups.length;
- for (int i=0; i<length; i++) {
- if (popups [i] == menu) return;
- }
- int index = 0;
- while (index < length) {
- if (popups [index] == null) break;
- index++;
- }
- if (index == length) {
- Menu [] newPopups = new Menu [length + 4];
- System.arraycopy (popups, 0, newPopups, 0, length);
- popups = newPopups;
- }
- popups [index] = menu;
-}
-
-void addWidget (NSObject view, Widget widget) {
- if (view == null) return;
- OS.object_setInstanceVariable (view.id, SWT_OBJECT, widget.jniRef);
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread at the next
- * reasonable opportunity. The caller of this method continues
- * to run in parallel, and is not notified when the
- * runnable has completed. Specifying <code>null</code> as the
- * runnable simply wakes the user-interface thread when run.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param runnable code to run on the user-interface thread or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #syncExec
- */
-public void asyncExec (Runnable runnable) {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- synchronizer.asyncExec (runnable);
- }
-}
-
-/**
- * Causes the system hardware to emit a short sound
- * (if it supports this capability).
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void beep () {
- checkDevice ();
- OS.NSBeep ();
-}
-
-void cascadeWindow (NSWindow window, NSScreen screen) {
- NSDictionary dictionary = screen.deviceDescription();
- int screenNumber = new NSNumber(dictionary.objectForKey(NSString.stringWith("NSScreenNumber")).id).intValue();
- int index = 0;
- while (screenID[index] != 0 && screenID[index] != screenNumber) index++;
- screenID[index] = screenNumber;
- NSPoint cascade = screenCascade[index];
- if (cascade == null) {
- NSRect frame = screen.frame();
- cascade = new NSPoint();
- cascade.x = frame.x;
- cascade.y = frame.y + frame.height;
- }
- screenCascade[index] = window.cascadeTopLeftFromPoint(cascade);
-}
-
-protected void checkDevice () {
- if (thread == null) error (SWT.ERROR_WIDGET_DISPOSED);
- if (thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
-}
-
-void checkEnterExit (Control control, NSEvent nsEvent, boolean send) {
- if (control != currentControl) {
- if (currentControl != null && !currentControl.isDisposed()) {
- currentControl.sendMouseEvent (nsEvent, SWT.MouseExit, send);
- }
- if (control != null && control.isDisposed()) control = null;
- currentControl = control;
- if (control != null) {
- control.sendMouseEvent (nsEvent, SWT.MouseEnter, send);
- }
- setCursor (control);
- }
- timerExec (control != null && !control.isDisposed() ? getToolTipTime () : -1, hoverTimer);
-}
-
-void checkFocus () {
- Control oldControl = currentFocusControl;
- Control newControl = getFocusControl ();
- if (oldControl != newControl) {
- if (oldControl != null && !oldControl.isDisposed ()) {
- oldControl.sendFocusEvent (SWT.FocusOut);
- }
- currentFocusControl = newControl;
- if (newControl != null && !newControl.isDisposed ()) {
- newControl.sendFocusEvent (SWT.FocusIn);
- }
- }
-}
-
-/**
- * Checks that this class can be subclassed.
- * <p>
- * IMPORTANT: See the comment in <code>Widget.checkSubclass()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- */
-protected void checkSubclass () {
- if (!Display.isValidClass (getClass ())) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * Note: The resulting display is marked as the <em>current</em>
- * display. If this is the first display which has been
- * constructed since the application started, it is also
- * marked as the <em>default</em> display.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if called from a thread that already created an existing display</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see #getCurrent
- * @see #getDefault
- * @see Widget#checkSubclass
- * @see Shell
- */
-public Display () {
- this (null);
-}
-
-/**
- * Constructs a new instance of this class using the parameter.
- *
- * @param data the device data
- */
-public Display (DeviceData data) {
- super (data);
-}
-
-static void checkDisplay (Thread thread, boolean multiple) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] != null) {
- if (!multiple) SWT.error (SWT.ERROR_NOT_IMPLEMENTED, null, " [multiple displays]");
- if (Displays [i].thread == thread) SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- }
- }
-}
-
-static String convertToLf(String text) {
- char Cr = '\r';
- char Lf = '\n';
- int length = text.length ();
- if (length == 0) return text;
-
- /* Check for an LF or CR/LF. Assume the rest of the string
- * is formated that way. This will not work if the string
- * contains mixed delimiters. */
- int i = text.indexOf (Lf, 0);
- if (i == -1 || i == 0) return text;
- if (text.charAt (i - 1) != Cr) return text;
-
- /* The string is formatted with CR/LF.
- * Create a new string with the LF line delimiter. */
- i = 0;
- StringBuffer result = new StringBuffer ();
- while (i < length) {
- int j = text.indexOf (Cr, i);
- if (j == -1) j = length;
- String s = text.substring (i, j);
- result.append (s);
- i = j + 2;
- result.append (Lf);
- }
- return result.toString ();
-}
-
-void clearModal (Shell shell) {
- if (modalShells == null) return;
- int index = 0, length = modalShells.length;
- while (index < length) {
- if (modalShells [index] == shell) break;
- if (modalShells [index] == null) return;
- index++;
- }
- if (index == length) return;
- System.arraycopy (modalShells, index + 1, modalShells, index, --length - index);
- modalShells [length] = null;
- if (index == 0 && modalShells [0] == null) modalShells = null;
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) shells [i].updateModal ();
-}
-
-void clearPool () {
- if (sendEventCount == 0 && loopCount == poolCount - 1 && Callback.getEntryCount () == 0) {
- removePool ();
- addPool ();
- }
-}
-
-/**
- * Requests that the connection between SWT and the underlying
- * operating system be closed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Device#dispose
- *
- * @since 2.0
- */
-public void close () {
- checkDevice ();
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- if (event.doit) dispose ();
-}
-
-/**
- * Creates the device in the operating system. If the device
- * does not have a handle, this method may do nothing depending
- * on the device.
- * <p>
- * This method is called before <code>init</code>.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #init
- */
-protected void create (DeviceData data) {
- checkSubclass ();
- checkDisplay (thread = Thread.currentThread (), false);
- createDisplay (data);
- register (this);
- synchronizer = new Synchronizer (this);
- if (Default == null) Default = this;
-}
-
-void createDisplay (DeviceData data) {
- if (OS.VERSION < 0x1050) {
- System.out.println ("***WARNING: SWT requires MacOS X version " + 10 + "." + 5 + " or greater"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- System.out.println ("***WARNING: Detected: " + Integer.toHexString((OS.VERSION & 0xFF00) >> 8) + "." + Integer.toHexString((OS.VERSION & 0xF0) >> 4) + "." + Integer.toHexString(OS.VERSION & 0xF)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- error(SWT.ERROR_NOT_IMPLEMENTED);
- }
-
- NSThread nsthread = NSThread.currentThread();
- NSMutableDictionary dictionary = nsthread.threadDictionary();
- NSString key = NSString.stringWith("SWT_NSAutoreleasePool");
- NSNumber id = new NSNumber(dictionary.objectForKey(key));
- addPool(new NSAutoreleasePool(id.integerValue()));
-
- application = NSApplication.sharedApplication();
-
- /*
- * TODO: If an NSApplication is already running we don't want to create another NSApplication.
- * But if we don't we won't get mouse events, since we currently need to subclass NSApplication and intercept sendEvent to
- * deliver mouse events correctly to widgets.
- */
- if (!application.isRunning()) {
- /*
- * Feature in the Macintosh. On OS 10.2, it is necessary
- * to explicitly check in with the Process Manager and set
- * the current process to be the front process in order for
- * windows to come to the front by default. The fix is call
- * both GetCurrentProcess() and SetFrontProcess().
- *
- * NOTE: It is not actually necessary to use the process
- * serial number returned by GetCurrentProcess() in the
- * call to SetFrontProcess() (ie. kCurrentProcess can be
- * used) but both functions must be called in order for
- * windows to come to the front.
- */
- int [] psn = new int [2];
- if (OS.GetCurrentProcess (psn) == OS.noErr) {
- int pid = OS.getpid ();
- int /*long*/ ptr = getAppName().UTF8String();
- if (ptr != 0) OS.CPSSetProcessName (psn, ptr);
- OS.TransformProcessType (psn, OS.kProcessTransformToForegroundApplication);
- OS.SetFrontProcess (psn);
- ptr = OS.getenv (ascii ("APP_ICON_" + pid));
- if (ptr != 0) {
- NSString path = NSString.stringWithUTF8String (ptr);
- NSImage image = (NSImage) new NSImage().alloc();
- image = image.initByReferencingFile(path);
- dockImage = image;
- application.setApplicationIconImage(image);
- }
- }
-
- String className = "SWTApplication";
- int /*long*/ cls;
- if ((cls = OS.objc_lookUpClass (className)) == 0) {
- Class clazz = getClass();
- applicationCallback2 = new Callback(clazz, "applicationProc", 2);
- int /*long*/ proc2 = applicationCallback2.getAddress();
- if (proc2 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- applicationCallback3 = new Callback(clazz, "applicationProc", 3);
- int /*long*/ proc3 = applicationCallback3.getAddress();
- if (proc3 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- applicationCallback6 = new Callback(clazz, "applicationProc", 6);
- int /*long*/ proc6 = applicationCallback6.getAddress();
- if (proc6 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- cls = OS.objc_allocateClassPair(OS.class_NSApplication, className, 0);
- OS.class_addMethod(cls, OS.sel_sendEvent_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_nextEventMatchingMask_untilDate_inMode_dequeue_, proc6, "@:i@@B");
- OS.class_addMethod(cls, OS.sel_isRunning, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_finishLaunching, proc2, "@:");
- OS.objc_registerClassPair(cls);
- }
- applicationClass = OS.object_setClass(application.id, cls);
-
- className = "SWTApplicationDelegate";
- if (OS.objc_lookUpClass (className) == 0) {
- int /*long*/ appProc3 = applicationCallback3.getAddress();
- if (appProc3 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- cls = OS.objc_allocateClassPair(OS.class_NSObject, className, 0);
- OS.class_addMethod(cls, OS.sel_applicationWillFinishLaunching_, appProc3, "@:@");
- OS.class_addMethod(cls, OS.sel_terminate_, appProc3, "@:@");
- OS.class_addMethod(cls, OS.sel_quitRequested_, appProc3, "@:@");
- OS.class_addMethod(cls, OS.sel_orderFrontStandardAboutPanel_, appProc3, "@:@");
- OS.class_addMethod(cls, OS.sel_hideOtherApplications_, appProc3, "@:@");
- OS.class_addMethod(cls, OS.sel_hide_, appProc3, "@:@");
- OS.class_addMethod(cls, OS.sel_unhideAllApplications_, appProc3, "@:@");
- OS.class_addMethod(cls, OS.sel_applicationDidBecomeActive_, appProc3, "@:@");
- OS.class_addMethod(cls, OS.sel_applicationDidResignActive_, appProc3, "@:@");
- OS.objc_registerClassPair(cls);
- }
- if (applicationDelegate == null) {
- applicationDelegate = (SWTApplicationDelegate)new SWTApplicationDelegate().alloc().init();
- application.setDelegate(applicationDelegate);
- }
- } else {
- isEmbedded = true;
- }
-}
-
-void createMainMenu () {
- NSString appName = getAppName();
- NSString emptyStr = NSString.stringWith("");
- NSMenu mainMenu = (NSMenu)new NSMenu().alloc();
- mainMenu.initWithTitle(emptyStr);
-
- NSMenuItem menuItem;
- NSMenu appleMenu;
- NSString format = NSString.stringWith("%@ %@"), title;
-
- NSMenuItem appItem = menuItem = mainMenu.addItemWithTitle(emptyStr, 0, emptyStr);
- appleMenu = (NSMenu)new NSMenu().alloc();
- appleMenu.initWithTitle(emptyStr);
- OS.objc_msgSend(application.id, OS.sel_registerName("setAppleMenu:"), appleMenu.id);
-
- title = new NSString(OS.objc_msgSend(OS.class_NSString, OS.sel_stringWithFormat_, format.id, NSString.stringWith(SWT.getMessage("About")).id, appName.id));
- menuItem = appleMenu.addItemWithTitle(title, OS.sel_orderFrontStandardAboutPanel_, emptyStr);
- menuItem.setTarget(applicationDelegate);
-
- appleMenu.addItem(NSMenuItem.separatorItem());
-
- title = NSString.stringWith(SWT.getMessage("Preferences..."));
- menuItem = appleMenu.addItemWithTitle(title, 0, NSString.stringWith(","));
-
- appleMenu.addItem(NSMenuItem.separatorItem());
-
- title = NSString.stringWith(SWT.getMessage("Services"));
- menuItem = appleMenu.addItemWithTitle(title, 0, emptyStr);
- NSMenu servicesMenu = (NSMenu)new NSMenu().alloc();
- servicesMenu.initWithTitle(emptyStr);
- appleMenu.setSubmenu(servicesMenu, menuItem);
- servicesMenu.release();
- application.setServicesMenu(servicesMenu);
-
- appleMenu.addItem(NSMenuItem.separatorItem());
-
- title = new NSString(OS.objc_msgSend(OS.class_NSString, OS.sel_stringWithFormat_, format.id, NSString.stringWith(SWT.getMessage("Hide")).id, appName.id));
- menuItem = appleMenu.addItemWithTitle(title, OS.sel_hide_, NSString.stringWith("h"));
- menuItem.setTarget(applicationDelegate);
-
- title = NSString.stringWith(SWT.getMessage("Hide Others"));
- menuItem = appleMenu.addItemWithTitle(title, OS.sel_hideOtherApplications_, NSString.stringWith("h"));
- menuItem.setKeyEquivalentModifierMask(OS.NSCommandKeyMask | OS.NSAlternateKeyMask);
- menuItem.setTarget(applicationDelegate);
-
- title = NSString.stringWith(SWT.getMessage("Show All"));
- menuItem = appleMenu.addItemWithTitle(title, OS.sel_unhideAllApplications_, emptyStr);
- menuItem.setTarget(applicationDelegate);
-
- appleMenu.addItem(NSMenuItem.separatorItem());
-
- title = new NSString(OS.objc_msgSend(OS.class_NSString, OS.sel_stringWithFormat_, format.id, NSString.stringWith(SWT.getMessage("Quit")).id, appName.id));
- menuItem = appleMenu.addItemWithTitle(title, OS.sel_quitRequested_, NSString.stringWith("q"));
- menuItem.setTarget(applicationDelegate);
-
- mainMenu.setSubmenu(appleMenu, appItem);
- appleMenu.release();
- application.setMainMenu(mainMenu);
- mainMenu.release();
-}
-
-int /*long*/ cursorSetProc (int /*long*/ id, int /*long*/ sel) {
- if (lockCursor) {
- if (currentControl != null) {
- Cursor cursor = currentControl.findCursor ();
- if (cursor != null && cursor.handle.id != id) return 0;
- }
- }
- OS.call (oldCursorSetProc, id, sel);
- return 0;
-}
-
-static void deregister (Display display) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (display == Displays [i]) Displays [i] = null;
- }
- }
-}
-
-/**
- * Destroys the device in the operating system and releases
- * the device's handle. If the device does not have a handle,
- * this method may do nothing depending on the device.
- * <p>
- * This method is called after <code>release</code>.
- * </p>
- * @see Device#dispose
- * @see #release
- */
-protected void destroy () {
- if (this == Default) Default = null;
- deregister (this);
- destroyDisplay ();
-}
-
-void destroyDisplay () {
- application = null;
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread just before the
- * receiver is disposed. Specifying a <code>null</code> runnable
- * is ignored.
- *
- * @param runnable code to run at dispose time.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void disposeExec (Runnable runnable) {
- checkDevice ();
- if (disposeList == null) disposeList = new Runnable [4];
- for (int i=0; i<disposeList.length; i++) {
- if (disposeList [i] == null) {
- disposeList [i] = runnable;
- return;
- }
- }
- Runnable [] newDisposeList = new Runnable [disposeList.length + 4];
- System.arraycopy (disposeList, 0, newDisposeList, 0, disposeList.length);
- newDisposeList [disposeList.length] = runnable;
- disposeList = newDisposeList;
-}
-
-void error (int code) {
- SWT.error(code);
-}
-
-boolean filterEvent (Event event) {
- if (filterTable != null) filterTable.sendEvent (event);
- return false;
-}
-
-boolean filters (int eventType) {
- if (filterTable == null) return false;
- return filterTable.hooks (eventType);
-}
-
-/**
- * Given the operating system handle for a widget, returns
- * the instance of the <code>Widget</code> subclass which
- * represents it in the currently running application, if
- * such exists, or null if no matching widget can be found.
- * <p>
- * <b>IMPORTANT:</b> This method should not be called from
- * application code. The arguments are platform-specific.
- * </p>
- *
- * @param handle the handle for the widget
- * @return the SWT widget that the handle represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Widget findWidget (int /*long*/ handle) {
- checkDevice ();
- return getWidget (handle);
-}
-
-/**
- * Given the operating system handle for a widget,
- * and widget-specific id, returns the instance of
- * the <code>Widget</code> subclass which represents
- * the handle/id pair in the currently running application,
- * if such exists, or null if no matching widget can be found.
- * <p>
- * <b>IMPORTANT:</b> This method should not be called from
- * application code. The arguments are platform-specific.
- * </p>
- *
- * @param handle the handle for the widget
- * @param id the id for the subwidget (usually an item)
- * @return the SWT widget that the handle/id pair represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public Widget findWidget (int /*long*/ handle, int id) {
- checkDevice ();
- return getWidget (handle);
-}
-
-/**
- * Given a widget and a widget-specific id, returns the
- * instance of the <code>Widget</code> subclass which represents
- * the widget/id pair in the currently running application,
- * if such exists, or null if no matching widget can be found.
- *
- * @param widget the widget
- * @param id the id for the subwidget (usually an item)
- * @return the SWT subwidget (usually an item) that the widget/id pair represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.3
- */
-public Widget findWidget (Widget widget, int id) {
- checkDevice ();
- return null;
-}
-
-/**
- * Returns the display which the given thread is the
- * user-interface thread for, or null if the given thread
- * is not a user-interface thread for any display. Specifying
- * <code>null</code> as the thread will return <code>null</code>
- * for the display.
- *
- * @param thread the user-interface thread
- * @return the display for the given thread
- */
-public static Display findDisplay (Thread thread) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- Display display = Displays [i];
- if (display != null && display.thread == thread) {
- return display;
- }
- }
- return null;
- }
-}
-
-/**
- * Returns the currently active <code>Shell</code>, or null
- * if no shell belonging to the currently running application
- * is active.
- *
- * @return the active shell or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Shell getActiveShell () {
- checkDevice ();
- NSWindow window = keyWindow != null ? keyWindow : application.keyWindow();
- if (window != null) {
- Widget widget = getWidget(window.contentView());
- if (widget instanceof Shell) {
- return (Shell)widget;
- }
- }
- return null;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location. Note that
- * on multi-monitor systems the origin can be negative.
- *
- * @return the bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkDevice ();
- NSArray screens = NSScreen.screens();
- return getBounds (screens);
-}
-
-Rectangle getBounds (NSArray screens) {
- NSRect primaryFrame = new NSScreen(screens.objectAtIndex(0)).frame();
- float /*double*/ minX = Float.MAX_VALUE, maxX = Float.MIN_VALUE;
- float /*double*/ minY = Float.MAX_VALUE, maxY = Float.MIN_VALUE;
- int /*long*/ count = screens.count();
- for (int i = 0; i < count; i++) {
- NSScreen screen = new NSScreen(screens.objectAtIndex(i));
- NSRect frame = screen.frame();
- float /*double*/ x1 = frame.x, x2 = frame.x + frame.width;
- float /*double*/ y1 = primaryFrame.height - frame.y, y2 = primaryFrame.height - (frame.y + frame.height);
- if (x1 < minX) minX = x1;
- if (x2 < minX) minX = x2;
- if (x1 > maxX) maxX = x1;
- if (x2 > maxX) maxX = x2;
- if (y1 < minY) minY = y1;
- if (y2 < minY) minY = y2;
- if (y1 > maxY) maxY = y1;
- if (y2 > maxY) maxY = y2;
- }
- return new Rectangle ((int)minX, (int)minY, (int)(maxX - minX), (int)(maxY - minY));
-}
-
-/**
- * Returns the display which the currently running thread is
- * the user-interface thread for, or null if the currently
- * running thread is not a user-interface thread for any display.
- *
- * @return the current display
- */
-public static Display getCurrent () {
- return findDisplay (Thread.currentThread ());
-}
-
-int getCaretBlinkTime () {
-// checkDevice ();
- return 560;
-}
-
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data.
- *
- * @return the client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getBounds
- */
-public Rectangle getClientArea () {
- checkDevice ();
- NSArray screens = NSScreen.screens();
- if (screens.count() != 1) return getBounds (screens);
- NSScreen screen = new NSScreen(screens.objectAtIndex(0));
- NSRect frame = screen.frame();
- NSRect visibleFrame = screen.visibleFrame();
- float /*double*/ y = frame.height - (visibleFrame.y + visibleFrame.height);
- return new Rectangle((int)visibleFrame.x, (int)y, (int)visibleFrame.width, (int)visibleFrame.height);
-}
-
-/**
- * Returns the control which the on-screen pointer is currently
- * over top of, or null if it is not currently over one of the
- * controls built by the currently running application.
- *
- * @return the control under the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Control getCursorControl () {
- checkDevice();
- return findControl(false);
-}
-
-/**
- * Returns the location of the on-screen pointer relative
- * to the top left corner of the screen.
- *
- * @return the cursor location
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point getCursorLocation () {
- checkDevice ();
- NSPoint location = NSEvent.mouseLocation();
- NSRect primaryFrame = getPrimaryFrame();
- return new Point ((int) location.x, (int) (primaryFrame.height - location.y));
-}
-
-/**
- * Returns an array containing the recommended cursor sizes.
- *
- * @return the array of cursor sizes
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public Point [] getCursorSizes () {
- checkDevice ();
- return new Point [] {new Point (16, 16)};
-}
-
-/**
- * Returns the default display. One is created (making the
- * thread that invokes this method its user-interface thread)
- * if it did not already exist.
- *
- * @return the default display
- */
-public static Display getDefault () {
- synchronized (Device.class) {
- if (Default == null) Default = new Display ();
- return Default;
- }
-}
-
-/**
- * Returns the application defined property of the receiver
- * with the specified name, or null if it has not been set.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the display is disposed
- * of, it is the application's responsibility to provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param key the name of the property
- * @return the value of the property or null if it has not been set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setData(String, Object)
- * @see #disposeExec(Runnable)
- */
-public Object getData (String key) {
- checkDevice ();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (keys == null) return null;
- for (int i=0; i<keys.length; i++) {
- if (keys [i].equals (key)) return values [i];
- }
- return null;
-}
-
-/**
- * Returns the application defined, display specific data
- * associated with the receiver, or null if it has not been
- * set. The <em>display specific data</em> is a single,
- * unnamed field that is stored with every display.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the display specific data needs to
- * be notified when the display is disposed of, it is the
- * application's responsibility to provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @return the display specific data
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setData(Object)
- * @see #disposeExec(Runnable)
- */
-public Object getData () {
- checkDevice ();
- return data;
-}
-
-/**
- * Returns the button dismissal alignment, one of <code>LEFT</code> or <code>RIGHT</code>.
- * The button dismissal alignment is the ordering that should be used when positioning the
- * default dismissal button for a dialog. For example, in a dialog that contains an OK and
- * CANCEL button, on platforms where the button dismissal alignment is <code>LEFT</code>, the
- * button ordering should be OK/CANCEL. When button dismissal alignment is <code>RIGHT</code>,
- * the button ordering should be CANCEL/OK.
- *
- * @return the button dismissal order
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1
- */
-public int getDismissalAlignment () {
- checkDevice ();
- return SWT.RIGHT;
-}
-
-/**
- * Returns the longest duration, in milliseconds, between
- * two mouse button clicks that will be considered a
- * <em>double click</em> by the underlying operating system.
- *
- * @return the double click time
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getDoubleClickTime () {
- checkDevice ();
- return OS.GetDblTime () * 1000 / 60;
-}
-
-/**
- * Returns the control which currently has keyboard focus,
- * or null if keyboard events are not currently going to
- * any of the controls built by the currently running
- * application.
- *
- * @return the control under the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Control getFocusControl () {
- checkDevice ();
- if (focusControl != null && !focusControl.isDisposed ()) {
- return focusControl;
- }
- NSWindow window = keyWindow != null ? keyWindow : application.keyWindow();
- return _getFocusControl(window);
-}
-
-Control _getFocusControl (NSWindow window) {
- if (window != null) {
- NSResponder responder = window.firstResponder();
- if (responder != null && !responder.respondsToSelector(OS.sel_superview)) {
- return null;
- }
- NSView view = new NSView(responder.id);
- if (view != null) {
- do {
- Widget widget = GetWidget (view.id);
- if (widget instanceof Control) {
- return (Control)widget;
- }
- view = view.superview();
- } while (view != null);
- }
- }
- return null;
-}
-
-/**
- * Returns true when the high contrast mode is enabled.
- * Otherwise, false is returned.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @return the high contrast mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public boolean getHighContrast () {
- checkDevice ();
- return false;
-}
-
-/**
- * Returns the maximum allowed depth of icons on this display, in bits per pixel.
- * On some platforms, this may be different than the actual depth of the display.
- *
- * @return the maximum icon depth
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Device#getDepth
- */
-public int getIconDepth () {
- return getDepth ();
-}
-
-/**
- * Returns an array containing the recommended icon sizes.
- *
- * @return the array of icon sizes
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Decorations#setImages(Image[])
- *
- * @since 3.0
- */
-public Point [] getIconSizes () {
- checkDevice ();
- return new Point [] {
- new Point (16, 16), new Point (32, 32),
- new Point (64, 64), new Point (128, 128)};
-}
-
-int getLastEventTime () {
- NSEvent event = application.currentEvent();
- return event != null ? (int)(event.timestamp() * 1000) : 0;
-}
-
-Menu [] getMenus (Decorations shell) {
- if (menus == null) return new Menu [0];
- int count = 0;
- for (int i = 0; i < menus.length; i++) {
- Menu menu = menus[i];
- if (menu != null && menu.parent == shell) count++;
- }
- int index = 0;
- Menu[] result = new Menu[count];
- for (int i = 0; i < menus.length; i++) {
- Menu menu = menus[i];
- if (menu != null && menu.parent == shell) {
- result[index++] = menu;
- }
- }
- return result;
-}
-
-int getMessageCount () {
- return synchronizer.getMessageCount ();
-}
-
-/**
- * Returns an array of monitors attached to the device.
- *
- * @return the array of monitors
- *
- * @since 3.0
- */
-public Monitor [] getMonitors () {
- checkDevice ();
- NSArray screens = NSScreen.screens();
- NSRect primaryFrame = new NSScreen(screens.objectAtIndex(0)).frame();
- int count = (int)/*64*/screens.count();
- Monitor [] monitors = new Monitor [count];
- for (int i=0; i<count; i++) {
- Monitor monitor = new Monitor ();
- NSScreen screen = new NSScreen(screens.objectAtIndex(i));
- NSRect frame = screen.frame();
- monitor.x = (int)frame.x;
- monitor.y = (int)(primaryFrame.height - (frame.y + frame.height));
- monitor.width = (int)frame.width;
- monitor.height = (int)frame.height;
- NSRect visibleFrame = screen.visibleFrame();
- monitor.clientX = (int)visibleFrame.x;
- monitor.clientY = (int)(primaryFrame.height - (visibleFrame.y + visibleFrame.height));
- monitor.clientWidth = (int)visibleFrame.width;
- monitor.clientHeight = (int)visibleFrame.height;
- monitors [i] = monitor;
- }
- return monitors;
-}
-
-NSRect getPrimaryFrame () {
- NSArray screens = NSScreen.screens();
- return new NSScreen(screens.objectAtIndex(0)).frame();
-}
-
-/**
- * Returns the primary monitor for that device.
- *
- * @return the primary monitor
- *
- * @since 3.0
- */
-public Monitor getPrimaryMonitor () {
- checkDevice ();
- Monitor monitor = new Monitor ();
- NSArray screens = NSScreen.screens();
- NSScreen screen = new NSScreen(screens.objectAtIndex(0));
- NSRect frame = screen.frame();
- monitor.x = (int)frame.x;
- monitor.y = (int)(frame.height - (frame.y + frame.height));
- monitor.width = (int)frame.width;
- monitor.height = (int)frame.height;
- NSRect visibleFrame = screen.visibleFrame();
- monitor.clientX = (int)visibleFrame.x;
- monitor.clientY = (int)(frame.height - (visibleFrame.y + visibleFrame.height));
- monitor.clientWidth = (int)visibleFrame.width;
- monitor.clientHeight = (int)visibleFrame.height;
- return monitor;
-}
-
-/**
- * Returns a (possibly empty) array containing all shells which have
- * not been disposed and have the receiver as their display.
- *
- * @return the receiver's shells
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Shell [] getShells () {
- checkDevice ();
- NSArray windows = application.windows();
- int index = 0;
- Shell [] result = new Shell [(int)/*64*/windows.count()];
- for (int i = 0; i < result.length; i++) {
- NSWindow window = new NSWindow(windows.objectAtIndex(i));
- Widget widget = getWidget(window.contentView());
- if (widget instanceof Shell) {
- result[index++] = (Shell)widget;
- }
- }
- if (index == result.length) return result;
- Shell [] newResult = new Shell [index];
- System.arraycopy (result, 0, newResult, 0, index);
- return newResult;
-}
-
-static boolean getSheetEnabled () {
- return !"false".equals(System.getProperty("org.eclipse.swt.sheet"));
-}
-
-/**
- * Gets the synchronizer used by the display.
- *
- * @return the receiver's synchronizer
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public Synchronizer getSynchronizer () {
- checkDevice ();
- return synchronizer;
-}
-
-/**
- * Returns the thread that has invoked <code>syncExec</code>
- * or null if no such runnable is currently being invoked by
- * the user-interface thread.
- * <p>
- * Note: If a runnable invoked by asyncExec is currently
- * running, this method will return null.
- * </p>
- *
- * @return the receiver's sync-interface thread
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Thread getSyncThread () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- return synchronizer.syncThread;
- }
-}
-
-/**
- * Returns the matching standard color for the given
- * constant, which should be one of the color constants
- * specified in class <code>SWT</code>. Any value other
- * than one of the SWT color constants which is passed
- * in will result in the color black. This color should
- * not be free'd because it was allocated by the system,
- * not the application.
- *
- * @param id the color constant
- * @return the matching color
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT
- */
-public Color getSystemColor (int id) {
- checkDevice ();
- Color color = getWidgetColor (id);
- if (color != null) return color;
- return super.getSystemColor (id);
-}
-
-Color getWidgetColor (int id) {
- if (0 <= id && id < colors.length && colors [id] != null) {
- return Color.cocoa_new (this, colors [id]);
- }
- return null;
-}
-
-float /*double*/ [] getWidgetColorRGB (int id) {
- NSColor color = null;
- switch (id) {
- case SWT.COLOR_INFO_FOREGROUND: color = NSColor.blackColor (); break;
- case SWT.COLOR_INFO_BACKGROUND: return new float /*double*/ [] {0xFF / 255f, 0xFF / 255f, 0xE1 / 255f, 1};
- case SWT.COLOR_TITLE_FOREGROUND: color = NSColor.windowFrameTextColor(); break;
- case SWT.COLOR_TITLE_BACKGROUND: color = NSColor.alternateSelectedControlColor(); break;
- case SWT.COLOR_TITLE_BACKGROUND_GRADIENT: color = NSColor.selectedControlColor(); break;
- case SWT.COLOR_TITLE_INACTIVE_FOREGROUND: color = NSColor.disabledControlTextColor(); break;
- case SWT.COLOR_TITLE_INACTIVE_BACKGROUND: color = NSColor.secondarySelectedControlColor(); break;
- case SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT: color = NSColor.secondarySelectedControlColor(); break;
- case SWT.COLOR_WIDGET_DARK_SHADOW: color = NSColor.controlDarkShadowColor(); break;
- case SWT.COLOR_WIDGET_NORMAL_SHADOW: color = NSColor.controlShadowColor(); break;
- case SWT.COLOR_WIDGET_LIGHT_SHADOW: color = NSColor.controlHighlightColor(); break;
- case SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: color = NSColor.controlLightHighlightColor(); break;
- case SWT.COLOR_WIDGET_BACKGROUND: color = NSColor.controlHighlightColor(); break;
- case SWT.COLOR_WIDGET_FOREGROUND: color = NSColor.controlTextColor(); break;
- case SWT.COLOR_WIDGET_BORDER: color = NSColor.blackColor (); break;
- case SWT.COLOR_LIST_FOREGROUND: color = NSColor.textColor(); break;
- case SWT.COLOR_LIST_BACKGROUND: color = NSColor.textBackgroundColor(); break;
- case SWT.COLOR_LIST_SELECTION_TEXT: color = NSColor.selectedTextColor(); break;
- case SWT.COLOR_LIST_SELECTION: color = NSColor.selectedTextBackgroundColor(); break;
- }
- return getWidgetColorRGB (color);
-}
-
-float /*double*/ [] getWidgetColorRGB (NSColor color) {
- if (color == null) return null;
- color = color.colorUsingColorSpace(NSColorSpace.deviceRGBColorSpace());
- if (color == null) return null;
- float /*double*/[] components = new float /*double*/[(int)/*64*/color.numberOfComponents()];
- color.getComponents(components);
- return new float /*double*/ []{components[0], components[1], components[2], components[3]};
-}
-
-/**
- * Returns the matching standard platform cursor for the given
- * constant, which should be one of the cursor constants
- * specified in class <code>SWT</code>. This cursor should
- * not be free'd because it was allocated by the system,
- * not the application. A value of <code>null</code> will
- * be returned if the supplied constant is not an SWT cursor
- * constant.
- *
- * @param id the SWT cursor constant
- * @return the corresponding cursor or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT#CURSOR_ARROW
- * @see SWT#CURSOR_WAIT
- * @see SWT#CURSOR_CROSS
- * @see SWT#CURSOR_APPSTARTING
- * @see SWT#CURSOR_HELP
- * @see SWT#CURSOR_SIZEALL
- * @see SWT#CURSOR_SIZENESW
- * @see SWT#CURSOR_SIZENS
- * @see SWT#CURSOR_SIZENWSE
- * @see SWT#CURSOR_SIZEWE
- * @see SWT#CURSOR_SIZEN
- * @see SWT#CURSOR_SIZES
- * @see SWT#CURSOR_SIZEE
- * @see SWT#CURSOR_SIZEW
- * @see SWT#CURSOR_SIZENE
- * @see SWT#CURSOR_SIZESE
- * @see SWT#CURSOR_SIZESW
- * @see SWT#CURSOR_SIZENW
- * @see SWT#CURSOR_UPARROW
- * @see SWT#CURSOR_IBEAM
- * @see SWT#CURSOR_NO
- * @see SWT#CURSOR_HAND
- *
- * @since 3.0
- */
-public Cursor getSystemCursor (int id) {
- checkDevice ();
- if (!(0 <= id && id < cursors.length)) return null;
- if (cursors [id] == null) {
- cursors [id] = new Cursor (this, id);
- }
- return cursors [id];
-}
-
-/**
- * Returns the matching standard platform image for the given
- * constant, which should be one of the icon constants
- * specified in class <code>SWT</code>. This image should
- * not be free'd because it was allocated by the system,
- * not the application. A value of <code>null</code> will
- * be returned either if the supplied constant is not an
- * SWT icon constant or if the platform does not define an
- * image that corresponds to the constant.
- *
- * @param id the SWT icon constant
- * @return the corresponding image or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_QUESTION
- * @see SWT#ICON_WARNING
- * @see SWT#ICON_WORKING
- *
- * @since 3.0
- */
-public Image getSystemImage (int id) {
- checkDevice ();
- switch(id) {
- case SWT.ICON_ERROR: {
- if (errorImage != null) return errorImage;
- NSImage nsImage = NSWorkspace.sharedWorkspace ().iconForFileType (new NSString (OS.NSFileTypeForHFSTypeCode (OS.kAlertStopIcon)));
- if (nsImage == null) return null;
- nsImage.retain ();
- return errorImage = Image.cocoa_new (this, SWT.ICON, nsImage);
- }
- case SWT.ICON_INFORMATION:
- case SWT.ICON_QUESTION:
- case SWT.ICON_WORKING: {
- if (infoImage != null) return infoImage;
- NSImage nsImage = NSWorkspace.sharedWorkspace ().iconForFileType (new NSString (OS.NSFileTypeForHFSTypeCode (OS.kAlertNoteIcon)));
- if (nsImage == null) return null;
- nsImage.retain ();
- return infoImage = Image.cocoa_new (this, SWT.ICON, nsImage);
- }
- case SWT.ICON_WARNING: {
- if (warningImage != null) return warningImage;
- NSImage nsImage = NSWorkspace.sharedWorkspace ().iconForFileType (new NSString (OS.NSFileTypeForHFSTypeCode (OS.kAlertCautionIcon)));
- if (nsImage == null) return null;
- nsImage.retain ();
- return warningImage = Image.cocoa_new (this, SWT.ICON, nsImage);
- }
- }
- return null;
-}
-
-/**
- * Returns the single instance of the system tray or null
- * when there is no system tray available for the platform.
- *
- * @return the system tray or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public Tray getSystemTray () {
- checkDevice ();
- if (tray != null) return tray;
- return tray = new Tray (this, SWT.NONE);
-}
-
-/**
- * Returns the user-interface thread for the receiver.
- *
- * @return the receiver's user-interface thread
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Thread getThread () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- return thread;
- }
-}
-
-int getToolTipTime () {
- checkDevice ();
- //TODO get OS value (NSTooltipManager?)
- return 560;
-}
-
-Widget getWidget (int /*long*/ id) {
- return GetWidget (id);
-}
-
-static Widget GetWidget (int /*long*/ id) {
- if (id == 0) return null;
- int /*long*/ [] jniRef = new int /*long*/ [1];
- OS.object_getInstanceVariable(id, SWT_OBJECT, jniRef);
- if (jniRef[0] == 0) return null;
- return (Widget)OS.JNIGetObject(jniRef[0]);
-}
-
-Widget getWidget (NSView view) {
- if (view == null) return null;
- return getWidget(view.id);
-}
-
-boolean hasDefaultButton () {
- NSArray windows = application.windows();
- int /*long*/ count = windows.count();
- for (int i = 0; i < count; i++) {
- NSWindow window = new NSWindow(windows.objectAtIndex(i));
- if (window.defaultButtonCell() != null) {
- return true;
- }
- }
- return false;
-}
-
-/**
- * Initializes any internal resources needed by the
- * device.
- * <p>
- * This method is called after <code>create</code>.
- * </p>
- *
- * @see #create
- */
-protected void init () {
- super.init ();
- initClasses ();
- initColors ();
- initFonts ();
-
- if (!isEmbedded) {
- /*
- * Feature in Cocoa: NSApplication.finishLaunching() adds an apple menu to the menu bar that isn't accessible via NSMenu.
- * If Display objects are created and disposed of multiple times in a single process, another apple menu is added to the menu bar.
- * It must be called or the dock icon will continue to bounce. So, it should only be called once per process, not just once per
- * creation of a Display. Use a static so creation of additional Display objects won't affect the menu bar.
- */
- if (!Display.launched) {
- application.finishLaunching();
- Display.launched = true;
-
- /* only add the shutdown hook once */
- Runtime.getRuntime().addShutdownHook(new Thread() {
- public void run() {
- NSApplication.sharedApplication().terminate(null);
- }
- });
- }
- }
-
- observerCallback = new Callback (this, "observerProc", 3); //$NON-NLS-1$
- int /*long*/ observerProc = observerCallback.getAddress ();
- if (observerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- int activities = OS.kCFRunLoopBeforeWaiting;
- runLoopObserver = OS.CFRunLoopObserverCreate (0, activities, true, 0, observerProc, 0);
- if (runLoopObserver == 0) error (SWT.ERROR_NO_HANDLES);
- OS.CFRunLoopAddObserver (OS.CFRunLoopGetCurrent (), runLoopObserver, OS.kCFRunLoopCommonModes ());
-
- cursorSetCallback = new Callback(this, "cursorSetProc", 2);
- int /*long*/ cursorSetProc = cursorSetCallback.getAddress();
- if (cursorSetProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- int /*long*/ method = OS.class_getInstanceMethod(OS.class_NSCursor, OS.sel_set);
- if (method != 0) oldCursorSetProc = OS.method_setImplementation(method, cursorSetProc);
-
- timerDelegate = (SWTWindowDelegate)new SWTWindowDelegate().alloc().init();
-
- settingsDelegate = (SWTWindowDelegate)new SWTWindowDelegate().alloc().init();
- NSNotificationCenter defaultCenter = NSNotificationCenter.defaultCenter();
- defaultCenter.addObserver(settingsDelegate, OS.sel_systemSettingsChanged_, OS.NSSystemColorsDidChangeNotification, null);
- defaultCenter.addObserver(settingsDelegate, OS.sel_systemSettingsChanged_, OS.NSApplicationDidChangeScreenParametersNotification, null);
-
- NSTextView textView = (NSTextView)new NSTextView().alloc();
- textView.init ();
- markedAttributes = textView.markedTextAttributes ();
- markedAttributes.retain ();
- textView.release ();
-
- isPainting = (NSMutableArray)new NSMutableArray().alloc();
- isPainting = isPainting.initWithCapacity(12);
-}
-
-void addEventMethods (int /*long*/ cls, int /*long*/ proc2, int /*long*/ proc3, int /*long*/ drawRectProc, int /*long*/ hitTestProc, int /*long*/ needsDisplayInRectProc) {
- if (proc3 != 0) {
- OS.class_addMethod(cls, OS.sel_mouseDown_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_mouseUp_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_scrollWheel_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_rightMouseDown_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_rightMouseUp_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_rightMouseDragged_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_otherMouseDown_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_otherMouseUp_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_otherMouseDragged_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_mouseDragged_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_mouseMoved_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_mouseEntered_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_mouseExited_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_menuForEvent_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_keyDown_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_keyUp_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_flagsChanged_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_cursorUpdate_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_setNeedsDisplay_, proc3, "@:B");
- OS.class_addMethod(cls, OS.sel_shouldDelayWindowOrderingForEvent_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_acceptsFirstMouse_, proc3, "@:@");
- }
- if (proc2 != 0) {
- OS.class_addMethod(cls, OS.sel_resignFirstResponder, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_becomeFirstResponder, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_resetCursorRects, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_updateTrackingAreas, proc2, "@:");
- }
- if (needsDisplayInRectProc != 0) {
- OS.class_addMethod(cls, OS.sel_setNeedsDisplayInRect_, needsDisplayInRectProc, "@:{NSRect}");
- }
- if (drawRectProc != 0) {
- OS.class_addMethod(cls, OS.sel_drawRect_, drawRectProc, "@:{NSRect}");
- }
- if (hitTestProc != 0) {
- OS.class_addMethod(cls, OS.sel_hitTest_, hitTestProc, "@:{NSPoint}");
- }
-}
-
-void addFrameMethods(int /*long*/ cls, int /*long*/ setFrameOriginProc, int /*long*/ setFrameSizeProc) {
- OS.class_addMethod(cls, OS.sel_setFrameOrigin_, setFrameOriginProc, "@:{NSPoint}");
- OS.class_addMethod(cls, OS.sel_setFrameSize_, setFrameSizeProc, "@:{NSSize}");
-}
-
-void addAccessibilityMethods(int /*long*/ cls, int /*long*/ proc2, int /*long*/ proc3, int /*long*/ proc4, int /*long*/ accessibilityHitTestProc) {
- OS.class_addMethod(cls, OS.sel_accessibilityActionNames, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_accessibilityAttributeNames, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_accessibilityParameterizedAttributeNames, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_accessibilityFocusedUIElement, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_accessibilityIsIgnored, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_accessibilityAttributeValue_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_accessibilityHitTest_, accessibilityHitTestProc, "@:{NSPoint}");
- OS.class_addMethod(cls, OS.sel_accessibilityAttributeValue_forParameter_, proc4, "@:@@");
- OS.class_addMethod(cls, OS.sel_accessibilityPerformAction_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_accessibilityActionDescription_, proc3, "@:@");
-}
-
-int /*long*/ registerCellSubclass(int /*long*/ cellClass, int size, int align, byte[] types) {
- String cellClassName = OS.class_getName(cellClass);
- int /*long*/ cls = OS.objc_allocateClassPair(cellClass, "SWTAccessible" + cellClassName, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.objc_registerClassPair(cls);
- return cls;
-}
-
-void initClasses () {
- if (OS.objc_lookUpClass ("SWTView") != 0) return;
-
- Class clazz = getClass ();
- dialogCallback3 = new Callback(clazz, "dialogProc", 3);
- int /*long*/ dialogProc3 = dialogCallback3.getAddress();
- if (dialogProc3 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- dialogCallback4 = new Callback(clazz, "dialogProc", 4);
- int /*long*/ dialogProc4 = dialogCallback4.getAddress();
- if (dialogProc4 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- dialogCallback5 = new Callback(clazz, "dialogProc", 5);
- int /*long*/ dialogProc5 = dialogCallback5.getAddress();
- if (dialogProc5 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- windowCallback3 = new Callback(clazz, "windowProc", 3);
- int /*long*/ proc3 = windowCallback3.getAddress();
- if (proc3 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- windowCallback2 = new Callback(clazz, "windowProc", 2);
- int /*long*/ proc2 = windowCallback2.getAddress();
- if (proc2 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- windowCallback4 = new Callback(clazz, "windowProc", 4);
- int /*long*/ proc4 = windowCallback4.getAddress();
- if (proc4 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- windowCallback5 = new Callback(clazz, "windowProc", 5);
- int /*long*/ proc5 = windowCallback5.getAddress();
- if (proc5 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- windowCallback6 = new Callback(clazz, "windowProc", 6);
- int /*long*/ proc6 = windowCallback6.getAddress();
- if (proc6 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- fieldEditorCallback3 = new Callback(clazz, "fieldEditorProc", 3);
- int /*long*/ fieldEditorProc3 = fieldEditorCallback3.getAddress();
- if (fieldEditorProc3 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- fieldEditorCallback4 = new Callback(clazz, "fieldEditorProc", 4);
- int /*long*/ fieldEditorProc4 = fieldEditorCallback4.getAddress();
- if (fieldEditorProc4 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- int /*long*/ isFlippedProc = OS.isFlipped_CALLBACK();
- int /*long*/ drawRectProc = OS.CALLBACK_drawRect_(proc3);
- int /*long*/ drawInteriorWithFrameInViewProc = OS.CALLBACK_drawInteriorWithFrame_inView_ (proc4);
- int /*long*/ drawWithExpansionFrameProc = OS.CALLBACK_drawWithExpansionFrame_inView_ (proc4);
- int /*long*/ imageRectForBoundsProc = OS.CALLBACK_imageRectForBounds_ (proc3);
- int /*long*/ titleRectForBoundsProc = OS.CALLBACK_titleRectForBounds_ (proc3);
- int /*long*/ hitTestForEvent_inRect_ofViewProc = OS.CALLBACK_hitTestForEvent_inRect_ofView_ (proc5);
- int /*long*/ cellSizeProc = OS.CALLBACK_cellSize (proc2);
- int /*long*/ drawImageWithFrameInViewProc = OS.CALLBACK_drawImage_withFrame_inView_ (proc5);
- int /*long*/ setFrameOriginProc = OS.CALLBACK_setFrameOrigin_(proc3);
- int /*long*/ setFrameSizeProc = OS.CALLBACK_setFrameSize_(proc3);
- int /*long*/ hitTestProc = OS.CALLBACK_hitTest_(proc3);
- int /*long*/ markedRangeProc = OS.CALLBACK_markedRange (proc2);
- int /*long*/ selectedRangeProc = OS.CALLBACK_selectedRange (proc2);
- int /*long*/ highlightSelectionInClipRectProc = OS.CALLBACK_highlightSelectionInClipRect_ (proc3);
- int /*long*/ setMarkedText_selectedRangeProc = OS.CALLBACK_setMarkedText_selectedRange_(proc4);
- int /*long*/ attributedSubstringFromRangeProc = OS.CALLBACK_attributedSubstringFromRange_(proc3);
- int /*long*/ characterIndexForPointProc = OS.CALLBACK_characterIndexForPoint_(proc3);
- int /*long*/ firstRectForCharacterRangeProc = OS.CALLBACK_firstRectForCharacterRange_(proc3);
- int /*long*/ textWillChangeSelectionProc = OS.CALLBACK_textView_willChangeSelectionFromCharacterRange_toCharacterRange_(proc5);
- int /*long*/ accessibilityHitTestProc = OS.CALLBACK_accessibilityHitTest_(proc3);
- int /*long*/ shouldChangeTextInRange_replacementString_Proc = OS.CALLBACK_shouldChangeTextInRange_replacementString_(fieldEditorProc4);
- int /*long*/ shouldChangeTextInRange_replacementString_fieldEditorProc = shouldChangeTextInRange_replacementString_Proc;
- int /*long*/ view_stringForToolTip_point_userDataProc = OS.CALLBACK_view_stringForToolTip_point_userData_(proc6);
- int /*long*/ canDragRowsWithIndexes_atPoint_Proc = OS.CALLBACK_canDragRowsWithIndexes_atPoint_(proc4);
- int /*long*/ setNeedsDisplayInRectProc = OS.CALLBACK_setNeedsDisplayInRect_(proc3);
- int /*long*/ expansionFrameWithFrameProc = OS.CALLBACK_expansionFrameWithFrame_inView_ (proc4);
-
- byte[] types = {'*','\0'};
- int size = C.PTR_SIZEOF, align = C.PTR_SIZEOF == 4 ? 2 : 3;
-
- String className;
- int /*long*/ cls;
-
- className = "SWTBox";
- cls = OS.objc_allocateClassPair(OS.class_NSBox, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.objc_registerClassPair(cls);
-
- className = "SWTButton";
- cls = OS.objc_allocateClassPair(OS.class_NSButton, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:");
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- OS.objc_registerClassPair(cls);
-
- cls = registerCellSubclass(NSButton.cellClass(), size, align, types);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.class_addMethod(cls, OS.sel_nextState, proc2, "@:");
- NSButton.setCellClass(cls);
-
- className = "SWTButtonCell";
- cls = OS.objc_allocateClassPair (OS.class_NSButtonCell, className, 0);
- OS.class_addIvar (cls, SWT_OBJECT, size, (byte)align, types);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.class_addMethod (cls, OS.sel_drawImage_withFrame_inView_, drawImageWithFrameInViewProc, "@:@{NSFrame}@");
- OS.class_addMethod(cls, OS.sel_cellSize, cellSizeProc, "@:");
- OS.class_addMethod(cls, OS.sel_drawInteriorWithFrame_inView_, drawInteriorWithFrameInViewProc, "@:{NSRect}@");
- OS.class_addMethod(cls, OS.sel_titleRectForBounds_, titleRectForBoundsProc, "@:{NSRect}");
- OS.objc_registerClassPair (cls);
-
- className = "SWTCanvasView";
- cls = OS.objc_allocateClassPair(OS.class_NSView, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- //NSTextInput protocol
- OS.class_addProtocol(cls, OS.objc_getProtocol("NSTextInput"));
- OS.class_addMethod(cls, OS.sel_hasMarkedText, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_markedRange, markedRangeProc, "@:");
- OS.class_addMethod(cls, OS.sel_selectedRange, selectedRangeProc, "@:");
- OS.class_addMethod(cls, OS.sel_setMarkedText_selectedRange_, setMarkedText_selectedRangeProc, "@:@{NSRange}");
- OS.class_addMethod(cls, OS.sel_unmarkText, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_validAttributesForMarkedText, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_attributedSubstringFromRange_, attributedSubstringFromRangeProc, "@:{NSRange}");
- OS.class_addMethod(cls, OS.sel_insertText_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_characterIndexForPoint_, characterIndexForPointProc, "@:{NSPoint}");
- OS.class_addMethod(cls, OS.sel_firstRectForCharacterRange_, firstRectForCharacterRangeProc, "@:{NSRange}");
- OS.class_addMethod(cls, OS.sel_doCommandBySelector_, proc3, "@::");
- //NSTextInput protocol end
- OS.class_addMethod(cls, OS.sel_canBecomeKeyView, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_isFlipped, isFlippedProc, "@:");
- OS.class_addMethod(cls, OS.sel_acceptsFirstResponder, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_isOpaque, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_updateOpenGLContext_, proc3, "@:@");
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.objc_registerClassPair(cls);
-
- className = "SWTComboBox";
- cls = OS.objc_allocateClassPair(OS.class_NSComboBox, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_textDidChange_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_textViewDidChangeSelection_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_, textWillChangeSelectionProc, "@:@{NSRange}{NSRange}");
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.objc_registerClassPair(cls);
-
- cls = registerCellSubclass(NSComboBox.cellClass(), size, align, types);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- NSComboBox.setCellClass(cls);
-
- className = "SWTDatePicker";
- cls = OS.objc_allocateClassPair(OS.class_NSDatePicker, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_isFlipped, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:");
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.objc_registerClassPair(cls);
-
- className = "SWTEditorView";
- cls = OS.objc_allocateClassPair(OS.class_NSTextView, className, 0);
- //TODO hitTestProc and drawRectProc should be set Control.setRegion()?
- addEventMethods(cls, 0, fieldEditorProc3, 0, 0, 0);
- OS.class_addMethod(cls, OS.sel_insertText_, fieldEditorProc3, "@:@");
- OS.class_addMethod(cls, OS.sel_doCommandBySelector_, fieldEditorProc3, "@::");
- OS.class_addMethod(cls, OS.sel_shouldChangeTextInRange_replacementString_, shouldChangeTextInRange_replacementString_fieldEditorProc, "@:{NSRange}@");
- OS.objc_registerClassPair(cls);
-
- className = "SWTImageView";
- cls = OS.objc_allocateClassPair(OS.class_NSImageView, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_isFlipped, isFlippedProc, "@:");
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.objc_registerClassPair(cls);
-
- cls = registerCellSubclass(NSImageView.cellClass(), size, align, types);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- NSImageView.setCellClass(cls);
-
- className = "SWTImageTextCell";
- cls = OS.objc_allocateClassPair (OS.class_NSTextFieldCell, className, 0);
- OS.class_addIvar (cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addIvar (cls, SWT_IMAGE, size, (byte)align, types);
- OS.class_addIvar (cls, SWT_ROW, size, (byte)align, types);
- OS.class_addIvar (cls, SWT_COLUMN, size, (byte)align, types);
- OS.class_addMethod (cls, OS.sel_drawInteriorWithFrame_inView_, drawInteriorWithFrameInViewProc, "@:{NSRect}@");
- OS.class_addMethod (cls, OS.sel_drawWithExpansionFrame_inView_, drawWithExpansionFrameProc, "@:{NSRect}@");
- OS.class_addMethod (cls, OS.sel_imageRectForBounds_, imageRectForBoundsProc, "@:{NSRect}");
- OS.class_addMethod (cls, OS.sel_titleRectForBounds_, titleRectForBoundsProc, "@:{NSRect}");
- OS.class_addMethod (cls, OS.sel_hitTestForEvent_inRect_ofView_, hitTestForEvent_inRect_ofViewProc, "@:@{NSRect}@");
- OS.class_addMethod (cls, OS.sel_cellSize, cellSizeProc, "@:");
- OS.class_addMethod (cls, OS.sel_image, proc2, "@:");
- OS.class_addMethod (cls, OS.sel_setImage_, proc3, "@:@");
- OS.class_addMethod (cls, OS.sel_expansionFrameWithFrame_inView_, expansionFrameWithFrameProc, "@:{NSRect}@");
- OS.objc_registerClassPair (cls);
-
- className = "SWTMenu";
- cls = OS.objc_allocateClassPair(OS.class_NSMenu, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_menuWillOpen_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_menuDidClose_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_menu_willHighlightItem_, proc4, "@:@@");
- OS.class_addMethod(cls, OS.sel_menuNeedsUpdate_, proc3, "@:@");
- OS.objc_registerClassPair(cls);
-
- className = "SWTMenuItem";
- cls = OS.objc_allocateClassPair(OS.class_NSMenuItem, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:");
- OS.objc_registerClassPair(cls);
-
- className = "SWTOutlineView";
- cls = OS.objc_allocateClassPair(OS.class_NSOutlineView, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_highlightSelectionInClipRect_, highlightSelectionInClipRectProc, "@:{NSRect}");
- OS.class_addMethod(cls, OS.sel_sendDoubleSelection, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_outlineViewSelectionDidChange_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_outlineView_child_ofItem_, proc5, "@:@i@");
- OS.class_addMethod(cls, OS.sel_outlineView_isItemExpandable_, proc4, "@:@@");
- OS.class_addMethod(cls, OS.sel_outlineView_numberOfChildrenOfItem_, proc4, "@:@@");
- OS.class_addMethod(cls, OS.sel_outlineView_objectValueForTableColumn_byItem_, proc5, "@:@@@");
- OS.class_addMethod(cls, OS.sel_outlineView_willDisplayCell_forTableColumn_item_, proc6, "@:@@@@");
- OS.class_addMethod(cls, OS.sel_outlineView_setObjectValue_forTableColumn_byItem_, proc6, "@:@@@@");
- OS.class_addMethod(cls, OS.sel_outlineViewColumnDidMove_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_outlineViewColumnDidResize_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_outlineView_didClickTableColumn_, proc4, "@:@@");
- OS.class_addMethod(cls, OS.sel_canDragRowsWithIndexes_atPoint_, canDragRowsWithIndexes_atPoint_Proc, "@:@{NSPoint=ff}");
- OS.class_addMethod(cls, OS.sel_outlineView_writeItems_toPasteboard_, proc5, "@:@@@");
- OS.class_addMethod(cls, OS.sel_expandItem_expandChildren_, proc4, "@:@Z");
- OS.class_addMethod(cls, OS.sel_collapseItem_collapseChildren_, proc4, "@:@Z");
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.objc_registerClassPair(cls);
-
- className = "SWTPanelDelegate";
- cls = OS.objc_allocateClassPair(OS.class_NSObject, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_windowWillClose_, dialogProc3, "@:@");
- OS.class_addMethod(cls, OS.sel_changeColor_, dialogProc3, "@:@");
- OS.class_addMethod(cls, OS.sel_changeFont_, dialogProc3, "@:@");
- OS.class_addMethod(cls, OS.sel_sendSelection_, dialogProc3, "@:@");
- OS.class_addMethod(cls, OS.sel_panel_shouldShowFilename_, dialogProc4, "@:@@");
- OS.class_addMethod(cls, OS.sel_panelDidEnd_returnCode_contextInfo_, dialogProc5, "@:@i@");
- OS.objc_registerClassPair(cls);
-
- className = "SWTPopUpButton";
- cls = OS.objc_allocateClassPair(OS.class_NSPopUpButton, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:");
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.objc_registerClassPair(cls);
-
- cls = registerCellSubclass(NSPopUpButton.cellClass(), size, align, types);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- NSPopUpButton.setCellClass(cls);
-
- className = "SWTProgressIndicator";
- cls = OS.objc_allocateClassPair(OS.class_NSProgressIndicator, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_viewDidMoveToWindow, proc2, "@:");
- OS.class_addMethod(cls, OS.sel__drawThemeProgressArea_, proc3, "@:c");
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.objc_registerClassPair(cls);
-
- className = "SWTScroller";
- cls = OS.objc_allocateClassPair(OS.class_NSScroller, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:");
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.objc_registerClassPair(cls);
-
- className = "SWTScrollView";
- cls = OS.objc_allocateClassPair(OS.class_NSScrollView, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_sendVerticalSelection, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_sendHorizontalSelection, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_pageDown_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_pageUp_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_reflectScrolledClipView_, proc3, "@:@");
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.objc_registerClassPair(cls);
-
- className = "SWTSearchField";
- cls = OS.objc_allocateClassPair(OS.class_NSSearchField, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.class_addMethod(cls, OS.sel_textDidChange_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_textViewDidChangeSelection_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_, textWillChangeSelectionProc, "@:@{NSRange}{NSRange}");
- OS.class_addMethod(cls, OS.sel_sendSearchSelection, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_sendCancelSelection, proc2, "@:");
- OS.objc_registerClassPair(cls);
-
- cls = registerCellSubclass(NSSearchField.cellClass(), size, align, types);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- NSSearchField.setCellClass(cls);
-
- // Don't subclass NSSecureTextFieldCell -- you'll get an NSException from [NSSecureTextField setCellClass:]!
- className = "SWTSecureTextField";
- cls = OS.objc_allocateClassPair(OS.class_NSSecureTextField, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.class_addMethod(cls, OS.sel_textDidChange_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_textViewDidChangeSelection_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_, textWillChangeSelectionProc, "@:@{NSRange}{NSRange}");
- OS.objc_registerClassPair(cls);
-
- className = "SWTSlider";
- cls = OS.objc_allocateClassPair(OS.class_NSSlider, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:");
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.objc_registerClassPair(cls);
-
- cls = registerCellSubclass(NSSlider.cellClass(), size, align, types);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- NSSlider.setCellClass(cls);
-
- className = "SWTStepper";
- cls = OS.objc_allocateClassPair(OS.class_NSStepper, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:");
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.objc_registerClassPair(cls);
-
- cls = registerCellSubclass(NSStepper.cellClass(), size, align, types);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- NSStepper.setCellClass(cls);
-
- className = "SWTTableHeaderCell";
- cls = OS.objc_allocateClassPair (OS.class_NSTableHeaderCell, className, 0);
- OS.class_addIvar (cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod (cls, OS.sel_drawInteriorWithFrame_inView_, drawInteriorWithFrameInViewProc, "@:{NSRect}@");
- OS.objc_registerClassPair (cls);
-
- className = "SWTTableHeaderView";
- cls = OS.objc_allocateClassPair(OS.class_NSTableHeaderView, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_mouseDown_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_resetCursorRects, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_updateTrackingAreas, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_menuForEvent_, proc3, "@:@");
- //TODO hitTestProc and drawRectProc should be set Control.setRegion()?
- OS.objc_registerClassPair(cls);
-
- className = "SWTTableView";
- cls = OS.objc_allocateClassPair(OS.class_NSTableView, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_highlightSelectionInClipRect_, highlightSelectionInClipRectProc, "@:{NSRect}");
- OS.class_addMethod(cls, OS.sel_sendDoubleSelection, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_numberOfRowsInTableView_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_tableView_objectValueForTableColumn_row_, proc5, "@:@:@:@");
- OS.class_addMethod(cls, OS.sel_tableView_shouldEditTableColumn_row_, proc5, "@:@:@:@");
- OS.class_addMethod(cls, OS.sel_tableViewSelectionDidChange_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_tableView_willDisplayCell_forTableColumn_row_, proc6, "@:@@@i");
- OS.class_addMethod(cls, OS.sel_tableView_setObjectValue_forTableColumn_row_, proc6, "@:@@@i");
- OS.class_addMethod(cls, OS.sel_tableViewColumnDidMove_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_tableViewColumnDidResize_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_tableView_didClickTableColumn_, proc4, "@:@");
- OS.class_addMethod(cls, OS.sel_canDragRowsWithIndexes_atPoint_, canDragRowsWithIndexes_atPoint_Proc, "@:@{NSPoint=ff}");
- OS.class_addMethod(cls, OS.sel_tableView_writeRowsWithIndexes_toPasteboard_, proc5, "@:@@@");
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.objc_registerClassPair(cls);
-
- className = "SWTTabView";
- cls = OS.objc_allocateClassPair(OS.class_NSTabView, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_tabView_willSelectTabViewItem_, proc4, "@:@@");
- OS.class_addMethod(cls, OS.sel_tabView_didSelectTabViewItem_, proc4, "@:@@");
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.objc_registerClassPair(cls);
-
- className = "SWTTextView";
- cls = OS.objc_allocateClassPair(OS.class_NSTextView, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.class_addMethod(cls, OS.sel_insertText_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_doCommandBySelector_, proc3, "@::");
- OS.class_addMethod(cls, OS.sel_textDidChange_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_textView_clickedOnLink_atIndex_, proc5, "@:@@@");
- OS.class_addMethod(cls, OS.sel_dragSelectionWithEvent_offset_slideBack_, proc5, "@:@@@");
- OS.class_addMethod(cls, OS.sel_shouldChangeTextInRange_replacementString_, shouldChangeTextInRange_replacementString_Proc, "@:{NSRange}@");
- OS.objc_registerClassPair(cls);
-
- className = "SWTTextField";
- cls = OS.objc_allocateClassPair(OS.class_NSTextField, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.class_addMethod(cls, OS.sel_acceptsFirstResponder, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_textDidChange_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_textDidEndEditing_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_textViewDidChangeSelection_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_, textWillChangeSelectionProc, "@:@{NSRange}{NSRange}");
- OS.objc_registerClassPair(cls);
-
- cls = registerCellSubclass(NSTextField.cellClass(), size, align, types);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- NSTextField.setCellClass(cls);
-
- className = "SWTTreeItem";
- cls = OS.objc_allocateClassPair(OS.class_NSObject, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.objc_registerClassPair(cls);
-
- className = "SWTView";
- cls = OS.objc_allocateClassPair(OS.class_NSView, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_canBecomeKeyView, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_isFlipped, isFlippedProc, "@:");
- OS.class_addMethod(cls, OS.sel_acceptsFirstResponder, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_isOpaque, proc2, "@:");
- addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc);
- addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.objc_registerClassPair(cls);
-
- className = "SWTWindow";
- cls = OS.objc_allocateClassPair(OS.class_NSWindow, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_sendEvent_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_helpRequested_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_canBecomeKeyWindow, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_becomeKeyWindow, proc2, "@:");
- OS.class_addMethod(cls, OS.sel_makeFirstResponder_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_noResponderFor_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_view_stringForToolTip_point_userData_, view_stringForToolTip_point_userDataProc, "@:@i{NSPoint}@");
- addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc);
- OS.objc_registerClassPair(cls);
-
- className = "SWTWindowDelegate";
- cls = OS.objc_allocateClassPair(OS.class_NSObject, className, 0);
- OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types);
- OS.class_addMethod(cls, OS.sel_windowDidResize_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_windowDidMove_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_windowShouldClose_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_windowWillClose_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_windowDidResignKey_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_windowDidBecomeKey_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_timerProc_, proc3, "@:@");
- OS.class_addMethod(cls, OS.sel_systemSettingsChanged_, proc3, "@:@");
- OS.objc_registerClassPair(cls);
-}
-
-NSFont getFont (int /*long*/ cls, int /*long*/ sel) {
- int /*long*/ widget = OS.objc_msgSend (OS.objc_msgSend (cls, OS.sel_alloc), OS.sel_initWithFrame_, new NSRect());
- int /*long*/ font = 0;
- if (OS.objc_msgSend_bool (widget, OS.sel_respondsToSelector_, sel)) {
- font = OS.objc_msgSend (widget, sel);
- }
- NSFont result = null;
- if (font != 0) {
- result = new NSFont (font);
- } else {
- result = NSFont.systemFontOfSize (NSFont.systemFontSizeForControlSize (OS.NSRegularControlSize));
- }
- result.retain ();
- OS.objc_msgSend (widget, OS.sel_release);
- return result;
-}
-
-void initColors () {
- colors = new float /*double*/ [SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT + 1][];
- colors[SWT.COLOR_INFO_FOREGROUND] = getWidgetColorRGB(SWT.COLOR_INFO_FOREGROUND);
- colors[SWT.COLOR_INFO_BACKGROUND] = getWidgetColorRGB(SWT.COLOR_INFO_BACKGROUND);
- colors[SWT.COLOR_TITLE_FOREGROUND] = getWidgetColorRGB(SWT.COLOR_TITLE_FOREGROUND);
- colors[SWT.COLOR_TITLE_BACKGROUND] = getWidgetColorRGB(SWT.COLOR_TITLE_BACKGROUND);
- colors[SWT.COLOR_TITLE_BACKGROUND_GRADIENT] = getWidgetColorRGB(SWT.COLOR_TITLE_BACKGROUND_GRADIENT);
- colors[SWT.COLOR_TITLE_INACTIVE_FOREGROUND] = getWidgetColorRGB(SWT.COLOR_TITLE_INACTIVE_FOREGROUND);
- colors[SWT.COLOR_TITLE_INACTIVE_BACKGROUND] = getWidgetColorRGB(SWT.COLOR_TITLE_INACTIVE_BACKGROUND);
- colors[SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT] = getWidgetColorRGB(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT);
- colors[SWT.COLOR_WIDGET_DARK_SHADOW] = getWidgetColorRGB(SWT.COLOR_WIDGET_DARK_SHADOW);
- colors[SWT.COLOR_WIDGET_NORMAL_SHADOW] = getWidgetColorRGB(SWT.COLOR_WIDGET_NORMAL_SHADOW);
- colors[SWT.COLOR_WIDGET_LIGHT_SHADOW] = getWidgetColorRGB(SWT.COLOR_WIDGET_LIGHT_SHADOW);
- colors[SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW] = getWidgetColorRGB(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
- colors[SWT.COLOR_WIDGET_BACKGROUND] = getWidgetColorRGB(SWT.COLOR_WIDGET_BACKGROUND);
- colors[SWT.COLOR_WIDGET_FOREGROUND] = getWidgetColorRGB(SWT.COLOR_WIDGET_FOREGROUND);
- colors[SWT.COLOR_WIDGET_BORDER] = getWidgetColorRGB(SWT.COLOR_WIDGET_BORDER);
- colors[SWT.COLOR_LIST_FOREGROUND] = getWidgetColorRGB(SWT.COLOR_LIST_FOREGROUND);
- colors[SWT.COLOR_LIST_BACKGROUND] = getWidgetColorRGB(SWT.COLOR_LIST_BACKGROUND);
- colors[SWT.COLOR_LIST_SELECTION_TEXT] = getWidgetColorRGB(SWT.COLOR_LIST_SELECTION_TEXT);
- colors[SWT.COLOR_LIST_SELECTION] = getWidgetColorRGB(SWT.COLOR_LIST_SELECTION);
-
- alternateSelectedControlColor = getWidgetColorRGB(NSColor.alternateSelectedControlColor());
- alternateSelectedControlTextColor = getWidgetColorRGB(NSColor.alternateSelectedControlTextColor());
- secondarySelectedControlColor = getWidgetColorRGB(NSColor.secondarySelectedControlColor());
- selectedControlTextColor = getWidgetColorRGB(NSColor.selectedControlTextColor());
-}
-
-void initFonts () {
- smallFonts = System.getProperty("org.eclipse.swt.internal.carbon.smallFonts") != null;
- buttonFont = getFont (OS.class_NSButton, OS.sel_font);
- popUpButtonFont = getFont (OS.class_NSPopUpButton, OS.sel_font);
- textFieldFont = getFont (OS.class_NSTextField, OS.sel_font);
- secureTextFieldFont = getFont (OS.class_NSSecureTextField, OS.sel_font);
- searchFieldFont = getFont (OS.class_NSSearchField, OS.sel_font);
- comboBoxFont = getFont (OS.class_NSComboBox, OS.sel_font);
- sliderFont = getFont (OS.class_NSSlider, OS.sel_font);
- scrollerFont = getFont (OS.class_NSScroller, OS.sel_font);
- textViewFont = getFont (OS.class_NSTextView, OS.sel_font);
- tableViewFont = getFont (OS.class_NSTableView, OS.sel_font);
- outlineViewFont = getFont (OS.class_NSOutlineView, OS.sel_font);
- datePickerFont = getFont (OS.class_NSDatePicker, OS.sel_font);
- boxFont = getFont (OS.class_NSBox, OS.sel_titleFont);
- tabViewFont = getFont (OS.class_NSTabView, OS.sel_font);
- progressIndicatorFont = getFont (OS.class_NSProgressIndicator, OS.sel_font);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Display</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for gc creation</li>
- * </ul>
- */
-public int /*long*/ internal_new_GC (GCData data) {
- if (isDisposed()) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
- if (screenWindow == null) {
- NSWindow window = (NSWindow) new NSWindow ().alloc ();
- NSRect rect = new NSRect();
- window = window.initWithContentRect(rect, OS.NSBorderlessWindowMask, OS.NSBackingStoreBuffered, false);
- window.setReleasedWhenClosed(false);
- screenWindow = window;
- }
- NSGraphicsContext context = screenWindow.graphicsContext();
-// NSAffineTransform transform = NSAffineTransform.transform();
-// NSSize size = handle.size();
-// transform.translateXBy(0, size.height);
-// transform.scaleXBy(1, -1);
-// transform.set();
- if (data != null) {
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) == 0) {
- data.style |= SWT.LEFT_TO_RIGHT;
- }
- data.device = this;
- data.background = getSystemColor(SWT.COLOR_WHITE).handle;
- data.foreground = getSystemColor(SWT.COLOR_BLACK).handle;
- data.font = getSystemFont();
- }
- return context.id;
-}
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Display</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int /*long*/ context, GCData data) {
- if (isDisposed()) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
-
-}
-
-static boolean isValidClass (Class clazz) {
- String name = clazz.getName ();
- int index = name.lastIndexOf ('.');
- return name.substring (0, index + 1).equals (PACKAGE_PREFIX);
-}
-
-boolean isValidThread () {
- return thread == Thread.currentThread ();
-}
-
-/**
- * Generate a low level system event.
- *
- * <code>post</code> is used to generate low level keyboard
- * and mouse events. The intent is to enable automated UI
- * testing by simulating the input from the user. Most
- * SWT applications should never need to call this method.
- * <p>
- * Note that this operation can fail when the operating system
- * fails to generate the event for any reason. For example,
- * this can happen when there is no such key or mouse button
- * or when the system event queue is full.
- * </p>
- * <p>
- * <b>Event Types:</b>
- * <p>KeyDown, KeyUp
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type KeyDown or KeyUp</li>
- * <p> Either one of:
- * <li>(in) character a character that corresponds to a keyboard key</li>
- * <li>(in) keyCode the key code of the key that was typed,
- * as defined by the key code constants in class <code>SWT</code></li>
- * </ul>
- * <p>MouseDown, MouseUp</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseDown or MouseUp
- * <li>(in) button the button that is pressed or released
- * </ul>
- * <p>MouseMove</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseMove
- * <li>(in) x the x coordinate to move the mouse pointer to in screen coordinates
- * <li>(in) y the y coordinate to move the mouse pointer to in screen coordinates
- * </ul>
- * <p>MouseWheel</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseWheel
- * <li>(in) detail either SWT.SCROLL_LINE or SWT.SCROLL_PAGE
- * <li>(in) count the number of lines or pages to scroll
- * </ul>
- * </dl>
- *
- * @param event the event to be generated
- *
- * @return true if the event was generated or false otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public boolean post(Event event) {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
-
- // TODO: Not sure if these calls have any effect on event posting.
- if (!eventSourceDelaySet) {
- OS.CGSetLocalEventsSuppressionInterval(0.0);
- OS.CGEnableEventStateCombining(1);
- OS.CGSetLocalEventsFilterDuringSuppressionState(OS.kCGEventFilterMaskPermitLocalKeyboardEvents | OS.kCGEventFilterMaskPermitLocalMouseEvents | OS.kCGEventFilterMaskPermitSystemDefinedEvents, OS.kCGEventSuppressionStateSuppressionInterval);
- OS.CGSetLocalEventsFilterDuringSuppressionState(OS.kCGEventFilterMaskPermitLocalKeyboardEvents | OS.kCGEventFilterMaskPermitLocalMouseEvents | OS.kCGEventFilterMaskPermitSystemDefinedEvents, OS.kCGEventSuppressionStateRemoteMouseDrag);
- eventSourceDelaySet = true;
- }
-
- int type = event.type;
- switch (type) {
- case SWT.KeyDown:
- case SWT.KeyUp: {
- short vKey = (short)Display.untranslateKey (event.keyCode);
- if (vKey == 0) {
- int /*long*/ uchrPtr = 0;
- int /*long*/ currentKbd = OS.TISCopyCurrentKeyboardInputSource();
- int /*long*/ uchrCFData = OS.TISGetInputSourceProperty(currentKbd, OS.kTISPropertyUnicodeKeyLayoutData());
-
- if (uchrCFData == 0) return false;
- uchrPtr = OS.CFDataGetBytePtr(uchrCFData);
- if (uchrPtr == 0) return false;
- if (OS.CFDataGetLength(uchrCFData) == 0) return false;
- int maxStringLength = 256;
- vKey = -1;
- char [] output = new char [maxStringLength];
- int [] actualStringLength = new int [1];
- for (short i = 0 ; i <= 0x7F ; i++) {
- OS.UCKeyTranslate (uchrPtr, i, (short)(type == SWT.KeyDown ? OS.kUCKeyActionDown : OS.kUCKeyActionUp), 0, OS.LMGetKbdType(), 0, deadKeyState, maxStringLength, actualStringLength, output);
- if (output[0] == event.character) {
- vKey = i;
- break;
- }
- }
- if (vKey == -1) {
- for (short i = 0 ; i <= 0x7F ; i++) {
- OS.UCKeyTranslate (uchrPtr, i, (short)(type == SWT.KeyDown ? OS.kUCKeyActionDown : OS.kUCKeyActionUp), OS.shiftKey, OS.LMGetKbdType(), 0, deadKeyState, maxStringLength, actualStringLength, output);
- if (output[0] == event.character) {
- vKey = i;
- break;
- }
- }
- }
- }
-
- /**
- * Bug(?) in UCKeyTranslate: If event.keyCode doesn't map to a valid SWT constant and event.characer is 0 we still need to post an event.
- * In Carbon, KeyTranslate eventually found a key that generated 0 but UCKeyTranslate never generates 0.
- * When that happens, post an event from key 127, which does nothing.
- */
- if (vKey == -1 && event.character == 0) {
- vKey = 127;
- }
-
- if (vKey == -1) return false;
-
- return OS.CGPostKeyboardEvent((short)0, vKey, type == SWT.KeyDown) == 0;
- }
- case SWT.MouseDown:
- case SWT.MouseMove:
- case SWT.MouseUp: {
- CGPoint mouseCursorPosition = new CGPoint ();
- int chord = OS.GetCurrentButtonState ();
-
- if (type == SWT.MouseMove) {
- mouseCursorPosition.x = event.x;
- mouseCursorPosition.y = event.y;
- return OS.CGPostMouseEvent (mouseCursorPosition, true, 5, (chord & 0x1) != 0, (chord & 0x2) != 0, (chord & 0x4) != 0, (chord & 0x8) != 0, (chord & 0x10) != 0) == 0;
- } else {
- int button = event.button;
- if (button < 1 || button > 5) return false;
- boolean button1 = false, button2 = false, button3 = false, button4 = false, button5 = false;
- switch (button) {
- case 1: {
- button1 = type == SWT.MouseDown;
- button2 = (chord & 0x4) != 0;
- button3 = (chord & 0x2) != 0;
- button4 = (chord & 0x8) != 0;
- button5 = (chord & 0x10) != 0;
- break;
- }
- case 2: {
- button1 = (chord & 0x1) != 0;
- button2 = type == SWT.MouseDown;
- button3 = (chord & 0x2) != 0;
- button4 = (chord & 0x8) != 0;
- button5 = (chord & 0x10) != 0;
- break;
- }
- case 3: {
- button1 = (chord & 0x1) != 0;
- button2 = (chord & 0x4) != 0;
- button3 = type == SWT.MouseDown;
- button4 = (chord & 0x8) != 0;
- button5 = (chord & 0x10) != 0;
- break;
- }
- case 4: {
- button1 = (chord & 0x1) != 0;
- button2 = (chord & 0x4) != 0;
- button3 = (chord & 0x2) != 0;
- button4 = type == SWT.MouseDown;
- button5 = (chord & 0x10) != 0;
- break;
- }
- case 5: {
- button1 = (chord & 0x1) != 0;
- button2 = (chord & 0x4) != 0;
- button3 = (chord & 0x2) != 0;
- button4 = (chord & 0x8) != 0;
- button5 = type == SWT.MouseDown;
- break;
- }
- }
-
- NSPoint nsCursorPosition = NSEvent.mouseLocation();
- NSRect primaryFrame = getPrimaryFrame();
- mouseCursorPosition.x = nsCursorPosition.x;
- mouseCursorPosition.y = (int) (primaryFrame.height - nsCursorPosition.y);
- return OS.CGPostMouseEvent (mouseCursorPosition, true, 5, button1, button3, button2, button4, button5) == 0;
- }
- }
- case SWT.MouseWheel: {
- return OS.CGPostScrollWheelEvent(1, event.count) == 0;
- }
- }
- return false;
- }
-}
-
-void postEvent (Event event) {
- /*
- * Place the event at the end of the event queue.
- * This code is always called in the Display's
- * thread so it must be re-enterant but does not
- * need to be synchronized.
- */
- if (eventQueue == null) eventQueue = new Event [4];
- int index = 0;
- int length = eventQueue.length;
- while (index < length) {
- if (eventQueue [index] == null) break;
- index++;
- }
- if (index == length) {
- Event [] newQueue = new Event [length + 4];
- System.arraycopy (eventQueue, 0, newQueue, 0, length);
- eventQueue = newQueue;
- }
- eventQueue [index] = event;
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param point to be mapped
- * @return point with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Point map (Control from, Control to, Point point) {
- checkDevice ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return map (from, to, point.x, point.y);
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param x coordinates to be mapped
- * @param y coordinates to be mapped
- * @return point with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Point map (Control from, Control to, int x, int y) {
- checkDevice ();
- if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- Point point = new Point (x, y);
- if (from == to) return point;
- NSPoint pt = new NSPoint();
- pt.x = x;
- pt.y = y;
- NSWindow fromWindow = from != null ? from.view.window() : null;
- NSWindow toWindow = to != null ? to.view.window() : null;
- if (toWindow != null && fromWindow != null && toWindow.id == fromWindow.id) {
- if (!from.view.isFlipped ()) {
- pt.y = from.view.bounds().height - pt.y;
- }
- pt = from.view.convertPoint_toView_(pt, to.view);
- if (!to.view.isFlipped ()) {
- pt.y = to.view.bounds().height - pt.y;
- }
- } else {
- NSRect primaryFrame = getPrimaryFrame();
- if (from != null) {
- NSView view = from.eventView ();
- if (!view.isFlipped ()) {
- pt.y = view.bounds().height - pt.y;
- }
- pt = view.convertPoint_toView_(pt, null);
- pt = fromWindow.convertBaseToScreen(pt);
- pt.y = primaryFrame.height - pt.y;
- }
- if (to != null) {
- NSView view = to.eventView ();
- pt.y = primaryFrame.height - pt.y;
- pt = toWindow.convertScreenToBase(pt);
- pt = view.convertPoint_fromView_(pt, null);
- if (!view.isFlipped ()) {
- pt.y = view.bounds().height - pt.y;
- }
- }
- }
- point.x = (int)pt.x;
- point.y = (int)pt.y;
- return point;
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param rectangle to be mapped
- * @return rectangle with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Rectangle map (Control from, Control to, Rectangle rectangle) {
- checkDevice ();
- if (rectangle == null) error (SWT.ERROR_NULL_ARGUMENT);
- return map (from, to, rectangle.x, rectangle.y, rectangle.width, rectangle.height);
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param x coordinates to be mapped
- * @param y coordinates to be mapped
- * @param width coordinates to be mapped
- * @param height coordinates to be mapped
- * @return rectangle with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Rectangle map (Control from, Control to, int x, int y, int width, int height) {
- checkDevice ();
- if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- Rectangle rectangle = new Rectangle (x, y, width, height);
- if (from == to) return rectangle;
- NSPoint pt = new NSPoint();
- pt.x = x;
- pt.y = y;
- NSWindow fromWindow = from != null ? from.view.window() : null;
- NSWindow toWindow = to != null ? to.view.window() : null;
- if (toWindow != null && fromWindow != null && toWindow.id == fromWindow.id) {
- if (!from.view.isFlipped ()) {
- pt.y = from.view.bounds().height - pt.y;
- }
- pt = from.view.convertPoint_toView_(pt, to.view);
- if (!to.view.isFlipped ()) {
- pt.y = to.view.bounds().height - pt.y;
- }
- } else {
- NSRect primaryFrame = getPrimaryFrame();
- if (from != null) {
- NSView view = from.eventView ();
- if (!view.isFlipped ()) {
- pt.y = view.bounds().height - pt.y;
- }
- pt = view.convertPoint_toView_(pt, null);
- pt = fromWindow.convertBaseToScreen(pt);
- pt.y = primaryFrame.height - pt.y;
- }
- if (to != null) {
- NSView view = to.eventView ();
- pt.y = primaryFrame.height - pt.y;
- pt = toWindow.convertScreenToBase(pt);
- pt = view.convertPoint_fromView_(pt, null);
- if (!view.isFlipped ()) {
- pt.y = view.bounds().height - pt.y;
- }
- }
- }
- rectangle.x = (int)pt.x;
- rectangle.y = (int)pt.y;
- return rectangle;
-}
-
-int /*long*/ observerProc (int /*long*/ observer, int /*long*/ activity, int /*long*/ info) {
- switch ((int)/*64*/activity) {
- case OS.kCFRunLoopBeforeWaiting:
- if (runAsyncMessages) {
- if (runAsyncMessages (false)) wakeThread ();
- }
- break;
- }
- return 0;
-}
-
-/**
- * Reads an event from the operating system's event queue,
- * dispatches it appropriately, and returns <code>true</code>
- * if there is potentially more work to do, or <code>false</code>
- * if the caller can sleep until another event is placed on
- * the event queue.
- * <p>
- * In addition to checking the system event queue, this method also
- * checks if any inter-thread messages (created by <code>syncExec()</code>
- * or <code>asyncExec()</code>) are waiting to be processed, and if
- * so handles them before returning.
- * </p>
- *
- * @return <code>false</code> if the caller can sleep upon return from this method
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li>
- * </ul>
- *
- * @see #sleep
- * @see #wake
- */
-public boolean readAndDispatch () {
- checkDevice ();
- if (sendEventCount == 0 && loopCount == poolCount - 1 && Callback.getEntryCount () == 0) removePool ();
- addPool ();
- loopCount++;
- boolean events = false;
- try {
- events |= runSettings ();
- events |= runTimers ();
- events |= runContexts ();
- events |= runPopups ();
- NSEvent event = application.nextEventMatchingMask(0, null, OS.NSDefaultRunLoopMode, true);
- if (event != null) {
- events = true;
- application.sendEvent(event);
- }
- events |= runPaint ();
- events |= runDeferredEvents ();
- if (!events) {
- events = isDisposed () || runAsyncMessages (false);
- }
- } finally {
- removePool ();
- loopCount--;
- if (sendEventCount == 0 && loopCount == poolCount && Callback.getEntryCount () == 0) addPool ();
- }
- return events;
-}
-
-static void register (Display display) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] == null) {
- Displays [i] = display;
- return;
- }
- }
- Display [] newDisplays = new Display [Displays.length + 4];
- System.arraycopy (Displays, 0, newDisplays, 0, Displays.length);
- newDisplays [Displays.length] = display;
- Displays = newDisplays;
- }
-}
-
-/**
- * Releases any internal resources back to the operating
- * system and clears all fields except the device handle.
- * <p>
- * Disposes all shells which are currently open on the display.
- * After this method has been invoked, all related related shells
- * will answer <code>true</code> when sent the message
- * <code>isDisposed()</code>.
- * </p><p>
- * When a device is destroyed, resources that were acquired
- * on behalf of the programmer need to be returned to the
- * operating system. For example, if the device allocated a
- * font to be used as the system font, this font would be
- * freed in <code>release</code>. Also,to assist the garbage
- * collector and minimize the amount of memory that is not
- * reclaimed when the programmer keeps a reference to a
- * disposed device, all fields except the handle are zero'd.
- * The handle is needed by <code>destroy</code>.
- * </p>
- * This method is called before <code>destroy</code>.
- *
- * @see Device#dispose
- * @see #destroy
- */
-protected void release () {
- disposing = true;
- sendEvent (SWT.Dispose, new Event ());
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) shell.dispose ();
- }
- if (tray != null) tray.dispose ();
- tray = null;
- while (readAndDispatch ()) {}
- if (disposeList != null) {
- for (int i=0; i<disposeList.length; i++) {
- if (disposeList [i] != null) disposeList [i].run ();
- }
- }
- disposeList = null;
- synchronizer.releaseSynchronizer ();
- synchronizer = null;
- releaseDisplay ();
- super.release ();
-}
-
-void releaseDisplay () {
- /* Release the System Images */
- if (errorImage != null) errorImage.dispose ();
- if (infoImage != null) infoImage.dispose ();
- if (warningImage != null) warningImage.dispose ();
- errorImage = infoImage = warningImage = null;
-
- currentCaret = null;
-
- /* Release Timers */
- if (hoverTimer != null) timerExec(-1, hoverTimer);
- hoverTimer = null;
- if (caretTimer != null) timerExec(-1, caretTimer);
- caretTimer = null;
- if (nsTimers != null) {
- for (int i=0; i<nsTimers.length; i++) {
- if (nsTimers [i] != null) {
- nsTimers [i].invalidate();
- nsTimers [i].release();
- }
- }
- }
- nsTimers = null;
- if (timerDelegate != null) timerDelegate.release();
- timerDelegate = null;
-
- /* Release the System Cursors */
- for (int i = 0; i < cursors.length; i++) {
- if (cursors [i] != null) cursors [i].dispose ();
- }
- cursors = null;
-
- /* Release default fonts */
- if (buttonFont != null) buttonFont.release ();
- if (popUpButtonFont != null) popUpButtonFont.release ();
- if (textFieldFont != null) textFieldFont.release ();
- if (secureTextFieldFont != null) secureTextFieldFont.release ();
- if (searchFieldFont != null) searchFieldFont.release ();
- if (comboBoxFont != null) comboBoxFont.release ();
- if (sliderFont != null) sliderFont.release ();
- if (scrollerFont != null) scrollerFont.release ();
- if (textViewFont != null) textViewFont.release ();
- if (tableViewFont != null) tableViewFont.release ();
- if (outlineViewFont != null) outlineViewFont.release ();
- if (datePickerFont != null) datePickerFont.release ();
- if (boxFont != null) boxFont.release ();
- if (tabViewFont != null) tabViewFont.release ();
- if (progressIndicatorFont != null) progressIndicatorFont.release ();
- buttonFont = popUpButtonFont = textFieldFont = secureTextFieldFont = null;
- searchFieldFont = comboBoxFont = sliderFont = scrollerFont;
- textViewFont = tableViewFont = outlineViewFont = datePickerFont = null;
- boxFont = tabViewFont = progressIndicatorFont = null;
-
- /* Release Dock image */
- if (dockImage != null) dockImage.release();
- dockImage = null;
-
- if (screenWindow != null) screenWindow.release();
- screenWindow = null;
-
- if (needsDisplay != null) needsDisplay.release();
- if (needsDisplayInRect != null) needsDisplayInRect.release();
- if (isPainting != null) isPainting.release();
- needsDisplay = needsDisplayInRect = isPainting = null;
-
- modalShells = null;
- menuBar = null;
- menus = null;
-
- if (markedAttributes != null) markedAttributes.release();
- markedAttributes = null;
-
- if (oldCursorSetProc != 0) {
- int /*long*/ method = OS.class_getInstanceMethod(OS.class_NSCursor, OS.sel_set);
- OS.method_setImplementation(method, oldCursorSetProc);
- }
- if (cursorSetCallback != null) cursorSetCallback.dispose();
- cursorSetCallback = null;
-
- deadKeyState = null;
-
- if (settingsDelegate != null) {
- NSNotificationCenter.defaultCenter().removeObserver(settingsDelegate);
- settingsDelegate.release();
- }
- settingsDelegate = null;
-
- // Clear the menu bar if we created it.
- if (!isEmbedded) {
- //remove all existing menu items except the application menu
- NSMenu menubar = application.mainMenu();
- int /*long*/ count = menubar.numberOfItems();
- while (count > 1) {
- menubar.removeItemAtIndex(count - 1);
- count--;
- }
- }
-
- // The autorelease pool is cleaned up when we call NSApplication.terminate().
-
- if (application != null && applicationClass != 0) {
- OS.object_setClass (application.id, applicationClass);
- }
- application = null;
- applicationClass = 0;
-
- if (runLoopObserver != 0) {
- OS.CFRunLoopObserverInvalidate (runLoopObserver);
- OS.CFRelease (runLoopObserver);
- }
- runLoopObserver = 0;
- if (observerCallback != null) observerCallback.dispose();
- observerCallback = null;
-}
-
-void removeContext (GCData context) {
- if (contexts == null) return;
- int count = 0;
- for (int i = 0; i < contexts.length; i++) {
- if (contexts[i] != null) {
- if (contexts [i] == context) {
- contexts[i] = null;
- } else {
- count++;
- }
- }
- }
- if (count == 0) contexts = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs anywhere in
- * a widget. The event type is one of the event constants defined
- * in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addFilter
- * @see #addListener
- *
- * @since 3.0
- */
-public void removeFilter (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (filterTable == null) return;
- filterTable.unhook (eventType, listener);
- if (filterTable.size () == 0) filterTable = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs. The event type
- * is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener
- *
- * @since 2.0
- */
-public void removeListener (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, listener);
-}
-
-Widget removeWidget (NSObject view) {
- if (view == null) return null;
- int /*long*/ [] jniRef = new int /*long*/ [1];
- OS.object_getInstanceVariable(view.id, SWT_OBJECT, jniRef);
- if (jniRef[0] == 0) return null;
- Widget widget = (Widget)OS.JNIGetObject(jniRef[0]);
- OS.object_setInstanceVariable(view.id, SWT_OBJECT, 0);
- return widget;
-}
-
-void removeMenu (Menu menu) {
- if (menus == null) return;
- for (int i = 0; i < menus.length; i++) {
- if (menus [i] == menu) {
- menus[i] = null;
- break;
- }
- }
-}
-
-void removePool () {
- NSAutoreleasePool pool = pools [poolCount - 1];
- pools [--poolCount] = null;
- if (poolCount == 0) {
- NSMutableDictionary dictionary = NSThread.currentThread().threadDictionary();
- dictionary.removeObjectForKey(NSString.stringWith("SWT_NSAutoreleasePool"));
- }
- pool.release ();
-}
-
-void removePopup (Menu menu) {
- if (popups == null) return;
- for (int i=0; i<popups.length; i++) {
- if (popups [i] == menu) {
- popups [i] = null;
- return;
- }
- }
-}
-
-boolean runAsyncMessages (boolean all) {
- return synchronizer.runAsyncMessages (all);
-}
-
-boolean runContexts () {
- if (contexts != null) {
- for (int i = 0; i < contexts.length; i++) {
- if (contexts[i] != null && contexts[i].flippedContext != null) {
- contexts[i].flippedContext.flushGraphics();
- }
- }
- }
- return false;
-}
-
-boolean runDeferredEvents () {
- boolean run = false;
- /*
- * Run deferred events. This code is always
- * called in the Display's thread so it must
- * be re-enterant need not be synchronized.
- */
- while (eventQueue != null) {
-
- /* Take an event off the queue */
- Event event = eventQueue [0];
- if (event == null) break;
- int length = eventQueue.length;
- System.arraycopy (eventQueue, 1, eventQueue, 0, --length);
- eventQueue [length] = null;
-
- /* Run the event */
- Widget widget = event.widget;
- if (widget != null && !widget.isDisposed ()) {
- Widget item = event.item;
- if (item == null || !item.isDisposed ()) {
- run = true;
- widget.notifyListeners (event.type, event);
- }
- }
-
- /*
- * At this point, the event queue could
- * be null due to a recursive invokation
- * when running the event.
- */
- }
-
- /* Clear the queue */
- eventQueue = null;
- return run;
-}
-
-boolean runPaint () {
- if (needsDisplay == null && needsDisplayInRect == null) return false;
- if (needsDisplay != null) {
- int /*long*/ count = needsDisplay.count();
- for (int i = 0; i < count; i++) {
- OS.objc_msgSend(needsDisplay.objectAtIndex(i).id, OS.sel_setNeedsDisplay_, true);
- }
- needsDisplay.release();
- needsDisplay = null;
- }
- if (needsDisplayInRect != null) {
- int /*long*/ count = needsDisplayInRect.count();
- for (int i = 0; i < count; i+=2) {
- NSValue value = new NSValue(needsDisplayInRect.objectAtIndex(i+1));
- OS.objc_msgSend(needsDisplayInRect.objectAtIndex(i).id, OS.sel_setNeedsDisplayInRect_, value.rectValue());
- }
- needsDisplayInRect.release();
- needsDisplayInRect = null;
- }
- return true;
-}
-
-boolean runPopups () {
- if (popups == null) return false;
- boolean result = false;
- while (popups != null) {
- Menu menu = popups [0];
- if (menu == null) break;
- runDeferredEvents ();
- int length = popups.length;
- System.arraycopy (popups, 1, popups, 0, --length);
- popups [length] = null;
- if (!menu.isDisposed ()) menu._setVisible (true);
- result = true;
- }
- popups = null;
- return result;
-}
-
-boolean runSettings () {
- if (!runSettings) return false;
- runSettings = false;
- initColors ();
- sendEvent (SWT.Settings, null);
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) {
- shell.redraw (true);
- shell.layout (true, true);
- }
- }
- return true;
-}
-
-boolean runTimers () {
- if (timerList == null) return false;
- boolean result = false;
- for (int i=0; i<timerList.length; i++) {
- if (nsTimers [i] == null && timerList [i] != null) {
- Runnable runnable = timerList [i];
- timerList [i] = null;
- if (runnable != null) {
- result = true;
- runnable.run ();
- }
- }
- }
- return result;
-}
-
-void sendEvent (int eventType, Event event) {
- if (eventTable == null && filterTable == null) {
- return;
- }
- if (event == null) event = new Event ();
- event.display = this;
- event.type = eventType;
- if (event.time == 0) event.time = getLastEventTime ();
- sendEvent(eventTable, event);
-}
-
-void sendEvent (EventTable table, Event event) {
- try {
- sendEventCount++;
- if (!filterEvent (event)) {
- if (table != null) table.sendEvent (event);
- }
- } finally {
- sendEventCount--;
- }
-}
-
-static NSString getAppName() {
- NSString name = null;
- int pid = OS.getpid ();
- int /*long*/ ptr = OS.getenv (ascii ("APP_NAME_" + pid));
- if (ptr != 0) name = NSString.stringWithUTF8String(ptr);
- if (name == null && APP_NAME != null) name = NSString.stringWith(APP_NAME);
- if (name == null) {
- id value = NSBundle.mainBundle().objectForInfoDictionaryKey(NSString.stringWith("CFBundleName"));
- if (value != null) {
- name = new NSString(value);
- }
- }
- if (name == null) name = NSString.stringWith("SWT");
- return name;
-}
-
-/**
- * On platforms which support it, sets the application name
- * to be the argument. On Motif, for example, this can be used
- * to set the name used for resource lookup. Specifying
- * <code>null</code> for the name clears it.
- *
- * @param name the new app name or <code>null</code>
- */
-public static void setAppName (String name) {
- APP_NAME = name;
-}
-
-//TODO use custom timer instead of timerExec
-Runnable hoverTimer = new Runnable () {
- public void run () {
- if (currentControl != null && !currentControl.isDisposed()) {
- currentControl.sendMouseEvent (NSApplication.sharedApplication().currentEvent(), SWT.MouseHover, trackingControl != null && !trackingControl.isDisposed());
- }
- }
-};
-//TODO - use custom timer instead of timerExec
-Runnable caretTimer = new Runnable () {
- public void run () {
- if (currentCaret != null) {
- if (currentCaret == null || currentCaret.isDisposed()) return;
- if (currentCaret.blinkCaret ()) {
- int blinkRate = currentCaret.blinkRate;
- if (blinkRate != 0) timerExec (blinkRate, this);
- } else {
- currentCaret = null;
- }
- }
-
- }
-};
-
-//TODO - use custom timer instead of timerExec
-Runnable defaultButtonTimer = new Runnable() {
- public void run() {
- if (isDisposed ()) return;
- Shell shell = getActiveShell();
- if (shell != null && !shell.isDisposed()) {
- Button defaultButton = shell.defaultButton;
- if (defaultButton != null && !defaultButton.isDisposed()) {
- NSView view = defaultButton.view;
- view.display();
- }
- }
- if (isDisposed ()) return;
- if (hasDefaultButton()) timerExec(DEFAULT_BUTTON_INTERVAL, this);
- }
-};
-
-void setCurrentCaret (Caret caret) {
- currentCaret = caret;
- int blinkRate = currentCaret != null ? currentCaret.blinkRate : -1;
- timerExec (blinkRate, caretTimer);
-}
-
-void setCursor (Control control) {
- Cursor cursor = null;
- if (control != null && !control.isDisposed()) cursor = control.findCursor ();
- if (cursor == null) {
- NSWindow window = application.keyWindow();
- if (window != null) {
- if (window.areCursorRectsEnabled ()) {
- window.disableCursorRects ();
- window.enableCursorRects ();
- }
- return;
- }
- cursor = getSystemCursor (SWT.CURSOR_ARROW);
- }
- lockCursor = false;
- cursor.handle.set ();
- lockCursor = true;
-}
-
-/**
- * Sets the location of the on-screen pointer relative to the top left corner
- * of the screen. <b>Note: It is typically considered bad practice for a
- * program to move the on-screen pointer location.</b>
- *
- * @param x the new x coordinate for the cursor
- * @param y the new y coordinate for the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1
- */
-public void setCursorLocation (int x, int y) {
- checkDevice ();
- CGPoint pt = new CGPoint ();
- pt.x = x; pt.y = y;
- OS.CGWarpMouseCursorPosition (pt);
-}
-
-/**
- * Sets the location of the on-screen pointer relative to the top left corner
- * of the screen. <b>Note: It is typically considered bad practice for a
- * program to move the on-screen pointer location.</b>
- *
- * @param point new position
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_NULL_ARGUMENT - if the point is null
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setCursorLocation (Point point) {
- checkDevice ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- setCursorLocation (point.x, point.y);
-}
-
-/**
- * Sets the application defined property of the receiver
- * with the specified name to the given argument.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the display is disposed
- * of, it is the application's responsibility provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param key the name of the property
- * @param value the new value for the property
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getData(String)
- * @see #disposeExec(Runnable)
- */
-public void setData (String key, Object value) {
- checkDevice ();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
-
- if (key.equals (ADD_WIDGET_KEY)) {
- Object [] data = (Object [])value;
- NSObject object = (NSObject)data [0];
- Widget widget = (Widget)data [1];
- if (widget == null) {
- removeWidget (object);
- } else {
- addWidget (object, widget);
- }
- }
-
- /* Remove the key/value pair */
- if (value == null) {
- if (keys == null) return;
- int index = 0;
- while (index < keys.length && !keys [index].equals (key)) index++;
- if (index == keys.length) return;
- if (keys.length == 1) {
- keys = null;
- values = null;
- } else {
- String [] newKeys = new String [keys.length - 1];
- Object [] newValues = new Object [values.length - 1];
- System.arraycopy (keys, 0, newKeys, 0, index);
- System.arraycopy (keys, index + 1, newKeys, index, newKeys.length - index);
- System.arraycopy (values, 0, newValues, 0, index);
- System.arraycopy (values, index + 1, newValues, index, newValues.length - index);
- keys = newKeys;
- values = newValues;
- }
- return;
- }
-
- /* Add the key/value pair */
- if (keys == null) {
- keys = new String [] {key};
- values = new Object [] {value};
- return;
- }
- for (int i=0; i<keys.length; i++) {
- if (keys [i].equals (key)) {
- values [i] = value;
- return;
- }
- }
- String [] newKeys = new String [keys.length + 1];
- Object [] newValues = new Object [values.length + 1];
- System.arraycopy (keys, 0, newKeys, 0, keys.length);
- System.arraycopy (values, 0, newValues, 0, values.length);
- newKeys [keys.length] = key;
- newValues [values.length] = value;
- keys = newKeys;
- values = newValues;
-}
-
-void setMenuBar (Menu menu) {
- if (menu == menuBar) return;
- menuBar = menu;
- //remove all existing menu items except the application menu
- NSMenu menubar = application.mainMenu();
- /*
- * For some reason, NSMenu.cancelTracking() does not dismisses
- * the menu right away when the menu bar is set in a stacked
- * event loop. The fix is to use CancelMenuTracking() instead.
- */
-// menubar.cancelTracking();
- OS.CancelMenuTracking (OS.AcquireRootMenu (), true, 0);
- int /*long*/ count = menubar.numberOfItems();
- while (count > 1) {
- menubar.removeItemAtIndex(count - 1);
- count--;
- }
- //set parent of each item to NULL and add them to menubar
- if (menu != null) {
- MenuItem[] items = menu.getItems();
- for (int i = 0; i < items.length; i++) {
- MenuItem item = items[i];
- NSMenuItem nsItem = item.nsItem;
- nsItem.setMenu(null);
- menubar.addItem(nsItem);
-
- /*
- * Bug in Cocoa: Calling NSMenuItem.setEnabled() for menu item of a menu bar only
- * works when the menu bar is the current menu bar. The underline OS menu does get
- * enabled/disable when that menu is set later on. The fix is to toggle the
- * item enabled state to force the underline menu to be updated.
- */
- boolean enabled = menu.getEnabled () && item.getEnabled ();
- nsItem.setEnabled(!enabled);
- nsItem.setEnabled(enabled);
- }
- }
-}
-
-void setModalShell (Shell shell) {
- if (modalShells == null) modalShells = new Shell [4];
- int index = 0, length = modalShells.length;
- while (index < length) {
- if (modalShells [index] == shell) return;
- if (modalShells [index] == null) break;
- index++;
- }
- if (index == length) {
- Shell [] newModalShells = new Shell [length + 4];
- System.arraycopy (modalShells, 0, newModalShells, 0, length);
- modalShells = newModalShells;
- }
- modalShells [index] = shell;
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) shells [i].updateModal ();
-}
-
-/**
- * Sets the application defined, display specific data
- * associated with the receiver, to the argument.
- * The <em>display specific data</em> is a single,
- * unnamed field that is stored with every display.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the display specific data needs to
- * be notified when the display is disposed of, it is the
- * application's responsibility provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param data the new display specific data
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getData()
- * @see #disposeExec(Runnable)
- */
-public void setData (Object data) {
- checkDevice ();
- this.data = data;
-}
-
-/**
- * Sets the synchronizer used by the display to be
- * the argument, which can not be null.
- *
- * @param synchronizer the new synchronizer for the display (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the synchronizer is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li>
- * </ul>
- */
-public void setSynchronizer (Synchronizer synchronizer) {
- checkDevice ();
- if (synchronizer == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (synchronizer == this.synchronizer) return;
- Synchronizer oldSynchronizer;
- synchronized (Device.class) {
- oldSynchronizer = this.synchronizer;
- this.synchronizer = synchronizer;
- }
- if (oldSynchronizer != null) {
- oldSynchronizer.runAsyncMessages(true);
- }
-}
-
-/**
- * Causes the user-interface thread to <em>sleep</em> (that is,
- * to be put in a state where it does not consume CPU cycles)
- * until an event is received or it is otherwise awakened.
- *
- * @return <code>true</code> if an event requiring dispatching was placed on the queue.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #wake
- */
-public boolean sleep () {
- checkDevice ();
- if (getMessageCount () != 0) return true;
- try {
- addPool();
- allowTimers = runAsyncMessages = false;
- NSRunLoop.currentRunLoop().runMode(OS.NSDefaultRunLoopMode, NSDate.distantFuture());
- allowTimers = runAsyncMessages = true;
- } finally {
- removePool();
- }
- return true;
-}
-
-int sourceProc (int info) {
- return 0;
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread at the next
- * reasonable opportunity. The thread which calls this method
- * is suspended until the runnable completes. Specifying <code>null</code>
- * as the runnable simply wakes the user-interface thread.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param runnable code to run on the user-interface thread or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_FAILED_EXEC - if an exception occurred when executing the runnable</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #asyncExec
- */
-public void syncExec (Runnable runnable) {
- Synchronizer synchronizer;
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- synchronizer = this.synchronizer;
- }
- synchronizer.syncExec (runnable);
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread after the specified
- * number of milliseconds have elapsed. If milliseconds is less
- * than zero, the runnable is not executed.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param milliseconds the delay before running the runnable
- * @param runnable code to run on the user-interface thread
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #asyncExec
- */
-public void timerExec (int milliseconds, Runnable runnable) {
- checkDevice ();
- //TODO - remove a timer, reschedule a timer not tested
- if (runnable == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (timerList == null) timerList = new Runnable [4];
- if (nsTimers == null) nsTimers = new NSTimer [4];
- int index = 0;
- while (index < timerList.length) {
- if (timerList [index] == runnable) break;
- index++;
- }
- if (index != timerList.length) {
- NSTimer timer = nsTimers [index];
- if (timer == null) {
- timerList [index] = null;
- } else {
- if (milliseconds < 0) {
- timer.invalidate();
- timer.release();
- timerList [index] = null;
- nsTimers [index] = null;
- } else {
- timer.setFireDate(NSDate.dateWithTimeIntervalSinceNow (milliseconds / 1000.0));
- }
- return;
- }
- }
- if (milliseconds < 0) return;
- index = 0;
- while (index < timerList.length) {
- if (timerList [index] == null) break;
- index++;
- }
- if (index == timerList.length) {
- Runnable [] newTimerList = new Runnable [timerList.length + 4];
- System.arraycopy (timerList, 0, newTimerList, 0, timerList.length);
- timerList = newTimerList;
- NSTimer [] newTimerIds = new NSTimer [nsTimers.length + 4];
- System.arraycopy (nsTimers, 0, newTimerIds, 0, nsTimers.length);
- nsTimers = newTimerIds;
- }
- NSNumber userInfo = NSNumber.numberWithInt(index);
- NSTimer timer = NSTimer.scheduledTimerWithTimeInterval(milliseconds / 1000.0, timerDelegate, OS.sel_timerProc_, userInfo, false);
- NSRunLoop.currentRunLoop().addTimer(timer, OS.NSEventTrackingRunLoopMode);
- timer.retain();
- if (timer != null) {
- nsTimers [index] = timer;
- timerList [index] = runnable;
- }
-}
-
-int /*long*/ timerProc (int /*long*/ id, int /*long*/ sel, int /*long*/ timerID) {
- NSTimer timer = new NSTimer (timerID);
- NSNumber number = new NSNumber(timer.userInfo());
- int index = number.intValue();
- if (timerList == null) return 0;
- if (0 <= index && index < timerList.length) {
- if (allowTimers) {
- Runnable runnable = timerList [index];
- timerList [index] = null;
- nsTimers [index] = null;
- if (runnable != null) runnable.run ();
- } else {
- nsTimers [index] = null;
- wakeThread ();
- }
- }
- timer.invalidate();
- timer.release();
- return 0;
-}
-
-/**
- * Forces all outstanding paint requests for the display
- * to be processed before this method returns.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Control#update()
- */
-public void update () {
- checkDevice ();
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) shell.update (true);
- }
-}
-
-void updateDefaultButton () {
- timerExec(hasDefaultButton() ? DEFAULT_BUTTON_INTERVAL : -1, defaultButtonTimer);
-}
-
-void updateQuitMenu () {
- boolean enabled = true;
- Shell [] shells = getShells ();
- int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if ((shell.style & mask) != 0 && shell.isVisible ()) {
- enabled = false;
- break;
- }
- }
-
- NSMenu mainmenu = application.mainMenu();
- NSMenuItem appitem = mainmenu.itemAtIndex(0);
- if (appitem != null) {
- NSMenu sm = appitem.submenu();
-
- // Normally this would be sel_terminate_ but we changed it so terminate: doesn't kill the app.
- int /*long*/ quitIndex = sm.indexOfItemWithTarget(applicationDelegate, OS.sel_quitRequested_);
-
- if (quitIndex != -1) {
- NSMenuItem quitItem = sm.itemAtIndex(quitIndex);
- quitItem.setEnabled(enabled);
- }
- }
-}
-
-
-/**
- * If the receiver's user-interface thread was <code>sleep</code>ing,
- * causes it to be awakened and start running again. Note that this
- * method may be called from any thread.
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #sleep
- */
-public void wake () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- if (thread == Thread.currentThread ()) return;
- wakeThread ();
- }
-}
-
-void wakeThread () {
- //new pool?
- NSObject object = new NSObject().alloc().init();
- object.performSelectorOnMainThread(OS.sel_release, null, false);
-}
-
-Control findControl (boolean checkTrim) {
- return findControl(checkTrim, null);
-}
-
-Control findControl (boolean checkTrim, NSView[] hitView) {
- NSView view = null;
- NSPoint screenLocation = NSEvent.mouseLocation();
- NSArray windows = application.orderedWindows();
- for (int i = 0, count = (int)/*64*/windows.count(); i < count && view == null; i++) {
- NSWindow window = new NSWindow(windows.objectAtIndex(i));
- NSView contentView = window.contentView();
- if (contentView != null && OS.NSPointInRect(screenLocation, window.frame())) {
- NSPoint location = window.convertScreenToBase(screenLocation);
- view = contentView.hitTest (location);
- if (view == null && !checkTrim) {
- view = contentView;
- }
- break;
- }
- }
- Control control = null;
- if (view != null) {
- do {
- Widget widget = getWidget (view);
- if (widget instanceof Control) {
- control = (Control)widget;
- break;
- }
- view = view.superview();
- } while (view != null);
- }
- if (checkTrim) {
- if (control != null && control.isTrim (view)) control = null;
- }
- if (control != null && hitView != null) hitView[0] = view;
- return control;
-}
-
-void finishLaunching (int /*long*/ id, int /*long*/ sel) {
- /*
- * [NSApplication finishLaunching] cannot run multiple times otherwise
- * multiple main menus are added.
- */
- if (launched) return;
- launched = true;
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- OS.objc_msgSendSuper(super_struct, sel);
-}
-
-void applicationDidBecomeActive (int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
- checkFocus();
- checkEnterExit(findControl(true), null, false);
-}
-
-void applicationDidResignActive (int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
- checkFocus();
- checkEnterExit(null, null, false);
-}
-
-int /*long*/ applicationNextEventMatchingMask (int /*long*/ id, int /*long*/ sel, int /*long*/ mask, int /*long*/ expiration, int /*long*/ mode, int /*long*/ dequeue) {
- if (dequeue != 0 && trackingControl != null && !trackingControl.isDisposed()) runDeferredEvents();
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- int /*long*/ result = OS.objc_msgSendSuper(super_struct, sel, mask, expiration, mode, dequeue != 0);
- if (result != 0) {
- if (dequeue != 0 && trackingControl != null && !trackingControl.isDisposed()) {
- applicationSendTrackingEvent(new NSEvent(result), trackingControl);
- }
- }
- return result;
-}
-
-void applicationSendTrackingEvent (NSEvent nsEvent, Control trackingControl) {
- int type = (int)/*64*/nsEvent.type();
- switch (type) {
- case OS.NSLeftMouseDown:
- case OS.NSRightMouseDown:
- case OS.NSOtherMouseDown:
- trackingControl.sendMouseEvent (nsEvent, SWT.MouseDown, true);
- break;
- case OS.NSLeftMouseUp:
- case OS.NSRightMouseUp:
- case OS.NSOtherMouseUp:
- checkEnterExit (findControl (true), nsEvent, true);
- if (trackingControl.isDisposed()) return;
- trackingControl.sendMouseEvent (nsEvent, SWT.MouseUp, true);
- break;
- case OS.NSLeftMouseDragged:
- case OS.NSRightMouseDragged:
- case OS.NSOtherMouseDragged:
- checkEnterExit (trackingControl, nsEvent, true);
- if (trackingControl.isDisposed()) return;
- //FALL THROUGH
- case OS.NSMouseMoved:
- trackingControl.sendMouseEvent (nsEvent, SWT.MouseMove, true);
- break;
- }
-}
-
-void applicationSendEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ event) {
- NSEvent nsEvent = new NSEvent(event);
- NSWindow window = nsEvent.window ();
- int type = (int)/*64*/nsEvent.type ();
- boolean down = false;
- switch (type) {
- case OS.NSLeftMouseDown:
- case OS.NSRightMouseDown:
- case OS.NSOtherMouseDown:
- down = true;
- case OS.NSLeftMouseUp:
- case OS.NSRightMouseUp:
- case OS.NSOtherMouseUp:
- case OS.NSLeftMouseDragged:
- case OS.NSRightMouseDragged:
- case OS.NSOtherMouseDragged:
- case OS.NSMouseMoved:
- case OS.NSMouseEntered:
- case OS.NSMouseExited:
- case OS.NSKeyDown:
- case OS.NSKeyUp:
- case OS.NSScrollWheel:
- if (window != null) {
- Shell shell = (Shell) getWidget (window.id);
- if (shell != null) {
- Shell modalShell = shell.getModalShell ();
- if (modalShell != null) {
- if (down) {
- if (!application.isActive()) {
- application.activateIgnoringOtherApps(true);
- }
- NSRect rect = window.contentRectForFrameRect(window.frame());
- NSPoint pt = window.convertBaseToScreen(nsEvent.locationInWindow());
- if (OS.NSPointInRect(pt, rect)) beep ();
- }
- return;
- }
- }
- }
- break;
- }
- sendEvent = true;
-
- /*
- * Feature in Cocoa. The help key triggers context-sensitive help but doesn't get forwarded to the window as a key event.
- * If the event is destined for the key window, is the help key, and is an NSKeyDown, send it directly to the window first.
- */
- if (window != null && window.isKeyWindow() && nsEvent.type() == OS.NSKeyDown && (nsEvent.modifierFlags() & OS.NSHelpKeyMask) != 0) {
- window.sendEvent(nsEvent);
- }
-
- /*
- * Feature in Cocoa. NSKeyUp events are not delivered to the window if the command key is down.
- * If the event is destined for the key window, and it's a key up and the command key is down, send it directly to the window.
- */
- if (window != null && window.isKeyWindow() && nsEvent.type() == OS.NSKeyUp && (nsEvent.modifierFlags() & OS.NSCommandKeyMask) != 0) {
- window.sendEvent(nsEvent);
- } else {
- objc_super super_struct = new objc_super ();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend (id, OS.sel_superclass);
- OS.objc_msgSendSuper (super_struct, sel, event);
- }
- sendEvent = false;
-}
-
-void applicationWillFinishLaunching (int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
- boolean loaded = false;
- NSBundle bundle = NSBundle.bundleWithIdentifier(NSString.stringWith("com.apple.JavaVM"));
- NSDictionary dict = NSDictionary.dictionaryWithObject(applicationDelegate, NSString.stringWith("NSOwner"));
- NSString path = bundle.pathForResource(NSString.stringWith("DefaultApp"), NSString.stringWith("nib"));
- if (!loaded) loaded = path != null && NSBundle.loadNibFile(path, dict, 0);
- if (!loaded) {
- NSString resourcePath = bundle.resourcePath();
- path = resourcePath != null ? resourcePath.stringByAppendingString(NSString.stringWith("/English.lproj/DefaultApp.nib")) : null;
- loaded = path != null && NSBundle.loadNibFile(path, dict, 0);
- }
- if (!loaded) {
- path = NSString.stringWith(System.getProperty("java.home") + "/../Resources/English.lproj/DefaultApp.nib");
- loaded = path != null && NSBundle.loadNibFile(path, dict, 0);
- }
- if (!loaded) {
- createMainMenu();
- }
- //replace %@ with application name
- NSMenu mainmenu = application.mainMenu();
- NSMenuItem appitem = mainmenu.itemAtIndex(0);
- if (appitem != null) {
- NSString name = getAppName();
- NSString match = NSString.stringWith("%@");
- appitem.setTitle(name);
- NSMenu sm = appitem.submenu();
- NSArray ia = sm.itemArray();
- for(int i = 0; i < ia.count(); i++) {
- NSMenuItem ni = new NSMenuItem(ia.objectAtIndex(i));
- NSString title = ni.title().stringByReplacingOccurrencesOfString(match, name);
- ni.setTitle(title);
- }
-
- int /*long*/ quitIndex = sm.indexOfItemWithTarget(applicationDelegate, OS.sel_terminate_);
-
- if (quitIndex != -1) {
- NSMenuItem quitItem = sm.itemAtIndex(quitIndex);
- quitItem.setAction(OS.sel_quitRequested_);
- }
- }
-}
-
-static int /*long*/ applicationProc(int /*long*/ id, int /*long*/ sel) {
- //TODO optimize getting the display
- Display display = getCurrent ();
- if (display == null) return 0;
- if (sel == OS.sel_isRunning) {
- // #245724: [NSApplication isRunning] must return true to allow the AWT to load correctly.
- return display.isDisposed() ? 0 : 1;
- }
- if (sel == OS.sel_finishLaunching) {
- display.finishLaunching (id, sel);
- }
- return 0;
-}
-
-static int /*long*/ applicationProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- //TODO optimize getting the display
- Display display = getCurrent ();
- if (display == null) return 0;
- NSApplication application = display.application;
- if (sel == OS.sel_sendEvent_) {
- display.applicationSendEvent (id, sel, arg0);
- } else if (sel == OS.sel_applicationWillFinishLaunching_) {
- display.applicationWillFinishLaunching(id, sel, arg0);
- } else if (sel == OS.sel_terminate_) {
- // Do nothing here -- without a definition of sel_terminate we get a warning dumped to the console.
- } else if (sel == OS.sel_orderFrontStandardAboutPanel_) {
-// application.orderFrontStandardAboutPanel(application);
- } else if (sel == OS.sel_hideOtherApplications_) {
- application.hideOtherApplications(application);
- } else if (sel == OS.sel_hide_) {
- application.hide(application);
- } else if (sel == OS.sel_unhideAllApplications_) {
- application.unhideAllApplications(application);
- } else if (sel == OS.sel_quitRequested_) {
- if (!display.disposing) {
- Event event = new Event ();
- display.sendEvent (SWT.Close, event);
- if (event.doit) {
- display.dispose();
- }
- }
- } else if (sel == OS.sel_applicationDidBecomeActive_) {
- display.applicationDidBecomeActive(id, sel, arg0);
- } else if (sel == OS.sel_applicationDidResignActive_) {
- display.applicationDidResignActive(id, sel, arg0);
- }
- return 0;
-}
-
-static int /*long*/ applicationProc(int /*long*/ id, int /*long*/sel, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2, int /*long*/ arg3) {
- //TODO optimize getting the display
- Display display = getCurrent ();
- if (display == null) return 0;
- if (sel == OS.sel_nextEventMatchingMask_untilDate_inMode_dequeue_) {
- return display.applicationNextEventMatchingMask(id, sel, arg0, arg1, arg2, arg3);
- }
- return 0;
-}
-
-static int /*long*/ dialogProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- int /*long*/ [] jniRef = new int /*long*/ [1];
- OS.object_getInstanceVariable(id, SWT_OBJECT, jniRef);
- if (jniRef[0] == 0) return 0;
- if (sel == OS.sel_changeColor_) {
- ColorDialog dialog = (ColorDialog)OS.JNIGetObject(jniRef[0]);
- if (dialog == null) return 0;
- dialog.changeColor(id, sel, arg0);
- } else if (sel == OS.sel_changeFont_) {
- FontDialog dialog = (FontDialog)OS.JNIGetObject(jniRef[0]);
- if (dialog == null) return 0;
- dialog.changeFont(id, sel, arg0);
- } else if (sel == OS.sel_sendSelection_) {
- FileDialog dialog = (FileDialog)OS.JNIGetObject(jniRef[0]);
- if (dialog == null) return 0;
- dialog.sendSelection(id, sel, arg0);
- } else if (sel == OS.sel_windowWillClose_) {
- Object object = OS.JNIGetObject(jniRef[0]);
- if (object instanceof FontDialog) {
- ((FontDialog)object).windowWillClose(id, sel, arg0);
- } else if (object instanceof ColorDialog) {
- ((ColorDialog)object).windowWillClose(id, sel, arg0);
- }
- }
- return 0;
-}
-
-static int /*long*/ dialogProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1) {
- int /*long*/ [] jniRef = new int /*long*/ [1];
- OS.object_getInstanceVariable(id, SWT_OBJECT, jniRef);
- if (jniRef[0] == 0) return 0;
- if (sel == OS.sel_panel_shouldShowFilename_) {
- FileDialog dialog = (FileDialog)OS.JNIGetObject(jniRef[0]);
- if (dialog == null) return 0;
- return dialog.panel_shouldShowFilename(id, sel, arg0, arg1);
- }
- return 0;
-}
-
-static int /*long*/ dialogProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2) {
- int /*long*/ [] jniRef = new int /*long*/ [1];
- OS.object_getInstanceVariable(id, SWT_OBJECT, jniRef);
- if (jniRef[0] == 0) return 0;
- if (sel == OS.sel_panelDidEnd_returnCode_contextInfo_) {
- MessageBox dialog = (MessageBox)OS.JNIGetObject(jniRef[0]);
- if (dialog == null) return 0;
- dialog.panelDidEnd_returnCode_contextInfo(id, sel, arg0, arg1, arg2);
- }
- return 0;
-}
-
-static int /*long*/ fieldEditorProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- Widget widget = null;
- NSView view = new NSView (id);
- do {
- widget = GetWidget (view.id);
- if (widget != null) break;
- view = view.superview ();
- } while (view != null);
- if (widget == null) return 0;
- if (sel == OS.sel_keyDown_) {
- widget.keyDown (id, sel, arg0);
- } else if (sel == OS.sel_keyUp_) {
- widget.keyUp (id, sel, arg0);
- } else if (sel == OS.sel_flagsChanged_) {
- widget.flagsChanged(id, sel, arg0);
- } else if (sel == OS.sel_insertText_) {
- return widget.insertText (id, sel, arg0) ? 1 : 0;
- } else if (sel == OS.sel_doCommandBySelector_) {
- widget.doCommandBySelector (id, sel, arg0);
- } else if (sel == OS.sel_menuForEvent_) {
- return widget.menuForEvent (id, sel, arg0);
- } else if (sel == OS.sel_mouseDown_) {
- widget.mouseDown(id, sel, arg0);
- } else if (sel == OS.sel_mouseUp_) {
- widget.mouseUp(id, sel, arg0);
- } else if (sel == OS.sel_mouseMoved_) {
- widget.mouseMoved(id, sel, arg0);
- } else if (sel == OS.sel_mouseDragged_) {
- widget.mouseDragged(id, sel, arg0);
- } else if (sel == OS.sel_mouseEntered_) {
- widget.mouseEntered(id, sel, arg0);
- } else if (sel == OS.sel_mouseExited_) {
- widget.mouseExited(id, sel, arg0);
- } else if (sel == OS.sel_cursorUpdate_) {
- widget.cursorUpdate(id, sel, arg0);
- } else if (sel == OS.sel_rightMouseDown_) {
- widget.rightMouseDown(id, sel, arg0);
- } else if (sel == OS.sel_rightMouseDragged_) {
- widget.rightMouseDragged(id, sel, arg0);
- } else if (sel == OS.sel_rightMouseUp_) {
- widget.rightMouseUp(id, sel, arg0);
- } else if (sel == OS.sel_otherMouseDown_) {
- widget.otherMouseDown(id, sel, arg0);
- } else if (sel == OS.sel_otherMouseUp_) {
- widget.otherMouseUp(id, sel, arg0);
- } else if (sel == OS.sel_otherMouseDragged_) {
- widget.otherMouseDragged(id, sel, arg0);
- }
- return 0;
-}
-
-static int /*long*/ fieldEditorProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1) {
- Widget widget = null;
- NSView view = new NSView (id);
- do {
- widget = GetWidget (view.id);
- if (widget != null) break;
- view = view.superview ();
- } while (view != null);
- if (sel == OS.sel_shouldChangeTextInRange_replacementString_) {
- return widget.shouldChangeTextInRange_replacementString(id, sel, arg0, arg1) ? 1 : 0;
- }
- return 0;
-}
-
-static int /*long*/ windowProc(int /*long*/ id, int /*long*/ sel) {
- /*
- * Feature in Cocoa. In Cocoa, the default button animation is done
- * in a separate thread that calls drawRect() and isOpaque() from
- * outside the UI thread. This means that those methods, and application
- * code that runs as a result of those methods, must be thread safe.
- * In SWT, paint events must happen in the UI thread. The fix is
- * to detect a non-UI thread and avoid the drawing. Instead, the
- * default button is animated by a timer.
- */
- if (!NSThread.isMainThread()) {
- if (sel == OS.sel_isOpaque) {
- return 1;
- }
- }
- Widget widget = GetWidget(id);
- if (widget == null) return 0;
- if (sel == OS.sel_sendSelection) {
- widget.sendSelection();
- } else if (sel == OS.sel_sendDoubleSelection) {
- widget.sendDoubleSelection();
- } else if (sel == OS.sel_sendVerticalSelection) {
- widget.sendVerticalSelection();
- } else if (sel == OS.sel_sendHorizontalSelection) {
- widget.sendHorizontalSelection();
- } else if (sel == OS.sel_sendSearchSelection) {
- widget.sendSearchSelection();
- } else if (sel == OS.sel_sendCancelSelection) {
- widget.sendCancelSelection();
- } else if (sel == OS.sel_acceptsFirstResponder) {
- return widget.acceptsFirstResponder(id, sel) ? 1 : 0;
- } else if (sel == OS.sel_becomeFirstResponder) {
- return widget.becomeFirstResponder(id, sel) ? 1 : 0;
- } else if (sel == OS.sel_resignFirstResponder) {
- return widget.resignFirstResponder(id, sel) ? 1 : 0;
- } else if (sel == OS.sel_isOpaque) {
- return widget.isOpaque(id, sel) ? 1 : 0;
- } else if (sel == OS.sel_isFlipped) {
- return widget.isFlipped(id, sel) ? 1 : 0;
- } else if (sel == OS.sel_canBecomeKeyView) {
- return widget.canBecomeKeyView(id,sel) ? 1 : 0;
- } else if (sel == OS.sel_becomeKeyWindow) {
- widget.becomeKeyWindow(id, sel);
- } else if (sel == OS.sel_unmarkText) {
- //TODO not called?
- } else if (sel == OS.sel_validAttributesForMarkedText) {
- return widget.validAttributesForMarkedText (id, sel);
- } else if (sel == OS.sel_markedRange) {
- NSRange range = widget.markedRange (id, sel);
- /* NOTE that this is freed in C */
- int /*long*/ result = OS.malloc (NSRange.sizeof);
- OS.memmove (result, range, NSRange.sizeof);
- return result;
- } else if (sel == OS.sel_selectedRange) {
- NSRange range = widget.selectedRange (id, sel);
- /* NOTE that this is freed in C */
- int /*long*/ result = OS.malloc (NSRange.sizeof);
- OS.memmove (result, range, NSRange.sizeof);
- return result;
- } else if (sel == OS.sel_cellSize) {
- NSSize size = widget.cellSize (id, sel);
- /* NOTE that this is freed in C */
- int /*long*/ result = OS.malloc (NSSize.sizeof);
- OS.memmove (result, size, NSSize.sizeof);
- return result;
- } else if (sel == OS.sel_hasMarkedText) {
- return widget.hasMarkedText (id, sel) ? 1 : 0;
- } else if (sel == OS.sel_canBecomeKeyWindow) {
- return widget.canBecomeKeyWindow (id, sel) ? 1 : 0;
- } else if (sel == OS.sel_accessibilityActionNames) {
- return widget.accessibilityActionNames(id, sel);
- } else if (sel == OS.sel_accessibilityAttributeNames) {
- return widget.accessibilityAttributeNames(id, sel);
- } else if (sel == OS.sel_accessibilityParameterizedAttributeNames) {
- return widget.accessibilityParameterizedAttributeNames(id, sel);
- } else if (sel == OS.sel_accessibilityFocusedUIElement) {
- return widget.accessibilityFocusedUIElement(id, sel);
- } else if (sel == OS.sel_accessibilityIsIgnored) {
- return (widget.accessibilityIsIgnored(id, sel) ? 1 : 0);
- } else if (sel == OS.sel_nextState) {
- return widget.nextState(id, sel);
- } else if (sel == OS.sel_resetCursorRects) {
- widget.resetCursorRects(id, sel);
- } else if (sel == OS.sel_updateTrackingAreas) {
- widget.updateTrackingAreas(id, sel);
- } else if (sel == OS.sel_viewDidMoveToWindow) {
- widget.viewDidMoveToWindow(id, sel);
- } else if (sel == OS.sel_image) {
- return widget.image(id, sel);
- }
- return 0;
-}
-
-static int /*long*/ windowProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- /*
- * Feature in Cocoa. In Cocoa, the default button animation is done
- * in a separate thread that calls drawRect() and isOpaque() from
- * outside the UI thread. This means that those methods, and application
- * code that runs as a result of those methods, must be thread safe.
- * In SWT, paint events must happen in the UI thread. The fix is
- * to detect a non-UI thread and avoid the drawing. Instead, the
- * default button is animated by a timer.
- */
- if (!NSThread.isMainThread()) {
- if (sel == OS.sel_drawRect_) {
- return 0;
- }
- }
- if (sel == OS.sel_timerProc_) {
- //TODO optimize getting the display
- Display display = getCurrent ();
- if (display == null) return 0;
- return display.timerProc (id, sel, arg0);
- }
- if (sel == OS.sel_systemSettingsChanged_) {
- //TODO optimize getting the display
- Display display = getCurrent ();
- if (display == null) return 0;
- display.runSettings = true;
- return 0;
- }
- Widget widget = GetWidget(id);
- if (widget == null) return 0;
- if (sel == OS.sel_windowWillClose_) {
- widget.windowWillClose(id, sel, arg0);
- } else if (sel == OS.sel_drawRect_) {
- NSRect rect = new NSRect();
- OS.memmove(rect, arg0, NSRect.sizeof);
- widget.drawRect(id, sel, rect);
- } else if (sel == OS.sel__drawThemeProgressArea_) {
- widget._drawThemeProgressArea(id, sel, arg0);
- } else if (sel == OS.sel_setFrameOrigin_) {
- NSPoint point = new NSPoint();
- OS.memmove(point, arg0, NSPoint.sizeof);
- widget.setFrameOrigin(id, sel, point);
- } else if (sel == OS.sel_setFrameSize_) {
- NSSize size = new NSSize();
- OS.memmove(size, arg0, NSSize.sizeof);
- widget.setFrameSize(id, sel, size);
- } else if (sel == OS.sel_hitTest_) {
- NSPoint point = new NSPoint();
- OS.memmove(point, arg0, NSPoint.sizeof);
- return widget.hitTest(id, sel, point);
- } else if (sel == OS.sel_windowShouldClose_) {
- return widget.windowShouldClose(id, sel, arg0) ? 1 : 0;
- } else if (sel == OS.sel_mouseDown_) {
- widget.mouseDown(id, sel, arg0);
- } else if (sel == OS.sel_keyDown_) {
- widget.keyDown(id, sel, arg0);
- } else if (sel == OS.sel_keyUp_) {
- widget.keyUp(id, sel, arg0);
- } else if (sel == OS.sel_flagsChanged_) {
- widget.flagsChanged(id, sel, arg0);
- } else if (sel == OS.sel_mouseUp_) {
- widget.mouseUp(id, sel, arg0);
- } else if (sel == OS.sel_rightMouseDown_) {
- widget.rightMouseDown(id, sel, arg0);
- } else if (sel == OS.sel_rightMouseDragged_) {
- widget.rightMouseDragged(id, sel, arg0);
- } else if (sel == OS.sel_rightMouseUp_) {
- widget.rightMouseUp(id, sel, arg0);
- } else if (sel == OS.sel_otherMouseDown_) {
- widget.otherMouseDown(id, sel, arg0);
- } else if (sel == OS.sel_otherMouseUp_) {
- widget.otherMouseUp(id, sel, arg0);
- } else if (sel == OS.sel_otherMouseDragged_) {
- widget.otherMouseDragged(id, sel, arg0);
- } else if (sel == OS.sel_mouseMoved_) {
- widget.mouseMoved(id, sel, arg0);
- } else if (sel == OS.sel_mouseDragged_) {
- widget.mouseDragged(id, sel, arg0);
- } else if (sel == OS.sel_mouseEntered_) {
- widget.mouseEntered(id, sel, arg0);
- } else if (sel == OS.sel_mouseExited_) {
- widget.mouseExited(id, sel, arg0);
- } else if (sel == OS.sel_cursorUpdate_) {
- widget.cursorUpdate(id, sel, arg0);
- } else if (sel == OS.sel_menuForEvent_) {
- return widget.menuForEvent(id, sel, arg0);
- } else if (sel == OS.sel_noResponderFor_) {
- widget.noResponderFor(id, sel, arg0);
- } else if (sel == OS.sel_shouldDelayWindowOrderingForEvent_) {
- return widget.shouldDelayWindowOrderingForEvent(id, sel, arg0) ? 1 : 0;
- } else if (sel == OS.sel_acceptsFirstMouse_) {
- return widget.acceptsFirstMouse(id, sel, arg0) ? 1 : 0;
- } else if (sel == OS.sel_numberOfRowsInTableView_) {
- return widget.numberOfRowsInTableView(id, sel, arg0);
- } else if (sel == OS.sel_tableViewSelectionDidChange_) {
- widget.tableViewSelectionDidChange(id, sel, arg0);
- } else if (sel == OS.sel_windowDidResignKey_) {
- widget.windowDidResignKey(id, sel, arg0);
- } else if (sel == OS.sel_windowDidBecomeKey_) {
- widget.windowDidBecomeKey(id, sel, arg0);
- } else if (sel == OS.sel_windowDidResize_) {
- widget.windowDidResize(id, sel, arg0);
- } else if (sel == OS.sel_windowDidMove_) {
- widget.windowDidMove(id, sel, arg0);
- } else if (sel == OS.sel_menuWillOpen_) {
- widget.menuWillOpen(id, sel, arg0);
- } else if (sel == OS.sel_menuDidClose_) {
- widget.menuDidClose(id, sel, arg0);
- } else if (sel == OS.sel_menuNeedsUpdate_) {
- widget.menuNeedsUpdate(id, sel, arg0);
- } else if (sel == OS.sel_outlineViewSelectionDidChange_) {
- widget.outlineViewSelectionDidChange(id, sel, arg0);
- } else if (sel == OS.sel_sendEvent_) {
- widget.windowSendEvent(id, sel, arg0);
- } else if (sel == OS.sel_helpRequested_) {
- widget.helpRequested(id, sel, arg0);
- } else if (sel == OS.sel_scrollWheel_) {
- widget.scrollWheel(id, sel, arg0);
- } else if (sel == OS.sel_pageDown_) {
- widget.pageDown(id, sel, arg0);
- } else if (sel == OS.sel_pageUp_) {
- widget.pageUp(id, sel, arg0);
- } else if (sel == OS.sel_textViewDidChangeSelection_) {
- widget.textViewDidChangeSelection(id, sel, arg0);
- } else if (sel == OS.sel_textDidChange_) {
- widget.textDidChange(id, sel, arg0);
- } else if (sel == OS.sel_textDidEndEditing_) {
- widget.textDidEndEditing(id, sel, arg0);
- } else if (sel == OS.sel_attributedSubstringFromRange_) {
- return widget.attributedSubstringFromRange (id, sel, arg0);
- } else if (sel == OS.sel_characterIndexForPoint_) {
- return widget.characterIndexForPoint (id, sel, arg0);
- } else if (sel == OS.sel_firstRectForCharacterRange_) {
- NSRect rect = widget.firstRectForCharacterRange (id, sel, arg0);
- /* NOTE that this is freed in C */
- int /*long*/ result = OS.malloc (NSRect.sizeof);
- OS.memmove (result, rect, NSRect.sizeof);
- return result;
- } else if (sel == OS.sel_insertText_) {
- return widget.insertText (id, sel, arg0) ? 1 : 0;
- } else if (sel == OS.sel_doCommandBySelector_) {
- widget.doCommandBySelector (id, sel, arg0);
- } else if (sel == OS.sel_highlightSelectionInClipRect_) {
- widget.highlightSelectionInClipRect (id, sel, arg0);
- } else if (sel == OS.sel_reflectScrolledClipView_) {
- widget.reflectScrolledClipView (id, sel, arg0);
- } else if (sel == OS.sel_accessibilityHitTest_) {
- NSPoint point = new NSPoint();
- OS.memmove(point, arg0, NSPoint.sizeof);
- return widget.accessibilityHitTest(id, sel, point);
- } else if (sel == OS.sel_accessibilityAttributeValue_) {
- return widget.accessibilityAttributeValue(id, sel, arg0);
- } else if (sel == OS.sel_accessibilityPerformAction_) {
- widget.accessibilityPerformAction(id, sel, arg0);
- } else if (sel == OS.sel_accessibilityActionDescription_) {
- widget.accessibilityActionDescription(id, sel, arg0);
- } else if (sel == OS.sel_makeFirstResponder_) {
- return widget.makeFirstResponder(id, sel, arg0) ? 1 : 0;
- } else if (sel == OS.sel_tableViewColumnDidMove_) {
- widget.tableViewColumnDidMove(id, sel, arg0);
- } else if (sel == OS.sel_tableViewColumnDidResize_) {
- widget.tableViewColumnDidResize(id, sel, arg0);
- } else if (sel == OS.sel_outlineViewColumnDidMove_) {
- widget.outlineViewColumnDidMove(id, sel, arg0);
- } else if (sel == OS.sel_outlineViewColumnDidResize_) {
- widget.outlineViewColumnDidResize(id, sel, arg0);
- } else if (sel == OS.sel_setNeedsDisplay_) {
- widget.setNeedsDisplay(id, sel, arg0 != 0);
- } else if (sel == OS.sel_setNeedsDisplayInRect_) {
- widget.setNeedsDisplayInRect(id, sel, arg0);
- } else if (sel == OS.sel_setImage_) {
- widget.setImage(id, sel, arg0);
- } else if (sel == OS.sel_imageRectForBounds_) {
- NSRect rect = new NSRect();
- OS.memmove(rect, arg0, NSRect.sizeof);
- rect = widget.imageRectForBounds(id, sel, rect);
- /* NOTE that this is freed in C */
- int /*long*/ result = OS.malloc (NSRect.sizeof);
- OS.memmove (result, rect, NSRect.sizeof);
- return result;
- } else if (sel == OS.sel_titleRectForBounds_) {
- NSRect rect = new NSRect();
- OS.memmove(rect, arg0, NSRect.sizeof);
- rect = widget.titleRectForBounds(id, sel, rect);
- /* NOTE that this is freed in C */
- int /*long*/ result = OS.malloc (NSRect.sizeof);
- OS.memmove (result, rect, NSRect.sizeof);
- return result;
- } else if (sel == OS.sel_setObjectValue_) {
- widget.setObjectValue(id, sel, arg0);
- } else if (sel == OS.sel_updateOpenGLContext_) {
- widget.updateOpenGLContext(id, sel, arg0);
- }
- return 0;
-}
-
-static int /*long*/ windowProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1) {
- Widget widget = GetWidget(id);
- if (widget == null) return 0;
- if (sel == OS.sel_tabView_willSelectTabViewItem_) {
- widget.tabView_willSelectTabViewItem(id, sel, arg0, arg1);
- } else if (sel == OS.sel_tabView_didSelectTabViewItem_) {
- widget.tabView_didSelectTabViewItem(id, sel, arg0, arg1);
- } else if (sel == OS.sel_outlineView_isItemExpandable_) {
- return widget.outlineView_isItemExpandable(id, sel, arg0, arg1) ? 1 : 0;
- } else if (sel == OS.sel_outlineView_numberOfChildrenOfItem_) {
- return widget.outlineView_numberOfChildrenOfItem(id, sel, arg0, arg1);
- } else if (sel == OS.sel_menu_willHighlightItem_) {
- widget.menu_willHighlightItem(id, sel, arg0, arg1);
- } else if (sel == OS.sel_setMarkedText_selectedRange_) {
- widget.setMarkedText_selectedRange (id, sel, arg0, arg1);
- } else if (sel == OS.sel_drawInteriorWithFrame_inView_) {
- NSRect rect = new NSRect ();
- OS.memmove (rect, arg0, NSRect.sizeof);
- widget.drawInteriorWithFrame_inView (id, sel, rect, arg1);
- } else if (sel == OS.sel_drawWithExpansionFrame_inView_) {
- NSRect rect = new NSRect();
- OS.memmove(rect, arg0, NSRect.sizeof);
- widget.drawWithExpansionFrame_inView (id, sel, rect, arg1);
- } else if (sel == OS.sel_accessibilityAttributeValue_forParameter_) {
- return widget.accessibilityAttributeValue_forParameter(id, sel, arg0, arg1);
- } else if (sel == OS.sel_tableView_didClickTableColumn_) {
- widget.tableView_didClickTableColumn (id, sel, arg0, arg1);
- } else if (sel == OS.sel_outlineView_didClickTableColumn_) {
- widget.outlineView_didClickTableColumn (id, sel, arg0, arg1);
- } else if (sel == OS.sel_shouldChangeTextInRange_replacementString_) {
- return widget.shouldChangeTextInRange_replacementString(id, sel, arg0, arg1) ? 1 : 0;
- } else if (sel == OS.sel_canDragRowsWithIndexes_atPoint_) {
- return widget.canDragRowsWithIndexes_atPoint(id, sel, arg0, arg1) ? 1 : 0;
- } else if (sel == OS.sel_expandItem_expandChildren_) {
- widget.expandItem_expandChildren(id, sel, arg0, arg1 != 0);
- } else if (sel == OS.sel_collapseItem_collapseChildren_) {
- widget.collapseItem_collapseChildren(id, sel, arg0, arg1 != 0);
- } else if (sel == OS.sel_expansionFrameWithFrame_inView_) {
- NSRect rect = new NSRect();
- OS.memmove(rect, arg0, NSRect.sizeof);
- rect = widget.expansionFrameWithFrame_inView(id, sel, rect, arg1);
- /* NOTE that this is freed in C */
- int /*long*/ result = OS.malloc (NSRect.sizeof);
- OS.memmove (result, rect, NSRect.sizeof);
- return result;
- }
- return 0;
-}
-
-static int /*long*/ windowProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2) {
- Widget widget = GetWidget(id);
- if (widget == null) return 0;
- if (sel == OS.sel_tableView_objectValueForTableColumn_row_) {
- return widget.tableView_objectValueForTableColumn_row(id, sel, arg0, arg1, arg2);
- } else if (sel == OS.sel_tableView_shouldEditTableColumn_row_) {
- return widget.tableView_shouldEditTableColumn_row(id, sel, arg0, arg1, arg2) ? 1 : 0;
- } else if (sel == OS.sel_textView_clickedOnLink_atIndex_) {
- return widget.textView_clickOnLink_atIndex(id, sel, arg0, arg1, arg2) ? 1 : 0;
- } else if (sel == OS.sel_outlineView_child_ofItem_) {
- return widget.outlineView_child_ofItem(id, sel, arg0, arg1, arg2);
- } else if (sel == OS.sel_outlineView_objectValueForTableColumn_byItem_) {
- return widget.outlineView_objectValueForTableColumn_byItem(id, sel, arg0, arg1, arg2);
- } else if (sel == OS.sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_) {
- NSRange range = widget.textView_willChangeSelectionFromCharacterRange_toCharacterRange(id, sel, arg0, arg1, arg2);
- /* NOTE that this is freed in C */
- int /*long*/ result = OS.malloc (NSRange.sizeof);
- OS.memmove (result, range, NSRange.sizeof);
- return result;
- } else if (sel == OS.sel_dragSelectionWithEvent_offset_slideBack_) {
- NSSize offset = new NSSize();
- OS.memmove(offset, arg0, NSSize.sizeof);
- return (widget.dragSelectionWithEvent(id, sel, arg0, arg1, arg2) ? 1 : 0);
- } else if (sel == OS.sel_drawImage_withFrame_inView_) {
- NSRect rect = new NSRect ();
- OS.memmove (rect, arg1, NSRect.sizeof);
- widget.drawImageWithFrameInView (id, sel, arg0, rect, arg2);
- } else if (sel == OS.sel_hitTestForEvent_inRect_ofView_) {
- NSRect rect = new NSRect ();
- OS.memmove (rect, arg1, NSRect.sizeof);
- return widget.hitTestForEvent (id, sel, arg0, rect, arg2);
- } else if (sel == OS.sel_tableView_writeRowsWithIndexes_toPasteboard_) {
- return (widget.tableView_writeRowsWithIndexes_toPasteboard(id, sel, arg0, arg1, arg2) ? 1 : 0);
- } else if (sel == OS.sel_outlineView_writeItems_toPasteboard_) {
- return (widget.outlineView_writeItems_toPasteboard(id, sel, arg0, arg1, arg2) ? 1 : 0);
- }
- return 0;
-}
-
-static int /*long*/ windowProc(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2, int /*long*/ arg3) {
- Widget widget = GetWidget(id);
- if (widget == null) return 0;
- if (sel == OS.sel_tableView_willDisplayCell_forTableColumn_row_) {
- widget.tableView_willDisplayCell_forTableColumn_row(id, sel, arg0, arg1, arg2, arg3);
- } else if (sel == OS.sel_outlineView_willDisplayCell_forTableColumn_item_) {
- widget.outlineView_willDisplayCell_forTableColumn_item(id, sel, arg0, arg1, arg2, arg3);
- } else if (sel == OS.sel_outlineView_setObjectValue_forTableColumn_byItem_) {
- widget.outlineView_setObjectValue_forTableColumn_byItem(id, sel, arg0, arg1, arg2, arg3);
- } else if (sel == OS.sel_tableView_setObjectValue_forTableColumn_row_) {
- widget.tableView_setObjectValue_forTableColumn_row(id, sel, arg0, arg1, arg2, arg3);
- } else if (sel == OS.sel_view_stringForToolTip_point_userData_) {
- return widget.view_stringForToolTip_point_userData(id, sel, arg0, arg1, arg2, arg3);
- }
- return 0;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/FileDialog.java
deleted file mode 100755
index 6192f9414c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/FileDialog.java
+++ /dev/null
@@ -1,461 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class allow the user to navigate
- * the file system and select or enter a file name.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SAVE, OPEN, MULTI</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles SAVE and OPEN may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#filedialog">FileDialog snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class FileDialog extends Dialog {
- NSSavePanel panel;
- NSPopUpButton popup;
- String [] filterNames = new String [0];
- String [] filterExtensions = new String [0];
- String [] fileNames = new String[0];
- String filterPath = "", fileName = "";
- int filterIndex = -1;
- boolean overwrite = false;
- static final char EXTENSION_SEPARATOR = ';';
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FileDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SAVE
- * @see SWT#OPEN
- * @see SWT#MULTI
- */
-public FileDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- if (Display.getSheetEnabled ()) {
- if (parent != null && (style & SWT.SHEET) != 0) this.style |= SWT.SHEET;
- }
- checkSubclass ();
-}
-
-/**
- * Returns the path of the first file that was
- * selected in the dialog relative to the filter path, or an
- * empty string if no such file has been selected.
- *
- * @return the relative path of the file
- */
-public String getFileName () {
- return fileName;
-}
-
-/**
- * Returns a (possibly empty) array with the paths of all files
- * that were selected in the dialog relative to the filter path.
- *
- * @return the relative paths of the files
- */
-public String [] getFileNames () {
- return fileNames;
-}
-
-/**
- * Returns the file extensions which the dialog will
- * use to filter the files it shows.
- *
- * @return the file extensions filter
- */
-public String [] getFilterExtensions () {
- return filterExtensions;
-}
-
-/**
- * Get the 0-based index of the file extension filter
- * which was selected by the user, or -1 if no filter
- * was selected.
- * <p>
- * This is an index into the FilterExtensions array and
- * the FilterNames array.
- * </p>
- *
- * @return index the file extension filter index
- *
- * @see #getFilterExtensions
- * @see #getFilterNames
- *
- * @since 3.4
- */
-public int getFilterIndex () {
- return filterIndex;
-}
-
-/**
- * Returns the names that describe the filter extensions
- * which the dialog will use to filter the files it shows.
- *
- * @return the list of filter names
- */
-public String [] getFilterNames () {
- return filterNames;
-}
-
-/**
- * Returns the directory path that the dialog will use, or an empty
- * string if this is not set. File names in this path will appear
- * in the dialog, filtered according to the filter extensions.
- *
- * @return the directory path string
- *
- * @see #setFilterExtensions
- */
-public String getFilterPath () {
- return filterPath;
-}
-
-/**
- * Returns the flag that the dialog will use to
- * determine whether to prompt the user for file
- * overwrite if the selected file already exists.
- *
- * @return true if the dialog will prompt for file overwrite, false otherwise
- *
- * @since 3.4
- */
-public boolean getOverwrite () {
- return overwrite;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a string describing the absolute path of the first selected file,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public String open () {
- String fullPath = null;
- fileNames = new String [0];
- int /*long*/ method = 0;
- int /*long*/ methodImpl = 0;
- Callback callback = null;
- if ((style & SWT.SAVE) != 0) {
- NSSavePanel savePanel = NSSavePanel.savePanel();
- panel = savePanel;
- if (!overwrite) {
- callback = new Callback(this, "_overwriteExistingFileCheck", 3);
- int /*long*/ proc = callback.getAddress();
- if (proc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- method = OS.class_getInstanceMethod(OS.class_NSSavePanel, OS.sel_overwriteExistingFileCheck);
- if (method != 0) methodImpl = OS.method_setImplementation(method, proc);
- }
- } else {
- NSOpenPanel openPanel = NSOpenPanel.openPanel();
- openPanel.setAllowsMultipleSelection((style & SWT.MULTI) != 0);
- panel = openPanel;
- }
- panel.setCanCreateDirectories(true);
- int /*long*/ jniRef = 0;
- SWTPanelDelegate delegate = null;
- if (filterExtensions != null && filterExtensions.length != 0) {
- delegate = (SWTPanelDelegate)new SWTPanelDelegate().alloc().init();
- jniRef = OS.NewGlobalRef(this);
- if (jniRef == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.object_setInstanceVariable(delegate.id, Display.SWT_OBJECT, jniRef);
- panel.setDelegate(delegate);
- NSPopUpButton widget = (NSPopUpButton)new NSPopUpButton().alloc();
- widget.initWithFrame(new NSRect(), false);
- widget.setTarget(delegate);
- widget.setAction(OS.sel_sendSelection_);
- NSMenu menu = widget.menu();
- menu.setAutoenablesItems(false);
- for (int i = 0; i < filterExtensions.length; i++) {
- String str = filterExtensions [i];
- if (filterNames != null && filterNames.length > i) {
- str = filterNames [i];
- }
- NSMenuItem nsItem = (NSMenuItem)new NSMenuItem().alloc();
- nsItem.initWithTitle(NSString.stringWith(str), 0, NSString.stringWith(""));
- menu.addItem(nsItem);
- nsItem.release();
- }
- widget.selectItemAtIndex(0 <= filterIndex && filterIndex < filterExtensions.length ? filterIndex : 0);
- widget.sizeToFit();
- panel.setAccessoryView(widget);
- popup = widget;
- }
- panel.setTitle(NSString.stringWith(title != null ? title : ""));
- NSApplication application = NSApplication.sharedApplication();
- if (parent != null && (style & SWT.SHEET) != 0) {
- application.beginSheet(panel, parent.window, null, 0, 0);
- }
- NSString dir = filterPath != null ? NSString.stringWith(filterPath) : null;
- NSString file = fileName != null ? NSString.stringWith(fileName) : null;
- int /*long*/ response = panel.runModalForDirectory(dir, file);
- if (parent != null && (style & SWT.SHEET) != 0) {
- application.endSheet(panel, 0);
- }
- if (!overwrite) {
- if (method != 0) OS.method_setImplementation(method, methodImpl);
- if (callback != null) callback.dispose();
- }
- if (response == OS.NSFileHandlingPanelOKButton) {
- NSString filename = panel.filename();
- fullPath = filename.getString();
- if ((style & SWT.SAVE) == 0) {
- NSArray filenames = ((NSOpenPanel)panel).filenames();
- int count = (int)/*64*/filenames.count();
- fileNames = new String[count];
-
- for (int i = 0; i < count; i++) {
- filename = new NSString(filenames.objectAtIndex(i));
- NSString filenameOnly = filename.lastPathComponent();
- NSString pathOnly = filename.stringByDeletingLastPathComponent();
-
- if (i == 0) {
- /* Filter path */
- filterPath = pathOnly.getString();
-
- /* File name */
- fileName = fileNames [0] = filenameOnly.getString();
- } else {
- if (pathOnly.getString().equals (filterPath)) {
- fileNames [i] = filenameOnly.getString();
- } else {
- fileNames [i] = filename.getString();
- }
- }
- }
- }
- filterIndex = -1;
- }
- if (popup != null) {
- filterIndex = (int)/*64*/popup.indexOfSelectedItem();
- panel.setAccessoryView(null);
- popup.release();
- popup = null;
- }
- if (delegate != null) {
- panel.setDelegate(null);
- delegate.release();
- }
- if (jniRef != 0) OS.DeleteGlobalRef(jniRef);
- panel = null;
- return fullPath;
-}
-
-int /*long*/ _overwriteExistingFileCheck (int /*long*/ id, int /*long*/ sel, int /*long*/ str) {
- return 1;
-}
-
-int /*long*/ panel_shouldShowFilename (int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1) {
- NSString path = new NSString(arg1);
- if (filterExtensions != null && filterExtensions.length != 0) {
- NSFileManager manager = NSFileManager.defaultManager();
- int /*long*/ ptr = OS.malloc(1);
- boolean found = manager.fileExistsAtPath(path, ptr);
- byte[] isDirectory = new byte[1];
- OS.memmove(isDirectory, ptr, 1);
- OS.free(ptr);
- if (found) {
- if (isDirectory[0] != 0) {
- return 1;
- } else {
- NSString ext = path.pathExtension();
- if (ext != null) {
- int filterIndex = (int)/*64*/popup.indexOfSelectedItem();
- String extension = ext.getString();
- String extensions = filterExtensions [filterIndex];
- int start = 0, length = extensions.length ();
- while (start < length) {
- int index = extensions.indexOf (EXTENSION_SEPARATOR, start);
- if (index == -1) index = length;
- String filter = extensions.substring (start, index).trim ();
- if (filter.equals ("*") || filter.equals ("*.*")) return 1;
- if (filter.startsWith ("*.")) filter = filter.substring (2);
- if (filter.toLowerCase ().equals(extension.toLowerCase ())) return 1;
- start = index + 1;
- }
- }
- return 0;
- }
- }
- }
- return 1;
-}
-
-void sendSelection (int /*long*/ id, int /*long*/ sel, int /*long*/ arg) {
- panel.validateVisibleColumns();
-}
-
-/**
- * Set the initial filename which the dialog will
- * select by default when opened to the argument,
- * which may be null. The name will be prefixed with
- * the filter path when one is supplied.
- *
- * @param string the file name
- */
-public void setFileName (String string) {
- fileName = string;
-}
-
-/**
- * Set the file extensions which the dialog will
- * use to filter the files it shows to the argument,
- * which may be null.
- * <p>
- * The strings are platform specific. For example, on
- * some platforms, an extension filter string is typically
- * of the form "*.extension", where "*.*" matches all files.
- * For filters with multiple extensions, use semicolon as
- * a separator, e.g. "*.jpg;*.png".
- * </p>
- *
- * @param extensions the file extension filter
- *
- * @see #setFilterNames to specify the user-friendly
- * names corresponding to the extensions
- */
-public void setFilterExtensions (String [] extensions) {
- filterExtensions = extensions;
-}
-
-/**
- * Set the 0-based index of the file extension filter
- * which the dialog will use initially to filter the files
- * it shows to the argument.
- * <p>
- * This is an index into the FilterExtensions array and
- * the FilterNames array.
- * </p>
- *
- * @param index the file extension filter index
- *
- * @see #setFilterExtensions
- * @see #setFilterNames
- *
- * @since 3.4
- */
-public void setFilterIndex (int index) {
- filterIndex = index;
-}
-
-/**
- * Sets the names that describe the filter extensions
- * which the dialog will use to filter the files it shows
- * to the argument, which may be null.
- * <p>
- * Each name is a user-friendly short description shown for
- * its corresponding filter. The <code>names</code> array must
- * be the same length as the <code>extensions</code> array.
- * </p>
- *
- * @param names the list of filter names, or null for no filter names
- *
- * @see #setFilterExtensions
- */
-public void setFilterNames (String [] names) {
- filterNames = names;
-}
-
-/**
- * Sets the directory path that the dialog will use
- * to the argument, which may be null. File names in this
- * path will appear in the dialog, filtered according
- * to the filter extensions. If the string is null,
- * then the operating system's default filter path
- * will be used.
- * <p>
- * Note that the path string is platform dependent.
- * For convenience, either '/' or '\' can be used
- * as a path separator.
- * </p>
- *
- * @param string the directory path
- *
- * @see #setFilterExtensions
- */
-public void setFilterPath (String string) {
- filterPath = string;
-}
-
-/**
- * Sets the flag that the dialog will use to
- * determine whether to prompt the user for file
- * overwrite if the selected file already exists.
- *
- * @param overwrite true if the dialog will prompt for file overwrite, false otherwise
- *
- * @since 3.4
- */
-public void setOverwrite (boolean overwrite) {
- this.overwrite = overwrite;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/FontDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/FontDialog.java
deleted file mode 100755
index df410af548..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/FontDialog.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class allow the user to select a font
- * from all available fonts in the system.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class FontDialog extends Dialog {
- FontData fontData;
- RGB rgb;
- boolean selected;
- int fontID, fontSize;
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FontDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FontDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-void changeFont(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- selected = true;
-}
-
-/**
- * Returns a FontData object describing the font that was
- * selected in the dialog, or null if none is available.
- *
- * @return the FontData for the selected font, or null
- * @deprecated use #getFontList ()
- */
-public FontData getFontData () {
- return fontData;
-}
-
-/**
- * Returns a FontData set describing the font that was
- * selected in the dialog, or null if none is available.
- *
- * @return the FontData for the selected font, or null
- * @since 2.1.1
- */
-public FontData [] getFontList () {
- if (fontData == null) return null;
- FontData [] result = new FontData [1];
- result [0] = fontData;
- return result;
-}
-
-/**
- * Returns an RGB describing the color that was selected
- * in the dialog, or null if none is available.
- *
- * @return the RGB value for the selected color, or null
- *
- * @see PaletteData#getRGBs
- *
- * @since 2.1
- */
-public RGB getRGB () {
- return rgb;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a FontData object describing the font that was selected,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public FontData open () {
- Display display = parent != null ? parent.display : Display.getCurrent ();
- NSFontPanel panel = NSFontPanel.sharedFontPanel();
- panel.setTitle(NSString.stringWith(title != null ? title : ""));
- boolean create = fontData != null;
- Font font = create ? new Font(display, fontData) : display.getSystemFont();
- panel.setPanelFont(font.handle, false);
- SWTPanelDelegate delegate = (SWTPanelDelegate)new SWTPanelDelegate().alloc().init();
- int /*long*/ jniRef = OS.NewGlobalRef(this);
- if (jniRef == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.object_setInstanceVariable(delegate.id, Display.SWT_OBJECT, jniRef);
- panel.setDelegate(delegate);
- fontData = null;
- selected = false;
- panel.orderFront(null);
- NSApplication.sharedApplication().runModalForWindow(panel);
- if (selected) {
- NSFont nsFont = panel.panelConvertFont(font.handle);
- if (nsFont != null) {
- fontData = Font.cocoa_new(display, nsFont).getFontData()[0];
- }
- }
- panel.setDelegate(null);
- delegate.release();
- OS.DeleteGlobalRef(jniRef);
- if (create) font.dispose();
- return fontData;
-}
-
-/**
- * Sets a FontData object describing the font to be
- * selected by default in the dialog, or null to let
- * the platform choose one.
- *
- * @param fontData the FontData to use initially, or null
- * @deprecated use #setFontList (FontData [])
- */
-public void setFontData (FontData fontData) {
- this.fontData = fontData;
-}
-
-/**
- * Sets the set of FontData objects describing the font to
- * be selected by default in the dialog, or null to let
- * the platform choose one.
- *
- * @param fontData the set of FontData objects to use initially, or null
- * to let the platform select a default when open() is called
- *
- * @see Font#getFontData
- *
- * @since 2.1.1
- */
-public void setFontList (FontData [] fontData) {
- if (fontData != null && fontData.length > 0) {
- this.fontData = fontData [0];
- } else {
- this.fontData = null;
- }
-}
-
-/**
- * Sets the RGB describing the color to be selected by default
- * in the dialog, or null to let the platform choose one.
- *
- * @param rgb the RGB value to use initially, or null to let
- * the platform select a default when open() is called
- *
- * @see PaletteData#getRGBs
- *
- * @since 2.1
- */
-public void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-
-void windowWillClose(int /*long*/ id, int /*long*/ sel, int /*long*/ sender) {
- NSApplication.sharedApplication().stop(null);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Group.java
deleted file mode 100755
index e5b1dc262e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Group.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class provide an etched border
- * with an optional title.
- * <p>
- * Shadow styles are hints and may not be honoured
- * by the platform. To create a group with the
- * default shadow style for the platform, do not
- * specify a shadow style.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SHADOW_ETCHED_IN, SHADOW_ETCHED_OUT, SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the above styles may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Group extends Composite {
- NSView contentView;
- String text = "";
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SHADOW_ETCHED_IN
- * @see SWT#SHADOW_ETCHED_OUT
- * @see SWT#SHADOW_IN
- * @see SWT#SHADOW_OUT
- * @see SWT#SHADOW_NONE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Group (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
- NSBox widget = (NSBox)view;
- int border = (int)Math.ceil (widget.borderWidth ());
- NSSize margins = widget.contentViewMargins();
- NSRect frame = contentView.frame();
- width += (margins.width + border) * 2;
- height += (margins.height + border) * 2 + frame.y;
- return super.computeTrim(x, y, width, height);
-}
-
-NSView contentView () {
- return contentView;
-}
-
-void createHandle () {
- state |= THEME_BACKGROUND;
- NSBox widget = (NSBox)new SWTBox().alloc();
- widget.init();
- widget.setTitlePosition(OS.NSNoTitle);
- NSView contentWidget = (NSView)new SWTView().alloc();
- contentWidget.init();
-// contentWidget.setDrawsBackground(false);
- widget.setContentView(contentWidget);
- contentView = contentWidget;
- view = widget;
-}
-
-NSFont defaultNSFont () {
- return display.boxFont;
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (contentView);
- SWTBox box = (SWTBox)view;
- display.removeWidget (box.titleCell());
-}
-
-void drawBackground (int /*long*/ id, NSGraphicsContext context, NSRect rect) {
- if (id != view.id) return;
- fillBackground (view, context, rect, -1);
-}
-
-NSView eventView () {
- return contentView;
-}
-
-public Rectangle getClientArea () {
- checkWidget();
- NSRect rect = contentView.bounds();
- return new Rectangle((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which is the string that the
- * is used as the <em>title</em>. If the text has not previously
- * been set, returns an empty string.
- *
- * @return the text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-float getThemeAlpha () {
- return (background != null ? 1 : 0.25f) * parent.getThemeAlpha ();
-}
-
-void register () {
- super.register ();
- display.addWidget (contentView, this);
- SWTBox box = (SWTBox)view;
- display.addWidget (box.titleCell(), this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (contentView != null) contentView.release();
- contentView = null;
-}
-
-void setFont(NSFont font) {
- ((NSBox) view).setTitleFont(font);
-}
-
-void setForeground (float /*double*/ [] color) {
- NSColor nsColor;
- if (color == null) {
- nsColor = NSColor.textColor ();
- } else {
- nsColor = NSColor.colorWithDeviceRed (color[0], color[1], color[2], 1);
- }
- NSTextFieldCell cell = new NSTextFieldCell (((NSBox)view).titleCell ().id);
- cell.setTextColor (nsColor);
-}
-
-/**
- * Sets the receiver's text, which is the string that will
- * be displayed as the receiver's <em>title</em>, to the argument,
- * which may not be null. The string may include the mnemonic character.
- * </p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, focus is assigned
- * to the first child of the group. On most platforms, the
- * mnemonic appears underlined but may be emphasised in a
- * platform specific manner. The mnemonic indicator character
- * '&amp;' can be escaped by doubling it in the string, causing
- * a single '&amp;' to be displayed.
- * </p>
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- text = string;
- char [] buffer = new char [text.length ()];
- text.getChars (0, buffer.length, buffer, 0);
- int length = fixMnemonic (buffer);
- NSBox box = (NSBox)view;
- box.setTitlePosition(length == 0 ? OS.NSNoTitle : OS.NSAtTop);
- box.setTitle(NSString.stringWithCharacters(buffer, length));
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/IME.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/IME.java
deleted file mode 100644
index f6c09b0693..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/IME.java
+++ /dev/null
@@ -1,510 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class represent input method editors.
- * These are typically in-line pre-edit text areas that allow
- * the user to compose characters from Far Eastern languages
- * such as Japanese, Chinese or Korean.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>ImeComposition</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.4
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class IME extends Widget {
- Canvas parent;
- int caretOffset;
- int startOffset;
- int commitCount;
- String text;
- int [] ranges;
- TextStyle [] styles;
-
- static final int UNDERLINE_THICK = 1 << 16;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-IME () {
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a canvas control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public IME (Canvas parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget ();
-}
-
-int /*long*/ attributedSubstringFromRange (int /*long*/ id, int /*long*/ sel, int /*long*/ rangePtr) {
- Event event = new Event ();
- event.detail = SWT.COMPOSITION_SELECTION;
- sendEvent (SWT.ImeComposition, event);
- NSRange range = new NSRange ();
- OS.memmove (range, rangePtr, NSRange.sizeof);
- int start = (int)/*64*/range.location;
- int end = (int)/*64*/(range.location + range.length);
- if (event.start <= start && start <= event.end && event.start <= end && end <= event.end) {
- NSString str = NSString.stringWith (event.text.substring(start - event.start, end - event.start));
- NSAttributedString attriStr = ((NSAttributedString)new NSAttributedString().alloc()).initWithString(str, null);
- attriStr.autorelease ();
- return attriStr.id;
- }
- return 0;
-}
-
-int /*long*/ characterIndexForPoint (int /*long*/ id, int /*long*/ sel, int /*long*/ point) {
- if (!isInlineEnabled ()) return OS.NSNotFound;
- NSPoint pt = new NSPoint ();
- OS.memmove (pt, point, NSPoint.sizeof);
- NSView view = parent.view;
- pt = view.window ().convertScreenToBase (pt);
- pt = view.convertPoint_fromView_ (pt, null);
- Event event = new Event ();
- event.detail = SWT.COMPOSITION_OFFSET;
- event.x = (int) pt.x;
- event.y = (int) pt.y;
- sendEvent (SWT.ImeComposition, event);
- int offset = event.index + event.count;
- return offset != -1 ? offset : OS.NSNotFound;
-}
-
-void createWidget () {
- text = "";
- startOffset = -1;
- if (parent.getIME () == null) {
- parent.setIME (this);
- }
-}
-
-NSRect firstRectForCharacterRange(int /*long*/ id, int /*long*/ sel, int /*long*/ range) {
- NSRect rect = new NSRect ();
- Caret caret = parent.caret;
- if (caret != null) {
- NSView view = parent.view;
- NSPoint pt = new NSPoint ();
- pt.x = caret.x;
- pt.y = caret.y + caret.height;
- pt = view.convertPoint_toView_ (pt, null);
- pt = view.window ().convertBaseToScreen (pt);
- rect.x = pt.x;
- rect.y = pt.y;
- rect.width = caret.width;
- rect.height = caret.height;
- }
- return rect;
-}
-
-/**
- * Returns the offset of the caret from the start of the document.
- * The caret is within the current composition.
- *
- * @return the caret offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretOffset () {
- checkWidget ();
- return startOffset + caretOffset;
-}
-
-/**
- * Returns the commit count of the composition. This is the
- * number of characters that have been composed. When the
- * commit count is equal to the length of the composition
- * text, then the in-line edit operation is complete.
- *
- * @return the commit count
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see IME#getText
- */
-public int getCommitCount () {
- checkWidget ();
- return commitCount;
-}
-
-/**
- * Returns the offset of the composition from the start of the document.
- * This is the start offset of the composition within the document and
- * in not changed by the input method editor itself during the in-line edit
- * session.
- *
- * @return the offset of the composition
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCompositionOffset () {
- checkWidget ();
- return startOffset;
-}
-
-/**
- * Returns the ranges for the style that should be applied during the
- * in-line edit session.
- * <p>
- * The ranges array contains start and end pairs. Each pair refers to
- * the corresponding style in the styles array. For example, the pair
- * that starts at ranges[n] and ends at ranges[n+1] uses the style
- * at styles[n/2] returned by <code>getStyles()</code>.
- * </p>
- * @return the ranges for the styles
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see IME#getStyles
- */
-public int [] getRanges () {
- checkWidget ();
- if (ranges == null) return new int [0];
- int [] result = new int [ranges.length];
- for (int i = 0; i < result.length; i++) {
- result [i] = ranges [i] + startOffset;
- }
- return result;
-}
-
-/**
- * Returns the styles for the ranges.
- * <p>
- * The ranges array contains start and end pairs. Each pair refers to
- * the corresponding style in the styles array. For example, the pair
- * that starts at ranges[n] and ends at ranges[n+1] uses the style
- * at styles[n/2].
- * </p>
- *
- * @return the ranges for the styles
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see IME#getRanges
- */
-public TextStyle [] getStyles () {
- checkWidget ();
- if (styles == null) return new TextStyle [0];
- TextStyle [] result = new TextStyle [styles.length];
- System.arraycopy (styles, 0, result, 0, styles.length);
- return result;
-}
-
-TextStyle getStyle (NSDictionary attribs) {
- NSArray keys = attribs.allKeys ();
- int /*long*/ count = keys.count ();
- TextStyle style = new TextStyle ();
- for (int j = 0; j < count; j++) {
- NSString key = new NSString (keys.objectAtIndex (j));
- if (key.isEqualTo (OS.NSBackgroundColorAttributeName)) {
- NSColor color = new NSColor (attribs.objectForKey (key)).colorUsingColorSpaceName (OS.NSCalibratedRGBColorSpace);
- float /*double*/ [] rgbColor = new float /*double*/ []{color.redComponent(), color.greenComponent(), color.blueComponent(), color.alphaComponent()};
- style.background = Color.cocoa_new (display, rgbColor);
- } else if (key.isEqualTo (OS.NSForegroundColorAttributeName)) {
- NSColor color = new NSColor (attribs.objectForKey (key)).colorUsingColorSpaceName (OS.NSCalibratedRGBColorSpace);
- float /*double*/ [] rgbColor = new float /*double*/ []{color.redComponent(), color.greenComponent(), color.blueComponent(), color.alphaComponent()};
- style.foreground = Color.cocoa_new (display, rgbColor);
- } else if (key.isEqualTo (OS.NSUnderlineColorAttributeName)) {
- NSColor color = new NSColor (attribs.objectForKey (key)).colorUsingColorSpaceName (OS.NSCalibratedRGBColorSpace);
- float /*double*/ [] rgbColor = new float /*double*/ []{color.redComponent(), color.greenComponent(), color.blueComponent(), color.alphaComponent()};
- style.underlineColor = Color.cocoa_new (display, rgbColor);
- } else if (key.isEqualTo (OS.NSUnderlineStyleAttributeName)) {
- NSNumber value = new NSNumber (attribs.objectForKey (key));
- switch (value.intValue ()) {
- case OS.NSUnderlineStyleSingle: style.underlineStyle = SWT.UNDERLINE_SINGLE; break;
- case OS.NSUnderlineStyleDouble: style.underlineStyle = SWT.UNDERLINE_DOUBLE; break;
- case OS.NSUnderlineStyleThick: style.underlineStyle = UNDERLINE_THICK; break;
- }
- style.underline = value.intValue () != OS.NSUnderlineStyleNone;
- } else if (key.isEqualTo (OS.NSStrikethroughColorAttributeName)) {
- NSColor color = new NSColor (attribs.objectForKey (key)).colorUsingColorSpaceName (OS.NSCalibratedRGBColorSpace);
- float /*double*/ [] rgbColor = new float /*double*/ []{color.redComponent(), color.greenComponent(), color.blueComponent(), color.alphaComponent()};
- style.strikeoutColor = Color.cocoa_new (display, rgbColor);
- } else if (key.isEqualTo (OS.NSStrikethroughStyleAttributeName)) {
- NSNumber value = new NSNumber (attribs.objectForKey (key));
- style.strikeout = value.intValue () != OS.NSUnderlineStyleNone;
- } else if (key.isEqualTo (OS.NSFontAttributeName)) {
- NSFont font = new NSFont (attribs.objectForKey (key));
- font.retain();
- style.font = Font.cocoa_new (display, font);
- }
- }
- return style;
-}
-
-/**
- * Returns the composition text.
- * <p>
- * The text for an IME is the characters in the widget that
- * are in the current composition. When the commit count is
- * equal to the length of the composition text, then the
- * in-line edit operation is complete.
- * </p>
- *
- * @return the widget text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-/**
- * Returns <code>true</code> if the caret should be wide, and
- * <code>false</code> otherwise. In some languages, for example
- * Korean, the caret is typically widened to the width of the
- * current character in the in-line edit session.
- *
- * @return the wide caret state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getWideCaret() {
- return false;
-}
-
-boolean hasMarkedText (int /*long*/ id, int /*long*/ sel) {
- return text.length () != 0;
-}
-
-boolean insertText (int /*long*/ id, int /*long*/ sel, int /*long*/ string) {
- if (startOffset == -1) return true;
- NSString str = new NSString (string);
- if (str.isKindOfClass (OS.objc_getClass ("NSAttributedString"))) {
- str = new NSAttributedString (string).string ();
- }
- int length = (int)/*64*/str.length ();
- int end = startOffset + text.length ();
- resetStyles ();
- caretOffset = commitCount = length;
- Event event = new Event ();
- event.detail = SWT.COMPOSITION_CHANGED;
- event.start = startOffset;
- event.end = end;
- event.text = text = str.getString();
- sendEvent (SWT.ImeComposition, event);
- text = "";
- caretOffset = commitCount = 0;
- startOffset = -1;
- return event.doit;
-}
-
-boolean isInlineEnabled () {
- return hooks (SWT.ImeComposition);
-}
-
-NSRange markedRange (int /*long*/ id, int /*long*/ sel) {
- NSRange range = new NSRange ();
- if (startOffset != -1) {
- range.location = startOffset;
- range.length = text.length ();
- } else {
- range.location = OS.NSNotFound;
- }
- return range;
-}
-
-void resetStyles () {
- if (styles != null) {
- for (int i = 0; i < styles.length; i++) {
- TextStyle style = styles [i];
- Font font = style.font;
- if (font != null) font.handle.release ();
- }
- }
- styles = null;
- ranges = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (this == parent.getIME ()) parent.setIME (null);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
- text = null;
- resetStyles ();
-}
-
-NSRange selectedRange (int /*long*/ id, int /*long*/ sel) {
- Event event = new Event ();
- event.detail = SWT.COMPOSITION_SELECTION;
- sendEvent (SWT.ImeComposition, event);
- NSRange range = new NSRange ();
- range.location = event.start;
- range.length = event.text.length ();
- return range;
-}
-
-/**
- * Sets the offset of the composition from the start of the document.
- * This is the start offset of the composition within the document and
- * in not changed by the input method editor itself during the in-line edit
- * session but may need to be changed by clients of the IME. For example,
- * if during an in-line edit operation, a text editor inserts characters
- * above the IME, then the IME must be informed that the composition
- * offset has changed.
- *
- * @param offset the offset of the composition
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCompositionOffset (int offset) {
- checkWidget ();
- if (offset < 0) return;
- if (startOffset != -1) {
- startOffset = offset;
- }
-}
-
-boolean setMarkedText_selectedRange (int /*long*/ id, int /*long*/ sel, int /*long*/ string, int /*long*/ selRange) {
- if (!isInlineEnabled ()) return true;
- resetStyles ();
- caretOffset = commitCount = 0;
- int end = startOffset + text.length ();
- if (startOffset == -1) {
- Event event = new Event ();
- event.detail = SWT.COMPOSITION_SELECTION;
- sendEvent (SWT.ImeComposition, event);
- startOffset = event.start;
- end = event.end;
- }
- NSString str = new NSString (string);
- if (str.isKindOfClass (OS.objc_getClass ("NSAttributedString"))) {
- NSAttributedString attribStr = new NSAttributedString (string);
- str = attribStr.string ();
- int length = (int)/*64*/str.length ();
- styles = new TextStyle [length];
- ranges = new int [length * 2];
- NSRange rangeLimit = new NSRange (), effectiveRange = new NSRange ();
- rangeLimit.length = length;
- int rangeCount = 0;
- int /*long*/ ptr = OS.malloc (NSRange.sizeof);
- for (int i = 0; i < length;) {
- NSDictionary attribs = attribStr.attributesAtIndex(i, ptr, rangeLimit);
- OS.memmove (effectiveRange, ptr, NSRange.sizeof);
- i = (int)/*64*/(effectiveRange.location + effectiveRange.length);
- ranges [rangeCount * 2] = (int)/*64*/effectiveRange.location;
- ranges [rangeCount * 2 + 1] = (int)/*64*/(effectiveRange.location + effectiveRange.length - 1);
- styles [rangeCount++] = getStyle (attribs);
- }
- OS.free (ptr);
- if (rangeCount != styles.length) {
- TextStyle [] newStyles = new TextStyle [rangeCount];
- System.arraycopy (styles, 0, newStyles, 0, newStyles.length);
- styles = newStyles;
- int [] newRanges = new int [rangeCount * 2];
- System.arraycopy (ranges, 0, newRanges, 0, newRanges.length);
- ranges = newRanges;
- }
- }
- int length = (int)/*64*/str.length ();
- if (ranges == null && length > 0) {
- styles = new TextStyle []{getStyle (display.markedAttributes)};
- ranges = new int[]{0, length - 1};
- }
- NSRange range = new NSRange ();
- OS.memmove (range, selRange, NSRange.sizeof);
- caretOffset = (int)/*64*/range.location;
- Event event = new Event ();
- event.detail = SWT.COMPOSITION_CHANGED;
- event.start = startOffset;
- event.end = end;
- event.text = text = str.getString();
- sendEvent (SWT.ImeComposition, event);
- if (isDisposed ()) return false;
- if (text.length () == 0) {
- Shell s = parent.getShell ();
- s.keyInputHappened = true;
- startOffset = -1;
- resetStyles ();
- }
- return true;
-}
-
-int /*long*/ validAttributesForMarkedText (int /*long*/ id, int /*long*/ sel) {
- NSMutableArray attribs = NSMutableArray.arrayWithCapacity (6);
- attribs.addObject (new NSString (OS.NSForegroundColorAttributeName ()));
- attribs.addObject (new NSString (OS.NSBackgroundColorAttributeName ()));
- attribs.addObject (new NSString (OS.NSUnderlineStyleAttributeName ()));
- attribs.addObject (new NSString (OS.NSUnderlineColorAttributeName ()));
- attribs.addObject (new NSString (OS.NSStrikethroughStyleAttributeName ()));
- attribs.addObject (new NSString (OS.NSStrikethroughColorAttributeName ()));
- return attribs.id;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java
deleted file mode 100755
index 2afd1625e8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java
+++ /dev/null
@@ -1,521 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.accessibility.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class represent a non-selectable
- * user interface object that displays a string or image.
- * When SEPARATOR is specified, displays a single
- * vertical or horizontal line.
- * <p>
- * Shadow styles are hints and may not be honored
- * by the platform. To create a separator label
- * with the default shadow style for the platform,
- * do not specify a shadow style.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SEPARATOR, HORIZONTAL, VERTICAL</dd>
- * <dd>SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd>
- * <dd>CENTER, LEFT, RIGHT, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of SHADOW_IN, SHADOW_OUT and SHADOW_NONE may be specified.
- * SHADOW_NONE is a HINT. Only one of HORIZONTAL and VERTICAL may be specified.
- * Only one of CENTER, LEFT and RIGHT may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#label">Label snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Label extends Control {
- String text;
- Image image;
- boolean isImage;
- NSTextField textView;
- NSImageView imageView;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SEPARATOR
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#SHADOW_IN
- * @see SWT#SHADOW_OUT
- * @see SWT#SHADOW_NONE
- * @see SWT#CENTER
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#WRAP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Label (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-int /*long*/ accessibilityAttributeNames(int /*long*/ id, int /*long*/ sel) {
- if (accessible != null) {
- if ((textView != null && (id == textView.id || id == textView.cell().id)) || (imageView != null && (id == imageView.id || id == imageView.cell().id))) {
- // See if the accessible will override or augment the standard list.
- // Help, title, and description can be overridden.
- NSMutableArray extraAttributes = NSMutableArray.arrayWithCapacity(3);
- extraAttributes.addObject(OS.NSAccessibilityHelpAttribute);
- extraAttributes.addObject(OS.NSAccessibilityDescriptionAttribute);
- extraAttributes.addObject(OS.NSAccessibilityTitleAttribute);
-
- for (int i = (int)/*64*/extraAttributes.count() - 1; i >= 0; i--) {
- NSString attribute = new NSString(extraAttributes.objectAtIndex(i).id);
- if (accessible.internal_accessibilityAttributeValue(attribute, ACC.CHILDID_SELF) == null) {
- extraAttributes.removeObjectAtIndex(i);
- }
- }
-
- if (extraAttributes.count() > 0) {
- int /*long*/ superResult = super.accessibilityAttributeNames(id, sel);
- NSArray baseAttributes = new NSArray(superResult);
- NSMutableArray mutableAttributes = NSMutableArray.arrayWithCapacity(baseAttributes.count() + 1);
- mutableAttributes.addObjectsFromArray(baseAttributes);
-
- for (int i = 0; i < extraAttributes.count(); i++) {
- id currAttribute = extraAttributes.objectAtIndex(i);
- if (!mutableAttributes.containsObject(currAttribute)) {
- mutableAttributes.addObject(currAttribute);
- }
- }
-
- return mutableAttributes.id;
- }
- }
- }
-
- return super.accessibilityAttributeNames(id, sel);
-}
-
-boolean accessibilityIsIgnored(int /*long*/ id, int /*long*/ sel) {
- if (id == view.id) return true;
- return super.accessibilityIsIgnored(id, sel);
-}
-
-void addRelation (Control control) {
- if (!control.isDescribedByLabel ()) return;
-
- if (textView != null) {
- NSObject accessibleElement = control.focusView();
-
- if (accessibleElement instanceof NSControl) {
- NSControl viewAsControl = (NSControl)accessibleElement;
- if (viewAsControl.cell() != null) accessibleElement = viewAsControl.cell();
- }
-
- accessibleElement.accessibilitySetOverrideValue(textView.cell(), OS.NSAccessibilityTitleUIElementAttribute);
- NSArray controlArray = NSArray.arrayWithObject(accessibleElement);
- textView.cell().accessibilitySetOverrideValue(controlArray, OS.NSAccessibilityServesAsTitleForUIElementsAttribute);
- }
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- if ((style & SWT.SEPARATOR) != 0) {
- style = checkBits (style, SWT.VERTICAL, SWT.HORIZONTAL, 0, 0, 0, 0);
- return checkBits (style, SWT.SHADOW_OUT, SWT.SHADOW_IN, SWT.SHADOW_NONE, 0, 0, 0);
- }
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = DEFAULT_WIDTH;
- int height = DEFAULT_HEIGHT;
- if ((style & SWT.SEPARATOR) != 0) {
- float /*double*/ lineWidth = ((NSBox)view).borderWidth ();
- if ((style & SWT.HORIZONTAL) != 0) {
- height = (int)Math.ceil (lineWidth * 2);
- } else {
- width = (int)Math.ceil (lineWidth * 2);
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2; height += border * 2;
- return new Point (width, height);
- }
- if (isImage) {
- if (image != null) {
- NSImage nsimage = image.handle;
- NSSize size = nsimage.size ();
- width = (int)size.width;
- height = (int)size.height;
- } else {
- width = height = 0;
- }
- } else {
- NSSize size = null;
- if ((style & SWT.WRAP) != 0 && wHint != SWT.DEFAULT) {
- NSRect rect = new NSRect ();
- rect.width = wHint;
- rect.height = hHint != SWT.DEFAULT ? hHint : Float.MAX_VALUE;
- size = textView.cell ().cellSizeForBounds (rect);
- } else {
- size = textView.cell ().cellSize ();
- }
- width = (int)Math.ceil (size.width);
- height = (int)Math.ceil (size.height);
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- return new Point (width, height);
-}
-
-void createHandle () {
- state |= THEME_BACKGROUND;
- NSBox widget = (NSBox)new SWTBox().alloc();
- widget.init();
- widget.setTitle(NSString.stringWith(""));
- if ((style & SWT.SEPARATOR) != 0) {
- widget.setBoxType(OS.NSBoxSeparator);
- NSView child = (NSView) new SWTView().alloc().init();
- widget.setContentView(child);
- child.release();
- } else {
- widget.setBorderType(OS.NSNoBorder);
- widget.setBorderWidth (0);
- widget.setBoxType (OS.NSBoxCustom);
- NSSize offsetSize = new NSSize ();
- widget.setContentViewMargins (offsetSize);
-
- NSImageView imageWidget = (NSImageView) new SWTImageView ().alloc ();
- imageWidget.init();
- imageWidget.setImageScaling (OS.NSScaleNone);
-
- NSTextField textWidget = (NSTextField)new SWTTextField().alloc();
- textWidget.init();
- textWidget.setBordered(false);
- textWidget.setEditable(false);
- textWidget.setDrawsBackground(false);
- NSTextFieldCell cell = new NSTextFieldCell(textWidget.cell());
- cell.setWraps ((style & SWT.WRAP) != 0);
-
- widget.addSubview(imageWidget);
- widget.addSubview(textWidget);
- widget.setContentView(textWidget);
-
- imageView = imageWidget;
- textView = textWidget;
- _setAlignment();
- }
- view = widget;
-}
-
-void createWidget() {
- text = "";
- super.createWidget ();
-}
-
-NSAttributedString createString() {
- NSAttributedString attribStr = createString(text, null, foreground, (style & SWT.WRAP) == 0 ? style : 0, true, true);
- attribStr.autorelease();
- return attribStr;
-}
-
-NSFont defaultNSFont () {
- return display.textFieldFont;
-}
-
-void deregister () {
- super.deregister ();
- if (textView != null) {
- display.removeWidget(textView);
- display.removeWidget(textView.cell());
- }
- if (imageView != null) {
- display.removeWidget (imageView);
- display.removeWidget (imageView.cell());
- }
-}
-
-NSView eventView () {
- return ((NSBox)view).contentView();
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is a <code>SEPARATOR</code> label, in
- * which case, <code>NONE</code> is returned.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-/**
- * Returns the receiver's image if it has one, or null
- * if it does not.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set or if the receiver is
- * a <code>SEPARATOR</code> label.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return "";
- return text;
-}
-
-boolean isDescribedByLabel () {
- return false;
-}
-
-void register () {
- super.register ();
- if (textView != null) {
- display.addWidget (textView, this);
- display.addWidget (textView.cell(), this);
- }
- if (imageView != null) {
- display.addWidget (imageView, this);
- display.addWidget (imageView.cell(), this);
- }
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (textView != null) textView.release();
- if (imageView != null) imageView.release();
- textView = null;
- imageView = null;
-}
-
-/*
- * Remove "Labeled by" relations from the receiver.
- */
-void removeRelation () {
- if (textView != null) {
- textView.cell().accessibilitySetOverrideValue(null, OS.NSAccessibilityServesAsTitleForUIElementsAttribute);
- }
-}
-
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>. If the receiver is a <code>SEPARATOR</code>
- * label, the argument is ignored and the alignment is not changed.
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return;
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- _setAlignment();
-}
-
-void updateBackground () {
- if ((style & SWT.SEPARATOR) != 0) return;
- NSColor nsColor = null;
- if (backgroundImage != null) {
- nsColor = NSColor.colorWithPatternImage(backgroundImage.handle);
- } else if (background != null) {
- nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]);
- } else {
- nsColor = NSColor.clearColor();
- }
- ((NSBox)view).setFillColor(nsColor);
-}
-
-void _setAlignment() {
- if (image != null) {
- if ((style & SWT.RIGHT) != 0) imageView.setImageAlignment(OS.NSImageAlignRight);
- if ((style & SWT.LEFT) != 0) imageView.setImageAlignment(OS.NSImageAlignLeft);
- if ((style & SWT.CENTER) != 0) imageView.setImageAlignment(OS.NSImageAlignCenter);
- }
- if (text != null) {
- NSCell cell = new NSCell(textView.cell());
- cell.setAttributedStringValue(createString());
- }
-}
-
-void setFont(NSFont font) {
- if (textView != null) {
- NSCell cell = new NSCell(textView.cell());
- cell.setAttributedStringValue(createString());
- textView.setFont (font);
- }
-}
-
-void setForeground (float /*double*/ [] color) {
- if ((style & SWT.SEPARATOR) != 0) return;
- NSCell cell = new NSCell(textView.cell());
- cell.setAttributedStringValue(createString());
-}
-
-boolean setTabItemFocus () {
- return false;
-}
-
-/**
- * Sets the receiver's image to the argument, which may be
- * null indicating that no image should be displayed.
- *
- * @param image the image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return;
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.image = image;
- isImage = true;
-
- /*
- * Feature in Cocoa. If the NSImage object being set into the view is
- * the same NSImage object that is already there then the new image is
- * not taken. This results in the view's image not changing even if the
- * NSImage object's content has changed since it was last set into the
- * view. The workaround is to temporarily set the view's image to null
- * so that the new image will then be taken.
- */
- if (image != null) {
- NSImage current = imageView.image ();
- if (current != null && current.id == image.handle.id) {
- imageView.setImage (null);
- }
- }
- imageView.setImage(image != null ? image.handle : null);
- ((NSBox)view).setContentView(imageView);
-}
-
-/**
- * Sets the receiver's text.
- * <p>
- * This method sets the widget label. The label may include
- * the mnemonic character and line delimiters.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, focus is assigned
- * to the control that follows the label. On most platforms,
- * the mnemonic appears underlined but may be emphasised in a
- * platform specific manner. The mnemonic indicator character
- * '&amp;' can be escaped by doubling it in the string, causing
- * a single '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- isImage = false;
- text = string;
- NSCell cell = new NSCell(textView.cell());
- cell.setAttributedStringValue(createString());
- ((NSBox)view).setContentView(textView);
-}
-
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Link.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Link.java
deleted file mode 100755
index 18210ff412..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Link.java
+++ /dev/null
@@ -1,532 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.cocoa.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable
- * user interface object that displays a text with
- * links.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#link">Link snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Link extends Control {
- NSScrollView scrollView;
- String text;
- Point [] offsets;
- Point selection;
- String [] ids;
- int [] mnemonics;
- NSColor linkColor;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Link (Composite parent, int style) {
- super (parent, style);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected by the user.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-boolean textView_clickOnLink_atIndex(int /*long*/ id, int /*long*/ sel, int /*long*/ textView, int /*long*/ link, int /*long*/ charIndex) {
- NSString str = new NSString (link);
- Event event = new Event ();
- event.text = str.getString();
- sendEvent (SWT.Selection, event);
- return true;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- int width, height;
- //TODO wrapping, wHint
- int borderStyle = hasBorder() ? OS.NSBezelBorder : OS.NSNoBorder;
- NSSize borderSize = NSScrollView.frameSizeForContentSize(new NSSize(), false, false, borderStyle);
- NSTextView widget = (NSTextView)view;
- NSSize size = widget.textStorage().size();
- width = (int)(size.width + borderSize.width);
- height = (int)(size.height + borderSize.height);
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2;
- height += border * 2;
-
- // TODO is this true? if so, can this rounding be turned off?
- /*
- * Bug in Cocoa. NSTextStorage.size() seems to return a width
- * value that is rounded down, because its result is never
- * fractional. The workaround is to increment width by 1
- * to ensure that it is wide enough to show the full text.
- */
- width += 1;
- return new Point (width, height);
-}
-
-void createHandle () {
- state |= THEME_BACKGROUND;
- NSScrollView scrollWidget = (NSScrollView)new SWTScrollView().alloc();
- scrollWidget.init();
- scrollWidget.setDrawsBackground(false);
- scrollWidget.setBorderType(hasBorder() ? OS.NSBezelBorder : OS.NSNoBorder);
-
- NSTextView widget = (NSTextView)new SWTTextView().alloc();
- widget.init();
- widget.setEditable(false);
- widget.setDrawsBackground(false);
- widget.setDelegate(widget);
- widget.setAutoresizingMask (OS.NSViewWidthSizable | OS.NSViewHeightSizable);
- widget.textContainer().setLineFragmentPadding(0);
-
- scrollView = scrollWidget;
- view = widget;
-}
-
-void createWidget () {
- super.createWidget ();
- text = "";
- NSDictionary dict = ((NSTextView)view).linkTextAttributes();
- linkColor = new NSColor(dict.valueForKey(OS.NSForegroundColorAttributeName));
-}
-
-NSFont defaultNSFont () {
- return display.textViewFont;
-}
-
-void deregister () {
- super.deregister ();
- if (scrollView != null) display.removeWidget (scrollView);
-}
-
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- NSColor nsColor = null;
- if (enabled) {
- if (foreground == null) {
- nsColor = NSColor.textColor ();
- } else {
- nsColor = NSColor.colorWithDeviceRed (foreground [0], foreground [1], foreground [2], foreground[3]);
- }
- } else {
- nsColor = NSColor.disabledControlTextColor();
- }
- NSTextView widget = (NSTextView)view;
- widget.setTextColor(nsColor);
- NSDictionary linkTextAttributes = widget.linkTextAttributes();
- int count = (int)/*64*/linkTextAttributes.count();
- NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity(count);
- dict.setDictionary(linkTextAttributes);
- dict.setValue(enabled ? linkColor : nsColor, OS.NSForegroundColorAttributeName);
- widget.setLinkTextAttributes(dict);
-}
-
-String getNameText () {
- return getText ();
-}
-
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-void register () {
- super.register ();
- if (scrollView != null) display.addWidget (scrollView, this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- offsets = null;
- ids = null;
- mnemonics = null;
- text = null;
- linkColor = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection, listener);
-}
-
-String parse (String string) {
- int length = string.length ();
- offsets = new Point [length / 4];
- ids = new String [length / 4];
- mnemonics = new int [length / 4 + 1];
- StringBuffer result = new StringBuffer ();
- char [] buffer = new char [length];
- string.getChars (0, string.length (), buffer, 0);
- int index = 0, state = 0, linkIndex = 0;
- int start = 0, tagStart = 0, linkStart = 0, endtagStart = 0, refStart = 0;
- while (index < length) {
- char c = Character.toLowerCase (buffer [index]);
- switch (state) {
- case 0:
- if (c == '<') {
- tagStart = index;
- state++;
- }
- break;
- case 1:
- if (c == 'a') state++;
- break;
- case 2:
- switch (c) {
- case 'h':
- state = 7;
- break;
- case '>':
- linkStart = index + 1;
- state++;
- break;
- default:
- if (Character.isWhitespace(c)) break;
- else state = 13;
- }
- break;
- case 3:
- if (c == '<') {
- endtagStart = index;
- state++;
- }
- break;
- case 4:
- state = c == '/' ? state + 1 : 3;
- break;
- case 5:
- state = c == 'a' ? state + 1 : 3;
- break;
- case 6:
- if (c == '>') {
- mnemonics [linkIndex] = parseMnemonics (buffer, start, tagStart, result);
- int offset = result.length ();
- parseMnemonics (buffer, linkStart, endtagStart, result);
- offsets [linkIndex] = new Point (offset, result.length () - 1);
- if (ids [linkIndex] == null) {
- ids [linkIndex] = new String (buffer, linkStart, endtagStart - linkStart);
- }
- linkIndex++;
- start = tagStart = linkStart = endtagStart = refStart = index + 1;
- state = 0;
- } else {
- state = 3;
- }
- break;
- case 7:
- state = c == 'r' ? state + 1 : 0;
- break;
- case 8:
- state = c == 'e' ? state + 1 : 0;
- break;
- case 9:
- state = c == 'f' ? state + 1 : 0;
- break;
- case 10:
- state = c == '=' ? state + 1 : 0;
- break;
- case 11:
- if (c == '"') {
- state++;
- refStart = index + 1;
- } else {
- state = 0;
- }
- break;
- case 12:
- if (c == '"') {
- ids[linkIndex] = new String (buffer, refStart, index - refStart);
- state = 2;
- }
- break;
- case 13:
- if (Character.isWhitespace (c)) {
- state = 0;
- } else if (c == '='){
- state++;
- }
- break;
- case 14:
- state = c == '"' ? state + 1 : 0;
- break;
- case 15:
- if (c == '"') state = 2;
- break;
- default:
- state = 0;
- break;
- }
- index++;
- }
- if (start < length) {
- int tmp = parseMnemonics (buffer, start, tagStart, result);
- int mnemonic = parseMnemonics (buffer, Math.max (tagStart, linkStart), length, result);
- if (mnemonic == -1) mnemonic = tmp;
- mnemonics [linkIndex] = mnemonic;
- } else {
- mnemonics [linkIndex] = -1;
- }
- if (offsets.length != linkIndex) {
- Point [] newOffsets = new Point [linkIndex];
- System.arraycopy (offsets, 0, newOffsets, 0, linkIndex);
- offsets = newOffsets;
- String [] newIDs = new String [linkIndex];
- System.arraycopy (ids, 0, newIDs, 0, linkIndex);
- ids = newIDs;
- int [] newMnemonics = new int [linkIndex + 1];
- System.arraycopy (mnemonics, 0, newMnemonics, 0, linkIndex + 1);
- mnemonics = newMnemonics;
- }
- return result.toString ();
-}
-
-int parseMnemonics (char[] buffer, int start, int end, StringBuffer result) {
- int mnemonic = -1, index = start;
- while (index < end) {
- if (buffer [index] == '&') {
- if (index + 1 < end && buffer [index + 1] == '&') {
- result.append (buffer [index]);
- index++;
- } else {
- mnemonic = result.length();
- }
- } else {
- result.append (buffer [index]);
- }
- index++;
- }
- return mnemonic;
-}
-
-void updateBackground () {
- NSColor nsColor = null;
- if (backgroundImage != null) {
- nsColor = NSColor.colorWithPatternImage(backgroundImage.handle);
- } else if (background != null) {
- nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]);
- }
- setBackground(nsColor);
-}
-
-void setBackground(NSColor nsColor) {
- NSTextView widget = (NSTextView)view;
- if (nsColor == null) {
- widget.setDrawsBackground(false);
- } else {
- widget.setDrawsBackground(true);
- widget.setBackgroundColor (nsColor);
- }
-}
-
-void setFont(NSFont font) {
- ((NSTextView) view).setFont(font);
-}
-
-void setForeground (float /*double*/ [] color) {
- if (!getEnabled ()) return;
- NSColor nsColor;
- if (color == null) {
- nsColor = NSColor.textColor ();
- } else {
- nsColor = NSColor.colorWithDeviceRed (color [0], color [1], color [2], 1);
- }
- ((NSTextView) view).setTextColor (nsColor);
-}
-
-/**
- * Sets the receiver's text.
- * <p>
- * The string can contain both regular text and hyperlinks. A hyperlink
- * is delimited by an anchor tag, &lt;A&gt; and &lt;/A&gt;. Within an
- * anchor, a single HREF attribute is supported. When a hyperlink is
- * selected, the text field of the selection event contains either the
- * text of the hyperlink or the value of its HREF, if one was specified.
- * In the rare case of identical hyperlinks within the same string, the
- * HREF attribute can be used to distinguish between them. The string may
- * include the mnemonic character and line delimiters. The only delimiter
- * the HREF attribute supports is the quotation mark (").
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (string.equals (text)) return;
- text = string;
- NSTextView widget = (NSTextView)view;
- widget.setString(NSString.stringWith(parse(string)));
- NSTextStorage textStorage = widget.textStorage();
- NSRange range = new NSRange();
- for (int i = 0; i < offsets.length; i++) {
- range.location = offsets[i].x;
- range.length = offsets[i].y - offsets[i].x + 1;
- textStorage.addAttribute(OS.NSLinkAttributeName, NSString.stringWith(ids[i]), range);
- }
-}
-
-public void setToolTipText(String string) {
- ((NSTextView)view).setDisplaysLinkToolTips(string == null);
- super.setToolTipText(string);
-}
-
-void setZOrder () {
- super.setZOrder ();
- if (scrollView != null) scrollView.setDocumentView (view);
-}
-
-NSView topView () {
- return scrollView;
-}
-
-void updateCursorRects (boolean enabled) {
- super.updateCursorRects (enabled);
- if (scrollView == null) return;
- updateCursorRects (enabled, scrollView);
- NSClipView contentView = scrollView.contentView ();
- updateCursorRects (enabled, contentView);
- contentView.setDocumentCursor (enabled ? NSCursor.IBeamCursor () : null);
-}
-
-//int traversalCode (int key, int theEvent) {
-// if (offsets.length == 0) return 0;
-// int bits = super.traversalCode (key, theEvent);
-// if (key == 48 /* Tab */ && theEvent != 0) {
-// int [] modifiers = new int [1];
-// OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
-// boolean next = (modifiers [0] & OS.shiftKey) == 0;
-// if (next && focusIndex < offsets.length - 1) {
-// return bits & ~ SWT.TRAVERSE_TAB_NEXT;
-// }
-// if (!next && focusIndex > 0) {
-// return bits & ~ SWT.TRAVERSE_TAB_PREVIOUS;
-// }
-// }
-// return bits;
-//}
-
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/List.java
deleted file mode 100755
index efc9e9af66..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/List.java
+++ /dev/null
@@ -1,1429 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.accessibility.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class represent a selectable user interface
- * object that displays a list of strings and issues notification
- * when a string is selected. A list may be single or multi select.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection</dd>
- * </dl>
- * <p>
- * Note: Only one of SINGLE and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#list">List snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class List extends Scrollable {
- NSTableColumn column;
- String [] items;
- int itemCount;
- boolean ignoreSelect;
-
- static int NEXT_ID;
-
- static final int CELL_GAP = 1;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public List (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-int /*long*/ accessibilityAttributeValue (int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
-
- if (accessible != null) {
- NSString attribute = new NSString(arg0);
- id returnValue = accessible.internal_accessibilityAttributeValue(attribute, ACC.CHILDID_SELF);
- if (returnValue != null) return returnValue.id;
- }
-
- NSString attributeName = new NSString(arg0);
-
- // Accessibility Verifier queries for a title or description. NSOutlineView doesn't
- // seem to return either, so we return a default description value here.
- if (attributeName.isEqualToString (OS.NSAccessibilityDescriptionAttribute)) {
- return NSString.stringWith("").id;
- }
-
-// if (attributeName.isEqualToString(OS.NSAccessibilityHeaderAttribute)) {
-// /*
-// * Bug in the Macintosh. Even when the header is not visible,
-// * VoiceOver still reports each column header's role for every row.
-// * This is confusing and overly verbose. The fix is to return
-// * "no header" when the screen reader asks for the header, by
-// * returning noErr without setting the event parameter.
-// */
-// return 0;
-// }
-
- return super.accessibilityAttributeValue(id, sel, arg0);
-}
-
-/**
- * Adds the argument to the end of the receiver's list.
- *
- * @param string the new item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String,int)
- */
-public void add (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (itemCount == items.length) {
- String [] newItems = new String [itemCount + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- items [itemCount++] = string;
- ((NSTableView)view).noteNumberOfRowsChanged ();
- setScrollWidth(string);
-}
-
-/**
- * Adds the argument to the receiver's list at the given
- * zero-relative index.
- * <p>
- * Note: To add an item at the end of the list, use the
- * result of calling <code>getItemCount()</code> as the
- * index or use <code>add(String)</code>.
- * </p>
- *
- * @param string the new item
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String)
- */
-public void add (String string, int index) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (itemCount == items.length) {
- String [] newItems = new String [itemCount + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- System.arraycopy (items, index, items, index + 1, itemCount++ - index);
- items [index] = string;
- ((NSTableView)view).noteNumberOfRowsChanged ();
- if (index != itemCount) fixSelection (index, true);
- setScrollWidth(string);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the selection changes.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = 0;
- if (wHint == SWT.DEFAULT) {
- NSCell cell = column.dataCell ();
- Font font = this.font != null ? this.font : defaultFont ();
- cell.setFont (font.handle);
- for (int i = 0; i < items.length; i++) {
- if (items[i] != null) {
- cell.setTitle (NSString.stringWith (items[i]));
- NSSize size = cell.cellSize ();
- width = Math.max (width, (int)Math.ceil (size.width));
- }
- }
- width += CELL_GAP;
- } else {
- width = wHint;
- }
- if (width <= 0) width = DEFAULT_WIDTH;
- int height = 0;
- if (hHint == SWT.DEFAULT) {
- int itemHeight = getItemHeight () + CELL_GAP;
- height = itemCount * itemHeight;
- } else {
- height = hHint;
- }
- if (height <= 0) height = DEFAULT_HEIGHT;
- Rectangle rect = computeTrim (0, 0, width, height);
- return new Point (rect.width, rect.height);
-}
-
-void createHandle () {
- NSScrollView scrollWidget = (NSScrollView)new SWTScrollView().alloc();
- scrollWidget.init();
- if ((style & SWT.H_SCROLL) != 0) scrollWidget.setHasHorizontalScroller(true);
- if ((style & SWT.V_SCROLL) != 0) scrollWidget.setHasVerticalScroller(true);
- scrollWidget.setAutohidesScrollers(true);
- scrollWidget.setBorderType((style & SWT.BORDER) != 0 ? OS.NSBezelBorder : OS.NSNoBorder);
-
- NSTableView widget = (NSTableView)new SWTTableView().alloc();
- widget.init();
- widget.setAllowsMultipleSelection((style & SWT.MULTI) != 0);
- widget.setDataSource(widget);
- widget.setHeaderView(null);
- widget.setDelegate(widget);
- if ((style & SWT.H_SCROLL) != 0) {
- widget.setColumnAutoresizingStyle (OS.NSTableViewNoColumnAutoresizing);
- }
- NSSize spacing = new NSSize();
- spacing.width = spacing.height = CELL_GAP;
- widget.setIntercellSpacing(spacing);
- widget.setDoubleAction(OS.sel_sendDoubleSelection);
- if (!hasBorder()) widget.setFocusRingType(OS.NSFocusRingTypeNone);
-
- column = (NSTableColumn)new NSTableColumn().alloc();
- column = column.initWithIdentifier(NSString.stringWith(String.valueOf(++NEXT_ID)));
- column.setWidth(0);
- widget.addTableColumn (column);
-
- scrollView = scrollWidget;
- view = widget;
-}
-
-void createWidget () {
- super.createWidget ();
- items = new String [4];
-}
-
-Color defaultBackground () {
- return display.getWidgetColor (SWT.COLOR_LIST_BACKGROUND);
-}
-
-NSFont defaultNSFont () {
- return display.tableViewFont;
-}
-
-Color defaultForeground () {
- return display.getWidgetColor (SWT.COLOR_LIST_FOREGROUND);
-}
-
-/**
- * Deselects the item at the given zero-relative index in the receiver.
- * If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget();
- if (0 <= index && index < itemCount) {
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- widget.deselectRow (index);
- ignoreSelect = false;
- }
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. The range of the
- * indices is inclusive. Indices that are out of range are ignored.
- *
- * @param start the start index of the items to deselect
- * @param end the end index of the items to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int start, int end) {
- checkWidget();
- if (start > end) return;
- if (end < 0 || start >= itemCount) return;
- start = Math.max (0, start);
- end = Math.min (itemCount - 1, end);
- if (start == 0 && end == itemCount - 1) {
- deselectAll ();
- } else {
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- for (int i=start; i<=end; i++) {
- widget.deselectRow (i);
- }
- ignoreSelect = false;
- }
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. Indices that are out
- * of range and duplicate indices are ignored.
- *
- * @param indices the array of indices for the items to deselect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int [] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- for (int i=0; i<indices.length; i++) {
- widget.deselectRow (indices [i]);
- }
- ignoreSelect = false;
-}
-
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll () {
- checkWidget ();
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- widget.deselectAll(null);
- ignoreSelect = false;
-}
-
-boolean dragDetect(int x, int y, boolean filter, boolean[] consume) {
- NSTableView widget = (NSTableView)view;
- NSPoint pt = new NSPoint();
- pt.x = x;
- pt.y = y;
- int /*long*/ row = widget.rowAtPoint(pt);
- if (row == -1) return false;
- boolean dragging = super.dragDetect(x, y, filter, consume);
- if (dragging) {
- if (!widget.isRowSelected(row)) {
- //TODO expand current selection when Shift, Command key pressed??
- NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc();
- set = set.initWithIndex(row);
- widget.selectRowIndexes (set, false);
- set.release();
- }
- }
- consume[0] = dragging;
- return dragging;
-}
-
-void fixSelection (int index, boolean add) {
- int [] selection = getSelectionIndices ();
- if (selection.length == 0) return;
- int newCount = 0;
- boolean fix = false;
- for (int i = 0; i < selection.length; i++) {
- if (!add && selection [i] == index) {
- fix = true;
- } else {
- int newIndex = newCount++;
- selection [newIndex] = selection [i];
- if (selection [newIndex] >= index) {
- selection [newIndex] += add ? 1 : -1;
- fix = true;
- }
- }
- }
- if (fix) select (selection, newCount, true);
-}
-
-/**
- * Returns the zero-relative index of the item which currently
- * has the focus in the receiver, or -1 if no item has focus.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getFocusIndex () {
- checkWidget();
- return (int)/*64*/((NSTableView)view).selectedRow();
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getItem (int index) {
- checkWidget();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- return itemCount;
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the list.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- return (int)((NSTableView)view).rowHeight();
-}
-
-/**
- * Returns a (possibly empty) array of <code>String</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver's list
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getItems () {
- checkWidget();
- String [] result = new String [itemCount];
- System.arraycopy (items, 0, result, 0, itemCount);
- return result;
-}
-
-/**
- * Returns an array of <code>String</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getSelection () {
- checkWidget ();
- NSTableView widget = (NSTableView)view;
- if (widget.numberOfSelectedRows() == 0) {
- return new String [0];
- }
- NSIndexSet selection = widget.selectedRowIndexes();
- int count = (int)/*64*/selection.count();
- int /*long*/ [] indexBuffer = new int /*long*/ [count];
- selection.getIndexes(indexBuffer, count, 0);
- String [] result = new String [count];
- for (int i=0; i<count; i++) {
- result [i] = items [(int)/*64*/indexBuffer [i]];
- }
- return result;
-}
-
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget ();
- return (int)/*64*/((NSTableView)view).numberOfSelectedRows();
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item or -1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget();
- NSTableView widget = (NSTableView)view;
- if (widget.numberOfSelectedRows() == 0) {
- return -1;
- }
- NSIndexSet selection = widget.selectedRowIndexes();
- int count = (int)/*64*/selection.count();
- int /*long*/ [] result = new int /*long*/ [count];
- selection.getIndexes(result, count, 0);
- return (int)/*64*/result [0];
-}
-
-/**
- * Returns the zero-relative indices of the items which are currently
- * selected in the receiver. The order of the indices is unspecified.
- * The array is empty if no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return the array of indices of the selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int [] getSelectionIndices () {
- checkWidget ();
- NSTableView widget = (NSTableView)view;
- if (widget.numberOfSelectedRows() == 0) {
- return new int [0];
- }
- NSIndexSet selection = widget.selectedRowIndexes();
- int count = (int)/*64*/selection.count();
- int /*long*/ [] indices = new int /*long*/ [count];
- selection.getIndexes(indices, count, 0);
- int [] result = new int [count];
- for (int i = 0; i < result.length; i++) {
- result [i] = (int)/*64*/indices [i];
- }
- return result;
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items are
- * scrolled or new items are added or removed.
- *
- * @return the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget();
- //TODO - partial item at the top
- NSRect rect = scrollView.documentVisibleRect();
- NSPoint point = new NSPoint();
- point.x = rect.x;
- point.y = rect.y;
- int result = (int)/*64*/((NSTableView)view).rowAtPoint(point);
- if (result == -1) result = 0;
- return result;
-}
-
-/**
- * Gets the index of an item.
- * <p>
- * The list is searched starting at 0 until an
- * item is found that is equal to the search item.
- * If no item is found, -1 is returned. Indexing
- * is zero based.
- *
- * @param string the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<itemCount; i++) {
- if (items [i].equals (item)) return i;
- }
- return -1;
-}
-
-/**
- * Searches the receiver's list starting at the given,
- * zero-relative index until an item is found that is equal
- * to the argument, and returns the index of that item. If
- * no item is found or the starting index is out of range,
- * returns -1.
- *
- * @param string the search item
- * @param start the zero-relative index at which to start the search
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string, int start) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=start; i<itemCount; i++) {
- if (items [i].equals (string)) return i;
- }
- return -1;
-}
-
-/**
- * Returns <code>true</code> if the item is selected,
- * and <code>false</code> otherwise. Indices out of
- * range are ignored.
- *
- * @param index the index of the item
- * @return the selection state of the item at the index
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isSelected (int index) {
- checkWidget();
- if (!(0 <= index && index < itemCount)) return false;
- return ((NSTableView)view).isRowSelected(index);
-}
-
-/*
- * Feature in Cocoa: Table views do not change the selection when the user
- * right-clicks or control-clicks on an NSTableView or its subclasses. Fix is to select the
- * clicked-on row ourselves.
- */
-int /*long*/ menuForEvent(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- NSEvent event = new NSEvent(theEvent);
- NSTableView table = (NSTableView)view;
-
- // get the current selections for the outline view.
- NSIndexSet selectedRowIndexes = table.selectedRowIndexes();
-
- // select the row that was clicked before showing the menu for the event
- NSPoint mousePoint = view.convertPoint_fromView_(event.locationInWindow(), null);
- int /*long*/ row = table.rowAtPoint(mousePoint);
-
- // figure out if the row that was just clicked on is currently selected
- if (selectedRowIndexes.containsIndex(row) == false) {
- NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc();
- set = set.initWithIndex(row);
- table.selectRowIndexes (set, false);
- set.release();
- }
- // else that row is currently selected, so don't change anything.
-
- return super.menuForEvent(id, sel, theEvent);
-}
-
-int /*long*/ numberOfRowsInTableView(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView) {
- return itemCount;
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (column != null) column.release();
- column = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- items = null;
-}
-
-/**
- * Removes the item from the receiver at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- remove(index, true);
-}
-
-void remove (int index, boolean fixScroll) {
- if (index != itemCount - 1) fixSelection (index, false);
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- ((NSTableView)view).noteNumberOfRowsChanged();
- if (fixScroll) setScrollWidth();
-}
-
-/**
- * Removes the items from the receiver which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget();
- if (start > end) return;
- if (!(0 <= start && start <= end && end < itemCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int length = end - start + 1;
- for (int i=0; i<length; i++) remove (start, false);
- setScrollWidth();
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * until an item is found that is equal to the argument,
- * and removes that item from the list.
- *
- * @param string the item to remove
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = indexOf (string, 0);
- if (index == -1) error (SWT.ERROR_INVALID_ARGUMENT);
- remove (index);
-}
-
-/**
- * Removes the items from the receiver at the given
- * zero-relative indices.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- int [] newIndices = new int [indices.length];
- System.arraycopy (indices, 0, newIndices, 0, indices.length);
- sort (newIndices);
- int start = newIndices [newIndices.length - 1], end = newIndices [0];
- int count = getItemCount ();
- if (!(0 <= start && start <= end && end < count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int last = -1;
- for (int i=0; i<newIndices.length; i++) {
- int index = newIndices [i];
- if (index != last) {
- remove (index, false);
- last = index;
- }
- }
- setScrollWidth();
-}
-
-/**
- * Removes all of the items from the receiver.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget();
- items = new String [4];
- itemCount = 0;
- ((NSTableView)view).noteNumberOfRowsChanged();
- setScrollWidth();
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget();
- if (0 <= index && index < itemCount) {
- NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc();
- set = set.initWithIndex(index);
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- widget.selectRowIndexes(set, (style & SWT.MULTI) != 0);
- ignoreSelect = false;
- set.release();
- }
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If an item in the given range is not selected, it is selected.
- * If an item in the given range was already selected, it remains selected.
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#setSelection(int,int)
- */
-public void select (int start, int end) {
- checkWidget ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- if (itemCount == 0 || start >= itemCount) return;
- if (start == 0 && end == itemCount - 1) {
- selectAll ();
- } else {
- start = Math.max (0, start);
- end = Math.min (end, itemCount - 1);
- NSRange range = new NSRange();
- range.location = start;
- range.length = end - start + 1;
- NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc();
- set = set.initWithIndexesInRange(range);
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- widget.selectRowIndexes(set, (style & SWT.MULTI) != 0);
- ignoreSelect = false;
- set.release();
- }
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If the item at a given index is not selected, it is selected.
- * If the item at a given index was already selected, it remains selected.
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- *
- * @param indices the array of indices for the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#setSelection(int[])
- */
-public void select (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- int count = 0;
- NSMutableIndexSet set = (NSMutableIndexSet)new NSMutableIndexSet().alloc().init();
- for (int i=0; i<length; i++) {
- int index = indices [i];
- if (index >= 0 && index < itemCount) {
- set.addIndex (indices [i]);
- count++;
- }
- }
- if (count > 0) {
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- widget.selectRowIndexes(set, (style & SWT.MULTI) != 0);
- ignoreSelect = false;
- }
- set.release();
-}
-
-void select (int [] indices, int count, boolean clear) {
- NSMutableIndexSet set = (NSMutableIndexSet)new NSMutableIndexSet().alloc().init();
- for (int i=0; i<count; i++) set.addIndex (indices [i]);
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- widget.selectRowIndexes(set, !clear);
- ignoreSelect = false;
- set.release();
-}
-
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- widget.selectAll(null);
- ignoreSelect = false;
-}
-
-void sendDoubleSelection() {
- if (((NSTableView)view).clickedRow () != -1) {
- postEvent (SWT.DefaultSelection);
- }
-}
-
-boolean sendKeyEvent (NSEvent nsEvent, int type) {
- boolean result = super.sendKeyEvent (nsEvent, type);
- if (!result) return result;
- if (type != SWT.KeyDown) return result;
- short keyCode = nsEvent.keyCode ();
- switch (keyCode) {
- case 76: /* KP Enter */
- case 36: { /* Return */
- postEvent (SWT.DefaultSelection);
- break;
- }
- }
- return result;
-}
-
-void updateBackground () {
- NSColor nsColor = null;
- if (backgroundImage != null) {
- nsColor = NSColor.colorWithPatternImage(backgroundImage.handle);
- } else if (background != null) {
- nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]);
- }
- ((NSTableView) view).setBackgroundColor (nsColor);
-}
-
-void setFont (NSFont font) {
- super.setFont (font);
- float /*double*/ ascent = font.ascender ();
- float /*double*/ descent = -font.descender () + font.leading ();
- ((NSTableView)view).setRowHeight ((int)Math.ceil (ascent + descent) + 1);
- setScrollWidth();
-}
-
-/**
- * Sets the text of the item in the receiver's list at the given
- * zero-relative index to the string argument.
- *
- * @param index the index for the item
- * @param string the new text for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItem (int index, String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- items [index] = string;
- NSTableView tableView = (NSTableView)view;
- NSRect rect = tableView.rectOfRow (index);
- tableView.setNeedsDisplayInRect (rect);
- setScrollWidth(string);
-}
-
-/**
- * Sets the receiver's items to be the given array of items.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItems (String [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<items.length; i++) {
- if (items [i] == null) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.items = new String [items.length];
- System.arraycopy (items, 0, this.items, 0, items.length);
- itemCount = items.length;
- ((NSTableView)view).reloadData();
- setScrollWidth();
-}
-
-boolean setScrollWidth (String item) {
- if ((style & SWT.H_SCROLL) == 0) return false;
- NSCell cell = column.dataCell ();
- Font font = this.font != null ? this.font : defaultFont ();
- cell.setFont (font.handle);
- cell.setTitle (NSString.stringWith (item));
- NSSize size = cell.cellSize ();
- float /*double*/ oldWidth = column.width ();
- if (oldWidth < size.width) {
- column.setWidth (size.width);
- return true;
- }
- return false;
-}
-
-boolean setScrollWidth () {
- if ((style & SWT.H_SCROLL) == 0) return false;
- if (items == null) return false;
- NSCell cell = column.dataCell ();
- Font font = this.font != null ? this.font : defaultFont ();
- cell.setFont (font.handle);
- float /*double*/ width = 0;
- for (int i = 0; i < itemCount; i++) {
- cell.setTitle (NSString.stringWith (items[i]));
- NSSize size = cell.cellSize ();
- width = Math.max (width, size.width);
- }
- column.setWidth (width);
- return true;
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains selected.
- * The current selection is first cleared, then the new item is selected.
- * Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @see List#deselectAll()
- * @see List#select(int)
- */
-public void setSelection (int index) {
- checkWidget();
- deselectAll ();
- if (0 <= index && index < itemCount) {
- NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc();
- set = set.initWithIndex(index);
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- widget.selectRowIndexes(set, false);
- ignoreSelect = false;
- set.release();
- showIndex (index);
- }
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- *
- * @param start the start index of the items to select
- * @param end the end index of the items to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int,int)
- */
-public void setSelection (int start, int end) {
- checkWidget ();
- deselectAll ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- if (itemCount == 0 || start >= itemCount) return;
- start = Math.max (0, start);
- end = Math.min (end, itemCount - 1);
- NSRange range = new NSRange();
- range.location = start;
- range.length = end - start + 1;
- NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc();
- set = set.initWithIndexesInRange(range);
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- widget.selectRowIndexes(set, false);
- ignoreSelect = false;
- set.release();
- showIndex(end);
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- *
- * @param indices the indices of the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int[])
- */
-public void setSelection (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- int [] newIndices = new int [length];
- int count = 0;
- for (int i=0; i<length; i++) {
- int index = indices [length - i - 1];
- if (index >= 0 && index < itemCount) {
- newIndices [count++] = index;
- }
- }
- if (count > 0) {
- select (newIndices, count, true);
- showIndex (newIndices [0]);
- }
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int[])
- * @see List#setSelection(int[])
- */
-public void setSelection (String [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = items.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- int count = 0;
- int [] indices = new int [length];
- for (int i=0; i<length; i++) {
- String string = items [length - i - 1];
- if ((style & SWT.SINGLE) != 0) {
- int index = indexOf (string, 0);
- if (index != -1) {
- count = 1;
- indices = new int [] {index};
- }
- } else {
- int index = 0;
- while ((index = indexOf (string, index)) != -1) {
- if (count == indices.length) {
- int [] newIds = new int [indices.length + 4];
- System.arraycopy (indices, 0, newIds, 0, indices.length);
- indices = newIds;
- }
- indices [count++] = index;
- index++;
- }
- }
- }
- if (count > 0) {
- select (indices, count, true);
- showIndex (indices [0]);
- }
-}
-
-/**
- * Sets the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items
- * are scrolled or new items are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget();
- NSTableView widget = (NSTableView) view;
- int row = Math.max(0, Math.min(index, itemCount));
- NSPoint pt = new NSPoint();
- pt.x = scrollView.contentView().bounds().x;
- pt.y = widget.frameOfCellAtColumn(0, row).y;
- view.scrollPoint(pt);
-}
-
-void showIndex (int index) {
- if (0 <= index && index < itemCount) {
- ((NSTableView)view).scrollRowToVisible(index);
- }
-}
-
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void showSelection () {
- checkWidget();
- int index = getSelectionIndex ();
- if (index >= 0) showIndex (index);
-}
-
-void tableViewSelectionDidChange (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
- if (ignoreSelect) return;
- postEvent (SWT.Selection);
-}
-
-boolean tableView_shouldEditTableColumn_row(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ aTableColumn, int /*long*/ rowIndex) {
- return false;
-}
-
-int /*long*/ tableView_objectValueForTableColumn_row(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ aTableColumn, int /*long*/ rowIndex) {
- NSAttributedString attribStr = createString(items[(int)/*64*/rowIndex], null, foreground, 0, true, false);
- attribStr.autorelease();
- return attribStr.id;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Menu.java
deleted file mode 100755
index 62934535e4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Menu.java
+++ /dev/null
@@ -1,926 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.cocoa.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are user interface objects that contain
- * menu items.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BAR, DROP_DOWN, POP_UP, NO_RADIO_GROUP</dd>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Help, Hide, Show </dd>
- * </dl>
- * <p>
- * Note: Only one of BAR, DROP_DOWN and POP_UP may be specified.
- * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#menu">Menu snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Menu extends Widget {
- /**
- * the handle to the OS resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- NSMenu nsMenu;
- int x, y, itemCount;
- boolean hasLocation, visible;
- MenuItem [] items;
- MenuItem cascade, defaultItem;
- Decorations parent;
-
-/**
- * Constructs a new instance of this class given its parent,
- * and sets the style for the instance so that the instance
- * will be a popup menu on the given parent's shell.
- * <p>
- * After constructing a menu, it can be set into its parent
- * using <code>parent.setMenu(menu)</code>. In this case, the parent may
- * be any control in the same widget tree as the parent.
- * </p>
- *
- * @param parent a control which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#POP_UP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Control parent) {
- this (checkNull (parent).menuShell (), SWT.POP_UP);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Decorations</code>) and a style value
- * describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * After constructing a menu or menuBar, it can be set into its parent
- * using <code>parent.setMenu(menu)</code> or <code>parent.setMenuBar(menuBar)</code>.
- * </p>
- *
- * @param parent a decorations control which will be the parent of the new instance (cannot be null)
- * @param style the style of menu to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BAR
- * @see SWT#DROP_DOWN
- * @see SWT#POP_UP
- * @see SWT#NO_RADIO_GROUP
- * @see SWT#LEFT_TO_RIGHT
- * @see SWT#RIGHT_TO_LEFT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Decorations parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget ();
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>) and sets the style
- * for the instance so that the instance will be a drop-down
- * menu on the given parent's parent.
- * <p>
- * After constructing a drop-down menu, it can be set into its parentMenu
- * using <code>parentMenu.setMenu(menu)</code>.
- * </p>
- *
- * @param parentMenu a menu which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Menu parentMenu) {
- this (checkNull (parentMenu).parent, SWT.DROP_DOWN);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>MenuItem</code>) and sets the style
- * for the instance so that the instance will be a drop-down
- * menu on the given parent's parent menu.
- * <p>
- * After constructing a drop-down menu, it can be set into its parentItem
- * using <code>parentItem.setMenu(menu)</code>.
- * </p>
- *
- * @param parentItem a menu item which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (MenuItem parentItem) {
- this (checkNull (parentItem).parent);
-}
-
-static Control checkNull (Control control) {
- if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return control;
-}
-
-static Menu checkNull (Menu menu) {
- if (menu == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return menu;
-}
-
-static MenuItem checkNull (MenuItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0);
-}
-
-void _setVisible (boolean visible) {
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- TrayItem trayItem = display.currentTrayItem;
- if (trayItem != null && visible) {
- trayItem.showMenu (this);
- return;
- }
- if (visible) {
- Shell shell = getShell ();
- NSWindow window = shell.window;
- NSPoint location = null;
- if (hasLocation) {
- NSView topView = window.contentView();
- Point shellCoord = display.map(null, shell, new Point(x,y));
- location = new NSPoint ();
- location.x = shellCoord.x;
- location.y = topView.frame().height - shellCoord.y;
- } else {
- location = window.mouseLocationOutsideOfEventStream();
- }
-
- // Hold on to window in case it is disposed while the popup is open.
- window.retain();
- NSEvent nsEvent = NSEvent.otherEventWithType(OS.NSApplicationDefined, location, 0, 0.0, window.windowNumber(), window.graphicsContext(), (short)0, 0, 0);
- NSMenu.popUpContextMenu(nsMenu, nsEvent, shell.view);
- window.release();
- } else {
- nsMenu.cancelTracking ();
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when help events are generated for the control,
- * by sending it one of the messages defined in the
- * <code>HelpListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when menus are hidden or shown, by sending it
- * one of the messages defined in the <code>MenuListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuListener
- * @see #removeMenuListener
- */
-public void addMenuListener (MenuListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Hide,typedListener);
- addListener (SWT.Show,typedListener);
-}
-
-void createHandle () {
- display.addMenu (this);
- NSMenu widget = (NSMenu)new SWTMenu().alloc();
- widget = widget.initWithTitle(NSString.stringWith(""));
- widget.setAutoenablesItems(false);
- widget.setDelegate(widget);
- nsMenu = widget;
-}
-
-void createItem (MenuItem item, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- NSMenuItem nsItem = null;
- if ((item.style & SWT.SEPARATOR) != 0) {
- nsItem = NSMenuItem.separatorItem();
- nsItem.retain();
- } else {
- nsItem = (NSMenuItem)new SWTMenuItem().alloc();
- nsItem.initWithTitle(NSString.stringWith(""), 0, NSString.stringWith(""));
- nsItem.setTarget(nsItem);
- nsItem.setAction(OS.sel_sendSelection);
- }
- item.nsItem = nsItem;
- item.createJNIRef();
- item.register();
- nsMenu.insertItem(nsItem, index);
- if (itemCount == items.length) {
- MenuItem [] newItems = new MenuItem [items.length + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- System.arraycopy (items, index, items, index + 1, itemCount++ - index);
- items [index] = item;
- NSMenu emptyMenu = item.createEmptyMenu ();
- if (emptyMenu != null) {
- nsItem.setSubmenu (emptyMenu);
- emptyMenu.release();
- }
- if (display.menuBar == this) {
- NSApplication application = display.application;
- NSMenu menubar = application.mainMenu();
- if (menubar != null) {
- nsItem.setMenu(null);
- menubar.insertItem(nsItem, index + 1);
- }
- }
- //TODO - find a way to disable the menu instead of each item
- if (!getEnabled ()) nsItem.setEnabled (false);
-}
-
-void createWidget () {
- checkOrientation (parent);
- super.createWidget ();
- items = new MenuItem [4];
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (nsMenu);
-}
-
-void destroyItem (MenuItem item) {
- int index = 0;
- while (index < itemCount) {
- if (items [index] == item) break;
- index++;
- }
- if (index == itemCount) return;
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- if (itemCount == 0) items = new MenuItem [4];
- nsMenu.removeItem (item.nsItem);
- if (display.menuBar == this) {
- NSApplication application = display.application;
- NSMenu menubar = application.mainMenu();
- if (menubar != null) {
- NSMenuItem nsItem = item.nsItem;
- menubar.removeItem(nsItem);
- }
- }
-}
-
-void fixMenus (Decorations newParent) {
- this.parent = newParent;
-}
-
-/**
- * Returns the default menu item or null if none has
- * been previously set.
- *
- * @return the default menu item.
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getDefaultItem () {
- checkWidget();
- return defaultItem;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled menu is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- return (state & DISABLED) == 0;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getItem (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return itemCount;
-}
-
-/**
- * Returns a (possibly empty) array of <code>MenuItem</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem [] getItems () {
- checkWidget ();
- MenuItem [] result = new MenuItem [itemCount];
- int index = 0;
- if (items != null) {
- for (int i = 0; i < itemCount; i++) {
- MenuItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- result [index++] = item;
- }
- }
- }
- if (index != result.length) {
- MenuItem [] newItems = new MenuItem[index];
- System.arraycopy(result, 0, newItems, 0, index);
- result = newItems;
- }
- return result;
-}
-
-String getNameText () {
- String result = "";
- MenuItem [] items = getItems ();
- int length = items.length;
- if (length > 0) {
- for (int i=0; i<length-1; i++) {
- result = result + items [i].getNameText() + ", ";
- }
- result = result + items [length-1].getNameText ();
- }
- return result;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Decorations</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Decorations getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>MenuItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getParentItem () {
- checkWidget ();
- return cascade;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>Menu</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getParentMenu () {
- checkWidget ();
- if (cascade != null) return cascade.parent;
- return null;
-}
-
-/**
- * Returns the receiver's shell. For all controls other than
- * shells, this simply returns the control's nearest ancestor
- * shell. Shells return themselves, even if they are children
- * of other shells.
- *
- * @return the receiver's shell
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getParent
- */
-public Shell getShell () {
- checkWidget ();
- return parent.getShell ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- if ((style & SWT.BAR) != 0) {
- return this == parent.menuShell ().menuBar;
- }
- if ((style & SWT.POP_UP) != 0) {
- Menu [] popups = display.popups;
- if (popups == null) return false;
- for (int i=0; i<popups.length; i++) {
- if (popups [i] == this) return true;
- }
- }
- return visible;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (MenuItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<itemCount; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled menu is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget ();
- Menu parentMenu = getParentMenu ();
- if (parentMenu == null) {
- return getEnabled () && parent.isEnabled ();
- }
- return getEnabled () && parentMenu.isEnabled ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget ();
- return getVisible ();
-}
-
-void menu_willHighlightItem(int /*long*/ id, int /*long*/ sel, int /*long*/ menu, int /*long*/ itemID) {
- Widget widget = display.getWidget(itemID);
- if (widget instanceof MenuItem) {
- MenuItem item = (MenuItem)widget;
- item.sendEvent (SWT.Arm);
- }
-}
-
-void menuNeedsUpdate(int /*long*/ id, int /*long*/ sel, int /*long*/ menu) {
- //This code is intentionally commented
- //sendEvent (SWT.Show);
-}
-
-void menuWillOpen(int /*long*/ id, int /*long*/ sel, int /*long*/ menu) {
- visible = true;
- sendEvent (SWT.Show);
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (item != null) item.updateAccelerator (true);
- }
-}
-
-void menuDidClose(int /*long*/ id, int /*long*/ sel, int /*long*/ menu) {
- sendEvent (SWT.Hide);
- visible = false;
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (item != null) item.updateAccelerator (false);
- }
-}
-
-void register () {
- super.register ();
- display.addWidget (nsMenu, this);
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (nsMenu != null) nsMenu.release();
- nsMenu = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (cascade != null) cascade.setMenu (null);
- if ((style & SWT.BAR) != 0 && this == parent.menuBar) {
- parent.setMenuBar (null);
- }
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- display.removeMenu (this);
- parent = null;
- cascade = defaultItem = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the menu events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuListener
- * @see #addMenuListener
- */
-public void removeMenuListener (MenuListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Hide, listener);
- eventTable.unhook (SWT.Show, listener);
-}
-
-/**
- * Sets the default menu item to the argument or removes
- * the default emphasis when the argument is <code>null</code>.
- *
- * @param item the default menu item or null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the menu item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDefaultItem (MenuItem item) {
- checkWidget();
- if (item != null && item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- defaultItem = item;
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled menu is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- if (enabled) {
- state &= ~DISABLED;
- } else {
- state |= DISABLED;
- }
- //TODO - find a way to disable the menu instead of each item
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (item != null) {
- /*
- * Feature in the Macintosh. When a cascade menu
- * item is disabled, rather than disabling the item,
- * the submenu is disabled.
- *
- * There is no fix for this at this time.
- */
- item.nsItem.setEnabled (enabled && item.getEnabled ());
- }
- }
-}
-
-/**
- * Sets the location of the receiver, which must be a popup,
- * to the point specified by the arguments which are relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p><p>
- * Note that the platform window manager ultimately has control
- * over the location of popup menus.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget ();
- this.x = x;
- this.y = y;
- hasLocation = true;
-}
-
-/**
- * Sets the location of the receiver, which must be a popup,
- * to the point specified by the argument which is relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p><p>
- * Note that the platform window manager ultimately has control
- * over the location of popup menus.
- * </p>
- *
- * @param location the new location for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void setLocation (Point location) {
- checkWidget ();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- if (visible) {
- display.addPopup (this);
- } else {
- display.removePopup (this);
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MenuItem.java
deleted file mode 100755
index d27761b4f8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MenuItem.java
+++ /dev/null
@@ -1,850 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.cocoa.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that issues notification when pressed and released.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>CHECK, CASCADE, PUSH, RADIO, SEPARATOR</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Arm, Help, Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR
- * may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class MenuItem extends Item {
- NSMenuItem nsItem;
- Menu parent, menu;
- int accelerator;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a menu control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#CHECK
- * @see SWT#CASCADE
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public MenuItem (Menu parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a menu control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#CHECK
- * @see SWT#CASCADE
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public MenuItem (Menu parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the arm events are generated for the control, by sending
- * it one of the messages defined in the <code>ArmListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ArmListener
- * @see #removeArmListener
- */
-public void addArmListener (ArmListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Arm, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the help events are generated for the control, by sending
- * it one of the messages defined in the <code>HelpListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the menu item is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the stateMask field of the event object is valid.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the menu item is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.CASCADE, 0);
-}
-
-NSMenu createEmptyMenu () {
- if ((parent.style & SWT.BAR) != 0) {
- return (NSMenu) new SWTMenu ().alloc ().init ();
- }
- return null;
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (nsItem);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns the widget accelerator. An accelerator is the bit-wise
- * OR of zero or more modifier masks and a key. Examples:
- * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
- * The default value is zero, indicating that the menu item does
- * not have an accelerator.
- *
- * @return the accelerator or 0
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAccelerator () {
- checkWidget ();
- return accelerator;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled menu item is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- return (state & DISABLED) == 0;
-}
-
-/**
- * Returns the receiver's cascade menu if it has one or null
- * if it does not. Only <code>CASCADE</code> menu items can have
- * a pull down menu. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pull down
- * menu is platform specific.
- *
- * @return the receiver's menu
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenu () {
- checkWidget ();
- return menu;
-}
-
-String getNameText () {
- if ((style & SWT.SEPARATOR) != 0) return "|";
- return super.getNameText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Menu</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked.
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget ();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
- return nsItem.state() == OS.NSOnState;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled menu item is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- return getEnabled () && parent.isEnabled ();
-}
-
-int keyChar (int key) {
- //TODO - use the NS key constants
- switch (key) {
- case SWT.BS: return OS.NSBackspaceCharacter;
- case SWT.CR: return OS.NSCarriageReturnCharacter;
- case SWT.DEL: return OS.NSDeleteCharacter;
- case SWT.ESC: return SWT.ESC;
- case SWT.LF: return OS.NSNewlineCharacter;
- case SWT.TAB: return OS.NSTabCharacter;
-// case ' ': return OS.kMenuBlankGlyph;
-// case ' ': return OS.kMenuSpaceGlyph;
- case SWT.ALT: return 0x2325;
- case SWT.SHIFT: return 0x21E7;
- case SWT.CONTROL: return 0xF2303;
- case SWT.COMMAND: return 0x2318;
- case SWT.ARROW_UP: return 0x2191;
- case SWT.ARROW_DOWN: return 0x2193;
- case SWT.ARROW_LEFT: return 0x2190;
- case SWT.ARROW_RIGHT: return 0x2192;
- case SWT.PAGE_UP: return 0x21DE;
- case SWT.PAGE_DOWN: return 0x21DF;
- case SWT.KEYPAD_CR: return OS.NSEnterCharacter;
- case SWT.HELP: return OS.NSHelpFunctionKey;
- case SWT.HOME: return 0xF729;
- case SWT.END: return 0xF72B;
-// case SWT.CAPS_LOCK: return ??;
- case SWT.F1: return 0xF704;
- case SWT.F2: return 0xF705;
- case SWT.F3: return 0xF706;
- case SWT.F4: return 0xF707;
- case SWT.F5: return 0xF708;
- case SWT.F6: return 0xF709;
- case SWT.F7: return 0xF70A;
- case SWT.F8: return 0xF70B;
- case SWT.F9: return 0xF70C;
- case SWT.F10: return 0xF70D;
- case SWT.F11: return 0xF70E;
- case SWT.F12: return 0xF70F;
- case SWT.F13: return 0xF710;
- case SWT.F14: return 0xF711;
- case SWT.F15: return 0xF712;
- /*
- * The following lines are intentionally commented.
- */
-// case SWT.INSERT: return ??;
- }
- return 0;
-}
-
-
-void register () {
- super.register ();
- display.addWidget (nsItem, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (nsItem != null) nsItem.release();
- nsItem = null;
- parent = null;
-}
-
-void releaseChildren (boolean destroy) {
- if (menu != null) {
- menu.release (false);
- menu = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- accelerator = 0;
- if (this == parent.defaultItem) parent.defaultItem = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the arm events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ArmListener
- * @see #addArmListener
- */
-public void removeArmListener (ArmListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Arm, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-void selectRadio () {
- int index = 0;
- MenuItem [] items = parent.getItems ();
- while (index < items.length && items [index] != this) index++;
- int i = index - 1;
- while (i >= 0 && items [i].setRadioSelection (false)) --i;
- int j = index + 1;
- while (j < items.length && items [j].setRadioSelection (false)) j++;
- setSelection (true);
-}
-
-void sendSelection () {
- if ((style & SWT.CHECK) != 0) {
- setSelection (!getSelection ());
- } else {
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) != 0) {
- setSelection (!getSelection ());
- } else {
- selectRadio ();
- }
- }
- }
- Event event = new Event ();
- NSEvent nsEvent = NSApplication.sharedApplication ().currentEvent ();
- if (nsEvent != null) setInputState (event, nsEvent, 0);
- postEvent (SWT.Selection, event);
-}
-
-/**
- * Sets the widget accelerator. An accelerator is the bit-wise
- * OR of zero or more modifier masks and a key. Examples:
- * <code>SWT.MOD1 | SWT.MOD2 | 'T', SWT.MOD3 | SWT.F2</code>.
- * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
- * The default value is zero, indicating that the menu item does
- * not have an accelerator.
- *
- * @param accelerator an integer that is the bit-wise OR of masks and a key
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAccelerator (int accelerator) {
- checkWidget ();
- if (this.accelerator == accelerator) return;
- this.accelerator = accelerator;
- int key = accelerator & SWT.KEY_MASK;
- int virtualKey = keyChar (key);
- NSString string = null;
- if (virtualKey != 0) {
- string = NSString.stringWith ((char)virtualKey + "");
- } else {
- string = NSString.stringWith ((char)key + "");
- }
- nsItem.setKeyEquivalent (string.lowercaseString());
- int mask = 0;
- if ((accelerator & SWT.SHIFT) != 0) mask |= OS.NSShiftKeyMask;
- if ((accelerator & SWT.CONTROL) != 0) mask |= OS.NSControlKeyMask;
- if ((accelerator & SWT.COMMAND) != 0) mask |= OS.NSCommandKeyMask;
- if ((accelerator & SWT.ALT) != 0) mask |= OS.NSAlternateKeyMask;
- nsItem.setKeyEquivalentModifierMask (mask);
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled menu item is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget ();
- if (enabled) {
- state &= ~DISABLED;
- } else {
- state |= DISABLED;
- }
- nsItem.setEnabled(enabled);
-}
-
-/**
- * Sets the image the receiver will display to the argument.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept (for example, Windows NT).
- * Furthermore, some platforms (such as GTK), cannot display both
- * a check box and an image at the same time. Instead, they hide
- * the image and display the check box.
- * </p>
- *
- * @param image the image to display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return;
- super.setImage (image);
- nsItem.setImage(image != null? image.handle : null);
-}
-
-/**
- * Sets the receiver's pull down menu to the argument.
- * Only <code>CASCADE</code> menu items can have a
- * pull down menu. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pull down
- * menu is platform specific.
- * <p>
- * Note: Disposing of a menu item that has a pull down menu
- * will dispose of the menu. To avoid this behavior, set the
- * menu to null before the menu item is disposed.
- * </p>
- *
- * @param menu the new pull down menu
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_MENU_NOT_DROP_DOWN - if the menu is not a drop down menu</li>
- * <li>ERROR_MENUITEM_NOT_CASCADE - if the menu item is not a <code>CASCADE</code></li>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenu (Menu menu) {
- checkWidget ();
-
- /* Check to make sure the new menu is valid */
- if ((style & SWT.CASCADE) == 0) {
- error (SWT.ERROR_MENUITEM_NOT_CASCADE);
- }
- if (menu != null) {
- if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.DROP_DOWN) == 0) {
- error (SWT.ERROR_MENU_NOT_DROP_DOWN);
- }
- if (menu.parent != parent.parent) {
- error (SWT.ERROR_INVALID_PARENT);
- }
- }
- /* Assign the new menu */
- Menu oldMenu = this.menu;
- if (oldMenu == menu) return;
- if (oldMenu != null) oldMenu.cascade = null;
- this.menu = menu;
-
- /* Update the menu in the OS */
- if (menu == null) {
- NSMenu emptyMenu = createEmptyMenu ();
- if (emptyMenu != null) {
- nsItem.setSubmenu (emptyMenu);
- emptyMenu.release();
- }
- } else {
- menu.cascade = this;
- nsItem.setSubmenu (menu.nsMenu);
- }
-
- if (menu != null) {
- nsItem.setTarget(null);
- nsItem.setAction(0);
- } else {
- nsItem.setTarget(nsItem);
- nsItem.setAction(OS.sel_sendSelection);
- }
-
- /* Update menu title with parent item title */
- updateText ();
-}
-
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-
-/**
- * Sets the selection state of the receiver.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked.
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget ();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
- nsItem.setState(selected ? OS.NSOnState : OS.NSOffState);
-}
-
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character and accelerator text.
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- * <p>
- * Accelerator text is indicated by the '\t' character.
- * On platforms that support accelerator text, the text
- * that follows the '\t' character is displayed to the user,
- * typically indicating the key stroke that will cause
- * the item to become selected. On most platforms, the
- * accelerator text appears right aligned in the menu.
- * Setting the accelerator text does not install the
- * accelerator key sequence. The accelerator key sequence
- * is installed using #setAccelerator.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setAccelerator
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- if (text.equals (string)) return;
- super.setText (string);
- updateText ();
-}
-
-void updateText () {
- char [] buffer = new char [text.length ()];
- text.getChars (0, buffer.length, buffer, 0);
- int i=0, j=0;
- while (i < buffer.length) {
- if (buffer [i] == '\t') break;
- if ((buffer [j++] = buffer [i++]) == '&') {
- if (i == buffer.length) {continue;}
- if (buffer [i] == '&') {i++; continue;}
- j--;
- }
- }
- String text = new String (buffer, 0, j);
- NSMenu submenu = nsItem.submenu ();
- NSString label = NSString.stringWith (text);
- if(submenu != null && (parent.getStyle () & SWT.BAR) != 0) {
- submenu.setTitle (label);
- } else {
- nsItem.setTitle (label);
- }
-}
-
-void updateAccelerator (boolean show) {
- if (accelerator != 0) return;
- int mask = 0, key = 0;
- if (show) {
- char [] buffer = new char [text.length ()];
- text.getChars (0, buffer.length, buffer, 0);
- int i=0, j=0;
- while (i < buffer.length) {
- if (buffer [i] == '\t') break;
- if ((buffer [j++] = buffer [i++]) == '&') {
- if (i == buffer.length) {continue;}
- if (buffer [i] == '&') {i++; continue;}
- j--;
- }
- }
- if (i < buffer.length && buffer [i] == '\t') {
- for (j = i + 1; j < buffer.length; j++) {
- switch (buffer [j]) {
- case '\u2303': mask |= OS.NSControlKeyMask; i++; break;
- case '\u2325': mask |= OS.NSAlternateKeyMask; i++; break;
- case '\u21E7': mask |= OS.NSShiftKeyMask; i++; break;
- case '\u2318': mask |= OS.NSCommandKeyMask; i++; break;
- default:
- j = buffer.length;
- break;
- }
- }
- switch (buffer.length - i - 1) {
- case 1:
- key = buffer [i + 1];
- if (key == 0x2423) key = ' ';
- break;
- case 2:
- if (buffer [i + 1] == 'F') {
- switch (buffer [i + 2]) {
- case '1': key = 0xF704; break;
- case '2': key = 0xF705; break;
- case '3': key = 0xF706; break;
- case '4': key = 0xF707; break;
- case '5': key = 0xF708; break;
- case '6': key = 0xF709; break;
- case '7': key = 0xF70A; break;
- case '8': key = 0xF70B; break;
- case '9': key = 0xF70C; break;
- }
- }
- break;
- case 3:
- if (buffer [i + 1] == 'F' && buffer [i + 2] == '1') {
- switch (buffer [i + 3]) {
- case '0': key = 0xF70D; break;
- case '1': key = 0xF70E; break;
- case '2': key = 0xF70F; break;
- case '3': key = 0xF710; break;
- case '4': key = 0xF711; break;
- case '5': key = 0xF712; break;
- }
- }
- break;
- }
- }
- }
- NSString string = NSString.stringWith (key == 0 ? "" : String.valueOf ((char)key));
- nsItem.setKeyEquivalentModifierMask (mask);
- nsItem.setKeyEquivalent (string.lowercaseString ());
-}
-
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MessageBox.java
deleted file mode 100755
index 9d0ff92045..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MessageBox.java
+++ /dev/null
@@ -1,331 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class are used to inform or warn the user.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, ICON_WARNING, ICON_WORKING</dd>
- * <dd>OK, OK | CANCEL</dd>
- * <dd>YES | NO, YES | NO | CANCEL</dd>
- * <dd>RETRY | CANCEL</dd>
- * <dd>ABORT | RETRY | IGNORE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION, ICON_QUESTION,
- * ICON_WARNING and ICON_WORKING may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class MessageBox extends Dialog {
- String message = "";
- int returnCode;
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public MessageBox (Shell parent) {
- this (parent, SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_QUESTION
- * @see SWT#ICON_WARNING
- * @see SWT#ICON_WORKING
- * @see SWT#OK
- * @see SWT#CANCEL
- * @see SWT#YES
- * @see SWT#NO
- * @see SWT#ABORT
- * @see SWT#RETRY
- * @see SWT#IGNORE
- */
-public MessageBox (Shell parent, int style) {
- super (parent, checkStyle (parent, checkStyle (style)));
- if (Display.getSheetEnabled ()) {
- if (parent != null && (style & SWT.SHEET) != 0) this.style |= SWT.SHEET;
- }
- checkSubclass ();
-}
-
-static int checkStyle (int style) {
- int mask = (SWT.YES | SWT.NO | SWT.OK | SWT.CANCEL | SWT.ABORT | SWT.RETRY | SWT.IGNORE);
- int bits = style & mask;
- if (bits == SWT.OK || bits == SWT.CANCEL || bits == (SWT.OK | SWT.CANCEL)) return style;
- if (bits == SWT.YES || bits == SWT.NO || bits == (SWT.YES | SWT.NO) || bits == (SWT.YES | SWT.NO | SWT.CANCEL)) return style;
- if (bits == (SWT.RETRY | SWT.CANCEL) || bits == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) return style;
- style = (style & ~mask) | SWT.OK;
- return style;
-}
-
-/**
- * Returns the dialog's message, or an empty string if it does not have one.
- * The message is a description of the purpose for which the dialog was opened.
- * This message will be visible in the dialog while it is open.
- *
- * @return the message
- */
-public String getMessage () {
- return message;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return the ID of the button that was selected to dismiss the
- * message box (e.g. SWT.OK, SWT.CANCEL, etc.)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public int open () {
- NSAlert alert = (NSAlert) new NSAlert().alloc().init();
- int alertType = OS.NSInformationalAlertStyle;
- if ((style & SWT.ICON_ERROR) != 0) alertType = OS.NSCriticalAlertStyle;
- if ((style & SWT.ICON_INFORMATION) != 0) alertType = OS.NSInformationalAlertStyle;
- if ((style & SWT.ICON_QUESTION) != 0) alertType = OS.NSInformationalAlertStyle;
- if ((style & SWT.ICON_WARNING) != 0) alertType = OS.NSWarningAlertStyle;
- if ((style & SWT.ICON_WORKING) != 0) alertType = OS.NSInformationalAlertStyle;
- alert.setAlertStyle(alertType);
-
- int mask = (SWT.YES | SWT.NO | SWT.OK | SWT.CANCEL | SWT.ABORT | SWT.RETRY | SWT.IGNORE);
- int bits = style & mask;
- NSString title;
- switch (bits) {
- case SWT.OK:
- title = NSString.stringWith(SWT.getMessage("SWT_OK"));
- alert.addButtonWithTitle(title);
- break;
- case SWT.CANCEL:
- title = NSString.stringWith(SWT.getMessage("SWT_Cancel"));
- alert.addButtonWithTitle(title);
- break;
- case SWT.OK | SWT.CANCEL:
- title = NSString.stringWith(SWT.getMessage("SWT_OK"));
- alert.addButtonWithTitle(title);
- title = NSString.stringWith(SWT.getMessage("SWT_Cancel"));
- alert.addButtonWithTitle(title);
- break;
- case SWT.YES:
- title = NSString.stringWith(SWT.getMessage("SWT_Yes"));
- alert.addButtonWithTitle(title);
- break;
- case SWT.NO:
- title = NSString.stringWith(SWT.getMessage("SWT_No"));
- alert.addButtonWithTitle(title);
- break;
- case SWT.YES | SWT.NO:
- title = NSString.stringWith(SWT.getMessage("SWT_Yes"));
- alert.addButtonWithTitle(title);
- title = NSString.stringWith(SWT.getMessage("SWT_No"));
- alert.addButtonWithTitle(title);
-// no.setKeyEquivalent(NSString.stringWith("\033"));
- break;
- case SWT.YES | SWT.NO | SWT.CANCEL:
- title = NSString.stringWith(SWT.getMessage("SWT_Yes"));
- alert.addButtonWithTitle(title);
- title = NSString.stringWith(SWT.getMessage("SWT_Cancel"));
- alert.addButtonWithTitle(title);
- title = NSString.stringWith(SWT.getMessage("SWT_No"));
- alert.addButtonWithTitle(title);
- break;
- case SWT.RETRY | SWT.CANCEL:
- title = NSString.stringWith(SWT.getMessage("SWT_Retry"));
- alert.addButtonWithTitle(title);
- title = NSString.stringWith(SWT.getMessage("SWT_Cancel"));
- alert.addButtonWithTitle(title);
- break;
- case SWT.ABORT | SWT.RETRY | SWT.IGNORE:
- title = NSString.stringWith(SWT.getMessage("SWT_Abort"));
- alert.addButtonWithTitle(title);
- title = NSString.stringWith(SWT.getMessage("SWT_Ignore"));
- alert.addButtonWithTitle(title);
- title = NSString.stringWith(SWT.getMessage("SWT_Retry"));
- alert.addButtonWithTitle(title);
- break;
- }
- title = NSString.stringWith(this.title != null ? this.title : "");
- alert.window().setTitle(title);
- NSString message = NSString.stringWith(this.message != null ? this.message : "");
- alert.setMessageText(message);
- int response = 0;
- int /*long*/ jniRef = 0;
- SWTPanelDelegate delegate = null;
- if ((style & SWT.SHEET) != 0) {
- delegate = (SWTPanelDelegate)new SWTPanelDelegate().alloc().init();
- jniRef = OS.NewGlobalRef(this);
- if (jniRef == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.object_setInstanceVariable(delegate.id, Display.SWT_OBJECT, jniRef);
- alert.beginSheetModalForWindow(parent.window, delegate, OS.sel_panelDidEnd_returnCode_contextInfo_, 0);
- if ((style & SWT.APPLICATION_MODAL) != 0) {
- response = (int)/*64*/alert.runModal();
- } else {
- this.returnCode = 0;
- NSWindow window = alert.window();
- NSApplication application = NSApplication.sharedApplication();
- while (window.isVisible()) application.run();
- response = this.returnCode;
- }
- } else {
- response = (int)/*64*/alert.runModal();
- }
- if (delegate != null) delegate.release();
- if (jniRef != 0) OS.DeleteGlobalRef(jniRef);
- alert.release();
- switch (bits) {
- case SWT.OK:
- switch (response) {
- case OS.NSAlertFirstButtonReturn:
- return SWT.OK;
- }
- break;
- case SWT.CANCEL:
- switch (response) {
- case OS.NSAlertFirstButtonReturn:
- return SWT.CANCEL;
- }
- break;
- case SWT.OK | SWT.CANCEL:
- switch (response) {
- case OS.NSAlertFirstButtonReturn:
- return SWT.OK;
- case OS.NSAlertSecondButtonReturn:
- return SWT.CANCEL;
- }
- break;
- case SWT.YES:
- switch (response) {
- case OS.NSAlertFirstButtonReturn:
- return SWT.YES;
- }
- break;
- case SWT.NO:
- switch (response) {
- case OS.NSAlertFirstButtonReturn:
- return SWT.NO;
- }
- break;
- case SWT.YES | SWT.NO:
- switch (response) {
- case OS.NSAlertFirstButtonReturn:
- return SWT.YES;
- case OS.NSAlertSecondButtonReturn:
- return SWT.NO;
- }
- break;
- case SWT.YES | SWT.NO | SWT.CANCEL:
- switch (response) {
- case OS.NSAlertFirstButtonReturn:
- return SWT.YES;
- case OS.NSAlertSecondButtonReturn:
- return SWT.CANCEL;
- case OS.NSAlertThirdButtonReturn:
- return SWT.NO;
- }
- break;
- case SWT.RETRY | SWT.CANCEL:
- switch (response) {
- case OS.NSAlertFirstButtonReturn:
- return SWT.RETRY;
- case OS.NSAlertSecondButtonReturn:
- return SWT.CANCEL;
- }
- break;
- case SWT.ABORT | SWT.RETRY | SWT.IGNORE:
- switch (response) {
- case OS.NSAlertFirstButtonReturn:
- return SWT.ABORT;
- case OS.NSAlertSecondButtonReturn:
- return SWT.IGNORE;
- case OS.NSAlertThirdButtonReturn:
- return SWT.RETRY;
- }
- break;
- }
- return SWT.CANCEL;
-}
-
-void panelDidEnd_returnCode_contextInfo(int /*long*/ id, int /*long*/ sel, int /*long*/ alert, int /*long*/ returnCode, int /*long*/ contextInfo) {
- this.returnCode = (int)/*64*/returnCode;
- NSApplication application = NSApplication.sharedApplication();
- application.endSheet(new NSAlert(alert).window(), returnCode);
- if ((style & SWT.PRIMARY_MODAL) != 0) {
- application.stop(null);
- }
-}
-
-/**
- * Sets the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @param string the message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- */
-public void setMessage (String string) {
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- message = string;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ProgressBar.java
deleted file mode 100755
index 55cd72486f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ProgressBar.java
+++ /dev/null
@@ -1,330 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of the receiver represent an unselectable
- * user interface object that is used to display progress,
- * typically in the form of a bar.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SMOOTH, HORIZONTAL, VERTICAL, INDETERMINATE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#progressbar">ProgressBar snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ProgressBar extends Control {
-
- NSBezierPath visiblePath;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SMOOTH
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#INDETERMINATE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ProgressBar (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int size = OS.NSProgressIndicatorPreferredThickness;
- int width = 0, height = 0;
- if ((style & SWT.HORIZONTAL) != 0) {
- height = size;
- width = height * 10;
- } else {
- width = size;
- height = width * 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- return new Point (width, height);
-}
-
-void createHandle () {
- NSProgressIndicator widget = (NSProgressIndicator)new SWTProgressIndicator().alloc();
- widget.init();
- widget.setUsesThreadedAnimation(false);
- widget.setIndeterminate((style & SWT.INDETERMINATE) != 0);
- view = widget;
-}
-
-NSFont defaultNSFont () {
- return display.progressIndicatorFont;
-}
-
-void _drawThemeProgressArea (int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- /*
- * Bug in Cocoa. When the threaded animation is turned off by calling
- * setUsesThreadedAnimation(), _drawThemeProgressArea() attempts to
- * access a deallocated NSBitmapGraphicsContext when drawing a zero sized
- * progress bar. The fix is to avoid calling super when the progress bar
- * is zero sized.
- */
- NSRect frame = view.frame();
- if (frame.width == 0 || frame.height == 0) return;
-
- /*
- * Bug in Cocoa. When the progress bar is animating it calls
- * _drawThemeProgressArea() directly without taking into account
- * obscured areas. The fix is to clip the drawing to the visible
- * region of the progress bar before calling super.
- */
- if (visiblePath == null) {
- int /*long*/ visibleRegion = getVisibleRegion();
- visiblePath = getPath(visibleRegion);
- OS.DisposeRgn(visibleRegion);
- }
- NSGraphicsContext context = NSGraphicsContext.currentContext();
- context.saveGraphicsState();
- visiblePath.setClip();
- super._drawThemeProgressArea (id, sel, arg0);
- context.restoreGraphicsState();
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget();
- return (int)((NSProgressIndicator)view).maxValue();
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget();
- return (int)((NSProgressIndicator)view).minValue();
-}
-
-/**
- * Returns the single 'selection' that is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget();
- return (int)((NSProgressIndicator)view).doubleValue();
-}
-
-/**
- * Returns the state of the receiver. The value will be one of:
- * <ul>
- * <li>{@link SWT#NORMAL}</li>
- * <li>{@link SWT#ERROR}</li>
- * <li>{@link SWT#PAUSED}</li>
- * </ul>
- *
- * @return the state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public int getState () {
- checkWidget ();
- return SWT.NORMAL;
-}
-
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget();
- int minimum = (int)((NSProgressIndicator)view).minValue();
- if (value <= minimum) return;
- ((NSProgressIndicator)view).setMaxValue(value);
- int selection = (int)((NSProgressIndicator)view).doubleValue();
- int newSelection = Math.min (selection, value);
- if (selection != newSelection) {
- ((NSProgressIndicator)view).setDoubleValue(newSelection);
- }
-}
-
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is negative or is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be nonnegative and less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget();
- int maximum = (int)((NSProgressIndicator)view).maxValue();
- if (!(0 <= value && value < maximum)) return;
- ((NSProgressIndicator)view).setMinValue(value);
- int selection = (int)((NSProgressIndicator)view).doubleValue();
- int newSelection = Math.max (selection, value);
- if (selection != newSelection) {
- ((NSProgressIndicator)view).setDoubleValue(newSelection);
- }
-}
-
-/**
- * Sets the single 'selection' that is the receiver's
- * position to the argument which must be greater than or equal
- * to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget();
- ((NSProgressIndicator)view).setDoubleValue(value);
- /*
- * Feature in Cocoa. The progress bar does
- * not redraw right away when a value is
- * changed. This is not strictly incorrect
- * but unexpected. The fix is to force all
- * outstanding redraws to be delivered.
- */
- update(false);
-}
-
-/**
- * Sets the state of the receiver. The state must be one of these values:
- * <ul>
- * <li>{@link SWT#NORMAL}</li>
- * <li>{@link SWT#ERROR}</li>
- * <li>{@link SWT#PAUSED}</li>
- * </ul>
- *
- * @param state the new state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setState (int state) {
- checkWidget ();
- //NOT IMPLEMENTED
-}
-
-void releaseWidget () {
- super.releaseWidget();
- if (visiblePath != null) visiblePath.release();
- visiblePath = null;
-}
-
-void resetVisibleRegion () {
- super.resetVisibleRegion ();
- if (visiblePath != null) visiblePath.release();
- visiblePath = null;
-}
-
-void viewDidMoveToWindow(int /*long*/ id, int /*long*/ sel) {
- /*
- * Bug in Cocoa. An indeterminate progress indicator doesn't start animating until it is in
- * a visible window. Workaround is to catch when the bar has been added to a window and start
- * the animation there.
- */
- if (view.window() != null) {
- if ((style & SWT.INDETERMINATE) != 0) {
- ((NSProgressIndicator)view).startAnimation(null);
- }
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Sash.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Sash.java
deleted file mode 100755
index dd1454aab4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Sash.java
+++ /dev/null
@@ -1,478 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.accessibility.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of the receiver represent a selectable user interface object
- * that allows the user to drag a rubber banded outline of the sash within
- * the parent control.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL, SMOOTH</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#sash">Sash snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Sash extends Control {
- Cursor sizeCursor;
- boolean dragging;
- int lastX, lastY, startX, startY;
- private final static int INCREMENT = 1;
- private final static int PAGE_INCREMENT = 9;
- NSArray accessibilityAttributes = null;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#SMOOTH
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Sash (Composite parent, int style) {
- super (parent, checkStyle (style));
- int cursorStyle = (style & SWT.VERTICAL) != 0 ? SWT.CURSOR_SIZEWE : SWT.CURSOR_SIZENS;
- sizeCursor = new Cursor (display, cursorStyle);
-}
-
-int /*long*/ accessibilityAttributeNames(int /*long*/ id, int /*long*/ sel) {
- if (accessibilityAttributes == null) {
- NSMutableArray ourAttributes = NSMutableArray.arrayWithCapacity(10);
- ourAttributes.addObject(OS.NSAccessibilityRoleAttribute);
- ourAttributes.addObject(OS.NSAccessibilityRoleDescriptionAttribute);
- ourAttributes.addObject(OS.NSAccessibilityParentAttribute);
- ourAttributes.addObject(OS.NSAccessibilityPositionAttribute);
- ourAttributes.addObject(OS.NSAccessibilitySizeAttribute);
- ourAttributes.addObject(OS.NSAccessibilityWindowAttribute);
- ourAttributes.addObject(OS.NSAccessibilityTopLevelUIElementAttribute);
- ourAttributes.addObject(OS.NSAccessibilityFocusedAttribute);
- ourAttributes.addObject(OS.NSAccessibilityValueAttribute);
- ourAttributes.addObject(OS.NSAccessibilityMaxValueAttribute);
- ourAttributes.addObject(OS.NSAccessibilityMinValueAttribute);
- // The accessibility documentation says that these next two are optional, but the
- // Accessibility Verifier says they are required.
- ourAttributes.addObject(OS.NSAccessibilityNextContentsAttribute);
- ourAttributes.addObject(OS.NSAccessibilityPreviousContentsAttribute);
- ourAttributes.addObject(OS.NSAccessibilityOrientationAttribute);
-
- if (accessible != null) {
- // See if the accessible will override or augment the standard list.
- // Help, title, and description can be overridden.
- NSMutableArray extraAttributes = NSMutableArray.arrayWithCapacity(3);
- extraAttributes.addObject(OS.NSAccessibilityHelpAttribute);
- extraAttributes.addObject(OS.NSAccessibilityDescriptionAttribute);
- extraAttributes.addObject(OS.NSAccessibilityTitleAttribute);
-
- for (int i = (int)/*64*/extraAttributes.count() - 1; i >= 0; i--) {
- NSString attribute = new NSString(extraAttributes.objectAtIndex(i).id);
- if (accessible.internal_accessibilityAttributeValue(attribute, ACC.CHILDID_SELF) != null) {
- ourAttributes.addObject(extraAttributes.objectAtIndex(i));
- }
- }
- }
-
- accessibilityAttributes = ourAttributes;
- accessibilityAttributes.retain();
- }
-
- return accessibilityAttributes.id;
-}
-
-int /*long*/ accessibilityAttributeValue(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- int /*long*/ returnValue = 0;
- NSString attributeName = new NSString(arg0);
-
- if (accessible != null) {
- id returnObject = accessible.internal_accessibilityAttributeValue(attributeName, ACC.CHILDID_SELF);
-
- if (returnObject != null) returnValue = returnObject.id;
- }
-
- if (returnValue != 0) return returnValue;
-
- if (attributeName.isEqualToString (OS.NSAccessibilityRoleAttribute) || attributeName.isEqualToString (OS.NSAccessibilityRoleDescriptionAttribute)) {
- NSString roleText = OS.NSAccessibilitySplitterRole;
-
- if (attributeName.isEqualToString (OS.NSAccessibilityRoleAttribute)) {
- return roleText.id;
- } else { // NSAccessibilityRoleDescriptionAttribute
- return OS.NSAccessibilityRoleDescription (roleText.id, 0);
- }
- } else if (attributeName.isEqualToString (OS.NSAccessibilityEnabledAttribute)) {
- return NSNumber.numberWithBool(isEnabled()).id;
- } else if (attributeName.isEqualToString (OS.NSAccessibilityOrientationAttribute)) {
- NSString orientation = (style & SWT.VERTICAL) != 0 ? OS.NSAccessibilityVerticalOrientationValue : OS.NSAccessibilityHorizontalOrientationValue;
- return orientation.id;
- } else if (attributeName.isEqualToString (OS.NSAccessibilityValueAttribute)) {
- Point location = getLocation();
- int value = (style & SWT.VERTICAL) != 0 ? location.x : location.y;
- return NSNumber.numberWithInt(value).id;
- } else if (attributeName.isEqualToString (OS.NSAccessibilityMaxValueAttribute)) {
- NSRect parentBounds = view.bounds();
- float /*double*/ maxValue = (style & SWT.VERTICAL) != 0 ?
- parentBounds.width :
- parentBounds.height;
- return NSNumber.numberWithInt((int)maxValue).id;
- } else if (attributeName.isEqualToString (OS.NSAccessibilityMinValueAttribute)) {
- return NSNumber.numberWithInt(0).id;
- } else if (attributeName.isEqualToString (OS.NSAccessibilityNextContentsAttribute)) {
- Control[] children = parent._getChildren();
- Control nextView = null;
- for (int i = 0; i < children.length; i++) {
- if (children[i] == this) {
- if (i < children.length - 1) {
- nextView = children[i + 1];
- break;
- }
- }
- }
-
- if (nextView != null)
- return NSArray.arrayWithObject(nextView.view).id;
- else
- return NSArray.array().id;
- } else if (attributeName.isEqualToString (OS.NSAccessibilityPreviousContentsAttribute)) {
- Control[] children = parent._getChildren();
- Control nextView = null;
- for (int i = 0; i < children.length; i++) {
- if (children[i] == this) {
- if (i > 0) {
- nextView = children[i - 1];
- break;
- }
- }
- }
-
- if (nextView != null)
- return NSArray.arrayWithObject(nextView.view).id;
- else
- return NSArray.array().id;
- }
-
- return super.accessibilityAttributeValue(id, sel, arg0);
-}
-
-boolean accessibilityIsIgnored(int /*long*/ id, int /*long*/ sel) {
- return false;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the x, y, width, and height fields of the event object are valid.
- * If the receiver is being dragged, the event object detail field contains the value <code>SWT.DRAG</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- /*
- * Macintosh only supports smooth dragging.
- */
- style |= SWT.SMOOTH;
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-boolean becomeFirstResponder (int /*long*/ id, int /*long*/ sel) {
- boolean result = super.becomeFirstResponder(id, sel);
- NSRect frame = view.frame();
- lastX = (int)frame.x;
- lastY = (int)frame.y;
- return result;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = 0, height = 0;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += DEFAULT_WIDTH; height += 5;
- } else {
- width += 5; height += DEFAULT_HEIGHT;
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- return new Point (width, height);
-}
-
-void createHandle () {
- state |= THEME_BACKGROUND;
- NSView widget = (NSView)new SWTView().alloc();
- widget.init ();
- view = widget;
-}
-
-void drawBackground (int /*long*/ id, NSGraphicsContext context, NSRect rect) {
- if (id != view.id) return;
- fillBackground (view, context, rect, -1);
-}
-
-Cursor findCursor () {
- Cursor cursor = super.findCursor ();
- if (cursor == null) {
- int cursorType = (style & SWT.HORIZONTAL) != 0 ? SWT.CURSOR_SIZENS : SWT.CURSOR_SIZEWE;
- cursor = display.getSystemCursor (cursorType);
- }
- return cursor;
-}
-
-boolean sendKeyEvent(NSEvent nsEvent, int type) {
- super.sendKeyEvent (nsEvent, type);
- if (type == SWT.KeyDown) {
- int keyCode = nsEvent.keyCode();
- switch (keyCode) {
- case 126: /* Up arrow */
- case 123: /* Left arrow */
- case 125: /* Down arrow */
- case 124: /* Right arrow */ {
- int xChange = 0, yChange = 0;
- int stepSize = PAGE_INCREMENT;
- int /*long*/ modifiers = nsEvent.modifierFlags();
- if ((modifiers & OS.NSControlKeyMask) != 0) stepSize = INCREMENT;
- if ((style & SWT.VERTICAL) != 0) {
- if (keyCode == 126 || keyCode == 125) break;
- xChange = keyCode == 123 ? -stepSize : stepSize;
- } else {
- if (keyCode == 123 || keyCode == 124) break;
- yChange = keyCode == 126 ? -stepSize : stepSize;
- }
-
- Rectangle bounds = getBounds ();
- int width = bounds.width, height = bounds.height;
- Rectangle parentBounds = parent.getBounds ();
- int parentWidth = parentBounds.width;
- int parentHeight = parentBounds.height;
- int newX = lastX, newY = lastY;
- if ((style & SWT.VERTICAL) != 0) {
- newX = Math.min (Math.max (0, lastX + xChange), parentWidth - width);
- } else {
- newY = Math.min (Math.max (0, lastY + yChange), parentHeight - height);
- }
- if (newX == lastX && newY == lastY) return true;
- Event event = new Event ();
- event.x = newX;
- event.y = newY;
- event.width = width;
- event.height = height;
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) break;
- if (event.doit) {
- setBounds (event.x, event.y, width, height);
- if (isDisposed ()) break;
- lastX = event.x;
- lastY = event.y;
- if (isDisposed ()) return false;
- int cursorX = event.x, cursorY = event.y;
- if ((style & SWT.VERTICAL) != 0) {
- cursorY += height / 2;
- } else {
- cursorX += width / 2;
- }
- display.setCursorLocation (parent.toDisplay (cursorX, cursorY));
- }
- break;
- }
- }
- }
- return true;
-}
-
-void mouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- //TODO use sendMouseEvent
- super.mouseDown(id, sel, theEvent);
- if (isDisposed()) return;
- NSEvent nsEvent = new NSEvent(theEvent);
- if (nsEvent.clickCount() != 1) return;
- NSPoint location = nsEvent.locationInWindow();
- NSPoint point = view.convertPoint_fromView_(location, null);
- startX = (int)point.x;
- startY = (int)point.y;
- NSRect frame = view.frame();
- Event event = new Event ();
- event.x = (int)frame.x;
- event.y = (int)frame.y;
- event.width = (int)frame.width;
- event.height = (int)frame.height;
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return;
- if (event.doit) {
- lastX = event.x;
- lastY = event.y;
- dragging = true;
- setLocation(event.x, event.y);
- }
-}
-
-boolean mouseEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent, int type) {
- super.mouseEvent (id, sel, theEvent, type);
- return new NSEvent (theEvent).type () != OS.NSLeftMouseDown;
-}
-
-void mouseDragged(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- //TODO use sendMouseEvent
- super.mouseDragged(id, sel, theEvent);
- if (isDisposed()) return;
- if (!dragging) return;
- NSEvent nsEvent = new NSEvent(theEvent);
- NSPoint location = nsEvent.locationInWindow();
- NSPoint point = view.convertPoint_fromView_(location, null);
- NSRect frame = view.frame();
- NSRect parentFrame = parent.topView().frame();
- int newX = lastX, newY = lastY;
- if ((style & SWT.VERTICAL) != 0) {
- newX = Math.min (Math.max (0, (int)(point.x + frame.x - startX)), (int)(parentFrame.width - frame.width));
- } else {
- newY = Math.min (Math.max (0, (int)(point.y + frame.y - startY)), (int)(parentFrame.height - frame.height));
- }
- if (newX == lastX && newY == lastY) return;
- Event event = new Event ();
- event.x = newX;
- event.y = newY;
- event.width = (int)frame.width;
- event.height = (int)frame.height;
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return;
- if (event.doit) {
- lastX = event.x;
- lastY = event.y;
- setBounds (event.x, event.y, (int)frame.width, (int)frame.height);
- }
-}
-
-void mouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- //TODO use sendMouseEvent
- super.mouseUp(id, sel, theEvent);
- if (isDisposed()) return;
- if (!dragging) return;
- dragging = false;
- NSRect frame = view.frame();
- Event event = new Event ();
- event.x = lastX;
- event.y = lastY;
- event.width = (int)frame.width;
- event.height = (int)frame.height;
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return;
- if (event.doit) {
- setBounds (event.x, event.y, (int)frame.width, (int)frame.height);
- }
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (accessibilityAttributes != null) accessibilityAttributes.release();
- accessibilityAttributes = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (sizeCursor != null) sizeCursor.dispose ();
- sizeCursor = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-
-void superKeyDown (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
-}
-
-void superKeyUp (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
-}
-
-int traversalCode (int key, NSEvent theEvent) {
- return 0;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Scale.java
deleted file mode 100755
index 2d120fe32d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Scale.java
+++ /dev/null
@@ -1,362 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.cocoa.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of the receiver represent a selectable user
- * interface object that present a range of continuous
- * numeric values.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#scale">Scale snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Scale extends Control {
- int increment = 1;
- int pageIncrement = 10;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Scale (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the receiver's value.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- NSSlider widget = (NSSlider)view;
- float /*double*/ thickness = widget.knobThickness();
- int width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT;
- if ((style & SWT.HORIZONTAL) != 0) {
- height = (int)Math.ceil(thickness);
- width = height * 10;
- } else {
- width = (int)Math.ceil(thickness);
- height = width * 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- return new Point (width, height);
-}
-
-void createHandle () {
- state |= THEME_BACKGROUND;
- NSSlider widget = (NSSlider)new SWTSlider().alloc();
- widget.init();
- widget.setMaxValue(100);
- widget.setTarget(widget);
- widget.setAction(OS.sel_sendSelection);
- view = widget;
-}
-
-NSFont defaultNSFont () {
- return display.sliderFont;
-}
-
-void deregister() {
- super.deregister();
- display.removeWidget(((NSControl)view).cell());
-}
-
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget();
- return increment;
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget();
- return (int)((NSSlider)view).maxValue();
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget();
- return (int)((NSSlider)view).minValue();
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget();
- return pageIncrement;
-}
-
-/**
- * Returns the 'selection', which is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget();
- return (int)((NSSlider)view).doubleValue();
-}
-
-void register() {
- super.register();
- display.addWidget(((NSControl)view).cell(), this);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-
-void sendSelection () {
- NSEvent currEvent = NSApplication.sharedApplication().currentEvent();
-
- if (currEvent.type() != OS.NSLeftMouseUp)
- postEvent (SWT.Selection);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param increment the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- increment = value;
-}
-
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget();
- int minimum = (int)((NSSlider)view).minValue();
- if (value <= minimum) return;
- ((NSSlider)view).setMaxValue(value);
-}
-
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is negative or is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be nonnegative and less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget();
- int maximum = (int)((NSSlider)view).maxValue();
- if (!(0 <= value && value < maximum)) return;
- ((NSSlider)view).setMinValue(value);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param pageIncrement the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- pageIncrement = value;
-}
-
-/**
- * Sets the 'selection', which is the receiver's value,
- * to the argument which must be greater than or equal to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget();
- ((NSSlider)view).setDoubleValue(value);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ScrollBar.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ScrollBar.java
deleted file mode 100755
index 2a9fee54bd..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ScrollBar.java
+++ /dev/null
@@ -1,685 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.cocoa.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that represent a range of positive, numeric values.
- * <p>
- * At any given moment, a given scroll bar will have a
- * single 'selection' that is considered to be its
- * value, which is constrained to be within the range of
- * values the scroll bar represents (that is, between its
- * <em>minimum</em> and <em>maximum</em> values).
- * </p><p>
- * Typically, scroll bars will be made up of five areas:
- * <ol>
- * <li>an arrow button for decrementing the value</li>
- * <li>a page decrement area for decrementing the value by a larger amount</li>
- * <li>a <em>thumb</em> for modifying the value by mouse dragging</li>
- * <li>a page increment area for incrementing the value by a larger amount</li>
- * <li>an arrow button for incrementing the value</li>
- * </ol>
- * Based on their style, scroll bars are either <code>HORIZONTAL</code>
- * (which have a left facing button for decrementing the value and a
- * right facing button for incrementing it) or <code>VERTICAL</code>
- * (which have an upward facing button for decrementing the value
- * and a downward facing buttons for incrementing it).
- * </p><p>
- * On some platforms, the size of the scroll bar's thumb can be
- * varied relative to the magnitude of the range of values it
- * represents (that is, relative to the difference between its
- * maximum and minimum values). Typically, this is used to
- * indicate some proportional value such as the ratio of the
- * visible area of a document to the total amount of space that
- * it would take to display it. SWT supports setting the thumb
- * size even if the underlying platform does not, but in this
- * case the appearance of the scroll bar will not change.
- * </p><p>
- * Scroll bars are created by specifying either <code>H_SCROLL</code>,
- * <code>V_SCROLL</code> or both when creating a <code>Scrollable</code>.
- * They are accessed from the <code>Scrollable</code> using
- * <code>getHorizontalBar</code> and <code>getVerticalBar</code>.
- * </p><p>
- * Note: Scroll bars are not Controls. On some platforms, scroll bars
- * that appear as part of some standard controls such as a text or list
- * have no operating system resources and are not children of the control.
- * For this reason, scroll bars are treated specially. To create a control
- * that looks like a scroll bar but has operating system resources, use
- * <code>Slider</code>.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see Slider
- * @see Scrollable
- * @see Scrollable#getHorizontalBar
- * @see Scrollable#getVerticalBar
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ScrollBar extends Widget {
- NSScroller view;
- Scrollable parent;
- int minimum, maximum = 100, thumb = 10;
- int increment = 1;
- int pageIncrement = 10;
- id target;
- int /*long*/ actionSelector;;
-
-ScrollBar () {
- /* Do nothing */
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values:
- * <code>SWT.NONE</code> - for the end of a drag.
- * <code>SWT.DRAG</code>.
- * <code>SWT.HOME</code>.
- * <code>SWT.END</code>.
- * <code>SWT.ARROW_DOWN</code>.
- * <code>SWT.ARROW_UP</code>.
- * <code>SWT.PAGE_DOWN</code>.
- * <code>SWT.PAGE_UP</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (view);
-}
-
-boolean getDrawing () {
- return parent.getDrawing ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- return (state & DISABLED) == 0;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget();
- return increment;
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget();
- return maximum;
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget();
- return minimum;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget();
- return pageIncrement;
-}
-
-/**
- * Returns the receiver's parent, which must be a Scrollable.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Scrollable getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the single 'selection' that is the receiver's value.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget();
- NSScroller widget = (NSScroller)view;
- double value = widget.doubleValue();
- return (int)(0.5f + ((maximum - thumb - minimum) * value + minimum));
-}
-
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- NSRect rect = ((NSScroller)view).frame();
- return new Point((int)rect.width, (int)rect.height);
-}
-
-/**
- * Returns the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values.
- *
- * @return the thumb value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ScrollBar
- */
-public int getThumb () {
- checkWidget();
- return thumb;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- return (state & HIDDEN) == 0;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-
-boolean isDrawing () {
- return getDrawing() && parent.isDrawing ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return getVisible () && parent.isVisible ();
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-
-void register () {
- super.register ();
- display.addWidget (view, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (view != null) view.release();
- view = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (parent.horizontalBar == this) parent.horizontalBar = null;
- if (parent.verticalBar == this) parent.verticalBar = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
-}
-
-void sendSelection () {
- int value = 0;
- if (target != null) {
- view.sendAction(actionSelector, target);
- } else {
- value = getSelection ();
- }
- Event event = new Event();
- int hitPart = (int)/*64*/((NSScroller)view).hitPart();
- switch (hitPart) {
- case OS.NSScrollerDecrementLine:
- value -= increment;
- event.detail = SWT.ARROW_UP;
- break;
- case OS.NSScrollerDecrementPage:
- value -= pageIncrement;
- event.detail = SWT.PAGE_UP;
- break;
- case OS.NSScrollerIncrementLine:
- value += increment;
- event.detail = SWT.ARROW_DOWN;
- break;
- case OS.NSScrollerIncrementPage:
- value += pageIncrement;
- event.detail = SWT.PAGE_DOWN;
- break;
- case OS.NSScrollerKnob:
- event.detail = SWT.DRAG;
- break;
- }
- if (target == null) {
- if (event.detail != SWT.DRAG) {
- setSelection(value);
- }
- }
- sendEvent(SWT.Selection, event);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- increment = value;
-}
-
-void setClipRegion (float /*double*/ x, float /*double*/ y) {
- NSRect frame = view.frame();
- parent.setClipRegion(frame.x + x, frame.y + y);
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- if (enabled) {
- if ((state & DISABLED) == 0) return;
- state &= ~DISABLED;
- } else {
- if ((state & DISABLED) != 0) return;
- state |= DISABLED;
- }
- enableWidget (enabled);
-}
-
-void enableWidget (boolean enabled) {
- if (!enabled || (state & DISABLED) == 0) {
- view.setEnabled (enabled);
- }
-}
-
-/**
- * Sets the maximum. If this value is negative or less than or
- * equal to the minimum, the value is ignored. If necessary, first
- * the thumb and then the selection are adjusted to fit within the
- * new range.
- *
- * @param value the new maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget();
- if (value < 0) return;
- if (value <= minimum) return;
- if (value - minimum < thumb) {
- thumb = value - minimum;
- }
- int selection = Math.max(minimum, Math.min (getSelection (), value - thumb));
- this.maximum = value;
- updateBar(selection, minimum, value, thumb);
-}
-
-/**
- * Sets the minimum value. If this value is negative or greater
- * than or equal to the maximum, the value is ignored. If necessary,
- * first the thumb and then the selection are adjusted to fit within
- * the new range.
- *
- * @param value the new minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget();
- if (value < 0) return;
- if (value >= maximum) return;
- if (maximum - value < thumb) {
- thumb = maximum - value;
- }
- int selection = Math.min(maximum - thumb, Math.max (getSelection (), value));
- this.minimum = value;
- updateBar(selection, value, maximum, thumb);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- pageIncrement = value;
-}
-
-/**
- * Sets the single <em>selection</em> that is the receiver's
- * value to the argument which must be greater than or equal
- * to zero.
- *
- * @param selection the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget();
- updateBar(value, minimum, maximum, thumb);
-}
-
-/**
- * Sets the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values. This new
- * value will be ignored if it is less than one, and will be
- * clamped if it exceeds the receiver's current range.
- *
- * @param value the new thumb value, which must be at least one and not
- * larger than the size of the current range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setThumb (int value) {
- checkWidget();
- if (value < 1) return;
- value = Math.min (value, maximum - minimum);
- updateBar(getSelection(), minimum, maximum, value);
- this.thumb = value;
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, thumb, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param thumb the new thumb value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- checkWidget();
- if (minimum < 0) return;
- if (maximum < 0) return;
- if (thumb < 1) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- this.thumb = thumb = Math.min (thumb, maximum - minimum);
- this.maximum = maximum;
- this.minimum = minimum;
- this.increment = increment;
- this.pageIncrement = pageIncrement;
- updateBar (selection, minimum, maximum, thumb);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget();
- parent.setScrollBarVisible (this, visible);
-}
-
-void updateBar (int selection, int minimum, int maximum, int thumb) {
- NSScroller widget = (NSScroller) view;
- selection = Math.max (minimum, Math.min (maximum - thumb, selection));
- int range = maximum - thumb - minimum;
- float fraction = range <= 0 ? 1 : (float) (selection - minimum) / range;
- float knob = range <= 0 ? 1 : (float) thumb / (maximum - minimum);
- widget.setFloatValue (fraction, knob);
- widget.setEnabled (range > 0);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Scrollable.java
deleted file mode 100755
index 50e08c80ba..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Scrollable.java
+++ /dev/null
@@ -1,335 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.cocoa.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * This class is the abstract superclass of all classes which
- * represent controls that have standard scroll bars.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>H_SCROLL, V_SCROLL</dd>
- * <dt><b>Events:</b>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public abstract class Scrollable extends Control {
- NSScrollView scrollView;
- ScrollBar horizontalBar, verticalBar;
-
-Scrollable () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#H_SCROLL
- * @see SWT#V_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Scrollable (Composite parent, int style) {
- super (parent, style);
-}
-
-boolean accessibilityIsIgnored(int /*long*/ id, int /*long*/ sel) {
- // Always ignore scrollers.
- if (scrollView != null && id == scrollView.id) return true;
- return super.accessibilityIsIgnored(id, sel);
-}
-
-/**
- * Given a desired <em>client area</em> for the receiver
- * (as described by the arguments), returns the bounding
- * rectangle which would be required to produce that client
- * area.
- * <p>
- * In other words, it returns a rectangle such that, if the
- * receiver's bounds were set to that rectangle, the area
- * of the receiver which is capable of displaying data
- * (that is, not covered by the "trimmings") would be the
- * rectangle described by the arguments (relative to the
- * receiver's parent).
- * </p>
- *
- * @param x the desired x coordinate of the client area
- * @param y the desired y coordinate of the client area
- * @param width the desired width of the client area
- * @param height the desired height of the client area
- * @return the required bounds to produce the given client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getClientArea
- */
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- if (scrollView != null) {
- NSSize size = new NSSize();
- size.width = width;
- size.height = height;
- int border = hasBorder() ? OS.NSBezelBorder : OS.NSNoBorder;
- size = NSScrollView.frameSizeForContentSize(size, (style & SWT.H_SCROLL) != 0, (style & SWT.V_SCROLL) != 0, border);
- width = (int)size.width;
- height = (int)size.height;
- NSRect frame = scrollView.contentView().frame();
- x -= frame.x;
- y -= frame.y;
- }
- return new Rectangle (x, y, width, height);
-}
-
-ScrollBar createScrollBar (int style) {
- if (scrollView == null) return null;
- ScrollBar bar = new ScrollBar ();
- bar.parent = this;
- bar.style = style;
- bar.display = display;
- NSScroller scroller;
- int /*long*/ actionSelector;
- NSRect rect = new NSRect();
- if ((style & SWT.H_SCROLL) != 0) {
- rect.width = 1;
- } else {
- rect.height = 1;
- }
- scroller = (NSScroller)new SWTScroller().alloc();
- scroller.initWithFrame(rect);
- if ((style & SWT.H_SCROLL) != 0) {
- scrollView.setHorizontalScroller(scroller);
- actionSelector = OS.sel_sendHorizontalSelection;
- } else {
- scrollView.setVerticalScroller(scroller);
- actionSelector = OS.sel_sendVerticalSelection;
- }
- bar.view = scroller;
- bar.createJNIRef();
- bar.register();
- if ((state & CANVAS) == 0) {
- bar.target = scroller.target();
- bar.actionSelector = scroller.action();
- }
- scroller.setTarget(scrollView);
- scroller.setAction(actionSelector);
- if ((state & CANVAS) != 0) {
- bar.updateBar(0, 0, 100, 10);
- }
- return bar;
-}
-
-void createWidget () {
- super.createWidget ();
- if ((style & SWT.H_SCROLL) != 0) horizontalBar = createScrollBar (SWT.H_SCROLL);
- if ((style & SWT.V_SCROLL) != 0) verticalBar = createScrollBar (SWT.V_SCROLL);
-}
-
-void deregister () {
- super.deregister ();
- if (scrollView != null) display.removeWidget (scrollView);
-}
-
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data (that is,
- * not covered by the "trimmings").
- *
- * @return the client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeTrim
- */
-public Rectangle getClientArea () {
- checkWidget();
- if (scrollView != null) {
- NSSize size = scrollView.contentSize();
- NSClipView contentView = scrollView.contentView();
- NSRect bounds = contentView.bounds();
- return new Rectangle((int)bounds.x, (int)bounds.y, (int)size.width, (int)size.height);
- } else {
- NSRect rect = view.bounds();
- return new Rectangle(0, 0, (int)rect.width, (int)rect.height);
- }
-}
-
-/**
- * Returns the receiver's horizontal scroll bar if it has
- * one, and null if it does not.
- *
- * @return the horizontal scroll bar (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ScrollBar getHorizontalBar () {
- checkWidget();
- return horizontalBar;
-}
-
-/**
- * Returns the receiver's vertical scroll bar if it has
- * one, and null if it does not.
- *
- * @return the vertical scroll bar (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ScrollBar getVerticalBar () {
- checkWidget();
- return verticalBar;
-}
-
-boolean hooksKeys () {
- return hooks (SWT.KeyDown) || hooks (SWT.KeyUp) || hooks (SWT.Traverse);
-}
-
-boolean isEventView (int /*long*/ id) {
- return id == eventView ().id;
-}
-
-boolean isTrim (NSView view) {
- if (scrollView != null) {
- if (scrollView.id == view.id) return true;
- if (horizontalBar != null && horizontalBar.view.id == view.id) return true;
- if (verticalBar != null && verticalBar.view.id == view.id) return true;
- }
- return super.isTrim (view);
-}
-
-void register () {
- super.register ();
- if (scrollView != null) display.addWidget (scrollView, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (scrollView != null) scrollView.release();
- scrollView = null;
-}
-
-void releaseChildren (boolean destroy) {
- if (horizontalBar != null) {
- horizontalBar.release (false);
- horizontalBar = null;
- }
- if (verticalBar != null) {
- verticalBar.release (false);
- verticalBar = null;
- }
- super.releaseChildren (destroy);
-}
-
-void sendHorizontalSelection () {
- if (horizontalBar.view.isHiddenOrHasHiddenAncestor()) return;
- if ((state & CANVAS) == 0 && scrollView != null && visibleRgn == 0) {
- scrollView.contentView().setCopiesOnScroll(!isObscured());
- }
- horizontalBar.sendSelection ();
-}
-
-void sendVerticalSelection () {
- if (verticalBar.view.isHiddenOrHasHiddenAncestor()) return;
- if ((state & CANVAS) == 0 && scrollView != null && visibleRgn == 0) {
- scrollView.contentView().setCopiesOnScroll(!isObscured());
- }
- verticalBar.sendSelection ();
-}
-
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- if (horizontalBar != null) horizontalBar.enableWidget (enabled);
- if (verticalBar != null) verticalBar.enableWidget (enabled);
-}
-
-boolean setScrollBarVisible (ScrollBar bar, boolean visible) {
- if (scrollView == null) return false;
- if ((state & CANVAS) == 0) return false;
- if (visible) {
- if ((bar.state & HIDDEN) == 0) return false;
- bar.state &= ~HIDDEN;
- } else {
- if ((bar.state & HIDDEN) != 0) return false;
- bar.state |= HIDDEN;
- }
- if ((bar.style & SWT.HORIZONTAL) != 0) {
- scrollView.setHasHorizontalScroller (visible);
- } else {
- scrollView.setHasVerticalScroller (visible);
- }
- bar.sendEvent (visible ? SWT.Show : SWT.Hide);
- sendEvent (SWT.Resize);
- return true;
-}
-
-void setZOrder () {
- super.setZOrder ();
- if (scrollView != null) scrollView.setDocumentView (view);
-}
-
-NSView topView () {
- if (scrollView != null) return scrollView;
- return super.topView ();
-}
-
-void updateCursorRects (boolean enabled) {
- super.updateCursorRects (enabled);
- if (scrollView == null) return;
- updateCursorRects (enabled, scrollView);
- NSClipView contentView = scrollView.contentView ();
- updateCursorRects (enabled, contentView);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java
deleted file mode 100755
index 3c2f2e66b3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java
+++ /dev/null
@@ -1,1829 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class represent the "windows"
- * which the desktop or "window manager" is managing.
- * Instances that do not have a parent (that is, they
- * are built using the constructor, which takes a
- * <code>Display</code> as the argument) are described
- * as <em>top level</em> shells. Instances that do have
- * a parent are described as <em>secondary</em> or
- * <em>dialog</em> shells.
- * <p>
- * Instances are always displayed in one of the maximized,
- * minimized or normal states:
- * <ul>
- * <li>
- * When an instance is marked as <em>maximized</em>, the
- * window manager will typically resize it to fill the
- * entire visible area of the display, and the instance
- * is usually put in a state where it can not be resized
- * (even if it has style <code>RESIZE</code>) until it is
- * no longer maximized.
- * </li><li>
- * When an instance is in the <em>normal</em> state (neither
- * maximized or minimized), its appearance is controlled by
- * the style constants which were specified when it was created
- * and the restrictions of the window manager (see below).
- * </li><li>
- * When an instance has been marked as <em>minimized</em>,
- * its contents (client area) will usually not be visible,
- * and depending on the window manager, it may be
- * "iconified" (that is, replaced on the desktop by a small
- * simplified representation of itself), relocated to a
- * distinguished area of the screen, or hidden. Combinations
- * of these changes are also possible.
- * </li>
- * </ul>
- * </p><p>
- * The <em>modality</em> of an instance may be specified using
- * style bits. The modality style bits are used to determine
- * whether input is blocked for other shells on the display.
- * The <code>PRIMARY_MODAL</code> style allows an instance to block
- * input to its parent. The <code>APPLICATION_MODAL</code> style
- * allows an instance to block input to every other shell in the
- * display. The <code>SYSTEM_MODAL</code> style allows an instance
- * to block input to all shells, including shells belonging to
- * different applications.
- * </p><p>
- * Note: The styles supported by this class are treated
- * as <em>HINT</em>s, since the window manager for the
- * desktop on which the instance is visible has ultimate
- * control over the appearance and behavior of decorations
- * and modality. For example, some window managers only
- * support resizable windows and will always assume the
- * RESIZE style, even if it is not set. In addition, if a
- * modality style is not supported, it is "upgraded" to a
- * more restrictive modality style that is supported. For
- * example, if <code>PRIMARY_MODAL</code> is not supported,
- * it would be upgraded to <code>APPLICATION_MODAL</code>.
- * A modality style may also be "downgraded" to a less
- * restrictive style. For example, most operating systems
- * no longer support <code>SYSTEM_MODAL</code> because
- * it can freeze up the desktop, so this is typically
- * downgraded to <code>APPLICATION_MODAL</code>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL, SHEET</dd>
- * <dd>APPLICATION_MODAL, MODELESS, PRIMARY_MODAL, SYSTEM_MODAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Activate, Close, Deactivate, Deiconify, Iconify</dd>
- * </dl>
- * Class <code>SWT</code> provides two "convenience constants"
- * for the most commonly required style combinations:
- * <dl>
- * <dt><code>SHELL_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application top level shell: (that
- * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>)
- * </dd>
- * <dt><code>DIALOG_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application dialog shell: (that
- * is, <code>TITLE | CLOSE | BORDER</code>)
- * </dd>
- * </dl>
- * </p>
- * <p>
- * Note: Only one of the styles APPLICATION_MODAL, MODELESS,
- * PRIMARY_MODAL and SYSTEM_MODAL may be specified.
- * </p><p>
- * IMPORTANT: This class is not intended to be subclassed.
- * </p>
- *
- * @see Decorations
- * @see SWT
- * @see <a href="http://www.eclipse.org/swt/snippets/#shell">Shell snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class Shell extends Decorations {
- NSWindow window;
- SWTWindowDelegate windowDelegate;
- int /*long*/ tooltipOwner, tooltipTag, tooltipUserData;
- boolean opened, moved, resized, fullScreen, center;
- Control lastActive;
- Rectangle normalBounds;
- boolean keyInputHappened;
- NSRect currentFrame;
- NSRect fullScreenFrame;
-
- static int DEFAULT_CLIENT_WIDTH = -1;
- static int DEFAULT_CLIENT_HEIGHT = -1;
-
-/**
- * Constructs a new instance of this class. This is equivalent
- * to calling <code>Shell((Display) null)</code>.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell () {
- this ((Display) null);
-}
-
-/**
- * Constructs a new instance of this class given only the style
- * value describing its behavior and appearance. This is equivalent
- * to calling <code>Shell((Display) null, style)</code>.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#TOOL
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (int style) {
- this ((Display) null, style);
-}
-
-/**
- * Constructs a new instance of this class given only the display
- * to create it on. It is created with style <code>SWT.SHELL_TRIM</code>.
- * <p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the shell on
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell (Display display) {
- this (display, SWT.SHELL_TRIM);
-}
-
-/**
- * Constructs a new instance of this class given the display
- * to create it on and a style value describing its behavior
- * and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the shell on
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#TOOL
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (Display display, int style) {
- this (display, null, style, 0, false);
-}
-
-Shell (Display display, Shell parent, int style, int /*long*/handle, boolean embedded) {
- super ();
- checkSubclass ();
- if (display == null) display = Display.getCurrent ();
- if (display == null) display = Display.getDefault ();
- if (!display.isValidThread ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- if (parent != null && parent.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (!Display.getSheetEnabled ()) {
- this.center = parent != null && (style & SWT.SHEET) != 0;
- }
- this.style = checkStyle (parent, style);
- this.parent = parent;
- this.display = display;
- if (handle != 0) {
- if (embedded) {
- view = new NSView(handle);
- } else {
- window = new NSWindow(handle);
- state |= FOREIGN_HANDLE;
- }
- }
- createWidget ();
-}
-
-/**
- * Constructs a new instance of this class given only its
- * parent. It is created with style <code>SWT.DIALOG_TRIM</code>.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the parent is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell (Shell parent) {
- this (parent, SWT.DIALOG_TRIM);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the parent is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#TOOL
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (Shell parent, int style) {
- this (parent != null ? parent.display : null, parent, style, 0, false);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new shell
- * that is not embedded.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Shell</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param display the display for the shell
- * @param handle the handle for the shell
- * @return a new shell object containing the specified display and handle
- *
- * @since 3.3
- */
-public static Shell internal_new (Display display, int /*long*/ handle) {
- return new Shell (display, null, SWT.NO_TRIM, handle, false);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new shell
- * that is 'embedded'. In this case, the handle represents an NSView
- * that acts as an embedded SWT Shell in an AWT Canvas.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Shell</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param display the display for the shell
- * @param handle the handle for the shell
- * @return a new shell object containing the specified display and handle
- *
- * @since 3.5
- */
-public static Shell cocoa_new (Display display, int /*long*/ handle) {
- return new Shell (display, null, SWT.NO_TRIM, handle, true);
-}
-
-static int checkStyle (Shell parent, int style) {
- style = Decorations.checkStyle (style);
- style &= ~SWT.TRANSPARENT;
- int mask = SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.PRIMARY_MODAL;
- if ((style & SWT.SHEET) != 0) {
- if (Display.getSheetEnabled ()) {
- style &= ~(SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX);
- if (parent == null) {
- style &= ~SWT.SHEET;
- style |= SWT.SHELL_TRIM;
- }
- } else {
- style &= ~SWT.SHEET;
- style |= parent == null ? SWT.SHELL_TRIM : SWT.DIALOG_TRIM;
- }
- if ((style & mask) == 0) {
- style |= parent == null ? SWT.APPLICATION_MODAL : SWT.PRIMARY_MODAL;
- }
- }
- int bits = style & ~mask;
- if ((style & SWT.SYSTEM_MODAL) != 0) return bits | SWT.SYSTEM_MODAL;
- if ((style & SWT.APPLICATION_MODAL) != 0) return bits | SWT.APPLICATION_MODAL;
- if ((style & SWT.PRIMARY_MODAL) != 0) return bits | SWT.PRIMARY_MODAL;
- return bits;
-}
-
-boolean accessibilityIsIgnored(int /*long*/ id, int /*long*/ sel) {
- // The content view of a shell is always ignored.
- if (id == view.id) return true;
- return super.accessibilityIsIgnored(id, sel);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when operations are performed on the receiver,
- * by sending the listener one of the messages defined in the
- * <code>ShellListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ShellListener
- * @see #removeShellListener
- */
-public void addShellListener(ShellListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.Activate,typedListener);
- addListener(SWT.Close,typedListener);
- addListener(SWT.Deactivate,typedListener);
- addListener(SWT.Iconify,typedListener);
- addListener(SWT.Deiconify,typedListener);
-}
-
-void becomeKeyWindow (int /*long*/ id, int /*long*/ sel) {
- Display display = this.display;
- display.keyWindow = window;
- super.becomeKeyWindow(id, sel);
- display.checkFocus();
- display.keyWindow = null;
-}
-
-void bringToTop (boolean force) {
- if (getMinimized ()) return;
- if (force) {
- forceActive ();
- } else {
- setActive ();
- }
-}
-
-boolean canBecomeKeyWindow (int /*long*/ id, int /*long*/ sel) {
- if (window.styleMask () == OS.NSBorderlessWindowMask) return true;
- return super.canBecomeKeyWindow (id, sel);
-}
-
-void checkOpen () {
- if (!opened) resized = false;
-}
-
-void center () {
- if (parent == null) return;
- Rectangle rect = getBounds ();
- Rectangle parentRect = display.map (parent, null, parent.getClientArea());
- int x = Math.max (parentRect.x, parentRect.x + (parentRect.width - rect.width) / 2);
- int y = Math.max (parentRect.y, parentRect.y + (parentRect.height - rect.height) / 2);
- Rectangle monitorRect = parent.getMonitor ().getClientArea();
- if (x + rect.width > monitorRect.x + monitorRect.width) {
- x = Math.max (monitorRect.x, monitorRect.x + monitorRect.width - rect.width);
- } else {
- x = Math.max (x, monitorRect.x);
- }
- if (y + rect.height > monitorRect.y + monitorRect.height) {
- y = Math.max (monitorRect.y, monitorRect.y + monitorRect.height - rect.height);
- } else {
- y = Math.max (y, monitorRect.y);
- }
- setLocation (x, y);
-}
-
-/**
- * Requests that the window manager close the receiver in
- * the same way it would be closed when the user clicks on
- * the "close box" or performs some other platform specific
- * key or mouse combination that indicates the window
- * should be removed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#Close
- * @see #dispose
- */
-public void close () {
- checkWidget();
- closeWidget ();
-}
-
-void closeWidget () {
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- if (event.doit && !isDisposed ()) dispose ();
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- Rectangle trim = super.computeTrim(x, y, width, height);
- NSRect rect = new NSRect ();
- rect.x = trim.x;
- rect.y = trim.y;
- rect.width = trim.width;
- rect.height = trim.height;
- if (window != null) {
- if (!fixResize()) {
- rect = window.frameRectForContentRect(rect);
- }
- }
- return new Rectangle ((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
-}
-
-void createHandle () {
- state |= HIDDEN;
- if (window == null) {
- window = (NSWindow) new SWTWindow ().alloc ();
- int styleMask = OS.NSBorderlessWindowMask;
- if ((style & SWT.NO_TRIM) == 0) {
- if ((style & SWT.TITLE) != 0) styleMask |= OS.NSTitledWindowMask;
- if ((style & SWT.CLOSE) != 0) styleMask |= OS.NSClosableWindowMask;
- if ((style & SWT.MIN) != 0) styleMask |= OS.NSMiniaturizableWindowMask;
- if ((style & SWT.MAX) != 0) styleMask |= OS.NSResizableWindowMask;
- if ((style & SWT.RESIZE) != 0) styleMask |= OS.NSResizableWindowMask;
- }
- NSScreen screen = null;
- NSScreen primaryScreen = new NSScreen(NSScreen.screens().objectAtIndex(0));
- if (parent != null) screen = parent.getShell().window.screen();
- if (screen == null) screen = primaryScreen;
- window = window.initWithContentRect(new NSRect(), styleMask, OS.NSBackingStoreBuffered, false, screen);
- if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0 || (style & (SWT.TOOL | SWT.SHEET)) != 0) {
- window.setHasShadow (true);
- }
- if ((style & SWT.NO_TRIM) == 0) {
- NSSize size = window.minSize();
- size.width = NSWindow.minFrameWidthWithTitle(NSString.stringWith(""), styleMask);
- window.setMinSize(size);
- }
- if (fixResize ()) {
- if (window.respondsToSelector(OS.sel_setMovable_)) {
- OS.objc_msgSend(window.id, OS.sel_setMovable_, 0);
- }
- }
- display.cascadeWindow(window, screen);
- NSRect screenFrame = screen.frame();
- float /*double*/ width = screenFrame.width * 5 / 8, height = screenFrame.height * 5 / 8;;
- NSRect frame = window.frame();
- NSRect primaryFrame = primaryScreen.frame();
- frame.y = primaryFrame.height - ((primaryFrame.height - (frame.y + frame.height)) + height);
- frame.width = width;
- frame.height = height;
- window.setFrame(frame, false);
- if ((style & SWT.ON_TOP) != 0) {
- window.setLevel(OS.NSStatusWindowLevel);
- }
- super.createHandle ();
- topView ().setHidden (true);
- } else {
-// int /*long*/ cls = OS.objc_lookUpClass ("SWTWindow");
-// OS.object_setClass(window.id, cls);
- state &= ~HIDDEN;
- //TODO - get the content of the foreign window instead of creating it
- super.createHandle ();
- style |= SWT.NO_BACKGROUND;
- }
- window.setAcceptsMouseMovedEvents(true);
- windowDelegate = (SWTWindowDelegate)new SWTWindowDelegate().alloc().init();
- window.setDelegate(windowDelegate);
- id id = window.fieldEditor (true, null);
- if (id != null) {
- OS.object_setClass (id.id, OS.objc_getClass ("SWTEditorView"));
- }
-}
-
-void deregister () {
- super.deregister ();
- if (window != null) display.removeWidget (window);
- if (windowDelegate != null) display.removeWidget (windowDelegate);
-}
-
-void destroyWidget () {
- NSWindow window = this.window;
- Display display = this.display;
- boolean sheet = (style & (SWT.SHEET)) != 0;
- releaseHandle ();
- if (window != null) {
- if (sheet) {
- NSApplication application = NSApplication.sharedApplication();
- application.endSheet(window, 0);
- }
- window.close();
- }
- //If another shell is not going to become active, clear the menu bar.
- if (!display.isDisposed () && display.getShells ().length == 0) {
- display.setMenuBar (null);
- }
-}
-
-void drawBackground (int /*long*/ id, NSGraphicsContext context, NSRect rect) {
- if (id != view.id) return;
- if (regionPath != null && background == null) {
- context.saveGraphicsState();
- NSColor.windowBackgroundColor().setFill();
- NSBezierPath.fillRect(rect);
- context.restoreGraphicsState();
- return;
- }
- super.drawBackground (id, context, rect);
-}
-
-Control findBackgroundControl () {
- return background != null || backgroundImage != null ? this : null;
-}
-
-Composite findDeferredControl () {
- return layoutCount > 0 ? this : null;
-}
-
-Cursor findCursor () {
- return cursor;
-}
-
-boolean fixResize () {
- /*
- * Feature in Cocoa. It is not possible to have a resizable window
- * without the title bar. The fix is to resize the content view on
- * top of the title bar.
- */
- if ((style & SWT.NO_TRIM) == 0) {
- if ((style & SWT.RESIZE) != 0 && (style & (SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX)) == 0) {
- return true;
- }
- }
- return false;
-}
-
-void fixShell (Shell newShell, Control control) {
- if (this == newShell) return;
- if (control == lastActive) setActiveControl (null);
-}
-
-/**
- * If the receiver is visible, moves it to the top of the
- * drawing order for the display on which it was created
- * (so that all other shells on that display, which are not
- * the receiver's children will be drawn behind it) and forces
- * the window manager to make the shell active.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#open
- * @see Shell#setActive
- */
-public void forceActive () {
- checkWidget ();
- if (!isVisible()) return;
- if (window == null) return;
- makeKeyAndOrderFront ();
- NSApplication application = NSApplication.sharedApplication ();
- application.activateIgnoringOtherApps (true);
-}
-
-/**
- * Returns the receiver's alpha value. The alpha value
- * is between 0 (transparent) and 255 (opaque).
- *
- * @return the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public int getAlpha () {
- checkWidget ();
- // TODO: Should we support embedded frame alpha?
- if (window == null) return 255;
- return (int)(window.alphaValue() * 255);
-}
-
-public Rectangle getBounds () {
- checkWidget();
- NSRect frame = (window == null ? view.frame() : window.frame());
- float /*double*/ y = display.getPrimaryFrame().height - (int)(frame.y + frame.height);
- return new Rectangle ((int)frame.x, (int)y, (int)frame.width, (int)frame.height);
-}
-
-public Rectangle getClientArea () {
- checkWidget();
- NSRect rect;
- if (window != null) {
- rect = window.frame();
- if (!fixResize ()) {
- rect = window.contentRectForFrameRect(rect);
- }
- } else {
- rect = scrollView != null ? scrollView.frame() : view.frame();
- }
- int width = (int)rect.width, height = (int)rect.height;
- if (scrollView != null) {
- NSSize size = new NSSize();
- size.width = width;
- size.height = height;
- size = NSScrollView.contentSizeForFrameSize(size, (style & SWT.H_SCROLL) != 0, (style & SWT.V_SCROLL) != 0, OS.NSNoBorder);
- width = (int)size.width;
- height = (int)size.height;
- }
- return new Rectangle (0, 0, width, height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is currently
- * in fullscreen state, and false otherwise.
- * <p>
- *
- * @return the fullscreen state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getFullScreen () {
- checkWidget();
- return fullScreen;
-}
-
-/**
- * Returns the receiver's input method editor mode. This
- * will be the result of bitwise OR'ing together one or
- * more of the following constants defined in class
- * <code>SWT</code>:
- * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>,
- * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>.
- *
- * @return the IME mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public int getImeInputMode () {
- checkWidget();
- return SWT.NONE;
-}
-
-public Point getLocation () {
- checkWidget();
- // TODO: frame is relative to superview. What does getLocation mean in the embedded case?
- NSRect frame = (window != null ? window.frame() : view.frame());
- float /*double*/ y = display.getPrimaryFrame().height - (int)(frame.y + frame.height);
- return new Point ((int)frame.x, (int)y);
-}
-
-public boolean getMaximized () {
- checkWidget();
- if (window == null) return false;
- return !fullScreen && window.isZoomed();
-}
-
-Shell getModalShell () {
- Shell shell = null;
- Shell [] modalShells = display.modalShells;
- if (modalShells != null) {
- int bits = SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- int index = modalShells.length;
- while (--index >= 0) {
- Shell modal = modalShells [index];
- if (modal != null) {
- if ((modal.style & bits) != 0) {
- Control control = this;
- while (control != null) {
- if (control == modal) break;
- control = control.parent;
- }
- if (control != modal) return modal;
- break;
- }
- if ((modal.style & SWT.PRIMARY_MODAL) != 0) {
- if (shell == null) shell = getShell ();
- if (modal.parent == shell) return modal;
- }
- }
- }
- }
- return null;
-}
-
-/**
- * Gets the receiver's modified state.
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.5
- */
-public boolean getModified () {
- checkWidget ();
- return window.isDocumentEdited ();
-}
-
-public boolean getMinimized () {
- checkWidget();
- if (!getVisible ()) return super.getMinimized ();
- if (window == null) return false;
- return window.isMiniaturized();
-}
-
-/**
- * Returns a point describing the minimum receiver's size. The
- * x coordinate of the result is the minimum width of the receiver.
- * The y coordinate of the result is the minimum height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Point getMinimumSize () {
- checkWidget();
- if (window == null) return new Point(0, 0);
- NSSize size = window.minSize();
- return new Point((int)size.width, (int)size.height);
-}
-
-/**
- * Returns the region that defines the shape of the shell,
- * or null if the shell has the default shape.
- *
- * @return the region that defines the shape of the shell (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public Region getRegion () {
- /* This method is needed for the @since 3.0 Javadoc */
- checkWidget ();
- return region;
-}
-
-public Shell getShell () {
- checkWidget();
- return this;
-}
-
-/**
- * Returns an array containing all shells which are
- * descendants of the receiver.
- * <p>
- * @return the dialog shells
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Shell [] getShells () {
- checkWidget();
- int count = 0;
- Shell [] shells = display.getShells ();
- for (int i=0; i<shells.length; i++) {
- Control shell = shells [i];
- do {
- shell = shell.parent;
- } while (shell != null && shell != this);
- if (shell == this) count++;
- }
- int index = 0;
- Shell [] result = new Shell [count];
- for (int i=0; i<shells.length; i++) {
- Control shell = shells [i];
- do {
- shell = shell.parent;
- } while (shell != null && shell != this);
- if (shell == this) {
- result [index++] = shells [i];
- }
- }
- return result;
-}
-
-public Point getSize () {
- checkWidget();
- NSRect frame = (window != null ? window.frame() : view.frame());
- return new Point ((int) frame.width, (int) frame.height);
-}
-
-float getThemeAlpha () {
- return 1;
-}
-
-boolean hasBorder () {
- return false;
-}
-
-void helpRequested(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- Control control = display.getFocusControl();
- while (control != null) {
- if (control.hooks (SWT.Help)) {
- control.postEvent (SWT.Help);
- break;
- }
- control = control.parent;
- }
-}
-
-void invalidateVisibleRegion () {
- resetVisibleRegion ();
- invalidateChildrenVisibleRegion ();
-}
-
-boolean isDrawing () {
- return getDrawing ();
-}
-
-public boolean isEnabled () {
- checkWidget();
- return getEnabled ();
-}
-
-boolean isEnabledCursor () {
- return true;
-}
-
-public boolean isVisible () {
- checkWidget();
- return getVisible ();
-}
-
-boolean makeFirstResponder (int /*long*/ id, int /*long*/ sel, int /*long*/ responder) {
- Display display = this.display;
- boolean result = super.makeFirstResponder(id, sel, responder);
- display.checkFocus();
- return result;
-}
-
-void makeKeyAndOrderFront() {
- /*
- * Bug in Cocoa. If a child window becomes the key window when its
- * parent window is miniaturized, the parent window appears as if
- * restored to its full size without actually being restored. In this
- * case the parent window does become active when its child is closed
- * and the user is forced to restore the window from the dock.
- * The fix is to be sure that the parent window is deminiaturized before
- * making the child a key window.
- */
- if (parent != null) {
- Shell shell = (Shell) parent;
- if (shell.window.isMiniaturized()) shell.window.deminiaturize(null);
- }
- window.makeKeyAndOrderFront (null);
-}
-
-void noResponderFor(int /*long*/ id, int /*long*/ sel, int /*long*/ selector) {
- /**
- * Feature in Cocoa. If the selector is keyDown and nothing has handled the event
- * a system beep is generated. There's no need to beep, as many keystrokes in the SWT
- * are listened for and acted upon but not explicitly handled in a keyDown handler. Fix is to
- * not call the default implementation when a keyDown: is being handled.
- */
- if (selector != OS.sel_keyDown_) super.noResponderFor(id, sel, selector);
-}
-
-/**
- * Moves the receiver to the top of the drawing order for
- * the display on which it was created (so that all other
- * shells on that display, which are not the receiver's
- * children will be drawn behind it), marks it visible,
- * sets the focus and asks the window manager to make the
- * shell active.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#setActive
- * @see Shell#forceActive
- */
-public void open () {
- checkWidget();
- int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- if ((style & mask) != 0) {
- display.setModalShell (this);
- } else {
- updateModal ();
- }
- bringToTop (false);
- setWindowVisible (true, true);
- if (isDisposed ()) return;
- if (!restoreFocus () && !traverseGroup (true)) {
- // if the parent shell is minimized, setting focus will cause it
- // to become unminimized.
- if (parent == null || !((Shell)parent).window.isMiniaturized()) {
- setFocus ();
- }
- }
-}
-
-public boolean print (GC gc) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- return false;
-}
-
-void register () {
- super.register ();
- if (window != null) display.addWidget (window, this);
- if (windowDelegate != null) display.addWidget (windowDelegate, this);
-}
-
-void releaseChildren (boolean destroy) {
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (shell != null && !shell.isDisposed ()) {
- shell.dispose ();
- }
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- if (window != null) window.setDelegate(null);
- if (windowDelegate != null) windowDelegate.release();
- windowDelegate = null;
- super.releaseHandle ();
- window = null;
-}
-
-void releaseParent () {
- /* Do nothing */
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- display.clearModal (this);
- updateParent (false);
- display.updateQuitMenu();
- lastActive = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when operations are performed on the receiver.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ShellListener
- * @see #addShellListener
- */
-public void removeShellListener(ShellListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Activate, listener);
- eventTable.unhook(SWT.Close, listener);
- eventTable.unhook(SWT.Deactivate, listener);
- eventTable.unhook(SWT.Iconify,listener);
- eventTable.unhook(SWT.Deiconify,listener);
-}
-
-void sendToolTipEvent (boolean enter) {
- if (!isVisible()) return;
- if (tooltipTag == 0) {
- NSView view = window.contentView();
- tooltipTag = view.addToolTipRect(new NSRect(), window, 0);
- if (tooltipTag != 0) {
- NSTrackingArea trackingArea = new NSTrackingArea(tooltipTag);
- id owner = trackingArea.owner();
- if (owner != null) tooltipOwner = owner.id;
- id userInfo = trackingArea.userInfo();
- if (userInfo != null) {
- tooltipUserData = userInfo.id;
- } else {
- int /*long*/ [] value = new int /*long*/ [1];
- OS.object_getInstanceVariable(tooltipTag, new byte[]{'_','u', 's', 'e', 'r', 'I', 'n', 'f', 'o'}, value);
- tooltipUserData = value[0];
- }
- }
- }
- if (tooltipTag == 0 || tooltipOwner == 0 || tooltipUserData == 0) return;
- NSPoint pt = window.convertScreenToBase(NSEvent.mouseLocation());
- NSEvent event = NSEvent.enterExitEventWithType(enter ? OS.NSMouseEntered : OS.NSMouseExited, pt, 0, 0, window.windowNumber(), null, 0, tooltipTag, tooltipUserData);
- OS.objc_msgSend(tooltipOwner, enter ? OS.sel_mouseEntered_ : OS.sel_mouseExited_, event.id);
-}
-
-/**
- * If the receiver is visible, moves it to the top of the
- * drawing order for the display on which it was created
- * (so that all other shells on that display, which are not
- * the receiver's children will be drawn behind it) and asks
- * the window manager to make the shell active
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#open
- * @see Shell#setActive
- */
-public void setActive () {
- if (window == null) return;
- checkWidget ();
- if (!isVisible()) return;
- makeKeyAndOrderFront ();
-}
-
-void setActiveControl (Control control) {
- if (control != null && control.isDisposed ()) control = null;
- if (lastActive != null && lastActive.isDisposed ()) lastActive = null;
- if (lastActive == control) return;
-
- /*
- * Compute the list of controls to be activated and
- * deactivated by finding the first common parent
- * control.
- */
- Control [] activate = (control == null) ? new Control[0] : control.getPath ();
- Control [] deactivate = (lastActive == null) ? new Control[0] : lastActive.getPath ();
- lastActive = control;
- int index = 0, length = Math.min (activate.length, deactivate.length);
- while (index < length) {
- if (activate [index] != deactivate [index]) break;
- index++;
- }
-
- /*
- * It is possible (but unlikely), that application
- * code could have destroyed some of the widgets. If
- * this happens, keep processing those widgets that
- * are not disposed.
- */
- for (int i=deactivate.length-1; i>=index; --i) {
- if (!deactivate [i].isDisposed ()) {
- deactivate [i].sendEvent (SWT.Deactivate);
- }
- }
- for (int i=activate.length-1; i>=index; --i) {
- if (!activate [i].isDisposed ()) {
- activate [i].sendEvent (SWT.Activate);
- }
- }
-}
-
-/**
- * Sets the receiver's alpha value which must be
- * between 0 (transparent) and 255 (opaque).
- * <p>
- * This operation requires the operating system's advanced
- * widgets subsystem which may not be available on some
- * platforms.
- * </p>
- * @param alpha the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setAlpha (int alpha) {
- if (window == null) return;
- checkWidget ();
- alpha &= 0xFF;
- window.setAlphaValue (alpha / 255f);
-}
-
-void setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- // Embedded Shells are not resizable.
- if (window == null) return;
- if (fullScreen) setFullScreen (false);
- boolean sheet = window.isSheet();
- if (sheet && move && !resize) return;
- int screenHeight = (int) display.getPrimaryFrame().height;
- NSRect frame = window.frame();
- if (!move) {
- x = (int)frame.x;
- y = screenHeight - (int)(frame.y + frame.height);
- }
- if (resize) {
- NSSize minSize = window.minSize();
- width = Math.max(width, (int)minSize.width);
- height = Math.max(height, (int)minSize.height);
- } else {
- width = (int)frame.width;
- height = (int)frame.height;
- }
- if (sheet) {
- y = screenHeight - (int)(frame.y + frame.height);
- NSRect parentRect = parent.getShell().window.frame();
- frame.width = width;
- frame.height = height;
- frame.x = parentRect.x + (parentRect.width - frame.width) / 2;
- frame.y = screenHeight - (int)(y + frame.height);
- window.setFrame(frame, isVisible(), true);
- } else {
- frame.x = x;
- frame.y = screenHeight - (int)(y + height);
- frame.width = width;
- frame.height = height;
- window.setFrame(frame, isVisible());
- }
-}
-
-void setClipRegion (float /*double*/ x, float /*double*/ y) {
- if (regionPath != null) {
- NSAffineTransform transform = NSAffineTransform.transform();
- transform.translateXBy(-x, -y);
- regionPath.transformUsingAffineTransform(transform);
- regionPath.addClip();
- transform.translateXBy(2*x, 2*y);
- regionPath.transformUsingAffineTransform(transform);
- }
-}
-
-public void setEnabled (boolean enabled) {
- checkWidget();
- if (((state & DISABLED) == 0) == enabled) return;
- super.setEnabled (enabled);
-// if (enabled && OS.IsWindowActive (shellHandle)) {
-// if (!restoreFocus ()) traverseGroup (false);
-// }
-}
-
-/**
- * Sets the full screen state of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the full screen state, and if the argument is
- * <code>false</code> and the receiver was previously switched
- * into full screen state, causes the receiver to switch back
- * to either the maximized or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setFullScreen(true)</code>,
- * <code>setMaximized(true)</code> and <code>setMinimized(true)</code> will
- * vary by platform. Typically, the behavior will match the platform user's
- * expectations, but not always. This should be avoided if possible.
- * </p>
- *
- * @param fullScreen the new fullscreen state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setFullScreen (boolean fullScreen) {
- checkWidget ();
- if (this.fullScreen == fullScreen) return;
- this.fullScreen = fullScreen;
-
- if (fullScreen) {
- currentFrame = window.frame();
- window.setShowsResizeIndicator(false); //only hides resize indicator
- if (window.respondsToSelector(OS.sel_setMovable_)) {
- OS.objc_msgSend(window.id, OS.sel_setMovable_, 0);
- }
-
- fullScreenFrame = NSScreen.mainScreen().frame();
- if (getMonitor().equals(display.getPrimaryMonitor ())) {
- if (menuBar != null) {
- float /*double*/ menuBarHt = currentFrame.height - contentView().frame().height;
- fullScreenFrame.height -= menuBarHt;
- OS.SetSystemUIMode(OS.kUIModeContentHidden, 0);
- }
- else {
- OS.SetSystemUIMode(OS.kUIModeAllHidden, 0);
- }
- }
- window.setFrame(fullScreenFrame, true);
- window.contentView().setFrame(fullScreenFrame);
- } else {
- window.setShowsResizeIndicator(true);
- if (window.respondsToSelector(OS.sel_setMovable_)) {
- OS.objc_msgSend(window.id, OS.sel_setMovable_, 1);
- }
- OS.SetSystemUIMode(OS.kUIModeNormal, 0);
- window.setFrame(currentFrame, true);
- }
-}
-
-public void setMenuBar (Menu menu) {
- checkWidget();
- super.setMenuBar (menu);
- if (display.getActiveShell () == this) {
- display.setMenuBar (menuBar);
- }
-}
-
-/**
- * Sets the input method editor mode to the argument which
- * should be the result of bitwise OR'ing together one or more
- * of the following constants defined in class <code>SWT</code>:
- * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>,
- * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>.
- *
- * @param mode the new IME mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public void setImeInputMode (int mode) {
- checkWidget();
-}
-
-public void setMaximized (boolean maximized) {
- checkWidget();
- super.setMaximized (maximized);
- if (window == null) return;
- if (window.isZoomed () == maximized) return;
- window.zoom (null);
-}
-
-public void setMinimized (boolean minimized) {
- checkWidget();
- super.setMinimized (minimized);
- if (window == null) return;
- if (minimized) {
- window.miniaturize (null);
- } else {
- window.deminiaturize (null);
- }
-}
-
-/**
- * Sets the receiver's minimum size to the size specified by the arguments.
- * If the new minimum size is larger than the current size of the receiver,
- * the receiver is resized to the new minimum size.
- *
- * @param width the new minimum width for the receiver
- * @param height the new minimum height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setMinimumSize (int width, int height) {
- checkWidget();
- if (window == null) return;
- NSSize size = new NSSize();
- size.width = width;
- size.height = height;
- window.setMinSize(size);
- NSRect frame = window.frame();
- if (width > frame.width || height > frame.height) {
- width = (int)(width > frame.width ? width : frame.width);
- height = (int)(height > frame.height ? height : frame.height);
- setBounds(0, 0, width, height, false, true);
- }
-}
-
-/**
- * Sets the receiver's minimum size to the size specified by the argument.
- * If the new minimum size is larger than the current size of the receiver,
- * the receiver is resized to the new minimum size.
- *
- * @param size the new minimum size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setMinimumSize (Point size) {
- checkWidget();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setMinimumSize (size.x, size.y);
-}
-
-/**
- * Sets the receiver's modified state as specified by the argument.
- *
- * @param modified the new modified state for the receiver
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.5
- */
-public void setModified (boolean modified) {
- checkWidget ();
- window.setDocumentEdited (modified);
-}
-
-/**
- * Sets the shape of the shell to the region specified
- * by the argument. When the argument is null, the
- * default shape of the shell is restored. The shell
- * must be created with the style SWT.NO_TRIM in order
- * to specify a region.
- *
- * @param region the region that defines the shape of the shell (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public void setRegion (Region region) {
- checkWidget ();
- if ((style & SWT.NO_TRIM) == 0) return;
- if (window == null) return;
- if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- this.region = region;
- if (regionPath != null) regionPath.release();
- regionPath = getPath(region);
- if (region != null) {
- window.setBackgroundColor(NSColor.clearColor());
- window.setOpaque(false);
- } else {
- window.setBackgroundColor(NSColor.windowBackgroundColor());
- window.setOpaque(true);
- }
- window.contentView().setNeedsDisplay(true);
- if (isVisible() && window.hasShadow()) {
- window.display();
- window.invalidateShadow();
- }
-}
-
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (window == null) return;
- super.setText (string);
- NSString str = NSString.stringWith(string);
- window.setTitle(str);
-}
-
-public void setVisible (boolean visible) {
- checkWidget();
- int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- if ((style & mask) != 0) {
- if (visible) {
- display.setModalShell (this);
- } else {
- display.clearModal (this);
- }
- } else {
- updateModal ();
- }
- if (window == null) {
- super.setVisible(visible);
- } else {
- setWindowVisible (visible, false);
- }
-}
-
-void setWindowVisible (boolean visible, boolean key) {
- if (visible) {
- if ((state & HIDDEN) == 0) return;
- state &= ~HIDDEN;
- } else {
- if ((state & HIDDEN) != 0) return;
- state |= HIDDEN;
- }
- if (window != null && (window.isVisible() == visible)) return;
- if (visible) {
- display.clearPool ();
- if (center && !moved) {
- if (isDisposed ()) return;
- center ();
- }
- sendEvent (SWT.Show);
- if (isDisposed ()) return;
- topView ().setHidden (false);
- invalidateVisibleRegion();
- if ((style & (SWT.SHEET)) != 0) {
- NSApplication application = NSApplication.sharedApplication();
- application.beginSheet(window, ((Shell)parent).window, null, 0, 0);
- if (OS.VERSION <= 0x1060 && window.respondsToSelector(OS.sel__setNeedsToUseHeartBeatWindow_)) {
- OS.objc_msgSend(window.id, OS.sel__setNeedsToUseHeartBeatWindow_, 0);
- }
- } else {
- // If the parent window is miniaturized, the window will be shown
- // when its parent is shown.
- boolean parentMinimized = parent != null && ((Shell)parent).window.isMiniaturized();
- if (!parentMinimized) {
- if (key) {
- makeKeyAndOrderFront ();
- } else {
- window.orderFront (null);
- }
- }
- }
- updateParent (visible);
- opened = true;
- if (!moved) {
- moved = true;
- sendEvent (SWT.Move);
- if (isDisposed ()) return;
- }
- if (!resized) {
- resized = true;
- sendEvent (SWT.Resize);
- if (isDisposed ()) return;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
- }
- } else {
- updateParent (visible);
- if ((style & (SWT.SHEET)) != 0) {
- NSApplication application = NSApplication.sharedApplication();
- application.endSheet(window, 0);
- }
- window.orderOut (null);
- topView ().setHidden (true);
- invalidateVisibleRegion();
- sendEvent (SWT.Hide);
- }
-
- display.updateQuitMenu();
-}
-
-void setZOrder () {
- if (scrollView != null) scrollView.setDocumentView (view);
- if (window == null) return;
- window.setContentView (scrollView != null ? scrollView : view);
- if (fixResize ()) {
- NSRect rect = window.frame();
- rect.x = rect.y = 0;
- window.contentView().setFrame(rect);
- }
-}
-
-void setZOrder (Control control, boolean above) {
- if (window == null) return;
- if (control == null) {
- if (above) {
- window.orderFront(null);
- } else {
- window.orderBack(null);
- }
- } else {
- NSWindow otherWindow = control.getShell().window;
- window.orderWindow(above ? OS.NSWindowAbove : OS.NSWindowBelow, otherWindow.windowNumber());
- }
-}
-
-boolean traverseEscape () {
- if (parent == null) return false;
- if (!isVisible () || !isEnabled ()) return false;
- close ();
- return true;
-}
-
-void updateModal () {
- // do nothing
-}
-
-void updateParent (boolean visible) {
- if (visible) {
- if (parent != null && parent.getVisible ()) {
- ((Shell)parent).window.addChildWindow (window, OS.NSWindowAbove);
- }
- } else {
- NSWindow parentWindow = window.parentWindow ();
- if (parentWindow != null) parentWindow.removeChildWindow (window);
- }
- Shell [] shells = getShells ();
- for (int i = 0; i < shells.length; i++) {
- Shell shell = shells [i];
- if (shell.parent == this && shell.getVisible ()) {
- shell.updateParent (visible);
- }
- }
-}
-
-void updateSystemUIMode () {
- if (!getMonitor ().equals (display.getPrimaryMonitor ())) return;
- if (fullScreen) {
- int mode = OS.kUIModeAllHidden;
- if (menuBar != null) {
- mode = OS.kUIModeContentHidden;
- }
- OS.SetSystemUIMode (mode, 0);
- window.setFrame(fullScreenFrame, true);
- } else {
- OS.SetSystemUIMode (OS.kUIModeNormal, 0);
- }
-}
-
-int /*long*/ view_stringForToolTip_point_userData (int /*long*/ id, int /*long*/ sel, int /*long*/ view, int /*long*/ tag, int /*long*/ point, int /*long*/ userData) {
- NSPoint pt = new NSPoint();
- OS.memmove (pt, point, NSPoint.sizeof);
- Control control = display.findControl (false);
- if (control == null) return 0;
- Widget target = control.findTooltip (new NSView (view).convertPoint_toView_ (pt, null));
- String string = target.tooltipText ();
- if (string == null) return 0;
- char[] chars = new char [string.length ()];
- string.getChars (0, chars.length, chars, 0);
- int length = fixMnemonic (chars);
- return NSString.stringWithCharacters (chars, length).id;
-}
-
-void windowDidBecomeKey(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
- super.windowDidBecomeKey(id, sel, notification);
- Display display = this.display;
- display.setMenuBar (menuBar);
- sendEvent (SWT.Activate);
- if (isDisposed ()) return;
- Shell parentShell = this;
- while (parentShell.parent != null) {
- parentShell = (Shell) parentShell.parent;
- if (parentShell.fullScreen) {
- break;
- }
- }
- if (!parentShell.fullScreen || menuBar != null) {
- updateSystemUIMode ();
- } else {
- parentShell.updateSystemUIMode ();
- }
-}
-
-void windowDidMove(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
- moved = true;
- sendEvent(SWT.Move);
-}
-
-void windowDidResize(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
- if (fullScreen) {
- window.setFrame(fullScreenFrame, true);
- window.contentView().setFrame(fullScreenFrame);
- }
- if (fixResize ()) {
- NSRect rect = window.frame ();
- rect.x = rect.y = 0;
- window.contentView ().setFrame (rect);
- }
- resized = true;
- sendEvent (SWT.Resize);
- if (isDisposed ()) return;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
-}
-
-void windowDidResignKey(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
- super.windowDidResignKey(id, sel, notification);
- sendEvent (SWT.Deactivate);
-}
-
-void windowSendEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ event) {
- NSEvent nsEvent = new NSEvent (event);
- int type = (int)/*64*/nsEvent.type ();
- switch (type) {
- case OS.NSLeftMouseUp:
- case OS.NSRightMouseUp:
- case OS.NSOtherMouseUp:
- case OS.NSMouseMoved:
- NSView[] hitView = new NSView[1];
- Control control = display.findControl (false, hitView);
- if (control != null && (!control.isActive() || !control.isEnabled())) control = null;
- if (type == OS.NSMouseMoved) {
- Control trimControl = control;
- if (trimControl != null && trimControl.isTrim (hitView[0])) trimControl = null;
- display.checkEnterExit (trimControl, nsEvent, false);
- if (trimControl != null) trimControl.sendMouseEvent (nsEvent, type, false);
- }
- Widget target = null;
- if (control != null) target = control.findTooltip (nsEvent.locationInWindow());
- if (display.tooltipControl != control || display.tooltipTarget != target) {
- Control oldControl = display.tooltipControl;
- Shell oldShell = oldControl != null && !oldControl.isDisposed() ? oldControl.getShell() : null;
- Shell shell = control != null && !control.isDisposed() ? control.getShell() : null;
- if (oldShell != null) oldShell.sendToolTipEvent (false);
- if (shell != null) shell.sendToolTipEvent (true);
- }
- display.tooltipControl = control;
- display.tooltipTarget = target;
- break;
-
- case OS.NSKeyDown:
- /**
- * Feature in cocoa. Control+Tab, Ctrl+Shift+Tab, Ctrl+PageDown and Ctrl+PageUp are
- * swallowed to handle native traversal. If we find that, force the key event to
- * the first responder.
- */
- if ((nsEvent.modifierFlags() & OS.NSControlKeyMask) != 0) {
- NSString chars = nsEvent.characters();
-
- if (chars != null && chars.length() == 1) {
- int firstChar = (int)/*64*/chars.characterAtIndex(0);
-
- // Shift-tab appears as control-Y.
- switch (firstChar) {
- case '\t':
- case 25:
- case OS.NSPageDownFunctionKey:
- case OS.NSPageUpFunctionKey:
- window.firstResponder().keyDown(nsEvent);
- return;
- }
- }
- }
- break;
- }
- super.windowSendEvent (id, sel, event);
-}
-
-boolean windowShouldClose(int /*long*/ id, int /*long*/ sel, int /*long*/ window) {
- closeWidget ();
- return false;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Slider.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Slider.java
deleted file mode 100755
index 305d47d879..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Slider.java
+++ /dev/null
@@ -1,527 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.cocoa.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that represent a range of positive, numeric values.
- * <p>
- * At any given moment, a given slider will have a
- * single 'selection' that is considered to be its
- * value, which is constrained to be within the range of
- * values the slider represents (that is, between its
- * <em>minimum</em> and <em>maximum</em> values).
- * </p><p>
- * Typically, sliders will be made up of five areas:
- * <ol>
- * <li>an arrow button for decrementing the value</li>
- * <li>a page decrement area for decrementing the value by a larger amount</li>
- * <li>a <em>thumb</em> for modifying the value by mouse dragging</li>
- * <li>a page increment area for incrementing the value by a larger amount</li>
- * <li>an arrow button for incrementing the value</li>
- * </ol>
- * Based on their style, sliders are either <code>HORIZONTAL</code>
- * (which have a left facing button for decrementing the value and a
- * right facing button for incrementing it) or <code>VERTICAL</code>
- * (which have an upward facing button for decrementing the value
- * and a downward facing buttons for incrementing it).
- * </p><p>
- * On some platforms, the size of the slider's thumb can be
- * varied relative to the magnitude of the range of values it
- * represents (that is, relative to the difference between its
- * maximum and minimum values). Typically, this is used to
- * indicate some proportional value such as the ratio of the
- * visible area of a document to the total amount of space that
- * it would take to display it. SWT supports setting the thumb
- * size even if the underlying platform does not, but in this
- * case the appearance of the slider will not change.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see ScrollBar
- * @see <a href="http://www.eclipse.org/swt/snippets/#slider">Slider snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Slider extends Control {
- boolean dragging;
- int minimum, maximum, thumb;
- int increment = 1;
- int pageIncrement = 10;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Slider (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values:
- * <code>SWT.NONE</code> - for the end of a drag.
- * <code>SWT.DRAG</code>.
- * <code>SWT.HOME</code>.
- * <code>SWT.END</code>.
- * <code>SWT.ARROW_DOWN</code>.
- * <code>SWT.ARROW_UP</code>.
- * <code>SWT.PAGE_DOWN</code>.
- * <code>SWT.PAGE_UP</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = 0, height = 0;
- if ((style & SWT.HORIZONTAL) != 0) {
- height = (int)NSScroller.scrollerWidthForControlSize(((NSScroller)view).controlSize());
- width = height * 10;
- } else {
- width = (int)NSScroller.scrollerWidthForControlSize(((NSScroller)view).controlSize());
- height = width * 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- return new Point (width, height);
-}
-
-void createHandle () {
- NSScroller widget = (NSScroller)new SWTScroller().alloc();
- NSRect rect = new NSRect();
- if ((style & SWT.HORIZONTAL) != 0) {
- rect.width = 1;
- } else {
- rect.height = 1;
- }
- widget.initWithFrame(rect);
- widget.setEnabled(true);
- widget.setTarget(widget);
- widget.setAction(OS.sel_sendSelection);
- view = widget;
- updateBar(0, minimum, maximum, thumb);
-}
-
-void createWidget () {
- maximum = 100;
- thumb = 10;
- super.createWidget();
-}
-
-NSFont defaultNSFont () {
- return display.scrollerFont;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget();
- return increment;
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget();
- return maximum;
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget();
- return minimum;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget();
- return pageIncrement;
-}
-
-/**
- * Returns the 'selection', which is the receiver's value.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget();
- NSScroller widget = (NSScroller)view;
- double value = widget.doubleValue();
- return (int)(0.5f + ((maximum - thumb - minimum) * value + minimum));
-}
-
-/**
- * Returns the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values.
- *
- * @return the thumb value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getThumb () {
- checkWidget();
- return thumb;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-
-void sendSelection () {
- Event event = new Event();
- int hitPart = (int)/*64*/((NSScroller)view).hitPart();
- int value = getSelection ();
- switch (hitPart) {
- case OS.NSScrollerDecrementLine:
- event.detail = SWT.ARROW_UP;
- value -= increment;
- break;
- case OS.NSScrollerDecrementPage:
- value -= pageIncrement;
- event.detail = SWT.PAGE_UP;
- break;
- case OS.NSScrollerIncrementLine:
- value += increment;
- event.detail = SWT.ARROW_DOWN;
- break;
- case OS.NSScrollerIncrementPage:
- value += pageIncrement;
- event.detail = SWT.PAGE_DOWN;
- break;
- case OS.NSScrollerKnob:
- event.detail = SWT.DRAG;
- break;
- }
- if (event.detail != SWT.DRAG) {
- setSelection(value);
- }
- sendEvent(SWT.Selection, event);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- increment = value;
-}
-
-/**
- * Sets the maximum. If this value is negative or less than or
- * equal to the minimum, the value is ignored. If necessary, first
- * the thumb and then the selection are adjusted to fit within the
- * new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget();
- if (value < 0) return;
- if (value <= minimum) return;
- if (value - minimum < thumb) {
- thumb = value - minimum;
- }
- int selection = Math.max(minimum, Math.min (getSelection (), value - thumb));
- this.maximum = value;
- updateBar(selection, minimum, value, thumb);
-}
-
-/**
- * Sets the minimum value. If this value is negative or greater
- * than or equal to the maximum, the value is ignored. If necessary,
- * first the thumb and then the selection are adjusted to fit within
- * the new range.
- *
- * @param value the new minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget();
- if (value < 0) return;
- if (value >= maximum) return;
- if (maximum - value < thumb) {
- thumb = maximum - value;
- }
- int selection = Math.min(maximum - thumb, Math.max (getSelection (), value));
- this.minimum = value;
- updateBar(selection, value, maximum, thumb);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- pageIncrement = value;
-}
-
-/**
- * Sets the 'selection', which is the receiver's
- * value, to the argument which must be greater than or equal
- * to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget();
- updateBar(value, minimum, maximum, thumb);
-}
-
-void setSmallSize () {
- /* This code is intentionally comment */
-// ((NSScroller)view).setControlSize (OS.NSSmallControlSize);
-}
-
-void updateBar (int selection, int minimum, int maximum, int thumb) {
- NSScroller widget = (NSScroller)view;
- selection = Math.max (minimum, Math.min (maximum - thumb, selection));
- int range = maximum - thumb - minimum;
- float fraction = range <= 0 ? 1 : (float)(selection - minimum) / range;
- float knob = range <= 0 ? 1 : (float)thumb / (maximum - minimum);
- widget.setFloatValue (fraction, knob);
-}
-
-/**
- * Sets the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values. This new
- * value will be ignored if it is less than one, and will be
- * clamped if it exceeds the receiver's current range.
- *
- * @param value the new thumb value, which must be at least one and not
- * larger than the size of the current range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setThumb (int value) {
- checkWidget();
- if (value < 1) return;
- value = Math.min (value, maximum - minimum);
- updateBar(getSelection(), minimum, maximum, value);
- this.thumb = value;
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, thumb, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param thumb the new thumb value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- checkWidget();
- if (minimum < 0) return;
- if (maximum < 0) return;
- if (thumb < 1) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- thumb = Math.min (thumb, maximum - minimum);
- this.thumb = thumb;
- this.maximum = maximum;
- this.minimum = minimum;
- this.increment = increment;
- this.pageIncrement = pageIncrement;
- updateBar(selection, minimum, maximum, thumb);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Spinner.java
deleted file mode 100755
index 6c53ac470b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Spinner.java
+++ /dev/null
@@ -1,1064 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify numeric
- * values.
- * <p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, Modify, Verify</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#spinner">Spinner snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Spinner extends Composite {
- NSTextField textView;
- NSNumberFormatter textFormatter;
- NSStepper buttonView;
- int pageIncrement = 10;
- int digits = 0;
- int textLimit = LIMIT;
- static int GAP = 0;
-
- /**
- * the operating system limit for the number of characters
- * that the text field in an instance of this class can hold
- *
- * @since 3.4
- */
- public static final int LIMIT;
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0x7FFFFFFF;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#READ_ONLY
- * @see SWT#WRAP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Spinner (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-boolean acceptsFirstResponder(int /*long*/ id, int /*long*/ sel) {
- if (id == view.id) return false;
- return super.acceptsFirstResponder (id, sel);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is not called for texts.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- */
-void addVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-
-static int checkStyle (int style) {
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- float /*double*/ width = 0, height = 0;
- String string = Double.toString (buttonView.maxValue ());
- Font font = Font.cocoa_new(display, textView.font ());
- NSAttributedString str = parent.createString(string, font, null, 0, true, false);
- NSSize size = str.size ();
- str.release ();
- width = (float)/*64*/size.width;
- height = (float)/*64*/size.height;
- NSRect frameRect = textView.frame();
- NSCell cell = new NSCell (textView.cell ());
- NSRect cellRect = cell.drawingRectForBounds(frameRect);
- width += frameRect.width - cellRect.width;
- height += frameRect.height - cellRect.height;
- width += GAP;
- size = buttonView.cell ().cellSize ();
- width += (int)/*64*/size.width;
- height = Math.max (height, size.height);
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- Rectangle trim = computeTrim (0, 0, (int)Math.ceil (width), (int)Math.ceil (height));
- return new Point (trim.width, trim.height);
-}
-
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void copy () {
- checkWidget ();
- NSText fieldEditor = textView.currentEditor();
- if (fieldEditor != null) {
- fieldEditor.copy(null);
- } else {
- //TODO
- }
-}
-
-void createHandle () {
- NSView widget = (NSView)new SWTView().alloc();
- widget.init();
-// widget.setDrawsBackground(false);
- NSStepper buttonWidget = (NSStepper)new SWTStepper().alloc();
- buttonWidget.init();
- buttonWidget.setValueWraps((style & SWT.WRAP) != 0);
- buttonWidget.setTarget(buttonWidget);
- buttonWidget.setAction(OS.sel_sendSelection);
- buttonWidget.setMaxValue(100);
- NSTextField textWidget = (NSTextField)new SWTTextField().alloc();
- textWidget.init();
-// textWidget.setTarget(widget);
- textWidget.setEditable((style & SWT.READ_ONLY) == 0);
- textFormatter = (NSNumberFormatter)new NSNumberFormatter().alloc();
- textFormatter.init();
- widget.addSubview(textWidget);
- widget.addSubview(buttonWidget);
- buttonView = buttonWidget;
- textView = textWidget;
- view = widget;
- setSelection (0, false, true, false);
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void cut () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- NSText fieldEditor = textView.currentEditor();
- if (fieldEditor != null) {
- fieldEditor.cut(null);
- } else {
- //TODO
- }
-}
-
-void enableWidget (boolean enabled) {
- super.enableWidget(enabled);
- buttonView.setEnabled(enabled);
- textView.setEnabled(enabled);
-}
-
-NSFont defaultNSFont () {
- return display.textFieldFont;
-}
-
-void deregister () {
- super.deregister ();
- if (textView != null) {
- display.removeWidget (textView);
- display.removeWidget (textView.cell());
- }
-
- if (buttonView != null) {
- display.removeWidget (buttonView);
- display.removeWidget (buttonView.cell());
- }
-}
-
-NSView focusView () {
- return textView;
-}
-
-/**
- * Returns the number of decimal places used by the receiver.
- *
- * @return the digits
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getDigits () {
- checkWidget ();
- return digits;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down arrows are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget ();
- return (int)buttonView.increment();
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget ();
- return (int)buttonView.maxValue();
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget ();
- return (int)buttonView.minValue();
-}
-
-/**
- * Returns the amount that the receiver's position will be
- * modified by when the page up/down keys are pressed.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget ();
- return pageIncrement;
-}
-
-/**
- * Returns the <em>selection</em>, which is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget ();
- return (int)((NSStepper)buttonView).doubleValue();
-}
-
-int getSelectionText (boolean[] parseFail) {
- String string = textView.stringValue().getString();
- try {
- int value;
- if (digits > 0) {
- String decimalSeparator = textFormatter.decimalSeparator().getString();
- int index = string.indexOf (decimalSeparator);
- if (index != -1) {
- int startIndex = string.startsWith ("+") || string.startsWith ("-") ? 1 : 0;
- String wholePart = startIndex != index ? string.substring (startIndex, index) : "0";
- String decimalPart = string.substring (index + 1);
- if (decimalPart.length () > digits) {
- decimalPart = decimalPart.substring (0, digits);
- } else {
- int i = digits - decimalPart.length ();
- for (int j = 0; j < i; j++) {
- decimalPart = decimalPart + "0";
- }
- }
- int wholeValue = Integer.parseInt (wholePart);
- int decimalValue = Integer.parseInt (decimalPart);
- for (int i = 0; i < digits; i++) wholeValue *= 10;
- value = wholeValue + decimalValue;
- if (string.startsWith ("-")) value = -value;
- } else {
- value = Integer.parseInt (string);
- for (int i = 0; i < digits; i++) value *= 10;
- }
- } else {
- value = Integer.parseInt (string);
- }
- int max = getMaximum();
- int min = getMinimum();
- if (min <= value && value <= max) return value;
- } catch (NumberFormatException e) {
- }
- parseFail [0] = true;
- return -1;
-}
-
-/**
- * Returns a string containing a copy of the contents of the
- * receiver's text field, or an empty string if there are no
- * contents.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public String getText () {
- checkWidget ();
- NSString str = new NSTextFieldCell (textView.cell ()).title ();
- return str.getString ();
-}
-
-/**
- * Returns the maximum number of characters that the receiver's
- * text field is capable of holding. If this has not been changed
- * by <code>setTextLimit()</code>, it will be the constant
- * <code>Spinner.LIMIT</code>.
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- *
- * @since 3.4
- */
-public int getTextLimit () {
- checkWidget();
- return textLimit;
-}
-
-boolean isEventView (int /*long*/ id) {
- return true;
-}
-
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void paste () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- NSText fieldEditor = textView.currentEditor();
- if (fieldEditor != null) {
- fieldEditor.paste(null);
- } else {
- //TODO
- }
-}
-
-void register () {
- super.register ();
- if (textView != null) {
- display.addWidget (textView, this);
- display.addWidget (textView.cell(), this);
- }
-
- if (buttonView != null) {
- display.addWidget (buttonView, this);
- display.addWidget (buttonView.cell(), this);
- }
-}
-
-void releaseHandle () {
- super.releaseHandle();
- if (textFormatter != null) textFormatter.release();
- if (buttonView != null) buttonView.release();
- if (textView != null) textView.release();
- textFormatter = null;
- buttonView = null;
- textView = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (textView != null) textView.abortEditing();
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- */
-void removeVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-
-void resized () {
- super.resized ();
- buttonView.sizeToFit();
- NSSize textSize = textView.cell ().cellSize ();
- NSRect buttonFrame = buttonView.bounds();
- NSRect frame = view.frame();
- buttonFrame.x = frame.width - buttonFrame.width;
- buttonFrame.y = (frame.height - buttonFrame.height) / 2;
- int textHeight = (int)Math.min(textSize.height, frame.height);
- frame.x = 0;
- frame.y = (frame.height - textHeight) / 2;
- frame.width -= buttonFrame.width + GAP;
- frame.height = textHeight;
- textView.setFrame(frame);
- buttonView.setFrame(buttonFrame);
-}
-
-boolean sendKeyEvent (NSEvent nsEvent, int type) {
- boolean result = super.sendKeyEvent (nsEvent, type);
- if (!result) return result;
- if (type != SWT.KeyDown) return result;
- int delta = 0;
- short keyCode = nsEvent.keyCode ();
- switch (keyCode) {
- case 76: /* KP Enter */
- case 36: { /* Return */
- postEvent (SWT.DefaultSelection);
- return true;
- }
-
- case 116: delta = pageIncrement; break; /* Page Up */
- case 121: delta = -pageIncrement; break; /* Page Down */
- case 125: delta = -getIncrement(); break; /* Down arrow */
- case 126: delta = getIncrement(); break; /* Up arrow */
- }
-
- if (delta != 0) {
- boolean [] parseFail = new boolean [1];
- int value = getSelectionText (parseFail);
- if (parseFail [0]) {
- value = (int)buttonView.doubleValue();
- }
- int newValue = value + delta;
- int max = (int)buttonView.maxValue();
- int min = (int)buttonView.minValue();
- if ((style & SWT.WRAP) != 0) {
- if (newValue > max) newValue = min;
- if (newValue < min) newValue = max;
- }
- newValue = Math.min (Math.max (min, newValue), max);
- if (value != newValue) setSelection (newValue, true, true, true);
- // Prevent the arrow or page up/down from being handled by the text field.
- result = false;
- } else {
- boolean [] parseFail = new boolean [1];
- int value = getSelectionText (parseFail);
- if (!parseFail [0]) {
- int pos = (int)buttonView.doubleValue();
- if (pos != value) setSelection (value, true, false, true);
- }
- }
-
- return result;
-}
-
-void sendSelection () {
- setSelection (getSelection(), false, true, true);
-}
-
-void updateBackground () {
- NSColor nsColor = null;
- if (backgroundImage != null) {
- nsColor = NSColor.colorWithPatternImage(backgroundImage.handle);
- } else if (background != null) {
- nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]);
- } else {
- nsColor = NSColor.textBackgroundColor ();
- }
- ((NSTextField) textView).setBackgroundColor (nsColor);
-}
-
-/**
- * Sets the number of decimal places used by the receiver.
- * <p>
- * The digit setting is used to allow for floating point values in the receiver.
- * For example, to set the selection to a floating point value of 1.37 call setDigits() with
- * a value of 2 and setSelection() with a value of 137. Similarly, if getDigits() has a value
- * of 2 and getSelection() returns 137 this should be interpreted as 1.37. This applies to all
- * numeric APIs.
- * </p>
- *
- * @param value the new digits (must be greater than or equal to zero)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the value is less than zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDigits (int value) {
- checkWidget ();
- if (value < 0) error (SWT.ERROR_INVALID_ARGUMENT);
- if (value == digits) return;
- digits = value;
- int pos = (int)buttonView.doubleValue();
- setSelection (pos, false, true, false);
-}
-
-void setFont(NSFont font) {
- textView.setFont(font);
-}
-
-void setForeground (float /*double*/ [] color) {
- NSColor nsColor;
- if (color == null) {
- nsColor = NSColor.textColor ();
- } else {
- nsColor = NSColor.colorWithDeviceRed (color [0], color [1], color [2], 1);
- }
- ((NSTextField) textView).setTextColor (nsColor);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down arrows are pressed to
- * the argument, which must be at least one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- buttonView.setIncrement(value);
-}
-
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget ();
- int min = getMinimum ();
- if (value <= min) return;
- int pos = getSelection();
- buttonView.setMaxValue(value);
- if (pos > value) setSelection (value, true, true, false);
-}
-
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget ();
- int max = getMaximum();
- if (value >= max) return;
- int pos = getSelection();
- buttonView.setMinValue(value);
- if (pos < value) setSelection (value, true, true, false);
-}
-
-/**
- * Sets the amount that the receiver's position will be
- * modified by when the page up/down keys are pressed
- * to the argument, which must be at least one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- pageIncrement = value;
-}
-
-/**
- * Sets the <em>selection</em>, which is the receiver's
- * position, to the argument. If the argument is not within
- * the range specified by minimum and maximum, it will be
- * adjusted to fall within this range.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget ();
- int min = getMinimum();
- int max = getMaximum();
- value = Math.min (Math.max (min, value), max);
- setSelection (value, true, true, false);
-}
-
-void setSelection (int value, boolean setPos, boolean setText, boolean notify) {
- if (setPos) {
- ((NSStepper)buttonView).setDoubleValue(value);
- }
- if (setText) {
- String string = String.valueOf (value);
- if (digits > 0) {
- String decimalSeparator = textFormatter.decimalSeparator().getString();
- int index = string.length () - digits;
- StringBuffer buffer = new StringBuffer ();
- if (index > 0) {
- buffer.append (string.substring (0, index));
- buffer.append (decimalSeparator);
- buffer.append (string.substring (index));
- } else {
- buffer.append ("0");
- buffer.append (decimalSeparator);
- while (index++ < 0) buffer.append ("0");
- buffer.append (string);
- }
- string = buffer.toString ();
- }
- NSCell cell = new NSCell(textView.cell());
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- int length = (int)/*64*/cell.title().length();
- string = verifyText (string, 0, length, null);
- if (string == null) return;
- }
- textView.setStringValue(NSString.stringWith(string));
- NSRange selection = new NSRange();
- selection.location = 0;
- selection.length = string.length();
- NSText fieldEditor = textView.currentEditor();
- if (fieldEditor != null) fieldEditor.setSelectedRange(selection);
- sendEvent (SWT.Modify);
- }
- if (notify) postEvent (SWT.Selection);
-}
-
-void setSmallSize () {
- textView.cell ().setControlSize (OS.NSSmallControlSize);
- buttonView.cell ().setControlSize (OS.NSSmallControlSize);
-}
-
-/**
- * Sets the maximum number of characters that the receiver's
- * text field is capable of holding to be the argument.
- * <p>
- * To reset this value to the default, use <code>setTextLimit(Spinner.LIMIT)</code>.
- * Specifying a limit value larger than <code>Spinner.LIMIT</code> sets the
- * receiver's limit to <code>Spinner.LIMIT</code>.
- * </p>
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- *
- * @since 3.4
- */
-public void setTextLimit (int limit) {
- checkWidget();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- textLimit = limit;
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, digits, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param digits the new digits value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setValues (int selection, int minimum, int maximum, int digits, int increment, int pageIncrement) {
- checkWidget ();
- if (maximum <= minimum) return;
- if (digits < 0) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- selection = Math.min (Math.max (minimum, selection), maximum);
- this.pageIncrement = pageIncrement;
- this.digits = digits;
- buttonView.setIncrement(increment);
- buttonView.setMaxValue(maximum);
- buttonView.setMinValue(minimum);
- setSelection (selection, true, true, false);
-}
-
-boolean shouldChangeTextInRange_replacementString(int /*long*/ id, int /*long*/ sel, int /*long*/ affectedCharRange, int /*long*/ replacementString) {
- NSRange range = new NSRange();
- OS.memmove(range, affectedCharRange, NSRange.sizeof);
- boolean result = callSuperBoolean(id, sel, range, replacementString);
- if (hooks (SWT.Verify)) {
- String text = new NSString(replacementString).getString();
- NSEvent currentEvent = display.application.currentEvent();
- int /*long*/ type = currentEvent.type();
- if (type != OS.NSKeyDown && type != OS.NSKeyUp) currentEvent = null;
- String newText = verifyText(text, (int)/*64*/range.location, (int)/*64*/(range.location+range.length), currentEvent);
- if (newText == null) return false;
- if (text != newText) {
- int length = newText.length();
- NSText fieldEditor = textView.currentEditor ();
- if (fieldEditor != null) {
- NSRange selectedRange = fieldEditor.selectedRange();
- if (textLimit != LIMIT) {
- int /*long*/ charCount = fieldEditor.string().length();
- if (charCount - selectedRange.length + length > textLimit) {
- length = (int)/*64*/(textLimit - charCount + selectedRange.length);
- }
- }
- char [] buffer = new char [length];
- newText.getChars (0, buffer.length, buffer, 0);
- NSString nsstring = NSString.stringWithCharacters (buffer, buffer.length);
- fieldEditor.replaceCharactersInRange (fieldEditor.selectedRange (), nsstring);
- result = false;
- }
- }
- if (!result) sendEvent (SWT.Modify);
- }
- return result;
-}
-
-void textDidChange (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
- super.textDidChange (id, sel, aNotification);
- boolean [] parseFail = new boolean [1];
- int value = getSelectionText (parseFail);
- if (!parseFail [0]) {
- int pos = (int)buttonView.doubleValue();
- if (value != pos) {
- setSelection (value, true, false, true);
- }
- }
- postEvent (SWT.Modify);
-}
-
-NSRange textView_willChangeSelectionFromCharacterRange_toCharacterRange (int /*long*/ id, int /*long*/ sel, int /*long*/ aTextView, int /*long*/ oldSelectedCharRange, int /*long*/ newSelectedCharRange) {
- /* allow the selection change to proceed */
- NSRange result = new NSRange ();
- OS.memmove(result, newSelectedCharRange, NSRange.sizeof);
- return result;
-}
-
-void textDidEndEditing(int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
- boolean [] parseFail = new boolean [1];
- int value = getSelectionText (parseFail);
- if (parseFail [0]) {
- value = (int)buttonView.doubleValue();
- setSelection (value, false, true, false);
- }
- super.textDidEndEditing(id, sel, aNotification);
-}
-
-void updateCursorRects (boolean enabled) {
- super.updateCursorRects (enabled);
- updateCursorRects (enabled, textView);
- updateCursorRects (enabled, buttonView);
-}
-
-String verifyText (String string, int start, int end, NSEvent keyEvent) {
- Event event = new Event ();
- if (keyEvent != null) setKeyState(event, SWT.MouseDown, keyEvent);
- event.text = string;
- event.start = start;
- event.end = end;
- int index = 0;
- if (digits > 0) {
- String decimalSeparator = ".";//getDecimalSeparator ();
- index = string.indexOf (decimalSeparator);
- if (index != -1) {
- string = string.substring (0, index) + string.substring (index + 1);
- }
- index = 0;
- }
- while (index < string.length ()) {
- if (!Character.isDigit (string.charAt (index))) break;
- index++;
- }
- event.doit = index == string.length ();
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the verify
- * event. If this happens, answer null to cancel
- * the operation.
- */
- sendEvent (SWT.Verify, event);
- if (!event.doit || isDisposed ()) return null;
- return event.text;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TabFolder.java
deleted file mode 100755
index 095bb05eda..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TabFolder.java
+++ /dev/null
@@ -1,652 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.cocoa.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class implement the notebook user interface
- * metaphor. It allows the user to select a notebook page from
- * set of pages.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TabItem</code>.
- * <code>Control</code> children are created and then set into a
- * tab item using <code>TabItem#setControl</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>TOP, BOTTOM</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles TOP and BOTTOM may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tabfolder">TabFolder, TabItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TabFolder extends Composite {
- TabItem [] items;
- int itemCount;
- boolean ignoreSelect;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see SWT#TOP
- * @see SWT#BOTTOM
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabFolder (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- style = checkBits (style, SWT.TOP, SWT.BOTTOM, 0, 0, 0, 0);
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- Point size = super.computeSize (wHint, hHint, changed);
- if (wHint == SWT.DEFAULT && items.length > 0) {
- NSSize minSize = ((NSTabView)view).minimumSize();
- Rectangle trim = computeTrim (0, 0, (int)Math.ceil (minSize.width), 0);
- size.x = Math.max (trim.width, size.x);
- }
- return size;
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
- NSTabView widget = (NSTabView)view;
- NSRect rect = widget.contentRect ();
- x -= rect.x;
- y -= rect.y;
- NSRect frame = widget.frame();
- width += Math.ceil (frame.width - rect.width);
- height += Math.ceil (frame.height - rect.height);
- return super.computeTrim (x, y, width, height);
-}
-
-void createHandle () {
- NSTabView widget = (NSTabView)new SWTTabView().alloc();
- widget.init ();
- widget.setDelegate(widget);
- if ((style & SWT.BOTTOM) != 0) {
- widget.setTabViewType(OS.NSBottomTabsBezelBorder);
- }
- view = widget;
-}
-
-void createItem (TabItem item, int index) {
- int count = itemCount;
- if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
- if (count == items.length) {
- TabItem [] newItems = new TabItem [items.length + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- System.arraycopy (items, index, items, index + 1, count - index);
- items [index] = item;
- itemCount++;
- NSTabViewItem nsItem = (NSTabViewItem)new NSTabViewItem().alloc().init();
- item.nsItem = nsItem;
- ((NSTabView)view).insertTabViewItem(nsItem, index);
-}
-
-void createWidget () {
- super.createWidget ();
- items = new TabItem [4];
-}
-
-NSFont defaultNSFont () {
- return display.tabViewFont;
-}
-
-void destroyItem (TabItem item) {
- int count = itemCount;
- int index = 0;
- while (index < count) {
- if (items [index] == item) break;
- index++;
- }
- if (index == count) return;
- --count;
- System.arraycopy (items, index + 1, items, index, count - index);
- items [count] = null;
- if (count == 0) {
- items = new TabItem [4];
- }
- itemCount = count;
- ((NSTabView)view).removeTabViewItem(item.nsItem);
-}
-
-Widget findTooltip (NSPoint pt) {
- pt = view.convertPoint_fromView_ (pt, null);
- NSTabViewItem nsItem = ((NSTabView)view).tabViewItemAtPoint (pt);
- if (nsItem != null) {
- for (int i = 0; i < itemCount; i++) {
- TabItem item = items [i];
- if (item.nsItem.id == nsItem.id) return item;
- }
- }
- return super.findTooltip (pt);
-}
-
-public Rectangle getClientArea () {
- checkWidget ();
- NSRect rect = ((NSTabView)view).contentRect();
- int x = Math.max (0, (int)rect.x);
- int y = Math.max (0, (int)rect.y);
- int width = Math.max (0, (int)Math.ceil (rect.width));
- int height = Math.max (0, (int)Math.ceil (rect.height));
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem getItem (int index) {
- checkWidget ();
- int count = itemCount;
- if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-
-/**
- * Returns the tab item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- *
- * @param point the point used to locate the item
- * @return the tab item at the given point, or null if the point is not in a tab item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public TabItem getItem (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- NSPoint nsPoint = new NSPoint ();
- nsPoint.x = point.x;
- nsPoint.y = point.y;
- NSTabView tabView = (NSTabView) view;
- NSTabViewItem tabViewItem = tabView.tabViewItemAtPoint (nsPoint);
- for (int i = 0; i < itemCount; i++) {
- NSTabViewItem item = items[i].nsItem;
- if (item.isEqual (tabViewItem)) {
- return items [i];
- }
- }
- return null;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return itemCount;
-}
-
-/**
- * Returns an array of <code>TabItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem [] getItems () {
- checkWidget ();
- int count = itemCount;
- TabItem [] result = new TabItem [count];
- System.arraycopy (items, 0, result, 0, count);
- return result;
-}
-
-/**
- * Returns an array of <code>TabItem</code>s that are currently
- * selected in the receiver. An empty array indicates that no
- * items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem [] getSelection () {
- checkWidget ();
- int index = getSelectionIndex ();
- if (index == -1) return new TabItem [0];
- return new TabItem [] {items [index]};
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget ();
- NSTabViewItem selected = ((NSTabView)view).selectedTabViewItem();
- if (selected == null) return -1;
- for (int i = 0; i < itemCount; i++) {
- if (items[i].nsItem.id == selected.id) return i;
- }
- return -1;
-}
-
-float getThemeAlpha () {
- return (background != null ? 1 : 0.25f) * parent.getThemeAlpha ();
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (TabItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = itemCount;
- for (int i=0; i<count; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-
-Point minimumSize (int wHint, int hHint, boolean flushCache) {
- Control [] children = _getChildren ();
- int width = 0, height = 0;
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- int index = 0;
- int count = itemCount;
- while (index < count) {
- if (items [index].control == child) break;
- index++;
- }
- if (index == count) {
- Rectangle rect = child.getBounds ();
- width = Math.max (width, rect.x + rect.width);
- height = Math.max (height, rect.y + rect.height);
- } else {
- Point size = child.computeSize (wHint, hHint, flushCache);
- width = Math.max (width, size.x);
- height = Math.max (height, size.y);
- }
- }
- return new Point (width, height);
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<items.length; i++) {
- TabItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- }
- super.releaseChildren (destroy);
-}
-
-void removeControl (Control control) {
- super.removeControl (control);
- int count = itemCount;
- for (int i=0; i<count; i++) {
- TabItem item = items [i];
- if (item.control == control) item.setControl (null);
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-void setFont (NSFont font) {
- ((NSTabView)view).setFont(font);
-}
-
-/**
- * Sets the receiver's selection to the given item.
- * The current selected is first cleared, then the new item is
- * selected.
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection (TabItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (new TabItem [] {item});
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selected is first cleared, then the new items are
- * selected.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (TabItem [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (items.length == 0) {
- setSelection (-1, false, false);
- } else {
- for (int i=items.length - 1; i>=0; --i) {
- int index = indexOf (items [i]);
- if (index != -1) setSelection (index, false, false);
- }
- }
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains selected.
- * The current selection is first cleared, then the new items are
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int index) {
- checkWidget ();
- int count = itemCount;
- if (!(0 <= index && index < count)) return;
- setSelection (index, false, false);
-}
-
-void setSelection (int index, boolean notify, boolean force) {
- if (!(0 <= index && index < itemCount)) return;
- int currentIndex = getSelectionIndex ();
- if (!force && currentIndex == index) return;
- if (currentIndex != -1) {
- TabItem item = items [currentIndex];
- if (item != null) {
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setVisible (false);
- }
- }
- }
- ignoreSelect = true;
- ((NSTabView)view).selectTabViewItemAtIndex(index);
- ignoreSelect = false;
- index = getSelectionIndex();
- if (index != -1) {
- TabItem item = items [index];
- if (item != null) {
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setVisible (true);
- }
- if (notify) {
- Event event = new Event ();
- event.item = item;
- sendEvent (SWT.Selection, event);
- }
- }
- }
-}
-
-void setSmallSize () {
- ((NSTabView)view).setControlSize (OS.NSSmallControlSize);
-}
-
-boolean traversePage (boolean next) {
- int count = getItemCount ();
- if (count == 0) return false;
- int index = getSelectionIndex ();
- if (index == -1) {
- index = 0;
- } else {
- int offset = (next) ? 1 : -1;
- index = (index + offset + count) % count;
- }
- setSelection (index, true, false);
- return index == getSelectionIndex ();
-}
-
-void tabView_willSelectTabViewItem(int /*long*/ id, int /*long*/ sel, int /*long*/ tabView, int /*long*/ tabViewItem) {
- if (tabViewItem == 0) return;
- for (int i = 0; i < itemCount; i++) {
- TabItem item = items [i];
- if (item.nsItem.id == tabViewItem) {
- int currentIndex = getSelectionIndex ();
- if (currentIndex != -1) {
- TabItem selected = items [currentIndex];
- if (selected != null) {
- Control control = selected.control;
- if (control != null && !control.isDisposed ()) {
- control.setVisible (false);
- }
- }
- }
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setVisible (true);
- }
- break;
- }
- }
-}
-
-void tabView_didSelectTabViewItem(int /*long*/ id, int /*long*/ sel, int /*long*/ tabView, int /*long*/ tabViewItem) {
- if (tabViewItem == 0) return;
- for (int i = 0; i < itemCount; i++) {
- TabItem item = items [i];
- /*
- * Feature in Cocoa. For some reason the control on a tab being
- * deselected has its parent removed natively. The fix is to
- * re-set the control's parent.
- */
- Control control = item.control;
- if (control != null) {
- NSView topView = control.topView ();
- if (topView.superview () == null) {
- contentView ().addSubview (topView, OS.NSWindowBelow, null);
- }
- }
- if (item.nsItem.id == tabViewItem) {
- if (!ignoreSelect) {
- Event event = new Event ();
- event.item = item;
- postEvent (SWT.Selection, event);
- }
- }
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TabItem.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TabItem.java
deleted file mode 100755
index dcbca3e71f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TabItem.java
+++ /dev/null
@@ -1,373 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * corresponding to a tab for a page in a tab folder.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tabfolder">TabFolder, TabItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TabItem extends Item {
- TabFolder parent;
- Control control;
- String toolTipText;
- NSTabViewItem nsItem;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>TabFolder</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabItem (TabFolder parent, int style) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>TabFolder</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabItem (TabFolder parent, int style, int index) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public Rectangle getBounds() {
- checkWidget();
- Rectangle result = new Rectangle (0, 0, 0, 0);
- if (nsItem.respondsToSelector (OS.sel_accessibilityAttributeValue_)) {
- int /*long*/ posValue = OS.objc_msgSend (nsItem.id, OS.sel_accessibilityAttributeValue_, OS.NSAccessibilityPositionAttribute ());
- int /*long*/ sizeValue = OS.objc_msgSend (nsItem.id, OS.sel_accessibilityAttributeValue_, OS.NSAccessibilitySizeAttribute ());
- NSValue val = new NSValue (posValue);
- NSPoint pt = val.pointValue ();
- NSWindow window = parent.view.window ();
- pt.y = display.getPrimaryFrame().height - pt.y;
- pt = parent.view.convertPoint_fromView_ (pt, null);
- pt = window.convertScreenToBase (pt);
- result.x = (int) pt.x;
- result.y = (int) pt.y;
- val = new NSValue (sizeValue);
- NSSize size = val.sizeValue ();
- result.width = (int) Math.ceil (size.width);
- result.height = (int) Math.ceil (size.height);
- }
- return result;
-}
-
-/**
- * Returns the control that is used to fill the client area of
- * the tab folder when the user selects the tab item. If no
- * control has been set, return <code>null</code>.
- * <p>
- * @return the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget ();
- return control;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>TabFolder</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabFolder getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (nsItem != null) nsItem.release();
- nsItem = null;
- parent = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- int index = parent.indexOf (this);
- if (index == parent.getSelectionIndex ()) {
- if (control != null) control.setVisible (false);
- }
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- control = null;
-}
-
-/**
- * Sets the control that is used to fill the client area of
- * the tab folder when the user selects the tab item.
- * <p>
- * @param control the new control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget ();
- if (control != null) {
- if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- if (this.control != null && this.control.isDisposed ()) {
- this.control = null;
- }
- Control oldControl = this.control, newControl = control;
- this.control = control;
- int index = parent.indexOf (this), selectionIndex = parent.getSelectionIndex();;
- if (index != selectionIndex) {
- if (newControl != null) {
- boolean hideControl = true;
- if (selectionIndex != -1) {
- Control selectedControl = parent.getItem(selectionIndex).getControl();
- if (selectedControl == newControl) hideControl=false;
- }
- if (hideControl) newControl.setVisible(false);
- }
- } else {
- if (newControl != null) {
- newControl.setVisible (true);
- }
- if (oldControl != null) oldControl.setVisible (false);
- }
- NSView view;
- if (newControl != null) {
- view = newControl.topView();
- } else {
- view = (NSView)new NSView().alloc();
- view.init ();
- view.autorelease();
- }
- nsItem.setView (view);
- /*
- * Feature in Cocoa. The method setView() removes the old view from
- * its parent. The fix is to detected it has been removed and add
- * it back.
- */
- if (oldControl != null) {
- NSView topView = oldControl.topView ();
- if (topView.superview () == null) {
- parent.contentView ().addSubview (topView, OS.NSWindowBelow, null);
- }
- }
-}
-
-public void setImage (Image image) {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) return;
- super.setImage (image);
-}
-
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = parent.indexOf (this);
- if (index == -1) return;
- super.setText (string);
- char [] chars = new char [string.length ()];
- string.getChars (0, chars.length, chars, 0);
- int length = fixMnemonic (chars);
- NSString str = NSString.stringWithCharacters (chars, length);
- nsItem.setLabel (str);
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
- parent.checkToolTip (this);
-}
-
-String tooltipText () {
- return toolTipText;
-}
-
-void update () {
- setText (text);
- setImage (image);
- setToolTipText (toolTipText);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java
deleted file mode 100755
index 6eb9b700ac..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java
+++ /dev/null
@@ -1,3087 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.accessibility.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class implement a selectable user interface
- * object that displays a list of images and strings and issues
- * notification when selected.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TableItem</code>.
- * </p><p>
- * Style <code>VIRTUAL</code> is used to create a <code>Table</code> whose
- * <code>TableItem</code>s are to be populated by the client on an on-demand basis
- * instead of up-front. This can provide significant performance improvements for
- * tables that are very large or for which <code>TableItem</code> population is
- * expensive (for example, retrieving values from an external source).
- * </p><p>
- * Here is an example of using a <code>Table</code> with style <code>VIRTUAL</code>:
- * <code><pre>
- * final Table table = new Table (parent, SWT.VIRTUAL | SWT.BORDER);
- * table.setItemCount (1000000);
- * table.addListener (SWT.SetData, new Listener () {
- * public void handleEvent (Event event) {
- * TableItem item = (TableItem) event.item;
- * int index = table.indexOf (item);
- * item.setText ("Item " + index);
- * System.out.println (item.getText ());
- * }
- * });
- * </pre></code>
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not normally make sense to add <code>Control</code> children to
- * it, or set a layout on it, unless implementing something like a cell
- * editor.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, HIDE_SELECTION, VIRTUAL, NO_SCROLL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection, SetData, MeasureItem, EraseItem, PaintItem</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles SINGLE, and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Table extends Composite {
- TableItem [] items;
- TableColumn [] columns;
- TableColumn sortColumn;
- TableItem currentItem;
- NSTableHeaderView headerView;
- NSTableColumn firstColumn, checkColumn;
- NSTextFieldCell dataCell;
- NSButtonCell buttonCell;
- int columnCount, itemCount, lastIndexOf, sortDirection;
- boolean ignoreSelect, fixScrollWidth, drawExpansion;
- Rectangle imageBounds;
-
- static int NEXT_ID;
-
- static final int FIRST_COLUMN_MINIMUM_WIDTH = 5;
- static final int IMAGE_GAP = 3;
- static final int TEXT_GAP = 2;
- static final int CELL_GAP = 1;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#CHECK
- * @see SWT#FULL_SELECTION
- * @see SWT#HIDE_SELECTION
- * @see SWT#VIRTUAL
- * @see SWT#NO_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Table (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-int /*long*/ accessibilityAttributeValue (int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
-
- if (accessible != null) {
- NSString attribute = new NSString(arg0);
- id returnValue = accessible.internal_accessibilityAttributeValue(attribute, ACC.CHILDID_SELF);
- if (returnValue != null) return returnValue.id;
- }
-
- NSString attributeName = new NSString(arg0);
-
- // Accessibility Verifier queries for a title or description. NSTableView doesn't
- // seem to return either, so we return a default description value here.
- if (attributeName.isEqualToString (OS.NSAccessibilityDescriptionAttribute)) {
- return NSString.stringWith("").id;
- }
-
- return super.accessibilityAttributeValue(id, sel, arg0);
-}
-
-void _addListener (int eventType, Listener listener) {
- super._addListener (eventType, listener);
- clearCachedWidth(items);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * If the receiver has the <code>SWT.CHECK</code> style and the check selection changes,
- * the event object detail field contains the value <code>SWT.CHECK</code>.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * The item field of the event object is valid for default selection, but the detail field is not used.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-TableItem _getItem (int index) {
- if ((style & SWT.VIRTUAL) == 0) return items [index];
- if (items [index] != null) return items [index];
- return items [index] = new TableItem (this, SWT.NULL, -1, false);
-}
-
-int calculateWidth (TableItem[] items, int index, GC gc) {
- int width = 0;
- for (int i=0; i < itemCount; i++) {
- TableItem item = items [i];
- if (item != null && item.cached) {
- width = Math.max (width, item.calculateWidth (index, gc));
- }
- }
- return width;
-}
-
-NSSize cellSize (int /*long*/ id, int /*long*/ sel) {
- NSSize size = super.cellSize(id, sel);
- NSImage image = new NSCell(id).image();
- if (image != null) size.width += imageBounds.width + IMAGE_GAP;
- if (hooks(SWT.MeasureItem)) {
- int /*long*/ [] outValue = new int /*long*/ [1];
- OS.object_getInstanceVariable(id, Display.SWT_ROW, outValue);
- int /*long*/ rowIndex = outValue [0];
- TableItem item = _getItem((int)/*64*/rowIndex);
- OS.object_getInstanceVariable(id, Display.SWT_COLUMN, outValue);
- int /*long*/ tableColumn = outValue[0];
- int columnIndex = 0;
- for (int i=0; i<columnCount; i++) {
- if (columns [i].nsColumn.id == tableColumn) {
- columnIndex = i;
- break;
- }
- }
- sendMeasureItem (item, columnIndex, size);
- }
- return size;
-}
-
-boolean canDragRowsWithIndexes_atPoint(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1) {
- NSPoint clickPoint = new NSPoint();
- OS.memmove(clickPoint, arg1, NSPoint.sizeof);
- NSTableView table = (NSTableView)view;
-
- // If the current row is not selected and the user is not attempting to modify the selection, select the row first.
- int /*long*/ row = table.rowAtPoint(clickPoint);
- int /*long*/ modifiers = NSApplication.sharedApplication().currentEvent().modifierFlags();
-
- boolean drag = (state & DRAG_DETECT) != 0 && hooks (SWT.DragDetect);
- if (drag) {
- if (!table.isRowSelected(row) && (modifiers & (OS.NSCommandKeyMask | OS.NSShiftKeyMask | OS.NSAlternateKeyMask)) == 0) {
- NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc();
- set = set.initWithIndex(row);
- table.selectRowIndexes (set, false);
- set.release();
- }
- }
-
- // The clicked row must be selected to initiate a drag.
- return (table.isRowSelected(row) && drag);
-}
-
-boolean checkData (TableItem item) {
- return checkData (item, indexOf (item));
-}
-
-boolean checkData (TableItem item, int index) {
- if (item.cached) return true;
- if ((style & SWT.VIRTUAL) != 0) {
- item.cached = true;
- Event event = new Event ();
- event.item = item;
- event.index = indexOf (item);
- currentItem = item;
- sendEvent (SWT.SetData, event);
- //widget could be disposed at this point
- currentItem = null;
- if (isDisposed () || item.isDisposed ()) return false;
- if (!setScrollWidth (item)) item.redraw (-1);
- }
- return true;
-}
-
-static int checkStyle (int style) {
- /*
- * Feature in Windows. Even when WS_HSCROLL or
- * WS_VSCROLL is not specified, Windows creates
- * trees and tables with scroll bars. The fix
- * is to set H_SCROLL and V_SCROLL.
- *
- * NOTE: This code appears on all platforms so that
- * applications have consistent scroll bar behavior.
- */
- if ((style & SWT.NO_SCROLL) == 0) {
- style |= SWT.H_SCROLL | SWT.V_SCROLL;
- }
- /* This platform is always FULL_SELECTION */
- style |= SWT.FULL_SELECTION;
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Clears the item at the given zero-relative index in the receiver.
- * The text, icon and other attributes of the item are set to the default
- * value. If the table was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param index the index of the item to clear
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clear (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- TableItem item = items [index];
- if (item != null) {
- if (currentItem != item) item.clear ();
- if (currentItem == null) item.redraw (-1);
- setScrollWidth (item);
- }
-}
-/**
- * Removes the items from the receiver which are between the given
- * zero-relative start and end indices (inclusive). The text, icon
- * and other attributes of the items are set to their default values.
- * If the table was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param start the start index of the item to clear
- * @param end the end index of the item to clear
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clear (int start, int end) {
- checkWidget ();
- if (start > end) return;
- if (!(0 <= start && start <= end && end < itemCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- if (start == 0 && end == itemCount - 1) {
- clearAll ();
- } else {
- for (int i=start; i<=end; i++) {
- clear (i);
- }
- }
-}
-
-/**
- * Clears the items at the given zero-relative indices in the receiver.
- * The text, icon and other attributes of the items are set to their default
- * values. If the table was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clear (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- for (int i=0; i<indices.length; i++) {
- if (!(0 <= indices [i] && indices [i] < itemCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- }
- for (int i=0; i<indices.length; i++) {
- clear (indices [i]);
- }
-}
-
-/**
- * Clears all the items in the receiver. The text, icon and other
- * attributes of the items are set to their default values. If the
- * table was created with the <code>SWT.VIRTUAL</code> style, these
- * attributes are requested again as needed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clearAll () {
- checkWidget ();
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (item != null) {
- item.clear ();
- }
- }
- if (currentItem == null && isDrawing ()) view.setNeedsDisplay(true);
- setScrollWidth (items, true);
-}
-
-void clearCachedWidth (TableItem[] items) {
- if (items == null) return;
- for (int i = 0; i < items.length; i++) {
- if (items [i] != null) items [i].width = -1;
- }
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0;
- if (wHint == SWT.DEFAULT) {
- if (columnCount != 0) {
- for (int i=0; i<columnCount; i++) {
- width += columns [i].getWidth ();
- }
- } else {
- GC gc = new GC (this);
- width += calculateWidth (items, 0, gc) + CELL_GAP;
- gc.dispose ();
- }
- if ((style & SWT.CHECK) != 0) width += getCheckColumnWidth ();
- } else {
- width = wHint;
- }
- if (width <= 0) width = DEFAULT_WIDTH;
- int height = 0;
- if (hHint == SWT.DEFAULT) {
- height = itemCount * getItemHeight () + getHeaderHeight();
- } else {
- height = hHint;
- }
- if (height <= 0) height = DEFAULT_HEIGHT;
- Rectangle rect = computeTrim (0, 0, width, height);
- return new Point (rect.width, rect.height);
-}
-
-void createColumn (TableItem item, int index) {
- String [] strings = item.strings;
- if (strings != null) {
- String [] temp = new String [columnCount];
- System.arraycopy (strings, 0, temp, 0, index);
- System.arraycopy (strings, index, temp, index+1, columnCount-index-1);
- temp [index] = "";
- item.strings = temp;
- }
- if (index == 0) item.text = "";
- Image [] images = item.images;
- if (images != null) {
- Image [] temp = new Image [columnCount];
- System.arraycopy (images, 0, temp, 0, index);
- System.arraycopy (images, index, temp, index+1, columnCount-index-1);
- item.images = temp;
- }
- if (index == 0) item.image = null;
- Color [] cellBackground = item.cellBackground;
- if (cellBackground != null) {
- Color [] temp = new Color [columnCount];
- System.arraycopy (cellBackground, 0, temp, 0, index);
- System.arraycopy (cellBackground, index, temp, index+1, columnCount-index-1);
- item.cellBackground = temp;
- }
- Color [] cellForeground = item.cellForeground;
- if (cellForeground != null) {
- Color [] temp = new Color [columnCount];
- System.arraycopy (cellForeground, 0, temp, 0, index);
- System.arraycopy (cellForeground, index, temp, index+1, columnCount-index-1);
- item.cellForeground = temp;
- }
- Font [] cellFont = item.cellFont;
- if (cellFont != null) {
- Font [] temp = new Font [columnCount];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index, temp, index+1, columnCount-index-1);
- item.cellFont = temp;
- }
-}
-
-void createHandle () {
- NSScrollView scrollWidget = (NSScrollView)new SWTScrollView().alloc();
- scrollWidget.init();
- scrollWidget.setHasHorizontalScroller ((style & SWT.H_SCROLL) != 0);
- scrollWidget.setHasVerticalScroller ((style & SWT.V_SCROLL) != 0);
- scrollWidget.setAutohidesScrollers(true);
- scrollWidget.setBorderType(hasBorder() ? OS.NSBezelBorder : OS.NSNoBorder);
-
- NSTableView widget = (NSTableView)new SWTTableView().alloc();
- widget.init();
- widget.setAllowsMultipleSelection((style & SWT.MULTI) != 0);
- widget.setAllowsColumnReordering (false);
- widget.setDataSource(widget);
- widget.setDelegate(widget);
- widget.setColumnAutoresizingStyle (OS.NSTableViewNoColumnAutoresizing);
- NSSize spacing = new NSSize();
- spacing.width = spacing.height = CELL_GAP;
- widget.setIntercellSpacing(spacing);
- widget.setDoubleAction(OS.sel_sendDoubleSelection);
- if (!hasBorder()) widget.setFocusRingType(OS.NSFocusRingTypeNone);
-
- headerView = (NSTableHeaderView)new SWTTableHeaderView ().alloc ().init ();
- widget.setHeaderView (null);
-
- NSString str = NSString.stringWith(""); //$NON-NLS-1$
- if ((style & SWT.CHECK) != 0) {
- checkColumn = (NSTableColumn)new NSTableColumn().alloc();
- checkColumn = checkColumn.initWithIdentifier(NSString.stringWith(String.valueOf(++NEXT_ID)));
- checkColumn.headerCell().setTitle(str);
- widget.addTableColumn (checkColumn);
- checkColumn.setResizingMask(OS.NSTableColumnNoResizing);
- checkColumn.setEditable(false);
- int /*long*/ cls = NSButton.cellClass (); /* use our custom cell class */
- buttonCell = new NSButtonCell (OS.class_createInstance (cls, 0));
- buttonCell.init ();
- checkColumn.setDataCell (buttonCell);
- buttonCell.setButtonType (OS.NSSwitchButton);
- buttonCell.setImagePosition (OS.NSImageOnly);
- buttonCell.setAllowsMixedState (true);
- checkColumn.setWidth(getCheckColumnWidth());
- }
-
- firstColumn = (NSTableColumn)new NSTableColumn().alloc();
- firstColumn = firstColumn.initWithIdentifier(NSString.stringWith(String.valueOf(++NEXT_ID)));
- /*
- * Feature in Cocoa. If a column's width is too small to show any content
- * then tableView_objectValueForTableColumn_row is never invoked to
- * query for item values, which is a problem for VIRTUAL Tables. The
- * workaround is to ensure that, for 0-column Tables, the internal first
- * column always has a minimal width that makes this call come in.
- */
- firstColumn.setMinWidth (FIRST_COLUMN_MINIMUM_WIDTH);
- firstColumn.setWidth(0);
- firstColumn.setResizingMask (OS.NSTableColumnNoResizing);
- firstColumn.headerCell ().setTitle (str);
- widget.addTableColumn (firstColumn);
- dataCell = (NSTextFieldCell)new SWTImageTextCell ().alloc ().init ();
- dataCell.setLineBreakMode(OS.NSLineBreakByClipping);
- firstColumn.setDataCell (dataCell);
-
- scrollView = scrollWidget;
- view = widget;
-}
-
-void createItem (TableColumn column, int index) {
- if (!(0 <= index && index <= columnCount)) error (SWT.ERROR_INVALID_RANGE);
- if (columnCount == columns.length) {
- TableColumn [] newColumns = new TableColumn [columnCount + 4];
- System.arraycopy (columns, 0, newColumns, 0, columns.length);
- columns = newColumns;
- }
- NSTableColumn nsColumn;
- if (columnCount == 0) {
- //TODO - clear attributes, alignment etc.
- nsColumn = firstColumn;
- nsColumn.setMinWidth (0);
- nsColumn.setResizingMask (OS.NSTableColumnUserResizingMask);
- firstColumn = null;
- } else {
- //TODO - set attributes, alignment etc.
- nsColumn = (NSTableColumn)new NSTableColumn().alloc();
- nsColumn = nsColumn.initWithIdentifier(NSString.stringWith(String.valueOf(++NEXT_ID)));
- nsColumn.setMinWidth(0);
- ((NSTableView)view).addTableColumn (nsColumn);
- int checkColumn = (style & SWT.CHECK) != 0 ? 1 : 0;
- ((NSTableView)view).moveColumn (columnCount + checkColumn, index + checkColumn);
- nsColumn.setDataCell (dataCell);
- }
- column.createJNIRef ();
- NSTableHeaderCell headerCell = (NSTableHeaderCell)new SWTTableHeaderCell ().alloc ().init ();
- nsColumn.setHeaderCell (headerCell);
- display.addWidget (headerCell, column);
- column.nsColumn = nsColumn;
- nsColumn.setWidth(0);
- System.arraycopy (columns, index, columns, index + 1, columnCount++ - index);
- columns [index] = column;
- for (int i = 0; i < itemCount; i++) {
- TableItem item = items [i];
- if (item != null) {
- if (columnCount > 1) {
- createColumn (item, index);
- }
- }
- }
-}
-
-void createItem (TableItem item, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (itemCount == items.length) {
- /* Grow the array faster when redraw is off */
- int length = getDrawing () ? items.length + 4 : Math.max (4, items.length * 3 / 2);
- TableItem [] newItems = new TableItem [length];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- System.arraycopy (items, index, items, index + 1, itemCount++ - index);
- items [index] = item;
- ((NSTableView)view).noteNumberOfRowsChanged ();
- if (index != itemCount) fixSelection (index, true);
-}
-
-void createWidget () {
- super.createWidget ();
- items = new TableItem [4];
- columns = new TableColumn [4];
-}
-
-Color defaultBackground () {
- return display.getWidgetColor (SWT.COLOR_LIST_BACKGROUND);
-}
-
-NSFont defaultNSFont () {
- return display.tableViewFont;
-}
-
-Color defaultForeground () {
- return display.getWidgetColor (SWT.COLOR_LIST_FOREGROUND);
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (headerView);
- display.removeWidget (dataCell);
- if (buttonCell != null) display.removeWidget (buttonCell);
-}
-
-/**
- * Deselects the item at the given zero-relative index in the receiver.
- * If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget ();
- if (0 <= index && index < itemCount) {
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- widget.deselectRow (index);
- ignoreSelect = false;
- }
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. The range of the
- * indices is inclusive. Indices that are out of range are ignored.
- *
- * @param start the start index of the items to deselect
- * @param end the end index of the items to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int start, int end) {
- checkWidget();
- if (start > end) return;
- if (end < 0 || start >= itemCount) return;
- start = Math.max (0, start);
- end = Math.min (itemCount - 1, end);
- if (start == 0 && end == itemCount - 1) {
- deselectAll ();
- } else {
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- for (int i=start; i<=end; i++) {
- widget.deselectRow (i);
- }
- ignoreSelect = false;
- }
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. Indices that are out
- * of range and duplicate indices are ignored.
- *
- * @param indices the array of indices for the items to deselect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- for (int i=0; i<indices.length; i++) {
- widget.deselectRow (indices [i]);
- }
- ignoreSelect = false;
-}
-
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll () {
- checkWidget ();
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- widget.deselectAll(null);
- ignoreSelect = false;
-}
-
-void destroyItem (TableColumn column) {
- int index = 0;
- while (index < columnCount) {
- if (columns [index] == column) break;
- index++;
- }
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (item != null) {
- if (columnCount <= 1) {
- item.strings = null;
- item.images = null;
- item.cellBackground = null;
- item.cellForeground = null;
- item.cellFont = null;
- } else {
- if (item.strings != null) {
- String [] strings = item.strings;
- if (index == 0) {
- item.text = strings [1] != null ? strings [1] : "";
- }
- String [] temp = new String [columnCount - 1];
- System.arraycopy (strings, 0, temp, 0, index);
- System.arraycopy (strings, index + 1, temp, index, columnCount - 1 - index);
- item.strings = temp;
- } else {
- if (index == 0) item.text = "";
- }
- if (item.images != null) {
- Image [] images = item.images;
- if (index == 0) item.image = images [1];
- Image [] temp = new Image [columnCount - 1];
- System.arraycopy (images, 0, temp, 0, index);
- System.arraycopy (images, index + 1, temp, index, columnCount - 1 - index);
- item.images = temp;
- } else {
- if (index == 0) item.image = null;
- }
- if (item.cellBackground != null) {
- Color [] cellBackground = item.cellBackground;
- Color [] temp = new Color [columnCount - 1];
- System.arraycopy (cellBackground, 0, temp, 0, index);
- System.arraycopy (cellBackground, index + 1, temp, index, columnCount - 1 - index);
- item.cellBackground = temp;
- }
- if (item.cellForeground != null) {
- Color [] cellForeground = item.cellForeground;
- Color [] temp = new Color [columnCount - 1];
- System.arraycopy (cellForeground, 0, temp, 0, index);
- System.arraycopy (cellForeground, index + 1, temp, index, columnCount - 1 - index);
- item.cellForeground = temp;
- }
- if (item.cellFont != null) {
- Font [] cellFont = item.cellFont;
- Font [] temp = new Font [columnCount - 1];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index + 1, temp, index, columnCount - 1 - index);
- item.cellFont = temp;
- }
- }
- }
- }
-
- int oldIndex = indexOf (column.nsColumn);
-
- System.arraycopy (columns, index + 1, columns, index, --columnCount - index);
- columns [columnCount] = null;
- if (columnCount == 0) {
- //TODO - reset attributes
- firstColumn = column.nsColumn;
- firstColumn.retain ();
- /*
- * Feature in Cocoa. If a column's width is too small to show any content
- * then tableView_objectValueForTableColumn_row is never invoked to
- * query for item values, which is a problem for VIRTUAL Tables. The
- * workaround is to ensure that, for 0-column Tables, the internal first
- * column always has a minimal width that makes this call come in.
- */
- firstColumn.setMinWidth (FIRST_COLUMN_MINIMUM_WIDTH);
- firstColumn.setResizingMask (OS.NSTableColumnNoResizing);
- setScrollWidth ();
- } else {
- ((NSTableView)view).removeTableColumn(column.nsColumn);
- }
-
- NSArray array = ((NSTableView)view).tableColumns ();
- int arraySize = (int)/*64*/array.count ();
- for (int i = oldIndex; i < arraySize; i++) {
- int /*long*/ columnId = array.objectAtIndex (i).id;
- for (int j = 0; j < columnCount; j++) {
- if (columns[j].nsColumn.id == columnId) {
- columns [j].sendEvent (SWT.Move);
- break;
- }
- }
- }
-}
-
-void destroyItem (TableItem item) {
- int index = 0;
- while (index < itemCount) {
- if (items [index] == item) break;
- index++;
- }
- if (index != itemCount - 1) fixSelection (index, false);
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- ((NSTableView)view).noteNumberOfRowsChanged();
- if (itemCount == 0) setTableEmpty ();
-}
-
-boolean dragDetect(int x, int y, boolean filter, boolean[] consume) {
- // Let Cocoa determine if a drag is starting and fire the notification when we get the callback.
- return false;
-}
-
-void drawInteriorWithFrame_inView (int /*long*/ id, int /*long*/ sel, NSRect rect, int /*long*/ view) {
- boolean hooksErase = hooks (SWT.EraseItem);
- boolean hooksPaint = hooks (SWT.PaintItem);
- boolean hooksMeasure = hooks (SWT.MeasureItem);
-
- NSTextFieldCell cell = new NSTextFieldCell (id);
-
- NSTableView widget = (NSTableView)this.view;
- int /*long*/ [] outValue = new int /*long*/ [1];
- OS.object_getInstanceVariable(id, Display.SWT_ROW, outValue);
- int /*long*/ rowIndex = outValue [0];
- TableItem item = _getItem((int)/*64*/rowIndex);
- OS.object_getInstanceVariable(id, Display.SWT_COLUMN, outValue);
- int /*long*/ tableColumn = outValue[0];
- int /*long*/ nsColumnIndex = widget.tableColumns().indexOfObjectIdenticalTo(new id(tableColumn));
- int columnIndex = 0;
- for (int i=0; i<columnCount; i++) {
- if (columns [i].nsColumn.id == tableColumn) {
- columnIndex = i;
- break;
- }
- }
-
- Color background = item.cellBackground != null ? item.cellBackground [columnIndex] : null;
- if (background == null) background = item.background;
- boolean drawBackground = background != null;
- boolean drawForeground = true;
- boolean isSelected = cell.isHighlighted();
- boolean drawSelection = isSelected;
- boolean hasFocus = hooksErase && hasFocus ();
-
- Color selectionBackground = null, selectionForeground = null;
- if (isSelected && (hooksErase || hooksPaint)) {
- selectionForeground = Color.cocoa_new(display, hasFocus ? display.alternateSelectedControlTextColor : display.selectedControlTextColor);
- selectionBackground = Color.cocoa_new(display, hasFocus ? display.alternateSelectedControlColor : display.secondarySelectedControlColor);
- }
-
- NSSize contentSize = super.cellSize(id, OS.sel_cellSize);
- NSImage image = cell.image();
- if (image != null) contentSize.width += imageBounds.width + IMAGE_GAP;
- int contentWidth = (int)Math.ceil (contentSize.width);
- NSSize spacing = widget.intercellSpacing();
- int itemHeight = (int)Math.ceil (widget.rowHeight() + spacing.height);
-
- NSRect cellRect = widget.rectOfColumn (nsColumnIndex);
- cellRect.y = rect.y;
- cellRect.height = rect.height + spacing.height;
- if (columnCount == 0) {
- NSRect rowRect = widget.rectOfRow (rowIndex);
- cellRect.width = rowRect.width;
- }
- float /*double*/ offsetX = 0, offsetY = 0;
- if (hooksPaint || hooksErase) {
- NSRect frameCell = widget.frameOfCellAtColumn(nsColumnIndex, rowIndex);
- offsetX = rect.x - frameCell.x;
- offsetY = rect.y - frameCell.y;
- if (drawExpansion) {
- offsetX -= 0.5f;
- offsetY -= 0.5f;
- }
- }
- int itemX = (int)(rect.x - offsetX), itemY = (int)(rect.y - offsetY);
- NSGraphicsContext context = NSGraphicsContext.currentContext ();
-
- if (hooksMeasure) {
- sendMeasureItem(item, columnIndex, contentSize);
- }
-
- Color userForeground = null;
- if (hooksErase) {
- context.saveGraphicsState();
- NSAffineTransform transform = NSAffineTransform.transform();
- transform.translateXBy(offsetX, offsetY);
- transform.concat();
-
- GCData data = new GCData ();
- data.paintRect = cellRect;
- GC gc = GC.cocoa_new (this, data);
- gc.setFont (item.getFont (columnIndex));
- if (isSelected) {
- gc.setForeground (selectionForeground);
- gc.setBackground (selectionBackground);
- } else {
- gc.setForeground (item.getForeground (columnIndex));
- gc.setBackground (item.getBackground (columnIndex));
- }
- if (!drawExpansion) {
- gc.setClipping ((int)(cellRect.x - offsetX), (int)(cellRect.y - offsetY), (int)cellRect.width, (int)cellRect.height);
- }
- Event event = new Event ();
- event.item = item;
- event.gc = gc;
- event.index = columnIndex;
- event.detail = SWT.FOREGROUND;
- if (drawBackground) event.detail |= SWT.BACKGROUND;
- if (isSelected) event.detail |= SWT.SELECTED;
- event.x = (int)cellRect.x;
- event.y = (int)cellRect.y;
- event.width = (int)cellRect.width;
- event.height = (int)cellRect.height;
- sendEvent (SWT.EraseItem, event);
- if (!event.doit) {
- drawForeground = drawBackground = drawSelection = false;
- } else {
- drawBackground = drawBackground && (event.detail & SWT.BACKGROUND) != 0;
- drawForeground = (event.detail & SWT.FOREGROUND) != 0;
- drawSelection = drawSelection && (event.detail & SWT.SELECTED) != 0;
- }
- if (!drawSelection && isSelected) {
- userForeground = Color.cocoa_new(display, gc.getForeground().handle);
- }
- gc.dispose ();
-
- context.restoreGraphicsState();
-
- if (isDisposed ()) return;
- if (item.isDisposed ()) return;
-
- if (drawSelection && ((style & SWT.HIDE_SELECTION) == 0 || hasFocus)) {
- cellRect.height -= spacing.height;
- callSuper (widget.id, OS.sel_highlightSelectionInClipRect_, cellRect);
- cellRect.height += spacing.height;
- }
- }
-
- if (drawBackground && !drawSelection) {
- context.saveGraphicsState ();
- float /*double*/ [] colorRGB = background.handle;
- NSColor color = NSColor.colorWithDeviceRed (colorRGB[0], colorRGB[1], colorRGB[2], 1f);
- color.setFill ();
- NSBezierPath.fillRect (cellRect);
- context.restoreGraphicsState ();
- }
-
- if (drawForeground) {
- if ((!drawExpansion || hooksMeasure) && image != null) {
- NSRect destRect = new NSRect();
- destRect.x = rect.x + IMAGE_GAP;
- destRect.y = rect.y + (float)Math.ceil((rect.height - imageBounds.height) / 2);
- destRect.width = imageBounds.width;
- destRect.height = imageBounds.height;
- NSRect srcRect = new NSRect();
- NSSize size = image.size();
- srcRect.width = size.width;
- srcRect.height = size.height;
- context.saveGraphicsState();
- NSBezierPath.bezierPathWithRect(rect).addClip();
- NSAffineTransform transform = NSAffineTransform.transform();
- transform.scaleXBy(1, -1);
- transform.translateXBy(0, -(destRect.height + 2 * destRect.y));
- transform.concat();
- image.drawInRect(destRect, srcRect, OS.NSCompositeSourceOver, 1);
- context.restoreGraphicsState();
- int imageWidth = imageBounds.width + IMAGE_GAP;
- rect.x += imageWidth;
- rect.width -= imageWidth;
- }
- cell.setHighlighted (false);
- boolean callSuper = false;
- if (userForeground != null) {
- /*
- * Bug in Cocoa. For some reason, it is not possible to change the
- * foreground color to black when the cell is highlighted. The text
- * still draws white. The fix is to draw the text and not call super.
- */
- float /*double*/ [] color = userForeground.handle;
- if (color[0] == 0 && color[1] == 0 && color[2] == 0 && color[3] == 1) {
- NSMutableAttributedString newStr = new NSMutableAttributedString(cell.attributedStringValue().mutableCopy());
- NSRange range = new NSRange();
- range.length = newStr.length();
- newStr.removeAttribute(OS.NSForegroundColorAttributeName, range);
- NSRect newRect = new NSRect();
- newRect.x = rect.x + TEXT_GAP;
- newRect.y = rect.y;
- newRect.width = rect.width - TEXT_GAP;
- newRect.height = rect.height;
- NSSize size = newStr.size();
- if (newRect.height > size.height) {
- newRect.y += (newRect.height - size.height) / 2;
- newRect.height = size.height;
- }
- newStr.drawInRect(newRect);
- newStr.release();
- } else {
- NSColor nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], color[3]);
- cell.setTextColor(nsColor);
- callSuper = true;
- }
- } else {
- callSuper = true;
- }
- if (callSuper) {
- NSAttributedString attrStr = cell.attributedStringValue();
- NSSize size = attrStr.size();
- if (rect.height > size.height) {
- rect.y += (rect.height - size.height) / 2;
- rect.height = size.height;
- }
- super.drawInteriorWithFrame_inView(id, sel, rect, view);
- }
- }
-
- if (hooksPaint) {
- context.saveGraphicsState();
- NSAffineTransform transform = NSAffineTransform.transform();
- transform.translateXBy(offsetX, offsetY);
- transform.concat();
-
- GCData data = new GCData ();
- data.paintRect = cellRect;
- GC gc = GC.cocoa_new (this, data);
- gc.setFont (item.getFont (columnIndex));
- if (drawSelection) {
- gc.setForeground (selectionForeground);
- gc.setBackground (selectionBackground);
- } else {
- gc.setForeground (userForeground != null ? userForeground : item.getForeground (columnIndex));
- gc.setBackground (item.getBackground (columnIndex));
- }
- if (!drawExpansion) {
- gc.setClipping ((int)(cellRect.x - offsetX), (int)(cellRect.y - offsetY), (int)cellRect.width, (int)cellRect.height);
- }
- Event event = new Event ();
- event.item = item;
- event.gc = gc;
- event.index = columnIndex;
- if (drawForeground) event.detail |= SWT.FOREGROUND;
- if (drawBackground) event.detail |= SWT.BACKGROUND;
- if (drawSelection) event.detail |= SWT.SELECTED;
- event.x = itemX;
- event.y = itemY;
- event.width = contentWidth;
- event.height = itemHeight;
- sendEvent (SWT.PaintItem, event);
- gc.dispose ();
-
- context.restoreGraphicsState();
- }
-}
-
-void drawWithExpansionFrame_inView (int /*long*/ id, int /*long*/ sel, NSRect cellFrame, int /*long*/ view) {
- drawExpansion = true;
- super.drawWithExpansionFrame_inView(id, sel, cellFrame, view);
- drawExpansion = false;
-}
-
-void drawRect(int id, int sel, NSRect rect) {
- fixScrollWidth = false;
- super.drawRect(id, sel, rect);
- if (isDisposed ()) return;
- if (fixScrollWidth) {
- fixScrollWidth = false;
- if (setScrollWidth (items, true)) view.setNeedsDisplay(true);
- }
-}
-
-NSRect expansionFrameWithFrame_inView(int /*long*/ id, int /*long*/ sel, NSRect cellRect, int /*long*/ view) {
- if (toolTipText == null) {
- NSRect rect = super.expansionFrameWithFrame_inView(id, sel, cellRect, view);
- NSCell cell = new NSCell(id);
- if (rect.width != 0 && rect.height != 0) {
- if (hooks(SWT.MeasureItem)) {
- NSSize cellSize = cell.cellSize();
- cellRect.width = cellSize.width;
- return cellRect;
- }
- } else {
- NSRect expansionRect;
- if (hooks(SWT.MeasureItem)) {
- expansionRect = cellRect;
- NSSize cellSize = cell.cellSize();
- expansionRect.width = cellSize.width;
- } else {
- expansionRect = cell.titleRectForBounds(cellRect);
- NSSize cellSize = super.cellSize(id, OS.sel_cellSize);
- expansionRect.width = cellSize.width;
- }
- NSRect contentRect = scrollView.contentView().bounds();
- OS.NSIntersectionRect(contentRect, expansionRect, contentRect);
- if (!OS.NSEqualRects(expansionRect, contentRect)) {
- return expansionRect;
- }
- }
- return rect;
- }
- return new NSRect();
-}
-
-Widget findTooltip (NSPoint pt) {
- NSTableView widget = (NSTableView)view;
- NSTableHeaderView headerView = widget.headerView();
- if (headerView != null) {
- pt = headerView.convertPoint_fromView_ (pt, null);
- int /*long*/ index = headerView.columnAtPoint (pt);
- if (index != -1) {
- NSArray nsColumns = widget.tableColumns ();
- id nsColumn = nsColumns.objectAtIndex (index);
- for (int i = 0; i < columnCount; i++) {
- TableColumn column = columns [i];
- if (column.nsColumn.id == nsColumn.id) {
- return column;
- }
- }
- }
- }
- return super.findTooltip (pt);
-}
-
-void fixSelection (int index, boolean add) {
- int [] selection = getSelectionIndices ();
- if (selection.length == 0) return;
- int newCount = 0;
- boolean fix = false;
- for (int i = 0; i < selection.length; i++) {
- if (!add && selection [i] == index) {
- fix = true;
- } else {
- int newIndex = newCount++;
- selection [newIndex] = selection [i];
- if (selection [newIndex] >= index) {
- selection [newIndex] += add ? 1 : -1;
- fix = true;
- }
- }
- }
- if (fix) select (selection, newCount, true);
-}
-
-int getCheckColumnWidth () {
- return (int)checkColumn.dataCell().cellSize().width;
-}
-
-public Rectangle getClientArea () {
- checkWidget ();
- Rectangle rect = super.getClientArea ();
- NSTableHeaderView headerView = ((NSTableView) view).headerView ();
- if (headerView != null) {
- int height = (int) headerView.bounds ().height;
- rect.y -= height;
- rect.height += height;
- }
- return rect;
-}
-
-TableColumn getColumn (id id) {
- for (int i = 0; i < columnCount; i++) {
- if (columns[i].nsColumn.id == id.id) {
- return columns[i];
- }
- }
- return null;
-}
-
-/**
- * Returns the column at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- * Columns are returned in the order that they were created.
- * If no <code>TableColumn</code>s were created by the programmer,
- * this method will throw <code>ERROR_INVALID_RANGE</code> despite
- * the fact that a single column of data may be visible in the table.
- * This occurs when the programmer uses the table like a list, adding
- * items but never creating a column.
- *
- * @param index the index of the column to return
- * @return the column at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- */
-public TableColumn getColumn (int index) {
- checkWidget ();
- if (!(0 <=index && index < columnCount)) error (SWT.ERROR_INVALID_RANGE);
- return columns [index];
-}
-
-/**
- * Returns the number of columns contained in the receiver.
- * If no <code>TableColumn</code>s were created by the programmer,
- * this value is zero, despite the fact that visually, one column
- * of items may be visible. This occurs when the programmer uses
- * the table like a list, adding items but never creating a column.
- *
- * @return the number of columns
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getColumnCount () {
- checkWidget ();
- return columnCount;
-}
-
-/**
- * Returns an array of zero-relative integers that map
- * the creation order of the receiver's items to the
- * order in which they are currently being displayed.
- * <p>
- * Specifically, the indices of the returned array represent
- * the current visual order of the items, and the contents
- * of the array represent the creation order of the items.
- * </p><p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the current visual order of the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public int [] getColumnOrder () {
- checkWidget ();
- int [] order = new int [columnCount];
- for (int i = 0; i < columnCount; i++) {
- TableColumn column = columns [i];
- int index = indexOf (column.nsColumn);
- if ((style & SWT.CHECK) != 0) index -= 1;
- order [index] = i;
- }
- return order;
-}
-
-/**
- * Returns an array of <code>TableColumn</code>s which are the
- * columns in the receiver. Columns are returned in the order
- * that they were created. If no <code>TableColumn</code>s were
- * created by the programmer, the array is empty, despite the fact
- * that visually, one column of items may be visible. This occurs
- * when the programmer uses the table like a list, adding items but
- * never creating a column.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- */
-public TableColumn [] getColumns () {
- checkWidget ();
- TableColumn [] result = new TableColumn [columnCount];
- System.arraycopy (columns, 0, result, 0, columnCount);
- return result;
-}
-
-/**
- * Returns the width in pixels of a grid line.
- *
- * @return the width of a grid line in pixels
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getGridLineWidth () {
- checkWidget ();
- return 0;
-}
-
-/**
- * Returns the height of the receiver's header
- *
- * @return the height of the header or zero if the header is not visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public int getHeaderHeight () {
- checkWidget ();
- NSTableHeaderView headerView = ((NSTableView)view).headerView();
- if (headerView == null) return 0;
- return (int)headerView.bounds().height;
-}
-
-/**
- * Returns <code>true</code> if the receiver's header is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's header's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getHeaderVisible () {
- checkWidget ();
- return ((NSTableView)view).headerView() != null;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem getItem (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- return _getItem (index);
-}
-
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- * <p>
- * The item that is returned represents an item that could be selected by the user.
- * For example, if selection only occurs in items in the first column, then null is
- * returned if the point is outside of the item.
- * Note that the SWT.FULL_SELECTION style hint, which specifies the selection policy,
- * determines the extent of the selection.
- * </p>
- *
- * @param point the point used to locate the item
- * @return the item at the given point, or null if the point is not in a selectable item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem getItem (Point point) {
- checkWidget ();
- NSTableView widget = (NSTableView)view;
- NSPoint pt = new NSPoint();
- pt.x = point.x;
- pt.y = point.y;
- int row = (int)/*64*/widget.rowAtPoint(pt);
- if (row == -1) return null;
- return items[row];
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return itemCount;
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the receiver.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- return (int)((NSTableView)view).rowHeight() + CELL_GAP;
-}
-
-/**
- * Returns a (possibly empty) array of <code>TableItem</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem [] getItems () {
- checkWidget ();
- TableItem [] result = new TableItem [itemCount];
- if ((style & SWT.VIRTUAL) != 0) {
- for (int i=0; i<itemCount; i++) {
- result [i] = _getItem (i);
- }
- } else {
- System.arraycopy (items, 0, result, 0, itemCount);
- }
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver's lines are visible,
- * and <code>false</code> otherwise. Note that some platforms draw
- * grid lines while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the visibility state of the lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getLinesVisible () {
- checkWidget ();
- return ((NSTableView)view).usesAlternatingRowBackgroundColors();
-}
-
-/**
- * Returns an array of <code>TableItem</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem [] getSelection () {
- checkWidget ();
- NSTableView widget = (NSTableView)view;
- if (widget.numberOfSelectedRows() == 0) {
- return new TableItem [0];
- }
- NSIndexSet selection = widget.selectedRowIndexes();
- int count = (int)/*64*/selection.count();
- int /*long*/ [] indexBuffer = new int /*long*/ [count];
- selection.getIndexes(indexBuffer, count, 0);
- TableItem [] result = new TableItem [count];
- for (int i=0; i<count; i++) {
- result [i] = _getItem ((int)/*64*/indexBuffer [i]);
- }
- return result;
-}
-
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget ();
- return (int)/*64*/((NSTableView)view).numberOfSelectedRows();
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget ();
- NSTableView widget = (NSTableView)view;
- if (widget.numberOfSelectedRows() == 0) {
- return -1;
- }
- NSIndexSet selection = widget.selectedRowIndexes();
- int count = (int)/*64*/selection.count();
- int /*long*/ [] result = new int /*long*/ [count];
- selection.getIndexes(result, count, 0);
- return (int)/*64*/result [0];
-}
-
-/**
- * Returns the zero-relative indices of the items which are currently
- * selected in the receiver. The order of the indices is unspecified.
- * The array is empty if no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return the array of indices of the selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int [] getSelectionIndices () {
- checkWidget ();
- NSTableView widget = (NSTableView)view;
- if (widget.numberOfSelectedRows() == 0) {
- return new int [0];
- }
- NSIndexSet selection = widget.selectedRowIndexes();
- int count = (int)/*64*/selection.count();
- int /*long*/ [] indices = new int /*long*/ [count];
- selection.getIndexes(indices, count, 0);
- int [] result = new int [count];
- for (int i = 0; i < indices.length; i++) {
- result [i] = (int)/*64*/indices [i];
- }
- return result;
-}
-
-/**
- * Returns the column which shows the sort indicator for
- * the receiver. The value may be null if no column shows
- * the sort indicator.
- *
- * @return the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortColumn(TableColumn)
- *
- * @since 3.2
- */
-public TableColumn getSortColumn () {
- checkWidget ();
- return sortColumn;
-}
-
-/**
- * Returns the direction of the sort indicator for the receiver.
- * The value will be one of <code>UP</code>, <code>DOWN</code>
- * or <code>NONE</code>.
- *
- * @return the sort direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortDirection(int)
- *
- * @since 3.2
- */
-public int getSortDirection () {
- checkWidget ();
- return sortDirection;
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items are
- * scrolled or new items are added or removed.
- *
- * @return the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget ();
- //TODO - partial item at the top
- NSRect rect = scrollView.documentVisibleRect();
- NSPoint point = new NSPoint();
- point.x = rect.x;
- point.y = rect.y;
- return (int)/*64*/((NSTableView)view).rowAtPoint(point);
-}
-
-void highlightSelectionInClipRect(int /*long*/ id, int /*long*/ sel, int /*long*/ rect) {
- if (hooks (SWT.EraseItem)) return;
- if ((style & SWT.HIDE_SELECTION) != 0 && !hasFocus()) return;
- NSRect clipRect = new NSRect ();
- OS.memmove (clipRect, rect, NSRect.sizeof);
- callSuper (id, sel, clipRect);
-}
-
-int /*long*/ hitTestForEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ event, NSRect rect, int /*long*/ controlView) {
- /*
- * For some reason, the cell class needs to implement hitTestForEvent:inRect:ofView:,
- * otherwise the double action selector is not called properly.
- */
- return callSuper(id, sel, event, rect, controlView);
-}
-
-int /*long*/ image (int /*long*/ id, int /*long*/ sel) {
- int /*long*/ [] image = new int /*long*/ [1];
- OS.object_getInstanceVariable(id, Display.SWT_IMAGE, image);
- return image[0];
-}
-
-NSRect imageRectForBounds (int /*long*/ id, int /*long*/ sel, NSRect cellFrame) {
- NSImage image = new NSCell(id).image();
- if (image != null) {
- cellFrame.x += IMAGE_GAP;
- cellFrame.width = imageBounds.width;
- cellFrame.height = imageBounds.height;
- }
- return cellFrame;
-}
-
-int indexOf (NSTableColumn column) {
- return (int)/*64*/((NSTableView)view).tableColumns().indexOfObjectIdenticalTo(column);
-}
-
-/**
- * Searches the receiver's list starting at the first column
- * (index 0) until a column is found that is equal to the
- * argument, and returns the index of that column. If no column
- * is found, returns -1.
- *
- * @param column the search column
- * @return the index of the column
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the column is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (TableColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<columnCount; i++) {
- if (columns [i] == column) return i;
- }
- return -1;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (TableItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (1 <= lastIndexOf && lastIndexOf < itemCount - 1) {
- if (items [lastIndexOf] == item) return lastIndexOf;
- if (items [lastIndexOf + 1] == item) return ++lastIndexOf;
- if (items [lastIndexOf - 1] == item) return --lastIndexOf;
- }
- if (lastIndexOf < itemCount / 2) {
- for (int i=0; i<itemCount; i++) {
- if (items [i] == item) return lastIndexOf = i;
- }
- } else {
- for (int i=itemCount - 1; i>=0; --i) {
- if (items [i] == item) return lastIndexOf = i;
- }
- }
- return -1;
-}
-
-/**
- * Returns <code>true</code> if the item is selected,
- * and <code>false</code> otherwise. Indices out of
- * range are ignored.
- *
- * @param index the index of the item
- * @return the selection state of the item at the index
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isSelected (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) return false;
- return ((NSTableView)view).isRowSelected(index);
-}
-
-boolean isTrim (NSView view) {
- if (super.isTrim (view)) return true;
- return view.id == headerView.id;
-}
-
-int /*long*/ menuForEvent(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (id != headerView.id) {
- /*
- * Feature in Cocoa: Table views do not change the selection when the user
- * right-clicks or control-clicks on an NSTableView or its subclasses. Fix is to select the
- * clicked-on row ourselves.
- */
- NSEvent event = new NSEvent(theEvent);
- NSTableView table = (NSTableView)view;
-
- // get the current selections for the table view.
- NSIndexSet selectedRowIndexes = table.selectedRowIndexes();
-
- // select the row that was clicked before showing the menu for the event
- NSPoint mousePoint = view.convertPoint_fromView_(event.locationInWindow(), null);
- int /*long*/ row = table.rowAtPoint(mousePoint);
-
- // figure out if the row that was just clicked on is currently selected
- if (selectedRowIndexes.containsIndex(row) == false) {
- NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc();
- set = set.initWithIndex(row);
- table.selectRowIndexes (set, false);
- set.release();
- }
- // else that row is currently selected, so don't change anything.
- }
- return super.menuForEvent(id, sel, theEvent);
-}
-
-void mouseDown (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (headerView != null && id == headerView.id) {
- NSTableView widget = (NSTableView)view;
- widget.setAllowsColumnReordering(false);
- NSPoint pt = headerView.convertPoint_fromView_(new NSEvent(theEvent).locationInWindow(), null);
- int /*long*/ nsIndex = headerView.columnAtPoint(pt);
- if (nsIndex != -1) {
- id nsColumn = widget.tableColumns().objectAtIndex(nsIndex);
- for (int i = 0; i < columnCount; i++) {
- if (columns[i].nsColumn.id == nsColumn.id) {
- widget.setAllowsColumnReordering(columns[i].movable);
- break;
- }
- }
- }
- }
- else if (id == view.id) {
- // Bug/feature in Cocoa: If the table has a context menu we just set it visible instead of returning
- // it from menuForEvent:. This has the side effect, however, of sending control-click to the NSTableView,
- // which is interpreted as a single click that clears the selection. Fix is to ignore control-click if the
- // view has a context menu.
- NSEvent event = new NSEvent(theEvent);
- if ((event.modifierFlags() & OS.NSControlKeyMask) != 0) return;
- }
- super.mouseDown(id, sel, theEvent);
-}
-
-/*
- * Feature in Cocoa. If a checkbox is in multi-state mode, nextState cycles
- * from off to mixed to on and back to off again. This will cause the on state
- * to momentarily appear while clicking on the checkbox. To avoid this,
- * override [NSCell nextState] to go directly to the desired state.
- */
-int /*long*/ nextState (int /*long*/ id, int /*long*/ sel) {
- NSTableView tableView = (NSTableView)view;
- int index = (int)/*64*/tableView.selectedRow ();
- TableItem item = items[index];
- if (item.grayed) {
- return item.checked ? OS.NSOffState : OS.NSMixedState;
- }
- return item.checked ? OS.NSOffState : OS.NSOnState;
-}
-
-int /*long*/ numberOfRowsInTableView(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView) {
- return itemCount;
-}
-
-void register () {
- super.register ();
- display.addWidget (headerView, this);
- display.addWidget (dataCell, this);
- if (buttonCell != null) display.addWidget (buttonCell, this);
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- }
- if (columns != null) {
- for (int i=0; i<columnCount; i++) {
- TableColumn column = columns [i];
- if (column != null && !column.isDisposed ()) {
- column.release (false);
- }
- }
- columns = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (headerView != null) headerView.release();
- headerView = null;
- if (firstColumn != null) firstColumn.release();
- firstColumn = null;
- if (checkColumn != null) checkColumn.release();
- checkColumn = null;
- if (dataCell != null) dataCell.release();
- dataCell = null;
- if (buttonCell != null) buttonCell.release();
- buttonCell = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- currentItem = null;
- sortColumn = null;
-}
-
-/**
- * Removes the item from the receiver at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- TableItem item = items [index];
- if (item != null) item.release (false);
- if (index != itemCount - 1) fixSelection (index, false);
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- ((NSTableView)view).noteNumberOfRowsChanged();
- if (itemCount == 0) {
- setTableEmpty ();
- }
-}
-
-/**
- * Removes the items from the receiver which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget ();
- if (start > end) return;
- if (!(0 <= start && start <= end && end < itemCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- if (start == 0 && end == itemCount - 1) {
- removeAll ();
- } else {
- int length = end - start + 1;
- for (int i=0; i<length; i++) remove (start);
- }
-}
-
-/**
- * Removes the items from the receiver's list at the given
- * zero-relative indices.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- int [] newIndices = new int [indices.length];
- System.arraycopy (indices, 0, newIndices, 0, indices.length);
- sort (newIndices);
- int start = newIndices [newIndices.length - 1], end = newIndices [0];
- if (!(0 <= start && start <= end && end < itemCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int last = -1;
- for (int i=0; i<newIndices.length; i++) {
- int index = newIndices [i];
- if (index != last) {
- remove (index);
- last = index;
- }
- }
-}
-
-/**
- * Removes all of the items from the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget ();
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (item != null && !item.isDisposed ()) item.release (false);
- }
- setTableEmpty ();
- ((NSTableView)view).noteNumberOfRowsChanged();
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener(SelectionListener)
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget ();
- if (0 <= index && index < itemCount) {
- NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc();
- set = set.initWithIndex(index);
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- widget.selectRowIndexes(set, (style & SWT.MULTI) != 0);
- ignoreSelect = false;
- set.release();
- }
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If an item in the given range is not selected, it is selected.
- * If an item in the given range was already selected, it remains selected.
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setSelection(int,int)
- */
-public void select (int start, int end) {
- checkWidget ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- if (itemCount == 0 || start >= itemCount) return;
- if (start == 0 && end == itemCount - 1) {
- selectAll ();
- } else {
- start = Math.max (0, start);
- end = Math.min (end, itemCount - 1);
- NSRange range = new NSRange();
- range.location = start;
- range.length = end - start + 1;
- NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc();
- set = set.initWithIndexesInRange(range);
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- widget.selectRowIndexes(set, (style & SWT.MULTI) != 0);
- ignoreSelect = false;
- set.release();
- }
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If the item at a given index is not selected, it is selected.
- * If the item at a given index was already selected, it remains selected.
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- * </p>
- *
- * @param indices the array of indices for the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setSelection(int[])
- */
-public void select (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- int count = 0;
- NSMutableIndexSet set = (NSMutableIndexSet)new NSMutableIndexSet().alloc().init();
- for (int i=0; i<length; i++) {
- int index = indices [i];
- if (index >= 0 && index < itemCount) {
- set.addIndex (indices [i]);
- count++;
- }
- }
- if (count > 0) {
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- widget.selectRowIndexes(set, (style & SWT.MULTI) != 0);
- ignoreSelect = false;
- }
- set.release();
-}
-
-void select (int [] indices, int count, boolean clear) {
- NSMutableIndexSet set = (NSMutableIndexSet)new NSMutableIndexSet().alloc().init();
- for (int i=0; i<count; i++) set.addIndex (indices [i]);
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- widget.selectRowIndexes(set, !clear);
- ignoreSelect = false;
- set.release();
-}
-
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- NSTableView widget = (NSTableView)view;
- ignoreSelect = true;
- widget.selectAll(null);
- ignoreSelect = false;
-}
-
-void updateBackground () {
- NSColor nsColor = null;
- if (backgroundImage != null) {
- nsColor = NSColor.colorWithPatternImage(backgroundImage.handle);
- } else if (background != null) {
- nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]);
- }
- ((NSTableView) view).setBackgroundColor (nsColor);
-}
-
-/**
- * Sets the order that the items in the receiver should
- * be displayed in to the given argument which is described
- * in terms of the zero-relative ordering of when the items
- * were added.
- *
- * @param order the new order to display the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item order is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public void setColumnOrder (int [] order) {
- checkWidget ();
- if (order == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (columnCount == 0) {
- if (order.length != 0) error (SWT.ERROR_INVALID_ARGUMENT);
- return;
- }
- if (order.length != columnCount) error (SWT.ERROR_INVALID_ARGUMENT);
- int [] oldOrder = getColumnOrder ();
- boolean reorder = false;
- boolean [] seen = new boolean [columnCount];
- for (int i=0; i<order.length; i++) {
- int index = order [i];
- if (index < 0 || index >= columnCount) error (SWT.ERROR_INVALID_ARGUMENT);
- if (seen [index]) error (SWT.ERROR_INVALID_ARGUMENT);
- seen [index] = true;
- if (order [i] != oldOrder [i]) reorder = true;
- }
- if (reorder) {
- NSTableView tableView = (NSTableView)view;
- int [] oldX = new int [oldOrder.length];
- int check = (style & SWT.CHECK) != 0 ? 1 : 0;
- for (int i=0; i<oldOrder.length; i++) {
- int index = oldOrder[i];
- oldX [index] = (int)tableView.rectOfColumn (i + check).x;
- }
- int [] newX = new int [order.length];
- for (int i=0; i<order.length; i++) {
- int index = order [i];
- TableColumn column = columns[index];
- int oldIndex = indexOf (column.nsColumn);
- int newIndex = i + check;
- tableView.moveColumn (oldIndex, newIndex);
- newX [index] = (int)tableView.rectOfColumn (newIndex).x;
- }
- TableColumn[] newColumns = new TableColumn [columnCount];
- System.arraycopy (columns, 0, newColumns, 0, columnCount);
- for (int i=0; i<columnCount; i++) {
- TableColumn column = newColumns [i];
- if (!column.isDisposed ()) {
- if (newX [i] != oldX [i]) {
- column.sendEvent (SWT.Move);
- }
- }
- }
- }
-}
-
-void setFont (NSFont font) {
- super.setFont (font);
- setItemHeight (null, font, !hooks (SWT.MeasureItem));
- view.setNeedsDisplay (true);
- clearCachedWidth (items);
- setScrollWidth (items, true);
-}
-
-/**
- * Marks the receiver's header as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHeaderVisible (boolean show) {
- checkWidget ();
- ((NSTableView)view).setHeaderView (show ? headerView : null);
-}
-
-void setImage (int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- OS.object_setInstanceVariable(id, Display.SWT_IMAGE, arg0);
-}
-
-/**
- * Sets the number of items contained in the receiver.
- *
- * @param count the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setItemCount (int count) {
- checkWidget ();
- count = Math.max (0, count);
- if (count == itemCount) return;
- if (count == itemCount) return;
- TableItem [] children = items;
- if (count < itemCount) {
- for (int index = count; index < itemCount; index ++) {
- TableItem item = children [index];
- if (item != null && !item.isDisposed()) item.release (false);
- }
- }
- if (count > itemCount) {
- if ((getStyle() & SWT.VIRTUAL) == 0) {
- for (int i=itemCount; i<count; i++) {
- new TableItem (this, SWT.NONE, i, true);
- }
- return;
- }
- }
- int length = Math.max (4, (count + 3) / 4 * 4);
- TableItem [] newItems = new TableItem [length];
- if (children != null) {
- System.arraycopy (items, 0, newItems, 0, Math.min (count, itemCount));
- }
- children = newItems;
- this.items = newItems;
- this.itemCount = count;
- ((NSTableView) view).noteNumberOfRowsChanged ();
-}
-
-/*public*/ void setItemHeight (int itemHeight) {
- checkWidget ();
- if (itemHeight < -1) error (SWT.ERROR_INVALID_ARGUMENT);
- if (itemHeight == -1) {
- //TODO - reset item height, ensure other API's such as setFont don't do this
- } else {
- ((NSTableView)view).setRowHeight (itemHeight);
- }
-}
-
-void setItemHeight (Image image, NSFont font, boolean set) {
- if (font == null) font = getFont ().handle;
- float /*double*/ ascent = font.ascender ();
- float /*double*/ descent = -font.descender () + font.leading ();
- int height = (int)Math.ceil (ascent + descent) + 1;
- Rectangle bounds = image != null ? image.getBounds () : imageBounds;
- if (bounds != null) {
- imageBounds = bounds;
- height = Math.max (height, bounds.height);
- }
- NSTableView widget = (NSTableView)view;
- if (set || widget.rowHeight () < height) {
- widget.setRowHeight (height);
- }
-}
-
-public void setRedraw (boolean redraw) {
- checkWidget ();
- super.setRedraw (redraw);
- if (redraw && drawCount == 0) {
- /* Resize the item array to match the item count */
- if (items.length > 4 && items.length - itemCount > 3) {
- int length = Math.max (4, (itemCount + 3) / 4 * 4);
- TableItem [] newItems = new TableItem [length];
- System.arraycopy (items, 0, newItems, 0, itemCount);
- items = newItems;
- }
- setScrollWidth ();
- }
-}
-
-/**
- * Marks the receiver's lines as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise. Note that some platforms draw grid lines
- * while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLinesVisible (boolean show) {
- checkWidget ();
- ((NSTableView)view).setUsesAlternatingRowBackgroundColors(show);
-}
-
-boolean setScrollWidth () {
- return setScrollWidth (items, true);
-}
-
-boolean setScrollWidth (TableItem item) {
- if (columnCount != 0) return false;
- if (!getDrawing()) return false;
- if (currentItem != null) {
- if (currentItem != item) fixScrollWidth = true;
- return false;
- }
- GC gc = new GC (this);
- int newWidth = item.calculateWidth (0, gc);
- gc.dispose ();
- int oldWidth = (int)firstColumn.width ();
- if (oldWidth < newWidth) {
- firstColumn.setWidth (newWidth);
- if (horizontalBar != null && horizontalBar.view != null) redrawWidget (horizontalBar.view, false);
- return true;
- }
- return false;
-}
-
-boolean setScrollWidth (TableItem [] items, boolean set) {
- if (items == null) return false;
- if (columnCount != 0) return false;
- if (!getDrawing()) return false;
- if (currentItem != null) {
- fixScrollWidth = true;
- return false;
- }
- GC gc = new GC (this);
- int newWidth = 0;
- for (int i = 0; i < items.length; i++) {
- TableItem item = items [i];
- if (item != null) {
- newWidth = Math.max (newWidth, item.calculateWidth (0, gc));
- }
- }
- gc.dispose ();
- if (!set) {
- int oldWidth = (int)firstColumn.width ();
- if (oldWidth >= newWidth) return false;
- }
- firstColumn.setWidth (newWidth);
- if (horizontalBar != null && horizontalBar.view != null) redrawWidget (horizontalBar.view, false);
- return true;
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * The current selection is first cleared, then the new item is selected.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int)
- */
-public void setSelection (int index) {
- checkWidget ();
- //TODO - optimize to use expand flag
- deselectAll ();
- if (0 <= index && index < itemCount) {
- select (index);
- showIndex (index);
- }
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- * </p>
- *
- * @param start the start index of the items to select
- * @param end the end index of the items to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int,int)
- */
-public void setSelection (int start, int end) {
- checkWidget ();
- //TODO - optimize to use expand flag
- deselectAll ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- if (itemCount == 0 || start >= itemCount) return;
- start = Math.max (0, start);
- end = Math.min (end, itemCount - 1);
- select (start, end);
- showIndex (start);
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- * </p>
- *
- * @param indices the indices of the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int[])
- */
-public void setSelection (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- //TODO - optimize to use expand flag
- deselectAll ();
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- select (indices);
- showIndex (indices [0]);
-}
-
-/**
- * Sets the receiver's selection to the given item.
- * The current selection is cleared before the new item is selected.
- * <p>
- * If the item is not in the receiver, then it is ignored.
- * </p>
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection (TableItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (new TableItem [] {item});
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- * </p>
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the items has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int[])
- * @see Table#setSelection(int[])
- */
-public void setSelection (TableItem [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- //TODO - optimize to use expand flag
- deselectAll ();
- int length = items.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- int [] indices = new int [length];
- int count = 0;
- for (int i=0; i<length; i++) {
- int index = indexOf (items [length - i - 1]);
- if (index != -1) {
- indices [count++] = index;
- }
- }
- if (count > 0) {
- select (indices);
- showIndex (indices [0]);
- }
-}
-
-void setSmallSize () {
- if (checkColumn == null) return;
- checkColumn.dataCell ().setControlSize (OS.NSSmallControlSize);
- checkColumn.setWidth (getCheckColumnWidth ());
-}
-
-/**
- * Sets the column used by the sort indicator for the receiver. A null
- * value will clear the sort indicator. The current sort column is cleared
- * before the new column is set.
- *
- * @param column the column used by the sort indicator or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the column is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortColumn (TableColumn column) {
- checkWidget ();
- if (column != null && column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (column == sortColumn) return;
- sortColumn = column;
- ((NSTableView)view).setHighlightedTableColumn (column == null ? null : column.nsColumn);
-}
-
-/**
- * Sets the direction of the sort indicator for the receiver. The value
- * can be one of <code>UP</code>, <code>DOWN</code> or <code>NONE</code>.
- *
- * @param direction the direction of the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortDirection (int direction) {
- checkWidget ();
- if (direction != SWT.UP && direction != SWT.DOWN && direction != SWT.NONE) return;
- if (direction == sortDirection) return;
- sortDirection = direction;
- if (sortColumn == null) return;
- NSTableHeaderView headerView = ((NSTableView)view).headerView ();
- if (headerView == null) return;
- int index = indexOf (sortColumn.nsColumn);
- NSRect rect = headerView.headerRectOfColumn (index);
- headerView.setNeedsDisplayInRect (rect);
-}
-
-void setTableEmpty () {
- itemCount = 0;
- items = new TableItem [4];
- imageBounds = null;
-}
-
-/**
- * Sets the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items
- * are scrolled or new items are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget ();
- NSTableView widget = (NSTableView) view;
- int row = Math.max(0, Math.min(index, itemCount));
- NSPoint pt = new NSPoint();
- pt.x = scrollView.contentView().bounds().x;
- pt.y = widget.frameOfCellAtColumn(0, row).y;
- view.scrollPoint(pt);
-}
-
-/**
- * Shows the column. If the column is already showing in the receiver,
- * this method simply returns. Otherwise, the columns are scrolled until
- * the column is visible.
- *
- * @param column the column to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the column is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the column has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void showColumn (TableColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (column.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (column.parent != this) return;
- if (columnCount <= 1) return;
- int index = indexOf (column.nsColumn);
- if (!(0 <= index && index < columnCount + ((style & SWT.CHECK) != 0 ? 1 : 0))) return;
- ((NSTableView)view).scrollColumnToVisible (index);
-}
-
-void showIndex (int index) {
- if (0 <= index && index < itemCount) {
- ((NSTableView)view).scrollRowToVisible(index);
- }
-}
-
-/**
- * Shows the item. If the item is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the item is visible.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#showSelection()
- */
-public void showItem (TableItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- int index = indexOf (item);
- if (index != -1) showIndex (index);
-}
-
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#showItem(TableItem)
- */
-public void showSelection () {
- checkWidget ();
- int index = getSelectionIndex ();
- if (index >= 0) {
- checkData(_getItem(index));
- showIndex (index);
- }
-}
-
-void sendDoubleSelection() {
- NSTableView tableView = (NSTableView)view;
- int rowIndex = (int)/*64*/tableView.clickedRow ();
- if (rowIndex != -1) {
- if ((style & SWT.CHECK) != 0) {
- NSArray columns = tableView.tableColumns ();
- int columnIndex = (int)/*64*/tableView.clickedColumn ();
- id column = columns.objectAtIndex (columnIndex);
- if (column.id == checkColumn.id) return;
- }
- Event event = new Event ();
- event.item = _getItem (rowIndex);
- postEvent (SWT.DefaultSelection, event);
- }
-}
-
-boolean sendKeyEvent (NSEvent nsEvent, int type) {
- boolean result = super.sendKeyEvent (nsEvent, type);
- if (!result) return result;
- if (type != SWT.KeyDown) return result;
- short keyCode = nsEvent.keyCode ();
- switch (keyCode) {
- case 76: /* KP Enter */
- case 36: { /* Return */
- postEvent (SWT.DefaultSelection);
- break;
- }
- }
- return result;
-}
-
-void sendMeasureItem (TableItem item, int columnIndex, NSSize size) {
- NSTableView widget = (NSTableView)this.view;
- int contentWidth = (int)Math.ceil (size.width);
- NSSize spacing = widget.intercellSpacing();
- int itemHeight = (int)Math.ceil (widget.rowHeight() + spacing.height);
- GCData data = new GCData ();
- data.paintRect = widget.frame ();
- GC gc = GC.cocoa_new (this, data);
- gc.setFont (item.getFont (columnIndex));
- Event event = new Event ();
- event.item = item;
- event.gc = gc;
- event.index = columnIndex;
- event.width = contentWidth;
- event.height = itemHeight;
- sendEvent (SWT.MeasureItem, event);
- gc.dispose ();
- if (!isDisposed () && !item.isDisposed ()) {
- size.width = event.width;
- size.height = event.height;
- if (itemHeight < event.height) {
- widget.setRowHeight (event.height);
- }
- if (contentWidth != event.width) {
- if (columnCount == 0 && columnIndex == 0) {
- item.width = event.width;
- if (setScrollWidth (item)) {
- widget.setNeedsDisplay(true);
- }
- }
- }
- }
-}
-
-void tableViewColumnDidMove (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
- NSNotification notification = new NSNotification (aNotification);
- NSDictionary userInfo = notification.userInfo ();
- id nsOldIndex = userInfo.valueForKey (NSString.stringWith ("NSOldColumn")); //$NON-NLS-1$
- id nsNewIndex = userInfo.valueForKey (NSString.stringWith ("NSNewColumn")); //$NON-NLS-1$
- int oldIndex = new NSNumber (nsOldIndex).intValue ();
- int newIndex = new NSNumber (nsNewIndex).intValue ();
- int startIndex = Math.min (oldIndex, newIndex);
- int endIndex = Math.max (oldIndex, newIndex);
- NSTableView tableView = (NSTableView)view;
- NSArray nsColumns = tableView.tableColumns ();
- for (int i = startIndex; i <= endIndex; i++) {
- id columnId = nsColumns.objectAtIndex (i);
- TableColumn column = getColumn (columnId);
- if (column != null) {
- column.sendEvent (SWT.Move);
- if (isDisposed ()) return;
- }
- }
-}
-
-void tableViewColumnDidResize (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
- NSNotification notification = new NSNotification (aNotification);
- NSDictionary userInfo = notification.userInfo ();
- id columnId = userInfo.valueForKey (NSString.stringWith ("NSTableColumn")); //$NON-NLS-1$
- TableColumn column = getColumn (columnId);
- if (column == null) return; /* either CHECK column or firstColumn in 0-column Table */
-
- column.sendEvent (SWT.Resize);
- if (isDisposed ()) return;
-
- NSTableView tableView = (NSTableView)view;
- int index = indexOf (column.nsColumn);
- if (index == -1) return; /* column was disposed in Resize callback */
-
- NSArray nsColumns = tableView.tableColumns ();
- int columnCount = (int)/*64*/tableView.numberOfColumns ();
- for (int i = index + 1; i < columnCount; i++) {
- columnId = nsColumns.objectAtIndex (i);
- column = getColumn (columnId);
- if (column != null) {
- column.sendEvent (SWT.Move);
- if (isDisposed ()) return;
- }
- }
-}
-
-void tableViewSelectionDidChange (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
- if (ignoreSelect) return;
- NSTableView widget = (NSTableView) view;
- int row = (int)/*64*/widget.selectedRow ();
- if(row == -1)
- postEvent (SWT.Selection);
- else {
- TableItem item = _getItem (row);
- Event event = new Event ();
- event.item = item;
- event.index = row;
- postEvent (SWT.Selection, event);
- }
-}
-
-void tableView_didClickTableColumn (int /*long*/ id, int /*long*/ sel, int /*long*/ tableView, int /*long*/ tableColumn) {
- TableColumn column = getColumn (new id (tableColumn));
- if (column == null) return; /* either CHECK column or firstColumn in 0-column Table */
- column.postEvent (SWT.Selection);
-}
-
-int /*long*/ tableView_objectValueForTableColumn_row (int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ aTableColumn, int /*long*/ rowIndex) {
- int index = (int)/*64*/rowIndex;
- TableItem item = _getItem (index);
- checkData (item, index);
- if (checkColumn != null && aTableColumn == checkColumn.id) {
- NSNumber value;
- if (item.checked && item.grayed) {
- value = NSNumber.numberWithInt (OS.NSMixedState);
- } else {
- value = NSNumber.numberWithInt (item.checked ? OS.NSOnState : OS.NSOffState);
- }
- return value.id;
- }
- for (int i=0; i<columnCount; i++) {
- if (columns [i].nsColumn.id == aTableColumn) {
- return item.createString (i).id;
- }
- }
- return item.createString (0).id;
-}
-
-void tableView_setObjectValue_forTableColumn_row (int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ anObject, int /*long*/ aTableColumn, int /*long*/ rowIndex) {
- if (checkColumn != null && aTableColumn == checkColumn.id) {
- TableItem item = items [(int)/*64*/rowIndex];
- item.checked = !item.checked;
- Event event = new Event ();
- event.detail = SWT.CHECK;
- event.item = item;
- event.index = (int)/*64*/rowIndex;
- postEvent (SWT.Selection, event);
- item.redraw (-1);
- }
-}
-
-boolean tableView_shouldEditTableColumn_row (int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ aTableColumn, int /*long*/ rowIndex) {
- return false;
-}
-
-void tableView_willDisplayCell_forTableColumn_row (int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ cell, int /*long*/ tableColumn, int /*long*/ rowIndex) {
- if (checkColumn != null && tableColumn == checkColumn.id) return;
- TableItem item = items [(int)/*64*/rowIndex];
- int index = 0;
- for (int i=0; i<columnCount; i++) {
- if (columns [i].nsColumn.id == tableColumn) {
- index = i;
- break;
- }
- }
- NSTextFieldCell textCell = new NSTextFieldCell (cell);
- OS.object_setInstanceVariable(cell, Display.SWT_ROW, rowIndex);
- OS.object_setInstanceVariable(cell, Display.SWT_COLUMN, tableColumn);
- Image image = index == 0 ? item.image : (item.images == null ? null : item.images [index]);
- textCell.setImage (image != null ? image.handle : null);
- NSColor color;
- if (textCell.isEnabled()) {
- if (textCell.isHighlighted()) {
- color = NSColor.selectedControlTextColor();
- } else {
- Color foreground = item.cellForeground != null ? item.cellForeground [index] : null;
- if (foreground == null) foreground = item.foreground;
- if (foreground == null) foreground = getForegroundColor();
- color = NSColor.colorWithDeviceRed (foreground.handle [0], foreground.handle [1], foreground.handle [2], 1);
- }
- } else {
- color = NSColor.disabledControlTextColor();
- }
- int alignment = OS.NSLeftTextAlignment;
- if (columnCount > 0) {
- int style = columns [index].style;
- if ((style & SWT.CENTER) != 0) {
- alignment = OS.NSCenterTextAlignment;
- } else if ((style & SWT.RIGHT) != 0) {
- alignment = OS.NSRightTextAlignment;
- }
- }
- Font font = item.cellFont != null ? item.cellFont [index] : null;
- if (font == null) font = item.font;
- if (font == null) font = this.font;
- if (font == null) font = defaultFont ();
- if (font.extraTraits != 0) {
- NSMutableDictionary dict = ((NSMutableDictionary)new NSMutableDictionary().alloc()).initWithCapacity(5);
- dict.setObject (color, OS.NSForegroundColorAttributeName);
- dict.setObject (font.handle, OS.NSFontAttributeName);
- addTraits(dict, font);
- NSMutableParagraphStyle paragraphStyle = (NSMutableParagraphStyle)new NSMutableParagraphStyle ().alloc ().init ();
- paragraphStyle.setLineBreakMode (OS.NSLineBreakByClipping);
- paragraphStyle.setAlignment (alignment);
- dict.setObject (paragraphStyle, OS.NSParagraphStyleAttributeName);
- paragraphStyle.release ();
- NSAttributedString attribStr = ((NSAttributedString) new NSAttributedString ().alloc ()).initWithString (textCell.title(), dict);
- textCell.setAttributedStringValue(attribStr);
- attribStr.release();
- dict.release();
- } else {
- textCell.setFont(font.handle);
- textCell.setTextColor(color);
- textCell.setAlignment (alignment);
- }
-}
-
-boolean tableView_writeRowsWithIndexes_toPasteboard(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2) {
- return sendMouseEvent(NSApplication.sharedApplication().currentEvent(), SWT.DragDetect, true);
-}
-
-NSRect titleRectForBounds (int /*long*/ id, int /*long*/ sel, NSRect cellFrame) {
- NSImage image = new NSCell(id).image();
- if (image != null) {
- int imageWidth = imageBounds.width + IMAGE_GAP;
- cellFrame.x += imageWidth;
- cellFrame.width -= imageWidth;
- }
- return cellFrame;
-}
-
-void updateCursorRects (boolean enabled) {
- super.updateCursorRects (enabled);
- if (headerView == null) return;
- updateCursorRects (enabled, headerView);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TableColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TableColumn.java
deleted file mode 100755
index 8bfd6587e4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TableColumn.java
+++ /dev/null
@@ -1,677 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.cocoa.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a column in a table widget.
- * <p><dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd> Move, Resize, Selection</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT and CENTER may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TableColumn extends Item {
- Table parent;
- NSTableColumn nsColumn;
- String toolTipText, displayText;
- boolean movable;
-
- static final int MARGIN = 2;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableColumn (Table parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, parent.columnCount);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableColumn (Table parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize,typedListener);
- addListener (SWT.Move,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the column header is selected.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (nsColumn.headerCell());
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-void drawInteriorWithFrame_inView (int /*long*/ id, int /*long*/ sel, NSRect cellRect, int /*long*/ view) {
- /*
- * Feature in Cocoa. When the last column in a table does not reach the
- * rightmost edge of the table view, the cell that draws the rightmost-
- * column's header is also invoked to draw the header space between its
- * right edge and the table's right edge. If this case is detected then
- * nothing should be drawn.
- */
- int columnIndex = parent.indexOf (nsColumn);
- NSRect headerRect = parent.headerView.headerRectOfColumn (columnIndex);
- if (headerRect.x != cellRect.x || headerRect.width != cellRect.width) return;
-
- NSGraphicsContext context = NSGraphicsContext.currentContext ();
- context.saveGraphicsState ();
-
- int contentWidth = 0;
- NSSize stringSize = null, imageSize = null;
- NSAttributedString attrString = null;
- NSTableHeaderCell headerCell = nsColumn.headerCell ();
- if (displayText != null) {
- Font font = Font.cocoa_new(display, headerCell.font ());
- attrString = parent.createString(displayText, font, null, SWT.LEFT, (parent.state & DISABLED) == 0, false);
- stringSize = attrString.size ();
- contentWidth += Math.ceil (stringSize.width);
- if (image != null) contentWidth += MARGIN; /* space between image and text */
- }
- if (image != null) {
- imageSize = image.handle.size ();
- contentWidth += Math.ceil (imageSize.width);
- }
-
- if (parent.sortColumn == this && parent.sortDirection != SWT.NONE) {
- boolean ascending = parent.sortDirection == SWT.UP;
- headerCell.drawSortIndicatorWithFrame (cellRect, new NSView(view), ascending, 0);
- /* remove the arrow's space from the available drawing width */
- NSRect sortRect = headerCell.sortIndicatorRectForBounds (cellRect);
- cellRect.width = Math.max (0, sortRect.x - cellRect.x);
- }
-
- int drawX = 0;
- if ((style & SWT.CENTER) != 0) {
- drawX = (int)(cellRect.x + Math.max (MARGIN, ((cellRect.width - contentWidth) / 2)));
- } else if ((style & SWT.RIGHT) != 0) {
- drawX = (int)(cellRect.x + Math.max (MARGIN, cellRect.width - contentWidth - MARGIN));
- } else {
- drawX = (int)cellRect.x + MARGIN;
- }
-
- if (image != null) {
- NSRect destRect = new NSRect ();
- destRect.x = drawX;
- destRect.y = cellRect.y;
- destRect.width = Math.min (imageSize.width, cellRect.width - 2 * MARGIN);
- destRect.height = Math.min (imageSize.height, cellRect.height);
- boolean isFlipped = new NSView (view).isFlipped();
- if (isFlipped) {
- context.saveGraphicsState ();
- NSAffineTransform transform = NSAffineTransform.transform ();
- transform.scaleXBy (1, -1);
- transform.translateXBy (0, -(destRect.height + 2 * destRect.y));
- transform.concat ();
- }
- NSRect sourceRect = new NSRect ();
- sourceRect.width = destRect.width;
- sourceRect.height = destRect.height;
- image.handle.drawInRect (destRect, sourceRect, OS.NSCompositeSourceOver, 1f);
- if (isFlipped) context.restoreGraphicsState ();
- drawX += destRect.width;
- }
-
- if (displayText != null && displayText.length () > 0) {
- if (image != null) drawX += MARGIN; /* space between image and text */
- NSRect destRect = new NSRect ();
- destRect.x = drawX;
- destRect.y = cellRect.y;
- destRect.width = Math.min (stringSize.width, cellRect.x + cellRect.width - MARGIN - drawX);
- destRect.height = Math.min (stringSize.height, cellRect.height);
- attrString.drawInRect (destRect);
- }
- if (attrString != null) attrString.release ();
-
- context.restoreGraphicsState ();
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget ();
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Table</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Table getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Gets the moveable attribute. A column that is
- * not moveable cannot be reordered by the user
- * by dragging the header but may be reordered
- * by the programmer.
- *
- * @return the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public boolean getMoveable () {
- checkWidget ();
- return movable;
-}
-
-/**
- * Gets the resizable attribute. A column that is
- * not resizable cannot be dragged by the user but
- * may be resized by the programmer.
- *
- * @return the resizable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getResizable () {
- checkWidget ();
- return nsColumn.resizingMask() != OS.NSTableColumnNoResizing;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget ();
- int width = (int)nsColumn.width();
- // TODO how to differentiate 0 and 1 cases?
- if (width > 0) width += Table.CELL_GAP;
- return width;
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void pack () {
- checkWidget ();
-
- int width = 0;
-
- /* compute header width */
- if (displayText != null) {
- NSTableHeaderCell headerCell = nsColumn.headerCell ();
- Font font = Font.cocoa_new(display, headerCell.font ());
- NSAttributedString attrString = parent.createString(displayText, font, null, 0, true, false);
- NSSize stringSize = attrString.size ();
- attrString.release ();
- width += Math.ceil (stringSize.width);
- if (image != null) width += MARGIN; /* space between image and text */
- }
- if (image != null) {
- NSSize imageSize = image.handle.size ();
- width += Math.ceil (imageSize.width);
- }
- if (parent.sortColumn == this && parent.sortDirection != SWT.NONE) {
- NSTableHeaderCell headerCell = nsColumn.headerCell ();
- NSRect rect = new NSRect ();
- rect.width = rect.height = Float.MAX_VALUE;
- NSSize cellSize = headerCell.cellSizeForBounds (rect);
- rect.height = cellSize.height;
- NSRect sortRect = headerCell.sortIndicatorRectForBounds (rect);
- width += Math.ceil (sortRect.width);
- }
-
- /* compute item widths down column */
- GC gc = new GC (parent);
- int index = parent.indexOf (this);
- width = Math.max (width, parent.calculateWidth (parent.items, index, gc));
- gc.dispose ();
- setWidth (width);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (nsColumn != null) {
- nsColumn.headerCell ().release ();
- nsColumn.release ();
- }
- nsColumn = null;
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (parent.sortColumn == this) {
- parent.sortColumn = null;
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>.
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget ();
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- int index = parent.indexOf (this);
- if (index == -1 || index == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- NSTableView tableView = ((NSTableView) parent.view);
- NSTableHeaderView headerView = tableView.headerView ();
- if (headerView == null) return;
- index = parent.indexOf (nsColumn);
- NSRect rect = headerView.headerRectOfColumn (index);
- headerView.setNeedsDisplayInRect (rect);
- rect = tableView.rectOfColumn (index);
- parent.view.setNeedsDisplayInRect (rect);
-}
-
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- super.setImage (image);
- NSTableHeaderView headerView = ((NSTableView) parent.view).headerView ();
- if (headerView == null) return;
- int index = parent.indexOf (nsColumn);
- NSRect rect = headerView.headerRectOfColumn (index);
- headerView.setNeedsDisplayInRect (rect);
-}
-
-/**
- * Sets the moveable attribute. A column that is
- * moveable can be reordered by the user by dragging
- * the header. A column that is not moveable cannot be
- * dragged by the user but may be reordered
- * by the programmer.
- *
- * @param moveable the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setColumnOrder(int[])
- * @see Table#getColumnOrder()
- * @see TableColumn#getMoveable()
- * @see SWT#Move
- *
- * @since 3.1
- */
-public void setMoveable (boolean moveable) {
- checkWidget ();
- this.movable = moveable;
-}
-
-/**
- * Sets the resizable attribute. A column that is
- * resizable can be resized by the user dragging the
- * edge of the header. A column that is not resizable
- * cannot be dragged by the user but may be resized
- * by the programmer.
- *
- * @param resizable the resize attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setResizable (boolean resizable) {
- checkWidget ();
- nsColumn.setResizingMask (resizable ? OS.NSTableColumnUserResizingMask : OS.NSTableColumnNoResizing);
-}
-
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- char [] buffer = new char [text.length ()];
- text.getChars (0, buffer.length, buffer, 0);
- int length = fixMnemonic (buffer);
- displayText = new String (buffer, 0, length);
- NSString title = NSString.stringWith (displayText);
- nsColumn.headerCell ().setTitle (title);
- NSTableHeaderView headerView = ((NSTableView) parent.view).headerView ();
- if (headerView == null) return;
- int index = parent.indexOf (nsColumn);
- NSRect rect = headerView.headerRectOfColumn (index);
- headerView.setNeedsDisplayInRect (rect);
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
- parent.checkToolTip (this);
-}
-
-/**
- * Sets the width of the receiver.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int width) {
- checkWidget ();
- if (width < 0) return;
- // TODO how to differentiate 0 and 1 cases?
- width = Math.max (0, width - Table.CELL_GAP);
- nsColumn.setWidth (width);
-}
-
-String tooltipText () {
- return toolTipText;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TableItem.java
deleted file mode 100755
index 3711d3dfb1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TableItem.java
+++ /dev/null
@@ -1,1031 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.cocoa.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents an item in a table.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TableItem extends Item {
- Table parent;
- String [] strings;
- Image [] images;
- boolean checked, grayed, cached;
- Color foreground, background;
- Color[] cellForeground, cellBackground;
- Font font;
- Font[] cellFont;
- int width = -1;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableItem (Table parent, int style) {
- this (parent, style, checkNull (parent).getItemCount (), true);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableItem (Table parent, int style, int index) {
- this (parent, style, index, true);
-}
-
-TableItem (Table parent, int style, int index, boolean create) {
- super (parent, style);
- this.parent = parent;
- if (create) parent.createItem (this, index);
-}
-
-static Table checkNull (Table control) {
- if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return control;
-}
-
-int calculateWidth (int index, GC gc) {
- if (index == 0 && width != -1) return width;
- Font font = null;
- if (cellFont != null) font = cellFont[index];
- if (font == null) font = this.font;
- if (font == null) font = parent.font;
- if (font == null) font = parent.defaultFont();
- String text = index == 0 ? this.text : (strings == null ? "" : strings [index]);
- Image image = index == 0 ? this.image : (images == null ? null : images [index]);
- NSCell cell = parent.dataCell;
- if (font.extraTraits != 0) {
- NSAttributedString attribStr = parent.createString(text, font, null, 0, true, false);
- cell.setAttributedStringValue(attribStr);
- attribStr.release();
- } else {
- cell.setFont (font.handle);
- cell.setTitle (NSString.stringWith(text != null ? text : ""));
- }
-
- /* This code is inlined for performance */
- objc_super super_struct = new objc_super();
- super_struct.receiver = cell.id;
- super_struct.super_class = OS.objc_msgSend(cell.id, OS.sel_superclass);
- NSSize size = new NSSize();
- OS.objc_msgSendSuper_stret(size, super_struct, OS.sel_cellSize);
- if (image != null) size.width += parent.imageBounds.width + Table.IMAGE_GAP;
-// cell.setImage (image != null ? image.handle : null);
-// NSSize size = cell.cellSize ();
-
- int width = (int)Math.ceil (size.width);
- boolean sendMeasure = true;
- if ((parent.style & SWT.VIRTUAL) != 0) {
- sendMeasure = cached;
- }
- if (sendMeasure && parent.hooks (SWT.MeasureItem)) {
- gc.setFont (font);
- Event event = new Event ();
- event.item = this;
- event.index = index;
- event.gc = gc;
- NSTableView widget = (NSTableView)parent.view;
- int height = (int)widget.rowHeight ();
- event.width = width;
- event.height = height;
- parent.sendEvent (SWT.MeasureItem, event);
- if (height < event.height) {
- widget.setRowHeight (event.height);
- widget.setNeedsDisplay (true);
- }
- width = event.width;
- }
- if (index == 0) this.width = width;
- return width;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void clear () {
- text = "";
- image = null;
- strings = null;
- images = null;
- checked = grayed = cached = false;
- foreground = background = null;
- cellForeground = cellBackground = null;
- font = null;
- cellFont = null;
- width = -1;
-}
-
-NSObject createString (int index) {
- String text = index == 0 ? this.text : (strings == null ? "" : strings [index]);
- return NSString.stringWith(text != null ? text : "");
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns the receiver's background color.
- *
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public Color getBackground () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return background != null ? background : parent.getBackground ();
-}
-
-/**
- * Returns the background color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Color getBackground (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count -1) return getBackground ();
- if (cellBackground == null || cellBackground [index] == null) return getBackground ();
- return cellBackground [index];
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Rectangle getBounds () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- NSTableView tableView = (NSTableView) parent.view;
- NSRect rect = tableView.rectOfRow (parent.indexOf (this));
- return new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height);
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent at a column in the table.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding column rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (!(0 <= index && index < Math.max (1, parent.columnCount))) return new Rectangle (0, 0, 0, 0);
-
- NSTableView tableView = (NSTableView) parent.view;
- if (parent.columnCount == 0) {
- index = (parent.style & SWT.CHECK) != 0 ? 1 : 0;
- } else {
- TableColumn column = parent.getColumn (index);
- index = parent.indexOf (column.nsColumn);
- }
- NSRect rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
- return new Rectangle ((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is checked,
- * and false otherwise. When the parent does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the checked state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getChecked () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return checked;
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information for this item.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return font != null ? font : parent.getFont ();
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information
- * for the specified cell in this item.
- *
- * @param index the column index
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count -1) return getFont ();
- if (cellFont == null || cellFont [index] == null) return getFont ();
- return cellFont [index];
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public Color getForeground () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return foreground != null ? foreground : parent.getForeground ();
-}
-
-/**
- *
- * Returns the foreground color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Color getForeground (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count -1) return getForeground ();
- if (cellForeground == null || cellForeground [index] == null) return getForeground ();
- return cellForeground [index];
-}
-
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the parent does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getGrayed () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return grayed;
-}
-
-public Image getImage () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return super.getImage ();
-}
-
-/**
- * Returns the image stored at the given column index in the receiver,
- * or null if the image has not been set or if the column does not exist.
- *
- * @param index the column index
- * @return the image stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index == 0) return getImage ();
- if (images != null) {
- if (0 <= index && index < images.length) return images [index];
- }
- return null;
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of an image at a column in the
- * table. An empty rectangle is returned if index exceeds
- * the index of the table's last column.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding image rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getImageBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (!(0 <= index && index < Math.max (1, parent.columnCount))) return new Rectangle (0, 0, 0, 0);
-
- NSTableView tableView = (NSTableView) parent.view;
- Image image = index == 0 ? this.image : (images != null) ? images [index] : null;
- if (parent.columnCount == 0) {
- index = (parent.style & SWT.CHECK) != 0 ? 1 : 0;
- } else {
- TableColumn column = parent.getColumn (index);
- index = parent.indexOf (column.nsColumn);
- }
- NSRect rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
- rect.x += Table.IMAGE_GAP;
- if (image != null) {
- rect.width = parent.imageBounds.width;
- } else {
- rect.width = 0;
- }
- return new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height);
-}
-
-/**
- * Gets the image indent.
- *
- * @return the indent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getImageIndent () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return 0;
-}
-
-String getNameText () {
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (!cached) return "*virtual*"; //$NON-NLS-1$
- }
- return super.getNameText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Table</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Table getParent () {
- checkWidget ();
- return parent;
-}
-
-public String getText () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return super.getText ();
-}
-
-/**
- * Returns the text stored at the given column index in the receiver,
- * or empty string if the text has not been set.
- *
- * @param index the column index
- * @return the text stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index == 0) return getText ();
- if (strings != null) {
- if (0 <= index && index < strings.length) {
- String string = strings [index];
- return string != null ? string : "";
- }
- }
- return "";
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of the text at a column in the
- * table. An empty rectangle is returned if index exceeds
- * the index of the table's last column.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding text rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Rectangle getTextBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (!(0 <= index && index < Math.max (1, parent.columnCount))) return new Rectangle (0, 0, 0, 0);
-
- NSTableView tableView = (NSTableView) parent.view;
- Image image = index == 0 ? this.image : (images != null) ? images [index] : null;
- if (parent.columnCount == 0) {
- index = (parent.style & SWT.CHECK) != 0 ? 1 : 0;
- } else {
- TableColumn column = parent.getColumn (index);
- index = parent.indexOf (column.nsColumn);
- }
- NSRect rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
- rect.x += Table.TEXT_GAP;
- rect.width -= Table.TEXT_GAP;
- if (image != null) {
- int offset = parent.imageBounds.width + Table.IMAGE_GAP;
- rect.x += offset;
- rect.width -= offset;
- }
- return new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height);
-}
-
-void redraw (int columnIndex) {
- if (parent.currentItem == this || !isDrawing()) return;
- /* redraw the full item if columnIndex == -1 */
- NSTableView tableView = (NSTableView) parent.view;
- NSRect rect = null;
- if (columnIndex == -1 || parent.hooks (SWT.MeasureItem) || parent.hooks (SWT.EraseItem) || parent.hooks (SWT.PaintItem)) {
- rect = tableView.rectOfRow (parent.indexOf (this));
- } else {
- int index;
- if (parent.columnCount == 0) {
- index = (parent.style & SWT.CHECK) != 0 ? 1 : 0;
- } else {
- if (0 <= columnIndex && columnIndex < parent.columnCount) {
- index = parent.indexOf (parent.columns[columnIndex].nsColumn);
- } else {
- return;
- }
- }
- rect = tableView.frameOfCellAtColumn (index, parent.indexOf (this));
- }
- tableView.setNeedsDisplayInRect (rect);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
-// parent.checkItems (true);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- strings = null;
- images = null;
- background = foreground = null;
- font = null;
- cellBackground = cellForeground = null;
- cellFont = null;
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setBackground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Color oldColor = background;
- if (oldColor == color) return;
- background = color;
- if (oldColor != null && oldColor.equals (color)) return;
- cached = true;
- redraw (-1);
-}
-
-/**
- * Sets the background color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setBackground (int index, Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count - 1) return;
- if (cellBackground == null) {
- if (color == null) return;
- cellBackground = new Color [count];
- }
- Color oldColor = cellBackground [index];
- if (oldColor == color) return;
- cellBackground [index] = color;
- if (oldColor != null && oldColor.equals (color)) return;
- cached = true;
- redraw (index);
-}
-
-/**
- * Sets the checked state of the checkbox for this item. This state change
- * only applies if the Table was created with the SWT.CHECK style.
- *
- * @param checked the new checked state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setChecked (boolean checked) {
- checkWidget ();
- if ((parent.style & SWT.CHECK) == 0) return;
- if (this.checked == checked) return;
- this.checked = checked;
- cached = true;
- redraw (-1);
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for this item to the font specified by the argument, or to the default font
- * for that kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (Font font) {
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Font oldFont = this.font;
- if (oldFont == font) return;
- this.font = font;
- if (oldFont != null && oldFont.equals (font)) return;
- width = -1;
- cached = true;
- redraw (-1);
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for the specified cell in this item to the font specified by the
- * argument, or to the default font for that kind of control if the
- * argument is null.
- *
- * @param index the column index
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (int index, Font font) {
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count - 1) return;
- if (cellFont == null) {
- if (font == null) return;
- cellFont = new Font [count];
- }
- Font oldFont = cellFont [index];
- if (oldFont == font) return;
- cellFont [index] = font;
- if (oldFont != null && oldFont.equals (font)) return;
- width = -1;
- cached = true;
- redraw (index);
-}
-
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setForeground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Color oldColor = foreground;
- if (oldColor == color) return;
- foreground = color;
- if (oldColor != null && oldColor.equals (color)) return;
- cached = true;
- redraw (-1);
-}
-
-/**
- * Sets the foreground color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setForeground (int index, Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count - 1) return;
- if (cellForeground == null) {
- if (color == null) return;
- cellForeground = new Color [count];
- }
- Color oldColor = cellForeground [index];
- if (oldColor == color) return;
- cellForeground [index] = color;
- if (oldColor != null && oldColor.equals (color)) return;
- cached = true;
- redraw (index);
-}
-
-/**
- * Sets the grayed state of the checkbox for this item. This state change
- * only applies if the Table was created with the SWT.CHECK style.
- *
- * @param grayed the new grayed state of the checkbox;
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setGrayed (boolean grayed) {
- checkWidget ();
- if ((parent.style & SWT.CHECK) == 0) return;
- if (this.grayed == grayed) return;
- this.grayed = grayed;
- cached = true;
- redraw (-1);
-}
-
-/**
- * Sets the image for multiple columns in the table.
- *
- * @param images the array of new images
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image [] images) {
- checkWidget ();
- if (images == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<images.length; i++) {
- setImage (i, images [i]);
- }
-}
-
-/**
- * Sets the receiver's image at a column.
- *
- * @param index the column index
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (int index, Image image) {
- checkWidget ();
- if (image != null && image.isDisposed ()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int itemIndex = parent.indexOf (this);
- if (itemIndex == -1) return;
- if (parent.imageBounds == null && image != null) {
- parent.setItemHeight (image, null, false);
- }
- if (index == 0) {
- if (image != null && image.type == SWT.ICON) {
- if (image.equals (this.image)) return;
- }
- width = -1;
- super.setImage (image);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 <= index && index < count) {
- if (images == null) images = new Image [count];
- if (image != null && image.type == SWT.ICON) {
- if (image.equals (images [index])) return;
- }
- images [index] = image;
- }
- cached = true;
- if (index == 0) parent.setScrollWidth (this);
- redraw (index);
-}
-
-public void setImage (Image image) {
- checkWidget ();
- setImage (0, image);
-}
-
-/**
- * Sets the indent of the first column's image, expressed in terms of the image's width.
- *
- * @param indent the new indent
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @deprecated this functionality is not supported on most platforms
- */
-public void setImageIndent (int indent) {
- checkWidget ();
- if (indent < 0) return;
- cached = true;
- /* Image indent is not supported on the Macintosh */
-}
-
-/**
- * Sets the text for multiple columns in the table.
- *
- * @param strings the array of new strings
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String [] strings) {
- checkWidget ();
- if (strings == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<strings.length; i++) {
- String string = strings [i];
- if (string != null) setText (i, string);
- }
-}
-
-/**
- * Sets the receiver's text at a column
- *
- * @param index the column index
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (int index, String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (index == 0) {
- if (string.equals (text)) return;
- width = -1;
- super.setText (string);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 <= index && index < count) {
- if (strings == null) strings = new String [count];
- if (string.equals (strings [index])) return;
- strings [index] = string;
- }
- cached = true;
- if (index == 0) parent.setScrollWidth (this);
- redraw (index);
-}
-
-public void setText (String string) {
- checkWidget ();
- setText (0, string);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java
deleted file mode 100755
index b7876ed9bf..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java
+++ /dev/null
@@ -1,1983 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify text.
- * Text controls can be either single or multi-line.
- * When a text control is created with a border, the
- * operating system includes a platform specific inset
- * around the contents of the control. When created
- * without a border, an effort is made to remove the
- * inset such that the preferred size of the control
- * is the same size as the contents.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>CENTER, ICON_CANCEL, ICON_SEARCH, LEFT, MULTI, PASSWORD, SEARCH, SINGLE, RIGHT, READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Modify, Verify</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles MULTI and SINGLE may be specified,
- * and only one of the styles LEFT, CENTER, and RIGHT may be specified.
- * </p>
- * <p>
- * Note: The styles ICON_CANCEL and ICON_SEARCH are hints used in combination with SEARCH.
- * When the platform supports the hint, the text control shows these icons. When an icon
- * is selected, a default selection event is sent with the detail field set to one of
- * ICON_CANCEL or ICON_SEARCH. Normally, application code does not need to check the
- * detail. In the case of ICON_CANCEL, the text is cleared before the default selection
- * event is sent causing the application to search for an empty string.
- * </p>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#text">Text snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Text extends Scrollable {
- int textLimit = LIMIT, tabs = 8;
- char echoCharacter;
- boolean doubleClick, receivingFocus;
- String hiddenText, message;
- NSRange selectionRange;
- id targetSearch, targetCancel;
- int /*long*/ actionSearch, actionCancel;
-
- /**
- * The maximum number of characters that can be entered
- * into a text widget.
- * <p>
- * Note that this value is platform dependent, based upon
- * the native widget implementation.
- * </p>
- */
- public static final int LIMIT;
-
- /**
- * The delimiter used by multi-line text widgets. When text
- * is queried and from the widget, it will be delimited using
- * this delimiter.
- */
- public static final String DELIMITER;
- static final char PASSWORD = '\u2022';
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0x7FFFFFFF;
- DELIMITER = "\r";
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#READ_ONLY
- * @see SWT#WRAP
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see SWT#PASSWORD
- * @see SWT#SEARCH
- * @see SWT#ICON_SEARCH
- * @see SWT#ICON_CANCEL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Text (Composite parent, int style) {
- super (parent, checkStyle (style));
- if ((style & SWT.SEARCH) != 0) {
- /*
- * Ensure that SWT.ICON_CANCEL and ICON_SEARCH are set.
- * NOTE: ICON_CANCEL has the same value as H_SCROLL and
- * ICON_SEARCH has the same value as V_SCROLL so it is
- * necessary to first clear these bits to avoid a scroll
- * bar and then reset the bit using the original style
- * supplied by the programmer.
- */
- NSSearchFieldCell cell = new NSSearchFieldCell (((NSSearchField) view).cell ());
- if ((style & SWT.ICON_CANCEL) != 0) {
- this.style |= SWT.ICON_CANCEL;
- NSButtonCell cancelCell = cell.cancelButtonCell();
- targetCancel = cancelCell.target();
- actionCancel = cancelCell.action();
- cancelCell.setTarget (view);
- cancelCell.setAction (OS.sel_sendCancelSelection);
- } else {
- cell.setCancelButtonCell (null);
- }
- if ((style & SWT.ICON_SEARCH) != 0) {
- this.style |= SWT.ICON_SEARCH;
- NSButtonCell searchCell = cell.searchButtonCell();
- targetSearch = searchCell.target();
- actionSearch = searchCell.action();
- searchCell.setTarget (view);
- searchCell.setAction (OS.sel_sendSearchSelection);
- } else {
- cell.setSearchButtonCell (null);
- }
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is not called for texts.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text,
- * or when ENTER is pressed in a search text. If the receiver has the <code>SWT.SEARCH | SWT.CANCEL</code> style
- * and the user cancels the search, the event object detail field contains the value <code>SWT.CANCEL</code>.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- */
-public void addVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-
-/**
- * Appends a string.
- * <p>
- * The new text is appended to the text at
- * the end of the widget.
- * </p>
- *
- * @param string the string to be appended
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void append (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- int charCount = getCharCount ();
- string = verifyText (string, charCount, charCount, null);
- if (string == null) return;
- }
- NSString str = NSString.stringWith (string);
- if ((style & SWT.SINGLE) != 0) {
- setSelection (getCharCount ());
- insertEditText (string);
- } else {
- NSTextView widget = (NSTextView) view;
- NSTextStorage storage = widget.textStorage ();
- NSRange range = new NSRange();
- range.location = storage.length();
- storage.replaceCharactersInRange (range, str);
- range.location = storage.length();
- widget.scrollRangeToVisible (range);
- widget.setSelectedRange(range);
- }
- if (string.length () != 0) sendEvent (SWT.Modify);
-}
-
-boolean becomeFirstResponder (int /*long*/ id, int /*long*/ sel) {
- receivingFocus = true;
- boolean result = super.becomeFirstResponder (id, sel);
- receivingFocus = false;
- return result;
-}
-
-static int checkStyle (int style) {
- if ((style & SWT.SEARCH) != 0) {
- style |= SWT.SINGLE | SWT.BORDER;
- style &= ~SWT.PASSWORD;
- /*
- * NOTE: ICON_CANCEL has the same value as H_SCROLL and
- * ICON_SEARCH has the same value as V_SCROLL so they are
- * cleared because SWT.SINGLE is set.
- */
- }
- if ((style & SWT.SINGLE) != 0 && (style & SWT.MULTI) != 0) {
- style &= ~SWT.MULTI;
- }
- style = checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
- if ((style & SWT.SINGLE) != 0) style &= ~(SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP);
- if ((style & SWT.WRAP) != 0) {
- style |= SWT.MULTI;
- style &= ~SWT.H_SCROLL;
- }
- if ((style & SWT.MULTI) != 0) style &= ~SWT.PASSWORD;
- if ((style & (SWT.SINGLE | SWT.MULTI)) != 0) return style;
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) return style | SWT.MULTI;
- return style | SWT.SINGLE;
-}
-
-/**
- * Clears the selection.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void clearSelection () {
- checkWidget ();
- Point selection = getSelection ();
- setSelection (selection.x);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0;
- if ((style & SWT.SINGLE) != 0) {
- NSTextField widget = (NSTextField) view;
- NSSize size = widget.cell ().cellSize ();
- width = (int)Math.ceil (size.width);
- height = (int)Math.ceil (size.height);
-
- Point border = null;
- if ((style & SWT.BORDER) != 0 && (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT)) {
- /* determine the size of the cell without its border */
- NSRect insets = widget.cell ().titleRectForBounds (new NSRect ());
- border = new Point (-(int)Math.ceil (insets.width), -(int)Math.ceil (insets.height));
- width -= border.x;
- height -= border.y;
- }
- if (width <= 0) width = DEFAULT_WIDTH;
- if (height <= 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- if (border != null) {
- /* re-add the border size (if any) now that wHint/hHint is taken */
- width += border.x;
- height += border.y;
- }
- } else {
- NSLayoutManager layoutManager = (NSLayoutManager)new NSLayoutManager ().alloc ().init ();
- NSTextContainer textContainer = (NSTextContainer)new NSTextContainer ().alloc ();
- NSSize size = new NSSize ();
- size.width = size.height = Float.MAX_VALUE;
- if ((style & SWT.WRAP) != 0) {
- if (wHint != SWT.DEFAULT) size.width = wHint;
- if (hHint != SWT.DEFAULT) size.height = hHint;
- }
- textContainer.initWithContainerSize (size);
- layoutManager.addTextContainer (textContainer);
-
- NSTextStorage textStorage = (NSTextStorage)new NSTextStorage ().alloc ().init ();
- textStorage.setAttributedString (((NSTextView)view).textStorage ());
- layoutManager.setTextStorage (textStorage);
- layoutManager.glyphRangeForTextContainer (textContainer);
-
- NSRect rect = layoutManager.usedRectForTextContainer (textContainer);
- width = layoutManager.numberOfGlyphs () == 0 ? DEFAULT_WIDTH : (int)Math.ceil (rect.width);
- height = (int)Math.ceil (rect.height);
- textStorage.release ();
- textContainer.release ();
- layoutManager.release ();
-
- if (width <= 0) width = DEFAULT_WIDTH;
- if (height <= 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- Rectangle trim = computeTrim (0, 0, width, height);
- width = trim.width;
- height = trim.height;
- }
- return new Point (width, height);
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- Rectangle result = super.computeTrim (x, y, width, height);
- if ((style & SWT.SINGLE) != 0) {
- NSTextField widget = (NSTextField) view;
- if ((style & SWT.SEARCH) != 0) {
- NSSearchFieldCell cell = new NSSearchFieldCell (widget.cell ());
- int testWidth = 100;
- NSRect rect = new NSRect ();
- rect.width = testWidth;
- rect = cell.searchTextRectForBounds (rect);
- int leftIndent = (int)rect.x;
- int rightIndent = testWidth - leftIndent - (int)Math.ceil (rect.width);
- result.x -= leftIndent;
- result.width += leftIndent + rightIndent;
- }
- NSRect inset = widget.cell ().titleRectForBounds (new NSRect ());
- result.x -= inset.x;
- result.y -= inset.y;
- result.width -= inset.width;
- result.height -= inset.height;
- }
- return result;
-}
-
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void copy () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- Point selection = getSelection ();
- if (selection.x == selection.y) return;
- copyToClipboard (getEditText (selection.x, selection.y - 1));
- } else {
- NSText text = (NSText) view;
- if (text.selectedRange ().length == 0) return;
- text.copy (null);
- }
-}
-
-void createHandle () {
- if ((style & SWT.READ_ONLY) != 0) {
- if ((style & (SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
- state |= THEME_BACKGROUND;
- }
- }
- if ((style & SWT.SINGLE) != 0) {
- NSTextField widget;
- if ((style & SWT.PASSWORD) != 0) {
- widget = (NSTextField) new SWTSecureTextField ().alloc ();
- } else if ((style & SWT.SEARCH) != 0) {
- widget = (NSTextField) new SWTSearchField ().alloc ();
- } else {
- widget = (NSTextField) new SWTTextField ().alloc ();
- }
- widget.init ();
- widget.setSelectable (true);
- widget.setEditable((style & SWT.READ_ONLY) == 0);
- if ((style & SWT.BORDER) == 0) {
- widget.setFocusRingType (OS.NSFocusRingTypeNone);
- widget.setBordered (false);
- }
- int align = OS.NSLeftTextAlignment;
- if ((style & SWT.CENTER) != 0) align = OS.NSCenterTextAlignment;
- if ((style & SWT.RIGHT) != 0) align = OS.NSRightTextAlignment;
- widget.setAlignment (align);
- NSCell cell = widget.cell();
- cell.setWraps(false);
- cell.setScrollable(true);
-// widget.setTarget(widget);
-// widget.setAction(OS.sel_sendSelection);
- view = widget;
- } else {
- NSScrollView scrollWidget = (NSScrollView) new SWTScrollView ().alloc ();
- scrollWidget.init ();
- scrollWidget.setHasVerticalScroller ((style & SWT.VERTICAL) != 0);
- scrollWidget.setHasHorizontalScroller ((style & SWT.HORIZONTAL) != 0);
- scrollWidget.setAutoresizesSubviews (true);
- if ((style & SWT.BORDER) != 0) scrollWidget.setBorderType (OS.NSBezelBorder);
-
- NSTextView widget = (NSTextView) new SWTTextView ().alloc ();
- widget.init ();
- widget.setEditable ((style & SWT.READ_ONLY) == 0);
-
- NSSize size = new NSSize ();
- size.width = size.height = Float.MAX_VALUE;
- widget.setMaxSize (size);
- widget.setAutoresizingMask (OS.NSViewWidthSizable | OS.NSViewHeightSizable);
-
- if ((style & SWT.WRAP) == 0) {
- NSTextContainer textContainer = widget.textContainer ();
- widget.setHorizontallyResizable (true);
- textContainer.setWidthTracksTextView (false);
- NSSize csize = new NSSize ();
- csize.width = csize.height = Float.MAX_VALUE;
- textContainer.setContainerSize (csize);
- }
-
- int align = OS.NSLeftTextAlignment;
- if ((style & SWT.CENTER) != 0) align = OS.NSCenterTextAlignment;
- if ((style & SWT.RIGHT) != 0) align = OS.NSRightTextAlignment;
- widget.setAlignment (align);
-// widget.setTarget(widget);
-// widget.setAction(OS.sel_sendSelection);
- widget.setRichText (false);
- widget.setDelegate(widget);
- widget.setFont (display.getSystemFont ().handle);
-
- view = widget;
- scrollView = scrollWidget;
- }
-}
-
-void createWidget () {
- super.createWidget ();
- doubleClick = true;
- message = "";
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void cut () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- boolean cut = true;
- char [] oldText = null;
- Point oldSelection = getSelection ();
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- if (oldSelection.x != oldSelection.y) {
- oldText = getEditText (oldSelection.x, oldSelection.y - 1);
- String newText = verifyText ("", oldSelection.x, oldSelection.y, null);
- if (newText == null) return;
- if (newText.length () != 0) {
- copyToClipboard (oldText);
- if ((style & SWT.SINGLE) != 0) {
- insertEditText (newText);
- } else {
- NSTextView widget = (NSTextView) view;
- widget.replaceCharactersInRange (widget.selectedRange (), NSString.stringWith (newText));
- }
- cut = false;
- }
- }
- }
- if (cut) {
- if ((style & SWT.SINGLE) != 0) {
- if (oldText == null) oldText = getEditText (oldSelection.x, oldSelection.y - 1);
- copyToClipboard (oldText);
- insertEditText ("");
- } else {
- ((NSTextView) view).cut (null);
- }
- }
- Point newSelection = getSelection ();
- if (!cut || !oldSelection.equals (newSelection)) sendEvent (SWT.Modify);
-}
-
-Color defaultBackground () {
- return display.getWidgetColor (SWT.COLOR_LIST_BACKGROUND);
-}
-
-NSFont defaultNSFont () {
- if ((style & SWT.MULTI) != 0) return display.textViewFont;
- if ((style & SWT.SEARCH) != 0) return display.searchFieldFont;
- if ((style & SWT.PASSWORD) != 0) return display.secureTextFieldFont;
- return display.textFieldFont;
-}
-
-Color defaultForeground () {
- return display.getWidgetColor (SWT.COLOR_LIST_FOREGROUND);
-}
-
-void deregister() {
- super.deregister();
-
- if ((style & SWT.SINGLE) != 0) {
- display.removeWidget(((NSControl)view).cell());
- }
-}
-
-boolean dragDetect (int x, int y, boolean filter, boolean [] consume) {
- Point selection = getSelection ();
- if (selection.x != selection.y) {
- int /*long*/ position = getPosition (x, y);
- if (selection.x <= position && position < selection.y) {
- if (super.dragDetect (x, y, filter, consume)) {
- if (consume != null) consume [0] = true;
- return true;
- }
- }
- }
- return false;
-}
-
-/**
- * Returns the line number of the caret.
- * <p>
- * The line number of the caret is returned.
- * </p>
- *
- * @return the line number
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretLineNumber () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return 0;
- return (getTopPixel () + getCaretLocation ().y) / getLineHeight ();
-}
-
-boolean acceptsFirstResponder(int /*long*/ id, int /*long*/ sel) {
- if ((style & SWT.READ_ONLY) != 0) return true;
- return super.acceptsFirstResponder(id, sel);
-}
-
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null).
- * <p>
- * The location of the caret is returned.
- * </p>
- *
- * @return a point, the location of the caret
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getCaretLocation () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- //TODO - caret location for single text
- return new Point (0, 0);
- }
- NSTextView widget = (NSTextView)view;
- NSLayoutManager layoutManager = widget.layoutManager();
- NSTextContainer container = widget.textContainer();
- NSRange range = widget.selectedRange();
- int /*long*/ pRectCount = OS.malloc(C.PTR_SIZEOF);
- int /*long*/ pArray = layoutManager.rectArrayForCharacterRange(range, range, container, pRectCount);
- int /*long*/ [] rectCount = new int /*long*/ [1];
- OS.memmove(rectCount, pRectCount, C.PTR_SIZEOF);
- OS.free(pRectCount);
- NSRect rect = new NSRect();
- if (rectCount[0] > 0) OS.memmove(rect, pArray, NSRect.sizeof);
- return new Point((int)rect.x, (int)rect.y);
-}
-
-/**
- * Returns the character position of the caret.
- * <p>
- * Indexing is zero based.
- * </p>
- *
- * @return the position of the caret
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretPosition () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- return selectionRange != null ? (int)/*64*/selectionRange.location : 0;
- } else {
- NSRange range = ((NSTextView)view).selectedRange();
- return (int)/*64*/range.location;
- }
-}
-
-/**
- * Returns the number of characters.
- *
- * @return number of characters in the widget
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCharCount () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- return (int)/*64*/new NSCell (((NSControl) view).cell ()).title ().length ();
- } else {
- return (int)/*64*/((NSTextView) view).textStorage ().length ();
- }
-}
-
-/**
- * Returns the double click enabled flag.
- * <p>
- * The double click flag enables or disables the
- * default action of the text widget when the user
- * double clicks.
- * </p>
- *
- * @return whether or not double click is enabled
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getDoubleClickEnabled () {
- checkWidget ();
- return doubleClick;
-}
-
-/**
- * Returns the echo character.
- * <p>
- * The echo character is the character that is
- * displayed when the user enters text or the
- * text is changed by the programmer.
- * </p>
- *
- * @return the echo character
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setEchoChar
- */
-public char getEchoChar () {
- checkWidget ();
- return echoCharacter;
-}
-
-/**
- * Returns the editable state.
- *
- * @return whether or not the receiver is editable
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getEditable () {
- checkWidget ();
- return (style & SWT.READ_ONLY) == 0;
-}
-
-char [] getEditText () {
- NSString str = null;
- if ((style & SWT.SINGLE) != 0) {
- str = new NSTextFieldCell (((NSTextField) view).cell ()).title ();
- } else {
- str = ((NSTextView)view).textStorage().string();
- }
-
- int length = (int)/*64*/str.length ();
- char [] buffer = new char [length];
- if (hiddenText != null) {
- hiddenText.getChars (0, length, buffer, 0);
- } else {
- NSRange range = new NSRange ();
- range.length = length;
- str.getCharacters (buffer, range);
- }
- return buffer;
-}
-
-char [] getEditText (int start, int end) {
- NSString str = null;
- if ((style & SWT.SINGLE) != 0) {
- str = new NSTextFieldCell (((NSTextField) view).cell ()).title ();
- } else {
- str = ((NSTextView)view).textStorage().string();
- }
-
- int length = (int)/*64*/str.length ();
- end = Math.min (end, length - 1);
- if (start > end) return new char [0];
- start = Math.max (0, start);
- NSRange range = new NSRange ();
- range.location = start;
- range.length = Math.max (0, end - start + 1);
- char [] buffer = new char [(int)/*64*/range.length];
- if (hiddenText != null) {
- hiddenText.getChars ((int)/*64*/range.location, (int)/*64*/(range.location + range.length), buffer, 0);
- } else {
- str.getCharacters (buffer, range);
- }
- return buffer;
-}
-
-/**
- * Returns the number of lines.
- *
- * @return the number of lines in the widget
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getLineCount () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return 1;
- NSTextStorage storage = ((NSTextView) view).textStorage ();
- int count = (int)/*64*/storage.paragraphs ().count ();
- NSString string = storage.string();
- int /*long*/ length = string.length(), c;
- if (length == 0 || (c = string.characterAtIndex(length - 1)) == '\n' || c == '\r') {
- count++;
- }
- return count;
-}
-
-/**
- * Returns the line delimiter.
- *
- * @return a string that is the line delimiter
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #DELIMITER
- */
-public String getLineDelimiter () {
- checkWidget ();
- return DELIMITER;
-}
-
-/**
- * Returns the height of a line.
- *
- * @return the height of a row of text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getLineHeight () {
- checkWidget ();
- Font font = this.font != null ? this.font : defaultFont();
- if ((style & SWT.SINGLE) != 0) {
- NSDictionary dict = NSDictionary.dictionaryWithObject(font.handle, OS.NSFontAttributeName);
- NSString str = NSString.stringWith(" ");
- NSAttributedString attribStr = ((NSAttributedString)new NSAttributedString().alloc()).initWithString(str, dict);
- NSSize size = attribStr.size();
- attribStr.release();
- return (int) size.height;
- } else {
- NSTextView widget = (NSTextView)view;
- return (int)Math.ceil(widget.layoutManager().defaultLineHeightForFont(font.handle));
- }
-}
-
-/**
- * Returns the orientation of the receiver, which will be one of the
- * constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getOrientation () {
- checkWidget ();
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-/**
- * Returns the widget message. The message text is displayed
- * as a hint for the user, indicating the purpose of the field.
- * <p>
- * Typically this is used in conjunction with <code>SWT.SEARCH</code>.
- * </p>
- *
- * @return the widget message
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public String getMessage () {
- checkWidget ();
- return message;
-}
-
-int /*long*/ getPosition (int /*long*/ x, int /*long*/ y) {
-// checkWidget ();
- if ((style & SWT.MULTI) != 0) {
- NSTextView widget = (NSTextView) view;
- NSPoint viewLocation = new NSPoint();
- viewLocation.x = x;
- viewLocation.y = y;
- return widget.characterIndexForInsertionAtPoint(viewLocation);
- } else {
- //TODO
- return 0;
- }
-}
-
-/**
- * Returns a <code>Point</code> whose x coordinate is the
- * character position representing the start of the selected
- * text, and whose y coordinate is the character position
- * representing the end of the selection. An "empty" selection
- * is indicated by the x and y coordinates having the same value.
- * <p>
- * Indexing is zero based. The range of a selection is from
- * 0..N where N is the number of characters in the widget.
- * </p>
- *
- * @return a point representing the selection start and end
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSelection () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- if (selectionRange == null) {
- NSString str = new NSTextFieldCell (((NSTextField) view).cell ()).title ();
- return new Point((int)/*64*/str.length (), (int)/*64*/str.length ());
- }
- return new Point ((int)/*64*/selectionRange.location, (int)/*64*/(selectionRange.location + selectionRange.length));
- } else {
- NSTextView widget = (NSTextView) view;
- NSRange range = widget.selectedRange ();
- return new Point ((int)/*64*/range.location, (int)/*64*/(range.location + range.length));
- }
-}
-
-/**
- * Returns the number of selected characters.
- *
- * @return the number of selected characters.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- return selectionRange != null ? (int)/*64*/selectionRange.length : 0;
- } else {
- NSTextView widget = (NSTextView) view;
- NSRange range = widget.selectedRange ();
- return (int)/*64*/range.length;
- }
-}
-
-/**
- * Gets the selected text, or an empty string if there is no current selection.
- *
- * @return the selected text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getSelectionText () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- Point selection = getSelection ();
- if (selection.x == selection.y) return "";
- return new String (getEditText (selection.x, selection.y - 1));
- } else {
- NSTextView widget = (NSTextView) view;
- NSRange range = widget.selectedRange ();
- NSString str = widget.textStorage ().string ();
- char[] buffer = new char [(int)/*64*/range.length];
- str.getCharacters (buffer, range);
- return new String (buffer);
- }
-}
-
-/**
- * Returns the number of tabs.
- * <p>
- * Tab stop spacing is specified in terms of the
- * space (' ') character. The width of a single
- * tab stop is the pixel width of the spaces.
- * </p>
- *
- * @return the number of tab characters
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTabs () {
- checkWidget ();
- return tabs;
-}
-
-/**
- * Returns the widget text.
- * <p>
- * The text for a text widget is the characters in the widget, or
- * an empty string if this has never been set.
- * </p>
- *
- * @return the widget text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- NSString str;
- if ((style & SWT.SINGLE) != 0) {
- return new String (getEditText ());
- } else {
- str = ((NSTextView)view).textStorage ().string ();
- }
- return str.getString();
-}
-
-/**
- * Returns a range of text. Returns an empty string if the
- * start of the range is greater than the end.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N-1 where N is
- * the number of characters in the widget.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- * @return the range of text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText (int start, int end) {
- checkWidget ();
- if (!(start <= end && 0 <= end)) return ""; //$NON-NLS-1$
- if ((style & SWT.SINGLE) != 0) {
- return new String (getEditText (start, end));
- }
- NSTextStorage storage = ((NSTextView) view).textStorage ();
- end = Math.min (end, (int)/*64*/storage.length () - 1);
- if (start > end) return ""; //$NON-NLS-1$
- start = Math.max (0, start);
- NSRange range = new NSRange ();
- range.location = start;
- range.length = end - start + 1;
- NSAttributedString substring = storage.attributedSubstringFromRange (range);
- NSString string = substring.string ();
- return string.getString();
-}
-
-/**
- * Returns the maximum number of characters that the receiver is capable of holding.
- * <p>
- * If this has not been changed by <code>setTextLimit()</code>,
- * it will be the constant <code>Text.LIMIT</code>.
- * </p>
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public int getTextLimit () {
- checkWidget ();
- return textLimit;
-}
-
-/**
- * Returns the zero-relative index of the line which is currently
- * at the top of the receiver.
- * <p>
- * This index can change when lines are scrolled or new lines are added or removed.
- * </p>
- *
- * @return the index of the top line
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return 0;
- return getTopPixel () / getLineHeight ();
-}
-
-/**
- * Returns the top pixel.
- * <p>
- * The top pixel is the pixel position of the line
- * that is currently at the top of the widget. On
- * some platforms, a text widget can be scrolled by
- * pixels instead of lines so that a partial line
- * is displayed at the top of the widget.
- * </p><p>
- * The top pixel changes when the widget is scrolled.
- * The top pixel does not include the widget trimming.
- * </p>
- *
- * @return the pixel position of the top line
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopPixel () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return 0;
- return (int)scrollView.contentView().bounds().y;
-}
-
-/**
- * Inserts a string.
- * <p>
- * The old selection is replaced with the new text.
- * </p>
- *
- * @param string the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is <code>null</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void insert (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- Point selection = getSelection ();
- string = verifyText (string, selection.x, selection.y, null);
- if (string == null) return;
- }
- if ((style & SWT.SINGLE) != 0) {
- insertEditText (string);
- } else {
- NSString str = NSString.stringWith (string);
- NSTextView widget = (NSTextView) view;
- NSRange range = widget.selectedRange ();
- widget.textStorage ().replaceCharactersInRange (range, str);
- }
- if (string.length () != 0) sendEvent (SWT.Modify);
-}
-
-void insertEditText (String string) {
- int length = string.length ();
- Point selection = getSelection ();
- if (hasFocus () && hiddenText == null) {
- if (textLimit != LIMIT) {
- int charCount = getCharCount();
- if (charCount - (selection.y - selection.x) + length > textLimit) {
- length = textLimit - charCount + (selection.y - selection.x);
- }
- }
- char [] buffer = new char [length];
- string.getChars (0, buffer.length, buffer, 0);
- NSString nsstring = NSString.stringWithCharacters (buffer, buffer.length);
- NSText fieldEditor = ((NSTextField) view).currentEditor ();
- if (fieldEditor != null) fieldEditor.replaceCharactersInRange (fieldEditor.selectedRange (), nsstring);
- selectionRange = null;
- } else {
- String oldText = getText ();
- if (textLimit != LIMIT) {
- int charCount = oldText.length ();
- if (charCount - (selection.y - selection.x) + length > textLimit) {
- string = string.substring(0, textLimit - charCount + (selection.y - selection.x));
- }
- }
- String newText = oldText.substring (0, selection.x) + string + oldText.substring (selection.y);
- setEditText (newText);
- setSelection (selection.x + string.length ());
- }
-}
-
-boolean isEventView (int /*long*/ id) {
- if ((style & SWT.MULTI) != 0) return super.isEventView (id);
- return true;
-}
-
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void paste () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- boolean paste = true;
- String oldText = null;
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- oldText = getClipboardText ();
- if (oldText != null) {
- Point selection = getSelection ();
- String newText = verifyText (oldText, selection.x, selection.y, null);
- if (newText == null) return;
- if (!newText.equals (oldText)) {
- if ((style & SWT.SINGLE) != 0) {
- insertEditText (newText);
- } else {
- NSTextView textView = (NSTextView) view;
- textView.replaceCharactersInRange (textView.selectedRange (), NSString.stringWith (newText));
- }
- paste = false;
- }
- }
- }
- if (paste) {
- if ((style & SWT.SINGLE) != 0) {
- if (oldText == null) oldText = getClipboardText ();
- if (oldText == null) return;
- insertEditText (oldText);
- } else {
- //TODO check text limit
- ((NSTextView) view).paste (null);
- }
- }
- sendEvent (SWT.Modify);
-}
-
-void register() {
- super.register();
-
- if ((style & SWT.SINGLE) != 0) {
- display.addWidget(((NSControl)view).cell(), this);
- }
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if ((style & SWT.SINGLE) != 0) ((NSControl)view).abortEditing();
- hiddenText = message = null;
- selectionRange = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- */
-public void removeVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-
-/**
- * Selects all the text in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- setSelection (0, getCharCount ());
- } else {
- ((NSTextView) view).selectAll (null);
- }
-}
-
-boolean sendKeyEvent (NSEvent nsEvent, int type) {
- boolean result = super.sendKeyEvent (nsEvent, type);
- if (!result) return result;
- if (type != SWT.KeyDown) return result;
- int stateMask = 0;
- int /*long*/ modifierFlags = nsEvent.modifierFlags();
- if ((modifierFlags & OS.NSAlternateKeyMask) != 0) stateMask |= SWT.ALT;
- if ((modifierFlags & OS.NSShiftKeyMask) != 0) stateMask |= SWT.SHIFT;
- if ((modifierFlags & OS.NSControlKeyMask) != 0) stateMask |= SWT.CONTROL;
- if ((modifierFlags & OS.NSCommandKeyMask) != 0) stateMask |= SWT.COMMAND;
- if (stateMask == SWT.COMMAND) {
- short keyCode = nsEvent.keyCode ();
- switch (keyCode) {
- case 7: /* X */
- cut ();
- return false;
- case 8: /* C */
- copy ();
- return false;
- case 9: /* V */
- paste ();
- return false;
- }
- }
- if ((style & SWT.SINGLE) != 0) {
- short keyCode = nsEvent.keyCode ();
- switch (keyCode) {
- case 76: /* KP Enter */
- case 36: /* Return */
- postEvent (SWT.DefaultSelection);
- }
- }
- return result;
-}
-
-void sendSearchSelection () {
- if (targetSearch != null) {
- ((NSSearchField)view).sendAction(actionSearch, targetSearch);
- }
- Event event = new Event ();
- event.detail = SWT.ICON_SEARCH;
- postEvent (SWT.DefaultSelection, event);
-}
-
-void sendCancelSelection () {
- if (targetCancel != null) {
- ((NSSearchField)view).sendAction(actionCancel, targetCancel);
- }
- Event event = new Event ();
- event.detail = SWT.ICON_CANCEL;
- postEvent (SWT.DefaultSelection, event);
-}
-
-void updateBackground () {
- NSColor nsColor = null;
- if (backgroundImage != null) {
- nsColor = NSColor.colorWithPatternImage(backgroundImage.handle);
- } else if (background != null) {
- nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]);
- } else {
- nsColor = NSColor.textBackgroundColor ();
- }
- if ((style & SWT.SINGLE) != 0) {
- ((NSTextField) view).setBackgroundColor (nsColor);
- } else {
- ((NSTextView) view).setBackgroundColor (nsColor);
- }
-}
-
-/**
- * Sets the double click enabled flag.
- * <p>
- * The double click flag enables or disables the
- * default action of the text widget when the user
- * double clicks.
- * </p><p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param doubleClick the new double click flag
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDoubleClickEnabled (boolean doubleClick) {
- checkWidget ();
- this.doubleClick = doubleClick;
-}
-
-/**
- * Sets the echo character.
- * <p>
- * The echo character is the character that is
- * displayed when the user enters text or the
- * text is changed by the programmer. Setting
- * the echo character to '\0' clears the echo
- * character and redraws the original text.
- * If for any reason the echo character is invalid,
- * or if the platform does not allow modification
- * of the echo character, the default echo character
- * for the platform is used.
- * </p>
- *
- * @param echo the new echo character
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEchoChar (char echo) {
- checkWidget ();
- if ((style & SWT.MULTI) != 0) return;
- if ((style & SWT.PASSWORD) == 0) {
- Point selection = getSelection ();
- String text = getText ();
- echoCharacter = echo;
- setEditText (text);
- setSelection (selection);
- }
- echoCharacter = echo;
-}
-
-/**
- * Sets the editable state.
- *
- * @param editable the new editable state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEditable (boolean editable) {
- checkWidget ();
- if (editable) {
- style &= ~SWT.READ_ONLY;
- } else {
- style |= SWT.READ_ONLY;
- }
- if ((style & SWT.SINGLE) != 0) {
- ((NSTextField) view).setEditable (editable);
- } else {
- ((NSTextView) view).setEditable (editable);
- }
-}
-
-void setEditText (String string) {
- char [] buffer;
- if ((style & SWT.PASSWORD) == 0 && echoCharacter != '\0') {
- hiddenText = string;
- buffer = new char [Math.min(hiddenText.length (), textLimit)];
- for (int i = 0; i < buffer.length; i++) buffer [i] = echoCharacter;
- } else {
- hiddenText = null;
- buffer = new char [Math.min(string.length (), textLimit)];
- string.getChars (0, buffer.length, buffer, 0);
- }
- NSString nsstring = NSString.stringWithCharacters (buffer, buffer.length);
- new NSCell (((NSTextField) view).cell ()).setTitle (nsstring);
- selectionRange = null;
-}
-
-void setFont(NSFont font) {
- if ((style & SWT.MULTI) != 0) {
- ((NSTextView) view).setFont (font);
- return;
- }
- super.setFont (font);
-}
-
-void setForeground (float /*double*/ [] color) {
- NSColor nsColor;
- if (color == null) {
- nsColor = NSColor.textColor ();
- } else {
- nsColor = NSColor.colorWithDeviceRed (color [0], color [1], color [2], 1);
- }
- if ((style & SWT.SINGLE) != 0) {
- ((NSTextField) view).setTextColor (nsColor);
- } else {
- ((NSTextView) view).setTextColor (nsColor);
- }
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public void setOrientation (int orientation) {
- checkWidget ();
-}
-
-/**
- * Sets the widget message. The message text is displayed
- * as a hint for the user, indicating the purpose of the field.
- * <p>
- * Typically this is used in conjunction with <code>SWT.SEARCH</code>.
- * </p>
- *
- * @param message the new message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the message is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public void setMessage (String message) {
- checkWidget ();
- if (message == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.message = message;
- if ((style & SWT.SINGLE) != 0) {
- NSString str = NSString.stringWith (message);
- NSTextFieldCell cell = new NSTextFieldCell (((NSTextField) view).cell ());
- cell.setPlaceholderString (str);
- }
-}
-
-/**
- * Sets the selection.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * regular array indexing rules.
- * </p>
- *
- * @param start new caret position
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int start) {
- checkWidget ();
- setSelection (start, start);
-}
-
-/**
- * Sets the selection to the range specified
- * by the given start and end indices.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * usual array indexing rules.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int start, int end) {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- NSString str = new NSCell (((NSTextField) view).cell ()).title ();
- int length = (int)/*64*/str.length ();
- int selStart = Math.min (Math.max (Math.min (start, end), 0), length);
- int selEnd = Math.min (Math.max (Math.max (start, end), 0), length);
- selectionRange = new NSRange ();
- selectionRange.location = selStart;
- selectionRange.length = selEnd - selStart;
- NSText fieldEditor = ((NSControl)view).currentEditor();
- if (fieldEditor != null) {
- fieldEditor.setSelectedRange (selectionRange);
- }
- } else {
- int length = (int)/*64*/((NSTextView) view).textStorage ().length ();
- int selStart = Math.min (Math.max (Math.min (start, end), 0), length);
- int selEnd = Math.min (Math.max (Math.max (start, end), 0), length);
- NSRange range = new NSRange ();
- range.location = selStart;
- range.length = selEnd - selStart;
- ((NSTextView) view).setSelectedRange (range);
- }
-}
-
-/**
- * Sets the selection to the range specified
- * by the given point, where the x coordinate
- * represents the start index and the y coordinate
- * represents the end index.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * usual array indexing rules.
- * </p>
- *
- * @param selection the point
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (Point selection) {
- checkWidget ();
- if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (selection.x, selection.y);
-}
-
-/**
- * Sets the number of tabs.
- * <p>
- * Tab stop spacing is specified in terms of the
- * space (' ') character. The width of a single
- * tab stop is the pixel width of the spaces.
- * </p>
- *
- * @param tabs the number of tabs
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTabs (int tabs) {
- checkWidget ();
- if (this.tabs == tabs) return;
- this.tabs = tabs;
- if ((style & SWT.SINGLE) != 0) return;
- float /*double*/ size = textExtent("s").width * tabs;
- NSTextView widget = (NSTextView)view;
- NSParagraphStyle defaultStyle = widget.defaultParagraphStyle();
- NSMutableParagraphStyle paragraphStyle = new NSMutableParagraphStyle(defaultStyle.mutableCopy());
- paragraphStyle.setTabStops(NSArray.array());
- NSTextTab tab = (NSTextTab)new NSTextTab().alloc();
- tab = tab.initWithType(OS.NSLeftTabStopType, size);
- paragraphStyle.addTabStop(tab);
- tab.release();
- paragraphStyle.setDefaultTabInterval(size);
- widget.setDefaultParagraphStyle(paragraphStyle);
- paragraphStyle.release();
-}
-
-/**
- * Sets the contents of the receiver to the given string. If the receiver has style
- * SINGLE and the argument contains multiple lines of text, the result of this
- * operation is undefined and may vary from platform to platform.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- string = verifyText (string, 0, getCharCount (), null);
- if (string == null) return;
- }
- if ((style & SWT.SINGLE) != 0) {
- setEditText (string);
- } else {
- NSTextView widget = (NSTextView)view;
- NSString str = NSString.stringWith (string);
- widget.setString (str);
- widget.setSelectedRange(new NSRange());
- }
- sendEvent (SWT.Modify);
-}
-
-/**
- * Sets the maximum number of characters that the receiver
- * is capable of holding to be the argument.
- * <p>
- * Instead of trying to set the text limit to zero, consider
- * creating a read-only text widget.
- * </p><p>
- * To reset this value to the default, use <code>setTextLimit(Text.LIMIT)</code>.
- * Specifying a limit value larger than <code>Text.LIMIT</code> sets the
- * receiver's limit to <code>Text.LIMIT</code>.
- * </p>
- *
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public void setTextLimit (int limit) {
- checkWidget ();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- textLimit = limit;
-}
-
-/**
- * Sets the zero-relative index of the line which is currently
- * at the top of the receiver. This index can change when lines
- * are scrolled or new lines are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- int row = Math.max(0, Math.min(index, getLineCount() - 1));
- NSPoint pt = new NSPoint();
- pt.x = scrollView.contentView().bounds().x;
- pt.y = getLineHeight() * row;
- view.scrollPoint(pt);
-}
-
-boolean shouldChangeTextInRange_replacementString(int /*long*/ id, int /*long*/ sel, int /*long*/ affectedCharRange, int /*long*/ replacementString) {
- NSRange range = new NSRange();
- OS.memmove(range, affectedCharRange, NSRange.sizeof);
- boolean result = callSuperBoolean(id, sel, range, replacementString);
- if (!hooks(SWT.Verify) && echoCharacter =='\0') return result;
- String text = new NSString(replacementString).getString();
- String newText = text;
- if (hooks (SWT.Verify)) {
- NSEvent currentEvent = display.application.currentEvent();
- int /*long*/ type = currentEvent.type();
- if (type != OS.NSKeyDown && type != OS.NSKeyUp) currentEvent = null;
- newText = verifyText(text, (int)/*64*/range.location, (int)/*64*/(range.location+range.length), currentEvent);
- }
- if (newText == null) return false;
- if ((style & SWT.SINGLE) != 0) {
- if (text != newText || echoCharacter != '\0') {
- //handle backspace and delete
- if (range.length == 1) {
- NSText editor = new NSText(id);
- editor.setSelectedRange (range);
- }
- insertEditText(newText);
- result = false;
- }
- } else {
- if (text != newText) {
- NSTextView widget = (NSTextView) view;
- Point selection = getSelection();
- NSRange selRange = new NSRange();
- selRange.location = selection.x;
- selRange.length = selection.x + selection.y;
- widget.textStorage ().replaceCharactersInRange (selRange, NSString.stringWith(newText));
- result = false;
- }
- }
- if (!result) sendEvent (SWT.Modify);
- return result;
-}
-
-/**
- * Shows the selection.
- * <p>
- * If the selection is already showing
- * in the receiver, this method simply returns. Otherwise,
- * lines are scrolled until the selection is visible.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void showSelection () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- setSelection (getSelection ());
- } else {
- NSTextView widget = (NSTextView) view;
- widget.scrollRangeToVisible (widget.selectedRange ());
- }
-}
-
-void textViewDidChangeSelection(int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
- NSNotification notification = new NSNotification (aNotification);
- NSText editor = new NSText (notification.object ().id);
- selectionRange = editor.selectedRange ();
-}
-
-void textDidChange (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
- if ((style & SWT.SINGLE) != 0) super.textDidChange (id, sel, aNotification);
- postEvent (SWT.Modify);
-}
-
-NSRange textView_willChangeSelectionFromCharacterRange_toCharacterRange (int /*long*/ id, int /*long*/ sel, int /*long*/ aTextView, int /*long*/ oldSelectedCharRange, int /*long*/ newSelectedCharRange) {
- /*
- * If the selection is changing as a result of the receiver getting focus
- * then return the receiver's last selection range, otherwise the full
- * text will be automatically selected.
- */
- if (receivingFocus && selectionRange != null) return selectionRange;
-
- /* allow the selection change to proceed */
- NSRange result = new NSRange ();
- OS.memmove(result, newSelectedCharRange, NSRange.sizeof);
- return result;
-}
-
-int traversalCode (int key, NSEvent theEvent) {
- int bits = super.traversalCode (key, theEvent);
- if ((style & SWT.READ_ONLY) != 0) return bits;
- if ((style & SWT.MULTI) != 0) {
- bits &= ~SWT.TRAVERSE_RETURN;
- if (key == 48 /* Tab */ && theEvent != null) {
- int /*long*/ modifiers = theEvent.modifierFlags ();
- boolean next = (modifiers & OS.NSShiftKeyMask) == 0;
- if (next && (modifiers & OS.NSControlKeyMask) == 0) {
- bits &= ~(SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS);
- }
- }
- }
- return bits;
-}
-
-void updateCursorRects (boolean enabled) {
- super.updateCursorRects (enabled);
- if (scrollView == null) return;
- NSClipView contentView = scrollView.contentView ();
- contentView.setDocumentCursor (enabled ? NSCursor.IBeamCursor () : null);
-}
-
-String verifyText (String string, int start, int end, NSEvent keyEvent) {
- Event event = new Event ();
- if (keyEvent != null) setKeyState(event, SWT.MouseDown, keyEvent);
- event.text = string;
- event.start = start;
- event.end = end;
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the verify
- * event. If this happens, answer null to cancel
- * the operation.
- */
- sendEvent (SWT.Verify, event);
- if (!event.doit || isDisposed ()) return null;
- return event.text;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolBar.java
deleted file mode 100755
index 77d70b71de..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolBar.java
+++ /dev/null
@@ -1,536 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.cocoa.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.accessibility.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class support the layout of selectable
- * tool bar items.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>ToolItem</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add <code>Control</code> children to it,
- * or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>FLAT, WRAP, RIGHT, HORIZONTAL, VERTICAL, SHADOW_OUT</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#toolbar">ToolBar, ToolItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolBar extends Composite {
- int itemCount;
- ToolItem [] items;
- NSArray accessibilityAttributes = null;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#FLAT
- * @see SWT#WRAP
- * @see SWT#RIGHT
- * @see SWT#HORIZONTAL
- * @see SWT#SHADOW_OUT
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass()
- * @see Widget#getStyle()
- */
-public ToolBar (Composite parent, int style) {
- super (parent, checkStyle (style));
-
- /*
- * Ensure that either of HORIZONTAL or VERTICAL is set.
- * NOTE: HORIZONTAL and VERTICAL have the same values
- * as H_SCROLL and V_SCROLL so it is necessary to first
- * clear these bits to avoid scroll bars and then reset
- * the bits using the original style supplied by the
- * programmer.
- */
- if ((style & SWT.VERTICAL) != 0) {
- this.style |= SWT.VERTICAL;
- } else {
- this.style |= SWT.HORIZONTAL;
- }
-}
-
-int /*long*/ accessibilityAttributeNames(int /*long*/ id, int /*long*/ sel) {
-
- if (accessibilityAttributes == null) {
- NSMutableArray ourAttributes = NSMutableArray.arrayWithCapacity(10);
- ourAttributes.addObject(OS.NSAccessibilityRoleAttribute);
- ourAttributes.addObject(OS.NSAccessibilityRoleDescriptionAttribute);
- ourAttributes.addObject(OS.NSAccessibilityParentAttribute);
- ourAttributes.addObject(OS.NSAccessibilityPositionAttribute);
- ourAttributes.addObject(OS.NSAccessibilitySizeAttribute);
- ourAttributes.addObject(OS.NSAccessibilityWindowAttribute);
- ourAttributes.addObject(OS.NSAccessibilityTopLevelUIElementAttribute);
- ourAttributes.addObject(OS.NSAccessibilityHelpAttribute);
- ourAttributes.addObject(OS.NSAccessibilityEnabledAttribute);
- ourAttributes.addObject(OS.NSAccessibilityFocusedAttribute);
- ourAttributes.addObject(OS.NSAccessibilityChildrenAttribute);
-
- if (accessible != null) {
- // See if the accessible will override or augment the standard list.
- // Help, title, and description can be overridden.
- NSMutableArray extraAttributes = NSMutableArray.arrayWithCapacity(3);
- extraAttributes.addObject(OS.NSAccessibilityHelpAttribute);
- extraAttributes.addObject(OS.NSAccessibilityDescriptionAttribute);
- extraAttributes.addObject(OS.NSAccessibilityTitleAttribute);
-
- for (int i = (int)/*64*/extraAttributes.count() - 1; i >= 0; i--) {
- NSString attribute = new NSString(extraAttributes.objectAtIndex(i).id);
- if (accessible.internal_accessibilityAttributeValue(attribute, ACC.CHILDID_SELF) != null) {
- ourAttributes.addObject(extraAttributes.objectAtIndex(i));
- }
- }
- }
-
- accessibilityAttributes = ourAttributes;
- accessibilityAttributes.retain();
- }
-
- return accessibilityAttributes.id;
-}
-
-int /*long*/ accessibilityAttributeValue (int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- NSString nsAttributeName = new NSString(arg0);
-
- if (accessible != null) {
- id returnObject = accessible.internal_accessibilityAttributeValue(nsAttributeName, ACC.CHILDID_SELF);
- if (returnObject != null) return returnObject.id;
- }
-
- if (nsAttributeName.isEqualToString (OS.NSAccessibilityRoleAttribute) || nsAttributeName.isEqualToString (OS.NSAccessibilityRoleDescriptionAttribute)) {
- NSString role = OS.NSAccessibilityToolbarRole;
-
- if (nsAttributeName.isEqualToString (OS.NSAccessibilityRoleAttribute))
- return role.id;
- else {
- int /*long*/ roleDescription = OS.NSAccessibilityRoleDescription(role.id, 0);
- return roleDescription;
- }
- } else if (nsAttributeName.isEqualToString(OS.NSAccessibilityEnabledAttribute)) {
- return NSNumber.numberWithBool(isEnabled()).id;
- } else if (nsAttributeName.isEqualToString(OS.NSAccessibilityFocusedAttribute)) {
- boolean focused = (view.id == view.window().firstResponder().id);
- return NSNumber.numberWithBool(focused).id;
- }
-
- return super.accessibilityAttributeValue(id, sel, arg0);
-}
-
-boolean accessibilityIsIgnored(int /*long*/ id, int /*long*/ sel) {
- // Toolbars aren't ignored.
- return false;
-}
-
-static int checkStyle (int style) {
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = wHint, height = hHint;
- if (wHint == SWT.DEFAULT) width = 0x7FFFFFFF;
- if (hHint == SWT.DEFAULT) height = 0x7FFFFFFF;
- int [] result = layout (width, height, false);
- Point extent = new Point (result [1], result [2]);
- if (wHint != SWT.DEFAULT) extent.x = wHint;
- if (hHint != SWT.DEFAULT) extent.y = hHint;
- return extent;
-}
-
-void createHandle () {
- state |= THEME_BACKGROUND;
- NSView widget = (NSView)new SWTView().alloc();
- widget.init();
-// widget.setDrawsBackground(false);
- view = widget;
-}
-
-void createItem (ToolItem item, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (itemCount == items.length) {
- ToolItem [] newItems = new ToolItem [itemCount + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- item.createWidget();
- view.addSubview(item.view);
- System.arraycopy (items, index, items, index + 1, itemCount++ - index);
- items [index] = item;
- relayout ();
-}
-
-void createWidget () {
- super.createWidget ();
- items = new ToolItem [4];
- itemCount = 0;
-}
-
-void destroyItem (ToolItem item) {
- int index = 0;
- while (index < itemCount) {
- if (items [index] == item) break;
- index++;
- }
- if (index == itemCount) return;
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- item.view.removeFromSuperview();
- relayout ();
-}
-
-void drawBackground (int /*long*/ id, NSGraphicsContext context, NSRect rect) {
- if (id != view.id) return;
- if (background != null) {
- fillBackground (view, context, rect, -1);
- }
-}
-
-void enableWidget(boolean enabled) {
- super.enableWidget(enabled);
- for (int i = 0; i < itemCount; i++) {
- ToolItem item = items[i];
- if (item != null) {
- item.enableWidget(enabled);
- }
- }
-}
-
-Widget findTooltip (NSPoint pt) {
- pt = view.convertPoint_fromView_ (pt, null);
- for (int i = 0; i < itemCount; i++) {
- ToolItem item = items [i];
- if (OS.NSPointInRect(pt, item.view.frame())) return item;
- }
- return super.findTooltip (pt);
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem getItem (int index) {
- checkWidget();
- if (0 <= index && index < itemCount) return items [index];
- error (SWT.ERROR_INVALID_RANGE);
- return null;
-}
-
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- *
- * @param point the point used to locate the item
- * @return the item at the given point
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem getItem (Point pt) {
- checkWidget();
- if (pt == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<itemCount; i++) {
- Rectangle rect = items [i].getBounds ();
- if (rect.contains (pt)) return items [i];
- }
- return null;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- return itemCount;
-}
-
-/**
- * Returns an array of <code>ToolItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem [] getItems () {
- checkWidget();
- ToolItem [] result = new ToolItem [itemCount];
- System.arraycopy (items, 0, result, 0, itemCount);
- return result;
-}
-
-/**
- * Returns the number of rows in the receiver. When
- * the receiver has the <code>WRAP</code> style, the
- * number of rows can be greater than one. Otherwise,
- * the number of rows is always one.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getRowCount () {
- checkWidget();
- Rectangle rect = getClientArea ();
- return layout (rect.width, rect.height, false) [0];
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the tool item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the tool item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (ToolItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<itemCount; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-
-int [] layoutHorizontal (int width, int height, boolean resize) {
- int xSpacing = 0, ySpacing = 2;
- int marginWidth = 0, marginHeight = 0;
- int x = marginWidth, y = marginHeight;
- int maxX = 0, rows = 1;
- boolean wrap = (style & SWT.WRAP) != 0;
- int itemHeight = 0;
- Point [] sizes = new Point [itemCount];
- for (int i=0; i<itemCount; i++) {
- Point size = sizes [i] = items [i].computeSize ();
- itemHeight = Math.max (itemHeight, size.y);
- }
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- Point size = sizes [i];
- if (wrap && i != 0 && x + size.x > width) {
- rows++;
- x = marginWidth;
- y += ySpacing + itemHeight;
- }
- if (resize) {
- item.setBounds (x, y, size.x, itemHeight);
- boolean visible = x + size.x <= width && y + itemHeight <= height;
- item.setVisible (visible);
- Control control = item.control;
- if (control != null) {
- int controlY = y + (itemHeight - size.y) / 2;
- control.setBounds (x, controlY, size.x, itemHeight - (controlY - y));
- }
- }
- x += xSpacing + size.x;
- maxX = Math.max (maxX, x);
- }
-
- return new int [] {rows, maxX, y + itemHeight};
-}
-
-int [] layoutVertical (int width, int height, boolean resize) {
- int xSpacing = 2, ySpacing = 0;
- int marginWidth = 0, marginHeight = 0;
- int x = marginWidth, y = marginHeight;
- int maxY = 0, cols = 1;
- boolean wrap = (style & SWT.WRAP) != 0;
- int itemWidth = 0;
- Point [] sizes = new Point [itemCount];
- for (int i=0; i<itemCount; i++) {
- Point size = sizes [i] = items [i].computeSize ();
- itemWidth = Math.max (itemWidth, size.x);
- }
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- Point size = sizes [i];
- if (wrap && i != 0 && y + size.y > height) {
- cols++;
- x += xSpacing + itemWidth;
- y = marginHeight;
- }
- if (resize) {
- item.setBounds (x, y, itemWidth, size.y);
- boolean visible = x + itemWidth <= width && y + size.y <= height;
- item.setVisible (visible);
- Control control = item.control;
- if (control != null) {
- int controlX = x + (itemWidth - size.x) / 2;
- control.setBounds (controlX, y, itemWidth - (controlX - x), size.y);
- }
- }
- y += ySpacing + size.y;
- maxY = Math.max (maxY, y);
- }
-
- return new int [] {cols, x + itemWidth, maxY};
-}
-
-int [] layout (int nWidth, int nHeight, boolean resize) {
- if ((style & SWT.VERTICAL) != 0) {
- return layoutVertical (nWidth, nHeight, resize);
- } else {
- return layoutHorizontal (nWidth, nHeight, resize);
- }
-}
-
-void relayout () {
- if (!getDrawing()) return;
- Rectangle rect = getClientArea ();
- layout (rect.width, rect.height, true);
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- itemCount = 0;
- items = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (accessibilityAttributes != null) accessibilityAttributes.release();
- accessibilityAttributes = null;
-}
-
-void removeControl (Control control) {
- super.removeControl (control);
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- if (item.control == control) item.setControl (null);
- }
-}
-
-void resized () {
- super.resized ();
- relayout ();
-}
-
-void setFont(NSFont font) {
- for (int i = 0; i < itemCount; i++) {
- ToolItem item = items[i];
- if (item.button != null) ((NSButton)item.button).setAttributedTitle(item.createString());
- }
-}
-
-public void setRedraw (boolean redraw) {
- checkWidget();
- super.setRedraw (redraw);
- if (redraw && drawCount == 0) relayout();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java
deleted file mode 100755
index 21853d587f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java
+++ /dev/null
@@ -1,992 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a button in a tool bar.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>PUSH, CHECK, RADIO, SEPARATOR, DROP_DOWN</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles CHECK, PUSH, RADIO, SEPARATOR and DROP_DOWN
- * may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#toolbar">ToolBar, ToolItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolItem extends Item {
- NSView view;
- NSButton button;
- int width = DEFAULT_SEPARATOR_WIDTH;
- ToolBar parent;
- Image hotImage, disabledImage;
- String toolTipText;
- Control control;
- boolean selection;
-
- static final int DEFAULT_WIDTH = 24;
- static final int DEFAULT_HEIGHT = 22;
- static final int DEFAULT_SEPARATOR_WIDTH = 6;
- static final int INSET = 3;
- static final int ARROW_WIDTH = 5;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>ToolBar</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#PUSH
- * @see SWT#CHECK
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ToolItem (ToolBar parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>ToolBar</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#PUSH
- * @see SWT#CHECK
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ToolItem (ToolBar parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-int /*long*/ accessibilityAttributeValue(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- NSString nsAttributeName = new NSString(arg0);
-
- if (nsAttributeName.isEqualToString (OS.NSAccessibilityRoleAttribute) || nsAttributeName.isEqualToString (OS.NSAccessibilityRoleDescriptionAttribute)) {
- NSString roleText = ((style & SWT.PUSH) != 0) ? OS.NSAccessibilityButtonRole
- : ((style & SWT.RADIO) != 0) ? OS.NSAccessibilityRadioButtonRole
- : ((style & SWT.CHECK) != 0) ? OS.NSAccessibilityCheckBoxRole
- : ((style & SWT.DROP_DOWN) != 0) ? OS.NSAccessibilityMenuButtonRole
- : null; // SEPARATOR
- if (roleText != null) {
- if (nsAttributeName.isEqualToString (OS.NSAccessibilityRoleAttribute)) {
- return roleText.id;
- } else { // NSAccessibilityRoleDescriptionAttribute
- int /*long*/ description = OS.NSAccessibilityRoleDescription (roleText.id, 0);
- return description;
- }
- }
- } else if (nsAttributeName.isEqualToString (OS.NSAccessibilityTitleAttribute) || nsAttributeName.isEqualToString (OS.NSAccessibilityDescriptionAttribute)) {
- String accessibleText = toolTipText;
- if (accessibleText == null || accessibleText.equals("")) accessibleText = text;
- if (!(accessibleText == null || accessibleText.equals(""))) {
- return NSString.stringWith(accessibleText).id;
- } else {
- return NSString.stringWith("").id;
- }
- } else if (nsAttributeName.isEqualToString (OS.NSAccessibilityValueAttribute) && (style & (SWT.CHECK | SWT.RADIO)) != 0) {
- NSNumber value = NSNumber.numberWithInt(selection ? 1 : 0);
- return value.id;
- } else if (nsAttributeName.isEqualToString(OS.NSAccessibilityEnabledAttribute)) {
- NSNumber value = NSNumber.numberWithInt(getEnabled() ? 1 : 0);
- return value.id;
- }
-
- return super.accessibilityAttributeValue(id, sel, arg0);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called when the mouse is over the arrow portion of a drop-down tool,
- * the event object detail field contains the value <code>SWT.ARROW</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user,
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.DROP_DOWN, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-Point computeSize () {
- checkWidget();
- int width = 0, height = 0;
- if ((style & SWT.SEPARATOR) != 0) {
- if ((parent.style & SWT.HORIZONTAL) != 0) {
- width = getWidth ();
- height = DEFAULT_HEIGHT;
- } else {
- width = DEFAULT_WIDTH;
- height = getWidth ();
- }
- if (control != null) {
- height = Math.max (height, control.getMininumHeight ());
- }
- } else {
- if (text.length () != 0 || image != null) {
- NSButton widget = (NSButton)button;
- NSSize size = widget.cell().cellSize();
- width = (int)Math.ceil(size.width);
- height = (int)Math.ceil(size.height);
- } else {
- width = DEFAULT_WIDTH;
- height = DEFAULT_HEIGHT;
- }
- if ((style & SWT.DROP_DOWN) != 0) {
- width += ARROW_WIDTH + INSET;
- }
- width += INSET * 2;
- height += INSET * 2;
- }
- return new Point (width, height);
-}
-
-void createHandle () {
- if ((style & SWT.SEPARATOR) != 0) {
- NSBox widget = (NSBox)new SWTBox().alloc();
- widget.init();
- widget.setBoxType(OS.NSBoxSeparator);
- widget.setBorderWidth(0);
- view = widget;
- } else {
- NSView widget = (NSView)new SWTView().alloc();
- widget.init();
- button = (NSButton)new SWTButton().alloc();
- button.init();
- /*
- * Feature in Cocoa. NSButtons without borders do not leave any margin
- * between their edge and their image. The workaround is to provide a
- * custom cell that displays the image in a better position.
- */
- NSButtonCell cell = (NSButtonCell)new SWTButtonCell ().alloc ().init ();
- button.setCell (cell);
- cell.release();
- button.setBordered(false);
- button.setAction(OS.sel_sendSelection);
- button.setTarget(button);
- Font font = parent.font != null ? parent.font : parent.defaultFont ();
- button.setFont(font.handle);
- button.setImagePosition(OS.NSImageOverlaps);
- NSString emptyStr = NSString.stringWith("");
- button.setTitle(emptyStr);
- button.setEnabled(parent.getEnabled());
- widget.addSubview(button);
- view = widget;
- }
-}
-
-NSAttributedString createString() {
- NSAttributedString attribStr = parent.createString(text, null, parent.foreground, SWT.CENTER, true, true);
- attribStr.autorelease();
- return attribStr;
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget(view);
-
- if (button != null) {
- display.removeWidget (button);
- display.removeWidget (button.cell());
- }
-}
-
-void destroyWidget() {
- parent.destroyItem(this);
- super.destroyWidget();
-}
-
-void drawImageWithFrameInView (int /*long*/ id, int /*long*/ sel, int /*long*/ image, NSRect rect, int /*long*/ view) {
- if (text.length () > 0) {
- if ((parent.style & SWT.RIGHT) != 0) {
- rect.x += 3;
- } else {
- rect.y += 3;
- }
- }
- callSuper (id, sel, image, rect, view);
-}
-
-void drawWidget (int /*long*/ id, NSGraphicsContext context, NSRect rect) {
- if (id == view.id) {
- if (getSelection ()) {
- NSRect bounds = view.bounds();
- context.saveGraphicsState();
- NSColor.colorWithDeviceRed(0.1f, 0.1f, 0.1f, 0.1f).setFill();
- NSColor.colorWithDeviceRed(0.2f, 0.2f, 0.2f, 0.2f).setStroke();
- NSBezierPath.fillRect(bounds);
- bounds.x += 0.5f;
- bounds.y += 0.5f;
- bounds.width -= 1;
- bounds.height -= 1;
- NSBezierPath.strokeRect(bounds);
- context.restoreGraphicsState();
- }
- if ((style & SWT.DROP_DOWN) != 0) {
- NSRect bounds = view.bounds();
- context.saveGraphicsState();
- NSBezierPath path = NSBezierPath.bezierPath();
- NSPoint pt = new NSPoint();
- path.moveToPoint(pt);
- pt.x += ARROW_WIDTH;
- path.lineToPoint(pt);
- pt.y += ARROW_WIDTH - 1;
- pt.x -= ARROW_WIDTH / 2f;
- path.lineToPoint(pt);
- path.closePath();
- NSAffineTransform transform = NSAffineTransform.transform();
- transform.translateXBy((int)bounds.width - ARROW_WIDTH - INSET, (int)(bounds.height - ARROW_WIDTH / 2) / 2);
- transform.concat();
- NSColor color = isEnabled() ? NSColor.blackColor() : NSColor.disabledControlTextColor();
- color.set();
- path.fill();
- context.restoreGraphicsState();
- }
- }
-}
-
-void enableWidget(boolean enabled) {
- if ((style & SWT.SEPARATOR) == 0) {
- ((NSButton)button).setEnabled(enabled);
- }
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- NSRect rect = view.frame();
- return new Rectangle((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
-}
-
-void setClipRegion (float /*double*/ x, float /*double*/ y) {
- NSRect frame = view.frame();
- parent.setClipRegion(frame.x + x, frame.y + y);
-}
-
-/**
- * Returns the control that is used to fill the bounds of
- * the item when the item is a <code>SEPARATOR</code>.
- *
- * @return the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget();
- return control;
-}
-
-/**
- * Returns the receiver's disabled image if it has one, or null
- * if it does not.
- * <p>
- * The disabled image is displayed when the receiver is disabled.
- * </p>
- *
- * @return the receiver's disabled image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getDisabledImage () {
- checkWidget();
- return disabledImage;
-}
-
-boolean getDrawing () {
- return parent.getDrawing ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- return (state & DISABLED) == 0;
-}
-
-/**
- * Returns the receiver's hot image if it has one, or null
- * if it does not.
- * <p>
- * The hot image is displayed when the mouse enters the receiver.
- * </p>
- *
- * @return the receiver's hot image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getHotImage () {
- checkWidget();
- return hotImage;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>ToolBar</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolBar getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked (which some platforms draw as a
- * pushed in button). If the receiver is of any other type, this method
- * returns false.
- * </p>
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
- return selection;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget();
- return width;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-
-boolean isDrawing () {
- return getDrawing() && parent.isDrawing ();
-}
-
-int /*long*/ menuForEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- return parent.menuForEvent (id, sel, theEvent);
-}
-
-void mouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!parent.mouseEvent(parent.view.id, sel, theEvent, SWT.MouseDown)) return;
- Display display = this.display;
- display.trackingControl = parent;
- super.mouseDown(id, sel, theEvent);
- display.trackingControl = null;
- if ((style & SWT.DROP_DOWN) != 0 && id == view.id) {
- NSRect frame = view.frame();
- Event event = new Event ();
- event.detail = SWT.ARROW;
- event.x = (int)frame.x;
- event.y = (int)(frame.y + frame.height);
- postEvent (SWT.Selection, event);
- }
-}
-
-void mouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!parent.mouseEvent(parent.view.id, sel, theEvent, SWT.MouseUp)) return;
- super.mouseUp(id, sel, theEvent);
-}
-
-void mouseDragged(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!parent.mouseEvent(parent.view.id, sel, theEvent, SWT.MouseMove)) return;
- super.mouseDragged(id, sel, theEvent);
-}
-
-void rightMouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!parent.mouseEvent(parent.view.id, sel, theEvent, SWT.MouseDown)) return;
- super.rightMouseDown(id, sel, theEvent);
-}
-
-void rightMouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!parent.mouseEvent(parent.view.id, sel, theEvent, SWT.MouseUp)) return;
- super.rightMouseUp(id, sel, theEvent);
-}
-
-void rightMouseDragged(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!parent.mouseEvent(parent.view.id, sel, theEvent, SWT.MouseMove)) return;
- super.rightMouseDragged(id, sel, theEvent);
-}
-
-void otherMouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!parent.mouseEvent(parent.view.id, sel, theEvent, SWT.MouseDown)) return;
- super.otherMouseDown(id, sel, theEvent);
-}
-
-void otherMouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!parent.mouseEvent(parent.view.id, sel, theEvent, SWT.MouseUp)) return;
- super.otherMouseUp(id, sel, theEvent);
-}
-
-void otherMouseDragged(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (!parent.mouseEvent(parent.view.id, sel, theEvent, SWT.MouseMove)) return;
- super.otherMouseDragged(id, sel, theEvent);
-}
-
-void register () {
- super.register ();
- display.addWidget (view, this);
-
- if (button != null) {
- display.addWidget (button, this);
- display.addWidget (button.cell(), this);
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-
-void releaseParent () {
- super.releaseParent ();
- setVisible (false);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (view != null) view.release ();
- if (button != null) button.release ();
- view = button = null;
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- control = null;
- toolTipText = null;
- image = disabledImage = hotImage = null;
-}
-
-void selectRadio () {
- int index = 0;
- ToolItem [] items = parent.getItems ();
- while (index < items.length && items [index] != this) index++;
- int i = index - 1;
- while (i >= 0 && items [i].setRadioSelection (false)) --i;
- int j = index + 1;
- while (j < items.length && items [j].setRadioSelection (false)) j++;
- setSelection (true);
-}
-
-void sendSelection () {
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) {
- selectRadio ();
- }
- }
- if ((style & SWT.CHECK) != 0) setSelection (!getSelection ());
- postEvent (SWT.Selection);
-}
-
-void setBounds (int x, int y, int width, int height) {
- NSRect rect = new NSRect();
- rect.x = x;
- rect.y = y;
- rect.width = width;
- rect.height = height;
- view.setFrame(rect);
- if (button != null) {
- rect.x = 0;
- rect.y = 0;
- rect.width = width;
- rect.height = height;
- if ((style & SWT.DROP_DOWN) != 0) rect.width -= ARROW_WIDTH + INSET;
- button.setFrame(rect);
- }
-}
-
-/**
- * Sets the control that is used to fill the bounds of
- * the item when the item is a <code>SEPARATOR</code>.
- *
- * @param control the new control
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- if ((style & SWT.SEPARATOR) == 0) return;
- if (this.control == control) return;
- NSBox widget = (NSBox)view;
- if (control == null) {
- widget.setBoxType(OS.NSBoxSeparator);
- } else {
- widget.setBoxType(OS.NSBoxCustom);
- }
- this.control = control;
- view.setHidden(control != null);
- if (control != null && !control.isDisposed ()) {
- control.moveAbove (null);
- }
- parent.relayout ();
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise.
- * <p>
- * A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- * </p>
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- if ((state & DISABLED) == 0 && enabled) return;
- if (enabled) {
- state &= ~DISABLED;
- } else {
- state |= DISABLED;
- }
- enableWidget(enabled);
-}
-
-/**
- * Sets the receiver's disabled image to the argument, which may be
- * null indicating that no disabled image should be displayed.
- * <p>
- * The disabled image is displayed when the receiver is disabled.
- * </p>
- *
- * @param image the disabled image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDisabledImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- disabledImage = image;
- updateImage (true);
-}
-
-/**
- * Sets the receiver's hot image to the argument, which may be
- * null indicating that no hot image should be displayed.
- * <p>
- * The hot image is displayed when the mouse enters the receiver.
- * </p>
- *
- * @param image the hot image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHotImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- hotImage = image;
- updateImage (true);
-}
-
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- super.setImage (image);
- updateImage (true);
-}
-
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-
-/**
- * Sets the selection state of the receiver.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked (which some platforms draw as a
- * pushed in button).
- * </p>
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
- this.selection = selected;
- view.setNeedsDisplay(true);
-}
-
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- super.setText (string);
- NSButton widget = (NSButton)button;
- widget.setAttributedTitle(createString());
- if (text.length() != 0 && image != null) {
- if ((parent.style & SWT.RIGHT) != 0) {
- widget.setImagePosition(OS.NSImageLeft);
- } else {
- widget.setImagePosition(OS.NSImageAbove);
- }
- } else {
- widget.setImagePosition(text.length() != 0 ? OS.NSNoImage : OS.NSImageOnly);
- }
- parent.relayout ();
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
- parent.checkToolTip (this);
-}
-
-void setVisible (boolean visible) {
- if (visible) {
- if ((state & HIDDEN) == 0) return;
- state &= ~HIDDEN;
- } else {
- if ((state & HIDDEN) != 0) return;
- state |= HIDDEN;
- }
- view.setHidden(!visible);
-}
-
-/**
- * Sets the width of the receiver, for <code>SEPARATOR</code> ToolItems.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int width) {
- checkWidget();
- if ((style & SWT.SEPARATOR) == 0) return;
- if (width < 0 || this.width == width) return;
- this.width = width;
- parent.relayout();
-}
-
-String tooltipText () {
- return toolTipText;
-}
-
-void updateImage (boolean layout) {
- if ((style & SWT.SEPARATOR) != 0) return;
- Image image = null;
- if (hotImage != null) {
- image = hotImage;
- } else {
- if (this.image != null) {
- image = this.image;
- } else {
- image = disabledImage;
- }
- }
- NSButton widget = (NSButton)button;
- /*
- * Feature in Cocoa. If the NSImage object being set into the button is
- * the same NSImage object that is already there then the button does not
- * redraw itself. This results in the button's image not visually updating
- * if the NSImage object's content has changed since it was last set
- * into the button. The workaround is to explicitly redraw the button.
- */
- widget.setImage(image != null ? image.handle : null);
- widget.setNeedsDisplay(true);
- if (text.length() != 0 && image != null) {
- if ((parent.style & SWT.RIGHT) != 0) {
- widget.setImagePosition(OS.NSImageLeft);
- } else {
- ((NSButton)button).setImagePosition(OS.NSImageAbove);
- }
- } else {
- widget.setImagePosition(text.length() != 0 ? OS.NSNoImage : OS.NSImageOnly);
- }
- parent.relayout();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tracker.java
deleted file mode 100755
index c7a9e95ef4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tracker.java
+++ /dev/null
@@ -1,1113 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class implement rubber banding rectangles that are
- * drawn onto a parent <code>Composite</code> or <code>Display</code>.
- * These rectangles can be specified to respond to mouse and key events
- * by either moving or resizing themselves accordingly. Trackers are
- * typically used to represent window geometries in a lightweight manner.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, UP, DOWN, RESIZE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Move, Resize</dd>
- * </dl>
- * <p>
- * Note: Rectangle move behavior is assumed unless RESIZE is specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tracker">Tracker snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Tracker extends Widget {
- Control parent;
- boolean tracking, cancelled, stippled;
- Cursor clientCursor, resizeCursor;
- Rectangle [] rectangles = new Rectangle [0], proportions = rectangles;
- Rectangle bounds;
- int cursorOrientation = SWT.NONE;
- boolean inEvent = false;
- NSWindow window;
- int oldX, oldY;
-
- /*
- * The following values mirror step sizes on Windows
- */
- final static int STEPSIZE_SMALL = 1;
- final static int STEPSIZE_LARGE = 9;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#RESIZE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Tracker (Composite parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
-}
-
-/**
- * Constructs a new instance of this class given the display
- * to create it on and a style value describing its behavior
- * and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the tracker on the currently active
- * display if there is one. If there is no current display, the
- * tracker is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the tracker on
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#RESIZE
- */
-public Tracker (Display display, int style) {
- if (display == null) display = Display.getCurrent ();
- if (display == null) display = Display.getDefault ();
- if (!display.isValidThread ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- this.style = checkStyle (style);
- this.display = display;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize, typedListener);
- addListener (SWT.Move, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard, by sending
- * it one of the messages defined in the <code>KeyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #removeKeyListener
- */
-public void addKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.KeyUp,typedListener);
- addListener(SWT.KeyDown,typedListener);
-}
-
-Point adjustMoveCursor () {
- if (bounds == null) return null;
- int newX = bounds.x + bounds.width / 2;
- int newY = bounds.y;
- /*
- * Convert to screen coordinates if needed
- */
- if (parent != null) {
- Point pt = parent.toDisplay (newX, newY);
- newX = pt.x;
- newY = pt.y;
- }
- display.setCursorLocation(newX, newY);
- return new Point (newX, newY);
-}
-
-Point adjustResizeCursor (boolean movePointer) {
- if (bounds == null) return null;
- int newX, newY;
-
- if ((cursorOrientation & SWT.LEFT) != 0) {
- newX = bounds.x;
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- newX = bounds.x + bounds.width;
- } else {
- newX = bounds.x + bounds.width / 2;
- }
-
- if ((cursorOrientation & SWT.UP) != 0) {
- newY = bounds.y;
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- newY = bounds.y + bounds.height;
- } else {
- newY = bounds.y + bounds.height / 2;
- }
-
- /*
- * Convert to screen coordinates if needed
- */
- if (parent != null) {
- Point pt = parent.toDisplay (newX, newY);
- newX = pt.x;
- newY = pt.y;
- }
- if (movePointer) {
- display.setCursorLocation(newX, newY);
- }
-
- /*
- * If the client has not provided a custom cursor then determine
- * the appropriate resize cursor.
- */
- if (clientCursor == null) {
- Cursor newCursor = null;
- switch (cursorOrientation) {
- case SWT.UP:
- newCursor = new Cursor(display, SWT.CURSOR_SIZENS);
- break;
- case SWT.DOWN:
- newCursor = new Cursor(display, SWT.CURSOR_SIZENS);
- break;
- case SWT.LEFT:
- newCursor = new Cursor(display, SWT.CURSOR_SIZEWE);
- break;
- case SWT.RIGHT:
- newCursor = new Cursor(display, SWT.CURSOR_SIZEWE);
- break;
- case SWT.LEFT | SWT.UP:
- newCursor = new Cursor(display, SWT.CURSOR_SIZENWSE);
- break;
- case SWT.RIGHT | SWT.DOWN:
- newCursor = new Cursor(display, SWT.CURSOR_SIZENWSE);
- break;
- case SWT.LEFT | SWT.DOWN:
- newCursor = new Cursor(display, SWT.CURSOR_SIZENESW);
- break;
- case SWT.RIGHT | SWT.UP:
- newCursor = new Cursor(display, SWT.CURSOR_SIZENESW);
- break;
- default:
- newCursor = new Cursor(display, SWT.CURSOR_SIZEALL);
- break;
- }
- display.lockCursor = false;
- newCursor.handle.set();
- display.lockCursor = true;
- if (resizeCursor != null) {
- resizeCursor.dispose ();
- }
- resizeCursor = newCursor;
- }
-
- return new Point (newX, newY);
-}
-
-static int checkStyle (int style) {
- if ((style & (SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN)) == 0) {
- style |= SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN;
- }
- return style;
-}
-
-/**
- * Stops displaying the tracker rectangles. Note that this is not considered
- * to be a cancelation by the user.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void close () {
- checkWidget ();
- tracking = false;
-}
-Rectangle computeBounds () {
- if (rectangles.length == 0) return null;
- int xMin = rectangles [0].x;
- int yMin = rectangles [0].y;
- int xMax = rectangles [0].x + rectangles [0].width;
- int yMax = rectangles [0].y + rectangles [0].height;
-
- for (int i = 1; i < rectangles.length; i++) {
- if (rectangles [i].x < xMin) xMin = rectangles [i].x;
- if (rectangles [i].y < yMin) yMin = rectangles [i].y;
- int rectRight = rectangles [i].x + rectangles [i].width;
- if (rectRight > xMax) xMax = rectRight;
- int rectBottom = rectangles [i].y + rectangles [i].height;
- if (rectBottom > yMax) yMax = rectBottom;
- }
-
- return new Rectangle (xMin, yMin, xMax - xMin, yMax - yMin);
-}
-
-Rectangle [] computeProportions (Rectangle [] rects) {
- Rectangle [] result = new Rectangle [rects.length];
- bounds = computeBounds ();
- if (bounds != null) {
- for (int i = 0; i < rects.length; i++) {
- int x = 0, y = 0, width = 0, height = 0;
- if (bounds.width != 0) {
- x = (rects [i].x - bounds.x) * 100 / bounds.width;
- width = rects [i].width * 100 / bounds.width;
- } else {
- width = 100;
- }
- if (bounds.height != 0) {
- y = (rects [i].y - bounds.y) * 100 / bounds.height;
- height = rects [i].height * 100 / bounds.height;
- } else {
- height = 100;
- }
- result [i] = new Rectangle (x, y, width, height);
- }
- }
- return result;
-}
-
-void drawRectangles (NSWindow window, Rectangle [] rects, boolean erase) {
- NSGraphicsContext context = window.graphicsContext();
- NSGraphicsContext.static_saveGraphicsState();
- NSGraphicsContext.setCurrentContext(context);
- context.saveGraphicsState();
- Point parentOrigin;
- if (parent != null) {
- parentOrigin = display.map (parent, null, 0, 0);
- } else {
- parentOrigin = new Point (0, 0);
- }
- context.setCompositingOperation(erase ? OS.NSCompositeClear : OS.NSCompositeSourceOver);
- NSRect rectFrame = new NSRect();
- NSPoint globalPoint = new NSPoint();
- float /*double*/ screenHeight = display.getPrimaryFrame().height;
- for (int i=0; i<rects.length; i++) {
- Rectangle rect = rects [i];
- rectFrame.x = rect.x + parentOrigin.x;
- rectFrame.y = screenHeight - (int)((rect.y + parentOrigin.y) + rect.height);
- rectFrame.width = rect.width;
- rectFrame.height = rect.height;
- globalPoint.x = rectFrame.x;
- globalPoint.y = rectFrame.y;
- globalPoint = window.convertScreenToBase(globalPoint);
- rectFrame.x = globalPoint.x;
- rectFrame.y = globalPoint.y;
-
- if (erase) {
- rectFrame.width++;
- rectFrame.height++;
- NSBezierPath.fillRect(rectFrame);
- } else {
- rectFrame.x += 0.5f;
- rectFrame.y += 0.5f;
- NSBezierPath.strokeRect(rectFrame);
- }
- }
- if (!erase) context.flushGraphics();
- context.restoreGraphicsState();
- NSGraphicsContext.static_restoreGraphicsState();
-}
-
-/**
- * Returns the bounds that are being drawn, expressed relative to the parent
- * widget. If the parent is a <code>Display</code> then these are screen
- * coordinates.
- *
- * @return the bounds of the Rectangles being drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle [] getRectangles () {
- checkWidget();
- Rectangle [] result = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- result [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- return result;
-}
-
-/**
- * Returns <code>true</code> if the rectangles are drawn with a stippled line, <code>false</code> otherwise.
- *
- * @return the stippled effect of the rectangles
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getStippled () {
- checkWidget ();
- return stippled;
-}
-
-void mouse (NSEvent nsEvent) {
- NSPoint location;
- if (nsEvent == null || nsEvent.type() == OS.NSMouseMoved) {
- location = NSEvent.mouseLocation();
- } else {
- location = nsEvent.locationInWindow();
- location = nsEvent.window().convertBaseToScreen(location);
- }
- location.y = display.getPrimaryFrame().height - location.y;
- int newX = (int)location.x, newY = (int)location.y;
- if (newX != oldX || newY != oldY) {
- Rectangle [] oldRectangles = rectangles;
- Rectangle [] rectsToErase = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- rectsToErase [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- Event event = new Event ();
- event.x = newX;
- event.y = newY;
- if ((style & SWT.RESIZE) != 0) {
- boolean orientationInit = resizeRectangles (newX - oldX, newY - oldY);
- inEvent = true;
- sendEvent (SWT.Resize, event);
- inEvent = false;
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the move
- * event. If this happens, return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the resize event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- }
- else {
- draw = true;
- }
- if (draw) {
- drawRectangles (window, rectsToErase, true);
- drawRectangles (window, rectangles, false);
- }
- Point cursorPos = adjustResizeCursor (orientationInit);
- if (cursorPos != null) {
- newX = cursorPos.x;
- newY = cursorPos.y;
- }
- } else {
- moveRectangles (newX - oldX, newY - oldY);
- inEvent = true;
- sendEvent (SWT.Move, event);
- inEvent = false;
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the move
- * event. If this happens, return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the move event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (window, rectsToErase, true);
- drawRectangles (window, rectangles, false);
- }
- }
- oldX = newX; oldY = newY;
- }
- switch ((int)/*64*/nsEvent.type()) {
- case OS.NSLeftMouseUp:
- case OS.NSRightMouseUp:
- case OS.NSOtherMouseUp:
- tracking = false;
- }
-}
-
-void key (NSEvent nsEvent) {
- //TODO send event
-// if (!sendKeyEvent (SWT.KeyDown, theEvent)) return OS.noErr;
- int /*long*/ modifierFlags = nsEvent.modifierFlags();
- int stepSize = (modifierFlags & OS.NSControlKeyMask) != 0 ? STEPSIZE_SMALL : STEPSIZE_LARGE;
- int xChange = 0, yChange = 0;
- switch (nsEvent.keyCode()) {
- case 53: /* Esc */
- cancelled = true;
- tracking = false;
- break;
- case 76: /* KP Enter */
- case 36: /* Return */
- tracking = false;
- break;
- case 123: /* Left arrow */
- xChange = -stepSize;
- break;
- case 124: /* Right arrow */
- xChange = stepSize;
- break;
- case 126: /* Up arrow */
- yChange = -stepSize;
- break;
- case 125: /* Down arrow */
- yChange = stepSize;
- break;
- }
- if (xChange != 0 || yChange != 0) {
- Rectangle [] oldRectangles = rectangles;
- Rectangle [] rectsToErase = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- rectsToErase [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- Event event = new Event ();
- int newX = oldX + xChange;
- int newY = oldY + yChange;
- event.x = newX;
- event.y = newY;
- Point cursorPos;
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (xChange, yChange);
- inEvent = true;
- sendEvent (SWT.Resize, event);
- inEvent = false;
- /*
- * It is possible (but unlikely) that application
- * code could have disposed the widget in the move
- * event. If this happens return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the resize event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (window, rectsToErase, true);
- drawRectangles (window, rectangles, false);
- }
- cursorPos = adjustResizeCursor (true);
- } else {
- moveRectangles (xChange, yChange);
- inEvent = true;
- sendEvent (SWT.Move, event);
- inEvent = false;
- /*
- * It is possible (but unlikely) that application
- * code could have disposed the widget in the move
- * event. If this happens return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the move event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (window, rectsToErase, true);
- drawRectangles (window, rectangles, false);
- }
- cursorPos = adjustMoveCursor ();
- }
- if (cursorPos != null) {
- oldX = cursorPos.x;
- oldY = cursorPos.y;
- }
- }
-}
-
-void moveRectangles (int xChange, int yChange) {
- if (bounds == null) return;
- if (xChange < 0 && ((style & SWT.LEFT) == 0)) xChange = 0;
- if (xChange > 0 && ((style & SWT.RIGHT) == 0)) xChange = 0;
- if (yChange < 0 && ((style & SWT.UP) == 0)) yChange = 0;
- if (yChange > 0 && ((style & SWT.DOWN) == 0)) yChange = 0;
- if (xChange == 0 && yChange == 0) return;
- bounds.x += xChange; bounds.y += yChange;
- for (int i = 0; i < rectangles.length; i++) {
- rectangles [i].x += xChange;
- rectangles [i].y += yChange;
- }
-}
-
-/**
- * Displays the Tracker rectangles for manipulation by the user. Returns when
- * the user has either finished manipulating the rectangles or has cancelled the
- * Tracker.
- *
- * @return <code>true</code> if the user did not cancel the Tracker, <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean open () {
- checkWidget ();
- Display display = this.display;
- cancelled = false;
- tracking = true;
- window = (NSWindow)new NSWindow().alloc();
- NSArray screens = NSScreen.screens();
- float /*double*/ minX = Float.MAX_VALUE, maxX = Float.MIN_VALUE;
- float /*double*/ minY = Float.MAX_VALUE, maxY = Float.MIN_VALUE;
- int count = (int)/*64*/screens.count();
- for (int i = 0; i < count; i++) {
- NSScreen screen = new NSScreen(screens.objectAtIndex(i));
- NSRect frame = screen.frame();
- float /*double*/ x1 = frame.x, x2 = frame.x + frame.width;
- float /*double*/ y1 = frame.y, y2 = frame.y + frame.height;
- if (x1 < minX) minX = x1;
- if (x2 < minX) minX = x2;
- if (x1 > maxX) maxX = x1;
- if (x2 > maxX) maxX = x2;
- if (y1 < minY) minY = y1;
- if (y2 < minY) minY = y2;
- if (y1 > maxY) maxY = y1;
- if (y2 > maxY) maxY = y2;
- }
- NSRect frame = new NSRect();
- frame.x = minX;
- frame.y = minY;
- frame.width = maxX - minX;
- frame.height = maxY - minY;
- window = window.initWithContentRect(frame, OS.NSBorderlessWindowMask, OS.NSBackingStoreBuffered, false);
- window.setOpaque(false);
- window.setContentView(null);
- window.setBackgroundColor(NSColor.clearColor());
- NSGraphicsContext context = window.graphicsContext();
- NSGraphicsContext.static_saveGraphicsState();
- NSGraphicsContext.setCurrentContext(context);
- context.setCompositingOperation(OS.NSCompositeClear);
- frame.x = frame.y = 0;
- NSBezierPath.fillRect(frame);
- NSGraphicsContext.static_restoreGraphicsState();
- window.orderFrontRegardless();
-
- drawRectangles (window, rectangles, false);
-
- /*
- * If exactly one of UP/DOWN is specified as a style then set the cursor
- * orientation accordingly (the same is done for LEFT/RIGHT styles below).
- */
- int vStyle = style & (SWT.UP | SWT.DOWN);
- if (vStyle == SWT.UP || vStyle == SWT.DOWN) {
- cursorOrientation |= vStyle;
- }
- int hStyle = style & (SWT.LEFT | SWT.RIGHT);
- if (hStyle == SWT.LEFT || hStyle == SWT.RIGHT) {
- cursorOrientation |= hStyle;
- }
-
- Point cursorPos;
- boolean down = false;
- NSApplication application = NSApplication.sharedApplication();
- NSEvent currentEvent = application.currentEvent();
- if (currentEvent != null) {
- switch ((int)/*64*/currentEvent.type()) {
- case OS.NSLeftMouseDown:
- case OS.NSLeftMouseDragged:
- case OS.NSRightMouseDown:
- case OS.NSRightMouseDragged:
- case OS.NSOtherMouseDown:
- case OS.NSOtherMouseDragged:
- down = true;
- }
- }
- if (down) {
- cursorPos = display.getCursorLocation();
- } else {
- if ((style & SWT.RESIZE) != 0) {
- cursorPos = adjustResizeCursor (true);
- } else {
- cursorPos = adjustMoveCursor ();
- }
- }
- if (cursorPos != null) {
- oldX = cursorPos.x;
- oldY = cursorPos.y;
- }
-
- Control oldTrackingControl = display.trackingControl;
- display.trackingControl = null;
- /* Tracker behaves like a Dialog with its own OS event loop. */
- while (tracking && !cancelled) {
- display.addPool();
- try {
- NSEvent event = application.nextEventMatchingMask(0, NSDate.distantFuture(), OS.NSDefaultRunLoopMode, true);
- if (event == null) continue;
- int type = (int)/*64*/event.type();
- switch (type) {
- case OS.NSLeftMouseUp:
- case OS.NSRightMouseUp:
- case OS.NSOtherMouseUp:
- case OS.NSMouseMoved:
- case OS.NSLeftMouseDragged:
- case OS.NSRightMouseDragged:
- case OS.NSOtherMouseDragged:
- mouse(event);
- break;
- case OS.NSKeyDown:
-// case OS.NSKeyUp:
- case OS.NSFlagsChanged:
- key(event);
- break;
- }
- boolean dispatch = true;
- switch (type) {
- case OS.NSLeftMouseDown:
- case OS.NSLeftMouseUp:
- case OS.NSRightMouseDown:
- case OS.NSRightMouseUp:
- case OS.NSOtherMouseDown:
- case OS.NSOtherMouseUp:
- case OS.NSMouseMoved:
- case OS.NSLeftMouseDragged:
- case OS.NSRightMouseDragged:
- case OS.NSOtherMouseDragged:
- case OS.NSMouseEntered:
- case OS.NSMouseExited:
- case OS.NSKeyDown:
- case OS.NSKeyUp:
- case OS.NSFlagsChanged:
- dispatch = false;
- }
- if (dispatch) application.sendEvent(event);
- if (clientCursor != null && resizeCursor == null) {
- display.lockCursor = false;
- clientCursor.handle.set();
- display.lockCursor = true;
- }
- } finally {
- display.removePool();
- }
- }
- if (oldTrackingControl != null && !oldTrackingControl.isDisposed()) {
- display.trackingControl = oldTrackingControl;
- }
- display.setCursor(display.findControl(true));
- if (!isDisposed()) {
- drawRectangles (window, rectangles, true);
- }
- if (window != null) window.close();
- tracking = false;
- window = null;
- return !cancelled;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
- rectangles = proportions = null;
- bounds = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Resize, listener);
- eventTable.unhook (SWT.Move, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #addKeyListener
- */
-public void removeKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.KeyUp, listener);
- eventTable.unhook(SWT.KeyDown, listener);
-}
-
-/*
- * Returns true if the pointer's orientation was initialized in some dimension,
- * and false otherwise.
- */
-boolean resizeRectangles (int xChange, int yChange) {
- if (bounds == null) return false;
- boolean orientationInit = false;
- /*
- * If the cursor orientation has not been set in the orientation of
- * this change then try to set it here.
- */
- if (xChange < 0 && ((style & SWT.LEFT) != 0) && ((cursorOrientation & SWT.RIGHT) == 0)) {
- if ((cursorOrientation & SWT.LEFT) == 0) {
- cursorOrientation |= SWT.LEFT;
- orientationInit = true;
- }
- }
- if (xChange > 0 && ((style & SWT.RIGHT) != 0) && ((cursorOrientation & SWT.LEFT) == 0)) {
- if ((cursorOrientation & SWT.RIGHT) == 0) {
- cursorOrientation |= SWT.RIGHT;
- orientationInit = true;
- }
- }
- if (yChange < 0 && ((style & SWT.UP) != 0) && ((cursorOrientation & SWT.DOWN) == 0)) {
- if ((cursorOrientation & SWT.UP) == 0) {
- cursorOrientation |= SWT.UP;
- orientationInit = true;
- }
- }
- if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) {
- if ((cursorOrientation & SWT.DOWN) == 0) {
- cursorOrientation |= SWT.DOWN;
- orientationInit = true;
- }
- }
-
- /*
- * If the bounds will flip about the x or y axis then apply the adjustment
- * up to the axis (ie.- where bounds width/height becomes 0), change the
- * cursor's orientation accordingly, and flip each Rectangle's origin (only
- * necessary for > 1 Rectangles)
- */
- if ((cursorOrientation & SWT.LEFT) != 0) {
- if (xChange > bounds.width) {
- if ((style & SWT.RIGHT) == 0) return orientationInit;
- cursorOrientation |= SWT.RIGHT;
- cursorOrientation &= ~SWT.LEFT;
- bounds.x += bounds.width;
- xChange -= bounds.width;
- bounds.width = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.x = 100 - proportion.x - proportion.width;
- }
- }
- }
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- if (bounds.width < -xChange) {
- if ((style & SWT.LEFT) == 0) return orientationInit;
- cursorOrientation |= SWT.LEFT;
- cursorOrientation &= ~SWT.RIGHT;
- xChange += bounds.width;
- bounds.width = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.x = 100 - proportion.x - proportion.width;
- }
- }
- }
- }
- if ((cursorOrientation & SWT.UP) != 0) {
- if (yChange > bounds.height) {
- if ((style & SWT.DOWN) == 0) return orientationInit;
- cursorOrientation |= SWT.DOWN;
- cursorOrientation &= ~SWT.UP;
- bounds.y += bounds.height;
- yChange -= bounds.height;
- bounds.height = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.y = 100 - proportion.y - proportion.height;
- }
- }
- }
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- if (bounds.height < -yChange) {
- if ((style & SWT.UP) == 0) return orientationInit;
- cursorOrientation |= SWT.UP;
- cursorOrientation &= ~SWT.DOWN;
- yChange += bounds.height;
- bounds.height = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.y = 100 - proportion.y - proportion.height;
- }
- }
- }
- }
-
- // apply the bounds adjustment
- if ((cursorOrientation & SWT.LEFT) != 0) {
- bounds.x += xChange;
- bounds.width -= xChange;
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- bounds.width += xChange;
- }
- if ((cursorOrientation & SWT.UP) != 0) {
- bounds.y += yChange;
- bounds.height -= yChange;
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- bounds.height += yChange;
- }
-
- Rectangle [] newRects = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle proportion = proportions[i];
- newRects[i] = new Rectangle (
- proportion.x * bounds.width / 100 + bounds.x,
- proportion.y * bounds.height / 100 + bounds.y,
- proportion.width * bounds.width / 100,
- proportion.height * bounds.height / 100);
- }
- rectangles = newRects;
- return orientationInit;
-}
-
-/**
- * Sets the <code>Cursor</code> of the Tracker. If this cursor is <code>null</code>
- * then the cursor reverts to the default.
- *
- * @param newCursor the new <code>Cursor</code> to display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCursor (Cursor newCursor) {
- checkWidget ();
- clientCursor = newCursor;
- if (newCursor != null) {
- display.lockCursor = false;
- if (inEvent) newCursor.handle.set();
- display.lockCursor = true;
- }
-}
-
-/**
- * Specifies the rectangles that should be drawn, expressed relative to the parent
- * widget. If the parent is a Display then these are screen coordinates.
- *
- * @param rectangles the bounds of the rectangles to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of rectangles is null or contains a null rectangle</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setRectangles (Rectangle [] rectangles) {
- checkWidget ();
- if (rectangles == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = rectangles.length;
- this.rectangles = new Rectangle [length];
- for (int i = 0; i < length; i++) {
- Rectangle current = rectangles [i];
- if (current == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.rectangles [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- proportions = computeProportions (rectangles);
-}
-
-/**
- * Changes the appearance of the line used to draw the rectangles.
- *
- * @param stippled <code>true</code> if rectangle should appear stippled
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setStippled (boolean stippled) {
- checkWidget ();
- this.stippled = stippled;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TrayItem.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TrayItem.java
deleted file mode 100755
index ec0a782aa6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TrayItem.java
+++ /dev/null
@@ -1,537 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class represent icons that can be placed on the
- * system tray or task bar status area.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, MenuDetect, Selection</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tray">Tray, TrayItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.0
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TrayItem extends Item {
- Tray parent;
- ToolTip toolTip;
- String toolTipText;
- boolean visible = true, highlight;
- NSStatusItem item;
- NSImageView view;
-
- static final float BORDER = 8f;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tray</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TrayItem (Tray parent, int style) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
- createWidget ();
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the platform-specific context menu trigger
- * has occurred, by sending it one of the messages defined in
- * the <code>MenuDetectListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #removeMenuDetectListener
- *
- * @since 3.3
- */
-public void addMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MenuDetect, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the receiver is selected
- * <code>widgetDefaultSelected</code> is called when the receiver is double-clicked
- * </p>
- *
- * @param listener the listener which should be notified when the receiver is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createHandle () {
- NSStatusBar statusBar = NSStatusBar.systemStatusBar();
- item = statusBar.statusItemWithLength(0);
- if (item == null) error (SWT.ERROR_NO_HANDLES);
- item.retain();
- item.setHighlightMode(true);
- view = (NSImageView)new SWTImageView().alloc();
- if (view == null) error (SWT.ERROR_NO_HANDLES);
- view.init ();
- item.setView(view);
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (view);
- display.removeWidget(view.cell());
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-Point getLocation () {
- NSRect rect = view.frame();
- NSRect windowRect = view.window().frame();
- NSPoint pt = new NSPoint();
- pt.x = rect.width / 2;
- pt = view.convertPoint_fromView_(pt, null);
- pt.x += windowRect.x;
- return new Point ((int)pt.x, (int)pt.y);
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Tray</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Tray getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's tool tip, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public ToolTip getToolTip () {
- checkWidget ();
- return toolTip;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and
- * <code>false</code> otherwise.
- *
- * @return the receiver's visibility
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- return visible;
-}
-
-void register () {
- super.register ();
- display.addWidget (view, this);
- display.addWidget (((NSControl)view).cell(), this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
- if (item != null) item.release();
- if (view != null) view.release();
- item = null;
- view = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- NSStatusBar statusBar = NSStatusBar.systemStatusBar();
- statusBar.removeStatusItem(item);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the platform-specific context menu trigger has
- * occurred.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #addMenuDetectListener
- *
- * @since 3.3
- */
-public void removeMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MenuDetect, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Sets the receiver's image.
- *
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- super.setImage (image);
- float /*double*/ width = 0;
- if (image == null) {
- view.setImage (null);
- } else {
- /*
- * Feature in Cocoa. If the NSImage object being set into the view is
- * the same NSImage object that is already there then the new image is
- * not taken. This results in the view's image not changing even if the
- * NSImage object's content has changed since it was last set into the
- * view. The workaround is to temporarily set the view's image to null
- * so that the new image will then be taken.
- */
- NSImage current = view.image ();
- if (current != null && current.id == image.handle.id) {
- view.setImage (null);
- }
- view.setImage (image.handle);
- if (visible) {
- width = image.handle.size ().width + BORDER;
- }
- }
- item.setLength (width);
-}
-
-/**
- * Sets the receiver's tool tip to the argument, which
- * may be null indicating that no tool tip should be shown.
- *
- * @param toolTip the new tool tip (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setToolTip (ToolTip toolTip) {
- checkWidget ();
- ToolTip oldTip = this.toolTip, newTip = toolTip;
- if (oldTip != null) oldTip.item = null;
- this.toolTip = newTip;
- if (newTip != null) newTip.item = this;
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget ();
- toolTipText = string;
- _setToolTipText (string);
-}
-
-void _setToolTipText (String string) {
- if (string != null) {
- char[] chars = new char [string.length ()];
- string.getChars (0, chars.length, chars, 0);
- int length = fixMnemonic (chars);
- NSString str = NSString.stringWithCharacters (chars, length);
- view.setToolTip (str);
- } else {
- view.setToolTip (null);
- }
-}
-
-/**
- * Makes the receiver visible if the argument is <code>true</code>,
- * and makes it invisible otherwise.
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- if (this.visible == visible) return;
- if (visible) {
- sendEvent (SWT.Show);
- if (isDisposed ()) return;
- }
- this.visible = visible;
- float /*double*/ width = image != null && visible ? image.handle.size().width + BORDER : 0;
- item.setLength(width);
- if (!visible) sendEvent (SWT.Hide);
-}
-
-void showMenu (Menu menu) {
- display.trayItemMenu = menu;
- item.popUpStatusItemMenu(menu.nsMenu);
-}
-
-void showMenu () {
- _setToolTipText (null);
- Display display = this.display;
- display.currentTrayItem = this;
- sendEvent (SWT.MenuDetect);
- if (!isDisposed ()) display.runPopups();
- display.currentTrayItem = null;
- if (isDisposed ()) return;
- _setToolTipText (toolTipText);
-}
-
-void displayMenu () {
- if (highlight) {
- view.display();
- display.trayItemMenu = null;
- showMenu();
- if (display.trayItemMenu != null) {
- display.trayItemMenu = null;
- highlight = false;
- view.setNeedsDisplay(true);
- }
- }
-}
-
-boolean shouldShowMenu (NSEvent event) {
- if (!hooks(SWT.MenuDetect)) return false;
- switch ((int)/*64*/event.type()) {
- case OS.NSRightMouseDown: return true;
- case OS.NSLeftMouseDown:
- if (!(hooks(SWT.Selection) || hooks(SWT.DefaultSelection))) {
- return true;
- }
- if ((event.modifierFlags() & OS.NSDeviceIndependentModifierFlagsMask) == OS.NSControlKeyMask) {
- return true;
- }
- return false;
- case OS.NSLeftMouseDragged:
- case OS.NSRightMouseDragged:
- return true;
- }
- return false;
-}
-
-void mouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- NSEvent nsEvent = new NSEvent(theEvent);
- highlight = true;
- view.setNeedsDisplay(true);
- if (shouldShowMenu(nsEvent)) displayMenu();
-}
-
-void mouseDragged(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- NSEvent nsEvent = new NSEvent(theEvent);
- NSRect frame = view.frame();
- highlight = OS.NSPointInRect(nsEvent.locationInWindow(), frame);
- view.setNeedsDisplay(true);
- if (shouldShowMenu(nsEvent)) displayMenu();
-}
-
-void mouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (highlight) {
- NSEvent nsEvent = new NSEvent(theEvent);
- if (nsEvent.type() == OS.NSLeftMouseUp) {
- postEvent(nsEvent.clickCount() == 2 ? SWT.DefaultSelection : SWT.Selection);
- }
- }
- highlight = false;
- view.setNeedsDisplay(true);
-}
-
-void rightMouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- mouseDown(id, sel, theEvent);
-}
-
-void rightMouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- mouseUp(id, sel, theEvent);
-}
-
-void rightMouseDragged(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- mouseDragged(id, sel, theEvent);
-}
-
-void drawRect(int /*long*/ id, int /*long*/ sel, NSRect rect) {
- item.drawStatusBarBackgroundInRect(rect, highlight);
- super.drawRect(id, sel, rect);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java
deleted file mode 100755
index efac0d6428..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java
+++ /dev/null
@@ -1,2974 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.accessibility.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class provide a selectable user interface object
- * that displays a hierarchy of items and issues notification when an
- * item in the hierarchy is selected.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TreeItem</code>.
- * </p><p>
- * Style <code>VIRTUAL</code> is used to create a <code>Tree</code> whose
- * <code>TreeItem</code>s are to be populated by the client on an on-demand basis
- * instead of up-front. This can provide significant performance improvements for
- * trees that are very large or for which <code>TreeItem</code> population is
- * expensive (for example, retrieving values from an external source).
- * </p><p>
- * Here is an example of using a <code>Tree</code> with style <code>VIRTUAL</code>:
- * <code><pre>
- * final Tree tree = new Tree(parent, SWT.VIRTUAL | SWT.BORDER);
- * tree.setItemCount(20);
- * tree.addListener(SWT.SetData, new Listener() {
- * public void handleEvent(Event event) {
- * TreeItem item = (TreeItem)event.item;
- * TreeItem parentItem = item.getParentItem();
- * String text = null;
- * if (parentItem == null) {
- * text = "node " + tree.indexOf(item);
- * } else {
- * text = parentItem.getText() + " - " + parentItem.indexOf(item);
- * }
- * item.setText(text);
- * System.out.println(text);
- * item.setItemCount(10);
- * }
- * });
- * </pre></code>
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not normally make sense to add <code>Control</code> children to
- * it, or set a layout on it, unless implementing something like a cell
- * editor.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, VIRTUAL, NO_SCROLL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection, Collapse, Expand, SetData, MeasureItem, EraseItem, PaintItem</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles SINGLE and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Tree extends Composite {
- NSTableColumn firstColumn, checkColumn;
- NSTextFieldCell dataCell;
- NSButtonCell buttonCell;
- NSTableHeaderView headerView;
- TreeItem [] items;
- int itemCount;
- TreeColumn [] columns;
- TreeColumn sortColumn;
- int columnCount;
- int sortDirection;
- boolean ignoreExpand, ignoreSelect, ignoreRedraw, reloadPending, drawExpansion;
- Rectangle imageBounds;
- TreeItem insertItem;
- boolean insertBefore;
-
- static int NEXT_ID;
-
- static final int FIRST_COLUMN_MINIMUM_WIDTH = 5;
- static final int IMAGE_GAP = 3;
- static final int TEXT_GAP = 2;
- static final int CELL_GAP = 1;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#CHECK
- * @see SWT#FULL_SELECTION
- * @see SWT#VIRTUAL
- * @see SWT#NO_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Tree (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-void _addListener (int eventType, Listener listener) {
- super._addListener (eventType, listener);
- clearCachedWidth (items);
-}
-
-TreeItem _getItem (TreeItem parentItem, int index, boolean create) {
- int count;
- TreeItem[] items;
- if (parentItem != null) {
- count = parentItem.itemCount;
- items = parentItem.items;
- } else {
- count = this.itemCount;
- items = this.items;
- }
- if (index < 0 || index >= count) return null;
- TreeItem item = items [index];
- if (item != null || (style & SWT.VIRTUAL) == 0 || !create) return item;
- item = new TreeItem (this, parentItem, SWT.NONE, index, false);
- items [index] = item;
- return item;
-}
-
-int /*long*/ accessibilityAttributeValue (int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
-
- if (accessible != null) {
- NSString attribute = new NSString(arg0);
- id returnValue = accessible.internal_accessibilityAttributeValue(attribute, ACC.CHILDID_SELF);
- if (returnValue != null) return returnValue.id;
- }
-
- NSString attributeName = new NSString(arg0);
-
- // Accessibility Verifier queries for a title or description. NSOutlineView doesn't
- // seem to return either, so we return a default description value here.
- if (attributeName.isEqualToString (OS.NSAccessibilityDescriptionAttribute)) {
- return NSString.stringWith("").id;
- }
-
- return super.accessibilityAttributeValue(id, sel, arg0);
-}
-
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * If the receiver has the <code>SWT.CHECK</code> style and the check selection changes,
- * the event object detail field contains the value <code>SWT.CHECK</code>.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * The item field of the event object is valid for default selection, but the detail field is not used.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an item in the receiver is expanded or collapsed
- * by sending it one of the messages defined in the <code>TreeListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TreeListener
- * @see #removeTreeListener
- */
-public void addTreeListener(TreeListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Expand, typedListener);
- addListener (SWT.Collapse, typedListener);
-}
-
-int calculateWidth (TreeItem[] items, int index, GC gc, boolean recurse) {
- if (items == null) return 0;
- int width = 0;
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null) {
- int itemWidth = item.calculateWidth (index, gc);
- width = Math.max (width, itemWidth);
- if (recurse && item.getExpanded ()) {
- width = Math.max (width, calculateWidth (item.items, index, gc, recurse));
- }
- }
- }
- return width;
-}
-
-NSSize cellSize (int /*long*/ id, int /*long*/ sel) {
- NSSize size = super.cellSize(id, sel);
- NSImage image = new NSCell(id).image();
- if (image != null) size.width += imageBounds.width + IMAGE_GAP;
- if (hooks(SWT.MeasureItem)) {
- int /*long*/ [] outValue = new int /*long*/ [1];
- OS.object_getInstanceVariable(id, Display.SWT_ROW, outValue);
- TreeItem item = (TreeItem) display.getWidget (outValue [0]);
- OS.object_getInstanceVariable(id, Display.SWT_COLUMN, outValue);
- int /*long*/ tableColumn = outValue[0];
- int columnIndex = 0;
- for (int i=0; i<columnCount; i++) {
- if (columns [i].nsColumn.id == tableColumn) {
- columnIndex = i;
- break;
- }
- }
- sendMeasureItem (item, columnIndex, size);
- }
- return size;
-}
-
-boolean canDragRowsWithIndexes_atPoint(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1) {
- NSPoint clickPoint = new NSPoint();
- OS.memmove(clickPoint, arg1, NSPoint.sizeof);
- NSOutlineView tree = (NSOutlineView)view;
-
- // If the current row is not selected and the user is not attempting to modify the selection, select the row first.
- int /*long*/ row = tree.rowAtPoint(clickPoint);
- int /*long*/ modifiers = NSApplication.sharedApplication().currentEvent().modifierFlags();
-
- boolean drag = (state & DRAG_DETECT) != 0 && hooks (SWT.DragDetect);
- if (drag) {
- if (!tree.isRowSelected(row) && (modifiers & (OS.NSCommandKeyMask | OS.NSShiftKeyMask | OS.NSAlternateKeyMask | OS.NSControlKeyMask)) == 0) {
- NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc();
- set = set.initWithIndex(row);
- tree.selectRowIndexes (set, false);
- set.release();
- }
- }
-
- // The clicked row must be selected to initiate a drag.
- return (tree.isRowSelected(row) && drag);
-}
-
-boolean checkData (TreeItem item) {
- if (item.cached) return true;
- if ((style & SWT.VIRTUAL) != 0) {
- item.cached = true;
- Event event = new Event ();
- TreeItem parentItem = item.getParentItem ();
- event.item = item;
- event.index = parentItem == null ? indexOf (item) : parentItem.indexOf (item);
- ignoreRedraw = true;
- sendEvent (SWT.SetData, event);
- //widget could be disposed at this point
- ignoreRedraw = false;
- if (isDisposed () || item.isDisposed ()) return false;
- if (!setScrollWidth (item)) item.redraw (-1);
- }
- return true;
-}
-
-static int checkStyle (int style) {
- /*
- * Feature in Windows. Even when WS_HSCROLL or
- * WS_VSCROLL is not specified, Windows creates
- * trees and tables with scroll bars. The fix
- * is to set H_SCROLL and V_SCROLL.
- *
- * NOTE: This code appears on all platforms so that
- * applications have consistent scroll bar behavior.
- */
- if ((style & SWT.NO_SCROLL) == 0) {
- style |= SWT.H_SCROLL | SWT.V_SCROLL;
- }
- /* This platform is always FULL_SELECTION */
- style |= SWT.FULL_SELECTION;
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void checkItems () {
- if (!reloadPending) return;
- reloadPending = false;
- TreeItem[] selectedItems = getSelection ();
- ((NSOutlineView)view).reloadData ();
- selectItems (selectedItems, true);
- ignoreExpand = true;
- for (int i = 0; i < itemCount; i++) {
- if (items[i] != null) items[i].updateExpanded ();
- }
- ignoreExpand = false;
-}
-
-void clear (TreeItem parentItem, int index, boolean all) {
- TreeItem item = _getItem (parentItem, index, false);
- if (item != null) {
- item.clear();
- item.redraw (-1);
- if (all) {
- clearAll (item, true);
- }
- }
-}
-
-void clearAll (TreeItem parentItem, boolean all) {
- int count = getItemCount (parentItem);
- if (count == 0) return;
- TreeItem [] children = parentItem == null ? items : parentItem.items;
- for (int i=0; i<count; i++) {
- TreeItem item = children [i];
- if (item != null) {
- item.clear ();
- item.redraw (-1);
- if (all) clearAll (item, true);
- }
- }
-}
-
-/**
- * Clears the item at the given zero-relative index in the receiver.
- * The text, icon and other attributes of the item are set to the default
- * value. If the tree was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param index the index of the item to clear
- * @param all <code>true</code> if all child items of the indexed item should be
- * cleared recursively, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clear (int index, boolean all) {
- checkWidget ();
- int count = getItemCount ();
- if (index < 0 || index >= count) error (SWT.ERROR_INVALID_RANGE);
- clear (null, index, all);
-}
-
-/**
- * Clears all the items in the receiver. The text, icon and other
- * attributes of the items are set to their default values. If the
- * tree was created with the <code>SWT.VIRTUAL</code> style, these
- * attributes are requested again as needed.
- *
- * @param all <code>true</code> if all child items should be cleared
- * recursively, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clearAll (boolean all) {
- checkWidget ();
- clearAll (null, all);
-}
-
-void clearCachedWidth (TreeItem[] items) {
- if (items == null) return;
- for (int i = 0; i < items.length; i++) {
- TreeItem item = items [i];
- if (item == null) break;
- item.width = -1;
- clearCachedWidth (item.items);
- }
-}
-
-void collapseItem_collapseChildren (int /*long*/ id, int /*long*/ sel, int /*long*/ itemID, boolean children) {
- TreeItem item = (TreeItem)display.getWidget(itemID);
- if (!ignoreExpand) item.sendExpand (false, children);
- ignoreExpand = true;
- super.collapseItem_collapseChildren (id, sel, itemID, children);
- ignoreExpand = false;
- if (isDisposed() || item.isDisposed()) return;
- setScrollWidth ();
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0;
- if (wHint == SWT.DEFAULT) {
- if (columnCount != 0) {
- for (int i=0; i<columnCount; i++) {
- width += columns [i].getWidth ();
- }
- } else {
- GC gc = new GC (this);
- width = calculateWidth (items, 0, gc, true) + CELL_GAP;
- gc.dispose ();
- }
- if ((style & SWT.CHECK) != 0) width += getCheckColumnWidth ();
- } else {
- width = wHint;
- }
- if (hHint == SWT.DEFAULT) {
- height = (int)/*64*/((NSOutlineView) view).numberOfRows () * getItemHeight () + getHeaderHeight ();
- } else {
- height = hHint;
- }
- if (width <= 0) width = DEFAULT_WIDTH;
- if (height <= 0) height = DEFAULT_HEIGHT;
- Rectangle rect = computeTrim (0, 0, width, height);
- return new Point (rect.width, rect.height);
-}
-
-void createColumn (TreeItem item, int index) {
- if (item.items != null) {
- for (int i = 0; i < item.items.length; i++) {
- if (item.items[i] != null) createColumn (item.items[i], index);
- }
- }
- String [] strings = item.strings;
- if (strings != null) {
- String [] temp = new String [columnCount];
- System.arraycopy (strings, 0, temp, 0, index);
- System.arraycopy (strings, index, temp, index+1, columnCount-index-1);
- temp [index] = "";
- item.strings = temp;
- }
- if (index == 0) item.text = "";
- Image [] images = item.images;
- if (images != null) {
- Image [] temp = new Image [columnCount];
- System.arraycopy (images, 0, temp, 0, index);
- System.arraycopy (images, index, temp, index+1, columnCount-index-1);
- item.images = temp;
- }
- if (index == 0) item.image = null;
- Color [] cellBackground = item.cellBackground;
- if (cellBackground != null) {
- Color [] temp = new Color [columnCount];
- System.arraycopy (cellBackground, 0, temp, 0, index);
- System.arraycopy (cellBackground, index, temp, index+1, columnCount-index-1);
- item.cellBackground = temp;
- }
- Color [] cellForeground = item.cellForeground;
- if (cellForeground != null) {
- Color [] temp = new Color [columnCount];
- System.arraycopy (cellForeground, 0, temp, 0, index);
- System.arraycopy (cellForeground, index, temp, index+1, columnCount-index-1);
- item.cellForeground = temp;
- }
- Font [] cellFont = item.cellFont;
- if (cellFont != null) {
- Font [] temp = new Font [columnCount];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index, temp, index+1, columnCount-index-1);
- item.cellFont = temp;
- }
-}
-
-void createHandle () {
- NSScrollView scrollWidget = (NSScrollView) new SWTScrollView ().alloc ();
- scrollWidget.init ();
- scrollWidget.setHasHorizontalScroller ((style & SWT.H_SCROLL) != 0);
- scrollWidget.setHasVerticalScroller ((style & SWT.V_SCROLL) != 0);
- scrollWidget.setAutohidesScrollers (true);
- scrollWidget.setBorderType(hasBorder () ? OS.NSBezelBorder : OS.NSNoBorder);
-
- NSOutlineView widget = (NSOutlineView) new SWTOutlineView ().alloc ();
- /*
- * Bug in Cocoa. Calling init, instead of initWithFrame on an NSOutlineView
- * cause the NSOutlineView to leak some memory. The work around is to call
- * initWithFrame and pass an empty NSRect instead of calling init.
- */
- widget.initWithFrame(new NSRect());
- widget.setAllowsMultipleSelection ((style & SWT.MULTI) != 0);
- widget.setAllowsColumnReordering (false);
- widget.setAutoresizesOutlineColumn (false);
- widget.setAutosaveExpandedItems (true);
- widget.setDataSource (widget);
- widget.setDelegate (widget);
- widget.setColumnAutoresizingStyle (OS.NSTableViewNoColumnAutoresizing);
- NSSize spacing = new NSSize();
- spacing.width = spacing.height = CELL_GAP;
- widget.setIntercellSpacing(spacing);
- widget.setDoubleAction (OS.sel_sendDoubleSelection);
- if (!hasBorder ()) widget.setFocusRingType (OS.NSFocusRingTypeNone);
-
- headerView = (NSTableHeaderView)new SWTTableHeaderView ().alloc ().init ();
- widget.setHeaderView (null);
-
- NSString str = NSString.stringWith (""); //$NON-NLS-1$
- if ((style & SWT.CHECK) != 0) {
- checkColumn = (NSTableColumn) new NSTableColumn ().alloc ();
- checkColumn = checkColumn.initWithIdentifier(NSString.stringWith(String.valueOf(++NEXT_ID)));
- checkColumn.headerCell ().setTitle (str);
- widget.addTableColumn (checkColumn);
- widget.setOutlineTableColumn (checkColumn);
- checkColumn.setResizingMask (OS.NSTableColumnNoResizing);
- checkColumn.setEditable (false);
- int /*long*/ cls = NSButton.cellClass (); /* use our custom cell class */
- buttonCell = new NSButtonCell (OS.class_createInstance (cls, 0));
- buttonCell.init ();
- checkColumn.setDataCell (buttonCell);
- buttonCell.setButtonType (OS.NSSwitchButton);
- buttonCell.setImagePosition (OS.NSImageOnly);
- buttonCell.setAllowsMixedState (true);
- checkColumn.setWidth (getCheckColumnWidth ());
- }
-
- firstColumn = (NSTableColumn) new NSTableColumn ().alloc ();
- firstColumn = firstColumn.initWithIdentifier(NSString.stringWith(String.valueOf(++NEXT_ID)));
- /*
- * Feature in Cocoa. If a column's width is too small to show any content
- * then outlineView_objectValueForTableColumn_byItem is never invoked to
- * query for item values, which is a problem for VIRTUAL Trees. The
- * workaround is to ensure that, for 0-column Trees, the internal first
- * column always has a minimal width that makes this call come in.
- */
- firstColumn.setMinWidth (FIRST_COLUMN_MINIMUM_WIDTH);
- firstColumn.setWidth(0);
- firstColumn.setResizingMask (OS.NSTableColumnNoResizing);
- firstColumn.headerCell ().setTitle (str);
- widget.addTableColumn (firstColumn);
- widget.setOutlineTableColumn (firstColumn);
- dataCell = (NSTextFieldCell)new SWTImageTextCell ().alloc ().init ();
- dataCell.setLineBreakMode(OS.NSLineBreakByClipping);
- firstColumn.setDataCell (dataCell);
-
- scrollView = scrollWidget;
- view = widget;
-}
-
-void createItem (TreeColumn column, int index) {
- if (!(0 <= index && index <= columnCount)) error (SWT.ERROR_INVALID_RANGE);
- if (index == 0) {
- // first column must be left aligned
- column.style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- column.style |= SWT.LEFT;
- }
- if (columnCount == columns.length) {
- TreeColumn [] newColumns = new TreeColumn [columnCount + 4];
- System.arraycopy (columns, 0, newColumns, 0, columns.length);
- columns = newColumns;
- }
- NSTableColumn nsColumn;
- if (columnCount == 0) {
- //TODO - clear attributes, alignment etc.
- nsColumn = firstColumn;
- nsColumn.setMinWidth (0);
- nsColumn.setResizingMask (OS.NSTableColumnUserResizingMask);
- firstColumn = null;
- } else {
- //TODO - set attributes, alignment etc.
- NSOutlineView outlineView = (NSOutlineView)view;
- NSString str = NSString.stringWith ("");
- nsColumn = (NSTableColumn) new NSTableColumn ().alloc ();
- nsColumn = nsColumn.initWithIdentifier(NSString.stringWith(String.valueOf(++NEXT_ID)));
- nsColumn.setMinWidth(0);
- nsColumn.headerCell ().setTitle (str);
- outlineView.addTableColumn (nsColumn);
- int checkColumn = (style & SWT.CHECK) != 0 ? 1 : 0;
- outlineView.moveColumn (columnCount + checkColumn, index + checkColumn);
- nsColumn.setDataCell (dataCell);
- if (index == 0) {
- outlineView.setOutlineTableColumn (nsColumn);
- }
- }
- column.createJNIRef ();
- NSTableHeaderCell headerCell = (NSTableHeaderCell)new SWTTableHeaderCell ().alloc ().init ();
- nsColumn.setHeaderCell (headerCell);
- display.addWidget (headerCell, column);
- column.nsColumn = nsColumn;
- nsColumn.setWidth (0);
- System.arraycopy (columns, index, columns, index + 1, columnCount++ - index);
- columns [index] = column;
- for (int i = 0; i < itemCount; i++) {
- TreeItem item = items [i];
- if (item != null) {
- if (columnCount > 1) {
- createColumn (item, index);
- }
- }
- }
-}
-
-void createItem (TreeItem item, TreeItem parentItem, int index) {
- int count;
- TreeItem [] items;
- if (parentItem != null) {
- count = parentItem.itemCount;
- items = parentItem.items;
- } else {
- count = this.itemCount;
- items = this.items;
- }
- if (index == -1) index = count;
- if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
- if (count == items.length) {
- TreeItem [] newItems = new TreeItem [items.length + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- if (parentItem != null) {
- parentItem.items = items;
- } else {
- this.items = items;
- }
- }
- System.arraycopy (items, index, items, index + 1, count++ - index);
- items [index] = item;
- item.items = new TreeItem [4];
- SWTTreeItem handle = (SWTTreeItem) new SWTTreeItem ().alloc ().init ();
- item.handle = handle;
- item.createJNIRef ();
- item.register ();
- if (parentItem != null) {
- parentItem.itemCount = count;
- } else {
- this.itemCount = count;
- }
- ignoreExpand = true;
- reloadItem (parentItem, true);
- if (parentItem != null && parentItem.itemCount == 1 && parentItem.expanded) {
- ((NSOutlineView)view).expandItem (parentItem.handle);
- }
- ignoreExpand = false;
-}
-
-void createWidget () {
- super.createWidget ();
- items = new TreeItem [4];
- columns = new TreeColumn [4];
-}
-
-Color defaultBackground () {
- return display.getWidgetColor (SWT.COLOR_LIST_BACKGROUND);
-}
-
-NSFont defaultNSFont () {
- return display.outlineViewFont;
-}
-
-Color defaultForeground () {
- return display.getWidgetColor (SWT.COLOR_LIST_FOREGROUND);
-}
-
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll () {
- checkWidget ();
- NSTableView widget = (NSOutlineView) view;
- ignoreSelect = true;
- widget.deselectAll (null);
- ignoreSelect = false;
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (headerView);
- display.removeWidget (dataCell);
- if (buttonCell != null) display.removeWidget (buttonCell);
-}
-
-/**
- * Deselects an item in the receiver. If the item was already
- * deselected, it remains deselected.
- *
- * @param item the item to be deselected
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void deselect (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- NSOutlineView widget = (NSOutlineView)view;
- int /*long*/ row = widget.rowForItem(item.handle);
- ignoreSelect = true;
- widget.deselectRow (row);
- ignoreSelect = false;
-}
-
-void destroyItem (TreeColumn column) {
- int index = 0;
- while (index < columnCount) {
- if (columns [index] == column) break;
- index++;
- }
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null) {
- if (columnCount <= 1) {
- item.strings = null;
- item.images = null;
- item.cellBackground = null;
- item.cellForeground = null;
- item.cellFont = null;
- } else {
- if (item.strings != null) {
- String [] strings = item.strings;
- if (index == 0) {
- item.text = strings [1] != null ? strings [1] : "";
- }
- String [] temp = new String [columnCount - 1];
- System.arraycopy (strings, 0, temp, 0, index);
- System.arraycopy (strings, index + 1, temp, index, columnCount - 1 - index);
- item.strings = temp;
- } else {
- if (index == 0) item.text = "";
- }
- if (item.images != null) {
- Image [] images = item.images;
- if (index == 0) item.image = images [1];
- Image [] temp = new Image [columnCount - 1];
- System.arraycopy (images, 0, temp, 0, index);
- System.arraycopy (images, index + 1, temp, index, columnCount - 1 - index);
- item.images = temp;
- } else {
- if (index == 0) item.image = null;
- }
- if (item.cellBackground != null) {
- Color [] cellBackground = item.cellBackground;
- Color [] temp = new Color [columnCount - 1];
- System.arraycopy (cellBackground, 0, temp, 0, index);
- System.arraycopy (cellBackground, index + 1, temp, index, columnCount - 1 - index);
- item.cellBackground = temp;
- }
- if (item.cellForeground != null) {
- Color [] cellForeground = item.cellForeground;
- Color [] temp = new Color [columnCount - 1];
- System.arraycopy (cellForeground, 0, temp, 0, index);
- System.arraycopy (cellForeground, index + 1, temp, index, columnCount - 1 - index);
- item.cellForeground = temp;
- }
- if (item.cellFont != null) {
- Font [] cellFont = item.cellFont;
- Font [] temp = new Font [columnCount - 1];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index + 1, temp, index, columnCount - 1 - index);
- item.cellFont = temp;
- }
- }
- }
- }
-
- int oldIndex = indexOf (column.nsColumn);
-
- System.arraycopy (columns, index + 1, columns, index, --columnCount - index);
- columns [columnCount] = null;
- if (columnCount == 0) {
- //TODO - reset attributes
- firstColumn = column.nsColumn;
- firstColumn.retain ();
- /*
- * Feature in Cocoa. If a column's width is too small to show any content
- * then outlineView_objectValueForTableColumn_byItem is never invoked to
- * query for item values, which is a problem for VIRTUAL Trees. The
- * workaround is to ensure that, for 0-column Trees, the internal first
- * column always has a minimal width that makes this call come in.
- */
- firstColumn.setMinWidth (FIRST_COLUMN_MINIMUM_WIDTH);
- firstColumn.setResizingMask (OS.NSTableColumnNoResizing);
- setScrollWidth ();
- } else {
- if (index == 0) {
- ((NSOutlineView)view).setOutlineTableColumn(columns[0].nsColumn);
- }
- ((NSOutlineView)view).removeTableColumn(column.nsColumn);
- }
-
- NSArray array = ((NSOutlineView)view).tableColumns ();
- int arraySize = (int)/*64*/array.count ();
- for (int i = oldIndex; i < arraySize; i++) {
- int /*long*/ columnId = array.objectAtIndex (i).id;
- for (int j = 0; j < columnCount; j++) {
- if (columns[j].nsColumn.id == columnId) {
- columns [j].sendEvent (SWT.Move);
- break;
- }
- }
- }
-}
-
-void destroyItem (TreeItem item) {
- int count;
- TreeItem[] items;
- TreeItem parentItem = item.parentItem;
- if (parentItem != null) {
- count = parentItem.itemCount;
- items = parentItem.items;
- } else {
- count = this.itemCount;
- items = this.items;
- }
- int index = 0;
- while (index < count) {
- if (items [index] == item) break;
- index++;
- }
- System.arraycopy (items, index + 1, items, index, --count - index);
- items [count] = null;
- if (parentItem != null) {
- parentItem.itemCount = count;
- } else {
- this.itemCount = count;
- }
- reloadItem (parentItem, true);
- setScrollWidth ();
- if (this.itemCount == 0) imageBounds = null;
-}
-
-boolean dragDetect(int x, int y, boolean filter, boolean[] consume) {
- // Let Cocoa determine if a drag is starting and fire the notification when we get the callback.
- return false;
-}
-
-void drawInteriorWithFrame_inView (int /*long*/ id, int /*long*/ sel, NSRect rect, int /*long*/ view) {
- boolean hooksErase = hooks (SWT.EraseItem);
- boolean hooksPaint = hooks (SWT.PaintItem);
- boolean hooksMeasure = hooks (SWT.MeasureItem);
-
- NSTextFieldCell cell = new NSTextFieldCell (id);
-
- NSOutlineView widget = (NSOutlineView)this.view;
- int /*long*/ [] outValue = new int /*long*/ [1];
- OS.object_getInstanceVariable(id, Display.SWT_ROW, outValue);
- TreeItem item = (TreeItem) display.getWidget (outValue [0]);
- int /*long*/ rowIndex = widget.rowForItem(item.handle);
- OS.object_getInstanceVariable(id, Display.SWT_COLUMN, outValue);
- int /*long*/ tableColumn = outValue[0];
- int /*long*/ nsColumnIndex = widget.tableColumns().indexOfObjectIdenticalTo(new id(tableColumn));
- int columnIndex = 0;
- for (int i=0; i<columnCount; i++) {
- if (columns [i].nsColumn.id == tableColumn) {
- columnIndex = i;
- break;
- }
- }
-
- Color background = item.cellBackground != null ? item.cellBackground [columnIndex] : null;
- if (background == null) background = item.background;
- boolean drawBackground = background != null;
- boolean drawForeground = true;
- boolean isSelected = cell.isHighlighted();
- boolean drawSelection = isSelected;
- boolean hasFocus = hooksErase && hasFocus ();
-
- Color selectionBackground = null, selectionForeground = null;
- if (isSelected && (hooksErase || hooksPaint)) {
- selectionForeground = Color.cocoa_new(display, hasFocus ? display.alternateSelectedControlTextColor : display.selectedControlTextColor);
- selectionBackground = Color.cocoa_new(display, hasFocus ? display.alternateSelectedControlColor : display.secondarySelectedControlColor);
- }
-
- NSSize contentSize = super.cellSize(id, OS.sel_cellSize);
- NSImage image = cell.image();
- if (image != null) contentSize.width += imageBounds.width + IMAGE_GAP;
- int contentWidth = (int)Math.ceil (contentSize.width);
- NSSize spacing = widget.intercellSpacing();
- int itemHeight = (int)Math.ceil (widget.rowHeight() + spacing.height);
-
- NSRect cellRect = widget.rectOfColumn (nsColumnIndex);
- cellRect.y = rect.y;
- cellRect.height = rect.height + spacing.height;
- if (columnCount == 0) {
- NSRect rowRect = widget.rectOfRow (rowIndex);
- cellRect.width = rowRect.width;
- }
- float /*double*/ offsetX = 0, offsetY = 0;
- if (hooksPaint || hooksErase) {
- NSRect frameCell = widget.frameOfCellAtColumn(nsColumnIndex, rowIndex);
- offsetX = rect.x - frameCell.x;
- offsetY = rect.y - frameCell.y;
- if (drawExpansion) {
- offsetX -= 0.5f;
- offsetY -= 0.5f;
- }
- }
- int itemX = (int)(rect.x - offsetX), itemY = (int)(rect.y - offsetY);
- NSGraphicsContext context = NSGraphicsContext.currentContext ();
-
- if (hooksMeasure) {
- sendMeasureItem(item, columnIndex, contentSize);
- }
-
- Color userForeground = null;
- if (hooksErase) {
- context.saveGraphicsState();
- NSAffineTransform transform = NSAffineTransform.transform();
- transform.translateXBy(offsetX, offsetY);
- transform.concat();
-
- GCData data = new GCData ();
- data.paintRect = cellRect;
- GC gc = GC.cocoa_new (this, data);
- gc.setFont (item.getFont (columnIndex));
- if (isSelected) {
- gc.setForeground (selectionForeground);
- gc.setBackground (selectionBackground);
- } else {
- gc.setForeground (item.getForeground (columnIndex));
- gc.setBackground (item.getBackground (columnIndex));
- }
- if (!drawExpansion) {
- gc.setClipping ((int)(cellRect.x - offsetX), (int)(cellRect.y - offsetY), (int)cellRect.width, (int)cellRect.height);
- }
- Event event = new Event ();
- event.item = item;
- event.gc = gc;
- event.index = columnIndex;
- event.detail = SWT.FOREGROUND;
- if (drawBackground) event.detail |= SWT.BACKGROUND;
- if (isSelected) event.detail |= SWT.SELECTED;
- event.x = (int)cellRect.x;
- event.y = (int)cellRect.y;
- event.width = (int)cellRect.width;
- event.height = (int)cellRect.height;
- sendEvent (SWT.EraseItem, event);
- if (!event.doit) {
- drawForeground = drawBackground = drawSelection = false;
- } else {
- drawBackground = drawBackground && (event.detail & SWT.BACKGROUND) != 0;
- drawForeground = (event.detail & SWT.FOREGROUND) != 0;
- drawSelection = drawSelection && (event.detail & SWT.SELECTED) != 0;
- }
- if (!drawSelection && isSelected) {
- userForeground = Color.cocoa_new(display, gc.getForeground().handle);
- }
- gc.dispose ();
-
- context.restoreGraphicsState();
-
- if (isDisposed ()) return;
- if (item.isDisposed ()) return;
-
- if (drawSelection && ((style & SWT.HIDE_SELECTION) == 0 || hasFocus)) {
- cellRect.height -= spacing.height;
- callSuper (widget.id, OS.sel_highlightSelectionInClipRect_, cellRect);
- cellRect.height += spacing.height;
- }
- }
-
- if (drawBackground && !drawSelection) {
- context.saveGraphicsState ();
- float /*double*/ [] colorRGB = background.handle;
- NSColor color = NSColor.colorWithDeviceRed (colorRGB[0], colorRGB[1], colorRGB[2], 1f);
- color.setFill ();
- NSBezierPath.fillRect (cellRect);
- context.restoreGraphicsState ();
- }
-
- if (insertItem != null && !insertItem.isDisposed()) {
- context.saveGraphicsState ();
- NSRect contentRect = cell.titleRectForBounds (rect);
- GCData data = new GCData ();
- data.paintRect = contentRect;
- GC gc = GC.cocoa_new (this, data);
- gc.setClipping ((int)(contentRect.x - offsetX), (int)(contentRect.y - offsetY), (int)contentRect.width, (int)contentRect.height);
- Rectangle itemRect = insertItem.getImageBounds(0).union(insertItem.getBounds());
- Rectangle clientRect = getClientArea();
- int x = clientRect.x + clientRect.width;
- int posY = insertBefore ? itemRect.y : itemRect.y + itemRect.height - 1;
- gc.drawLine(itemRect.x, posY, x, posY);
- gc.dispose ();
- context.restoreGraphicsState ();
- }
-
- if (drawForeground) {
- if ((!drawExpansion || hooksMeasure) && image != null) {
- NSRect destRect = new NSRect();
- destRect.x = rect.x + IMAGE_GAP;
- destRect.y = rect.y + (float)Math.ceil((rect.height - imageBounds.height) / 2);
- destRect.width = imageBounds.width;
- destRect.height = imageBounds.height;
- NSRect srcRect = new NSRect();
- NSSize size = image.size();
- srcRect.width = size.width;
- srcRect.height = size.height;
- context.saveGraphicsState();
- NSBezierPath.bezierPathWithRect(rect).addClip();
- NSAffineTransform transform = NSAffineTransform.transform();
- transform.scaleXBy(1, -1);
- transform.translateXBy(0, -(destRect.height + 2 * destRect.y));
- transform.concat();
- image.drawInRect(destRect, srcRect, OS.NSCompositeSourceOver, 1);
- context.restoreGraphicsState();
- int imageWidth = imageBounds.width + IMAGE_GAP;
- rect.x += imageWidth;
- rect.width -= imageWidth;
- }
- cell.setHighlighted (false);
- boolean callSuper = false;
- if (userForeground != null) {
- /*
- * Bug in Cocoa. For some reason, it is not possible to change the
- * foreground color to black when the cell is highlighted. The text
- * still draws white. The fix is to draw the text and not call super.
- */
- float /*double*/ [] color = userForeground.handle;
- if (color[0] == 0 && color[1] == 0 && color[2] == 0 && color[3] == 1) {
- NSMutableAttributedString newStr = new NSMutableAttributedString(cell.attributedStringValue().mutableCopy());
- NSRange range = new NSRange();
- range.length = newStr.length();
- newStr.removeAttribute(OS.NSForegroundColorAttributeName, range);
- NSRect newRect = new NSRect();
- newRect.x = rect.x + TEXT_GAP;
- newRect.y = rect.y;
- newRect.width = rect.width - TEXT_GAP;
- newRect.height = rect.height;
- NSSize size = newStr.size();
- if (newRect.height > size.height) {
- newRect.y += (newRect.height - size.height) / 2;
- newRect.height = size.height;
- }
- newStr.drawInRect(newRect);
- newStr.release();
- } else {
- NSColor nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], color[3]);
- cell.setTextColor(nsColor);
- callSuper = true;
- }
- } else {
- callSuper = true;
- }
- if (callSuper) {
- NSAttributedString attrStr = cell.attributedStringValue();
- NSSize size = attrStr.size();
- if (rect.height > size.height) {
- rect.y += (rect.height - size.height) / 2;
- rect.height = size.height;
- }
- super.drawInteriorWithFrame_inView(id, sel, rect, view);
- }
- }
-
- if (hooksPaint) {
- context.saveGraphicsState();
- NSAffineTransform transform = NSAffineTransform.transform();
- transform.translateXBy(offsetX, offsetY);
- transform.concat();
-
- GCData data = new GCData ();
- data.paintRect = cellRect;
- GC gc = GC.cocoa_new (this, data);
- gc.setFont (item.getFont (columnIndex));
- if (drawSelection) {
- gc.setForeground (selectionForeground);
- gc.setBackground (selectionBackground);
- } else {
- gc.setForeground (userForeground != null ? userForeground : item.getForeground (columnIndex));
- gc.setBackground (item.getBackground (columnIndex));
- }
- if (!drawExpansion) {
- gc.setClipping ((int)(cellRect.x - offsetX), (int)(cellRect.y - offsetY), (int)cellRect.width, (int)cellRect.height);
- }
- Event event = new Event ();
- event.item = item;
- event.gc = gc;
- event.index = columnIndex;
- if (drawForeground) event.detail |= SWT.FOREGROUND;
- if (drawBackground) event.detail |= SWT.BACKGROUND;
- if (drawSelection) event.detail |= SWT.SELECTED;
- event.x = itemX;
- event.y = itemY;
- event.width = contentWidth;
- event.height = itemHeight;
- sendEvent (SWT.PaintItem, event);
- gc.dispose ();
-
- context.restoreGraphicsState();
- }
-}
-
-void drawWithExpansionFrame_inView (int /*long*/ id, int /*long*/ sel, NSRect cellFrame, int /*long*/ view) {
- drawExpansion = true;
- super.drawWithExpansionFrame_inView(id, sel, cellFrame, view);
- drawExpansion = false;
-}
-
-void expandItem_expandChildren (int /*long*/ id, int /*long*/ sel, int /*long*/ itemID, boolean children) {
- TreeItem item = (TreeItem)display.getWidget(itemID);
- if (!ignoreExpand) item.sendExpand (true, children);
- ignoreExpand = true;
- super.expandItem_expandChildren (id, sel, itemID, children);
- ignoreExpand = false;
- if (isDisposed() || item.isDisposed()) return;
- if (!children) {
- ignoreExpand = true;
- TreeItem[] items = item.items;
- for (int i = 0; i < item.itemCount; i++) {
- if (items[i] != null) items[i].updateExpanded ();
- }
- ignoreExpand = false;
- }
- setScrollWidth (false, item.items, true);
-}
-
-NSRect expansionFrameWithFrame_inView(int /*long*/ id, int /*long*/ sel, NSRect cellRect, int /*long*/ view) {
- if (toolTipText == null) {
- NSRect rect = super.expansionFrameWithFrame_inView(id, sel, cellRect, view);
- NSCell cell = new NSCell(id);
- if (rect.width != 0 && rect.height != 0) {
- if (hooks(SWT.MeasureItem)) {
- NSSize cellSize = cell.cellSize();
- cellRect.width = cellSize.width;
- return cellRect;
- }
- } else {
- NSRect expansionRect;
- if (hooks(SWT.MeasureItem)) {
- expansionRect = cellRect;
- NSSize cellSize = cell.cellSize();
- expansionRect.width = cellSize.width;
- } else {
- expansionRect = cell.titleRectForBounds(cellRect);
- NSSize cellSize = super.cellSize(id, OS.sel_cellSize);
- expansionRect.width = cellSize.width;
- }
- NSRect contentRect = scrollView.contentView().bounds();
- OS.NSIntersectionRect(contentRect, expansionRect, contentRect);
- if (!OS.NSEqualRects(expansionRect, contentRect)) {
- return expansionRect;
- }
- }
- return rect;
- }
- return new NSRect();
-}
-
-Widget findTooltip (NSPoint pt) {
- NSTableView widget = (NSTableView)view;
- NSTableHeaderView headerView = widget.headerView();
- if (headerView != null) {
- pt = headerView.convertPoint_fromView_ (pt, null);
- int /*long*/ index = headerView.columnAtPoint (pt);
- if (index != -1) {
- NSArray nsColumns = widget.tableColumns ();
- id nsColumn = nsColumns.objectAtIndex (index);
- for (int i = 0; i < columnCount; i++) {
- TreeColumn column = columns [i];
- if (column.nsColumn.id == nsColumn.id) {
- return column;
- }
- }
- }
- }
- return super.findTooltip (pt);
-}
-
-int getCheckColumnWidth () {
- return (int)checkColumn.dataCell().cellSize().width;
-}
-
-public Rectangle getClientArea () {
- checkWidget ();
- Rectangle rect = super.getClientArea ();
- NSTableHeaderView headerView = ((NSTableView) view).headerView ();
- if (headerView != null) {
- int height = (int) headerView.bounds ().height;
- rect.y -= height;
- rect.height += height;
- }
- return rect;
-}
-
-TreeColumn getColumn (id id) {
- for (int i = 0; i < columnCount; i++) {
- if (columns[i].nsColumn.id == id.id) {
- return columns[i];
- }
- }
- return null;
-}
-
-/**
- * Returns the column at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- * Columns are returned in the order that they were created.
- * If no <code>TreeColumn</code>s were created by the programmer,
- * this method will throw <code>ERROR_INVALID_RANGE</code> despite
- * the fact that a single column of data may be visible in the tree.
- * This occurs when the programmer uses the tree like a list, adding
- * items but never creating a column.
- *
- * @param index the index of the column to return
- * @return the column at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public TreeColumn getColumn (int index) {
- checkWidget ();
- if (!(0 <=index && index < columnCount)) error (SWT.ERROR_INVALID_RANGE);
- return columns [index];
-}
-
-/**
- * Returns the number of columns contained in the receiver.
- * If no <code>TreeColumn</code>s were created by the programmer,
- * this value is zero, despite the fact that visually, one column
- * of items may be visible. This occurs when the programmer uses
- * the tree like a list, adding items but never creating a column.
- *
- * @return the number of columns
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getColumnCount () {
- checkWidget ();
- return columnCount;
-}
-
-/**
- * Returns an array of zero-relative integers that map
- * the creation order of the receiver's items to the
- * order in which they are currently being displayed.
- * <p>
- * Specifically, the indices of the returned array represent
- * the current visual order of the items, and the contents
- * of the array represent the creation order of the items.
- * </p><p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the current visual order of the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
-public int [] getColumnOrder () {
- checkWidget ();
- int [] order = new int [columnCount];
- for (int i = 0; i < columnCount; i++) {
- TreeColumn column = columns [i];
- int index = indexOf (column.nsColumn);
- if ((style & SWT.CHECK) != 0) index -= 1;
- order [index] = i;
- }
- return order;
-}
-
-/**
- * Returns an array of <code>TreeColumn</code>s which are the
- * columns in the receiver. Columns are returned in the order
- * that they were created. If no <code>TreeColumn</code>s were
- * created by the programmer, the array is empty, despite the fact
- * that visually, one column of items may be visible. This occurs
- * when the programmer uses the tree like a list, adding items but
- * never creating a column.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public TreeColumn [] getColumns () {
- checkWidget ();
- TreeColumn [] result = new TreeColumn [columnCount];
- System.arraycopy (columns, 0, result, 0, columnCount);
- return result;
-}
-
-/**
- * Returns the width in pixels of a grid line.
- *
- * @return the width of a grid line in pixels
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getGridLineWidth () {
- checkWidget ();
- return 0;
-}
-
-/**
- * Returns the height of the receiver's header
- *
- * @return the height of the header or zero if the header is not visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getHeaderHeight () {
- checkWidget ();
- NSTableHeaderView headerView = ((NSOutlineView) view).headerView ();
- if (headerView == null) return 0;
- return (int) headerView.bounds ().height;
-}
-
-/**
- * Returns <code>true</code> if the receiver's header is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's header's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public boolean getHeaderVisible () {
- checkWidget ();
- return ((NSOutlineView) view).headerView () != null;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public TreeItem getItem (int index) {
- checkWidget ();
- int count = getItemCount ();
- if (index < 0 || index >= count) error (SWT.ERROR_INVALID_RANGE);
- return _getItem (null, index, true);
-}
-
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- * <p>
- * The item that is returned represents an item that could be selected by the user.
- * For example, if selection only occurs in items in the first column, then null is
- * returned if the point is outside of the item.
- * Note that the SWT.FULL_SELECTION style hint, which specifies the selection policy,
- * determines the extent of the selection.
- * </p>
- *
- * @param point the point used to locate the item
- * @return the item at the given point, or null if the point is not in a selectable item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem getItem (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- checkItems ();
- NSOutlineView widget = (NSOutlineView)view;
- NSPoint pt = new NSPoint();
- pt.x = point.x;
- pt.y = point.y;
- int row = (int)/*64*/widget.rowAtPoint(pt);
- if (row == -1) return null;
- NSRect rect = widget.frameOfOutlineCellAtRow(row);
- if (OS.NSPointInRect(pt, rect)) return null;
- id id = widget.itemAtRow(row);
- Widget item = display.getWidget (id.id);
- if (item != null && item instanceof TreeItem) {
- return (TreeItem)item;
- }
- return null;
-}
-
-/**
- * Returns the number of items contained in the receiver
- * that are direct item children of the receiver. The
- * number that is returned is the number of roots in the
- * tree.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return itemCount;
-}
-
-int getItemCount (TreeItem item) {
- return item == null ? itemCount : item.itemCount;
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the tree.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- return (int)((NSOutlineView) view).rowHeight () + CELL_GAP;
-}
-
-/**
- * Returns a (possibly empty) array of items contained in the
- * receiver that are direct item children of the receiver. These
- * are the roots of the tree.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem [] getItems () {
- checkWidget ();
- TreeItem [] result = new TreeItem [itemCount];
- for (int i=0; i<itemCount; i++) {
- result [i] = _getItem (null, i, true);
- }
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver's lines are visible,
- * and <code>false</code> otherwise. Note that some platforms draw
- * grid lines while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the visibility state of the lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public boolean getLinesVisible () {
- checkWidget ();
- return ((NSOutlineView) view).usesAlternatingRowBackgroundColors ();
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>TreeItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem getParentItem () {
- checkWidget ();
- return null;
-}
-
-/**
- * Returns an array of <code>TreeItem</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem [] getSelection () {
- checkWidget ();
- NSOutlineView widget = (NSOutlineView) view;
- if (widget.numberOfSelectedRows () == 0) {
- return new TreeItem [0];
- }
- NSIndexSet selection = widget.selectedRowIndexes ();
- int count = (int)/*64*/selection.count ();
- int /*long*/ [] indexBuffer = new int /*long*/ [count];
- selection.getIndexes (indexBuffer, count, 0);
- TreeItem [] result = new TreeItem [count];
- for (int i=0; i<count; i++) {
- id id = widget.itemAtRow (indexBuffer [i]);
- Widget item = display.getWidget (id.id);
- if (item != null && item instanceof TreeItem) {
- result[i] = (TreeItem) item;
- }
- }
- return result;
-}
-
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget ();
- return (int)/*64*/((NSOutlineView) view).numberOfSelectedRows ();
-}
-
-/**
- * Returns the column which shows the sort indicator for
- * the receiver. The value may be null if no column shows
- * the sort indicator.
- *
- * @return the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortColumn(TreeColumn)
- *
- * @since 3.2
- */
-public TreeColumn getSortColumn () {
- checkWidget ();
- return sortColumn;
-}
-
-/**
- * Returns the direction of the sort indicator for the receiver.
- * The value will be one of <code>UP</code>, <code>DOWN</code>
- * or <code>NONE</code>.
- *
- * @return the sort direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortDirection(int)
- *
- * @since 3.2
- */
-public int getSortDirection () {
- checkWidget ();
- return sortDirection;
-}
-
-/**
- * Returns the item which is currently at the top of the receiver.
- * This item can change when items are expanded, collapsed, scrolled
- * or new items are added or removed.
- *
- * @return the item at the top of the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public TreeItem getTopItem () {
- checkWidget ();
- //TODO - partial item at the top
- NSRect rect = scrollView.documentVisibleRect ();
- NSPoint point = new NSPoint ();
- point.x = rect.x;
- point.y = rect.y;
- NSOutlineView outlineView = (NSOutlineView)view;
- int /*long*/ index = outlineView.rowAtPoint (point);
- if (index == -1) return null; /* empty */
- id item = outlineView.itemAtRow (index);
- return (TreeItem)display.getWidget (item.id);
-}
-
-void highlightSelectionInClipRect(int /*long*/ id, int /*long*/ sel, int /*long*/ rect) {
- if (hooks (SWT.EraseItem)) return;
- if ((style & SWT.HIDE_SELECTION) != 0 && !hasFocus()) return;
- NSRect clipRect = new NSRect ();
- OS.memmove (clipRect, rect, NSRect.sizeof);
- callSuper (id, sel, clipRect);
-}
-
-int /*long*/ hitTestForEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ event, NSRect rect, int /*long*/ controlView) {
- /*
- * For some reason, the cell class needs to implement hitTestForEvent:inRect:ofView:,
- * otherwise the double action selector is not called properly.
- */
- return callSuper(id, sel, event, rect, controlView);
-}
-
-int /*long*/ image (int /*long*/ id, int /*long*/ sel) {
- int /*long*/ [] image = new int /*long*/ [1];
- OS.object_getInstanceVariable(id, Display.SWT_IMAGE, image);
- return image[0];
-}
-
-NSRect imageRectForBounds (int /*long*/ id, int /*long*/ sel, NSRect cellFrame) {
- NSImage image = new NSCell(id).image();
- if (image != null) {
- cellFrame.x += IMAGE_GAP;
- cellFrame.width = imageBounds.width;
- cellFrame.height = imageBounds.height;
- }
- return cellFrame;
-}
-
-int indexOf (NSTableColumn column) {
- return (int)/*64*/((NSTableView)view).tableColumns().indexOfObjectIdenticalTo(column);
-}
-
-/**
- * Searches the receiver's list starting at the first column
- * (index 0) until a column is found that is equal to the
- * argument, and returns the index of that column. If no column
- * is found, returns -1.
- *
- * @param column the search column
- * @return the index of the column
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the column is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int indexOf (TreeColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<columnCount; i++) {
- if (columns [i] == column) return i;
- }
- return -1;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int indexOf (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (item.parentItem != null) return -1;
- for (int i = 0; i < itemCount; i++) {
- if (item == items[i]) return i;
- }
- return -1;
-}
-
-boolean isTrim (NSView view) {
- if (super.isTrim (view)) return true;
- return view.id == headerView.id;
-}
-
-int /*long*/ menuForEvent(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (id != headerView.id) {
- /*
- * Feature in Cocoa: Table views do not change the selection when the user
- * right-clicks or control-clicks on an NSTableView or its subclasses. Fix is to select the
- * clicked-on row ourselves.
- */
- NSEvent event = new NSEvent(theEvent);
- NSOutlineView tree = (NSOutlineView)view;
-
- // get the current selections for the outline view.
- NSIndexSet selectedRowIndexes = tree.selectedRowIndexes();
-
- // select the row that was clicked before showing the menu for the event
- NSPoint mousePoint = view.convertPoint_fromView_(event.locationInWindow(), null);
- int /*long*/ row = tree.rowAtPoint(mousePoint);
-
- // figure out if the row that was just clicked on is currently selected
- if (selectedRowIndexes.containsIndex(row) == false) {
- NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc();
- set = set.initWithIndex(row);
- tree.selectRowIndexes (set, false);
- set.release();
- }
- // else that row is currently selected, so don't change anything.
- }
-
- return super.menuForEvent(id, sel, theEvent);
-}
-
-void mouseDown (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- if (headerView != null && id == headerView.id) {
- NSTableView widget = (NSTableView)view;
- widget.setAllowsColumnReordering(false);
- NSPoint pt = headerView.convertPoint_fromView_(new NSEvent(theEvent).locationInWindow(), null);
- int /*long*/ nsIndex = headerView.columnAtPoint(pt);
- if (nsIndex != -1) {
- id nsColumn = widget.tableColumns().objectAtIndex(nsIndex);
- for (int i = 0; i < columnCount; i++) {
- if (columns[i].nsColumn.id == nsColumn.id) {
- widget.setAllowsColumnReordering(columns[i].movable);
- break;
- }
- }
- }
- }
- else if (id == view.id) {
- // Bug/feature in Cocoa: If the tree has a context menu we just set it visible instead of returning
- // it from menuForEvent:. This has the side effect, however, of sending control-click to the NSTableView,
- // which is interpreted as a single click that clears the selection. Fix is to ignore control-click,
- NSEvent event = new NSEvent(theEvent);
- if ((event.modifierFlags() & OS.NSControlKeyMask) != 0) return;
- }
- super.mouseDown(id, sel, theEvent);
-}
-
-/*
- * Feature in Cocoa. If a checkbox is in multi-state mode, nextState cycles
- * from off to mixed to on and back to off again. This will cause the on state
- * to momentarily appear while clicking on the checkbox. To avoid this,
- * override [NSCell nextState] to go directly to the desired state.
- */
-int /*long*/ nextState (int /*long*/ id, int /*long*/ sel) {
- NSOutlineView outlineView = (NSOutlineView)view;
- int index = (int)/*64*/outlineView.selectedRow ();
- TreeItem item = (TreeItem)display.getWidget (outlineView.itemAtRow (index).id);
- if (item.grayed) {
- return item.checked ? OS.NSOffState : OS.NSMixedState;
- }
- return item.checked ? OS.NSOffState : OS.NSOnState;
-}
-
-int /*long*/ outlineView_child_ofItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ index, int /*long*/ itemID) {
- TreeItem parent = (TreeItem) display.getWidget (itemID);
- TreeItem item = _getItem (parent, (int)/*64*/index, true);
- return item.handle.id;
-}
-
-void outlineView_didClickTableColumn (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ tableColumn) {
- TreeColumn column = getColumn (new id (tableColumn));
- if (column == null) return; /* either CHECK column or firstColumn in 0-column Tree */
- column.postEvent (SWT.Selection);
-}
-
-int /*long*/ outlineView_objectValueForTableColumn_byItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ tableColumn, int /*long*/ itemID) {
- TreeItem item = (TreeItem) display.getWidget (itemID);
- checkData (item);
- if (checkColumn != null && tableColumn == checkColumn.id) {
- NSNumber value;
- if (item.checked && item.grayed) {
- value = NSNumber.numberWithInt (OS.NSMixedState);
- } else {
- value = NSNumber.numberWithInt (item.checked ? OS.NSOnState : OS.NSOffState);
- }
- return value.id;
- }
- for (int i=0; i<columnCount; i++) {
- if (columns [i].nsColumn.id == tableColumn) {
- return item.createString (i).id;
- }
- }
- return item.createString (0).id;
-}
-
-boolean outlineView_isItemExpandable (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ item) {
- if (item == 0) return true;
- return ((TreeItem) display.getWidget (item)).itemCount != 0;
-}
-
-int /*long*/ outlineView_numberOfChildrenOfItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ item) {
- if (item == 0) return itemCount;
- return ((TreeItem) display.getWidget (item)).itemCount;
-}
-
-void outlineView_willDisplayCell_forTableColumn_item (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ cell, int /*long*/ tableColumn, int /*long*/ itemID) {
- if (checkColumn != null && tableColumn == checkColumn.id) return;
- TreeItem item = (TreeItem) display.getWidget(itemID);
- int index = 0;
- for (int i=0; i<columnCount; i++) {
- if (columns [i].nsColumn.id == tableColumn) {
- index = i;
- break;
- }
- }
- NSTextFieldCell textCell = new NSTextFieldCell (cell);
- OS.object_setInstanceVariable(cell, Display.SWT_ROW, itemID);
- OS.object_setInstanceVariable(cell, Display.SWT_COLUMN, tableColumn);
- Image image = index == 0 ? item.image : (item.images == null ? null : item.images [index]);
- textCell.setImage (image != null ? image.handle : null);
- NSColor color;
- if (textCell.isEnabled()) {
- if (textCell.isHighlighted ()) {
- color = NSColor.selectedControlTextColor();
- } else {
- Color foreground = item.cellForeground != null ? item.cellForeground [index] : null;
- if (foreground == null) foreground = item.foreground;
- if (foreground == null) foreground = getForegroundColor ();
- color = NSColor.colorWithDeviceRed (foreground.handle [0], foreground.handle [1], foreground.handle [2], 1);
- }
- } else {
- color = NSColor.disabledControlTextColor();
- }
- int alignment = OS.NSLeftTextAlignment;
- if (columnCount > 0) {
- int style = columns [index].style;
- if ((style & SWT.CENTER) != 0) {
- alignment = OS.NSCenterTextAlignment;
- } else if ((style & SWT.RIGHT) != 0) {
- alignment = OS.NSRightTextAlignment;
- }
- }
- Font font = item.cellFont != null ? item.cellFont [index] : null;
- if (font == null) font = item.font;
- if (font == null) font = this.font;
- if (font == null) font = defaultFont ();
- if (font.extraTraits != 0) {
- NSMutableDictionary dict = ((NSMutableDictionary)new NSMutableDictionary().alloc()).initWithCapacity(5);
- dict.setObject (color, OS.NSForegroundColorAttributeName);
- dict.setObject (font.handle, OS.NSFontAttributeName);
- addTraits(dict, font);
- NSMutableParagraphStyle paragraphStyle = (NSMutableParagraphStyle)new NSMutableParagraphStyle ().alloc ().init ();
- paragraphStyle.setLineBreakMode (OS.NSLineBreakByClipping);
- paragraphStyle.setAlignment (alignment);
- dict.setObject (paragraphStyle, OS.NSParagraphStyleAttributeName);
- paragraphStyle.release ();
- NSAttributedString attribStr = ((NSAttributedString) new NSAttributedString ().alloc ()).initWithString (textCell.title(), dict);
- textCell.setAttributedStringValue(attribStr);
- attribStr.release();
- dict.release();
- } else {
- textCell.setFont(font.handle);
- textCell.setTextColor(color);
- textCell.setAlignment (alignment);
- }
-}
-
-void outlineViewColumnDidMove (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
- NSNotification notification = new NSNotification (aNotification);
- NSDictionary userInfo = notification.userInfo ();
- id nsOldIndex = userInfo.valueForKey (NSString.stringWith ("NSOldColumn")); //$NON-NLS-1$
- id nsNewIndex = userInfo.valueForKey (NSString.stringWith ("NSNewColumn")); //$NON-NLS-1$
- int oldIndex = new NSNumber (nsOldIndex).intValue ();
- int newIndex = new NSNumber (nsNewIndex).intValue ();
- int startIndex = Math.min (oldIndex, newIndex);
- int endIndex = Math.max (oldIndex, newIndex);
- NSOutlineView outlineView = (NSOutlineView)view;
- NSArray nsColumns = outlineView.tableColumns ();
- for (int i = startIndex; i <= endIndex; i++) {
- id columnId = nsColumns.objectAtIndex (i);
- TreeColumn column = getColumn (columnId);
- if (column != null) {
- column.sendEvent (SWT.Move);
- if (isDisposed ()) return;
- }
- }
-}
-
-void outlineViewColumnDidResize (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
- NSNotification notification = new NSNotification (aNotification);
- NSDictionary userInfo = notification.userInfo ();
- id columnId = userInfo.valueForKey (NSString.stringWith ("NSTableColumn")); //$NON-NLS-1$
- TreeColumn column = getColumn (columnId);
- if (column == null) return; /* either CHECK column or firstColumn in 0-column Tree */
-
- column.sendEvent (SWT.Resize);
- if (isDisposed ()) return;
-
- NSOutlineView outlineView = (NSOutlineView)view;
- int index = indexOf (column.nsColumn);
- if (index == -1) return; /* column was disposed in Resize callback */
-
- NSArray nsColumns = outlineView.tableColumns ();
- int columnCount = (int)/*64*/outlineView.numberOfColumns ();
- for (int i = index + 1; i < columnCount; i++) {
- columnId = nsColumns.objectAtIndex (i);
- column = getColumn (columnId);
- if (column != null) {
- column.sendEvent (SWT.Move);
- if (isDisposed ()) return;
- }
- }
-}
-
-void outlineViewSelectionDidChange (int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
- if (ignoreSelect) return;
- NSOutlineView widget = (NSOutlineView) view;
- int row = (int)/*64*/widget.selectedRow ();
- if (row == -1)
- postEvent (SWT.Selection);
- else {
- id _id = widget.itemAtRow (row);
- TreeItem item = (TreeItem) display.getWidget (_id.id);
- Event event = new Event ();
- event.item = item;
- event.index = row;
- postEvent (SWT.Selection, event);
- }
-}
-
-void outlineView_setObjectValue_forTableColumn_byItem (int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ object, int /*long*/ tableColumn, int /*long*/ itemID) {
- if (checkColumn != null && tableColumn == checkColumn.id) {
- TreeItem item = (TreeItem) display.getWidget (itemID);
- item.checked = !item.checked;
- Event event = new Event ();
- event.detail = SWT.CHECK;
- event.item = item;
- postEvent (SWT.Selection, event);
- item.redraw (-1);
- }
-}
-
-boolean outlineView_writeItems_toPasteboard(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2) {
- return sendMouseEvent(NSApplication.sharedApplication().currentEvent(), SWT.DragDetect, true);
-}
-
-void register () {
- super.register ();
- display.addWidget (headerView, this);
- display.addWidget (dataCell, this);
- if (buttonCell != null) display.addWidget (buttonCell, this);
-}
-
-void releaseChildren (boolean destroy) {
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- if (columns != null) {
- for (int i=0; i<columnCount; i++) {
- TreeColumn column = columns [i];
- if (column != null && !column.isDisposed ()) {
- column.release (false);
- }
- }
- columns = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (headerView != null) headerView.release ();
- headerView = null;
- if (firstColumn != null) firstColumn.release ();
- firstColumn = null;
- if (checkColumn != null) checkColumn.release ();
- checkColumn = null;
- if (dataCell != null) dataCell.release ();
- dataCell = null;
- if (buttonCell != null) buttonCell.release();
- buttonCell = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- sortColumn = null;
-}
-
-void reloadItem (TreeItem item, boolean recurse) {
- if (getDrawing()) {
- NSOutlineView widget = (NSOutlineView)view;
- TreeItem[] selectedItems = getSelection ();
- if (item != null) {
- widget.reloadItem (item.handle, recurse);
- } else {
- widget.reloadData ();
- }
- selectItems (selectedItems, true);
- } else {
- reloadPending = true;
- }
-}
-
-/**
- * Removes all of the items from the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget ();
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null && !item.isDisposed ()) item.release (false);
- }
- items = new TreeItem [4];
- itemCount = 0;
- imageBounds = null;
- ((NSOutlineView) view).reloadData ();
- setScrollWidth ();
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when items in the receiver are expanded or collapsed.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TreeListener
- * @see #addTreeListener
- */
-public void removeTreeListener (TreeListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Expand, listener);
- eventTable.unhook (SWT.Collapse, listener);
-}
-
-void setImage (int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- OS.object_setInstanceVariable(id, Display.SWT_IMAGE, arg0);
-}
-
-/**
- * Display a mark indicating the point at which an item will be inserted.
- * The drop insert item has a visual hint to show where a dragged item
- * will be inserted when dropped on the tree.
- *
- * @param item the insert item. Null will clear the insertion mark.
- * @param before true places the insert mark above 'item'. false places
- * the insert mark below 'item'.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setInsertMark (TreeItem item, boolean before) {
- checkWidget ();
- if (item != null && item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- TreeItem oldMark = insertItem;
- insertItem = item;
- insertBefore = before;
- if (oldMark != null && !oldMark.isDisposed()) oldMark.redraw (-1);
- if (item != null) item.redraw (-1);
-}
-
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- checkItems ();
- NSOutlineView widget = (NSOutlineView) view;
- ignoreSelect = true;
- widget.selectAll (null);
- ignoreSelect = false;
-}
-
-/**
- * Selects an item in the receiver. If the item was already
- * selected, it remains selected.
- *
- * @param item the item to be selected
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void select (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- checkItems ();
- showItem (item);
- NSOutlineView outlineView = (NSOutlineView) view;
- int /*long*/ row = outlineView.rowForItem (item.handle);
- NSIndexSet set = (NSIndexSet)new NSIndexSet().alloc();
- set = set.initWithIndex(row);
- ignoreSelect = true;
- outlineView.selectRowIndexes (set, false);
- ignoreSelect = false;
- set.release();
-}
-
-void sendDoubleSelection() {
- NSOutlineView outlineView = (NSOutlineView)view;
- int rowIndex = (int)/*64*/outlineView.clickedRow ();
- if (rowIndex != -1) {
- if ((style & SWT.CHECK) != 0) {
- NSArray columns = outlineView.tableColumns ();
- int columnIndex = (int)/*64*/outlineView.clickedColumn ();
- id column = columns.objectAtIndex (columnIndex);
- if (column.id == checkColumn.id) return;
- }
- TreeItem item = (TreeItem) display.getWidget (outlineView.itemAtRow (rowIndex).id);
- Event event = new Event ();
- event.item = item;
- postEvent (SWT.DefaultSelection, event);
- }
-}
-
-boolean sendKeyEvent (NSEvent nsEvent, int type) {
- boolean result = super.sendKeyEvent (nsEvent, type);
- if (!result) return result;
- if (type != SWT.KeyDown) return result;
- short keyCode = nsEvent.keyCode ();
- switch (keyCode) {
- case 76: /* KP Enter */
- case 36: { /* Return */
- postEvent (SWT.DefaultSelection);
- break;
- }
- }
- return result;
-}
-
-void sendMeasureItem (TreeItem item, int columnIndex, NSSize size) {
- NSOutlineView widget = (NSOutlineView)this.view;
- int contentWidth = (int)Math.ceil (size.width);
- NSSize spacing = widget.intercellSpacing();
- int itemHeight = (int)Math.ceil (widget.rowHeight() + spacing.height);
- GCData data = new GCData ();
- data.paintRect = widget.frame ();
- GC gc = GC.cocoa_new (this, data);
- gc.setFont (item.getFont (columnIndex));
- Event event = new Event ();
- event.item = item;
- event.gc = gc;
- event.index = columnIndex;
- event.width = contentWidth;
- event.height = itemHeight;
- sendEvent (SWT.MeasureItem, event);
- gc.dispose ();
- if (!isDisposed () && !item.isDisposed ()) {
- size.width = event.width;
- size.height = event.height;
- if (itemHeight < event.height) {
- widget.setRowHeight (event.height);
- }
- if (contentWidth != event.width) {
- if (columnCount == 0 && columnIndex == 0) {
- item.width = event.width;
- item.width += widget.indentationPerLevel () * (1 + widget.levelForItem (item.handle));
- if (setScrollWidth (item)) {
- widget.setNeedsDisplay(true);
- }
- }
- }
- }
-}
-
-void selectItems (TreeItem[] items, boolean ignoreDisposed) {
- NSOutlineView outlineView = (NSOutlineView) view;
- NSMutableIndexSet set = (NSMutableIndexSet) new NSMutableIndexSet ().alloc ().init ();
- int length = items.length;
- for (int i=0; i<length; i++) {
- if (items [i] != null) {
- if (items [i].isDisposed ()) {
- if (ignoreDisposed) continue;
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- TreeItem item = items [i];
- if (!ignoreDisposed) showItem (items [i], false);
- set.addIndex (outlineView.rowForItem (item.handle));
- }
- }
- ignoreSelect = true;
- outlineView.selectRowIndexes (set, false);
- ignoreSelect = false;
- set.release();
-}
-
-NSRect titleRectForBounds (int /*long*/ id, int /*long*/ sel, NSRect cellFrame) {
- NSImage image = new NSCell(id).image();
- if (image != null) {
- int imageWidth = imageBounds.width + IMAGE_GAP;
- cellFrame.x += imageWidth;
- cellFrame.width -= imageWidth;
- }
- return cellFrame;
-}
-
-void updateBackground () {
- NSColor nsColor = null;
- if (backgroundImage != null) {
- nsColor = NSColor.colorWithPatternImage(backgroundImage.handle);
- } else if (background != null) {
- nsColor = NSColor.colorWithDeviceRed(background[0], background[1], background[2], background[3]);
- }
- ((NSOutlineView) view).setBackgroundColor (nsColor);
-}
-
-/**
- * Sets the order that the items in the receiver should
- * be displayed in to the given argument which is described
- * in terms of the zero-relative ordering of when the items
- * were added.
- *
- * @param order the new order to display the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item order is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
-public void setColumnOrder (int [] order) {
- checkWidget ();
- if (order == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (columnCount == 0) {
- if (order.length != 0) error (SWT.ERROR_INVALID_ARGUMENT);
- return;
- }
- if (order.length != columnCount) error (SWT.ERROR_INVALID_ARGUMENT);
- int [] oldOrder = getColumnOrder ();
- boolean reorder = false;
- boolean [] seen = new boolean [columnCount];
- for (int i=0; i<order.length; i++) {
- int index = order [i];
- if (index < 0 || index >= columnCount) error (SWT.ERROR_INVALID_ARGUMENT);
- if (seen [index]) error (SWT.ERROR_INVALID_ARGUMENT);
- seen [index] = true;
- if (order [i] != oldOrder [i]) reorder = true;
- }
- if (reorder) {
- NSOutlineView outlineView = (NSOutlineView)view;
- int [] oldX = new int [oldOrder.length];
- int check = (style & SWT.CHECK) != 0 ? 1 : 0;
- for (int i=0; i<oldOrder.length; i++) {
- int index = oldOrder[i];
- oldX [index] = (int)outlineView.rectOfColumn (i + check).x;
- }
- int [] newX = new int [order.length];
- for (int i=0; i<order.length; i++) {
- int index = order [i];
- TreeColumn column = columns[index];
- int oldIndex = indexOf (column.nsColumn);
- int newIndex = i + check;
- outlineView.moveColumn (oldIndex, newIndex);
- newX [index] = (int)outlineView.rectOfColumn (newIndex).x;
- }
-
- TreeColumn[] newColumns = new TreeColumn [columnCount];
- System.arraycopy (columns, 0, newColumns, 0, columnCount);
- for (int i=0; i<columnCount; i++) {
- TreeColumn column = newColumns [i];
- if (!column.isDisposed ()) {
- if (newX [i] != oldX [i]) {
- column.sendEvent (SWT.Move);
- }
- }
- }
- }
-}
-
-void setFont (NSFont font) {
- super.setFont (font);
- setItemHeight (null, font, !hooks (SWT.MeasureItem));
- view.setNeedsDisplay (true);
- clearCachedWidth (items);
- setScrollWidth ();
-}
-
-/**
- * Marks the receiver's header as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setHeaderVisible (boolean show) {
- checkWidget ();
- ((NSOutlineView) view).setHeaderView (show ? headerView : null);
-}
-
-/**
- * Sets the number of root-level items contained in the receiver.
- *
- * @param count the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setItemCount (int count) {
- checkWidget ();
- checkItems ();
- count = Math.max (0, count);
- setItemCount (null, count);
-}
-
-void setItemCount (TreeItem parentItem, int count) {
- int itemCount = getItemCount (parentItem);
- if (count == itemCount) return;
- NSOutlineView widget = (NSOutlineView) view;
- int length = Math.max (4, (count + 3) / 4 * 4);
- TreeItem [] children = parentItem == null ? items : parentItem.items;
- boolean expanded = parentItem == null || parentItem.getExpanded();
- if (count < itemCount) {
- /*
- * Note that the item count has to be updated before the call to reloadItem(), but
- * the items have to be released after.
- */
- if (parentItem == null) {
- this.itemCount = count;
- } else {
- parentItem.itemCount = count;
- }
- /*
- * Bug in Cocoa. When removing selected items from an NSOutlineView, the selection
- * is not properly updated. The fix is to ensure that the item and its subitems
- * are deselected before the item is removed by the reloadItem call.
- */
- if (expanded) {
- for (int index = count; index < itemCount; index ++) {
- TreeItem item = children [index];
- if (item != null && !item.isDisposed ()) item.clearSelection ();
- }
- }
- TreeItem[] selectedItems = getSelection ();
- widget.reloadItem (parentItem != null ? parentItem.handle : null, expanded);
- selectItems (selectedItems, true);
- for (int index = count; index < itemCount; index ++) {
- TreeItem item = children [index];
- if (item != null && !item.isDisposed()) item.release (false);
- }
- TreeItem [] newItems = new TreeItem [length];
- if (children != null) {
- System.arraycopy (children, 0, newItems, 0, count);
- }
- children = newItems;
- if (parentItem == null) {
- this.items = newItems;
- } else {
- parentItem.items = newItems;
- }
- } else {
- if ((style & SWT.VIRTUAL) == 0) {
- for (int i=itemCount; i<count; i++) {
- new TreeItem (this, parentItem, SWT.NONE, i, true);
- }
- } else {
- TreeItem [] newItems = new TreeItem [length];
- if (children != null) {
- System.arraycopy (children, 0, newItems, 0, itemCount);
- }
- children = newItems;
- if (parentItem == null) {
- this.items = newItems;
- this.itemCount = count;
- } else {
- parentItem.items = newItems;
- parentItem.itemCount = count;
- }
- TreeItem[] selectedItems = getSelection ();
- widget.reloadItem (parentItem != null ? parentItem.handle : null, expanded);
- selectItems (selectedItems, true);
-
- if (parentItem != null && itemCount == 0 && parentItem.expanded) {
- ignoreExpand = true;
- widget.expandItem (parentItem.handle);
- ignoreExpand = false;
- }
- }
- }
-}
-
-/*public*/ void setItemHeight (int itemHeight) {
- checkWidget ();
- if (itemHeight < -1) error (SWT.ERROR_INVALID_ARGUMENT);
- if (itemHeight == -1) {
- setItemHeight (null, null, true);
- } else {
- ((NSOutlineView)view).setRowHeight (itemHeight);
- }
-}
-
-void setItemHeight (Image image, NSFont font, boolean set) {
- if (font == null) font = getFont ().handle;
- float /*double*/ ascent = font.ascender ();
- float /*double*/ descent = -font.descender () + font.leading ();
- int height = (int)Math.ceil (ascent + descent) + 1;
- Rectangle bounds = image != null ? image.getBounds () : imageBounds;
- if (bounds != null) {
- imageBounds = bounds;
- height = Math.max (height, bounds.height);
- }
- NSTableView widget = (NSTableView)view;
- if (set || widget.rowHeight () < height) {
- widget.setRowHeight (height);
- }
-}
-
-/**
- * Marks the receiver's lines as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise. Note that some platforms draw
- * grid lines while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLinesVisible (boolean show) {
- checkWidget ();
- ((NSOutlineView) view).setUsesAlternatingRowBackgroundColors (show);
-}
-
-public void setRedraw (boolean redraw) {
- checkWidget ();
- super.setRedraw (redraw);
- if (redraw && drawCount == 0) {
- checkItems ();
- setScrollWidth ();
- }
-}
-
-boolean setScrollWidth () {
- return setScrollWidth (true, items, true);
-}
-
-boolean setScrollWidth (boolean set, TreeItem[] items, boolean recurse) {
- if (items == null) return false;
- if (ignoreRedraw || !getDrawing()) return false;
- if (columnCount != 0) return false;
- GC gc = new GC (this);
- int newWidth = calculateWidth (items, 0, gc, recurse);
- gc.dispose ();
- if (!set) {
- int oldWidth = (int)firstColumn.width ();
- if (oldWidth >= newWidth) return false;
- }
- firstColumn.setWidth (newWidth);
- if (horizontalBar != null && horizontalBar.view != null) redrawWidget (horizontalBar.view, false);
- return true;
-}
-
-boolean setScrollWidth (TreeItem item) {
- if (ignoreRedraw || !getDrawing()) return false;
- if (columnCount != 0) return false;
- TreeItem parentItem = item.parentItem;
- if (parentItem != null && !parentItem.getExpanded ()) return false;
- GC gc = new GC (this);
- int newWidth = item.calculateWidth (0, gc);
- gc.dispose ();
- int oldWidth = (int)firstColumn.width ();
- if (oldWidth < newWidth) {
- firstColumn.setWidth (newWidth);
- if (horizontalBar != null && horizontalBar.view != null) redrawWidget (horizontalBar.view, false);
- return true;
- }
- return false;
-}
-
-/**
- * Sets the receiver's selection to the given item.
- * The current selection is cleared before the new item is selected.
- * <p>
- * If the item is not in the receiver, then it is ignored.
- * </p>
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (new TreeItem [] {item});
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- * </p>
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the items has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#deselectAll()
- */
-public void setSelection (TreeItem [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- checkItems ();
- deselectAll ();
- int length = items.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- selectItems (items, false);
- if (items.length > 0) {
- for (int i = 0; i < items.length; i++) {
- TreeItem item = items[i];
- if (item != null) {
- showItem(item, true);
- break;
- }
- }
- }
-}
-
-void setSmallSize () {
- if (checkColumn == null) return;
- checkColumn.dataCell ().setControlSize (OS.NSSmallControlSize);
- checkColumn.setWidth (getCheckColumnWidth ());
-}
-
-/**
- * Sets the column used by the sort indicator for the receiver. A null
- * value will clear the sort indicator. The current sort column is cleared
- * before the new column is set.
- *
- * @param column the column used by the sort indicator or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the column is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortColumn (TreeColumn column) {
- checkWidget ();
- if (column != null && column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (column == sortColumn) return;
- sortColumn = column;
- ((NSOutlineView)view).setHighlightedTableColumn (column == null ? null : column.nsColumn);
-}
-
-/**
- * Sets the direction of the sort indicator for the receiver. The value
- * can be one of <code>UP</code>, <code>DOWN</code> or <code>NONE</code>.
- *
- * @param direction the direction of the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortDirection (int direction) {
- checkWidget ();
- if (direction != SWT.UP && direction != SWT.DOWN && direction != SWT.NONE) return;
- if (direction == sortDirection) return;
- sortDirection = direction;
- if (sortColumn == null) return;
- NSTableHeaderView headerView = ((NSOutlineView)view).headerView ();
- if (headerView == null) return;
- int index = indexOf (sortColumn.nsColumn);
- NSRect rect = headerView.headerRectOfColumn (index);
- headerView.setNeedsDisplayInRect (rect);
-}
-
-/**
- * Sets the item which is currently at the top of the receiver.
- * This item can change when items are expanded, collapsed, scrolled
- * or new items are added or removed.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getTopItem()
- *
- * @since 2.1
- */
-public void setTopItem (TreeItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- checkItems ();
- showItem (item, false);
- NSOutlineView widget = (NSOutlineView) view;
- int /*long*/ row = widget.rowForItem (item.handle);
- if (row == -1) return;
- NSPoint pt = new NSPoint();
- pt.x = scrollView.contentView().bounds().x;
- pt.y = widget.frameOfCellAtColumn(0, row).y;
- view.scrollPoint(pt);
-}
-
-/**
- * Shows the column. If the column is already showing in the receiver,
- * this method simply returns. Otherwise, the columns are scrolled until
- * the column is visible.
- *
- * @param column the column to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void showColumn (TreeColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (column.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (column.parent != this) return;
- if (columnCount <= 1) return;
- int index = indexOf (column.nsColumn);
- if (!(0 <= index && index < columnCount + ((style & SWT.CHECK) != 0 ? 1 : 0))) return;
- ((NSOutlineView)view).scrollColumnToVisible (index);
-}
-
-/**
- * Shows the item. If the item is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled
- * and expanded until the item is visible.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#showSelection()
- */
-public void showItem (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- checkItems ();
- showItem (item, true);
-}
-
-void showItem (TreeItem item, boolean scroll) {
- TreeItem parentItem = item.parentItem;
- if (parentItem != null) {
- showItem (parentItem, false);
- parentItem.setExpanded (true);
- }
- if (scroll) {
- NSOutlineView outlineView = (NSOutlineView) view;
- outlineView.scrollRowToVisible (outlineView.rowForItem (item.handle));
- }
-}
-
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#showItem(TreeItem)
- */
-public void showSelection () {
- checkWidget ();
- checkItems ();
- //TODO - optimize
- TreeItem [] selection = getSelection ();
- if (selection.length > 0) {
- checkData(selection [0]);
- showItem (selection [0], true);
- }
-}
-
-void updateCursorRects (boolean enabled) {
- super.updateCursorRects (enabled);
- if (headerView == null) return;
- updateCursorRects (enabled, headerView);
-}
-
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TreeColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TreeColumn.java
deleted file mode 100755
index ed0180f373..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TreeColumn.java
+++ /dev/null
@@ -1,675 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.cocoa.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a column in a tree widget.
- * <p><dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd> Move, Resize, Selection</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT and CENTER may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TreeColumn extends Item {
- NSTableColumn nsColumn;
- Tree parent;
- String toolTipText, displayText;
- boolean movable;
-
- static final int MARGIN = 2;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeColumn (Tree parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, parent.columnCount);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeColumn (Tree parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize,typedListener);
- addListener (SWT.Move,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the column header is selected.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (nsColumn.headerCell());
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-void drawInteriorWithFrame_inView (int /*long*/ id, int /*long*/ sel, NSRect cellRect, int /*long*/ view) {
- /*
- * Feature in Cocoa. When the last column in a tree does not reach the
- * rightmost edge of the tree view, the cell that draws the rightmost-
- * column's header is also invoked to draw the header space between its
- * right edge and the tree's right edge. If this case is detected then
- * nothing should be drawn.
- */
- int columnIndex = parent.indexOf (nsColumn);
- NSRect headerRect = parent.headerView.headerRectOfColumn (columnIndex);
- if (headerRect.x != cellRect.x || headerRect.width != cellRect.width) return;
-
- NSGraphicsContext context = NSGraphicsContext.currentContext ();
- context.saveGraphicsState ();
-
- int contentWidth = 0;
- NSSize stringSize = null, imageSize = null;
- NSAttributedString attrString = null;
- NSTableHeaderCell headerCell = nsColumn.headerCell ();
- if (displayText != null) {
- Font font = Font.cocoa_new(display, headerCell.font ());
- attrString = parent.createString(displayText, font, null, SWT.LEFT, (parent.state & DISABLED) == 0, false);
- stringSize = attrString.size ();
- contentWidth += Math.ceil (stringSize.width);
- if (image != null) contentWidth += MARGIN; /* space between image and text */
- }
- if (image != null) {
- imageSize = image.handle.size ();
- contentWidth += Math.ceil (imageSize.width);
- }
-
- if (parent.sortColumn == this && parent.sortDirection != SWT.NONE) {
- boolean ascending = parent.sortDirection == SWT.UP;
- headerCell.drawSortIndicatorWithFrame (cellRect, new NSView(view), ascending, 0);
- /* remove the arrow's space from the available drawing width */
- NSRect sortRect = headerCell.sortIndicatorRectForBounds (cellRect);
- cellRect.width = Math.max (0, sortRect.x - cellRect.x);
- }
-
- int drawX = 0;
- if ((style & SWT.CENTER) != 0) {
- drawX = (int)(cellRect.x + Math.max (MARGIN, ((cellRect.width - contentWidth) / 2)));
- } else if ((style & SWT.RIGHT) != 0) {
- drawX = (int)(cellRect.x + Math.max (MARGIN, cellRect.width - contentWidth - MARGIN));
- } else {
- drawX = (int)cellRect.x + MARGIN;
- }
-
- if (image != null) {
- NSRect destRect = new NSRect ();
- destRect.x = drawX;
- destRect.y = cellRect.y;
- destRect.width = Math.min (imageSize.width, cellRect.width - 2 * MARGIN);
- destRect.height = Math.min (imageSize.height, cellRect.height);
- boolean isFlipped = new NSView (view).isFlipped();
- if (isFlipped) {
- context.saveGraphicsState ();
- NSAffineTransform transform = NSAffineTransform.transform ();
- transform.scaleXBy (1, -1);
- transform.translateXBy (0, -(destRect.height + 2 * destRect.y));
- transform.concat ();
- }
- NSRect sourceRect = new NSRect ();
- sourceRect.width = destRect.width;
- sourceRect.height = destRect.height;
- image.handle.drawInRect (destRect, sourceRect, OS.NSCompositeSourceOver, 1f);
- if (isFlipped) context.restoreGraphicsState ();
- drawX += destRect.width;
- }
-
- if (displayText != null && displayText.length () > 0) {
- if (image != null) drawX += MARGIN; /* space between image and text */
- NSRect destRect = new NSRect ();
- destRect.x = drawX;
- destRect.y = cellRect.y;
- destRect.width = Math.min (stringSize.width, cellRect.x + cellRect.width - MARGIN - drawX);
- destRect.height = Math.min (stringSize.height, cellRect.height);
- attrString.drawInRect (destRect);
- }
- if (attrString != null) attrString.release ();
-
- context.restoreGraphicsState ();
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget ();
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Tree</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Tree getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Gets the moveable attribute. A column that is
- * not moveable cannot be reordered by the user
- * by dragging the header but may be reordered
- * by the programmer.
- *
- * @return the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
-public boolean getMoveable () {
- checkWidget ();
- return movable;
-}
-
-/**
- * Gets the resizable attribute. A column that is
- * not resizable cannot be dragged by the user but
- * may be resized by the programmer.
- *
- * @return the resizable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getResizable () {
- checkWidget ();
- return nsColumn.resizingMask() != OS.NSTableColumnNoResizing;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget ();
- int width = (int)nsColumn.width();
- // TODO how to differentiate 0 and 1 cases?
- if (width > 0) width += Tree.CELL_GAP;
- return width;
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void pack () {
- checkWidget ();
-
- int width = 0;
-
- /* compute header width */
- if (displayText != null) {
- NSTableHeaderCell headerCell = nsColumn.headerCell ();
- Font font = Font.cocoa_new(display, headerCell.font ());
- NSAttributedString attrString = parent.createString(displayText, font, null, 0, true, false);
- NSSize stringSize = attrString.size ();
- attrString.release ();
- width += Math.ceil (stringSize.width);
- if (image != null) width += MARGIN; /* space between image and text */
- }
- if (image != null) {
- NSSize imageSize = image.handle.size ();
- width += Math.ceil (imageSize.width);
- }
- if (parent.sortColumn == this && parent.sortDirection != SWT.NONE) {
- NSTableHeaderCell headerCell = nsColumn.headerCell ();
- NSRect rect = new NSRect ();
- rect.width = rect.height = Float.MAX_VALUE;
- NSSize cellSize = headerCell.cellSizeForBounds (rect);
- rect.height = cellSize.height;
- NSRect sortRect = headerCell.sortIndicatorRectForBounds (rect);
- width += Math.ceil (sortRect.width);
- }
-
- /* compute item widths down column */
- GC gc = new GC (parent);
- width = Math.max(width, parent.calculateWidth(parent.items, parent.indexOf (this), gc, true));
- gc.dispose ();
- setWidth (width);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (nsColumn != null) {
- nsColumn.headerCell ().release ();
- nsColumn.release ();
- }
- nsColumn = null;
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (parent.sortColumn == this) {
- parent.sortColumn = null;
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>.
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget ();
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- int index = parent.indexOf (this);
- if (index == -1 || index == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- NSOutlineView outlineView = ((NSOutlineView) parent.view);
- NSTableHeaderView headerView = outlineView.headerView ();
- if (headerView == null) return;
- index = parent.indexOf (nsColumn);
- NSRect rect = headerView.headerRectOfColumn (index);
- headerView.setNeedsDisplayInRect (rect);
- rect = outlineView.rectOfColumn (index);
- parent.view.setNeedsDisplayInRect (rect);
-}
-
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- super.setImage (image);
- NSTableHeaderView headerView = ((NSOutlineView) parent.view).headerView ();
- if (headerView == null) return;
- int index = parent.indexOf (nsColumn);
- NSRect rect = headerView.headerRectOfColumn (index);
- headerView.setNeedsDisplayInRect (rect);
-}
-
-/**
- * Sets the moveable attribute. A column that is
- * moveable can be reordered by the user by dragging
- * the header. A column that is not moveable cannot be
- * dragged by the user but may be reordered
- * by the programmer.
- *
- * @param moveable the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#setColumnOrder(int[])
- * @see Tree#getColumnOrder()
- * @see TreeColumn#getMoveable()
- * @see SWT#Move
- *
- * @since 3.2
- */
-public void setMoveable (boolean moveable) {
- checkWidget ();
- this.movable = moveable;
-}
-
-/**
- * Sets the resizable attribute. A column that is
- * not resizable cannot be dragged by the user but
- * may be resized by the programmer.
- *
- * @param resizable the resize attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setResizable (boolean resizable) {
- checkWidget ();
- nsColumn.setResizingMask(resizable ? OS.NSTableColumnUserResizingMask : OS.NSTableColumnNoResizing);
-}
-
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- char [] buffer = new char [text.length ()];
- text.getChars (0, buffer.length, buffer, 0);
- int length = fixMnemonic (buffer);
- displayText = new String (buffer, 0, length);
- NSString title = NSString.stringWith (displayText);
- nsColumn.headerCell ().setTitle (title);
- NSTableHeaderView headerView = ((NSOutlineView) parent.view).headerView ();
- if (headerView == null) return;
- int index = parent.indexOf (nsColumn);
- NSRect rect = headerView.headerRectOfColumn (index);
- headerView.setNeedsDisplayInRect (rect);
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
- parent.checkToolTip (this);
-}
-
-/**
- * Sets the width of the receiver.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int width) {
- checkWidget ();
- if (width < 0) return;
- // TODO how to differentiate 0 and 1 cases?
- width = Math.max (0, width - Tree.CELL_GAP);
- nsColumn.setWidth (width);
-}
-
-String tooltipText () {
- return toolTipText;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TreeItem.java
deleted file mode 100755
index 7a02097ce1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TreeItem.java
+++ /dev/null
@@ -1,1456 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.cocoa.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a hierarchy of tree items in a tree widget.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TreeItem extends Item {
- Tree parent;
- TreeItem parentItem;
- TreeItem[] items;
- int itemCount;
- String [] strings;
- Image [] images;
- boolean checked, grayed, cached, expanded;
- Color foreground, background;
- Color [] cellForeground, cellBackground;
- Font font;
- Font [] cellFont;
- int width = -1;
- /**
- * the handle to the OS resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public SWTTreeItem handle;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>)
- * and a style value describing its behavior and appearance.
- * The item is added to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (Tree parent, int style) {
- this (checkNull (parent), null, style, -1, true);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>),
- * a style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (Tree parent, int style, int index) {
- this (checkNull (parent), null, style, checkIndex (index), true);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>)
- * and a style value describing its behavior and appearance.
- * The item is added to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parentItem a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (TreeItem parentItem, int style) {
- this (checkNull (parentItem).parent, parentItem, style, -1, true);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>),
- * a style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parentItem a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (TreeItem parentItem, int style, int index) {
- this (checkNull (parentItem).parent, parentItem, style, checkIndex (index), true);
-}
-
-TreeItem (Tree parent, TreeItem parentItem, int style, int index, boolean create) {
- super (parent, style);
- this.parent = parent;
- this.parentItem = parentItem;
- if (create) {
- parent.createItem (this, parentItem, index);
- } else {
- handle = (SWTTreeItem) new SWTTreeItem ().alloc ().init ();
- createJNIRef ();
- register ();
- items = new TreeItem[4];
- }
-}
-
-static TreeItem checkNull (TreeItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-
-static Tree checkNull (Tree parent) {
- if (parent == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return parent;
-}
-
-static int checkIndex (int index) {
- if (index < 0) SWT.error (SWT.ERROR_INVALID_RANGE);
- return index;
-}
-
-int calculateWidth (int index, GC gc) {
- if (index == 0 && width != -1) return width;
- Font font = null;
- if (cellFont != null) font = cellFont[index];
- if (font == null) font = this.font;
- if (font == null) font = parent.font;
- if (font == null) font = parent.defaultFont();
- String text = index == 0 ? this.text : (strings == null ? "" : strings [index]);
- Image image = index == 0 ? this.image : (images == null ? null : images [index]);
- NSCell cell = parent.dataCell;
- if (font.extraTraits != 0) {
- NSAttributedString attribStr = parent.createString(text, font, null, 0, true, false);
- cell.setAttributedStringValue(attribStr);
- attribStr.release();
- } else {
- cell.setFont (font.handle);
- cell.setTitle (NSString.stringWith(text != null ? text : ""));
- }
-
- /* This code is inlined for performance */
- objc_super super_struct = new objc_super();
- super_struct.receiver = cell.id;
- super_struct.super_class = OS.objc_msgSend(cell.id, OS.sel_superclass);
- NSSize size = new NSSize();
- OS.objc_msgSendSuper_stret(size, super_struct, OS.sel_cellSize);
- if (image != null) size.width += parent.imageBounds.width + Tree.IMAGE_GAP;
-// cell.setImage (image != null ? image.handle : null);
-// NSSize size = cell.cellSize ();
-
- int width = (int)Math.ceil (size.width);
- boolean sendMeasure = true;
- if ((parent.style & SWT.VIRTUAL) != 0) {
- sendMeasure = cached;
- }
- if (sendMeasure && parent.hooks (SWT.MeasureItem)) {
- gc.setFont (font);
- Event event = new Event ();
- event.item = this;
- event.index = index;
- event.gc = gc;
- NSTableView widget = (NSTableView)parent.view;
- int height = (int)widget.rowHeight ();
- event.width = width;
- event.height = height;
- parent.sendEvent (SWT.MeasureItem, event);
- if (height < event.height) {
- widget.setRowHeight (event.height);
- widget.setNeedsDisplay (true);
- }
- width = event.width;
- }
- if (index == 0) {
- NSOutlineView outlineView = (NSOutlineView)parent.view;
- width += outlineView.indentationPerLevel () * (1 + outlineView.levelForItem (handle));
- this.width = width;
- }
- return width;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void clear () {
- cached = false;
- text = "";
- image = null;
- strings = null;
- images = null;
- checked = grayed = false;
- foreground = background = null;
- cellForeground = cellBackground = null;
- font = null;
- cellFont = null;
- width = -1;
-}
-
-/**
- * Clears the item at the given zero-relative index in the receiver.
- * The text, icon and other attributes of the item are set to the default
- * value. If the tree was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param index the index of the item to clear
- * @param all <code>true</code> if all child items of the indexed item should be
- * cleared recursively, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clear (int index, boolean all) {
- checkWidget ();
- int count = getItemCount ();
- if (index < 0 || index >= count)
- SWT.error (SWT.ERROR_INVALID_RANGE);
- parent.clear (this, index, all);
-}
-
-
-/**
- * Clears all the items in the receiver. The text, icon and other
- * attributes of the items are set to their default values. If the
- * tree was created with the <code>SWT.VIRTUAL</code> style, these
- * attributes are requested again as needed.
- *
- * @param all <code>true</code> if all child items should be cleared
- * recursively, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clearAll (boolean all) {
- checkWidget ();
- parent.clearAll (this, all);
-}
-
-void clearSelection () {
- NSOutlineView widget = (NSOutlineView) parent.view;
- int /*long*/ row = widget.rowForItem (handle);
- if (widget.isRowSelected(row)) widget.deselectRow (row);
- if (items != null && getExpanded ()) {
- for (int i = 0; i < items.length; i++) {
- TreeItem item = items [i];
- if (item != null && !item.isDisposed ()) item.clearSelection ();
- }
- }
-}
-
-NSObject createString(int index) {
- String text = index == 0 ? this.text : (strings == null ? "" : strings [index]);
- return NSString.stringWith(text != null ? text : "");
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (handle);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns the receiver's background color.
- *
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public Color getBackground () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return background != null ? background : parent.getBackground ();
-}
-
-/**
- * Returns the background color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Color getBackground (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count -1) return getBackground ();
- if (cellBackground == null || cellBackground [index] == null) return getBackground ();
- return cellBackground [index];
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- parent.checkItems ();
- NSOutlineView outlineView = (NSOutlineView) parent.view;
- NSRect rect = outlineView.rectOfRow (outlineView.rowForItem (handle));
- return new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height);
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent at a column in the tree.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding column rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Rectangle getBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (!(0 <= index && index < Math.max (1, parent.columnCount))) return new Rectangle (0, 0, 0, 0);
-
- parent.checkItems ();
- NSOutlineView outlineView = (NSOutlineView) parent.view;
- if (parent.columnCount == 0) {
- index = (parent.style & SWT.CHECK) != 0 ? 1 : 0;
- } else {
- TreeColumn column = parent.getColumn (index);
- index = parent.indexOf (column.nsColumn);
- }
- NSRect rect = outlineView.frameOfCellAtColumn (index, outlineView.rowForItem (handle));
- return new Rectangle ((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is checked,
- * and false otherwise. When the parent does not have
- * the <code>CHECK style, return false.
- * <p>
- *
- * @return the checked state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getChecked () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return checked;
-}
-
-/**
- * Returns <code>true</code> if the receiver is expanded,
- * and false otherwise.
- * <p>
- *
- * @return the expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getExpanded () {
- checkWidget ();
- return expanded;
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information for this item.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return font != null ? font : parent.getFont ();
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information
- * for the specified cell in this item.
- *
- * @param index the column index
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Font getFont (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count -1) return getFont ();
- if (cellFont == null || cellFont [index] == null) return getFont ();
- return cellFont [index];
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public Color getForeground () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return foreground != null ? foreground : parent.getForeground ();
-}
-
-/**
- *
- * Returns the foreground color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Color getForeground (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count -1) return getForeground ();
- if (cellForeground == null || cellForeground [index] == null) return getForeground ();
- return cellForeground [index];
-}
-
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the parent does not have
- * the <code>CHECK style, return false.
- * <p>
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getGrayed () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return grayed;
-}
-
-public Image getImage () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return super.getImage ();
-}
-
-/**
- * Returns the image stored at the given column index in the receiver,
- * or null if the image has not been set or if the column does not exist.
- *
- * @param index the column index
- * @return the image stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Image getImage (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index == 0) return getImage ();
- if (images != null) {
- if (0 <= index && index < images.length) return images [index];
- }
- return null;
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of an image at a column in the
- * tree.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding image rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Rectangle getImageBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (!(0 <= index && index < Math.max (1, parent.columnCount))) return new Rectangle (0, 0, 0, 0);
-
- parent.checkItems ();
- NSOutlineView outlineView = (NSOutlineView) parent.view;
- Image image = index == 0 ? this.image : (images != null) ? images [index] : null;
- if (parent.columnCount == 0) {
- index = (parent.style & SWT.CHECK) != 0 ? 1 : 0;
- } else {
- TreeColumn column = parent.getColumn (index);
- index = parent.indexOf (column.nsColumn);
- }
- NSRect rect = outlineView.frameOfCellAtColumn (index, outlineView.rowForItem (handle));
- rect.x += Tree.IMAGE_GAP;
- if (image != null) {
- rect.width = parent.imageBounds.width;
- } else {
- rect.width = 0;
- }
- return new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height);
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public TreeItem getItem (int index) {
- checkWidget ();
- if (index < 0) error (SWT.ERROR_INVALID_RANGE);
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index >= itemCount) error (SWT.ERROR_INVALID_RANGE);
- return parent._getItem (this, index, true);
-}
-
-/**
- * Returns the number of items contained in the receiver
- * that are direct item children of the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return itemCount;
-}
-
-/**
- * Returns a (possibly empty) array of <code>TreeItem</code>s which
- * are the direct item children of the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem [] getItems () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- TreeItem [] result = new TreeItem [itemCount];
- for (int i=0; i<itemCount; i++) {
- result [i] = parent._getItem (this, i, true);
- }
- return result;
-}
-
-String getNameText () {
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (!cached) return "*virtual*"; //$NON-NLS-1$
- }
- return super.getNameText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Tree</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Tree getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>TreeItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem getParentItem () {
- checkWidget ();
- return parentItem;
-}
-
-public String getText () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return super.getText ();
-}
-
-/**
- * Returns the text stored at the given column index in the receiver,
- * or empty string if the text has not been set.
- *
- * @param index the column index
- * @return the text stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public String getText (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index == 0) return getText ();
- if (strings != null) {
- if (0 <= index && index < strings.length) {
- String string = strings [index];
- return string != null ? string : "";
- }
- }
- return "";
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of the text at a column in the
- * tree.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding text rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Rectangle getTextBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (!(0 <= index && index < Math.max (1, parent.columnCount))) return new Rectangle (0, 0, 0, 0);
-
- parent.checkItems ();
- NSOutlineView outlineView = (NSOutlineView) parent.view;
- Image image = index == 0 ? this.image : (images != null) ? images [index] : null;
- if (parent.columnCount == 0) {
- index = (parent.style & SWT.CHECK) != 0 ? 1 : 0;
- } else {
- TreeColumn column = parent.getColumn (index);
- index = parent.indexOf (column.nsColumn);
- }
- NSRect rect = outlineView.frameOfCellAtColumn (index, outlineView.rowForItem (handle));
- rect.x += Tree.TEXT_GAP;
- rect.width -= Tree.TEXT_GAP;
- if (image != null) {
- int offset = parent.imageBounds.width + Tree.IMAGE_GAP;
- rect.x += offset;
- rect.width -= offset;
- }
- return new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height);
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int indexOf (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (item.parentItem != this) return -1;
- for (int i = 0; i < itemCount; i++) {
- if (item == items [i]) return i;
- }
- return -1;
-}
-
-void redraw (int columnIndex) {
- if (parent.ignoreRedraw || !isDrawing()) return;
- /* redraw the full item if columnIndex == -1 */
- NSOutlineView outlineView = (NSOutlineView) parent.view;
- NSRect rect;
- if (columnIndex == -1 || parent.hooks (SWT.MeasureItem) || parent.hooks (SWT.EraseItem) || parent.hooks (SWT.PaintItem)) {
- rect = outlineView.rectOfRow (outlineView.rowForItem (handle));
- } else {
- int index;
- if (parent.columnCount == 0) {
- index = (parent.style & SWT.CHECK) != 0 ? 1 : 0;
- } else {
- if (0 <= columnIndex && columnIndex < parent.columnCount) {
- index = parent.indexOf (parent.columns[columnIndex].nsColumn);
- } else {
- return;
- }
- }
- rect = outlineView.frameOfCellAtColumn (index, outlineView.rowForItem (handle));
- }
- outlineView.setNeedsDisplayInRect (rect);
-}
-
-void register () {
- super.register ();
- display.addWidget (handle, this);
-}
-
-void release(boolean destroy) {
- /*
- * Bug in Cocoa. When removing selected items from an NSOutlineView, the selection
- * is not properly updated. The fix is to ensure that the item and its subitems
- * are deselected before the item is removed by the reloadItem call.
- *
- * This has to be done in release to avoid traversing the tree twice when items are
- * removed from the tree by setItemCount.
- */
- if (destroy) clearSelection ();
- super.release(destroy);
-}
-
-void releaseChildren (boolean destroy) {
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- itemCount = 0;
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (handle != null) handle.release ();
- handle = null;
- parentItem = null;
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- strings = null;
- images = null;
- background = foreground = null;
- font = null;
- cellBackground = cellForeground = null;
- cellFont = null;
-}
-
-/**
- * Removes all of the items from the receiver.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void removeAll () {
- checkWidget ();
- parent.setItemCount (this, 0);
-}
-
-void sendExpand (boolean expand, boolean recurse) {
- if (itemCount == 0) return;
- if (expanded != expand) {
- Event event = new Event ();
- event.item = this;
- parent.sendEvent (expand ? SWT.Expand : SWT.Collapse, event);
- if (isDisposed ()) return;
- expanded = expand;
- }
- if (recurse) {
- for (int i = 0; i < itemCount; i++) {
- if (items[i] != null) items[i].sendExpand (expand, recurse);
- }
- }
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public void setBackground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Color oldColor = background;
- if (oldColor == color) return;
- background = color;
- if (oldColor != null && oldColor.equals (color)) return;
- cached = true;
- redraw (-1);
-}
-
-/**
- * Sets the background color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- *
- */
-public void setBackground (int index, Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count - 1) return;
- if (cellBackground == null) {
- if (color == null) return;
- cellBackground = new Color [count];
- }
- Color oldColor = cellBackground [index];
- if (oldColor == color) return;
- cellBackground [index] = color;
- if (oldColor != null && oldColor.equals (color)) return;
- cached = true;
- redraw (index);
-}
-
-/**
- * Sets the checked state of the receiver.
- * <p>
- *
- * @param checked the new checked state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setChecked (boolean checked) {
- checkWidget ();
- if ((parent.style & SWT.CHECK) == 0) return;
- if (this.checked == checked) return;
- this.checked = checked;
- cached = true;
- redraw (-1);
-}
-
-/**
- * Sets the expanded state of the receiver.
- * <p>
- *
- * @param expanded the new expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setExpanded (boolean expanded) {
- checkWidget ();
-
- /* Do nothing when the item is a leaf or already expanded */
- if (itemCount == 0 || expanded == getExpanded ()) return;
-
- parent.checkItems ();
- parent.ignoreExpand = true;
- this.expanded = expanded;
- if (expanded) {
- ((NSOutlineView) parent.view).expandItem (handle);
- } else {
- ((NSOutlineView) parent.view).collapseItem (handle);
- }
- parent.ignoreExpand = false;
- cached = true;
- if (!expanded) {
- parent.setScrollWidth ();
- }
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for this item to the font specified by the argument, or to the default font
- * for that kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (Font font) {
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Font oldFont = this.font;
- if (oldFont == font) return;
- this.font = font;
- if (oldFont != null && oldFont.equals (font)) return;
- width = -1;
- cached = true;
- redraw (-1);
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for the specified cell in this item to the font specified by the
- * argument, or to the default font for that kind of control if the
- * argument is null.
- *
- * @param index the column index
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setFont (int index, Font font) {
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count - 1) return;
- if (cellFont == null) {
- if (font == null) return;
- cellFont = new Font [count];
- }
- Font oldFont = cellFont [index];
- if (oldFont == font) return;
- cellFont [index] = font;
- if (oldFont != null && oldFont.equals (font)) return;
- width = -1;
- cached = true;
- redraw (index);
-}
-
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @since 2.0
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public void setForeground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Color oldColor = foreground;
- if (oldColor == color) return;
- foreground = color;
- if (oldColor != null && oldColor.equals (color)) return;
- cached = true;
- redraw (-1);
-}
-
-/**
- * Sets the foreground color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- *
- */
-public void setForeground (int index, Color color){
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count - 1) return;
- if (cellForeground == null) {
- if (color == null) return;
- cellForeground = new Color [count];
- }
- Color oldColor = cellForeground [index];
- if (oldColor == color) return;
- cellForeground [index] = color;
- if (oldColor != null && oldColor.equals (color)) return;
- cached = true;
- redraw (index);
-}
-
-/**
- * Sets the grayed state of the checkbox for this item. This state change
- * only applies if the Tree was created with the SWT.CHECK style.
- *
- * @param grayed the new grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setGrayed (boolean grayed) {
- checkWidget ();
- if ((parent.style & SWT.CHECK) == 0) return;
- if (this.grayed == grayed) return;
- this.grayed = grayed;
- cached = true;
- redraw (-1);
-}
-
-/**
- * Sets the image for multiple columns in the tree.
- *
- * @param images the array of new images
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setImage (Image [] images) {
- checkWidget ();
- if (images == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<images.length; i++) {
- setImage (i, images [i]);
- }
-}
-
-/**
- * Sets the receiver's image at a column.
- *
- * @param index the column index
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setImage (int index, Image image) {
- checkWidget ();
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (parent.imageBounds == null && image != null) {
- parent.setItemHeight (image, null, false);
- }
- if (index == 0) {
- if (image != null && image.type == SWT.ICON) {
- if (image.equals (this.image)) return;
- }
- width = -1;
- super.setImage (image);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 <= index && index < count) {
- if (images == null) images = new Image [count];
- if (image != null && image.type == SWT.ICON) {
- if (image.equals (images [index])) return;
- }
- images [index] = image;
- }
- cached = true;
- if (index == 0) parent.setScrollWidth (this);
- if (0 <= index && index < count) redraw (index);
-}
-
-public void setImage (Image image) {
- checkWidget ();
- setImage (0, image);
-}
-
-/**
- * Sets the number of child items contained in the receiver.
- *
- * @param count the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setItemCount (int count) {
- checkWidget ();
- count = Math.max (0, count);
- parent.setItemCount (this, count);
-}
-
-/**
- * Sets the text for multiple columns in the tree.
- *
- * @param strings the array of new strings
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setText (String [] strings) {
- checkWidget ();
- if (strings == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<strings.length; i++) {
- String string = strings [i];
- if (string != null) setText (i, string);
- }
-}
-
-/**
- * Sets the receiver's text at a column
- *
- * @param index the column index
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setText (int index, String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (index == 0) {
- if (string.equals (text)) return;
- width = -1;
- super.setText (string);
- }
- int count = Math.max (1, parent.columnCount);
- if (0 <= index && index < count) {
- if (strings == null) strings = new String [count];
- if (string.equals (strings [index])) return;
- strings [index] = string;
- }
- cached = true;
- if (index == 0) parent.setScrollWidth (this);
- if (0 <= index && index < count) redraw (index);
-}
-
-public void setText (String string) {
- checkWidget ();
- setText (0, string);
-}
-
-void updateExpanded () {
- if (itemCount == 0) return;
- NSOutlineView outlineView = (NSOutlineView)parent.view;
- if (expanded != outlineView.isItemExpanded (handle)) {
- if (expanded) {
- outlineView.expandItem (handle);
- } else {
- outlineView.collapseItem (handle);
- }
- }
- for (int i = 0; i < itemCount; i++) {
- if (items[i] != null) items[i].updateExpanded ();
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java
deleted file mode 100755
index 3ec4eadbcb..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java
+++ /dev/null
@@ -1,1767 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
-/**
- * This class is the abstract superclass of all user interface objects.
- * Widgets are created, disposed and issue notification to listeners
- * when events occur which affect them.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Dispose</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation. However, it has not been marked
- * final to allow those outside of the SWT development team to implement
- * patched versions of the class in order to get around specific
- * limitations in advance of when those limitations can be addressed
- * by the team. Any class built using subclassing to access the internals
- * of this class will likely fail to compile or run between releases and
- * may be strongly platform specific. Subclassing should not be attempted
- * without an intimate and detailed understanding of the workings of the
- * hierarchy. No support is provided for user-written classes which are
- * implemented as subclasses of this class.
- * </p>
- *
- * @see #checkSubclass
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class Widget {
- int style, state;
- Display display;
- EventTable eventTable;
- Object data;
-
- int /*long*/ jniRef;
-
- /* Global state flags */
- static final int DISPOSED = 1 << 0;
- static final int CANVAS = 1 << 1;
- static final int KEYED_DATA = 1 << 2;
- static final int DISABLED = 1 << 3;
- static final int HIDDEN = 1 << 4;
- static final int GRAB = 1 << 5;
- static final int MOVED = 1 << 6;
- static final int RESIZED = 1 << 7;
- static final int EXPANDING = 1 << 8;
- static final int IGNORE_WHEEL = 1 << 9;
- static final int PARENT_BACKGROUND = 1 << 10;
- static final int THEME_BACKGROUND = 1 << 11;
-
- /* A layout was requested on this widget */
- static final int LAYOUT_NEEDED = 1<<12;
-
- /* The preferred size of a child has changed */
- static final int LAYOUT_CHANGED = 1<<13;
-
- /* A layout was requested in this widget hierachy */
- static final int LAYOUT_CHILD = 1<<14;
-
- /* More global state flags */
- static final int RELEASED = 1<<15;
- static final int DISPOSE_SENT = 1<<16;
- static final int FOREIGN_HANDLE = 1<<17;
- static final int DRAG_DETECT = 1<<18;
-
- /* Safari fixes */
- static final int SAFARI_EVENTS_FIX = 1<<19;
- static final String SAFARI_EVENTS_FIX_KEY = "org.eclipse.swt.internal.safariEventsFix"; //$NON-NLS-1$
- static final String GLCONTEXT_KEY = "org.eclipse.swt.internal.cocoa.glcontext"; //$NON-NLS-1$
-
- /* Default size for widgets */
- static final int DEFAULT_WIDTH = 64;
- static final int DEFAULT_HEIGHT = 64;
-
-Widget () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see #checkSubclass
- * @see #getStyle
- */
-public Widget (Widget parent, int style) {
- checkSubclass ();
- checkParent (parent);
- this.style = style;
- display = parent.display;
-}
-
-int /*long*/ accessibilityActionDescription(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- return callSuperObject(id, sel, arg0);
-}
-
-int /*long*/ accessibilityActionNames(int /*long*/ id, int /*long*/ sel) {
- return callSuperObject(id, sel);
-}
-
-int /*long*/ accessibilityAttributeNames(int /*long*/ id, int /*long*/ sel) {
- return callSuperObject(id, sel);
-}
-
-int /*long*/ accessibilityAttributeValue(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- return callSuperObject(id, sel, arg0);
-}
-
-int /*long*/ accessibilityAttributeValue_forParameter(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- return OS.objc_msgSendSuper(super_struct, sel, arg0, arg1);
-}
-
-int /*long*/ accessibilityFocusedUIElement(int /*long*/ id, int /*long*/ sel) {
- return callSuperObject(id, sel);
-}
-
-int /*long*/ accessibilityHitTest(int /*long*/ id, int /*long*/ sel, NSPoint point) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- return OS.objc_msgSendSuper(super_struct, sel, point);
-}
-
-boolean accessibilityIsIgnored(int /*long*/ id, int /*long*/ sel) {
- return callSuperBoolean(id, sel);
-}
-
-int /*long*/ accessibilityParameterizedAttributeNames(int /*long*/ id, int /*long*/ sel) {
- return callSuperObject(id, sel);
-}
-
-void accessibilityPerformAction(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- callSuper(id, sel, arg0);
-}
-
-String getClipboardText () {
- NSPasteboard pasteboard = NSPasteboard.generalPasteboard ();
- NSString string = pasteboard.stringForType (OS.NSStringPboardType);
- return string != null ? string.getString () : null;
-}
-
-void setClipRegion (float /*double*/ x, float /*double*/ y) {
-}
-
-int /*long*/ attributedSubstringFromRange (int /*long*/ id, int /*long*/ sel, int /*long*/ range) {
- return 0;
-}
-
-void callSuper(int /*long*/ id, int /*long*/ sel) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- OS.objc_msgSendSuper(super_struct, sel);
-}
-
-void callSuper(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- OS.objc_msgSendSuper(super_struct, sel, arg0);
-}
-
-void callSuper(int /*long*/ id, int /*long*/ sel, NSRect arg0) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- OS.objc_msgSendSuper(super_struct, sel, arg0);
-}
-
-void callSuper(int /*long*/ id, int /*long*/ sel, NSRect arg0, int /*long*/ arg1) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- OS.objc_msgSendSuper(super_struct, sel, arg0, arg1);
-}
-
-int /*long*/ callSuper(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, NSRect arg1, int /*long*/ arg2) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- return OS.objc_msgSendSuper(super_struct, sel, arg0, arg1, arg2);
-}
-
-boolean callSuperBoolean(int /*long*/ id, int /*long*/ sel) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- return OS.objc_msgSendSuper(super_struct, sel) != 0;
-}
-
-boolean canBecomeKeyWindow (int /*long*/ id, int /*long*/ sel) {
- return callSuperBoolean (id, sel);
-}
-
-NSSize cellSize (int /*long*/ id, int /*long*/ sel) {
- NSSize result = new NSSize();
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- OS.objc_msgSendSuper_stret(result, super_struct, sel);
- return result;
-}
-
-boolean callSuperBoolean(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- return OS.objc_msgSendSuper(super_struct, sel, arg0) != 0;
-}
-
-boolean callSuperBoolean(int /*long*/ id, int /*long*/ sel, NSRange range, int /*long*/ arg1) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- return OS.objc_msgSendSuper_bool(super_struct, sel, range, arg1);
-}
-
-int /*long*/ callSuperObject(int /*long*/ id, int /*long*/ sel) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- return OS.objc_msgSendSuper(super_struct, sel);
-}
-
-int /*long*/ callSuperObject(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- return OS.objc_msgSendSuper(super_struct, sel, arg0);
-}
-
-boolean canDragRowsWithIndexes_atPoint(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1) {
- // Trees/tables are not draggable unless explicitly told they are.
- return false;
-}
-
-int /*long*/ characterIndexForPoint (int /*long*/ id, int /*long*/ sel, int /*long*/ point) {
- return OS.NSNotFound;
-}
-
-boolean acceptsFirstMouse (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- return OS.objc_msgSendSuper(super_struct, sel, theEvent) != 0;
-}
-
-boolean acceptsFirstResponder (int /*long*/ id, int /*long*/ sel) {
- return callSuperBoolean(id, sel);
-}
-
-boolean becomeFirstResponder (int /*long*/ id, int /*long*/ sel) {
- return callSuperBoolean(id, sel);
-}
-
-void becomeKeyWindow (int /*long*/ id, int /*long*/ sel) {
- callSuper(id, sel);
-}
-
-boolean resignFirstResponder (int /*long*/ id, int /*long*/ sel) {
- return callSuperBoolean(id, sel);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs. When the
- * event does occur in the widget, the listener is notified by
- * sending it the <code>handleEvent()</code> message. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #getListeners(int)
- * @see #removeListener(int, Listener)
- * @see #notifyListeners
- */
-public void addListener (int eventType, Listener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- _addListener (eventType, listener);
-}
-
-void _addListener (int eventType, Listener listener) {
- if (eventTable == null) eventTable = new EventTable ();
- eventTable.hook (eventType, listener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the widget is disposed. When the widget is
- * disposed, the listener is notified by sending it the
- * <code>widgetDisposed()</code> message.
- *
- * @param listener the listener which should be notified when the receiver is disposed
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DisposeListener
- * @see #removeDisposeListener
- */
-public void addDisposeListener (DisposeListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Dispose, typedListener);
-}
-
-boolean canBecomeKeyView(int /*long*/ id, int /*long*/ sel) {
- return true;
-}
-
-static int checkBits (int style, int int0, int int1, int int2, int int3, int int4, int int5) {
- int mask = int0 | int1 | int2 | int3 | int4 | int5;
- if ((style & mask) == 0) style |= int0;
- if ((style & int0) != 0) style = (style & ~mask) | int0;
- if ((style & int1) != 0) style = (style & ~mask) | int1;
- if ((style & int2) != 0) style = (style & ~mask) | int2;
- if ((style & int3) != 0) style = (style & ~mask) | int3;
- if ((style & int4) != 0) style = (style & ~mask) | int4;
- if ((style & int5) != 0) style = (style & ~mask) | int5;
- return style;
-}
-
-void checkOpen () {
- /* Do nothing */
-}
-
-void checkOrientation (Widget parent) {
- style &= ~SWT.MIRRORED;
- if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) {
- if (parent != null) {
- if ((parent.style & SWT.LEFT_TO_RIGHT) != 0) style |= SWT.LEFT_TO_RIGHT;
- if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) style |= SWT.RIGHT_TO_LEFT;
- }
- }
- style = checkBits (style, SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT, 0, 0, 0, 0);
-}
-
-void checkParent (Widget parent) {
- if (parent == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (parent.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- parent.checkWidget ();
- parent.checkOpen ();
-}
-
-/**
- * Checks that this class can be subclassed.
- * <p>
- * The SWT class library is intended to be subclassed
- * only at specific, controlled points (most notably,
- * <code>Composite</code> and <code>Canvas</code> when
- * implementing new widgets). This method enforces this
- * rule unless it is overridden.
- * </p><p>
- * <em>IMPORTANT:</em> By providing an implementation of this
- * method that allows a subclass of a class which does not
- * normally allow subclassing to be created, the implementer
- * agrees to be fully responsible for the fact that any such
- * subclass will likely fail between SWT releases and will be
- * strongly platform specific. No support is provided for
- * user-written classes which are implemented in this fashion.
- * </p><p>
- * The ability to subclass outside of the allowed SWT classes
- * is intended purely to enable those not on the SWT development
- * team to implement patches in order to get around specific
- * limitations in advance of when those limitations can be
- * addressed by the team. Subclassing should not be attempted
- * without an intimate and detailed understanding of the hierarchy.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Throws an <code>SWTException</code> if the receiver can not
- * be accessed by the caller. This may include both checks on
- * the state of the receiver and more generally on the entire
- * execution context. This method <em>should</em> be called by
- * widget implementors to enforce the standard SWT invariants.
- * <p>
- * Currently, it is an error to invoke any method (other than
- * <code>isDisposed()</code>) on a widget that has had its
- * <code>dispose()</code> method called. It is also an error
- * to call widget methods from any thread that is different
- * from the thread that created the widget.
- * </p><p>
- * In future releases of SWT, there may be more or fewer error
- * checks and exceptions may be thrown for different reasons.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-protected void checkWidget () {
- Display display = this.display;
- if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
- if (display.thread != Thread.currentThread () && !display.isEmbedded) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if ((state & DISPOSED) != 0) error (SWT.ERROR_WIDGET_DISPOSED);
-}
-
-boolean textView_clickOnLink_atIndex(int /*long*/ id, int /*long*/ sel, int /*long*/ textView, int /*long*/ link, int /*long*/ charIndex) {
- return true;
-}
-
-void collapseItem_collapseChildren (int /*long*/ id, int /*long*/ sel, int /*long*/ item, boolean children) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- OS.objc_msgSendSuper(super_struct, sel, item, children);
-}
-
-void copyToClipboard (char [] buffer) {
- if (buffer.length == 0) return;
- NSPasteboard pasteboard = NSPasteboard.generalPasteboard ();
- pasteboard.declareTypes (NSArray.arrayWithObject (OS.NSStringPboardType), null);
- pasteboard.setString (NSString.stringWithCharacters (buffer, buffer.length), OS.NSStringPboardType);
-}
-
-void createHandle () {
-}
-
-void createJNIRef () {
- jniRef = OS.NewGlobalRef(this);
- if (jniRef == 0) error (SWT.ERROR_NO_HANDLES);
-}
-
-void createWidget () {
- createJNIRef ();
- createHandle ();
- register ();
-}
-
-void deregister () {
-}
-
-void destroyJNIRef () {
- if (jniRef != 0) OS.DeleteGlobalRef (jniRef);
- jniRef = 0;
-}
-
-void destroyWidget () {
- releaseHandle ();
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the receiver and all its descendants. After this method has
- * been invoked, the receiver and all descendants will answer
- * <code>true</code> when sent the message <code>isDisposed()</code>.
- * Any internal connections between the widgets in the tree will
- * have been removed to facilitate garbage collection.
- * <p>
- * NOTE: This method is not called recursively on the descendants
- * of the receiver. This means that, widget implementers can not
- * detect when a widget is being disposed of by re-implementing
- * this method, but should instead listen for the <code>Dispose</code>
- * event.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #addDisposeListener
- * @see #removeDisposeListener
- * @see #checkWidget
- */
-public void dispose () {
- /*
- * Note: It is valid to attempt to dispose a widget
- * more than once. If this happens, fail silently.
- */
- if (isDisposed ()) return;
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- release (true);
-}
-
-void doCommandBySelector (int /*long*/ id, int /*long*/ sel, int /*long*/ aSelector) {
- callSuper (id, sel, aSelector);
-}
-
-boolean dragSelectionWithEvent(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2) {
- return false;
-}
-
-void drawBackground (int /*long*/ id, NSGraphicsContext context, NSRect rect) {
- /* Do nothing */
-}
-
-void drawImageWithFrameInView (int /*long*/ id, int /*long*/ sel, int /*long*/ image, NSRect rect, int /*long*/ view) {
-}
-
-void drawInteriorWithFrame_inView (int /*long*/ id, int /*long*/ sel, NSRect cellFrame, int /*long*/ view) {
- callSuper(id, sel, cellFrame, view);
-}
-
-void drawWithExpansionFrame_inView (int /*long*/ id, int /*long*/ sel, NSRect cellFrame, int /*long*/ view) {
- callSuper(id, sel, cellFrame, view);
-}
-
-void drawRect (int /*long*/ id, int /*long*/ sel, NSRect rect) {
- if (!isDrawing()) return;
- Display display = this.display;
- NSView view = new NSView(id);
- display.isPainting.addObject(view);
- NSGraphicsContext context = NSGraphicsContext.currentContext();
- context.saveGraphicsState();
- setClipRegion(0, 0);
- drawBackground (id, context, rect);
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- OS.objc_msgSendSuper(super_struct, sel, rect);
- if (!isDisposed()) {
- /*
- * Feature in Cocoa. There are widgets that draw outside of the UI thread,
- * such as the progress bar and default button. The fix is to draw the
- * widget but not send paint events.
- */
- drawWidget (id, context, rect);
- }
- context.restoreGraphicsState();
- display.isPainting.removeObjectIdenticalTo(view);
-}
-
-void _drawThemeProgressArea (int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- OS.objc_msgSendSuper(super_struct, sel, arg0);
-}
-
-void drawWidget (int /*long*/ id, NSGraphicsContext context, NSRect rect) {
-}
-
-void redrawWidget (NSView view, boolean children) {
- view.setNeedsDisplay(true);
-}
-
-void redrawWidget (NSView view, int /*long*/ x, int /*long*/ y, int /*long*/ width, int /*long*/ height, boolean children) {
- NSRect rect = new NSRect();
- rect.x = x;
- rect.y = y;
- rect.width = width;
- rect.height = height;
- view.setNeedsDisplayInRect(rect);
-}
-
-void error (int code) {
- SWT.error(code);
-}
-
-void expandItem_expandChildren (int /*long*/ id, int /*long*/ sel, int /*long*/ item, boolean children) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- OS.objc_msgSendSuper(super_struct, sel, item, children);
-}
-
-NSRect expansionFrameWithFrame_inView(int /*long*/ id, int /*long*/ sel, NSRect cellRect, int /*long*/ view) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- NSRect result = new NSRect();
- OS.objc_msgSendSuper_stret(result, super_struct, sel, cellRect, view);
- return result;
-}
-
-boolean filters (int eventType) {
- return display.filters (eventType);
-}
-
-NSRect firstRectForCharacterRange(int /*long*/ id, int /*long*/ sel, int /*long*/ range) {
- return new NSRect ();
-}
-
-int fixMnemonic (char [] buffer) {
- int i=0, j=0;
- while (i < buffer.length) {
- if ((buffer [j++] = buffer [i++]) == '&') {
- if (i == buffer.length) {continue;}
- if (buffer [i] == '&') {i++; continue;}
- j--;
- }
- }
- return j;
-}
-
-/**
- * Returns the application defined widget data associated
- * with the receiver, or null if it has not been set. The
- * <em>widget data</em> is a single, unnamed field that is
- * stored with every widget.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the widget data needs to be notified
- * when the widget is disposed of, it is the application's
- * responsibility to hook the Dispose event on the widget and
- * do so.
- * </p>
- *
- * @return the widget data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
- * </ul>
- *
- * @see #setData(Object)
- */
-public Object getData () {
- checkWidget();
- return (state & KEYED_DATA) != 0 ? ((Object []) data) [0] : data;
-}
-
-/**
- * Returns the application defined property of the receiver
- * with the specified name, or null if it has not been set.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the widget is disposed
- * of, it is the application's responsibility to hook the
- * Dispose event on the widget and do so.
- * </p>
- *
- * @param key the name of the property
- * @return the value of the property or null if it has not been set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setData(String, Object)
- */
-public Object getData (String key) {
- checkWidget();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((state & KEYED_DATA) != 0) {
- Object [] table = (Object []) data;
- for (int i=1; i<table.length; i+=2) {
- if (key.equals (table [i])) return table [i+1];
- }
- }
- return null;
-}
-
-/**
- * Returns the <code>Display</code> that is associated with
- * the receiver.
- * <p>
- * A widget's display is either provided when it is created
- * (for example, top level <code>Shell</code>s) or is the
- * same as its parent's display.
- * </p>
- *
- * @return the receiver's display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Display getDisplay () {
- Display display = this.display;
- if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return display;
-}
-
-boolean getDrawing () {
- return true;
-}
-
-/**
- * Returns an array of listeners who will be notified when an event
- * of the given type occurs. The event type is one of the event constants
- * defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @return an array of listeners that will be notified when the event occurs
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener(int, Listener)
- * @see #removeListener(int, Listener)
- * @see #notifyListeners
- *
- * @since 3.4
- */
-public Listener[] getListeners (int eventType) {
- checkWidget();
- if (eventTable == null) return new Listener[0];
- return eventTable.getListeners(eventType);
-}
-
-String getName () {
- String string = getClass ().getName ();
- int index = string.lastIndexOf ('.');
- if (index == -1) return string;
- return string.substring (index + 1, string.length ());
-}
-
-String getNameText () {
- return "";
-}
-
-/**
- * Returns the receiver's style information.
- * <p>
- * Note that the value which is returned by this method <em>may
- * not match</em> the value which was provided to the constructor
- * when the receiver was created. This can occur when the underlying
- * operating system does not support a particular combination of
- * requested styles. For example, if the platform widget used to
- * implement a particular SWT widget always has scroll bars, the
- * result of calling this method would always have the
- * <code>SWT.H_SCROLL</code> and <code>SWT.V_SCROLL</code> bits set.
- * </p>
- *
- * @return the style bits
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getStyle () {
- checkWidget();
- return style;
-}
-
-boolean hasMarkedText (int /*long*/ id, int /*long*/ sel) {
- return false;
-}
-
-void helpRequested(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
-}
-
-void highlightSelectionInClipRect(int /*long*/ id, int /*long*/ sel, int /*long*/ rect) {
-}
-
-int /*long*/ hitTest (int /*long*/ id, int /*long*/ sel, NSPoint point) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- return OS.objc_msgSendSuper(super_struct, sel, point);
-}
-
-int /*long*/ hitTestForEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ event, NSRect rect, int /*long*/ controlView) {
- return 0;
-}
-
-boolean hooks (int eventType) {
- if (eventTable == null) return false;
- return eventTable.hooks (eventType);
-}
-
-int /*long*/ image (int /*long*/ id, int /*long*/ sel) {
- return 0;
-}
-
-NSRect imageRectForBounds (int /*long*/ id, int /*long*/ sel, NSRect cellFrame) {
- return new NSRect();
-}
-
-boolean insertText (int /*long*/ id, int /*long*/ sel, int /*long*/ string) {
- callSuper (id, sel, string);
- return true;
-}
-
-/**
- * Returns <code>true</code> if the widget has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the widget.
- * When a widget has been disposed, it is an error to
- * invoke any other method using the widget.
- * </p>
- *
- * @return <code>true</code> when the widget is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- return (state & DISPOSED) != 0;
-}
-
-boolean isDrawing () {
- return true;
-}
-
-boolean isFlipped(int /*long*/ id, int /*long*/ sel) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- return OS.objc_msgSendSuper(super_struct, sel) != 0;
-}
-
-/**
- * Returns <code>true</code> if there are any listeners
- * for the specified event type associated with the receiver,
- * and <code>false</code> otherwise. The event type is one of
- * the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event
- * @return true if the event is hooked
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public boolean isListening (int eventType) {
- checkWidget();
- return hooks (eventType);
-}
-
-boolean isOpaque(int /*long*/ id, int /*long*/ sel) {
- return false;
-}
-
-boolean isValidSubclass () {
- return Display.isValidClass (getClass ());
-}
-
-boolean isValidThread () {
- return getDisplay ().isValidThread ();
-}
-
-void flagsChanged (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- callSuper (id, sel, theEvent);
-}
-
-void keyDown (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- superKeyDown(id, sel, theEvent);
-}
-
-void keyUp (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- superKeyUp(id, sel, theEvent);
-}
-
-void mouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- callSuper(id, sel, theEvent);
-}
-
-void mouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- callSuper(id, sel, theEvent);
-}
-
-void mouseMoved(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- callSuper(id, sel, theEvent);
-}
-
-void mouseDragged(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- callSuper(id, sel, theEvent);
-}
-
-void mouseEntered(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- callSuper(id, sel, theEvent);
-}
-
-void mouseExited(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- callSuper(id, sel, theEvent);
-}
-
-void cursorUpdate(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- callSuper(id, sel, theEvent);
-}
-
-void rightMouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- callSuper(id, sel, theEvent);
-}
-
-void rightMouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- callSuper(id, sel, theEvent);
-}
-
-void rightMouseDragged(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- callSuper(id, sel, theEvent);
-}
-
-void otherMouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- callSuper(id, sel, theEvent);
-}
-
-void otherMouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- callSuper(id, sel, theEvent);
-}
-
-void otherMouseDragged(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- callSuper(id, sel, theEvent);
-}
-
-boolean shouldDelayWindowOrderingForEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- return OS.objc_msgSendSuper(super_struct, sel, theEvent) != 0;
-}
-
-boolean menuHasKeyEquivalent_forEvent_target_action(int /*long*/ id, int /*long*/ sel, int /*long*/ menu, int /*long*/ event, int /*long*/ target, int /*long*/ action) {
- return true;
-}
-
-int /*long*/ menuForEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- return OS.objc_msgSendSuper(super_struct, sel, theEvent);
-}
-
-void menuNeedsUpdate(int /*long*/ id, int /*long*/ sel, int /*long*/ menu) {
-}
-
-boolean makeFirstResponder(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
- return callSuperBoolean(id, sel, notification);
-}
-
-NSRange markedRange (int /*long*/ id, int /*long*/ sel) {
- return new NSRange ();
-}
-
-void menu_willHighlightItem(int /*long*/ id, int /*long*/ sel, int /*long*/ menu, int /*long*/ item) {
-}
-
-void menuDidClose(int /*long*/ id, int /*long*/ sel, int /*long*/ menu) {
-}
-
-void menuWillOpen(int /*long*/ id, int /*long*/ sel, int /*long*/ menu) {
-}
-
-void noResponderFor(int /*long*/ id, int /*long*/ sel, int /*long*/ selector) {
- callSuper(id, sel, selector);
-}
-
-int /*long*/ numberOfRowsInTableView(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView) {
- return 0;
-}
-
-int /*long*/ outlineView_child_ofItem(int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ index, int /*long*/ item) {
- return 0;
-}
-
-void outlineView_didClickTableColumn(int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ tableColumn) {
-}
-
-int /*long*/ outlineView_objectValueForTableColumn_byItem(int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ tableColumn, int /*long*/ item) {
- return 0;
-}
-
-boolean outlineView_isItemExpandable(int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ item) {
- return false;
-}
-
-int /*long*/ outlineView_numberOfChildrenOfItem(int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ item) {
- return 0;
-}
-
-void outlineView_willDisplayCell_forTableColumn_item(int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ cell, int /*long*/ tableColumn, int /*long*/ item) {
-}
-
-void outlineViewColumnDidMove (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
-}
-
-void outlineViewColumnDidResize (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
-}
-
-void outlineViewSelectionDidChange(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
-}
-
-void outlineView_setObjectValue_forTableColumn_byItem(int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ object, int /*long*/ tableColumn, int /*long*/ item) {
-}
-
-boolean outlineView_writeItems_toPasteboard(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2) {
- return false;
-}
-
-
-/**
- * Notifies all of the receiver's listeners for events
- * of the given type that one such event has occurred by
- * invoking their <code>handleEvent()</code> method. The
- * event type is one of the event constants defined in class
- * <code>SWT</code>.
- *
- * @param eventType the type of event which has occurred
- * @param event the event data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- * @see #addListener
- * @see #getListeners(int)
- * @see #removeListener(int, Listener)
- */
-public void notifyListeners (int eventType, Event event) {
- checkWidget();
- if (event == null) event = new Event ();
- sendEvent (eventType, event);
-}
-
-void pageDown (int /*long*/ id, int /*long*/ sel, int /*long*/ sender) {
- callSuper(id, sel, sender);
-}
-
-void pageUp (int /*long*/ id, int /*long*/ sel, int /*long*/ sender) {
- callSuper(id, sel, sender);
-}
-
-void postEvent (int eventType) {
- sendEvent (eventType, null, false);
-}
-
-void postEvent (int eventType, Event event) {
- sendEvent (eventType, event, false);
-}
-
-void reflectScrolledClipView (int /*long*/ id, int /*long*/ sel, int /*long*/ aClipView) {
- callSuper (id, sel, aClipView);
-}
-
-void register () {
-}
-
-void release (boolean destroy) {
- if ((state & DISPOSE_SENT) == 0) {
- state |= DISPOSE_SENT;
- sendEvent (SWT.Dispose);
- }
- if ((state & DISPOSED) == 0) {
- releaseChildren (destroy);
- }
- if ((state & RELEASED) == 0) {
- state |= RELEASED;
- if (destroy) {
- releaseParent ();
- releaseWidget ();
- destroyWidget ();
- } else {
- releaseWidget ();
- releaseHandle ();
- }
- }
-}
-
-void releaseChildren (boolean destroy) {
-}
-
-void releaseHandle () {
- state |= DISPOSED;
- display = null;
- destroyJNIRef ();
-}
-
-void releaseParent () {
- /* Do nothing */
-}
-
-void releaseWidget () {
- deregister ();
- if (display.tooltipTarget == this) display.tooltipTarget = null;
- eventTable = null;
- data = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener
- * @see #getListeners(int)
- * @see #notifyListeners
- */
-public void removeListener (int eventType, Listener handler) {
- checkWidget();
- if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, handler);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It should never be
- * referenced from application code.
- * </p>
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see #addListener
- */
-protected void removeListener (int eventType, SWTEventListener handler) {
- checkWidget();
- if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, handler);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the widget is disposed.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DisposeListener
- * @see #addDisposeListener
- */
-public void removeDisposeListener (DisposeListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Dispose, listener);
-}
-
-void scrollWheel (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- callSuper(id, sel, theEvent);
-}
-
-NSRange selectedRange (int /*long*/ id, int /*long*/ sel) {
- return new NSRange ();
-}
-
-int /*long*/ nextValidKeyView (int /*long*/ id, int /*long*/ sel) {
- return callSuperObject(id, sel);
-}
-
-int /*long*/ previousValidKeyView (int /*long*/ id, int /*long*/ sel) {
- return callSuperObject(id, sel);
-}
-
-void sendDoubleSelection() {
-}
-
-void sendEvent (Event event) {
- display.sendEvent (eventTable, event);
-}
-
-void sendEvent (int eventType) {
- sendEvent (eventType, null, true);
-}
-
-void sendEvent (int eventType, Event event) {
- sendEvent (eventType, event, true);
-}
-
-void sendEvent (int eventType, Event event, boolean send) {
- if (eventTable == null && !display.filters (eventType)) {
- return;
- }
- if (event == null) event = new Event ();
- event.type = eventType;
- event.display = display;
- event.widget = this;
- if (event.time == 0) {
- event.time = display.getLastEventTime ();
- }
- if (send) {
- sendEvent (event);
- } else {
- display.postEvent (event);
- }
-}
-
-boolean sendKeyEvent (NSEvent nsEvent, int type) {
- if ((state & SAFARI_EVENTS_FIX) != 0) return true;
- Event event = new Event ();
- if (!setKeyState (event, type, nsEvent)) return true;
- return sendKeyEvent (type, event);
-}
-
-boolean sendKeyEvent (int type, Event event) {
- sendEvent (type, event);
- // widget could be disposed at this point
-
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the key
- * events. If this happens, end the processing of
- * the key by returning false.
- */
- if (isDisposed ()) return false;
- return event.doit;
-}
-
-void sendHorizontalSelection () {
-}
-
-void sendCancelSelection () {
-}
-
-void sendSearchSelection () {
-}
-
-void sendSelection () {
-}
-
-void sendVerticalSelection () {
-}
-
-/**
- * Sets the application defined widget data associated
- * with the receiver to be the argument. The <em>widget
- * data</em> is a single, unnamed field that is stored
- * with every widget.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the widget data needs to be notified
- * when the widget is disposed of, it is the application's
- * responsibility to hook the Dispose event on the widget and
- * do so.
- * </p>
- *
- * @param data the widget data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
- * </ul>
- *
- * @see #getData()
- */
-public void setData (Object data) {
- checkWidget();
- if (SAFARI_EVENTS_FIX_KEY.equals (data)) {
- state |= SAFARI_EVENTS_FIX;
- return;
- }
- if ((state & KEYED_DATA) != 0) {
- ((Object []) this.data) [0] = data;
- } else {
- this.data = data;
- }
-}
-
-/**
- * Sets the application defined property of the receiver
- * with the specified name to the given value.
- * <p>
- * Applications may associate arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the widget is disposed
- * of, it is the application's responsibility to hook the
- * Dispose event on the widget and do so.
- * </p>
- *
- * @param key the name of the property
- * @param value the new value for the property
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getData(String)
- */
-public void setData (String key, Object value) {
- checkWidget();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (GLCONTEXT_KEY.equals (key)) {
- setOpenGLContext(value);
- return;
- }
- int index = 1;
- Object [] table = null;
- if ((state & KEYED_DATA) != 0) {
- table = (Object []) data;
- while (index < table.length) {
- if (key.equals (table [index])) break;
- index += 2;
- }
- }
- if (value != null) {
- if ((state & KEYED_DATA) != 0) {
- if (index == table.length) {
- Object [] newTable = new Object [table.length + 2];
- System.arraycopy (table, 0, newTable, 0, table.length);
- data = table = newTable;
- }
- } else {
- table = new Object [3];
- table [0] = data;
- data = table;
- state |= KEYED_DATA;
- }
- table [index] = key;
- table [index + 1] = value;
- } else {
- if ((state & KEYED_DATA) != 0) {
- if (index != table.length) {
- int length = table.length - 2;
- if (length == 1) {
- data = table [0];
- state &= ~KEYED_DATA;
- } else {
- Object [] newTable = new Object [length];
- System.arraycopy (table, 0, newTable, 0, index);
- System.arraycopy (table, index + 2, newTable, index, length - index);
- data = newTable;
- }
- }
- }
- }
-}
-
-void setOpenGLContext(Object value) {
-}
-
-void setFrameOrigin (int /*long*/ id, int /*long*/ sel, NSPoint point) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- OS.objc_msgSendSuper(super_struct, sel, point);
-}
-
-void setFrameSize (int /*long*/ id, int /*long*/ sel, NSSize size) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- OS.objc_msgSendSuper(super_struct, sel, size);
-}
-
-void setImage (int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
-}
-
-boolean setInputState (Event event, NSEvent nsEvent, int type) {
- if (nsEvent == null) return true;
- int /*long*/ modifierFlags = nsEvent.modifierFlags();
- if ((modifierFlags & OS.NSAlternateKeyMask) != 0) event.stateMask |= SWT.ALT;
- if ((modifierFlags & OS.NSShiftKeyMask) != 0) event.stateMask |= SWT.SHIFT;
- if ((modifierFlags & OS.NSControlKeyMask) != 0) event.stateMask |= SWT.CONTROL;
- if ((modifierFlags & OS.NSCommandKeyMask) != 0) event.stateMask |= SWT.COMMAND;
- //TODO multiple mouse buttons pressed
- switch ((int)/*64*/nsEvent.type()) {
- case OS.NSLeftMouseDragged:
- case OS.NSRightMouseDragged:
- case OS.NSOtherMouseDragged:
- switch ((int)/*64*/nsEvent.buttonNumber()) {
- case 0: event.stateMask |= SWT.BUTTON1; break;
- case 1: event.stateMask |= SWT.BUTTON3; break;
- case 2: event.stateMask |= SWT.BUTTON2; break;
- case 3: event.stateMask |= SWT.BUTTON4; break;
- case 4: event.stateMask |= SWT.BUTTON5; break;
- }
- break;
- case OS.NSScrollWheel:
- case OS.NSKeyDown:
- case OS.NSKeyUp:
- int state = OS.GetCurrentButtonState ();
- if ((state & 0x1) != 0) event.stateMask |= SWT.BUTTON1;
- if ((state & 0x2) != 0) event.stateMask |= SWT.BUTTON3;
- if ((state & 0x4) != 0) event.stateMask |= SWT.BUTTON2;
- if ((state & 0x8) != 0) event.stateMask |= SWT.BUTTON4;
- if ((state & 0x10) != 0) event.stateMask |= SWT.BUTTON5;
- break;
- }
- switch (type) {
- case SWT.MouseDown:
- case SWT.MouseDoubleClick:
- if (event.button == 1) event.stateMask &= ~SWT.BUTTON1;
- if (event.button == 2) event.stateMask &= ~SWT.BUTTON2;
- if (event.button == 3) event.stateMask &= ~SWT.BUTTON3;
- if (event.button == 4) event.stateMask &= ~SWT.BUTTON4;
- if (event.button == 5) event.stateMask &= ~SWT.BUTTON5;
- break;
- case SWT.MouseUp:
- if (event.button == 1) event.stateMask |= SWT.BUTTON1;
- if (event.button == 2) event.stateMask |= SWT.BUTTON2;
- if (event.button == 3) event.stateMask |= SWT.BUTTON3;
- if (event.button == 4) event.stateMask |= SWT.BUTTON4;
- if (event.button == 5) event.stateMask |= SWT.BUTTON5;
- break;
- case SWT.KeyDown:
- case SWT.Traverse:
- if (event.keyCode == SWT.ALT) event.stateMask &= ~SWT.ALT;
- if (event.keyCode == SWT.SHIFT) event.stateMask &= ~SWT.SHIFT;
- if (event.keyCode == SWT.CONTROL) event.stateMask &= ~SWT.CONTROL;
- if (event.keyCode == SWT.COMMAND) event.stateMask &= ~SWT.COMMAND;
- break;
- case SWT.KeyUp:
- if (event.keyCode == SWT.ALT) event.stateMask |= SWT.ALT;
- if (event.keyCode == SWT.SHIFT) event.stateMask |= SWT.SHIFT;
- if (event.keyCode == SWT.CONTROL) event.stateMask |= SWT.CONTROL;
- if (event.keyCode == SWT.COMMAND) event.stateMask |= SWT.COMMAND;
- break;
- }
- return true;
-}
-
-boolean setKeyState (Event event, int type, NSEvent nsEvent) {
- boolean isNull = false;
- int keyCode = nsEvent.keyCode ();
- event.keyCode = Display.translateKey (keyCode);
- switch (event.keyCode) {
- case SWT.LF: {
- /*
- * Feature in the Macintosh. When the numeric key pad
- * Enter key is pressed, it generates '\n'. This is the
- * correct platform behavior but is not portable. The
- * fix is to convert the '\n' into '\r'.
- */
- event.keyCode = SWT.KEYPAD_CR;
- event.character = '\r';
- break;
- }
- case SWT.BS: event.character = '\b'; break;
- case SWT.CR: event.character = '\r'; break;
- case SWT.DEL: event.character = 0x7F; break;
- case SWT.ESC: event.character = 0x1B; break;
- case SWT.TAB: event.character = '\t'; break;
- default:
- if (event.keyCode == 0 || (SWT.KEYPAD_MULTIPLY <= event.keyCode && event.keyCode <= SWT.KEYPAD_CR)) {
- NSString chars = nsEvent.characters ();
- if (chars.length() > 0) event.character = (char)chars.characterAtIndex (0);
- }
- if (event.keyCode == 0) {
- int /*long*/ uchrPtr = 0;
- int /*long*/ currentKbd = OS.TISCopyCurrentKeyboardInputSource();
- int /*long*/ uchrCFData = OS.TISGetInputSourceProperty(currentKbd, OS.kTISPropertyUnicodeKeyLayoutData());
-
- if (uchrCFData != 0) {
- // If the keyboard changed since the last keystroke clear the dead key state.
- if (uchrCFData != display.currentKeyboardUCHRdata) display.deadKeyState[0] = 0;
- uchrPtr = OS.CFDataGetBytePtr(uchrCFData);
-
- if (uchrPtr != 0 && OS.CFDataGetLength(uchrCFData) > 0) {
- int /*long*/ cgEvent = nsEvent.CGEvent();
- long keyboardType = OS.CGEventGetIntegerValueField(cgEvent, OS.kCGKeyboardEventKeyboardType);
-
- int maxStringLength = 256;
- char [] output = new char [maxStringLength];
- int [] actualStringLength = new int [1];
- OS.UCKeyTranslate (uchrPtr, (short)keyCode, (short)OS.kUCKeyActionDown, 0, (int)keyboardType, 0, display.deadKeyState, maxStringLength, actualStringLength, output);
- if (actualStringLength[0] < 1) {
- // part of a multi-key key
- event.keyCode = 0;
- } else {
- event.keyCode = output[0];
- }
- }
- } else {
- // KCHR keyboard layouts are no longer supported, so fall back to the basic but flawed
- // method of determining which key was pressed.
- NSString unmodifiedChars = nsEvent.charactersIgnoringModifiers ().lowercaseString();
- if (unmodifiedChars.length() > 0) event.keyCode = (char)unmodifiedChars.characterAtIndex(0);
- }
-
- if (currentKbd != 0) OS.CFRelease(currentKbd);
- }
- }
- if (event.keyCode == 0 && event.character == 0) {
- if (!isNull) return false;
- }
- setInputState (event, nsEvent, type);
- return true;
-}
-
-boolean setMarkedText_selectedRange (int /*long*/ id, int /*long*/ sel, int /*long*/ string, int /*long*/ range) {
- return true;
-}
-
-void setNeedsDisplay (int /*long*/ id, int /*long*/ sel, boolean flag) {
- if (flag && !isDrawing()) return;
- NSView view = new NSView(id);
- if (flag && display.isPainting.containsObject(view)) {
- NSMutableArray needsDisplay = display.needsDisplay;
- if (needsDisplay == null) {
- needsDisplay = (NSMutableArray)new NSMutableArray().alloc();
- display.needsDisplay = needsDisplay = needsDisplay.initWithCapacity(12);
- }
- needsDisplay.addObject(view);
- return;
- }
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- OS.objc_msgSendSuper(super_struct, sel, flag);
-}
-
-void setNeedsDisplayInRect (int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- if (!isDrawing()) return;
- NSRect rect = new NSRect();
- OS.memmove(rect, arg0, NSRect.sizeof);
- NSView view = new NSView(id);
- if (display.isPainting.containsObject(view)) {
- NSMutableArray needsDisplayInRect = display.needsDisplayInRect;
- if (needsDisplayInRect == null) {
- needsDisplayInRect = (NSMutableArray)new NSMutableArray().alloc();
- display.needsDisplayInRect = needsDisplayInRect = needsDisplayInRect.initWithCapacity(12);
- }
- needsDisplayInRect.addObject(view);
- needsDisplayInRect.addObject(NSValue.valueWithRect(rect));
- return;
- }
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- OS.objc_msgSendSuper(super_struct, sel, rect);
-}
-
-void setObjectValue(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
- callSuper(id, sel, arg0);
-}
-
-boolean setTabGroupFocus () {
- return setTabItemFocus ();
-}
-
-boolean setTabItemFocus () {
- return false;
-}
-
-boolean shouldChangeTextInRange_replacementString(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1) {
- return true;
-}
-
-void superKeyDown (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- callSuper (id, sel, theEvent);
-}
-
-void superKeyUp (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
- callSuper (id, sel, theEvent);
-}
-
-void tableViewColumnDidMove (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
-}
-
-void tableViewColumnDidResize (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
-}
-
-void tableViewSelectionDidChange (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
-}
-
-void tableView_didClickTableColumn(int /*long*/ id, int /*long*/ sel, int /*long*/ tableView, int /*long*/ tableColumn) {
-}
-
-int /*long*/ tableView_objectValueForTableColumn_row(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ aTableColumn, int /*long*/ rowIndex) {
- return 0;
-}
-
-void tableView_setObjectValue_forTableColumn_row(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ anObject, int /*long*/ aTableColumn, int /*long*/ rowIndex) {
-}
-
-boolean tableView_shouldEditTableColumn_row(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ aTableColumn, int /*long*/ rowIndex) {
- return true;
-}
-
-void tableView_willDisplayCell_forTableColumn_row(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ aCell, int /*long*/ aTableColumn, int /*long*/ rowIndex) {
-}
-
-void textViewDidChangeSelection(int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
-}
-
-void textDidChange(int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
- callSuper (id, sel, aNotification);
-}
-
-void textDidEndEditing(int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
- callSuper(id, sel, aNotification);
-}
-
-NSRange textView_willChangeSelectionFromCharacterRange_toCharacterRange(int /*long*/ id, int /*long*/ sel, int /*long*/ aTextView, int /*long*/ oldSelectedCharRange, int /*long*/ newSelectedCharRange) {
- return new NSRange();
-}
-
-NSRect titleRectForBounds (int /*long*/ id, int /*long*/ sel, NSRect cellFrame) {
- objc_super super_struct = new objc_super();
- super_struct.receiver = id;
- super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
- NSRect result = new NSRect();
- OS.objc_msgSendSuper_stret(result, super_struct, sel, cellFrame);
- return result;
-}
-
-String tooltipText () {
- return null;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- String string = "*Disposed*";
- if (!isDisposed ()) {
- string = "*Wrong Thread*";
- if (isValidThread ()) string = getNameText ();
- }
- return getName () + " {" + string + "}";
-}
-
-void resetCursorRects (int /*long*/ id, int /*long*/ sel) {
- callSuper (id, sel);
-}
-
-void updateTrackingAreas (int /*long*/ id, int /*long*/ sel) {
- callSuper (id, sel);
-}
-
-int /*long*/ validAttributesForMarkedText (int /*long*/ id, int /*long*/ sel) {
- return 0;
-}
-
-void tabView_didSelectTabViewItem(int /*long*/ id, int /*long*/ sel, int /*long*/ tabView, int /*long*/ tabViewItem) {
-}
-
-void tabView_willSelectTabViewItem(int /*long*/ id, int /*long*/ sel, int /*long*/ tabView, int /*long*/ tabViewItem) {
-}
-
-boolean tableView_writeRowsWithIndexes_toPasteboard(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2) {
- return false;
-}
-
-int /*long*/ view_stringForToolTip_point_userData (int /*long*/ id, int /*long*/ sel, int /*long*/ view, int /*long*/ tag, int /*long*/ point, int /*long*/ userData) {
- return 0;
-}
-
-void viewDidMoveToWindow(int /*long*/ id, int /*long*/ sel) {
-}
-
-void windowDidMove(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
-}
-
-void windowDidResize(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
-}
-
-void windowDidResignKey(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
-}
-
-void windowDidBecomeKey(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
-}
-
-void windowSendEvent(int /*long*/ id, int /*long*/ sel, int /*long*/ event) {
- callSuper(id, sel, event);
-}
-
-boolean windowShouldClose(int /*long*/ id, int /*long*/ sel, int /*long*/ window) {
- return false;
-}
-
-void windowWillClose(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
-}
-
-int /*long*/ nextState(int /*long*/ id, int /*long*/ sel) {
- return callSuperObject(id, sel);
-}
-
-void updateOpenGLContext(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/library/callback.c b/bundles/org.eclipse.swt/Eclipse SWT/common/library/callback.c
deleted file mode 100755
index 25e66053d2..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/library/callback.c
+++ /dev/null
@@ -1,753 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-/**
- * Callback implementation.
- */
-#include "callback.h"
-#include <string.h>
-
-/* define this to print out debug statements */
-/* #define DEBUG_CALL_PRINTS */
-
-/* --------------- callback globals ----------------- */
-
-static JavaVM *jvm = NULL;
-static CALLBACK_DATA callbackData[MAX_CALLBACKS];
-static int callbackEnabled = 1;
-static int callbackEntryCount = 0;
-static int initialized = 0;
-static jint JNI_VERSION = 0;
-
-#ifdef DEBUG_CALL_PRINTS
-static int counter = 0;
-#endif
-
-#ifdef ATOMIC
-#include <libkern/OSAtomic.h>
-#define ATOMIC_INC(value) OSAtomicIncrement32(&value);
-#define ATOMIC_DEC(value) OSAtomicDecrement32(&value);
-#else
-#define ATOMIC_INC(value) value++;
-#define ATOMIC_DEC(value) value--;
-#endif
-
-jintLong callback(int index, ...);
-
-#ifdef USE_ASSEMBLER
-
-#if !(defined (_WIN32) || defined (_WIN32_WCE))
-#include <sys/mman.h>
-#endif
-
-static unsigned char *callbackCode = NULL;
-#define CALLBACK_THUNK_SIZE 64
-
-#else
-
-/* --------------- callback functions --------------- */
-
-
-/* Function name from index and number of arguments */
-#define FN(index, args) fn##index##_##args
-
-/**
- * Functions templates
- *
- * NOTE: If the maximum number of arguments changes (MAX_ARGS), the number
- * of function templates has to change accordingly.
- */
-
-/* Function template with no arguments */
-#define FN_0(index) RETURN_TYPE FN(index, 0)() { return RETURN_CAST callback(index); }
-
-/* Function template with 1 argument */
-#define FN_1(index) RETURN_TYPE FN(index, 1)(jintLong p1) { return RETURN_CAST callback(index, p1); }
-
-/* Function template with 2 arguments */
-#define FN_2(index) RETURN_TYPE FN(index, 2)(jintLong p1, jintLong p2) { return RETURN_CAST callback(index, p1, p2); }
-
-/* Function template with 3 arguments */
-#define FN_3(index) RETURN_TYPE FN(index, 3)(jintLong p1, jintLong p2, jintLong p3) { return RETURN_CAST callback(index, p1, p2, p3); }
-
-/* Function template with 4 arguments */
-#define FN_4(index) RETURN_TYPE FN(index, 4)(jintLong p1, jintLong p2, jintLong p3, jintLong p4) { return RETURN_CAST callback(index, p1, p2, p3, p4); }
-
-/* Function template with 5 arguments */
-#define FN_5(index) RETURN_TYPE FN(index, 5)(jintLong p1, jintLong p2, jintLong p3, jintLong p4, jintLong p5) { return RETURN_CAST callback(index, p1, p2, p3, p4, p5); }
-
-/* Function template with 6 arguments */
-#define FN_6(index) RETURN_TYPE FN(index, 6)(jintLong p1, jintLong p2, jintLong p3, jintLong p4, jintLong p5, jintLong p6) { return RETURN_CAST callback(index, p1, p2, p3, p4, p5, p6); }
-
-/* Function template with 7 arguments */
-#define FN_7(index) RETURN_TYPE FN(index, 7)(jintLong p1, jintLong p2, jintLong p3, jintLong p4, jintLong p5, jintLong p6, jintLong p7) { return RETURN_CAST callback(index, p1, p2, p3, p4, p5, p6, p7); }
-
-/* Function template with 8 arguments */
-#define FN_8(index) RETURN_TYPE FN(index, 8)(jintLong p1, jintLong p2, jintLong p3, jintLong p4, jintLong p5, jintLong p6, jintLong p7, jintLong p8) { return RETURN_CAST callback(index, p1, p2, p3, p4, p5, p6, p7, p8); }
-
-/* Function template with 9 arguments */
-#define FN_9(index) RETURN_TYPE FN(index, 9)(jintLong p1, jintLong p2, jintLong p3, jintLong p4, jintLong p5, jintLong p6, jintLong p7, jintLong p8, jintLong p9) { return RETURN_CAST callback(index, p1, p2, p3, p4, p5, p6, p7, p8, p9); }
-
-/* Function template with 10 arguments */
-#define FN_10(index) RETURN_TYPE FN(index, 10) (jintLong p1, jintLong p2, jintLong p3, jintLong p4, jintLong p5, jintLong p6, jintLong p7, jintLong p8, jintLong p9, jintLong p10) { return RETURN_CAST callback(index, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); }
-
-/* Function template with 11 arguments */
-#define FN_11(index) RETURN_TYPE FN(index, 11) (jintLong p1, jintLong p2, jintLong p3, jintLong p4, jintLong p5, jintLong p6, jintLong p7, jintLong p8, jintLong p9, jintLong p10, jintLong p11) { return RETURN_CAST callback(index, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); }
-
-/* Function template with 12 arguments */
-#define FN_12(index) RETURN_TYPE FN(index, 12) (jintLong p1, jintLong p2, jintLong p3, jintLong p4, jintLong p5, jintLong p6, jintLong p7, jintLong p8, jintLong p9, jintLong p10, jintLong p11, jintLong p12) { return RETURN_CAST callback(index, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12); }
-
-/**
- * Define all functions with the specified number of arguments.
- *
- * NOTE: If the maximum number of callbacks changes (MAX_CALLBACKS),
- * this macro has to be updated.
- */
-#if MAX_CALLBACKS == 16
-#define FN_BLOCK(args) \
- FN_##args(0) \
- FN_##args(1) \
- FN_##args(2) \
- FN_##args(3) \
- FN_##args(4) \
- FN_##args(5) \
- FN_##args(6) \
- FN_##args(7) \
- FN_##args(8) \
- FN_##args(9) \
- FN_##args(10) \
- FN_##args(11) \
- FN_##args(12) \
- FN_##args(13) \
- FN_##args(14) \
- FN_##args(15)
-#elif MAX_CALLBACKS == 128
-#define FN_BLOCK(args) \
- FN_##args(0) \
- FN_##args(1) \
- FN_##args(2) \
- FN_##args(3) \
- FN_##args(4) \
- FN_##args(5) \
- FN_##args(6) \
- FN_##args(7) \
- FN_##args(8) \
- FN_##args(9) \
- FN_##args(10) \
- FN_##args(11) \
- FN_##args(12) \
- FN_##args(13) \
- FN_##args(14) \
- FN_##args(15) \
- FN_##args(16) \
- FN_##args(17) \
- FN_##args(18) \
- FN_##args(19) \
- FN_##args(20) \
- FN_##args(21) \
- FN_##args(22) \
- FN_##args(23) \
- FN_##args(24) \
- FN_##args(25) \
- FN_##args(26) \
- FN_##args(27) \
- FN_##args(28) \
- FN_##args(29) \
- FN_##args(30) \
- FN_##args(31) \
- FN_##args(32) \
- FN_##args(33) \
- FN_##args(34) \
- FN_##args(35) \
- FN_##args(36) \
- FN_##args(37) \
- FN_##args(38) \
- FN_##args(39) \
- FN_##args(40) \
- FN_##args(41) \
- FN_##args(42) \
- FN_##args(43) \
- FN_##args(44) \
- FN_##args(45) \
- FN_##args(46) \
- FN_##args(47) \
- FN_##args(48) \
- FN_##args(49) \
- FN_##args(50) \
- FN_##args(51) \
- FN_##args(52) \
- FN_##args(53) \
- FN_##args(54) \
- FN_##args(55) \
- FN_##args(56) \
- FN_##args(57) \
- FN_##args(58) \
- FN_##args(59) \
- FN_##args(60) \
- FN_##args(61) \
- FN_##args(62) \
- FN_##args(63) \
- FN_##args(64) \
- FN_##args(65) \
- FN_##args(66) \
- FN_##args(67) \
- FN_##args(68) \
- FN_##args(69) \
- FN_##args(70) \
- FN_##args(71) \
- FN_##args(72) \
- FN_##args(73) \
- FN_##args(74) \
- FN_##args(75) \
- FN_##args(76) \
- FN_##args(77) \
- FN_##args(78) \
- FN_##args(79) \
- FN_##args(80) \
- FN_##args(81) \
- FN_##args(82) \
- FN_##args(83) \
- FN_##args(84) \
- FN_##args(85) \
- FN_##args(86) \
- FN_##args(87) \
- FN_##args(88) \
- FN_##args(89) \
- FN_##args(90) \
- FN_##args(91) \
- FN_##args(92) \
- FN_##args(93) \
- FN_##args(94) \
- FN_##args(95) \
- FN_##args(96) \
- FN_##args(97) \
- FN_##args(98) \
- FN_##args(99) \
- FN_##args(100) \
- FN_##args(101) \
- FN_##args(102) \
- FN_##args(103) \
- FN_##args(104) \
- FN_##args(105) \
- FN_##args(106) \
- FN_##args(107) \
- FN_##args(108) \
- FN_##args(109) \
- FN_##args(110) \
- FN_##args(111) \
- FN_##args(112) \
- FN_##args(113) \
- FN_##args(114) \
- FN_##args(115) \
- FN_##args(116) \
- FN_##args(117) \
- FN_##args(118) \
- FN_##args(119) \
- FN_##args(120) \
- FN_##args(121) \
- FN_##args(122) \
- FN_##args(123) \
- FN_##args(124) \
- FN_##args(125) \
- FN_##args(126) \
- FN_##args(127)
-#else
-#error Invalid MAX_CALLBACKS
-#endif /* MAX_CALLBACKS == 16 */
-
-/**
- * Define all callback functions.
- *
- * NOTE: If the maximum number of arguments changes (MAX_ARGS), the following
- * has to change accordinglly.
- */
-FN_BLOCK(0)
-FN_BLOCK(1)
-FN_BLOCK(2)
-FN_BLOCK(3)
-FN_BLOCK(4)
-FN_BLOCK(5)
-FN_BLOCK(6)
-FN_BLOCK(7)
-FN_BLOCK(8)
-FN_BLOCK(9)
-FN_BLOCK(10)
-FN_BLOCK(11)
-FN_BLOCK(12)
-
-/**
- * Initialize the function pointers for the callback routines.
- *
- * NOTE: If MAX_ARGS or MAX_CALLBACKS changes, the following has to be updated.
- */
-#if MAX_CALLBACKS == 16
-#define FN_A_BLOCK(args) { \
- (jintLong)FN(0, args), \
- (jintLong)FN(1, args), \
- (jintLong)FN(2, args), \
- (jintLong)FN(3, args), \
- (jintLong)FN(4, args), \
- (jintLong)FN(5, args), \
- (jintLong)FN(6, args), \
- (jintLong)FN(7, args), \
- (jintLong)FN(8, args), \
- (jintLong)FN(9, args), \
- (jintLong)FN(10, args), \
- (jintLong)FN(11, args), \
- (jintLong)FN(12, args), \
- (jintLong)FN(13, args), \
- (jintLong)FN(14, args), \
- (jintLong)FN(15, args), \
-},
-#elif MAX_CALLBACKS == 128
-#define FN_A_BLOCK(args) { \
- (jintLong)FN(0, args), \
- (jintLong)FN(1, args), \
- (jintLong)FN(2, args), \
- (jintLong)FN(3, args), \
- (jintLong)FN(4, args), \
- (jintLong)FN(5, args), \
- (jintLong)FN(6, args), \
- (jintLong)FN(7, args), \
- (jintLong)FN(8, args), \
- (jintLong)FN(9, args), \
- (jintLong)FN(10, args), \
- (jintLong)FN(11, args), \
- (jintLong)FN(12, args), \
- (jintLong)FN(13, args), \
- (jintLong)FN(14, args), \
- (jintLong)FN(15, args), \
- (jintLong)FN(16, args), \
- (jintLong)FN(17, args), \
- (jintLong)FN(18, args), \
- (jintLong)FN(19, args), \
- (jintLong)FN(20, args), \
- (jintLong)FN(21, args), \
- (jintLong)FN(22, args), \
- (jintLong)FN(23, args), \
- (jintLong)FN(24, args), \
- (jintLong)FN(25, args), \
- (jintLong)FN(26, args), \
- (jintLong)FN(27, args), \
- (jintLong)FN(28, args), \
- (jintLong)FN(29, args), \
- (jintLong)FN(30, args), \
- (jintLong)FN(31, args), \
- (jintLong)FN(32, args), \
- (jintLong)FN(33, args), \
- (jintLong)FN(34, args), \
- (jintLong)FN(35, args), \
- (jintLong)FN(36, args), \
- (jintLong)FN(37, args), \
- (jintLong)FN(38, args), \
- (jintLong)FN(39, args), \
- (jintLong)FN(40, args), \
- (jintLong)FN(41, args), \
- (jintLong)FN(42, args), \
- (jintLong)FN(43, args), \
- (jintLong)FN(44, args), \
- (jintLong)FN(45, args), \
- (jintLong)FN(46, args), \
- (jintLong)FN(47, args), \
- (jintLong)FN(48, args), \
- (jintLong)FN(49, args), \
- (jintLong)FN(50, args), \
- (jintLong)FN(51, args), \
- (jintLong)FN(52, args), \
- (jintLong)FN(53, args), \
- (jintLong)FN(54, args), \
- (jintLong)FN(55, args), \
- (jintLong)FN(56, args), \
- (jintLong)FN(57, args), \
- (jintLong)FN(58, args), \
- (jintLong)FN(59, args), \
- (jintLong)FN(60, args), \
- (jintLong)FN(61, args), \
- (jintLong)FN(62, args), \
- (jintLong)FN(63, args), \
- (jintLong)FN(64, args), \
- (jintLong)FN(65, args), \
- (jintLong)FN(66, args), \
- (jintLong)FN(67, args), \
- (jintLong)FN(68, args), \
- (jintLong)FN(69, args), \
- (jintLong)FN(70, args), \
- (jintLong)FN(71, args), \
- (jintLong)FN(72, args), \
- (jintLong)FN(73, args), \
- (jintLong)FN(74, args), \
- (jintLong)FN(75, args), \
- (jintLong)FN(76, args), \
- (jintLong)FN(77, args), \
- (jintLong)FN(78, args), \
- (jintLong)FN(79, args), \
- (jintLong)FN(80, args), \
- (jintLong)FN(81, args), \
- (jintLong)FN(82, args), \
- (jintLong)FN(83, args), \
- (jintLong)FN(84, args), \
- (jintLong)FN(85, args), \
- (jintLong)FN(86, args), \
- (jintLong)FN(87, args), \
- (jintLong)FN(88, args), \
- (jintLong)FN(89, args), \
- (jintLong)FN(90, args), \
- (jintLong)FN(91, args), \
- (jintLong)FN(92, args), \
- (jintLong)FN(93, args), \
- (jintLong)FN(94, args), \
- (jintLong)FN(95, args), \
- (jintLong)FN(96, args), \
- (jintLong)FN(97, args), \
- (jintLong)FN(98, args), \
- (jintLong)FN(99, args), \
- (jintLong)FN(100, args), \
- (jintLong)FN(101, args), \
- (jintLong)FN(102, args), \
- (jintLong)FN(103, args), \
- (jintLong)FN(104, args), \
- (jintLong)FN(105, args), \
- (jintLong)FN(106, args), \
- (jintLong)FN(107, args), \
- (jintLong)FN(108, args), \
- (jintLong)FN(109, args), \
- (jintLong)FN(110, args), \
- (jintLong)FN(111, args), \
- (jintLong)FN(112, args), \
- (jintLong)FN(113, args), \
- (jintLong)FN(114, args), \
- (jintLong)FN(115, args), \
- (jintLong)FN(116, args), \
- (jintLong)FN(117, args), \
- (jintLong)FN(118, args), \
- (jintLong)FN(119, args), \
- (jintLong)FN(120, args), \
- (jintLong)FN(121, args), \
- (jintLong)FN(122, args), \
- (jintLong)FN(123, args), \
- (jintLong)FN(124, args), \
- (jintLong)FN(125, args), \
- (jintLong)FN(126, args), \
- (jintLong)FN(127, args), \
-},
-#else
-#error Invalid MAX_CALLBACKS
-#endif /* MAX_CALLBACKS == 16 */
-
-jintLong fnx_array[MAX_ARGS+1][MAX_CALLBACKS] = {
- FN_A_BLOCK(0)
- FN_A_BLOCK(1)
- FN_A_BLOCK(2)
- FN_A_BLOCK(3)
- FN_A_BLOCK(4)
- FN_A_BLOCK(5)
- FN_A_BLOCK(6)
- FN_A_BLOCK(7)
- FN_A_BLOCK(8)
- FN_A_BLOCK(9)
- FN_A_BLOCK(10)
- FN_A_BLOCK(11)
- FN_A_BLOCK(12)
-};
-
-#endif /* USE_ASSEMBLER */
-
-/* --------------- callback class calls --------------- */
-
-JNIEXPORT jintLong JNICALL Java_org_eclipse_swt_internal_Callback_bind
- (JNIEnv *env, jclass that, jobject callbackObject, jobject object, jstring method, jstring signature, jint argCount, jboolean isStatic, jboolean isArrayBased, jintLong errorResult)
-{
- int i;
- jmethodID mid = NULL;
- jclass javaClass = that;
- const char *methodString = NULL, *sigString = NULL;
- if (jvm == NULL) (*env)->GetJavaVM(env, &jvm);
- if (JNI_VERSION == 0) JNI_VERSION = (*env)->GetVersion(env);
- if (!initialized) {
- memset(&callbackData, 0, sizeof(callbackData));
- initialized = 1;
- }
- if (method) methodString = (const char *) (*env)->GetStringUTFChars(env, method, NULL);
- if (signature) sigString = (const char *) (*env)->GetStringUTFChars(env, signature, NULL);
- if (object && methodString && sigString) {
- if (isStatic) {
- mid = (*env)->GetStaticMethodID(env, object, methodString, sigString);
- } else {
- javaClass = (*env)->GetObjectClass(env, object);
- mid = (*env)->GetMethodID(env, javaClass, methodString, sigString);
- }
- }
- if (method && methodString) (*env)->ReleaseStringUTFChars(env, method, methodString);
- if (signature && sigString) (*env)->ReleaseStringUTFChars(env, signature, sigString);
- if (mid == 0) goto fail;
- for (i=0; i<MAX_CALLBACKS; i++) {
- if (!callbackData[i].callback) {
- if ((callbackData[i].callback = (*env)->NewGlobalRef(env, callbackObject)) == NULL) goto fail;
- if ((callbackData[i].object = (*env)->NewGlobalRef(env, object)) == NULL) goto fail;
- callbackData[i].isStatic = isStatic;
- callbackData[i].isArrayBased = isArrayBased;
- callbackData[i].argCount = argCount;
- callbackData[i].errorResult = errorResult;
- callbackData[i].methodID = mid;
-#ifndef USE_ASSEMBLER
- return (jintLong) fnx_array[argCount][i];
-#else
- {
- int j = 0, k;
- unsigned char* code;
-#ifdef __APPLE__
- int pad = 0;
-#endif
- if (callbackCode == NULL) {
-#if defined (_WIN32) || defined (_WIN32_WCE)
- callbackCode = VirtualAlloc(NULL, CALLBACK_THUNK_SIZE * MAX_CALLBACKS, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
- if (callbackCode == NULL) return 0;
-#else
- callbackCode = mmap(NULL, CALLBACK_THUNK_SIZE * MAX_CALLBACKS, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
- if (callbackCode == MAP_FAILED) return 0;
-#endif
- }
- code = (unsigned char *)(callbackCode + (i * CALLBACK_THUNK_SIZE));
-
- //PUSH EBP - 1 byte
- code[j++] = 0x55;
-
- //MOV EBP,ESP - 2 bytes
- code[j++] = 0x8b;
- code[j++] = 0xec;
-
-#ifdef __APPLE__
- /* darwin calling conventions require that the stack be aligned on a 16-byte boundary. */
- k = (argCount+3)*sizeof(jintLong);
- pad = ((k + 15) & ~15) - k;
- if (pad > 0) {
- //SUB ESP,pad - 3 bytes
- code[j++] = 0x83;
- code[j++] = 0xec;
- code[j++] = pad;
- }
-#endif
-
- // 3*argCount bytes
- for (k=(argCount + 1) * sizeof(jintLong); k >= sizeof(jintLong)*2; k -= sizeof(jintLong)) {
- //PUSH SS:[EBP+k]
- code[j++] = 0xff;
- code[j++] = 0x75;
- code[j++] = k;
- }
-
- if (i > 127) {
- //PUSH i - 5 bytes
- code[j++] = 0x68;
- code[j++] = ((i >> 0) & 0xFF);
- code[j++] = ((i >> 8) & 0xFF);
- code[j++] = ((i >> 16) & 0xFF);
- code[j++] = ((i >> 24) & 0xFF);
- } else {
- //PUSH i - 2 bytes
- code[j++] = 0x6a;
- code[j++] = i;
- }
-
- //MOV EAX callback - 1 + sizeof(jintLong) bytes
- code[j++] = 0xb8;
- ((jintLong *)&code[j])[0] = (jintLong)&callback;
- j += sizeof(jintLong);
-
- //CALL EAX - 2 bytes
- code[j++] = 0xff;
- code[j++] = 0xd0;
-
- //ADD ESP,(argCount + 1) * sizeof(jintLong) - 3 bytes
- code[j++] = 0x83;
- code[j++] = 0xc4;
-#ifdef __APPLE__
- code[j++] = (unsigned char)(pad + ((argCount + 1) * sizeof(jintLong)));
-#else
- code[j++] = (unsigned char)((argCount + 1) * sizeof(jintLong));
-#endif
-
- //POP EBP - 1 byte
- code[j++] = 0x5d;
-
-#if defined (_WIN32) || defined (_WIN32_WCE)
- //RETN argCount * sizeof(jintLong) - 3 bytes
- code[j++] = 0xc2;
- code[j++] = (unsigned char)(argCount * sizeof(jintLong));
- code[j++] = 0x00;
-#else
- //RETN - 1 byte
- code[j++] = 0xc3;
-#endif
-
- if (j > CALLBACK_THUNK_SIZE) {
- jclass errorClass = (*env)->FindClass(env, "java/lang/Error");
- (*env)->ThrowNew(env, errorClass, "Callback thunk overflow");
- }
-
- return (jintLong)code;
- }
-#endif /* USE_ASSEMBLER */
- }
- }
-fail:
- return 0;
-}
-
-JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_Callback_unbind
- (JNIEnv *env, jclass that, jobject callback)
-{
- int i;
- for (i=0; i<MAX_CALLBACKS; i++) {
- if (callbackData[i].callback != NULL && (*env)->IsSameObject(env, callback, callbackData[i].callback)) {
- if (callbackData[i].callback != NULL) (*env)->DeleteGlobalRef(env, callbackData[i].callback);
- if (callbackData[i].object != NULL) (*env)->DeleteGlobalRef(env, callbackData[i].object);
- memset(&callbackData[i], 0, sizeof(CALLBACK_DATA));
- }
- }
-}
-
-JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_Callback_getEnabled
- (JNIEnv *env, jclass that)
-{
- return (jboolean)callbackEnabled;
-}
-
-JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_Callback_getEntryCount
- (JNIEnv *env, jclass that)
-{
- return (jint)callbackEntryCount;
-}
-
-JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_Callback_setEnabled
- (JNIEnv *env, jclass that, jboolean enable)
-{
- callbackEnabled = enable;
-}
-
-JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_Callback_reset
- (JNIEnv *env, jclass that)
-{
- memset((void *)&callbackData, 0, sizeof(callbackData));
-}
-
-jintLong callback(int index, ...)
-{
- if (!callbackEnabled) return 0;
-
- {
- JNIEnv *env = NULL;
- jmethodID mid = callbackData[index].methodID;
- jobject object = callbackData[index].object;
- jboolean isStatic = callbackData[index].isStatic;
- jboolean isArrayBased = callbackData[index].isArrayBased;
- jint argCount = callbackData[index].argCount;
- jintLong result = callbackData[index].errorResult;
- int detach = 0;
- va_list vl;
-
-#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "* callback starting %d\n", counter++);
-#endif
-
-#ifdef JNI_VERSION_1_2
- if (IS_JNI_1_2) {
- (*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2);
- }
-#endif
-
-#ifdef JNI_VERSION_1_4
- if (env == NULL) {
- if (JNI_VERSION == JNI_VERSION_1_4) {
- (*jvm)->AttachCurrentThreadAsDaemon(jvm, (void **)&env, NULL);
- }
- }
-#endif
-
- if (env == NULL) {
- (*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
- if (IS_JNI_1_2) detach = 1;
- }
-
- /* If the current thread is not attached to the VM, it is not possible to call into the VM */
- if (env == NULL) {
-#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "* could not get env\n");
-#endif
- goto noEnv;
- }
-
- /* If an exception has occurred in previous callbacks do not call into the VM. */
- if ((*env)->ExceptionOccurred(env)) {
- goto done;
- }
-
- /* Call into the VM. */
- ATOMIC_INC(callbackEntryCount);
- va_start(vl, index);
- if (isArrayBased) {
- int i;
- jintLongArray argsArray = (*env)->NewIntLongArray(env, argCount);
- if (argsArray != NULL) {
- jintLong *elements = (*env)->GetIntLongArrayElements(env, argsArray, NULL);
- if (elements != NULL) {
- for (i=0; i<argCount; i++) {
- elements[i] = va_arg(vl, jintLong);
- }
- (*env)->ReleaseIntLongArrayElements(env, argsArray, elements, 0);
- if (isStatic) {
- result = (*env)->CallStaticIntLongMethod(env, object, mid, argsArray);
- } else {
- result = (*env)->CallIntLongMethod(env, object, mid, argsArray);
- }
- }
- /*
- * This function may be called many times before returning to Java,
- * explicitly delete local references to avoid GP's in certain VMs.
- */
- (*env)->DeleteLocalRef(env, argsArray);
- }
- } else {
- if (isStatic) {
- result = (*env)->CallStaticIntLongMethodV(env, object, mid, vl);
- } else {
- result = (*env)->CallIntLongMethodV(env, object, mid, vl);
- }
- }
- va_end(vl);
- ATOMIC_DEC(callbackEntryCount);
-
-done:
- /* If an exception has occurred in Java, return the error result. */
- if ((*env)->ExceptionOccurred(env)) {
-#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "* java exception occurred\n");
- (*env)->ExceptionDescribe(env);
-#endif
- result = callbackData[index].errorResult;
- }
-
- if (detach) {
- (*jvm)->DetachCurrentThread(jvm);
- env = NULL;
- }
-
-noEnv:
-
-#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "* callback exiting %d\n", --counter);
-#endif
-
- return result;
- }
-}
-
-/* ------------- callback class calls end --------------- */
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/library/callback.h b/bundles/org.eclipse.swt/Eclipse SWT/common/library/callback.h
deleted file mode 100755
index 040ac69833..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/library/callback.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-/**
- * Callback implementation.
- */
-#ifndef INC_callback_H
-#define INC_callback_H
-
-#include "swt.h"
-
-#if defined (_WIN32) || defined (_WIN32_WCE)
-#include "windows.h"
-#define RETURN_TYPE LRESULT CALLBACK
-#define RETURN_CAST (LRESULT)
-#endif
-
-#ifndef RETURN_TYPE
-#define RETURN_TYPE jintLong
-#endif
-
-#ifndef RETURN_CAST
-#define RETURN_CAST
-#endif
-
-/*
-* Note that only x86 assembler is supported
-*/
-#if !(defined(__i386__) || defined(_M_IX86) || defined(_X86_))
-#undef USE_ASSEMBLER
-#endif
-
-#ifdef REDUCED_CALLBACKS
-#define MAX_CALLBACKS 16
-#else
-#ifdef USE_ASSEMBLER
-#define MAX_CALLBACKS 256
-#else
-#define MAX_CALLBACKS 128
-#endif
-#endif /* REDUCED_CALLBACKS */
-
-#define MAX_ARGS 12
-
-typedef struct CALLBACK_DATA {
- jobject callback;
- jmethodID methodID;
- jobject object;
- jboolean isStatic;
- jboolean isArrayBased;
- jint argCount;
- jintLong errorResult;
-} CALLBACK_DATA;
-
-#endif /* ifndef INC_callback_H */
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/library/make_common.mak b/bundles/org.eclipse.swt/Eclipse SWT/common/library/make_common.mak
deleted file mode 100644
index 11f26bf8c3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/library/make_common.mak
+++ /dev/null
@@ -1,14 +0,0 @@
-#*******************************************************************************
-# Copyright (c) 2000, 2009 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
-# http://www.eclipse.org/legal/epl-v10.html
-#
-# Contributors:
-# IBM Corporation - initial API and implementation
-#*******************************************************************************
-
-maj_ver=3
-min_ver=601
-comma_ver=3,6,0,1
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.c b/bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.c
deleted file mode 100644
index a34dc72e5d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-#include "swt.h"
-
-int IS_JNI_1_2 = 0;
-
-#ifdef JNI_VERSION_1_2
-JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
- IS_JNI_1_2 = 1;
- return JNI_VERSION_1_2;
-}
-#endif
-
-void throwOutOfMemory(JNIEnv *env) {
- jclass clazz = (*env)->FindClass(env, "java/lang/OutOfMemoryError");
- if (clazz != NULL) {
- (*env)->ThrowNew(env, clazz, "");
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.h b/bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.h
deleted file mode 100644
index b955471c70..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.h
+++ /dev/null
@@ -1,150 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-/**
- * swt.h
- *
- * This file contains the global macro declarations for the
- * SWT library.
- *
- */
-
-#ifndef INC_swt_H
-#define INC_swt_H
-
-#include "jni.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern int IS_JNI_1_2;
-
-#ifndef JNI64
-#if __x86_64__
-#define JNI64
-#endif
-#endif
-
-/* 64 bit support */
-#ifndef JNI64
-
-/* int/long defines */
-#define GetIntLongField GetIntField
-#define SetIntLongField SetIntField
-#define GetIntLongArrayElements GetIntArrayElements
-#define ReleaseIntLongArrayElements ReleaseIntArrayElements
-#define GetIntLongArrayRegion GetIntArrayRegion
-#define SetIntLongArrayRegion SetIntArrayRegion
-#define NewIntLongArray NewIntArray
-#define CallStaticIntLongMethod CallStaticIntMethod
-#define CallIntLongMethod CallIntMethod
-#define CallStaticIntLongMethodV CallStaticIntMethodV
-#define CallIntLongMethodV CallIntMethodV
-#define jintLongArray jintArray
-#define jintLong jint
-#define I_J "I"
-#define I_JArray "[I"
-
-/* float/double defines */
-#define GetFloatDoubleField GetFloatField
-#define SetFloatDoubleField SetFloatField
-#define GetFloatDoubleArrayElements GetFloatArrayElements
-#define ReleaseFloatDoubleArrayElements ReleaseFloatArrayElements
-#define GetFloatDoubleArrayRegion GetFloatArrayRegion
-#define jfloatDoubleArray jfloatArray
-#define jfloatDouble jfloat
-#define F_D "F"
-#define F_DArray "[F"
-
-#else
-
-/* int/long defines */
-#define GetIntLongField GetLongField
-#define SetIntLongField SetLongField
-#define GetIntLongArrayElements GetLongArrayElements
-#define ReleaseIntLongArrayElements ReleaseLongArrayElements
-#define GetIntLongArrayRegion GetLongArrayRegion
-#define SetIntLongArrayRegion SetLongArrayRegion
-#define NewIntLongArray NewLongArray
-#define CallStaticIntLongMethod CallStaticLongMethod
-#define CallIntLongMethod CallLongMethod
-#define CallStaticIntLongMethodV CallStaticLongMethodV
-#define CallIntLongMethodV CallLongMethodV
-#define jintLongArray jlongArray
-#define jintLong jlong
-#define I_J "J"
-#define I_JArray "[J"
-
-/* float/double defines */
-#define GetFloatDoubleField GetDoubleField
-#define SetFloatDoubleField SetDoubleField
-#define GetFloatDoubleArrayElements GetDoubleArrayElements
-#define ReleaseFloatDoubleArrayElements ReleaseDoubleArrayElements
-#define GetFloatDoubleArrayRegion GetDoubleArrayRegion
-#define jfloatDoubleArray jdoubleArray
-#define jfloatDouble jdouble
-#define F_D "D"
-#define F_DArray "[D"
-
-#endif
-
-#ifdef __APPLE__
-#define CALLING_CONVENTION
-#define LOAD_FUNCTION(var, name) \
- static int initialized = 0; \
- static void *var = NULL; \
- if (!initialized) { \
- CFBundleRef bundle = CFBundleGetBundleWithIdentifier(CFSTR(name##_LIB)); \
- if (bundle) var = CFBundleGetFunctionPointerForName(bundle, CFSTR(#name)); \
- initialized = 1; \
- }
-#elif defined (_WIN32) || defined (_WIN32_WCE)
-#define CALLING_CONVENTION CALLBACK
-#define LOAD_FUNCTION(var, name) \
- static int initialized = 0; \
- static FARPROC var = NULL; \
- if (!initialized) { \
- HMODULE hm = LoadLibrary(name##_LIB); \
- if (hm) var = GetProcAddress(hm, #name); \
- initialized = 1; \
- }
-#else
-#define CALLING_CONVENTION
-#define LOAD_FUNCTION(var, name) \
- static int initialized = 0; \
- static void *var = NULL; \
- if (!initialized) { \
- void* handle = dlopen(name##_LIB, RTLD_LAZY); \
- if (handle) var = dlsym(handle, #name); \
- initialized = 1; \
- }
-#endif
-
-void throwOutOfMemory(JNIEnv *env);
-
-#define CHECK_NULL_VOID(ptr) \
- if ((ptr) == NULL) { \
- throwOutOfMemory(env); \
- return; \
- }
-
-#define CHECK_NULL(ptr) \
- if ((ptr) == NULL) { \
- throwOutOfMemory(env); \
- return 0; \
- }
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* ifndef INC_swt_H */
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java
deleted file mode 100755
index 6d5b5d9d39..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java
+++ /dev/null
@@ -1,3952 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt;
-
-
-import org.eclipse.swt.internal.*;
-
-/**
- * This class provides access to a small number of SWT system-wide
- * methods, and in addition defines the public constants provided
- * by SWT.
- * <p>
- * By defining constants like UP and DOWN in a single class, SWT
- * can share common names and concepts at the same time minimizing
- * the number of classes, names and constants for the application
- * programmer.
- * </p><p>
- * Note that some of the constants provided by this class represent
- * optional, appearance related aspects of widgets which are available
- * either only on some window systems, or for a differing set of
- * widgets on each window system. These constants are marked
- * as <em>HINT</em>s. The set of widgets which support a particular
- * <em>HINT</em> may change from release to release, although we typically
- * will not withdraw support for a <em>HINT</em> once it is made available.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-/* NOTE:
- * Good javadoc coding style is to put the values of static final
- * constants in the comments. This reinforces the fact that
- * consumers are allowed to rely on the value (and they must
- * since the values are compiled inline in their code). We
- * can <em>not</em> change the values of these constants between
- * releases.
- */
-public class SWT {
-
- /* Widget Event Constants */
-
- /**
- * The null event type (value is 0).
- *
- * @since 3.0
- */
- public static final int None = 0;
-
- /**
- * The key down event type (value is 1).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Control#addKeyListener
- * @see org.eclipse.swt.widgets.Tracker#addKeyListener
- * @see org.eclipse.swt.events.KeyListener#keyPressed
- * @see org.eclipse.swt.events.KeyEvent
- */
- public static final int KeyDown = 1;
-
- /**
- * The key up event type (value is 2).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Control#addKeyListener
- * @see org.eclipse.swt.widgets.Tracker#addKeyListener
- * @see org.eclipse.swt.events.KeyListener#keyReleased
- * @see org.eclipse.swt.events.KeyEvent
- */
- public static final int KeyUp = 2;
-
- /**
- * The mouse down event type (value is 3).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Control#addMouseListener
- * @see org.eclipse.swt.events.MouseListener#mouseDown
- * @see org.eclipse.swt.events.MouseEvent
- */
- public static final int MouseDown = 3;
-
- /**
- * The mouse up event type (value is 4).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Control#addMouseListener
- * @see org.eclipse.swt.events.MouseListener#mouseUp
- * @see org.eclipse.swt.events.MouseEvent
- */
- public static final int MouseUp = 4;
-
- /**
- * The mouse move event type (value is 5).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Control#addMouseMoveListener
- * @see org.eclipse.swt.events.MouseMoveListener#mouseMove
- * @see org.eclipse.swt.events.MouseEvent
- */
- public static final int MouseMove = 5;
-
- /**
- * The mouse enter event type (value is 6).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Control#addMouseTrackListener
- * @see org.eclipse.swt.events.MouseTrackListener#mouseEnter
- * @see org.eclipse.swt.events.MouseEvent
- */
- public static final int MouseEnter = 6;
-
- /**
- * The mouse exit event type (value is 7).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Control#addMouseTrackListener
- * @see org.eclipse.swt.events.MouseTrackListener#mouseExit
- * @see org.eclipse.swt.events.MouseEvent
- */
- public static final int MouseExit = 7;
-
- /**
- * The mouse double click event type (value is 8).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Control#addMouseListener
- * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick
- * @see org.eclipse.swt.events.MouseEvent
- */
- public static final int MouseDoubleClick = 8;
-
- /**
- * The paint event type (value is 9).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Control#addPaintListener
- * @see org.eclipse.swt.events.PaintListener#paintControl
- * @see org.eclipse.swt.events.PaintEvent
- */
- public static final int Paint = 9;
-
- /**
- * The move event type (value is 10).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Control#addControlListener
- * @see org.eclipse.swt.widgets.TableColumn#addControlListener
- * @see org.eclipse.swt.widgets.Tracker#addControlListener
- * @see org.eclipse.swt.widgets.TreeColumn#addControlListener
- * @see org.eclipse.swt.events.ControlListener#controlMoved
- * @see org.eclipse.swt.events.ControlEvent
- */
- public static final int Move = 10;
-
- /**
- * The resize event type (value is 11).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Control#addControlListener
- * @see org.eclipse.swt.widgets.TableColumn#addControlListener
- * @see org.eclipse.swt.widgets.Tracker#addControlListener
- * @see org.eclipse.swt.widgets.TreeColumn#addControlListener
- * @see org.eclipse.swt.events.ControlListener#controlResized
- * @see org.eclipse.swt.events.ControlEvent
- */
- public static final int Resize = 11;
-
- /**
- * The dispose event type (value is 12).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Widget#addDisposeListener
- * @see org.eclipse.swt.events.DisposeListener#widgetDisposed
- * @see org.eclipse.swt.events.DisposeEvent
- */
- public static final int Dispose = 12;
-
- /**
- * The selection event type (value is 13).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Button#addSelectionListener
- * @see org.eclipse.swt.widgets.Combo#addSelectionListener
- * @see org.eclipse.swt.widgets.CoolItem#addSelectionListener
- * @see org.eclipse.swt.widgets.Link#addSelectionListener
- * @see org.eclipse.swt.widgets.List#addSelectionListener
- * @see org.eclipse.swt.widgets.MenuItem#addSelectionListener
- * @see org.eclipse.swt.widgets.Sash#addSelectionListener
- * @see org.eclipse.swt.widgets.Scale#addSelectionListener
- * @see org.eclipse.swt.widgets.ScrollBar#addSelectionListener
- * @see org.eclipse.swt.widgets.Slider#addSelectionListener
- * @see org.eclipse.swt.widgets.TabFolder#addSelectionListener
- * @see org.eclipse.swt.widgets.Table#addSelectionListener
- * @see org.eclipse.swt.widgets.TableColumn#addSelectionListener
- * @see org.eclipse.swt.widgets.ToolItem#addSelectionListener
- * @see org.eclipse.swt.widgets.TrayItem#addSelectionListener
- * @see org.eclipse.swt.widgets.Tree#addSelectionListener
- * @see org.eclipse.swt.widgets.TreeColumn#addSelectionListener
- * @see org.eclipse.swt.events.SelectionListener#widgetSelected
- * @see org.eclipse.swt.events.SelectionEvent
- */
- public static final int Selection = 13;
-
- /**
- * The default selection event type (value is 14).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Combo#addSelectionListener
- * @see org.eclipse.swt.widgets.List#addSelectionListener
- * @see org.eclipse.swt.widgets.Spinner#addSelectionListener
- * @see org.eclipse.swt.widgets.Table#addSelectionListener
- * @see org.eclipse.swt.widgets.Text#addSelectionListener
- * @see org.eclipse.swt.widgets.TrayItem#addSelectionListener
- * @see org.eclipse.swt.widgets.Tree#addSelectionListener
- * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected
- * @see org.eclipse.swt.events.SelectionEvent
- */
- public static final int DefaultSelection = 14;
-
- /**
- * The focus in event type (value is 15).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Control#addFocusListener
- * @see org.eclipse.swt.events.FocusListener#focusGained
- * @see org.eclipse.swt.events.FocusEvent
- */
- public static final int FocusIn = 15;
-
- /**
- * The focus out event type (value is 16).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Control#addFocusListener
- * @see org.eclipse.swt.events.FocusListener#focusLost
- * @see org.eclipse.swt.events.FocusEvent
- */
- public static final int FocusOut = 16;
-
- /**
- * The expand event type (value is 17).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Tree#addTreeListener
- * @see org.eclipse.swt.events.TreeListener#treeExpanded
- * @see org.eclipse.swt.events.TreeEvent
- */
- public static final int Expand = 17;
-
- /**
- * The collapse event type (value is 18).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Tree#addTreeListener
- * @see org.eclipse.swt.events.TreeListener#treeCollapsed
- * @see org.eclipse.swt.events.TreeEvent
- */
- public static final int Collapse = 18;
-
- /**
- * The iconify event type (value is 19).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Shell#addShellListener
- * @see org.eclipse.swt.events.ShellListener#shellIconified
- * @see org.eclipse.swt.events.ShellEvent
- */
- public static final int Iconify = 19;
-
- /**
- * The de-iconify event type (value is 20).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Shell#addShellListener
- * @see org.eclipse.swt.events.ShellListener#shellDeiconified
- * @see org.eclipse.swt.events.ShellEvent
- */
- public static final int Deiconify = 20;
-
- /**
- * The close event type (value is 21).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Shell#addShellListener
- * @see org.eclipse.swt.events.ShellListener#shellClosed
- * @see org.eclipse.swt.events.ShellEvent
- */
- public static final int Close = 21;
-
- /**
- * The show event type (value is 22).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Menu#addMenuListener
- * @see org.eclipse.swt.events.MenuListener#menuShown
- * @see org.eclipse.swt.events.MenuEvent
- */
- public static final int Show = 22;
-
- /**
- * The hide event type (value is 23).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Menu#addMenuListener
- * @see org.eclipse.swt.events.MenuListener#menuHidden
- * @see org.eclipse.swt.events.MenuEvent
- */
- public static final int Hide = 23;
-
- /**
- * The modify event type (value is 24).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Combo#addModifyListener
- * @see org.eclipse.swt.widgets.Spinner#addModifyListener
- * @see org.eclipse.swt.widgets.Text#addModifyListener
- * @see org.eclipse.swt.events.ModifyListener#modifyText
- * @see org.eclipse.swt.events.ModifyEvent
- */
- public static final int Modify = 24;
-
- /**
- * The verify event type (value is 25).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.custom.CCombo#addVerifyListener
- * @see org.eclipse.swt.widgets.Combo#addVerifyListener
- * @see org.eclipse.swt.custom.StyledText#addVerifyListener
- * @see org.eclipse.swt.widgets.Text#addVerifyListener
- * @see org.eclipse.swt.events.VerifyListener#verifyText
- * @see org.eclipse.swt.events.VerifyEvent
- */
- public static final int Verify = 25;
-
- /**
- * The activate event type (value is 26).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Shell#addShellListener
- * @see org.eclipse.swt.events.ShellListener#shellActivated
- * @see org.eclipse.swt.events.ShellEvent
- */
- public static final int Activate = 26;
-
- /**
- * The deactivate event type (value is 27).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Shell#addShellListener
- * @see org.eclipse.swt.events.ShellListener#shellDeactivated
- * @see org.eclipse.swt.events.ShellEvent
- */
- public static final int Deactivate = 27;
-
- /**
- * The help event type (value is 28).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Control#addHelpListener
- * @see org.eclipse.swt.widgets.Menu#addHelpListener
- * @see org.eclipse.swt.widgets.MenuItem#addHelpListener
- * @see org.eclipse.swt.events.HelpListener#helpRequested
- * @see org.eclipse.swt.events.HelpEvent
- */
- public static final int Help = 28;
-
- /**
- * The drag detect event type (value is 29).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Control#addDragDetectListener
- * @see org.eclipse.swt.events.DragDetectListener#dragDetected
- * @see org.eclipse.swt.events.DragDetectEvent
- * @see org.eclipse.swt.dnd.DragSource
- */
- public static final int DragDetect = 29;
-
- /**
- * The arm event type (value is 30).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.MenuItem#addArmListener
- * @see org.eclipse.swt.events.ArmListener#widgetArmed
- * @see org.eclipse.swt.events.ArmEvent
- */
- public static final int Arm = 30;
-
- /**
- * The traverse event type (value is 31).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Control#addTraverseListener
- * @see org.eclipse.swt.events.TraverseListener#keyTraversed
- * @see org.eclipse.swt.events.TraverseEvent
- */
- public static final int Traverse = 31;
-
- /**
- * The mouse hover event type (value is 32).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Control#addMouseTrackListener
- * @see org.eclipse.swt.events.MouseTrackListener#mouseHover
- * @see org.eclipse.swt.events.MouseEvent
- */
- public static final int MouseHover = 32;
-
- /**
- * The hardware key down event type (value is 33).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- */
- public static final int HardKeyDown = 33;
-
- /**
- * The hardware key up event type (value is 34).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- */
- public static final int HardKeyUp = 34;
-
- /**
- * The menu detect event type (value is 35).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @since 3.0
- */
- public static final int MenuDetect = 35;
-
- /**
- * The set data event type (value is 36).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @see org.eclipse.swt.widgets.Table
- * @see org.eclipse.swt.widgets.Tree
- *
- * @since 3.0
- */
- public static final int SetData = 36;
-
- /**
- * The mouse wheel event type (value is 37).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @since 3.1
- */
- public static final int MouseWheel = 37;
-
- /**
- * The settings changed event type (value is 39).
- * <p>
- * The settings changed event is sent when an operating system
- * property, such as a system font or color, has been changed.
- * The event occurs after the property has been changed, but
- * before any widget is redrawn. Applications that cache operating
- * system properties can use this event to update their caches.
- * A specific property change can be detected by querying the
- * new value of a property and comparing it with the equivalent
- * cached value. The operating system automatically redraws and
- * lays out all widgets after this event is sent.
- * </p>
- *
- * @see org.eclipse.swt.widgets.Display#addListener
- * @see org.eclipse.swt.widgets.Event
- *
- * @since 3.2
- */
- public static final int Settings = 39;
-
- /**
- * The erase item event type (value is 40).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @since 3.2
- */
- public static final int EraseItem = 40;
-
- /**
- * The measure item event type (value is 41).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @since 3.2
- */
- public static final int MeasureItem = 41;
-
- /**
- * The paint item event type (value is 42).
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @since 3.2
- */
- public static final int PaintItem = 42;
-
- /**
- * The IME composition event type (value is 43).
- * <p>
- * The IME composition event is sent to allow
- * custom text editors to implement in-line
- * editing of international text.
- * </p>
- *
- * The detail field indicates the action to be taken:
- * <p><ul>
- * <li>{@link SWT#COMPOSITION_CHANGED}</li>
- * <li>{@link SWT#COMPOSITION_OFFSET}</li>
- * <li>{@link SWT#COMPOSITION_SELECTION}</li>
- * </ul></p>
- *
- * @see org.eclipse.swt.widgets.Widget#addListener
- * @see org.eclipse.swt.widgets.Display#addFilter
- * @see org.eclipse.swt.widgets.Event
- *
- * @since 3.4
- */
- public static final int ImeComposition = 43;
-
- /* Event Details */
-
- /**
- * The IME composition event detail that indicates
- * a change in the IME composition. The text field
- * of the event is the new composition text.
- * The start and end indicate the offsets where the
- * composition text should be inserted.
- * The styles and ranges are stored in the IME
- * object (value is 1).
- *
- * @see SWT#ImeComposition
- *
- * @since 3.4
- */
- public static final int COMPOSITION_CHANGED = 1;
-
- /**
- * The IME composition event detail that indicates
- * that the IME needs the offset for a given location.
- * The x and y fields of the event are used by the
- * application to determine the offset.
- *
- * The index field of the event should be set to the
- * text offset at that location. The count field should
- * be set to indicate whether the location is closer to
- * the leading edge (0) or the trailing edge (1) (value is 2).
- *
- * @see SWT#ImeComposition
- * @see org.eclipse.swt.graphics.TextLayout#getOffset(int, int, int[])
- *
- * @since 3.4
- */
- public static final int COMPOSITION_OFFSET = 2;
-
- /**
- * The IME composition event detail that indicates
- * that IME needs the selected text and its start
- * and end offsets (value is 3).
- *
- * @see SWT#ImeComposition
- *
- * @since 3.4
- */
- public static final int COMPOSITION_SELECTION = 3;
-
- /**
- * Indicates that a user-interface component is being dragged,
- * for example dragging the thumb of a scroll bar (value is 1).
- */
- public static final int DRAG = 1;
-
- /**
- * Event detail field that indicates a user-interface component
- * state is selected (value is 1&lt;&lt;1).
- *
- * @since 3.2
- */
- public static final int SELECTED = 1 << 1;
-
- /**
- * Event detail field that indicates a user-interface component
- * state is focused (value is 1&lt;&lt;2).
- *
- * @since 3.2
- */
- public static final int FOCUSED = 1 << 2;
-
- /**
- * Event detail field that indicates a user-interface component
- * draws the background (value is 1&lt;&lt;3).
- *
- * @since 3.2
- */
- public static final int BACKGROUND = 1 << 3;
-
- /**
- * Event detail field that indicates a user-interface component
- * draws the foreground (value is 1&lt;&lt;4).
- *
- * @since 3.2
- */
- public static final int FOREGROUND = 1 << 4;
-
- /**
- * Event detail field that indicates a user-interface component
- * state is hot (value is 1&lt;&lt;5).
- *
- * @since 3.3
- */
- public static final int HOT = 1 << 5;
-
- /* This code is intentionally commented */
- //public static final int PRESSED = 1 << 3;
- //public static final int ACTIVE = 1 << 4;
- //public static final int DISABLED = 1 << 5;
- //public static final int HOT = 1 << 6;
- //public static final int DEFAULTED = 1 << 7;
-
- /**
- * Traversal event detail field value indicating that no
- * traversal action should be taken
- * (value is 0).
- */
- public static final int TRAVERSE_NONE = 0;
-
- /**
- * Traversal event detail field value indicating that the
- * key which designates that a dialog should be cancelled was
- * pressed; typically, this is the ESC key
- * (value is 1&lt;&lt;1).
- */
- public static final int TRAVERSE_ESCAPE = 1 << 1;
-
- /**
- * Traversal event detail field value indicating that the
- * key which activates the default button in a dialog was
- * pressed; typically, this is the ENTER key
- * (value is 1&lt;&lt;2).
- */
- public static final int TRAVERSE_RETURN = 1 << 2;
-
- /**
- * Traversal event detail field value indicating that the
- * key which designates that focus should be given to the
- * previous tab group was pressed; typically, this is the
- * SHIFT-TAB key sequence
- * (value is 1&lt;&lt;3).
- */
- public static final int TRAVERSE_TAB_PREVIOUS = 1 << 3;
-
- /**
- * Traversal event detail field value indicating that the
- * key which designates that focus should be given to the
- * next tab group was pressed; typically, this is the
- * TAB key
- * (value is 1&lt;&lt;4).
- */
- public static final int TRAVERSE_TAB_NEXT = 1 << 4;
-
- /**
- * Traversal event detail field value indicating that the
- * key which designates that focus should be given to the
- * previous tab item was pressed; typically, this is either
- * the LEFT-ARROW or UP-ARROW keys
- * (value is 1&lt;&lt;5).
- */
- public static final int TRAVERSE_ARROW_PREVIOUS = 1 << 5;
-
- /**
- * Traversal event detail field value indicating that the
- * key which designates that focus should be given to the
- * previous tab item was pressed; typically, this is either
- * the RIGHT-ARROW or DOWN-ARROW keys
- * (value is 1&lt;&lt;6).
- */
- public static final int TRAVERSE_ARROW_NEXT = 1 << 6;
-
- /**
- * Traversal event detail field value indicating that a
- * mnemonic key sequence was pressed
- * (value is 1&lt;&lt;7).
- */
- public static final int TRAVERSE_MNEMONIC = 1 << 7;
-
- /**
- * Traversal event detail field value indicating that the
- * key which designates that the previous page of a multi-page
- * window should be shown was pressed; typically, this
- * is the CTRL-PAGEUP key sequence
- * (value is 1&lt;&lt;8).
- */
- public static final int TRAVERSE_PAGE_PREVIOUS = 1 << 8;
-
- /**
- * Traversal event detail field value indicating that the
- * key which designates that the next page of a multi-page
- * window should be shown was pressed; typically, this
- * is the CTRL-PAGEDOWN key sequence
- * (value is 1&lt;&lt;9).
- */
- public static final int TRAVERSE_PAGE_NEXT = 1 << 9;
-
- /**
- * A constant known to be zero (0), typically used in operations
- * which take bit flags to indicate that "no bits are set".
- */
- public static final int NONE = 0;
-
- /**
- * A constant known to be zero (0), used in operations which
- * take pointers to indicate a null argument.
- */
- public static final int NULL = 0;
-
- /**
- * Indicates that a default should be used (value is -1).
- */
- public static final int DEFAULT = -1;
-
- /**
- * Indicates that a property is off (value is 0).
- *
- * @since 3.1
- */
- public static final int OFF = 0;
-
- /**
- * Indicates that a property is on (value is 1).
- *
- * @since 3.1
- */
- public static final int ON = 1;
-
- /**
- * Indicates low quality (value is 1).
- *
- * @since 3.1
- */
- public static final int LOW = 1;
-
- /**
- * Indicates high quality (value is 2).
- *
- * @since 3.1
- */
- public static final int HIGH = 2;
-
- /**
- * Style constant for menu bar behavior (value is 1&lt;&lt;1).
- * <p><b>Used By:</b><ul>
- * <li><code>Menu</code></li>
- * </ul></p>
- */
- public static final int BAR = 1 << 1;
-
- /**
- * Style constant for drop down menu/list behavior (value is 1&lt;&lt;2).
- * <br>Note that for <code>DateTime</code> this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Menu</code></li>
- * <li><code>ToolItem</code></li>
- * <li><code>CoolItem</code></li>
- * <li><code>Combo</code></li>
- * <li><code>DateTime</code></li>
- * </ul></p>
- */
- public static final int DROP_DOWN = 1 << 2;
-
- /**
- * Style constant for pop up menu behavior (value is 1&lt;&lt;3).
- * <p><b>Used By:</b><ul>
- * <li><code>Menu</code></li>
- * </ul></p>
- */
- public static final int POP_UP = 1 << 3;
-
- /**
- * Style constant for line separator behavior (value is 1&lt;&lt;1).
- * <p><b>Used By:</b><ul>
- * <li><code>Label</code></li>
- * <li><code>MenuItem</code></li>
- * <li><code>ToolItem</code></li>
- * </ul></p>
- */
- public static final int SEPARATOR = 1 << 1;
-
- /**
- * Style constant for toggle button behavior (value is 1&lt;&lt;1).
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code></li>
- * </ul></p>
- */
- public static final int TOGGLE = 1 << 1;
-
- /**
- * Style constant for arrow button behavior (value is 1&lt;&lt;2).
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code></li>
- * </ul></p>
- */
- public static final int ARROW = 1 << 2;
-
- /**
- * Style constant for push button behavior (value is 1&lt;&lt;3).
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code></li>
- * <li><code>MenuItem</code></li>
- * <li><code>ToolItem</code></li>
- * </ul></p>
- */
- public static final int PUSH = 1 << 3;
-
- /**
- * Style constant for radio button behavior (value is 1&lt;&lt;4).
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code></li>
- * <li><code>MenuItem</code></li>
- * <li><code>ToolItem</code></li>
- * </ul></p>
- */
- public static final int RADIO = 1 << 4;
-
- /**
- * Style constant for check box behavior (value is 1&lt;&lt;5).
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code></li>
- * <li><code>MenuItem</code></li>
- * <li><code>ToolItem</code></li>
- * <li><code>Table</code></li>
- * <li><code>Tree</code></li>
- * </ul></p>
- */
- public static final int CHECK = 1 << 5;
-
- /**
- * Style constant for cascade behavior (value is 1&lt;&lt;6).
- * <p><b>Used By:</b><ul>
- * <li><code>MenuItem</code></li>
- * </ul></p>
- */
- public static final int CASCADE = 1 << 6;
-
- /**
- * Style constant for multi-selection behavior in lists
- * and multiple line support on text fields (value is 1&lt;&lt;1).
- * <p><b>Used By:</b><ul>
- * <li><code>Text</code></li>
- * <li><code>List</code></li>
- * <li><code>Table</code></li>
- * <li><code>Tree</code></li>
- * <li><code>FileDialog</code></li>
- * </ul></p>
- */
- public static final int MULTI = 1 << 1;
-
- /**
- * Style constant for single selection behavior in lists
- * and single line support on text fields (value is 1&lt;&lt;2).
- * <p><b>Used By:</b><ul>
- * <li><code>Text</code></li>
- * <li><code>List</code></li>
- * <li><code>Table</code></li>
- * <li><code>Tree</code></li>
- * </ul></p>
- */
- public static final int SINGLE = 1 << 2;
-
- /**
- * Style constant for read-only behavior (value is 1&lt;&lt;3).
- * <p><b>Used By:</b><ul>
- * <li><code>Combo</code></li>
- * <li><code>Text</code></li>
- * </ul></p>
- */
- public static final int READ_ONLY = 1 << 3;
-
- /**
- * Style constant for automatic line wrap behavior (value is 1&lt;&lt;6).
- * <p><b>Used By:</b><ul>
- * <li><code>Label</code></li>
- * <li><code>Text</code></li>
- * <li><code>ToolBar</code></li>
- * <li><code>Spinner</code></li>
- * </ul></p>
- */
- public static final int WRAP = 1 << 6;
-
- /**
- * Style constant for search behavior (value is 1&lt;&lt;7).
- * <p><b>Used By:</b><ul>
- * <li><code>Text</code></li>
- * </ul></p>
- *
- * @since 3.3
- */
- public static final int SEARCH = 1 << 7;
-
- /**
- * Style constant for simple (not drop down) behavior (value is 1&lt;&lt;6).
- * <p><b>Used By:</b><ul>
- * <li><code>Combo</code></li>
- * </ul></p>
- */
- public static final int SIMPLE = 1 << 6;
-
- /**
- * Style constant for password behavior (value is 1&lt;&lt;22).
- * <p><b>Used By:</b><ul>
- * <li><code>Text</code></li>
- * </ul></p>
- *
- * @since 3.0
- */
- public static final int PASSWORD = 1 << 22;
-
- /**
- * Style constant for shadow in behavior (value is 1&lt;&lt;2).
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Label</code></li>
- * <li><code>Group</code></li>
- * </ul></p>
- */
- public static final int SHADOW_IN = 1 << 2;
-
- /**
- * Style constant for shadow out behavior (value is 1&lt;&lt;3).
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Label</code></li>
- * <li><code>Group</code></li>
- * <li><code>ToolBar</code></li>
- * </ul></p>
- */
- public static final int SHADOW_OUT = 1 << 3;
-
- /**
- * Style constant for shadow etched in behavior (value is 1&lt;&lt;4).
- * <br>Note that this is a <em>HINT</em>. It is ignored on all platforms except Motif.
- * <p><b>Used By:</b><ul>
- * <li><code>Group</code></li>
- * </ul></p>
- */
- public static final int SHADOW_ETCHED_IN = 1 << 4;
-
- /**
- * Style constant for shadow etched out behavior (value is 1&lt;&lt;6).
- * <br>Note that this is a <em>HINT</em>. It is ignored on all platforms except Motif.
- * <p><b>Used By:</b><ul>
- * <li><code>Group</code></li>
- * </ul></p>
- */
- public static final int SHADOW_ETCHED_OUT = 1 << 6;
-
- /**
- * Style constant for no shadow behavior (value is 1&lt;&lt;5).
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Label</code></li>
- * <li><code>Group</code></li>
- * </ul></p>
- */
- public static final int SHADOW_NONE = 1 << 5;
-
- /**
- * Style constant for progress bar behavior (value is 1&lt;&lt;1).
- * <p><b>Used By:</b><ul>
- * <li><code>ProgressBar</code></li>
- * </ul></p>
- */
- public static final int INDETERMINATE = 1 << 1;
-
- /**
- * Style constant for tool window behavior (value is 1&lt;&lt;2).
- * <p>
- * A tool window is a window intended to be used as a floating toolbar.
- * It typically has a title bar that is shorter than a normal title bar,
- * and the window title is typically drawn using a smaller font.
- * <br>Note that this is a <em>HINT</em>.
- * </p><p><b>Used By:</b><ul>
- * <li><code>Decorations</code> and subclasses</li>
- * </ul></p>
- */
- public static final int TOOL = 1 << 2;
-
- /**
- * Style constant to ensure no trimmings are used (value is 1&lt;&lt;3).
- * <br>Note that this overrides all other trim styles.
- * <p><b>Used By:</b><ul>
- * <li><code>Decorations</code> and subclasses</li>
- * </ul></p>
- */
- public static final int NO_TRIM = 1 << 3;
-
- /**
- * Style constant for resize box trim (value is 1&lt;&lt;4).
- * <p><b>Used By:</b><ul>
- * <li><code>Decorations</code> and subclasses</li>
- * <li><code>Tracker</code></li>
- * </ul></p>
- */
- public static final int RESIZE = 1 << 4;
-
- /**
- * Style constant for title area trim (value is 1&lt;&lt;5).
- * <p><b>Used By:</b><ul>
- * <li><code>Decorations</code> and subclasses</li>
- * </ul></p>
- */
- public static final int TITLE = 1 << 5;
-
- /**
- * Style constant for close box trim (value is 1&lt;&lt;6,
- * since we do not distinguish between CLOSE style and MENU style).
- * <p><b>Used By:</b><ul>
- * <li><code>Decorations</code> and subclasses</li>
- * </ul></p>
- */
- public static final int CLOSE = 1 << 6;
-
- /**
- * Style constant for shell menu trim (value is 1&lt;&lt;6,
- * since we do not distinguish between CLOSE style and MENU style).
- * <p><b>Used By:</b><ul>
- * <li><code>Decorations</code> and subclasses</li>
- * </ul></p>
- */
- public static final int MENU = CLOSE;
-
- /**
- * Style constant for minimize box trim (value is 1&lt;&lt;7).
- * <p><b>Used By:</b><ul>
- * <li><code>Decorations</code> and subclasses</li>
- * </ul></p>
- */
- public static final int MIN = 1 << 7;
-
- /**
- * Style constant for maximize box trim (value is 1&lt;&lt;10).
- * <p><b>Used By:</b><ul>
- * <li><code>Decorations</code> and subclasses</li>
- * </ul></p>
- */
- public static final int MAX = 1 << 10;
-
- /**
- * Style constant for horizontal scrollbar behavior (value is 1&lt;&lt;8).
- * <p><b>Used By:</b><ul>
- * <li><code>Scrollable</code> and subclasses</li>
- * </ul></p>
- */
- public static final int H_SCROLL = 1 << 8;
-
- /**
- * Style constant for vertical scrollbar behavior (value is 1&lt;&lt;9).
- * <p><b>Used By:</b><ul>
- * <li><code>Scrollable</code> and subclasses</li>
- * </ul></p>
- */
- public static final int V_SCROLL = 1 << 9;
-
- /**
- * Style constant for no scrollbar behavior (value is 1&lt;&lt;4).
- * <p>
- * When neither H_SCROLL or V_SCROLL are specified, controls
- * are free to create the default scroll bars for the control.
- * Using NO_SCROLL overrides the default and forces the control
- * to have no scroll bars.
- *
- * <b>Used By:</b><ul>
- * <li><code>Tree</code></li>
- * <li><code>Table</code></li>
- * </ul></p>
- *
- * @since 3.4
- */
- public static final int NO_SCROLL = 1 << 4;
-
- /**
- * Style constant for bordered behavior (value is 1&lt;&lt;11).
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Control</code> and subclasses</li>
- * </ul></p>
- */
- public static final int BORDER = 1 << 11;
-
- /**
- * Style constant indicating that the window manager should clip
- * a widget's children with respect to its viewable area. (value is 1&lt;&lt;12).
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Control</code> and subclasses</li>
- * </ul></p>
- */
- public static final int CLIP_CHILDREN = 1 << 12;
-
- /**
- * Style constant indicating that the window manager should clip
- * a widget's siblings with respect to its viewable area. (value is 1&lt;&lt;13).
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Control</code> and subclasses</li>
- * </ul></p>
- */
- public static final int CLIP_SIBLINGS = 1 << 13;
-
- /**
- * Style constant for always on top behavior (value is 1&lt;&lt;14).
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Shell</code> and subclasses</li>
- * </ul></p>
- */
- public static final int ON_TOP = 1 << 14;
-
- /**
- * Style constant for sheet window behavior (value is 1&lt;&lt;28).
- * <p>
- * A sheet window is a window intended to be used as a temporary modal
- * dialog that is attached to a parent window. It is typically used to
- * prompt the user before proceeding. The window trim, positioning and
- * general look of a sheet window is platform specific. For example,
- * on the Macintosh, at the time this documentation was written, the
- * window title is not visible.
- * <br>Note that this is a <em>HINT</em>.
- * </p><p><b>Used By:</b><ul>
- * <li><code>Dialog</code> and subclasses</li>
- * <li><code>Shell</code> and subclasses</li>
- * </ul></p>
- *
- * @since 3.5
- */
- public static final int SHEET = 1 << 28;
-
- /**
- * Trim style convenience constant for the most common top level shell appearance
- * (value is CLOSE|TITLE|MIN|MAX|RESIZE).
- * <p><b>Used By:</b><ul>
- * <li><code>Shell</code></li>
- * </ul></p>
- */
- public static final int SHELL_TRIM = CLOSE | TITLE | MIN | MAX | RESIZE;
-
- /**
- * Trim style convenience constant for the most common dialog shell appearance
- * (value is CLOSE|TITLE|BORDER).
- * <p><b>Used By:</b><ul>
- * <li><code>Shell</code></li>
- * </ul></p>
- */
- public static final int DIALOG_TRIM = TITLE | CLOSE | BORDER;
-
- /**
- * Style constant for modeless behavior (value is 0).
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Dialog</code></li>
- * <li><code>Shell</code></li>
- * </ul></p>
- */
- public static final int MODELESS = 0;
-
- /**
- * Style constant for primary modal behavior (value is 1&lt;&lt;15).
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Dialog</code></li>
- * <li><code>Shell</code></li>
- * </ul></p>
- */
- public static final int PRIMARY_MODAL = 1 << 15;
-
- /**
- * Style constant for application modal behavior (value is 1&lt;&lt;16).
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Dialog</code></li>
- * <li><code>Shell</code></li>
- * </ul></p>
- */
- public static final int APPLICATION_MODAL = 1 << 16;
-
- /**
- * Style constant for system modal behavior (value is 1&lt;&lt;17).
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Dialog</code></li>
- * <li><code>Shell</code></li>
- * </ul></p>
- */
- public static final int SYSTEM_MODAL = 1 << 17;
-
- /**
- * Style constant for selection hiding behavior when the widget loses focus (value is 1&lt;&lt;15).
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Table</code></li>
- * </ul></p>
- */
- public static final int HIDE_SELECTION = 1 << 15;
-
- /**
- * Style constant for full row selection behavior and
- * selection constant indicating that a full line should be
- * drawn. (value is 1&lt;&lt;16).
- * <br>Note that for some widgets this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Table</code></li>
- * <li><code>Tree</code></li>
- * <li><code>StyledText</code></li>
- * <li><code>TextLayout</code></li>
- * </ul></p>
- */
- public static final int FULL_SELECTION = 1 << 16;
-
- /**
- * Style constant for flat appearance. (value is 1&lt;&lt;23).
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code></li>
- * <li><code>ToolBar</code></li>
- * </ul></p>
- */
- public static final int FLAT = 1 << 23;
-
- /**
- * Style constant for smooth appearance. (value is 1&lt;&lt;16).
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>ProgressBar</code></li>
- * <li><code>Sash</code></li>
- * </ul></p>
- */
- public static final int SMOOTH = 1 << 16;
-
- /**
- * Style constant for no background behavior (value is 1&lt;&lt;18).
- * <p>
- * By default, before a widget paints, the client area is filled with the current background.
- * When this style is specified, the background is not filled, and the application is responsible
- * for filling every pixel of the client area.
- * This style might be used as an alternative to "double-buffering" in order to reduce flicker.
- * This style does not mean "transparent" - widgets that are obscured will not draw through.
- * </p><p><b>Used By:</b><ul>
- * <li><code>Composite</code></li>
- * </ul></p>
- */
- public static final int NO_BACKGROUND = 1 << 18;
-
- /**
- * Style constant for no focus from the mouse behavior (value is 1&lt;&lt;19).
- * <p>
- * Normally, when the user clicks on a control, focus is assigned to that
- * control, providing the control has no children. Some controls, such as
- * tool bars and sashes, don't normally take focus when the mouse is clicked
- * or accept focus when assigned from within the program. This style allows
- * Composites to implement "no focus" mouse behavior.
- *
- * <br>Note that this is a <em>HINT</em>.
- * </p>
- * <p><b>Used By:</b><ul>
- * <li><code>Composite</code></li>
- * </ul></p>
- */
- public static final int NO_FOCUS = 1 << 19;
-
- /**
- * Style constant for no redraw on resize behavior (value is 1&lt;&lt;20).
- * <p>
- * This style stops the entire client area from being invalidated when the size
- * of the Canvas changes. Specifically, when the size of the Canvas gets smaller,
- * the SWT.Paint event is not sent. When it gets bigger, an SWT.Paint event is
- * sent with a GC clipped to only the new areas to be painted. Without this
- * style, the entire client area will be repainted.
- *
- * <br>Note that this is a <em>HINT</em>.
- * </p><p><b>Used By:</b><ul>
- * <li><code>Composite</code></li>
- * </ul></p>
- */
- public static final int NO_REDRAW_RESIZE = 1 << 20;
-
- /**
- * Style constant for no paint event merging behavior (value is 1&lt;&lt;21).
- *
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Composite</code></li>
- * </ul></p>
- */
- public static final int NO_MERGE_PAINTS = 1 << 21;
-
- /**
- * Style constant for preventing child radio group behavior (value is 1&lt;&lt;22).
- * <p><b>Used By:</b><ul>
- * <li><code>Composite</code></li>
- * <li><code>Menu</code></li>
- * </ul></p>
- */
- public static final int NO_RADIO_GROUP = 1 << 22;
-
- /**
- * Style constant for left to right orientation (value is 1&lt;&lt;25).
- * <p>
- * When orientation is not explicitly specified, orientation is
- * inherited. This means that children will be assigned the
- * orientation of their parent. To override this behavior and
- * force an orientation for a child, explicitly set the orientation
- * of the child when that child is created.
- * <br>Note that this is a <em>HINT</em>.
- * </p>
- * <p><b>Used By:</b><ul>
- * <li><code>Control</code></li>
- * <li><code>Menu</code></li>
- * <li><code>GC</code></li>
- * </ul></p>
- *
- * @since 2.1.2
- */
- public static final int LEFT_TO_RIGHT = 1 << 25;
-
- /**
- * Style constant for right to left orientation (value is 1&lt;&lt;26).
- * <p>
- * When orientation is not explicitly specified, orientation is
- * inherited. This means that children will be assigned the
- * orientation of their parent. To override this behavior and
- * force an orientation for a child, explicitly set the orientation
- * of the child when that child is created.
- * <br>Note that this is a <em>HINT</em>.
- * </p>
- * <p><b>Used By:</b><ul>
- * <li><code>Control</code></li>
- * <li><code>Menu</code></li>
- * <li><code>GC</code></li>
- * </ul></p>
- *
- * @since 2.1.2
- */
- public static final int RIGHT_TO_LEFT = 1 << 26;
-
- /**
- * Style constant to indicate coordinate mirroring (value is 1&lt;&lt;27).
- * <p><b>Used By:</b><ul>
- * <li><code>Control</code></li>
- * <li><code>Menu</code></li>
- * </ul></p>
- *
- * @since 2.1.2
- */
- public static final int MIRRORED = 1 << 27;
-
- /**
- * Style constant to allow embedding (value is 1&lt;&lt;24).
- * <p><b>Used By:</b><ul>
- * <li><code>Composite</code></li>
- * </ul></p>
- *
- * @since 3.0
- */
- public static final int EMBEDDED = 1 << 24;
-
- /**
- * Style constant to allow virtual data (value is 1&lt;&lt;28).
- * <p><b>Used By:</b><ul>
- * <li><code>Table</code></li>
- * <li><code>Tree</code></li>
- * </ul></p>
- *
- * @since 3.0
- */
- public static final int VIRTUAL = 1 << 28;
-
- /**
- * Style constant to indicate double buffering (value is 1&lt;&lt;29).
- * <p><b>Used By:</b><ul>
- * <li><code>Control</code></li>
- * </ul></p>
- *
- * @since 3.1
- */
- public static final int DOUBLE_BUFFERED = 1 << 29;
-
- /**
- * Style constant for transparent behavior (value is 1&lt;&lt;30).
- * <p>
- * By default, before a widget paints, the client area is filled with the current background.
- * When this style is specified, the background is not filled and widgets that are obscured
- * will draw through.
- * </p><p><b>Used By:</b><ul>
- * <li><code>Composite</code></li>
- * </ul></p>
- *
- * @since 3.4
- *
- * WARNING: THIS API IS UNDER CONSTRUCTION AND SHOULD NOT BE USED
- */
- public static final int TRANSPARENT = 1 << 30;
-
- /**
- * Style constant for align up behavior (value is 1&lt;&lt;7,
- * since align UP and align TOP are considered the same).
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code> with <code>ARROW</code> style</li>
- * <li><code>Tracker</code></li>
- * <li><code>Table</code></li>
- * <li><code>Tree</code></li>
- * </ul></p>
- */
- public static final int UP = 1 << 7;
-
- /**
- * Style constant to indicate single underline (value is 0).
- * <p><b>Used By:</b><ul>
- * <li><code>TextStyle</code></li>
- * </ul></p>
- *
- * @since 3.4
- */
- public static final int UNDERLINE_SINGLE = 0;
-
- /**
- * Style constant to indicate double underline (value is 1).
- * <p><b>Used By:</b><ul>
- * <li><code>TextStyle</code></li>
- * </ul></p>
- *
- * @since 3.4
- */
- public static final int UNDERLINE_DOUBLE = 1;
-
- /**
- * Style constant to indicate error underline (value is 2).
- * <p><b>Used By:</b><ul>
- * <li><code>TextStyle</code></li>
- * </ul></p>
- *
- * @since 3.4
- */
- public static final int UNDERLINE_ERROR = 2;
-
- /**
- * Style constant to indicate squiggle underline (value is 3).
- * <p><b>Used By:</b><ul>
- * <li><code>TextStyle</code></li>
- * </ul></p>
- *
- * @since 3.4
- */
- public static final int UNDERLINE_SQUIGGLE = 3;
-
- /**
- * Style constant to indicate link underline (value is 0).
- * <p>
- * If the text color or the underline color are not set in the range
- * the usage of <code>UNDERLINE_LINK</code> will change these colors
- * to the preferred link color of the platform.<br>
- * Note that clients that use this style, such as <code>StyledText</code>,
- * will include code to track the mouse and change the cursor to the hand
- * cursor when mouse is over the link.
- * </p>
- * <p><b>Used By:</b><ul>
- * <li><code>TextStyle</code></li>
- * </ul></p>
- *
- * @since 3.5
- */
- public static final int UNDERLINE_LINK = 4;
-
- /**
- * Style constant to indicate solid border (value is 1).
- * <p><b>Used By:</b><ul>
- * <li><code>TextStyle</code></li>
- * </ul></p>
- *
- * @since 3.4
- */
- public static final int BORDER_SOLID = 1;
-
- /**
- * Style constant to indicate dashed border (value is 2).
- * <p><b>Used By:</b><ul>
- * <li><code>TextStyle</code></li>
- * </ul></p>
- *
- * @since 3.4
- */
- public static final int BORDER_DASH = 2;
-
- /**
- * Style constant to indicate dotted border (value is 4).
- * <p><b>Used By:</b><ul>
- * <li><code>TextStyle</code></li>
- * </ul></p>
- *
- * @since 3.4
- */
- public static final int BORDER_DOT = 4;
-
- /**
- * Style constant for align top behavior (value is 1&lt;&lt;7,
- * since align UP and align TOP are considered the same).
- * <p><b>Used By:</b><ul>
- * <li><code>FormAttachment</code> in a <code>FormLayout</code></li>
- * </ul></p>
- */
- public static final int TOP = UP;
-
- /**
- * Style constant for align down behavior (value is 1&lt;&lt;10,
- * since align DOWN and align BOTTOM are considered the same).
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code> with <code>ARROW</code> style</li>
- * <li><code>Tracker</code></li>
- * <li><code>Table</code></li>
- * <li><code>Tree</code></li>
- * </ul></p>
- */
- public static final int DOWN = 1 << 10;
-
- /**
- * Style constant for align bottom behavior (value is 1&lt;&lt;10,
- * since align DOWN and align BOTTOM are considered the same).
- * <p><b>Used By:</b><ul>
- * <li><code>FormAttachment</code> in a <code>FormLayout</code></li>
- * </ul></p>
- */
- public static final int BOTTOM = DOWN;
-
- /**
- * Style constant for leading alignment (value is 1&lt;&lt;14).
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code></li>
- * <li><code>Label</code></li>
- * <li><code>TableColumn</code></li>
- * <li><code>Tracker</code></li>
- * <li><code>FormAttachment</code> in a <code>FormLayout</code></li>
- * </ul></p>
- *
- * @since 2.1.2
- */
- public static final int LEAD = 1 << 14;
-
- /**
- * Style constant for align left behavior (value is 1&lt;&lt;14).
- * This is a synonym for LEAD (value is 1&lt;&lt;14). Newer
- * applications should use LEAD instead of LEFT to make code more
- * understandable on right-to-left platforms.
- */
- public static final int LEFT = LEAD;
-
- /**
- * Style constant for trailing alignment (value is 1&lt;&lt;17).
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code></li>
- * <li><code>Label</code></li>
- * <li><code>TableColumn</code></li>
- * <li><code>Tracker</code></li>
- * <li><code>FormAttachment</code> in a <code>FormLayout</code></li>
- * </ul></p>
- *
- * @since 2.1.2
- */
- public static final int TRAIL = 1 << 17;
-
- /**
- * Style constant for align right behavior (value is 1&lt;&lt;17).
- * This is a synonym for TRAIL (value is 1&lt;&lt;17). Newer
- * applications should use TRAIL instead of RIGHT to make code more
- * understandable on right-to-left platforms.
- */
- public static final int RIGHT = TRAIL;
-
- /**
- * Style constant for align center behavior (value is 1&lt;&lt;24).
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code></li>
- * <li><code>Label</code></li>
- * <li><code>TableColumn</code></li>
- * <li><code>FormAttachment</code> in a <code>FormLayout</code></li>
- * </ul></p>
- */
- public static final int CENTER = 1 << 24;
-
- /**
- * Style constant for horizontal alignment or orientation behavior (value is 1&lt;&lt;8).
- * <p><b>Used By:</b><ul>
- * <li><code>Label</code></li>
- * <li><code>ProgressBar</code></li>
- * <li><code>Sash</code></li>
- * <li><code>Scale</code></li>
- * <li><code>ScrollBar</code></li>
- * <li><code>Slider</code></li>
- * <li><code>ToolBar</code></li>
- * <li><code>FillLayout</code> type</li>
- * <li><code>RowLayout</code> type</li>
- * </ul></p>
- */
- public static final int HORIZONTAL = 1 << 8;
-
- /**
- * Style constant for vertical alignment or orientation behavior (value is 1&lt;&lt;9).
- * <p><b>Used By:</b><ul>
- * <li><code>Label</code></li>
- * <li><code>ProgressBar</code></li>
- * <li><code>Sash</code></li>
- * <li><code>Scale</code></li>
- * <li><code>ScrollBar</code></li>
- * <li><code>Slider</code></li>
- * <li><code>ToolBar</code></li>
- * <li><code>CoolBar</code></li>
- * <li><code>FillLayout</code> type</li>
- * <li><code>RowLayout</code> type</li>
- * </ul></p>
- */
- public static final int VERTICAL = 1 << 9;
-
- /**
- * Style constant for date display (value is 1&lt;&lt;5).
- * <p><b>Used By:</b><ul>
- * <li><code>DateTime</code></li>
- * </ul></p>
- *
- * @since 3.3
- */
- public static final int DATE = 1 << 5;
-
- /**
- * Style constant for time display (value is 1&lt;&lt;7).
- * <p><b>Used By:</b><ul>
- * <li><code>DateTime</code></li>
- * </ul></p>
- *
- * @since 3.3
- */
- public static final int TIME = 1 << 7;
-
- /**
- * Style constant for calendar display (value is 1&lt;&lt;10).
- * <p><b>Used By:</b><ul>
- * <li><code>DateTime</code></li>
- * </ul></p>
- *
- * @since 3.3
- */
- public static final int CALENDAR = 1 << 10;
-
- /**
- * Style constant for short date/time format (value is 1&lt;&lt;15).
- * <p>
- * A short date displays the month and year.
- * A short time displays hours and minutes.
- * <br>Note that this is a <em>HINT</em>.
- * </p>
- * <p><b>Used By:</b><ul>
- * <li><code>DateTime</code></li>
- * </ul></p>
- *
- * @since 3.3
- */
- public static final int SHORT = 1 << 15;
-
- /**
- * Style constant for medium date/time format (value is 1&lt;&lt;16).
- * <p>
- * A medium date displays the day, month and year.
- * A medium time displays hours, minutes, and seconds.
- * <br>Note that this is a <em>HINT</em>.
- * </p>
- * <p><b>Used By:</b><ul>
- * <li><code>DateTime</code></li>
- * </ul></p>
- *
- * @since 3.3
- */
- public static final int MEDIUM = 1 << 16;
-
- /**
- * Style constant for long date/time format (value is 1&lt;&lt;28).
- * <p>
- * A long date displays the day, month and year.
- * A long time displays hours, minutes, and seconds.
- * The day and month names may be displayed.
- * <br>Note that this is a <em>HINT</em>.
- * </p>
- * <p><b>Used By:</b><ul>
- * <li><code>DateTime</code></li>
- * </ul></p>
- *
- * @since 3.3
- */
- public static final int LONG = 1 << 28;
-
- /**
- * Style constant specifying that a Browser should use a Mozilla GRE
- * for rendering its content (value is 1&lt;&lt;15).
- * <p>
- * <p><b>Used By:</b><ul>
- * <li><code>Browser</code></li>
- * </ul></p>
- *
- * @since 3.3
- */
- public static final int MOZILLA = 1 << 15;
-
- /**
- * Style constant for balloon behavior (value is 1&lt;&lt;12).
- * <p><b>Used By:</b><ul>
- * <li><code>ToolTip</code></li>
- * </ul></p>
- *
- * @since 3.2
- */
- public static final int BALLOON = 1 << 12;
-
- /**
- * Style constant for vertical alignment or orientation behavior (value is 1).
- * <p><b>Used By:</b><ul>
- * <li><code>GridLayout</code> type</li>
- * </ul></p>
- */
- public static final int BEGINNING = 1;
-
- /**
- * Style constant for vertical alignment or orientation behavior (value is 4).
- * <p><b>Used By:</b><ul>
- * <li><code>GridLayout</code> type</li>
- * </ul></p>
- */
- public static final int FILL = 4;
-
- /**
- * Input Method Editor style constant for double byte
- * input behavior (value is 1&lt;&lt;1).
- */
- public static final int DBCS = 1 << 1;
-
- /**
- * Input Method Editor style constant for alpha
- * input behavior (value is 1&lt;&lt;2).
- */
- public static final int ALPHA = 1 << 2;
-
- /**
- * Input Method Editor style constant for native
- * input behavior (value is 1&lt;&lt;3).
- */
- public static final int NATIVE = 1 << 3;
-
- /**
- * Input Method Editor style constant for phonetic
- * input behavior (value is 1&lt;&lt;4).
- */
- public static final int PHONETIC = 1 << 4;
-
- /**
- * Input Method Editor style constant for romanicized
- * input behavior (value is 1&lt;&lt;5).
- */
- public static final int ROMAN = 1 << 5;
-
- /**
- * ASCII character convenience constant for the backspace character
- * (value is the <code>char</code> '\b').
- */
- public static final char BS = '\b';
-
- /**
- * ASCII character convenience constant for the carriage return character
- * (value is the <code>char</code> '\r').
- */
- public static final char CR = '\r';
-
- /**
- * ASCII character convenience constant for the delete character
- * (value is the <code>char</code> with value 127).
- */
- public static final char DEL = 0x7F;
-
- /**
- * ASCII character convenience constant for the escape character
- * (value is the <code>char</code> with value 27).
- */
- public static final char ESC = 0x1B;
-
- /**
- * ASCII character convenience constant for the line feed character
- * (value is the <code>char</code> '\n').
- */
- public static final char LF = '\n';
-
- /**
- * ASCII character convenience constant for the tab character
- * (value is the <code>char</code> '\t').
- *
- * @since 2.1
- */
- public static final char TAB = '\t';
-
- /**
- * keyboard and/or mouse event mask indicating that the ALT key
- * was pushed on the keyboard when the event was generated
- * (value is 1&lt;&lt;16).
- */
- public static final int ALT = 1 << 16;
-
- /**
- * Keyboard and/or mouse event mask indicating that the SHIFT key
- * was pushed on the keyboard when the event was generated
- * (value is 1&lt;&lt;17).
- */
- public static final int SHIFT = 1 << 17;
-
- /**
- * Keyboard and/or mouse event mask indicating that the CTRL key
- * was pushed on the keyboard when the event was generated
- * (value is 1&lt;&lt;18).
- */
- public static final int CTRL = 1 << 18;
-
- /**
- * Keyboard and/or mouse event mask indicating that the CTRL key
- * was pushed on the keyboard when the event was generated. This
- * is a synonym for CTRL (value is 1&lt;&lt;18).
- */
- public static final int CONTROL = CTRL;
-
- /**
- * Keyboard and/or mouse event mask indicating that the COMMAND key
- * was pushed on the keyboard when the event was generated
- * (value is 1&lt;&lt;22).
- *
- * @since 2.1
- */
- public static final int COMMAND = 1 << 22;
-
- /**
- * Keyboard and/or mouse event mask indicating all possible
- * keyboard modifiers.
- *
- * To allow for the future, this mask is intended to be used in
- * place of code that references each individual keyboard mask.
- * For example, the following expression will determine whether
- * any modifier is pressed and will continue to work as new modifier
- * masks are added.
- *
- * <code>(stateMask & SWT.MODIFIER_MASK) != 0</code>.
- *
- * @since 2.1
- */
- public static final int MODIFIER_MASK;
-
- /**
- * Keyboard and/or mouse event mask indicating that mouse button one
- * was pushed when the event was generated. (value is 1&lt;&lt;19).
- */
- public static final int BUTTON1 = 1 << 19;
-
- /**
- * Keyboard and/or mouse event mask indicating that mouse button two
- * was pushed when the event was generated. (value is 1&lt;&lt;20).
- */
- public static final int BUTTON2 = 1 << 20;
-
- /**
- * Keyboard and/or mouse event mask indicating that mouse button three
- * was pushed when the event was generated. (value is 1&lt;&lt;21).
- */
- public static final int BUTTON3 = 1 << 21;
-
- /**
- * Keyboard and/or mouse event mask indicating that mouse button four
- * was pushed when the event was generated. (value is 1&lt;&lt;23).
- *
- * @since 3.1
- */
- public static final int BUTTON4 = 1 << 23;
-
- /**
- * Keyboard and/or mouse event mask indicating that mouse button five
- * was pushed when the event was generated. (value is 1&lt;&lt;25).
- *
- * @since 3.1
- */
- public static final int BUTTON5 = 1 << 25;
-
- /**
- * Keyboard and/or mouse event mask indicating all possible
- * mouse buttons.
- *
- * To allow for the future, this mask is intended to be used
- * in place of code that references each individual button mask.
- * For example, the following expression will determine whether
- * any button is pressed and will continue to work as new button
- * masks are added.
- *
- * <code>(stateMask & SWT.BUTTON_MASK) != 0</code>.
- *
- * @since 2.1
- */
- public static final int BUTTON_MASK;
-
- /**
- * Keyboard and/or mouse event mask indicating that the MOD1 key
- * was pushed on the keyboard when the event was generated.
- *
- * This is the primary keyboard modifier for the platform.
- *
- * @since 2.1
- */
- public static final int MOD1;
-
- /**
- * Keyboard and/or mouse event mask indicating that the MOD2 key
- * was pushed on the keyboard when the event was generated.
- *
- * This is the secondary keyboard modifier for the platform.
- *
- * @since 2.1
- */
- public static final int MOD2;
-
- /**
- * Keyboard and/or mouse event mask indicating that the MOD3 key
- * was pushed on the keyboard when the event was generated.
- *
- * @since 2.1
- */
- public static final int MOD3;
-
- /**
- * Keyboard and/or mouse event mask indicating that the MOD4 key
- * was pushed on the keyboard when the event was generated.
- *
- * @since 2.1
- */
- public static final int MOD4;
-
- /**
- * Constants to indicate line scrolling (value is 1).
- * <p><b>Used By:</b><ul>
- * <li><code>Control</code></li>
- * </ul></p>
- *
- * @since 3.1
- */
- public static final int SCROLL_LINE = 1;
-
- /**
- * Constants to indicate page scrolling (value is 2).
- * <p><b>Used By:</b><ul>
- * <li><code>Control</code></li>
- * </ul></p>
- *
- * @since 3.1
- */
- public static final int SCROLL_PAGE = 2;
-
- /**
- * Accelerator constant used to differentiate a key code from a
- * unicode character.
- *
- * If this bit is set, then the key stroke
- * portion of an accelerator represents a key code. If this bit
- * is not set, then the key stroke portion of an accelerator is
- * a unicode character.
- *
- * The following expression is false:
- *
- * <code>((SWT.MOD1 | SWT.MOD2 | 'T') & SWT.KEYCODE_BIT) != 0</code>.
- *
- * The following expression is true:
- *
- * <code>((SWT.MOD3 | SWT.F2) & SWT.KEYCODE_BIT) != 0</code>.
- *
- * (value is (1&lt;&lt;24))
- *
- * @since 2.1
- */
- public static final int KEYCODE_BIT = (1 << 24);
-
- /**
- * Accelerator constant used to extract the key stroke portion of
- * an accelerator.
- *
- * The key stroke may be a key code or a unicode
- * value. If the key stroke is a key code <code>KEYCODE_BIT</code>
- * will be set.
- *
- * @since 2.1
- */
- public static final int KEY_MASK = KEYCODE_BIT + 0xFFFF;
-
- /**
- * Keyboard event constant representing the UP ARROW key
- * (value is (1&lt;&lt;24)+1).
- */
- public static final int ARROW_UP = KEYCODE_BIT + 1;
-
- /**
- * Keyboard event constant representing the DOWN ARROW key
- * (value is (1&lt;&lt;24)+2).
- */
- public static final int ARROW_DOWN = KEYCODE_BIT + 2;
-
- /**
- * Keyboard event constant representing the LEFT ARROW key
- * (value is (1&lt;&lt;24)+3).
- */
- public static final int ARROW_LEFT = KEYCODE_BIT + 3;
-
- /**
- * Keyboard event constant representing the RIGHT ARROW key
- * (value is (1&lt;&lt;24)+4).
- */
- public static final int ARROW_RIGHT = KEYCODE_BIT + 4;
-
- /**
- * Keyboard event constant representing the PAGE UP key
- * (value is (1&lt;&lt;24)+5).
- */
- public static final int PAGE_UP = KEYCODE_BIT + 5;
-
- /**
- * Keyboard event constant representing the PAGE DOWN key
- * (value is (1&lt;&lt;24)+6).
- */
- public static final int PAGE_DOWN = KEYCODE_BIT + 6;
-
- /**
- * Keyboard event constant representing the HOME key
- * (value is (1&lt;&lt;24)+7).
- */
- public static final int HOME = KEYCODE_BIT + 7;
-
- /**
- * Keyboard event constant representing the END key
- * (value is (1&lt;&lt;24)+8).
- */
- public static final int END = KEYCODE_BIT + 8;
-
- /**
- * Keyboard event constant representing the INSERT key
- * (value is (1&lt;&lt;24)+9).
- */
- public static final int INSERT = KEYCODE_BIT + 9;
-
- /**
- * Keyboard event constant representing the F1 key
- * (value is (1&lt;&lt;24)+10).
- */
- public static final int F1 = KEYCODE_BIT + 10;
-
- /**
- * Keyboard event constant representing the F2 key
- * (value is (1&lt;&lt;24)+11).
- */
- public static final int F2 = KEYCODE_BIT + 11;
-
- /**
- * Keyboard event constant representing the F3 key
- * (value is (1&lt;&lt;24)+12).
- */
- public static final int F3 = KEYCODE_BIT + 12;
-
- /**
- * Keyboard event constant representing the F4 key
- * (value is (1&lt;&lt;24)+13).
- */
- public static final int F4 = KEYCODE_BIT + 13;
-
- /**
- * Keyboard event constant representing the F5 key
- * (value is (1&lt;&lt;24)+14).
- */
- public static final int F5 = KEYCODE_BIT + 14;
-
- /**
- * Keyboard event constant representing the F6 key
- * (value is (1&lt;&lt;24)+15).
- */
- public static final int F6 = KEYCODE_BIT + 15;
-
- /**
- * Keyboard event constant representing the F7 key
- * (value is (1&lt;&lt;24)+16).
- */
- public static final int F7 = KEYCODE_BIT + 16;
-
- /**
- * Keyboard event constant representing the F8 key
- * (value is (1&lt;&lt;24)+17).
- */
- public static final int F8 = KEYCODE_BIT + 17;
-
- /**
- * Keyboard event constant representing the F9 key
- * (value is (1&lt;&lt;24)+18).
- */
- public static final int F9 = KEYCODE_BIT + 18;
-
- /**
- * Keyboard event constant representing the F10 key
- * (value is (1&lt;&lt;24)+19).
- */
- public static final int F10 = KEYCODE_BIT + 19;
-
- /**
- * Keyboard event constant representing the F11 key
- * (value is (1&lt;&lt;24)+20).
- */
- public static final int F11 = KEYCODE_BIT + 20;
-
- /**
- * Keyboard event constant representing the F12 key
- * (value is (1&lt;&lt;24)+21).
- */
- public static final int F12 = KEYCODE_BIT + 21;
-
- /**
- * Keyboard event constant representing the F13 key
- * (value is (1&lt;&lt;24)+22).
- *
- * @since 3.0
- */
- public static final int F13 = KEYCODE_BIT + 22;
-
- /**
- * Keyboard event constant representing the F14 key
- * (value is (1&lt;&lt;24)+23).
- *
- * @since 3.0
- */
- public static final int F14 = KEYCODE_BIT + 23;
-
- /**
- * Keyboard event constant representing the F15 key
- * (value is (1&lt;&lt;24)+24).
- *
- * @since 3.0
- */
- public static final int F15 = KEYCODE_BIT + 24;
-
- /**
- * Keyboard event constant representing the numeric key
- * pad multiply key (value is (1&lt;&lt;24)+42).
- *
- * @since 3.0
- */
- public static final int KEYPAD_MULTIPLY = KEYCODE_BIT + 42;
-
- /**
- * Keyboard event constant representing the numeric key
- * pad add key (value is (1&lt;&lt;24)+43).
- *
- * @since 3.0
- */
- public static final int KEYPAD_ADD = KEYCODE_BIT + 43;
-
- /**
- * Keyboard event constant representing the numeric key
- * pad subtract key (value is (1&lt;&lt;24)+45).
- *
- * @since 3.0
- */
- public static final int KEYPAD_SUBTRACT = KEYCODE_BIT + 45;
-
- /**
- * Keyboard event constant representing the numeric key
- * pad decimal key (value is (1&lt;&lt;24)+46).
- *
- * @since 3.0
- */
- public static final int KEYPAD_DECIMAL = KEYCODE_BIT + 46;
-
- /**
- * Keyboard event constant representing the numeric key
- * pad divide key (value is (1&lt;&lt;24)+47).
- *
- * @since 3.0
- */
- public static final int KEYPAD_DIVIDE = KEYCODE_BIT + 47;
-
- /**
- * Keyboard event constant representing the numeric key
- * pad zero key (value is (1&lt;&lt;24)+48).
- *
- * @since 3.0
- */
- public static final int KEYPAD_0 = KEYCODE_BIT + 48;
-
- /**
- * Keyboard event constant representing the numeric key
- * pad one key (value is (1&lt;&lt;24)+49).
- *
- * @since 3.0
- */
- public static final int KEYPAD_1 = KEYCODE_BIT + 49;
-
- /**
- * Keyboard event constant representing the numeric key
- * pad two key (value is (1&lt;&lt;24)+50).
- *
- * @since 3.0
- */
- public static final int KEYPAD_2 = KEYCODE_BIT + 50;
-
- /**
- * Keyboard event constant representing the numeric key
- * pad three key (value is (1&lt;&lt;24)+51).
- *
- * @since 3.0
- */
- public static final int KEYPAD_3 = KEYCODE_BIT + 51;
-
- /**
- * Keyboard event constant representing the numeric key
- * pad four key (value is (1&lt;&lt;24)+52).
- *
- * @since 3.0
- */
- public static final int KEYPAD_4 = KEYCODE_BIT + 52;
-
- /**
- * Keyboard event constant representing the numeric key
- * pad five key (value is (1&lt;&lt;24)+53).
- *
- * @since 3.0
- */
- public static final int KEYPAD_5 = KEYCODE_BIT + 53;
-
- /**
- * Keyboard event constant representing the numeric key
- * pad six key (value is (1&lt;&lt;24)+54).
- *
- * @since 3.0
- */
- public static final int KEYPAD_6 = KEYCODE_BIT + 54;
-
- /**
- * Keyboard event constant representing the numeric key
- * pad seven key (value is (1&lt;&lt;24)+55).
- *
- * @since 3.0
- */
- public static final int KEYPAD_7 = KEYCODE_BIT + 55;
-
- /**
- * Keyboard event constant representing the numeric key
- * pad eight key (value is (1&lt;&lt;24)+56).
- *
- * @since 3.0
- */
- public static final int KEYPAD_8 = KEYCODE_BIT + 56;
-
- /**
- * Keyboard event constant representing the numeric key
- * pad nine key (value is (1&lt;&lt;24)+57).
- *
- * @since 3.0
- */
- public static final int KEYPAD_9 = KEYCODE_BIT + 57;
-
- /**
- * Keyboard event constant representing the numeric key
- * pad equal key (value is (1&lt;&lt;24)+61).
- *
- * @since 3.0
- */
- public static final int KEYPAD_EQUAL = KEYCODE_BIT + 61;
-
- /**
- * Keyboard event constant representing the numeric key
- * pad enter key (value is (1&lt;&lt;24)+80).
- *
- * @since 3.0
- */
- public static final int KEYPAD_CR = KEYCODE_BIT + 80;
-
- /**
- * Keyboard event constant representing the help
- * key (value is (1&lt;&lt;24)+81).
- *
- * NOTE: The HELP key maps to the key labeled "help",
- * not "F1". If your keyboard does not have a HELP key,
- * you will never see this key press. To listen for
- * help on a control, use SWT.Help.
- *
- * @since 3.0
- *
- * @see SWT#Help
- */
- public static final int HELP = KEYCODE_BIT + 81;
-
- /**
- * Keyboard event constant representing the caps
- * lock key (value is (1&lt;&lt;24)+82).
- *
- * @since 3.0
- */
- public static final int CAPS_LOCK = KEYCODE_BIT + 82;
-
- /**
- * Keyboard event constant representing the num
- * lock key (value is (1&lt;&lt;24)+83).
- *
- * @since 3.0
- */
- public static final int NUM_LOCK = KEYCODE_BIT + 83;
-
- /**
- * Keyboard event constant representing the scroll
- * lock key (value is (1&lt;&lt;24)+84).
- *
- * @since 3.0
- */
- public static final int SCROLL_LOCK = KEYCODE_BIT + 84;
-
- /**
- * Keyboard event constant representing the pause
- * key (value is (1&lt;&lt;24)+85).
- *
- * @since 3.0
- */
- public static final int PAUSE = KEYCODE_BIT + 85;
-
- /**
- * Keyboard event constant representing the break
- * key (value is (1&lt;&lt;24)+86).
- *
- * @since 3.0
- */
- public static final int BREAK = KEYCODE_BIT + 86;
-
- /**
- * Keyboard event constant representing the print screen
- * key (value is (1&lt;&lt;24)+87).
- *
- * @since 3.0
- */
- public static final int PRINT_SCREEN = KEYCODE_BIT + 87;
-
- /**
- * The <code>MessageBox</code> style constant for error icon
- * behavior (value is 1).
- */
- public static final int ICON_ERROR = 1;
-
- /**
- * The <code>MessageBox</code> style constant for information icon
- * behavior (value is 1&lt;&lt;1).
- */
- public static final int ICON_INFORMATION = 1 << 1;
-
- /**
- * The <code>MessageBox</code> style constant for question icon
- * behavior (value is 1&lt;&lt;2).
- */
- public static final int ICON_QUESTION = 1 << 2;
-
- /**
- * The <code>MessageBox</code> style constant for warning icon
- * behavior (value is 1&lt;&lt;3).
- */
- public static final int ICON_WARNING = 1 << 3;
-
- /**
- * The <code>MessageBox</code> style constant for "working" icon
- * behavior (value is 1&lt;&lt;4).
- */
- public static final int ICON_WORKING = 1 << 4;
-
- /**
- * The style constant for "search" icon. This style constant is
- * used with <code>Text</code> in combination with <code>SWT.SEARCH
- * </code> (value is 1&lt;&lt;9).
- * <br>Note that this is a <em>HINT</em>.
- *
- * <p><b>Used By:</b><ul>
- * <li><code>Text</code></li>
- * </ul></p>
- *
- * @see #SEARCH
- * @see #ICON_CANCEL
- *
- * @since 3.5
- */
- public static final int ICON_SEARCH = 1 << 9;
-
- /**
- * The style constant for "cancel" icon. This style constant is
- * used with <code>Text</code> in combination with <code>SWT.SEARCH
- * </code> (value is 1&lt;&lt;8).
- * <br>Note that this is a <em>HINT</em>.
- *
- * <p><b>Used By:</b><ul>
- * <li><code>Text</code></li>
- * </ul></p>
- *
- * @see #SEARCH
- * @see #ICON_SEARCH
- *
- * @since 3.5
- */
- public static final int ICON_CANCEL = 1 << 8;
-
-
- /**
- * The <code>MessageBox</code> style constant for an OK button;
- * valid combinations are OK, OK|CANCEL
- * (value is 1&lt;&lt;5).
- */
- public static final int OK = 1 << 5;
-
- /**
- * The <code>MessageBox</code> style constant for YES button;
- * valid combinations are YES|NO, YES|NO|CANCEL
- * (value is 1&lt;&lt;6).
- */
- public static final int YES = 1 << 6;
-
- /**
- * The <code>MessageBox</code> style constant for NO button;
- * valid combinations are YES|NO, YES|NO|CANCEL
- * (value is 1&lt;&lt;7).
- */
- public static final int NO = 1 << 7;
-
- /**
- * The <code>MessageBox</code> style constant for a CANCEL button;
- * valid combinations are OK|CANCEL, YES|NO|CANCEL, RETRY|CANCEL
- * (value is 1&lt;&lt;8).
- *
- * <p><b>Used By:</b><ul>
- * <li><code>MessageBox</code></li>
- * </ul></p>
- */
- public static final int CANCEL = 1 << 8;
-
- /**
- * The <code>MessageBox</code> style constant for an ABORT button;
- * the only valid combination is ABORT|RETRY|IGNORE
- * (value is 1&lt;&lt;9).
- */
- public static final int ABORT = 1 << 9;
-
- /**
- * The <code>MessageBox</code> style constant for a RETRY button;
- * valid combinations are ABORT|RETRY|IGNORE, RETRY|CANCEL
- * (value is 1&lt;&lt;10).
- */
- public static final int RETRY = 1 << 10;
-
- /**
- * The <code>MessageBox</code> style constant for an IGNORE button;
- * the only valid combination is ABORT|RETRY|IGNORE
- * (value is 1&lt;&lt;11).
- */
- public static final int IGNORE = 1 << 11;
-
- /**
- * The <code>FileDialog</code> style constant for open file dialog behavior
- * (value is 1&lt;&lt;12).
- */
- public static final int OPEN = 1 << 12;
-
- /**
- * The <code>FileDialog</code> style constant for save file dialog behavior
- * (value is 1&lt;&lt;13).
- */
- public static final int SAVE = 1 << 13;
-
- /**
- * The <code>Composite</code> constant to indicate that
- * an attribute (such as background) is not inherited
- * by the children (value is 0).
- *
- * @since 3.2
- */
- public static final int INHERIT_NONE = 0;
-
- /**
- * The <code>Composite</code> constant to indicate that
- * an attribute (such as background) is inherited by
- * children who choose this value as their "default"
- * (value is 1). For example, a label child will
- * typically choose to inherit the background color
- * of a composite while a list or table will not.
- *
- * @since 3.2
- */
- public static final int INHERIT_DEFAULT = 1;
-
- /**
- * The <code>Composite</code> constant to indicate that
- * an attribute (such as background) is inherited by
- * all children.
- *
- * @since 3.2
- */
- public static final int INHERIT_FORCE = 2;
-
- /**
- * Default color white (value is 1).
- */
- public static final int COLOR_WHITE = 1;
-
- /**
- * Default color black (value is 2).
- */
- public static final int COLOR_BLACK = 2;
-
- /**
- * Default color red (value is 3).
- */
- public static final int COLOR_RED = 3;
-
- /**
- * Default color dark red (value is 4).
- */
- public static final int COLOR_DARK_RED = 4;
-
- /**
- * Default color green (value is 5).
- */
- public static final int COLOR_GREEN = 5;
-
- /**
- * Default color dark green (value is 6).
- */
- public static final int COLOR_DARK_GREEN = 6;
-
- /**
- * Default color yellow (value is 7).
- */
- public static final int COLOR_YELLOW = 7;
-
- /**
- * Default color dark yellow (value is 8).
- */
- public static final int COLOR_DARK_YELLOW = 8;
-
- /**
- * Default color blue (value is 9).
- */
- public static final int COLOR_BLUE = 9;
-
- /**
- * Default color dark blue (value is 10).
- */
- public static final int COLOR_DARK_BLUE = 10;
-
- /**
- * Default color magenta (value is 11).
- */
- public static final int COLOR_MAGENTA = 11;
-
- /**
- * Default color dark magenta (value is 12).
- */
- public static final int COLOR_DARK_MAGENTA = 12;
-
- /**
- * Default color cyan (value is 13).
- */
- public static final int COLOR_CYAN = 13;
-
- /**
- * Default color dark cyan (value is 14).
- */
- public static final int COLOR_DARK_CYAN = 14;
-
- /**
- * Default color gray (value is 15).
- */
- public static final int COLOR_GRAY = 15;
-
- /**
- * Default color dark gray (value is 16).
- */
- public static final int COLOR_DARK_GRAY = 16;
-
- /*
- * System Colors
- *
- * Dealing with system colors is an area where there are
- * many platform differences. On some platforms, system
- * colors can change dynamically while the program is
- * running. On other platforms, system colors can be
- * changed for all instances of a particular widget.
- * Therefore, the only truly portable method to obtain
- * a widget color query is to query the color from an
- * instance of the widget.
- *
- * It is expected that the list of supported colors
- * will grow over time.
- */
-
- /**
- * System color used to paint dark shadow areas (value is 17).
- */
- public static final int COLOR_WIDGET_DARK_SHADOW = 17;
-
- /**
- * System color used to paint normal shadow areas (value is 18).
- */
- public static final int COLOR_WIDGET_NORMAL_SHADOW = 18;
-
- /**
- * System color used to paint light shadow areas (value is 19).
- */
- public static final int COLOR_WIDGET_LIGHT_SHADOW = 19;
-
- /**
- * System color used to paint highlight shadow areas (value is 20).
- */
- public static final int COLOR_WIDGET_HIGHLIGHT_SHADOW = 20;
-
- /**
- * System color used to paint foreground areas (value is 21).
- */
- public static final int COLOR_WIDGET_FOREGROUND = 21;
-
- /**
- * System color used to paint background areas (value is 22).
- */
- public static final int COLOR_WIDGET_BACKGROUND = 22;
-
- /**
- * System color used to paint border areas (value is 23).
- */
- public static final int COLOR_WIDGET_BORDER = 23;
-
- /**
- * System color used to paint list foreground areas (value is 24).
- */
- public static final int COLOR_LIST_FOREGROUND = 24;
-
- /**
- * System color used to paint list background areas (value is 25).
- */
- public static final int COLOR_LIST_BACKGROUND = 25;
-
- /**
- * System color used to paint list selection background areas (value is 26).
- */
- public static final int COLOR_LIST_SELECTION = 26;
-
- /**
- * System color used to paint list selected text (value is 27).
- */
- public static final int COLOR_LIST_SELECTION_TEXT = 27;
-
- /**
- * System color used to paint tooltip text (value is 28).
- */
- public static final int COLOR_INFO_FOREGROUND = 28;
-
- /**
- * System color used to paint tooltip background areas (value is 29).
- */
- public static final int COLOR_INFO_BACKGROUND = 29;
-
- /**
- * System color used to paint title text (value is 30).
- */
- public static final int COLOR_TITLE_FOREGROUND = 30;
-
- /**
- * System color used to paint title background areas (value is 31).
- */
- public static final int COLOR_TITLE_BACKGROUND = 31;
-
- /**
- * System color used to paint title background gradient (value is 32).
- */
- public static final int COLOR_TITLE_BACKGROUND_GRADIENT = 32;
-
- /**
- * System color used to paint inactive title text (value is 33).
- */
- public static final int COLOR_TITLE_INACTIVE_FOREGROUND = 33;
-
- /**
- * System color used to paint inactive title background areas (value is 34).
- */
- public static final int COLOR_TITLE_INACTIVE_BACKGROUND = 34;
-
- /**
- * System color used to paint inactive title background gradient (value is 35).
- */
- public static final int COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT = 35;
-
- /**
- * Draw constant indicating whether the drawing operation
- * should fill the background (value is 1&lt;&lt;0).
- */
- public static final int DRAW_TRANSPARENT = 1 << 0;
-
- /**
- * Draw constant indicating whether the string drawing operation
- * should handle line-delimiters (value is 1&lt;&lt;1).
- */
- public static final int DRAW_DELIMITER = 1 << 1;
-
- /**
- * Draw constant indicating whether the string drawing operation
- * should expand TAB characters (value is 1&lt;&lt;2).
- */
- public static final int DRAW_TAB = 1 << 2;
-
- /**
- * Draw constant indicating whether the string drawing operation
- * should handle mnemonics (value is 1&lt;&lt;3).
- */
- public static final int DRAW_MNEMONIC = 1 << 3;
-
-
- /**
- * Selection constant indicating that a line delimiter should be
- * drawn (value is 1&lt;&lt;17).
- *
- * <p><b>Used By:</b><ul>
- * <li><code>TextLayout</code></li>
- * </ul></p>
- *
- * @see #FULL_SELECTION
- * @see #LAST_LINE_SELECTION
- *
- * @since 3.3
- */
- public static final int DELIMITER_SELECTION = 1 << 17;
-
- /**
- * Selection constant indicating that the last line is selected
- * to the end and should be drawn using either a line delimiter
- * or full line selection (value is 1&lt;&lt;20).
- *
- * <p><b>Used By:</b><ul>
- * <li><code>TextLayout</code></li>
- * </ul></p>
- *
- * @see #DELIMITER_SELECTION
- * @see #FULL_SELECTION
- *
- * @since 3.3
- */
- public static final int LAST_LINE_SELECTION = 1 << 20;
-
- /**
- * SWT error constant indicating that no error number was specified
- * (value is 1).
- */
- public static final int ERROR_UNSPECIFIED = 1;
-
- /**
- * SWT error constant indicating that no more handles for an
- * operating system resource are available
- * (value is 2).
- */
- public static final int ERROR_NO_HANDLES = 2;
-
- /**
- * SWT error constant indicating that no more callback resources are available
- * (value is 3).
- */
- public static final int ERROR_NO_MORE_CALLBACKS = 3;
-
- /**
- * SWT error constant indicating that a null argument was passed in
- * (value is 4).
- */
- public static final int ERROR_NULL_ARGUMENT = 4;
-
- /**
- * SWT error constant indicating that an invalid argument was passed in
- * (value is 5).
- */
- public static final int ERROR_INVALID_ARGUMENT = 5;
-
- /**
- * SWT error constant indicating that a value was found to be
- * outside the allowable range
- * (value is 6).
- */
- public static final int ERROR_INVALID_RANGE = 6;
-
- /**
- * SWT error constant indicating that a value which can not be
- * zero was found to be
- * (value is 7).
- */
- public static final int ERROR_CANNOT_BE_ZERO = 7;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to provide the value of an item
- * (value is 8).
- */
- public static final int ERROR_CANNOT_GET_ITEM = 8;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to provide the selection
- * (value is 9).
- */
- public static final int ERROR_CANNOT_GET_SELECTION = 9;
-
- /**
- * SWT error constant indicating that the matrix is not invertible
- * (value is 10).
- *
- * @since 3.1
- */
- public static final int ERROR_CANNOT_INVERT_MATRIX = 10;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to provide the height of an item
- * (value is 11).
- */
- public static final int ERROR_CANNOT_GET_ITEM_HEIGHT = 11;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to provide the text of a widget
- * (value is 12).
- */
- public static final int ERROR_CANNOT_GET_TEXT = 12;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to set the text of a widget
- * (value is 13).
- */
- public static final int ERROR_CANNOT_SET_TEXT = 13;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to add an item
- * (value is 14).
- */
- public static final int ERROR_ITEM_NOT_ADDED = 14;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to remove an item
- * (value is 15).
- */
- public static final int ERROR_ITEM_NOT_REMOVED = 15;
-
- /**
- * SWT error constant indicating that the graphics library
- * is not available
- * (value is 16).
- */
- public static final int ERROR_NO_GRAPHICS_LIBRARY = 16;
-
- /**
- * SWT error constant indicating that a particular feature has
- * not been implemented on this platform
- * (value is 20).
- */
- public static final int ERROR_NOT_IMPLEMENTED = 20;
-
- /**
- * SWT error constant indicating that a menu which needed
- * to have the drop down style had some other style instead
- * (value is 21).
- */
- public static final int ERROR_MENU_NOT_DROP_DOWN = 21;
-
- /**
- * SWT error constant indicating that an attempt was made to
- * invoke an SWT operation which can only be executed by the
- * user-interface thread from some other thread
- * (value is 22).
- */
- public static final int ERROR_THREAD_INVALID_ACCESS = 22;
-
- /**
- * SWT error constant indicating that an attempt was made to
- * invoke an SWT operation using a widget which had already
- * been disposed
- * (value is 24).
- */
- public static final int ERROR_WIDGET_DISPOSED = 24;
-
- /**
- * SWT error constant indicating that a menu item which needed
- * to have the cascade style had some other style instead
- * (value is 27).
- */
- public static final int ERROR_MENUITEM_NOT_CASCADE = 27;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to set the selection of a widget
- * (value is 28).
- */
- public static final int ERROR_CANNOT_SET_SELECTION = 28;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to set the menu
- * (value is 29).
- */
- public static final int ERROR_CANNOT_SET_MENU = 29;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to set the enabled state
- * (value is 30).
- */
- public static final int ERROR_CANNOT_SET_ENABLED = 30;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to provide enabled/disabled state information
- * (value is 31).
- */
- public static final int ERROR_CANNOT_GET_ENABLED = 31;
-
- /**
- * SWT error constant indicating that a provided widget can
- * not be used as a parent in the current operation
- * (value is 32).
- */
- public static final int ERROR_INVALID_PARENT = 32;
-
- /**
- * SWT error constant indicating that a menu which needed
- * to have the menu bar style had some other style instead
- * (value is 33).
- */
- public static final int ERROR_MENU_NOT_BAR = 33;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to provide count information
- * (value is 36).
- */
- public static final int ERROR_CANNOT_GET_COUNT = 36;
-
- /**
- * SWT error constant indicating that a menu which needed
- * to have the pop up menu style had some other style instead
- * (value is 37).
- */
- public static final int ERROR_MENU_NOT_POP_UP = 37;
-
- /**
- * SWT error constant indicating that a graphics operation
- * was attempted with an image of an unsupported depth
- * (value is 38).
- */
- public static final int ERROR_UNSUPPORTED_DEPTH = 38;
-
- /**
- * SWT error constant indicating that an input/output operation
- * failed during the execution of an SWT operation
- * (value is 39).
- */
- public static final int ERROR_IO = 39;
-
- /**
- * SWT error constant indicating that a graphics operation
- * was attempted with an image having an invalid format
- * (value is 40).
- */
- public static final int ERROR_INVALID_IMAGE = 40;
-
- /**
- * SWT error constant indicating that a graphics operation
- * was attempted with an image having a valid but unsupported
- * format
- * (value is 42).
- */
- public static final int ERROR_UNSUPPORTED_FORMAT = 42;
-
- /**
- * SWT error constant indicating that an attempt was made
- * to subclass an SWT widget class without implementing the
- * <code>checkSubclass()</code> method
- * (value is 43).
- *
- * For additional information see the comment in
- * <code>Widget.checkSubclass()</code>.
- *
- * @see org.eclipse.swt.widgets.Widget#checkSubclass
- */
- public static final int ERROR_INVALID_SUBCLASS = 43;
-
- /**
- * SWT error constant indicating that an attempt was made to
- * invoke an SWT operation using a graphics object which had
- * already been disposed
- * (value is 44).
- */
- public static final int ERROR_GRAPHIC_DISPOSED = 44;
-
- /**
- * SWT error constant indicating that an attempt was made to
- * invoke an SWT operation using a device which had already
- * been disposed
- * (value is 45).
- */
- public static final int ERROR_DEVICE_DISPOSED = 45;
-
- /**
- * SWT error constant indicating that an exception happened
- * when executing a runnable
- * (value is 46).
- */
- public static final int ERROR_FAILED_EXEC = 46;
-
- /**
- * SWT error constant indicating that an unsatisfied link
- * error occurred while attempting to load a library
- * (value is 47).
- *
- * @since 3.1
- */
- public static final int ERROR_FAILED_LOAD_LIBRARY = 47;
-
- /**
- * SWT error constant indicating that a font is not valid
- * (value is 48).
- *
- * @since 3.1
- */
- public static final int ERROR_INVALID_FONT = 48;
-
- /**
- * SWT error constant indicating that an attempt was made to
- * use an BrowserFunction object which had already been disposed
- * (value is 49).
- *
- * @since 3.5
- */
- public static final int ERROR_FUNCTION_DISPOSED = 49;
-
- /**
- * SWT error constant indicating that an exception happened
- * when evaluating a javascript expression
- * (value is 50).
- *
- * @since 3.5
- */
- public static final int ERROR_FAILED_EVALUATE = 50;
-
- /**
- * SWT error constant indicating that an invalid value was returned
- * (value is 51).
- *
- * @since 3.5
- */
- public static final int ERROR_INVALID_RETURN_VALUE = 51;
-
- /**
- * Constant indicating that an image or operation is of type bitmap (value is 0).
- */
- public static final int BITMAP = 0;
-
- /**
- * Constant indicating that an image or operation is of type icon (value is 1).
- */
- public static final int ICON = 1;
-
- /**
- * The <code>Image</code> constructor argument indicating that
- * the new image should be a copy of the image provided as
- * an argument (value is 0).
- */
- public static final int IMAGE_COPY = 0;
-
- /**
- * The <code>Image</code> constructor argument indicating that
- * the new image should have the appearance of a "disabled"
- * (using the platform's rules for how this should look)
- * copy of the image provided as an argument (value is 1).
- */
- public static final int IMAGE_DISABLE = 1;
-
- /**
- * The <code>Image</code> constructor argument indicating that
- * the new image should have the appearance of a "gray scaled"
- * copy of the image provided as an argument (value is 2).
- */
- public static final int IMAGE_GRAY = 2;
-
- /**
- * Constant to indicate an error state (value is 1).
- * <p><b>Used By:</b><ul>
- * <li><code>ProgressBar</code></li>
- * </ul></p>
- *
- * @since 3.4
- */
- public static final int ERROR = 1;
-
- /**
- * Constant to a indicate a paused state (value is 4).
- * <p><b>Used By:</b><ul>
- * <li><code>ProgressBar</code></li>
- * </ul></p>
- *
- * @since 3.4
- */
- public static final int PAUSED = 1 << 2;
-
- /**
- * The font style constant indicating a normal weight, non-italic font
- * (value is 0). This constant is also used with <code>ProgressBar</code>
- * to indicate a normal state.
- * <p><b>Used By:</b><ul>
- * <li><code>ProgressBar</code></li>
- * </ul></p>
- */
- public static final int NORMAL = 0;
-
- /**
- * The font style constant indicating a bold weight font
- * (value is 1&lt;&lt;0).
- */
- public static final int BOLD = 1 << 0;
-
- /**
- * The font style constant indicating an italic font
- * (value is 1&lt;&lt;1).
- */
- public static final int ITALIC = 1 << 1;
-
- /**
- * System arrow cursor (value is 0).
- */
- public static final int CURSOR_ARROW = 0;
-
- /**
- * System wait cursor (value is 1).
- */
- public static final int CURSOR_WAIT = 1;
-
- /**
- * System cross hair cursor (value is 2).
- */
- public static final int CURSOR_CROSS = 2;
-
- /**
- * System app startup cursor (value is 3).
- */
- public static final int CURSOR_APPSTARTING = 3;
-
- /**
- * System help cursor (value is 4).
- */
- public static final int CURSOR_HELP = 4;
-
- /**
- * System resize all directions cursor (value is 5).
- */
- public static final int CURSOR_SIZEALL = 5;
-
- /**
- * System resize north-east-south-west cursor (value is 6).
- */
- public static final int CURSOR_SIZENESW = 6;
-
- /**
- * System resize north-south cursor (value is 7).
- */
- public static final int CURSOR_SIZENS = 7;
-
- /**
- * System resize north-west-south-east cursor (value is 8).
- */
- public static final int CURSOR_SIZENWSE = 8;
-
- /**
- * System resize west-east cursor (value is 9).
- */
- public static final int CURSOR_SIZEWE = 9;
-
- /**
- * System resize north cursor (value is 10).
- */
- public static final int CURSOR_SIZEN = 10;
-
- /**
- * System resize south cursor (value is 11).
- */
- public static final int CURSOR_SIZES = 11;
-
- /**
- * System resize east cursor (value is 12).
- */
- public static final int CURSOR_SIZEE = 12;
-
- /**
- * System resize west cursor (value is 13).
- */
- public static final int CURSOR_SIZEW = 13;
-
- /**
- * System resize north-east cursor (value is 14).
- */
- public static final int CURSOR_SIZENE = 14;
-
- /**
- * System resize south-east cursor (value is 15).
- */
- public static final int CURSOR_SIZESE = 15;
-
- /**
- * System resize south-west cursor (value is 16).
- */
- public static final int CURSOR_SIZESW = 16;
-
- /**
- * System resize north-west cursor (value is 17).
- */
- public static final int CURSOR_SIZENW = 17;
-
- /**
- * System up arrow cursor (value is 18).
- */
- public static final int CURSOR_UPARROW = 18;
-
- /**
- * System i-beam cursor (value is 19).
- */
- public static final int CURSOR_IBEAM = 19;
-
- /**
- * System "not allowed" cursor (value is 20).
- */
- public static final int CURSOR_NO = 20;
-
- /**
- * System hand cursor (value is 21).
- */
- public static final int CURSOR_HAND = 21;
-
- /**
- * Line drawing style for flat end caps (value is 1).
- *
- * @see org.eclipse.swt.graphics.GC#setLineCap(int)
- * @see org.eclipse.swt.graphics.GC#getLineCap()
- *
- * @since 3.1
- */
- public static final int CAP_FLAT = 1;
-
- /**
- * Line drawing style for rounded end caps (value is 2).
- *
- * @see org.eclipse.swt.graphics.GC#setLineCap(int)
- * @see org.eclipse.swt.graphics.GC#getLineCap()
- *
- * @since 3.1
- */
- public static final int CAP_ROUND = 2;
-
- /**
- * Line drawing style for square end caps (value is 3).
- *
- * @see org.eclipse.swt.graphics.GC#setLineCap(int)
- * @see org.eclipse.swt.graphics.GC#getLineCap()
- *
- * @since 3.1
- */
- public static final int CAP_SQUARE = 3;
-
- /**
- * Line drawing style for miter joins (value is 1).
- *
- * @see org.eclipse.swt.graphics.GC#setLineJoin(int)
- * @see org.eclipse.swt.graphics.GC#getLineJoin()
- *
- * @since 3.1
- */
- public static final int JOIN_MITER = 1;
-
- /**
- * Line drawing style for rounded joins (value is 2).
- *
- * @see org.eclipse.swt.graphics.GC#setLineJoin(int)
- * @see org.eclipse.swt.graphics.GC#getLineJoin()
- *
- * @since 3.1
- */
- public static final int JOIN_ROUND = 2;
-
- /**
- * Line drawing style for bevel joins (value is 3).
- *
- * @see org.eclipse.swt.graphics.GC#setLineJoin(int)
- * @see org.eclipse.swt.graphics.GC#getLineJoin()
- *
- * @since 3.1
- */
- public static final int JOIN_BEVEL = 3;
-
- /**
- * Line drawing style for solid lines (value is 1).
- */
- public static final int LINE_SOLID = 1;
-
- /**
- * Line drawing style for dashed lines (value is 2).
- */
- public static final int LINE_DASH = 2;
-
- /**
- * Line drawing style for dotted lines (value is 3).
- */
- public static final int LINE_DOT = 3;
-
- /**
- * Line drawing style for alternating dash-dot lines (value is 4).
- */
- public static final int LINE_DASHDOT = 4;
-
- /**
- * Line drawing style for dash-dot-dot lines (value is 5).
- */
- public static final int LINE_DASHDOTDOT = 5;
-
- /**
- * Line drawing style for custom dashed lines (value is 6).
- *
- * @see org.eclipse.swt.graphics.GC#setLineDash(int[])
- * @see org.eclipse.swt.graphics.GC#getLineDash()
- *
- * @since 3.1
- */
- public static final int LINE_CUSTOM = 6;
-
- /**
- * Path constant that represents a "move to" operation (value is 1).
- *
- * @since 3.1
- */
- public static final int PATH_MOVE_TO = 1;
-
- /**
- * Path constant that represents a "line to" operation (value is 2).
- *
- * @since 3.1
- */
- public static final int PATH_LINE_TO = 2;
-
- /**
- * Path constant that represents a "quadratic curve to" operation (value is 3).
- *
- * @since 3.1
- */
- public static final int PATH_QUAD_TO = 3;
-
- /**
- * Path constant that represents a "cubic curve to" operation (value is 4).
- *
- * @since 3.1
- */
- public static final int PATH_CUBIC_TO = 4;
-
- /**
- * Path constant that represents a "close" operation (value is 5).
- *
- * @since 3.1
- */
- public static final int PATH_CLOSE = 5;
-
- /**
- * Even odd rule for filling operations (value is 1).
- *
- * @since 3.1
- */
- public static final int FILL_EVEN_ODD = 1;
-
- /**
- * Winding rule for filling operations (value is 2).
- *
- * @since 3.1
- */
- public static final int FILL_WINDING = 2;
-
- /**
- * Image format constant indicating an unknown image type (value is -1).
- */
- public static final int IMAGE_UNDEFINED = -1;
-
- /**
- * Image format constant indicating a Windows BMP format image (value is 0).
- */
- public static final int IMAGE_BMP = 0;
-
- /**
- * Image format constant indicating a run-length encoded
- * Windows BMP format image (value is 1).
- */
- public static final int IMAGE_BMP_RLE = 1;
-
- /**
- * Image format constant indicating a GIF format image (value is 2).
- */
- public static final int IMAGE_GIF = 2;
-
- /**
- * Image format constant indicating a ICO format image (value is 3).
- */
- public static final int IMAGE_ICO = 3;
-
- /**
- * Image format constant indicating a JPEG format image (value is 4).
- */
- public static final int IMAGE_JPEG = 4;
-
- /**
- * Image format constant indicating a PNG format image (value is 5).
- */
- public static final int IMAGE_PNG = 5;
-
- /**
- * Image format constant indicating a TIFF format image (value is 6).
- */
- public static final int IMAGE_TIFF = 6;
-
- /**
- * Image format constant indicating an OS/2 BMP format image (value is 7).
- */
- public static final int IMAGE_OS2_BMP = 7;
-
- /**
- * GIF image disposal method constants indicating that the
- * disposal method is unspecified (value is 0).
- */
- public static final int DM_UNSPECIFIED = 0x0;
-
- /**
- * GIF image disposal method constants indicating that the
- * disposal method is to do nothing; that is, to leave the
- * previous image in place (value is 1).
- */
- public static final int DM_FILL_NONE = 0x1;
-
- /**
- * GIF image disposal method constants indicating that the
- * the previous images should be covered with the background
- * color before displaying the next image (value is 2).
- */
- public static final int DM_FILL_BACKGROUND = 0x2;
-
- /**
- * GIF image disposal method constants indicating that the
- * disposal method is to restore the previous picture
- * (value is 3).
- */
- public static final int DM_FILL_PREVIOUS = 0x3;
-
- /**
- * Image transparency constant indicating that the image
- * contains no transparency information (value is 0).
- */
- public static final int TRANSPARENCY_NONE = 0x0;
-
- /**
- * Image transparency constant indicating that the image
- * contains alpha transparency information (value is 1&lt;&lt;0).
- */
- public static final int TRANSPARENCY_ALPHA = 1 << 0;
-
- /**
- * Image transparency constant indicating that the image
- * contains a transparency mask (value is 1&lt;&lt;1).
- */
- public static final int TRANSPARENCY_MASK = 1 << 1;
-
- /**
- * Image transparency constant indicating that the image
- * contains a transparent pixel (value is 1&lt;&lt;2).
- */
- public static final int TRANSPARENCY_PIXEL = 1 << 2;
-
- /**
- * The character movement type (value is 1&lt;&lt;0).
- * This constant is used to move a text offset over a character.
- *
- * @see org.eclipse.swt.graphics.TextLayout#getNextOffset(int, int)
- * @see org.eclipse.swt.graphics.TextLayout#getPreviousOffset(int, int)
- *
- * @since 3.0
- */
- public static final int MOVEMENT_CHAR = 1 << 0;
-
- /**
- * The cluster movement type (value is 1&lt;&lt;1).
- * This constant is used to move a text offset over a cluster.
- * A cluster groups one or more characters. A cluster is
- * undivisible, this means that a caret offset can not be placed in the
- * middle of a cluster.
- *
- * @see org.eclipse.swt.graphics.TextLayout#getNextOffset(int, int)
- * @see org.eclipse.swt.graphics.TextLayout#getPreviousOffset(int, int)
- *
- * @since 3.0
- */
- public static final int MOVEMENT_CLUSTER = 1 << 1;
-
- /**
- * The word movement type (value is 1&lt;&lt;2).
- * This constant is used to move a text offset over a word.
- * The behavior of this constant depends on the platform and on the
- * direction of the movement. For example, on Windows the stop is
- * always at the start of the word. On GTK and Mac the stop is at the end
- * of the word if the direction is next and at the start of the word if the
- * direction is previous.
- *
- * @see org.eclipse.swt.graphics.TextLayout#getNextOffset(int, int)
- * @see org.eclipse.swt.graphics.TextLayout#getPreviousOffset(int, int)
- *
- * @since 3.0
- */
- public static final int MOVEMENT_WORD = 1 << 2;
-
- /**
- * The word end movement type (value is 1&lt;&lt;3).
- * This constant is used to move a text offset to the next or previous
- * word end. The behavior of this constant does not depend on the platform.
- *
- *
- * @see org.eclipse.swt.graphics.TextLayout#getNextOffset(int, int)
- * @see org.eclipse.swt.graphics.TextLayout#getPreviousOffset(int, int)
- *
- * @since 3.3
- */
- public static final int MOVEMENT_WORD_END = 1 << 3;
-
- /**
- * The word start movement type (value is 1&lt;&lt;4).
- * This constant is used to move a text offset to the next or previous
- * word start. The behavior of this constant does not depend on the platform.
- *
- * @see org.eclipse.swt.graphics.TextLayout#getNextOffset(int, int)
- * @see org.eclipse.swt.graphics.TextLayout#getPreviousOffset(int, int)
- *
- * @since 3.3
- */
- public static final int MOVEMENT_WORD_START = 1 << 4;
-
-
-/**
- * Answers a concise, human readable description of the error code.
- *
- * @param code the SWT error code.
- * @return a description of the error code.
- *
- * @see SWT
- */
-static String findErrorText (int code) {
- switch (code) {
- case ERROR_UNSPECIFIED: return "Unspecified error"; //$NON-NLS-1$
- case ERROR_NO_HANDLES: return "No more handles"; //$NON-NLS-1$
- case ERROR_NO_MORE_CALLBACKS: return "No more callbacks"; //$NON-NLS-1$
- case ERROR_NULL_ARGUMENT: return "Argument cannot be null"; //$NON-NLS-1$
- case ERROR_INVALID_ARGUMENT: return "Argument not valid"; //$NON-NLS-1$
- case ERROR_INVALID_RETURN_VALUE: return "Return value not valid"; //$NON-NLS-1$
- case ERROR_INVALID_RANGE: return "Index out of bounds"; //$NON-NLS-1$
- case ERROR_CANNOT_BE_ZERO: return "Argument cannot be zero"; //$NON-NLS-1$
- case ERROR_CANNOT_GET_ITEM: return "Cannot get item"; //$NON-NLS-1$
- case ERROR_CANNOT_GET_SELECTION: return "Cannot get selection"; //$NON-NLS-1$
- case ERROR_CANNOT_GET_ITEM_HEIGHT: return "Cannot get item height"; //$NON-NLS-1$
- case ERROR_CANNOT_GET_TEXT: return "Cannot get text"; //$NON-NLS-1$
- case ERROR_CANNOT_SET_TEXT: return "Cannot set text"; //$NON-NLS-1$
- case ERROR_ITEM_NOT_ADDED: return "Item not added"; //$NON-NLS-1$
- case ERROR_ITEM_NOT_REMOVED: return "Item not removed"; //$NON-NLS-1$
- case ERROR_NOT_IMPLEMENTED: return "Not implemented"; //$NON-NLS-1$
- case ERROR_MENU_NOT_DROP_DOWN: return "Menu must be a drop down"; //$NON-NLS-1$
- case ERROR_THREAD_INVALID_ACCESS: return "Invalid thread access"; //$NON-NLS-1$
- case ERROR_WIDGET_DISPOSED: return "Widget is disposed"; //$NON-NLS-1$
- case ERROR_MENUITEM_NOT_CASCADE: return "Menu item is not a CASCADE"; //$NON-NLS-1$
- case ERROR_CANNOT_SET_SELECTION: return "Cannot set selection"; //$NON-NLS-1$
- case ERROR_CANNOT_SET_MENU: return "Cannot set menu"; //$NON-NLS-1$
- case ERROR_CANNOT_SET_ENABLED: return "Cannot set the enabled state"; //$NON-NLS-1$
- case ERROR_CANNOT_GET_ENABLED: return "Cannot get the enabled state"; //$NON-NLS-1$
- case ERROR_INVALID_PARENT: return "Widget has the wrong parent"; //$NON-NLS-1$
- case ERROR_MENU_NOT_BAR: return "Menu is not a BAR"; //$NON-NLS-1$
- case ERROR_CANNOT_GET_COUNT: return "Cannot get count"; //$NON-NLS-1$
- case ERROR_MENU_NOT_POP_UP: return "Menu is not a POP_UP"; //$NON-NLS-1$
- case ERROR_UNSUPPORTED_DEPTH: return "Unsupported color depth"; //$NON-NLS-1$
- case ERROR_IO: return "i/o error"; //$NON-NLS-1$
- case ERROR_INVALID_IMAGE: return "Invalid image"; //$NON-NLS-1$
- case ERROR_UNSUPPORTED_FORMAT: return "Unsupported or unrecognized format"; //$NON-NLS-1$
- case ERROR_INVALID_SUBCLASS: return "Subclassing not allowed"; //$NON-NLS-1$
- case ERROR_GRAPHIC_DISPOSED: return "Graphic is disposed"; //$NON-NLS-1$
- case ERROR_DEVICE_DISPOSED: return "Device is disposed"; //$NON-NLS-1$
- case ERROR_FUNCTION_DISPOSED: return "BrowserFunction is disposed"; //$NON-NLS-1$
- case ERROR_FAILED_EXEC: return "Failed to execute runnable"; //$NON-NLS-1$
- case ERROR_FAILED_EVALUATE: return "Failed to evaluate javascript expression"; //$NON-NLS-1$
- case ERROR_FAILED_LOAD_LIBRARY: return "Unable to load library"; //$NON-NLS-1$
- case ERROR_CANNOT_INVERT_MATRIX: return "Cannot invert matrix"; //$NON-NLS-1$
- case ERROR_NO_GRAPHICS_LIBRARY: return "Unable to load graphics library"; //$NON-NLS-1$
- case ERROR_INVALID_FONT: return "Font not valid"; //$NON-NLS-1$
- }
- return "Unknown error"; //$NON-NLS-1$
-}
-
-/**
- * Returns the NLS'ed message for the given argument.
- *
- * @param key the key to look up
- * @return the message for the given key
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- */
-public static String getMessage(String key) {
- return Compatibility.getMessage(key);
-}
-
-/**
- * Returns the SWT platform name.
- * Examples: "win32", "motif", "gtk", "photon", "carbon", "cocoa", "wpf"
- *
- * @return the SWT platform name
- */
-public static String getPlatform () {
- return Platform.PLATFORM;
-}
-
-/**
- * Returns the SWT version number as an integer.
- * Example: "SWT051" == 51
- *
- * @return the SWT version number
- */
-public static int getVersion () {
- return Library.SWT_VERSION;
-}
-
-/**
- * Throws an appropriate exception based on the passed in error code.
- *
- * @param code the SWT error code
- */
-public static void error (int code) {
- error (code, null);
-}
-
-/**
- * Throws an appropriate exception based on the passed in error code.
- * The <code>throwable</code> argument should be either null, or the
- * throwable which caused SWT to throw an exception.
- * <p>
- * In SWT, errors are reported by throwing one of three exceptions:
- * <dl>
- * <dd>java.lang.IllegalArgumentException</dd>
- * <dt>thrown whenever one of the API methods is invoked with an illegal argument</dt>
- * <dd>org.eclipse.swt.SWTException (extends java.lang.RuntimeException)</dd>
- * <dt>thrown whenever a recoverable error happens internally in SWT</dt>
- * <dd>org.eclipse.swt.SWTError (extends java.lang.Error)</dd>
- * <dt>thrown whenever a <b>non-recoverable</b> error happens internally in SWT</dt>
- * </dl>
- * This method provides the logic which maps between error codes
- * and one of the above exceptions.
- * </p>
- *
- * @param code the SWT error code.
- * @param throwable the exception which caused the error to occur.
- *
- * @see SWTError
- * @see SWTException
- * @see IllegalArgumentException
- */
-public static void error (int code, Throwable throwable) {
- error (code, throwable, null);
-}
-
-/**
- * Throws an appropriate exception based on the passed in error code.
- * The <code>throwable</code> argument should be either null, or the
- * throwable which caused SWT to throw an exception.
- * <p>
- * In SWT, errors are reported by throwing one of three exceptions:
- * <dl>
- * <dd>java.lang.IllegalArgumentException</dd>
- * <dt>thrown whenever one of the API methods is invoked with an illegal argument</dt>
- * <dd>org.eclipse.swt.SWTException (extends java.lang.RuntimeException)</dd>
- * <dt>thrown whenever a recoverable error happens internally in SWT</dt>
- * <dd>org.eclipse.swt.SWTError (extends java.lang.Error)</dd>
- * <dt>thrown whenever a <b>non-recoverable</b> error happens internally in SWT</dt>
- * </dl>
- * This method provides the logic which maps between error codes
- * and one of the above exceptions.
- * </p>
- *
- * @param code the SWT error code.
- * @param throwable the exception which caused the error to occur.
- * @param detail more information about error.
- *
- * @see SWTError
- * @see SWTException
- * @see IllegalArgumentException
- *
- * @since 3.0
- */
-public static void error (int code, Throwable throwable, String detail) {
-
- /*
- * This code prevents the creation of "chains" of SWTErrors and
- * SWTExceptions which in turn contain other SWTErrors and
- * SWTExceptions as their throwable. This can occur when low level
- * code throws an exception past a point where a higher layer is
- * being "safe" and catching all exceptions. (Note that, this is
- * _a_bad_thing_ which we always try to avoid.)
- *
- * On the theory that the low level code is closest to the
- * original problem, we simply re-throw the original exception here.
- *
- * NOTE: Exceptions thrown in syncExec and asyncExec must be
- * wrapped.
- */
- if (code != SWT.ERROR_FAILED_EXEC) {
- if (throwable instanceof SWTError) throw (SWTError) throwable;
- if (throwable instanceof SWTException) throw (SWTException) throwable;
- }
-
- String message = findErrorText (code);
- if (detail != null) message += detail;
- switch (code) {
-
- /* Illegal Arguments (non-fatal) */
- case ERROR_NULL_ARGUMENT:
- case ERROR_CANNOT_BE_ZERO:
- case ERROR_INVALID_ARGUMENT:
- case ERROR_MENU_NOT_BAR:
- case ERROR_MENU_NOT_DROP_DOWN:
- case ERROR_MENU_NOT_POP_UP:
- case ERROR_MENUITEM_NOT_CASCADE:
- case ERROR_INVALID_PARENT:
- case ERROR_INVALID_RANGE: {
- throw new IllegalArgumentException (message);
- }
-
- /* SWT Exceptions (non-fatal) */
- case ERROR_INVALID_SUBCLASS:
- case ERROR_THREAD_INVALID_ACCESS:
- case ERROR_WIDGET_DISPOSED:
- case ERROR_GRAPHIC_DISPOSED:
- case ERROR_DEVICE_DISPOSED:
- case ERROR_FUNCTION_DISPOSED:
- case ERROR_INVALID_IMAGE:
- case ERROR_UNSUPPORTED_DEPTH:
- case ERROR_UNSUPPORTED_FORMAT:
- case ERROR_FAILED_EXEC:
- case ERROR_FAILED_EVALUATE:
- case ERROR_CANNOT_INVERT_MATRIX:
- case ERROR_NO_GRAPHICS_LIBRARY:
- case ERROR_INVALID_RETURN_VALUE:
- case ERROR_IO: {
- SWTException exception = new SWTException (code, message);
- exception.throwable = throwable;
- throw exception;
- }
-
- /* Operation System Errors (fatal, may occur only on some platforms) */
- case ERROR_CANNOT_GET_COUNT:
- case ERROR_CANNOT_GET_ENABLED:
- case ERROR_CANNOT_GET_ITEM:
- case ERROR_CANNOT_GET_ITEM_HEIGHT:
- case ERROR_CANNOT_GET_SELECTION:
- case ERROR_CANNOT_GET_TEXT:
- case ERROR_CANNOT_SET_ENABLED:
- case ERROR_CANNOT_SET_MENU:
- case ERROR_CANNOT_SET_SELECTION:
- case ERROR_CANNOT_SET_TEXT:
- case ERROR_ITEM_NOT_ADDED:
- case ERROR_ITEM_NOT_REMOVED:
- case ERROR_NO_HANDLES:
- //FALL THROUGH
-
- /* SWT Errors (fatal, may occur only on some platforms) */
- case ERROR_FAILED_LOAD_LIBRARY:
- case ERROR_NO_MORE_CALLBACKS:
- case ERROR_NOT_IMPLEMENTED:
- case ERROR_UNSPECIFIED: {
- SWTError error = new SWTError (code, message);
- error.throwable = throwable;
- throw error;
- }
- }
-
- /* Unknown/Undefined Error */
- SWTError error = new SWTError (code, message);
- error.throwable = throwable;
- throw error;
-}
-
-static {
- /*
- * These values represent bit masks that may need to
- * expand in the future. Therefore they are not initialized
- * in the declaration to stop the compiler from inlining.
- */
- BUTTON_MASK = BUTTON1 | BUTTON2 | BUTTON3 | BUTTON4 | BUTTON5;
- MODIFIER_MASK = ALT | SHIFT | CTRL | COMMAND;
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- String platform = getPlatform ();
- if ("carbon".equals (platform) || "cocoa".equals (platform)) { //$NON-NLS-1$ //$NON-NLS-2$
- MOD1 = COMMAND;
- MOD2 = SHIFT;
- MOD3 = ALT;
- MOD4 = CONTROL;
- } else {
- MOD1 = CONTROL;
- MOD2 = SHIFT;
- MOD3 = ALT;
- MOD4 = 0;
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTError.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTError.java
deleted file mode 100755
index 6a2341db66..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTError.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt;
-
-import org.eclipse.swt.internal.*;
-
-/**
- * This error is thrown whenever an unrecoverable error
- * occurs internally in SWT. The message text and error code
- * provide a further description of the problem. The exception
- * has a <code>throwable</code> field which holds the underlying
- * throwable that caused the problem (if this information is
- * available (i.e. it may be null)).
- * <p>
- * SWTErrors are thrown when something fails internally which
- * either leaves SWT in an unknown state (eg. the o/s call to
- * remove an item from a list returns an error code) or when SWT
- * is left in a known-to-be-unrecoverable state (eg. it runs out
- * of callback resources). SWTErrors should not occur in typical
- * programs, although "high reliability" applications should
- * still catch them.
- * </p><p>
- * This class also provides support methods used by SWT to match
- * error codes to the appropriate exception class (SWTError,
- * SWTException, or IllegalArgumentException) and to provide
- * human readable strings for SWT error codes.
- * </p>
- *
- * @see SWTException
- * @see SWT#error(int)
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public class SWTError extends Error {
- /**
- * The SWT error code, one of SWT.ERROR_*.
- */
- public int code;
-
- /**
- * The underlying throwable that caused the problem,
- * or null if this information is not available.
- */
- public Throwable throwable;
-
- static final long serialVersionUID = 3833467327105808433L;
-
-/**
- * Constructs a new instance of this class with its
- * stack trace filled in. The error code is set to an
- * unspecified value.
- */
-public SWTError () {
- this (SWT.ERROR_UNSPECIFIED);
-}
-
-/**
- * Constructs a new instance of this class with its
- * stack trace and message filled in. The error code is
- * set to an unspecified value. Specifying <code>null</code>
- * as the message is equivalent to specifying an empty string.
- *
- * @param message the detail message for the exception
- */
-public SWTError (String message) {
- this (SWT.ERROR_UNSPECIFIED, message);
-}
-
-/**
- * Constructs a new instance of this class with its
- * stack trace and error code filled in.
- *
- * @param code the SWT error code
- */
-public SWTError (int code) {
- this (code, SWT.findErrorText (code));
-}
-
-/**
- * Constructs a new instance of this class with its
- * stack trace, error code and message filled in.
- * Specifying <code>null</code> as the message is
- * equivalent to specifying an empty string.
- *
- * @param code the SWT error code
- * @param message the detail message for the exception
- */
-public SWTError (int code, String message) {
- super (message);
- this.code = code;
-}
-
-/**
- * Returns the underlying throwable that caused the problem,
- * or null if this information is not available.
- * <p>
- * NOTE: This method overrides Throwable.getCause() that was
- * added to JDK1.4. It is necessary to override this method
- * in order for inherited printStackTrace() methods to work.
- * </p>
- * @return the underlying throwable
- *
- * @since 3.1
- */
-public Throwable getCause() {
- return throwable;
-}
-
-/**
- * Returns the string describing this SWTError object.
- * <p>
- * It is combined with the message string of the Throwable
- * which caused this SWTError (if this information is available).
- * </p>
- * @return the error message string of this SWTError object
- */
-public String getMessage () {
- if (throwable == null) return super.getMessage ();
- return super.getMessage () + " (" + throwable.toString () + ")"; //$NON-NLS-1$ //$NON-NLS-2$
-}
-
-/**
- * Outputs a printable representation of this error's
- * stack trace on the standard error stream.
- * <p>
- * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter)
- * are not provided in order to maintain compatibility with CLDC.
- * </p>
- */
-public void printStackTrace () {
- super.printStackTrace ();
- if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 4, 0) && throwable != null) {
- System.err.println ("*** Stack trace of contained error ***"); //$NON-NLS-1$
- throwable.printStackTrace ();
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTException.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTException.java
deleted file mode 100755
index c139457ff5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTException.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt;
-
-import org.eclipse.swt.internal.*;
-
-/**
- * This runtime exception is thrown whenever a recoverable error
- * occurs internally in SWT. The message text and error code
- * provide a further description of the problem. The exception
- * has a <code>throwable</code> field which holds the underlying
- * exception that caused the problem (if this information is
- * available (i.e. it may be null)).
- * <p>
- * SWTExceptions are thrown when something fails internally,
- * but SWT is left in a known stable state (eg. a widget call
- * was made from a non-u/i thread, or there is failure while
- * reading an Image because the source file was corrupt).
- * </p>
- *
- * @see SWTError
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public class SWTException extends RuntimeException {
- /**
- * The SWT error code, one of SWT.ERROR_*.
- */
- public int code;
-
- /**
- * The underlying throwable that caused the problem,
- * or null if this information is not available.
- */
- public Throwable throwable;
-
- static final long serialVersionUID = 3257282552304842547L;
-
-/**
- * Constructs a new instance of this class with its
- * stack trace filled in. The error code is set to an
- * unspecified value.
- */
-public SWTException () {
- this (SWT.ERROR_UNSPECIFIED);
-}
-
-/**
- * Constructs a new instance of this class with its
- * stack trace and message filled in. The error code is
- * set to an unspecified value. Specifying <code>null</code>
- * as the message is equivalent to specifying an empty string.
- *
- * @param message the detail message for the exception
- */
-public SWTException (String message) {
- this (SWT.ERROR_UNSPECIFIED, message);
-}
-
-/**
- * Constructs a new instance of this class with its
- * stack trace and error code filled in.
- *
- * @param code the SWT error code
- */
-public SWTException (int code) {
- this (code, SWT.findErrorText (code));
-}
-
-/**
- * Constructs a new instance of this class with its
- * stack trace, error code and message filled in.
- * Specifying <code>null</code> as the message is
- * equivalent to specifying an empty string.
- *
- * @param code the SWT error code
- * @param message the detail message for the exception
- */
-public SWTException (int code, String message) {
- super (message);
- this.code = code;
-}
-
-/**
- * Returns the underlying throwable that caused the problem,
- * or null if this information is not available.
- * <p>
- * NOTE: This method overrides Throwable.getCause() that was
- * added to JDK1.4. It is necessary to override this method
- * in order for inherited printStackTrace() methods to work.
- * </p>
- * @return the underlying throwable
- *
- * @since 3.1
- */
-public Throwable getCause() {
- return throwable;
-}
-
-/**
- * Returns the string describing this SWTException object.
- * <p>
- * It is combined with the message string of the Throwable
- * which caused this SWTException (if this information is available).
- * </p>
- * @return the error message string of this SWTException object
- */
-public String getMessage () {
- if (throwable == null) return super.getMessage ();
- return super.getMessage () + " (" + throwable.toString () + ")"; //$NON-NLS-1$ //$NON-NLS-2$
-}
-
-/**
- * Outputs a printable representation of this exception's
- * stack trace on the standard error stream.
- * <p>
- * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter)
- * are not provided in order to maintain compatibility with CLDC.
- * </p>
- */
-public void printStackTrace () {
- super.printStackTrace ();
- if (Library.JAVA_VERSION < Library.JAVA_VERSION(1, 4, 0) && throwable != null) {
- System.err.println ("*** Stack trace of contained exception ***"); //$NON-NLS-1$
- throwable.printStackTrace ();
- }
-}
-
-}
-
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmEvent.java
deleted file mode 100755
index 5b6f9826a1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmEvent.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * a widget such as a menu item being armed.
- *
- * @see ArmListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class ArmEvent extends TypedEvent {
-
- static final long serialVersionUID = 3258126964249212217L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public ArmEvent(Event e) {
- super(e);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmListener.java
deleted file mode 100755
index 23e983afc7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmListener.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide a method
- * that deals with the event that is generated when a widget,
- * such as a menu item, is armed.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a widget using the
- * <code>addArmListener</code> method and removed using
- * the <code>removeArmListener</code> method. When the
- * widget is armed, the widgetArmed method will be invoked.
- * </p>
- *
- * @see ArmEvent
- */
-public interface ArmListener extends SWTEventListener {
-
-/**
- * Sent when a widget is armed, or 'about to be selected'.
- *
- * @param e an event containing information about the arm
- */
-public void widgetArmed(ArmEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlAdapter.java
deleted file mode 100755
index 10f273b09f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlAdapter.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>ControlListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>ControlEvent</code>s can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see ControlListener
- * @see ControlEvent
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class ControlAdapter implements ControlListener {
-
-/**
- * Sent when the location (x, y) of a control changes relative
- * to its parent (or relative to the display, for <code>Shell</code>s).
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the move
- */
-public void controlMoved(ControlEvent e) {
-}
-
-/**
- * Sent when the size (width, height) of a control changes.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the resize
- */
-public void controlResized(ControlEvent e) {
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlEvent.java
deleted file mode 100755
index 3513ef31c2..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlEvent.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * controls being moved or resized.
- *
- * @see ControlListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class ControlEvent extends TypedEvent {
-
- static final long serialVersionUID = 3258132436155119161L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public ControlEvent(Event e) {
- super(e);
-}
-
-}
-
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlListener.java
deleted file mode 100755
index 4895ec1946..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlListener.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the events that are generated by moving
- * and resizing controls.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addControlListener</code> method and removed using
- * the <code>removeControlListener</code> method. When a
- * control is moved or resized, the appropriate method will
- * be invoked.
- * </p>
- *
- * @see ControlAdapter
- * @see ControlEvent
- */
-public interface ControlListener extends SWTEventListener {
-
-/**
- * Sent when the location (x, y) of a control changes relative
- * to its parent (or relative to the display, for <code>Shell</code>s).
- *
- * @param e an event containing information about the move
- */
-public void controlMoved(ControlEvent e);
-
-/**
- * Sent when the size (width, height) of a control changes.
- *
- * @param e an event containing information about the resize
- */
-public void controlResized(ControlEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeEvent.java
deleted file mode 100755
index 04dbdd9639..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeEvent.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * widgets being disposed.
- *
- * @see DisposeListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class DisposeEvent extends TypedEvent {
-
- static final long serialVersionUID = 3257566187633521206L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public DisposeEvent(Event e) {
- super(e);
-}
-
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeListener.java
deleted file mode 100755
index 980f0b30ae..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeListener.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide a method
- * that deals with the event that is generated when a widget
- * is disposed.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a widget using the
- * <code>addDisposeListener</code> method and removed using
- * the <code>removeDisposeListener</code> method. When a
- * widget is disposed, the widgetDisposed method will
- * be invoked.
- * </p>
- *
- * @see DisposeEvent
- */
-public interface DisposeListener extends SWTEventListener {
-
-/**
- * Sent when the widget is disposed.
- *
- * @param e an event containing information about the dispose
- */
-public void widgetDisposed(DisposeEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DragDetectEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DragDetectEvent.java
deleted file mode 100644
index a10148d87d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DragDetectEvent.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * a drag gesture.
- *
- * @see DragDetectListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.3
- */
-
-public final class DragDetectEvent extends MouseEvent {
-
- private static final long serialVersionUID = -7229172519733647232L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public DragDetectEvent(Event e) {
- super(e);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DragDetectListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DragDetectListener.java
deleted file mode 100644
index 805747da3b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DragDetectListener.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the events that are generated when a drag
- * gesture is detected.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addDragDetectListener</code> method and removed using
- * the <code>removeDragDetectListener</code> method. When the
- * drag is detected, the drageDetected method will be invoked.
- * </p>
- *
- * @see DragDetectEvent
- *
- * @since 3.3
- */
-public interface DragDetectListener extends SWTEventListener {
-
-/**
- * Sent when a drag gesture is detected.
- *
- * @param e an event containing information about the drag
- */
-public void dragDetected(DragDetectEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandAdapter.java
deleted file mode 100644
index 6d9751368c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandAdapter.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>ExpandListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>ExpandEvent</code>s can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see ExpandListener
- * @see ExpandEvent
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.2
- */
-public abstract class ExpandAdapter implements ExpandListener {
-
-/**
- * Sent when an item is collapsed.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the operation
- */
-public void itemCollapsed(ExpandEvent e) {
-}
-
-/**
- * Sent when an item is expanded.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the operation
- */
-public void itemExpanded(ExpandEvent e) {
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandEvent.java
deleted file mode 100644
index 439de1702d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandEvent.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.widgets.*;
-
-/**
- * Instances of this class are sent as a result of
- * <code>ExpandItem</code>s being expanded or collapsed.
- *
- * @see ExpandListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.2
- */
-
-public class ExpandEvent extends SelectionEvent {
-
- static final long serialVersionUID = 3976735856884987356L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public ExpandEvent(Event e) {
- super(e);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandListener.java
deleted file mode 100644
index 4991d97a2f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandListener.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the expanding and collapsing of <code>ExpandItem</code>s.
- *
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a <code>ExpandBar</code>
- * control using the <code>addExpandListener</code> method and
- * removed using the <code>removeExpandListener</code> method.
- * When a item of the <code>ExpandBar</code> is expanded or
- * collapsed, the appropriate method will be invoked.
- * </p>
- *
- * @see ExpandAdapter
- * @see ExpandEvent
- *
- * @since 3.2
- */
-public interface ExpandListener extends SWTEventListener {
-
-/**
- * Sent when an item is collapsed.
- *
- * @param e an event containing information about the operation
- */
-public void itemCollapsed(ExpandEvent e);
-
-/**
- * Sent when an item is expanded.
- *
- * @param e an event containing information about the operation
- */
-public void itemExpanded(ExpandEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusAdapter.java
deleted file mode 100755
index eab687e12d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusAdapter.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>FocusListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>FocusEvent</code>s can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see FocusListener
- * @see FocusEvent
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class FocusAdapter implements FocusListener {
-
-/**
- * Sent when a control gets focus.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the focus change
- */
-public void focusGained(FocusEvent e) {
-}
-
-/**
- * Sent when a control loses focus.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the focus change
- */
-public void focusLost(FocusEvent e) {
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusEvent.java
deleted file mode 100755
index a703db7cfe..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusEvent.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * widgets gaining and losing focus.
- *
- * @see FocusListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class FocusEvent extends TypedEvent {
-
- static final long serialVersionUID = 3258134643684227381L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public FocusEvent(Event e) {
- super(e);
-}
-
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusListener.java
deleted file mode 100755
index 9aa3097d0a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusListener.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the events that are generated as controls
- * gain and lose focus.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addFocusListener</code> method and removed using
- * the <code>removeFocusListener</code> method. When a
- * control gains or loses focus, the appropriate method
- * will be invoked.
- * </p>
- *
- * @see FocusAdapter
- * @see FocusEvent
- */
-public interface FocusListener extends SWTEventListener {
-
-/**
- * Sent when a control gets focus.
- *
- * @param e an event containing information about the focus change
- */
-public void focusGained(FocusEvent e);
-
-/**
- * Sent when a control loses focus.
- *
- * @param e an event containing information about the focus change
- */
-public void focusLost(FocusEvent e);
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpEvent.java
deleted file mode 100755
index fd38eba361..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpEvent.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * help being requested for a widget.
- *
- * @see HelpListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class HelpEvent extends TypedEvent {
-
- static final long serialVersionUID = 3257001038606251315L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public HelpEvent(Event e) {
- super(e);
-}
-
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpListener.java
deleted file mode 100755
index 9437c093ea..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpListener.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide a method
- * that deals with the event that is generated when help is
- * requested for a control, typically when the user presses F1.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addHelpListener</code> method and removed using
- * the <code>removeHelpListener</code> method. When help
- * is requested for a control, the helpRequested method
- * will be invoked.
- * </p>
- *
- * @see HelpEvent
- */
-public interface HelpListener extends SWTEventListener {
-
-/**
- * Sent when help is requested for a control, typically
- * when the user presses F1.
- *
- * @param e an event containing information about the help
- */
-public void helpRequested(HelpEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyAdapter.java
deleted file mode 100755
index dca53cc517..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyAdapter.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>KeyListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>KeyEvent</code>s can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see KeyListener
- * @see KeyEvent
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class KeyAdapter implements KeyListener {
-
-/**
- * Sent when a key is pressed on the system keyboard.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the key press
- */
-public void keyPressed(KeyEvent e) {
-}
-
-/**
- * Sent when a key is released on the system keyboard.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the key release
- */
-public void keyReleased(KeyEvent e) {
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyEvent.java
deleted file mode 100755
index 7a3a1d77db..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyEvent.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * keys being pressed and released on the keyboard.
- * <p>
- * When a key listener is added to a control, the control
- * will take part in widget traversal. By default, all
- * traversal keys (such as the tab key and so on) are
- * delivered to the control. In order for a control to take
- * part in traversal, it should listen for traversal events.
- * Otherwise, the user can traverse into a control but not
- * out. Note that native controls such as table and tree
- * implement key traversal in the operating system. It is
- * not necessary to add traversal listeners for these controls,
- * unless you want to override the default traversal.
- * </p>
- *
- * @see KeyListener
- * @see TraverseListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public class KeyEvent extends TypedEvent {
-
- /**
- * the character represented by the key that was typed.
- * This is the final character that results after all modifiers have been
- * applied. For example, when the user types Ctrl+A, the character value
- * is 0x01. It is important that applications do not attempt to modify the
- * character value based on a stateMask (such as SWT.CTRL) or the resulting
- * character will not be correct.
- */
- public char character;
-
- /**
- * the key code of the key that was typed,
- * as defined by the key code constants in class <code>SWT</code>.
- * When the character field of the event is ambiguous, this field
- * contains the unicode value of the original character. For example,
- * typing Ctrl+M or Return both result in the character '\r' but the
- * keyCode field will also contain '\r' when Return was typed.
- *
- * @see org.eclipse.swt.SWT
- */
- public int keyCode;
-
- /**
- * the state of the keyboard modifier keys at the time
- * the event was generated, as defined by the key code
- * constants in class <code>SWT</code>.
- *
- * @see org.eclipse.swt.SWT
- */
- public int stateMask;
-
- /**
- * A flag indicating whether the operation should be allowed.
- * Setting this field to <code>false</code> will cancel the operation.
- */
- public boolean doit;
-
- static final long serialVersionUID = 3256442491011412789L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public KeyEvent(Event e) {
- super(e);
- this.character = e.character;
- this.keyCode = e.keyCode;
- this.stateMask = e.stateMask;
- this.doit = e.doit;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the event
- */
-public String toString() {
- String string = super.toString ();
- return string.substring (0, string.length() - 1) // remove trailing '}'
- + " character='" + ((character == 0) ? "\\0" : "" + character) + "'"
- + " keyCode=" + keyCode
- + " stateMask=" + stateMask
- + " doit=" + doit
- + "}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyListener.java
deleted file mode 100755
index 6107f8370e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyListener.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the events that are generated as keys
- * are pressed on the system keyboard.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addKeyListener</code> method and removed using
- * the <code>removeKeyListener</code> method. When a
- * key is pressed or released, the appropriate method will
- * be invoked.
- * </p>
- *
- * @see KeyAdapter
- * @see KeyEvent
- */
-public interface KeyListener extends SWTEventListener {
-
-/**
- * Sent when a key is pressed on the system keyboard.
- *
- * @param e an event containing information about the key press
- */
-public void keyPressed(KeyEvent e);
-
-/**
- * Sent when a key is released on the system keyboard.
- *
- * @param e an event containing information about the key release
- */
-public void keyReleased(KeyEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuAdapter.java
deleted file mode 100755
index 6bd3c6e5df..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuAdapter.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>MenuListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>MenuEvent</code>s can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see MenuListener
- * @see MenuEvent
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class MenuAdapter implements MenuListener {
-
-/**
- * Sent when a menu is hidden.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the menu operation
- */
-public void menuHidden(MenuEvent e) {
-}
-
-/**
- * Sent when a menu is shown.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the menu operation
- */
-public void menuShown(MenuEvent e) {
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuDetectEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuDetectEvent.java
deleted file mode 100644
index 8f36c30d39..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuDetectEvent.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent whenever the platform-
- * specific trigger for showing a context menu is detected.
- *
- * @see MenuDetectListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.3
- */
-
-public final class MenuDetectEvent extends TypedEvent {
-
- /**
- * the display-relative x coordinate of the pointer
- * at the time the context menu trigger occurred
- */
- public int x;
-
- /**
- * the display-relative y coordinate of the pointer
- * at the time the context menu trigger occurred
- */
- public int y;
-
- /**
- * A flag indicating whether the operation should be allowed.
- * Setting this field to <code>false</code> will cancel the operation.
- */
- public boolean doit;
-
- private static final long serialVersionUID = -3061660596590828941L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public MenuDetectEvent(Event e) {
- super(e);
- this.x = e.x;
- this.y = e.y;
- this.doit = e.doit;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the event
- */
-public String toString() {
- String string = super.toString ();
- return string.substring (0, string.length() - 1) // remove trailing '}'
- + " x=" + x
- + " y=" + y
- + " doit=" + doit
- + "}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuDetectListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuDetectListener.java
deleted file mode 100644
index 1d6769cca7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuDetectListener.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the events that are generated when the
- * platform-specific trigger for showing a context menu is
- * detected.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control or TrayItem
- * using the <code>addMenuDetectListener</code> method and
- * removed using the <code>removeMenuDetectListener</code> method.
- * When the context menu trigger occurs, the
- * <code>menuDetected</code> method will be invoked.
- * </p>
- *
- * @see MenuDetectEvent
- *
- * @since 3.3
- */
-public interface MenuDetectListener extends SWTEventListener {
-
-/**
- * Sent when the platform-dependent trigger for showing a menu item is detected.
- *
- * @param e an event containing information about the menu detect
- */
-public void menuDetected (MenuDetectEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuEvent.java
deleted file mode 100755
index 4697a9df42..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuEvent.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * menus being shown and hidden.
- *
- * @see MenuListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class MenuEvent extends TypedEvent {
-
- static final long serialVersionUID = 3258132440332383025L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public MenuEvent(Event e) {
- super(e);
-}
-
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuListener.java
deleted file mode 100755
index 0c74780ce9..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuListener.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the hiding and showing of menus.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a menu using the
- * <code>addMenuListener</code> method and removed using
- * the <code>removeMenuListener</code> method. When the
- * menu is hidden or shown, the appropriate method will
- * be invoked.
- * </p>
- *
- * @see MenuAdapter
- * @see MenuEvent
- */
-public interface MenuListener extends SWTEventListener {
-
-/**
- * Sent when a menu is hidden.
- *
- * @param e an event containing information about the menu operation
- */
-public void menuHidden(MenuEvent e);
-
-/**
- * Sent when a menu is shown.
- *
- * @param e an event containing information about the menu operation
- */
-public void menuShown(MenuEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyEvent.java
deleted file mode 100755
index 36642cfdd5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyEvent.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * text being modified.
- *
- * @see ModifyListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class ModifyEvent extends TypedEvent {
-
- static final long serialVersionUID = 3258129146227011891L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public ModifyEvent(Event e) {
- super(e);
-}
-
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyListener.java
deleted file mode 100755
index 614b13ad5a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyListener.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide a method
- * that deals with the events that are generated when text
- * is modified.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a text widget using the
- * <code>addModifyListener</code> method and removed using
- * the <code>removeModifyListener</code> method. When the
- * text is modified, the modifyText method will be invoked.
- * </p>
- *
- * @see ModifyEvent
- */
-public interface ModifyListener extends SWTEventListener {
-
-/**
- * Sent when the text is modified.
- *
- * @param e an event containing information about the modify
- */
-public void modifyText(ModifyEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseAdapter.java
deleted file mode 100755
index 1ae1c4821f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseAdapter.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>MouseListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>MouseEvent</code>s
- * which occur as mouse buttons are pressed and released can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see MouseListener
- * @see MouseEvent
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class MouseAdapter implements MouseListener {
-
-/**
- * Sent when a mouse button is pressed twice within the
- * (operating system specified) double click period.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the mouse double click
- *
- * @see org.eclipse.swt.widgets.Display#getDoubleClickTime()
- */
-public void mouseDoubleClick(MouseEvent e) {
-}
-
-/**
- * Sent when a mouse button is pressed.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the mouse button press
- */
-public void mouseDown(MouseEvent e) {
-}
-
-/**
- * Sent when a mouse button is released.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the mouse button release
- */
-public void mouseUp(MouseEvent e) {
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseEvent.java
deleted file mode 100755
index 19da7695a8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseEvent.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent whenever mouse
- * related actions occur. This includes mouse buttons
- * being pressed and released, the mouse pointer being
- * moved and the mouse pointer crossing widget boundaries.
- * <p>
- * Note: The <code>button</code> field is an integer that
- * represents the mouse button number. This is not the same
- * as the <code>SWT</code> mask constants <code>BUTTONx</code>.
- * </p>
- *
- * @see MouseListener
- * @see MouseMoveListener
- * @see MouseTrackListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public class MouseEvent extends TypedEvent {
-
- /**
- * the button that was pressed or released; 1 for the
- * first button, 2 for the second button, and 3 for the
- * third button, etc.
- */
- public int button;
-
- /**
- * the state of the keyboard modifier keys and mouse masks
- * at the time the event was generated.
- */
- public int stateMask;
-
- /**
- * the widget-relative, x coordinate of the pointer
- * at the time the mouse button was pressed or released
- */
- public int x;
-
- /**
- * the widget-relative, y coordinate of the pointer
- * at the time the mouse button was pressed or released
- */
- public int y;
-
- /**
- * the number times the mouse has been clicked, as defined
- * by the operating system; 1 for the first click, 2 for the
- * second click and so on.
- *
- * @since 3.3
- */
- public int count;
-
- static final long serialVersionUID = 3257288037011566898L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public MouseEvent(Event e) {
- super(e);
- this.x = e.x;
- this.y = e.y;
- this.button = e.button;
- this.stateMask = e.stateMask;
- this.count = e.count;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the event
- */
-public String toString() {
- String string = super.toString ();
- return string.substring (0, string.length() - 1) // remove trailing '}'
- + " button=" + button
- + " stateMask=" + stateMask
- + " x=" + x
- + " y=" + y
- + " count=" + count
- + "}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseListener.java
deleted file mode 100755
index 8ee2158624..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseListener.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the events that are generated as mouse buttons
- * are pressed.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addMouseListener</code> method and removed using
- * the <code>removeMouseListener</code> method. When a
- * mouse button is pressed or released, the appropriate method
- * will be invoked.
- * </p>
- *
- * @see MouseAdapter
- * @see MouseEvent
- */
-public interface MouseListener extends SWTEventListener {
-
-/**
- * Sent when a mouse button is pressed twice within the
- * (operating system specified) double click period.
- *
- * @param e an event containing information about the mouse double click
- *
- * @see org.eclipse.swt.widgets.Display#getDoubleClickTime()
- */
-public void mouseDoubleClick(MouseEvent e);
-
-/**
- * Sent when a mouse button is pressed.
- *
- * @param e an event containing information about the mouse button press
- */
-public void mouseDown(MouseEvent e);
-
-/**
- * Sent when a mouse button is released.
- *
- * @param e an event containing information about the mouse button release
- */
-public void mouseUp(MouseEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseMoveListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseMoveListener.java
deleted file mode 100755
index cc4e00f1a7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseMoveListener.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide a method
- * that deals with the events that are generated as the mouse
- * pointer moves.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addMouseMoveListener</code> method and removed using
- * the <code>removeMouseMoveListener</code> method. As the
- * mouse moves, the mouseMove method will be invoked.
- * </p>
- *
- * @see MouseEvent
- */
-public interface MouseMoveListener extends SWTEventListener {
-
-/**
- * Sent when the mouse moves.
- *
- * @param e an event containing information about the mouse move
- */
-public void mouseMove(MouseEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackAdapter.java
deleted file mode 100755
index d5ba0ef8bf..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackAdapter.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>MouseTrackListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>MouseEvent</code>s which
- * occur as the mouse pointer passes (or hovers) over controls can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see MouseTrackListener
- * @see MouseEvent
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class MouseTrackAdapter implements MouseTrackListener {
-
-/**
- * Sent when the mouse pointer passes into the area of
- * the screen covered by a control.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the mouse enter
- */
-public void mouseEnter(MouseEvent e) {
-}
-
-/**
- * Sent when the mouse pointer passes out of the area of
- * the screen covered by a control.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the mouse exit
- */
-public void mouseExit(MouseEvent e) {
-}
-
-/**
- * Sent when the mouse pointer hovers (that is, stops moving
- * for an (operating system specified) period of time) over
- * a control.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the hover
- */
-public void mouseHover(MouseEvent e) {
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackListener.java
deleted file mode 100755
index 9b01407c7d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackListener.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the events that are generated as the mouse
- * pointer passes (or hovers) over controls.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addMouseTrackListener</code> method and removed using
- * the <code>removeMouseTrackListener</code> method. When the
- * mouse pointer passes into or out of the area of the screen
- * covered by a control or pauses while over a control, the
- * appropriate method will be invoked.
- * </p>
- *
- * @see MouseTrackAdapter
- * @see MouseEvent
- */
-public interface MouseTrackListener extends SWTEventListener {
-
-/**
- * Sent when the mouse pointer passes into the area of
- * the screen covered by a control.
- *
- * @param e an event containing information about the mouse enter
- */
-public void mouseEnter(MouseEvent e);
-
-/**
- * Sent when the mouse pointer passes out of the area of
- * the screen covered by a control.
- *
- * @param e an event containing information about the mouse exit
- */
-public void mouseExit(MouseEvent e);
-
-/**
- * Sent when the mouse pointer hovers (that is, stops moving
- * for an (operating system specified) period of time) over
- * a control.
- *
- * @param e an event containing information about the hover
- */
-public void mouseHover(MouseEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseWheelListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseWheelListener.java
deleted file mode 100644
index 74d50b1676..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseWheelListener.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide a method
- * that deals with the event that is generated as the mouse
- * wheel is scrolled.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addMouseWheelListener</code> method and removed using
- * the <code>removeMouseWheelListener</code> method. When the
- * mouse wheel is scrolled the <code>mouseScrolled</code> method
- * will be invoked.
- * </p>
- *
- * @see MouseEvent
- *
- * @since 3.3
- */
-public interface MouseWheelListener extends SWTEventListener {
-
-/**
- * Sent when the mouse wheel is scrolled.
- *
- * @param e an event containing information about the mouse wheel action
- */
-public void mouseScrolled (MouseEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintEvent.java
deleted file mode 100755
index e7c4443ff1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintEvent.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.graphics.GC;
-
-/**
- * Instances of this class are sent as a result of
- * visible areas of controls requiring re-painting.
- *
- * @see PaintListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class PaintEvent extends TypedEvent {
-
- /**
- * the graphics context to use when painting
- * that is configured to use the colors, font and
- * damaged region of the control. It is valid
- * only during the paint and must not be disposed
- */
- public GC gc;
-
- /**
- * the x offset of the bounding rectangle of the
- * region that requires painting
- */
- public int x;
-
- /**
- * the y offset of the bounding rectangle of the
- * region that requires painting
- */
- public int y;
-
- /**
- * the width of the bounding rectangle of the
- * region that requires painting
- */
- public int width;
-
- /**
- * the height of the bounding rectangle of the
- * region that requires painting
- */
- public int height;
-
- /**
- * the number of following paint events which
- * are pending which may always be zero on
- * some platforms
- */
- public int count;
-
- static final long serialVersionUID = 3256446919205992497L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public PaintEvent(Event e) {
- super(e);
- this.gc = e.gc;
- this.x = e.x;
- this.y = e.y;
- this.width = e.width;
- this.height = e.height;
- this.count = e.count;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the event
- */
-public String toString() {
- String string = super.toString ();
- return string.substring (0, string.length() - 1) // remove trailing '}'
- + " gc=" + gc
- + " x=" + x
- + " y=" + y
- + " width=" + width
- + " height=" + height
- + " count=" + count
- + "}";
-}
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintListener.java
deleted file mode 100755
index 7a047c82ea..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintListener.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the events that are generated when the
- * control needs to be painted.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addPaintListener</code> method and removed using
- * the <code>removePaintListener</code> method. When a
- * paint event occurs, the paintControl method will be
- * invoked.
- * </p>
- *
- * @see PaintEvent
- */
-public interface PaintListener extends SWTEventListener {
-
-/**
- * Sent when a paint event occurs for the control.
- *
- * @param e an event containing information about the paint
- */
-public void paintControl(PaintEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionAdapter.java
deleted file mode 100755
index be1fe9fdc0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionAdapter.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>SelectionListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>SelectionEvent</code>s can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see SelectionListener
- * @see SelectionEvent
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class SelectionAdapter implements SelectionListener {
-
-/**
- * Sent when selection occurs in the control.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the selection
- */
-public void widgetSelected(SelectionEvent e) {
-}
-
-/**
- * Sent when default selection occurs in the control.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the default selection
- */
-public void widgetDefaultSelected(SelectionEvent e) {
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionEvent.java
deleted file mode 100755
index 7f6a77eb2d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionEvent.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.widgets.*;
-
-/**
- * Instances of this class are sent as a result of
- * widgets being selected.
- * <p>
- * Note: The fields that are filled in depend on the widget.
- * </p>
- *
- * @see SelectionListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public class SelectionEvent extends TypedEvent {
-
- /**
- * The item that was selected.
- */
- public Widget item;
-
- /**
- * Extra detail information about the selection, depending on the widget.
- *
- * <p><b>Sash</b><ul>
- * <li>{@link org.eclipse.swt.SWT#DRAG}</li>
- * </ul></p><p><b>ScrollBar and Slider</b><ul>
- * <li>{@link org.eclipse.swt.SWT#DRAG}</li>
- * <li>{@link org.eclipse.swt.SWT#HOME}</li>
- * <li>{@link org.eclipse.swt.SWT#END}</li>
- * <li>{@link org.eclipse.swt.SWT#ARROW_DOWN}</li>
- * <li>{@link org.eclipse.swt.SWT#ARROW_UP}</li>
- * <li>{@link org.eclipse.swt.SWT#PAGE_DOWN}</li>
- * <li>{@link org.eclipse.swt.SWT#PAGE_UP}</li>
- * </ul></p><p><b>Table and Tree</b><ul>
- * <li>{@link org.eclipse.swt.SWT#CHECK}</li>
- * </ul></p><p><b>Text</b><ul>
- * <li>{@link org.eclipse.swt.SWT#CANCEL}</li>
- * </ul></p><p><b>CoolItem and ToolItem</b><ul>
- * <li>{@link org.eclipse.swt.SWT#ARROW}</li>
- * </ul></p>
- */
- public int detail;
-
- /**
- * The x location of the selected area.
- */
- public int x;
-
- /**
- * The y location of selected area.
- */
- public int y;
-
- /**
- * The width of selected area.
- */
- public int width;
-
- /**
- * The height of selected area.
- */
- public int height;
-
- /**
- * The state of the keyboard modifier keys at the time
- * the event was generated.
- */
- public int stateMask;
-
- /**
- * The text of the hyperlink that was selected.
- * This will be either the text of the hyperlink or the value of its HREF,
- * if one was specified.
- *
- * @see org.eclipse.swt.widgets.Link#setText(String)
- * @since 3.1
- */
- public String text;
-
- /**
- * A flag indicating whether the operation should be allowed.
- * Setting this field to <code>false</code> will cancel the
- * operation, depending on the widget.
- */
- public boolean doit;
-
- static final long serialVersionUID = 3976735856884987953L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public SelectionEvent(Event e) {
- super(e);
- this.item = e.item;
- this.x = e.x;
- this.y = e.y;
- this.width = e.width;
- this.height = e.height;
- this.detail = e.detail;
- this.stateMask = e.stateMask;
- this.text = e.text;
- this.doit = e.doit;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the event
- */
-public String toString() {
- String string = super.toString ();
- return string.substring (0, string.length() - 1) // remove trailing '}'
- + " item=" + item
- + " detail=" + detail
- + " x=" + x
- + " y=" + y
- + " width=" + width
- + " height=" + height
- + " stateMask=" + stateMask
- + " text=" + text
- + " doit=" + doit
- + "}";
-}
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionListener.java
deleted file mode 100755
index 32938d3f07..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionListener.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the events that are generated when selection
- * occurs in a control.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addSelectionListener</code> method and removed using
- * the <code>removeSelectionListener</code> method. When
- * selection occurs in a control the appropriate method
- * will be invoked.
- * </p>
- *
- * @see SelectionAdapter
- * @see SelectionEvent
- */
-public interface SelectionListener extends SWTEventListener {
-
-/**
- * Sent when selection occurs in the control.
- * <p>
- * For example, selection occurs in a List when the user selects
- * an item or items with the keyboard or mouse. On some platforms,
- * the event occurs when a mouse button or key is pressed. On others,
- * it happens when the mouse or key is released. The exact key or
- * mouse gesture that causes this event is platform specific.
- * </p>
- *
- * @param e an event containing information about the selection
- */
-public void widgetSelected(SelectionEvent e);
-
-/**
- * Sent when default selection occurs in the control.
- * <p>
- * For example, on some platforms default selection occurs in a List
- * when the user double-clicks an item or types return in a Text.
- * On some platforms, the event occurs when a mouse button or key is
- * pressed. On others, it happens when the mouse or key is released.
- * The exact key or mouse gesture that causes this event is platform
- * specific.
- * </p>
- *
- * @param e an event containing information about the default selection
- */
-public void widgetDefaultSelected(SelectionEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellAdapter.java
deleted file mode 100755
index 39e7d188f1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellAdapter.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>ShellListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>ShellEvent</code>s can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see ShellListener
- * @see ShellEvent
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class ShellAdapter implements ShellListener {
-
-/**
- * Sent when a shell becomes the active window.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the activation
- */
-public void shellActivated(ShellEvent e) {
-}
-
-/**
- * Sent when a shell is closed.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the close
- */
-public void shellClosed(ShellEvent e) {
-}
-
-/**
- * Sent when a shell stops being the active window.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the deactivation
- */
-public void shellDeactivated(ShellEvent e) {
-}
-
-/**
- * Sent when a shell is un-minimized.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the un-minimization
- */
-public void shellDeiconified(ShellEvent e) {
-}
-
-/**
- * Sent when a shell is minimized.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the minimization
- */
-public void shellIconified(ShellEvent e) {
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellEvent.java
deleted file mode 100755
index 736cca3f14..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellEvent.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * operations being performed on shells.
- *
- * @see ShellListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class ShellEvent extends TypedEvent {
-
- /**
- * A flag indicating whether the operation should be allowed.
- * Setting this field to <code>false</code> will cancel the operation.
- */
- public boolean doit;
-
- static final long serialVersionUID = 3257569490479888441L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public ShellEvent(Event e) {
- super(e);
- this.doit = e.doit;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the event
- */
-public String toString() {
- String string = super.toString ();
- return string.substring (0, string.length() - 1) // remove trailing '}'
- + " doit=" + doit
- + "}";
-}
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellListener.java
deleted file mode 100755
index 36cd8a146a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellListener.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with changes in state of <code>Shell</code>s.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a shell using the
- * <code>addShellListener</code> method and removed using
- * the <code>removeShellListener</code> method. When the
- * state of the shell changes, the appropriate method will
- * be invoked.
- * </p>
- *
- * @see ShellAdapter
- * @see ShellEvent
- */
-public interface ShellListener extends SWTEventListener {
-
-/**
- * Sent when a shell becomes the active window.
- *
- * @param e an event containing information about the activation
- */
-public void shellActivated(ShellEvent e);
-
-/**
- * Sent when a shell is closed.
- *
- * @param e an event containing information about the close
- */
-public void shellClosed(ShellEvent e);
-
-/**
- * Sent when a shell stops being the active window.
- *
- * @param e an event containing information about the deactivation
- */
-public void shellDeactivated(ShellEvent e);
-
-/**
- * Sent when a shell is un-minimized.
- *
- * @param e an event containing information about the un-minimization
- */
-public void shellDeiconified(ShellEvent e);
-
-/**
- * Sent when a shell is minimized.
- *
- * @param e an event containing information about the minimization
- */
-public void shellIconified(ShellEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseEvent.java
deleted file mode 100755
index f50e42ab2a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseEvent.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.widgets.*;
-
-/**
- * Instances of this class are sent as a result of
- * widget traversal actions.
- * <p>
- * The traversal event allows fine control over keyboard traversal
- * in a control both to implement traversal and override the default
- * traversal behavior defined by the system. This is achieved using
- * two fields, <code>detail</code> and <code>doit</code>.
- * </p><p>
- * When a control is traversed, a traverse event is sent. The detail
- * describes the type of traversal and the doit field indicates the default
- * behavior of the system. For example, when a right arrow key is pressed
- * in a text control, the detail field is <code>TRAVERSE_ARROW_NEXT</code>
- * and the doit field is <code>false</code>, indicating that the system
- * will not traverse to the next tab item and the arrow key will be
- * delivered to the text control. If the same key is pressed in a radio
- * button, the doit field will be <code>true</code>, indicating that
- * traversal is to proceed to the next tab item, possibly another radio
- * button in the group and that the arrow key is not to be delivered
- * to the radio button.
- * </p><p>
- * How can the traversal event be used to implement traversal?
- * When a tab key is pressed in a canvas, the detail field will be
- * <code>TRAVERSE_TAB_NEXT</code> and the doit field will be
- * <code>false</code>. The default behavior of the system is to
- * provide no traversal for canvas controls. This means that by
- * default in a canvas, a key listener will see every key that the
- * user types, including traversal keys. To understand why this
- * is so, it is important to understand that only the widget implementor
- * can decide which traversal is appropriate for the widget. Returning
- * to the <code>TRAVERSE_TAB_NEXT</code> example, a text widget implemented
- * by a canvas would typically want to use the tab key to insert a
- * tab character into the widget. A list widget implementation, on the
- * other hand, would like the system default traversal behavior. Using
- * only the doit flag, both implementations are possible. The text widget
- * implementor sets doit to <code>false</code>, ensuring that the system
- * will not traverse and that the tab key will be delivered to key listeners.
- * The list widget implementor sets doit to <code>true</code>, indicating
- * that the system should perform tab traversal and that the key should not
- * be delivered to the list widget.
- * </p><p>
- * How can the traversal event be used to override system traversal?
- * When the return key is pressed in a single line text control, the
- * detail field is <code>TRAVERSE_RETURN</code> and the doit field
- * is <code>true</code>. This means that the return key will be processed
- * by the default button, not the text widget. If the text widget has
- * a default selection listener, it will not run because the return key
- * will be processed by the default button. Imagine that the text control
- * is being used as an in-place editor and return is used to dispose the
- * widget. Setting doit to <code>false</code> will stop the system from
- * activating the default button but the key will be delivered to the text
- * control, running the key and selection listeners for the text. How
- * can <code>TRAVERSE_RETURN</code> be implemented so that the default button
- * will not be activated and the text widget will not see the return key?
- * This is achieved by setting doit to <code>true</code>, and the detail
- * to <code>TRAVERSE_NONE</code>.
- * </p><p>
- * Note: A widget implementor will typically implement traversal using
- * only the doit flag to either enable or disable system traversal.
- * </p>
- *
- * @see TraverseListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class TraverseEvent extends KeyEvent {
-
- /**
- * The traversal type.
- * <p><ul>
- * <li>{@link org.eclipse.swt.SWT#TRAVERSE_NONE}</li>
- * <li>{@link org.eclipse.swt.SWT#TRAVERSE_ESCAPE}</li>
- * <li>{@link org.eclipse.swt.SWT#TRAVERSE_RETURN}</li>
- * <li>{@link org.eclipse.swt.SWT#TRAVERSE_TAB_NEXT}</li>
- * <li>{@link org.eclipse.swt.SWT#TRAVERSE_TAB_PREVIOUS}</li>
- * <li>{@link org.eclipse.swt.SWT#TRAVERSE_ARROW_NEXT}</li>
- * <li>{@link org.eclipse.swt.SWT#TRAVERSE_ARROW_PREVIOUS}</li>
- * <li>{@link org.eclipse.swt.SWT#TRAVERSE_MNEMONIC}</li>
- * <li>{@link org.eclipse.swt.SWT#TRAVERSE_PAGE_NEXT}</li>
- * <li>{@link org.eclipse.swt.SWT#TRAVERSE_PAGE_PREVIOUS}</li>
- * </ul></p>
- *
- * Setting this field will change the type of traversal.
- * For example, setting the detail to <code>TRAVERSE_NONE</code>
- * causes no traversal action to be taken.
- *
- * When used in conjunction with the <code>doit</code> field, the
- * traversal detail field can be useful when overriding the default
- * traversal mechanism for a control. For example, setting the doit
- * field to <code>false</code> will cancel the operation and allow
- * the traversal key stroke to be delivered to the control. Setting
- * the doit field to <code>true</code> indicates that the traversal
- * described by the detail field is to be performed.
- */
- public int detail;
-
- static final long serialVersionUID = 3257565105301239349L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public TraverseEvent(Event e) {
- super(e);
- this.detail = e.detail;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the event
- */
-public String toString() {
- String string = super.toString ();
- return string.substring (0, string.length() - 1) // remove trailing '}'
- + " detail=" + detail
- + "}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseListener.java
deleted file mode 100755
index 2d1d4b3261..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseListener.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide a method
- * that deals with the events that are generated when a
- * traverse event occurs in a control.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addTraverseListener</code> method and removed using
- * the <code>removeTraverseListener</code> method. When a
- * traverse event occurs in a control, the keyTraversed method
- * will be invoked.
- * </p>
- *
- * @see TraverseEvent
- */
-public interface TraverseListener extends SWTEventListener {
-
-/**
- * Sent when a traverse event occurs in a control.
- * <p>
- * A traverse event occurs when the user presses a traversal
- * key. Traversal keys are typically tab and arrow keys, along
- * with certain other keys on some platforms. Traversal key
- * constants beginning with <code>TRAVERSE_</code> are defined
- * in the <code>SWT</code> class.
- * </p>
- *
- * @param e an event containing information about the traverse
- */
-public void keyTraversed(TraverseEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeAdapter.java
deleted file mode 100755
index c7dacb892b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeAdapter.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>TreeListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>TreeEvent</code>s can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see TreeListener
- * @see TreeEvent
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class TreeAdapter implements TreeListener {
-
-/**
- * Sent when a tree branch is collapsed.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the tree operation
- */
-public void treeCollapsed(TreeEvent e) {
-}
-
-/**
- * Sent when a tree branch is expanded.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the tree operation
- */
-public void treeExpanded(TreeEvent e) {
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeEvent.java
deleted file mode 100755
index 1a3dbc547d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeEvent.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * trees being expanded and collapsed.
- *
- * @see TreeListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class TreeEvent extends SelectionEvent {
-
- static final long serialVersionUID = 3257282548009677109L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public TreeEvent(Event e) {
- super(e);
-}
-
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeListener.java
deleted file mode 100755
index 9e45cc2630..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeListener.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the expanding and collapsing of tree
- * branches.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a tree control using the
- * <code>addTreeListener</code> method and removed using
- * the <code>removeTreeListener</code> method. When a branch
- * of the tree is expanded or collapsed, the appropriate method
- * will be invoked.
- * </p>
- *
- * @see TreeAdapter
- * @see TreeEvent
- */
-public interface TreeListener extends SWTEventListener {
-
-/**
- * Sent when a tree branch is collapsed.
- *
- * @param e an event containing information about the tree operation
- */
-public void treeCollapsed(TreeEvent e);
-
-/**
- * Sent when a tree branch is expanded.
- *
- * @param e an event containing information about the tree operation
- */
-public void treeExpanded(TreeEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TypedEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TypedEvent.java
deleted file mode 100755
index 1f2f8676f7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TypedEvent.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.internal.SWTEventObject;
-
-/**
- * This is the super class for all typed event classes provided
- * by SWT. Typed events contain particular information which is
- * applicable to the event occurrence.
- *
- * @see org.eclipse.swt.widgets.Event
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class TypedEvent extends SWTEventObject {
-
- /**
- * the display where the event occurred
- *
- * @since 2.0
- */
- public Display display;
-
- /**
- * the widget that issued the event
- */
- public Widget widget;
-
- /**
- * the time that the event occurred.
- *
- * NOTE: This field is an unsigned integer and should
- * be AND'ed with 0xFFFFFFFFL so that it can be treated
- * as a signed long.
- */
- public int time;
-
- /**
- * a field for application use
- */
- public Object data;
-
- static final long serialVersionUID = 3257285846578377524L;
-
-/**
- * Constructs a new instance of this class.
- *
- * @param object the object that fired the event
- */
-public TypedEvent(Object object) {
- super(object);
-}
-
-/**
- * Constructs a new instance of this class based on the
- * information in the argument.
- *
- * @param e the low level event to initialize the receiver with
- */
-public TypedEvent(Event e) {
- super(e.widget);
- this.display = e.display;
- this.widget = e.widget;
- this.time = e.time;
- this.data = e.data;
-}
-
-/**
- * Returns the name of the event. This is the name of
- * the class without the package name.
- *
- * @return the name of the event
- */
-String getName () {
- String string = getClass ().getName ();
- int index = string.lastIndexOf ('.');
- if (index == -1) return string;
- return string.substring (index + 1, string.length ());
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the event
- */
-public String toString() {
- return getName ()
- + "{" + widget
- + " time=" + time
- + " data=" + data
- + "}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyEvent.java
deleted file mode 100755
index 527aaba7e6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyEvent.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * widgets handling keyboard events
- *
- * @see VerifyListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class VerifyEvent extends KeyEvent {
-
- /**
- * the range of text being modified.
- * Setting these fields has no effect.
- */
- public int start, end;
-
- /**
- * the new text that will be inserted.
- * Setting this field will change the text that is about to
- * be inserted or deleted.
- */
- public String text;
-
- static final long serialVersionUID = 3257003246269577014L;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public VerifyEvent(Event e) {
- super(e);
- this.start = e.start;
- this.end = e.end;
- this.text = e.text;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the event
- */
-public String toString() {
- String string = super.toString ();
- return string.substring (0, string.length() - 1) // remove trailing '}'
- + " start=" + start
- + " end=" + end
- + " text=" + text
- + "}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyListener.java
deleted file mode 100755
index 653e203387..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyListener.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.events;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide a method
- * that deals with the events that are generated when text
- * is about to be modified.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a text control using the
- * <code>addVerifyListener</code> method and removed using
- * the <code>removeVerifyListener</code> method. When the
- * text is about to be modified, the verifyText method
- * will be invoked.
- * </p>
- *
- * @see VerifyEvent
- */
-public interface VerifyListener extends SWTEventListener {
-
-/**
- * Sent when the text is about to be modified.
- * <p>
- * A verify event occurs after the user has done something
- * to modify the text (typically typed a key), but before
- * the text is modified. The doit field in the verify event
- * indicates whether or not to modify the text.
- * </p>
- *
- * @param e an event containing information about the verify
- */
-public void verifyText(VerifyEvent e);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/package.html b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/package.html
deleted file mode 100755
index b6325f9463..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/package.html
+++ /dev/null
@@ -1,23 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-<html>
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <meta name="Author" content="IBM">
- <title>Package-level Javadoc</title>
-</head>
-<body>
-SWT typed listener support.
-<h2>
-Package Specification</h2>
-This package provides the typed events and listener interfaces and,
-where appropriate, matching adapter classes which make up the
-"high level" <em>typed listener</em> support provided by SWT.
-<p>
-For contrast, see also the <em>untyped listener</em> support provided
-by class <code>org.eclipse.swt.widgets.Event</code> and interface
-<code>org.eclipse.swt.widgets.Listener</code>, and the
-<code>addListener</code> and <code>removeListener</code> methods in
-class <code>org.eclipse.swt.widgets.Widget</code>.
-</p>
-</body>
-</html>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Drawable.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Drawable.java
deleted file mode 100755
index 2d909d1c0f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Drawable.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-/**
- * Implementers of <code>Drawable</code> can have a graphics context (GC)
- * created for them, and then they can be drawn on by sending messages to
- * their associated GC. SWT images, and device objects such as the Display
- * device and the Printer device, are drawables.
- * <p>
- * <b>IMPORTANT:</b> This interface is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It should never be
- * referenced from application code.
- * </p>
- *
- * @see Device
- * @see Image
- * @see GC
- */
-public interface Drawable {
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Drawable</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-
-public int /*long*/ internal_new_GC (GCData data);
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Drawable</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param handle the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int /*long*/ handle, GCData data);
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/GlyphMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/GlyphMetrics.java
deleted file mode 100644
index ccc0c386b5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/GlyphMetrics.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class represent glyph metrics.
- * <p>
- * The hashCode() method in this class uses the values of the public
- * fields to compute the hash value. When storing instances of the
- * class in hashed collections, do not modify these fields after the
- * object has been inserted.
- * </p>
- * <p>
- * Application code does <em>not</em> need to explicitly release the
- * resources managed by each instance when those instances are no longer
- * required, and thus no <code>dispose()</code> method is provided.
- * </p>
- *
- * @see TextStyle
- * @see TextLayout
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.2
- */
-public final class GlyphMetrics {
-
- /**
- * the ascent of the GlyphMetrics
- */
- public int ascent;
-
- /**
- * the descent of the GlyphMetrics
- */
- public int descent;
-
- /**
- * the width of the GlyphMetrics
- */
- public int width;
-
-/**
- * Constructs an instance of this class with the given
- * ascent, descent and width values.
- *
- * @param ascent the GlyphMetrics ascent
- * @param descent the GlyphMetrics descent
- * @param width the GlyphMetrics width
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the ascent, descent or width argument is negative</li>
- * </ul>
- */
-public GlyphMetrics(int ascent, int descent, int width) {
- if (ascent < 0 || descent < 0 || width < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- this.ascent = ascent;
- this.descent = descent;
- this.width = width;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode()
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof GlyphMetrics)) return false;
- GlyphMetrics metrics = (GlyphMetrics)object;
- return metrics.ascent == ascent && metrics.descent == descent && metrics.width == width;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals(Object)
- */
-public int hashCode () {
- return ascent ^ descent ^ width;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the <code>GlyphMetrics</code>
- */
-public String toString () {
- return "GlyphMetrics {" + ascent + ", " + descent + ", " + width + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java
deleted file mode 100755
index 24c7f646b8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java
+++ /dev/null
@@ -1,3673 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import java.io.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.CloneableCompatibility;
-
-/**
- * Instances of this class are device-independent descriptions
- * of images. They are typically used as an intermediate format
- * between loading from or writing to streams and creating an
- * <code>Image</code>.
- * <p>
- * Note that the public fields <code>x</code>, <code>y</code>,
- * <code>disposalMethod</code> and <code>delayTime</code> are
- * typically only used when the image is in a set of images used
- * for animation.
- * </p>
- *
- * @see Image
- * @see ImageLoader
- * @see <a href="http://www.eclipse.org/swt/snippets/#image">ImageData snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ImageAnalyzer</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class ImageData implements CloneableCompatibility {
-
- /**
- * The width of the image, in pixels.
- */
- public int width;
-
- /**
- * The height of the image, in pixels.
- */
- public int height;
-
- /**
- * The color depth of the image, in bits per pixel.
- * <p>
- * Note that a depth of 8 or less does not necessarily
- * mean that the image is palette indexed, or
- * conversely that a depth greater than 8 means that
- * the image is direct color. Check the associated
- * PaletteData's isDirect field for such determinations.
- */
- public int depth;
-
- /**
- * The scanline padding.
- * <p>
- * If one scanline of the image is not a multiple of
- * this number, it will be padded with zeros until it is.
- * </p>
- */
- public int scanlinePad;
-
- /**
- * The number of bytes per scanline.
- * <p>
- * This is a multiple of the scanline padding.
- * </p>
- */
- public int bytesPerLine;
-
- /**
- * The pixel data of the image.
- * <p>
- * Note that for 16 bit depth images the pixel data is stored
- * in least significant byte order; however, for 24bit and
- * 32bit depth images the pixel data is stored in most
- * significant byte order.
- * </p>
- */
- public byte[] data;
-
- /**
- * The color table for the image.
- */
- public PaletteData palette;
-
- /**
- * The transparent pixel.
- * <p>
- * Pixels with this value are transparent.
- * </p><p>
- * The default is -1 which means 'no transparent pixel'.
- * </p>
- */
- public int transparentPixel;
-
- /**
- * An icon-specific field containing the data from the icon mask.
- * <p>
- * This is a 1 bit bitmap stored with the most significant
- * bit first. The number of bytes per scanline is
- * '((width + 7) / 8 + (maskPad - 1)) / maskPad * maskPad'.
- * </p><p>
- * The default is null which means 'no transparency mask'.
- * </p>
- */
- public byte[] maskData;
-
- /**
- * An icon-specific field containing the scanline pad of the mask.
- * <p>
- * If one scanline of the transparency mask is not a
- * multiple of this number, it will be padded with zeros until
- * it is.
- * </p>
- */
- public int maskPad;
-
- /**
- * The alpha data of the image.
- * <p>
- * Every pixel can have an <em>alpha blending</em> value that
- * varies from 0, meaning fully transparent, to 255 meaning
- * fully opaque. The number of bytes per scanline is
- * 'width'.
- * </p>
- */
- public byte[] alphaData;
-
- /**
- * The global alpha value to be used for every pixel.
- * <p>
- * If this value is set, the <code>alphaData</code> field
- * is ignored and when the image is rendered each pixel
- * will be blended with the background an amount
- * proportional to this value.
- * </p><p>
- * The default is -1 which means 'no global alpha value'
- * </p>
- */
- public int alpha;
-
- /**
- * The type of file from which the image was read.
- *
- * It is expressed as one of the following values:
- * <dl>
- * <dt><code>IMAGE_BMP</code></dt>
- * <dd>Windows BMP file format, no compression</dd>
- * <dt><code>IMAGE_BMP_RLE</code></dt>
- * <dd>Windows BMP file format, RLE compression if appropriate</dd>
- * <dt><code>IMAGE_GIF</code></dt>
- * <dd>GIF file format</dd>
- * <dt><code>IMAGE_ICO</code></dt>
- * <dd>Windows ICO file format</dd>
- * <dt><code>IMAGE_JPEG</code></dt>
- * <dd>JPEG file format</dd>
- * <dt><code>IMAGE_PNG</code></dt>
- * <dd>PNG file format</dd>
- * </dl>
- */
- public int type;
-
- /**
- * The x coordinate of the top left corner of the image
- * within the logical screen (this field corresponds to
- * the GIF89a Image Left Position value).
- */
- public int x;
-
- /**
- * The y coordinate of the top left corner of the image
- * within the logical screen (this field corresponds to
- * the GIF89a Image Top Position value).
- */
- public int y;
-
- /**
- * A description of how to dispose of the current image
- * before displaying the next.
- *
- * It is expressed as one of the following values:
- * <dl>
- * <dt><code>DM_UNSPECIFIED</code></dt>
- * <dd>disposal method not specified</dd>
- * <dt><code>DM_FILL_NONE</code></dt>
- * <dd>do nothing - leave the image in place</dd>
- * <dt><code>DM_FILL_BACKGROUND</code></dt>
- * <dd>fill with the background color</dd>
- * <dt><code>DM_FILL_PREVIOUS</code></dt>
- * <dd>restore the previous picture</dd>
- * </dl>
- * (this field corresponds to the GIF89a Disposal Method value)
- */
- public int disposalMethod;
-
- /**
- * The time to delay before displaying the next image
- * in an animation (this field corresponds to the GIF89a
- * Delay Time value).
- */
- public int delayTime;
-
- /**
- * Arbitrary channel width data to 8-bit conversion table.
- */
- static final byte[][] ANY_TO_EIGHT = new byte[9][];
- static {
- for (int b = 0; b < 9; ++b) {
- byte[] data = ANY_TO_EIGHT[b] = new byte[1 << b];
- if (b == 0) continue;
- int inc = 0;
- for (int bit = 0x10000; (bit >>= b) != 0;) inc |= bit;
- for (int v = 0, p = 0; v < 0x10000; v+= inc) data[p++] = (byte)(v >> 8);
- }
- }
- static final byte[] ONE_TO_ONE_MAPPING = ANY_TO_EIGHT[8];
-
- /**
- * Scaled 8x8 Bayer dither matrix.
- */
- static final int[][] DITHER_MATRIX = {
- { 0xfc0000, 0x7c0000, 0xdc0000, 0x5c0000, 0xf40000, 0x740000, 0xd40000, 0x540000 },
- { 0x3c0000, 0xbc0000, 0x1c0000, 0x9c0000, 0x340000, 0xb40000, 0x140000, 0x940000 },
- { 0xcc0000, 0x4c0000, 0xec0000, 0x6c0000, 0xc40000, 0x440000, 0xe40000, 0x640000 },
- { 0x0c0000, 0x8c0000, 0x2c0000, 0xac0000, 0x040000, 0x840000, 0x240000, 0xa40000 },
- { 0xf00000, 0x700000, 0xd00000, 0x500000, 0xf80000, 0x780000, 0xd80000, 0x580000 },
- { 0x300000, 0xb00000, 0x100000, 0x900000, 0x380000, 0xb80000, 0x180000, 0x980000 },
- { 0xc00000, 0x400000, 0xe00000, 0x600000, 0xc80000, 0x480000, 0xe80000, 0x680000 },
- { 0x000000, 0x800000, 0x200000, 0xa00000, 0x080000, 0x880000, 0x280000, 0xa80000 }
- };
-
-/**
- * Constructs a new, empty ImageData with the given width, height,
- * depth and palette. The data will be initialized to an (all zero)
- * array of the appropriate size.
- *
- * @param width the width of the image
- * @param height the height of the image
- * @param depth the depth of the image
- * @param palette the palette of the image (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the width or height is zero or negative, or if the depth is not
- * one of 1, 2, 4, 8, 16, 24 or 32</li>
- * <li>ERROR_NULL_ARGUMENT - if the palette is null</li>
- * </ul>
- */
-public ImageData(int width, int height, int depth, PaletteData palette) {
- this(width, height, depth, palette,
- 4, null, 0, null,
- null, -1, -1, SWT.IMAGE_UNDEFINED,
- 0, 0, 0, 0);
-}
-
-/**
- * Constructs a new, empty ImageData with the given width, height,
- * depth, palette, scanlinePad and data.
- *
- * @param width the width of the image
- * @param height the height of the image
- * @param depth the depth of the image
- * @param palette the palette of the image
- * @param scanlinePad the padding of each line, in bytes
- * @param data the data of the image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the width or height is zero or negative, or if the depth is not
- * one of 1, 2, 4, 8, 16, 24 or 32, or the data array is too small to contain the image data</li>
- * <li>ERROR_NULL_ARGUMENT - if the palette or data is null</li>
- * <li>ERROR_CANNOT_BE_ZERO - if the scanlinePad is zero</li>
- * </ul>
- */
-public ImageData(int width, int height, int depth, PaletteData palette, int scanlinePad, byte[] data) {
- this(width, height, depth, palette,
- scanlinePad, checkData(data), 0, null,
- null, -1, -1, SWT.IMAGE_UNDEFINED,
- 0, 0, 0, 0);
-}
-
-/**
- * Constructs an <code>ImageData</code> loaded from the specified
- * input stream. Throws an error if an error occurs while loading
- * the image, or if the image has an unsupported type. Application
- * code is still responsible for closing the input stream.
- * <p>
- * This constructor is provided for convenience when loading a single
- * image only. If the stream contains multiple images, only the first
- * one will be loaded. To load multiple images, use
- * <code>ImageLoader.load()</code>.
- * </p><p>
- * This constructor may be used to load a resource as follows:
- * </p>
- * <pre>
- * static ImageData loadImageData (Class clazz, String string) {
- * InputStream stream = clazz.getResourceAsStream (string);
- * if (stream == null) return null;
- * ImageData imageData = null;
- * try {
- * imageData = new ImageData (stream);
- * } catch (SWTException ex) {
- * } finally {
- * try {
- * stream.close ();
- * } catch (IOException ex) {}
- * }
- * return imageData;
- * }
- * </pre>
- *
- * @param stream the input stream to load the image from (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the stream is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from the stream</li>
- * <li>ERROR_INVALID_IMAGE - if the image stream contains invalid data</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format</li>
- * </ul>
- *
- * @see ImageLoader#load(InputStream)
- */
-public ImageData(InputStream stream) {
- ImageData[] data = ImageDataLoader.load(stream);
- if (data.length < 1) SWT.error(SWT.ERROR_INVALID_IMAGE);
- ImageData i = data[0];
- setAllFields(
- i.width,
- i.height,
- i.depth,
- i.scanlinePad,
- i.bytesPerLine,
- i.data,
- i.palette,
- i.transparentPixel,
- i.maskData,
- i.maskPad,
- i.alphaData,
- i.alpha,
- i.type,
- i.x,
- i.y,
- i.disposalMethod,
- i.delayTime);
-}
-
-/**
- * Constructs an <code>ImageData</code> loaded from a file with the
- * specified name. Throws an error if an error occurs loading the
- * image, or if the image has an unsupported type.
- * <p>
- * This constructor is provided for convenience when loading a single
- * image only. If the file contains multiple images, only the first
- * one will be loaded. To load multiple images, use
- * <code>ImageLoader.load()</code>.
- * </p>
- *
- * @param filename the name of the file to load the image from (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the file name is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from the file</li>
- * <li>ERROR_INVALID_IMAGE - if the image file contains invalid data</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format</li>
- * </ul>
- */
-public ImageData(String filename) {
- ImageData[] data = ImageDataLoader.load(filename);
- if (data.length < 1) SWT.error(SWT.ERROR_INVALID_IMAGE);
- ImageData i = data[0];
- setAllFields(
- i.width,
- i.height,
- i.depth,
- i.scanlinePad,
- i.bytesPerLine,
- i.data,
- i.palette,
- i.transparentPixel,
- i.maskData,
- i.maskPad,
- i.alphaData,
- i.alpha,
- i.type,
- i.x,
- i.y,
- i.disposalMethod,
- i.delayTime);
-}
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-ImageData() {
-}
-
-/**
- * Constructs an image data by giving values for all non-computable fields.
- * <p>
- * This method is for internal use, and is not described further.
- * </p>
- */
-ImageData(
- int width, int height, int depth, PaletteData palette,
- int scanlinePad, byte[] data, int maskPad, byte[] maskData,
- byte[] alphaData, int alpha, int transparentPixel, int type,
- int x, int y, int disposalMethod, int delayTime)
-{
-
- if (palette == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (!(depth == 1 || depth == 2 || depth == 4 || depth == 8
- || depth == 16 || depth == 24 || depth == 32)) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (width <= 0 || height <= 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (scanlinePad == 0) SWT.error (SWT.ERROR_CANNOT_BE_ZERO);
-
- int bytesPerLine = (((width * depth + 7) / 8) + (scanlinePad - 1))
- / scanlinePad * scanlinePad;
-
- /*
- * When the image is being loaded from a PNG, we need to use the theoretical minimum
- * number of bytes per line to check whether there is enough data, because the actual
- * number of bytes per line is calculated based on the given depth, which may be larger
- * than the actual depth of the PNG.
- */
- int minBytesPerLine = type == SWT.IMAGE_PNG ? ((((width + 7) / 8) + 3) / 4) * 4 : bytesPerLine;
- if (data != null && data.length < minBytesPerLine * height) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- setAllFields(
- width,
- height,
- depth,
- scanlinePad,
- bytesPerLine,
- data != null ? data : new byte[bytesPerLine * height],
- palette,
- transparentPixel,
- maskData,
- maskPad,
- alphaData,
- alpha,
- type,
- x,
- y,
- disposalMethod,
- delayTime);
-}
-
-/**
- * Initializes all fields in the receiver. This method must be called
- * by all public constructors to ensure that all fields are initialized
- * for a new ImageData object. If a new field is added to the class,
- * then it must be added to this method.
- * <p>
- * This method is for internal use, and is not described further.
- * </p>
- */
-void setAllFields(int width, int height, int depth, int scanlinePad,
- int bytesPerLine, byte[] data, PaletteData palette, int transparentPixel,
- byte[] maskData, int maskPad, byte[] alphaData, int alpha,
- int type, int x, int y, int disposalMethod, int delayTime) {
-
- this.width = width;
- this.height = height;
- this.depth = depth;
- this.scanlinePad = scanlinePad;
- this.bytesPerLine = bytesPerLine;
- this.data = data;
- this.palette = palette;
- this.transparentPixel = transparentPixel;
- this.maskData = maskData;
- this.maskPad = maskPad;
- this.alphaData = alphaData;
- this.alpha = alpha;
- this.type = type;
- this.x = x;
- this.y = y;
- this.disposalMethod = disposalMethod;
- this.delayTime = delayTime;
-}
-
-/**
- * Invokes internal SWT functionality to create a new instance of
- * this class.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>ImageData</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is subject
- * to change without notice, and should never be called from
- * application code.
- * </p>
- * <p>
- * This method is for internal use, and is not described further.
- * </p>
- */
-public static ImageData internal_new(
- int width, int height, int depth, PaletteData palette,
- int scanlinePad, byte[] data, int maskPad, byte[] maskData,
- byte[] alphaData, int alpha, int transparentPixel, int type,
- int x, int y, int disposalMethod, int delayTime)
-{
- return new ImageData(
- width, height, depth, palette, scanlinePad, data, maskPad, maskData,
- alphaData, alpha, transparentPixel, type, x, y, disposalMethod, delayTime);
-}
-
-ImageData colorMaskImage(int pixel) {
- ImageData mask = new ImageData(width, height, 1, bwPalette(),
- 2, null, 0, null, null, -1, -1, SWT.IMAGE_UNDEFINED,
- 0, 0, 0, 0);
- int[] row = new int[width];
- for (int y = 0; y < height; y++) {
- getPixels(0, y, width, row, 0);
- for (int i = 0; i < width; i++) {
- if (pixel != -1 && row[i] == pixel) {
- row[i] = 0;
- } else {
- row[i] = 1;
- }
- }
- mask.setPixels(0, y, width, row, 0);
- }
- return mask;
-}
-
-static byte[] checkData(byte [] data) {
- if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return data;
-}
-
-/**
- * Returns a new instance of the same class as the receiver,
- * whose slots have been filled in with <em>copies</em> of
- * the values in the slots of the receiver. That is, the
- * returned object is a <em>deep copy</em> of the receiver.
- *
- * @return a copy of the receiver.
- */
-public Object clone() {
- byte[] cloneData = new byte[data.length];
- System.arraycopy(data, 0, cloneData, 0, data.length);
- byte[] cloneMaskData = null;
- if (maskData != null) {
- cloneMaskData = new byte[maskData.length];
- System.arraycopy(maskData, 0, cloneMaskData, 0, maskData.length);
- }
- byte[] cloneAlphaData = null;
- if (alphaData != null) {
- cloneAlphaData = new byte[alphaData.length];
- System.arraycopy(alphaData, 0, cloneAlphaData, 0, alphaData.length);
- }
- return new ImageData(
- width,
- height,
- depth,
- palette,
- scanlinePad,
- cloneData,
- maskPad,
- cloneMaskData,
- cloneAlphaData,
- alpha,
- transparentPixel,
- type,
- x,
- y,
- disposalMethod,
- delayTime);
-}
-
-/**
- * Returns the alpha value at offset <code>x</code> in
- * scanline <code>y</code> in the receiver's alpha data.
- * The alpha value is between 0 (transparent) and
- * 255 (opaque).
- *
- * @param x the x coordinate of the pixel to get the alpha value of
- * @param y the y coordinate of the pixel to get the alpha value of
- * @return the alpha value at the given coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if either argument is out of range</li>
- * </ul>
- */
-public int getAlpha(int x, int y) {
- if (x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-
- if (alphaData == null) return 255;
- return alphaData[y * width + x] & 0xFF;
-}
-
-/**
- * Returns <code>getWidth</code> alpha values starting at offset
- * <code>x</code> in scanline <code>y</code> in the receiver's alpha
- * data starting at <code>startIndex</code>. The alpha values
- * are unsigned, between <code>(byte)0</code> (transparent) and
- * <code>(byte)255</code> (opaque).
- *
- * @param x the x position of the pixel to begin getting alpha values
- * @param y the y position of the pixel to begin getting alpha values
- * @param getWidth the width of the data to get
- * @param alphas the buffer in which to put the alpha values
- * @param startIndex the offset into the image to begin getting alpha values
- *
- * @exception IndexOutOfBoundsException if getWidth is too large
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if pixels is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li>
- * <li>ERROR_INVALID_ARGUMENT - if getWidth is negative</li>
- * </ul>
- */
-public void getAlphas(int x, int y, int getWidth, byte[] alphas, int startIndex) {
- if (alphas == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (getWidth < 0 || x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (getWidth == 0) return;
-
- if (alphaData == null) {
- int endIndex = startIndex + getWidth;
- for (int i = startIndex; i < endIndex; i++) {
- alphas[i] = (byte)255;
- }
- return;
- }
- // may throw an IndexOutOfBoundsException
- System.arraycopy(alphaData, y * width + x, alphas, startIndex, getWidth);
-}
-
-/**
- * Returns the pixel value at offset <code>x</code> in
- * scanline <code>y</code> in the receiver's data.
- *
- * @param x the x position of the pixel to get
- * @param y the y position of the pixel to get
- * @return the pixel at the given coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if either argument is out of bounds</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH if the depth is not one of 1, 2, 4, 8, 16, 24 or 32</li>
- * </ul>
- */
-public int getPixel(int x, int y) {
- if (x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int index;
- int theByte;
- int mask;
- switch (depth) {
- case 32:
- index = (y * bytesPerLine) + (x * 4);
- return ((data[index] & 0xFF) << 24) + ((data[index+1] & 0xFF) << 16) +
- ((data[index+2] & 0xFF) << 8) + (data[index+3] & 0xFF);
- case 24:
- index = (y * bytesPerLine) + (x * 3);
- return ((data[index] & 0xFF) << 16) + ((data[index+1] & 0xFF) << 8) +
- (data[index+2] & 0xFF);
- case 16:
- index = (y * bytesPerLine) + (x * 2);
- return ((data[index+1] & 0xFF) << 8) + (data[index] & 0xFF);
- case 8:
- index = (y * bytesPerLine) + x ;
- return data[index] & 0xFF;
- case 4:
- index = (y * bytesPerLine) + (x >> 1);
- theByte = data[index] & 0xFF;
- if ((x & 0x1) == 0) {
- return theByte >> 4;
- } else {
- return theByte & 0x0F;
- }
- case 2:
- index = (y * bytesPerLine) + (x >> 2);
- theByte = data[index] & 0xFF;
- int offset = 3 - (x % 4);
- mask = 3 << (offset * 2);
- return (theByte & mask) >> (offset * 2);
- case 1:
- index = (y * bytesPerLine) + (x >> 3);
- theByte = data[index] & 0xFF;
- mask = 1 << (7 - (x & 0x7));
- if ((theByte & mask) == 0) {
- return 0;
- } else {
- return 1;
- }
- }
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- return 0;
-}
-
-/**
- * Returns <code>getWidth</code> pixel values starting at offset
- * <code>x</code> in scanline <code>y</code> in the receiver's
- * data starting at <code>startIndex</code>.
- *
- * @param x the x position of the first pixel to get
- * @param y the y position of the first pixel to get
- * @param getWidth the width of the data to get
- * @param pixels the buffer in which to put the pixels
- * @param startIndex the offset into the byte array to begin storing pixels
- *
- * @exception IndexOutOfBoundsException if getWidth is too large
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if pixels is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li>
- * <li>ERROR_INVALID_ARGUMENT - if getWidth is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth is not one of 1, 2, 4 or 8
- * (For higher depths, use the int[] version of this method.)</li>
- * </ul>
- */
-public void getPixels(int x, int y, int getWidth, byte[] pixels, int startIndex) {
- if (pixels == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (getWidth < 0 || x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (getWidth == 0) return;
- int index;
- int theByte;
- int mask = 0;
- int n = getWidth;
- int i = startIndex;
- int srcX = x, srcY = y;
- switch (depth) {
- case 8:
- index = (y * bytesPerLine) + x;
- for (int j = 0; j < getWidth; j++) {
- pixels[i] = data[index];
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index++;
- }
- }
- return;
- case 4:
- index = (y * bytesPerLine) + (x >> 1);
- if ((x & 0x1) == 1) {
- theByte = data[index] & 0xFF;
- pixels[i] = (byte)(theByte & 0x0F);
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index++;
- }
- }
- while (n > 1) {
- theByte = data[index] & 0xFF;
- pixels[i] = (byte)(theByte >> 4);
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- pixels[i] = (byte)(theByte & 0x0F);
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index++;
- }
- }
- }
- if (n > 0) {
- theByte = data[index] & 0xFF;
- pixels[i] = (byte)(theByte >> 4);
- }
- return;
- case 2:
- index = (y * bytesPerLine) + (x >> 2);
- theByte = data[index] & 0xFF;
- int offset;
- while (n > 0) {
- offset = 3 - (srcX % 4);
- mask = 3 << (offset * 2);
- pixels[i] = (byte)((theByte & mask) >> (offset * 2));
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- if (n > 0) theByte = data[index] & 0xFF;
- srcX = 0;
- } else {
- if (offset == 0) {
- index++;
- theByte = data[index] & 0xFF;
- }
- }
- }
- return;
- case 1:
- index = (y * bytesPerLine) + (x >> 3);
- theByte = data[index] & 0xFF;
- while (n > 0) {
- mask = 1 << (7 - (srcX & 0x7));
- if ((theByte & mask) == 0) {
- pixels[i] = 0;
- } else {
- pixels[i] = 1;
- }
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- if (n > 0) theByte = data[index] & 0xFF;
- srcX = 0;
- } else {
- if (mask == 1) {
- index++;
- if (n > 0) theByte = data[index] & 0xFF;
- }
- }
- }
- return;
- }
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
-}
-
-/**
- * Returns <code>getWidth</code> pixel values starting at offset
- * <code>x</code> in scanline <code>y</code> in the receiver's
- * data starting at <code>startIndex</code>.
- *
- * @param x the x position of the first pixel to get
- * @param y the y position of the first pixel to get
- * @param getWidth the width of the data to get
- * @param pixels the buffer in which to put the pixels
- * @param startIndex the offset into the buffer to begin storing pixels
- *
- * @exception IndexOutOfBoundsException if getWidth is too large
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if pixels is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li>
- * <li>ERROR_INVALID_ARGUMENT - if getWidth is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth is not one of 1, 2, 4, 8, 16, 24 or 32</li>
- * </ul>
- */
-public void getPixels(int x, int y, int getWidth, int[] pixels, int startIndex) {
- if (pixels == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (getWidth < 0 || x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (getWidth == 0) return;
- int index;
- int theByte;
- int mask;
- int n = getWidth;
- int i = startIndex;
- int srcX = x, srcY = y;
- switch (depth) {
- case 32:
- index = (y * bytesPerLine) + (x * 4);
- i = startIndex;
- for (int j = 0; j < getWidth; j++) {
- pixels[i] = ((data[index] & 0xFF) << 24) | ((data[index+1] & 0xFF) << 16)
- | ((data[index+2] & 0xFF) << 8) | (data[index+3] & 0xFF);
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index += 4;
- }
- }
- return;
- case 24:
- index = (y * bytesPerLine) + (x * 3);
- for (int j = 0; j < getWidth; j++) {
- pixels[i] = ((data[index] & 0xFF) << 16) | ((data[index+1] & 0xFF) << 8)
- | (data[index+2] & 0xFF);
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index += 3;
- }
- }
- return;
- case 16:
- index = (y * bytesPerLine) + (x * 2);
- for (int j = 0; j < getWidth; j++) {
- pixels[i] = ((data[index+1] & 0xFF) << 8) + (data[index] & 0xFF);
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index += 2;
- }
- }
- return;
- case 8:
- index = (y * bytesPerLine) + x;
- for (int j = 0; j < getWidth; j++) {
- pixels[i] = data[index] & 0xFF;
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index++;
- }
- }
- return;
- case 4:
- index = (y * bytesPerLine) + (x >> 1);
- if ((x & 0x1) == 1) {
- theByte = data[index] & 0xFF;
- pixels[i] = theByte & 0x0F;
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index++;
- }
- }
- while (n > 1) {
- theByte = data[index] & 0xFF;
- pixels[i] = theByte >> 4;
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- pixels[i] = theByte & 0x0F;
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index++;
- }
- }
- }
- if (n > 0) {
- theByte = data[index] & 0xFF;
- pixels[i] = theByte >> 4;
- }
- return;
- case 2:
- index = (y * bytesPerLine) + (x >> 2);
- theByte = data[index] & 0xFF;
- int offset;
- while (n > 0) {
- offset = 3 - (srcX % 4);
- mask = 3 << (offset * 2);
- pixels[i] = (byte)((theByte & mask) >> (offset * 2));
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- if (n > 0) theByte = data[index] & 0xFF;
- srcX = 0;
- } else {
- if (offset == 0) {
- index++;
- theByte = data[index] & 0xFF;
- }
- }
- }
- return;
- case 1:
- index = (y * bytesPerLine) + (x >> 3);
- theByte = data[index] & 0xFF;
- while (n > 0) {
- mask = 1 << (7 - (srcX & 0x7));
- if ((theByte & mask) == 0) {
- pixels[i] = 0;
- } else {
- pixels[i] = 1;
- }
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- if (n > 0) theByte = data[index] & 0xFF;
- srcX = 0;
- } else {
- if (mask == 1) {
- index++;
- if (n > 0) theByte = data[index] & 0xFF;
- }
- }
- }
- return;
- }
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
-}
-
-/**
- * Returns an array of <code>RGB</code>s which comprise the
- * indexed color table of the receiver, or null if the receiver
- * has a direct color model.
- *
- * @return the RGB values for the image or null if direct color
- *
- * @see PaletteData#getRGBs()
- */
-public RGB[] getRGBs() {
- return palette.getRGBs();
-}
-
-/**
- * Returns an <code>ImageData</code> which specifies the
- * transparency mask information for the receiver. If the
- * receiver has no transparency or is not an icon, returns
- * an opaque mask.
- *
- * @return the transparency mask
- */
-public ImageData getTransparencyMask() {
- if (getTransparencyType() == SWT.TRANSPARENCY_MASK) {
- return new ImageData(width, height, 1, bwPalette(), maskPad, maskData);
- } else {
- return colorMaskImage(transparentPixel);
- }
-}
-
-/**
- * Returns the image transparency type, which will be one of
- * <code>SWT.TRANSPARENCY_NONE</code>, <code>SWT.TRANSPARENCY_MASK</code>,
- * <code>SWT.TRANSPARENCY_PIXEL</code> or <code>SWT.TRANSPARENCY_ALPHA</code>.
- *
- * @return the receiver's transparency type
- */
-public int getTransparencyType() {
- if (maskData != null) return SWT.TRANSPARENCY_MASK;
- if (transparentPixel != -1) return SWT.TRANSPARENCY_PIXEL;
- if (alphaData != null) return SWT.TRANSPARENCY_ALPHA;
- return SWT.TRANSPARENCY_NONE;
-}
-
-/**
- * Returns the byte order of the receiver.
- *
- * @return MSB_FIRST or LSB_FIRST
- */
-int getByteOrder() {
- return depth != 16 ? MSB_FIRST : LSB_FIRST;
-}
-
-/**
- * Returns a copy of the receiver which has been stretched or
- * shrunk to the specified size. If either the width or height
- * is negative, the resulting image will be inverted in the
- * associated axis.
- *
- * @param width the width of the new ImageData
- * @param height the height of the new ImageData
- * @return a scaled copy of the image
- */
-public ImageData scaledTo(int width, int height) {
- /* Create a destination image with no data */
- final boolean flipX = (width < 0);
- if (flipX) width = - width;
- final boolean flipY = (height < 0);
- if (flipY) height = - height;
-
- ImageData dest = new ImageData(
- width, height, depth, palette,
- scanlinePad, null, 0, null,
- null, -1, transparentPixel, type,
- x, y, disposalMethod, delayTime);
-
- /* Scale the image contents */
- if (palette.isDirect) blit(BLIT_SRC,
- this.data, this.depth, this.bytesPerLine, this.getByteOrder(), 0, 0, this.width, this.height, 0, 0, 0,
- ALPHA_OPAQUE, null, 0, 0, 0,
- dest.data, dest.depth, dest.bytesPerLine, dest.getByteOrder(), 0, 0, dest.width, dest.height, 0, 0, 0,
- flipX, flipY);
- else blit(BLIT_SRC,
- this.data, this.depth, this.bytesPerLine, this.getByteOrder(), 0, 0, this.width, this.height, null, null, null,
- ALPHA_OPAQUE, null, 0, 0, 0,
- dest.data, dest.depth, dest.bytesPerLine, dest.getByteOrder(), 0, 0, dest.width, dest.height, null, null, null,
- flipX, flipY);
-
- /* Scale the image mask or alpha */
- if (maskData != null) {
- dest.maskPad = this.maskPad;
- int destBpl = (dest.width + 7) / 8;
- destBpl = (destBpl + (dest.maskPad - 1)) / dest.maskPad * dest.maskPad;
- dest.maskData = new byte[destBpl * dest.height];
- int srcBpl = (this.width + 7) / 8;
- srcBpl = (srcBpl + (this.maskPad - 1)) / this.maskPad * this.maskPad;
- blit(BLIT_SRC,
- this.maskData, 1, srcBpl, MSB_FIRST, 0, 0, this.width, this.height, null, null, null,
- ALPHA_OPAQUE, null, 0, 0, 0,
- dest.maskData, 1, destBpl, MSB_FIRST, 0, 0, dest.width, dest.height, null, null, null,
- flipX, flipY);
- } else if (alpha != -1) {
- dest.alpha = this.alpha;
- } else if (alphaData != null) {
- dest.alphaData = new byte[dest.width * dest.height];
- blit(BLIT_SRC,
- this.alphaData, 8, this.width, MSB_FIRST, 0, 0, this.width, this.height, null, null, null,
- ALPHA_OPAQUE, null, 0, 0, 0,
- dest.alphaData, 8, dest.width, MSB_FIRST, 0, 0, dest.width, dest.height, null, null, null,
- flipX, flipY);
- }
- return dest;
-}
-
-/**
- * Sets the alpha value at offset <code>x</code> in
- * scanline <code>y</code> in the receiver's alpha data.
- * The alpha value must be between 0 (transparent)
- * and 255 (opaque).
- *
- * @param x the x coordinate of the alpha value to set
- * @param y the y coordinate of the alpha value to set
- * @param alpha the value to set the alpha to
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li>
- * </ul>
- */
-public void setAlpha(int x, int y, int alpha) {
- if (x >= width || y >= height || x < 0 || y < 0 || alpha < 0 || alpha > 255)
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-
- if (alphaData == null) alphaData = new byte[width * height];
- alphaData[y * width + x] = (byte)alpha;
-}
-
-/**
- * Sets the alpha values starting at offset <code>x</code> in
- * scanline <code>y</code> in the receiver's alpha data to the
- * values from the array <code>alphas</code> starting at
- * <code>startIndex</code>. The alpha values must be between
- * <code>(byte)0</code> (transparent) and <code>(byte)255</code> (opaque)
- *
- * @param x the x coordinate of the pixel to being setting the alpha values
- * @param y the y coordinate of the pixel to being setting the alpha values
- * @param putWidth the width of the alpha values to set
- * @param alphas the alpha values to set
- * @param startIndex the index at which to begin setting
- *
- * @exception IndexOutOfBoundsException if putWidth is too large
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if pixels is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li>
- * <li>ERROR_INVALID_ARGUMENT - if putWidth is negative</li>
- * </ul>
- */
-public void setAlphas(int x, int y, int putWidth, byte[] alphas, int startIndex) {
- if (alphas == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (putWidth < 0 || x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (putWidth == 0) return;
-
- if (alphaData == null) alphaData = new byte[width * height];
- // may throw an IndexOutOfBoundsException
- System.arraycopy(alphas, startIndex, alphaData, y * width + x, putWidth);
-}
-
-/**
- * Sets the pixel value at offset <code>x</code> in
- * scanline <code>y</code> in the receiver's data.
- *
- * @param x the x coordinate of the pixel to set
- * @param y the y coordinate of the pixel to set
- * @param pixelValue the value to set the pixel to
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH if the depth is not one of 1, 2, 4, 8, 16, 24 or 32</li>
- * </ul>
- */
-public void setPixel(int x, int y, int pixelValue) {
- if (x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int index;
- byte theByte;
- int mask;
- switch (depth) {
- case 32:
- index = (y * bytesPerLine) + (x * 4);
- data[index] = (byte)((pixelValue >> 24) & 0xFF);
- data[index + 1] = (byte)((pixelValue >> 16) & 0xFF);
- data[index + 2] = (byte)((pixelValue >> 8) & 0xFF);
- data[index + 3] = (byte)(pixelValue & 0xFF);
- return;
- case 24:
- index = (y * bytesPerLine) + (x * 3);
- data[index] = (byte)((pixelValue >> 16) & 0xFF);
- data[index + 1] = (byte)((pixelValue >> 8) & 0xFF);
- data[index + 2] = (byte)(pixelValue & 0xFF);
- return;
- case 16:
- index = (y * bytesPerLine) + (x * 2);
- data[index + 1] = (byte)((pixelValue >> 8) & 0xFF);
- data[index] = (byte)(pixelValue & 0xFF);
- return;
- case 8:
- index = (y * bytesPerLine) + x ;
- data[index] = (byte)(pixelValue & 0xFF);
- return;
- case 4:
- index = (y * bytesPerLine) + (x >> 1);
- if ((x & 0x1) == 0) {
- data[index] = (byte)((data[index] & 0x0F) | ((pixelValue & 0x0F) << 4));
- } else {
- data[index] = (byte)((data[index] & 0xF0) | (pixelValue & 0x0F));
- }
- return;
- case 2:
- index = (y * bytesPerLine) + (x >> 2);
- theByte = data[index];
- int offset = 3 - (x % 4);
- mask = 0xFF ^ (3 << (offset * 2));
- data[index] = (byte)((data[index] & mask) | (pixelValue << (offset * 2)));
- return;
- case 1:
- index = (y * bytesPerLine) + (x >> 3);
- theByte = data[index];
- mask = 1 << (7 - (x & 0x7));
- if ((pixelValue & 0x1) == 1) {
- data[index] = (byte)(theByte | mask);
- } else {
- data[index] = (byte)(theByte & (mask ^ -1));
- }
- return;
- }
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
-}
-
-/**
- * Sets the pixel values starting at offset <code>x</code> in
- * scanline <code>y</code> in the receiver's data to the
- * values from the array <code>pixels</code> starting at
- * <code>startIndex</code>.
- *
- * @param x the x position of the pixel to set
- * @param y the y position of the pixel to set
- * @param putWidth the width of the pixels to set
- * @param pixels the pixels to set
- * @param startIndex the index at which to begin setting
- *
- * @exception IndexOutOfBoundsException if putWidth is too large
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if pixels is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li>
- * <li>ERROR_INVALID_ARGUMENT - if putWidth is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH if the depth is not one of 1, 2, 4, 8
- * (For higher depths, use the int[] version of this method.)</li>
- * </ul>
- */
-public void setPixels(int x, int y, int putWidth, byte[] pixels, int startIndex) {
- if (pixels == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (putWidth < 0 || x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (putWidth == 0) return;
- int index;
- int theByte;
- int mask;
- int n = putWidth;
- int i = startIndex;
- int srcX = x, srcY = y;
- switch (depth) {
- case 8:
- index = (y * bytesPerLine) + x;
- for (int j = 0; j < putWidth; j++) {
- data[index] = (byte)(pixels[i] & 0xFF);
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index++;
- }
- }
- return;
- case 4:
- index = (y * bytesPerLine) + (x >> 1);
- boolean high = (x & 0x1) == 0;
- while (n > 0) {
- theByte = pixels[i] & 0x0F;
- if (high) {
- data[index] = (byte)((data[index] & 0x0F) | (theByte << 4));
- } else {
- data[index] = (byte)((data[index] & 0xF0) | theByte);
- }
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- high = true;
- srcX = 0;
- } else {
- if (!high) index++;
- high = !high;
- }
- }
- return;
- case 2:
- byte [] masks = { (byte)0xFC, (byte)0xF3, (byte)0xCF, (byte)0x3F };
- index = (y * bytesPerLine) + (x >> 2);
- int offset = 3 - (x % 4);
- while (n > 0) {
- theByte = pixels[i] & 0x3;
- data[index] = (byte)((data[index] & masks[offset]) | (theByte << (offset * 2)));
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- offset = 0;
- srcX = 0;
- } else {
- if (offset == 0) {
- index++;
- offset = 3;
- } else {
- offset--;
- }
- }
- }
- return;
- case 1:
- index = (y * bytesPerLine) + (x >> 3);
- while (n > 0) {
- mask = 1 << (7 - (srcX & 0x7));
- if ((pixels[i] & 0x1) == 1) {
- data[index] = (byte)((data[index] & 0xFF) | mask);
- } else {
- data[index] = (byte)((data[index] & 0xFF) & (mask ^ -1));
- }
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- if (mask == 1) {
- index++;
- }
- }
- }
- return;
- }
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
-}
-
-/**
- * Sets the pixel values starting at offset <code>x</code> in
- * scanline <code>y</code> in the receiver's data to the
- * values from the array <code>pixels</code> starting at
- * <code>startIndex</code>.
- *
- * @param x the x position of the pixel to set
- * @param y the y position of the pixel to set
- * @param putWidth the width of the pixels to set
- * @param pixels the pixels to set
- * @param startIndex the index at which to begin setting
- *
- * @exception IndexOutOfBoundsException if putWidth is too large
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if pixels is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li>
- * <li>ERROR_INVALID_ARGUMENT - if putWidth is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH if the depth is not one of 1, 2, 4, 8, 16, 24 or 32</li>
- * </ul>
- */
-public void setPixels(int x, int y, int putWidth, int[] pixels, int startIndex) {
- if (pixels == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (putWidth < 0 || x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (putWidth == 0) return;
- int index;
- int theByte;
- int mask;
- int n = putWidth;
- int i = startIndex;
- int pixel;
- int srcX = x, srcY = y;
- switch (depth) {
- case 32:
- index = (y * bytesPerLine) + (x * 4);
- for (int j = 0; j < putWidth; j++) {
- pixel = pixels[i];
- data[index] = (byte)((pixel >> 24) & 0xFF);
- data[index + 1] = (byte)((pixel >> 16) & 0xFF);
- data[index + 2] = (byte)((pixel >> 8) & 0xFF);
- data[index + 3] = (byte)(pixel & 0xFF);
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index += 4;
- }
- }
- return;
- case 24:
- index = (y * bytesPerLine) + (x * 3);
- for (int j = 0; j < putWidth; j++) {
- pixel = pixels[i];
- data[index] = (byte)((pixel >> 16) & 0xFF);
- data[index + 1] = (byte)((pixel >> 8) & 0xFF);
- data[index + 2] = (byte)(pixel & 0xFF);
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index += 3;
- }
- }
- return;
- case 16:
- index = (y * bytesPerLine) + (x * 2);
- for (int j = 0; j < putWidth; j++) {
- pixel = pixels[i];
- data[index] = (byte)(pixel & 0xFF);
- data[index + 1] = (byte)((pixel >> 8) & 0xFF);
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index += 2;
- }
- }
- return;
- case 8:
- index = (y * bytesPerLine) + x;
- for (int j = 0; j < putWidth; j++) {
- data[index] = (byte)(pixels[i] & 0xFF);
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index++;
- }
- }
- return;
- case 4:
- index = (y * bytesPerLine) + (x >> 1);
- boolean high = (x & 0x1) == 0;
- while (n > 0) {
- theByte = pixels[i] & 0x0F;
- if (high) {
- data[index] = (byte)((data[index] & 0x0F) | (theByte << 4));
- } else {
- data[index] = (byte)((data[index] & 0xF0) | theByte);
- }
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- high = true;
- srcX = 0;
- } else {
- if (!high) index++;
- high = !high;
- }
- }
- return;
- case 2:
- byte [] masks = { (byte)0xFC, (byte)0xF3, (byte)0xCF, (byte)0x3F };
- index = (y * bytesPerLine) + (x >> 2);
- int offset = 3 - (x % 4);
- while (n > 0) {
- theByte = pixels[i] & 0x3;
- data[index] = (byte)((data[index] & masks[offset]) | (theByte << (offset * 2)));
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- offset = 3;
- srcX = 0;
- } else {
- if (offset == 0) {
- index++;
- offset = 3;
- } else {
- offset--;
- }
- }
- }
- return;
- case 1:
- index = (y * bytesPerLine) + (x >> 3);
- while (n > 0) {
- mask = 1 << (7 - (srcX & 0x7));
- if ((pixels[i] & 0x1) == 1) {
- data[index] = (byte)((data[index] & 0xFF) | mask);
- } else {
- data[index] = (byte)((data[index] & 0xFF) & (mask ^ -1));
- }
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- if (mask == 1) {
- index++;
- }
- }
- }
- return;
- }
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
-}
-
-/**
- * Returns a palette with 2 colors: black & white.
- */
-static PaletteData bwPalette() {
- return new PaletteData(new RGB[] {new RGB(0, 0, 0), new RGB(255, 255, 255)});
-}
-
-/**
- * Gets the offset of the most significant bit for
- * the given mask.
- */
-static int getMSBOffset(int mask) {
- for (int i = 31; i >= 0; i--) {
- if (((mask >> i) & 0x1) != 0) return i + 1;
- }
- return 0;
-}
-
-/**
- * Finds the closest match.
- */
-static int closestMatch(int depth, byte red, byte green, byte blue, int redMask, int greenMask, int blueMask, byte[] reds, byte[] greens, byte[] blues) {
- if (depth > 8) {
- int rshift = 32 - getMSBOffset(redMask);
- int gshift = 32 - getMSBOffset(greenMask);
- int bshift = 32 - getMSBOffset(blueMask);
- return (((red << 24) >>> rshift) & redMask) |
- (((green << 24) >>> gshift) & greenMask) |
- (((blue << 24) >>> bshift) & blueMask);
- }
- int r, g, b;
- int minDistance = 0x7fffffff;
- int nearestPixel = 0;
- int n = reds.length;
- for (int j = 0; j < n; j++) {
- r = (reds[j] & 0xFF) - (red & 0xFF);
- g = (greens[j] & 0xFF) - (green & 0xFF);
- b = (blues[j] & 0xFF) - (blue & 0xFF);
- int distance = r*r + g*g + b*b;
- if (distance < minDistance) {
- nearestPixel = j;
- if (distance == 0) break;
- minDistance = distance;
- }
- }
- return nearestPixel;
-}
-
-static final ImageData convertMask(ImageData mask) {
- if (mask.depth == 1) return mask;
- PaletteData palette = new PaletteData(new RGB[] {new RGB(0, 0, 0), new RGB(255,255,255)});
- ImageData newMask = new ImageData(mask.width, mask.height, 1, palette);
- /* Find index of black in mask palette */
- int blackIndex = 0;
- RGB[] rgbs = mask.getRGBs();
- if (rgbs != null) {
- while (blackIndex < rgbs.length) {
- if (rgbs[blackIndex].equals(palette.colors[0])) break;
- blackIndex++;
- }
- }
- int[] pixels = new int[mask.width];
- for (int y = 0; y < mask.height; y++) {
- mask.getPixels(0, y, mask.width, pixels, 0);
- for (int i = 0; i < pixels.length; i++) {
- if (pixels[i] == blackIndex) {
- pixels[i] = 0;
- } else {
- pixels[i] = 1;
- }
- }
- newMask.setPixels(0, y, mask.width, pixels, 0);
- }
- return newMask;
-}
-
-static final byte[] convertPad(byte[] data, int width, int height, int depth, int pad, int newPad) {
- if (pad == newPad) return data;
- int stride = (width * depth + 7) / 8;
- int bpl = (stride + (pad - 1)) / pad * pad;
- int newBpl = (stride + (newPad - 1)) / newPad * newPad;
- byte[] newData = new byte[height * newBpl];
- int srcIndex = 0, destIndex = 0;
- for (int y = 0; y < height; y++) {
- System.arraycopy(data, srcIndex, newData, destIndex, stride);
- srcIndex += bpl;
- destIndex += newBpl;
- }
- return newData;
-}
-
-/**
- * Blit operation bits to be OR'ed together to specify the desired operation.
- */
-static final int
- BLIT_SRC = 1, // copy source directly, else applies logic operations
- BLIT_ALPHA = 2, // enable alpha blending
- BLIT_DITHER = 4; // enable dithering in low color modes
-
-/**
- * Alpha mode, values 0 - 255 specify global alpha level
- */
-static final int
- ALPHA_OPAQUE = 255, // Fully opaque (ignores any alpha data)
- ALPHA_TRANSPARENT = 0, // Fully transparent (ignores any alpha data)
- ALPHA_CHANNEL_SEPARATE = -1, // Use alpha channel from separate alphaData
- ALPHA_CHANNEL_SOURCE = -2, // Use alpha channel embedded in sourceData
- ALPHA_MASK_UNPACKED = -3, // Use transparency mask formed by bytes in alphaData (non-zero is opaque)
- ALPHA_MASK_PACKED = -4, // Use transparency mask formed by packed bits in alphaData
- ALPHA_MASK_INDEX = -5, // Consider source palette indices transparent if in alphaData array
- ALPHA_MASK_RGB = -6; // Consider source RGBs transparent if in RGB888 format alphaData array
-
-/**
- * Byte and bit order constants.
- */
-static final int LSB_FIRST = 0;
-static final int MSB_FIRST = 1;
-
-/**
- * Data types (internal)
- */
-private static final int
- // direct / true color formats with arbitrary masks & shifts
- TYPE_GENERIC_8 = 0,
- TYPE_GENERIC_16_MSB = 1,
- TYPE_GENERIC_16_LSB = 2,
- TYPE_GENERIC_24 = 3,
- TYPE_GENERIC_32_MSB = 4,
- TYPE_GENERIC_32_LSB = 5,
- // palette indexed color formats
- TYPE_INDEX_8 = 6,
- TYPE_INDEX_4 = 7,
- TYPE_INDEX_2 = 8,
- TYPE_INDEX_1_MSB = 9,
- TYPE_INDEX_1_LSB = 10;
-
-/**
- * Blits a direct palette image into a direct palette image.
- * <p>
- * Note: When the source and destination depth, order and masks
- * are pairwise equal and the blitter operation is BLIT_SRC,
- * the masks are ignored. Hence when not changing the image
- * data format, 0 may be specified for the masks.
- * </p>
- *
- * @param op the blitter operation: a combination of BLIT_xxx flags
- * (see BLIT_xxx constants)
- * @param srcData the source byte array containing image data
- * @param srcDepth the source depth: one of 8, 16, 24, 32
- * @param srcStride the source number of bytes per line
- * @param srcOrder the source byte ordering: one of MSB_FIRST or LSB_FIRST;
- * ignored if srcDepth is not 16 or 32
- * @param srcX the top-left x-coord of the source blit region
- * @param srcY the top-left y-coord of the source blit region
- * @param srcWidth the width of the source blit region
- * @param srcHeight the height of the source blit region
- * @param srcRedMask the source red channel mask
- * @param srcGreenMask the source green channel mask
- * @param srcBlueMask the source blue channel mask
- * @param alphaMode the alpha blending or mask mode, may be
- * an integer 0-255 for global alpha; ignored if BLIT_ALPHA
- * not specified in the blitter operations
- * (see ALPHA_MODE_xxx constants)
- * @param alphaData the alpha blending or mask data, varies depending
- * on the value of alphaMode and sometimes ignored
- * @param alphaStride the alpha data number of bytes per line
- * @param alphaX the top-left x-coord of the alpha blit region
- * @param alphaY the top-left y-coord of the alpha blit region
- * @param destData the destination byte array containing image data
- * @param destDepth the destination depth: one of 8, 16, 24, 32
- * @param destStride the destination number of bytes per line
- * @param destOrder the destination byte ordering: one of MSB_FIRST or LSB_FIRST;
- * ignored if destDepth is not 16 or 32
- * @param destX the top-left x-coord of the destination blit region
- * @param destY the top-left y-coord of the destination blit region
- * @param destWidth the width of the destination blit region
- * @param destHeight the height of the destination blit region
- * @param destRedMask the destination red channel mask
- * @param destGreenMask the destination green channel mask
- * @param destBlueMask the destination blue channel mask
- * @param flipX if true the resulting image is flipped along the vertical axis
- * @param flipY if true the resulting image is flipped along the horizontal axis
- */
-static void blit(int op,
- byte[] srcData, int srcDepth, int srcStride, int srcOrder,
- int srcX, int srcY, int srcWidth, int srcHeight,
- int srcRedMask, int srcGreenMask, int srcBlueMask,
- int alphaMode, byte[] alphaData, int alphaStride, int alphaX, int alphaY,
- byte[] destData, int destDepth, int destStride, int destOrder,
- int destX, int destY, int destWidth, int destHeight,
- int destRedMask, int destGreenMask, int destBlueMask,
- boolean flipX, boolean flipY) {
- if ((destWidth <= 0) || (destHeight <= 0) || (alphaMode == ALPHA_TRANSPARENT)) return;
-
- // these should be supplied as params later
- final int srcAlphaMask = 0, destAlphaMask = 0;
-
- /*** Prepare scaling data ***/
- final int dwm1 = destWidth - 1;
- final int sfxi = (dwm1 != 0) ? (int)((((long)srcWidth << 16) - 1) / dwm1) : 0;
- final int dhm1 = destHeight - 1;
- final int sfyi = (dhm1 != 0) ? (int)((((long)srcHeight << 16) - 1) / dhm1) : 0;
-
- /*** Prepare source-related data ***/
- final int sbpp, stype;
- switch (srcDepth) {
- case 8:
- sbpp = 1;
- stype = TYPE_GENERIC_8;
- break;
- case 16:
- sbpp = 2;
- stype = (srcOrder == MSB_FIRST) ? TYPE_GENERIC_16_MSB : TYPE_GENERIC_16_LSB;
- break;
- case 24:
- sbpp = 3;
- stype = TYPE_GENERIC_24;
- break;
- case 32:
- sbpp = 4;
- stype = (srcOrder == MSB_FIRST) ? TYPE_GENERIC_32_MSB : TYPE_GENERIC_32_LSB;
- break;
- default:
- //throw new IllegalArgumentException("Invalid source type");
- return;
- }
- int spr = srcY * srcStride + srcX * sbpp;
-
- /*** Prepare destination-related data ***/
- final int dbpp, dtype;
- switch (destDepth) {
- case 8:
- dbpp = 1;
- dtype = TYPE_GENERIC_8;
- break;
- case 16:
- dbpp = 2;
- dtype = (destOrder == MSB_FIRST) ? TYPE_GENERIC_16_MSB : TYPE_GENERIC_16_LSB;
- break;
- case 24:
- dbpp = 3;
- dtype = TYPE_GENERIC_24;
- break;
- case 32:
- dbpp = 4;
- dtype = (destOrder == MSB_FIRST) ? TYPE_GENERIC_32_MSB : TYPE_GENERIC_32_LSB;
- break;
- default:
- //throw new IllegalArgumentException("Invalid destination type");
- return;
- }
- int dpr = ((flipY) ? destY + dhm1 : destY) * destStride + ((flipX) ? destX + dwm1 : destX) * dbpp;
- final int dprxi = (flipX) ? -dbpp : dbpp;
- final int dpryi = (flipY) ? -destStride : destStride;
-
- /*** Prepare special processing data ***/
- int apr;
- if ((op & BLIT_ALPHA) != 0) {
- switch (alphaMode) {
- case ALPHA_MASK_UNPACKED:
- case ALPHA_CHANNEL_SEPARATE:
- if (alphaData == null) alphaMode = 0x10000;
- apr = alphaY * alphaStride + alphaX;
- break;
- case ALPHA_MASK_PACKED:
- if (alphaData == null) alphaMode = 0x10000;
- alphaStride <<= 3;
- apr = alphaY * alphaStride + alphaX;
- break;
- case ALPHA_MASK_INDEX:
- //throw new IllegalArgumentException("Invalid alpha type");
- return;
- case ALPHA_MASK_RGB:
- if (alphaData == null) alphaMode = 0x10000;
- apr = 0;
- break;
- default:
- alphaMode = (alphaMode << 16) / 255; // prescale
- case ALPHA_CHANNEL_SOURCE:
- apr = 0;
- break;
- }
- } else {
- alphaMode = 0x10000;
- apr = 0;
- }
-
- /*** Blit ***/
- int dp = dpr;
- int sp = spr;
- if ((alphaMode == 0x10000) && (stype == dtype) &&
- (srcRedMask == destRedMask) && (srcGreenMask == destGreenMask) &&
- (srcBlueMask == destBlueMask) && (srcAlphaMask == destAlphaMask)) {
- /*** Fast blit (straight copy) ***/
- switch (sbpp) {
- case 1:
- for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) {
- for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) {
- destData[dp] = srcData[sp];
- sp += (sfx >>> 16);
- }
- }
- break;
- case 2:
- for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) {
- for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) {
- destData[dp] = srcData[sp];
- destData[dp + 1] = srcData[sp + 1];
- sp += (sfx >>> 16) * 2;
- }
- }
- break;
- case 3:
- for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) {
- for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) {
- destData[dp] = srcData[sp];
- destData[dp + 1] = srcData[sp + 1];
- destData[dp + 2] = srcData[sp + 2];
- sp += (sfx >>> 16) * 3;
- }
- }
- break;
- case 4:
- for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) {
- for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) {
- destData[dp] = srcData[sp];
- destData[dp + 1] = srcData[sp + 1];
- destData[dp + 2] = srcData[sp + 2];
- destData[dp + 3] = srcData[sp + 3];
- sp += (sfx >>> 16) * 4;
- }
- }
- break;
- }
- return;
- }
- /*Fast 32 to 32 blit */
- if (alphaMode == 0x10000 && stype == TYPE_GENERIC_32_MSB && dtype == TYPE_GENERIC_32_MSB) {
- if (srcRedMask == 0xFF00 && srcGreenMask == 0xff0000 && srcBlueMask == 0xff000000 && destRedMask == 0xFF0000 && destGreenMask == 0xff00 && destBlueMask == 0xff) {
- for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) {
- for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) {
- destData[dp] = srcData[sp + 3];
- destData[dp + 1] = srcData[sp + 2];
- destData[dp + 2] = srcData[sp + 1];
- destData[dp + 3] = srcData[sp];
- sp += (sfx >>> 16) * 4;
- }
- }
- return;
- }
- }
- /*Fast 24 to 32 blit */
- if (alphaMode == 0x10000 && stype == TYPE_GENERIC_24 && dtype == TYPE_GENERIC_32_MSB) {
- if (srcRedMask == 0xFF && srcGreenMask == 0xff00 && srcBlueMask == 0xff0000 && destRedMask == 0xFF0000 && destGreenMask == 0xff00 && destBlueMask == 0xff) {
- for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) {
- for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) {
- destData[dp] = 0;
- destData[dp + 1] = srcData[sp + 2];
- destData[dp + 2] = srcData[sp + 1];
- destData[dp + 3] = srcData[sp];
- sp += (sfx >>> 16) * 3;
- }
- }
- return;
- }
- }
-
- /*** Comprehensive blit (apply transformations) ***/
- final int srcRedShift = getChannelShift(srcRedMask);
- final byte[] srcReds = ANY_TO_EIGHT[getChannelWidth(srcRedMask, srcRedShift)];
- final int srcGreenShift = getChannelShift(srcGreenMask);
- final byte[] srcGreens = ANY_TO_EIGHT[getChannelWidth(srcGreenMask, srcGreenShift)];
- final int srcBlueShift = getChannelShift(srcBlueMask);
- final byte[] srcBlues = ANY_TO_EIGHT[getChannelWidth(srcBlueMask, srcBlueShift)];
- final int srcAlphaShift = getChannelShift(srcAlphaMask);
- final byte[] srcAlphas = ANY_TO_EIGHT[getChannelWidth(srcAlphaMask, srcAlphaShift)];
-
- final int destRedShift = getChannelShift(destRedMask);
- final int destRedWidth = getChannelWidth(destRedMask, destRedShift);
- final byte[] destReds = ANY_TO_EIGHT[destRedWidth];
- final int destRedPreShift = 8 - destRedWidth;
- final int destGreenShift = getChannelShift(destGreenMask);
- final int destGreenWidth = getChannelWidth(destGreenMask, destGreenShift);
- final byte[] destGreens = ANY_TO_EIGHT[destGreenWidth];
- final int destGreenPreShift = 8 - destGreenWidth;
- final int destBlueShift = getChannelShift(destBlueMask);
- final int destBlueWidth = getChannelWidth(destBlueMask, destBlueShift);
- final byte[] destBlues = ANY_TO_EIGHT[destBlueWidth];
- final int destBluePreShift = 8 - destBlueWidth;
- final int destAlphaShift = getChannelShift(destAlphaMask);
- final int destAlphaWidth = getChannelWidth(destAlphaMask, destAlphaShift);
- final byte[] destAlphas = ANY_TO_EIGHT[destAlphaWidth];
- final int destAlphaPreShift = 8 - destAlphaWidth;
-
- int ap = apr, alpha = alphaMode;
- int r = 0, g = 0, b = 0, a = 0;
- int rq = 0, gq = 0, bq = 0, aq = 0;
- for (int dy = destHeight, sfy = sfyi; dy > 0; --dy,
- sp = spr += (sfy >>> 16) * srcStride,
- ap = apr += (sfy >>> 16) * alphaStride,
- sfy = (sfy & 0xffff) + sfyi,
- dp = dpr += dpryi) {
- for (int dx = destWidth, sfx = sfxi; dx > 0; --dx,
- dp += dprxi,
- sfx = (sfx & 0xffff) + sfxi) {
- /*** READ NEXT PIXEL ***/
- switch (stype) {
- case TYPE_GENERIC_8: {
- final int data = srcData[sp] & 0xff;
- sp += (sfx >>> 16);
- r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff;
- g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff;
- b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff;
- a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_16_MSB: {
- final int data = ((srcData[sp] & 0xff) << 8) | (srcData[sp + 1] & 0xff);
- sp += (sfx >>> 16) * 2;
- r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff;
- g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff;
- b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff;
- a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_16_LSB: {
- final int data = ((srcData[sp + 1] & 0xff) << 8) | (srcData[sp] & 0xff);
- sp += (sfx >>> 16) * 2;
- r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff;
- g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff;
- b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff;
- a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_24: {
- final int data = (( ((srcData[sp] & 0xff) << 8) |
- (srcData[sp + 1] & 0xff)) << 8) |
- (srcData[sp + 2] & 0xff);
- sp += (sfx >>> 16) * 3;
- r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff;
- g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff;
- b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff;
- a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_32_MSB: {
- final int data = (( (( ((srcData[sp] & 0xff) << 8) |
- (srcData[sp + 1] & 0xff)) << 8) |
- (srcData[sp + 2] & 0xff)) << 8) |
- (srcData[sp + 3] & 0xff);
- sp += (sfx >>> 16) * 4;
- r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff;
- g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff;
- b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff;
- a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_32_LSB: {
- final int data = (( (( ((srcData[sp + 3] & 0xff) << 8) |
- (srcData[sp + 2] & 0xff)) << 8) |
- (srcData[sp + 1] & 0xff)) << 8) |
- (srcData[sp] & 0xff);
- sp += (sfx >>> 16) * 4;
- r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff;
- g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff;
- b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff;
- a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff;
- } break;
- }
-
- /*** DO SPECIAL PROCESSING IF REQUIRED ***/
- switch (alphaMode) {
- case ALPHA_CHANNEL_SEPARATE:
- alpha = ((alphaData[ap] & 0xff) << 16) / 255;
- ap += (sfx >> 16);
- break;
- case ALPHA_CHANNEL_SOURCE:
- alpha = (a << 16) / 255;
- break;
- case ALPHA_MASK_UNPACKED:
- alpha = (alphaData[ap] != 0) ? 0x10000 : 0;
- ap += (sfx >> 16);
- break;
- case ALPHA_MASK_PACKED:
- alpha = (alphaData[ap >> 3] << ((ap & 7) + 9)) & 0x10000;
- ap += (sfx >> 16);
- break;
- case ALPHA_MASK_RGB:
- alpha = 0x10000;
- for (int i = 0; i < alphaData.length; i += 3) {
- if ((r == alphaData[i]) && (g == alphaData[i + 1]) && (b == alphaData[i + 2])) {
- alpha = 0x0000;
- break;
- }
- }
- break;
- }
- if (alpha != 0x10000) {
- if (alpha == 0x0000) continue;
- switch (dtype) {
- case TYPE_GENERIC_8: {
- final int data = destData[dp] & 0xff;
- rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff;
- gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff;
- bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff;
- aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_16_MSB: {
- final int data = ((destData[dp] & 0xff) << 8) | (destData[dp + 1] & 0xff);
- rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff;
- gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff;
- bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff;
- aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_16_LSB: {
- final int data = ((destData[dp + 1] & 0xff) << 8) | (destData[dp] & 0xff);
- rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff;
- gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff;
- bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff;
- aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_24: {
- final int data = (( ((destData[dp] & 0xff) << 8) |
- (destData[dp + 1] & 0xff)) << 8) |
- (destData[dp + 2] & 0xff);
- rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff;
- gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff;
- bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff;
- aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_32_MSB: {
- final int data = (( (( ((destData[dp] & 0xff) << 8) |
- (destData[dp + 1] & 0xff)) << 8) |
- (destData[dp + 2] & 0xff)) << 8) |
- (destData[dp + 3] & 0xff);
- rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff;
- gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff;
- bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff;
- aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_32_LSB: {
- final int data = (( (( ((destData[dp + 3] & 0xff) << 8) |
- (destData[dp + 2] & 0xff)) << 8) |
- (destData[dp + 1] & 0xff)) << 8) |
- (destData[dp] & 0xff);
- rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff;
- gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff;
- bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff;
- aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff;
- } break;
- }
- // Perform alpha blending
- a = aq + ((a - aq) * alpha >> 16);
- r = rq + ((r - rq) * alpha >> 16);
- g = gq + ((g - gq) * alpha >> 16);
- b = bq + ((b - bq) * alpha >> 16);
- }
-
- /*** WRITE NEXT PIXEL ***/
- final int data =
- (r >>> destRedPreShift << destRedShift) |
- (g >>> destGreenPreShift << destGreenShift) |
- (b >>> destBluePreShift << destBlueShift) |
- (a >>> destAlphaPreShift << destAlphaShift);
- switch (dtype) {
- case TYPE_GENERIC_8: {
- destData[dp] = (byte) data;
- } break;
- case TYPE_GENERIC_16_MSB: {
- destData[dp] = (byte) (data >>> 8);
- destData[dp + 1] = (byte) (data & 0xff);
- } break;
- case TYPE_GENERIC_16_LSB: {
- destData[dp] = (byte) (data & 0xff);
- destData[dp + 1] = (byte) (data >>> 8);
- } break;
- case TYPE_GENERIC_24: {
- destData[dp] = (byte) (data >>> 16);
- destData[dp + 1] = (byte) (data >>> 8);
- destData[dp + 2] = (byte) (data & 0xff);
- } break;
- case TYPE_GENERIC_32_MSB: {
- destData[dp] = (byte) (data >>> 24);
- destData[dp + 1] = (byte) (data >>> 16);
- destData[dp + 2] = (byte) (data >>> 8);
- destData[dp + 3] = (byte) (data & 0xff);
- } break;
- case TYPE_GENERIC_32_LSB: {
- destData[dp] = (byte) (data & 0xff);
- destData[dp + 1] = (byte) (data >>> 8);
- destData[dp + 2] = (byte) (data >>> 16);
- destData[dp + 3] = (byte) (data >>> 24);
- } break;
- }
- }
- }
-}
-
-/**
- * Blits an index palette image into an index palette image.
- * <p>
- * Note: The source and destination red, green, and blue
- * arrays may be null if no alpha blending or dither is to be
- * performed.
- * </p>
- *
- * @param op the blitter operation: a combination of BLIT_xxx flags
- * (see BLIT_xxx constants)
- * @param srcData the source byte array containing image data
- * @param srcDepth the source depth: one of 1, 2, 4, 8
- * @param srcStride the source number of bytes per line
- * @param srcOrder the source byte ordering: one of MSB_FIRST or LSB_FIRST;
- * ignored if srcDepth is not 1
- * @param srcX the top-left x-coord of the source blit region
- * @param srcY the top-left y-coord of the source blit region
- * @param srcWidth the width of the source blit region
- * @param srcHeight the height of the source blit region
- * @param srcReds the source palette red component intensities
- * @param srcGreens the source palette green component intensities
- * @param srcBlues the source palette blue component intensities
- * @param alphaMode the alpha blending or mask mode, may be
- * an integer 0-255 for global alpha; ignored if BLIT_ALPHA
- * not specified in the blitter operations
- * (see ALPHA_MODE_xxx constants)
- * @param alphaData the alpha blending or mask data, varies depending
- * on the value of alphaMode and sometimes ignored
- * @param alphaStride the alpha data number of bytes per line
- * @param alphaX the top-left x-coord of the alpha blit region
- * @param alphaY the top-left y-coord of the alpha blit region
- * @param destData the destination byte array containing image data
- * @param destDepth the destination depth: one of 1, 2, 4, 8
- * @param destStride the destination number of bytes per line
- * @param destOrder the destination byte ordering: one of MSB_FIRST or LSB_FIRST;
- * ignored if destDepth is not 1
- * @param destX the top-left x-coord of the destination blit region
- * @param destY the top-left y-coord of the destination blit region
- * @param destWidth the width of the destination blit region
- * @param destHeight the height of the destination blit region
- * @param destReds the destination palette red component intensities
- * @param destGreens the destination palette green component intensities
- * @param destBlues the destination palette blue component intensities
- * @param flipX if true the resulting image is flipped along the vertical axis
- * @param flipY if true the resulting image is flipped along the horizontal axis
- */
-static void blit(int op,
- byte[] srcData, int srcDepth, int srcStride, int srcOrder,
- int srcX, int srcY, int srcWidth, int srcHeight,
- byte[] srcReds, byte[] srcGreens, byte[] srcBlues,
- int alphaMode, byte[] alphaData, int alphaStride, int alphaX, int alphaY,
- byte[] destData, int destDepth, int destStride, int destOrder,
- int destX, int destY, int destWidth, int destHeight,
- byte[] destReds, byte[] destGreens, byte[] destBlues,
- boolean flipX, boolean flipY) {
- if ((destWidth <= 0) || (destHeight <= 0) || (alphaMode == ALPHA_TRANSPARENT)) return;
-
- /*** Prepare scaling data ***/
- final int dwm1 = destWidth - 1;
- final int sfxi = (dwm1 != 0) ? (int)((((long)srcWidth << 16) - 1) / dwm1) : 0;
- final int dhm1 = destHeight - 1;
- final int sfyi = (dhm1 != 0) ? (int)((((long)srcHeight << 16) - 1) / dhm1) : 0;
-
- /*** Prepare source-related data ***/
- final int stype;
- switch (srcDepth) {
- case 8:
- stype = TYPE_INDEX_8;
- break;
- case 4:
- srcStride <<= 1;
- stype = TYPE_INDEX_4;
- break;
- case 2:
- srcStride <<= 2;
- stype = TYPE_INDEX_2;
- break;
- case 1:
- srcStride <<= 3;
- stype = (srcOrder == MSB_FIRST) ? TYPE_INDEX_1_MSB : TYPE_INDEX_1_LSB;
- break;
- default:
- //throw new IllegalArgumentException("Invalid source type");
- return;
- }
- int spr = srcY * srcStride + srcX;
-
- /*** Prepare destination-related data ***/
- final int dtype;
- switch (destDepth) {
- case 8:
- dtype = TYPE_INDEX_8;
- break;
- case 4:
- destStride <<= 1;
- dtype = TYPE_INDEX_4;
- break;
- case 2:
- destStride <<= 2;
- dtype = TYPE_INDEX_2;
- break;
- case 1:
- destStride <<= 3;
- dtype = (destOrder == MSB_FIRST) ? TYPE_INDEX_1_MSB : TYPE_INDEX_1_LSB;
- break;
- default:
- //throw new IllegalArgumentException("Invalid source type");
- return;
- }
- int dpr = ((flipY) ? destY + dhm1 : destY) * destStride + ((flipX) ? destX + dwm1 : destX);
- final int dprxi = (flipX) ? -1 : 1;
- final int dpryi = (flipY) ? -destStride : destStride;
-
- /*** Prepare special processing data ***/
- int apr;
- if ((op & BLIT_ALPHA) != 0) {
- switch (alphaMode) {
- case ALPHA_MASK_UNPACKED:
- case ALPHA_CHANNEL_SEPARATE:
- if (alphaData == null) alphaMode = 0x10000;
- apr = alphaY * alphaStride + alphaX;
- break;
- case ALPHA_MASK_PACKED:
- if (alphaData == null) alphaMode = 0x10000;
- alphaStride <<= 3;
- apr = alphaY * alphaStride + alphaX;
- break;
- case ALPHA_MASK_INDEX:
- case ALPHA_MASK_RGB:
- if (alphaData == null) alphaMode = 0x10000;
- apr = 0;
- break;
- default:
- alphaMode = (alphaMode << 16) / 255; // prescale
- case ALPHA_CHANNEL_SOURCE:
- apr = 0;
- break;
- }
- } else {
- alphaMode = 0x10000;
- apr = 0;
- }
- final boolean ditherEnabled = (op & BLIT_DITHER) != 0;
-
- /*** Blit ***/
- int dp = dpr;
- int sp = spr;
- int ap = apr;
- int destPaletteSize = 1 << destDepth;
- if ((destReds != null) && (destReds.length < destPaletteSize)) destPaletteSize = destReds.length;
- byte[] paletteMapping = null;
- boolean isExactPaletteMapping = true;
- switch (alphaMode) {
- case 0x10000:
- /*** If the palettes and formats are equivalent use a one-to-one mapping ***/
- if ((stype == dtype) &&
- (srcReds == destReds) && (srcGreens == destGreens) && (srcBlues == destBlues)) {
- paletteMapping = ONE_TO_ONE_MAPPING;
- break;
- /*** If palettes have not been supplied, supply a suitable mapping ***/
- } else if ((srcReds == null) || (destReds == null)) {
- if (srcDepth <= destDepth) {
- paletteMapping = ONE_TO_ONE_MAPPING;
- } else {
- paletteMapping = new byte[1 << srcDepth];
- int mask = (0xff << destDepth) >>> 8;
- for (int i = 0; i < paletteMapping.length; ++i) paletteMapping[i] = (byte)(i & mask);
- }
- break;
- }
- case ALPHA_MASK_UNPACKED:
- case ALPHA_MASK_PACKED:
- case ALPHA_MASK_INDEX:
- case ALPHA_MASK_RGB:
- /*** Generate a palette mapping ***/
- int srcPaletteSize = 1 << srcDepth;
- paletteMapping = new byte[srcPaletteSize];
- if ((srcReds != null) && (srcReds.length < srcPaletteSize)) srcPaletteSize = srcReds.length;
- for (int i = 0, r, g, b, index; i < srcPaletteSize; ++i) {
- r = srcReds[i] & 0xff;
- g = srcGreens[i] & 0xff;
- b = srcBlues[i] & 0xff;
- index = 0;
- int minDistance = 0x7fffffff;
- for (int j = 0, dr, dg, db, distance; j < destPaletteSize; ++j) {
- dr = (destReds[j] & 0xff) - r;
- dg = (destGreens[j] & 0xff) - g;
- db = (destBlues[j] & 0xff) - b;
- distance = dr * dr + dg * dg + db * db;
- if (distance < minDistance) {
- index = j;
- if (distance == 0) break;
- minDistance = distance;
- }
- }
- paletteMapping[i] = (byte)index;
- if (minDistance != 0) isExactPaletteMapping = false;
- }
- break;
- }
- if ((paletteMapping != null) && (isExactPaletteMapping || ! ditherEnabled)) {
- if ((stype == dtype) && (alphaMode == 0x10000)) {
- /*** Fast blit (copy w/ mapping) ***/
- switch (stype) {
- case TYPE_INDEX_8:
- for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) {
- for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) {
- destData[dp] = paletteMapping[srcData[sp] & 0xff];
- sp += (sfx >>> 16);
- }
- }
- break;
- case TYPE_INDEX_4:
- for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) {
- for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) {
- final int v;
- if ((sp & 1) != 0) v = paletteMapping[srcData[sp >> 1] & 0x0f];
- else v = (srcData[sp >> 1] >>> 4) & 0x0f;
- sp += (sfx >>> 16);
- if ((dp & 1) != 0) destData[dp >> 1] = (byte)((destData[dp >> 1] & 0xf0) | v);
- else destData[dp >> 1] = (byte)((destData[dp >> 1] & 0x0f) | (v << 4));
- }
- }
- break;
- case TYPE_INDEX_2:
- for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) {
- for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) {
- final int index = paletteMapping[(srcData[sp >> 2] >>> (6 - (sp & 3) * 2)) & 0x03];
- sp += (sfx >>> 16);
- final int shift = 6 - (dp & 3) * 2;
- destData[dp >> 2] = (byte)(destData[dp >> 2] & ~(0x03 << shift) | (index << shift));
- }
- }
- break;
- case TYPE_INDEX_1_MSB:
- for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) {
- for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) {
- final int index = paletteMapping[(srcData[sp >> 3] >>> (7 - (sp & 7))) & 0x01];
- sp += (sfx >>> 16);
- final int shift = 7 - (dp & 7);
- destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (index << shift));
- }
- }
- break;
- case TYPE_INDEX_1_LSB:
- for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) {
- for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) {
- final int index = paletteMapping[(srcData[sp >> 3] >>> (sp & 7)) & 0x01];
- sp += (sfx >>> 16);
- final int shift = dp & 7;
- destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (index << shift));
- }
- }
- break;
- }
- } else {
- /*** Convert between indexed modes using mapping and mask ***/
- for (int dy = destHeight, sfy = sfyi; dy > 0; --dy,
- sp = spr += (sfy >>> 16) * srcStride,
- sfy = (sfy & 0xffff) + sfyi,
- dp = dpr += dpryi) {
- for (int dx = destWidth, sfx = sfxi; dx > 0; --dx,
- dp += dprxi,
- sfx = (sfx & 0xffff) + sfxi) {
- int index;
- /*** READ NEXT PIXEL ***/
- switch (stype) {
- case TYPE_INDEX_8:
- index = srcData[sp] & 0xff;
- sp += (sfx >>> 16);
- break;
- case TYPE_INDEX_4:
- if ((sp & 1) != 0) index = srcData[sp >> 1] & 0x0f;
- else index = (srcData[sp >> 1] >>> 4) & 0x0f;
- sp += (sfx >>> 16);
- break;
- case TYPE_INDEX_2:
- index = (srcData[sp >> 2] >>> (6 - (sp & 3) * 2)) & 0x03;
- sp += (sfx >>> 16);
- break;
- case TYPE_INDEX_1_MSB:
- index = (srcData[sp >> 3] >>> (7 - (sp & 7))) & 0x01;
- sp += (sfx >>> 16);
- break;
- case TYPE_INDEX_1_LSB:
- index = (srcData[sp >> 3] >>> (sp & 7)) & 0x01;
- sp += (sfx >>> 16);
- break;
- default:
- return;
- }
- /*** APPLY MASK ***/
- switch (alphaMode) {
- case ALPHA_MASK_UNPACKED: {
- final byte mask = alphaData[ap];
- ap += (sfx >> 16);
- if (mask == 0) continue;
- } break;
- case ALPHA_MASK_PACKED: {
- final int mask = alphaData[ap >> 3] & (1 << (ap & 7));
- ap += (sfx >> 16);
- if (mask == 0) continue;
- } break;
- case ALPHA_MASK_INDEX: {
- int i = 0;
- while (i < alphaData.length) {
- if (index == (alphaData[i] & 0xff)) break;
- }
- if (i < alphaData.length) continue;
- } break;
- case ALPHA_MASK_RGB: {
- final byte r = srcReds[index], g = srcGreens[index], b = srcBlues[index];
- int i = 0;
- while (i < alphaData.length) {
- if ((r == alphaData[i]) && (g == alphaData[i + 1]) && (b == alphaData[i + 2])) break;
- i += 3;
- }
- if (i < alphaData.length) continue;
- } break;
- }
- index = paletteMapping[index] & 0xff;
-
- /*** WRITE NEXT PIXEL ***/
- switch (dtype) {
- case TYPE_INDEX_8:
- destData[dp] = (byte) index;
- break;
- case TYPE_INDEX_4:
- if ((dp & 1) != 0) destData[dp >> 1] = (byte)((destData[dp >> 1] & 0xf0) | index);
- else destData[dp >> 1] = (byte)((destData[dp >> 1] & 0x0f) | (index << 4));
- break;
- case TYPE_INDEX_2: {
- final int shift = 6 - (dp & 3) * 2;
- destData[dp >> 2] = (byte)(destData[dp >> 2] & ~(0x03 << shift) | (index << shift));
- } break;
- case TYPE_INDEX_1_MSB: {
- final int shift = 7 - (dp & 7);
- destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (index << shift));
- } break;
- case TYPE_INDEX_1_LSB: {
- final int shift = dp & 7;
- destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (index << shift));
- } break;
- }
- }
- }
- }
- return;
- }
-
- /*** Comprehensive blit (apply transformations) ***/
- int alpha = alphaMode;
- int index = 0;
- int indexq = 0;
- int lastindex = 0, lastr = -1, lastg = -1, lastb = -1;
- final int[] rerr, gerr, berr;
- if (ditherEnabled) {
- rerr = new int[destWidth + 2];
- gerr = new int[destWidth + 2];
- berr = new int[destWidth + 2];
- } else {
- rerr = null; gerr = null; berr = null;
- }
- for (int dy = destHeight, sfy = sfyi; dy > 0; --dy,
- sp = spr += (sfy >>> 16) * srcStride,
- ap = apr += (sfy >>> 16) * alphaStride,
- sfy = (sfy & 0xffff) + sfyi,
- dp = dpr += dpryi) {
- int lrerr = 0, lgerr = 0, lberr = 0;
- for (int dx = destWidth, sfx = sfxi; dx > 0; --dx,
- dp += dprxi,
- sfx = (sfx & 0xffff) + sfxi) {
- /*** READ NEXT PIXEL ***/
- switch (stype) {
- case TYPE_INDEX_8:
- index = srcData[sp] & 0xff;
- sp += (sfx >>> 16);
- break;
- case TYPE_INDEX_4:
- if ((sp & 1) != 0) index = srcData[sp >> 1] & 0x0f;
- else index = (srcData[sp >> 1] >>> 4) & 0x0f;
- sp += (sfx >>> 16);
- break;
- case TYPE_INDEX_2:
- index = (srcData[sp >> 2] >>> (6 - (sp & 3) * 2)) & 0x03;
- sp += (sfx >>> 16);
- break;
- case TYPE_INDEX_1_MSB:
- index = (srcData[sp >> 3] >>> (7 - (sp & 7))) & 0x01;
- sp += (sfx >>> 16);
- break;
- case TYPE_INDEX_1_LSB:
- index = (srcData[sp >> 3] >>> (sp & 7)) & 0x01;
- sp += (sfx >>> 16);
- break;
- }
-
- /*** DO SPECIAL PROCESSING IF REQUIRED ***/
- int r = srcReds[index] & 0xff, g = srcGreens[index] & 0xff, b = srcBlues[index] & 0xff;
- switch (alphaMode) {
- case ALPHA_CHANNEL_SEPARATE:
- alpha = ((alphaData[ap] & 0xff) << 16) / 255;
- ap += (sfx >> 16);
- break;
- case ALPHA_MASK_UNPACKED:
- alpha = (alphaData[ap] != 0) ? 0x10000 : 0;
- ap += (sfx >> 16);
- break;
- case ALPHA_MASK_PACKED:
- alpha = (alphaData[ap >> 3] << ((ap & 7) + 9)) & 0x10000;
- ap += (sfx >> 16);
- break;
- case ALPHA_MASK_INDEX: { // could speed up using binary search if we sorted the indices
- int i = 0;
- while (i < alphaData.length) {
- if (index == (alphaData[i] & 0xff)) break;
- }
- if (i < alphaData.length) continue;
- } break;
- case ALPHA_MASK_RGB: {
- int i = 0;
- while (i < alphaData.length) {
- if ((r == (alphaData[i] & 0xff)) &&
- (g == (alphaData[i + 1] & 0xff)) &&
- (b == (alphaData[i + 2] & 0xff))) break;
- i += 3;
- }
- if (i < alphaData.length) continue;
- } break;
- }
- if (alpha != 0x10000) {
- if (alpha == 0x0000) continue;
- switch (dtype) {
- case TYPE_INDEX_8:
- indexq = destData[dp] & 0xff;
- break;
- case TYPE_INDEX_4:
- if ((dp & 1) != 0) indexq = destData[dp >> 1] & 0x0f;
- else indexq = (destData[dp >> 1] >>> 4) & 0x0f;
- break;
- case TYPE_INDEX_2:
- indexq = (destData[dp >> 2] >>> (6 - (dp & 3) * 2)) & 0x03;
- break;
- case TYPE_INDEX_1_MSB:
- indexq = (destData[dp >> 3] >>> (7 - (dp & 7))) & 0x01;
- break;
- case TYPE_INDEX_1_LSB:
- indexq = (destData[dp >> 3] >>> (dp & 7)) & 0x01;
- break;
- }
- // Perform alpha blending
- final int rq = destReds[indexq] & 0xff;
- final int gq = destGreens[indexq] & 0xff;
- final int bq = destBlues[indexq] & 0xff;
- r = rq + ((r - rq) * alpha >> 16);
- g = gq + ((g - gq) * alpha >> 16);
- b = bq + ((b - bq) * alpha >> 16);
- }
-
- /*** MAP COLOR TO THE PALETTE ***/
- if (ditherEnabled) {
- // Floyd-Steinberg error diffusion
- r += rerr[dx] >> 4;
- if (r < 0) r = 0; else if (r > 255) r = 255;
- g += gerr[dx] >> 4;
- if (g < 0) g = 0; else if (g > 255) g = 255;
- b += berr[dx] >> 4;
- if (b < 0) b = 0; else if (b > 255) b = 255;
- rerr[dx] = lrerr;
- gerr[dx] = lgerr;
- berr[dx] = lberr;
- }
- if (r != lastr || g != lastg || b != lastb) {
- // moving the variable declarations out seems to make the JDK JIT happier...
- for (int j = 0, dr, dg, db, distance, minDistance = 0x7fffffff; j < destPaletteSize; ++j) {
- dr = (destReds[j] & 0xff) - r;
- dg = (destGreens[j] & 0xff) - g;
- db = (destBlues[j] & 0xff) - b;
- distance = dr * dr + dg * dg + db * db;
- if (distance < minDistance) {
- lastindex = j;
- if (distance == 0) break;
- minDistance = distance;
- }
- }
- lastr = r; lastg = g; lastb = b;
- }
- if (ditherEnabled) {
- // Floyd-Steinberg error diffusion, cont'd...
- final int dxm1 = dx - 1, dxp1 = dx + 1;
- int acc;
- rerr[dxp1] += acc = (lrerr = r - (destReds[lastindex] & 0xff)) + lrerr + lrerr;
- rerr[dx] += acc += lrerr + lrerr;
- rerr[dxm1] += acc + lrerr + lrerr;
- gerr[dxp1] += acc = (lgerr = g - (destGreens[lastindex] & 0xff)) + lgerr + lgerr;
- gerr[dx] += acc += lgerr + lgerr;
- gerr[dxm1] += acc + lgerr + lgerr;
- berr[dxp1] += acc = (lberr = b - (destBlues[lastindex] & 0xff)) + lberr + lberr;
- berr[dx] += acc += lberr + lberr;
- berr[dxm1] += acc + lberr + lberr;
- }
-
- /*** WRITE NEXT PIXEL ***/
- switch (dtype) {
- case TYPE_INDEX_8:
- destData[dp] = (byte) lastindex;
- break;
- case TYPE_INDEX_4:
- if ((dp & 1) != 0) destData[dp >> 1] = (byte)((destData[dp >> 1] & 0xf0) | lastindex);
- else destData[dp >> 1] = (byte)((destData[dp >> 1] & 0x0f) | (lastindex << 4));
- break;
- case TYPE_INDEX_2: {
- final int shift = 6 - (dp & 3) * 2;
- destData[dp >> 2] = (byte)(destData[dp >> 2] & ~(0x03 << shift) | (lastindex << shift));
- } break;
- case TYPE_INDEX_1_MSB: {
- final int shift = 7 - (dp & 7);
- destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (lastindex << shift));
- } break;
- case TYPE_INDEX_1_LSB: {
- final int shift = dp & 7;
- destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (lastindex << shift));
- } break;
- }
- }
- }
-}
-
-/**
- * Blits an index palette image into a direct palette image.
- * <p>
- * Note: The source and destination masks and palettes must
- * always be fully specified.
- * </p>
- *
- * @param op the blitter operation: a combination of BLIT_xxx flags
- * (see BLIT_xxx constants)
- * @param srcData the source byte array containing image data
- * @param srcDepth the source depth: one of 1, 2, 4, 8
- * @param srcStride the source number of bytes per line
- * @param srcOrder the source byte ordering: one of MSB_FIRST or LSB_FIRST;
- * ignored if srcDepth is not 1
- * @param srcX the top-left x-coord of the source blit region
- * @param srcY the top-left y-coord of the source blit region
- * @param srcWidth the width of the source blit region
- * @param srcHeight the height of the source blit region
- * @param srcReds the source palette red component intensities
- * @param srcGreens the source palette green component intensities
- * @param srcBlues the source palette blue component intensities
- * @param alphaMode the alpha blending or mask mode, may be
- * an integer 0-255 for global alpha; ignored if BLIT_ALPHA
- * not specified in the blitter operations
- * (see ALPHA_MODE_xxx constants)
- * @param alphaData the alpha blending or mask data, varies depending
- * on the value of alphaMode and sometimes ignored
- * @param alphaStride the alpha data number of bytes per line
- * @param alphaX the top-left x-coord of the alpha blit region
- * @param alphaY the top-left y-coord of the alpha blit region
- * @param destData the destination byte array containing image data
- * @param destDepth the destination depth: one of 8, 16, 24, 32
- * @param destStride the destination number of bytes per line
- * @param destOrder the destination byte ordering: one of MSB_FIRST or LSB_FIRST;
- * ignored if destDepth is not 16 or 32
- * @param destX the top-left x-coord of the destination blit region
- * @param destY the top-left y-coord of the destination blit region
- * @param destWidth the width of the destination blit region
- * @param destHeight the height of the destination blit region
- * @param destRedMask the destination red channel mask
- * @param destGreenMask the destination green channel mask
- * @param destBlueMask the destination blue channel mask
- * @param flipX if true the resulting image is flipped along the vertical axis
- * @param flipY if true the resulting image is flipped along the horizontal axis
- */
-static void blit(int op,
- byte[] srcData, int srcDepth, int srcStride, int srcOrder,
- int srcX, int srcY, int srcWidth, int srcHeight,
- byte[] srcReds, byte[] srcGreens, byte[] srcBlues,
- int alphaMode, byte[] alphaData, int alphaStride, int alphaX, int alphaY,
- byte[] destData, int destDepth, int destStride, int destOrder,
- int destX, int destY, int destWidth, int destHeight,
- int destRedMask, int destGreenMask, int destBlueMask,
- boolean flipX, boolean flipY) {
- if ((destWidth <= 0) || (destHeight <= 0) || (alphaMode == ALPHA_TRANSPARENT)) return;
-
- /*** Fast blit (straight copy) ***/
- if (srcX == 0 && srcY == 0 && destX == 0 && destY == 0 && destWidth == srcWidth && destHeight == srcHeight) {
- if (destDepth == 24 && srcDepth == 8 && (op & BLIT_ALPHA) == 0 && destRedMask == 0xFF0000 && destGreenMask == 0xFF00 && destBlueMask == 0xFF) {
- for (int y = 0, sp = 0, dp = 0, spad = srcStride - srcWidth, dpad = destStride - (destWidth * 3); y < destHeight; y++, sp += spad, dp += dpad) {
- for (int x = 0; x < destWidth; x++) {
- int index = srcData[sp++] & 0xff;
- destData[dp++] = srcReds[index];
- destData[dp++] = srcGreens[index];
- destData[dp++] = srcBlues[index];
- }
- }
- return;
- }
- if (destDepth == 32 && destOrder == MSB_FIRST && srcDepth == 8 && (op & BLIT_ALPHA) == 0 && destRedMask == 0xFF0000 && destGreenMask == 0xFF00 && destBlueMask == 0xFF) {
- for (int y = 0, sp = 0, dp = 0, spad = srcStride - srcWidth, dpad = destStride - (destWidth * 4); y < destHeight; y++, sp += spad, dp += dpad) {
- for (int x = 0; x < destWidth; x++) {
- int index = srcData[sp++] & 0xff;
- dp++;
- destData[dp++] = srcReds[index];
- destData[dp++] = srcGreens[index];
- destData[dp++] = srcBlues[index];
- }
- }
- return;
- }
- }
- // these should be supplied as params later
- final int destAlphaMask = 0;
-
- /*** Prepare scaling data ***/
- final int dwm1 = destWidth - 1;
- final int sfxi = (dwm1 != 0) ? (int)((((long)srcWidth << 16) - 1) / dwm1) : 0;
- final int dhm1 = destHeight - 1;
- final int sfyi = (dhm1 != 0) ? (int)((((long)srcHeight << 16) - 1) / dhm1) : 0;
-
- /*** Prepare source-related data ***/
- final int stype;
- switch (srcDepth) {
- case 8:
- stype = TYPE_INDEX_8;
- break;
- case 4:
- srcStride <<= 1;
- stype = TYPE_INDEX_4;
- break;
- case 2:
- srcStride <<= 2;
- stype = TYPE_INDEX_2;
- break;
- case 1:
- srcStride <<= 3;
- stype = (srcOrder == MSB_FIRST) ? TYPE_INDEX_1_MSB : TYPE_INDEX_1_LSB;
- break;
- default:
- //throw new IllegalArgumentException("Invalid source type");
- return;
- }
- int spr = srcY * srcStride + srcX;
-
- /*** Prepare destination-related data ***/
- final int dbpp, dtype;
- switch (destDepth) {
- case 8:
- dbpp = 1;
- dtype = TYPE_GENERIC_8;
- break;
- case 16:
- dbpp = 2;
- dtype = (destOrder == MSB_FIRST) ? TYPE_GENERIC_16_MSB : TYPE_GENERIC_16_LSB;
- break;
- case 24:
- dbpp = 3;
- dtype = TYPE_GENERIC_24;
- break;
- case 32:
- dbpp = 4;
- dtype = (destOrder == MSB_FIRST) ? TYPE_GENERIC_32_MSB : TYPE_GENERIC_32_LSB;
- break;
- default:
- //throw new IllegalArgumentException("Invalid destination type");
- return;
- }
- int dpr = ((flipY) ? destY + dhm1 : destY) * destStride + ((flipX) ? destX + dwm1 : destX) * dbpp;
- final int dprxi = (flipX) ? -dbpp : dbpp;
- final int dpryi = (flipY) ? -destStride : destStride;
-
- /*** Prepare special processing data ***/
- int apr;
- if ((op & BLIT_ALPHA) != 0) {
- switch (alphaMode) {
- case ALPHA_MASK_UNPACKED:
- case ALPHA_CHANNEL_SEPARATE:
- if (alphaData == null) alphaMode = 0x10000;
- apr = alphaY * alphaStride + alphaX;
- break;
- case ALPHA_MASK_PACKED:
- if (alphaData == null) alphaMode = 0x10000;
- alphaStride <<= 3;
- apr = alphaY * alphaStride + alphaX;
- break;
- case ALPHA_MASK_INDEX:
- case ALPHA_MASK_RGB:
- if (alphaData == null) alphaMode = 0x10000;
- apr = 0;
- break;
- default:
- alphaMode = (alphaMode << 16) / 255; // prescale
- case ALPHA_CHANNEL_SOURCE:
- apr = 0;
- break;
- }
- } else {
- alphaMode = 0x10000;
- apr = 0;
- }
-
- /*** Comprehensive blit (apply transformations) ***/
- final int destRedShift = getChannelShift(destRedMask);
- final int destRedWidth = getChannelWidth(destRedMask, destRedShift);
- final byte[] destReds = ANY_TO_EIGHT[destRedWidth];
- final int destRedPreShift = 8 - destRedWidth;
- final int destGreenShift = getChannelShift(destGreenMask);
- final int destGreenWidth = getChannelWidth(destGreenMask, destGreenShift);
- final byte[] destGreens = ANY_TO_EIGHT[destGreenWidth];
- final int destGreenPreShift = 8 - destGreenWidth;
- final int destBlueShift = getChannelShift(destBlueMask);
- final int destBlueWidth = getChannelWidth(destBlueMask, destBlueShift);
- final byte[] destBlues = ANY_TO_EIGHT[destBlueWidth];
- final int destBluePreShift = 8 - destBlueWidth;
- final int destAlphaShift = getChannelShift(destAlphaMask);
- final int destAlphaWidth = getChannelWidth(destAlphaMask, destAlphaShift);
- final byte[] destAlphas = ANY_TO_EIGHT[destAlphaWidth];
- final int destAlphaPreShift = 8 - destAlphaWidth;
-
- int dp = dpr;
- int sp = spr;
- int ap = apr, alpha = alphaMode;
- int r = 0, g = 0, b = 0, a = 0, index = 0;
- int rq = 0, gq = 0, bq = 0, aq = 0;
- for (int dy = destHeight, sfy = sfyi; dy > 0; --dy,
- sp = spr += (sfy >>> 16) * srcStride,
- ap = apr += (sfy >>> 16) * alphaStride,
- sfy = (sfy & 0xffff) + sfyi,
- dp = dpr += dpryi) {
- for (int dx = destWidth, sfx = sfxi; dx > 0; --dx,
- dp += dprxi,
- sfx = (sfx & 0xffff) + sfxi) {
- /*** READ NEXT PIXEL ***/
- switch (stype) {
- case TYPE_INDEX_8:
- index = srcData[sp] & 0xff;
- sp += (sfx >>> 16);
- break;
- case TYPE_INDEX_4:
- if ((sp & 1) != 0) index = srcData[sp >> 1] & 0x0f;
- else index = (srcData[sp >> 1] >>> 4) & 0x0f;
- sp += (sfx >>> 16);
- break;
- case TYPE_INDEX_2:
- index = (srcData[sp >> 2] >>> (6 - (sp & 3) * 2)) & 0x03;
- sp += (sfx >>> 16);
- break;
- case TYPE_INDEX_1_MSB:
- index = (srcData[sp >> 3] >>> (7 - (sp & 7))) & 0x01;
- sp += (sfx >>> 16);
- break;
- case TYPE_INDEX_1_LSB:
- index = (srcData[sp >> 3] >>> (sp & 7)) & 0x01;
- sp += (sfx >>> 16);
- break;
- }
-
- /*** DO SPECIAL PROCESSING IF REQUIRED ***/
- r = srcReds[index] & 0xff;
- g = srcGreens[index] & 0xff;
- b = srcBlues[index] & 0xff;
- switch (alphaMode) {
- case ALPHA_CHANNEL_SEPARATE:
- alpha = ((alphaData[ap] & 0xff) << 16) / 255;
- ap += (sfx >> 16);
- break;
- case ALPHA_MASK_UNPACKED:
- alpha = (alphaData[ap] != 0) ? 0x10000 : 0;
- ap += (sfx >> 16);
- break;
- case ALPHA_MASK_PACKED:
- alpha = (alphaData[ap >> 3] << ((ap & 7) + 9)) & 0x10000;
- ap += (sfx >> 16);
- break;
- case ALPHA_MASK_INDEX: { // could speed up using binary search if we sorted the indices
- int i = 0;
- while (i < alphaData.length) {
- if (index == (alphaData[i] & 0xff)) break;
- }
- if (i < alphaData.length) continue;
- } break;
- case ALPHA_MASK_RGB: {
- int i = 0;
- while (i < alphaData.length) {
- if ((r == (alphaData[i] & 0xff)) &&
- (g == (alphaData[i + 1] & 0xff)) &&
- (b == (alphaData[i + 2] & 0xff))) break;
- i += 3;
- }
- if (i < alphaData.length) continue;
- } break;
- }
- if (alpha != 0x10000) {
- if (alpha == 0x0000) continue;
- switch (dtype) {
- case TYPE_GENERIC_8: {
- final int data = destData[dp] & 0xff;
- rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff;
- gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff;
- bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff;
- aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_16_MSB: {
- final int data = ((destData[dp] & 0xff) << 8) | (destData[dp + 1] & 0xff);
- rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff;
- gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff;
- bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff;
- aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_16_LSB: {
- final int data = ((destData[dp + 1] & 0xff) << 8) | (destData[dp] & 0xff);
- rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff;
- gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff;
- bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff;
- aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_24: {
- final int data = (( ((destData[dp] & 0xff) << 8) |
- (destData[dp + 1] & 0xff)) << 8) |
- (destData[dp + 2] & 0xff);
- rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff;
- gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff;
- bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff;
- aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_32_MSB: {
- final int data = (( (( ((destData[dp] & 0xff) << 8) |
- (destData[dp + 1] & 0xff)) << 8) |
- (destData[dp + 2] & 0xff)) << 8) |
- (destData[dp + 3] & 0xff);
- rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff;
- gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff;
- bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff;
- aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_32_LSB: {
- final int data = (( (( ((destData[dp + 3] & 0xff) << 8) |
- (destData[dp + 2] & 0xff)) << 8) |
- (destData[dp + 1] & 0xff)) << 8) |
- (destData[dp] & 0xff);
- rq = destReds[(data & destRedMask) >>> destRedShift] & 0xff;
- gq = destGreens[(data & destGreenMask) >>> destGreenShift] & 0xff;
- bq = destBlues[(data & destBlueMask) >>> destBlueShift] & 0xff;
- aq = destAlphas[(data & destAlphaMask) >>> destAlphaShift] & 0xff;
- } break;
- }
- // Perform alpha blending
- a = aq + ((a - aq) * alpha >> 16);
- r = rq + ((r - rq) * alpha >> 16);
- g = gq + ((g - gq) * alpha >> 16);
- b = bq + ((b - bq) * alpha >> 16);
- }
-
- /*** WRITE NEXT PIXEL ***/
- final int data =
- (r >>> destRedPreShift << destRedShift) |
- (g >>> destGreenPreShift << destGreenShift) |
- (b >>> destBluePreShift << destBlueShift) |
- (a >>> destAlphaPreShift << destAlphaShift);
- switch (dtype) {
- case TYPE_GENERIC_8: {
- destData[dp] = (byte) data;
- } break;
- case TYPE_GENERIC_16_MSB: {
- destData[dp] = (byte) (data >>> 8);
- destData[dp + 1] = (byte) (data & 0xff);
- } break;
- case TYPE_GENERIC_16_LSB: {
- destData[dp] = (byte) (data & 0xff);
- destData[dp + 1] = (byte) (data >>> 8);
- } break;
- case TYPE_GENERIC_24: {
- destData[dp] = (byte) (data >>> 16);
- destData[dp + 1] = (byte) (data >>> 8);
- destData[dp + 2] = (byte) (data & 0xff);
- } break;
- case TYPE_GENERIC_32_MSB: {
- destData[dp] = (byte) (data >>> 24);
- destData[dp + 1] = (byte) (data >>> 16);
- destData[dp + 2] = (byte) (data >>> 8);
- destData[dp + 3] = (byte) (data & 0xff);
- } break;
- case TYPE_GENERIC_32_LSB: {
- destData[dp] = (byte) (data & 0xff);
- destData[dp + 1] = (byte) (data >>> 8);
- destData[dp + 2] = (byte) (data >>> 16);
- destData[dp + 3] = (byte) (data >>> 24);
- } break;
- }
- }
- }
-}
-
-/**
- * Blits a direct palette image into an index palette image.
- * <p>
- * Note: The source and destination masks and palettes must
- * always be fully specified.
- * </p>
- *
- * @param op the blitter operation: a combination of BLIT_xxx flags
- * (see BLIT_xxx constants)
- * @param srcData the source byte array containing image data
- * @param srcDepth the source depth: one of 8, 16, 24, 32
- * @param srcStride the source number of bytes per line
- * @param srcOrder the source byte ordering: one of MSB_FIRST or LSB_FIRST;
- * ignored if srcDepth is not 16 or 32
- * @param srcX the top-left x-coord of the source blit region
- * @param srcY the top-left y-coord of the source blit region
- * @param srcWidth the width of the source blit region
- * @param srcHeight the height of the source blit region
- * @param srcRedMask the source red channel mask
- * @param srcGreenMask the source green channel mask
- * @param srcBlueMask the source blue channel mask
- * @param alphaMode the alpha blending or mask mode, may be
- * an integer 0-255 for global alpha; ignored if BLIT_ALPHA
- * not specified in the blitter operations
- * (see ALPHA_MODE_xxx constants)
- * @param alphaData the alpha blending or mask data, varies depending
- * on the value of alphaMode and sometimes ignored
- * @param alphaStride the alpha data number of bytes per line
- * @param alphaX the top-left x-coord of the alpha blit region
- * @param alphaY the top-left y-coord of the alpha blit region
- * @param destData the destination byte array containing image data
- * @param destDepth the destination depth: one of 1, 2, 4, 8
- * @param destStride the destination number of bytes per line
- * @param destOrder the destination byte ordering: one of MSB_FIRST or LSB_FIRST;
- * ignored if destDepth is not 1
- * @param destX the top-left x-coord of the destination blit region
- * @param destY the top-left y-coord of the destination blit region
- * @param destWidth the width of the destination blit region
- * @param destHeight the height of the destination blit region
- * @param destReds the destination palette red component intensities
- * @param destGreens the destination palette green component intensities
- * @param destBlues the destination palette blue component intensities
- * @param flipX if true the resulting image is flipped along the vertical axis
- * @param flipY if true the resulting image is flipped along the horizontal axis
- */
-static void blit(int op,
- byte[] srcData, int srcDepth, int srcStride, int srcOrder,
- int srcX, int srcY, int srcWidth, int srcHeight,
- int srcRedMask, int srcGreenMask, int srcBlueMask,
- int alphaMode, byte[] alphaData, int alphaStride, int alphaX, int alphaY,
- byte[] destData, int destDepth, int destStride, int destOrder,
- int destX, int destY, int destWidth, int destHeight,
- byte[] destReds, byte[] destGreens, byte[] destBlues,
- boolean flipX, boolean flipY) {
- if ((destWidth <= 0) || (destHeight <= 0) || (alphaMode == ALPHA_TRANSPARENT)) return;
-
- // these should be supplied as params later
- final int srcAlphaMask = 0;
-
- /*** Prepare scaling data ***/
- final int dwm1 = destWidth - 1;
- final int sfxi = (dwm1 != 0) ? (int)((((long)srcWidth << 16) - 1) / dwm1) : 0;
- final int dhm1 = destHeight - 1;
- final int sfyi = (dhm1 != 0) ? (int)((((long)srcHeight << 16) - 1) / dhm1) : 0;
-
- /*** Prepare source-related data ***/
- final int sbpp, stype;
- switch (srcDepth) {
- case 8:
- sbpp = 1;
- stype = TYPE_GENERIC_8;
- break;
- case 16:
- sbpp = 2;
- stype = (srcOrder == MSB_FIRST) ? TYPE_GENERIC_16_MSB : TYPE_GENERIC_16_LSB;
- break;
- case 24:
- sbpp = 3;
- stype = TYPE_GENERIC_24;
- break;
- case 32:
- sbpp = 4;
- stype = (srcOrder == MSB_FIRST) ? TYPE_GENERIC_32_MSB : TYPE_GENERIC_32_LSB;
- break;
- default:
- //throw new IllegalArgumentException("Invalid source type");
- return;
- }
- int spr = srcY * srcStride + srcX * sbpp;
-
- /*** Prepare destination-related data ***/
- final int dtype;
- switch (destDepth) {
- case 8:
- dtype = TYPE_INDEX_8;
- break;
- case 4:
- destStride <<= 1;
- dtype = TYPE_INDEX_4;
- break;
- case 2:
- destStride <<= 2;
- dtype = TYPE_INDEX_2;
- break;
- case 1:
- destStride <<= 3;
- dtype = (destOrder == MSB_FIRST) ? TYPE_INDEX_1_MSB : TYPE_INDEX_1_LSB;
- break;
- default:
- //throw new IllegalArgumentException("Invalid source type");
- return;
- }
- int dpr = ((flipY) ? destY + dhm1 : destY) * destStride + ((flipX) ? destX + dwm1 : destX);
- final int dprxi = (flipX) ? -1 : 1;
- final int dpryi = (flipY) ? -destStride : destStride;
-
- /*** Prepare special processing data ***/
- int apr;
- if ((op & BLIT_ALPHA) != 0) {
- switch (alphaMode) {
- case ALPHA_MASK_UNPACKED:
- case ALPHA_CHANNEL_SEPARATE:
- if (alphaData == null) alphaMode = 0x10000;
- apr = alphaY * alphaStride + alphaX;
- break;
- case ALPHA_MASK_PACKED:
- if (alphaData == null) alphaMode = 0x10000;
- alphaStride <<= 3;
- apr = alphaY * alphaStride + alphaX;
- break;
- case ALPHA_MASK_INDEX:
- //throw new IllegalArgumentException("Invalid alpha type");
- return;
- case ALPHA_MASK_RGB:
- if (alphaData == null) alphaMode = 0x10000;
- apr = 0;
- break;
- default:
- alphaMode = (alphaMode << 16) / 255; // prescale
- case ALPHA_CHANNEL_SOURCE:
- apr = 0;
- break;
- }
- } else {
- alphaMode = 0x10000;
- apr = 0;
- }
- final boolean ditherEnabled = (op & BLIT_DITHER) != 0;
-
- /*** Comprehensive blit (apply transformations) ***/
- final int srcRedShift = getChannelShift(srcRedMask);
- final byte[] srcReds = ANY_TO_EIGHT[getChannelWidth(srcRedMask, srcRedShift)];
- final int srcGreenShift = getChannelShift(srcGreenMask);
- final byte[] srcGreens = ANY_TO_EIGHT[getChannelWidth(srcGreenMask, srcGreenShift)];
- final int srcBlueShift = getChannelShift(srcBlueMask);
- final byte[] srcBlues = ANY_TO_EIGHT[getChannelWidth(srcBlueMask, srcBlueShift)];
- final int srcAlphaShift = getChannelShift(srcAlphaMask);
- final byte[] srcAlphas = ANY_TO_EIGHT[getChannelWidth(srcAlphaMask, srcAlphaShift)];
-
- int dp = dpr;
- int sp = spr;
- int ap = apr, alpha = alphaMode;
- int r = 0, g = 0, b = 0, a = 0;
- int indexq = 0;
- int lastindex = 0, lastr = -1, lastg = -1, lastb = -1;
- final int[] rerr, gerr, berr;
- int destPaletteSize = 1 << destDepth;
- if ((destReds != null) && (destReds.length < destPaletteSize)) destPaletteSize = destReds.length;
- if (ditherEnabled) {
- rerr = new int[destWidth + 2];
- gerr = new int[destWidth + 2];
- berr = new int[destWidth + 2];
- } else {
- rerr = null; gerr = null; berr = null;
- }
- for (int dy = destHeight, sfy = sfyi; dy > 0; --dy,
- sp = spr += (sfy >>> 16) * srcStride,
- ap = apr += (sfy >>> 16) * alphaStride,
- sfy = (sfy & 0xffff) + sfyi,
- dp = dpr += dpryi) {
- int lrerr = 0, lgerr = 0, lberr = 0;
- for (int dx = destWidth, sfx = sfxi; dx > 0; --dx,
- dp += dprxi,
- sfx = (sfx & 0xffff) + sfxi) {
- /*** READ NEXT PIXEL ***/
- switch (stype) {
- case TYPE_GENERIC_8: {
- final int data = srcData[sp] & 0xff;
- sp += (sfx >>> 16);
- r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff;
- g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff;
- b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff;
- a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_16_MSB: {
- final int data = ((srcData[sp] & 0xff) << 8) | (srcData[sp + 1] & 0xff);
- sp += (sfx >>> 16) * 2;
- r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff;
- g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff;
- b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff;
- a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_16_LSB: {
- final int data = ((srcData[sp + 1] & 0xff) << 8) | (srcData[sp] & 0xff);
- sp += (sfx >>> 16) * 2;
- r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff;
- g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff;
- b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff;
- a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_24: {
- final int data = (( ((srcData[sp] & 0xff) << 8) |
- (srcData[sp + 1] & 0xff)) << 8) |
- (srcData[sp + 2] & 0xff);
- sp += (sfx >>> 16) * 3;
- r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff;
- g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff;
- b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff;
- a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_32_MSB: {
- final int data = (( (( ((srcData[sp] & 0xff) << 8) |
- (srcData[sp + 1] & 0xff)) << 8) |
- (srcData[sp + 2] & 0xff)) << 8) |
- (srcData[sp + 3] & 0xff);
- sp += (sfx >>> 16) * 4;
- r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff;
- g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff;
- b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff;
- a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff;
- } break;
- case TYPE_GENERIC_32_LSB: {
- final int data = (( (( ((srcData[sp + 3] & 0xff) << 8) |
- (srcData[sp + 2] & 0xff)) << 8) |
- (srcData[sp + 1] & 0xff)) << 8) |
- (srcData[sp] & 0xff);
- sp += (sfx >>> 16) * 4;
- r = srcReds[(data & srcRedMask) >>> srcRedShift] & 0xff;
- g = srcGreens[(data & srcGreenMask) >>> srcGreenShift] & 0xff;
- b = srcBlues[(data & srcBlueMask) >>> srcBlueShift] & 0xff;
- a = srcAlphas[(data & srcAlphaMask) >>> srcAlphaShift] & 0xff;
- } break;
- }
-
- /*** DO SPECIAL PROCESSING IF REQUIRED ***/
- switch (alphaMode) {
- case ALPHA_CHANNEL_SEPARATE:
- alpha = ((alphaData[ap] & 0xff) << 16) / 255;
- ap += (sfx >> 16);
- break;
- case ALPHA_CHANNEL_SOURCE:
- alpha = (a << 16) / 255;
- break;
- case ALPHA_MASK_UNPACKED:
- alpha = (alphaData[ap] != 0) ? 0x10000 : 0;
- ap += (sfx >> 16);
- break;
- case ALPHA_MASK_PACKED:
- alpha = (alphaData[ap >> 3] << ((ap & 7) + 9)) & 0x10000;
- ap += (sfx >> 16);
- break;
- case ALPHA_MASK_RGB:
- alpha = 0x10000;
- for (int i = 0; i < alphaData.length; i += 3) {
- if ((r == alphaData[i]) && (g == alphaData[i + 1]) && (b == alphaData[i + 2])) {
- alpha = 0x0000;
- break;
- }
- }
- break;
- }
- if (alpha != 0x10000) {
- if (alpha == 0x0000) continue;
- switch (dtype) {
- case TYPE_INDEX_8:
- indexq = destData[dp] & 0xff;
- break;
- case TYPE_INDEX_4:
- if ((dp & 1) != 0) indexq = destData[dp >> 1] & 0x0f;
- else indexq = (destData[dp >> 1] >>> 4) & 0x0f;
- break;
- case TYPE_INDEX_2:
- indexq = (destData[dp >> 2] >>> (6 - (dp & 3) * 2)) & 0x03;
- break;
- case TYPE_INDEX_1_MSB:
- indexq = (destData[dp >> 3] >>> (7 - (dp & 7))) & 0x01;
- break;
- case TYPE_INDEX_1_LSB:
- indexq = (destData[dp >> 3] >>> (dp & 7)) & 0x01;
- break;
- }
- // Perform alpha blending
- final int rq = destReds[indexq] & 0xff;
- final int gq = destGreens[indexq] & 0xff;
- final int bq = destBlues[indexq] & 0xff;
- r = rq + ((r - rq) * alpha >> 16);
- g = gq + ((g - gq) * alpha >> 16);
- b = bq + ((b - bq) * alpha >> 16);
- }
-
- /*** MAP COLOR TO THE PALETTE ***/
- if (ditherEnabled) {
- // Floyd-Steinberg error diffusion
- r += rerr[dx] >> 4;
- if (r < 0) r = 0; else if (r > 255) r = 255;
- g += gerr[dx] >> 4;
- if (g < 0) g = 0; else if (g > 255) g = 255;
- b += berr[dx] >> 4;
- if (b < 0) b = 0; else if (b > 255) b = 255;
- rerr[dx] = lrerr;
- gerr[dx] = lgerr;
- berr[dx] = lberr;
- }
- if (r != lastr || g != lastg || b != lastb) {
- // moving the variable declarations out seems to make the JDK JIT happier...
- for (int j = 0, dr, dg, db, distance, minDistance = 0x7fffffff; j < destPaletteSize; ++j) {
- dr = (destReds[j] & 0xff) - r;
- dg = (destGreens[j] & 0xff) - g;
- db = (destBlues[j] & 0xff) - b;
- distance = dr * dr + dg * dg + db * db;
- if (distance < minDistance) {
- lastindex = j;
- if (distance == 0) break;
- minDistance = distance;
- }
- }
- lastr = r; lastg = g; lastb = b;
- }
- if (ditherEnabled) {
- // Floyd-Steinberg error diffusion, cont'd...
- final int dxm1 = dx - 1, dxp1 = dx + 1;
- int acc;
- rerr[dxp1] += acc = (lrerr = r - (destReds[lastindex] & 0xff)) + lrerr + lrerr;
- rerr[dx] += acc += lrerr + lrerr;
- rerr[dxm1] += acc + lrerr + lrerr;
- gerr[dxp1] += acc = (lgerr = g - (destGreens[lastindex] & 0xff)) + lgerr + lgerr;
- gerr[dx] += acc += lgerr + lgerr;
- gerr[dxm1] += acc + lgerr + lgerr;
- berr[dxp1] += acc = (lberr = b - (destBlues[lastindex] & 0xff)) + lberr + lberr;
- berr[dx] += acc += lberr + lberr;
- berr[dxm1] += acc + lberr + lberr;
- }
-
- /*** WRITE NEXT PIXEL ***/
- switch (dtype) {
- case TYPE_INDEX_8:
- destData[dp] = (byte) lastindex;
- break;
- case TYPE_INDEX_4:
- if ((dp & 1) != 0) destData[dp >> 1] = (byte)((destData[dp >> 1] & 0xf0) | lastindex);
- else destData[dp >> 1] = (byte)((destData[dp >> 1] & 0x0f) | (lastindex << 4));
- break;
- case TYPE_INDEX_2: {
- final int shift = 6 - (dp & 3) * 2;
- destData[dp >> 2] = (byte)(destData[dp >> 2] & ~(0x03 << shift) | (lastindex << shift));
- } break;
- case TYPE_INDEX_1_MSB: {
- final int shift = 7 - (dp & 7);
- destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (lastindex << shift));
- } break;
- case TYPE_INDEX_1_LSB: {
- final int shift = dp & 7;
- destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (lastindex << shift));
- } break;
- }
- }
- }
-}
-
-/**
- * Computes the required channel shift from a mask.
- */
-static int getChannelShift(int mask) {
- if (mask == 0) return 0;
- int i;
- for (i = 0; ((mask & 1) == 0) && (i < 32); ++i) {
- mask >>>= 1;
- }
- return i;
-}
-
-/**
- * Computes the required channel width (depth) from a mask.
- */
-static int getChannelWidth(int mask, int shift) {
- if (mask == 0) return 0;
- int i;
- mask >>>= shift;
- for (i = shift; ((mask & 1) != 0) && (i < 32); ++i) {
- mask >>>= 1;
- }
- return i - shift;
-}
-
-/**
- * Extracts a field from packed RGB data given a mask for that field.
- */
-static byte getChannelField(int data, int mask) {
- final int shift = getChannelShift(mask);
- return ANY_TO_EIGHT[getChannelWidth(mask, shift)][(data & mask) >>> shift];
-}
-
-/**
- * Creates an ImageData containing one band's worth of a gradient filled
- * block. If <code>vertical</code> is true, the band must be tiled
- * horizontally to fill a region, otherwise it must be tiled vertically.
- *
- * @param width the width of the region to be filled
- * @param height the height of the region to be filled
- * @param vertical if true sweeps from top to bottom, else
- * sweeps from left to right
- * @param fromRGB the color to start with
- * @param toRGB the color to end with
- * @param redBits the number of significant red bits, 0 for palette modes
- * @param greenBits the number of significant green bits, 0 for palette modes
- * @param blueBits the number of significant blue bits, 0 for palette modes
- * @return the new ImageData
- */
-static ImageData createGradientBand(
- int width, int height, boolean vertical,
- RGB fromRGB, RGB toRGB,
- int redBits, int greenBits, int blueBits) {
- /* Gradients are drawn as tiled bands */
- final int bandWidth, bandHeight, bitmapDepth;
- final byte[] bitmapData;
- final PaletteData paletteData;
- /* Select an algorithm depending on the depth of the screen */
- if (redBits != 0 && greenBits != 0 && blueBits != 0) {
- paletteData = new PaletteData(0x0000ff00, 0x00ff0000, 0xff000000);
- bitmapDepth = 32;
- if (redBits >= 8 && greenBits >= 8 && blueBits >= 8) {
- /* Precise color */
- final int steps;
- if (vertical) {
- bandWidth = 1;
- bandHeight = height;
- steps = bandHeight > 1 ? bandHeight - 1 : 1;
- } else {
- bandWidth = width;
- bandHeight = 1;
- steps = bandWidth > 1 ? bandWidth - 1 : 1;
- }
- final int bytesPerLine = bandWidth * 4;
- bitmapData = new byte[bandHeight * bytesPerLine];
- buildPreciseGradientChannel(fromRGB.blue, toRGB.blue, steps, bandWidth, bandHeight, vertical, bitmapData, 0, bytesPerLine);
- buildPreciseGradientChannel(fromRGB.green, toRGB.green, steps, bandWidth, bandHeight, vertical, bitmapData, 1, bytesPerLine);
- buildPreciseGradientChannel(fromRGB.red, toRGB.red, steps, bandWidth, bandHeight, vertical, bitmapData, 2, bytesPerLine);
- } else {
- /* Dithered color */
- final int steps;
- if (vertical) {
- bandWidth = (width < 8) ? width : 8;
- bandHeight = height;
- steps = bandHeight > 1 ? bandHeight - 1 : 1;
- } else {
- bandWidth = width;
- bandHeight = (height < 8) ? height : 8;
- steps = bandWidth > 1 ? bandWidth - 1 : 1;
- }
- final int bytesPerLine = bandWidth * 4;
- bitmapData = new byte[bandHeight * bytesPerLine];
- buildDitheredGradientChannel(fromRGB.blue, toRGB.blue, steps, bandWidth, bandHeight, vertical, bitmapData, 0, bytesPerLine, blueBits);
- buildDitheredGradientChannel(fromRGB.green, toRGB.green, steps, bandWidth, bandHeight, vertical, bitmapData, 1, bytesPerLine, greenBits);
- buildDitheredGradientChannel(fromRGB.red, toRGB.red, steps, bandWidth, bandHeight, vertical, bitmapData, 2, bytesPerLine, redBits);
- }
- } else {
- /* Dithered two tone */
- paletteData = new PaletteData(new RGB[] { fromRGB, toRGB });
- bitmapDepth = 8;
- final int blendi;
- if (vertical) {
- bandWidth = (width < 8) ? width : 8;
- bandHeight = height;
- blendi = (bandHeight > 1) ? 0x1040000 / (bandHeight - 1) + 1 : 1;
- } else {
- bandWidth = width;
- bandHeight = (height < 8) ? height : 8;
- blendi = (bandWidth > 1) ? 0x1040000 / (bandWidth - 1) + 1 : 1;
- }
- final int bytesPerLine = (bandWidth + 3) & -4;
- bitmapData = new byte[bandHeight * bytesPerLine];
- if (vertical) {
- for (int dy = 0, blend = 0, dp = 0; dy < bandHeight;
- ++dy, blend += blendi, dp += bytesPerLine) {
- for (int dx = 0; dx < bandWidth; ++dx) {
- bitmapData[dp + dx] = (blend + DITHER_MATRIX[dy & 7][dx]) <
- 0x1000000 ? (byte)0 : (byte)1;
- }
- }
- } else {
- for (int dx = 0, blend = 0; dx < bandWidth; ++dx, blend += blendi) {
- for (int dy = 0, dptr = dx; dy < bandHeight; ++dy, dptr += bytesPerLine) {
- bitmapData[dptr] = (blend + DITHER_MATRIX[dy][dx & 7]) <
- 0x1000000 ? (byte)0 : (byte)1;
- }
- }
- }
- }
- return new ImageData(bandWidth, bandHeight, bitmapDepth, paletteData, 4, bitmapData);
-}
-
-/*
- * Fill in gradated values for a color channel
- */
-static final void buildPreciseGradientChannel(int from, int to, int steps,
- int bandWidth, int bandHeight, boolean vertical,
- byte[] bitmapData, int dp, int bytesPerLine) {
- int val = from << 16;
- final int inc = ((to << 16) - val) / steps + 1;
- if (vertical) {
- for (int dy = 0; dy < bandHeight; ++dy, dp += bytesPerLine) {
- bitmapData[dp] = (byte)(val >>> 16);
- val += inc;
- }
- } else {
- for (int dx = 0; dx < bandWidth; ++dx, dp += 4) {
- bitmapData[dp] = (byte)(val >>> 16);
- val += inc;
- }
- }
-}
-
-/*
- * Fill in dithered gradated values for a color channel
- */
-static final void buildDitheredGradientChannel(int from, int to, int steps,
- int bandWidth, int bandHeight, boolean vertical,
- byte[] bitmapData, int dp, int bytesPerLine, int bits) {
- final int mask = 0xff00 >>> bits;
- int val = from << 16;
- final int inc = ((to << 16) - val) / steps + 1;
- if (vertical) {
- for (int dy = 0; dy < bandHeight; ++dy, dp += bytesPerLine) {
- for (int dx = 0, dptr = dp; dx < bandWidth; ++dx, dptr += 4) {
- final int thresh = DITHER_MATRIX[dy & 7][dx] >>> bits;
- int temp = val + thresh;
- if (temp > 0xffffff) bitmapData[dptr] = -1;
- else bitmapData[dptr] = (byte)((temp >>> 16) & mask);
- }
- val += inc;
- }
- } else {
- for (int dx = 0; dx < bandWidth; ++dx, dp += 4) {
- for (int dy = 0, dptr = dp; dy < bandHeight; ++dy, dptr += bytesPerLine) {
- final int thresh = DITHER_MATRIX[dy][dx & 7] >>> bits;
- int temp = val + thresh;
- if (temp > 0xffffff) bitmapData[dptr] = -1;
- else bitmapData[dptr] = (byte)((temp >>> 16) & mask);
- }
- val += inc;
- }
- }
-}
-
-/**
- * Renders a gradient onto a GC.
- * <p>
- * This is a GC helper.
- * </p>
- *
- * @param gc the GC to render the gradient onto
- * @param device the device the GC belongs to
- * @param x the top-left x coordinate of the region to be filled
- * @param y the top-left y coordinate of the region to be filled
- * @param width the width of the region to be filled
- * @param height the height of the region to be filled
- * @param vertical if true sweeps from top to bottom, else
- * sweeps from left to right
- * @param fromRGB the color to start with
- * @param toRGB the color to end with
- * @param redBits the number of significant red bits, 0 for palette modes
- * @param greenBits the number of significant green bits, 0 for palette modes
- * @param blueBits the number of significant blue bits, 0 for palette modes
- */
-static void fillGradientRectangle(GC gc, Device device,
- int x, int y, int width, int height, boolean vertical,
- RGB fromRGB, RGB toRGB,
- int redBits, int greenBits, int blueBits) {
- /* Create the bitmap and tile it */
- ImageData band = createGradientBand(width, height, vertical,
- fromRGB, toRGB, redBits, greenBits, blueBits);
- Image image = new Image(device, band);
- if ((band.width == 1) || (band.height == 1)) {
- gc.drawImage(image, 0, 0, band.width, band.height, x, y, width, height);
- } else {
- if (vertical) {
- for (int dx = 0; dx < width; dx += band.width) {
- int blitWidth = width - dx;
- if (blitWidth > band.width) blitWidth = band.width;
- gc.drawImage(image, 0, 0, blitWidth, band.height, dx + x, y, blitWidth, band.height);
- }
- } else {
- for (int dy = 0; dy < height; dy += band.height) {
- int blitHeight = height - dy;
- if (blitHeight > band.height) blitHeight = band.height;
- gc.drawImage(image, 0, 0, band.width, blitHeight, x, dy + y, band.width, blitHeight);
- }
- }
- }
- image.dispose();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataLoader.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataLoader.java
deleted file mode 100644
index b0aa89772c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageDataLoader.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import java.io.*;
-
-/**
- * Internal class that separates ImageData from ImageLoader
- * to allow removal of ImageLoader from the toolkit.
- */
-class ImageDataLoader {
-
- public static ImageData[] load(InputStream stream) {
- return new ImageLoader().load(stream);
- }
-
- public static ImageData[] load(String filename) {
- return new ImageLoader().load(filename);
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoader.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoader.java
deleted file mode 100755
index 0feebe2873..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoader.java
+++ /dev/null
@@ -1,323 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import java.io.*;
-import java.util.Vector;
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.Compatibility;
-import org.eclipse.swt.internal.image.*;
-
-/**
- * Instances of this class are used to load images from,
- * and save images to, a file or stream.
- * <p>
- * Currently supported image formats are:
- * </p><ul>
- * <li>BMP (Windows or OS/2 Bitmap)</li>
- * <li>ICO (Windows Icon)</li>
- * <li>JPEG</li>
- * <li>GIF</li>
- * <li>PNG</li>
- * <li>TIFF</li>
- * </ul>
- * <code>ImageLoaders</code> can be used to:
- * <ul>
- * <li>load/save single images in all formats</li>
- * <li>load/save multiple images (GIF/ICO/TIFF)</li>
- * <li>load/save animated GIF images</li>
- * <li>load interlaced GIF/PNG images</li>
- * <li>load progressive JPEG images</li>
- * </ul>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ImageAnalyzer</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public class ImageLoader {
-
- /**
- * the array of ImageData objects in this ImageLoader.
- * This array is read in when the load method is called,
- * and it is written out when the save method is called
- */
- public ImageData[] data;
-
- /**
- * the width of the logical screen on which the images
- * reside, in pixels (this corresponds to the GIF89a
- * Logical Screen Width value)
- */
- public int logicalScreenWidth;
-
- /**
- * the height of the logical screen on which the images
- * reside, in pixels (this corresponds to the GIF89a
- * Logical Screen Height value)
- */
- public int logicalScreenHeight;
-
- /**
- * the background pixel for the logical screen (this
- * corresponds to the GIF89a Background Color Index value).
- * The default is -1 which means 'unspecified background'
- *
- */
- public int backgroundPixel;
-
- /**
- * the number of times to repeat the display of a sequence
- * of animated images (this corresponds to the commonly-used
- * GIF application extension for "NETSCAPE 2.0 01").
- * The default is 1. A value of 0 means 'display repeatedly'
- */
- public int repeatCount;
-
- /*
- * the set of ImageLoader event listeners, created on demand
- */
- Vector imageLoaderListeners;
-
-/**
- * Construct a new empty ImageLoader.
- */
-public ImageLoader() {
- reset();
-}
-
-/**
- * Resets the fields of the ImageLoader, except for the
- * <code>imageLoaderListeners</code> field.
- */
-void reset() {
- data = null;
- logicalScreenWidth = 0;
- logicalScreenHeight = 0;
- backgroundPixel = -1;
- repeatCount = 1;
-}
-
-/**
- * Loads an array of <code>ImageData</code> objects from the
- * specified input stream. Throws an error if either an error
- * occurs while loading the images, or if the images are not
- * of a supported type. Returns the loaded image data array.
- *
- * @param stream the input stream to load the images from
- * @return an array of <code>ImageData</code> objects loaded from the specified input stream
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the stream is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from the stream</li>
- * <li>ERROR_INVALID_IMAGE - if the image stream contains invalid data</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format</li>
- * </ul>
- */
-public ImageData[] load(InputStream stream) {
- if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- reset();
- data = FileFormat.load(stream, this);
- return data;
-}
-
-/**
- * Loads an array of <code>ImageData</code> objects from the
- * file with the specified name. Throws an error if either
- * an error occurs while loading the images, or if the images are
- * not of a supported type. Returns the loaded image data array.
- *
- * @param filename the name of the file to load the images from
- * @return an array of <code>ImageData</code> objects loaded from the specified file
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the file name is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from the file</li>
- * <li>ERROR_INVALID_IMAGE - if the image file contains invalid data</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format</li>
- * </ul>
- */
-public ImageData[] load(String filename) {
- if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- InputStream stream = null;
- try {
- stream = Compatibility.newFileInputStream(filename);
- return load(stream);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- } finally {
- try {
- if (stream != null) stream.close();
- } catch (IOException e) {
- // Ignore error
- }
- }
- return null;
-}
-
-/**
- * Saves the image data in this ImageLoader to the specified stream.
- * The format parameter can have one of the following values:
- * <dl>
- * <dt><code>IMAGE_BMP</code></dt>
- * <dd>Windows BMP file format, no compression</dd>
- * <dt><code>IMAGE_BMP_RLE</code></dt>
- * <dd>Windows BMP file format, RLE compression if appropriate</dd>
- * <dt><code>IMAGE_GIF</code></dt>
- * <dd>GIF file format</dd>
- * <dt><code>IMAGE_ICO</code></dt>
- * <dd>Windows ICO file format</dd>
- * <dt><code>IMAGE_JPEG</code></dt>
- * <dd>JPEG file format</dd>
- * <dt><code>IMAGE_PNG</code></dt>
- * <dd>PNG file format</dd>
- * </dl>
- *
- * @param stream the output stream to write the images to
- * @param format the format to write the images in
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the stream is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while writing to the stream</li>
- * <li>ERROR_INVALID_IMAGE - if the image data contains invalid data</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image data cannot be saved to the requested format</li>
- * </ul>
- */
-public void save(OutputStream stream, int format) {
- if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- FileFormat.save(stream, format, this);
-}
-
-/**
- * Saves the image data in this ImageLoader to a file with the specified name.
- * The format parameter can have one of the following values:
- * <dl>
- * <dt><code>IMAGE_BMP</code></dt>
- * <dd>Windows BMP file format, no compression</dd>
- * <dt><code>IMAGE_BMP_RLE</code></dt>
- * <dd>Windows BMP file format, RLE compression if appropriate</dd>
- * <dt><code>IMAGE_GIF</code></dt>
- * <dd>GIF file format</dd>
- * <dt><code>IMAGE_ICO</code></dt>
- * <dd>Windows ICO file format</dd>
- * <dt><code>IMAGE_JPEG</code></dt>
- * <dd>JPEG file format</dd>
- * <dt><code>IMAGE_PNG</code></dt>
- * <dd>PNG file format</dd>
- * </dl>
- *
- * @param filename the name of the file to write the images to
- * @param format the format to write the images in
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the file name is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while writing to the file</li>
- * <li>ERROR_INVALID_IMAGE - if the image data contains invalid data</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image data cannot be saved to the requested format</li>
- * </ul>
- */
-public void save(String filename, int format) {
- if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- OutputStream stream = null;
- try {
- stream = Compatibility.newFileOutputStream(filename);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- save(stream, format);
- try {
- stream.close();
- } catch (IOException e) {
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will be
- * notified when image data is either partially or completely loaded.
- * <p>
- * An ImageLoaderListener should be added before invoking
- * one of the receiver's load methods. The listener's
- * <code>imageDataLoaded</code> method is called when image
- * data has been partially loaded, as is supported by interlaced
- * GIF/PNG or progressive JPEG images.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- *
- * @see ImageLoaderListener
- * @see ImageLoaderEvent
- */
-public void addImageLoaderListener(ImageLoaderListener listener) {
- if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (imageLoaderListeners == null) {
- imageLoaderListeners = new Vector();
- }
- imageLoaderListeners.addElement(listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will be
- * notified when image data is either partially or completely loaded.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- *
- * @see #addImageLoaderListener(ImageLoaderListener)
- */
-public void removeImageLoaderListener(ImageLoaderListener listener) {
- if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (imageLoaderListeners == null) return;
- imageLoaderListeners.removeElement(listener);
-}
-
-/**
- * Returns <code>true</code> if the receiver has image loader
- * listeners, and <code>false</code> otherwise.
- *
- * @return <code>true</code> if there are <code>ImageLoaderListener</code>s, and <code>false</code> otherwise
- *
- * @see #addImageLoaderListener(ImageLoaderListener)
- * @see #removeImageLoaderListener(ImageLoaderListener)
- */
-public boolean hasListeners() {
- return imageLoaderListeners != null && imageLoaderListeners.size() > 0;
-}
-
-/**
- * Notifies all image loader listeners that an image loader event
- * has occurred. Pass the specified event object to each listener.
- *
- * @param event the <code>ImageLoaderEvent</code> to send to each <code>ImageLoaderListener</code>
- */
-public void notifyListeners(ImageLoaderEvent event) {
- if (!hasListeners()) return;
- int size = imageLoaderListeners.size();
- for (int i = 0; i < size; i++) {
- ImageLoaderListener listener = (ImageLoaderListener) imageLoaderListeners.elementAt(i);
- listener.imageDataLoaded(event);
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderEvent.java
deleted file mode 100755
index d365596052..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderEvent.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.SWTEventObject;
-
-/**
- * Instances of this class are sent as a result of the incremental
- * loading of image data.
- * <p>
- * <b>Notes:</b>
- * </p><ul>
- * <li>The number of events which will be sent when loading images
- * is not constant. It varies by image type, and for JPEG images it
- * varies from image to image.</li>
- * <li>For image sources which contain multiple images, the
- * <code>endOfImage</code> flag in the event will be set to true
- * after each individual image is loaded.</li>
- * </ul>
- *
- * @see ImageLoader
- * @see ImageLoaderListener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public class ImageLoaderEvent extends SWTEventObject {
-
- /**
- * if the <code>endOfImage</code> flag is false, then this is a
- * partially complete copy of the current <code>ImageData</code>,
- * otherwise this is a completely loaded <code>ImageData</code>
- */
- public ImageData imageData;
-
- /**
- * the zero-based count of image data increments -- this is
- * equivalent to the number of events that have been generated
- * while loading a particular image
- */
- public int incrementCount;
-
- /**
- * If this flag is true, then the current image data has been
- * completely loaded, otherwise the image data is only partially
- * loaded, and further ImageLoader events will occur unless an
- * exception is thrown
- */
- public boolean endOfImage;
-
- static final long serialVersionUID = 3257284738325558065L;
-
-/**
- * Constructs a new instance of this class given the event source and
- * the values to store in its fields.
- *
- * @param source the ImageLoader that was loading when the event occurred
- * @param imageData the image data for the event
- * @param incrementCount the image data increment for the event
- * @param endOfImage the end of image flag for the event
- */
-public ImageLoaderEvent(ImageLoader source, ImageData imageData, int incrementCount, boolean endOfImage) {
- super(source);
- this.imageData = imageData;
- this.incrementCount = incrementCount;
- this.endOfImage = endOfImage;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the event
- */
-public String toString () {
- return "ImageLoaderEvent {source=" + source + " imageData=" + imageData + " incrementCount=" + incrementCount + " endOfImage=" + endOfImage + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderListener.java
deleted file mode 100755
index 631779fc0a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderListener.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the incremental loading of image data.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to an image loader using the
- * <code>addImageLoaderListener</code> method and removed using
- * the <code>removeImageLoaderListener</code> method. When
- * image data is either partially or completely loaded, this
- * method will be invoked.
- * </p>
- *
- * @see ImageLoader
- * @see ImageLoaderEvent
- */
-
-public interface ImageLoaderListener extends SWTEventListener {
-
-/**
- * Sent when image data is either partially or completely loaded.
- * <p>
- * The timing of when this method is called varies depending on
- * the format of the image being loaded.
- * </p>
- *
- * @param e an event containing information about the image loading operation
- */
-public void imageDataLoaded(ImageLoaderEvent e);
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/LineAttributes.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/LineAttributes.java
deleted file mode 100644
index 6d02341579..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/LineAttributes.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-
-/**
- * <code>LineAttributes</code> defines a set of line attributes that
- * can be modified in a GC.
- * <p>
- * Application code does <em>not</em> need to explicitly release the
- * resources managed by each instance when those instances are no longer
- * required, and thus no <code>dispose()</code> method is provided.
- * </p>
- *
- * @see GC#getLineAttributes()
- * @see GC#setLineAttributes(LineAttributes)
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.3
- */
-public class LineAttributes {
-
- /**
- * The line width.
- */
- public float width;
-
- /**
- * The line style.
- *
- * @see org.eclipse.swt.SWT#LINE_CUSTOM
- * @see org.eclipse.swt.SWT#LINE_DASH
- * @see org.eclipse.swt.SWT#LINE_DASHDOT
- * @see org.eclipse.swt.SWT#LINE_DASHDOTDOT
- * @see org.eclipse.swt.SWT#LINE_DOT
- * @see org.eclipse.swt.SWT#LINE_SOLID
- */
- public int style;
-
- /**
- * The line cap style.
- *
- * @see org.eclipse.swt.SWT#CAP_FLAT
- * @see org.eclipse.swt.SWT#CAP_ROUND
- * @see org.eclipse.swt.SWT#CAP_SQUARE
- */
- public int cap;
-
- /**
- * The line join style.
- *
- * @see org.eclipse.swt.SWT#JOIN_BEVEL
- * @see org.eclipse.swt.SWT#JOIN_MITER
- * @see org.eclipse.swt.SWT#JOIN_ROUND
- */
- public int join;
-
- /**
- * The line dash style for SWT.LINE_CUSTOM.
- */
- public float[] dash;
-
- /**
- * The line dash style offset for SWT.LINE_CUSTOM.
- */
- public float dashOffset;
-
- /**
- * The line miter limit.
- */
- public float miterLimit;
-
-/**
- * Create a new line attributes with the specified line width.
- *
- * @param width the line width
- */
-public LineAttributes(float width) {
- this(width, SWT.CAP_FLAT, SWT.JOIN_MITER, SWT.LINE_SOLID, null, 0, 10);
-}
-
-/**
- * Create a new line attributes with the specified line cap, join and width.
- *
- * @param width the line width
- * @param cap the line cap style
- * @param join the line join style
- */
-public LineAttributes(float width, int cap, int join) {
- this(width, cap, join, SWT.LINE_SOLID, null, 0, 10);
-}
-
-/**
- * Create a new line attributes with the specified arguments.
- *
- * @param width the line width
- * @param cap the line cap style
- * @param join the line join style
- * @param style the line style
- * @param dash the line dash style
- * @param dashOffset the line dash style offset
- * @param miterLimit the line miter limit
- */
-public LineAttributes(float width, int cap, int join, int style, float[] dash, float dashOffset, float miterLimit) {
- this.width = width;
- this.cap = cap;
- this.join = join;
- this.style = style;
- this.dash = dash;
- this.dashOffset = dashOffset;
- this.miterLimit = miterLimit;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PaletteData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PaletteData.java
deleted file mode 100755
index c73a01fa9c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PaletteData.java
+++ /dev/null
@@ -1,214 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class describe the color data used by an image.
- * <p>
- * Depending on the depth of the image, the PaletteData can take one
- * of two forms, indicated by the isDirect field:
- * </p>
- * <dl>
- * <dt>
- * <em>isDirect is false</em>
- * </dt>
- * <dd>
- * If isDirect is <code>false</code>, this palette is an indexed
- * palette which maps pixel values to RGBs. The actual RGB values
- * may be retrieved by using the getRGBs() method.
- * </dd>
- * <dt>
- * <em>isDirect is true</em>
- * </dt>
- * <dd>
- * If isDirect is <code>true</code>, this palette is a direct color
- * palette. Instead of containing RGB values, it contains red,
- * green and blue mask and shift information which indicates how
- * the color components may be extracted from a given pixel.
- * This means that the RGB value is actually encoded in the pixel value.
- * <p>
- * In this case, the shift data is the number of bits required to shift
- * the RGB value to the left in order to align the high bit of the
- * corresponding mask with the high bit of the first byte. This number
- * may be negative, so care must be taken when shifting. For example,
- * with a red mask of 0xFF0000, the red shift would be -16. With a red
- * mask of 0x1F, the red shift would be 3.
- * </p>
- * </dd>
- * </dl>
- *
- * @see Image
- * @see RGB
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class PaletteData {
-
- /**
- * true if the receiver is a direct palette,
- * and false otherwise
- */
- public boolean isDirect;
-
- /**
- * the RGB values for an indexed palette, where the
- * indices of the array correspond to pixel values
- */
- public RGB[] colors;
-
- /**
- * the red mask for a direct palette
- */
- public int redMask;
-
- /**
- * the green mask for a direct palette
- */
- public int greenMask;
-
- /**
- * the blue mask for a direct palette
- */
- public int blueMask;
-
- /**
- * the red shift for a direct palette
- */
- public int redShift;
-
- /**
- * the green shift for a direct palette
- */
- public int greenShift;
-
- /**
- * the blue shift for a direct palette
- */
- public int blueShift;
-
-/**
- * Constructs a new indexed palette given an array of RGB values.
- *
- * @param colors the array of <code>RGB</code>s for the palette
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- */
-public PaletteData(RGB[] colors) {
- if (colors == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.colors = colors;
- this.isDirect = false;
-}
-
-/**
- * Constructs a new direct palette given the red, green and blue masks.
- *
- * @param redMask the red mask
- * @param greenMask the green mask
- * @param blueMask the blue mask
- */
-public PaletteData(int redMask, int greenMask, int blueMask) {
- this.redMask = redMask;
- this.greenMask = greenMask;
- this.blueMask = blueMask;
- this.isDirect = true;
- this.redShift = shiftForMask(redMask);
- this.greenShift = shiftForMask(greenMask);
- this.blueShift = shiftForMask(blueMask);
-}
-
-/**
- * Returns the pixel value corresponding to the given <code>RGB</code>.
- *
- * @param rgb the RGB to get the pixel value for
- * @return the pixel value for the given RGB
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the RGB is not found in the palette</li>
- * </ul>
- */
-public int getPixel(RGB rgb) {
- if (rgb == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (isDirect) {
- int pixel = 0;
- pixel |= (redShift < 0 ? rgb.red << -redShift : rgb.red >>> redShift) & redMask;
- pixel |= (greenShift < 0 ? rgb.green << -greenShift : rgb.green >>> greenShift) & greenMask;
- pixel |= (blueShift < 0 ? rgb.blue << -blueShift : rgb.blue >>> blueShift) & blueMask;
- return pixel;
- } else {
- for (int i = 0; i < colors.length; i++) {
- if (colors[i].equals(rgb)) return i;
- }
- /* The RGB did not exist in the palette */
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return 0;
- }
-}
-
-/**
- * Returns an <code>RGB</code> corresponding to the given pixel value.
- *
- * @param pixel the pixel to get the RGB value for
- * @return the RGB value for the given pixel
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the pixel does not exist in the palette</li>
- * </ul>
- */
-public RGB getRGB(int pixel) {
- if (isDirect) {
- int r = pixel & redMask;
- r = (redShift < 0) ? r >>> -redShift : r << redShift;
- int g = pixel & greenMask;
- g = (greenShift < 0) ? g >>> -greenShift : g << greenShift;
- int b = pixel & blueMask;
- b = (blueShift < 0) ? b >>> -blueShift : b << blueShift;
- return new RGB(r, g, b);
- } else {
- if (pixel < 0 || pixel >= colors.length) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- return colors[pixel];
- }
-}
-
-/**
- * Returns all the RGB values in the receiver if it is an
- * indexed palette, or null if it is a direct palette.
- *
- * @return the <code>RGB</code>s for the receiver or null
- */
-public RGB[] getRGBs() {
- return colors;
-}
-
-/**
- * Computes the shift value for a given mask.
- *
- * @param mask the mask to compute the shift for
- * @return the shift amount
- *
- * @see PaletteData
- */
-int shiftForMask(int mask) {
- for (int i = 31; i >= 0; i--) {
- if (((mask >> i) & 0x1) != 0) return 7 - i;
- }
- return 32;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PathData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PathData.java
deleted file mode 100644
index 8702dcfbe2..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PathData.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-/**
- * Instances of this class describe device-independent paths.
- *
- * @see Path
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public final class PathData {
-
- /**
- * The type of each point.
- */
- public byte[] types;
-
- /**
- * The points of a path.
- */
- public float[] points;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java
deleted file mode 100755
index 3d3f9cbc5d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.SerializableCompatibility;
-
-/**
- * Instances of this class represent places on the (x, y)
- * coordinate plane.
- * <p>
- * The coordinate space for rectangles and points is considered
- * to have increasing values downward and to the right from its
- * origin making this the normal, computer graphics oriented notion
- * of (x, y) coordinates rather than the strict mathematical one.
- * </p>
- * <p>
- * The hashCode() method in this class uses the values of the public
- * fields to compute the hash value. When storing instances of the
- * class in hashed collections, do not modify these fields after the
- * object has been inserted.
- * </p>
- * <p>
- * Application code does <em>not</em> need to explicitly release the
- * resources managed by each instance when those instances are no longer
- * required, and thus no <code>dispose()</code> method is provided.
- * </p>
- *
- * @see Rectangle
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class Point implements SerializableCompatibility {
-
- /**
- * the x coordinate of the point
- */
- public int x;
-
- /**
- * the y coordinate of the point
- */
- public int y;
-
- static final long serialVersionUID = 3257002163938146354L;
-
-/**
- * Constructs a new point with the given x and y coordinates.
- *
- * @param x the x coordinate of the new point
- * @param y the y coordinate of the new point
- */
-public Point (int x, int y) {
- this.x = x;
- this.y = y;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode()
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Point)) return false;
- Point p = (Point)object;
- return (p.x == this.x) && (p.y == this.y);
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals(Object)
- */
-public int hashCode () {
- return x ^ y;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the point
- */
-public String toString () {
- return "Point {" + x + ", " + y + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-}
-
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/RGB.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/RGB.java
deleted file mode 100755
index e7a5630bbd..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/RGB.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.internal.SerializableCompatibility;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class are descriptions of colors in
- * terms of the primary additive color model (red, green and
- * blue). A color may be described in terms of the relative
- * intensities of these three primary colors. The brightness
- * of each color is specified by a value in the range 0 to 255,
- * where 0 indicates no color (blackness) and 255 indicates
- * maximum intensity.
- * <p>
- * The hashCode() method in this class uses the values of the public
- * fields to compute the hash value. When storing instances of the
- * class in hashed collections, do not modify these fields after the
- * object has been inserted.
- * </p>
- * <p>
- * Application code does <em>not</em> need to explicitly release the
- * resources managed by each instance when those instances are no longer
- * required, and thus no <code>dispose()</code> method is provided.
- * </p>
- *
- * @see Color
- * @see <a href="http://www.eclipse.org/swt/snippets/#color">Color and RGB snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class RGB implements SerializableCompatibility {
-
- /**
- * the red component of the RGB
- */
- public int red;
-
- /**
- * the green component of the RGB
- */
- public int green;
-
- /**
- * the blue component of the RGB
- */
- public int blue;
-
- static final long serialVersionUID = 3258415023461249074L;
-
-/**
- * Constructs an instance of this class with the given
- * red, green and blue values.
- *
- * @param red the red component of the new instance
- * @param green the green component of the new instance
- * @param blue the blue component of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255</li>
- * </ul>
- */
-public RGB(int red, int green, int blue) {
- if ((red > 255) || (red < 0) ||
- (green > 255) || (green < 0) ||
- (blue > 255) || (blue < 0))
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.red = red;
- this.green = green;
- this.blue = blue;
-}
-
-/**
-* Constructs an instance of this class with the given
-* hue, saturation, and brightness.
-*
-* @param hue the hue value for the HSB color (from 0 to 360)
-* @param saturation the saturation value for the HSB color (from 0 to 1)
-* @param brightness the brightness value for the HSB color (from 0 to 1)
-*
-* @exception IllegalArgumentException <ul>
-* <li>ERROR_INVALID_ARGUMENT - if the hue is not between 0 and 360 or
-* the saturation or brightness is not between 0 and 1</li>
-* </ul>
-*
-* @since 3.2
-*/
-public RGB(float hue, float saturation, float brightness) {
- if (hue < 0 || hue > 360 || saturation < 0 || saturation > 1 ||
- brightness < 0 || brightness > 1) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- float r, g, b;
- if (saturation == 0) {
- r = g = b = brightness;
- } else {
- if (hue == 360) hue = 0;
- hue /= 60;
- int i = (int)hue;
- float f = hue - i;
- float p = brightness * (1 - saturation);
- float q = brightness * (1 - saturation * f);
- float t = brightness * (1 - saturation * (1 - f));
- switch(i) {
- case 0:
- r = brightness;
- g = t;
- b = p;
- break;
- case 1:
- r = q;
- g = brightness;
- b = p;
- break;
- case 2:
- r = p;
- g = brightness;
- b = t;
- break;
- case 3:
- r = p;
- g = q;
- b = brightness;
- break;
- case 4:
- r = t;
- g = p;
- b = brightness;
- break;
- case 5:
- default:
- r = brightness;
- g = p;
- b = q;
- break;
- }
- }
- red = (int)(r * 255 + 0.5);
- green = (int)(g * 255 + 0.5);
- blue = (int)(b * 255 + 0.5);
-}
-
-/**
- * Returns the hue, saturation, and brightness of the color.
- *
- * @return color space values in float format (hue, saturation, brightness)
- *
- * @since 3.2
- */
-public float[] getHSB() {
- float r = red / 255f;
- float g = green / 255f;
- float b = blue / 255f;
- float max = Math.max(Math.max(r, g), b);
- float min = Math.min(Math.min(r, g), b);
- float delta = max - min;
- float hue = 0;
- float brightness = max;
- float saturation = max == 0 ? 0 : (max - min) / max;
- if (delta != 0) {
- if (r == max) {
- hue = (g - b) / delta;
- } else {
- if (g == max) {
- hue = 2 + (b - r) / delta;
- } else {
- hue = 4 + (r - g) / delta;
- }
- }
- hue *= 60;
- if (hue < 0) hue += 360;
- }
- return new float[] {hue, saturation, brightness};
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode()
- */
-public boolean equals(Object object) {
- if (object == this) return true;
- if (!(object instanceof RGB)) return false;
- RGB rgb = (RGB)object;
- return (rgb.red == this.red) && (rgb.green == this.green) && (rgb.blue == this.blue);
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals(Object)
- */
-public int hashCode() {
- return (blue << 16) | (green << 8) | red;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the <code>RGB</code>
- */
-public String toString() {
- return "RGB {" + red + ", " + green + ", " + blue + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java
deleted file mode 100755
index c09e15f454..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java
+++ /dev/null
@@ -1,346 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.SerializableCompatibility;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class represent rectangular areas in an
- * (x, y) coordinate system. The top left corner of the rectangle
- * is specified by its x and y values, and the extent of the
- * rectangle is specified by its width and height.
- * <p>
- * The coordinate space for rectangles and points is considered
- * to have increasing values downward and to the right from its
- * origin making this the normal, computer graphics oriented notion
- * of (x, y) coordinates rather than the strict mathematical one.
- * </p>
- * <p>
- * The hashCode() method in this class uses the values of the public
- * fields to compute the hash value. When storing instances of the
- * class in hashed collections, do not modify these fields after the
- * object has been inserted.
- * </p>
- * <p>
- * Application code does <em>not</em> need to explicitly release the
- * resources managed by each instance when those instances are no longer
- * required, and thus no <code>dispose()</code> method is provided.
- * </p>
- *
- * @see Point
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class Rectangle implements SerializableCompatibility {
-
- /**
- * the x coordinate of the rectangle
- */
- public int x;
-
- /**
- * the y coordinate of the rectangle
- */
- public int y;
-
- /**
- * the width of the rectangle
- */
- public int width;
-
- /**
- * the height of the rectangle
- */
- public int height;
-
- static final long serialVersionUID = 3256439218279428914L;
-
-/**
- * Construct a new instance of this class given the
- * x, y, width and height values.
- *
- * @param x the x coordinate of the origin of the rectangle
- * @param y the y coordinate of the origin of the rectangle
- * @param width the width of the rectangle
- * @param height the height of the rectangle
- */
-public Rectangle (int x, int y, int width, int height) {
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
-}
-
-/**
- * Destructively replaces the x, y, width and height values
- * in the receiver with ones which represent the union of the
- * rectangles specified by the receiver and the given rectangle.
- * <p>
- * The union of two rectangles is the smallest single rectangle
- * that completely covers both of the areas covered by the two
- * given rectangles.
- * </p>
- *
- * @param rect the rectangle to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- */
-public void add (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int left = x < rect.x ? x : rect.x;
- int top = y < rect.y ? y : rect.y;
- int lhs = x + width;
- int rhs = rect.x + rect.width;
- int right = lhs > rhs ? lhs : rhs;
- lhs = y + height;
- rhs = rect.y + rect.height;
- int bottom = lhs > rhs ? lhs : rhs;
- x = left; y = top; width = right - left; height = bottom - top;
-}
-
-/**
- * Returns <code>true</code> if the point specified by the
- * arguments is inside the area specified by the receiver,
- * and <code>false</code> otherwise.
- *
- * @param x the x coordinate of the point to test for containment
- * @param y the y coordinate of the point to test for containment
- * @return <code>true</code> if the rectangle contains the point and <code>false</code> otherwise
- */
-public boolean contains (int x, int y) {
- return (x >= this.x) && (y >= this.y) && x < (this.x + width) && y < (this.y + height);
-}
-
-/**
- * Returns <code>true</code> if the given point is inside the
- * area specified by the receiver, and <code>false</code>
- * otherwise.
- *
- * @param pt the point to test for containment
- * @return <code>true</code> if the rectangle contains the point and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- */
-public boolean contains (Point pt) {
- if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return contains(pt.x, pt.y);
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode()
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Rectangle)) return false;
- Rectangle r = (Rectangle)object;
- return (r.x == this.x) && (r.y == this.y) && (r.width == this.width) && (r.height == this.height);
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals(Object)
- */
-public int hashCode () {
- return x ^ y ^ width ^ height;
-}
-
-/**
- * Destructively replaces the x, y, width and height values
- * in the receiver with ones which represent the intersection of the
- * rectangles specified by the receiver and the given rectangle.
- *
- * @param rect the rectangle to intersect with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- *
- * since 3.0
- */
-public void intersect (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (this == rect) return;
- int left = x > rect.x ? x : rect.x;
- int top = y > rect.y ? y : rect.y;
- int lhs = x + width;
- int rhs = rect.x + rect.width;
- int right = lhs < rhs ? lhs : rhs;
- lhs = y + height;
- rhs = rect.y + rect.height;
- int bottom = lhs < rhs ? lhs : rhs;
- x = right < left ? 0 : left;
- y = bottom < top ? 0 : top;
- width = right < left ? 0 : right - left;
- height = bottom < top ? 0 : bottom - top;
-}
-
-/**
- * Returns a new rectangle which represents the intersection
- * of the receiver and the given rectangle.
- * <p>
- * The intersection of two rectangles is the rectangle that
- * covers the area which is contained within both rectangles.
- * </p>
- *
- * @param rect the rectangle to intersect with the receiver
- * @return the intersection of the receiver and the argument
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- */
-public Rectangle intersection (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (this == rect) return new Rectangle (x, y, width, height);
- int left = x > rect.x ? x : rect.x;
- int top = y > rect.y ? y : rect.y;
- int lhs = x + width;
- int rhs = rect.x + rect.width;
- int right = lhs < rhs ? lhs : rhs;
- lhs = y + height;
- rhs = rect.y + rect.height;
- int bottom = lhs < rhs ? lhs : rhs;
- return new Rectangle (
- right < left ? 0 : left,
- bottom < top ? 0 : top,
- right < left ? 0 : right - left,
- bottom < top ? 0 : bottom - top);
-}
-
-/**
- * Returns <code>true</code> if the rectangle described by the
- * arguments intersects with the receiver and <code>false</code>
- * otherwise.
- * <p>
- * Two rectangles intersect if the area of the rectangle
- * representing their intersection is not empty.
- * </p>
- *
- * @param x the x coordinate of the origin of the rectangle
- * @param y the y coordinate of the origin of the rectangle
- * @param width the width of the rectangle
- * @param height the height of the rectangle
- * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- *
- * @see #intersection(Rectangle)
- * @see #isEmpty()
- *
- * @since 3.0
- */
-public boolean intersects (int x, int y, int width, int height) {
- return (x < this.x + this.width) && (y < this.y + this.height) &&
- (x + width > this.x) && (y + height > this.y);
-}
-
-/**
- * Returns <code>true</code> if the given rectangle intersects
- * with the receiver and <code>false</code> otherwise.
- * <p>
- * Two rectangles intersect if the area of the rectangle
- * representing their intersection is not empty.
- * </p>
- *
- * @param rect the rectangle to test for intersection
- * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- *
- * @see #intersection(Rectangle)
- * @see #isEmpty()
- */
-public boolean intersects (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return rect == this || intersects (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Returns <code>true</code> if the receiver does not cover any
- * area in the (x, y) coordinate plane, and <code>false</code> if
- * the receiver does cover some area in the plane.
- * <p>
- * A rectangle is considered to <em>cover area</em> in the
- * (x, y) coordinate plane if both its width and height are
- * non-zero.
- * </p>
- *
- * @return <code>true</code> if the receiver is empty, and <code>false</code> otherwise
- */
-public boolean isEmpty () {
- return (width <= 0) || (height <= 0);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the rectangle
- */
-public String toString () {
- return "Rectangle {" + x + ", " + y + ", " + width + ", " + height + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
-}
-
-/**
- * Returns a new rectangle which represents the union of
- * the receiver and the given rectangle.
- * <p>
- * The union of two rectangles is the smallest single rectangle
- * that completely covers both of the areas covered by the two
- * given rectangles.
- * </p>
- *
- * @param rect the rectangle to perform union with
- * @return the union of the receiver and the argument
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- *
- * @see #add(Rectangle)
- */
-public Rectangle union (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int left = x < rect.x ? x : rect.x;
- int top = y < rect.y ? y : rect.y;
- int lhs = x + width;
- int rhs = rect.x + rect.width;
- int right = lhs > rhs ? lhs : rhs;
- lhs = y + height;
- rhs = rect.y + rect.height;
- int bottom = lhs > rhs ? lhs : rhs;
- return new Rectangle (left, top, right - left, bottom - top);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java
deleted file mode 100644
index 82c45043b9..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-
-/**
- * This class is the abstract superclass of all graphics resource objects.
- * Resources created by the application must be disposed.
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation. However, it has not been marked
- * final to allow those outside of the SWT development team to implement
- * patched versions of the class in order to get around specific
- * limitations in advance of when those limitations can be addressed
- * by the team. Any class built using subclassing to access the internals
- * of this class will likely fail to compile or run between releases and
- * may be strongly platform specific. Subclassing should not be attempted
- * without an intimate and detailed understanding of the workings of the
- * hierarchy. No support is provided for user-written classes which are
- * implemented as subclasses of this class.
- * </p>
- *
- * @see #dispose
- * @see #isDisposed
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public abstract class Resource {
-
- /**
- * the device where this resource was created
- */
- Device device;
-
-public Resource() {
-}
-
-Resource(Device device) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = device;
-}
-
-void destroy() {
-}
-
-/**
- * Disposes of the operating system resources associated with
- * this resource. Applications must dispose of all resources
- * which they allocate.
- */
-public void dispose() {
- if (device == null) return;
- if (device.isDisposed()) return;
- destroy();
- if (device.tracking) device.dispose_Object(this);
- device = null;
-}
-
-/**
- * Returns the <code>Device</code> where this resource was
- * created.
- *
- * @return <code>Device</code> the device of the receiver
- *
- * @since 3.2
- */
-public Device getDevice() {
- Device device = this.device;
- if (device == null || isDisposed ()) SWT.error (SWT.ERROR_GRAPHIC_DISPOSED);
- return device;
-}
-
-void init() {
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * Returns <code>true</code> if the resource has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the resource.
- * When a resource has been disposed, it is an error to
- * invoke any other method using the resource.
- *
- * @return <code>true</code> when the resource is disposed and <code>false</code> otherwise
- */
-public abstract boolean isDisposed();
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/TextStyle.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/TextStyle.java
deleted file mode 100644
index 6b7b1cd9a9..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/TextStyle.java
+++ /dev/null
@@ -1,395 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-
-/**
- * <code>TextStyle</code> defines a set of styles that can be applied
- * to a range of text.
- * <p>
- * The hashCode() method in this class uses the values of the public
- * fields to compute the hash value. When storing instances of the
- * class in hashed collections, do not modify these fields after the
- * object has been inserted.
- * </p>
- * <p>
- * Application code does <em>not</em> need to explicitly release the
- * resources managed by each instance when those instances are no longer
- * required, and thus no <code>dispose()</code> method is provided.
- * </p>
- *
- * @see TextLayout
- * @see Font
- * @see Color
- * @see <a href="http://www.eclipse.org/swt/snippets/#textlayout">TextLayout, TextStyle snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.0
- */
-public class TextStyle {
-
- /**
- * the font of the style
- */
- public Font font;
-
- /**
- * the foreground of the style
- */
- public Color foreground;
-
- /**
- * the background of the style
- */
- public Color background;
-
- /**
- * the underline flag of the style. The default underline
- * style is <code>SWT.UNDERLINE_SINGLE</code>.
- *
- *
- * @since 3.1
- */
- public boolean underline;
-
- /**
- * the underline color of the style
- *
- * @since 3.4
- */
- public Color underlineColor;
-
- /**
- * the underline style. This style is ignored when
- * <code>underline</code> is false.
- * <p>
- * This value should be one of <code>SWT.UNDERLINE_SINGLE</code>,
- * <code>SWT.UNDERLINE_DOUBLE</code>, <code>SWT.UNDERLINE_ERROR</code>,
- * or <code>SWT.UNDERLINE_SQUIGGLE</code>.
- * </p>
- *
- * @see SWT#UNDERLINE_SINGLE
- * @see SWT#UNDERLINE_DOUBLE
- * @see SWT#UNDERLINE_ERROR
- * @see SWT#UNDERLINE_SQUIGGLE
- * @see SWT#UNDERLINE_LINK
- *
- * @since 3.4
- */
- public int underlineStyle;
-
- /**
- * the strikeout flag of the style
- *
- * @since 3.1
- */
- public boolean strikeout;
-
- /**
- * the strikeout color of the style
- *
- * @since 3.4
- */
- public Color strikeoutColor;
-
- /**
- * the border style. The default border style is <code>SWT.NONE</code>.
- * <p>
- * This value should be one of <code>SWT.BORDER_SOLID</code>,
- * <code>SWT.BORDER_DASH</code>,<code>SWT.BORDER_DOT</code> or
- * <code>SWT.NONE</code>.
- * </p>
- *
- * @see SWT#BORDER_SOLID
- * @see SWT#BORDER_DASH
- * @see SWT#BORDER_DOT
- * @see SWT#NONE
- *
- * @since 3.4
- */
- public int borderStyle;
-
- /**
- * the border color of the style
- *
- * @since 3.4
- */
- public Color borderColor;
-
- /**
- * the GlyphMetrics of the style
- *
- * @since 3.2
- */
- public GlyphMetrics metrics;
-
- /**
- * the baseline rise of the style.
- *
- * @since 3.2
- */
- public int rise;
-
-
- /**
- * the data. An user data field. It can be used to hold the HREF when the range
- * is used as a link or the embed object when the range is used with <code>GlyphMetrics</code>.
- * <p>
- *
- * @since 3.5
- */
- public Object data;
-
-
-/**
- * Create an empty text style.
- *
- * @since 3.4
- */
-public TextStyle () {
-}
-
-/**
- * Create a new text style with the specified font, foreground
- * and background.
- *
- * @param font the font of the style, <code>null</code> if none
- * @param foreground the foreground color of the style, <code>null</code> if none
- * @param background the background color of the style, <code>null</code> if none
- */
-public TextStyle (Font font, Color foreground, Color background) {
- if (font != null && font.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- if (foreground != null && foreground.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- if (background != null && background.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- this.font = font;
- this.foreground = foreground;
- this.background = background;
-}
-
-
-/**
- * Create a new text style from an existing text style.
- *
- * @param style the style to copy
- *
- * @since 3.4
- */
-public TextStyle (TextStyle style) {
- if (style == null) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- font = style.font;
- foreground = style.foreground;
- background = style.background;
- underline = style.underline;
- underlineColor = style.underlineColor;
- underlineStyle = style.underlineStyle;
- strikeout = style.strikeout;
- strikeoutColor = style.strikeoutColor;
- borderStyle = style.borderStyle;
- borderColor = style.borderColor;
- metrics = style.metrics;
- rise = style.rise;
- data = style.data;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode()
- */
-public boolean equals(Object object) {
- if (object == this) return true;
- if (object == null) return false;
- if (!(object instanceof TextStyle)) return false;
- TextStyle style = (TextStyle)object;
- if (foreground != null) {
- if (!foreground.equals(style.foreground)) return false;
- } else if (style.foreground != null) return false;
- if (background != null) {
- if (!background.equals(style.background)) return false;
- } else if (style.background != null) return false;
- if (font != null) {
- if (!font.equals(style.font)) return false;
- } else if (style.font != null) return false;
- if (metrics != null || style.metrics != null) return false;
- if (underline != style.underline) return false;
- if (underlineStyle != style.underlineStyle) return false;
- if (borderStyle != style.borderStyle) return false;
- if (strikeout != style.strikeout) return false;
- if (rise != style.rise) return false;
- if (underlineColor != null) {
- if (!underlineColor.equals(style.underlineColor)) return false;
- } else if (style.underlineColor != null) return false;
- if (strikeoutColor != null) {
- if (!strikeoutColor.equals(style.strikeoutColor)) return false;
- } else if (style.strikeoutColor != null) return false;
- if (underlineStyle != style.underlineStyle) return false;
- if (borderColor != null) {
- if (!borderColor.equals(style.borderColor)) return false;
- } else if (style.borderColor != null) return false;
- if (data != null) {
- if (!data.equals(style.data)) return false;
- } else if (style.data != null) return false;
- return true;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals(Object)
- */
-public int hashCode() {
- int hash = 0;
- if (foreground != null) hash ^= foreground.hashCode();
- if (background != null) hash ^= background.hashCode();
- if (font != null) hash ^= font.hashCode();
- if (metrics != null) hash ^= metrics.hashCode();
- if (underline) hash ^= hash;
- if (strikeout) hash ^= hash;
- hash ^= rise;
- if (underlineColor != null) hash ^= underlineColor.hashCode();
- if (strikeoutColor != null) hash ^= strikeoutColor.hashCode();
- if (borderColor != null) hash ^= borderColor.hashCode();
- hash ^= underlineStyle;
- return hash;
-}
-
-boolean isAdherentBorder(TextStyle style) {
- if (this == style) return true;
- if (style == null) return false;
- if (borderStyle != style.borderStyle) return false;
- if (borderColor != null) {
- if (!borderColor.equals(style.borderColor)) return false;
- } else {
- if (style.borderColor != null) return false;
- if (foreground != null) {
- if (!foreground.equals(style.foreground)) return false;
- } else if (style.foreground != null) return false;
- }
- return true;
-}
-
-boolean isAdherentUnderline(TextStyle style) {
- if (this == style) return true;
- if (style == null) return false;
- if (underline != style.underline) return false;
- if (underlineStyle != style.underlineStyle) return false;
- if (underlineColor != null) {
- if (!underlineColor.equals(style.underlineColor)) return false;
- } else {
- if (style.underlineColor != null) return false;
- if (foreground != null) {
- if (!foreground.equals(style.foreground)) return false;
- } else if (style.foreground != null) return false;
- }
- return true;
-}
-
-boolean isAdherentStrikeout(TextStyle style) {
- if (this == style) return true;
- if (style == null) return false;
- if (strikeout != style.strikeout) return false;
- if (strikeoutColor != null) {
- if (!strikeoutColor.equals(style.strikeoutColor)) return false;
- } else {
- if (style.strikeoutColor != null) return false;
- if (foreground != null) {
- if (!foreground.equals(style.foreground)) return false;
- } else if (style.foreground != null) return false;
- }
- return true;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the <code>TextStyle</code>
- */
-public String toString () {
- StringBuffer buffer = new StringBuffer("TextStyle {"); //$NON-NLS-1$
- int startLength = buffer.length();
- if (font != null) {
- if (buffer.length() > startLength) buffer.append(", "); //$NON-NLS-1$
- buffer.append("font="); //$NON-NLS-1$
- buffer.append(font);
- }
- if (foreground != null) {
- if (buffer.length() > startLength) buffer.append(", "); //$NON-NLS-1$
- buffer.append("foreground="); //$NON-NLS-1$
- buffer.append(foreground);
- }
- if (background != null) {
- if (buffer.length() > startLength) buffer.append(", "); //$NON-NLS-1$
- buffer.append("background="); //$NON-NLS-1$
- buffer.append(background);
- }
- if (underline) {
- if (buffer.length() > startLength) buffer.append(", "); //$NON-NLS-1$
- buffer.append("underline="); //$NON-NLS-1$
- switch (underlineStyle) {
- case SWT.UNDERLINE_SINGLE: buffer.append("single"); break; //$NON-NLS-1$
- case SWT.UNDERLINE_DOUBLE: buffer.append("double"); break; //$NON-NLS-1$
- case SWT.UNDERLINE_SQUIGGLE: buffer.append("squiggle"); break; //$NON-NLS-1$
- case SWT.UNDERLINE_ERROR: buffer.append("error"); break; //$NON-NLS-1$
- case SWT.UNDERLINE_LINK: buffer.append("link"); break; //$NON-NLS-1$
- }
- if (underlineColor != null) {
- buffer.append(", underlineColor="); //$NON-NLS-1$
- buffer.append(underlineColor);
- }
- }
- if (strikeout) {
- if (buffer.length() > startLength) buffer.append(", "); //$NON-NLS-1$
- buffer.append("striked out"); //$NON-NLS-1$
- if (strikeoutColor != null) {
- buffer.append(", strikeoutColor="); //$NON-NLS-1$
- buffer.append(strikeoutColor);
- }
- }
- if (borderStyle != SWT.NONE) {
- if (buffer.length() > startLength) buffer.append(", "); //$NON-NLS-1$
- buffer.append("border="); //$NON-NLS-1$
- switch (borderStyle) {
- case SWT.BORDER_SOLID: buffer.append("solid"); break; //$NON-NLS-1$
- case SWT.BORDER_DOT: buffer.append("dot"); break; //$NON-NLS-1$
- case SWT.BORDER_DASH: buffer.append("dash"); break; //$NON-NLS-1$
- }
- if (borderColor != null) {
- buffer.append(", borderColor="); //$NON-NLS-1$
- buffer.append(borderColor);
- }
- }
- if (rise != 0) {
- if (buffer.length() > startLength) buffer.append(", "); //$NON-NLS-1$
- buffer.append("rise="); //$NON-NLS-1$
- buffer.append(rise);
- }
- if (metrics != null) {
- if (buffer.length() > startLength) buffer.append(", "); //$NON-NLS-1$
- buffer.append("metrics="); //$NON-NLS-1$
- buffer.append(metrics);
- }
- buffer.append("}"); //$NON-NLS-1$
- return buffer.toString();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/package.html b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/package.html
deleted file mode 100755
index d71267ad85..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/package.html
+++ /dev/null
@@ -1,18 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-<html>
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <meta name="Author" content="IBM">
- <title>Package-level Javadoc</title>
-</head>
-<body>
-SWT graphics classes.
-<h2>
-Package Specification</h2>
-This package provides the classes which implement points, rectangles,
-regions, colors, cursors, fonts, graphics contexts (that is, <code>GC</code>s)
-where most of the primitive drawing operations are implemented, and
-images including both the code for displaying them and the public API for
-loading/saving them.
-</body>
-</html>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/Callback.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/Callback.java
deleted file mode 100755
index ce73d17e0e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/Callback.java
+++ /dev/null
@@ -1,243 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal;
-
-
-/**
- * Instances of this class represent entry points into Java
- * which can be invoked from operating system level callback
- * routines.
- * <p>
- * IMPORTANT: A callback is only valid when invoked on the
- * thread which created it. The results are undefined (and
- * typically bad) when a callback is passed out to the
- * operating system (or other code) in such a way that the
- * callback is called from a different thread.
- */
-
-public class Callback {
-
- Object object;
- String method, signature;
- int argCount;
- int /*long*/ address, errorResult;
- boolean isStatic, isArrayBased;
-
- static final String PTR_SIGNATURE = C.PTR_SIZEOF == 4 ? "I" : "J"; //$NON-NLS-1$ //$NON-NLS-2$
- static final String SIGNATURE_0 = getSignature(0);
- static final String SIGNATURE_1 = getSignature(1);
- static final String SIGNATURE_2 = getSignature(2);
- static final String SIGNATURE_3 = getSignature(3);
- static final String SIGNATURE_4 = getSignature(4);
- static final String SIGNATURE_N = "(["+PTR_SIGNATURE+")"+PTR_SIGNATURE; //$NON-NLS-1$ //$NON-NLS-2$
-
-/**
- * Constructs a new instance of this class given an object
- * to send the message to, a string naming the method to
- * invoke and an argument count. Note that, if the object
- * is an instance of <code>Class</code> it is assumed that
- * the method is a static method on that class.
- *
- * @param object the object to send the message to
- * @param method the name of the method to invoke
- * @param argCount the number of arguments that the method takes
- */
-public Callback (Object object, String method, int argCount) {
- this (object, method, argCount, false);
-}
-
-/**
- * Constructs a new instance of this class given an object
- * to send the message to, a string naming the method to
- * invoke, an argument count and a flag indicating whether
- * or not the arguments will be passed in an array. Note
- * that, if the object is an instance of <code>Class</code>
- * it is assumed that the method is a static method on that
- * class.
- *
- * @param object the object to send the message to
- * @param method the name of the method to invoke
- * @param argCount the number of arguments that the method takes
- * @param isArrayBased <code>true</code> if the arguments should be passed in an array and false otherwise
- */
-public Callback (Object object, String method, int argCount, boolean isArrayBased) {
- this (object, method, argCount, isArrayBased, 0);
-}
-
-/**
- * Constructs a new instance of this class given an object
- * to send the message to, a string naming the method to
- * invoke, an argument count, a flag indicating whether
- * or not the arguments will be passed in an array and a value
- * to return when an exception happens. Note that, if
- * the object is an instance of <code>Class</code>
- * it is assumed that the method is a static method on that
- * class.
- *
- * @param object the object to send the message to
- * @param method the name of the method to invoke
- * @param argCount the number of arguments that the method takes
- * @param isArrayBased <code>true</code> if the arguments should be passed in an array and false otherwise
- * @param errorResult the return value if the java code throws an exception
- */
-public Callback (Object object, String method, int argCount, boolean isArrayBased, int /*long*/ errorResult) {
-
- /* Set the callback fields */
- this.object = object;
- this.method = method;
- this.argCount = argCount;
- this.isStatic = object instanceof Class;
- this.isArrayBased = isArrayBased;
- this.errorResult = errorResult;
-
- /* Inline the common cases */
- if (isArrayBased) {
- signature = SIGNATURE_N;
- } else {
- switch (argCount) {
- case 0: signature = SIGNATURE_0; break; //$NON-NLS-1$
- case 1: signature = SIGNATURE_1; break; //$NON-NLS-1$
- case 2: signature = SIGNATURE_2; break; //$NON-NLS-1$
- case 3: signature = SIGNATURE_3; break; //$NON-NLS-1$
- case 4: signature = SIGNATURE_4; break; //$NON-NLS-1$
- default:
- signature = getSignature(argCount);
- }
- }
-
- /* Bind the address */
- address = bind (this, object, method, signature, argCount, isStatic, isArrayBased, errorResult);
-}
-
-/**
- * Allocates the native level resources associated with the
- * callback. This method is only invoked from within the
- * constructor for the argument.
- *
- * @param callback the callback to bind
- * @param object the callback's object
- * @param method the callback's method
- * @param signature the callback's method signature
- * @param argCount the callback's method argument count
- * @param isStatic whether the callback's method is static
- * @param isArrayBased whether the callback's method is array based
- * @param errorResult the callback's error result
- */
-static native synchronized int /*long*/ bind (Callback callback, Object object, String method, String signature, int argCount, boolean isStatic, boolean isArrayBased, int /*long*/ errorResult);
-
-/**
- * Releases the native level resources associated with the callback,
- * and removes all references between the callback and
- * other objects. This helps to prevent (bad) application code
- * from accidentally holding onto extraneous garbage.
- */
-public void dispose () {
- if (object == null) return;
- unbind (this);
- object = method = signature = null;
- address = 0;
-}
-
-/**
- * Returns the address of a block of machine code which will
- * invoke the callback represented by the receiver.
- *
- * @return the callback address
- */
-public int /*long*/ getAddress () {
- return address;
-}
-
-/**
- * Returns the SWT platform name.
- *
- * @return the platform name of the currently running SWT
- */
-public static native String getPlatform ();
-
-/**
- * Returns the number of times the system has been recursively entered
- * through a callback.
- * <p>
- * Note: This should not be called by application code.
- * </p>
- *
- * @return the entry count
- *
- * @since 2.1
- */
-public static native int getEntryCount ();
-
-static String getSignature(int argCount) {
- String signature = "("; //$NON-NLS-1$
- for (int i = 0; i < argCount; i++) signature += PTR_SIGNATURE;
- signature += ")" + PTR_SIGNATURE; //$NON-NLS-1$
- return signature;
-}
-
-/**
- * Indicates whether or not callbacks which are triggered at the
- * native level should cause the messages described by the matching
- * <code>Callback</code> objects to be invoked. This method is used
- * to safely shut down SWT when it is run within environments
- * which can generate spurious events.
- * <p>
- * Note: This should not be called by application code.
- * </p>
- *
- * @param enable true if callbacks should be invoked
- */
-public static final native synchronized void setEnabled (boolean enable);
-
-/**
- * Returns whether or not callbacks which are triggered at the
- * native level should cause the messages described by the matching
- * <code>Callback</code> objects to be invoked. This method is used
- * to safely shut down SWT when it is run within environments
- * which can generate spurious events.
- * <p>
- * Note: This should not be called by application code.
- * </p>
- *
- * @return true if callbacks should not be invoked
- */
-public static final native synchronized boolean getEnabled ();
-
-/**
- * This might be called directly from native code in environments
- * which can generate spurious events. Check before removing it.
- *
- * @deprecated
- *
- * @param ignore true if callbacks should not be invoked
- */
-static final void ignoreCallbacks (boolean ignore) {
- setEnabled (!ignore);
-}
-
-/**
- * Immediately wipes out all native level state associated
- * with <em>all</em> callbacks.
- * <p>
- * <b>WARNING:</b> This operation is <em>extremely</em> dangerous,
- * and should never be performed by application code.
- * </p>
- */
-public static final native synchronized void reset ();
-
-/**
- * Releases the native level resources associated with the callback.
- *
- * @see #dispose
- */
-static final native synchronized void unbind (Callback callback);
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java
deleted file mode 100755
index 074b038bb5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import java.io.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Abstract factory class for loading/unloading images from files or streams
- * in various image file formats.
- *
- */
-public abstract class FileFormat {
- static final String FORMAT_PACKAGE = "org.eclipse.swt.internal.image"; //$NON-NLS-1$
- static final String FORMAT_SUFFIX = "FileFormat"; //$NON-NLS-1$
- static final String[] FORMATS = {"WinBMP", "WinBMP", "GIF", "WinICO", "JPEG", "PNG", "TIFF", "OS2BMP"}; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$//$NON-NLS-5$ //$NON-NLS-6$//$NON-NLS-7$//$NON-NLS-8$
-
- LEDataInputStream inputStream;
- LEDataOutputStream outputStream;
- ImageLoader loader;
- int compression;
-
-/**
- * Return whether or not the specified input stream
- * represents a supported file format.
- */
-abstract boolean isFileFormat(LEDataInputStream stream);
-
-abstract ImageData[] loadFromByteStream();
-
-/**
- * Read the specified input stream, and return the
- * device independent image array represented by the stream.
- */
-public ImageData[] loadFromStream(LEDataInputStream stream) {
- try {
- inputStream = stream;
- return loadFromByteStream();
- } catch (Exception e) {
- if (e instanceof IOException) {
- SWT.error(SWT.ERROR_IO, e);
- } else {
- SWT.error(SWT.ERROR_INVALID_IMAGE, e);
- }
- return null;
- }
-}
-
-/**
- * Read the specified input stream using the specified loader, and
- * return the device independent image array represented by the stream.
- */
-public static ImageData[] load(InputStream is, ImageLoader loader) {
- FileFormat fileFormat = null;
- LEDataInputStream stream = new LEDataInputStream(is);
- boolean isSupported = false;
- for (int i = 1; i < FORMATS.length; i++) {
- if (FORMATS[i] != null) {
- try {
- Class clazz = Class.forName(FORMAT_PACKAGE + '.' + FORMATS[i] + FORMAT_SUFFIX);
- fileFormat = (FileFormat) clazz.newInstance();
- if (fileFormat.isFileFormat(stream)) {
- isSupported = true;
- break;
- }
- } catch (ClassNotFoundException e) {
- FORMATS[i] = null;
- } catch (Exception e) {
- }
- }
- }
- if (!isSupported) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
- fileFormat.loader = loader;
- return fileFormat.loadFromStream(stream);
-}
-
-/**
- * Write the device independent image array stored in the specified loader
- * to the specified output stream using the specified file format.
- */
-public static void save(OutputStream os, int format, ImageLoader loader) {
- if (format < 0 || format >= FORMATS.length) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
- if (FORMATS[format] == null) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
- if (loader.data == null || loader.data.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-
- LEDataOutputStream stream = new LEDataOutputStream(os);
- FileFormat fileFormat = null;
- try {
- Class clazz = Class.forName(FORMAT_PACKAGE + '.' + FORMATS[format] + FORMAT_SUFFIX);
- fileFormat = (FileFormat) clazz.newInstance();
- } catch (Exception e) {
- SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
- }
- if (format == SWT.IMAGE_BMP_RLE) {
- switch (loader.data[0].depth) {
- case 8: fileFormat.compression = 1; break;
- case 4: fileFormat.compression = 2; break;
- }
- }
- fileFormat.unloadIntoStream(loader, stream);
-}
-
-abstract void unloadIntoByteStream(ImageLoader loader);
-
-/**
- * Write the device independent image array stored in the specified loader
- * to the specified output stream.
- */
-public void unloadIntoStream(ImageLoader loader, LEDataOutputStream stream) {
- try {
- outputStream = stream;
- unloadIntoByteStream(loader);
- outputStream.flush();
- } catch (Exception e) {
- try {outputStream.flush();} catch (Exception f) {}
- SWT.error(SWT.ERROR_IO, e);
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/GIFFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/GIFFileFormat.java
deleted file mode 100755
index 583e7c0e99..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/GIFFileFormat.java
+++ /dev/null
@@ -1,612 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import java.io.*;
-
-public final class GIFFileFormat extends FileFormat {
- String signature;
- int screenWidth, screenHeight, backgroundPixel, bitsPerPixel, defaultDepth;
- int disposalMethod = 0;
- int delayTime = 0;
- int transparentPixel = -1;
- int repeatCount = 1;
-
- static final int GIF_APPLICATION_EXTENSION_BLOCK_ID = 0xFF;
- static final int GIF_GRAPHICS_CONTROL_BLOCK_ID = 0xF9;
- static final int GIF_PLAIN_TEXT_BLOCK_ID = 0x01;
- static final int GIF_COMMENT_BLOCK_ID = 0xFE;
- static final int GIF_EXTENSION_BLOCK_ID = 0x21;
- static final int GIF_IMAGE_BLOCK_ID = 0x2C;
- static final int GIF_TRAILER_ID = 0x3B;
- static final byte [] GIF89a = new byte[] { (byte)'G', (byte)'I', (byte)'F', (byte)'8', (byte)'9', (byte)'a' };
- static final byte [] NETSCAPE2_0 = new byte[] { (byte)'N', (byte)'E', (byte)'T', (byte)'S', (byte)'C', (byte)'A', (byte)'P', (byte)'E', (byte)'2', (byte)'.', (byte)'0' };
-
- /**
- * Answer a palette containing numGrays
- * shades of gray, ranging from black to white.
- */
- static PaletteData grayRamp(int numGrays) {
- int n = numGrays - 1;
- RGB[] colors = new RGB[numGrays];
- for (int i = 0; i < numGrays; i++) {
- int intensity = (byte)((i * 3) * 256 / n);
- colors[i] = new RGB(intensity, intensity, intensity);
- }
- return new PaletteData(colors);
- }
-
- boolean isFileFormat(LEDataInputStream stream) {
- try {
- byte[] signature = new byte[3];
- stream.read(signature);
- stream.unread(signature);
- return signature[0] == 'G' && signature[1] == 'I' && signature[2] == 'F';
- } catch (Exception e) {
- return false;
- }
- }
-
- /**
- * Load the GIF image(s) stored in the input stream.
- * Return an array of ImageData representing the image(s).
- */
- ImageData[] loadFromByteStream() {
- byte[] signature = new byte[3];
- byte[] versionBytes = new byte[3];
- byte[] block = new byte[7];
- try {
- inputStream.read(signature);
- if (!(signature[0] == 'G' && signature[1] == 'I' && signature[2] == 'F'))
- SWT.error(SWT.ERROR_INVALID_IMAGE);
-
- inputStream.read(versionBytes);
-
- inputStream.read(block);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- screenWidth = (block[0] & 0xFF) | ((block[1] & 0xFF) << 8);
- loader.logicalScreenWidth = screenWidth;
- screenHeight = (block[2] & 0xFF) | ((block[3] & 0xFF) << 8);
- loader.logicalScreenHeight = screenHeight;
- byte bitField = block[4];
- backgroundPixel = block[5] & 0xFF;
- //aspect = block[6] & 0xFF;
- bitsPerPixel = ((bitField >> 4) & 0x07) + 1;
- defaultDepth = (bitField & 0x7) + 1;
- PaletteData palette = null;
- if ((bitField & 0x80) != 0) {
- // Global palette.
- //sorted = (bitField & 0x8) != 0;
- palette = readPalette(1 << defaultDepth);
- } else {
- // No global palette.
- //sorted = false;
- backgroundPixel = -1;
- defaultDepth = bitsPerPixel;
- }
- loader.backgroundPixel = backgroundPixel;
-
- getExtensions();
- int id = readID();
- ImageData[] images = new ImageData[0];
- while (id == GIF_IMAGE_BLOCK_ID) {
- ImageData image = readImageBlock(palette);
- if (loader.hasListeners()) {
- loader.notifyListeners(new ImageLoaderEvent(loader, image, 3, true));
- }
- ImageData[] oldImages = images;
- images = new ImageData[oldImages.length + 1];
- System.arraycopy(oldImages, 0, images, 0, oldImages.length);
- images[images.length - 1] = image;
- try {
- /* Read the 0-byte terminator at the end of the image. */
- id = inputStream.read();
- if (id > 0) {
- /* We read the terminator earlier. */
- inputStream.unread(new byte[] {(byte)id});
- }
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- getExtensions();
- id = readID();
- }
- return images;
- }
-
- /**
- * Read and return the next block or extension identifier from the file.
- */
- int readID() {
- try {
- return inputStream.read();
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- return -1;
- }
-
- /**
- * Read extensions until an image descriptor appears.
- * In the future, if we care about the extensions, they
- * should be properly grouped with the image data before
- * which they appeared. Right now, the interesting parts
- * of some extensions are kept, but the rest is discarded.
- * Throw an error if an error occurs.
- */
- void getExtensions() {
- int id = readID();
- while (id != GIF_IMAGE_BLOCK_ID && id != GIF_TRAILER_ID && id > 0) {
- if (id == GIF_EXTENSION_BLOCK_ID) {
- readExtension();
- } else {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- id = readID();
- }
- if (id == GIF_IMAGE_BLOCK_ID || id == GIF_TRAILER_ID) {
- try {
- inputStream.unread(new byte[] {(byte)id});
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
- }
-
- /**
- * Read a control extension.
- * Return the extension block data.
- */
- byte[] readExtension() {
- int extensionID = readID();
- if (extensionID == GIF_COMMENT_BLOCK_ID)
- return readCommentExtension();
- if (extensionID == GIF_PLAIN_TEXT_BLOCK_ID)
- return readPlainTextExtension();
- if (extensionID == GIF_GRAPHICS_CONTROL_BLOCK_ID)
- return readGraphicsControlExtension();
- if (extensionID == GIF_APPLICATION_EXTENSION_BLOCK_ID)
- return readApplicationExtension();
- // Otherwise, we don't recognize the block. If the
- // field size is correct, we can just skip over
- // the block contents.
- try {
- int extSize = inputStream.read();
- if (extSize < 0) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- byte[] ext = new byte[extSize];
- inputStream.read(ext, 0, extSize);
- return ext;
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- return null;
- }
- }
-
- /**
- * We have just read the Comment extension identifier
- * from the input stream. Read in the rest of the comment
- * and return it. GIF comment blocks are variable size.
- */
- byte[] readCommentExtension() {
- try {
- byte[] comment = new byte[0];
- byte[] block = new byte[255];
- int size = inputStream.read();
- while ((size > 0) && (inputStream.read(block, 0, size) != -1)) {
- byte[] oldComment = comment;
- comment = new byte[oldComment.length + size];
- System.arraycopy(oldComment, 0, comment, 0, oldComment.length);
- System.arraycopy(block, 0, comment, oldComment.length, size);
- size = inputStream.read();
- }
- return comment;
- } catch (Exception e) {
- SWT.error(SWT.ERROR_IO, e);
- return null;
- }
- }
-
- /**
- * We have just read the PlainText extension identifier
- * from the input stream. Read in the plain text info and text,
- * and return the text. GIF plain text blocks are variable size.
- */
- byte[] readPlainTextExtension() {
- try {
- // Read size of block = 0x0C.
- inputStream.read();
- // Read the text information (x, y, width, height, colors).
- byte[] info = new byte[12];
- inputStream.read(info);
- // Read the text.
- byte[] text = new byte[0];
- byte[] block = new byte[255];
- int size = inputStream.read();
- while ((size > 0) && (inputStream.read(block, 0, size) != -1)) {
- byte[] oldText = text;
- text = new byte[oldText.length + size];
- System.arraycopy(oldText, 0, text, 0, oldText.length);
- System.arraycopy(block, 0, text, oldText.length, size);
- size = inputStream.read();
- }
- return text;
- } catch (Exception e) {
- SWT.error(SWT.ERROR_IO, e);
- return null;
- }
- }
-
- /**
- * We have just read the GraphicsControl extension identifier
- * from the input stream. Read in the control information, store
- * it, and return it.
- */
- byte[] readGraphicsControlExtension() {
- try {
- // Read size of block = 0x04.
- inputStream.read();
- // Read the control block.
- byte[] controlBlock = new byte[4];
- inputStream.read(controlBlock);
- byte bitField = controlBlock[0];
- // Store the user input field.
- //userInput = (bitField & 0x02) != 0;
- // Store the disposal method.
- disposalMethod = (bitField >> 2) & 0x07;
- // Store the delay time.
- delayTime = (controlBlock[1] & 0xFF) | ((controlBlock[2] & 0xFF) << 8);
- // Store the transparent color.
- if ((bitField & 0x01) != 0) {
- transparentPixel = controlBlock[3] & 0xFF;
- } else {
- transparentPixel = -1;
- }
- // Read block terminator.
- inputStream.read();
- return controlBlock;
- } catch (Exception e) {
- SWT.error(SWT.ERROR_IO, e);
- return null;
- }
- }
-
- /**
- * We have just read the Application extension identifier
- * from the input stream. Read in the rest of the extension,
- * look for and store 'number of repeats', and return the data.
- */
- byte[] readApplicationExtension() {
- try {
- // Read block data.
- int blockSize = inputStream.read();
- byte[] blockData = new byte[blockSize];
- inputStream.read(blockData);
- // Read application data.
- byte[] data = new byte[0];
- byte[] block = new byte[255];
- int size = inputStream.read();
- while ((size > 0) && (inputStream.read(block, 0, size) != -1)) {
- byte[] oldData = data;
- data = new byte[oldData.length + size];
- System.arraycopy(oldData, 0, data, 0, oldData.length);
- System.arraycopy(block, 0, data, oldData.length, size);
- size = inputStream.read();
- }
- // Look for the NETSCAPE 'repeat count' field for an animated GIF.
- boolean netscape =
- blockSize > 7 &&
- blockData[0] == 'N' &&
- blockData[1] == 'E' &&
- blockData[2] == 'T' &&
- blockData[3] == 'S' &&
- blockData[4] == 'C' &&
- blockData[5] == 'A' &&
- blockData[6] == 'P' &&
- blockData[7] == 'E';
- boolean authentic =
- blockSize > 10 &&
- blockData[8] == '2' &&
- blockData[9] == '.' &&
- blockData[10] == '0';
- if (netscape && authentic && data[0] == 01) { //$NON-NLS-1$ //$NON-NLS-2$
- repeatCount = (data[1] & 0xFF) | ((data[2] & 0xFF) << 8);
- loader.repeatCount = repeatCount;
- }
- return data;
- } catch (Exception e) {
- SWT.error(SWT.ERROR_IO, e);
- return null;
- }
- }
-
- /**
- * Return a DeviceIndependentImage representing the
- * image block at the current position in the input stream.
- * Throw an error if an error occurs.
- */
- ImageData readImageBlock(PaletteData defaultPalette) {
- int depth;
- PaletteData palette;
- byte[] block = new byte[9];
- try {
- inputStream.read(block);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- int left = (block[0] & 0xFF) | ((block[1] & 0xFF) << 8);
- int top = (block[2] & 0xFF) | ((block[3] & 0xFF) << 8);
- int width = (block[4] & 0xFF) | ((block[5] & 0xFF) << 8);
- int height = (block[6] & 0xFF) | ((block[7] & 0xFF) << 8);
- byte bitField = block[8];
- boolean interlaced = (bitField & 0x40) != 0;
- //boolean sorted = (bitField & 0x20) != 0;
- if ((bitField & 0x80) != 0) {
- // Local palette.
- depth = (bitField & 0x7) + 1;
- palette = readPalette(1 << depth);
- } else {
- // No local palette.
- depth = defaultDepth;
- palette = defaultPalette;
- }
- /* Work around: Ignore the case where a GIF specifies an
- * invalid index for the transparent pixel that is larger
- * than the number of entries in the palette. */
- if (transparentPixel > 1 << depth) {
- transparentPixel = -1;
- }
- // Promote depth to next highest supported value.
- if (!(depth == 1 || depth == 4 || depth == 8)) {
- if (depth < 4)
- depth = 4;
- else
- depth = 8;
- }
- if (palette == null) {
- palette = grayRamp(1 << depth);
- }
- int initialCodeSize = -1;
- try {
- initialCodeSize = inputStream.read();
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- if (initialCodeSize < 0) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- ImageData image = ImageData.internal_new(
- width,
- height,
- depth,
- palette,
- 4,
- null,
- 0,
- null,
- null,
- -1,
- transparentPixel,
- SWT.IMAGE_GIF,
- left,
- top,
- disposalMethod,
- delayTime);
- LZWCodec codec = new LZWCodec();
- codec.decode(inputStream, loader, image, interlaced, initialCodeSize);
- return image;
- }
-
- /**
- * Read a palette from the input stream.
- */
- PaletteData readPalette(int numColors) {
- byte[] bytes = new byte[numColors * 3];
- try {
- if (inputStream.read(bytes) != bytes.length)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- RGB[] colors = new RGB[numColors];
- for (int i = 0; i < numColors; i++)
- colors[i] = new RGB(bytes[i*3] & 0xFF,
- bytes[i*3+1] & 0xFF, bytes[i*3+2] & 0xFF);
- return new PaletteData(colors);
- }
-
- void unloadIntoByteStream(ImageLoader loader) {
-
- /* Step 1: Acquire GIF parameters. */
- ImageData[] data = loader.data;
- int frameCount = data.length;
- boolean multi = frameCount > 1;
- ImageData firstImage = data[0];
- int logicalScreenWidth = multi ? loader.logicalScreenWidth : firstImage.width;
- int logicalScreenHeight = multi ? loader.logicalScreenHeight : firstImage.height;
- int backgroundPixel = loader.backgroundPixel;
- int depth = firstImage.depth;
- PaletteData palette = firstImage.palette;
- RGB[] colors = palette.getRGBs();
- short globalTable = 1;
-
- /* Step 2: Check for validity and global/local color map. */
- if (!(depth == 1 || depth == 4 || depth == 8)) {
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- }
- for (int i=0; i<frameCount; i++) {
- if (data[i].palette.isDirect) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- if (multi) {
- if (!(data[i].height <= logicalScreenHeight && data[i].width <= logicalScreenWidth && data[i].depth == depth)) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- if (globalTable == 1) {
- RGB rgbs[] = data[i].palette.getRGBs();
- if (rgbs.length != colors.length) {
- globalTable = 0;
- } else {
- for (int j=0; j<colors.length; j++) {
- if (!(rgbs[j].red == colors[j].red &&
- rgbs[j].green == colors[j].green &&
- rgbs[j].blue == colors[j].blue))
- globalTable = 0;
- }
- }
- }
- }
- }
-
- try {
- /* Step 3: Write the GIF89a Header and Logical Screen Descriptor. */
- outputStream.write(GIF89a);
- int bitField = globalTable*128 + (depth-1)*16 + depth-1;
- outputStream.writeShort((short)logicalScreenWidth);
- outputStream.writeShort((short)logicalScreenHeight);
- outputStream.write(bitField);
- outputStream.write(backgroundPixel);
- outputStream.write(0); // Aspect ratio is 1:1
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
-
- /* Step 4: Write Global Color Table if applicable. */
- if (globalTable == 1) {
- writePalette(palette, depth);
- }
-
- /* Step 5: Write Application Extension if applicable. */
- if (multi) {
- int repeatCount = loader.repeatCount;
- try {
- outputStream.write(GIF_EXTENSION_BLOCK_ID);
- outputStream.write(GIF_APPLICATION_EXTENSION_BLOCK_ID);
- outputStream.write(NETSCAPE2_0.length);
- outputStream.write(NETSCAPE2_0);
- outputStream.write(3); // Three bytes follow
- outputStream.write(1); // Extension type
- outputStream.writeShort((short) repeatCount);
- outputStream.write(0); // Block terminator
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
-
- for (int frame=0; frame<frameCount; frame++) {
-
- /* Step 6: Write Graphics Control Block for each frame if applicable. */
- if (multi || data[frame].transparentPixel != -1) {
- writeGraphicsControlBlock(data[frame]);
- }
-
- /* Step 7: Write Image Header for each frame. */
- int x = data[frame].x;
- int y = data[frame].y;
- int width = data[frame].width;
- int height = data[frame].height;
- try {
- outputStream.write(GIF_IMAGE_BLOCK_ID);
- byte[] block = new byte[9];
- block[0] = (byte)(x & 0xFF);
- block[1] = (byte)((x >> 8) & 0xFF);
- block[2] = (byte)(y & 0xFF);
- block[3] = (byte)((y >> 8) & 0xFF);
- block[4] = (byte)(width & 0xFF);
- block[5] = (byte)((width >> 8) & 0xFF);
- block[6] = (byte)(height & 0xFF);
- block[7] = (byte)((height >> 8) & 0xFF);
- block[8] = (byte)(globalTable == 0 ? (depth-1) | 0x80 : 0x00);
- outputStream.write(block);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
-
- /* Step 8: Write Local Color Table for each frame if applicable. */
- if (globalTable == 0) {
- writePalette(data[frame].palette, depth);
- }
-
- /* Step 9: Write the actual data for each frame. */
- try {
- outputStream.write(depth); // Minimum LZW Code size
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- new LZWCodec().encode(outputStream, data[frame]);
- }
-
- /* Step 10: Write GIF terminator. */
- try {
- outputStream.write(0x3B);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
-
- /**
- * Write out a GraphicsControlBlock to describe
- * the specified device independent image.
- */
- void writeGraphicsControlBlock(ImageData image) {
- try {
- outputStream.write(GIF_EXTENSION_BLOCK_ID);
- outputStream.write(GIF_GRAPHICS_CONTROL_BLOCK_ID);
- byte[] gcBlock = new byte[4];
- gcBlock[0] = 0;
- gcBlock[1] = 0;
- gcBlock[2] = 0;
- gcBlock[3] = 0;
- if (image.transparentPixel != -1) {
- gcBlock[0] = (byte)0x01;
- gcBlock[3] = (byte)image.transparentPixel;
- }
- if (image.disposalMethod != 0) {
- gcBlock[0] |= (byte)((image.disposalMethod & 0x07) << 2);
- }
- if (image.delayTime != 0) {
- gcBlock[1] = (byte)(image.delayTime & 0xFF);
- gcBlock[2] = (byte)((image.delayTime >> 8) & 0xFF);
- }
- outputStream.write((byte)gcBlock.length);
- outputStream.write(gcBlock);
- outputStream.write(0); // Block terminator
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
-
- /**
- * Write the specified palette to the output stream.
- */
- void writePalette(PaletteData palette, int depth) {
- byte[] bytes = new byte[(1 << depth) * 3];
- int offset = 0;
- for (int i = 0; i < palette.colors.length; i++) {
- RGB color = palette.colors[i];
- bytes[offset] = (byte)color.red;
- bytes[offset + 1] = (byte)color.green;
- bytes[offset + 2] = (byte)color.blue;
- offset += 3;
- }
- try {
- outputStream.write(bytes);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGAppn.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGAppn.java
deleted file mode 100755
index 37160a220b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGAppn.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-final class JPEGAppn extends JPEGVariableSizeSegment {
-
- public JPEGAppn(byte[] reference) {
- super(reference);
- }
-
- public JPEGAppn(LEDataInputStream byteStream) {
- super(byteStream);
- }
-
- public boolean verify() {
- int marker = getSegmentMarker();
- return marker >= JPEGFileFormat.APP0 && marker <= JPEGFileFormat.APP15;
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGArithmeticConditioningTable.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGArithmeticConditioningTable.java
deleted file mode 100755
index b8c8392e1e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGArithmeticConditioningTable.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-final class JPEGArithmeticConditioningTable extends JPEGVariableSizeSegment {
-
- public JPEGArithmeticConditioningTable(LEDataInputStream byteStream) {
- super(byteStream);
- }
-
- public int signature() {
- return JPEGFileFormat.DAC;
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGComment.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGComment.java
deleted file mode 100755
index 21070f16ea..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGComment.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-final class JPEGComment extends JPEGVariableSizeSegment {
-
- public JPEGComment(byte[] reference) {
- super(reference);
- }
-
- public JPEGComment(LEDataInputStream byteStream) {
- super(byteStream);
- }
-
- public int signature() {
- return JPEGFileFormat.COM;
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGDecoder.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGDecoder.java
deleted file mode 100644
index 54d6daa793..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGDecoder.java
+++ /dev/null
@@ -1,6355 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-import java.io.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-public class JPEGDecoder {
-
- static final int DCTSIZE = 8;
- static final int DCTSIZE2 = 64;
- static final int NUM_QUANT_TBLS = 4;
- static final int NUM_HUFF_TBLS = 4;
- static final int NUM_ARITH_TBLS = 16;
- static final int MAX_COMPS_IN_SCAN = 4;
- static final int MAX_COMPONENTS = 10;
- static final int MAX_SAMP_FACTOR = 4;
- static final int D_MAX_BLOCKS_IN_MCU = 10;
- static final int HUFF_LOOKAHEAD = 8;
- static final int MAX_Q_COMPS = 4;
- static final int IFAST_SCALE_BITS = 2;
- static final int MAXJSAMPLE = 255;
- static final int CENTERJSAMPLE = 128;
- static final int MIN_GET_BITS = 32-7;
- static final int INPUT_BUFFER_SIZE = 4096;
-
- static final int SCALEBITS = 16; /* speediest right-shift on some machines */
- static final int ONE_HALF = 1 << (SCALEBITS-1);
-
- static final int RGB_RED = 2; /* Offset of Red in an RGB scanline element */
- static final int RGB_GREEN = 1; /* Offset of Green */
- static final int RGB_BLUE = 0; /* Offset of Blue */
- static final int RGB_PIXELSIZE = 3;
-
- static final int JBUF_PASS_THRU = 0;
- static final int JBUF_SAVE_SOURCE = 1; /* Run source subobject only, save output */
- static final int JBUF_CRANK_DEST = 2; /* Run dest subobject only, using saved data */
- static final int JBUF_SAVE_AND_PASS = 3;
-
- static final int JPEG_MAX_DIMENSION = 65500;
- static final int BITS_IN_JSAMPLE = 8;
-
- static final int JDITHER_NONE = 0; /* no dithering */
- static final int JDITHER_ORDERED = 1; /* simple ordered dither */
- static final int JDITHER_FS = 2;
-
- static final int JDCT_ISLOW = 0; /* slow but accurate integer algorithm */
- static final int JDCT_IFAST = 1; /* faster, less accurate integer method */
- static final int JDCT_FLOAT = 2; /* floating-point: accurate, fast on fast HW */
- static final int JDCT_DEFAULT = JDCT_ISLOW;
-
- static final int JCS_UNKNOWN = 0; /* error/unspecified */
- static final int JCS_GRAYSCALE = 1; /* monochrome */
- static final int JCS_RGB = 2; /* red/green/blue */
- static final int JCS_YCbCr = 3; /* Y/Cb/Cr (also known as YUV) */
- static final int JCS_CMYK = 4; /* C/M/Y/K */
- static final int JCS_YCCK = 5; /* Y/Cb/Cr/K */
-
- static final int SAVED_COEFS = 6;
- static final int Q01_POS = 1;
- static final int Q10_POS = 8;
- static final int Q20_POS = 16;
- static final int Q11_POS = 9;
- static final int Q02_POS = 2;
-
- static final int CTX_PREPARE_FOR_IMCU = 0; /* need to prepare for MCU row */
- static final int CTX_PROCESS_IMCU = 1; /* feeding iMCU to postprocessor */
- static final int CTX_POSTPONED_ROW = 2; /* feeding postponed row group */
-
- static final int APP0_DATA_LEN = 14; /* Length of interesting data in APP0 */
- static final int APP14_DATA_LEN = 12; /* Length of interesting data in APP14 */
- static final int APPN_DATA_LEN = 14; /* Must be the largest of the above!! */
-
- /* markers */
- static final int M_SOF0 = 0xc0;
- static final int M_SOF1 = 0xc1;
- static final int M_SOF2 = 0xc2;
- static final int M_SOF3 = 0xc3;
- static final int M_SOF5 = 0xc5;
- static final int M_SOF6 = 0xc6;
- static final int M_SOF7 = 0xc7;
- static final int M_JPG = 0xc8;
- static final int M_SOF9 = 0xc9;
- static final int M_SOF10 = 0xca;
- static final int M_SOF11 = 0xcb;
- static final int M_SOF13 = 0xcd;
- static final int M_SOF14 = 0xce;
- static final int M_SOF15 = 0xcf;
- static final int M_DHT = 0xc4;
- static final int M_DAC = 0xcc;
- static final int M_RST0 = 0xd0;
- static final int M_RST1 = 0xd1;
- static final int M_RST2 = 0xd2;
- static final int M_RST3 = 0xd3;
- static final int M_RST4 = 0xd4;
- static final int M_RST5 = 0xd5;
- static final int M_RST6 = 0xd6;
- static final int M_RST7 = 0xd7;
- static final int M_SOI = 0xd8;
- static final int M_EOI = 0xd9;
- static final int M_SOS = 0xda;
- static final int M_DQT = 0xdb;
- static final int M_DNL = 0xdc;
- static final int M_DRI = 0xdd;
- static final int M_DHP = 0xde;
- static final int M_EXP = 0xdf;
- static final int M_APP0 = 0xe0;
- static final int M_APP1 = 0xe1;
- static final int M_APP2 = 0xe2;
- static final int M_APP3 = 0xe3;
- static final int M_APP4 = 0xe4;
- static final int M_APP5 = 0xe5;
- static final int M_APP6 = 0xe6;
- static final int M_APP7 = 0xe7;
- static final int M_APP8 = 0xe8;
- static final int M_APP9 = 0xe9;
- static final int M_APP10 = 0xea;
- static final int M_APP11 = 0xeb;
- static final int M_APP12 = 0xec;
- static final int M_APP13 = 0xed;
- static final int M_APP14 = 0xee;
- static final int M_APP15 = 0xef;
- static final int M_JPG0 = 0xf0;
- static final int M_JPG13 = 0xfd;
- static final int M_COM = 0xfe;
- static final int M_TEM = 0x01;
- static final int M_ERROR = 0x100;
-
- /* Values of global_state field (jdapi.c has some dependencies on ordering!) */
- static final int CSTATE_START = 100; /* after create_compress */
- static final int CSTATE_SCANNING = 101; /* start_compress done, write_scanlines OK */
- static final int CSTATE_RAW_OK = 102; /* start_compress done, write_raw_data OK */
- static final int CSTATE_WRCOEFS = 103; /* jpeg_write_coefficients done */
- static final int DSTATE_START = 200; /* after create_decompress */
- static final int DSTATE_INHEADER = 201; /* reading header markers, no SOS yet */
- static final int DSTATE_READY = 202; /* found SOS, ready for start_decompress */
- static final int DSTATE_PRELOAD = 203; /* reading multiscan file in start_decompress*/
- static final int DSTATE_PRESCAN = 204; /* performing dummy pass for 2-pass quant */
- static final int DSTATE_SCANNING = 205; /* start_decompress done, read_scanlines OK */
- static final int DSTATE_RAW_OK = 206; /* start_decompress done, read_raw_data OK */
- static final int DSTATE_BUFIMAGE = 207; /* expecting jpeg_start_output */
- static final int DSTATE_BUFPOST = 208; /* looking for SOS/EOI in jpeg_finish_output */
- static final int DSTATE_RDCOEFS = 209; /* reading file in jpeg_read_coefficients */
- static final int DSTATE_STOPPING = 210; /* looking for EOI in jpeg_finish_decompress */
-
- static final int JPEG_REACHED_SOS = 1; /* Reached start of new scan */
- static final int JPEG_REACHED_EOI = 2; /* Reached end of image */
- static final int JPEG_ROW_COMPLETED = 3; /* Completed one iMCU row */
- static final int JPEG_SCAN_COMPLETED = 4; /* Completed last iMCU row of a scan */
-
- static final int JPEG_SUSPENDED = 0; /* Suspended due to lack of input data */
- static final int JPEG_HEADER_OK = 1; /* Found valid image datastream */
- static final int JPEG_HEADER_TABLES_ONLY = 2; /* Found valid table-specs-only datastream */
-
- /* Function pointers */
- static final int DECOMPRESS_DATA = 0;
- static final int DECOMPRESS_SMOOTH_DATA = 1;
- static final int DECOMPRESS_ONEPASS = 2;
-
- static final int CONSUME_DATA = 0;
- static final int DUMMY_CONSUME_DATA = 1;
-
- static final int PROCESS_DATA_SIMPLE_MAIN = 0;
- static final int PROCESS_DATA_CONTEXT_MAIN = 1;
- static final int PROCESS_DATA_CRANK_POST = 2;
-
- static final int POST_PROCESS_1PASS = 0;
- static final int POST_PROCESS_DATA_UPSAMPLE = 1;
-
- static final int NULL_CONVERT = 0;
- static final int GRAYSCALE_CONVERT = 1;
- static final int YCC_RGB_CONVERT = 2;
- static final int GRAY_RGB_CONVERT = 3;
- static final int YCCK_CMYK_CONVERT = 4;
-
- static final int NOOP_UPSAMPLE = 0;
- static final int FULLSIZE_UPSAMPLE = 1;
- static final int H2V1_FANCY_UPSAMPLE = 2;
- static final int H2V1_UPSAMPLE = 3;
- static final int H2V2_FANCY_UPSAMPLE = 4;
- static final int H2V2_UPSAMPLE = 5;
- static final int INT_UPSAMPLE = 6;
-
- static final int INPUT_CONSUME_INPUT = 0;
- static final int COEF_CONSUME_INPUT = 1;
-
- static int extend_test[] = /* entry n is 2**(n-1) */
- {
- 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
- 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000
- };
-
- static int extend_offset[] = /* entry n is (-1 << n) + 1 */
- {
- 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
- ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
- ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
- ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1
- };
-
- static int jpeg_natural_order[] = {
- 0, 1, 8, 16, 9, 2, 3, 10,
- 17, 24, 32, 25, 18, 11, 4, 5,
- 12, 19, 26, 33, 40, 48, 41, 34,
- 27, 20, 13, 6, 7, 14, 21, 28,
- 35, 42, 49, 56, 57, 50, 43, 36,
- 29, 22, 15, 23, 30, 37, 44, 51,
- 58, 59, 52, 45, 38, 31, 39, 46,
- 53, 60, 61, 54, 47, 55, 62, 63,
- 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
- 63, 63, 63, 63, 63, 63, 63, 63
- };
-
- static final class JQUANT_TBL {
- /* This array gives the coefficient quantizers in natural array order
- * (not the zigzag order in which they are stored in a JPEG DQT marker).
- * CAUTION: IJG versions prior to v6a kept this array in zigzag order.
- */
- short[] quantval = new short[DCTSIZE2]; /* quantization step for each coefficient */
- /* This field is used only during compression. It's initialized false when
- * the table is created, and set true when it's been output to the file.
- * You could suppress output of a table by setting this to true.
- * (See jpeg_suppress_tables for an example.)
- */
- boolean sent_table; /* true when table has been output */
- }
-
- static final class JHUFF_TBL {
- /* These two fields directly represent the contents of a JPEG DHT marker */
- byte[] bits = new byte[17]; /* bits[k] = # of symbols with codes of */
- /* length k bits; bits[0] is unused */
- byte[] huffval = new byte[256]; /* The symbols, in order of incr code length */
- /* This field is used only during compression. It's initialized false when
- * the table is created, and set true when it's been output to the file.
- * You could suppress output of a table by setting this to true.
- * (See jpeg_suppress_tables for an example.)
- */
- boolean sent_table; /* true when table has been output */
- }
-
- static final class bitread_perm_state { /* Bitreading state saved across MCUs */
- int get_buffer; /* current bit-extraction buffer */
- int bits_left; /* # of unused bits in it */
- }
-
- static final class bitread_working_state { /* Bitreading working state within an MCU */
- /* Current data source location */
- /* We need a copy, rather than munging the original, in case of suspension */
- byte[] buffer; /* => next byte to read from source */
- int bytes_offset;
- int bytes_in_buffer; /* # of bytes remaining in source buffer */
- /* Bit input buffer --- note these values are kept in register variables,
- * not in this struct, inside the inner loops.
- */
- int get_buffer; /* current bit-extraction buffer */
- int bits_left; /* # of unused bits in it */
- /* Pointer needed by jpeg_fill_bit_buffer. */
- jpeg_decompress_struct cinfo; /* back link to decompress master record */
- }
-
- static final class savable_state {
- int EOBRUN; //Note that this is only used in the progressive case
- int[] last_dc_val = new int[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
- }
-
- static final class d_derived_tbl {
- /* Basic tables: (element [0] of each array is unused) */
- int[] maxcode = new int[18]; /* largest code of length k (-1 if none) */
- /* (maxcode[17] is a sentinel to ensure jpeg_huff_decode terminates) */
- int[] valoffset = new int[17]; /* huffval[] offset for codes of length k */
- /* valoffset[k] = huffval[] index of 1st symbol of code length k, less
- * the smallest code of length k; so given a code of length k, the
- * corresponding symbol is huffval[code + valoffset[k]]
- */
-
- /* Link to public Huffman table (needed only in jpeg_huff_decode) */
- JHUFF_TBL pub;
-
- /* Lookahead tables: indexed by the next HUFF_LOOKAHEAD bits of
- * the input data stream. If the next Huffman code is no more
- * than HUFF_LOOKAHEAD bits long, we can obtain its length and
- * the corresponding symbol directly from these tables.
- */
- int[] look_nbits = new int[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
- byte[] look_sym = new byte[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
- }
-
- static final class jpeg_d_coef_controller {
- int consume_data;
- int decompress_data;
-
- /* Pointer to array of coefficient virtual arrays, or null if none */
- short[][][] coef_arrays;
-
- /* These variables keep track of the current location of the input side. */
- /* cinfo.input_iMCU_row is also used for this. */
- int MCU_ctr; /* counts MCUs processed in current row */
- int MCU_vert_offset; /* counts MCU rows within iMCU row */
- int MCU_rows_per_iMCU_row; /* number of such rows needed */
-
- /* The output side's location is represented by cinfo.output_iMCU_row. */
-
- /* In single-pass modes, it's sufficient to buffer just one MCU.
- * We allocate a workspace of D_MAX_BLOCKS_IN_MCU coefficient blocks,
- * and let the entropy decoder write into that workspace each time.
- * (On 80x86, the workspace is FAR even though it's not really very big;
- * this is to keep the module interfaces unchanged when a large coefficient
- * buffer is necessary.)
- * In multi-pass modes, this array points to the current MCU's blocks
- * within the virtual arrays; it is used only by the input side.
- */
- short[][] MCU_buffer = new short[D_MAX_BLOCKS_IN_MCU][];
-
- /* In multi-pass modes, we need a virtual block array for each component. */
- short[][][][] whole_image = new short[MAX_COMPONENTS][][][];
-
- /* When doing block smoothing, we latch coefficient Al values here */
- int[] coef_bits_latch;
-
- short[] workspace;
-
- void start_input_pass (jpeg_decompress_struct cinfo) {
- cinfo.input_iMCU_row = 0;
- start_iMCU_row(cinfo);
- }
-
- /* Reset within-iMCU-row counters for a new row (input side) */
- void start_iMCU_row (jpeg_decompress_struct cinfo) {
- jpeg_d_coef_controller coef = cinfo.coef;
-
- /* In an interleaved scan, an MCU row is the same as an iMCU row.
- * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
- * But at the bottom of the image, process only what's left.
- */
- if (cinfo.comps_in_scan > 1) {
- coef.MCU_rows_per_iMCU_row = 1;
- } else {
- if (cinfo.input_iMCU_row < (cinfo.total_iMCU_rows-1))
- coef.MCU_rows_per_iMCU_row = cinfo.cur_comp_info[0].v_samp_factor;
- else
- coef.MCU_rows_per_iMCU_row = cinfo.cur_comp_info[0].last_row_height;
- }
-
- coef.MCU_ctr = 0;
- coef.MCU_vert_offset = 0;
- }
-
- }
-
- static abstract class jpeg_entropy_decoder {
- abstract void start_pass (jpeg_decompress_struct cinfo);
- abstract boolean decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data);
-
- /* This is here to share code between baseline and progressive decoders; */
- /* other modules probably should not use it */
- boolean insufficient_data; /* set true after emitting warning */
-
- bitread_working_state br_state_local = new bitread_working_state();
- savable_state state_local = new savable_state();
- }
-
- static final class huff_entropy_decoder extends jpeg_entropy_decoder {
- bitread_perm_state bitstate = new bitread_perm_state(); /* Bit buffer at start of MCU */
- savable_state saved = new savable_state(); /* Other state at start of MCU */
-
- /* These fields are NOT loaded into local working state. */
- int restarts_to_go; /* MCUs left in this restart interval */
-
- /* Pointers to derived tables (these workspaces have image lifespan) */
- d_derived_tbl[] dc_derived_tbls = new d_derived_tbl[NUM_HUFF_TBLS];
- d_derived_tbl[] ac_derived_tbls = new d_derived_tbl[NUM_HUFF_TBLS];
-
- /* Precalculated info set up by start_pass for use in decode_mcu: */
-
- /* Pointers to derived tables to be used for each block within an MCU */
- d_derived_tbl[] dc_cur_tbls = new d_derived_tbl[D_MAX_BLOCKS_IN_MCU];
- d_derived_tbl[] ac_cur_tbls = new d_derived_tbl[D_MAX_BLOCKS_IN_MCU];
- /* Whether we care about the DC and AC coefficient values for each block */
- boolean[] dc_needed = new boolean[D_MAX_BLOCKS_IN_MCU];
- boolean[] ac_needed = new boolean[D_MAX_BLOCKS_IN_MCU];
-
- void start_pass (jpeg_decompress_struct cinfo) {
- start_pass_huff_decoder(cinfo);
- }
-
- boolean decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data) {
- huff_entropy_decoder entropy = this;
- int blkn;
-// BITREAD_STATE_VARS;
- int get_buffer;
- int bits_left;
-// bitread_working_state br_state = new bitread_working_state();
-// savable_state state = new savable_state();
- bitread_working_state br_state = br_state_local;
- savable_state state = state_local;
-
- /* Process restart marker if needed; may have to suspend */
- if (cinfo.restart_interval != 0) {
- if (entropy.restarts_to_go == 0)
- if (! process_restart(cinfo))
- return false;
- }
-
- /* If we've run out of data, just leave the MCU set to zeroes.
- * This way, we return uniform gray for the remainder of the segment.
- */
- if (! entropy.insufficient_data) {
-
- /* Load up working state */
-// BITREAD_LOAD_STATE(cinfo,entropy.bitstate);
- br_state.cinfo = cinfo;
- br_state.buffer = cinfo.buffer;
- br_state.bytes_in_buffer = cinfo.bytes_in_buffer;
- br_state.bytes_offset = cinfo.bytes_offset;
- get_buffer = entropy.bitstate.get_buffer;
- bits_left = entropy.bitstate.bits_left;
-
-// ASSIGN_STATE(state, entropy.saved);
- state.last_dc_val[0] = entropy.saved.last_dc_val[0];
- state.last_dc_val[1] = entropy.saved.last_dc_val[1];
- state.last_dc_val[2] = entropy.saved.last_dc_val[2];
- state.last_dc_val[3] = entropy.saved.last_dc_val[3];
-
- /* Outer loop handles each block in the MCU */
-
- for (blkn = 0; blkn < cinfo.blocks_in_MCU; blkn++) {
- short[] block = MCU_data[blkn];
- d_derived_tbl dctbl = entropy.dc_cur_tbls[blkn];
- d_derived_tbl actbl = entropy.ac_cur_tbls[blkn];
- int s = 0, k, r;
-
- /* Decode a single block's worth of coefficients */
-
- /* Section F.2.2.1: decode the DC coefficient difference */
-// HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
- {
- int nb = 0, look;
- if (bits_left < HUFF_LOOKAHEAD) {
- if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) {
- return false;
- }
- get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
- if (bits_left < HUFF_LOOKAHEAD) {
- nb = 1;
-// goto slowlabel;
- if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,dctbl,nb)) < 0) {
- return false;
- }
- get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
- }
- }
-// look = PEEK_BITS(HUFF_LOOKAHEAD);
- if (nb != 1) {
- look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1));
- if ((nb = dctbl.look_nbits[look]) != 0) {
-// DROP_BITS(nb);
- bits_left -= nb;
- s = dctbl.look_sym[look] & 0xFF;
- } else {
- nb = HUFF_LOOKAHEAD+1;
-// slowlabel:
- if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,dctbl,nb)) < 0) {
- return false;
- }
- get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
- }
- }
- }
-
- if (s != 0) {
-// CHECK_BIT_BUFFER(br_state, s, return FALSE);
- {
- if (bits_left < (s)) {
- if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) {
- return false;
- }
- get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
- }
- }
-// r = GET_BITS(s);
- r = (( (get_buffer >> (bits_left -= (s)))) & ((1<<(s))-1));
-// s = HUFF_EXTEND(r, s);
- s = ((r) < extend_test[s] ? (r) + extend_offset[s] : (r));
- }
-
- if (entropy.dc_needed[blkn]) {
- /* Convert DC difference to actual value, update last_dc_val */
- int ci = cinfo.MCU_membership[blkn];
- s += state.last_dc_val[ci];
- state.last_dc_val[ci] = s;
- /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */
- block[0] = (short) s;
- }
-
- if (entropy.ac_needed[blkn]) {
-
- /* Section F.2.2.2: decode the AC coefficients */
- /* Since zeroes are skipped, output area must be cleared beforehand */
- for (k = 1; k < DCTSIZE2; k++) {
-// HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
- {
- int nb = 0, look;
- if (bits_left < HUFF_LOOKAHEAD) {
- if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) {
- return false;
- }
- get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
- if (bits_left < HUFF_LOOKAHEAD) {
- nb = 1;
-// goto slowlabel;
- if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,actbl,nb)) < 0) {
- return false;
- }
- get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
- }
- }
- if (nb != 1) {
-// look = PEEK_BITS(HUFF_LOOKAHEAD);
- look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1));
- if ((nb = actbl.look_nbits[look]) != 0) {
-// DROP_BITS(nb);
- bits_left -= (nb);
- s = actbl.look_sym[look] & 0xFF;
- } else {
- nb = HUFF_LOOKAHEAD+1;
-// slowlabel:
- if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,actbl,nb)) < 0) {
- return false;
- }
- get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
- }
- }
- }
- r = s >> 4;
- s &= 15;
-
- if (s != 0) {
- k += r;
-// CHECK_BIT_BUFFER(br_state, s, return FALSE);
- {
- if (bits_left < (s)) {
- if (!jpeg_fill_bit_buffer(br_state, get_buffer, bits_left, s)) {
- return false;
- }
- get_buffer = (br_state).get_buffer;
- bits_left = (br_state).bits_left;
- }
- }
-// r = GET_BITS(s);
- r = (((get_buffer >> (bits_left -= (s)))) & ((1 << (s)) - 1));
-// s = HUFF_EXTEND(r, s);
- s = ((r) < extend_test[s] ? (r) + extend_offset[s] : (r));
- /*
- * Output coefficient in natural (dezigzagged)
- * order. Note: the extra entries in
- * jpeg_natural_order[] will save us if k >=
- * DCTSIZE2, which could happen if the data is
- * corrupted.
- */
- block[jpeg_natural_order[k]] = (short) s;
- } else {
- if (r != 15)
- break;
- k += 15;
- }
- }
-
- } else {
-
- /* Section F.2.2.2: decode the AC coefficients */
- /* In this path we just discard the values */
- for (k = 1; k < DCTSIZE2; k++) {
-// HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
- {
- int nb = 0, look;
- if (bits_left < HUFF_LOOKAHEAD) {
- if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) {
- return false;
- }
- get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
- if (bits_left < HUFF_LOOKAHEAD) {
- nb = 1;
-// goto slowlabel;
- if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,actbl,nb)) < 0) {
- return false;
- }
- get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
- }
- }
- if (nb != 1) {
-// look = PEEK_BITS(HUFF_LOOKAHEAD);
- look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1));
- if ((nb = actbl.look_nbits[look]) != 0) {
-// DROP_BITS(nb);
- bits_left -= (nb);
- s = actbl.look_sym[look] & 0xFF;
- } else {
- nb = HUFF_LOOKAHEAD+1;
-// slowlabel:
- if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,actbl,nb)) < 0) {
- return false;
- }
- get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
- }
- }
- }
- r = s >> 4;
- s &= 15;
-
- if (s != 0) {
- k += r;
-// CHECK_BIT_BUFFER(br_state, s, return FALSE);
- {
- if (bits_left < (s)) {
- if (!jpeg_fill_bit_buffer((br_state),get_buffer,bits_left,s)) {
- return false;
- }
- get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
- }
- }
-// DROP_BITS(s);
- bits_left -= s;
- } else {
- if (r != 15)
- break;
- k += 15;
- }
- }
-
- }
- }
-
- /* Completed MCU, so update state */
-// BITREAD_SAVE_STATE(cinfo,entropy.bitstate);
- cinfo.buffer = br_state.buffer;
- cinfo.bytes_in_buffer = br_state.bytes_in_buffer;
- cinfo.bytes_offset = br_state.bytes_offset;
- entropy.bitstate.get_buffer = get_buffer;
- entropy.bitstate.bits_left = bits_left;
-// ASSIGN_STATE(entropy.saved, state);
- entropy.saved.last_dc_val[0] = state.last_dc_val[0];
- entropy.saved.last_dc_val[1] = state.last_dc_val[1];
- entropy.saved.last_dc_val[2] = state.last_dc_val[2];
- entropy.saved.last_dc_val[3] = state.last_dc_val[3];
- }
-
- /* Account for restart interval (no-op if not using restarts) */
- entropy.restarts_to_go--;
-
- return true;
- }
-
- void start_pass_huff_decoder (jpeg_decompress_struct cinfo) {
- huff_entropy_decoder entropy = this;
- int ci, blkn, dctbl, actbl;
- jpeg_component_info compptr;
-
- /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG.
- * This ought to be an error condition, but we make it a warning because
- * there are some baseline files out there with all zeroes in these bytes.
- */
- if (cinfo.Ss != 0 || cinfo.Se != DCTSIZE2-1 || cinfo.Ah != 0 || cinfo.Al != 0) {
-// WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
- }
-
- for (ci = 0; ci < cinfo.comps_in_scan; ci++) {
- compptr = cinfo.cur_comp_info[ci];
- dctbl = compptr.dc_tbl_no;
- actbl = compptr.ac_tbl_no;
- /* Compute derived values for Huffman tables */
- /* We may do this more than once for a table, but it's not expensive */
- jpeg_make_d_derived_tbl(cinfo, true, dctbl, entropy.dc_derived_tbls[dctbl] = new d_derived_tbl());
- jpeg_make_d_derived_tbl(cinfo, false, actbl, entropy.ac_derived_tbls[actbl] = new d_derived_tbl());
- /* Initialize DC predictions to 0 */
- entropy.saved.last_dc_val[ci] = 0;
- }
-
- /* Precalculate decoding info for each block in an MCU of this scan */
- for (blkn = 0; blkn < cinfo.blocks_in_MCU; blkn++) {
- ci = cinfo.MCU_membership[blkn];
- compptr = cinfo.cur_comp_info[ci];
- /* Precalculate which table to use for each block */
- entropy.dc_cur_tbls[blkn] = entropy.dc_derived_tbls[compptr.dc_tbl_no];
- entropy.ac_cur_tbls[blkn] = entropy.ac_derived_tbls[compptr.ac_tbl_no];
- /* Decide whether we really care about the coefficient values */
- if (compptr.component_needed) {
- entropy.dc_needed[blkn] = true;
- /* we don't need the ACs if producing a 1/8th-size image */
- entropy.ac_needed[blkn] = (compptr.DCT_scaled_size > 1);
- } else {
- entropy.dc_needed[blkn] = entropy.ac_needed[blkn] = false;
- }
- }
-
- /* Initialize bitread state variables */
- entropy.bitstate.bits_left = 0;
- entropy.bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
- entropy.insufficient_data = false;
-
- /* Initialize restart counter */
- entropy.restarts_to_go = cinfo.restart_interval;
- }
-
- boolean process_restart (jpeg_decompress_struct cinfo) {
- huff_entropy_decoder entropy = this;
- int ci;
-
- /* Throw away any unused bits remaining in bit buffer; */
- /* include any full bytes in next_marker's count of discarded bytes */
- cinfo.marker.discarded_bytes += entropy.bitstate.bits_left / 8;
- entropy.bitstate.bits_left = 0;
-
- /* Advance past the RSTn marker */
- if (! read_restart_marker (cinfo))
- return false;
-
- /* Re-initialize DC predictions to 0 */
- for (ci = 0; ci < cinfo.comps_in_scan; ci++)
- entropy.saved.last_dc_val[ci] = 0;
-
- /* Reset restart counter */
- entropy.restarts_to_go = cinfo.restart_interval;
-
- /* Reset out-of-data flag, unless read_restart_marker left us smack up
- * against a marker. In that case we will end up treating the next data
- * segment as empty, and we can avoid producing bogus output pixels by
- * leaving the flag set.
- */
- if (cinfo.unread_marker == 0)
- entropy.insufficient_data = false;
-
- return true;
- }
- }
-
- static final class phuff_entropy_decoder extends jpeg_entropy_decoder {
-
- /* These fields are loaded into local variables at start of each MCU.
- * In case of suspension, we exit WITHOUT updating them.
- */
- bitread_perm_state bitstate = new bitread_perm_state(); /* Bit buffer at start of MCU */
- savable_state saved = new savable_state(); /* Other state at start of MCU */
-
- /* These fields are NOT loaded into local working state. */
- int restarts_to_go; /* MCUs left in this restart interval */
-
- /* Pointers to derived tables (these workspaces have image lifespan) */
- d_derived_tbl[] derived_tbls = new d_derived_tbl[NUM_HUFF_TBLS];
-
- d_derived_tbl ac_derived_tbl; /* active table during an AC scan */
-
- int[] newnz_pos = new int[DCTSIZE2];
-
- void start_pass (jpeg_decompress_struct cinfo) {
- start_pass_phuff_decoder(cinfo);
- }
-
- boolean decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data) {
- boolean is_DC_band = (cinfo.Ss == 0);
- if (cinfo.Ah == 0) {
- if (is_DC_band)
- return decode_mcu_DC_first(cinfo, MCU_data);
- else
- return decode_mcu_AC_first(cinfo, MCU_data);
- } else {
- if (is_DC_band)
- return decode_mcu_DC_refine(cinfo, MCU_data);
- else
- return decode_mcu_AC_refine(cinfo, MCU_data);
- }
- }
-
- boolean decode_mcu_DC_refine (jpeg_decompress_struct cinfo, short[][] MCU_data) {
- phuff_entropy_decoder entropy = this;
- int p1 = 1 << cinfo.Al; /* 1 in the bit position being coded */
- int blkn;
- short[] block;
-// BITREAD_STATE_VARS;
- int get_buffer;
- int bits_left;
-// bitread_working_state br_state = new bitread_working_state();
- bitread_working_state br_state = br_state_local;
-
- /* Process restart marker if needed; may have to suspend */
- if (cinfo.restart_interval != 0) {
- if (entropy.restarts_to_go == 0)
- if (! process_restart(cinfo))
- return false;
- }
-
- /* Not worth the cycles to check insufficient_data here,
- * since we will not change the data anyway if we read zeroes.
- */
-
- /* Load up working state */
-// BITREAD_LOAD_STATE(cinfo,entropy.bitstate);
- br_state.cinfo = cinfo;
- br_state.buffer = cinfo.buffer;
- br_state.bytes_in_buffer = cinfo.bytes_in_buffer;
- br_state.bytes_offset = cinfo.bytes_offset;
- get_buffer = entropy.bitstate.get_buffer;
- bits_left = entropy.bitstate.bits_left;
-
- /* Outer loop handles each block in the MCU */
-
- for (blkn = 0; blkn < cinfo.blocks_in_MCU; blkn++) {
- block = MCU_data[blkn];
-
- /* Encoded data is simply the next bit of the two's-complement DC value */
-// CHECK_BIT_BUFFER(br_state, 1, return FALSE);
- {
- if (bits_left < (1)) {
- if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) {
- return false;
- }
- get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
- }
- }
-// if (GET_BITS(1))
- if ((( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)) != 0)
- block[0] |= p1;
- /* Note: since we use |=, repeating the assignment later is safe */
- }
-
- /* Completed MCU, so update state */
-// BITREAD_SAVE_STATE(cinfo,entropy.bitstate);
- cinfo.buffer = br_state.buffer;
- cinfo.bytes_in_buffer = br_state.bytes_in_buffer;
- cinfo.bytes_offset = br_state.bytes_offset;
- entropy.bitstate.get_buffer = get_buffer;
- entropy.bitstate.bits_left = bits_left;
-
- /* Account for restart interval (no-op if not using restarts) */
- entropy.restarts_to_go--;
-
- return true;
-
- }
-
- boolean decode_mcu_AC_refine (jpeg_decompress_struct cinfo, short[][] MCU_data) {
- phuff_entropy_decoder entropy = this;
- int Se = cinfo.Se;
- int p1 = 1 << cinfo.Al; /* 1 in the bit position being coded */
- int m1 = (-1) << cinfo.Al; /* -1 in the bit position being coded */
- int s = 0, k, r;
- int EOBRUN;
- short[] block;
- short[] thiscoef;
-// BITREAD_STATE_VARS;
- int get_buffer;
- int bits_left;
-// bitread_working_state br_state = new bitread_working_state();
- bitread_working_state br_state = br_state_local;
-
- d_derived_tbl tbl;
- int num_newnz;
- int[] newnz_pos = entropy.newnz_pos;
-
- /* Process restart marker if needed; may have to suspend */
- if (cinfo.restart_interval != 0) {
- if (entropy.restarts_to_go == 0)
- if (! process_restart(cinfo))
- return false;
- }
-
- /* If we've run out of data, don't modify the MCU.
- */
- if (! entropy.insufficient_data) {
-
- /* Load up working state */
-// BITREAD_LOAD_STATE(cinfo,entropy.bitstate);
- br_state.cinfo = cinfo;
- br_state.buffer = cinfo.buffer;
- br_state.bytes_in_buffer = cinfo.bytes_in_buffer;
- br_state.bytes_offset = cinfo.bytes_offset;
- get_buffer = entropy.bitstate.get_buffer;
- bits_left = entropy.bitstate.bits_left;
-
- EOBRUN = entropy.saved.EOBRUN; /* only part of saved state we need */
-
- /* There is always only one block per MCU */
- block = MCU_data[0];
- tbl = entropy.ac_derived_tbl;
-
- /* If we are forced to suspend, we must undo the assignments to any newly
- * nonzero coefficients in the block, because otherwise we'd get confused
- * next time about which coefficients were already nonzero.
- * But we need not undo addition of bits to already-nonzero coefficients;
- * instead, we can test the current bit to see if we already did it.
- */
- num_newnz = 0;
-
- /* initialize coefficient loop counter to start of band */
- k = cinfo.Ss;
-
- if (EOBRUN == 0) {
- for (; k <= Se; k++) {
-// HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
- {
- int nb = 0, look;
- if (bits_left < HUFF_LOOKAHEAD) {
- if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) {
-// failaction;
- while (num_newnz > 0)
- block[newnz_pos[--num_newnz]] = 0;
-
- return false;
- }
- get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
- if (bits_left < HUFF_LOOKAHEAD) {
- nb = 1;
-// goto slowlabel;
- if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) {
-// failaction;
- while (num_newnz > 0)
- block[newnz_pos[--num_newnz]] = 0;
-
- return false;
- }
- get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
- }
- }
- if (nb != 1) {
-// look = PEEK_BITS(HUFF_LOOKAHEAD);
- look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1));
- if ((nb = tbl.look_nbits[look]) != 0) {
-// DROP_BITS(nb);
- bits_left -= nb;
- s = tbl.look_sym[look] & 0xFF;
- } else {
- nb = HUFF_LOOKAHEAD+1;
-// slowlabel:
- if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) {
-// failaction;
- while (num_newnz > 0)
- block[newnz_pos[--num_newnz]] = 0;
-
- return false;
- }
- get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
- }
- }
- }
- r = s >> 4;
- s &= 15;
- if (s != 0) {
- if (s != 1) { /* size of new coef should always be 1 */
-// WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
- }
-// CHECK_BIT_BUFFER(br_state, 1, goto undoit);
- {
- if (bits_left < (1)) {
- if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) {
-// failaction;
- while (num_newnz > 0)
- block[newnz_pos[--num_newnz]] = 0;
-
- return false;
- }
- get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
- }
- }
-// if (GET_BITS(1))
- if ((( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)) != 0)
- s = p1; /* newly nonzero coef is positive */
- else
- s = m1; /* newly nonzero coef is negative */
- } else {
- if (r != 15) {
- EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
- if (r != 0) {
-// CHECK_BIT_BUFFER(br_state, r, goto undoit);
- {
- if (bits_left < (r)) {
- if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,r)) {
-// failaction;
- while (num_newnz > 0)
- block[newnz_pos[--num_newnz]] = 0;
-
- return false;
- }
- get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
- }
- }
-// r = GET_BITS(r);
- r = (( (get_buffer >> (bits_left -= (r)))) & ((1<<(r))-1));
- EOBRUN += r;
- }
- break; /* rest of block is handled by EOB logic */
- }
- /* note s = 0 for processing ZRL */
- }
- /* Advance over already-nonzero coefs and r still-zero coefs,
- * appending correction bits to the nonzeroes. A correction bit is 1
- * if the absolute value of the coefficient must be increased.
- */
- do {
- thiscoef = block;
- int thiscoef_offset = jpeg_natural_order[k];
- if (thiscoef[thiscoef_offset] != 0) {
-// CHECK_BIT_BUFFER(br_state, 1, goto undoit);
- {
- if (bits_left < (1)) {
- if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) {
-// failaction;
- while (num_newnz > 0)
- block[newnz_pos[--num_newnz]] = 0;
-
- return false;
- }
- get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
- }
- }
-// if (GET_BITS(1)) {
- if ((( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)) != 0) {
- if ((thiscoef[thiscoef_offset] & p1) == 0) { /* do nothing if already set it */
- if (thiscoef[thiscoef_offset] >= 0)
- thiscoef[thiscoef_offset] += p1;
- else
- thiscoef[thiscoef_offset] += m1;
- }
- }
- } else {
- if (--r < 0)
- break; /* reached target zero coefficient */
- }
- k++;
- } while (k <= Se);
- if (s != 0) {
- int pos = jpeg_natural_order[k];
- /* Output newly nonzero coefficient */
- block[pos] = (short) s;
- /* Remember its position in case we have to suspend */
- newnz_pos[num_newnz++] = pos;
- }
- }
- }
-
- if (EOBRUN > 0) {
- /* Scan any remaining coefficient positions after the end-of-band
- * (the last newly nonzero coefficient, if any). Append a correction
- * bit to each already-nonzero coefficient. A correction bit is 1
- * if the absolute value of the coefficient must be increased.
- */
- for (; k <= Se; k++) {
- thiscoef = block;
- int thiscoef_offset = jpeg_natural_order[k];
- if (thiscoef[thiscoef_offset] != 0) {
-// CHECK_BIT_BUFFER(br_state, 1, goto undoit);
- {
- if (bits_left < (1)) {
- if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) {
-// failaction;
- while (num_newnz > 0)
- block[newnz_pos[--num_newnz]] = 0;
-
- return false;
- }
- get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
- }
- }
-// if (GET_BITS(1)) {
- if ((( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)) != 0) {
- if ((thiscoef[thiscoef_offset] & p1) == 0) { /* do nothing if already changed it */
- if (thiscoef[thiscoef_offset] >= 0)
- thiscoef[thiscoef_offset] += p1;
- else
- thiscoef[thiscoef_offset] += m1;
- }
- }
- }
- }
- /* Count one block completed in EOB run */
- EOBRUN--;
- }
-
- /* Completed MCU, so update state */
-// BITREAD_SAVE_STATE(cinfo,entropy.bitstate);
- cinfo.buffer = br_state.buffer;
- cinfo.bytes_in_buffer = br_state.bytes_in_buffer;
- cinfo.bytes_offset = br_state.bytes_offset;
- entropy.bitstate.get_buffer = get_buffer;
- entropy.bitstate.bits_left = bits_left;
-
- entropy.saved.EOBRUN = EOBRUN; /* only part of saved state we need */
- }
-
- /* Account for restart interval (no-op if not using restarts) */
- entropy.restarts_to_go--;
-
- return true;
-
-// undoit:
-// /* Re-zero any output coefficients that we made newly nonzero */
-// while (num_newnz > 0)
-// (*block)[newnz_pos[--num_newnz]] = 0;
-//
-// return false;
-
- }
-
- boolean decode_mcu_AC_first (jpeg_decompress_struct cinfo, short[][] MCU_data) {
- phuff_entropy_decoder entropy = this;
- int Se = cinfo.Se;
- int Al = cinfo.Al;
- int s = 0, k, r;
- int EOBRUN;
- short[] block;
-// BITREAD_STATE_VARS;
- int get_buffer;
- int bits_left;
-// bitread_working_state br_state = new bitread_working_state();
- bitread_working_state br_state = br_state_local;
-
- d_derived_tbl tbl;
-
- /* Process restart marker if needed; may have to suspend */
- if (cinfo.restart_interval != 0) {
- if (entropy.restarts_to_go == 0)
- if (! process_restart(cinfo))
- return false;
- }
-
- /* If we've run out of data, just leave the MCU set to zeroes.
- * This way, we return uniform gray for the remainder of the segment.
- */
- if (! entropy.insufficient_data) {
-
- /* Load up working state.
- * We can avoid loading/saving bitread state if in an EOB run.
- */
- EOBRUN = entropy.saved.EOBRUN; /* only part of saved state we need */
-
- /* There is always only one block per MCU */
-
- if (EOBRUN > 0) /* if it's a band of zeroes... */
- EOBRUN--; /* ...process it now (we do nothing) */
- else {
-// BITREAD_LOAD_STATE(cinfo,entropy.bitstate);
- br_state.cinfo = cinfo;
- br_state.buffer = cinfo.buffer;
- br_state.bytes_in_buffer = cinfo.bytes_in_buffer;
- br_state.bytes_offset = cinfo.bytes_offset;
- get_buffer = entropy.bitstate.get_buffer;
- bits_left = entropy.bitstate.bits_left;
-
- block = MCU_data[0];
- tbl = entropy.ac_derived_tbl;
-
- for (k = cinfo.Ss; k <= Se; k++) {
-// HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
- {
- int nb = 0, look;
- if (bits_left < HUFF_LOOKAHEAD) {
- if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) {
- return false;
- }
- get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
- if (bits_left < HUFF_LOOKAHEAD) {
- nb = 1;
-// goto slowlabel;
- if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) {
- return false;
- }
- get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
- }
- }
- if (nb != 1) {
-// look = PEEK_BITS(HUFF_LOOKAHEAD);
- look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1));
-
- if ((nb = tbl.look_nbits[look]) != 0) {
-// DROP_BITS(nb);
- bits_left -= nb;
- s = tbl.look_sym[look] & 0xFF;
- } else {
- nb = HUFF_LOOKAHEAD+1;
-// slowlabel:
- if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) {
- return false;
- }
- get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
- }
- }
- }
- r = s >> 4;
- s &= 15;
- if (s != 0) {
- k += r;
-// CHECK_BIT_BUFFER(br_state, s, return FALSE);
- {
- if (bits_left < (s)) {
- if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) {
- return false;
- }
- get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
- }
- }
-// r = GET_BITS(s);
- r = (( (get_buffer >> (bits_left -= (s)))) & ((1<<(s))-1));
-// s = HUFF_EXTEND(r, s);
- s = ((r) < extend_test[s] ? (r) + extend_offset[s] : (r));
- /* Scale and output coefficient in natural (dezigzagged) order */
- block[jpeg_natural_order[k]] = (short) (s << Al);
- } else {
- if (r == 15) { /* ZRL */
- k += 15; /* skip 15 zeroes in band */
- } else { /* EOBr, run length is 2^r + appended bits */
- EOBRUN = 1 << r;
- if (r != 0) { /* EOBr, r > 0 */
-// CHECK_BIT_BUFFER(br_state, r, return FALSE);
- {
- if (bits_left < (r)) {
- if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,r)) {
- return false;
- }
- get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
- }
- }
-// r = GET_BITS(r);
- r = (( (get_buffer >> (bits_left -= (r)))) & ((1<<(r))-1));
- EOBRUN += r;
- }
- EOBRUN--; /* this band is processed at this moment */
- break; /* force end-of-band */
- }
- }
- }
-
-// BITREAD_SAVE_STATE(cinfo,entropy.bitstate);
- cinfo.buffer = br_state.buffer;
- cinfo.bytes_in_buffer = br_state.bytes_in_buffer;
- cinfo.bytes_offset = br_state.bytes_offset;
- entropy.bitstate.get_buffer = get_buffer;
- entropy.bitstate.bits_left = bits_left;
- }
-
- /* Completed MCU, so update state */
- entropy.saved.EOBRUN = EOBRUN; /* only part of saved state we need */
- }
-
- /* Account for restart interval (no-op if not using restarts) */
- entropy.restarts_to_go--;
-
- return true;
- }
-
- boolean decode_mcu_DC_first (jpeg_decompress_struct cinfo, short[][] MCU_data) {
- phuff_entropy_decoder entropy = this;
- int Al = cinfo.Al;
- int s = 0, r;
- int blkn, ci;
- short[] block;
-// BITREAD_STATE_VARS;
- int get_buffer;
- int bits_left;
-// bitread_working_state br_state = new bitread_working_state();
- bitread_working_state br_state = br_state_local;
-
-// savable_state state = new savable_state();
- savable_state state = state_local;
- d_derived_tbl tbl;
- jpeg_component_info compptr;
-
- /* Process restart marker if needed; may have to suspend */
- if (cinfo.restart_interval != 0) {
- if (entropy.restarts_to_go == 0)
- if (! process_restart(cinfo))
- return false;
- }
-
- /* If we've run out of data, just leave the MCU set to zeroes.
- * This way, we return uniform gray for the remainder of the segment.
- */
- if (! entropy.insufficient_data) {
-
- /* Load up working state */
-// BITREAD_LOAD_STATE(cinfo,entropy.bitstate);
- br_state.cinfo = cinfo;
- br_state.buffer = cinfo.buffer;
- br_state.bytes_in_buffer = cinfo.bytes_in_buffer;
- br_state.bytes_offset = cinfo.bytes_offset;
- get_buffer = entropy.bitstate.get_buffer;
- bits_left = entropy.bitstate.bits_left;
-
-// ASSIGN_STATE(state, entropy.saved);
- state.EOBRUN = entropy.saved.EOBRUN;
- state.last_dc_val[0] = entropy.saved.last_dc_val[0];
- state.last_dc_val[1] = entropy.saved.last_dc_val[1];
- state.last_dc_val[2] = entropy.saved.last_dc_val[2];
- state.last_dc_val[3] = entropy.saved.last_dc_val[3];
-
- /* Outer loop handles each block in the MCU */
-
- for (blkn = 0; blkn < cinfo.blocks_in_MCU; blkn++) {
- block = MCU_data[blkn];
- ci = cinfo.MCU_membership[blkn];
- compptr = cinfo.cur_comp_info[ci];
- tbl = entropy.derived_tbls[compptr.dc_tbl_no];
-
- /* Decode a single block's worth of coefficients */
-
- /* Section F.2.2.1: decode the DC coefficient difference */
-// HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
- {
- int nb = 0, look;
- if (bits_left < HUFF_LOOKAHEAD) {
- if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) {
- return false;
- }
- get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
- if (bits_left < HUFF_LOOKAHEAD) {
- nb = 1;
-// goto slowlabel;
- if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) {
- return false;
- }
- get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
- }
- }
- if (nb != 1) {
-// look = PEEK_BITS(HUFF_LOOKAHEAD);
- look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1));
-
- if ((nb = tbl.look_nbits[look]) != 0) {
-// DROP_BITS(nb);
- bits_left -= nb;
- s = tbl.look_sym[look] & 0xFF;
- } else {
- nb = HUFF_LOOKAHEAD+1;
-// slowlabel:
- if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) {
- return false;
- }
- get_buffer = br_state.get_buffer; bits_left = br_state.bits_left;
- }
- }
- }
- if (s != 0) {
-// CHECK_BIT_BUFFER(br_state, s, return FALSE);
- {
- if (bits_left < (s)) {
- if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) {
- return false;
- }
- get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left;
- }
- }
-// r = GET_BITS(s);
- r = (( (get_buffer >> (bits_left -= (s)))) & ((1<<(s))-1));
-// s = HUFF_EXTEND(r, s);
- s = ((r) < extend_test[s] ? (r) + extend_offset[s] : (r));
- }
-
- /* Convert DC difference to actual value, update last_dc_val */
- s += state.last_dc_val[ci];
- state.last_dc_val[ci] = s;
- /* Scale and output the coefficient (assumes jpeg_natural_order[0]=0) */
- block[0] = (short) (s << Al);
- }
-
- /* Completed MCU, so update state */
-// BITREAD_SAVE_STATE(cinfo,entropy.bitstate);
- cinfo.buffer = br_state.buffer;
- cinfo.bytes_in_buffer = br_state.bytes_in_buffer;
- cinfo.bytes_offset = br_state.bytes_offset;
- entropy.bitstate.get_buffer = get_buffer;
- entropy.bitstate.bits_left = bits_left;
-// ASSIGN_STATE(entropy.saved, state);
- entropy.saved.EOBRUN = state.EOBRUN;
- entropy.saved.last_dc_val[0] = state.last_dc_val[0];
- entropy.saved.last_dc_val[1] = state.last_dc_val[1];
- entropy.saved.last_dc_val[2] = state.last_dc_val[2];
- entropy.saved.last_dc_val[3] = state.last_dc_val[3];
- }
-
- /* Account for restart interval (no-op if not using restarts) */
- entropy.restarts_to_go--;
-
- return true;
- }
-
- boolean process_restart (jpeg_decompress_struct cinfo) {
- phuff_entropy_decoder entropy = this;
- int ci;
-
- /* Throw away any unused bits remaining in bit buffer; */
- /* include any full bytes in next_marker's count of discarded bytes */
- cinfo.marker.discarded_bytes += entropy.bitstate.bits_left / 8;
- entropy.bitstate.bits_left = 0;
-
- /* Advance past the RSTn marker */
- if (! read_restart_marker (cinfo))
- return false;
-
- /* Re-initialize DC predictions to 0 */
- for (ci = 0; ci < cinfo.comps_in_scan; ci++)
- entropy.saved.last_dc_val[ci] = 0;
- /* Re-init EOB run count, too */
- entropy.saved.EOBRUN = 0;
-
- /* Reset restart counter */
- entropy.restarts_to_go = cinfo.restart_interval;
-
- /* Reset out-of-data flag, unless read_restart_marker left us smack up
- * against a marker. In that case we will end up treating the next data
- * segment as empty, and we can avoid producing bogus output pixels by
- * leaving the flag set.
- */
- if (cinfo.unread_marker == 0)
- entropy.insufficient_data = false;
-
- return true;
- }
-
- void start_pass_phuff_decoder (jpeg_decompress_struct cinfo) {
- phuff_entropy_decoder entropy = this;
- boolean is_DC_band, bad;
- int ci, coefi, tbl;
- int[] coef_bit_ptr;
- jpeg_component_info compptr;
-
- is_DC_band = (cinfo.Ss == 0);
-
- /* Validate scan parameters */
- bad = false;
- if (is_DC_band) {
- if (cinfo.Se != 0)
- bad = true;
- } else {
- /* need not check Ss/Se < 0 since they came from unsigned bytes */
- if (cinfo.Ss > cinfo.Se || cinfo.Se >= DCTSIZE2)
- bad = true;
- /* AC scans may have only one component */
- if (cinfo.comps_in_scan != 1)
- bad = true;
- }
- if (cinfo.Ah != 0) {
- /* Successive approximation refinement scan: must have Al = Ah-1. */
- if (cinfo.Al != cinfo.Ah-1)
- bad = true;
- }
- if (cinfo.Al > 13) /* need not check for < 0 */
- bad = true;
- /* Arguably the maximum Al value should be less than 13 for 8-bit precision,
- * but the spec doesn't say so, and we try to be liberal about what we
- * accept. Note: large Al values could result in out-of-range DC
- * coefficients during early scans, leading to bizarre displays due to
- * overflows in the IDCT math. But we won't crash.
- */
- if (bad)
- error();
-// ERREXIT4(cinfo, JERR_BAD_PROGRESSION, cinfo.Ss, cinfo.Se, cinfo.Ah, cinfo.Al);
- /* Update progression status, and verify that scan order is legal.
- * Note that inter-scan inconsistencies are treated as warnings
- * not fatal errors ... not clear if this is right way to behave.
- */
- for (ci = 0; ci < cinfo.comps_in_scan; ci++) {
- int cindex = cinfo.cur_comp_info[ci].component_index;
- coef_bit_ptr = cinfo.coef_bits[cindex];
- if (!is_DC_band && coef_bit_ptr[0] < 0) {/* AC without prior DC scan */
-// WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
- }
- for (coefi = cinfo.Ss; coefi <= cinfo.Se; coefi++) {
- int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
- if (cinfo.Ah != expected) {
-// WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
- }
- coef_bit_ptr[coefi] = cinfo.Al;
- }
- }
-
- /* Select MCU decoding routine */
-// if (cinfo.Ah == 0) {
-// if (is_DC_band)
-// entropy.pub.decode_mcu = decode_mcu_DC_first;
-// else
-// entropy.pub.decode_mcu = decode_mcu_AC_first;
-// } else {
-// if (is_DC_band)
-// entropy.pub.decode_mcu = decode_mcu_DC_refine;
-// else
-// entropy.pub.decode_mcu = decode_mcu_AC_refine;
-// }
-
- for (ci = 0; ci < cinfo.comps_in_scan; ci++) {
- compptr = cinfo.cur_comp_info[ci];
- /* Make sure requested tables are present, and compute derived tables.
- * We may build same derived table more than once, but it's not expensive.
- */
- if (is_DC_band) {
- if (cinfo.Ah == 0) { /* DC refinement needs no table */
- tbl = compptr.dc_tbl_no;
- jpeg_make_d_derived_tbl(cinfo, true, tbl, entropy.derived_tbls[tbl] = new d_derived_tbl());
- }
- } else {
- tbl = compptr.ac_tbl_no;
- jpeg_make_d_derived_tbl(cinfo, false, tbl, entropy.derived_tbls[tbl] = new d_derived_tbl());
- /* remember the single active table */
- entropy.ac_derived_tbl = entropy.derived_tbls[tbl];
- }
- /* Initialize DC predictions to 0 */
- entropy.saved.last_dc_val[ci] = 0;
- }
-
- /* Initialize bitread state variables */
- entropy.bitstate.bits_left = 0;
- entropy.bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
- entropy.insufficient_data = false;
-
- /* Initialize private state variables */
- entropy.saved.EOBRUN = 0;
-
- /* Initialize restart counter */
- entropy.restarts_to_go = cinfo.restart_interval;
- }
-
- }
-
- static final class jpeg_component_info {
- /* These values are fixed over the whole image. */
- /* For compression, they must be supplied by parameter setup; */
- /* for decompression, they are read from the SOF marker. */
- int component_id; /* identifier for this component (0..255) */
- int component_index; /* its index in SOF or cinfo.comp_info[] */
- int h_samp_factor; /* horizontal sampling factor (1..4) */
- int v_samp_factor; /* vertical sampling factor (1..4) */
- int quant_tbl_no; /* quantization table selector (0..3) */
- /* These values may vary between scans. */
- /* For compression, they must be supplied by parameter setup; */
- /* for decompression, they are read from the SOS marker. */
- /* The decompressor output side may not use these variables. */
- int dc_tbl_no; /* DC entropy table selector (0..3) */
- int ac_tbl_no; /* AC entropy table selector (0..3) */
-
- /* Remaining fields should be treated as private by applications. */
-
- /* These values are computed during compression or decompression startup: */
- /* Component's size in DCT blocks.
- * Any dummy blocks added to complete an MCU are not counted; therefore
- * these values do not depend on whether a scan is interleaved or not.
- */
- int width_in_blocks;
- int height_in_blocks;
- /* Size of a DCT block in samples. Always DCTSIZE for compression.
- * For decompression this is the size of the output from one DCT block,
- * reflecting any scaling we choose to apply during the IDCT step.
- * Values of 1,2,4,8 are likely to be supported. Note that different
- * components may receive different IDCT scalings.
- */
- int DCT_scaled_size;
- /* The downsampled dimensions are the component's actual, unpadded number
- * of samples at the main buffer (preprocessing/compression interface), thus
- * downsampled_width = ceil(image_width * Hi/Hmax)
- * and similarly for height. For decompression, IDCT scaling is included, so
- * downsampled_width = ceil(image_width * Hi/Hmax * DCT_scaled_size/DCTSIZE)
- */
- int downsampled_width; /* actual width in samples */
- int downsampled_height; /* actual height in samples */
- /* This flag is used only for decompression. In cases where some of the
- * components will be ignored (eg grayscale output from YCbCr image),
- * we can skip most computations for the unused components.
- */
- boolean component_needed; /* do we need the value of this component? */
-
- /* These values are computed before starting a scan of the component. */
- /* The decompressor output side may not use these variables. */
- int MCU_width; /* number of blocks per MCU, horizontally */
- int MCU_height; /* number of blocks per MCU, vertically */
- int MCU_blocks; /* MCU_width * MCU_height */
- int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
- int last_col_width; /* # of non-dummy blocks across in last MCU */
- int last_row_height; /* # of non-dummy blocks down in last MCU */
-
- /* Saved quantization table for component; null if none yet saved.
- * See jdinput.c comments about the need for this information.
- * This field is currently used only for decompression.
- */
- JQUANT_TBL quant_table;
-
- /* Private per-component storage for DCT or IDCT subsystem. */
- int[] dct_table;
- }
-
- static final class jpeg_color_quantizer {
-// JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
-// JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
-// JSAMPARRAY input_buf, JSAMPARRAY output_buf,
-// int num_rows));
-// JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
-// JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
-
- /* Initially allocated colormap is saved here */
- int[][] sv_colormap; /* The color map as a 2-D pixel array */
- int sv_actual; /* number of entries in use */
-
- int[][] colorindex; /* Precomputed mapping for speed */
- /* colorindex[i][j] = index of color closest to pixel value j in component i,
- * premultiplied as described above. Since colormap indexes must fit into
- * JSAMPLEs, the entries of this array will too.
- */
- boolean is_padded; /* is the colorindex padded for odither? */
-
- int[] Ncolors = new int [MAX_Q_COMPS]; /* # of values alloced to each component */
-
- /* Variables for ordered dithering */
- int row_index; /* cur row's vertical index in dither matrix */
-// ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
-
- /* Variables for Floyd-Steinberg dithering */
-// FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
- boolean on_odd_row;
-
- void start_pass (jpeg_decompress_struct cinfo, boolean is_pre_scan) {
- error();
- }
- }
-
- static final class jpeg_upsampler {
-// JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
-// JMETHOD(void, upsample, (j_decompress_ptr cinfo,
-// JSAMPIMAGE input_buf,
-// JDIMENSION *in_row_group_ctr,
-// JDIMENSION in_row_groups_avail,
-// JSAMPARRAY output_buf,
-// JDIMENSION *out_row_ctr,
-// JDIMENSION out_rows_avail));
-
- boolean need_context_rows; /* TRUE if need rows above & below */
-
- /* Color conversion buffer. When using separate upsampling and color
- * conversion steps, this buffer holds one upsampled row group until it
- * has been color converted and output.
- * Note: we do not allocate any storage for component(s) which are full-size,
- * ie do not need rescaling. The corresponding entry of color_buf[] is
- * simply set to point to the input data array, thereby avoiding copying.
- */
- byte[][][] color_buf = new byte[MAX_COMPONENTS][][];
- int[] color_buf_offset = new int[MAX_COMPONENTS];
-
- /* Per-component upsampling method pointers */
- int[] methods = new int[MAX_COMPONENTS];
-
- int next_row_out; /* counts rows emitted from color_buf */
- int rows_to_go; /* counts rows remaining in image */
-
- /* Height of an input row group for each component. */
- int[] rowgroup_height = new int[MAX_COMPONENTS];
-
- /* These arrays save pixel expansion factors so that int_expand need not
- * recompute them each time. They are unused for other upsampling methods.
- */
- byte[] h_expand = new byte[MAX_COMPONENTS];
- byte[] v_expand = new byte[MAX_COMPONENTS];
-
- void start_pass (jpeg_decompress_struct cinfo) {
- jpeg_upsampler upsample = cinfo.upsample;
-
- /* Mark the conversion buffer empty */
- upsample.next_row_out = cinfo.max_v_samp_factor;
- /* Initialize total-height counter for detecting bottom of image */
- upsample.rows_to_go = cinfo.output_height;
- }
-
- }
-
- static final class jpeg_marker_reader {
- /* Read a restart marker --- exported for use by entropy decoder only */
-// jpeg_marker_parser_method read_restart_marker;
-
- /* State of marker reader --- nominally internal, but applications
- * supplying COM or APPn handlers might like to know the state.
- */
- boolean saw_SOI; /* found SOI? */
- boolean saw_SOF; /* found SOF? */
- int next_restart_num; /* next restart number expected (0-7) */
- int discarded_bytes; /* # of bytes skipped looking for a marker */
-
- /* Application-overridable marker processing methods */
-// jpeg_marker_parser_method process_COM;
-// jpeg_marker_parser_method process_APPn[16];
-
- /* Limit on marker data length to save for each marker type */
- int length_limit_COM;
- int[] length_limit_APPn = new int[16];
-
- /* Status of COM/APPn marker saving */
-// jpeg_marker_reader cur_marker; /* null if not processing a marker */
-// int bytes_read; /* data bytes read so far in marker */
- /* Note: cur_marker is not linked into marker_list until it's all read. */
- }
-
-
- static final class jpeg_d_main_controller {
-// JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
- int process_data;
-
- /* Pointer to allocated workspace (M or M+2 row groups). */
- byte[][][] buffer = new byte[MAX_COMPONENTS][][];
- int[] buffer_offset = new int[MAX_COMPONENTS];
-
- boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
- int[] rowgroup_ctr = new int[1]; /* counts row groups output to postprocessor */
-
- /* Remaining fields are only used in the context case. */
-
- /* These are the master pointers to the funny-order pointer lists. */
- byte[][][][] xbuffer = new byte[2][][][]; /* pointers to weird pointer lists */
- int[][] xbuffer_offset = new int[2][];
-
- int whichptr; /* indicates which pointer set is now in use */
- int context_state; /* process_data state machine status */
- int rowgroups_avail; /* row groups available to postprocessor */
- int iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
-
- void start_pass (jpeg_decompress_struct cinfo, int pass_mode) {
- jpeg_d_main_controller main = cinfo.main;
-
- switch (pass_mode) {
- case JBUF_PASS_THRU:
- if (cinfo.upsample.need_context_rows) {
- main.process_data = PROCESS_DATA_CONTEXT_MAIN;
- make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
- main.whichptr = 0; /* Read first iMCU row into xbuffer[0] */
- main.context_state = CTX_PREPARE_FOR_IMCU;
- main.iMCU_row_ctr = 0;
- } else {
- /* Simple case with no context needed */
- main.process_data = PROCESS_DATA_SIMPLE_MAIN;
- }
- main.buffer_full = false; /* Mark buffer empty */
- main.rowgroup_ctr[0] = 0;
- break;
-// #ifdef QUANT_2PASS_SUPPORTED
-// case JBUF_CRANK_DEST:
-// /* For last pass of 2-pass quantization, just crank the postprocessor */
-// main.process_data = PROCESS_DATA_CRANK_POST;
-// break;
-// #endif
- default:
- error();
-// ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
- break;
- }
- }
-
- }
-
- static final class jpeg_decomp_master {
-// JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
-// JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
-
- /* State variables made visible to other modules */
- boolean is_dummy_pass;
-
- int pass_number; /* # of passes completed */
-
- boolean using_merged_upsample; /* true if using merged upsample/cconvert */
-
- /* Saved references to initialized quantizer modules,
- * in case we need to switch modes.
- */
- jpeg_color_quantizer quantizer_1pass;
- jpeg_color_quantizer quantizer_2pass;
- }
-
- static final class jpeg_inverse_dct {
-// JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
-// /* It is useful to allow each component to have a separate IDCT method. */
-// inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
- int[] cur_method = new int[MAX_COMPONENTS];
-
- void start_pass (jpeg_decompress_struct cinfo) {
- jpeg_inverse_dct idct = cinfo.idct;
- int ci, i;
- jpeg_component_info compptr;
- int method = 0;
-// inverse_DCT_method_ptr method_ptr = NULL;
- JQUANT_TBL qtbl;
-
- for (ci = 0; ci < cinfo.num_components; ci++) {
- compptr = cinfo.comp_info[ci];
- /* Select the proper IDCT routine for this component's scaling */
- switch (compptr.DCT_scaled_size) {
-// #ifdef IDCT_SCALING_SUPPORTED
-// case 1:
-// method_ptr = jpeg_idct_1x1;
-// method = JDCT_ISLOW; /* jidctred uses islow-style table */
-// break;
-// case 2:
-// method_ptr = jpeg_idct_2x2;
-// method = JDCT_ISLOW; /* jidctred uses islow-style table */
-// break;
-// case 4:
-// method_ptr = jpeg_idct_4x4;
-// method = JDCT_ISLOW; /* jidctred uses islow-style table */
-// break;
-// #endif
- case DCTSIZE:
- switch (cinfo.dct_method) {
-// #ifdef DCT_ISLOW_SUPPORTED
- case JDCT_ISLOW:
-// method_ptr = jpeg_idct_islow;
- method = JDCT_ISLOW;
- break;
-// #endif
-// #ifdef DCT_IFAST_SUPPORTED
-// case JDCT_IFAST:
-// method_ptr = jpeg_idct_ifast;
-// method = JDCT_IFAST;
-// break;
-// #endif
-// #ifdef DCT_FLOAT_SUPPORTED
-// case JDCT_FLOAT:
-// method_ptr = jpeg_idct_float;
-// method = JDCT_FLOAT;
-// break;
-// #endif
- default:
- error();
-// ERREXIT(cinfo, JERR_NOT_COMPILED);
- break;
- }
- break;
- default:
- error();
-// ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr.DCT_scaled_size);
- break;
- }
-// idct.inverse_DCT[ci] = method_ptr;
- /* Create multiplier table from quant table.
- * However, we can skip this if the component is uninteresting
- * or if we already built the table. Also, if no quant table
- * has yet been saved for the component, we leave the
- * multiplier table all-zero; we'll be reading zeroes from the
- * coefficient controller's buffer anyway.
- */
- if (! compptr.component_needed || idct.cur_method[ci] == method)
- continue;
- qtbl = compptr.quant_table;
- if (qtbl == null) /* happens if no data yet for component */
- continue;
- idct.cur_method[ci] = method;
- switch (method) {
-// #ifdef PROVIDE_ISLOW_TABLES
- case JDCT_ISLOW:
- {
- /* For LL&M IDCT method, multipliers are equal to raw quantization
- * coefficients, but are stored as ints to ensure access efficiency.
- */
- int[] ismtbl = compptr.dct_table;
- for (i = 0; i < DCTSIZE2; i++) {
- ismtbl[i] = qtbl.quantval[i];
- }
- }
- break;
-// #endif
-// #ifdef DCT_IFAST_SUPPORTED
-// case JDCT_IFAST:
-// {
-// /* For AA&N IDCT method, multipliers are equal to quantization
-// * coefficients scaled by scalefactor[row]*scalefactor[col], where
-// * scalefactor[0] = 1
-// * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
-// * For integer operation, the multiplier table is to be scaled by
-// * IFAST_SCALE_BITS.
-// */
-// int[] ifmtbl = compptr.dct_table;
-// short aanscales[] = {
-// /* precomputed values scaled up by 14 bits */
-// 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
-// 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
-// 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
-// 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
-// 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
-// 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
-// 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
-// 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
-// };
-// SHIFT_TEMPS
-//
-// for (i = 0; i < DCTSIZE2; i++) {
-// ifmtbl[i] = DESCALE(MULTIPLY16V16( qtbl.quantval[i], aanscales[i]), CONST_BITS-IFAST_SCALE_BITS);
-// }
-// }
-// break;
-// #endif
-// #ifdef DCT_FLOAT_SUPPORTED
-// case JDCT_FLOAT:
-// {
-// /* For float AA&N IDCT method, multipliers are equal to quantization
-// * coefficients scaled by scalefactor[row]*scalefactor[col], where
-// * scalefactor[0] = 1
-// * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
-// */
-// FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr.dct_table;
-// int row, col;
-// static const double aanscalefactor[DCTSIZE] = {
-// 1.0, 1.387039845, 1.306562965, 1.175875602,
-// 1.0, 0.785694958, 0.541196100, 0.275899379
-// };
-//
-// i = 0;
-// for (row = 0; row < DCTSIZE; row++) {
-// for (col = 0; col < DCTSIZE; col++) {
-// fmtbl[i] = (FLOAT_MULT_TYPE)
-// ((double) qtbl.quantval[i] *
-// aanscalefactor[row] * aanscalefactor[col]);
-// i++;
-// }
-// }
-// }
-// break;
-// #endif
- default:
- error();
-// ERREXIT(cinfo, JERR_NOT_COMPILED);
- break;
- }
- }
- }
- }
-
- static final class jpeg_input_controller {
- int consume_input;
- boolean has_multiple_scans; /* True if file has multiple scans */
- boolean eoi_reached;
-
- boolean inheaders; /* true until first SOS is reached */
- }
-
- static final class jpeg_color_deconverter {
-// JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
- int color_convert;
-
- /* Private state for YCC.RGB conversion */
- int[] Cr_r_tab; /* => table for Cr to R conversion */
- int[] Cb_b_tab; /* => table for Cb to B conversion */
- int[] Cr_g_tab; /* => table for Cr to G conversion */
- int[] Cb_g_tab; /* => table for Cb to G conversion */
-
- void start_pass (jpeg_decompress_struct cinfo) {
- /* no work needed */
- }
-
- }
-
- static final class jpeg_d_post_controller {
-// JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
- int post_process_data;
-
- /* Color quantization source buffer: this holds output data from
- * the upsample/color conversion step to be passed to the quantizer.
- * For two-pass color quantization, we need a full-image buffer;
- * for one-pass operation, a strip buffer is sufficient.
- */
- int[] whole_image; /* virtual array, or NULL if one-pass */
- int[][] buffer; /* strip buffer, or current strip of virtual */
- int strip_height; /* buffer size in rows */
- /* for two-pass mode only: */
- int starting_row; /* row # of first row in current strip */
- int next_row; /* index of next row to fill/empty in strip */
-
- void start_pass (jpeg_decompress_struct cinfo, int pass_mode) {
- jpeg_d_post_controller post = cinfo.post;
-
- switch (pass_mode) {
- case JBUF_PASS_THRU:
- if (cinfo.quantize_colors) {
- error(SWT.ERROR_NOT_IMPLEMENTED);
-// /* Single-pass processing with color quantization. */
-// post.post_process_data = POST_PROCESS_1PASS;
-// /* We could be doing buffered-image output before starting a 2-pass
-// * color quantization; in that case, jinit_d_post_controller did not
-// * allocate a strip buffer. Use the virtual-array buffer as workspace.
-// */
-// if (post.buffer == null) {
-// post.buffer = (*cinfo.mem.access_virt_sarray)
-// ((j_common_ptr) cinfo, post.whole_image,
-// (JDIMENSION) 0, post.strip_height, TRUE);
-// }
- } else {
- /* For single-pass processing without color quantization,
- * I have no work to do; just call the upsampler directly.
- */
- post.post_process_data = POST_PROCESS_DATA_UPSAMPLE;
- }
- break;
-// #ifdef QUANT_2PASS_SUPPORTED
-// case JBUF_SAVE_AND_PASS:
-// /* First pass of 2-pass quantization */
-// if (post.whole_image == NULL)
-// ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
-// post.pub.post_process_data = post_process_prepass;
-// break;
-// case JBUF_CRANK_DEST:
-// /* Second pass of 2-pass quantization */
-// if (post.whole_image == NULL)
-// ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
-// post.pub.post_process_data = post_process_2pass;
-// break;
-// #endif /* QUANT_2PASS_SUPPORTED */
- default:
- error();
-// ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
- break;
- }
- post.starting_row = post.next_row = 0;
- }
-
- }
-
- static final class jpeg_decompress_struct {
-// jpeg_error_mgr * err; /* Error handler module */\
-// struct jpeg_memory_mgr * mem; /* Memory manager module */\
-// struct jpeg_progress_mgr * progress; /* Progress monitor, or null if none */\
-// void * client_data; /* Available for use by application */\
- boolean is_decompressor; /* So common code can tell which is which */
- int global_state; /* For checking call sequence validity */
-
-// /* Source of compressed data */
-// struct jpeg_source_mgr * src;
- InputStream inputStream;
- byte[] buffer;
- int bytes_in_buffer;
- int bytes_offset;
- boolean start_of_file;
-
- /* Basic description of image --- filled in by jpeg_read_header(). */
- /* Application may inspect these values to decide how to process image. */
-
- int image_width; /* nominal image width (from SOF marker) */
- int image_height; /* nominal image height */
- int num_components; /* # of color components in JPEG image */
- int jpeg_color_space; /* colorspace of JPEG image */
-
- /* Decompression processing parameters --- these fields must be set before
- * calling jpeg_start_decompress(). Note that jpeg_read_header() initializes
- * them to default values.
- */
-
- int out_color_space; /* colorspace for output */
-
- int scale_num, scale_denom; /* fraction by which to scale image */
-
- double output_gamma; /* image gamma wanted in output */
-
- boolean buffered_image; /* true=multiple output passes */
- boolean raw_data_out; /* true=downsampled data wanted */
-
- int dct_method; /* IDCT algorithm selector */
- boolean do_fancy_upsampling; /* true=apply fancy upsampling */
- boolean do_block_smoothing; /* true=apply interblock smoothing */
-
- boolean quantize_colors; /* true=colormapped output wanted */
- /* the following are ignored if not quantize_colors: */
- int dither_mode; /* type of color dithering to use */
- boolean two_pass_quantize; /* true=use two-pass color quantization */
- int desired_number_of_colors; /* max # colors to use in created colormap */
- /* these are significant only in buffered-image mode: */
- boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
- boolean enable_external_quant;/* enable future use of external colormap */
- boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
-
- /* Description of actual output image that will be returned to application.
- * These fields are computed by jpeg_start_decompress().
- * You can also use jpeg_calc_output_dimensions() to determine these values
- * in advance of calling jpeg_start_decompress().
- */
-
- int output_width; /* scaled image width */
- int output_height; /* scaled image height */
- int out_color_components; /* # of color components in out_color_space */
- int output_components; /* # of color components returned */
- /* output_components is 1 (a colormap index) when quantizing colors;
- * otherwise it equals out_color_components.
- */
- int rec_outbuf_height; /* min recommended height of scanline buffer */
- /* If the buffer passed to jpeg_read_scanlines() is less than this many rows
- * high, space and time will be wasted due to unnecessary data copying.
- * Usually rec_outbuf_height will be 1 or 2, at most 4.
- */
-
- /* When quantizing colors, the output colormap is described by these fields.
- * The application can supply a colormap by setting colormap non-null before
- * calling jpeg_start_decompress; otherwise a colormap is created during
- * jpeg_start_decompress or jpeg_start_output.
- * The map has out_color_components rows and actual_number_of_colors columns.
- */
- int actual_number_of_colors; /* number of entries in use */
- int[] colormap; /* The color map as a 2-D pixel array */
-
- /* State variables: these variables indicate the progress of decompression.
- * The application may examine these but must not modify them.
- */
-
- /* Row index of next scanline to be read from jpeg_read_scanlines().
- * Application may use this to control its processing loop, e.g.,
- * "while (output_scanline < output_height)".
- */
- int output_scanline; /* 0 .. output_height-1 */
-
- /* Current input scan number and number of iMCU rows completed in scan.
- * These indicate the progress of the decompressor input side.
- */
- int input_scan_number; /* Number of SOS markers seen so far */
- int input_iMCU_row; /* Number of iMCU rows completed */
-
- /* The "output scan number" is the notional scan being displayed by the
- * output side. The decompressor will not allow output scan/row number
- * to get ahead of input scan/row, but it can fall arbitrarily far behind.
- */
- int output_scan_number; /* Nominal scan number being displayed */
- int output_iMCU_row; /* Number of iMCU rows read */
-
- /* Current progression status. coef_bits[c][i] indicates the precision
- * with which component c's DCT coefficient i (in zigzag order) is known.
- * It is -1 when no data has yet been received, otherwise it is the point
- * transform (shift) value for the most recent scan of the coefficient
- * (thus, 0 at completion of the progression).
- * This pointer is null when reading a non-progressive file.
- */
- int[][] coef_bits; /* -1 or current Al value for each coef */
-
- /* Internal JPEG parameters --- the application usually need not look at
- * these fields. Note that the decompressor output side may not use
- * any parameters that can change between scans.
- */
-
- /* Quantization and Huffman tables are carried forward across input
- * datastreams when processing abbreviated JPEG datastreams.
- */
-
- JQUANT_TBL[] quant_tbl_ptrs = new JQUANT_TBL[NUM_QUANT_TBLS];
- /* ptrs to coefficient quantization tables, or null if not defined */
-
- JHUFF_TBL[] dc_huff_tbl_ptrs = new JHUFF_TBL[NUM_HUFF_TBLS];
- JHUFF_TBL[] ac_huff_tbl_ptrs = new JHUFF_TBL[NUM_HUFF_TBLS];
- /* ptrs to Huffman coding tables, or null if not defined */
-
- /* These parameters are never carried across datastreams, since they
- * are given in SOF/SOS markers or defined to be reset by SOI.
- */
-
- int data_precision; /* bits of precision in image data */
-
- jpeg_component_info[] comp_info;
- /* comp_info[i] describes component that appears i'th in SOF */
-
- boolean progressive_mode; /* true if SOFn specifies progressive mode */
- boolean arith_code; /* true=arithmetic coding, false=Huffman */
-
- byte[] arith_dc_L = new byte[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
- byte[] arith_dc_U = new byte[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
- byte[] arith_ac_K = new byte[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
-
- int restart_interval; /* MCUs per restart interval, or 0 for no restart */
-
- /* These fields record data obtained from optional markers recognized by
- * the JPEG library.
- */
- boolean saw_JFIF_marker; /* true iff a JFIF APP0 marker was found */
- /* Data copied from JFIF marker; only valid if saw_JFIF_marker is true: */
- byte JFIF_major_version; /* JFIF version number */
- byte JFIF_minor_version;
- byte density_unit; /* JFIF code for pixel size units */
- short X_density; /* Horizontal pixel density */
- short Y_density; /* Vertical pixel density */
- boolean saw_Adobe_marker; /* true iff an Adobe APP14 marker was found */
- byte Adobe_transform; /* Color transform code from Adobe marker */
-
- boolean CCIR601_sampling; /* true=first samples are cosited */
-
- /* Aside from the specific data retained from APPn markers known to the
- * library, the uninterpreted contents of any or all APPn and COM markers
- * can be saved in a list for examination by the application.
- */
- jpeg_marker_reader marker_list; /* Head of list of saved markers */
-
- /* Remaining fields are known throughout decompressor, but generally
- * should not be touched by a surrounding application.
- */
-
- /*
- * These fields are computed during decompression startup
- */
- int max_h_samp_factor; /* largest h_samp_factor */
- int max_v_samp_factor; /* largest v_samp_factor */
-
- int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
-
- int total_iMCU_rows; /* # of iMCU rows in image */
- /* The coefficient controller's input and output progress is measured in
- * units of "iMCU" (interleaved MCU) rows. These are the same as MCU rows
- * in fully interleaved JPEG scans, but are used whether the scan is
- * interleaved or not. We define an iMCU row as v_samp_factor DCT block
- * rows of each component. Therefore, the IDCT output contains
- * v_samp_factor*DCT_scaled_size sample rows of a component per iMCU row.
- */
-
- byte[] sample_range_limit; /* table for fast range-limiting */
- int sample_range_limit_offset;
-
- /*
- * These fields are valid during any one scan.
- * They describe the components and MCUs actually appearing in the scan.
- * Note that the decompressor output side must not use these fields.
- */
- int comps_in_scan; /* # of JPEG components in this scan */
- jpeg_component_info[] cur_comp_info = new jpeg_component_info[MAX_COMPS_IN_SCAN];
- /* *cur_comp_info[i] describes component that appears i'th in SOS */
-
- int MCUs_per_row; /* # of MCUs across the image */
- int MCU_rows_in_scan; /* # of MCU rows in the image */
-
- int blocks_in_MCU; /* # of DCT blocks per MCU */
- int[] MCU_membership = new int[D_MAX_BLOCKS_IN_MCU];
- /* MCU_membership[i] is index in cur_comp_info of component owning */
- /* i'th block in an MCU */
-
- int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
-
- /* This field is shared between entropy decoder and marker parser.
- * It is either zero or the code of a JPEG marker that has been
- * read from the data source, but has not yet been processed.
- */
- int unread_marker;
-
- int[] workspace = new int[DCTSIZE2];
- int[] row_ctr = new int[1];
-
- /*
- * Links to decompression subobjects (methods, private variables of modules)
- */
- jpeg_decomp_master master;
- jpeg_d_main_controller main;
- jpeg_d_coef_controller coef;
- jpeg_d_post_controller post;
- jpeg_input_controller inputctl;
- jpeg_marker_reader marker;
- jpeg_entropy_decoder entropy;
- jpeg_inverse_dct idct;
- jpeg_upsampler upsample;
- jpeg_color_deconverter cconvert;
- jpeg_color_quantizer cquantize;
- }
-
-static void error() {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
-}
-
-static void error(int code) {
- SWT.error(code);
-}
-
-static void error(String msg) {
- SWT.error(SWT.ERROR_INVALID_IMAGE, null, msg);
-}
-
-static void jinit_marker_reader (jpeg_decompress_struct cinfo) {
- jpeg_marker_reader marker = cinfo.marker = new jpeg_marker_reader();
-// int i;
-
- /* Initialize COM/APPn processing.
- * By default, we examine and then discard APP0 and APP14,
- * but simply discard COM and all other APPn.
- */
-// marker.process_COM = skip_variable;
- marker.length_limit_COM = 0;
-// for (i = 0; i < 16; i++) {
-// marker.process_APPn[i] = skip_variable;
-// marker.length_limit_APPn[i] = 0;
-// }
-// marker.process_APPn[0] = get_interesting_appn;
-// marker.process_APPn[14] = get_interesting_appn;
- /* Reset marker processing state */
- reset_marker_reader(cinfo);
-}
-
-static void jinit_d_coef_controller (jpeg_decompress_struct cinfo, boolean need_full_buffer) {
- jpeg_d_coef_controller coef = new jpeg_d_coef_controller();
- cinfo.coef = coef;
-// coef.pub.start_input_pass = start_input_pass;
-// coef.pub.start_output_pass = start_output_pass;
- coef.coef_bits_latch = null;
-
- /* Create the coefficient buffer. */
- if (need_full_buffer) {
-//#ifdef D_MULTISCAN_FILES_SUPPORTED
- /* Allocate a full-image virtual array for each component, */
- /* padded to a multiple of samp_factor DCT blocks in each direction. */
- /* Note we ask for a pre-zeroed array. */
- int ci, access_rows;
- jpeg_component_info compptr;
-
- for (ci = 0; ci < cinfo.num_components; ci++) {
- compptr = cinfo.comp_info[ci];
- access_rows = compptr.v_samp_factor;
-//#ifdef BLOCK_SMOOTHING_SUPPORTED
- /* If block smoothing could be used, need a bigger window */
- if (cinfo.progressive_mode)
- access_rows *= 3;
-//#endif
- coef.whole_image[ci] =
- new short
- [(int)jround_up( compptr.height_in_blocks, compptr.v_samp_factor)]
- [(int)jround_up( compptr.width_in_blocks, compptr.h_samp_factor)]
- [DCTSIZE2];
- }
-// coef.consume_data = consume_data;
- coef.decompress_data = DECOMPRESS_DATA;
- coef.coef_arrays = coef.whole_image[0]; /* link to virtual arrays */
-// #else
-// ERREXIT(cinfo, JERR_NOT_COMPILED);
-// #endif
- } else {
- /* We only need a single-MCU buffer. */
- coef.MCU_buffer = new short[D_MAX_BLOCKS_IN_MCU][DCTSIZE2];
-// coef.consume_data = dummy_consume_data;
- coef.decompress_data = DECOMPRESS_ONEPASS;
- coef.coef_arrays = null; /* flag for no virtual arrays */
- }
-}
-
-static void start_output_pass (jpeg_decompress_struct cinfo) {
-//#ifdef BLOCK_SMOOTHING_SUPPORTED
- jpeg_d_coef_controller coef = cinfo.coef;
-
- /* If multipass, check to see whether to use block smoothing on this pass */
- if (coef.coef_arrays != null) {
- if (cinfo.do_block_smoothing && smoothing_ok(cinfo))
- coef.decompress_data = DECOMPRESS_SMOOTH_DATA;
- else
- coef.decompress_data = DECOMPRESS_DATA;
- }
-//#endif
- cinfo.output_iMCU_row = 0;
-}
-
-static void jpeg_create_decompress(jpeg_decompress_struct cinfo) {
- cinfo.is_decompressor = true;
-
-
- /* Initialize marker processor so application can override methods
- * for COM, APPn markers before calling jpeg_read_header.
- */
- cinfo.marker_list = null;
- jinit_marker_reader(cinfo);
-
- /* And initialize the overall input controller. */
- jinit_input_controller(cinfo);
-
- /* OK, I'm ready */
- cinfo.global_state = DSTATE_START;
-}
-
-static void jpeg_calc_output_dimensions (jpeg_decompress_struct cinfo)
-/* Do computations that are needed before master selection phase */
-{
-//#ifdef IDCT_SCALING_SUPPORTED
-// int ci;
-// jpeg_component_info compptr;
-//#endif
-
- /* Prevent application from calling me at wrong times */
- if (cinfo.global_state != DSTATE_READY)
- error();
-// ERREXIT1(cinfo, JERR_BAD_STATE, cinfo.global_state);
-
-//#ifdef IDCT_SCALING_SUPPORTED
-//
-// /* Compute actual output image dimensions and DCT scaling choices. */
-// if (cinfo.scale_num * 8 <= cinfo.scale_denom) {
-// /* Provide 1/8 scaling */
-// cinfo.output_width = (int)
-// jdiv_round_up(cinfo.image_width, 8L);
-// cinfo.output_height = (int)
-// jdiv_round_up(cinfo.image_height, 8L);
-// cinfo.min_DCT_scaled_size = 1;
-// } else if (cinfo.scale_num * 4 <= cinfo.scale_denom) {
-// /* Provide 1/4 scaling */
-// cinfo.output_width = (int)
-// jdiv_round_up(cinfo.image_width, 4L);
-// cinfo.output_height = (int)
-// jdiv_round_up(cinfo.image_height, 4L);
-// cinfo.min_DCT_scaled_size = 2;
-// } else if (cinfo.scale_num * 2 <= cinfo.scale_denom) {
-// /* Provide 1/2 scaling */
-// cinfo.output_width = (int)
-// jdiv_round_up(cinfo.image_width, 2L);
-// cinfo.output_height = (int)
-// jdiv_round_up(cinfo.image_height, 2L);
-// cinfo.min_DCT_scaled_size = 4;
-// } else {
-// /* Provide 1/1 scaling */
-// cinfo.output_width = cinfo.image_width;
-// cinfo.output_height = cinfo.image_height;
-// cinfo.min_DCT_scaled_size = DCTSIZE;
-// }
-// /* In selecting the actual DCT scaling for each component, we try to
-// * scale up the chroma components via IDCT scaling rather than upsampling.
-// * This saves time if the upsampler gets to use 1:1 scaling.
-// * Note this code assumes that the supported DCT scalings are powers of 2.
-// */
-// for (ci = 0; ci < cinfo.num_components; ci++) {
-// compptr = cinfo.comp_info[ci];
-// int ssize = cinfo.min_DCT_scaled_size;
-// while (ssize < DCTSIZE &&
-// (compptr.h_samp_factor * ssize * 2 <= cinfo.max_h_samp_factor * cinfo.min_DCT_scaled_size) &&
-// (compptr.v_samp_factor * ssize * 2 <= cinfo.max_v_samp_factor * cinfo.min_DCT_scaled_size))
-// {
-// ssize = ssize * 2;
-// }
-// compptr.DCT_scaled_size = ssize;
-// }
-//
-// /* Recompute downsampled dimensions of components;
-// * application needs to know these if using raw downsampled data.
-// */
-// for (ci = 0; ci < cinfo.num_components; ci++) {
-// compptr = cinfo.comp_info[ci];
-// /* Size in samples, after IDCT scaling */
-// compptr.downsampled_width = (int)
-// jdiv_round_up((long) cinfo.image_width * (long) (compptr.h_samp_factor * compptr.DCT_scaled_size),
-// (cinfo.max_h_samp_factor * DCTSIZE));
-// compptr.downsampled_height = (int)
-// jdiv_round_up((long) cinfo.image_height * (long) (compptr.v_samp_factor * compptr.DCT_scaled_size),
-// (cinfo.max_v_samp_factor * DCTSIZE));
-// }
-//
-//#else /* !IDCT_SCALING_SUPPORTED */
-
- /* Hardwire it to "no scaling" */
- cinfo.output_width = cinfo.image_width;
- cinfo.output_height = cinfo.image_height;
- /* jdinput.c has already initialized DCT_scaled_size to DCTSIZE,
- * and has computed unscaled downsampled_width and downsampled_height.
- */
-
-//#endif /* IDCT_SCALING_SUPPORTED */
-
- /* Report number of components in selected colorspace. */
- /* Probably this should be in the color conversion module... */
- switch (cinfo.out_color_space) {
- case JCS_GRAYSCALE:
- cinfo.out_color_components = 1;
- break;
- case JCS_RGB:
- case JCS_YCbCr:
- cinfo.out_color_components = 3;
- break;
- case JCS_CMYK:
- case JCS_YCCK:
- cinfo.out_color_components = 4;
- break;
- default: /* else must be same colorspace as in file */
- cinfo.out_color_components = cinfo.num_components;
- break;
- }
- cinfo.output_components = (cinfo.quantize_colors ? 1 : cinfo.out_color_components);
-
- /* See if upsampler will want to emit more than one row at a time */
- if (use_merged_upsample(cinfo))
- cinfo.rec_outbuf_height = cinfo.max_v_samp_factor;
- else
- cinfo.rec_outbuf_height = 1;
-}
-
-static boolean use_merged_upsample (jpeg_decompress_struct cinfo) {
-//#ifdef UPSAMPLE_MERGING_SUPPORTED
- /* Merging is the equivalent of plain box-filter upsampling */
- if (cinfo.do_fancy_upsampling || cinfo.CCIR601_sampling)
- return false;
- /* jdmerge.c only supports YCC=>RGB color conversion */
- if (cinfo.jpeg_color_space != JCS_YCbCr || cinfo.num_components != 3 ||
- cinfo.out_color_space != JCS_RGB ||
- cinfo.out_color_components != RGB_PIXELSIZE)
- return false;
- /* and it only handles 2h1v or 2h2v sampling ratios */
- if (cinfo.comp_info[0].h_samp_factor != 2 ||
- cinfo.comp_info[1].h_samp_factor != 1 ||
- cinfo.comp_info[2].h_samp_factor != 1 ||
- cinfo.comp_info[0].v_samp_factor > 2 ||
- cinfo.comp_info[1].v_samp_factor != 1 ||
- cinfo.comp_info[2].v_samp_factor != 1)
- return false;
- /* furthermore, it doesn't work if we've scaled the IDCTs differently */
- if (cinfo.comp_info[0].DCT_scaled_size != cinfo.min_DCT_scaled_size ||
- cinfo.comp_info[1].DCT_scaled_size != cinfo.min_DCT_scaled_size ||
- cinfo.comp_info[2].DCT_scaled_size != cinfo.min_DCT_scaled_size)
- return false;
- /* ??? also need to test for upsample-time rescaling, when & if supported */
- return true; /* by golly, it'll work... */
-//#else
-// return false;
-//#endif
-}
-
-static void prepare_range_limit_table (jpeg_decompress_struct cinfo)
-/* Allocate and fill in the sample_range_limit table */
-{
- byte[] table;
- int i;
-
- table = new byte[5 * (MAXJSAMPLE+1) + CENTERJSAMPLE];
- int offset = (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
- cinfo.sample_range_limit_offset = offset;
- cinfo.sample_range_limit = table;
- /* First segment of "simple" table: limit[x] = 0 for x < 0 */
- /* Main part of "simple" table: limit[x] = x */
- for (i = 0; i <= MAXJSAMPLE; i++)
- table[i + offset] = (byte)i;
- offset += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
- /* End of simple table, rest of first half of post-IDCT table */
- for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
- table[i+offset] = (byte)MAXJSAMPLE;
- /* Second half of post-IDCT table */
- System.arraycopy(cinfo.sample_range_limit, cinfo.sample_range_limit_offset, table, offset + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE), CENTERJSAMPLE);
-}
-
-static void build_ycc_rgb_table (jpeg_decompress_struct cinfo) {
- jpeg_color_deconverter cconvert = cinfo.cconvert;
- int i;
- int x;
-// SHIFT_TEMPS
-
- cconvert.Cr_r_tab = new int[MAXJSAMPLE+1];
- cconvert.Cb_b_tab = new int[MAXJSAMPLE+1];
- cconvert.Cr_g_tab = new int[MAXJSAMPLE+1];
- cconvert.Cb_g_tab = new int[MAXJSAMPLE+1];
-
- for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
- /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
- /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
- /* Cr=>R value is nearest int to 1.40200 * x */
- cconvert.Cr_r_tab[i] = ((int)(1.40200f * (1<<SCALEBITS) + 0.5f) * x + ONE_HALF) >> SCALEBITS;
- /* Cb=>B value is nearest int to 1.77200 * x */
- cconvert.Cb_b_tab[i] = ((int)(1.77200f * (1<<SCALEBITS) + 0.5f) * x + ONE_HALF) >> SCALEBITS;
- /* Cr=>G value is scaled-up -0.71414 * x */
- cconvert.Cr_g_tab[i] = ((int)(- (0.71414f * (1<<SCALEBITS) + 0.5f)) * x);
- /* Cb=>G value is scaled-up -0.34414 * x */
- /* We also add in ONE_HALF so that need not do it in inner loop */
- cconvert.Cb_g_tab[i] = ((int)(- (0.34414f* (1<<SCALEBITS) + 0.5f)) * x + ONE_HALF);
- }
-}
-
-static void jinit_color_deconverter (jpeg_decompress_struct cinfo) {
- jpeg_color_deconverter cconvert = cinfo.cconvert = new jpeg_color_deconverter();
-// cconvert.start_pass = start_pass_dcolor;
-
- /* Make sure num_components agrees with jpeg_color_space */
- switch (cinfo.jpeg_color_space) {
- case JCS_GRAYSCALE:
- if (cinfo.num_components != 1)
- error();
-// ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
- break;
-
- case JCS_RGB:
- case JCS_YCbCr:
- if (cinfo.num_components != 3)
- error();
-// ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
- break;
-
- case JCS_CMYK:
- case JCS_YCCK:
- if (cinfo.num_components != 4)
- error();
-// ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
- break;
-
- default: /* JCS_UNKNOWN can be anything */
- if (cinfo.num_components < 1)
- error();
-// ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
- break;
- }
-
- /* Set out_color_components and conversion method based on requested space.
- * Also clear the component_needed flags for any unused components,
- * so that earlier pipeline stages can avoid useless computation.
- */
-
- int ci;
- switch (cinfo.out_color_space) {
- case JCS_GRAYSCALE:
- cinfo.out_color_components = 1;
- if (cinfo.jpeg_color_space == JCS_GRAYSCALE || cinfo.jpeg_color_space == JCS_YCbCr) {
- cconvert.color_convert = GRAYSCALE_CONVERT;
- /* For color.grayscale conversion, only the Y (0) component is needed */
- for (ci = 1; ci < cinfo.num_components; ci++)
- cinfo.comp_info[ci].component_needed = false;
- } else
- error();
-// ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
- break;
-
- case JCS_RGB:
- cinfo.out_color_components = RGB_PIXELSIZE;
- if (cinfo.jpeg_color_space == JCS_YCbCr) {
- cconvert.color_convert = YCC_RGB_CONVERT;
- build_ycc_rgb_table(cinfo);
- } else if (cinfo.jpeg_color_space == JCS_GRAYSCALE) {
- cconvert.color_convert = GRAY_RGB_CONVERT;
- } else if (cinfo.jpeg_color_space == JCS_RGB) {
- cconvert.color_convert = NULL_CONVERT;
- } else
- error();
-// ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
- break;
-
- case JCS_CMYK:
- cinfo.out_color_components = 4;
- if (cinfo.jpeg_color_space == JCS_YCCK) {
- cconvert.color_convert = YCCK_CMYK_CONVERT;
- build_ycc_rgb_table(cinfo);
- } else if (cinfo.jpeg_color_space == JCS_CMYK) {
- cconvert.color_convert = NULL_CONVERT;
- } else
- error();
-// ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
- break;
-
- default:
- /* Permit null conversion to same output space */
- if (cinfo.out_color_space == cinfo.jpeg_color_space) {
- cinfo.out_color_components = cinfo.num_components;
- cconvert.color_convert = NULL_CONVERT;
- } else /* unsupported non-null conversion */
- error();
-// ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
- break;
- }
-
- if (cinfo.quantize_colors)
- cinfo.output_components = 1; /* single colormapped output component */
- else
- cinfo.output_components = cinfo.out_color_components;
-}
-
-static void jinit_d_post_controller (jpeg_decompress_struct cinfo, boolean need_full_buffer) {
- jpeg_d_post_controller post = cinfo.post = new jpeg_d_post_controller();
-// post.pub.start_pass = start_pass_dpost;
- post.whole_image = null; /* flag for no virtual arrays */
- post.buffer = null; /* flag for no strip buffer */
-
- /* Create the quantization buffer, if needed */
- if (cinfo.quantize_colors) {
- error(SWT.ERROR_NOT_IMPLEMENTED);
-// /* The buffer strip height is max_v_samp_factor, which is typically
-// * an efficient number of rows for upsampling to return.
-// * (In the presence of output rescaling, we might want to be smarter?)
-// */
-// post.strip_height = cinfo.max_v_samp_factor;
-// if (need_full_buffer) {
-// /* Two-pass color quantization: need full-image storage. */
-// /* We round up the number of rows to a multiple of the strip height. */
-//#ifdef QUANT_2PASS_SUPPORTED
-// post.whole_image = (*cinfo.mem.request_virt_sarray)
-// ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
-// cinfo.output_width * cinfo.out_color_components,
-// (JDIMENSION) jround_up((long) cinfo.output_height,
-// (long) post.strip_height),
-// post.strip_height);
-//#else
-// ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
-//#endif /* QUANT_2PASS_SUPPORTED */
-// } else {
-// /* One-pass color quantization: just make a strip buffer. */
-// post.buffer = (*cinfo.mem.alloc_sarray)
-// ((j_common_ptr) cinfo, JPOOL_IMAGE,
-// cinfo.output_width * cinfo.out_color_components,
-// post.strip_height);
-// }
- }
-}
-
-static void make_funny_pointers (jpeg_decompress_struct cinfo)
-/* Create the funny pointer lists discussed in the comments above.
- * The actual workspace is already allocated (in main.buffer),
- * and the space for the pointer lists is allocated too.
- * This routine just fills in the curiously ordered lists.
- * This will be repeated at the beginning of each pass.
- */
-{
- jpeg_d_main_controller main = cinfo.main;
- int ci, i, rgroup;
- int M = cinfo.min_DCT_scaled_size;
- jpeg_component_info compptr;
- byte[][] buf, xbuf0, xbuf1;
-
- for (ci = 0; ci < cinfo.num_components; ci++) {
- compptr = cinfo.comp_info[ci];
- rgroup = (compptr.v_samp_factor * compptr.DCT_scaled_size) /
- cinfo.min_DCT_scaled_size; /* height of a row group of component */
- xbuf0 = main.xbuffer[0][ci];
- int xbuf0_offset = main.xbuffer_offset[0][ci];
- xbuf1 = main.xbuffer[1][ci];
- int xbuf1_offset = main.xbuffer_offset[1][ci];
- /* First copy the workspace pointers as-is */
- buf = main.buffer[ci];
- for (i = 0; i < rgroup * (M + 2); i++) {
- xbuf0[i + xbuf0_offset] = xbuf1[i + xbuf1_offset] = buf[i];
- }
- /* In the second list, put the last four row groups in swapped order */
- for (i = 0; i < rgroup * 2; i++) {
- xbuf1[rgroup*(M-2) + i + xbuf1_offset] = buf[rgroup*M + i];
- xbuf1[rgroup*M + i + xbuf1_offset] = buf[rgroup*(M-2) + i];
- }
- /* The wraparound pointers at top and bottom will be filled later
- * (see set_wraparound_pointers, below). Initially we want the "above"
- * pointers to duplicate the first actual data line. This only needs
- * to happen in xbuffer[0].
- */
- for (i = 0; i < rgroup; i++) {
- xbuf0[i - rgroup + xbuf0_offset] = xbuf0[0 + xbuf0_offset];
- }
- }
-}
-
-static void alloc_funny_pointers (jpeg_decompress_struct cinfo)
-/* Allocate space for the funny pointer lists.
- * This is done only once, not once per pass.
- */
-{
- jpeg_d_main_controller main = cinfo.main;
- int ci, rgroup;
- int M = cinfo.min_DCT_scaled_size;
- jpeg_component_info compptr;
- byte[][] xbuf;
-
- /* Get top-level space for component array pointers.
- * We alloc both arrays with one call to save a few cycles.
- */
- main.xbuffer[0] = new byte[cinfo.num_components][][];
- main.xbuffer[1] = new byte[cinfo.num_components][][];
- main.xbuffer_offset[0] = new int[cinfo.num_components];
- main.xbuffer_offset[1] = new int[cinfo.num_components];
-
- for (ci = 0; ci < cinfo.num_components; ci++) {
- compptr = cinfo.comp_info[ci];
- rgroup = (compptr.v_samp_factor * compptr.DCT_scaled_size) / cinfo.min_DCT_scaled_size; /* height of a row group of component */
- /* Get space for pointer lists --- M+4 row groups in each list.
- * We alloc both pointer lists with one call to save a few cycles.
- */
- xbuf = new byte[2 * (rgroup * (M + 4))][];
- int offset = rgroup;
- main.xbuffer_offset[0][ci] = offset;
- main.xbuffer[0][ci] = xbuf;
- offset += rgroup * (M + 4);
- main.xbuffer_offset[1][ci] = offset;
- main.xbuffer[1][ci] = xbuf;
- }
-}
-
-
-static void jinit_d_main_controller (jpeg_decompress_struct cinfo, boolean need_full_buffer) {
- int ci, rgroup, ngroups;
- jpeg_component_info compptr;
-
- jpeg_d_main_controller main = cinfo.main = new jpeg_d_main_controller();
-// main.pub.start_pass = start_pass_main;
-
- if (need_full_buffer) /* shouldn't happen */
- error();
-// ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
-
- /* Allocate the workspace.
- * ngroups is the number of row groups we need.
- */
- if (cinfo.upsample.need_context_rows) {
- if (cinfo.min_DCT_scaled_size < 2) /* unsupported, see comments above */
- error();
-// ERREXIT(cinfo, JERR_NOTIMPL);
- alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
- ngroups = cinfo.min_DCT_scaled_size + 2;
- } else {
- ngroups = cinfo.min_DCT_scaled_size;
- }
-
- for (ci = 0; ci < cinfo.num_components; ci++) {
- compptr = cinfo.comp_info[ci];
- rgroup = (compptr.v_samp_factor * compptr.DCT_scaled_size) / cinfo.min_DCT_scaled_size; /* height of a row group of component */
- main.buffer[ci] = new byte[rgroup * ngroups][compptr.width_in_blocks * compptr.DCT_scaled_size];
- }
-}
-
-static long jround_up (long a, long b)
-/* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */
-/* Assumes a >= 0, b > 0 */
-{
- a += b - 1L;
- return a - (a % b);
-}
-
-static void jinit_upsampler (jpeg_decompress_struct cinfo) {
- int ci;
- jpeg_component_info compptr;
- boolean need_buffer, do_fancy;
- int h_in_group, v_in_group, h_out_group, v_out_group;
-
- jpeg_upsampler upsample = new jpeg_upsampler();
- cinfo.upsample = upsample;
-// upsample.start_pass = start_pass_upsample;
-// upsample.upsample = sep_upsample;
- upsample.need_context_rows = false; /* until we find out differently */
-
- if (cinfo.CCIR601_sampling) /* this isn't supported */
- error();
-// ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
-
- /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
- * so don't ask for it.
- */
- do_fancy = cinfo.do_fancy_upsampling && cinfo.min_DCT_scaled_size > 1;
-
- /* Verify we can handle the sampling factors, select per-component methods,
- * and create storage as needed.
- */
- for (ci = 0; ci < cinfo.num_components; ci++) {
- compptr = cinfo.comp_info[ci];
- /* Compute size of an "input group" after IDCT scaling. This many samples
- * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
- */
- h_in_group = (compptr.h_samp_factor * compptr.DCT_scaled_size) /
- cinfo.min_DCT_scaled_size;
- v_in_group = (compptr.v_samp_factor * compptr.DCT_scaled_size) /
- cinfo.min_DCT_scaled_size;
- h_out_group = cinfo.max_h_samp_factor;
- v_out_group = cinfo.max_v_samp_factor;
- upsample.rowgroup_height[ci] = v_in_group; /* save for use later */
- need_buffer = true;
- if (! compptr.component_needed) {
- /* Don't bother to upsample an uninteresting component. */
- upsample.methods[ci] = NOOP_UPSAMPLE;
- need_buffer = false;
- } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
- /* Fullsize components can be processed without any work. */
- upsample.methods[ci] = FULLSIZE_UPSAMPLE;
- need_buffer = false;
- } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
- /* Special cases for 2h1v upsampling */
- if (do_fancy && compptr.downsampled_width > 2)
- upsample.methods[ci] = H2V1_FANCY_UPSAMPLE;
- else
- upsample.methods[ci] = H2V1_UPSAMPLE;
- } else if (h_in_group * 2 == h_out_group && v_in_group * 2 == v_out_group) {
- /* Special cases for 2h2v upsampling */
- if (do_fancy && compptr.downsampled_width > 2) {
- upsample.methods[ci] = H2V2_FANCY_UPSAMPLE;
- upsample.need_context_rows = true;
- } else
- upsample.methods[ci] = H2V2_UPSAMPLE;
- } else if ((h_out_group % h_in_group) == 0 && (v_out_group % v_in_group) == 0) {
- /* Generic integral-factors upsampling method */
- upsample.methods[ci] = INT_UPSAMPLE;
- upsample.h_expand[ci] = (byte) (h_out_group / h_in_group);
- upsample.v_expand[ci] = (byte) (v_out_group / v_in_group);
- } else
- error();
-// ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
- if (need_buffer) {
- upsample.color_buf[ci] = new byte[cinfo.max_v_samp_factor]
- [(int) jround_up(cinfo.output_width, cinfo.max_h_samp_factor)];
- }
- }
-}
-
-static void jinit_phuff_decoder (jpeg_decompress_struct cinfo) {
- int[][] coef_bit_ptr;
- int ci, i;
-
- cinfo.entropy = new phuff_entropy_decoder();
-// entropy.pub.start_pass = start_pass_phuff_decoder;
-
- /* Create progression status table */
- cinfo.coef_bits = new int[cinfo.num_components][DCTSIZE2];
- coef_bit_ptr = cinfo.coef_bits;
- for (ci = 0; ci < cinfo.num_components; ci++)
- for (i = 0; i < DCTSIZE2; i++)
- coef_bit_ptr[ci][i] = -1;
-}
-
-
-static void jinit_huff_decoder (jpeg_decompress_struct cinfo) {
-
- cinfo.entropy = new huff_entropy_decoder();
-// entropy.pub.start_pass = start_pass_huff_decoder;
-// entropy.pub.decode_mcu = decode_mcu;
-
-}
-
-static void jinit_inverse_dct (jpeg_decompress_struct cinfo) {
- int ci;
- jpeg_component_info compptr;
-
- jpeg_inverse_dct idct = cinfo.idct = new jpeg_inverse_dct();
-// idct.pub.start_pass = start_pass;
-
- for (ci = 0; ci < cinfo.num_components; ci++) {
- compptr = cinfo.comp_info[ci];
- /* Allocate and pre-zero a multiplier table for each component */
- compptr.dct_table = new int[DCTSIZE2];
- /* Mark multiplier table not yet set up for any method */
- idct.cur_method[ci] = -1;
- }
-}
-
-static final int CONST_BITS = 13;
-static final int PASS1_BITS = 2;
-static final int RANGE_MASK =(MAXJSAMPLE * 4 + 3);
-static void jpeg_idct_islow (jpeg_decompress_struct cinfo, jpeg_component_info compptr,
- short[] coef_block,
- byte[][] output_buf, int output_buf_offset, int output_col)
-{
- int tmp0, tmp1, tmp2, tmp3;
- int tmp10, tmp11, tmp12, tmp13;
- int z1, z2, z3, z4, z5;
- short[] inptr;
- int[] quantptr;
- int[] wsptr;
- byte[] outptr;
- byte[] range_limit = cinfo.sample_range_limit;
- int range_limit_offset = cinfo.sample_range_limit_offset + CENTERJSAMPLE;
- int ctr;
- int[] workspace = cinfo.workspace; /* buffers data between passes */
-// SHIFT_TEMPS
-
- /* Pass 1: process columns from input, store into work array. */
- /* Note results are scaled up by sqrt(8) compared to a true IDCT; */
- /* furthermore, we scale the results by 2**PASS1_BITS. */
-
- inptr = coef_block;
- quantptr = compptr.dct_table;
- wsptr = workspace;
- int inptr_offset = 0, quantptr_offset = 0, wsptr_offset = 0;
- for (ctr = DCTSIZE; ctr > 0; ctr--) {
- /* Due to quantization, we will usually find that many of the input
- * coefficients are zero, especially the AC terms. We can exploit this
- * by short-circuiting the IDCT calculation for any column in which all
- * the AC terms are zero. In that case each output is equal to the
- * DC coefficient (with scale factor as needed).
- * With typical images and quantization tables, half or more of the
- * column DCT calculations can be simplified this way.
- */
-
- if (inptr[DCTSIZE*1+inptr_offset] == 0 && inptr[DCTSIZE*2+inptr_offset] == 0 &&
- inptr[DCTSIZE*3+inptr_offset] == 0 && inptr[DCTSIZE*4+inptr_offset] == 0 &&
- inptr[DCTSIZE*5+inptr_offset] == 0 && inptr[DCTSIZE*6+inptr_offset] == 0 &&
- inptr[DCTSIZE*7+inptr_offset] == 0)
- {
- /* AC terms all zero */
- int dcval = ((inptr[DCTSIZE*0+inptr_offset]) * quantptr[DCTSIZE*0+quantptr_offset]) << PASS1_BITS;
-
- wsptr[DCTSIZE*0+wsptr_offset] = dcval;
- wsptr[DCTSIZE*1+wsptr_offset] = dcval;
- wsptr[DCTSIZE*2+wsptr_offset] = dcval;
- wsptr[DCTSIZE*3+wsptr_offset] = dcval;
- wsptr[DCTSIZE*4+wsptr_offset] = dcval;
- wsptr[DCTSIZE*5+wsptr_offset] = dcval;
- wsptr[DCTSIZE*6+wsptr_offset] = dcval;
- wsptr[DCTSIZE*7+wsptr_offset] = dcval;
-
- inptr_offset++; /* advance pointers to next column */
- quantptr_offset++;
- wsptr_offset++;
- continue;
- }
-
- /* Even part: reverse the even part of the forward DCT. */
- /* The rotator is sqrt(2)*c(-6). */
-
- z2 = ((inptr[DCTSIZE*2+inptr_offset]) * quantptr[DCTSIZE*2+quantptr_offset]);
- z3 = ((inptr[DCTSIZE*6+inptr_offset]) * quantptr[DCTSIZE*6+quantptr_offset]);
-
- z1 = ((z2 + z3) * 4433/*FIX_0_541196100*/);
- tmp2 = z1 + (z3 * - 15137/*FIX_1_847759065*/);
- tmp3 = z1 + (z2 * 6270/*FIX_0_765366865*/);
-
- z2 = ((inptr[DCTSIZE*0+inptr_offset]) * quantptr[DCTSIZE*0+quantptr_offset]);
- z3 = ((inptr[DCTSIZE*4+inptr_offset]) * quantptr[DCTSIZE*4+quantptr_offset]);
-
- tmp0 = (z2 + z3) << CONST_BITS;
- tmp1 = (z2 - z3) << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp1 + tmp2;
- tmp12 = tmp1 - tmp2;
-
- /* Odd part per figure 8; the matrix is unitary and hence its
- * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
- */
-
- tmp0 = ((inptr[DCTSIZE*7+inptr_offset]) * quantptr[DCTSIZE*7+quantptr_offset]);
- tmp1 = ((inptr[DCTSIZE*5+inptr_offset]) * quantptr[DCTSIZE*5+quantptr_offset]);
- tmp2 = ((inptr[DCTSIZE*3+inptr_offset]) * quantptr[DCTSIZE*3+quantptr_offset]);
- tmp3 = ((inptr[DCTSIZE*1+inptr_offset]) * quantptr[DCTSIZE*1+quantptr_offset]);
-
- z1 = tmp0 + tmp3;
- z2 = tmp1 + tmp2;
- z3 = tmp0 + tmp2;
- z4 = tmp1 + tmp3;
- z5 = ((z3 + z4) * 9633/*FIX_1_175875602*/); /* sqrt(2) * c3 */
-
- tmp0 = (tmp0 * 2446/*FIX_0_298631336*/); /* sqrt(2) * (-c1+c3+c5-c7) */
- tmp1 = (tmp1 * 16819/*FIX_2_053119869*/); /* sqrt(2) * ( c1+c3-c5+c7) */
- tmp2 = (tmp2 * 25172/*FIX_3_072711026*/); /* sqrt(2) * ( c1+c3+c5-c7) */
- tmp3 = (tmp3 * 12299/*FIX_1_501321110*/); /* sqrt(2) * ( c1+c3-c5-c7) */
- z1 = (z1 * - 7373/*FIX_0_899976223*/); /* sqrt(2) * (c7-c3) */
- z2 = (z2 * - 20995/*FIX_2_562915447*/); /* sqrt(2) * (-c1-c3) */
- z3 = (z3 * - 16069/*FIX_1_961570560*/); /* sqrt(2) * (-c3-c5) */
- z4 = (z4 * - 3196/*FIX_0_390180644*/); /* sqrt(2) * (c5-c3) */
-
- z3 += z5;
- z4 += z5;
-
- tmp0 += z1 + z3;
- tmp1 += z2 + z4;
- tmp2 += z2 + z3;
- tmp3 += z1 + z4;
-
- /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
-
-// #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
- wsptr[DCTSIZE*0+wsptr_offset] = (((tmp10 + tmp3) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS));
- wsptr[DCTSIZE*7+wsptr_offset] = (((tmp10 - tmp3) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS));
- wsptr[DCTSIZE*1+wsptr_offset] = (((tmp11 + tmp2) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS));
- wsptr[DCTSIZE*6+wsptr_offset] = (((tmp11 - tmp2) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS));
- wsptr[DCTSIZE*2+wsptr_offset] = (((tmp12 + tmp1) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS));
- wsptr[DCTSIZE*5+wsptr_offset] = (((tmp12 - tmp1) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS));
- wsptr[DCTSIZE*3+wsptr_offset] = (((tmp13 + tmp0) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS));
- wsptr[DCTSIZE*4+wsptr_offset] = (((tmp13 - tmp0) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS));
-
- inptr_offset++; /* advance pointers to next column */
- quantptr_offset++;
- wsptr_offset++;
- }
-
-
- /* Pass 2: process rows from work array, store into output array. */
- /* Note that we must descale the results by a factor of 8 == 2**3, */
- /* and also undo the PASS1_BITS scaling. */
-
- int outptr_offset = 0;
- wsptr = workspace;
- wsptr_offset =0;
- for (ctr = 0; ctr < DCTSIZE; ctr++) {
- outptr = output_buf[ctr+output_buf_offset];
- outptr_offset = output_col;
- /* Rows of zeroes can be exploited in the same way as we did with columns.
- * However, the column calculation has created many nonzero AC terms, so
- * the simplification applies less often (typically 5% to 10% of the time).
- * On machines with very fast multiplication, it's possible that the
- * test takes more time than it's worth. In that case this section
- * may be commented out.
- */
-
-//#ifndef NO_ZERO_ROW_TEST
- if (wsptr[1+wsptr_offset] == 0 && wsptr[2+wsptr_offset] == 0 && wsptr[3+wsptr_offset] == 0 && wsptr[4+wsptr_offset] == 0 &&
- wsptr[5+wsptr_offset] == 0 && wsptr[6+wsptr_offset] == 0 && wsptr[7+wsptr_offset] == 0)
- {
- /* AC terms all zero */
-// #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
- byte dcval = range_limit[range_limit_offset + ((((wsptr[0+wsptr_offset]) + (1 << ((PASS1_BITS+3)-1))) >> PASS1_BITS+3)
- & RANGE_MASK)];
-
- outptr[0+outptr_offset] = dcval;
- outptr[1+outptr_offset] = dcval;
- outptr[2+outptr_offset] = dcval;
- outptr[3+outptr_offset] = dcval;
- outptr[4+outptr_offset] = dcval;
- outptr[5+outptr_offset] = dcval;
- outptr[6+outptr_offset] = dcval;
- outptr[7+outptr_offset] = dcval;
-
- wsptr_offset += DCTSIZE; /* advance pointer to next row */
- continue;
- }
-//#endif
-
- /* Even part: reverse the even part of the forward DCT. */
- /* The rotator is sqrt(2)*c(-6). */
-
- z2 = wsptr[2+wsptr_offset];
- z3 = wsptr[6+wsptr_offset];
-
- z1 = ((z2 + z3) * 4433/*FIX_0_541196100*/);
- tmp2 = z1 + (z3 * - 15137/*FIX_1_847759065*/);
- tmp3 = z1 + (z2 * 6270/*FIX_0_765366865*/);
-
- tmp0 = (wsptr[0+wsptr_offset] + wsptr[4+wsptr_offset]) << CONST_BITS;
- tmp1 = (wsptr[0+wsptr_offset] - wsptr[4+wsptr_offset]) << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp1 + tmp2;
- tmp12 = tmp1 - tmp2;
-
- /* Odd part per figure 8; the matrix is unitary and hence its
- * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
- */
-
- tmp0 = wsptr[7+wsptr_offset];
- tmp1 = wsptr[5+wsptr_offset];
- tmp2 = wsptr[3+wsptr_offset];
- tmp3 = wsptr[1+wsptr_offset];
-
- z1 = tmp0 + tmp3;
- z2 = tmp1 + tmp2;
- z3 = tmp0 + tmp2;
- z4 = tmp1 + tmp3;
- z5 = ((z3 + z4) * 9633/*FIX_1_175875602*/); /* sqrt(2) * c3 */
-
- tmp0 = (tmp0 * 2446/*FIX_0_298631336*/); /* sqrt(2) * (-c1+c3+c5-c7) */
- tmp1 = (tmp1 * 16819/*FIX_2_053119869*/); /* sqrt(2) * ( c1+c3-c5+c7) */
- tmp2 = (tmp2 * 25172/*FIX_3_072711026*/); /* sqrt(2) * ( c1+c3+c5-c7) */
- tmp3 = (tmp3 * 12299/*FIX_1_501321110*/); /* sqrt(2) * ( c1+c3-c5-c7) */
- z1 = (z1 * - 7373/*FIX_0_899976223*/); /* sqrt(2) * (c7-c3) */
- z2 = (z2 * - 20995/*FIX_2_562915447*/); /* sqrt(2) * (-c1-c3) */
- z3 = (z3 * - 16069/*FIX_1_961570560*/); /* sqrt(2) * (-c3-c5) */
- z4 = (z4 * - 3196/*FIX_0_390180644*/); /* sqrt(2) * (c5-c3) */
-
- z3 += z5;
- z4 += z5;
-
- tmp0 += z1 + z3;
- tmp1 += z2 + z4;
- tmp2 += z2 + z3;
- tmp3 += z1 + z4;
-
- /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
-
-
-// #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
- outptr[0+outptr_offset] = range_limit[range_limit_offset + ((((tmp10 + tmp3) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >>
- CONST_BITS+PASS1_BITS+3)
- & RANGE_MASK)];
- outptr[7+outptr_offset] = range_limit[range_limit_offset + ((((tmp10 - tmp3) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >>
- CONST_BITS+PASS1_BITS+3)
- & RANGE_MASK)];
- outptr[1+outptr_offset] = range_limit[range_limit_offset + ((((tmp11 + tmp2) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >>
- CONST_BITS+PASS1_BITS+3)
- & RANGE_MASK)];
- outptr[6+outptr_offset] = range_limit[range_limit_offset + ((((tmp11 - tmp2) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >>
- CONST_BITS+PASS1_BITS+3)
- & RANGE_MASK)];
- outptr[2+outptr_offset] = range_limit[range_limit_offset + ((((tmp12 + tmp1) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >>
- CONST_BITS+PASS1_BITS+3)
- & RANGE_MASK)];
- outptr[5+outptr_offset] = range_limit[range_limit_offset + ((((tmp12 - tmp1) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >>
- CONST_BITS+PASS1_BITS+3)
- & RANGE_MASK)];
- outptr[3+outptr_offset] = range_limit[range_limit_offset + ((((tmp13 + tmp0) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >>
- CONST_BITS+PASS1_BITS+3)
- & RANGE_MASK)];
- outptr[4+outptr_offset] = range_limit[range_limit_offset + ((((tmp13 - tmp0) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >>
- CONST_BITS+PASS1_BITS+3)
- & RANGE_MASK)];
-
- wsptr_offset += DCTSIZE; /* advance pointer to next row */
- }
-}
-
-static void upsample (jpeg_decompress_struct cinfo,
- byte[][][] input_buf, int[] input_buf_offset, int[] in_row_group_ctr,
- int in_row_groups_avail,
- byte[][] output_buf, int[] out_row_ctr,
- int out_rows_avail)
-{
- sep_upsample(cinfo, input_buf, input_buf_offset, in_row_group_ctr, in_row_groups_avail, output_buf, out_row_ctr, out_rows_avail);
-}
-
-static boolean smoothing_ok (jpeg_decompress_struct cinfo) {
- jpeg_d_coef_controller coef = cinfo.coef;
- boolean smoothing_useful = false;
- int ci, coefi;
- jpeg_component_info compptr;
- JQUANT_TBL qtable;
- int[] coef_bits;
- int[] coef_bits_latch;
-
- if (! cinfo.progressive_mode || cinfo.coef_bits == null)
- return false;
-
- /* Allocate latch area if not already done */
- if (coef.coef_bits_latch == null)
- coef.coef_bits_latch = new int[cinfo.num_components * SAVED_COEFS];
- coef_bits_latch = coef.coef_bits_latch;
- int coef_bits_latch_offset = 0;
-
- for (ci = 0; ci < cinfo.num_components; ci++) {
- compptr = cinfo.comp_info[ci];
- /* All components' quantization values must already be latched. */
- if ((qtable = compptr.quant_table) == null)
- return false;
- /* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */
- if (qtable.quantval[0] == 0 ||
- qtable.quantval[Q01_POS] == 0 ||
- qtable.quantval[Q10_POS] == 0 ||
- qtable.quantval[Q20_POS] == 0 ||
- qtable.quantval[Q11_POS] == 0 ||
- qtable.quantval[Q02_POS] == 0)
- return false;
- /* DC values must be at least partly known for all components. */
- coef_bits = cinfo.coef_bits[ci];
- if (coef_bits[0] < 0)
- return false;
- /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
- for (coefi = 1; coefi <= 5; coefi++) {
- coef_bits_latch[coefi+coef_bits_latch_offset] = coef_bits[coefi];
- if (coef_bits[coefi] != 0)
- smoothing_useful = true;
- }
- coef_bits_latch_offset += SAVED_COEFS;
- }
-
- return smoothing_useful;
-}
-
-static void master_selection (jpeg_decompress_struct cinfo) {
- jpeg_decomp_master master = cinfo.master;
- boolean use_c_buffer;
- long samplesperrow;
- int jd_samplesperrow;
-
- /* Initialize dimensions and other stuff */
- jpeg_calc_output_dimensions(cinfo);
- prepare_range_limit_table(cinfo);
-
- /* Width of an output scanline must be representable as JDIMENSION. */
- samplesperrow = (long) cinfo.output_width * (long) cinfo.out_color_components;
- jd_samplesperrow = (int) samplesperrow;
- if ( jd_samplesperrow != samplesperrow)
- error();
-// ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
-
- /* Initialize my private state */
- master.pass_number = 0;
- master.using_merged_upsample = use_merged_upsample(cinfo);
-
- /* Color quantizer selection */
- master.quantizer_1pass = null;
- master.quantizer_2pass = null;
- /* No mode changes if not using buffered-image mode. */
- if (! cinfo.quantize_colors || ! cinfo.buffered_image) {
- cinfo.enable_1pass_quant = false;
- cinfo.enable_external_quant = false;
- cinfo.enable_2pass_quant = false;
- }
- if (cinfo.quantize_colors) {
- error(SWT.ERROR_NOT_IMPLEMENTED);
-// if (cinfo.raw_data_out)
-// ERREXIT(cinfo, JERR_NOTIMPL);
-// /* 2-pass quantizer only works in 3-component color space. */
-// if (cinfo.out_color_components != 3) {
-// cinfo.enable_1pass_quant = true;
-// cinfo.enable_external_quant = false;
-// cinfo.enable_2pass_quant = false;
-// cinfo.colormap = null;
-// } else if (cinfo.colormap != null) {
-// cinfo.enable_external_quant = true;
-// } else if (cinfo.two_pass_quantize) {
-// cinfo.enable_2pass_quant = true;
-// } else {
-// cinfo.enable_1pass_quant = true;
-// }
-//
-// if (cinfo.enable_1pass_quant) {
-//#ifdef QUANT_1PASS_SUPPORTED
-// jinit_1pass_quantizer(cinfo);
-// master.quantizer_1pass = cinfo.cquantize;
-//#else
-// ERREXIT(cinfo, JERR_NOT_COMPILED);
-//#endif
-// }
-//
-// /* We use the 2-pass code to map to external colormaps. */
-// if (cinfo.enable_2pass_quant || cinfo.enable_external_quant) {
-//#ifdef QUANT_2PASS_SUPPORTED
-// jinit_2pass_quantizer(cinfo);
-// master.quantizer_2pass = cinfo.cquantize;
-//#else
-// ERREXIT(cinfo, JERR_NOT_COMPILED);
-//#endif
-// }
-// /* If both quantizers are initialized, the 2-pass one is left active;
-// * this is necessary for starting with quantization to an external map.
-// */
- }
-
- /* Post-processing: in particular, color conversion first */
- if (! cinfo.raw_data_out) {
- if (master.using_merged_upsample) {
-//#ifdef UPSAMPLE_MERGING_SUPPORTED
-// jinit_merged_upsampler(cinfo); /* does color conversion too */
-//#else
- error();
-// ERREXIT(cinfo, JERR_NOT_COMPILED);
-//#endif
- } else {
- jinit_color_deconverter(cinfo);
- jinit_upsampler(cinfo);
- }
- jinit_d_post_controller(cinfo, cinfo.enable_2pass_quant);
- }
- /* Inverse DCT */
- jinit_inverse_dct(cinfo);
- /* Entropy decoding: either Huffman or arithmetic coding. */
- if (cinfo.arith_code) {
- error();
-// ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
- } else {
- if (cinfo.progressive_mode) {
-//#ifdef D_PROGRESSIVE_SUPPORTED
- jinit_phuff_decoder(cinfo);
-//#else
-// ERREXIT(cinfo, JERR_NOT_COMPILED);
-//#endif
- } else
- jinit_huff_decoder(cinfo);
- }
-
- /* Initialize principal buffer controllers. */
- use_c_buffer = cinfo.inputctl.has_multiple_scans || cinfo.buffered_image;
- jinit_d_coef_controller(cinfo, use_c_buffer);
-
- if (! cinfo.raw_data_out)
- jinit_d_main_controller(cinfo, false /* never need full buffer here */);
-
- /* Initialize input side of decompressor to consume first scan. */
- start_input_pass (cinfo);
-
-//#ifdef D_MULTISCAN_FILES_SUPPORTED
- /* If jpeg_start_decompress will read the whole file, initialize
- * progress monitoring appropriately. The input step is counted
- * as one pass.
- */
-// if (cinfo.progress != null && ! cinfo.buffered_image &&
-// cinfo.inputctl.has_multiple_scans) {
-// int nscans;
-// /* Estimate number of scans to set pass_limit. */
-// if (cinfo.progressive_mode) {
-// /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */
-// nscans = 2 + 3 * cinfo.num_components;
-// } else {
-// /* For a nonprogressive multiscan file, estimate 1 scan per component. */
-// nscans = cinfo.num_components;
-// }
-// cinfo.progress.pass_counter = 0L;
-// cinfo.progress.pass_limit = (long) cinfo.total_iMCU_rows * nscans;
-// cinfo.progress.completed_passes = 0;
-// cinfo.progress.total_passes = (cinfo.enable_2pass_quant ? 3 : 2);
-// /* Count the input pass as done */
-// master.pass_number++;
-// }
-//#endif /* D_MULTISCAN_FILES_SUPPORTED */
-}
-
-static void jinit_master_decompress (jpeg_decompress_struct cinfo) {
- jpeg_decomp_master master = new jpeg_decomp_master();
- cinfo.master = master;
-// master.prepare_for_output_pass = prepare_for_output_pass;
-// master.finish_output_pass = finish_output_pass;
-
- master.is_dummy_pass = false;
-
- master_selection(cinfo);
-}
-
-static void
-jcopy_sample_rows (byte[][] input_array, int source_row,
- byte[][] output_array, int dest_row,
- int num_rows, int num_cols)
-/* Copy some rows of samples from one place to another.
- * num_rows rows are copied from input_array[source_row++]
- * to output_array[dest_row++]; these areas may overlap for duplication.
- * The source and destination arrays must be at least as wide as num_cols.
- */
-{
- byte[] inptr, outptr;
- int count = num_cols;
- int row;
-
- int input_array_offset = source_row;
- int output_array_offset = dest_row;
-
- for (row = num_rows; row > 0; row--) {
- inptr = input_array[input_array_offset++];
- outptr = output_array[output_array_offset++];
- System.arraycopy(inptr, 0, outptr, 0, count);
- }
-}
-
-static boolean jpeg_start_decompress (jpeg_decompress_struct cinfo) {
- if (cinfo.global_state == DSTATE_READY) {
- /* First call: initialize master control, select active modules */
- jinit_master_decompress(cinfo);
- if (cinfo.buffered_image) {
- /* No more work here; expecting jpeg_start_output next */
- cinfo.global_state = DSTATE_BUFIMAGE;
- return true;
- }
- cinfo.global_state = DSTATE_PRELOAD;
- }
- if (cinfo.global_state == DSTATE_PRELOAD) {
- /* If file has multiple scans, absorb them all into the coef buffer */
- if (cinfo.inputctl.has_multiple_scans) {
-//#ifdef D_MULTISCAN_FILES_SUPPORTED
- for (;;) {
- int retcode;
- /* Call progress monitor hook if present */
-// if (cinfo.progress != null)
-// (*cinfo.progress.progress_monitor) ((j_common_ptr) cinfo);
- /* Absorb some more input */
- retcode = consume_input (cinfo);
- if (retcode == JPEG_SUSPENDED)
- return false;
- if (retcode == JPEG_REACHED_EOI)
- break;
- /* Advance progress counter if appropriate */
-// if (cinfo.progress != null && (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
-// if (++cinfo.progress.pass_counter >= cinfo.progress.pass_limit) {
-// /* jdmaster underestimated number of scans; ratchet up one scan */
-// cinfo.progress.pass_limit += (long) cinfo.total_iMCU_rows;
-// }
-// }
- }
-//#else
-// ERREXIT(cinfo, JERR_NOT_COMPILED);
-//#endif /* D_MULTISCAN_FILES_SUPPORTED */
- }
- cinfo.output_scan_number = cinfo.input_scan_number;
- } else if (cinfo.global_state != DSTATE_PRESCAN)
- error();
-// ERREXIT1(cinfo, JERR_BAD_STATE, cinfo.global_state);
- /* Perform any dummy output passes, and set up for the final pass */
- return output_pass_setup(cinfo);
-}
-
-static void prepare_for_output_pass (jpeg_decompress_struct cinfo) {
- jpeg_decomp_master master = cinfo.master;
-
- if (master.is_dummy_pass) {
-//#ifdef QUANT_2PASS_SUPPORTED
-// /* Final pass of 2-pass quantization */
-// master.pub.is_dummy_pass = FALSE;
-// (*cinfo.cquantize.start_pass) (cinfo, FALSE);
-// (*cinfo.post.start_pass) (cinfo, JBUF_CRANK_DEST);
-// (*cinfo.main.start_pass) (cinfo, JBUF_CRANK_DEST);
-//#else
- error(SWT.ERROR_NOT_IMPLEMENTED);
-// ERREXIT(cinfo, JERR_NOT_COMPILED);
-//#endif /* QUANT_2PASS_SUPPORTED */
- } else {
- if (cinfo.quantize_colors && cinfo.colormap == null) {
- /* Select new quantization method */
- if (cinfo.two_pass_quantize && cinfo.enable_2pass_quant) {
- cinfo.cquantize = master.quantizer_2pass;
- master.is_dummy_pass = true;
- } else if (cinfo.enable_1pass_quant) {
- cinfo.cquantize = master.quantizer_1pass;
- } else {
- error();
-// ERREXIT(cinfo, JERR_MODE_CHANGE);
- }
- }
- cinfo.idct.start_pass (cinfo);
- start_output_pass (cinfo);
- if (! cinfo.raw_data_out) {
- if (! master.using_merged_upsample)
- cinfo.cconvert.start_pass (cinfo);
- cinfo.upsample.start_pass (cinfo);
- if (cinfo.quantize_colors)
- cinfo.cquantize.start_pass (cinfo, master.is_dummy_pass);
- cinfo.post.start_pass (cinfo, (master.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
- cinfo.main.start_pass (cinfo, JBUF_PASS_THRU);
- }
- }
-
-// /* Set up progress monitor's pass info if present */
-// if (cinfo.progress != NULL) {
-// cinfo.progress.completed_passes = master.pass_number;
-// cinfo.progress.total_passes = master.pass_number +
-// (master.pub.is_dummy_pass ? 2 : 1);
-// /* In buffered-image mode, we assume one more output pass if EOI not
-// * yet reached, but no more passes if EOI has been reached.
-// */
-// if (cinfo.buffered_image && ! cinfo.inputctl.eoi_reached) {
-// cinfo.progress.total_passes += (cinfo.enable_2pass_quant ? 2 : 1);
-// }
-// }
-}
-
-
-static boolean jpeg_resync_to_restart (jpeg_decompress_struct cinfo, int desired) {
- int marker = cinfo.unread_marker;
- int action = 1;
-
- /* Always put up a warning. */
-// WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
-
- /* Outer loop handles repeated decision after scanning forward. */
- for (;;) {
- if (marker < M_SOF0)
- action = 2; /* invalid marker */
- else if (marker < M_RST0 || marker > M_RST7)
- action = 3; /* valid non-restart marker */
- else {
- if (marker == (M_RST0 + ((desired+1) & 7)) || marker == ( M_RST0 + ((desired+2) & 7)))
- action = 3; /* one of the next two expected restarts */
- else if (marker == (M_RST0 + ((desired-1) & 7)) || marker == ( M_RST0 + ((desired-2) & 7)))
- action = 2; /* a prior restart, so advance */
- else
- action = 1; /* desired restart or too far away */
- }
-// TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
- switch (action) {
- case 1:
- /* Discard marker and let entropy decoder resume processing. */
- cinfo.unread_marker = 0;
- return true;
- case 2:
- /* Scan to the next marker, and repeat the decision loop. */
- if (! next_marker(cinfo))
- return false;
- marker = cinfo.unread_marker;
- break;
- case 3:
- /* Return without advancing past this marker. */
- /* Entropy decoder will be forced to process an empty segment. */
- return true;
- }
- } /* end loop */
-}
-
-static boolean read_restart_marker (jpeg_decompress_struct cinfo) {
- /* Obtain a marker unless we already did. */
- /* Note that next_marker will complain if it skips any data. */
- if (cinfo.unread_marker == 0) {
- if (! next_marker(cinfo))
- return false;
- }
-
- if (cinfo.unread_marker == (M_RST0 + cinfo.marker.next_restart_num)) {
- /* Normal case --- swallow the marker and let entropy decoder continue */
-// TRACEMS1(cinfo, 3, JTRC_RST, cinfo.marker.next_restart_num);
- cinfo.unread_marker = 0;
- } else {
- /* Uh-oh, the restart markers have been messed up. */
- /* Let the data source manager determine how to resync. */
- if (! jpeg_resync_to_restart (cinfo, cinfo.marker.next_restart_num))
- return false;
- }
-
- /* Update next-restart state */
- cinfo.marker.next_restart_num = (cinfo.marker.next_restart_num + 1) & 7;
-
- return true;
-}
-
-static boolean jpeg_fill_bit_buffer (bitread_working_state state, int get_buffer, int bits_left, int nbits)
-/* Load up the bit buffer to a depth of at least nbits */
-{
- /* Copy heavily used state fields into locals (hopefully registers) */
- byte[] buffer = state.buffer;
- int bytes_in_buffer = state.bytes_in_buffer;
- int bytes_offset = state.bytes_offset;
- jpeg_decompress_struct cinfo = state.cinfo;
-
- /* Attempt to load at least MIN_GET_BITS bits into get_buffer. */
- /* (It is assumed that no request will be for more than that many bits.) */
- /* We fail to do so only if we hit a marker or are forced to suspend. */
-
- if (cinfo.unread_marker == 0) { /* cannot advance past a marker */
- while (bits_left < MIN_GET_BITS) {
- int c;
-
- /* Attempt to read a byte */
- if (bytes_offset == bytes_in_buffer) {
- if (! fill_input_buffer (cinfo))
- return false;
- buffer = cinfo.buffer;
- bytes_in_buffer = cinfo.bytes_in_buffer;
- bytes_offset = cinfo.bytes_offset;
- }
- c = buffer[bytes_offset++] & 0xFF;
-
- /* If it's 0xFF, check and discard stuffed zero byte */
- if (c == 0xFF) {
- /* Loop here to discard any padding FF's on terminating marker,
- * so that we can save a valid unread_marker value. NOTE: we will
- * accept multiple FF's followed by a 0 as meaning a single FF data
- * byte. This data pattern is not valid according to the standard.
- */
- do {
- if (bytes_offset == bytes_in_buffer) {
- if (! fill_input_buffer (cinfo))
- return false;
- buffer = cinfo.buffer;
- bytes_in_buffer = cinfo.bytes_in_buffer;
- bytes_offset = cinfo.bytes_offset;
- }
- c = buffer[bytes_offset++] & 0xFF;
- } while (c == 0xFF);
-
- if (c == 0) {
- /* Found FF/00, which represents an FF data byte */
- c = 0xFF;
- } else {
- /* Oops, it's actually a marker indicating end of compressed data.
- * Save the marker code for later use.
- * Fine point: it might appear that we should save the marker into
- * bitread working state, not straight into permanent state. But
- * once we have hit a marker, we cannot need to suspend within the
- * current MCU, because we will read no more bytes from the data
- * source. So it is OK to update permanent state right away.
- */
- cinfo.unread_marker = c;
- /* See if we need to insert some fake zero bits. */
-// goto no_more_bytes;
- if (nbits > bits_left) {
- /* Uh-oh. Report corrupted data to user and stuff zeroes into
- * the data stream, so that we can produce some kind of image.
- * We use a nonvolatile flag to ensure that only one warning message
- * appears per data segment.
- */
- if (! cinfo.entropy.insufficient_data) {
-// WARNMS(cinfo, JWRN_HIT_MARKER);
- cinfo.entropy.insufficient_data = true;
- }
- /* Fill the buffer with zero bits */
- get_buffer <<= MIN_GET_BITS - bits_left;
- bits_left = MIN_GET_BITS;
- }
-
- /* Unload the local registers */
- state.buffer = buffer;
- state.bytes_in_buffer = bytes_in_buffer;
- state.bytes_offset = bytes_offset;
- state.get_buffer = get_buffer;
- state.bits_left = bits_left;
-
- return true;
-
- }
- }
-
- /* OK, load c into get_buffer */
- get_buffer = (get_buffer << 8) | c;
- bits_left += 8;
- } /* end while */
- } else {
-// no_more_bytes:
- /* We get here if we've read the marker that terminates the compressed
- * data segment. There should be enough bits in the buffer register
- * to satisfy the request; if so, no problem.
- */
- if (nbits > bits_left) {
- /* Uh-oh. Report corrupted data to user and stuff zeroes into
- * the data stream, so that we can produce some kind of image.
- * We use a nonvolatile flag to ensure that only one warning message
- * appears per data segment.
- */
- if (! cinfo.entropy.insufficient_data) {
-// WARNMS(cinfo, JWRN_HIT_MARKER);
- cinfo.entropy.insufficient_data = true;
- }
- /* Fill the buffer with zero bits */
- get_buffer <<= MIN_GET_BITS - bits_left;
- bits_left = MIN_GET_BITS;
- }
- }
-
- /* Unload the local registers */
- state.buffer = buffer;
- state.bytes_in_buffer = bytes_in_buffer;
- state.bytes_offset = bytes_offset;
- state.get_buffer = get_buffer;
- state.bits_left = bits_left;
-
- return true;
-}
-
-static int jpeg_huff_decode (bitread_working_state state, int get_buffer, int bits_left, d_derived_tbl htbl, int min_bits) {
- int l = min_bits;
- int code;
-
- /* HUFF_DECODE has determined that the code is at least min_bits */
- /* bits long, so fetch that many bits in one swoop. */
-
-// CHECK_BIT_BUFFER(*state, l, return -1);
- {
- if (bits_left < (l)) {
- if (! jpeg_fill_bit_buffer(state,get_buffer,bits_left,l)) {
- return -1;
- }
- get_buffer = (state).get_buffer; bits_left = (state).bits_left;
- }
- }
-// code = GET_BITS(l);
- code = (( (get_buffer >> (bits_left -= (l)))) & ((1<<(l))-1));
-
- /* Collect the rest of the Huffman code one bit at a time. */
- /* This is per Figure F.16 in the JPEG spec. */
-
- while (code > htbl.maxcode[l]) {
- code <<= 1;
-// CHECK_BIT_BUFFER(*state, 1, return -1);
- {
- if (bits_left < (1)) {
- if (! jpeg_fill_bit_buffer(state,get_buffer,bits_left,1)) {
- return -1;
- }
- get_buffer = (state).get_buffer; bits_left = (state).bits_left;
- }
- }
-// code |= GET_BITS(1);
- code |= (( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1));
- l++;
- }
-
- /* Unload the local registers */
- state.get_buffer = get_buffer;
- state.bits_left = bits_left;
-
- /* With garbage input we may reach the sentinel value l = 17. */
-
- if (l > 16) {
-// WARNMS(state.cinfo, JWRN_HUFF_BAD_CODE);
- return 0; /* fake a zero as the safest result */
- }
-
- return htbl.pub.huffval[ (code + htbl.valoffset[l]) ] & 0xFF;
-}
-
-static int decompress_onepass (jpeg_decompress_struct cinfo, byte[][][] output_buf, int[] output_buf_offset) {
- jpeg_d_coef_controller coef = cinfo.coef;
- int MCU_col_num; /* index of current MCU within row */
- int last_MCU_col = cinfo.MCUs_per_row - 1;
- int last_iMCU_row = cinfo.total_iMCU_rows - 1;
- int blkn, ci, xindex, yindex, yoffset, useful_width;
- byte[][] output_ptr;
- int start_col, output_col;
- jpeg_component_info compptr;
-// inverse_DCT_method_ptr inverse_DCT;
-
- /* Loop to process as much as one whole iMCU row */
- for (yoffset = coef.MCU_vert_offset; yoffset < coef.MCU_rows_per_iMCU_row; yoffset++) {
- for (MCU_col_num = coef.MCU_ctr; MCU_col_num <= last_MCU_col; MCU_col_num++) {
- /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */
- for (int i = 0; i < cinfo.blocks_in_MCU; i++) {
- short[] blk = coef.MCU_buffer[i];
- for (int j = 0; j < blk.length; j++) {
- blk[j] = 0;
- }
- }
- if (! cinfo.entropy.decode_mcu (cinfo, coef.MCU_buffer)) {
- /* Suspension forced; update state counters and exit */
- coef.MCU_vert_offset = yoffset;
- coef.MCU_ctr = MCU_col_num;
- return JPEG_SUSPENDED;
- }
- /* Determine where data should go in output_buf and do the IDCT thing.
- * We skip dummy blocks at the right and bottom edges (but blkn gets
- * incremented past them!). Note the inner loop relies on having
- * allocated the MCU_buffer[] blocks sequentially.
- */
- blkn = 0; /* index of current DCT block within MCU */
- for (ci = 0; ci < cinfo.comps_in_scan; ci++) {
- compptr = cinfo.cur_comp_info[ci];
- /* Don't bother to IDCT an uninteresting component. */
- if (! compptr.component_needed) {
- blkn += compptr.MCU_blocks;
- continue;
- }
-// inverse_DCT = cinfo.idct.inverse_DCT[compptr.component_index];
- useful_width = (MCU_col_num < last_MCU_col) ? compptr.MCU_width : compptr.last_col_width;
- output_ptr = output_buf[compptr.component_index];
- int output_ptr_offset = output_buf_offset[compptr.component_index] + yoffset * compptr.DCT_scaled_size;
- start_col = MCU_col_num * compptr.MCU_sample_width;
- for (yindex = 0; yindex < compptr.MCU_height; yindex++) {
- if (cinfo.input_iMCU_row < last_iMCU_row || yoffset+yindex < compptr.last_row_height) {
- output_col = start_col;
- for (xindex = 0; xindex < useful_width; xindex++) {
- jpeg_idct_islow(cinfo, compptr, coef.MCU_buffer[blkn+xindex], output_ptr, output_ptr_offset, output_col);
- output_col += compptr.DCT_scaled_size;
- }
- }
- blkn += compptr.MCU_width;
- output_ptr_offset += compptr.DCT_scaled_size;
- }
- }
- }
- /* Completed an MCU row, but perhaps not an iMCU row */
- coef.MCU_ctr = 0;
- }
- /* Completed the iMCU row, advance counters for next one */
- cinfo.output_iMCU_row++;
- if (++(cinfo.input_iMCU_row) < cinfo.total_iMCU_rows) {
- coef.start_iMCU_row(cinfo);
- return JPEG_ROW_COMPLETED;
- }
- /* Completed the scan */
- finish_input_pass (cinfo);
- return JPEG_SCAN_COMPLETED;
-}
-
-static int decompress_smooth_data (jpeg_decompress_struct cinfo, byte[][][] output_buf, int[] output_buf_offset) {
- jpeg_d_coef_controller coef = cinfo.coef;
- int last_iMCU_row = cinfo.total_iMCU_rows - 1;
- int block_num, last_block_column;
- int ci, block_row, block_rows, access_rows;
- short[][][] buffer;
- short[][] buffer_ptr, prev_block_row, next_block_row;
- byte[][] output_ptr;
- int output_col;
- jpeg_component_info compptr;
-// inverse_DCT_method_ptr inverse_DCT;
- boolean first_row, last_row;
- short[] workspace = coef.workspace;
- if (workspace == null) workspace = coef.workspace = new short[DCTSIZE2];
- int[] coef_bits;
- JQUANT_TBL quanttbl;
- int Q00,Q01,Q02,Q10,Q11,Q20, num;
- int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
- int Al, pred;
-
- /* Force some input to be done if we are getting ahead of the input. */
- while (cinfo.input_scan_number <= cinfo.output_scan_number && ! cinfo.inputctl.eoi_reached) {
- if (cinfo.input_scan_number == cinfo.output_scan_number) {
- /* If input is working on current scan, we ordinarily want it to
- * have completed the current row. But if input scan is DC,
- * we want it to keep one row ahead so that next block row's DC
- * values are up to date.
- */
- int delta = (cinfo.Ss == 0) ? 1 : 0;
- if (cinfo.input_iMCU_row > cinfo.output_iMCU_row+delta)
- break;
- }
- if (consume_input(cinfo) == JPEG_SUSPENDED)
- return JPEG_SUSPENDED;
- }
-
- /* OK, output from the virtual arrays. */
- for (ci = 0; ci < cinfo.num_components; ci++) {
- compptr = cinfo.comp_info[ci];
- /* Don't bother to IDCT an uninteresting component. */
- if (! compptr.component_needed)
- continue;
- /* Count non-dummy DCT block rows in this iMCU row. */
- if (cinfo.output_iMCU_row < last_iMCU_row) {
- block_rows = compptr.v_samp_factor;
- access_rows = block_rows * 2; /* this and next iMCU row */
- last_row = false;
- } else {
- /* NB: can't use last_row_height here; it is input-side-dependent! */
- block_rows = (compptr.height_in_blocks % compptr.v_samp_factor);
- if (block_rows == 0) block_rows = compptr.v_samp_factor;
- access_rows = block_rows; /* this iMCU row only */
- last_row = true;
- }
- /* Align the virtual buffer for this component. */
- int buffer_offset;
- if (cinfo.output_iMCU_row > 0) {
- access_rows += compptr.v_samp_factor; /* prior iMCU row too */
- buffer = coef.whole_image[ci];
- buffer_offset = (cinfo.output_iMCU_row - 1) * compptr.v_samp_factor;
- buffer_offset += compptr.v_samp_factor; /* point to current iMCU row */
- first_row = false;
- } else {
- buffer = coef.whole_image[ci];
- buffer_offset = 0;
- first_row = true;
- }
- /* Fetch component-dependent info */
- coef_bits = coef.coef_bits_latch;
- int coef_offset = (ci * SAVED_COEFS);
- quanttbl = compptr.quant_table;
- Q00 = quanttbl.quantval[0];
- Q01 = quanttbl.quantval[Q01_POS];
- Q10 = quanttbl.quantval[Q10_POS];
- Q20 = quanttbl.quantval[Q20_POS];
- Q11 = quanttbl.quantval[Q11_POS];
- Q02 = quanttbl.quantval[Q02_POS];
-// inverse_DCT = cinfo.idct.inverse_DCT[ci];
- output_ptr = output_buf[ci];
- int output_ptr_offset = output_buf_offset[ci];
- /* Loop over all DCT blocks to be processed. */
- for (block_row = 0; block_row < block_rows; block_row++) {
- buffer_ptr = buffer[block_row+buffer_offset];
- int buffer_ptr_offset = 0, prev_block_row_offset = 0, next_block_row_offset = 0;
- if (first_row && block_row == 0) {
- prev_block_row = buffer_ptr;
- prev_block_row_offset = buffer_ptr_offset;
- } else {
- prev_block_row = buffer[block_row-1+buffer_offset];
- prev_block_row_offset = 0;
- }
- if (last_row && block_row == block_rows-1) {
- next_block_row = buffer_ptr;
- next_block_row_offset = buffer_ptr_offset;
- } else {
- next_block_row = buffer[block_row+1+buffer_offset];
- next_block_row_offset = 0;
- }
- /* We fetch the surrounding DC values using a sliding-register approach.
- * Initialize all nine here so as to do the right thing on narrow pics.
- */
- DC1 = DC2 = DC3 = prev_block_row[0+prev_block_row_offset][0];
- DC4 = DC5 = DC6 = buffer_ptr[0+buffer_ptr_offset][0];
- DC7 = DC8 = DC9 = next_block_row[0+next_block_row_offset][0];
- output_col = 0;
- last_block_column = compptr.width_in_blocks - 1;
- for (block_num = 0; block_num <= last_block_column; block_num++) {
- /* Fetch current DCT block into workspace so we can modify it. */
-// jcopy_block_row(buffer_ptr, workspace, 1);
- System.arraycopy(buffer_ptr[buffer_ptr_offset], 0, workspace, 0, workspace.length);
- /* Update DC values */
- if (block_num < last_block_column) {
- DC3 = prev_block_row[1+prev_block_row_offset][0];
- DC6 = buffer_ptr[1+buffer_ptr_offset][0];
- DC9 = next_block_row[1+next_block_row_offset][0];
- }
- /* Compute coefficient estimates per K.8.
- * An estimate is applied only if coefficient is still zero,
- * and is not known to be fully accurate.
- */
- /* AC01 */
- if ((Al=coef_bits[1+coef_offset]) != 0 && workspace[1] == 0) {
- num = 36 * Q00 * (DC4 - DC6);
- if (num >= 0) {
- pred = (((Q01<<7) + num) / (Q01<<8));
- if (Al > 0 && pred >= (1<<Al))
- pred = (1<<Al)-1;
- } else {
- pred = (((Q01<<7) - num) / (Q01<<8));
- if (Al > 0 && pred >= (1<<Al))
- pred = (1<<Al)-1;
- pred = -pred;
- }
- workspace[1] = (short) pred;
- }
- /* AC10 */
- if ((Al=coef_bits[2+coef_offset]) != 0 && workspace[8] == 0) {
- num = 36 * Q00 * (DC2 - DC8);
- if (num >= 0) {
- pred = (((Q10<<7) + num) / (Q10<<8));
- if (Al > 0 && pred >= (1<<Al))
- pred = (1<<Al)-1;
- } else {
- pred = (((Q10<<7) - num) / (Q10<<8));
- if (Al > 0 && pred >= (1<<Al))
- pred = (1<<Al)-1;
- pred = -pred;
- }
- workspace[8] = (short) pred;
- }
- /* AC20 */
- if ((Al=coef_bits[3+coef_offset]) != 0 && workspace[16] == 0) {
- num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
- if (num >= 0) {
- pred = (((Q20<<7) + num) / (Q20<<8));
- if (Al > 0 && pred >= (1<<Al))
- pred = (1<<Al)-1;
- } else {
- pred = (((Q20<<7) - num) / (Q20<<8));
- if (Al > 0 && pred >= (1<<Al))
- pred = (1<<Al)-1;
- pred = -pred;
- }
- workspace[16] = (short) pred;
- }
- /* AC11 */
- if ((Al=coef_bits[4+coef_offset]) != 0 && workspace[9] == 0) {
- num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
- if (num >= 0) {
- pred = (((Q11<<7) + num) / (Q11<<8));
- if (Al > 0 && pred >= (1<<Al))
- pred = (1<<Al)-1;
- } else {
- pred = (((Q11<<7) - num) / (Q11<<8));
- if (Al > 0 && pred >= (1<<Al))
- pred = (1<<Al)-1;
- pred = -pred;
- }
- workspace[9] = (short) pred;
- }
- /* AC02 */
- if ((Al=coef_bits[5+coef_offset]) != 0 && workspace[2] == 0) {
- num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
- if (num >= 0) {
- pred = (((Q02<<7) + num) / (Q02<<8));
- if (Al > 0 && pred >= (1<<Al))
- pred = (1<<Al)-1;
- } else {
- pred = (((Q02<<7) - num) / (Q02<<8));
- if (Al > 0 && pred >= (1<<Al))
- pred = (1<<Al)-1;
- pred = -pred;
- }
- workspace[2] = (short) pred;
- }
- /* OK, do the IDCT */
- jpeg_idct_islow(cinfo, compptr, workspace, output_ptr, output_ptr_offset, output_col);
- /* Advance for next column */
- DC1 = DC2; DC2 = DC3;
- DC4 = DC5; DC5 = DC6;
- DC7 = DC8; DC8 = DC9;
- buffer_ptr_offset++; prev_block_row_offset++; next_block_row_offset++;
- output_col += compptr.DCT_scaled_size;
- }
- output_ptr_offset += compptr.DCT_scaled_size;
- }
- }
-
- if (++(cinfo.output_iMCU_row) < cinfo.total_iMCU_rows)
- return JPEG_ROW_COMPLETED;
- return JPEG_SCAN_COMPLETED;
-}
-
-static int decompress_data (jpeg_decompress_struct cinfo, byte[][][] output_buf, int[] output_buf_offset) {
- jpeg_d_coef_controller coef = cinfo.coef;
- int last_iMCU_row = cinfo.total_iMCU_rows - 1;
- int block_num;
- int ci, block_row, block_rows;
- short[][][] buffer;
- short[][] buffer_ptr;
- byte[][] output_ptr;
- int output_col;
- jpeg_component_info compptr;
-// inverse_DCT_method_ptr inverse_DCT;
-
- /* Force some input to be done if we are getting ahead of the input. */
- while (cinfo.input_scan_number < cinfo.output_scan_number ||
- (cinfo.input_scan_number == cinfo.output_scan_number &&
- cinfo.input_iMCU_row <= cinfo.output_iMCU_row))
- {
- if (consume_input(cinfo) == JPEG_SUSPENDED)
- return JPEG_SUSPENDED;
- }
-
- /* OK, output from the virtual arrays. */
- for (ci = 0; ci < cinfo.num_components; ci++) {
- compptr = cinfo.comp_info[ci];
- /* Don't bother to IDCT an uninteresting component. */
- if (! compptr.component_needed)
- continue;
- /* Align the virtual buffer for this component. */
- buffer = coef.whole_image[ci];
- int buffer_offset = cinfo.output_iMCU_row * compptr.v_samp_factor;
- /* Count non-dummy DCT block rows in this iMCU row. */
- if (cinfo.output_iMCU_row < last_iMCU_row)
- block_rows = compptr.v_samp_factor;
- else {
- /* NB: can't use last_row_height here; it is input-side-dependent! */
- block_rows = (compptr.height_in_blocks % compptr.v_samp_factor);
- if (block_rows == 0) block_rows = compptr.v_samp_factor;
- }
-// inverse_DCT = cinfo.idct.inverse_DCT[ci];
- output_ptr = output_buf[ci];
- int output_ptr_offset = output_buf_offset[ci];
- /* Loop over all DCT blocks to be processed. */
- for (block_row = 0; block_row < block_rows; block_row++) {
- buffer_ptr = buffer[block_row+buffer_offset];
- int buffer_ptr_offset = 0;
- output_col = 0;
- for (block_num = 0; block_num < compptr.width_in_blocks; block_num++) {
- jpeg_idct_islow(cinfo, compptr, buffer_ptr[buffer_ptr_offset], output_ptr, output_ptr_offset, output_col);
-
- buffer_ptr_offset++;
- output_col += compptr.DCT_scaled_size;
- }
- output_ptr_offset += compptr.DCT_scaled_size;
- }
- }
-
- if (++(cinfo.output_iMCU_row) < cinfo.total_iMCU_rows)
- return JPEG_ROW_COMPLETED;
- return JPEG_SCAN_COMPLETED;
-}
-
-static void post_process_data (jpeg_decompress_struct cinfo,
- byte[][][] input_buf, int[] input_buf_offset, int[] in_row_group_ctr,
- int in_row_groups_avail,
- byte[][] output_buf, int[] out_row_ctr,
- int out_rows_avail)
-{
- upsample(cinfo, input_buf, input_buf_offset, in_row_group_ctr, in_row_groups_avail, output_buf, out_row_ctr, out_rows_avail);
-}
-
-static void set_bottom_pointers (jpeg_decompress_struct cinfo)
-/* Change the pointer lists to duplicate the last sample row at the bottom
- * of the image. whichptr indicates which xbuffer holds the final iMCU row.
- * Also sets rowgroups_avail to indicate number of nondummy row groups in row.
- */
-{
- jpeg_d_main_controller main = cinfo.main;
- int ci, i, rgroup, iMCUheight, rows_left;
- jpeg_component_info compptr;
- byte[][] xbuf;
-
- for (ci = 0; ci < cinfo.num_components; ci++) {
- compptr = cinfo.comp_info[ci];
- /* Count sample rows in one iMCU row and in one row group */
- iMCUheight = compptr.v_samp_factor * compptr.DCT_scaled_size;
- rgroup = iMCUheight / cinfo.min_DCT_scaled_size;
- /* Count nondummy sample rows remaining for this component */
- rows_left = (compptr.downsampled_height % iMCUheight);
- if (rows_left == 0) rows_left = iMCUheight;
- /* Count nondummy row groups. Should get same answer for each component,
- * so we need only do it once.
- */
- if (ci == 0) {
- main.rowgroups_avail = ((rows_left-1) / rgroup + 1);
- }
- /* Duplicate the last real sample row rgroup*2 times; this pads out the
- * last partial rowgroup and ensures at least one full rowgroup of context.
- */
- xbuf = main.xbuffer[main.whichptr][ci];
- int xbuf_offset = main.xbuffer_offset[main.whichptr][ci];
- for (i = 0; i < rgroup * 2; i++) {
- xbuf[rows_left + i + xbuf_offset] = xbuf[rows_left-1 + xbuf_offset];
- }
- }
-}
-
-static void set_wraparound_pointers (jpeg_decompress_struct cinfo)
-/* Set up the "wraparound" pointers at top and bottom of the pointer lists.
- * This changes the pointer list state from top-of-image to the normal state.
- */
-{
- jpeg_d_main_controller main = cinfo.main;
- int ci, i, rgroup;
- int M = cinfo.min_DCT_scaled_size;
- jpeg_component_info compptr;
- byte[][] xbuf0, xbuf1;
-
- for (ci = 0; ci < cinfo.num_components; ci++) {
- compptr = cinfo.comp_info[ci];
- rgroup = (compptr.v_samp_factor * compptr.DCT_scaled_size) / cinfo.min_DCT_scaled_size; /* height of a row group of component */
- xbuf0 = main.xbuffer[0][ci];
- int xbuf0_offset = main.xbuffer_offset[0][ci];
- xbuf1 = main.xbuffer[1][ci];
- int xbuf1_offset = main.xbuffer_offset[1][ci];
- for (i = 0; i < rgroup; i++) {
- xbuf0[i - rgroup + xbuf0_offset] = xbuf0[rgroup*(M+1) + i + xbuf0_offset];
- xbuf1[i - rgroup + xbuf1_offset] = xbuf1[rgroup*(M+1) + i + xbuf1_offset];
- xbuf0[rgroup*(M+2) + i + xbuf0_offset] = xbuf0[i + xbuf0_offset];
- xbuf1[rgroup*(M+2) + i + xbuf1_offset] = xbuf1[i + xbuf1_offset];
- }
- }
-}
-
-static void process_data_crank_post (jpeg_decompress_struct cinfo,
- byte[][] output_buf, int[] out_row_ctr,
- int out_rows_avail)
-{
- error();
-}
-
-static void process_data_context_main (jpeg_decompress_struct cinfo,
- byte[][] output_buf, int[] out_row_ctr,
- int out_rows_avail)
-{
- jpeg_d_main_controller main = cinfo.main;
-
- /* Read input data if we haven't filled the main buffer yet */
- if (! main.buffer_full) {
- int result;
- switch (cinfo.coef.decompress_data) {
- case DECOMPRESS_DATA:
- result = decompress_data(cinfo, main.xbuffer[main.whichptr], main.xbuffer_offset[main.whichptr]);
- break;
- case DECOMPRESS_SMOOTH_DATA:
- result = decompress_smooth_data(cinfo, main.xbuffer[main.whichptr], main.xbuffer_offset[main.whichptr]);
- break;
- case DECOMPRESS_ONEPASS:
- result = decompress_onepass(cinfo, main.xbuffer[main.whichptr], main.xbuffer_offset[main.whichptr]);
- break;
- default: result = 0;
- }
- if (result == 0)
- return; /* suspension forced, can do nothing more */
- main.buffer_full = true; /* OK, we have an iMCU row to work with */
- main.iMCU_row_ctr++; /* count rows received */
- }
-
- /* Postprocessor typically will not swallow all the input data it is handed
- * in one call (due to filling the output buffer first). Must be prepared
- * to exit and restart. This switch lets us keep track of how far we got.
- * Note that each case falls through to the next on successful completion.
- */
- switch (main.context_state) {
- case CTX_POSTPONED_ROW:
- /* Call postprocessor using previously set pointers for postponed row */
- post_process_data (cinfo, main.xbuffer[main.whichptr], main.xbuffer_offset[main.whichptr], main.rowgroup_ctr, main.rowgroups_avail, output_buf, out_row_ctr, out_rows_avail);
- if (main.rowgroup_ctr[0] < main.rowgroups_avail)
- return; /* Need to suspend */
- main.context_state = CTX_PREPARE_FOR_IMCU;
- if (out_row_ctr[0] >= out_rows_avail)
- return; /* Postprocessor exactly filled output buf */
- /*FALLTHROUGH*/
- case CTX_PREPARE_FOR_IMCU:
- /* Prepare to process first M-1 row groups of this iMCU row */
- main.rowgroup_ctr[0] = 0;
- main.rowgroups_avail = (cinfo.min_DCT_scaled_size - 1);
- /* Check for bottom of image: if so, tweak pointers to "duplicate"
- * the last sample row, and adjust rowgroups_avail to ignore padding rows.
- */
- if (main.iMCU_row_ctr == cinfo.total_iMCU_rows)
- set_bottom_pointers(cinfo);
- main.context_state = CTX_PROCESS_IMCU;
- /*FALLTHROUGH*/
- case CTX_PROCESS_IMCU:
- /* Call postprocessor using previously set pointers */
- post_process_data (cinfo, main.xbuffer[main.whichptr], main.xbuffer_offset[main.whichptr], main.rowgroup_ctr, main.rowgroups_avail, output_buf, out_row_ctr, out_rows_avail);
- if (main.rowgroup_ctr[0] < main.rowgroups_avail)
- return; /* Need to suspend */
- /* After the first iMCU, change wraparound pointers to normal state */
- if (main.iMCU_row_ctr == 1)
- set_wraparound_pointers(cinfo);
- /* Prepare to load new iMCU row using other xbuffer list */
- main.whichptr ^= 1; /* 0=>1 or 1=>0 */
- main.buffer_full = false;
- /* Still need to process last row group of this iMCU row, */
- /* which is saved at index M+1 of the other xbuffer */
- main.rowgroup_ctr[0] = (cinfo.min_DCT_scaled_size + 1);
- main.rowgroups_avail = (cinfo.min_DCT_scaled_size + 2);
- main.context_state = CTX_POSTPONED_ROW;
- }
-}
-
-static void process_data_simple_main (jpeg_decompress_struct cinfo, byte[][] output_buf, int[] out_row_ctr, int out_rows_avail) {
- jpeg_d_main_controller main = cinfo.main;
- int rowgroups_avail;
-
- /* Read input data if we haven't filled the main buffer yet */
- if (! main.buffer_full) {
- int result;
- switch (cinfo.coef.decompress_data) {
- case DECOMPRESS_DATA:
- result = decompress_data(cinfo, main.buffer, main.buffer_offset);
- break;
- case DECOMPRESS_SMOOTH_DATA:
- result = decompress_smooth_data(cinfo, main.buffer, main.buffer_offset);
- break;
- case DECOMPRESS_ONEPASS:
- result = decompress_onepass(cinfo, main.buffer, main.buffer_offset);
- break;
- default: result = 0;
- }
- if (result == 0)
- return; /* suspension forced, can do nothing more */
- main.buffer_full = true; /* OK, we have an iMCU row to work with */
- }
-
- /* There are always min_DCT_scaled_size row groups in an iMCU row. */
- rowgroups_avail = cinfo.min_DCT_scaled_size;
- /* Note: at the bottom of the image, we may pass extra garbage row groups
- * to the postprocessor. The postprocessor has to check for bottom
- * of image anyway (at row resolution), so no point in us doing it too.
- */
-
- /* Feed the postprocessor */
- post_process_data (cinfo, main.buffer, main.buffer_offset, main.rowgroup_ctr, rowgroups_avail, output_buf, out_row_ctr, out_rows_avail);
-
- /* Has postprocessor consumed all the data yet? If so, mark buffer empty */
- if (main.rowgroup_ctr[0] >= rowgroups_avail) {
- main.buffer_full = false;
- main.rowgroup_ctr[0] = 0;
- }
-}
-
-static int jpeg_read_scanlines (jpeg_decompress_struct cinfo, byte[][] scanlines, int max_lines) {
-
- if (cinfo.global_state != DSTATE_SCANNING)
- error();
-// ERREXIT1(cinfo, JERR_BAD_STATE, cinfo.global_state);
- if (cinfo.output_scanline >= cinfo.output_height) {
-// WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
- return 0;
- }
-
- /* Call progress monitor hook if present */
-// if (cinfo.progress != NULL) {
-// cinfo.progress.pass_counter = (long) cinfo.output_scanline;
-// cinfo.progress.pass_limit = (long) cinfo.output_height;
-// (*cinfo.progress.progress_monitor) ((j_common_ptr) cinfo);
-// }
-
- /* Process some data */
- cinfo.row_ctr[0] = 0;
- switch (cinfo.main.process_data) {
- case PROCESS_DATA_SIMPLE_MAIN:
- process_data_simple_main (cinfo, scanlines, cinfo.row_ctr, max_lines);
- break;
- case PROCESS_DATA_CONTEXT_MAIN:
- process_data_context_main (cinfo, scanlines, cinfo.row_ctr, max_lines);
- break;
- case PROCESS_DATA_CRANK_POST:
- process_data_crank_post (cinfo, scanlines, cinfo.row_ctr, max_lines);
- break;
- default: error();
- }
- cinfo.output_scanline += cinfo.row_ctr[0];
- return cinfo.row_ctr[0];
-}
-
-
-static boolean output_pass_setup (jpeg_decompress_struct cinfo) {
- if (cinfo.global_state != DSTATE_PRESCAN) {
- /* First call: do pass setup */
- prepare_for_output_pass (cinfo);
- cinfo.output_scanline = 0;
- cinfo.global_state = DSTATE_PRESCAN;
- }
- /* Loop over any required dummy passes */
- while (cinfo.master.is_dummy_pass) {
- error();
-//#ifdef QUANT_2PASS_SUPPORTED
-// /* Crank through the dummy pass */
-// while (cinfo.output_scanline < cinfo.output_height) {
-// JDIMENSION last_scanline;
-// /* Call progress monitor hook if present */
-// if (cinfo.progress != NULL) {
-// cinfo.progress.pass_counter = (long) cinfo.output_scanline;
-// cinfo.progress.pass_limit = (long) cinfo.output_height;
-// (*cinfo.progress.progress_monitor) ((j_common_ptr) cinfo);
-// }
-// /* Process some data */
-// last_scanline = cinfo.output_scanline;
-// (*cinfo.main.process_data) (cinfo, (JSAMPARRAY) NULL,
-// &cinfo.output_scanline, (JDIMENSION) 0);
-// if (cinfo.output_scanline == last_scanline)
-// return FALSE; /* No progress made, must suspend */
-// }
-// /* Finish up dummy pass, and set up for another one */
-// (*cinfo.master.finish_output_pass) (cinfo);
-// (*cinfo.master.prepare_for_output_pass) (cinfo);
-// cinfo.output_scanline = 0;
-//#else
-// ERREXIT(cinfo, JERR_NOT_COMPILED);
-//#endif /* QUANT_2PASS_SUPPORTED */
- }
- /* Ready for application to drive output pass through
- * jpeg_read_scanlines or jpeg_read_raw_data.
- */
- cinfo.global_state = cinfo.raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
- return true;
-}
-
-static boolean get_dht (jpeg_decompress_struct cinfo)
-/* Process a DHT marker */
-{
- int length;
- byte[] bits = new byte[17];
- byte[] huffval = new byte[256];
- int i, index, count;
- JHUFF_TBL htblptr;
-
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- length -= 2;
-
- while (length > 16) {
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- index = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
-
-// TRACEMS1(cinfo, 1, JTRC_DHT, index);
-
- bits[0] = 0;
- count = 0;
- for (i = 1; i <= 16; i++) {
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- bits[i] = cinfo.buffer[cinfo.bytes_offset++];
- count += bits[i] & 0xFF;
- }
-
- length -= 1 + 16;
-
-// TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
-// bits[1], bits[2], bits[3], bits[4],
-// bits[5], bits[6], bits[7], bits[8]);
-// TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
-// bits[9], bits[10], bits[11], bits[12],
-// bits[13], bits[14], bits[15], bits[16]);
-
- /* Here we just do minimal validation of the counts to avoid walking
- * off the end of our table space. jdhuff.c will check more carefully.
- */
- if (count > 256 || (count) > length)
- error();
-// ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
-
- for (i = 0; i < count; i++) {
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- huffval[i] = cinfo.buffer[cinfo.bytes_offset++];
- }
-
- length -= count;
-
- if ((index & 0x10) != 0) { /* AC table definition */
- index -= 0x10;
- htblptr = cinfo.ac_huff_tbl_ptrs[index] = new JHUFF_TBL();
- } else { /* DC table definition */
- htblptr = cinfo.dc_huff_tbl_ptrs[index] = new JHUFF_TBL();
- }
-
- if (index < 0 || index >= NUM_HUFF_TBLS)
- error();
-// ERREXIT1(cinfo, JERR_DHT_INDEX, index);
-
- System.arraycopy(bits, 0, htblptr.bits, 0, bits.length);
- System.arraycopy(huffval, 0, htblptr.huffval, 0, huffval.length);
- }
-
- if (length != 0)
- error();
-// ERREXIT(cinfo, JERR_BAD_LENGTH);
-
- return true;
-}
-
-
-static boolean get_dqt (jpeg_decompress_struct cinfo)
-/* Process a DQT marker */
-{
- int length;
- int n, i, prec;
- int tmp;
- JQUANT_TBL quant_ptr;
-
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- length -= 2;
-
- while (length > 0) {
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- n = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- prec = n >> 4;
- n &= 0x0F;
-
-// TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
-
- if (n >= NUM_QUANT_TBLS)
- error();
-// ERREXIT1(cinfo, JERR_DQT_INDEX, n);
-
- if (cinfo.quant_tbl_ptrs[n] == null)
- cinfo.quant_tbl_ptrs[n] = new JQUANT_TBL();
- quant_ptr = cinfo.quant_tbl_ptrs[n];
-
- for (i = 0; i < DCTSIZE2; i++) {
- if (prec != 0) {
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- tmp = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- tmp |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- } else {
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- tmp = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- }
- /* We convert the zigzag-order table to natural array order. */
- quant_ptr.quantval[jpeg_natural_order[i]] = (short) tmp;
- }
-
-// if (cinfo.err.trace_level >= 2) {
-// for (i = 0; i < DCTSIZE2; i += 8) {
-// TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
-// quant_ptr.quantval[i], quant_ptr.quantval[i+1],
-// quant_ptr.quantval[i+2], quant_ptr.quantval[i+3],
-// quant_ptr.quantval[i+4], quant_ptr.quantval[i+5],
-// quant_ptr.quantval[i+6], quant_ptr.quantval[i+7]);
-// }
-// }
-
- length -= (DCTSIZE2+1);
- if (prec != 0) length -= DCTSIZE2;
- }
-
- if (length != 0)
- error();
-// ERREXIT(cinfo, JERR_BAD_LENGTH);
-
- return true;
-}
-
-static boolean get_dri (jpeg_decompress_struct cinfo)
-/* Process a DRI marker */
-{
- int length;
- int tmp;
-
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
-
- if (length != 4)
- error();
-// ERREXIT(cinfo, JERR_BAD_LENGTH);
-
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- tmp = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- tmp |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
-
-// TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
-
- cinfo.restart_interval = tmp;
-
- return true;
-}
-
-static boolean get_dac (jpeg_decompress_struct cinfo)
-/* Process a DAC marker */
-{
- int length;
- int index, val;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- length -= 2;
-
- while (length > 0) {
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- index = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- val = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
-
- length -= 2;
-
-// TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
-
- if (index < 0 || index >= (2*NUM_ARITH_TBLS))
- error();
-// ERREXIT1(cinfo, JERR_DAC_INDEX, index);
-
- if (index >= NUM_ARITH_TBLS) { /* define AC table */
- cinfo.arith_ac_K[index-NUM_ARITH_TBLS] = (byte) val;
- } else { /* define DC table */
- cinfo.arith_dc_L[index] = (byte) (val & 0x0F);
- cinfo.arith_dc_U[index] = (byte) (val >> 4);
- if (cinfo.arith_dc_L[index] > cinfo.arith_dc_U[index])
- error();
-// ERREXIT1(cinfo, JERR_DAC_VALUE, val);
- }
- }
-
- if (length != 0)
- error();
-// ERREXIT(cinfo, JERR_BAD_LENGTH);
-
- return true;
-}
-
-
-static boolean get_sos (jpeg_decompress_struct cinfo)
-/* Process a SOS marker */
-{
- int length;
- int i, ci, n, c, cc;
- jpeg_component_info compptr = null;
-
- if (! cinfo.marker.saw_SOF)
- error();
-// ERREXIT(cinfo, JERR_SOS_NO_SOF);
-
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
-
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- n = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
-
-// TRACEMS1(cinfo, 1, JTRC_SOS, n);
-
- if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
- error();
-// ERREXIT(cinfo, JERR_BAD_LENGTH);
-
- cinfo.comps_in_scan = n;
-
- /* Collect the component-spec parameters */
-
- for (i = 0; i < n; i++) {
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- cc = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
-
- for (ci = 0; ci < cinfo.num_components; ci++) {
- compptr = cinfo.comp_info[ci];
- if (cc == compptr.component_id)
- break;
- }
-
- if (ci == cinfo.num_components)
- error();
-// ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
-
- cinfo.cur_comp_info[i] = compptr;
- compptr.dc_tbl_no = (c >> 4) & 15;
- compptr.ac_tbl_no = (c ) & 15;
-
-// TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc, compptr.dc_tbl_no, compptr.ac_tbl_no);
- }
-
- /* Collect the additional scan parameters Ss, Se, Ah/Al. */
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- cinfo.Ss = c;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- cinfo.Se = c;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- cinfo.Ah = (c >> 4) & 15;
- cinfo.Al = (c ) & 15;
-
-// TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo.Ss, cinfo.Se, cinfo.Ah, cinfo.Al);
-
- /* Prepare to scan data & restart markers */
- cinfo.marker.next_restart_num = 0;
-
- /* Count another SOS marker */
- cinfo.input_scan_number++;
-
- return true;
-}
-
-static boolean get_sof (jpeg_decompress_struct cinfo, boolean is_prog, boolean is_arith) {
- int length;
- int c, ci;
-
- cinfo.progressive_mode = is_prog;
- cinfo.arith_code = is_arith;
-
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
-
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- cinfo.data_precision = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
-
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- cinfo.image_height = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- cinfo.image_height |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
-
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- cinfo.image_width = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- cinfo.image_width |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
-
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- cinfo.num_components = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
-
- length -= 8;
-
-// TRACEMS4(cinfo, 1, JTRC_SOF, cinfo.unread_marker,
-// (int) cinfo.image_width, (int) cinfo.image_height,
-// cinfo.num_components);
-
- if (cinfo.marker.saw_SOF)
- error();
-// ERREXIT(cinfo, JERR_SOF_DUPLICATE);
-
- /* We don't support files in which the image height is initially specified */
- /* as 0 and is later redefined by DNL. As long as we have to check that, */
- /* might as well have a general sanity check. */
- if (cinfo.image_height <= 0 || cinfo.image_width <= 0 || cinfo.num_components <= 0)
- error();
-// ERREXIT(cinfo, JERR_EMPTY_IMAGE);
-
- if (length != (cinfo.num_components * 3))
- error();
-// ERREXIT(cinfo, JERR_BAD_LENGTH);
-
- if (cinfo.comp_info == null) /* do only once, even if suspend */
- cinfo.comp_info = new jpeg_component_info[cinfo.num_components];
-
- for (ci = 0; ci < cinfo.num_components; ci++) {
- jpeg_component_info compptr = cinfo.comp_info[ci] = new jpeg_component_info();
- compptr.component_index = ci;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- compptr.component_id = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- compptr.h_samp_factor = (c >> 4) & 15;
- compptr.v_samp_factor = (c ) & 15;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- compptr.quant_tbl_no = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
-
-// TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
-// compptr.component_id, compptr.h_samp_factor,
-// compptr.v_samp_factor, compptr.quant_tbl_no);
- }
-
- cinfo.marker.saw_SOF = true;
-
- return true;
-}
-
-static void sep_upsample (jpeg_decompress_struct cinfo, byte[][][] input_buf, int[] input_buf_offset,
- int[] in_row_group_ctr, int in_row_groups_avail,
- byte[][] output_buf, int[] out_row_ctr, int out_rows_avail)
-{
- jpeg_upsampler upsample = cinfo.upsample;
- int ci;
- jpeg_component_info compptr;
- int num_rows;
-
- /* Fill the conversion buffer, if it's empty */
- if (upsample.next_row_out >= cinfo.max_v_samp_factor) {
- for (ci = 0; ci < cinfo.num_components; ci++) {
- compptr = cinfo.comp_info[ci];
- /* Invoke per-component upsample method. Notice we pass a POINTER
- * to color_buf[ci], so that fullsize_upsample can change it.
- */
- int offset = input_buf_offset[ci] + (in_row_group_ctr[0] * upsample.rowgroup_height[ci]);
- switch (upsample.methods[ci]) {
- case NOOP_UPSAMPLE: noop_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break;
- case FULLSIZE_UPSAMPLE: fullsize_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break;
- case H2V1_FANCY_UPSAMPLE: h2v1_fancy_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break;
- case H2V1_UPSAMPLE: h2v1_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break;
- case H2V2_FANCY_UPSAMPLE: h2v2_fancy_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break;
- case H2V2_UPSAMPLE: h2v2_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break;
- case INT_UPSAMPLE: int_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break;
- }
- }
- upsample.next_row_out = 0;
- }
-
- /* Color-convert and emit rows */
-
- /* How many we have in the buffer: */
- num_rows = (cinfo.max_v_samp_factor - upsample.next_row_out);
- /* Not more than the distance to the end of the image. Need this test
- * in case the image height is not a multiple of max_v_samp_factor:
- */
- if (num_rows > upsample.rows_to_go)
- num_rows = upsample.rows_to_go;
- /* And not more than what the client can accept: */
- out_rows_avail -= out_row_ctr[0];
- if (num_rows > out_rows_avail)
- num_rows = out_rows_avail;
-
- switch (cinfo.cconvert.color_convert) {
- case NULL_CONVERT: null_convert (cinfo, upsample.color_buf, upsample.color_buf_offset, upsample.next_row_out, output_buf, out_row_ctr[0], num_rows); break;
- case GRAYSCALE_CONVERT: grayscale_convert (cinfo, upsample.color_buf, upsample.color_buf_offset, upsample.next_row_out, output_buf, out_row_ctr[0], num_rows); break;
- case YCC_RGB_CONVERT: ycc_rgb_convert (cinfo, upsample.color_buf, upsample.color_buf_offset, upsample.next_row_out, output_buf, out_row_ctr[0], num_rows); break;
- case GRAY_RGB_CONVERT: gray_rgb_convert (cinfo, upsample.color_buf, upsample.color_buf_offset, upsample.next_row_out, output_buf, out_row_ctr[0], num_rows); break;
- case YCCK_CMYK_CONVERT: error(); break;
- }
-
- /* Adjust counts */
- out_row_ctr[0] += num_rows;
- upsample.rows_to_go -= num_rows;
- upsample.next_row_out += num_rows;
- /* When the buffer is emptied, declare this input row group consumed */
- if (upsample.next_row_out >= cinfo.max_v_samp_factor) {
- in_row_group_ctr[0]++;
- }
-}
-
-static void noop_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr,
- byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index)
-{
- output_data_ptr[output_data_index] = null; /* safety check */
-}
-
-static void fullsize_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr,
- byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index)
-{
- output_data_ptr[output_data_index] = input_data;
- output_data_offset[output_data_index] = input_data_offset;
-}
-
-static void h2v1_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr,
- byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index)
-{
- byte[][] output_data = output_data_ptr[output_data_index];
- byte[] inptr, outptr;
- byte invalue;
- int outend;
- int inrow;
- output_data_offset[output_data_index] = 0;
-
- for (inrow = 0; inrow < cinfo.max_v_samp_factor; inrow++) {
- inptr = input_data[inrow+input_data_offset];
- outptr = output_data[inrow];
- int inptr_offset = 0, outptr_offset = 0;
- outend = outptr_offset + cinfo.output_width;
- while (outptr_offset < outend) {
- invalue = inptr[inptr_offset++]; /* don't need GETJSAMPLE() here */
- outptr[outptr_offset++] = invalue;
- outptr[outptr_offset++] = invalue;
- }
- }
-}
-
-static void h2v2_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr,
- byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index)
-{
- byte[][] output_data = output_data_ptr[output_data_index];
- byte[] inptr, outptr;
- byte invalue;
- int outend;
- int inrow, outrow;
- output_data_offset[output_data_index] = 0;
-
- inrow = outrow = 0;
- while (outrow < cinfo.max_v_samp_factor) {
- inptr = input_data[inrow+input_data_offset];
- outptr = output_data[outrow];
- int inptr_offset = 0, outptr_offset = 0;
- outend = outptr_offset + cinfo.output_width;
- while (outptr_offset < outend) {
- invalue = inptr[inptr_offset++]; /* don't need GETJSAMPLE() here */
- outptr[outptr_offset++] = invalue;
- outptr[outptr_offset++] = invalue;
- }
- jcopy_sample_rows(output_data, outrow, output_data, outrow+1, 1, cinfo.output_width);
- inrow++;
- outrow += 2;
- }
-}
-
-static void h2v1_fancy_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr,
- byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index)
-{
- byte[][] output_data = output_data_ptr[output_data_index];
- byte[] inptr, outptr;
- int invalue;
- int colctr;
- int inrow;
- output_data_offset[output_data_index] = 0;
-
- for (inrow = 0; inrow < cinfo.max_v_samp_factor; inrow++) {
- inptr = input_data[inrow+input_data_offset];
- outptr = output_data[inrow];
- int inptr_offset = 0, outptr_offset = 0;
- /* Special case for first column */
- invalue = inptr[inptr_offset++] & 0xFF;
- outptr[outptr_offset++] = (byte) invalue;
- outptr[outptr_offset++] = (byte) ((invalue * 3 + (inptr[inptr_offset] & 0xFF) + 2) >> 2);
-
- for (colctr = compptr.downsampled_width - 2; colctr > 0; colctr--) {
- /* General case: 3/4 * nearer pixel + 1/4 * further pixel */
- invalue = (inptr[inptr_offset++] & 0xFF) * 3;
- outptr[outptr_offset++] = (byte) ((invalue + (inptr[inptr_offset-2] & 0xFF) + 1) >> 2);
- outptr[outptr_offset++] = (byte) ((invalue + (inptr[inptr_offset] & 0xFF) + 2) >> 2);
- }
-
- /* Special case for last column */
- invalue = (inptr[inptr_offset] & 0xFF);
- outptr[outptr_offset++] = (byte) ((invalue * 3 + (inptr[inptr_offset-1] & 0xFF) + 1) >> 2);
- outptr[outptr_offset++] = (byte) invalue;
- }
-}
-
-static void h2v2_fancy_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr,
- byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index)
-{
- byte[][] output_data = output_data_ptr[output_data_index];
- byte[] inptr0, inptr1, outptr;
- int thiscolsum, lastcolsum, nextcolsum;
- int colctr;
- int inrow, outrow, v;
- output_data_offset[output_data_index] = 0;
-
- inrow = outrow = 0;
- while (outrow < cinfo.max_v_samp_factor) {
- for (v = 0; v < 2; v++) {
- /* inptr0 points to nearest input row, inptr1 points to next nearest */
- inptr0 = input_data[inrow+input_data_offset];
- if (v == 0) /* next nearest is row above */
- inptr1 = input_data[inrow-1+input_data_offset];
- else /* next nearest is row below */
- inptr1 = input_data[inrow+1+input_data_offset];
- outptr = output_data[outrow++];
-
- int inptr0_offset = 0, inptr1_offset = 0, outptr_offset = 0;
-
- /* Special case for first column */
- thiscolsum = (inptr0[inptr0_offset++] & 0xFF) * 3 + (inptr1[inptr1_offset++] & 0xFF);
- nextcolsum = (inptr0[inptr0_offset++] & 0xFF) * 3 + (inptr1[inptr1_offset++] & 0xFF);
- outptr[outptr_offset++] = (byte) ((thiscolsum * 4 + 8) >> 4);
- outptr[outptr_offset++] = (byte) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
- lastcolsum = thiscolsum; thiscolsum = nextcolsum;
-
- for (colctr = compptr.downsampled_width - 2; colctr > 0; colctr--) {
- /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
- /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
- nextcolsum = (inptr0[inptr0_offset++] & 0xFF) * 3 + (inptr1[inptr1_offset++] & 0xFF);
- outptr[outptr_offset++] = (byte) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
- outptr[outptr_offset++] = (byte) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
- lastcolsum = thiscolsum; thiscolsum = nextcolsum;
- }
-
- /* Special case for last column */
- outptr[outptr_offset++] = (byte) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
- outptr[outptr_offset++] = (byte) ((thiscolsum * 4 + 7) >> 4);
- }
- inrow++;
- }
-}
-
-static void int_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr,
- byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index)
-{
- jpeg_upsampler upsample = cinfo.upsample;
- byte[][] output_data = output_data_ptr[output_data_index];
- byte[] inptr, outptr;
- byte invalue;
- int h;
- int outend;
- int h_expand, v_expand;
- int inrow, outrow;
- output_data_offset[output_data_index] = 0;
-
- h_expand = upsample.h_expand[compptr.component_index];
- v_expand = upsample.v_expand[compptr.component_index];
-
- inrow = outrow = 0;
- while (outrow < cinfo.max_v_samp_factor) {
- /* Generate one output row with proper horizontal expansion */
- inptr = input_data[inrow+input_data_offset];
- int inptr_offset = 0;
- outptr = output_data[outrow];
- int outptr_offset = 0;
- outend = outptr_offset + cinfo.output_width;
- while (outptr_offset < outend) {
- invalue = inptr[inptr_offset++]; /* don't need GETJSAMPLE() here */
- for (h = h_expand; h > 0; h--) {
- outptr[outptr_offset++] = invalue;
- }
- }
- /* Generate any additional output rows by duplicating the first one */
- if (v_expand > 1) {
- jcopy_sample_rows(output_data, outrow, output_data, outrow+1, v_expand-1, cinfo.output_width);
- }
- inrow++;
- outrow += v_expand;
- }
-}
-
-static void null_convert (jpeg_decompress_struct cinfo,
- byte[][][] input_buf, int[] input_buf_offset, int input_row,
- byte[][] output_buf, int output_buf_offset, int num_rows)
-{
- byte[] inptr, outptr;
- int count;
- int num_components = cinfo.num_components;
- int num_cols = cinfo.output_width;
- int ci;
-
- while (--num_rows >= 0) {
- for (ci = 0; ci < num_components; ci++) {
- inptr = input_buf[ci][input_row+input_buf_offset[0]];
- outptr = output_buf[output_buf_offset];
- /* BGR instead of RGB */
- int offset = 0;
- switch (ci) {
- case 2: offset = RGB_BLUE; break;
- case 1: offset = RGB_GREEN; break;
- case 0: offset = RGB_RED; break;
- }
- int outptr_offset = offset, inptr_offset = 0;
- for (count = num_cols; count > 0; count--) {
- outptr[outptr_offset] = inptr[inptr_offset++]; /* needn't bother with GETJSAMPLE() here */
- outptr_offset += num_components;
- }
- }
- input_row++;
- output_buf_offset++;
- }
-}
-
-static void grayscale_convert (jpeg_decompress_struct cinfo,
- byte[][][] input_buf, int[] input_buf_offset, int input_row,
- byte[][] output_buf, int output_buf_offset, int num_rows)
-{
- jcopy_sample_rows(input_buf[0], input_row+input_buf_offset[0], output_buf, output_buf_offset,
- num_rows, cinfo.output_width);
-}
-
-static void gray_rgb_convert (jpeg_decompress_struct cinfo,
- byte[][][] input_buf, int[] input_buf_offset, int input_row,
- byte[][] output_buf, int output_buf_offset, int num_rows)
-{
- byte[] inptr, outptr;
- int col;
- int num_cols = cinfo.output_width;
-
- while (--num_rows >= 0) {
- inptr = input_buf[0][input_row+++input_buf_offset[0]];
- outptr = output_buf[output_buf_offset++];
- int outptr_offset = 0;
- for (col = 0; col < num_cols; col++) {
- /* We can dispense with GETJSAMPLE() here */
- outptr[RGB_RED+outptr_offset] = outptr[RGB_GREEN+outptr_offset] = outptr[RGB_BLUE+outptr_offset] = inptr[col];
- outptr_offset += RGB_PIXELSIZE;
- }
- }
-}
-
-static void ycc_rgb_convert (jpeg_decompress_struct cinfo,
- byte[][][] input_buf, int[] input_buf_offset, int input_row,
- byte[][] output_buf, int output_buf_offset, int num_rows)
-{
- jpeg_color_deconverter cconvert = cinfo.cconvert;
- int y, cb, cr;
- byte[] outptr;
- byte[] inptr0, inptr1, inptr2;
- int col;
- int num_cols = cinfo.output_width;
- /* copy these pointers into registers if possible */
- byte[] range_limit = cinfo.sample_range_limit;
- int range_limit_offset = cinfo.sample_range_limit_offset;
- int[] Crrtab = cconvert.Cr_r_tab;
- int[] Cbbtab = cconvert.Cb_b_tab;
- int[] Crgtab = cconvert.Cr_g_tab;
- int[] Cbgtab = cconvert.Cb_g_tab;
-// SHIFT_TEMPS
-
- while (--num_rows >= 0) {
- inptr0 = input_buf[0][input_row+input_buf_offset[0]];
- inptr1 = input_buf[1][input_row+input_buf_offset[1]];
- inptr2 = input_buf[2][input_row+input_buf_offset[2]];
- input_row++;
- outptr = output_buf[output_buf_offset++];
- int outptr_offset = 0;
- for (col = 0; col < num_cols; col++) {
- y = (inptr0[col] & 0xFF);
- cb = (inptr1[col] & 0xFF);
- cr = (inptr2[col] & 0xFF);
- /* Range-limiting is essential due to noise introduced by DCT losses. */
- outptr[outptr_offset + RGB_RED] = range_limit[y + Crrtab[cr] + range_limit_offset];
- outptr[outptr_offset + RGB_GREEN] = range_limit[y + ((Cbgtab[cb] + Crgtab[cr]>>SCALEBITS)) + range_limit_offset];
- outptr[outptr_offset + RGB_BLUE] = range_limit[y + Cbbtab[cb] + range_limit_offset];
- outptr_offset += RGB_PIXELSIZE;
- }
- }
-}
-
-static boolean process_APPn(int n, jpeg_decompress_struct cinfo) {
- if (n == 0 || n == 14) {
- return get_interesting_appn(cinfo);
- }
- return skip_variable(cinfo);
-}
-
-static boolean process_COM(jpeg_decompress_struct cinfo) {
- return skip_variable(cinfo);
-}
-
-static void skip_input_data (jpeg_decompress_struct cinfo, int num_bytes) {
- if (num_bytes > 0) {
- while (num_bytes > cinfo.bytes_in_buffer - cinfo.bytes_offset) {
- num_bytes -= cinfo.bytes_in_buffer - cinfo.bytes_offset;
- if (!fill_input_buffer(cinfo)) error();
- /* note we assume that fill_input_buffer will never return FALSE,
- * so suspension need not be handled.
- */
- }
- cinfo.bytes_offset += num_bytes;
- }
-}
-
-static boolean skip_variable (jpeg_decompress_struct cinfo)
-/* Skip over an unknown or uninteresting variable-length marker */
-{
- int length;
-
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
-
- length -= 2;
-
-// TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo.unread_marker, (int) length);
-
- if (length > 0) {
- skip_input_data (cinfo, length);
- }
-
- return true;
-}
-
-static boolean get_interesting_appn (jpeg_decompress_struct cinfo)
-/* Process an APP0 or APP14 marker without saving it */
-{
- int length;
- byte[] b = new byte[APPN_DATA_LEN];
- int i, numtoread;
-
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- length -= 2;
-
- /* get the interesting part of the marker data */
- if (length >= APPN_DATA_LEN)
- numtoread = APPN_DATA_LEN;
- else if (length > 0)
- numtoread = length;
- else
- numtoread = 0;
- for (i = 0; i < numtoread; i++) {
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- b[i] = cinfo.buffer[cinfo.bytes_offset++];
- }
- length -= numtoread;
-
- /* process it */
- switch (cinfo.unread_marker) {
- case M_APP0:
- examine_app0(cinfo, b, numtoread, length);
- break;
- case M_APP14:
- examine_app14(cinfo, b, numtoread, length);
- break;
- default:
- /* can't get here unless jpeg_save_markers chooses wrong processor */
- error();
-// ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo.unread_marker);
- break;
- }
-
- /* skip any remaining data -- could be lots */
- if (length > 0)
- skip_input_data (cinfo, length);
-
- return true;
-}
-
-static void examine_app0 (jpeg_decompress_struct cinfo, byte[] data, int datalen, int remaining)
-/* Examine first few bytes from an APP0.
- * Take appropriate action if it is a JFIF marker.
- * datalen is # of bytes at data[], remaining is length of rest of marker data.
- */
-{
- int totallen = datalen + remaining;
-
- if (datalen >= APP0_DATA_LEN &&
- (data[0] & 0xFF) == 0x4A &&
- (data[1] & 0xFF) == 0x46 &&
- (data[2] & 0xFF) == 0x49 &&
- (data[3] & 0xFF) == 0x46 &&
- (data[4] & 0xFF) == 0)
- {
- /* Found JFIF APP0 marker: save info */
- cinfo.saw_JFIF_marker = true;
- cinfo.JFIF_major_version = (data[5]);
- cinfo.JFIF_minor_version = (byte)(data[6] & 0xFF);
- cinfo.density_unit = (byte)(data[7] & 0xFF);
- cinfo.X_density = (short)(((data[8] & 0xFF) << 8) + (data[9] & 0xFF));
- cinfo.Y_density = (short)(((data[10] & 0xFF) << 8) + (data[11] & 0xFF));
- /* Check version.
- * Major version must be 1, anything else signals an incompatible change.
- * (We used to treat this as an error, but now it's a nonfatal warning,
- * because some bozo at Hijaak couldn't read the spec.)
- * Minor version should be 0..2, but process anyway if newer.
- */
- if (cinfo.JFIF_major_version != 1) {
-// WARNMS2(cinfo, JWRN_JFIF_MAJOR,
-// cinfo.JFIF_major_version, cinfo.JFIF_minor_version);
- }
- /* Generate trace messages */
-// TRACEMS5(cinfo, 1, JTRC_JFIF,
-// cinfo.JFIF_major_version, cinfo.JFIF_minor_version,
-// cinfo.X_density, cinfo.Y_density, cinfo.density_unit);
- /* Validate thumbnail dimensions and issue appropriate messages */
- if (((data[12] & 0xFF) | (data[13]) & 0xFF) != 0) {
-// TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
-// GETJOCTET(data[12]), GETJOCTET(data[13]));
- }
- totallen -= APP0_DATA_LEN;
- if (totallen != ((data[12] & 0xFF) * (data[13] & 0xFF) * 3)) {
-// TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
- }
- } else if (datalen >= 6 &&
- (data[0] & 0xFF) == 0x4A &&
- (data[1] & 0xFF) == 0x46 &&
- (data[2] & 0xFF) == 0x58 &&
- (data[3] & 0xFF) == 0x58 &&
- (data[4] & 0xFF) == 0)
- {
- /* Found JFIF "JFXX" extension APP0 marker */
- /* The library doesn't actually do anything with these,
- * but we try to produce a helpful trace message.
- */
- switch ((data[5]) & 0xFF) {
- case 0x10:
-// TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
- break;
- case 0x11:
-// TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
- break;
- case 0x13:
-// TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
- break;
- default:
-// TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION, GETJOCTET(data[5]), (int) totallen);
- break;
- }
- } else {
- /* Start of APP0 does not match "JFIF" or "JFXX", or too short */
-// TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
- }
-}
-
-static void examine_app14 (jpeg_decompress_struct cinfo, byte[] data, int datalen, int remaining)
-/* Examine first few bytes from an APP14.
- * Take appropriate action if it is an Adobe marker.
- * datalen is # of bytes at data[], remaining is length of rest of marker data.
- */
-{
- int /*version, flags0, flags1, */transform;
-
- if (datalen >= APP14_DATA_LEN &&
- (data[0] & 0xFF) == 0x41 &&
- (data[1] & 0xFF) == 0x64 &&
- (data[2] & 0xFF) == 0x6F &&
- (data[3] & 0xFF) == 0x62 &&
- (data[4] & 0xFF) == 0x65)
- {
- /* Found Adobe APP14 marker */
-// version = ((data[5] & 0xFF) << 8) + (data[6] & 0xFF);
-// flags0 = ((data[7] & 0xFF) << 8) + (data[8] & 0xFF);
-// flags1 = ((data[9] & 0xFF) << 8) + (data[10] & 0xFF);
- transform = (data[11] & 0xFF);
-// TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
- cinfo.saw_Adobe_marker = true;
- cinfo.Adobe_transform = (byte) transform;
- } else {
- /* Start of APP14 does not match "Adobe", or too short */
-// TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
- }
-}
-
-static boolean get_soi (jpeg_decompress_struct cinfo) /* Process an SOI marker */ {
- int i;
-
-// TRACEMS(cinfo, 1, JTRC_SOI);
-
- if (cinfo.marker.saw_SOI)
- error();
-// ERREXIT(cinfo, JERR_SOI_DUPLICATE);
-
- /* Reset all parameters that are defined to be reset by SOI */
-
- for (i = 0; i < NUM_ARITH_TBLS; i++) {
- cinfo.arith_dc_L[i] = 0;
- cinfo.arith_dc_U[i] = 1;
- cinfo.arith_ac_K[i] = 5;
- }
- cinfo.restart_interval = 0;
-
- /* Set initial assumptions for colorspace etc */
-
- cinfo.jpeg_color_space = JCS_UNKNOWN;
- cinfo.CCIR601_sampling = false; /* Assume non-CCIR sampling??? */
-
- cinfo.saw_JFIF_marker = false;
- cinfo.JFIF_major_version = 1; /* set default JFIF APP0 values */
- cinfo.JFIF_minor_version = 1;
- cinfo.density_unit = 0;
- cinfo.X_density = 1;
- cinfo.Y_density = 1;
- cinfo.saw_Adobe_marker = false;
- cinfo.Adobe_transform = 0;
-
- cinfo.marker.saw_SOI = true;
-
- return true;
-}
-
-static void jinit_input_controller (jpeg_decompress_struct cinfo)
-{
- /* Initialize state: can't use reset_input_controller since we don't
- * want to try to reset other modules yet.
- */
- jpeg_input_controller inputctl = cinfo.inputctl = new jpeg_input_controller();
- inputctl.has_multiple_scans = false; /* "unknown" would be better */
- inputctl.eoi_reached = false;
- inputctl.inheaders = true;
-}
-
-static void reset_marker_reader (jpeg_decompress_struct cinfo) {
- jpeg_marker_reader marker = cinfo.marker;
-
- cinfo.comp_info = null; /* until allocated by get_sof */
- cinfo.input_scan_number = 0; /* no SOS seen yet */
- cinfo.unread_marker = 0; /* no pending marker */
- marker.saw_SOI = false; /* set internal state too */
- marker.saw_SOF = false;
- marker.discarded_bytes = 0;
-// marker.cur_marker = null;
-}
-
-static void reset_input_controller (jpeg_decompress_struct cinfo) {
- jpeg_input_controller inputctl = cinfo.inputctl;
-
- inputctl.has_multiple_scans = false; /* "unknown" would be better */
- inputctl.eoi_reached = false;
- inputctl.inheaders = true;
- /* Reset other modules */
- reset_marker_reader (cinfo);
- /* Reset progression state -- would be cleaner if entropy decoder did this */
- cinfo.coef_bits = null;
-}
-
-static void finish_output_pass (jpeg_decompress_struct cinfo) {
- jpeg_decomp_master master = cinfo.master;
-
- if (cinfo.quantize_colors) {
- error(SWT.ERROR_NOT_IMPLEMENTED);
-// (*cinfo.cquantize.finish_pass) (cinfo);
- }
- master.pass_number++;
-}
-
-static void jpeg_destroy (jpeg_decompress_struct cinfo) {
- /* We need only tell the memory manager to release everything. */
- /* NB: mem pointer is NULL if memory mgr failed to initialize. */
-// if (cinfo.mem != NULL)
-// (*cinfo.mem.self_destruct) (cinfo);
-// cinfo.mem = NULL; /* be safe if jpeg_destroy is called twice */
- cinfo.global_state = 0; /* mark it destroyed */
-}
-
-static void jpeg_destroy_decompress (jpeg_decompress_struct cinfo) {
- jpeg_destroy(cinfo); /* use common routine */
-}
-
-static boolean jpeg_input_complete (jpeg_decompress_struct cinfo) {
- /* Check for valid jpeg object */
- if (cinfo.global_state < DSTATE_START || cinfo.global_state > DSTATE_STOPPING)
- error();
-// ERREXIT1(cinfo, JERR_BAD_STATE, cinfo.global_state);
- return cinfo.inputctl.eoi_reached;
-}
-
-static boolean jpeg_start_output (jpeg_decompress_struct cinfo, int scan_number) {
- if (cinfo.global_state != DSTATE_BUFIMAGE && cinfo.global_state != DSTATE_PRESCAN)
- error();
-// ERREXIT1(cinfo, JERR_BAD_STATE, cinfo.global_state);
- /* Limit scan number to valid range */
- if (scan_number <= 0)
- scan_number = 1;
- if (cinfo.inputctl.eoi_reached && scan_number > cinfo.input_scan_number)
- scan_number = cinfo.input_scan_number;
- cinfo.output_scan_number = scan_number;
- /* Perform any dummy output passes, and set up for the real pass */
- return output_pass_setup(cinfo);
-}
-
-static boolean jpeg_finish_output (jpeg_decompress_struct cinfo) {
- if ((cinfo.global_state == DSTATE_SCANNING || cinfo.global_state == DSTATE_RAW_OK) && cinfo.buffered_image) {
- /* Terminate this pass. */
- /* We do not require the whole pass to have been completed. */
- finish_output_pass (cinfo);
- cinfo.global_state = DSTATE_BUFPOST;
- } else if (cinfo.global_state != DSTATE_BUFPOST) {
- /* BUFPOST = repeat call after a suspension, anything else is error */
- error();
-// ERREXIT1(cinfo, JERR_BAD_STATE, cinfo.global_state);
- }
- /* Read markers looking for SOS or EOI */
- while (cinfo.input_scan_number <= cinfo.output_scan_number && !cinfo.inputctl.eoi_reached) {
- if (consume_input (cinfo) == JPEG_SUSPENDED)
- return false; /* Suspend, come back later */
- }
- cinfo.global_state = DSTATE_BUFIMAGE;
- return true;
-}
-
-static boolean jpeg_finish_decompress (jpeg_decompress_struct cinfo) {
- if ((cinfo.global_state == DSTATE_SCANNING || cinfo.global_state == DSTATE_RAW_OK) && ! cinfo.buffered_image) {
- /* Terminate final pass of non-buffered mode */
- if (cinfo.output_scanline < cinfo.output_height)
- error();
-// ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
- finish_output_pass (cinfo);
- cinfo.global_state = DSTATE_STOPPING;
- } else if (cinfo.global_state == DSTATE_BUFIMAGE) {
- /* Finishing after a buffered-image operation */
- cinfo.global_state = DSTATE_STOPPING;
- } else if (cinfo.global_state != DSTATE_STOPPING) {
- /* STOPPING = repeat call after a suspension, anything else is error */
- error();
-// ERREXIT1(cinfo, JERR_BAD_STATE, cinfo.global_state);
- }
- /* Read until EOI */
- while (! cinfo.inputctl.eoi_reached) {
- if (consume_input (cinfo) == JPEG_SUSPENDED)
- return false; /* Suspend, come back later */
- }
- /* Do final cleanup */
-// (*cinfo.src.term_source) (cinfo);
- /* We can use jpeg_abort to release memory and reset global_state */
- jpeg_abort(cinfo);
- return true;
-}
-
-
-static int jpeg_read_header (jpeg_decompress_struct cinfo, boolean require_image) {
- int retcode;
-
- if (cinfo.global_state != DSTATE_START && cinfo.global_state != DSTATE_INHEADER)
- error();
-// ERREXIT1(cinfo, JERR_BAD_STATE, cinfo.global_state);
-
- retcode = jpeg_consume_input(cinfo);
-
- switch (retcode) {
- case JPEG_REACHED_SOS:
- retcode = JPEG_HEADER_OK;
- break;
- case JPEG_REACHED_EOI:
- if (require_image) /* Complain if application wanted an image */
- error();
-// ERREXIT(cinfo, JERR_NO_IMAGE);
- /* Reset to start state; it would be safer to require the application to
- * call jpeg_abort, but we can't change it now for compatibility reasons.
- * A side effect is to free any temporary memory (there shouldn't be any).
- */
- jpeg_abort(cinfo); /* sets state = DSTATE_START */
- retcode = JPEG_HEADER_TABLES_ONLY;
- break;
- case JPEG_SUSPENDED:
- /* no work */
- break;
- }
-
- return retcode;
-}
-
-static int dummy_consume_data (jpeg_decompress_struct cinfo) {
- return JPEG_SUSPENDED; /* Always indicate nothing was done */
-}
-
-static int consume_data (jpeg_decompress_struct cinfo) {
- jpeg_d_coef_controller coef = cinfo.coef;
- int MCU_col_num; /* index of current MCU within row */
- int blkn, ci, xindex, yindex, yoffset;
- int start_col;
-// short[][][][] buffer = new short[MAX_COMPS_IN_SCAN][][][];
- short[][] buffer_ptr;
- jpeg_component_info compptr;
-
-// /* Align the virtual buffers for the components used in this scan. */
-// for (ci = 0; ci < cinfo.comps_in_scan; ci++) {
-// compptr = cinfo.cur_comp_info[ci];
-// buffer[ci] = coef.whole_image[compptr.component_index];
-// /* Note: entropy decoder expects buffer to be zeroed,
-// * but this is handled automatically by the memory manager
-// * because we requested a pre-zeroed array.
-// */
-// }
-
- /* Loop to process one whole iMCU row */
- for (yoffset = coef.MCU_vert_offset; yoffset < coef.MCU_rows_per_iMCU_row; yoffset++) {
- for (MCU_col_num = coef.MCU_ctr; MCU_col_num < cinfo.MCUs_per_row; MCU_col_num++) {
- /* Construct list of pointers to DCT blocks belonging to this MCU */
- blkn = 0; /* index of current DCT block within MCU */
- for (ci = 0; ci < cinfo.comps_in_scan; ci++) {
- compptr = cinfo.cur_comp_info[ci];
- start_col = MCU_col_num * compptr.MCU_width;
- for (yindex = 0; yindex < compptr.MCU_height; yindex++) {
-// buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
- buffer_ptr = coef.whole_image[compptr.component_index][yindex+yoffset+cinfo.input_iMCU_row*compptr.v_samp_factor];
- int buffer_ptr_offset = start_col;
- for (xindex = 0; xindex < compptr.MCU_width; xindex++) {
- coef.MCU_buffer[blkn++] = buffer_ptr[buffer_ptr_offset++];
- }
- }
- }
- /* Try to fetch the MCU. */
- if (! cinfo.entropy.decode_mcu (cinfo, coef.MCU_buffer)) {
- /* Suspension forced; update state counters and exit */
- coef.MCU_vert_offset = yoffset;
- coef.MCU_ctr = MCU_col_num;
- return JPEG_SUSPENDED;
- }
- }
- /* Completed an MCU row, but perhaps not an iMCU row */
- coef.MCU_ctr = 0;
- }
- /* Completed the iMCU row, advance counters for next one */
- if (++(cinfo.input_iMCU_row) < cinfo.total_iMCU_rows) {
- coef.start_iMCU_row(cinfo);
- return JPEG_ROW_COMPLETED;
- }
- /* Completed the scan */
- finish_input_pass (cinfo);
- return JPEG_SCAN_COMPLETED;
-}
-
-static int consume_input (jpeg_decompress_struct cinfo) {
- switch (cinfo.inputctl.consume_input) {
- case COEF_CONSUME_INPUT:
- switch (cinfo.coef.consume_data) {
- case CONSUME_DATA: return consume_data(cinfo);
- case DUMMY_CONSUME_DATA: return dummy_consume_data(cinfo);
- default: error();
- }
- break;
- case INPUT_CONSUME_INPUT:
- return consume_markers(cinfo);
- default:
- error();
- }
- return 0;
-}
-
-static boolean fill_input_buffer(jpeg_decompress_struct cinfo) {
- try {
- InputStream inputStream = cinfo.inputStream;
- int nbytes = inputStream.read(cinfo.buffer);
- if (nbytes <= 0) {
- if (cinfo.start_of_file) /* Treat empty input file as fatal error */
- error();
-// ERREXIT(cinfo, JERR_INPUT_EMPTY);
-// WARNMS(cinfo, JWRN_JPEG_EOF);
- /* Insert a fake EOI marker */
- cinfo.buffer[0] = (byte)0xFF;
- cinfo.buffer[1] = (byte)M_EOI;
- nbytes = 2;
- }
- cinfo.bytes_in_buffer = nbytes;
- cinfo.bytes_offset = 0;
- cinfo.start_of_file = false;
- } catch (IOException e) {
- error(SWT.ERROR_IO);
- return false;
- }
- return true;
-}
-
-static boolean first_marker (jpeg_decompress_struct cinfo) {
- /* Like next_marker, but used to obtain the initial SOI marker. */
- /* For this marker, we do not allow preceding garbage or fill; otherwise,
- * we might well scan an entire input file before realizing it ain't JPEG.
- * If an application wants to process non-JFIF files, it must seek to the
- * SOI before calling the JPEG library.
- */
- int c, c2;
-
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- c2 = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- if (c != 0xFF || c2 != M_SOI)
- error();
-// ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
-
- cinfo.unread_marker = c2;
-
- return true;
-}
-
-static boolean next_marker (jpeg_decompress_struct cinfo) {
- int c;
-
- for (;;) {
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- /* Skip any non-FF bytes.
- * This may look a bit inefficient, but it will not occur in a valid file.
- * We sync after each discarded byte so that a suspending data source
- * can discard the byte from its buffer.
- */
- while (c != 0xFF) {
- cinfo.marker.discarded_bytes++;
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- }
- /* This loop swallows any duplicate FF bytes. Extra FFs are legal as
- * pad bytes, so don't count them in discarded_bytes. We assume there
- * will not be so many consecutive FF bytes as to overflow a suspending
- * data source's input buffer.
- */
- do {
- if (cinfo.bytes_offset == cinfo.bytes_in_buffer) fill_input_buffer(cinfo);
- c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF;
- } while (c == 0xFF);
- if (c != 0)
- break; /* found a valid marker, exit loop */
- /* Reach here if we found a stuffed-zero data sequence (FF/00).
- * Discard it and loop back to try again.
- */
- cinfo.marker.discarded_bytes += 2;
- }
-
- if (cinfo.marker.discarded_bytes != 0) {
-// WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo.marker.discarded_bytes, c);
- cinfo.marker.discarded_bytes = 0;
- }
-
- cinfo.unread_marker = c;
-
- return true;
-}
-
-static int read_markers (jpeg_decompress_struct cinfo) {
- /* Outer loop repeats once for each marker. */
- for (;;) {
- /* Collect the marker proper, unless we already did. */
- /* NB: first_marker() enforces the requirement that SOI appear first. */
- if (cinfo.unread_marker == 0) {
- if (! cinfo.marker.saw_SOI) {
- if (! first_marker(cinfo))
- return JPEG_SUSPENDED;
- } else {
- if (! next_marker(cinfo))
- return JPEG_SUSPENDED;
- }
- }
- /* At this point cinfo.unread_marker contains the marker code and the
- * input point is just past the marker proper, but before any parameters.
- * A suspension will cause us to return with this state still true.
- */
- switch (cinfo.unread_marker) {
- case M_SOI:
- if (! get_soi(cinfo))
- return JPEG_SUSPENDED;
- break;
-
- case M_SOF0: /* Baseline */
- case M_SOF1: /* Extended sequential, Huffman */
- if (! get_sof(cinfo, false, false))
- return JPEG_SUSPENDED;
- break;
-
- case M_SOF2: /* Progressive, Huffman */
- if (! get_sof(cinfo, true, false))
- return JPEG_SUSPENDED;
- break;
-
- case M_SOF9: /* Extended sequential, arithmetic */
- if (! get_sof(cinfo, false, true))
- return JPEG_SUSPENDED;
- break;
-
- case M_SOF10: /* Progressive, arithmetic */
- if (! get_sof(cinfo, true, true))
- return JPEG_SUSPENDED;
- break;
-
- /* Currently unsupported SOFn types */
- case M_SOF3: /* Lossless, Huffman */
- case M_SOF5: /* Differential sequential, Huffman */
- case M_SOF6: /* Differential progressive, Huffman */
- case M_SOF7: /* Differential lossless, Huffman */
- case M_JPG: /* Reserved for JPEG extensions */
- case M_SOF11: /* Lossless, arithmetic */
- case M_SOF13: /* Differential sequential, arithmetic */
- case M_SOF14: /* Differential progressive, arithmetic */
- case M_SOF15: /* Differential lossless, arithmetic */
- error();
-// ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo.unread_marker);
- break;
-
- case M_SOS:
- if (! get_sos(cinfo))
- return JPEG_SUSPENDED;
- cinfo.unread_marker = 0; /* processed the marker */
- return JPEG_REACHED_SOS;
-
- case M_EOI:
-// TRACEMS(cinfo, 1, JTRC_EOI);
- cinfo.unread_marker = 0; /* processed the marker */
- return JPEG_REACHED_EOI;
-
- case M_DAC:
- if (! get_dac(cinfo))
- return JPEG_SUSPENDED;
- break;
-
- case M_DHT:
- if (! get_dht(cinfo))
- return JPEG_SUSPENDED;
- break;
-
- case M_DQT:
- if (! get_dqt(cinfo))
- return JPEG_SUSPENDED;
- break;
-
- case M_DRI:
- if (! get_dri(cinfo))
- return JPEG_SUSPENDED;
- break;
-
- case M_APP0:
- case M_APP1:
- case M_APP2:
- case M_APP3:
- case M_APP4:
- case M_APP5:
- case M_APP6:
- case M_APP7:
- case M_APP8:
- case M_APP9:
- case M_APP10:
- case M_APP11:
- case M_APP12:
- case M_APP13:
- case M_APP14:
- case M_APP15:
- if (! process_APPn(cinfo.unread_marker - M_APP0, cinfo))
- return JPEG_SUSPENDED;
- break;
-
- case M_COM:
- if (! process_COM(cinfo))
- return JPEG_SUSPENDED;
- break;
-
- case M_RST0: /* these are all parameterless */
- case M_RST1:
- case M_RST2:
- case M_RST3:
- case M_RST4:
- case M_RST5:
- case M_RST6:
- case M_RST7:
- case M_TEM:
-// TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo.unread_marker);
- break;
-
- case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
- if (! skip_variable(cinfo))
- return JPEG_SUSPENDED;
- break;
-
- default: /* must be DHP, EXP, JPGn, or RESn */
- /* For now, we treat the reserved markers as fatal errors since they are
- * likely to be used to signal incompatible JPEG Part 3 extensions.
- * Once the JPEG 3 version-number marker is well defined, this code
- * ought to change!
- */
- error();
- // ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo.unread_marker);
- break;
- }
- /* Successfully processed marker, so reset state variable */
- cinfo.unread_marker = 0;
- } /* end loop */
-}
-
-static long jdiv_round_up (long a, long b)
-/* Compute a/b rounded up to next integer, ie, ceil(a/b) */
-/* Assumes a >= 0, b > 0 */
-{
- return (a + b - 1) / b;
-}
-
-static void initial_setup (jpeg_decompress_struct cinfo)
-/* Called once, when first SOS marker is reached */
-{
- int ci;
- jpeg_component_info compptr;
-
- /* Make sure image isn't bigger than I can handle */
- if (cinfo.image_height > JPEG_MAX_DIMENSION || cinfo.image_width > JPEG_MAX_DIMENSION)
- error();
-// ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
-
- /* For now, precision must match compiled-in value... */
- if (cinfo.data_precision != BITS_IN_JSAMPLE)
- error(" [data precision=" + cinfo.data_precision + "]");
-// ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo.data_precision);
-
- /* Check that number of components won't exceed internal array sizes */
- if (cinfo.num_components > MAX_COMPONENTS)
- error();
-// ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo.num_components, MAX_COMPONENTS);
-
- /* Compute maximum sampling factors; check factor validity */
- cinfo.max_h_samp_factor = 1;
- cinfo.max_v_samp_factor = 1;
- for (ci = 0; ci < cinfo.num_components; ci++) {
- compptr = cinfo.comp_info[ci];
- if (compptr.h_samp_factor<=0 || compptr.h_samp_factor>MAX_SAMP_FACTOR || compptr.v_samp_factor<=0 || compptr.v_samp_factor>MAX_SAMP_FACTOR)
- error();
-// ERREXIT(cinfo, JERR_BAD_SAMPLING);
- cinfo.max_h_samp_factor = Math.max(cinfo.max_h_samp_factor, compptr.h_samp_factor);
- cinfo.max_v_samp_factor = Math.max(cinfo.max_v_samp_factor, compptr.v_samp_factor);
- }
-
- /* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE.
- * In the full decompressor, this will be overridden by jdmaster.c;
- * but in the transcoder, jdmaster.c is not used, so we must do it here.
- */
- cinfo.min_DCT_scaled_size = DCTSIZE;
-
- /* Compute dimensions of components */
- for (ci = 0; ci < cinfo.num_components; ci++) {
- compptr = cinfo.comp_info[ci];
- compptr.DCT_scaled_size = DCTSIZE;
- /* Size in DCT blocks */
- compptr.width_in_blocks = (int)jdiv_round_up((long) cinfo.image_width * (long) compptr.h_samp_factor, (cinfo.max_h_samp_factor * DCTSIZE));
- compptr.height_in_blocks = (int)jdiv_round_up((long) cinfo.image_height * (long) compptr.v_samp_factor, (cinfo.max_v_samp_factor * DCTSIZE));
- /* downsampled_width and downsampled_height will also be overridden by
- * jdmaster.c if we are doing full decompression. The transcoder library
- * doesn't use these values, but the calling application might.
- */
- /* Size in samples */
- compptr.downsampled_width = (int)jdiv_round_up((long) cinfo.image_width * (long) compptr.h_samp_factor, cinfo.max_h_samp_factor);
- compptr.downsampled_height = (int)jdiv_round_up((long) cinfo.image_height * (long) compptr.v_samp_factor, cinfo.max_v_samp_factor);
- /* Mark component needed, until color conversion says otherwise */
- compptr.component_needed = true;
- /* Mark no quantization table yet saved for component */
- compptr.quant_table = null;
- }
-
- /* Compute number of fully interleaved MCU rows. */
- cinfo.total_iMCU_rows = (int)jdiv_round_up( cinfo.image_height, (cinfo.max_v_samp_factor*DCTSIZE));
-
- /* Decide whether file contains multiple scans */
- if (cinfo.comps_in_scan < cinfo.num_components || cinfo.progressive_mode)
- cinfo.inputctl.has_multiple_scans = true;
- else
- cinfo.inputctl.has_multiple_scans = false;
-}
-
-
-static void per_scan_setup (jpeg_decompress_struct cinfo)
-/* Do computations that are needed before processing a JPEG scan */
-/* cinfo.comps_in_scan and cinfo.cur_comp_info[] were set from SOS marker */
-{
- int ci, mcublks, tmp = 0;
- jpeg_component_info compptr;
-
- if (cinfo.comps_in_scan == 1) {
-
- /* Noninterleaved (single-component) scan */
- compptr = cinfo.cur_comp_info[0];
-
- /* Overall image size in MCUs */
- cinfo.MCUs_per_row = compptr.width_in_blocks;
- cinfo.MCU_rows_in_scan = compptr.height_in_blocks;
-
- /* For noninterleaved scan, always one block per MCU */
- compptr.MCU_width = 1;
- compptr.MCU_height = 1;
- compptr.MCU_blocks = 1;
- compptr.MCU_sample_width = compptr.DCT_scaled_size;
- compptr.last_col_width = 1;
- /* For noninterleaved scans, it is convenient to define last_row_height
- * as the number of block rows present in the last iMCU row.
- */
- tmp = (compptr.height_in_blocks % compptr.v_samp_factor);
- if (tmp == 0) tmp = compptr.v_samp_factor;
- compptr.last_row_height = tmp;
-
- /* Prepare array describing MCU composition */
- cinfo.blocks_in_MCU = 1;
- cinfo.MCU_membership[0] = 0;
-
- } else {
-
- /* Interleaved (multi-component) scan */
- if (cinfo.comps_in_scan <= 0 || cinfo.comps_in_scan > MAX_COMPS_IN_SCAN)
- error();
-// ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo.comps_in_scan, MAX_COMPS_IN_SCAN);
-
- /* Overall image size in MCUs */
- cinfo.MCUs_per_row = (int)jdiv_round_up( cinfo.image_width, (cinfo.max_h_samp_factor*DCTSIZE));
- cinfo.MCU_rows_in_scan = (int)jdiv_round_up( cinfo.image_height, (cinfo.max_v_samp_factor*DCTSIZE));
-
- cinfo.blocks_in_MCU = 0;
-
- for (ci = 0; ci < cinfo.comps_in_scan; ci++) {
- compptr = cinfo.cur_comp_info[ci];
- /* Sampling factors give # of blocks of component in each MCU */
- compptr.MCU_width = compptr.h_samp_factor;
- compptr.MCU_height = compptr.v_samp_factor;
- compptr.MCU_blocks = compptr.MCU_width * compptr.MCU_height;
- compptr.MCU_sample_width = compptr.MCU_width * compptr.DCT_scaled_size;
- /* Figure number of non-dummy blocks in last MCU column & row */
- tmp = (compptr.width_in_blocks % compptr.MCU_width);
- if (tmp == 0) tmp = compptr.MCU_width;
- compptr.last_col_width = tmp;
- tmp = (compptr.height_in_blocks % compptr.MCU_height);
- if (tmp == 0) tmp = compptr.MCU_height;
- compptr.last_row_height = tmp;
- /* Prepare array describing MCU composition */
- mcublks = compptr.MCU_blocks;
- if (cinfo.blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
- error();
-// ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
- while (mcublks-- > 0) {
- cinfo.MCU_membership[cinfo.blocks_in_MCU++] = ci;
- }
- }
-
- }
-}
-
-static void latch_quant_tables (jpeg_decompress_struct cinfo) {
- int ci, qtblno;
- jpeg_component_info compptr;
- JQUANT_TBL qtbl;
-
- for (ci = 0; ci < cinfo.comps_in_scan; ci++) {
- compptr = cinfo.cur_comp_info[ci];
- /* No work if we already saved Q-table for this component */
- if (compptr.quant_table != null)
- continue;
- /* Make sure specified quantization table is present */
- qtblno = compptr.quant_tbl_no;
- if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS || cinfo.quant_tbl_ptrs[qtblno] == null)
- error();
-// ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
- /* OK, save away the quantization table */
- qtbl = new JQUANT_TBL();
- System.arraycopy(cinfo.quant_tbl_ptrs[qtblno].quantval, 0, qtbl.quantval, 0, qtbl.quantval.length);
- qtbl.sent_table = cinfo.quant_tbl_ptrs[qtblno].sent_table;
- compptr.quant_table = qtbl;
- }
-}
-
-static void jpeg_make_d_derived_tbl (jpeg_decompress_struct cinfo, boolean isDC, int tblno, d_derived_tbl dtbl) {
- JHUFF_TBL htbl;
- int p, i = 0, l, si, numsymbols;
- int lookbits, ctr;
- byte[] huffsize = new byte[257];
- int[] huffcode = new int[257];
- int code;
-
- /* Note that huffsize[] and huffcode[] are filled in code-length order,
- * paralleling the order of the symbols themselves in htbl.huffval[].
- */
-
- /* Find the input Huffman table */
- if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
- error();
-// ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
- htbl = isDC ? cinfo.dc_huff_tbl_ptrs[tblno] : cinfo.ac_huff_tbl_ptrs[tblno];
- if (htbl == null)
- error();
-// ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
-
- /* Allocate a workspace if we haven't already done so. */
- dtbl.pub = htbl; /* fill in back link */
-
- /* Figure C.1: make table of Huffman code length for each symbol */
-
- p = 0;
- for (l = 1; l <= 16; l++) {
- i = htbl.bits[l] & 0xFF;
- if (i < 0 || p + i > 256) /* protect against table overrun */
- error();
-// ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
- while (i-- != 0)
- huffsize[p++] = (byte) l;
- }
- huffsize[p] = 0;
- numsymbols = p;
-
- /* Figure C.2: generate the codes themselves */
- /* We also validate that the counts represent a legal Huffman code tree. */
-
- code = 0;
- si = huffsize[0];
- p = 0;
- while ((huffsize[p]) != 0) {
- while (( huffsize[p]) == si) {
- huffcode[p++] = code;
- code++;
- }
- /* code is now 1 more than the last code used for codelength si; but
- * it must still fit in si bits, since no code is allowed to be all ones.
- */
- if (( code) >= (( 1) << si))
- error();
-// ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
- code <<= 1;
- si++;
- }
-
- /* Figure F.15: generate decoding tables for bit-sequential decoding */
-
- p = 0;
- for (l = 1; l <= 16; l++) {
- if ((htbl.bits[l] & 0xFF) != 0) {
- /* valoffset[l] = huffval[] index of 1st symbol of code length l,
- * minus the minimum code of length l
- */
- dtbl.valoffset[l] = p - huffcode[p];
- p += (htbl.bits[l] & 0xFF);
- dtbl.maxcode[l] = huffcode[p-1]; /* maximum code of length l */
- } else {
- dtbl.maxcode[l] = -1; /* -1 if no codes of this length */
- }
- }
- dtbl.maxcode[17] = 0xFFFFF; /* ensures jpeg_huff_decode terminates */
-
- /* Compute lookahead tables to speed up decoding.
- * First we set all the table entries to 0, indicating "too long";
- * then we iterate through the Huffman codes that are short enough and
- * fill in all the entries that correspond to bit sequences starting
- * with that code.
- */
-
- for (int j = 0; j < dtbl.look_nbits.length; j++) {
- dtbl.look_nbits[j] = 0;
- }
-
- p = 0;
- for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
- for (i = 1; i <= (htbl.bits[l] & 0xFF); i++, p++) {
- /* l = current code's length, p = its index in huffcode[] & huffval[]. */
- /* Generate left-justified code followed by all possible bit sequences */
- lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
- for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
- dtbl.look_nbits[lookbits] = l;
- dtbl.look_sym[lookbits] = htbl.huffval[p];
- lookbits++;
- }
- }
- }
-
- /* Validate symbols as being reasonable.
- * For AC tables, we make no check, but accept all byte values 0..255.
- * For DC tables, we require the symbols to be in range 0..15.
- * (Tighter bounds could be applied depending on the data depth and mode,
- * but this is sufficient to ensure safe decoding.)
- */
- if (isDC) {
- for (i = 0; i < numsymbols; i++) {
- int sym = htbl.huffval[i] & 0xFF;
- if (sym < 0 || sym > 15)
- error();
-// ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
- }
- }
-}
-
-static void start_input_pass (jpeg_decompress_struct cinfo) {
- per_scan_setup(cinfo);
- latch_quant_tables(cinfo);
- cinfo.entropy.start_pass(cinfo);
- cinfo.coef.start_input_pass (cinfo);
- cinfo.inputctl.consume_input = COEF_CONSUME_INPUT;
-}
-
-static void finish_input_pass (jpeg_decompress_struct cinfo) {
- cinfo.inputctl.consume_input = INPUT_CONSUME_INPUT;
-}
-
-static int consume_markers (jpeg_decompress_struct cinfo) {
- jpeg_input_controller inputctl = cinfo.inputctl;
- int val;
-
- if (inputctl.eoi_reached) /* After hitting EOI, read no further */
- return JPEG_REACHED_EOI;
-
- val = read_markers (cinfo);
-
- switch (val) {
- case JPEG_REACHED_SOS: /* Found SOS */
- if (inputctl.inheaders) { /* 1st SOS */
- initial_setup(cinfo);
- inputctl.inheaders = false;
- /* Note: start_input_pass must be called by jdmaster.c
- * before any more input can be consumed. jdapimin.c is
- * responsible for enforcing this sequencing.
- */
- } else { /* 2nd or later SOS marker */
- if (! inputctl.has_multiple_scans)
- error();
-// ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
- start_input_pass(cinfo);
- }
- break;
- case JPEG_REACHED_EOI: /* Found EOI */
- inputctl.eoi_reached = true;
- if (inputctl.inheaders) { /* Tables-only datastream, apparently */
- if (cinfo.marker.saw_SOF)
- error();
-// ERREXIT(cinfo, JERR_SOF_NO_SOS);
- } else {
- /* Prevent infinite loop in coef ctlr's decompress_data routine
- * if user set output_scan_number larger than number of scans.
- */
- if (cinfo.output_scan_number > cinfo.input_scan_number)
- cinfo.output_scan_number = cinfo.input_scan_number;
- }
- break;
- case JPEG_SUSPENDED:
- break;
- }
-
- return val;
-}
-
-static void default_decompress_parms (jpeg_decompress_struct cinfo) {
- /* Guess the input colorspace, and set output colorspace accordingly. */
- /* (Wish JPEG committee had provided a real way to specify this...) */
- /* Note application may override our guesses. */
- switch (cinfo.num_components) {
- case 1:
- cinfo.jpeg_color_space = JCS_GRAYSCALE;
- cinfo.out_color_space = JCS_GRAYSCALE;
- break;
-
- case 3:
- if (cinfo.saw_JFIF_marker) {
- cinfo.jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
- } else if (cinfo.saw_Adobe_marker) {
- switch (cinfo.Adobe_transform) {
- case 0:
- cinfo.jpeg_color_space = JCS_RGB;
- break;
- case 1:
- cinfo.jpeg_color_space = JCS_YCbCr;
- break;
- default:
-// WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo.Adobe_transform);
- cinfo.jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
- break;
- }
- } else {
- /* Saw no special markers, try to guess from the component IDs */
- int cid0 = cinfo.comp_info[0].component_id;
- int cid1 = cinfo.comp_info[1].component_id;
- int cid2 = cinfo.comp_info[2].component_id;
-
- if (cid0 == 1 && cid1 == 2 && cid2 == 3)
- cinfo.jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
- else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
- cinfo.jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
- else {
-// TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
- cinfo.jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
- }
- }
- /* Always guess RGB is proper output colorspace. */
- cinfo.out_color_space = JCS_RGB;
- break;
-
- case 4:
- if (cinfo.saw_Adobe_marker) {
- switch (cinfo.Adobe_transform) {
- case 0:
- cinfo.jpeg_color_space = JCS_CMYK;
- break;
- case 2:
- cinfo.jpeg_color_space = JCS_YCCK;
- break;
- default:
-// WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo.Adobe_transform);
- cinfo.jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
- break;
- }
- } else {
- /* No special markers, assume straight CMYK. */
- cinfo.jpeg_color_space = JCS_CMYK;
- }
- cinfo.out_color_space = JCS_CMYK;
- break;
-
- default:
- cinfo.jpeg_color_space = JCS_UNKNOWN;
- cinfo.out_color_space = JCS_UNKNOWN;
- break;
- }
-
- /* Set defaults for other decompression parameters. */
- cinfo.scale_num = 1; /* 1:1 scaling */
- cinfo.scale_denom = 1;
- cinfo.output_gamma = 1.0;
- cinfo.buffered_image = false;
- cinfo.raw_data_out = false;
- cinfo.dct_method = JDCT_DEFAULT;
- cinfo.do_fancy_upsampling = true;
- cinfo.do_block_smoothing = true;
- cinfo.quantize_colors = false;
- /* We set these in case application only sets quantize_colors. */
- cinfo.dither_mode = JDITHER_FS;
- cinfo.two_pass_quantize = true;
- cinfo.desired_number_of_colors = 256;
- cinfo.colormap = null;
- /* Initialize for no mode change in buffered-image mode. */
- cinfo.enable_1pass_quant = false;
- cinfo.enable_external_quant = false;
- cinfo.enable_2pass_quant = false;
-}
-
-static void init_source(jpeg_decompress_struct cinfo) {
- cinfo.buffer = new byte[INPUT_BUFFER_SIZE];
- cinfo.bytes_in_buffer = 0;
- cinfo.bytes_offset = 0;
- cinfo.start_of_file = true;
-}
-
-static int jpeg_consume_input (jpeg_decompress_struct cinfo) {
- int retcode = JPEG_SUSPENDED;
-
- /* NB: every possible DSTATE value should be listed in this switch */
- switch (cinfo.global_state) {
- case DSTATE_START:
- /* Start-of-datastream actions: reset appropriate modules */
- reset_input_controller(cinfo);
- /* Initialize application's data source module */
- init_source (cinfo);
- cinfo.global_state = DSTATE_INHEADER;
- /*FALLTHROUGH*/
- case DSTATE_INHEADER:
- retcode = consume_input(cinfo);
- if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
- /* Set up default parameters based on header data */
- default_decompress_parms(cinfo);
- /* Set global state: ready for start_decompress */
- cinfo.global_state = DSTATE_READY;
- }
- break;
- case DSTATE_READY:
- /* Can't advance past first SOS until start_decompress is called */
- retcode = JPEG_REACHED_SOS;
- break;
- case DSTATE_PRELOAD:
- case DSTATE_PRESCAN:
- case DSTATE_SCANNING:
- case DSTATE_RAW_OK:
- case DSTATE_BUFIMAGE:
- case DSTATE_BUFPOST:
- case DSTATE_STOPPING:
- retcode = consume_input (cinfo);
- break;
- default:
- error();
-// ERREXIT1(cinfo, JERR_BAD_STATE, cinfo.global_state);
- }
- return retcode;
-}
-
-
-static void jpeg_abort (jpeg_decompress_struct cinfo) {
-// int pool;
-//
-// /* Releasing pools in reverse order might help avoid fragmentation
-// * with some (brain-damaged) malloc libraries.
-// */
-// for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
-// (*cinfo.mem.free_pool) (cinfo, pool);
-// }
-
- /* Reset overall state for possible reuse of object */
- if (cinfo.is_decompressor) {
- cinfo.global_state = DSTATE_START;
- /* Try to keep application from accessing now-deleted marker list.
- * A bit kludgy to do it here, but this is the most central place.
- */
-// ((j_decompress_ptr) cinfo).marker_list = null;
- } else {
- cinfo.global_state = CSTATE_START;
- }
-}
-
-
-static boolean isFileFormat(LEDataInputStream stream) {
- try {
- byte[] buffer = new byte[2];
- stream.read(buffer);
- stream.unread(buffer);
- return (buffer[0] & 0xFF) == 0xFF && (buffer[1] & 0xFF) == M_SOI;
- } catch (Exception e) {
- return false;
- }
-}
-
-static ImageData[] loadFromByteStream(InputStream inputStream, ImageLoader loader) {
- jpeg_decompress_struct cinfo = new jpeg_decompress_struct();
- cinfo.inputStream = inputStream;
- jpeg_create_decompress(cinfo);
- jpeg_read_header(cinfo, true);
- cinfo.buffered_image = cinfo.progressive_mode && loader.hasListeners();
- jpeg_start_decompress(cinfo);
- PaletteData palette = null;
- switch (cinfo.out_color_space) {
- case JCS_RGB:
- palette = new PaletteData(0xFF, 0xFF00, 0xFF0000);
- break;
- case JCS_GRAYSCALE:
- RGB[] colors = new RGB[256];
- for (int i = 0; i < colors.length; i++) {
- colors[i] = new RGB(i, i, i);
- }
- palette = new PaletteData(colors);
- break;
- default:
- error();
- }
- int scanlinePad = 4;
- int row_stride = (((cinfo.output_width * cinfo.out_color_components * 8 + 7) / 8) + (scanlinePad - 1)) / scanlinePad * scanlinePad;
- byte[][] buffer = new byte[1][row_stride];
- byte[] data = new byte[row_stride * cinfo.output_height];
- ImageData imageData = ImageData.internal_new(
- cinfo.output_width, cinfo.output_height, palette.isDirect ? 24 : 8, palette, scanlinePad, data,
- 0, null, null, -1, -1, SWT.IMAGE_JPEG, 0, 0, 0, 0);
- if (cinfo.buffered_image) {
- boolean done;
- do {
- int incrementCount = cinfo.input_scan_number - 1;
- jpeg_start_output(cinfo, cinfo.input_scan_number);
- while (cinfo.output_scanline < cinfo.output_height) {
- int offset = row_stride * cinfo.output_scanline;
- jpeg_read_scanlines(cinfo, buffer, 1);
- System.arraycopy(buffer[0], 0, data, offset, row_stride);
- }
- jpeg_finish_output(cinfo);
- loader.notifyListeners(new ImageLoaderEvent(loader, (ImageData)imageData.clone(), incrementCount, done = jpeg_input_complete(cinfo)));
- } while (!done);
- } else {
- while (cinfo.output_scanline < cinfo.output_height) {
- int offset = row_stride * cinfo.output_scanline;
- jpeg_read_scanlines(cinfo, buffer, 1);
- System.arraycopy(buffer[0], 0, data, offset, row_stride);
- }
- }
- jpeg_finish_decompress(cinfo);
- jpeg_destroy_decompress(cinfo);
- return new ImageData[]{imageData};
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGEndOfImage.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGEndOfImage.java
deleted file mode 100755
index faa369ccb0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGEndOfImage.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-final class JPEGEndOfImage extends JPEGFixedSizeSegment {
-
- public JPEGEndOfImage() {
- super();
- }
-
- public JPEGEndOfImage(byte[] reference) {
- super(reference);
- }
-
- public int signature() {
- return JPEGFileFormat.EOI;
- }
-
- public int fixedSize() {
- return 2;
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFileFormat.java
deleted file mode 100755
index 967feb708d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFileFormat.java
+++ /dev/null
@@ -1,1882 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * All rights reserved. This source file is made available under the terms contained in the README file
- * accompanying this program. The README file should be located in the about_files directory of the
- * plug-in that contains this source file.
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import java.io.*;
-
-public final class JPEGFileFormat extends FileFormat {
- int restartInterval;
- JPEGFrameHeader frameHeader;
- int imageWidth, imageHeight;
- int interleavedMcuCols, interleavedMcuRows;
- int maxV, maxH;
- boolean progressive;
- int samplePrecision;
- int nComponents;
- int[][] frameComponents;
- int[] componentIds;
- byte[][] imageComponents;
- int[] dataUnit;
- int[][][] dataUnits;
- int[] precedingDCs;
- JPEGScanHeader scanHeader;
- byte[] dataBuffer;
- int currentBitCount;
- int bufferCurrentPosition;
- int restartsToGo;
- int nextRestartNumber;
- JPEGHuffmanTable[] acHuffmanTables;
- JPEGHuffmanTable[] dcHuffmanTables;
- int[][] quantizationTables;
- int currentByte;
- int encoderQFactor = 75;
- int eobrun = 0;
- /* JPEGConstants */
- public static final int DCTSIZE = 8;
- public static final int DCTSIZESQR = 64;
- /* JPEGFixedPointConstants */
- public static final int FIX_0_899976223 = 7373;
- public static final int FIX_1_961570560 = 16069;
- public static final int FIX_2_053119869 = 16819;
- public static final int FIX_0_298631336 = 2446;
- public static final int FIX_1_847759065 = 15137;
- public static final int FIX_1_175875602 = 9633;
- public static final int FIX_3_072711026 = 25172;
- public static final int FIX_0_765366865 = 6270;
- public static final int FIX_2_562915447 = 20995;
- public static final int FIX_0_541196100 = 4433;
- public static final int FIX_0_390180644 = 3196;
- public static final int FIX_1_501321110 = 12299;
- /* JPEGMarkerCodes */
- public static final int APP0 = 0xFFE0;
- public static final int APP15 = 0xFFEF;
- public static final int COM = 0xFFFE;
- public static final int DAC = 0xFFCC;
- public static final int DHP = 0xFFDE;
- public static final int DHT = 0xFFC4;
- public static final int DNL = 0xFFDC;
- public static final int DRI = 0xFFDD;
- public static final int DQT = 0xFFDB;
- public static final int EOI = 0xFFD9;
- public static final int EXP = 0xFFDF;
- public static final int JPG = 0xFFC8;
- public static final int JPG0 = 0xFFF0;
- public static final int JPG13 = 0xFFFD;
- public static final int RST0 = 0xFFD0;
- public static final int RST1 = 0xFFD1;
- public static final int RST2 = 0xFFD2;
- public static final int RST3 = 0xFFD3;
- public static final int RST4 = 0xFFD4;
- public static final int RST5 = 0xFFD5;
- public static final int RST6 = 0xFFD6;
- public static final int RST7 = 0xFFD7;
- public static final int SOF0 = 0xFFC0;
- public static final int SOF1 = 0xFFC1;
- public static final int SOF2 = 0xFFC2;
- public static final int SOF3 = 0xFFC3;
- public static final int SOF5 = 0xFFC5;
- public static final int SOF6 = 0xFFC6;
- public static final int SOF7 = 0xFFC7;
- public static final int SOF9 = 0xFFC9;
- public static final int SOF10 = 0xFFCA;
- public static final int SOF11 = 0xFFCB;
- public static final int SOF13 = 0xFFCD;
- public static final int SOF14 = 0xFFCE;
- public static final int SOF15 = 0xFFCF;
- public static final int SOI = 0xFFD8;
- public static final int SOS = 0xFFDA;
- public static final int TEM = 0xFF01;
- /* JPEGFrameComponentParameterConstants */
- public static final int TQI = 0;
- public static final int HI = 1;
- public static final int VI = 2;
- public static final int CW = 3;
- public static final int CH = 4;
- /* JPEGScanComponentParameterConstants */
- public static final int DC = 0;
- public static final int AC = 1;
- /* JFIF Component Constants */
- public static final int ID_Y = 1 - 1;
- public static final int ID_CB = 2 - 1;
- public static final int ID_CR = 3 - 1;
- public static final RGB[] RGB16 = new RGB[] {
- new RGB(0,0,0),
- new RGB(0x80,0,0),
- new RGB(0,0x80,0),
- new RGB(0x80,0x80,0),
- new RGB(0,0,0x80),
- new RGB(0x80,0,0x80),
- new RGB(0,0x80,0x80),
- new RGB(0xC0,0xC0,0xC0),
- new RGB(0x80,0x80,0x80),
- new RGB(0xFF,0,0),
- new RGB(0,0xFF,0),
- new RGB(0xFF,0xFF,0),
- new RGB(0,0,0xFF),
- new RGB(0xFF,0,0xFF),
- new RGB(0,0xFF,0xFF),
- new RGB(0xFF,0xFF,0xFF),
- };
- public static final int[] ExtendTest = {
- 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048,
- 4096, 8192, 16384, 32768, 65536, 131072, 262144
- };
- public static final int[] ExtendOffset = new int[] {
- 0, -1, -3, -7, -15, -31, -63, -127, -255, -511, -1023, -2047,
- -4095, -8191, -16383, -32767, -65535, -131071, -262143
- };
- public static final int[] ZigZag8x8 = {
- 0, 1, 8, 16, 9, 2, 3, 10,
- 17, 24, 32, 25, 18, 11, 4, 5,
- 12, 19, 26, 33, 40, 48, 41, 34,
- 27, 20, 13, 6, 7, 14, 21, 28,
- 35, 42, 49, 56, 57, 50, 43, 36,
- 29, 22, 15, 23, 30, 37, 44, 51,
- 58, 59, 52, 45, 38, 31, 39, 46,
- 53, 60, 61, 54, 47, 55, 62, 63
- };
-
- public static final int[] CrRTable, CbBTable, CrGTable, CbGTable;
- public static final int[] RYTable, GYTable, BYTable,
- RCbTable, GCbTable, BCbTable, RCrTable, GCrTable, BCrTable, NBitsTable;
- static {
- /* Initialize RGB-YCbCr Tables */
- int [] rYTable = new int[256];
- int [] gYTable = new int[256];
- int [] bYTable = new int[256];
- int [] rCbTable = new int[256];
- int [] gCbTable = new int[256];
- int [] bCbTable = new int[256];
- int [] gCrTable = new int[256];
- int [] bCrTable = new int[256];
- for (int i = 0; i < 256; i++) {
- rYTable[i] = i * 19595;
- gYTable[i] = i * 38470;
- bYTable[i] = i * 7471 + 32768;
- rCbTable[i] = i * -11059;
- gCbTable[i] = i * -21709;
- bCbTable[i] = i * 32768 + 8388608;
- gCrTable[i] = i * -27439;
- bCrTable[i] = i * -5329;
- }
- RYTable = rYTable;
- GYTable = gYTable;
- BYTable = bYTable;
- RCbTable = rCbTable;
- GCbTable = gCbTable;
- BCbTable = bCbTable;
- RCrTable = bCbTable;
- GCrTable = gCrTable;
- BCrTable = bCrTable;
-
- /* Initialize YCbCr-RGB Tables */
- int [] crRTable = new int[256];
- int [] cbBTable = new int[256];
- int [] crGTable = new int[256];
- int [] cbGTable = new int[256];
- for (int i = 0; i < 256; i++) {
- int x2 = 2 * i - 255;
- crRTable[i] = (45941 * x2 + 32768) >> 16;
- cbBTable[i] = (58065 * x2 + 32768) >> 16;
- crGTable[i] = -23401 * x2;
- cbGTable[i] = -11277 * x2 + 32768;
- }
- CrRTable = crRTable;
- CbBTable = cbBTable;
- CrGTable = crGTable;
- CbGTable = cbGTable;
-
- /* Initialize BitCount Table */
- int nBits = 1;
- int power2 = 2;
- int [] nBitsTable = new int[2048];
- nBitsTable[0] = 0;
- for (int i = 1; i < nBitsTable.length; i++) {
- if (!(i < power2)) {
- nBits++;
- power2 *= 2;
- }
- nBitsTable[i] = nBits;
- }
- NBitsTable = nBitsTable;
- }
-void compress(ImageData image, byte[] dataYComp, byte[] dataCbComp, byte[] dataCrComp) {
- int srcWidth = image.width;
- int srcHeight = image.height;
- int vhFactor = maxV * maxH;
- int[] frameComponent;
- imageComponents = new byte[nComponents][];
- for (int i = 0; i < nComponents; i++) {
- frameComponent = frameComponents[componentIds[i]];
- imageComponents[i] = new byte[frameComponent[CW] * frameComponent[CH]];
- }
- frameComponent = frameComponents[componentIds[ID_Y]];
- for (int yPos = 0; yPos < srcHeight; yPos++) {
- int srcOfs = yPos * srcWidth;
- int dstOfs = yPos * frameComponent[CW];
- System.arraycopy(dataYComp, srcOfs, imageComponents[ID_Y], dstOfs, srcWidth);
- }
- frameComponent = frameComponents[componentIds[ID_CB]];
- for (int yPos = 0; yPos < srcHeight / maxV; yPos++) {
- int destRowIndex = yPos * frameComponent[CW];
- for (int xPos = 0; xPos < srcWidth / maxH; xPos++) {
- int sum = 0;
- for (int iv = 0; iv < maxV; iv++) {
- int srcIndex = (yPos * maxV + iv) * srcWidth + (xPos * maxH);
- for (int ih = 0; ih < maxH; ih++) {
- sum += dataCbComp[srcIndex + ih] & 0xFF;
- }
- }
- imageComponents[ID_CB][destRowIndex + xPos] = (byte)(sum / vhFactor);
- }
- }
- frameComponent = frameComponents[componentIds[ID_CR]];
- for (int yPos = 0; yPos < srcHeight / maxV; yPos++) {
- int destRowIndex = yPos * frameComponent[CW];
- for (int xPos = 0; xPos < srcWidth / maxH; xPos++) {
- int sum = 0;
- for (int iv = 0; iv < maxV; iv++) {
- int srcIndex = (yPos * maxV + iv) * srcWidth + (xPos * maxH);
- for (int ih = 0; ih < maxH; ih++) {
- sum += dataCrComp[srcIndex + ih] & 0xFF;
- }
- }
- imageComponents[ID_CR][destRowIndex + xPos] = (byte)(sum / vhFactor);
- }
- }
- for (int iComp = 0; iComp < nComponents; iComp++) {
- byte[] imageComponent = imageComponents[iComp];
- frameComponent = frameComponents[componentIds[iComp]];
- int hFactor = frameComponent[HI];
- int vFactor = frameComponent[VI];
- int componentWidth = frameComponent[CW];
- int componentHeight = frameComponent[CH];
- int compressedWidth = srcWidth / (maxH / hFactor);
- int compressedHeight = srcHeight / (maxV / vFactor);
- if (compressedWidth < componentWidth) {
- int delta = componentWidth - compressedWidth;
- for (int yPos = 0; yPos < compressedHeight; yPos++) {
- int dstOfs = ((yPos + 1) * componentWidth - delta);
- int dataValue = imageComponent[(dstOfs > 0) ? dstOfs - 1 : 0] & 0xFF;
- for (int i = 0; i < delta; i++) {
- imageComponent[dstOfs + i] = (byte)dataValue;
- }
- }
- }
- if (compressedHeight < componentHeight) {
- int srcOfs = (compressedHeight > 0) ? (compressedHeight - 1) * componentWidth : 1;
- for (int yPos = (compressedHeight > 0) ? compressedHeight : 1; yPos <= componentHeight; yPos++) {
- int dstOfs = (yPos - 1) * componentWidth;
- System.arraycopy(imageComponent, srcOfs, imageComponent, dstOfs, componentWidth);
- }
- }
- }
-}
-void convert4BitRGBToYCbCr(ImageData image) {
- RGB[] rgbs = image.getRGBs();
- int paletteSize = rgbs.length;
- byte[] yComp = new byte[paletteSize];
- byte[] cbComp = new byte[paletteSize];
- byte[] crComp = new byte[paletteSize];
- int srcWidth = image.width;
- int srcHeight = image.height;
- for (int i = 0; i < paletteSize; i++) {
- RGB color = rgbs[i];
- int r = color.red;
- int g = color.green;
- int b = color.blue;
- int n = RYTable[r] + GYTable[g] + BYTable[b];
- yComp[i] = (byte)(n >> 16);
- if ((n < 0) && ((n & 0xFFFF) != 0)) yComp[i]--;
- n = RCbTable[r] + GCbTable[g] + BCbTable[b];
- cbComp[i] = (byte)(n >> 16);
- if ((n < 0) && ((n & 0xFFFF) != 0)) cbComp[i]--;
- n = RCrTable[r] + GCrTable[g] + BCrTable[b];
- crComp[i] = (byte)(n >> 16);
- if ((n < 0) && ((n & 0xFFFF) != 0)) crComp[i]--;
- }
- int bSize = srcWidth * srcHeight;
- byte[] dataYComp = new byte[bSize];
- byte[] dataCbComp = new byte[bSize];
- byte[] dataCrComp = new byte[bSize];
- byte[] origData = image.data;
- int bytesPerLine = image.bytesPerLine;
- int maxScanlineByte = srcWidth >> 1;
- for (int yPos = 0; yPos < srcHeight; yPos++) {
- for (int xPos = 0; xPos < maxScanlineByte; xPos++) {
- int srcIndex = yPos * bytesPerLine + xPos;
- int dstIndex = yPos * srcWidth + (xPos * 2);
- int value2 = origData[srcIndex] & 0xFF;
- int value1 = value2 >> 4;
- value2 &= 0x0F;
- dataYComp[dstIndex] = yComp[value1];
- dataCbComp[dstIndex] = cbComp[value1];
- dataCrComp[dstIndex] = crComp[value1];
- dataYComp[dstIndex + 1] = yComp[value2];
- dataCbComp[dstIndex + 1] = cbComp[value2];
- dataCrComp[dstIndex + 1] = crComp[value2];
- }
- }
- compress(image, dataYComp, dataCbComp, dataCrComp);
-}
-void convert8BitRGBToYCbCr(ImageData image) {
- RGB[] rgbs = image.getRGBs();
- int paletteSize = rgbs.length;
- byte[] yComp = new byte[paletteSize];
- byte[] cbComp = new byte[paletteSize];
- byte[] crComp = new byte[paletteSize];
- int srcWidth = image.width;
- int srcHeight = image.height;
- for (int i = 0; i < paletteSize; i++) {
- RGB color = rgbs[i];
- int r = color.red;
- int g = color.green;
- int b = color.blue;
- int n = RYTable[r] + GYTable[g] + BYTable[b];
- yComp[i] = (byte)(n >> 16);
- if ((n < 0) && ((n & 0xFFFF) != 0)) yComp[i]--;
- n = RCbTable[r] + GCbTable[g] + BCbTable[b];
- cbComp[i] = (byte)(n >> 16);
- if ((n < 0) && ((n & 0xFFFF) != 0)) cbComp[i]--;
- n = RCrTable[r] + GCrTable[g] + BCrTable[b];
- crComp[i] = (byte)(n >> 16);
- if ((n < 0) && ((n & 0xFFFF) != 0)) crComp[i]--;
- }
- int dstWidth = image.width;
- int dstHeight = srcHeight;
- int stride = ((srcWidth + 3) >> 2) << 2;
- int bSize = dstWidth * dstHeight;
- byte[] dataYComp = new byte[bSize];
- byte[] dataCbComp = new byte[bSize];
- byte[] dataCrComp = new byte[bSize];
- byte[] origData = image.data;
- for (int yPos = 0; yPos < srcHeight; yPos++) {
- int srcRowIndex = yPos * stride;
- int dstRowIndex = yPos * dstWidth;
- for (int xPos = 0; xPos < srcWidth; xPos++) {
- int value = origData[srcRowIndex + xPos] & 0xFF;
- int dstIndex = dstRowIndex + xPos;
- dataYComp[dstIndex] = yComp[value];
- dataCbComp[dstIndex] = cbComp[value];
- dataCrComp[dstIndex] = crComp[value];
- }
- }
- compress(image, dataYComp, dataCbComp, dataCrComp);
-}
-byte[] convertCMYKToRGB() {
- /* Unsupported CMYK format. Answer an empty byte array. */
- return new byte[0];
-}
-void convertImageToYCbCr(ImageData image) {
- switch (image.depth) {
- case 4:
- convert4BitRGBToYCbCr(image);
- return;
- case 8:
- convert8BitRGBToYCbCr(image);
- return;
- case 16:
- case 24:
- case 32:
- convertMultiRGBToYCbCr(image);
- return;
- default:
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- }
- return;
-}
-void convertMultiRGBToYCbCr(ImageData image) {
- int srcWidth = image.width;
- int srcHeight = image.height;
- int bSize = srcWidth * srcHeight;
- byte[] dataYComp = new byte[bSize];
- byte[] dataCbComp = new byte[bSize];
- byte[] dataCrComp = new byte[bSize];
- PaletteData palette = image.palette;
- int[] buffer = new int[srcWidth];
- if (palette.isDirect) {
- int redMask = palette.redMask;
- int greenMask = palette.greenMask;
- int blueMask = palette.blueMask;
- int redShift = palette.redShift;
- int greenShift = palette.greenShift;
- int blueShift = palette.blueShift;
- for (int yPos = 0; yPos < srcHeight; yPos++) {
- image.getPixels(0, yPos, srcWidth, buffer, 0);
- int dstRowIndex = yPos * srcWidth;
- for (int xPos = 0; xPos < srcWidth; xPos++) {
- int pixel = buffer[xPos];
- int dstDataIndex = dstRowIndex + xPos;
- int r = pixel & redMask;
- r = (redShift < 0) ? r >>> -redShift : r << redShift;
- int g = pixel & greenMask;
- g = (greenShift < 0) ? g >>> -greenShift : g << greenShift;
- int b = pixel & blueMask;
- b = (blueShift < 0) ? b >>> -blueShift : b << blueShift;
- dataYComp[dstDataIndex] = (byte)((RYTable[r] + GYTable[g] + BYTable[b]) >> 16);
- dataCbComp[dstDataIndex] = (byte)((RCbTable[r] + GCbTable[g] + BCbTable[b]) >> 16);
- dataCrComp[dstDataIndex] = (byte)((RCrTable[r] + GCrTable[g] + BCrTable[b]) >> 16);
- }
- }
- } else {
- for (int yPos = 0; yPos < srcHeight; yPos++) {
- image.getPixels(0, yPos, srcWidth, buffer, 0);
- int dstRowIndex = yPos * srcWidth;
- for (int xPos = 0; xPos < srcWidth; xPos++) {
- int pixel = buffer[xPos];
- int dstDataIndex = dstRowIndex + xPos;
- RGB rgb = palette.getRGB(pixel);
- int r = rgb.red;
- int g = rgb.green;
- int b = rgb.blue;
- dataYComp[dstDataIndex] = (byte)((RYTable[r] + GYTable[g] + BYTable[b]) >> 16);
- dataCbComp[dstDataIndex] = (byte)((RCbTable[r] + GCbTable[g] + BCbTable[b]) >> 16);
- dataCrComp[dstDataIndex] = (byte)((RCrTable[r] + GCrTable[g] + BCrTable[b]) >> 16);
- }
- }
- }
- compress(image, dataYComp, dataCbComp, dataCrComp);
-}
-byte[] convertYToRGB() {
- int compWidth = frameComponents[componentIds[ID_Y]][CW];
- int bytesPerLine = (((imageWidth * 8 + 7) / 8) + 3) / 4 * 4;
- byte[] data = new byte[bytesPerLine * imageHeight];
- byte[] yComp = imageComponents[ID_Y];
- int destIndex = 0;
- for (int i = 0; i < imageHeight; i++) {
- int srcIndex = i * compWidth;
- for (int j = 0; j < bytesPerLine; j++) {
- int y = yComp[srcIndex] & 0xFF;
- if (y < 0) {
- y = 0;
- } else {
- if (y > 255) y = 255;
- }
- if (j >= imageWidth) {
- y = 0;
- }
- data[destIndex] = (byte)y;
- srcIndex++;
- destIndex++;
- }
- }
- return data;
-}
-byte[] convertYCbCrToRGB() {
- /**
- * Convert existing image components into an RGB format.
- * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
- * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
- * The conversion equations to be implemented are therefore
- * R = Y + 1.40200 * Cr
- * G = Y - 0.34414 * Cb - 0.71414 * Cr
- * B = Y + 1.77200 * Cb
- * where Cb and Cr represent the incoming values less MAXJSAMPLE/2.
- * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
- *
- * To avoid floating-point arithmetic, we represent the fractional constants
- * as integers scaled up by 2^16 (about 4 digits precision); we have to divide
- * the products by 2^16, with appropriate rounding, to get the correct answer.
- * Notice that Y, being an integral input, does not contribute any fraction
- * so it need not participate in the rounding.
- *
- * For even more speed, we avoid doing any multiplications in the inner loop
- * by precalculating the constants times Cb and Cr for all possible values.
- * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
- * for 12-bit samples it is still acceptable. It's not very reasonable for
- * 16-bit samples, but if you want lossless storage you shouldn't be changing
- * colorspace anyway.
- * The Cr=>R and Cb=>B values can be rounded to integers in advance; the
- * values for the G calculation are left scaled up, since we must add them
- * together before rounding.
- */
- int bSize = imageWidth * imageHeight * nComponents;
- byte[] rgbData = new byte[bSize];
- int destIndex = 0;
- expandImageComponents();
- byte[] yComp = imageComponents[ID_Y];
- byte[] cbComp = imageComponents[ID_CB];
- byte[] crComp = imageComponents[ID_CR];
- int compWidth = frameComponents[componentIds[ID_Y]][CW];
- for (int v = 0; v < imageHeight; v++) {
- int srcIndex = v * compWidth;
- for (int i = 0; i < imageWidth; i++) {
- int y = yComp[srcIndex] & 0xFF;
- int cb = cbComp[srcIndex] & 0xFF;
- int cr = crComp[srcIndex] & 0xFF;
- int r = y + CrRTable[cr];
- int g = y + ((CbGTable[cb] + CrGTable[cr]) >> 16);
- int b = y + CbBTable[cb];
- if (r < 0) {
- r = 0;
- } else {
- if (r > 255) r = 255;
- }
- if (g < 0) {
- g = 0;
- } else {
- if (g > 255) g = 255;
- }
- if (b < 0) {
- b = 0;
- } else {
- if (b > 255) b = 255;
- }
- rgbData[destIndex] = (byte)b;
- rgbData[destIndex + 1] = (byte)g;
- rgbData[destIndex + 2] = (byte)r;
- destIndex += 3;
- srcIndex++;
- }
- }
- return rgbData;
-}
-void decodeACCoefficients(int[] dataUnit, int iComp) {
- int[] sParams = scanHeader.componentParameters[componentIds[iComp]];
- JPEGHuffmanTable acTable = acHuffmanTables[sParams[AC]];
- int k = 1;
- while (k < 64) {
- int rs = decodeUsingTable(acTable);
- int r = rs >> 4;
- int s = rs & 0xF;
- if (s == 0) {
- if (r == 15) {
- k += 16;
- } else {
- break;
- }
- } else {
- k += r;
- int bits = receive(s);
- dataUnit[ZigZag8x8[k]] = extendBy(bits, s);
- k++;
- }
- }
-}
-void decodeACFirstCoefficients(int[] dataUnit, int iComp, int start, int end, int approxBit) {
- if (eobrun > 0) {
- eobrun--;
- return;
- }
- int[] sParams = scanHeader.componentParameters[componentIds[iComp]];
- JPEGHuffmanTable acTable = acHuffmanTables[sParams[AC]];
- int k = start;
- while (k <= end) {
- int rs = decodeUsingTable(acTable);
- int r = rs >> 4;
- int s = rs & 0xF;
- if (s == 0) {
- if (r == 15) {
- k += 16;
- } else {
- eobrun = (1 << r) + receive(r) - 1;
- break;
- }
- } else {
- k += r;
- int bits = receive(s);
- dataUnit[ZigZag8x8[k]] = extendBy(bits, s) << approxBit;
- k++;
- }
- }
-}
-void decodeACRefineCoefficients(int[] dataUnit, int iComp, int start, int end, int approxBit) {
- int[] sParams = scanHeader.componentParameters[componentIds[iComp]];
- JPEGHuffmanTable acTable = acHuffmanTables[sParams[AC]];
- int k = start;
- while (k <= end) {
- if (eobrun > 0) {
- while (k <= end) {
- int zzIndex = ZigZag8x8[k];
- if (dataUnit[zzIndex] != 0) {
- dataUnit[zzIndex] = refineAC(dataUnit[zzIndex], approxBit);
- }
- k++;
- }
- eobrun--;
- } else {
- int rs = decodeUsingTable(acTable);
- int r = rs >> 4;
- int s = rs & 0xF;
- if (s == 0) {
- if (r == 15) {
- int zeros = 0;
- while (zeros < 16 && k <= end) {
- int zzIndex = ZigZag8x8[k];
- if (dataUnit[zzIndex] != 0) {
- dataUnit[zzIndex] = refineAC(dataUnit[zzIndex], approxBit);
- } else {
- zeros++;
- }
- k++;
- }
- } else {
- eobrun = (1 << r) + receive(r);
- }
- } else {
- int bit = receive(s);
- int zeros = 0;
- int zzIndex = ZigZag8x8[k];
- while ((zeros < r || dataUnit[zzIndex] != 0) && k <= end) {
- if (dataUnit[zzIndex] != 0) {
- dataUnit[zzIndex] = refineAC(dataUnit[zzIndex], approxBit);
- } else {
- zeros++;
- }
- k++;
- zzIndex = ZigZag8x8[k];
- }
- if (bit != 0) {
- dataUnit[zzIndex] = 1 << approxBit;
- } else {
- dataUnit[zzIndex] = -1 << approxBit;
- }
- k++;
- }
- }
- }
-}
-int refineAC(int ac, int approxBit) {
- if (ac > 0) {
- int bit = nextBit();
- if (bit != 0) {
- ac += 1 << approxBit;
- }
- } else if (ac < 0) {
- int bit = nextBit();
- if (bit != 0) {
- ac += -1 << approxBit;
- }
- }
- return ac;
-}
-void decodeDCCoefficient(int[] dataUnit, int iComp, boolean first, int approxBit) {
- int[] sParams = scanHeader.componentParameters[componentIds[iComp]];
- JPEGHuffmanTable dcTable = dcHuffmanTables[sParams[DC]];
- int lastDC = 0;
- if (progressive && !first) {
- int bit = nextBit();
- lastDC = dataUnit[0] + (bit << approxBit);
- } else {
- lastDC = precedingDCs[iComp];
- int nBits = decodeUsingTable(dcTable);
- if (nBits != 0) {
- int bits = receive(nBits);
- int diff = extendBy(bits, nBits);
- lastDC += diff;
- precedingDCs[iComp] = lastDC;
- }
- if (progressive) {
- lastDC = lastDC << approxBit;
- }
- }
- dataUnit[0] = lastDC;
-}
-void dequantize(int[] dataUnit, int iComp) {
- int[] qTable = quantizationTables[frameComponents[componentIds[iComp]][TQI]];
- for (int i = 0; i < dataUnit.length; i++) {
- int zzIndex = ZigZag8x8[i];
- dataUnit[zzIndex] = dataUnit[zzIndex] * qTable[i];
- }
-}
-byte[] decodeImageComponents() {
- if (nComponents == 3) { // compIds 1, 2, 3
- return convertYCbCrToRGB();
- }
-// if (nComponents == 3) { // compIds 1, 4, 5
-// Unsupported CMYK format.
-// return convertYIQToRGB();
-// }
- if (nComponents == 4) {
- return convertCMYKToRGB();
- }
- return convertYToRGB();
-}
-void decodeMCUAtXAndY(int xmcu, int ymcu, int nComponentsInScan, boolean first, int start, int end, int approxBit) {
- for (int iComp = 0; iComp < nComponentsInScan; iComp++) {
- int scanComponent = iComp;
- while (scanHeader.componentParameters[componentIds[scanComponent]] == null) {
- scanComponent++;
- }
- int[] frameComponent = frameComponents[componentIds[scanComponent]];
- int hi = frameComponent[HI];
- int vi = frameComponent[VI];
- if (nComponentsInScan == 1) {
- hi = 1;
- vi = 1;
- }
- int compWidth = frameComponent[CW];
- for (int ivi = 0; ivi < vi; ivi++) {
- for (int ihi = 0; ihi < hi; ihi++) {
- if (progressive) {
- // Progressive: First scan - create a new data unit.
- // Subsequent scans - refine the existing data unit.
- int index = (ymcu * vi + ivi) * compWidth + xmcu * hi + ihi;
- dataUnit = dataUnits[scanComponent][index];
- if (dataUnit == null) {
- dataUnit = new int[64];
- dataUnits[scanComponent][index] = dataUnit;
- }
- } else {
- // Sequential: Clear and reuse the data unit buffer.
- for (int i = 0; i < dataUnit.length; i++) {
- dataUnit[i] = 0;
- }
- }
- if (!progressive || scanHeader.isDCProgressiveScan()) {
- decodeDCCoefficient(dataUnit, scanComponent, first, approxBit);
- }
- if (!progressive) {
- decodeACCoefficients(dataUnit, scanComponent);
- } else {
- if (scanHeader.isACProgressiveScan()) {
- if (first) {
- decodeACFirstCoefficients(dataUnit, scanComponent, start, end, approxBit);
- } else {
- decodeACRefineCoefficients(dataUnit, scanComponent, start, end, approxBit);
- }
- }
- if (loader.hasListeners()) {
- // Dequantization, IDCT, up-sampling and color conversion
- // are done on a copy of the coefficient data in order to
- // display the image incrementally.
- int[] temp = dataUnit;
- dataUnit = new int[64];
- System.arraycopy(temp, 0, dataUnit, 0, 64);
- }
- }
- if (!progressive || (progressive && loader.hasListeners())) {
- dequantize(dataUnit, scanComponent);
- inverseDCT(dataUnit);
- storeData(dataUnit, scanComponent, xmcu, ymcu, hi, ihi, vi, ivi);
- }
- }
- }
- }
-}
-void decodeScan() {
- if (progressive && !scanHeader.verifyProgressiveScan()) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- int nComponentsInScan = scanHeader.getNumberOfImageComponents();
- int mcuRowsInScan = interleavedMcuRows;
- int mcusPerRow = interleavedMcuCols;
- if (nComponentsInScan == 1) {
- // Non-interleaved.
- int scanComponent = 0;
- while (scanHeader.componentParameters[componentIds[scanComponent]] == null) {
- scanComponent++;
- }
- int[] frameComponent = frameComponents[componentIds[scanComponent]];
- int hi = frameComponent[HI];
- int vi = frameComponent[VI];
- int mcuWidth = DCTSIZE * maxH / hi;
- int mcuHeight = DCTSIZE * maxV / vi;
- mcusPerRow = (imageWidth + mcuWidth - 1) / mcuWidth;
- mcuRowsInScan = (imageHeight + mcuHeight - 1) / mcuHeight;
- }
- boolean first = scanHeader.isFirstScan();
- int start = scanHeader.getStartOfSpectralSelection();
- int end = scanHeader.getEndOfSpectralSelection();
- int approxBit = scanHeader.getApproxBitPositionLow();
- restartsToGo = restartInterval;
- nextRestartNumber = 0;
- for (int ymcu = 0; ymcu < mcuRowsInScan; ymcu++) {
- for (int xmcu = 0; xmcu < mcusPerRow; xmcu++) {
- if (restartInterval != 0) {
- if (restartsToGo == 0) processRestartInterval();
- restartsToGo--;
- }
- decodeMCUAtXAndY(xmcu, ymcu, nComponentsInScan, first, start, end, approxBit);
- }
- }
-}
-int decodeUsingTable(JPEGHuffmanTable huffmanTable) {
- int i = 0;
- int[] maxCodes = huffmanTable.getDhMaxCodes();
- int[] minCodes = huffmanTable.getDhMinCodes();
- int[] valPtrs = huffmanTable.getDhValPtrs();
- int[] huffVals = huffmanTable.getDhValues();
- int code = nextBit();
- while (code > maxCodes[i]) {
- code = code * 2 + nextBit();
- i++;
- }
- int j = valPtrs[i] + code - minCodes[i];
- return huffVals[j];
-}
-void emit(int huffCode, int nBits) {
- if (nBits == 0) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- int[] power2m1 = new int[] {
- 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191,
- 16383, 32767, 65535, 131125
- };
- int code = (huffCode & power2m1[nBits - 1]) << (24 - nBits - currentBitCount);
- byte[] codeBuffer = new byte[4];
- codeBuffer[0] = (byte)(code & 0xFF);
- codeBuffer[1] = (byte)((code >> 8) & 0xFF);
- codeBuffer[2] = (byte)((code >> 16) & 0xFF);
- codeBuffer[3] = (byte)((code >> 24) & 0xFF);
- int abs = nBits - (8 - currentBitCount);
- if (abs < 0) abs = -abs;
- if ((abs >> 3) > 0) {
- currentByte += codeBuffer[2];
- emitByte((byte)currentByte);
- emitByte(codeBuffer[1]);
- currentByte = codeBuffer[0];
- currentBitCount += nBits - 16;
- } else {
- currentBitCount += nBits;
- if (currentBitCount >= 8) {
- currentByte += codeBuffer[2];
- emitByte((byte)currentByte);
- currentByte = codeBuffer[1];
- currentBitCount -= 8;
- } else {
- currentByte += codeBuffer[2];
- }
- }
-}
-void emitByte(byte byteValue) {
- if (bufferCurrentPosition >= 512) {
- resetOutputBuffer();
- }
- dataBuffer[bufferCurrentPosition] = byteValue;
- bufferCurrentPosition++;
- if (byteValue == -1) {
- emitByte((byte)0);
- }
-}
-void encodeACCoefficients(int[] dataUnit, int iComp) {
- int[] sParams = scanHeader.componentParameters[iComp];
- JPEGHuffmanTable acTable = acHuffmanTables[sParams[AC]];
- int[] ehCodes = acTable.ehCodes;
- byte[] ehSizes = acTable.ehCodeLengths;
- int r = 0;
- int k = 1;
- while (k < 64) {
- k++;
- int acValue = dataUnit[ZigZag8x8[k - 1]];
- if (acValue == 0) {
- if (k == 64) {
- emit(ehCodes[0], ehSizes[0] & 0xFF);
- } else {
- r++;
- }
- } else {
- while (r > 15) {
- emit(ehCodes[0xF0], ehSizes[0xF0] & 0xFF);
- r -= 16;
- }
- if (acValue < 0) {
- int absACValue = acValue;
- if (absACValue < 0) absACValue = -absACValue;
- int nBits = NBitsTable[absACValue];
- int rs = r * 16 + nBits;
- emit(ehCodes[rs], ehSizes[rs] & 0xFF);
- emit(0xFFFFFF - absACValue, nBits);
- } else {
- int nBits = NBitsTable[acValue];
- int rs = r * 16 + nBits;
- emit(ehCodes[rs], ehSizes[rs] & 0xFF);
- emit(acValue, nBits);
- }
- r = 0;
- }
- }
-}
-void encodeDCCoefficients(int[] dataUnit, int iComp) {
- int[] sParams = scanHeader.componentParameters[iComp];
- JPEGHuffmanTable dcTable = dcHuffmanTables[sParams[DC]];
- int lastDC = precedingDCs[iComp];
- int dcValue = dataUnit[0];
- int diff = dcValue - lastDC;
- precedingDCs[iComp] = dcValue;
- if (diff < 0) {
- int absDiff = 0 - diff;
- int nBits = NBitsTable[absDiff];
- emit(dcTable.ehCodes[nBits], dcTable.ehCodeLengths[nBits]);
- emit(0xFFFFFF - absDiff, nBits);
- } else {
- int nBits = NBitsTable[diff];
- emit(dcTable.ehCodes[nBits], dcTable.ehCodeLengths[nBits]);
- if (nBits != 0) {
- emit(diff, nBits);
- }
- }
-}
-void encodeMCUAtXAndY(int xmcu, int ymcu) {
- int nComponentsInScan = scanHeader.getNumberOfImageComponents();
- dataUnit = new int[64];
- for (int iComp = 0; iComp < nComponentsInScan; iComp++) {
- int[] frameComponent = frameComponents[componentIds[iComp]];
- int hi = frameComponent[HI];
- int vi = frameComponent[VI];
- for (int ivi = 0; ivi < vi; ivi++) {
- for (int ihi = 0; ihi < hi; ihi++) {
- extractData(dataUnit, iComp, xmcu, ymcu, ihi, ivi);
- forwardDCT(dataUnit);
- quantizeData(dataUnit, iComp);
- encodeDCCoefficients(dataUnit, iComp);
- encodeACCoefficients(dataUnit, iComp);
- }
- }
- }
-}
-void encodeScan() {
- for (int ymcu = 0; ymcu < interleavedMcuRows; ymcu++) {
- for (int xmcu = 0; xmcu < interleavedMcuCols; xmcu++) {
- encodeMCUAtXAndY(xmcu, ymcu);
- }
- }
- if (currentBitCount != 0) {
- emitByte((byte)currentByte);
- }
- resetOutputBuffer();
-}
-void expandImageComponents() {
- for (int iComp = 0; iComp < nComponents; iComp++) {
- int[] frameComponent = frameComponents[componentIds[iComp]];
- int hi = frameComponent[HI];
- int vi = frameComponent[VI];
- int upH = maxH / hi;
- int upV = maxV / vi;
- if ((upH * upV) > 1) {
- byte[] component = imageComponents[iComp];
- int compWidth = frameComponent[CW];
- int compHeight = frameComponent[CH];
- int upCompWidth = compWidth * upH;
- int upCompHeight = compHeight * upV;
- ImageData src = new ImageData(compWidth, compHeight, 8, new PaletteData(RGB16), 4, component);
- ImageData dest = src.scaledTo(upCompWidth, upCompHeight);
- imageComponents[iComp] = dest.data;
- }
- }
-}
-int extendBy(int diff, int t) {
- if (diff < ExtendTest[t]) {
- return diff + ExtendOffset[t];
- } else {
- return diff;
- }
-}
-void extractData(int[] dataUnit, int iComp, int xmcu, int ymcu, int ihi, int ivi) {
- byte[] compImage = imageComponents[iComp];
- int[] frameComponent = frameComponents[componentIds[iComp]];
- int hi = frameComponent[HI];
- int vi = frameComponent[VI];
- int compWidth = frameComponent[CW];
- int srcIndex = ((ymcu * vi + ivi) * compWidth * DCTSIZE) + ((xmcu * hi + ihi) * DCTSIZE);
- int destIndex = 0;
- for (int i = 0; i < DCTSIZE; i++) {
- for (int col = 0; col < DCTSIZE; col++) {
- dataUnit[destIndex] = (compImage[srcIndex + col] & 0xFF) - 128;
- destIndex++;
- }
- srcIndex += compWidth;
- }
-}
-void forwardDCT(int[] dataUnit) {
- for (int row = 0; row < 8; row++) {
- int rIndex = row * DCTSIZE;
- int tmp0 = dataUnit[rIndex] + dataUnit[rIndex + 7];
- int tmp7 = dataUnit[rIndex] - dataUnit[rIndex + 7];
- int tmp1 = dataUnit[rIndex + 1] + dataUnit[rIndex + 6];
- int tmp6 = dataUnit[rIndex + 1] - dataUnit[rIndex + 6];
- int tmp2 = dataUnit[rIndex + 2] + dataUnit[rIndex + 5];
- int tmp5 = dataUnit[rIndex + 2] - dataUnit[rIndex + 5];
- int tmp3 = dataUnit[rIndex + 3] + dataUnit[rIndex + 4];
- int tmp4 = dataUnit[rIndex + 3] - dataUnit[rIndex + 4];
-
- /**
- * Even part per LL&M figure 1 --- note that published figure
- * is faulty; rotator 'sqrt(2)*c1' should be 'sqrt(2)*c6'.
- */
- int tmp10 = tmp0 + tmp3;
- int tmp13 = tmp0 - tmp3;
- int tmp11 = tmp1 + tmp2;
- int tmp12 = tmp1 - tmp2;
-
- dataUnit[rIndex] = (tmp10 + tmp11) * 4;
- dataUnit[rIndex + 4] = (tmp10 - tmp11) * 4;
-
- int z1 = (tmp12 + tmp13) * FIX_0_541196100;
- int n = z1 + (tmp13 * FIX_0_765366865) + 1024;
- dataUnit[rIndex + 2] = n >> 11;
- if ((n < 0) && ((n & 0x07FF) != 0)) dataUnit[rIndex + 2]--;
- n = z1 + (tmp12 * (0 - FIX_1_847759065)) + 1024;
- dataUnit[rIndex + 6] = n >> 11;
- if ((n < 0) && ((n & 0x07FF) != 0)) dataUnit[rIndex + 6]--;
-
- /**
- * Odd part per figure 8 --- note paper omits factor of sqrt(2).
- * cK represents cos(K*pi/16).
- * i0..i3 in the paper are tmp4..tmp7 here.
- */
- z1 = tmp4 + tmp7;
- int z2 = tmp5 + tmp6;
- int z3 = tmp4 + tmp6;
- int z4 = tmp5 + tmp7;
- int z5 = (z3 + z4) * FIX_1_175875602; // sqrt(2) * c3
-
- tmp4 *= FIX_0_298631336; // sqrt(2) * (-c1+c3+c5-c7)
- tmp5 *= FIX_2_053119869; // sqrt(2) * ( c1+c3-c5+c7)
- tmp6 *= FIX_3_072711026; // sqrt(2) * ( c1+c3+c5-c7)
- tmp7 *= FIX_1_501321110; // sqrt(2) * ( c1+c3-c5-c7)
- z1 *= 0 - FIX_0_899976223; // sqrt(2) * (c7-c3)
- z2 *= 0 - FIX_2_562915447; // sqrt(2) * (-c1-c3)
- z3 *= 0 - FIX_1_961570560; // sqrt(2) * (-c3-c5)
- z4 *= 0 - FIX_0_390180644; // sqrt(2) * (c5-c3)
-
- z3 += z5;
- z4 += z5;
-
- n = tmp4 + z1 + z3 + 1024;
- dataUnit[rIndex + 7] = n >> 11;
- if ((n < 0) && ((n & 0x07FF) != 0)) dataUnit[rIndex + 7]--;
- n = tmp5 + z2 + z4 + 1024;
- dataUnit[rIndex + 5] = n >> 11;
- if ((n < 0) && ((n & 0x07FF) != 0)) dataUnit[rIndex + 5]--;
- n = tmp6 + z2 + z3 + 1024;
- dataUnit[rIndex + 3] = n >> 11;
- if ((n < 0) && ((n & 0x07FF) != 0)) dataUnit[rIndex + 3]--;
- n = tmp7 + z1 + z4 + 1024;
- dataUnit[rIndex + 1] = n >> 11;
- if ((n < 0) && ((n & 0x07FF) != 0)) dataUnit[rIndex + 1]--;
- }
-
- /**
- * Pass 2: process columns.
- * Note that we must descale the results by a factor of 8 == 2**3,
- * and also undo the PASS1_BITS scaling.
- */
- for (int col = 0; col < 8; col++) {
- int c0 = col;
- int c1 = col + 8;
- int c2 = col + 16;
- int c3 = col + 24;
- int c4 = col + 32;
- int c5 = col + 40;
- int c6 = col + 48;
- int c7 = col + 56;
- int tmp0 = dataUnit[c0] + dataUnit[c7];
- int tmp7 = dataUnit[c0] - dataUnit[c7];
- int tmp1 = dataUnit[c1] + dataUnit[c6];
- int tmp6 = dataUnit[c1] - dataUnit[c6];
- int tmp2 = dataUnit[c2] + dataUnit[c5];
- int tmp5 = dataUnit[c2] - dataUnit[c5];
- int tmp3 = dataUnit[c3] + dataUnit[c4];
- int tmp4 = dataUnit[c3] - dataUnit[c4];
-
- /**
- * Even part per LL&M figure 1 --- note that published figure
- * is faulty; rotator 'sqrt(2)*c1' should be 'sqrt(2)*c6'.
- */
- int tmp10 = tmp0 + tmp3;
- int tmp13 = tmp0 - tmp3;
- int tmp11 = tmp1 + tmp2;
- int tmp12 = tmp1 - tmp2;
-
- int n = tmp10 + tmp11 + 16;
- dataUnit[c0] = n >> 5;
- if ((n < 0) && ((n & 0x1F) != 0)) dataUnit[c0]--;
- n = tmp10 - tmp11 + 16;
- dataUnit[c4] = n >> 5;
- if ((n < 0) && ((n & 0x1F) != 0)) dataUnit[c4]--;
-
- int z1 = (tmp12 + tmp13) * FIX_0_541196100;
- n = z1 + (tmp13 * FIX_0_765366865) + 131072;
- dataUnit[c2] = n >> 18;
- if ((n < 0) && ((n & 0x3FFFF) != 0)) dataUnit[c2]--;
- n = z1 + (tmp12 * (0 - FIX_1_847759065)) + 131072;
- dataUnit[c6] = n >> 18;
- if ((n < 0) && ((n & 0x3FFFF) != 0)) dataUnit[c6]--;
-
- /**
- * Odd part per figure 8 --- note paper omits factor of sqrt(2).
- * cK represents cos(K*pi/16).
- * i0..i3 in the paper are tmp4..tmp7 here.
- */
- z1 = tmp4 + tmp7;
- int z2 = tmp5 + tmp6;
- int z3 = tmp4 + tmp6;
- int z4 = tmp5 + tmp7;
- int z5 = (z3 + z4) * FIX_1_175875602; // sqrt(2) * c3
-
- tmp4 *= FIX_0_298631336; // sqrt(2) * (-c1+c3+c5-c7)
- tmp5 *= FIX_2_053119869; // sqrt(2) * ( c1+c3-c5+c7)
- tmp6 *= FIX_3_072711026; // sqrt(2) * ( c1+c3+c5-c7)
- tmp7 *= FIX_1_501321110; // sqrt(2) * ( c1+c3-c5-c7)
- z1 *= 0 - FIX_0_899976223; // sqrt(2) * (c7-c3)
- z2 *= 0 - FIX_2_562915447; // sqrt(2) * (-c1-c3)
- z3 *= 0 - FIX_1_961570560; // sqrt(2) * (-c3-c5)
- z4 *= 0 - FIX_0_390180644; // sqrt(2) * (c5-c3)
-
- z3 += z5;
- z4 += z5;
-
- n = tmp4 + z1 + z3 + 131072;
- dataUnit[c7] = n >> 18;
- if ((n < 0) && ((n & 0x3FFFF) != 0)) dataUnit[c7]--;
- n = tmp5 + z2 + z4 + 131072;
- dataUnit[c5] = n >> 18;
- if ((n < 0) && ((n & 0x3FFFF) != 0)) dataUnit[c5]--;
- n = tmp6 + z2 + z3 + 131072;
- dataUnit[c3] = n >> 18;
- if ((n < 0) && ((n & 0x3FFFF) != 0)) dataUnit[c3]--;
- n = tmp7 + z1 + z4 + 131072;
- dataUnit[c1] = n >> 18;
- if ((n < 0) && ((n & 0x3FFFF) != 0)) dataUnit[c1]--;
- }
-}
-void getAPP0() {
- JPEGAppn appn = new JPEGAppn(inputStream);
- if (!appn.verify()) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
-}
-void getCOM() {
- new JPEGComment(inputStream);
-}
-void getDAC() {
- new JPEGArithmeticConditioningTable(inputStream);
-}
-void getDHT() {
- JPEGHuffmanTable dht = new JPEGHuffmanTable(inputStream);
- if (!dht.verify()) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- if (acHuffmanTables == null) {
- acHuffmanTables = new JPEGHuffmanTable[4];
- }
- if (dcHuffmanTables == null) {
- dcHuffmanTables = new JPEGHuffmanTable[4];
- }
- JPEGHuffmanTable[] dhtTables = dht.getAllTables();
- for (int i = 0; i < dhtTables.length; i++) {
- JPEGHuffmanTable dhtTable = dhtTables[i];
- if (dhtTable.getTableClass() == 0) {
- dcHuffmanTables[dhtTable.getTableIdentifier()] = dhtTable;
- } else {
- acHuffmanTables[dhtTable.getTableIdentifier()] = dhtTable;
- }
- }
-}
-void getDNL() {
- new JPEGRestartInterval(inputStream);
-}
-void getDQT() {
- JPEGQuantizationTable dqt = new JPEGQuantizationTable(inputStream);
- int[][] currentTables = quantizationTables;
- if (currentTables == null) {
- currentTables = new int[4][];
- }
- int[] dqtTablesKeys = dqt.getQuantizationTablesKeys();
- int[][] dqtTablesValues = dqt.getQuantizationTablesValues();
- for (int i = 0; i < dqtTablesKeys.length; i++) {
- int index = dqtTablesKeys[i];
- currentTables[index] = dqtTablesValues[i];
- }
- quantizationTables = currentTables;
-}
-void getDRI() {
- JPEGRestartInterval dri = new JPEGRestartInterval(inputStream);
- if (!dri.verify()) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- restartInterval = dri.getRestartInterval();
-}
-void inverseDCT(int[] dataUnit) {
- for (int row = 0; row < 8; row++) {
- int rIndex = row * DCTSIZE;
- /**
- * Due to quantization, we will usually find that many of the input
- * coefficients are zero, especially the AC terms. We can exploit this
- * by short-circuiting the IDCT calculation for any row in which all
- * the AC terms are zero. In that case each output is equal to the
- * DC coefficient (with scale factor as needed).
- * With typical images and quantization tables, half or more of the
- * row DCT calculations can be simplified this way.
- */
- if (isZeroInRow(dataUnit, rIndex)) {
- int dcVal = dataUnit[rIndex] << 2;
- for (int i = rIndex + 7; i >= rIndex; i--) {
- dataUnit[i] = dcVal;
- }
- } else {
- /**
- * Even part: reverse the even part of the forward DCT.
- * The rotator is sqrt(2)*c(-6).
- */
- int z2 = dataUnit[rIndex + 2];
- int z3 = dataUnit[rIndex + 6];
- int z1 = (z2 + z3) * FIX_0_541196100;
- int tmp2 = z1 + (z3 * (0 - FIX_1_847759065));
- int tmp3 = z1 + (z2 * FIX_0_765366865);
- int tmp0 = (dataUnit[rIndex] + dataUnit[rIndex + 4]) << 13;
- int tmp1 = (dataUnit[rIndex] - dataUnit[rIndex + 4]) << 13;
- int tmp10 = tmp0 + tmp3;
- int tmp13 = tmp0 - tmp3;
- int tmp11 = tmp1 + tmp2;
- int tmp12 = tmp1 - tmp2;
- /**
- * Odd part per figure 8; the matrix is unitary and hence its
- * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
- */
- tmp0 = dataUnit[rIndex + 7];
- tmp1 = dataUnit[rIndex + 5];
- tmp2 = dataUnit[rIndex + 3];
- tmp3 = dataUnit[rIndex + 1];
- z1 = tmp0 + tmp3;
- z2 = tmp1 + tmp2;
- z3 = tmp0 + tmp2;
- int z4 = tmp1 + tmp3;
- int z5 = (z3 + z4) * FIX_1_175875602; /* sqrt(2) * c3 */
-
- tmp0 *= FIX_0_298631336; /* sqrt(2) * (-c1+c3+c5-c7) */
- tmp1 *= FIX_2_053119869; /* sqrt(2) * ( c1+c3-c5+c7) */
- tmp2 *= FIX_3_072711026; /* sqrt(2) * ( c1+c3+c5-c7) */
- tmp3 *= FIX_1_501321110; /* sqrt(2) * ( c1+c3-c5-c7) */
- z1 *= 0 - FIX_0_899976223; /* sqrt(2) * (c7-c3) */
- z2 *= 0 - FIX_2_562915447; /* sqrt(2) * (-c1-c3) */
- z3 *= 0 - FIX_1_961570560; /* sqrt(2) * (-c3-c5) */
- z4 *= 0 - FIX_0_390180644; /* sqrt(2) * (c5-c3) */
-
- z3 += z5;
- z4 += z5;
- tmp0 += z1 + z3;
- tmp1 += z2 + z4;
- tmp2 += z2 + z3;
- tmp3 += z1 + z4;
-
- dataUnit[rIndex] = (tmp10 + tmp3 + 1024) >> 11;
- dataUnit[rIndex + 7] = (tmp10 - tmp3 + 1024) >> 11;
- dataUnit[rIndex + 1] = (tmp11 + tmp2 + 1024) >> 11;
- dataUnit[rIndex + 6] = (tmp11 - tmp2 + 1024) >> 11;
- dataUnit[rIndex + 2] = (tmp12 + tmp1 + 1024) >> 11;
- dataUnit[rIndex + 5] = (tmp12 - tmp1 + 1024) >> 11;
- dataUnit[rIndex + 3] = (tmp13 + tmp0 + 1024) >> 11;
- dataUnit[rIndex + 4] = (tmp13 - tmp0 + 1024) >> 11;
- }
- }
- /**
- * Pass 2: process columns.
- * Note that we must descale the results by a factor of 8 == 2**3,
- * and also undo the PASS1_BITS scaling.
- */
- for (int col = 0; col < 8; col++) {
- int c0 = col;
- int c1 = col + 8;
- int c2 = col + 16;
- int c3 = col + 24;
- int c4 = col + 32;
- int c5 = col + 40;
- int c6 = col + 48;
- int c7 = col + 56;
- if (isZeroInColumn(dataUnit, col)) {
- int dcVal = (dataUnit[c0] + 16) >> 5;
- dataUnit[c0] = dcVal;
- dataUnit[c1] = dcVal;
- dataUnit[c2] = dcVal;
- dataUnit[c3] = dcVal;
- dataUnit[c4] = dcVal;
- dataUnit[c5] = dcVal;
- dataUnit[c6] = dcVal;
- dataUnit[c7] = dcVal;
- } else {
- /**
- * Even part: reverse the even part of the forward DCT.
- * The rotator is sqrt(2)*c(-6).
- */
- int z0 = dataUnit[c0];
- int z2 = dataUnit[c2];
- int z3 = dataUnit[c6];
- int z4 = dataUnit[c4];
- int z1 = (z2 + z3) * FIX_0_541196100;
- int tmp2 = z1 + (z3 * (0 - FIX_1_847759065));
- int tmp3 = z1 + (z2 * FIX_0_765366865);
- int tmp0 = (z0 + z4) << 13;
- int tmp1 = (z0 - z4) << 13;
- int tmp10 = tmp0 + tmp3;
- int tmp13 = tmp0 - tmp3;
- int tmp11 = tmp1 + tmp2;
- int tmp12 = tmp1 - tmp2;
- /**
- * Odd part per figure 8; the matrix is unitary and hence its
- * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
- */
- tmp0 = dataUnit[c7];
- tmp1 = dataUnit[c5];
- tmp2 = dataUnit[c3];
- tmp3 = dataUnit[c1];
- z1 = tmp0 + tmp3;
- z2 = tmp1 + tmp2;
- z3 = tmp0 + tmp2;
- z4 = tmp1 + tmp3;
- z0 = (z3 + z4) * FIX_1_175875602; /* sqrt(2) * c3 */
-
- tmp0 *= FIX_0_298631336; /* sqrt(2) * (-c1+c3+c5-c7) */
- tmp1 *= FIX_2_053119869; /* sqrt(2) * ( c1+c3-c5+c7) */
- tmp2 *= FIX_3_072711026; /* sqrt(2) * ( c1+c3+c5-c7) */
- tmp3 *= FIX_1_501321110; /* sqrt(2) * ( c1+c3-c5-c7) */
- z1 *= 0 - FIX_0_899976223; /* sqrt(2) * (c7-c3) */
- z2 *= 0 - FIX_2_562915447; /* sqrt(2) * (-c1-c3) */
- z3 *= 0 - FIX_1_961570560; /* sqrt(2) * (-c3-c5) */
- z4 *= 0 - FIX_0_390180644; /* sqrt(2) * (c5-c3) */
-
- z3 += z0;
- z4 += z0;
-
- tmp0 += z1 + z3;
- tmp1 += z2 + z4;
- tmp2 += z2 + z3;
- tmp3 += z1 + z4;
-
- /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
- dataUnit[c0] = (tmp10 + tmp3 + 131072) >> 18;
- dataUnit[c7] = (tmp10 - tmp3 + 131072) >> 18;
- dataUnit[c1] = (tmp11 + tmp2 + 131072) >> 18;
- dataUnit[c6] = (tmp11 - tmp2 + 131072) >> 18;
- dataUnit[c2] = (tmp12 + tmp1 + 131072) >> 18;
- dataUnit[c5] = (tmp12 - tmp1 + 131072) >> 18;
- dataUnit[c3] = (tmp13 + tmp0 + 131072) >> 18;
- dataUnit[c4] = (tmp13 - tmp0 + 131072) >> 18;
- }
- }
-}
-boolean isFileFormat(LEDataInputStream stream) {
- try {
- JPEGStartOfImage soi = new JPEGStartOfImage(stream);
- stream.unread(soi.reference);
- return soi.verify(); // we no longer check for appN
- } catch (Exception e) {
- return false;
- }
-}
-boolean isZeroInColumn(int[] dataUnit, int col) {
- return dataUnit[col + 8] == 0 && dataUnit[col + 16] == 0
- && dataUnit[col + 24] == 0 && dataUnit[col + 32] == 0
- && dataUnit[col + 40] == 0 && dataUnit[col + 48] == 0
- && dataUnit[col + 56] == 0;
-}
-boolean isZeroInRow(int[] dataUnit, int rIndex) {
- return dataUnit[rIndex + 1] == 0 && dataUnit[rIndex + 2] == 0
- && dataUnit[rIndex + 3] == 0 && dataUnit[rIndex + 4] == 0
- && dataUnit[rIndex + 5] == 0 && dataUnit[rIndex + 6] == 0
- && dataUnit[rIndex + 7] == 0;
-}
-ImageData[] loadFromByteStream() {
- //TEMPORARY CODE
- if (System.getProperty("org.eclipse.swt.internal.image.JPEGFileFormat_3.2") == null) {
- return JPEGDecoder.loadFromByteStream(inputStream, loader);
- }
- JPEGStartOfImage soi = new JPEGStartOfImage(inputStream);
- if (!soi.verify()) SWT.error(SWT.ERROR_INVALID_IMAGE);
- restartInterval = 0;
-
- /* Process the tables preceding the frame header. */
- processTables();
-
- /* Start of Frame. */
- frameHeader = new JPEGFrameHeader(inputStream);
- if (!frameHeader.verify()) SWT.error(SWT.ERROR_INVALID_IMAGE);
- imageWidth = frameHeader.getSamplesPerLine();
- imageHeight = frameHeader.getNumberOfLines();
- maxH = frameHeader.getMaxHFactor();
- maxV = frameHeader.getMaxVFactor();
- int mcuWidth = maxH * DCTSIZE;
- int mcuHeight = maxV * DCTSIZE;
- interleavedMcuCols = (imageWidth + mcuWidth - 1) / mcuWidth;
- interleavedMcuRows = (imageHeight + mcuHeight - 1) / mcuHeight;
- progressive = frameHeader.isProgressive();
- samplePrecision = frameHeader.getSamplePrecision();
- nComponents = frameHeader.getNumberOfImageComponents();
- frameComponents = frameHeader.componentParameters;
- componentIds = frameHeader.componentIdentifiers;
- imageComponents = new byte[nComponents][];
- if (progressive) {
- // Progressive jpeg: need to keep all of the data units.
- dataUnits = new int[nComponents][][];
- } else {
- // Sequential jpeg: only need one data unit.
- dataUnit = new int[8 * 8];
- }
- for (int i = 0; i < nComponents; i++) {
- int[] frameComponent = frameComponents[componentIds[i]];
- int bufferSize = frameComponent[CW] * frameComponent[CH];
- imageComponents[i] = new byte[bufferSize];
- if (progressive) {
- dataUnits[i] = new int[bufferSize][];
- }
- }
-
- /* Process the tables preceding the scan header. */
- processTables();
-
- /* Start of Scan. */
- scanHeader = new JPEGScanHeader(inputStream);
- if (!scanHeader.verify()) SWT.error(SWT.ERROR_INVALID_IMAGE);
-
- /* Process scan(s) and further tables until EOI. */
- int progressiveScanCount = 0;
- boolean done = false;
- while(!done) {
- resetInputBuffer();
- precedingDCs = new int[4];
- decodeScan();
- if (progressive && loader.hasListeners()) {
- ImageData imageData = createImageData();
- loader.notifyListeners(new ImageLoaderEvent(loader, imageData, progressiveScanCount, false));
- progressiveScanCount++;
- }
-
- /* Unread any buffered data before looking for tables again. */
- int delta = 512 - bufferCurrentPosition - 1;
- if (delta > 0) {
- byte[] unreadBuffer = new byte[delta];
- System.arraycopy(dataBuffer, bufferCurrentPosition + 1, unreadBuffer, 0, delta);
- try {
- inputStream.unread(unreadBuffer);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
-
- /* Process the tables preceding the next scan header. */
- JPEGSegment jpegSegment = processTables();
- if (jpegSegment == null || jpegSegment.getSegmentMarker() == EOI) {
- done = true;
- } else {
- scanHeader = new JPEGScanHeader(inputStream);
- if (!scanHeader.verify()) SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- }
-
- if (progressive) {
- for (int ymcu = 0; ymcu < interleavedMcuRows; ymcu++) {
- for (int xmcu = 0; xmcu < interleavedMcuCols; xmcu++) {
- for (int iComp = 0; iComp < nComponents; iComp++) {
- int[] frameComponent = frameComponents[componentIds[iComp]];
- int hi = frameComponent[HI];
- int vi = frameComponent[VI];
- int compWidth = frameComponent[CW];
- for (int ivi = 0; ivi < vi; ivi++) {
- for (int ihi = 0; ihi < hi; ihi++) {
- int index = (ymcu * vi + ivi) * compWidth + xmcu * hi + ihi;
- dataUnit = dataUnits[iComp][index];
- dequantize(dataUnit, iComp);
- inverseDCT(dataUnit);
- storeData(dataUnit, iComp, xmcu, ymcu, hi, ihi, vi, ivi);
- }
- }
- }
- }
- }
- dataUnits = null; // release memory
- }
- ImageData imageData = createImageData();
- if (progressive && loader.hasListeners()) {
- loader.notifyListeners(new ImageLoaderEvent(loader, imageData, progressiveScanCount, true));
- }
- return new ImageData[] {imageData};
-}
-ImageData createImageData() {
- return ImageData.internal_new(
- imageWidth,
- imageHeight,
- nComponents * samplePrecision,
- setUpPalette(),
- nComponents == 1 ? 4 : 1,
- decodeImageComponents(),
- 0,
- null,
- null,
- -1,
- -1,
- SWT.IMAGE_JPEG,
- 0,
- 0,
- 0,
- 0);
-}
-int nextBit() {
- if (currentBitCount != 0) {
- currentBitCount--;
- currentByte *= 2;
- if (currentByte > 255) {
- currentByte -= 256;
- return 1;
- } else {
- return 0;
- }
- }
- bufferCurrentPosition++;
- if (bufferCurrentPosition >= 512) {
- resetInputBuffer();
- bufferCurrentPosition = 0;
- }
- currentByte = dataBuffer[bufferCurrentPosition] & 0xFF;
- currentBitCount = 8;
- byte nextByte;
- if (bufferCurrentPosition == 511) {
- resetInputBuffer();
- currentBitCount = 8;
- nextByte = dataBuffer[0];
- } else {
- nextByte = dataBuffer[bufferCurrentPosition + 1];
- }
- if (currentByte == 0xFF) {
- if (nextByte == 0) {
- bufferCurrentPosition ++;
- currentBitCount--;
- currentByte *= 2;
- if (currentByte > 255) {
- currentByte -= 256;
- return 1;
- } else {
- return 0;
- }
- } else {
- if ((nextByte & 0xFF) + 0xFF00 == DNL) {
- getDNL();
- return 0;
- } else {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return 0;
- }
- }
- } else {
- currentBitCount--;
- currentByte *= 2;
- if (currentByte > 255) {
- currentByte -= 256;
- return 1;
- } else {
- return 0;
- }
- }
-}
-void processRestartInterval() {
- do {
- bufferCurrentPosition++;
- if (bufferCurrentPosition > 511) {
- resetInputBuffer();
- bufferCurrentPosition = 0;
- }
- currentByte = dataBuffer[bufferCurrentPosition] & 0xFF;
- } while (currentByte != 0xFF);
- while (currentByte == 0xFF) {
- bufferCurrentPosition++;
- if (bufferCurrentPosition > 511) {
- resetInputBuffer();
- bufferCurrentPosition = 0;
- }
- currentByte = dataBuffer[bufferCurrentPosition] & 0xFF;
- }
- if (currentByte != ((RST0 + nextRestartNumber) & 0xFF)) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- bufferCurrentPosition++;
- if (bufferCurrentPosition > 511) {
- resetInputBuffer();
- bufferCurrentPosition = 0;
- }
- currentByte = dataBuffer[bufferCurrentPosition] & 0xFF;
- currentBitCount = 8;
- restartsToGo = restartInterval;
- nextRestartNumber = (nextRestartNumber + 1) & 0x7;
- precedingDCs = new int[4];
- eobrun = 0;
-}
-/* Process all markers until a frame header, scan header, or EOI is found. */
-JPEGSegment processTables() {
- while (true) {
- JPEGSegment jpegSegment = seekUnspecifiedMarker(inputStream);
- if (jpegSegment == null) return null;
- JPEGFrameHeader sof = new JPEGFrameHeader(jpegSegment.reference);
- if (sof.verify()) {
- return jpegSegment;
- }
- int marker = jpegSegment.getSegmentMarker();
- switch (marker) {
- case SOI: // there should only be one SOI per file
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- case EOI:
- case SOS:
- return jpegSegment;
- case DQT:
- getDQT();
- break;
- case DHT:
- getDHT();
- break;
- case DAC:
- getDAC();
- break;
- case DRI:
- getDRI();
- break;
- case APP0:
- getAPP0();
- break;
- case COM:
- getCOM();
- break;
- default:
- skipSegmentFrom(inputStream);
-
- }
- }
-}
-void quantizeData(int[] dataUnit, int iComp) {
- int[] qTable = quantizationTables[frameComponents[componentIds[iComp]][TQI]];
- for (int i = 0; i < dataUnit.length; i++) {
- int zzIndex = ZigZag8x8[i];
- int data = dataUnit[zzIndex];
- int absData = data < 0 ? 0 - data : data;
- int qValue = qTable[i];
- int q2 = qValue >> 1;
- absData += q2;
- if (absData < qValue) {
- dataUnit[zzIndex] = 0;
- } else {
- absData /= qValue;
- if (data >= 0) {
- dataUnit[zzIndex] = absData;
- } else {
- dataUnit[zzIndex] = 0 - absData;
- }
- }
- }
-}
-int receive(int nBits) {
- int v = 0;
- for (int i = 0; i < nBits; i++) {
- v = v * 2 + nextBit();
- }
- return v;
-}
-void resetInputBuffer() {
- if (dataBuffer == null) {
- dataBuffer = new byte[512];
- }
- try {
- inputStream.read(dataBuffer);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- currentBitCount = 0;
- bufferCurrentPosition = -1;
-}
-void resetOutputBuffer() {
- if (dataBuffer == null) {
- dataBuffer = new byte[512];
- } else {
- try {
- outputStream.write(dataBuffer, 0, bufferCurrentPosition);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
- bufferCurrentPosition = 0;
-}
-static JPEGSegment seekUnspecifiedMarker(LEDataInputStream byteStream) {
- byte[] byteArray = new byte[2];
- try {
- while (true) {
- if (byteStream.read(byteArray, 0, 1) != 1) return null;
- if (byteArray[0] == (byte) 0xFF) {
- if (byteStream.read(byteArray, 1, 1) != 1) return null;
- if (byteArray[1] != (byte) 0xFF && byteArray[1] != 0) {
- byteStream.unread(byteArray);
- return new JPEGSegment(byteArray);
- }
- }
- }
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- return null;
-}
-PaletteData setUpPalette() {
- if (nComponents == 1) {
- RGB[] entries = new RGB[256];
- for (int i = 0; i < 256; i++) {
- entries[i] = new RGB(i, i, i);
- }
- return new PaletteData(entries);
- }
- return new PaletteData(0xFF, 0xFF00, 0xFF0000);
-}
-static void skipSegmentFrom(LEDataInputStream byteStream) {
- try {
- byte[] byteArray = new byte[4];
- JPEGSegment jpegSegment = new JPEGSegment(byteArray);
-
- if (byteStream.read(byteArray) != byteArray.length) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- if (!(byteArray[0] == -1 && byteArray[1] != 0 && byteArray[1] != -1)) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- int delta = jpegSegment.getSegmentLength() - 2;
- byteStream.skip(delta);
- } catch (Exception e) {
- SWT.error(SWT.ERROR_IO, e);
- }
-}
-void storeData(int[] dataUnit, int iComp, int xmcu, int ymcu, int hi, int ihi, int vi, int ivi) {
- byte[] compImage = imageComponents[iComp];
- int[] frameComponent = frameComponents[componentIds[iComp]];
- int compWidth = frameComponent[CW];
- int destIndex = ((ymcu * vi + ivi) * compWidth * DCTSIZE) + ((xmcu * hi + ihi) * DCTSIZE);
- int srcIndex = 0;
- for (int i = 0; i < DCTSIZE; i++) {
- for (int col = 0; col < DCTSIZE; col++) {
- int x = dataUnit[srcIndex] + 128;
- if (x < 0) {
- x = 0;
- } else {
- if (x > 255) x = 255;
- }
- compImage[destIndex + col] = (byte)x;
- srcIndex++;
- }
- destIndex += compWidth;
- }
-}
-void unloadIntoByteStream(ImageLoader loader) {
- ImageData image = loader.data[0];
- if (!new JPEGStartOfImage().writeToStream(outputStream)) {
- SWT.error(SWT.ERROR_IO);
- }
- JPEGAppn appn = new JPEGAppn(new byte[] {(byte)0xFF, (byte)0xE0, 0, 0x10, 0x4A, 0x46, 0x49, 0x46, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0});
- if (!appn.writeToStream(outputStream)) {
- SWT.error(SWT.ERROR_IO);
- }
- quantizationTables = new int[4][];
- JPEGQuantizationTable chromDQT = JPEGQuantizationTable.defaultChrominanceTable();
- chromDQT.scaleBy(encoderQFactor);
- int[] jpegDQTKeys = chromDQT.getQuantizationTablesKeys();
- int[][] jpegDQTValues = chromDQT.getQuantizationTablesValues();
- for (int i = 0; i < jpegDQTKeys.length; i++) {
- quantizationTables[jpegDQTKeys[i]] = jpegDQTValues[i];
- }
- JPEGQuantizationTable lumDQT = JPEGQuantizationTable.defaultLuminanceTable();
- lumDQT.scaleBy(encoderQFactor);
- jpegDQTKeys = lumDQT.getQuantizationTablesKeys();
- jpegDQTValues = lumDQT.getQuantizationTablesValues();
- for (int i = 0; i < jpegDQTKeys.length; i++) {
- quantizationTables[jpegDQTKeys[i]] = jpegDQTValues[i];
- }
- if (!lumDQT.writeToStream(outputStream)) {
- SWT.error(SWT.ERROR_IO);
- }
- if (!chromDQT.writeToStream(outputStream)) {
- SWT.error(SWT.ERROR_IO);
- }
- int frameLength, scanLength, precision;
- int[][] frameParams, scanParams;
- if (image.depth == 1) {
- frameLength = 11;
- frameParams = new int[1][];
- frameParams[0] = new int[] {1, 1, 1, 0, 0};
- scanParams = new int[1][];
- scanParams[0] = new int[] {0, 0};
- scanLength = 8;
- nComponents = 1;
- precision = 1;
- } else {
- frameLength = 17;
- frameParams = new int[3][];
- frameParams[0] = new int[] {0, 2, 2, 0, 0};
- frameParams[1] = new int[] {1, 1, 1, 0, 0};
- frameParams[2] = new int[] {1, 1, 1, 0, 0};
- scanParams = new int[3][];
- scanParams[0] = new int[] {0, 0};
- scanParams[1] = new int[] {1, 1};
- scanParams[2] = new int[] {1, 1};
- scanLength = 12;
- nComponents = 3;
- precision = 8;
- }
- imageWidth = image.width;
- imageHeight = image.height;
- frameHeader = new JPEGFrameHeader(new byte[19]);
- frameHeader.setSegmentMarker(SOF0);
- frameHeader.setSegmentLength(frameLength);
- frameHeader.setSamplePrecision(precision);
- frameHeader.setSamplesPerLine(imageWidth);
- frameHeader.setNumberOfLines(imageHeight);
- frameHeader.setNumberOfImageComponents(nComponents);
- frameHeader.componentParameters = frameParams;
- frameHeader.componentIdentifiers = new int[] {0, 1, 2};
- frameHeader.initializeContents();
- if (!frameHeader.writeToStream(outputStream)) {
- SWT.error(SWT.ERROR_IO);
- }
- frameComponents = frameParams;
- componentIds = frameHeader.componentIdentifiers;
- maxH = frameHeader.getMaxHFactor();
- maxV = frameHeader.getMaxVFactor();
- int mcuWidth = maxH * DCTSIZE;
- int mcuHeight = maxV * DCTSIZE;
- interleavedMcuCols = (imageWidth + mcuWidth - 1) / mcuWidth;
- interleavedMcuRows = (imageHeight + mcuHeight - 1) / mcuHeight;
- acHuffmanTables = new JPEGHuffmanTable[4];
- dcHuffmanTables = new JPEGHuffmanTable[4];
- JPEGHuffmanTable[] dhtTables = new JPEGHuffmanTable[] {
- JPEGHuffmanTable.getDefaultDCLuminanceTable(),
- JPEGHuffmanTable.getDefaultDCChrominanceTable(),
- JPEGHuffmanTable.getDefaultACLuminanceTable(),
- JPEGHuffmanTable.getDefaultACChrominanceTable()
- };
- for (int i = 0; i < dhtTables.length; i++) {
- JPEGHuffmanTable dhtTable = dhtTables[i];
- if (!dhtTable.writeToStream(outputStream)) {
- SWT.error(SWT.ERROR_IO);
- }
- JPEGHuffmanTable[] allTables = dhtTable.getAllTables();
- for (int j = 0; j < allTables.length; j++) {
- JPEGHuffmanTable huffmanTable = allTables[j];
- if (huffmanTable.getTableClass() == 0) {
- dcHuffmanTables[huffmanTable.getTableIdentifier()] = huffmanTable;
- } else {
- acHuffmanTables[huffmanTable.getTableIdentifier()] = huffmanTable;
- }
- }
- }
- precedingDCs = new int[4];
- scanHeader = new JPEGScanHeader(new byte[14]);
- scanHeader.setSegmentMarker(SOS);
- scanHeader.setSegmentLength(scanLength);
- scanHeader.setNumberOfImageComponents(nComponents);
- scanHeader.setStartOfSpectralSelection(0);
- scanHeader.setEndOfSpectralSelection(63);
- scanHeader.componentParameters = scanParams;
- scanHeader.initializeContents();
- if (!scanHeader.writeToStream(outputStream)) {
- SWT.error(SWT.ERROR_IO);
- }
- convertImageToYCbCr(image);
- resetOutputBuffer();
- currentByte = 0;
- currentBitCount = 0;
- encodeScan();
- if (!new JPEGEndOfImage().writeToStream(outputStream)) {
- SWT.error(SWT.ERROR_IO);
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFixedSizeSegment.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFixedSizeSegment.java
deleted file mode 100755
index 28da86905d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFixedSizeSegment.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-
-abstract class JPEGFixedSizeSegment extends JPEGSegment {
-
- public JPEGFixedSizeSegment() {
- reference = new byte[fixedSize()];
- setSegmentMarker(signature());
- }
-
- public JPEGFixedSizeSegment(byte[] reference) {
- super(reference);
- }
-
- public JPEGFixedSizeSegment(LEDataInputStream byteStream) {
- reference = new byte[fixedSize()];
- try {
- byteStream.read(reference);
- } catch (Exception e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
-
- abstract public int fixedSize();
-
- public int getSegmentLength() {
- return fixedSize() - 2;
- }
-
- public void setSegmentLength(int length) {
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFrameHeader.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFrameHeader.java
deleted file mode 100755
index 00d761078c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFrameHeader.java
+++ /dev/null
@@ -1,214 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-
-final class JPEGFrameHeader extends JPEGVariableSizeSegment {
- int maxVFactor;
- int maxHFactor;
- public int[] componentIdentifiers;
- public int[][] componentParameters;
-
- public JPEGFrameHeader(byte[] reference) {
- super(reference);
- }
-
- public JPEGFrameHeader(LEDataInputStream byteStream) {
- super(byteStream);
- initializeComponentParameters();
- }
-
- public int getSamplePrecision() {
- return reference[4] & 0xFF;
- }
-
- public int getNumberOfLines() {
- return (reference[5] & 0xFF) << 8 | (reference[6] & 0xFF);
- }
-
- public int getSamplesPerLine() {
- return (reference[7] & 0xFF) << 8 | (reference[8] & 0xFF);
- }
-
- public int getNumberOfImageComponents() {
- return reference[9] & 0xFF;
- }
-
- public void setSamplePrecision(int precision) {
- reference[4] = (byte)(precision & 0xFF);
- }
-
- public void setNumberOfLines(int anInteger) {
- reference[5] = (byte)((anInteger & 0xFF00) >> 8);
- reference[6] = (byte)(anInteger & 0xFF);
- }
-
- public void setSamplesPerLine(int samples) {
- reference[7] = (byte)((samples & 0xFF00) >> 8);
- reference[8] = (byte)(samples & 0xFF);
- }
-
- public void setNumberOfImageComponents(int anInteger) {
- reference[9] = (byte)(anInteger & 0xFF);
- }
-
- public int getMaxHFactor() {
- return maxHFactor;
- }
-
- public int getMaxVFactor() {
- return maxVFactor;
- }
-
- public void setMaxHFactor(int anInteger) {
- maxHFactor = anInteger;
- }
-
- public void setMaxVFactor(int anInteger) {
- maxVFactor = anInteger;
- }
-
- /* Used when decoding. */
- void initializeComponentParameters() {
- int nf = getNumberOfImageComponents();
- componentIdentifiers = new int[nf];
- int[][] compSpecParams = new int[0][];
- int hmax = 1;
- int vmax = 1;
- for (int i = 0; i < nf; i++) {
- int ofs = i * 3 + 10;
- int ci = reference[ofs] & 0xFF;
- componentIdentifiers[i] = ci;
- int hi = (reference[ofs + 1] & 0xFF) >> 4;
- int vi = reference[ofs + 1] & 0xF;
- int tqi = reference[ofs + 2] & 0xFF;
- if (hi > hmax) {
- hmax = hi;
- }
- if (vi > vmax) {
- vmax = vi;
- }
- int[] compParam = new int[5];
- compParam[0] = tqi;
- compParam[1] = hi;
- compParam[2] = vi;
- if (compSpecParams.length <= ci) {
- int[][] newParams = new int[ci + 1][];
- System.arraycopy(compSpecParams, 0, newParams, 0, compSpecParams.length);
- compSpecParams = newParams;
- }
- compSpecParams[ci] = compParam;
- }
- int x = getSamplesPerLine();
- int y = getNumberOfLines();
- int[] multiples = new int[] { 8, 16, 24, 32 };
- for (int i = 0; i < nf; i++) {
- int[] compParam = compSpecParams[componentIdentifiers[i]];
- int hi = compParam[1];
- int vi = compParam[2];
- int compWidth = (x * hi + hmax - 1) / hmax;
- int compHeight = (y * vi + vmax - 1) / vmax;
- int dsWidth = roundUpToMultiple(compWidth, multiples[hi - 1]);
- int dsHeight = roundUpToMultiple(compHeight, multiples[vi - 1]);
- compParam[3] = dsWidth;
- compParam[4] = dsHeight;
- }
- setMaxHFactor(hmax);
- setMaxVFactor(vmax);
- componentParameters = compSpecParams;
- }
-
- /* Used when encoding. */
- public void initializeContents() {
- int nf = getNumberOfImageComponents();
- if (nf == 0 || nf != componentParameters.length) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- int hmax = 0;
- int vmax = 0;
- int[][] compSpecParams = componentParameters;
- for (int i = 0; i < nf; i++) {
- int ofs = i * 3 + 10;
- int[] compParam = compSpecParams[componentIdentifiers[i]];
- int hi = compParam[1];
- int vi = compParam[2];
- if (hi * vi > 4) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- reference[ofs] = (byte)(i + 1);
- reference[ofs + 1] = (byte)(hi * 16 + vi);
- reference[ofs + 2] = (byte)(compParam[0]);
- if (hi > hmax) hmax = hi;
- if (vi > vmax) vmax = vi;
- }
- int x = getSamplesPerLine();
- int y = getNumberOfLines();
- int[] multiples = new int[] {8, 16, 24, 32};
- for (int i = 0; i < nf; i++) {
- int[] compParam = compSpecParams[componentIdentifiers[i]];
- int hi = compParam[1];
- int vi = compParam[2];
- int compWidth = (x * hi + hmax - 1) / hmax;
- int compHeight = (y * vi + vmax - 1) / vmax;
- int dsWidth = roundUpToMultiple(compWidth, multiples[hi - 1]);
- int dsHeight = roundUpToMultiple(compHeight, multiples[vi - 1]);
- compParam[3] = dsWidth;
- compParam[4] = dsHeight;
- }
- setMaxHFactor(hmax);
- setMaxVFactor(vmax);
- }
-
- int roundUpToMultiple(int anInteger, int mInteger) {
- int a = anInteger + mInteger - 1;
- return a - (a % mInteger);
- }
-
- /*
- * Verify the information contained in the receiver is correct.
- * Answer true if the header contains a valid marker. Otherwise,
- * answer false. Valid Start Of Frame markers are:
- * SOF_0 - Baseline DCT, Huffman coding
- * SOF_1 - Extended sequential DCT, Huffman coding
- * SOF_2 - Progressive DCT, Huffman coding
- * SOF_3 - Lossless (sequential), Huffman coding
- * SOF_5 - Differential sequential, Huffman coding
- * SOF_6 - Differential progressive, Huffman coding
- * SOF_7 - Differential lossless, Huffman coding
- * SOF_9 - Extended sequential DCT, arithmetic coding
- * SOF_10 - Progressive DCT, arithmetic coding
- * SOF_11 - Lossless (sequential), arithmetic coding
- * SOF_13 - Differential sequential, arithmetic coding
- * SOF_14 - Differential progressive, arithmetic coding
- * SOF_15 - Differential lossless, arithmetic coding
- */
- public boolean verify() {
- int marker = getSegmentMarker();
- return (marker >= JPEGFileFormat.SOF0 && marker <= JPEGFileFormat.SOF3) ||
- (marker >= JPEGFileFormat.SOF5 && marker <= JPEGFileFormat.SOF7) ||
- (marker >= JPEGFileFormat.SOF9 && marker <= JPEGFileFormat.SOF11) ||
- (marker >= JPEGFileFormat.SOF13 && marker <= JPEGFileFormat.SOF15);
- }
-
- public boolean isProgressive() {
- int marker = getSegmentMarker();
- return marker == JPEGFileFormat.SOF2
- || marker == JPEGFileFormat.SOF6
- || marker == JPEGFileFormat.SOF10
- || marker == JPEGFileFormat.SOF14;
- }
-
- public boolean isArithmeticCoding() {
- return getSegmentMarker() >= JPEGFileFormat.SOF9;
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGHuffmanTable.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGHuffmanTable.java
deleted file mode 100755
index 043c6157e0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGHuffmanTable.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-/**
- * JPEGHuffmanTable class actually represents two types of object:
- * 1) A DHT (Define Huffman Tables) segment, which may represent
- * as many as 4 Huffman tables. In this case, the tables are
- * stored in the allTables array.
- * 2) A single Huffman table. In this case, the allTables array
- * will be null.
- * The 'reference' field is stored in both types of object, but
- * 'initialize' is only called if the object represents a DHT.
- */
-final class JPEGHuffmanTable extends JPEGVariableSizeSegment {
- JPEGHuffmanTable[] allTables;
- int tableClass;
- int tableIdentifier;
- int[] dhMaxCodes;
- int[] dhMinCodes;
- int[] dhValPtrs;
- int[] dhValues;
- int[] ehCodes;
- byte[] ehCodeLengths;
- static byte[] DCLuminanceTable = {
- (byte)255, (byte)196, 0, 31, 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
- };
- static byte[] DCChrominanceTable = {
- (byte)255, (byte)196, 0, 31, 1, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
- };
- static byte[] ACLuminanceTable = {
- (byte)255, (byte)196, 0, (byte)181, 16, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125,
- 1, 2, 3, 0, 4, 17, 5, 18, 33, 49, 65, 6, 19, 81, 97, 7, 34, 113, 20,
- 50, (byte)129, (byte)145, (byte)161, 8, 35, 66, (byte)177, (byte)193, 21, 82, (byte)209, (byte)240, 36, 51, 98,
- 114, (byte)130, 9, 10, 22, 23, 24, 25, 26, 37, 38, 39, 40, 41, 42, 52, 53,
- 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87,
- 88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118,
- 119, 120, 121, 122, (byte)131, (byte)132, (byte)133, (byte)134, (byte)135, (byte)136, (byte)137, (byte)138, (byte)146, (byte)147, (byte)148,
- (byte)149, (byte)150, (byte)151, (byte)152, (byte)153, (byte)154, (byte)162, (byte)163, (byte)164, (byte)165, (byte)166, (byte)167, (byte)168, (byte)169, (byte)170,
- (byte)178, (byte)179, (byte)180, (byte)181, (byte)182, (byte)183, (byte)184, (byte)185, (byte)186, (byte)194, (byte)195, (byte)196, (byte)197, (byte)198, (byte)199,
- (byte)200, (byte)201, (byte)202, (byte)210, (byte)211, (byte)212, (byte)213, (byte)214, (byte)215, (byte)216, (byte)217, (byte)218, (byte)225, (byte)226, (byte)227,
- (byte)228, (byte)229, (byte)230, (byte)231, (byte)232, (byte)233, (byte)234, (byte)241, (byte)242, (byte)243, (byte)244, (byte)245, (byte)246, (byte)247, (byte)248,
- (byte)249, (byte)250
- };
- static byte[] ACChrominanceTable = {
- (byte)255, (byte)196, 0, (byte)181, 17, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0,
- 1, 2, 119, 0, 1, 2, 3, 17, 4, 5, 33, 49, 6, 18, 65, 81, 7, 97, 113, 19, 34,
- 50, (byte)129, 8, 20, 66, (byte)145, (byte)161, (byte)177, (byte)193, 9, 35,
- 51, 82, (byte)240, 21, 98, 114, (byte)209, 10, 22, 36, 52, (byte)225, 37,
- (byte)241, 23, 24, 25, 26, 38, 39, 40, 41, 42, 53, 54, 55, 56, 57, 58, 67,
- 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102,
- 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, (byte)130,
- (byte)131, (byte)132, (byte)133, (byte)134, (byte)135, (byte)136, (byte)137,
- (byte)138, (byte)146, (byte)147, (byte)148, (byte)149, (byte)150, (byte)151,
- (byte)152, (byte)153, (byte)154, (byte)162, (byte)163, (byte)164, (byte)165,
- (byte)166, (byte)167, (byte)168, (byte)169, (byte)170, (byte)178, (byte)179,
- (byte)180, (byte)181, (byte)182, (byte)183, (byte)184, (byte)185, (byte)186,
- (byte)194, (byte)195, (byte)196, (byte)197, (byte)198, (byte)199, (byte)200,
- (byte)201, (byte)202, (byte)210, (byte)211, (byte)212, (byte)213, (byte)214,
- (byte)215, (byte)216, (byte)217, (byte)218, (byte)226, (byte)227, (byte)228,
- (byte)229, (byte)230, (byte)231, (byte)232, (byte)233, (byte)234, (byte)242,
- (byte)243, (byte)244, (byte)245, (byte)246, (byte)247, (byte)248, (byte)249,
- (byte)250
- };
-
-public JPEGHuffmanTable(byte[] reference) {
- super(reference);
-}
-
-public JPEGHuffmanTable(LEDataInputStream byteStream) {
- super(byteStream);
- initialize();
-}
-
-public JPEGHuffmanTable[] getAllTables() {
- return allTables;
-}
-
-public static JPEGHuffmanTable getDefaultACChrominanceTable() {
- JPEGHuffmanTable result = new JPEGHuffmanTable(ACChrominanceTable);
- result.initialize();
- return result;
-}
-
-public static JPEGHuffmanTable getDefaultACLuminanceTable() {
- JPEGHuffmanTable result = new JPEGHuffmanTable(ACLuminanceTable);
- result.initialize();
- return result;
-}
-
-public static JPEGHuffmanTable getDefaultDCChrominanceTable() {
- JPEGHuffmanTable result = new JPEGHuffmanTable(DCChrominanceTable);
- result.initialize();
- return result;
-}
-
-public static JPEGHuffmanTable getDefaultDCLuminanceTable() {
- JPEGHuffmanTable result = new JPEGHuffmanTable(DCLuminanceTable);
- result.initialize();
- return result;
-}
-
-public int[] getDhMaxCodes() {
- return dhMaxCodes;
-}
-
-public int[] getDhMinCodes() {
- return dhMinCodes;
-}
-
-public int[] getDhValPtrs() {
- return dhValPtrs;
-}
-
-public int[] getDhValues() {
- return dhValues;
-}
-
-public int getTableClass() {
- return tableClass;
-}
-
-public int getTableIdentifier() {
- return tableIdentifier;
-}
-
-void initialize() {
- int totalLength = getSegmentLength() - 2;
- int ofs = 4;
- int[] bits = new int[16];
- JPEGHuffmanTable[] huffTables = new JPEGHuffmanTable[8]; // maximum is 4 AC + 4 DC
- int huffTableCount = 0;
- while (totalLength > 0) {
- int tc = (reference[ofs] & 0xFF) >> 4; // table class: AC (1) or DC (0)
- int tid = reference[ofs] & 0xF; // table id: 0-1 baseline, 0-3 prog/ext
- ofs++;
-
- /* Read the 16 count bytes and add them together to get the table size. */
- int count = 0;
- for (int i = 0; i < bits.length; i++) {
- int bCount = reference[ofs + i] & 0xFF;
- bits[i] = bCount;
- count += bCount;
- }
- ofs += 16;
- totalLength -= 17;
-
- /* Read the table. */
- int[] huffVals = new int[count];
- for (int i = 0; i < count; i++) {
- huffVals[i] = reference[ofs + i] & 0xFF;
- }
- ofs += count;
- totalLength -= count;
-
- /* Calculate the lengths. */
- int[] huffCodeLengths = new int[50]; // start with 50 and increment as needed
- int huffCodeLengthsIndex = 0;
- for (int i = 0; i < 16; i++) {
- for (int j = 0; j < bits[i]; j++) {
- if (huffCodeLengthsIndex >= huffCodeLengths.length) {
- int[] newHuffCodeLengths = new int[huffCodeLengths.length + 50];
- System.arraycopy(huffCodeLengths, 0, newHuffCodeLengths, 0, huffCodeLengths.length);
- huffCodeLengths = newHuffCodeLengths;
- }
- huffCodeLengths[huffCodeLengthsIndex] = i + 1;
- huffCodeLengthsIndex++;
- }
- }
-
- /* Truncate huffCodeLengths to the correct size. */
- if (huffCodeLengthsIndex < huffCodeLengths.length) {
- int[] newHuffCodeLengths = new int[huffCodeLengthsIndex];
- System.arraycopy(huffCodeLengths, 0, newHuffCodeLengths, 0, huffCodeLengthsIndex);
- huffCodeLengths = newHuffCodeLengths;
- }
-
- /* Calculate the Huffman codes. */
- int[] huffCodes = new int[50]; // start with 50 and increment as needed
- int huffCodesIndex = 0;
- int k = 1;
- int code = 0;
- int si = huffCodeLengths[0];
- int p = 0;
- while (p < huffCodeLengthsIndex) {
- while ((p < huffCodeLengthsIndex) && (huffCodeLengths[p] == si)) {
- if (huffCodesIndex >= huffCodes.length) {
- int[] newHuffCodes = new int[huffCodes.length + 50];
- System.arraycopy(huffCodes, 0, newHuffCodes, 0, huffCodes.length);
- huffCodes = newHuffCodes;
- }
- huffCodes[huffCodesIndex] = code;
- huffCodesIndex++;
- code++;
- p++;
- }
- code *= 2;
- si++;
- }
-
- /* Truncate huffCodes to the correct size. */
- if (huffCodesIndex < huffCodes.length) {
- int[] newHuffCodes = new int[huffCodesIndex];
- System.arraycopy(huffCodes, 0, newHuffCodes, 0, huffCodesIndex);
- huffCodes = newHuffCodes;
- }
-
- /* Calculate the maximum and minimum codes */
- k = 0;
- int[] maxCodes = new int[16];
- int[] minCodes = new int[16];
- int[] valPtrs = new int[16];
- for (int i = 0; i < 16; i++) {
- int bSize = bits[i];
- if (bSize == 0) {
- maxCodes[i] = -1;
- } else {
- valPtrs[i] = k;
- minCodes[i] = huffCodes[k];
- k += bSize;
- maxCodes[i] = huffCodes[k - 1];
- }
- }
-
- /* Calculate the eHuffman codes and lengths. */
- int[] eHuffCodes = new int[256];
- byte[] eHuffSize = new byte[256];
- for (int i = 0; i < huffCodesIndex; i++) {
- eHuffCodes[huffVals[i]] = huffCodes[i];
- eHuffSize[huffVals[i]] = (byte)huffCodeLengths[i];
- }
-
- /* Create the new JPEGHuffmanTable and add it to the allTables array. */
- JPEGHuffmanTable dhtTable = new JPEGHuffmanTable(reference);
- dhtTable.tableClass = tc;
- dhtTable.tableIdentifier = tid;
- dhtTable.dhValues = huffVals;
- dhtTable.dhMinCodes = minCodes;
- dhtTable.dhMaxCodes = maxCodes;
- dhtTable.dhValPtrs = valPtrs;
- dhtTable.ehCodes = eHuffCodes;
- dhtTable.ehCodeLengths = eHuffSize;
- huffTables[huffTableCount] = dhtTable;
- huffTableCount++;
- }
- allTables = new JPEGHuffmanTable[huffTableCount];
- System.arraycopy(huffTables, 0, allTables, 0, huffTableCount);
-}
-
-public int signature() {
- return JPEGFileFormat.DHT;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGQuantizationTable.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGQuantizationTable.java
deleted file mode 100755
index 18eab61ff6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGQuantizationTable.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-final class JPEGQuantizationTable extends JPEGVariableSizeSegment {
- public static byte[] DefaultLuminanceQTable = {
- (byte)255, (byte)219, 0, 67, 0,
- 16, 11, 10, 16, 24, 40, 51, 61,
- 12, 12, 14, 19, 26, 58, 60, 55,
- 14, 13, 16, 24, 40, 57, 69, 56,
- 14, 17, 22, 29, 51, 87, 80, 62,
- 18, 22, 37, 56, 68, 109, 103, 77,
- 24, 35, 55, 64, 81, 104, 113, 92,
- 49, 64, 78, 87, 103, 121, 120, 101,
- 72, 92, 95, 98, 112, 100, 103, 99
- };
- public static byte[] DefaultChrominanceQTable = {
- (byte)255, (byte)219, 0, 67, 1,
- 17, 18, 24, 47, 99, 99, 99, 99,
- 18, 21, 26, 66, 99, 99, 99, 99,
- 24, 26, 56, 99, 99, 99, 99, 99,
- 47, 66, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99
- };
-
-public JPEGQuantizationTable(byte[] reference) {
- super(reference);
-}
-
-public JPEGQuantizationTable(LEDataInputStream byteStream) {
- super(byteStream);
-}
-
-public static JPEGQuantizationTable defaultChrominanceTable() {
- byte[] data = new byte[DefaultChrominanceQTable.length];
- System.arraycopy(DefaultChrominanceQTable, 0, data, 0, data.length);
- return new JPEGQuantizationTable(data);
-}
-
-public static JPEGQuantizationTable defaultLuminanceTable() {
- byte[] data = new byte[DefaultLuminanceQTable.length];
- System.arraycopy(DefaultLuminanceQTable, 0, data, 0, data.length);
- return new JPEGQuantizationTable(data);
-}
-
-public int[] getQuantizationTablesKeys() {
- int[] keys = new int[4];
- int keysIndex = 0;
- int totalLength = getSegmentLength() - 2;
- int ofs = 4;
- while (totalLength > 64) {
- int tq = reference[ofs] & 0xF;
- int pq = (reference[ofs] & 0xFF) >> 4;
- if (pq == 0) {
- ofs += 65;
- totalLength -= 65;
- } else {
- ofs += 129;
- totalLength -= 129;
- }
- if (keysIndex >= keys.length) {
- int[] newKeys = new int[keys.length + 4];
- System.arraycopy(keys, 0, newKeys, 0, keys.length);
- keys = newKeys;
- }
- keys[keysIndex] = tq;
- keysIndex++;
- }
- int[] newKeys = new int[keysIndex];
- System.arraycopy(keys, 0, newKeys, 0, keysIndex);
- return newKeys;
-}
-
-public int[][] getQuantizationTablesValues() {
- int[][] values = new int[4][];
- int valuesIndex = 0;
- int totalLength = getSegmentLength() - 2;
- int ofs = 4;
- while (totalLength > 64) {
- int[] qk = new int[64];
- int pq = (reference[ofs] & 0xFF) >> 4;
- if (pq == 0) {
- for (int i = 0; i < qk.length; i++) {
- qk[i] = reference[ofs + i + 1] & 0xFF;
- }
- ofs += 65;
- totalLength -= 65;
- } else {
- for (int i = 0; i < qk.length; i++) {
- int idx = (i - 1) * 2 ;
- qk[i] = (reference[ofs + idx + 1] & 0xFF) * 256 + (reference[ofs + idx + 2] & 0xFF);
- }
- ofs += 129;
- totalLength -= 129;
- }
- if (valuesIndex >= values.length) {
- int[][] newValues = new int[values.length + 4][];
- System.arraycopy(values, 0, newValues, 0, values.length);
- values = newValues;
- }
- values[valuesIndex] = qk;
- valuesIndex++;
- }
- int[][] newValues = new int[valuesIndex][];
- System.arraycopy(values, 0, newValues, 0, valuesIndex);
- return newValues;
-}
-
-public void scaleBy(int qualityFactor) {
- int qFactor = qualityFactor;
- if (qFactor <= 0) {
- qFactor = 1;
- }
- if (qFactor > 100) {
- qFactor = 100;
- }
- if (qFactor < 50) {
- qFactor = 5000 / qFactor;
- } else {
- qFactor = 200 - (qFactor * 2);
- }
- int totalLength = getSegmentLength() - 2;
- int ofs = 4;
- while (totalLength > 64) {
-// int tq = reference[ofs] & 0xFF;
- int pq = (reference[ofs] & 0xFF) >> 4;
- if (pq == 0) {
- for (int i = ofs + 1; i <= ofs + 64; i++) {
- int temp = ((reference[i] & 0xFF) * qFactor + 50) / 100;
- if (temp <= 0) temp = 1;
- if (temp > 255) temp = 255;
- reference[i] = (byte)temp;
- }
- ofs += 65;
- totalLength -= 65;
- } else {
- for (int i = ofs + 1; i <= ofs + 128; i += 2) {
- int temp = (((reference[i] & 0xFF) * 256 + (reference[i + 1] & 0xFF)) * qFactor + 50) / 100;
- if (temp <= 0) temp = 1;
- if (temp > 32767) temp = 32767;
- reference[i] = (byte)(temp >> 8);
- reference[i + 1] = (byte)(temp & 0xFF);
- }
- ofs += 129;
- totalLength -= 129;
- }
- }
-}
-
-public int signature() {
- return JPEGFileFormat.DQT;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGRestartInterval.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGRestartInterval.java
deleted file mode 100755
index fd6fc48ef0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGRestartInterval.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-final class JPEGRestartInterval extends JPEGFixedSizeSegment {
-
- public JPEGRestartInterval(LEDataInputStream byteStream) {
- super(byteStream);
- }
-
- public int signature() {
- return JPEGFileFormat.DRI;
- }
-
- public int getRestartInterval() {
- return ((reference[4] & 0xFF) << 8 | (reference[5] & 0xFF));
- }
-
- public int fixedSize() {
- return 6;
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGScanHeader.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGScanHeader.java
deleted file mode 100755
index ae8d25d884..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGScanHeader.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-
-final class JPEGScanHeader extends JPEGVariableSizeSegment {
- public int[][] componentParameters;
-
-public JPEGScanHeader(byte[] reference) {
- super(reference);
-}
-
-public JPEGScanHeader(LEDataInputStream byteStream) {
- super(byteStream);
- initializeComponentParameters();
-}
-
-public int getApproxBitPositionHigh() {
- return reference[(2 * getNumberOfImageComponents()) + 7] >> 4;
-}
-
-public int getApproxBitPositionLow() {
- return reference[(2 * getNumberOfImageComponents()) + 7] & 0xF;
-}
-
-public int getEndOfSpectralSelection() {
- return reference[(2 * getNumberOfImageComponents()) + 6];
-}
-
-public int getNumberOfImageComponents() {
- return reference[4];
-}
-
-public int getStartOfSpectralSelection() {
- return reference[(2 * getNumberOfImageComponents()) + 5];
-}
-
-/* Used when decoding. */
-void initializeComponentParameters() {
- int compCount = getNumberOfImageComponents();
- componentParameters = new int[0][];
- for (int i = 0; i < compCount; i++) {
- int ofs = 5 + i * 2;
- int cid = reference[ofs] & 0xFF;
- int dc = (reference[ofs + 1] & 0xFF) >> 4;
- int ac = reference[ofs + 1] & 0xF;
- if (componentParameters.length <= cid) {
- int[][] newParams = new int[cid + 1][];
- System.arraycopy(componentParameters, 0, newParams, 0, componentParameters.length);
- componentParameters = newParams;
- }
- componentParameters[cid] = new int[] { dc, ac };
- }
-}
-
-/* Used when encoding. */
-public void initializeContents() {
- int compCount = getNumberOfImageComponents();
- int[][] compSpecParams = componentParameters;
- if (compCount == 0 || compCount != compSpecParams.length) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- for (int i = 0; i < compCount; i++) {
- int ofs = i * 2 + 5;
- int[] compParams = compSpecParams[i];
- reference[ofs] = (byte)(i + 1);
- reference[ofs + 1] = (byte)(compParams[0] * 16 + compParams[1]);
- }
-}
-
-public void setEndOfSpectralSelection(int anInteger) {
- reference[(2 * getNumberOfImageComponents()) + 6] = (byte)anInteger;
-}
-
-public void setNumberOfImageComponents(int anInteger) {
- reference[4] = (byte)(anInteger & 0xFF);
-}
-
-public void setStartOfSpectralSelection(int anInteger) {
- reference[(2 * getNumberOfImageComponents()) + 5] = (byte)anInteger;
-}
-
-public int signature() {
- return JPEGFileFormat.SOS;
-}
-
-public boolean verifyProgressiveScan() {
- int start = getStartOfSpectralSelection();
- int end = getEndOfSpectralSelection();
- int low = getApproxBitPositionLow();
- int high = getApproxBitPositionHigh();
- int count = getNumberOfImageComponents();
- if ((start == 0 && end == 00) || (start <= end && end <= 63)) {
- if (low <= 13 && high <= 13 && (high == 0 || high == low + 1)) {
- return start == 0 || (start > 0 && count == 1);
- }
- }
- return false;
-}
-
-public boolean isACProgressiveScan() {
- return getStartOfSpectralSelection() != 0 && getEndOfSpectralSelection() != 0;
-}
-
-public boolean isDCProgressiveScan() {
- return getStartOfSpectralSelection() == 0 && getEndOfSpectralSelection() == 0;
-}
-
-public boolean isFirstScan() {
- return getApproxBitPositionHigh() == 0;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGSegment.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGSegment.java
deleted file mode 100755
index 0dbf42aa89..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGSegment.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-class JPEGSegment {
- public byte[] reference;
-
- JPEGSegment() {
- }
-
- public JPEGSegment(byte[] reference) {
- this.reference = reference;
- }
-
- public int signature() {
- return 0;
- }
-
- public boolean verify() {
- return getSegmentMarker() == signature();
- }
-
- public int getSegmentMarker() {
- return ((reference[0] & 0xFF) << 8 | (reference[1] & 0xFF));
- }
-
- public void setSegmentMarker(int marker) {
- reference[0] = (byte)((marker & 0xFF00) >> 8);
- reference[1] = (byte)(marker & 0xFF);
- }
-
- public int getSegmentLength() {
- return ((reference[2] & 0xFF) << 8 | (reference[3] & 0xFF));
- }
-
- public void setSegmentLength(int length) {
- reference[2] = (byte)((length & 0xFF00) >> 8);
- reference[3] = (byte)(length & 0xFF);
- }
-
- public boolean writeToStream(LEDataOutputStream byteStream) {
- try {
- byteStream.write(reference);
- return true;
- } catch (Exception e) {
- return false;
- }
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGStartOfImage.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGStartOfImage.java
deleted file mode 100755
index 5b809994e4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGStartOfImage.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-final class JPEGStartOfImage extends JPEGFixedSizeSegment {
-
- public JPEGStartOfImage() {
- super();
- }
-
- public JPEGStartOfImage(byte[] reference) {
- super(reference);
- }
-
- public JPEGStartOfImage(LEDataInputStream byteStream) {
- super(byteStream);
- }
-
- public int signature() {
- return JPEGFileFormat.SOI;
- }
-
- public int fixedSize() {
- return 2;
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGVariableSizeSegment.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGVariableSizeSegment.java
deleted file mode 100755
index a3896e6706..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGVariableSizeSegment.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-
-abstract class JPEGVariableSizeSegment extends JPEGSegment {
-
- public JPEGVariableSizeSegment(byte[] reference) {
- super(reference);
- }
-
- public JPEGVariableSizeSegment(LEDataInputStream byteStream) {
- try {
- byte[] header = new byte[4];
- byteStream.read(header);
- reference = header; // to use getSegmentLength()
- byte[] contents = new byte[getSegmentLength() + 2];
- contents[0] = header[0];
- contents[1] = header[1];
- contents[2] = header[2];
- contents[3] = header[3];
- byteStream.read(contents, 4, contents.length - 4);
- reference = contents;
- } catch (Exception e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LEDataInputStream.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LEDataInputStream.java
deleted file mode 100755
index f399989a32..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LEDataInputStream.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import java.io.*;
-
-final class LEDataInputStream extends InputStream {
- int position;
- InputStream in;
-
- /**
- * The byte array containing the bytes to read.
- */
- protected byte[] buf;
-
- /**
- * The current position within the byte array <code>buf</code>. A value
- * equal to buf.length indicates no bytes available. A value of
- * 0 indicates the buffer is full.
- */
- protected int pos;
-
-
- public LEDataInputStream(InputStream input) {
- this(input, 512);
- }
-
- public LEDataInputStream(InputStream input, int bufferSize) {
- this.in = input;
- if (bufferSize > 0) {
- buf = new byte[bufferSize];
- pos = bufferSize;
- }
- else throw new IllegalArgumentException();
- }
-
- public void close() throws IOException {
- buf = null;
- if (in != null) {
- in.close();
- in = null;
- }
- }
-
- /**
- * Answer how many bytes were read.
- */
- public int getPosition() {
- return position;
- }
-
- /**
- * Answers how many bytes are available for reading without blocking
- */
- public int available() throws IOException {
- if (buf == null) throw new IOException();
- return (buf.length - pos) + in.available();
- }
-
- /**
- * Answer the next byte of the input stream.
- */
- public int read() throws IOException {
- if (buf == null) throw new IOException();
- if (pos < buf.length) {
- position++;
- return (buf[pos++] & 0xFF);
- }
- int c = in.read();
- if (c != -1) position++;
- return c;
- }
-
- /**
- * Don't imitate the JDK behaviour of reading a random number
- * of bytes when you can actually read them all.
- */
- public int read(byte b[], int off, int len) throws IOException {
- int read = 0, count;
- while (read != len && (count = readData(b, off, len - read)) != -1) {
- off += count;
- read += count;
- }
- position += read;
- if (read == 0 && read != len) return -1;
- return read;
- }
-
- /**
- * Reads at most <code>length</code> bytes from this LEDataInputStream and
- * stores them in byte array <code>buffer</code> starting at <code>offset</code>.
- * <p>
- * Answer the number of bytes actually read or -1 if no bytes were read and
- * end of stream was encountered. This implementation reads bytes from
- * the pushback buffer first, then the target stream if more bytes are required
- * to satisfy <code>count</code>.
- * </p>
- * @param buffer the byte array in which to store the read bytes.
- * @param offset the offset in <code>buffer</code> to store the read bytes.
- * @param length the maximum number of bytes to store in <code>buffer</code>.
- *
- * @return int the number of bytes actually read or -1 if end of stream.
- *
- * @exception java.io.IOException if an IOException occurs.
- */
- private int readData(byte[] buffer, int offset, int length) throws IOException {
- if (buf == null) throw new IOException();
- if (offset < 0 || offset > buffer.length ||
- length < 0 || (length > buffer.length - offset)) {
- throw new ArrayIndexOutOfBoundsException();
- }
-
- int cacheCopied = 0;
- int newOffset = offset;
-
- // Are there pushback bytes available?
- int available = buf.length - pos;
- if (available > 0) {
- cacheCopied = (available >= length) ? length : available;
- System.arraycopy(buf, pos, buffer, newOffset, cacheCopied);
- newOffset += cacheCopied;
- pos += cacheCopied;
- }
-
- // Have we copied enough?
- if (cacheCopied == length) return length;
-
- int inCopied = in.read(buffer, newOffset, length - cacheCopied);
-
- if (inCopied > 0) return inCopied + cacheCopied;
- if (cacheCopied == 0) return inCopied;
- return cacheCopied;
- }
-
- /**
- * Answer an integer comprised of the next
- * four bytes of the input stream.
- */
- public int readInt() throws IOException {
- byte[] buf = new byte[4];
- read(buf);
- return ((buf[3] & 0xFF) << 24) |
- ((buf[2] & 0xFF) << 16) |
- ((buf[1] & 0xFF) << 8) |
- (buf[0] & 0xFF);
- }
-
- /**
- * Answer a short comprised of the next
- * two bytes of the input stream.
- */
- public short readShort() throws IOException {
- byte[] buf = new byte[2];
- read(buf);
- return (short)(((buf[1] & 0xFF) << 8) | (buf[0] & 0xFF));
- }
-
- /**
- * Push back the entire content of the given buffer <code>b</code>.
- * <p>
- * The bytes are pushed so that they would be read back b[0], b[1], etc.
- * If the push back buffer cannot handle the bytes copied from <code>b</code>,
- * an IOException will be thrown and no byte will be pushed back.
- * </p>
- *
- * @param b the byte array containing bytes to push back into the stream
- *
- * @exception java.io.IOException if the pushback buffer is too small
- */
- public void unread(byte[] b) throws IOException {
- int length = b.length;
- if (length > pos) throw new IOException();
- position -= length;
- pos -= length;
- System.arraycopy(b, 0, buf, pos, length);
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LEDataOutputStream.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LEDataOutputStream.java
deleted file mode 100755
index bd8a330280..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LEDataOutputStream.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import java.io.*;
-
-final class LEDataOutputStream extends OutputStream {
- OutputStream out;
-public LEDataOutputStream(OutputStream output) {
- this.out = output;
-}
-/**
- * Write the specified number of bytes of the given byte array,
- * starting at the specified offset, to the output stream.
- */
-public void write(byte b[], int off, int len) throws IOException {
- out.write(b, off, len);
-}
-/**
- * Write the given byte to the output stream.
- */
-public void write(int b) throws IOException {
- out.write(b);
-}
-/**
- * Write the given byte to the output stream.
- */
-public void writeByte(byte b) throws IOException {
- out.write(b & 0xFF);
-}
-/**
- * Write the four bytes of the given integer
- * to the output stream.
- */
-public void writeInt(int theInt) throws IOException {
- out.write(theInt & 0xFF);
- out.write((theInt >> 8) & 0xFF);
- out.write((theInt >> 16) & 0xFF);
- out.write((theInt >> 24) & 0xFF);
-}
-/**
- * Write the two bytes of the given short
- * to the output stream.
- */
-public void writeShort(int theShort) throws IOException {
- out.write(theShort & 0xFF);
- out.write((theShort >> 8) & 0xFF);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LZWCodec.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LZWCodec.java
deleted file mode 100755
index 190ff01b7e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LZWCodec.java
+++ /dev/null
@@ -1,477 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-final class LZWCodec {
- int bitsPerPixel, blockSize, blockIndex, currentByte, bitsLeft,
- codeSize, clearCode, endCode, newCodes, topSlot, currentSlot,
- imageWidth, imageHeight, imageX, imageY, pass, line, codeMask;
- byte[] block, lineArray;
- int[] stack, suffix, prefix;
- LZWNode[] nodeStack;
- LEDataInputStream inputStream;
- LEDataOutputStream outputStream;
- ImageData image;
- ImageLoader loader;
- boolean interlaced;
- static final int[] MASK_TABLE = new int[] {
- 0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F,
- 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF
- };
-
-/**
- * Decode the input.
- */
-void decode() {
- int code;
- int oc = 0;
- int fc = 0;
- byte[] buf = new byte[imageWidth];
- int stackIndex = 0;
- int bufIndex = 0;
- int c;
- while ((c = nextCode()) != endCode) {
- if (c == clearCode) {
- codeSize = bitsPerPixel + 1;
- codeMask = MASK_TABLE[bitsPerPixel];
- currentSlot = newCodes;
- topSlot = 1 << codeSize;
- while ((c = nextCode()) == clearCode) {}
- if (c != endCode) {
- oc = fc = c;
- buf[bufIndex] = (byte)c;
- bufIndex++;
- if (bufIndex == imageWidth) {
- nextPutPixels(buf);
- bufIndex = 0;
- }
- }
- } else {
- code = c;
- if (code >= currentSlot) {
- code = oc;
- stack[stackIndex] = fc;
- stackIndex++;
- }
- while (code >= newCodes) {
- stack[stackIndex] = suffix[code];
- stackIndex++;
- code = prefix[code];
- }
- stack[stackIndex] = code;
- stackIndex++;
- if (currentSlot < topSlot) {
- fc = code;
- suffix[currentSlot] = fc;
- prefix[currentSlot] = oc;
- currentSlot++;
- oc = c;
- }
- if (currentSlot >= topSlot) {
- if (codeSize < 12) {
- codeMask = MASK_TABLE[codeSize];
- codeSize++;
- topSlot = topSlot + topSlot;
- }
- }
- while (stackIndex > 0) {
- stackIndex--;
- buf[bufIndex] = (byte)stack[stackIndex];
- bufIndex++;
- if (bufIndex == imageWidth) {
- nextPutPixels(buf);
- bufIndex = 0;
- }
- }
- }
- }
- if (bufIndex != 0 && line < imageHeight) {
- nextPutPixels(buf);
- }
-}
-/**
- * Decode the LZW-encoded bytes in the given byte stream
- * into the given DeviceIndependentImage.
- */
-public void decode(LEDataInputStream inputStream, ImageLoader loader, ImageData image, boolean interlaced, int depth) {
- this.inputStream = inputStream;
- this.loader = loader;
- this.image = image;
- this.interlaced = interlaced;
- this.bitsPerPixel = depth;
- initializeForDecoding();
- decode();
-}
-/**
- * Encode the image.
- */
-void encode() {
- nextPutCode(clearCode);
- int lastPrefix = encodeLoop();
- nextPutCode(lastPrefix);
- nextPutCode(endCode);
-
- // Write out last partial block
- if (bitsLeft == 8) {
- block[0] = (byte)(blockIndex - 1); // Nothing in last byte
- } else {
- block[0] = (byte)(blockIndex); // Last byte has data
- }
- writeBlock();
-
- // Write out empty block to indicate the end (if needed)
- if (block[0] != 0) {
- block[0] = 0;
- writeBlock();
- }
-}
-/**
- * Encode the bytes into the given byte stream
- * from the given DeviceIndependentImage.
- */
-public void encode(LEDataOutputStream byteStream, ImageData image) {
- this.outputStream = byteStream;
- this.image = image;
- initializeForEncoding();
- encode();
-}
-/**
- * Encoding loop broken out to allow early return.
- */
-int encodeLoop() {
- int pixel = nextPixel();
- boolean found;
- LZWNode node;
- while (true) {
- int currentPrefix = pixel;
- node = nodeStack[currentPrefix];
- found = true;
- pixel = nextPixel();
- if (pixel < 0)
- return currentPrefix;
- while (found && (node.children != null)) {
- node = node.children;
- while (found && (node.suffix != pixel)) {
- if (pixel < node.suffix) {
- if (node.left == null) {
- node.left = new LZWNode();
- found = false;
- }
- node = node.left;
- } else {
- if (node.right == null) {
- node.right = new LZWNode();
- found = false;
- }
- node = node.right;
- }
- }
- if (found) {
- currentPrefix = node.code;
- pixel = nextPixel();
- if (pixel < 0)
- return currentPrefix;
- }
- }
- if (found) {
- node.children = new LZWNode();
- node = node.children;
- }
- node.children = null;
- node.left = null;
- node.right = null;
- node.code = currentSlot;
- node.prefix = currentPrefix;
- node.suffix = pixel;
- nextPutCode(currentPrefix);
- currentSlot++;
- // Off by one?
- if (currentSlot < 4096) {
- if (currentSlot > topSlot) {
- codeSize++;
- codeMask = MASK_TABLE[codeSize - 1];
- topSlot *= 2;
- }
- } else {
- nextPutCode(clearCode);
- for (int i = 0; i < nodeStack.length; i++)
- nodeStack[i].children = null;
- codeSize = bitsPerPixel + 1;
- codeMask = MASK_TABLE[codeSize - 1];
- currentSlot = newCodes;
- topSlot = 1 << codeSize;
- }
- }
-}
-/**
- * Initialize the receiver for decoding the given
- * byte array.
- */
-void initializeForDecoding() {
- pass = 1;
- line = 0;
- codeSize = bitsPerPixel + 1;
- topSlot = 1 << codeSize;
- clearCode = 1 << bitsPerPixel;
- endCode = clearCode + 1;
- newCodes = currentSlot = endCode + 1;
- currentByte = -1;
- blockSize = bitsLeft = 0;
- blockIndex = 0;
- codeMask = MASK_TABLE[codeSize - 1];
- stack = new int[4096];
- suffix = new int[4096];
- prefix = new int[4096];
- block = new byte[256];
- imageWidth = image.width;
- imageHeight = image.height;
-}
-/**
- * Initialize the receiver for encoding the given
- * byte array.
- */
-void initializeForEncoding() {
- interlaced = false;
- bitsPerPixel = image.depth;
- codeSize = bitsPerPixel + 1;
- topSlot = 1 << codeSize;
- clearCode = 1 << bitsPerPixel;
- endCode = clearCode + 1;
- newCodes = currentSlot = endCode + 1;
- bitsLeft = 8;
- currentByte = 0;
- blockIndex = 1;
- blockSize = 255;
- block = new byte[blockSize];
- block[0] = (byte)(blockSize - 1);
- nodeStack = new LZWNode[1 << bitsPerPixel];
- for (int i = 0; i < nodeStack.length; i++) {
- LZWNode node = new LZWNode();
- node.code = i + 1;
- node.prefix = -1;
- node.suffix = i + 1;
- nodeStack[i] = node;
- }
- imageWidth = image.width;
- imageHeight = image.height;
- imageY = -1;
- lineArray = new byte[imageWidth];
- imageX = imageWidth + 1; // Force a read
-}
-/**
- * Answer the next code from the input byte array.
- */
-int nextCode() {
- int code;
- if (bitsLeft == 0) {
- if (blockIndex >= blockSize) {
- blockSize = readBlock();
- blockIndex = 0;
- if (blockSize == 0) return endCode;
- }
- blockIndex++;
- currentByte = block[blockIndex] & 0xFF;
- bitsLeft = 8;
- code = currentByte;
- } else {
- int shift = bitsLeft - 8;
- if (shift < 0)
- code = currentByte >> (0 - shift);
- else
- code = currentByte << shift;
- }
- while (codeSize > bitsLeft) {
- if (blockIndex >= blockSize) {
- blockSize = readBlock();
- blockIndex = 0;
- if (blockSize == 0) return endCode;
- }
- blockIndex++;
- currentByte = block[blockIndex] & 0xFF;
- code += currentByte << bitsLeft;
- bitsLeft += 8;
- }
- bitsLeft -= codeSize;
- return code & codeMask;
-}
-/**
- * Answer the next pixel to encode in the image
- */
-int nextPixel() {
- imageX++;
- if (imageX > imageWidth) {
- imageY++;
- if (imageY >= imageHeight) {
- return -1;
- } else {
- nextPixels(lineArray, imageWidth);
- }
- imageX = 1;
- }
- return this.lineArray[imageX - 1] & 0xFF;
-}
-/**
- * Copy a row of pixel values from the image.
- */
-void nextPixels(byte[] buf, int lineWidth) {
- if (image.depth == 8) {
- System.arraycopy(image.data, imageY * image.bytesPerLine, buf, 0, lineWidth);
- } else {
- image.getPixels(0, imageY, lineWidth, buf, 0);
- }
-}
-/**
- * Output aCode to the output stream.
- */
-void nextPutCode(int aCode) {
- int codeToDo = aCode;
- int codeBitsToDo = codeSize;
- // Fill in the remainder of the current byte with the
- // *high-order* bits of the code.
- int c = codeToDo & MASK_TABLE[bitsLeft - 1];
- currentByte = currentByte | (c << (8 - bitsLeft));
- block[blockIndex] = (byte)currentByte;
- codeBitsToDo -= bitsLeft;
- if (codeBitsToDo < 1) {
- // The whole code fit in the first byte, so we are done.
- bitsLeft -= codeSize;
- if (bitsLeft == 0) {
- // We used the whole last byte, so get ready
- // for the next one.
- bitsLeft = 8;
- blockIndex++;
- if (blockIndex >= blockSize) {
- writeBlock();
- blockIndex = 1;
- }
- currentByte = 0;
- }
- return;
- }
- codeToDo = codeToDo >> bitsLeft;
-
- // Fill in any remaining whole bytes (i.e. not the last one!)
- blockIndex++;
- if (blockIndex >= blockSize) {
- writeBlock();
- blockIndex = 1;
- }
- while (codeBitsToDo >= 8) {
- currentByte = codeToDo & 0xFF;
- block[blockIndex] = (byte)currentByte;
- codeToDo = codeToDo >> 8;
- codeBitsToDo -= 8;
- blockIndex++;
- if (blockIndex >= blockSize) {
- writeBlock();
- blockIndex = 1;
- }
- }
- // Fill the *low-order* bits of the last byte with the remainder
- bitsLeft = 8 - codeBitsToDo;
- currentByte = codeToDo;
- block[blockIndex] = (byte)currentByte;
-}
-/**
- * Copy a row of pixel values to the image.
- */
-void nextPutPixels(byte[] buf) {
- if (image.depth == 8) {
- // Slight optimization for depth = 8.
- int start = line * image.bytesPerLine;
- for (int i = 0; i < imageWidth; i++)
- image.data[start + i] = buf[i];
- } else {
- image.setPixels(0, line, imageWidth, buf, 0);
- }
- if (interlaced) {
- if (pass == 1) {
- copyRow(buf, 7);
- line += 8;
- } else if (pass == 2) {
- copyRow(buf, 3);
- line += 8;
- } else if (pass == 3) {
- copyRow(buf, 1);
- line += 4;
- } else if (pass == 4) {
- line += 2;
- } else if (pass == 5) {
- line += 0;
- }
- if (line >= imageHeight) {
- pass++;
- if (pass == 2) line = 4;
- else if (pass == 3) line = 2;
- else if (pass == 4) line = 1;
- else if (pass == 5) line = 0;
- if (pass < 5) {
- if (loader.hasListeners()) {
- ImageData imageCopy = (ImageData) image.clone();
- loader.notifyListeners(
- new ImageLoaderEvent(loader, imageCopy, pass - 2, false));
- }
- }
- }
- if (line >= imageHeight) line = 0;
- } else {
- line++;
- }
-}
-/**
- * Copy duplicate rows of pixel values to the image.
- * This is to fill in rows if the image is interlaced.
- */
-void copyRow(byte[] buf, int copies) {
- for (int i = 1; i <= copies; i++) {
- if (line + i < imageHeight) {
- image.setPixels(0, line + i, imageWidth, buf, 0);
- }
- }
-}
-/**
- * Read a block from the byte stream.
- * Return the number of bytes read.
- * Throw an exception if the block could not be read.
- */
-int readBlock() {
- int size = -1;
- try {
- size = inputStream.read();
- if (size == -1) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- block[0] = (byte)size;
- size = inputStream.read(block, 1, size);
- if (size == -1) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- } catch (Exception e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- return size;
-}
-/**
- * Write a block to the byte stream.
- * Throw an exception if the block could not be written.
- */
-void writeBlock() {
- try {
- outputStream.write(block, 0, (block[0] & 0xFF) + 1);
- } catch (Exception e) {
- SWT.error(SWT.ERROR_IO, e);
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LZWNode.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LZWNode.java
deleted file mode 100755
index 869e532ba3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LZWNode.java
+++ /dev/null
@@ -1,17 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-final class LZWNode {
- public LZWNode left, right, children;
- public int code, prefix, suffix;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/OS2BMPFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/OS2BMPFileFormat.java
deleted file mode 100644
index 4f4a2d34d5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/OS2BMPFileFormat.java
+++ /dev/null
@@ -1,294 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import java.io.*;
-
-public final class OS2BMPFileFormat extends FileFormat {
- static final int BMPFileHeaderSize = 14;
- static final int BMPHeaderFixedSize = 12;
- int width, height, bitCount;
-
-boolean isFileFormat(LEDataInputStream stream) {
- try {
- byte[] header = new byte[18];
- stream.read(header);
- stream.unread(header);
- int infoHeaderSize = (header[14] & 0xFF) | ((header[15] & 0xFF) << 8) | ((header[16] & 0xFF) << 16) | ((header[17] & 0xFF) << 24);
- return header[0] == 0x42 && header[1] == 0x4D && infoHeaderSize == BMPHeaderFixedSize;
- } catch (Exception e) {
- return false;
- }
-}
-byte[] loadData(byte[] infoHeader) {
- int stride = (width * bitCount + 7) / 8;
- stride = (stride + 3) / 4 * 4; // Round up to 4 byte multiple
- byte[] data = loadData(infoHeader, stride);
- flipScanLines(data, stride, height);
- return data;
-}
-byte[] loadData(byte[] infoHeader, int stride) {
- int dataSize = height * stride;
- byte[] data = new byte[dataSize];
- try {
- if (inputStream.read(data) != dataSize)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- return data;
-}
-int[] loadFileHeader() {
- int[] header = new int[5];
- try {
- header[0] = inputStream.readShort();
- header[1] = inputStream.readInt();
- header[2] = inputStream.readShort();
- header[3] = inputStream.readShort();
- header[4] = inputStream.readInt();
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- if (header[0] != 0x4D42)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return header;
-}
-ImageData[] loadFromByteStream() {
- int[] fileHeader = loadFileHeader();
- byte[] infoHeader = new byte[BMPHeaderFixedSize];
- try {
- inputStream.read(infoHeader);
- } catch (Exception e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- width = (infoHeader[4] & 0xFF) | ((infoHeader[5] & 0xFF) << 8);
- height = (infoHeader[6] & 0xFF) | ((infoHeader[7] & 0xFF) << 8);
- bitCount = (infoHeader[10] & 0xFF) | ((infoHeader[11] & 0xFF) << 8);
- PaletteData palette = loadPalette(infoHeader);
- if (inputStream.getPosition() < fileHeader[4]) {
- // Seek to the specified offset
- try {
- inputStream.skip(fileHeader[4] - inputStream.getPosition());
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
- byte[] data = loadData(infoHeader);
- int type = SWT.IMAGE_OS2_BMP;
- return new ImageData[] {
- ImageData.internal_new(
- width,
- height,
- bitCount,
- palette,
- 4,
- data,
- 0,
- null,
- null,
- -1,
- -1,
- type,
- 0,
- 0,
- 0,
- 0)
- };
-}
-PaletteData loadPalette(byte[] infoHeader) {
- if (bitCount <= 8) {
- int numColors = 1 << bitCount;
- byte[] buf = new byte[numColors * 3];
- try {
- if (inputStream.read(buf) != buf.length)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- return paletteFromBytes(buf, numColors);
- }
- if (bitCount == 16) return new PaletteData(0x7C00, 0x3E0, 0x1F);
- if (bitCount == 24) return new PaletteData(0xFF, 0xFF00, 0xFF0000);
- return new PaletteData(0xFF00, 0xFF0000, 0xFF000000);
-}
-PaletteData paletteFromBytes(byte[] bytes, int numColors) {
- int bytesOffset = 0;
- RGB[] colors = new RGB[numColors];
- for (int i = 0; i < numColors; i++) {
- colors[i] = new RGB(bytes[bytesOffset + 2] & 0xFF,
- bytes[bytesOffset + 1] & 0xFF,
- bytes[bytesOffset] & 0xFF);
- bytesOffset += 3;
- }
- return new PaletteData(colors);
-}
-/**
- * Answer a byte array containing the BMP representation of
- * the given device independent palette.
- */
-static byte[] paletteToBytes(PaletteData pal) {
- int n = pal.colors == null ? 0 : (pal.colors.length < 256 ? pal.colors.length : 256);
- byte[] bytes = new byte[n * 3];
- int offset = 0;
- for (int i = 0; i < n; i++) {
- RGB col = pal.colors[i];
- bytes[offset] = (byte)col.blue;
- bytes[offset + 1] = (byte)col.green;
- bytes[offset + 2] = (byte)col.red;
- offset += 3;
- }
- return bytes;
-}
-/**
- * Unload the given image's data into the given byte stream.
- * Answer the number of bytes written.
- */
-int unloadData(ImageData image, OutputStream out) {
- int bmpBpl = 0;
- try {
- int bpl = (image.width * image.depth + 7) / 8;
- bmpBpl = (bpl + 3) / 4 * 4; // BMP pads scanlines to multiples of 4 bytes
- int linesPerBuf = 32678 / bmpBpl;
- byte[] buf = new byte[linesPerBuf * bmpBpl];
- byte[] data = image.data;
- int imageBpl = image.bytesPerLine;
- int dataIndex = imageBpl * (image.height - 1); // Start at last line
- if (image.depth == 16) {
- for (int y = 0; y < image.height; y += linesPerBuf) {
- int count = image.height - y;
- if (linesPerBuf < count) count = linesPerBuf;
- int bufOffset = 0;
- for (int i = 0; i < count; i++) {
- for (int wIndex = 0; wIndex < bpl; wIndex += 2) {
- buf[bufOffset + wIndex + 1] = data[dataIndex + wIndex + 1];
- buf[bufOffset + wIndex] = data[dataIndex + wIndex];
- }
- bufOffset += bmpBpl;
- dataIndex -= imageBpl;
- }
- out.write(buf, 0, bufOffset);
- }
- } else {
- for (int y = 0; y < image.height; y += linesPerBuf) {
- int tmp = image.height - y;
- int count = tmp < linesPerBuf ? tmp : linesPerBuf;
- int bufOffset = 0;
- for (int i = 0; i < count; i++) {
- System.arraycopy(data, dataIndex, buf, bufOffset, bpl);
- bufOffset += bmpBpl;
- dataIndex -= imageBpl;
- }
- out.write(buf, 0, bufOffset);
- }
- }
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- return bmpBpl * image.height;
-}
-/**
- * Unload a DeviceIndependentImage using Windows .BMP format into the given
- * byte stream.
- */
-void unloadIntoByteStream(ImageLoader loader) {
- ImageData image = loader.data[0];
- byte[] rgbs;
- int numCols;
- if (!((image.depth == 1) || (image.depth == 4) || (image.depth == 8) ||
- (image.depth == 16) || (image.depth == 24) || (image.depth == 32)))
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- PaletteData pal = image.palette;
- if ((image.depth == 16) || (image.depth == 24) || (image.depth == 32)) {
- if (!pal.isDirect)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- numCols = 0;
- rgbs = null;
- } else {
- if (pal.isDirect)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- numCols = pal.colors.length;
- rgbs = paletteToBytes(pal);
- }
- // Fill in file header, except for bfsize, which is done later.
- int headersSize = BMPFileHeaderSize + BMPHeaderFixedSize;
- int[] fileHeader = new int[5];
- fileHeader[0] = 0x4D42; // Signature
- fileHeader[1] = 0; // File size - filled in later
- fileHeader[2] = 0; // Reserved 1
- fileHeader[3] = 0; // Reserved 2
- fileHeader[4] = headersSize; // Offset to data
- if (rgbs != null) {
- fileHeader[4] += rgbs.length;
- }
-
- // Prepare data. This is done first so we don't have to try to rewind
- // the stream and fill in the details later.
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- unloadData(image, out);
- byte[] data = out.toByteArray();
-
- // Calculate file size
- fileHeader[1] = fileHeader[4] + data.length;
-
- // Write the headers
- try {
- outputStream.writeShort(fileHeader[0]);
- outputStream.writeInt(fileHeader[1]);
- outputStream.writeShort(fileHeader[2]);
- outputStream.writeShort(fileHeader[3]);
- outputStream.writeInt(fileHeader[4]);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- try {
- outputStream.writeInt(BMPHeaderFixedSize);
- outputStream.writeShort(image.width);
- outputStream.writeShort(image.height);
- outputStream.writeShort(1);
- outputStream.writeShort((short)image.depth);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
-
- // Unload palette
- if (numCols > 0) {
- try {
- outputStream.write(rgbs);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
-
- // Unload the data
- try {
- outputStream.write(data);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
-}
-void flipScanLines(byte[] data, int stride, int height) {
- int i1 = 0;
- int i2 = (height - 1) * stride;
- for (int i = 0; i < height / 2; i++) {
- for (int index = 0; index < stride; index++) {
- byte b = data[index + i1];
- data[index + i1] = data[index + i2];
- data[index + i2] = b;
- }
- i1 += stride;
- i2 -= stride;
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PNGFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PNGFileFormat.java
deleted file mode 100755
index cf563d4e20..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PNGFileFormat.java
+++ /dev/null
@@ -1,574 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import java.io.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.*;
-
-public final class PNGFileFormat extends FileFormat {
- static final int SIGNATURE_LENGTH = 8;
- static final int PRIME = 65521;
- PngIhdrChunk headerChunk;
- PngPlteChunk paletteChunk;
- ImageData imageData;
- byte[] data;
- byte[] alphaPalette;
- byte headerByte1;
- byte headerByte2;
- int adler;
-
-/**
- * Skip over signature data. This has already been
- * verified in isFileFormat().
- */
-void readSignature() throws IOException {
- byte[] signature = new byte[SIGNATURE_LENGTH];
- inputStream.read(signature);
-}
-/**
- * Load the PNG image from the byte stream.
- */
-ImageData[] loadFromByteStream() {
- try {
- readSignature();
- PngChunkReader chunkReader = new PngChunkReader(inputStream);
- headerChunk = chunkReader.getIhdrChunk();
- int width = headerChunk.getWidth(), height = headerChunk.getHeight();
- if (width <= 0 || height <= 0) SWT.error(SWT.ERROR_INVALID_IMAGE);
- int imageSize = getAlignedBytesPerRow() * height;
- data = new byte[imageSize];
- imageData = ImageData.internal_new(
- width,
- height,
- headerChunk.getSwtBitsPerPixel(),
- new PaletteData(0, 0, 0),
- 4,
- data,
- 0,
- null,
- null,
- -1,
- -1,
- SWT.IMAGE_PNG,
- 0,
- 0,
- 0,
- 0);
-
- if (headerChunk.usesDirectColor()) {
- imageData.palette = headerChunk.getPaletteData();
- }
-
- // Read and process chunks until the IEND chunk is encountered.
- while (chunkReader.hasMoreChunks()) {
- readNextChunk(chunkReader);
- }
-
- return new ImageData[] {imageData};
- } catch (IOException e) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return null;
- }
-}
-/**
- * Read and handle the next chunk of data from the
- * PNG file.
- */
-void readNextChunk(PngChunkReader chunkReader) throws IOException {
- PngChunk chunk = chunkReader.readNextChunk();
- switch (chunk.getChunkType()) {
- case PngChunk.CHUNK_IEND:
- break;
- case PngChunk.CHUNK_PLTE:
- if (!headerChunk.usesDirectColor()) {
- paletteChunk = (PngPlteChunk) chunk;
- imageData.palette = paletteChunk.getPaletteData();
- }
- break;
- case PngChunk.CHUNK_tRNS:
- PngTrnsChunk trnsChunk = (PngTrnsChunk) chunk;
- if (trnsChunk.getTransparencyType(headerChunk) ==
- PngTrnsChunk.TRANSPARENCY_TYPE_PIXEL)
- {
- imageData.transparentPixel =
- trnsChunk.getSwtTransparentPixel(headerChunk);
- } else {
- alphaPalette = trnsChunk.getAlphaValues(headerChunk, paletteChunk);
- int transparentCount = 0, transparentPixel = -1;
- for (int i = 0; i < alphaPalette.length; i++) {
- if ((alphaPalette[i] & 0xFF) != 255) {
- transparentCount++;
- transparentPixel = i;
- }
- }
- if (transparentCount == 0) {
- alphaPalette = null;
- } else if (transparentCount == 1 && alphaPalette[transparentPixel] == 0) {
- alphaPalette = null;
- imageData.transparentPixel = transparentPixel;
- }
- }
- break;
- case PngChunk.CHUNK_IDAT:
- if (chunkReader.readPixelData()) {
- // All IDAT chunks in an image file must be
- // sequential. If the pixel data has already
- // been read and another IDAT block is encountered,
- // then this is an invalid image.
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- } else {
- // Read in the pixel data for the image. This should
- // go through all the image's IDAT chunks.
- PngIdatChunk dataChunk = (PngIdatChunk) chunk;
- readPixelData(dataChunk, chunkReader);
- }
- break;
- default:
- if (chunk.isCritical()) {
- // All critical chunks must be supported.
- SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- }
- }
-}
-void unloadIntoByteStream(ImageLoader loader) {
- PngEncoder encoder = new PngEncoder(loader);
- encoder.encode(outputStream);
-}
-boolean isFileFormat(LEDataInputStream stream) {
- try {
- byte[] signature = new byte[SIGNATURE_LENGTH];
- stream.read(signature);
- stream.unread(signature);
- if ((signature[0] & 0xFF) != 137) return false; //137
- if ((signature[1] & 0xFF) != 80) return false; //P
- if ((signature[2] & 0xFF) != 78) return false; //N
- if ((signature[3] & 0xFF) != 71) return false; //G
- if ((signature[4] & 0xFF) != 13) return false; //<RETURN>
- if ((signature[5] & 0xFF) != 10) return false; //<LINEFEED>
- if ((signature[6] & 0xFF) != 26) return false; //<CTRL/Z>
- if ((signature[7] & 0xFF) != 10) return false; //<LINEFEED>
- return true;
- } catch (Exception e) {
- return false;
- }
-}
-/**
- * SWT does not support 16-bit depths. If this image uses
- * 16-bit depths, convert the data to an 8-bit depth.
- */
-byte[] validateBitDepth(byte[] data) {
- if (headerChunk.getBitDepth() > 8) {
- byte[] result = new byte[data.length / 2];
- compress16BitDepthTo8BitDepth(data, 0, result, 0, result.length);
- return result;
- } else {
- return data;
- }
-}
-/**
- * SWT does not support greyscale as a color type. For
- * plain grayscale, we create a palette. For Grayscale
- * with Alpha, however, we need to convert the pixels
- * to use RGB values.
- * Note: This method assumes that the bit depth of the
- * data has already been restricted to 8 or less.
- */
-void setPixelData(byte[] data, ImageData imageData) {
- switch (headerChunk.getColorType()) {
- case PngIhdrChunk.COLOR_TYPE_GRAYSCALE_WITH_ALPHA:
- {
- int width = imageData.width;
- int height = imageData.height;
- int destBytesPerLine = imageData.bytesPerLine;
- /*
- * If the image uses 16-bit depth, it is converted
- * to an 8-bit depth image.
- */
- int srcBytesPerLine = getAlignedBytesPerRow();
- if (headerChunk.getBitDepth() > 8) srcBytesPerLine /= 2;
-
- byte[] rgbData = new byte[destBytesPerLine * height];
- byte[] alphaData = new byte[width * height];
- for (int y = 0; y < height; y++) {
- int srcIndex = srcBytesPerLine * y;
- int destIndex = destBytesPerLine * y;
- int destAlphaIndex = width * y;
- for (int x = 0; x < width; x++) {
- byte grey = data[srcIndex];
- byte alpha = data[srcIndex + 1];
- rgbData[destIndex + 0] = grey;
- rgbData[destIndex + 1] = grey;
- rgbData[destIndex + 2] = grey;
- alphaData[destAlphaIndex] = alpha;
- srcIndex += 2;
- destIndex += 3;
- destAlphaIndex++;
- }
- }
- imageData.data = rgbData;
- imageData.alphaData = alphaData;
- break;
- }
- case PngIhdrChunk.COLOR_TYPE_RGB_WITH_ALPHA:
- {
- int width = imageData.width;
- int height = imageData.height;
- int destBytesPerLine = imageData.bytesPerLine;
- int srcBytesPerLine = getAlignedBytesPerRow();
- /*
- * If the image uses 16-bit depth, it is converted
- * to an 8-bit depth image.
- */
- if (headerChunk.getBitDepth() > 8) srcBytesPerLine /= 2;
-
- byte[] rgbData = new byte[destBytesPerLine * height];
- byte[] alphaData = new byte[width * height];
- for (int y = 0; y < height; y++) {
- int srcIndex = srcBytesPerLine * y;
- int destIndex = destBytesPerLine * y;
- int destAlphaIndex = width * y;
- for (int x = 0; x < width; x++) {
- rgbData[destIndex + 0] = data[srcIndex + 0];
- rgbData[destIndex + 1] = data[srcIndex + 1];
- rgbData[destIndex + 2] = data[srcIndex + 2];
- alphaData[destAlphaIndex] = data[srcIndex + 3];
- srcIndex += 4;
- destIndex += 3;
- destAlphaIndex++;
- }
- }
- imageData.data = rgbData;
- imageData.alphaData = alphaData;
- break;
- }
- case PngIhdrChunk.COLOR_TYPE_RGB:
- imageData.data = data;
- break;
- case PngIhdrChunk.COLOR_TYPE_PALETTE:
- imageData.data = data;
- if (alphaPalette != null) {
- int size = imageData.width * imageData.height;
- byte[] alphaData = new byte[size];
- byte[] pixelData = new byte[size];
- imageData.getPixels(0, 0, size, pixelData, 0);
- for (int i = 0; i < pixelData.length; i++) {
- alphaData[i] = alphaPalette[pixelData[i] & 0xFF];
- }
- imageData.alphaData = alphaData;
- }
- break;
- default:
- imageData.data = data;
- break;
- }
-}
-/**
- * PNG supports some color types and bit depths that are
- * unsupported by SWT. If the image uses an unsupported
- * color type (either of the gray scale types) or bit
- * depth (16), convert the data to an SWT-supported
- * format. Then assign the data into the ImageData given.
- */
-void setImageDataValues(byte[] data, ImageData imageData) {
- byte[] result = validateBitDepth(data);
- setPixelData(result, imageData);
-}
-/**
- * Read the image data from the data stream. This must handle
- * decoding the data, filtering, and interlacing.
- */
-void readPixelData(PngIdatChunk chunk, PngChunkReader chunkReader) throws IOException {
- InputStream stream = new PngInputStream(chunk, chunkReader);
- //TEMPORARY CODE
- boolean use3_2 = System.getProperty("org.eclipse.swt.internal.image.PNGFileFormat_3.2") != null;
- InputStream inflaterStream = use3_2 ? null : Compatibility.newInflaterInputStream(stream);
- if (inflaterStream != null) {
- stream = inflaterStream;
- } else {
- stream = new PngDecodingDataStream(stream);
- }
- int interlaceMethod = headerChunk.getInterlaceMethod();
- if (interlaceMethod == PngIhdrChunk.INTERLACE_METHOD_NONE) {
- readNonInterlacedImage(stream);
- } else {
- readInterlacedImage(stream);
- }
- /*
- * InflaterInputStream does not consume all bytes in the stream
- * when it is closed. This may leave unread IDAT chunks. The fix
- * is to read all available bytes before closing it.
- */
- while (stream.available() > 0) stream.read();
- stream.close();
-}
-/**
- * Answer the number of bytes in a word-aligned row of pixel data.
- */
-int getAlignedBytesPerRow() {
- return ((getBytesPerRow(headerChunk.getWidth()) + 3) / 4) * 4;
-}
-/**
- * Answer the number of bytes in each row of the image
- * data. Each PNG row is byte-aligned, so images with bit
- * depths less than a byte may have unused bits at the
- * end of each row. The value of these bits is undefined.
- */
-int getBytesPerRow() {
- return getBytesPerRow(headerChunk.getWidth());
-}
-/**
- * Answer the number of bytes needed to represent a pixel.
- * This value depends on the image's color type and bit
- * depth.
- * Note that this method rounds up if an image's pixel size
- * isn't byte-aligned.
- */
-int getBytesPerPixel() {
- int bitsPerPixel = headerChunk.getBitsPerPixel();
- return (bitsPerPixel + 7) / 8;
-}
-/**
- * Answer the number of bytes in a row of the given pixel
- * width. Each row is byte-aligned, so images with bit
- * depths less than a byte may have unused bits at the
- * end of each row. The value of these bits is undefined.
- */
-int getBytesPerRow(int rowWidthInPixels) {
- int bitsPerPixel = headerChunk.getBitsPerPixel();
- int bitsPerRow = bitsPerPixel * rowWidthInPixels;
- int bitsPerByte = 8;
- return (bitsPerRow + (bitsPerByte - 1)) / bitsPerByte;
-}
-/**
- * 1. Read one of the seven frames of interlaced data.
- * 2. Update the imageData.
- * 3. Notify the image loader's listeners of the frame load.
- */
-void readInterlaceFrame(
- InputStream inputStream,
- int rowInterval,
- int columnInterval,
- int startRow,
- int startColumn,
- int frameCount) throws IOException
-{
- int width = headerChunk.getWidth();
- int alignedBytesPerRow = getAlignedBytesPerRow();
- int height = headerChunk.getHeight();
- if (startRow >= height || startColumn >= width) return;
-
- int pixelsPerRow = (width - startColumn + columnInterval - 1) / columnInterval;
- int bytesPerRow = getBytesPerRow(pixelsPerRow);
- byte[] row1 = new byte[bytesPerRow];
- byte[] row2 = new byte[bytesPerRow];
- byte[] currentRow = row1;
- byte[] lastRow = row2;
- for (int row = startRow; row < height; row += rowInterval) {
- byte filterType = (byte)inputStream.read();
- int read = 0;
- while (read != bytesPerRow) {
- read += inputStream.read(currentRow, read, bytesPerRow - read);
- }
- filterRow(currentRow, lastRow, filterType);
- if (headerChunk.getBitDepth() >= 8) {
- int bytesPerPixel = getBytesPerPixel();
- int dataOffset = (row * alignedBytesPerRow) + (startColumn * bytesPerPixel);
- for (int rowOffset = 0; rowOffset < currentRow.length; rowOffset += bytesPerPixel) {
- for (int byteOffset = 0; byteOffset < bytesPerPixel; byteOffset++) {
- data[dataOffset + byteOffset] = currentRow[rowOffset + byteOffset];
- }
- dataOffset += (columnInterval * bytesPerPixel);
- }
- } else {
- int bitsPerPixel = headerChunk.getBitDepth();
- int pixelsPerByte = 8 / bitsPerPixel;
- int column = startColumn;
- int rowBase = row * alignedBytesPerRow;
- int valueMask = 0;
- for (int i = 0; i < bitsPerPixel; i++) {
- valueMask <<= 1;
- valueMask |= 1;
- }
- int maxShift = 8 - bitsPerPixel;
- for (int byteOffset = 0; byteOffset < currentRow.length; byteOffset++) {
- for (int bitOffset = maxShift; bitOffset >= 0; bitOffset -= bitsPerPixel) {
- if (column < width) {
- int dataOffset = rowBase + (column * bitsPerPixel / 8);
- int value = (currentRow[byteOffset] >> bitOffset) & valueMask;
- int dataShift = maxShift - (bitsPerPixel * (column % pixelsPerByte));
- data[dataOffset] |= value << dataShift;
- }
- column += columnInterval;
- }
- }
- }
- currentRow = (currentRow == row1) ? row2 : row1;
- lastRow = (lastRow == row1) ? row2 : row1;
- }
- setImageDataValues(data, imageData);
- fireInterlacedFrameEvent(frameCount);
-}
-/**
- * Read the pixel data for an interlaced image from the
- * data stream.
- */
-void readInterlacedImage(InputStream inputStream) throws IOException {
- readInterlaceFrame(inputStream, 8, 8, 0, 0, 0);
- readInterlaceFrame(inputStream, 8, 8, 0, 4, 1);
- readInterlaceFrame(inputStream, 8, 4, 4, 0, 2);
- readInterlaceFrame(inputStream, 4, 4, 0, 2, 3);
- readInterlaceFrame(inputStream, 4, 2, 2, 0, 4);
- readInterlaceFrame(inputStream, 2, 2, 0, 1, 5);
- readInterlaceFrame(inputStream, 2, 1, 1, 0, 6);
-}
-/**
- * Fire an event to let listeners know that an interlaced
- * frame has been loaded.
- * finalFrame should be true if the image has finished
- * loading, false if there are more frames to come.
- */
-void fireInterlacedFrameEvent(int frameCount) {
- if (loader.hasListeners()) {
- ImageData image = (ImageData) imageData.clone();
- boolean finalFrame = frameCount == 6;
- loader.notifyListeners(new ImageLoaderEvent(loader, image, frameCount, finalFrame));
- }
-}
-/**
- * Read the pixel data for a non-interlaced image from the
- * data stream.
- * Update the imageData to reflect the new data.
- */
-void readNonInterlacedImage(InputStream inputStream) throws IOException {
- int dataOffset = 0;
- int alignedBytesPerRow = getAlignedBytesPerRow();
- int bytesPerRow = getBytesPerRow();
- byte[] row1 = new byte[bytesPerRow];
- byte[] row2 = new byte[bytesPerRow];
- byte[] currentRow = row1;
- byte[] lastRow = row2;
- int height = headerChunk.getHeight();
- for (int row = 0; row < height; row++) {
- byte filterType = (byte)inputStream.read();
- int read = 0;
- while (read != bytesPerRow) {
- read += inputStream.read(currentRow, read, bytesPerRow - read);
- }
- filterRow(currentRow, lastRow, filterType);
- System.arraycopy(currentRow, 0, data, dataOffset, bytesPerRow);
- dataOffset += alignedBytesPerRow;
- currentRow = (currentRow == row1) ? row2 : row1;
- lastRow = (lastRow == row1) ? row2 : row1;
- }
- setImageDataValues(data, imageData);
-}
-/**
- * SWT does not support 16-bit depth color formats.
- * Convert the 16-bit data to 8-bit data.
- * The correct way to do this is to multiply each
- * 16 bit value by the value:
- * (2^8 - 1) / (2^16 - 1).
- * The fast way to do this is just to drop the low
- * byte of the 16-bit value.
- */
-static void compress16BitDepthTo8BitDepth(
- byte[] source,
- int sourceOffset,
- byte[] destination,
- int destinationOffset,
- int numberOfValues)
-{
- //double multiplier = (Compatibility.pow2(8) - 1) / (Compatibility.pow2(16) - 1);
- for (int i = 0; i < numberOfValues; i++) {
- int sourceIndex = sourceOffset + (2 * i);
- int destinationIndex = destinationOffset + i;
- //int value = (source[sourceIndex] << 8) | source[sourceIndex + 1];
- //byte compressedValue = (byte)(value * multiplier);
- byte compressedValue = source[sourceIndex];
- destination[destinationIndex] = compressedValue;
- }
-}
-/**
- * SWT does not support 16-bit depth color formats.
- * Convert the 16-bit data to 8-bit data.
- * The correct way to do this is to multiply each
- * 16 bit value by the value:
- * (2^8 - 1) / (2^16 - 1).
- * The fast way to do this is just to drop the low
- * byte of the 16-bit value.
- */
-static int compress16BitDepthTo8BitDepth(int value) {
- //double multiplier = (Compatibility.pow2(8) - 1) / (Compatibility.pow2(16) - 1);
- //byte compressedValue = (byte)(value * multiplier);
- return value >> 8;
-}
-/**
- * PNG supports four filtering types. These types are applied
- * per row of image data. This method unfilters the given row
- * based on the filterType.
- */
-void filterRow(byte[] row, byte[] previousRow, int filterType) {
- int byteOffset = headerChunk.getFilterByteOffset();
- switch (filterType) {
- case PngIhdrChunk.FILTER_NONE:
- break;
- case PngIhdrChunk.FILTER_SUB:
- for (int i = byteOffset; i < row.length; i++) {
- int current = row[i] & 0xFF;
- int left = row[i - byteOffset] & 0xFF;
- row[i] = (byte)((current + left) & 0xFF);
- }
- break;
- case PngIhdrChunk.FILTER_UP:
- for (int i = 0; i < row.length; i++) {
- int current = row[i] & 0xFF;
- int above = previousRow[i] & 0xFF;
- row[i] = (byte)((current + above) & 0xFF);
- }
- break;
- case PngIhdrChunk.FILTER_AVERAGE:
- for (int i = 0; i < row.length; i++) {
- int left = (i < byteOffset) ? 0 : row[i - byteOffset] & 0xFF;
- int above = previousRow[i] & 0xFF;
- int current = row[i] & 0xFF;
- row[i] = (byte)((current + ((left + above) / 2)) & 0xFF);
- }
- break;
- case PngIhdrChunk.FILTER_PAETH:
- for (int i = 0; i < row.length; i++) {
- int left = (i < byteOffset) ? 0 : row[i - byteOffset] & 0xFF;
- int aboveLeft = (i < byteOffset) ? 0 : previousRow[i - byteOffset] & 0xFF;
- int above = previousRow[i] & 0xFF;
-
- int a = Math.abs(above - aboveLeft);
- int b = Math.abs(left - aboveLeft);
- int c = Math.abs(left - aboveLeft + above - aboveLeft);
-
- int preductor = 0;
- if (a <= b && a <= c) {
- preductor = left;
- } else if (b <= c) {
- preductor = above;
- } else {
- preductor = aboveLeft;
- }
-
- int currentValue = row[i] & 0xFF;
- row[i] = (byte) ((currentValue + preductor) & 0xFF);
- }
- break;
- }
-}
-
-} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunk.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunk.java
deleted file mode 100755
index 74b438ea46..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunk.java
+++ /dev/null
@@ -1,381 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-import java.io.*;
-
-class PngChunk extends Object {
- byte[] reference;
-
- static final int LENGTH_OFFSET = 0;
- static final int TYPE_OFFSET = 4;
- static final int DATA_OFFSET = 8;
-
- static final int TYPE_FIELD_LENGTH = 4;
- static final int LENGTH_FIELD_LENGTH = 4;
- static final int MIN_LENGTH = 12;
-
- static final int CHUNK_UNKNOWN = -1;
- // Critical chunks.
- static final int CHUNK_IHDR = 0;
- static final int CHUNK_PLTE = 1;
- static final int CHUNK_IDAT = 2;
- static final int CHUNK_IEND = 3;
- // Non-critical chunks.
- static final int CHUNK_tRNS = 5;
-
- static final byte[] TYPE_IHDR = {(byte) 'I', (byte) 'H', (byte) 'D', (byte) 'R'};
- static final byte[] TYPE_PLTE = {(byte) 'P', (byte) 'L', (byte) 'T', (byte) 'E'};
- static final byte[] TYPE_IDAT = {(byte) 'I', (byte) 'D', (byte) 'A', (byte) 'T'};
- static final byte[] TYPE_IEND = {(byte) 'I', (byte) 'E', (byte) 'N', (byte) 'D'};
- static final byte[] TYPE_tRNS = {(byte) 't', (byte) 'R', (byte) 'N', (byte) 'S'};
-
- static final int[] CRC_TABLE;
- static {
- CRC_TABLE = new int[256];
- for (int i = 0; i < 256; i++) {
- CRC_TABLE[i] = i;
- for (int j = 0; j < 8; j++) {
- if ((CRC_TABLE[i] & 0x1) == 0) {
- CRC_TABLE[i] = (CRC_TABLE[i] >> 1) & 0x7FFFFFFF;
- } else {
- CRC_TABLE[i] = 0xEDB88320 ^ ((CRC_TABLE[i] >> 1) & 0x7FFFFFFF);
- }
- }
- }
- }
-
- int length;
-
-/**
- * Construct a PngChunk using the reference bytes
- * given.
- */
-PngChunk(byte[] reference) {
- super();
- setReference(reference);
- if (reference.length < LENGTH_OFFSET + LENGTH_FIELD_LENGTH) SWT.error(SWT.ERROR_INVALID_IMAGE);
- length = getInt32(LENGTH_OFFSET);
-}
-
-/**
- * Construct a PngChunk with the specified number of
- * data bytes.
- */
-PngChunk(int dataLength) {
- this(new byte[MIN_LENGTH + dataLength]);
- setLength(dataLength);
-}
-
-/**
- * Get the PngChunk's reference byteArray;
- */
-byte[] getReference() {
- return reference;
-}
-
-/**
- * Set the PngChunk's reference byteArray;
- */
-void setReference(byte[] reference) {
- this.reference = reference;
-}
-
-/**
- * Get the 16-bit integer from the reference byte
- * array at the given offset.
- */
-int getInt16(int offset) {
- int answer = 0;
- answer |= (reference[offset] & 0xFF) << 8;
- answer |= (reference[offset + 1] & 0xFF);
- return answer;
-}
-
-/**
- * Set the 16-bit integer in the reference byte
- * array at the given offset.
- */
-void setInt16(int offset, int value) {
- reference[offset] = (byte) ((value >> 8) & 0xFF);
- reference[offset + 1] = (byte) (value & 0xFF);
-}
-
-/**
- * Get the 32-bit integer from the reference byte
- * array at the given offset.
- */
-int getInt32(int offset) {
- int answer = 0;
- answer |= (reference[offset] & 0xFF) << 24;
- answer |= (reference[offset + 1] & 0xFF) << 16;
- answer |= (reference[offset + 2] & 0xFF) << 8;
- answer |= (reference[offset + 3] & 0xFF);
- return answer;
-}
-
-/**
- * Set the 32-bit integer in the reference byte
- * array at the given offset.
- */
-void setInt32(int offset, int value) {
- reference[offset] = (byte) ((value >> 24) & 0xFF);
- reference[offset + 1] = (byte) ((value >> 16) & 0xFF);
- reference[offset + 2] = (byte) ((value >> 8) & 0xFF);
- reference[offset + 3] = (byte) (value & 0xFF);
-}
-
-/**
- * Get the length of the data component of this chunk.
- * This is not the length of the entire chunk.
- */
-int getLength() {
- return length;
-}
-
-/**
- * Set the length of the data component of this chunk.
- * This is not the length of the entire chunk.
- */
-void setLength(int value) {
- setInt32(LENGTH_OFFSET, value);
- length = value;
-}
-
-/**
- * Get the chunk type. This is a four byte value.
- * Each byte should be an ASCII character.
- * The first byte is upper case if the chunk is critical.
- * The second byte is upper case if the chunk is publicly defined.
- * The third byte must be upper case.
- * The fourth byte is upper case if the chunk is unsafe to copy.
- * Public chunk types are defined by the PNG Development Group.
- */
-byte[] getTypeBytes() {
- byte[] type = new byte[4];
- System.arraycopy(reference, TYPE_OFFSET, type, 0, TYPE_FIELD_LENGTH);
- return type;
-}
-
-/**
- * Set the chunk type. This is a four byte value.
- * Each byte should be an ASCII character.
- * The first byte is upper case if the chunk is critical.
- * The second byte is upper case if the chunk is publicly defined.
- * The third byte must be upper case.
- * The fourth byte is upper case if the chunk is unsafe to copy.
- * Public chunk types are defined by the PNG Development Group.
- */
-void setType(byte[] value) {
- if (value.length != TYPE_FIELD_LENGTH) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- System.arraycopy(value, 0, reference, TYPE_OFFSET, TYPE_FIELD_LENGTH);
-}
-
-/**
- * Get the chunk's data.
- */
-byte[] getData() {
- int dataLength = getLength();
- if (reference.length < MIN_LENGTH + dataLength) {
- SWT.error (SWT.ERROR_INVALID_RANGE);
- }
- byte[] data = new byte[dataLength];
- System.arraycopy(reference, DATA_OFFSET, data, 0, dataLength);
- return data;
-}
-
-/**
- * Set the chunk's data.
- * This method has two side-effects.
- * 1. It will set the length field to be the length
- * of the data array given.
- * 2. It will set the CRC field to the computed CRC
- * value of the data array given.
- */
-void setData(byte[] data) {
- setLength(data.length);
- System.arraycopy(data, 0, reference, DATA_OFFSET, data.length);
- setCRC(computeCRC());
-}
-
-/**
- * Get the CRC value for the chunk's data.
- * Ensure that the length field has a good
- * value before making this call.
- */
-int getCRC() {
- int crcOffset = DATA_OFFSET + getLength();
- return getInt32(crcOffset);
-}
-
-/**
- * Set the CRC value for the chunk's data.
- * Ensure that the length field has a good
- * value before making this call.
- */
-void setCRC(int value) {
- int crcOffset = DATA_OFFSET + getLength();
- setInt32(crcOffset, value);
-}
-
-/**
- * Get the chunk's total size including the length, type, and crc fields.
- */
-int getSize() {
- return MIN_LENGTH + getLength();
-}
-
-/**
- * Compute the CRC value for the chunk's data. Answer
- * whether this value matches the value stored in the
- * chunk.
- */
-boolean checkCRC() {
- int crc = computeCRC();
- int storedCRC = getCRC();
- return crc == storedCRC;
-}
-
-/**
- * Answer the CRC value of chunk's data.
- */
-int computeCRC() {
- int crc = 0xFFFFFFFF;
- int start = TYPE_OFFSET;
- int stop = DATA_OFFSET + getLength();
- for (int i = start; i < stop; i++) {
- int index = (crc ^ reference[i]) & 0xFF;
- crc = CRC_TABLE[index] ^ ((crc >> 8) & 0x00FFFFFF);
- }
- return ~crc;
-}
-
-boolean typeMatchesArray(byte[] array) {
- for (int i = 0; i < TYPE_FIELD_LENGTH; i++) {
- if (reference[TYPE_OFFSET + i] != array[i]){
- return false;
- }
- }
- return true;
-}
-
-boolean isCritical() {
- char c = (char) getTypeBytes()[0];
- return 'A' <= c && c <= 'Z';
-}
-
-int getChunkType() {
- if (typeMatchesArray(TYPE_IHDR)) return CHUNK_IHDR;
- if (typeMatchesArray(TYPE_PLTE)) return CHUNK_PLTE;
- if (typeMatchesArray(TYPE_IDAT)) return CHUNK_IDAT;
- if (typeMatchesArray(TYPE_IEND)) return CHUNK_IEND;
- if (typeMatchesArray(TYPE_tRNS)) return CHUNK_tRNS;
- return CHUNK_UNKNOWN;
-}
-
-/**
- * Read the next PNG chunk from the input stream given.
- * If unable to read a chunk, return null.
- */
-static PngChunk readNextFromStream(LEDataInputStream stream) {
- try {
- int headerLength = LENGTH_FIELD_LENGTH + TYPE_FIELD_LENGTH;
- byte[] headerBytes = new byte[headerLength];
- int result = stream.read(headerBytes, 0, headerLength);
- stream.unread(headerBytes);
- if (result != headerLength) return null;
-
- PngChunk tempChunk = new PngChunk(headerBytes);
-
- int chunkLength = tempChunk.getSize();
- byte[] chunk = new byte[chunkLength];
- result = stream.read(chunk, 0, chunkLength);
- if (result != chunkLength) return null;
-
- switch (tempChunk.getChunkType()) {
- case CHUNK_IHDR:
- return new PngIhdrChunk(chunk);
- case CHUNK_PLTE:
- return new PngPlteChunk(chunk);
- case CHUNK_IDAT:
- return new PngIdatChunk(chunk);
- case CHUNK_IEND:
- return new PngIendChunk(chunk);
- case CHUNK_tRNS:
- return new PngTrnsChunk(chunk);
- default:
- return new PngChunk(chunk);
- }
- } catch (IOException e) {
- return null;
- }
-}
-
-/**
- * Answer whether the chunk is a valid PNG chunk.
- */
-void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
- if (reference.length < MIN_LENGTH) SWT.error(SWT.ERROR_INVALID_IMAGE);
-
- byte[] type = getTypeBytes();
-
- // The third character MUST be upper case.
- char c = (char) type[2];
- if (!('A' <= c && c <= 'Z')) SWT.error(SWT.ERROR_INVALID_IMAGE);
-
- // All characters must be letters.
- for (int i = 0; i < TYPE_FIELD_LENGTH; i++) {
- c = (char) type[i];
- if (!(('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- }
-
- // The stored CRC must match the data's computed CRC.
- if (!checkCRC()) SWT.error(SWT.ERROR_INVALID_IMAGE);
-}
-
-/**
- * Provided so that subclasses can override and add
- * data to the toString() call.
- */
-void contributeToString(StringBuffer buffer) {}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the event
- */
-public String toString() {
- StringBuffer buffer = new StringBuffer();
- buffer.append("{");
- buffer.append("\n\tLength: ");
- buffer.append(getLength());
- buffer.append("\n\tType: ");
- byte[] type = getTypeBytes();
- for(int i = 0; i < type.length; i++) {
- buffer.append((char) type[i]);
- }
-
- contributeToString(buffer);
-
- buffer.append("\n\tCRC: ");
- buffer.append(Integer.toHexString(getCRC()));
- buffer.append("\n}");
- return buffer.toString();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunkReader.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunkReader.java
deleted file mode 100755
index 0997c46b97..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunkReader.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-
-public class PngChunkReader {
- LEDataInputStream inputStream;
- PngFileReadState readState;
- PngIhdrChunk headerChunk;
- PngPlteChunk paletteChunk;
-
-PngChunkReader(LEDataInputStream inputStream) {
- this.inputStream = inputStream;
- readState = new PngFileReadState();
- headerChunk = null;
-}
-
-PngIhdrChunk getIhdrChunk() {
- if (headerChunk == null) {
- try {
- PngChunk chunk = PngChunk.readNextFromStream(inputStream);
- if (chunk == null) SWT.error(SWT.ERROR_INVALID_IMAGE);
- headerChunk = (PngIhdrChunk) chunk;
- headerChunk.validate(readState, null);
- } catch (ClassCastException e) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- }
- return headerChunk;
-}
-
-PngChunk readNextChunk() {
- if (headerChunk == null) return getIhdrChunk();
-
- PngChunk chunk = PngChunk.readNextFromStream(inputStream);
- if (chunk == null) SWT.error(SWT.ERROR_INVALID_IMAGE);
- switch (chunk.getChunkType()) {
- case PngChunk.CHUNK_tRNS:
- ((PngTrnsChunk) chunk).validate(readState, headerChunk, paletteChunk);
- break;
- case PngChunk.CHUNK_PLTE:
- chunk.validate(readState, headerChunk);
- paletteChunk = (PngPlteChunk) chunk;
- break;
- default:
- chunk.validate(readState, headerChunk);
- }
- if (readState.readIDAT && !(chunk.getChunkType() == PngChunk.CHUNK_IDAT)) {
- readState.readPixelData = true;
- }
- return chunk;
-}
-
-boolean readPixelData() {
- return readState.readPixelData;
-}
-
-boolean hasMoreChunks() {
- return !readState.readIEND;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDecodingDataStream.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDecodingDataStream.java
deleted file mode 100755
index a05021a0db..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDecodingDataStream.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import java.io.*;
-
-import org.eclipse.swt.*;
-
-public class PngDecodingDataStream extends InputStream {
- InputStream stream;
- byte currentByte;
- int nextBitIndex;
-
- PngLzBlockReader lzBlockReader;
- int adlerValue;
-
- static final int PRIME = 65521;
- static final int MAX_BIT = 7;
-
-PngDecodingDataStream(InputStream stream) throws IOException {
- super();
- this.stream = stream;
- nextBitIndex = MAX_BIT + 1;
- adlerValue = 1;
- lzBlockReader = new PngLzBlockReader(this);
- readCompressedDataHeader();
- lzBlockReader.readNextBlockHeader();
-}
-
-/**
- * This method should be called when the image decoder thinks
- * that all of the compressed image data has been read. This
- * method will ensure that the next data value is an end of
- * block marker. If there are more blocks after this one,
- * the method will read them and ensure that they are empty.
- */
-void assertImageDataAtEnd() throws IOException {
- lzBlockReader.assertCompressedDataAtEnd();
-}
-
-public void close() throws IOException {
- assertImageDataAtEnd();
- checkAdler();
-}
-
-int getNextIdatBits(int length) throws IOException {
- int value = 0;
- for (int i = 0; i < length; i++) {
- value |= (getNextIdatBit() << i);
- }
- return value;
-}
-
-int getNextIdatBit() throws IOException {
- if (nextBitIndex > MAX_BIT) {
- currentByte = getNextIdatByte();
- nextBitIndex = 0;
- }
- return (currentByte & (1 << nextBitIndex)) >> nextBitIndex++;
-}
-
-byte getNextIdatByte() throws IOException {
- byte nextByte = (byte)stream.read();
- nextBitIndex = MAX_BIT + 1;
- return nextByte;
-}
-
-void updateAdler(byte value) {
- int low = adlerValue & 0xFFFF;
- int high = (adlerValue >> 16) & 0xFFFF;
- int valueInt = value & 0xFF;
- low = (low + valueInt) % PRIME;
- high = (low + high) % PRIME;
- adlerValue = (high << 16) | low;
-}
-
-public int read() throws IOException {
- byte nextDecodedByte = lzBlockReader.getNextByte();
- updateAdler(nextDecodedByte);
- return nextDecodedByte & 0xFF;
-}
-
-public int read(byte[] buffer, int off, int len) throws IOException {
- for (int i = 0; i < len; i++) {
- int b = read();
- if (b == -1) return i;
- buffer[off + i] = (byte)b;
- }
- return len;
-}
-
-void error() {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
-}
-
-private void readCompressedDataHeader() throws IOException {
- byte headerByte1 = getNextIdatByte();
- byte headerByte2 = getNextIdatByte();
-
- int number = ((headerByte1 & 0xFF) << 8) | (headerByte2 & 0xFF);
- if (number % 31 != 0) error();
-
- int compressionMethod = headerByte1 & 0x0F;
- if (compressionMethod != 8) error();
-
- int windowSizeHint = (headerByte1 & 0xF0) >> 4;
- if (windowSizeHint > 7) error();
- int windowSize = (1 << (windowSizeHint + 8));
- lzBlockReader.setWindowSize(windowSize);
-
- int dictionary = (headerByte2 & (1 << 5));
- if (dictionary != 0) error();
-
-// int compressionLevel = (headerByte2 & 0xC0) >> 6;
-}
-
-void checkAdler() throws IOException {
- int storedAdler = ((getNextIdatByte() & 0xFF) << 24)
- | ((getNextIdatByte() & 0xFF) << 16)
- | ((getNextIdatByte() & 0xFF) << 8)
- | (getNextIdatByte() & 0xFF);
- if (storedAdler != adlerValue) error();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDeflater.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDeflater.java
deleted file mode 100644
index d382f38d4f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDeflater.java
+++ /dev/null
@@ -1,618 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-import java.io.ByteArrayOutputStream;
-
-public class PngDeflater {
-
- static final int BASE = 65521;
- static final int WINDOW = 32768;
- static final int MIN_LENGTH = 3;
- static final int MAX_MATCHES = 32;
- static final int HASH = 8209;
-
- byte[] in;
- int inLength;
-
- ByteArrayOutputStream bytes = new ByteArrayOutputStream(1024);
-
- int adler32 = 1;
-
- int buffer, bitCount;
-
- Link[] hashtable = new Link[HASH];
- Link[] window = new Link[WINDOW];
- int nextWindow;
-
-static class Link {
-
- int hash, value;
- Link previous, next;
-
- Link() {
-
- this.hash = 0;
- this.value = 0;
- this.previous = null;
- this.next = null;
-
- }
-
-}
-
-static class Match {
-
- int length, distance;
-
- Match(int length, int distance) {
-
- this.length = length;
- this.distance = distance;
-
- }
-
-}
-
-static final short mirrorBytes[] = {
-
- 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
- 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
- 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
- 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
- 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
- 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
- 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
- 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
- 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
- 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
- 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
- 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
- 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
- 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
- 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
- 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
- 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
- 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
- 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
- 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
- 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
- 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
- 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
- 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
- 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
- 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
- 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
- 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
- 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
- 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
- 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
- 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
-
-};
-
-static class Code {
-
- int code, extraBits, min, max;
-
- Code(int code, int extraBits, int min, int max) {
-
- this.code = code;
- this.extraBits = extraBits;
- this.min = min;
- this.max = max;
-
- }
-
-}
-
-static final Code lengthCodes[] = {
-
- new Code(257, 0, 3, 3),
- new Code(258, 0, 4, 4),
- new Code(259, 0, 5, 5),
- new Code(260, 0, 6, 6),
- new Code(261, 0, 7, 7),
- new Code(262, 0, 8, 8),
- new Code(263, 0, 9, 9),
- new Code(264, 0, 10, 10),
- new Code(265, 1, 11, 12),
- new Code(266, 1, 13, 14),
- new Code(267, 1, 15, 16),
- new Code(268, 1, 17, 18),
- new Code(269, 2, 19, 22),
- new Code(270, 2, 23, 26),
- new Code(271, 2, 27, 30),
- new Code(272, 2, 31, 34),
- new Code(273, 3, 35, 42),
- new Code(274, 3, 43, 50),
- new Code(275, 3, 51, 58),
- new Code(276, 3, 59, 66),
- new Code(277, 4, 67, 82),
- new Code(278, 4, 83, 98),
- new Code(279, 4, 99, 114),
- new Code(280, 4, 115, 130),
- new Code(281, 5, 131, 162),
- new Code(282, 5, 163, 194),
- new Code(283, 5, 195, 226),
- new Code(284, 5, 227, 257),
- new Code(285, 0, 258, 258)
-
-};
-
-static final Code distanceCodes[] = {
-
- new Code(0, 0, 1, 1),
- new Code(1, 0, 2, 2),
- new Code(2, 0, 3, 3),
- new Code(3, 0, 4, 4),
- new Code(4, 1, 5, 6),
- new Code(5, 1, 7, 8),
- new Code(6, 2, 9, 12),
- new Code(7, 2, 13, 16),
- new Code(8, 3, 17, 24),
- new Code(9, 3, 25, 32),
- new Code(10, 4, 33, 48),
- new Code(11, 4, 49, 64),
- new Code(12, 5, 65, 96),
- new Code(13, 5, 97, 128),
- new Code(14, 6, 129, 192),
- new Code(15, 6, 193, 256),
- new Code(16, 7, 257, 384),
- new Code(17, 7, 385, 512),
- new Code(18, 8, 513, 768),
- new Code(19, 8, 769, 1024),
- new Code(20, 9, 1025, 1536),
- new Code(21, 9, 1537, 2048),
- new Code(22, 10, 2049, 3072),
- new Code(23, 10, 3073, 4096),
- new Code(24, 11, 4097, 6144),
- new Code(25, 11, 6145, 8192),
- new Code(26, 12, 8193, 12288),
- new Code(27, 12, 12289, 16384),
- new Code(28, 13, 16385, 24576),
- new Code(29, 13, 24577, 32768)
-
-};
-
-void writeShortLSB(ByteArrayOutputStream baos, int theShort) {
-
- byte byte1 = (byte) (theShort & 0xff);
- byte byte2 = (byte) ((theShort >> 8) & 0xff);
- byte[] temp = {byte1, byte2};
- baos.write(temp, 0, 2);
-
-}
-
-void writeInt(ByteArrayOutputStream baos, int theInt) {
-
- byte byte1 = (byte) ((theInt >> 24) & 0xff);
- byte byte2 = (byte) ((theInt >> 16) & 0xff);
- byte byte3 = (byte) ((theInt >> 8) & 0xff);
- byte byte4 = (byte) (theInt & 0xff);
- byte[] temp = {byte1, byte2, byte3, byte4};
- baos.write(temp, 0, 4);
-
-}
-
-void updateAdler(byte value) {
-
- int low = adler32 & 0xffff;
- int high = (adler32 >> 16) & 0xffff;
- int valueInt = value & 0xff;
- low = (low + valueInt) % BASE;
- high = (low + high) % BASE;
- adler32 = (high << 16) | low;
-
-}
-
-int hash(byte[] bytes) {
-
- int hash = ((bytes[0] & 0xff) << 24 | (bytes[1] & 0xff) << 16 | (bytes[2] & 0xff) << 8) % HASH;
- if (hash < 0) {
- hash = hash + HASH;
- }
- return hash;
-
-}
-
-void writeBits(int value, int count) {
-
- buffer |= value << bitCount;
- bitCount += count;
- if (bitCount >= 16) {
- bytes.write((byte) buffer);
- bytes.write((byte) (buffer >>> 8));
- buffer >>>= 16;
- bitCount -= 16;
- }
-
-}
-
-void alignToByte() {
-
- if (bitCount > 0) {
- bytes.write((byte) buffer);
- if (bitCount > 8) bytes.write((byte) (buffer >>> 8));
- }
- buffer = 0;
- bitCount = 0;
-
-}
-
-void outputLiteral(byte literal) {
-
- int i = literal & 0xff;
-
- if (i <= 143) {
- // 0 through 143 are 8 bits long starting at 00110000
- writeBits(mirrorBytes[0x30 + i], 8);
- }
- else {
- // 144 through 255 are 9 bits long starting at 110010000
- writeBits(1 + 2 * mirrorBytes[0x90 - 144 + i], 9);
- }
-
-}
-
-Code findCode(int value, Code[] codes) {
-
- int i, j, k;
-
- i = -1;
- j = codes.length;
- while (true) {
- k = (j + i) / 2;
- if (value < codes[k].min) {
- j = k;
- }
- else if (value > codes[k].max) {
- i = k;
- }
- else {
- return codes[k];
- }
- }
-
-}
-
-void outputMatch(int length, int distance) {
-
- Code d, l;
- int thisLength;
-
- while (length > 0) {
-
- // we can transmit matches of lengths 3 through 258 inclusive
- // so if length exceeds 258, we must transmit in several steps,
- // with 258 or less in each step
-
- if (length > 260) {
- thisLength = 258;
- }
- else if (length <= 258) {
- thisLength = length;
- }
- else {
- thisLength = length - 3;
- }
-
- length = length - thisLength;
-
- // find length code
- l = findCode(thisLength, lengthCodes);
-
- // transmit the length code
- // 256 through 279 are 7 bits long starting at 0000000
- // 280 through 287 are 8 bits long starting at 11000000
- if (l.code <= 279) {
- writeBits(mirrorBytes[(l.code - 256) * 2], 7);
- }
- else {
- writeBits(mirrorBytes[0xc0 - 280 + l.code], 8);
- }
-
- // transmit the extra bits
- if (l.extraBits != 0) {
- writeBits(thisLength - l.min, l.extraBits);
- }
-
- // find distance code
- d = findCode(distance, distanceCodes);
-
- // transmit the distance code
- // 5 bits long starting at 00000
- writeBits(mirrorBytes[d.code * 8], 5);
-
- // transmit the extra bits
- if (d.extraBits != 0) {
- writeBits(distance - d.min, d.extraBits);
- }
-
- }
-
-}
-
-Match findLongestMatch(int position, Link firstPosition) {
-
- Link link = firstPosition;
- int numberOfMatches = 0;
- Match bestMatch = new Match(-1, -1);
-
- while (true) {
-
- int matchPosition = link.value;
-
- if (position - matchPosition < WINDOW && matchPosition != 0) {
-
- int i;
-
- for (i = 1; position + i < inLength; i++) {
- if (in[position + i] != in[matchPosition + i]) {
- break;
- }
- }
-
- if (i >= MIN_LENGTH) {
-
- if (i > bestMatch.length) {
- bestMatch.length = i;
- bestMatch.distance = position - matchPosition;
- }
-
- numberOfMatches = numberOfMatches + 1;
-
- if (numberOfMatches == MAX_MATCHES) {
- break;
- }
-
- }
-
- }
-
- link = link.next;
- if (link == null) {
- break;
- }
-
- }
-
- if (bestMatch.length < MIN_LENGTH || bestMatch.distance < 1 || bestMatch.distance > WINDOW) {
- return null;
- }
-
- return bestMatch;
-
-}
-
-void updateHashtable(int to, int from) {
-
- byte[] data = new byte[3];
- int hash;
- Link temp;
-
- for (int i = to; i < from; i++) {
-
- if (i + MIN_LENGTH > inLength) {
- break;
- }
-
- data[0] = in[i];
- data[1] = in[i + 1];
- data[2] = in[i + 2];
-
- hash = hash(data);
-
- if (window[nextWindow].previous != null) {
- window[nextWindow].previous.next = null;
- }
- else if (window[nextWindow].hash != 0) {
- hashtable[window[nextWindow].hash].next = null;
- }
-
- window[nextWindow].hash = hash;
- window[nextWindow].value = i;
- window[nextWindow].previous = null;
- temp = window[nextWindow].next = hashtable[hash].next;
- hashtable[hash].next = window[nextWindow];
- if (temp != null) {
- temp.previous = window[nextWindow];
- }
-
- nextWindow = nextWindow + 1;
- if (nextWindow == WINDOW) {
- nextWindow = 0;
- }
-
- }
-
-}
-
-void compress() {
-
- int position, newPosition;
- byte[] data = new byte[3];
- int hash;
- for (int i = 0; i < HASH; i++) {
- hashtable[i] = new Link();
- }
- for (int i = 0; i < WINDOW; i++) {
- window[i] = new Link();
- }
- nextWindow = 0;
- Link firstPosition;
- Match match;
- int deferredPosition = -1;
- Match deferredMatch = null;
-
- writeBits(0x01, 1); // BFINAL = 0x01 (final block)
- writeBits(0x01, 2); // BTYPE = 0x01 (compression with fixed Huffman codes)
-
- // just output first byte so we never match at zero
- outputLiteral(in[0]);
- position = 1;
-
- while (position < inLength) {
-
- if (inLength - position < MIN_LENGTH) {
- outputLiteral(in[position]);
- position = position + 1;
- continue;
- }
-
- data[0] = in[position];
- data[1] = in[position + 1];
- data[2] = in[position + 2];
-
- hash = hash(data);
- firstPosition = hashtable[hash];
-
- match = findLongestMatch(position, firstPosition);
-
- updateHashtable(position, position + 1);
-
- if (match != null) {
-
- if (deferredMatch != null) {
- if (match.length > deferredMatch.length + 1) {
- // output literal at deferredPosition
- outputLiteral(in[deferredPosition]);
- // defer this match
- deferredPosition = position;
- deferredMatch = match;
- position = position + 1;
- }
- else {
- // output deferredMatch
- outputMatch(deferredMatch.length, deferredMatch.distance);
- newPosition = deferredPosition + deferredMatch.length;
- deferredPosition = -1;
- deferredMatch = null;
- updateHashtable(position + 1, newPosition);
- position = newPosition;
- }
- }
- else {
- // defer this match
- deferredPosition = position;
- deferredMatch = match;
- position = position + 1;
- }
-
- }
-
- else {
-
- // no match found
- if (deferredMatch != null) {
- outputMatch(deferredMatch.length, deferredMatch.distance);
- newPosition = deferredPosition + deferredMatch.length;
- deferredPosition = -1;
- deferredMatch = null;
- updateHashtable(position + 1, newPosition);
- position = newPosition;
- }
- else {
- outputLiteral(in[position]);
- position = position + 1;
- }
-
- }
-
- }
-
- writeBits(0, 7); // end of block code
- alignToByte();
-
-}
-
-void compressHuffmanOnly() {
-
- int position;
-
- writeBits(0x01, 1); // BFINAL = 0x01 (final block)
- writeBits(0x01, 2); // BTYPE = 0x01 (compression with fixed Huffman codes)
-
- for (position = 0; position < inLength;) {
-
- outputLiteral(in[position]);
- position = position + 1;
-
- }
-
- writeBits(0, 7); // end of block code
- alignToByte();
-
-}
-
-void store() {
-
- // stored blocks are limited to 0xffff bytes
-
- int start = 0;
- int length = inLength;
- int blockLength;
- int BFINAL = 0x00; // BFINAL = 0x00 or 0x01 (if final block), BTYPE = 0x00 (no compression)
-
- while (length > 0) {
-
- if (length < 65535) {
- blockLength = length;
- BFINAL = 0x01;
- }
- else {
- blockLength = 65535;
- BFINAL = 0x00;
- }
-
- // write data header
- bytes.write((byte) BFINAL);
- writeShortLSB(bytes, blockLength); // LEN
- writeShortLSB(bytes, blockLength ^ 0xffff); // NLEN (one's complement of LEN)
-
- // write actual data
- bytes.write(in, start, blockLength);
-
- length = length - blockLength;
- start = start + blockLength;
-
- }
-
-}
-
-public byte[] deflate(byte[] input) {
-
- in = input;
- inLength = input.length;
-
- // write zlib header
- bytes.write((byte) 0x78); // window size = 0x70 (32768), compression method = 0x08
- bytes.write((byte) 0x9C); // compression level = 0x80 (default), check bits = 0x1C
-
- // compute checksum
- for (int i = 0; i < inLength; i++) {
- updateAdler(in[i]);
- }
-
- //store();
-
- //compressHuffmanOnly();
-
- compress();
-
- // write checksum
- writeInt(bytes, adler32);
-
- return bytes.toByteArray();
-
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngEncoder.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngEncoder.java
deleted file mode 100644
index 26fe5746b7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngEncoder.java
+++ /dev/null
@@ -1,364 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.ImageLoader;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.internal.Compatibility;
-
-final class PngEncoder extends Object {
-
- static final byte SIGNATURE[] = {(byte) '\211', (byte) 'P', (byte) 'N', (byte) 'G', (byte) '\r', (byte) '\n', (byte) '\032', (byte) '\n'};
- static final byte TAG_IHDR[] = {(byte) 'I', (byte) 'H', (byte) 'D', (byte) 'R'};
- static final byte TAG_PLTE[] = {(byte) 'P', (byte) 'L', (byte) 'T', (byte) 'E'};
- static final byte TAG_TRNS[] = {(byte) 't', (byte) 'R', (byte) 'N', (byte) 'S'};
- static final byte TAG_IDAT[] = {(byte) 'I', (byte) 'D', (byte) 'A', (byte) 'T'};
- static final byte TAG_IEND[] = {(byte) 'I', (byte) 'E', (byte) 'N', (byte) 'D'};
-
- ByteArrayOutputStream bytes = new ByteArrayOutputStream(1024);
- PngChunk chunk;
-
- ImageLoader loader;
- ImageData data;
- int transparencyType;
-
- int width, height, bitDepth, colorType;
-
- int compressionMethod = 0;
- int filterMethod = 0;
- int interlaceMethod = 0;
-
-public PngEncoder(ImageLoader loader) {
-
- this.loader = loader;
- this.data = loader.data[0];
- this.transparencyType = data.getTransparencyType();
-
- this.width = data.width;
- this.height = data.height;
-
- this.bitDepth = 8;
-
- this.colorType = 2;
-
- if (data.palette.isDirect) {
- if (transparencyType == SWT.TRANSPARENCY_ALPHA) {
- this.colorType = 6;
- }
- }
- else {
- this.colorType = 3;
- }
-
- if (!(colorType == 2 || colorType == 3 || colorType == 6)) SWT.error(SWT.ERROR_INVALID_IMAGE);
-
-}
-
-void writeShort(ByteArrayOutputStream baos, int theShort) {
-
- byte byte1 = (byte) ((theShort >> 8) & 0xff);
- byte byte2 = (byte) (theShort & 0xff);
- byte[] temp = {byte1, byte2};
- baos.write(temp, 0, 2);
-
-}
-
-void writeInt(ByteArrayOutputStream baos, int theInt) {
-
- byte byte1 = (byte) ((theInt >> 24) & 0xff);
- byte byte2 = (byte) ((theInt >> 16) & 0xff);
- byte byte3 = (byte) ((theInt >> 8) & 0xff);
- byte byte4 = (byte) (theInt & 0xff);
- byte[] temp = {byte1, byte2, byte3, byte4};
- baos.write(temp, 0, 4);
-
-}
-
-void writeChunk(byte[] tag, byte[] buffer) {
-
- int bufferLength = (buffer != null) ? buffer.length : 0;
-
- chunk = new PngChunk(bufferLength);
-
- writeInt(bytes, bufferLength);
- bytes.write(tag, 0, 4);
- chunk.setType(tag);
- if (bufferLength != 0) {
- bytes.write(buffer, 0, bufferLength);
- chunk.setData(buffer);
- }
- else {
- chunk.setCRC(chunk.computeCRC());
- }
- writeInt(bytes, chunk.getCRC());
-
-}
-
-void writeSignature() {
-
- bytes.write(SIGNATURE, 0, 8);
-
-}
-
-void writeHeader() {
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream(13);
-
- writeInt(baos, width);
- writeInt(baos, height);
- baos.write(bitDepth);
- baos.write(colorType);
- baos.write(compressionMethod);
- baos.write(filterMethod);
- baos.write(interlaceMethod);
-
- writeChunk(TAG_IHDR, baos.toByteArray());
-
-}
-
-void writePalette() {
-
- RGB[] RGBs = data.palette.getRGBs();
-
- if (RGBs.length > 256) SWT.error(SWT.ERROR_INVALID_IMAGE);
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream(RGBs.length);
-
- for (int i = 0; i < RGBs.length; i++) {
-
- baos.write((byte) RGBs[i].red);
- baos.write((byte) RGBs[i].green);
- baos.write((byte) RGBs[i].blue);
-
- }
-
- writeChunk(TAG_PLTE, baos.toByteArray());
-
-}
-
-void writeTransparency() {
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- switch (transparencyType) {
-
- case SWT.TRANSPARENCY_ALPHA:
-
- int pixelValue, alphaValue;
-
- byte[] alphas = new byte[data.palette.getRGBs().length];
-
- for (int y = 0; y < height; y++) {
-
- for (int x = 0; x < width; x++) {
-
- pixelValue = data.getPixel(x, y);
- alphaValue = data.getAlpha(x, y);
-
- alphas[pixelValue] = (byte) alphaValue;
-
- }
-
- }
-
- baos.write(alphas, 0, alphas.length);
-
- break;
-
- case SWT.TRANSPARENCY_PIXEL:
-
- int pixel = data.transparentPixel;
-
- if (colorType == 2) {
-
- int redMask = data.palette.redMask;
- int redShift = data.palette.redShift;
- int greenMask = data.palette.greenMask;
- int greenShift = data.palette.greenShift;
- int blueShift = data.palette.blueShift;
- int blueMask = data.palette.blueMask;
-
- int r = pixel & redMask;
- r = (redShift < 0) ? r >>> -redShift : r << redShift;
- int g = pixel & greenMask;
- g = (greenShift < 0) ? g >>> -greenShift : g << greenShift;
- int b = pixel & blueMask;
- b = (blueShift < 0) ? b >>> -blueShift : b << blueShift;
-
- writeShort(baos, r);
- writeShort(baos, g);
- writeShort(baos, b);
-
- }
-
- if (colorType == 3) {
-
- byte[] padding = new byte[pixel + 1];
-
- for (int i = 0; i < pixel; i++) {
-
- padding[i] = (byte) 255;
-
- }
-
- padding[pixel] = (byte) 0;
-
- baos.write(padding, 0, padding.length);
-
- }
-
- break;
-
- }
-
- writeChunk(TAG_TRNS, baos.toByteArray());
-
-}
-
-void writeImageData() throws IOException {
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
- OutputStream os = Compatibility.newDeflaterOutputStream(baos);
- if (os == null) os = baos;
-
- if (colorType == 3) {
-
- byte[] lineData = new byte[width];
-
- for (int y = 0; y < height; y++) {
-
- int filter = 0;
- os.write(filter);
-
- data.getPixels(0, y, width, lineData, 0);
-
- for (int x = 0; x < lineData.length; x++) {
-
- os.write(lineData[x]);
-
- }
-
- }
-
- }
-
- else {
-
- int[] lineData = new int[width];
- byte[] alphaData = null;
- if (colorType == 6) {
- alphaData = new byte[width];
- }
-
- int redMask = data.palette.redMask;
- int redShift = data.palette.redShift;
- int greenMask = data.palette.greenMask;
- int greenShift = data.palette.greenShift;
- int blueShift = data.palette.blueShift;
- int blueMask = data.palette.blueMask;
-
- for (int y = 0; y < height; y++) {
-
- int filter = 0;
- os.write(filter);
-
- data.getPixels(0, y, width, lineData, 0);
-
- if (colorType == 6) {
- data.getAlphas(0, y, width, alphaData, 0);
- }
-
- for (int x = 0; x < lineData.length; x++) {
-
- int pixel = lineData[x];
-
- int r = pixel & redMask;
- r = (redShift < 0) ? r >>> -redShift : r << redShift;
- int g = pixel & greenMask;
- g = (greenShift < 0) ? g >>> -greenShift : g << greenShift;
- int b = pixel & blueMask;
- b = (blueShift < 0) ? b >>> -blueShift : b << blueShift;
-
- os.write(r);
- os.write(g);
- os.write(b);
-
- if (colorType == 6) {
- os.write(alphaData[x]);
- }
-
- }
-
- }
-
- }
-
- os.flush();
- os.close();
-
- byte[] compressed = baos.toByteArray();
- if (os == baos) {
- PngDeflater deflater = new PngDeflater();
- compressed = deflater.deflate(compressed);
- }
-
- writeChunk(TAG_IDAT, compressed);
-
-}
-
-void writeEnd() {
-
- writeChunk(TAG_IEND, null);
-
-}
-
-public void encode(LEDataOutputStream outputStream) {
-
- try {
-
- writeSignature();
- writeHeader();
-
- if (colorType == 3) {
- writePalette();
- }
-
- boolean transparencyAlpha = (transparencyType == SWT.TRANSPARENCY_ALPHA);
- boolean transparencyPixel = (transparencyType == SWT.TRANSPARENCY_PIXEL);
- boolean type2Transparency = (colorType == 2 && transparencyPixel);
- boolean type3Transparency = (colorType == 3 && (transparencyAlpha || transparencyPixel));
-
- if (type2Transparency || type3Transparency) {
- writeTransparency();
- }
-
- writeImageData();
- writeEnd();
-
- outputStream.write(bytes.toByteArray());
-
- }
-
- catch (IOException e) {
-
- SWT.error(SWT.ERROR_IO, e);
-
- }
-
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngFileReadState.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngFileReadState.java
deleted file mode 100755
index f8f0064de7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngFileReadState.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-class PngFileReadState extends Object {
- boolean readIHDR;
- boolean readPLTE;
- boolean readIDAT;
- boolean readIEND;
-
- // Non - critical chunks
- boolean readTRNS;
-
- // Set to true after IDATs have been read.
- boolean readPixelData;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTable.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTable.java
deleted file mode 100755
index 48e026958b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTable.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-import java.io.*;
-
-public class PngHuffmanTable {
- CodeLengthInfo[] codeLengthInfo;
- int[] codeValues;
-
- static final int MAX_CODE_LENGTH = 15;
- static final int BAD_CODE = 0xFFFFFFF;
- static final int incs[] = {1391376, 463792, 198768, 86961, 33936, 13776, 4592, 1968, 861, 336, 112, 48, 21, 7, 3, 1};
-
-PngHuffmanTable (int[] lengths) {
- super();
- initialize(lengths);
- generateTable(lengths);
-}
-
-private void initialize(int[] lengths) {
- codeValues = new int[lengths.length];
- for (int i = 0; i < codeValues.length; i++) {
- codeValues[i] = i;
- }
-
- // minCodesByLength[n] : The smallest Huffman code of length n + 1.
- // maxCodesByLength[n] : The largest Huffman code of length n + 1.
- // indexesByLength[n] : Index into the values array. First value with a code of length n + 1.
- codeLengthInfo = new CodeLengthInfo[MAX_CODE_LENGTH];
- for (int i = 0; i < MAX_CODE_LENGTH; i++) {
- codeLengthInfo[i] = new CodeLengthInfo();
- codeLengthInfo[i].length = i;
- codeLengthInfo[i].baseIndex = 0;
- codeLengthInfo[i].min = BAD_CODE;
- codeLengthInfo[i].max = -1;
- }
-}
-
-private void generateTable(int[] lengths) {
- // Sort the values using shellsort. Primary key is code size. Secondary key is value.
- int codeValuesTemp;
- for (int k = 0; k < 16; k++) {
- for (int h = incs[k], i = h; i < lengths.length; i++) {
- int v = lengths[i];
- codeValuesTemp = codeValues[i];
- int j = i;
- while (j >= h && (lengths[j - h] > v || (lengths[j - h] == v && codeValues[j - h] > codeValuesTemp))) {
- lengths[j] = lengths[j - h];
- codeValues[j] = codeValues[j - h];
- j -= h;
- }
- lengths[j] = v;
- codeValues[j] = codeValuesTemp;
- }
- }
-
- // These values in these arrays correspond to the elements of the
- // "values" array. The Huffman code for codeValues[N] is codes[N]
- // and the length of the code is lengths[N].
- int[] codes = new int[lengths.length];
- int lastLength = 0;
- int code = 0;
- for (int i = 0; i < lengths.length; i++) {
- while (lastLength != lengths[i]) {
- lastLength++;
- code <<= 1;
- }
- if (lastLength != 0) {
- codes[i] = code;
- code++;
- }
- }
-
- int last = 0;
- for (int i = 0; i < lengths.length; i++) {
- if (last != lengths[i]) {
- last = lengths[i];
- codeLengthInfo[last - 1].baseIndex = i;
- codeLengthInfo[last - 1].min = codes[i];
- }
- if (last != 0) codeLengthInfo[last - 1].max = codes[i];
- }
-}
-
-int getNextValue(PngDecodingDataStream stream) throws IOException {
- int code = stream.getNextIdatBit();
- int codelength = 0;
-
- // Here we are taking advantage of the fact that 1 bits are used as
- // a prefix to the longer codeValues.
- while (codelength < MAX_CODE_LENGTH && code > codeLengthInfo[codelength].max) {
- code = ((code << 1) | stream.getNextIdatBit());
- codelength++;
- }
- if (codelength >= MAX_CODE_LENGTH) stream.error();
-
- // Now we have a Huffman code of length (codelength + 1) that
- // is somewhere in the range
- // minCodesByLength[codelength]..maxCodesByLength[codelength].
- // This code is the (offset + 1)'th code of (codelength + 1);
- int offset = code - codeLengthInfo[codelength].min;
-
- // indexesByLength[codelength] is the first code of length (codelength + 1)
- // so now we can look up the value for the Huffman code in the table.
- int index = codeLengthInfo[codelength].baseIndex + offset;
- return codeValues[index];
-}
-
-static class CodeLengthInfo {
- int length;
- int max;
- int min;
- int baseIndex;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTables.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTables.java
deleted file mode 100755
index 6ecaeb4764..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTables.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-import java.io.*;
-
-public class PngHuffmanTables {
- PngHuffmanTable literalTable;
- PngHuffmanTable distanceTable;
-
- static PngHuffmanTable FixedLiteralTable;
- static PngHuffmanTable FixedDistanceTable;
-
- static final int LiteralTableSize = 288;
- static final int[] FixedLiteralLengths = {
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8,
- };
-
- static final int DistanceTableSize = 32;
- static final int[] FixedDistanceLengths = {
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- };
-
- static final int LengthCodeTableSize = 19;
- static final int[] LengthCodeOrder = {
- 16, 17, 18, 0, 8, 7, 9, 6, 10, 5,
- 11, 4, 12, 3, 13, 2, 14, 1, 15
- };
-
-static PngHuffmanTables getDynamicTables(PngDecodingDataStream stream) throws IOException {
- return new PngHuffmanTables(stream);
-}
-static PngHuffmanTables getFixedTables() {
- return new PngHuffmanTables();
-}
-
-private PngHuffmanTable getFixedLiteralTable() {
- if (FixedLiteralTable == null) {
- FixedLiteralTable = new PngHuffmanTable(FixedLiteralLengths);
- }
- return FixedLiteralTable;
-}
-
-private PngHuffmanTable getFixedDistanceTable() {
- if (FixedDistanceTable == null) {
- FixedDistanceTable = new PngHuffmanTable(FixedDistanceLengths);
- }
- return FixedDistanceTable;
-}
-
-private PngHuffmanTables () {
- literalTable = getFixedLiteralTable();
- distanceTable = getFixedDistanceTable();
-}
-
-private PngHuffmanTables (PngDecodingDataStream stream) throws IOException {
- int literals = PngLzBlockReader.FIRST_LENGTH_CODE
- + stream.getNextIdatBits(5);
- int distances = PngLzBlockReader.FIRST_DISTANCE_CODE
- + stream.getNextIdatBits(5);
- int codeLengthCodes = PngLzBlockReader.FIRST_CODE_LENGTH_CODE
- + stream.getNextIdatBits(4);
-
- if (codeLengthCodes > PngLzBlockReader.LAST_CODE_LENGTH_CODE) {
- stream.error();
- }
-
- /* Tricky, tricky, tricky. The length codes are stored in
- * a very odd order. (For the order, see the definition of
- * the static field lengthCodeOrder.) Also, the data may
- * not contain values for all the codes. It may just contain
- * values for the first X number of codes. The table should
- * be of size <LengthCodeTableSize> regardless of the number
- * of values actually given in the table.
- */
- int[] lengthCodes = new int[LengthCodeTableSize];
- for (int i = 0; i < codeLengthCodes; i++) {
- lengthCodes[LengthCodeOrder[i]] = stream.getNextIdatBits(3);
- }
- PngHuffmanTable codeLengthsTable = new PngHuffmanTable(lengthCodes);
-
- int[] literalLengths = readLengths(
- stream, literals, codeLengthsTable, LiteralTableSize);
- int[] distanceLengths = readLengths(
- stream, distances, codeLengthsTable, DistanceTableSize);
-
- literalTable = new PngHuffmanTable(literalLengths);
- distanceTable = new PngHuffmanTable(distanceLengths);
-}
-
-private int [] readLengths (PngDecodingDataStream stream,
- int numLengths,
- PngHuffmanTable lengthsTable,
- int tableSize) throws IOException
-{
- int[] lengths = new int[tableSize];
-
- for (int index = 0; index < numLengths;) {
- int value = lengthsTable.getNextValue(stream);
- if (value < 16) {
- // Literal value
- lengths[index] = value;
- index++;
- } else if (value == 16) {
- // Repeat the previous code 3-6 times.
- int count = stream.getNextIdatBits(2) + 3;
- for (int i = 0; i < count; i++) {
- lengths[index] = lengths [index - 1];
- index++;
- }
- } else if (value == 17) {
- // Repeat 0 3-10 times.
- int count = stream.getNextIdatBits(3) + 3;
- for (int i = 0; i < count; i++) {
- lengths[index] = 0;
- index++;
- }
- } else if (value == 18) {
- // Repeat 0 11-138 times.
- int count = stream.getNextIdatBits(7) + 11;
- for (int i = 0; i < count; i++) {
- lengths[index] = 0;
- index++;
- }
- } else {
- stream.error();
- }
- }
- return lengths;
-}
-
-int getNextLiteralValue(PngDecodingDataStream stream) throws IOException {
- return literalTable.getNextValue(stream);
-}
-
-int getNextDistanceValue(PngDecodingDataStream stream) throws IOException {
- return distanceTable.getNextValue(stream);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIdatChunk.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIdatChunk.java
deleted file mode 100755
index 6dfac62210..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIdatChunk.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-
-class PngIdatChunk extends PngChunk {
-
- static final int HEADER_BYTES_LENGTH = 2;
- static final int ADLER_FIELD_LENGTH = 4;
- static final int HEADER_BYTE1_DATA_OFFSET = DATA_OFFSET + 0;
- static final int HEADER_BYTE2_DATA_OFFSET = DATA_OFFSET + 1;
- static final int ADLER_DATA_OFFSET = DATA_OFFSET + 2; // plus variable compressed data length
-
-PngIdatChunk(byte headerByte1, byte headerByte2, byte[] data, int adler) {
- super(data.length + HEADER_BYTES_LENGTH + ADLER_FIELD_LENGTH);
- setType(TYPE_IDAT);
- reference[HEADER_BYTE1_DATA_OFFSET] = headerByte1;
- reference[HEADER_BYTE2_DATA_OFFSET] = headerByte2;
- System.arraycopy(data, 0, reference, DATA_OFFSET, data.length);
- setInt32(ADLER_DATA_OFFSET, adler);
- setCRC(computeCRC());
-}
-
-PngIdatChunk(byte[] reference) {
- super(reference);
-}
-
-int getChunkType() {
- return CHUNK_IDAT;
-}
-
-/**
- * Answer whether the chunk is a valid IDAT chunk.
- */
-void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
- if (!readState.readIHDR
- || (headerChunk.getMustHavePalette() && !readState.readPLTE)
- || readState.readIEND)
- {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- } else {
- readState.readIDAT = true;
- }
-
- super.validate(readState, headerChunk);
-}
-
-byte getDataByteAtOffset(int offset) {
- return reference[DATA_OFFSET + offset];
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIendChunk.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIendChunk.java
deleted file mode 100755
index ed604e0ae9..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIendChunk.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-
-class PngIendChunk extends PngChunk {
-
-PngIendChunk() {
- super(0);
- setType(TYPE_IEND);
- setCRC(computeCRC());
-}
-
-PngIendChunk(byte[] reference){
- super(reference);
-}
-
-int getChunkType() {
- return CHUNK_IEND;
-}
-
-/**
- * Answer whether the chunk is a valid IEND chunk.
- */
-void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
- // An IEND chunk is invalid if no IHDR has been read.
- // Or if a palette is required and has not been read.
- // Or if no IDAT chunk has been read.
- if (!readState.readIHDR
- || (headerChunk.getMustHavePalette() && !readState.readPLTE)
- || !readState.readIDAT
- || readState.readIEND)
- {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- } else {
- readState.readIEND = true;
- }
-
- super.validate(readState, headerChunk);
-
- // IEND chunks are not allowed to have any data.
- if (getLength() > 0) SWT.error(SWT.ERROR_INVALID_IMAGE);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIhdrChunk.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIhdrChunk.java
deleted file mode 100755
index 37d550883e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIhdrChunk.java
+++ /dev/null
@@ -1,408 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-class PngIhdrChunk extends PngChunk {
- static final int IHDR_DATA_LENGTH = 13;
-
- static final int WIDTH_DATA_OFFSET = DATA_OFFSET + 0;
- static final int HEIGHT_DATA_OFFSET = DATA_OFFSET + 4;
- static final int BIT_DEPTH_OFFSET = DATA_OFFSET + 8;
- static final int COLOR_TYPE_OFFSET = DATA_OFFSET + 9;
- static final int COMPRESSION_METHOD_OFFSET = DATA_OFFSET + 10;
- static final int FILTER_METHOD_OFFSET = DATA_OFFSET + 11;
- static final int INTERLACE_METHOD_OFFSET = DATA_OFFSET + 12;
-
- static final byte COLOR_TYPE_GRAYSCALE = 0;
- static final byte COLOR_TYPE_RGB = 2;
- static final byte COLOR_TYPE_PALETTE = 3;
- static final byte COLOR_TYPE_GRAYSCALE_WITH_ALPHA = 4;
- static final byte COLOR_TYPE_RGB_WITH_ALPHA = 6;
-
- static final int INTERLACE_METHOD_NONE = 0;
- static final int INTERLACE_METHOD_ADAM7 = 1;
-
- static final int FILTER_NONE = 0;
- static final int FILTER_SUB = 1;
- static final int FILTER_UP = 2;
- static final int FILTER_AVERAGE = 3;
- static final int FILTER_PAETH = 4;
-
- static final byte[] ValidBitDepths = {1, 2, 4, 8, 16};
- static final byte[] ValidColorTypes = {0, 2, 3, 4, 6};
-
- int width, height;
- byte bitDepth, colorType, compressionMethod, filterMethod, interlaceMethod;
-
-PngIhdrChunk(int width, int height, byte bitDepth, byte colorType, byte compressionMethod, byte filterMethod, byte interlaceMethod) {
- super(IHDR_DATA_LENGTH);
- setType(TYPE_IHDR);
- setWidth(width);
- setHeight(height);
- setBitDepth(bitDepth);
- setColorType(colorType);
- setCompressionMethod(compressionMethod);
- setFilterMethod(filterMethod);
- setInterlaceMethod(interlaceMethod);
- setCRC(computeCRC());
-}
-
-/**
- * Construct a PNGChunk using the reference bytes
- * given.
- */
-PngIhdrChunk(byte[] reference) {
- super(reference);
- if (reference.length <= IHDR_DATA_LENGTH) SWT.error(SWT.ERROR_INVALID_IMAGE);
- width = getInt32(WIDTH_DATA_OFFSET);
- height = getInt32(HEIGHT_DATA_OFFSET);
- bitDepth = reference[BIT_DEPTH_OFFSET];
- colorType = reference[COLOR_TYPE_OFFSET];
- compressionMethod = reference[COMPRESSION_METHOD_OFFSET];
- filterMethod = reference[FILTER_METHOD_OFFSET];
- interlaceMethod = reference[INTERLACE_METHOD_OFFSET];
-}
-
-int getChunkType() {
- return CHUNK_IHDR;
-}
-
-/**
- * Get the image's width in pixels.
- */
-int getWidth() {
- return width;
-}
-
-/**
- * Set the image's width in pixels.
- */
-void setWidth(int value) {
- setInt32(WIDTH_DATA_OFFSET, value);
- width = value;
-}
-
-/**
- * Get the image's height in pixels.
- */
-int getHeight() {
- return height;
-}
-
-/**
- * Set the image's height in pixels.
- */
-void setHeight(int value) {
- setInt32(HEIGHT_DATA_OFFSET, value);
- height = value;
-}
-
-/**
- * Get the image's bit depth.
- * This is limited to the values 1, 2, 4, 8, or 16.
- */
-byte getBitDepth() {
- return bitDepth;
-}
-
-/**
- * Set the image's bit depth.
- * This is limited to the values 1, 2, 4, 8, or 16.
- */
-void setBitDepth(byte value) {
- reference[BIT_DEPTH_OFFSET] = value;
- bitDepth = value;
-}
-
-/**
- * Get the image's color type.
- * This is limited to the values:
- * 0 - Grayscale image.
- * 2 - RGB triple.
- * 3 - Palette.
- * 4 - Grayscale with Alpha channel.
- * 6 - RGB with Alpha channel.
- */
-byte getColorType() {
- return colorType;
-}
-
-/**
- * Set the image's color type.
- * This is limited to the values:
- * 0 - Grayscale image.
- * 2 - RGB triple.
- * 3 - Palette.
- * 4 - Grayscale with Alpha channel.
- * 6 - RGB with Alpha channel.
- */
-void setColorType(byte value) {
- reference[COLOR_TYPE_OFFSET] = value;
- colorType = value;
-}
-
-/**
- * Get the image's compression method.
- * This value must be 0.
- */
-byte getCompressionMethod() {
- return compressionMethod;
-}
-
-/**
- * Set the image's compression method.
- * This value must be 0.
- */
-void setCompressionMethod(byte value) {
- reference[COMPRESSION_METHOD_OFFSET] = value;
- compressionMethod = value;
-}
-
-/**
- * Get the image's filter method.
- * This value must be 0.
- */
-byte getFilterMethod() {
- return filterMethod;
-}
-
-/**
- * Set the image's filter method.
- * This value must be 0.
- */
-void setFilterMethod(byte value) {
- reference[FILTER_METHOD_OFFSET] = value;
- filterMethod = value;
-}
-
-/**
- * Get the image's interlace method.
- * This value is limited to:
- * 0 - No interlacing used.
- * 1 - Adam7 interlacing used.
- */
-byte getInterlaceMethod() {
- return interlaceMethod;
-}
-
-/**
- * Set the image's interlace method.
- * This value is limited to:
- * 0 - No interlacing used.
- * 1 - Adam7 interlacing used.
- */
-void setInterlaceMethod(byte value) {
- reference[INTERLACE_METHOD_OFFSET] = value;
- interlaceMethod = value;
-}
-
-/**
- * Answer whether the chunk is a valid IHDR chunk.
- */
-void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
- // An IHDR chunk is invalid if any other chunk has
- // been read.
- if (readState.readIHDR
- || readState.readPLTE
- || readState.readIDAT
- || readState.readIEND)
- {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- } else {
- readState.readIHDR = true;
- }
-
- super.validate(readState, headerChunk);
-
- if (length != IHDR_DATA_LENGTH) SWT.error(SWT.ERROR_INVALID_IMAGE);
- if (compressionMethod != 0) SWT.error(SWT.ERROR_INVALID_IMAGE);
- if (interlaceMethod != INTERLACE_METHOD_NONE &&
- interlaceMethod != INTERLACE_METHOD_ADAM7) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
-
- boolean colorTypeIsValid = false;
- for (int i = 0; i < ValidColorTypes.length; i++) {
- if (ValidColorTypes[i] == colorType) {
- colorTypeIsValid = true;
- break;
- }
- }
- if (!colorTypeIsValid) SWT.error(SWT.ERROR_INVALID_IMAGE);
-
- boolean bitDepthIsValid = false;
- for (int i = 0; i < ValidBitDepths.length; i++) {
- if (ValidBitDepths[i] == bitDepth) {
- bitDepthIsValid = true;
- break;
- }
- }
- if (!bitDepthIsValid) SWT.error(SWT.ERROR_INVALID_IMAGE);
-
- if ((colorType == COLOR_TYPE_RGB
- || colorType == COLOR_TYPE_RGB_WITH_ALPHA
- || colorType == COLOR_TYPE_GRAYSCALE_WITH_ALPHA)
- && bitDepth < 8)
- {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
-
- if (colorType == COLOR_TYPE_PALETTE && bitDepth > 8) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
-}
-
-String getColorTypeString() {
- switch (colorType) {
- case COLOR_TYPE_GRAYSCALE: return "Grayscale";
- case COLOR_TYPE_RGB: return "RGB";
- case COLOR_TYPE_PALETTE: return "Palette";
- case COLOR_TYPE_GRAYSCALE_WITH_ALPHA: return "Grayscale with Alpha";
- case COLOR_TYPE_RGB_WITH_ALPHA: return "RGB with Alpha";
- default: return "Unknown - " + colorType;
- }
-}
-
-String getFilterMethodString() {
- switch (filterMethod) {
- case FILTER_NONE: return "None";
- case FILTER_SUB: return "Sub";
- case FILTER_UP: return "Up";
- case FILTER_AVERAGE: return "Average";
- case FILTER_PAETH: return "Paeth";
- default: return "Unknown";
- }
-}
-
-String getInterlaceMethodString() {
- switch (interlaceMethod) {
- case INTERLACE_METHOD_NONE: return "Not Interlaced";
- case INTERLACE_METHOD_ADAM7: return "Interlaced - ADAM7";
- default: return "Unknown";
- }
-}
-
-void contributeToString(StringBuffer buffer) {
- buffer.append("\n\tWidth: ");
- buffer.append(width);
- buffer.append("\n\tHeight: ");
- buffer.append(height);
- buffer.append("\n\tBit Depth: ");
- buffer.append(bitDepth);
- buffer.append("\n\tColor Type: ");
- buffer.append(getColorTypeString());
- buffer.append("\n\tCompression Method: ");
- buffer.append(compressionMethod);
- buffer.append("\n\tFilter Method: ");
- buffer.append(getFilterMethodString());
- buffer.append("\n\tInterlace Method: ");
- buffer.append(getInterlaceMethodString());
-}
-
-boolean getMustHavePalette() {
- return colorType == COLOR_TYPE_PALETTE;
-}
-
-boolean getCanHavePalette() {
- return colorType != COLOR_TYPE_GRAYSCALE &&
- colorType != COLOR_TYPE_GRAYSCALE_WITH_ALPHA;
-}
-
-/**
- * Answer the pixel size in bits based on the color type
- * and bit depth.
- */
-int getBitsPerPixel() {
- switch (colorType) {
- case COLOR_TYPE_RGB_WITH_ALPHA:
- return 4 * bitDepth;
- case COLOR_TYPE_RGB:
- return 3 * bitDepth;
- case COLOR_TYPE_GRAYSCALE_WITH_ALPHA:
- return 2 * bitDepth;
- case COLOR_TYPE_GRAYSCALE:
- case COLOR_TYPE_PALETTE:
- return bitDepth;
- default:
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return 0;
- }
-}
-
-/**
- * Answer the pixel size in bits based on the color type
- * and bit depth.
- */
-int getSwtBitsPerPixel() {
- switch (colorType) {
- case COLOR_TYPE_RGB_WITH_ALPHA:
- case COLOR_TYPE_RGB:
- case COLOR_TYPE_GRAYSCALE_WITH_ALPHA:
- return 24;
- case COLOR_TYPE_GRAYSCALE:
- case COLOR_TYPE_PALETTE:
- return Math.min(bitDepth, 8);
- default:
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return 0;
- }
-}
-
-int getFilterByteOffset() {
- if (bitDepth < 8) return 1;
- return getBitsPerPixel() / 8;
-}
-
-boolean usesDirectColor() {
- switch (colorType) {
- case COLOR_TYPE_GRAYSCALE:
- case COLOR_TYPE_GRAYSCALE_WITH_ALPHA:
- case COLOR_TYPE_RGB:
- case COLOR_TYPE_RGB_WITH_ALPHA:
- return true;
- default:
- return false;
- }
-}
-
-PaletteData createGrayscalePalette() {
- int depth = Math.min(bitDepth, 8);
- int max = (1 << depth) - 1;
- int delta = 255 / max;
- int gray = 0;
- RGB[] rgbs = new RGB[max + 1];
- for (int i = 0; i <= max; i++) {
- rgbs[i] = new RGB(gray, gray, gray);
- gray += delta;
- }
- return new PaletteData(rgbs);
-}
-
-PaletteData getPaletteData() {
- switch (colorType) {
- case COLOR_TYPE_GRAYSCALE:
- return createGrayscalePalette();
- case COLOR_TYPE_GRAYSCALE_WITH_ALPHA:
- case COLOR_TYPE_RGB:
- case COLOR_TYPE_RGB_WITH_ALPHA:
- return new PaletteData(0xFF0000, 0xFF00, 0xFF);
- default:
- return null;
- }
-}
-
-
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngInputStream.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngInputStream.java
deleted file mode 100644
index c0fd08e329..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngInputStream.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-import java.io.*;
-
-public class PngInputStream extends InputStream {
- PngChunkReader reader;
- PngChunk chunk;
- int offset, length;
-
- final static int DATA_OFFSET = 8;
-
-public PngInputStream(PngIdatChunk chunk, PngChunkReader reader) {
- this.chunk = chunk;
- this.reader = reader;
- length = chunk.getLength();
- offset = 0;
-}
-
-private boolean checkChunk() throws IOException {
- while (offset == length) {
- chunk = reader.readNextChunk();
- if (chunk == null) throw new IOException();
- if (chunk.getChunkType() == PngChunk.CHUNK_IEND) return false;
- if (chunk.getChunkType() != PngChunk.CHUNK_IDAT) throw new IOException();
- length = chunk.getLength();
- offset = 0;
- }
- return true;
-}
-
-public void close() throws IOException {
- chunk = null;
-}
-
-public int read() throws IOException {
- if (chunk == null) throw new IOException();
- if (offset == length && !checkChunk()) return -1;
- int b = chunk.reference[DATA_OFFSET + offset] & 0xFF;
- offset++;
- return b;
-}
-
-public int read(byte[] b, int off, int len) throws IOException {
- if (chunk == null) throw new IOException();
- if (offset == length && !checkChunk()) return -1;
- len = Math.min(len, length - offset);
- System.arraycopy(chunk.reference, DATA_OFFSET + offset, b, off, len);
- offset += len;
- return len;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngLzBlockReader.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngLzBlockReader.java
deleted file mode 100755
index e4b8d71a7e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngLzBlockReader.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-import java.io.*;
-
-public class PngLzBlockReader {
- boolean isLastBlock;
- byte compressionType;
- int uncompressedBytesRemaining;
- PngDecodingDataStream stream;
- PngHuffmanTables huffmanTables;
-
- byte[] window;
- int windowIndex;
- int copyIndex;
- int copyBytesRemaining;
-
- static final int UNCOMPRESSED = 0;
- static final int COMPRESSED_FIXED = 1;
- static final int COMPRESSED_DYNAMIC = 2;
-
- static final int END_OF_COMPRESSED_BLOCK = 256;
- static final int FIRST_LENGTH_CODE = 257;
- static final int LAST_LENGTH_CODE = 285;
- static final int FIRST_DISTANCE_CODE = 1;
- static final int LAST_DISTANCE_CODE = 29;
- static final int FIRST_CODE_LENGTH_CODE = 4;
- static final int LAST_CODE_LENGTH_CODE = 19;
-
- static final int[] lengthBases = {
- 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27,
- 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258
- } ;
- static final int[] extraLengthBits = {
- 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
- 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0,
- };
- static final int[] distanceBases = {
- 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129,
- 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097,
- 6145, 8193, 12289, 16385, 24577,
- };
- static final int[] extraDistanceBits = {
- 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7,
- 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13,
- };
-
-
-PngLzBlockReader(PngDecodingDataStream stream) {
- this.stream = stream;
- isLastBlock = false;
-}
-
-void setWindowSize(int windowSize) {
- window = new byte[windowSize];
-}
-
-void readNextBlockHeader() throws IOException {
- isLastBlock = stream.getNextIdatBit() != 0;
- compressionType = (byte)(stream.getNextIdatBits(2) & 0xFF);
- if (compressionType > 2) stream.error();
-
- if (compressionType == UNCOMPRESSED) {
- byte b1 = stream.getNextIdatByte();
- byte b2 = stream.getNextIdatByte();
- byte b3 = stream.getNextIdatByte();
- byte b4 = stream.getNextIdatByte();
- if (b1 != ~b3 || b2 != ~b4) stream.error();
- uncompressedBytesRemaining = (b1 & 0xFF) | ((b2 & 0xFF) << 8);
- } else if (compressionType == COMPRESSED_DYNAMIC) {
- huffmanTables = PngHuffmanTables.getDynamicTables(stream);
- } else {
- huffmanTables = PngHuffmanTables.getFixedTables();
- }
-}
-
-byte getNextByte() throws IOException {
- if (compressionType == UNCOMPRESSED) {
- if (uncompressedBytesRemaining == 0) {
- readNextBlockHeader();
- return getNextByte();
- }
- uncompressedBytesRemaining--;
- return stream.getNextIdatByte();
- } else {
- byte value = getNextCompressedByte();
- if (value == END_OF_COMPRESSED_BLOCK) {
- if (isLastBlock) stream.error();
- readNextBlockHeader();
- return getNextByte();
- } else {
- return value;
- }
- }
-}
-
-private void assertBlockAtEnd() throws IOException {
- if (compressionType == UNCOMPRESSED) {
- if (uncompressedBytesRemaining > 0) stream.error();
- } else if (copyBytesRemaining > 0 ||
- (huffmanTables.getNextLiteralValue(stream) != END_OF_COMPRESSED_BLOCK))
- {
- stream.error();
- }
-}
-void assertCompressedDataAtEnd() throws IOException {
- assertBlockAtEnd();
- while (!isLastBlock) {
- readNextBlockHeader();
- assertBlockAtEnd();
- }
-}
-
-private byte getNextCompressedByte() throws IOException {
- if (copyBytesRemaining > 0) {
- byte value = window[copyIndex];
- window[windowIndex] = value;
- copyBytesRemaining--;
-
- copyIndex++;
- windowIndex++;
- if (copyIndex == window.length) copyIndex = 0;
- if (windowIndex == window.length) windowIndex = 0;
-
- return value;
- }
-
- int value = huffmanTables.getNextLiteralValue(stream);
- if (value < END_OF_COMPRESSED_BLOCK) {
- window[windowIndex] = (byte) (value & 0xFF);
- windowIndex++;
- if (windowIndex >= window.length) windowIndex = 0;
- return (byte) (value & 0xFF);
- } else if (value == END_OF_COMPRESSED_BLOCK) {
- readNextBlockHeader();
- return getNextByte();
- } else if (value <= LAST_LENGTH_CODE) {
- int extraBits = extraLengthBits[value - FIRST_LENGTH_CODE];
- int length = lengthBases[value - FIRST_LENGTH_CODE];
- if (extraBits > 0) {
- length += stream.getNextIdatBits(extraBits);
- }
-
- value = huffmanTables.getNextDistanceValue(stream);
- if (value > LAST_DISTANCE_CODE) stream.error();
- extraBits = extraDistanceBits[value];
- int distance = distanceBases[value];
- if (extraBits > 0) {
- distance += stream.getNextIdatBits(extraBits);
- }
-
- copyIndex = windowIndex - distance;
- if (copyIndex < 0) copyIndex += window.length;
-
- copyBytesRemaining = length;
- return getNextCompressedByte();
- } else {
- stream.error();
- return 0;
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngPlteChunk.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngPlteChunk.java
deleted file mode 100755
index 421849b730..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngPlteChunk.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-class PngPlteChunk extends PngChunk {
-
- int paletteSize;
-
-PngPlteChunk(PaletteData palette) {
- super(palette.getRGBs().length * 3);
- paletteSize = length / 3;
- setType(TYPE_PLTE);
- setPaletteData(palette);
- setCRC(computeCRC());
-}
-
-PngPlteChunk(byte[] reference){
- super(reference);
- paletteSize = length / 3;
-}
-
-int getChunkType() {
- return CHUNK_PLTE;
-}
-
-/**
- * Get the number of colors in this palette.
- */
-int getPaletteSize() {
- return paletteSize;
-}
-
-/**
- * Get a PaletteData object representing the colors
- * stored in this PLTE chunk.
- * The result should be cached as the PLTE chunk
- * does not store the palette data created.
- */
-PaletteData getPaletteData() {
- RGB[] rgbs = new RGB[paletteSize];
-// int start = DATA_OFFSET;
-// int end = DATA_OFFSET + length;
- for (int i = 0; i < rgbs.length; i++) {
- int offset = DATA_OFFSET + (i * 3);
- int red = reference[offset] & 0xFF;
- int green = reference[offset + 1] & 0xFF;
- int blue = reference[offset + 2] & 0xFF;
- rgbs[i] = new RGB(red, green, blue);
- }
- return new PaletteData(rgbs);
-}
-
-/**
- * Set the data of a PLTE chunk to the colors
- * stored in the specified PaletteData object.
- */
-void setPaletteData(PaletteData palette) {
- RGB[] rgbs = palette.getRGBs();
- for (int i = 0; i < rgbs.length; i++) {
- int offset = DATA_OFFSET + (i * 3);
- reference[offset] = (byte) rgbs[i].red;
- reference[offset + 1] = (byte) rgbs[i].green;
- reference[offset + 2] = (byte) rgbs[i].blue;
- }
-}
-
-/**
- * Answer whether the chunk is a valid PLTE chunk.
- */
-void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
- // A PLTE chunk is invalid if no IHDR has been read or if any PLTE,
- // IDAT, or IEND chunk has been read.
- if (!readState.readIHDR
- || readState.readPLTE
- || readState.readTRNS
- || readState.readIDAT
- || readState.readIEND)
- {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- } else {
- readState.readPLTE = true;
- }
-
- super.validate(readState, headerChunk);
-
- // Palettes cannot be included in grayscale images.
- //
- // Note: just ignore the palette.
-// if (!headerChunk.getCanHavePalette()) SWT.error(SWT.ERROR_INVALID_IMAGE);
-
- // Palette chunks' data fields must be event multiples
- // of 3. Each 3-byte group represents an RGB value.
- if (getLength() % 3 != 0) SWT.error(SWT.ERROR_INVALID_IMAGE);
-
- // Palettes cannot have more entries than 2^bitDepth
- // where bitDepth is the bit depth of the image given
- // in the IHDR chunk.
- if (1 << headerChunk.getBitDepth() < paletteSize) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
-
- // Palettes cannot have more than 256 entries.
- if (256 < paletteSize) SWT.error(SWT.ERROR_INVALID_IMAGE);
-}
-
-void contributeToString(StringBuffer buffer) {
- buffer.append("\n\tPalette size:");
- buffer.append(paletteSize);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngTrnsChunk.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngTrnsChunk.java
deleted file mode 100755
index d659a677d8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngTrnsChunk.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-public class PngTrnsChunk extends PngChunk {
- static final int TRANSPARENCY_TYPE_PIXEL = 0;
- static final int TRANSPARENCY_TYPE_ALPHAS = 1;
- static final int RGB_DATA_LENGTH = 6;
-
-PngTrnsChunk(RGB rgb) {
- super(RGB_DATA_LENGTH);
- setType(TYPE_tRNS);
- setInt16(DATA_OFFSET, rgb.red);
- setInt16(DATA_OFFSET + 2, rgb.green);
- setInt16(DATA_OFFSET + 4, rgb.blue);
- setCRC(computeCRC());
-}
-
-PngTrnsChunk(byte[] reference){
- super(reference);
-}
-
-int getChunkType() {
- return CHUNK_tRNS;
-}
-
-void validateLength(PngIhdrChunk header, PngPlteChunk paletteChunk) {
- boolean valid;
- switch (header.getColorType()) {
- case PngIhdrChunk.COLOR_TYPE_RGB:
- // Three 2-byte values (RGB)
- valid = getLength() == 6;
- break;
- case PngIhdrChunk.COLOR_TYPE_PALETTE:
- // Three 2-byte values (RGB)
- valid = getLength() <= paletteChunk.getLength();
- break;
- case PngIhdrChunk.COLOR_TYPE_GRAYSCALE:
- // One 2-byte value
- valid = getLength() == 2;
- break;
- // Cannot use both Alpha and tRNS
- case PngIhdrChunk.COLOR_TYPE_RGB_WITH_ALPHA:
- case PngIhdrChunk.COLOR_TYPE_GRAYSCALE_WITH_ALPHA:
- default:
- valid = false;
- }
- if (!valid) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
-}
-
-/**
- * Answer whether the chunk is a valid tRNS chunk.
- */
-void validate(PngFileReadState readState, PngIhdrChunk headerChunk, PngPlteChunk paletteChunk) {
- if (!readState.readIHDR
- || (headerChunk.getMustHavePalette() && !readState.readPLTE)
- || readState.readIDAT
- || readState.readIEND)
- {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- } else {
- readState.readTRNS = true;
- }
-
- validateLength(headerChunk, paletteChunk);
-
- super.validate(readState, headerChunk);
-}
-
-
-int getTransparencyType(PngIhdrChunk header) {
- if (header.getColorType() == PngIhdrChunk.COLOR_TYPE_PALETTE) {
- return TRANSPARENCY_TYPE_ALPHAS;
- }
- return TRANSPARENCY_TYPE_PIXEL;
-}
-
-/**
- * Answer the transparent pixel RGB value.
- * This is not valid for palette color types.
- * This is not valid for alpha color types.
- * This will convert a grayscale value into
- * a palette index.
- * It will compress a 6 byte RGB into a 3 byte
- * RGB.
- */
-int getSwtTransparentPixel(PngIhdrChunk header) {
- switch (header.getColorType()) {
- case PngIhdrChunk.COLOR_TYPE_GRAYSCALE:
- int gray = ((reference[DATA_OFFSET] & 0xFF) << 8)
- + (reference[DATA_OFFSET + 1] & 0xFF);
- if (header.getBitDepth() > 8) {
- return PNGFileFormat.compress16BitDepthTo8BitDepth(gray);
- }
- return gray & 0xFF;
- case PngIhdrChunk.COLOR_TYPE_RGB:
- int red = ((reference[DATA_OFFSET] & 0xFF) << 8)
- | (reference[DATA_OFFSET + 1] & 0xFF);
- int green = ((reference[DATA_OFFSET + 2] & 0xFF) << 8)
- | (reference[DATA_OFFSET + 3] & 0xFF);
- int blue = ((reference[DATA_OFFSET + 4] & 0xFF) << 8)
- | (reference[DATA_OFFSET + 5] & 0xFF);
- if (header.getBitDepth() > 8) {
- red = PNGFileFormat.compress16BitDepthTo8BitDepth(red);
- green = PNGFileFormat.compress16BitDepthTo8BitDepth(green);
- blue = PNGFileFormat.compress16BitDepthTo8BitDepth(blue);
- }
- return (red << 16) | (green << 8) | blue;
- default:
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return -1;
- }
-}
-
-/**
- * Answer an array of Alpha values that correspond to the
- * colors in the palette.
- * This is only valid for the COLOR_TYPE_PALETTE color type.
- */
-byte[] getAlphaValues(PngIhdrChunk header, PngPlteChunk paletteChunk) {
- if (header.getColorType() != PngIhdrChunk.COLOR_TYPE_PALETTE) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- byte[] alphas = new byte[paletteChunk.getPaletteSize()];
- int dataLength = getLength();
- int i = 0;
- for (i = 0; i < dataLength; i++) {
- alphas[i] = reference[DATA_OFFSET + i];
- }
- /**
- * Any palette entries which do not have a corresponding
- * alpha value in the tRNS chunk are spec'd to have an
- * alpha of 255.
- */
- for (int j = i; j < alphas.length; j++) {
- alphas[j] = (byte) 255;
- }
- return alphas;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFDirectory.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFDirectory.java
deleted file mode 100644
index da5f84cf1f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFDirectory.java
+++ /dev/null
@@ -1,625 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import java.io.*;
-
-final class TIFFDirectory {
-
- TIFFRandomFileAccess file;
- boolean isLittleEndian;
- ImageLoader loader;
- int depth;
-
- /* Directory fields */
- int imageWidth;
- int imageLength;
- int[] bitsPerSample;
- int compression;
- int photometricInterpretation;
- int[] stripOffsets;
- int samplesPerPixel;
- int rowsPerStrip;
- int[] stripByteCounts;
- int t4Options;
- int colorMapOffset;
-
- /* Encoder fields */
- ImageData image;
- LEDataOutputStream out;
-
- static final int NO_VALUE = -1;
-
- static final short TAG_ImageWidth = 256;
- static final short TAG_ImageLength = 257;
- static final short TAG_BitsPerSample = 258;
- static final short TAG_Compression = 259;
- static final short TAG_PhotometricInterpretation = 262;
- static final short TAG_StripOffsets = 273;
- static final short TAG_SamplesPerPixel = 277;
- static final short TAG_RowsPerStrip = 278;
- static final short TAG_StripByteCounts = 279;
- static final short TAG_XResolution = 282;
- static final short TAG_YResolution = 283;
- static final short TAG_T4Options = 292;
- static final short TAG_ResolutionUnit = 296;
- static final short TAG_ColorMap = 320;
-
- static final int TYPE_BYTE = 1;
- static final int TYPE_ASCII = 2;
- static final int TYPE_SHORT = 3;
- static final int TYPE_LONG = 4;
- static final int TYPE_RATIONAL = 5;
-
- /* Different compression schemes */
- static final int COMPRESSION_NONE = 1;
- static final int COMPRESSION_CCITT_3_1 = 2;
- static final int COMPRESSION_PACKBITS = 32773;
-
- static final int IFD_ENTRY_SIZE = 12;
-
-public TIFFDirectory(TIFFRandomFileAccess file, boolean isLittleEndian, ImageLoader loader) {
- this.file = file;
- this.isLittleEndian = isLittleEndian;
- this.loader = loader;
-}
-
-public TIFFDirectory(ImageData image) {
- this.image = image;
-}
-
-/* PackBits decoder */
-int decodePackBits(byte[] src, byte[] dest, int offsetDest) {
- int destIndex = offsetDest;
- int srcIndex = 0;
- while (srcIndex < src.length) {
- byte n = src[srcIndex];
- if (0 <= n && n <= 127) {
- /* Copy next n+1 bytes literally */
- System.arraycopy(src, ++srcIndex, dest, destIndex, n + 1);
- srcIndex += n + 1;
- destIndex += n + 1;
- } else if (-127 <= n && n <= -1) {
- /* Copy next byte -n+1 times */
- byte value = src[++srcIndex];
- for (int j = 0; j < -n + 1; j++) {
- dest[destIndex++] = value;
- }
- srcIndex++;
- } else {
- /* Noop when n == -128 */
- srcIndex++;
- }
- }
- /* Number of bytes copied */
- return destIndex - offsetDest;
-}
-
-int getEntryValue(int type, byte[] buffer, int index) {
- return toInt(buffer, index + 8, type);
-}
-
-void getEntryValue(int type, byte[] buffer, int index, int[] values) throws IOException {
- int start = index + 8;
- int size;
- int offset = toInt(buffer, start, TYPE_LONG);
- switch (type) {
- case TYPE_SHORT: size = 2; break;
- case TYPE_LONG: size = 4; break;
- case TYPE_RATIONAL: size = 8; break;
- case TYPE_ASCII:
- case TYPE_BYTE: size = 1; break;
- default: SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); return;
- }
- if (values.length * size > 4) {
- buffer = new byte[values.length * size];
- file.seek(offset);
- file.read(buffer);
- start = 0;
- }
- for (int i = 0; i < values.length; i++) {
- values[i] = toInt(buffer, start + i * size, type);
- }
-}
-
-void decodePixels(ImageData image) throws IOException {
- /* Each row is byte aligned */
- byte[] imageData = new byte[(imageWidth * depth + 7) / 8 * imageLength];
- image.data = imageData;
- int destIndex = 0;
- int length = stripOffsets.length;
- for (int i = 0; i < length; i++) {
- /* Read a strip */
- byte[] data = new byte[stripByteCounts[i]];
- file.seek(stripOffsets[i]);
- file.read(data);
- if (compression == COMPRESSION_NONE) {
- System.arraycopy(data, 0, imageData, destIndex, data.length);
- destIndex += data.length;
- } else if (compression == COMPRESSION_PACKBITS) {
- destIndex += decodePackBits(data, imageData, destIndex);
- } else if (compression == COMPRESSION_CCITT_3_1 || compression == 3) {
- TIFFModifiedHuffmanCodec codec = new TIFFModifiedHuffmanCodec();
- int nRows = rowsPerStrip;
- if (i == length -1) {
- int n = imageLength % rowsPerStrip;
- if (n != 0) nRows = n;
- }
- destIndex += codec.decode(data, imageData, destIndex, imageWidth, nRows);
- }
- if (loader.hasListeners()) {
- loader.notifyListeners(new ImageLoaderEvent(loader, image, i, i == length - 1));
- }
- }
-}
-
-PaletteData getColorMap() throws IOException {
- int numColors = 1 << bitsPerSample[0];
- /* R, G, B entries are 16 bit wide (2 bytes) */
- int numBytes = 3 * 2 * numColors;
- byte[] buffer = new byte[numBytes];
- file.seek(colorMapOffset);
- file.read(buffer);
- RGB[] colors = new RGB[numColors];
- /**
- * SWT does not support 16-bit depth color formats.
- * Convert the 16-bit data to 8-bit data.
- * The correct way to do this is to multiply each
- * 16 bit value by the value:
- * (2^8 - 1) / (2^16 - 1).
- * The fast way to do this is just to drop the low
- * byte of the 16-bit value.
- */
- int offset = isLittleEndian ? 1 : 0;
- int startG = 2 * numColors;
- int startB = startG + 2 * numColors;
- for (int i = 0; i < numColors; i++) {
- int r = buffer[offset] & 0xFF;
- int g = buffer[startG + offset] & 0xFF;
- int b = buffer[startB + offset] & 0xFF;
- colors[i] = new RGB(r, g, b);
- offset += 2;
- }
- return new PaletteData(colors);
-}
-
-PaletteData getGrayPalette() {
- int numColors = 1 << bitsPerSample[0];
- RGB[] rgbs = new RGB[numColors];
- for (int i = 0; i < numColors; i++) {
- int value = i * 0xFF / (numColors - 1);
- if (photometricInterpretation == 0) value = 0xFF - value;
- rgbs[i] = new RGB(value, value, value);
- }
- return new PaletteData(rgbs);
-}
-
-PaletteData getRGBPalette(int bitsR, int bitsG, int bitsB) {
- int blueMask = 0;
- for (int i = 0; i < bitsB; i++) {
- blueMask |= 1 << i;
- }
- int greenMask = 0;
- for (int i = bitsB; i < bitsB + bitsG; i++) {
- greenMask |= 1 << i;
- }
- int redMask = 0;
- for (int i = bitsB + bitsG; i < bitsB + bitsG + bitsR; i++) {
- redMask |= 1 << i;
- }
- return new PaletteData(redMask, greenMask, blueMask);
-}
-
-int formatStrips(int rowByteSize, int nbrRows, byte[] data, int maxStripByteSize, int offsetPostIFD, int extraBytes, int[][] strips) {
- /*
- * Calculate the nbr of required strips given the following requirements:
- * - each strip should, if possible, not be greater than maxStripByteSize
- * - each strip should contain 1 or more entire rows
- *
- * Format the strip fields arrays so that the image data is stored in one
- * contiguous block. This block is stored after the IFD and after any tag
- * info described in the IFD.
- */
- int n, nbrRowsPerStrip;
- if (rowByteSize > maxStripByteSize) {
- /* Each strip contains 1 row */
- n = data.length / rowByteSize;
- nbrRowsPerStrip = 1;
- } else {
- int nbr = (data.length + maxStripByteSize - 1) / maxStripByteSize;
- nbrRowsPerStrip = nbrRows / nbr;
- n = (nbrRows + nbrRowsPerStrip - 1) / nbrRowsPerStrip;
- }
- int stripByteSize = rowByteSize * nbrRowsPerStrip;
-
- int[] offsets = new int[n];
- int[] counts = new int[n];
- /*
- * Nbr of bytes between the end of the IFD directory and the start of
- * the image data. Keep space for at least the offsets and counts
- * data, each field being TYPE_LONG (4 bytes). If other tags require
- * space between the IFD and the image block, use the extraBytes
- * parameter.
- * If there is only one strip, the offsets and counts data is stored
- * directly in the IFD and we need not reserve space for it.
- */
- int postIFDData = n == 1 ? 0 : n * 2 * 4;
- int startOffset = offsetPostIFD + extraBytes + postIFDData; /* offset of image data */
-
- int offset = startOffset;
- for (int i = 0; i < n; i++) {
- /*
- * Store all strips sequentially to allow us
- * to copy all pixels in one contiguous area.
- */
- offsets[i] = offset;
- counts[i] = stripByteSize;
- offset += stripByteSize;
- }
- /* The last strip may contain fewer rows */
- int mod = data.length % stripByteSize;
- if (mod != 0) counts[counts.length - 1] = mod;
-
- strips[0] = offsets;
- strips[1] = counts;
- return nbrRowsPerStrip;
-}
-
-int[] formatColorMap(RGB[] rgbs) {
- /*
- * In a TIFF ColorMap, all red come first, followed by
- * green and blue. All values must be converted from
- * 8 bit to 16 bit.
- */
- int[] colorMap = new int[rgbs.length * 3];
- int offsetGreen = rgbs.length;
- int offsetBlue = rgbs.length * 2;
- for (int i = 0; i < rgbs.length; i++) {
- colorMap[i] = rgbs[i].red << 8 | rgbs[i].red;
- colorMap[i + offsetGreen] = rgbs[i].green << 8 | rgbs[i].green;
- colorMap[i + offsetBlue] = rgbs[i].blue << 8 | rgbs[i].blue;
- }
- return colorMap;
-}
-
-void parseEntries(byte[] buffer) throws IOException {
- for (int offset = 0; offset < buffer.length; offset += IFD_ENTRY_SIZE) {
- int tag = toInt(buffer, offset, TYPE_SHORT);
- int type = toInt(buffer, offset + 2, TYPE_SHORT);
- int count = toInt(buffer, offset + 4, TYPE_LONG);
- switch (tag) {
- case TAG_ImageWidth: {
- imageWidth = getEntryValue(type, buffer, offset);
- break;
- }
- case TAG_ImageLength: {
- imageLength = getEntryValue(type, buffer, offset);
- break;
- }
- case TAG_BitsPerSample: {
- if (type != TYPE_SHORT) SWT.error(SWT.ERROR_INVALID_IMAGE);
- bitsPerSample = new int[count];
- getEntryValue(type, buffer, offset, bitsPerSample);
- break;
- }
- case TAG_Compression: {
- compression = getEntryValue(type, buffer, offset);
- break;
- }
- case TAG_PhotometricInterpretation: {
- photometricInterpretation = getEntryValue(type, buffer, offset);
- break;
- }
- case TAG_StripOffsets: {
- if (type != TYPE_LONG && type != TYPE_SHORT) SWT.error(SWT.ERROR_INVALID_IMAGE);
- stripOffsets = new int[count];
- getEntryValue(type, buffer, offset, stripOffsets);
- break;
- }
- case TAG_SamplesPerPixel: {
- if (type != TYPE_SHORT) SWT.error(SWT.ERROR_INVALID_IMAGE);
- samplesPerPixel = getEntryValue(type, buffer, offset);
- /* Only the basic 1 and 3 values are supported */
- if (samplesPerPixel != 1 && samplesPerPixel != 3) SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- break;
- }
- case TAG_RowsPerStrip: {
- rowsPerStrip = getEntryValue(type, buffer, offset);
- break;
- }
- case TAG_StripByteCounts: {
- stripByteCounts = new int[count];
- getEntryValue(type, buffer, offset, stripByteCounts);
- break;
- }
- case TAG_XResolution: {
- /* Ignored */
- break;
- }
- case TAG_YResolution: {
- /* Ignored */
- break;
- }
- case TAG_T4Options: {
- if (type != TYPE_LONG) SWT.error(SWT.ERROR_INVALID_IMAGE);
- t4Options = getEntryValue(type, buffer, offset);
- if ((t4Options & 0x1) == 1) {
- /* 2-dimensional coding is not supported */
- SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
- }
- break;
- }
- case TAG_ResolutionUnit: {
- /* Ignored */
- break;
- }
- case TAG_ColorMap: {
- if (type != TYPE_SHORT) SWT.error(SWT.ERROR_INVALID_IMAGE);
- /* Get the offset of the colorMap (use TYPE_LONG) */
- colorMapOffset = getEntryValue(TYPE_LONG, buffer, offset);
- break;
- }
- }
- }
-}
-
-public ImageData read() throws IOException {
- /* Set TIFF default values */
- bitsPerSample = new int[] {1};
- colorMapOffset = NO_VALUE;
- compression = 1;
- imageLength = NO_VALUE;
- imageWidth = NO_VALUE;
- photometricInterpretation = NO_VALUE;
- rowsPerStrip = Integer.MAX_VALUE;
- samplesPerPixel = 1;
- stripByteCounts = null;
- stripOffsets = null;
-
- byte[] buffer = new byte[2];
- file.read(buffer);
- int numberEntries = toInt(buffer, 0, TYPE_SHORT);
- buffer = new byte[IFD_ENTRY_SIZE * numberEntries];
- file.read(buffer);
- parseEntries(buffer);
-
- PaletteData palette = null;
- depth = 0;
- switch (photometricInterpretation) {
- case 0:
- case 1: {
- /* Bilevel or Grayscale image */
- palette = getGrayPalette();
- depth = bitsPerSample[0];
- break;
- }
- case 2: {
- /* RGB image */
- if (colorMapOffset != NO_VALUE) SWT.error(SWT.ERROR_INVALID_IMAGE);
- /* SamplesPerPixel 3 is the only value supported */
- palette = getRGBPalette(bitsPerSample[0], bitsPerSample[1], bitsPerSample[2]);
- depth = bitsPerSample[0] + bitsPerSample[1] + bitsPerSample[2];
- break;
- }
- case 3: {
- /* Palette Color image */
- if (colorMapOffset == NO_VALUE) SWT.error(SWT.ERROR_INVALID_IMAGE);
- palette = getColorMap();
- depth = bitsPerSample[0];
- break;
- }
- default: {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- }
-
- ImageData image = ImageData.internal_new(
- imageWidth,
- imageLength,
- depth,
- palette,
- 1,
- null,
- 0,
- null,
- null,
- -1,
- -1,
- SWT.IMAGE_TIFF,
- 0,
- 0,
- 0,
- 0);
- decodePixels(image);
- return image;
-}
-
-int toInt(byte[] buffer, int i, int type) {
- if (type == TYPE_LONG) {
- return isLittleEndian ?
- (buffer[i] & 0xFF) | ((buffer[i + 1] & 0xFF) << 8) | ((buffer[i + 2] & 0xFF) << 16) | ((buffer[i + 3] & 0xFF) << 24) :
- (buffer[i + 3] & 0xFF) | ((buffer[i + 2] & 0xFF) << 8) | ((buffer[i + 1] & 0xFF) << 16) | ((buffer[i] & 0xFF) << 24);
- }
- if (type == TYPE_SHORT) {
- return isLittleEndian ?
- (buffer[i] & 0xFF) | ((buffer[i + 1] & 0xFF) << 8) :
- (buffer[i + 1] & 0xFF) | ((buffer[i] & 0xFF) << 8);
- }
- /* Invalid type */
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return -1;
-}
-
-void write(int photometricInterpretation) throws IOException {
- boolean isRGB = photometricInterpretation == 2;
- boolean isColorMap = photometricInterpretation == 3;
- boolean isBiLevel = photometricInterpretation == 0 || photometricInterpretation == 1;
-
- int imageWidth = image.width;
- int imageLength = image.height;
- int rowByteSize = image.bytesPerLine;
-
- int numberEntries = isBiLevel ? 9 : 11;
- int lengthDirectory = 2 + 12 * numberEntries + 4;
- /* Offset following the header and the directory */
- int nextOffset = 8 + lengthDirectory;
-
- /* Extra space used by XResolution and YResolution values */
- int extraBytes = 16;
-
- int[] colorMap = null;
- if (isColorMap) {
- PaletteData palette = image.palette;
- RGB[] rgbs = palette.getRGBs();
- colorMap = formatColorMap(rgbs);
- /* The number of entries of the Color Map must match the bitsPerSample field */
- if (colorMap.length != 3 * 1 << image.depth) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
- /* Extra space used by ColorMap values */
- extraBytes += colorMap.length * 2;
- }
- if (isRGB) {
- /* Extra space used by BitsPerSample values */
- extraBytes += 6;
- }
- /* TIFF recommends storing the data in strips of no more than 8 Ko */
- byte[] data = image.data;
- int[][] strips = new int[2][];
- int nbrRowsPerStrip = formatStrips(rowByteSize, imageLength, data, 8192, nextOffset, extraBytes, strips);
- int[] stripOffsets = strips[0];
- int[] stripByteCounts = strips[1];
-
- int bitsPerSampleOffset = NO_VALUE;
- if (isRGB) {
- bitsPerSampleOffset = nextOffset;
- nextOffset += 6;
- }
- int stripOffsetsOffset = NO_VALUE, stripByteCountsOffset = NO_VALUE;
- int xResolutionOffset, yResolutionOffset, colorMapOffset = NO_VALUE;
- int cnt = stripOffsets.length;
- if (cnt > 1) {
- stripOffsetsOffset = nextOffset;
- nextOffset += 4 * cnt;
- stripByteCountsOffset = nextOffset;
- nextOffset += 4 * cnt;
- }
- xResolutionOffset = nextOffset;
- nextOffset += 8;
- yResolutionOffset = nextOffset;
- nextOffset += 8;
- if (isColorMap) {
- colorMapOffset = nextOffset;
- nextOffset += colorMap.length * 2;
- }
- /* TIFF header */
- writeHeader();
-
- /* Image File Directory */
- out.writeShort(numberEntries);
- writeEntry(TAG_ImageWidth, TYPE_LONG, 1, imageWidth);
- writeEntry(TAG_ImageLength, TYPE_LONG, 1, imageLength);
- if (isColorMap) writeEntry(TAG_BitsPerSample, TYPE_SHORT, 1, image.depth);
- if (isRGB) writeEntry(TAG_BitsPerSample, TYPE_SHORT, 3, bitsPerSampleOffset);
- writeEntry(TAG_Compression, TYPE_SHORT, 1, COMPRESSION_NONE);
- writeEntry(TAG_PhotometricInterpretation, TYPE_SHORT, 1, photometricInterpretation);
- writeEntry(TAG_StripOffsets, TYPE_LONG, cnt, cnt > 1 ? stripOffsetsOffset : stripOffsets[0]);
- if (isRGB) writeEntry(TAG_SamplesPerPixel, TYPE_SHORT, 1, 3);
- writeEntry(TAG_RowsPerStrip, TYPE_LONG, 1, nbrRowsPerStrip);
- writeEntry(TAG_StripByteCounts, TYPE_LONG, cnt, cnt > 1 ? stripByteCountsOffset : stripByteCounts[0]);
- writeEntry(TAG_XResolution, TYPE_RATIONAL, 1, xResolutionOffset);
- writeEntry(TAG_YResolution, TYPE_RATIONAL, 1, yResolutionOffset);
- if (isColorMap) writeEntry(TAG_ColorMap, TYPE_SHORT, colorMap.length, colorMapOffset);
- /* Offset of next IFD (0 for last IFD) */
- out.writeInt(0);
-
- /* Values longer than 4 bytes Section */
-
- /* BitsPerSample 8,8,8 */
- if (isRGB) for (int i = 0; i < 3; i++) out.writeShort(8);
- if (cnt > 1) {
- for (int i = 0; i < cnt; i++) out.writeInt(stripOffsets[i]);
- for (int i = 0; i < cnt; i++) out.writeInt(stripByteCounts[i]);
- }
- /* XResolution and YResolution set to 300 dpi */
- for (int i = 0; i < 2; i++) {
- out.writeInt(300);
- out.writeInt(1);
- }
- /* ColorMap */
- if (isColorMap) for (int i = 0; i < colorMap.length; i++) out.writeShort(colorMap[i]);
-
- /* Image Data */
- out.write(data);
-}
-
-void writeEntry(short tag, int type, int count, int value) throws IOException {
- out.writeShort(tag);
- out.writeShort(type);
- out.writeInt(count);
- out.writeInt(value);
-}
-
-void writeHeader() throws IOException {
- /* little endian */
- out.write(0x49);
- out.write(0x49);
-
- /* TIFF identifier */
- out.writeShort(42);
- /*
- * Offset of the first IFD is chosen to be 8.
- * It is word aligned and immediately after this header.
- */
- out.writeInt(8);
-}
-
-void writeToStream(LEDataOutputStream byteStream) throws IOException {
- out = byteStream;
- int photometricInterpretation = -1;
-
- /* Scanline pad must be 1 */
- if (image.scanlinePad != 1) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
- switch (image.depth) {
- case 1: {
- /* Palette must be black and white or white and black */
- PaletteData palette = image.palette;
- RGB[] rgbs = palette.colors;
- if (palette.isDirect || rgbs == null || rgbs.length != 2) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
- RGB rgb0 = rgbs[0];
- RGB rgb1 = rgbs[1];
- if (!(rgb0.red == rgb0.green && rgb0.green == rgb0.blue &&
- rgb1.red == rgb1.green && rgb1.green == rgb1.blue &&
- ((rgb0.red == 0x0 && rgb1.red == 0xFF) || (rgb0.red == 0xFF && rgb1.red == 0x0)))) {
- SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
- }
- /* 0 means a color index of 0 is imaged as white */
- photometricInterpretation = image.palette.colors[0].red == 0xFF ? 0 : 1;
- break;
- }
- case 4:
- case 8: {
- photometricInterpretation = 3;
- break;
- }
- case 24: {
- photometricInterpretation = 2;
- break;
- }
- default: {
- SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
- }
- }
- write(photometricInterpretation);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFFileFormat.java
deleted file mode 100644
index b419a57106..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFFileFormat.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import java.io.*;
-
-/**
- * Baseline TIFF decoder revision 6.0
- * Extension T4-encoding CCITT T.4 1D
- */
-public final class TIFFFileFormat extends FileFormat {
-
-boolean isFileFormat(LEDataInputStream stream) {
- try {
- byte[] header = new byte[4];
- stream.read(header);
- stream.unread(header);
- if (header[0] != header[1]) return false;
- if (!(header[0] == 0x49 && header[2] == 42 && header[3] == 0) &&
- !(header[0] == 0x4d && header[2] == 0 && header[3] == 42)) {
- return false;
- }
- return true;
- } catch (Exception e) {
- return false;
- }
-}
-
-ImageData[] loadFromByteStream() {
- byte[] header = new byte[8];
- boolean isLittleEndian;
- ImageData[] images = new ImageData[0];
- TIFFRandomFileAccess file = new TIFFRandomFileAccess(inputStream);
- try {
- file.read(header);
- if (header[0] != header[1]) SWT.error(SWT.ERROR_INVALID_IMAGE);
- if (!(header[0] == 0x49 && header[2] == 42 && header[3] == 0) &&
- !(header[0] == 0x4d && header[2] == 0 && header[3] == 42)) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- isLittleEndian = header[0] == 0x49;
- int offset = isLittleEndian ?
- (header[4] & 0xFF) | ((header[5] & 0xFF) << 8) | ((header[6] & 0xFF) << 16) | ((header[7] & 0xFF) << 24) :
- (header[7] & 0xFF) | ((header[6] & 0xFF) << 8) | ((header[5] & 0xFF) << 16) | ((header[4] & 0xFF) << 24);
- file.seek(offset);
- TIFFDirectory directory = new TIFFDirectory(file, isLittleEndian, loader);
- ImageData image = directory.read();
- /* A baseline reader is only expected to read the first directory */
- images = new ImageData[] {image};
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- return images;
-}
-
-void unloadIntoByteStream(ImageLoader loader) {
- /* We do not currently support writing multi-page tiff,
- * so we use the first image data in the loader's array. */
- ImageData image = loader.data[0];
- TIFFDirectory directory = new TIFFDirectory(image);
- try {
- directory.writeToStream(outputStream);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFModifiedHuffmanCodec.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFModifiedHuffmanCodec.java
deleted file mode 100644
index 5f0904c790..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFModifiedHuffmanCodec.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-import org.eclipse.swt.*;
-
-/*
-* Decoder for
-* - CCITT Group 3 1-Dimensional Modified Huffman run length encoding
-* (TIFF compression type 2)
-* - CCITT T.4 bi-level encoding 1D
-* (TIFF compression type 3 option 1D)
-*/
-final class TIFFModifiedHuffmanCodec {
- static final short[][][] BLACK_CODE = {
- /* 2 bits */
- {{2, 3}, {3, 2}},
- /* 3 bits */
- {{2, 1}, {3, 4}},
- /* 4 bits */
- {{2, 6}, {3, 5}},
- /* 5 bits */
- {{3, 7}},
- /* 6 bits */
- {{4, 9}, {5, 8}},
- /* 7 bits */
- {{4, 10}, {5, 11}, {7, 12}},
- /* 8 bits */
- {{4, 13}, {7, 14}},
- /* 9 bits */
- {{24, 15}},
- /* 10 bits */
- {{8, 18}, {15, 64}, {23, 16}, {24, 17}, {55, 0}},
- /* 11 bits */
- {/* EOL */{0, -1}, {8, 1792}, {23, 24}, {24, 25}, {40, 23}, {55, 22}, {103, 19},
- {104, 20}, {108, 21}, {12, 1856}, {13, 1920}},
- /* 12 bits */
- {{18, 1984}, {19, 2048}, {20, 2112}, {21, 2176}, {22, 2240}, {23, 2304},
- {28, 2368}, {29, 2432}, {30, 2496}, {31, 2560}, {36, 52}, {39, 55}, {40, 56},
- {43, 59}, {44, 60}, {51, 320}, {52, 384}, {53, 448}, {55, 53}, {56, 54}, {82, 50},
- {83, 51}, {84, 44}, {85, 45}, {86, 46}, {87, 47}, {88, 57}, {89, 58}, {90, 61},
- {91, 256}, {100, 48}, {101, 49}, {102, 62}, {103, 63}, {104, 30}, {105, 31},
- {106, 32}, {107, 33}, {108, 40}, {109, 41}, {200, 128}, {201, 192}, {202, 26},
- {203, 27}, {204, 28}, {205, 29}, {210, 34}, {211, 35}, {212, 36}, {213, 37},
- {214, 38}, {215, 39}, {218, 42}, {219, 43}},
- /* 13 bits */
- {{74, 640}, {75, 704}, {76, 768}, {77, 832}, {82, 1280}, {83, 1344}, {84, 1408},
- {85, 1472}, {90, 1536}, {91, 1600}, {100, 1664}, {101, 1728}, {108, 512},
- {109, 576}, {114, 896}, {115, 960}, {116, 1024}, {117, 1088}, {118, 1152},
- {119, 1216}}
- };
-
- static final short[][][] WHITE_CODE = {
- /* 4 bits */
- {{7, 2}, {8, 3}, {11, 4}, {12, 5}, {14, 6}, {15, 7}},
- /* 5 bits */
- {{7, 10}, {8, 11}, {18, 128}, {19, 8}, {20, 9}, {27, 64}},
- /* 6 bits */
- {{3, 13}, {7, 1}, {8, 12}, {23, 192}, {24, 1664}, {42, 16}, {43, 17}, {52, 14},
- {53, 15}},
- /* 7 bits */
- {{3, 22}, {4, 23}, {8, 20}, {12, 19}, {19, 26}, {23, 21}, {24, 28}, {36, 27},
- {39, 18}, {40, 24}, {43, 25}, {55, 256}},
- /* 8 bits */
- {{2, 29}, {3, 30}, {4, 45}, {5, 46}, {10, 47}, {11, 48}, {18, 33}, {19, 34},
- {20, 35}, {21, 36}, {22, 37}, {23, 38}, {26, 31}, {27, 32}, {36, 53}, {37, 54},
- {40, 39}, {41, 40}, {42, 41}, {43, 42}, {44, 43}, {45, 44}, {50, 61}, {51, 62},
- {52, 63}, {53, 0}, {54, 320}, {55, 384}, {74, 59}, {75, 60}, {82, 49}, {83, 50},
- {84, 51}, {85, 52}, {88, 55}, {89, 56}, {90, 57}, {91, 58}, {100, 448},
- {101, 512}, {103, 640}, {104, 576}},
- /* 9 bits */
- {{152, 1472}, {153, 1536}, {154, 1600}, {155, 1728}, {204, 704}, {205, 768},
- {210, 832}, {211, 896}, {212, 960}, {213, 1024}, {214, 1088}, {215, 1152},
- {216, 1216}, {217, 1280}, {218, 1344}, {219, 1408}},
- /* 10 bits */
- {},
- /* 11 bits */
- {{8, 1792}, {12, 1856}, {13, 1920}},
- /* 12 bits */
- {/* EOL */{1, -1}, {18, 1984}, {19, 2048}, {20, 2112}, {21, 2176}, {22, 2240}, {23, 2304},
- {28, 2368}, {29, 2432}, {30, 2496}, {31, 2560}}
- };
-
- static final int BLACK_MIN_BITS = 2;
- static final int WHITE_MIN_BITS = 4;
-
- boolean isWhite;
- int whiteValue = 0;
- int blackValue = 1;
- byte[] src;
- byte[] dest;
- int byteOffsetSrc = 0;
- int bitOffsetSrc = 0;
- int byteOffsetDest = 0;
- int bitOffsetDest = 0;
- int code = 0;
- int nbrBits = 0;
- /* nbr of bytes per row */
- int rowSize;
-
-public int decode(byte[] src, byte[] dest, int offsetDest, int rowSize, int nRows) {
- this.src = src;
- this.dest = dest;
- this.rowSize = rowSize;
- byteOffsetSrc = 0;
- bitOffsetSrc = 0;
- byteOffsetDest = offsetDest;
- bitOffsetDest = 0;
- int cnt = 0;
- while (cnt < nRows && decodeRow()) {
- cnt++;
- /* byte aligned */
- if (bitOffsetDest > 0) {
- byteOffsetDest++;
- bitOffsetDest = 0;
- }
- }
- return byteOffsetDest - offsetDest;
-}
-
-boolean decodeRow() {
- isWhite = true;
- int n = 0;
- while (n < rowSize) {
- int runLength = decodeRunLength();
- if (runLength < 0) return false;
- n += runLength;
- setNextBits(isWhite ? whiteValue : blackValue, runLength);
- isWhite = !isWhite;
- }
- return true;
-}
-
-int decodeRunLength() {
- int runLength = 0;
- int partialRun = 0;
- short[][][] huffmanCode = isWhite ? WHITE_CODE : BLACK_CODE;
- while (true) {
- boolean found = false;
- nbrBits = isWhite ? WHITE_MIN_BITS : BLACK_MIN_BITS;
- code = getNextBits(nbrBits);
- for (int i = 0; i < huffmanCode.length; i++) {
- for (int j = 0; j < huffmanCode[i].length; j++) {
- if (huffmanCode[i][j][0] == code) {
- found = true;
- partialRun = huffmanCode[i][j][1];
- if (partialRun == -1) {
- /* Stop when reaching final EOL on last byte */
- if (byteOffsetSrc == src.length - 1) return -1;
- /* Group 3 starts each row with an EOL - ignore it */
- } else {
- runLength += partialRun;
- if (partialRun < 64) return runLength;
- }
- break;
- }
- }
- if (found) break;
- code = code << 1 | getNextBit();
- }
- if (!found) SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
-}
-
-int getNextBit() {
- int value = (src[byteOffsetSrc] >>> (7 - bitOffsetSrc)) & 0x1;
- bitOffsetSrc++;
- if (bitOffsetSrc > 7) {
- byteOffsetSrc++;
- bitOffsetSrc = 0;
- }
- return value;
-}
-
-int getNextBits(int cnt) {
- int value = 0;
- for (int i = 0; i < cnt; i++) {
- value = value << 1 | getNextBit();
- }
- return value;
-}
-
-void setNextBits(int value, int cnt) {
- int n = cnt;
- while (bitOffsetDest > 0 && bitOffsetDest <= 7 && n > 0) {
- dest[byteOffsetDest] = value == 1 ?
- (byte)(dest[byteOffsetDest] | (1 << (7 - bitOffsetDest))) :
- (byte)(dest[byteOffsetDest] & ~(1 << (7 - bitOffsetDest)));
- n--;
- bitOffsetDest++;
- }
- if (bitOffsetDest == 8) {
- byteOffsetDest++;
- bitOffsetDest = 0;
- }
- while (n >= 8) {
- dest[byteOffsetDest++] = (byte) (value == 1 ? 0xFF : 0);
- n -= 8;
- }
- while (n > 0) {
- dest[byteOffsetDest] = value == 1 ?
- (byte)(dest[byteOffsetDest] | (1 << (7 - bitOffsetDest))) :
- (byte)(dest[byteOffsetDest] & ~(1 << (7 - bitOffsetDest)));
- n--;
- bitOffsetDest++;
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFRandomFileAccess.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFRandomFileAccess.java
deleted file mode 100644
index 8cc7e390f3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFRandomFileAccess.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-import java.io.*;
-
-final class TIFFRandomFileAccess {
-
- LEDataInputStream inputStream;
- int start, current, next;
- byte[][] buffers;
-
- static final int CHUNK_SIZE = 8192;
- static final int LIST_SIZE = 128;
-
-public TIFFRandomFileAccess(LEDataInputStream stream) {
- inputStream = stream;
- start = current = next = inputStream.getPosition();
- buffers = new byte[LIST_SIZE][];
-}
-
-void seek(int pos) throws IOException {
- if (pos == current) return;
- if (pos < start) throw new IOException();
- current = pos;
- if (current > next) {
- int n = current - next;
- /* store required bytes */
- int index = next / CHUNK_SIZE;
- int offset = next % CHUNK_SIZE;
- while (n > 0) {
- if (index >= buffers.length) {
- byte[][] oldBuffers = buffers;
- buffers = new byte[Math.max(index + 1, oldBuffers.length + LIST_SIZE)][];
- System.arraycopy(oldBuffers, 0, buffers, 0, oldBuffers.length);
- }
- if (buffers[index] == null) buffers[index] = new byte[CHUNK_SIZE];
- int cnt = inputStream.read(buffers[index], offset, Math.min(n, CHUNK_SIZE - offset));
- n -= cnt;
- next += cnt;
- index++;
- offset = 0;
- }
- }
-}
-
-void read(byte b[]) throws IOException {
- int size = b.length;
- int nCached = Math.min(size, next - current);
- int nMissing = size - next + current;
- int destNext = 0;
- if (nCached > 0) {
- /* Get cached bytes */
- int index = current / CHUNK_SIZE;
- int offset = current % CHUNK_SIZE;
- while (nCached > 0) {
- int cnt = Math.min(nCached, CHUNK_SIZE - offset);
- System.arraycopy(buffers[index], offset, b, destNext, cnt);
- nCached -= cnt;
- destNext += cnt;
- index++;
- offset = 0;
- }
- }
- if (nMissing > 0) {
- /* Read required bytes */
- int index = next / CHUNK_SIZE;
- int offset = next % CHUNK_SIZE;
- while (nMissing > 0) {
- if (index >= buffers.length) {
- byte[][] oldBuffers = buffers;
- buffers = new byte[Math.max(index, oldBuffers.length + LIST_SIZE)][];
- System.arraycopy(oldBuffers, 0, buffers, 0, oldBuffers.length);
- }
- if (buffers[index] == null) buffers[index] = new byte[CHUNK_SIZE];
- int cnt = inputStream.read(buffers[index], offset, Math.min(nMissing, CHUNK_SIZE - offset));
- System.arraycopy(buffers[index], offset, b, destNext, cnt);
- nMissing -= cnt;
- next += cnt;
- destNext += cnt;
- index++;
- offset = 0;
- }
- }
- current += size;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinBMPFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinBMPFileFormat.java
deleted file mode 100755
index 81d08aa7bf..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinBMPFileFormat.java
+++ /dev/null
@@ -1,690 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import java.io.*;
-
-public final class WinBMPFileFormat extends FileFormat {
- static final int BMPFileHeaderSize = 14;
- static final int BMPHeaderFixedSize = 40;
- int importantColors;
- Point pelsPerMeter = new Point(0, 0);
-
-/**
- * Compress numBytes bytes of image data from src, storing in dest
- * (starting at 0), using the technique specified by comp.
- * If last is true, this indicates the last line of the image.
- * Answer the size of the compressed data.
- */
-int compress(int comp, byte[] src, int srcOffset, int numBytes, byte[] dest, boolean last) {
- if (comp == 1) { // BMP_RLE8_COMPRESSION
- return compressRLE8Data(src, srcOffset, numBytes, dest, last);
- }
- if (comp == 2) { // BMP_RLE4_COMPRESSION
- return compressRLE4Data(src, srcOffset, numBytes, dest, last);
- }
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return 0;
-}
-int compressRLE4Data(byte[] src, int srcOffset, int numBytes, byte[] dest, boolean last) {
- int sp = srcOffset, end = srcOffset + numBytes, dp = 0;
- int size = 0, left, i, n;
- byte theByte;
- while (sp < end) {
- /* find two consecutive bytes that are the same in the next 128 */
- left = end - sp - 1;
- if (left > 127)
- left = 127;
- for (n = 0; n < left; n++) {
- if (src[sp + n] == src[sp + n + 1])
- break;
- }
- /* if there is only one more byte in the scan line, include it */
- if (n < 127 && n == left)
- n++;
- /* store the intervening data */
- switch (n) {
- case 0:
- break;
- case 1: /* handled separately because 0,2 is a command */
- dest[dp] = 2; dp++; /* 1 byte == 2 pixels */
- dest[dp] = src[sp];
- dp++; sp++;
- size += 2;
- break;
- default:
- dest[dp] = 0; dp++;
- dest[dp] = (byte)(n + n); dp++; /* n bytes = n*2 pixels */
- for (i = n; i > 0; i--) {
- dest[dp] = src[sp];
- dp++; sp++;
- }
- size += 2 + n;
- if ((n & 1) != 0) { /* pad to word */
- dest[dp] = 0;
- dp++;
- size++;
- }
- break;
- }
- /* find the length of the next run (up to 127) and store it */
- left = end - sp;
- if (left > 0) {
- if (left > 127)
- left = 127;
- theByte = src[sp];
- for (n = 1; n < left; n++) {
- if (src[sp + n] != theByte)
- break;
- }
- dest[dp] = (byte)(n + n); dp++; /* n bytes = n*2 pixels */
- dest[dp] = theByte; dp++;
- sp += n;
- size += 2;
- }
- }
-
- /* store the end of line or end of bitmap codes */
- dest[dp] = 0; dp++;
- if (last) {
- dest[dp] = 1; dp++;
- } else {
- dest[dp] = 0; dp++;
- }
- size += 2;
-
- return size;
-}
-int compressRLE8Data(byte[] src, int srcOffset, int numBytes, byte[] dest, boolean last) {
- int sp = srcOffset, end = srcOffset + numBytes, dp = 0;
- int size = 0, left, i, n;
- byte theByte;
- while (sp < end) {
- /* find two consecutive bytes that are the same in the next 256 */
- left = end - sp - 1;
- if (left > 254)
- left = 254;
- for (n = 0; n < left; n++) {
- if (src[sp + n] == src[sp + n + 1])
- break;
- }
- /* if there is only one more byte in the scan line, include it */
- if (n == left)
- n++;
- /* store the intervening data */
- switch (n) {
- case 0:
- break;
- case 2: /* handled separately because 0,2 is a command */
- dest[dp] = 1; dp++;
- dest[dp] = src[sp];
- dp++; sp++;
- size += 2;
- /* don't break, fall through */
- case 1: /* handled separately because 0,1 is a command */
- dest[dp] = 1; dp++;
- dest[dp] = src[sp];
- dp++; sp++;
- size += 2;
- break;
- default:
- dest[dp] = 0; dp++;
- dest[dp] = (byte)n; dp++;
- for (i = n; i > 0; i--) {
- dest[dp] = src[sp];
- dp++; sp++;
- }
- size += 2 + n;
- if ((n & 1) != 0) { /* pad to word */
- dest[dp] = 0;
- dp++;
- size++;
- }
- break;
- }
- /* find the length of the next run (up to 255) and store it */
- left = end - sp;
- if (left > 0) {
- if (left > 255)
- left = 255;
- theByte = src[sp];
- for (n = 1; n < left; n++) {
- if (src[sp + n] != theByte)
- break;
- }
- dest[dp] = (byte)n; dp++;
- dest[dp] = theByte; dp++;
- sp += n;
- size += 2;
- }
- }
-
- /* store the end of line or end of bitmap codes */
- dest[dp] = 0; dp++;
- if (last) {
- dest[dp] = 1; dp++;
- } else {
- dest[dp] = 0; dp++;
- }
- size += 2;
-
- return size;
-}
-void decompressData(byte[] src, byte[] dest, int stride, int cmp) {
- if (cmp == 1) { // BMP_RLE8_COMPRESSION
- if (decompressRLE8Data(src, src.length, stride, dest, dest.length) <= 0)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return;
- }
- if (cmp == 2) { // BMP_RLE4_COMPRESSION
- if (decompressRLE4Data(src, src.length, stride, dest, dest.length) <= 0)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return;
- }
- SWT.error(SWT.ERROR_INVALID_IMAGE);
-}
-int decompressRLE4Data(byte[] src, int numBytes, int stride, byte[] dest, int destSize) {
- int sp = 0;
- int se = numBytes;
- int dp = 0;
- int de = destSize;
- int x = 0, y = 0;
- while (sp < se) {
- int len = src[sp] & 0xFF;
- sp++;
- if (len == 0) {
- len = src[sp] & 0xFF;
- sp++;
- switch (len) {
- case 0: /* end of line */
- y++;
- x = 0;
- dp = y * stride;
- if (dp > de)
- return -1;
- break;
- case 1: /* end of bitmap */
- return 1;
- case 2: /* delta */
- x += src[sp] & 0xFF;
- sp++;
- y += src[sp] & 0xFF;
- sp++;
- dp = y * stride + x / 2;
- if (dp > de)
- return -1;
- break;
- default: /* absolute mode run */
- if ((len & 1) != 0) /* odd run lengths not currently supported */
- return -1;
- x += len;
- len = len / 2;
- if (len > (se - sp))
- return -1;
- if (len > (de - dp))
- return -1;
- for (int i = 0; i < len; i++) {
- dest[dp] = src[sp];
- dp++;
- sp++;
- }
- if ((sp & 1) != 0)
- sp++; /* word align sp? */
- break;
- }
- } else {
- if ((len & 1) != 0)
- return -1;
- x += len;
- len = len / 2;
- byte theByte = src[sp];
- sp++;
- if (len > (de - dp))
- return -1;
- for (int i = 0; i < len; i++) {
- dest[dp] = theByte;
- dp++;
- }
- }
- }
- return 1;
-}
-int decompressRLE8Data(byte[] src, int numBytes, int stride, byte[] dest, int destSize) {
- int sp = 0;
- int se = numBytes;
- int dp = 0;
- int de = destSize;
- int x = 0, y = 0;
- while (sp < se) {
- int len = src[sp] & 0xFF;
- sp++;
- if (len == 0) {
- len = src[sp] & 0xFF;
- sp++;
- switch (len) {
- case 0: /* end of line */
- y++;
- x = 0;
- dp = y * stride;
- if (dp > de)
- return -1;
- break;
- case 1: /* end of bitmap */
- return 1;
- case 2: /* delta */
- x += src[sp] & 0xFF;
- sp++;
- y += src[sp] & 0xFF;
- sp++;
- dp = y * stride + x;
- if (dp > de)
- return -1;
- break;
- default: /* absolute mode run */
- if (len > (se - sp))
- return -1;
- if (len > (de - dp))
- return -1;
- for (int i = 0; i < len; i++) {
- dest[dp] = src[sp];
- dp++;
- sp++;
- }
- if ((sp & 1) != 0)
- sp++; /* word align sp? */
- x += len;
- break;
- }
- } else {
- byte theByte = src[sp];
- sp++;
- if (len > (de - dp))
- return -1;
- for (int i = 0; i < len; i++) {
- dest[dp] = theByte;
- dp++;
- }
- x += len;
- }
- }
- return 1;
-}
-boolean isFileFormat(LEDataInputStream stream) {
- try {
- byte[] header = new byte[18];
- stream.read(header);
- stream.unread(header);
- int infoHeaderSize = (header[14] & 0xFF) | ((header[15] & 0xFF) << 8) | ((header[16] & 0xFF) << 16) | ((header[17] & 0xFF) << 24);
- return header[0] == 0x42 && header[1] == 0x4D && infoHeaderSize >= BMPHeaderFixedSize;
- } catch (Exception e) {
- return false;
- }
-}
-byte[] loadData(byte[] infoHeader) {
- int width = (infoHeader[4] & 0xFF) | ((infoHeader[5] & 0xFF) << 8) | ((infoHeader[6] & 0xFF) << 16) | ((infoHeader[7] & 0xFF) << 24);
- int height = (infoHeader[8] & 0xFF) | ((infoHeader[9] & 0xFF) << 8) | ((infoHeader[10] & 0xFF) << 16) | ((infoHeader[11] & 0xFF) << 24);
- int bitCount = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8);
- int stride = (width * bitCount + 7) / 8;
- stride = (stride + 3) / 4 * 4; // Round up to 4 byte multiple
- byte[] data = loadData(infoHeader, stride);
- flipScanLines(data, stride, height);
- return data;
-}
-byte[] loadData(byte[] infoHeader, int stride) {
- int height = (infoHeader[8] & 0xFF) | ((infoHeader[9] & 0xFF) << 8) | ((infoHeader[10] & 0xFF) << 16) | ((infoHeader[11] & 0xFF) << 24);
- if (height < 0) height = -height;
- int dataSize = height * stride;
- byte[] data = new byte[dataSize];
- int cmp = (infoHeader[16] & 0xFF) | ((infoHeader[17] & 0xFF) << 8) | ((infoHeader[18] & 0xFF) << 16) | ((infoHeader[19] & 0xFF) << 24);
- if (cmp == 0 || cmp == 3) { // BMP_NO_COMPRESSION
- try {
- if (inputStream.read(data) != dataSize)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- } else {
- int compressedSize = (infoHeader[20] & 0xFF) | ((infoHeader[21] & 0xFF) << 8) | ((infoHeader[22] & 0xFF) << 16) | ((infoHeader[23] & 0xFF) << 24);
- byte[] compressed = new byte[compressedSize];
- try {
- if (inputStream.read(compressed) != compressedSize)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- decompressData(compressed, data, stride, cmp);
- }
- return data;
-}
-int[] loadFileHeader() {
- int[] header = new int[5];
- try {
- header[0] = inputStream.readShort();
- header[1] = inputStream.readInt();
- header[2] = inputStream.readShort();
- header[3] = inputStream.readShort();
- header[4] = inputStream.readInt();
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- if (header[0] != 0x4D42)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return header;
-}
-ImageData[] loadFromByteStream() {
- int[] fileHeader = loadFileHeader();
- byte[] infoHeader = new byte[BMPHeaderFixedSize];
- try {
- inputStream.read(infoHeader);
- } catch (Exception e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- int width = (infoHeader[4] & 0xFF) | ((infoHeader[5] & 0xFF) << 8) | ((infoHeader[6] & 0xFF) << 16) | ((infoHeader[7] & 0xFF) << 24);
- int height = (infoHeader[8] & 0xFF) | ((infoHeader[9] & 0xFF) << 8) | ((infoHeader[10] & 0xFF) << 16) | ((infoHeader[11] & 0xFF) << 24);
- if (height < 0) height = -height;
- int bitCount = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8);
- this.compression = (infoHeader[16] & 0xFF) | ((infoHeader[17] & 0xFF) << 8) | ((infoHeader[18] & 0xFF) << 16) | ((infoHeader[19] & 0xFF) << 24);
- PaletteData palette = loadPalette(infoHeader);
- if (inputStream.getPosition() < fileHeader[4]) {
- // Seek to the specified offset
- try {
- inputStream.skip(fileHeader[4] - inputStream.getPosition());
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
- byte[] data = loadData(infoHeader);
- this.importantColors = (infoHeader[36] & 0xFF) | ((infoHeader[37] & 0xFF) << 8) | ((infoHeader[38] & 0xFF) << 16) | ((infoHeader[39] & 0xFF) << 24);
- int xPelsPerMeter = (infoHeader[24] & 0xFF) | ((infoHeader[25] & 0xFF) << 8) | ((infoHeader[26] & 0xFF) << 16) | ((infoHeader[27] & 0xFF) << 24);
- int yPelsPerMeter = (infoHeader[28] & 0xFF) | ((infoHeader[29] & 0xFF) << 8) | ((infoHeader[30] & 0xFF) << 16) | ((infoHeader[31] & 0xFF) << 24);
- this.pelsPerMeter = new Point(xPelsPerMeter, yPelsPerMeter);
- int type = (this.compression == 1 /*BMP_RLE8_COMPRESSION*/) || (this.compression == 2 /*BMP_RLE4_COMPRESSION*/) ? SWT.IMAGE_BMP_RLE : SWT.IMAGE_BMP;
- return new ImageData[] {
- ImageData.internal_new(
- width,
- height,
- bitCount,
- palette,
- 4,
- data,
- 0,
- null,
- null,
- -1,
- -1,
- type,
- 0,
- 0,
- 0,
- 0)
- };
-}
-PaletteData loadPalette(byte[] infoHeader) {
- int depth = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8);
- if (depth <= 8) {
- int numColors = (infoHeader[32] & 0xFF) | ((infoHeader[33] & 0xFF) << 8) | ((infoHeader[34] & 0xFF) << 16) | ((infoHeader[35] & 0xFF) << 24);
- if (numColors == 0) {
- numColors = 1 << depth;
- } else {
- if (numColors > 256)
- numColors = 256;
- }
- byte[] buf = new byte[numColors * 4];
- try {
- if (inputStream.read(buf) != buf.length)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- return paletteFromBytes(buf, numColors);
- }
- if (depth == 16) {
- if (this.compression == 3) {
- try {
- return new PaletteData(inputStream.readInt(), inputStream.readInt(), inputStream.readInt());
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
- return new PaletteData(0x7C00, 0x3E0, 0x1F);
- }
- if (depth == 24) return new PaletteData(0xFF, 0xFF00, 0xFF0000);
- if (this.compression == 3) {
- try {
- return new PaletteData(inputStream.readInt(), inputStream.readInt(), inputStream.readInt());
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
- return new PaletteData(0xFF00, 0xFF0000, 0xFF000000);
-}
-PaletteData paletteFromBytes(byte[] bytes, int numColors) {
- int bytesOffset = 0;
- RGB[] colors = new RGB[numColors];
- for (int i = 0; i < numColors; i++) {
- colors[i] = new RGB(bytes[bytesOffset + 2] & 0xFF,
- bytes[bytesOffset + 1] & 0xFF,
- bytes[bytesOffset] & 0xFF);
- bytesOffset += 4;
- }
- return new PaletteData(colors);
-}
-/**
- * Answer a byte array containing the BMP representation of
- * the given device independent palette.
- */
-static byte[] paletteToBytes(PaletteData pal) {
- int n = pal.colors == null ? 0 : (pal.colors.length < 256 ? pal.colors.length : 256);
- byte[] bytes = new byte[n * 4];
- int offset = 0;
- for (int i = 0; i < n; i++) {
- RGB col = pal.colors[i];
- bytes[offset] = (byte)col.blue;
- bytes[offset + 1] = (byte)col.green;
- bytes[offset + 2] = (byte)col.red;
- offset += 4;
- }
- return bytes;
-}
-/**
- * Unload the given image's data into the given byte stream
- * using the given compression strategy.
- * Answer the number of bytes written.
- */
-int unloadData(ImageData image, OutputStream out, int comp) {
- int totalSize = 0;
- try {
- if (comp == 0)
- return unloadDataNoCompression(image, out);
- int bpl = (image.width * image.depth + 7) / 8;
- int bmpBpl = (bpl + 3) / 4 * 4; // BMP pads scanlines to multiples of 4 bytes
- int imageBpl = image.bytesPerLine;
- // Compression can actually take twice as much space, in worst case
- byte[] buf = new byte[bmpBpl * 2];
- int srcOffset = imageBpl * (image.height - 1); // Start at last line
- byte[] data = image.data;
- totalSize = 0;
- byte[] buf2 = new byte[32768];
- int buf2Offset = 0;
- for (int y = image.height - 1; y >= 0; y--) {
- int lineSize = compress(comp, data, srcOffset, bpl, buf, y == 0);
- if (buf2Offset + lineSize > buf2.length) {
- out.write(buf2, 0, buf2Offset);
- buf2Offset = 0;
- }
- System.arraycopy(buf, 0, buf2, buf2Offset, lineSize);
- buf2Offset += lineSize;
- totalSize += lineSize;
- srcOffset -= imageBpl;
- }
- if (buf2Offset > 0)
- out.write(buf2, 0, buf2Offset);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- return totalSize;
-}
-/**
- * Prepare the given image's data for unloading into a byte stream
- * using no compression strategy.
- * Answer the number of bytes written.
- */
-int unloadDataNoCompression(ImageData image, OutputStream out) {
- int bmpBpl = 0;
- try {
- int bpl = (image.width * image.depth + 7) / 8;
- bmpBpl = (bpl + 3) / 4 * 4; // BMP pads scanlines to multiples of 4 bytes
- int linesPerBuf = 32678 / bmpBpl;
- byte[] buf = new byte[linesPerBuf * bmpBpl];
- byte[] data = image.data;
- int imageBpl = image.bytesPerLine;
- int dataIndex = imageBpl * (image.height - 1); // Start at last line
- if (image.depth == 16) {
- for (int y = 0; y < image.height; y += linesPerBuf) {
- int count = image.height - y;
- if (linesPerBuf < count) count = linesPerBuf;
- int bufOffset = 0;
- for (int i = 0; i < count; i++) {
- for (int wIndex = 0; wIndex < bpl; wIndex += 2) {
- buf[bufOffset + wIndex + 1] = data[dataIndex + wIndex + 1];
- buf[bufOffset + wIndex] = data[dataIndex + wIndex];
- }
- bufOffset += bmpBpl;
- dataIndex -= imageBpl;
- }
- out.write(buf, 0, bufOffset);
- }
- } else {
- for (int y = 0; y < image.height; y += linesPerBuf) {
- int tmp = image.height - y;
- int count = tmp < linesPerBuf ? tmp : linesPerBuf;
- int bufOffset = 0;
- for (int i = 0; i < count; i++) {
- System.arraycopy(data, dataIndex, buf, bufOffset, bpl);
- bufOffset += bmpBpl;
- dataIndex -= imageBpl;
- }
- out.write(buf, 0, bufOffset);
- }
- }
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- return bmpBpl * image.height;
-}
-/**
- * Unload a DeviceIndependentImage using Windows .BMP format into the given
- * byte stream.
- */
-void unloadIntoByteStream(ImageLoader loader) {
- ImageData image = loader.data[0];
- byte[] rgbs;
- int numCols;
- if (!((image.depth == 1) || (image.depth == 4) || (image.depth == 8) ||
- (image.depth == 16) || (image.depth == 24) || (image.depth == 32)))
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- int comp = this.compression;
- if (!((comp == 0) || ((comp == 1) && (image.depth == 8)) ||
- ((comp == 2) && (image.depth == 4))))
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- PaletteData pal = image.palette;
- if ((image.depth == 16) || (image.depth == 24) || (image.depth == 32)) {
- if (!pal.isDirect)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- numCols = 0;
- rgbs = null;
- } else {
- if (pal.isDirect)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- numCols = pal.colors.length;
- rgbs = paletteToBytes(pal);
- }
- // Fill in file header, except for bfsize, which is done later.
- int headersSize = BMPFileHeaderSize + BMPHeaderFixedSize;
- int[] fileHeader = new int[5];
- fileHeader[0] = 0x4D42; // Signature
- fileHeader[1] = 0; // File size - filled in later
- fileHeader[2] = 0; // Reserved 1
- fileHeader[3] = 0; // Reserved 2
- fileHeader[4] = headersSize; // Offset to data
- if (rgbs != null) {
- fileHeader[4] += rgbs.length;
- }
-
- // Prepare data. This is done first so we don't have to try to rewind
- // the stream and fill in the details later.
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- unloadData(image, out, comp);
- byte[] data = out.toByteArray();
-
- // Calculate file size
- fileHeader[1] = fileHeader[4] + data.length;
-
- // Write the headers
- try {
- outputStream.writeShort(fileHeader[0]);
- outputStream.writeInt(fileHeader[1]);
- outputStream.writeShort(fileHeader[2]);
- outputStream.writeShort(fileHeader[3]);
- outputStream.writeInt(fileHeader[4]);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- try {
- outputStream.writeInt(BMPHeaderFixedSize);
- outputStream.writeInt(image.width);
- outputStream.writeInt(image.height);
- outputStream.writeShort(1);
- outputStream.writeShort((short)image.depth);
- outputStream.writeInt(comp);
- outputStream.writeInt(data.length);
- outputStream.writeInt(pelsPerMeter.x);
- outputStream.writeInt(pelsPerMeter.y);
- outputStream.writeInt(numCols);
- outputStream.writeInt(importantColors);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
-
- // Unload palette
- if (numCols > 0) {
- try {
- outputStream.write(rgbs);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
-
- // Unload the data
- try {
- outputStream.write(data);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
-}
-void flipScanLines(byte[] data, int stride, int height) {
- int i1 = 0;
- int i2 = (height - 1) * stride;
- for (int i = 0; i < height / 2; i++) {
- for (int index = 0; index < stride; index++) {
- byte b = data[index + i1];
- data[index + i1] = data[index + i2];
- data[index + i2] = b;
- }
- i1 += stride;
- i2 -= stride;
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java
deleted file mode 100755
index 3dbc5f51b3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java
+++ /dev/null
@@ -1,325 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal.image;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import java.io.*;
-
-public final class WinICOFileFormat extends FileFormat {
-
-byte[] bitInvertData(byte[] data, int startIndex, int endIndex) {
- // Destructively bit invert data in the given byte array.
- for (int i = startIndex; i < endIndex; i++) {
- data[i] = (byte)(255 - data[i - startIndex]);
- }
- return data;
-}
-
-static final byte[] convertPad(byte[] data, int width, int height, int depth, int pad, int newPad) {
- if (pad == newPad) return data;
- int stride = (width * depth + 7) / 8;
- int bpl = (stride + (pad - 1)) / pad * pad;
- int newBpl = (stride + (newPad - 1)) / newPad * newPad;
- byte[] newData = new byte[height * newBpl];
- int srcIndex = 0, destIndex = 0;
- for (int y = 0; y < height; y++) {
- System.arraycopy(data, srcIndex, newData, destIndex, newBpl);
- srcIndex += bpl;
- destIndex += newBpl;
- }
- return newData;
-}
-/**
- * Answer the size in bytes of the file representation of the given
- * icon
- */
-int iconSize(ImageData i) {
- int shapeDataStride = (i.width * i.depth + 31) / 32 * 4;
- int maskDataStride = (i.width + 31) / 32 * 4;
- int dataSize = (shapeDataStride + maskDataStride) * i.height;
- int paletteSize = i.palette.colors != null ? i.palette.colors.length * 4 : 0;
- return WinBMPFileFormat.BMPHeaderFixedSize + paletteSize + dataSize;
-}
-boolean isFileFormat(LEDataInputStream stream) {
- try {
- byte[] header = new byte[4];
- stream.read(header);
- stream.unread(header);
- return header[0] == 0 && header[1] == 0 && header[2] == 1 && header[3] == 0;
- } catch (Exception e) {
- return false;
- }
-}
-boolean isValidIcon(ImageData i) {
- switch (i.depth) {
- case 1:
- case 4:
- case 8:
- if (i.palette.isDirect) return false;
- int size = i.palette.colors.length;
- return size == 2 || size == 16 || size == 32 || size == 256;
- case 24:
- case 32:
- return i.palette.isDirect;
- }
- return false;
-}
-int loadFileHeader(LEDataInputStream byteStream) {
- int[] fileHeader = new int[3];
- try {
- fileHeader[0] = byteStream.readShort();
- fileHeader[1] = byteStream.readShort();
- fileHeader[2] = byteStream.readShort();
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- if ((fileHeader[0] != 0) || (fileHeader[1] != 1))
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- int numIcons = fileHeader[2];
- if (numIcons <= 0)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return numIcons;
-}
-int loadFileHeader(LEDataInputStream byteStream, boolean hasHeader) {
- int[] fileHeader = new int[3];
- try {
- if (hasHeader) {
- fileHeader[0] = byteStream.readShort();
- fileHeader[1] = byteStream.readShort();
- } else {
- fileHeader[0] = 0;
- fileHeader[1] = 1;
- }
- fileHeader[2] = byteStream.readShort();
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- if ((fileHeader[0] != 0) || (fileHeader[1] != 1))
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- int numIcons = fileHeader[2];
- if (numIcons <= 0)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return numIcons;
-}
-ImageData[] loadFromByteStream() {
- int numIcons = loadFileHeader(inputStream);
- int[][] headers = loadIconHeaders(numIcons);
- ImageData[] icons = new ImageData[headers.length];
- for (int i = 0; i < icons.length; i++) {
- icons[i] = loadIcon(headers[i]);
- }
- return icons;
-}
-/**
- * Load one icon from the byte stream.
- */
-ImageData loadIcon(int[] iconHeader) {
- byte[] infoHeader = loadInfoHeader(iconHeader);
- WinBMPFileFormat bmpFormat = new WinBMPFileFormat();
- bmpFormat.inputStream = inputStream;
- PaletteData palette = bmpFormat.loadPalette(infoHeader);
- byte[] shapeData = bmpFormat.loadData(infoHeader);
- int width = (infoHeader[4] & 0xFF) | ((infoHeader[5] & 0xFF) << 8) | ((infoHeader[6] & 0xFF) << 16) | ((infoHeader[7] & 0xFF) << 24);
- int height = (infoHeader[8] & 0xFF) | ((infoHeader[9] & 0xFF) << 8) | ((infoHeader[10] & 0xFF) << 16) | ((infoHeader[11] & 0xFF) << 24);
- if (height < 0) height = -height;
- int depth = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8);
- infoHeader[14] = 1;
- infoHeader[15] = 0;
- byte[] maskData = bmpFormat.loadData(infoHeader);
- maskData = convertPad(maskData, width, height, 1, 4, 2);
- bitInvertData(maskData, 0, maskData.length);
- return ImageData.internal_new(
- width,
- height,
- depth,
- palette,
- 4,
- shapeData,
- 2,
- maskData,
- null,
- -1,
- -1,
- SWT.IMAGE_ICO,
- 0,
- 0,
- 0,
- 0);
-}
-int[][] loadIconHeaders(int numIcons) {
- int[][] headers = new int[numIcons][7];
- try {
- for (int i = 0; i < numIcons; i++) {
- headers[i][0] = inputStream.read();
- headers[i][1] = inputStream.read();
- headers[i][2] = inputStream.readShort();
- headers[i][3] = inputStream.readShort();
- headers[i][4] = inputStream.readShort();
- headers[i][5] = inputStream.readInt();
- headers[i][6] = inputStream.readInt();
- }
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- return headers;
-}
-byte[] loadInfoHeader(int[] iconHeader) {
- int width = iconHeader[0];
- int height = iconHeader[1];
- int numColors = iconHeader[2]; // the number of colors is in the low byte, but the high byte must be 0
- if (numColors == 0) numColors = 256; // this is specified: '00' represents '256' (0x100) colors
- if ((numColors != 2) && (numColors != 8) && (numColors != 16) &&
- (numColors != 32) && (numColors != 256))
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- if (inputStream.getPosition() < iconHeader[6]) {
- // Seek to the specified offset
- try {
- inputStream.skip(iconHeader[6] - inputStream.getPosition());
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- return null;
- }
- }
- byte[] infoHeader = new byte[WinBMPFileFormat.BMPHeaderFixedSize];
- try {
- inputStream.read(infoHeader);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- if (((infoHeader[12] & 0xFF) | ((infoHeader[13] & 0xFF) << 8)) != 1)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- int infoWidth = (infoHeader[4] & 0xFF) | ((infoHeader[5] & 0xFF) << 8) | ((infoHeader[6] & 0xFF) << 16) | ((infoHeader[7] & 0xFF) << 24);
- int infoHeight = (infoHeader[8] & 0xFF) | ((infoHeader[9] & 0xFF) << 8) | ((infoHeader[10] & 0xFF) << 16) | ((infoHeader[11] & 0xFF) << 24);
- int bitCount = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8);
- if (height == infoHeight && bitCount == 1) height /= 2;
- if (!((width == infoWidth) && (height * 2 == infoHeight) &&
- (bitCount == 1 || bitCount == 4 || bitCount == 8 || bitCount == 24 || bitCount == 32)))
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- infoHeader[8] = (byte)(height & 0xFF);
- infoHeader[9] = (byte)((height >> 8) & 0xFF);
- infoHeader[10] = (byte)((height >> 16) & 0xFF);
- infoHeader[11] = (byte)((height >> 24) & 0xFF);
- return infoHeader;
-}
-/**
- * Unload a single icon
- */
-void unloadIcon(ImageData icon) {
- int sizeImage = (((icon.width * icon.depth + 31) / 32 * 4) +
- ((icon.width + 31) / 32 * 4)) * icon.height;
- try {
- outputStream.writeInt(WinBMPFileFormat.BMPHeaderFixedSize);
- outputStream.writeInt(icon.width);
- outputStream.writeInt(icon.height * 2);
- outputStream.writeShort(1);
- outputStream.writeShort((short)icon.depth);
- outputStream.writeInt(0);
- outputStream.writeInt(sizeImage);
- outputStream.writeInt(0);
- outputStream.writeInt(0);
- outputStream.writeInt(icon.palette.colors != null ? icon.palette.colors.length : 0);
- outputStream.writeInt(0);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
-
- byte[] rgbs = WinBMPFileFormat.paletteToBytes(icon.palette);
- try {
- outputStream.write(rgbs);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- unloadShapeData(icon);
- unloadMaskData(icon);
-}
-/**
- * Unload the icon header for the given icon, calculating the offset.
- */
-void unloadIconHeader(ImageData i) {
- int headerSize = 16;
- int offset = headerSize + 6;
- int iconSize = iconSize(i);
- try {
- outputStream.write(i.width);
- outputStream.write(i.height);
- outputStream.writeShort(i.palette.colors != null ? i.palette.colors.length : 0);
- outputStream.writeShort(0);
- outputStream.writeShort(0);
- outputStream.writeInt(iconSize);
- outputStream.writeInt(offset);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
-}
-void unloadIntoByteStream(ImageLoader loader) {
- /* We do not currently support writing multi-image ico,
- * so we use the first image data in the loader's array. */
- ImageData image = loader.data[0];
- if (!isValidIcon(image))
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- try {
- outputStream.writeShort(0);
- outputStream.writeShort(1);
- outputStream.writeShort(1);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- unloadIconHeader(image);
- unloadIcon(image);
-}
-/**
- * Unload the mask data for an icon. The data is flipped vertically
- * and inverted.
- */
-void unloadMaskData(ImageData icon) {
- ImageData mask = icon.getTransparencyMask();
- int bpl = (icon.width + 7) / 8;
- int pad = mask.scanlinePad;
- int srcBpl = (bpl + pad - 1) / pad * pad;
- int destBpl = (bpl + 3) / 4 * 4;
- byte[] buf = new byte[destBpl];
- int offset = (icon.height - 1) * srcBpl;
- byte[] data = mask.data;
- try {
- for (int i = 0; i < icon.height; i++) {
- System.arraycopy(data, offset, buf, 0, bpl);
- bitInvertData(buf, 0, bpl);
- outputStream.write(buf, 0, destBpl);
- offset -= srcBpl;
- }
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
-}
-/**
- * Unload the shape data for an icon. The data is flipped vertically.
- */
-void unloadShapeData(ImageData icon) {
- int bpl = (icon.width * icon.depth + 7) / 8;
- int pad = icon.scanlinePad;
- int srcBpl = (bpl + pad - 1) / pad * pad;
- int destBpl = (bpl + 3) / 4 * 4;
- byte[] buf = new byte[destBpl];
- int offset = (icon.height - 1) * srcBpl;
- byte[] data = icon.data;
- try {
- for (int i = 0; i < icon.height; i++) {
- System.arraycopy(data, offset, buf, 0, bpl);
- outputStream.write(buf, 0, destBpl);
- offset -= srcBpl;
- }
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/package.html b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/package.html
deleted file mode 100755
index ab7efd4a18..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/package.html
+++ /dev/null
@@ -1,19 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-<html>
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <meta name="Author" content="IBM">
- <title>Package-level Javadoc</title>
-</head>
-<body>
-SWT internal image loading/saving support classes.
-<h2>
-Package Specification</h2>
-This package contains the classes used by SWT to load and save images
-in the various formats we support, including GIF, JPEG, PNG, BMP, and ICO.
-<p>
-Applications should not need to reference the classes in this package
-directly.
-</p>
-</body>
-</html>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/package.html b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/package.html
deleted file mode 100755
index d1b671ef87..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/package.html
+++ /dev/null
@@ -1,21 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-<html>
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <meta name="Author" content="IBM">
- <title>Package-level Javadoc</title>
-</head>
-<body>
-SWT internal classes
-<h2>
-Package Specification</h2>
-This package provides the <code>Callback</code> class which is used to
-map the operating system's callback mechanism to Java message sends, and
-the <code>Converter</code> class which provides translation between Unicode
-and platform specific character sets.
-<p>
-Applications should not need to reference the classes in this package
-directly.
-</p>
-</body>
-</html>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillData.java
deleted file mode 100644
index ef9de8ac9d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillData.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.layout;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-
-class FillData {
-
- int defaultWidth = -1, defaultHeight = -1;
- int currentWhint, currentHhint, currentWidth = -1, currentHeight = -1;
-
-Point computeSize (Control control, int wHint, int hHint, boolean flushCache) {
- if (flushCache) flushCache();
- if (wHint == SWT.DEFAULT && hHint == SWT.DEFAULT) {
- if (defaultWidth == -1 || defaultHeight == -1) {
- Point size = control.computeSize (wHint, hHint, flushCache);
- defaultWidth = size.x;
- defaultHeight = size.y;
- }
- return new Point(defaultWidth, defaultHeight);
- }
- if (currentWidth == -1 || currentHeight == -1 || wHint != currentWhint || hHint != currentHhint) {
- Point size = control.computeSize (wHint, hHint, flushCache);
- currentWhint = wHint;
- currentHhint = hHint;
- currentWidth = size.x;
- currentHeight = size.y;
- }
- return new Point(currentWidth, currentHeight);
-}
-void flushCache () {
- defaultWidth = defaultHeight = -1;
- currentWidth = currentHeight = -1;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java
deleted file mode 100755
index b2354723d3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java
+++ /dev/null
@@ -1,238 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.layout;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * <code>FillLayout</code> is the simplest layout class. It lays out
- * controls in a single row or column, forcing them to be the same size.
- * <p>
- * Initially, the controls will all be as tall as the tallest control,
- * and as wide as the widest. <code>FillLayout</code> does not wrap,
- * but you can specify margins and spacing. You might use it to
- * lay out buttons in a task bar or tool bar, or to stack checkboxes
- * in a <code>Group</code>. <code>FillLayout</code> can also be used
- * when a <code>Composite</code> only has one child. For example,
- * if a <code>Shell</code> has a single <code>Group</code> child,
- * <code>FillLayout</code> will cause the <code>Group</code> to
- * completely fill the <code>Shell</code> (if margins are 0).
- * </p>
- * <p>
- * Example code: first a <code>FillLayout</code> is created and
- * its type field is set, and then the layout is set into the
- * <code>Composite</code>. Note that in a <code>FillLayout</code>,
- * children are always the same size, and they fill all available space.
- * <pre>
- * FillLayout fillLayout = new FillLayout();
- * fillLayout.type = SWT.VERTICAL;
- * shell.setLayout(fillLayout);
- * </pre>
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: LayoutExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class FillLayout extends Layout {
- /**
- * type specifies how controls will be positioned
- * within the layout.
- *
- * The default value is HORIZONTAL.
- *
- * Possible values are: <ul>
- * <li>HORIZONTAL: Position the controls horizontally from left to right</li>
- * <li>VERTICAL: Position the controls vertically from top to bottom</li>
- * </ul>
- */
- public int type = SWT.HORIZONTAL;
-
- /**
- * marginWidth specifies the number of pixels of horizontal margin
- * that will be placed along the left and right edges of the layout.
- *
- * The default value is 0.
- *
- * @since 3.0
- */
- public int marginWidth = 0;
-
- /**
- * marginHeight specifies the number of pixels of vertical margin
- * that will be placed along the top and bottom edges of the layout.
- *
- * The default value is 0.
- *
- * @since 3.0
- */
- public int marginHeight = 0;
-
- /**
- * spacing specifies the number of pixels between the edge of one cell
- * and the edge of its neighbouring cell.
- *
- * The default value is 0.
- *
- * @since 3.0
- */
- public int spacing = 0;
-
-/**
- * Constructs a new instance of this class.
- */
-public FillLayout () {
-}
-
-/**
- * Constructs a new instance of this class given the type.
- *
- * @param type the type of fill layout
- *
- * @since 2.0
- */
-public FillLayout (int type) {
- this.type = type;
-}
-
-protected Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache) {
- Control [] children = composite.getChildren ();
- int count = children.length;
- int maxWidth = 0, maxHeight = 0;
- for (int i=0; i<count; i++) {
- Control child = children [i];
- int w = wHint, h = hHint;
- if (count > 0) {
- if (type == SWT.HORIZONTAL && wHint != SWT.DEFAULT) {
- w = Math.max (0, (wHint - (count - 1) * spacing) / count);
- }
- if (type == SWT.VERTICAL && hHint != SWT.DEFAULT) {
- h = Math.max (0, (hHint - (count - 1) * spacing) / count);
- }
- }
- Point size = computeChildSize (child, w, h, flushCache);
- maxWidth = Math.max (maxWidth, size.x);
- maxHeight = Math.max (maxHeight, size.y);
- }
- int width = 0, height = 0;
- if (type == SWT.HORIZONTAL) {
- width = count * maxWidth;
- if (count != 0) width += (count - 1) * spacing;
- height = maxHeight;
- } else {
- width = maxWidth;
- height = count * maxHeight;
- if (count != 0) height += (count - 1) * spacing;
- }
- width += marginWidth * 2;
- height += marginHeight * 2;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- return new Point (width, height);
-}
-
-Point computeChildSize (Control control, int wHint, int hHint, boolean flushCache) {
- FillData data = (FillData)control.getLayoutData ();
- if (data == null) {
- data = new FillData ();
- control.setLayoutData (data);
- }
- Point size = null;
- if (wHint == SWT.DEFAULT && hHint == SWT.DEFAULT) {
- size = data.computeSize (control, wHint, hHint, flushCache);
- } else {
- // TEMPORARY CODE
- int trimX, trimY;
- if (control instanceof Scrollable) {
- Rectangle rect = ((Scrollable) control).computeTrim (0, 0, 0, 0);
- trimX = rect.width;
- trimY = rect.height;
- } else {
- trimX = trimY = control.getBorderWidth () * 2;
- }
- int w = wHint == SWT.DEFAULT ? wHint : Math.max (0, wHint - trimX);
- int h = hHint == SWT.DEFAULT ? hHint : Math.max (0, hHint - trimY);
- size = data.computeSize (control, w, h, flushCache);
- }
- return size;
-}
-
-protected boolean flushCache (Control control) {
- Object data = control.getLayoutData();
- if (data != null) ((FillData)data).flushCache();
- return true;
-}
-
-String getName () {
- String string = getClass ().getName ();
- int index = string.lastIndexOf ('.');
- if (index == -1) return string;
- return string.substring (index + 1, string.length ());
-}
-
-protected void layout (Composite composite, boolean flushCache) {
- Rectangle rect = composite.getClientArea ();
- Control [] children = composite.getChildren ();
- int count = children.length;
- if (count == 0) return;
- int width = rect.width - marginWidth * 2;
- int height = rect.height - marginHeight * 2;
- if (type == SWT.HORIZONTAL) {
- width -= (count - 1) * spacing;
- int x = rect.x + marginWidth, extra = width % count;
- int y = rect.y + marginHeight, cellWidth = width / count;
- for (int i=0; i<count; i++) {
- Control child = children [i];
- int childWidth = cellWidth;
- if (i == 0) {
- childWidth += extra / 2;
- } else {
- if (i == count - 1) childWidth += (extra + 1) / 2;
- }
- child.setBounds (x, y, childWidth, height);
- x += childWidth + spacing;
- }
- } else {
- height -= (count - 1) * spacing;
- int x = rect.x + marginWidth, cellHeight = height / count;
- int y = rect.y + marginHeight, extra = height % count;
- for (int i=0; i<count; i++) {
- Control child = children [i];
- int childHeight = cellHeight;
- if (i == 0) {
- childHeight += extra / 2;
- } else {
- if (i == count - 1) childHeight += (extra + 1) / 2;
- }
- child.setBounds (x, y, width, childHeight);
- y += childHeight + spacing;
- }
- }
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the layout
- */
-public String toString () {
- String string = getName ()+" {";
- string += "type="+((type == SWT.VERTICAL) ? "SWT.VERTICAL" : "SWT.HORIZONTAL")+" ";
- if (marginWidth != 0) string += "marginWidth="+marginWidth+" ";
- if (marginHeight != 0) string += "marginHeight="+marginHeight+" ";
- if (spacing != 0) string += "spacing="+spacing+" ";
- string = string.trim();
- string += "}";
- return string;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormAttachment.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormAttachment.java
deleted file mode 100644
index d426a8a43e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormAttachment.java
+++ /dev/null
@@ -1,316 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.layout;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * Instances of this class are used to define the edges of a control
- * within a <code>FormLayout</code>.
- * <p>
- * <code>FormAttachments</code> are set into the top, bottom, left,
- * and right fields of the <code>FormData</code> for a control.
- * For example:
- * <pre>
- * FormData data = new FormData();
- * data.top = new FormAttachment(0,5);
- * data.bottom = new FormAttachment(100,-5);
- * data.left = new FormAttachment(0,5);
- * data.right = new FormAttachment(100,-5);
- * button.setLayoutData(data);
- * </pre>
- * </p>
- * <p>
- * A <code>FormAttachment</code> defines where to attach the side of
- * a control by using the equation, y = ax + b. The "a" term represents
- * a fraction of the parent composite's width (from the left) or height
- * (from the top). It can be defined using a numerator and denominator,
- * or just a percentage value. If a percentage is used, the denominator
- * is set to 100. The "b" term in the equation represents an offset, in
- * pixels, from the attachment position. For example:
- * <pre>
- * FormAttachment attach = new FormAttachment (20, -5);
- * </pre>
- * specifies that the side to which the <code>FormAttachment</code>
- * object belongs will lie at 20% of the parent composite, minus 5 pixels.
- * </p>
- * <p>
- * Control sides can also be attached to another control.
- * For example:
- * <pre>
- * FormAttachment attach = new FormAttachment (button, 10);
- * </pre>
- * specifies that the side to which the <code>FormAttachment</code>
- * object belongs will lie in the same position as the adjacent side of
- * the <code>button</code> control, plus 10 pixels. The control side can
- * also be attached to the opposite side of the specified control.
- * For example:
- * <pre>
- * FormData data = new FormData ();
- * data.left = new FormAttachment (button, 0, SWT.LEFT);
- * </pre>
- * specifies that the left side of the control will lie in the same position
- * as the left side of the <code>button</code> control. The control can also
- * be attached in a position that will center the control on the specified
- * control. For example:
- * <pre>
- * data.left = new FormAttachment (button, 0, SWT.CENTER);
- * </pre>
- * specifies that the left side of the control will be positioned so that it is
- * centered between the left and right sides of the <code>button</code> control.
- * If the alignment is not specified, the default is to attach to the adjacent side.
- * </p>
- *
- * @see FormLayout
- * @see FormData
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 2.0
- */
-public final class FormAttachment {
- /**
- * numerator specifies the numerator of the "a" term in the
- * equation, y = ax + b, which defines the attachment.
- */
- public int numerator;
-
- /**
- * denominator specifies the denominator of the "a" term in the
- * equation, y = ax + b, which defines the attachment.
- *
- * The default value is 100.
- */
- public int denominator = 100;
-
- /**
- * offset specifies the offset, in pixels, of the control side
- * from the attachment position.
- * If the offset is positive, then the control side is offset
- * to the right of or below the attachment position. If it is
- * negative, then the control side is offset to the left of or
- * above the attachment position.
- *
- * This is equivalent to the "b" term in the equation y = ax + b.
- * The default value is 0.
- */
- public int offset;
-
- /**
- * control specifies the control to which the control side is
- * attached.
- */
- public Control control;
-
- /**
- * alignment specifies the alignment of the control side that is
- * attached to a control.
- * <p>
- * For top and bottom attachments, TOP, BOTTOM and CENTER are used. For left
- * and right attachments, LEFT, RIGHT and CENTER are used. If any other case
- * occurs, the default will be used instead.
- * </p>
- *
- * <br>Possible values are: <ul>
- * <li>{@link SWT#TOP}: Attach the side to the top side of the specified control.</li>
- * <li>{@link SWT#BOTTOM}: Attach the side to the bottom side of the specified control.</li>
- * <li>{@link SWT#LEFT}: Attach the side to the left side of the specified control.</li>
- * <li>{@link SWT#RIGHT}: Attach the side to the right side of the specified control.</li>
- * <li>{@link SWT#CENTER}: Attach the side at a position which will center the control on the specified control.</li>
- * <li>{@link SWT#DEFAULT}: Attach the side to the adjacent side of the specified control.</li>
- * </ul>
- */
- public int alignment;
-
-/**
- * Constructs a new instance of this class.
- * Since no numerator, denominator or offset is specified,
- * the attachment is treated as a percentage of the form.
- * The numerator is zero, the denominator is 100 and the
- * offset is zero.
- *
- * @since 3.2
- */
-public FormAttachment () {
-}
-
-/**
- * Constructs a new instance of this class given a numerator
- * Since no denominator or offset is specified, the default
- * is to treat the numerator as a percentage of the form, with a
- * denominator of 100. The offset is zero.
- *
- * @param numerator the percentage of the position
- *
- * @since 3.0
- */
-public FormAttachment (int numerator) {
- this (numerator, 100, 0);
-}
-
-/**
- * Constructs a new instance of this class given a numerator
- * and an offset. Since no denominator is specified, the default
- * is to treat the numerator as a percentage of the form, with a
- * denominator of 100.
- *
- * @param numerator the percentage of the position
- * @param offset the offset of the side from the position
- */
-public FormAttachment (int numerator, int offset) {
- this (numerator, 100, offset);
-}
-
-/**
- * Constructs a new instance of this class given a numerator
- * and denominator and an offset. The position of the side is
- * given by the fraction of the form defined by the numerator
- * and denominator.
- *
- * @param numerator the numerator of the position
- * @param denominator the denominator of the position
- * @param offset the offset of the side from the position
- */
-public FormAttachment (int numerator, int denominator, int offset) {
- if (denominator == 0) SWT.error (SWT.ERROR_CANNOT_BE_ZERO);
- this.numerator = numerator;
- this.denominator = denominator;
- this.offset = offset;
-}
-
-/**
- * Constructs a new instance of this class given a control.
- * Since no alignment is specified, the default alignment is
- * to attach the side to the adjacent side of the specified
- * control. Since no offset is specified, an offset of 0 is
- * used.
- *
- * @param control the control the side is attached to
- */
-public FormAttachment (Control control) {
- this (control, 0, SWT.DEFAULT);
-}
-
-/**
- * Constructs a new instance of this class given a control
- * and an offset. Since no alignment is specified, the default
- * alignment is to attach the side to the adjacent side of the
- * specified control.
- *
- * @param control the control the side is attached to
- * @param offset the offset of the side from the control
- */
-public FormAttachment (Control control, int offset) {
- this (control, offset, SWT.DEFAULT);
-}
-
-/**
- * Constructs a new instance of this class given a control,
- * an offset and an alignment. The possible alignment values are:
- * <dl>
- * <dt><b>{@link SWT#TOP}</b></dt>
- * <dd>the side will be attached to the top side of the specified control</dd>
- * <dt><b>{@link SWT#BOTTOM}</b></dt>
- * <dd>the side will be attached to the bottom side of the specified control</dd>
- * <dt><b>{@link SWT#LEFT}</b></dt>
- * <dd>the side will be attached to the left side of the specified control</dd>
- * <dt><b>{@link SWT#RIGHT}</b></dt>
- * <dd>the side will be attached to the right side of the specified control</dd>
- * <dt><b>{@link SWT#CENTER}</b></dt>
- * <dd>the side will be centered on the same side of the specified control</dd>
- * <dt><b>{@link SWT#DEFAULT}</b></dt>
- * <dd>the side will be attached to the adjacent side of the specified control</dd>
- * </dl>
- *
- * @param control the control the side is attached to
- * @param offset the offset of the side from the control
- * @param alignment the alignment of the side to the control it is attached to,
- * one of TOP, BOTTOM, LEFT, RIGHT, CENTER, or DEFAULT
- */
-public FormAttachment (Control control, int offset, int alignment) {
- this.control = control;
- this.offset = offset;
- this.alignment = alignment;
-}
-
-FormAttachment divide (int value) {
- return new FormAttachment (numerator, denominator * value, offset / value);
-}
-
-int gcd (int m, int n) {
- int temp;
- m = Math.abs (m);
- n = Math.abs (n);
- if (m < n) {
- temp = m;
- m = n;
- n = temp;
- }
- while (n != 0){
- temp = m;
- m = n;
- n = temp % n;
- }
- return m;
-}
-
-FormAttachment minus (FormAttachment attachment) {
- FormAttachment solution = new FormAttachment ();
- solution.numerator = numerator * attachment.denominator - denominator * attachment.numerator;
- solution.denominator = denominator * attachment.denominator;
- int gcd = gcd (solution.denominator, solution.numerator);
- solution.numerator = solution.numerator / gcd;
- solution.denominator = solution.denominator / gcd;
- solution.offset = offset - attachment.offset;
- return solution;
-}
-
-FormAttachment minus (int value) {
- return new FormAttachment (numerator, denominator, offset - value);
-}
-
-FormAttachment plus (FormAttachment attachment) {
- FormAttachment solution = new FormAttachment ();
- solution.numerator = numerator * attachment.denominator + denominator * attachment.numerator;
- solution.denominator = denominator * attachment.denominator;
- int gcd = gcd (solution.denominator, solution.numerator);
- solution.numerator = solution.numerator / gcd;
- solution.denominator = solution.denominator / gcd;
- solution.offset = offset + attachment.offset;
- return solution;
-}
-
-FormAttachment plus (int value) {
- return new FormAttachment (numerator, denominator, offset + value);
-}
-
-int solveX (int value) {
- if (denominator == 0) SWT.error (SWT.ERROR_CANNOT_BE_ZERO);
- return ((numerator * value) / denominator) + offset;
-}
-
-int solveY (int value) {
- if (numerator == 0) SWT.error (SWT.ERROR_CANNOT_BE_ZERO);
- return (value - offset) * denominator / numerator;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the FormAttachment
- */
-public String toString () {
- String string = control != null ? control.toString () : numerator + "/" + denominator;
- return "{y = (" + string + (offset >= 0 ? ")x + " + offset: ")x - " + (-offset))+"}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormData.java
deleted file mode 100644
index cd6939d093..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormData.java
+++ /dev/null
@@ -1,344 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.layout;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * Instances of this class are used to define the attachments
- * of a control in a <code>FormLayout</code>.
- * <p>
- * To set a <code>FormData</code> object into a control, you use the
- * <code>setLayoutData ()</code> method. To define attachments for the
- * <code>FormData</code>, set the fields directly, like this:
- * <pre>
- * FormData data = new FormData();
- * data.left = new FormAttachment(0,5);
- * data.right = new FormAttachment(100,-5);
- * button.setLayoutData(formData);
- * </pre>
- * </p>
- * <p>
- * <code>FormData</code> contains the <code>FormAttachments</code> for
- * each edge of the control that the <code>FormLayout</code> uses to
- * determine the size and position of the control. <code>FormData</code>
- * objects also allow you to set the width and height of controls within
- * a <code>FormLayout</code>.
- * </p>
- *
- * @see FormLayout
- * @see FormAttachment
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 2.0
- */
-public final class FormData {
- /**
- * width specifies the preferred width in pixels. This value
- * is the wHint passed into Control.computeSize(int, int, boolean)
- * to determine the preferred size of the control.
- *
- * The default value is SWT.DEFAULT.
- *
- * @see Control#computeSize(int, int, boolean)
- */
- public int width = SWT.DEFAULT;
- /**
- * height specifies the preferred height in pixels. This value
- * is the hHint passed into Control.computeSize(int, int, boolean)
- * to determine the preferred size of the control.
- *
- * The default value is SWT.DEFAULT.
- *
- * @see Control#computeSize(int, int, boolean)
- */
- public int height = SWT.DEFAULT;
- /**
- * left specifies the attachment of the left side of
- * the control.
- */
- public FormAttachment left;
- /**
- * right specifies the attachment of the right side of
- * the control.
- */
- public FormAttachment right;
- /**
- * top specifies the attachment of the top of the control.
- */
- public FormAttachment top;
- /**
- * bottom specifies the attachment of the bottom of the
- * control.
- */
- public FormAttachment bottom;
-
- int cacheWidth = -1, cacheHeight = -1;
- int defaultWhint, defaultHhint, defaultWidth = -1, defaultHeight = -1;
- int currentWhint, currentHhint, currentWidth = -1, currentHeight = -1;
- FormAttachment cacheLeft, cacheRight, cacheTop, cacheBottom;
- boolean isVisited, needed;
-
-/**
- * Constructs a new instance of FormData using
- * default values.
- */
-public FormData () {
-}
-
-/**
- * Constructs a new instance of FormData according to the parameters.
- * A value of SWT.DEFAULT indicates that no minimum width or
- * no minimum height is specified.
- *
- * @param width a minimum width for the control
- * @param height a minimum height for the control
- */
-public FormData (int width, int height) {
- this.width = width;
- this.height = height;
-}
-
-void computeSize (Control control, int wHint, int hHint, boolean flushCache) {
- if (cacheWidth != -1 && cacheHeight != -1) return;
- if (wHint == this.width && hHint == this.height) {
- if (defaultWidth == -1 || defaultHeight == -1 || wHint != defaultWhint || hHint != defaultHhint) {
- Point size = control.computeSize (wHint, hHint, flushCache);
- defaultWhint = wHint;
- defaultHhint = hHint;
- defaultWidth = size.x;
- defaultHeight = size.y;
- }
- cacheWidth = defaultWidth;
- cacheHeight = defaultHeight;
- return;
- }
- if (currentWidth == -1 || currentHeight == -1 || wHint != currentWhint || hHint != currentHhint) {
- Point size = control.computeSize (wHint, hHint, flushCache);
- currentWhint = wHint;
- currentHhint = hHint;
- currentWidth = size.x;
- currentHeight = size.y;
- }
- cacheWidth = currentWidth;
- cacheHeight = currentHeight;
-}
-
-void flushCache () {
- cacheWidth = cacheHeight = -1;
- defaultHeight = defaultWidth = -1;
- currentHeight = currentWidth = -1;
-}
-
-int getWidth (Control control, boolean flushCache) {
- needed = true;
- computeSize (control, width, height, flushCache);
- return cacheWidth;
-}
-
-int getHeight (Control control, boolean flushCache) {
- computeSize (control, width, height, flushCache);
- return cacheHeight;
-}
-
-FormAttachment getBottomAttachment (Control control, int spacing, boolean flushCache) {
- if (cacheBottom != null) return cacheBottom;
- if (isVisited) return cacheBottom = new FormAttachment (0, getHeight (control, flushCache));
- if (bottom == null) {
- if (top == null) return cacheBottom = new FormAttachment (0, getHeight (control, flushCache));
- return cacheBottom = getTopAttachment (control, spacing, flushCache).plus (getHeight (control, flushCache));
- }
- Control bottomControl = bottom.control;
- if (bottomControl != null) {
- if (bottomControl.isDisposed ()) {
- bottom.control = bottomControl = null;
- } else {
- if (bottomControl.getParent () != control.getParent ()) {
- bottomControl = null;
- }
- }
- }
- if (bottomControl == null) return cacheBottom = bottom;
- isVisited = true;
- FormData bottomData = (FormData) bottomControl.getLayoutData ();
- FormAttachment bottomAttachment = bottomData.getBottomAttachment (bottomControl, spacing, flushCache);
- switch (bottom.alignment) {
- case SWT.BOTTOM:
- cacheBottom = bottomAttachment.plus (bottom.offset);
- break;
- case SWT.CENTER: {
- FormAttachment topAttachment = bottomData.getTopAttachment (bottomControl, spacing, flushCache);
- FormAttachment bottomHeight = bottomAttachment.minus (topAttachment);
- cacheBottom = bottomAttachment.minus (bottomHeight.minus (getHeight (control, flushCache)).divide (2));
- break;
- }
- default: {
- FormAttachment topAttachment = bottomData.getTopAttachment (bottomControl, spacing, flushCache);
- cacheBottom = topAttachment.plus (bottom.offset - spacing);
- break;
- }
- }
- isVisited = false;
- return cacheBottom;
-}
-
-FormAttachment getLeftAttachment (Control control, int spacing, boolean flushCache) {
- if (cacheLeft != null) return cacheLeft;
- if (isVisited) return cacheLeft = new FormAttachment (0, 0);
- if (left == null) {
- if (right == null) return cacheLeft = new FormAttachment (0, 0);
- return cacheLeft = getRightAttachment (control, spacing, flushCache).minus (getWidth (control, flushCache));
- }
- Control leftControl = left.control;
- if (leftControl != null) {
- if (leftControl.isDisposed ()) {
- left.control = leftControl = null;
- } else {
- if (leftControl.getParent () != control.getParent ()) {
- leftControl = null;
- }
- }
- }
- if (leftControl == null) return cacheLeft = left;
- isVisited = true;
- FormData leftData = (FormData) leftControl.getLayoutData ();
- FormAttachment leftAttachment = leftData.getLeftAttachment (leftControl, spacing, flushCache);
- switch (left.alignment) {
- case SWT.LEFT:
- cacheLeft = leftAttachment.plus (left.offset);
- break;
- case SWT.CENTER: {
- FormAttachment rightAttachment = leftData.getRightAttachment (leftControl, spacing, flushCache);
- FormAttachment leftWidth = rightAttachment.minus (leftAttachment);
- cacheLeft = leftAttachment.plus (leftWidth.minus (getWidth (control, flushCache)).divide (2));
- break;
- }
- default: {
- FormAttachment rightAttachment = leftData.getRightAttachment (leftControl, spacing, flushCache);
- cacheLeft = rightAttachment.plus (left.offset + spacing);
- }
- }
- isVisited = false;
- return cacheLeft;
-}
-
-String getName () {
- String string = getClass ().getName ();
- int index = string.lastIndexOf ('.');
- if (index == -1) return string;
- return string.substring (index + 1, string.length ());
-}
-
-FormAttachment getRightAttachment (Control control, int spacing, boolean flushCache) {
- if (cacheRight != null) return cacheRight;
- if (isVisited) return cacheRight = new FormAttachment (0, getWidth (control, flushCache));
- if (right == null) {
- if (left == null) return cacheRight = new FormAttachment (0, getWidth (control, flushCache));
- return cacheRight = getLeftAttachment (control, spacing, flushCache).plus (getWidth (control, flushCache));
- }
- Control rightControl = right.control;
- if (rightControl != null) {
- if (rightControl.isDisposed ()) {
- right.control = rightControl = null;
- } else {
- if (rightControl.getParent () != control.getParent ()) {
- rightControl = null;
- }
- }
- }
- if (rightControl == null) return cacheRight = right;
- isVisited = true;
- FormData rightData = (FormData) rightControl.getLayoutData ();
- FormAttachment rightAttachment = rightData.getRightAttachment (rightControl, spacing, flushCache);
- switch (right.alignment) {
- case SWT.RIGHT:
- cacheRight = rightAttachment.plus (right.offset);
- break;
- case SWT.CENTER: {
- FormAttachment leftAttachment = rightData.getLeftAttachment (rightControl, spacing, flushCache);
- FormAttachment rightWidth = rightAttachment.minus (leftAttachment);
- cacheRight = rightAttachment.minus (rightWidth.minus (getWidth (control, flushCache)).divide (2));
- break;
- }
- default: {
- FormAttachment leftAttachment = rightData.getLeftAttachment (rightControl, spacing, flushCache);
- cacheRight = leftAttachment.plus (right.offset - spacing);
- break;
- }
- }
- isVisited = false;
- return cacheRight;
-}
-
-FormAttachment getTopAttachment (Control control, int spacing, boolean flushCache) {
- if (cacheTop != null) return cacheTop;
- if (isVisited) return cacheTop = new FormAttachment (0, 0);
- if (top == null) {
- if (bottom == null) return cacheTop = new FormAttachment (0, 0);
- return cacheTop = getBottomAttachment (control, spacing, flushCache).minus (getHeight (control, flushCache));
- }
- Control topControl = top.control;
- if (topControl != null) {
- if (topControl.isDisposed ()) {
- top.control = topControl = null;
- } else {
- if (topControl.getParent () != control.getParent ()) {
- topControl = null;
- }
- }
- }
- if (topControl == null) return cacheTop = top;
- isVisited = true;
- FormData topData = (FormData) topControl.getLayoutData ();
- FormAttachment topAttachment = topData.getTopAttachment (topControl, spacing, flushCache);
- switch (top.alignment) {
- case SWT.TOP:
- cacheTop = topAttachment.plus (top.offset);
- break;
- case SWT.CENTER: {
- FormAttachment bottomAttachment = topData.getBottomAttachment (topControl, spacing, flushCache);
- FormAttachment topHeight = bottomAttachment.minus (topAttachment);
- cacheTop = topAttachment.plus (topHeight.minus (getHeight (control, flushCache)).divide (2));
- break;
- }
- default: {
- FormAttachment bottomAttachment = topData.getBottomAttachment (topControl, spacing, flushCache);
- cacheTop = bottomAttachment.plus (top.offset + spacing);
- break;
- }
- }
- isVisited = false;
- return cacheTop;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the FormData object
- */
-public String toString () {
- String string = getName()+" {";
- if (width != SWT.DEFAULT) string += "width="+width+" ";
- if (height != SWT.DEFAULT) string += "height="+height+" ";
- if (left != null) string += "left="+left+" ";
- if (right != null) string += "right="+right+" ";
- if (top != null) string += "top="+top+" ";
- if (bottom != null) string += "bottom="+bottom+" ";
- string = string.trim();
- string += "}";
- return string;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormLayout.java
deleted file mode 100644
index 8661996568..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormLayout.java
+++ /dev/null
@@ -1,385 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.layout;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * Instances of this class control the position and size of the
- * children of a composite control by using <code>FormAttachments</code>
- * to optionally configure the left, top, right and bottom edges of
- * each child.
- * <p>
- * The following example code creates a <code>FormLayout</code> and then sets
- * it into a <code>Shell</code>:
- * <pre>
- * Display display = new Display ();
- * Shell shell = new Shell(display);
- * FormLayout layout = new FormLayout();
- * layout.marginWidth = 3;
- * layout.marginHeight = 3;
- * shell.setLayout(layout);
- * </pre>
- * </p>
- * <p>
- * To use a <code>FormLayout</code>, create a <code>FormData</code> with
- * <code>FormAttachment</code> for each child of <code>Composite</code>.
- * The following example code attaches <code>button1</code> to the top
- * and left edge of the composite and <code>button2</code> to the right
- * edge of <code>button1</code> and the top and right edges of the
- * composite:
- * <pre>
- * FormData data1 = new FormData();
- * data1.left = new FormAttachment(0, 0);
- * data1.top = new FormAttachment(0, 0);
- * button1.setLayoutData(data1);
- * FormData data2 = new FormData();
- * data2.left = new FormAttachment(button1);
- * data2.top = new FormAttachment(0, 0);
- * data2.right = new FormAttachment(100, 0);
- * button2.setLayoutData(data2);
- * </pre>
- * </p>
- * <p>
- * Each side of a child control can be attached to a position in the parent
- * composite, or to other controls within the <code>Composite</code> by
- * creating instances of <code>FormAttachment</code> and setting them into
- * the top, bottom, left, and right fields of the child's <code>FormData</code>.
- * </p>
- * <p>
- * If a side is not given an attachment, it is defined as not being attached
- * to anything, causing the child to remain at its preferred size. If a child
- * is given no attachment on either the left or the right or top or bottom, it is
- * automatically attached to the left and top of the composite respectively.
- * The following code positions <code>button1</code> and <code>button2</code>
- * but relies on default attachments:
- * <pre>
- * FormData data2 = new FormData();
- * data2.left = new FormAttachment(button1);
- * data2.right = new FormAttachment(100, 0);
- * button2.setLayoutData(data2);
- * </pre>
- * </p>
- * <p>
- * IMPORTANT: Do not define circular attachments. For example, do not attach
- * the right edge of <code>button1</code> to the left edge of <code>button2</code>
- * and then attach the left edge of <code>button2</code> to the right edge of
- * <code>button1</code>. This will over constrain the layout, causing undefined
- * behavior. The algorithm will terminate, but the results are undefined.
- * </p>
- *
- * @see FormData
- * @see FormAttachment
- * @see <a href="http://www.eclipse.org/swt/snippets/#formlayout">FormLayout snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: LayoutExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 2.0
- */
-public final class FormLayout extends Layout {
-
- /**
- * marginWidth specifies the number of pixels of horizontal margin
- * that will be placed along the left and right edges of the layout.
- *
- * The default value is 0.
- */
- public int marginWidth = 0;
-
- /**
- * marginHeight specifies the number of pixels of vertical margin
- * that will be placed along the top and bottom edges of the layout.
- *
- * The default value is 0.
- */
- public int marginHeight = 0;
-
-
- /**
- * marginLeft specifies the number of pixels of horizontal margin
- * that will be placed along the left edge of the layout.
- *
- * The default value is 0.
- *
- * @since 3.1
- */
- public int marginLeft = 0;
-
- /**
- * marginTop specifies the number of pixels of vertical margin
- * that will be placed along the top edge of the layout.
- *
- * The default value is 0.
- *
- * @since 3.1
- */
- public int marginTop = 0;
-
- /**
- * marginRight specifies the number of pixels of horizontal margin
- * that will be placed along the right edge of the layout.
- *
- * The default value is 0.
- *
- * @since 3.1
- */
- public int marginRight = 0;
-
- /**
- * marginBottom specifies the number of pixels of vertical margin
- * that will be placed along the bottom edge of the layout.
- *
- * The default value is 0.
- *
- * @since 3.1
- */
- public int marginBottom = 0;
-
- /**
- * spacing specifies the number of pixels between the edge of one control
- * and the edge of its neighbouring control.
- *
- * The default value is 0.
- *
- * @since 3.0
- */
- public int spacing = 0;
-
-/**
- * Constructs a new instance of this class.
- */
-public FormLayout () {
-}
-
-/*
- * Computes the preferred height of the form with
- * respect to the preferred height of the control.
- *
- * Given that the equations for top (T) and bottom (B)
- * of the control in terms of the height of the form (X)
- * are:
- * T = AX + B
- * B = CX + D
- *
- * The equation for the height of the control (H)
- * is bottom (B) minus top (T) or (H = B - T) or:
- *
- * H = (CX + D) - (AX + B)
- *
- * Solving for (X), the height of the form, we get:
- *
- * X = (H + B - D) / (C - A)
- *
- * When (A = C), (C - A = 0) and the equation has no
- * solution for X. This is a special case meaning that
- * the control does not constrain the height of the
- * form. In this case, we need to arbitrarily define
- * the height of the form (X):
- *
- * Case 1: A = C, A = 0, C = 0
- *
- * Let X = D, the distance from the top of the form
- * to the bottom edge of the control. In this case,
- * the control was attached to the top of the form
- * and the form needs to be large enough to show the
- * bottom edge of the control.
- *
- * Case 2: A = C, A = 1, C = 1
- *
- * Let X = -B, the distance from the bottom of the
- * form to the top edge of the control. In this case,
- * the control was attached to the bottom of the form
- * and the only way that the control would be visible
- * is if the offset is negative. If the offset is
- * positive, there is no possible height for the form
- * that will show the control as it will always be
- * below the bottom edge of the form.
- *
- * Case 3: A = C, A != 0, C != 0 and A != 1, C != 0
- *
- * Let X = D / (1 - C), the distance from the top of the
- * form to the bottom edge of the control. In this case,
- * since C is not 0 or 1, it must be a fraction, U / V.
- * The offset D is the distance from CX to the bottom edge
- * of the control. This represents a fraction of the form
- * (1 - C)X. Since the height of a fraction of the form is
- * known, the height of the entire form can be found by setting
- * (1 - C)X = D. We solve this equation for X in terms of U
- * and V, giving us X = (U * D) / (U - V). Similarly, if the
- * offset D is negative, the control is positioned above CX.
- * The offset -B is the distance from the top edge of the control
- * to CX. We can find the height of the entire form by setting
- * CX = -B. Solving in terms of U and V gives us X = (-B * V) / U.
- */
-int computeHeight (Control control, FormData data, boolean flushCache) {
- FormAttachment top = data.getTopAttachment (control, spacing, flushCache);
- FormAttachment bottom = data.getBottomAttachment (control, spacing, flushCache);
- FormAttachment height = bottom.minus (top);
- if (height.numerator == 0) {
- if (bottom.numerator == 0) return bottom.offset;
- if (bottom.numerator == bottom.denominator) return -top.offset;
- if (bottom.offset <= 0) {
- return -top.offset * top.denominator / bottom.numerator;
- }
- int divider = bottom.denominator - bottom.numerator;
- return bottom.denominator * bottom.offset / divider;
- }
- return height.solveY (data.getHeight (control, flushCache));
-}
-
-protected Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache) {
- Point size = layout (composite, false, 0, 0, wHint, hHint, flushCache);
- if (wHint != SWT.DEFAULT) size.x = wHint;
- if (hHint != SWT.DEFAULT) size.y = hHint;
- return size;
-}
-
-protected boolean flushCache (Control control) {
- Object data = control.getLayoutData ();
- if (data != null) ((FormData) data).flushCache ();
- return true;
-}
-
-String getName () {
- String string = getClass ().getName ();
- int index = string.lastIndexOf ('.');
- if (index == -1) return string;
- return string.substring (index + 1, string.length ());
-}
-
-/*
- * Computes the preferred height of the form with
- * respect to the preferred height of the control.
- */
-int computeWidth (Control control, FormData data, boolean flushCache) {
- FormAttachment left = data.getLeftAttachment (control, spacing, flushCache);
- FormAttachment right = data.getRightAttachment (control, spacing, flushCache);
- FormAttachment width = right.minus (left);
- if (width.numerator == 0) {
- if (right.numerator == 0) return right.offset;
- if (right.numerator == right.denominator) return -left.offset;
- if (right.offset <= 0) {
- return -left.offset * left.denominator / left.numerator;
- }
- int divider = right.denominator - right.numerator;
- return right.denominator * right.offset / divider;
- }
- return width.solveY (data.getWidth (control, flushCache));
-}
-
-protected void layout (Composite composite, boolean flushCache) {
- Rectangle rect = composite.getClientArea ();
- int x = rect.x + marginLeft + marginWidth;
- int y = rect.y + marginTop + marginHeight;
- int width = Math.max (0, rect.width - marginLeft - 2 * marginWidth - marginRight);
- int height = Math.max (0, rect.height - marginTop - 2 * marginHeight - marginBottom);
- layout (composite, true, x, y, width, height, flushCache);
-}
-
-Point layout (Composite composite, boolean move, int x, int y, int width, int height, boolean flushCache) {
- Control [] children = composite.getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- FormData data = (FormData) child.getLayoutData ();
- if (data == null) child.setLayoutData (data = new FormData ());
- if (flushCache) data.flushCache ();
- data.cacheLeft = data.cacheRight = data.cacheTop = data.cacheBottom = null;
- }
- boolean [] flush = null;
- Rectangle [] bounds = null;
- int w = 0, h = 0;
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- FormData data = (FormData) child.getLayoutData ();
- if (width != SWT.DEFAULT) {
- data.needed = false;
- FormAttachment left = data.getLeftAttachment (child, spacing, flushCache);
- FormAttachment right = data.getRightAttachment (child, spacing, flushCache);
- int x1 = left.solveX (width), x2 = right.solveX (width);
- if (data.height == SWT.DEFAULT && !data.needed) {
- int trim = 0;
- //TEMPORARY CODE
- if (child instanceof Scrollable) {
- Rectangle rect = ((Scrollable) child).computeTrim (0, 0, 0, 0);
- trim = rect.width;
- } else {
- trim = child.getBorderWidth () * 2;
- }
- data.cacheWidth = data.cacheHeight = -1;
- int currentWidth = Math.max (0, x2 - x1 - trim);
- data.computeSize (child, currentWidth, data.height, flushCache);
- if (flush == null) flush = new boolean [children.length];
- flush [i] = true;
- }
- w = Math.max (x2, w);
- if (move) {
- if (bounds == null) bounds = new Rectangle [children.length];
- bounds [i] = new Rectangle (0, 0, 0, 0);
- bounds [i].x = x + x1;
- bounds [i].width = x2 - x1;
- }
- } else {
- w = Math.max (computeWidth (child, data, flushCache), w);
- }
- }
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- FormData data = (FormData) child.getLayoutData ();
- if (height != SWT.DEFAULT) {
- int y1 = data.getTopAttachment (child, spacing, flushCache).solveX (height);
- int y2 = data.getBottomAttachment (child, spacing, flushCache).solveX (height);
- h = Math.max (y2, h);
- if (move) {
- bounds [i].y = y + y1;
- bounds [i].height = y2 - y1;
- }
- } else {
- h = Math.max (computeHeight (child, data, flushCache), h);
- }
- }
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- FormData data = (FormData) child.getLayoutData ();
- if (flush != null && flush [i]) data.cacheWidth = data.cacheHeight = -1;
- data.cacheLeft = data.cacheRight = data.cacheTop = data.cacheBottom = null;
- }
- if (move) {
- for (int i=0; i<children.length; i++) {
- children [i].setBounds (bounds [i]);
- }
- }
- w += marginLeft + marginWidth * 2 + marginRight;
- h += marginTop + marginHeight * 2 + marginBottom;
- return new Point (w, h);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the layout
- */
-public String toString () {
- String string = getName ()+" {";
- if (marginWidth != 0) string += "marginWidth="+marginWidth+" ";
- if (marginHeight != 0) string += "marginHeight="+marginHeight+" ";
- if (marginLeft != 0) string += "marginLeft="+marginLeft+" ";
- if (marginRight != 0) string += "marginRight="+marginRight+" ";
- if (marginTop != 0) string += "marginTop="+marginTop+" ";
- if (marginBottom != 0) string += "marginBottom="+marginBottom+" ";
- if (spacing != 0) string += "spacing="+spacing+" ";
- string = string.trim();
- string += "}";
- return string;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridData.java
deleted file mode 100755
index d26c60cf4c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridData.java
+++ /dev/null
@@ -1,566 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.layout;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * <code>GridData</code> is the layout data object associated with
- * <code>GridLayout</code>. To set a <code>GridData</code> object into a
- * control, you use the <code>Control.setLayoutData(Object)</code> method.
- * <p>
- * There are two ways to create a <code>GridData</code> object with certain
- * fields set. The first is to set the fields directly, like this:
- * <pre>
- * GridData gridData = new GridData();
- * gridData.horizontalAlignment = GridData.FILL;
- * gridData.grabExcessHorizontalSpace = true;
- * button1.setLayoutData(gridData);
- * </pre>
- * The second is to take advantage of convenience style bits defined
- * by <code>GridData</code>:
- * <pre>
- * button1.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
- * </pre>
- * </p>
- * <p>
- * NOTE: Do not reuse <code>GridData</code> objects. Every control in a
- * <code>Composite</code> that is managed by a <code>GridLayout</code>
- * must have a unique <code>GridData</code> object. If the layout data
- * for a control in a <code>GridLayout</code> is null at layout time,
- * a unique <code>GridData</code> object is created for it.
- * </p>
- *
- * @see GridLayout
- * @see Control#setLayoutData
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class GridData {
- /**
- * verticalAlignment specifies how controls will be positioned
- * vertically within a cell.
- *
- * The default value is CENTER.
- *
- * Possible values are: <ul>
- * <li>SWT.BEGINNING (or SWT.TOP): Position the control at the top of the cell</li>
- * <li>SWT.CENTER: Position the control in the vertical center of the cell</li>
- * <li>SWT.END (or SWT.BOTTOM): Position the control at the bottom of the cell</li>
- * <li>SWT.FILL: Resize the control to fill the cell vertically</li>
- * </ul>
- */
- public int verticalAlignment = CENTER;
-
- /**
- * horizontalAlignment specifies how controls will be positioned
- * horizontally within a cell.
- *
- * The default value is BEGINNING.
- *
- * Possible values are: <ul>
- * <li>SWT.BEGINNING (or SWT.LEFT): Position the control at the left of the cell</li>
- * <li>SWT.CENTER: Position the control in the horizontal center of the cell</li>
- * <li>SWT.END (or SWT.RIGHT): Position the control at the right of the cell</li>
- * <li>SWT.FILL: Resize the control to fill the cell horizontally</li>
- * </ul>
- */
- public int horizontalAlignment = BEGINNING;
-
- /**
- * widthHint specifies the preferred width in pixels. This value
- * is the wHint passed into Control.computeSize(int, int, boolean)
- * to determine the preferred size of the control.
- *
- * The default value is SWT.DEFAULT.
- *
- * @see Control#computeSize(int, int, boolean)
- */
- public int widthHint = SWT.DEFAULT;
-
- /**
- * heightHint specifies the preferred height in pixels. This value
- * is the hHint passed into Control.computeSize(int, int, boolean)
- * to determine the preferred size of the control.
- *
- * The default value is SWT.DEFAULT.
- *
- * @see Control#computeSize(int, int, boolean)
- */
- public int heightHint = SWT.DEFAULT;
-
- /**
- * horizontalIndent specifies the number of pixels of indentation
- * that will be placed along the left side of the cell.
- *
- * The default value is 0.
- */
- public int horizontalIndent = 0;
-
- /**
- * verticalIndent specifies the number of pixels of indentation
- * that will be placed along the top side of the cell.
- *
- * The default value is 0.
- *
- * @since 3.1
- */
- public int verticalIndent = 0;
-
- /**
- * horizontalSpan specifies the number of column cells that the control
- * will take up.
- *
- * The default value is 1.
- */
- public int horizontalSpan = 1;
-
- /**
- * verticalSpan specifies the number of row cells that the control
- * will take up.
- *
- * The default value is 1.
- */
- public int verticalSpan = 1;
-
- /**
- * <p>grabExcessHorizontalSpace specifies whether the width of the cell
- * changes depending on the size of the parent Composite. If
- * grabExcessHorizontalSpace is <code>true</code>, the following rules
- * apply to the width of the cell:</p>
- * <ul>
- * <li>If extra horizontal space is available in the parent, the cell will
- * grow to be wider than its preferred width. The new width
- * will be "preferred width + delta" where delta is the extra
- * horizontal space divided by the number of grabbing columns.</li>
- * <li>If there is not enough horizontal space available in the parent, the
- * cell will shrink until it reaches its minimum width as specified by
- * GridData.minimumWidth. The new width will be the maximum of
- * "minimumWidth" and "preferred width - delta", where delta is
- * the amount of space missing divided by the number of grabbing columns.</li>
- * <li>If the parent is packed, the cell will be its preferred width
- * as specified by GridData.widthHint.</li>
- * <li>If the control spans multiple columns and there are no other grabbing
- * controls in any of the spanned columns, the last column in the span will
- * grab the extra space. If there is at least one other grabbing control
- * in the span, the grabbing will be spread over the columns already
- * marked as grabExcessHorizontalSpace.</li>
- * </ul>
- *
- * <p>The default value is false.</p>
- *
- * @see GridData#minimumWidth
- * @see GridData#widthHint
- */
- public boolean grabExcessHorizontalSpace = false;
-
- /**
- * <p>grabExcessVerticalSpace specifies whether the height of the cell
- * changes depending on the size of the parent Composite. If
- * grabExcessVerticalSpace is <code>true</code>, the following rules
- * apply to the height of the cell:</p>
- * <ul>
- * <li>If extra vertical space is available in the parent, the cell will
- * grow to be taller than its preferred height. The new height
- * will be "preferred height + delta" where delta is the extra
- * vertical space divided by the number of grabbing rows.</li>
- * <li>If there is not enough vertical space available in the parent, the
- * cell will shrink until it reaches its minimum height as specified by
- * GridData.minimumHeight. The new height will be the maximum of
- * "minimumHeight" and "preferred height - delta", where delta is
- * the amount of space missing divided by the number of grabbing rows.</li>
- * <li>If the parent is packed, the cell will be its preferred height
- * as specified by GridData.heightHint.</li>
- * <li>If the control spans multiple rows and there are no other grabbing
- * controls in any of the spanned rows, the last row in the span will
- * grab the extra space. If there is at least one other grabbing control
- * in the span, the grabbing will be spread over the rows already
- * marked as grabExcessVerticalSpace.</li>
- * </ul>
- *
- * <p>The default value is false.</p>
- *
- * @see GridData#minimumHeight
- * @see GridData#heightHint
- */
- public boolean grabExcessVerticalSpace = false;
-
- /**
- * minimumWidth specifies the minimum width in pixels. This value
- * applies only if grabExcessHorizontalSpace is true. A value of
- * SWT.DEFAULT means that the minimum width will be the result
- * of Control.computeSize(int, int, boolean) where wHint is
- * determined by GridData.widthHint.
- *
- * The default value is 0.
- *
- * @since 3.1
- * @see Control#computeSize(int, int, boolean)
- * @see GridData#widthHint
- */
- public int minimumWidth = 0;
-
- /**
- * minimumHeight specifies the minimum height in pixels. This value
- * applies only if grabExcessVerticalSpace is true. A value of
- * SWT.DEFAULT means that the minimum height will be the result
- * of Control.computeSize(int, int, boolean) where hHint is
- * determined by GridData.heightHint.
- *
- * The default value is 0.
- *
- * @since 3.1
- * @see Control#computeSize(int, int, boolean)
- * @see GridData#heightHint
- */
- public int minimumHeight = 0;
-
- /**
- * exclude informs the layout to ignore this control when sizing
- * and positioning controls. If this value is <code>true</code>,
- * the size and position of the control will not be managed by the
- * layout. If this value is <code>false</code>, the size and
- * position of the control will be computed and assigned.
- *
- * The default value is <code>false</code>.
- *
- * @since 3.1
- */
- public boolean exclude = false;
-
- /**
- * Value for horizontalAlignment or verticalAlignment.
- * Position the control at the top or left of the cell.
- * Not recommended. Use SWT.BEGINNING, SWT.TOP or SWT.LEFT instead.
- */
- public static final int BEGINNING = SWT.BEGINNING;
-
- /**
- * Value for horizontalAlignment or verticalAlignment.
- * Position the control in the vertical or horizontal center of the cell
- * Not recommended. Use SWT.CENTER instead.
- */
- public static final int CENTER = 2;
-
- /**
- * Value for horizontalAlignment or verticalAlignment.
- * Position the control at the bottom or right of the cell
- * Not recommended. Use SWT.END, SWT.BOTTOM or SWT.RIGHT instead.
- */
- public static final int END = 3;
-
- /**
- * Value for horizontalAlignment or verticalAlignment.
- * Resize the control to fill the cell horizontally or vertically.
- * Not recommended. Use SWT.FILL instead.
- */
- public static final int FILL = SWT.FILL;
-
- /**
- * Style bit for <code>new GridData(int)</code>.
- * Position the control at the top of the cell.
- * Not recommended. Use
- * <code>new GridData(int, SWT.BEGINNING, boolean, boolean)</code>
- * instead.
- */
- public static final int VERTICAL_ALIGN_BEGINNING = 1 << 1;
-
- /**
- * Style bit for <code>new GridData(int)</code> to position the
- * control in the vertical center of the cell.
- * Not recommended. Use
- * <code>new GridData(int, SWT.CENTER, boolean, boolean)</code>
- * instead.
- */
- public static final int VERTICAL_ALIGN_CENTER = 1 << 2;
-
- /**
- * Style bit for <code>new GridData(int)</code> to position the
- * control at the bottom of the cell.
- * Not recommended. Use
- * <code>new GridData(int, SWT.END, boolean, boolean)</code>
- * instead.
- */
- public static final int VERTICAL_ALIGN_END = 1 << 3;
-
- /**
- * Style bit for <code>new GridData(int)</code> to resize the
- * control to fill the cell vertically.
- * Not recommended. Use
- * <code>new GridData(int, SWT.FILL, boolean, boolean)</code>
- * instead
- */
- public static final int VERTICAL_ALIGN_FILL = 1 << 4;
-
- /**
- * Style bit for <code>new GridData(int)</code> to position the
- * control at the left of the cell.
- * Not recommended. Use
- * <code>new GridData(SWT.BEGINNING, int, boolean, boolean)</code>
- * instead.
- */
- public static final int HORIZONTAL_ALIGN_BEGINNING = 1 << 5;
-
- /**
- * Style bit for <code>new GridData(int)</code> to position the
- * control in the horizontal center of the cell.
- * Not recommended. Use
- * <code>new GridData(SWT.CENTER, int, boolean, boolean)</code>
- * instead.
- */
- public static final int HORIZONTAL_ALIGN_CENTER = 1 << 6;
-
- /**
- * Style bit for <code>new GridData(int)</code> to position the
- * control at the right of the cell.
- * Not recommended. Use
- * <code>new GridData(SWT.END, int, boolean, boolean)</code>
- * instead.
- */
- public static final int HORIZONTAL_ALIGN_END = 1 << 7;
-
- /**
- * Style bit for <code>new GridData(int)</code> to resize the
- * control to fill the cell horizontally.
- * Not recommended. Use
- * <code>new GridData(SWT.FILL, int, boolean, boolean)</code>
- * instead.
- */
- public static final int HORIZONTAL_ALIGN_FILL = 1 << 8;
-
- /**
- * Style bit for <code>new GridData(int)</code> to resize the
- * control to fit the remaining horizontal space.
- * Not recommended. Use
- * <code>new GridData(int, int, true, boolean)</code>
- * instead.
- */
- public static final int GRAB_HORIZONTAL = 1 << 9;
-
- /**
- * Style bit for <code>new GridData(int)</code> to resize the
- * control to fit the remaining vertical space.
- * Not recommended. Use
- * <code>new GridData(int, int, boolean, true)</code>
- * instead.
- */
- public static final int GRAB_VERTICAL = 1 << 10;
-
- /**
- * Style bit for <code>new GridData(int)</code> to resize the
- * control to fill the cell vertically and to fit the remaining
- * vertical space.
- * FILL_VERTICAL = VERTICAL_ALIGN_FILL | GRAB_VERTICAL
- * Not recommended. Use
- * <code>new GridData(int, SWT.FILL, boolean, true)</code>
- * instead.
- */
- public static final int FILL_VERTICAL = VERTICAL_ALIGN_FILL | GRAB_VERTICAL;
-
- /**
- * Style bit for <code>new GridData(int)</code> to resize the
- * control to fill the cell horizontally and to fit the remaining
- * horizontal space.
- * FILL_HORIZONTAL = HORIZONTAL_ALIGN_FILL | GRAB_HORIZONTAL
- * Not recommended. Use
- * <code>new GridData(SWT.FILL, int, true, boolean)</code>
- * instead.
- */
- public static final int FILL_HORIZONTAL = HORIZONTAL_ALIGN_FILL | GRAB_HORIZONTAL;
-
- /**
- * Style bit for <code>new GridData(int)</code> to resize the
- * control to fill the cell horizontally and vertically and
- * to fit the remaining horizontal and vertical space.
- * FILL_BOTH = FILL_VERTICAL | FILL_HORIZONTAL
- * Not recommended. Use
- * <code>new GridData(SWT.FILL, SWT.FILL, true, true)</code>
- * instead.
- */
- public static final int FILL_BOTH = FILL_VERTICAL | FILL_HORIZONTAL;
-
- int cacheWidth = -1, cacheHeight = -1;
- int defaultWhint, defaultHhint, defaultWidth = -1, defaultHeight = -1;
- int currentWhint, currentHhint, currentWidth = -1, currentHeight = -1;
-
-/**
- * Constructs a new instance of GridData using
- * default values.
- */
-public GridData () {
- super ();
-}
-
-/**
- * Constructs a new instance based on the GridData style.
- * This constructor is not recommended.
- *
- * @param style the GridData style
- */
-public GridData (int style) {
- super ();
- if ((style & VERTICAL_ALIGN_BEGINNING) != 0) verticalAlignment = BEGINNING;
- if ((style & VERTICAL_ALIGN_CENTER) != 0) verticalAlignment = CENTER;
- if ((style & VERTICAL_ALIGN_FILL) != 0) verticalAlignment = FILL;
- if ((style & VERTICAL_ALIGN_END) != 0) verticalAlignment = END;
- if ((style & HORIZONTAL_ALIGN_BEGINNING) != 0) horizontalAlignment = BEGINNING;
- if ((style & HORIZONTAL_ALIGN_CENTER) != 0) horizontalAlignment = CENTER;
- if ((style & HORIZONTAL_ALIGN_FILL) != 0) horizontalAlignment = FILL;
- if ((style & HORIZONTAL_ALIGN_END) != 0) horizontalAlignment = END;
- grabExcessHorizontalSpace = (style & GRAB_HORIZONTAL) != 0;
- grabExcessVerticalSpace = (style & GRAB_VERTICAL) != 0;
-}
-
-/**
- * Constructs a new instance of GridData according to the parameters.
- *
- * @param horizontalAlignment how control will be positioned horizontally within a cell,
- * one of: SWT.BEGINNING (or SWT.LEFT), SWT.CENTER, SWT.END (or SWT.RIGHT), or SWT.FILL
- * @param verticalAlignment how control will be positioned vertically within a cell,
- * one of: SWT.BEGINNING (or SWT.TOP), SWT.CENTER, SWT.END (or SWT.BOTTOM), or SWT.FILL
- * @param grabExcessHorizontalSpace whether cell will be made wide enough to fit the remaining horizontal space
- * @param grabExcessVerticalSpace whether cell will be made high enough to fit the remaining vertical space
- *
- * @since 3.0
- */
-public GridData (int horizontalAlignment, int verticalAlignment, boolean grabExcessHorizontalSpace, boolean grabExcessVerticalSpace) {
- this (horizontalAlignment, verticalAlignment, grabExcessHorizontalSpace, grabExcessVerticalSpace, 1, 1);
-}
-
-/**
- * Constructs a new instance of GridData according to the parameters.
- *
- * @param horizontalAlignment how control will be positioned horizontally within a cell,
- * one of: SWT.BEGINNING (or SWT.LEFT), SWT.CENTER, SWT.END (or SWT.RIGHT), or SWT.FILL
- * @param verticalAlignment how control will be positioned vertically within a cell,
- * one of: SWT.BEGINNING (or SWT.TOP), SWT.CENTER, SWT.END (or SWT.BOTTOM), or SWT.FILL
- * @param grabExcessHorizontalSpace whether cell will be made wide enough to fit the remaining horizontal space
- * @param grabExcessVerticalSpace whether cell will be made high enough to fit the remaining vertical space
- * @param horizontalSpan the number of column cells that the control will take up
- * @param verticalSpan the number of row cells that the control will take up
- *
- * @since 3.0
- */
-public GridData (int horizontalAlignment, int verticalAlignment, boolean grabExcessHorizontalSpace, boolean grabExcessVerticalSpace, int horizontalSpan, int verticalSpan) {
- super ();
- this.horizontalAlignment = horizontalAlignment;
- this.verticalAlignment = verticalAlignment;
- this.grabExcessHorizontalSpace = grabExcessHorizontalSpace;
- this.grabExcessVerticalSpace = grabExcessVerticalSpace;
- this.horizontalSpan = horizontalSpan;
- this.verticalSpan = verticalSpan;
-}
-
-/**
- * Constructs a new instance of GridData according to the parameters.
- * A value of SWT.DEFAULT indicates that no minimum width or
- * no minimum height is specified.
- *
- * @param width a minimum width for the column
- * @param height a minimum height for the row
- *
- * @since 3.0
- */
-public GridData (int width, int height) {
- super ();
- this.widthHint = width;
- this.heightHint = height;
-}
-
-void computeSize (Control control, int wHint, int hHint, boolean flushCache) {
- if (cacheWidth != -1 && cacheHeight != -1) return;
- if (wHint == this.widthHint && hHint == this.heightHint) {
- if (defaultWidth == -1 || defaultHeight == -1 || wHint != defaultWhint || hHint != defaultHhint) {
- Point size = control.computeSize (wHint, hHint, flushCache);
- defaultWhint = wHint;
- defaultHhint = hHint;
- defaultWidth = size.x;
- defaultHeight = size.y;
- }
- cacheWidth = defaultWidth;
- cacheHeight = defaultHeight;
- return;
- }
- if (currentWidth == -1 || currentHeight == -1 || wHint != currentWhint || hHint != currentHhint) {
- Point size = control.computeSize (wHint, hHint, flushCache);
- currentWhint = wHint;
- currentHhint = hHint;
- currentWidth = size.x;
- currentHeight = size.y;
- }
- cacheWidth = currentWidth;
- cacheHeight = currentHeight;
-}
-
-void flushCache () {
- cacheWidth = cacheHeight = -1;
- defaultWidth = defaultHeight = -1;
- currentWidth = currentHeight = -1;
-}
-
-String getName () {
- String string = getClass ().getName ();
- int index = string.lastIndexOf ('.');
- if (index == -1) return string;
- return string.substring (index + 1, string.length ());
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the GridData object
- */
-public String toString () {
- String hAlign = "";
- switch (horizontalAlignment) {
- case SWT.FILL: hAlign = "SWT.FILL"; break;
- case SWT.BEGINNING: hAlign = "SWT.BEGINNING"; break;
- case SWT.LEFT: hAlign = "SWT.LEFT"; break;
- case SWT.END: hAlign = "SWT.END"; break;
- case END: hAlign = "GridData.END"; break;
- case SWT.RIGHT: hAlign = "SWT.RIGHT"; break;
- case SWT.CENTER: hAlign = "SWT.CENTER"; break;
- case CENTER: hAlign = "GridData.CENTER"; break;
- default: hAlign = "Undefined "+horizontalAlignment; break;
- }
- String vAlign = "";
- switch (verticalAlignment) {
- case SWT.FILL: vAlign = "SWT.FILL"; break;
- case SWT.BEGINNING: vAlign = "SWT.BEGINNING"; break;
- case SWT.TOP: vAlign = "SWT.TOP"; break;
- case SWT.END: vAlign = "SWT.END"; break;
- case END: vAlign = "GridData.END"; break;
- case SWT.BOTTOM: vAlign = "SWT.BOTTOM"; break;
- case SWT.CENTER: vAlign = "SWT.CENTER"; break;
- case CENTER: vAlign = "GridData.CENTER"; break;
- default: vAlign = "Undefined "+verticalAlignment; break;
- }
- String string = getName()+" {";
- string += "horizontalAlignment="+hAlign+" ";
- if (horizontalIndent != 0) string += "horizontalIndent="+horizontalIndent+" ";
- if (horizontalSpan != 1) string += "horizontalSpan="+horizontalSpan+" ";
- if (grabExcessHorizontalSpace) string += "grabExcessHorizontalSpace="+grabExcessHorizontalSpace+" ";
- if (widthHint != SWT.DEFAULT) string += "widthHint="+widthHint+" ";
- if (minimumWidth != 0) string += "minimumWidth="+minimumWidth+" ";
- string += "verticalAlignment="+vAlign+" ";
- if (verticalIndent != 0) string += "verticalIndent="+verticalIndent+" ";
- if (verticalSpan != 1) string += "verticalSpan="+verticalSpan+" ";
- if (grabExcessVerticalSpace) string += "grabExcessVerticalSpace="+grabExcessVerticalSpace+" ";
- if (heightHint != SWT.DEFAULT) string += "heightHint="+heightHint+" ";
- if (minimumHeight != 0) string += "minimumHeight="+minimumHeight+" ";
- if (exclude) string += "exclude="+exclude+" ";
- string = string.trim();
- string += "}";
- return string;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridLayout.java
deleted file mode 100755
index 2dd176361e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridLayout.java
+++ /dev/null
@@ -1,745 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.layout;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * Instances of this class lay out the control children of a
- * <code>Composite</code> in a grid.
- * <p>
- * <code>GridLayout</code> has a number of configuration fields, and the
- * controls it lays out can have an associated layout data object, called
- * <code>GridData</code>. The power of <code>GridLayout</code> lies in the
- * ability to configure <code>GridData</code> for each control in the layout.
- * </p>
- * <p>
- * The following code creates a shell managed by a <code>GridLayout</code>
- * with 3 columns:
- * <pre>
- * Display display = new Display();
- * Shell shell = new Shell(display);
- * GridLayout gridLayout = new GridLayout();
- * gridLayout.numColumns = 3;
- * shell.setLayout(gridLayout);
- * </pre>
- * The <code>numColumns</code> field is the most important field in a
- * <code>GridLayout</code>. Widgets are laid out in columns from left
- * to right, and a new row is created when <code>numColumns</code> + 1
- * controls are added to the <code>Composite<code>.
- * </p>
- *
- * @see GridData
- * @see <a href="http://www.eclipse.org/swt/snippets/#gridlayout">GridLayout snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: LayoutExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class GridLayout extends Layout {
-
- /**
- * numColumns specifies the number of cell columns in the layout.
- * If numColumns has a value less than 1, the layout will not
- * set the size and position of any controls.
- *
- * The default value is 1.
- */
- public int numColumns = 1;
-
- /**
- * makeColumnsEqualWidth specifies whether all columns in the layout
- * will be forced to have the same width.
- *
- * The default value is false.
- */
- public boolean makeColumnsEqualWidth = false;
-
- /**
- * marginWidth specifies the number of pixels of horizontal margin
- * that will be placed along the left and right edges of the layout.
- *
- * The default value is 5.
- */
- public int marginWidth = 5;
-
- /**
- * marginHeight specifies the number of pixels of vertical margin
- * that will be placed along the top and bottom edges of the layout.
- *
- * The default value is 5.
- */
- public int marginHeight = 5;
-
- /**
- * marginLeft specifies the number of pixels of horizontal margin
- * that will be placed along the left edge of the layout.
- *
- * The default value is 0.
- *
- * @since 3.1
- */
- public int marginLeft = 0;
-
- /**
- * marginTop specifies the number of pixels of vertical margin
- * that will be placed along the top edge of the layout.
- *
- * The default value is 0.
- *
- * @since 3.1
- */
- public int marginTop = 0;
-
- /**
- * marginRight specifies the number of pixels of horizontal margin
- * that will be placed along the right edge of the layout.
- *
- * The default value is 0.
- *
- * @since 3.1
- */
- public int marginRight = 0;
-
- /**
- * marginBottom specifies the number of pixels of vertical margin
- * that will be placed along the bottom edge of the layout.
- *
- * The default value is 0.
- *
- * @since 3.1
- */
- public int marginBottom = 0;
-
- /**
- * horizontalSpacing specifies the number of pixels between the right
- * edge of one cell and the left edge of its neighbouring cell to
- * the right.
- *
- * The default value is 5.
- */
- public int horizontalSpacing = 5;
-
- /**
- * verticalSpacing specifies the number of pixels between the bottom
- * edge of one cell and the top edge of its neighbouring cell underneath.
- *
- * The default value is 5.
- */
- public int verticalSpacing = 5;
-
-/**
- * Constructs a new instance of this class.
- */
-public GridLayout () {}
-
-/**
- * Constructs a new instance of this class given the
- * number of columns, and whether or not the columns
- * should be forced to have the same width.
- * If numColumns has a value less than 1, the layout will not
- * set the size and position of any controls.
- *
- * @param numColumns the number of columns in the grid
- * @param makeColumnsEqualWidth whether or not the columns will have equal width
- *
- * @since 2.0
- */
-public GridLayout (int numColumns, boolean makeColumnsEqualWidth) {
- this.numColumns = numColumns;
- this.makeColumnsEqualWidth = makeColumnsEqualWidth;
-}
-
-protected Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache) {
- Point size = layout (composite, false, 0, 0, wHint, hHint, flushCache);
- if (wHint != SWT.DEFAULT) size.x = wHint;
- if (hHint != SWT.DEFAULT) size.y = hHint;
- return size;
-}
-
-protected boolean flushCache (Control control) {
- Object data = control.getLayoutData ();
- if (data != null) ((GridData) data).flushCache ();
- return true;
-}
-
-GridData getData (Control [][] grid, int row, int column, int rowCount, int columnCount, boolean first) {
- Control control = grid [row] [column];
- if (control != null) {
- GridData data = (GridData) control.getLayoutData ();
- int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount));
- int vSpan = Math.max (1, data.verticalSpan);
- int i = first ? row + vSpan - 1 : row - vSpan + 1;
- int j = first ? column + hSpan - 1 : column - hSpan + 1;
- if (0 <= i && i < rowCount) {
- if (0 <= j && j < columnCount) {
- if (control == grid [i][j]) return data;
- }
- }
- }
- return null;
-}
-
-protected void layout (Composite composite, boolean flushCache) {
- Rectangle rect = composite.getClientArea ();
- layout (composite, true, rect.x, rect.y, rect.width, rect.height, flushCache);
-}
-
-Point layout (Composite composite, boolean move, int x, int y, int width, int height, boolean flushCache) {
- if (numColumns < 1) {
- return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom);
- }
- Control [] children = composite.getChildren ();
- int count = 0;
- for (int i=0; i<children.length; i++) {
- Control control = children [i];
- GridData data = (GridData) control.getLayoutData ();
- if (data == null || !data.exclude) {
- children [count++] = children [i];
- }
- }
- if (count == 0) {
- return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom);
- }
- for (int i=0; i<count; i++) {
- Control child = children [i];
- GridData data = (GridData) child.getLayoutData ();
- if (data == null) child.setLayoutData (data = new GridData ());
- if (flushCache) data.flushCache ();
- data.computeSize (child, data.widthHint, data.heightHint, flushCache);
- if (data.grabExcessHorizontalSpace && data.minimumWidth > 0) {
- if (data.cacheWidth < data.minimumWidth) {
- int trim = 0;
- //TEMPORARY CODE
- if (child instanceof Scrollable) {
- Rectangle rect = ((Scrollable) child).computeTrim (0, 0, 0, 0);
- trim = rect.width;
- } else {
- trim = child.getBorderWidth () * 2;
- }
- data.cacheWidth = data.cacheHeight = SWT.DEFAULT;
- data.computeSize (child, Math.max (0, data.minimumWidth - trim), data.heightHint, false);
- }
- }
- if (data.grabExcessVerticalSpace && data.minimumHeight > 0) {
- data.cacheHeight = Math.max (data.cacheHeight, data.minimumHeight);
- }
- }
-
- /* Build the grid */
- int row = 0, column = 0, rowCount = 0, columnCount = numColumns;
- Control [][] grid = new Control [4] [columnCount];
- for (int i=0; i<count; i++) {
- Control child = children [i];
- GridData data = (GridData) child.getLayoutData ();
- int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount));
- int vSpan = Math.max (1, data.verticalSpan);
- while (true) {
- int lastRow = row + vSpan;
- if (lastRow >= grid.length) {
- Control [][] newGrid = new Control [lastRow + 4] [columnCount];
- System.arraycopy (grid, 0, newGrid, 0, grid.length);
- grid = newGrid;
- }
- if (grid [row] == null) {
- grid [row] = new Control [columnCount];
- }
- while (column < columnCount && grid [row] [column] != null) {
- column++;
- }
- int endCount = column + hSpan;
- if (endCount <= columnCount) {
- int index = column;
- while (index < endCount && grid [row] [index] == null) {
- index++;
- }
- if (index == endCount) break;
- column = index;
- }
- if (column + hSpan >= columnCount) {
- column = 0;
- row++;
- }
- }
- for (int j=0; j<vSpan; j++) {
- if (grid [row + j] == null) {
- grid [row + j] = new Control [columnCount];
- }
- for (int k=0; k<hSpan; k++) {
- grid [row + j] [column + k] = child;
- }
- }
- rowCount = Math.max (rowCount, row + vSpan);
- column += hSpan;
- }
-
- /* Column widths */
- int availableWidth = width - horizontalSpacing * (columnCount - 1) - (marginLeft + marginWidth * 2 + marginRight);
- int expandCount = 0;
- int [] widths = new int [columnCount];
- int [] minWidths = new int [columnCount];
- boolean [] expandColumn = new boolean [columnCount];
- for (int j=0; j<columnCount; j++) {
- for (int i=0; i<rowCount; i++) {
- GridData data = getData (grid, i, j, rowCount, columnCount, true);
- if (data != null) {
- int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount));
- if (hSpan == 1) {
- int w = data.cacheWidth + data.horizontalIndent;
- widths [j] = Math.max (widths [j], w);
- if (data.grabExcessHorizontalSpace) {
- if (!expandColumn [j]) expandCount++;
- expandColumn [j] = true;
- }
- if (!data.grabExcessHorizontalSpace || data.minimumWidth != 0) {
- w = !data.grabExcessHorizontalSpace || data.minimumWidth == SWT.DEFAULT ? data.cacheWidth : data.minimumWidth;
- w += data.horizontalIndent;
- minWidths [j] = Math.max (minWidths [j], w);
- }
- }
- }
- }
- for (int i=0; i<rowCount; i++) {
- GridData data = getData (grid, i, j, rowCount, columnCount, false);
- if (data != null) {
- int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount));
- if (hSpan > 1) {
- int spanWidth = 0, spanMinWidth = 0, spanExpandCount = 0;
- for (int k=0; k<hSpan; k++) {
- spanWidth += widths [j-k];
- spanMinWidth += minWidths [j-k];
- if (expandColumn [j-k]) spanExpandCount++;
- }
- if (data.grabExcessHorizontalSpace && spanExpandCount == 0) {
- expandCount++;
- expandColumn [j] = true;
- }
- int w = data.cacheWidth + data.horizontalIndent - spanWidth - (hSpan - 1) * horizontalSpacing;
- if (w > 0) {
- if (makeColumnsEqualWidth) {
- int equalWidth = (w + spanWidth) / hSpan;
- int remainder = (w + spanWidth) % hSpan, last = -1;
- for (int k = 0; k < hSpan; k++) {
- widths [last=j-k] = Math.max (equalWidth, widths [j-k]);
- }
- if (last > -1) widths [last] += remainder;
- } else {
- if (spanExpandCount == 0) {
- widths [j] += w;
- } else {
- int delta = w / spanExpandCount;
- int remainder = w % spanExpandCount, last = -1;
- for (int k = 0; k < hSpan; k++) {
- if (expandColumn [j-k]) {
- widths [last=j-k] += delta;
- }
- }
- if (last > -1) widths [last] += remainder;
- }
- }
- }
- if (!data.grabExcessHorizontalSpace || data.minimumWidth != 0) {
- w = !data.grabExcessHorizontalSpace || data.minimumWidth == SWT.DEFAULT ? data.cacheWidth : data.minimumWidth;
- w += data.horizontalIndent - spanMinWidth - (hSpan - 1) * horizontalSpacing;
- if (w > 0) {
- if (spanExpandCount == 0) {
- minWidths [j] += w;
- } else {
- int delta = w / spanExpandCount;
- int remainder = w % spanExpandCount, last = -1;
- for (int k = 0; k < hSpan; k++) {
- if (expandColumn [j-k]) {
- minWidths [last=j-k] += delta;
- }
- }
- if (last > -1) minWidths [last] += remainder;
- }
- }
- }
- }
- }
- }
- }
- if (makeColumnsEqualWidth) {
- int minColumnWidth = 0;
- int columnWidth = 0;
- for (int i=0; i<columnCount; i++) {
- minColumnWidth = Math.max (minColumnWidth, minWidths [i]);
- columnWidth = Math.max (columnWidth, widths [i]);
- }
- columnWidth = width == SWT.DEFAULT || expandCount == 0 ? columnWidth : Math.max (minColumnWidth, availableWidth / columnCount);
- for (int i=0; i<columnCount; i++) {
- expandColumn [i] = expandCount > 0;
- widths [i] = columnWidth;
- }
- } else {
- if (width != SWT.DEFAULT && expandCount > 0) {
- int totalWidth = 0;
- for (int i=0; i<columnCount; i++) {
- totalWidth += widths [i];
- }
- int c = expandCount;
- int delta = (availableWidth - totalWidth) / c;
- int remainder = (availableWidth - totalWidth) % c;
- int last = -1;
- while (totalWidth != availableWidth) {
- for (int j=0; j<columnCount; j++) {
- if (expandColumn [j]) {
- if (widths [j] + delta > minWidths [j]) {
- widths [last = j] = widths [j] + delta;
- } else {
- widths [j] = minWidths [j];
- expandColumn [j] = false;
- c--;
- }
- }
- }
- if (last > -1) widths [last] += remainder;
-
- for (int j=0; j<columnCount; j++) {
- for (int i=0; i<rowCount; i++) {
- GridData data = getData (grid, i, j, rowCount, columnCount, false);
- if (data != null) {
- int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount));
- if (hSpan > 1) {
- if (!data.grabExcessHorizontalSpace || data.minimumWidth != 0) {
- int spanWidth = 0, spanExpandCount = 0;
- for (int k=0; k<hSpan; k++) {
- spanWidth += widths [j-k];
- if (expandColumn [j-k]) spanExpandCount++;
- }
- int w = !data.grabExcessHorizontalSpace || data.minimumWidth == SWT.DEFAULT ? data.cacheWidth : data.minimumWidth;
- w += data.horizontalIndent - spanWidth - (hSpan - 1) * horizontalSpacing;
- if (w > 0) {
- if (spanExpandCount == 0) {
- widths [j] += w;
- } else {
- int delta2 = w / spanExpandCount;
- int remainder2 = w % spanExpandCount, last2 = -1;
- for (int k = 0; k < hSpan; k++) {
- if (expandColumn [j-k]) {
- widths [last2=j-k] += delta2;
- }
- }
- if (last2 > -1) widths [last2] += remainder2;
- }
- }
- }
- }
- }
- }
- }
- if (c == 0) break;
- totalWidth = 0;
- for (int i=0; i<columnCount; i++) {
- totalWidth += widths [i];
- }
- delta = (availableWidth - totalWidth) / c;
- remainder = (availableWidth - totalWidth) % c;
- last = -1;
- }
- }
- }
-
- /* Wrapping */
- GridData [] flush = null;
- int flushLength = 0;
- if (width != SWT.DEFAULT) {
- for (int j=0; j<columnCount; j++) {
- for (int i=0; i<rowCount; i++) {
- GridData data = getData (grid, i, j, rowCount, columnCount, false);
- if (data != null) {
- if (data.heightHint == SWT.DEFAULT) {
- Control child = grid [i][j];
- //TEMPORARY CODE
- int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount));
- int currentWidth = 0;
- for (int k=0; k<hSpan; k++) {
- currentWidth += widths [j-k];
- }
- currentWidth += (hSpan - 1) * horizontalSpacing - data.horizontalIndent;
- if ((currentWidth != data.cacheWidth && data.horizontalAlignment == SWT.FILL) || (data.cacheWidth > currentWidth)) {
- int trim = 0;
- if (child instanceof Scrollable) {
- Rectangle rect = ((Scrollable) child).computeTrim (0, 0, 0, 0);
- trim = rect.width;
- } else {
- trim = child.getBorderWidth () * 2;
- }
- data.cacheWidth = data.cacheHeight = SWT.DEFAULT;
- data.computeSize (child, Math.max (0, currentWidth - trim), data.heightHint, false);
- if (data.grabExcessVerticalSpace && data.minimumHeight > 0) {
- data.cacheHeight = Math.max (data.cacheHeight, data.minimumHeight);
- }
- if (flush == null) flush = new GridData [count];
- flush [flushLength++] = data;
- }
- }
- }
- }
- }
- }
-
- /* Row heights */
- int availableHeight = height - verticalSpacing * (rowCount - 1) - (marginTop + marginHeight * 2 + marginBottom);
- expandCount = 0;
- int [] heights = new int [rowCount];
- int [] minHeights = new int [rowCount];
- boolean [] expandRow = new boolean [rowCount];
- for (int i=0; i<rowCount; i++) {
- for (int j=0; j<columnCount; j++) {
- GridData data = getData (grid, i, j, rowCount, columnCount, true);
- if (data != null) {
- int vSpan = Math.max (1, Math.min (data.verticalSpan, rowCount));
- if (vSpan == 1) {
- int h = data.cacheHeight + data.verticalIndent;
- heights [i] = Math.max (heights [i], h);
- if (data.grabExcessVerticalSpace) {
- if (!expandRow [i]) expandCount++;
- expandRow [i] = true;
- }
- if (!data.grabExcessVerticalSpace || data.minimumHeight != 0) {
- h = !data.grabExcessVerticalSpace || data.minimumHeight == SWT.DEFAULT ? data.cacheHeight : data.minimumHeight;
- h += data.verticalIndent;
- minHeights [i] = Math.max (minHeights [i], h);
- }
- }
- }
- }
- for (int j=0; j<columnCount; j++) {
- GridData data = getData (grid, i, j, rowCount, columnCount, false);
- if (data != null) {
- int vSpan = Math.max (1, Math.min (data.verticalSpan, rowCount));
- if (vSpan > 1) {
- int spanHeight = 0, spanMinHeight = 0, spanExpandCount = 0;
- for (int k=0; k<vSpan; k++) {
- spanHeight += heights [i-k];
- spanMinHeight += minHeights [i-k];
- if (expandRow [i-k]) spanExpandCount++;
- }
- if (data.grabExcessVerticalSpace && spanExpandCount == 0) {
- expandCount++;
- expandRow [i] = true;
- }
- int h = data.cacheHeight + data.verticalIndent - spanHeight - (vSpan - 1) * verticalSpacing;
- if (h > 0) {
- if (spanExpandCount == 0) {
- heights [i] += h;
- } else {
- int delta = h / spanExpandCount;
- int remainder = h % spanExpandCount, last = -1;
- for (int k = 0; k < vSpan; k++) {
- if (expandRow [i-k]) {
- heights [last=i-k] += delta;
- }
- }
- if (last > -1) heights [last] += remainder;
- }
- }
- if (!data.grabExcessVerticalSpace || data.minimumHeight != 0) {
- h = !data.grabExcessVerticalSpace || data.minimumHeight == SWT.DEFAULT ? data.cacheHeight : data.minimumHeight;
- h += data.verticalIndent - spanMinHeight - (vSpan - 1) * verticalSpacing;
- if (h > 0) {
- if (spanExpandCount == 0) {
- minHeights [i] += h;
- } else {
- int delta = h / spanExpandCount;
- int remainder = h % spanExpandCount, last = -1;
- for (int k = 0; k < vSpan; k++) {
- if (expandRow [i-k]) {
- minHeights [last=i-k] += delta;
- }
- }
- if (last > -1) minHeights [last] += remainder;
- }
- }
- }
- }
- }
- }
- }
- if (height != SWT.DEFAULT && expandCount > 0) {
- int totalHeight = 0;
- for (int i=0; i<rowCount; i++) {
- totalHeight += heights [i];
- }
- int c = expandCount;
- int delta = (availableHeight - totalHeight) / c;
- int remainder = (availableHeight - totalHeight) % c;
- int last = -1;
- while (totalHeight != availableHeight) {
- for (int i=0; i<rowCount; i++) {
- if (expandRow [i]) {
- if (heights [i] + delta > minHeights [i]) {
- heights [last = i] = heights [i] + delta;
- } else {
- heights [i] = minHeights [i];
- expandRow [i] = false;
- c--;
- }
- }
- }
- if (last > -1) heights [last] += remainder;
-
- for (int i=0; i<rowCount; i++) {
- for (int j=0; j<columnCount; j++) {
- GridData data = getData (grid, i, j, rowCount, columnCount, false);
- if (data != null) {
- int vSpan = Math.max (1, Math.min (data.verticalSpan, rowCount));
- if (vSpan > 1) {
- if (!data.grabExcessVerticalSpace || data.minimumHeight != 0) {
- int spanHeight = 0, spanExpandCount = 0;
- for (int k=0; k<vSpan; k++) {
- spanHeight += heights [i-k];
- if (expandRow [i-k]) spanExpandCount++;
- }
- int h = !data.grabExcessVerticalSpace || data.minimumHeight == SWT.DEFAULT ? data.cacheHeight : data.minimumHeight;
- h += data.verticalIndent - spanHeight - (vSpan - 1) * verticalSpacing;
- if (h > 0) {
- if (spanExpandCount == 0) {
- heights [i] += h;
- } else {
- int delta2 = h / spanExpandCount;
- int remainder2 = h % spanExpandCount, last2 = -1;
- for (int k = 0; k < vSpan; k++) {
- if (expandRow [i-k]) {
- heights [last2=i-k] += delta2;
- }
- }
- if (last2 > -1) heights [last2] += remainder2;
- }
- }
- }
- }
- }
- }
- }
- if (c == 0) break;
- totalHeight = 0;
- for (int i=0; i<rowCount; i++) {
- totalHeight += heights [i];
- }
- delta = (availableHeight - totalHeight) / c;
- remainder = (availableHeight - totalHeight) % c;
- last = -1;
- }
- }
-
- /* Position the controls */
- if (move) {
- int gridY = y + marginTop + marginHeight;
- for (int i=0; i<rowCount; i++) {
- int gridX = x + marginLeft + marginWidth;
- for (int j=0; j<columnCount; j++) {
- GridData data = getData (grid, i, j, rowCount, columnCount, true);
- if (data != null) {
- int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount));
- int vSpan = Math.max (1, data.verticalSpan);
- int cellWidth = 0, cellHeight = 0;
- for (int k=0; k<hSpan; k++) {
- cellWidth += widths [j+k];
- }
- for (int k=0; k<vSpan; k++) {
- cellHeight += heights [i+k];
- }
- cellWidth += horizontalSpacing * (hSpan - 1);
- int childX = gridX + data.horizontalIndent;
- int childWidth = Math.min (data.cacheWidth, cellWidth);
- switch (data.horizontalAlignment) {
- case SWT.CENTER:
- case GridData.CENTER:
- childX += Math.max (0, (cellWidth - data.horizontalIndent - childWidth) / 2);
- break;
- case SWT.RIGHT:
- case SWT.END:
- case GridData.END:
- childX += Math.max (0, cellWidth - data.horizontalIndent - childWidth);
- break;
- case SWT.FILL:
- childWidth = cellWidth - data.horizontalIndent;
- break;
- }
- cellHeight += verticalSpacing * (vSpan - 1);
- int childY = gridY + data.verticalIndent;
- int childHeight = Math.min (data.cacheHeight, cellHeight);
- switch (data.verticalAlignment) {
- case SWT.CENTER:
- case GridData.CENTER:
- childY += Math.max (0, (cellHeight - data.verticalIndent - childHeight) / 2);
- break;
- case SWT.BOTTOM:
- case SWT.END:
- case GridData.END:
- childY += Math.max (0, cellHeight - data.verticalIndent - childHeight);
- break;
- case SWT.FILL:
- childHeight = cellHeight - data.verticalIndent;
- break;
- }
- Control child = grid [i][j];
- if (child != null) {
- child.setBounds (childX, childY, childWidth, childHeight);
- }
- }
- gridX += widths [j] + horizontalSpacing;
- }
- gridY += heights [i] + verticalSpacing;
- }
- }
-
- // clean up cache
- for (int i = 0; i < flushLength; i++) {
- flush [i].cacheWidth = flush [i].cacheHeight = -1;
- }
-
- int totalDefaultWidth = 0;
- int totalDefaultHeight = 0;
- for (int i=0; i<columnCount; i++) {
- totalDefaultWidth += widths [i];
- }
- for (int i=0; i<rowCount; i++) {
- totalDefaultHeight += heights [i];
- }
- totalDefaultWidth += horizontalSpacing * (columnCount - 1) + marginLeft + marginWidth * 2 + marginRight;
- totalDefaultHeight += verticalSpacing * (rowCount - 1) + marginTop + marginHeight * 2 + marginBottom;
- return new Point (totalDefaultWidth, totalDefaultHeight);
-}
-
-String getName () {
- String string = getClass ().getName ();
- int index = string.lastIndexOf ('.');
- if (index == -1) return string;
- return string.substring (index + 1, string.length ());
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the layout
- */
-public String toString () {
- String string = getName ()+" {";
- if (numColumns != 1) string += "numColumns="+numColumns+" ";
- if (makeColumnsEqualWidth) string += "makeColumnsEqualWidth="+makeColumnsEqualWidth+" ";
- if (marginWidth != 0) string += "marginWidth="+marginWidth+" ";
- if (marginHeight != 0) string += "marginHeight="+marginHeight+" ";
- if (marginLeft != 0) string += "marginLeft="+marginLeft+" ";
- if (marginRight != 0) string += "marginRight="+marginRight+" ";
- if (marginTop != 0) string += "marginTop="+marginTop+" ";
- if (marginBottom != 0) string += "marginBottom="+marginBottom+" ";
- if (horizontalSpacing != 0) string += "horizontalSpacing="+horizontalSpacing+" ";
- if (verticalSpacing != 0) string += "verticalSpacing="+verticalSpacing+" ";
- string = string.trim();
- string += "}";
- return string;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowData.java
deleted file mode 100755
index c0a9e03293..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowData.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.layout;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Each control controlled by a <code>RowLayout</code> can have its initial
- * width and height specified by setting a <code>RowData</code> object
- * into the control.
- * <p>
- * The following code uses a <code>RowData</code> object to change the initial
- * size of a <code>Button</code> in a <code>Shell</code>:
- * <pre>
- * Display display = new Display();
- * Shell shell = new Shell(display);
- * shell.setLayout(new RowLayout());
- * Button button1 = new Button(shell, SWT.PUSH);
- * button1.setText("Button 1");
- * button1.setLayoutData(new RowData(50, 40));
- * </pre>
- * </p>
- *
- * @see RowLayout
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class RowData {
- /**
- * width specifies the desired width in pixels. This value
- * is the wHint passed into Control.computeSize(int, int, boolean)
- * to determine the preferred size of the control.
- *
- * The default value is SWT.DEFAULT.
- *
- * @see org.eclipse.swt.widgets.Control#computeSize(int, int, boolean)
- */
- public int width = SWT.DEFAULT;
- /**
- * height specifies the preferred height in pixels. This value
- * is the hHint passed into Control.computeSize(int, int, boolean)
- * to determine the preferred size of the control.
- *
- * The default value is SWT.DEFAULT.
- *
- * @see org.eclipse.swt.widgets.Control#computeSize(int, int, boolean)
- */
- public int height = SWT.DEFAULT;
-
- /**
- * exclude informs the layout to ignore this control when sizing
- * and positioning controls. If this value is <code>true</code>,
- * the size and position of the control will not be managed by the
- * layout. If this value is <code>false</code>, the size and
- * position of the control will be computed and assigned.
- *
- * The default value is <code>false</code>.
- *
- * @since 3.1
- */
- public boolean exclude = false;
-
-/**
- * Constructs a new instance of RowData using
- * default values.
- */
-public RowData () {
-}
-
-/**
- * Constructs a new instance of RowData according to the parameters.
- * A value of SWT.DEFAULT indicates that no minimum width or
- * no minimum height is specified.
- *
- * @param width a minimum width for the control
- * @param height a minimum height for the control
- */
-public RowData (int width, int height) {
- this.width = width;
- this.height = height;
-}
-
-/**
- * Constructs a new instance of RowData according to the parameter.
- * A value of SWT.DEFAULT indicates that no minimum width or
- * no minimum height is specified.
- *
- * @param point a point whose x coordinate specifies a minimum width for the control
- * and y coordinate specifies a minimum height for the control
- */
-public RowData (Point point) {
- this (point.x, point.y);
-}
-
-String getName () {
- String string = getClass ().getName ();
- int index = string.lastIndexOf ('.');
- if (index == -1) return string;
- return string.substring (index + 1, string.length ());
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the RowData object
- */
-public String toString () {
- String string = getName ()+" {";
- if (width != SWT.DEFAULT) string += "width="+width+" ";
- if (height != SWT.DEFAULT) string += "height="+height+" ";
- if (exclude) string += "exclude="+exclude+" ";
- string = string.trim();
- string += "}";
- return string;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowLayout.java
deleted file mode 100755
index 2d8b5742c1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowLayout.java
+++ /dev/null
@@ -1,506 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.layout;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * Instances of this class determine the size and position of the
- * children of a <code>Composite</code> by placing them either in
- * horizontal rows or vertical columns within the parent <code>Composite</code>.
- * <p>
- * <code>RowLayout</code> aligns all controls in one row if the
- * <code>type</code> is set to horizontal, and one column if it is
- * set to vertical. It has the ability to wrap, and provides configurable
- * margins and spacing. <code>RowLayout</code> has a number of configuration
- * fields. In addition, the height and width of each control in a
- * <code>RowLayout</code> can be specified by setting a <code>RowData</code>
- * object into the control using <code>setLayoutData ()</code>.
- * </p>
- * <p>
- * The following example code creates a <code>RowLayout</code>, sets all
- * of its fields to non-default values, and then sets it into a
- * <code>Shell</code>.
- * <pre>
- * RowLayout rowLayout = new RowLayout();
- * rowLayout.wrap = false;
- * rowLayout.pack = false;
- * rowLayout.justify = true;
- * rowLayout.type = SWT.VERTICAL;
- * rowLayout.marginLeft = 5;
- * rowLayout.marginTop = 5;
- * rowLayout.marginRight = 5;
- * rowLayout.marginBottom = 5;
- * rowLayout.spacing = 0;
- * shell.setLayout(rowLayout);
- * </pre>
- * If you are using the default field values, you only need one line of code:
- * <pre>
- * shell.setLayout(new RowLayout());
- * </pre>
- * </p>
- *
- * @see RowData
- * @see <a href="http://www.eclipse.org/swt/snippets/#rowlayout">RowLayout snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: LayoutExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class RowLayout extends Layout {
-
- /**
- * type specifies whether the layout places controls in rows or
- * columns.
- *
- * The default value is HORIZONTAL.
- *
- * Possible values are: <ul>
- * <li>HORIZONTAL: Position the controls horizontally from left to right</li>
- * <li>VERTICAL: Position the controls vertically from top to bottom</li>
- * </ul>
- *
- * @since 2.0
- */
- public int type = SWT.HORIZONTAL;
-
- /**
- * marginWidth specifies the number of pixels of horizontal margin
- * that will be placed along the left and right edges of the layout.
- *
- * The default value is 0.
- *
- * @since 3.0
- */
- public int marginWidth = 0;
-
- /**
- * marginHeight specifies the number of pixels of vertical margin
- * that will be placed along the top and bottom edges of the layout.
- *
- * The default value is 0.
- *
- * @since 3.0
- */
- public int marginHeight = 0;
-
- /**
- * spacing specifies the number of pixels between the edge of one cell
- * and the edge of its neighbouring cell.
- *
- * The default value is 3.
- */
- public int spacing = 3;
-
- /**
- * wrap specifies whether a control will be wrapped to the next
- * row if there is insufficient space on the current row.
- *
- * The default value is true.
- */
- public boolean wrap = true;
-
- /**
- * pack specifies whether all controls in the layout take
- * their preferred size. If pack is false, all controls will
- * have the same size which is the size required to accommodate the
- * largest preferred height and the largest preferred width of all
- * the controls in the layout.
- *
- * The default value is true.
- */
- public boolean pack = true;
-
- /**
- * fill specifies whether the controls in a row should be
- * all the same height for horizontal layouts, or the same
- * width for vertical layouts.
- *
- * The default value is false.
- *
- * @since 3.0
- */
- public boolean fill = false;
-
- /**
- * center specifies whether the controls in a row should be
- * centered vertically in each cell for horizontal layouts,
- * or centered horizontally in each cell for vertical layouts.
- *
- * The default value is false.
- *
- * @since 3.4
- */
- public boolean center = false;
-
- /**
- * justify specifies whether the controls in a row should be
- * fully justified, with any extra space placed between the controls.
- *
- * The default value is false.
- */
- public boolean justify = false;
-
- /**
- * marginLeft specifies the number of pixels of horizontal margin
- * that will be placed along the left edge of the layout.
- *
- * The default value is 3.
- */
- public int marginLeft = 3;
-
- /**
- * marginTop specifies the number of pixels of vertical margin
- * that will be placed along the top edge of the layout.
- *
- * The default value is 3.
- */
- public int marginTop = 3;
-
- /**
- * marginRight specifies the number of pixels of horizontal margin
- * that will be placed along the right edge of the layout.
- *
- * The default value is 3.
- */
- public int marginRight = 3;
-
- /**
- * marginBottom specifies the number of pixels of vertical margin
- * that will be placed along the bottom edge of the layout.
- *
- * The default value is 3.
- */
- public int marginBottom = 3;
-
-/**
- * Constructs a new instance of this class.
- */
-public RowLayout () {
-}
-
-/**
- * Constructs a new instance of this class given the type.
- *
- * @param type the type of row layout
- *
- * @since 2.0
- */
-public RowLayout (int type) {
- this.type = type;
-}
-
-protected Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache) {
- Point extent;
- if (type == SWT.HORIZONTAL) {
- extent = layoutHorizontal (composite, false, (wHint != SWT.DEFAULT) && wrap, wHint, flushCache);
- } else {
- extent = layoutVertical (composite, false, (hHint != SWT.DEFAULT) && wrap, hHint, flushCache);
- }
- if (wHint != SWT.DEFAULT) extent.x = wHint;
- if (hHint != SWT.DEFAULT) extent.y = hHint;
- return extent;
-}
-
-Point computeSize (Control control, boolean flushCache) {
- int wHint = SWT.DEFAULT, hHint = SWT.DEFAULT;
- RowData data = (RowData) control.getLayoutData ();
- if (data != null) {
- wHint = data.width;
- hHint = data.height;
- }
- return control.computeSize (wHint, hHint, flushCache);
-}
-
-protected boolean flushCache (Control control) {
- return true;
-}
-
-String getName () {
- String string = getClass ().getName ();
- int index = string.lastIndexOf ('.');
- if (index == -1) return string;
- return string.substring (index + 1, string.length ());
-}
-
-protected void layout (Composite composite, boolean flushCache) {
- Rectangle clientArea = composite.getClientArea ();
- if (type == SWT.HORIZONTAL) {
- layoutHorizontal (composite, true, wrap, clientArea.width, flushCache);
- } else {
- layoutVertical (composite, true, wrap, clientArea.height, flushCache);
- }
-}
-
-Point layoutHorizontal (Composite composite, boolean move, boolean wrap, int width, boolean flushCache) {
- Control [] children = composite.getChildren ();
- int count = 0;
- for (int i=0; i<children.length; i++) {
- Control control = children [i];
- RowData data = (RowData) control.getLayoutData ();
- if (data == null || !data.exclude) {
- children [count++] = children [i];
- }
- }
- if (count == 0) {
- return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom);
- }
- int childWidth = 0, childHeight = 0, maxHeight = 0;
- if (!pack) {
- for (int i=0; i<count; i++) {
- Control child = children [i];
- Point size = computeSize (child, flushCache);
- childWidth = Math.max (childWidth, size.x);
- childHeight = Math.max (childHeight, size.y);
- }
- maxHeight = childHeight;
- }
- int clientX = 0, clientY = 0;
- if (move) {
- Rectangle rect = composite.getClientArea ();
- clientX = rect.x;
- clientY = rect.y;
- }
- int [] wraps = null;
- boolean wrapped = false;
- Rectangle [] bounds = null;
- if (move && (justify || fill || center)) {
- bounds = new Rectangle [count];
- wraps = new int [count];
- }
- int maxX = 0, x = marginLeft + marginWidth, y = marginTop + marginHeight;
- for (int i=0; i<count; i++) {
- Control child = children [i];
- if (pack) {
- Point size = computeSize (child, flushCache);
- childWidth = size.x;
- childHeight = size.y;
- }
- if (wrap && (i != 0) && (x + childWidth > width)) {
- wrapped = true;
- if (move && (justify || fill || center)) wraps [i - 1] = maxHeight;
- x = marginLeft + marginWidth;
- y += spacing + maxHeight;
- if (pack) maxHeight = 0;
- }
- if (pack || fill || center) {
- maxHeight = Math.max (maxHeight, childHeight);
- }
- if (move) {
- int childX = x + clientX, childY = y + clientY;
- if (justify || fill || center) {
- bounds [i] = new Rectangle (childX, childY, childWidth, childHeight);
- } else {
- child.setBounds (childX, childY, childWidth, childHeight);
- }
- }
- x += spacing + childWidth;
- maxX = Math.max (maxX, x);
- }
- maxX = Math.max (clientX + marginLeft + marginWidth, maxX - spacing);
- if (!wrapped) maxX += marginRight + marginWidth;
- if (move && (justify || fill || center)) {
- int space = 0, margin = 0;
- if (!wrapped) {
- space = Math.max (0, (width - maxX) / (count + 1));
- margin = Math.max (0, ((width - maxX) % (count + 1)) / 2);
- } else {
- if (fill || justify || center) {
- int last = 0;
- if (count > 0) wraps [count - 1] = maxHeight;
- for (int i=0; i<count; i++) {
- if (wraps [i] != 0) {
- int wrapCount = i - last + 1;
- if (justify) {
- int wrapX = 0;
- for (int j=last; j<=i; j++) {
- wrapX += bounds [j].width + spacing;
- }
- space = Math.max (0, (width - wrapX) / (wrapCount + 1));
- margin = Math.max (0, ((width - wrapX) % (wrapCount + 1)) / 2);
- }
- for (int j=last; j<=i; j++) {
- if (justify) bounds [j].x += (space * (j - last + 1)) + margin;
- if (fill) {
- bounds [j].height = wraps [i];
- } else {
- if (center) {
- bounds [j].y += Math.max (0, (wraps [i] - bounds [j].height) / 2);
- }
- }
- }
- last = i + 1;
- }
- }
- }
- }
- for (int i=0; i<count; i++) {
- if (!wrapped) {
- if (justify) bounds [i].x += (space * (i + 1)) + margin;
- if (fill) {
- bounds [i].height = maxHeight;
- } else {
- if (center) {
- bounds [i].y += Math.max (0, (maxHeight - bounds [i].height) / 2);
- }
- }
- }
- children [i].setBounds (bounds [i]);
- }
- }
- return new Point (maxX, y + maxHeight + marginBottom + marginHeight);
-}
-
-Point layoutVertical (Composite composite, boolean move, boolean wrap, int height, boolean flushCache) {
- Control [] children = composite.getChildren ();
- int count = 0;
- for (int i=0; i<children.length; i++) {
- Control control = children [i];
- RowData data = (RowData) control.getLayoutData ();
- if (data == null || !data.exclude) {
- children [count++] = children [i];
- }
- }
- if (count == 0) {
- return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom);
- }
- int childWidth = 0, childHeight = 0, maxWidth = 0;
- if (!pack) {
- for (int i=0; i<count; i++) {
- Control child = children [i];
- Point size = computeSize (child, flushCache);
- childWidth = Math.max (childWidth, size.x);
- childHeight = Math.max (childHeight, size.y);
- }
- maxWidth = childWidth;
- }
- int clientX = 0, clientY = 0;
- if (move) {
- Rectangle rect = composite.getClientArea ();
- clientX = rect.x;
- clientY = rect.y;
- }
- int [] wraps = null;
- boolean wrapped = false;
- Rectangle [] bounds = null;
- if (move && (justify || fill || center)) {
- bounds = new Rectangle [count];
- wraps = new int [count];
- }
- int maxY = 0, x = marginLeft + marginWidth, y = marginTop + marginHeight;
- for (int i=0; i<count; i++) {
- Control child = children [i];
- if (pack) {
- Point size = computeSize (child, flushCache);
- childWidth = size.x;
- childHeight = size.y;
- }
- if (wrap && (i != 0) && (y + childHeight > height)) {
- wrapped = true;
- if (move && (justify || fill || center)) wraps [i - 1] = maxWidth;
- x += spacing + maxWidth;
- y = marginTop + marginHeight;
- if (pack) maxWidth = 0;
- }
- if (pack || fill || center) {
- maxWidth = Math.max (maxWidth, childWidth);
- }
- if (move) {
- int childX = x + clientX, childY = y + clientY;
- if (justify || fill || center) {
- bounds [i] = new Rectangle (childX, childY, childWidth, childHeight);
- } else {
- child.setBounds (childX, childY, childWidth, childHeight);
- }
- }
- y += spacing + childHeight;
- maxY = Math.max (maxY, y);
- }
- maxY = Math.max (clientY + marginTop + marginHeight, maxY - spacing);
- if (!wrapped) maxY += marginBottom + marginHeight;
- if (move && (justify || fill || center)) {
- int space = 0, margin = 0;
- if (!wrapped) {
- space = Math.max (0, (height - maxY) / (count + 1));
- margin = Math.max (0, ((height - maxY) % (count + 1)) / 2);
- } else {
- if (fill || justify || center) {
- int last = 0;
- if (count > 0) wraps [count - 1] = maxWidth;
- for (int i=0; i<count; i++) {
- if (wraps [i] != 0) {
- int wrapCount = i - last + 1;
- if (justify) {
- int wrapY = 0;
- for (int j=last; j<=i; j++) {
- wrapY += bounds [j].height + spacing;
- }
- space = Math.max (0, (height - wrapY) / (wrapCount + 1));
- margin = Math.max (0, ((height - wrapY) % (wrapCount + 1)) / 2);
- }
- for (int j=last; j<=i; j++) {
- if (justify) bounds [j].y += (space * (j - last + 1)) + margin;
- if (fill) {
- bounds [j].width = wraps [i];
- } else {
- if (center) {
- bounds [j].x += Math.max (0, (wraps [i] - bounds [j].width) / 2);
- }
- }
- }
- last = i + 1;
- }
- }
- }
- }
- for (int i=0; i<count; i++) {
- if (!wrapped) {
- if (justify) bounds [i].y += (space * (i + 1)) + margin;
- if (fill) {
- bounds [i].width = maxWidth;
- } else {
- if (center) {
- bounds [i].x += Math.max (0, (maxWidth - bounds [i].width) / 2);
- }
- }
-
- }
- children [i].setBounds (bounds [i]);
- }
- }
- return new Point (x + maxWidth + marginRight + marginWidth, maxY);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the layout
- */
-public String toString () {
- String string = getName ()+" {";
- string += "type="+((type != SWT.HORIZONTAL) ? "SWT.VERTICAL" : "SWT.HORIZONTAL")+" ";
- if (marginWidth != 0) string += "marginWidth="+marginWidth+" ";
- if (marginHeight != 0) string += "marginHeight="+marginHeight+" ";
- if (marginLeft != 0) string += "marginLeft="+marginLeft+" ";
- if (marginTop != 0) string += "marginTop="+marginTop+" ";
- if (marginRight != 0) string += "marginRight="+marginRight+" ";
- if (marginBottom != 0) string += "marginBottom="+marginBottom+" ";
- if (spacing != 0) string += "spacing="+spacing+" ";
- string += "wrap="+wrap+" ";
- string += "pack="+pack+" ";
- string += "fill="+fill+" ";
- string += "justify="+justify+" ";
- string = string.trim();
- string += "}";
- return string;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/package.html b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/package.html
deleted file mode 100755
index 0c6c14d815..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/package.html
+++ /dev/null
@@ -1,15 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-<html>
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <meta name="Author" content="IBM">
- <title>Package-level Javadoc</title>
-</head>
-<body>
-This package contains the SWT layout classes.
-<h2>
-Package Specification</h2>
-This package contains several standard layout classes which provide
-automated positioning and sizing support for SWT widgets.
-</body>
-</html>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/package.html b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/package.html
deleted file mode 100755
index 31459b907b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/package.html
+++ /dev/null
@@ -1,16 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-<html>
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <meta name="Author" content="IBM">
- <title>Package-level Javadoc</title>
-</head>
-<body>
-SWT constants and error handling support.
-<h2>
-Package Specification</h2>
-This package provides the class <code>SWT</code> which contains all of the
-constants used by SWT as well as a small selection of error handling routines
-and queries such as <code>getPlatform</code> and <code>getVersion</code>.
-</body>
-</html>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Dialog.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Dialog.java
deleted file mode 100755
index 95de81f4fa..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Dialog.java
+++ /dev/null
@@ -1,272 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-
-/**
- * This class is the abstract superclass of the classes
- * that represent the built in platform dialogs.
- * A <code>Dialog</code> typically contains other widgets
- * that are not accessible. A <code>Dialog</code> is not
- * a <code>Widget</code>.
- * <p>
- * This class can also be used as the abstract superclass
- * for user-designed dialogs. Such dialogs usually consist
- * of a Shell with child widgets. The basic template for a
- * user-defined dialog typically looks something like this:
- * <pre><code>
- * public class MyDialog extends Dialog {
- * Object result;
- *
- * public MyDialog (Shell parent, int style) {
- * super (parent, style);
- * }
- * public MyDialog (Shell parent) {
- * this (parent, 0); // your default style bits go here (not the Shell's style bits)
- * }
- * public Object open () {
- * Shell parent = getParent();
- * Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
- * shell.setText(getText());
- * // Your code goes here (widget creation, set result, etc).
- * shell.open();
- * Display display = parent.getDisplay();
- * while (!shell.isDisposed()) {
- * if (!display.readAndDispatch()) display.sleep();
- * }
- * return result;
- * }
- * }
- * </pre></code>
- * <p>
- * Note: The <em>modality</em> styles supported by this class
- * are treated as <em>HINT</em>s, because not all are supported
- * by every subclass on every platform. If a modality style is
- * not supported, it is "upgraded" to a more restrictive modality
- * style that is supported. For example, if <code>PRIMARY_MODAL</code>
- * is not supported by a particular dialog, it would be upgraded to
- * <code>APPLICATION_MODAL</code>. In addition, as is the case
- * for shells, the window manager for the desktop on which the
- * instance is visible has ultimate control over the appearance
- * and behavior of the instance, including its modality.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>APPLICATION_MODAL, PRIMARY_MODAL, SYSTEM_MODAL, SHEET</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles APPLICATION_MODAL, PRIMARY_MODAL,
- * and SYSTEM_MODAL may be specified.
- * </p>
- *
- * @see Shell
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public abstract class Dialog {
- int style;
- Shell parent;
- String title;
-
-/**
- * Constructs a new instance of this class given only its
- * parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- */
-public Dialog (Shell parent) {
- this (parent, SWT.PRIMARY_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- *
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- */
-public Dialog (Shell parent, int style) {
- checkParent (parent);
- this.parent = parent;
- this.style = style;
- title = "";
-}
-
-/**
- * Checks that this class can be subclassed.
- * <p>
- * IMPORTANT: See the comment in <code>Widget.checkSubclass()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- */
-protected void checkSubclass () {
- if (!Display.isValidClass (getClass ())) {
- error (SWT.ERROR_INVALID_SUBCLASS);
- }
-}
-
-/**
- * Throws an exception if the specified widget can not be
- * used as a parent for the receiver.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- */
-void checkParent (Shell parent) {
- if (parent == null) error (SWT.ERROR_NULL_ARGUMENT);
- parent.checkWidget ();
-}
-
-static int checkStyle (Shell parent, int style) {
- int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- if ((style & SWT.SHEET) != 0) {
- style &= ~SWT.SHEET;
- if ((style & mask) == 0) {
- style |= parent == null ? SWT.APPLICATION_MODAL : SWT.PRIMARY_MODAL;
- }
- }
- if ((style & mask) == 0) {
- style |= SWT.APPLICATION_MODAL;
- }
- style &= ~SWT.MIRRORED;
- if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) {
- if (parent != null) {
- if ((parent.style & SWT.LEFT_TO_RIGHT) != 0) style |= SWT.LEFT_TO_RIGHT;
- if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) style |= SWT.RIGHT_TO_LEFT;
- }
- }
- return Widget.checkBits (style, SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT, 0, 0, 0, 0);
-}
-
-/**
- * Does whatever dialog specific cleanup is required, and then
- * uses the code in <code>SWTError.error</code> to handle the error.
- *
- * @param code the descriptive error code
- *
- * @see SWT#error(int)
- */
-void error (int code) {
- SWT.error(code);
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Shell</code>
- * or null.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Shell getParent () {
- return parent;
-}
-
-/**
- * Returns the receiver's style information.
- * <p>
- * Note that, the value which is returned by this method <em>may
- * not match</em> the value which was provided to the constructor
- * when the receiver was created.
- * </p>
- *
- * @return the style bits
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getStyle () {
- return style;
-}
-
-/**
- * Returns the receiver's text, which is the string that the
- * window manager will typically display as the receiver's
- * <em>title</em>. If the text has not previously been set,
- * returns an empty string.
- *
- * @return the text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- return title;
-}
-
-/**
- * Sets the receiver's text, which is the string that the
- * window manager will typically display as the receiver's
- * <em>title</em>, to the argument, which must not be null.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- title = string;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Event.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Event.java
deleted file mode 100755
index 76cee32637..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Event.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide a description of a particular
- * event which occurred within SWT. The SWT <em>untyped listener</em>
- * API uses these instances for all event dispatching.
- * <p>
- * Note: For a given event, only the fields which are appropriate
- * will be filled in. The contents of the fields which are not used
- * by the event are unspecified.
- * </p>
- *
- * @see Listener
- * @see org.eclipse.swt.events.TypedEvent
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Listeners</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public class Event {
-
- /**
- * the display where the event occurred
- *
- * @since 2.0
- */
- public Display display;
-
- /**
- * the widget that issued the event
- */
- public Widget widget;
-
- /**
- * the type of event, as defined by the event type constants
- * in class <code>SWT</code>
- *
- * @see org.eclipse.swt.SWT
- */
- public int type;
-
- /**
- * the event specific detail field, as defined by the detail constants
- * in class <code>SWT</code>
- *
- * @see org.eclipse.swt.SWT
- */
- public int detail;
-
- /**
- * the item that the event occurred in (can be null)
- */
- public Widget item;
-
- /**
- * the index of the item where the event occurred
- *
- * @since 3.2
- */
- public int index;
-
- /**
- * the graphics context to use when painting
- * that is configured to use the colors, font and
- * damaged region of the control. It is valid
- * only during the paint and must not be disposed
- */
- public GC gc;
-
- /**
- * depending on the event type, the x offset of the bounding
- * rectangle of the region that requires painting or the
- * widget-relative, x coordinate of the pointer at the
- * time the mouse button was pressed or released
- */
- public int x;
-
- /**
- * depending on the event type, the y offset of the bounding
- * rectangle of the region that requires painting or the
- * widget-relative, y coordinate of the pointer at the
- * time the mouse button was pressed or released
- */
- public int y;
-
- /**
- * the width of the bounding rectangle of the
- * region that requires painting
- */
- public int width;
-
- /**
- * the height of the bounding rectangle of the
- * region that requires painting
- */
- public int height;
-
- /**
- * depending on the event type, the number of following
- * paint events that are pending which may always be zero
- * on some platforms, or the number of lines or pages to
- * scroll using the mouse wheel, or the number of times the
- * mouse has been clicked
- */
- public int count;
-
- /**
- * the time that the event occurred.
- *
- * NOTE: This field is an unsigned integer and should
- * be AND'ed with 0xFFFFFFFFL so that it can be treated
- * as a signed long.
- */
- public int time;
-
- /**
- * the button that was pressed or released; 1 for the
- * first button, 2 for the second button, and 3 for the
- * third button, etc.
- */
- public int button;
-
- /**
- * depending on the event, the character represented by the key
- * that was typed. This is the final character that results
- * after all modifiers have been applied. For example, when the
- * user types Ctrl+A, the character value is 0x01 (ASCII SOH).
- * It is important that applications do not attempt to modify the
- * character value based on a stateMask (such as SWT.CTRL) or the
- * resulting character will not be correct.
- */
- public char character;
-
- /**
- * depending on the event, the key code of the key that was typed,
- * as defined by the key code constants in class <code>SWT</code>.
- * When the character field of the event is ambiguous, this field
- * contains the unaffected value of the original character. For
- * example, typing Ctrl+M or Enter both result in the character '\r'
- * but the keyCode field will also contain '\r' when Enter was typed
- * and 'm' when Ctrl+M was typed.
- *
- * @see org.eclipse.swt.SWT
- */
- public int keyCode;
-
- /**
- * depending on the event, the state of the keyboard modifier
- * keys and mouse masks at the time the event was generated.
- *
- * @see org.eclipse.swt.SWT
- */
- public int stateMask;
-
- /**
- * depending on the event, the range of text being modified.
- * Setting these fields only has effect during ImeComposition
- * events.
- */
- public int start, end;
-
- /**
- * depending on the event, the new text that will be inserted.
- * Setting this field will change the text that is about to
- * be inserted or deleted.
- */
- public String text;
-
- /**
- * depending on the event, a flag indicating whether the operation
- * should be allowed. Setting this field to false will cancel the
- * operation.
- */
- public boolean doit = true;
-
- /**
- * a field for application use
- */
- public Object data;
-
-/**
- * Gets the bounds.
- *
- * @return a rectangle that is the bounds.
- */
-public Rectangle getBounds () {
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Sets the bounds.
- *
- * @param rect the new rectangle
- */
-public void setBounds (Rectangle rect) {
- this.x = rect.x;
- this.y = rect.y;
- this.width = rect.width;
- this.height = rect.height;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the event
- */
-public String toString () {
- return "Event {type=" + type + " " + widget + " time=" + time + " data=" + data + " x=" + x + " y=" + y + " width=" + width + " height=" + height + " detail=" + detail + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/EventTable.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/EventTable.java
deleted file mode 100755
index a9cda7b1b8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/EventTable.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Instances of this class implement a simple
- * look up mechanism that maps an event type
- * to a listener. Multiple listeners for the
- * same event type are supported.
- */
-
-class EventTable {
- int [] types;
- Listener [] listeners;
- int level;
- static final int GROW_SIZE = 4;
-
-public Listener [] getListeners (int eventType) {
- if (types == null) return new Listener [0];
- int count = 0;
- for (int i=0; i<types.length; i++) {
- if (types [i] == eventType) count++;
- }
- if (count == 0) return new Listener [0];
- Listener [] result = new Listener [count];
- count = 0;
- for (int i=0; i<types.length; i++) {
- if (types [i] == eventType) {
- result [count++] = listeners [i];
- }
- }
- return result;
-}
-
-public void hook (int eventType, Listener listener) {
- if (types == null) types = new int [GROW_SIZE];
- if (listeners == null) listeners = new Listener [GROW_SIZE];
- int length = types.length, index = length - 1;
- while (index >= 0) {
- if (types [index] != 0) break;
- --index;
- }
- index++;
- if (index == length) {
- int [] newTypes = new int [length + GROW_SIZE];
- System.arraycopy (types, 0, newTypes, 0, length);
- types = newTypes;
- Listener [] newListeners = new Listener [length + GROW_SIZE];
- System.arraycopy (listeners, 0, newListeners, 0, length);
- listeners = newListeners;
- }
- types [index] = eventType;
- listeners [index] = listener;
-}
-
-public boolean hooks (int eventType) {
- if (types == null) return false;
- for (int i=0; i<types.length; i++) {
- if (types [i] == eventType) return true;
- }
- return false;
-}
-
-public void sendEvent (Event event) {
- if (types == null) return;
- level += level >= 0 ? 1 : -1;
- try {
- for (int i=0; i<types.length; i++) {
- if (event.type == SWT.None) return;
- if (types [i] == event.type) {
- Listener listener = listeners [i];
- if (listener != null) listener.handleEvent (event);
- }
- }
- } finally {
- boolean compact = level < 0;
- level -= level >= 0 ? 1 : -1;
- if (compact && level == 0) {
- int index = 0;
- for (int i=0; i<types.length; i++) {
- if (types [i] != 0) {
- types [index] = types [i];
- listeners [index] = listeners [i];
- index++;
- }
- }
- for (int i=index; i<types.length; i++) {
- types [i] = 0;
- listeners [i] = null;
- }
- }
- }
-}
-
-public int size () {
- if (types == null) return 0;
- int count = 0;
- for (int i=0; i<types.length; i++) {
- if (types [i] != 0) count++;
- }
- return count;
-}
-
-void remove (int index) {
- if (level == 0) {
- int end = types.length - 1;
- System.arraycopy (types, index + 1, types, index, end - index);
- System.arraycopy (listeners, index + 1, listeners, index, end - index);
- index = end;
- } else {
- if (level > 0) level = -level;
- }
- types [index] = 0;
- listeners [index] = null;
-}
-
-public void unhook (int eventType, Listener listener) {
- if (types == null) return;
- for (int i=0; i<types.length; i++) {
- if (types [i] == eventType && listeners [i] == listener) {
- remove (i);
- return;
- }
- }
-}
-
-public void unhook (int eventType, SWTEventListener listener) {
- if (types == null) return;
- for (int i=0; i<types.length; i++) {
- if (types [i] == eventType) {
- if (listeners [i] instanceof TypedListener) {
- TypedListener typedListener = (TypedListener) listeners [i];
- if (typedListener.getEventListener () == listener) {
- remove (i);
- return;
- }
- }
- }
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Item.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Item.java
deleted file mode 100755
index 282bff2132..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Item.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * This class is the abstract superclass of all non-windowed
- * user interface objects that occur within specific controls.
- * For example, a tree will contain tree items.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public abstract class Item extends Widget {
- String text;
- Image image;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * The item is added to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of item to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#getStyle
- */
-public Item (Widget parent, int style) {
- super (parent, style);
- text = "";
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance,
- * and the index at which to place it in the items maintained
- * by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of item to construct
- * @param index the zero-relative index at which to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#getStyle
- */
-public Item (Widget parent, int style, int index) {
- this (parent, style);
-}
-
-protected void checkSubclass () {
- /* Do Nothing - Subclassing is allowed */
-}
-
-/**
- * Returns the receiver's image if it has one, or null
- * if it does not.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget ();
- return image;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- return text;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- text = null;
- image = null;
-}
-
-/**
- * Sets the receiver's image to the argument, which may be
- * null indicating that no image should be displayed.
- *
- * @param image the image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- this.image = image;
-}
-
-/**
- * Sets the receiver's text.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- text = string;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Layout.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Layout.java
deleted file mode 100755
index 5c8f3c2850..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Layout.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.graphics.*;
-
-/**
- * A layout controls the position and size
- * of the children of a composite widget.
- * This class is the abstract base class for
- * layouts.
- *
- * @see Composite#setLayout(Layout)
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class Layout {
-
-/**
- * Computes and returns the size of the specified
- * composite's client area according to this layout.
- * <p>
- * This method computes the size that the client area
- * of the composite must be in order to position all
- * children at their preferred size inside the
- * composite according to the layout algorithm
- * encoded by this layout.
- * </p>
- * <p>
- * When a width or height hint is supplied, it is
- * used to constrain the result. For example, if a
- * width hint is provided that is less than the
- * width of the client area, the layout may choose
- * to wrap and increase height, clip, overlap, or
- * otherwise constrain the children.
- * </p>
- *
- * @param composite a composite widget using this layout
- * @param wHint width (<code>SWT.DEFAULT</code> for preferred size)
- * @param hHint height (<code>SWT.DEFAULT</code> for preferred size)
- * @param flushCache <code>true</code> means flush cached layout values
- * @return a point containing the computed size (width, height)
- *
- * @see #layout
- * @see Control#getBorderWidth
- * @see Control#getBounds
- * @see Control#getSize
- * @see Control#pack(boolean)
- * @see "computeTrim, getClientArea for controls that implement them"
- */
-protected abstract Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache);
-
-/**
- * Instruct the layout to flush any cached values
- * associated with the control specified in the argument
- * <code>control</code>.
- *
- * @param control a control managed by this layout
- * @return true if the Layout has flushed all cached information associated with control
- *
- * @since 3.1
- */
-protected boolean flushCache (Control control) {
- return false;
-}
-
-/**
- * Lays out the children of the specified composite
- * according to this layout.
- * <p>
- * This method positions and sizes the children of a
- * composite using the layout algorithm encoded by this
- * layout. Children of the composite are positioned in
- * the client area of the composite. The position of
- * the composite is not altered by this method.
- * </p>
- * <p>
- * When the flush cache hint is true, the layout is
- * instructed to flush any cached values associated
- * with the children. Typically, a layout will cache
- * the preferred sizes of the children to avoid the
- * expense of computing these values each time the
- * widget is laid out.
- * </p>
- * <p>
- * When layout is triggered explicitly by the programmer
- * the flush cache hint is true. When layout is triggered
- * by a resize, either caused by the programmer or by the
- * user, the hint is false.
- * </p>
- *
- * @param composite a composite widget using this layout
- * @param flushCache <code>true</code> means flush cached layout values
- */
-protected abstract void layout (Composite composite, boolean flushCache);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Listener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Listener.java
deleted file mode 100755
index b02efa2cd3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Listener.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-/**
- * Implementers of <code>Listener</code> provide a simple
- * <code>handleEvent()</code> method that is used internally
- * by SWT to dispatch events.
- * <p>
- * After creating an instance of a class that implements this interface
- * it can be added to a widget using the
- * <code>addListener(int eventType, Listener handler)</code> method and
- * removed using the
- * <code>removeListener (int eventType, Listener handler)</code> method.
- * When the specified event occurs, <code>handleEvent(...)</code> will
- * be sent to the instance.
- * </p>
- * <p>
- * Classes which implement this interface are described within SWT as
- * providing the <em>untyped listener</em> API. Typically, widgets will
- * also provide a higher-level <em>typed listener</em> API, that is based
- * on the standard <code>java.util.EventListener</code> pattern.
- * </p>
- * <p>
- * Note that, since all internal SWT event dispatching is based on untyped
- * listeners, it is simple to build subsets of SWT for use on memory
- * constrained, small footprint devices, by removing the classes and
- * methods which implement the typed listener API.
- * </p>
- *
- * @see Widget#addListener
- * @see java.util.EventListener
- * @see org.eclipse.swt.events
- */
-public interface Listener {
-
-/**
- * Sent when an event that the receiver has registered for occurs.
- *
- * @param event the event which occurred
- */
-void handleEvent (Event event);
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Monitor.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Monitor.java
deleted file mode 100644
index f22948a087..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Monitor.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are descriptions of monitors.
- *
- * @see Display
- * @see <a href="http://www.eclipse.org/swt/snippets/#monitor">Monitor snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.0
- */
-public final class Monitor {
- int /*long*/ handle;
- int x, y, width, height;
- int clientX, clientY, clientWidth, clientHeight;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Monitor () {
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode()
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Monitor)) return false;
- Monitor monitor = (Monitor) object;
- return handle == monitor.handle;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its device. Note that on multi-monitor systems the
- * origin can be negative.
- *
- * @return the receiver's bounding rectangle
- */
-public Rectangle getBounds () {
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data.
- *
- * @return the client area
- */
-public Rectangle getClientArea () {
- return new Rectangle (clientX, clientY, clientWidth, clientHeight);
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals(Object)
- */
-public int hashCode () {
- return (int)/*64*/handle;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/RunnableLock.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/RunnableLock.java
deleted file mode 100755
index 40a0e6b2b7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/RunnableLock.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-/**
- * Instances of this class are used to ensure that an
- * application cannot interfere with the locking mechanism
- * used to implement asynchronous and synchronous communication
- * between widgets and background threads.
- */
-
-class RunnableLock {
- Runnable runnable;
- Thread thread;
- Throwable throwable;
-
-RunnableLock (Runnable runnable) {
- this.runnable = runnable;
-}
-
-boolean done () {
- return runnable == null || throwable != null;
-}
-
-void run () {
- if (runnable != null) runnable.run ();
- runnable = null;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Synchronizer.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Synchronizer.java
deleted file mode 100755
index 5bcf914974..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Synchronizer.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.Compatibility;
-
-/**
- * Instances of this class provide synchronization support
- * for displays. A default instance is created automatically
- * for each display, and this instance is sufficient for almost
- * all applications.
- * <p>
- * <b>IMPORTANT:</b> Typical application code <em>never</em>
- * needs to deal with this class. It is provided only to
- * allow applications which require non-standard
- * synchronization behavior to plug in the support they
- * require. <em>Subclasses which override the methods in
- * this class must ensure that the superclass methods are
- * invoked in their implementations</em>
- * </p>
- *
- * @see Display#setSynchronizer
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class Synchronizer {
- Display display;
- int messageCount;
- RunnableLock [] messages;
- Object messageLock = new Object ();
- Thread syncThread;
- static final int GROW_SIZE = 4;
- static final int MESSAGE_LIMIT = 64;
-
- //TEMPORARY CODE
- static final boolean IS_CARBON = "carbon".equals (SWT.getPlatform ());
- static final boolean IS_GTK = "gtk".equals (SWT.getPlatform ());
-
-/**
- * Constructs a new instance of this class.
- *
- * @param display the display to create the synchronizer on
- */
-public Synchronizer (Display display) {
- this.display = display;
-}
-
-void addLast (RunnableLock lock) {
- boolean wake = false;
- synchronized (messageLock) {
- if (messages == null) messages = new RunnableLock [GROW_SIZE];
- if (messageCount == messages.length) {
- RunnableLock[] newMessages = new RunnableLock [messageCount + GROW_SIZE];
- System.arraycopy (messages, 0, newMessages, 0, messageCount);
- messages = newMessages;
- }
- messages [messageCount++] = lock;
- wake = messageCount == 1;
- }
- if (wake) display.wakeThread ();
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread at the next
- * reasonable opportunity. The caller of this method continues
- * to run in parallel, and is not notified when the
- * runnable has completed.
- *
- * @param runnable code to run on the user-interface thread.
- *
- * @see #syncExec
- */
-protected void asyncExec (Runnable runnable) {
- if (runnable == null) {
- //TEMPORARY CODE
- if (!(IS_CARBON || IS_GTK)) {
- display.wake ();
- return;
- }
- }
- addLast (new RunnableLock (runnable));
-}
-
-int getMessageCount () {
- synchronized (messageLock) {
- return messageCount;
- }
-}
-
-void releaseSynchronizer () {
- display = null;
- messages = null;
- messageLock = null;
- syncThread = null;
-}
-
-RunnableLock removeFirst () {
- synchronized (messageLock) {
- if (messageCount == 0) return null;
- RunnableLock lock = messages [0];
- System.arraycopy (messages, 1, messages, 0, --messageCount);
- messages [messageCount] = null;
- if (messageCount == 0) {
- if (messages.length > MESSAGE_LIMIT) messages = null;
- }
- return lock;
- }
-}
-
-boolean runAsyncMessages () {
- return runAsyncMessages (false);
-}
-
-boolean runAsyncMessages (boolean all) {
- boolean run = false;
- do {
- RunnableLock lock = removeFirst ();
- if (lock == null) return run;
- run = true;
- synchronized (lock) {
- syncThread = lock.thread;
- try {
- lock.run ();
- } catch (Throwable t) {
- lock.throwable = t;
- SWT.error (SWT.ERROR_FAILED_EXEC, t);
- } finally {
- syncThread = null;
- lock.notifyAll ();
- }
- }
- } while (all);
- return run;
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread at the next
- * reasonable opportunity. The thread which calls this method
- * is suspended until the runnable completes.
- *
- * @param runnable code to run on the user-interface thread.
- *
- * @exception SWTException <ul>
- * <li>ERROR_FAILED_EXEC - if an exception occurred when executing the runnable</li>
- * </ul>
- *
- * @see #asyncExec
- */
-protected void syncExec (Runnable runnable) {
- RunnableLock lock = null;
- synchronized (Device.class) {
- if (display == null || display.isDisposed ()) SWT.error (SWT.ERROR_DEVICE_DISPOSED);
- if (!display.isValidThread ()) {
- if (runnable == null) {
- display.wake ();
- return;
- }
- lock = new RunnableLock (runnable);
- /*
- * Only remember the syncThread for syncExec.
- */
- lock.thread = Thread.currentThread();
- addLast (lock);
- }
- }
- if (lock == null) {
- if (runnable != null) runnable.run ();
- return;
- }
- synchronized (lock) {
- boolean interrupted = false;
- while (!lock.done ()) {
- try {
- lock.wait ();
- } catch (InterruptedException e) {
- interrupted = true;
- }
- }
- if (interrupted) {
- Compatibility.interrupt();
- }
- if (lock.throwable != null) {
- SWT.error (SWT.ERROR_FAILED_EXEC, lock.throwable);
- }
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Tray.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Tray.java
deleted file mode 100644
index 53fadefae4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Tray.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class represent the system tray that is part
- * of the task bar status area on some operating systems.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see Display#getSystemTray
- * @see <a href="http://www.eclipse.org/swt/snippets/#tray">Tray, TrayItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.0
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Tray extends Widget {
- int itemCount;
- TrayItem [] items = new TrayItem [4];
-
-Tray (Display display, int style) {
- if (display == null) display = Display.getCurrent ();
- if (display == null) display = Display.getDefault ();
- if (!display.isValidThread ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- this.display = display;
-}
-
-void createItem (TrayItem item, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (itemCount == items.length) {
- TrayItem [] newItems = new TrayItem [items.length + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- System.arraycopy (items, index, items, index + 1, itemCount++ - index);
- items [index] = item;
-}
-
-void destroyItem (TrayItem item) {
- int index = 0;
- while (index < itemCount) {
- if (items [index] == item) break;
- index++;
- }
- if (index == itemCount) return;
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TrayItem getItem (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return itemCount;
-}
-
-/**
- * Returns an array of <code>TrayItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TrayItem [] getItems () {
- checkWidget ();
- TrayItem [] result = new TrayItem [itemCount];
- System.arraycopy (items, 0, result, 0, result.length);
- return result;
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<items.length; i++) {
- TrayItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (display.tray == this) display.tray = null;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/TypedListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/TypedListener.java
deleted file mode 100755
index d352c1051d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/TypedListener.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.SWTEventListener;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are <em>internal SWT implementation</em>
- * objects which provide a mapping between the typed and untyped
- * listener mechanisms that SWT supports.
- * <p>
- * <b>IMPORTANT:</b> This class is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It should never be
- * referenced from application code.
- * </p>
- *
- * @see Listener
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class TypedListener implements Listener {
-
- /**
- * The receiver's event listener
- */
- protected SWTEventListener eventListener;
-
-/**
- * Constructs a new instance of this class for the given event listener.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It should never be
- * referenced from application code.
- * </p>
- *
- * @param listener the event listener to store in the receiver
- */
-public TypedListener (SWTEventListener listener) {
- eventListener = listener;
-}
-
-/**
- * Returns the receiver's event listener.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It should never be
- * referenced from application code.
- * </p>
- *
- * @return the receiver's event listener
- */
-public SWTEventListener getEventListener () {
- return eventListener;
-}
-
-/**
- * Handles the given event.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It should never be
- * referenced from application code.
- * </p>
- * @param e the event to handle
- */
-public void handleEvent (Event e) {
- switch (e.type) {
- case SWT.Activate: {
- ((ShellListener) eventListener).shellActivated(new ShellEvent(e));
- break;
- }
- case SWT.Arm: {
- ((ArmListener) eventListener).widgetArmed (new ArmEvent (e));
- break;
- }
- case SWT.Close: {
- /* Fields set by Decorations */
- ShellEvent event = new ShellEvent (e);
- ((ShellListener) eventListener).shellClosed(event);
- e.doit = event.doit;
- break;
- }
- case SWT.Collapse: {
- if (eventListener instanceof TreeListener) {
- ((TreeListener) eventListener).treeCollapsed(new TreeEvent(e));
- } else {
- ((ExpandListener) eventListener).itemCollapsed(new ExpandEvent(e));
- }
- break;
- }
- case SWT.Deactivate: {
- ((ShellListener) eventListener).shellDeactivated(new ShellEvent(e));
- break;
- }
- case SWT.Deiconify: {
- ((ShellListener) eventListener).shellDeiconified(new ShellEvent(e));
- break;
- }
- case SWT.DefaultSelection: {
- ((SelectionListener)eventListener).widgetDefaultSelected(new SelectionEvent(e));
- break;
- }
- case SWT.Dispose: {
- ((DisposeListener) eventListener).widgetDisposed(new DisposeEvent(e));
- break;
- }
- case SWT.DragDetect: {
- ((DragDetectListener) eventListener).dragDetected(new DragDetectEvent(e));
- break;
- }
- case SWT.Expand: {
- if (eventListener instanceof TreeListener) {
- ((TreeListener) eventListener).treeExpanded(new TreeEvent(e));
- } else {
- ((ExpandListener) eventListener).itemExpanded(new ExpandEvent(e));
- }
- break;
- }
- case SWT.FocusIn: {
- ((FocusListener) eventListener).focusGained(new FocusEvent(e));
- break;
- }
- case SWT.FocusOut: {
- ((FocusListener) eventListener).focusLost(new FocusEvent(e));
- break;
- }
- case SWT.Help: {
- ((HelpListener) eventListener).helpRequested (new HelpEvent (e));
- break;
- }
- case SWT.Hide: {
- ((MenuListener) eventListener).menuHidden(new MenuEvent(e));
- break;
- }
- case SWT.Iconify: {
- ((ShellListener) eventListener).shellIconified(new ShellEvent(e));
- break;
- }
- case SWT.KeyDown: {
- /* Fields set by Control */
- KeyEvent event = new KeyEvent(e);
- ((KeyListener) eventListener).keyPressed(event);
- e.doit = event.doit;
- break;
- }
- case SWT.KeyUp: {
- /* Fields set by Control */
- KeyEvent event = new KeyEvent(e);
- ((KeyListener) eventListener).keyReleased(event);
- e.doit = event.doit;
- break;
- }
- case SWT.Modify: {
- ((ModifyListener) eventListener).modifyText(new ModifyEvent(e));
- break;
- }
- case SWT.MenuDetect: {
- MenuDetectEvent event = new MenuDetectEvent(e);
- ((MenuDetectListener) eventListener).menuDetected(event);
- e.x = event.x;
- e.y = event.y;
- e.doit = event.doit;
- break;
- }
- case SWT.MouseDown: {
- ((MouseListener) eventListener).mouseDown(new MouseEvent(e));
- break;
- }
- case SWT.MouseDoubleClick: {
- ((MouseListener) eventListener).mouseDoubleClick(new MouseEvent(e));
- break;
- }
- case SWT.MouseEnter: {
- ((MouseTrackListener) eventListener).mouseEnter (new MouseEvent (e));
- break;
- }
- case SWT.MouseExit: {
- ((MouseTrackListener) eventListener).mouseExit (new MouseEvent (e));
- break;
- }
- case SWT.MouseHover: {
- ((MouseTrackListener) eventListener).mouseHover (new MouseEvent (e));
- break;
- }
- case SWT.MouseMove: {
- ((MouseMoveListener) eventListener).mouseMove(new MouseEvent(e));
- return;
- }
- case SWT.MouseWheel: {
- ((MouseWheelListener) eventListener).mouseScrolled(new MouseEvent(e));
- return;
- }
- case SWT.MouseUp: {
- ((MouseListener) eventListener).mouseUp(new MouseEvent(e));
- break;
- }
- case SWT.Move: {
- ((ControlListener) eventListener).controlMoved(new ControlEvent(e));
- break;
- }
- case SWT.Paint: {
- /* Fields set by Control */
- PaintEvent event = new PaintEvent (e);
- ((PaintListener) eventListener).paintControl (event);
- e.gc = event.gc;
- break;
- }
- case SWT.Resize: {
- ((ControlListener) eventListener).controlResized(new ControlEvent(e));
- break;
- }
- case SWT.Selection: {
- /* Fields set by Sash */
- SelectionEvent event = new SelectionEvent (e);
- ((SelectionListener) eventListener).widgetSelected (event);
- e.x = event.x;
- e.y = event.y;
- e.doit = event.doit;
- break;
- }
- case SWT.Show: {
- ((MenuListener) eventListener).menuShown(new MenuEvent(e));
- break;
- }
- case SWT.Traverse: {
- /* Fields set by Control */
- TraverseEvent event = new TraverseEvent (e);
- ((TraverseListener) eventListener).keyTraversed (event);
- e.detail = event.detail;
- e.doit = event.doit;
- break;
- }
- case SWT.Verify: {
- /* Fields set by Text, RichText */
- VerifyEvent event = new VerifyEvent (e);
- ((VerifyListener) eventListener).verifyText (event);
- e.text = event.text;
- e.doit = event.doit;
- break;
- }
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/package.html b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/package.html
deleted file mode 100755
index 6068615622..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/package.html
+++ /dev/null
@@ -1,16 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-<html>
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <meta name="Author" content="IBM">
- <title>Package-level Javadoc</title>
-</head>
-<body>
-SWT widget public API classes.
-<h2>
-Package Specification</h2>
-This package contains the classes which make up the public SWT widget
-API as well as the related public support classes (for example, class
-<code>Event</code>).
-</body>
-</html>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/version.txt b/bundles/org.eclipse.swt/Eclipse SWT/common/version.txt
deleted file mode 100755
index 70437d283f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/version.txt
+++ /dev/null
@@ -1 +0,0 @@
-version 3.601 \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/CloneableCompatibility.java b/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/CloneableCompatibility.java
deleted file mode 100644
index 1201e3a506..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/CloneableCompatibility.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal;
-
-
-/**
- * This interface is the cross-platform version of the
- * java.lang.Cloneable interface.
- * <p>
- * It is part of our effort to provide support for both J2SE
- * and J2ME platforms. Under this scheme, classes need to
- * implement CloneableCompatibility instead of java.lang.Cloneable.
- * </p>
- * <p>
- * Note: java.lang.Cloneable is not part of CLDC.
- * </p>
- * <p>
- * IMPORTANT: CDC mandates Cloneable. Behavior on CLDC will have
- * to be discussed further.
- * </p>
- */
-public interface CloneableCompatibility {
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/Compatibility.java b/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/Compatibility.java
deleted file mode 100644
index 94becf9755..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/Compatibility.java
+++ /dev/null
@@ -1,444 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal;
-
-
-import org.eclipse.swt.SWT;
-import java.io.*;
-
-/**
- * This class is a placeholder for utility methods commonly
- * used on J2SE platforms but not supported on some J2ME
- * profiles.
- * <p>
- * It is part of our effort to provide support for both J2SE
- * and J2ME platforms.
- * </p>
- * <p>
- * IMPORTANT: some of the methods have been modified from their
- * J2SE parents. Refer to the description of each method for
- * specific changes.
- * </p>
- * <ul>
- * <li>Exceptions thrown may differ since J2ME's set of
- * exceptions is a subset of J2SE's one.
- * </li>
- * <li>The range of the mathematic functions is subject to
- * change.
- * </li>
- * </ul>
- */
-public final class Compatibility {
-
-/**
- * Returns the PI constant as a double.
- */
-public static double PI = (double)3.141592653589793;
-
-/**
- * Sine table
- * <p>
- * Values represent sine for each degree between 0 and 90. Values have
- * been multiplied by 65536 and rounded.
- * </p>
- */
-static int[] sineTable = {
- 0, 1143, 2287, 3429, 4571, 5711, 6850, 7986, 9120, 10252, // 0 to 9 degrees
- 11380, 12504, 13625, 14742, 15854, 16961, 18064, 19160, 20251, 21336, // 10 to 19 degrees
- 22414, 23486, 24550, 25606, 26655, 27696, 28729, 29752, 30767, 31772, // 20 to 29 degrees
- 32767, 33753, 34728, 35693, 36647, 37589, 38521, 39440, 40347, 41243, // 30 to 39 degrees
- 42125, 42995, 43852, 44695, 45525, 46340, 47142, 47929, 48702, 49460, // 40 to 49 degrees
- 50203, 50931, 51643, 52339, 53019, 53683, 54331, 54963, 55577, 56175, // 50 to 59 degrees
- 56755, 57319, 57864, 58393, 58903, 59395, 59870, 60326, 60763, 61183, // 60 to 69 degrees
- 61583, 61965, 62328, 62672, 62997, 63302, 63589, 63856, 64103, 64331, // 70 to 79 degrees
- 64540, 64729, 64898, 65047, 65176, 65286, 65376, 65446, 65496, 65526, // 80 to 89 degrees
- 65536 }; // 90 degrees
-
-/**
- * Answers the length of the side adjacent to the given angle
- * of a right triangle. In other words, it returns the integer
- * conversion of length * cos (angle).
- * <p>
- * IMPORTANT: the j2me version has an additional restriction on
- * the argument. length must be between -32767 and 32767 (inclusive).
- * </p>
- *
- * @param angle the angle in degrees
- * @param length the length of the triangle's hypotenuse
- * @return the integer conversion of length * cos (angle)
- */
-public static int cos(int angle, int length) {
- return sin(90 - angle, length);
-}
-
-/**
- * Answers the length of the side opposite to the given angle
- * of a right triangle. In other words, it returns the integer
- * conversion of length * sin (angle).
- * <p>
- * IMPORTANT: the j2me version has an additional restriction on
- * the argument. length must be between -32767 and 32767 (inclusive).
- * </p>
- *
- * @param angle the angle in degrees
- * @param length the length of the triangle's hypotenuse
- * @return the integer conversion of length * sin (angle)
- */
-public static int sin(int angle, int length) {
- if (length < -32767 || length > 32767) {
- SWT.error(SWT.ERROR_INVALID_RANGE);
- }
- if (angle < 0 || angle >= 360) {
- angle = angle % 360;
- if (angle < 0) angle += 360;
- }
-
- int sineValue;
- if (angle >= 0 && angle < 90) sineValue = sineTable[angle];
- else if (angle >= 90 && angle < 180) sineValue = sineTable[180 - angle];
- else if (angle >= 180 && angle < 270) sineValue = 0 - sineTable[angle - 180];
- else {
- // angle >= 270 && angle < 360
- sineValue = 0 - sineTable[360 - angle];
- }
-
- return (sineValue * length) >> 16;
-}
-
-/**
- * Answers the most negative (i.e. closest to negative infinity)
- * integer value which is greater than the number obtained by dividing
- * the first argument p by the second argument q.
- *
- * @param p numerator
- * @param q denominator (must be different from zero)
- * @return the ceiling of the rational number p / q.
- */
-public static int ceil(int p, int q) {
- int res = p / q;
- if ((p % q == 0) ||
- (res < 0) ||
- ((res == 0) && ((p < 0 && q > 0) || (p > 0 && q < 0))))
- return res;
- else
- return res + 1;
-}
-
-/**
- * Answers the most positive (i.e. closest to positive infinity)
- * integer value which is less than the number obtained by dividing
- * the first argument p by the second argument q.
- *
- * @param p numerator
- * @param q denominator (must be different from zero)
- * @return the floor of the rational number p / q.
- */
-public static int floor(int p, int q) {
- int res = p / q;
- if ((p % q == 0) ||
- (res > 0) ||
- ((res == 0) && ((p > 0 && q > 0) || (p < 0 && q < 0))))
- return res;
- else
- return res - 1;
-}
-
-/**
- * Answers the result of rounding to the closest integer the number obtained
- * by dividing the first argument p by the second argument q.
- * <p>
- * IMPORTANT: the j2me version has an additional restriction on
- * the arguments. p must be within the range 0 - 32767 (inclusive).
- * q must be within the range 1 - 32767 (inclusive).
- * </p>
- *
- * @param p numerator
- * @param q denominator (must be different from zero)
- * @return the closest integer to the rational number p / q
- */
-public static int round(int p, int q) {
- if (p < 0 || p > 32767 || q < 1 || q > 32767) {
- SWT.error(SWT.ERROR_INVALID_RANGE);
- }
- return (2 * p + q) / (2 * q);
-}
-
-/**
- * Returns 2 raised to the power of the argument.
- *
- * @param n an int value between 0 and 30 (inclusive)
- * @return 2 raised to the power of the argument
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the argument is not between 0 and 30 (inclusive)</li>
- * </ul>
- */
-public static int pow2(int n) {
- if (n >= 1 && n <= 30)
- return 2 << (n - 1);
- else if (n != 0) {
- SWT.error(SWT.ERROR_INVALID_RANGE);
- }
- return 1;
-}
-
-/**
- * Create an DeflaterOutputStream if such things are supported.
- *
- * @param stream the output stream
- * @return a deflater stream or <code>null</code>
- * @exception IOException
- *
- * @since 3.4
- */
-public static OutputStream newDeflaterOutputStream(OutputStream stream) throws IOException {
- return null;
-}
-
-/**
- * Open a file if such things are supported.
- *
- * @param filename the name of the file to open
- * @return a stream on the file if it could be opened.
- */
-public static InputStream newFileInputStream (String filename) throws IOException {
- throw new IOException();
-}
-
-/**
- * Open a file if such things are supported.
- *
- * @param filename the name of the file to open
- * @return a stream on the file if it could be opened.
- */
-public static OutputStream newFileOutputStream (String filename) throws IOException {
- throw new IOException();
-}
-
-/**
- * Create an InflaterInputStream if such things are supported.
- *
- * @param stream the input stream
- * @return a inflater stream or <code>null</code>
- * @exception IOException
- *
- * @since 3.3
- */
-public static InputStream newInflaterInputStream(InputStream stream) throws IOException {
- return null;
-}
-
-/**
- * Answers whether the character is a letter.
- *
- * @param c the character
- * @return true when the character is a letter
- */
-public static boolean isLetter(char c) {
- return (Character.isUpperCase(c)) || (Character.isLowerCase(c));
-}
-
-/**
- * Answers whether the character is a letter or a digit.
- *
- * @param c the character
- * @return true when the character is a letter or a digit
- */
-public static boolean isLetterOrDigit(char c) {
- return isLetter(c) || Character.isDigit(c);
-}
-
-/**
- * Answers whether the character is a Unicode space character.
- *
- * @param c the character
- * @return true when the character is a Unicode space character
- */
-public static boolean isSpaceChar(char c) {
- return c == ' ';
-}
-
-/**
- * Answers whether the character is whitespace character.
- *
- * @param c the character
- * @return true when the character is a whitespace character
- */
-public static boolean isWhitespace(char c) {
- // Optimized case for ASCII
- if ((c >= 0x1c && c <= 0x20) || (c >= 0x9 && c <= 0xd))
- return true;
- return false;
-}
-
-/**
- * Execute a program in a separate platform process if the
- * underlying platform support this.
- * <p>
- * The new process inherits the environment of the caller.
- * </p>
- *
- * @param program the name of the program to execute
- *
- * @exception IOException
- * if the program cannot be executed
- * @exception SecurityException
- * if the current SecurityManager disallows program execution
- */
-public static void exec(String prog) throws java.io.IOException {
- throw new IOException();
-}
-
-/**
- * Answers whether the indicated file exists or not.
- *
- * @param parent the file's parent directory
- * @param child the file's name
- * @return true if the file exists
- */
-public static boolean fileExists(String parent, String child) {
- return false;
-}
-
-/**
- * Execute progArray[0] in a separate platform process if the
- * underlying platform support this.
- * <p>
- * The new process inherits the environment of the caller.
- * <p>
- *
- * @param progArray array containing the program to execute and its arguments
- *
- * @exception IOException
- * if the program cannot be executed
- * @exception SecurityException
- * if the current SecurityManager disallows program execution
- */
-public static void exec(String[] progArray) throws java.io.IOException{
- throw new IOException();
-}
-
-/**
- * Returns the NLS'ed message for the given argument. This is only being
- * called from SWT.
- *
- * @param key the key to look up
- * @return the message for the given key
- *
- * @see SWT#getMessage
- */
-public static String getMessage(String key) {
- if (key == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (key.equals("SWT_Yes")) return "Yes"; //$NON-NLS-1$
- if (key.equals("SWT_No")) return "No"; //$NON-NLS-1$
- if (key.equals("SWT_OK")) return "OK"; //$NON-NLS-1$
- if (key.equals("SWT_Cancel")) return "Cancel"; //$NON-NLS-1$
- if (key.equals("SWT_Abort")) return "Abort"; //$NON-NLS-1$
- if (key.equals("SWT_Retry")) return "Retry"; //$NON-NLS-1$
- if (key.equals("SWT_Ignore")) return "Ignore"; //$NON-NLS-1$
- if (key.equals("SWT_Sample")) return "Sample"; //$NON-NLS-1$
- if (key.equals("SWT_A_Sample_Text")) return "A Sample Text"; //$NON-NLS-1$
- if (key.equals("SWT_Selection")) return "Selection"; //$NON-NLS-1$
- if (key.equals("SWT_Current_Selection")) return "Current Selection"; //$NON-NLS-1$
- if (key.equals("SWT_Font")) return "Font"; //$NON-NLS-1$
- if (key.equals("SWT_Color")) return "Color"; //$NON-NLS-1$
- if (key.equals("SWT_Extended_style")) return "Extended style"; //$NON-NLS-1$
- if (key.equals("SWT_Size")) return "Size"; //$NON-NLS-1$
- if (key.equals("SWT_Style")) return "Style"; //$NON-NLS-1$
- if (key.equals("SWT_Save")) return "Save"; //$NON-NLS-1$
- if (key.equals("SWT_Character_set")) return "Character set"; //$NON-NLS-1$
- if (key.equals("SWT_ColorDialog_Title")) return "Colors"; //$NON-NLS-1$
- if (key.equals("SWT_FontDialog_Title")) return "Fonts"; //$NON-NLS-1$
- if (key.equals("SWT_FontSet")) return "Font Set"; //$NON-NLS-1$
- if (key.equals("SWT_NewFont")) return "New Font"; //$NON-NLS-1$
- if (key.equals("SWT_Remove")) return "Remove"; //$NON-NLS-1$
- if (key.equals("SWT_Up")) return "Up"; //$NON-NLS-1$
- if (key.equals("SWT_Down")) return "Down"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_Western")) return "western"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_EastEuropean")) return "east european"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_SouthEuropean")) return "south european"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_NorthEuropean")) return "north european"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_Cyrillic")) return "cyrillic"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_Arabic")) return "arabic"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_Greek")) return "greek"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_Hebrew")) return "hebrew"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_Turkish")) return "turkish"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_Nordic")) return "nordic"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_Thai")) return "thai"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_BalticRim")) return "baltic rim"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_Celtic")) return "celtic"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_Euro")) return "euro"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_Romanian")) return "romanian"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_SimplifiedChinese")) return "simplified chinese"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_TraditionalChinese")) return "traditional chinese"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_Japanese")) return "japanese"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_Korean")) return "korean"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_Unicode")) return "unicode"; //$NON-NLS-1$
- if (key.equals("SWT_Charset_ASCII")) return "ASCII"; //$NON-NLS-1$
- if (key.equals("SWT_InputMethods")) return "Input Methods"; //$NON-NLS-1$
- if (key.equals("SWT_Password")) return "Password:"; //$NON-NLS-1$
- if (key.equals("SWT_Username")) return "User Name:"; //$NON-NLS-1$
- if (key.equals("SWT_Close")) return "Close"; //$NON-NLS-1$
- if (key.equals("SWT_Minimize")) return "Minimize"; //$NON-NLS-1$
- if (key.equals("SWT_Maximize")) return "Maximize"; //$NON-NLS-1$
- if (key.equals("SWT_Restore")) return "Restore"; //$NON-NLS-1$
- if (key.equals("SWT_ShowList")) return "Show List"; //$NON-NLS-1$
- if (key.equals("SWT_Download_Started")) return "Downloading..."; //$NON-NLS-1$
- return key;
-}
-
-public static String getMessage(String key, Object[] args) {
- if (key == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (key.equals("SWT_Download_File")) return "Download: "+args[0]; //$NON-NLS-1$
- if (key.equals("SWT_Download_Location")) return "Saving "+args[0]+" from "+args[1]; //$NON-NLS-1$
- if (key.equals("SWT_Download_Status")) return "Download: "+args[0]+" KB of "+args[1]+" KB"; //$NON-NLS-1$
- return key;
-}
-
-/**
- * Interrupt the current thread.
- * <p>
- * Note that this is not available on CLDC.
- * </p>
- */
-public static void interrupt() {
-}
-
-/**
- * Compares two instances of class String ignoring the case of the
- * characters and answers if they are equal.
- *
- * @param s1 string
- * @param s2 string
- * @return true if the two instances of class String are equal
- */
-public static boolean equalsIgnoreCase(String s1, String s2) {
- if (s1 == s2) return true;
- if (s2 == null || s1.length() != s2.length()) return false;
-
- char[] cArray1 = s1.toCharArray();
- char[] cArray2 = s2.toCharArray();
- int length = s1.length();
- char c1, c2;
-
- for (int index = 0; index < length; index++) {
- c1 = cArray1[index];
- c2 = cArray2[index];
- if (c1 != c2 &&
- Character.toUpperCase(c1) != Character.toUpperCase(c2) &&
- Character.toLowerCase(c1) != Character.toLowerCase(c2)) {
- return false;
- }
- }
- return true;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SWTEventListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SWTEventListener.java
deleted file mode 100644
index db6de2140a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SWTEventListener.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal;
-
-
-/**
- * This interface is the cross-platform version of the
- * java.util.EventListener interface.
- * <p>
- * It is part of our effort to provide support for both J2SE
- * and J2ME platforms. Under this scheme, classes need to
- * implement SWTEventListener instead of java.util.EventListener.
- * </p>
- * <p>
- * Note: java.util.EventListener is not part of CDC and CLDC.
- * </p>
- */
-public interface SWTEventListener {
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SWTEventObject.java b/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SWTEventObject.java
deleted file mode 100644
index a88b322112..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SWTEventObject.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal;
-
-
-/**
- * This class is the cross-platform version of the
- * java.util.EventObject class.
- * <p>
- * It is part of our effort to provide support for both J2SE
- * and J2ME platforms. Under this scheme, classes need to
- * extend SWTEventObject instead of java.util.EventObject.
- * </p>
- * <p>
- * Note: java.util.EventObject is not part of CDC and CLDC.
- * </p>
- */
-public class SWTEventObject implements SerializableCompatibility {
-
- /**
- * The event source.
- */
- protected transient Object source;
-
-/**
- * Constructs a new instance of this class.
- *
- * @param source the object which fired the event
- */
-public SWTEventObject(Object source) {
- if (source != null) this.source = source;
- else throw new IllegalArgumentException();
-}
-
-/**
- * Answers the event source.
- *
- * @return the object which fired the event
- */
-public Object getSource() {
- return source;
-}
-
-/**
- * Answers the string representation of this SWTEventObject.
- *
- * @return the string representation of this SWTEventObject
- */
-public String toString() {
- return getClass().getName() + "[source=" + String.valueOf(source) + ']';
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SerializableCompatibility.java b/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SerializableCompatibility.java
deleted file mode 100644
index ad97888d04..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SerializableCompatibility.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal;
-
-
-/**
- * This interface is the cross-platform version of the
- * java.io.Serializable interface.
- * <p>
- * It is part of our effort to provide support for both J2SE
- * and J2ME platforms. Under this scheme, classes need to
- * implement SerializableCompatibility instead of
- * java.io.Serializable.
- * </p>
- * <p>
- * Note: java.io.Serializable is not part of CLDC.
- * </p>
- * <p>
- * IMPORTANT: CDC mandates Serializable. Behavior on CLDC will have
- * to be discussed further.
- * </p>
- */
-public interface SerializableCompatibility {
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/CloneableCompatibility.java b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/CloneableCompatibility.java
deleted file mode 100644
index 66ab82ab0f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/CloneableCompatibility.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal;
-
-
-/**
- * This interface is the cross-platform version of the
- * java.lang.Cloneable interface.
- * <p>
- * It is part of our effort to provide support for both J2SE
- * and J2ME platforms. Under this scheme, classes need to
- * implement CloneableCompatibility instead of java.lang.Cloneable.
- * </p>
- * <p>
- * Note: java.lang.Cloneable is not part of CLDC.
- * </p>
- */
-public interface CloneableCompatibility extends Cloneable {
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/Compatibility.java b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/Compatibility.java
deleted file mode 100644
index 13e2a65066..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/Compatibility.java
+++ /dev/null
@@ -1,362 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal;
-
-
-import java.io.*;
-import java.text.MessageFormat;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import java.util.zip.InflaterInputStream;
-import java.util.zip.DeflaterOutputStream;
-
-import org.eclipse.swt.SWT;
-
-/**
- * This class is a placeholder for utility methods commonly
- * used on J2SE platforms but not supported on some J2ME
- * profiles.
- * <p>
- * It is part of our effort to provide support for both J2SE
- * and J2ME platforms.
- * </p>
- * <p>
- * IMPORTANT: some of the methods have been modified from their
- * J2SE parents. Refer to the description of each method for
- * specific changes.
- * </p>
- * <ul>
- * <li>Exceptions thrown may differ since J2ME's set of
- * exceptions is a subset of J2SE's one.
- * </li>
- * <li>The range of the mathematic functions is subject to
- * change.
- * </li>
- * </ul>
- */
-public final class Compatibility {
-
-/**
- * Returns the PI constant as a double.
- */
-public static double PI = Math.PI;
-
-static double toRadians = PI / 180;
-
-/**
- * Answers the length of the side adjacent to the given angle
- * of a right triangle. In other words, it returns the integer
- * conversion of length * cos (angle).
- * <p>
- * IMPORTANT: the j2me version has an additional restriction on
- * the argument. length must be between -32767 and 32767 (inclusive).
- * </p>
- *
- * @param angle the angle in degrees
- * @param length the length of the triangle's hypotenuse
- * @return the integer conversion of length * cos (angle)
- */
-public static int cos(int angle, int length) {
- return (int)(Math.cos(angle * toRadians) * length);
-}
-
-/**
- * Answers the length of the side opposite to the given angle
- * of a right triangle. In other words, it returns the integer
- * conversion of length * sin (angle).
- * <p>
- * IMPORTANT: the j2me version has an additional restriction on
- * the argument. length must be between -32767 and 32767 (inclusive).
- * </p>
- *
- * @param angle the angle in degrees
- * @param length the length of the triangle's hypotenuse
- * @return the integer conversion of length * sin (angle)
- */
-public static int sin(int angle, int length) {
- return (int)(Math.sin(angle * toRadians) * length);
-}
-
-/**
- * Answers the most negative (i.e. closest to negative infinity)
- * integer value which is greater than the number obtained by dividing
- * the first argument p by the second argument q.
- *
- * @param p numerator
- * @param q denominator (must be different from zero)
- * @return the ceiling of the rational number p / q.
- */
-public static int ceil(int p, int q) {
- return (int)Math.ceil((float)p / q);
-}
-
-/**
- * Answers whether the indicated file exists or not.
- *
- * @param parent the file's parent directory
- * @param child the file's name
- * @return true if the file exists
- */
-public static boolean fileExists(String parent, String child) {
- return new File (parent, child).exists();
-}
-
-/**
- * Answers the most positive (i.e. closest to positive infinity)
- * integer value which is less than the number obtained by dividing
- * the first argument p by the second argument q.
- *
- * @param p numerator
- * @param q denominator (must be different from zero)
- * @return the floor of the rational number p / q.
- */
-public static int floor(int p, int q) {
- return (int)Math.floor((double)p / q);
-}
-
-/**
- * Answers the result of rounding to the closest integer the number obtained
- * by dividing the first argument p by the second argument q.
- * <p>
- * IMPORTANT: the j2me version has an additional restriction on
- * the arguments. p must be within the range 0 - 32767 (inclusive).
- * q must be within the range 1 - 32767 (inclusive).
- * </p>
- *
- * @param p numerator
- * @param q denominator (must be different from zero)
- * @return the closest integer to the rational number p / q
- */
-public static int round(int p, int q) {
- return Math.round((float)p / q);
-}
-
-/**
- * Returns 2 raised to the power of the argument.
- *
- * @param n an int value between 0 and 30 (inclusive)
- * @return 2 raised to the power of the argument
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the argument is not between 0 and 30 (inclusive)</li>
- * </ul>
- */
-public static int pow2(int n) {
- if (n >= 1 && n <= 30)
- return 2 << (n - 1);
- else if (n != 0) {
- SWT.error(SWT.ERROR_INVALID_RANGE);
- }
- return 1;
-}
-
-/**
- * Create an DeflaterOutputStream if such things are supported.
- *
- * @param stream the output stream
- * @return a deflater stream or <code>null</code>
- * @exception IOException
- *
- * @since 3.4
- */
-public static OutputStream newDeflaterOutputStream(OutputStream stream) throws IOException {
- return new DeflaterOutputStream(stream);
-}
-
-/**
- * Open a file if such things are supported.
- *
- * @param filename the name of the file to open
- * @return a stream on the file if it could be opened.
- * @exception IOException
- */
-public static InputStream newFileInputStream(String filename) throws IOException {
- return new FileInputStream(filename);
-}
-
-/**
- * Open a file if such things are supported.
- *
- * @param filename the name of the file to open
- * @return a stream on the file if it could be opened.
- * @exception IOException
- */
-public static OutputStream newFileOutputStream(String filename) throws IOException {
- return new FileOutputStream(filename);
-}
-
-/**
- * Create an InflaterInputStream if such things are supported.
- *
- * @param stream the input stream
- * @return a inflater stream or <code>null</code>
- * @exception IOException
- *
- * @since 3.3
- */
-public static InputStream newInflaterInputStream(InputStream stream) throws IOException {
- return new BufferedInputStream(new InflaterInputStream(stream));
-}
-
-/**
- * Answers whether the character is a letter.
- *
- * @param c the character
- * @return true when the character is a letter
- */
-public static boolean isLetter(char c) {
- return Character.isLetter(c);
-}
-
-/**
- * Answers whether the character is a letter or a digit.
- *
- * @param c the character
- * @return true when the character is a letter or a digit
- */
-public static boolean isLetterOrDigit(char c) {
- return Character.isLetterOrDigit(c);
-}
-
-/**
- * Answers whether the character is a Unicode space character.
- *
- * @param c the character
- * @return true when the character is a Unicode space character
- */
-public static boolean isSpaceChar(char c) {
- return Character.isSpaceChar(c);
-}
-
-/**
- * Answers whether the character is a whitespace character.
- *
- * @param c the character to test
- * @return true if the character is whitespace
- */
-public static boolean isWhitespace(char c) {
- return Character.isWhitespace(c);
-}
-
-/**
- * Execute a program in a separate platform process if the
- * underlying platform support this.
- * <p>
- * The new process inherits the environment of the caller.
- * </p>
- *
- * @param prog the name of the program to execute
- *
- * @exception IOException
- * if the program cannot be executed
- * @exception SecurityException
- * if the current SecurityManager disallows program execution
- */
-public static void exec(String prog) throws java.io.IOException {
- Runtime.getRuntime().exec(prog);
-}
-
-/**
- * Execute progArray[0] in a separate platform process if the
- * underlying platform support this.
- * <p>
- * The new process inherits the environment of the caller.
- * <p>
- *
- * @param progArray array containing the program to execute and its arguments
- *
- * @exception IOException
- * if the program cannot be executed
- * @exception SecurityException
- * if the current SecurityManager disallows program execution
- */
-public static void exec(String[] progArray) throws java.io.IOException{
- Runtime.getRuntime().exec(progArray);
-}
-
-private static ResourceBundle msgs = null;
-
-/**
- * Returns the NLS'ed message for the given argument. This is only being
- * called from SWT.
- *
- * @param key the key to look up
- * @return the message for the given key
- *
- * @see SWT#getMessage(String)
- */
-public static String getMessage(String key) {
- String answer = key;
-
- if (key == null) {
- SWT.error (SWT.ERROR_NULL_ARGUMENT);
- }
- if (msgs == null) {
- try {
- msgs = ResourceBundle.getBundle("org.eclipse.swt.internal.SWTMessages"); //$NON-NLS-1$
- } catch (MissingResourceException ex) {
- answer = key + " (no resource bundle)"; //$NON-NLS-1$
- }
- }
- if (msgs != null) {
- try {
- answer = msgs.getString(key);
- } catch (MissingResourceException ex2) {}
- }
- return answer;
-}
-
-public static String getMessage(String key, Object[] args) {
- String answer = key;
-
- if (key == null || args == null) {
- SWT.error (SWT.ERROR_NULL_ARGUMENT);
- }
- if (msgs == null) {
- try {
- msgs = ResourceBundle.getBundle("org.eclipse.swt.internal.SWTMessages"); //$NON-NLS-1$
- } catch (MissingResourceException ex) {
- answer = key + " (no resource bundle)"; //$NON-NLS-1$
- }
- }
- if (msgs != null) {
- try {
- MessageFormat formatter = new MessageFormat("");
- formatter.applyPattern(msgs.getString(key));
- answer = formatter.format(args);
- } catch (MissingResourceException ex2) {}
- }
- return answer;
-}
-
-/**
- * Interrupt the current thread.
- * <p>
- * Note that this is not available on CLDC.
- * </p>
- */
-public static void interrupt() {
- Thread.currentThread().interrupt();
-}
-
-/**
- * Compares two instances of class String ignoring the case of the
- * characters and answers if they are equal.
- *
- * @param s1 string
- * @param s2 string
- * @return true if the two instances of class String are equal
- */
-public static boolean equalsIgnoreCase(String s1, String s2) {
- return s1.equalsIgnoreCase(s2);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTEventListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTEventListener.java
deleted file mode 100644
index b242904b13..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTEventListener.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal;
-
-
-import java.util.EventListener;
-
-/**
- * This interface is the cross-platform version of the
- * java.util.EventListener interface.
- * <p>
- * It is part of our effort to provide support for both J2SE
- * and J2ME platforms. Under this scheme, classes need to
- * implement SWTEventListener instead of java.util.EventListener.
- * </p>
- * <p>
- * Note: java.util.EventListener is not part of CDC and CLDC.
- * </p>
- */
-public interface SWTEventListener extends EventListener {
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTEventObject.java b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTEventObject.java
deleted file mode 100644
index 2296a36250..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTEventObject.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal;
-
-
-import java.util.EventObject;
-
-/**
- * This class is the cross-platform version of the
- * java.util.EventObject class.
- * <p>
- * It is part of our effort to provide support for both J2SE
- * and J2ME platforms. Under this scheme, classes need to
- * extend SWTEventObject instead of java.util.EventObject.
- * </p>
- * <p>
- * Note: java.util.EventObject is not part of CDC and CLDC.
- * </p>
- */
-public class SWTEventObject extends EventObject {
-
- static final long serialVersionUID = 3258125873411470903L;
-
-/**
- * Constructs a new instance of this class.
- *
- * @param source the object which fired the event
- */
-public SWTEventObject(Object source) {
- super(source);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages.properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages.properties
deleted file mode 100644
index 04dbd0f4e5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages.properties
+++ /dev/null
@@ -1,75 +0,0 @@
-###############################################################################
-# Copyright (c) 2000, 2009 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
-# http://www.eclipse.org/legal/epl-v10.html
-#
-# Contributors:
-# IBM Corporation - initial API and implementation
-###############################################################################
-SWT_Yes=Yes
-SWT_No=No
-SWT_OK=OK
-SWT_Cancel=Cancel
-SWT_Abort=Abort
-SWT_Retry=Retry
-SWT_Ignore=Ignore
-SWT_Sample=Sample
-SWT_A_Sample_Text=A Sample Text
-SWT_Selection=Selection
-SWT_Current_Selection=Current Selection
-SWT_Font=Font
-SWT_Color=Color
-SWT_Extended_style=Extended style
-SWT_Size=Size
-SWT_Style=Style
-SWT_Save=Save
-SWT_Character_set=Character set
-SWT_ColorDialog_Title=Colors
-SWT_FontDialog_Title=Fonts
-SWT_FontSet=Font Set
-SWT_NewFont=New Font
-SWT_Remove=Remove
-SWT_Up=Up
-SWT_Down=Down
-SWT_Charset_Western=western
-SWT_Charset_EastEuropean=eastern
-SWT_Charset_SouthEuropean=southern
-SWT_Charset_NorthEuropean=northern
-SWT_Charset_Cyrillic=cyrillic
-SWT_Charset_Arabic=arabic
-SWT_Charset_Greek=greek
-SWT_Charset_Hebrew=hebrew
-SWT_Charset_Turkish=turkish
-SWT_Charset_Nordic=nordic
-SWT_Charset_Thai=thai
-SWT_Charset_BalticRim=baltic rim
-SWT_Charset_Celtic=celtic
-SWT_Charset_Euro=euro
-SWT_Charset_Romanian=romanian
-SWT_Charset_SimplifiedChinese=simp. chinese
-SWT_Charset_TraditionalChinese=trad. chinese
-SWT_Charset_Japanese=japanese
-SWT_Charset_Korean=korean
-SWT_Charset_Unicode=unicode
-SWT_Charset_ASCII=ASCII
-SWT_InputMethods=Input Methods
-SWT_Password=Password:
-SWT_Username=User Name:
-SWT_Switch=Switch
-SWT_Press=Press
-SWT_Open=Open
-SWT_Close=Close
-SWT_Minimize=Minimize
-SWT_Maximize=Maximize
-SWT_Restore=Restore
-SWT_ShowList=Show List
-SWT_FileDownload=File Download
-SWT_Download_File=Download: {0}
-SWT_Download_Location=Saving {0} from {1}
-SWT_Download_Started=Downloading...
-SWT_Download_Status=Download: {0,number,integer} KB of {1,number,integer} KB
-SWT_Authentication_Required=Authentication Required
-SWT_Enter_Username_and_Password=Enter user name and password for {0} at {1}
-SWT_Page_Load_Failed=Page load failed with error: {0} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ar._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ar._properties
deleted file mode 100644
index c14fda9b60..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ar._properties
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=\u0646\u0639\u0645
-SWT_No=\u0644\u0627
-SWT_OK=\u062d\u0633\u0646\u0627
-SWT_Cancel=\u0627\u0644\u063a\u0627\u0621
-SWT_Abort=\u0627\u0646\u0647\u0627\u0621
-SWT_Ignore=\u062a\u062c\u0627\u0647\u0644
-SWT_Sample=\u0646\u0645\u0648\u0630\u062c
-SWT_Selection=\u0627\u0644\u0627\u062e\u062a\u064a\u0627\u0631
-SWT_Font=\u0637\u0627\u0642\u0645 \u0627\u0644\u0637\u0628\u0627\u0639\u0629
-SWT_Color=\u0627\u0644\u0644\u0648\u0646
-SWT_Size=\u062a\u063a\u064a\u064a\u0631 \u062d\u062c\u0645
-SWT_Style=\u0627\u0644\u0646\u0645\u0637
-SWT_Save=\u062d\u0641\u0638
-SWT_FontDialog_Title=\u0623\u0637\u0642\u0645 \u0627\u0644\u0637\u0628\u0627\u0639\u0629
-SWT_Remove=\u0627\u0632\u0627\u0644\u0629
-SWT_Up=\u0644\u0623\u0639\u0644\u0649
-SWT_Down=\u0644\u0623\u0633\u0641\u0644
-SWT_Charset_ASCII=ASCII
-SWT_Password=\u0643\u0644\u0645\u0629 \u0627\u0644\u0633\u0631\u064a\u0629:
-SWT_Open=\u0641\u062a\u062d
-SWT_Close=\u0627\u063a\u0644\u0627\u0642
-SWT_Minimize=\u062a\u0635\u063a\u064a\u0631
-SWT_Maximize=\u062a\u0643\u0628\u064a\u0631
-SWT_Restore=\u0627\u0633\u062a\u0639\u0627\u062f\u0629 \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_cs._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_cs._properties
deleted file mode 100644
index f6c9664d0f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_cs._properties
+++ /dev/null
@@ -1,29 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=Ano
-SWT_No=Ne
-SWT_OK=OK
-SWT_Cancel=Storno
-SWT_Abort=P\u0159ed\u010dasn\u011b ukon\u010dit
-SWT_Retry=Zkusit znovu
-SWT_Ignore=Ignorovat
-SWT_Sample=Uk\u00e1zka
-SWT_Selection=V\u00fdb\u011br
-SWT_Current_Selection=Aktu\u00e1ln\u00ed v\u00fdb\u011br
-SWT_Font=P\u00edsmo
-SWT_Color=Barva
-SWT_Size=Velikost
-SWT_Style=Styl
-SWT_Save=Ulo\u017eit
-SWT_ColorDialog_Title=Barvy
-SWT_FontDialog_Title=P\u00edsma
-SWT_Remove=Odstranit
-SWT_Up=Nahoru
-SWT_Down=Dol\u016f
-SWT_Charset_ASCII=ASCII
-SWT_Password=Heslo:
-SWT_Username=U\u017eivatelsk\u00e9 jm\u00e9no:
-SWT_Open=Otev\u0159\u00edt
-SWT_Close=Zav\u0159\u00edt
-SWT_Minimize=Minimalizovat
-SWT_Maximize=Maximalizovat
-SWT_Restore=Obnovit \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_da._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_da._properties
deleted file mode 100644
index e6efe92663..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_da._properties
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=Ja
-SWT_No=Nej
-SWT_OK=OK
-SWT_Cancel=Annull\u00e9r
-SWT_Abort=Afbryd
-SWT_Ignore=Ignor\u00e9r
-SWT_Sample=Eksempel
-SWT_Selection=Valg
-SWT_Font=Font
-SWT_Color=Farve
-SWT_Size=St\u00f8rrelse
-SWT_Style=Typografi
-SWT_Save=Gem
-SWT_FontDialog_Title=Fonte
-SWT_Remove=Fjern
-SWT_Up=Op
-SWT_Down=Ned
-SWT_Charset_ASCII=ASCII
-SWT_Password=Kodeord:
-SWT_Open=\u00c5bn
-SWT_Close=Luk
-SWT_Minimize=Minim\u00e9r
-SWT_Maximize=Maksim\u00e9r
-SWT_Restore=Gendan \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_de._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_de._properties
deleted file mode 100644
index 28563b7a11..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_de._properties
+++ /dev/null
@@ -1,65 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=Ja
-SWT_No=Nein
-SWT_OK=OK
-SWT_Cancel=Abbrechen
-SWT_Abort=Abbrechen
-SWT_Retry=Erneut versuchen
-SWT_Ignore=Ignorieren
-SWT_Sample=Beispiel
-SWT_A_Sample_Text=Beispieltext
-SWT_Selection=Auswahl
-SWT_Current_Selection=Aktuelle Auswahl
-SWT_Font=Schriftart
-SWT_Color=Farbe
-SWT_Extended_style=Erweiterter Stil
-SWT_Size=Gr\u00f6\u00dfe
-SWT_Style=Darstellung
-SWT_Save=Speichern
-SWT_Character_set=Zeichensatz
-SWT_ColorDialog_Title=Farben
-SWT_FontDialog_Title=Schriftarten
-SWT_FontSet=Schriftsatz
-SWT_NewFont=Neue Schriftart
-SWT_Remove=Entfernen
-SWT_Up=Nach oben
-SWT_Down=Nach unten
-SWT_Charset_Western=westlich
-SWT_Charset_EastEuropean=\u00f6stlich
-SWT_Charset_SouthEuropean=s\u00fcdlich
-SWT_Charset_NorthEuropean=n\u00f6rdlich
-SWT_Charset_Cyrillic=kyrillisch
-SWT_Charset_Arabic=arabisch
-SWT_Charset_Greek=Griechisch
-SWT_Charset_Hebrew=Hebr\u00e4isch
-SWT_Charset_Turkish=T\u00fcrkisch
-SWT_Charset_Nordic=Nordisch
-SWT_Charset_Thai=Thail\u00e4ndisch
-SWT_Charset_BalticRim=Baltisch
-SWT_Charset_Celtic=Keltisch
-SWT_Charset_Euro=Euro
-SWT_Charset_Romanian=Rum\u00e4nisch
-SWT_Charset_SimplifiedChinese=chinesisch, vereinfacht
-SWT_Charset_TraditionalChinese=chinesisch, traditionell
-SWT_Charset_Japanese=Japanisch
-SWT_Charset_Korean=Koreanisch
-SWT_Charset_Unicode=Unicode
-SWT_Charset_ASCII=ASCII
-SWT_InputMethods=Eingabemethoden
-SWT_Password=Kennwort\:
-SWT_Username=Benutzername:
-SWT_Switch=Schalter
-SWT_Press=Dr\u00fccken
-SWT_Open=\u00d6ffnen
-SWT_Close=Schlie\u00dfen
-SWT_Minimize=Minimieren
-SWT_Maximize=Maximieren
-SWT_Restore=Wiederherstellen
-SWT_ShowList=Liste anzeigen
-SWT_FileDownload=Datei-Download
-SWT_Download_File=Herunterladen: {0}
-SWT_Download_Location=Speichern von {0} von {1}
-SWT_Download_Started=Herunterladen\...
-SWT_Download_Status=Download: {0,Zahl,Ganzzahl} KB von {1,Zahl,Ganzzahl} KB
-SWT_Authentication_Required=Authentifizierung erforderlich
-SWT_Enter_Username_and_Password=Benutzernamen und Kennwort f\u00fcr {0} unter {1} eingeben \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_el._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_el._properties
deleted file mode 100644
index a14609ec1a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_el._properties
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=\u039d\u03b1\u03b9
-SWT_No=\u038c\u03c7\u03b9
-SWT_OK=OK
-SWT_Cancel=\u0391\u03ba\u03cd\u03c1\u03c9\u03c3\u03b7
-SWT_Abort=\u039c\u03b1\u03c4\u03b1\u03af\u03c9\u03c3\u03b7
-SWT_Ignore=\u03a0\u03b1\u03c1\u03ac\u03b2\u03bb\u03b5\u03c8\u03b7
-SWT_Sample=\u0394\u03b5\u03af\u03b3\u03bc\u03b1
-SWT_Selection=\u0395\u03c0\u03b9\u03bb\u03bf\u03b3\u03ae
-SWT_Font=\u0393\u03c1\u03b1\u03bc\u03bc\u03b1\u03c4\u03bf\u03c3\u03b5\u03b9\u03c1\u03ac
-SWT_Color=\u03a7\u03c1\u03ce\u03bc\u03b1
-SWT_Size=\u039c\u03ad\u03b3\u03b5\u03b8\u03bf\u03c2
-SWT_Style=\u03a3\u03c4\u03c5\u03bb
-SWT_Save=\u0391\u03c0\u03bf\u03b8\u03ae\u03ba\u03b5\u03c5\u03c3\u03b7
-SWT_FontDialog_Title=\u0393\u03c1\u03b1\u03bc\u03bc\u03b1\u03c4\u03bf\u03c3\u03b5\u03b9\u03c1\u03ad\u03c2
-SWT_Remove=\u0391\u03c6\u03b1\u03af\u03c1\u03b5\u03c3\u03b7
-SWT_Up=\u03a0\u03ac\u03bd\u03c9
-SWT_Down=\u039a\u03ac\u03c4\u03c9
-SWT_Charset_ASCII=ASCII
-SWT_Password=\u039a\u03c9\u03b4\u03b9\u03ba\u03cc\u03c2 \u03c0\u03c1\u03cc\u03c3\u03b2\u03b1\u03c3\u03b7\u03c2:
-SWT_Open=\u0386\u03bd\u03bf\u03b9\u03b3\u03bc\u03b1
-SWT_Close=\u039a\u03bb\u03b5\u03af\u03c3\u03b9\u03bc\u03bf
-SWT_Minimize=\u0395\u03bb\u03b1\u03c7\u03b9\u03c3\u03c4\u03bf\u03c0\u03bf\u03af\u03b7\u03c3\u03b7
-SWT_Maximize=\u039c\u03b5\u03b3\u03b9\u03c3\u03c4\u03bf\u03c0\u03bf\u03af\u03b7\u03c3\u03b7
-SWT_Restore=\u0395\u03c0\u03b1\u03bd\u03b1\u03c6\u03bf\u03c1\u03ac \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_es._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_es._properties
deleted file mode 100644
index 6c891db675..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_es._properties
+++ /dev/null
@@ -1,57 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=S\u00ed
-SWT_No=No
-SWT_OK=Aceptar
-SWT_Cancel=Cancelar
-SWT_Abort=Terminar anormalmente
-SWT_Retry=Reintentar
-SWT_Ignore=Omitir
-SWT_Sample=Muestra
-SWT_A_Sample_Text=Un Texto de Muestra
-SWT_Selection=Selecci\u00f3n
-SWT_Current_Selection=Seleccion Actual
-SWT_Font=Fuente
-SWT_Color=Color
-SWT_Extended_style=Estilo extendido
-SWT_Size=Tama\u00f1o
-SWT_Style=Estilo
-SWT_Save=Guardar
-SWT_Character_set=Conjunto de caracteres
-SWT_ColorDialog_Title=Colores
-SWT_FontDialog_Title=Fuentes
-SWT_FontSet=Conjunto de Fuentes
-SWT_NewFont=Nueva Fuente
-SWT_Remove=Eliminar
-SWT_Up=Subir
-SWT_Down=Bajar
-SWT_Charset_Western=oeste
-SWT_Charset_EastEuropean=este
-SWT_Charset_SouthEuropean=sur
-SWT_Charset_NorthEuropean=norte
-SWT_Charset_Arabic=ar\u00e1bico
-SWT_Charset_Greek=griego
-SWT_Charset_Hebrew=hebreo
-SWT_Charset_Turkish=turco
-SWT_Charset_Nordic=noruego
-SWT_Charset_Celtic=celta
-SWT_Charset_Romanian=rumano
-SWT_Charset_SimplifiedChinese=chino simple
-SWT_Charset_TraditionalChinese=chino tradicional
-SWT_Charset_Japanese=japones
-SWT_Charset_Korean=coreano
-SWT_Charset_Unicode=unicode
-SWT_Charset_ASCII=ASCII
-SWT_Password=Contrase\u00f1a:
-SWT_Username=Nombre de Usuario:
-SWT_Switch=Cambiar
-SWT_Press=Presionar
-SWT_Open=Abrir
-SWT_Close=Cerrar
-SWT_Minimize=Minimizar
-SWT_Maximize=Maximizar
-SWT_Restore=Restaurar
-SWT_ShowList=Mostrar Lista
-SWT_FileDownload=Descarga Fichero
-SWT_Download_File=Descarga: {0}
-SWT_Download_Location=Guardando {0} desde {1}
-SWT_Download_Started=Descargando... \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_fi._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_fi._properties
deleted file mode 100644
index 796ae744d5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_fi._properties
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=Kyll\u00e4
-SWT_No=Ei
-SWT_OK=OK
-SWT_Cancel=Peruuta
-SWT_Abort=Keskeyt\u00e4
-SWT_Ignore=Ohita
-SWT_Sample=Malli
-SWT_Selection=Valinta
-SWT_Font=Fontti
-SWT_Color=V\u00e4ri
-SWT_Size=Koko
-SWT_Style=Tyyli
-SWT_Save=Tallenna
-SWT_FontDialog_Title=Fontit
-SWT_Remove=Poista
-SWT_Up=Yl\u00f6s
-SWT_Down=Alas
-SWT_Charset_ASCII=ASCII
-SWT_Password=Salasana:
-SWT_Open=Avaa
-SWT_Close=Sulje
-SWT_Minimize=Pienenn\u00e4
-SWT_Maximize=Suurenna
-SWT_Restore=Palauta \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_fr._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_fr._properties
deleted file mode 100644
index b5ea714273..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_fr._properties
+++ /dev/null
@@ -1,65 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=Oui
-SWT_No=Non
-SWT_OK=OK
-SWT_Cancel=Annuler
-SWT_Abort=Abandonner
-SWT_Retry=Recommencer
-SWT_Ignore=Ignorer
-SWT_Sample=Exemple
-SWT_A_Sample_Text=Exemple de texte
-SWT_Selection=S\u00e9lection
-SWT_Current_Selection=S\u00e9lection en cours
-SWT_Font=Police
-SWT_Color=Couleur
-SWT_Extended_style=Style \u00e9tendu
-SWT_Size=Taille
-SWT_Style=Style
-SWT_Save=Enregistrer
-SWT_Character_set=Jeu de caract\u00e8res
-SWT_ColorDialog_Title=Couleurs
-SWT_FontDialog_Title=Polices
-SWT_FontSet=Jeu de polices
-SWT_NewFont=Nouvelle police
-SWT_Remove=Supprimer
-SWT_Up=Haut
-SWT_Down=Bas
-SWT_Charset_Western=occidental
-SWT_Charset_EastEuropean=oriental
-SWT_Charset_SouthEuropean=austral
-SWT_Charset_NorthEuropean=septentrional
-SWT_Charset_Cyrillic=cyrillique
-SWT_Charset_Arabic=arabe
-SWT_Charset_Greek=grec
-SWT_Charset_Hebrew=h\u00e9breu
-SWT_Charset_Turkish=turc
-SWT_Charset_Nordic=nordique
-SWT_Charset_Thai=tha\u00ef
-SWT_Charset_BalticRim=baltique
-SWT_Charset_Celtic=celtique
-SWT_Charset_Euro=euro
-SWT_Charset_Romanian=roumain
-SWT_Charset_SimplifiedChinese=chinois simplifi\u00e9
-SWT_Charset_TraditionalChinese=chinois traditionnel
-SWT_Charset_Japanese=japonais
-SWT_Charset_Korean=cor\u00e9en
-SWT_Charset_Unicode=unicode
-SWT_Charset_ASCII=ASCII
-SWT_InputMethods=M\u00e9thodes d'entr\u00e9e
-SWT_Password=Mot de passe \:
-SWT_Username=Nom d'utilisateur\u00a0:
-SWT_Switch=Commuter
-SWT_Press=Appuyer
-SWT_Open=Ouvrir
-SWT_Close=Fermer
-SWT_Minimize=R\u00e9duire
-SWT_Maximize=Agrandir
-SWT_Restore=Restaurer
-SWT_ShowList=Afficher la liste
-SWT_FileDownload=T\u00e9l\u00e9chargement de fichiers
-SWT_Download_File=T\u00e9l\u00e9charger\u00a0: {0}
-SWT_Download_Location=Enregistrement de {0} depuis {1}
-SWT_Download_Started=T\u00e9l\u00e9chargement \...
-SWT_Download_Status=T\u00e9l\u00e9charger\u00a0: {0,number,integer} ko de {1,number,integer} ko
-SWT_Authentication_Required=Authentification requise
-SWT_Enter_Username_and_Password=Entrer le nom d'utilisateur et le mot de passe pour {0} au niveau de {1} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_hu._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_hu._properties
deleted file mode 100644
index f2dd2c1438..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_hu._properties
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=Igen
-SWT_No=Nem
-SWT_OK=OK
-SWT_Cancel=M\u00e9gse
-SWT_Abort=Megszak\u00edt\u00e1s
-SWT_Ignore=Mell\u0151z\u00e9s
-SWT_Sample=Minta
-SWT_Selection=Kiv\u00e1laszt\u00e1s
-SWT_Font=Bet\u0171t\u00edpus
-SWT_Color=Sz\u00edn
-SWT_Size=M\u00e9ret
-SWT_Style=St\u00edlus
-SWT_Save=Ment\u00e9s
-SWT_FontDialog_Title=Bet\u0171t\u00edpusok
-SWT_Remove=Elt\u00e1vol\u00edt\u00e1s
-SWT_Up=Fel
-SWT_Down=Le
-SWT_Charset_ASCII=ASCII
-SWT_Password=Jelsz\u00f3:
-SWT_Open=Megnyit\u00e1s
-SWT_Close=Bez\u00e1r\u00e1s
-SWT_Minimize=Kis m\u00e9ret
-SWT_Maximize=Teljes m\u00e9ret
-SWT_Restore=Vissza\u00e1ll\u00edt\u00e1s \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_it._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_it._properties
deleted file mode 100644
index bb229e6cb5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_it._properties
+++ /dev/null
@@ -1,63 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=S\u00ec
-SWT_No=No
-SWT_OK=OK
-SWT_Cancel=Annulla
-SWT_Abort=Interrompi
-SWT_Retry=Riprova
-SWT_Ignore=Ignora
-SWT_Sample=Esempio
-SWT_A_Sample_Text=Testo di esempio
-SWT_Selection=Selezione
-SWT_Current_Selection=Selezione corrente
-SWT_Font=Tipo di carattere
-SWT_Color=Colore
-SWT_Extended_style=Stile esteso
-SWT_Size=Dimensione
-SWT_Style=Stile
-SWT_Save=Salva
-SWT_Character_set=Insieme di caratteri
-SWT_ColorDialog_Title=Colori
-SWT_FontDialog_Title=Tipi di carattere
-SWT_FontSet=Insieme di tipi di carattere
-SWT_NewFont=Nuovo tipo di carattere
-SWT_Remove=Rimuovi
-SWT_Up=Su
-SWT_Down=Gi\u00f9
-SWT_Charset_Western=occidentali
-SWT_Charset_EastEuropean=orientali
-SWT_Charset_SouthEuropean=area del Mediterraneo
-SWT_Charset_NorthEuropean=area settentrionale
-SWT_Charset_Cyrillic=cirillici
-SWT_Charset_Arabic=arabi
-SWT_Charset_Greek=greci
-SWT_Charset_Hebrew=ebraici
-SWT_Charset_Turkish=turchi
-SWT_Charset_Nordic=nordici
-SWT_Charset_Thai=thai
-SWT_Charset_BalticRim=del Baltico
-SWT_Charset_Celtic=celtici
-SWT_Charset_Euro=europei
-SWT_Charset_Romanian=rumeni
-SWT_Charset_SimplifiedChinese=cinesi sempl.
-SWT_Charset_TraditionalChinese=cinesi trad.
-SWT_Charset_Japanese=giapponesi
-SWT_Charset_Korean=coreani
-SWT_Charset_Unicode=unicode
-SWT_Charset_ASCII=ASCII
-SWT_InputMethods=Metodi di input
-SWT_Password=Password:
-SWT_Username=Nome utente:
-SWT_Switch=Passa a
-SWT_Press=Premi
-SWT_Open=Apertura
-SWT_Close=Chiudi
-SWT_Minimize=Riduci a icona
-SWT_Maximize=Ingrandisci
-SWT_Restore=Ripristina
-SWT_ShowList=Mostra elenco
-SWT_FileDownload=Download file
-SWT_Download_File=Download: {0}
-SWT_Download_Location=Salvataggio di {0} da {1}
-SWT_Download_Started=Download in corso...
-SWT_Download_Status=Download: {0,number,integer} KB di {1,number,integer} KB \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_iw._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_iw._properties
deleted file mode 100644
index 0e9d119997..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_iw._properties
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=\u05db\u05df
-SWT_No=\u05dc\u05d0
-SWT_OK=OK
-SWT_Cancel=\u05d1\u05d9\u05d8\u05d5\u05dc
-SWT_Abort=Abort
-SWT_Ignore=Ignore
-SWT_Selection=Selection
-SWT_Font=\u05d2\u05d5\u05e4\u05df
-SWT_Style=Style
-SWT_Save=\u05e9\u05de\u05d9\u05e8\u05d4
-SWT_Remove=Remove
-SWT_Up=Up
-SWT_Down=Down
-SWT_Charset_ASCII=ASCII
-SWT_Password=\u05e1\u05d9\u05e1\u05de\u05d4:
-SWT_Open=Open
-SWT_Close=\u05e1\u05d2\u05d9\u05e8\u05d4
-SWT_Minimize=\u05de\u05d6\u05e2\u05d5\u05e8
-SWT_Maximize=\u05d4\u05d2\u05d3\u05dc\u05d4
-SWT_Restore=\u05e9\u05d7\u05d6\u05d5\u05e8 \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ja._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ja._properties
deleted file mode 100644
index 3f48738490..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ja._properties
+++ /dev/null
@@ -1,65 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=\u306f\u3044
-SWT_No=\u3044\u3044\u3048
-SWT_OK=OK
-SWT_Cancel=\u30ad\u30e3\u30f3\u30bb\u30eb
-SWT_Abort=\u4e2d\u65ad
-SWT_Retry=\u518d\u8a66\u884c
-SWT_Ignore=\u7121\u8996
-SWT_Sample=\u30b5\u30f3\u30d7\u30eb
-SWT_A_Sample_Text=\u30b5\u30f3\u30d7\u30eb\u30c6\u30ad\u30b9\u30c8
-SWT_Selection=\u9078\u629e
-SWT_Current_Selection=\u73fe\u5728\u306e\u9078\u629e
-SWT_Font=\u30d5\u30a9\u30f3\u30c8
-SWT_Color=\u8272
-SWT_Extended_style=\u62e1\u5f35\u30b9\u30bf\u30a4\u30eb
-SWT_Size=\u30b5\u30a4\u30ba
-SWT_Style=\u30b9\u30bf\u30a4\u30eb
-SWT_Save=\u4fdd\u7ba1
-SWT_Character_set=\u6587\u5b57\u30bb\u30c3\u30c8
-SWT_ColorDialog_Title=\u8272
-SWT_FontDialog_Title=\u30d5\u30a9\u30f3\u30c8
-SWT_FontSet=\u30d5\u30a9\u30f3\u30c8\u30bb\u30c3\u30c8
-SWT_NewFont=\u65b0\u3057\u3044\u30d5\u30a9\u30f3\u30c8
-SWT_Remove=\u524a\u9664
-SWT_Up=\u4e0a\u3078
-SWT_Down=\u4e0b\u3078
-SWT_Charset_Western=\u897f\u90e8
-SWT_Charset_EastEuropean=\u6771\u90e8
-SWT_Charset_SouthEuropean=\u5357\u90e8
-SWT_Charset_NorthEuropean=\u5317\u90e8
-SWT_Charset_Cyrillic=\u30ad\u30ea\u30eb\u8a9e
-SWT_Charset_Arabic=\u30a2\u30e9\u30d3\u30a2\u8a9e
-SWT_Charset_Greek=\u30ae\u30ea\u30b7\u30e3\u8a9e
-SWT_Charset_Hebrew=\u30d8\u30d6\u30e9\u30a4\u8a9e
-SWT_Charset_Turkish=\u30c8\u30eb\u30b3\u8a9e
-SWT_Charset_Nordic=\u30ce\u30eb\u30a6\u30a7\u30fc\u8a9e
-SWT_Charset_Thai=\u30bf\u30a4\u8a9e
-SWT_Charset_BalticRim=\u30d0\u30eb\u30c8\u6d77\u5468\u8fba
-SWT_Charset_Celtic=\u30b1\u30eb\u30c8\u8a9e
-SWT_Charset_Euro=\u30e6\u30fc\u30ed
-SWT_Charset_Romanian=\u30eb\u30fc\u30de\u30cb\u30a2\u8a9e
-SWT_Charset_SimplifiedChinese=\u7c21\u4f53\u5b57\u4e2d\u56fd\u8a9e
-SWT_Charset_TraditionalChinese=\u7e41\u4f53\u5b57\u4e2d\u56fd\u8a9e
-SWT_Charset_Japanese=\u65e5\u672c\u8a9e
-SWT_Charset_Korean=\u97d3\u56fd\u8a9e
-SWT_Charset_Unicode=Unicode
-SWT_Charset_ASCII=ASCII
-SWT_InputMethods=\u5165\u529b\u30e1\u30bd\u30c3\u30c9
-SWT_Password=\u30d1\u30b9\u30ef\u30fc\u30c9\:
-SWT_Username=\u30e6\u30fc\u30b6\u540d :
-SWT_Switch=\u5207\u308a\u66ff\u3048
-SWT_Press=\u62bc\u3059
-SWT_Open=\u958b\u304f
-SWT_Close=\u9589\u3058\u308b
-SWT_Minimize=\u6700\u5c0f\u5316
-SWT_Maximize=\u6700\u5927\u5316
-SWT_Restore=\u5fa9\u5143
-SWT_ShowList=\u30ea\u30b9\u30c8\u3092\u8868\u793a
-SWT_FileDownload=\u30d5\u30a1\u30a4\u30eb\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9
-SWT_Download_File=\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9 : {0}
-SWT_Download_Location={1} \u304b\u3089 {0} \u3092\u4fdd\u5b58\u3057\u3066\u3044\u307e\u3059
-SWT_Download_Started=\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9...
-SWT_Download_Status=\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9 : {0,number,integer} KB / {1,number,integer} KB
-SWT_Authentication_Required=\u8a8d\u8a3c\u304c\u5fc5\u8981\u3067\u3059
-SWT_Enter_Username_and_Password={1} \u306b\u304a\u3051\u308b {0} \u306e\u30e6\u30fc\u30b6\u540d\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044 \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ko._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ko._properties
deleted file mode 100644
index 2adca26b77..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ko._properties
+++ /dev/null
@@ -1,65 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=\uc608
-SWT_No=\uc544\ub2c8\uc624
-SWT_OK=\ud655\uc778
-SWT_Cancel=\ucde8\uc18c
-SWT_Abort=\uc911\ub2e8
-SWT_Retry=\uc7ac\uc2dc\ub3c4
-SWT_Ignore=\ubb34\uc2dc
-SWT_Sample=\uc0d8\ud50c
-SWT_A_Sample_Text=\uc0d8\ud50c \ud14d\uc2a4\ud2b8
-SWT_Selection=\uc120\ud0dd\uc0ac\ud56d
-SWT_Current_Selection=\ud604\uc7ac \uc120\ud0dd\uc0ac\ud56d
-SWT_Font=\uae00\uaf34
-SWT_Color=\uc0c9\uc0c1
-SWT_Extended_style=\ud655\uc7a5 \uc2a4\ud0c0\uc77c
-SWT_Size=\ud06c\uae30
-SWT_Style=\uc2a4\ud0c0\uc77c
-SWT_Save=\uc800\uc7a5
-SWT_Character_set=\ubb38\uc790 \uc138\ud2b8
-SWT_ColorDialog_Title=\uc0c9\uc0c1
-SWT_FontDialog_Title=\uae00\uaf34
-SWT_FontSet=\uae00\uaf34 \uc138\ud2b8
-SWT_NewFont=\uc0c8 \uae00\uaf34
-SWT_Remove=\uc81c\uac70
-SWT_Up=\uc704\ub85c
-SWT_Down=\uc544\ub798\ub85c
-SWT_Charset_Western=\uc11c\ubc29
-SWT_Charset_EastEuropean=\ub3d9\ubc29
-SWT_Charset_SouthEuropean=\ub0a8\ubc29
-SWT_Charset_NorthEuropean=\ubd81\ubc29
-SWT_Charset_Cyrillic=\ud0a4\ub9b4 \uc790\ubaa8
-SWT_Charset_Arabic=\uc544\ub78d\uc5b4
-SWT_Charset_Greek=\uadf8\ub9ac\uc2a4\uc5b4
-SWT_Charset_Hebrew=\ud5e4\ube0c\ub8e8\uc5b4
-SWT_Charset_Turkish=\ud130\ud0a4\uc5b4
-SWT_Charset_Nordic=\ubd81\uc720\ub7fd\uc5b4
-SWT_Charset_Thai=\ud0dc\uad6d\uc5b4
-SWT_Charset_BalticRim=\ubc1c\ud2b8\ud574 \uc5f0\uc548\uad6d\uac00
-SWT_Charset_Celtic=\ucf08\ud2b8\uc5b4
-SWT_Charset_Euro=\uc720\ub85c
-SWT_Charset_Romanian=\ub8e8\ub9c8\ub2c8\uc544\uc5b4
-SWT_Charset_SimplifiedChinese=\uc911\uad6d\uc5b4 \uac04\uccb4
-SWT_Charset_TraditionalChinese=\uc911\uad6d\uc5b4 \ubc88\uccb4
-SWT_Charset_Japanese=\uc77c\ubcf8\uc5b4
-SWT_Charset_Korean=\ud55c\uad6d\uc5b4
-SWT_Charset_Unicode=\uc720\ub2c8\ucf54\ub4dc
-SWT_Charset_ASCII=ASCII
-SWT_InputMethods=\uc785\ub825 \uba54\uc18c\ub4dc
-SWT_Password=\uc554\ud638:
-SWT_Username=\uc0ac\uc6a9\uc790 \uc774\ub984:
-SWT_Switch=\uc804\ud658
-SWT_Press=\ub204\ub974\uae30
-SWT_Open=\uc5f4\uae30
-SWT_Close=\ub2eb\uae30
-SWT_Minimize=\ucd5c\uc18c\ud654
-SWT_Maximize=\ucd5c\ub300\ud654
-SWT_Restore=\ubcf5\uc6d0
-SWT_ShowList=\ubaa9\ub85d \ud45c\uc2dc
-SWT_FileDownload=\ud30c\uc77c \ub2e4\uc6b4\ub85c\ub4dc
-SWT_Download_File=\ub2e4\uc6b4\ub85c\ub4dc: {0}
-SWT_Download_Location={1}\uc5d0\uc11c {0} \uc800\uc7a5
-SWT_Download_Started=\ub2e4\uc6b4\ub85c\ub4dc \uc911 ...
-SWT_Download_Status=\ub2e4\uc6b4\ub85c\ub4dc: {0,number,integer}KB/{1,number,integer}KB
-SWT_Authentication_Required=\uc778\uc99d \ud544\uc694
-SWT_Enter_Username_and_Password={1}\uc5d0 {0}\uc758 \uc0ac\uc6a9\uc790 \uc774\ub984\uacfc \uc554\ud638\ub97c \uc785\ub825\ud569\ub2c8\ub2e4. \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_mn._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_mn._properties
deleted file mode 100644
index 7ce97ec981..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_mn._properties
+++ /dev/null
@@ -1,2 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Cancel=\u0411\u043e\u043b\u0438\u0445 \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_nl._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_nl._properties
deleted file mode 100644
index db94758126..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_nl._properties
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=Ja
-SWT_No=Nee
-SWT_OK=OK
-SWT_Cancel=Annuleren
-SWT_Abort=Afbreken
-SWT_Ignore=Negeren
-SWT_Sample=Voorbeeld
-SWT_Selection=Selectie
-SWT_Font=Lettertype
-SWT_Color=Kleur
-SWT_Size=Grootte
-SWT_Style=Stijl
-SWT_Save=Opslaan
-SWT_FontDialog_Title=Lettertypen
-SWT_Remove=Verwijderen
-SWT_Up=Omhoog
-SWT_Down=Omlaag
-SWT_Charset_ASCII=ASCII
-SWT_Password=Wachtwoord:
-SWT_Open=Openen
-SWT_Close=Sluiten
-SWT_Minimize=Minimaliseren
-SWT_Maximize=Maximaliseren
-SWT_Restore=Herstellen \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_no._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_no._properties
deleted file mode 100644
index 2d1bc5de2c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_no._properties
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=Ja
-SWT_No=Nei
-SWT_OK=Ok
-SWT_Cancel=Avbryt
-SWT_Abort=Avbryt
-SWT_Ignore=Ignorer
-SWT_Sample=Eksempel
-SWT_Selection=Valg
-SWT_Font=Font
-SWT_Color=Farge
-SWT_Size=St\u00f8rrelse
-SWT_Style=Stil
-SWT_Save=Lagre
-SWT_FontDialog_Title=Fonter
-SWT_Remove=Fjern
-SWT_Up=Opp
-SWT_Down=Ned
-SWT_Charset_ASCII=ASCII
-SWT_Password=Passord:
-SWT_Open=\u00c5pne
-SWT_Close=Lukk
-SWT_Minimize=Minimer
-SWT_Maximize=Maksimer
-SWT_Restore=Gjenopprett \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_pl._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_pl._properties
deleted file mode 100644
index 5f09c29c93..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_pl._properties
+++ /dev/null
@@ -1,42 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=Tak
-SWT_No=Nie
-SWT_OK=OK
-SWT_Cancel=Anuluj
-SWT_Abort=Przerwij
-SWT_Retry=Powt\u00f3rz
-SWT_Ignore=Ignoruj
-SWT_Sample=Przyk\u0142ad
-SWT_A_Sample_Text=Przyk\u0142adowy text
-SWT_Selection=Wyb\u00f3r
-SWT_Current_Selection=Obecny wyb\u00f3r
-SWT_Font=Czcionka
-SWT_Color=Kolor
-SWT_Extended_style=Rozszerzony styl
-SWT_Size=Rozmiar
-SWT_Style=Styl
-SWT_Save=Zapisz
-SWT_Character_set=Tablica znak\u00f3w
-SWT_ColorDialog_Title=Kolory
-SWT_FontDialog_Title=Czcionki
-SWT_FontSet=Zestaw czcionek
-SWT_NewFont=Nowa czcionka
-SWT_Remove=Usu\u0144
-SWT_Up=W g\u00f3r\u0119
-SWT_Down=W d\u00f3\u0142
-SWT_Charset_ASCII=ASCII
-SWT_Password=Has\u0142o:
-SWT_Username=Nazwa u\u017cytkownika:
-SWT_Switch=Zmie\u0144
-SWT_Press=Wci\u015bnij
-SWT_Open=Otwieranie
-SWT_Close=Zamknij
-SWT_Minimize=Minimalizuj
-SWT_Maximize=Maksymalizuj
-SWT_Restore=Odtw\u00f3rz
-SWT_ShowList=Poka\u017c list\u0119
-SWT_FileDownload=Pobierz plik
-SWT_Download_File=Pobierz
-SWT_Download_Location=Zapisuj\u0119 {0} z {1}
-SWT_Download_Started=Pobieranie...
-SWT_Download_Status=Pobrano: {0,number,integer} KB z {1,number,integer} KB \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_pt._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_pt._properties
deleted file mode 100644
index 6b03c743a7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_pt._properties
+++ /dev/null
@@ -1,64 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=Sim
-SWT_No=N\u00e3o
-SWT_OK=OK
-SWT_Cancel=Cancelar
-SWT_Abort=Abortar
-SWT_Retry=Tentar Novamente
-SWT_Ignore=Ignorar
-SWT_Sample=Exemplo
-SWT_A_Sample_Text=Texto de Exemplo
-SWT_Selection=Selec\u00e7\u00e3o
-SWT_Current_Selection=Selec\u00e7\u00e3o Actual
-SWT_Font=Tipo de letra
-SWT_Color=Cor
-SWT_Extended_style=Estilo Adicional
-SWT_Size=Tamanho
-SWT_Style=Estilo
-SWT_Save=Guardar
-SWT_Character_set=Conjunto de caracteres
-SWT_ColorDialog_Title=Cores
-SWT_FontDialog_Title=Tipos de Letra
-SWT_FontSet=Conjunto de Fontes
-SWT_NewFont=Nova Fonte
-SWT_Remove=Remover
-SWT_Up=Para cima
-SWT_Down=Para baixo
-SWT_Charset_Western=ocidental
-SWT_Charset_EastEuropean=oriental
-SWT_Charset_SouthEuropean=sul
-SWT_Charset_NorthEuropean=norte
-SWT_Charset_Cyrillic=cir\u00edlico
-SWT_Charset_Arabic=\u00e1rabe
-SWT_Charset_Greek=grego
-SWT_Charset_Hebrew=hebraico
-SWT_Charset_Turkish=turco
-SWT_Charset_Nordic=n\u00f3rdico
-SWT_Charset_Thai=tailand\u00eas
-SWT_Charset_BalticRim=b\u00e1ltico
-SWT_Charset_Celtic=celta
-SWT_Charset_Euro=euro
-SWT_Charset_Romanian=romeno
-SWT_Charset_SimplifiedChinese=chin\u00eas simp.
-SWT_Charset_TraditionalChinese=chin\u00eas trad.
-SWT_Charset_Japanese=japon\u00eas
-SWT_Charset_Korean=coreano
-SWT_Charset_ASCII=ASCII
-SWT_InputMethods=M\u00e9todos de Entrada
-SWT_Password=Palavra-passe:
-SWT_Username=Nome de Utilizador:
-SWT_Switch=Bot\u00e3o
-SWT_Press=Pressionar
-SWT_Open=Abrir
-SWT_Close=Fechar
-SWT_Minimize=Minimizar
-SWT_Maximize=Maximizar
-SWT_Restore=Restaurar
-SWT_ShowList=Mostrar Lista
-SWT_FileDownload=Descarregar Ficheiro
-SWT_Download_File=Descarga: {0}
-SWT_Download_Location=Gravando {0} de {1}
-SWT_Download_Started=Descarregando...
-SWT_Download_Status=Descarregar: {0,number,integer} KB de {1,number,integer} KB
-SWT_Authentication_Required=Autentica\u00e7\u00e3o Necess\u00e1ria
-SWT_Enter_Username_and_Password=Insira nome de utilizador e palavra-passe para {0} em {1} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_pt_BR._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_pt_BR._properties
deleted file mode 100644
index e80c352097..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_pt_BR._properties
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=Sim
-SWT_No=N\u00e3o
-SWT_OK=OK
-SWT_Cancel=Cancelar
-SWT_Abort=Interromper
-SWT_Ignore=Ignorar
-SWT_Sample=Exemplo
-SWT_Selection=Sele\u00e7\u00e3o
-SWT_Font=Fonte
-SWT_Color=Cor
-SWT_Size=Tamanho
-SWT_Style=Estilo
-SWT_Save=Salvar
-SWT_FontDialog_Title=Fontes
-SWT_Remove=Remover
-SWT_Up=Para Cima
-SWT_Down=Para Baixo
-SWT_Charset_ASCII=ASCII
-SWT_Password=Senha:
-SWT_Open=Abrir
-SWT_Close=Fechar
-SWT_Minimize=Minimizar
-SWT_Maximize=Maximizar
-SWT_Restore=Restaurar \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ro._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ro._properties
deleted file mode 100644
index 820114f8e9..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ro._properties
+++ /dev/null
@@ -1,5 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=Da
-SWT_No=Nu
-SWT_Password=Parol\u0103:
-SWT_Close=\u00cenchide \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ru._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ru._properties
deleted file mode 100644
index 415f033f2f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_ru._properties
+++ /dev/null
@@ -1,30 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=\u0414\u0430
-SWT_No=\u041d\u0435\u0442
-SWT_OK=OK
-SWT_Cancel=\u041e\u0442\u043c\u0435\u043d\u0430
-SWT_Abort=\u041f\u0440\u0435\u0440\u0432\u0430\u0442\u044c
-SWT_Retry=\u041f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c
-SWT_Ignore=\u0418\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c
-SWT_Sample=\u041f\u0440\u0438\u043c\u0435\u0440
-SWT_Selection=\u0412\u044b\u0431\u043e\u0440
-SWT_Font=\u0428\u0440\u0438\u0444\u0442
-SWT_Color=\u0426\u0432\u0435\u0442
-SWT_Size=\u0420\u0430\u0437\u043c\u0435\u0440
-SWT_Style=\u0421\u0442\u0438\u043b\u044c
-SWT_Save=\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c
-SWT_ColorDialog_Title=\u0426\u0432\u0435\u0442\u0430
-SWT_FontDialog_Title=\u0428\u0440\u0438\u0444\u0442\u044b
-SWT_NewFont=\u041d\u043e\u0432\u044b\u0439 \u0448\u0440\u0438\u0444\u0442
-SWT_Remove=\u0423\u0434\u0430\u043b\u0438\u0442\u044c
-SWT_Up=\u0412\u044b\u0448\u0435
-SWT_Down=\u041d\u0438\u0436\u0435
-SWT_Charset_ASCII=ASCII
-SWT_Password=\u041f\u0430\u0440\u043e\u043b\u044c:
-SWT_Username=\u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f:
-SWT_Open=\u041e\u0442\u043a\u0440\u044b\u0442\u044c
-SWT_Close=\u0417\u0430\u043a\u0440\u044b\u0442\u044c
-SWT_Minimize=\u0421\u0432\u0435\u0440\u043d\u0443\u0442\u044c
-SWT_Maximize=\u0420\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c
-SWT_Restore=\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c
-SWT_Download_Started=\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430: \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_sv._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_sv._properties
deleted file mode 100644
index b251051d90..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_sv._properties
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=Ja
-SWT_No=Nej
-SWT_OK=OK
-SWT_Cancel=Avbryt
-SWT_Abort=Avbryt
-SWT_Ignore=Ignorera
-SWT_Sample=Exempel
-SWT_Selection=Urval
-SWT_Font=Teckensnitt
-SWT_Color=F\u00e4rg
-SWT_Size=Storlek
-SWT_Style=Format
-SWT_Save=Spara
-SWT_FontDialog_Title=Teckensnitt
-SWT_Remove=Ta bort
-SWT_Up=Upp
-SWT_Down=Ned
-SWT_Charset_ASCII=ASCII
-SWT_Password=L\u00f6senord:
-SWT_Open=\u00d6ppna
-SWT_Close=St\u00e4ng
-SWT_Minimize=Minimera
-SWT_Maximize=Maximera
-SWT_Restore=\u00c5terst\u00e4ll \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_tr._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_tr._properties
deleted file mode 100644
index 1b90791f41..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_tr._properties
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=Evet
-SWT_No=Hay\u0131r
-SWT_OK=Tamam
-SWT_Cancel=\u0130ptal
-SWT_Abort=Durdur
-SWT_Ignore=Yoksay
-SWT_Sample=\u00d6rnek
-SWT_Selection=Se\u00e7im
-SWT_Font=Yaz\u0131y\u00fcz\u00fc
-SWT_Color=Renk
-SWT_Size=B\u00fcy\u00fckl\u00fck
-SWT_Style=Bi\u00e7em
-SWT_Save=Sakla
-SWT_FontDialog_Title=Yaz\u0131y\u00fczleri
-SWT_Remove=Kald\u0131r
-SWT_Up=Yukar\u0131
-SWT_Down=A\u015fa\u011f\u0131
-SWT_Charset_ASCII=ASCII
-SWT_Password=Parola:
-SWT_Open=A\u00e7
-SWT_Close=Kapat
-SWT_Minimize=Simge Durumuna K\u00fc\u00e7\u00fclt
-SWT_Maximize=Ekran Boyutuna Getir
-SWT_Restore=Geri Y\u00fckle \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_uk._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_uk._properties
deleted file mode 100644
index b254c7317a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_uk._properties
+++ /dev/null
@@ -1,65 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=\u0422\u0430\u043a
-SWT_No=\u041d\u0456
-SWT_OK=OK
-SWT_Cancel=\u0421\u043a\u0430\u0441\u0443\u0432\u0430\u0442\u0438
-SWT_Abort=\u041f\u0435\u0440\u0435\u0440\u0432\u0430\u0442\u0438
-SWT_Retry=\u041f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u0438
-SWT_Ignore=\u0406\u0433\u043d\u043e\u0440\u0443\u0432\u0430\u0442\u0438
-SWT_Sample=\u041f\u0440\u0438\u043a\u043b\u0430\u0434
-SWT_A_Sample_Text=\u0422\u0435\u043a\u0441\u0442 \u041f\u0440\u0438\u043a\u043b\u0430\u0434
-SWT_Selection=\u0412\u0438\u0431\u0456\u0440
-SWT_Current_Selection=\u041f\u043e\u0442\u043e\u0447\u043d\u0438\u0439 \u0412\u0438\u0431\u0456\u0440
-SWT_Font=\u0428\u0440\u0438\u0444\u0442
-SWT_Color=\u041a\u043e\u043b\u0456\u0440
-SWT_Extended_style=\u0420\u043e\u0437\u0448\u0438\u0440\u0435\u043d\u0438\u0439 \u0441\u0442\u0438\u043b\u044c
-SWT_Size=\u0420\u043e\u0437\u043c\u0456\u0440
-SWT_Style=\u0421\u0442\u0438\u043b\u044c
-SWT_Save=\u0417\u0431\u0435\u0440\u0435\u0433\u0442\u0438
-SWT_Character_set=\u041a\u043e\u0434\u043e\u0432\u0430 \u0441\u0442\u043e\u0440\u0456\u043d\u043a\u0430
-SWT_ColorDialog_Title=\u041a\u043e\u043b\u044c\u043e\u0440\u0438
-SWT_FontDialog_Title=\u0428\u0440\u0438\u0444\u0442\u0438
-SWT_FontSet=\u041d\u0430\u0431\u0456\u0440 \u0428\u0440\u0438\u0444\u0442\u0456\u0432
-SWT_NewFont=\u041d\u043e\u0432\u0438\u0439 \u0428\u0440\u0438\u0444\u0442
-SWT_Remove=\u0412\u0438\u043b\u0443\u0447\u0438\u0442\u0438
-SWT_Up=\u041d\u0430\u0433\u043e\u0440\u0443
-SWT_Down=\u0412\u043d\u0438\u0437
-SWT_Charset_Western=\u0437\u0430\u0445\u0456\u0434\u043d\u0438\u0439
-SWT_Charset_EastEuropean=\u0441\u0445\u0456\u0434\u043d\u0438\u0439
-SWT_Charset_SouthEuropean=\u043f\u0456\u0432\u0434\u0435\u043d\u043d\u0438\u0439
-SWT_Charset_NorthEuropean=\u043f\u0456\u0432\u043d\u0456\u0447\u043d\u0438\u0439
-SWT_Charset_Cyrillic=\u043a\u0438\u0440\u0438\u043b\u0438\u0446\u044f
-SWT_Charset_Arabic=\u0430\u0440\u0430\u0431\u0441\u044c\u043a\u0430
-SWT_Charset_Greek=\u0433\u0440\u0435\u0446\u044c\u043a\u0430
-SWT_Charset_Hebrew=\u0433\u0435\u0431\u0440\u0435\u0439\u0441\u044c\u043a\u0430
-SWT_Charset_Turkish=\u0442\u0443\u0440\u0435\u0446\u044c\u043a\u0430
-SWT_Charset_Nordic=\u0441\u043a\u0430\u043d\u0434\u0438\u043d\u0430\u0432\u0441\u044c\u043a\u0430
-SWT_Charset_Thai=\u0442\u0430\u0439\u0441\u044c\u043a\u0430
-SWT_Charset_BalticRim=\u043f\u0440\u0438\u0431\u0430\u043b\u0442\u0456\u0439\u0441\u044c\u043a\u0430
-SWT_Charset_Celtic=\u043a\u0435\u043b\u044c\u0442\u0441\u044c\u043a\u0430
-SWT_Charset_Euro=\u0435\u0432\u0440\u043e\u043f\u0435\u0439\u0441\u044c\u043a\u0430
-SWT_Charset_Romanian=\u0440\u0443\u043c\u0443\u043d\u0441\u044c\u043a\u0430
-SWT_Charset_SimplifiedChinese=\u0441\u043f\u0440\u043e\u0449\u0435\u043d\u0430 \u043a\u0438\u0442\u0430\u0439\u0441\u044c\u043a\u0430
-SWT_Charset_TraditionalChinese=\u0442\u0440\u0430\u0434\u0438\u0446\u0456\u0439\u043d\u0430 \u043a\u0438\u0442\u0430\u0439\u0441\u044c\u043a\u0430
-SWT_Charset_Japanese=\u044f\u043f\u043e\u043d\u0441\u044c\u043a\u0430
-SWT_Charset_Korean=\u043a\u043e\u0440\u0435\u0439\u0441\u044c\u043a\u0430
-SWT_Charset_Unicode=\u0443\u043d\u0456\u043a\u043e\u0434
-SWT_Charset_ASCII=ASCII
-SWT_InputMethods=\u041c\u0435\u0442\u043e\u0434 \u0412\u0432\u043e\u0434\u0443
-SWT_Password=\u041f\u0430\u0440\u043e\u043b\u044c
-SWT_Username=\u0406\u043c\'\u044f \u041a\u043e\u0440\u0438\u0441\u0442\u0443\u0432\u0430\u0447\u0430:
-SWT_Switch=\u041f\u0435\u0440\u0435\u043c\u0438\u043a\u0430\u0447
-SWT_Press=\u041d\u0430\u0442\u0438\u0441\u043d\u0456\u0442\u044c
-SWT_Open=\u0412\u0456\u0434\u043a\u0440\u0438\u0442\u0438
-SWT_Close=\u0417\u0430\u043a\u0440\u0438\u0442\u0438
-SWT_Minimize=\u041c\u0456\u043d\u0456\u043c\u0456\u0437\u0443\u0432\u0430\u0442\u0438
-SWT_Maximize=\u041c\u0430\u043a\u0441\u0438\u043c\u0456\u0437\u0443\u0432\u0430\u0442\u0438
-SWT_Restore=\u0412\u0456\u0434\u043d\u043e\u0432\u0438\u0442\u0438
-SWT_ShowList=\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u0438 \u041f\u0435\u0440\u0435\u043b\u0456\u043a
-SWT_FileDownload=\u0417\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0435\u043d\u043d\u044f \u0424\u0430\u0439\u043b\u0443
-SWT_Download_File=\u0417\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0435\u043d\u043d\u044f: {0}
-SWT_Download_Location=\u0417\u0431\u0435\u0440\u0435\u0436\u0435\u043d\u043e {0} \u0437 {1}
-SWT_Download_Started=\u0422\u0440\u0438\u0432\u0430\u0454 \u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0435\u043d\u043d\u044f...
-SWT_Download_Status=\u0417\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0435\u043d\u043d\u044f: {0,number,integer} KB \u0437 {1,number,integer} KB
-SWT_Authentication_Required=\u041f\u043e\u0442\u0440\u0456\u0431\u043d\u0430 \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0456\u044f
-SWT_Enter_Username_and_Password=\u0412\u0432\u0435\u0434\u0456\u0442\u044c \u0456\u043c\'\u044f \u043a\u043e\u0440\u0438\u0441\u0442\u0443\u0432\u0430\u0447\u0430 \u0442\u0430 \u043f\u0430\u0440\u043e\u043b\u044c \u0434\u043b\u044f {0} \u0432 {1} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_zh._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_zh._properties
deleted file mode 100644
index 064802ec44..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_zh._properties
+++ /dev/null
@@ -1,65 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=\u662f
-SWT_No=\u5426
-SWT_OK=\u786e\u5b9a
-SWT_Cancel=\u53d6\u6d88
-SWT_Abort=\u653e\u5f03
-SWT_Retry=\u91cd\u8bd5
-SWT_Ignore=\u5ffd\u7565
-SWT_Sample=\u6837\u672c
-SWT_A_Sample_Text=\u6837\u672c\u6587\u672c
-SWT_Selection=\u9009\u62e9
-SWT_Current_Selection=\u5f53\u524d\u9009\u62e9
-SWT_Font=\u5b57\u4f53
-SWT_Color=\u989c\u8272
-SWT_Extended_style=\u6269\u5c55\u6837\u5f0f
-SWT_Size=\u5927\u5c0f
-SWT_Style=\u6837\u5f0f
-SWT_Save=\u4fdd\u5b58
-SWT_Character_set=\u5b57\u7b26\u96c6
-SWT_ColorDialog_Title=\u989c\u8272
-SWT_FontDialog_Title=\u5b57\u4f53
-SWT_FontSet=\u5b57\u4f53\u96c6
-SWT_NewFont=\u65b0\u5b57\u4f53
-SWT_Remove=\u5220\u9664
-SWT_Up=\u5411\u4e0a
-SWT_Down=\u5411\u4e0b
-SWT_Charset_Western=\u897f\u6b27\u8bed\u8a00
-SWT_Charset_EastEuropean=\u4e1c\u6b27\u8bed\u8a00
-SWT_Charset_SouthEuropean=\u5357\u6b27\u8bed\u8a00
-SWT_Charset_NorthEuropean=\u5317\u6b27\u8bed\u8a00
-SWT_Charset_Cyrillic=\u897f\u91cc\u5c14\u8bed
-SWT_Charset_Arabic=\u963f\u62c9\u4f2f\u8bed
-SWT_Charset_Greek=\u5e0c\u814a\u8bed
-SWT_Charset_Hebrew=\u5e0c\u4f2f\u83b1\u8bed
-SWT_Charset_Turkish=\u571f\u8033\u5176\u8bed
-SWT_Charset_Nordic=\u632a\u5a01\u8bed
-SWT_Charset_Thai=\u6cf0\u56fd\u8bed
-SWT_Charset_BalticRim=\u6ce2\u7f57\u7684\u8bed
-SWT_Charset_Celtic=\u51ef\u5c14\u7279\u8bed
-SWT_Charset_Euro=\u6b27\u6d32\u8bed\u8a00
-SWT_Charset_Romanian=\u7f57\u9a6c\u5c3c\u4e9a\u8bed
-SWT_Charset_SimplifiedChinese=\u7b80\u4f53\u4e2d\u6587
-SWT_Charset_TraditionalChinese=\u7e41\u4f53\u4e2d\u6587
-SWT_Charset_Japanese=\u65e5\u8bed
-SWT_Charset_Korean=\u671d\u9c9c\u8bed
-SWT_Charset_Unicode=Unicode
-SWT_Charset_ASCII=ASCII
-SWT_InputMethods=\u8f93\u5165\u6cd5
-SWT_Password=\u5bc6\u7801\uff1a
-SWT_Username=\u7528\u6237\u540d\uff1a
-SWT_Switch=\u5207\u6362
-SWT_Press=\u6309
-SWT_Open=\u6253\u5f00
-SWT_Close=\u5173\u95ed
-SWT_Minimize=\u6700\u5c0f\u5316
-SWT_Maximize=\u6700\u5927\u5316
-SWT_Restore=\u590d\u539f
-SWT_ShowList=\u663e\u793a\u5217\u8868
-SWT_FileDownload=\u6587\u4ef6\u4e0b\u8f7d
-SWT_Download_File=\u4e0b\u8f7d\uff1a{0}
-SWT_Download_Location=\u4fdd\u5b58 {1} \u4e2d\u7684 {0}
-SWT_Download_Started=\u6b63\u5728\u4e0b\u8f7d...
-SWT_Download_Status=\u4e0b\u8f7d\uff1a{0,number,integer} KB\uff08\u5171 {1,number,integer} KB\uff09
-SWT_Authentication_Required=\u9700\u8981\u8ba4\u8bc1
-SWT_Enter_Username_and_Password=\u8f93\u5165 {0}\uff08\u4f4d\u4e8e {1}\uff09\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801 \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_zh_TW._properties b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_zh_TW._properties
deleted file mode 100644
index 9ec42ccf52..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages_zh_TW._properties
+++ /dev/null
@@ -1,64 +0,0 @@
-# Copyright by many contributors; see http://babel.eclipse.org/
-SWT_Yes=\u662f
-SWT_No=\u5426
-SWT_OK=\u78ba\u5b9a
-SWT_Cancel=\u53d6\u6d88
-SWT_Abort=\u4e2d\u6b62
-SWT_Retry=\u91cd\u8a66
-SWT_Ignore=\u5ffd\u7565
-SWT_Sample=\u7bc4\u4f8b
-SWT_A_Sample_Text=\u7bc4\u4f8b\u6587\u5b57
-SWT_Selection=\u9078\u53d6
-SWT_Current_Selection=\u73fe\u884c\u9078\u64c7
-SWT_Font=\u5b57\u578b
-SWT_Color=\u984f\u8272
-SWT_Extended_style=\u5ef6\u4f38\u6a23\u5f0f
-SWT_Size=\u5927\u5c0f
-SWT_Style=\u6a23\u5f0f
-SWT_Save=\u5132\u5b58
-SWT_Character_set=\u5b57\u96c6
-SWT_ColorDialog_Title=\u984f\u8272
-SWT_FontDialog_Title=\u5b57\u578b
-SWT_FontSet=\u5b57\u578b\u8a2d\u5b9a
-SWT_NewFont=\u65b0\u5b57\u578b
-SWT_Remove=\u79fb\u9664
-SWT_Up=\u4e0a
-SWT_Down=\u4e0b
-SWT_Charset_Western=\u897f\u90e8
-SWT_Charset_EastEuropean=\u6771\u90e8
-SWT_Charset_SouthEuropean=\u5357\u90e8
-SWT_Charset_NorthEuropean=\u5317\u90e8
-SWT_Charset_Cyrillic=\u65af\u62c9\u592b\u6587
-SWT_Charset_Arabic=\u963f\u62c9\u4f2f\u6587
-SWT_Charset_Greek=\u5e0c\u81d8\u6587
-SWT_Charset_Hebrew=\u5e0c\u4f2f\u4f86\u6587
-SWT_Charset_Turkish=\u571f\u8033\u5176\u6587
-SWT_Charset_Nordic=\u65e5\u8033\u66fc\u6587
-SWT_Charset_Thai=\u6cf0\u6587
-SWT_Charset_BalticRim=\u6ce2\u7f85\u7684\u6d77\u5404\u65cf\u6587
-SWT_Charset_Celtic=\u585e\u723e\u7279\u6587
-SWT_Charset_Euro=\u6b50\u6d32
-SWT_Charset_Romanian=\u7f85\u99ac\u5c3c\u4e9e\u6587
-SWT_Charset_SimplifiedChinese=\u7c21\u9ad4\u4e2d\u6587
-SWT_Charset_TraditionalChinese=\u7e41\u9ad4\u4e2d\u6587
-SWT_Charset_Japanese=\u65e5\u6587
-SWT_Charset_Korean=\u97d3\u6587
-SWT_Charset_ASCII=ASCII
-SWT_InputMethods=\u8f38\u5165\u65b9\u6cd5
-SWT_Password=\u5bc6\u78bc\uff1a
-SWT_Username=\u4f7f\u7528\u8005\u540d\u7a31\uff1a
-SWT_Switch=\u5207\u63db
-SWT_Press=\u6309
-SWT_Open=\u958b\u555f
-SWT_Close=\u95dc\u9589
-SWT_Minimize=\u6700\u5c0f\u5316
-SWT_Maximize=\u6700\u5927\u5316
-SWT_Restore=\u9084\u539f
-SWT_ShowList=\u986f\u793a\u6e05\u55ae
-SWT_FileDownload=\u6a94\u6848\u4e0b\u8f09
-SWT_Download_File=\u4e0b\u8f09\uff1a{0}
-SWT_Download_Location=\u5132\u5b58 {1} \u7684 {0}
-SWT_Download_Started=\u6b63\u5728\u4e0b\u8f09...
-SWT_Download_Status=\u4e0b\u8f09\uff1a{0,number,integer} KB (\u5171 {1,number,integer} KB)
-SWT_Authentication_Required=\u9700\u8981\u9451\u5225
-SWT_Enter_Username_and_Password=\u65bc {1} \u8655\u8f38\u5165 {0} \u7684\u4f7f\u7528\u8005\u540d\u7a31\u53ca\u5bc6\u78bc \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SerializableCompatibility.java b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SerializableCompatibility.java
deleted file mode 100644
index dc7dd4c51d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SerializableCompatibility.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal;
-
-
-import java.io.Serializable;
-
-/**
- * This interface is the cross-platform version of the
- * java.io.Serializable interface.
- * <p>
- * It is part of our effort to provide support for both J2SE
- * and J2ME platforms. Under this scheme, classes need to
- * implement SerializableCompatibility instead of
- * java.io.Serializable.
- * </p>
- * <p>
- * Note: java.io.Serializable is not part of CLDC.
- * </p>
- */
-public interface SerializableCompatibility extends Serializable {
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/bidi/org/eclipse/swt/internal/BidiUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/bidi/org/eclipse/swt/internal/BidiUtil.java
deleted file mode 100644
index b46c26361d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/bidi/org/eclipse/swt/internal/BidiUtil.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal;
-
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.widgets.Control;
-
-/*
- * This class is supplied so that the StyledText code that supports bidi text (supported
- * for win platforms) is not platform dependent. Bidi text is not implemented on
- * emulated platforms.
- */
-public class BidiUtil {
- // Keyboard language types
- public static final int KEYBOARD_NON_BIDI = 0;
- public static final int KEYBOARD_BIDI = 1;
-
- // bidi rendering input flag constants, not used
- // on emulated platforms
- public static final int CLASSIN = 1;
- public static final int LINKBEFORE = 2;
- public static final int LINKAFTER = 4;
-
- // bidi rendering/ordering constants, not used on
- // emulated platforms
- public static final int CLASS_HEBREW = 2;
- public static final int CLASS_ARABIC = 2;
- public static final int CLASS_LOCALNUMBER = 4;
- public static final int CLASS_LATINNUMBER = 5;
- public static final int REORDER = 0;
- public static final int LIGATE = 0;
- public static final int GLYPHSHAPE = 0;
-
-/*
- * Not implemented.
- */
-public static void addLanguageListener(int /*long*/ hwnd, Runnable runnable) {
-}
-public static void addLanguageListener (Control control, Runnable runnable) {
-}
-/*
- * Not implemented.
- *
- */
-public static void drawGlyphs(GC gc, char[] renderBuffer, int[] renderDx, int x, int y) {
-}
-/*
- * Bidi not supported on emulated platforms.
- *
- */
-public static boolean isBidiPlatform() {
- return false;
-}
-/*
- * Not implemented.
- */
-public static boolean isKeyboardBidi() {
- return false;
-}
-/*
- * Not implemented.
- */
-public static int getFontBidiAttributes(GC gc) {
- return 0;
-}
-/*
- * Not implemented.
- *
- */
-public static void getOrderInfo(GC gc, String text, int[] order, byte[] classBuffer, int flags, int [] offsets) {
-}
-/*
- * Not implemented. Returns null.
- *
- */
-public static char[] getRenderInfo(GC gc, String text, int[] order, byte[] classBuffer, int[] dx, int flags, int[] offsets) {
- return null;
-}
-/*
- * Not implemented. Returns 0.
- */
-public static int getKeyboardLanguage() {
- return 0;
-}
-/*
- * Not implemented.
- */
-public static void removeLanguageListener(int /*long*/ hwnd) {
-}
-public static void removeLanguageListener (Control control) {
-}
-/*
- * Not implemented.
- */
-public static void setKeyboardLanguage(int language) {
-}
-/*
- * Not implemented.
- */
-public static boolean setOrientation(int /*long*/ hwnd, int orientation) {
- return false;
-}
-public static boolean setOrientation (Control control, int orientation) {
- return false;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/coolbar/org/eclipse/swt/widgets/CoolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/coolbar/org/eclipse/swt/widgets/CoolBar.java
deleted file mode 100644
index 8abac1a4e0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/coolbar/org/eclipse/swt/widgets/CoolBar.java
+++ /dev/null
@@ -1,1193 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide an area for dynamically
- * positioning the items they contain.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>CoolItem</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add <code>Control</code> children to it,
- * or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>FLAT, HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#coolbar">CoolBar snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class CoolBar extends Composite {
- CoolItem[][] items = new CoolItem[0][0];
- CoolItem[] originalItems = new CoolItem[0];
- Cursor hoverCursor, dragCursor, cursor;
- CoolItem dragging = null;
- int mouseXOffset, itemXOffset;
- boolean isLocked = false;
- boolean inDispose = false;
- static final int ROW_SPACING = 2;
- static final int CLICK_DISTANCE = 3;
- static final int DEFAULT_COOLBAR_WIDTH = 0;
- static final int DEFAULT_COOLBAR_HEIGHT = 0;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see SWT#FLAT
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public CoolBar (Composite parent, int style) {
- super (parent, checkStyle(style));
- if ((style & SWT.VERTICAL) != 0) {
- this.style |= SWT.VERTICAL;
- hoverCursor = new Cursor(display, SWT.CURSOR_SIZENS);
- } else {
- this.style |= SWT.HORIZONTAL;
- hoverCursor = new Cursor(display, SWT.CURSOR_SIZEWE);
- }
- dragCursor = new Cursor(display, SWT.CURSOR_SIZEALL);
- Listener listener = new Listener() {
- public void handleEvent(Event event) {
- switch (event.type) {
- case SWT.Dispose: onDispose(event); break;
- case SWT.MouseDown: onMouseDown(event); break;
- case SWT.MouseExit: onMouseExit(); break;
- case SWT.MouseMove: onMouseMove(event); break;
- case SWT.MouseUp: onMouseUp(event); break;
- case SWT.MouseDoubleClick: onMouseDoubleClick(event); break;
- case SWT.Paint: onPaint(event); break;
- case SWT.Resize: onResize(); break;
- }
- }
- };
- int[] events = new int[] {
- SWT.Dispose,
- SWT.MouseDown,
- SWT.MouseExit,
- SWT.MouseMove,
- SWT.MouseUp,
- SWT.MouseDoubleClick,
- SWT.Paint,
- SWT.Resize
- };
- for (int i = 0; i < events.length; i++) {
- addListener(events[i], listener);
- }
-}
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- return (style | SWT.NO_REDRAW_RESIZE) & ~(SWT.V_SCROLL | SWT.H_SCROLL);
-}
-void _setCursor (Cursor cursor) {
- if (this.cursor != null) return;
- super.setCursor (cursor);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = 0, height = 0;
- wrapItems((style & SWT.VERTICAL) != 0 ? hHint : wHint);
- boolean flat = (style & SWT.FLAT) != 0;
- for (int row = 0; row < items.length; row++) {
- int rowWidth = 0, rowHeight = 0;
- for (int i = 0; i < items[row].length; i++) {
- CoolItem item = items[row][i];
- rowWidth += item.preferredWidth;
- rowHeight = Math.max(rowHeight, item.preferredHeight);
- }
- height += rowHeight;
- if (!flat && row > 0) height += ROW_SPACING;
- width = Math.max(width, rowWidth);
- }
- wrapItems(getWidth());
- if (width == 0) width = DEFAULT_COOLBAR_WIDTH;
- if (height == 0) height = DEFAULT_COOLBAR_HEIGHT;
- Point size = fixPoint(width, height);
- if (wHint != SWT.DEFAULT) size.x = wHint;
- if (hHint != SWT.DEFAULT) size.y = hHint;
- Rectangle trim = computeTrim(0, 0, size.x, size.y);
- return new Point(trim.width, trim.height);
-}
-CoolItem getGrabbedItem(int x, int y) {
- for (int row = 0; row < items.length; row++) {
- for (int i = 0; i < items[row].length; i++) {
- CoolItem item = items[row][i];
- Rectangle bounds = item.internalGetBounds();
- bounds.width = CoolItem.MINIMUM_WIDTH;
- if (bounds.x > x) break;
- if (bounds.y > y) return null;
- if (bounds.contains(x, y)) {
- return item;
- }
- }
- }
- return null;
-}
-/**
- * Returns the item that is currently displayed at the given,
- * zero-relative index. Throws an exception if the index is
- * out of range.
- *
- * @param index the visual index of the item to return
- * @return the item at the given visual index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public CoolItem getItem (int index) {
- checkWidget();
- if (index < 0) error (SWT.ERROR_INVALID_RANGE);
- for (int row = 0; row < items.length; row++) {
- if (items[row].length > index) {
- return items[row][index];
- } else {
- index -= items[row].length;
- }
- }
- error (SWT.ERROR_INVALID_RANGE);
- return null;
-}
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- return originalItems.length;
-}
-/**
- * Returns an array of <code>CoolItem</code>s in the order
- * in which they are currently being displayed.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the receiver's items in their current visual order
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public CoolItem [] getItems () {
- checkWidget();
- CoolItem [] result = new CoolItem [getItemCount()];
- int offset = 0;
- for (int row = 0; row < items.length; row++) {
- System.arraycopy(items[row], 0, result, offset, items[row].length);
- offset += items[row].length;
- }
- return result;
-}
-Point findItem (CoolItem item) {
- for (int row = 0; row < items.length; row++) {
- for (int i = 0; i < items[row].length; i++) {
- if (items[row][i].equals(item)) return new Point(i, row);
- }
- }
- return new Point(-1, -1);
-}
-void fixEvent (Event event) {
- if ((style & SWT.VERTICAL) != 0) {
- int tmp = event.x;
- event.x = event.y;
- event.y = tmp;
- }
-}
-Rectangle fixRectangle (int x, int y, int width, int height) {
- if ((style & SWT.VERTICAL) != 0) {
- return new Rectangle(y, x, height, width);
- }
- return new Rectangle(x, y, width, height);
-}
-Point fixPoint (int x, int y) {
- if ((style & SWT.VERTICAL) != 0) {
- return new Point(y, x);
- }
- return new Point(x, y);
-}
-/**
- * Searches the receiver's items in the order they are currently
- * being displayed, starting at the first item (index 0), until
- * an item is found that is equal to the argument, and returns
- * the index of that item. If no item is found, returns -1.
- *
- * @param item the search item
- * @return the visual order index of the search item, or -1 if the item is not found
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (CoolItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- int answer = 0;
- for (int row = 0; row < items.length; row++) {
- for (int i = 0; i < items[row].length; i++) {
- if (items[row][i].equals(item)) {
- return answer;
- } else {
- answer++;
- }
- }
- }
- return -1;
-}
-/**
- * Insert the item into the row. Adjust the x and width values
- * appropriately.
- */
-boolean insertItemIntoRow(CoolItem item, int rowIndex, int x_root) {
- if (rowIndex < 0 || rowIndex >= items.length) {
- /* Create a new row for the item. */
- boolean bottom = rowIndex >= items.length;
- CoolItem[][] newRows = new CoolItem[items.length + 1][];
- System.arraycopy(items, 0, newRows, bottom ? 0 : 1, items.length);
- int row = bottom ? items.length : 0;
- newRows[row] = new CoolItem[1];
- newRows[row][0] = item;
- items = newRows;
- item.wrap = true;
- return true;
- }
-
- int barWidth = getWidth();
- Rectangle bounds = items[rowIndex][0].internalGetBounds();
- int rowY = bounds.y;
- int oldRowHeight = bounds.height;
- int x = Math.max(0, Math.abs(x_root - toDisplay(new Point(0, 0)).x));
-
- /* Find the insertion index and add the item. */
- int index;
- for (index = 0; index < items[rowIndex].length; index++) {
- if (x < items[rowIndex][index].internalGetBounds().x) break;
- }
- if (index == 0) {
- item.wrap = true;
- items[rowIndex][0].wrap = false;
- }
- int oldLength = items[rowIndex].length;
- CoolItem[] newRow = new CoolItem[oldLength + 1];
- System.arraycopy(items[rowIndex], 0, newRow, 0, index);
- newRow[index] = item;
- System.arraycopy(items[rowIndex], index, newRow, index + 1, oldLength - index);
- items[rowIndex] = newRow;
-
- /* Adjust the width of the item to the left. */
- if (index > 0) {
- CoolItem left = items[rowIndex][index - 1];
- Rectangle leftBounds = left.internalGetBounds();
- int newWidth = x - leftBounds.x;
- if (newWidth < left.internalGetMinimumWidth()) {
- x += left.internalGetMinimumWidth() - newWidth;
- newWidth = left.internalGetMinimumWidth();
- }
- left.setBounds(leftBounds.x, leftBounds.y, newWidth, leftBounds.height);
- left.requestedWidth = newWidth;
- }
-
- /* Set the item's bounds. */
- int width = 0, height = item.preferredHeight;
- if (index < items[rowIndex].length - 1) {
- CoolItem right = items[rowIndex][index + 1];
- width = right.internalGetBounds().x - x;
- if (width < right.internalGetMinimumWidth()) {
- moveRight(right, right.internalGetMinimumWidth() - width);
- width = right.internalGetBounds().x - x;
- }
- item.setBounds(x, rowY, width, height);
- if (width < item.internalGetMinimumWidth()) moveLeft(item, item.internalGetMinimumWidth() - width);
- } else {
- width = Math.max(item.internalGetMinimumWidth(), barWidth - x);
- item.setBounds(x, rowY, width, height);
- if (x + width > barWidth) moveLeft(item, x + width - barWidth);
- }
- bounds = item.internalGetBounds();
- item.requestedWidth = bounds.width;
- internalRedraw(bounds.x, bounds.y, item.internalGetMinimumWidth(), bounds.height);
- return height > oldRowHeight;
-}
-void internalRedraw (int x, int y, int width, int height) {
- if ((style & SWT.VERTICAL) != 0) {
- redraw (y, x, height, width, false);
- } else {
- redraw (x, y, width, height, false);
- }
-}
-void createItem (CoolItem item, int index) {
- int itemCount = getItemCount(), row = 0;
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (items.length == 0) {
- items = new CoolItem[1][1];
- items[0][0] = item;
- } else {
- int i = index;
- /* find the row to insert into */
- if (index < itemCount) {
- while (i > items[row].length) {
- i -= items[row].length;
- row++;
- }
- } else {
- row = items.length - 1;
- i = items[row].length;
- }
-
- // Set the last item in the row to the preferred size
- // and add the new one just to it's right
- int lastIndex = items[row].length - 1;
- CoolItem lastItem = items[row][lastIndex];
- if (lastItem.ideal) {
- Rectangle bounds = lastItem.internalGetBounds();
- bounds.width = lastItem.preferredWidth;
- bounds.height = lastItem.preferredHeight;
- lastItem.requestedWidth = lastItem.preferredWidth;
- lastItem.setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
- }
- if (i == 0) {
- item.wrap = true;
- items[row][0].wrap = false;
- }
- int oldLength = items[row].length;
- CoolItem[] newRow = new CoolItem[oldLength + 1];
- System.arraycopy(items[row], 0, newRow, 0, i);
- newRow[i] = item;
- System.arraycopy(items[row], i, newRow, i + 1, oldLength - i);
- items[row] = newRow;
- }
- item.requestedWidth = CoolItem.MINIMUM_WIDTH;
-
- int length = originalItems.length;
- CoolItem [] newOriginals = new CoolItem [length + 1];
- System.arraycopy (originalItems, 0, newOriginals, 0, index);
- System.arraycopy (originalItems, index, newOriginals, index + 1, length - index);
- newOriginals [index] = item;
- originalItems = newOriginals;
- layoutItems();
-
-}
-void destroyItem(CoolItem item) {
- if (inDispose) return;
- int row = findItem(item).y;
- if (row == -1) return;
- Rectangle bounds = item.internalGetBounds();
- removeItemFromRow(item, row, true);
-
- int index = 0;
- while (index < originalItems.length) {
- if (originalItems [index] == item) break;
- index++;
- }
- int length = originalItems.length - 1;
- CoolItem [] newOriginals = new CoolItem [length];
- System.arraycopy (originalItems, 0, newOriginals, 0, index);
- System.arraycopy (originalItems, index + 1, newOriginals, index, length - index);
- originalItems = newOriginals;
-
- internalRedraw(bounds.x, bounds.y, CoolItem.MINIMUM_WIDTH, bounds.height);
- relayout();
-}
-void moveDown(CoolItem item, int x_root) {
- int oldRowIndex = findItem(item).y;
- if (items[oldRowIndex].length == 1) {
- /* If this is the only item in the bottom row, don't move it. */
- if (oldRowIndex == items.length - 1) return;
- }
- int newRowIndex = (items[oldRowIndex].length == 1) ? oldRowIndex : oldRowIndex + 1;
- boolean resize = removeItemFromRow(item, oldRowIndex, false);
- Rectangle old = item.internalGetBounds();
- internalRedraw(old.x, old.y, CoolItem.MINIMUM_WIDTH, old.height);
- resize |= insertItemIntoRow(item, newRowIndex, x_root);
- if (resize) {
- relayout();
- } else {
- layoutItems();
- }
-}
-void moveLeft(CoolItem item, int pixels) {
- Point point = findItem(item);
- int row = point.y;
- int index = point.x;
- if (index == 0) return;
- Rectangle bounds = item.internalGetBounds();
- int minSpaceOnLeft = 0;
- for (int i = 0; i < index; i++) {
- minSpaceOnLeft += items[row][i].internalGetMinimumWidth();
- }
- int x = Math.max(minSpaceOnLeft, bounds.x - pixels);
- CoolItem left = items[row][index - 1];
- Rectangle leftBounds = left.internalGetBounds();
- if (leftBounds.x + left.internalGetMinimumWidth() > x) {
- int shift = leftBounds.x + left.internalGetMinimumWidth() - x;
- moveLeft(left, shift);
- leftBounds = left.internalGetBounds();
- }
- int leftWidth = Math.max(left.internalGetMinimumWidth(), leftBounds.width - pixels);
- left.setBounds(leftBounds.x, leftBounds.y, leftWidth, leftBounds.height);
- left.requestedWidth = leftWidth;
- int width = bounds.width + (bounds.x - x);
- item.setBounds(x, bounds.y, width, bounds.height);
- item.requestedWidth = width;
-
- int damagedWidth = bounds.x - x + CoolItem.MINIMUM_WIDTH;
- if (damagedWidth > CoolItem.MINIMUM_WIDTH) {
- internalRedraw(x, bounds.y, damagedWidth, bounds.height);
- }
-}
-void moveRight(CoolItem item, int pixels) {
- Point point = findItem(item);
- int row = point.y;
- int index = point.x;
- if (index == 0) return;
- Rectangle bounds = item.internalGetBounds();
- int minSpaceOnRight = 0;
- for (int i = index; i < items[row].length; i++) {
- minSpaceOnRight += items[row][i].internalGetMinimumWidth();
- }
- int max = getWidth() - minSpaceOnRight;
- int x = Math.min(max, bounds.x + pixels);
- int width = 0;
- if (index + 1 == items[row].length) {
- width = getWidth() - x;
- } else {
- CoolItem right = items[row][index + 1];
- Rectangle rightBounds = right.internalGetBounds();
- if (x + item.internalGetMinimumWidth() > rightBounds.x) {
- int shift = x + item.internalGetMinimumWidth() - rightBounds.x;
- moveRight(right, shift);
- rightBounds = right.internalGetBounds();
- }
- width = rightBounds.x - x;
- }
- item.setBounds(x, bounds.y, width, bounds.height);
- item.requestedWidth = width;
- CoolItem left = items[row][index - 1];
- Rectangle leftBounds = left.internalGetBounds();
- int leftWidth = x - leftBounds.x;
- left.setBounds(leftBounds.x, leftBounds.y, leftWidth, leftBounds.height);
- left.requestedWidth = leftWidth;
-
- int damagedWidth = x - bounds.x + CoolItem.MINIMUM_WIDTH + CoolItem.MARGIN_WIDTH;
- if (x - bounds.x > 0) {
- internalRedraw(bounds.x - CoolItem.MARGIN_WIDTH, bounds.y, damagedWidth, bounds.height);
- }
-}
-void moveUp(CoolItem item, int x_root) {
- Point point = findItem(item);
- int oldRowIndex = point.y;
- if (items[oldRowIndex].length == 1) {
- /* If this is the only item in the top row, don't move it. */
- if (oldRowIndex == 0) return;
- }
- boolean resize = removeItemFromRow(item, oldRowIndex, false);
- Rectangle old = item.internalGetBounds();
- internalRedraw(old.x, old.y, CoolItem.MINIMUM_WIDTH, old.height);
- int newRowIndex = oldRowIndex - 1;
- resize |= insertItemIntoRow(item, newRowIndex, x_root);
- if (resize) {
- relayout();
- } else {
- layoutItems();
- }
-}
-void onDispose(Event event) {
- /*
- * Usually when an item is disposed, destroyItem will change the size of the items array
- * and reset the bounds of all the remaining cool items.
- * Since the whole cool bar is being disposed, this is not necessary. For speed
- * the inDispose flag is used to skip over this part of the item dispose.
- */
- if (inDispose) return;
- inDispose = true;
- notifyListeners(SWT.Dispose, event);
- event.type = SWT.None;
- for (int i = 0; i < items.length; i++) {
- for (int j = 0; j < items[i].length; j++) {
- items[i][j].dispose();
- }
- }
- hoverCursor.dispose();
- dragCursor.dispose();
- cursor = null;
-}
-void onMouseDown(Event event) {
- if (isLocked || event.button != 1) return;
- fixEvent(event);
- dragging = getGrabbedItem(event.x, event.y);
- if (dragging != null) {
- mouseXOffset = event.x;
- itemXOffset = mouseXOffset - dragging.internalGetBounds().x;
- _setCursor(dragCursor);
- }
- fixEvent(event);
-}
-void onMouseExit() {
- if (dragging == null) _setCursor(null);
-}
-void onMouseMove(Event event) {
- if (isLocked) return;
- fixEvent(event);
- CoolItem grabbed = getGrabbedItem(event.x, event.y);
- if (dragging != null) {
- int left_root = toDisplay(new Point(event.x - itemXOffset, event.y)).x;
- Rectangle bounds = dragging.internalGetBounds();
- if (event.y < bounds.y) {
- moveUp(dragging, left_root);
- } else if (event.y > bounds.y + bounds.height){
- moveDown(dragging, left_root);
- } else if (event.x < mouseXOffset) {
- int distance = Math.min(mouseXOffset, bounds.x + itemXOffset) - event.x;
- if (distance > 0) moveLeft(dragging, distance);
- } else if (event.x > mouseXOffset) {
- int distance = event.x - Math.max(mouseXOffset, bounds.x + itemXOffset);
- if (distance > 0) moveRight(dragging, distance);
- }
- mouseXOffset = event.x;
- } else {
- if (grabbed != null) {
- _setCursor(hoverCursor);
- } else {
- _setCursor(null);
- }
- }
- fixEvent(event);
-}
-void onMouseUp(Event event) {
- dragging = null;
- CoolItem grabbed = getGrabbedItem(event.x, event.y);
- if (grabbed != null) {
- _setCursor(hoverCursor);
- } else {
- _setCursor(null);
- }
-}
-void onMouseDoubleClick(Event event) {
- if (isLocked) return;
- dragging = null;
- fixEvent(event);
- CoolItem target = getGrabbedItem(event.x, event.y);
- if (target == null) {
- _setCursor(null);
- } else {
- Point location = findItem(target);
- int row = location.y;
- int index = location.x;
- if (items[row].length > 1) {
- Rectangle bounds = target.internalGetBounds();
- int maxSize = getWidth ();
- for (int i = 0; i < items[row].length; i++) {
- if (i != index) {
- maxSize -= items[row][i].internalGetMinimumWidth();
- }
- }
- if (bounds.width == maxSize) {
- /* The item is at its maximum width. It should be resized to its minimum width. */
- int distance = bounds.width - target.internalGetMinimumWidth();
- if (index + 1 < items[row].length) {
- /* There is an item to the right. Maximize it. */
- CoolItem right = items[row][index + 1];
- moveLeft(right, distance);
- } else {
- /* There is no item to the right. Move the item all the way right. */
- moveRight(target, distance);
- }
- } else if (bounds.width < target.preferredWidth) {
- /* The item is less than its preferredWidth. Resize to preferredWidth. */
- int distance = target.preferredWidth - bounds.width;
- if (index + 1 < items[row].length) {
- CoolItem right = items[row][index + 1];
- moveRight(right, distance);
- distance = target.preferredWidth - target.internalGetBounds().width;
- }
- if (distance > 0) {
- moveLeft(target, distance);
- }
- } else {
- /* The item is at its minimum width. Maximize it. */
- for (int i = 0; i < items[row].length; i++) {
- if (i != index) {
- CoolItem item = items[row][i];
- item.requestedWidth = Math.max(item.internalGetMinimumWidth(), CoolItem.MINIMUM_WIDTH);
- }
- }
- target.requestedWidth = maxSize;
- layoutItems();
- }
- _setCursor(hoverCursor);
- }
- }
- fixEvent(event);
-}
-void onPaint(Event event) {
- GC gc = event.gc;
- if (items.length == 0) return;
- Color shadowColor = display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
- Color highlightColor = display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
- boolean vertical = (style & SWT.VERTICAL) != 0;
- boolean flat = (style & SWT.FLAT) != 0;
- int stopX = getWidth();
- Rectangle rect;
- Rectangle clipping = gc.getClipping();
- for (int row = 0; row < items.length; row++) {
- Rectangle bounds = new Rectangle(0, 0, 0, 0);
- for (int i = 0; i < items[row].length; i++) {
- bounds = items[row][i].internalGetBounds();
- rect = fixRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
- if (!clipping.intersects(rect)) continue;
- boolean nativeGripper = false;
-
- /* Draw gripper. */
- if (!isLocked) {
- rect = fixRectangle(bounds.x, bounds.y, CoolItem.MINIMUM_WIDTH, bounds.height);
- if (!flat) nativeGripper = drawGripper(rect.x, rect.y, rect.width, rect.height, vertical);
- if (!nativeGripper) {
- int grabberTrim = 2;
- int grabberHeight = bounds.height - (2 * grabberTrim) - 1;
- gc.setForeground(shadowColor);
- rect = fixRectangle(
- bounds.x + CoolItem.MARGIN_WIDTH,
- bounds.y + grabberTrim,
- 2,
- grabberHeight);
- gc.drawRectangle(rect);
- gc.setForeground(highlightColor);
- rect = fixRectangle(
- bounds.x + CoolItem.MARGIN_WIDTH,
- bounds.y + grabberTrim + 1,
- bounds.x + CoolItem.MARGIN_WIDTH,
- bounds.y + grabberTrim + grabberHeight - 1);
- gc.drawLine(rect.x, rect.y, rect.width, rect.height);
- rect = fixRectangle(
- bounds.x + CoolItem.MARGIN_WIDTH,
- bounds.y + grabberTrim,
- bounds.x + CoolItem.MARGIN_WIDTH + 1,
- bounds.y + grabberTrim);
- gc.drawLine(rect.x, rect.y, rect.width, rect.height);
- }
- }
-
- /* Draw separator. */
- if (!flat && !nativeGripper && i != 0) {
- gc.setForeground(shadowColor);
- rect = fixRectangle(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height - 1);
- gc.drawLine(rect.x, rect.y, rect.width, rect.height);
- gc.setForeground(highlightColor);
- rect = fixRectangle(bounds.x + 1, bounds.y, bounds.x + 1, bounds.y + bounds.height - 1);
- gc.drawLine(rect.x, rect.y, rect.width, rect.height);
- }
- }
- if (!flat && row + 1 < items.length) {
- /* Draw row separator. */
- int separatorY = bounds.y + bounds.height;
- gc.setForeground(shadowColor);
- rect = fixRectangle(0, separatorY, stopX, separatorY);
- gc.drawLine(rect.x, rect.y, rect.width, rect.height);
- gc.setForeground(highlightColor);
- rect = fixRectangle(0, separatorY + 1, stopX, separatorY + 1);
- gc.drawLine(rect.x, rect.y, rect.width, rect.height);
- }
- }
-}
-void onResize () {
- layoutItems ();
-}
-void removeControl (Control control) {
- super.removeControl (control);
- CoolItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- CoolItem item = items [i];
- if (item.control == control) item.setControl (null);
- }
-}
-/**
- * Remove the item from the row. Adjust the x and width values
- * appropriately.
- */
-boolean removeItemFromRow(CoolItem item, int rowIndex, boolean disposed) {
- int index = findItem(item).x;
- int newLength = items[rowIndex].length - 1;
- Rectangle itemBounds = item.internalGetBounds();
- int oldRowHeight = itemBounds.height;
- item.wrap = false;
- if (newLength > 0) {
- CoolItem[] newRow = new CoolItem[newLength];
- System.arraycopy(items[rowIndex], 0, newRow, 0, index);
- System.arraycopy(items[rowIndex], index + 1, newRow, index, newRow.length - index);
- items[rowIndex] = newRow;
- items[rowIndex][0].wrap = true;
- } else {
- CoolItem[][] newRows = new CoolItem[items.length - 1][];
- System.arraycopy(items, 0, newRows, 0, rowIndex);
- System.arraycopy(items, rowIndex + 1, newRows, rowIndex, newRows.length - rowIndex);
- items = newRows;
- return true;
- }
- if (!disposed) {
- if (index == 0) {
- CoolItem first = items[rowIndex][0];
- Rectangle bounds = first.internalGetBounds();
- int width = bounds.x + bounds.width;
- first.setBounds(0, bounds.y, width, bounds.height);
- first.requestedWidth = width;
- internalRedraw(bounds.x, bounds.y, CoolItem.MINIMUM_WIDTH, bounds.height);
- } else {
- CoolItem previous = items[rowIndex][index - 1];
- Rectangle bounds = previous.internalGetBounds();
- int width = bounds.width + itemBounds.width;
- previous.setBounds(bounds.x, bounds.y, width, bounds.height);
- previous.requestedWidth = width;
- }
- }
- int newRowHeight = 0;
- for (int i = 0; i < newLength; i++) {
- newRowHeight = Math.max(newRowHeight, items[rowIndex][i].preferredHeight);
- }
- return newRowHeight != oldRowHeight;
-}
-/**
- * Return the height of the bar after it has
- * been properly laid out for the given width.
- */
-int layoutItems () {
- int y = 0, width;
- if ((style&SWT.VERTICAL) != 0) {
- width = getClientArea().height;
- } else {
- width = getClientArea().width;
- }
- wrapItems(width);
- int rowSpacing = (style & SWT.FLAT) != 0 ? 0 : ROW_SPACING;
- for (int row = 0; row < items.length; row++) {
- int count = items[row].length;
- int x = 0;
-
- /* determine the height and the available width for the row */
- int rowHeight = 0;
- int available = width;
- for (int i = 0; i < count; i++) {
- CoolItem item = items[row][i];
- rowHeight = Math.max(rowHeight, item.preferredHeight);
- available -= item.internalGetMinimumWidth();
- }
- if (row > 0) y += rowSpacing;
-
- /* lay the items out */
- for (int i = 0; i < count; i++) {
- CoolItem child = items[row][i];
- int newWidth = available + child.internalGetMinimumWidth();
- if (i + 1 < count) {
- newWidth = Math.min(newWidth, child.requestedWidth);
- available -= (newWidth - child.internalGetMinimumWidth());
- }
- Rectangle oldBounds = child.internalGetBounds();
- Rectangle newBounds = new Rectangle(x, y, newWidth, rowHeight);
- if (!oldBounds.equals(newBounds)) {
- child.setBounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
- Rectangle damage = new Rectangle(0, 0, 0, 0);
- /* Cases are in descending order from most area to redraw to least. */
- if (oldBounds.y != newBounds.y) {
- damage = newBounds;
- damage.add(oldBounds);
- /* Redraw the row separator as well. */
- damage.y -= rowSpacing;
- damage.height += 2 * rowSpacing;
- } else if (oldBounds.height != newBounds.height) {
- /*
- * Draw from the bottom of the gripper to the bottom of the new area.
- * (Bottom of the gripper is -3 from the bottom of the item).
- */
- damage.y = newBounds.y + Math.min(oldBounds.height, newBounds.height) - 3;
- damage.height = newBounds.y + newBounds.height + rowSpacing;
- damage.x = oldBounds.x - CoolItem.MARGIN_WIDTH;
- damage.width = oldBounds.width + CoolItem.MARGIN_WIDTH;
- } else if (oldBounds.x != newBounds.x) {
- /* Redraw only the difference between the separators. */
- damage.x = Math.min(oldBounds.x, newBounds.x);
- damage.width = Math.abs(oldBounds.x - newBounds.x) + CoolItem.MINIMUM_WIDTH;
- damage.y = oldBounds.y;
- damage.height = oldBounds.height;
- }
- internalRedraw(damage.x, damage.y, damage.width, damage.height);
- }
- x += newWidth;
- }
- y += rowHeight;
- }
- return y;
-}
-void relayout() {
- Point size = getSize();
- int height = layoutItems();
- if ((style & SWT.VERTICAL) != 0) {
- Rectangle trim = computeTrim (0, 0, height, 0);
- if (height != size.x) super.setSize(trim.width, size.y);
- } else {
- Rectangle trim = computeTrim (0, 0, 0, height);
- if (height != size.y) super.setSize(size.x, trim.height);
- }
-}
-/**
- * Returns an array of zero-relative ints that map
- * the creation order of the receiver's items to the
- * order in which they are currently being displayed.
- * <p>
- * Specifically, the indices of the returned array represent
- * the current visual order of the items, and the contents
- * of the array represent the creation order of the items.
- * </p><p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the current visual order of the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int[] getItemOrder () {
- checkWidget ();
- int count = getItemCount ();
- int [] indices = new int [count];
- count = 0;
- for (int i = 0; i < items.length; i++) {
- for (int j = 0; j < items[i].length; j++) {
- CoolItem item = items[i][j];
- int index = 0;
- while (index<originalItems.length) {
- if (originalItems [index] == item) break;
- index++;
- }
- if (index == originalItems.length) error (SWT.ERROR_CANNOT_GET_ITEM);
- indices [count++] = index;
- }
- }
- return indices;
-}
-void setItemOrder (int[] itemOrder) {
- if (itemOrder == null) error(SWT.ERROR_NULL_ARGUMENT);
- int count = originalItems.length;
- if (itemOrder.length != count) error(SWT.ERROR_INVALID_ARGUMENT);
-
- /* Ensure that itemOrder does not contain any duplicates. */
- boolean [] set = new boolean [count];
- for (int i = 0; i < set.length; i++) set [i] = false;
- for (int i = 0; i < itemOrder.length; i++) {
- if (itemOrder [i] < 0 || itemOrder [i] >= count) error (SWT.ERROR_INVALID_ARGUMENT);
- if (set [itemOrder [i]]) error (SWT.ERROR_INVALID_ARGUMENT);
- set [itemOrder [i]] = true;
- }
-
- CoolItem[] row = new CoolItem[count];
- for (int i = 0; i < count; i++) {
- row[i] = originalItems[itemOrder[i]];
- }
- items = new CoolItem[1][count];
- items[0] = row;
-}
-/**
- * Returns an array of points whose x and y coordinates describe
- * the widths and heights (respectively) of the items in the receiver
- * in the order in which they are currently being displayed.
- *
- * @return the receiver's item sizes in their current visual order
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point[] getItemSizes () {
- checkWidget();
- CoolItem[] items = getItems();
- Point[] sizes = new Point[items.length];
- for (int i = 0; i < items.length; i++) {
- sizes[i] = items[i].getSize();
- }
- return sizes;
-}
-void setItemSizes (Point[] sizes) {
- if (sizes == null) error(SWT.ERROR_NULL_ARGUMENT);
- CoolItem[] items = getItems();
- if (sizes.length != items.length) error(SWT.ERROR_INVALID_ARGUMENT);
- for (int i = 0; i < items.length; i++) {
- items[i].setSize(sizes[i]);
- }
-}
-/**
- * Returns whether or not the receiver is 'locked'. When a coolbar
- * is locked, its items cannot be repositioned.
- *
- * @return true if the coolbar is locked, false otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public boolean getLocked () {
- checkWidget ();
- return isLocked;
-}
-int getWidth () {
- if ((style & SWT.VERTICAL) != 0) return getSize().y;
- return getSize().x;
-}
-/**
- * Returns an array of ints that describe the zero-relative
- * indices of any item(s) in the receiver that will begin on
- * a new row. The 0th visible item always begins the first row,
- * therefore it does not count as a wrap index.
- *
- * @return an array containing the receiver's wrap indices, or an empty array if all items are in one row
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int[] getWrapIndices () {
- checkWidget();
- if (items.length <= 1) return new int[]{};
- int[] wrapIndices = new int[items.length - 1];
- int i = 0, nextWrap = items[0].length;
- for (int row = 1; row < items.length; row++) {
- if (items[row][0].wrap) wrapIndices[i++] = nextWrap;
- nextWrap += items[row].length;
- }
- if (i != wrapIndices.length) {
- int[] tmp = new int[i];
- System.arraycopy(wrapIndices, 0, tmp, 0, i);
- return tmp;
- }
- return wrapIndices;
-}
-/**
- * Sets whether or not the receiver is 'locked'. When a coolbar
- * is locked, its items cannot be repositioned.
- *
- * @param locked lock the coolbar if true, otherwise unlock the coolbar
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setLocked (boolean locked) {
- checkWidget ();
- if (isLocked != locked) {
- redraw();
- }
- isLocked = locked;
-
-}
-/**
- * Sets the indices of all item(s) in the receiver that will
- * begin on a new row. The indices are given in the order in
- * which they are currently being displayed. The 0th item
- * always begins the first row, therefore it does not count
- * as a wrap index. If indices is null or empty, the items
- * will be placed on one line.
- *
- * @param indices an array of wrap indices, or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWrapIndices (int[] indices) {
- checkWidget();
- if (indices == null) indices = new int[0];
- int count = originalItems.length;
- for (int i=0; i<indices.length; i++) {
- if (indices[i] < 0 || indices[i] >= count) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- for (int i=0; i<originalItems.length; i++) {
- originalItems[i].wrap = false;
- }
- for (int i=0; i<indices.length; i++) {
- int index = indices[i];
- for (int row = 0; row < items.length; row++) {
- if (items[row].length > index) {
- items[row][index].wrap = true;
- break;
- } else {
- index -= items[row].length;
- }
- }
- }
- relayout();
-}
-public void setCursor (Cursor cursor) {
- checkWidget ();
- super.setCursor (this.cursor = cursor);
-}
-/**
- * Sets the receiver's item order, wrap indices, and item sizes
- * all at once. This method is typically used to restore the
- * displayed state of the receiver to a previously stored state.
- * <p>
- * The item order is the order in which the items in the receiver
- * should be displayed, given in terms of the zero-relative ordering
- * of when the items were added.
- * </p><p>
- * The wrap indices are the indices of all item(s) in the receiver
- * that will begin on a new row. The indices are given in the order
- * specified by the item order. The 0th item always begins the first
- * row, therefore it does not count as a wrap index. If wrap indices
- * is null or empty, the items will be placed on one line.
- * </p><p>
- * The sizes are specified in an array of points whose x and y
- * coordinates describe the new widths and heights (respectively)
- * of the receiver's items in the order specified by the item order.
- * </p>
- *
- * @param itemOrder an array of indices that describe the new order to display the items in
- * @param wrapIndices an array of wrap indices, or null
- * @param sizes an array containing the new sizes for each of the receiver's items in visual order
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if item order or sizes is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if item order or sizes is not the same length as the number of items</li>
- * </ul>
- */
-public void setItemLayout (int[] itemOrder, int[] wrapIndices, Point[] sizes) {
- checkWidget();
- setItemOrder(itemOrder);
- setWrapIndices(wrapIndices);
- setItemSizes(sizes);
- relayout();
-}
-void wrapItems (int maxWidth) {
- int itemCount = originalItems.length;
- if (itemCount < 2) return;
- CoolItem[] itemsVisual = new CoolItem[itemCount];
- int start = 0;
- for (int row = 0; row < items.length; row++) {
- System.arraycopy(items[row], 0, itemsVisual, start, items[row].length);
- start += items[row].length;
- }
- CoolItem[][] newItems = new CoolItem[itemCount][];
- int rowCount = 0, rowWidth = 0;
- start = 0;
- for (int i = 0; i < itemCount; i++) {
- CoolItem item = itemsVisual[i];
- int itemWidth = item.internalGetMinimumWidth();
- if ((i > 0 && item.wrap) || (maxWidth != SWT.DEFAULT && rowWidth + itemWidth > maxWidth)) {
- if (i == start) {
- newItems[rowCount] = new CoolItem[1];
- newItems[rowCount][0] = item;
- start = i + 1;
- rowWidth = 0;
- } else {
- int count = i - start;
- newItems[rowCount] = new CoolItem[count];
- System.arraycopy(itemsVisual, start, newItems[rowCount], 0, count);
- start = i;
- rowWidth = itemWidth;
- }
- rowCount++;
- } else {
- rowWidth += itemWidth;
- }
- }
- if (start < itemCount) {
- int count = itemCount - start;
- newItems[rowCount] = new CoolItem[count];
- System.arraycopy(itemsVisual, start, newItems[rowCount], 0, count);
- rowCount++;
- }
- if (newItems.length != rowCount) {
- CoolItem[][] tmp = new CoolItem[rowCount][];
- System.arraycopy(newItems, 0, tmp, 0, rowCount);
- items = tmp;
- } else {
- items = newItems;
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/coolbar/org/eclipse/swt/widgets/CoolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/coolbar/org/eclipse/swt/widgets/CoolItem.java
deleted file mode 100644
index 2681e09245..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/coolbar/org/eclipse/swt/widgets/CoolItem.java
+++ /dev/null
@@ -1,657 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that represent the dynamically positionable
- * areas of a <code>CoolBar</code>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>DROP_DOWN</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class CoolItem extends Item {
- Control control;
- CoolBar parent;
- boolean ideal;
- int preferredWidth, preferredHeight, minimumWidth, minimumHeight, requestedWidth;
- Rectangle itemBounds = new Rectangle(0, 0, 0, 0);
-
- static final int MARGIN_WIDTH = 4;
- static final int GRABBER_WIDTH = 2;
- static final int MINIMUM_WIDTH = (2 * MARGIN_WIDTH) + GRABBER_WIDTH;
-
- private int CHEVRON_HORIZONTAL_TRIM = -1; //platform dependent values
- private int CHEVRON_VERTICAL_TRIM = -1;
- private static final int CHEVRON_LEFT_MARGIN = 2;
- private static final int CHEVRON_IMAGE_WIDTH = 8; //Width to draw the double arrow
-
- ToolBar chevron;
- boolean wrap;
- Image arrowImage = null;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>CoolBar</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public CoolItem (CoolBar parent, int style) {
- super(parent, style);
- this.parent = parent;
- parent.createItem (this, parent.getItemCount());
- calculateChevronTrim ();
-}
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>CoolBar</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index at which to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public CoolItem (CoolBar parent, int style, int index) {
- super(parent, style);
- this.parent = parent;
- parent.createItem (this, index);
- calculateChevronTrim ();
-}
-/**
- * Adds the listener to the collection of listeners that will
- * be notified when the control is selected by the user, by sending it one
- * of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * If <code>widgetSelected</code> is called when the mouse is over
- * the drop-down arrow (or 'chevron') portion of the cool item,
- * the event object detail field contains the value <code>SWT.ARROW</code>,
- * and the x and y fields in the event object represent the point at
- * the bottom left of the chevron, where the menu should be popped up.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- *
- * @since 2.0
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-/*
- * Find the trim size of the Toolbar widget in the current platform.
- */
-void calculateChevronTrim () {
- ToolBar tb = new ToolBar (parent, SWT.FLAT);
- ToolItem ti = new ToolItem (tb, SWT.PUSH);
- Image image = new Image (display, 1, 1);
- ti.setImage (image);
- Point size = tb.computeSize (SWT.DEFAULT, SWT.DEFAULT);
- size = parent.fixPoint(size.x, size.y);
- CHEVRON_HORIZONTAL_TRIM = size.x - 1;
- CHEVRON_VERTICAL_TRIM = size.y - 1;
- tb.dispose ();
- ti.dispose ();
- image.dispose ();
-}
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>preferred size</em> of a <code>CoolItem</code> is the size that
- * it would best be displayed at. The width hint and height hint arguments
- * allow the caller to ask the instance questions such as "Given a particular
- * width, how high does it need to be to show all of the contents?"
- * To indicate that the caller does not wish to constrain a particular
- * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
- * </p>
- *
- * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
- * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
- * @return the preferred size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Layout
- * @see #getBounds
- * @see #getSize
- * @see Control#getBorderWidth
- * @see Scrollable#computeTrim
- * @see Scrollable#getClientArea
- */
-public Point computeSize (int wHint, int hHint) {
- checkWidget();
- int width = wHint, height = hHint;
- if (wHint == SWT.DEFAULT) width = 32;
- if (hHint == SWT.DEFAULT) height = 32;
- if ((parent.style & SWT.VERTICAL) != 0) {
- height += MINIMUM_WIDTH;
- } else {
- width += MINIMUM_WIDTH;
- }
- return new Point (width, height);
-}
-public void dispose () {
- if (isDisposed()) return;
-
- /*
- * Must call parent.destroyItem() before super.dispose(), since it needs to
- * query the bounds to properly remove the item.
- */
- parent.destroyItem(this);
- super.dispose ();
- parent = null;
- control = null;
-
- /*
- * Although the parent for the chevron is the CoolBar (CoolItem can not be the parent)
- * it has to be disposed with the item
- */
- if (chevron != null && !chevron.isDisposed()) chevron.dispose();
- chevron = null;
- if (arrowImage != null && !arrowImage.isDisposed()) arrowImage.dispose();
- arrowImage = null;
-}
-
-Image createArrowImage (int width, int height) {
- Point point = parent.fixPoint(width, height);
- width = point.x;
- height = point.y;
- Color foreground = parent.getForeground ();
- Color black = display.getSystemColor (SWT.COLOR_BLACK);
- Color background = parent.getBackground ();
-
- PaletteData palette = new PaletteData (new RGB[]{foreground.getRGB(), background.getRGB(), black.getRGB()});
- ImageData imageData = new ImageData (width, height, 4, palette);
- imageData.transparentPixel = 1;
- Image image = new Image (display, imageData);
-
- GC gc = new GC (image, parent.getStyle() & SWT.RIGHT_TO_LEFT);
- gc.setBackground (background);
- gc.fillRectangle (0, 0, width, height);
- gc.setForeground (black);
-
- int startX = 0 ;
- if ((parent.style & SWT.VERTICAL) != 0) {
- startX = width - CHEVRON_IMAGE_WIDTH;
- }
- int startY = height / 6;
- int step = 2;
- gc.drawLine (startX, startY, startX + step, startY + step);
- gc.drawLine (startX, startY + (2 * step), startX + step, startY + step);
- startX++;
- gc.drawLine (startX, startY, startX + step, startY + step);
- gc.drawLine (startX, startY + (2 * step), startX + step, startY + step);
- startX += 3;
- gc.drawLine (startX, startY, startX + step, startY + step);
- gc.drawLine (startX, startY + (2 * step), startX + step, startY + step);
- startX++;
- gc.drawLine (startX, startY, startX + step, startY + step);
- gc.drawLine (startX, startY + (2 * step), startX + step, startY + step);
- gc.dispose ();
- return image;
-}
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- return parent.fixRectangle(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height);
-}
-Rectangle internalGetBounds () {
- return new Rectangle(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height);
-}
-/**
- * Returns the control that is associated with the receiver.
- *
- * @return the control that is contained by the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget();
- return control;
-}
-/**
- * Returns the minimum size that the cool item can
- * be resized to using the cool item's gripper.
- *
- * @return a point containing the minimum width and height of the cool item, in pixels
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public Point getMinimumSize () {
- checkWidget();
- return parent.fixPoint(minimumWidth, minimumHeight);
-}
-/**
- * Returns the receiver's parent, which must be a <code>CoolBar</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public CoolBar getParent () {
- checkWidget();
- return parent;
-}
-/**
- * Returns a point describing the receiver's ideal size.
- * The x coordinate of the result is the ideal width of the receiver.
- * The y coordinate of the result is the ideal height of the receiver.
- *
- * @return the receiver's ideal size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getPreferredSize () {
- checkWidget();
- return parent.fixPoint(preferredWidth, preferredHeight);
-}
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- return parent.fixPoint(itemBounds.width, itemBounds.height);
-}
-int internalGetMinimumWidth () {
- int width = minimumWidth + MINIMUM_WIDTH;
- if ((style & SWT.DROP_DOWN) != 0 && width < preferredWidth) {
- width += CHEVRON_IMAGE_WIDTH + CHEVRON_HORIZONTAL_TRIM + CHEVRON_LEFT_MARGIN;
- }
- return width;
-}
-/*
- * Called when the chevron is selected.
- */
-void onSelection (Event ev) {
- Rectangle bounds = chevron.getBounds();
- Event event = new Event();
- event.detail = SWT.ARROW;
- if ((parent.style & SWT.VERTICAL) != 0) {
- event.x = bounds.x + bounds.width;
- event.y = bounds.y;
- } else {
- event.x = bounds.x;
- event.y = bounds.y + bounds.height;
- }
- postEvent (SWT.Selection, event);
-}
-/**
- * Removes the listener from the collection of listeners that
- * will be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- *
- * @since 2.0
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-void setBounds (int x, int y, int width, int height) {
- itemBounds.x = x;
- itemBounds.y = y;
- itemBounds.width = width;
- itemBounds.height = height;
- if (control != null) {
- int controlWidth = width - MINIMUM_WIDTH;
- if ((style & SWT.DROP_DOWN) != 0 && width < preferredWidth) {
- controlWidth -= CHEVRON_IMAGE_WIDTH + CHEVRON_HORIZONTAL_TRIM + CHEVRON_LEFT_MARGIN;
- }
- if (height > preferredHeight) {
- y += (height - preferredHeight) / 2;
- height = preferredHeight;
- }
- control.setBounds (parent.fixRectangle(x + MINIMUM_WIDTH, y, controlWidth, height));
- }
- updateChevron();
-}
-/**
- * Sets the control that is associated with the receiver
- * to the argument.
- *
- * @param control the new control that will be contained by the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- this.control = control;
- if (control != null) {
- int controlWidth = itemBounds.width - MINIMUM_WIDTH;
- if ((style & SWT.DROP_DOWN) != 0 && itemBounds.width < preferredWidth) {
- controlWidth -= CHEVRON_IMAGE_WIDTH + CHEVRON_HORIZONTAL_TRIM + CHEVRON_LEFT_MARGIN;
- }
- control.setBounds (parent.fixRectangle(itemBounds.x + MINIMUM_WIDTH, itemBounds.y, controlWidth, itemBounds.height));
- }
-}
-/**
- * Sets the minimum size that the cool item can be resized to
- * using the cool item's gripper, to the point specified by the arguments.
- *
- * @param width the minimum width of the cool item, in pixels
- * @param height the minimum height of the cool item, in pixels
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setMinimumSize (int width, int height) {
- checkWidget ();
- Point point = parent.fixPoint(width, height);
- minimumWidth = point.x;
- minimumHeight = point.y;
-}
-/**
- * Sets the minimum size that the cool item can be resized to
- * using the cool item's gripper, to the point specified by the argument.
- *
- * @param size a point representing the minimum width and height of the cool item, in pixels
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setMinimumSize (Point size) {
- checkWidget ();
- if (size == null) error(SWT.ERROR_NULL_ARGUMENT);
- setMinimumSize(size.x, size.y);
-}
-/**
- * Sets the receiver's ideal size to the point specified by the arguments.
- *
- * @param width the new ideal width for the receiver
- * @param height the new ideal height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPreferredSize (int width, int height) {
- checkWidget();
- ideal = true;
- Point point = parent.fixPoint(width, height);
- preferredWidth = Math.max (point.x, MINIMUM_WIDTH);
- preferredHeight = point.y;
-}
-/**
- * Sets the receiver's ideal size to the point specified by the argument.
- *
- * @param size the new ideal size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPreferredSize (Point size) {
- checkWidget();
- if (size == null) error(SWT.ERROR_NULL_ARGUMENT);
- setPreferredSize(size.x, size.y);
-}
-/**
- * Sets the receiver's size to the point specified by the arguments.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (int width, int height) {
- checkWidget();
- Point point = parent.fixPoint(width, height);
- width = Math.max(point.x, minimumWidth + MINIMUM_WIDTH);
- height = point.y;
- if (!ideal) {
- preferredWidth = width;
- preferredHeight = height;
- }
- itemBounds.width = requestedWidth = width;
- itemBounds.height = height;
- if (control != null) {
- int controlWidth = width - MINIMUM_WIDTH;
- if ((style & SWT.DROP_DOWN) != 0 && width < preferredWidth) {
- controlWidth -= CHEVRON_IMAGE_WIDTH + CHEVRON_HORIZONTAL_TRIM + CHEVRON_LEFT_MARGIN;
- }
- control.setSize(parent.fixPoint(controlWidth, height));
- }
- parent.relayout();
- updateChevron();
-}
-/**
- * Sets the receiver's size to the point specified by the argument.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause them to be
- * set to zero instead.
- * </p>
- *
- * @param size the new size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (Point size) {
- checkWidget();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSize (size.x, size.y);
-}
-void updateChevron() {
- if (control != null) {
- int width = itemBounds.width;
- if ((style & SWT.DROP_DOWN) != 0 && width < preferredWidth) {
- if (chevron == null) {
- chevron = new ToolBar (parent, SWT.FLAT | SWT.NO_FOCUS);
- ToolItem toolItem = new ToolItem (chevron, SWT.PUSH);
- toolItem.addListener (SWT.Selection, new Listener() {
- public void handleEvent (Event event) {
- CoolItem.this.onSelection (event);
- }
- });
- }
- int controlHeight, currentImageHeight = 0;
- if ((parent.style & SWT.VERTICAL) != 0) {
- controlHeight = control.getSize ().x;
- if (arrowImage != null) currentImageHeight = arrowImage.getBounds().width;
- } else {
- controlHeight = control.getSize ().y;
- if (arrowImage != null) currentImageHeight = arrowImage.getBounds().height;
- }
- int height = Math.min (controlHeight, itemBounds.height);
- int imageHeight = Math.max(1, height - CHEVRON_VERTICAL_TRIM);
- if (currentImageHeight != imageHeight) {
- Image image = createArrowImage (CHEVRON_IMAGE_WIDTH, imageHeight);
- chevron.getItem (0).setImage (image);
- if (arrowImage != null) arrowImage.dispose ();
- arrowImage = image;
- }
- chevron.setBackground (parent.getBackground());
- chevron.setBounds (parent.fixRectangle (
- itemBounds.x + width - CHEVRON_LEFT_MARGIN - CHEVRON_IMAGE_WIDTH - CHEVRON_HORIZONTAL_TRIM,
- itemBounds.y,
- CHEVRON_IMAGE_WIDTH + CHEVRON_HORIZONTAL_TRIM,
- height));
- chevron.setVisible(true);
- } else {
- if (chevron != null) {
- chevron.setVisible(false);
- }
- }
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/datetime/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/datetime/org/eclipse/swt/widgets/DateTime.java
deleted file mode 100644
index cafcb0959b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/datetime/org/eclipse/swt/widgets/DateTime.java
+++ /dev/null
@@ -1,1180 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import java.text.DateFormatSymbols; //TODO: not in CLDC
-import java.util.Calendar; // TODO: Gregorian not in CLDC
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify date
- * or time values.
- * <p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>DATE, TIME, CALENDAR, SHORT, MEDIUM, LONG, DROP_DOWN</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles DATE, TIME, or CALENDAR may be specified,
- * and only one of the styles SHORT, MEDIUM, or LONG may be specified.
- * The DROP_DOWN style is a <em>HINT</em>, and it is only valid with the DATE style.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#datetime">DateTime snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.3
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class DateTime extends Composite {
- Color fg, bg;
- Calendar calendar;
- DateFormatSymbols formatSymbols;
- Button down, up, monthDown, monthUp, yearDown, yearUp;
- Text text;
- Point[] fieldIndices;
- int[] fieldNames;
- int fieldCount, currentField = 0, characterCount = 0;
- boolean ignoreVerify = false;
-
- // TODO: default format strings need more work for locale
- static final String DEFAULT_SHORT_DATE_FORMAT = "MM/YYYY";
- static final String DEFAULT_MEDIUM_DATE_FORMAT = "MM/DD/YYYY";
- static final String DEFAULT_LONG_DATE_FORMAT = "MM/DD/YYYY";
- static final String DEFAULT_SHORT_TIME_FORMAT = "HH:MM AM";
- static final String DEFAULT_MEDIUM_TIME_FORMAT = "HH:MM:SS AM";
- static final String DEFAULT_LONG_TIME_FORMAT = "HH:MM:SS AM";
- static final int MARGIN_WIDTH = 2;
- static final int MARGIN_HEIGHT = 1;
- static final int MIN_YEAR = 1752; // Gregorian switchover in North America: September 19, 1752
- static final int MAX_YEAR = 9999;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DATE
- * @see SWT#TIME
- * @see SWT#CALENDAR
- * @see SWT#SHORT
- * @see SWT#MEDIUM
- * @see SWT#LONG
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public DateTime(Composite parent, int style) {
- super(parent, checkStyle(style) | SWT.NO_REDRAW_RESIZE);
- calendar = Calendar.getInstance();
- formatSymbols = new DateFormatSymbols();
- if ((this.style & SWT.CALENDAR) != 0) {
- Listener listener = new Listener() {
- public void handleEvent(Event event) {
- switch(event.type) {
- case SWT.Paint: handlePaint(event); break;
- case SWT.Resize: handleResize(event); break;
- case SWT.MouseDown: handleMouseDown(event); break;
- case SWT.KeyDown: handleKeyDown(event); break;
- case SWT.Traverse: handleTraverse(event); break;
- }
- }
- };
- addListener(SWT.Paint, listener);
- addListener(SWT.Resize, listener);
- addListener(SWT.MouseDown, listener);
- addListener(SWT.KeyDown, listener);
- addListener(SWT.Traverse, listener);
- yearDown = new Button(this, SWT.ARROW | SWT.LEFT);
- //yearDown.setToolTipText(SWT.getMessage ("SWT_Last_Year")); //$NON-NLS-1$
- monthDown = new Button(this, SWT.ARROW | SWT.LEFT);
- //monthDown.setToolTipText(SWT.getMessage ("SWT_Last_Month")); //$NON-NLS-1$
- monthUp = new Button(this, SWT.ARROW | SWT.RIGHT);
- //monthUp.setToolTipText(SWT.getMessage ("SWT_Next_Month")); //$NON-NLS-1$
- yearUp = new Button(this, SWT.ARROW | SWT.RIGHT);
- //yearUp.setToolTipText(SWT.getMessage ("SWT_Next_Year")); //$NON-NLS-1$
- listener = new Listener() {
- public void handleEvent(Event event) {
- handleSelection(event);
- }
- };
- yearDown.addListener(SWT.Selection, listener);
- monthDown.addListener(SWT.Selection, listener);
- monthUp.addListener(SWT.Selection, listener);
- yearUp.addListener(SWT.Selection, listener);
- } else {
- text = new Text(this, SWT.SINGLE);
- if ((this.style & SWT.DATE) != 0) {
- setFormat((this.style & SWT.SHORT) != 0 ? DEFAULT_SHORT_DATE_FORMAT : (this.style & SWT.LONG) != 0 ? DEFAULT_LONG_DATE_FORMAT : DEFAULT_MEDIUM_DATE_FORMAT);
- } else { // SWT.TIME
- setFormat((this.style & SWT.SHORT) != 0 ? DEFAULT_SHORT_TIME_FORMAT : (this.style & SWT.LONG) != 0 ? DEFAULT_LONG_TIME_FORMAT : DEFAULT_MEDIUM_TIME_FORMAT);
- }
- text.setText(getFormattedString(this.style));
- Listener listener = new Listener() {
- public void handleEvent(Event event) {
- switch(event.type) {
- case SWT.KeyDown: onKeyDown(event); break;
- case SWT.FocusIn: onFocusIn(event); break;
- case SWT.FocusOut: onFocusOut(event); break;
- case SWT.MouseDown: onMouseClick(event); break;
- case SWT.MouseUp: onMouseClick(event); break;
- case SWT.Verify: onVerify(event); break;
- }
- }
- };
- text.addListener(SWT.KeyDown, listener);
- text.addListener(SWT.FocusIn, listener);
- text.addListener(SWT.FocusOut, listener);
- text.addListener(SWT.MouseDown, listener);
- text.addListener(SWT.MouseUp, listener);
- text.addListener(SWT.Verify, listener);
- up = new Button(this, SWT.ARROW | SWT.UP);
- //up.setToolTipText(SWT.getMessage ("SWT_Up")); //$NON-NLS-1$
- down = new Button(this, SWT.ARROW | SWT.DOWN);
- //down.setToolTipText(SWT.getMessage ("SWT_Down")); //$NON-NLS-1$
- up.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- incrementField(+1);
- text.setFocus();
- }
- });
- down.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- incrementField(-1);
- text.setFocus();
- }
- });
- addListener(SWT.Resize, new Listener() {
- public void handleEvent(Event event) {
- onResize(event);
- }
- });
- }
-}
-
-static int checkStyle (int style) {
- style = checkBits (style, SWT.DATE, SWT.TIME, SWT.CALENDAR, 0, 0, 0);
- return checkBits (style, SWT.MEDIUM, SWT.SHORT, SWT.LONG, 0, 0, 0);
-}
-
-String formattedStringValue(int fieldName, int value, boolean adjust) {
- if (fieldName == Calendar.AM_PM) {
- String[] ampm = formatSymbols.getAmPmStrings();
- return ampm[value];
- }
- if (adjust) {
- if (fieldName == Calendar.HOUR && value == 0) {
- return String.valueOf(12); // TODO: needs more work for setFormat and locale
- }
- if (fieldName == Calendar.MONTH) {
- return String.valueOf(value + 1);
- }
- }
- return String.valueOf(value);
-}
-
-String getFormattedString(int style) {
- if ((style & SWT.TIME) != 0) {
- String[] ampm = formatSymbols.getAmPmStrings();
- int h = calendar.get(Calendar.HOUR); if (h == 0) h = 12;
- int m = calendar.get(Calendar.MINUTE);
- int s = calendar.get(Calendar.SECOND);
- int a = calendar.get(Calendar.AM_PM);
- if ((style & SWT.SHORT) != 0) return "" + (h < 10 ? " " : "") + h + ":" + (m < 10 ? "0" : "") + m + " " + ampm[a];
- return "" + (h < 10 ? " " : "") + h + ":" + (m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s + " " + ampm[a];
- }
- /* SWT.DATE */
- int y = calendar.get(Calendar.YEAR);
- int m = calendar.get(Calendar.MONTH) + 1;
- int d = calendar.get(Calendar.DAY_OF_MONTH);
- if ((style & SWT.SHORT) != 0) return "" + (m < 10 ? " " : "") + m + "/" + y;
- return "" + (m < 10 ? " " : "") + m + "/" + (d < 10 ? " " : "") + d + "/" + y;
-}
-
-String getComputeSizeString(int style) {
- if ((style & SWT.DATE) != 0) {
- return (style & SWT.SHORT) != 0 ? DEFAULT_SHORT_DATE_FORMAT : (style & SWT.LONG) != 0 ? DEFAULT_LONG_DATE_FORMAT : DEFAULT_MEDIUM_DATE_FORMAT;
- }
- // SWT.TIME
- return (style & SWT.SHORT) != 0 ? DEFAULT_SHORT_TIME_FORMAT : (style & SWT.LONG) != 0 ? DEFAULT_LONG_TIME_FORMAT : DEFAULT_MEDIUM_TIME_FORMAT;
-}
-
-int getFieldIndex(int fieldName) {
- for (int i = 0; i < fieldCount; i++) {
- if (fieldNames[i] == fieldName) {
- return i;
- }
- }
- return -1;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the control's value.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void commitCurrentField() {
- if (characterCount > 0) {
- characterCount = 0;
- int fieldName = fieldNames[currentField];
- int start = fieldIndices[currentField].x;
- int end = fieldIndices[currentField].y;
- String value = text.getText(start, end - 1);
- int s = value.lastIndexOf(' ');
- if (s != -1) value = value.substring(s + 1);
- int newValue = unformattedIntValue(fieldName, value, characterCount == 0, calendar.getActualMaximum(fieldName));
- if (newValue != -1) setTextField(fieldName, newValue, true, true);
- }
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = 0, height = 0;
- Rectangle trim;
- if ((style & SWT.CALENDAR) != 0) {
- Point cellSize = getCellSize(null);
- Point buttonSize = monthDown.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
- width = cellSize.x * 7;
- height = cellSize.y * 7 + Math.max(cellSize.y, buttonSize.y);
- } else { /* SWT.DATE and SWT.TIME */
- GC gc = new GC(text);
- Point textSize = gc.stringExtent(getComputeSizeString(style));
- gc.dispose();
- trim = text.computeTrim(0, 0, textSize.x, textSize.y);
- Point buttonSize = up.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
- width = trim.width + buttonSize.x;
- height = Math.max(trim.height, buttonSize.y);
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int borderWidth = getBorderWidth ();
- return new Point (width + 2*borderWidth, height + 2*borderWidth);
-}
-
-void drawDay(GC gc, Point cellSize, int day) {
- int cell = getCell(day);
- Point location = getCellLocation(cell, cellSize);
- String str = String.valueOf(day);
- Point extent = gc.stringExtent(str);
- int date = calendar.get(Calendar.DAY_OF_MONTH);
- if (day == date) {
- Display display = getDisplay();
- gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_SELECTION));
- gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
- gc.fillRectangle(location.x, location.y, cellSize.x, cellSize.y);
- }
- gc.drawString(str, location.x + (cellSize.x - extent.x) / 2, location.y + (cellSize.y - extent.y) / 2, true);
- if (day == date) {
- gc.setBackground(getBackground());
- gc.setForeground(getForeground());
- }
-}
-
-void drawDays(GC gc, Point cellSize, Rectangle client) {
- gc.setBackground(getBackground());
- gc.setForeground(getForeground());
- gc.fillRectangle(0, cellSize.y, client.width, cellSize.y * 7);
- int firstDay = calendar.getActualMinimum(Calendar.DAY_OF_MONTH);
- int lastDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
- for (int day = firstDay; day <= lastDay; day++) {
- drawDay(gc, cellSize, day);
- }
-}
-
-void drawDaysOfWeek(GC gc, Point cellSize, Rectangle client) {
- Display display = getDisplay();
- gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
- gc.fillRectangle(0, 0, client.width, cellSize.y);
- String[] days = formatSymbols.getShortWeekdays();
- int x = 0, y = 0;
- for (int i = 1; i < days.length; i++) {
- String day = days[i];
- Point extent = gc.stringExtent(day);
- gc.drawString(day, x + (cellSize.x - extent.x) / 2, y + (cellSize.y - extent.y) / 2, true);
- x += cellSize.x;
- }
- gc.drawLine(0, cellSize.y - 1, client.width, cellSize.y - 1);
-}
-
-void drawMonth(GC gc, Point cellSize, Rectangle client) {
- Display display = getDisplay();
- gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
- int y = cellSize.y * 7;
- gc.fillRectangle(0, y, client.width, cellSize.y);
- gc.drawLine(0, y - 1, client.width, y - 1);
- String str = formatSymbols.getShortMonths()[calendar.get(Calendar.MONTH)] + ", " + calendar.get(Calendar.YEAR);
- Point extent = gc.stringExtent(str);
- gc.drawString(str, (cellSize.x * 7 - extent.x) / 2, y + (cellSize.y - extent.y) / 2, true);
-}
-
-Point getCellSize(GC gc) {
- boolean dispose = gc == null;
- if (gc == null) gc = new GC(this);
- int width = 0, height = 0;
- String[] days = formatSymbols.getShortWeekdays();
- for (int i = 0; i < days.length; i++) {
- Point extent = gc.stringExtent(days[i]);
- width = Math.max(width, extent.x);
- height = Math.max(height, extent.y);
- }
- int firstDay = calendar.getMinimum(Calendar.DAY_OF_MONTH);
- int lastDay = calendar.getMaximum(Calendar.DAY_OF_MONTH);
- for (int day = firstDay; day <= lastDay; day++) {
- Point extent = gc.stringExtent(String.valueOf(day));
- width = Math.max(width, extent.x);
- height = Math.max(height, extent.y);
- }
- if (dispose) gc.dispose();
- return new Point(width + MARGIN_WIDTH * 2, height + MARGIN_HEIGHT * 2);
-}
-
-Point getCellLocation(int cell, Point cellSize) {
- return new Point(cell % 7 * cellSize.x, cell / 7 * cellSize.y);
-}
-
-int getCell(int date) {
- int day = calendar.get(Calendar.DAY_OF_MONTH);
- calendar.set(Calendar.DAY_OF_MONTH, 1);
- int result = date + calendar.get(Calendar.DAY_OF_WEEK) + 5;
- calendar.set(Calendar.DAY_OF_MONTH, day);
- return result;
-}
-
-int getDate(int cell) {
- int day = calendar.get(Calendar.DAY_OF_MONTH);
- calendar.set(Calendar.DAY_OF_MONTH, 1);
- int result = cell - calendar.get(Calendar.DAY_OF_WEEK) - 5;
- calendar.set(Calendar.DAY_OF_MONTH, day);
- return result;
-}
-
-public Color getBackground() {
- checkWidget();
- if (bg == null) {
- return getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
- }
- return bg;
-}
-
-/**
- * Returns the receiver's date, or day of the month.
- * <p>
- * The first day of the month is 1, and the last day depends on the month and year.
- * </p>
- *
- * @return a positive integer beginning with 1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getDay() {
- checkWidget();
- return calendar.get(Calendar.DAY_OF_MONTH);
-}
-
-public Color getForeground() {
- checkWidget();
- if (fg == null) {
- return getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
- }
- return fg;
-}
-
-/**
- * Returns the receiver's hours.
- * <p>
- * Hours is an integer between 0 and 23.
- * </p>
- *
- * @return an integer between 0 and 23
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getHours () {
- checkWidget ();
- return calendar.get(Calendar.HOUR_OF_DAY);
-}
-
-/**
- * Returns the receiver's minutes.
- * <p>
- * Minutes is an integer between 0 and 59.
- * </p>
- *
- * @return an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinutes () {
- checkWidget ();
- return calendar.get(Calendar.MINUTE);
-}
-
-/**
- * Returns the receiver's month.
- * <p>
- * The first month of the year is 0, and the last month is 11.
- * </p>
- *
- * @return an integer between 0 and 11
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMonth() {
- checkWidget();
- return calendar.get(Calendar.MONTH);
-}
-
-String getNameText() {
- return (style & SWT.TIME) != 0 ? getHours() + ":" + getMinutes() + ":" + getSeconds()
- : (getMonth() + 1) + "/" + getDay() + "/" + getYear();
-}
-
-/**
- * Returns the receiver's seconds.
- * <p>
- * Seconds is an integer between 0 and 59.
- * </p>
- *
- * @return an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSeconds () {
- checkWidget ();
- return calendar.get(Calendar.SECOND);
-}
-
-/**
- * Returns the receiver's year.
- * <p>
- * The first year is 1752 and the last year is 9999.
- * </p>
- *
- * @return an integer between 1752 and 9999
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getYear() {
- checkWidget();
- return calendar.get(Calendar.YEAR);
-}
-
-void handleKeyDown(Event event) {
- int newDay = calendar.get(Calendar.DAY_OF_MONTH);
- switch (event.keyCode) {
- case SWT.ARROW_DOWN: newDay += 7; break;
- case SWT.ARROW_UP: newDay -= 7; break;
- case SWT.ARROW_RIGHT: newDay += 1; break;
- case SWT.ARROW_LEFT: newDay -= 1; break;
- }
- setDay(newDay, true);
-}
-
-void handleMouseDown(Event event) {
- setFocus();
- Point cellSize = getCellSize(null);
- int column = event.x / cellSize.x;
- int row = event.y / cellSize.y;
- int cell = row * 7 + column;
- int newDay = getDate(cell);
- setDay(newDay, true);
-}
-
-void handlePaint(Event event) {
- GC gc = event.gc;
- Rectangle client = getClientArea();
- Point cellSize = getCellSize(gc);
- drawDaysOfWeek(gc, cellSize, client);
- drawDays(gc, cellSize, client);
- drawMonth(gc, cellSize, client);
-}
-
-void handleResize(Event event) {
- yearDown.pack();
- monthDown.pack();
- monthUp.pack();
- yearUp.pack();
- Point cellSize = getCellSize(null);
- Point size = monthDown.getSize();
- int height = Math.max(cellSize.y, size.y);
- int y = cellSize.y * 7 + (height - size.y) / 2;
- yearDown.setLocation(0, y);
- monthDown.setLocation(size.x, y);
- int x = cellSize.x * 7 - size.x;
- monthUp.setLocation(x - size.x, y);
- yearUp.setLocation(x, y);
-}
-
-void handleSelection(Event event) {
- if (event.widget == monthDown) {
- calendar.add(Calendar.MONTH, -1);
- } else if (event.widget == monthUp) {
- calendar.add(Calendar.MONTH, 1);
- } else if (event.widget == yearDown) {
- calendar.add(Calendar.YEAR, -1);
- } else if (event.widget == yearUp) {
- calendar.add(Calendar.YEAR, 1);
- } else {
- return;
- }
- redraw();
- postEvent(SWT.Selection);
-}
-
-void handleTraverse(Event event) {
- switch (event.detail) {
- case SWT.TRAVERSE_ESCAPE:
- case SWT.TRAVERSE_PAGE_NEXT:
- case SWT.TRAVERSE_PAGE_PREVIOUS:
- case SWT.TRAVERSE_RETURN:
- case SWT.TRAVERSE_TAB_NEXT:
- case SWT.TRAVERSE_TAB_PREVIOUS:
- event.doit = true;
- break;
- }
-}
-
-boolean isValidTime(int fieldName, int value) {
- int min = calendar.getActualMinimum(fieldName);
- int max = calendar.getActualMaximum(fieldName);
- return value >= min && value <= max;
-}
-
-boolean isValidDate(int year, int month, int day) {
- if (year < MIN_YEAR || year > MAX_YEAR) return false;
- Calendar valid = Calendar.getInstance();
- valid.set(year, month, day);
- return valid.get(Calendar.YEAR) == year
- && valid.get(Calendar.MONTH) == month
- && valid.get(Calendar.DAY_OF_MONTH) == day;
-}
-
-void onKeyDown(Event event) {
- int fieldName;
- switch (event.keyCode) {
- case SWT.ARROW_RIGHT:
- case SWT.KEYPAD_DIVIDE:
- // a right arrow or a valid separator navigates to the field on the right, with wraping
- selectField((currentField + 1) % fieldCount);
- break;
- case SWT.ARROW_LEFT:
- // navigate to the field on the left, with wrapping
- int index = currentField - 1;
- selectField(index < 0 ? fieldCount - 1 : index);
- break;
- case SWT.ARROW_UP:
- case SWT.KEYPAD_ADD:
- // set the value of the current field to value + 1, with wrapping
- commitCurrentField();
- incrementField(+1);
- break;
- case SWT.ARROW_DOWN:
- case SWT.KEYPAD_SUBTRACT:
- // set the value of the current field to value - 1, with wrapping
- commitCurrentField();
- incrementField(-1);
- break;
- case SWT.HOME:
- // set the value of the current field to its minimum
- fieldName = fieldNames[currentField];
- setTextField(fieldName, calendar.getActualMinimum(fieldName), true, true);
- break;
- case SWT.END:
- // set the value of the current field to its maximum
- fieldName = fieldNames[currentField];
- setTextField(fieldName, calendar.getActualMaximum(fieldName), true, true);
- break;
- default:
- switch (event.character) {
- case '/':
- case ':':
- case '-':
- case '.':
- // a valid separator navigates to the field on the right, with wraping
- selectField((currentField + 1) % fieldCount);
- break;
- }
- }
-}
-
-void onFocusIn(Event event) {
- selectField(currentField);
-}
-
-void onFocusOut(Event event) {
- commitCurrentField();
-}
-
-void onMouseClick(Event event) {
- if (event.button != 1) return;
- Point sel = text.getSelection();
- for (int i = 0; i < fieldCount; i++) {
- if (fieldIndices[i].x <= sel.x && sel.x <= fieldIndices[i].y) {
- selectField(i);
- break;
- }
- }
-}
-
-void onResize(Event event) {
- Rectangle rect = getClientArea ();
- int width = rect.width;
- int height = rect.height;
- Point buttonSize = up.computeSize(SWT.DEFAULT, height);
- int buttonHeight = buttonSize.y / 2;
- text.setBounds(0, 0, width - buttonSize.x, height);
- up.setBounds(width - buttonSize.x, 0, buttonSize.x, buttonHeight);
- down.setBounds(width - buttonSize.x, buttonHeight, buttonSize.x, buttonHeight);
-}
-
-void onVerify(Event event) {
- if (ignoreVerify) return;
- event.doit = false;
- int fieldName = fieldNames[currentField];
- int start = fieldIndices[currentField].x;
- int end = fieldIndices[currentField].y;
- int length = end - start;
- String newText = event.text;
- if (fieldName == Calendar.AM_PM) {
- String[] ampm = formatSymbols.getAmPmStrings();
- if (newText.equalsIgnoreCase(ampm[Calendar.AM].substring(0, 1)) || newText.equalsIgnoreCase(ampm[Calendar.AM])) {
- setTextField(fieldName, Calendar.AM, true, false);
- } else if (newText.equalsIgnoreCase(ampm[Calendar.PM].substring(0, 1)) || newText.equalsIgnoreCase(ampm[Calendar.PM])) {
- setTextField(fieldName, Calendar.PM, true, false);
- }
- return;
- }
- if (characterCount > 0) {
- try {
- Integer.parseInt(newText);
- } catch (NumberFormatException ex) {
- return;
- }
- String value = text.getText(start, end - 1);
- int s = value.lastIndexOf(' ');
- if (s != -1) value = value.substring(s + 1);
- newText = "" + value + newText;
- }
- int newTextLength = newText.length();
- boolean first = characterCount == 0;
- characterCount = (newTextLength < length) ? newTextLength : 0;
- int max = calendar.getActualMaximum(fieldName);
- int min = calendar.getActualMinimum(fieldName);
- int newValue = unformattedIntValue(fieldName, newText, characterCount == 0, max);
- if (newValue == -1) {
- characterCount = 0;
- return;
- }
- if (first && newValue == 0 && length > 1) {
- setTextField(fieldName, newValue, false, false);
- } else if (min <= newValue && newValue <= max) {
- setTextField(fieldName, newValue, characterCount == 0, characterCount == 0);
- } else {
- if (newTextLength >= length) {
- newText = newText.substring(newTextLength - length + 1);
- newValue = unformattedIntValue(fieldName, newText, characterCount == 0, max);
- if (newValue != -1) {
- characterCount = length - 1;
- if (min <= newValue && newValue <= max) {
- setTextField(fieldName, newValue, characterCount == 0, true);
- }
- }
- }
- }
-}
-
-void incrementField(int amount) {
- int fieldName = fieldNames[currentField];
- int value = calendar.get(fieldName);
- if (fieldName == Calendar.HOUR) {
- int max = calendar.getMaximum(Calendar.HOUR);
- int min = calendar.getMinimum(Calendar.HOUR);
- if ((value == max && amount == 1) || (value == min && amount == -1)) {
- int temp = currentField;
- currentField = getFieldIndex(Calendar.AM_PM);
- setTextField(Calendar.AM_PM, (calendar.get(Calendar.AM_PM) + 1) % 2, true, true);
- currentField = temp;
- }
- }
- setTextField(fieldName, value + amount, true, true);
-}
-
-void selectField(int index) {
- if (index != currentField) {
- commitCurrentField();
- }
- final int start = fieldIndices[index].x;
- final int end = fieldIndices[index].y;
- Point pt = text.getSelection();
- if (index == currentField && start == pt.x && end == pt.y) return;
- currentField = index;
- display.asyncExec(new Runnable() {
- public void run() {
- if (!text.isDisposed()) {
- String value = text.getText(start, end - 1);
- int s = value.lastIndexOf(' ');
- if (s == -1) s = start;
- else s = start + s + 1;
- text.setSelection(s, end);
- }
- }
- });
-}
-
-void setTextField(int fieldName, int value, boolean commit, boolean adjust) {
- if (commit) {
- int max = calendar.getActualMaximum(fieldName);
- int min = calendar.getActualMinimum(fieldName);
- if (fieldName == Calendar.YEAR) {
- max = MAX_YEAR;
- min = MIN_YEAR;
- /* Special case: convert 1 or 2-digit years into reasonable 4-digit years. */
- int currentYear = Calendar.getInstance().get(Calendar.YEAR);
- int currentCentury = (currentYear / 100) * 100;
- if (value < (currentYear + 30) % 100) value += currentCentury;
- else if (value < 100) value += currentCentury - 100;
- }
- if (value > max) value = min; // wrap
- if (value < min) value = max; // wrap
- }
- int start = fieldIndices[currentField].x;
- int end = fieldIndices[currentField].y;
- text.setSelection(start, end);
- String newValue = formattedStringValue(fieldName, value, adjust);
- StringBuffer buffer = new StringBuffer(newValue);
- /* Convert leading 0's into spaces. */
- int prependCount = end - start - buffer.length();
- for (int i = 0; i < prependCount; i++) {
- switch (fieldName) {
- case Calendar.MINUTE:
- case Calendar.SECOND:
- buffer.insert(0, 0);
- break;
- default:
- buffer.insert(0, ' ');
- break;
- }
- }
- newValue = buffer.toString();
- ignoreVerify = true;
- text.insert(newValue);
- ignoreVerify = false;
- selectField(currentField);
- if (commit) setField(fieldName, value);
-}
-
-void setField(int fieldName, int value) {
- if (calendar.get(fieldName) == value) return;
- if (fieldName == Calendar.AM_PM) {
- calendar.roll(Calendar.HOUR_OF_DAY, 12); // TODO: needs more work for setFormat and locale
- }
- calendar.set(fieldName, value);
- postEvent(SWT.Selection);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- removeListener (SWT.Selection, listener);
- removeListener (SWT.DefaultSelection,listener);
-}
-
-void redraw(int cell, Point cellSize) {
- Point location = getCellLocation(cell, cellSize);
- redraw(location.x, location.y, cellSize.x, cellSize.y, false);
-}
-
-public void setBackground(Color color) {
- checkWidget();
- super.setBackground(color);
- bg = color;
- if (text != null) text.setBackground(color);
-}
-
-/**
- * Sets the receiver's year, month, and day in a single operation.
- * <p>
- * This is the recommended way to set the date, because setting the year,
- * month, and day separately may result in invalid intermediate dates.
- * </p>
- *
- * @param year an integer between 1752 and 9999
- * @param month an integer between 0 and 11
- * @param day a positive integer beginning with 1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setDate (int year, int month, int day) {
- checkWidget ();
- if (!isValidDate(year, month, day)) return;
- calendar.set(Calendar.YEAR, year);
- calendar.set(Calendar.DAY_OF_MONTH, 1);
- calendar.set(Calendar.MONTH, month);
- if ((style & SWT.CALENDAR) != 0) {
- updateControl();
- setDay(day, false);
- } else {
- calendar.set(Calendar.DAY_OF_MONTH, day);
- updateControl();
- }
-}
-
-/**
- * Sets the receiver's date, or day of the month, to the specified day.
- * <p>
- * The first day of the month is 1, and the last day depends on the month and year.
- * If the specified day is not valid for the receiver's month and year, then it is ignored.
- * </p>
- *
- * @param day a positive integer beginning with 1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDate
- */
-public void setDay (int day) {
- checkWidget();
- if (!isValidDate(getYear(), getMonth(), day)) return;
- if ((style & SWT.CALENDAR) != 0) {
- setDay(day, false);
- } else {
- calendar.set(Calendar.DAY_OF_MONTH, day);
- updateControl();
- }
-}
-
-void setDay(int newDay, boolean notify) {
- int firstDay = calendar.getActualMinimum(Calendar.DAY_OF_MONTH);
- int lastDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
- if (!(firstDay <= newDay && newDay <= lastDay)) return;
- Point cellSize = getCellSize(null);
- redraw(getCell(calendar.get(Calendar.DAY_OF_MONTH)), cellSize);
- calendar.set(Calendar.DAY_OF_MONTH, newDay);
- redraw(getCell(calendar.get(Calendar.DAY_OF_MONTH)), cellSize);
- if (notify) postEvent(SWT.Selection);
-}
-
-public void setFont(Font font) {
- checkWidget();
- super.setFont(font);
- if (text != null) text.setFont(font);
- redraw();
-}
-
-public void setForeground(Color color) {
- checkWidget();
- super.setForeground(color);
- fg = color;
- if (text != null) text.setForeground(color);
-}
-
-void setFormat(String string) {
- checkWidget();
- // TODO: this needs to be locale sensitive
- fieldCount = (style & SWT.DATE) != 0 ? ((style & SWT.SHORT) != 0 ? 2 : 3) : ((style & SWT.SHORT) != 0 ? 3 : 4);
- fieldIndices = new Point[fieldCount];
- fieldNames = new int[fieldCount];
- if ((style & SWT.DATE) != 0) {
- fieldNames[0] = Calendar.MONTH;
- fieldIndices[0] = new Point(0, 2);
- if ((style & SWT.SHORT) != 0) {
- fieldNames[1] = Calendar.YEAR;
- fieldIndices[1] = new Point(3, 7);
- } else {
- fieldNames[1] = Calendar.DAY_OF_MONTH;
- fieldIndices[1] = new Point(3, 5);
- fieldNames[2] = Calendar.YEAR;
- fieldIndices[2] = new Point(6, 10);
- }
- } else { /* SWT.TIME */
- fieldNames[0] = Calendar.HOUR;
- fieldIndices[0] = new Point(0, 2);
- fieldNames[1] = Calendar.MINUTE;
- fieldIndices[1] = new Point(3, 5);
- if ((style & SWT.SHORT) != 0) {
- fieldNames[2] = Calendar.AM_PM;
- fieldIndices[2] = new Point(6, 8);
- } else {
- fieldNames[2] = Calendar.SECOND;
- fieldIndices[2] = new Point(6, 8);
- fieldNames[3] = Calendar.AM_PM;
- fieldIndices[3] = new Point(9, 11);
- }
- }
-}
-
-/**
- * Sets the receiver's hours.
- * <p>
- * Hours is an integer between 0 and 23.
- * </p>
- *
- * @param hours an integer between 0 and 23
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHours (int hours) {
- checkWidget ();
- if (!isValidTime(Calendar.HOUR_OF_DAY, hours)) return;
- calendar.set(Calendar.HOUR_OF_DAY, hours);
- updateControl();
-}
-
-/**
- * Sets the receiver's minutes.
- * <p>
- * Minutes is an integer between 0 and 59.
- * </p>
- *
- * @param minutes an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinutes (int minutes) {
- checkWidget ();
- if (!isValidTime(Calendar.MINUTE, minutes)) return;
- calendar.set(Calendar.MINUTE, minutes);
- updateControl();
-}
-
-/**
- * Sets the receiver's month.
- * <p>
- * The first month of the year is 0, and the last month is 11.
- * If the specified month is not valid for the receiver's day and year, then it is ignored.
- * </p>
- *
- * @param month an integer between 0 and 11
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDate
- */
-public void setMonth (int month) {
- checkWidget();
- if (!isValidDate(getYear(), month, getDay())) return;
- calendar.set(Calendar.MONTH, month);
- updateControl();
-}
-
-/**
- * Sets the receiver's seconds.
- * <p>
- * Seconds is an integer between 0 and 59.
- * </p>
- *
- * @param seconds an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSeconds (int seconds) {
- checkWidget ();
- if (!isValidTime(Calendar.SECOND, seconds)) return;
- calendar.set(Calendar.SECOND, seconds);
- updateControl();
-}
-
-/**
- * Sets the receiver's hours, minutes, and seconds in a single operation.
- *
- * @param hours an integer between 0 and 23
- * @param minutes an integer between 0 and 59
- * @param seconds an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setTime (int hours, int minutes, int seconds) {
- checkWidget ();
- if (!isValidTime(Calendar.HOUR_OF_DAY, hours)) return;
- if (!isValidTime(Calendar.MINUTE, minutes)) return;
- if (!isValidTime(Calendar.SECOND, seconds)) return;
- calendar.set(Calendar.HOUR_OF_DAY, hours);
- calendar.set(Calendar.MINUTE, minutes);
- calendar.set(Calendar.SECOND, seconds);
- updateControl();
-}
-
-/**
- * Sets the receiver's year.
- * <p>
- * The first year is 1752 and the last year is 9999.
- * If the specified year is not valid for the receiver's day and month, then it is ignored.
- * </p>
- *
- * @param year an integer between 1752 and 9999
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDate
- */
-public void setYear (int year) {
- checkWidget();
- //if (!isValidDate(year, getMonth(), getDay())) return;
- if (year < MIN_YEAR || year > MAX_YEAR) return;
- calendar.set(Calendar.YEAR, year);
- updateControl();
-}
-
-int unformattedIntValue(int fieldName, String newText, boolean adjust, int max) {
- int newValue;
- try {
- newValue = Integer.parseInt(newText);
- } catch (NumberFormatException ex) {
- return -1;
- }
- if (fieldName == Calendar.MONTH && adjust) {
- newValue--;
- if (newValue == -1) newValue = max;
- }
- if (fieldName == Calendar.HOUR && adjust) {
- if (newValue == 12) newValue = 0; // TODO: needs more work for setFormat and locale
- }
- return newValue;
-}
-
-void updateControl() {
- if (text != null) {
- String string = getFormattedString(style);
- ignoreVerify = true;
- text.setText(string);
- ignoreVerify = false;
- }
- redraw();
-}
-} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/expand/org/eclipse/swt/widgets/ExpandBar.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/expand/org/eclipse/swt/widgets/ExpandBar.java
deleted file mode 100644
index 86e4a47bb7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/expand/org/eclipse/swt/widgets/ExpandBar.java
+++ /dev/null
@@ -1,575 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class support the layout of selectable
- * expand bar items.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>ExpandItem</code>.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>V_SCROLL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Expand, Collapse</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see ExpandItem
- * @see ExpandEvent
- * @see ExpandListener
- * @see ExpandAdapter
- * @see <a href="http://www.eclipse.org/swt/snippets/#expandbar">ExpandBar snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.2
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ExpandBar extends Composite {
- ExpandItem [] items;
- int itemCount;
- ExpandItem focusItem;
- int spacing;
- int yCurrentScroll;
- Font font;
- Color foreground;
- Listener listener;
- boolean inDispose;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#V_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ExpandBar (Composite parent, int style) {
- super (parent, checkStyle (style));
- items = new ExpandItem [4];
-
- listener = new Listener () {
- public void handleEvent (Event event) {
- switch (event.type) {
- case SWT.Dispose: onDispose (event); break;
- case SWT.MouseDown: onMouseDown (event); break;
- case SWT.MouseUp: onMouseUp (event); break;
- case SWT.Paint: onPaint (event); break;
- case SWT.Resize: onResize (); break;
- case SWT.KeyDown: onKeyDown (event); break;
- case SWT.FocusIn: onFocus (); break;
- case SWT.FocusOut: onFocus (); break;
- case SWT.Traverse: onTraverse (event); break;
- }
- }
- };
- addListener (SWT.Dispose, listener);
- addListener (SWT.MouseDown, listener);
- addListener (SWT.MouseUp, listener);
- addListener (SWT.Paint, listener);
- addListener (SWT.Resize, listener);
- addListener (SWT.KeyDown, listener);
- addListener (SWT.FocusIn, listener);
- addListener (SWT.FocusOut, listener);
- addListener (SWT.Traverse, listener);
-
- ScrollBar verticalBar = getVerticalBar ();
- if (verticalBar != null) {
- verticalBar.addListener (SWT.Selection, new Listener () {
- public void handleEvent (Event event) {
- onScroll (event);
- }
- });
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an item in the receiver is expanded or collapsed
- * by sending it one of the messages defined in the <code>ExpandListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ExpandListener
- * @see #removeExpandListener
- */
-public void addExpandListener (ExpandListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Expand, typedListener);
- addListener (SWT.Collapse, typedListener);
-}
-
-static int checkStyle (int style) {
- return style & ~SWT.H_SCROLL;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int height = 0, width = 0;
- if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
- if (itemCount > 0) {
- height += spacing;
- GC gc = new GC (this);
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- height += item.getHeaderHeight ();
- if (item.expanded) height += item.height;
- height += spacing;
- width = Math.max (width, item.getPreferredWidth (gc));
- }
- gc.dispose ();
- }
- }
- if (width == 0) width = DEFAULT_WIDTH;
- if (height == 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- Rectangle trim = computeTrim (0, 0, width, height);
- return new Point (trim.width, trim.height);
-}
-
-void createItem (ExpandItem item, int style, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (itemCount == items.length) {
- ExpandItem [] newItems = new ExpandItem [itemCount + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- System.arraycopy (items, index, items, index + 1, itemCount - index);
- items [index] = item;
- itemCount++;
- if (focusItem == null) focusItem = item;
- item.width = Math.max (0, getClientArea ().width - spacing * 2);
- layoutItems (index, true);
-}
-
-void destroyItem (ExpandItem item) {
- if (inDispose) return;
- int index = 0;
- while (index < itemCount) {
- if (items [index] == item) break;
- index++;
- }
- if (index == itemCount) return;
- if (item == focusItem) {
- int focusIndex = index > 0 ? index - 1 : 1;
- if (focusIndex < itemCount) {
- focusItem = items [focusIndex];
- focusItem.redraw ();
- } else {
- focusItem = null;
- }
- }
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- item.redraw ();
- layoutItems (index, true);
-}
-
-int getBandHeight () {
- if (font == null) return ExpandItem.CHEVRON_SIZE;
- GC gc = new GC (this);
- FontMetrics metrics = gc.getFontMetrics ();
- gc.dispose ();
- return Math.max (ExpandItem.CHEVRON_SIZE, metrics.getHeight ());
-}
-
-public Color getForeground () {
- checkWidget ();
- if (foreground == null) {
- Display display = getDisplay ();
- return display.getSystemColor (SWT.COLOR_TITLE_FOREGROUND);
- }
- return foreground;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ExpandItem getItem (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return itemCount;
-}
-
-/**
- * Returns an array of <code>ExpandItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ExpandItem [] getItems () {
- checkWidget ();
- ExpandItem [] result = new ExpandItem [itemCount];
- System.arraycopy (items, 0, result, 0, itemCount);
- return result;
-}
-
-/**
- * Returns the receiver's spacing.
- *
- * @return the spacing
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSpacing () {
- checkWidget ();
- return spacing;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (ExpandItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i = 0; i < itemCount; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-
-void layoutItems (int index, boolean setScrollbar) {
- if (index < itemCount) {
- int y = spacing - yCurrentScroll;
- for (int i = 0; i < index; i++) {
- ExpandItem item = items [i];
- if (item.expanded) y += item.height;
- y += item.getHeaderHeight() + spacing;
- }
- for (int i = index; i < itemCount; i++) {
- ExpandItem item = items [i];
- item.setBounds (spacing, y, 0, 0, true, false);
- if (item.expanded) y += item.height;
- y += item.getHeaderHeight() + spacing;
- }
- }
- if (setScrollbar) setScrollbar ();
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when items in the receiver are expanded or collapsed.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ExpandListener
- * @see #addExpandListener
- */
-public void removeExpandListener (ExpandListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Expand, listener);
- eventTable.unhook (SWT.Collapse, listener);
-}
-
-public void setFont(Font font) {
- super.setFont (font);
- this.font = font;
- layoutItems (0, true);
-}
-
-public void setForeground (Color color) {
- super.setForeground (color);
- foreground = color;
-}
-
-void setScrollbar () {
- if (itemCount == 0) return;
- ScrollBar verticalBar = getVerticalBar ();
- if (verticalBar == null) return;
- int height = getClientArea ().height;
- ExpandItem item = items [itemCount - 1];
- int maxHeight = item.y + getBandHeight () + spacing;
- if (item.expanded) maxHeight += item.height;
-
- //claim bottom free space
- if (yCurrentScroll > 0 && height > maxHeight) {
- yCurrentScroll = Math.max (0, yCurrentScroll + maxHeight - height);
- layoutItems (0, false);
- }
- maxHeight += yCurrentScroll;
-
- int selection = Math.min (yCurrentScroll, maxHeight);
- int increment = verticalBar.getIncrement ();
- int pageIncrement = verticalBar.getPageIncrement ();
- verticalBar.setValues(selection, 0, maxHeight, height, increment, pageIncrement);
- verticalBar.setVisible(maxHeight > height);
-}
-
-/**
- * Sets the receiver's spacing. Spacing specifies the number of pixels allocated around
- * each item.
- *
- * @param spacing the spacing around each item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSpacing (int spacing) {
- checkWidget ();
- if (spacing < 0) return;
- if (spacing == this.spacing) return;
- this.spacing = spacing;
- int width = Math.max (0, getClientArea ().width - spacing * 2);
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items[i];
- if (item.width != width) item.setBounds (0, 0, width, item.height, false, true);
- }
- layoutItems (0, true);
- redraw ();
-}
-
-void showItem (ExpandItem item) {
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setVisible (item.expanded);
- }
- item.redraw ();
- int index = indexOf (item);
- layoutItems (index + 1, true);
-}
-
-void onDispose (Event event) {
- removeListener (SWT.Dispose, listener);
- notifyListeners (SWT.Dispose, event);
- event.type = SWT.None;
- /*
- * Usually when an item is disposed, destroyItem will change the size of the items array,
- * reset the bounds of all the tabs and manage the widget associated with the tab.
- * Since the whole folder is being disposed, this is not necessary. For speed
- * the inDispose flag is used to skip over this part of the item dispose.
- */
- inDispose = true;
-
- for (int i = 0; i < itemCount; i++) {
- items [i].dispose ();
- }
- items = null;
- font = null;
- foreground = null;
- focusItem = null;
-}
-
-void onFocus () {
- if (focusItem != null) focusItem.redraw ();
-}
-
-void onKeyDown (Event event) {
- if (focusItem == null) return;
- switch (event.keyCode) {
- case 13: /* Return */
- case 32: /* Space */
- Event ev = new Event ();
- ev.item = focusItem;
- sendEvent (focusItem.expanded ? SWT.Collapse :SWT.Expand, ev);
- focusItem.expanded = !focusItem.expanded;
- showItem (focusItem);
- break;
- case SWT.ARROW_UP: {
- int focusIndex = indexOf (focusItem);
- if (focusIndex > 0) {
- focusItem.redraw ();
- focusItem = items [focusIndex - 1];
- focusItem.redraw ();
- }
- break;
- }
- case SWT.ARROW_DOWN: {
- int focusIndex = indexOf (focusItem);
- if (focusIndex < itemCount - 1) {
- focusItem.redraw ();
- focusItem = items [focusIndex + 1];
- focusItem.redraw ();
- }
- break;
- }
- }
-}
-
-void onMouseDown (Event event) {
- if (event.button != 1) return;
- int x = event.x;
- int y = event.y;
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items[i];
- boolean hover = item.x <= x && x < (item.x + item.width) && item.y <= y && y < (item.y + getBandHeight ());
- if (hover && item != focusItem) {
- focusItem.redraw ();
- focusItem = item;
- focusItem.redraw ();
- forceFocus ();
- break;
- }
- }
-}
-
-void onMouseUp (Event event) {
- if (event.button != 1) return;
- if (focusItem == null) return;
- int x = event.x;
- int y = event.y;
- boolean hover = focusItem.x <= x && x < (focusItem.x + focusItem.width) && focusItem.y <= y && y < (focusItem.y + getBandHeight ());
- if (hover) {
- Event ev = new Event ();
- ev.item = focusItem;
- notifyListeners (focusItem.expanded ? SWT.Collapse : SWT.Expand, ev);
- focusItem.expanded = !focusItem.expanded;
- showItem (focusItem);
- }
-}
-
-void onPaint (Event event) {
- boolean hasFocus = isFocusControl ();
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- item.drawItem (event.gc, hasFocus && item == focusItem);
- }
-}
-
-void onResize () {
- Rectangle rect = getClientArea ();
- int width = Math.max (0, rect.width - spacing * 2);
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items[i];
- item.setBounds (0, 0, width, item.height, false, true);
- }
- setScrollbar ();
-}
-
-void onScroll (Event event) {
- ScrollBar verticalBar = getVerticalBar ();
- if (verticalBar != null) {
- yCurrentScroll = verticalBar.getSelection();
- layoutItems (0, false);
- }
-}
-
-void onTraverse (Event event) {
- switch (event.detail) {
- case SWT.TRAVERSE_TAB_NEXT:
- case SWT.TRAVERSE_TAB_PREVIOUS:
- event.doit = true;
- break;
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/expand/org/eclipse/swt/widgets/ExpandItem.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/expand/org/eclipse/swt/widgets/ExpandItem.java
deleted file mode 100644
index a8fca05283..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/expand/org/eclipse/swt/widgets/ExpandItem.java
+++ /dev/null
@@ -1,391 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a expandable item in a expand bar.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see ExpandBar
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.2
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ExpandItem extends Item {
- ExpandBar parent;
- Control control;
- boolean expanded;
- int x, y, width, height;
- int imageHeight, imageWidth;
- static final int TEXT_INSET = 6;
- static final int BORDER = 1;
- static final int CHEVRON_SIZE = 24;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ExpandItem (ExpandBar parent, int style) {
- this (parent, style, checkNull (parent).getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent, a
- * style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ExpandItem (ExpandBar parent, int style, int index) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, style, index);
-}
-
-static ExpandBar checkNull (ExpandBar control) {
- if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return control;
-}
-
-public void dispose () {
- if (isDisposed ()) return;
- //if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- parent.destroyItem (this);
- super.dispose();
- parent = null;
- control = null;
-}
-
-void drawChevron (GC gc, int x, int y) {
- int [] polyline1, polyline2;
- if (expanded) {
- int px = x + 4 + 5;
- int py = y + 4 + 7;
- polyline1 = new int [] {
- px,py, px+1,py, px+1,py-1, px+2,py-1, px+2,py-2, px+3,py-2, px+3,py-3,
- px+3,py-2, px+4,py-2, px+4,py-1, px+5,py-1, px+5,py, px+6,py};
- py += 4;
- polyline2 = new int [] {
- px,py, px+1,py, px+1,py-1, px+2,py-1, px+2,py-2, px+3,py-2, px+3,py-3,
- px+3,py-2, px+4,py-2, px+4,py-1, px+5,py-1, px+5,py, px+6,py};
- } else {
- int px = x + 4 + 5;
- int py = y + 4 + 4;
- polyline1 = new int[] {
- px,py, px+1,py, px+1,py+1, px+2,py+1, px+2,py+2, px+3,py+2, px+3,py+3,
- px+3,py+2, px+4,py+2, px+4,py+1, px+5,py+1, px+5,py, px+6,py};
- py += 4;
- polyline2 = new int [] {
- px,py, px+1,py, px+1,py+1, px+2,py+1, px+2,py+2, px+3,py+2, px+3,py+3,
- px+3,py+2, px+4,py+2, px+4,py+1, px+5,py+1, px+5,py, px+6,py};
- }
- gc.setForeground (display.getSystemColor (SWT.COLOR_TITLE_FOREGROUND));
- gc.drawPolyline (polyline1);
- gc.drawPolyline (polyline2);
-}
-
-void drawItem (GC gc, boolean drawFocus) {
- int headerHeight = parent.getBandHeight ();
- Display display = getDisplay ();
- gc.setForeground (display.getSystemColor (SWT.COLOR_TITLE_BACKGROUND));
- gc.setBackground (display.getSystemColor (SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
- gc.fillGradientRectangle (x, y, width, headerHeight, true);
- if (expanded) {
- gc.setForeground (display.getSystemColor (SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
- gc.drawLine (x, y + headerHeight, x, y + headerHeight + height - 1);
- gc.drawLine (x, y + headerHeight + height - 1, x + width - 1, y + headerHeight + height - 1);
- gc.drawLine (x + width - 1, y + headerHeight + height - 1, x + width - 1, y + headerHeight);
- }
- int drawX = x;
- if (image != null) {
- drawX += ExpandItem.TEXT_INSET;
- if (imageHeight > headerHeight) {
- gc.drawImage (image, drawX, y + headerHeight - imageHeight);
- } else {
- gc.drawImage (image, drawX, y + (headerHeight - imageHeight) / 2);
- }
- drawX += imageWidth;
- }
- if (text.length() > 0) {
- drawX += ExpandItem.TEXT_INSET;
- Point size = gc.stringExtent (text);
- gc.setForeground (parent.getForeground ());
- gc.drawString (text, drawX, y + (headerHeight - size.y) / 2, true);
- }
- int chevronSize = ExpandItem.CHEVRON_SIZE;
- drawChevron (gc, x + width - chevronSize, y + (headerHeight - chevronSize) / 2);
- if (drawFocus) {
- gc.drawFocus (x + 1, y + 1, width - 2, headerHeight - 2);
- }
-}
-
-/**
- * Returns the control that is shown when the item is expanded.
- * If no control has been set, return <code>null</code>.
- *
- * @return the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl() {
- checkWidget ();
- return control;
-}
-
-/**
- * Returns <code>true</code> if the receiver is expanded,
- * and false otherwise.
- *
- * @return the expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getExpanded() {
- checkWidget ();
- return expanded;
-}
-
-/**
- * Returns the height of the receiver's header
- *
- * @return the height of the header
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getHeaderHeight () {
- checkWidget ();
- return Math.max (parent.getBandHeight (), imageHeight);
-}
-
-/**
- * Gets the height of the receiver.
- *
- * @return the height
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getHeight () {
- checkWidget ();
- return height;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>ExpandBar</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ExpandBar getParent () {
- checkWidget ();
- return parent;
-}
-
-int getPreferredWidth (GC gc) {
- int width = ExpandItem.TEXT_INSET * 2 + ExpandItem.CHEVRON_SIZE;
- if (image != null) {
- width += ExpandItem.TEXT_INSET + imageWidth;
- }
- if (text.length() > 0) {
- width += gc.stringExtent (text).x;
- }
- return width;
-}
-
-void redraw () {
- int headerHeight = parent.getBandHeight ();
- if (imageHeight > headerHeight) {
- parent.redraw (x + ExpandItem.TEXT_INSET, y + headerHeight - imageHeight, imageWidth, imageHeight, false);
- }
- parent.redraw (x, y, width, headerHeight + height, false);
-}
-
-void setBounds (int x, int y, int width, int height, boolean move, boolean size) {
- redraw ();
- int headerHeight = parent.getBandHeight ();
- if (move) {
- if (imageHeight > headerHeight) {
- y += (imageHeight - headerHeight);
- }
- this.x = x;
- this.y = y;
- redraw ();
- }
- if (size) {
- this.width = width;
- this.height = height;
- redraw ();
- }
- if (control != null && !control.isDisposed ()) {
- if (move) control.setLocation (x + BORDER, y + headerHeight);
- if (size) control.setSize (Math.max (0, width - 2 * BORDER), Math.max (0, height - BORDER));
- }
-}
-
-/**
- * Sets the control that is shown when the item is expanded.
- *
- * @param control the new control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl(Control control) {
- checkWidget ();
- if (control != null) {
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- this.control = control;
- if (control != null) {
- control.setVisible (expanded);
- int headerHeight = parent.getBandHeight ();
- control.setBounds (x + BORDER, y + headerHeight, Math.max (0, width - 2 * BORDER), Math.max (0, height - BORDER));
- }
-}
-
-/**
- * Sets the expanded state of the receiver.
- *
- * @param expanded the new expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setExpanded (boolean expanded) {
- checkWidget ();
- this.expanded = expanded;
- parent.showItem (this);
-}
-
-public void setImage (Image image) {
- super.setImage (image);
- int oldImageHeight = imageHeight;
- if (image != null) {
- Rectangle bounds = image.getBounds ();
- imageHeight = bounds.height;
- imageWidth = bounds.width;
- } else {
- imageHeight = imageWidth = 0;
- }
- if (oldImageHeight != imageHeight) {
- parent.layoutItems (parent.indexOf (this), true);
- } else {
- redraw ();
- }
-}
-
-/**
- * Sets the height of the receiver. This is height of the item when it is expanded,
- * excluding the height of the header.
- *
- * @param height the new height
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHeight (int height) {
- checkWidget ();
- if (height < 0) return;
- setBounds (0, 0, width, height, false, true);
- if (expanded) parent.layoutItems (parent.indexOf (this) + 1, true);
-}
-
-public void setText (String string) {
- super.setText (string);
- redraw ();
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/graphics/org/eclipse/swt/graphics/Path.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/graphics/org/eclipse/swt/graphics/Path.java
deleted file mode 100644
index 31c0b13b96..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/graphics/org/eclipse/swt/graphics/Path.java
+++ /dev/null
@@ -1,463 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class represent paths through the two-dimensional
- * coordinate system. Paths do not have to be continuous, and can be
- * described using lines, rectangles, arcs, cubic or quadratic bezier curves,
- * glyphs, or other paths.
- * <p>
- * Application code must explicitly invoke the <code>Path.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#path">Path, Pattern snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Path extends Resource {
-
- /**
- * the OS resource for the Path
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
-/**
- * Constructs a new empty Path.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the path
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Path (Device device) {
- super(device);
- SWT.error(SWT.ERROR_NO_GRAPHICS_LIBRARY);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new Path that is a copy of <code>path</code>. If
- * <code>flatness</code> is less than or equal to zero, an unflatten
- * copy of the path is created. Otherwise, it specifies the maximum
- * error between the path and its flatten copy. Smaller numbers give
- * better approximation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the path
- * @param path the path to make a copy
- * @param flatness the flatness value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the path is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the path has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- * @since 3.4
- */
-public Path (Device device, Path path, float flatness) {
- super(device);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- flatness = Math.max(0, flatness);
- SWT.error(SWT.ERROR_NO_GRAPHICS_LIBRARY);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new Path with the specifed PathData.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the path
- * @param data the data for the path
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the data is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- * @since 3.4
- */
-public Path (Device device, PathData data) {
- this(device);
- if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(data);
-}
-
-/**
- * Adds to the receiver a circular or elliptical arc that lies within
- * the specified rectangular area.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc
- * @param y the y coordinate of the upper-left corner of the arc
- * @param width the width of the arc
- * @param height the height of the arc
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addArc(float x, float y, float width, float height, float startAngle, float arcAngle) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-/**
- * Adds to the receiver the path described by the parameter.
- *
- * @param path the path to add to the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addPath(Path path) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-}
-
-/**
- * Adds to the receiver the rectangle specified by x, y, width and height.
- *
- * @param x the x coordinate of the rectangle to add
- * @param y the y coordinate of the rectangle to add
- * @param width the width of the rectangle to add
- * @param height the height of the rectangle to add
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addRectangle(float x, float y, float width, float height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-/**
- * Adds to the receiver the pattern of glyphs generated by drawing
- * the given string using the given font starting at the point (x, y).
- *
- * @param string the text to use
- * @param x the x coordinate of the starting point
- * @param y the y coordinate of the starting point
- * @param font the font to use
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the font is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addString(String string, float x, float y, Font font) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (font == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-}
-
-/**
- * Returns <code>true</code> if the specified point is contained by
- * the receiver and false otherwise.
- * <p>
- * If outline is <code>true</code>, the point (x, y) checked for containment in
- * the receiver's outline. If outline is <code>false</code>, the point is
- * checked to see if it is contained within the bounds of the (closed) area
- * covered by the receiver.
- *
- * @param x the x coordinate of the point to test for containment
- * @param y the y coordinate of the point to test for containment
- * @param gc the GC to use when testing for containment
- * @param outline controls whether to check the outline or contained area of the path
- * @return <code>true</code> if the path contains the point and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains(float x, float y, GC gc, boolean outline) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return false;
-}
-
-/**
- * Closes the current sub path by adding to the receiver a line
- * from the current point of the path back to the starting point
- * of the sub path.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void close() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-/**
- * Adds to the receiver a cubic bezier curve based on the parameters.
- *
- * @param cx1 the x coordinate of the first control point of the spline
- * @param cy1 the y coordinate of the first control of the spline
- * @param cx2 the x coordinate of the second control of the spline
- * @param cy2 the y coordinate of the second control of the spline
- * @param x the x coordinate of the end point of the spline
- * @param y the y coordinate of the end point of the spline
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-/**
- * Replaces the first four elements in the parameter with values that
- * describe the smallest rectangle that will completely contain the
- * receiver (i.e. the bounding box).
- *
- * @param bounds the array to hold the result
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the bounding box</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getBounds(float[] bounds) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (bounds.length < 4) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-}
-
-/**
- * Replaces the first two elements in the parameter with values that
- * describe the current point of the path.
- *
- * @param point the array to hold the result
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the end point</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getCurrentPoint(float[] point) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (point == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (point.length < 2) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-}
-
-/**
- * Returns a device independent representation of the receiver.
- *
- * @return the PathData for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see PathData
- */
-public PathData getPathData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return null;
-}
-
-/**
- * Adds to the receiver a line from the current point to
- * the point specified by (x, y).
- *
- * @param x the x coordinate of the end of the line to add
- * @param y the y coordinate of the end of the line to add
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void lineTo(float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-/**
- * Sets the current point of the receiver to the point
- * specified by (x, y). Note that this starts a new
- * sub path.
- *
- * @param x the x coordinate of the new end point
- * @param y the y coordinate of the new end point
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void moveTo(float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-/**
- * Adds to the receiver a quadratic curve based on the parameters.
- *
- * @param cx the x coordinate of the control point of the spline
- * @param cy the y coordinate of the control point of the spline
- * @param x the x coordinate of the end point of the spline
- * @param y the y coordinate of the end point of the spline
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void quadTo(float cx, float cy, float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-void destroy() {
- handle = 0;
-}
-
-void init(PathData data) {
- byte[] types = data.types;
- float[] points = data.points;
- for (int i = 0, j = 0; i < types.length; i++) {
- switch (types[i]) {
- case SWT.PATH_MOVE_TO:
- moveTo(points[j++], points[j++]);
- break;
- case SWT.PATH_LINE_TO:
- lineTo(points[j++], points[j++]);
- break;
- case SWT.PATH_CUBIC_TO:
- cubicTo(points[j++], points[j++], points[j++], points[j++], points[j++], points[j++]);
- break;
- case SWT.PATH_QUAD_TO:
- quadTo(points[j++], points[j++], points[j++], points[j++]);
- break;
- case SWT.PATH_CLOSE:
- close();
- break;
- default:
- dispose();
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
-}
-
-/**
- * Returns <code>true</code> if the Path has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Path.
- * When a Path has been disposed, it is an error to
- * invoke any other method using the Path.
- *
- * @return <code>true</code> when the Path is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString() {
- if (isDisposed()) return "Path {*DISPOSED*}";
- return "Path {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/graphics/org/eclipse/swt/graphics/Pattern.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/graphics/org/eclipse/swt/graphics/Pattern.java
deleted file mode 100644
index c5b9947eb6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/graphics/org/eclipse/swt/graphics/Pattern.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class represent patterns to use while drawing. Patterns
- * can be specified either as bitmaps or gradients.
- * <p>
- * Application code must explicitly invoke the <code>Pattern.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#path">Path, Pattern snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Pattern extends Resource {
-
- /**
- * the OS resource for the Pattern
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
-/**
- * Constructs a new Pattern given an image. Drawing with the resulting
- * pattern will cause the image to be tiled over the resulting area.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the pattern
- * @param image the image that the pattern will draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device, or the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Pattern(Device device, Image image) {
- super(device);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new Pattern that represents a linear, two color
- * gradient. Drawing with the pattern will cause the resulting area to be
- * tiled with the gradient specified by the arguments.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the pattern
- * @param x1 the x coordinate of the starting corner of the gradient
- * @param y1 the y coordinate of the starting corner of the gradient
- * @param x2 the x coordinate of the ending corner of the gradient
- * @param y2 the y coordinate of the ending corner of the gradient
- * @param color1 the starting color of the gradient
- * @param color2 the ending color of the gradient
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device,
- * or if either color1 or color2 is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either color1 or color2 has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Pattern(Device device, float x1, float y1, float x2, float y2, Color color1, Color color2) {
- this(device, x1, y1, x2, y2, color1, 0xFF, color2, 0xFF);
-}
-
-/**
- * Constructs a new Pattern that represents a linear, two color
- * gradient. Drawing with the pattern will cause the resulting area to be
- * tiled with the gradient specified by the arguments.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the pattern
- * @param x1 the x coordinate of the starting corner of the gradient
- * @param y1 the y coordinate of the starting corner of the gradient
- * @param x2 the x coordinate of the ending corner of the gradient
- * @param y2 the y coordinate of the ending corner of the gradient
- * @param color1 the starting color of the gradient
- * @param alpha1 the starting alpha value of the gradient
- * @param color2 the ending color of the gradient
- * @param alpha2 the ending alpha value of the gradient
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device,
- * or if either color1 or color2 is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either color1 or color2 has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- *
- * @since 3.2
- */
-public Pattern(Device device, float x1, float y1, float x2, float y2, Color color1, int alpha1, Color color2, int alpha2) {
- super(device);
- if (color1 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color1.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (color2 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color2.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-void destroy() {
- handle = 0;
-}
-
-/**
- * Returns <code>true</code> if the Pattern has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Pattern.
- * When a Pattern has been disposed, it is an error to
- * invoke any other method using the Pattern.
- *
- * @return <code>true</code> when the Pattern is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString() {
- if (isDisposed()) return "Pattern {*DISPOSED*}";
- return "Pattern {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/graphics/org/eclipse/swt/graphics/Transform.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/graphics/org/eclipse/swt/graphics/Transform.java
deleted file mode 100644
index 0fdfaa82c5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/graphics/org/eclipse/swt/graphics/Transform.java
+++ /dev/null
@@ -1,357 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class represent transformation matrices for
- * points expressed as (x, y) pairs of floating point numbers.
- * <p>
- * Application code must explicitly invoke the <code>Transform.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Transform extends Resource {
- /**
- * the OS resource for the Transform
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
-/**
- * Constructs a new identity Transform.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform (Device device) {
- this(device, 1, 0, 0, 1, 0, 0);
-}
-
-/**
- * Constructs a new Transform given an array of elements that represent the
- * matrix that describes the transformation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- * @param elements an array of floats that describe the transformation matrix
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device, or the elements array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the elements array is too small to hold the matrix values</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform(Device device, float[] elements) {
- this (device, checkTransform(elements)[0], elements[1], elements[2], elements[3], elements[4], elements[5]);
-}
-
-/**
- * Constructs a new Transform given all of the elements that represent the
- * matrix that describes the transformation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- * @param m11 the first element of the first row of the matrix
- * @param m12 the second element of the first row of the matrix
- * @param m21 the first element of the second row of the matrix
- * @param m22 the second element of the second row of the matrix
- * @param dx the third element of the first row of the matrix
- * @param dy the third element of the second row of the matrix
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform (Device device, float m11, float m12, float m21, float m22, float dx, float dy) {
- super(device);
- SWT.error(SWT.ERROR_NO_GRAPHICS_LIBRARY);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-static float[] checkTransform(float[] elements) {
- if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return elements;
-}
-
-void destroy() {
- handle = 0;
-}
-
-/**
- * Fills the parameter with the values of the transformation matrix
- * that the receiver represents, in the order {m11, m12, m21, m22, dx, dy}.
- *
- * @param elements array to hold the matrix values
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the matrix values</li>
- * </ul>
- */
-public void getElements(float[] elements) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes the
- * identity matrix.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public void identity() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes
- * the mathematical inverse of the matrix it previously represented.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_CANNOT_INVERT_MATRIX - if the matrix is not invertible</li>
- * </ul>
- */
-public void invert() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-/**
- * Returns <code>true</code> if the Transform has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Transform.
- * When a Transform has been disposed, it is an error to
- * invoke any other method using the Transform.
- *
- * @return <code>true</code> when the Transform is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns <code>true</code> if the Transform represents the identity matrix
- * and false otherwise.
- *
- * @return <code>true</code> if the receiver is an identity Transform, and <code>false</code> otherwise
- */
-public boolean isIdentity() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float[] m = new float[6];
- getElements(m);
- return m[0] == 1 && m[1] == 0 && m[2] == 0 && m[3] == 1 && m[4] == 0 && m[5] == 0;
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes the
- * the result of multiplying the matrix it previously represented by the
- * argument.
- *
- * @param matrix the matrix to multiply the receiver by
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- */
-public void multiply(Transform matrix) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (matrix == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (matrix.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation rotated by the specified angle.
- * The angle is specified in degrees and for the identity transform 0 degrees
- * is at the 3 o'clock position. A positive value indicates a clockwise rotation
- * while a negative value indicates a counter-clockwise rotation.
- *
- * @param angle the angle to rotate the transformation by
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void rotate(float angle) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation scaled by (scaleX, scaleY).
- *
- * @param scaleX the amount to scale in the X direction
- * @param scaleY the amount to scale in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void scale(float scaleX, float scaleY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-/**
- * Modifies the receiver to represent a new transformation given all of
- * the elements that represent the matrix that describes that transformation.
- *
- * @param m11 the first element of the first row of the matrix
- * @param m12 the second element of the first row of the matrix
- * @param m21 the first element of the second row of the matrix
- * @param m22 the second element of the second row of the matrix
- * @param dx the third element of the first row of the matrix
- * @param dy the third element of the second row of the matrix
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setElements(float m11, float m12, float m21, float m22, float dx, float dy) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation sheared by (shearX, shearY).
- *
- * @param shearX the shear factor in the X direction
- * @param shearY the shear factor in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public void shear(float shearX, float shearY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-/**
- * Given an array containing points described by alternating x and y values,
- * modify that array such that each point has been replaced with the result of
- * applying the transformation represented by the receiver to that point.
- *
- * @param pointArray an array of alternating x and y values to be transformed
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void transform(float[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation translated by (offsetX, offsetY).
- *
- * @param offsetX the distance to translate in the X direction
- * @param offsetY the distance to translate in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void translate(float offsetX, float offsetY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString() {
- if (isDisposed()) return "Transform {*DISPOSED*}";
- float[] elements = new float[6];
- getElements(elements);
- return "Transform {" + elements [0] + "," + elements [1] + "," +elements [2] + "," +elements [3] + "," +elements [4] + "," +elements [5] + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/ime/org/eclipse/swt/widgets/IME.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/ime/org/eclipse/swt/widgets/IME.java
deleted file mode 100644
index 8b144cb99a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/ime/org/eclipse/swt/widgets/IME.java
+++ /dev/null
@@ -1,268 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent input method editors.
- * These are typically in-line pre-edit text areas that allow
- * the user to compose characters from Far Eastern languages
- * such as Japanese, Chinese or Korean.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>ImeComposition</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.4
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class IME extends Widget {
- Canvas parent;
- int caretOffset;
- int startOffset;
- int commitCount;
- String text;
- int [] ranges;
- TextStyle [] styles;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-IME () {
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a canvas control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public IME (Canvas parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget ();
-}
-
-void createWidget () {
- text = "";
- startOffset = -1;
- if (parent.getIME () == null) {
- parent.setIME (this);
- }
-}
-
-/**
- * Returns the offset of the caret from the start of the document.
- * The caret is within the current composition.
- *
- * @return the caret offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretOffset () {
- checkWidget ();
- return startOffset + caretOffset;
-}
-
-/**
- * Returns the commit count of the composition. This is the
- * number of characters that have been composed. When the
- * commit count is equal to the length of the composition
- * text, then the in-line edit operation is complete.
- *
- * @return the commit count
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see IME#getText
- */
-public int getCommitCount () {
- checkWidget ();
- return commitCount;
-}
-
-/**
- * Returns the offset of the composition from the start of the document.
- * This is the start offset of the composition within the document and
- * in not changed by the input method editor itself during the in-line edit
- * session.
- *
- * @return the offset of the composition
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCompositionOffset () {
- checkWidget ();
- return startOffset;
-}
-
-/**
- * Returns the ranges for the style that should be applied during the
- * in-line edit session.
- * <p>
- * The ranges array contains start and end pairs. Each pair refers to
- * the corresponding style in the styles array. For example, the pair
- * that starts at ranges[n] and ends at ranges[n+1] uses the style
- * at styles[n/2] returned by <code>getStyles()</code>.
- * </p>
- * @return the ranges for the styles
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see IME#getStyles
- */
-public int [] getRanges () {
- checkWidget ();
- return ranges != null ? ranges : new int [0];
-}
-
-/**
- * Returns the styles for the ranges.
- * <p>
- * The ranges array contains start and end pairs. Each pair refers to
- * the corresponding style in the styles array. For example, the pair
- * that starts at ranges[n] and ends at ranges[n+1] uses the style
- * at styles[n/2].
- * </p>
- *
- * @return the ranges for the styles
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see IME#getRanges
- */
-public TextStyle [] getStyles () {
- checkWidget ();
- return styles != null ? styles : new TextStyle [0];
-}
-
-/**
- * Returns the composition text.
- * <p>
- * The text for an IME is the characters in the widget that
- * are in the current composition. When the commit count is
- * equal to the length of the composition text, then the
- * in-line edit operation is complete.
- * </p>
- *
- * @return the widget text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-/**
- * Returns <code>true</code> if the caret should be wide, and
- * <code>false</code> otherwise. In some languages, for example
- * Korean, the caret is typically widened to the width of the
- * current character in the in-line edit session.
- *
- * @return the wide caret state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getWideCaret() {
- return false;
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (this == parent.getIME ()) parent.setIME (null);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
- text = null;
- styles = null;
- ranges = null;
-}
-
-/**
- * Sets the offset of the composition from the start of the document.
- * This is the start offset of the composition within the document and
- * in not changed by the input method editor itself during the in-line edit
- * session but may need to be changed by clients of the IME. For example,
- * if during an in-line edit operation, a text editor inserts characters
- * above the IME, then the IME must be informed that the composition
- * offset has changed.
- *
- * @param offset the offset of the composition
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCompositionOffset (int offset) {
- checkWidget ();
- if (offset < 0) return;
- if (startOffset != -1) {
- startOffset = offset;
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/tabfolder/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/tabfolder/org/eclipse/swt/widgets/TabFolder.java
deleted file mode 100644
index 9c1384f2c2..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/tabfolder/org/eclipse/swt/widgets/TabFolder.java
+++ /dev/null
@@ -1,1230 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class implement the notebook user interface
- * metaphor. It allows the user to select a notebook page from
- * set of pages.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TabItem</code>.
- * <code>Control</code> children are created and then set into a
- * tab item using <code>TabItem#setControl</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>TOP, BOTTOM</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles TOP and BOTTOM may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tabfolder">TabFolder, TabItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TabFolder extends Composite {
- TabItem items[] = new TabItem [0];
- int selectedIndex = -1;
- int xClient, yClient;
- int imageHeight = -1; // all images have the height of the first image ever set
- int topTabIndex = 0; // index of the first visible tab. Used for tab scrolling
- boolean scrollButtonDown = false; // true=one of the scroll buttons is being pushed
- boolean inDispose = false;
- String toolTipText;
-
- // internal constants
- static final int SCROLL_BUTTON_SIZE = 20; // width/height of the scroll button used for scrolling tab items
- static final int CLIENT_MARGIN_WIDTH = 2; // distance between widget border and client rect
- static final int SELECTED_TAB_TOP_EXPANSION = 2; // amount we expand the selected tab on top
- static final int SELECTED_TAB_HORIZONTAL_EXPANSION = 2; // amount we expand so it overlays to left and right
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see SWT#TOP
- * @see SWT#BOTTOM
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabFolder(Composite parent, int style) {
- super(parent, checkStyle (style));
- Listener listener = new Listener() {
- public void handleEvent(Event event) {handleEvents(event);}
- };
- addListener (SWT.Dispose, listener);
- addListener (SWT.MouseDown, listener);
- addListener (SWT.MouseUp, listener);
- addListener (SWT.MouseHover, listener);
- addListener (SWT.Paint, listener);
-// addListener (SWT.Resize, listener);
- addListener (SWT.Traverse, listener);
- addListener (SWT.KeyDown, listener);
- addListener (SWT.FocusIn, listener);
- addListener (SWT.FocusOut, listener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-static int checkStyle (int style) {
- style = checkBits (style, SWT.TOP, SWT.BOTTOM, 0, 0, 0, 0);
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- Point size = super.computeSize (wHint, hHint, changed);
- if (items.length > 0) {
- TabItem lastItem = items[items.length-1];
- int border = getBorderWidth ();
- int width = lastItem.x + lastItem.width + border * 2 + CLIENT_MARGIN_WIDTH * 2 + TabItem.SHADOW_WIDTH * 2;
- size.x = Math.max (width, size.x);
- }
- return size;
-}
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- int border = getBorderWidth ();
- int trimX = x - border - CLIENT_MARGIN_WIDTH - TabItem.SHADOW_WIDTH;
- int trimY = y - border - CLIENT_MARGIN_WIDTH - TabItem.SHADOW_WIDTH;
- int tabHeight = 0;
- if (items.length > 0) {
- TabItem item = items [0];
- tabHeight = item.y + item.height; // only use height of the first item because all items should be the same height
- }
- int trimWidth = width + border * 2 + CLIENT_MARGIN_WIDTH * 2 + TabItem.SHADOW_WIDTH * 2;
- int trimHeight = height + tabHeight + border * 2 + CLIENT_MARGIN_WIDTH * 2 + TabItem.SHADOW_WIDTH * 2;
- return new Rectangle (trimX, trimY - tabHeight, trimWidth, trimHeight);
-}
-/**
- * Create the specified item at 'index'.
- */
-void createChild (TabItem item, int index) {
- boolean isTabScrolling = isTabScrolling();
-
- if (!(0 <= index && index <= getItemCount ())) error (SWT.ERROR_INVALID_RANGE);
- item.parent = this;
-
- // grow by one and rearrange the array.
- TabItem[] newItems = new TabItem [items.length + 1];
- System.arraycopy(items, 0, newItems, 0, index);
- newItems[index] = item;
- System.arraycopy(items, index, newItems, index + 1, items.length - index);
- items = newItems;
- if (selectedIndex >= index) selectedIndex ++;
-
- layoutItems();
- redrawTabs();
- // redraw scroll buttons if they just became visible
- // fixes 1G5X1QL
- if (isTabScrolling() != isTabScrolling && isTabScrolling == false) {
- redrawScrollButtons();
- }
- if (getItemCount() == 1) {
- // select the first added item and send a selection event.
- // fixes 1GAP79N
- setSelection(0, true);
- }
-}
-/**
- * Destroy the specified item.
- */
-void destroyChild (TabItem item) {
- int index = indexOf(item);
- if (index == -1) return; // should trigger an error?
- if (items.length == 1) {
- items = new TabItem [0];
- selectedIndex = -1;
- topTabIndex = 0;
- if (!inDispose){
- Control control = item.control;
- if (control != null && !control.isDisposed()) {
- control.setVisible(false);
- }
- redraw();
- }
- } else {
- // shrink by one and rearrange the array.
- TabItem[] newItems = new TabItem [items.length - 1];
- System.arraycopy(items, 0, newItems, 0, index);
- System.arraycopy(items, index + 1, newItems, index, items.length - index - 1);
- items = newItems;
-
- // move the selection if this item is selected
- if (selectedIndex == index) {
- if (!inDispose) {
- Control control = item.control;
- if (control != null && !control.isDisposed()) {
- control.setVisible(false);
- }
- selectedIndex = -1;
- setSelection(Math.max(0, index - 1), true);
- }
- } else if (selectedIndex > index) {
- selectedIndex--;
- }
- if (topTabIndex == items.length) {
- --topTabIndex;
- }
- }
- // Make sure that the first tab is visible if scroll buttons are no longer drawn.
- // Fixes 1FXW5DV
- if (topTabIndex > 0 && !isTabScrolling()) {
- topTabIndex = 0;
- }
- if (!inDispose) {
- layoutItems();
- redrawTabs();
- }
-}
-/**
- * Dispose the items of the receiver
- */
-void doDispose(Event event) {
- if (inDispose) return;
- inDispose = true;
- notifyListeners(SWT.Dispose, event);
- event.type = SWT.None;
- // items array is resized during TabItem.dispose
- // it is length 0 if the last item is removed
- while (items.length > 0) {
- if (items[items.length-1] != null) {
- items[items.length-1].dispose();
- }
- }
-}
-/**
- * Draw an arrow like that used in Button with SWT.ARROW style.
- * @param gc - GC to draw on
- * @param xPos - x position the underlying button is drawn at
- * @param yPos - y position the underlying button is drawn at
- * @param size - size of the underlying button
- * @param left - true=arrow is facing left. false=arrow is facing right
- */
-void drawArrow(GC gc, int xPos, int yPos, int size, boolean left) {
- int arrowWidth = size / 4;
- int arrow[] = new int[6];
-
- if (!left) arrowWidth *= -1;
- // start polygon lines with vertical line which is always the same
- arrow[0] = xPos + (size + arrowWidth) / 2;
- arrow[1] = yPos + size / 4;
- arrow[2] = arrow[0];
- arrow[3] = arrow[1] + size / 2;
-
- arrow[4] = arrow[0] - arrowWidth;
- arrow[5] = yPos + size / 2;
-
- gc.setBackground(getForeground());
- gc.fillPolygon(arrow);
- gc.setBackground(getBackground());
-}
-/**
- * Draw a border around the receiver.
- */
-void drawBorder(Event event) {
- GC gc = event.gc;
- Rectangle clientArea = getClientArea();
- int wClient = clientArea.width;
- int hClient = clientArea.height;
- int x, y, x1, y1;
- final Color HighlightShadow = display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
- final Color LightShadow = display.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW);
-
- // Draw the left line
- gc.setForeground(HighlightShadow);
- gc.drawLine((x = xClient - CLIENT_MARGIN_WIDTH),
- yClient + hClient + CLIENT_MARGIN_WIDTH,
- x,
- (y = yClient - CLIENT_MARGIN_WIDTH) + 1);
- // Second, darker, line right of the previous line.
- // Necessary to workaround color constant differences on Windows/Motif
- gc.setForeground(LightShadow);
- gc.drawLine(x + 1, yClient + hClient + CLIENT_MARGIN_WIDTH, x + 1, y + 1);
- gc.setForeground(HighlightShadow);
-
- // Draw the upper line in two chunks so we don't overwrite the selected tab
- if (selectedIndex == -1) {
- gc.setForeground(LightShadow);
- gc.drawLine(x + 1, y + 1, xClient + wClient + CLIENT_MARGIN_WIDTH, y + 1);
- } else {
- TabItem item = items[selectedIndex];
- gc.setForeground(LightShadow);
- if (selectedIndex > 0) {
- gc.drawLine(x + 1, y + 1, item.x - 1 + CLIENT_MARGIN_WIDTH, y + 1);
- }
- gc.drawLine(item.x + item.width, y + 1, xClient + wClient + CLIENT_MARGIN_WIDTH, y + 1);
- }
-
- // Draw the right and bottom black lines
- gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
- gc.drawLine((x = xClient - CLIENT_MARGIN_WIDTH),
- (y = yClient + hClient + CLIENT_MARGIN_WIDTH),
- (x1 = xClient + wClient + CLIENT_MARGIN_WIDTH),
- y);
- gc.drawLine(x1, y, x1, (y1 = yClient - CLIENT_MARGIN_WIDTH + 1));
- x1--;
- x++;
- y--;
- y1++;
-
-
- // There is a dark gray line above the bottom back line
- gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
- gc.drawLine(x, y, x1, y);
- // On the right there is a dark gray line, left of the black one
- gc.drawLine(x1, y-1, x1, y1);
-
- // restore the foreground color.
- gc.setForeground(getForeground());
-}
-/**
- * Draw a plain push button
- * @param gc - GC to draw on
- * @param xPos - x position the button is drawn at
- * @param yPos - y position the button is drawn at
- * @param size - size of the button
- */
-void drawPlainButton(GC gc, int xPos, int yPos, int size) {
- Color rightBottomColor = getForeground();
- Color leftTopColor = display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
- Color rightBottomInnerColor = display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
- Color leftTopInnerColor = display.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW);
- int upper = yPos;
- int left = xPos;
- int lower = yPos + size - 1;
- int right = xPos + size - 1;
-
- if (scrollButtonDown) { // draw the button in the pressed down state?
- rightBottomColor = display.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW);
- leftTopColor = display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
- rightBottomInnerColor = display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
- leftTopInnerColor = getForeground();
- }
- gc.fillRectangle(left, upper, right - left, lower - upper);
- // draw right, bottom line in foreground color
- gc.setForeground(rightBottomColor);
- gc.drawLine(right, upper, right, lower);
- gc.drawLine(left, lower, right, lower);
-
- // draw left, top line in normal shadow (default light gray)
- gc.setForeground(leftTopColor);
- gc.drawLine(left, upper, left, lower - 1);
- gc.drawLine(left, upper, right - 1, upper);
-
- upper++;
- left++;
- lower--;
- right--;
- // draw right, bottom line in dark shadow (default dark gray)
- gc.setForeground(rightBottomInnerColor);
- gc.drawLine(right, upper, right, lower);
- gc.drawLine(left, lower, right, lower);
-
- // draw left, top line in high light shadow (default off white)
- gc.setForeground(leftTopInnerColor);
- gc.drawLine(left, upper, left, lower - 1);
- gc.drawLine(left, upper, right - 1, upper);
- gc.setForeground(getForeground());
-}
-/**
- * Draw the buttons used to scroll tab items
- */
-void drawScrollButtons(Event event) {
- Rectangle buttonArea = getScrollButtonArea();
- int buttonSize = buttonArea.width / 2;
-
- drawPlainButton(event.gc, buttonArea.x, buttonArea.y, buttonSize);
- drawPlainButton(event.gc, buttonArea.x + buttonSize, buttonArea.y, buttonSize);
- if (scrollButtonDown) {
- drawArrow(event.gc, buttonArea.x, buttonArea.y, buttonSize, true);
- drawArrow(event.gc, buttonArea.x + buttonSize + 1, buttonArea.y, buttonSize + 1, false);
- }
- else {
- drawArrow(event.gc, buttonArea.x - 1, buttonArea.y - 1, buttonSize, true);
- drawArrow(event.gc, buttonArea.x + buttonSize, buttonArea.y - 1, buttonSize, false);
- }
-}
-
-/**
- * Make sure that the first tab is visible if scroll buttons are no
- * longer drawn.
- */
-void ensureRightFreeSpaceUsed() {
- if (topTabIndex > 0 && !isTabScrolling()) {
- topTabIndex = 0;
- layoutItems();
- redrawTabs();
- }
-}
-
-/**
- * If the tab at 'tabIndex' is not visible or partially covered by the tab
- * scroll buttons and there is enough space to completely show the tab,
- * the tab is scrolled to the left to make it fully visible.
- */
-void ensureVisible(int tabIndex) {
- if (tabIndex < 0 || tabIndex >= items.length) return;
- if (!isTabScrolling()) return;
- if (tabIndex < topTabIndex) {
- topTabIndex = tabIndex;
- layoutItems();
- redrawTabs();
- return;
- }
- int rightEdge = getScrollButtonArea().x;
- TabItem tabItem = items[tabIndex];
- while (tabItem.x + tabItem.width > rightEdge && tabIndex != topTabIndex) {
- topTabIndex++;
- layoutItems();
- redrawTabs();
- }
-}
-void focus (Event e) {
- if (selectedIndex == -1) return;
- TabItem tab = items[selectedIndex];
- redraw(tab.x, tab.y, tab.width, tab.height);
-}
-
-public Rectangle getClientArea() {
- checkWidget();
- Rectangle clientArea = super.getClientArea();
-
- if (yClient == 0) { // position not calculated yet
- layoutItems(); // calculate tab folder bounds as soon as there is tab data to use.
- }
- clientArea.x = xClient;
- clientArea.y = yClient;
- clientArea.width = Math.max (0, clientArea.width - (xClient + CLIENT_MARGIN_WIDTH + 1));
- clientArea.height = Math.max (0, clientArea.height - (yClient + CLIENT_MARGIN_WIDTH + 1));
- return clientArea;
-}
-/**
- * Return the height of item images. All images are scaled to
- * the height of the first image.
- */
-int getImageHeight() {
- return imageHeight;
-}
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem getItem (int index) {
- checkWidget();
- if (!(0 <= index && index < getItemCount())) error(SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-/**
- * Returns the tab item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- *
- * @param point the point used to locate the item
- * @return the tab item at the given point, or null if the point is not in a tab item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public TabItem getItem (Point point) {
- checkWidget();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = items.length;
- for (int index = 0; index < count; index++) {
- TabItem item = items[index];
- Rectangle bounds = item.getBounds();
- if (bounds.contains(point)) return item;
- }
- return null;
-}
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount(){
- checkWidget();
- return items.length;
-}
-/**
- * Returns an array of <code>TabItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem [] getItems() {
- checkWidget();
- TabItem[] tabItems = new TabItem [items.length];
- System.arraycopy(items, 0, tabItems, 0, items.length);
- return tabItems;
-}
-char getMnemonic (String string) {
- int index = 0;
- int length = string.length ();
- do {
- while ((index < length) && (string.charAt (index) != '&')) index++;
- if (++index >= length) return '\0';
- if (string.charAt (index) != '&') return string.charAt (index);
- index++;
- } while (index < length);
- return '\0';
-}
-/**
- * Returns the area where the two scroll buttons are drawn.
- */
-Rectangle getScrollButtonArea() {
- return new Rectangle(
- super.getClientArea().width - SCROLL_BUTTON_SIZE * 2, SELECTED_TAB_TOP_EXPANSION,
- SCROLL_BUTTON_SIZE * 2, SCROLL_BUTTON_SIZE);
-}
-/**
- * Returns an array of <code>TabItem</code>s that are currently
- * selected in the receiver. An empty array indicates that no
- * items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem [] getSelection() {
- checkWidget();
- if (selectedIndex == -1) return new TabItem [0];
- return new TabItem [] {items[selectedIndex]};
-}
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex() {
- checkWidget();
- return selectedIndex;
-}
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-/**
- * Handle the events that I have hooked on the canvas.
- */
-void handleEvents (Event event){
- switch (event.type) {
- case SWT.Dispose:
- doDispose(event);
- break;
- case SWT.Paint:
- paint(event);
- break;
-// case SWT.Resize:
-// resize();
-// break;
- case SWT.MouseDown:
- mouseDown(event);
- break;
- case SWT.MouseUp:
- mouseUp(event);
- break;
- case SWT.MouseHover:
- mouseHover(event);
- break;
- case SWT.Traverse:
- traversal(event);
- break;
- case SWT.FocusIn:
- case SWT.FocusOut:
- focus(event);
- break;
- case SWT.KeyDown:
- // this callback is always needed so that widget is included in tab order
- keyDown(event);
- break;
- default:
- break;
- }
-}
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf(TabItem item) {
- checkWidget();
- if (item == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- for (int i = 0; i < items.length; i++) {
- if (items[i] == item) return i;
- }
- return -1;
-}
-/**
- * Answer true when the left scroll button was clicked with mouse button 1.
- */
-boolean isLeftButtonHit(Event event) {
- Rectangle buttonArea = getScrollButtonArea();
-
- buttonArea.width /= 2;
- return isTabScrolling() && event.button == 1 && buttonArea.contains(event.x, event.y);
-}
-/**
- * Answer true when the right scroll button was clicked with mouse button 1.
- */
-boolean isRightButtonHit(Event event) {
- Rectangle buttonArea = getScrollButtonArea();
- int buttonSize = buttonArea.width / 2;
-
- buttonArea.x += buttonSize;
- buttonArea.width = buttonSize;
- return isTabScrolling() && event.button == 1 && buttonArea.contains(event.x, event.y);
-}
-/**
- * Answer true if not all tabs can be visible in the receive
- * thus requiring the scroll buttons to be visible.
- */
-boolean isTabScrolling() {
- boolean isVisible = false;
-
- if (items.length > 0) {
- TabItem tabItem = items[items.length-1];
- int tabStopX = tabItem.x + tabItem.width;
- tabItem = items[0];
- if (tabStopX - tabItem.x > super.getClientArea().width) {
- isVisible = true; // not all tabs fit in the client area
- }
- }
- return isVisible;
-}
-/**
- * 'item' has changed. Store the image size if this is the
- * first item with an image.
- */
-void itemChanged(TabItem item) {
- Image itemImage = item.getImage();
- boolean isTabScrolling = isTabScrolling();
-
- if (imageHeight == -1 && itemImage != null) {
- imageHeight = itemImage.getBounds().height;
- }
- layoutItems();
- redrawTabs();
- // redraw scroll buttons if they just became visible
- // fixes 1G5X1QL
- if (isTabScrolling() != isTabScrolling && isTabScrolling == false) {
- redrawScrollButtons();
- }
-}
-/**
- * A key was pressed. If one of the tab-selection keys that is not a traversal
- * was pressed then change tabs accordingly.
- */
-void keyDown(Event event) {
- int count = items.length;
- if (count <= 1) return;
- switch (event.keyCode) {
- case SWT.ARROW_RIGHT:
- if (selectedIndex < items.length - 1) {
- setSelection(selectedIndex + 1, true);
- }
- break;
- case SWT.ARROW_LEFT:
- if (selectedIndex > 0) {
- setSelection(selectedIndex - 1, true);
- }
- break;
- case SWT.HOME:
- if (selectedIndex > 0) {
- setSelection(0, true);
- }
- break;
- case SWT.END:
- if (selectedIndex < count - 1) {
- setSelection(count - 1, true);
- }
- break;
- }
-}
-/**
- * Layout the items and store the client area size.
- */
-void layoutItems() {
- int x = SELECTED_TAB_HORIZONTAL_EXPANSION;
- int y = SELECTED_TAB_TOP_EXPANSION;
- int tabHeight = 0;
-
- GC gc = new GC(this);
- for (int i=topTabIndex - 1; i>=0; i--) { // if the first visible tab is not the first tab
- TabItem tab = items[i];
- tab.width = tab.preferredWidth(gc);
- tab.height = tab.preferredHeight(gc);
- x -= tab.width; // layout tab items from right to left thus making them invisible
- tab.x = x;
- tab.y = y;
- if (tab.height > tabHeight) tabHeight = tab.height;
- }
- x = SELECTED_TAB_HORIZONTAL_EXPANSION;
- for (int i=topTabIndex; i<items.length; i++) { // continue laying out remaining, visible items left to right
- TabItem tab = items[i];
- tab.x = x;
- tab.y = y;
- tab.width = tab.preferredWidth(gc);
- tab.height = tab.preferredHeight(gc);
- x = x + tab.width;
- if (tab.height > tabHeight) tabHeight = tab.height;
- }
- gc.dispose();
- xClient = CLIENT_MARGIN_WIDTH;
- yClient = CLIENT_MARGIN_WIDTH + tabHeight;
- TabItem selection[] = getSelection();
- if (selection.length > 0)
- selection[0].expand(SELECTED_TAB_HORIZONTAL_EXPANSION, SELECTED_TAB_TOP_EXPANSION, SELECTED_TAB_HORIZONTAL_EXPANSION, 0);
-}
-Point minimumSize (int wHint, int hHint, boolean flushCache) {
- Control [] children = _getChildren ();
- int width = 0, height = 0;
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- int index = 0;
- while (index < items.length) {
- if (items [index].control == child) break;
- index++;
- }
- if (index == items.length) {
- Rectangle rect = child.getBounds ();
- width = Math.max (width, rect.x + rect.width);
- height = Math.max (height, rect.y + rect.height);
- } else {
- Point size = child.computeSize (wHint, hHint, flushCache);
- width = Math.max (width, size.x);
- height = Math.max (height, size.y);
- }
- }
- return new Point (width, height);
-}
-boolean mnemonicHit (char key) {
- for (int i = 0; i < items.length; i++) {
- char mnemonic = getMnemonic (items[i].getText ());
- if (mnemonic != '\0') {
- if (Character.toUpperCase (key) == Character.toUpperCase (mnemonic)) {
- if (forceFocus ()) {
- if (i != selectedIndex) setSelection(i, true);
- return true;
- }
- }
- }
- }
- return false;
-}
-/**
- * A mouse button was pressed down.
- * If one of the tab scroll buttons was hit, scroll in the appropriate
- * direction.
- * If a tab was hit select the tab.
- */
-void mouseDown(Event event) {
- if (isLeftButtonHit(event)) {
- scrollButtonDown = true;
- redrawHitButton(event);
- scrollLeft();
- }
- else
- if (isRightButtonHit(event)) {
- scrollButtonDown = true;
- redrawHitButton(event);
- scrollRight();
- }
- else {
- for (int i=0; i<items.length; i++) {
- if (items[i].getBounds().contains(new Point(event.x, event.y))) {
- forceFocus();
- setSelection(i, true);
- return;
- }
- }
- }
-}
-void mouseHover(Event event) {
- String current = super.getToolTipText();
- if (toolTipText == null) {
- Point point = new Point(event.x, event.y);
- for (int i=0; i<items.length; i++) {
- if (items[i].getBounds().contains(point)) {
- String string = items[i].getToolTipText();
- if (string != null && !string.equals(current)) {
- super.setToolTipText(string);
- }
- return;
- }
- }
- if (current != null) super.setToolTipText(null);
- return;
- }
- if (!toolTipText.equals(current)) {
- super.setToolTipText(toolTipText);
- }
-}
-/**
- * A mouse button was released.
- */
-void mouseUp(Event event) {
- if (scrollButtonDown && event.button == 1) {
- scrollButtonDown = false;
- redrawHitButton(event);
- }
-}
-/**
- * Paint the receiver.
- */
-void paint(Event event) {
- // Draw the unselected tabs first.
- for (int i=0; i<getItemCount(); i++) {
- if (i != selectedIndex && event.getBounds().intersects(items[i].getBounds())) {
- items[i].paint(event.gc, false);
- }
- }
- drawBorder(event);
- // Selected tab comes last since selected tabs overlay adjacent tabs
- // and the border
- if (selectedIndex != -1) {
- items[selectedIndex].paint(event.gc, true);
- }
- if (isTabScrolling()) drawScrollButtons(event);
-}
-/**
- * Redraw the area of the receiver specified by x, y, width, height.
- * Don't redraw the scroll buttons to avoid flashing.
- */
-void redraw (int x, int y, int width, int height) {
- Rectangle buttonArea = getScrollButtonArea();
- boolean fixScrollButtons = false;
-
- if (isTabScrolling()) {
- if (x > buttonArea.x) {
- x = buttonArea.x;
- fixScrollButtons = true;
- }
- if (x + width > buttonArea.x) {
- width = buttonArea.x - x;
- fixScrollButtons = true;
- }
- }
- redraw(x, y, width, height, false);
- if (fixScrollButtons) {
- redraw(buttonArea.x, 0, buttonArea.width, buttonArea.y, false); // redraw space above scroll buttons
- if (buttonArea.height < getClientArea().y) {
- int redrawY = buttonArea.y + buttonArea.height;
- redraw(
- buttonArea.x, redrawY,
- buttonArea.width, getClientArea().y - redrawY, false); // redraw space below scroll buttons
- }
- }
-}
-/**
- * Redraw the scroll button that was pressed down
- */
-void redrawHitButton(Event event) {
- Rectangle scrollButtonArea = getScrollButtonArea();
- int scrollButtonWidth = scrollButtonArea.width / 2;
-
- if (isLeftButtonHit(event)) {
- redraw(
- scrollButtonArea.x, scrollButtonArea.y,
- scrollButtonWidth, scrollButtonArea.height, false);
- }
- else
- if (isRightButtonHit(event)) {
- redraw(
- scrollButtonArea.x + scrollButtonWidth, scrollButtonArea.y,
- scrollButtonWidth, scrollButtonArea.height, false);
- }
-}
-/**
- * Redraw both scroll buttons
- */
-void redrawScrollButtons() {
- Rectangle scrollButtonArea = getScrollButtonArea();
-
- redraw(
- scrollButtonArea.x, scrollButtonArea.y,
- scrollButtonArea.width, scrollButtonArea.height, false);
-}
-/**
- * Redraw the tabs at the specified indexes.
- */
-void redrawSelectionChange(int oldSelection, int newSelection) {
- if (oldSelection != -1) {
- TabItem tab = items[oldSelection];
- // since the tab used to be selected, we need to clear its old expanded size
- redraw(tab.x - SELECTED_TAB_HORIZONTAL_EXPANSION,
- tab.y - SELECTED_TAB_TOP_EXPANSION,
- tab.width + 2 * SELECTED_TAB_HORIZONTAL_EXPANSION,
- tab.height + SELECTED_TAB_TOP_EXPANSION);
- }
- if (newSelection != -1) {
- TabItem tab = items[newSelection];
- // this tab is already at the expanded size
- redraw(tab.x, tab.y, tab.width, tab.height);
- }
- // make sure the tab is repainted before the new page is made visible.
- // The latter could take a long time and delay the screen update.
- update();
-}
-/**
- * Redraw the whole tab area
- */
-void redrawTabs() {
- redraw(0, 0, super.getClientArea().width, getClientArea().y);
-}
-void removeControl (Control control) {
- super.removeControl (control);
- for (int i=0; i<items.length; i++) {
- TabItem item = items [i];
- if (item.control == control) item.setControl (null);
- }
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- removeListener(SWT.Selection, listener);
- removeListener(SWT.DefaultSelection, listener);
-}
-/**
- * The widget was resized. Adjust the size of the currently selected page.
- */
-void resize() {
- if (selectedIndex != -1) {
- Control control = items[selectedIndex].getControl();
- if (control != null && !control.isDisposed()) {
- control.setBounds(getClientArea());
- }
- }
- ensureRightFreeSpaceUsed();
-}
-
-/**
- * Scroll the tab items to the left.
- */
-void scrollLeft() {
- if (topTabIndex > 0) {
- --topTabIndex;
- layoutItems();
- redrawTabs();
- }
-}
-/**
- * Scroll the tab items to the right.
- */
-void scrollRight() {
- if (items.length > 0 && topTabIndex < items.length - 1) {
- TabItem lastTabItem = items[items.length-1];
- int tabStopX = lastTabItem.x + lastTabItem.width;
- if (tabStopX > super.getClientArea().width - SCROLL_BUTTON_SIZE * 2) {
- topTabIndex++;
- layoutItems();
- redrawTabs();
- }
- }
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- boolean changed = super.setBounds (x, y, width, height, move, resize);
- if (changed && resize) resize ();
- return changed;
-}
-public void setFont(Font font) {
- checkWidget();
- if (font != null && font.equals(getFont())) return;
- super.setFont(font);
- layoutItems();
- redrawTabs();
-}
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains selected.
- * The current selection is first cleared, then the new items are
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection(int index) {
- checkWidget();
- if (!(0 <= index && index < items.length)) return;
- setSelection(index, false);
-}
-/**
- * Sets the receiver's selection to the given item.
- * The current selected is first cleared, then the new item is
- * selected.
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection(TabItem item) {
- checkWidget();
- if (item == null) error(SWT.ERROR_NULL_ARGUMENT);
- setSelection(new TabItem[]{item});
-}
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selected is first cleared, then the new items are
- * selected.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection(TabItem selectedItems[]) {
- checkWidget();
- if (selectedItems == null) error(SWT.ERROR_NULL_ARGUMENT);
- int index = -1;
- if (selectedItems.length > 0) {
- index = indexOf(selectedItems[0]);
- }
- setSelection(index, false);
-}
-/**
- * Set the selection to the tab at the specified index.
- */
-void setSelection(int index, boolean notify) {
- if (selectedIndex == index) return;
- int oldIndex = selectedIndex;
-
- if (selectedIndex == index || index >= getItemCount()) return;
- if (selectedIndex != -1) {
- Control control = items[selectedIndex].control;
- if (control != null && !control.isDisposed()) {
- control.setVisible(false);
- }
- }
- if (index < 0) {
- index = -1; // make sure the index is always -1 if it's negative
- }
- selectedIndex = index;
- layoutItems();
- ensureVisible(index);
- redrawSelectionChange(oldIndex, index);
- if (index >= 0) {
- Control control = items[index].control;
- if (control != null && !control.isDisposed()) {
- control.setBounds(getClientArea());
- control.setVisible(true);
- }
- }
-
- if (notify) {
- if (selectedIndex != oldIndex && selectedIndex != -1) {
- Event event = new Event();
- event.item = getSelection()[0];
- notifyListeners(SWT.Selection, event);
- }
- }
-}
-public void setToolTipText (String string) {
- checkWidget();
- super.setToolTipText (string);
- toolTipText = string;
-}
-void traversal(Event event) {
- switch (event.detail) {
- case SWT.TRAVERSE_ESCAPE:
- case SWT.TRAVERSE_RETURN:
- case SWT.TRAVERSE_TAB_NEXT:
- case SWT.TRAVERSE_TAB_PREVIOUS:
- case SWT.TRAVERSE_MNEMONIC:
- case SWT.TRAVERSE_PAGE_NEXT:
- case SWT.TRAVERSE_PAGE_PREVIOUS:
- event.doit = true;
- }
-}
-boolean traverseItem (boolean next) {
- return false;
-}
-boolean traversePage (boolean next) {
- int count = items.length;
- if (count == 0) return false;
- int index = selectedIndex;
- if (index == -1) {
- index = 0;
- } else {
- int offset = next ? 1 : -1;
- index = (index + offset + count) % count;
- }
- setSelection (index, true);
- return true;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/tabfolder/org/eclipse/swt/widgets/TabItem.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/tabfolder/org/eclipse/swt/widgets/TabItem.java
deleted file mode 100644
index 09eeac1362..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/tabfolder/org/eclipse/swt/widgets/TabItem.java
+++ /dev/null
@@ -1,452 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * corresponding to a tab for a page in a tab folder.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tabfolder">TabFolder, TabItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TabItem extends Item {
- TabFolder parent;
- int x,y,width,height = 0;
- String toolTipText;
- Control control; // the tab page
-
- // internal constants
- static final int LEFT_HORIZONTAL_MARGIN = 8;
- static final int RIGHT_HORIZONTAL_MARGIN = 2;
- static final int VERTICAL_MARGIN = 1; // space between tab shadow and tab content
- static final int ICON_MARGIN = 6;
- static final int SHADOW_WIDTH = 2; // width of the tab shadow
- static final int DEFAULT_TEXT_WIDTH = 36; // preferred text width if there is no text.
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>TabFolder</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabItem (TabFolder parent, int style) {
- super (parent, style);
- parent.createChild (this, parent.getItemCount());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>TabFolder</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabItem (TabFolder parent, int style, int index) {
- super (parent, style);
- parent.createChild (this, index);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public void dispose() {
- if (isDisposed()) return;
- super.dispose();
- parent.destroyChild(this);
- parent = null;
- control = null;
- toolTipText = null;
-}
-/**
- * Expand the receiver's bounds by the specified number of pixels on
- * the left,top,right,and bottom.
- */
-void expand(int left, int top, int right, int bottom) {
- if (hasLocation()) {
- x = x - left;
- y = y - top;
- width = width + left + right;
- height = height + top + bottom;
- }
-}
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public Rectangle getBounds () {
- checkWidget();
- return new Rectangle(x, y, width, height);
-}
-/**
- * Returns the control that is used to fill the client area of
- * the tab folder when the user selects the tab item. If no
- * control has been set, return <code>null</code>.
- * <p>
- * @return the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget();
- return control;
-}
-/**
- * Returns the receiver's parent, which must be a <code>TabFolder</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabFolder getParent () {
- checkWidget();
- return parent;
-}
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-/**
- * Answer true if the receiver has been laid out.
- */
-boolean hasLocation() {
- return !(width == 0 && height == 0 && x == 0 && y == 0);
-}
-/**
- * Answer the image height.
- */
-private int imageHeight() {
- Image image = getImage();
-
- if (parent.getImageHeight() != -1) {
- return parent.getImageHeight();
- } else if (image != null && !image.isDisposed()) {
- return image.getBounds().height;
- }
- else {
- return 0;
- }
-}
-/**
- * Answer the icon width.
- */
-private int imageWidth() {
- Image image = getImage();
-
- if (image != null && !image.isDisposed()) {
- return image.getBounds().width;
- } else {
- return 0;
- }
-}
-/**
- * Paint the receiver.
- */
-void paint(GC gc, boolean isSelected) {
- // high light colored line across left and top
- gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
- gc.drawLine(x, y + height - 2, x, y + 2);
- gc.drawLine(x, y + 2, x + 2, y);
- gc.drawLine(x + 2, y, x + width - 3, y);
-
- // light color next to the left and below the top line.
- // Since tabs expand horizontally when selected, we actually draw
- // the background color to erase any debris from a selected tab.
- gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
- gc.drawLine(x + 1, y + height - 2, x + 1, y + 2);
- gc.drawLine(x + 2, y + 1, x + width - 3, y + 1);
-
- // dark colored line at right
- gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
- gc.drawLine(x + width - 1, y + 2, x + width - 1, y + height - 1);
- // dark pixel on top of shadowed line, inside dark line
- gc.drawLine(x + width - 2, y + 1, x + width - 2, y + 1);
-
- // shadowed line on right inside the dark line
- gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
- gc.drawLine(x + width - 2, y + 2, x + width - 2, y + height - 1);
-
- if (parent.isFocusControl() && isSelected) {
- // draw a focus rectangle
- gc.drawFocus(x + 3, y + 3, width - 6, height - 3);
- }
-
- // icon and bitmap. Should probably be checking style bits to determine
- // exactly what to paint. Do we just draw the icon when the icon/text combination
- // is too wide to fit all tabs?
- gc.setForeground(parent.getForeground());
- int xDraw = x + LEFT_HORIZONTAL_MARGIN;
- int yCenter;
- int decorationHeight = SHADOW_WIDTH * 2 + VERTICAL_MARGIN * 2;
- Image image = getImage();
- Rectangle sourceBounds = null;
- if (image != null) {
- sourceBounds = image.getBounds();
- yCenter = y + SHADOW_WIDTH + VERTICAL_MARGIN + (height - decorationHeight - imageHeight()) / 2;
- gc.drawImage(
- image,
- sourceBounds.x, sourceBounds.y, sourceBounds.width, sourceBounds.height,
- xDraw, yCenter, sourceBounds.width, parent.getImageHeight());
- }
- xDraw = xDraw + ICON_MARGIN;
- if (sourceBounds != null) {
- xDraw += sourceBounds.width;
- }
- yCenter = y + SHADOW_WIDTH + VERTICAL_MARGIN + (height - decorationHeight - textHeight(gc)) / 2;
- int flags = SWT.DRAW_MNEMONIC | SWT.DRAW_TRANSPARENT;
- gc.drawText(getText(), xDraw, yCenter, flags);
-}
-/**
- * Answer the preferred height of the receiver for the GC.
- */
-int preferredHeight(GC gc) {
- int height = textHeight(gc);
- if (imageHeight() > height) height = imageHeight();
- height += VERTICAL_MARGIN * 2 + SHADOW_WIDTH * 2;
- return height;
-}
-/**
- * Answer the preferred width of the receiver for the GC.
- */
-int preferredWidth(GC gc) {
- return imageWidth() + textWidth(gc) + LEFT_HORIZONTAL_MARGIN +
- RIGHT_HORIZONTAL_MARGIN + ICON_MARGIN + SHADOW_WIDTH * 2;
-}
-/**
- * Sets the control that is used to fill the client area of
- * the tab folder when the user selects the tab item.
- * <p>
- * @param control the new control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- if (this.control != null && this.control.isDisposed ()) {
- this.control = null;
- }
- Control oldControl = this.control, newControl = control;
- this.control = control;
- int index = parent.indexOf (this), selectionIndex = parent.getSelectionIndex();
- if (index != selectionIndex) {
- if (newControl != null) {
- if (selectionIndex != -1) {
- Control selectedControl = parent.getItem(selectionIndex).getControl();
- if (selectedControl == newControl) return;
- }
- newControl.setVisible(false);
- return;
- }
- }
- if (newControl != null) {
- newControl.setBounds (parent.getClientArea ());
- newControl.setVisible (true);
- }
- if (oldControl != null) oldControl.setVisible (false);
-}
-public void setImage (Image image) {
- checkWidget();
- Image oldImage = this.image;
-
- super.setImage(image);
- if (image == null || !image.equals(oldImage)) {
- parent.itemChanged(this);
- }
-}
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void setText (String string) {
- checkWidget();
- String oldText = text;
-
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText(string);
- if (!string.equals(oldText)) {
- parent.itemChanged(this);
- }
-}
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
-}
-/**
- * Answer the text height.
- */
-private int textHeight(GC gc) {
- String text = getText();
-
- if (text == null) {
- return 0;
- } else {
- int flags = SWT.DRAW_MNEMONIC;
- return gc.textExtent(text, flags).y;
- }
-}
-/**
- * Answer the text width.
- */
-private int textWidth(GC gc) {
- String text = getText();
- int textWidth = 0;
-
- if (text != null) {
- int flags = SWT.DRAW_MNEMONIC;
- textWidth = gc.textExtent(text, flags).x;
- }
- if (textWidth == 0) {
- textWidth = DEFAULT_TEXT_WIDTH;
- }
- return textWidth;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/textlayout/org/eclipse/swt/graphics/TextLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/textlayout/org/eclipse/swt/graphics/TextLayout.java
deleted file mode 100644
index 6c00d2310b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/textlayout/org/eclipse/swt/graphics/TextLayout.java
+++ /dev/null
@@ -1,1759 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.*;
-
-/**
- * <code>TextLayout</code> is a graphic object that represents
- * styled text.
- * <p>
- * Instances of this class provide support for drawing, cursor
- * navigation, hit testing, text wrapping, alignment, tab expansion
- * line breaking, etc. These are aspects required for rendering internationalized text.
- * </p><p>
- * Application code must explicitly invoke the <code>TextLayout#dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#textlayout">TextLayout, TextStyle snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: CustomControlExample, StyledText tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.0
- */
-public final class TextLayout extends Resource {
- Device device;
- Font font;
- String text;
- int lineSpacing;
- int ascent, descent;
- int alignment;
- int wrapWidth;
- int orientation;
- int indent;
- boolean justify;
- int[] tabs;
- int[] segments;
- StyleItem[] styles;
-
- StyleItem[][] runs;
- int[] lineOffset, lineY, lineWidth;
-
- static class StyleItem {
- TextStyle style;
- int start, length, width, ascent, descent;
- boolean lineBreak, softBreak, tab;
- public String toString () {
- return "StyleItem {" + start + ", " + style + "}";
- }
- }
-
-/**
- * Constructs a new instance of this class on the given device.
- * <p>
- * You must dispose the text layout when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the text layout
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- *
- * @see #dispose()
- */
-public TextLayout (Device device) {
- super(device);
- wrapWidth = ascent = descent = -1;
- lineSpacing = 0;
- orientation = SWT.LEFT_TO_RIGHT;
- styles = new StyleItem[2];
- styles[0] = new StyleItem();
- styles[1] = new StyleItem();
- text = ""; //$NON-NLS-1$
- init();
-}
-
-void checkLayout () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-void computeRuns (GC gc) {
- if (runs != null) return;
- boolean newGC = gc == null;
- if (newGC) gc = new GC (device);
- StyleItem[] allRuns = itemize();
- for (int i=0; i<allRuns.length-1; i++) {
- StyleItem run = allRuns[i];
- gc.setFont(getItemFont(run));
- place(gc, run);
- }
- int lineWidth = 0, lineStart = 0, lineCount = 1;
- for (int i=0; i<allRuns.length - 1; i++) {
- StyleItem run = allRuns[i];
- if (run.length == 1) {
- char ch = text.charAt(run.start);
- switch (ch) {
- case '\t': {
- run.tab = true;
- if (tabs == null) break;
- int tabsLength = tabs.length, j;
- for (j = 0; j < tabsLength; j++) {
- if (tabs[j] > lineWidth) {
- run.width = tabs[j] - lineWidth;
- break;
- }
- }
- if (j == tabsLength) {
- int tabX = tabs[tabsLength-1];
- int lastTabWidth = tabsLength > 1 ? tabs[tabsLength-1] - tabs[tabsLength-2] : tabs[0];
- if (lastTabWidth > 0) {
- while (tabX <= lineWidth) tabX += lastTabWidth;
- run.width = tabX - lineWidth;
- }
- }
- break;
- }
- case '\n':
- run.lineBreak = true;
- run.width = 0;
- break;
- case '\r':
- run.lineBreak = true;
- run.width = 0;
- StyleItem next = allRuns[i + 1];
- if (next.length != 0 && text.charAt(next.start) == '\n') {
- run.length += 1;
- i++;
- }
- break;
- }
- }
- if (wrapWidth != -1 && lineWidth + run.width > wrapWidth && !run.tab) {
- int start = 0;
- gc.setFont(getItemFont(run));
- char[] chars = new char[run.length];
- text.getChars(run.start, run.start + run.length, chars, 0);
- if (!(run.style != null && run.style.metrics != null)) {
- int width = 0, maxWidth = wrapWidth - lineWidth;
- int charWidth = gc.stringExtent(String.valueOf(chars[start])).x;
- while (width + charWidth < maxWidth) {
- width += charWidth;
- start++;
- charWidth = gc.stringExtent(String.valueOf(chars[start])).x;
- }
- }
- int firstStart = start;
- int firstIndice = i;
- while (i >= lineStart) {
- chars = new char[run.length];
- text.getChars(run.start, run.start + run.length, chars, 0);
- while(start >= 0) {
- if (Compatibility.isSpaceChar(chars[start]) || Compatibility.isWhitespace(chars[start])) break;
- start--;
- }
- if (start >= 0 || i == lineStart) break;
- run = allRuns[--i];
- start = run.length - 1;
- }
- if (start == 0 && i != lineStart) {
- run = allRuns[--i];
- } else if (start <= 0 && i == lineStart) {
- i = firstIndice;
- run = allRuns[i];
- start = Math.max(1, firstStart);
- }
- chars = new char[run.length];
- text.getChars(run.start, run.start + run.length, chars, 0);
- while (start < run.length) {
- if (!Compatibility.isWhitespace(chars[start])) break;
- start++;
- }
- if (0 < start && start < run.length) {
- StyleItem newRun = new StyleItem();
- newRun.start = run.start + start;
- newRun.length = run.length - start;
- newRun.style = run.style;
- run.length = start;
- gc.setFont(getItemFont(run));
- place (gc, run);
- place (gc, newRun);
- StyleItem[] newAllRuns = new StyleItem[allRuns.length + 1];
- System.arraycopy(allRuns, 0, newAllRuns, 0, i + 1);
- System.arraycopy(allRuns, i + 1, newAllRuns, i + 2, allRuns.length - i - 1);
- allRuns = newAllRuns;
- allRuns[i + 1] = newRun;
- }
- if (i != allRuns.length - 2) {
- run.softBreak = run.lineBreak = true;
- }
- }
- lineWidth += run.width;
- if (run.lineBreak) {
- lineStart = i + 1;
- lineWidth = 0;
- lineCount++;
- }
- }
- lineWidth = 0;
- runs = new StyleItem[lineCount][];
- lineOffset = new int[lineCount + 1];
- lineY = new int[lineCount + 1];
- this.lineWidth = new int[lineCount];
- int lineRunCount = 0, line = 0;
- int ascent = Math.max(0, this.ascent);
- int descent = Math.max(0, this.descent);
- StyleItem[] lineRuns = new StyleItem[allRuns.length];
- for (int i=0; i<allRuns.length; i++) {
- StyleItem run = allRuns[i];
- lineRuns[lineRunCount++] = run;
- lineWidth += run.width;
- ascent = Math.max(ascent, run.ascent);
- descent = Math.max(descent, run.descent);
- if (run.lineBreak || i == allRuns.length - 1) {
- /* Update the run metrics if the last run is a hard break */
- if (lineRunCount == 1 && i == allRuns.length - 1) {
- gc.setFont(getItemFont(run));
- FontMetrics metrics = gc.getFontMetrics();
- run.ascent = metrics.getAscent() + metrics.getLeading();
- run.descent = metrics.getDescent();
- ascent = Math.max(ascent, run.ascent);
- descent = Math.max(descent, run.descent);
- }
- runs[line] = new StyleItem[lineRunCount];
- System.arraycopy(lineRuns, 0, runs[line], 0, lineRunCount);
- StyleItem lastRun = runs[line][lineRunCount - 1];
- this.lineWidth[line] = lineWidth;
- line++;
- lineY[line] = lineY[line - 1] + ascent + descent + lineSpacing;
- lineOffset[line] = lastRun.start + lastRun.length;
- lineRunCount = lineWidth = 0;
- ascent = Math.max(0, this.ascent);
- descent = Math.max(0, this.descent);
- }
- }
- if (newGC) gc.dispose();
-}
-
-void destroy() {
- freeRuns();
- font = null;
- text = null;
- tabs = null;
- styles = null;
- lineOffset = null;
- lineY = null;
- lineWidth = null;
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- *
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- */
-public void draw (GC gc, int x, int y) {
- draw(gc, x, y, -1, -1, null, null);
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- *
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param selectionStart the offset where the selections starts, or -1 indicating no selection
- * @param selectionEnd the offset where the selections ends, or -1 indicating no selection
- * @param selectionForeground selection foreground, or NULL to use the system default color
- * @param selectionBackground selection background, or NULL to use the system default color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- */
-public void draw (GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground) {
- draw(gc, x, y, selectionStart, selectionEnd, selectionForeground, selectionBackground, 0);
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- * <p>
- * The parameter <code>flags</code> can include one of <code>SWT.DELIMITER_SELECTION</code>
- * or <code>SWT.FULL_SELECTION</code> to specify the selection behavior on all lines except
- * for the last line, and can also include <code>SWT.LAST_LINE_SELECTION</code> to extend
- * the specified selection behavior to the last line.
- * </p>
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param selectionStart the offset where the selections starts, or -1 indicating no selection
- * @param selectionEnd the offset where the selections ends, or -1 indicating no selection
- * @param selectionForeground selection foreground, or NULL to use the system default color
- * @param selectionBackground selection background, or NULL to use the system default color
- * @param flags drawing options
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- *
- * @since 3.3
- */
-public void draw (GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags) {
- checkLayout();
- if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (selectionForeground != null && selectionForeground.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (selectionBackground != null && selectionBackground.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int length = text.length();
- if (length == 0) return;
- computeRuns(gc);
- boolean hasSelection = selectionStart <= selectionEnd && selectionStart != -1 && selectionEnd != -1;
- if (hasSelection) {
- selectionStart = Math.min(Math.max(0, selectionStart), length - 1);
- selectionEnd = Math.min(Math.max(0, selectionEnd), length - 1);
- if (selectionForeground == null) selectionForeground = device.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
- if (selectionBackground == null) selectionBackground = device.getSystemColor(SWT.COLOR_LIST_SELECTION);
- }
- final Color foreground = gc.getForeground();
- final Color background = gc.getBackground();
- final Font gcFont = gc.getFont();
- Rectangle clip = gc.getClipping();
- for (int line=0; line<runs.length; line++) {
- int drawX = x + getLineIndent(line);
- int drawY = y + lineY[line];
- StyleItem[] lineRuns = runs[line];
- if (drawX > clip.x + clip.width) continue;
- if (drawX + lineWidth[line] < clip.x) continue;
- int baseline = Math.max(0, this.ascent);
- for (int i = 0; i < lineRuns.length; i++) {
- baseline = Math.max(baseline, lineRuns[i].ascent);
- }
- int lineHeight = lineY[line+1] - lineY[line];
- Font lastFont = null, currentFont = null;
- int drawRunY = 0;
- for (int i = 0; i < lineRuns.length; i++) {
- StyleItem run = lineRuns[i];
- if (run.length == 0) continue;
- if (drawX > clip.x + clip.width) break;
- if (drawX + run.width >= clip.x) {
- if (!run.lineBreak || run.softBreak) {
- currentFont = getItemFont(run);
- if (!currentFont.equals(lastFont)) {
- gc.setFont(currentFont);
- lastFont = currentFont;
- }
- drawRunY = drawY + (baseline - run.ascent);
- int end = run.start + run.length - 1;
- boolean fullSelection = hasSelection && selectionStart <= run.start && selectionEnd >= end;
- if (fullSelection) {
- gc.setBackground(selectionBackground);
- gc.fillRectangle(drawX, drawY, run.width, lineHeight);
- if (!run.tab && !(run.style != null && run.style.metrics != null)) {
- gc.setForeground(selectionForeground);
- String string = text.substring(run.start, run.start + run.length);
- gc.drawString(string, drawX, drawRunY, true);
- if (run.style != null && run.style.underline) {
- int underlineY = drawRunY + run.ascent + 1 - run.style.rise;
- gc.drawLine (drawX, underlineY, drawX + run.width, underlineY);
- }
- if (run.style != null && run.style.strikeout) {
- int strikeoutY = drawRunY + (run.ascent + run.descent) - (run.ascent + run.descent)/2 - 1;
- gc.drawLine (drawX, strikeoutY, drawX + run.width, strikeoutY);
- }
- }
- } else {
- if (run.style != null && run.style.background != null) {
- Color bg = run.style.background;
- gc.setBackground(bg);
- gc.fillRectangle(drawX, drawRunY, run.width, run.ascent + run.descent);
- }
- if (!run.tab) {
- Color fg = foreground;
- if (run.style != null && run.style.foreground != null) fg = run.style.foreground;
- gc.setForeground(fg);
- String string = text.substring(run.start, run.start + run.length);
- if (!(run.style != null && run.style.metrics != null)) {
- gc.drawString(string, drawX, drawRunY, true);
- if (run.style != null && run.style.underline) {
- int underlineY = drawRunY + run.ascent + 1 - run.style.rise;
- gc.drawLine (drawX, underlineY, drawX + run.width, underlineY);
- }
- if (run.style != null && run.style.strikeout) {
- int strikeoutY = drawRunY + (run.ascent + run.descent) - (run.ascent + run.descent)/2 - 1;
- gc.drawLine (drawX, strikeoutY, drawX + run.width, strikeoutY);
- }
- }
- boolean partialSelection = hasSelection && !(selectionStart > end || run.start > selectionEnd);
- if (partialSelection) {
- int selStart = Math.max(selectionStart, run.start);
- int selEnd = Math.min(selectionEnd, end);
- string = text.substring(run.start, selStart);
- int selX = drawX + gc.stringExtent(string).x;
- string = text.substring(selStart, selEnd + 1);
- int selWidth = gc.stringExtent(string).x;
- gc.setBackground(selectionBackground);
- gc.fillRectangle(selX, drawY, selWidth, lineHeight);
- if (fg != selectionForeground && !(run.style != null && run.style.metrics != null)) {
- gc.setForeground(selectionForeground);
- gc.drawString(string, selX, drawRunY, true);
- if (run.style != null && run.style.underline) {
- int underlineY = drawRunY + run.ascent + 1 - run.style.rise;
- gc.drawLine (selX, underlineY, selX + selWidth, underlineY);
- }
- if (run.style != null && run.style.strikeout) {
- int strikeoutY = drawRunY + (run.ascent + run.descent) - (run.ascent + run.descent)/2 - 1;
- gc.drawLine (selX, strikeoutY, selX + selWidth, strikeoutY);
- }
- }
- }
- }
- }
- }
- }
- drawX += run.width;
- }
- }
- gc.setForeground(foreground);
- gc.setBackground(background);
- gc.setFont(gcFont);
-}
-
-void freeRuns() {
- runs = null;
-}
-
-/**
- * Returns the receiver's horizontal text alignment, which will be one
- * of <code>SWT.LEFT</code>, <code>SWT.CENTER</code> or
- * <code>SWT.RIGHT</code>.
- *
- * @return the alignment used to positioned text horizontally
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getAlignment () {
- checkLayout();
- return alignment;
-}
-
-/**
- * Returns the ascent of the receiver.
- *
- * @return the ascent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getDescent()
- * @see #setDescent(int)
- * @see #setAscent(int)
- * @see #getLineMetrics(int)
- */
-public int getAscent () {
- checkLayout();
- return ascent;
-}
-
-/**
- * Returns the bounds of the receiver. The width returned is either the
- * width of the longest line or the width set using {@link TextLayout#setWidth(int)}.
- * To obtain the text bounds of a line use {@link TextLayout#getLineBounds(int)}.
- *
- * @return the bounds of the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setWidth(int)
- * @see #getLineBounds(int)
- */
-public Rectangle getBounds () {
- checkLayout();
- computeRuns(null);
- int width = 0;
- if (wrapWidth != -1) {
- width = wrapWidth;
- } else {
- for (int line=0; line<runs.length; line++) {
- width = Math.max(width, lineWidth[line] + getLineIndent(line));
- }
- }
- return new Rectangle (0, 0, width, lineY[lineY.length - 1]);
-}
-
-
-/**
- * Returns the bounds for the specified range of characters. The
- * bounds is the smallest rectangle that encompasses all characters
- * in the range. The start and end offsets are inclusive and will be
- * clamped if out of range.
- *
- * @param start the start offset
- * @param end the end offset
- * @return the bounds of the character range
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds (int start, int end) {
- checkLayout();
- int length = text.length();
- if (length == 0) return new Rectangle(0, 0, 0, 0);
- if (start > end) return new Rectangle(0, 0, 0, 0);
- start = Math.min(Math.max(0, start), length - 1);
- end = Math.min(Math.max(0, end), length - 1);
- computeRuns(null);
- int startLine = getLineIndex(start);
- int endLine = getLineIndex(end);
-
- Rectangle rect = new Rectangle(0, 0, 0, 0);
- rect.y = lineY[startLine];
- rect.height = lineY[endLine + 1] - rect.y - lineSpacing;
- if (startLine == endLine) {
- rect.x = getLocation(start, false).x;
- rect.width = getLocation(end, true).x - rect.x;
- } else {
- while (startLine <= endLine) {
- rect.width = Math.max(rect.width, lineWidth[startLine++]);
- }
- }
- return rect;
-}
-
-/**
- * Returns the descent of the receiver.
- *
- * @return the descent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getAscent()
- * @see #setAscent(int)
- * @see #setDescent(int)
- * @see #getLineMetrics(int)
- */
-public int getDescent () {
- checkLayout();
- return descent;
-}
-
-/**
- * Returns the default font currently being used by the receiver
- * to draw and measure text.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getFont () {
- checkLayout();
- return font;
-}
-
-
-/**
-* Returns the receiver's indent.
-*
-* @return the receiver's indent
-*
-* @exception SWTException <ul>
-* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
-* </ul>
-*
-* @since 3.2
-*/
-public int getIndent () {
- checkLayout();
- return indent;
-}
-
-/**
-* Returns the receiver's justification.
-*
-* @return the receiver's justification
-*
-* @exception SWTException <ul>
-* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
-* </ul>
-*
-* @since 3.2
-*/
-public boolean getJustify () {
- checkLayout();
- return justify;
-}
-
-/**
- * Returns the embedding level for the specified character offset. The
- * embedding level is usually used to determine the directionality of a
- * character in bidirectional text.
- *
- * @param offset the character offset
- * @return the embedding level
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- */
-public int getLevel (int offset) {
- checkLayout();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- return 0;
-}
-
-/**
- * Returns the line offsets. Each value in the array is the
- * offset for the first character in a line except for the last
- * value, which contains the length of the text.
- *
- * @return the line offsets
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getLineOffsets () {
- checkLayout();
- computeRuns(null);
- int[] offsets = new int[lineOffset.length];
- System.arraycopy(lineOffset, 0, offsets, 0, offsets.length);
- return offsets;
-}
-
-/**
- * Returns the bounds of the line for the specified line index.
- *
- * @param lineIndex the line index
- * @return the line bounds
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getLineBounds(int lineIndex) {
- checkLayout();
- computeRuns(null);
- if (!(0 <= lineIndex && lineIndex < runs.length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- int x = getLineIndent(lineIndex);
- int y = lineY[lineIndex];
- int width = lineWidth[lineIndex];
- int height = lineY[lineIndex + 1] - y - lineSpacing;
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the receiver's line count. This includes lines caused
- * by wrapping.
- *
- * @return the line count
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineCount () {
- checkLayout();
- computeRuns(null);
- return runs.length;
-}
-
-int getLineIndent (int lineIndex) {
- int lineIndent = 0;
- if (lineIndex == 0) {
- lineIndent = indent;
- } else {
- StyleItem[] previousLine = runs[lineIndex - 1];
- StyleItem previousRun = previousLine[previousLine.length - 1];
- if (previousRun.lineBreak && !previousRun.softBreak) {
- lineIndent = indent;
- }
- }
- if (wrapWidth != -1) {
- boolean partialLine = true;
-// if (justify) {
-// StyleItem[] lineRun = runs[lineIndex];
-// if (lineRun[lineRun.length - 1].softBreak) {
-// partialLine = false;
-// }
-// }
- if (partialLine) {
- int lineWidth = this.lineWidth[lineIndex] + lineIndent;
- switch (alignment) {
- case SWT.CENTER: lineIndent += (wrapWidth - lineWidth) / 2; break;
- case SWT.RIGHT: lineIndent += wrapWidth - lineWidth; break;
- }
- }
- }
- return lineIndent;
-}
-
-/**
- * Returns the index of the line that contains the specified
- * character offset.
- *
- * @param offset the character offset
- * @return the line index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineIndex (int offset) {
- checkLayout();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- computeRuns(null);
- for (int line=0; line<runs.length; line++) {
- if (lineOffset[line + 1] > offset) {
- return line;
- }
- }
- return runs.length - 1;
-}
-
-/**
- * Returns the font metrics for the specified line index.
- *
- * @param lineIndex the line index
- * @return the font metrics
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontMetrics getLineMetrics (int lineIndex) {
- checkLayout();
- computeRuns(null);
- if (!(0 <= lineIndex && lineIndex < runs.length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- GC gc = new GC(device);
- gc.setFont(this.font != null ? this.font : device.getSystemFont());
- FontMetrics metrics = gc.getFontMetrics();
- int ascent = Math.max(metrics.getAscent(), this.ascent);
- int descent = Math.max(metrics.getDescent(), this.descent);
- if (text.length() != 0) {
- StyleItem[] lineRuns = runs[lineIndex];
- for (int i = 0; i < lineRuns.length; i++) {
- StyleItem run = lineRuns[i];
- if (run.style != null) {
- int runAscent = 0;
- int runDescent = 0;
- if (run.style.metrics != null) {
- GlyphMetrics glyphMetrics = run.style.metrics;
- runAscent = glyphMetrics.ascent;
- runDescent = glyphMetrics.descent;
- } else if (run.style.font != null) {
- gc.setFont(run.style.font);
- metrics = gc.getFontMetrics();
- runAscent = metrics.getAscent();
- runDescent = metrics.getDescent();
- }
- ascent = Math.max(ascent, runAscent + run.style.rise);
- descent = Math.max(descent, runDescent - run.style.rise);
- }
- }
- }
- gc.dispose();
- return FontMetrics.internal_new(ascent, descent, 0, 0, ascent + descent);
-}
-
-/**
- * Returns the location for the specified character offset. The
- * <code>trailing</code> argument indicates whether the offset
- * corresponds to the leading or trailing edge of the cluster.
- *
- * @param offset the character offset
- * @param trailing the trailing flag
- * @return the location of the character offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getOffset(Point, int[])
- * @see #getOffset(int, int, int[])
- */
-public Point getLocation (int offset, boolean trailing) {
- checkLayout();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- computeRuns(null);
- int line;
- for (line=0; line<runs.length; line++) {
- if (lineOffset[line + 1] > offset) break;
- }
- line = Math.min(line, runs.length - 1);
- StyleItem[] lineRuns = runs[line];
- Point result = null;
- if (offset == length) {
- result = new Point(lineWidth[line], lineY[line]);
- } else {
- int width = 0;
- for (int i=0; i<lineRuns.length; i++) {
- StyleItem run = lineRuns[i];
- int end = run.start + run.length;
- if (run.start <= offset && offset < end) {
- if (run.tab) {
- if (trailing || offset == length) width += run.width;
- } else {
- if (trailing) offset++;
- if (run.style != null && run.style.metrics != null) {
- GlyphMetrics metrics = run.style.metrics;
- width += metrics.width * (offset - run.start);
- } else {
- String string = text.substring(run.start, offset);
- GC gc = new GC (device);
- gc.setFont(getItemFont(run));
- width += gc.stringExtent(string).x;
- gc.dispose();
- }
- }
- result = new Point(width, lineY[line]);
- break;
- }
- width += run.width;
- }
- }
- if (result == null) result = new Point(0, 0);
- result.x += getLineIndent(line);
- return result;
-}
-
-Font getItemFont(StyleItem item) {
- if (item.style != null && item.style.font != null) {
- return item.style.font;
- }
- if (this.font != null) {
- return this.font;
- }
- return device.getSystemFont();
-}
-
-/**
- * Returns the next offset for the specified offset and movement
- * type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>,
- * <code>SWT.MOVEMENT_CLUSTER</code>, <code>SWT.MOVEMENT_WORD</code>,
- * <code>SWT.MOVEMENT_WORD_END</code> or <code>SWT.MOVEMENT_WORD_START</code>.
- *
- * @param offset the start offset
- * @param movement the movement type
- * @return the next offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getPreviousOffset(int, int)
- */
-public int getNextOffset (int offset, int movement) {
- checkLayout();
- computeRuns(null);
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- if (offset == length) return length;
- if ((movement & (SWT.MOVEMENT_CHAR | SWT.MOVEMENT_CLUSTER)) != 0) return offset + 1;
- int lineEnd = 0;
- for (int i=1; i<lineOffset.length; i++) {
- if (lineOffset[i] > offset) {
- lineEnd = Math.max(lineOffset[i - 1], lineOffset[i] - 1);
- if (i == runs.length) lineEnd++;
- break;
- }
- }
- boolean previousSpaceChar = !Compatibility.isLetterOrDigit(text.charAt(offset));
- offset++;
- while (offset < lineEnd) {
- boolean spaceChar = !Compatibility.isLetterOrDigit(text.charAt(offset));
- if (!spaceChar && previousSpaceChar) break;
- previousSpaceChar = spaceChar;
- offset++;
- }
- return offset;
-}
-
-/**
- * Returns the character offset for the specified point.
- * For a typical character, the trailing argument will be filled in to
- * indicate whether the point is closer to the leading edge (0) or
- * the trailing edge (1). When the point is over a cluster composed
- * of multiple characters, the trailing argument will be filled with the
- * position of the character in the cluster that is closest to
- * the point.
- *
- * @param point the point
- * @param trailing the trailing buffer
- * @return the character offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getLocation(int, boolean)
- */
-public int getOffset (Point point, int[] trailing) {
- checkLayout();
- if (point == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return getOffset (point.x, point.y, trailing);
-}
-
-/**
- * Returns the character offset for the specified point.
- * For a typical character, the trailing argument will be filled in to
- * indicate whether the point is closer to the leading edge (0) or
- * the trailing edge (1). When the point is over a cluster composed
- * of multiple characters, the trailing argument will be filled with the
- * position of the character in the cluster that is closest to
- * the point.
- *
- * @param x the x coordinate of the point
- * @param y the y coordinate of the point
- * @param trailing the trailing buffer
- * @return the character offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getLocation(int, boolean)
- */
-public int getOffset (int x, int y, int[] trailing) {
- checkLayout();
- if (trailing != null && trailing.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- computeRuns(null);
- int line;
- int lineCount = runs.length;
- for (line=0; line<lineCount; line++) {
- if (lineY[line + 1] > y) break;
- }
- line = Math.min(line, runs.length - 1);
- x -= getLineIndent(line);
- if (x >= lineWidth[line]) x = lineWidth[line] - 1;
- if (x < 0) x = 0;
- StyleItem[] lineRuns = runs[line];
- int width = 0;
- for (int i = 0; i < lineRuns.length; i++) {
- StyleItem run = lineRuns[i];
- if (run.lineBreak && !run.softBreak) return run.start;
- if (width + run.width > x) {
- if (run.style != null && run.style.metrics != null) {
- int xRun = x - width;
- GlyphMetrics metrics = run.style.metrics;
- if (metrics.width > 0) {
- if (trailing != null) {
- trailing[0] = (xRun % metrics.width < metrics.width / 2) ? 0 : 1;
- }
- return run.start + xRun / metrics.width;
- }
- }
- if (run.tab) {
- if (trailing != null) {
- trailing[0] = x < (width + run.width / 2) ? 0 : 1;
- }
- return run.start;
- }
- int offset = 0;
- GC gc = new GC(device);
- gc.setFont(getItemFont(run));
- char[] chars = new char[run.length];
- text.getChars(run.start, run.start + run.length, chars, 0);
- for (offset = 0; offset < chars.length; offset++) {
- int charWidth = gc.stringExtent(String.valueOf(chars[offset])).x;
- if (width + charWidth > x) {
- if (trailing != null) {
- trailing[0] = x < (width + charWidth / 2) ? 0 : 1;
- }
- break;
- }
- width += charWidth;
- }
- gc.dispose();
- return run.start + offset;
- }
- width += run.width;
- }
- if (trailing != null) trailing[0] = 0;
- return lineOffset[line + 1];
-}
-
-/**
- * Returns the orientation of the receiver.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getOrientation () {
- checkLayout();
- return orientation;
-}
-
-/**
- * Returns the previous offset for the specified offset and movement
- * type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>,
- * <code>SWT.MOVEMENT_CLUSTER</code> or <code>SWT.MOVEMENT_WORD</code>,
- * <code>SWT.MOVEMENT_WORD_END</code> or <code>SWT.MOVEMENT_WORD_START</code>.
- *
- * @param offset the start offset
- * @param movement the movement type
- * @return the previous offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getNextOffset(int, int)
- */
-public int getPreviousOffset (int offset, int movement) {
- checkLayout();
- computeRuns(null);
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- if (offset == 0) return 0;
- if ((movement & (SWT.MOVEMENT_CHAR | SWT.MOVEMENT_CLUSTER)) != 0) return offset - 1;
- int lineStart = 0;
- for (int i=0; i<lineOffset.length-1; i++) {
- int lineEnd = lineOffset[i+1];
- if (i == runs.length - 1) lineEnd++;
- if (lineEnd > offset) {
- lineStart = lineOffset[i];
- break;
- }
- }
- offset--;
- boolean previousSpaceChar = !Compatibility.isLetterOrDigit(text.charAt(offset));
- while (lineStart < offset) {
- boolean spaceChar = !Compatibility.isLetterOrDigit(text.charAt(offset - 1));
- if (spaceChar && !previousSpaceChar) break;
- offset--;
- previousSpaceChar = spaceChar;
- }
- return offset;
-}
-
-/**
- * Gets the ranges of text that are associated with a <code>TextStyle</code>.
- *
- * @return the ranges, an array of offsets representing the start and end of each
- * text style.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getStyles()
- *
- * @since 3.2
- */
-public int[] getRanges () {
- checkLayout();
- int[] result = new int[styles.length * 2];
- int count = 0;
- for (int i=0; i<styles.length - 1; i++) {
- if (styles[i].style != null) {
- result[count++] = styles[i].start;
- result[count++] = styles[i + 1].start - 1;
- }
- }
- if (count != result.length) {
- int[] newResult = new int[count];
- System.arraycopy(result, 0, newResult, 0, count);
- result = newResult;
- }
- return result;
-}
-
-/**
- * Returns the line spacing of the receiver.
- *
- * @return the line spacing
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getSpacing () {
- checkLayout();
- return lineSpacing;
-}
-
-/**
- * Returns the text segments offsets of the receiver.
- *
- * @return the text segments offsets
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getSegments() {
- checkLayout();
- return segments;
-}
-
-/**
- * Gets the style of the receiver at the specified character offset.
- *
- * @param offset the text offset
- * @return the style or <code>null</code> if not set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public TextStyle getStyle (int offset) {
- checkLayout();
- int length = text.length();
- if (!(0 <= offset && offset < length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- for (int i=1; i<styles.length; i++) {
- StyleItem item = styles[i];
- if (item.start > offset) {
- return styles[i - 1].style;
- }
- }
- return null;
-}
-
-/**
- * Gets all styles of the receiver.
- *
- * @return the styles
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getRanges()
- *
- * @since 3.2
- */
-public TextStyle[] getStyles () {
- checkLayout();
- TextStyle[] result = new TextStyle[styles.length];
- int count = 0;
- for (int i=0; i<styles.length; i++) {
- if (styles[i].style != null) {
- result[count++] = styles[i].style;
- }
- }
- if (count != result.length) {
- TextStyle[] newResult = new TextStyle[count];
- System.arraycopy(result, 0, newResult, 0, count);
- result = newResult;
- }
- return result;
-}
-
-/**
- * Returns the tab list of the receiver.
- *
- * @return the tab list
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getTabs () {
- checkLayout();
- return tabs;
-}
-
-/**
- * Gets the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public String getText () {
- checkLayout();
- return text;
-}
-
-/**
- * Returns the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getWidth () {
- checkLayout();
- return wrapWidth;
-}
-
-/**
- * Returns <code>true</code> if the text layout has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the text layout.
- * When a text layout has been disposed, it is an error to
- * invoke any other method using the text layout.
- * </p>
- *
- * @return <code>true</code> when the text layout is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- return device == null;
-}
-
-/*
- * Itemize the receiver text, create run for
- */
-StyleItem[] itemize () {
- int length = text.length();
- if (length == 0) {
- return new StyleItem[]{new StyleItem(), new StyleItem()};
- }
- int runCount = 0, start = 0;
- StyleItem[] runs = new StyleItem[length];
- char[] chars = text.toCharArray();
- for (int i = 0; i<length; i++) {
- char ch = chars[i];
- if (ch == '\t' || ch == '\r' || ch == '\n') {
- if (i != start) {
- StyleItem item = new StyleItem();
- item.start = start;
- runs[runCount++] = item;
- }
- StyleItem item = new StyleItem();
- item.start = i;
- runs[runCount++] = item;
- start = i + 1;
- }
- }
- char lastChar = chars[length - 1];
- if (!(lastChar == '\t' || lastChar == '\r' || lastChar == '\n')) {
- StyleItem item = new StyleItem();
- item.start = start;
- runs[runCount++] = item;
- }
- if (runCount != length) {
- StyleItem[] newRuns = new StyleItem[runCount];
- System.arraycopy(runs, 0, newRuns, 0, runCount);
- runs = newRuns;
- }
- runs = merge(runs, runCount);
- return runs;
-}
-
-/*
- * Merge styles ranges and script items
- */
-StyleItem[] merge (StyleItem[] items, int itemCount) {
- int length = text.length();
- int count = 0, start = 0, end = length, itemIndex = 0, styleIndex = 0;
- StyleItem[] runs = new StyleItem[itemCount + styles.length];
- while (start < end) {
- StyleItem item = new StyleItem();
- item.start = start;
- item.style = styles[styleIndex].style;
- runs[count++] = item;
- int itemLimit = itemIndex + 1 < items.length ? items[itemIndex + 1].start : length;
- int styleLimit = styleIndex + 1 < styles.length ? styles[styleIndex + 1].start : length;
- if (styleLimit <= itemLimit) {
- styleIndex++;
- start = styleLimit;
- }
- if (itemLimit <= styleLimit) {
- itemIndex++;
- start = itemLimit;
- }
- item.length = start - item.start;
- }
- StyleItem item = new StyleItem();
- item.start = end;
- runs[count++] = item;
- if (runs.length != count) {
- StyleItem[] result = new StyleItem[count];
- System.arraycopy(runs, 0, result, 0, count);
- return result;
- }
- return runs;
-}
-
-void place (GC gc, StyleItem run) {
- if (run.style != null && run.style.metrics != null) {
- GlyphMetrics metrics = run.style.metrics;
- run.ascent = metrics.ascent;
- run.descent = metrics.descent;
- run.width = metrics.width * run.length;
- } else {
- String string = text.substring(run.start, run.start + run.length);
- Point extent = gc.stringExtent(string);
- FontMetrics metrics = gc.getFontMetrics();
- run.width = extent.x;
- run.ascent = metrics.getAscent() + metrics.getLeading();
- run.descent = metrics.getDescent();
- }
- if (run.style != null) {
- run.ascent += run.style.rise;
- run.descent -= run.style.rise;
- }
-}
-
-/**
- * Sets the text alignment for the receiver. The alignment controls
- * how a line of text is positioned horizontally. The argument should
- * be one of <code>SWT.LEFT</code>, <code>SWT.RIGHT</code> or <code>SWT.CENTER</code>.
- * <p>
- * The default alignment is <code>SWT.LEFT</code>. Note that the receiver's
- * width must be set in order to use <code>SWT.RIGHT</code> or <code>SWT.CENTER</code>
- * alignment.
- * </p>
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setWidth(int)
- */
-public void setAlignment (int alignment) {
- checkLayout();
- int mask = SWT.LEFT | SWT.CENTER | SWT.RIGHT;
- alignment &= mask;
- if (alignment == 0) return;
- if ((alignment & SWT.LEFT) != 0) alignment = SWT.LEFT;
- if ((alignment & SWT.RIGHT) != 0) alignment = SWT.RIGHT;
- freeRuns();
- this.alignment = alignment;
-}
-
-/**
- * Sets the ascent of the receiver. The ascent is distance in pixels
- * from the baseline to the top of the line and it is applied to all
- * lines. The default value is <code>-1</code> which means that the
- * ascent is calculated from the line fonts.
- *
- * @param ascent the new ascent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the ascent is less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setDescent(int)
- * @see #getLineMetrics(int)
- */
-public void setAscent (int ascent) {
- checkLayout();
- if (ascent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.ascent == ascent) return;
- freeRuns();
- this.ascent = ascent;
-}
-
-/**
- * Sets the descent of the receiver. The descent is distance in pixels
- * from the baseline to the bottom of the line and it is applied to all
- * lines. The default value is <code>-1</code> which means that the
- * descent is calculated from the line fonts.
- *
- * @param descent the new descent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the descent is less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAscent(int)
- * @see #getLineMetrics(int)
- */
-public void setDescent (int descent) {
- checkLayout();
- if (descent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.descent == descent) return;
- freeRuns();
- this.descent = descent;
-}
-
-/**
- * Sets the default font which will be used by the receiver
- * to draw and measure text. If the
- * argument is null, then a default font appropriate
- * for the platform will be used instead. Note that a text
- * style can override the default font.
- *
- * @param font the new font for the receiver, or null to indicate a default font
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkLayout ();
- if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Font oldFont = this.font;
- if (oldFont == font) return;
- this.font = font;
- if (oldFont != null && oldFont.equals(font)) return;
- freeRuns();
-}
-
-/**
- * Sets the indent of the receiver. This indent it applied of the first line of
- * each paragraph.
- *
- * @param indent new indent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setIndent (int indent) {
- checkLayout();
- if (indent < 0) return;
- if (this.indent == indent) return;
- freeRuns();
- this.indent = indent;
-}
-
-/**
- * Sets the justification of the receiver. Note that the receiver's
- * width must be set in order to use justification.
- *
- * @param justify new justify
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setJustify (boolean justify) {
- checkLayout();
- if (this.justify == justify) return;
- freeRuns();
- this.justify = justify;
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setOrientation (int orientation) {
- checkLayout();
- int mask = SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT;
- orientation &= mask;
- if (orientation == 0) return;
- if ((orientation & SWT.LEFT_TO_RIGHT) != 0) orientation = SWT.LEFT_TO_RIGHT;
- this.orientation = orientation;
-}
-
-/**
- * Sets the line spacing of the receiver. The line spacing
- * is the space left between lines.
- *
- * @param spacing the new line spacing
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the spacing is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setSpacing (int spacing) {
- checkLayout();
- if (spacing < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.lineSpacing == spacing) return;
- freeRuns();
- this.lineSpacing = spacing;
-}
-
-/**
- * Sets the offsets of the receiver's text segments. Text segments are used to
- * override the default behaviour of the bidirectional algorithm.
- * Bidirectional reordering can happen within a text segment but not
- * between two adjacent segments.
- * <p>
- * Each text segment is determined by two consecutive offsets in the
- * <code>segments</code> arrays. The first element of the array should
- * always be zero and the last one should always be equals to length of
- * the text.
- * </p>
- *
- * @param segments the text segments offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setSegments(int[] segments) {
- checkLayout();
- if (this.segments == null && segments == null) return;
- if (this.segments != null && segments !=null) {
- if (this.segments.length == segments.length) {
- int i;
- for (i = 0; i <segments.length; i++) {
- if (this.segments[i] != segments[i]) break;
- }
- if (i == segments.length) return;
- }
- }
- freeRuns();
- this.segments = segments;
-}
-
-/**
- * Sets the style of the receiver for the specified range. Styles previously
- * set for that range will be overwritten. The start and end offsets are
- * inclusive and will be clamped if out of range.
- *
- * @param style the style
- * @param start the start offset
- * @param end the end offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setStyle (TextStyle style, int start, int end) {
- checkLayout();
- int length = text.length();
- if (length == 0) return;
- if (start > end) return;
- start = Math.min(Math.max(0, start), length - 1);
- end = Math.min(Math.max(0, end), length - 1);
- int low = -1;
- int high = styles.length;
- while (high - low > 1) {
- int index = (high + low) / 2;
- if (styles[index + 1].start > start) {
- high = index;
- } else {
- low = index;
- }
- }
- if (0 <= high && high < styles.length) {
- StyleItem item = styles[high];
- if (item.start == start && styles[high + 1].start - 1 == end) {
- if (style == null) {
- if (item.style == null) return;
- } else {
- if (style.equals(item.style)) return;
- }
- }
- }
- freeRuns();
- int modifyStart = high;
- int modifyEnd = modifyStart;
- while (modifyEnd < styles.length) {
- if (styles[modifyEnd + 1].start > end) break;
- modifyEnd++;
- }
- if (modifyStart == modifyEnd) {
- int styleStart = styles[modifyStart].start;
- int styleEnd = styles[modifyEnd + 1].start - 1;
- if (styleStart == start && styleEnd == end) {
- styles[modifyStart].style = style;
- return;
- }
- if (styleStart != start && styleEnd != end) {
- StyleItem[] newStyles = new StyleItem[styles.length + 2];
- System.arraycopy(styles, 0, newStyles, 0, modifyStart + 1);
- StyleItem item = new StyleItem();
- item.start = start;
- item.style = style;
- newStyles[modifyStart + 1] = item;
- item = new StyleItem();
- item.start = end + 1;
- item.style = styles[modifyStart].style;
- newStyles[modifyStart + 2] = item;
- System.arraycopy(styles, modifyEnd + 1, newStyles, modifyEnd + 3, styles.length - modifyEnd - 1);
- styles = newStyles;
- return;
- }
- }
- if (start == styles[modifyStart].start) modifyStart--;
- if (end == styles[modifyEnd + 1].start - 1) modifyEnd++;
- int newLength = styles.length + 1 - (modifyEnd - modifyStart - 1);
- StyleItem[] newStyles = new StyleItem[newLength];
- System.arraycopy(styles, 0, newStyles, 0, modifyStart + 1);
- StyleItem item = new StyleItem();
- item.start = start;
- item.style = style;
- newStyles[modifyStart + 1] = item;
- styles[modifyEnd].start = end + 1;
- System.arraycopy(styles, modifyEnd, newStyles, modifyStart + 2, styles.length - modifyEnd);
- styles = newStyles;
-}
-
-/**
- * Sets the receiver's tab list. Each value in the tab list specifies
- * the space in pixels from the origin of the text layout to the respective
- * tab stop. The last tab stop width is repeated continuously.
- *
- * @param tabs the new tab list
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setTabs (int[] tabs) {
- checkLayout();
- if (this.tabs == null && tabs == null) return;
- if (this.tabs != null && tabs !=null) {
- if (this.tabs.length == tabs.length) {
- int i;
- for (i = 0; i <tabs.length; i++) {
- if (this.tabs[i] != tabs[i]) break;
- }
- if (i == tabs.length) return;
- }
- }
- freeRuns();
- this.tabs = tabs;
-}
-
-/**
- * Sets the receiver's text.
- *<p>
- * Note: Setting the text also clears all the styles. This method
- * returns without doing anything if the new text is the same as
- * the current text.
- * </p>
- *
- * @param text the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setText (String text) {
- checkLayout();
- if (text == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (text.equals(this.text)) return;
- freeRuns();
- this.text = text;
- styles = new StyleItem[2];
- styles[0] = new StyleItem();
- styles[1] = new StyleItem();
- styles[1].start = text.length();
-}
-
-/**
- * Sets the line width of the receiver, which determines how
- * text should be wrapped and aligned. The default value is
- * <code>-1</code> which means wrapping is disabled.
- *
- * @param width the new width
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the width is <code>0</code> or less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAlignment(int)
- */
-public void setWidth (int width) {
- checkLayout();
- if (width < -1 || width == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.wrapWidth == width) return;
- freeRuns();
- this.wrapWidth = width;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "TextLayout {*DISPOSED*}";
- return "TextLayout {}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/tooltip/org/eclipse/swt/widgets/ToolTip.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/tooltip/org/eclipse/swt/widgets/ToolTip.java
deleted file mode 100644
index 3edac98b97..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/tooltip/org/eclipse/swt/widgets/ToolTip.java
+++ /dev/null
@@ -1,644 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent popup windows that are used
- * to inform or warn the user.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BALLOON, ICON_ERROR, ICON_INFORMATION, ICON_WARNING</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION,
- * and ICON_WARNING may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tooltips">Tool Tips snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.2
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolTip extends Widget {
- Shell parent, tip;
- TrayItem item;
- int x, y;
- int [] borderPolygon;
- boolean spikeAbove, autohide;
- Listener listener, parentListener;
- TextLayout layoutText, layoutMessage;
- Region region;
- Font boldFont;
- Runnable runnable;
-
- static final int BORDER = 5;
- static final int PADDING = 5;
- static final int INSET = 4;
- static final int TIP_HEIGHT = 20;
- static final int IMAGE_SIZE = 16;
- static final int DELAY = 10000;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BALLOON
- * @see SWT#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_WARNING
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ToolTip (Shell parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- this.autohide = true;
- x = y = -1;
- Display display = getDisplay ();
- tip = new Shell (parent, SWT.ON_TOP | SWT.NO_TRIM);
- Color background = display.getSystemColor (SWT.COLOR_INFO_BACKGROUND);
- tip.setBackground (background);
- listener = new Listener () {
- public void handleEvent (Event event) {
- switch (event.type) {
- case SWT.Dispose: onDispose (event); break;
- case SWT.Paint: onPaint (event); break;
- case SWT.MouseDown: onMouseDown (event); break;
- }
- }
- };
- addListener (SWT.Dispose, listener);
- tip.addListener (SWT.Paint, listener);
- tip.addListener (SWT.MouseDown, listener);
- parentListener = new Listener () {
- public void handleEvent (Event event) {
- dispose ();
- }
- };
- parent.addListener(SWT.Dispose, parentListener);
-}
-
-static int checkStyle (int style) {
- int mask = SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING;
- if ((style & mask) == 0) return style;
- return checkBits (style, SWT.ICON_INFORMATION, SWT.ICON_WARNING, SWT.ICON_ERROR, 0, 0, 0);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the receiver is selected.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the receiver is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-void configure () {
- Display display = parent.getDisplay ();
- int x = this.x;
- int y = this.y;
- if (x == -1 || y == -1) {
- Point point;
- if (item != null) {
- point = item.getLocation ();
- } else {
- point = display.getCursorLocation ();
- }
- x = point.x;
- y = point.y;
- }
- Monitor monitor = parent.getMonitor ();
- Rectangle dest = monitor.getBounds ();
- Point size = getSize (dest.width / 4);
- int w = size.x;
- int h = size.y;
- int t = (style & SWT.BALLOON) != 0 ? TIP_HEIGHT : 0;
- int i = (style & SWT.BALLOON) != 0 ? 16 : 0;
- tip.setSize (w, h + t);
- int [] polyline;
- spikeAbove = dest.height >= y + size.y + t;
- if (dest.width >= x + size.x) {
- if (dest.height >= y + size.y + t) {
- polyline = new int [] {
- 0, 5+t, 1, 5+t, 1, 3+t, 3, 1+t, 5, 1+t, 5, t,
- 16, t, 16, 0, 35, t,
- w-5, t, w-5, 1+t, w-3, 1+t, w-1, 3+t, w-1, 5+t, w, 5+t,
- w, h-5+t, w-1, h-5+t, w-1, h-3+t, w-2, h-3+t, w-2, h-2+t, w-3, h-2+t, w-3, h-1+t, w-5, h-1+t, w-5, h+t,
- 5, h+t, 5, h-1+t, 3, h-1+t, 3, h-2+t, 2, h-2+t, 2, h-3+t, 1, h-3+t, 1, h-5+t, 0, h-5+t,
- 0, 5+t};
- borderPolygon = new int[] {
- 0, 5+t, 1, 4+t, 1, 3+t, 3, 1+t, 4, 1+t, 5, t,
- 16, t, 16, 1, 35, t,
- w-6, 0+t, w-5, 1+t, w-4, 1+t, w-2, 3+t, w-2, 4+t, w-1, 5+t,
- w-1, h-6+t, w-2, h-5+t, w-2, h-4+t, w-4, h-2+t, w-5, h-2+t, w-6, h-1+t,
- 5, h-1+t, 4, h-2+t, 3, h-2+t, 1, h-4+t, 1, h-5+t, 0, h-6+t,
- 0, 5+t};
- tip.setLocation (Math.max (0, x - i), y);
- } else {
- polyline = new int [] {
- 0, 5, 1, 5, 1, 3, 3, 1, 5, 1, 5, 0,
- w-5, 0, w-5, 1, w-3, 1, w-1, 3, w-1, 5, w, 5,
- w, h-5, w-1, h-5, w-1, h-3, w-2, h-3, w-2, h-2, w-3, h-2, w-3, h-1, w-5, h-1, w-5, h,
- 35, h, 16, h+t, 16, h,
- 5, h, 5, h-1, 3, h-1, 3, h-2, 2, h-2, 2, h-3, 1, h-3, 1, h-5, 0, h-5,
- 0, 5};
- borderPolygon = new int[] {
- 0, 5, 1, 4, 1, 3, 3, 1, 4, 1, 5, 0,
- w-6, 0, w-5, 1, w-4, 1, w-2, 3, w-2, 4, w-1, 5,
- w-1, h-6, w-2, h-5, w-2, h-4, w-4, h-2, w-5, h-2, w-6, h-1,
- 36, h-1, 16, h+t-1, 16, h-1,
- 5, h-1, 4, h-2, 3, h-2, 1, h-4, 1, h-5, 0, h-6,
- 0, 5};
- tip.setLocation (Math.max (0, x - i), y - size.y - t);
- }
- } else {
- if (dest.height >= y + size.y + t) {
- polyline = new int [] {
- 0, 5+t, 1, 5+t, 1, 3+t, 3, 1+t, 5, 1+t, 5, t,
- w-35, t, w-16, 0, w-16, t,
- w-5, t, w-5, 1+t, w-3, 1+t, w-1, 3+t, w-1, 5+t, w, 5+t,
- w, h-5+t, w-1, h-5+t, w-1, h-3+t, w-2, h-3+t, w-2, h-2+t, w-3, h-2+t, w-3, h-1+t, w-5, h-1+t, w-5, h+t,
- 5, h+t, 5, h-1+t, 3, h-1+t, 3, h-2+t, 2, h-2+t, 2, h-3+t, 1, h-3+t, 1, h-5+t, 0, h-5+t,
- 0, 5+t};
- borderPolygon = new int[] {
- 0, 5+t, 1, 4+t, 1, 3+t, 3, 1+t, 4, 1+t, 5, t,
- w-35, t, w-17, 2, w-17, t,
- w-6, t, w-5, 1+t, w-4, 1+t, w-2, 3+t, w-2, 4+t, w-1, 5+t,
- w-1, h-6+t, w-2, h-5+t, w-2, h-4+t, w-4, h-2+t, w-5, h-2+t, w-6, h-1+t,
- 5, h-1+t, 4, h-2+t, 3, h-2+t, 1, h-4+t, 1, h-5+t, 0, h-6+t,
- 0, 5+t};
- tip.setLocation (Math.min (dest.width - size.x, x - size.x + i), y);
- } else {
- polyline = new int [] {
- 0, 5, 1, 5, 1, 3, 3, 1, 5, 1, 5, 0,
- w-5, 0, w-5, 1, w-3, 1, w-1, 3, w-1, 5, w, 5,
- w, h-5, w-1, h-5, w-1, h-3, w-2, h-3, w-2, h-2, w-3, h-2, w-3, h-1, w-5, h-1, w-5, h,
- w-16, h, w-16, h+t, w-35, h,
- 5, h, 5, h-1, 3, h-1, 3, h-2, 2, h-2, 2, h-3, 1, h-3, 1, h-5, 0, h-5,
- 0, 5};
- borderPolygon = new int[] {
- 0, 5, 1, 4, 1, 3, 3, 1, 4, 1, 5, 0,
- w-6, 0, w-5, 1, w-4, 1, w-2, 3, w-2, 4, w-1, 5,
- w-1, h-6, w-2, h-5, w-2, h-4, w-4, h-2, w-5, h-2, w-6, h-1,
- w-17, h-1, w-17, h+t-2, w-36, h-1,
- 5, h-1, 4, h-2, 3, h-2, 1, h-4, 1, h-5, 0, h-6,
- 0, 5};
- tip.setLocation (Math.min (dest.width - size.x, x - size.x + i), y - size.y - t);
- }
- }
- if ((style & SWT.BALLOON) != 0) {
- if (region != null) region.dispose ();
- region = new Region (display);
- region.add (polyline);
- tip.setRegion (region);
- }
-}
-
-/**
- * Returns <code>true</code> if the receiver is automatically
- * hidden by the platform, and <code>false</code> otherwise.
- *
- * @return the receiver's auto hide state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public boolean getAutoHide () {
- checkWidget ();
- return autohide;
-}
-
-Point getSize (int maxWidth) {
- int textWidth = 0, messageWidth = 0;
- if (layoutText != null) {
- layoutText.setWidth (-1);
- textWidth = layoutText.getBounds ().width;
- }
- if (layoutMessage != null) {
- layoutMessage.setWidth (-1);
- messageWidth = layoutMessage.getBounds ().width;
- }
- int messageTrim = 2 * INSET + 2 * BORDER + 2 * PADDING;
- boolean hasImage = layoutText != null && (style & SWT.BALLOON) != 0 && (style & (SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING)) != 0;
- int textTrim = messageTrim + (hasImage ? IMAGE_SIZE : 0);
- int width = Math.min (maxWidth, Math.max (textWidth + textTrim, messageWidth + messageTrim));
- int textHeight = 0, messageHeight = 0;
- if (layoutText != null) {
- layoutText.setWidth (maxWidth - textTrim);
- textHeight = layoutText.getBounds ().height;
- }
- if (layoutMessage != null) {
- layoutMessage.setWidth (maxWidth - messageTrim);
- messageHeight = layoutMessage.getBounds ().height;
- }
- int height = 2 * BORDER + 2 * PADDING + messageHeight;
- if (layoutText != null) height += Math.max (IMAGE_SIZE, textHeight) + 2 * PADDING;
- return new Point (width, height);
-}
-
-/**
- * Returns the receiver's message, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's message
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getMessage () {
- checkWidget ();
- return layoutMessage != null ? layoutMessage.getText() : "";
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Shell</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Shell getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return layoutText != null ? layoutText.getText() : "";
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- return tip.getVisible ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget ();
- return getVisible ();
-}
-
-void onDispose (Event event) {
- Control parent = getParent ();
- parent.removeListener (SWT.Dispose, parentListener);
- removeListener (SWT.Dispose, listener);
- notifyListeners (SWT.Dispose, event);
- event.type = SWT.None;
-
- if (runnable != null) {
- Display display = getDisplay ();
- display.timerExec (-1, runnable);
- }
- runnable = null;
- tip.dispose ();
- tip = null;
- if (region != null) region.dispose ();
- region = null;
- if (layoutText != null) layoutText.dispose ();
- layoutText = null;
- if (layoutMessage != null) layoutMessage.dispose ();
- layoutMessage = null;
- if (boldFont != null) boldFont.dispose ();
- boldFont = null;
- borderPolygon = null;
-}
-
-void onMouseDown (Event event) {
- notifyListeners (SWT.Selection, new Event ());
- setVisible (false);
-}
-
-void onPaint (Event event) {
- GC gc = event.gc;
- int x = BORDER + PADDING;
- int y = BORDER + PADDING;
- if ((style & SWT.BALLOON) != 0) {
- if (spikeAbove) y += TIP_HEIGHT;
- gc.drawPolygon (borderPolygon);
- } else {
- Rectangle rect = tip.getClientArea ();
- gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height -1);
- }
- if (layoutText != null) {
- int id = style & (SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING);
- if ((style & SWT.BALLOON) != 0 && id != 0) {
- Display display = getDisplay ();
- Image image = display.getSystemImage (id);
- Rectangle rect = image.getBounds ();
- gc.drawImage (image, 0, 0, rect.width, rect.height, x, y, IMAGE_SIZE, IMAGE_SIZE);
- x += IMAGE_SIZE;
- }
- x += INSET;
- layoutText.draw (gc, x, y);
- y += 2 * PADDING + Math.max (IMAGE_SIZE, layoutText.getBounds ().height);
- }
- if (layoutMessage != null) {
- x = BORDER + PADDING + INSET;
- layoutMessage.draw (gc, x, y);
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Makes the receiver hide automatically when <code>true</code>,
- * and remain visible when <code>false</code>.
- *
- * @param autoHide the auto hide state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- * @see #setVisible
- */
-public void setAutoHide (boolean autohide) {
- checkWidget ();
- this.autohide = autohide;
- //TODO - update when visible
-}
-
-/**
- * Sets the location of the receiver, which must be a tooltip,
- * to the point specified by the arguments which are relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget ();
- if (this.x == x && this.y == y) return;
- this.x = x;
- this.y = y;
- if (tip.getVisible ()) configure ();
-}
-
-/**
- * Sets the location of the receiver, which must be a tooltip,
- * to the point specified by the argument which is relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p><p>
- * Note that the platform window manager ultimately has control
- * over the location of tooltips.
- * </p>
- *
- * @param location the new location for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (Point location) {
- checkWidget ();
- if (location == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-/**
- * Sets the receiver's message.
- *
- * @param string the new message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMessage (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (layoutMessage != null) layoutMessage.dispose();
- layoutMessage = null;
- if (string.length () != 0) {
- Display display = getDisplay ();
- layoutMessage = new TextLayout (display);
- layoutMessage.setText (string);
- }
- if (tip.getVisible ()) configure ();
-}
-
-/**
- * Sets the receiver's text.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (layoutText != null) layoutText.dispose ();
- layoutText = null;
- if (boldFont != null) boldFont.dispose ();
- boldFont = null;
- if (string.length () != 0) {
- Display display = getDisplay ();
- layoutText = new TextLayout (display);
- layoutText.setText (string);
- Font font = display.getSystemFont ();
- FontData data = font.getFontData () [0];
- boldFont = new Font (display, data.getName (), data.getHeight (), SWT.BOLD);
- TextStyle style = new TextStyle (boldFont, null, null);
- layoutText.setStyle (style, 0, string.length ());
- }
- if (tip.getVisible ()) configure ();
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- if (visible) configure ();
- tip.setVisible (visible);
- Display display = getDisplay ();
- if (runnable != null) display.timerExec (-1, runnable);
- runnable = null;
- if (autohide && visible) {
- runnable = new Runnable () {
- public void run () {
- if (!isDisposed ()) setVisible (false);
- }
- };
- display.timerExec(DELAY, runnable);
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/tray/org/eclipse/swt/widgets/TrayItem.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/tray/org/eclipse/swt/widgets/TrayItem.java
deleted file mode 100644
index 07044a454b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/tray/org/eclipse/swt/widgets/TrayItem.java
+++ /dev/null
@@ -1,350 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent icons that can be placed on the
- * system tray or task bar status area.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, MenuDetect, Selection</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tray">Tray, TrayItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.0
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TrayItem extends Item {
- Tray parent;
- ToolTip toolTip;
- String toolTipText;
- boolean visible = true;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tray</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TrayItem (Tray parent, int style) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the platform-specific context menu trigger
- * has occurred, by sending it one of the messages defined in
- * the <code>MenuDetectListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #removeMenuDetectListener
- *
- * @since 3.3
- */
-public void addMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the receiver is selected
- * <code>widgetDefaultSelected</code> is called when the receiver is double-clicked
- * </p>
- *
- * @param listener the listener which should be notified when the receiver is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-Point getLocation () {
- return display.getCursorLocation ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Tray</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Tray getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's tool tip, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public ToolTip getToolTip () {
- checkWidget ();
- return toolTip;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and
- * <code>false</code> otherwise.
- *
- * @return the receiver's visibility
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- return visible;
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the platform-specific context menu trigger has
- * occurred.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #addMenuDetectListener
- *
- * @since 3.3
- */
-public void removeMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
-}
-
-/**
- * Sets the receiver's image.
- *
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- super.setImage (image);
-}
-
-/**
- * Sets the receiver's tool tip to the argument, which
- * may be null indicating that no tool tip should be shown.
- *
- * @param toolTip the new tool tip (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setToolTip (ToolTip toolTip) {
- checkWidget ();
- ToolTip oldTip = this.toolTip, newTip = toolTip;
- if (oldTip != null) oldTip.item = null;
- this.toolTip = newTip;
- if (newTip != null) newTip.item = this;
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget ();
- toolTipText = string;
-}
-
-/**
- * Makes the receiver visible if the argument is <code>true</code>,
- * and makes it invisible otherwise.
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- if (this.visible == visible) return;
- if (visible) sendEvent (SWT.Show);
- this.visible = visible;
- if (!visible) sendEvent (SWT.Hide);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Table.java
deleted file mode 100644
index af445fdd61..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Table.java
+++ /dev/null
@@ -1,4166 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.*;
-
-/**
- * Instances of this class implement a selectable user interface
- * object that displays a list of images and strings and issues
- * notification when selected.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TableItem</code>.
- * </p><p>
- * Style <code>VIRTUAL</code> is used to create a <code>Table</code> whose
- * <code>TableItem</code>s are to be populated by the client on an on-demand basis
- * instead of up-front. This can provide significant performance improvements for
- * tables that are very large or for which <code>TableItem</code> population is
- * expensive (for example, retrieving values from an external source).
- * </p><p>
- * Here is an example of using a <code>Table</code> with style <code>VIRTUAL</code>:
- * <code><pre>
- * final Table table = new Table (parent, SWT.VIRTUAL | SWT.BORDER);
- * table.setItemCount (1000000);
- * table.addListener (SWT.SetData, new Listener () {
- * public void handleEvent (Event event) {
- * TableItem item = (TableItem) event.item;
- * int index = table.indexOf (item);
- * item.setText ("Item " + index);
- * System.out.println (item.getText ());
- * }
- * });
- * </pre></code>
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not normally make sense to add <code>Control</code> children to
- * it, or set a layout on it, unless implementing something like a cell
- * editor.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, HIDE_SELECTION, VIRTUAL, NO_SCROLL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection, SetData, MeasureItem, EraseItem, PaintItem</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles SINGLE, and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Table extends Composite {
- Canvas header;
- TableColumn[] columns = new TableColumn [0];
- TableColumn[] orderedColumns;
- TableItem[] items = new TableItem [0];
- TableItem[] selectedItems = new TableItem [0];
- TableItem focusItem, anchorItem, lastClickedItem;
- Event lastSelectionEvent;
- boolean linesVisible, ignoreKey, ignoreDispose, customHeightSet;
- int itemsCount = 0;
- int topIndex = 0, horizontalOffset = 0;
- int fontHeight = 0, imageHeight = 0, itemHeight = 0;
- int col0ImageWidth = 0;
- int headerImageHeight = 0;
- TableColumn resizeColumn;
- int resizeColumnX = -1;
- int drawCount = 0;
- TableColumn sortColumn;
- int sortDirection = SWT.NONE;
-
- /* column header tooltip */
- Listener toolTipListener;
- Shell toolTipShell;
- Label toolTipLabel;
-
- Rectangle arrowBounds, checkboxBounds, clientArea;
-
- static final int MARGIN_IMAGE = 3;
- static final int MARGIN_CELL = 1;
- static final int SIZE_HORIZONTALSCROLL = 5;
- static final int TOLLERANCE_COLUMNRESIZE = 2;
- static final int WIDTH_HEADER_SHADOW = 2;
- static final int WIDTH_CELL_HIGHLIGHT = 1;
- static final int [] toolTipEvents = new int[] {SWT.MouseExit, SWT.MouseHover, SWT.MouseMove, SWT.MouseDown};
- static final String ELLIPSIS = "..."; //$NON-NLS-1$
- static final String ID_UNCHECKED = "UNCHECKED"; //$NON-NLS-1$
- static final String ID_GRAYUNCHECKED = "GRAYUNCHECKED"; //$NON-NLS-1$
- static final String ID_CHECKMARK = "CHECKMARK"; //$NON-NLS-1$
- static final String ID_ARROWUP = "ARROWUP"; //$NON-NLS-1$
- static final String ID_ARROWDOWN = "ARROWDOWN"; //$NON-NLS-1$
-
-//TEMPORARY CODE
-boolean hasFocus;
-public boolean isFocusControl() {
- return hasFocus;
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#CHECK
- * @see SWT#FULL_SELECTION
- * @see SWT#HIDE_SELECTION
- * @see SWT#VIRTUAL
- * @see SWT#NO_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Table (Composite parent, int style) {
- super (parent, checkStyle (style));
- setForeground (null); /* set foreground and background to chosen default colors */
- setBackground (null);
- GC gc = new GC (this);
- fontHeight = gc.getFontMetrics ().getHeight ();
- gc.dispose ();
- itemHeight = fontHeight + (2 * getCellPadding ());
- initImages (display);
- checkboxBounds = getUncheckedImage ().getBounds ();
- arrowBounds = getArrowDownImage ().getBounds ();
- clientArea = getClientArea ();
-
- Listener listener = new Listener () {
- public void handleEvent (Event event) {
- handleEvents (event);
- }
- };
- addListener (SWT.Paint, listener);
- addListener (SWT.MouseDown, listener);
- addListener (SWT.MouseUp, listener);
- addListener (SWT.MouseDoubleClick, listener);
- addListener (SWT.Dispose, listener);
- addListener (SWT.Resize, listener);
- addListener (SWT.KeyDown, listener);
- addListener (SWT.FocusOut, listener);
- addListener (SWT.FocusIn, listener);
- addListener (SWT.Traverse, listener);
-
- header = new Canvas (this, SWT.NO_REDRAW_RESIZE | SWT.NO_FOCUS);
- header.setVisible (false);
- header.setBounds (0, 0, 0, fontHeight + 2 * getHeaderPadding ());
- header.addListener (SWT.Paint, listener);
- header.addListener (SWT.MouseDown, listener);
- header.addListener (SWT.MouseUp, listener);
- header.addListener (SWT.MouseHover, listener);
- header.addListener (SWT.MouseDoubleClick, listener);
- header.addListener (SWT.MouseMove, listener);
- header.addListener (SWT.MouseExit, listener);
- header.addListener (SWT.MenuDetect, listener);
-
- toolTipListener = new Listener () {
- public void handleEvent (Event event) {
- switch (event.type) {
- case SWT.MouseHover:
- case SWT.MouseMove:
- if (headerUpdateToolTip (event.x)) break;
- // FALL THROUGH
- case SWT.MouseExit:
- case SWT.MouseDown:
- headerHideToolTip ();
- break;
- }
- }
- };
-
- ScrollBar hBar = getHorizontalBar ();
- if (hBar != null) {
- hBar.setValues (0, 0, 1, 1, 1, 1);
- hBar.setVisible (false);
- hBar.addListener (SWT.Selection, listener);
- }
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) {
- vBar.setValues (0, 0, 1, 1, 1, 1);
- vBar.setVisible (false);
- vBar.addListener (SWT.Selection, listener);
- }
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * If the receiver has the <code>SWT.CHECK</code> style and the check selection changes,
- * the event object detail field contains the value <code>SWT.CHECK</code>.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * The item field of the event object is valid for default selection, but the detail field is not used.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-boolean checkData (TableItem item, boolean redraw) {
- if (item.cached) return true;
- if ((style & SWT.VIRTUAL) != 0) {
- item.cached = true;
- Event event = new Event ();
- event.item = item;
- event.index = indexOf (item);
- sendEvent (SWT.SetData, event);
- if (isDisposed () || item.isDisposed ()) return false;
- if (redraw) redrawItem (item.index, false);
- }
- return true;
-}
-static int checkStyle (int style) {
- /*
- * Feature in Windows. Even when WS_HSCROLL or
- * WS_VSCROLL is not specified, Windows creates
- * trees and tables with scroll bars. The fix
- * is to set H_SCROLL and V_SCROLL.
- *
- * NOTE: This code appears on all platforms so that
- * applications have consistent scroll bar behavior.
- */
- if ((style & SWT.NO_SCROLL) == 0) {
- style |= SWT.H_SCROLL | SWT.V_SCROLL;
- }
- style |= SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED;
- //TEMPORARY CODE
- style |= SWT.FULL_SELECTION;
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-/**
- * Clears the item at the given zero-relative index in the receiver.
- * The text, icon and other attributes of the item are set to the default
- * value. If the table was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param index the index of the item to clear
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clear (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemsCount)) error (SWT.ERROR_INVALID_RANGE);
- Rectangle bounds = items [index].getBounds (false);
- int oldRightX = bounds.x + bounds.width;
- items [index].clear ();
- if (columns.length == 0) updateHorizontalBar (0, -oldRightX);
- redrawItem (index, false);
-}
-/**
- * Removes the items from the receiver which are between the given
- * zero-relative start and end indices (inclusive). The text, icon
- * and other attributes of the items are set to their default values.
- * If the table was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param start the start index of the item to clear
- * @param end the end index of the item to clear
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clear (int start, int end) {
- checkWidget ();
- if (start > end) return;
- if (!(0 <= start && start <= end && end < itemsCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- for (int i = start; i <= end; i++) {
- items [i].clear ();
- }
- updateHorizontalBar ();
- redrawItems (start, end, false);
-}
-/**
- * Clears the items at the given zero-relative indices in the receiver.
- * The text, icon and other attributes of the items are set to their default
- * values. If the table was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clear (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- for (int i = 0; i < indices.length; i++) {
- if (!(0 <= indices [i] && indices [i] < itemsCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- }
-
- for (int i = 0; i < indices.length; i++) {
- items [indices [i]].clear ();
- }
- updateHorizontalBar ();
- for (int i = 0; i < indices.length; i++) {
- redrawItem (indices [i], false);
- }
-}
-/**
- * Clears all the items in the receiver. The text, icon and other
- * attributes of the items are set to their default values. If the
- * table was created with the <code>SWT.VIRTUAL</code> style, these
- * attributes are requested again as needed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clearAll () {
- checkWidget ();
- clear (0, itemsCount - 1);
-}
-/*
- * Returns the ORDERED index of the column that the specified x falls within,
- * or -1 if the x lies to the right of the last column.
- */
-int computeColumnIntersect (int x, int startColumn) {
- TableColumn[] orderedColumns = getOrderedColumns ();
- if (orderedColumns.length - 1 < startColumn) return -1;
- int rightX = orderedColumns [startColumn].getX ();
- for (int i = startColumn; i < orderedColumns.length; i++) {
- rightX += orderedColumns [i].width;
- if (x < rightX) return i;
- }
- return -1;
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0;
- if (wHint != SWT.DEFAULT) {
- width = wHint;
- } else {
- if (columns.length == 0) {
- for (int i = 0; i < itemsCount; i++) {
- Rectangle itemBounds = items [i].getBounds (false);
- width = Math.max (width, itemBounds.x + itemBounds.width);
- }
- } else {
- TableColumn[] orderedColumns = getOrderedColumns ();
- TableColumn lastColumn = orderedColumns [orderedColumns.length - 1];
- width = lastColumn.getX () + lastColumn.width;
- }
- }
- if (hHint != SWT.DEFAULT) {
- height = hHint;
- } else {
- height = getHeaderHeight () + itemsCount * itemHeight;
- }
- Rectangle result = computeTrim (0, 0, width, height);
- return new Point (result.width, result.height);
-}
-void createItem (TableColumn column, int index) {
- TableColumn[] newColumns = new TableColumn [columns.length + 1];
- System.arraycopy (columns, 0, newColumns, 0, index);
- newColumns [index] = column;
- System.arraycopy (columns, index, newColumns, index + 1, columns.length - index);
- columns = newColumns;
-
- if (orderedColumns != null) {
- int insertIndex = 0;
- if (index > 0) {
- insertIndex = columns [index - 1].getOrderIndex () + 1;
- }
- TableColumn[] newOrderedColumns = new TableColumn [orderedColumns.length + 1];
- System.arraycopy (orderedColumns, 0, newOrderedColumns, 0, insertIndex);
- newOrderedColumns [insertIndex] = column;
- System.arraycopy (
- orderedColumns,
- insertIndex,
- newOrderedColumns,
- insertIndex + 1,
- orderedColumns.length - insertIndex);
- orderedColumns = newOrderedColumns;
- }
-
- /* allow all items to update their internal structures accordingly */
- for (int i = 0; i < itemsCount; i++) {
- items [i].addColumn (column);
- }
-
- /* existing items become hidden when going from 0 to 1 column (0 width) */
- if (columns.length == 1 && itemsCount > 0) {
- redrawFromItemDownwards (topIndex);
- } else {
- /* checkboxes become hidden when creating a column with index == orderedIndex == 0 (0 width) */
- if (itemsCount > 0 && (style & SWT.CHECK) != 0 && index == 0 && column.getOrderIndex () == 0) {
- redrawFromItemDownwards (topIndex);
- }
- }
-}
-void createItem (TableItem item) {
- int index = item.index;
- if (itemsCount == items.length) {
- int grow = drawCount <= 0 ? 4 : Math.max (4, items.length * 3 / 2);
- TableItem[] newItems = new TableItem [items.length + grow];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- if (index != itemsCount) {
- /* new item is not at end of list, so shift other items right to create space for it */
- System.arraycopy (items, index, items, index + 1, itemsCount - index);
- }
- items [index] = item;
- itemsCount++;
-
- /* update the index for items bumped down by this new item */
- for (int i = index + 1; i < itemsCount; i++) {
- items [i].index = i;
- }
-
- /* update scrollbars */
- updateVerticalBar ();
- Rectangle bounds = item.getBounds (false);
- int rightX = bounds.x + bounds.width;
- updateHorizontalBar (rightX, rightX);
- /*
- * If new item is above viewport then adjust topIndex and the vertical
- * scrollbar so that the current viewport items will not change.
- */
- if (item.index < topIndex) {
- topIndex++;
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) vBar.setSelection (topIndex);
- return;
- }
- /*
- * If this is the first item and the receiver has focus then its boundary
- * focus ring must be removed.
- */
- if (itemsCount == 1 && isFocusControl ()) {
- focusItem = item;
- redraw ();
- return;
- }
- if (item.isInViewport ()) {
- redrawFromItemDownwards (index);
- }
-}
-/**
- * Deselects the item at the given zero-relative index in the receiver.
- * If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemsCount)) return;
- TableItem item = items [index];
- int selectIndex = getSelectionIndex (item);
- if (selectIndex == -1) return;
-
- TableItem[] newSelectedItems = new TableItem [selectedItems.length - 1];
- System.arraycopy (selectedItems, 0, newSelectedItems, 0, selectIndex);
- System.arraycopy (selectedItems, selectIndex + 1, newSelectedItems, selectIndex, newSelectedItems.length - selectIndex);
- selectedItems = newSelectedItems;
-
- if (hasFocus () || (style & SWT.HIDE_SELECTION) == 0) {
- redrawItem (item.index, false);
- }
-}
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. The range of the
- * indices is inclusive. Indices that are out of range are ignored.
- *
- * @param start the start index of the items to deselect
- * @param end the end index of the items to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int start, int end) {
- checkWidget ();
- if (start == 0 && end == itemsCount - 1) {
- deselectAll ();
- } else {
- start = Math.max (start, 0);
- end = Math.min (end, itemsCount - 1);
- for (int i = start; i <= end; i++) {
- deselect (i);
- }
- }
-}
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. Indices that are out
- * of range and duplicate indices are ignored.
- *
- * @param indices the array of indices for the items to deselect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- for (int i = 0; i < indices.length; i++) {
- deselect (indices [i]);
- }
-}
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll () {
- checkWidget ();
- TableItem[] oldSelection = selectedItems;
- selectedItems = new TableItem [0];
- if (hasFocus () || (style & SWT.HIDE_SELECTION) == 0) {
- for (int i = 0; i < oldSelection.length; i++) {
- redrawItem (oldSelection [i].index, true);
- }
- }
-}
-void deselectItem (TableItem item) {
- int index = getSelectionIndex (item);
- if (index == -1) return;
- TableItem[] newSelectedItems = new TableItem [selectedItems.length - 1];
- System.arraycopy (selectedItems, 0, newSelectedItems, 0, index);
- System.arraycopy (
- selectedItems,
- index + 1,
- newSelectedItems,
- index,
- newSelectedItems.length - index);
- selectedItems = newSelectedItems;
-}
-void destroyItem (TableColumn column) {
- headerHideToolTip ();
- int index = column.getIndex ();
- int orderedIndex = column.getOrderIndex ();
-
- TableColumn[] newColumns = new TableColumn [columns.length - 1];
- System.arraycopy (columns, 0, newColumns, 0, index);
- System.arraycopy (columns, index + 1, newColumns, index, newColumns.length - index);
- columns = newColumns;
-
- if (orderedColumns != null) {
- if (columns.length < 2) {
- orderedColumns = null;
- } else {
- int removeIndex = column.getOrderIndex ();
- TableColumn[] newOrderedColumns = new TableColumn [orderedColumns.length - 1];
- System.arraycopy (orderedColumns, 0, newOrderedColumns, 0, removeIndex);
- System.arraycopy (
- orderedColumns,
- removeIndex + 1,
- newOrderedColumns,
- removeIndex,
- newOrderedColumns.length - removeIndex);
- orderedColumns = newOrderedColumns;
- }
- }
-
- /* ensure that column 0 always has left-alignment */
- if (index == 0 && columns.length > 0) {
- columns [0].style |= SWT.LEFT;
- columns [0].style &= ~(SWT.CENTER | SWT.RIGHT);
- }
-
- /* allow all items to update their internal structures accordingly */
- for (int i = 0; i < itemsCount; i++) {
- items [i].removeColumn (column, index);
- }
-
- /* update horizontal scrollbar */
- int lastColumnIndex = columns.length - 1;
- if (lastColumnIndex < 0) { /* no more columns */
- updateHorizontalBar ();
- } else {
- int newWidth = 0;
- for (int i = 0; i < columns.length; i++) {
- newWidth += columns [i].width;
- }
- ScrollBar hBar = getHorizontalBar ();
- if (hBar != null) {
- hBar.setMaximum (newWidth);
- hBar.setVisible (clientArea.width < newWidth);
- }
- int selection = hBar.getSelection ();
- if (selection != horizontalOffset) {
- horizontalOffset = selection;
- redraw ();
- if (header.isVisible () && drawCount <= 0) header.redraw ();
- }
- }
- TableColumn[] orderedColumns = getOrderedColumns ();
- for (int i = orderedIndex; i < orderedColumns.length; i++) {
- if (!orderedColumns [i].isDisposed ()) {
- orderedColumns [i].sendEvent (SWT.Move);
- }
- }
-
- if (sortColumn == column) {
- sortColumn = null;
- }
-}
-/*
- * Allows the Table to update internal structures it has that may contain the
- * item being destroyed.
- */
-void destroyItem (TableItem item) {
- if (item == focusItem) reassignFocus ();
-
- int index = item.index;
- Rectangle bounds = item.getBounds (false);
- int rightX = bounds.x + bounds.width;
-
- if (index != itemsCount - 1) {
- /* item is not at end of items list, so must shift items left to reclaim its slot */
- System.arraycopy (items, index + 1, items, index, itemsCount - index - 1);
- items [itemsCount - 1] = null;
- } else {
- items [index] = null; /* last item, so no array copy needed */
- }
- itemsCount--;
-
- if (drawCount <= 0 && items.length - itemsCount == 4) {
- /* shrink the items array */
- TableItem[] newItems = new TableItem [itemsCount];
- System.arraycopy (items, 0, newItems, 0, newItems.length);
- items = newItems;
- }
-
- /* update the index on affected items */
- for (int i = index; i < itemsCount; i++) {
- items [i].index = i;
- }
- item.index = -1;
-
- int oldTopIndex = topIndex;
- updateVerticalBar ();
- updateHorizontalBar (0, -rightX);
- /*
- * If destroyed item is above viewport then adjust topIndex and the vertical
- * scrollbar so that the current viewport items will not change.
- */
- if (index < topIndex) {
- topIndex = oldTopIndex - 1;
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) vBar.setSelection (topIndex);
- }
-
- /* selectedItems array */
- if (item.isSelected ()) {
- int selectionIndex = getSelectionIndex (item);
- TableItem[] newSelectedItems = new TableItem [selectedItems.length - 1];
- System.arraycopy (selectedItems, 0, newSelectedItems, 0, selectionIndex);
- System.arraycopy (
- selectedItems,
- selectionIndex + 1,
- newSelectedItems,
- selectionIndex,
- newSelectedItems.length - selectionIndex);
- selectedItems = newSelectedItems;
- }
- if (item == anchorItem) anchorItem = null;
- if (item == lastClickedItem) lastClickedItem = null;
- /*
- * If this was the last item and the receiver has focus then its boundary
- * focus ring must be redrawn.
- */
- if (itemsCount == 0 && isFocusControl ()) {
- redraw ();
- return;
- }
-}
-Image getArrowDownImage () {
- return (Image) display.getData (ID_ARROWDOWN);
-}
-Image getArrowUpImage () {
- return (Image) display.getData (ID_ARROWUP);
-}
-int getCellPadding () {
- return MARGIN_CELL + WIDTH_CELL_HIGHLIGHT;
-}
-Image getCheckmarkImage () {
- return (Image) display.getData (ID_CHECKMARK);
-}
-public Control[] getChildren () {
- checkWidget ();
- Control[] controls = _getChildren ();
- if (header == null) return controls;
- Control[] result = new Control [controls.length - 1];
- /* remove the Header from the returned set of children */
- int index = 0;
- for (int i = 0; i < controls.length; i++) {
- if (controls [i] != header) {
- result [index++] = controls [i];
- }
- }
- return result;
-}
-/**
- * Returns the column at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- * Columns are returned in the order that they were created.
- * If no <code>TableColumn</code>s were created by the programmer,
- * this method will throw <code>ERROR_INVALID_RANGE</code> despite
- * the fact that a single column of data may be visible in the table.
- * This occurs when the programmer uses the table like a list, adding
- * items but never creating a column.
- *
- * @param index the index of the column to return
- * @return the column at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- */
-public TableColumn getColumn (int index) {
- checkWidget ();
- if (!(0 <= index && index < columns.length)) error (SWT.ERROR_INVALID_RANGE);
- return columns [index];
-}
-/**
- * Returns the number of columns contained in the receiver.
- * If no <code>TableColumn</code>s were created by the programmer,
- * this value is zero, despite the fact that visually, one column
- * of items may be visible. This occurs when the programmer uses
- * the table like a list, adding items but never creating a column.
- *
- * @return the number of columns
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getColumnCount () {
- checkWidget ();
- return columns.length;
-}
-/**
- * Returns an array of zero-relative integers that map
- * the creation order of the receiver's items to the
- * order in which they are currently being displayed.
- * <p>
- * Specifically, the indices of the returned array represent
- * the current visual order of the items, and the contents
- * of the array represent the creation order of the items.
- * </p><p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the current visual order of the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public int[] getColumnOrder () {
- checkWidget ();
- int[] result = new int [columns.length];
- if (orderedColumns != null) {
- for (int i = 0; i < result.length; i++) {
- result [i] = orderedColumns [i].getIndex ();
- }
- } else {
- for (int i = 0; i < columns.length; i++) {
- result [i] = i;
- }
- }
- return result;
-}
-/**
- * Returns an array of <code>TableColumn</code>s which are the
- * columns in the receiver. Columns are returned in the order
- * that they were created. If no <code>TableColumn</code>s were
- * created by the programmer, the array is empty, despite the fact
- * that visually, one column of items may be visible. This occurs
- * when the programmer uses the table like a list, adding items but
- * never creating a column.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- */
-public TableColumn[] getColumns () {
- checkWidget ();
- TableColumn[] result = new TableColumn [columns.length];
- System.arraycopy (columns, 0, result, 0, columns.length);
- return result;
-}
-Image getGrayUncheckedImage () {
- return (Image) display.getData (ID_GRAYUNCHECKED);
-}
-/**
- * Returns the width in pixels of a grid line.
- *
- * @return the width of a grid line in pixels
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getGridLineWidth () {
- checkWidget ();
- return 1;
-}
-/**
- * Returns the height of the receiver's header
- *
- * @return the height of the header or zero if the header is not visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public int getHeaderHeight () {
- checkWidget ();
- if (!header.getVisible ()) return 0;
- return header.getSize ().y;
-}
-int getHeaderPadding () {
- return MARGIN_CELL + WIDTH_HEADER_SHADOW;
-}
-/**
- * Returns <code>true</code> if the receiver's header is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's header's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getHeaderVisible () {
- checkWidget ();
- return header.getVisible ();
-}
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem getItem (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemsCount)) error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- * <p>
- * The item that is returned represents an item that could be selected by the user.
- * For example, if selection only occurs in items in the first column, then null is
- * returned if the point is outside of the item.
- * Note that the SWT.FULL_SELECTION style hint, which specifies the selection policy,
- * determines the extent of the selection.
- * </p>
- *
- * @param point the point used to locate the item
- * @return the item at the given point, or null if the point is not in a selectable item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem getItem (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = (point.y - getHeaderHeight ()) / itemHeight + topIndex;
- if (!(0 <= index && index < itemsCount)) return null; /* below the last item */
- TableItem result = items [index];
- if (!result.getHitBounds ().contains (point)) return null; /* considers the x value */
- return result;
-}
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return itemsCount;
-}
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the receiver.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- return itemHeight;
-}
-/**
- * Returns a (possibly empty) array of <code>TableItem</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem[] getItems () {
- checkWidget ();
- TableItem[] result = new TableItem [itemsCount];
- System.arraycopy (items, 0, result, 0, itemsCount);
- return result;
-}
-/*
- * Returns the current y-coordinate that the specified item should have.
- */
-int getItemY (TableItem item) {
- return (item.index - topIndex) * itemHeight + getHeaderHeight ();
-}
-/**
- * Returns <code>true</code> if the receiver's lines are visible,
- * and <code>false</code> otherwise. Note that some platforms draw
- * grid lines while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the visibility state of the lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getLinesVisible () {
- checkWidget ();
- return linesVisible;
-}
-TableColumn[] getOrderedColumns () {
- if (orderedColumns != null) return orderedColumns;
- return columns;
-}
-/**
- * Returns an array of <code>TableItem</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem[] getSelection () {
- checkWidget ();
- TableItem[] result = new TableItem [selectedItems.length];
- System.arraycopy (selectedItems, 0, result, 0, selectedItems.length);
- sortAscent (result);
- return result;
-}
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget ();
- return selectedItems.length;
-}
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget ();
- if (selectedItems.length == 0) return -1;
- return selectedItems [0].index;
-}
-/*
- * Returns the index of the argument in the receiver's array of currently-
- * selected items, or -1 if the item is not currently selected.
- */
-int getSelectionIndex (TableItem item) {
- for (int i = 0; i < selectedItems.length; i++) {
- if (selectedItems [i] == item) return i;
- }
- return -1;
-}
-/**
- * Returns the zero-relative indices of the items which are currently
- * selected in the receiver. The order of the indices is unspecified.
- * The array is empty if no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return the array of indices of the selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int [] getSelectionIndices () {
- checkWidget ();
- int[] result = new int [selectedItems.length];
- for (int i = 0; i < selectedItems.length; i++) {
- result [i] = selectedItems [i].index;
- }
- sortAscent (result);
- return result;
-}
-/**
- * Returns the column which shows the sort indicator for
- * the receiver. The value may be null if no column shows
- * the sort indicator.
- *
- * @return the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortColumn(TableColumn)
- *
- * @since 3.2
- */
-public TableColumn getSortColumn () {
- checkWidget ();
- return sortColumn;
-}
-/**
- * Returns the direction of the sort indicator for the receiver.
- * The value will be one of <code>UP</code>, <code>DOWN</code>
- * or <code>NONE</code>.
- *
- * @return the sort direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortDirection(int)
- *
- * @since 3.2
- */
-public int getSortDirection () {
- checkWidget ();
- return sortDirection;
-}
-/**
- * Returns the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items are
- * scrolled or new items are added or removed.
- *
- * @return the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget ();
- return topIndex;
-}
-Image getUncheckedImage () {
- return (Image) display.getData (ID_UNCHECKED);
-}
-void handleEvents (Event event) {
- switch (event.type) {
- case SWT.Paint:
- if (event.widget == header) {
- headerOnPaint (event);
- } else {
- onPaint (event);
- }
- break;
- case SWT.MenuDetect: {
- notifyListeners (SWT.MenuDetect, event);
- break;
- }
- case SWT.MouseDown:
- if (event.widget == header) {
- headerOnMouseDown (event);
- } else {
- onMouseDown (event);
- }
- break;
- case SWT.MouseUp:
- if (event.widget == header) {
- headerOnMouseUp (event);
- } else {
- onMouseUp (event);
- }
- break;
- case SWT.MouseHover:
- headerOnMouseHover (event); break;
- case SWT.MouseMove:
- headerOnMouseMove (event); break;
- case SWT.MouseDoubleClick:
- if (event.widget == header) {
- headerOnMouseDoubleClick (event);
- } else {
- onMouseDoubleClick (event);
- }
- break;
- case SWT.MouseExit:
- headerOnMouseExit (); break;
- case SWT.Dispose:
- onDispose (event); break;
- case SWT.KeyDown:
- onKeyDown (event); break;
- case SWT.Resize:
- onResize (event); break;
- case SWT.Selection:
- if (event.widget == getHorizontalBar ()) {
- onScrollHorizontal (event);
- }
- if (event.widget == getVerticalBar ()) {
- onScrollVertical (event);
- }
- break;
- case SWT.FocusOut:
- onFocusOut (); break;
- case SWT.FocusIn:
- onFocusIn (); break;
- case SWT.Traverse:
- switch (event.detail) {
- case SWT.TRAVERSE_ESCAPE:
- case SWT.TRAVERSE_RETURN:
- case SWT.TRAVERSE_TAB_NEXT:
- case SWT.TRAVERSE_TAB_PREVIOUS:
- case SWT.TRAVERSE_PAGE_NEXT:
- case SWT.TRAVERSE_PAGE_PREVIOUS:
- event.doit = true;
- break;
- }
- break;
- }
-}
-String headerGetToolTip (int x) {
- if (resizeColumn != null) return null;
- int orderedIndex = computeColumnIntersect (x, 0);
- if (orderedIndex == -1) return null;
- TableColumn[] orderedColumns = getOrderedColumns ();
- TableColumn column = orderedColumns [orderedIndex];
- if (column.toolTipText == null) return null;
-
- /* no tooltip should appear if the hover is at a column resize opportunity */
- int columnX = column.getX ();
- if (orderedIndex > 0 && orderedColumns [orderedIndex - 1].resizable) {
- /* left column bound is resizable */
- if (x - columnX <= TOLLERANCE_COLUMNRESIZE) return null;
- }
- if (column.resizable) {
- /* right column bound is resizable */
- int columnRightX = columnX + column.width;
- if (columnRightX - x <= TOLLERANCE_COLUMNRESIZE) return null;
- }
- return removeMnemonics (column.toolTipText);
-}
-void headerHideToolTip() {
- if (toolTipShell == null) return;
- for (int i = 0; i < toolTipEvents.length; i++) {
- header.removeListener (toolTipEvents [i], toolTipListener);
- }
- toolTipShell.dispose ();
- toolTipShell = null;
- toolTipLabel = null;
-}
-void headerOnMouseDoubleClick (Event event) {
- if (!isFocusControl ()) setFocus ();
- if (columns.length == 0) return;
- TableColumn[] orderedColumns = getOrderedColumns ();
- int x = -horizontalOffset;
- for (int i = 0; i < orderedColumns.length; i++) {
- TableColumn column = orderedColumns [i];
- x += column.width;
- if (event.x < x) {
- /* found the clicked column */
- TableColumn packColumn = null;
- if (x - event.x <= TOLLERANCE_COLUMNRESIZE) {
- /* clicked on column bound for this column */
- packColumn = column;
- } else {
- if (i > 0 && event.x - column.getX () <= TOLLERANCE_COLUMNRESIZE) {
- /* clicked on column bound that applies to previous column */
- packColumn = orderedColumns [i - 1];
- }
- }
- if (packColumn != null) {
- packColumn.pack ();
- resizeColumn = null;
- if (Math.abs (packColumn.getX () + packColumn.width - event.x) > TOLLERANCE_COLUMNRESIZE) {
- /* column separator has relocated away from pointer location */
- setCursor (null);
- }
- return;
- }
- /* did not click on column separator, so just fire column event */
- Event newEvent = new Event ();
- newEvent.widget = column;
- column.postEvent (SWT.DefaultSelection, newEvent);
- return;
- }
- }
-}
-void headerOnMouseDown (Event event) {
- if (event.button != 1) return;
- TableColumn[] orderedColumns = getOrderedColumns ();
- int x = -horizontalOffset;
- for (int i = 0; i < orderedColumns.length; i++) {
- TableColumn column = orderedColumns [i];
- x += column.width;
- /* if close to a resizable column separator line then begin column resize */
- if (column.resizable && Math.abs (x - event.x) <= TOLLERANCE_COLUMNRESIZE) {
- resizeColumn = column;
- resizeColumnX = x;
- return;
- }
- /*
- * If within column but not near separator line then start column drag
- * if column is moveable, or just fire column Selection otherwise.
- */
- if (event.x < x) {
- if (column.moveable) {
- /* open tracker on the dragged column's header cell */
- int columnX = column.getX ();
- int pointerOffset = event.x - columnX;
- headerHideToolTip ();
- Tracker tracker = new Tracker (this, SWT.NONE);
- tracker.setRectangles (new Rectangle[] {
- new Rectangle (columnX, 0, column.width, getHeaderHeight ())
- });
- if (!tracker.open ()) return; /* cancelled */
- /* determine which column was dragged onto */
- Rectangle result = tracker.getRectangles () [0];
- int pointerX = result.x + pointerOffset;
- if (pointerX < 0) return; /* dragged too far left */
- x = -horizontalOffset;
- for (int destIndex = 0; destIndex < orderedColumns.length; destIndex++) {
- TableColumn destColumn = orderedColumns [destIndex];
- x += destColumn.width;
- if (pointerX < x) {
- int oldIndex = column.getOrderIndex ();
- if (destIndex == oldIndex) { /* dragged onto self */
- Event newEvent = new Event ();
- newEvent.widget = column;
- column.postEvent (SWT.Selection, newEvent);
- return;
- }
- int leftmostIndex = Math.min (destIndex, oldIndex);
- int[] oldOrder = getColumnOrder ();
- int[] newOrder = new int [oldOrder.length];
- System.arraycopy (oldOrder, 0, newOrder, 0, leftmostIndex);
- if (leftmostIndex == oldIndex) {
- /* column moving to the right */
- System.arraycopy (oldOrder, oldIndex + 1, newOrder, oldIndex, destIndex - oldIndex);
- } else {
- /* column moving to the left */
- System.arraycopy (oldOrder, destIndex, newOrder, destIndex + 1, oldIndex - destIndex);
- }
- newOrder [destIndex] = oldOrder [oldIndex];
- int rightmostIndex = Math.max (destIndex, oldIndex);
- System.arraycopy (
- oldOrder,
- rightmostIndex + 1,
- newOrder,
- rightmostIndex + 1,
- newOrder.length - rightmostIndex - 1);
- setColumnOrder (newOrder);
- return;
- }
- }
- return; /* dragged too far right */
- }
- /* column is not moveable */
- Event newEvent = new Event ();
- newEvent.widget = column;
- column.postEvent (SWT.Selection, newEvent);
- return;
- }
- }
-}
-void headerOnMouseExit () {
- if (resizeColumn != null) return;
- setCursor (null); /* ensure that a column resize cursor does not escape */
-}
-void headerOnMouseHover (Event event) {
- headerShowToolTip (event.x);
-}
-void headerOnMouseMove (Event event) {
- if (resizeColumn == null) {
- /* not currently resizing a column */
- for (int i = 0; i < columns.length; i++) {
- TableColumn column = columns [i];
- int x = column.getX () + column.width;
- if (Math.abs (x - event.x) <= TOLLERANCE_COLUMNRESIZE) {
- if (column.resizable) {
- setCursor (display.getSystemCursor (SWT.CURSOR_SIZEWE));
- } else {
- setCursor (null);
- }
- return;
- }
- }
- setCursor (null);
- return;
- }
-
- /* currently resizing a column */
-
- /* don't allow the resize x to move left of the column's x position */
- if (event.x <= resizeColumn.getX ()) return;
-
- /* redraw the resizing line at its new location */
- GC gc = new GC (this);
- gc.setForeground (display.getSystemColor (SWT.COLOR_BLACK));
- int lineHeight = clientArea.height;
- redraw (resizeColumnX - 1, 0, 1, lineHeight, false);
- resizeColumnX = event.x;
- gc.drawLine (resizeColumnX - 1, 0, resizeColumnX - 1, lineHeight);
- gc.dispose ();
-}
-void headerOnMouseUp (Event event) {
- if (resizeColumn == null) return; /* not resizing a column */
-
- /* remove the resize line */
- GC gc = new GC (this);
- redraw (resizeColumnX - 1, 0, 1, clientArea.height, false);
- gc.dispose ();
-
- int newWidth = resizeColumnX - resizeColumn.getX ();
- if (newWidth != resizeColumn.width) {
- setCursor (null);
- updateColumnWidth (resizeColumn, newWidth);
- }
- resizeColumnX = -1;
- resizeColumn = null;
-}
-void headerOnPaint (Event event) {
- TableColumn[] orderedColumns = getOrderedColumns ();
- int numColumns = orderedColumns.length;
- GC gc = event.gc;
- Rectangle clipping = gc.getClipping ();
- int startColumn = -1, endColumn = -1;
- if (numColumns > 0) {
- startColumn = computeColumnIntersect (clipping.x, 0);
- if (startColumn != -1) { /* the clip x is within a column's bounds */
- endColumn = computeColumnIntersect (clipping.x + clipping.width, startColumn);
- if (endColumn == -1) endColumn = numColumns - 1;
- }
- } else {
- startColumn = endColumn = 0;
- }
-
- /* paint the column header shadow that spans the full header width */
- Point headerSize = header.getSize ();
- headerPaintHShadows (gc, 0, 0, headerSize.x, headerSize.y);
-
- /* if all damage is to the right of the last column then finished */
- if (startColumn == -1) return;
-
- /* paint each of the column headers */
- if (numColumns == 0) return; /* no headers to paint */
- for (int i = startColumn; i <= endColumn; i++) {
- headerPaintVShadows (gc, orderedColumns [i].getX (), 0, orderedColumns [i].width, headerSize.y);
- orderedColumns [i].paint (gc);
- }
-}
-void headerPaintHShadows (GC gc, int x, int y, int width, int height) {
- gc.setClipping (x, y, width, height);
- int endX = x + width;
- gc.setForeground (display.getSystemColor (SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
- gc.drawLine (x, y, endX, y); /* highlight shadow */
- gc.setForeground (display.getSystemColor (SWT.COLOR_WIDGET_NORMAL_SHADOW));
- gc.drawLine (x, height - 2, endX, height - 2); /* lowlight shadow */
- gc.setForeground (display.getSystemColor (SWT.COLOR_WIDGET_DARK_SHADOW));
- gc.drawLine (x, height - 1, endX, height - 1); /* outer shadow */
-}
-void headerPaintVShadows (GC gc, int x, int y, int width, int height) {
- gc.setClipping (x, y, width, height);
- int endX = x + width;
- gc.setForeground (display.getSystemColor (SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
- gc.drawLine (x, y, x, y + height - 1); /* highlight shadow */
- gc.setForeground (display.getSystemColor (SWT.COLOR_WIDGET_NORMAL_SHADOW));
- gc.drawLine (endX - 2, y + 1, endX - 2, height - 2); /* light inner shadow */
- gc.setForeground (display.getSystemColor (SWT.COLOR_WIDGET_DARK_SHADOW));
- gc.drawLine (endX - 1, y, endX - 1, height - 1); /* dark outer shadow */
-}
-void headerShowToolTip (int x) {
- String tooltip = headerGetToolTip (x);
- if (tooltip == null || tooltip.length () == 0) return;
-
- if (toolTipShell == null) {
- toolTipShell = new Shell (getShell (), SWT.ON_TOP | SWT.TOOL);
- toolTipLabel = new Label (toolTipShell, SWT.CENTER);
- Display display = toolTipShell.getDisplay ();
- toolTipLabel.setForeground (display.getSystemColor (SWT.COLOR_INFO_FOREGROUND));
- toolTipLabel.setBackground (display.getSystemColor (SWT.COLOR_INFO_BACKGROUND));
- for (int i = 0; i < toolTipEvents.length; i++) {
- header.addListener (toolTipEvents [i], toolTipListener);
- }
- }
- if (headerUpdateToolTip (x)) {
- toolTipShell.setVisible (true);
- } else {
- headerHideToolTip ();
- }
-}
-boolean headerUpdateToolTip (int x) {
- String tooltip = headerGetToolTip (x);
- if (tooltip == null || tooltip.length () == 0) return false;
- if (tooltip.equals (toolTipLabel.getText ())) return true;
-
- toolTipLabel.setText (tooltip);
- TableColumn column = getOrderedColumns () [computeColumnIntersect (x, 0)];
- toolTipShell.setData (new Integer (column.getIndex ()));
- Point labelSize = toolTipLabel.computeSize (SWT.DEFAULT, SWT.DEFAULT, true);
- labelSize.x += 2; labelSize.y += 2;
- toolTipLabel.setSize (labelSize);
- toolTipShell.pack ();
- /*
- * On some platforms, there is a minimum size for a shell
- * which may be greater than the label size.
- * To avoid having the background of the tip shell showing
- * around the label, force the label to fill the entire client area.
- */
- Rectangle area = toolTipShell.getClientArea ();
- toolTipLabel.setSize (area.width, area.height);
-
- /* Position the tooltip and ensure it's not located off the screen */
- Point cursorLocation = getDisplay ().getCursorLocation ();
- int cursorHeight = 21; /* assuming cursor is 21x21 */
- Point size = toolTipShell.getSize ();
- Rectangle rect = getMonitor ().getBounds ();
- Point pt = new Point (cursorLocation.x, cursorLocation.y + cursorHeight + 2);
- pt.x = Math.max (pt.x, rect.x);
- if (pt.x + size.x > rect.x + rect.width) pt.x = rect.x + rect.width - size.x;
- if (pt.y + size.y > rect.y + rect.height) pt.y = cursorLocation.y - 2 - size.y;
- toolTipShell.setLocation (pt);
- return true;
-}
-/**
- * Searches the receiver's list starting at the first column
- * (index 0) until a column is found that is equal to the
- * argument, and returns the index of that column. If no column
- * is found, returns -1.
- *
- * @param column the search column
- * @return the index of the column
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the column is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (TableColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (column.parent != this) return -1;
- return column.getIndex ();
-}
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (TableItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.parent != this) return -1;
- return item.index;
-}
-static void initImages (final Display display) {
- PaletteData arrowPalette = new PaletteData (new RGB[] {
- new RGB (0, 0, 0), new RGB (255, 255, 255)});
- if (display.getData (ID_ARROWDOWN) == null) {
- ImageData arrowDown = new ImageData (
- 7, 4, 1,
- arrowPalette, 1,
- new byte[] {0x00, (byte)0x83, (byte)0xC7, (byte)0xEF});
- arrowDown.transparentPixel = 0x1; /* use white for transparency */
- display.setData (ID_ARROWDOWN, new Image (display, arrowDown));
- }
- if (display.getData (ID_ARROWUP) == null) {
- ImageData arrowUp = new ImageData (
- 7, 4, 1,
- arrowPalette, 1,
- new byte[] {(byte)0xEF, (byte)0xC7, (byte)0x83, 0x00});
- arrowUp.transparentPixel = 0x1; /* use white for transparency */
- display.setData (ID_ARROWUP, new Image (display, arrowUp));
- }
-
- PaletteData checkMarkPalette = new PaletteData (
- new RGB[] {new RGB (0, 0, 0), new RGB (252, 3, 251)});
- byte[] checkbox = new byte[] {0, 0, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 0, 0};
- ImageData checkmark = new ImageData (7, 7, 1, checkMarkPalette, 1, new byte[] {-4, -8, 112, 34, 6, -114, -34});
- checkmark.transparentPixel = 1;
- if (display.getData (ID_CHECKMARK) == null) {
- display.setData (ID_CHECKMARK, new Image (display, checkmark));
- }
-
- if (display.getData (ID_UNCHECKED) == null) {
- PaletteData uncheckedPalette = new PaletteData (
- new RGB[] {new RGB (128, 128, 128), new RGB (255, 255, 255)});
- ImageData unchecked = new ImageData (11, 11, 1, uncheckedPalette, 2, checkbox);
- display.setData (ID_UNCHECKED, new Image (display, unchecked));
- }
-
- if (display.getData (ID_GRAYUNCHECKED) == null) {
- PaletteData grayUncheckedPalette = new PaletteData (
- new RGB[] {new RGB (128, 128, 128), new RGB (192, 192, 192)});
- ImageData grayUnchecked = new ImageData (11, 11, 1, grayUncheckedPalette, 2, checkbox);
- display.setData (ID_GRAYUNCHECKED, new Image (display, grayUnchecked));
- }
-
- display.disposeExec (new Runnable () {
- public void run() {
- Image unchecked = (Image) display.getData (ID_UNCHECKED);
- if (unchecked != null) unchecked.dispose ();
- Image grayUnchecked = (Image) display.getData (ID_GRAYUNCHECKED);
- if (grayUnchecked != null) grayUnchecked.dispose ();
- Image checkmark = (Image) display.getData (ID_CHECKMARK);
- if (checkmark != null) checkmark.dispose ();
- Image arrowDown = (Image) display.getData (ID_ARROWDOWN);
- if (arrowDown != null) arrowDown.dispose ();
- Image arrowUp = (Image) display.getData (ID_ARROWUP);
- if (arrowUp != null) arrowUp.dispose ();
-
- display.setData (ID_UNCHECKED, null);
- display.setData (ID_GRAYUNCHECKED, null);
- display.setData (ID_CHECKMARK, null);
- display.setData (ID_ARROWDOWN, null);
- display.setData (ID_ARROWUP, null);
- }
- });
-}
-/**
- * Returns <code>true</code> if the item is selected,
- * and <code>false</code> otherwise. Indices out of
- * range are ignored.
- *
- * @param index the index of the item
- * @return the selection state of the item at the index
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isSelected (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemsCount)) return false;
- return items [index].isSelected ();
-}
-void onArrowDown (int stateMask) {
- if ((stateMask & (SWT.SHIFT | SWT.CTRL)) == 0) {
- /* Down Arrow with no modifiers */
- int newFocusIndex = focusItem.index + 1;
- if (newFocusIndex == itemsCount) return; /* at bottom */
- selectItem (items [newFocusIndex], false);
- setFocusItem (items [newFocusIndex], true);
- redrawItem (newFocusIndex, true);
- showItem (items [newFocusIndex]);
- Event newEvent = new Event ();
- newEvent.item = items [newFocusIndex];
- postEvent (SWT.Selection, newEvent);
- return;
- }
- if ((style & SWT.SINGLE) != 0) {
- if ((stateMask & SWT.CTRL) != 0) {
- /* CTRL+Down Arrow, CTRL+Shift+Down Arrow */
- int visibleItemCount = (clientArea.height - getHeaderHeight ()) / itemHeight;
- if (itemsCount <= topIndex + visibleItemCount) return; /* at bottom */
- update ();
- topIndex++;
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) vBar.setSelection (topIndex);
- GC gc = new GC (this);
- gc.copyArea (
- 0, 0,
- clientArea.width, clientArea.height,
- 0, -itemHeight);
- gc.dispose ();
- return;
- }
- /* Shift+Down Arrow */
- int newFocusIndex = focusItem.index + 1;
- if (newFocusIndex == itemsCount) return; /* at bottom */
- selectItem (items [newFocusIndex], false);
- setFocusItem (items [newFocusIndex], true);
- redrawItem (newFocusIndex, true);
- showItem (items [newFocusIndex]);
- Event newEvent = new Event ();
- newEvent.item = items [newFocusIndex];
- postEvent (SWT.Selection, newEvent);
- return;
- }
- /* SWT.MULTI */
- if ((stateMask & SWT.CTRL) != 0) {
- if ((stateMask & SWT.SHIFT) != 0) {
- /* CTRL+Shift+Down Arrow */
- int visibleItemCount = (clientArea.height - getHeaderHeight ()) / itemHeight;
- if (itemsCount <= topIndex + visibleItemCount) return; /* at bottom */
- update ();
- topIndex++;
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) vBar.setSelection (topIndex);
- GC gc = new GC (this);
- gc.copyArea (
- 0, 0,
- clientArea.width, clientArea.height,
- 0, -itemHeight);
- gc.dispose ();
- return;
- }
- /* CTRL+Down Arrow */
- int focusIndex = focusItem.index;
- if (focusIndex == itemsCount - 1) return; /* at bottom */
- TableItem newFocusItem = items [focusIndex + 1];
- setFocusItem (newFocusItem, true);
- redrawItem (newFocusItem.index, true);
- showItem (newFocusItem);
- return;
- }
- /* Shift+Down Arrow */
- int newFocusIndex = focusItem.index + 1;
- if (newFocusIndex == itemsCount) return; /* at bottom */
- if (anchorItem == null) anchorItem = focusItem;
- if (focusItem.index < anchorItem.index) {
- deselectItem (focusItem);
- redrawItem (focusItem.index, true);
- }
- selectItem (items [newFocusIndex], true);
- setFocusItem (items [newFocusIndex], true);
- redrawItem (newFocusIndex, true);
- showItem (items [newFocusIndex]);
- Event newEvent = new Event ();
- newEvent.item = items [newFocusIndex];
- postEvent (SWT.Selection, newEvent);
-}
-void onArrowLeft (int stateMask) {
- if (horizontalOffset == 0) return;
- int newSelection = Math.max (0, horizontalOffset - SIZE_HORIZONTALSCROLL);
- update ();
- GC gc = new GC (this);
- gc.copyArea (
- 0, 0,
- clientArea.width, clientArea.height,
- horizontalOffset - newSelection, 0);
- gc.dispose ();
- if (header.getVisible ()) {
- header.update ();
- Rectangle headerClientArea = header.getClientArea ();
- gc = new GC (header);
- gc.copyArea (
- 0, 0,
- headerClientArea.width, headerClientArea.height,
- horizontalOffset - newSelection, 0);
- gc.dispose();
- }
- horizontalOffset = newSelection;
- ScrollBar hBar = getHorizontalBar ();
- if (hBar != null) hBar.setSelection (horizontalOffset);
-}
-void onArrowRight (int stateMask) {
- ScrollBar hBar = getHorizontalBar ();
- if (hBar == null) return;
- int maximum = hBar.getMaximum ();
- int clientWidth = clientArea.width;
- if ((horizontalOffset + clientArea.width) == maximum) return;
- if (maximum <= clientWidth) return;
- int newSelection = Math.min (horizontalOffset + SIZE_HORIZONTALSCROLL, maximum - clientWidth);
- update ();
- GC gc = new GC (this);
- gc.copyArea (
- 0, 0,
- clientArea.width, clientArea.height,
- horizontalOffset - newSelection, 0);
- gc.dispose ();
- if (header.getVisible ()) {
- Rectangle headerClientArea = header.getClientArea ();
- header.update ();
- gc = new GC (header);
- gc.copyArea (
- 0, 0,
- headerClientArea.width, headerClientArea.height,
- horizontalOffset - newSelection, 0);
- gc.dispose();
- }
- horizontalOffset = newSelection;
- hBar.setSelection (horizontalOffset);
-}
-void onArrowUp (int stateMask) {
- if ((stateMask & (SWT.SHIFT | SWT.CTRL)) == 0) {
- /* Up Arrow with no modifiers */
- int newFocusIndex = focusItem.index - 1;
- if (newFocusIndex < 0) return; /* at top */
- TableItem item = items [newFocusIndex];
- selectItem (item, false);
- setFocusItem (item, true);
- redrawItem (newFocusIndex, true);
- showItem (item);
- Event newEvent = new Event ();
- newEvent.item = item;
- postEvent (SWT.Selection, newEvent);
- return;
- }
- if ((style & SWT.SINGLE) != 0) {
- if ((stateMask & SWT.CTRL) != 0) {
- /* CTRL+Up Arrow, CTRL+Shift+Up Arrow */
- if (topIndex == 0) return; /* at top */
- update ();
- topIndex--;
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) vBar.setSelection (topIndex);
- GC gc = new GC (this);
- gc.copyArea (
- 0, 0,
- clientArea.width, clientArea.height,
- 0, itemHeight);
- gc.dispose ();
- return;
- }
- /* Shift+Up Arrow */
- int newFocusIndex = focusItem.index - 1;
- if (newFocusIndex < 0) return; /* at top */
- TableItem item = items [newFocusIndex];
- selectItem (item, false);
- setFocusItem (item, true);
- redrawItem (newFocusIndex, true);
- showItem (item);
- Event newEvent = new Event ();
- newEvent.item = item;
- postEvent (SWT.Selection, newEvent);
- return;
- }
- /* SWT.MULTI */
- if ((stateMask & SWT.CTRL) != 0) {
- if ((stateMask & SWT.SHIFT) != 0) {
- /* CTRL+Shift+Up Arrow */
- if (topIndex == 0) return; /* at top */
- update ();
- topIndex--;
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) vBar.setSelection (topIndex);
- GC gc = new GC (this);
- gc.copyArea (
- 0, 0,
- clientArea.width, clientArea.height,
- 0, itemHeight);
- gc.dispose ();
- return;
- }
- /* CTRL+Up Arrow */
- int focusIndex = focusItem.index;
- if (focusIndex == 0) return; /* at top */
- TableItem newFocusItem = items [focusIndex - 1];
- setFocusItem (newFocusItem, true);
- showItem (newFocusItem);
- redrawItem (newFocusItem.index, true);
- return;
- }
- /* Shift+Up Arrow */
- int newFocusIndex = focusItem.index - 1;
- if (newFocusIndex < 0) return; /* at top */
- if (anchorItem == null) anchorItem = focusItem;
- if (anchorItem.index < focusItem.index) {
- deselectItem (focusItem);
- redrawItem (focusItem.index, true);
- }
- TableItem item = items [newFocusIndex];
- selectItem (item, true);
- setFocusItem (item, true);
- redrawItem (newFocusIndex, true);
- showItem (item);
- Event newEvent = new Event ();
- newEvent.item = item;
- postEvent (SWT.Selection, newEvent);
-}
-void onCR () {
- if (focusItem == null) return;
- Event event = new Event ();
- event.item = focusItem;
- postEvent (SWT.DefaultSelection, event);
-}
-void onDispose (Event event) {
- if (isDisposed ()) return;
- if (ignoreDispose) return;
- ignoreDispose = true;
- notifyListeners(SWT.Dispose, event);
- event.type = SWT.None;
- for (int i = 0; i < itemsCount; i++) {
- items [i].dispose (false);
- }
- for (int i = 0; i < columns.length; i++) {
- columns [i].dispose (false);
- }
- if (toolTipShell != null) {
- toolTipShell.dispose ();
- toolTipShell = null;
- toolTipLabel = null;
- }
- toolTipListener = null;
- itemsCount = topIndex = horizontalOffset = 0;
- items = selectedItems = null;
- columns = orderedColumns = null;
- focusItem = anchorItem = lastClickedItem = null;
- lastSelectionEvent = null;
- header = null;
- resizeColumn = sortColumn = null;
-}
-void onEnd (int stateMask) {
- int lastAvailableIndex = itemsCount - 1;
- if ((stateMask & (SWT.CTRL | SWT.SHIFT)) == 0) {
- /* End with no modifiers */
- if (focusItem.index == lastAvailableIndex) return; /* at bottom */
- TableItem item = items [lastAvailableIndex];
- selectItem (item, false);
- setFocusItem (item, true);
- redrawItem (lastAvailableIndex, true);
- showItem (item);
- Event newEvent = new Event ();
- newEvent.item = item;
- postEvent (SWT.Selection, newEvent);
- return;
- }
- if ((style & SWT.SINGLE) != 0) {
- if ((stateMask & SWT.CTRL) != 0) {
- /* CTRL+End, CTRL+Shift+End */
- int visibleItemCount = (clientArea.height - getHeaderHeight ()) / itemHeight;
- setTopIndex (itemsCount - visibleItemCount);
- return;
- }
- /* Shift+End */
- if (focusItem.index == lastAvailableIndex) return; /* at bottom */
- TableItem item = items [lastAvailableIndex];
- selectItem (item, false);
- setFocusItem (item, true);
- redrawItem (lastAvailableIndex, true);
- showItem (item);
- Event newEvent = new Event ();
- newEvent.item = item;
- postEvent (SWT.Selection, newEvent);
- return;
- }
- /* SWT.MULTI */
- if ((stateMask & SWT.CTRL) != 0) {
- if ((stateMask & SWT.SHIFT) != 0) {
- /* CTRL+Shift+End */
- showItem (items [lastAvailableIndex]);
- return;
- }
- /* CTRL+End */
- if (focusItem.index == lastAvailableIndex) return; /* at bottom */
- TableItem item = items [lastAvailableIndex];
- setFocusItem (item, true);
- showItem (item);
- redrawItem (item.index, true);
- return;
- }
- /* Shift+End */
- if (anchorItem == null) anchorItem = focusItem;
- TableItem selectedItem = items [lastAvailableIndex];
- if (selectedItem == focusItem && selectedItem.isSelected ()) return;
- int anchorIndex = anchorItem.index;
- int selectIndex = selectedItem.index;
- TableItem[] newSelection = new TableItem [selectIndex - anchorIndex + 1];
- int writeIndex = 0;
- for (int i = anchorIndex; i <= selectIndex; i++) {
- newSelection [writeIndex++] = items [i];
- }
- setSelection (newSelection, false);
- setFocusItem (selectedItem, true);
- redrawItems (anchorIndex, selectIndex, true);
- showItem (selectedItem);
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
-}
-void onFocusIn () {
- hasFocus = true;
- if (itemsCount == 0) {
- redraw ();
- return;
- }
- if ((style & (SWT.HIDE_SELECTION | SWT.MULTI)) == (SWT.HIDE_SELECTION | SWT.MULTI)) {
- for (int i = 0; i < selectedItems.length; i++) {
- redrawItem (selectedItems [i].index, true);
- }
- }
- if (focusItem != null) {
- redrawItem (focusItem.index, true);
- return;
- }
- /* an initial focus item must be selected */
- TableItem initialFocus;
- if (selectedItems.length > 0) {
- initialFocus = selectedItems [0];
- } else {
- initialFocus = items [topIndex];
- }
- setFocusItem (initialFocus, false);
- redrawItem (initialFocus.index, true);
- return;
-}
-void onFocusOut () {
- hasFocus = false;
- if (itemsCount == 0) {
- redraw ();
- return;
- }
- if (focusItem != null) {
- redrawItem (focusItem.index, true);
- }
- if ((style & (SWT.HIDE_SELECTION | SWT.MULTI)) == (SWT.HIDE_SELECTION | SWT.MULTI)) {
- for (int i = 0; i < selectedItems.length; i++) {
- redrawItem (selectedItems [i].index, true);
- }
- }
-}
-void onHome (int stateMask) {
- if ((stateMask & (SWT.CTRL | SWT.SHIFT)) == 0) {
- /* Home with no modifiers */
- if (focusItem.index == 0) return; /* at top */
- TableItem item = items [0];
- selectItem (item, false);
- setFocusItem (item, true);
- redrawItem (0, true);
- showItem (item);
- Event newEvent = new Event ();
- newEvent.item = item;
- postEvent (SWT.Selection, newEvent);
- return;
- }
- if ((style & SWT.SINGLE) != 0) {
- if ((stateMask & SWT.CTRL) != 0) {
- /* CTRL+Home, CTRL+Shift+Home */
- setTopIndex (0);
- return;
- }
- /* Shift+Home */
- if (focusItem.index == 0) return; /* at top */
- TableItem item = items [0];
- selectItem (item, false);
- setFocusItem (item, true);
- redrawItem (0, true);
- showItem (item);
- Event newEvent = new Event ();
- newEvent.item = item;
- postEvent (SWT.Selection, newEvent);
- return;
- }
- /* SWT.MULTI */
- if ((stateMask & SWT.CTRL) != 0) {
- if ((stateMask & SWT.SHIFT) != 0) {
- /* CTRL+Shift+Home */
- setTopIndex (0);
- return;
- }
- /* CTRL+Home */
- if (focusItem.index == 0) return; /* at top */
- TableItem item = items [0];
- setFocusItem (item, true);
- showItem (item);
- redrawItem (item.index, true);
- return;
- }
- /* Shift+Home */
- if (anchorItem == null) anchorItem = focusItem;
- TableItem selectedItem = items [0];
- if (selectedItem == focusItem && selectedItem.isSelected ()) return;
- int anchorIndex = anchorItem.index;
- int selectIndex = selectedItem.index;
- TableItem[] newSelection = new TableItem [anchorIndex + 1];
- int writeIndex = 0;
- for (int i = anchorIndex; i >= 0; i--) {
- newSelection [writeIndex++] = items [i];
- }
- setSelection (newSelection, false);
- setFocusItem (selectedItem, true);
- redrawItems (anchorIndex, selectIndex, true);
- showItem (selectedItem);
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
-}
-void onKeyDown (Event event) {
- if (ignoreKey) {
- ignoreKey = false;
- return;
- }
- ignoreKey = true;
- notifyListeners (event.type, event);
- event.type = SWT.None;
- if (!event.doit) return;
- if (focusItem == null) return;
- if ((event.stateMask & SWT.SHIFT) == 0 && event.keyCode != SWT.SHIFT) {
- anchorItem = null;
- }
- switch (event.keyCode) {
- case SWT.ARROW_UP:
- onArrowUp (event.stateMask);
- return;
- case SWT.ARROW_DOWN:
- onArrowDown (event.stateMask);
- return;
- case SWT.ARROW_LEFT:
- onArrowLeft (event.stateMask);
- return;
- case SWT.ARROW_RIGHT:
- onArrowRight (event.stateMask);
- return;
- case SWT.PAGE_UP:
- onPageUp (event.stateMask);
- return;
- case SWT.PAGE_DOWN:
- onPageDown (event.stateMask);
- return;
- case SWT.HOME:
- onHome (event.stateMask);
- return;
- case SWT.END:
- onEnd (event.stateMask);
- return;
- }
- if (event.character == ' ') {
- onSpace ();
- return;
- }
- if (event.character == SWT.CR) {
- onCR ();
- return;
- }
- if ((event.stateMask & SWT.CTRL) != 0) return;
-
- int initialIndex = focusItem.index;
- char character = Character.toLowerCase (event.character);
- /* check available items from current focus item to bottom */
- for (int i = initialIndex + 1; i < itemsCount; i++) {
- TableItem item = items [i];
- String text = item.getText (0, false);
- if (text.length () > 0) {
- if (Character.toLowerCase (text.charAt (0)) == character) {
- selectItem (item, false);
- setFocusItem (item, true);
- redrawItem (i, true);
- showItem (item);
- Event newEvent = new Event ();
- newEvent.item = item;
- postEvent (SWT.Selection, newEvent);
- return;
- }
- }
- }
- /* check available items from top to current focus item */
- for (int i = 0; i < initialIndex; i++) {
- TableItem item = items [i];
- String text = item.getText (0, false);
- if (text.length () > 0) {
- if (Character.toLowerCase (text.charAt (0)) == character) {
- selectItem (item, false);
- setFocusItem (item, true);
- redrawItem (i, true);
- showItem (item);
- Event newEvent = new Event ();
- newEvent.item = item;
- postEvent (SWT.Selection, newEvent);
- return;
- }
- }
- }
-}
-void onMouseDoubleClick (Event event) {
- if (!isFocusControl ()) setFocus ();
- int index = (event.y - getHeaderHeight ()) / itemHeight + topIndex;
- if (!(0 <= index && index < itemsCount)) return; /* not on an available item */
- TableItem selectedItem = items [index];
-
- /*
- * If the two clicks of the double click did not occur over the same item then do not
- * consider this to be a default selection.
- */
- if (selectedItem != lastClickedItem) return;
-
- if (!selectedItem.getHitBounds ().contains (event.x, event.y)) return; /* considers x */
-
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.DefaultSelection, newEvent);
-}
-void onMouseDown (Event event) {
- if (!isFocusControl ()) forceFocus ();
- int index = (event.y - getHeaderHeight ()) / itemHeight + topIndex;
- if (!(0 <= index && index < itemsCount)) return; /* not on an available item */
- TableItem selectedItem = items [index];
-
- /* if click was in checkbox */
- if ((style & SWT.CHECK) != 0 && selectedItem.getCheckboxBounds ().contains (event.x, event.y)) {
- if (event.button != 1) return;
- selectedItem.setChecked (!selectedItem.checked);
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- newEvent.detail = SWT.CHECK;
- postEvent (SWT.Selection, newEvent);
- return;
- }
-
- if (!selectedItem.getHitBounds ().contains (event.x, event.y)) return;
-
- if ((event.stateMask & SWT.SHIFT) == 0 && event.keyCode != SWT.SHIFT) anchorItem = null;
-
- boolean sendSelection = true;
- /* Detect when this is the second click of a DefaultSelection and don't fire Selection */
- if (lastSelectionEvent != null && lastSelectionEvent.item == selectedItem) {
- if (event.time - lastSelectionEvent.time <= display.getDoubleClickTime ()) {
- sendSelection = false;
- } else {
- lastSelectionEvent = event;
- event.item = selectedItem;
- }
- } else {
- lastSelectionEvent = event;
- event.item = selectedItem;
- }
-
- if ((style & SWT.SINGLE) != 0) {
- if (!selectedItem.isSelected ()) {
- if (event.button == 1) {
- selectItem (selectedItem, false);
- setFocusItem (selectedItem, true);
- redrawItem (selectedItem.index, true);
- if (sendSelection) {
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
- }
- return;
- }
- if ((event.stateMask & (SWT.CTRL | SWT.SHIFT)) == 0) {
- selectItem (selectedItem, false);
- setFocusItem (selectedItem, true);
- redrawItem (selectedItem.index, true);
- if (sendSelection) {
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
- }
- return;
- }
- }
- /* item is selected */
- if (event.button == 1) {
- /* fire a selection event, though the selection did not change */
- if (sendSelection) {
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
- }
- return;
- }
- }
- /* SWT.MULTI */
- if (!selectedItem.isSelected ()) {
- if (event.button == 1) {
- if ((event.stateMask & (SWT.CTRL | SWT.SHIFT)) == SWT.SHIFT) {
- if (anchorItem == null) anchorItem = focusItem;
- int anchorIndex = anchorItem.index;
- int selectIndex = selectedItem.index;
- TableItem[] newSelection = new TableItem [Math.abs (anchorIndex - selectIndex) + 1];
- int step = anchorIndex < selectIndex ? 1 : -1;
- int writeIndex = 0;
- for (int i = anchorIndex; i != selectIndex; i += step) {
- newSelection [writeIndex++] = items [i];
- }
- newSelection [writeIndex] = items [selectIndex];
- setSelection (newSelection, false);
- setFocusItem (selectedItem, true);
- redrawItems (
- Math.min (anchorIndex, selectIndex),
- Math.max (anchorIndex, selectIndex),
- true);
- if (sendSelection) {
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
- }
- return;
- }
- selectItem (selectedItem, (event.stateMask & SWT.CTRL) != 0);
- setFocusItem (selectedItem, true);
- redrawItem (selectedItem.index, true);
- if (sendSelection) {
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
- }
- return;
- }
- /* button 3 */
- if ((event.stateMask & (SWT.CTRL | SWT.SHIFT)) == 0) {
- selectItem (selectedItem, false);
- setFocusItem (selectedItem, true);
- redrawItem (selectedItem.index, true);
- if (sendSelection) {
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
- }
- return;
- }
- }
- /* item is selected */
- if (event.button != 1) return;
- if ((event.stateMask & SWT.CTRL) != 0) {
- removeSelectedItem (getSelectionIndex (selectedItem));
- setFocusItem (selectedItem, true);
- redrawItem (selectedItem.index, true);
- if (sendSelection) {
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
- }
- return;
- }
- if ((event.stateMask & SWT.SHIFT) != 0) {
- if (anchorItem == null) anchorItem = focusItem;
- int anchorIndex = anchorItem.index;
- int selectIndex = selectedItem.index;
- TableItem[] newSelection = new TableItem [Math.abs (anchorIndex - selectIndex) + 1];
- int step = anchorIndex < selectIndex ? 1 : -1;
- int writeIndex = 0;
- for (int i = anchorIndex; i != selectIndex; i += step) {
- newSelection [writeIndex++] = items [i];
- }
- newSelection [writeIndex] = items [selectIndex];
- setSelection (newSelection, false);
- setFocusItem (selectedItem, true);
- redrawItems (
- Math.min (anchorIndex, selectIndex),
- Math.max (anchorIndex, selectIndex),
- true);
- if (sendSelection) {
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
- }
- return;
- }
- selectItem (selectedItem, false);
- setFocusItem (selectedItem, true);
- redrawItem (selectedItem.index, true);
- if (sendSelection) {
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
- }
-}
-void onMouseUp (Event event) {
- int index = (event.y - getHeaderHeight ()) / itemHeight + topIndex;
- if (!(0 <= index && index < itemsCount)) return; /* not on an available item */
- lastClickedItem = items [index];
-}
-void onPageDown (int stateMask) {
- int visibleItemCount = (clientArea.height - getHeaderHeight ()) / itemHeight;
- if ((stateMask & (SWT.CTRL | SWT.SHIFT)) == 0) {
- /* PageDown with no modifiers */
- int newFocusIndex = focusItem.index + visibleItemCount - 1;
- newFocusIndex = Math.min (newFocusIndex, itemsCount - 1);
- if (newFocusIndex == focusItem.index) return;
- TableItem item = items [newFocusIndex];
- selectItem (item, false);
- setFocusItem (item, true);
- showItem (item);
- redrawItem (item.index, true);
- return;
- }
- if ((stateMask & (SWT.CTRL | SWT.SHIFT)) == (SWT.CTRL | SWT.SHIFT)) {
- /* CTRL+Shift+PageDown */
- int newTopIndex = topIndex + visibleItemCount;
- newTopIndex = Math.min (newTopIndex, itemsCount - visibleItemCount);
- if (newTopIndex == topIndex) return;
- setTopIndex (newTopIndex);
- return;
- }
- if ((style & SWT.SINGLE) != 0) {
- if ((stateMask & SWT.SHIFT) != 0) {
- /* Shift+PageDown */
- int newFocusIndex = focusItem.index + visibleItemCount - 1;
- newFocusIndex = Math.min (newFocusIndex, itemsCount - 1);
- if (newFocusIndex == focusItem.index) return;
- TableItem item = items [newFocusIndex];
- selectItem (item, false);
- setFocusItem (item, true);
- showItem (item);
- redrawItem (item.index, true);
- return;
- }
- /* CTRL+PageDown */
- int newTopIndex = topIndex + visibleItemCount;
- newTopIndex = Math.min (newTopIndex, itemsCount - visibleItemCount);
- if (newTopIndex == topIndex) return;
- setTopIndex (newTopIndex);
- return;
- }
- /* SWT.MULTI */
- if ((stateMask & SWT.CTRL) != 0) {
- /* CTRL+PageDown */
- int bottomIndex = Math.min (topIndex + visibleItemCount - 1, itemsCount - 1);
- if (focusItem.index != bottomIndex) {
- /* move focus to bottom item in viewport */
- setFocusItem (items [bottomIndex], true);
- redrawItem (bottomIndex, true);
- } else {
- /* at bottom of viewport, so set focus to bottom item one page down */
- int newFocusIndex = Math.min (itemsCount - 1, bottomIndex + visibleItemCount);
- if (newFocusIndex == focusItem.index) return;
- setFocusItem (items [newFocusIndex], true);
- showItem (items [newFocusIndex]);
- redrawItem (newFocusIndex, true);
- }
- return;
- }
- /* Shift+PageDown */
- if (anchorItem == null) anchorItem = focusItem;
- int anchorIndex = anchorItem.index;
- int bottomIndex = Math.min (topIndex + visibleItemCount - 1, itemsCount - 1);
- int selectIndex;
- if (focusItem.index != bottomIndex) {
- /* select from focus to bottom item in viewport */
- selectIndex = bottomIndex;
- } else {
- /* already at bottom of viewport, so select to bottom of one page down */
- selectIndex = Math.min (itemsCount - 1, bottomIndex + visibleItemCount);
- if (selectIndex == focusItem.index && focusItem.isSelected ()) return;
- }
- TableItem selectedItem = items [selectIndex];
- TableItem[] newSelection = new TableItem [Math.abs (anchorIndex - selectIndex) + 1];
- int step = anchorIndex < selectIndex ? 1 : -1;
- int writeIndex = 0;
- for (int i = anchorIndex; i != selectIndex; i += step) {
- newSelection [writeIndex++] = items [i];
- }
- newSelection [writeIndex] = items [selectIndex];
- setSelection (newSelection, false);
- setFocusItem (selectedItem, true);
- showItem (selectedItem);
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
-}
-void onPageUp (int stateMask) {
- int visibleItemCount = (clientArea.height - getHeaderHeight ()) / itemHeight;
- if ((stateMask & (SWT.CTRL | SWT.SHIFT)) == 0) {
- /* PageUp with no modifiers */
- int newFocusIndex = Math.max (0, focusItem.index - visibleItemCount + 1);
- if (newFocusIndex == focusItem.index) return;
- TableItem item = items [newFocusIndex];
- selectItem (item, false);
- setFocusItem (item, true);
- showItem (item);
- redrawItem (item.index, true);
- return;
- }
- if ((stateMask & (SWT.CTRL | SWT.SHIFT)) == (SWT.CTRL | SWT.SHIFT)) {
- /* CTRL+Shift+PageUp */
- int newTopIndex = Math.max (0, topIndex - visibleItemCount);
- if (newTopIndex == topIndex) return;
- setTopIndex (newTopIndex);
- return;
- }
- if ((style & SWT.SINGLE) != 0) {
- if ((stateMask & SWT.SHIFT) != 0) {
- /* Shift+PageUp */
- int newFocusIndex = Math.max (0, focusItem.index - visibleItemCount + 1);
- if (newFocusIndex == focusItem.index) return;
- TableItem item = items [newFocusIndex];
- selectItem (item, false);
- setFocusItem (item, true);
- showItem (item);
- redrawItem (item.index, true);
- return;
- }
- /* CTRL+PageUp */
- int newTopIndex = Math.max (0, topIndex - visibleItemCount);
- if (newTopIndex == topIndex) return;
- setTopIndex (newTopIndex);
- return;
- }
- /* SWT.MULTI */
- if ((stateMask & SWT.CTRL) != 0) {
- /* CTRL+PageUp */
- if (focusItem.index != topIndex) {
- /* move focus to top item in viewport */
- setFocusItem (items [topIndex], true);
- redrawItem (topIndex, true);
- } else {
- /* at top of viewport, so set focus to top item one page up */
- int newFocusIndex = Math.max (0, focusItem.index - visibleItemCount);
- if (newFocusIndex == focusItem.index) return;
- setFocusItem (items [newFocusIndex], true);
- showItem (items [newFocusIndex]);
- redrawItem (newFocusIndex, true);
- }
- return;
- }
- /* Shift+PageUp */
- if (anchorItem == null) anchorItem = focusItem;
- int anchorIndex = anchorItem.index;
- int selectIndex;
- if (focusItem.index != topIndex) {
- /* select from focus to top item in viewport */
- selectIndex = topIndex;
- } else {
- /* already at top of viewport, so select to top of one page up */
- selectIndex = Math.max (0, topIndex - visibleItemCount);
- if (selectIndex == focusItem.index && focusItem.isSelected ()) return;
- }
- TableItem selectedItem = items [selectIndex];
- TableItem[] newSelection = new TableItem [Math.abs (anchorIndex - selectIndex) + 1];
- int step = anchorIndex < selectIndex ? 1 : -1;
- int writeIndex = 0;
- for (int i = anchorIndex; i != selectIndex; i += step) {
- newSelection [writeIndex++] = items [i];
- }
- newSelection [writeIndex] = items [selectIndex];
- setSelection (newSelection, false);
- setFocusItem (selectedItem, true);
- showItem (selectedItem);
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
-}
-void onPaint (Event event) {
- TableColumn[] orderedColumns = getOrderedColumns ();
- GC gc = event.gc;
- Rectangle clipping = gc.getClipping ();
- int headerHeight = getHeaderHeight ();
- int numColumns = orderedColumns.length;
- int startColumn = -1, endColumn = -1;
- if (numColumns > 0) {
- startColumn = computeColumnIntersect (clipping.x, 0);
- if (startColumn != -1) { /* the clip x is within a column's bounds */
- endColumn = computeColumnIntersect (clipping.x + clipping.width, startColumn);
- if (endColumn == -1) endColumn = numColumns - 1;
- }
- } else {
- startColumn = endColumn = 0;
- }
-
- /* Determine the items to be painted */
- int startIndex = (clipping.y - headerHeight) / itemHeight + topIndex;
- int endIndex = -1;
- if (startIndex < itemsCount) {
- endIndex = startIndex + Compatibility.ceil (clipping.height, itemHeight);
- }
- startIndex = Math.max (0, startIndex);
- endIndex = Math.min (endIndex, itemsCount - 1);
-
- /* fill background not handled by items */
- gc.setBackground (getBackground ());
- gc.setClipping (clipping);
- int bottomY = endIndex >= 0 ? getItemY (items [endIndex]) + itemHeight : 0;
- int fillHeight = Math.max (0, clientArea.height - bottomY);
- if (fillHeight > 0) { /* space below bottom item */
- drawBackground (gc, 0, bottomY, clientArea.width, fillHeight);
- }
- if (columns.length > 0) {
- TableColumn column = orderedColumns [orderedColumns.length - 1]; /* last column */
- int rightX = column.getX () + column.width;
- if (rightX < clientArea.width) {
- drawBackground (gc, rightX, 0, clientArea.width - rightX, clientArea.height - fillHeight);
- }
- }
-
- /* paint the items */
- boolean noFocusDraw = false;
- int[] lineDash = gc.getLineDash ();
- int lineWidth = gc.getLineWidth ();
- for (int i = startIndex; i <= Math.min (endIndex, itemsCount - 1); i++) {
- TableItem item = items [i];
- if (!item.isDisposed ()) { /* ensure that item was not disposed in a callback */
- if (startColumn == -1) {
- /* indicates that region to paint is to the right of the last column */
- noFocusDraw = item.paint (gc, null, true) || noFocusDraw;
- } else {
- if (numColumns == 0) {
- noFocusDraw = item.paint (gc, null, false) || noFocusDraw;
- } else {
- for (int j = startColumn; j <= Math.min (endColumn, columns.length - 1); j++) {
- if (!item.isDisposed ()) { /* ensure that item was not disposed in a callback */
- noFocusDraw = item.paint (gc, orderedColumns [j], false) || noFocusDraw;
- }
- if (isDisposed () || gc.isDisposed ()) return; /* ensure that receiver was not disposed in a callback */
- }
- }
- }
- }
- if (isDisposed () || gc.isDisposed ()) return; /* ensure that receiver was not disposed in a callback */
- }
-
- /* repaint grid lines */
- gc.setClipping(clipping);
- gc.setLineWidth (lineWidth);
- if (linesVisible) {
- gc.setForeground (display.getSystemColor (SWT.COLOR_WIDGET_LIGHT_SHADOW));
- gc.setLineDash (lineDash);
- if (numColumns > 0 && startColumn != -1) {
- /* vertical column lines */
- for (int i = startColumn; i <= endColumn; i++) {
- int x = orderedColumns [i].getX () + orderedColumns [i].width - 1;
- gc.drawLine (x, clipping.y, x, clipping.y + clipping.height);
- }
- }
- /* horizontal item lines */
- bottomY = clipping.y + clipping.height;
- int rightX = clipping.x + clipping.width;
- int y = (clipping.y - headerHeight) / itemHeight * itemHeight + headerHeight;
- while (y <= bottomY) {
- gc.drawLine (clipping.x, y, rightX, y);
- y += itemHeight;
- }
- }
-
- /* paint focus rectangle */
- if (!noFocusDraw && isFocusControl ()) {
- if (focusItem != null) {
- Rectangle focusBounds = focusItem.getFocusBounds ();
- if (focusBounds.width > 0) {
- gc.setForeground (display.getSystemColor (SWT.COLOR_BLACK));
- gc.setClipping (focusBounds);
- if (focusItem.isSelected ()) {
- gc.setLineDash (new int[] {2, 2});
- } else {
- gc.setLineDash (new int[] {1, 1});
- }
- gc.drawFocus (focusBounds.x, focusBounds.y, focusBounds.width, focusBounds.height);
- }
- } else {
- /* no items, so draw focus border around Table */
- int y = headerHeight + 1;
- int width = Math.max (0, clientArea.width - 2);
- int height = Math.max (0, clientArea.height - headerHeight - 2);
- gc.setForeground (display.getSystemColor (SWT.COLOR_BLACK));
- gc.setClipping (1, y, width, height);
- gc.setLineDash (new int[] {1, 1});
- gc.drawFocus (1, y, width, height);
- }
- }
-}
-void onResize (Event event) {
- clientArea = getClientArea ();
- /* vertical scrollbar */
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) {
- int clientHeight = (clientArea.height - getHeaderHeight ()) / itemHeight;
- int thumb = Math.min (clientHeight, itemsCount);
- vBar.setThumb (thumb);
- vBar.setPageIncrement (thumb);
- int index = vBar.getSelection ();
- if (index != topIndex) {
- topIndex = index;
- redraw ();
- }
- boolean visible = clientHeight < itemsCount;
- if (visible != vBar.getVisible ()) {
- vBar.setVisible (visible);
- clientArea = getClientArea ();
- }
- }
-
- /* horizontal scrollbar */
- ScrollBar hBar = getHorizontalBar ();
- if (hBar != null) {
- int hBarMaximum = hBar.getMaximum ();
- int thumb = Math.min (clientArea.width, hBarMaximum);
- hBar.setThumb (thumb);
- hBar.setPageIncrement (thumb);
- horizontalOffset = hBar.getSelection ();
- boolean visible = clientArea.width < hBarMaximum;
- if (visible != hBar.getVisible ()) {
- hBar.setVisible (visible);
- clientArea = getClientArea ();
- }
- }
-
- /* header */
- int headerHeight = Math.max (fontHeight, headerImageHeight) + 2 * getHeaderPadding ();
- header.setSize (clientArea.width, headerHeight);
-
- /* if this is the focus control but there are no items then the boundary focus ring must be repainted */
- if (itemsCount == 0 && isFocusControl ()) redraw ();
-}
-void onScrollHorizontal (Event event) {
- ScrollBar hBar = getHorizontalBar ();
- if (hBar == null) return;
- int newSelection = hBar.getSelection ();
- update ();
- if (itemsCount > 0) {
- GC gc = new GC (this);
- gc.copyArea (
- 0, 0,
- clientArea.width, clientArea.height,
- horizontalOffset - newSelection, 0);
- gc.dispose ();
- } else {
- redraw (); /* ensure that static focus rectangle updates properly */
- }
-
- if (drawCount <= 0 && header.isVisible ()) {
- header.update ();
- Rectangle headerClientArea = header.getClientArea ();
- GC gc = new GC (header);
- gc.copyArea (
- 0, 0,
- headerClientArea.width, headerClientArea.height,
- horizontalOffset - newSelection, 0);
- gc.dispose ();
- }
- horizontalOffset = newSelection;
-}
-void onScrollVertical (Event event) {
- ScrollBar vBar = getVerticalBar ();
- if (vBar == null) return;
- int newSelection = vBar.getSelection ();
- update ();
- GC gc = new GC (this);
- gc.copyArea (
- 0, 0,
- clientArea.width, clientArea.height,
- 0, (topIndex - newSelection) * itemHeight);
- gc.dispose ();
- topIndex = newSelection;
-}
-void onSpace () {
- if (focusItem == null) return;
- if (!focusItem.isSelected ()) {
- selectItem (focusItem, (style & SWT.MULTI) != 0);
- redrawItem (focusItem.index, true);
- }
- if ((style & SWT.CHECK) != 0) {
- focusItem.setChecked (!focusItem.checked);
- }
- showItem (focusItem);
- Event event = new Event ();
- event.item = focusItem;
- postEvent (SWT.Selection, event);
- if ((style & SWT.CHECK) == 0) return;
-
- /* SWT.CHECK */
- event = new Event ();
- event.item = focusItem;
- event.detail = SWT.CHECK;
- postEvent (SWT.Selection, event);
-}
-/*
- * The current focus item is about to become unavailable, so reassign focus.
- */
-void reassignFocus () {
- if (focusItem == null) return;
-
- /*
- * reassign to the previous root-level item if there is one, or the next
- * root-level item otherwise
- */
- int index = focusItem.index;
- if (index != 0) {
- index--;
- } else {
- index++;
- }
- if (index < itemsCount) {
- TableItem item = items [index];
- setFocusItem (item, false);
- showItem (item);
- } else {
- setFocusItem (null, false); /* no items left */
- }
-}
-public void redraw () {
- checkWidget ();
- if (drawCount <= 0) super.redraw ();
-}
-public void redraw (int x, int y, int width, int height, boolean all) {
- checkWidget ();
- if (drawCount <= 0) super.redraw (x, y, width, height, all);
-}
-/*
- * Redraws from the specified index down to the last available item inclusive. Note
- * that the redraw bounds do not extend beyond the current last item, so clients
- * that reduce the number of available items should use #redrawItems(int,int) instead
- * to ensure that redrawing extends down to the previous bottom item boundary.
- */
-void redrawFromItemDownwards (int index) {
- redrawItems (index, itemsCount - 1, false);
-}
-/*
- * Redraws the table item at the specified index. It is valid for this index to reside
- * beyond the last available item.
- */
-void redrawItem (int itemIndex, boolean focusBoundsOnly) {
- if (itemIndex < itemsCount && !items [itemIndex].isInViewport ()) return;
- redrawItems (itemIndex, itemIndex, focusBoundsOnly);
-}
-/*
- * Redraws the table between the start and end item indices inclusive. It is valid
- * for the end index value to extend beyond the last available item.
- */
-void redrawItems (int startIndex, int endIndex, boolean focusBoundsOnly) {
- if (drawCount > 0) return;
-
- int startY = (startIndex - topIndex) * itemHeight + getHeaderHeight ();
- int height = (endIndex - startIndex + 1) * itemHeight;
- if (focusBoundsOnly) {
- boolean custom = hooks (SWT.EraseItem) || hooks (SWT.PaintItem);
- if (!custom && columns.length > 0) {
- TableColumn lastColumn;
- if ((style & SWT.FULL_SELECTION) != 0) {
- TableColumn[] orderedColumns = getOrderedColumns ();
- lastColumn = orderedColumns [orderedColumns.length - 1];
- } else {
- lastColumn = columns [0];
- }
- int rightX = lastColumn.getX () + lastColumn.getWidth ();
- if (rightX <= 0) return; /* focus column(s) not visible */
- }
- endIndex = Math.min (endIndex, itemsCount - 1);
- for (int i = startIndex; i <= endIndex; i++) {
- TableItem item = items [i];
- if (item.isInViewport ()) {
- /* if custom painting is being done then repaint the full item */
- if (custom) {
- redraw (0, getItemY (item), clientArea.width, itemHeight, false);
- } else {
- /* repaint the item's focus bounds */
- Rectangle bounds = item.getFocusBounds ();
- redraw (bounds.x, startY, bounds.width, height, false);
- }
- }
- }
- } else {
- redraw (0, startY, clientArea.width, height, false);
- }
-}
-/**
- * Removes the item from the receiver at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemsCount)) error (SWT.ERROR_INVALID_RANGE);
- items [index].dispose ();
-}
-/**
- * Removes the items from the receiver which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget ();
- if (start > end) return;
- if (!(0 <= start && start <= end && end < itemsCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- if (start == 0 && end == itemsCount - 1) {
- removeAll ();
- } else {
- for (int i = end; i >= start; i--) {
- items [i].dispose ();
- }
- }
-}
-/**
- * Removes the items from the receiver's list at the given
- * zero-relative indices.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- int [] newIndices = new int [indices.length];
- System.arraycopy (indices, 0, newIndices, 0, indices.length);
- sortDescent (newIndices);
- int start = newIndices [newIndices.length - 1], end = newIndices [0];
- if (!(0 <= start && start <= end && end < itemsCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int lastRemovedIndex = -1;
- for (int i = 0; i < newIndices.length; i++) {
- if (newIndices [i] != lastRemovedIndex) {
- items [newIndices [i]].dispose ();
- lastRemovedIndex = newIndices [i];
- }
- }
-}
-/**
- * Removes all of the items from the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget ();
- if (itemsCount == 0) return;
- setRedraw (false);
-
- setFocusItem (null, false);
- for (int i = 0; i < itemsCount; i++) {
- items [i].dispose (false);
- }
- items = new TableItem [0];
- selectedItems = new TableItem [0];
- itemsCount = topIndex = 0;
- anchorItem = lastClickedItem = null;
- lastSelectionEvent = null;
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) {
- vBar.setMaximum (1);
- vBar.setVisible (false);
- }
- if (columns.length == 0) {
- horizontalOffset = 0;
- ScrollBar hBar = getHorizontalBar ();
- if (hBar != null) {
- hBar.setMaximum (1);
- hBar.setVisible (false);
- }
- }
-
- setRedraw (true);
-}
-String removeMnemonics (String string) {
- /* removes single ampersands and preserves double-ampersands */
- char [] chars = new char [string.length ()];
- string.getChars (0, chars.length, chars, 0);
- int i = 0, j = 0;
- for ( ; i < chars.length; i++, j++) {
- if (chars[i] == '&') {
- if (++i == chars.length) break;
- if (chars[i] == '&') {
- chars[j++] = chars[i - 1];
- }
- }
- chars[j] = chars[i];
- }
- if (i == j) return string;
- return new String (chars, 0, j);
-}
-void removeSelectedItem (int index) {
- TableItem[] newSelectedItems = new TableItem [selectedItems.length - 1];
- System.arraycopy (selectedItems, 0, newSelectedItems, 0, index);
- System.arraycopy (selectedItems, index + 1, newSelectedItems, index, newSelectedItems.length - index);
- selectedItems = newSelectedItems;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener(SelectionListener)
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- removeListener (SWT.Selection, listener);
- removeListener (SWT.DefaultSelection, listener);
-}
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemsCount)) return;
- selectItem (items [index], (style & SWT.MULTI) != 0);
- if (hasFocus () || (style & SWT.HIDE_SELECTION) == 0) {
- redrawItem (index, false);
- }
-}
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If an item in the given range is not selected, it is selected.
- * If an item in the given range was already selected, it remains selected.
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setSelection(int,int)
- */
-public void select (int start, int end) {
- checkWidget ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- if (itemsCount == 0 || start >= itemsCount) return;
- start = Math.max (start, 0);
- end = Math.min (end, itemsCount - 1);
- for (int i = start; i <= end; i++) {
- selectItem (items [i], (style & SWT.MULTI) != 0);
- }
- if (hasFocus () || (style & SWT.HIDE_SELECTION) == 0) {
- redrawItems (start, end, false);
- }
-}
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If the item at a given index is not selected, it is selected.
- * If the item at a given index was already selected, it remains selected.
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- * </p>
- *
- * @param indices the array of indices for the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setSelection(int[])
- */
-public void select (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0 || ((style & SWT.SINGLE) != 0 && indices.length > 1)) return;
-
- for (int i = 0; i < indices.length; i++) {
- if (0 <= indices [i] && indices [i] < itemsCount) {
- selectItem (items [indices [i]], (style & SWT.MULTI) != 0);
- }
- }
- if (hasFocus () || (style & SWT.HIDE_SELECTION) == 0) {
- for (int i = 0; i < indices.length; i++) {
- if (0 <= indices [i] && indices [i] < itemsCount) {
- redrawItem (indices [i], false);
- }
- }
- }
-}
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- selectedItems = new TableItem [itemsCount];
- System.arraycopy (items, 0, selectedItems, 0, itemsCount);
- if (hasFocus () || (style & SWT.HIDE_SELECTION) == 0) {
- redraw ();
- }
-}
-void selectItem (TableItem item, boolean addToSelection) {
- TableItem[] oldSelectedItems = selectedItems;
- if (!addToSelection || (style & SWT.SINGLE) != 0) {
- selectedItems = new TableItem[] {item};
- if (hasFocus () || (style & SWT.HIDE_SELECTION) == 0) {
- for (int i = 0; i < oldSelectedItems.length; i++) {
- if (oldSelectedItems [i] != item) {
- redrawItem (oldSelectedItems [i].index, true);
- }
- }
- }
- } else {
- if (item.isSelected ()) return;
- selectedItems = new TableItem [selectedItems.length + 1];
- System.arraycopy (oldSelectedItems, 0, selectedItems, 0, oldSelectedItems.length);
- selectedItems [selectedItems.length - 1] = item;
- }
-}
-public void setBackground (Color color) {
- checkWidget ();
- if (color == null) color = display.getSystemColor (SWT.COLOR_LIST_BACKGROUND);
- super.setBackground (color);
-}
-public void setForeground (Color color) {
- checkWidget ();
- if (color == null) color = display.getSystemColor (SWT.COLOR_LIST_FOREGROUND);
- super.setForeground (color);
-}
-/**
- * Sets the order that the items in the receiver should
- * be displayed in to the given argument which is described
- * in terms of the zero-relative ordering of when the items
- * were added.
- *
- * @param order the new order to display the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item order is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public void setColumnOrder (int [] order) {
- checkWidget ();
- if (order == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (columns.length == 0) {
- if (order.length != 0) error (SWT.ERROR_INVALID_ARGUMENT);
- return;
- }
- if (order.length != columns.length) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean reorder = false;
- boolean [] seen = new boolean [columns.length];
- int[] oldOrder = getColumnOrder ();
- for (int i = 0; i < order.length; i++) {
- int index = order [i];
- if (index < 0 || index >= columns.length) error (SWT.ERROR_INVALID_RANGE);
- if (seen [index]) error (SWT.ERROR_INVALID_ARGUMENT);
- seen [index] = true;
- if (index != oldOrder [i]) reorder = true;
- }
- if (!reorder) return;
-
- headerHideToolTip ();
- int[] oldX = new int [columns.length];
- for (int i = 0; i < columns.length; i++) {
- oldX [i] = columns [i].getX ();
- }
- orderedColumns = new TableColumn [order.length];
- for (int i = 0; i < order.length; i++) {
- orderedColumns [i] = columns [order [i]];
- }
- for (int i = 0; i < orderedColumns.length; i++) {
- TableColumn column = orderedColumns [i];
- if (!column.isDisposed () && column.getX () != oldX [column.getIndex ()]) {
- column.sendEvent (SWT.Move);
- }
- }
-
- redraw ();
- if (drawCount <= 0 && header.isVisible ()) header.redraw ();
-}
-void setFocusItem (TableItem item, boolean redrawOldFocus) {
- if (item == focusItem) return;
- TableItem oldFocusItem = focusItem;
- focusItem = item;
- if (redrawOldFocus && oldFocusItem != null) {
- redrawItem (oldFocusItem.index, true);
- }
-}
-public void setFont (Font value) {
- checkWidget ();
- Font oldFont = getFont ();
- super.setFont (value);
- Font font = getFont ();
- if (font.equals (oldFont)) return;
-
- GC gc = new GC (this);
-
- /* recompute the receiver's cached font height and item height values */
- fontHeight = gc.getFontMetrics ().getHeight ();
- setItemHeight (Math.max (fontHeight, imageHeight) + 2 * getCellPadding ());
- Point headerSize = header.getSize ();
- int newHeaderHeight = Math.max (fontHeight, headerImageHeight) + 2 * getHeaderPadding ();
- if (headerSize.y != newHeaderHeight) {
- header.setSize (headerSize.x, newHeaderHeight);
- }
- header.setFont (font);
-
- /*
- * Notify all columns and items of the font change so that elements that
- * use the receiver's font can recompute their cached string widths.
- */
- for (int i = 0; i < columns.length; i++) {
- columns [i].updateFont (gc);
- }
- for (int i = 0; i < itemsCount; i++) {
- items [i].updateFont (gc);
- }
-
- gc.dispose ();
-
- if (drawCount <= 0 && header.isVisible ()) header.redraw ();
-
- /* update scrollbars */
- if (columns.length == 0) updateHorizontalBar ();
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) {
- int thumb = (clientArea.height - getHeaderHeight ()) / itemHeight;
- vBar.setThumb (thumb);
- vBar.setPageIncrement (thumb);
- topIndex = vBar.getSelection ();
- vBar.setVisible (thumb < vBar.getMaximum ());
- }
- redraw ();
-}
-void setHeaderImageHeight (int value) {
- headerImageHeight = value;
- Point headerSize = header.getSize ();
- int newHeaderHeight = Math.max (fontHeight, headerImageHeight) + 2 * getHeaderPadding ();
- if (headerSize.y != newHeaderHeight) {
- header.setSize (headerSize.x, newHeaderHeight);
- }
-}
-/**
- * Marks the receiver's header as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHeaderVisible (boolean value) {
- checkWidget ();
- if (header.getVisible () == value) return; /* no change */
- headerHideToolTip ();
- header.setVisible (value);
- updateVerticalBar ();
- redraw ();
-}
-void setImageHeight (int value) {
- imageHeight = value;
- setItemHeight (Math.max (fontHeight, imageHeight) + 2 * getCellPadding ());
-}
-/**
- * Sets the number of items contained in the receiver.
- *
- * @param count the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setItemCount (int count) {
- checkWidget ();
- count = Math.max (0, count);
- if (count == itemsCount) return;
- int oldCount = itemsCount;
- int redrawStart, redrawEnd;
-
- /* if the new item count is less than the current count then remove all excess items from the end */
- if (count < itemsCount) {
- redrawStart = count;
- redrawEnd = itemsCount - 1;
- for (int i = count; i < itemsCount; i++) {
- items [i].dispose (false);
- }
-
- int newSelectedCount = 0;
- for (int i = 0; i < selectedItems.length; i++) {
- if (!selectedItems [i].isDisposed ()) newSelectedCount++;
- }
- if (newSelectedCount != selectedItems.length) {
- /* one or more selected items have been disposed */
- TableItem[] newSelectedItems = new TableItem [newSelectedCount];
- int pos = 0;
- for (int i = 0; i < selectedItems.length; i++) {
- TableItem item = selectedItems [i];
- if (!item.isDisposed ()) {
- newSelectedItems [pos++] = item;
- }
- }
- selectedItems = newSelectedItems;
- }
-
- if (anchorItem != null && anchorItem.isDisposed ()) anchorItem = null;
- if (lastClickedItem != null && lastClickedItem.isDisposed ()) lastClickedItem = null;
- if (focusItem != null && focusItem.isDisposed ()) {
- TableItem newFocusItem = count > 0 ? items [count - 1] : null;
- setFocusItem (newFocusItem, false);
- }
- itemsCount = count;
- if (columns.length == 0) updateHorizontalBar ();
- } else {
- redrawStart = itemsCount;
- redrawEnd = count - 1;
- TableItem[] newItems = new TableItem [count];
- System.arraycopy (items, 0, newItems, 0, itemsCount);
- items = newItems;
- for (int i = itemsCount; i < count; i++) {
- items [i] = new TableItem (this, SWT.NONE, i, false);
- itemsCount++;
- }
- if (oldCount == 0) focusItem = items [0];
- }
-
- updateVerticalBar ();
- /*
- * If this is the focus control and the item count is going from 0->!0 or !0->0 then the
- * receiver must be redrawn to ensure that its boundary focus ring is updated.
- */
- if ((oldCount == 0 || itemsCount == 0) && isFocusControl ()) {
- redraw ();
- return;
- }
- redrawItems (redrawStart, redrawEnd, false);
-}
-boolean setItemHeight (int value) {
- boolean update = !customHeightSet || itemHeight < value;
- if (update) itemHeight = value;
- return update;
-}
-/**
- * Marks the receiver's lines as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise. Note that some platforms draw grid lines
- * while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLinesVisible (boolean value) {
- checkWidget ();
- if (linesVisible == value) return; /* no change */
- linesVisible = value;
- redraw ();
-}
-public void setMenu (Menu menu) {
- super.setMenu (menu);
- header.setMenu (menu);
-}
-public void setRedraw (boolean value) {
- checkWidget();
- if (value) {
- if (--drawCount == 0) {
- if (items.length - itemsCount > 3) {
- TableItem[] newItems = new TableItem [itemsCount];
- System.arraycopy (items, 0, newItems, 0, itemsCount);
- items = newItems;
- }
- updateVerticalBar ();
- updateHorizontalBar ();
- }
- } else {
- drawCount++;
- }
- super.setRedraw (value);
- header.setRedraw (value);
-}
-/**
- * Sets the receiver's selection to the given item.
- * The current selection is cleared before the new item is selected.
- * <p>
- * If the item is not in the receiver, then it is ignored.
- * </p>
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection (TableItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (new TableItem[] {item}, true);
-}
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- * </p>
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the items has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int[])
- * @see Table#setSelection(int[])
- */
-public void setSelection (TableItem[] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (items, true);
-}
-void setSelection (TableItem[] items, boolean updateViewport) {
- if (items.length == 0 || ((style & SWT.SINGLE) != 0 && items.length > 1)) {
- deselectAll ();
- return;
- }
- TableItem[] oldSelection = selectedItems;
-
- /* remove null and duplicate items */
- int index = 0;
- selectedItems = new TableItem [items.length]; /* assume all valid items */
- for (int i = 0; i < items.length; i++) {
- TableItem item = items [i];
- if (item != null && item.parent == this && !item.isSelected ()) {
- selectedItems [index++] = item;
- }
- }
- if (index != items.length) {
- /* an invalid item was provided so resize the array accordingly */
- TableItem[] temp = new TableItem [index];
- System.arraycopy (selectedItems, 0, temp, 0, index);
- selectedItems = temp;
- }
- if (selectedItems.length == 0) { /* no valid items */
- deselectAll ();
- return;
- }
-
- if (hasFocus () || (style & SWT.HIDE_SELECTION) == 0) {
- for (int i = 0; i < oldSelection.length; i++) {
- if (!oldSelection [i].isSelected ()) {
- redrawItem (oldSelection [i].index, true);
- }
- }
- for (int i = 0; i < selectedItems.length; i++) {
- redrawItem (selectedItems [i].index, true);
- }
- }
- if (updateViewport) {
- showItem (selectedItems [0]);
- setFocusItem (selectedItems [0], true);
- }
-}
-/**
- * Sets the column used by the sort indicator for the receiver. A null
- * value will clear the sort indicator. The current sort column is cleared
- * before the new column is set.
- *
- * @param column the column used by the sort indicator or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the column is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortColumn (TableColumn column) {
- checkWidget ();
- if (column != null && column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (column == sortColumn) return;
- if (sortColumn != null && !sortColumn.isDisposed ()) {
- sortColumn.setSortDirection (SWT.NONE);
- }
- sortColumn = column;
- if (sortColumn != null) {
- sortColumn.setSortDirection (sortDirection);
- }
-}
-/**
- * Sets the direction of the sort indicator for the receiver. The value
- * can be one of <code>UP</code>, <code>DOWN</code> or <code>NONE</code>.
- *
- * @param direction the direction of the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortDirection (int direction) {
- checkWidget ();
- if (direction != SWT.UP && direction != SWT.DOWN && direction != SWT.NONE) return;
- sortDirection = direction;
- if (sortColumn == null || sortColumn.isDisposed ()) return;
- sortColumn.setSortDirection (sortDirection);
-}
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * The current selection is first cleared, then the new item is selected.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int)
- */
-public void setSelection (int index) {
- checkWidget ();
- deselectAll ();
- if (!(0 <= index && index < itemsCount)) return;
- selectItem (items [index], false);
- setFocusItem (items [index], true);
- redrawItem (index, true);
- showSelection ();
-}
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- * </p>
- *
- * @param start the start index of the items to select
- * @param end the end index of the items to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int,int)
- */
-public void setSelection (int start, int end) {
- checkWidget ();
- deselectAll ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- if (itemsCount == 0 || start >= itemsCount) return;
- start = Math.max (0, start);
- end = Math.min (end, itemsCount - 1);
- select (start, end);
- setFocusItem (items [start], true);
- showSelection ();
-}
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- * </p>
- *
- * @param indices the indices of the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int[])
- */
-public void setSelection (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- select (indices);
- int focusIndex = -1;
- for (int i = 0; i < indices.length && focusIndex == -1; i++) {
- if (0 <= indices [i] && indices [i] < itemsCount) {
- focusIndex = indices [i];
- }
- }
- if (focusIndex != -1) setFocusItem (items [focusIndex], true);
- showSelection ();
-}
-/**
- * Sets the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items
- * are scrolled or new items are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemsCount)) return;
- int visibleItemCount = (clientArea.height - getHeaderHeight ()) / itemHeight;
- if (itemsCount <= visibleItemCount) return;
- index = Math.min (index, itemsCount - visibleItemCount);
- if (index == topIndex) return;
-
- update ();
- int change = topIndex - index;
- topIndex = index;
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) vBar.setSelection (topIndex);
- if (drawCount <= 0) {
- GC gc = new GC (this);
- gc.copyArea (0, 0, clientArea.width, clientArea.height, 0, change * itemHeight);
- gc.dispose ();
- }
-}
-/**
- * Shows the column. If the column is already showing in the receiver,
- * this method simply returns. Otherwise, the columns are scrolled until
- * the column is visible.
- *
- * @param column the column to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the column is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the column has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void showColumn (TableColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (column.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (column.parent != this) return;
-
- int x = column.getX ();
- int rightX = x + column.width;
- if (0 <= x && rightX <= clientArea.width) return; /* column is fully visible */
-
- headerHideToolTip ();
- int absX = 0; /* the X of the column irrespective of the horizontal scroll */
- TableColumn[] orderedColumns = getOrderedColumns ();
- for (int i = 0; i < column.getOrderIndex (); i++) {
- absX += orderedColumns [i].width;
- }
- if (x < clientArea.x) { /* column is to left of viewport */
- horizontalOffset = absX;
- } else {
- horizontalOffset = absX + column.width - clientArea.width;
- }
- ScrollBar hBar = getHorizontalBar ();
- if (hBar != null) hBar.setSelection (horizontalOffset);
- redraw ();
- if (drawCount <= 0 && header.isVisible ()) header.redraw ();
-}
-/**
- * Shows the item. If the item is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the item is visible.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#showSelection()
- */
-public void showItem (TableItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (item.parent != this) return;
-
- int index = item.index;
- int visibleItemCount = (clientArea.height - getHeaderHeight ()) / itemHeight;
- /* nothing to do if item is already in viewport */
- if (topIndex <= index && index < topIndex + visibleItemCount) return;
-
- if (index <= topIndex) {
- /* item is above current viewport, so show on top */
- setTopIndex (item.index);
- } else {
- /* item is below current viewport, so show on bottom */
- visibleItemCount = Math.max (visibleItemCount, 1); /* item to show should be top item */
- setTopIndex (Math.min (index - visibleItemCount + 1, itemsCount - 1));
- }
-}
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#showItem(TableItem)
- */
-public void showSelection () {
- checkWidget ();
- if (selectedItems.length == 0) return;
- showItem (selectedItems [0]);
-}
-void sortDescent (int [] items) {
- /* Shell Sort from K&R, pg 108 */
- int length = items.length;
- for (int gap = length / 2; gap > 0; gap /= 2) {
- for (int i = gap; i < length; i++) {
- for (int j = i - gap; j >= 0; j -= gap) {
- if (items [j] <= items [j + gap]) {
- int swap = items [j];
- items [j] = items [j + gap];
- items [j + gap] = swap;
- }
- }
- }
- }
-}
-void sortAscent (int [] items) {
- /* Shell Sort from K&R, pg 108 */
- int length = items.length;
- for (int gap = length / 2; gap > 0; gap /= 2) {
- for (int i = gap; i < length; i++) {
- for (int j = i - gap; j >= 0; j -= gap) {
- if (items [j] >= items [j + gap]) {
- int swap = items [j];
- items [j] = items [j + gap];
- items [j + gap] = swap;
- }
- }
- }
- }
-}
-void sortAscent (TableItem [] items) {
- /* Shell Sort from K&R, pg 108 */
- int length = items.length;
- for (int gap = length / 2; gap > 0; gap /= 2) {
- for (int i = gap; i < length; i++) {
- for (int j = i - gap; j >= 0; j -= gap) {
- if (items [j].index >= items [j + gap].index) {
- TableItem swap = items [j];
- items [j] = items [j + gap];
- items [j + gap] = swap;
- }
- }
- }
- }
-}
-void updateColumnWidth (TableColumn column, int width) {
- headerHideToolTip ();
- int oldWidth = column.width;
- int columnX = column.getX ();
- int x = columnX + oldWidth - 1; /* -1 ensures that grid line is included */
-
- update ();
- GC gc = new GC (this);
- gc.copyArea (x, 0, clientArea.width - x, clientArea.height, columnX + width - 1, 0); /* dest x -1 offsets x's -1 above */
- if (width > oldWidth) {
- /* column width grew */
- int change = width - oldWidth + 1; /* +1 offsets x's -1 above */
- /* -1/+1 below ensure that right bound of selection redraws correctly in column */
- redraw (x - 1, 0, change + 1, clientArea.height, false);
- } else {
- int change = oldWidth - width + 1; /* +1 offsets x's -1 above */
- redraw (clientArea.width - change, 0, change, clientArea.height, false);
- }
- /* the focus box must be repainted because its stipple may become shifted as a result of its new width */
- if (focusItem != null) redrawItem (focusItem.index, true);
-
- GC headerGC = new GC (header);
- if (drawCount <= 0 && header.getVisible ()) {
- Rectangle headerBounds = header.getClientArea ();
- header.update ();
- x -= 1; /* -1 ensures that full header column separator is included */
- headerGC.copyArea (x, 0, headerBounds.width - x, headerBounds.height, columnX + width - 2, 0); /* dest x -2 offsets x's -1s above */
- if (width > oldWidth) {
- /* column width grew */
- int change = width - oldWidth + 2; /* +2 offsets x's -1s above */
- header.redraw (x, 0, change, headerBounds.height, false);
- } else {
- int change = oldWidth - width + 2; /* +2 offsets x's -1s above */
- header.redraw (headerBounds.width - change, 0, change, headerBounds.height, false);
- }
- }
-
- column.width = width;
-
- /*
- * Notify column and all items of column width change so that display labels
- * can be recomputed if needed.
- */
- column.updateWidth (headerGC);
- headerGC.dispose ();
- for (int i = 0; i < itemsCount; i++) {
- items [i].updateColumnWidth (column, gc);
- }
- gc.dispose ();
-
- int maximum = 0;
- for (int i = 0; i < columns.length; i++) {
- maximum += columns [i].width;
- }
- ScrollBar hBar = getHorizontalBar ();
- if (hBar != null) {
- hBar.setMaximum (Math.max (1, maximum)); /* setting a value of 0 here is ignored */
- if (hBar.getThumb () != clientArea.width) {
- hBar.setThumb (clientArea.width);
- hBar.setPageIncrement (clientArea.width);
- }
- int oldHorizontalOffset = horizontalOffset; /* hBar.setVisible() can modify horizontalOffset */
- hBar.setVisible (clientArea.width < maximum);
- int selection = hBar.getSelection ();
- if (selection != oldHorizontalOffset) {
- horizontalOffset = selection;
- redraw ();
- if (drawCount <= 0 && header.getVisible ()) header.redraw ();
- }
- }
-
- column.sendEvent (SWT.Resize);
- TableColumn[] orderedColumns = getOrderedColumns ();
- for (int i = column.getOrderIndex () + 1; i < orderedColumns.length; i++) {
- if (!orderedColumns [i].isDisposed ()) {
- orderedColumns [i].sendEvent (SWT.Move);
- }
- }
-
- if (itemsCount == 0) redraw (); /* ensure that static focus rectangle updates properly */
-}
-/*
- * This is a naive implementation that computes the value from scratch.
- */
-void updateHorizontalBar () {
- if (drawCount > 0) return;
- ScrollBar hBar = getHorizontalBar ();
- if (hBar == null) return;
-
- int maxX = 0;
- if (columns.length > 0) {
- for (int i = 0; i < columns.length; i++) {
- maxX += columns [i].width;
- }
- } else {
- for (int i = 0; i < itemsCount; i++) {
- Rectangle itemBounds = items [i].getCellBounds (0);
- maxX = Math.max (maxX, itemBounds.x + itemBounds.width + horizontalOffset);
- }
- }
-
- int clientWidth = clientArea.width;
- if (maxX != hBar.getMaximum ()) {
- hBar.setMaximum (Math.max (1, maxX)); /* setting a value of 0 here is ignored */
- }
- int thumb = Math.min (clientWidth, maxX);
- if (thumb != hBar.getThumb ()) {
- hBar.setThumb (thumb);
- hBar.setPageIncrement (thumb);
- }
- hBar.setVisible (clientWidth < maxX);
-
- /* reclaim any space now left on the right */
- if (maxX < horizontalOffset + thumb) {
- horizontalOffset = maxX - thumb;
- hBar.setSelection (horizontalOffset);
- redraw ();
- } else {
- int selection = hBar.getSelection ();
- if (selection != horizontalOffset) {
- horizontalOffset = selection;
- redraw ();
- }
- }
-}
-/*
- * Update the horizontal bar, if needed, in response to an item change (eg.- created,
- * disposed, expanded, etc.). newRightX is the new rightmost X value of the item,
- * and rightXchange is the change that led to the item's rightmost X value becoming
- * newRightX (so oldRightX + rightXchange = newRightX)
- */
-void updateHorizontalBar (int newRightX, int rightXchange) {
- if (drawCount > 0) return;
- ScrollBar hBar = getHorizontalBar ();
- if (hBar == null) return;
-
- newRightX += horizontalOffset;
- int barMaximum = hBar.getMaximum ();
- if (newRightX > barMaximum) { /* item has extended beyond previous maximum */
- hBar.setMaximum (newRightX);
- int clientAreaWidth = clientArea.width;
- int thumb = Math.min (newRightX, clientAreaWidth);
- hBar.setThumb (thumb);
- hBar.setPageIncrement (thumb);
- hBar.setVisible (clientAreaWidth <= newRightX);
- return;
- }
-
- int previousRightX = newRightX - rightXchange;
- if (previousRightX != barMaximum) {
- /* this was not the rightmost item, so just check for client width change */
- int clientAreaWidth = clientArea.width;
- int thumb = Math.min (barMaximum, clientAreaWidth);
- hBar.setThumb (thumb);
- hBar.setPageIncrement (thumb);
- hBar.setVisible (clientAreaWidth <= barMaximum);
- return;
- }
- updateHorizontalBar (); /* must search for the new rightmost item */
-}
-void updateVerticalBar () {
- if (drawCount > 0) return;
- ScrollBar vBar = getVerticalBar ();
- if (vBar == null) return;
-
- int pageSize = (clientArea.height - getHeaderHeight ()) / itemHeight;
- int maximum = Math.max (1, itemsCount); /* setting a value of 0 here is ignored */
- if (maximum != vBar.getMaximum ()) {
- vBar.setMaximum (maximum);
- }
- int thumb = Math.min (pageSize, maximum);
- if (thumb != vBar.getThumb ()) {
- vBar.setThumb (thumb);
- vBar.setPageIncrement (thumb);
- }
- vBar.setVisible (pageSize < maximum);
-
- /* reclaim any space now left on the bottom */
- if (maximum < topIndex + thumb) {
- topIndex = maximum - thumb;
- vBar.setSelection (topIndex);
- redraw ();
- } else {
- int selection = vBar.getSelection ();
- if (selection != topIndex) {
- topIndex = selection;
- redraw ();
- }
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TableColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TableColumn.java
deleted file mode 100644
index 7ef48a0fdd..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TableColumn.java
+++ /dev/null
@@ -1,762 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a column in a table widget.
- * <p><dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd> Move, Resize, Selection</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT and CENTER may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TableColumn extends Item {
- Table parent;
- String displayText = "";
- int width;
- boolean moveable, resizable = true;
- int sort = SWT.NONE;
- String toolTipText;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableColumn (Table parent, int style) {
- this (parent, style, checkNull (parent).columns.length);
-}
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableColumn (Table parent, int style, int index) {
- super (parent, checkStyle (style), index);
- if (!(0 <= index && index <= parent.columns.length)) error (SWT.ERROR_INVALID_RANGE);
- this.parent = parent;
- parent.createItem (this, index);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize, typedListener);
- addListener (SWT.Move, typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the column header is selected.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-static Table checkNull (Table table) {
- if (table == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return table;
-}
-static int checkStyle (int style) {
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-void computeDisplayText (GC gc) {
- int availableWidth = width - 2 * parent.getHeaderPadding ();
- if (image != null) {
- availableWidth -= image.getBounds ().width;
- availableWidth -= Table.MARGIN_IMAGE;
- }
- if (sort != SWT.NONE) {
- availableWidth -= parent.arrowBounds.width;
- availableWidth -= Table.MARGIN_IMAGE;
- }
- String text = this.text;
- int textWidth = gc.textExtent (text, SWT.DRAW_MNEMONIC).x;
- if (textWidth <= availableWidth) {
- displayText = text;
- return;
- }
-
- /* Ellipsis will be needed, so subtract their width from the available text width */
- int ellipsisWidth = gc.stringExtent (Table.ELLIPSIS).x;
- availableWidth -= ellipsisWidth;
- if (availableWidth <= 0) {
- displayText = Table.ELLIPSIS;
- return;
- }
-
- /* Make initial guess. */
- int index = Math.min (availableWidth / gc.getFontMetrics ().getAverageCharWidth (), text.length ());
- textWidth = gc.textExtent (text.substring (0, index), SWT.DRAW_MNEMONIC).x;
-
- /* Initial guess is correct. */
- if (availableWidth == textWidth) {
- displayText = text.substring (0, index) + Table.ELLIPSIS;
- return;
- }
-
- /* Initial guess is too high, so reduce until fit is found. */
- if (availableWidth < textWidth) {
- do {
- index--;
- if (index < 0) {
- displayText = Table.ELLIPSIS;
- return;
- }
- text = text.substring (0, index);
- textWidth = gc.textExtent (text, SWT.DRAW_MNEMONIC).x;
- } while (availableWidth < textWidth);
- displayText = text + Table.ELLIPSIS;
- return;
- }
-
- /* Initial guess is too low, so increase until overrun is found. */
- while (textWidth < availableWidth) {
- index++;
- textWidth = gc.textExtent (text.substring (0, index), SWT.DRAW_MNEMONIC).x;
- }
- displayText = text.substring (0, index - 1) + Table.ELLIPSIS;
-}
-public void dispose () {
- if (isDisposed ()) return;
- Rectangle parentBounds = parent.clientArea;
- int x = getX ();
- int index = getIndex ();
- int orderIndex = getOrderIndex ();
- int nextColumnAlignment = parent.columns.length > 1 ? parent.columns [1].getAlignment () : SWT.LEFT;
- Table parent = this.parent;
- dispose (true);
-
- int width = parentBounds.width - x;
- parent.redraw (x, 0, width, parentBounds.height, false);
- /*
- * If column 0 was disposed then the new column 0 must be redrawn if it appears to the
- * left of the disposed column in the column order AND one the following are true:
- * - the parent has style CHECK, since these will now appear in the new column 0
- * - the new column 0 had non-left alignment before the dispose, since the parent will have
- * changed this to LEFT in the call to dispose(true)
- */
- if (index == 0 && ((parent.style & SWT.CHECK) != 0 || nextColumnAlignment != SWT.LEFT)) {
- if (parent.columns.length > 0) {
- TableColumn newColumn0 = parent.columns [0];
- if (newColumn0.getOrderIndex () < orderIndex) {
- int newColumn0x = newColumn0.getX ();
- parent.redraw (newColumn0x, 0, newColumn0.width, parentBounds.height, false);
- /* if the alignment changed then the header text must be repainted with its new alignment */
- if (nextColumnAlignment != SWT.LEFT && parent.getHeaderVisible () && parent.drawCount <= 0) {
- parent.header.redraw (newColumn0x, 0, newColumn0.width, parent.header.getClientArea ().height, false);
- }
- }
- }
- }
- if (parent.drawCount <= 0 && parent.getHeaderVisible ()) {
- parent.header.redraw (x, 0, width, parent.getHeaderHeight (), false);
- }
-}
-void dispose (boolean notifyParent) {
- super.dispose (); /* super is intentional here */
- if (notifyParent) parent.destroyItem (this);
- parent = null;
-}
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget ();
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-/*
- * Returns the width of the header's content
- * (image + text + sort arrow + internal margins)
- */
-int getContentWidth (GC gc, boolean useDisplayText) {
- int contentWidth = 0;
- String text = useDisplayText ? displayText : this.text;
- if (text.length () > 0) {
- contentWidth += gc.textExtent (text, SWT.DRAW_MNEMONIC).x;
- }
- if (image != null) {
- contentWidth += image.getBounds ().width;
- if (text.length () > 0) contentWidth += Table.MARGIN_IMAGE;
- }
- if (sort != SWT.NONE) {
- contentWidth += parent.arrowBounds.width;
- if (text.length () > 0 || image != null) {
- contentWidth += Table.MARGIN_IMAGE;
- }
- }
- return contentWidth;
-}
-int getIndex () {
- TableColumn[] columns = parent.columns;
- for (int i = 0; i < columns.length; i++) {
- if (columns [i] == this) return i;
- }
- return -1;
-}
-/**
- * Gets the moveable attribute. A column that is
- * not moveable cannot be reordered by the user
- * by dragging the header but may be reordered
- * by the programmer.
- *
- * @return the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public boolean getMoveable () {
- checkWidget ();
- return moveable;
-}
-int getOrderIndex () {
- TableColumn[] orderedColumns = parent.orderedColumns;
- if (orderedColumns == null) return getIndex ();
- for (int i = 0; i < orderedColumns.length; i++) {
- if (orderedColumns [i] == this) return i;
- }
- return -1;
-}
-/**
- * Returns the receiver's parent, which must be a <code>Table</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Table getParent () {
- checkWidget ();
- return parent;
-}
-int getPreferredWidth () {
- if (!parent.getHeaderVisible ()) return 0;
- GC gc = new GC (parent);
- int result = getContentWidth (gc, false);
- gc.dispose ();
- return result + 2 * parent.getHeaderPadding ();
-}
-/**
- * Gets the resizable attribute. A column that is
- * not resizable cannot be dragged by the user but
- * may be resized by the programmer.
- *
- * @return the resizable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getResizable () {
- checkWidget ();
- return resizable;
-}
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget ();
- return width;
-}
-int getX () {
- TableColumn[] orderedColumns = parent.getOrderedColumns ();
- int index = getOrderIndex ();
- int result = -parent.horizontalOffset;
- for (int i = 0; i < index; i++) {
- result += orderedColumns [i].width;
- }
- return result;
-}
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void pack () {
- checkWidget ();
- TableItem[] items = parent.items;
- int index = getIndex ();
- int newWidth = getPreferredWidth ();
- for (int i = 0; i < parent.itemsCount; i++) {
- int width = items [i].getPreferredWidth (index);
- /* ensure that receiver and parent were not disposed in a callback */
- if (parent.isDisposed () || isDisposed ()) return;
- if (!items [i].isDisposed ()) {
- newWidth = Math.max (newWidth, width);
- }
- }
- if (newWidth != width) parent.updateColumnWidth (this, newWidth);
-}
-void paint (GC gc) {
- int padding = parent.getHeaderPadding ();
-
- int x = getX ();
- int startX = x + padding;
- if ((style & SWT.LEFT) == 0) {
- int contentWidth = getContentWidth (gc, true);
- if ((style & SWT.RIGHT) != 0) {
- startX = Math.max (startX, x + width - padding - contentWidth);
- } else { /* SWT.CENTER */
- startX = Math.max (startX, x + (width - contentWidth) / 2);
- }
- }
- int headerHeight = parent.getHeaderHeight ();
-
- /* restrict the clipping region to the header cell */
- gc.setClipping (
- x + padding,
- padding,
- width - 2 * padding,
- headerHeight - 2 * padding);
-
- if (image != null) {
- Rectangle imageBounds = image.getBounds ();
- int drawHeight = Math.min (imageBounds.height, headerHeight - 2 * padding);
- gc.drawImage (
- image,
- 0, 0,
- imageBounds.width, imageBounds.height,
- startX, (headerHeight - drawHeight) / 2,
- imageBounds.width, drawHeight);
- startX += imageBounds.width + Table.MARGIN_IMAGE;
- }
- if (displayText.length () > 0) {
- gc.setForeground (display.getSystemColor (SWT.COLOR_BLACK));
- int fontHeight = parent.fontHeight;
- gc.drawText (displayText, startX, (headerHeight - fontHeight) / 2, SWT.DRAW_MNEMONIC);
- startX += gc.textExtent (displayText, SWT.DRAW_MNEMONIC).x + Table.MARGIN_IMAGE;
- }
- if (sort != SWT.NONE) {
- Image image = sort == SWT.DOWN ? parent.getArrowDownImage () : parent.getArrowUpImage ();
- int y = (headerHeight - parent.arrowBounds.height) / 2;
- gc.drawImage (image, startX, y);
- }
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- removeListener (SWT.Selection, listener);
- removeListener (SWT.DefaultSelection, listener);
-}
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>.
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget ();
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- int index = getIndex ();
- if (index == -1 || index == 0) return; /* column 0 can only have left-alignment */
- alignment = checkBits (alignment, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
- if ((style & alignment) != 0) return; /* same value */
- style &= ~(SWT.LEFT | SWT.CENTER | SWT.RIGHT);
- style |= alignment;
- int x = getX ();
- parent.redraw (x, 0, width, parent.clientArea.height, false);
- if (parent.drawCount <= 0 && parent.getHeaderVisible ()) {
- /* don't damage the header's drawn borders */
- parent.header.redraw (x, 1, width - 2, parent.getHeaderHeight () - 3, false);
- }
-}
-public void setImage (Image value) {
- checkWidget ();
- if (value == image) return;
- if (value != null && value.equals (image)) return; /* same value */
- super.setImage (value);
-
- /* An image width change may affect the space available for the column's displayText. */
- GC gc = new GC (parent);
- computeDisplayText (gc);
- gc.dispose ();
-
- /*
- * If this is the first image being put into the header then the header
- * height may be adjusted, in which case a full redraw is needed.
- */
- if (parent.headerImageHeight == 0) {
- int oldHeaderHeight = parent.getHeaderHeight ();
- parent.setHeaderImageHeight (value.getBounds ().height);
- if (oldHeaderHeight != parent.getHeaderHeight ()) {
- /* parent header height changed */
- if (parent.drawCount <= 0 && parent.getHeaderVisible ()) {
- parent.header.redraw ();
- }
- parent.redraw ();
- return;
- }
- }
-
- if (parent.drawCount <= 0 && parent.getHeaderVisible ()) {
- /* don't damage the header's drawn borders */
- parent.header.redraw (getX (), 1, width - 2, parent.getHeaderHeight () - 3, false);
- }
-}
-/**
- * Sets the moveable attribute. A column that is
- * moveable can be reordered by the user by dragging
- * the header. A column that is not moveable cannot be
- * dragged by the user but may be reordered
- * by the programmer.
- *
- * @param moveable the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setColumnOrder(int[])
- * @see Table#getColumnOrder()
- * @see TableColumn#getMoveable()
- * @see SWT#Move
- *
- * @since 3.1
- */
-public void setMoveable (boolean moveable) {
- checkWidget ();
- this.moveable = moveable;
-}
-/**
- * Sets the resizable attribute. A column that is
- * resizable can be resized by the user dragging the
- * edge of the header. A column that is not resizable
- * cannot be dragged by the user but may be resized
- * by the programmer.
- *
- * @param resizable the resize attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setResizable (boolean value) {
- checkWidget ();
- resizable = value;
-}
-void setSortDirection (int value) {
- if (value == sort) return;
- boolean widthChange = value == SWT.NONE || sort == SWT.NONE;
- sort = value;
- if (widthChange) {
- /*
- * adding/removing the sort arrow decreases/increases the width that is
- * available for the column's header text, so recompute the display text
- */
- GC gc = new GC (parent);
- computeDisplayText (gc);
- gc.dispose ();
- }
- if (parent.drawCount <= 0 && parent.getHeaderVisible ()) {
- /* don't damage the header's drawn borders */
- parent.header.redraw (getX (), 1, width - 2, parent.getHeaderHeight () - 3, false);
- }
-}
-public void setText (String value) {
- checkWidget ();
- if (value == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (value.equals (text)) return; /* same value */
- super.setText (value);
- GC gc = new GC (parent);
- computeDisplayText (gc);
- gc.dispose ();
- if (parent.drawCount <= 0 && parent.getHeaderVisible ()) {
- /* don't damage the header's drawn borders */
- parent.header.redraw (getX (), 1, width - 2, parent.getHeaderHeight () - 3, false);
- }
-}
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setToolTipText (String string) {
- checkWidget ();
- if (toolTipText == string) return;
- if (toolTipText != null && toolTipText.equals (string)) return;
- toolTipText = string;
- if (parent.toolTipShell == null) return; /* tooltip not currently showing */
- if (((Integer) parent.toolTipShell.getData ()).intValue () != getIndex ()) return; /* tooltip showing for different column */
- parent.headerUpdateToolTip (getX () + (width / 2)); /* update the tooltip text */
-}
-/**
- * Sets the width of the receiver.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int value) {
- checkWidget ();
- if (value < 0) return;
- if (width == value) return; /* same value */
- parent.updateColumnWidth (this, value);
-}
-void updateFont (GC gc) {
- computeDisplayText (gc);
-}
-/*
- * Perform any internal changes necessary to reflect a changed width.
- */
-void updateWidth (GC gc) {
- String oldDisplayText = displayText;
- computeDisplayText (gc);
- /* the header must be damaged if the display text has changed or if the alignment is not LEFT */
- if (parent.getHeaderVisible ()) {
- if ((style & SWT.LEFT) == 0 || !oldDisplayText.equals (displayText)) {
- int padding = parent.getHeaderPadding ();
- parent.header.redraw (getX () + padding, 0, width - padding, parent.getHeaderHeight (), false);
- }
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TableItem.java
deleted file mode 100644
index e4c3476995..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TableItem.java
+++ /dev/null
@@ -1,2032 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents an item in a table.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TableItem extends Item {
- Table parent;
- int index = -1;
- boolean checked, grayed, cached;
-
- String[] texts;
- int[] textWidths = new int [1]; /* cached string measurements */
- int customWidth = -1; /* width specified by Measure callback */
- int fontHeight; /* cached item font height */
- int[] fontHeights;
- int imageIndent;
- Image[] images;
- Color foreground, background;
- String[] displayTexts;
- Color[] cellForegrounds, cellBackgrounds;
- Font font;
- Font[] cellFonts;
-
- static final int MARGIN_TEXT = 3; /* the left and right margins within the text's space */
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableItem (Table parent, int style) {
- this (parent, style, checkNull (parent).itemsCount);
-}
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableItem (Table parent, int style, int index) {
- this (parent, style, index, true);
-}
-TableItem (Table parent, int style, int index, boolean notifyParent) {
- super (parent, style);
- int validItemIndex = parent.itemsCount;
- if (!(0 <= index && index <= validItemIndex)) error (SWT.ERROR_INVALID_RANGE);
- this.parent = parent;
- this.index = index;
- int columnCount = parent.columns.length;
- if (columnCount > 0) {
- displayTexts = new String [columnCount];
- if (columnCount > 1) {
- texts = new String [columnCount];
- textWidths = new int [columnCount];
- images = new Image [columnCount];
- }
- }
- if (notifyParent) parent.createItem (this);
-}
-/*
- * Updates internal structures in the receiver and its child items to handle the creation of a new column.
- */
-void addColumn (TableColumn column) {
- int index = column.getIndex ();
- int columnCount = parent.columns.length;
-
- if (columnCount > 1) {
- if (columnCount == 2) {
- texts = new String [2];
- } else {
- String[] newTexts = new String [columnCount];
- System.arraycopy (texts, 0, newTexts, 0, index);
- System.arraycopy (texts, index, newTexts, index + 1, columnCount - index - 1);
- texts = newTexts;
- }
- if (index == 0) {
- texts [1] = text;
- text = ""; //$NON-NLS-1$
- }
-
- if (columnCount == 2) {
- images = new Image [2];
- } else {
- Image[] newImages = new Image [columnCount];
- System.arraycopy (images, 0, newImages, 0, index);
- System.arraycopy (images, index, newImages, index + 1, columnCount - index - 1);
- images = newImages;
- }
- if (index == 0) {
- images [1] = image;
- image = null;
- }
-
- int[] newTextWidths = new int [columnCount];
- System.arraycopy (textWidths, 0, newTextWidths, 0, index);
- System.arraycopy (textWidths, index, newTextWidths, index + 1, columnCount - index - 1);
- textWidths = newTextWidths;
- } else {
- customWidth = -1; /* columnCount == 1 */
- }
-
- /*
- * The length of displayTexts always matches the parent's column count, unless this
- * count is zero, in which case displayTexts is null.
- */
- String[] newDisplayTexts = new String [columnCount];
- if (columnCount > 1) {
- System.arraycopy (displayTexts, 0, newDisplayTexts, 0, index);
- System.arraycopy (displayTexts, index, newDisplayTexts, index + 1, columnCount - index - 1);
- }
- displayTexts = newDisplayTexts;
-
- if (cellBackgrounds != null) {
- Color[] newCellBackgrounds = new Color [columnCount];
- System.arraycopy (cellBackgrounds, 0, newCellBackgrounds, 0, index);
- System.arraycopy (cellBackgrounds, index, newCellBackgrounds, index + 1, columnCount - index - 1);
- cellBackgrounds = newCellBackgrounds;
- }
- if (cellForegrounds != null) {
- Color[] newCellForegrounds = new Color [columnCount];
- System.arraycopy (cellForegrounds, 0, newCellForegrounds, 0, index);
- System.arraycopy (cellForegrounds, index, newCellForegrounds, index + 1, columnCount - index - 1);
- cellForegrounds = newCellForegrounds;
- }
- if (cellFonts != null) {
- Font[] newCellFonts = new Font [columnCount];
- System.arraycopy (cellFonts, 0, newCellFonts, 0, index);
- System.arraycopy (cellFonts, index, newCellFonts, index + 1, columnCount - index - 1);
- cellFonts = newCellFonts;
-
- int[] newFontHeights = new int [columnCount];
- System.arraycopy (fontHeights, 0, newFontHeights, 0, index);
- System.arraycopy (fontHeights, index, newFontHeights, index + 1, columnCount - index - 1);
- fontHeights = newFontHeights;
- }
-
- if (index == 0 && columnCount > 1) {
- /*
- * The new second column may have more width available to it than it did when it was
- * the first column if checkboxes are being shown, so recompute its displayText if needed.
- */
- if ((parent.style & SWT.CHECK) != 0) {
- GC gc = new GC (parent);
- gc.setFont (getFont (1, false));
- computeDisplayText (1, gc);
- gc.dispose ();
- }
- }
-}
-static Table checkNull (Table table) {
- if (table == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return table;
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-void clear () {
- checked = grayed = false;
- texts = null;
- textWidths = new int [1];
- fontHeight = 0;
- fontHeights = null;
- images = null;
- foreground = background = null;
- displayTexts = null;
- cellForegrounds = cellBackgrounds = null;
- font = null;
- cellFonts = null;
- cached = false;
- text = "";
- image = null;
-
- int columnCount = parent.columns.length;
- if (columnCount > 0) {
- displayTexts = new String [columnCount];
- if (columnCount > 1) {
- texts = new String [columnCount];
- textWidths = new int [columnCount];
- images = new Image [columnCount];
- }
- }
-}
-void computeDisplayText (int columnIndex, GC gc) {
- if ((parent.style & SWT.VIRTUAL) != 0 && !cached) return; /* nothing to do */
-
- int columnCount = parent.columns.length;
- if (columnCount == 0) {
- String text = getText (0, false);
- textWidths [columnIndex] = gc.stringExtent (text).x;
- return;
- }
-
- TableColumn column = parent.columns [columnIndex];
- int availableWidth = column.width - 2 * parent.getCellPadding () - 2 * MARGIN_TEXT;
- if (columnIndex == 0) {
- availableWidth -= parent.col0ImageWidth;
- if (parent.col0ImageWidth > 0) availableWidth -= Table.MARGIN_IMAGE;
- if ((parent.style & SWT.CHECK) != 0) {
- availableWidth -= parent.checkboxBounds.width;
- availableWidth -= Table.MARGIN_IMAGE;
- }
- } else {
- Image image = getImage (columnIndex, false);
- if (image != null) {
- availableWidth -= image.getBounds ().width;
- availableWidth -= Table.MARGIN_IMAGE;
- }
- }
-
- String text = getText (columnIndex, false);
- int textWidth = gc.stringExtent (text).x;
- if (textWidth <= availableWidth) {
- displayTexts [columnIndex] = text;
- textWidths [columnIndex] = textWidth;
- return;
- }
-
- /* Ellipsis will be needed, so subtract their width from the available text width */
- int ellipsisWidth = gc.stringExtent (Table.ELLIPSIS).x;
- availableWidth -= ellipsisWidth;
- if (availableWidth <= 0) {
- displayTexts [columnIndex] = Table.ELLIPSIS;
- textWidths [columnIndex] = ellipsisWidth;
- return;
- }
-
- /* Make initial guess. */
- int index = Math.min (availableWidth / gc.getFontMetrics ().getAverageCharWidth (), text.length ());
- textWidth = gc.stringExtent (text.substring (0, index)).x;
-
- /* Initial guess is correct. */
- if (availableWidth == textWidth) {
- displayTexts [columnIndex] = text.substring (0, index) + Table.ELLIPSIS;
- textWidths [columnIndex] = textWidth + ellipsisWidth;
- return;
- }
-
- /* Initial guess is too high, so reduce until fit is found. */
- if (availableWidth < textWidth) {
- do {
- index--;
- if (index < 0) {
- displayTexts [columnIndex] = Table.ELLIPSIS;
- textWidths [columnIndex] = ellipsisWidth;
- return;
- }
- text = text.substring (0, index);
- textWidth = gc.stringExtent (text).x;
- } while (availableWidth < textWidth);
- displayTexts [columnIndex] = text + Table.ELLIPSIS;
- textWidths [columnIndex] = textWidth + ellipsisWidth;
- return;
- }
-
- /* Initial guess is too low, so increase until overrun is found. */
- int previousWidth = 0;
- while (textWidth < availableWidth) {
- index++;
- previousWidth = textWidth;
- textWidth = gc.stringExtent (text.substring (0, index)).x;
- }
- displayTexts [columnIndex] = text.substring (0, index - 1) + Table.ELLIPSIS;
- textWidths [columnIndex] = previousWidth + ellipsisWidth;
-}
-void computeDisplayTexts (GC gc) {
- if ((parent.style & SWT.VIRTUAL) != 0 && !cached) return; /* nothing to do */
-
- int columnCount = parent.columns.length;
- if (columnCount == 0) return;
-
- for (int i = 0; i < columnCount; i++) {
- gc.setFont (getFont (i, false));
- computeDisplayText (i, gc);
- }
-}
-/*
- * Computes the cached text widths.
- */
-void computeTextWidths (GC gc) {
- if ((parent.style & SWT.VIRTUAL) != 0 && !cached) return; /* nothing to do */
-
- int validColumnCount = Math.max (1, parent.columns.length);
- textWidths = new int [validColumnCount];
- for (int i = 0; i < textWidths.length; i++) {
- String value = getDisplayText (i);
- if (value != null) {
- gc.setFont (getFont (i, false));
- textWidths [i] = gc.stringExtent (value).x;
- }
- }
-}
-public void dispose () {
- if (isDisposed ()) return;
- Table parent = this.parent;
- int startIndex = index;
- int endIndex = parent.itemsCount - 1;
- dispose (true);
- parent.redrawItems (startIndex, endIndex, false);
-}
-void dispose (boolean notifyParent) {
- if (isDisposed ()) return;
- if (notifyParent) parent.destroyItem (this);
- super.dispose (); /* super is intentional here */
- background = foreground = null;
- cellBackgrounds = cellForegrounds = null;
- font = null;
- cellFonts = null;
- images = null;
- texts = displayTexts = null;
- textWidths = fontHeights = null;
- parent = null;
-}
-/**
- * Returns the receiver's background color.
- *
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public Color getBackground () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (background != null) return background;
- return parent.getBackground ();
-}
-/**
- * Returns the background color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Color getBackground (int columnIndex) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return getBackground ();
- if (cellBackgrounds == null || cellBackgrounds [columnIndex] == null) return getBackground ();
- return cellBackgrounds [columnIndex];
-}
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Rectangle getBounds () {
- checkWidget ();
- return getBounds (true);
-}
-Rectangle getBounds (boolean checkData) {
- if (checkData && !parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int x = getTextX (0);
- int width = textWidths [0] + 2 * MARGIN_TEXT;
- if (parent.columns.length > 0) {
- TableColumn column = parent.columns [0];
- int right = column.getX () + column.width;
- if (x + width > right) {
- width = Math.max (0, right - x);
- }
- }
- return new Rectangle (x, parent.getItemY (this), width, parent.itemHeight);
-}
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent at a column in the table.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding column rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds (int columnIndex) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- TableColumn[] columns = parent.columns;
- int columnCount = columns.length;
- int validColumnCount = Math.max (1, columnCount);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) {
- return new Rectangle (0, 0, 0, 0);
- }
- /*
- * If there are no columns then this is the bounds of the receiver's content.
- */
- if (columnCount == 0) {
- int width = getContentWidth (0);
- return new Rectangle (
- getContentX (0),
- parent.getItemY (this),
- width,
- parent.itemHeight - 1);
- }
-
- TableColumn column = columns [columnIndex];
- if (columnIndex == 0) {
- /*
- * For column 0 this is bounds from the beginning of the content to the
- * end of the column.
- */
- int x = getContentX (0);
- int offset = x - column.getX ();
- int width = Math.max (0, column.width - offset - 1); /* max is for columns with small widths */
- return new Rectangle (x, parent.getItemY (this) + 1, width, parent.itemHeight - 1);
- }
- /*
- * For columns > 0 this is the bounds of the table cell.
- */
- return new Rectangle (column.getX (), parent.getItemY (this) + 1, column.width, parent.itemHeight - 1);
-}
-/*
- * Returns the full bounds of a cell in a table, regardless of its content.
- */
-Rectangle getCellBounds (int columnIndex) {
- int y = parent.getItemY (this);
- if (parent.columns.length == 0) {
- int width;
- if (customWidth != -1) {
- width = getContentX (0) + customWidth + parent.horizontalOffset;
- } else {
- int textPaintWidth = textWidths [0] + 2 * MARGIN_TEXT;
- width = getTextX (0) + textPaintWidth + parent.horizontalOffset;
- }
- return new Rectangle (-parent.horizontalOffset, y, width, parent.itemHeight);
- }
- TableColumn column = parent.columns [columnIndex];
- return new Rectangle (column.getX (), y, column.width, parent.itemHeight);
-}
-/*
- * Returns the bounds of the receiver's checkbox, or null if the parent's style does not
- * include SWT.CHECK.
- */
-Rectangle getCheckboxBounds () {
- if ((parent.getStyle () & SWT.CHECK) == 0) return null;
- Rectangle result = parent.checkboxBounds;
- if (parent.columns.length == 0) {
- result.x = parent.getCellPadding () - parent.horizontalOffset;
- } else {
- result.x = parent.columns [0].getX () + parent.getCellPadding ();
- }
- result.y = parent.getItemY (this) + (parent.itemHeight - result.height) / 2;
- return result;
-}
-/**
- * Returns <code>true</code> if the receiver is checked,
- * and false otherwise. When the parent does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the checked state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getChecked () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return checked;
-}
-int getContentWidth (int columnIndex) {
- int width = textWidths [columnIndex] + 2 * MARGIN_TEXT;
- if (columnIndex == 0) {
- width += parent.col0ImageWidth;
- if (parent.col0ImageWidth > 0) width += Table.MARGIN_IMAGE;
- } else {
- Image image = getImage (columnIndex, false);
- if (image != null) {
- width += image.getBounds ().width + Table.MARGIN_IMAGE;
- }
- }
- return width;
-}
-/*
- * Returns the x value where the receiver's content (ie.- its image or text) begins
- * for the specified column.
- */
-int getContentX (int columnIndex) {
- int minX = parent.getCellPadding ();
- if (columnIndex == 0) {
- Rectangle checkboxBounds = getCheckboxBounds ();
- if (checkboxBounds != null) {
- minX += checkboxBounds.width + Table.MARGIN_IMAGE;
- }
- }
-
- if (parent.columns.length == 0) return minX - parent.horizontalOffset; /* free first column */
-
- TableColumn column = parent.columns [columnIndex];
- int columnX = column.getX ();
- if ((column.style & SWT.LEFT) != 0) return columnX + minX;
-
- /* column is not left-aligned */
- int contentWidth = getContentWidth (columnIndex);
- int contentX = 0;
- if ((column.style & SWT.RIGHT) != 0) {
- contentX = column.width - parent.getCellPadding () - contentWidth;
- } else { /* SWT.CENTER */
- contentX = (column.width - contentWidth) / 2;
- }
- return Math.max (columnX + minX, columnX + contentX);
-}
-String getDisplayText (int columnIndex) {
- if (parent.columns.length == 0) return getText (0, false);
- String result = displayTexts [columnIndex];
- return result != null ? result : ""; //$NON-NLS-1$
-}
-/*
- * Returns the bounds that should be used for drawing a focus rectangle on the receiver
- */
-Rectangle getFocusBounds () {
- int x = 0;
- TableColumn[] columns = parent.columns;
- int[] columnOrder = parent.getColumnOrder ();
- if ((parent.style & SWT.FULL_SELECTION) != 0) {
- int col0index = columnOrder.length == 0 ? 0 : columnOrder [0];
- if (col0index == 0) {
- x = getTextX (0);
- } else {
- x = -parent.horizontalOffset;
- }
- } else {
- x = getTextX (0);
- }
-
- if (columns.length > 0) {
- /* ensure that the focus x does not start beyond the right bound of column 0 */
- int rightX = columns [0].getX () + columns [0].width;
- x = Math.min (x, rightX - 1);
- }
-
- int width;
- if (columns.length == 0) {
- if (customWidth != -1) {
- width = customWidth;
- } else {
- width = textWidths [0] + 2 * MARGIN_TEXT;
- }
- } else {
- TableColumn column;
- if ((parent.style & SWT.FULL_SELECTION) != 0) {
- column = columns [columnOrder [columnOrder.length - 1]];
- } else {
- column = columns [0];
- }
- width = column.getX () + column.width - x - 1;
- }
- return new Rectangle (
- x,
- parent.getItemY (this) + (parent.linesVisible ? 1 : 0),
- width,
- parent.itemHeight - (parent.linesVisible ? 1 : 0));
-}
-/**
- * Returns the font that the receiver will use to paint textual information for this item.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont () {
- checkWidget ();
- return getFont (true);
-}
-Font getFont (boolean checkData) {
- if (checkData && !parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (font != null) return font;
- return parent.getFont ();
-}
-/**
- * Returns the font that the receiver will use to paint textual information
- * for the specified cell in this item.
- *
- * @param index the column index
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont (int columnIndex) {
- checkWidget ();
- return getFont (columnIndex, true);
-}
-Font getFont (int columnIndex, boolean checkData) {
- if (checkData && !parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return getFont (checkData);
- if (cellFonts == null || cellFonts [columnIndex] == null) return getFont (checkData);
- return cellFonts [columnIndex];
-}
-int getFontHeight () {
- if (fontHeight != 0) return fontHeight;
- return parent.fontHeight;
-}
-int getFontHeight (int columnIndex) {
- if (fontHeights == null || fontHeights [columnIndex] == 0) return getFontHeight ();
- return fontHeights [columnIndex];
-}
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public Color getForeground () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (foreground != null) return foreground;
- return parent.getForeground ();
-}
-/**
- *
- * Returns the foreground color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Color getForeground (int columnIndex) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return getForeground ();
- if (cellForegrounds == null || cellForegrounds [columnIndex] == null) return getForeground ();
- return cellForegrounds [columnIndex];
-}
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the parent does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getGrayed () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return grayed;
-}
-/*
- * Returns the bounds representing the clickable region that should select the receiver.
- */
-Rectangle getHitBounds () {
- int[] columnOrder = parent.getColumnOrder ();
- int contentX = 0;
- if ((parent.style & SWT.FULL_SELECTION) != 0) {
- int col0index = columnOrder.length == 0 ? 0 : columnOrder [0];
- if (col0index == 0) {
- contentX = getContentX (0);
- } else {
- contentX = 0;
- }
- } else {
- contentX = getContentX (0);
- }
-
- int width = 0;
- TableColumn[] columns = parent.columns;
- if (columns.length == 0) {
- width = getContentWidth (0);
- } else {
- /*
- * If there are columns then this spans from the beginning of the receiver's column 0
- * image or text to the end of either column 0 or the last column (FULL_SELECTION).
- */
- TableColumn column;
- if ((parent.style & SWT.FULL_SELECTION) != 0) {
- column = columns [columnOrder [columnOrder.length - 1]];
- } else {
- column = columns [0];
- }
- width = column.getX () + column.width - contentX;
- }
- return new Rectangle (contentX, parent.getItemY (this), width, parent.itemHeight);
-}
-public Image getImage () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return super.getImage ();
-}
-/**
- * Returns the image stored at the given column index in the receiver,
- * or null if the image has not been set or if the column does not exist.
- *
- * @param index the column index
- * @return the image stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage (int columnIndex) {
- checkWidget ();
- return getImage (columnIndex, true);
-}
-Image getImage (int columnIndex, boolean checkData) {
- if (checkData && !parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return null;
- if (columnIndex == 0) return super.getImage (); /* super is intentional here */
- return images [columnIndex];
-}
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of an image at a column in the
- * table. An empty rectangle is returned if index exceeds
- * the index of the table's last column.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding image rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getImageBounds (int columnIndex) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return new Rectangle (0,0,0,0);
-
- int padding = parent.getCellPadding ();
- int startX = getContentX (columnIndex);
- int itemHeight = parent.itemHeight;
- int imageSpaceY = itemHeight - 2 * padding;
- int y = parent.getItemY (this);
- Image image = getImage (columnIndex, false);
- int drawWidth = 0;
- if (columnIndex == 0) {
- /* for column 0 all images have the same width */
- drawWidth = parent.col0ImageWidth;
- } else {
- if (image != null) drawWidth = image.getBounds ().width;
- }
- return new Rectangle (startX, y + padding, drawWidth, imageSpaceY);
-}
-/**
- * Gets the image indent.
- *
- * @return the indent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getImageIndent () {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return imageIndent; // TODO
-}
-String getNameText () {
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (!cached) return "*virtual*"; //$NON-NLS-1$
- }
- return super.getNameText ();
-}
-/**
- * Returns the receiver's parent, which must be a <code>Table</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Table getParent () {
- checkWidget ();
- return parent;
-}
-/*
- * Returns the receiver's ideal width for the specified columnIndex.
- */
-int getPreferredWidth (int columnIndex) {
- int width = 0;
- GC gc = new GC (parent);
- gc.setFont (getFont (columnIndex, false));
- width += gc.stringExtent (getText (columnIndex, false)).x + 2 * MARGIN_TEXT;
- if (columnIndex == 0) {
- if (parent.col0ImageWidth > 0) {
- width += parent.col0ImageWidth;
- width += Table.MARGIN_IMAGE;
- }
- } else {
- Image image = getImage (columnIndex, false);
- if (image != null) {
- width += image.getBounds ().width;
- width += Table.MARGIN_IMAGE;
- }
- }
-
- if (parent.hooks (SWT.MeasureItem)) {
- Event event = new Event ();
- event.item = this;
- event.gc = gc;
- event.index = columnIndex;
- event.x = getContentX (columnIndex);
- event.y = parent.getItemY (this);
- event.width = width;
- event.height = parent.itemHeight;
- parent.sendEvent (SWT.MeasureItem, event);
- if (parent.itemHeight != event.height) {
- parent.customHeightSet = true;
- boolean update = parent.setItemHeight (event.height + 2 * parent.getCellPadding ());
- if (update) parent.redraw ();
- }
- width = event.width;
- }
-
- gc.dispose ();
- if (columnIndex == 0 && (parent.style & SWT.CHECK) != 0) {
- width += parent.checkboxBounds.width;
- width += Table.MARGIN_IMAGE;
- }
- return width + 2 * parent.getCellPadding ();
-}
-public String getText () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return super.getText ();
-}
-/**
- * Returns the text stored at the given column index in the receiver,
- * or empty string if the text has not been set.
- *
- * @param index the column index
- * @return the text stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText (int columnIndex) {
- checkWidget ();
- return getText (columnIndex, true);
-}
-String getText (int columnIndex, boolean checkData) {
- if (checkData && !parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return ""; //$NON-NLS-1$
- if (columnIndex == 0) return super.getText (); /* super is intentional here */
- if (texts [columnIndex] == null) return ""; //$NON-NLS-1$
- return texts [columnIndex];
-}
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of the text at a column in the
- * table. An empty rectangle is returned if index exceeds
- * the index of the table's last column.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding text rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Rectangle getTextBounds (int columnIndex) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- TableColumn[] columns = parent.columns;
- int columnCount = columns.length;
- int validColumnCount = Math.max (1, columnCount);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) {
- return new Rectangle (0, 0, 0, 0);
- }
- /*
- * If there are no columns then this is the bounds of the receiver's content,
- * starting from the text.
- */
- if (columnCount == 0) {
- int x = getTextX (0) + MARGIN_TEXT;
- int width = Math.max (0, getContentX(0) + getContentWidth (0) - x);
- return new Rectangle (
- x,
- parent.getItemY (this),
- width,
- parent.itemHeight - 1);
- }
-
- TableColumn column = columns [columnIndex];
- if (columnIndex == 0) {
- /*
- * For column 0 this is bounds from the beginning of the content to the
- * end of the column, starting from the text.
- */
- int x = getTextX (0) + MARGIN_TEXT;
- int offset = x - column.getX ();
- int width = Math.max (0, column.width - offset - 1); /* max is for columns with small widths */
- return new Rectangle (x, parent.getItemY (this) + 1, width, parent.itemHeight - 1);
- }
- /*
- * For columns > 0 this is the bounds of the table cell, starting from the text.
- */
- int x = getTextX (columnIndex) + MARGIN_TEXT;
- int offset = x - column.getX ();
- int width = Math.max (0, column.width - offset - MARGIN_TEXT);
- return new Rectangle (x, parent.getItemY (this) + 1, width, parent.itemHeight - 1);
-}
-/*
- * Returns the x value where the receiver's text begins.
- */
-int getTextX (int columnIndex) {
- int textX = getContentX (columnIndex);
- if (columnIndex == 0) {
- textX += parent.col0ImageWidth;
- if (parent.col0ImageWidth > 0) textX += Table.MARGIN_IMAGE;
- } else {
- Image image = getImage (columnIndex, false);
- if (image != null) {
- textX += image.getBounds ().width + Table.MARGIN_IMAGE;
- }
- }
- return textX;
-}
-/*
- * Answers a boolean indicating whether the receiver's y is within the current
- * viewport of the parent.
- */
-boolean isInViewport () {
- int topIndex = parent.topIndex;
- if (index < topIndex) return false;
- int visibleCount = parent.clientArea.height / parent.itemHeight;
- return index <= topIndex + visibleCount;
-}
-boolean isSelected () {
- return parent.getSelectionIndex (this) != -1;
-}
-/*
- * The backgroundOnly argument indicates whether the item should only
- * worry about painting its background color and selection.
- *
- * Returns a boolean indicating whether to abort drawing focus on the item.
- * If the receiver is not the current focus item then this value is irrelevant.
- */
-boolean paint (GC gc, TableColumn column, boolean backgroundOnly) {
- if (!parent.checkData (this, true)) return false;
- int columnIndex = 0, x = 0;
- if (column != null) {
- columnIndex = column.getIndex ();
- x = column.getX ();
- }
-
- /*
- * Capture GC attributes that will need to be restored later in the paint
- * process to ensure that the item paints as intended without being affected
- * by GC changes made in MeasureItem/EraseItem/PaintItem callbacks.
- */
- int oldAlpha = gc.getAlpha ();
- boolean oldAdvanced = gc.getAdvanced ();
- int oldAntialias = gc.getAntialias ();
- Pattern oldBackgroundPattern = gc.getBackgroundPattern ();
- Pattern oldForegroundPattern = gc.getForegroundPattern ();
- int oldInterpolation = gc.getInterpolation ();
- int oldTextAntialias = gc.getTextAntialias ();
-
- if (parent.hooks (SWT.MeasureItem)) {
- int contentWidth = getContentWidth (columnIndex);
- int contentX = getContentX (columnIndex);
- gc.setFont (getFont (columnIndex, false));
- Event event = new Event ();
- event.item = this;
- event.gc = gc;
- event.index = columnIndex;
- event.x = contentX;
- event.y = parent.getItemY (this);
- event.width = contentWidth;
- event.height = parent.itemHeight;
- parent.sendEvent (SWT.MeasureItem, event);
- event.gc = null;
- if (gc.isDisposed ()) return false;
- gc.setAlpha (oldAlpha);
- gc.setAntialias (oldAntialias);
- gc.setBackgroundPattern (oldBackgroundPattern);
- gc.setForegroundPattern (oldForegroundPattern);
- gc.setInterpolation (oldInterpolation);
- gc.setTextAntialias (oldTextAntialias);
- gc.setAdvanced (oldAdvanced);
- if (isDisposed ()) return false;
- if (parent.itemHeight != event.height) {
- parent.customHeightSet = true;
- boolean update = parent.setItemHeight (event.height + 2 * parent.getCellPadding ());
- if (update) parent.redraw ();
- }
- if (parent.columns.length == 0) {
- int change = event.width - (customWidth != -1 ? customWidth : contentWidth);
- if (event.width != contentWidth || customWidth != -1) customWidth = event.width;
- if (change != 0) { /* scrollbar may be affected since no columns */
- parent.updateHorizontalBar (contentX + event.width, change);
- // TODO what if clip is too small now?
- }
- }
- }
-
- /* if this cell is completely to the right of the client area then there's no need to paint it */
- Rectangle clientArea = parent.clientArea;
- if (clientArea.x + clientArea.width < x) return false;
-
- Rectangle cellBounds = getCellBounds (columnIndex);
- if (parent.linesVisible) {
- cellBounds.y++;
- cellBounds.height--;
- }
- int cellRightX = 0;
- if (column != null) {
- cellRightX = column.getX () + column.width;
- } else {
- cellRightX = cellBounds.x + cellBounds.width;
- }
-
- /* restrict the clipping region to the cell */
- gc.setClipping (x, cellBounds.y, clientArea.width - x, cellBounds.height);
-
- int y = parent.getItemY (this);
- int itemHeight = parent.itemHeight;
-
- /* draw the parent background color/image of this cell */
- if (column == null) {
- parent.drawBackground (gc, 0, y, clientArea.width, itemHeight);
- } else {
- int fillWidth = cellBounds.width;
- if (parent.linesVisible) fillWidth--;
- parent.drawBackground (gc, cellBounds.x, cellBounds.y, fillWidth, cellBounds.height);
- }
-
- boolean isSelected = isSelected ();
- boolean isFocusItem = parent.focusItem == this && parent.isFocusControl ();
- boolean drawBackground = true;
- boolean drawForeground = true;
- boolean drawSelection = isSelected;
- boolean drawFocus = isFocusItem;
- if (parent.hooks (SWT.EraseItem)) {
- drawBackground = background != null || (cellBackgrounds != null && cellBackgrounds [columnIndex] != null);
- gc.setFont (getFont (columnIndex, false));
- if (isSelected && (columnIndex == 0 || (parent.style & SWT.FULL_SELECTION) != 0)) {
- gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT));
- gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION));
- } else {
- gc.setForeground (getForeground (columnIndex));
- gc.setBackground (getBackground (columnIndex));
- }
- Event event = new Event ();
- event.item = this;
- event.gc = gc;
- event.index = columnIndex;
- event.doit = true;
- event.detail = SWT.FOREGROUND;
- if (drawBackground) event.detail |= SWT.BACKGROUND;
- if (isSelected) event.detail |= SWT.SELECTED;
- if (isFocusItem) event.detail |= SWT.FOCUSED;
- event.x = cellBounds.x;
- event.y = cellBounds.y;
- event.width = cellBounds.width;
- event.height = cellBounds.height;
- gc.setClipping (cellBounds);
- parent.sendEvent (SWT.EraseItem, event);
- event.gc = null;
- if (gc.isDisposed ()) return false;
- gc.setAlpha (oldAlpha);
- gc.setAntialias (oldAntialias);
- gc.setBackgroundPattern (oldBackgroundPattern);
- gc.setClipping (cellBounds);
- gc.setForegroundPattern (oldForegroundPattern);
- gc.setInterpolation (oldInterpolation);
- gc.setTextAntialias (oldTextAntialias);
- gc.setAdvanced (oldAdvanced);
- if (isDisposed ()) return false;
- if (!event.doit) {
- drawBackground = drawForeground = drawSelection = drawFocus = false;
- } else {
- drawBackground = drawBackground && (event.detail & SWT.BACKGROUND) != 0;
- drawForeground = (event.detail & SWT.FOREGROUND) != 0;
- drawSelection = isSelected && (event.detail & SWT.SELECTED) != 0;
- drawFocus = isFocusItem && (event.detail & SWT.FOCUSED) != 0;
- }
- }
-
- /* draw the cell's set background if appropriate */
- if (drawBackground) {
- gc.setBackground (getBackground (columnIndex));
- if (columnIndex == 0 && (column == null || column.getOrderIndex () == 0)) {
- Rectangle focusBounds = getFocusBounds ();
- int fillWidth = 0;
- if (column == null) {
- fillWidth = focusBounds.width;
- } else {
- fillWidth = column.width - focusBounds.x;
- if (parent.linesVisible) fillWidth--;
- }
- gc.fillRectangle (focusBounds.x, focusBounds.y, fillWidth, focusBounds.height);
- } else {
- int fillWidth = cellBounds.width;
- gc.fillRectangle (cellBounds.x, cellBounds.y, fillWidth, cellBounds.height);
- }
- }
-
- /* draw the selection bar if the receiver is selected */
- if (drawSelection && (columnIndex == 0 || (parent.style & SWT.FULL_SELECTION) != 0)) {
- if (parent.hasFocus () || (parent.style & SWT.HIDE_SELECTION) == 0) {
- gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION));
- if (columnIndex == 0) {
- Rectangle focusBounds = getFocusBounds ();
- int startX, fillWidth;
- if (column == null || column.getOrderIndex () == 0 || (parent.style & SWT.FULL_SELECTION) == 0) {
- startX = focusBounds.x + 1; /* space for left bound of focus rect */
- } else {
- startX = column.getX ();
- }
- if (column == null) {
- fillWidth = focusBounds.width - 2;
- } else {
- fillWidth = column.getX () + column.width - startX;
- if (column.getOrderIndex () == parent.columns.length - 1 || (parent.style & SWT.FULL_SELECTION) == 0) {
- fillWidth -= 2; /* space for right bound of focus rect */
- }
- }
- if (fillWidth > 0) {
- gc.fillRectangle (startX, focusBounds.y + 1, fillWidth, focusBounds.height - 2);
- }
- } else {
- int startX = column.getX ();
- int fillWidth = column.width;
- if (column.getOrderIndex () == 0) {
- startX += 1; /* space for left bound of focus rect */
- fillWidth -= 1;
- }
- if (column.getOrderIndex () == parent.columns.length - 1) {
- fillWidth -= 2; /* space for right bound of focus rect */
- }
- if (fillWidth > 0) {
- gc.fillRectangle (
- column.getX (),
- cellBounds.y + 1,
- fillWidth,
- cellBounds.height - 2);
- }
- }
- }
- }
-
- if (backgroundOnly) return false;
-
- /* Draw checkbox if drawing column 0 and parent has style SWT.CHECK */
- if (columnIndex == 0 && (parent.style & SWT.CHECK) != 0) {
- Image baseImage = grayed ? parent.getGrayUncheckedImage () : parent.getUncheckedImage ();
- Rectangle checkboxBounds = getCheckboxBounds ();
- gc.drawImage (baseImage, checkboxBounds.x, checkboxBounds.y);
- /* Draw checkmark if item is checked */
- if (checked) {
- Image checkmarkImage = parent.getCheckmarkImage ();
- Rectangle checkmarkBounds = checkmarkImage.getBounds ();
- int xInset = (checkboxBounds.width - checkmarkBounds.width) / 2;
- int yInset = (checkboxBounds.height - checkmarkBounds.height) / 2;
- gc.drawImage (checkmarkImage, checkboxBounds.x + xInset, checkboxBounds.y + yInset);
- }
- }
-
- if (drawForeground) {
- Image image = getImage (columnIndex, false);
- String text = getDisplayText (columnIndex);
- Rectangle imageArea = getImageBounds (columnIndex);
- int startX = imageArea.x;
-
- /* while painting the cell's content restrict the clipping region */
- int padding = parent.getCellPadding ();
- gc.setClipping (
- startX,
- cellBounds.y + padding - (parent.linesVisible ? 1 : 0),
- cellRightX - startX - padding,
- cellBounds.height - 2 * (padding - (parent.linesVisible ? 1 : 0)));
-
- /* draw the image */
- if (image != null) {
- Rectangle imageBounds = image.getBounds ();
- gc.drawImage (
- image,
- 0, 0, /* source x, y */
- imageBounds.width, imageBounds.height, /* source width, height */
- imageArea.x, imageArea.y, /* dest x, y */
- imageArea.width, imageArea.height); /* dest width, height */
- }
-
- /* draw the text */
- if (text.length () > 0) {
- gc.setFont (getFont (columnIndex, false));
- int fontHeight = getFontHeight (columnIndex);
- if (drawSelection && (columnIndex == 0 || (parent.style & SWT.FULL_SELECTION) != 0)) {
- if (parent.hasFocus () || (parent.style & SWT.HIDE_SELECTION) == 0) {
- gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT));
- }
- } else {
- if (!isSelected || drawSelection) {
- gc.setForeground (getForeground (columnIndex));
- }
- }
- x = getTextX (columnIndex) + MARGIN_TEXT;
- gc.drawString (text, x, y + (itemHeight - fontHeight) / 2, true);
- }
- }
-
- if (parent.hooks (SWT.PaintItem)) {
- int contentWidth = getContentWidth (columnIndex);
- int contentX = getContentX (columnIndex);
- gc.setFont (getFont (columnIndex, false));
- if (isSelected && (columnIndex == 0 || (parent.style & SWT.FULL_SELECTION) != 0)) {
- gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT));
- gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION));
- } else {
- gc.setForeground (getForeground (columnIndex));
- gc.setBackground (getBackground (columnIndex));
- }
- Event event = new Event ();
- event.item = this;
- event.gc = gc;
- event.index = columnIndex;
- if (isSelected) event.detail |= SWT.SELECTED;
- if (drawFocus) event.detail |= SWT.FOCUSED;
- event.x = contentX;
- event.y = cellBounds.y;
- event.width = contentWidth;
- event.height = cellBounds.height;
- gc.setClipping (cellBounds);
- parent.sendEvent (SWT.PaintItem, event);
- event.gc = null;
- if (gc.isDisposed ()) return false;
- gc.setAlpha (oldAlpha);
- gc.setAntialias (oldAntialias);
- gc.setBackgroundPattern (oldBackgroundPattern);
- gc.setClipping (cellBounds);
- gc.setForegroundPattern (oldForegroundPattern);
- gc.setInterpolation (oldInterpolation);
- gc.setTextAntialias (oldTextAntialias);
- gc.setAdvanced (oldAdvanced);
- drawFocus = isFocusItem && (event.detail & SWT.FOCUSED) != 0;
- }
-
- return isFocusItem && !drawFocus;
-}
-/*
- * Redraw part of the receiver. If either EraseItem or PaintItem is hooked then
- * only full cells should be damaged, so adjust accordingly. If neither of these
- * events are hooked then the exact bounds given for damaging can be used.
- */
-void redraw (int x, int y, int width, int height, int columnIndex) {
- if (!parent.hooks (SWT.EraseItem) && !parent.hooks (SWT.PaintItem)) {
- parent.redraw (x, y, width, height, false);
- return;
- }
- Rectangle cellBounds = getCellBounds (columnIndex);
- parent.redraw (cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height, false);
-}
-void redrawItem () {
- parent.redraw (0, parent.getItemY (this), parent.clientArea.width, parent.itemHeight, false);
-}
-/*
- * Updates internal structures in the receiver and its child items to handle the removal of a column.
- */
-void removeColumn (TableColumn column, int index) {
- int columnCount = parent.columns.length;
-
- if (columnCount == 0) {
- /* reverts to normal table when last column disposed */
- cellBackgrounds = cellForegrounds = null;
- displayTexts = null;
- cellFonts = null;
- fontHeights = null;
- GC gc = new GC (parent);
- computeTextWidths (gc);
- gc.dispose ();
- return;
- }
-
- String[] newTexts = new String [columnCount];
- System.arraycopy (texts, 0, newTexts, 0, index);
- System.arraycopy (texts, index + 1, newTexts, index, columnCount - index);
- texts = newTexts;
-
- Image[] newImages = new Image [columnCount];
- System.arraycopy (images, 0, newImages, 0, index);
- System.arraycopy (images, index + 1, newImages, index, columnCount - index);
- images = newImages;
-
- int[] newTextWidths = new int [columnCount];
- System.arraycopy (textWidths, 0, newTextWidths, 0, index);
- System.arraycopy (textWidths, index + 1, newTextWidths, index, columnCount - index);
- textWidths = newTextWidths;
-
- String[] newDisplayTexts = new String [columnCount];
- System.arraycopy (displayTexts, 0, newDisplayTexts, 0, index);
- System.arraycopy (displayTexts, index + 1, newDisplayTexts, index, columnCount - index);
- displayTexts = newDisplayTexts;
-
- if (cellBackgrounds != null) {
- Color[] newCellBackgrounds = new Color [columnCount];
- System.arraycopy (cellBackgrounds, 0, newCellBackgrounds, 0, index);
- System.arraycopy (cellBackgrounds, index + 1, newCellBackgrounds, index, columnCount - index);
- cellBackgrounds = newCellBackgrounds;
- }
- if (cellForegrounds != null) {
- Color[] newCellForegrounds = new Color [columnCount];
- System.arraycopy (cellForegrounds, 0, newCellForegrounds, 0, index);
- System.arraycopy (cellForegrounds, index + 1, newCellForegrounds, index, columnCount - index);
- cellForegrounds = newCellForegrounds;
- }
- if (cellFonts != null) {
- Font[] newCellFonts = new Font [columnCount];
- System.arraycopy (cellFonts, 0, newCellFonts, 0, index);
- System.arraycopy (cellFonts, index + 1, newCellFonts, index, columnCount - index);
- cellFonts = newCellFonts;
-
- int[] newFontHeights = new int [columnCount];
- System.arraycopy (fontHeights, 0, newFontHeights, 0, index);
- System.arraycopy (fontHeights, index + 1, newFontHeights, index, columnCount - index);
- fontHeights = newFontHeights;
- }
-
- if (index == 0) {
- text = texts [0] != null ? texts [0] : ""; //$NON-NLS-1$
- texts [0] = null;
- image = images [0];
- images [0] = null;
- /*
- * The new first column may not have as much width available to it as it did when it was
- * the second column if checkboxes are being shown, so recompute its displayText if needed.
- */
- if ((parent.style & SWT.CHECK) != 0) {
- GC gc = new GC (parent);
- gc.setFont (getFont (0, false));
- computeDisplayText (0, gc);
- gc.dispose ();
- }
- }
- if (columnCount < 2) {
- texts = null;
- images = null;
- }
-}
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setBackground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Color oldColor = background;
- if (oldColor == color) return;
- background = color;
- if (oldColor != null && oldColor.equals (color)) return;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- redrawItem ();
-}
-/**
- * Sets the background color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setBackground (int columnIndex, Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return;
- if (cellBackgrounds == null) {
- if (color == null) return;
- cellBackgrounds = new Color [validColumnCount];
- }
- Color oldColor = cellBackgrounds [columnIndex];
- if (oldColor == color) return;
- cellBackgrounds [columnIndex] = color;
- if (oldColor != null && oldColor.equals (color)) return;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-
- if (isInViewport ()) {
- Rectangle bounds = getCellBounds (columnIndex);
- parent.redraw (bounds.x, bounds.y, bounds.width, bounds.height, false);
- }
-}
-/**
- * Sets the checked state of the checkbox for this item. This state change
- * only applies if the Table was created with the SWT.CHECK style.
- *
- * @param checked the new checked state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setChecked (boolean value) {
- checkWidget ();
- if ((parent.getStyle () & SWT.CHECK) == 0) return;
- if (checked == value) return;
- checked = value;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-
- if (isInViewport ()) {
- if (parent.hooks (SWT.EraseItem) || parent.hooks (SWT.PaintItem)) {
- redrawItem ();
- } else {
- Rectangle bounds = getCheckboxBounds ();
- parent.redraw (bounds.x, bounds.y, bounds.width, bounds.height, false);
- }
- }
-}
-/**
- * Sets the font that the receiver will use to paint textual information
- * for this item to the font specified by the argument, or to the default font
- * for that kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (Font font) {
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Font oldFont = this.font;
- if (oldFont == font) return;
- this.font = font;
- if (oldFont != null && oldFont.equals (font)) return;
-
- Rectangle bounds = getBounds (false);
- int oldRightX = bounds.x + bounds.width;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-
- /* recompute cached values for string measurements */
- GC gc = new GC (parent);
- gc.setFont (getFont (false));
- fontHeight = gc.getFontMetrics ().getHeight ();
- computeDisplayTexts (gc);
- computeTextWidths (gc);
- gc.dispose ();
-
- /* horizontal bar could be affected if table has no columns */
- if (parent.columns.length == 0) {
- bounds = getBounds (false);
- int newRightX = bounds.x + bounds.width;
- parent.updateHorizontalBar (newRightX, newRightX - oldRightX);
- }
- redrawItem ();
-}
-/**
- * Sets the font that the receiver will use to paint textual information
- * for the specified cell in this item to the font specified by the
- * argument, or to the default font for that kind of control if the
- * argument is null.
- *
- * @param index the column index
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (int columnIndex, Font font) {
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
-
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return;
- if (cellFonts == null) {
- if (font == null) return;
- cellFonts = new Font [validColumnCount];
- }
- Font oldFont = cellFonts [columnIndex];
- if (oldFont == font) return;
- cellFonts [columnIndex] = font;
- if (oldFont != null && oldFont.equals (font)) return;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-
- /* recompute cached values for string measurements */
- GC gc = new GC (parent);
- gc.setFont (getFont (columnIndex, false));
- if (fontHeights == null) fontHeights = new int [validColumnCount];
- fontHeights [columnIndex] = gc.getFontMetrics ().getHeight ();
- computeDisplayText (columnIndex, gc);
- gc.dispose ();
-
- if (isInViewport ()) {
- Rectangle bounds = getCellBounds (columnIndex);
- parent.redraw (bounds.x, bounds.y, bounds.width, bounds.height, false);
- }
-}
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setForeground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Color oldColor = foreground;
- if (oldColor == color) return;
- foreground = color;
- if (oldColor != null && oldColor.equals (color)) return;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- redrawItem ();
-}
-/**
- * Sets the foreground color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setForeground (int columnIndex, Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return;
- if (cellForegrounds == null) {
- if (color == null) return;
- cellForegrounds = new Color [validColumnCount];
- }
- Color oldColor = cellForegrounds [columnIndex];
- if (oldColor == color) return;
- cellForegrounds [columnIndex] = color;
- if (oldColor != null && oldColor.equals (color)) return;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-
- if (isInViewport ()) {
- redraw (
- getTextX (columnIndex),
- parent.getItemY (this),
- textWidths [columnIndex] + 2 * MARGIN_TEXT,
- parent.itemHeight,
- columnIndex);
- }
-}
-/**
- * Sets the grayed state of the checkbox for this item. This state change
- * only applies if the Table was created with the SWT.CHECK style.
- *
- * @param grayed the new grayed state of the checkbox;
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setGrayed (boolean value) {
- checkWidget ();
- if ((parent.getStyle () & SWT.CHECK) == 0) return;
- if (grayed == value) return;
- grayed = value;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-
- if (isInViewport ()) {
- Rectangle bounds = getCheckboxBounds ();
- parent.redraw (bounds.x, bounds.y, bounds.width, bounds.height, false);
- }
-}
-public void setImage (Image value) {
- checkWidget ();
- setImage (0, value);
-}
-/**
- * Sets the image for multiple columns in the table.
- *
- * @param images the array of new images
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image[] value) {
- checkWidget ();
- if (value == null) error (SWT.ERROR_NULL_ARGUMENT);
-
- // TODO make a smarter implementation of this
- for (int i = 0; i < value.length; i++) {
- if (value [i] != null) setImage (i, value [i]);
- }
-}
-/**
- * Sets the receiver's image at a column.
- *
- * @param index the column index
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (int columnIndex, Image value) {
- checkWidget ();
- if (value != null && value.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
-
- TableColumn[] columns = parent.columns;
- int validColumnCount = Math.max (1, columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return;
- Image image = getImage (columnIndex, false);
- if (value == image) return;
- if (value != null && value.equals (image)) return;
- if (columnIndex == 0) {
- super.setImage (value);
- } else {
- images [columnIndex] = value;
- }
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-
- /*
- * An image width change may affect the space available for the item text, so
- * recompute the displayText if there are columns.
- */
- if (columns.length > 0) {
- GC gc = new GC (parent);
- gc.setFont (getFont (columnIndex, false));
- computeDisplayText (columnIndex, gc);
- gc.dispose ();
- }
-
- if (value == null) {
- redrawItem (); // TODO why the whole item?
- return;
- }
-
- /*
- * If this is the first image being put into the table then its item height
- * may be adjusted, in which case a full redraw is needed.
- */
- if (parent.imageHeight == 0) {
- int oldItemHeight = parent.itemHeight;
- parent.setImageHeight (value.getBounds ().height);
- if (oldItemHeight != parent.itemHeight) {
- if (columnIndex == 0) {
- parent.col0ImageWidth = value.getBounds ().width;
- if (columns.length > 0) {
- /*
- * All column 0 cells will now have less room available for their texts,
- * so all items must now recompute their column 0 displayTexts.
- */
- GC gc = new GC (parent);
- TableItem[] rootItems = parent.items;
- for (int i = 0; i < parent.itemsCount; i++) {
- rootItems [i].updateColumnWidth (columns [0], gc);
- }
- gc.dispose ();
- }
- }
- parent.redraw ();
- return;
- }
- }
-
- /*
- * If this is the first image being put into column 0 then all cells
- * in the column should also indent accordingly.
- */
- if (columnIndex == 0 && parent.col0ImageWidth == 0) {
- parent.col0ImageWidth = value.getBounds ().width;
- /* redraw the column */
- if (columns.length == 0) {
- parent.redraw ();
- } else {
- /*
- * All column 0 cells will now have less room available for their texts,
- * so all items must now recompute their column 0 displayTexts.
- */
- GC gc = new GC (parent);
- TableItem[] rootItems = parent.items;
- for (int i = 0; i < parent.itemsCount; i++) {
- rootItems [i].updateColumnWidth (columns [0], gc);
- }
- gc.dispose ();
- parent.redraw (
- columns [0].getX (), 0,
- columns [0].width,
- parent.clientArea.height,
- false);
- }
- return;
- }
- redrawItem (); // TODO why the whole item?
-}
-/**
- * Sets the indent of the first column's image, expressed in terms of the image's width.
- *
- * @param indent the new indent
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @deprecated this functionality is not supported on most platforms
- */
-public void setImageIndent (int indent) {
- checkWidget();
- if (indent < 0) return;
- if (imageIndent == indent) return;
- imageIndent = indent;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-}
-/**
- * Sets the receiver's text at a column
- *
- * @param index the column index
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (int columnIndex, String value) {
- checkWidget ();
- if (value == null) error (SWT.ERROR_NULL_ARGUMENT);
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return;
- if (value.equals (getText (columnIndex, false))) return;
- if (columnIndex == 0) {
- super.setText (value);
- } else {
- texts [columnIndex] = value;
- }
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-
- int oldWidth = textWidths [columnIndex];
- GC gc = new GC (parent);
- gc.setFont (getFont (columnIndex, false));
- computeDisplayText (columnIndex, gc);
- gc.dispose ();
-
- if (parent.columns.length == 0) {
- Rectangle bounds = getBounds (false);
- int rightX = bounds.x + bounds.width;
- parent.updateHorizontalBar (rightX, textWidths [columnIndex] - oldWidth);
- }
- if (isInViewport ()) {
- redraw (
- getTextX (columnIndex),
- parent.getItemY (this),
- Math.max (oldWidth, textWidths [columnIndex]) + 2 * MARGIN_TEXT,
- parent.itemHeight,
- columnIndex);
- }
-}
-public void setText (String value) {
- checkWidget ();
- Rectangle bounds = getBounds (false);
- int oldRightX = bounds.x + bounds.width;
- setText (0, value);
- /* horizontal bar could be affected if table has no columns */
- if (parent.columns.length == 0) {
- bounds = getBounds (false);
- int newRightX = bounds.x + bounds.width;
- parent.updateHorizontalBar (newRightX, newRightX - oldRightX);
- }
-}
-/**
- * Sets the text for multiple columns in the table.
- *
- * @param strings the array of new strings
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String[] value) {
- checkWidget ();
- if (value == null) error (SWT.ERROR_NULL_ARGUMENT);
- Rectangle bounds = getBounds (false);
- int oldRightX = bounds.x + bounds.width;
- // TODO make a smarter implementation of this
- for (int i = 0; i < value.length; i++) {
- if (value [i] != null) setText (i, value [i]);
- }
- /* horizontal bar could be affected if table has no columns */
- if (parent.columns.length == 0) {
- bounds = getBounds (false);
- int newRightX = bounds.x + bounds.width;
- parent.updateHorizontalBar (newRightX, newRightX - oldRightX);
- }
-}
-/*
- * Perform any internal changes necessary to reflect a changed column width.
- */
-void updateColumnWidth (TableColumn column, GC gc) {
- int columnIndex = column.getIndex ();
- gc.setFont (getFont (columnIndex, false));
- String oldDisplayText = displayTexts [columnIndex];
- computeDisplayText (columnIndex, gc);
-
- /* the cell must be damaged if there is custom drawing being done or if the alignment is not LEFT */
- if (isInViewport ()) {
- boolean columnIsLeft = (column.style & SWT.LEFT) != 0;
- if (!columnIsLeft || parent.hooks (SWT.EraseItem) || parent.hooks (SWT.PaintItem)) {
- Rectangle cellBounds = getCellBounds (columnIndex);
- parent.redraw (cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height, false);
- return;
- }
- /* if the display text has changed then the cell text must be damaged in order to repaint */
- if (oldDisplayText == null || !oldDisplayText.equals (displayTexts [columnIndex])) {
- Rectangle cellBounds = getCellBounds (columnIndex);
- int textX = getTextX (columnIndex);
- parent.redraw (textX, cellBounds.y, cellBounds.x + cellBounds.width - textX, cellBounds.height, false);
- }
- }
-}
-/*
- * The parent's font has changed, so if this font was being used by the receiver then
- * recompute its cached text sizes using the gc argument.
- */
-void updateFont (GC gc) {
- if (font == null) { /* receiver is using the Table's font */
- computeDisplayTexts (gc);
- computeTextWidths (gc);
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Tree.java
deleted file mode 100644
index 1e65f8c530..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Tree.java
+++ /dev/null
@@ -1,4295 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.*;
-
-/**
- * Instances of this class provide a selectable user interface object
- * that displays a hierarchy of items and issues notification when an
- * item in the hierarchy is selected.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TreeItem</code>.
- * </p><p>
- * Style <code>VIRTUAL</code> is used to create a <code>Tree</code> whose
- * <code>TreeItem</code>s are to be populated by the client on an on-demand basis
- * instead of up-front. This can provide significant performance improvements for
- * trees that are very large or for which <code>TreeItem</code> population is
- * expensive (for example, retrieving values from an external source).
- * </p><p>
- * Here is an example of using a <code>Tree</code> with style <code>VIRTUAL</code>:
- * <code><pre>
- * final Tree tree = new Tree(parent, SWT.VIRTUAL | SWT.BORDER);
- * tree.setItemCount(20);
- * tree.addListener(SWT.SetData, new Listener() {
- * public void handleEvent(Event event) {
- * TreeItem item = (TreeItem)event.item;
- * TreeItem parentItem = item.getParentItem();
- * String text = null;
- * if (parentItem == null) {
- * text = "node " + tree.indexOf(item);
- * } else {
- * text = parentItem.getText() + " - " + parentItem.indexOf(item);
- * }
- * item.setText(text);
- * System.out.println(text);
- * item.setItemCount(10);
- * }
- * });
- * </pre></code>
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not normally make sense to add <code>Control</code> children to
- * it, or set a layout on it, unless implementing something like a cell
- * editor.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, VIRTUAL, NO_SCROLL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection, Collapse, Expand, SetData, MeasureItem, EraseItem, PaintItem</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles SINGLE and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Tree extends Composite {
- Canvas header;
- TreeColumn[] columns = new TreeColumn [0];
- TreeColumn[] orderedColumns;
- TreeItem[] items = NO_ITEMS;
- TreeItem[] availableItems = NO_ITEMS;
- TreeItem[] selectedItems = NO_ITEMS;
- TreeItem focusItem, anchorItem, insertMarkItem;
- TreeItem lastClickedItem;
- Event lastSelectionEvent;
- int availableItemsCount = 0;
- boolean insertMarkPrecedes = false;
- boolean linesVisible, ignoreKey, ignoreDispose, customHeightSet;
- int topIndex = 0, horizontalOffset = 0;
- int fontHeight = 0, imageHeight = 0, itemHeight = 0;
- int headerImageHeight = 0, orderedCol0imageWidth = 0;
- TreeColumn resizeColumn;
- int resizeColumnX = -1;
- int drawCount = 0;
- boolean inExpand = false; /* for item creation within Expand callback */
- TreeColumn sortColumn;
- int sortDirection = SWT.NONE;
-
- /* column header tooltip */
- Listener toolTipListener;
- Shell toolTipShell;
- Label toolTipLabel;
-
- Rectangle arrowBounds, expanderBounds, checkboxBounds, clientArea;
-
- static final TreeItem[] NO_ITEMS = new TreeItem [0];
-
- static final int MARGIN_IMAGE = 3;
- static final int MARGIN_CELL = 1;
- static final int SIZE_HORIZONTALSCROLL = 5;
- static final int TOLLERANCE_COLUMNRESIZE = 2;
- static final int WIDTH_HEADER_SHADOW = 2;
- static final int WIDTH_CELL_HIGHLIGHT = 1;
- static final int [] toolTipEvents = new int[] {SWT.MouseExit, SWT.MouseHover, SWT.MouseMove, SWT.MouseDown};
- static final String ELLIPSIS = "..."; //$NON-NLS-1$
- static final String ID_EXPANDED = "EXPANDED"; //$NON-NLS-1$
- static final String ID_COLLAPSED = "COLLAPSED"; //$NON-NLS-1$
- static final String ID_UNCHECKED = "UNCHECKED"; //$NON-NLS-1$
- static final String ID_GRAYUNCHECKED = "GRAYUNCHECKED"; //$NON-NLS-1$
- static final String ID_CHECKMARK = "CHECKMARK"; //$NON-NLS-1$
- static final String ID_CONNECTOR_COLOR = "CONNECTOR_COLOR"; //$NON-NLS-1$
- static final String ID_ARROWUP = "ARROWUP"; //$NON-NLS-1$
- static final String ID_ARROWDOWN = "ARROWDOWN"; //$NON-NLS-1$
-
-// TEMPORARY CODE
-boolean hasFocus;
-
-public boolean isFocusControl() {
- return hasFocus;
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#CHECK
- * @see SWT#FULL_SELECTION
- * @see SWT#VIRTUAL
- * @see SWT#NO_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Tree (Composite parent, int style) {
- super (parent, checkStyle (style));
- setForeground (null); /* set foreground and background to chosen default colors */
- setBackground (null);
- GC gc = new GC (this);
- fontHeight = gc.getFontMetrics ().getHeight ();
- gc.dispose ();
- itemHeight = fontHeight + (2 * getCellPadding ());
- initImages (display);
- expanderBounds = getExpandedImage ().getBounds ();
- checkboxBounds = getUncheckedImage ().getBounds ();
- arrowBounds = getArrowDownImage ().getBounds ();
- clientArea = getClientArea ();
-
- Listener listener = new Listener () {
- public void handleEvent (Event event) {
- handleEvents (event);
- }
- };
- addListener (SWT.Paint, listener);
- addListener (SWT.MouseDown, listener);
- addListener (SWT.MouseUp, listener);
- addListener (SWT.MouseDoubleClick, listener);
- addListener (SWT.Dispose, listener);
- addListener (SWT.Resize, listener);
- addListener (SWT.KeyDown, listener);
- addListener (SWT.FocusOut, listener);
- addListener (SWT.FocusIn, listener);
- addListener (SWT.Traverse, listener);
-
- header = new Canvas (this, SWT.NO_REDRAW_RESIZE | SWT.NO_FOCUS);
- header.setVisible (false);
- header.setBounds (0, 0, 0, fontHeight + 2 * getHeaderPadding ());
- header.addListener (SWT.Paint, listener);
- header.addListener (SWT.MouseDown, listener);
- header.addListener (SWT.MouseUp, listener);
- header.addListener (SWT.MouseHover, listener);
- header.addListener (SWT.MouseDoubleClick, listener);
- header.addListener (SWT.MouseMove, listener);
- header.addListener (SWT.MouseExit, listener);
- header.addListener (SWT.MenuDetect, listener);
-
- toolTipListener = new Listener () {
- public void handleEvent (Event event) {
- switch (event.type) {
- case SWT.MouseHover:
- case SWT.MouseMove:
- if (headerUpdateToolTip (event.x)) break;
- // FALL THROUGH
- case SWT.MouseExit:
- case SWT.MouseDown:
- headerHideToolTip ();
- break;
- }
- }
- };
-
- ScrollBar hBar = getHorizontalBar ();
- if (hBar != null) {
- hBar.setValues (0, 0, 1, 1, 1, 1);
- hBar.setVisible (false);
- hBar.addListener (SWT.Selection, listener);
- }
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) {
- vBar.setValues (0, 0, 1, 1, 1, 1);
- vBar.setVisible (false);
- vBar.addListener (SWT.Selection, listener);
- }
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * If the receiver has the <code>SWT.CHECK</code> style and the check selection changes,
- * the event object detail field contains the value <code>SWT.CHECK</code>.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * The item field of the event object is valid for default selection, but the detail field is not used.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an item in the receiver is expanded or collapsed
- * by sending it one of the messages defined in the <code>TreeListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TreeListener
- * @see #removeTreeListener
- */
-public void addTreeListener (TreeListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Expand, typedListener);
- addListener (SWT.Collapse, typedListener);
-}
-boolean checkData (TreeItem item, boolean redraw) {
- if (item.cached) return true;
- if ((style & SWT.VIRTUAL) != 0) {
- item.cached = true;
- Event event = new Event ();
- TreeItem parentItem = item.getParentItem ();
- event.item = item;
- event.index = parentItem == null ? indexOf (item) : parentItem.indexOf (item);
- sendEvent (SWT.SetData, event);
- if (isDisposed () || item.isDisposed ()) return false;
- if (redraw) redrawItem (item.availableIndex, false);
- }
- return true;
-}
-static int checkStyle (int style) {
- /*
- * Feature in Windows. Even when WS_HSCROLL or
- * WS_VSCROLL is not specified, Windows creates
- * trees and tables with scroll bars. The fix
- * is to set H_SCROLL and V_SCROLL.
- *
- * NOTE: This code appears on all platforms so that
- * applications have consistent scroll bar behavior.
- */
- if ((style & SWT.NO_SCROLL) == 0) {
- style |= SWT.H_SCROLL | SWT.V_SCROLL;
- }
- style |= SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED;
- //TEMPORARY CODE
- style |= SWT.FULL_SELECTION;
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-/**
- * Clears the item at the given zero-relative index in the receiver.
- * The text, icon and other attributes of the item are set to the default
- * value. If the tree was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param index the index of the item to clear
- * @param all <code>true</code> if all child items of the indexed item should be
- * cleared recursively, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clear (int index, boolean recursive) {
- checkWidget ();
- if (!(0 <= index && index < items.length)) error (SWT.ERROR_INVALID_RANGE);
- TreeItem item = items [index];
-
- /* if there are no columns then the horizontal scrollbar may need adjusting */
- TreeItem[] availableDescendents = null;
- int oldRightX = 0;
- if (columns.length == 0) {
- if (recursive) {
- availableDescendents = item.computeAvailableDescendents ();
- for (int i = 0; i < availableDescendents.length; i++) {
- Rectangle bounds = availableDescendents [i].getBounds (false);
- oldRightX = Math.max (oldRightX, bounds.x + bounds.width);
- }
- } else {
- Rectangle bounds = item.getBounds (false);
- oldRightX = bounds.x + bounds.width;
- }
- }
-
- /* clear the item(s) */
- item.clear ();
- if (recursive) {
- item.clearAll (true, false);
- }
-
- /* adjust the horizontal scrollbar if needed */
- if (columns.length == 0) {
- int newRightX = 0;
- if (recursive) {
- for (int i = 0; i < availableDescendents.length; i++) {
- Rectangle bounds = availableDescendents [i].getBounds (false);
- newRightX = Math.max (newRightX, bounds.x + bounds.width);
- }
- } else {
- Rectangle bounds = item.getBounds (false);
- newRightX = bounds.x + bounds.width;
- }
- updateHorizontalBar (newRightX, newRightX - oldRightX);
- }
-
- /* redraw the item(s) */
- if (recursive && item.expanded) {
- int descendentCount = availableDescendents == null ?
- item.computeAvailableDescendentCount () :
- availableDescendents.length;
- redrawItems (item.availableIndex, item.availableIndex + descendentCount - 1, false);
- } else {
- redrawItem (item.availableIndex, false);
- }
-}
-/**
- * Clears all the items in the receiver. The text, icon and other
- * attributes of the items are set to their default values. If the
- * tree was created with the <code>SWT.VIRTUAL</code> style, these
- * attributes are requested again as needed.
- *
- * @param all <code>true</code> if all child items should be cleared
- * recursively, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clearAll (boolean recursive) {
- checkWidget ();
- if (items.length == 0) return;
-
- /* if there are no columns then the horizontal scrollbar may need adjusting */
- int oldRightX = 0;
- if (columns.length == 0 && !recursive) {
- for (int i = 0; i < items.length; i++) {
- Rectangle bounds = items [i].getBounds (false);
- oldRightX = Math.max (oldRightX, bounds.x + bounds.width);
- }
- }
-
- /* clear the item(s) */
- for (int i = 0; i < items.length; i++) {
- items [i].clear ();
- if (recursive) items [i].clearAll (true, false);
- }
-
- /* adjust the horizontal scrollbar if needed */
- if (columns.length == 0) {
- if (recursive) {
- updateHorizontalBar (); /* recompute from scratch */
- } else {
- /*
- * All cleared root items will have the same x and width values now,
- * so just measure the first one as a sample.
- */
- Rectangle bounds = items [0].getBounds (false);
- int newRightX = bounds.x + bounds.width;
- updateHorizontalBar (newRightX, newRightX - oldRightX);
- }
- }
-
- /* redraw the item(s) */
- if (recursive) {
- redrawItems (0, availableItemsCount - 1, false);
- } else {
- for (int i = 0; i < items.length; i++) {
- redrawItem (items [i].availableIndex, false);
- }
- }
-}
-/*
- * Returns the ORDERED index of the column that the specified x falls within,
- * or -1 if the x lies to the right of the last column.
- */
-int computeColumnIntersect (int x, int startColumn) {
- TreeColumn[] orderedColumns = getOrderedColumns ();
- if (orderedColumns.length - 1 < startColumn) return -1;
- int rightX = orderedColumns [startColumn].getX ();
- for (int i = startColumn; i < orderedColumns.length; i++) {
- rightX += orderedColumns [i].width;
- if (x < rightX) return i;
- }
- return -1;
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0;
- if (wHint != SWT.DEFAULT) {
- width = wHint;
- } else {
- if (columns.length == 0) {
- for (int i = 0; i < availableItemsCount; i++) {
- Rectangle itemBounds = availableItems [i].getBounds (false);
- width = Math.max (width, itemBounds.x + itemBounds.width);
- }
- } else {
- TreeColumn[] orderedColumns = getOrderedColumns ();
- TreeColumn lastColumn = orderedColumns [orderedColumns.length - 1];
- width = lastColumn.getX () + lastColumn.width;
- }
- }
- if (hHint != SWT.DEFAULT) {
- height = hHint;
- } else {
- height = getHeaderHeight () + availableItemsCount * itemHeight;
- }
- Rectangle result = computeTrim (0, 0, width, height);
- return new Point (result.width, result.height);
-}
-void createItem (TreeColumn column, int index) {
- TreeColumn[] newColumns = new TreeColumn [columns.length + 1];
- System.arraycopy (columns, 0, newColumns, 0, index);
- newColumns [index] = column;
- System.arraycopy (columns, index, newColumns, index + 1, columns.length - index);
- columns = newColumns;
-
- if (orderedColumns != null) {
- int insertIndex = 0;
- if (index > 0) {
- insertIndex = columns [index - 1].getOrderIndex () + 1;
- }
- TreeColumn[] newOrderedColumns = new TreeColumn [orderedColumns.length + 1];
- System.arraycopy (orderedColumns, 0, newOrderedColumns, 0, insertIndex);
- newOrderedColumns [insertIndex] = column;
- System.arraycopy (
- orderedColumns,
- insertIndex,
- newOrderedColumns,
- insertIndex + 1,
- orderedColumns.length - insertIndex);
- orderedColumns = newOrderedColumns;
- }
-
- if (columns.length == 1) {
- column.itemImageWidth = orderedCol0imageWidth;
- } else {
- if (column.getOrderIndex () == 0) orderedCol0imageWidth = 0;
- }
-
- /* allow all items to update their internal structures accordingly */
- for (int i = 0; i < items.length; i++) {
- items [i].addColumn (column);
- }
-
- /* existing items become hidden when going from 0 to 1 column (0 width) */
- if (columns.length == 1 && availableItemsCount > 0) {
- redrawFromItemDownwards (topIndex);
- } else {
- /* checkboxes become hidden when creating a column with index == ordered index == 0 (0 width) */
- if (availableItemsCount > 0 && (style & SWT.CHECK) != 0 && index == 0 && column.getOrderIndex () == 0) {
- redrawFromItemDownwards (topIndex);
- }
- }
-}
-void createItem (TreeItem item, int index) {
- TreeItem[] newItems = new TreeItem [items.length + 1];
- System.arraycopy (items, 0, newItems, 0, index);
- newItems [index] = item;
- System.arraycopy (items, index, newItems, index + 1, items.length - index);
- items = newItems;
-
- /* determine the item's availability index */
- int startIndex;
- if (index == items.length - 1) {
- startIndex = availableItemsCount; /* last item */
- } else {
- startIndex = items [index + 1].availableIndex;
- }
-
- if (availableItemsCount == availableItems.length) {
- int grow = drawCount <= 0 ? 4 : Math.max (4, availableItems.length * 3 / 2);
- TreeItem[] newAvailableItems = new TreeItem [availableItems.length + grow];
- System.arraycopy (availableItems, 0, newAvailableItems, 0, availableItems.length);
- availableItems = newAvailableItems;
- }
- if (startIndex != availableItemsCount) {
- /* new item is not at end of list, so shift other items right to create space for it */
- System.arraycopy (
- availableItems,
- startIndex,
- availableItems,
- startIndex + 1,
- availableItemsCount - startIndex);
- }
- availableItems [startIndex] = item;
- availableItemsCount++;
-
- /* update the availableIndex for items bumped down by this new item */
- for (int i = startIndex; i < availableItemsCount; i++) {
- availableItems [i].availableIndex = i;
- }
-
- /* update scrollbars */
- updateVerticalBar ();
- Rectangle bounds = item.getBounds (false);
- int rightX = bounds.x + bounds.width;
- updateHorizontalBar (rightX, rightX);
- /*
- * If new item is above viewport then adjust topIndex and the vertical
- * scrollbar so that the current viewport items will not change.
- */
- if (item.availableIndex < topIndex) {
- topIndex++;
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) vBar.setSelection (topIndex);
- return;
- }
- /*
- * If this is the first item and the receiver has focus then its boundary
- * focus ring must be removed.
- */
- if (availableItemsCount == 1 && isFocusControl ()) {
- focusItem = item;
- redraw ();
- return;
- }
- int redrawIndex = index;
- if (redrawIndex > 0 && item.isLastChild ()) redrawIndex--;
- redrawFromItemDownwards (items [redrawIndex].availableIndex);
-}
-/**
- * Deselects an item in the receiver. If the item was already
- * deselected, it remains deselected.
- *
- * @param item the item to be deselected
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void deselect (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- deselectItem (item);
- redrawItem (item.availableIndex, true);
-}
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll () {
- checkWidget ();
- TreeItem[] oldSelection = selectedItems;
- selectedItems = NO_ITEMS;
- for (int i = 0; i < oldSelection.length; i++) {
- redrawItem (oldSelection [i].availableIndex, true);
- }
-}
-void deselectItem (TreeItem item) {
- int index = getSelectionIndex (item);
- if (index == -1) return;
- TreeItem[] newSelectedItems = new TreeItem [selectedItems.length - 1];
- System.arraycopy (selectedItems, 0, newSelectedItems, 0, index);
- System.arraycopy (
- selectedItems,
- index + 1,
- newSelectedItems,
- index,
- newSelectedItems.length - index);
- selectedItems = newSelectedItems;
-}
-void destroyItem (TreeColumn column) {
- headerHideToolTip ();
- int index = column.getIndex ();
- int orderedIndex = column.getOrderIndex ();
-
- TreeColumn[] newColumns = new TreeColumn [columns.length - 1];
- System.arraycopy (columns, 0, newColumns, 0, index);
- System.arraycopy (columns, index + 1, newColumns, index, newColumns.length - index);
- columns = newColumns;
-
- if (orderedColumns != null) {
- if (columns.length < 2) {
- orderedColumns = null;
- } else {
- int removeIndex = column.getOrderIndex ();
- TreeColumn[] newOrderedColumns = new TreeColumn [orderedColumns.length - 1];
- System.arraycopy (orderedColumns, 0, newOrderedColumns, 0, removeIndex);
- System.arraycopy (
- orderedColumns,
- removeIndex + 1,
- newOrderedColumns,
- removeIndex,
- newOrderedColumns.length - removeIndex);
- orderedColumns = newOrderedColumns;
- }
- }
-
- if (orderedIndex == 0 && columns.length > 0) {
- orderedCol0imageWidth = columns [getColumnOrder ()[0]].itemImageWidth;
- }
-
- /* allow all items to update their internal structures accordingly */
- for (int i = 0; i < items.length; i++) {
- items [i].removeColumn (column, index, orderedIndex);
- }
-
- /* update horizontal scrollbar */
- int lastColumnIndex = columns.length - 1;
- if (lastColumnIndex < 0) { /* no more columns */
- updateHorizontalBar ();
- } else {
- int newWidth = 0;
- for (int i = 0; i < columns.length; i++) {
- newWidth += columns [i].width;
- }
- ScrollBar hBar = getHorizontalBar ();
- if (hBar != null) {
- hBar.setMaximum (newWidth);
- hBar.setVisible (clientArea.width < newWidth);
- int selection = hBar.getSelection ();
- if (selection != horizontalOffset) {
- horizontalOffset = selection;
- redraw ();
- if (header.isVisible () && drawCount <= 0) header.redraw ();
- }
- }
- }
- TreeColumn[] orderedColumns = getOrderedColumns ();
- for (int i = orderedIndex; i < orderedColumns.length; i++) {
- if (!orderedColumns [i].isDisposed ()) {
- orderedColumns [i].sendEvent (SWT.Move);
- }
- }
-
- if (sortColumn == column) {
- sortColumn = null;
- }
-}
-/*
- * Allows the Tree to update internal structures it has that may contain the
- * item being destroyed. The argument is not necessarily a root-level item.
- */
-void destroyItem (TreeItem item) {
- if (item == focusItem) reassignFocus ();
-
- /* availableItems array */
- int availableIndex = item.availableIndex;
- if (availableIndex != -1) {
- Rectangle bounds = item.getBounds (false);
- int rightX = bounds.x + bounds.width;
-
- if (availableIndex != availableItemsCount - 1) {
- /* item is not at end of available items list, so must shift items left to reclaim its slot */
- System.arraycopy (
- availableItems,
- availableIndex + 1,
- availableItems,
- availableIndex,
- availableItemsCount - availableIndex - 1);
- availableItems [availableItemsCount - 1] = null;
- } else {
- availableItems [availableIndex] = null; /* last item, so no array copy needed */
- }
- availableItemsCount--;
-
- if (drawCount <= 0 && availableItems.length - availableItemsCount == 4) {
- /* shrink the available items array */
- TreeItem[] newAvailableItems = new TreeItem [availableItemsCount];
- System.arraycopy (availableItems, 0, newAvailableItems, 0, newAvailableItems.length);
- availableItems = newAvailableItems;
- }
-
- /* update the availableIndex on affected items */
- for (int i = availableIndex; i < availableItemsCount; i++) {
- availableItems [i].availableIndex = i;
- }
- item.availableIndex = -1;
- int oldTopIndex = topIndex;
- updateVerticalBar ();
- updateHorizontalBar (0, -rightX);
- /*
- * If destroyed item is above viewport then adjust topIndex and the vertical
- * scrollbar so that the current viewport items will not change.
- */
- if (availableIndex < topIndex) {
- topIndex = oldTopIndex - 1;
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) vBar.setSelection (topIndex);
- }
- }
- /* selectedItems array */
- if (item.isSelected ()) {
- int selectionIndex = getSelectionIndex (item);
- TreeItem[] newSelectedItems = new TreeItem [selectedItems.length - 1];
- System.arraycopy (selectedItems, 0, newSelectedItems, 0, selectionIndex);
- System.arraycopy (
- selectedItems,
- selectionIndex + 1,
- newSelectedItems,
- selectionIndex,
- newSelectedItems.length - selectionIndex);
- selectedItems = newSelectedItems;
- }
- /* root-level items array */
- if (item.depth == 0) {
- int index = item.getIndex ();
- TreeItem[] newItems = new TreeItem [items.length - 1];
- System.arraycopy (items, 0, newItems, 0, index);
- System.arraycopy (items, index + 1, newItems, index, newItems.length - index);
- items = newItems;
- }
- if (item == anchorItem) anchorItem = null;
- if (item == insertMarkItem) insertMarkItem = null;
- if (item == lastClickedItem) lastClickedItem = null;
- /*
- * If this was the last item and the receiver has focus then its boundary
- * focus ring must be redrawn.
- */
- if (availableItemsCount == 0 && isFocusControl ()) {
- redraw ();
- return;
- }
-}
-Image getArrowDownImage () {
- return (Image) display.getData (ID_ARROWDOWN);
-}
-Image getArrowUpImage () {
- return (Image) display.getData (ID_ARROWUP);
-}
-int getCellPadding () {
- return MARGIN_CELL + WIDTH_CELL_HIGHLIGHT;
-}
-Image getCheckmarkImage () {
- return (Image) display.getData (ID_CHECKMARK);
-}
-public Control[] getChildren () {
- checkWidget ();
- Control[] controls = _getChildren ();
- if (header == null) return controls;
- Control[] result = new Control [controls.length - 1];
- /* remove the Header from the returned set of children */
- int index = 0;
- for (int i = 0; i < controls.length; i++) {
- if (controls [i] != header) {
- result [index++] = controls [i];
- }
- }
- return result;
-}
-Image getCollapsedImage () {
- return (Image) display.getData (ID_COLLAPSED);
-}
-/**
- * Returns the column at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- * Columns are returned in the order that they were created.
- * If no <code>TreeColumn</code>s were created by the programmer,
- * this method will throw <code>ERROR_INVALID_RANGE</code> despite
- * the fact that a single column of data may be visible in the tree.
- * This occurs when the programmer uses the tree like a list, adding
- * items but never creating a column.
- *
- * @param index the index of the column to return
- * @return the column at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public TreeColumn getColumn (int index) {
- checkWidget ();
- if (!(0 <= index && index < columns.length)) error (SWT.ERROR_INVALID_RANGE);
- return columns [index];
-}
-/**
- * Returns the number of columns contained in the receiver.
- * If no <code>TreeColumn</code>s were created by the programmer,
- * this value is zero, despite the fact that visually, one column
- * of items may be visible. This occurs when the programmer uses
- * the tree like a list, adding items but never creating a column.
- *
- * @return the number of columns
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getColumnCount () {
- checkWidget ();
- return columns.length;
-}
-/**
- * Returns an array of zero-relative integers that map
- * the creation order of the receiver's items to the
- * order in which they are currently being displayed.
- * <p>
- * Specifically, the indices of the returned array represent
- * the current visual order of the items, and the contents
- * of the array represent the creation order of the items.
- * </p><p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the current visual order of the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
-public int[] getColumnOrder () {
- checkWidget ();
- int[] result = new int [columns.length];
- if (orderedColumns != null) {
- for (int i = 0; i < result.length; i++) {
- result [i] = orderedColumns [i].getIndex ();
- }
- } else {
- for (int i = 0; i < columns.length; i++) {
- result [i] = i;
- }
- }
- return result;
-}
-/**
- * Returns an array of <code>TreeColumn</code>s which are the
- * columns in the receiver. Columns are returned in the order
- * that they were created. If no <code>TreeColumn</code>s were
- * created by the programmer, the array is empty, despite the fact
- * that visually, one column of items may be visible. This occurs
- * when the programmer uses the tree like a list, adding items but
- * never creating a column.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public TreeColumn[] getColumns () {
- checkWidget ();
- TreeColumn[] result = new TreeColumn [columns.length];
- System.arraycopy (columns, 0, result, 0, columns.length);
- return result;
-}
-Color getConnectorColor () {
- return (Color) display.getData (ID_CONNECTOR_COLOR);
-}
-Image getExpandedImage () {
- return (Image) display.getData (ID_EXPANDED);
-}
-Image getGrayUncheckedImage () {
- return (Image) display.getData (ID_GRAYUNCHECKED);
-}
-/**
- * Returns the width in pixels of a grid line.
- *
- * @return the width of a grid line in pixels
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getGridLineWidth () {
- checkWidget ();
- return 1;
-}
-/**
- * Returns the height of the receiver's header
- *
- * @return the height of the header or zero if the header is not visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getHeaderHeight () {
- checkWidget ();
- if (!header.getVisible ()) return 0;
- return header.getSize ().y;
-}
-int getHeaderPadding () {
- return MARGIN_CELL + WIDTH_HEADER_SHADOW;
-}
-/**
- * Returns <code>true</code> if the receiver's header is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's header's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public boolean getHeaderVisible () {
- checkWidget ();
- return header.getVisible ();
-}
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- * <p>
- * The item that is returned represents an item that could be selected by the user.
- * For example, if selection only occurs in items in the first column, then null is
- * returned if the point is outside of the item.
- * Note that the SWT.FULL_SELECTION style hint, which specifies the selection policy,
- * determines the extent of the selection.
- * </p>
- *
- * @param point the point used to locate the item
- * @return the item at the given point, or null if the point is not in a selectable item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem getItem (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = (point.y - getHeaderHeight ()) / itemHeight + topIndex;
- if (!(0 <= index && index < availableItemsCount)) return null; /* below the last item */
- TreeItem result = availableItems [index];
- if (!result.getHitBounds ().contains (point)) return null; /* considers the x value */
- return result;
-}
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public TreeItem getItem (int index) {
- checkWidget ();
- if (!(0 <= index && index < items.length)) error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-/**
- * Returns the number of items contained in the receiver
- * that are direct item children of the receiver. The
- * number that is returned is the number of roots in the
- * tree.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return items.length;
-}
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the tree.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- return itemHeight;
-}
-/**
- * Returns a (possibly empty) array of items contained in the
- * receiver that are direct item children of the receiver. These
- * are the roots of the tree.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem[] getItems () {
- checkWidget ();
- TreeItem[] result = new TreeItem [items.length];
- System.arraycopy (items, 0, result, 0, items.length);
- return result;
-}
-/*
- * Returns the current y-coordinate that the specified item should have.
- */
-int getItemY (TreeItem item) {
- int index = item.availableIndex;
- if (index == -1) return -1;
- return (index - topIndex) * itemHeight + getHeaderHeight ();
-}
-/**
- * Returns <code>true</code> if the receiver's lines are visible,
- * and <code>false</code> otherwise. Note that some platforms draw
- * grid lines while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the visibility state of the lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public boolean getLinesVisible () {
- checkWidget ();
- return linesVisible;
-}
-TreeColumn[] getOrderedColumns () {
- if (orderedColumns != null) return orderedColumns;
- return columns;
-}
-/**
- * Returns the receiver's parent item, which must be a
- * <code>TreeItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem getParentItem () {
- checkWidget ();
- return null;
-}
-/**
- * Returns an array of <code>TreeItem</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem[] getSelection () {
- checkWidget ();
- int count = selectedItems.length;
- TreeItem[] result = new TreeItem [count];
- if (count > 0) {
- if (count == 1) {
- System.arraycopy (selectedItems, 0, result, 0, count);
- } else {
- getSelection (result, items, 0);
- }
- }
- return result;
-}
-int getSelection (TreeItem[] result, TreeItem[] items, int index) {
- for (int i = 0; i < items.length; i++) {
- TreeItem item = items [i];
- if (item.isSelected ()) result [index++] = item;
- if (index == result.length) break;
- index = getSelection (result, items [i].items, index);
- if (index == result.length) break;
- }
- return index;
-}
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget ();
- return selectedItems.length;
-}
-/*
- * Returns the index of the argument in the receiver's array of currently-
- * selected items, or -1 if the item is not currently selected.
- */
-int getSelectionIndex (TreeItem item) {
- for (int i = 0; i < selectedItems.length; i++) {
- if (selectedItems [i] == item) return i;
- }
- return -1;
-}
-/**
- * Returns the column which shows the sort indicator for
- * the receiver. The value may be null if no column shows
- * the sort indicator.
- *
- * @return the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortColumn(TreeColumn)
- *
- * @since 3.2
- */
-public TreeColumn getSortColumn () {
- checkWidget ();
- return sortColumn;
-}
-/**
- * Returns the direction of the sort indicator for the receiver.
- * The value will be one of <code>UP</code>, <code>DOWN</code>
- * or <code>NONE</code>.
- *
- * @return the sort direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortDirection(int)
- *
- * @since 3.2
- */
-public int getSortDirection () {
- checkWidget ();
- return sortDirection;
-}
-/**
- * Returns the item which is currently at the top of the receiver.
- * This item can change when items are expanded, collapsed, scrolled
- * or new items are added or removed.
- *
- * @return the item at the top of the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public TreeItem getTopItem () {
- checkWidget ();
- if (availableItemsCount == 0) return null;
- return availableItems [topIndex];
-}
-Image getUncheckedImage () {
- return (Image) display.getData (ID_UNCHECKED);
-}
-void handleEvents (Event event) {
- switch (event.type) {
- case SWT.Paint:
- if (event.widget == header) {
- headerOnPaint (event);
- } else {
- onPaint (event);
- }
- break;
- case SWT.MenuDetect: {
- notifyListeners (SWT.MenuDetect, event);
- break;
- }
- case SWT.MouseDown:
- if (event.widget == header) {
- headerOnMouseDown (event);
- } else {
- onMouseDown (event);
- }
- break;
- case SWT.MouseUp:
- if (event.widget == header) {
- headerOnMouseUp (event);
- } else {
- onMouseUp (event);
- }
- break;
- case SWT.MouseHover:
- headerOnMouseHover (event); break;
- case SWT.MouseMove:
- headerOnMouseMove (event); break;
- case SWT.MouseDoubleClick:
- if (event.widget == header) {
- headerOnMouseDoubleClick (event);
- } else {
- onMouseDoubleClick (event);
- }
- break;
- case SWT.MouseExit:
- headerOnMouseExit (); break;
- case SWT.Dispose:
- onDispose (event); break;
- case SWT.KeyDown:
- onKeyDown (event); break;
- case SWT.Resize:
- onResize (event); break;
- case SWT.Selection:
- if (event.widget == getHorizontalBar ()) {
- onScrollHorizontal (event);
- }
- if (event.widget == getVerticalBar ()) {
- onScrollVertical (event);
- }
- break;
- case SWT.FocusOut:
- onFocusOut (); break;
- case SWT.FocusIn:
- onFocusIn (); break;
- case SWT.Traverse:
- switch (event.detail) {
- case SWT.TRAVERSE_ESCAPE:
- case SWT.TRAVERSE_RETURN:
- case SWT.TRAVERSE_TAB_NEXT:
- case SWT.TRAVERSE_TAB_PREVIOUS:
- case SWT.TRAVERSE_PAGE_NEXT:
- case SWT.TRAVERSE_PAGE_PREVIOUS:
- event.doit = true;
- break;
- }
- break;
- }
-}
-String headerGetToolTip (int x) {
- if (resizeColumn != null) return null;
- int orderedIndex = computeColumnIntersect (x, 0);
- if (orderedIndex == -1) return null;
- TreeColumn[] orderedColumns = getOrderedColumns ();
- TreeColumn column = orderedColumns [orderedIndex];
- if (column.toolTipText == null) return null;
-
- /* no tooltip should appear if the hover is at a column resize opportunity */
- int columnX = column.getX ();
- if (orderedIndex > 0 && orderedColumns [orderedIndex - 1].resizable) {
- /* left column bound is resizable */
- if (x - columnX <= TOLLERANCE_COLUMNRESIZE) return null;
- }
- if (column.resizable) {
- /* right column bound is resizable */
- int columnRightX = columnX + column.width;
- if (columnRightX - x <= TOLLERANCE_COLUMNRESIZE) return null;
- }
- return removeMnemonics (column.toolTipText);
-}
-void headerHideToolTip() {
- if (toolTipShell == null) return;
- for (int i = 0; i < toolTipEvents.length; i++) {
- header.removeListener (toolTipEvents [i], toolTipListener);
- }
- toolTipShell.dispose ();
- toolTipShell = null;
- toolTipLabel = null;
-}
-void headerOnMouseDoubleClick (Event event) {
- if (!isFocusControl ()) setFocus ();
- if (columns.length == 0) return;
- TreeColumn[] orderedColumns = getOrderedColumns ();
- int x = -horizontalOffset;
- for (int i = 0; i < orderedColumns.length; i++) {
- TreeColumn column = orderedColumns [i];
- x += column.width;
- if (event.x < x) {
- /* found the clicked column */
- TreeColumn packColumn = null;
- if (x - event.x <= TOLLERANCE_COLUMNRESIZE) {
- /* clicked on column bound for this column */
- packColumn = column;
- } else {
- if (i > 0 && event.x - column.getX () <= TOLLERANCE_COLUMNRESIZE) {
- /* clicked on column bound that applies to previous column */
- packColumn = orderedColumns [i - 1];
- }
- }
- if (packColumn != null) {
- packColumn.pack ();
- resizeColumn = null;
- if (Math.abs (packColumn.getX () + packColumn.width - event.x) > TOLLERANCE_COLUMNRESIZE) {
- /* column separator has relocated away from pointer location */
- setCursor (null);
- }
- return;
- }
- /* did not click on column separator, so just fire column event */
- Event newEvent = new Event ();
- newEvent.widget = column;
- column.postEvent (SWT.DefaultSelection, newEvent);
- return;
- }
- }
-}
-void headerOnMouseDown (Event event) {
- if (event.button != 1) return;
- TreeColumn[] orderedColumns = getOrderedColumns ();
- int x = -horizontalOffset;
- for (int i = 0; i < orderedColumns.length; i++) {
- TreeColumn column = orderedColumns [i];
- x += column.width;
- /* if close to a resizable column separator line then begin column resize */
- if (column.resizable && Math.abs (x - event.x) <= TOLLERANCE_COLUMNRESIZE) {
- resizeColumn = column;
- resizeColumnX = x;
- return;
- }
- /*
- * If within column but not near separator line then start column drag
- * if column is moveable, or just fire column Selection otherwise.
- */
- if (event.x < x) {
- if (column.moveable) {
- /* open tracker on the dragged column's header cell */
- int columnX = column.getX ();
- int pointerOffset = event.x - columnX;
- headerHideToolTip ();
- Tracker tracker = new Tracker (this, SWT.NONE);
- tracker.setRectangles (new Rectangle[] {
- new Rectangle (columnX, 0, column.width, getHeaderHeight ())
- });
- if (!tracker.open ()) return; /* cancelled */
- /* determine which column was dragged onto */
- Rectangle result = tracker.getRectangles () [0];
- int pointerX = result.x + pointerOffset;
- if (pointerX < 0) return; /* dragged too far left */
- x = -horizontalOffset;
- for (int destIndex = 0; destIndex < orderedColumns.length; destIndex++) {
- TreeColumn destColumn = orderedColumns [destIndex];
- x += destColumn.width;
- if (pointerX < x) {
- int oldIndex = column.getOrderIndex ();
- if (destIndex == oldIndex) { /* dragged onto self */
- Event newEvent = new Event ();
- newEvent.widget = column;
- column.postEvent (SWT.Selection, newEvent);
- return;
- }
- int leftmostIndex = Math.min (destIndex, oldIndex);
- int[] oldOrder = getColumnOrder ();
- int[] newOrder = new int [oldOrder.length];
- System.arraycopy (oldOrder, 0, newOrder, 0, leftmostIndex);
- if (leftmostIndex == oldIndex) {
- /* column moving to the right */
- System.arraycopy (oldOrder, oldIndex + 1, newOrder, oldIndex, destIndex - oldIndex);
- } else {
- /* column moving to the left */
- System.arraycopy (oldOrder, destIndex, newOrder, destIndex + 1, oldIndex - destIndex);
- }
- newOrder [destIndex] = oldOrder [oldIndex];
- int rightmostIndex = Math.max (destIndex, oldIndex);
- System.arraycopy (
- oldOrder,
- rightmostIndex + 1,
- newOrder,
- rightmostIndex + 1,
- newOrder.length - rightmostIndex - 1);
- setColumnOrder (newOrder);
- return;
- }
- }
- return; /* dragged too far right */
- }
- /* column is not moveable */
- Event newEvent = new Event ();
- newEvent.widget = column;
- column.postEvent (SWT.Selection, newEvent);
- return;
- }
- }
-}
-void headerOnMouseExit () {
- if (resizeColumn != null) return;
- setCursor (null); /* ensure that a column resize cursor does not escape */
-}
-void headerOnMouseHover (Event event) {
- headerShowToolTip (event.x);
-}
-void headerOnMouseMove (Event event) {
- if (resizeColumn == null) {
- /* not currently resizing a column */
- for (int i = 0; i < columns.length; i++) {
- TreeColumn column = columns [i];
- int x = column.getX () + column.width;
- if (Math.abs (x - event.x) <= TOLLERANCE_COLUMNRESIZE) {
- if (column.resizable) {
- setCursor (display.getSystemCursor (SWT.CURSOR_SIZEWE));
- } else {
- setCursor (null);
- }
- return;
- }
- }
- setCursor (null);
- return;
- }
-
- /* currently resizing a column */
-
- /* don't allow the resize x to move left of the column's x position */
- if (event.x <= resizeColumn.getX ()) return;
-
- /* redraw the resizing line at its new location */
- GC gc = new GC (this);
- gc.setForeground (display.getSystemColor (SWT.COLOR_BLACK));
- int lineHeight = clientArea.height;
- redraw (resizeColumnX - 1, 0, 1, lineHeight, false);
- resizeColumnX = event.x;
- gc.drawLine (resizeColumnX - 1, 0, resizeColumnX - 1, lineHeight);
- gc.dispose ();
-}
-void headerOnMouseUp (Event event) {
- if (resizeColumn == null) return; /* not resizing a column */
-
- /* remove the resize line */
- GC gc = new GC (this);
- redraw (resizeColumnX - 1, 0, 1, clientArea.height, false);
- gc.dispose ();
-
- int newWidth = resizeColumnX - resizeColumn.getX ();
- if (newWidth != resizeColumn.width) {
- setCursor (null);
- updateColumnWidth (resizeColumn, newWidth);
- }
- resizeColumnX = -1;
- resizeColumn = null;
-}
-void headerOnPaint (Event event) {
- TreeColumn[] orderedColumns = getOrderedColumns ();
- int numColumns = orderedColumns.length;
- GC gc = event.gc;
- Rectangle clipping = gc.getClipping ();
- int startColumn = -1, endColumn = -1;
- if (numColumns > 0) {
- startColumn = computeColumnIntersect (clipping.x, 0);
- if (startColumn != -1) { /* the clip x is within a column's bounds */
- endColumn = computeColumnIntersect (clipping.x + clipping.width, startColumn);
- if (endColumn == -1) endColumn = numColumns - 1;
- }
- } else {
- startColumn = endColumn = 0;
- }
-
- /* paint the column header shadow that spans the full header width */
- Point headerSize = header.getSize ();
- headerPaintHShadows (gc, 0, 0, headerSize.x, headerSize.y);
-
- /* if all damage is to the right of the last column then finished */
- if (startColumn == -1) return;
-
- /* paint each of the column headers */
- if (numColumns == 0) return; /* no headers to paint */
- for (int i = startColumn; i <= endColumn; i++) {
- headerPaintVShadows (gc, orderedColumns [i].getX (), 0, orderedColumns [i].width, headerSize.y);
- orderedColumns [i].paint (gc);
- }
-}
-void headerPaintHShadows (GC gc, int x, int y, int width, int height) {
- gc.setClipping (x, y, width, height);
- int endX = x + width;
- gc.setForeground (display.getSystemColor (SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
- gc.drawLine (x, y, endX, y); /* highlight shadow */
- gc.setForeground (display.getSystemColor (SWT.COLOR_WIDGET_NORMAL_SHADOW));
- gc.drawLine (x, height - 2, endX, height - 2); /* lowlight shadow */
- gc.setForeground (display.getSystemColor (SWT.COLOR_WIDGET_DARK_SHADOW));
- gc.drawLine (x, height - 1, endX, height - 1); /* outer shadow */
-}
-void headerPaintVShadows (GC gc, int x, int y, int width, int height) {
- gc.setClipping (x, y, width, height);
- int endX = x + width;
- gc.setForeground (display.getSystemColor (SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
- gc.drawLine (x, y, x, y + height - 1); /* highlight shadow */
- gc.setForeground (display.getSystemColor (SWT.COLOR_WIDGET_NORMAL_SHADOW));
- gc.drawLine (endX - 2, y + 1, endX - 2, height - 2); /* light inner shadow */
- gc.setForeground (display.getSystemColor (SWT.COLOR_WIDGET_DARK_SHADOW));
- gc.drawLine (endX - 1, y, endX - 1, height - 1); /* dark outer shadow */
-}
-void headerShowToolTip (int x) {
- String tooltip = headerGetToolTip (x);
- if (tooltip == null || tooltip.length () == 0) return;
-
- if (toolTipShell == null) {
- toolTipShell = new Shell (getShell (), SWT.ON_TOP | SWT.TOOL);
- toolTipLabel = new Label (toolTipShell, SWT.CENTER);
- Display display = toolTipShell.getDisplay ();
- toolTipLabel.setForeground (display.getSystemColor (SWT.COLOR_INFO_FOREGROUND));
- toolTipLabel.setBackground (display.getSystemColor (SWT.COLOR_INFO_BACKGROUND));
- for (int i = 0; i < toolTipEvents.length; i++) {
- header.addListener (toolTipEvents [i], toolTipListener);
- }
- }
- if (headerUpdateToolTip (x)) {
- toolTipShell.setVisible (true);
- } else {
- headerHideToolTip ();
- }
-}
-boolean headerUpdateToolTip (int x) {
- String tooltip = headerGetToolTip (x);
- if (tooltip == null || tooltip.length () == 0) return false;
- if (tooltip.equals (toolTipLabel.getText ())) return true;
-
- toolTipLabel.setText (tooltip);
- TreeColumn column = getOrderedColumns () [computeColumnIntersect (x, 0)];
- toolTipShell.setData (new Integer (column.getIndex ()));
- Point labelSize = toolTipLabel.computeSize (SWT.DEFAULT, SWT.DEFAULT, true);
- labelSize.x += 2; labelSize.y += 2;
- toolTipLabel.setSize (labelSize);
- toolTipShell.pack ();
- /*
- * On some platforms, there is a minimum size for a shell
- * which may be greater than the label size.
- * To avoid having the background of the tip shell showing
- * around the label, force the label to fill the entire client area.
- */
- Rectangle area = toolTipShell.getClientArea ();
- toolTipLabel.setSize (area.width, area.height);
-
- /* Position the tooltip and ensure it's not located off the screen */
- Point cursorLocation = getDisplay ().getCursorLocation ();
- int cursorHeight = 21; /* assuming cursor is 21x21 */
- Point size = toolTipShell.getSize ();
- Rectangle rect = getMonitor ().getBounds ();
- Point pt = new Point (cursorLocation.x, cursorLocation.y + cursorHeight + 2);
- pt.x = Math.max (pt.x, rect.x);
- if (pt.x + size.x > rect.x + rect.width) pt.x = rect.x + rect.width - size.x;
- if (pt.y + size.y > rect.y + rect.height) pt.y = cursorLocation.y - 2 - size.y;
- toolTipShell.setLocation (pt);
- return true;
-}
-/**
- * Searches the receiver's list starting at the first column
- * (index 0) until a column is found that is equal to the
- * argument, and returns the index of that column. If no column
- * is found, returns -1.
- *
- * @param column the search column
- * @return the index of the column
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the column is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int indexOf (TreeColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- return column.getIndex ();
-}
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int indexOf (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (item.parentItem != null || item.parent != this) return -1;
- return item.getIndex ();
-}
-static void initImages (final Display display) {
- PaletteData fourBit = new PaletteData (new RGB[] {
- new RGB (0, 0, 0), new RGB (128, 0, 0), new RGB (0, 128, 0), new RGB (128, 128, 0),
- new RGB (0, 0, 128), new RGB (128, 0, 128), new RGB (0, 128, 128), new RGB (128, 128, 128),
- new RGB (192, 192, 192), new RGB (255, 0, 0), new RGB (0, 255, 0), new RGB (255, 255, 0),
- new RGB (0, 0, 255), new RGB (255, 0, 255), new RGB (0, 255, 255), new RGB (255, 255, 255)});
-
- if (display.getData (ID_EXPANDED) == null) {
- ImageData expanded = new ImageData (
- 9, 9, 4, /* width, height, depth */
- fourBit, 4,
- new byte[] {
- 119, 119, 119, 119, 112, 0, 0, 0,
- 127, -1, -1, -1, 112, 0, 0, 0,
- 127, -1, -1, -1, 112, 0, 0, 0,
- 127, -1, -1, -1, 112, 0, 0, 0,
- 127, 0, 0, 15, 112, 0, 0, 0,
- 127, -1, -1, -1, 112, 0, 0, 0,
- 127, -1, -1, -1, 112, 0, 0, 0,
- 127, -1, -1, -1, 112, 0, 0, 0,
- 119, 119, 119, 119, 112, 0, 0, 0});
- expanded.transparentPixel = 15; /* use white for transparency */
- display.setData (ID_EXPANDED, new Image (display, expanded));
- }
-
- if (display.getData (ID_COLLAPSED) == null) {
- ImageData collapsed = new ImageData (
- 9, 9, 4, /* width, height, depth */
- fourBit, 4,
- new byte[] {
- 119, 119, 119, 119, 112, 0, 0, 0,
- 127, -1, -1, -1, 112, 0, 0, 0,
- 127, -1, 15, -1, 112, 0, 0, 0,
- 127, -1, 15, -1, 112, 0, 0, 0,
- 127, 0, 0, 15, 112, 0, 0, 0,
- 127, -1, 15, -1, 112, 0, 0, 0,
- 127, -1, 15, -1, 112, 0, 0, 0,
- 127, -1, -1, -1, 112, 0, 0, 0,
- 119, 119, 119, 119, 112, 0, 0, 0});
- collapsed.transparentPixel = 15; /* use white for transparency */
- display.setData (ID_COLLAPSED, new Image (display, collapsed));
- }
-
- PaletteData arrowPalette = new PaletteData (new RGB[] {
- new RGB (0, 0, 0), new RGB (255, 255, 255)});
- if (display.getData (ID_ARROWDOWN) == null) {
- ImageData arrowDown = new ImageData (
- 7, 4, 1,
- arrowPalette, 1,
- new byte[] {0x00, (byte)0x83, (byte)0xC7, (byte)0xEF});
- arrowDown.transparentPixel = 0x1; /* use white for transparency */
- display.setData (ID_ARROWDOWN, new Image (display, arrowDown));
- }
- if (display.getData (ID_ARROWUP) == null) {
- ImageData arrowUp = new ImageData (
- 7, 4, 1,
- arrowPalette, 1,
- new byte[] {(byte)0xEF, (byte)0xC7, (byte)0x83, 0x00});
- arrowUp.transparentPixel = 0x1; /* use white for transparency */
- display.setData (ID_ARROWUP, new Image (display, arrowUp));
- }
-
- PaletteData checkMarkPalette = new PaletteData (
- new RGB[] {new RGB (0, 0, 0), new RGB (252, 3, 251)});
- byte[] checkbox = new byte[] {0, 0, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 0, 0};
- ImageData checkmark = new ImageData (7, 7, 1, checkMarkPalette, 1, new byte[] {-4, -8, 112, 34, 6, -114, -34});
- checkmark.transparentPixel = 1;
- if (display.getData (ID_CHECKMARK) == null) {
- display.setData (ID_CHECKMARK, new Image (display, checkmark));
- }
-
- if (display.getData (ID_UNCHECKED) == null) {
- PaletteData uncheckedPalette = new PaletteData (
- new RGB[] {new RGB (128, 128, 128), new RGB (255, 255, 255)});
- ImageData unchecked = new ImageData (11, 11, 1, uncheckedPalette, 2, checkbox);
- display.setData (ID_UNCHECKED, new Image (display, unchecked));
- }
-
- if (display.getData (ID_GRAYUNCHECKED) == null) {
- PaletteData grayUncheckedPalette = new PaletteData (
- new RGB[] {new RGB (128, 128, 128), new RGB (192, 192, 192)});
- ImageData grayUnchecked = new ImageData (11, 11, 1, grayUncheckedPalette, 2, checkbox);
- display.setData (ID_GRAYUNCHECKED, new Image (display, grayUnchecked));
- }
-
- if (display.getData (ID_CONNECTOR_COLOR) == null) {
- display.setData (ID_CONNECTOR_COLOR, new Color (display, 170, 170, 170));
- }
-
- display.disposeExec (new Runnable () {
- public void run() {
- Image expanded = (Image) display.getData (ID_EXPANDED);
- if (expanded != null) expanded.dispose ();
- Image collapsed = (Image) display.getData (ID_COLLAPSED);
- if (collapsed != null) collapsed.dispose ();
- Color connectorColor = (Color) display.getData (ID_CONNECTOR_COLOR);
- if (connectorColor != null) connectorColor.dispose ();
- Image unchecked = (Image) display.getData (ID_UNCHECKED);
- if (unchecked != null) unchecked.dispose ();
- Image grayUnchecked = (Image) display.getData (ID_GRAYUNCHECKED);
- if (grayUnchecked != null) grayUnchecked.dispose ();
- Image checkmark = (Image) display.getData (ID_CHECKMARK);
- if (checkmark != null) checkmark.dispose ();
- Image arrowDown = (Image) display.getData (ID_ARROWDOWN);
- if (arrowDown != null) arrowDown.dispose ();
- Image arrowUp = (Image) display.getData (ID_ARROWUP);
- if (arrowUp != null) arrowUp.dispose ();
-
- display.setData (ID_EXPANDED, null);
- display.setData (ID_COLLAPSED, null);
- display.setData (ID_CONNECTOR_COLOR, null);
- display.setData (ID_UNCHECKED, null);
- display.setData (ID_GRAYUNCHECKED, null);
- display.setData (ID_CHECKMARK, null);
- display.setData (ID_ARROWDOWN, null);
- display.setData (ID_ARROWUP, null);
- }
- });
-}
-/*
- * Important: Assumes that item just became available (ie.- was either created
- * or the parent item was expanded) and the parent is available.
- */
-void makeAvailable (TreeItem item) {
- int parentItemCount = item.parentItem.items.length;
- int index = 0;
- if (parentItemCount == 1) { /* this is the only child of parentItem */
- index = item.parentItem.availableIndex + 1;
- } else {
- /* determine this item's index in its parent */
- int itemIndex = 0;
- TreeItem[] items = item.parentItem.items;
- for (int i = 0; i < items.length; i++) {
- if (items [i] == item) {
- itemIndex = i;
- break;
- }
- }
- if (itemIndex != parentItemCount - 1) { /* this is not the last child */
- index = items [itemIndex + 1].availableIndex;
- } else { /* this is the last child */
- TreeItem previousItem = items [itemIndex - 1];
- index = previousItem.availableIndex + previousItem.computeAvailableDescendentCount ();
- }
- }
-
- if (availableItemsCount == availableItems.length) {
- int grow = drawCount <= 0 ? 4 : Math.max (4, availableItems.length * 3 / 2);
- TreeItem[] newAvailableItems = new TreeItem [availableItems.length + grow];
- System.arraycopy (availableItems, 0, newAvailableItems, 0, availableItems.length);
- availableItems = newAvailableItems;
- }
- if (index != availableItemsCount) {
- /* new item is not at end of list, so shift other items right to create space for it */
- System.arraycopy (availableItems, index, availableItems, index + 1, availableItemsCount - index);
- }
- availableItems [index] = item;
- availableItemsCount++;
-
- /* update availableIndex as needed */
- for (int i = index; i < availableItemsCount; i++) {
- availableItems [i].availableIndex = i;
- }
-}
-
-/*
- * Important: Assumes that item is available and its descendents have just become
- * available (ie.- they were either created or the item was expanded).
- */
-void makeDescendentsAvailable (TreeItem item, TreeItem[] descendents) {
- int itemAvailableIndex = item.availableIndex;
- TreeItem[] newAvailableItems = new TreeItem [availableItemsCount + descendents.length - 1];
-
- System.arraycopy (availableItems, 0, newAvailableItems, 0, itemAvailableIndex);
- System.arraycopy (descendents, 0, newAvailableItems, itemAvailableIndex, descendents.length);
- int startIndex = itemAvailableIndex + 1;
- System.arraycopy (
- availableItems,
- startIndex,
- newAvailableItems,
- itemAvailableIndex + descendents.length,
- availableItemsCount - startIndex);
- availableItems = newAvailableItems;
- availableItemsCount = availableItems.length;
-
- /* update availableIndex as needed */
- for (int i = itemAvailableIndex; i < availableItemsCount; i++) {
- availableItems [i].availableIndex = i;
- }
-}
-
-/*
- * Important: Assumes that item is available and its descendents have just become
- * unavailable (ie.- they were either disposed or the item was collapsed).
- */
-void makeDescendentsUnavailable (TreeItem item, TreeItem[] descendents) {
- int descendentsLength = descendents.length;
- TreeItem[] newAvailableItems = new TreeItem [availableItemsCount - descendentsLength + 1];
-
- System.arraycopy (availableItems, 0, newAvailableItems, 0, item.availableIndex + 1);
- int startIndex = item.availableIndex + descendentsLength;
- System.arraycopy (
- availableItems,
- startIndex,
- newAvailableItems,
- item.availableIndex + 1,
- availableItemsCount - startIndex);
- availableItems = newAvailableItems;
- availableItemsCount = availableItems.length;
-
- /* update availableIndexes */
- for (int i = 1; i < descendents.length; i++) {
- /* skip the first descendent since this is the item being collapsed */
- descendents [i].availableIndex = -1;
- }
- for (int i = item.availableIndex; i < availableItemsCount; i++) {
- availableItems [i].availableIndex = i;
- }
-
- /* remove the selection from all descendents */
- for (int i = selectedItems.length - 1; i >= 0; i--) {
- if (selectedItems [i] != item && selectedItems [i].hasAncestor (item)) {
- removeSelectedItem (i);
- }
- }
-
- /* if the anchorItem is being hidden then clear it */
- if (anchorItem != null && anchorItem != item && anchorItem.hasAncestor (item)) {
- anchorItem = null;
- }
-}
-void onArrowDown (int stateMask) {
- if ((stateMask & (SWT.SHIFT | SWT.CTRL)) == 0) {
- /* Down Arrow with no modifiers */
- int newFocusIndex = focusItem.availableIndex + 1;
- if (newFocusIndex == availableItemsCount) return; /* at bottom */
- selectItem (availableItems [newFocusIndex], false);
- setFocusItem (availableItems [newFocusIndex], true);
- redrawItem (newFocusIndex, true);
- showItem (availableItems [newFocusIndex]);
- Event newEvent = new Event ();
- newEvent.item = availableItems [newFocusIndex];
- postEvent (SWT.Selection, newEvent);
- return;
- }
- if ((style & SWT.SINGLE) != 0) {
- if ((stateMask & SWT.CTRL) != 0) {
- /* CTRL+Down Arrow, CTRL+Shift+Down Arrow */
- int visibleItemCount = (clientArea.height - getHeaderHeight ()) / itemHeight;
- if (availableItemsCount <= topIndex + visibleItemCount) return; /* at bottom */
- update ();
- topIndex++;
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) vBar.setSelection (topIndex);
- GC gc = new GC (this);
- gc.copyArea (
- 0, 0,
- clientArea.width, clientArea.height,
- 0, -itemHeight);
- gc.dispose ();
- return;
- }
- /* Shift+Down Arrow */
- int newFocusIndex = focusItem.availableIndex + 1;
- if (newFocusIndex == availableItemsCount) return; /* at bottom */
- selectItem (availableItems [newFocusIndex], false);
- setFocusItem (availableItems [newFocusIndex], true);
- redrawItem (newFocusIndex, true);
- showItem (availableItems [newFocusIndex]);
- Event newEvent = new Event ();
- newEvent.item = availableItems [newFocusIndex];
- postEvent (SWT.Selection, newEvent);
- return;
- }
- /* SWT.MULTI */
- if ((stateMask & SWT.CTRL) != 0) {
- if ((stateMask & SWT.SHIFT) != 0) {
- /* CTRL+Shift+Down Arrow */
- int visibleItemCount = (clientArea.height - getHeaderHeight ()) / itemHeight;
- if (availableItemsCount <= topIndex + visibleItemCount) return; /* at bottom */
- update ();
- topIndex++;
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) vBar.setSelection (topIndex);
- GC gc = new GC (this);
- gc.copyArea (
- 0, 0,
- clientArea.width, clientArea.height,
- 0, -itemHeight);
- gc.dispose ();
- return;
- }
- /* CTRL+Down Arrow */
- int focusIndex = focusItem.availableIndex;
- if (focusIndex == availableItemsCount - 1) return; /* at bottom */
- TreeItem newFocusItem = availableItems [focusIndex + 1];
- setFocusItem (newFocusItem, true);
- redrawItem (newFocusItem.availableIndex, true);
- showItem (newFocusItem);
- return;
- }
- /* Shift+Down Arrow */
- int newFocusIndex = focusItem.availableIndex + 1;
- if (newFocusIndex == availableItemsCount) return; /* at bottom */
- if (anchorItem == null) anchorItem = focusItem;
- if (focusItem.availableIndex < anchorItem.availableIndex) {
- deselectItem (focusItem);
- redrawItem (focusItem.availableIndex, true);
- }
- selectItem (availableItems [newFocusIndex], true);
- setFocusItem (availableItems [newFocusIndex], true);
- redrawItem (newFocusIndex, true);
- showItem (availableItems [newFocusIndex]);
- Event newEvent = new Event ();
- newEvent.item = availableItems [newFocusIndex];
- postEvent (SWT.Selection, newEvent);
-}
-void onArrowLeft (int stateMask) {
- if ((stateMask & SWT.CTRL) != 0) {
- /* CTRL+Left Arrow, CTRL+Shift+Left Arrow */
- if (horizontalOffset == 0) return;
- int newSelection = Math.max (0, horizontalOffset - SIZE_HORIZONTALSCROLL);
- update ();
- GC gc = new GC (this);
- gc.copyArea (
- 0, 0,
- clientArea.width, clientArea.height,
- horizontalOffset - newSelection, 0);
- gc.dispose ();
- if (header.getVisible ()) {
- header.update ();
- Rectangle headerClientArea = header.getClientArea ();
- gc = new GC (header);
- gc.copyArea (
- 0, 0,
- headerClientArea.width, headerClientArea.height,
- horizontalOffset - newSelection, 0);
- gc.dispose();
- }
- horizontalOffset = newSelection;
- ScrollBar hBar = getHorizontalBar ();
- if (hBar != null) hBar.setSelection (horizontalOffset);
- return;
- }
- /* Left Arrow with no modifiers, Shift+Left Arrow */
- if (focusItem.expanded) {
- focusItem.setExpanded (false);
- Event newEvent = new Event ();
- newEvent.item = focusItem;
- sendEvent (SWT.Collapse, newEvent);
- return;
- }
- TreeItem parentItem = focusItem.parentItem;
- if (parentItem == null) return;
-
- selectItem (parentItem, false);
- setFocusItem (parentItem, true);
- redrawItem (parentItem.availableIndex, true);
- showItem (parentItem);
- Event newEvent = new Event ();
- newEvent.item = parentItem;
- postEvent (SWT.Selection, newEvent);
-}
-void onArrowRight (int stateMask) {
- if ((stateMask & SWT.CTRL) != 0) {
- /* CTRL+Right Arrow, CTRL+Shift+Right Arrow */
- ScrollBar hBar = getHorizontalBar ();
- if (hBar != null) {
- int maximum = hBar.getMaximum ();
- int clientWidth = clientArea.width;
- if ((horizontalOffset + clientWidth) == maximum) return;
- if (maximum <= clientWidth) return;
- int newSelection = Math.min (horizontalOffset + SIZE_HORIZONTALSCROLL, maximum - clientWidth);
- update ();
- GC gc = new GC (this);
- gc.copyArea (
- 0, 0,
- clientArea.width, clientArea.height,
- horizontalOffset - newSelection, 0);
- gc.dispose ();
- if (header.getVisible ()) {
- Rectangle headerClientArea = header.getClientArea ();
- header.update ();
- gc = new GC (header);
- gc.copyArea (
- 0, 0,
- headerClientArea.width, headerClientArea.height,
- horizontalOffset - newSelection, 0);
- gc.dispose();
- }
- horizontalOffset = newSelection;
- hBar.setSelection (horizontalOffset);
- }
- return;
- }
- /* Right Arrow with no modifiers, Shift+Right Arrow */
- TreeItem[] children = focusItem.items;
- if (children.length == 0) return;
- if (!focusItem.expanded) {
- focusItem.setExpanded (true);
- Event newEvent = new Event ();
- newEvent.item = focusItem;
- inExpand = true;
- sendEvent (SWT.Expand, newEvent);
- inExpand = false;
- if (isDisposed ()) return;
- if (focusItem.items.length == 0) {
- focusItem.expanded = false;
- }
- return;
- }
- selectItem (children [0], false);
- setFocusItem (children [0], true);
- redrawItem (children [0].availableIndex, true);
- showItem (children [0]);
- Event newEvent = new Event ();
- newEvent.item = children [0];
- postEvent (SWT.Selection, newEvent);
-}
-void onArrowUp (int stateMask) {
- if ((stateMask & (SWT.SHIFT | SWT.CTRL)) == 0) {
- /* Up Arrow with no modifiers */
- int newFocusIndex = focusItem.availableIndex - 1;
- if (newFocusIndex < 0) return; /* at top */
- TreeItem item = availableItems [newFocusIndex];
- selectItem (item, false);
- setFocusItem (item, true);
- redrawItem (newFocusIndex, true);
- showItem (item);
- Event newEvent = new Event ();
- newEvent.item = item;
- postEvent (SWT.Selection, newEvent);
- return;
- }
- if ((style & SWT.SINGLE) != 0) {
- if ((stateMask & SWT.CTRL) != 0) {
- /* CTRL+Up Arrow, CTRL+Shift+Up Arrow */
- if (topIndex == 0) return; /* at top */
- update ();
- topIndex--;
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) vBar.setSelection (topIndex);
- GC gc = new GC (this);
- gc.copyArea (
- 0, 0,
- clientArea.width, clientArea.height,
- 0, itemHeight);
- gc.dispose ();
- return;
- }
- /* Shift+Up Arrow */
- int newFocusIndex = focusItem.availableIndex - 1;
- if (newFocusIndex < 0) return; /* at top */
- TreeItem item = availableItems [newFocusIndex];
- selectItem (item, false);
- setFocusItem (item, true);
- redrawItem (newFocusIndex, true);
- showItem (item);
- Event newEvent = new Event ();
- newEvent.item = item;
- postEvent (SWT.Selection, newEvent);
- return;
- }
- /* SWT.MULTI */
- if ((stateMask & SWT.CTRL) != 0) {
- if ((stateMask & SWT.SHIFT) != 0) {
- /* CTRL+Shift+Up Arrow */
- if (topIndex == 0) return; /* at top */
- update ();
- topIndex--;
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) vBar.setSelection (topIndex);
- GC gc = new GC (this);
- gc.copyArea (
- 0, 0,
- clientArea.width, clientArea.height,
- 0, itemHeight);
- gc.dispose ();
- return;
- }
- /* CTRL+Up Arrow */
- int focusIndex = focusItem.availableIndex;
- if (focusIndex == 0) return; /* at top */
- TreeItem newFocusItem = availableItems [focusIndex - 1];
- setFocusItem (newFocusItem, true);
- showItem (newFocusItem);
- redrawItem (newFocusItem.availableIndex, true);
- return;
- }
- /* Shift+Up Arrow */
- int newFocusIndex = focusItem.availableIndex - 1;
- if (newFocusIndex < 0) return; /* at top */
- if (anchorItem == null) anchorItem = focusItem;
- if (anchorItem.availableIndex < focusItem.availableIndex) {
- deselectItem (focusItem);
- redrawItem (focusItem.availableIndex, true);
- }
- TreeItem item = availableItems [newFocusIndex];
- selectItem (item, true);
- setFocusItem (item, true);
- redrawItem (newFocusIndex, true);
- showItem (item);
- Event newEvent = new Event ();
- newEvent.item = item;
- postEvent (SWT.Selection, newEvent);
-}
-void onCR () {
- if (focusItem == null) return;
- Event event = new Event ();
- event.item = focusItem;
- postEvent (SWT.DefaultSelection, event);
-}
-void onDispose (Event event) {
- if (isDisposed ()) return;
- if (ignoreDispose) return;
- ignoreDispose = true;
- notifyListeners(SWT.Dispose, event);
- event.type = SWT.None;
- for (int i = 0; i < items.length; i++) {
- items [i].dispose (false);
- }
- for (int i = 0; i < columns.length; i++) {
- columns [i].dispose (false);
- }
- if (toolTipShell != null) {
- toolTipShell.dispose ();
- toolTipShell = null;
- toolTipLabel = null;
- }
- toolTipListener = null;
- topIndex = availableItemsCount = horizontalOffset = 0;
- availableItems = items = selectedItems = null;
- columns = orderedColumns = null;
- focusItem = anchorItem = insertMarkItem = lastClickedItem = null;
- lastSelectionEvent = null;
- header = null;
- resizeColumn = sortColumn = null;
- expanderBounds = null;
-}
-void onEnd (int stateMask) {
- int lastAvailableIndex = availableItemsCount - 1;
- if ((stateMask & (SWT.CTRL | SWT.SHIFT)) == 0) {
- /* End with no modifiers */
- if (focusItem.availableIndex == lastAvailableIndex) return; /* at bottom */
- TreeItem item = availableItems [lastAvailableIndex];
- selectItem (item, false);
- setFocusItem (item, true);
- redrawItem (lastAvailableIndex, true);
- showItem (item);
- Event newEvent = new Event ();
- newEvent.item = item;
- postEvent (SWT.Selection, newEvent);
- return;
- }
- if ((style & SWT.SINGLE) != 0) {
- if ((stateMask & SWT.CTRL) != 0) {
- /* CTRL+End, CTRL+Shift+End */
- int visibleItemCount = (clientArea.height - getHeaderHeight ()) / itemHeight;
- setTopItem (availableItems [availableItemsCount - visibleItemCount]);
- return;
- }
- /* Shift+End */
- if (focusItem.availableIndex == lastAvailableIndex) return; /* at bottom */
- TreeItem item = availableItems [lastAvailableIndex];
- selectItem (item, false);
- setFocusItem (item, true);
- redrawItem (lastAvailableIndex, true);
- showItem (item);
- Event newEvent = new Event ();
- newEvent.item = item;
- postEvent (SWT.Selection, newEvent);
- return;
- }
- /* SWT.MULTI */
- if ((stateMask & SWT.CTRL) != 0) {
- if ((stateMask & SWT.SHIFT) != 0) {
- /* CTRL+Shift+End */
- showItem (availableItems [lastAvailableIndex]);
- return;
- }
- /* CTRL+End */
- if (focusItem.availableIndex == lastAvailableIndex) return; /* at bottom */
- TreeItem item = availableItems [lastAvailableIndex];
- setFocusItem (item, true);
- showItem (item);
- redrawItem (item.availableIndex, true);
- return;
- }
- /* Shift+End */
- if (anchorItem == null) anchorItem = focusItem;
- TreeItem selectedItem = availableItems [lastAvailableIndex];
- if (selectedItem == focusItem && selectedItem.isSelected ()) return;
- int anchorIndex = anchorItem.availableIndex;
- int selectIndex = selectedItem.availableIndex;
- TreeItem[] newSelection = new TreeItem [selectIndex - anchorIndex + 1];
- int writeIndex = 0;
- for (int i = anchorIndex; i <= selectIndex; i++) {
- newSelection [writeIndex++] = availableItems [i];
- }
- setSelection (newSelection, false);
- setFocusItem (selectedItem, true);
- redrawItems (anchorIndex, selectIndex, true);
- showItem (selectedItem);
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
-}
-void onFocusIn () {
- hasFocus = true;
-
- if (items.length == 0) {
- redraw ();
- return;
- }
- if (focusItem != null) {
- redrawItem (focusItem.availableIndex, true);
- return;
- }
- /* an initial focus item must be selected */
- TreeItem initialFocus = null;
- if (selectedItems.length > 0) {
- for (int i = 0; i < selectedItems.length && initialFocus == null; i++) {
- if (selectedItems [i].isAvailable ()) {
- initialFocus = selectedItems [i];
- }
- }
- if (initialFocus == null) {
- /* none of the selected items are available */
- initialFocus = availableItems [topIndex];
- }
- } else {
- initialFocus = availableItems [topIndex];
- }
- setFocusItem (initialFocus, false);
- redrawItem (initialFocus.availableIndex, true);
- return;
-}
-void onFocusOut () {
- hasFocus = false;
-
- if (items.length == 0) {
- redraw ();
- return;
- }
-
- if (focusItem != null) {
- redrawItem (focusItem.availableIndex, true);
- }
-}
-void onHome (int stateMask) {
- if ((stateMask & (SWT.CTRL | SWT.SHIFT)) == 0) {
- /* Home with no modifiers */
- if (focusItem.availableIndex == 0) return; /* at top */
- TreeItem item = availableItems [0];
- selectItem (item, false);
- setFocusItem (item, true);
- redrawItem (0, true);
- showItem (item);
- Event newEvent = new Event ();
- newEvent.item = item;
- postEvent (SWT.Selection, newEvent);
- return;
- }
- if ((style & SWT.SINGLE) != 0) {
- if ((stateMask & SWT.CTRL) != 0) {
- /* CTRL+Home, CTRL+Shift+Home */
- setTopItem (availableItems [0]);
- return;
- }
- /* Shift+Home */
- if (focusItem.availableIndex == 0) return; /* at top */
- TreeItem item = availableItems [0];
- selectItem (item, false);
- setFocusItem (item, true);
- redrawItem (0, true);
- showItem (item);
- Event newEvent = new Event ();
- newEvent.item = item;
- postEvent (SWT.Selection, newEvent);
- return;
- }
- /* SWT.MULTI */
- if ((stateMask & SWT.CTRL) != 0) {
- if ((stateMask & SWT.SHIFT) != 0) {
- /* CTRL+Shift+Home */
- setTopItem (availableItems [0]);
- return;
- }
- /* CTRL+Home */
- if (focusItem.availableIndex == 0) return; /* at top */
- TreeItem item = availableItems [0];
- setFocusItem (item, true);
- showItem (item);
- redrawItem (item.availableIndex, true);
- return;
- }
- /* Shift+Home */
- if (anchorItem == null) anchorItem = focusItem;
- TreeItem selectedItem = availableItems [0];
- if (selectedItem == focusItem && selectedItem.isSelected ()) return;
- int anchorIndex = anchorItem.availableIndex;
- int selectIndex = selectedItem.availableIndex;
- TreeItem[] newSelection = new TreeItem [anchorIndex + 1];
- int writeIndex = 0;
- for (int i = anchorIndex; i >= 0; i--) {
- newSelection [writeIndex++] = availableItems [i];
- }
- setSelection (newSelection, false);
- setFocusItem (selectedItem, true);
- redrawItems (anchorIndex, selectIndex, true);
- showItem (selectedItem);
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
-}
-void onKeyDown (Event event) {
- if (ignoreKey) {
- ignoreKey = false;
- return;
- }
- ignoreKey = true;
- notifyListeners (event.type, event);
- event.type = SWT.None;
- if (!event.doit) return;
- if (focusItem == null) return;
- if ((event.stateMask & SWT.SHIFT) == 0 && event.keyCode != SWT.SHIFT) {
- anchorItem = null;
- }
- switch (event.keyCode) {
- case SWT.ARROW_UP:
- onArrowUp (event.stateMask);
- return;
- case SWT.ARROW_DOWN:
- onArrowDown (event.stateMask);
- return;
- case SWT.ARROW_LEFT:
- onArrowLeft (event.stateMask);
- return;
- case SWT.ARROW_RIGHT:
- onArrowRight (event.stateMask);
- return;
- case SWT.PAGE_UP:
- onPageUp (event.stateMask);
- return;
- case SWT.PAGE_DOWN:
- onPageDown (event.stateMask);
- return;
- case SWT.HOME:
- onHome (event.stateMask);
- return;
- case SWT.END:
- onEnd (event.stateMask);
- return;
- }
- if (event.character == ' ') {
- onSpace ();
- return;
- }
- if (event.character == SWT.CR) {
- onCR ();
- return;
- }
- if ((event.stateMask & SWT.CTRL) != 0) return;
-
- int initialIndex = focusItem.availableIndex;
- char character = Character.toLowerCase (event.character);
- /* check available items from current focus item to bottom */
- for (int i = initialIndex + 1; i < availableItemsCount; i++) {
- TreeItem item = availableItems [i];
- String text = item.getText (0, false);
- if (text.length() > 0) {
- if (Character.toLowerCase (text.charAt (0)) == character) {
- selectItem (item, false);
- setFocusItem (item, true);
- redrawItem (i, true);
- showItem (item);
- Event newEvent = new Event ();
- newEvent.item = item;
- postEvent (SWT.Selection, newEvent);
- return;
- }
- }
- }
- /* check available items from top to current focus item */
- for (int i = 0; i < initialIndex; i++) {
- TreeItem item = availableItems [i];
- String text = item.getText (0, false);
- if (text.length() > 0) {
- if (Character.toLowerCase (text.charAt (0)) == character) {
- selectItem (item, false);
- setFocusItem (item, true);
- redrawItem (i, true);
- showItem (item);
- Event newEvent = new Event ();
- newEvent.item = item;
- postEvent (SWT.Selection, newEvent);
- return;
- }
- }
- }
-}
-void onMouseDoubleClick (Event event) {
- if (!isFocusControl ()) setFocus ();
- int index = (event.y - getHeaderHeight ()) / itemHeight + topIndex;
- if (!(0 <= index && index < availableItemsCount)) return; /* not on an available item */
- TreeItem selectedItem = availableItems [index];
-
- /*
- * If the two clicks of the double click did not occur over the same item then do not
- * consider this to be a default selection.
- */
- if (selectedItem != lastClickedItem) return;
-
- /* if click was in expander box then don't fire event */
- if (selectedItem.items.length > 0 && selectedItem.getExpanderBounds ().contains (event.x, event.y)) {
- return;
- }
-
- if (!selectedItem.getHitBounds ().contains (event.x, event.y)) return; /* considers x */
-
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.DefaultSelection, newEvent);
-}
-void onMouseDown (Event event) {
- if (!isFocusControl ()) forceFocus ();
- int index = (event.y - getHeaderHeight ()) / itemHeight + topIndex;
- if (!(0 <= index && index < availableItemsCount)) return; /* not on an available item */
- TreeItem selectedItem = availableItems [index];
-
- /* if click was in expander box */
- if (selectedItem.items.length > 0 && selectedItem.getExpanderBounds ().contains (event.x, event.y)) {
- if (event.button != 1) return;
- boolean expand = !selectedItem.expanded;
- selectedItem.setExpanded (expand);
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- if (expand) {
- inExpand = true;
- sendEvent (SWT.Expand, newEvent);
- inExpand = false;
- if (isDisposed ()) return;
- if (selectedItem.items.length == 0) {
- selectedItem.expanded = false;
- }
- } else {
- sendEvent (SWT.Collapse, newEvent);
- }
- return;
- }
- /* if click was in checkbox */
- if ((style & SWT.CHECK) != 0 && selectedItem.getCheckboxBounds ().contains (event.x, event.y)) {
- if (event.button != 1) return;
- selectedItem.setChecked (!selectedItem.checked);
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- newEvent.detail = SWT.CHECK;
- postEvent (SWT.Selection, newEvent);
- return;
- }
-
- if (!selectedItem.getHitBounds ().contains (event.x, event.y)) return;
-
- if ((event.stateMask & SWT.SHIFT) == 0 && event.keyCode != SWT.SHIFT) anchorItem = null;
-
- boolean sendSelection = true;
- /* Detect when this is the second click of a DefaultSelection and don't fire Selection */
- if (lastSelectionEvent != null && lastSelectionEvent.item == selectedItem) {
- if (event.time - lastSelectionEvent.time <= display.getDoubleClickTime ()) {
- sendSelection = false;
- } else {
- lastSelectionEvent = event;
- event.item = selectedItem;
- }
- } else {
- lastSelectionEvent = event;
- event.item = selectedItem;
- }
-
- if ((style & SWT.SINGLE) != 0) {
- if (!selectedItem.isSelected ()) {
- if (event.button == 1) {
- selectItem (selectedItem, false);
- setFocusItem (selectedItem, true);
- redrawItem (selectedItem.availableIndex, true);
- if (sendSelection) {
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
- }
- return;
- }
- if ((event.stateMask & (SWT.CTRL | SWT.SHIFT)) == 0) {
- selectItem (selectedItem, false);
- setFocusItem (selectedItem, true);
- redrawItem (selectedItem.availableIndex, true);
- if (sendSelection) {
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
- }
- return;
- }
- }
- /* item is selected */
- if (event.button == 1) {
- /* fire a selection event, though the selection did not change */
- if (sendSelection) {
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
- }
- return;
- }
- }
- /* SWT.MULTI */
- if (!selectedItem.isSelected ()) {
- if (event.button == 1) {
- if ((event.stateMask & (SWT.CTRL | SWT.SHIFT)) == SWT.SHIFT) {
- if (anchorItem == null) anchorItem = focusItem;
- int anchorIndex = anchorItem.availableIndex;
- int selectIndex = selectedItem.availableIndex;
- TreeItem[] newSelection = new TreeItem [Math.abs (anchorIndex - selectIndex) + 1];
- int step = anchorIndex < selectIndex ? 1 : -1;
- int writeIndex = 0;
- for (int i = anchorIndex; i != selectIndex; i += step) {
- newSelection [writeIndex++] = availableItems [i];
- }
- newSelection [writeIndex] = availableItems [selectIndex];
- setSelection (newSelection, false);
- setFocusItem (selectedItem, true);
- redrawItems (
- Math.min (anchorIndex, selectIndex),
- Math.max (anchorIndex, selectIndex),
- true);
- if (sendSelection) {
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
- }
- return;
- }
- selectItem (selectedItem, (event.stateMask & SWT.CTRL) != 0);
- setFocusItem (selectedItem, true);
- redrawItem (selectedItem.availableIndex, true);
- if (sendSelection) {
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
- }
- return;
- }
- /* button 3 */
- if ((event.stateMask & (SWT.CTRL | SWT.SHIFT)) == 0) {
- selectItem (selectedItem, false);
- setFocusItem (selectedItem, true);
- redrawItem (selectedItem.availableIndex, true);
- if (sendSelection) {
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
- }
- return;
- }
- }
- /* item is selected */
- if (event.button != 1) return;
- if ((event.stateMask & SWT.CTRL) != 0) {
- removeSelectedItem (getSelectionIndex (selectedItem));
- setFocusItem (selectedItem, true);
- redrawItem (selectedItem.availableIndex, true);
- if (sendSelection) {
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
- }
- return;
- }
- if ((event.stateMask & SWT.SHIFT) != 0) {
- if (anchorItem == null) anchorItem = focusItem;
- int anchorIndex = anchorItem.availableIndex;
- int selectIndex = selectedItem.availableIndex;
- TreeItem[] newSelection = new TreeItem [Math.abs (anchorIndex - selectIndex) + 1];
- int step = anchorIndex < selectIndex ? 1 : -1;
- int writeIndex = 0;
- for (int i = anchorIndex; i != selectIndex; i += step) {
- newSelection [writeIndex++] = availableItems [i];
- }
- newSelection [writeIndex] = availableItems [selectIndex];
- setSelection (newSelection, false);
- setFocusItem (selectedItem, true);
- redrawItems (
- Math.min (anchorIndex, selectIndex),
- Math.max (anchorIndex, selectIndex),
- true);
- if (sendSelection) {
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
- }
- return;
- }
- selectItem (selectedItem, false);
- setFocusItem (selectedItem, true);
- redrawItem (selectedItem.availableIndex, true);
- if (sendSelection) {
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
- }
-}
-void onMouseUp (Event event) {
- int index = (event.y - getHeaderHeight ()) / itemHeight + topIndex;
- if (!(0 <= index && index < availableItemsCount)) return; /* not on an available item */
- lastClickedItem = availableItems [index];
-}
-void onPageDown (int stateMask) {
- int visibleItemCount = (clientArea.height - getHeaderHeight ()) / itemHeight;
- if ((stateMask & (SWT.CTRL | SWT.SHIFT)) == 0) {
- /* PageDown with no modifiers */
- int newFocusIndex = focusItem.availableIndex + visibleItemCount - 1;
- newFocusIndex = Math.min (newFocusIndex, availableItemsCount - 1);
- if (newFocusIndex == focusItem.availableIndex) return;
- TreeItem item = availableItems [newFocusIndex];
- selectItem (item, false);
- setFocusItem (item, true);
- showItem (item);
- redrawItem (item.availableIndex, true);
- return;
- }
- if ((stateMask & (SWT.CTRL | SWT.SHIFT)) == (SWT.CTRL | SWT.SHIFT)) {
- /* CTRL+Shift+PageDown */
- int newTopIndex = topIndex + visibleItemCount;
- newTopIndex = Math.min (newTopIndex, availableItemsCount - visibleItemCount);
- if (newTopIndex == topIndex) return;
- setTopItem (availableItems [newTopIndex]);
- return;
- }
- if ((style & SWT.SINGLE) != 0) {
- if ((stateMask & SWT.SHIFT) != 0) {
- /* Shift+PageDown */
- int newFocusIndex = focusItem.availableIndex + visibleItemCount - 1;
- newFocusIndex = Math.min (newFocusIndex, availableItemsCount - 1);
- if (newFocusIndex == focusItem.availableIndex) return;
- TreeItem item = availableItems [newFocusIndex];
- selectItem (item, false);
- setFocusItem (item, true);
- showItem (item);
- redrawItem (item.availableIndex, true);
- return;
- }
- /* CTRL+PageDown */
- int newTopIndex = topIndex + visibleItemCount;
- newTopIndex = Math.min (newTopIndex, availableItemsCount - visibleItemCount);
- if (newTopIndex == topIndex) return;
- setTopItem (availableItems [newTopIndex]);
- return;
- }
- /* SWT.MULTI */
- if ((stateMask & SWT.CTRL) != 0) {
- /* CTRL+PageDown */
- int bottomIndex = Math.min (topIndex + visibleItemCount - 1, availableItemsCount - 1);
- if (focusItem.availableIndex != bottomIndex) {
- /* move focus to bottom item in viewport */
- setFocusItem (availableItems [bottomIndex], true);
- redrawItem (bottomIndex, true);
- } else {
- /* at bottom of viewport, so set focus to bottom item one page down */
- int newFocusIndex = Math.min (availableItemsCount - 1, bottomIndex + visibleItemCount);
- if (newFocusIndex == focusItem.availableIndex) return;
- setFocusItem (availableItems [newFocusIndex], true);
- showItem (availableItems [newFocusIndex]);
- redrawItem (newFocusIndex, true);
- }
- return;
- }
- /* Shift+PageDown */
- if (anchorItem == null) anchorItem = focusItem;
- int anchorIndex = anchorItem.availableIndex;
- int bottomIndex = Math.min (topIndex + visibleItemCount - 1, availableItemsCount - 1);
- int selectIndex;
- if (focusItem.availableIndex != bottomIndex) {
- /* select from focus to bottom item in viewport */
- selectIndex = bottomIndex;
- } else {
- /* already at bottom of viewport, so select to bottom of one page down */
- selectIndex = Math.min (availableItemsCount - 1, bottomIndex + visibleItemCount);
- if (selectIndex == focusItem.availableIndex && focusItem.isSelected ()) return;
- }
- TreeItem selectedItem = availableItems [selectIndex];
- TreeItem[] newSelection = new TreeItem [Math.abs (anchorIndex - selectIndex) + 1];
- int step = anchorIndex < selectIndex ? 1 : -1;
- int writeIndex = 0;
- for (int i = anchorIndex; i != selectIndex; i += step) {
- newSelection [writeIndex++] = availableItems [i];
- }
- newSelection [writeIndex] = availableItems [selectIndex];
- setSelection (newSelection, false);
- setFocusItem (selectedItem, true);
- showItem (selectedItem);
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
-}
-void onPageUp (int stateMask) {
- int visibleItemCount = (clientArea.height - getHeaderHeight ()) / itemHeight;
- if ((stateMask & (SWT.CTRL | SWT.SHIFT)) == 0) {
- /* PageUp with no modifiers */
- int newFocusIndex = Math.max (0, focusItem.availableIndex - visibleItemCount + 1);
- if (newFocusIndex == focusItem.availableIndex) return;
- TreeItem item = availableItems [newFocusIndex];
- selectItem (item, false);
- setFocusItem (item, true);
- showItem (item);
- redrawItem (item.availableIndex, true);
- return;
- }
- if ((stateMask & (SWT.CTRL | SWT.SHIFT)) == (SWT.CTRL | SWT.SHIFT)) {
- /* CTRL+Shift+PageUp */
- int newTopIndex = Math.max (0, topIndex - visibleItemCount);
- if (newTopIndex == topIndex) return;
- setTopItem (availableItems [newTopIndex]);
- return;
- }
- if ((style & SWT.SINGLE) != 0) {
- if ((stateMask & SWT.SHIFT) != 0) {
- /* Shift+PageUp */
- int newFocusIndex = Math.max (0, focusItem.availableIndex - visibleItemCount + 1);
- if (newFocusIndex == focusItem.availableIndex) return;
- TreeItem item = availableItems [newFocusIndex];
- selectItem (item, false);
- setFocusItem (item, true);
- showItem (item);
- redrawItem (item.availableIndex, true);
- return;
- }
- /* CTRL+PageUp */
- int newTopIndex = Math.max (0, topIndex - visibleItemCount);
- if (newTopIndex == topIndex) return;
- setTopItem (availableItems [newTopIndex]);
- return;
- }
- /* SWT.MULTI */
- if ((stateMask & SWT.CTRL) != 0) {
- /* CTRL+PageUp */
- if (focusItem.availableIndex != topIndex) {
- /* move focus to top item in viewport */
- setFocusItem (availableItems [topIndex], true);
- redrawItem (topIndex, true);
- } else {
- /* at top of viewport, so set focus to top item one page up */
- int newFocusIndex = Math.max (0, focusItem.availableIndex - visibleItemCount);
- if (newFocusIndex == focusItem.availableIndex) return;
- setFocusItem (availableItems [newFocusIndex], true);
- showItem (availableItems [newFocusIndex]);
- redrawItem (newFocusIndex, true);
- }
- return;
- }
- /* Shift+PageUp */
- if (anchorItem == null) anchorItem = focusItem;
- int anchorIndex = anchorItem.availableIndex;
- int selectIndex;
- if (focusItem.availableIndex != topIndex) {
- /* select from focus to top item in viewport */
- selectIndex = topIndex;
- } else {
- /* already at top of viewport, so select to top of one page up */
- selectIndex = Math.max (0, topIndex - visibleItemCount);
- if (selectIndex == focusItem.availableIndex && focusItem.isSelected ()) return;
- }
- TreeItem selectedItem = availableItems [selectIndex];
- TreeItem[] newSelection = new TreeItem [Math.abs (anchorIndex - selectIndex) + 1];
- int step = anchorIndex < selectIndex ? 1 : -1;
- int writeIndex = 0;
- for (int i = anchorIndex; i != selectIndex; i += step) {
- newSelection [writeIndex++] = availableItems [i];
- }
- newSelection [writeIndex] = availableItems [selectIndex];
- setSelection (newSelection, false);
- setFocusItem (selectedItem, true);
- showItem (selectedItem);
- Event newEvent = new Event ();
- newEvent.item = selectedItem;
- postEvent (SWT.Selection, newEvent);
-}
-void onPaint (Event event) {
- TreeColumn[] orderedColumns = getOrderedColumns ();
- GC gc = event.gc;
- Rectangle clipping = gc.getClipping ();
- int headerHeight = getHeaderHeight ();
- int numColumns = orderedColumns.length;
- int startColumn = -1, endColumn = -1;
- if (numColumns > 0) {
- startColumn = computeColumnIntersect (clipping.x, 0);
- if (startColumn != -1) { /* the clip x is within a column's bounds */
- endColumn = computeColumnIntersect (clipping.x + clipping.width, startColumn);
- if (endColumn == -1) endColumn = numColumns - 1;
- }
- } else {
- startColumn = endColumn = 0;
- }
-
- /* Determine the items to be painted */
- int startIndex = (clipping.y - headerHeight) / itemHeight + topIndex;
- int endIndex = -1;
- if (startIndex < availableItemsCount) {
- endIndex = startIndex + Compatibility.ceil (clipping.height, itemHeight);
- }
- startIndex = Math.max (0, startIndex);
- endIndex = Math.min (endIndex, availableItemsCount - 1);
-
- /* fill background not handled by items */
- gc.setBackground (getBackground ());
- gc.setClipping (clipping);
- int bottomY = endIndex >= 0 ? getItemY (availableItems [endIndex]) + itemHeight : 0;
- int fillHeight = Math.max (0, clientArea.height - bottomY);
- if (fillHeight > 0) { /* space below bottom item */
- drawBackground (gc, 0, bottomY, clientArea.width, fillHeight);
- }
- if (columns.length > 0) {
- TreeColumn column = orderedColumns [orderedColumns.length - 1]; /* last column */
- int rightX = column.getX () + column.width;
- if (rightX < clientArea.width) {
- drawBackground (gc, rightX, 0, clientArea.width - rightX, clientArea.height - fillHeight);
- }
- }
-
- /* paint the items */
- boolean noFocusDraw = false;
- int[] lineDash = gc.getLineDash ();
- int lineWidth = gc.getLineWidth ();
- for (int i = startIndex; i <= Math.min (endIndex, availableItemsCount - 1); i++) {
- TreeItem item = availableItems [i];
- if (!item.isDisposed ()) { /* ensure that item was not disposed in a callback */
- if (startColumn == -1) {
- /* indicates that region to paint is to the right of the last column */
- noFocusDraw = item.paint (gc, null, true) || noFocusDraw;
- } else {
- if (numColumns == 0) {
- noFocusDraw = item.paint (gc, null, false) || noFocusDraw;
- } else {
- for (int j = startColumn; j <= Math.min (endColumn, columns.length - 1); j++) {
- if (!item.isDisposed ()) { /* ensure that item was not disposed in a callback */
- noFocusDraw = item.paint (gc, orderedColumns [j], false) || noFocusDraw;
- }
- if (isDisposed () || gc.isDisposed ()) return; /* ensure that receiver was not disposed in a callback */
- }
- }
- }
- }
- if (isDisposed () || gc.isDisposed ()) return; /* ensure that receiver was not disposed in a callback */
- }
-
- /* repaint grid lines */
- gc.setClipping(clipping);
- gc.setLineWidth (lineWidth);
- if (linesVisible) {
- gc.setForeground (display.getSystemColor (SWT.COLOR_WIDGET_LIGHT_SHADOW));
- gc.setLineDash (lineDash);
- if (numColumns > 0 && startColumn != -1) {
- /* vertical column lines */
- for (int i = startColumn; i <= endColumn; i++) {
- int x = orderedColumns [i].getX () + orderedColumns [i].width - 1;
- gc.drawLine (x, clipping.y, x, clipping.y + clipping.height);
- }
- }
- /* horizontal item lines */
- bottomY = clipping.y + clipping.height;
- int rightX = clipping.x + clipping.width;
- int y = (clipping.y - headerHeight) / itemHeight * itemHeight + headerHeight;
- while (y <= bottomY) {
- gc.drawLine (clipping.x, y, rightX, y);
- y += itemHeight;
- }
- }
-
- /* draw focus rectangle */
- if (!noFocusDraw && isFocusControl ()) {
- if (focusItem != null) {
- Rectangle focusBounds = focusItem.getFocusBounds ();
- if (focusBounds.width > 0) {
- gc.setForeground (display.getSystemColor (SWT.COLOR_BLACK));
- gc.setClipping (focusBounds);
- if (focusItem.isSelected ()) {
- gc.setLineDash (new int[] {2, 2});
- } else {
- gc.setLineDash (new int[] {1, 1});
- }
- gc.drawFocus (focusBounds.x, focusBounds.y, focusBounds.width, focusBounds.height);
- }
- } else {
- /* no items, so draw focus border around Tree */
- int y = headerHeight + 1;
- int width = Math.max (0, clientArea.width - 2);
- int height = Math.max (0, clientArea.height - headerHeight - 2);
- gc.setForeground (display.getSystemColor (SWT.COLOR_BLACK));
- gc.setClipping (1, y, width, height);
- gc.setLineDash (new int[] {1, 1});
- gc.drawFocus (1, y, width, height);
- }
- }
-
- /* draw insert mark */
- if (insertMarkItem != null) {
- Rectangle focusBounds = insertMarkItem.getFocusBounds ();
- gc.setForeground (display.getSystemColor (SWT.COLOR_BLACK));
- gc.setClipping (focusBounds);
- gc.setLineDash (lineDash);
- if (insertMarkPrecedes) {
- gc.drawLine (focusBounds.x, focusBounds.y, focusBounds.x + focusBounds.width, focusBounds.y);
- } else {
- int y = focusBounds.y + focusBounds.height - 1;
- gc.drawLine (focusBounds.x, y, focusBounds.x + focusBounds.width, y);
- }
- }
-}
-void onResize (Event event) {
- clientArea = getClientArea ();
- /* vertical scrollbar */
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) {
- int clientHeight = (clientArea.height - getHeaderHeight ()) / itemHeight;
- int thumb = Math.min (clientHeight, availableItemsCount);
- vBar.setThumb (thumb);
- vBar.setPageIncrement (thumb);
- int index = vBar.getSelection ();
- if (index != topIndex) {
- topIndex = index;
- redraw ();
- }
- boolean visible = clientHeight < availableItemsCount;
- if (visible != vBar.getVisible ()) {
- vBar.setVisible (visible);
- clientArea = getClientArea ();
- }
- }
-
- /* horizontal scrollbar */
- ScrollBar hBar = getHorizontalBar ();
- if (hBar != null) {
- int hBarMaximum = hBar.getMaximum ();
- int thumb = Math.min (clientArea.width, hBarMaximum);
- hBar.setThumb (thumb);
- hBar.setPageIncrement (thumb);
- horizontalOffset = hBar.getSelection ();
- boolean visible = clientArea.width < hBarMaximum;
- if (visible != hBar.getVisible ()) {
- hBar.setVisible (visible);
- clientArea = getClientArea ();
- }
- }
-
- /* header */
- int headerHeight = Math.max (fontHeight, headerImageHeight) + 2 * getHeaderPadding ();
- header.setSize (clientArea.width, headerHeight);
-
- /* if this is the focus control but there are no items then the boundary focus ring must be repainted */
- if (availableItemsCount == 0 && isFocusControl ()) redraw ();
-}
-void onScrollHorizontal (Event event) {
- ScrollBar hBar = getHorizontalBar ();
- if (hBar == null) return;
- int newSelection = hBar.getSelection ();
- update ();
- if (availableItemsCount > 0) {
- GC gc = new GC (this);
- gc.copyArea (
- 0, 0,
- clientArea.width, clientArea.height,
- horizontalOffset - newSelection, 0);
- gc.dispose ();
- } else {
- redraw (); /* ensure that static focus rectangle updates properly */
- }
- if (drawCount <= 0 && header.isVisible ()) {
- header.update ();
- Rectangle headerClientArea = header.getClientArea ();
- GC gc = new GC (header);
- gc.copyArea (
- 0, 0,
- headerClientArea.width, headerClientArea.height,
- horizontalOffset - newSelection, 0);
- gc.dispose ();
- }
- horizontalOffset = newSelection;
-}
-void onScrollVertical (Event event) {
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) {
- int newSelection = vBar.getSelection ();
- update ();
- GC gc = new GC (this);
- gc.copyArea (
- 0, 0,
- clientArea.width, clientArea.height,
- 0, (topIndex - newSelection) * itemHeight);
- gc.dispose ();
- topIndex = newSelection;
- }
-}
-void onSpace () {
- if (focusItem == null) return;
- if (!focusItem.isSelected ()) {
- selectItem (focusItem, (style & SWT.MULTI) != 0);
- redrawItem (focusItem.availableIndex, true);
- }
- if ((style & SWT.CHECK) != 0) {
- focusItem.setChecked (!focusItem.checked);
- }
- showItem (focusItem);
- Event event = new Event ();
- event.item = focusItem;
- postEvent (SWT.Selection, event);
- if ((style & SWT.CHECK) == 0) return;
-
- /* SWT.CHECK */
- event = new Event ();
- event.item = focusItem;
- event.detail = SWT.CHECK;
- postEvent (SWT.Selection, event);
-}
-/*
- * The current focus item is about to become unavailable, so reassign focus.
- */
-void reassignFocus () {
- if (focusItem == null) return;
-
- /* reassign to current focus' parent item if it has one */
- if (focusItem.parentItem != null) {
- TreeItem item = focusItem.parentItem;
- setFocusItem (item, false);
- showItem (item);
- return;
- }
-
- /*
- * reassign to the previous root-level item if there is one, or the next
- * root-level item otherwise
- */
- int index = focusItem.getIndex ();
- if (index != 0) {
- index--;
- } else {
- index++;
- }
- if (index < items.length) {
- TreeItem item = items [index];
- setFocusItem (item, false);
- showItem (item);
- } else {
- setFocusItem (null, false); /* no items left */
- }
-}
-public void redraw () {
- checkWidget ();
- if (drawCount <= 0) super.redraw ();
-}
-public void redraw (int x, int y, int width, int height, boolean all) {
- checkWidget ();
- if (drawCount <= 0) super.redraw (x, y, width, height, all);
-}
-/*
- * Redraws from the specified index down to the last available item inclusive. Note
- * that the redraw bounds do not extend beyond the current last item, so clients
- * that reduce the number of available items should use #redrawItems(int,int) instead
- * to ensure that redrawing extends down to the previous bottom item boundary.
- */
-void redrawFromItemDownwards (int index) {
- redrawItems (index, availableItemsCount - 1, false);
-}
-/*
- * Redraws the tree item at the specified index. It is valid for this index to reside
- * beyond the last available item.
- */
-void redrawItem (int itemIndex, boolean focusBoundsOnly) {
- if (itemIndex == -1) return;
- if (itemIndex < availableItemsCount && !availableItems [itemIndex].isInViewport ()) return;
- redrawItems (itemIndex, itemIndex, focusBoundsOnly);
-}
-/*
- * Redraws the tree between the start and end item indices inclusive. It is valid
- * for the end index value to extend beyond the last available item.
- */
-void redrawItems (int startIndex, int endIndex, boolean focusBoundsOnly) {
- if (drawCount > 0) return;
-
- int startY = (startIndex - topIndex) * itemHeight + getHeaderHeight ();
- int height = (endIndex - startIndex + 1) * itemHeight;
- if (focusBoundsOnly) {
- boolean custom = hooks (SWT.EraseItem) || hooks (SWT.PaintItem);
- if (!custom && columns.length > 0) {
- TreeColumn lastColumn;
- if ((style & SWT.FULL_SELECTION) != 0) {
- TreeColumn[] orderedColumns = getOrderedColumns ();
- lastColumn = orderedColumns [orderedColumns.length - 1];
- } else {
- lastColumn = columns [0];
- }
- int rightX = lastColumn.getX () + lastColumn.getWidth ();
- if (rightX <= 0) return; /* focus column(s) not visible */
- }
- endIndex = Math.min (endIndex, availableItemsCount - 1);
- for (int i = startIndex; i <= endIndex; i++) {
- TreeItem item = availableItems [i];
- if (item.isInViewport ()) {
- /* if custom painting is being done then repaint the full item */
- if (custom) {
- redraw (0, getItemY (item), clientArea.width, itemHeight, false);
- } else {
- /* repaint the item's focus bounds */
- Rectangle bounds = item.getFocusBounds ();
- redraw (bounds.x, startY, bounds.width, height, false);
- }
- }
- }
- } else {
- redraw (0, startY, clientArea.width, height, false);
- }
-}
-/**
- * Removes all of the items from the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget ();
- if (items.length == 0) return;
- setRedraw (false);
-
- setFocusItem (null, false);
- for (int i = 0; i < items.length; i++) {
- items [i].dispose (false);
- }
- items = availableItems = selectedItems = NO_ITEMS;
- availableItemsCount = topIndex = 0;
- anchorItem = lastClickedItem = insertMarkItem = null;
- lastSelectionEvent = null;
- inExpand = false;
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) {
- vBar.setMaximum (1);
- vBar.setVisible (false);
- }
- if (columns.length == 0) {
- horizontalOffset = 0;
- ScrollBar hBar = getHorizontalBar ();
- if (hBar != null) {
- hBar.setMaximum (1);
- hBar.setVisible (false);
- }
- }
-
- setRedraw (true);
-}
-String removeMnemonics (String string) {
- /* removes single ampersands and preserves double-ampersands */
- char [] chars = new char [string.length ()];
- string.getChars (0, chars.length, chars, 0);
- int i = 0, j = 0;
- for ( ; i < chars.length; i++, j++) {
- if (chars[i] == '&') {
- if (++i == chars.length) break;
- if (chars[i] == '&') {
- chars[j++] = chars[i - 1];
- }
- }
- chars[j] = chars[i];
- }
- if (i == j) return string;
- return new String (chars, 0, j);
-}
-void removeSelectedItem (int index) {
- TreeItem[] newSelectedItems = new TreeItem [selectedItems.length - 1];
- System.arraycopy (selectedItems, 0, newSelectedItems, 0, index);
- System.arraycopy (selectedItems, index + 1, newSelectedItems, index, newSelectedItems.length - index);
- selectedItems = newSelectedItems;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- removeListener (SWT.Selection, listener);
- removeListener (SWT.DefaultSelection, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when items in the receiver are expanded or collapsed.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TreeListener
- * @see #addTreeListener
- */
-public void removeTreeListener (TreeListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- removeListener (SWT.Expand, listener);
- removeListener (SWT.Collapse, listener);
-}
-/**
- * Selects an item in the receiver. If the item was already
- * selected, it remains selected.
- *
- * @param item the item to be selected
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void select (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- selectItem (item, (style & SWT.MULTI) != 0);
- redrawItem (item.availableIndex, true);
-}
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- selectedItems = new TreeItem [availableItemsCount];
- System.arraycopy (availableItems, 0, selectedItems, 0, availableItemsCount);
- redraw ();
-}
-void selectItem (TreeItem item, boolean addToSelection) {
- TreeItem[] oldSelectedItems = selectedItems;
- if (!addToSelection || (style & SWT.SINGLE) != 0) {
- selectedItems = new TreeItem[] {item};
- for (int i = 0; i < oldSelectedItems.length; i++) {
- if (oldSelectedItems [i] != item) {
- redrawItem (oldSelectedItems [i].availableIndex, true);
- }
- }
- } else {
- if (item.isSelected ()) return;
- selectedItems = new TreeItem [selectedItems.length + 1];
- System.arraycopy (oldSelectedItems, 0, selectedItems, 0, oldSelectedItems.length);
- selectedItems [selectedItems.length - 1] = item;
- }
-}
-public void setBackground (Color color) {
- checkWidget ();
- if (color == null) color = display.getSystemColor (SWT.COLOR_LIST_BACKGROUND);
- super.setBackground (color);
-}
-/**
- * Sets the order that the items in the receiver should
- * be displayed in to the given argument which is described
- * in terms of the zero-relative ordering of when the items
- * were added.
- *
- * @param order the new order to display the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item order is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
-public void setColumnOrder (int [] order) {
- checkWidget ();
- if (order == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (columns.length == 0) {
- if (order.length != 0) error (SWT.ERROR_INVALID_ARGUMENT);
- return;
- }
- if (order.length != columns.length) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean reorder = false;
- boolean [] seen = new boolean [columns.length];
- int[] oldOrder = getColumnOrder ();
- for (int i = 0; i < order.length; i++) {
- int index = order [i];
- if (index < 0 || index >= columns.length) error (SWT.ERROR_INVALID_RANGE);
- if (seen [index]) error (SWT.ERROR_INVALID_ARGUMENT);
- seen [index] = true;
- if (index != oldOrder [i]) reorder = true;
- }
- if (!reorder) return;
-
- headerHideToolTip ();
- int[] oldX = new int [columns.length];
- for (int i = 0; i < columns.length; i++) {
- oldX [i] = columns [i].getX ();
- }
- orderedColumns = new TreeColumn [order.length];
- for (int i = 0; i < order.length; i++) {
- orderedColumns [i] = columns [order [i]];
- }
- /*
- * If the first ordered column has changed then the old and new ordered column 0's
- * have to recompute their display texts since they will now have just gained/lost
- * space as a result of the hierarchy decorations that appear in ordered column 0.
- */
- if (oldOrder [0] != order [0]) {
- orderedCol0imageWidth = columns [order [0]].itemImageWidth;
- GC gc = new GC (this);
- for (int i = 0; i < items.length; i++) {
- items [i].updateColumnWidth (columns [oldOrder [0]], gc);
- items [i].updateColumnWidth (columns [order [0]], gc);
- }
- gc.dispose();
- }
- for (int i = 0; i < orderedColumns.length; i++) {
- TreeColumn column = orderedColumns [i];
- if (!column.isDisposed () && column.getX () != oldX [column.getIndex ()]) {
- column.sendEvent (SWT.Move);
- }
- }
-
- redraw ();
- if (drawCount <= 0 && header.isVisible ()) header.redraw ();
-}
-void setFocusItem (TreeItem item, boolean redrawOldFocus) {
- if (item == focusItem) return;
- TreeItem oldFocusItem = focusItem;
- focusItem = item;
- if (redrawOldFocus && oldFocusItem != null) {
- redrawItem (oldFocusItem.availableIndex, true);
- }
-}
-public void setFont (Font value) {
- checkWidget ();
- Font oldFont = getFont ();
- super.setFont (value);
- Font font = getFont ();
- if (font.equals (oldFont)) return;
-
- GC gc = new GC (this);
-
- /* recompute the receiver's cached font height and item height values */
- fontHeight = gc.getFontMetrics ().getHeight ();
- setItemHeight (Math.max (fontHeight, imageHeight) + 2 * getCellPadding ());
- Point headerSize = header.getSize ();
- int newHeaderHeight = Math.max (fontHeight, headerImageHeight) + 2 * getHeaderPadding ();
- if (headerSize.y != newHeaderHeight) {
- header.setSize (headerSize.x, newHeaderHeight);
- }
- header.setFont (font);
-
- /*
- * Notify all columns and items of the font change so that elements that
- * use the receiver's font can recompute their cached string widths.
- */
- for (int i = 0; i < columns.length; i++) {
- columns [i].updateFont (gc);
- }
- for (int i = 0; i < items.length; i++) {
- items [i].updateFont (gc);
- }
-
- gc.dispose ();
-
- if (drawCount <= 0 && header.isVisible ()) header.redraw ();
-
- /* update scrollbars */
- if (columns.length == 0) updateHorizontalBar ();
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) {
- int thumb = (clientArea.height - getHeaderHeight ()) / itemHeight;
- if (vBar.getThumb () != thumb) {
- vBar.setThumb (thumb);
- vBar.setPageIncrement (thumb);
- }
- topIndex = vBar.getSelection ();
- vBar.setVisible (thumb < vBar.getMaximum ());
- }
- redraw ();
-}
-public void setForeground (Color color) {
- checkWidget ();
- if (color == null) color = display.getSystemColor (SWT.COLOR_LIST_FOREGROUND);
- super.setForeground (color);
-}
-void setHeaderImageHeight (int value) {
- headerImageHeight = value;
- Point headerSize = header.getSize ();
- int newHeaderHeight = Math.max (fontHeight, headerImageHeight) + 2 * getHeaderPadding ();
- if (headerSize.y != newHeaderHeight) {
- header.setSize (headerSize.x, newHeaderHeight);
- }
-}
-/**
- * Marks the receiver's header as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setHeaderVisible (boolean value) {
- checkWidget ();
- if (header.getVisible () == value) return; /* no change */
- headerHideToolTip ();
- header.setVisible (value);
- updateVerticalBar ();
- redraw ();
-}
-void setImageHeight (int value) {
- imageHeight = value;
- setItemHeight (Math.max (fontHeight, imageHeight) + 2 * getCellPadding ());
-}
-/**
- * Display a mark indicating the point at which an item will be inserted.
- * The drop insert item has a visual hint to show where a dragged item
- * will be inserted when dropped on the tree.
- *
- * @param item the insert item. Null will clear the insertion mark.
- * @param before true places the insert mark above 'item'. false places
- * the insert mark below 'item'.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setInsertMark (TreeItem item, boolean before) {
- checkWidget ();
- if (item != null && item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (item != null && item.parent != this) return;
- if (item == insertMarkItem && before == insertMarkPrecedes) return; /* no change */
-
- TreeItem oldInsertItem = insertMarkItem;
- insertMarkItem = item;
- insertMarkPrecedes = before;
- if (oldInsertItem != null && oldInsertItem.availableIndex != -1) {
- redrawItem (oldInsertItem.availableIndex, true);
- }
- if (item != null && item != oldInsertItem && item.availableIndex != -1) {
- redrawItem (item.availableIndex, true);
- }
-}
-/**
- * Sets the number of root-level items contained in the receiver.
- *
- * @param count the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setItemCount (int count) {
- checkWidget ();
- count = Math.max (0, count);
- if (count == items.length) return;
- int oldCount = availableItemsCount;
- int redrawStart, redrawEnd;
-
- /* if the new item count is less than the current count then remove all excess items from the end */
- if (count < items.length) {
- redrawStart = count > 0 ? items [count - 1].availableIndex : 0;
- redrawEnd = availableItemsCount - 1;
- availableItemsCount = items [count].availableIndex;
- for (int i = count; i < items.length; i++) {
- items [i].dispose (false);
- }
- if (count == 0) {
- items = Tree.NO_ITEMS;
- } else {
- TreeItem[] newItems = new TreeItem [count];
- System.arraycopy (items, 0, newItems, 0, count);
- items = newItems;
- }
-
- int newSelectedCount = 0;
- for (int i = 0; i < selectedItems.length; i++) {
- if (!selectedItems [i].isDisposed ()) newSelectedCount++;
- }
- if (newSelectedCount != selectedItems.length) {
- /* one or more selected items have been disposed */
- TreeItem[] newSelectedItems = new TreeItem [newSelectedCount];
- int pos = 0;
- for (int i = 0; i < selectedItems.length; i++) {
- TreeItem item = selectedItems [i];
- if (!item.isDisposed ()) {
- newSelectedItems [pos++] = item;
- }
- }
- selectedItems = newSelectedItems;
- }
-
- if (insertMarkItem != null && insertMarkItem.isDisposed ()) insertMarkItem = null;
- if (lastClickedItem != null && lastClickedItem.isDisposed ()) lastClickedItem = null;
- if (anchorItem != null && anchorItem.isDisposed ()) anchorItem = null;
- if (focusItem != null && focusItem.isDisposed ()) {
- TreeItem newFocusItem = count > 0 ? items [count - 1] : null;
- setFocusItem (newFocusItem, false);
- }
- if (columns.length == 0) updateHorizontalBar ();
- } else {
- int grow = count - items.length;
- redrawStart = items.length == 0 ? 0 : items [items.length - 1].availableIndex;
- redrawEnd = availableItemsCount + grow - 1;
- TreeItem[] newItems = new TreeItem [count];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- if (availableItems.length < availableItemsCount + grow) {
- TreeItem[] newAvailableItems = new TreeItem [availableItemsCount + grow];
- System.arraycopy (availableItems, 0, newAvailableItems, 0, availableItemsCount);
- availableItems = newAvailableItems;
- }
- for (int i = items.length - grow; i < count; i++) {
- TreeItem newItem = new TreeItem (this, SWT.NONE, i, false);
- items [i] = newItem;
- items [i].availableIndex = availableItemsCount;
- availableItems [availableItemsCount++] = newItem;
- }
- if (oldCount == 0) focusItem = availableItems [0];
- }
-
- updateVerticalBar ();
- /*
- * If this is the focus control and the available item count is going from 0->!0 or !0->0
- * then the receiver must be redrawn to ensure that its boundary focus ring is updated.
- */
- if ((oldCount == 0 || availableItemsCount == 0) && isFocusControl ()) {
- redraw ();
- return;
- }
- redrawItems (redrawStart, redrawEnd, false);
-}
-boolean setItemHeight (int value) {
- boolean update = !customHeightSet || itemHeight < value;
- if (update) itemHeight = value;
- return update;
-}
-/**
- * Marks the receiver's lines as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise. Note that some platforms draw
- * grid lines while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLinesVisible (boolean value) {
- checkWidget ();
- if (linesVisible == value) return; /* no change */
- linesVisible = value;
- redraw ();
-}
-public void setMenu (Menu menu) {
- super.setMenu (menu);
- header.setMenu (menu);
-}
-public void setRedraw (boolean value) {
- checkWidget();
- if (value) {
- if (--drawCount == 0) {
- if (availableItems.length - availableItemsCount > 3) {
- TreeItem[] newAvailableItems = new TreeItem [availableItemsCount];
- System.arraycopy (availableItems, 0, newAvailableItems, 0, availableItemsCount);
- availableItems = newAvailableItems;
- }
- updateVerticalBar ();
- updateHorizontalBar ();
- }
- } else {
- drawCount++;
- }
- super.setRedraw (value);
- header.setRedraw (value);
-}
-/**
- * Sets the receiver's selection to the given item.
- * The current selection is cleared before the new item is selected.
- * <p>
- * If the item is not in the receiver, then it is ignored.
- * </p>
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (new TreeItem [] {item}, true);
-}
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- * </p>
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the items has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#deselectAll()
- */
-public void setSelection (TreeItem[] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (items, true);
-}
-
-void setSelection (TreeItem[] items, boolean updateViewport) {
- if (items.length == 0 || ((style & SWT.SINGLE) != 0 && items.length > 1)) {
- deselectAll ();
- return;
- }
- TreeItem[] oldSelection = selectedItems;
-
- /* remove null and duplicate items */
- int index = 0;
- selectedItems = new TreeItem [items.length]; /* initially assume all valid items */
- for (int i = 0; i < items.length; i++) {
- TreeItem item = items [i];
- if (item != null && item.parent == this && !item.isSelected ()) {
- selectedItems [index++] = item;
- }
- }
- if (index != items.length) {
- /* an invalid item was provided so resize the array accordingly */
- TreeItem[] temp = new TreeItem [index];
- System.arraycopy (selectedItems, 0, temp, 0, index);
- selectedItems = temp;
- }
- if (selectedItems.length == 0) { /* no valid items */
- deselectAll ();
- return;
- }
-
- for (int i = 0; i < oldSelection.length; i++) {
- if (!oldSelection [i].isSelected ()) {
- int availableIndex = oldSelection [i].availableIndex;
- if (availableIndex != -1) {
- redrawItem (availableIndex, true);
- }
- }
- }
- if (updateViewport) {
- showItem (selectedItems [0]);
- setFocusItem (selectedItems [0], true);
- }
- for (int i = 0; i < selectedItems.length; i++) {
- int availableIndex = selectedItems [i].availableIndex;
- if (availableIndex != -1) {
- redrawItem (availableIndex, true);
- }
- }
-}
-/**
- * Sets the column used by the sort indicator for the receiver. A null
- * value will clear the sort indicator. The current sort column is cleared
- * before the new column is set.
- *
- * @param column the column used by the sort indicator or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the column is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortColumn (TreeColumn column) {
- checkWidget ();
- if (column != null && column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (column == sortColumn) return;
- if (sortColumn != null && !sortColumn.isDisposed ()) {
- sortColumn.setSortDirection (SWT.NONE);
- }
- sortColumn = column;
- if (sortColumn != null) {
- sortColumn.setSortDirection (sortDirection);
- }
-}
-/**
- * Sets the direction of the sort indicator for the receiver. The value
- * can be one of <code>UP</code>, <code>DOWN</code> or <code>NONE</code>.
- *
- * @param direction the direction of the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortDirection (int direction) {
- checkWidget ();
- if (direction != SWT.UP && direction != SWT.DOWN && direction != SWT.NONE) return;
- sortDirection = direction;
- if (sortColumn == null || sortColumn.isDisposed ()) return;
- sortColumn.setSortDirection (sortDirection);
-}
-/**
- * Sets the item which is currently at the top of the receiver.
- * This item can change when items are expanded, collapsed, scrolled
- * or new items are added or removed.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getTopItem()
- *
- * @since 2.1
- */
-public void setTopItem (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (item.parent != this) return;
-
- /* item must be available */
- if (!item.isAvailable ()) item.parentItem.expandAncestors ();
-
- int visibleItemCount = (clientArea.height - getHeaderHeight ()) / itemHeight;
- if (availableItemsCount < visibleItemCount) return;
- int index = Math.min (item.availableIndex, availableItemsCount - visibleItemCount);
- if (topIndex == index) return;
-
- update ();
- int change = topIndex - index;
- topIndex = index;
- ScrollBar vBar = getVerticalBar ();
- if (vBar != null) vBar.setSelection (topIndex);
- if (drawCount <= 0) {
- GC gc = new GC (this);
- gc.copyArea (0, 0, clientArea.width, clientArea.height, 0, change * itemHeight);
- gc.dispose ();
- }
-}
-/**
- * Shows the column. If the column is already showing in the receiver,
- * this method simply returns. Otherwise, the columns are scrolled until
- * the column is visible.
- *
- * @param column the column to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void showColumn (TreeColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (column.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (column.parent != this) return;
-
- int x = column.getX ();
- int rightX = x + column.width;
- if (0 <= x && rightX <= clientArea.width) return; /* column is fully visible */
-
- headerHideToolTip ();
- int absX = 0; /* the X of the column irrespective of the horizontal scroll */
- TreeColumn[] orderedColumns = getOrderedColumns ();
- for (int i = 0; i < column.getOrderIndex (); i++) {
- absX += orderedColumns [i].width;
- }
- if (x < clientArea.x) { /* column is to left of viewport */
- horizontalOffset = absX;
- } else {
- horizontalOffset = absX + column.width - clientArea.width;
- }
- ScrollBar hBar = getHorizontalBar ();
- if (hBar != null) hBar.setSelection (horizontalOffset);
- redraw ();
- if (drawCount <= 0 && header.isVisible ()) header.redraw ();
-}
-/**
- * Shows the item. If the item is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled
- * and expanded until the item is visible.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#showSelection()
- */
-public void showItem (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (item.parent != this) return;
-
- /* item must be available */
- if (!item.isAvailable ()) item.parentItem.expandAncestors ();
-
- int index = item.availableIndex;
- int visibleItemCount = (clientArea.height - getHeaderHeight ()) / itemHeight;
- /* nothing to do if item is already in viewport */
- if (topIndex <= index && index < topIndex + visibleItemCount) return;
-
- if (index <= topIndex) {
- /* item is above current viewport, so show on top */
- setTopItem (item);
- } else {
- /* item is below current viewport, so show on bottom */
- visibleItemCount = Math.max (visibleItemCount, 1); /* item to show should be top item */
- setTopItem (availableItems [Math.min (index - visibleItemCount + 1, availableItemsCount - 1)]);
- }
-}
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#showItem(TreeItem)
- */
-public void showSelection () {
- checkWidget ();
- if (selectedItems.length == 0) return;
- showItem (selectedItems [0]);
-}
-void updateColumnWidth (TreeColumn column, int width) {
- headerHideToolTip ();
- int oldWidth = column.width;
- int columnX = column.getX ();
- int x = columnX + oldWidth - 1; /* -1 ensures that grid line is included */
-
- update ();
- GC gc = new GC (this);
- gc.copyArea (x, 0, clientArea.width - x, clientArea.height, columnX + width - 1, 0); /* dest x -1 offsets x's -1 above */
- if (width > oldWidth) {
- /* column width grew */
- int change = width - oldWidth + 1; /* +1 offsets x's -1 above */
- /* -1/+1 below ensure that right bound of selection redraws correctly in column */
- redraw (x - 1, 0, change + 1, clientArea.height, false);
- } else {
- int change = oldWidth - width + 1; /* +1 offsets x's -1 above */
- redraw (clientArea.width - change, 0, change, clientArea.height, false);
- }
- /* the focus box must be repainted because its stipple may become shifted as a result of its new width */
- if (focusItem != null) redrawItem (focusItem.availableIndex, true);
-
- GC headerGC = new GC (header);
- if (drawCount <= 0 && header.getVisible ()) {
- Rectangle headerBounds = header.getClientArea ();
- header.update ();
- x -= 1; /* -1 ensures that full header column separator is included */
- headerGC.copyArea (x, 0, headerBounds.width - x, headerBounds.height, columnX + width - 2, 0); /* dest x -2 offsets x's -1s above */
- if (width > oldWidth) {
- /* column width grew */
- int change = width - oldWidth + 2; /* +2 offsets x's -1s above */
- header.redraw (x, 0, change, headerBounds.height, false);
- } else {
- int change = oldWidth - width + 2; /* +2 offsets x's -1s above */
- header.redraw (headerBounds.width - change, 0, change, headerBounds.height, false);
- }
- }
-
- column.width = width;
-
- /*
- * Notify column and all items of column width change so that display labels
- * can be recomputed if needed.
- */
- column.updateWidth (headerGC);
- headerGC.dispose ();
- for (int i = 0; i < items.length; i++) {
- items [i].updateColumnWidth (column, gc);
- }
- gc.dispose ();
-
- int maximum = 0;
- for (int i = 0; i < columns.length; i++) {
- maximum += columns [i].width;
- }
- ScrollBar hBar = getHorizontalBar ();
- if (hBar != null) {
- hBar.setMaximum (Math.max (1, maximum)); /* setting a value of 0 here is ignored */
- if (hBar.getThumb () != clientArea.width) {
- hBar.setThumb (clientArea.width);
- hBar.setPageIncrement (clientArea.width);
- }
- int oldHorizontalOffset = horizontalOffset; /* hBar.setVisible() can modify horizontalOffset */
- hBar.setVisible (clientArea.width < maximum);
- int selection = hBar.getSelection ();
- if (selection != oldHorizontalOffset) {
- horizontalOffset = selection;
- redraw ();
- if (drawCount <= 0 && header.getVisible ()) header.redraw ();
- }
- }
-
- column.sendEvent (SWT.Resize);
- TreeColumn[] orderedColumns = getOrderedColumns ();
- for (int i = column.getOrderIndex () + 1; i < orderedColumns.length; i++) {
- if (!orderedColumns [i].isDisposed ()) {
- orderedColumns [i].sendEvent (SWT.Move);
- }
- }
-
- if (availableItemsCount == 0) redraw (); /* ensure that static focus rectangle updates properly */
-}
-/*
- * This is a naive implementation that computes the value from scratch.
- */
-void updateHorizontalBar () {
- if (drawCount > 0) return;
- ScrollBar hBar = getHorizontalBar ();
- if (hBar == null) return;
-
- int maxX = 0;
- if (columns.length > 0) {
- for (int i = 0; i < columns.length; i++) {
- maxX += columns [i].width;
- }
- } else {
- for (int i = 0; i < availableItemsCount; i++) {
- Rectangle itemBounds = availableItems [i].getCellBounds (0);
- maxX = Math.max (maxX, itemBounds.x + itemBounds.width + horizontalOffset);
- }
- }
-
- int clientWidth = clientArea.width;
- if (maxX != hBar.getMaximum ()) {
- hBar.setMaximum (Math.max (1, maxX)); /* setting a value of 0 here is ignored */
- }
- int thumb = Math.min (clientWidth, maxX);
- if (thumb != hBar.getThumb ()) {
- hBar.setThumb (thumb);
- hBar.setPageIncrement (thumb);
- }
- hBar.setVisible (clientWidth < maxX);
-
- /* reclaim any space now left on the right */
- if (maxX < horizontalOffset + thumb) {
- horizontalOffset = maxX - thumb;
- hBar.setSelection (horizontalOffset);
- redraw ();
- } else {
- int selection = hBar.getSelection ();
- if (selection != horizontalOffset) {
- horizontalOffset = selection;
- redraw ();
- }
- }
-}
-/*
- * Update the horizontal bar, if needed, in response to an item change (eg.- created,
- * disposed, expanded, etc.). newRightX is the new rightmost X value of the item,
- * and rightXchange is the change that led to the item's rightmost X value becoming
- * newRightX (so oldRightX + rightXchange = newRightX)
- */
-void updateHorizontalBar (int newRightX, int rightXchange) {
- if (drawCount > 0) return;
- ScrollBar hBar = getHorizontalBar ();
- if (hBar == null) return;
-
- newRightX += horizontalOffset;
- int barMaximum = hBar.getMaximum ();
- if (newRightX > barMaximum) { /* item has extended beyond previous maximum */
- hBar.setMaximum (newRightX);
- int clientAreaWidth = clientArea.width;
- int thumb = Math.min (newRightX, clientAreaWidth);
- if (hBar.getThumb () != thumb) {
- hBar.setThumb (thumb);
- hBar.setPageIncrement (thumb);
- }
- hBar.setVisible (clientAreaWidth <= newRightX);
- return;
- }
-
- int previousRightX = newRightX - rightXchange;
- if (previousRightX != barMaximum) {
- /* this was not the rightmost item, so just check for client width change */
- int clientAreaWidth = clientArea.width;
- int thumb = Math.min (barMaximum, clientAreaWidth);
- if (hBar.getThumb () != thumb) {
- hBar.setThumb (thumb);
- hBar.setPageIncrement (thumb);
- }
- hBar.setVisible (clientAreaWidth <= barMaximum);
- return;
- }
- updateHorizontalBar (); /* must search for the new rightmost item */
-}
-void updateVerticalBar () {
- if (drawCount > 0) return;
- ScrollBar vBar = getVerticalBar ();
- if (vBar == null) return;
-
- int pageSize = (clientArea.height - getHeaderHeight ()) / itemHeight;
- int maximum = Math.max (1, availableItemsCount);
- if (maximum != vBar.getMaximum ()) {
- vBar.setMaximum (maximum);
- }
- int thumb = Math.min (pageSize, maximum);
- if (thumb != vBar.getThumb ()) {
- vBar.setThumb (thumb);
- vBar.setPageIncrement (thumb);
- }
- vBar.setVisible (pageSize < maximum);
-
- /* reclaim any space now left on the bottom */
- if (maximum < topIndex + thumb) {
- topIndex = maximum - thumb;
- vBar.setSelection (topIndex);
- redraw ();
- } else {
- int selection = vBar.getSelection ();
- if (selection != topIndex) {
- topIndex = selection;
- redraw ();
- }
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeColumn.java
deleted file mode 100644
index 41d1715a87..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeColumn.java
+++ /dev/null
@@ -1,738 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a column in a tree widget.
- * <p><dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd> Move, Resize, Selection</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT and CENTER may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TreeColumn extends Item {
- Tree parent;
- String displayText = "";
- int width, itemImageWidth;
- boolean moveable, resizable = true;
- int sort = SWT.NONE;
- String toolTipText;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeColumn (Tree parent, int style) {
- this (parent, style, checkNull (parent).columns.length);
-}
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeColumn (Tree parent, int style, int index) {
- super (parent, checkStyle (style), index);
- if (!(0 <= index && index <= parent.columns.length)) error (SWT.ERROR_INVALID_RANGE);
- this.parent = parent;
- parent.createItem (this, index);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize, typedListener);
- addListener (SWT.Move, typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the column header is selected.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-static Tree checkNull (Tree tree) {
- if (tree == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return tree;
-}
-static int checkStyle (int style) {
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-void computeDisplayText (GC gc) {
- int availableWidth = width - 2 * parent.getHeaderPadding ();
- if (image != null) {
- availableWidth -= image.getBounds ().width;
- availableWidth -= Tree.MARGIN_IMAGE;
- }
- if (sort != SWT.NONE) {
- availableWidth -= parent.arrowBounds.width;
- availableWidth -= Tree.MARGIN_IMAGE;
- }
- String text = this.text;
- int textWidth = gc.textExtent (text, SWT.DRAW_MNEMONIC).x;
- if (textWidth <= availableWidth) {
- displayText = text;
- return;
- }
-
- /* Ellipsis will be needed, so subtract their width from the available text width */
- int ellipsisWidth = gc.stringExtent (Tree.ELLIPSIS).x;
- availableWidth -= ellipsisWidth;
- if (availableWidth <= 0) {
- displayText = Tree.ELLIPSIS;
- return;
- }
-
- /* Make initial guess. */
- int index = Math.min (availableWidth / gc.getFontMetrics ().getAverageCharWidth (), text.length ());
- textWidth = gc.textExtent (text.substring (0, index), SWT.DRAW_MNEMONIC).x;
-
- /* Initial guess is correct. */
- if (availableWidth == textWidth) {
- displayText = text.substring (0, index) + Tree.ELLIPSIS;
- return;
- }
-
- /* Initial guess is too high, so reduce until fit is found. */
- if (availableWidth < textWidth) {
- do {
- index--;
- if (index < 0) {
- displayText = Tree.ELLIPSIS;
- return;
- }
- text = text.substring (0, index);
- textWidth = gc.textExtent (text, SWT.DRAW_MNEMONIC).x;
- } while (availableWidth < textWidth);
- displayText = text + Tree.ELLIPSIS;
- return;
- }
-
- /* Initial guess is too low, so increase until overrun is found. */
- while (textWidth < availableWidth) {
- index++;
- textWidth = gc.textExtent (text.substring (0, index), SWT.DRAW_MNEMONIC).x;
- }
- displayText = text.substring (0, index - 1) + Tree.ELLIPSIS;
-}
-public void dispose () {
- if (isDisposed ()) return;
- Rectangle parentBounds = parent.clientArea;
- int x = getX ();
- Tree parent = this.parent;
- dispose (true);
- int width = parentBounds.width - x;
- parent.redraw (x, 0, width, parentBounds.height, false);
- if (parent.drawCount <= 0 && parent.getHeaderVisible ()) {
- parent.header.redraw (x, 0, width, parent.getHeaderHeight (), false);
- }
-}
-void dispose (boolean notifyParent) {
- super.dispose (); /* super is intentional here */
- if (notifyParent) parent.destroyItem (this);
- parent = null;
-}
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget ();
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-/*
- * Returns the width of the header's content
- * (image + text + sort arrow + internal margins)
- */
-int getContentWidth (GC gc, boolean useDisplayText) {
- int contentWidth = 0;
- String text = useDisplayText ? displayText : this.text;
- if (text.length () > 0) {
- contentWidth += gc.textExtent (text, SWT.DRAW_MNEMONIC).x;
- }
- if (image != null) {
- contentWidth += image.getBounds ().width;
- if (text.length () > 0) contentWidth += Tree.MARGIN_IMAGE;
- }
- if (sort != SWT.NONE) {
- contentWidth += parent.arrowBounds.width;
- if (text.length () > 0 || image != null) {
- contentWidth += Tree.MARGIN_IMAGE;
- }
- }
- return contentWidth;
-}
-int getIndex () {
- TreeColumn[] columns = parent.columns;
- for (int i = 0; i < columns.length; i++) {
- if (columns [i] == this) return i;
- }
- return -1;
-}
-/**
- * Gets the moveable attribute. A column that is
- * not moveable cannot be reordered by the user
- * by dragging the header but may be reordered
- * by the programmer.
- *
- * @return the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
-public boolean getMoveable () {
- checkWidget ();
- return moveable;
-}
-int getOrderIndex () {
- TreeColumn[] orderedColumns = parent.orderedColumns;
- if (orderedColumns == null) return getIndex ();
- for (int i = 0; i < orderedColumns.length; i++) {
- if (orderedColumns [i] == this) return i;
- }
- return -1;
-}
-/**
- * Returns the receiver's parent, which must be a <code>Tree</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Tree getParent () {
- checkWidget ();
- return parent;
-}
-int getPreferredWidth () {
- if (!parent.getHeaderVisible ()) return 0;
- GC gc = new GC (parent);
- int result = getContentWidth (gc, false);
- gc.dispose ();
- return result + 2 * parent.getHeaderPadding ();
-}
-/**
- * Gets the resizable attribute. A column that is
- * not resizable cannot be dragged by the user but
- * may be resized by the programmer.
- *
- * @return the resizable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getResizable () {
- checkWidget ();
- return resizable;
-}
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget ();
- return width;
-}
-int getX () {
- TreeColumn[] orderedColumns = parent.getOrderedColumns ();
- int index = getOrderIndex ();
- int result = -parent.horizontalOffset;
- for (int i = 0; i < index; i++) {
- result += orderedColumns [i].width;
- }
- return result;
-}
-void paint (GC gc) {
- int padding = parent.getHeaderPadding ();
-
- int x = getX ();
- int startX = x + padding;
- if (getOrderIndex () != 0 && (style & SWT.LEFT) == 0) {
- int contentWidth = getContentWidth (gc, true);
- if ((style & SWT.RIGHT) != 0) {
- startX = Math.max (startX, x + width - padding - contentWidth);
- } else { /* SWT.CENTER */
- startX = Math.max (startX, x + (width - contentWidth) / 2);
- }
- }
- int headerHeight = parent.getHeaderHeight ();
-
- /* restrict the clipping region to the header cell */
- gc.setClipping (
- x + padding,
- padding,
- width - 2 * padding,
- headerHeight - 2 * padding);
-
- if (image != null) {
- Rectangle imageBounds = image.getBounds ();
- int drawHeight = Math.min (imageBounds.height, headerHeight - 2 * padding);
- gc.drawImage (
- image,
- 0, 0,
- imageBounds.width, imageBounds.height,
- startX, (headerHeight - drawHeight) / 2,
- imageBounds.width, drawHeight);
- startX += imageBounds.width;
- startX += Tree.MARGIN_IMAGE;
- }
- if (displayText.length () > 0) {
- gc.setForeground (display.getSystemColor (SWT.COLOR_BLACK));
- int fontHeight = parent.fontHeight;
- gc.drawText (displayText, startX, (headerHeight - fontHeight) / 2, SWT.DRAW_MNEMONIC);
- startX += gc.textExtent (displayText, SWT.DRAW_MNEMONIC).x + Tree.MARGIN_IMAGE;
- }
- if (sort != SWT.NONE) {
- Image image = sort == SWT.DOWN ? parent.getArrowDownImage () : parent.getArrowUpImage ();
- int y = (headerHeight - parent.arrowBounds.height) / 2;
- gc.drawImage (image, startX, y);
- }
-}
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void pack () {
- checkWidget ();
- TreeItem[] availableItems = parent.availableItems;
- int index = getIndex ();
- int newWidth = getPreferredWidth ();
- for (int i = 0; i < parent.availableItemsCount; i++) {
- int width = availableItems [i].getPreferredWidth (index);
- /* ensure that receiver and parent were not disposed in a callback */
- if (parent.isDisposed () || isDisposed ()) return;
- if (!availableItems [i].isDisposed ()) {
- newWidth = Math.max (newWidth, width);
- }
- }
- if (newWidth != width) parent.updateColumnWidth (this, newWidth);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- removeListener (SWT.Selection, listener);
- removeListener (SWT.DefaultSelection, listener);
-}
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>.
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget ();
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- alignment = checkBits (alignment, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
- if ((style & alignment) != 0) return; /* same value */
- style &= ~(SWT.LEFT | SWT.CENTER | SWT.RIGHT);
- style |= alignment;
- if (getOrderIndex () == 0) return; /* no update needed since first ordered column appears left-aligned */
- int x = getX ();
- parent.redraw (x, 0, width, parent.clientArea.height, false);
- if (parent.drawCount <= 0 && parent.getHeaderVisible ()) {
- /* don't damage the header's drawn borders */
- parent.header.redraw (x, 1, width - 2, parent.getHeaderHeight () - 3, false);
- }
-}
-public void setImage (Image value) {
- checkWidget ();
- if (value == image) return;
- if (value != null && value.equals (image)) return; /* same value */
- super.setImage (value);
-
- /* An image width change may affect the space available for the column's displayText. */
- GC gc = new GC (parent);
- computeDisplayText (gc);
- gc.dispose ();
-
- /*
- * If this is the first image being put into the header then the header
- * height may be adjusted, in which case a full redraw is needed.
- */
- if (parent.headerImageHeight == 0) {
- int oldHeaderHeight = parent.getHeaderHeight ();
- parent.setHeaderImageHeight (value.getBounds ().height);
- if (oldHeaderHeight != parent.getHeaderHeight ()) {
- /* parent header height changed */
- if (parent.drawCount <= 0 && parent.getHeaderVisible ()) {
- parent.header.redraw ();
- }
- parent.redraw ();
- return;
- }
- }
-
- if (parent.drawCount <= 0 && parent.getHeaderVisible ()) {
- /* don't damage the header's drawn borders */
- parent.header.redraw (getX (), 1, width - 2, parent.getHeaderHeight () - 3, false);
- }
-}
-/**
- * Sets the moveable attribute. A column that is
- * moveable can be reordered by the user by dragging
- * the header. A column that is not moveable cannot be
- * dragged by the user but may be reordered
- * by the programmer.
- *
- * @param moveable the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#setColumnOrder(int[])
- * @see Tree#getColumnOrder()
- * @see TreeColumn#getMoveable()
- * @see SWT#Move
- *
- * @since 3.2
- */
-public void setMoveable (boolean moveable) {
- checkWidget ();
- this.moveable = moveable;
-}
-/**
- * Sets the resizable attribute. A column that is
- * not resizable cannot be dragged by the user but
- * may be resized by the programmer.
- *
- * @param resizable the resize attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setResizable (boolean value) {
- checkWidget ();
- resizable = value;
-}
-void setSortDirection (int value) {
- if (value == sort) return;
- boolean widthChange = value == SWT.NONE || sort == SWT.NONE;
- sort = value;
- if (widthChange) {
- /*
- * adding/removing the sort arrow decreases/increases the width that is
- * available for the column's header text, so recompute the display text
- */
- GC gc = new GC (parent);
- computeDisplayText (gc);
- gc.dispose ();
- }
- if (parent.drawCount <= 0 && parent.getHeaderVisible ()) {
- /* don't damage the header's drawn borders */
- parent.header.redraw (getX (), 1, width - 2, parent.getHeaderHeight () - 3, false);
- }
-}
-public void setText (String value) {
- checkWidget ();
- if (value == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (value.equals (text)) return; /* same value */
- super.setText (value);
- GC gc = new GC (parent);
- computeDisplayText (gc);
- gc.dispose ();
- if (parent.drawCount <= 0 && parent.getHeaderVisible ()) {
- /* don't damage the header's drawn borders */
- parent.header.redraw (getX (), 1, width - 2, parent.getHeaderHeight () - 3, false);
- }
-}
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setToolTipText (String string) {
- checkWidget ();
- if (toolTipText == string) return;
- if (toolTipText != null && toolTipText.equals (string)) return;
- toolTipText = string;
- if (parent.toolTipShell == null) return; /* tooltip not currently showing */
- if (((Integer) parent.toolTipShell.getData ()).intValue () != getIndex ()) return; /* tooltip showing for different column */
- parent.headerUpdateToolTip (getX () + (width / 2)); /* update the tooltip text */
-}
-/**
- * Sets the width of the receiver.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int value) {
- checkWidget ();
- if (value < 0) return;
- if (width == value) return; /* same value */
- parent.updateColumnWidth (this, value);
-}
-/*
- * Perform any internal changes necessary to reflect a changed width.
- */
-void updateWidth (GC gc) {
- String oldDisplayText = displayText;
- computeDisplayText (gc);
- /* the header must be damaged if the display text has changed or if the alignment is not LEFT */
- if (parent.getHeaderVisible ()) {
- if ((style & SWT.LEFT) == 0 || !oldDisplayText.equals (displayText)) {
- int padding = parent.getHeaderPadding ();
- parent.header.redraw (getX () + padding, 0, width - padding, parent.getHeaderHeight (), false);
- }
- }
-}
-void updateFont (GC gc) {
- computeDisplayText (gc);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeItem.java
deleted file mode 100644
index f762439f45..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeItem.java
+++ /dev/null
@@ -1,2959 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.Compatibility;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a hierarchy of tree items in a tree widget.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TreeItem extends Item {
- Tree parent;
- TreeItem parentItem;
- TreeItem[] items = Tree.NO_ITEMS;
- int availableIndex = -1; /* index in parent's flat list of available (though not necessarily within viewport) items */
- int depth = 0; /* cached for performance, does not change after instantiation */
- boolean checked, grayed, expanded, cached;
-
- String[] texts;
- int[] textWidths = new int [1]; /* cached string measurements */
- int customWidth = -1; /* width specified by Measure callback */
- int fontHeight; /* cached item font height */
- int[] fontHeights;
- Image[] images;
- Color foreground, background;
- String[] displayTexts;
- Color[] cellForegrounds, cellBackgrounds;
- Font font;
- Font[] cellFonts;
-
- static final int INDENT_HIERARCHY = 6; /* the margin between an item's expander and its checkbox or content */
- static final int MARGIN_TEXT = 3; /* the left and right margins within the text's space */
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>)
- * and a style value describing its behavior and appearance.
- * The item is added to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (Tree parent, int style) {
- this (parent, style, checkNull (parent).items.length);
-}
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>),
- * a style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (Tree parent, int style, int index) {
- this (parent, style, index, true);
-}
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>)
- * and a style value describing its behavior and appearance.
- * The item is added to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parentItem a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (TreeItem parentItem, int style) {
- this (parentItem, style, checkNull (parentItem).items.length);
-}
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>),
- * a style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parentItem a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (TreeItem parentItem, int style, int index) {
- this (parentItem, style, index, true);
-}
-TreeItem (TreeItem parentItem, int style, int index, boolean notifyParent) {
- super (parentItem, style);
- this.parentItem = parentItem;
- parent = parentItem.parent;
- depth = parentItem.depth + 1;
- int validItemIndex = parentItem.items.length;
- if (!(0 <= index && index <= validItemIndex)) error (SWT.ERROR_INVALID_RANGE);
- int columnCount = parent.columns.length;
- if (columnCount > 0) {
- displayTexts = new String [columnCount];
- if (columnCount > 1) {
- texts = new String [columnCount];
- textWidths = new int [columnCount];
- images = new Image [columnCount];
- }
- }
- if (notifyParent) parentItem.addItem (this, index);
-}
-TreeItem (Tree parent, int style, int index, boolean notifyParent) {
- super (parent, style);
- int validItemIndex = parent.items.length;
- if (!(0 <= index && index <= validItemIndex)) error (SWT.ERROR_INVALID_RANGE);
- this.parent = parent;
- int columnCount = parent.columns.length;
- if (columnCount > 0) {
- displayTexts = new String [columnCount];
- if (columnCount > 1) {
- texts = new String [columnCount];
- textWidths = new int [columnCount];
- images = new Image [columnCount];
- }
- }
- if (notifyParent) parent.createItem (this, index);
-}
-/*
- * Updates internal structures in the receiver and its child items to handle the creation of a new column.
- */
-void addColumn (TreeColumn column) {
- int index = column.getIndex ();
- int columnCount = parent.columns.length;
-
- if (columnCount > 1) {
- if (columnCount == 2) {
- texts = new String [2];
- } else {
- String[] newTexts = new String [columnCount];
- System.arraycopy (texts, 0, newTexts, 0, index);
- System.arraycopy (texts, index, newTexts, index + 1, columnCount - index - 1);
- texts = newTexts;
- }
- if (index == 0) {
- texts [1] = text;
- text = ""; //$NON-NLS-1$
- }
-
- if (columnCount == 2) {
- images = new Image [2];
- } else {
- Image[] newImages = new Image [columnCount];
- System.arraycopy (images, 0, newImages, 0, index);
- System.arraycopy (images, index, newImages, index + 1, columnCount - index - 1);
- images = newImages;
- }
- if (index == 0) {
- images [1] = image;
- image = null;
- }
-
- int[] newTextWidths = new int [columnCount];
- System.arraycopy (textWidths, 0, newTextWidths, 0, index);
- System.arraycopy (textWidths, index, newTextWidths, index + 1, columnCount - index - 1);
- textWidths = newTextWidths;
- } else {
- customWidth = -1; /* columnCount == 1 */
- }
-
- /*
- * The length of displayTexts always matches the parent's column count, unless this
- * count is zero, in which case displayTexts is null.
- */
- String[] newDisplayTexts = new String [columnCount];
- if (columnCount > 1) {
- System.arraycopy (displayTexts, 0, newDisplayTexts, 0, index);
- System.arraycopy (displayTexts, index, newDisplayTexts, index + 1, columnCount - index - 1);
- }
- displayTexts = newDisplayTexts;
-
- if (cellBackgrounds != null) {
- Color[] newCellBackgrounds = new Color [columnCount];
- System.arraycopy (cellBackgrounds, 0, newCellBackgrounds, 0, index);
- System.arraycopy (cellBackgrounds, index, newCellBackgrounds, index + 1, columnCount - index - 1);
- cellBackgrounds = newCellBackgrounds;
- }
- if (cellForegrounds != null) {
- Color[] newCellForegrounds = new Color [columnCount];
- System.arraycopy (cellForegrounds, 0, newCellForegrounds, 0, index);
- System.arraycopy (cellForegrounds, index, newCellForegrounds, index + 1, columnCount - index - 1);
- cellForegrounds = newCellForegrounds;
- }
- if (cellFonts != null) {
- Font[] newCellFonts = new Font [columnCount];
- System.arraycopy (cellFonts, 0, newCellFonts, 0, index);
- System.arraycopy (cellFonts, index, newCellFonts, index + 1, columnCount - index - 1);
- cellFonts = newCellFonts;
-
- int[] newFontHeights = new int [columnCount];
- System.arraycopy (fontHeights, 0, newFontHeights, 0, index);
- System.arraycopy (fontHeights, index, newFontHeights, index + 1, columnCount - index - 1);
- fontHeights = newFontHeights;
- }
-
- int orderedIndex = column.getOrderIndex ();
- if (orderedIndex == 0 && columnCount > 1) {
- /*
- * The new second ordered column now has more space available to it than it did while
- * it was the first ordered column since it no longer has to show hierarchy decorations,
- * so recompute its displayText.
- */
- TreeColumn[] orderedColumns = parent.getOrderedColumns ();
- int secondColumnIndex = orderedColumns [1].getIndex ();
- GC gc = new GC (parent);
- gc.setFont (getFont (secondColumnIndex, false));
- computeDisplayText (secondColumnIndex, gc);
- gc.dispose ();
- }
-
- /* notify all child items as well */
- for (int i = 0; i < items.length; i++) {
- items[i].addColumn (column);
- }
-}
-/*
- * Adds a child item to the receiver.
- */
-void addItem (TreeItem item, int index) {
- TreeItem[] newChildren = new TreeItem [items.length + 1];
- System.arraycopy (items, 0, newChildren, 0, index);
- newChildren [index] = item;
- System.arraycopy (items, index, newChildren, index + 1, items.length - index);
- items = newChildren;
-
- if (!item.isAvailable ()) {
- /* receiver will now need an expander box if this is its first child */
- if (isInViewport () && items.length == 1) {
- Rectangle bounds = getExpanderBounds ();
- parent.redraw (bounds.x, bounds.y, bounds.width, bounds.height, false);
- }
- return;
- }
-
- /* item should be available immediately so update parent */
- parent.makeAvailable (item);
-
- /* update scrollbars */
- Rectangle bounds = item.getBounds (false);
- int rightX = bounds.x + bounds.width;
- parent.updateHorizontalBar (rightX, rightX);
- parent.updateVerticalBar ();
- /*
- * If new item is above viewport then adjust topIndex and the vertical scrollbar
- * so that the current viewport items will not change.
- */
- if (item.availableIndex < parent.topIndex) {
- parent.topIndex++;
- ScrollBar vBar = parent.getVerticalBar ();
- if (vBar != null) vBar.setSelection (parent.topIndex);
- return;
- }
-
- parent.redrawFromItemDownwards (availableIndex);
-}
-static Tree checkNull (Tree tree) {
- if (tree == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return tree;
-}
-static TreeItem checkNull (TreeItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-void clear () {
- checked = grayed = false;
- texts = null;
- textWidths = new int [1];
- fontHeight = 0;
- fontHeights = null;
- images = null;
- foreground = background = null;
- displayTexts = null;
- cellForegrounds = cellBackgrounds = null;
- font = null;
- cellFonts = null;
- cached = false;
- text = "";
- image = null;
-
- int columnCount = parent.columns.length;
- if (columnCount > 0) {
- displayTexts = new String [columnCount];
- if (columnCount > 1) {
- texts = new String [columnCount];
- textWidths = new int [columnCount];
- images = new Image [columnCount];
- }
- }
-}
-/**
- * Clears the item at the given zero-relative index in the receiver.
- * The text, icon and other attributes of the item are set to the default
- * value. If the tree was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param index the index of the item to clear
- * @param all <code>true</code> if all child items of the indexed item should be
- * cleared recursively, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clear (int index, boolean recursive) {
- checkWidget ();
- if (!(0 <= index && index < items.length)) error (SWT.ERROR_INVALID_RANGE);
- TreeItem item = items [index];
-
- /* if there are no columns then the horizontal scrollbar may need adjusting */
- TreeItem[] availableDescendents = null;
- int oldRightX = 0;
- if (item.availableIndex != -1 && parent.columns.length == 0) {
- if (recursive) {
- availableDescendents = item.computeAvailableDescendents ();
- for (int i = 0; i < availableDescendents.length; i++) {
- Rectangle bounds = availableDescendents [i].getBounds (false);
- oldRightX = Math.max (oldRightX, bounds.x + bounds.width);
- }
- } else {
- Rectangle bounds = item.getBounds (false);
- oldRightX = bounds.x + bounds.width;
- }
- }
-
- /* clear the item(s) */
- item.clear ();
- if (recursive) {
- item.clearAll (true, false);
- }
- if (item.availableIndex == -1) return; /* no visual update needed */
-
- /* adjust the horizontal scrollbar if needed */
- if (parent.columns.length == 0) {
- int newRightX = 0;
- if (recursive) {
- for (int i = 0; i < availableDescendents.length; i++) {
- Rectangle bounds = availableDescendents [i].getBounds (false);
- newRightX = Math.max (newRightX, bounds.x + bounds.width);
- }
- } else {
- Rectangle bounds = item.getBounds (false);
- newRightX = bounds.x + bounds.width;
- }
- parent.updateHorizontalBar (newRightX, newRightX - oldRightX);
- }
-
- /* redraw the item(s) */
- if (recursive) {
- int descendentCount = availableDescendents == null ?
- item.computeAvailableDescendentCount () :
- availableDescendents.length;
- parent.redrawItems (item.availableIndex, item.availableIndex + descendentCount - 1, false);
- } else {
- parent.redrawItem (item.availableIndex, false);
- }
-}
-/**
- * Clears all the items in the receiver. The text, icon and other
- * attributes of the items are set to their default values. If the
- * tree was created with the <code>SWT.VIRTUAL</code> style, these
- * attributes are requested again as needed.
- *
- * @param all <code>true</code> if all child items should be cleared
- * recursively, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clearAll (boolean recursive) {
- clearAll (recursive, true);
-}
-void clearAll (boolean recursive, boolean doVisualUpdate) {
- checkWidget ();
- if (items.length == 0) return;
-
- /* if there are no columns then the horizontal scrollbar may need adjusting */
- TreeItem[] availableDescendents = null;
- int oldRightX = 0;
- if (doVisualUpdate && availableIndex != -1 && expanded && parent.columns.length == 0) {
- if (recursive) {
- availableDescendents = computeAvailableDescendents ();
- /*
- * i starts at 1 here because item 0 in availableDescendents
- * will be the receiver, but this item is not being cleared.
- */
- for (int i = 1; i < availableDescendents.length; i++) {
- Rectangle bounds = availableDescendents [i].getBounds (false);
- oldRightX = Math.max (oldRightX, bounds.x + bounds.width);
- }
- } else {
- for (int i = 0; i < items.length; i++) {
- Rectangle bounds = items [i].getBounds (false);
- oldRightX = Math.max (oldRightX, bounds.x + bounds.width);
- }
- }
- }
-
- /* clear the item(s) */
- for (int i = 0; i < items.length; i++) {
- items [i].clear ();
- if (recursive) items [i].clearAll (true, false);
- }
-
- if (!doVisualUpdate || availableIndex == -1 || !expanded) return; /* no visual update needed */
-
- /* adjust the horizontal scrollbar if needed */
- if (parent.columns.length == 0) {
- int newRightX = 0;
- if (recursive) {
- /*
- * i starts at 1 here because item 0 in availableDescendents
- * is the receiver, but this item was not cleared.
- */
- for (int i = 1; i < availableDescendents.length; i++) {
- Rectangle bounds = availableDescendents [i].getBounds (false);
- newRightX = Math.max (newRightX, bounds.x + bounds.width);
- }
- } else {
- /*
- * All cleared direct child items will have the same x and width
- * values now, so just measure the first one as a sample.
- */
- Rectangle bounds = items [0].getBounds (false);
- newRightX = bounds.x + bounds.width;
- }
- parent.updateHorizontalBar (newRightX, newRightX - oldRightX);
- }
-
- /* redraw the item(s) */
- if (recursive) {
- int startIndex = items [0].availableIndex;
- TreeItem lastChild = items [items.length - 1];
- int endIndex = lastChild.availableIndex + lastChild.computeAvailableDescendentCount () - 1;
- parent.redrawItems (startIndex, endIndex, false);
- } else {
- for (int i = 0; i < items.length; i++) {
- parent.redrawItem (items [i].availableIndex, false);
- }
- }
-}
-/*
- * Returns a collection of all tree items descending from the receiver, including
- * the receiver. The order of the items in this collection are receiver, child0tree,
- * child1tree, ..., childNtree.
- */
-TreeItem[] computeAllDescendents () {
- int childCount = items.length;
- TreeItem[][] childResults = new TreeItem [childCount][];
- int count = 1; /* receiver */
- for (int i = 0; i < childCount; i++) {
- childResults [i] = items [i].computeAllDescendents ();
- count += childResults [i].length;
- }
- TreeItem[] result = new TreeItem [count];
- int index = 0;
- result [index++] = this;
- for (int i = 0; i < childCount; i++) {
- System.arraycopy (childResults [i], 0, result, index, childResults [i].length);
- index += childResults [i].length;
- }
- return result;
-}
-/*
- * Returns the number of tree items descending from the receiver, including the
- * receiver, that are currently available. It is assumed that the receiver is
- * currently available.
- */
-int computeAvailableDescendentCount () {
- int result = 1; /* receiver */
- if (!expanded) return result;
- for (int i = 0; i < items.length; i++) {
- result += items [i].computeAvailableDescendentCount ();
- }
- return result;
-}
-/*
- * Returns a collection of the tree items descending from the receiver, including
- * the receiver, that are currently available. It is assumed that the receiver is
- * currently available. The order of the items in this collection are receiver,
- * child0tree, child1tree, ..., childNtree.
- */
-TreeItem[] computeAvailableDescendents () {
- if (!expanded) return new TreeItem[] {this};
- int childCount = items.length;
- TreeItem[][] childResults = new TreeItem [childCount][];
- int count = 1; /* receiver */
- for (int i = 0; i < childCount; i++) {
- childResults [i] = items [i].computeAvailableDescendents ();
- count += childResults [i].length;
- }
- TreeItem[] result = new TreeItem [count];
- int index = 0;
- result [index++] = this;
- for (int i = 0; i < childCount; i++) {
- System.arraycopy (childResults [i], 0, result, index, childResults [i].length);
- index += childResults [i].length;
- }
- return result;
-}
-void computeDisplayText (int columnIndex, GC gc) {
- if ((parent.style & SWT.VIRTUAL) != 0 && !cached) return; /* nothing to do */
-
- int columnCount = parent.columns.length;
- if (columnCount == 0) {
- String text = getText (0, false);
- textWidths [columnIndex] = gc.stringExtent (text).x;
- return;
- }
-
- int orderedIndex = parent.columns.length == 0 ? 0 : parent.columns [columnIndex].getOrderIndex ();
- TreeColumn column = parent.columns [columnIndex];
- int availableWidth;
- if (orderedIndex == 0) {
- /* ordered column 0 is always LEFT and must consider hierarchy decorations */
- availableWidth = column.getX () + column.width - getTextX (columnIndex) - 2 * MARGIN_TEXT;
- } else {
- /* ordered columns > 0 may not be LEFT so cannot use getTextX (int) */
- availableWidth = column.width - 2 * parent.getCellPadding () - 2 * MARGIN_TEXT;
- if (images [columnIndex] != null) {
- availableWidth -= images [columnIndex].getBounds ().width;
- availableWidth -= Tree.MARGIN_IMAGE;
- }
- }
- String text = getText (columnIndex, false);
- int textWidth = gc.stringExtent (text).x;
- if (textWidth <= availableWidth) {
- displayTexts [columnIndex] = text;
- textWidths [columnIndex] = textWidth;
- return;
- }
-
- /* Ellipsis will be needed, so subtract their width from the available text width */
- int ellipsisWidth = gc.stringExtent (Tree.ELLIPSIS).x;
- availableWidth -= ellipsisWidth;
- if (availableWidth <= 0) {
- displayTexts [columnIndex] = Tree.ELLIPSIS;
- textWidths [columnIndex] = ellipsisWidth;
- return;
- }
-
- /* Make initial guess. */
- int index = Math.min (availableWidth / gc.getFontMetrics ().getAverageCharWidth (), text.length ());
- textWidth = gc.stringExtent (text.substring (0, index)).x;
-
- /* Initial guess is correct. */
- if (availableWidth == textWidth) {
- displayTexts [columnIndex] = text.substring (0, index) + Tree.ELLIPSIS;
- textWidths [columnIndex] = textWidth + ellipsisWidth;
- return;
- }
-
- /* Initial guess is too high, so reduce until fit is found. */
- if (availableWidth < textWidth) {
- do {
- index--;
- if (index < 0) {
- displayTexts [columnIndex] = Tree.ELLIPSIS;
- textWidths [columnIndex] = ellipsisWidth;
- return;
- }
- text = text.substring (0, index);
- textWidth = gc.stringExtent (text).x;
- } while (availableWidth < textWidth);
- displayTexts [columnIndex] = text + Tree.ELLIPSIS;
- textWidths [columnIndex] = textWidth + ellipsisWidth;
- return;
- }
-
- /* Initial guess is too low, so increase until overrun is found. */
- int previousWidth = 0;
- while (textWidth < availableWidth) {
- index++;
- previousWidth = textWidth;
- textWidth = gc.stringExtent (text.substring (0, index)).x;
- }
- displayTexts [columnIndex] = text.substring (0, index - 1) + Tree.ELLIPSIS;
- textWidths [columnIndex] = previousWidth + ellipsisWidth;
-}
-void computeDisplayTexts (GC gc) {
- if ((parent.style & SWT.VIRTUAL) != 0 && !cached) return; /* nothing to do */
-
- int columnCount = parent.columns.length;
- if (columnCount == 0) return;
-
- for (int i = 0; i < columnCount; i++) {
- gc.setFont (getFont (i, false));
- computeDisplayText (i, gc);
- }
-}
-/*
- * Computes the cached text widths.
- */
-void computeTextWidths (GC gc) {
- if ((parent.style & SWT.VIRTUAL) != 0 && !cached) return; /* nothing to do */
-
- int validColumnCount = Math.max (1, parent.columns.length);
- textWidths = new int [validColumnCount];
- for (int i = 0; i < textWidths.length; i++) {
- String value = getDisplayText (i);
- if (value != null) {
- gc.setFont (getFont (i, false));
- textWidths [i] = gc.stringExtent (value).x;
- }
- }
-}
-public void dispose () {
- if (isDisposed ()) return;
- int startIndex = -1, endIndex = -1;
- Tree parent = this.parent;
- int index = getIndex ();
-
- /* determine the indices, if any, that will need to be visually updated */
- if (isAvailable ()) {
- if (isLastChild () && index > 0) {
- /* vertical connector lines no longer needed for this item */
- if (parentItem != null) {
- startIndex = parentItem.items [index - 1].availableIndex;
- } else {
- startIndex = parent.items [index - 1].availableIndex;
- }
- } else {
- startIndex = availableIndex;
- }
- endIndex = parent.availableItemsCount - 1;
- }
-
- /* for performance do this upfront for whole descendent chain */
- TreeItem focusItem = parent.focusItem;
- if (focusItem != null && focusItem.hasAncestor (this)) {
- parent.setFocusItem (this, false);
- parent.reassignFocus ();
- focusItem = parent.focusItem;
- if (focusItem != null) {
- parent.redrawItem (focusItem.availableIndex, true);
- }
- }
- if (parentItem != null) parentItem.removeItem (this, index);
- dispose (true);
- if (startIndex != -1) {
- parent.redrawItems (startIndex, endIndex, false);
- }
-}
-void dispose (boolean notifyParent) {
- if (isDisposed ()) return;
- for (int i = 0; i < items.length; i++) {
- items [i].dispose (notifyParent);
- }
- if (notifyParent) parent.destroyItem (this);
- super.dispose (); /* super is intentional here */
- background = foreground = null;
- cellBackgrounds = cellForegrounds = null;
- font = null;
- cellFonts = null;
- images = null;
- texts = displayTexts = null;
- textWidths = fontHeights = null;
- parent = null;
- parentItem = null;
- items = null;
-}
-/*
- * Ensure that all ancestors of the receiver are expanded
- */
-void expandAncestors () {
- if (parentItem != null) parentItem.expandAncestors ();
- setExpanded (true);
- Event newEvent = new Event ();
- newEvent.item = this;
- parent.inExpand = true;
- parent.sendEvent (SWT.Expand, newEvent);
- parent.inExpand = false;
- if (isDisposed ()) return;
- if (items.length == 0) {
- expanded = false;
- }
-}
-/**
- * Returns the receiver's background color.
- *
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public Color getBackground () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (background != null) return background;
- return parent.getBackground ();
-}
-/**
- * Returns the background color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Color getBackground (int columnIndex) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return getBackground ();
- if (cellBackgrounds == null || cellBackgrounds [columnIndex] == null) return getBackground ();
- return cellBackgrounds [columnIndex];
-}
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget ();
- return getBounds (true);
-}
-Rectangle getBounds (boolean checkData) {
- if (checkData && !parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (!isAvailable ()) return new Rectangle (0, 0, 0, 0);
- TreeColumn[] orderedColumns = parent.getOrderedColumns ();
- int orderedCol0Index = orderedColumns.length == 0 ? 0 : orderedColumns [0].getIndex ();
- int x = getTextX (orderedCol0Index);
- int width = textWidths [orderedCol0Index] + 2 * MARGIN_TEXT;
- if (orderedColumns.length > 0) {
- TreeColumn column = orderedColumns [0];
- int right = column.getX () + column.width;
- if (x + width > right) {
- width = Math.max (0, right - x);
- }
- }
- return new Rectangle (x, parent.getItemY (this), width, parent.itemHeight);
-}
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent at a column in the tree.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding column rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Rectangle getBounds (int columnIndex) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (!isAvailable ()) return new Rectangle (0, 0, 0, 0);
- TreeColumn[] columns = parent.columns;
- int columnCount = columns.length;
- int validColumnCount = Math.max (1, columnCount);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) {
- return new Rectangle (0, 0, 0, 0);
- }
- /*
- * If there are no columns then this is the bounds of the receiver's content.
- */
- if (columnCount == 0) {
- return new Rectangle (
- getContentX (0),
- parent.getItemY (this),
- getContentWidth (0),
- parent.itemHeight - 1);
- }
-
- TreeColumn column = columns [columnIndex];
- if (column.getOrderIndex () == 0) {
- /*
- * For ordered column 0 this is bounds from the beginning of the content to the
- * end of the column.
- */
- int x = getContentX (columnIndex);
- int offset = x - column.getX ();
- int width = Math.max (0, column.width - offset - 1); /* max is for columns with small widths */
- return new Rectangle (x, parent.getItemY (this) + 1, width, parent.itemHeight - 1);
- }
- /*
- * For ordered columns > 0 this is the bounds of the tree cell.
- */
- return new Rectangle (column.getX (), parent.getItemY (this) + 1, column.width, parent.itemHeight - 1);
-}
-/*
- * Returns the full bounds of a cell in a tree, regardless of its content.
- */
-Rectangle getCellBounds (int columnIndex) {
- int y = parent.getItemY (this);
- if (parent.columns.length == 0) {
- int width;
- if (customWidth != -1) {
- width = getContentX (0) + customWidth + parent.horizontalOffset;
- } else {
- int textPaintWidth = textWidths [0] + 2 * MARGIN_TEXT;
- width = getTextX (0) + textPaintWidth + parent.horizontalOffset;
- }
- return new Rectangle (-parent.horizontalOffset, y, width, parent.itemHeight);
- }
- TreeColumn column = parent.columns [columnIndex];
- return new Rectangle (column.getX (), y, column.width, parent.itemHeight);
-}
-/*
- * Returns the bounds of the receiver's checkbox, or null if the parent's style does not
- * include SWT.CHECK.
- */
-Rectangle getCheckboxBounds () {
- if ((parent.getStyle () & SWT.CHECK) == 0) return null;
- int itemHeight = parent.itemHeight;
- Rectangle result = parent.checkboxBounds;
- Point[] hLinePoints = getHconnectorEndpoints ();
- result.x = hLinePoints [1].x;
- result.y = parent.getItemY (this) + (itemHeight - result.height) / 2;
- return result;
-}
-/**
- * Returns <code>true</code> if the receiver is checked,
- * and false otherwise. When the parent does not have
- * the <code>CHECK style, return false.
- * <p>
- *
- * @return the checked state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getChecked () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return checked;
-}
-int getContentWidth (int columnIndex) {
- int width = textWidths [columnIndex] + 2 * MARGIN_TEXT;
- int orderedIndex = parent.columns.length == 0 ? 0 : parent.columns [columnIndex].getOrderIndex ();
- if (orderedIndex == 0) {
- width += parent.orderedCol0imageWidth;
- if (parent.orderedCol0imageWidth > 0) width += Tree.MARGIN_IMAGE;
- } else {
- Image image = getImage (columnIndex, false);
- if (image != null) {
- width += image.getBounds ().width + Tree.MARGIN_IMAGE;
- }
- }
- return width;
-}
-/*
- * Returns the x value where the receiver's content (ie.- its image or text) begins
- * for the specified column. For ordered columns > 0 this is dependent upon column
- * alignment, and for ordered column 0 this is dependent upon the receiver's depth in
- * the tree item hierarchy and the presence/absence of a checkbox.
- */
-int getContentX (int columnIndex) {
- int orderedIndex = parent.columns.length == 0 ? 0 : parent.columns [columnIndex].getOrderIndex ();
- if (orderedIndex > 0) {
- TreeColumn column = parent.columns [columnIndex];
- int contentX = column.getX () + parent.getCellPadding ();
- if ((column.style & SWT.LEFT) != 0) return contentX;
-
- /* column is not left-aligned */
- int contentWidth = getContentWidth (columnIndex);
- if ((column.style & SWT.RIGHT) != 0) {
- int padding = parent.getCellPadding ();
- contentX = Math.max (contentX, column.getX () + column.width - padding - contentWidth);
- } else { /* SWT.CENTER */
- contentX = Math.max (contentX, column.getX () + (column.width - contentWidth) / 2);
- }
- return contentX;
- }
-
- /* ordered column 0 (always left-aligned) */
- if ((parent.style & SWT.CHECK) != 0) {
- Rectangle checkBounds = getCheckboxBounds ();
- return checkBounds.x + checkBounds.width + Tree.MARGIN_IMAGE;
- }
-
- int contentX = parent.getCellPadding () - parent.horizontalOffset;
- if (parentItem != null) {
- int expanderWidth = parent.expanderBounds.width + INDENT_HIERARCHY;
- contentX += expanderWidth * depth;
- }
- contentX += parent.expanderBounds.width;
- return contentX + Tree.MARGIN_IMAGE + INDENT_HIERARCHY;
-}
-String getDisplayText (int columnIndex) {
- if (parent.columns.length == 0) return getText (0, false);
- String result = displayTexts [columnIndex];
- return result != null ? result : ""; //$NON-NLS-1$
-}
-/**
- * Returns <code>true</code> if the receiver is expanded,
- * and false otherwise.
- * <p>
- *
- * @return the expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getExpanded () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return expanded;
-}
-/*
- * Returns the bounds of the receiver's expander box, regardless of whether the
- * receiver currently has children or not.
- */
-Rectangle getExpanderBounds () {
- int itemHeight = parent.itemHeight;
- int x = parent.getCellPadding () - parent.horizontalOffset;
- int y = parent.getItemY (this);
- if (parentItem != null) {
- int expanderWidth = parent.expanderBounds.width + INDENT_HIERARCHY;
- x += expanderWidth * depth;
- }
- return new Rectangle (
- x, y + (itemHeight - parent.expanderBounds.height) / 2,
- parent.expanderBounds.width, parent.expanderBounds.height);
-}
-/*
- * Returns the bounds that should be used for drawing a focus rectangle on the receiver
- */
-Rectangle getFocusBounds () {
- TreeColumn[] columns = parent.columns;
- int orderedCol0index = columns.length == 0 ? 0 : parent.getOrderedColumns ()[0].getIndex ();
- int x = getTextX (orderedCol0index);
-
- int width;
- if (columns.length > 0) {
- /* ensure that the focus x does not start beyond the right bound of ordered column 0 */
- int rightX = columns [orderedCol0index].getX () + columns [orderedCol0index].width;
- x = Math.min (x, rightX - 1);
-
- TreeColumn column;
- if ((parent.style & SWT.FULL_SELECTION) != 0) {
- int[] columnOrder = parent.getColumnOrder ();
- column = columns [columnOrder [columnOrder.length - 1]]; /* last ordered column */
- } else {
- column = columns [orderedCol0index];
- }
- width = column.getX () + column.width - x - 1;
- } else { /* no columns */
- if (customWidth != -1) {
- width = customWidth;
- } else {
- width = textWidths [0] + 2 * MARGIN_TEXT;
- }
- }
-
- return new Rectangle (
- x,
- parent.getItemY (this) + (parent.linesVisible ? 1 : 0),
- width,
- parent.itemHeight - (parent.linesVisible ? 1 : 0));
-}
-/**
- * Returns the font that the receiver will use to paint textual information for this item.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont () {
- checkWidget ();
- return getFont (true);
-}
-Font getFont (boolean checkData) {
- if (checkData && !parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (font != null) return font;
- return parent.getFont ();
-}
-/**
- * Returns the font that the receiver will use to paint textual information
- * for the specified cell in this item.
- *
- * @param index the column index
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Font getFont (int columnIndex) {
- checkWidget ();
- return getFont (columnIndex, true);
-}
-Font getFont (int columnIndex, boolean checkData) {
- if (checkData && !parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return getFont (checkData);
- if (cellFonts == null || cellFonts [columnIndex] == null) return getFont (checkData);
- return cellFonts [columnIndex];
-}
-int getFontHeight () {
- if (fontHeight != 0) return fontHeight;
- return parent.fontHeight;
-}
-int getFontHeight (int columnIndex) {
- if (fontHeights == null || fontHeights [columnIndex] == 0) return getFontHeight ();
- return fontHeights [columnIndex];
-}
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public Color getForeground () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (foreground != null) return foreground;
- return parent.getForeground ();
-}
-/**
- *
- * Returns the foreground color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Color getForeground (int columnIndex) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return getForeground ();
- if (cellForegrounds == null || cellForegrounds [columnIndex] == null) return getForeground ();
- return cellForegrounds [columnIndex];
-}
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the parent does not have
- * the <code>CHECK style, return false.
- * <p>
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getGrayed () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return grayed;
-}
-/*
- * Answers the start and end points of the horizontal connector line that is
- * drawn between an item's expander box and its checkbox or content.
- */
-Point[] getHconnectorEndpoints () {
- Rectangle expanderBounds = getExpanderBounds ();
- int x, width;
- if (items.length == 0) { /* no child items, so no expander box */
- x = expanderBounds.x + Compatibility.ceil (expanderBounds.width, 2);
- width = Compatibility.floor (expanderBounds.width, 2) + INDENT_HIERARCHY;
- } else { /* has child items */
- x = expanderBounds.x + expanderBounds.width;
- width = INDENT_HIERARCHY;
- }
- int y = expanderBounds.y + expanderBounds.height / 2;
- return new Point[] {
- new Point (x, y),
- new Point (x + width, y)
- };
-}
-/*
- * Returns the bounds representing the clickable region that should select the receiver.
- */
-Rectangle getHitBounds () {
- int[] columnOrder = parent.getColumnOrder ();
- int orderedCol0index = columnOrder.length == 0 ? 0 : parent.columns [columnOrder [0]].getIndex ();
- int contentX = getContentX (orderedCol0index);
- int width = 0;
- TreeColumn[] columns = parent.columns;
- if (columns.length == 0) {
- width = getContentWidth (0);
- } else {
- /*
- * If there are columns then this spans from the beginning of the receiver's column 0
- * image or text to the end of either column 0 or the last column (FULL_SELECTION).
- */
- TreeColumn column;
- if ((parent.style & SWT.FULL_SELECTION) != 0) {
- column = columns [columnOrder [columnOrder.length - 1]]; /* last column */
- } else {
- column = columns [orderedCol0index];
- }
- width = column.getX () + column.width - contentX;
- }
- return new Rectangle (contentX, parent.getItemY (this), width, parent.itemHeight);
-}
-public Image getImage () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return super.getImage ();
-}
-/**
- * Returns the image stored at the given column index in the receiver,
- * or null if the image has not been set or if the column does not exist.
- *
- * @param index the column index
- * @return the image stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Image getImage (int columnIndex) {
- checkWidget ();
- return getImage (columnIndex, true);
-}
-Image getImage (int columnIndex, boolean checkData) {
- if (checkData && !parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return null;
- if (columnIndex == 0) return super.getImage (); /* super is intentional here */
- return images [columnIndex];
-}
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of an image at a column in the
- * tree.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding image rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Rectangle getImageBounds (int columnIndex) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return new Rectangle (0,0,0,0);
-
- int padding = parent.getCellPadding ();
- int startX = getContentX (columnIndex);
- int itemHeight = parent.itemHeight;
- int imageSpaceY = itemHeight - 2 * padding;
- int y = parent.getItemY (this);
- int orderedIndex = parent.columns.length == 0 ? 0 : parent.columns [columnIndex].getOrderIndex ();
- Image image = getImage (columnIndex, false);
- int drawWidth = 0;
- if (orderedIndex == 0) {
- /* for ordered column 0 all images have the same width */
- drawWidth = parent.orderedCol0imageWidth;
- } else {
- if (image != null) drawWidth = image.getBounds ().width;
- }
- return new Rectangle (startX, y + padding, drawWidth, imageSpaceY);
-}
-int getIndex () {
- TreeItem[] items;
- if (parentItem != null) {
- items = parentItem.items;
- } else {
- items = parent.items;
- }
- for (int i = 0; i < items.length; i++) {
- if (items [i] == this) return i;
- }
- return -1;
-}
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public TreeItem getItem (int index) {
- checkWidget ();
- if (index < 0) error (SWT.ERROR_INVALID_RANGE);
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index >= items.length) error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-/**
- * Returns the number of items contained in the receiver
- * that are direct item children of the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return items.length;
-}
-String getNameText () {
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (!cached) return "*virtual*"; //$NON-NLS-1$
- }
- return super.getNameText ();
-}
-/**
- * Returns a (possibly empty) array of <code>TreeItem</code>s which
- * are the direct item children of the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem [] getItems () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- TreeItem[] result = new TreeItem [items.length];
- System.arraycopy (items, 0, result, 0, items.length);
- return result;
-}
-/**
- * Returns the receiver's parent, which must be a <code>Tree</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Tree getParent () {
- checkWidget ();
- return parent;
-}
-/**
- * Returns the receiver's parent item, which must be a
- * <code>TreeItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem getParentItem () {
- checkWidget ();
- return parentItem;
-}
-/*
- * Returns the receiver's ideal width for the specified columnIndex.
- */
-int getPreferredWidth (int columnIndex) {
- int width = 0;
- GC gc = new GC (parent);
- gc.setFont (getFont (columnIndex, false));
- width += gc.stringExtent (getText (columnIndex, false)).x + 2 * MARGIN_TEXT;
- int orderedIndex = parent.columns.length == 0 ? 0 : parent.columns [columnIndex].getOrderIndex ();
- if (orderedIndex == 0) {
- if (parent.orderedCol0imageWidth > 0) {
- width += parent.orderedCol0imageWidth;
- width += Tree.MARGIN_IMAGE;
- }
- } else {
- Image image = getImage (columnIndex, false);
- if (image != null) {
- width += image.getBounds ().width;
- width += Tree.MARGIN_IMAGE;
- }
- }
-
- if (parent.hooks (SWT.MeasureItem)) {
- Event event = new Event ();
- event.item = this;
- event.gc = gc;
- event.index = columnIndex;
- event.x = getContentX (columnIndex);
- event.y = parent.getItemY (this);
- event.width = width;
- event.height = parent.itemHeight;
- parent.sendEvent (SWT.MeasureItem, event);
- if (parent.itemHeight != event.height) {
- parent.customHeightSet = true;
- boolean update = parent.setItemHeight (event.height + 2 * parent.getCellPadding ());
- if (update) parent.redraw ();
- }
- width = event.width;
- }
- gc.dispose ();
-
- if (orderedIndex == 0) {
- return getContentX (columnIndex) + parent.horizontalOffset + width + parent.getCellPadding (); /* right side cell pad */
- }
-
- return width + 2 * parent.getCellPadding ();
-}
-public String getText () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return super.getText ();
-}
-/**
- * Returns the text stored at the given column index in the receiver,
- * or empty string if the text has not been set.
- *
- * @param index the column index
- * @return the text stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public String getText (int columnIndex) {
- checkWidget ();
- return getText (columnIndex, true);
-}
-String getText (int columnIndex, boolean checkData) {
- if (checkData && !parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return ""; //$NON-NLS-1$
- if (columnIndex == 0) return super.getText (); /* super is intentional here */
- if (texts [columnIndex] == null) return ""; //$NON-NLS-1$
- return texts [columnIndex];
-}
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of the text at a column in the
- * tree.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding text rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Rectangle getTextBounds (int columnIndex) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (!isAvailable ()) return new Rectangle (0, 0, 0, 0);
- TreeColumn[] columns = parent.columns;
- int columnCount = columns.length;
- int validColumnCount = Math.max (1, columnCount);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) {
- return new Rectangle (0, 0, 0, 0);
- }
- /*
- * If there are no columns then this is the bounds of the receiver's content.
- */
- if (columnCount == 0) {
- int x = getTextX (0) + MARGIN_TEXT;
- int width = Math.max (0, getContentX(0) + getContentWidth (0) - x);
- return new Rectangle (
- x,
- parent.getItemY (this),
- width,
- parent.itemHeight - 1);
- }
-
- TreeColumn column = columns [columnIndex];
- if (column.getOrderIndex () == 0) {
- /*
- * For ordered column 0 this is bounds from the beginning of the content to the
- * end of the column.
- */
- int x = getTextX (columnIndex) + MARGIN_TEXT;
- int offset = x - column.getX ();
- int width = Math.max (0, column.width - offset - 1); /* max is for columns with small widths */
- return new Rectangle (x, parent.getItemY (this) + 1, width, parent.itemHeight - 1);
- }
- /*
- * For ordered columns > 0 this is the bounds of the tree cell.
- */
- int x = getTextX (columnIndex) + MARGIN_TEXT;
- int offset = x - column.getX ();
- int width = Math.max (0, column.width - offset - MARGIN_TEXT);
- return new Rectangle (x, parent.getItemY (this) + 1, width, parent.itemHeight - 1);
-}
-/*
- * Returns the x value where the receiver's text begins.
- */
-int getTextX (int columnIndex) {
- int orderedIndex = parent.columns.length == 0 ? 0 : parent.columns [columnIndex].getOrderIndex ();
- int textX = getContentX (columnIndex);
- if (orderedIndex == 0) {
- textX += parent.orderedCol0imageWidth;
- if (parent.orderedCol0imageWidth > 0) textX += Tree.MARGIN_IMAGE;
- } else {
- Image image = getImage (columnIndex, false);
- if (image != null) {
- textX += image.getBounds ().width + Tree.MARGIN_IMAGE;
- }
- }
- return textX;
-}
-/*
- * Returns true if the receiver descends from (or is identical to) the item.
- */
-boolean hasAncestor (TreeItem item) {
- if (this == item) return true;
- if (parentItem == null) return false;
- return parentItem.hasAncestor (item);
-}
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int indexOf (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (item.parentItem != this) return -1;
- return item.getIndex ();
-}
-/*
- * Returns true if the receiver is currently available (though not necessary in the viewport).
- */
-boolean isAvailable () {
- if (parentItem == null) return true; /* root items are always available */
- if (!parentItem.expanded) return false;
- return parentItem.isAvailable ();
-}
-/*
- * Answers a boolean indicating whether the receiver's y is within the current
- * viewport of the parent.
- */
-boolean isInViewport () {
- if (availableIndex == -1) return false;
- int topIndex = parent.topIndex;
- if (availableIndex < topIndex) return false;
- int visibleCount = parent.clientArea.height / parent.itemHeight;
- return availableIndex <= topIndex + visibleCount;
-}
-/*
- * Returns true if the receiver is the last child of its parent item, or of its parent
- * if the receiver is a root item, and false otherwise.
- */
-boolean isLastChild () {
- if (parentItem != null) {
- return getIndex () == parentItem.items.length - 1;
- }
- return getIndex () == parent.items.length - 1;
-}
-boolean isSelected () {
- return parent.getSelectionIndex (this) != -1;
-}
-/*
- * The backgroundOnly argument indicates whether the item should only
- * worry about painting its background color and selection.
- *
- * Returns a boolean indicating whether to abort drawing focus on the item.
- * If the receiver is not the current focus item then this value is irrelevant.
- */
-boolean paint (GC gc, TreeColumn column, boolean backgroundOnly) {
- if (!parent.checkData (this, true)) return false;
- int columnIndex = 0, orderedIndex = 0, x = 0;
- if (column != null) {
- columnIndex = column.getIndex ();
- orderedIndex = column.getOrderIndex ();
- x = column.getX ();
- }
-
- /*
- * Capture GC attributes that will need to be restored later in the paint
- * process to ensure that the item paints as intended without being affected
- * by GC changes made in MeasureItem/EraseItem/PaintItem callbacks.
- */
- int oldAlpha = gc.getAlpha ();
- boolean oldAdvanced = gc.getAdvanced ();
- int oldAntialias = gc.getAntialias ();
- Pattern oldBackgroundPattern = gc.getBackgroundPattern ();
- Pattern oldForegroundPattern = gc.getForegroundPattern ();
- int oldInterpolation = gc.getInterpolation ();
- int[] oldLineDash = gc.getLineDash ();
- int oldLineWidth = gc.getLineWidth ();
- int oldTextAntialias = gc.getTextAntialias ();
-
- if (parent.hooks (SWT.MeasureItem)) {
- int contentWidth = getContentWidth (columnIndex);
- int contentX = getContentX (columnIndex);
- gc.setFont (getFont (columnIndex, false));
- Event event = new Event ();
- event.item = this;
- event.gc = gc;
- event.index = columnIndex;
- event.x = contentX;
- event.y = parent.getItemY (this);
- event.width = contentWidth;
- event.height = parent.itemHeight;
- parent.sendEvent (SWT.MeasureItem, event);
- event.gc = null;
- if (gc.isDisposed ()) return false;
- gc.setAlpha (oldAlpha);
- gc.setAntialias (oldAntialias);
- gc.setBackgroundPattern (oldBackgroundPattern);
- gc.setForegroundPattern (oldForegroundPattern);
- gc.setInterpolation (oldInterpolation);
- gc.setLineDash (oldLineDash);
- gc.setLineWidth (oldLineWidth);
- gc.setTextAntialias (oldTextAntialias);
- gc.setAdvanced (oldAdvanced);
- if (isDisposed ()) return false;
- if (parent.itemHeight != event.height) {
- parent.customHeightSet = true;
- boolean update = parent.setItemHeight (event.height + 2 * parent.getCellPadding ());
- if (update) parent.redraw ();
- }
- if (parent.columns.length == 0) {
- int change = event.width - (customWidth != -1 ? customWidth : contentWidth);
- if (event.width != contentWidth || customWidth != -1) customWidth = event.width;
- if (change != 0) { /* scrollbar may be affected since no columns */
- parent.updateHorizontalBar (contentX + event.width, change);
- // TODO what if clip is too small now?
- }
- }
- }
-
- /* if this cell is completely to the right of the client area then there's no need to paint it */
- Rectangle clientArea = parent.clientArea;
- if (clientArea.x + clientArea.width < x) return false;
-
- Rectangle cellBounds = getCellBounds (columnIndex);
- if (parent.linesVisible) {
- cellBounds.y++;
- cellBounds.height--;
- }
- int cellRightX = 0;
- if (column != null) {
- cellRightX = column.getX () + column.width;
- } else {
- cellRightX = cellBounds.x + cellBounds.width;
- }
-
- /* restrict the clipping region to the cell */
- gc.setClipping (x, cellBounds.y, clientArea.width - x, cellBounds.height);
-
- int y = parent.getItemY (this);
- int itemHeight = parent.itemHeight;
-
- /* draw the parent background color/image of this cell */
- if (column == null) {
- parent.drawBackground (gc, 0, y, clientArea.width, itemHeight);
- } else {
- int fillWidth = cellBounds.width;
- if (parent.linesVisible) fillWidth--;
- parent.drawBackground (gc, cellBounds.x, cellBounds.y, fillWidth, cellBounds.height);
- }
-
- boolean isSelected = isSelected ();
- boolean isFocusItem = parent.focusItem == this && parent.isFocusControl ();
- boolean drawBackground = true;
- boolean drawForeground = true;
- boolean drawSelection = isSelected;
- boolean drawFocus = isFocusItem;
- if (parent.hooks (SWT.EraseItem)) {
- drawBackground = background != null || (cellBackgrounds != null && cellBackgrounds [columnIndex] != null);
- gc.setFont (getFont (columnIndex, false));
- if (isSelected && (columnIndex == 0 || (parent.style & SWT.FULL_SELECTION) != 0)) {
- gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT));
- gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION));
- } else {
- gc.setForeground (getForeground (columnIndex));
- gc.setBackground (getBackground (columnIndex));
- }
- Event event = new Event ();
- event.item = this;
- event.gc = gc;
- event.index = columnIndex;
- event.doit = true;
- event.detail = SWT.FOREGROUND;
- if (drawBackground) event.detail |= SWT.BACKGROUND;
- if (isSelected) event.detail |= SWT.SELECTED;
- if (isFocusItem) event.detail |= SWT.FOCUSED;
- event.x = cellBounds.x;
- event.y = cellBounds.y;
- event.width = cellBounds.width;
- event.height = cellBounds.height;
- gc.setClipping (cellBounds);
- parent.sendEvent (SWT.EraseItem, event);
- event.gc = null;
- if (gc.isDisposed ()) return false;
- gc.setAlpha (oldAlpha);
- gc.setAntialias (oldAntialias);
- gc.setBackgroundPattern (oldBackgroundPattern);
- gc.setClipping (cellBounds);
- gc.setForegroundPattern (oldForegroundPattern);
- gc.setInterpolation (oldInterpolation);
- gc.setLineDash (oldLineDash);
- gc.setLineWidth (oldLineWidth);
- gc.setTextAntialias (oldTextAntialias);
- gc.setAdvanced (oldAdvanced);
- if (isDisposed ()) return false;
- if (!event.doit) {
- drawBackground = drawForeground = drawSelection = drawFocus = false;
- } else {
- drawBackground = drawBackground && (event.detail & SWT.BACKGROUND) != 0;
- drawForeground = (event.detail & SWT.FOREGROUND) != 0;
- drawSelection = isSelected && (event.detail & SWT.SELECTED) != 0;
- drawFocus = isFocusItem && (event.detail & SWT.FOCUSED) != 0;
- }
- }
-
- /* draw the cell's set background if appropriate */
- if (drawBackground) {
- gc.setBackground (getBackground (columnIndex));
- if (columnIndex == 0 && (column == null || column.getOrderIndex () == 0)) {
- Rectangle focusBounds = getFocusBounds ();
- int fillWidth = 0;
- if (column == null) {
- fillWidth = focusBounds.width;
- } else {
- fillWidth = column.width - focusBounds.x;
- if (parent.linesVisible) fillWidth--;
- }
- gc.fillRectangle (focusBounds.x, focusBounds.y, fillWidth, focusBounds.height);
- } else {
- int fillWidth = cellBounds.width;
- gc.fillRectangle (cellBounds.x, cellBounds.y, fillWidth, cellBounds.height);
- }
- }
-
- /* draw the selection bar if the receiver is selected */
- if (drawSelection && isSelected && (orderedIndex == 0 || (parent.style & SWT.FULL_SELECTION) != 0)) {
- gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION));
- if (orderedIndex == 0) {
- Rectangle focusBounds = getFocusBounds ();
- int fillWidth = focusBounds.width;
- if (parent.columns.length < 2 || (parent.style & SWT.FULL_SELECTION) == 0) {
- fillWidth -= 2; /* space for right bound of focus rect */
- }
- if (fillWidth > 0) {
- gc.fillRectangle (focusBounds.x + 1, focusBounds.y + 1, fillWidth, focusBounds.height - 2);
- }
- } else {
- int fillWidth = column.width;
- int[] columnOrder = parent.getColumnOrder ();
- if (columnIndex == columnOrder [columnOrder.length - 1]) {
- fillWidth -= 2; /* space for right bound of focus rect */
- }
- if (fillWidth > 0) {
- gc.fillRectangle (
- column.getX (),
- cellBounds.y + 1,
- fillWidth,
- cellBounds.height - 2);
- }
- }
- }
-
- if (backgroundOnly) return false;
-
- /* Draw column 0 decorations */
- if (orderedIndex == 0) {
- gc.setClipping (cellBounds);
-
- /* Draw hierarchy connector lines */
- Rectangle expanderBounds = getExpanderBounds ();
- Color oldForeground = gc.getForeground ();
- gc.setForeground (parent.getConnectorColor ());
-
- /* Draw vertical line above expander */
- int lineX = expanderBounds.x + expanderBounds.width / 2;
- int y2 = expanderBounds.y;
- if (items.length == 0) {
- y2 += expanderBounds.height / 2;
- }
- /* Do not draw this line iff this is the very first item in the tree */
- if (parentItem != null || getIndex () != 0) {
- gc.drawLine (lineX, y, lineX, y2);
- }
-
- /* Draw vertical line below expander if the receiver has lower siblings */
- if (!isLastChild ()) {
- if (items.length != 0) y2 += expanderBounds.height;
- gc.drawLine (lineX, y2, lineX, y + itemHeight);
- }
-
- /* Draw horizontal line to right of expander */
- Point[] endpoints = getHconnectorEndpoints ();
- gc.drawLine (endpoints [0].x, endpoints [0].y, endpoints [1].x - Tree.MARGIN_IMAGE, endpoints [1].y);
-
- /*
- * Draw hierarchy lines that are needed by other items that are shown below
- * this item but whose parents are shown above (ie.- lines to the left of
- * this item's connector line).
- */
- TreeItem item = parentItem;
- while (item != null) {
- if (!item.isLastChild ()) {
- Rectangle itemExpanderBounds = item.getExpanderBounds ();
- lineX = itemExpanderBounds.x + itemExpanderBounds.width / 2;
- gc.drawLine (lineX, y, lineX, y + itemHeight);
- }
- item = item.parentItem;
- }
-
- gc.setForeground (oldForeground);
-
- /* Draw expand/collapse image if receiver has children */
- if (items.length > 0) {
- Image image = expanded ? parent.getExpandedImage () : parent.getCollapsedImage ();
- gc.drawImage (image, expanderBounds.x, expanderBounds.y);
- }
-
- /* Draw checkbox if parent Tree has style SWT.CHECK */
- if ((parent.style & SWT.CHECK) != 0) {
- Image baseImage = grayed ? parent.getGrayUncheckedImage () : parent.getUncheckedImage ();
- Rectangle checkboxBounds = getCheckboxBounds ();
- gc.drawImage (baseImage, checkboxBounds.x, checkboxBounds.y);
- /* Draw checkmark if item is checked */
- if (checked) {
- Image checkmarkImage = parent.getCheckmarkImage ();
- Rectangle checkmarkBounds = checkmarkImage.getBounds ();
- int xInset = (checkboxBounds.width - checkmarkBounds.width) / 2;
- int yInset = (checkboxBounds.height - checkmarkBounds.height) / 2;
- gc.drawImage (checkmarkImage, checkboxBounds.x + xInset, checkboxBounds.y + yInset);
- }
- }
- }
-
- if (drawForeground) {
- Image image = getImage (columnIndex, false);
- String text = getDisplayText (columnIndex);
- Rectangle imageArea = getImageBounds (columnIndex);
- int startX = imageArea.x;
-
- /* while painting the cell's content restrict the clipping region */
- int padding = parent.getCellPadding ();
- gc.setClipping (
- startX,
- cellBounds.y + padding - (parent.linesVisible ? 1 : 0),
- cellRightX - startX - padding,
- cellBounds.height - 2 * (padding - (parent.linesVisible ? 1 : 0)));
-
- /* draw the image */
- if (image != null) {
- Rectangle imageBounds = image.getBounds ();
- gc.drawImage (
- image,
- 0, 0, /* source x, y */
- imageBounds.width, imageBounds.height, /* source width, height */
- imageArea.x, imageArea.y, /* dest x, y */
- imageArea.width, imageArea.height); /* dest width, height */
- }
-
- /* draw the text */
- if (text.length () > 0) {
- gc.setFont (getFont (columnIndex, false));
- int fontHeight = getFontHeight (columnIndex);
- if (drawSelection && (orderedIndex == 0 || (parent.style & SWT.FULL_SELECTION) != 0)) {
- gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT));
- } else {
- if (!isSelected || drawSelection) {
- gc.setForeground (getForeground (columnIndex));
- }
- }
- x = getTextX (columnIndex) + MARGIN_TEXT;
- gc.drawString (text, x, y + (itemHeight - fontHeight) / 2, true);
- }
- }
-
- if (parent.hooks (SWT.PaintItem)) {
- int contentWidth = getContentWidth (columnIndex);
- int contentX = getContentX (columnIndex);
- gc.setFont (getFont (columnIndex, false));
- if (isSelected && (columnIndex == 0 || (parent.style & SWT.FULL_SELECTION) != 0)) {
- gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT));
- gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION));
- } else {
- gc.setForeground (getForeground (columnIndex));
- gc.setBackground (getBackground (columnIndex));
- }
- Event event = new Event ();
- event.item = this;
- event.gc = gc;
- event.index = columnIndex;
- if (isSelected) event.detail |= SWT.SELECTED;
- if (drawFocus) event.detail |= SWT.FOCUSED;
- event.x = contentX;
- event.y = cellBounds.y;
- event.width = contentWidth;
- event.height = cellBounds.height;
- gc.setClipping (cellBounds);
- parent.sendEvent (SWT.PaintItem, event);
- event.gc = null;
- if (gc.isDisposed ()) return false;
- gc.setAlpha (oldAlpha);
- gc.setAntialias (oldAntialias);
- gc.setBackgroundPattern (oldBackgroundPattern);
- gc.setClipping (cellBounds);
- gc.setForegroundPattern (oldForegroundPattern);
- gc.setInterpolation (oldInterpolation);
- gc.setLineDash (oldLineDash);
- gc.setLineWidth (oldLineWidth);
- gc.setTextAntialias (oldTextAntialias);
- gc.setAdvanced (oldAdvanced);
- drawFocus = isFocusItem && (event.detail & SWT.FOCUSED) != 0;
- }
-
- return isFocusItem && !drawFocus;
-}
-/*
- * Redraw part of the receiver. If either EraseItem or PaintItem is hooked then
- * only full cells should be damaged, so adjust accordingly. If neither of these
- * events are hooked then the exact bounds given for damaging can be used.
- */
-void redraw (int x, int y, int width, int height, int columnIndex) {
- if (!parent.hooks (SWT.EraseItem) && !parent.hooks (SWT.PaintItem)) {
- parent.redraw (x, y, width, height, false);
- return;
- }
- Rectangle cellBounds = getCellBounds (columnIndex);
- parent.redraw (cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height, false);
-}
-void redrawItem () {
- if (!isAvailable ()) return;
- parent.redraw (0, parent.getItemY (this), parent.clientArea.width, parent.itemHeight, false);
-}
-/*
- * Updates internal structures in the receiver and its child items to handle the removal of a column.
- */
-void removeColumn (TreeColumn column, int index, int orderedIndex) {
- int columnCount = parent.columns.length;
-
- if (columnCount == 0) {
- /* reverts to normal tree when last column disposed */
- cellBackgrounds = cellForegrounds = null;
- displayTexts = null;
- cellFonts = null;
- fontHeights = null;
- GC gc = new GC (parent);
- computeTextWidths (gc);
- gc.dispose ();
- /* notify all child items as well */
- for (int i = 0; i < items.length; i++) {
- items [i].removeColumn (column, index, orderedIndex);
- }
- return;
- }
-
- String[] newTexts = new String [columnCount];
- System.arraycopy (texts, 0, newTexts, 0, index);
- System.arraycopy (texts, index + 1, newTexts, index, columnCount - index);
- texts = newTexts;
-
- Image[] newImages = new Image [columnCount];
- System.arraycopy (images, 0, newImages, 0, index);
- System.arraycopy (images, index + 1, newImages, index, columnCount - index);
- images = newImages;
-
- int[] newTextWidths = new int [columnCount];
- System.arraycopy (textWidths, 0, newTextWidths, 0, index);
- System.arraycopy (textWidths, index + 1, newTextWidths, index, columnCount - index);
- textWidths = newTextWidths;
-
- String[] newDisplayTexts = new String [columnCount];
- System.arraycopy (displayTexts, 0, newDisplayTexts, 0, index);
- System.arraycopy (displayTexts, index + 1, newDisplayTexts, index, columnCount - index);
- displayTexts = newDisplayTexts;
-
- if (cellBackgrounds != null) {
- Color[] newCellBackgrounds = new Color [columnCount];
- System.arraycopy (cellBackgrounds, 0, newCellBackgrounds, 0, index);
- System.arraycopy (cellBackgrounds, index + 1, newCellBackgrounds, index, columnCount - index);
- cellBackgrounds = newCellBackgrounds;
- }
- if (cellForegrounds != null) {
- Color[] newCellForegrounds = new Color [columnCount];
- System.arraycopy (cellForegrounds, 0, newCellForegrounds, 0, index);
- System.arraycopy (cellForegrounds, index + 1, newCellForegrounds, index, columnCount - index);
- cellForegrounds = newCellForegrounds;
- }
- if (cellFonts != null) {
- Font[] newCellFonts = new Font [columnCount];
- System.arraycopy (cellFonts, 0, newCellFonts, 0, index);
- System.arraycopy (cellFonts, index + 1, newCellFonts, index, columnCount - index);
- cellFonts = newCellFonts;
-
- int[] newFontHeights = new int [columnCount];
- System.arraycopy (fontHeights, 0, newFontHeights, 0, index);
- System.arraycopy (fontHeights, index + 1, newFontHeights, index, columnCount - index);
- fontHeights = newFontHeights;
- }
-
- if (index == 0) {
- text = texts [0] != null ? texts [0] : ""; //$NON-NLS-1$
- texts [0] = null;
- image = images [0];
- images [0] = null;
- }
-
- if (orderedIndex == 0) {
- /*
- * The new first ordered column will not have as much width available to it as it did when
- * it was the second ordered column since it now has to show hierarchy decorations as well,
- * so recompute its displayText.
- */
- int firstColumnIndex = parent.getOrderedColumns () [0].getIndex ();
- GC gc = new GC (parent);
- gc.setFont (getFont (firstColumnIndex, false));
- computeDisplayText (firstColumnIndex, gc);
- gc.dispose ();
- }
- if (columnCount < 2) {
- texts = null;
- images = null;
- }
-
- /* notify all child items as well */
- for (int i = 0; i < items.length; i++) {
- items [i].removeColumn (column, index, orderedIndex);
- }
-}
-/**
- * Removes all of the items from the receiver.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void removeAll () {
- checkWidget ();
- if (items.length == 0) return;
-
- int lastAvailableIndex = parent.availableItemsCount - 1;
- /* for performance do this upfront for whole descendent chain */
- TreeItem focusItem = parent.focusItem;
- if (focusItem != null && focusItem.hasAncestor (this)) {
- parent.setFocusItem (this, false);
- }
- while (items.length > 0) {
- items [0].dispose (true);
- removeItem (items [0], 0);
- }
- items = Tree.NO_ITEMS;
- expanded = false;
- if (isAvailable ()) {
- parent.redrawItems (availableIndex, lastAvailableIndex, false);
- }
-}
-/*
- * Removes a child item from the receiver.
- */
-void removeItem (TreeItem item, int index) {
- if (isDisposed ()) return;
- TreeItem[] newItems = new TreeItem [items.length - 1];
- System.arraycopy (items, 0, newItems, 0, index);
- System.arraycopy (items, index + 1, newItems, index, newItems.length - index);
- items = newItems;
- if (items.length == 0) {
- items = Tree.NO_ITEMS;
- /* condition below handles creation of item within Expand callback */
- if (!parent.inExpand) {
- expanded = false;
- if (isInViewport ()) {
- Rectangle bounds = getExpanderBounds (); /* expander box no longer needed */
- parent.redraw (bounds.x, bounds.y, bounds.width, bounds.height, false);
- }
- }
- return;
- }
-}
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public void setBackground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Color oldColor = background;
- if (oldColor == color) return;
- background = color;
- if (oldColor != null && oldColor.equals (color)) return;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- redrawItem ();
-}
-/**
- * Sets the background color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- *
- */
-public void setBackground (int columnIndex, Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return;
- if (cellBackgrounds == null) {
- if (color == null) return;
- cellBackgrounds = new Color [validColumnCount];
- }
- Color oldColor = cellBackgrounds [columnIndex];
- if (oldColor == color) return;
- cellBackgrounds [columnIndex] = color;
- if (oldColor != null && oldColor.equals (color)) return;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- if (isInViewport ()) {
- Rectangle bounds = getCellBounds (columnIndex);
- parent.redraw (bounds.x, bounds.y, bounds.width, bounds.height, false);
- }
-}
-/**
- * Sets the checked state of the receiver.
- * <p>
- *
- * @param checked the new checked state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setChecked (boolean value) {
- checkWidget ();
- if ((parent.getStyle () & SWT.CHECK) == 0) return;
- if (checked == value) return;
- checked = value;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- if (isInViewport ()) {
- if (parent.hooks (SWT.EraseItem) || parent.hooks (SWT.PaintItem)) {
- redrawItem ();
- } else {
- Rectangle bounds = getCheckboxBounds ();
- parent.redraw (bounds.x, bounds.y, bounds.width, bounds.height, false);
- }
- }
-}
-/**
- * Sets the expanded state of the receiver.
- * <p>
- *
- * @param expanded the new expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setExpanded (boolean value) {
- checkWidget ();
- if (expanded == value) return;
- if (items.length == 0) return;
- if (parent.inExpand) return;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- if (value) {
- expanded = value;
- if (availableIndex == -1) return;
-
- TreeItem[] availableDescendents = computeAvailableDescendents ();
- int descendentsCount = availableDescendents.length;
- if (availableIndex != parent.availableItemsCount - 1) {
- /* the receiver is not the last available item */
- Rectangle clientArea = parent.clientArea;
- int y = parent.getItemY (this) + parent.itemHeight;
- if (0 < y && y < clientArea.height) {
- if (parent.drawCount <= 0) {
- parent.update ();
- GC gc = new GC (parent);
- gc.copyArea (
- 0, y,
- clientArea.width, clientArea.height - y,
- 0, y + ((descendentsCount - 1) * parent.itemHeight));
- gc.dispose ();
- }
- }
- }
-
- parent.makeDescendentsAvailable (this, availableDescendents);
-
- /* update scrollbars */
- int rightX = 0;
- for (int i = 1; i < availableDescendents.length; i++) {
- Rectangle bounds = availableDescendents [i].getBounds (false);
- rightX = Math.max (rightX, bounds.x + bounds.width);
- }
- parent.updateHorizontalBar (rightX, rightX);
- parent.updateVerticalBar ();
- /*
- * If new item is above viewport then adjust topIndex and the vertical scrollbar
- * so that the current viewport items will not change.
- */
- if (availableIndex < parent.topIndex) {
- parent.topIndex += descendentsCount - 1;
- ScrollBar vBar = parent.getVerticalBar ();
- if (vBar != null) vBar.setSelection (parent.topIndex);
- return;
- }
-
- int redrawStart = availableIndex + 1;
- int redrawEnd = redrawStart + descendentsCount - 2;
- parent.redrawItems (redrawStart, redrawEnd, false);
- } else {
- TreeItem[] descendents = computeAvailableDescendents ();
- expanded = value;
- if (availableIndex == -1) return;
- Rectangle clientArea = parent.clientArea;
-
- int y = parent.getItemY (this) + parent.itemHeight;
- int startY = y + (descendents.length - 1) * parent.itemHeight;
- if (y < clientArea.height && 0 < startY) { /* determine whether any visual update is actually needed */
- if (parent.drawCount <= 0) {
- parent.update ();
- GC gc = new GC (parent);
- gc.copyArea (0, startY, clientArea.width, clientArea.height - startY, 0, y);
- gc.dispose ();
- int redrawY = y + Math.max (0, clientArea.height - startY);
- parent.redraw (0, redrawY, clientArea.width, clientArea.height - redrawY, false);
- }
- }
-
- parent.makeDescendentsUnavailable (this, descendents);
-
- /*
- * If all collapsed items are above the viewport then adjust topIndex and
- * the vertical scrollbar so that the current viewport items will not change.
- */
- int bottomIndex = availableIndex + descendents.length - 1;
- if (bottomIndex < parent.topIndex) {
- parent.topIndex = parent.topIndex - descendents.length + 1;
- ScrollBar vBar = parent.getVerticalBar ();
- if (vBar != null) vBar.setSelection (parent.topIndex);
- }
-
- parent.updateHorizontalBar ();
- parent.updateVerticalBar ();
-
- /* move focus (and selection if SWT.SINGLE) to item if a descendent had focus */
- TreeItem focusItem = parent.focusItem;
- if (focusItem != null && focusItem != this && focusItem.hasAncestor (this)) {
- parent.setFocusItem (this, false);
- if ((parent.style & SWT.SINGLE) != 0) {
- parent.selectItem (this, false);
- }
- /* Fire an event since the selection is being changed automatically */
- Event newEvent = new Event ();
- newEvent.item = this;
- parent.sendEvent (SWT.Selection, newEvent);
- if (isDisposed ()) return;
- parent.showItem (this);
- parent.redrawItem (availableIndex, true);
- }
- }
- /* redraw the receiver's expander box */
- if (isInViewport ()) {
- Rectangle bounds = getExpanderBounds ();
- parent.redraw (bounds.x, bounds.y, bounds.width, bounds.height, false);
- }
-}
-/**
- * Sets the font that the receiver will use to paint textual information
- * for this item to the font specified by the argument, or to the default font
- * for that kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (Font font) {
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Font oldFont = this.font;
- if (oldFont == font) return;
- this.font = font;
- if (oldFont != null && oldFont.equals (font)) return;
-
- Rectangle bounds = getBounds (false);
- int oldRightX = bounds.x + bounds.width;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-
- /* recompute cached values for string measurements */
- GC gc = new GC (parent);
- gc.setFont (getFont (false));
- fontHeight = gc.getFontMetrics ().getHeight ();
- computeDisplayTexts (gc);
- computeTextWidths (gc);
- gc.dispose ();
-
- /* horizontal bar could be affected if tree has no columns */
- if (parent.columns.length == 0) {
- bounds = getBounds (false);
- int newRightX = bounds.x + bounds.width;
- parent.updateHorizontalBar (newRightX, newRightX - oldRightX);
- }
- redrawItem ();
-}
-/**
- * Sets the font that the receiver will use to paint textual information
- * for the specified cell in this item to the font specified by the
- * argument, or to the default font for that kind of control if the
- * argument is null.
- *
- * @param index the column index
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setFont (int columnIndex, Font font) {
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
-
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return;
- if (cellFonts == null) {
- if (font == null) return;
- cellFonts = new Font [validColumnCount];
- }
- Font oldFont = cellFonts [columnIndex];
- if (oldFont == font) return;
- cellFonts [columnIndex] = font;
- if (oldFont != null && oldFont.equals (font)) return;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-
- /* recompute cached values for string measurements */
- GC gc = new GC (parent);
- gc.setFont (getFont (columnIndex, false));
- if (fontHeights == null) fontHeights = new int [validColumnCount];
- fontHeights [columnIndex] = gc.getFontMetrics ().getHeight ();
- computeDisplayText (columnIndex, gc);
- gc.dispose ();
-
- if (isInViewport ()) {
- Rectangle bounds = getCellBounds (columnIndex);
- parent.redraw (bounds.x, bounds.y, bounds.width, bounds.height, false);
- }
-}
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @since 2.0
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public void setForeground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Color oldColor = foreground;
- if (oldColor == color) return;
- foreground = color;
- if (oldColor != null && oldColor.equals (color)) return;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- redrawItem ();
-}
-/**
- * Sets the foreground color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- *
- */
-public void setForeground (int columnIndex, Color value) {
- checkWidget ();
- if (value != null && value.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return;
- if (cellForegrounds == null) {
- if (value == null) return;
- cellForegrounds = new Color [validColumnCount];
- }
- Color oldColor = cellForegrounds [columnIndex];
- if (oldColor == value) return;
- cellForegrounds [columnIndex] = value;
- if (oldColor != null && oldColor.equals (value)) return;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- if (isInViewport ()) {
- redraw (
- getTextX (columnIndex),
- parent.getItemY (this),
- textWidths [columnIndex] + 2 * MARGIN_TEXT,
- parent.itemHeight,
- columnIndex);
- }
-}
-/**
- * Sets the grayed state of the checkbox for this item. This state change
- * only applies if the Tree was created with the SWT.CHECK style.
- *
- * @param grayed the new grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setGrayed (boolean value) {
- checkWidget ();
- if ((parent.getStyle () & SWT.CHECK) == 0) return;
- if (grayed == value) return;
- grayed = value;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- if (isInViewport ()) {
- Rectangle bounds = getCheckboxBounds ();
- parent.redraw (bounds.x, bounds.y, bounds.width, bounds.height, false);
- }
-}
-public void setImage (Image value) {
- checkWidget ();
- setImage (0, value);
-}
-/**
- * Sets the image for multiple columns in the tree.
- *
- * @param images the array of new images
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setImage (Image[] value) {
- checkWidget ();
- if (value == null) error (SWT.ERROR_NULL_ARGUMENT);
-
- // TODO make a smarter implementation of this
- for (int i = 0; i < value.length; i++) {
- if (value [i] != null) setImage (i, value [i]);
- }
-}
-/**
- * Sets the receiver's image at a column.
- *
- * @param index the column index
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setImage (int columnIndex, Image value) {
- checkWidget ();
- if (value != null && value.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
-
- TreeColumn[] columns = parent.columns;
- int validColumnCount = Math.max (1, columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return;
- Image image = getImage (columnIndex, false);
- if (value == image) return;
- if (value != null && value.equals (image)) return;
- if (columnIndex == 0) {
- super.setImage (value);
- } else {
- images [columnIndex] = value;
- }
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-
- /*
- * An image width change may affect the space available for the item text, so
- * recompute the displayText if there are columns.
- */
- if (columns.length > 0) {
- GC gc = new GC (parent);
- gc.setFont (getFont (columnIndex, false));
- computeDisplayText (columnIndex, gc);
- gc.dispose ();
- }
-
- if (value == null) {
- redrawItem (); // TODO why the whole item?
- return;
- }
-
- if (columns.length == 0) {
- if (parent.imageHeight == 0) {
- /* this is the first image being put into the parent Tree */
- Rectangle bounds = value.getBounds ();
- parent.orderedCol0imageWidth = bounds.width;
- parent.setImageHeight (bounds.height);
- parent.redrawItems (0, parent.availableItemsCount - 1, false);
- } else {
- redrawItem ();
- }
- return;
- }
-
- /* there are 1+ columns */
- TreeColumn column = columns [columnIndex];
- int orderedIndex = column.getOrderIndex ();
- Rectangle bounds = value.getBounds ();
- if (column.itemImageWidth == 0) column.itemImageWidth = bounds.width;
-
- if (parent.imageHeight == 0) {
- /* this is the first image being put into the parent Tree */
- int oldItemHeight = parent.itemHeight;
- parent.setImageHeight (bounds.height);
-
- if (orderedIndex == 0) { /* the first ordered column */
- parent.orderedCol0imageWidth = bounds.width;
- /*
- * All column 0 cells will now have less room available for their texts,
- * so all items must now recompute their column 0 displayTexts.
- */
- TreeItem[] rootItems = parent.items;
- GC gc = new GC (parent);
- for (int i = 0; i < rootItems.length; i++) {
- rootItems [i].updateColumnWidth (column, gc);
- }
- gc.dispose ();
- if (oldItemHeight != parent.itemHeight) {
- /* the item height grew as a result of the new image height, so redraw everything */
- parent.redraw ();
- } else {
- /* redraw the column since all items should now have image space */
- parent.redraw (column.getX (), 0, column.width, parent.clientArea.height, false);
- }
- } else { /* not the first ordered column */
- if (oldItemHeight != parent.itemHeight) {
- /* the item height grew as a result of the new image height, so redraw everything */
- parent.redraw ();
- } else {
- redrawItem ();
- }
- }
- return;
- }
-
- if (orderedIndex == 0 && parent.orderedCol0imageWidth == 0) {
- /* this is the first image being put into the current ordered column 0 */
- parent.orderedCol0imageWidth = bounds.width;
- /*
- * All column 0 cells will now have less room available for their texts,
- * so all items must now recompute their column 0 displayTexts.
- */
- TreeItem[] rootItems = parent.items;
- GC gc = new GC (parent);
- for (int i = 0; i < rootItems.length; i++) {
- rootItems [i].updateColumnWidth (column, gc);
- }
- gc.dispose ();
- parent.redraw (column.getX (), 0, column.width, parent.clientArea.height, false);
- return;
- }
-
- redrawItem (); // TODO why the whole item?
-}
-/**
- * Sets the number of child items contained in the receiver.
- *
- * @param count the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setItemCount (int count) {
- checkWidget ();
- count = Math.max (0, count);
- if (count == items.length) return;
- int redrawStart, redrawEnd;
-
- /* if the new item count is less than the current count then remove all excess items from the end */
- if (count < items.length) {
- redrawStart = count > 0 ? items [count - 1].availableIndex : availableIndex;
- redrawEnd = parent.availableItemsCount - 1;
- for (int i = count; i < items.length; i++) {
- items [i].dispose (true);
- }
- if (count == 0) {
- items = Tree.NO_ITEMS;
- } else {
- TreeItem[] newItems = new TreeItem [count];
- System.arraycopy (items, 0, newItems, 0, count);
- items = newItems;
- }
- if (count == 0) expanded = false;
- } else {
- int oldAvailableDescendentCount = computeAvailableDescendentCount ();
- int grow = count - items.length;
- redrawStart = items.length == 0 ? availableIndex : items [items.length - 1].availableIndex;
- redrawEnd = expanded && isAvailable () ? parent.availableItemsCount + grow - 1: redrawStart;
- TreeItem[] newItems = new TreeItem [count];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- for (int i = items.length - grow; i < count; i++) {
- items [i] = new TreeItem (this, SWT.NONE, i, false);
- }
-
- if (expanded && availableIndex != -1) {
- /* expand the availableItems array if necessary */
- if (parent.availableItems.length < parent.availableItemsCount + grow) {
- TreeItem[] newAvailableItems = new TreeItem [parent.availableItemsCount + grow];
- System.arraycopy (parent.availableItems, 0, newAvailableItems, 0, parent.availableItemsCount);
- parent.availableItems = newAvailableItems;
- }
- TreeItem[] availableItems = parent.availableItems;
- /* shift items right to create space for the new available items */
- int dest = availableIndex + oldAvailableDescendentCount + grow;
- System.arraycopy (
- availableItems,
- availableIndex + oldAvailableDescendentCount,
- availableItems,
- dest,
- availableItems.length - dest);
- parent.availableItemsCount += grow;
- /* copy new items in */
- System.arraycopy (
- items,
- items.length - grow,
- availableItems,
- availableIndex + oldAvailableDescendentCount,
- grow);
- /* update availableIndex for all affected items */
- for (int i = availableIndex + oldAvailableDescendentCount; i < parent.availableItemsCount; i++) {
- availableItems [i].availableIndex = i;
- }
- }
- }
-
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- if (availableIndex != -1) {
- if (expanded) parent.updateVerticalBar ();
- parent.redrawItems (redrawStart, redrawEnd, false);
- }
-}
-public void setText (String value) {
- checkWidget ();
- Rectangle bounds = getBounds (false);
- int oldRightX = bounds.x + bounds.width;
- setText (0, value);
- /* horizontal bar could be affected if tree has no columns */
- if (parent.columns.length == 0) {
- bounds = getBounds (false);
- int newRightX = bounds.x + bounds.width;
- parent.updateHorizontalBar (newRightX, newRightX - oldRightX);
- }
-}
-/**
- * Sets the text for multiple columns in the tree.
- *
- * @param strings the array of new strings
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setText (String[] value) {
- checkWidget ();
- if (value == null) error (SWT.ERROR_NULL_ARGUMENT);
- Rectangle bounds = getBounds (false);
- int oldRightX = bounds.x + bounds.width;
- // TODO make a smarter implementation of this
- for (int i = 0; i < value.length; i++) {
- if (value [i] != null) setText (i, value [i]);
- }
- /* horizontal bar could be affected if tree has no columns */
- if (parent.columns.length == 0) {
- bounds = getBounds (false);
- int newRightX = bounds.x + bounds.width;
- parent.updateHorizontalBar (newRightX, newRightX - oldRightX);
- }
-}
-/**
- * Sets the receiver's text at a column
- *
- * @param index the column index
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setText (int columnIndex, String value) {
- checkWidget ();
- if (value == null) error (SWT.ERROR_NULL_ARGUMENT);
- int validColumnCount = Math.max (1, parent.columns.length);
- if (!(0 <= columnIndex && columnIndex < validColumnCount)) return;
- if (value.equals (getText (columnIndex, false))) return;
- if (columnIndex == 0) {
- super.setText (value);
- } else {
- texts [columnIndex] = value;
- }
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-
- int oldWidth = textWidths [columnIndex];
- GC gc = new GC (parent);
- gc.setFont (getFont (columnIndex, false));
- computeDisplayText (columnIndex, gc);
- gc.dispose ();
- if (availableIndex == -1) return;
- if (parent.columns.length == 0) {
- Rectangle bounds = getBounds (false);
- int rightX = bounds.x + bounds.width;
- parent.updateHorizontalBar (rightX, textWidths [columnIndex] - oldWidth);
- }
- if (isInViewport ()) {
- redraw (
- getTextX (columnIndex),
- parent.getItemY (this),
- Math.max (oldWidth, textWidths [columnIndex]) + 2 * MARGIN_TEXT,
- parent.itemHeight,
- columnIndex);
- }
-}
-/*
- * Perform any internal changes necessary to reflect a changed column width.
- */
-void updateColumnWidth (TreeColumn column, GC gc) {
- int columnIndex = column.getIndex ();
- gc.setFont (getFont (columnIndex, false));
- String oldDisplayText = displayTexts [columnIndex];
- computeDisplayText (columnIndex, gc);
-
- /* the cell must be damaged if there is custom drawing being done or if the alignment is not LEFT */
- if (isInViewport ()) {
- boolean columnIsLeft = (column.style & SWT.LEFT) != 0;
- if (!columnIsLeft || parent.hooks (SWT.EraseItem) || parent.hooks (SWT.PaintItem)) {
- Rectangle cellBounds = getCellBounds (columnIndex);
- parent.redraw (cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height, false);
- } else {
- /* if the display text has changed then the cell text must be damaged in order to repaint */
- if (oldDisplayText == null || !oldDisplayText.equals (displayTexts [columnIndex])) {
- Rectangle cellBounds = getCellBounds (columnIndex);
- int textX = getTextX (columnIndex);
- parent.redraw (textX, cellBounds.y, cellBounds.x + cellBounds.width - textX, cellBounds.height, false);
- }
- }
- }
-
- for (int i = 0; i < items.length; i++) {
- items [i].updateColumnWidth (column, gc);
- }
-}
-
-/*
- * The parent's font has changed, so if this font was being used by the receiver then
- * recompute its cached text sizes using the gc argument. Pass this notification on to
- * all child items as well.
- */
-void updateFont (GC gc) {
- if (font == null) { /* receiver is using the Tree's font */
- computeDisplayTexts (gc);
- computeTextWidths (gc);
- }
- /* pass notification on to all children */
- for (int i = 0; i < items.length; i++) {
- items [i].updateFont (gc);
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Color.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Color.java
deleted file mode 100644
index e3fae9ed44..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Color.java
+++ /dev/null
@@ -1,289 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage the operating system resources that
- * implement SWT's RGB color model. To create a color you can either
- * specify the individual color components as integers in the range
- * 0 to 255 or provide an instance of an <code>RGB</code>.
- * <p>
- * Application code must explicitly invoke the <code>Color.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see RGB
- * @see Device#getSystemColor
- * @see <a href="http://www.eclipse.org/swt/snippets/#color">Color and RGB snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Color extends Resource {
- /**
- * the handle to the OS color resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public GdkColor handle;
-
-Color(Device device) {
- super(device);
-}
-
-/**
- * Constructs a new instance of this class given a device and the
- * desired red, green and blue values expressed as ints in the range
- * 0 to 255 (where 0 is black and 255 is full brightness). On limited
- * color devices, the color instance created by this call may not have
- * the same RGB values as the ones specified by the arguments. The
- * RGB values on the returned instance will be the color values of
- * the operating system color.
- * <p>
- * You must dispose the color when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param red the amount of red in the color
- * @param green the amount of green in the color
- * @param blue the amount of blue in the color
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255</li>
- * </ul>
- *
- * @see #dispose
- */
-public Color(Device device, int red, int green, int blue) {
- super(device);
- init(red, green, blue);
- init();
-}
-
-/**
- * Constructs a new instance of this class given a device and an
- * <code>RGB</code> describing the desired red, green and blue values.
- * On limited color devices, the color instance created by this call
- * may not have the same RGB values as the ones specified by the
- * argument. The RGB values on the returned instance will be the color
- * values of the operating system color.
- * <p>
- * You must dispose the color when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param rgb the RGB values of the desired color
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the rgb argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue components of the argument are not between 0 and 255</li>
- * </ul>
- *
- * @see #dispose
- */
-public Color(Device device, RGB rgb) {
- super(device);
- if (rgb == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(rgb.red, rgb.green, rgb.blue);
- init();
-}
-
-void destroy() {
- int pixel = handle.pixel;
- if (device.colorRefCount != null) {
- /* If this was the last reference, remove the color from the list */
- if (--device.colorRefCount[pixel] == 0) {
- device.gdkColors[pixel] = null;
- }
- }
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_colormap_free_colors(colormap, handle, 1);
- handle = null;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals(Object object) {
- if (object == this) return true;
- if (!(object instanceof Color)) return false;
- Color color = (Color)object;
- GdkColor gdkColor = color.handle;
- if (handle == gdkColor) return true;
- return device == color.device && handle.red == gdkColor.red &&
- handle.green == gdkColor.green && handle.blue == gdkColor.blue;
-}
-
-/**
- * Returns the amount of blue in the color, from 0 to 255.
- *
- * @return the blue component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getBlue() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (handle.blue >> 8) & 0xFF;
-}
-
-/**
- * Returns the amount of green in the color, from 0 to 255.
- *
- * @return the green component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getGreen() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (handle.green >> 8) & 0xFF;
-}
-
-/**
- * Returns the amount of red in the color, from 0 to 255.
- *
- * @return the red component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getRed() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (handle.red >> 8) & 0xFF;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode() {
- if (isDisposed()) return 0;
- return handle.red ^ handle.green ^ handle.blue;
-}
-
-/**
- * Returns an <code>RGB</code> representing the receiver.
- *
- * @return the RGB for the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public RGB getRGB () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return new RGB(getRed(), getGreen(), getBlue());
-}
-
-/**
- * Invokes platform specific functionality to allocate a new color.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Color</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param handle the handle for the color
- *
- * @private
- */
-public static Color gtk_new(Device device, GdkColor gdkColor) {
- Color color = new Color(device);
- color.handle = gdkColor;
- return color;
-}
-
-void init(int red, int green, int blue) {
- if ((red > 255) || (red < 0) ||
- (green > 255) || (green < 0) ||
- (blue > 255) || (blue < 0)) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- GdkColor gdkColor = new GdkColor();
- gdkColor.red = (short)((red & 0xFF) | ((red & 0xFF) << 8));
- gdkColor.green = (short)((green & 0xFF) | ((green & 0xFF) << 8));
- gdkColor.blue = (short)((blue & 0xFF) | ((blue & 0xFF) << 8));
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- if (!OS.gdk_colormap_alloc_color(colormap, gdkColor, true, true)) {
- /* Allocate black. */
- gdkColor = new GdkColor();
- OS.gdk_colormap_alloc_color(colormap, gdkColor, true, true);
- }
- handle = gdkColor;
- if (device.colorRefCount != null) {
- /* Make a copy of the color to put in the colors array */
- GdkColor colorCopy = new GdkColor();
- colorCopy.red = handle.red;
- colorCopy.green = handle.green;
- colorCopy.blue = handle.blue;
- colorCopy.pixel = handle.pixel;
- device.gdkColors[colorCopy.pixel] = colorCopy;
- device.colorRefCount[colorCopy.pixel]++;
- }
-}
-
-/**
- * Returns <code>true</code> if the color has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the color.
- * When a color has been disposed, it is an error to
- * invoke any other method using the color.
- *
- * @return <code>true</code> when the color is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == null;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Color {*DISPOSED*}";
- return "Color {" + getRed() + ", " + getGreen() + ", " + getBlue() + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Cursor.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Cursor.java
deleted file mode 100644
index ce5768c244..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Cursor.java
+++ /dev/null
@@ -1,527 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gtk.*;
-
-/**
- * Instances of this class manage operating system resources that
- * specify the appearance of the on-screen pointer. To create a
- * cursor you specify the device and either a simple cursor style
- * describing one of the standard operating system provided cursors
- * or the image and mask data for the desired appearance.
- * <p>
- * Application code must explicitly invoke the <code>Cursor.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>
- * CURSOR_ARROW, CURSOR_WAIT, CURSOR_CROSS, CURSOR_APPSTARTING, CURSOR_HELP,
- * CURSOR_SIZEALL, CURSOR_SIZENESW, CURSOR_SIZENS, CURSOR_SIZENWSE, CURSOR_SIZEWE,
- * CURSOR_SIZEN, CURSOR_SIZES, CURSOR_SIZEE, CURSOR_SIZEW, CURSOR_SIZENE, CURSOR_SIZESE,
- * CURSOR_SIZESW, CURSOR_SIZENW, CURSOR_UPARROW, CURSOR_IBEAM, CURSOR_NO, CURSOR_HAND
- * </dd>
- * </dl>
- * <p>
- * Note: Only one of the above styles may be specified.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#cursor">Cursor snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Cursor extends Resource {
- /**
- * the handle to the OS cursor resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
-
- static final byte[] APPSTARTING_SRC = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
- 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
- 0x7c, 0x00, 0x00, 0x00, (byte)0xfc, 0x00, 0x00, 0x00, (byte)0xfc, 0x01, 0x00, 0x00,
- (byte)0xfc, 0x3b, 0x00, 0x00, 0x7c, 0x38, 0x00, 0x00, 0x6c, 0x54, 0x00, 0x00,
- (byte)0xc4, (byte)0xdc, 0x00, 0x00, (byte)0xc0, 0x44, 0x00, 0x00, (byte)0x80, 0x39, 0x00, 0x00,
- (byte)0x80, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-
- static final byte[] APPSTARTING_MASK = {
- 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00,
- 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00,
- (byte)0xfe, 0x00, 0x00, 0x00, (byte)0xfe, 0x01, 0x00, 0x00, (byte)0xfe, 0x3b, 0x00, 0x00,
- (byte)0xfe, 0x7f, 0x00, 0x00, (byte)0xfe, 0x7f, 0x00, 0x00, (byte)0xfe, (byte)0xfe, 0x00, 0x00,
- (byte)0xee, (byte)0xff, 0x01, 0x00, (byte)0xe4, (byte)0xff, 0x00, 0x00, (byte)0xc0, 0x7f, 0x00, 0x00,
- (byte)0xc0, 0x7f, 0x00, 0x00, (byte)0x80, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-
-Cursor (Device device) {
- super(device);
-}
-
-/**
- * Constructs a new cursor given a device and a style
- * constant describing the desired cursor appearance.
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param style the style of cursor to allocate
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - when an unknown style is specified</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- *
- * @see SWT#CURSOR_ARROW
- * @see SWT#CURSOR_WAIT
- * @see SWT#CURSOR_CROSS
- * @see SWT#CURSOR_APPSTARTING
- * @see SWT#CURSOR_HELP
- * @see SWT#CURSOR_SIZEALL
- * @see SWT#CURSOR_SIZENESW
- * @see SWT#CURSOR_SIZENS
- * @see SWT#CURSOR_SIZENWSE
- * @see SWT#CURSOR_SIZEWE
- * @see SWT#CURSOR_SIZEN
- * @see SWT#CURSOR_SIZES
- * @see SWT#CURSOR_SIZEE
- * @see SWT#CURSOR_SIZEW
- * @see SWT#CURSOR_SIZENE
- * @see SWT#CURSOR_SIZESE
- * @see SWT#CURSOR_SIZESW
- * @see SWT#CURSOR_SIZENW
- * @see SWT#CURSOR_UPARROW
- * @see SWT#CURSOR_IBEAM
- * @see SWT#CURSOR_NO
- * @see SWT#CURSOR_HAND
- */
-public Cursor(Device device, int style) {
- super(device);
- int shape = 0;
- switch (style) {
- case SWT.CURSOR_APPSTARTING: break;
- case SWT.CURSOR_ARROW: shape = OS.GDK_LEFT_PTR; break;
- case SWT.CURSOR_WAIT: shape = OS.GDK_WATCH; break;
- case SWT.CURSOR_CROSS: shape = OS.GDK_CROSS; break;
- case SWT.CURSOR_HAND: shape = OS.GDK_HAND2; break;
- case SWT.CURSOR_HELP: shape = OS.GDK_QUESTION_ARROW; break;
- case SWT.CURSOR_SIZEALL: shape = OS.GDK_FLEUR; break;
- case SWT.CURSOR_SIZENESW: shape = OS.GDK_SIZING; break;
- case SWT.CURSOR_SIZENS: shape = OS.GDK_DOUBLE_ARROW; break;
- case SWT.CURSOR_SIZENWSE: shape = OS.GDK_SIZING; break;
- case SWT.CURSOR_SIZEWE: shape = OS.GDK_SB_H_DOUBLE_ARROW; break;
- case SWT.CURSOR_SIZEN: shape = OS.GDK_TOP_SIDE; break;
- case SWT.CURSOR_SIZES: shape = OS.GDK_BOTTOM_SIDE; break;
- case SWT.CURSOR_SIZEE: shape = OS.GDK_RIGHT_SIDE; break;
- case SWT.CURSOR_SIZEW: shape = OS.GDK_LEFT_SIDE; break;
- case SWT.CURSOR_SIZENE: shape = OS.GDK_TOP_RIGHT_CORNER; break;
- case SWT.CURSOR_SIZESE: shape = OS.GDK_BOTTOM_RIGHT_CORNER; break;
- case SWT.CURSOR_SIZESW: shape = OS.GDK_BOTTOM_LEFT_CORNER; break;
- case SWT.CURSOR_SIZENW: shape = OS.GDK_TOP_LEFT_CORNER; break;
- case SWT.CURSOR_UPARROW: shape = OS.GDK_SB_UP_ARROW; break;
- case SWT.CURSOR_IBEAM: shape = OS.GDK_XTERM; break;
- case SWT.CURSOR_NO: shape = OS.GDK_X_CURSOR; break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (shape == 0 && style == SWT.CURSOR_APPSTARTING) {
- handle = createCursor(APPSTARTING_SRC, APPSTARTING_MASK, 32, 32, 2, 2, true);
- } else {
- handle = OS.gdk_cursor_new(shape);
- }
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new cursor given a device, image and mask
- * data describing the desired cursor appearance, and the x
- * and y coordinates of the <em>hotspot</em> (that is, the point
- * within the area covered by the cursor which is considered
- * to be where the on-screen pointer is "pointing").
- * <p>
- * The mask data is allowed to be null, but in this case the source
- * must be an ImageData representing an icon that specifies both
- * color data and mask data.
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param source the color data for the cursor
- * @param mask the mask data for the cursor (or null)
- * @param hotspotX the x coordinate of the cursor's hotspot
- * @param hotspotY the y coordinate of the cursor's hotspot
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the source is null</li>
- * <li>ERROR_NULL_ARGUMENT - if the mask is null and the source does not have a mask</li>
- * <li>ERROR_INVALID_ARGUMENT - if the source and the mask are not the same
- * size, or if the hotspot is outside the bounds of the image</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- */
-public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (mask == null) {
- if (!(source.getTransparencyType() == SWT.TRANSPARENCY_MASK)) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- mask = source.getTransparencyMask();
- }
- /* Check the bounds. Mask must be the same size as source */
- if (mask.width != source.width || mask.height != source.height) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- /* Check the hotspots */
- if (hotspotX >= source.width || hotspotX < 0 ||
- hotspotY >= source.height || hotspotY < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- /* Convert depth to 1 */
- source = ImageData.convertMask(source);
- mask = ImageData.convertMask(mask);
-
- /* Swap the bits in each byte and convert to appropriate scanline pad */
- byte[] sourceData = new byte[source.data.length];
- byte[] maskData = new byte[mask.data.length];
- byte[] data = source.data;
- for (int i = 0; i < data.length; i++) {
- byte s = data[i];
- sourceData[i] = (byte)(((s & 0x80) >> 7) |
- ((s & 0x40) >> 5) |
- ((s & 0x20) >> 3) |
- ((s & 0x10) >> 1) |
- ((s & 0x08) << 1) |
- ((s & 0x04) << 3) |
- ((s & 0x02) << 5) |
- ((s & 0x01) << 7));
- sourceData[i] = (byte) ~sourceData[i];
- }
- sourceData = ImageData.convertPad(sourceData, source.width, source.height, source.depth, source.scanlinePad, 1);
- data = mask.data;
- for (int i = 0; i < data.length; i++) {
- byte s = data[i];
- maskData[i] = (byte)(((s & 0x80) >> 7) |
- ((s & 0x40) >> 5) |
- ((s & 0x20) >> 3) |
- ((s & 0x10) >> 1) |
- ((s & 0x08) << 1) |
- ((s & 0x04) << 3) |
- ((s & 0x02) << 5) |
- ((s & 0x01) << 7));
- maskData[i] = (byte) ~maskData[i];
- }
- maskData = ImageData.convertPad(maskData, mask.width, mask.height, mask.depth, mask.scanlinePad, 1);
- handle = createCursor(maskData, sourceData, source.width, source.height, hotspotX, hotspotY, true);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new cursor given a device, image data describing
- * the desired cursor appearance, and the x and y coordinates of
- * the <em>hotspot</em> (that is, the point within the area
- * covered by the cursor which is considered to be where the
- * on-screen pointer is "pointing").
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param source the image data for the cursor
- * @param hotspotX the x coordinate of the cursor's hotspot
- * @param hotspotY the y coordinate of the cursor's hotspot
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the hotspot is outside the bounds of the
- * image</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- *
- * @since 3.0
- */
-public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (hotspotX >= source.width || hotspotX < 0 ||
- hotspotY >= source.height || hotspotY < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int /*long*/ display = 0;
- if (OS.GTK_VERSION >= OS.VERSION(2, 4, 0) && OS.gdk_display_supports_cursor_color(display = OS.gdk_display_get_default ())) {
- int width = source.width;
- int height = source.height;
- PaletteData palette = source.palette;
- int /*long*/ pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, true, 8, width, height);
- if (pixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int stride = OS.gdk_pixbuf_get_rowstride(pixbuf);
- int /*long*/ data = OS.gdk_pixbuf_get_pixels(pixbuf);
- byte[] buffer = source.data;
- if (!palette.isDirect || source.depth != 24 || stride != source.bytesPerLine || palette.redMask != 0xFF000000 || palette.greenMask != 0xFF0000 || palette.blueMask != 0xFF00) {
- buffer = new byte[source.width * source.height * 4];
- if (palette.isDirect) {
- ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, palette.redMask, palette.greenMask, palette.blueMask,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- buffer, 32, source.width * 4, ImageData.MSB_FIRST, 0, 0, source.width, source.height, 0xFF000000, 0xFF0000, 0xFF00,
- false, false);
- } else {
- RGB[] rgbs = palette.getRGBs();
- int length = rgbs.length;
- byte[] srcReds = new byte[length];
- byte[] srcGreens = new byte[length];
- byte[] srcBlues = new byte[length];
- for (int i = 0; i < rgbs.length; i++) {
- RGB rgb = rgbs[i];
- if (rgb == null) continue;
- srcReds[i] = (byte)rgb.red;
- srcGreens[i] = (byte)rgb.green;
- srcBlues[i] = (byte)rgb.blue;
- }
- ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, srcReds, srcGreens, srcBlues,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- buffer, 32, source.width * 4, ImageData.MSB_FIRST, 0, 0, source.width, source.height, 0xFF000000, 0xFF0000, 0xFF00,
- false, false);
- }
- if (source.maskData != null || source.transparentPixel != -1) {
- ImageData mask = source.getTransparencyMask();
- byte[] maskData = mask.data;
- int maskBpl = mask.bytesPerLine;
- int offset = 3, maskOffset = 0;
- for (int y = 0; y<source.height; y++) {
- for (int x = 0; x<source.width; x++) {
- buffer[offset] = ((maskData[maskOffset + (x >> 3)]) & (1 << (7 - (x & 0x7)))) != 0 ? (byte)0xff : 0;
- offset += 4;
- }
- maskOffset += maskBpl;
- }
- } else if (source.alpha != -1) {
- byte alpha = (byte)source.alpha;
- for (int i=3; i<buffer.length; i+=4) {
- buffer[i] = alpha;
- }
- } else if (source.alphaData != null) {
- byte[] alphaData = source.alphaData;
- for (int i=3; i<buffer.length; i+=4) {
- buffer[i] = alphaData[i/4];
- }
- }
- }
- OS.memmove(data, buffer, stride * height);
- handle = OS.gdk_cursor_new_from_pixbuf(display, pixbuf, hotspotX, hotspotY);
- OS.g_object_unref(pixbuf);
- } else {
-
- ImageData mask = source.getTransparencyMask();
-
- /* Ensure depth is equal to 1 */
- if (source.depth > 1) {
- /* Create a destination image with no data */
- ImageData newSource = new ImageData(
- source.width, source.height, 1, ImageData.bwPalette(),
- 1, null, 0, null, null, -1, -1, 0, 0, 0, 0, 0);
-
- byte[] newReds = new byte[]{0, (byte)255}, newGreens = newReds, newBlues = newReds;
-
- /* Convert the source to a black and white image of depth 1 */
- PaletteData palette = source.palette;
- if (palette.isDirect) {
- ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, palette.redMask, palette.greenMask, palette.blueMask,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- newSource.data, newSource.depth, newSource.bytesPerLine, newSource.getByteOrder(), 0, 0, newSource.width, newSource.height, newReds, newGreens, newBlues,
- false, false);
- } else {
- RGB[] rgbs = palette.getRGBs();
- int length = rgbs.length;
- byte[] srcReds = new byte[length];
- byte[] srcGreens = new byte[length];
- byte[] srcBlues = new byte[length];
- for (int i = 0; i < rgbs.length; i++) {
- RGB rgb = rgbs[i];
- if (rgb == null) continue;
- srcReds[i] = (byte)rgb.red;
- srcGreens[i] = (byte)rgb.green;
- srcBlues[i] = (byte)rgb.blue;
- }
- ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, srcReds, srcGreens, srcBlues,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- newSource.data, newSource.depth, newSource.bytesPerLine, newSource.getByteOrder(), 0, 0, newSource.width, newSource.height, newReds, newGreens, newBlues,
- false, false);
- }
- source = newSource;
- }
-
- /* Swap the bits in each byte and convert to appropriate scanline pad */
- byte[] sourceData = new byte[source.data.length];
- byte[] maskData = new byte[mask.data.length];
- byte[] data = source.data;
- for (int i = 0; i < data.length; i++) {
- byte s = data[i];
- sourceData[i] = (byte)(((s & 0x80) >> 7) |
- ((s & 0x40) >> 5) |
- ((s & 0x20) >> 3) |
- ((s & 0x10) >> 1) |
- ((s & 0x08) << 1) |
- ((s & 0x04) << 3) |
- ((s & 0x02) << 5) |
- ((s & 0x01) << 7));
- }
- sourceData = ImageData.convertPad(sourceData, source.width, source.height, source.depth, source.scanlinePad, 1);
- data = mask.data;
- for (int i = 0; i < data.length; i++) {
- byte s = data[i];
- maskData[i] = (byte)(((s & 0x80) >> 7) |
- ((s & 0x40) >> 5) |
- ((s & 0x20) >> 3) |
- ((s & 0x10) >> 1) |
- ((s & 0x08) << 1) |
- ((s & 0x04) << 3) |
- ((s & 0x02) << 5) |
- ((s & 0x01) << 7));
- }
- maskData = ImageData.convertPad(maskData, mask.width, mask.height, mask.depth, mask.scanlinePad, 1);
- handle = createCursor(sourceData, maskData, source.width, source.height, hotspotX, hotspotY, false);
- }
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-int /*long*/ createCursor(byte[] sourceData, byte[] maskData, int width, int height, int hotspotX, int hotspotY, boolean reverse) {
- int /*long*/ sourcePixmap = OS.gdk_bitmap_create_from_data(0, sourceData, width, height);
- int /*long*/ maskPixmap = OS.gdk_bitmap_create_from_data(0, maskData, width, height);
- int /*long*/ cursor = 0;
- if (sourcePixmap != 0 && maskPixmap != 0) {
- GdkColor foreground = new GdkColor();
- if (!reverse) foreground.red = foreground.green = foreground.blue = (short)0xFFFF;
- GdkColor background = new GdkColor();
- if (reverse) background.red = background.green = background.blue = (short)0xFFFF;
- cursor = OS.gdk_cursor_new_from_pixmap (sourcePixmap, maskPixmap, foreground, background, hotspotX, hotspotY);
- }
- if (sourcePixmap != 0) OS.g_object_unref (sourcePixmap);
- if (maskPixmap != 0) OS.g_object_unref (maskPixmap);
- return cursor;
-}
-
-void destroy() {
- OS.gdk_cursor_destroy(handle);
- handle = 0;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals(Object object) {
- if (object == this) return true;
- if (!(object instanceof Cursor)) return false;
- Cursor cursor = (Cursor) object;
- return device == cursor.device && handle == cursor.handle;
-}
-
-/**
- * Invokes platform specific functionality to allocate a new cursor.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Cursor</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param handle the handle for the cursor
- *
- * @private
- */
-public static Cursor gtk_new(Device device, int /*long*/ handle) {
- Cursor cursor = new Cursor(device);
- cursor.handle = handle;
- return cursor;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode() {
- return (int)/*64*/handle;
-}
-
-/**
- * Returns <code>true</code> if the cursor has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the cursor.
- * When a cursor has been disposed, it is an error to
- * invoke any other method using the cursor.
- *
- * @return <code>true</code> when the cursor is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Cursor {*DISPOSED*}";
- return "Cursor {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java
deleted file mode 100644
index fbacfcf587..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java
+++ /dev/null
@@ -1,902 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-
-/**
- * This class is the abstract superclass of all device objects,
- * such as the Display device and the Printer device. Devices
- * can have a graphics context (GC) created for them, and they
- * can be drawn on by sending messages to the associated GC.
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class Device implements Drawable {
- /**
- * the handle to the X Display
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked protected only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- protected int /*long*/ xDisplay;
- int /*long*/ shellHandle;
-
- /* Debugging */
- public static boolean DEBUG;
- boolean debug = DEBUG;
- boolean tracking = DEBUG;
- Error [] errors;
- Object [] objects;
- Object trackingLock;
-
- /* Colormap and reference count */
- GdkColor [] gdkColors;
- int [] colorRefCount;
-
- /* Disposed flag */
- boolean disposed;
-
- /* Warning and Error Handlers */
- int /*long*/ logProc;
- Callback logCallback;
- //NOT DONE - get list of valid names
- String [] log_domains = {"GLib-GObject", "GLib", "GObject", "Pango", "ATK", "GdkPixbuf", "Gdk", "Gtk", "GnomeVFS"};
- int [] handler_ids = new int [log_domains.length];
- int warningLevel;
-
- /* X Warning and Error Handlers */
- static Callback XErrorCallback, XIOErrorCallback;
- static int /*long*/ XErrorProc, XIOErrorProc, XNullErrorProc, XNullIOErrorProc;
- static Device[] Devices = new Device[4];
-
- /*
- * The following colors are listed in the Windows
- * Programmer's Reference as the colors in the default
- * palette.
- */
- Color COLOR_BLACK, COLOR_DARK_RED, COLOR_DARK_GREEN, COLOR_DARK_YELLOW, COLOR_DARK_BLUE;
- Color COLOR_DARK_MAGENTA, COLOR_DARK_CYAN, COLOR_GRAY, COLOR_DARK_GRAY, COLOR_RED;
- Color COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE;
-
- /* System Font */
- Font systemFont;
-
- int /*long*/ emptyTab;
-
- boolean useXRender;
-
- static boolean CAIRO_LOADED;
-
- /*
- * TEMPORARY CODE. When a graphics object is
- * created and the device parameter is null,
- * the current Display is used. This presents
- * a problem because SWT graphics does not
- * reference classes in SWT widgets. The correct
- * fix is to remove this feature. Unfortunately,
- * too many application programs rely on this
- * feature.
- */
- protected static Device CurrentDevice;
- protected static Runnable DeviceFinder;
- static {
- try {
- Class.forName ("org.eclipse.swt.widgets.Display");
- } catch (ClassNotFoundException e) {}
- }
-
-/*
-* TEMPORARY CODE.
-*/
-static synchronized Device getDevice () {
- if (DeviceFinder != null) DeviceFinder.run();
- Device device = CurrentDevice;
- CurrentDevice = null;
- return device;
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * You must dispose the device when it is no longer required.
- * </p>
- *
- * @see #create
- * @see #init
- *
- * @since 3.1
- */
-public Device() {
- this(null);
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * You must dispose the device when it is no longer required.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #create
- * @see #init
- * @see DeviceData
- */
-public Device(DeviceData data) {
- synchronized (Device.class) {
- if (data != null) {
- debug = data.debug;
- tracking = data.tracking;
- }
- if (tracking) {
- errors = new Error [128];
- objects = new Object [128];
- trackingLock = new Object ();
- }
- create (data);
- init ();
- register (this);
- }
-}
-
-void checkCairo() {
- if (CAIRO_LOADED) return;
- try {
- /* Check if cairo is available on the system */
- byte[] buffer = Converter.wcsToMbcs(null, "libcairo.so.2", true);
- int /*long*/ libcairo = OS.dlopen(buffer, OS.RTLD_LAZY);
- if (libcairo != 0) {
- OS.dlclose(libcairo);
- } else {
- try {
- System.loadLibrary("cairo-swt");
- } catch (UnsatisfiedLinkError e) {
- /* Ignore problems loading the fallback library */
- }
- }
- Class.forName("org.eclipse.swt.internal.cairo.Cairo");
- CAIRO_LOADED = true;
- } catch (Throwable t) {
- SWT.error(SWT.ERROR_NO_GRAPHICS_LIBRARY, t, " [Cairo is required]");
- }
-}
-
-/**
- * Throws an <code>SWTException</code> if the receiver can not
- * be accessed by the caller. This may include both checks on
- * the state of the receiver and more generally on the entire
- * execution context. This method <em>should</em> be called by
- * device implementors to enforce the standard SWT invariants.
- * <p>
- * Currently, it is an error to invoke any method (other than
- * <code>isDisposed()</code> and <code>dispose()</code>) on a
- * device that has had its <code>dispose()</code> method called.
- * </p><p>
- * In future releases of SWT, there may be more or fewer error
- * checks and exceptions may be thrown for different reasons.
- * <p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-protected void checkDevice () {
- if (disposed) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
-}
-
-/**
- * Creates the device in the operating system. If the device
- * does not have a handle, this method may do nothing depending
- * on the device.
- * <p>
- * This method is called before <code>init</code>.
- * </p><p>
- * Subclasses are supposed to reimplement this method and not
- * call the <code>super</code> implementation.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #init
- */
-protected void create (DeviceData data) {
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the receiver. After this method has been invoked, the receiver
- * will answer <code>true</code> when sent the message
- * <code>isDisposed()</code>.
- *
- * @see #release
- * @see #destroy
- * @see #checkDevice
- */
-public void dispose () {
- synchronized (Device.class) {
- if (isDisposed()) return;
- checkDevice ();
- release ();
- destroy ();
- deregister (this);
- xDisplay = 0;
- disposed = true;
- if (tracking) {
- synchronized (trackingLock) {
- objects = null;
- errors = null;
- trackingLock = null;
- }
- }
- }
-}
-
-void dispose_Object (Object object) {
- synchronized (trackingLock) {
- for (int i=0; i<objects.length; i++) {
- if (objects [i] == object) {
- objects [i] = null;
- errors [i] = null;
- return;
- }
- }
- }
-}
-
-static synchronized Device findDevice (int /*long*/ xDisplay) {
- for (int i=0; i<Devices.length; i++) {
- Device device = Devices [i];
- if (device != null && device.xDisplay == xDisplay) {
- return device;
- }
- }
- return null;
-}
-
-synchronized static void deregister (Device device) {
- for (int i=0; i<Devices.length; i++) {
- if (device == Devices [i]) Devices [i] = null;
- }
-}
-
-/**
- * Destroys the device in the operating system and releases
- * the device's handle. If the device does not have a handle,
- * this method may do nothing depending on the device.
- * <p>
- * This method is called after <code>release</code>.
- * </p><p>
- * Subclasses are supposed to reimplement this method and not
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #dispose
- * @see #release
- */
-protected void destroy () {
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location.
- *
- * @return the bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkDevice ();
- return new Rectangle(0, 0, 0, 0);
-}
-
-/**
- * Returns a <code>DeviceData</code> based on the receiver.
- * Modifications made to this <code>DeviceData</code> will not
- * affect the receiver.
- *
- * @return a <code>DeviceData</code> containing the device's data and attributes
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see DeviceData
- */
-public DeviceData getDeviceData () {
- checkDevice();
- DeviceData data = new DeviceData ();
- data.debug = debug;
- data.tracking = tracking;
- if (tracking) {
- synchronized (trackingLock) {
- int count = 0, length = objects.length;
- for (int i=0; i<length; i++) {
- if (objects [i] != null) count++;
- }
- int index = 0;
- data.objects = new Object [count];
- data.errors = new Error [count];
- for (int i=0; i<length; i++) {
- if (objects [i] != null) {
- data.objects [index] = objects [i];
- data.errors [index] = errors [i];
- index++;
- }
- }
- }
- } else {
- data.objects = new Object [0];
- data.errors = new Error [0];
- }
- return data;
-}
-
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data.
- *
- * @return the client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getBounds
- */
-public Rectangle getClientArea () {
- checkDevice ();
- return getBounds ();
-}
-
-/**
- * Returns the bit depth of the screen, which is the number of
- * bits it takes to represent the number of unique colors that
- * the screen is currently capable of displaying. This number
- * will typically be one of 1, 8, 15, 16, 24 or 32.
- *
- * @return the depth of the screen
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getDepth () {
- checkDevice ();
- return 0;
-}
-
-/**
- * Returns a point whose x coordinate is the horizontal
- * dots per inch of the display, and whose y coordinate
- * is the vertical dots per inch of the display.
- *
- * @return the horizontal and vertical DPI
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point getDPI () {
- checkDevice ();
- return new Point (72, 72);
-}
-
-/**
- * Returns <code>FontData</code> objects which describe
- * the fonts that match the given arguments. If the
- * <code>faceName</code> is null, all fonts will be returned.
- *
- * @param faceName the name of the font to look for, or null
- * @param scalable if true only scalable fonts are returned, otherwise only non-scalable fonts are returned.
- * @return the matching font data
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontData[] getFontList (String faceName, boolean scalable) {
- checkDevice ();
- if (!scalable) return new FontData[0];
- int /*long*/[] family = new int /*long*/[1];
- int /*long*/[] face = new int /*long*/[1];
- int /*long*/[] families = new int /*long*/[1];
- int[] n_families = new int[1];
- int /*long*/[] faces = new int /*long*/[1];
- int[] n_faces = new int[1];
- int /*long*/ context = OS.gdk_pango_context_get();
- OS.pango_context_list_families(context, families, n_families);
- int nFds = 0;
- FontData[] fds = new FontData[faceName != null ? 4 : n_families[0]];
- for (int i=0; i<n_families[0]; i++) {
- OS.memmove(family, families[0] + i * OS.PTR_SIZEOF, OS.PTR_SIZEOF);
- boolean match = true;
- if (faceName != null) {
- int /*long*/ familyName = OS.pango_font_family_get_name(family[0]);
- int length = OS.strlen(familyName);
- byte[] buffer = new byte[length];
- OS.memmove(buffer, familyName, length);
- String name = new String(Converter.mbcsToWcs(null, buffer));
- match = Compatibility.equalsIgnoreCase(faceName, name);
- }
- if (match) {
- OS.pango_font_family_list_faces(family[0], faces, n_faces);
- for (int j=0; j<n_faces[0]; j++) {
- OS.memmove(face, faces[0] + j * OS.PTR_SIZEOF, OS.PTR_SIZEOF);
- int /*long*/ fontDesc = OS.pango_font_face_describe(face[0]);
- Font font = Font.gtk_new(this, fontDesc);
- FontData data = font.getFontData()[0];
- if (nFds == fds.length) {
- FontData[] newFds = new FontData[fds.length + n_families[0]];
- System.arraycopy(fds, 0, newFds, 0, nFds);
- fds = newFds;
- }
- fds[nFds++] = data;
- OS.pango_font_description_free(fontDesc);
- }
- OS.g_free(faces[0]);
- if (faceName != null) break;
- }
- }
- OS.g_free(families[0]);
- OS.g_object_unref(context);
- if (nFds == fds.length) return fds;
- FontData[] result = new FontData[nFds];
- System.arraycopy(fds, 0, result, 0, nFds);
- return result;
-}
-
-/**
- * Returns the matching standard color for the given
- * constant, which should be one of the color constants
- * specified in class <code>SWT</code>. Any value other
- * than one of the SWT color constants which is passed
- * in will result in the color black. This color should
- * not be freed because it was allocated by the system,
- * not the application.
- *
- * @param id the color constant
- * @return the matching color
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT
- */
-public Color getSystemColor (int id) {
- checkDevice ();
- switch (id) {
- case SWT.COLOR_BLACK: return COLOR_BLACK;
- case SWT.COLOR_DARK_RED: return COLOR_DARK_RED;
- case SWT.COLOR_DARK_GREEN: return COLOR_DARK_GREEN;
- case SWT.COLOR_DARK_YELLOW: return COLOR_DARK_YELLOW;
- case SWT.COLOR_DARK_BLUE: return COLOR_DARK_BLUE;
- case SWT.COLOR_DARK_MAGENTA: return COLOR_DARK_MAGENTA;
- case SWT.COLOR_DARK_CYAN: return COLOR_DARK_CYAN;
- case SWT.COLOR_GRAY: return COLOR_GRAY;
- case SWT.COLOR_DARK_GRAY: return COLOR_DARK_GRAY;
- case SWT.COLOR_RED: return COLOR_RED;
- case SWT.COLOR_GREEN: return COLOR_GREEN;
- case SWT.COLOR_YELLOW: return COLOR_YELLOW;
- case SWT.COLOR_BLUE: return COLOR_BLUE;
- case SWT.COLOR_MAGENTA: return COLOR_MAGENTA;
- case SWT.COLOR_CYAN: return COLOR_CYAN;
- case SWT.COLOR_WHITE: return COLOR_WHITE;
- }
- return COLOR_BLACK;
-}
-
-/**
- * Returns a reasonable font for applications to use.
- * On some platforms, this will match the "default font"
- * or "system font" if such can be found. This font
- * should not be freed because it was allocated by the
- * system, not the application.
- * <p>
- * Typically, applications which want the default look
- * should simply not set the font on the widgets they
- * create. Widgets are always created with the correct
- * default font for the class of user-interface component
- * they represent.
- * </p>
- *
- * @return a font
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getSystemFont () {
- checkDevice ();
- return systemFont;
-}
-
-/**
- * Returns <code>true</code> if the underlying window system prints out
- * warning messages on the console, and <code>setWarnings</code>
- * had previously been called with <code>true</code>.
- *
- * @return <code>true</code>if warnings are being handled, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean getWarnings () {
- checkDevice ();
- return warningLevel == 0;
-}
-
-/**
- * Initializes any internal resources needed by the
- * device.
- * <p>
- * This method is called after <code>create</code>.
- * </p><p>
- * If subclasses reimplement this method, they must
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #create
- */
-protected void init () {
- if (xDisplay != 0) {
- int[] event_basep = new int[1], error_basep = new int [1];
- if (OS.XRenderQueryExtension (xDisplay, event_basep, error_basep)) {
- int[] major_versionp = new int[1], minor_versionp = new int [1];
- OS.XRenderQueryVersion (xDisplay, major_versionp, minor_versionp);
- useXRender = major_versionp[0] > 0 || (major_versionp[0] == 0 && minor_versionp[0] >= 8);
- }
- }
-
- if (debug) {
- if (xDisplay != 0) {
- /* Create the warning and error callbacks */
- Class clazz = getClass ();
- synchronized (clazz) {
- int index = 0;
- while (index < Devices.length) {
- if (Devices [index] != null) break;
- index++;
- }
- if (index == Devices.length) {
- XErrorCallback = new Callback (clazz, "XErrorProc", 2);
- XNullErrorProc = XErrorCallback.getAddress ();
- if (XNullErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- XIOErrorCallback = new Callback (clazz, "XIOErrorProc", 1);
- XNullIOErrorProc = XIOErrorCallback.getAddress ();
- if (XNullIOErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- XErrorProc = OS.XSetErrorHandler (XNullErrorProc);
- XIOErrorProc = OS.XSetIOErrorHandler (XNullIOErrorProc);
- }
- }
- OS.XSynchronize (xDisplay, true);
- }
- }
-
- /* Create GTK warnings and error callbacks */
- if (xDisplay != 0) {
- logCallback = new Callback (this, "logProc", 4);
- logProc = logCallback.getAddress ();
- if (logProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- /* Set GTK warning and error handlers */
- if (debug) {
- int flags = OS.G_LOG_LEVEL_MASK | OS.G_LOG_FLAG_FATAL | OS.G_LOG_FLAG_RECURSION;
- for (int i=0; i<log_domains.length; i++) {
- byte [] log_domain = Converter.wcsToMbcs (null, log_domains [i], true);
- handler_ids [i] = OS.g_log_set_handler (log_domain, flags, logProc, 0);
- }
- }
- }
-
- /* Create the standard colors */
- COLOR_BLACK = new Color (this, 0,0,0);
- COLOR_DARK_RED = new Color (this, 0x80,0,0);
- COLOR_DARK_GREEN = new Color (this, 0,0x80,0);
- COLOR_DARK_YELLOW = new Color (this, 0x80,0x80,0);
- COLOR_DARK_BLUE = new Color (this, 0,0,0x80);
- COLOR_DARK_MAGENTA = new Color (this, 0x80,0,0x80);
- COLOR_DARK_CYAN = new Color (this, 0,0x80,0x80);
- COLOR_GRAY = new Color (this, 0xC0,0xC0,0xC0);
- COLOR_DARK_GRAY = new Color (this, 0x80,0x80,0x80);
- COLOR_RED = new Color (this, 0xFF,0,0);
- COLOR_GREEN = new Color (this, 0,0xFF,0);
- COLOR_YELLOW = new Color (this, 0xFF,0xFF,0);
- COLOR_BLUE = new Color (this, 0,0,0xFF);
- COLOR_MAGENTA = new Color (this, 0xFF,0,0xFF);
- COLOR_CYAN = new Color (this, 0,0xFF,0xFF);
- COLOR_WHITE = new Color (this, 0xFF,0xFF,0xFF);
-
- emptyTab = OS.pango_tab_array_new(1, false);
- if (emptyTab == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.pango_tab_array_set_tab(emptyTab, 0, OS.PANGO_TAB_LEFT, 1);
-
- shellHandle = OS.gtk_window_new(OS.GTK_WINDOW_TOPLEVEL);
- if (shellHandle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.gtk_widget_realize(shellHandle);
-
- /* Initialize the system font slot */
- systemFont = getSystemFont ();
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Device</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public abstract int /*long*/ internal_new_GC (GCData data);
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Device</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public abstract void internal_dispose_GC (int /*long*/ handle, GCData data);
-
-/**
- * Returns <code>true</code> if the device has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the device.
- * When a device has been disposed, it is an error to
- * invoke any other method using the device.
- *
- * @return <code>true</code> when the device is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- synchronized (Device.class) {
- return disposed;
- }
-}
-
-/**
- * Loads the font specified by a file. The font will be
- * present in the list of fonts available to the application.
- *
- * @param path the font file path
- * @return whether the font was successfully loaded
- *
- * @exception SWTException <ul>
- * <li>ERROR_NULL_ARGUMENT - if path is null</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Font
- *
- * @since 3.3
- */
-public boolean loadFont (String path) {
- checkDevice();
- if (path == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, path, true);
- return OS.FcConfigAppFontAddFile (0, buffer);
-}
-
-int /*long*/ logProc (int /*long*/ log_domain, int /*long*/ log_level, int /*long*/ message, int /*long*/ user_data) {
- if (warningLevel == 0) {
- if (DEBUG || debug) {
- new Error ().printStackTrace ();
- }
- OS.g_log_default_handler (log_domain, (int)/*64*/log_level, message, 0);
- }
- return 0;
-}
-
-void new_Object (Object object) {
- synchronized (trackingLock) {
- for (int i=0; i<objects.length; i++) {
- if (objects [i] == null) {
- objects [i] = object;
- errors [i] = new Error ();
- return;
- }
- }
- Object [] newObjects = new Object [objects.length + 128];
- System.arraycopy (objects, 0, newObjects, 0, objects.length);
- newObjects [objects.length] = object;
- objects = newObjects;
- Error [] newErrors = new Error [errors.length + 128];
- System.arraycopy (errors, 0, newErrors, 0, errors.length);
- newErrors [errors.length] = new Error ();
- errors = newErrors;
- }
-}
-
-static synchronized void register (Device device) {
- for (int i=0; i<Devices.length; i++) {
- if (Devices [i] == null) {
- Devices [i] = device;
- return;
- }
- }
- Device [] newDevices = new Device [Devices.length + 4];
- System.arraycopy (Devices, 0, newDevices, 0, Devices.length);
- newDevices [Devices.length] = device;
- Devices = newDevices;
-}
-
-/**
- * Releases any internal resources back to the operating
- * system and clears all fields except the device handle.
- * <p>
- * When a device is destroyed, resources that were acquired
- * on behalf of the programmer need to be returned to the
- * operating system. For example, if the device allocated a
- * font to be used as the system font, this font would be
- * freed in <code>release</code>. Also,to assist the garbage
- * collector and minimize the amount of memory that is not
- * reclaimed when the programmer keeps a reference to a
- * disposed device, all fields except the handle are zero'd.
- * The handle is needed by <code>destroy</code>.
- * </p>
- * This method is called before <code>destroy</code>.
- * </p><p>
- * If subclasses reimplement this method, they must
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #dispose
- * @see #destroy
- */
-protected void release () {
- if (shellHandle != 0) OS.gtk_widget_destroy(shellHandle);
- shellHandle = 0;
-
- if (gdkColors != null) {
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- for (int i = 0; i < gdkColors.length; i++) {
- GdkColor color = gdkColors [i];
- if (color != null) {
- while (colorRefCount [i] > 0) {
- OS.gdk_colormap_free_colors(colormap, color, 1);
- --colorRefCount [i];
- }
- }
- }
- }
- gdkColors = null;
- colorRefCount = null;
-
- if (COLOR_BLACK != null) COLOR_BLACK.dispose();
- if (COLOR_DARK_RED != null) COLOR_DARK_RED.dispose();
- if (COLOR_DARK_GREEN != null) COLOR_DARK_GREEN.dispose();
- if (COLOR_DARK_YELLOW != null) COLOR_DARK_YELLOW.dispose();
- if (COLOR_DARK_BLUE != null) COLOR_DARK_BLUE.dispose();
- if (COLOR_DARK_MAGENTA != null) COLOR_DARK_MAGENTA.dispose();
- if (COLOR_DARK_CYAN != null) COLOR_DARK_CYAN.dispose();
- if (COLOR_GRAY != null) COLOR_GRAY.dispose();
- if (COLOR_DARK_GRAY != null) COLOR_DARK_GRAY.dispose();
- if (COLOR_RED != null) COLOR_RED.dispose();
- if (COLOR_GREEN != null) COLOR_GREEN.dispose();
- if (COLOR_YELLOW != null) COLOR_YELLOW.dispose();
- if (COLOR_BLUE != null) COLOR_BLUE.dispose();
- if (COLOR_MAGENTA != null) COLOR_MAGENTA.dispose();
- if (COLOR_CYAN != null) COLOR_CYAN.dispose();
- if (COLOR_WHITE != null) COLOR_WHITE.dispose();
- COLOR_BLACK = COLOR_DARK_RED = COLOR_DARK_GREEN = COLOR_DARK_YELLOW = COLOR_DARK_BLUE =
- COLOR_DARK_MAGENTA = COLOR_DARK_CYAN = COLOR_GRAY = COLOR_DARK_GRAY = COLOR_RED =
- COLOR_GREEN = COLOR_YELLOW = COLOR_BLUE = COLOR_MAGENTA = COLOR_CYAN = COLOR_WHITE = null;
-
- if (emptyTab != 0) OS.pango_tab_array_free(emptyTab);
- emptyTab = 0;
-
- /* Free the GTK error and warning handler */
- if (xDisplay != 0) {
- for (int i=0; i<handler_ids.length; i++) {
- if (handler_ids [i] != 0) {
- byte [] log_domain = Converter.wcsToMbcs (null, log_domains [i], true);
- OS.g_log_remove_handler (log_domain, handler_ids [i]);
- handler_ids [i] = 0;
- }
- }
- logCallback.dispose (); logCallback = null;
- handler_ids = null; log_domains = null;
- logProc = 0;
- }
-}
-
-/**
- * If the underlying window system supports printing warning messages
- * to the console, setting warnings to <code>false</code> prevents these
- * messages from being printed. If the argument is <code>true</code> then
- * message printing is not blocked.
- *
- * @param warnings <code>true</code>if warnings should be printed, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setWarnings (boolean warnings) {
- checkDevice ();
- if (warnings) {
- if (--warningLevel == 0) {
- if (debug) return;
- if (logProc != 0) {
- for (int i=0; i<handler_ids.length; i++) {
- if (handler_ids [i] != 0) {
- byte [] log_domain = Converter.wcsToMbcs (null, log_domains [i], true);
- OS.g_log_remove_handler (log_domain, handler_ids [i]);
- handler_ids [i] = 0;
- }
- }
- }
- }
- } else {
- if (warningLevel++ == 0) {
- if (debug) return;
- if (logProc != 0) {
- int flags = OS.G_LOG_LEVEL_MASK | OS.G_LOG_FLAG_FATAL | OS.G_LOG_FLAG_RECURSION;
- for (int i=0; i<log_domains.length; i++) {
- byte [] log_domain = Converter.wcsToMbcs (null, log_domains [i], true);
- handler_ids [i] = OS.g_log_set_handler (log_domain, flags, logProc, 0);
- }
- }
- }
- }
-}
-
-static int /*long*/ XErrorProc (int /*long*/ xDisplay, int /*long*/ xErrorEvent) {
- Device device = findDevice (xDisplay);
- if (device != null) {
- if (device.warningLevel == 0) {
- if (DEBUG || device.debug) {
- new SWTError ().printStackTrace ();
- }
- OS.Call (XErrorProc, xDisplay, xErrorEvent);
- }
- } else {
- if (DEBUG) new SWTError ().printStackTrace ();
- OS.Call (XErrorProc, xDisplay, xErrorEvent);
- }
- return 0;
-}
-
-static int /*long*/ XIOErrorProc (int /*long*/ xDisplay) {
- Device device = findDevice (xDisplay);
- if (device != null) {
- if (DEBUG || device.debug) {
- new SWTError ().printStackTrace ();
- }
- } else {
- if (DEBUG) new SWTError ().printStackTrace ();
- }
- OS.Call (XIOErrorProc, xDisplay, 0);
- return 0;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/DeviceData.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/DeviceData.java
deleted file mode 100644
index 6fc287fd81..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/DeviceData.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-public class DeviceData {
- /*
- * The following fields are platform dependent.
- * <p>
- * <b>IMPORTANT:</b> These fields are <em>not</em> part of the SWT
- * public API. They are marked public only so that they can be shared
- * within the packages provided by SWT. They are not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public String display_name;
- public String application_name;
- public String application_class;
-
- /*
- * Debug fields - may not be honoured
- * on some SWT platforms.
- */
- public boolean debug;
- public boolean tracking;
- public Error [] errors;
- public Object [] objects;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java
deleted file mode 100644
index 3607e38cfa..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java
+++ /dev/null
@@ -1,288 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-
-/**
- * Instances of this class manage operating system resources that
- * define how text looks when it is displayed. Fonts may be constructed
- * by providing a device and either name, size and style information
- * or a <code>FontData</code> object which encapsulates this data.
- * <p>
- * Application code must explicitly invoke the <code>Font.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see FontData
- * @see <a href="http://www.eclipse.org/swt/snippets/#font">Font snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Font extends Resource {
- /**
- * the handle to the OS font resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
-
-Font(Device device) {
- super(device);
-}
-
-/**
- * Constructs a new font given a device and font data
- * which describes the desired font's appearance.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param fd the FontData that describes the desired font (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the fd argument is null</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li>
- * </ul>
- */
-public Font(Device device, FontData fd) {
- super(device);
- if (fd == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(fd.getName(), fd.getHeightF(), fd.getStyle(), fd.string);
- init();
-}
-
-/**
- * Constructs a new font given a device and an array
- * of font data which describes the desired font's
- * appearance.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param fds the array of FontData that describes the desired font (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the fds argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the length of fds is zero</li>
- * <li>ERROR_NULL_ARGUMENT - if any fd in the array is null</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li>
- * </ul>
- *
- * @since 2.1
- */
-public Font(Device device, FontData[] fds) {
- super(device);
- if (fds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (fds.length == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<fds.length; i++) {
- if (fds[i] == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- FontData fd = fds[0];
- init(fd.getName(), fd.getHeightF(), fd.getStyle(), fd.string);
- init();
-}
-
-/**
- * Constructs a new font given a device, a font name,
- * the height of the desired font in points, and a font
- * style.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param name the name of the font (must not be null)
- * @param height the font height in points
- * @param style a bit or combination of NORMAL, BOLD, ITALIC
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the name argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given arguments</li>
- * </ul>
- */
-public Font(Device device, String name, int height, int style) {
- super(device);
- init(name, height, style, null);
- init();
-}
-
-/*public*/ Font(Device device, String name, float height, int style) {
- super(device);
- init(name, height, style, null);
- init();
-}
-
-void destroy() {
- OS.pango_font_description_free(handle);
- handle = 0;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals(Object object) {
- if (object == this) return true;
- if (!(object instanceof Font)) return false;
- return handle == ((Font)object).handle;
-}
-
-/**
- * Returns an array of <code>FontData</code>s representing the receiver.
- * On Windows, only one FontData will be returned per font. On X however,
- * a <code>Font</code> object <em>may</em> be composed of multiple X
- * fonts. To support this case, we return an array of font data objects.
- *
- * @return an array of font data objects describing the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontData[] getFontData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-
- int /*long*/ family = OS.pango_font_description_get_family(handle);
- int length = OS.strlen(family);
- byte[] buffer = new byte[length];
- OS.memmove(buffer, family, length);
- String name = new String(Converter.mbcsToWcs(null, buffer));
- float height = (float)OS.pango_font_description_get_size(handle) / OS.PANGO_SCALE;
- int pangoStyle = OS.pango_font_description_get_style(handle);
- int pangoWeight = OS.pango_font_description_get_weight(handle);
- int style = SWT.NORMAL;
- if (pangoStyle == OS.PANGO_STYLE_ITALIC) style |= SWT.ITALIC;
- if (pangoStyle == OS.PANGO_STYLE_OBLIQUE) style |= SWT.ROMAN;
- if (pangoWeight >= OS.PANGO_WEIGHT_BOLD) style |= SWT.BOLD;
- int /*long*/ fontString = OS.pango_font_description_to_string (handle);
- length = OS.strlen (fontString);
- buffer = new byte [length + 1];
- OS.memmove (buffer, fontString, length);
- OS.g_free (fontString);
- FontData data = new FontData(name, height, style);
- data.string = buffer;
- return new FontData[]{data};
-}
-
-/**
- * Invokes platform specific functionality to allocate a new font.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Font</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param handle the handle for the font
- *
- * @private
- */
-public static Font gtk_new(Device device, int /*long*/ handle) {
- Font font = new Font(device);
- font.handle = handle;
- return font;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode() {
- return (int)/*64*/handle;
-}
-
-void init(String name, float height, int style, byte[] fontString) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (fontString != null) {
- handle = OS.pango_font_description_from_string (fontString);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- } else {
- handle = OS.pango_font_description_new();
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- byte[] buffer = Converter.wcsToMbcs(null, name, true);
- OS.pango_font_description_set_family(handle, buffer);
- if (height > 0) {
- OS.pango_font_description_set_size(handle, (int)(0.5f + height * OS.PANGO_SCALE));
- }
- OS.pango_font_description_set_stretch(handle, OS.PANGO_STRETCH_NORMAL);
- int pangoStyle = OS.PANGO_STYLE_NORMAL;
- int pangoWeight = OS.PANGO_WEIGHT_NORMAL;
- if ((style & SWT.ITALIC) != 0) pangoStyle = OS.PANGO_STYLE_ITALIC;
- if ((style & SWT.ROMAN) != 0) pangoStyle = OS.PANGO_STYLE_OBLIQUE;
- if ((style & SWT.BOLD) != 0) pangoWeight = OS.PANGO_WEIGHT_BOLD;
- OS.pango_font_description_set_style(handle, pangoStyle);
- OS.pango_font_description_set_weight(handle, pangoWeight);
- }
-}
-
-/**
- * Returns <code>true</code> if the font has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the font.
- * When a font has been disposed, it is an error to
- * invoke any other method using the font.
- *
- * @return <code>true</code> when the font is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Font {*DISPOSED*}";
- return "Font {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontData.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontData.java
deleted file mode 100644
index 6d15004b12..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontData.java
+++ /dev/null
@@ -1,446 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class describe operating system fonts.
- * <p>
- * For platform-independent behaviour, use the get and set methods
- * corresponding to the following properties:
- * <dl>
- * <dt>height</dt><dd>the height of the font in points</dd>
- * <dt>name</dt><dd>the face name of the font, which may include the foundry</dd>
- * <dt>style</dt><dd>A bitwise combination of NORMAL, ITALIC and BOLD</dd>
- * </dl>
- * If extra, platform-dependent functionality is required:
- * <ul>
- * <li>On <em>Windows</em>, the data member of the <code>FontData</code>
- * corresponds to a Windows <code>LOGFONT</code> structure whose fields
- * may be retrieved and modified.</li>
- * <li>On <em>X</em>, the fields of the <code>FontData</code> correspond
- * to the entries in the font's XLFD name and may be retrieved and modified.
- * </ul>
- * Application code does <em>not</em> need to explicitly release the
- * resources managed by each instance when those instances are no longer
- * required, and thus no <code>dispose()</code> method is provided.
- *
- * @see Font
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class FontData {
- /**
- * the font name
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public String name;
-
- /**
- * The height of the font data in points
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public float height;
-
- /**
- * the font style
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int style;
-
- /**
- * the Pango string
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public byte[] string;
-
- /**
- * The locales of the font
- */
- String lang, country, variant;
-
-/**
- * Constructs a new uninitialized font data.
- */
-public FontData () {
- this("", 12, SWT.NORMAL);
-}
-
-/**
- * Constructs a new FontData given a string representation
- * in the form generated by the <code>FontData.toString</code>
- * method.
- * <p>
- * Note that the representation varies between platforms,
- * and a FontData can only be created from a string that was
- * generated on the same platform.
- * </p>
- *
- * @param string the string representation of a <code>FontData</code> (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument does not represent a valid description</li>
- * </ul>
- *
- * @see #toString
- */
-public FontData(String string) {
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int start = 0;
- int end = string.indexOf('|');
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- String version1 = string.substring(start, end);
- try {
- if (Integer.parseInt(version1) != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- String name = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- float height = 0;
- try {
- height = Float.parseFloat(string.substring(start, end));
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int style = 0;
- try {
- style = Integer.parseInt(string.substring(start, end));
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- setName(name);
- setHeight(height);
- setStyle(style);
- if (end == -1) return;
- String platform = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- String version2 = string.substring(start, end);
-
- if (platform.equals("GTK") && version2.equals("1")) {
- return;
- }
-}
-
-/**
- * Constructs a new font data given a font name,
- * the height of the desired font in points,
- * and a font style.
- *
- * @param name the name of the font (must not be null)
- * @param height the font height in points
- * @param style a bit or combination of NORMAL, BOLD, ITALIC
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - when the font name is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- */
-public FontData(String name, int height, int style) {
- setName(name);
- setHeight(height);
- setStyle(style);
-}
-
-/*public*/ FontData(String name, float height, int style) {
- setName(name);
- setHeight(height);
- setStyle(style);
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof FontData)) return false;
- FontData data = (FontData)object;
- return name.equals(data.name) && height == data.height && style == data.style;
-}
-
-/**
- * Returns the height of the receiver in points.
- *
- * @return the height of this FontData
- *
- * @see #setHeight(int)
- */
-public int getHeight() {
- return (int)(0.5f + height);
-}
-
-/*public*/ float getHeightF() {
- return height;
-}
-
-/**
- * Returns the locale of the receiver.
- * <p>
- * The locale determines which platform character set this
- * font is going to use. Widgets and graphics operations that
- * use this font will convert UNICODE strings to the platform
- * character set of the specified locale.
- * </p>
- * <p>
- * On platforms where there are multiple character sets for a
- * given language/country locale, the variant portion of the
- * locale will determine the character set.
- * </p>
- *
- * @return the <code>String</code> representing a Locale object
- * @since 3.0
- */
-public String getLocale () {
- StringBuffer buffer = new StringBuffer ();
- char sep = '_';
- if (lang != null) {
- buffer.append (lang);
- buffer.append (sep);
- }
- if (country != null) {
- buffer.append (country);
- buffer.append (sep);
- }
- if (variant != null) {
- buffer.append (variant);
- }
-
- String result = buffer.toString ();
- int length = result.length ();
- if (length > 0) {
- if (result.charAt (length - 1) == sep) {
- result = result.substring (0, length - 1);
- }
- }
- return result;
-}
-
-/**
- * Returns the name of the receiver.
- * On platforms that support font foundries, the return value will
- * be the foundry followed by a dash ("-") followed by the face name.
- *
- * @return the name of this <code>FontData</code>
- *
- * @see #setName
- */
-public String getName() {
- return name;
-}
-
-/**
- * Returns the style of the receiver which is a bitwise OR of
- * one or more of the <code>SWT</code> constants NORMAL, BOLD
- * and ITALIC.
- *
- * @return the style of this <code>FontData</code>
- *
- * @see #setStyle
- */
-public int getStyle() {
- return style;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return name.hashCode() ^ getHeight() ^ style;
-}
-
-/**
- * Sets the height of the receiver. The parameter is
- * specified in terms of points, where a point is one
- * seventy-second of an inch.
- *
- * @param height the height of the <code>FontData</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- *
- * @see #getHeight
- */
-public void setHeight(int height) {
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.height = height;
- this.string = null;
-}
-
-/*public*/ void setHeight(float height) {
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.height = height;
- this.string = null;
-}
-
-/**
- * Sets the locale of the receiver.
- * <p>
- * The locale determines which platform character set this
- * font is going to use. Widgets and graphics operations that
- * use this font will convert UNICODE strings to the platform
- * character set of the specified locale.
- * </p>
- * <p>
- * On platforms where there are multiple character sets for a
- * given language/country locale, the variant portion of the
- * locale will determine the character set.
- * </p>
- *
- * @param locale the <code>String</code> representing a Locale object
- * @see java.util.Locale#toString
- */
-public void setLocale(String locale) {
- lang = country = variant = null;
- if (locale != null) {
- char sep = '_';
- int length = locale.length();
- int firstSep, secondSep;
-
- firstSep = locale.indexOf(sep);
- if (firstSep == -1) {
- firstSep = secondSep = length;
- } else {
- secondSep = locale.indexOf(sep, firstSep + 1);
- if (secondSep == -1) secondSep = length;
- }
- if (firstSep > 0) lang = locale.substring(0, firstSep);
- if (secondSep > firstSep + 1) country = locale.substring(firstSep + 1, secondSep);
- if (length > secondSep + 1) variant = locale.substring(secondSep + 1);
- }
-}
-
-/**
- * Sets the name of the receiver.
- * <p>
- * Some platforms support font foundries. On these platforms, the name
- * of the font specified in setName() may have one of the following forms:
- * <ol>
- * <li>a face name (for example, "courier")</li>
- * <li>a foundry followed by a dash ("-") followed by a face name (for example, "adobe-courier")</li>
- * </ol>
- * In either case, the name returned from getName() will include the
- * foundry.
- * </p>
- * <p>
- * On platforms that do not support font foundries, only the face name
- * (for example, "courier") is used in <code>setName()</code> and
- * <code>getName()</code>.
- * </p>
- *
- * @param name the name of the font data (must not be null)
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - when the font name is null</li>
- * </ul>
- *
- * @see #getName
- */
-public void setName(String name) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.name = name;
- this.string = null;
-}
-
-/**
- * Sets the style of the receiver to the argument which must
- * be a bitwise OR of one or more of the <code>SWT</code>
- * constants NORMAL, BOLD and ITALIC. All other style bits are
- * ignored.
- *
- * @param style the new style for this <code>FontData</code>
- *
- * @see #getStyle
- */
-public void setStyle(int style) {
- this.style = style;
- this.string = null;
-}
-
-/**
- * Returns a string representation of the receiver which is suitable
- * for constructing an equivalent instance using the
- * <code>FontData(String)</code> constructor.
- *
- * @return a string representation of the FontData
- *
- * @see FontData
- */
-public String toString() {
- StringBuffer buffer = new StringBuffer(128);
- buffer.append("1|");
- buffer.append(getName());
- buffer.append("|");
- buffer.append(getHeightF());
- buffer.append("|");
- buffer.append(getStyle());
- buffer.append("|");
- buffer.append("GTK|1|");
- return buffer.toString();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java
deleted file mode 100644
index cd33b62ccf..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-/**
- * Instances of this class provide measurement information
- * about fonts including ascent, descent, height, leading
- * space between rows, and average character width.
- * <code>FontMetrics</code> are obtained from <code>GC</code>s
- * using the <code>getFontMetrics()</code> method.
- *
- * @see GC#getFontMetrics
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class FontMetrics {
- int ascent, descent, averageCharWidth, leading, height;
-
-FontMetrics() {
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof FontMetrics)) return false;
- FontMetrics metrics = (FontMetrics)object;
- return ascent == metrics.ascent && descent == metrics.descent &&
- averageCharWidth == metrics.averageCharWidth && leading == metrics.leading &&
- height == metrics.height;
-}
-
-/**
- * Returns the ascent of the font described by the receiver. A
- * font's <em>ascent</em> is the distance from the baseline to the
- * top of actual characters, not including any of the leading area,
- * measured in pixels.
- *
- * @return the ascent of the font
- */
-public int getAscent() {
- return ascent;
-}
-
-/**
- * Returns the average character width, measured in pixels,
- * of the font described by the receiver.
- *
- * @return the average character width of the font
- */
-public int getAverageCharWidth() {
- return averageCharWidth;
-}
-
-/**
- * Returns the descent of the font described by the receiver. A
- * font's <em>descent</em> is the distance from the baseline to the
- * bottom of actual characters, not including any of the leading area,
- * measured in pixels.
- *
- * @return the descent of the font
- */
-public int getDescent() {
- return descent;
-}
-
-/**
- * Returns the height of the font described by the receiver,
- * measured in pixels. A font's <em>height</em> is the sum of
- * its ascent, descent and leading area.
- *
- * @return the height of the font
- *
- * @see #getAscent
- * @see #getDescent
- * @see #getLeading
- */
-public int getHeight() {
- return height;
-}
-
-/**
- * Returns the leading area of the font described by the
- * receiver. A font's <em>leading area</em> is the space
- * above its ascent which may include accents or other marks.
- *
- * @return the leading space of the font
- */
-public int getLeading() {
- return leading;
-}
-
-public static FontMetrics gtk_new(int ascent, int descent, int averageCharWidth, int leading, int height) {
- FontMetrics fontMetrics = new FontMetrics();
- fontMetrics.ascent = ascent;
- fontMetrics.descent = descent;
- fontMetrics.averageCharWidth = averageCharWidth;
- fontMetrics.leading = leading;
- fontMetrics.height = height;
- return fontMetrics;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode() {
- return ascent ^ descent ^ averageCharWidth ^ leading ^ height;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java
deleted file mode 100644
index 78c020d109..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java
+++ /dev/null
@@ -1,4036 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.cairo.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.*;
-
-/**
- * Class <code>GC</code> is where all of the drawing capabilities that are
- * supported by SWT are located. Instances are used to draw on either an
- * <code>Image</code>, a <code>Control</code>, or directly on a <code>Display</code>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * </dl>
- *
- * <p>
- * The SWT drawing coordinate system is the two-dimensional space with the origin
- * (0,0) at the top left corner of the drawing area and with (x,y) values increasing
- * to the right and downward respectively.
- * </p>
- *
- * <p>
- * The result of drawing on an image that was created with an indexed
- * palette using a color that is not in the palette is platform specific.
- * Some platforms will match to the nearest color while other will draw
- * the color itself. This happens because the allocated image might use
- * a direct palette on platforms that do not support indexed palette.
- * </p>
- *
- * <p>
- * Application code must explicitly invoke the <code>GC.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required. This is <em>particularly</em>
- * important on Windows95 and Windows98 where the operating system has a limited
- * number of device contexts available.
- * </p>
- *
- * <p>
- * Note: Only one of LEFT_TO_RIGHT and RIGHT_TO_LEFT may be specified.
- * </p>
- *
- * @see org.eclipse.swt.events.PaintEvent
- * @see <a href="http://www.eclipse.org/swt/snippets/#gc">GC snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class GC extends Resource {
- /**
- * the handle to the OS device context
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
-
- Drawable drawable;
- GCData data;
-
- final static int FOREGROUND = 1 << 0;
- final static int BACKGROUND = 1 << 1;
- final static int FONT = 1 << 2;
- final static int LINE_STYLE = 1 << 3;
- final static int LINE_CAP = 1 << 4;
- final static int LINE_JOIN = 1 << 5;
- final static int LINE_WIDTH = 1 << 6;
- final static int LINE_MITERLIMIT = 1 << 7;
- final static int BACKGROUND_BG = 1 << 8;
- final static int DRAW_OFFSET = 1 << 9;
- final static int DRAW = FOREGROUND | LINE_WIDTH | LINE_STYLE | LINE_CAP | LINE_JOIN | LINE_MITERLIMIT | DRAW_OFFSET;
- final static int FILL = BACKGROUND;
-
- static final float[] LINE_DOT = new float[]{1, 1};
- static final float[] LINE_DASH = new float[]{3, 1};
- static final float[] LINE_DASHDOT = new float[]{3, 1, 1, 1};
- static final float[] LINE_DASHDOTDOT = new float[]{3, 1, 1, 1, 1, 1};
- static final float[] LINE_DOT_ZERO = new float[]{3, 3};
- static final float[] LINE_DASH_ZERO = new float[]{18, 6};
- static final float[] LINE_DASHDOT_ZERO = new float[]{9, 6, 3, 6};
- static final float[] LINE_DASHDOTDOT_ZERO = new float[]{9, 3, 3, 3, 3, 3};
-
-GC() {
-}
-
-/**
- * Constructs a new instance of this class which has been
- * configured to draw on the specified drawable. Sets the
- * foreground color, background color and font in the GC
- * to match those in the drawable.
- * <p>
- * You must dispose the graphics context when it is no longer required.
- * </p>
- * @param drawable the drawable to draw on
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li>
- * <li>ERROR_NULL_ARGUMENT - if there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT
- * - if the drawable is an image that is not a bitmap or an icon
- * - if the drawable is an image or printer that is already selected
- * into another graphics context</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li>
- * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li>
- * </ul>
- */
-public GC(Drawable drawable) {
- this(drawable, 0);
-}
-
-/**
- * Constructs a new instance of this class which has been
- * configured to draw on the specified drawable. Sets the
- * foreground color, background color and font in the GC
- * to match those in the drawable.
- * <p>
- * You must dispose the graphics context when it is no longer required.
- * </p>
- *
- * @param drawable the drawable to draw on
- * @param style the style of GC to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li>
- * <li>ERROR_NULL_ARGUMENT - if there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT
- * - if the drawable is an image that is not a bitmap or an icon
- * - if the drawable is an image or printer that is already selected
- * into another graphics context</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li>
- * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public GC(Drawable drawable, int style) {
- if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- GCData data = new GCData();
- data.style = checkStyle(style);
- int /*long*/ gdkGC = drawable.internal_new_GC(data);
- Device device = data.device;
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = data.device = device;
- init(drawable, data, gdkGC);
- init();
-}
-
-static void addCairoString(int /*long*/ cairo, String string, float x, float y, Font font) {
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
- if (OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
- int /*long*/ layout = OS.pango_cairo_create_layout(cairo);
- if (layout == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.pango_layout_set_text(layout, buffer, -1);
- OS.pango_layout_set_font_description(layout, font.handle);
- double[] currentX = new double[1], currentY = new double[1];
- Cairo.cairo_get_current_point(cairo, currentX, currentY);
- if (currentX[0] != x || currentY[0] != y) {
- Cairo.cairo_move_to(cairo, x, y);
- }
- OS.pango_cairo_layout_path(cairo, layout);
- OS.g_object_unref(layout);
- } else {
- GC.setCairoFont(cairo, font);
- cairo_font_extents_t extents = new cairo_font_extents_t();
- Cairo.cairo_font_extents(cairo, extents);
- double baseline = y + extents.ascent;
- Cairo.cairo_move_to(cairo, x, baseline);
- Cairo.cairo_text_path(cairo, buffer);
- }
-}
-
-static int checkStyle (int style) {
- if ((style & SWT.LEFT_TO_RIGHT) != 0) style &= ~SWT.RIGHT_TO_LEFT;
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-public static GC gtk_new(int /*long*/ handle, GCData data) {
- GC gc = new GC();
- gc.device = data.device;
- gc.init(null, data, handle);
- return gc;
-}
-
-public static GC gtk_new(Drawable drawable, GCData data) {
- GC gc = new GC();
- int /*long*/ gdkGC = drawable.internal_new_GC(data);
- gc.device = data.device;
- gc.init(drawable, data, gdkGC);
- return gc;
-}
-
-void checkGC (int mask) {
- int state = data.state;
- if ((state & mask) == mask) return;
- state = (state ^ mask) & mask;
- data.state |= mask;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- if ((state & (BACKGROUND | FOREGROUND)) != 0) {
- GdkColor color;
- Pattern pattern;
- if ((state & FOREGROUND) != 0) {
- color = data.foreground;
- pattern = data.foregroundPattern;
- data.state &= ~BACKGROUND;
- } else {
- color = data.background;
- pattern = data.backgroundPattern;
- data.state &= ~FOREGROUND;
- }
- if (pattern != null) {
- if ((data.style & SWT.MIRRORED) != 0 && pattern.surface != 0) {
- int /*long*/ newPattern = Cairo.cairo_pattern_create_for_surface(pattern.surface);
- if (newPattern == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Cairo.cairo_pattern_set_extend(newPattern, Cairo.CAIRO_EXTEND_REPEAT);
- double[] matrix = {-1, 0, 0, 1, 0, 0};
- Cairo.cairo_pattern_set_matrix(newPattern, matrix);
- Cairo.cairo_set_source(cairo, newPattern);
- Cairo.cairo_pattern_destroy(newPattern);
- } else {
- Cairo.cairo_set_source(cairo, pattern.handle);
- }
- } else {
- Cairo.cairo_set_source_rgba(cairo, (color.red & 0xFFFF) / (float)0xFFFF, (color.green & 0xFFFF) / (float)0xFFFF, (color.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF);
- }
- }
- if ((state & FONT) != 0) {
- if (data.layout != 0) {
- Font font = data.font;
- OS.pango_layout_set_font_description(data.layout, font.handle);
- }
- if (OS.GTK_VERSION < OS.VERSION(2, 8, 0)) {
- setCairoFont(cairo, data.font);
- }
- }
- if ((state & LINE_CAP) != 0) {
- int cap_style = 0;
- switch (data.lineCap) {
- case SWT.CAP_ROUND: cap_style = Cairo.CAIRO_LINE_CAP_ROUND; break;
- case SWT.CAP_FLAT: cap_style = Cairo.CAIRO_LINE_CAP_BUTT; break;
- case SWT.CAP_SQUARE: cap_style = Cairo.CAIRO_LINE_CAP_SQUARE; break;
- }
- Cairo.cairo_set_line_cap(cairo, cap_style);
- }
- if ((state & LINE_JOIN) != 0) {
- int join_style = 0;
- switch (data.lineJoin) {
- case SWT.JOIN_MITER: join_style = Cairo.CAIRO_LINE_JOIN_MITER; break;
- case SWT.JOIN_ROUND: join_style = Cairo.CAIRO_LINE_JOIN_ROUND; break;
- case SWT.JOIN_BEVEL: join_style = Cairo.CAIRO_LINE_JOIN_BEVEL; break;
- }
- Cairo.cairo_set_line_join(cairo, join_style);
- }
- if ((state & LINE_WIDTH) != 0) {
- Cairo.cairo_set_line_width(cairo, data.lineWidth == 0 ? 1 : data.lineWidth);
- switch (data.lineStyle) {
- case SWT.LINE_DOT:
- case SWT.LINE_DASH:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- state |= LINE_STYLE;
- }
- }
- if ((state & LINE_STYLE) != 0) {
- float dashesOffset = 0;
- float[] dashes = null;
- float width = data.lineWidth;
- switch (data.lineStyle) {
- case SWT.LINE_SOLID: break;
- case SWT.LINE_DASH: dashes = width != 0 ? LINE_DASH : LINE_DASH_ZERO; break;
- case SWT.LINE_DOT: dashes = width != 0 ? LINE_DOT : LINE_DOT_ZERO; break;
- case SWT.LINE_DASHDOT: dashes = width != 0 ? LINE_DASHDOT : LINE_DASHDOT_ZERO; break;
- case SWT.LINE_DASHDOTDOT: dashes = width != 0 ? LINE_DASHDOTDOT : LINE_DASHDOTDOT_ZERO; break;
- case SWT.LINE_CUSTOM: dashes = data.lineDashes; break;
- }
- if (dashes != null) {
- dashesOffset = data.lineDashesOffset;
- double[] cairoDashes = new double[dashes.length];
- for (int i = 0; i < cairoDashes.length; i++) {
- cairoDashes[i] = width == 0 || data.lineStyle == SWT.LINE_CUSTOM ? dashes[i] : dashes[i] * width;
- }
- Cairo.cairo_set_dash(cairo, cairoDashes, cairoDashes.length, dashesOffset);
- } else {
- Cairo.cairo_set_dash(cairo, null, 0, 0);
- }
- }
- if ((state & LINE_MITERLIMIT) != 0) {
- Cairo.cairo_set_miter_limit(cairo, data.lineMiterLimit);
- }
- if ((state & DRAW_OFFSET) != 0) {
- data.cairoXoffset = data.cairoYoffset = 0;
- double[] matrix = new double[6];
- Cairo.cairo_get_matrix(cairo, matrix);
- double[] dx = new double[]{1};
- double[] dy = new double[]{1};
- Cairo.cairo_user_to_device_distance(cairo, dx, dy);
- double scaling = dx[0];
- if (scaling < 0) scaling = -scaling;
- double strokeWidth = data.lineWidth * scaling;
- if (strokeWidth == 0 || ((int)strokeWidth % 2) == 1) {
- data.cairoXoffset = 0.5 / scaling;
- }
- scaling = dy[0];
- if (scaling < 0) scaling = -scaling;
- strokeWidth = data.lineWidth * scaling;
- if (strokeWidth == 0 || ((int)strokeWidth % 2) == 1) {
- data.cairoYoffset = 0.5 / scaling;
- }
- }
- return;
- }
- if ((state & (BACKGROUND | FOREGROUND)) != 0) {
- GdkColor foreground;
- if ((state & FOREGROUND) != 0) {
- foreground = data.foreground;
- data.state &= ~BACKGROUND;
- } else {
- foreground = data.background;
- data.state &= ~FOREGROUND;
- }
- OS.gdk_gc_set_foreground(handle, foreground);
- }
- if ((state & BACKGROUND_BG) != 0) {
- GdkColor background = data.background;
- OS.gdk_gc_set_background(handle, background);
- }
- if ((state & FONT) != 0) {
- if (data.layout != 0) {
- Font font = data.font;
- OS.pango_layout_set_font_description(data.layout, font.handle);
- }
- }
- if ((state & (LINE_CAP | LINE_JOIN | LINE_STYLE | LINE_WIDTH)) != 0) {
- int cap_style = 0;
- int join_style = 0;
- int width = (int)data.lineWidth;
- int line_style = 0;
- float[] dashes = null;
- switch (data.lineCap) {
- case SWT.CAP_ROUND: cap_style = OS.GDK_CAP_ROUND; break;
- case SWT.CAP_FLAT: cap_style = OS.GDK_CAP_BUTT; break;
- case SWT.CAP_SQUARE: cap_style = OS.GDK_CAP_PROJECTING; break;
- }
- switch (data.lineJoin) {
- case SWT.JOIN_ROUND: join_style = OS.GDK_JOIN_ROUND; break;
- case SWT.JOIN_MITER: join_style = OS.GDK_JOIN_MITER; break;
- case SWT.JOIN_BEVEL: join_style = OS.GDK_JOIN_BEVEL; break;
- }
- switch (data.lineStyle) {
- case SWT.LINE_SOLID: break;
- case SWT.LINE_DASH: dashes = width != 0 ? LINE_DASH : LINE_DASH_ZERO; break;
- case SWT.LINE_DOT: dashes = width != 0 ? LINE_DOT : LINE_DOT_ZERO; break;
- case SWT.LINE_DASHDOT: dashes = width != 0 ? LINE_DASHDOT : LINE_DASHDOT_ZERO; break;
- case SWT.LINE_DASHDOTDOT: dashes = width != 0 ? LINE_DASHDOTDOT : LINE_DASHDOTDOT_ZERO; break;
- case SWT.LINE_CUSTOM: dashes = data.lineDashes; break;
- }
- if (dashes != null) {
- if ((state & LINE_STYLE) != 0) {
- byte[] dash_list = new byte[dashes.length];
- for (int i = 0; i < dash_list.length; i++) {
- dash_list[i] = (byte)(width == 0 || data.lineStyle == SWT.LINE_CUSTOM ? dashes[i] : dashes[i] * width);
- }
- OS.gdk_gc_set_dashes(handle, 0, dash_list, dash_list.length);
- }
- line_style = OS.GDK_LINE_ON_OFF_DASH;
- } else {
- line_style = OS.GDK_LINE_SOLID;
- }
- OS.gdk_gc_set_line_attributes(handle, width, line_style, cap_style, join_style);
- }
-}
-
-int /*long*/ convertRgn(int /*long*/ rgn, double[] matrix) {
- int /*long*/ newRgn = OS.gdk_region_new();
- int[] nRects = new int[1];
- int /*long*/[] rects = new int /*long*/[1];
- OS.gdk_region_get_rectangles(rgn, rects, nRects);
- GdkRectangle rect = new GdkRectangle();
- int[] pointArray = new int[8];
- double[] x = new double[1], y = new double[1];
- for (int i=0; i<nRects[0]; i++) {
- OS.memmove(rect, rects[0] + (i * GdkRectangle.sizeof), GdkRectangle.sizeof);
- x[0] = rect.x;
- y[0] = rect.y;
- Cairo.cairo_matrix_transform_point(matrix, x, y);
- pointArray[0] = (int)x[0];
- pointArray[1] = (int)y[0];
- x[0] = rect.x + rect.width;
- y[0] = rect.y;
- Cairo.cairo_matrix_transform_point(matrix, x, y);
- pointArray[2] = (int)Math.round(x[0]);
- pointArray[3] = (int)y[0];
- x[0] = rect.x + rect.width;
- y[0] = rect.y + rect.height;
- Cairo.cairo_matrix_transform_point(matrix, x, y);
- pointArray[4] = (int)Math.round(x[0]);
- pointArray[5] = (int)Math.round(y[0]);
- x[0] = rect.x;
- y[0] = rect.y + rect.height;
- Cairo.cairo_matrix_transform_point(matrix, x, y);
- pointArray[6] = (int)x[0];
- pointArray[7] = (int)Math.round(y[0]);
- int /*long*/ polyRgn = OS.gdk_region_polygon(pointArray, pointArray.length / 2, OS.GDK_EVEN_ODD_RULE);
- OS.gdk_region_union(newRgn, polyRgn);
- OS.gdk_region_destroy(polyRgn);
- }
- if (rects[0] != 0) OS.g_free(rects[0]);
- return newRgn;
-}
-
-/**
- * Copies a rectangular area of the receiver at the specified
- * position into the image, which must be of type <code>SWT.BITMAP</code>.
- *
- * @param image the image to copy into
- * @param x the x coordinate in the receiver of the area to be copied
- * @param y the y coordinate in the receiver of the area to be copied
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image is not a bitmap or has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void copyArea(Image image, int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Rectangle rect = image.getBounds();
- int /*long*/ gdkGC = OS.gdk_gc_new(image.pixmap);
- if (gdkGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.gdk_gc_set_subwindow(gdkGC, OS.GDK_INCLUDE_INFERIORS);
- OS.gdk_draw_drawable(image.pixmap, gdkGC, data.drawable, x, y, 0, 0, rect.width, rect.height);
- OS.g_object_unref(gdkGC);
-}
-
-/**
- * Copies a rectangular area of the receiver at the source
- * position onto the receiver at the destination position.
- *
- * @param srcX the x coordinate in the receiver of the area to be copied
- * @param srcY the y coordinate in the receiver of the area to be copied
- * @param width the width of the area to copy
- * @param height the height of the area to copy
- * @param destX the x coordinate in the receiver of the area to copy to
- * @param destY the y coordinate in the receiver of the area to copy to
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY) {
- copyArea(srcX, srcY, width, height, destX, destY, true);
-}
-/**
- * Copies a rectangular area of the receiver at the source
- * position onto the receiver at the destination position.
- *
- * @param srcX the x coordinate in the receiver of the area to be copied
- * @param srcY the y coordinate in the receiver of the area to be copied
- * @param width the width of the area to copy
- * @param height the height of the area to copy
- * @param destX the x coordinate in the receiver of the area to copy to
- * @param destY the y coordinate in the receiver of the area to copy to
- * @param paint if <code>true</code> paint events will be generated for old and obscured areas
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width <= 0 || height <= 0) return;
- int deltaX = destX - srcX, deltaY = destY - srcY;
- if (deltaX == 0 && deltaY == 0) return;
- int /*long*/ drawable = data.drawable;
- if (data.image == null && paint) OS.gdk_gc_set_exposures(handle, true);
- OS.gdk_draw_drawable(drawable, handle, drawable, srcX, srcY, destX, destY, width, height);
- if (data.image == null & paint) {
- OS.gdk_gc_set_exposures(handle, false);
- boolean disjoint = (destX + width < srcX) || (srcX + width < destX) || (destY + height < srcY) || (srcY + height < destY);
- GdkRectangle rect = new GdkRectangle ();
- if (disjoint) {
- rect.x = srcX;
- rect.y = srcY;
- rect.width = width;
- rect.height = height;
- OS.gdk_window_invalidate_rect (drawable, rect, false);
-// OS.gdk_window_clear_area_e(drawable, srcX, srcY, width, height);
- } else {
- if (deltaX != 0) {
- int newX = destX - deltaX;
- if (deltaX < 0) newX = destX + width;
- rect.x = newX;
- rect.y = srcY;
- rect.width = Math.abs(deltaX);
- rect.height = height;
- OS.gdk_window_invalidate_rect (drawable, rect, false);
-// OS.gdk_window_clear_area_e(drawable, newX, srcY, Math.abs(deltaX), height);
- }
- if (deltaY != 0) {
- int newY = destY - deltaY;
- if (deltaY < 0) newY = destY + height;
- rect.x = srcX;
- rect.y = newY;
- rect.width = width;
- rect.height = Math.abs(deltaY);
- OS.gdk_window_invalidate_rect (drawable, rect, false);
-// OS.gdk_window_clear_area_e(drawable, srcX, newY, width, Math.abs(deltaY));
- }
- }
- }
-}
-
-void createLayout() {
- int /*long*/ context = OS.gdk_pango_context_get();
- if (context == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- data.context = context;
- int /*long*/ layout = OS.pango_layout_new(context);
- if (layout == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- data.layout = layout;
- OS.pango_context_set_language(context, OS.gtk_get_default_language());
- OS.pango_context_set_base_dir(context, (data.style & SWT.MIRRORED) != 0 ? OS.PANGO_DIRECTION_RTL : OS.PANGO_DIRECTION_LTR);
- OS.gdk_pango_context_set_colormap(context, OS.gdk_colormap_get_system());
- if (OS.GTK_VERSION >= OS.VERSION(2, 4, 0)) {
- OS.pango_layout_set_auto_dir(layout, false);
- }
-}
-
-void disposeLayout() {
- data.string = null;
- if (data.context != 0) OS.g_object_unref(data.context);
- if (data.layout != 0) OS.g_object_unref(data.layout);
- data.layout = data.context = 0;
-}
-
-void destroy() {
- if (data.disposeCairo) {
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) Cairo.cairo_destroy(cairo);
- data.cairo = 0;
- }
-
- /* Free resources */
- int /*long*/ clipRgn = data.clipRgn;
- if (clipRgn != 0) OS.gdk_region_destroy(clipRgn);
- Image image = data.image;
- if (image != null) {
- image.memGC = null;
- if (image.transparentPixel != -1) image.createMask();
- }
-
- disposeLayout();
-
- /* Dispose the GC */
- if (drawable != null) {
- drawable.internal_dispose_GC(handle, data);
- }
- data.drawable = data.clipRgn = 0;
- drawable = null;
- handle = 0;
- data.image = null;
- data.string = null;
- data = null;
-}
-
-/**
- * Draws the outline of a circular or elliptical arc
- * within the specified rectangular area.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees, using the current color.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc to be drawn
- * @param y the y coordinate of the upper-left corner of the arc to be drawn
- * @param width the width of the arc to be drawn
- * @param height the height of the arc to be drawn
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
- if (width == height) {
- if (arcAngle >= 0) {
- Cairo.cairo_arc_negative(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f, width / 2f, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- } else {
- Cairo.cairo_arc(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f, width / 2f, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- }
- } else {
- Cairo.cairo_save(cairo);
- Cairo.cairo_translate(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f);
- Cairo.cairo_scale(cairo, width / 2f, height / 2f);
- if (arcAngle >= 0) {
- Cairo.cairo_arc_negative(cairo, 0, 0, 1, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- } else {
- Cairo.cairo_arc(cairo, 0, 0, 1, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- }
- Cairo.cairo_restore(cairo);
- }
- Cairo.cairo_stroke(cairo);
- return;
- }
- OS.gdk_draw_arc(data.drawable, handle, 0, x, y, width, height, startAngle * 64, arcAngle * 64);
-}
-
-/**
- * Draws a rectangle, based on the specified arguments, which has
- * the appearance of the platform's <em>focus rectangle</em> if the
- * platform supports such a notion, and otherwise draws a simple
- * rectangle in the receiver's foreground color.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width of the rectangle
- * @param height the height of the rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void drawFocus(int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- /*
- * Feature in GTK. The function gtk_widget_get_default_style()
- * can't be used here because gtk_paint_focus() uses GCs, which
- * are not valid in the default style. The fix is to use a style
- * from a widget.
- */
- int /*long*/ style = OS.gtk_widget_get_style(data.device.shellHandle);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- checkGC(FOREGROUND);
- int[] lineWidth = new int[1];
- OS.gtk_widget_style_get(data.device.shellHandle, OS.focus_line_width, lineWidth, 0);
- Cairo.cairo_save(cairo);
- Cairo.cairo_set_line_width(cairo, lineWidth[0]);
- double[] dashes = new double[]{1, 1};
- double dash_offset = -lineWidth[0] / 2f;
- while (dash_offset < 0) dash_offset += 2;
- Cairo.cairo_set_dash(cairo, dashes, dashes.length, dash_offset);
- Cairo.cairo_rectangle(cairo, x + lineWidth[0] / 2f, y + lineWidth[0] / 2f, width, height);
- Cairo.cairo_stroke(cairo);
- Cairo.cairo_restore(cairo);
- return;
- }
- OS.gtk_paint_focus(style, data.drawable, OS.GTK_STATE_NORMAL, null, data.device.shellHandle, new byte[1], x, y, width, height);
-}
-
-/**
- * Draws the given image in the receiver at the specified
- * coordinates.
- *
- * @param image the image to draw
- * @param x the x coordinate of where to draw
- * @param y the y coordinate of where to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if the given coordinates are outside the bounds of the image</li>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- */
-public void drawImage(Image image, int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- drawImage(image, 0, 0, -1, -1, x, y, -1, -1, true);
-}
-
-/**
- * Copies a rectangular area from the source image into a (potentially
- * different sized) rectangular area in the receiver. If the source
- * and destination areas are of differing sizes, then the source
- * area will be stretched or shrunk to fit the destination area
- * as it is copied. The copy fails if any part of the source rectangle
- * lies outside the bounds of the source image, or if any of the width
- * or height arguments are negative.
- *
- * @param image the source image
- * @param srcX the x coordinate in the source image to copy from
- * @param srcY the y coordinate in the source image to copy from
- * @param srcWidth the width in pixels to copy from the source
- * @param srcHeight the height in pixels to copy from the source
- * @param destX the x coordinate in the destination to copy to
- * @param destY the y coordinate in the destination to copy to
- * @param destWidth the width in pixels of the destination rectangle
- * @param destHeight the height in pixels of the destination rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if any of the width or height arguments are negative.
- * <li>ERROR_INVALID_ARGUMENT - if the source rectangle is not contained within the bounds of the source image</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- */
-public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (srcWidth == 0 || srcHeight == 0 || destWidth == 0 || destHeight == 0) return;
- if (srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 || destWidth < 0 || destHeight < 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- drawImage(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false);
-}
-
-void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
- int[] width = new int[1];
- int[] height = new int[1];
- OS.gdk_drawable_get_size(srcImage.pixmap, width, height);
- int imgWidth = width[0];
- int imgHeight = height[0];
- if (simple) {
- srcWidth = destWidth = imgWidth;
- srcHeight = destHeight = imgHeight;
- } else {
- simple = srcX == 0 && srcY == 0 &&
- srcWidth == destWidth && destWidth == imgWidth &&
- srcHeight == destHeight && destHeight == imgHeight;
- if (srcX + srcWidth > imgWidth || srcY + srcHeight > imgHeight) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- if (data.alpha != 0) {
- srcImage.createSurface();
- Cairo.cairo_save(cairo);
- if ((data.style & SWT.MIRRORED) != 0) {
- Cairo.cairo_scale(cairo, -1f, 1);
- Cairo.cairo_translate(cairo, - 2 * destX - destWidth, 0);
- }
- Cairo.cairo_rectangle(cairo, destX , destY, destWidth, destHeight);
- Cairo.cairo_clip(cairo);
- Cairo.cairo_translate(cairo, destX - srcX, destY - srcY);
- if (srcWidth != destWidth || srcHeight != destHeight) {
- Cairo.cairo_scale(cairo, destWidth / (float)srcWidth, destHeight / (float)srcHeight);
- }
- int filter = Cairo.CAIRO_FILTER_GOOD;
- switch (data.interpolation) {
- case SWT.DEFAULT: filter = Cairo.CAIRO_FILTER_GOOD; break;
- case SWT.NONE: filter = Cairo.CAIRO_FILTER_NEAREST; break;
- case SWT.LOW: filter = Cairo.CAIRO_FILTER_FAST; break;
- case SWT.HIGH: filter = Cairo.CAIRO_FILTER_BEST; break;
- }
- int /*long*/ pattern = Cairo.cairo_pattern_create_for_surface(srcImage.surface);
- if (pattern == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (srcWidth != destWidth || srcHeight != destHeight) {
- /*
- * Bug in Cairo. When drawing the image streched with an interpolation
- * alghorithm, the edges of the image are faded. This is not a bug, but
- * it is not desired. To avoid the faded edges, it should be possible to
- * use cairo_pattern_set_extend() to set the pattern extend to either
- * CAIRO_EXTEND_REFLECT or CAIRO_EXTEND_PAD, but these are not implemented
- * in some versions of cairo (1.2.x) and have bugs in others (in 1.4.2 it
- * draws with black edges). The fix is to implement CAIRO_EXTEND_REFLECT
- * by creating an image that is 3 times bigger than the original, drawing
- * the original image in every quadrant (with an appropriate transform) and
- * use this image as the pattern.
- *
- * NOTE: For some reaons, it is necessary to use CAIRO_EXTEND_PAD with
- * the image that was created or the edges are still faded.
- */
- if (Cairo.cairo_version () >= Cairo.CAIRO_VERSION_ENCODE(1, 4, 0)) {
- int /*long*/ surface = Cairo.cairo_image_surface_create(Cairo.CAIRO_FORMAT_ARGB32, imgWidth * 3, imgHeight * 3);
- int /*long*/ cr = Cairo.cairo_create(surface);
- Cairo.cairo_set_source_surface(cr, srcImage.surface, imgWidth, imgHeight);
- Cairo.cairo_paint(cr);
- Cairo.cairo_scale(cr, -1, -1);
- Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth, -imgHeight);
- Cairo.cairo_paint(cr);
- Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth * 3, -imgHeight);
- Cairo.cairo_paint(cr);
- Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth, -imgHeight * 3);
- Cairo.cairo_paint(cr);
- Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth * 3, -imgHeight * 3);
- Cairo.cairo_paint(cr);
- Cairo.cairo_scale(cr, 1, -1);
- Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth, imgHeight);
- Cairo.cairo_paint(cr);
- Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth * 3, imgHeight);
- Cairo.cairo_paint(cr);
- Cairo.cairo_scale(cr, -1, -1);
- Cairo.cairo_set_source_surface(cr, srcImage.surface, imgWidth, -imgHeight);
- Cairo.cairo_paint(cr);
- Cairo.cairo_set_source_surface(cr, srcImage.surface, imgWidth, -imgHeight * 3);
- Cairo.cairo_paint(cr);
- Cairo.cairo_destroy(cr);
- int /*long*/ newPattern = Cairo.cairo_pattern_create_for_surface(surface);
- Cairo.cairo_surface_destroy(surface);
- if (newPattern == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Cairo.cairo_pattern_destroy(pattern);
- pattern = newPattern;
- Cairo.cairo_pattern_set_extend(pattern, Cairo.CAIRO_EXTEND_PAD);
- double[] matrix = new double[6];
- Cairo.cairo_matrix_init_translate(matrix, imgWidth, imgHeight);
- Cairo.cairo_pattern_set_matrix(pattern, matrix);
- }
-// Cairo.cairo_pattern_set_extend(pattern, Cairo.CAIRO_EXTEND_REFLECT);
- }
- Cairo.cairo_pattern_set_filter(pattern, filter);
- Cairo.cairo_set_source(cairo, pattern);
- if (data.alpha != 0xFF) {
- Cairo.cairo_paint_with_alpha(cairo, data.alpha / (float)0xFF);
- } else {
- Cairo.cairo_paint(cairo);
- }
- Cairo.cairo_restore(cairo);
- Cairo.cairo_pattern_destroy(pattern);
- }
- return;
- }
- if (srcImage.alpha != -1 || srcImage.alphaData != null) {
- drawImageAlpha(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight);
- } else if (srcImage.transparentPixel != -1 || srcImage.mask != 0) {
- drawImageMask(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight);
- } else {
- drawImage(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight);
- }
-}
-void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight) {
- if (srcWidth == destWidth && srcHeight == destHeight) {
- OS.gdk_draw_drawable(data.drawable, handle, srcImage.pixmap, srcX, srcY, destX, destY, destWidth, destHeight);
- } else {
- if (device.useXRender) {
- drawImageXRender(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, 0, -1);
- return;
- }
- int /*long*/ pixbuf = scale(srcImage.pixmap, srcX, srcY, srcWidth, srcHeight, destWidth, destHeight);
- if (pixbuf != 0) {
- OS.gdk_pixbuf_render_to_drawable(pixbuf, data.drawable, handle, 0, 0, destX, destY, destWidth, destHeight, OS.GDK_RGB_DITHER_NORMAL, 0, 0);
- OS.g_object_unref(pixbuf);
- }
- }
-}
-void drawImageAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight) {
- if (srcImage.alpha == 0) return;
- if (srcImage.alpha == 255) {
- drawImage(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight);
- return;
- }
- if (device.useXRender) {
- drawImageXRender(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, srcImage.mask, OS.PictStandardA8);
- return;
- }
- int /*long*/ pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, true, 8, srcWidth, srcHeight);
- if (pixbuf == 0) return;
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_pixbuf_get_from_drawable(pixbuf, srcImage.pixmap, colormap, srcX, srcY, 0, 0, srcWidth, srcHeight);
- int stride = OS.gdk_pixbuf_get_rowstride(pixbuf);
- int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf);
- byte[] line = new byte[stride];
- byte alpha = (byte)srcImage.alpha;
- byte[] alphaData = srcImage.alphaData;
- for (int y=0; y<srcHeight; y++) {
- int alphaIndex = (y + srcY) * imgWidth + srcX;
- OS.memmove(line, pixels + (y * stride), stride);
- for (int x=3; x<stride; x+=4) {
- line[x] = alphaData == null ? alpha : alphaData[alphaIndex++];
- }
- OS.memmove(pixels + (y * stride), line, stride);
- }
- if (srcWidth != destWidth || srcHeight != destHeight) {
- int /*long*/ scaledPixbuf = OS.gdk_pixbuf_scale_simple(pixbuf, destWidth, destHeight, OS.GDK_INTERP_BILINEAR);
- OS.g_object_unref(pixbuf);
- if (scaledPixbuf == 0) return;
- pixbuf = scaledPixbuf;
- }
- /*
- * Feature in GTK. gdk_draw_pixbuf was introduced in GTK+ 2.2.0 and
- * supports clipping.
- */
- if (OS.GTK_VERSION >= OS.VERSION (2, 2, 0)) {
- OS.gdk_draw_pixbuf(data.drawable, handle, pixbuf, 0, 0, destX, destY, destWidth, destHeight, OS.GDK_RGB_DITHER_NORMAL, 0, 0);
- } else {
- OS.gdk_pixbuf_render_to_drawable_alpha(pixbuf, data.drawable, 0, 0, destX, destY, destWidth, destHeight, OS.GDK_PIXBUF_ALPHA_BILEVEL, 128, OS.GDK_RGB_DITHER_NORMAL, 0, 0);
- }
- OS.g_object_unref(pixbuf);
-}
-void drawImageMask(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight) {
- int /*long*/ drawable = data.drawable;
- int /*long*/ colorPixmap = srcImage.pixmap;
- /* Generate the mask if necessary. */
- if (srcImage.transparentPixel != -1) srcImage.createMask();
- int /*long*/ maskPixmap = srcImage.mask;
-
- if (device.useXRender) {
- drawImageXRender(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, maskPixmap, OS.PictStandardA1);
- } else {
- if (srcWidth != destWidth || srcHeight != destHeight) {
- int /*long*/ pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, true, 8, srcWidth, srcHeight);
- if (pixbuf != 0) {
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_pixbuf_get_from_drawable(pixbuf, colorPixmap, colormap, srcX, srcY, 0, 0, srcWidth, srcHeight);
- int /*long*/ maskPixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, srcWidth, srcHeight);
- if (maskPixbuf != 0) {
- OS.gdk_pixbuf_get_from_drawable(maskPixbuf, maskPixmap, 0, srcX, srcY, 0, 0, srcWidth, srcHeight);
- int stride = OS.gdk_pixbuf_get_rowstride(pixbuf);
- int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf);
- byte[] line = new byte[stride];
- int maskStride = OS.gdk_pixbuf_get_rowstride(maskPixbuf);
- int /*long*/ maskPixels = OS.gdk_pixbuf_get_pixels(maskPixbuf);
- byte[] maskLine = new byte[maskStride];
- for (int y=0; y<srcHeight; y++) {
- int /*long*/ offset = pixels + (y * stride);
- OS.memmove(line, offset, stride);
- int /*long*/ maskOffset = maskPixels + (y * maskStride);
- OS.memmove(maskLine, maskOffset, maskStride);
- for (int x=0; x<srcWidth; x++) {
- if (maskLine[x * 3] == 0) {
- line[x*4+3] = 0;
- }
- }
- OS.memmove(offset, line, stride);
- }
- OS.g_object_unref(maskPixbuf);
- int /*long*/ scaledPixbuf = OS.gdk_pixbuf_scale_simple(pixbuf, destWidth, destHeight, OS.GDK_INTERP_BILINEAR);
- if (scaledPixbuf != 0) {
- int /*long*/[] colorBuffer = new int /*long*/[1];
- int /*long*/[] maskBuffer = new int /*long*/[1];
- OS.gdk_pixbuf_render_pixmap_and_mask(scaledPixbuf, colorBuffer, maskBuffer, 128);
- colorPixmap = colorBuffer[0];
- maskPixmap = maskBuffer[0];
- OS.g_object_unref(scaledPixbuf);
- }
- }
- OS.g_object_unref(pixbuf);
- }
- srcX = 0;
- srcY = 0;
- srcWidth = destWidth;
- srcHeight = destHeight;
- }
-
- /* Merge clipping with mask if necessary */
- if (data.clipRgn != 0) {
- int newWidth = srcX + srcWidth;
- int newHeight = srcY + srcHeight;
- int bytesPerLine = (newWidth + 7) / 8;
- byte[] maskData = new byte[bytesPerLine * newHeight];
- int /*long*/ mask = OS.gdk_bitmap_create_from_data(0, maskData, newWidth, newHeight);
- if (mask != 0) {
- int /*long*/ gc = OS.gdk_gc_new(mask);
- OS.gdk_region_offset(data.clipRgn, -destX + srcX, -destY + srcY);
- OS.gdk_gc_set_clip_region(gc, data.clipRgn);
- OS.gdk_region_offset(data.clipRgn, destX - srcX, destY - srcY);
- GdkColor color = new GdkColor();
- color.pixel = 1;
- OS.gdk_gc_set_foreground(gc, color);
- OS.gdk_draw_rectangle(mask, gc, 1, 0, 0, newWidth, newHeight);
- OS.gdk_gc_set_function(gc, OS.GDK_AND);
- OS.gdk_draw_drawable(mask, gc, maskPixmap, 0, 0, 0, 0, newWidth, newHeight);
- OS.g_object_unref(gc);
- if (maskPixmap != 0 && srcImage.mask != maskPixmap) OS.g_object_unref(maskPixmap);
- maskPixmap = mask;
- }
- }
-
- /* Blit cliping the mask */
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- OS.gdk_gc_set_clip_mask(handle, maskPixmap);
- OS.gdk_gc_set_clip_origin(handle, destX - srcX, destY - srcY);
- OS.gdk_draw_drawable(drawable, handle, colorPixmap, srcX, srcY, destX, destY, srcWidth, srcHeight);
- OS.gdk_gc_set_values(handle, values, OS.GDK_GC_CLIP_MASK | OS.GDK_GC_CLIP_X_ORIGIN | OS.GDK_GC_CLIP_Y_ORIGIN);
- if (data.clipRgn != 0) OS.gdk_gc_set_clip_region(handle, data.clipRgn);
- }
-
- /* Destroy scaled pixmaps */
- if (colorPixmap != 0 && srcImage.pixmap != colorPixmap) OS.g_object_unref(colorPixmap);
- if (maskPixmap != 0 && srcImage.mask != maskPixmap) OS.g_object_unref(maskPixmap);
- /* Destroy the image mask if the there is a GC created on the image */
- if (srcImage.transparentPixel != -1 && srcImage.memGC != null) srcImage.destroyMask();
-}
-void drawImageXRender(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int /*long*/ maskPixmap, int maskType) {
- int translateX = 0, translateY = 0;
- int /*long*/ drawable = data.drawable;
- if (data.image == null && !data.realDrawable) {
- int[] x = new int[1], y = new int[1];
- int /*long*/ [] real_drawable = new int /*long*/ [1];
- OS.gdk_window_get_internal_paint_info(drawable, real_drawable, x, y);
- drawable = real_drawable[0];
- translateX = -x[0];
- translateY = -y[0];
- }
- int /*long*/ xDisplay = OS.GDK_DISPLAY();
- int /*long*/ maskPict = 0;
- if (maskPixmap != 0) {
- int attribCount = 0;
- XRenderPictureAttributes attrib = null;
- if (srcImage.alpha != -1) {
- attribCount = 1;
- attrib = new XRenderPictureAttributes();
- attrib.repeat = true;
- }
- maskPict = OS.XRenderCreatePicture(xDisplay, OS.gdk_x11_drawable_get_xid(maskPixmap), OS.XRenderFindStandardFormat(xDisplay, maskType), attribCount, attrib);
- if (maskPict == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- }
- int /*long*/ format = OS.XRenderFindVisualFormat(xDisplay, OS.gdk_x11_visual_get_xvisual(OS.gdk_visual_get_system()));
- int /*long*/ destPict = OS.XRenderCreatePicture(xDisplay, OS.gdk_x11_drawable_get_xid(drawable), format, 0, null);
- if (destPict == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ srcPict = OS.XRenderCreatePicture(xDisplay, OS.gdk_x11_drawable_get_xid(srcImage.pixmap), format, 0, null);
- if (srcPict == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (srcWidth != destWidth || srcHeight != destHeight) {
- int[] transform = new int[]{(int)(((float)srcWidth / destWidth) * 65536), 0, 0, 0, (int)(((float)srcHeight / destHeight) * 65536), 0, 0, 0, 65536};
- OS.XRenderSetPictureTransform(xDisplay, srcPict, transform);
- if (maskPict != 0) OS.XRenderSetPictureTransform(xDisplay, maskPict, transform);
- srcX *= destWidth / (float)srcWidth;
- srcY *= destHeight / (float)srcHeight;
- }
- int /*long*/ clipping = data.clipRgn;
- if (data.damageRgn != 0) {
- if (clipping == 0) {
- clipping = data.damageRgn;
- } else {
- clipping = OS.gdk_region_new();
- OS.gdk_region_union(clipping, data.clipRgn);
- OS.gdk_region_intersect(clipping, data.damageRgn);
- }
- }
- if (clipping != 0) {
- int[] nRects = new int[1];
- int /*long*/[] rects = new int /*long*/[1];
- OS.gdk_region_get_rectangles(clipping, rects, nRects);
- GdkRectangle rect = new GdkRectangle();
- short[] xRects = new short[nRects[0] * 4];
- for (int i=0, j=0; i<nRects[0]; i++, j+=4) {
- OS.memmove(rect, rects[0] + (i * GdkRectangle.sizeof), GdkRectangle.sizeof);
- xRects[j] = (short)rect.x;
- xRects[j+1] = (short)rect.y;
- xRects[j+2] = (short)rect.width;
- xRects[j+3] = (short)rect.height;
- }
- OS.XRenderSetPictureClipRectangles(xDisplay, destPict, translateX, translateY, xRects, nRects[0]);
- if (clipping != data.clipRgn && clipping != data.damageRgn) {
- OS.gdk_region_destroy(clipping);
- }
- if (rects[0] != 0) OS.g_free(rects[0]);
- }
- OS.XRenderComposite(xDisplay, maskPict != 0 ? OS.PictOpOver : OS.PictOpSrc, srcPict, maskPict, destPict, srcX, srcY, srcX, srcY, destX + translateX, destY + translateY, destWidth, destHeight);
- OS.XRenderFreePicture(xDisplay, destPict);
- OS.XRenderFreePicture(xDisplay, srcPict);
- if (maskPict != 0) OS.XRenderFreePicture(xDisplay, maskPict);
-}
-int /*long*/ scale(int /*long*/ src, int srcX, int srcY, int srcWidth, int srcHeight, int destWidth, int destHeight) {
- int /*long*/ pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, srcWidth, srcHeight);
- if (pixbuf == 0) return 0;
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_pixbuf_get_from_drawable(pixbuf, src, colormap, srcX, srcY, 0, 0, srcWidth, srcHeight);
- int /*long*/ scaledPixbuf = OS.gdk_pixbuf_scale_simple(pixbuf, destWidth, destHeight, OS.GDK_INTERP_BILINEAR);
- OS.g_object_unref(pixbuf);
- return scaledPixbuf;
-}
-
-/**
- * Draws a line, using the foreground color, between the points
- * (<code>x1</code>, <code>y1</code>) and (<code>x2</code>, <code>y2</code>).
- *
- * @param x1 the first point's x coordinate
- * @param y1 the first point's y coordinate
- * @param x2 the second point's x coordinate
- * @param y2 the second point's y coordinate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawLine(int x1, int y1, int x2, int y2) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
- Cairo.cairo_move_to(cairo, x1 + xOffset, y1 + yOffset);
- Cairo.cairo_line_to(cairo, x2 + xOffset, y2 + yOffset);
- Cairo.cairo_stroke(cairo);
- return;
- }
- OS.gdk_draw_line (data.drawable, handle, x1, y1, x2, y2);
-}
-
-/**
- * Draws the outline of an oval, using the foreground color,
- * within the specified rectangular area.
- * <p>
- * The result is a circle or ellipse that fits within the
- * rectangle specified by the <code>x</code>, <code>y</code>,
- * <code>width</code>, and <code>height</code> arguments.
- * </p><p>
- * The oval covers an area that is <code>width + 1</code>
- * pixels wide and <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper left corner of the oval to be drawn
- * @param y the y coordinate of the upper left corner of the oval to be drawn
- * @param width the width of the oval to be drawn
- * @param height the height of the oval to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawOval(int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
- if (width == height) {
- Cairo.cairo_arc_negative(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f, width / 2f, 0, -2 * (float)Compatibility.PI);
- } else {
- Cairo.cairo_save(cairo);
- Cairo.cairo_translate(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f);
- Cairo.cairo_scale(cairo, width / 2f, height / 2f);
- Cairo.cairo_arc_negative(cairo, 0, 0, 1, 0, -2 * (float)Compatibility.PI);
- Cairo.cairo_restore(cairo);
- }
- Cairo.cairo_stroke(cairo);
- return;
- }
- OS.gdk_draw_arc(data.drawable, handle, 0, x, y, width, height, 0, 23040);
-}
-
-/**
- * Draws the path described by the parameter.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the path to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- *
- * @since 3.1
- */
-public void drawPath(Path path) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- initCairo();
- checkGC(DRAW);
- int /*long*/ cairo = data.cairo;
- Cairo.cairo_save(cairo);
- double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
- Cairo.cairo_translate(cairo, xOffset, yOffset);
- int /*long*/ copy = Cairo.cairo_copy_path(path.handle);
- if (copy == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Cairo.cairo_append_path(cairo, copy);
- Cairo.cairo_path_destroy(copy);
- Cairo.cairo_stroke(cairo);
- Cairo.cairo_restore(cairo);
-}
-
-/**
- * Draws a pixel, using the foreground color, at the specified
- * point (<code>x</code>, <code>y</code>).
- * <p>
- * Note that the receiver's line attributes do not affect this
- * operation.
- * </p>
- *
- * @param x the point's x coordinate
- * @param y the point's y coordinate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void drawPoint (int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- Cairo.cairo_rectangle(cairo, x, y, 1, 1);
- Cairo.cairo_fill(cairo);
- return;
- }
- OS.gdk_draw_point(data.drawable, handle, x, y);
-}
-
-/**
- * Draws the closed polygon which is defined by the specified array
- * of integer coordinates, using the receiver's foreground color. The array
- * contains alternating x and y values which are considered to represent
- * points which are the vertices of the polygon. Lines are drawn between
- * each consecutive pair, and between the first pair and last pair in the
- * array.
- *
- * @param pointArray an array of alternating x and y values which are the vertices of the polygon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT if pointArray is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawPolygon(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(DRAW);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- drawPolyline(cairo, pointArray, true);
- Cairo.cairo_stroke(cairo);
- return;
- }
- OS.gdk_draw_polygon(data.drawable, handle, 0, pointArray, pointArray.length / 2);
-}
-
-/**
- * Draws the polyline which is defined by the specified array
- * of integer coordinates, using the receiver's foreground color. The array
- * contains alternating x and y values which are considered to represent
- * points which are the corners of the polyline. Lines are drawn between
- * each consecutive pair, but not between the first pair and last pair in
- * the array.
- *
- * @param pointArray an array of alternating x and y values which are the corners of the polyline
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawPolyline(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(DRAW);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- drawPolyline(cairo, pointArray, false);
- Cairo.cairo_stroke(cairo);
- return;
- }
- OS.gdk_draw_lines(data.drawable, handle, pointArray, pointArray.length / 2);
-}
-
-void drawPolyline(int /*long*/ cairo, int[] pointArray, boolean close) {
- int count = pointArray.length / 2;
- if (count == 0) return;
- double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
- Cairo.cairo_move_to(cairo, pointArray[0] + xOffset, pointArray[1] + yOffset);
- for (int i = 1, j=2; i < count; i++, j += 2) {
- Cairo.cairo_line_to(cairo, pointArray[j] + xOffset, pointArray[j + 1] + yOffset);
- }
- if (close) Cairo.cairo_close_path(cairo);
-}
-
-/**
- * Draws the outline of the rectangle specified by the arguments,
- * using the receiver's foreground color. The left and right edges
- * of the rectangle are at <code>x</code> and <code>x + width</code>.
- * The top and bottom edges are at <code>y</code> and <code>y + height</code>.
- *
- * @param x the x coordinate of the rectangle to be drawn
- * @param y the y coordinate of the rectangle to be drawn
- * @param width the width of the rectangle to be drawn
- * @param height the height of the rectangle to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRectangle(int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
- Cairo.cairo_rectangle(cairo, x + xOffset, y + yOffset, width, height);
- Cairo.cairo_stroke(cairo);
- return;
- }
- OS.gdk_draw_rectangle(data.drawable, handle, 0, x, y, width, height);
-}
-
-/**
- * Draws the outline of the specified rectangle, using the receiver's
- * foreground color. The left and right edges of the rectangle are at
- * <code>rect.x</code> and <code>rect.x + rect.width</code>. The top
- * and bottom edges are at <code>rect.y</code> and
- * <code>rect.y + rect.height</code>.
- *
- * @param rect the rectangle to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRectangle(Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- drawRectangle (rect.x, rect.y, rect.width, rect.height);
-}
-/**
- * Draws the outline of the round-cornered rectangle specified by
- * the arguments, using the receiver's foreground color. The left and
- * right edges of the rectangle are at <code>x</code> and <code>x + width</code>.
- * The top and bottom edges are at <code>y</code> and <code>y + height</code>.
- * The <em>roundness</em> of the corners is specified by the
- * <code>arcWidth</code> and <code>arcHeight</code> arguments, which
- * are respectively the width and height of the ellipse used to draw
- * the corners.
- *
- * @param x the x coordinate of the rectangle to be drawn
- * @param y the y coordinate of the rectangle to be drawn
- * @param width the width of the rectangle to be drawn
- * @param height the height of the rectangle to be drawn
- * @param arcWidth the width of the arc
- * @param arcHeight the height of the arc
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- int nx = x;
- int ny = y;
- int nw = width;
- int nh = height;
- int naw = arcWidth;
- int nah = arcHeight;
- if (nw < 0) {
- nw = 0 - nw;
- nx = nx - nw;
- }
- if (nh < 0) {
- nh = 0 - nh;
- ny = ny -nh;
- }
- if (naw < 0) naw = 0 - naw;
- if (nah < 0) nah = 0 - nah;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
- if (naw == 0 || nah == 0) {
- Cairo.cairo_rectangle(cairo, x + xOffset, y + yOffset, width, height);
- } else {
- float naw2 = naw / 2f;
- float nah2 = nah / 2f;
- float fw = nw / naw2;
- float fh = nh / nah2;
- Cairo.cairo_save(cairo);
- Cairo.cairo_translate(cairo, nx + xOffset, ny + yOffset);
- Cairo.cairo_scale(cairo, naw2, nah2);
- Cairo.cairo_move_to(cairo, fw - 1, 0);
- Cairo.cairo_arc(cairo, fw - 1, 1, 1, Compatibility.PI + Compatibility.PI/2.0, Compatibility.PI*2.0);
- Cairo.cairo_arc(cairo, fw - 1, fh - 1, 1, 0, Compatibility.PI/2.0);
- Cairo.cairo_arc(cairo, 1, fh - 1, 1, Compatibility.PI/2, Compatibility.PI);
- Cairo.cairo_arc(cairo, 1, 1, 1, Compatibility.PI, 270.0*Compatibility.PI/180.0);
- Cairo.cairo_close_path(cairo);
- Cairo.cairo_restore(cairo);
- }
- Cairo.cairo_stroke(cairo);
- return;
- }
- int naw2 = naw / 2;
- int nah2 = nah / 2;
- int /*long*/ drawable = data.drawable;
- if (nw > naw) {
- if (nh > nah) {
- OS.gdk_draw_arc(drawable, handle, 0, nx, ny, naw, nah, 5760, 5760);
- OS.gdk_draw_line(drawable, handle, nx + naw2, ny, nx + nw - naw2, ny);
- OS.gdk_draw_arc(drawable, handle, 0, nx + nw - naw, ny, naw, nah, 0, 5760);
- OS.gdk_draw_line(drawable, handle, nx + nw, ny + nah2, nx + nw, ny + nh - nah2);
- OS.gdk_draw_arc(drawable, handle, 0, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760);
- OS.gdk_draw_line(drawable,handle, nx + naw2, ny + nh, nx + nw - naw2, ny + nh);
- OS.gdk_draw_arc(drawable, handle, 0, nx, ny + nh - nah, naw, nah, 11520, 5760);
- OS.gdk_draw_line(drawable, handle, nx, ny + nah2, nx, ny + nh - nah2);
- } else {
- OS.gdk_draw_arc(drawable, handle, 0, nx, ny, naw, nh, 5760, 11520);
- OS.gdk_draw_line(drawable, handle, nx + naw2, ny, nx + nw - naw2, ny);
- OS.gdk_draw_arc(drawable, handle, 0, nx + nw - naw, ny, naw, nh, 17280, 11520);
- OS.gdk_draw_line(drawable,handle, nx + naw2, ny + nh, nx + nw - naw2, ny + nh);
- }
- } else {
- if (nh > nah) {
- OS.gdk_draw_arc(drawable, handle, 0, nx, ny, nw, nah, 0, 11520);
- OS.gdk_draw_line(drawable, handle, nx + nw, ny + nah2, nx + nw, ny + nh - nah2);
- OS.gdk_draw_arc(drawable, handle, 0, nx, ny + nh - nah, nw, nah, 11520, 11520);
- OS.gdk_draw_line(drawable,handle, nx, ny + nah2, nx, ny + nh - nah2);
- } else {
- OS.gdk_draw_arc(drawable, handle, 0, nx, ny, nw, nh, 0, 23040);
- }
- }
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. No tab expansion or carriage return processing
- * will be performed. The background of the rectangular area where
- * the string is being drawn will be filled with the receiver's
- * background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawString (String string, int x, int y) {
- drawString(string, x, y, false);
-}
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. No tab expansion or carriage return processing
- * will be performed. If <code>isTransparent</code> is <code>true</code>,
- * then the background of the rectangular area where the string is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawString(String string, int x, int y, boolean isTransparent) {
- drawText(string, x, y, isTransparent ? SWT.DRAW_TRANSPARENT : 0);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion and carriage return processing
- * are performed. The background of the rectangular area where
- * the text is being drawn will be filled with the receiver's
- * background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText(String string, int x, int y) {
- drawText(string, x, y, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion and carriage return processing
- * are performed. If <code>isTransparent</code> is <code>true</code>,
- * then the background of the rectangular area where the text is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText(String string, int x, int y, boolean isTransparent) {
- int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB;
- if (isTransparent) flags |= SWT.DRAW_TRANSPARENT;
- drawText(string, x, y, flags);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion, line delimiter and mnemonic
- * processing are performed according to the specified flags. If
- * <code>flags</code> includes <code>DRAW_TRANSPARENT</code>,
- * then the background of the rectangular area where the text is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- * <p>
- * The parameter <code>flags</code> may be a combination of:
- * <dl>
- * <dt><b>DRAW_DELIMITER</b></dt>
- * <dd>draw multiple lines</dd>
- * <dt><b>DRAW_TAB</b></dt>
- * <dd>expand tabs</dd>
- * <dt><b>DRAW_MNEMONIC</b></dt>
- * <dd>underline the mnemonic character</dd>
- * <dt><b>DRAW_TRANSPARENT</b></dt>
- * <dd>transparent background</dd>
- * </dl>
- * </p>
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param flags the flags specifying how to process the text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText (String string, int x, int y, int flags) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (string.length() == 0) return;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- if (OS.GTK_VERSION < OS.VERSION(2, 8, 0)) {
- //TODO - honor flags
- checkGC(FOREGROUND | FONT);
- cairo_font_extents_t extents = new cairo_font_extents_t();
- Cairo.cairo_font_extents(cairo, extents);
- double baseline = y + extents.ascent;
- Cairo.cairo_move_to(cairo, x, baseline);
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
- Cairo.cairo_show_text(cairo, buffer);
- Cairo.cairo_new_path(cairo);
- return;
- }
- }
- setString(string, flags);
- if (cairo != 0) {
- checkGC(FONT);
- if ((flags & SWT.DRAW_TRANSPARENT) == 0) {
- checkGC(BACKGROUND);
- if (data.stringWidth == -1) {
- computeStringSize();
- }
- Cairo.cairo_rectangle(cairo, x, y, data.stringWidth, data.stringHeight);
- Cairo.cairo_fill(cairo);
- }
- checkGC(FOREGROUND);
- if ((data.style & SWT.MIRRORED) != 0) {
- Cairo.cairo_save(cairo);
- if (data.stringWidth == -1) {
- computeStringSize();
- }
- Cairo.cairo_scale(cairo, -1f, 1);
- Cairo.cairo_translate(cairo, -2 * x - data.stringWidth, 0);
- }
- Cairo.cairo_move_to(cairo, x, y);
- OS.pango_cairo_show_layout(cairo, data.layout);
- if ((data.style & SWT.MIRRORED) != 0) {
- Cairo.cairo_restore(cairo);
- }
- Cairo.cairo_new_path(cairo);
- return;
- }
- checkGC(FOREGROUND | FONT | BACKGROUND_BG);
- GdkColor background = null;
- if ((flags & SWT.DRAW_TRANSPARENT) == 0) background = data.background;
- if (!data.xorMode) {
- OS.gdk_draw_layout_with_colors(data.drawable, handle, x, y, data.layout, null, background);
- } else {
- int /*long*/ layout = data.layout;
- if (data.stringWidth == -1) {
- computeStringSize();
- }
- int /*long*/ pixmap = OS.gdk_pixmap_new(OS.GDK_ROOT_PARENT(), data.stringWidth, data.stringHeight, -1);
- if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ gdkGC = OS.gdk_gc_new(pixmap);
- if (gdkGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- GdkColor black = new GdkColor();
- OS.gdk_gc_set_foreground(gdkGC, black);
- OS.gdk_draw_rectangle(pixmap, gdkGC, 1, 0, 0, data.stringWidth, data.stringHeight);
- OS.gdk_gc_set_foreground(gdkGC, data.foreground);
- OS.gdk_draw_layout_with_colors(pixmap, gdkGC, 0, 0, layout, null, background);
- OS.g_object_unref(gdkGC);
- OS.gdk_draw_drawable(data.drawable, handle, pixmap, 0, 0, x, y, data.stringWidth, data.stringHeight);
- OS.g_object_unref(pixmap);
- }
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals(Object object) {
- if (object == this) return true;
- if (!(object instanceof GC)) return false;
- return handle == ((GC)object).handle;
-}
-
-/**
- * Fills the interior of a circular or elliptical arc within
- * the specified rectangular area, with the receiver's background
- * color.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees, using the current color.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc to be filled
- * @param y the y coordinate of the upper-left corner of the arc to be filled
- * @param width the width of the arc to be filled
- * @param height the height of the arc to be filled
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawArc
- */
-public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- if (width == height) {
- if (arcAngle >= 0) {
- Cairo.cairo_arc_negative(cairo, x + width / 2f, y + height / 2f, width / 2f, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- } else {
- Cairo.cairo_arc(cairo, x + width / 2f, y + height / 2f, width / 2f, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- }
- Cairo.cairo_line_to(cairo, x + width / 2f, y + height / 2f);
- } else {
- Cairo.cairo_save(cairo);
- Cairo.cairo_translate(cairo, x + width / 2f, y + height / 2f);
- Cairo.cairo_scale(cairo, width / 2f, height / 2f);
- if (arcAngle >= 0) {
- Cairo.cairo_arc_negative(cairo, 0, 0, 1, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- } else {
- Cairo.cairo_arc(cairo, 0, 0, 1, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- }
- Cairo.cairo_line_to(cairo, 0, 0);
- Cairo.cairo_restore(cairo);
- }
- Cairo.cairo_fill(cairo);
- return;
- }
- OS.gdk_draw_arc(data.drawable, handle, 1, x, y, width, height, startAngle * 64, arcAngle * 64);
-}
-
-/**
- * Fills the interior of the specified rectangle with a gradient
- * sweeping from left to right or top to bottom progressing
- * from the receiver's foreground color to its background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled, may be negative
- * (inverts direction of gradient if horizontal)
- * @param height the height of the rectangle to be filled, may be negative
- * (inverts direction of gradient if vertical)
- * @param vertical if true sweeps from top to bottom, else
- * sweeps from left to right
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if ((width == 0) || (height == 0)) return;
-
- /* Rewrite this to use GdkPixbuf */
-
- RGB backgroundRGB, foregroundRGB;
- backgroundRGB = getBackground().getRGB();
- foregroundRGB = getForeground().getRGB();
-
- RGB fromRGB, toRGB;
- fromRGB = foregroundRGB;
- toRGB = backgroundRGB;
- boolean swapColors = false;
- if (width < 0) {
- x += width; width = -width;
- if (! vertical) swapColors = true;
- }
- if (height < 0) {
- y += height; height = -height;
- if (vertical) swapColors = true;
- }
- if (swapColors) {
- fromRGB = backgroundRGB;
- toRGB = foregroundRGB;
- }
- if (fromRGB.equals(toRGB)) {
- fillRectangle(x, y, width, height);
- return;
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- int /*long*/ pattern;
- if (vertical) {
- pattern = Cairo.cairo_pattern_create_linear (0.0, 0.0, 0.0, 1.0);
- } else {
- pattern = Cairo.cairo_pattern_create_linear (0.0, 0.0, 1.0, 0.0);
- }
- Cairo.cairo_pattern_add_color_stop_rgba (pattern, 0, fromRGB.red / 255f, fromRGB.green / 255f, fromRGB.blue / 255f, data.alpha / 255f);
- Cairo.cairo_pattern_add_color_stop_rgba (pattern, 1, toRGB.red / 255f, toRGB.green / 255f, toRGB.blue / 255f, data.alpha / 255f);
- Cairo.cairo_save(cairo);
- Cairo.cairo_translate(cairo, x, y);
- Cairo.cairo_scale(cairo, width, height);
- Cairo.cairo_rectangle(cairo, 0, 0, 1, 1);
- Cairo.cairo_set_source(cairo, pattern);
- Cairo.cairo_fill(cairo);
- Cairo.cairo_restore(cairo);
- Cairo.cairo_pattern_destroy(pattern);
- return;
- }
- ImageData.fillGradientRectangle(this, data.device,
- x, y, width, height, vertical, fromRGB, toRGB,
- 8, 8, 8);
-}
-
-/**
- * Fills the interior of an oval, within the specified
- * rectangular area, with the receiver's background
- * color.
- *
- * @param x the x coordinate of the upper left corner of the oval to be filled
- * @param y the y coordinate of the upper left corner of the oval to be filled
- * @param width the width of the oval to be filled
- * @param height the height of the oval to be filled
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawOval
- */
-public void fillOval(int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- if (width == height) {
- Cairo.cairo_arc_negative(cairo, x + width / 2f, y + height / 2f, width / 2f, 0, 2 * (float)Compatibility.PI);
- } else {
- Cairo.cairo_save(cairo);
- Cairo.cairo_translate(cairo, x + width / 2f, y + height / 2f);
- Cairo.cairo_scale(cairo, width / 2f, height / 2f);
- Cairo.cairo_arc_negative(cairo, 0, 0, 1, 0, 2 * (float)Compatibility.PI);
- Cairo.cairo_restore(cairo);
- }
- Cairo.cairo_fill(cairo);
- return;
- }
- OS.gdk_draw_arc(data.drawable, handle, 1, x, y, width, height, 0, 23040);
-}
-
-/**
- * Fills the path described by the parameter.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the path to fill
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- *
- * @since 3.1
- */
-public void fillPath (Path path) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- initCairo();
- checkGC(FILL);
- int /*long*/ cairo = data.cairo;
- int /*long*/ copy = Cairo.cairo_copy_path(path.handle);
- if (copy == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Cairo.cairo_append_path(cairo, copy);
- Cairo.cairo_path_destroy(copy);
- Cairo.cairo_fill(cairo);
-}
-
-/**
- * Fills the interior of the closed polygon which is defined by the
- * specified array of integer coordinates, using the receiver's
- * background color. The array contains alternating x and y values
- * which are considered to represent points which are the vertices of
- * the polygon. Lines are drawn between each consecutive pair, and
- * between the first pair and last pair in the array.
- *
- * @param pointArray an array of alternating x and y values which are the vertices of the polygon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT if pointArray is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawPolygon
- */
-public void fillPolygon(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(FILL);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- drawPolyline(cairo, pointArray, true);
- Cairo.cairo_fill(cairo);
- return;
- }
- OS.gdk_draw_polygon(data.drawable, handle, 1, pointArray, pointArray.length / 2);
-}
-
-/**
- * Fills the interior of the rectangle specified by the arguments,
- * using the receiver's background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillRectangle(int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- Cairo.cairo_rectangle(cairo, x, y, width, height);
- Cairo.cairo_fill(cairo);
- return;
- }
- OS.gdk_draw_rectangle(data.drawable, handle, 1, x, y, width, height);
-}
-
-/**
- * Fills the interior of the specified rectangle, using the receiver's
- * background color.
- *
- * @param rect the rectangle to be filled
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillRectangle(Rectangle rect) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- fillRectangle(rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Fills the interior of the round-cornered rectangle specified by
- * the arguments, using the receiver's background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- * @param arcWidth the width of the arc
- * @param arcHeight the height of the arc
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRoundRectangle
- */
-public void fillRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- int nx = x;
- int ny = y;
- int nw = width;
- int nh = height;
- int naw = arcWidth;
- int nah = arcHeight;
- if (nw < 0) {
- nw = 0 - nw;
- nx = nx - nw;
- }
- if (nh < 0) {
- nh = 0 - nh;
- ny = ny -nh;
- }
- if (naw < 0) naw = 0 - naw;
- if (nah < 0) nah = 0 - nah;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- if (naw == 0 || nah == 0) {
- Cairo.cairo_rectangle(cairo, x, y, width, height);
- } else {
- float naw2 = naw / 2f;
- float nah2 = nah / 2f;
- float fw = nw / naw2;
- float fh = nh / nah2;
- Cairo.cairo_save(cairo);
- Cairo.cairo_translate(cairo, nx, ny);
- Cairo.cairo_scale(cairo, naw2, nah2);
- Cairo.cairo_move_to(cairo, fw - 1, 0);
- Cairo.cairo_arc(cairo, fw - 1, 1, 1, Compatibility.PI + Compatibility.PI/2.0, Compatibility.PI*2.0);
- Cairo.cairo_arc(cairo, fw - 1, fh - 1, 1, 0, Compatibility.PI/2.0);
- Cairo.cairo_arc(cairo, 1, fh - 1, 1, Compatibility.PI/2, Compatibility.PI);
- Cairo.cairo_arc(cairo, 1, 1, 1, Compatibility.PI, 270.0*Compatibility.PI/180.0);
- Cairo.cairo_close_path(cairo);
- Cairo.cairo_restore(cairo);
- }
- Cairo.cairo_fill(cairo);
- return;
- }
- int naw2 = naw / 2;
- int nah2 = nah / 2;
- int /*long*/ drawable = data.drawable;
- if (nw > naw) {
- if (nh > nah) {
- OS.gdk_draw_arc(drawable, handle, 1, nx, ny, naw, nah, 5760, 5760);
- OS.gdk_draw_rectangle(drawable, handle, 1, nx + naw2, ny, nw - naw2 * 2, nh);
- OS.gdk_draw_arc(drawable, handle, 1, nx + nw - naw, ny, naw, nah, 0, 5760);
- OS.gdk_draw_rectangle(drawable, handle, 1, nx, ny + nah2, naw2, nh - nah2 * 2);
- OS.gdk_draw_arc(drawable, handle, 1, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760);
- OS.gdk_draw_rectangle(drawable, handle, 1, nx + nw - naw2, ny + nah2, naw2, nh - nah2 * 2);
- OS.gdk_draw_arc(drawable, handle, 1, nx, ny + nh - nah, naw, nah, 11520, 5760);
- } else {
- OS.gdk_draw_arc(drawable, handle, 1, nx, ny, naw, nh, 5760, 11520);
- OS.gdk_draw_rectangle(drawable, handle, 1, nx + naw2, ny, nw - naw2 * 2, nh);
- OS.gdk_draw_arc(drawable, handle, 1, nx + nw - naw, ny, naw, nh, 17280, 11520);
- }
- } else {
- if (nh > nah) {
- OS.gdk_draw_arc(drawable, handle, 1, nx, ny, nw, nah, 0, 11520);
- OS.gdk_draw_rectangle(drawable, handle, 1, nx, ny + nah2, nw, nh - nah2 * 2);
- OS.gdk_draw_arc(drawable, handle, 1, nx, ny + nh - nah, nw, nah, 11520, 11520);
- } else {
- OS.gdk_draw_arc(drawable, handle, 1, nx, ny, nw, nh, 0, 23040);
- }
- }
-}
-
-int fixMnemonic (char [] buffer) {
- int i=0, j=0;
- int mnemonic=-1;
- while (i < buffer.length) {
- if ((buffer [j++] = buffer [i++]) == '&') {
- if (i == buffer.length) {continue;}
- if (buffer [i] == '&') {i++; continue;}
- if (mnemonic == -1) mnemonic = j;
- j--;
- }
- }
- while (j < buffer.length) buffer [j++] = 0;
- return mnemonic;
-}
-
-/**
- * Returns the <em>advance width</em> of the specified character in
- * the font which is currently selected into the receiver.
- * <p>
- * The advance width is defined as the horizontal distance the cursor
- * should move after printing the character in the selected font.
- * </p>
- *
- * @param ch the character to measure
- * @return the distance in the x direction to move past the character before painting the next
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getAdvanceWidth(char ch) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- //BOGUS
- return stringExtent(new String(new char[]{ch})).x;
-}
-
-/**
- * Returns <code>true</code> if receiver is using the operating system's
- * advanced graphics subsystem. Otherwise, <code>false</code> is returned
- * to indicate that normal graphics are in use.
- * <p>
- * Advanced graphics may not be installed for the operating system. In this
- * case, <code>false</code> is always returned. Some operating system have
- * only one graphics subsystem. If this subsystem supports advanced graphics,
- * then <code>true</code> is always returned. If any graphics operation such
- * as alpha, antialias, patterns, interpolation, paths, clipping or transformation
- * has caused the receiver to switch from regular to advanced graphics mode,
- * <code>true</code> is returned. If the receiver has been explicitly switched
- * to advanced mode and this mode is supported, <code>true</code> is returned.
- * </p>
- *
- * @return the advanced value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public boolean getAdvanced() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.cairo != 0;
-}
-
-/**
- * Returns the receiver's alpha value. The alpha value
- * is between 0 (transparent) and 255 (opaque).
- *
- * @return the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getAlpha() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.alpha;
-}
-
-/**
- * Returns the receiver's anti-aliasing setting value, which will be
- * one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code>. Note that this controls anti-aliasing for all
- * <em>non-text drawing</em> operations.
- *
- * @return the anti-aliasing setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getTextAntialias
- *
- * @since 3.1
- */
-public int getAntialias() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.cairo == 0) return SWT.DEFAULT;
- int antialias = Cairo.cairo_get_antialias(data.cairo);
- switch (antialias) {
- case Cairo.CAIRO_ANTIALIAS_DEFAULT: return SWT.DEFAULT;
- case Cairo.CAIRO_ANTIALIAS_NONE: return SWT.OFF;
- case Cairo.CAIRO_ANTIALIAS_GRAY:
- case Cairo.CAIRO_ANTIALIAS_SUBPIXEL: return SWT.ON;
- }
- return SWT.DEFAULT;
-}
-
-/**
- * Returns the background color.
- *
- * @return the receiver's background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getBackground() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return Color.gtk_new(data.device, data.background);
-}
-
-/**
- * Returns the background pattern. The default value is
- * <code>null</code>.
- *
- * @return the receiver's background pattern
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Pattern
- *
- * @since 3.1
- */
-public Pattern getBackgroundPattern() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.backgroundPattern;
-}
-
-/**
- * Returns the width of the specified character in the font
- * selected into the receiver.
- * <p>
- * The width is defined as the space taken up by the actual
- * character, not including the leading and tailing whitespace
- * or overhang.
- * </p>
- *
- * @param ch the character to measure
- * @return the width of the character
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getCharWidth(char ch) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- //BOGUS
- return stringExtent(new String(new char[]{ch})).x;
-}
-
-/**
- * Returns the bounding rectangle of the receiver's clipping
- * region. If no clipping region is set, the return value
- * will be a rectangle which covers the entire bounds of the
- * object the receiver is drawing on.
- *
- * @return the bounding rectangle of the clipping region
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getClipping() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- /* Calculate visible bounds in device space */
- int x = 0, y = 0, width = 0, height = 0;
- if (data.width != -1 && data.height != -1) {
- width = data.width;
- height = data.height;
- } else {
- int[] w = new int[1], h = new int[1];
- OS.gdk_drawable_get_size(data.drawable, w, h);
- width = w[0];
- height = h[0];
- }
- /* Intersect visible bounds with clipping in device space and then convert then to user space */
- int /*long*/ cairo = data.cairo;
- int /*long*/ clipRgn = data.clipRgn;
- int /*long*/ damageRgn = data.damageRgn;
- if (clipRgn != 0 || damageRgn != 0 || cairo != 0) {
- int /*long*/ rgn = OS.gdk_region_new();
- GdkRectangle rect = new GdkRectangle();
- rect.width = width;
- rect.height = height;
- OS.gdk_region_union_with_rect(rgn, rect);
- if (damageRgn != 0) {
- OS.gdk_region_intersect (rgn, damageRgn);
- }
- /* Intersect visible bounds with clipping */
- if (clipRgn != 0) {
- /* Convert clipping to device space if needed */
- if (data.clippingTransform != null) {
- clipRgn = convertRgn(clipRgn, data.clippingTransform);
- OS.gdk_region_intersect(rgn, clipRgn);
- OS.gdk_region_destroy(clipRgn);
- } else {
- OS.gdk_region_intersect(rgn, clipRgn);
- }
- }
- /* Convert to user space */
- if (cairo != 0) {
- double[] matrix = new double[6];
- Cairo.cairo_get_matrix(cairo, matrix);
- Cairo.cairo_matrix_invert(matrix);
- clipRgn = convertRgn(rgn, matrix);
- OS.gdk_region_destroy(rgn);
- rgn = clipRgn;
- }
- OS.gdk_region_get_clipbox(rgn, rect);
- OS.gdk_region_destroy(rgn);
- x = rect.x;
- y = rect.y;
- width = rect.width;
- height = rect.height;
- }
- return new Rectangle(x, y, width, height);
-}
-
-/**
- * Sets the region managed by the argument to the current
- * clipping region of the receiver.
- *
- * @param region the region to fill with the clipping region
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the region is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the region is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getClipping(Region region) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int /*long*/ clipping = region.handle;
- OS.gdk_region_subtract(clipping, clipping);
- int /*long*/ cairo = data.cairo;
- int /*long*/ clipRgn = data.clipRgn;
- if (clipRgn == 0) {
- GdkRectangle rect = new GdkRectangle();
- if (data.width != -1 && data.height != -1) {
- rect.width = data.width;
- rect.height = data.height;
- } else {
- int[] width = new int[1], height = new int[1];
- OS.gdk_drawable_get_size(data.drawable, width, height);
- rect.width = width[0];
- rect.height = height[0];
- }
- OS.gdk_region_union_with_rect(clipping, rect);
- } else {
- /* Convert clipping to device space if needed */
- if (data.clippingTransform != null) {
- int /*long*/ rgn = convertRgn(clipRgn, data.clippingTransform);
- OS.gdk_region_union(clipping, rgn);
- OS.gdk_region_destroy(rgn);
- } else {
- OS.gdk_region_union(clipping, clipRgn);
- }
- }
- if (data.damageRgn != 0) {
- OS.gdk_region_intersect(clipping, data.damageRgn);
- }
- /* Convert to user space */
- if (cairo != 0) {
- double[] matrix = new double[6];
- Cairo.cairo_get_matrix(cairo, matrix);
- Cairo.cairo_matrix_invert(matrix);
- int /*long*/ rgn = convertRgn(clipping, matrix);
- OS.gdk_region_subtract(clipping, clipping);
- OS.gdk_region_union(clipping, rgn);
- OS.gdk_region_destroy(rgn);
- }
-}
-
-/**
- * Returns the receiver's fill rule, which will be one of
- * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>.
- *
- * @return the receiver's fill rule
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getFillRule() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int /*long*/ cairo = data.cairo;
- if (cairo == 0) return SWT.FILL_EVEN_ODD;
- return Cairo.cairo_get_fill_rule(cairo) == Cairo.CAIRO_FILL_RULE_WINDING ? SWT.FILL_WINDING : SWT.FILL_EVEN_ODD;
-}
-
-/**
- * Returns the font currently being used by the receiver
- * to draw and measure text.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getFont() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.font;
-}
-
-/**
- * Returns a FontMetrics which contains information
- * about the font currently being used by the receiver
- * to draw and measure text.
- *
- * @return font metrics for the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontMetrics getFontMetrics() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.context == 0) createLayout();
- checkGC(FONT);
- Font font = data.font;
- int /*long*/ context = data.context;
- int /*long*/ lang = OS.pango_context_get_language(context);
- int /*long*/ metrics = OS.pango_context_get_metrics(context, font.handle, lang);
- FontMetrics fm = new FontMetrics();
- fm.ascent = OS.PANGO_PIXELS(OS.pango_font_metrics_get_ascent(metrics));
- fm.descent = OS.PANGO_PIXELS(OS.pango_font_metrics_get_descent(metrics));
- fm.averageCharWidth = OS.PANGO_PIXELS(OS.pango_font_metrics_get_approximate_char_width(metrics));
- fm.height = fm.ascent + fm.descent;
- OS.pango_font_metrics_unref(metrics);
- return fm;
-}
-
-/**
- * Returns the receiver's foreground color.
- *
- * @return the color used for drawing foreground things
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getForeground() {
- if (handle == 0) SWT.error(SWT.ERROR_WIDGET_DISPOSED);
- return Color.gtk_new(data.device, data.foreground);
-}
-
-/**
- * Returns the foreground pattern. The default value is
- * <code>null</code>.
- *
- * @return the receiver's foreground pattern
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Pattern
- *
- * @since 3.1
- */
-public Pattern getForegroundPattern() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.foregroundPattern;
-}
-
-/**
- * Returns the GCData.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>GC</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @return the receiver's GCData
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see GCData
- *
- * @since 3.2
- * @noreference This method is not intended to be referenced by clients.
- */
-public GCData getGCData() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data;
-}
-
-/**
- * Returns the receiver's interpolation setting, which will be one of
- * <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>,
- * <code>SWT.LOW</code> or <code>SWT.HIGH</code>.
- *
- * @return the receiver's interpolation setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getInterpolation() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.interpolation;
-}
-
-/**
- * Returns the receiver's line attributes.
- *
- * @return the line attributes used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.3
- */
-public LineAttributes getLineAttributes() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float[] dashes = null;
- if (data.lineDashes != null) {
- dashes = new float[data.lineDashes.length];
- System.arraycopy(data.lineDashes, 0, dashes, 0, dashes.length);
- }
- return new LineAttributes(data.lineWidth, data.lineCap, data.lineJoin, data.lineStyle, dashes, data.lineDashesOffset, data.lineMiterLimit);
-}
-
-/**
- * Returns the receiver's line cap style, which will be one
- * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>,
- * or <code>SWT.CAP_SQUARE</code>.
- *
- * @return the cap style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getLineCap() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineCap;
-}
-
-/**
- * Returns the receiver's line dash style. The default value is
- * <code>null</code>.
- *
- * @return the line dash style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int[] getLineDash() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineDashes == null) return null;
- int[] lineDashes = new int[data.lineDashes.length];
- for (int i = 0; i < lineDashes.length; i++) {
- lineDashes[i] = (int)data.lineDashes[i];
- }
- return lineDashes;
-}
-
-/**
- * Returns the receiver's line join style, which will be one
- * of the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>,
- * or <code>SWT.JOIN_BEVEL</code>.
- *
- * @return the join style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getLineJoin() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineJoin;
-}
-
-/**
- * Returns the receiver's line style, which will be one
- * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
- * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or
- * <code>SWT.LINE_DASHDOTDOT</code>.
- *
- * @return the style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineStyle() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineStyle;
-}
-
-/**
- * Returns the width that will be used when drawing lines
- * for all of the figure drawing operations (that is,
- * <code>drawLine</code>, <code>drawRectangle</code>,
- * <code>drawPolyline</code>, and so forth.
- *
- * @return the receiver's line width
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineWidth() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (int)data.lineWidth;
-}
-
-/**
- * Returns the receiver's style information.
- * <p>
- * Note that the value which is returned by this method <em>may
- * not match</em> the value which was provided to the constructor
- * when the receiver was created. This can occur when the underlying
- * operating system does not support a particular combination of
- * requested styles.
- * </p>
- *
- * @return the style bits
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getStyle () {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.style;
-}
-
-/**
- * Returns the receiver's text drawing anti-aliasing setting value,
- * which will be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code>. Note that this controls anti-aliasing
- * <em>only</em> for text drawing operations.
- *
- * @return the anti-aliasing setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getAntialias
- *
- * @since 3.1
- */
-public int getTextAntialias() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.cairo == 0) return SWT.DEFAULT;
- int antialias = Cairo.CAIRO_ANTIALIAS_DEFAULT;
- if (OS.GTK_VERSION < OS.VERSION(2, 8, 0)) {
- int /*long*/ options = Cairo.cairo_font_options_create();
- Cairo.cairo_get_font_options(data.cairo, options);
- antialias = Cairo.cairo_font_options_get_antialias(options);
- Cairo.cairo_font_options_destroy(options);
- } else {
- if (data.context != 0) {
- int /*long*/ options = OS.pango_cairo_context_get_font_options(data.context);
- if (options != 0) antialias = Cairo.cairo_font_options_get_antialias(options);
- }
- }
- switch (antialias) {
- case Cairo.CAIRO_ANTIALIAS_DEFAULT: return SWT.DEFAULT;
- case Cairo.CAIRO_ANTIALIAS_NONE: return SWT.OFF;
- case Cairo.CAIRO_ANTIALIAS_GRAY:
- case Cairo.CAIRO_ANTIALIAS_SUBPIXEL: return SWT.ON;
- }
- return SWT.DEFAULT;
-}
-
-/**
- * Sets the parameter to the transform that is currently being
- * used by the receiver.
- *
- * @param transform the destination to copy the transform into
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Transform
- *
- * @since 3.1
- */
-public void getTransform(Transform transform) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transform == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- Cairo.cairo_get_matrix(cairo, transform.handle);
- double[] identity = identity();
- Cairo.cairo_matrix_invert(identity);
- Cairo.cairo_matrix_multiply(transform.handle, transform.handle, identity);
- } else {
- transform.setElements(1, 0, 0, 1, 0, 0);
- }
-}
-
-/**
- * Returns <code>true</code> if this GC is drawing in the mode
- * where the resulting color in the destination is the
- * <em>exclusive or</em> of the color values in the source
- * and the destination, and <code>false</code> if it is
- * drawing in the mode where the destination color is being
- * replaced with the source color value.
- *
- * @return <code>true</code> true if the receiver is in XOR mode, and false otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean getXORMode() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.xorMode;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #equals
- */
-public int hashCode() {
- return (int)/*64*/handle;
-}
-
-double[] identity() {
- double[] identity = new double[6];
- if ((data.style & SWT.MIRRORED) != 0) {
- int[] w = new int[1], h = new int[1];
- OS.gdk_drawable_get_size(data.drawable, w, h);
- Cairo.cairo_matrix_init(identity, -1, 0, 0, 1, w[0], 0);
- } else {
- Cairo.cairo_matrix_init_identity(identity);
- }
- return identity;
-}
-
-void init(Drawable drawable, GCData data, int /*long*/ gdkGC) {
- if (data.foreground != null) data.state &= ~FOREGROUND;
- if (data.background != null) data.state &= ~(BACKGROUND | BACKGROUND_BG);
- if (data.font != null) data.state &= ~FONT;
-
- Image image = data.image;
- if (image != null) {
- image.memGC = this;
- /*
- * The transparent pixel mask might change when drawing on
- * the image. Destroy it so that it is regenerated when
- * necessary.
- */
- if (image.transparentPixel != -1) image.destroyMask();
- }
- this.drawable = drawable;
- this.data = data;
- handle = gdkGC;
- if ((data.style & SWT.MIRRORED) != 0) {
- initCairo();
- int /*long*/ cairo = data.cairo;
- Cairo.cairo_set_matrix(cairo, identity());
- }
-}
-
-void initCairo() {
- data.device.checkCairo();
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) return;
- int /*long*/ xDisplay = OS.GDK_DISPLAY();
- int /*long*/ xVisual = OS.gdk_x11_visual_get_xvisual(OS.gdk_visual_get_system());
- int /*long*/ xDrawable = 0;
- int translateX = 0, translateY = 0;
- int /*long*/ drawable = data.drawable;
- if (data.image != null) {
- xDrawable = OS.GDK_PIXMAP_XID(drawable);
- } else {
- if (!data.realDrawable) {
- int[] x = new int[1], y = new int[1];
- int /*long*/ [] real_drawable = new int /*long*/ [1];
- OS.gdk_window_get_internal_paint_info(drawable, real_drawable, x, y);
- xDrawable = OS.gdk_x11_drawable_get_xid(real_drawable[0]);
- translateX = -x[0];
- translateY = -y[0];
- }
- }
- int[] w = new int[1], h = new int[1];
- OS.gdk_drawable_get_size(drawable, w, h);
- int width = w[0], height = h[0];
- int /*long*/ surface = Cairo.cairo_xlib_surface_create(xDisplay, xDrawable, xVisual, width, height);
- if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Cairo.cairo_surface_set_device_offset(surface, translateX, translateY);
- data.cairo = cairo = Cairo.cairo_create(surface);
- Cairo.cairo_surface_destroy(surface);
- if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- data.disposeCairo = true;
- Cairo.cairo_set_fill_rule(cairo, Cairo.CAIRO_FILL_RULE_EVEN_ODD);
- data.state &= ~(BACKGROUND | FOREGROUND | FONT | LINE_WIDTH | LINE_CAP | LINE_JOIN | LINE_STYLE | DRAW_OFFSET);
- setCairoClip(data.damageRgn, data.clipRgn);
-}
-
-void computeStringSize() {
- int[] width = new int[1], height = new int[1];
- OS.pango_layout_get_size(data.layout, width, height);
- data.stringHeight = OS.PANGO_PIXELS(height[0]);
- data.stringWidth = OS.PANGO_PIXELS(width[0]);
-}
-
-/**
- * Returns <code>true</code> if the receiver has a clipping
- * region set into it, and <code>false</code> otherwise.
- * If this method returns false, the receiver will draw on all
- * available space in the destination. If it returns true,
- * it will draw only in the area that is covered by the region
- * that can be accessed with <code>getClipping(region)</code>.
- *
- * @return <code>true</code> if the GC has a clipping region, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean isClipped() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.clipRgn != 0;
-}
-
-/**
- * Returns <code>true</code> if the GC has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the GC.
- * When a GC has been disposed, it is an error to
- * invoke any other method using the GC.
- *
- * @return <code>true</code> when the GC is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-boolean isIdentity(double[] matrix) {
- if (matrix == null) return true;
- return matrix[0] == 1 && matrix[1] == 0 && matrix[2] == 0 && matrix[3] == 1 && matrix[4] == 0 && matrix[5] == 0;
-}
-
-/**
- * Sets the receiver to always use the operating system's advanced graphics
- * subsystem for all graphics operations if the argument is <code>true</code>.
- * If the argument is <code>false</code>, the advanced graphics subsystem is
- * no longer used, advanced graphics state is cleared and the normal graphics
- * subsystem is used from now on.
- * <p>
- * Normally, the advanced graphics subsystem is invoked automatically when
- * any one of the alpha, antialias, patterns, interpolation, paths, clipping
- * or transformation operations in the receiver is requested. When the receiver
- * is switched into advanced mode, the advanced graphics subsystem performs both
- * advanced and normal graphics operations. Because the two subsystems are
- * different, their output may differ. Switching to advanced graphics before
- * any graphics operations are performed ensures that the output is consistent.
- * </p><p>
- * Advanced graphics may not be installed for the operating system. In this
- * case, this operation does nothing. Some operating system have only one
- * graphics subsystem, so switching from normal to advanced graphics does
- * nothing. However, switching from advanced to normal graphics will always
- * clear the advanced graphics state, even for operating systems that have
- * only one graphics subsystem.
- * </p>
- *
- * @param advanced the new advanced graphics state
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAlpha
- * @see #setAntialias
- * @see #setBackgroundPattern
- * @see #setClipping(Path)
- * @see #setForegroundPattern
- * @see #setLineAttributes
- * @see #setInterpolation
- * @see #setTextAntialias
- * @see #setTransform
- * @see #getAdvanced
- *
- * @since 3.1
- */
-public void setAdvanced(boolean advanced) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if ((data.style & SWT.MIRRORED) != 0) {
- if (!advanced) {
- setAlpha(0xFF);
- setAntialias(SWT.DEFAULT);
- setBackgroundPattern(null);
- setClipping(0);
- setForegroundPattern(null);
- setInterpolation(SWT.DEFAULT);
- setTextAntialias(SWT.DEFAULT);
- setTransform(null);
- }
- return;
- }
- if (advanced && data.cairo != 0) return;
- if (advanced) {
- try {
- initCairo();
- } catch (SWTException e) {}
- } else {
- if (!data.disposeCairo) return;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) Cairo.cairo_destroy(cairo);
- data.cairo = 0;
- data.interpolation = SWT.DEFAULT;
- data.alpha = 0xFF;
- data.backgroundPattern = data.foregroundPattern = null;
- data.state = 0;
- setClipping(0);
- }
-}
-
-/**
- * Sets the receiver's alpha value which must be
- * between 0 (transparent) and 255 (opaque).
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param alpha the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setAlpha(int alpha) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.cairo == 0 && (alpha & 0xff) == 0xff) return;
- initCairo();
- data.alpha = alpha & 0xff;
- data.state &= ~(BACKGROUND | FOREGROUND | BACKGROUND_BG);
-}
-
-/**
- * Sets the receiver's anti-aliasing value to the parameter,
- * which must be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code>
- * or <code>SWT.ON</code>. Note that this controls anti-aliasing for all
- * <em>non-text drawing</em> operations.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param antialias the anti-aliasing setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.OFF</code> or <code>SWT.ON</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- * @see #setTextAntialias
- *
- * @since 3.1
- */
-public void setAntialias(int antialias) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.cairo == 0 && antialias == SWT.DEFAULT) return;
- int mode = 0;
- switch (antialias) {
- case SWT.DEFAULT: mode = Cairo.CAIRO_ANTIALIAS_DEFAULT; break;
- case SWT.OFF: mode = Cairo.CAIRO_ANTIALIAS_NONE; break;
- case SWT.ON: mode = Cairo.CAIRO_ANTIALIAS_GRAY;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- initCairo();
- int /*long*/ cairo = data.cairo;
- Cairo.cairo_set_antialias(cairo, mode);
-}
-
-/**
- * Sets the background color. The background color is used
- * for fill operations and as the background color when text
- * is drawn.
- *
- * @param color the new background color for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setBackground(Color color) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.background = color.handle;
- data.backgroundPattern = null;
- data.state &= ~(BACKGROUND | BACKGROUND_BG);
-}
-
-/**
- * Sets the background pattern. The default value is <code>null</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param pattern the new background pattern
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Pattern
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setBackgroundPattern(Pattern pattern) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.cairo == 0 && pattern == null) return;
- initCairo();
- if (data.backgroundPattern == pattern) return;
- data.backgroundPattern = pattern;
- data.state &= ~BACKGROUND;
-}
-
-static void setCairoFont(int /*long*/ cairo, Font font) {
- setCairoFont(cairo, font.handle);
-}
-
-static void setCairoFont(int /*long*/ cairo, int /*long*/ font) {
- int /*long*/ family = OS.pango_font_description_get_family(font);
- int length = OS.strlen(family);
- byte[] buffer = new byte[length + 1];
- OS.memmove(buffer, family, length);
- //TODO - convert font height from pango to cairo
- double height = OS.PANGO_PIXELS(OS.pango_font_description_get_size(font)) * 96 / 72;
- int pangoStyle = OS.pango_font_description_get_style(font);
- int pangoWeight = OS.pango_font_description_get_weight(font);
- int slant = Cairo.CAIRO_FONT_SLANT_NORMAL;
- if (pangoStyle == OS.PANGO_STYLE_ITALIC) slant = Cairo.CAIRO_FONT_SLANT_ITALIC;
- if (pangoStyle == OS.PANGO_STYLE_OBLIQUE) slant = Cairo.CAIRO_FONT_SLANT_OBLIQUE;
- int weight = Cairo.CAIRO_FONT_WEIGHT_NORMAL;
- if (pangoWeight == OS.PANGO_WEIGHT_BOLD) weight = Cairo.CAIRO_FONT_WEIGHT_BOLD;
- Cairo.cairo_select_font_face(cairo, buffer, slant, weight);
- Cairo.cairo_set_font_size(cairo, height);
-}
-
-static void setCairoRegion(int /*long*/ cairo, int /*long*/ rgn) {
- if (OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
- OS.gdk_cairo_region(cairo, rgn);
- } else {
- int[] nRects = new int[1];
- int /*long*/[] rects = new int /*long*/[1];
- OS.gdk_region_get_rectangles(rgn, rects, nRects);
- GdkRectangle rect = new GdkRectangle();
- for (int i=0; i<nRects[0]; i++) {
- OS.memmove(rect, rects[0] + (i * GdkRectangle.sizeof), GdkRectangle.sizeof);
- Cairo.cairo_rectangle(cairo, rect.x, rect.y, rect.width, rect.height);
- }
- if (rects[0] != 0) OS.g_free(rects[0]);
- }
-}
-
-static void setCairoPatternColor(int /*long*/ pattern, int offset, Color c, int alpha) {
- GdkColor color = c.handle;
- double aa = (alpha & 0xFF) / (double)0xFF;
- double red = ((color.red & 0xFFFF) / (double)0xFFFF);
- double green = ((color.green & 0xFFFF) / (double)0xFFFF);
- double blue = ((color.blue & 0xFFFF) / (double)0xFFFF);
- Cairo.cairo_pattern_add_color_stop_rgba(pattern, offset, red, green, blue, aa);
-}
-
-void setCairoClip(int /*long*/ damageRgn, int /*long*/ clipRgn) {
- int /*long*/ cairo = data.cairo;
- Cairo.cairo_reset_clip(cairo);
- if (damageRgn != 0) {
- double[] matrix = new double[6];
- Cairo.cairo_get_matrix(cairo, matrix);
- double[] identity = new double[6];
- Cairo.cairo_matrix_init_identity(identity);
- Cairo.cairo_set_matrix(cairo, identity);
- setCairoRegion(cairo, damageRgn);
- Cairo.cairo_clip(cairo);
- Cairo.cairo_set_matrix(cairo, matrix);
- }
- if (clipRgn != 0) {
- setCairoRegion(cairo, clipRgn);
- Cairo.cairo_clip(cairo);
- }
-}
-
-void setClipping(int /*long*/ clipRgn) {
- int /*long*/ cairo = data.cairo;
- if (clipRgn == 0) {
- if (data.clipRgn != 0) {
- OS.gdk_region_destroy(data.clipRgn);
- data.clipRgn = 0;
- }
- if (cairo != 0) {
- data.clippingTransform = null;
- setCairoClip(data.damageRgn, 0);
- } else {
- int /*long*/ clipping = data.damageRgn != 0 ? data.damageRgn : 0;
- OS.gdk_gc_set_clip_region(handle, clipping);
- }
- } else {
- if (data.clipRgn == 0) data.clipRgn = OS.gdk_region_new();
- OS.gdk_region_subtract(data.clipRgn, data.clipRgn);
- OS.gdk_region_union(data.clipRgn, clipRgn);
- if (cairo != 0) {
- if (data.clippingTransform == null) data.clippingTransform = new double[6];
- Cairo.cairo_get_matrix(cairo, data.clippingTransform);
- setCairoClip(data.damageRgn, clipRgn);
- } else {
- int /*long*/ clipping = clipRgn;
- if (data.damageRgn != 0) {
- clipping = OS.gdk_region_new();
- OS.gdk_region_union(clipping, clipRgn);
- OS.gdk_region_intersect(clipping, data.damageRgn);
- }
- OS.gdk_gc_set_clip_region(handle, clipping);
- if (clipping != clipRgn) OS.gdk_region_destroy(clipping);
- }
- }
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the rectangular area specified
- * by the arguments.
- *
- * @param x the x coordinate of the clipping rectangle
- * @param y the y coordinate of the clipping rectangle
- * @param width the width of the clipping rectangle
- * @param height the height of the clipping rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping(int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- GdkRectangle rect = new GdkRectangle();
- rect.x = x;
- rect.y = y;
- rect.width = width;
- rect.height = height;
- int /*long*/ clipRgn = OS.gdk_region_new();
- OS.gdk_region_union_with_rect(clipRgn, rect);
- setClipping(clipRgn);
- OS.gdk_region_destroy(clipRgn);
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the path specified
- * by the argument.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the clipping path.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the path has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setClipping(Path path) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path != null && path.isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- setClipping(0);
- if (path != null) {
- initCairo();
- int /*long*/ cairo = data.cairo;
- int /*long*/ copy = Cairo.cairo_copy_path(path.handle);
- if (copy == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Cairo.cairo_append_path(cairo, copy);
- Cairo.cairo_path_destroy(copy);
- Cairo.cairo_clip(cairo);
- }
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the rectangular area specified
- * by the argument. Specifying <code>null</code> for the
- * rectangle reverts the receiver's clipping area to its
- * original value.
- *
- * @param rect the clipping rectangle or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping(Rectangle rect) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) {
- setClipping(0);
- } else {
- setClipping(rect.x, rect.y, rect.width, rect.height);
- }
-}
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the region specified
- * by the argument. Specifying <code>null</code> for the
- * region reverts the receiver's clipping area to its
- * original value.
- *
- * @param region the clipping region or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping(Region region) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region != null && region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- setClipping(region != null ? region.handle : 0);
-}
-
-/**
- * Sets the font which will be used by the receiver
- * to draw and measure text to the argument. If the
- * argument is null, then a default font appropriate
- * for the platform will be used instead.
- *
- * @param font the new font for the receiver, or null to indicate a default font
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setFont(Font font) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.font = font != null ? font : data.device.systemFont;
- data.state &= ~FONT;
- data.stringWidth = data.stringHeight = -1;
-}
-
-/**
- * Sets the receiver's fill rule to the parameter, which must be one of
- * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>.
- *
- * @param rule the new fill rule
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of <code>SWT.FILL_EVEN_ODD</code>
- * or <code>SWT.FILL_WINDING</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setFillRule(int rule) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int cairo_mode = Cairo.CAIRO_FILL_RULE_EVEN_ODD;
- switch (rule) {
- case SWT.FILL_WINDING:
- cairo_mode = Cairo.CAIRO_FILL_RULE_WINDING; break;
- case SWT.FILL_EVEN_ODD:
- cairo_mode = Cairo.CAIRO_FILL_RULE_EVEN_ODD; break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- //TODO - need fill rule in X, GDK has no API
- initCairo();
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- Cairo.cairo_set_fill_rule(cairo, cairo_mode);
- }
-}
-
-/**
- * Sets the foreground color. The foreground color is used
- * for drawing operations including when text is drawn.
- *
- * @param color the new foreground color for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setForeground(Color color) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.foreground = color.handle;
- data.foregroundPattern = null;
- data.state &= ~FOREGROUND;
-}
-
-/**
- * Sets the foreground pattern. The default value is <code>null</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param pattern the new foreground pattern
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Pattern
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setForegroundPattern(Pattern pattern) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.cairo == 0 && pattern == null) return;
- initCairo();
- if (data.foregroundPattern == pattern) return;
- data.foregroundPattern = pattern;
- data.state &= ~FOREGROUND;
-}
-
-/**
- * Sets the receiver's interpolation setting to the parameter, which
- * must be one of <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>,
- * <code>SWT.LOW</code> or <code>SWT.HIGH</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param interpolation the new interpolation setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.NONE</code>, <code>SWT.LOW</code> or <code>SWT.HIGH</code>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setInterpolation(int interpolation) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.cairo == 0 && interpolation == SWT.DEFAULT) return;
- switch (interpolation) {
- case SWT.DEFAULT:
- case SWT.NONE:
- case SWT.LOW:
- case SWT.HIGH:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- initCairo();
- data.interpolation = interpolation;
-}
-
-/**
- * Sets the receiver's line attributes.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param attributes the line attributes
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the attributes is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if any of the line attributes is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see LineAttributes
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.3
- */
-public void setLineAttributes(LineAttributes attributes) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (attributes == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int mask = 0;
- float lineWidth = attributes.width;
- if (lineWidth != data.lineWidth) {
- mask |= LINE_WIDTH | DRAW_OFFSET;
- }
- int lineStyle = attributes.style;
- if (lineStyle != data.lineStyle) {
- mask |= LINE_STYLE;
- switch (lineStyle) {
- case SWT.LINE_SOLID:
- case SWT.LINE_DASH:
- case SWT.LINE_DOT:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- break;
- case SWT.LINE_CUSTOM:
- if (attributes.dash == null) lineStyle = SWT.LINE_SOLID;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- int join = attributes.join;
- if (join != data.lineJoin) {
- mask |= LINE_JOIN;
- switch (join) {
- case SWT.CAP_ROUND:
- case SWT.CAP_FLAT:
- case SWT.CAP_SQUARE:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- int cap = attributes.cap;
- if (cap != data.lineCap) {
- mask |= LINE_CAP;
- switch (cap) {
- case SWT.JOIN_MITER:
- case SWT.JOIN_ROUND:
- case SWT.JOIN_BEVEL:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- float[] dashes = attributes.dash;
- float[] lineDashes = data.lineDashes;
- if (dashes != null && dashes.length > 0) {
- boolean changed = lineDashes == null || lineDashes.length != dashes.length;
- for (int i = 0; i < dashes.length; i++) {
- float dash = dashes[i];
- if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (!changed && lineDashes[i] != dash) changed = true;
- }
- if (changed) {
- float[] newDashes = new float[dashes.length];
- System.arraycopy(dashes, 0, newDashes, 0, dashes.length);
- dashes = newDashes;
- mask |= LINE_STYLE;
- } else {
- dashes = lineDashes;
- }
- } else {
- if (lineDashes != null && lineDashes.length > 0) {
- mask |= LINE_STYLE;
- } else {
- dashes = lineDashes;
- }
- }
- float dashOffset = attributes.dashOffset;
- if (dashOffset != data.lineDashesOffset) {
- mask |= LINE_STYLE;
- }
- float miterLimit = attributes.miterLimit;
- if (miterLimit != data.lineMiterLimit) {
- mask |= LINE_MITERLIMIT;
- }
- initCairo();
- if (mask == 0) return;
- data.lineWidth = lineWidth;
- data.lineStyle = lineStyle;
- data.lineCap = cap;
- data.lineJoin = join;
- data.lineDashes = dashes;
- data.lineDashesOffset = dashOffset;
- data.lineMiterLimit = miterLimit;
- data.state &= ~mask;
-}
-
-/**
- * Sets the receiver's line cap style to the argument, which must be one
- * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>,
- * or <code>SWT.CAP_SQUARE</code>.
- *
- * @param cap the cap style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineCap(int cap) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineCap == cap) return;
- switch (cap) {
- case SWT.CAP_ROUND:
- case SWT.CAP_FLAT:
- case SWT.CAP_SQUARE:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineCap = cap;
- data.state &= ~LINE_CAP;
-}
-
-/**
- * Sets the receiver's line dash style to the argument. The default
- * value is <code>null</code>. If the argument is not <code>null</code>,
- * the receiver's line style is set to <code>SWT.LINE_CUSTOM</code>, otherwise
- * it is set to <code>SWT.LINE_SOLID</code>.
- *
- * @param dashes the dash style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if any of the values in the array is less than or equal 0</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineDash(int[] dashes) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float[] lineDashes = data.lineDashes;
- if (dashes != null && dashes.length > 0) {
- boolean changed = data.lineStyle != SWT.LINE_CUSTOM || lineDashes == null || lineDashes.length != dashes.length;
- for (int i = 0; i < dashes.length; i++) {
- int dash = dashes[i];
- if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (!changed && lineDashes[i] != dash) changed = true;
- }
- if (!changed) return;
- data.lineDashes = new float[dashes.length];
- for (int i = 0; i < dashes.length; i++) {
- data.lineDashes[i] = dashes[i];
- }
- data.lineStyle = SWT.LINE_CUSTOM;
- } else {
- if (data.lineStyle == SWT.LINE_SOLID && (lineDashes == null || lineDashes.length == 0)) return;
- data.lineDashes = null;
- data.lineStyle = SWT.LINE_SOLID;
- }
- data.state &= ~LINE_STYLE;
-}
-
-/**
- * Sets the receiver's line join style to the argument, which must be one
- * of the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>,
- * or <code>SWT.JOIN_BEVEL</code>.
- *
- * @param join the join style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineJoin(int join) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineJoin == join) return;
- switch (join) {
- case SWT.JOIN_MITER:
- case SWT.JOIN_ROUND:
- case SWT.JOIN_BEVEL:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineJoin = join;
- data.state &= ~LINE_JOIN;
-}
-
-/**
- * Sets the receiver's line style to the argument, which must be one
- * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
- * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or
- * <code>SWT.LINE_DASHDOTDOT</code>.
- *
- * @param lineStyle the style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setLineStyle(int lineStyle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineStyle == lineStyle) return;
- switch (lineStyle) {
- case SWT.LINE_SOLID:
- case SWT.LINE_DASH:
- case SWT.LINE_DOT:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- break;
- case SWT.LINE_CUSTOM:
- if (data.lineDashes == null) lineStyle = SWT.LINE_SOLID;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineStyle = lineStyle;
- data.state &= ~LINE_STYLE;
-}
-
-/**
- * Sets the width that will be used when drawing lines
- * for all of the figure drawing operations (that is,
- * <code>drawLine</code>, <code>drawRectangle</code>,
- * <code>drawPolyline</code>, and so forth.
- * <p>
- * Note that line width of zero is used as a hint to
- * indicate that the fastest possible line drawing
- * algorithms should be used. This means that the
- * output may be different from line width one.
- * </p>
- *
- * @param lineWidth the width of a line
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setLineWidth(int lineWidth) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineWidth == lineWidth) return;
- data.lineWidth = lineWidth;
- data.state &= ~(LINE_WIDTH | DRAW_OFFSET);
-}
-
-void setString(String string, int flags) {
- if (data.layout == 0) createLayout();
- if (string == data.string && (flags & ~SWT.DRAW_TRANSPARENT) == (data.drawFlags & ~SWT.DRAW_TRANSPARENT)) {
- return;
- }
- byte[] buffer;
- int mnemonic, length = string.length ();
- int /*long*/ layout = data.layout;
- char[] text = new char[length];
- string.getChars(0, length, text, 0);
- if ((flags & SWT.DRAW_MNEMONIC) != 0 && (mnemonic = fixMnemonic(text)) != -1) {
- char[] text1 = new char[mnemonic - 1];
- System.arraycopy(text, 0, text1, 0, text1.length);
- byte[] buffer1 = Converter.wcsToMbcs(null, text1, false);
- char[] text2 = new char[text.length - mnemonic];
- System.arraycopy(text, mnemonic - 1, text2, 0, text2.length);
- byte[] buffer2 = Converter.wcsToMbcs(null, text2, false);
- buffer = new byte[buffer1.length + buffer2.length];
- System.arraycopy(buffer1, 0, buffer, 0, buffer1.length);
- System.arraycopy(buffer2, 0, buffer, buffer1.length, buffer2.length);
- int /*long*/ attr_list = OS.pango_attr_list_new();
- int /*long*/ attr = OS.pango_attr_underline_new(OS.PANGO_UNDERLINE_LOW);
- PangoAttribute attribute = new PangoAttribute();
- OS.memmove(attribute, attr, PangoAttribute.sizeof);
- attribute.start_index = buffer1.length;
- attribute.end_index = buffer1.length + 1;
- OS.memmove(attr, attribute, PangoAttribute.sizeof);
- OS.pango_attr_list_insert(attr_list, attr);
- OS.pango_layout_set_attributes(layout, attr_list);
- OS.pango_attr_list_unref(attr_list);
- } else {
- buffer = Converter.wcsToMbcs(null, text, false);
- OS.pango_layout_set_attributes(layout, 0);
- }
- OS.pango_layout_set_text(layout, buffer, buffer.length);
- OS.pango_layout_set_single_paragraph_mode(layout, (flags & SWT.DRAW_DELIMITER) == 0);
- OS.pango_layout_set_tabs(layout, (flags & SWT.DRAW_TAB) != 0 ? 0 : data.device.emptyTab);
- data.string = string;
- data.stringWidth = data.stringHeight = -1;
- data.drawFlags = flags;
-}
-
-/**
- * Sets the receiver's text anti-aliasing value to the parameter,
- * which must be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code>
- * or <code>SWT.ON</code>. Note that this controls anti-aliasing only
- * for all <em>text drawing</em> operations.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param antialias the anti-aliasing setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.OFF</code> or <code>SWT.ON</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- * @see #setAntialias
- *
- * @since 3.1
- */
-public void setTextAntialias(int antialias) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.cairo == 0 && antialias == SWT.DEFAULT) return;
- int mode = 0;
- switch (antialias) {
- case SWT.DEFAULT: mode = Cairo.CAIRO_ANTIALIAS_DEFAULT; break;
- case SWT.OFF: mode = Cairo.CAIRO_ANTIALIAS_NONE; break;
- case SWT.ON: mode = Cairo.CAIRO_ANTIALIAS_GRAY;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- initCairo();
- int /*long*/ options = Cairo.cairo_font_options_create();
- Cairo.cairo_font_options_set_antialias(options, mode);
- if (OS.GTK_VERSION < OS.VERSION(2, 8, 0)) {
- Cairo.cairo_set_font_options(data.cairo, options);
- } else {
- if (data.context == 0) createLayout();
- OS.pango_cairo_context_set_font_options(data.context, options);
- }
- Cairo.cairo_font_options_destroy(options);
-}
-
-/**
- * Sets the transform that is currently being used by the receiver. If
- * the argument is <code>null</code>, the current transform is set to
- * the identity transform.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param transform the transform to set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Transform
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setTransform(Transform transform) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transform != null && transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.cairo == 0 && transform == null) return;
- initCairo();
- int /*long*/ cairo = data.cairo;
- double[] identity = identity();
- if (transform != null) {
- Cairo.cairo_matrix_multiply(identity, transform.handle, identity);
- }
- Cairo.cairo_set_matrix(cairo, identity);
- data.state &= ~DRAW_OFFSET;
-}
-
-/**
- * If the argument is <code>true</code>, puts the receiver
- * in a drawing mode where the resulting color in the destination
- * is the <em>exclusive or</em> of the color values in the source
- * and the destination, and if the argument is <code>false</code>,
- * puts the receiver in a drawing mode where the destination color
- * is replaced with the source color value.
- * <p>
- * Note that this mode in fundamentally unsupportable on certain
- * platforms, notably Carbon (Mac OS X). Clients that want their
- * code to run on all platforms need to avoid this method.
- * </p>
- *
- * @param xor if <code>true</code>, then <em>xor</em> mode is used, otherwise <em>source copy</em> mode is used
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @deprecated this functionality is not supported on some platforms
- */
-public void setXORMode(boolean xor) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.gdk_gc_set_function(handle, xor ? OS.GDK_XOR : OS.GDK_COPY);
- data.xorMode = xor;
-}
-
-/**
- * Returns the extent of the given string. No tab
- * expansion or carriage return processing will be performed.
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point stringExtent(String string) {
- return textExtent(string, 0);
-}
-
-/**
- * Returns the extent of the given string. Tab expansion and
- * carriage return processing are performed.
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point textExtent(String string) {
- return textExtent(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
-}
-
-/**
- * Returns the extent of the given string. Tab expansion, line
- * delimiter and mnemonic processing are performed according to
- * the specified flags, which can be a combination of:
- * <dl>
- * <dt><b>DRAW_DELIMITER</b></dt>
- * <dd>draw multiple lines</dd>
- * <dt><b>DRAW_TAB</b></dt>
- * <dd>expand tabs</dd>
- * <dt><b>DRAW_MNEMONIC</b></dt>
- * <dd>underline the mnemonic character</dd>
- * <dt><b>DRAW_TRANSPARENT</b></dt>
- * <dd>transparent background</dd>
- * </dl>
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @param flags the flags specifying how to process the text
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point textExtent(String string, int flags) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- if (OS.GTK_VERSION < OS.VERSION(2, 8, 0)) {
- //TODO - honor flags
- checkGC(FONT);
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
- cairo_font_extents_t font_extents = new cairo_font_extents_t();
- Cairo.cairo_font_extents(cairo, font_extents);
- cairo_text_extents_t extents = new cairo_text_extents_t();
- Cairo.cairo_text_extents(cairo, buffer, extents);
- return new Point((int)extents.width, (int)font_extents.height);
- }
- }
- setString(string, flags);
- checkGC(FONT);
- if (data.stringWidth == -1) {
- computeStringSize();
- }
- return new Point(data.stringWidth, data.stringHeight);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "GC {*DISPOSED*}";
- return "GC {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GCData.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GCData.java
deleted file mode 100644
index d507acb51b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GCData.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class are descriptions of GCs in terms
- * of unallocated platform-specific data fields.
- * <p>
- * <b>IMPORTANT:</b> This class is <em>not</em> part of the public
- * API for SWT. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms, and should never be called from application code.
- * </p>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noinstantiate This class is not intended to be instantiated by clients.
- */
-public final class GCData {
- public Device device;
- public int style, state = -1;
- public GdkColor foreground;
- public GdkColor background;
- public Font font;
- public Pattern foregroundPattern;
- public Pattern backgroundPattern;
- public int /*long*/ clipRgn;
- public float lineWidth;
- public int lineStyle = SWT.LINE_SOLID;
- public float[] lineDashes;
- public float lineDashesOffset;
- public float lineMiterLimit = 10;
- public int lineCap = SWT.CAP_FLAT;
- public int lineJoin = SWT.JOIN_MITER;
- public boolean xorMode;
- public int alpha = 0xFF;
- public int interpolation = SWT.DEFAULT;
-
- public int /*long*/ context;
- public int /*long*/ layout;
- public int /*long*/ damageRgn;
- public Image image;
- public int /*long*/ drawable;
- public int /*long*/ cairo;
- public double cairoXoffset, cairoYoffset;
- public boolean disposeCairo;
- public double[] clippingTransform;
- public String string;
- public int stringWidth = -1;
- public int stringHeight = -1;
- public int drawFlags;
- public boolean realDrawable;
- public int width = -1, height = -1;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
deleted file mode 100644
index 1754574694..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
+++ /dev/null
@@ -1,1165 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.cairo.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.*;
-
-import java.io.*;
-
-/**
- * Instances of this class are graphics which have been prepared
- * for display on a specific device. That is, they are ready
- * to paint using methods such as <code>GC.drawImage()</code>
- * and display on widgets with, for example, <code>Button.setImage()</code>.
- * <p>
- * If loaded from a file format that supports it, an
- * <code>Image</code> may have transparency, meaning that certain
- * pixels are specified as being transparent when drawn. Examples
- * of file formats that support transparency are GIF and PNG.
- * </p><p>
- * There are two primary ways to use <code>Images</code>.
- * The first is to load a graphic file from disk and create an
- * <code>Image</code> from it. This is done using an <code>Image</code>
- * constructor, for example:
- * <pre>
- * Image i = new Image(device, "C:\\graphic.bmp");
- * </pre>
- * A graphic file may contain a color table specifying which
- * colors the image was intended to possess. In the above example,
- * these colors will be mapped to the closest available color in
- * SWT. It is possible to get more control over the mapping of
- * colors as the image is being created, using code of the form:
- * <pre>
- * ImageData data = new ImageData("C:\\graphic.bmp");
- * RGB[] rgbs = data.getRGBs();
- * // At this point, rgbs contains specifications of all
- * // the colors contained within this image. You may
- * // allocate as many of these colors as you wish by
- * // using the Color constructor Color(RGB), then
- * // create the image:
- * Image i = new Image(device, data);
- * </pre>
- * <p>
- * Applications which require even greater control over the image
- * loading process should use the support provided in class
- * <code>ImageLoader</code>.
- * </p><p>
- * Application code must explicitly invoke the <code>Image.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see Color
- * @see ImageData
- * @see ImageLoader
- * @see <a href="http://www.eclipse.org/swt/snippets/#image">Image snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, ImageAnalyzer</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Image extends Resource implements Drawable {
-
- /**
- * specifies whether the receiver is a bitmap or an icon
- * (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int type;
-
- /**
- * The handle to the OS pixmap resource.
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ pixmap;
-
- /**
- * The handle to the OS mask resource.
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ mask;
-
- int /*long*/ surface, surfaceData;
-
- /**
- * specifies the transparent pixel
- */
- int transparentPixel = -1;
-
- /**
- * The GC the image is currently selected in.
- */
- GC memGC;
-
- /**
- * The alpha data of the image.
- */
- byte[] alphaData;
-
- /**
- * The global alpha value to be used for every pixel.
- */
- int alpha = -1;
-
- /**
- * The width of the image.
- */
- int width = -1;
-
- /**
- * The height of the image.
- */
- int height = -1;
-
- /**
- * Specifies the default scanline padding.
- */
- static final int DEFAULT_SCANLINE_PAD = 4;
-
-Image(Device device) {
- super(device);
-}
-
-/**
- * Constructs an empty instance of this class with the
- * specified width and height. The result may be drawn upon
- * by creating a GC and using any of its drawing operations,
- * as shown in the following example:
- * <pre>
- * Image i = new Image(device, width, height);
- * GC gc = new GC(i);
- * gc.drawRectangle(0, 0, 50, 50);
- * gc.dispose();
- * </pre>
- * <p>
- * Note: Some platforms may have a limitation on the size
- * of image that can be created (size depends on width, height,
- * and depth). For example, Windows 95, 98, and ME do not allow
- * images larger than 16M.
- * </p>
- *
- * @param device the device on which to create the image
- * @param width the width of the new image
- * @param height the height of the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - if either the width or height is negative or zero</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, int width, int height) {
- super(device);
- init(width, height);
- init();
-}
-
-/**
- * Constructs a new instance of this class based on the
- * provided image, with an appearance that varies depending
- * on the value of the flag. The possible flag values are:
- * <dl>
- * <dt><b>{@link SWT#IMAGE_COPY}</b></dt>
- * <dd>the result is an identical copy of srcImage</dd>
- * <dt><b>{@link SWT#IMAGE_DISABLE}</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>disabled</em> look</dd>
- * <dt><b>{@link SWT#IMAGE_GRAY}</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>gray scale</em> look</dd>
- * </dl>
- *
- * @param device the device on which to create the image
- * @param srcImage the image to use as the source
- * @param flag the style, either <code>IMAGE_COPY</code>, <code>IMAGE_DISABLE</code> or <code>IMAGE_GRAY</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if srcImage is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the flag is not one of <code>IMAGE_COPY</code>, <code>IMAGE_DISABLE</code> or <code>IMAGE_GRAY</code></li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon, or is otherwise in an invalid state</li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the image is not supported</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, Image srcImage, int flag) {
- super(device);
- if (srcImage == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (srcImage.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- switch (flag) {
- case SWT.IMAGE_COPY:
- case SWT.IMAGE_DISABLE:
- case SWT.IMAGE_GRAY:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- device = this.device;
- this.type = srcImage.type;
-
- /* Get source image size */
- int[] w = new int[1], h = new int[1];
- OS.gdk_drawable_get_size(srcImage.pixmap, w, h);
- int width = w[0];
- int height = h[0];
-
- /* Copy the mask */
- if ((srcImage.type == SWT.ICON && srcImage.mask != 0) || srcImage.transparentPixel != -1) {
- /* Generate the mask if necessary. */
- if (srcImage.transparentPixel != -1) srcImage.createMask();
- int /*long*/ mask = OS.gdk_pixmap_new(0, width, height, 1);
- if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ gdkGC = OS.gdk_gc_new(mask);
- if (gdkGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.gdk_draw_drawable(mask, gdkGC, srcImage.mask, 0, 0, 0, 0, width, height);
- OS.g_object_unref(gdkGC);
- this.mask = mask;
- /* Destroy the image mask if the there is a GC created on the image */
- if (srcImage.transparentPixel != -1 && srcImage.memGC != null) srcImage.destroyMask();
- }
-
- /* Copy transparent pixel and alpha data */
- if (flag != SWT.IMAGE_DISABLE) transparentPixel = srcImage.transparentPixel;
- alpha = srcImage.alpha;
- if (srcImage.alphaData != null) {
- alphaData = new byte[srcImage.alphaData.length];
- System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length);
- }
- createAlphaMask(width, height);
-
- /* Create the new pixmap */
- int /*long*/ pixmap = OS.gdk_pixmap_new (OS.GDK_ROOT_PARENT(), width, height, -1);
- if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ gdkGC = OS.gdk_gc_new(pixmap);
- if (gdkGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- this.pixmap = pixmap;
-
- if (flag == SWT.IMAGE_COPY) {
- OS.gdk_draw_drawable(pixmap, gdkGC, srcImage.pixmap, 0, 0, 0, 0, width, height);
- OS.g_object_unref(gdkGC);
- } else {
-
- /* Retrieve the source pixmap data */
- int /*long*/ pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, width, height);
- if (pixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_pixbuf_get_from_drawable(pixbuf, srcImage.pixmap, colormap, 0, 0, 0, 0, width, height);
- int stride = OS.gdk_pixbuf_get_rowstride(pixbuf);
- int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf);
-
- /* Apply transformation */
- switch (flag) {
- case SWT.IMAGE_DISABLE: {
- Color zeroColor = device.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
- RGB zeroRGB = zeroColor.getRGB();
- byte zeroRed = (byte)zeroRGB.red;
- byte zeroGreen = (byte)zeroRGB.green;
- byte zeroBlue = (byte)zeroRGB.blue;
- Color oneColor = device.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
- RGB oneRGB = oneColor.getRGB();
- byte oneRed = (byte)oneRGB.red;
- byte oneGreen = (byte)oneRGB.green;
- byte oneBlue = (byte)oneRGB.blue;
- byte[] line = new byte[stride];
- for (int y=0; y<height; y++) {
- OS.memmove(line, pixels + (y * stride), stride);
- for (int x=0; x<width; x++) {
- int offset = x*3;
- int red = line[offset] & 0xFF;
- int green = line[offset+1] & 0xFF;
- int blue = line[offset+2] & 0xFF;
- int intensity = red * red + green * green + blue * blue;
- if (intensity < 98304) {
- line[offset] = zeroRed;
- line[offset+1] = zeroGreen;
- line[offset+2] = zeroBlue;
- } else {
- line[offset] = oneRed;
- line[offset+1] = oneGreen;
- line[offset+2] = oneBlue;
- }
- }
- OS.memmove(pixels + (y * stride), line, stride);
- }
- break;
- }
- case SWT.IMAGE_GRAY: {
- byte[] line = new byte[stride];
- for (int y=0; y<height; y++) {
- OS.memmove(line, pixels + (y * stride), stride);
- for (int x=0; x<width; x++) {
- int offset = x*3;
- int red = line[offset] & 0xFF;
- int green = line[offset+1] & 0xFF;
- int blue = line[offset+2] & 0xFF;
- byte intensity = (byte)((red+red+green+green+green+green+green+blue) >> 3);
- line[offset] = line[offset+1] = line[offset+2] = intensity;
- }
- OS.memmove(pixels + (y * stride), line, stride);
- }
- break;
- }
- }
-
- /* Copy data back to destination pixmap */
- OS.gdk_pixbuf_render_to_drawable(pixbuf, pixmap, gdkGC, 0, 0, 0, 0, width, height, OS.GDK_RGB_DITHER_NORMAL, 0, 0);
-
- /* Free resources */
- OS.g_object_unref(pixbuf);
- OS.g_object_unref(gdkGC);
- }
- init();
-}
-
-/**
- * Constructs an empty instance of this class with the
- * width and height of the specified rectangle. The result
- * may be drawn upon by creating a GC and using any of its
- * drawing operations, as shown in the following example:
- * <pre>
- * Image i = new Image(device, boundsRectangle);
- * GC gc = new GC(i);
- * gc.drawRectangle(0, 0, 50, 50);
- * gc.dispose();
- * </pre>
- * <p>
- * Note: Some platforms may have a limitation on the size
- * of image that can be created (size depends on width, height,
- * and depth). For example, Windows 95, 98, and ME do not allow
- * images larger than 16M.
- * </p>
- *
- * @param device the device on which to create the image
- * @param bounds a rectangle specifying the image's width and height (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the bounds rectangle is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, Rectangle bounds) {
- super(device);
- if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(bounds.width, bounds.height);
- init();
-}
-
-/**
- * Constructs an instance of this class from the given
- * <code>ImageData</code>.
- *
- * @param device the device on which to create the image
- * @param data the image data to create the image from (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the image data is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the ImageData is not supported</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, ImageData data) {
- super(device);
- init(data);
- init();
-}
-
-/**
- * Constructs an instance of this class, whose type is
- * <code>SWT.ICON</code>, from the two given <code>ImageData</code>
- * objects. The two images must be the same size. Pixel transparency
- * in either image will be ignored.
- * <p>
- * The mask image should contain white wherever the icon is to be visible,
- * and black wherever the icon is to be transparent. In addition,
- * the source image should contain black wherever the icon is to be
- * transparent.
- * </p>
- *
- * @param device the device on which to create the icon
- * @param source the color data for the icon
- * @param mask the mask data for the icon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if either the source or mask is null </li>
- * <li>ERROR_INVALID_ARGUMENT - if source and mask are different sizes</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, ImageData source, ImageData mask) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (mask == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (source.width != mask.width || source.height != mask.height) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- mask = ImageData.convertMask (mask);
- ImageData image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad, source.data);
- image.maskPad = mask.scanlinePad;
- image.maskData = mask.data;
- init(image);
- init();
-}
-
-/**
- * Constructs an instance of this class by loading its representation
- * from the specified input stream. Throws an error if an error
- * occurs while loading the image, or if the result is an image
- * of an unsupported type. Application code is still responsible
- * for closing the input stream.
- * <p>
- * This constructor is provided for convenience when loading a single
- * image only. If the stream contains multiple images, only the first
- * one will be loaded. To load multiple images, use
- * <code>ImageLoader.load()</code>.
- * </p><p>
- * This constructor may be used to load a resource as follows:
- * </p>
- * <pre>
- * static Image loadImage (Display display, Class clazz, String string) {
- * InputStream stream = clazz.getResourceAsStream (string);
- * if (stream == null) return null;
- * Image image = null;
- * try {
- * image = new Image (display, stream);
- * } catch (SWTException ex) {
- * } finally {
- * try {
- * stream.close ();
- * } catch (IOException ex) {}
- * }
- * return image;
- * }
- * </pre>
- *
- * @param device the device on which to create the image
- * @param stream the input stream to load the image from
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the stream is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from the stream</li>
- * <li>ERROR_INVALID_IMAGE - if the image stream contains invalid data </li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the image stream describes an image with an unsupported depth</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, InputStream stream) {
- super(device);
- init(new ImageData(stream));
- init();
-}
-
-/**
- * Constructs an instance of this class by loading its representation
- * from the file with the specified name. Throws an error if an error
- * occurs while loading the image, or if the result is an image
- * of an unsupported type.
- * <p>
- * This constructor is provided for convenience when loading
- * a single image only. If the specified file contains
- * multiple images, only the first one will be used.
- *
- * @param device the device on which to create the image
- * @param filename the name of the file to load the image from
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the file name is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from the file</li>
- * <li>ERROR_INVALID_IMAGE - if the image file contains invalid data </li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the image file describes an image with an unsupported depth</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, String filename) {
- super(device);
- if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- initNative(filename);
- if (this.pixmap == 0) init(new ImageData(filename));
- init();
-}
-
-void initNative(String filename) {
- try {
- int length = filename.length ();
- char [] chars = new char [length];
- filename.getChars (0, length, chars, 0);
- byte [] buffer = Converter.wcsToMbcs(null, chars, true);
- int /*long*/ pixbuf = OS.gdk_pixbuf_new_from_file(buffer, null);
- if (pixbuf != 0) {
- boolean hasAlpha = OS.gdk_pixbuf_get_has_alpha(pixbuf);
- if (hasAlpha) {
- /*
- * Bug in GTK. Depending on the image (seems to affect images that have
- * some degree of transparency all over the image), gdk_pixbuff_render_pixmap_and_mask()
- * will return a corrupt pixmap. To avoid this, read in and store the alpha channel data
- * for the image and then set it to 0xFF to prevent any possible corruption from
- * gdk_pixbuff_render_pixmap_and_mask().
- */
- int width = OS.gdk_pixbuf_get_width(pixbuf);
- int height = OS.gdk_pixbuf_get_height(pixbuf);
- int stride = OS.gdk_pixbuf_get_rowstride(pixbuf);
- int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf);
- byte[] line = new byte[stride];
- alphaData = new byte[width * height];
- for (int y = 0; y < height; y++) {
- OS.memmove(line, pixels + (y * stride), stride);
- for (int x = 0; x < width; x++) {
- alphaData[y*width+x] = line[x*4 + 3];
- line[x*4 + 3] = (byte) 0xFF;
- }
- OS.memmove(pixels + (y * stride), line, stride);
- }
- createAlphaMask(width, height);
- }
- int /*long*/ [] pixmap_return = new int /*long*/ [1];
- OS.gdk_pixbuf_render_pixmap_and_mask(pixbuf, pixmap_return, null, 0);
- this.type = SWT.BITMAP;
- this.pixmap = pixmap_return[0];
- if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.g_object_unref (pixbuf);
- }
- } catch (SWTException e) {}
-}
-
-void createAlphaMask (int width, int height) {
- if (device.useXRender && (alpha != -1 || alphaData != null)) {
- mask = OS.gdk_pixmap_new(0, alpha != -1 ? 1 : width, alpha != -1 ? 1 : height, 8);
- if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ gc = OS.gdk_gc_new(mask);
- if (alpha != -1) {
- GdkColor color = new GdkColor();
- color.pixel = (alpha & 0xFF) << 8 | (alpha & 0xFF);
- OS.gdk_gc_set_foreground(gc, color);
- OS.gdk_draw_rectangle(mask, gc, 1, 0, 0, 1, 1);
- } else {
- int /*long*/ imagePtr = OS.gdk_drawable_get_image(mask, 0, 0, width, height);
- if (imagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- GdkImage gdkImage = new GdkImage();
- OS.memmove(gdkImage, imagePtr);
- if (gdkImage.bpl == width) {
- OS.memmove(gdkImage.mem, alphaData, alphaData.length);
- } else {
- byte[] line = new byte[gdkImage.bpl];
- for (int y = 0; y < height; y++) {
- System.arraycopy(alphaData, width * y, line, 0, width);
- OS.memmove(gdkImage.mem + (gdkImage.bpl * y), line, gdkImage.bpl);
- }
- }
- OS.gdk_draw_image(mask, gc, imagePtr, 0, 0, 0, 0, width, height);
- OS.g_object_unref(imagePtr);
- }
- OS.g_object_unref(gc);
- }
-}
-
-/**
- * Create the receiver's mask if necessary.
- */
-void createMask() {
- if (mask != 0) return;
- mask = createMask(getImageData(), false);
- if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
-}
-
-int /*long*/ createMask(ImageData image, boolean copy) {
- ImageData mask = image.getTransparencyMask();
- byte[] data = mask.data;
- byte[] maskData = copy ? new byte[data.length] : data;
- for (int i = 0; i < maskData.length; i++) {
- byte s = data[i];
- maskData[i] = (byte)(((s & 0x80) >> 7) | ((s & 0x40) >> 5) |
- ((s & 0x20) >> 3) | ((s & 0x10) >> 1) | ((s & 0x08) << 1) |
- ((s & 0x04) << 3) | ((s & 0x02) << 5) | ((s & 0x01) << 7));
- }
- maskData = ImageData.convertPad(maskData, mask.width, mask.height, mask.depth, mask.scanlinePad, 1);
- return OS.gdk_bitmap_create_from_data(0, maskData, mask.width, mask.height);
-}
-
-void createSurface() {
- if (surface != 0) return;
- /* Generate the mask if necessary. */
- if (transparentPixel != -1) createMask();
- int[] w = new int[1], h = new int[1];
- OS.gdk_drawable_get_size(pixmap, w, h);
- int width = w[0], height = h[0];
- if (mask != 0 || alpha != -1 || alphaData != null) {
- int /*long*/ pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, true, 8, width, height);
- if (pixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_pixbuf_get_from_drawable(pixbuf, pixmap, colormap, 0, 0, 0, 0, width, height);
- int stride = OS.gdk_pixbuf_get_rowstride(pixbuf);
- int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf);
- byte[] line = new byte[stride];
- if (mask != 0 && OS.gdk_drawable_get_depth(mask) == 1) {
- int /*long*/ maskPixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, width, height);
- if (maskPixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.gdk_pixbuf_get_from_drawable(maskPixbuf, mask, 0, 0, 0, 0, 0, width, height);
- int maskStride = OS.gdk_pixbuf_get_rowstride(maskPixbuf);
- int /*long*/ maskPixels = OS.gdk_pixbuf_get_pixels(maskPixbuf);
- byte[] maskLine = new byte[maskStride];
- int /*long*/ offset = pixels, maskOffset = maskPixels;
- for (int y=0; y<height; y++) {
- OS.memmove(line, offset, stride);
- OS.memmove(maskLine, maskOffset, maskStride);
- for (int x=0, offset1=0; x<width; x++, offset1 += 4) {
- if (maskLine[x * 3] == 0) {
- line[offset1 + 0] = line[offset1 + 1] = line[offset1 + 2] = line[offset1 + 3] = 0;
- }
- byte temp = line[offset1];
- line[offset1] = line[offset1 + 2];
- line[offset1 + 2] = temp;
- }
- OS.memmove(offset, line, stride);
- offset += stride;
- maskOffset += maskStride;
- }
- OS.g_object_unref(maskPixbuf);
- } else if (alpha != -1) {
- int /*long*/ offset = pixels;
- for (int y=0; y<height; y++) {
- OS.memmove(line, offset, stride);
- for (int x=0, offset1=0; x<width; x++, offset1 += 4) {
- line[offset1+3] = (byte)alpha;
- /* pre-multiplied alpha */
- int r = ((line[offset1 + 0] & 0xFF) * alpha) + 128;
- r = (r + (r >> 8)) >> 8;
- int g = ((line[offset1 + 1] & 0xFF) * alpha) + 128;
- g = (g + (g >> 8)) >> 8;
- int b = ((line[offset1 + 2] & 0xFF) * alpha) + 128;
- b = (b + (b >> 8)) >> 8;
- line[offset1 + 0] = (byte)b;
- line[offset1 + 1] = (byte)g;
- line[offset1 + 2] = (byte)r;
- }
- OS.memmove(offset, line, stride);
- offset += stride;
- }
- } else if (alphaData != null) {
- int /*long*/ offset = pixels;
- for (int y = 0; y < h [0]; y++) {
- OS.memmove (line, offset, stride);
- for (int x=0, offset1=0; x<width; x++, offset1 += 4) {
- int alpha = alphaData [y*w [0]+x] & 0xFF;
- line[offset1+3] = (byte)alpha;
- /* pre-multiplied alpha */
- int r = ((line[offset1 + 0] & 0xFF) * alpha) + 128;
- r = (r + (r >> 8)) >> 8;
- int g = ((line[offset1 + 1] & 0xFF) * alpha) + 128;
- g = (g + (g >> 8)) >> 8;
- int b = ((line[offset1 + 2] & 0xFF) * alpha) + 128;
- b = (b + (b >> 8)) >> 8;
- line[offset1 + 0] = (byte)b;
- line[offset1 + 1] = (byte)g;
- line[offset1 + 2] = (byte)r;
- }
- OS.memmove (offset, line, stride);
- offset += stride;
- }
- } else {
- int /*long*/ offset = pixels;
- for (int y = 0; y < h [0]; y++) {
- OS.memmove (line, offset, stride);
- for (int x=0, offset1=0; x<width; x++, offset1 += 4) {
- line[offset1+3] = (byte)0xFF;
- byte temp = line[offset1];
- line[offset1] = line[offset1 + 2];
- line[offset1 + 2] = temp;
- }
- OS.memmove (offset, line, stride);
- offset += stride;
- }
- }
- surfaceData = OS.g_malloc(stride * height);
- OS.memmove(surfaceData, pixels, stride * height);
- surface = Cairo.cairo_image_surface_create_for_data(surfaceData, Cairo.CAIRO_FORMAT_ARGB32, width, height, stride);
- OS.g_object_unref(pixbuf);
- } else {
- int /*long*/ xDisplay = OS.GDK_DISPLAY();
- int /*long*/ xDrawable = OS.GDK_PIXMAP_XID(pixmap);
- int /*long*/ xVisual = OS.gdk_x11_visual_get_xvisual(OS.gdk_visual_get_system());
- surface = Cairo.cairo_xlib_surface_create(xDisplay, xDrawable, xVisual, width, height);
- }
- /* Destroy the image mask if the there is a GC created on the image */
- if (transparentPixel != -1 && memGC != null) destroyMask();
-}
-
-/**
- * Destroy the receiver's mask if it exists.
- */
-void destroyMask() {
- if (mask == 0) return;
- OS.g_object_unref(mask);
- mask = 0;
-}
-
-void destroy() {
- if (memGC != null) memGC.dispose();
- if (pixmap != 0) OS.g_object_unref(pixmap);
- if (mask != 0) OS.g_object_unref(mask);
- if (surface != 0) Cairo.cairo_surface_destroy(surface);
- if (surfaceData != 0) OS.g_free(surfaceData);
- surfaceData = surface = pixmap = mask = 0;
- memGC = null;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Image)) return false;
- Image image = (Image)object;
- return device == image.device && pixmap == image.pixmap;
-}
-
-/**
- * Returns the color to which to map the transparent pixel, or null if
- * the receiver has no transparent pixel.
- * <p>
- * There are certain uses of Images that do not support transparency
- * (for example, setting an image into a button or label). In these cases,
- * it may be desired to simulate transparency by using the background
- * color of the widget to paint the transparent pixels of the image.
- * Use this method to check which color will be used in these cases
- * in place of transparency. This value may be set with setBackground().
- * <p>
- *
- * @return the background color of the image, or null if there is no transparency in the image
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getBackground() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transparentPixel == -1) return null;
- //NOT DONE
- return null;
-}
-
-/**
- * Returns the bounds of the receiver. The rectangle will always
- * have x and y values of 0, and the width and height of the
- * image.
- *
- * @return a rectangle specifying the image's bounds
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li>
- * </ul>
- */
-public Rectangle getBounds() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width != -1 && height != -1) {
- return new Rectangle(0, 0, width, height);
- }
- int[] w = new int[1]; int[] h = new int[1];
- OS.gdk_drawable_get_size(pixmap, w, h);
- return new Rectangle(0, 0, width = w[0], height = h[0]);
-}
-
-/**
- * Returns an <code>ImageData</code> based on the receiver
- * Modifications made to this <code>ImageData</code> will not
- * affect the Image.
- *
- * @return an <code>ImageData</code> containing the image's data and attributes
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li>
- * </ul>
- *
- * @see ImageData
- */
-public ImageData getImageData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-
- int[] w = new int[1], h = new int[1];
- OS.gdk_drawable_get_size(pixmap, w, h);
- int width = w[0], height = h[0];
- int /*long*/ pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, width, height);
- if (pixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_pixbuf_get_from_drawable(pixbuf, pixmap, colormap, 0, 0, 0, 0, width, height);
- int stride = OS.gdk_pixbuf_get_rowstride(pixbuf);
- int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf);
- byte[] srcData = new byte[stride * height];
- OS.memmove(srcData, pixels, srcData.length);
- OS.g_object_unref(pixbuf);
-
- PaletteData palette = new PaletteData(0xFF0000, 0xFF00, 0xFF);
- ImageData data = new ImageData(width, height, 24, palette, 4, srcData);
- data.bytesPerLine = stride;
-
- if (transparentPixel == -1 && type == SWT.ICON && mask != 0) {
- /* Get the icon mask data */
- int /*long*/ gdkImagePtr = OS.gdk_drawable_get_image(mask, 0, 0, width, height);
- if (gdkImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- GdkImage gdkImage = new GdkImage();
- OS.memmove(gdkImage, gdkImagePtr);
- byte[] maskData = new byte[gdkImage.bpl * gdkImage.height];
- OS.memmove(maskData, gdkImage.mem, maskData.length);
- OS.g_object_unref(gdkImagePtr);
- int maskPad;
- for (maskPad = 1; maskPad < 128; maskPad++) {
- int bpl = (((width + 7) / 8) + (maskPad - 1)) / maskPad * maskPad;
- if (gdkImage.bpl == bpl) break;
- }
- /* Make mask scanline pad equals to 2 */
- data.maskPad = 2;
- maskData = ImageData.convertPad(maskData, width, height, 1, maskPad, data.maskPad);
- /* Bit swap the mask data if necessary */
- if (gdkImage.byte_order == OS.GDK_LSB_FIRST) {
- for (int i = 0; i < maskData.length; i++) {
- byte b = maskData[i];
- maskData[i] = (byte)(((b & 0x01) << 7) | ((b & 0x02) << 5) |
- ((b & 0x04) << 3) | ((b & 0x08) << 1) | ((b & 0x10) >> 1) |
- ((b & 0x20) >> 3) | ((b & 0x40) >> 5) | ((b & 0x80) >> 7));
- }
- }
- data.maskData = maskData;
- }
- data.transparentPixel = transparentPixel;
- data.alpha = alpha;
- if (alpha == -1 && alphaData != null) {
- data.alphaData = new byte[alphaData.length];
- System.arraycopy(alphaData, 0, data.alphaData, 0, alphaData.length);
- }
- return data;
-}
-
-/**
- * Invokes platform specific functionality to allocate a new image.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param type the type of the image (<code>SWT.BITMAP</code> or <code>SWT.ICON</code>)
- * @param pixmap the OS handle for the image
- * @param mask the OS handle for the image mask
- *
- * @private
- */
-public static Image gtk_new(Device device, int type, int /*long*/ pixmap, int /*long*/ mask) {
- Image image = new Image(device);
- image.type = type;
- image.pixmap = pixmap;
- image.mask = mask;
- return image;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return (int)/*64*/pixmap;
-}
-
-void init(int width, int height) {
- if (width <= 0 || height <= 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.type = SWT.BITMAP;
-
- /* Create the pixmap */
- this.pixmap = OS.gdk_pixmap_new(OS.GDK_ROOT_PARENT(), width, height, -1);
- if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- /* Fill the bitmap with white */
- GdkColor white = new GdkColor();
- white.red = (short)0xFFFF;
- white.green = (short)0xFFFF;
- white.blue = (short)0xFFFF;
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_colormap_alloc_color(colormap, white, true, true);
- int /*long*/ gdkGC = OS.gdk_gc_new(pixmap);
- OS.gdk_gc_set_foreground(gdkGC, white);
- OS.gdk_draw_rectangle(pixmap, gdkGC, 1, 0, 0, width, height);
- OS.g_object_unref(gdkGC);
- OS.gdk_colormap_free_colors(colormap, white, 1);
-}
-
-void init(ImageData image) {
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int width = image.width;
- int height = image.height;
- PaletteData palette = image.palette;
- if (!(((image.depth == 1 || image.depth == 2 || image.depth == 4 || image.depth == 8) && !palette.isDirect) ||
- ((image.depth == 8) || (image.depth == 16 || image.depth == 24 || image.depth == 32) && palette.isDirect)))
- SWT.error (SWT.ERROR_UNSUPPORTED_DEPTH);
- int /*long*/ pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, width, height);
- if (pixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int stride = OS.gdk_pixbuf_get_rowstride(pixbuf);
- int /*long*/ data = OS.gdk_pixbuf_get_pixels(pixbuf);
- byte[] buffer = image.data;
- if (!palette.isDirect || image.depth != 24 || stride != image.bytesPerLine || palette.redMask != 0xFF0000 || palette.greenMask != 0xFF00 || palette.blueMask != 0xFF) {
- buffer = new byte[stride * height];
- if (palette.isDirect) {
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, image.getByteOrder(), 0, 0, width, height, palette.redMask, palette.greenMask, palette.blueMask,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- buffer, 24, stride, ImageData.MSB_FIRST, 0, 0, width, height, 0xFF0000, 0xFF00, 0xFF,
- false, false);
- } else {
- RGB[] rgbs = palette.getRGBs();
- int length = rgbs.length;
- byte[] srcReds = new byte[length];
- byte[] srcGreens = new byte[length];
- byte[] srcBlues = new byte[length];
- for (int i = 0; i < rgbs.length; i++) {
- RGB rgb = rgbs[i];
- if (rgb == null) continue;
- srcReds[i] = (byte)rgb.red;
- srcGreens[i] = (byte)rgb.green;
- srcBlues[i] = (byte)rgb.blue;
- }
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, image.getByteOrder(), 0, 0, width, height, srcReds, srcGreens, srcBlues,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- buffer, 24, stride, ImageData.MSB_FIRST, 0, 0, width, height, 0xFF0000, 0xFF00, 0xFF,
- false, false);
- }
- }
- OS.memmove(data, buffer, stride * height);
- int /*long*/ pixmap = OS.gdk_pixmap_new (OS.GDK_ROOT_PARENT(), width, height, -1);
- if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ gdkGC = OS.gdk_gc_new(pixmap);
- if (gdkGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.gdk_pixbuf_render_to_drawable(pixbuf, pixmap, gdkGC, 0, 0, 0, 0, width, height, OS.GDK_RGB_DITHER_NORMAL, 0, 0);
- OS.g_object_unref(gdkGC);
- OS.g_object_unref(pixbuf);
-
- boolean isIcon = image.getTransparencyType() == SWT.TRANSPARENCY_MASK;
- if (isIcon || image.transparentPixel != -1) {
- if (image.transparentPixel != -1) {
- RGB rgb = null;
- if (palette.isDirect) {
- rgb = palette.getRGB(image.transparentPixel);
- } else {
- if (image.transparentPixel < palette.colors.length) {
- rgb = palette.getRGB(image.transparentPixel);
- }
- }
- if (rgb != null) {
- transparentPixel = rgb.red << 16 | rgb.green << 8 | rgb.blue;
- }
- }
- int /*long*/ mask = createMask(image, isIcon);
- if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- this.mask = mask;
- if (isIcon) {
- this.type = SWT.ICON;
- } else {
- this.type = SWT.BITMAP;
- }
- } else {
- this.type = SWT.BITMAP;
- this.mask = 0;
- this.alpha = image.alpha;
- if (image.alpha == -1 && image.alphaData != null) {
- this.alphaData = new byte[image.alphaData.length];
- System.arraycopy(image.alphaData, 0, this.alphaData, 0, alphaData.length);
- }
- createAlphaMask(width, height);
- }
- this.pixmap = pixmap;
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public int /*long*/ internal_new_GC (GCData data) {
- if (pixmap == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (type != SWT.BITMAP || memGC != null) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int /*long*/ gdkGC = OS.gdk_gc_new(pixmap);
- if (data != null) {
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) == 0) {
- data.style |= SWT.LEFT_TO_RIGHT;
- } else {
- if ((data.style & SWT.RIGHT_TO_LEFT) != 0) {
- data.style |= SWT.MIRRORED;
- }
- }
- data.device = device;
- data.drawable = pixmap;
- data.background = device.COLOR_WHITE.handle;
- data.foreground = device.COLOR_BLACK.handle;
- data.font = device.systemFont;
- data.image = this;
- }
- return gdkGC;
-}
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int /*long*/ gdkGC, GCData data) {
- OS.g_object_unref(gdkGC);
-}
-
-/**
- * Returns <code>true</code> if the image has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the image.
- * When an image has been disposed, it is an error to
- * invoke any other method using the image.
- *
- * @return <code>true</code> when the image is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return pixmap == 0;
-}
-
-/**
- * Sets the color to which to map the transparent pixel.
- * <p>
- * There are certain uses of <code>Images</code> that do not support
- * transparency (for example, setting an image into a button or label).
- * In these cases, it may be desired to simulate transparency by using
- * the background color of the widget to paint the transparent pixels
- * of the image. This method specifies the color that will be used in
- * these cases. For example:
- * <pre>
- * Button b = new Button();
- * image.setBackground(b.getBackground());
- * b.setImage(image);
- * </pre>
- * </p><p>
- * The image may be modified by this operation (in effect, the
- * transparent regions may be filled with the supplied color). Hence
- * this operation is not reversible and it is not legal to call
- * this function twice or with a null argument.
- * </p><p>
- * This method has no effect if the receiver does not have a transparent
- * pixel value.
- * </p>
- *
- * @param color the color to use when a transparent pixel is specified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setBackground(Color color) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (transparentPixel == -1) return;
- //NOT DONE
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Image {*DISPOSED*}";
- return "Image {" + pixmap + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Region.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Region.java
deleted file mode 100644
index 3ddb8b5b0e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Region.java
+++ /dev/null
@@ -1,594 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class represent areas of an x-y coordinate
- * system that are aggregates of the areas covered by a number
- * of polygons.
- * <p>
- * Application code must explicitly invoke the <code>Region.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Region extends Resource {
- /**
- * the OS resource for the region
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
-
-/**
- * Constructs a new empty region.
- *
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
- * </ul>
- */
-public Region() {
- this(null);
-}
-
-/**
- * Constructs a new empty region.
- * <p>
- * You must dispose the region when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the region
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
- * </ul>
- *
- * @see #dispose
- *
- * @since 3.0
- */
-public Region(Device device) {
- super(device);
- handle = OS.gdk_region_new();
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-Region(Device device, int /*long*/ handle) {
- super(device);
- this.handle = handle;
-}
-
-/**
- * Adds the given polygon to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param pointArray points that describe the polygon to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
-*
- */
-public void add (int[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- /*
- * Bug in GTK. If gdk_region_polygon() is called with one point,
- * it segment faults. The fix is to make sure that it is called
- * with enough points for a polygon.
- */
- if (pointArray.length < 6) return;
- int /*long*/ polyRgn = OS.gdk_region_polygon(pointArray, pointArray.length / 2, OS.GDK_EVEN_ODD_RULE);
- OS.gdk_region_union(handle, polyRgn);
- OS.gdk_region_destroy(polyRgn);
-}
-
-/**
- * Adds the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void add(Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- add (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Adds the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void add(int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- GdkRectangle gdkRect = new GdkRectangle();
- gdkRect.x = x;
- gdkRect.y = y;
- gdkRect.width = width;
- gdkRect.height = height;
- OS.gdk_region_union_with_rect(handle, gdkRect);
-}
-
-/**
- * Adds all of the polygons which make up the area covered
- * by the argument to the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to merge
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void add(Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.gdk_region_union(handle, region.handle);
-}
-
-/**
- * Returns <code>true</code> if the point specified by the
- * arguments is inside the area specified by the receiver,
- * and <code>false</code> otherwise.
- *
- * @param x the x coordinate of the point to test for containment
- * @param y the y coordinate of the point to test for containment
- * @return <code>true</code> if the region contains the point and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains(int x, int y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return OS.gdk_region_point_in(handle, x, y);
-}
-
-/**
- * Returns <code>true</code> if the given point is inside the
- * area specified by the receiver, and <code>false</code>
- * otherwise.
- *
- * @param pt the point to test for containment
- * @return <code>true</code> if the region contains the point and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains(Point pt) {
- if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return contains(pt.x, pt.y);
-}
-
-void destroy() {
- OS.gdk_region_destroy(handle);
- handle = 0;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals(Object object) {
- if (this == object) return true;
- if (!(object instanceof Region)) return false;
- Region region = (Region)object;
- return handle == region.handle;
-}
-
-/**
- * Returns a rectangle which represents the rectangular
- * union of the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @return a bounding rectangle for the region
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#union
- */
-public Rectangle getBounds() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- GdkRectangle gdkRect = new GdkRectangle();
- OS.gdk_region_get_clipbox(handle, gdkRect);
- return new Rectangle(gdkRect.x, gdkRect.y, gdkRect.width, gdkRect.height);
-}
-
-public static Region gtk_new(Device device, int /*long*/ handle) {
- return new Region(device, handle);
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode() {
- return (int)/*64*/handle;
-}
-
-/**
- * Intersects the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to intersect with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void intersect(Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- intersect (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Intersects the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void intersect(int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- GdkRectangle gdkRect = new GdkRectangle();
- gdkRect.x = x;
- gdkRect.y = y;
- gdkRect.width = width;
- gdkRect.height = height;
- int /*long*/ rectRgn = OS.gdk_region_rectangle(gdkRect);
- OS.gdk_region_intersect(handle, rectRgn);
- OS.gdk_region_destroy(rectRgn);
-}
-
-/**
- * Intersects all of the polygons which make up the area covered
- * by the argument to the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to intersect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void intersect(Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.gdk_region_intersect(handle, region.handle);
-}
-
-/**
- * Returns <code>true</code> if the rectangle described by the
- * arguments intersects with any of the polygons the receiver
- * maintains to describe its area, and <code>false</code> otherwise.
- *
- * @param x the x coordinate of the origin of the rectangle
- * @param y the y coordinate of the origin of the rectangle
- * @param width the width of the rectangle
- * @param height the height of the rectangle
- * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#intersects(Rectangle)
- */
-public boolean intersects (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- GdkRectangle gdkRect = new GdkRectangle();
- gdkRect.x = x;
- gdkRect.y = y;
- gdkRect.width = width;
- gdkRect.height = height;
- return OS.gdk_region_rect_in(handle, gdkRect) != OS.GDK_OVERLAP_RECTANGLE_OUT;
-}
-/**
- * Returns <code>true</code> if the given rectangle intersects
- * with any of the polygons the receiver maintains to describe
- * its area and <code>false</code> otherwise.
- *
- * @param rect the rectangle to test for intersection
- * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#intersects(Rectangle)
- */
-public boolean intersects(Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return intersects(rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Returns <code>true</code> if the region has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the region.
- * When a region has been disposed, it is an error to
- * invoke any other method using the region.
- *
- * @return <code>true</code> when the region is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns <code>true</code> if the receiver does not cover any
- * area in the (x, y) coordinate plane, and <code>false</code> if
- * the receiver does cover some area in the plane.
- *
- * @return <code>true</code> if the receiver is empty, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean isEmpty() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return OS.gdk_region_empty(handle);
-}
-
-/**
- * Subtracts the given polygon from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param pointArray points that describe the polygon to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract (int[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- /*
- * Bug in GTK. If gdk_region_polygon() is called with one point,
- * it segment faults. The fix is to make sure that it is called
- * with enough points for a polygon.
- */
- if (pointArray.length < 6) return;
- int /*long*/ polyRgn = OS.gdk_region_polygon(pointArray, pointArray.length / 2, OS.GDK_EVEN_ODD_RULE);
- OS.gdk_region_subtract(handle, polyRgn);
- OS.gdk_region_destroy(polyRgn);
-}
-
-/**
- * Subtracts the given rectangle from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to subtract from the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract(Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- subtract (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Subtracts the given rectangle from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void subtract(int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- GdkRectangle gdkRect = new GdkRectangle();
- gdkRect.x = x;
- gdkRect.y = y;
- gdkRect.width = width;
- gdkRect.height = height;
- int /*long*/ rectRgn = OS.gdk_region_rectangle(gdkRect);
- OS.gdk_region_subtract(handle, rectRgn);
- OS.gdk_region_destroy(rectRgn);
-}
-
-/**
- * Subtracts all of the polygons which make up the area covered
- * by the argument from the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to subtract
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract(Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.gdk_region_subtract(handle, region.handle);
-}
-
-/**
- * Translate all of the polygons the receiver maintains to describe
- * its area by the specified point.
- *
- * @param x the x coordinate of the point to translate
- * @param y the y coordinate of the point to translate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void translate (int x, int y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.gdk_region_offset (handle, x, y);
-}
-
-/**
- * Translate all of the polygons the receiver maintains to describe
- * its area by the specified point.
- *
- * @param pt the point to translate
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void translate (Point pt) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- translate (pt.x, pt.y);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Region {*DISPOSED*}";
- return "Region {" + handle + "}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java
deleted file mode 100644
index d72c2bac6d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java
+++ /dev/null
@@ -1,2201 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.cairo.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.*;
-
-/**
- * <code>TextLayout</code> is a graphic object that represents
- * styled text.
- * <p>
- * Instances of this class provide support for drawing, cursor
- * navigation, hit testing, text wrapping, alignment, tab expansion
- * line breaking, etc. These are aspects required for rendering internationalized text.
- * </p><p>
- * Application code must explicitly invoke the <code>TextLayout#dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#textlayout">TextLayout, TextStyle snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: CustomControlExample, StyledText tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.0
- */
-public final class TextLayout extends Resource {
-
- static class StyleItem {
- TextStyle style;
- int start;
-
- public String toString () {
- return "StyleItem {" + start + ", " + style + "}";
- }
- }
-
- Font font;
- String text;
- int ascent, descent;
- int[] segments;
- int[] tabs;
- StyleItem[] styles;
- int /*long*/ layout, context, attrList;
- int[] invalidOffsets;
- static final char LTR_MARK = '\u200E', RTL_MARK = '\u200F', ZWS = '\u200B', ZWNBS = '\uFEFF';
-
-/**
- * Constructs a new instance of this class on the given device.
- * <p>
- * You must dispose the text layout when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the text layout
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- *
- * @see #dispose()
- */
-public TextLayout (Device device) {
- super(device);
- device = this.device;
- context = OS.gdk_pango_context_get();
- if (context == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.pango_context_set_language(context, OS.gtk_get_default_language());
- OS.pango_context_set_base_dir(context, OS.PANGO_DIRECTION_LTR);
- OS.gdk_pango_context_set_colormap(context, OS.gdk_colormap_get_system());
- layout = OS.pango_layout_new(context);
- if (layout == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.pango_layout_set_font_description(layout, device.systemFont.handle);
- OS.pango_layout_set_wrap(layout, OS.PANGO_WRAP_WORD_CHAR);
- OS.pango_layout_set_tabs(layout, device.emptyTab);
- if (OS.GTK_VERSION >= OS.VERSION(2, 4, 0)) {
- OS.pango_layout_set_auto_dir(layout, false);
- }
- text = "";
- ascent = descent = -1;
- styles = new StyleItem[2];
- styles[0] = new StyleItem();
- styles[1] = new StyleItem();
- init();
-}
-
-void checkLayout() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-void computeRuns () {
- if (attrList != 0) return;
- String segmentsText = getSegmentsText();
- byte[] buffer = Converter.wcsToMbcs(null, segmentsText, false);
- OS.pango_layout_set_text (layout, buffer, buffer.length);
- if (styles.length == 2 && styles[0].style == null && ascent == -1 && descent == -1 && segments == null) return;
- int /*long*/ ptr = OS.pango_layout_get_text(layout);
- attrList = OS.pango_attr_list_new();
- PangoAttribute attribute = new PangoAttribute();
- char[] chars = null;
- int segementsLength = segmentsText.length();
- if ((ascent != -1 || descent != -1) && segementsLength > 0) {
- PangoRectangle rect = new PangoRectangle();
- if (ascent != -1) rect.y = -(ascent * OS.PANGO_SCALE);
- rect.height = (Math.max(0, ascent) + Math.max(0, descent)) * OS.PANGO_SCALE;
- int lineCount = OS.pango_layout_get_line_count(layout);
- chars = new char[segementsLength + lineCount * 2];
- int oldPos = 0, lineIndex = 0;
- PangoLayoutLine line = new PangoLayoutLine();
- while (lineIndex < lineCount) {
- int /*long*/ linePtr = OS.pango_layout_get_line(layout, lineIndex);
- OS.memmove(line, linePtr, PangoLayoutLine.sizeof);
- int bytePos = line.start_index;
- /* Note: The length in bytes of ZWS and ZWNBS are both equals to 3 */
- int offset = lineIndex * 6;
- int /*long*/ attr = OS.pango_attr_shape_new (rect, rect);
- OS.memmove (attribute, attr, PangoAttribute.sizeof);
- attribute.start_index = bytePos + offset;
- attribute.end_index = bytePos + offset + 3;
- OS.memmove (attr, attribute, PangoAttribute.sizeof);
- OS.pango_attr_list_insert(attrList, attr);
- attr = OS.pango_attr_shape_new (rect, rect);
- OS.memmove (attribute, attr, PangoAttribute.sizeof);
- attribute.start_index = bytePos + offset + 3;
- attribute.end_index = bytePos + offset + 6;
- OS.memmove (attr, attribute, PangoAttribute.sizeof);
- OS.pango_attr_list_insert(attrList, attr);
- int pos = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + bytePos);
- chars[pos + lineIndex * 2] = ZWS;
- chars[pos + lineIndex * 2 + 1] = ZWNBS;
- segmentsText.getChars(oldPos, pos, chars, oldPos + lineIndex * 2);
- oldPos = pos;
- lineIndex++;
- }
- segmentsText.getChars(oldPos, segementsLength, chars, oldPos + lineIndex * 2);
- buffer = Converter.wcsToMbcs(null, chars, false);
- OS.pango_layout_set_text (layout, buffer, buffer.length);
- ptr = OS.pango_layout_get_text(layout);
- } else {
- chars = new char[segementsLength];
- segmentsText.getChars(0, segementsLength, chars, 0);
- }
- int offsetCount = 0;
- for (int i = 0; i < chars.length; i++) {
- char c = chars[i];
- if (c == LTR_MARK || c == RTL_MARK || c == ZWNBS || c == ZWS) {
- offsetCount++;
- }
- }
- invalidOffsets = new int[offsetCount];
- offsetCount = 0;
- for (int i = 0; i < chars.length; i++) {
- char c = chars[i];
- if (c == LTR_MARK || c == RTL_MARK || c == ZWNBS || c == ZWS) {
- invalidOffsets[offsetCount++] = i;
- }
- }
- int strlen = OS.strlen(ptr);
- Font defaultFont = font != null ? font : device.systemFont;
- for (int i = 0; i < styles.length - 1; i++) {
- StyleItem styleItem = styles[i];
- TextStyle style = styleItem.style;
- if (style == null) continue;
- int start = translateOffset(styleItem.start);
- int end = translateOffset(styles[i+1].start - 1);
- int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, start) - ptr);
- int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, end + 1) - ptr);
- byteStart = Math.min(byteStart, strlen);
- byteEnd = Math.min(byteEnd, strlen);
- Font font = style.font;
- if (font != null && !font.isDisposed() && !defaultFont.equals(font)) {
- int /*long*/ attr = OS.pango_attr_font_desc_new (font.handle);
- OS.memmove (attribute, attr, PangoAttribute.sizeof);
- attribute.start_index = byteStart;
- attribute.end_index = byteEnd;
- OS.memmove (attr, attribute, PangoAttribute.sizeof);
- OS.pango_attr_list_insert(attrList, attr);
- }
- if (style.underline) {
- int underlineStyle = OS.PANGO_UNDERLINE_NONE;
- switch (style.underlineStyle) {
- case SWT.UNDERLINE_SINGLE:
- underlineStyle = OS.PANGO_UNDERLINE_SINGLE;
- break;
- case SWT.UNDERLINE_DOUBLE:
- underlineStyle = OS.PANGO_UNDERLINE_DOUBLE;
- break;
- case SWT.UNDERLINE_SQUIGGLE:
- case SWT.UNDERLINE_ERROR:
- if (OS.GTK_VERSION >= OS.VERSION(2, 4, 0)) {
- underlineStyle = OS.PANGO_UNDERLINE_ERROR;
- }
- break;
- case SWT.UNDERLINE_LINK: {
- if (style.foreground == null) {
- int /*long*/ attr = OS.pango_attr_foreground_new((short)0, (short)0x3333, (short)0x9999);
- OS.memmove (attribute, attr, PangoAttribute.sizeof);
- attribute.start_index = byteStart;
- attribute.end_index = byteEnd;
- OS.memmove (attr, attribute, PangoAttribute.sizeof);
- OS.pango_attr_list_insert(attrList, attr);
- }
- if (style.underlineColor == null) {
- underlineStyle = OS.PANGO_UNDERLINE_SINGLE;
- }
- break;
- }
- }
- if (underlineStyle != OS.PANGO_UNDERLINE_NONE && style.underlineColor == null) {
- int /*long*/ attr = OS.pango_attr_underline_new(underlineStyle);
- OS.memmove(attribute, attr, PangoAttribute.sizeof);
- attribute.start_index = byteStart;
- attribute.end_index = byteEnd;
- OS.memmove(attr, attribute, PangoAttribute.sizeof);
- OS.pango_attr_list_insert(attrList, attr);
- }
- }
- if (style.strikeout && style.strikeoutColor == null) {
- int /*long*/ attr = OS.pango_attr_strikethrough_new(true);
- OS.memmove(attribute, attr, PangoAttribute.sizeof);
- attribute.start_index = byteStart;
- attribute.end_index = byteEnd;
- OS.memmove(attr, attribute, PangoAttribute.sizeof);
- OS.pango_attr_list_insert(attrList, attr);
- }
- Color foreground = style.foreground;
- if (foreground != null && !foreground.isDisposed()) {
- GdkColor fg = foreground.handle;
- int /*long*/ attr = OS.pango_attr_foreground_new(fg.red, fg.green, fg.blue);
- OS.memmove (attribute, attr, PangoAttribute.sizeof);
- attribute.start_index = byteStart;
- attribute.end_index = byteEnd;
- OS.memmove (attr, attribute, PangoAttribute.sizeof);
- OS.pango_attr_list_insert(attrList, attr);
- }
- Color background = style.background;
- if (background != null && !background.isDisposed()) {
- GdkColor bg = background.handle;
- int /*long*/ attr = OS.pango_attr_background_new(bg.red, bg.green, bg.blue);
- OS.memmove (attribute, attr, PangoAttribute.sizeof);
- attribute.start_index = byteStart;
- attribute.end_index = byteEnd;
- OS.memmove (attr, attribute, PangoAttribute.sizeof);
- OS.pango_attr_list_insert(attrList, attr);
- }
- GlyphMetrics metrics = style.metrics;
- if (metrics != null) {
- PangoRectangle rect = new PangoRectangle();
- rect.y = -(metrics.ascent * OS.PANGO_SCALE);
- rect.height = (metrics.ascent + metrics.descent) * OS.PANGO_SCALE;
- rect.width = metrics.width * OS.PANGO_SCALE;
- int /*long*/ attr = OS.pango_attr_shape_new (rect, rect);
- OS.memmove (attribute, attr, PangoAttribute.sizeof);
- attribute.start_index = byteStart;
- attribute.end_index = byteEnd;
- OS.memmove (attr, attribute, PangoAttribute.sizeof);
- OS.pango_attr_list_insert(attrList, attr);
- }
- int rise = style.rise;
- if (rise != 0) {
- int /*long*/ attr = OS.pango_attr_rise_new (rise * OS.PANGO_SCALE);
- OS.memmove (attribute, attr, PangoAttribute.sizeof);
- attribute.start_index = byteStart;
- attribute.end_index = byteEnd;
- OS.memmove (attr, attribute, PangoAttribute.sizeof);
- OS.pango_attr_list_insert(attrList, attr);
- }
- }
- OS.pango_layout_set_attributes(layout, attrList);
-}
-
-int[] computePolyline(int left, int top, int right, int bottom) {
- int height = bottom - top; // can be any number
- int width = 2 * height; // must be even
- int peaks = Compatibility.ceil(right - left, width);
- if (peaks == 0 && right - left > 2) {
- peaks = 1;
- }
- int length = ((2 * peaks) + 1) * 2;
- if (length < 0) return new int[0];
-
- int[] coordinates = new int[length];
- for (int i = 0; i < peaks; i++) {
- int index = 4 * i;
- coordinates[index] = left + (width * i);
- coordinates[index+1] = bottom;
- coordinates[index+2] = coordinates[index] + width / 2;
- coordinates[index+3] = top;
- }
- coordinates[length-2] = left + (width * peaks);
- coordinates[length-1] = bottom;
- return coordinates;
-}
-
-void destroy() {
- font = null;
- text = null;
- styles = null;
- freeRuns();
- if (layout != 0) OS.g_object_unref(layout);
- layout = 0;
- if (context != 0) OS.g_object_unref(context);
- context = 0;
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- *
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- */
-public void draw(GC gc, int x, int y) {
- draw(gc, x, y, -1, -1, null, null);
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- *
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param selectionStart the offset where the selections starts, or -1 indicating no selection
- * @param selectionEnd the offset where the selections ends, or -1 indicating no selection
- * @param selectionForeground selection foreground, or NULL to use the system default color
- * @param selectionBackground selection background, or NULL to use the system default color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- */
-public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground) {
- draw(gc, x, y, selectionStart, selectionEnd, selectionForeground, selectionBackground, 0);
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- * <p>
- * The parameter <code>flags</code> can include one of <code>SWT.DELIMITER_SELECTION</code>
- * or <code>SWT.FULL_SELECTION</code> to specify the selection behavior on all lines except
- * for the last line, and can also include <code>SWT.LAST_LINE_SELECTION</code> to extend
- * the specified selection behavior to the last line.
- * </p>
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param selectionStart the offset where the selections starts, or -1 indicating no selection
- * @param selectionEnd the offset where the selections ends, or -1 indicating no selection
- * @param selectionForeground selection foreground, or NULL to use the system default color
- * @param selectionBackground selection background, or NULL to use the system default color
- * @param flags drawing options
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- *
- * @since 3.3
- */
-public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags) {
- checkLayout ();
- computeRuns();
- if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (selectionForeground != null && selectionForeground.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (selectionBackground != null && selectionBackground.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- gc.checkGC(GC.FOREGROUND);
- int length = text.length();
- boolean hasSelection = selectionStart <= selectionEnd && selectionStart != -1 && selectionEnd != -1;
- GCData data = gc.data;
- int /*long*/ cairo = data.cairo;
- if (flags != 0 && (hasSelection || (flags & SWT.LAST_LINE_SELECTION) != 0)) {
- int /*long*/[] attrs = new int /*long*/[1];
- int[] nAttrs = new int[1];
- PangoLogAttr logAttr = new PangoLogAttr();
- PangoRectangle rect = new PangoRectangle();
- int lineCount = OS.pango_layout_get_line_count(layout);
- int /*long*/ ptr = OS.pango_layout_get_text(layout);
- int /*long*/ iter = OS.pango_layout_get_iter(layout);
- if (selectionBackground == null) selectionBackground = device.getSystemColor(SWT.COLOR_LIST_SELECTION);
- if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
- Cairo.cairo_save(cairo);
- GdkColor color = selectionBackground.handle;
- Cairo.cairo_set_source_rgba(cairo, (color.red & 0xFFFF) / (float)0xFFFF, (color.green & 0xFFFF) / (float)0xFFFF, (color.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF);
- } else {
- OS.gdk_gc_set_foreground(gc.handle, selectionBackground.handle);
- }
- int lineIndex = 0;
- do {
- int lineEnd;
- OS.pango_layout_iter_get_line_extents(iter, null, rect);
- if (OS.pango_layout_iter_next_line(iter)) {
- int bytePos = OS.pango_layout_iter_get_index(iter);
- lineEnd = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + bytePos);
- } else {
- lineEnd = (int)/*64*/OS.g_utf8_strlen(ptr, -1);
- }
- boolean extent = false;
- if (lineIndex == lineCount - 1 && (flags & SWT.LAST_LINE_SELECTION) != 0) {
- extent = true;
- } else {
- if (attrs[0] == 0) OS.pango_layout_get_log_attrs(layout, attrs, nAttrs);
- OS.memmove(logAttr, attrs[0] + lineEnd * PangoLogAttr.sizeof, PangoLogAttr.sizeof);
- if (!logAttr.is_line_break) {
- if (selectionStart <= lineEnd && lineEnd <= selectionEnd) extent = true;
- } else {
- if (selectionStart <= lineEnd && lineEnd < selectionEnd && (flags & SWT.FULL_SELECTION) != 0) {
- extent = true;
- }
- }
- }
- if (extent) {
- int lineX = x + OS.PANGO_PIXELS(rect.x) + OS.PANGO_PIXELS(rect.width);
- int lineY = y + OS.PANGO_PIXELS(rect.y);
- int height = OS.PANGO_PIXELS(rect.height);
- if (ascent != -1 && descent != -1) {
- height = Math.max (height, ascent + descent);
- }
- int width = (flags & SWT.FULL_SELECTION) != 0 ? 0x7fffffff : height / 3;
- if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
- Cairo.cairo_rectangle(cairo, lineX, lineY, width, height);
- Cairo.cairo_fill(cairo);
- } else {
- OS.gdk_draw_rectangle(data.drawable, gc.handle, 1, lineX, lineY, width, height);
- }
- }
- lineIndex++;
- } while (lineIndex < lineCount);
- OS.pango_layout_iter_free(iter);
- if (attrs[0] != 0) OS.g_free(attrs[0]);
- if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
- Cairo.cairo_restore(cairo);
- } else {
- OS.gdk_gc_set_foreground(gc.handle, data.foreground);
- }
- }
- if (length == 0) return;
- if (!hasSelection) {
- if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
- if ((data.style & SWT.MIRRORED) != 0) {
- Cairo.cairo_save(cairo);
- Cairo.cairo_scale(cairo, -1, 1);
- Cairo.cairo_translate(cairo, -2 * x - width(), 0);
- }
- Cairo.cairo_move_to(cairo, x, y);
- OS.pango_cairo_show_layout(cairo, layout);
- drawBorder(gc, x, y, null);
- if ((data.style & SWT.MIRRORED) != 0) {
- Cairo.cairo_restore(cairo);
- }
- } else {
- OS.gdk_draw_layout(data.drawable, gc.handle, x, y, layout);
- drawBorder(gc, x, y, null);
- }
- } else {
- selectionStart = Math.min(Math.max(0, selectionStart), length - 1);
- selectionEnd = Math.min(Math.max(0, selectionEnd), length - 1);
- length = (int)/*64*/OS.g_utf8_strlen(OS.pango_layout_get_text(layout), -1);
- selectionStart = translateOffset(selectionStart);
- selectionEnd = translateOffset(selectionEnd);
- if (selectionForeground == null) selectionForeground = device.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
- if (selectionBackground == null) selectionBackground = device.getSystemColor(SWT.COLOR_LIST_SELECTION);
- boolean fullSelection = selectionStart == 0 && selectionEnd == length - 1;
- if (fullSelection) {
- if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
- int /*long*/ ptr = OS.pango_layout_get_text(layout);
- if ((data.style & SWT.MIRRORED) != 0) {
- Cairo.cairo_save(cairo);
- Cairo.cairo_scale(cairo, -1, 1);
- Cairo.cairo_translate(cairo, -2 * x - width(), 0);
- }
- drawWithCairo(gc, x, y, 0, OS.strlen(ptr), fullSelection, selectionForeground.handle, selectionBackground.handle);
- if ((data.style & SWT.MIRRORED) != 0) {
- Cairo.cairo_restore(cairo);
- }
- } else {
- OS.gdk_draw_layout_with_colors(data.drawable, gc.handle, x, y, layout, selectionForeground.handle, selectionBackground.handle);
- drawBorder(gc, x, y, selectionForeground.handle);
- }
- } else {
- int /*long*/ ptr = OS.pango_layout_get_text(layout);
- int byteSelStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, selectionStart) - ptr);
- int byteSelEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, selectionEnd + 1) - ptr);
- int strlen = OS.strlen(ptr);
- byteSelStart = Math.min(byteSelStart, strlen);
- byteSelEnd = Math.min(byteSelEnd, strlen);
- if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
- if ((data.style & SWT.MIRRORED) != 0) {
- Cairo.cairo_save(cairo);
- Cairo.cairo_scale(cairo, -1, 1);
- Cairo.cairo_translate(cairo, -2 * x - width(), 0);
- }
- drawWithCairo(gc, x, y, byteSelStart, byteSelEnd, fullSelection, selectionForeground.handle, selectionBackground.handle);
- if ((data.style & SWT.MIRRORED) != 0) {
- Cairo.cairo_restore(cairo);
- }
- } else {
- Region clipping = new Region();
- gc.getClipping(clipping);
- OS.gdk_draw_layout(data.drawable, gc.handle, x, y, layout);
- drawBorder(gc, x, y, null);
- int[] ranges = new int[]{byteSelStart, byteSelEnd};
- int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2);
- if (rgn != 0) {
- OS.gdk_gc_set_clip_region(gc.handle, rgn);
- OS.gdk_region_destroy(rgn);
- }
- OS.gdk_draw_layout_with_colors(data.drawable, gc.handle, x, y, layout, selectionForeground.handle, selectionBackground.handle);
- drawBorder(gc, x, y, selectionForeground.handle);
- gc.setClipping(clipping);
- clipping.dispose();
- }
- }
- }
-}
-
-void drawWithCairo(GC gc, int x, int y, int start, int end, boolean fullSelection, GdkColor fg, GdkColor bg) {
- GCData data = gc.data;
- int /*long*/ cairo = data.cairo;
- Cairo.cairo_save(cairo);
- if (!fullSelection) {
- Cairo.cairo_move_to(cairo, x, y);
- OS.pango_cairo_show_layout(cairo, layout);
- drawBorder(gc, x, y, null);
- }
- int[] ranges = new int[]{start, end};
- int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2);
- if (rgn != 0) {
- OS.gdk_cairo_region(cairo, rgn);
- Cairo.cairo_clip(cairo);
- Cairo.cairo_set_source_rgba(cairo, (bg.red & 0xFFFF) / (float)0xFFFF, (bg.green & 0xFFFF) / (float)0xFFFF, (bg.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF);
- Cairo.cairo_paint(cairo);
- OS.gdk_region_destroy(rgn);
- }
- Cairo.cairo_set_source_rgba(cairo, (fg.red & 0xFFFF) / (float)0xFFFF, (fg.green & 0xFFFF) / (float)0xFFFF, (fg.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF);
- Cairo.cairo_move_to(cairo, x, y);
- OS.pango_cairo_show_layout(cairo, layout);
- drawBorder(gc, x, y, fg);
- Cairo.cairo_restore(cairo);
-}
-
-void drawBorder(GC gc, int x, int y, GdkColor selectionColor) {
- GCData data = gc.data;
- int /*long*/ cairo = data.cairo;
- int /*long*/ gdkGC = gc.handle;
- int /*long*/ ptr = OS.pango_layout_get_text(layout);
- GdkGCValues gcValues = null;
- if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
- Cairo.cairo_save(cairo);
- }
- for (int i = 0; i < styles.length - 1; i++) {
- TextStyle style = styles[i].style;
- if (style == null) continue;
-
- boolean drawBorder = style.borderStyle != SWT.NONE;
- if (drawBorder && !style.isAdherentBorder(styles[i+1].style)) {
- int start = styles[i].start;
- for (int j = i; j > 0 && style.isAdherentBorder(styles[j-1].style); j--) {
- start = styles[j - 1].start;
- }
- start = translateOffset(start);
- int end = translateOffset(styles[i+1].start - 1);
- int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, start) - ptr);
- int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, end + 1) - ptr);
- int[] ranges = new int[]{byteStart, byteEnd};
- int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2);
- if (rgn != 0) {
- int[] nRects = new int[1];
- int /*long*/[] rects = new int /*long*/[1];
- OS.gdk_region_get_rectangles(rgn, rects, nRects);
- GdkRectangle rect = new GdkRectangle();
- GdkColor color = null;
- if (color == null && style.borderColor != null) color = style.borderColor.handle;
- if (color == null && selectionColor != null) color = selectionColor;
- if (color == null && style.foreground != null) color = style.foreground.handle;
- if (color == null) color = data.foreground;
- int width = 1;
- float[] dashes = null;
- switch (style.borderStyle) {
- case SWT.BORDER_SOLID: break;
- case SWT.BORDER_DASH: dashes = width != 0 ? GC.LINE_DASH : GC.LINE_DASH_ZERO; break;
- case SWT.BORDER_DOT: dashes = width != 0 ? GC.LINE_DOT : GC.LINE_DOT_ZERO; break;
- }
- if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
- Cairo.cairo_set_source_rgba(cairo, (color.red & 0xFFFF) / (float)0xFFFF, (color.green & 0xFFFF) / (float)0xFFFF, (color.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF);
- Cairo.cairo_set_line_width(cairo, width);
- if (dashes != null) {
- double[] cairoDashes = new double[dashes.length];
- for (int j = 0; j < cairoDashes.length; j++) {
- cairoDashes[j] = width == 0 || data.lineStyle == SWT.LINE_CUSTOM ? dashes[j] : dashes[j] * width;
- }
- Cairo.cairo_set_dash(cairo, cairoDashes, cairoDashes.length, 0);
- } else {
- Cairo.cairo_set_dash(cairo, null, 0, 0);
- }
- for (int j=0; j<nRects[0]; j++) {
- OS.memmove(rect, rects[0] + (j * GdkRectangle.sizeof), GdkRectangle.sizeof);
- Cairo.cairo_rectangle(cairo, rect.x + 0.5, rect.y + 0.5, rect.width - 1, rect.height - 1);
- }
- Cairo.cairo_stroke(cairo);
- } else {
- if (gcValues == null) {
- gcValues = new GdkGCValues();
- OS.gdk_gc_get_values(gdkGC, gcValues);
- }
- OS.gdk_gc_set_foreground(gdkGC, color);
- int cap_style = OS.GDK_CAP_BUTT;
- int join_style = OS.GDK_JOIN_MITER;
- int line_style = 0;
- if (dashes != null) {
- byte[] dash_list = new byte[dashes.length];
- for (int j = 0; j < dash_list.length; j++) {
- dash_list[j] = (byte)(width == 0 || data.lineStyle == SWT.LINE_CUSTOM ? dashes[j] : dashes[j] * width);
- }
- OS.gdk_gc_set_dashes(gdkGC, 0, dash_list, dash_list.length);
- line_style = OS.GDK_LINE_ON_OFF_DASH;
- } else {
- line_style = OS.GDK_LINE_SOLID;
- }
- OS.gdk_gc_set_line_attributes(gdkGC, width, line_style, cap_style, join_style);
- for (int j=0; j<nRects[0]; j++) {
- OS.memmove(rect, rects[0] + (j * GdkRectangle.sizeof), GdkRectangle.sizeof);
- OS.gdk_draw_rectangle(data.drawable, gdkGC, 0, rect.x, rect.y, rect.width - 1, rect.height - 1);
- }
- }
- if (rects[0] != 0) OS.g_free(rects[0]);
- OS.gdk_region_destroy(rgn);
- }
- }
-
- boolean drawUnderline = false;
- if (style.underline && style.underlineColor != null) drawUnderline = true;
- if (style.underline && (style.underlineStyle == SWT.UNDERLINE_ERROR || style.underlineStyle == SWT.UNDERLINE_SQUIGGLE)&& OS.GTK_VERSION < OS.VERSION(2, 4, 0)) drawUnderline = true;
- if (drawUnderline && !style.isAdherentUnderline(styles[i+1].style)) {
- int start = styles[i].start;
- for (int j = i; j > 0 && style.isAdherentUnderline(styles[j-1].style); j--) {
- start = styles[j - 1].start;
- }
- start = translateOffset(start);
- int end = translateOffset(styles[i+1].start - 1);
- int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, start) - ptr);
- int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, end + 1) - ptr);
- int[] ranges = new int[]{byteStart, byteEnd};
- int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2);
- if (rgn != 0) {
- int[] nRects = new int[1];
- int /*long*/[] rects = new int /*long*/[1];
- OS.gdk_region_get_rectangles(rgn, rects, nRects);
- GdkRectangle rect = new GdkRectangle();
- GdkColor color = null;
- if (color == null && style.underlineColor != null) color = style.underlineColor.handle;
- if (color == null && selectionColor != null) color = selectionColor;
- if (color == null && style.foreground != null) color = style.foreground.handle;
- if (color == null) color = data.foreground;
- if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
- Cairo.cairo_set_source_rgba(cairo, (color.red & 0xFFFF) / (float)0xFFFF, (color.green & 0xFFFF) / (float)0xFFFF, (color.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF);
- } else {
- if (gcValues == null) {
- gcValues = new GdkGCValues();
- OS.gdk_gc_get_values(gdkGC, gcValues);
- }
- OS.gdk_gc_set_foreground(gdkGC, color);
- }
- int underlinePosition = -1;
- int underlineThickness = 1;
- if (OS.GTK_VERSION >= OS.VERSION(2, 6, 0)) {
- Font font = style.font;
- if (font == null) font = this.font;
- if (font == null) font = device.systemFont;
- int /*long*/ lang = OS.pango_context_get_language(context);
- int /*long*/ metrics = OS.pango_context_get_metrics(context, font.handle, lang);
- underlinePosition = OS.PANGO_PIXELS(OS.pango_font_metrics_get_underline_position(metrics));
- underlineThickness = OS.PANGO_PIXELS(OS.pango_font_metrics_get_underline_thickness(metrics));
- OS.pango_font_metrics_unref(metrics);
- }
- for (int j=0; j<nRects[0]; j++) {
- OS.memmove(rect, rects[0] + (j * GdkRectangle.sizeof), GdkRectangle.sizeof);
- int offset = getOffset(rect.x - x, rect.y - y, null);
- int lineIndex = getLineIndex(offset);
- FontMetrics metrics = getLineMetrics(lineIndex);
- int underlineY = rect.y + metrics.ascent - underlinePosition - style.rise;
- switch (style.underlineStyle) {
- case SWT.UNDERLINE_SQUIGGLE:
- case SWT.UNDERLINE_ERROR: {
- int squigglyThickness = underlineThickness;
- int squigglyHeight = 2 * squigglyThickness;
- int squigglyY = Math.min(underlineY, rect.y + rect.height - squigglyHeight - 1);
- int[] points = computePolyline(rect.x, squigglyY, rect.x + rect.width, squigglyY + squigglyHeight);
- if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
- Cairo.cairo_set_line_width(cairo, squigglyThickness);
- Cairo.cairo_set_line_cap(cairo, Cairo.CAIRO_LINE_CAP_BUTT);
- Cairo.cairo_set_line_join(cairo, Cairo.CAIRO_LINE_JOIN_MITER);
- if (points.length > 0) {
- double xOffset = 0.5, yOffset = 0.5;
- Cairo.cairo_move_to(cairo, points[0] + xOffset, points[1] + yOffset);
- for (int k = 2; k < points.length; k += 2) {
- Cairo.cairo_line_to(cairo, points[k] + xOffset, points[k + 1] + yOffset);
- }
- Cairo.cairo_stroke(cairo);
- }
- } else {
- OS.gdk_gc_set_line_attributes(gdkGC, squigglyThickness, OS.GDK_LINE_SOLID, OS.GDK_CAP_BUTT, OS.GDK_JOIN_MITER);
- OS.gdk_draw_lines(data.drawable, gdkGC, points, points.length / 2);
- }
- break;
- }
- case SWT.UNDERLINE_DOUBLE:
- if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
- Cairo.cairo_rectangle(cairo, rect.x, underlineY + underlineThickness * 2, rect.width, underlineThickness);
- Cairo.cairo_fill(cairo);
- } else {
- OS.gdk_draw_rectangle(data.drawable, gdkGC, 1, rect.x, underlineY + underlineThickness * 2, rect.width, underlineThickness);
- }
- //FALLTHROUGH
- case SWT.UNDERLINE_LINK:
- case SWT.UNDERLINE_SINGLE:
- if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
- Cairo.cairo_rectangle(cairo, rect.x, underlineY, rect.width, underlineThickness);
- Cairo.cairo_fill(cairo);
- } else {
- OS.gdk_draw_rectangle(data.drawable, gdkGC, 1, rect.x, underlineY, rect.width, underlineThickness);
- }
- break;
- }
- }
- if (rects[0] != 0) OS.g_free(rects[0]);
- OS.gdk_region_destroy(rgn);
- }
- }
-
- boolean drawStrikeout = false;
- if (style.strikeout && style.strikeoutColor != null) drawStrikeout = true;
- if (drawStrikeout && !style.isAdherentStrikeout(styles[i+1].style)) {
- int start = styles[i].start;
- for (int j = i; j > 0 && style.isAdherentStrikeout(styles[j-1].style); j--) {
- start = styles[j - 1].start;
- }
- start = translateOffset(start);
- int end = translateOffset(styles[i+1].start - 1);
- int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, start) - ptr);
- int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, end + 1) - ptr);
- int[] ranges = new int[]{byteStart, byteEnd};
- int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2);
- if (rgn != 0) {
- int[] nRects = new int[1];
- int /*long*/[] rects = new int /*long*/[1];
- OS.gdk_region_get_rectangles(rgn, rects, nRects);
- GdkRectangle rect = new GdkRectangle();
- GdkColor color = null;
- if (color == null && style.strikeoutColor != null) color = style.strikeoutColor.handle;
- if (color == null && selectionColor != null) color = selectionColor;
- if (color == null && style.foreground != null) color = style.foreground.handle;
- if (color == null) color = data.foreground;
- if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
- Cairo.cairo_set_source_rgba(cairo, (color.red & 0xFFFF) / (float)0xFFFF, (color.green & 0xFFFF) / (float)0xFFFF, (color.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF);
- } else {
- if (gcValues == null) {
- gcValues = new GdkGCValues();
- OS.gdk_gc_get_values(gdkGC, gcValues);
- }
- OS.gdk_gc_set_foreground(gdkGC, color);
- }
- int strikeoutPosition = -1;
- int strikeoutThickness = 1;
- if (OS.GTK_VERSION >= OS.VERSION(2, 6, 0)) {
- Font font = style.font;
- if (font == null) font = this.font;
- if (font == null) font = device.systemFont;
- int /*long*/ lang = OS.pango_context_get_language(context);
- int /*long*/ metrics = OS.pango_context_get_metrics(context, font.handle, lang);
- strikeoutPosition = OS.PANGO_PIXELS(OS.pango_font_metrics_get_strikethrough_position(metrics));
- strikeoutThickness = OS.PANGO_PIXELS(OS.pango_font_metrics_get_strikethrough_thickness(metrics));
- OS.pango_font_metrics_unref(metrics);
- }
- for (int j=0; j<nRects[0]; j++) {
- OS.memmove(rect, rects[0] + (j * GdkRectangle.sizeof), GdkRectangle.sizeof);
- int strikeoutY = rect.y + rect.height / 2 - style.rise;
- if (OS.GTK_VERSION >= OS.VERSION(2, 6, 0)) {
- int offset = getOffset(rect.x - x, rect.y - y, null);
- int lineIndex = getLineIndex(offset);
- FontMetrics metrics = getLineMetrics(lineIndex);
- strikeoutY = rect.y + metrics.ascent - strikeoutPosition - style.rise;
- }
- if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
- Cairo.cairo_rectangle(cairo, rect.x, strikeoutY, rect.width, strikeoutThickness);
- Cairo.cairo_fill(cairo);
- } else {
- OS.gdk_draw_rectangle(data.drawable, gdkGC, 1, rect.x, strikeoutY, rect.width, strikeoutThickness);
- }
- }
- if (rects[0] != 0) OS.g_free(rects[0]);
- OS.gdk_region_destroy(rgn);
- }
- }
- }
- if (gcValues != null) {
- int mask = OS.GDK_GC_FOREGROUND | OS.GDK_GC_LINE_WIDTH | OS.GDK_GC_LINE_STYLE | OS.GDK_GC_CAP_STYLE | OS.GDK_GC_JOIN_STYLE;
- OS.gdk_gc_set_values(gdkGC, gcValues, mask);
- data.state &= ~GC.LINE_STYLE;
- }
- if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
- Cairo.cairo_restore(cairo);
- }
-}
-
-void freeRuns() {
- if (attrList == 0) return;
- OS.pango_layout_set_attributes(layout, 0);
- OS.pango_attr_list_unref(attrList);
- attrList = 0;
- invalidOffsets = null;
-}
-
-/**
- * Returns the receiver's horizontal text alignment, which will be one
- * of <code>SWT.LEFT</code>, <code>SWT.CENTER</code> or
- * <code>SWT.RIGHT</code>.
- *
- * @return the alignment used to positioned text horizontally
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getAlignment() {
- checkLayout();
- int align = OS.pango_layout_get_alignment(layout);
- boolean rtl = OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL;
- switch (align) {
- case OS.PANGO_ALIGN_LEFT: return rtl ? SWT.RIGHT : SWT.LEFT;
- case OS.PANGO_ALIGN_RIGHT: return rtl ? SWT.LEFT : SWT.RIGHT;
- }
- return SWT.CENTER;
-}
-
-/**
- * Returns the ascent of the receiver.
- *
- * @return the ascent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getDescent()
- * @see #setDescent(int)
- * @see #setAscent(int)
- * @see #getLineMetrics(int)
- */
-public int getAscent () {
- checkLayout();
- return ascent;
-}
-
-/**
- * Returns the bounds of the receiver. The width returned is either the
- * width of the longest line or the width set using {@link TextLayout#setWidth(int)}.
- * To obtain the text bounds of a line use {@link TextLayout#getLineBounds(int)}.
- *
- * @return the bounds of the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setWidth(int)
- * @see #getLineBounds(int)
- */
-public Rectangle getBounds() {
- checkLayout();
- computeRuns();
- int[] w = new int[1], h = new int[1];
- OS.pango_layout_get_size(layout, w, h);
- int wrapWidth = OS.pango_layout_get_width(layout);
- w[0] = wrapWidth != -1 ? wrapWidth : w[0] + OS.pango_layout_get_indent(layout);
- int width = OS.PANGO_PIXELS(w[0]);
- int height = OS.PANGO_PIXELS(h[0]);
- if (ascent != -1 && descent != -1) {
- height = Math.max (height, ascent + descent);
- }
- height += OS.PANGO_PIXELS(OS.pango_layout_get_spacing(layout));
- return new Rectangle(0, 0, width, height);
-}
-
-/**
- * Returns the bounds for the specified range of characters. The
- * bounds is the smallest rectangle that encompasses all characters
- * in the range. The start and end offsets are inclusive and will be
- * clamped if out of range.
- *
- * @param start the start offset
- * @param end the end offset
- * @return the bounds of the character range
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds(int start, int end) {
- checkLayout();
- computeRuns();
- int length = text.length();
- if (length == 0) return new Rectangle(0, 0, 0, 0);
- if (start > end) return new Rectangle(0, 0, 0, 0);
- start = Math.min(Math.max(0, start), length - 1);
- end = Math.min(Math.max(0, end), length - 1);
- start = translateOffset(start);
- end = translateOffset(end);
- int /*long*/ ptr = OS.pango_layout_get_text(layout);
- int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer (ptr, start) - ptr);
- int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer (ptr, end + 1) - ptr);
- int strlen = OS.strlen(ptr);
- byteStart = Math.min(byteStart, strlen);
- byteEnd = Math.min(byteEnd, strlen);
- int[] ranges = new int[]{byteStart, byteEnd};
- int /*long*/ clipRegion = OS.gdk_pango_layout_get_clip_region(layout, 0, 0, ranges, 1);
- if (clipRegion == 0) return new Rectangle(0, 0, 0, 0);
- GdkRectangle rect = new GdkRectangle();
-
- /*
- * Bug in Pango. The region returned by gdk_pango_layout_get_clip_region()
- * includes areas from lines outside of the requested range. The fix
- * is to subtract these areas from the clip region.
- */
- PangoRectangle pangoRect = new PangoRectangle();
- int /*long*/ iter = OS.pango_layout_get_iter(layout);
- if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ linesRegion = OS.gdk_region_new();
- if (linesRegion == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int lineEnd = 0;
- do {
- OS.pango_layout_iter_get_line_extents(iter, null, pangoRect);
- if (OS.pango_layout_iter_next_line(iter)) {
- lineEnd = OS.pango_layout_iter_get_index(iter) - 1;
- } else {
- lineEnd = strlen;
- }
- if (byteStart > lineEnd) continue;
- rect.x = OS.PANGO_PIXELS(pangoRect.x);
- rect.y = OS.PANGO_PIXELS(pangoRect.y);
- rect.width = OS.PANGO_PIXELS(pangoRect.width);
- rect.height = OS.PANGO_PIXELS(pangoRect.height);
- OS.gdk_region_union_with_rect(linesRegion, rect);
- } while (lineEnd + 1 <= byteEnd);
- OS.gdk_region_intersect(clipRegion, linesRegion);
- OS.gdk_region_destroy(linesRegion);
- OS.pango_layout_iter_free(iter);
-
- OS.gdk_region_get_clipbox(clipRegion, rect);
- OS.gdk_region_destroy(clipRegion);
- if (OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL) {
- rect.x = width() - rect.x - rect.width;
- }
- return new Rectangle(rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Returns the descent of the receiver.
- *
- * @return the descent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getAscent()
- * @see #setAscent(int)
- * @see #setDescent(int)
- * @see #getLineMetrics(int)
- */
-public int getDescent () {
- checkLayout();
- return descent;
-}
-
-/**
- * Returns the default font currently being used by the receiver
- * to draw and measure text.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getFont () {
- checkLayout();
- return font;
-}
-
-/**
-* Returns the receiver's indent.
-*
-* @return the receiver's indent
-*
-* @exception SWTException <ul>
-* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
-* </ul>
-*
-* @since 3.2
-*/
-public int getIndent () {
- checkLayout();
- return OS.PANGO_PIXELS(OS.pango_layout_get_indent(layout));
-}
-
-/**
-* Returns the receiver's justification.
-*
-* @return the receiver's justification
-*
-* @exception SWTException <ul>
-* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
-* </ul>
-*
-* @since 3.2
-*/
-public boolean getJustify () {
- checkLayout();
- return OS.pango_layout_get_justify(layout);
-}
-
-/**
- * Returns the embedding level for the specified character offset. The
- * embedding level is usually used to determine the directionality of a
- * character in bidirectional text.
- *
- * @param offset the character offset
- * @return the embedding level
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- */
-public int getLevel(int offset) {
- checkLayout();
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- offset = translateOffset(offset);
- int /*long*/ iter = OS.pango_layout_get_iter(layout);
- if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int level = 0;
- PangoItem item = new PangoItem();
- PangoLayoutRun run = new PangoLayoutRun();
- int /*long*/ ptr = OS.pango_layout_get_text(layout);
- int /*long*/ byteOffset = OS.g_utf8_offset_to_pointer(ptr, offset) - ptr;
- int strlen = OS.strlen(ptr);
- byteOffset = Math.min(byteOffset, strlen);
- do {
- int /*long*/ runPtr = OS.pango_layout_iter_get_run(iter);
- if (runPtr != 0) {
- OS.memmove(run, runPtr, PangoLayoutRun.sizeof);
- OS.memmove(item, run.item, PangoItem.sizeof);
- if (item.offset <= byteOffset && byteOffset < item.offset + item.length) {
- level = item.analysis_level;
- break;
- }
- }
- } while (OS.pango_layout_iter_next_run(iter));
- OS.pango_layout_iter_free(iter);
- return level;
-}
-
-/**
- * Returns the bounds of the line for the specified line index.
- *
- * @param lineIndex the line index
- * @return the line bounds
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getLineBounds(int lineIndex) {
- checkLayout();
- computeRuns();
- int lineCount = OS.pango_layout_get_line_count(layout);
- if (!(0 <= lineIndex && lineIndex < lineCount)) SWT.error(SWT.ERROR_INVALID_RANGE);
- int /*long*/ iter = OS.pango_layout_get_iter(layout);
- if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- for (int i = 0; i < lineIndex; i++) OS.pango_layout_iter_next_line(iter);
- PangoRectangle rect = new PangoRectangle();
- OS.pango_layout_iter_get_line_extents(iter, null, rect);
- OS.pango_layout_iter_free(iter);
- int x = OS.PANGO_PIXELS(rect.x);
- int y = OS.PANGO_PIXELS(rect.y);
- int width = OS.PANGO_PIXELS(rect.width);
- int height = OS.PANGO_PIXELS(rect.height);
- if (ascent != -1 && descent != -1) {
- height = Math.max (height, ascent + descent);
- }
- if (OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL) {
- x = width() - x - width;
- }
- return new Rectangle(x, y, width, height);
-}
-
-/**
- * Returns the receiver's line count. This includes lines caused
- * by wrapping.
- *
- * @return the line count
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineCount() {
- checkLayout ();
- computeRuns();
- return OS.pango_layout_get_line_count(layout);
-}
-
-/**
- * Returns the index of the line that contains the specified
- * character offset.
- *
- * @param offset the character offset
- * @return the line index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineIndex(int offset) {
- checkLayout ();
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- offset = translateOffset(offset);
- int line = 0;
- int /*long*/ ptr = OS.pango_layout_get_text(layout);
- int /*long*/ byteOffset = OS.g_utf8_offset_to_pointer(ptr,offset) - ptr;
- int strlen = OS.strlen(ptr);
- byteOffset = Math.min(byteOffset, strlen);
- int /*long*/ iter = OS.pango_layout_get_iter(layout);
- if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- while (OS.pango_layout_iter_next_line(iter)) {
- if (OS.pango_layout_iter_get_index(iter) > byteOffset) break;
- line++;
- }
- OS.pango_layout_iter_free(iter);
- return line;
-}
-
-/**
- * Returns the font metrics for the specified line index.
- *
- * @param lineIndex the line index
- * @return the font metrics
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontMetrics getLineMetrics (int lineIndex) {
- checkLayout ();
- computeRuns();
- int lineCount = OS.pango_layout_get_line_count(layout);
- if (!(0 <= lineIndex && lineIndex < lineCount)) SWT.error(SWT.ERROR_INVALID_RANGE);
- int ascent = 0, descent = 0;
- PangoLayoutLine line = new PangoLayoutLine();
- OS.memmove(line, OS.pango_layout_get_line(layout, lineIndex), PangoLayoutLine.sizeof);
- if (line.runs == 0) {
- int /*long*/ font = this.font != null ? this.font.handle : device.systemFont.handle;
- int /*long*/ lang = OS.pango_context_get_language(context);
- int /*long*/ metrics = OS.pango_context_get_metrics(context, font, lang);
- ascent = OS.pango_font_metrics_get_ascent(metrics);
- descent = OS.pango_font_metrics_get_descent(metrics);
- OS.pango_font_metrics_unref(metrics);
- } else {
- PangoRectangle rect = new PangoRectangle();
- OS.pango_layout_line_get_extents(OS.pango_layout_get_line(layout, lineIndex), null, rect);
- ascent = -rect.y;
- descent = rect.height - ascent;
- }
- ascent = Math.max(this.ascent, OS.PANGO_PIXELS(ascent));
- descent = Math.max(this.descent, OS.PANGO_PIXELS(descent));
- return FontMetrics.gtk_new(ascent, descent, 0, 0, ascent + descent);
-}
-
-/**
- * Returns the line offsets. Each value in the array is the
- * offset for the first character in a line except for the last
- * value, which contains the length of the text.
- *
- * @return the line offsets
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getLineOffsets() {
- checkLayout();
- computeRuns();
- int lineCount = OS.pango_layout_get_line_count(layout);
- int[] offsets = new int [lineCount + 1];
- int /*long*/ ptr = OS.pango_layout_get_text(layout);
- PangoLayoutLine line = new PangoLayoutLine();
- for (int i = 0; i < lineCount; i++) {
- int /*long*/ linePtr = OS.pango_layout_get_line(layout, i);
- OS.memmove(line, linePtr, PangoLayoutLine.sizeof);
- int pos = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + line.start_index);
- offsets[i] = untranslateOffset(pos);
- }
- offsets[lineCount] = text.length();
- return offsets;
-}
-
-/**
- * Returns the location for the specified character offset. The
- * <code>trailing</code> argument indicates whether the offset
- * corresponds to the leading or trailing edge of the cluster.
- *
- * @param offset the character offset
- * @param trailing the trailing flag
- * @return the location of the character offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getOffset(Point, int[])
- * @see #getOffset(int, int, int[])
- */
-public Point getLocation(int offset, boolean trailing) {
- checkLayout();
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- offset = translateOffset(offset);
- int /*long*/ ptr = OS.pango_layout_get_text(layout);
- int byteOffset = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, offset) - ptr);
- int strlen = OS.strlen(ptr);
- byteOffset = Math.min(byteOffset, strlen);
- PangoRectangle pos = new PangoRectangle();
- OS.pango_layout_index_to_pos(layout, byteOffset, pos);
- int x = trailing ? pos.x + pos.width : pos.x;
- int y = pos.y;
- x = OS.PANGO_PIXELS(x);
- if (OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL) {
- x = width() - x;
- }
- return new Point(x, OS.PANGO_PIXELS(y));
-}
-
-/**
- * Returns the next offset for the specified offset and movement
- * type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>,
- * <code>SWT.MOVEMENT_CLUSTER</code>, <code>SWT.MOVEMENT_WORD</code>,
- * <code>SWT.MOVEMENT_WORD_END</code> or <code>SWT.MOVEMENT_WORD_START</code>.
- *
- * @param offset the start offset
- * @param movement the movement type
- * @return the next offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getPreviousOffset(int, int)
- */
-public int getNextOffset (int offset, int movement) {
- return _getOffset(offset, movement, true);
-}
-
-int _getOffset (int offset, int movement, boolean forward) {
- checkLayout();
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- if (forward) {
- if (offset == length) return length;
- } else {
- if (offset == 0) return 0;
- }
- int step = forward ? 1 : -1;
- if ((movement & SWT.MOVEMENT_CHAR) != 0) return offset + step;
- int /*long*/[] attrs = new int /*long*/[1];
- int[] nAttrs = new int[1];
- OS.pango_layout_get_log_attrs(layout, attrs, nAttrs);
- if (attrs[0] == 0) return offset + step;
- length = (int)/*64*/OS.g_utf8_strlen(OS.pango_layout_get_text(layout), -1);
- offset = translateOffset(offset);
- PangoLogAttr logAttr = new PangoLogAttr();
- offset = validateOffset(offset, step);
- while (0 < offset && offset < length) {
- OS.memmove(logAttr, attrs[0] + offset * PangoLogAttr.sizeof, PangoLogAttr.sizeof);
- if (((movement & SWT.MOVEMENT_CLUSTER) != 0) && logAttr.is_cursor_position) break;
- if ((movement & SWT.MOVEMENT_WORD) != 0) {
- if (forward) {
- if (logAttr.is_word_end) break;
- } else {
- if (logAttr.is_word_start) break;
- }
- }
- if ((movement & SWT.MOVEMENT_WORD_START) != 0) {
- if (logAttr.is_word_start) break;
- }
- if ((movement & SWT.MOVEMENT_WORD_END) != 0) {
- if (logAttr.is_word_end) break;
- }
- offset = validateOffset(offset, step);
- }
- OS.g_free(attrs[0]);
- return Math.min(Math.max(0, untranslateOffset(offset)), text.length());
-}
-
-/**
- * Returns the character offset for the specified point.
- * For a typical character, the trailing argument will be filled in to
- * indicate whether the point is closer to the leading edge (0) or
- * the trailing edge (1). When the point is over a cluster composed
- * of multiple characters, the trailing argument will be filled with the
- * position of the character in the cluster that is closest to
- * the point.
- *
- * @param point the point
- * @param trailing the trailing buffer
- * @return the character offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getLocation(int, boolean)
- */
-public int getOffset(Point point, int[] trailing) {
- checkLayout();
- if (point == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return getOffset(point.x, point.y, trailing);
-}
-
-/**
- * Returns the character offset for the specified point.
- * For a typical character, the trailing argument will be filled in to
- * indicate whether the point is closer to the leading edge (0) or
- * the trailing edge (1). When the point is over a cluster composed
- * of multiple characters, the trailing argument will be filled with the
- * position of the character in the cluster that is closest to
- * the point.
- *
- * @param x the x coordinate of the point
- * @param y the y coordinate of the point
- * @param trailing the trailing buffer
- * @return the character offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getLocation(int, boolean)
- */
-public int getOffset(int x, int y, int[] trailing) {
- checkLayout();
- computeRuns();
- if (trailing != null && trailing.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL) {
- x = width() - x;
- }
-
- /*
- * Feature in GTK. pango_layout_xy_to_index() returns the
- * logical end/start offset of a line when the coordinates are outside
- * the line bounds. In SWT the correct behavior is to return the closest
- * visual offset. The fix is to clamp the coordinates inside the
- * line bounds.
- */
- int /*long*/ iter = OS.pango_layout_get_iter(layout);
- if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- PangoRectangle rect = new PangoRectangle();
- do {
- OS.pango_layout_iter_get_line_extents(iter, null, rect);
- rect.y = OS.PANGO_PIXELS(rect.y);
- rect.height = OS.PANGO_PIXELS(rect.height);
- if (rect.y <= y && y < rect.y + rect.height) {
- rect.x = OS.PANGO_PIXELS(rect.x);
- rect.width = OS.PANGO_PIXELS(rect.width);
- if (x >= rect.x + rect.width) x = rect.x + rect.width - 1;
- if (x < rect.x) x = rect.x;
- break;
- }
- } while (OS.pango_layout_iter_next_line(iter));
- OS.pango_layout_iter_free(iter);
-
- int[] index = new int[1];
- int[] piTrailing = new int[1];
- OS.pango_layout_xy_to_index(layout, x * OS.PANGO_SCALE, y * OS.PANGO_SCALE, index, piTrailing);
- int /*long*/ ptr = OS.pango_layout_get_text(layout);
- int offset = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + index[0]);
- if (trailing != null) trailing[0] = piTrailing[0];
- return untranslateOffset(offset);
-}
-
-/**
- * Returns the orientation of the receiver.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getOrientation() {
- checkLayout();
- int baseDir = OS.pango_context_get_base_dir(context);
- return baseDir == OS.PANGO_DIRECTION_RTL ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT;
-}
-
-/**
- * Returns the previous offset for the specified offset and movement
- * type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>,
- * <code>SWT.MOVEMENT_CLUSTER</code> or <code>SWT.MOVEMENT_WORD</code>,
- * <code>SWT.MOVEMENT_WORD_END</code> or <code>SWT.MOVEMENT_WORD_START</code>.
- *
- * @param offset the start offset
- * @param movement the movement type
- * @return the previous offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getNextOffset(int, int)
- */
-public int getPreviousOffset (int index, int movement) {
- return _getOffset(index, movement, false);
-}
-
-/**
- * Gets the ranges of text that are associated with a <code>TextStyle</code>.
- *
- * @return the ranges, an array of offsets representing the start and end of each
- * text style.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getStyles()
- *
- * @since 3.2
- */
-public int[] getRanges () {
- checkLayout();
- int[] result = new int[styles.length * 2];
- int count = 0;
- for (int i=0; i<styles.length - 1; i++) {
- if (styles[i].style != null) {
- result[count++] = styles[i].start;
- result[count++] = styles[i + 1].start - 1;
- }
- }
- if (count != result.length) {
- int[] newResult = new int[count];
- System.arraycopy(result, 0, newResult, 0, count);
- result = newResult;
- }
- return result;
-}
-
-/**
- * Returns the text segments offsets of the receiver.
- *
- * @return the text segments offsets
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getSegments() {
- checkLayout();
- return segments;
-}
-
-String getSegmentsText() {
- if (segments == null) return text;
- int nSegments = segments.length;
- if (nSegments <= 1) return text;
- int length = text.length();
- if (length == 0) return text;
- if (nSegments == 2) {
- if (segments[0] == 0 && segments[1] == length) return text;
- }
- char[] oldChars = new char[length];
- text.getChars(0, length, oldChars, 0);
- char[] newChars = new char[length + nSegments];
- int charCount = 0, segmentCount = 0;
- char separator = getOrientation() == SWT.RIGHT_TO_LEFT ? RTL_MARK : LTR_MARK;
- while (charCount < length) {
- if (segmentCount < nSegments && charCount == segments[segmentCount]) {
- newChars[charCount + segmentCount++] = separator;
- } else {
- newChars[charCount + segmentCount] = oldChars[charCount++];
- }
- }
- if (segmentCount < nSegments) {
- segments[segmentCount] = charCount;
- newChars[charCount + segmentCount++] = separator;
- }
- return new String(newChars, 0, Math.min(charCount + segmentCount, newChars.length));
-}
-
-/**
- * Returns the line spacing of the receiver.
- *
- * @return the line spacing
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getSpacing () {
- checkLayout();
- return OS.PANGO_PIXELS(OS.pango_layout_get_spacing(layout));
-}
-
-/**
- * Gets the style of the receiver at the specified character offset.
- *
- * @param offset the text offset
- * @return the style or <code>null</code> if not set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public TextStyle getStyle (int offset) {
- checkLayout();
- int length = text.length();
- if (!(0 <= offset && offset < length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- for (int i=1; i<styles.length; i++) {
- StyleItem item = styles[i];
- if (item.start > offset) {
- return styles[i - 1].style;
- }
- }
- return null;
-}
-
-/**
- * Gets all styles of the receiver.
- *
- * @return the styles
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getRanges()
- *
- * @since 3.2
- */
-public TextStyle[] getStyles () {
- checkLayout();
- TextStyle[] result = new TextStyle[styles.length];
- int count = 0;
- for (int i=0; i<styles.length; i++) {
- if (styles[i].style != null) {
- result[count++] = styles[i].style;
- }
- }
- if (count != result.length) {
- TextStyle[] newResult = new TextStyle[count];
- System.arraycopy(result, 0, newResult, 0, count);
- result = newResult;
- }
- return result;
-}
-
-/**
- * Returns the tab list of the receiver.
- *
- * @return the tab list
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getTabs() {
- checkLayout();
- return tabs;
-}
-
-/**
- * Gets the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public String getText () {
- checkLayout ();
- return text;
-}
-
-/**
- * Returns the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getWidth () {
- checkLayout ();
- int width = OS.pango_layout_get_width(layout);
- return width != -1 ? OS.PANGO_PIXELS(width) : -1;
-}
-
-/**
- * Returns <code>true</code> if the text layout has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the text layout.
- * When a text layout has been disposed, it is an error to
- * invoke any other method using the text layout.
- * </p>
- *
- * @return <code>true</code> when the text layout is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- return layout == 0;
-}
-
-/**
- * Sets the text alignment for the receiver. The alignment controls
- * how a line of text is positioned horizontally. The argument should
- * be one of <code>SWT.LEFT</code>, <code>SWT.RIGHT</code> or <code>SWT.CENTER</code>.
- * <p>
- * The default alignment is <code>SWT.LEFT</code>. Note that the receiver's
- * width must be set in order to use <code>SWT.RIGHT</code> or <code>SWT.CENTER</code>
- * alignment.
- * </p>
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setWidth(int)
- */
-public void setAlignment (int alignment) {
- checkLayout();
- int mask = SWT.LEFT | SWT.CENTER | SWT.RIGHT;
- alignment &= mask;
- if (alignment == 0) return;
- if ((alignment & SWT.LEFT) != 0) alignment = SWT.LEFT;
- if ((alignment & SWT.RIGHT) != 0) alignment = SWT.RIGHT;
- boolean rtl = OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL;
- int align = OS.PANGO_ALIGN_CENTER;
- switch (alignment) {
- case SWT.LEFT:
- align = rtl ? OS.PANGO_ALIGN_RIGHT : OS.PANGO_ALIGN_LEFT;
- break;
- case SWT.RIGHT:
- align = rtl ? OS.PANGO_ALIGN_LEFT : OS.PANGO_ALIGN_RIGHT;
- break;
- }
- OS.pango_layout_set_alignment(layout, align);
-}
-
-/**
- * Sets the ascent of the receiver. The ascent is distance in pixels
- * from the baseline to the top of the line and it is applied to all
- * lines. The default value is <code>-1</code> which means that the
- * ascent is calculated from the line fonts.
- *
- * @param ascent the new ascent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the ascent is less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setDescent(int)
- * @see #getLineMetrics(int)
- */
-public void setAscent (int ascent) {
- checkLayout();
- if (ascent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.ascent == ascent) return;
- freeRuns();
- this.ascent = ascent;
-}
-
-/**
- * Sets the descent of the receiver. The descent is distance in pixels
- * from the baseline to the bottom of the line and it is applied to all
- * lines. The default value is <code>-1</code> which means that the
- * descent is calculated from the line fonts.
- *
- * @param descent the new descent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the descent is less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAscent(int)
- * @see #getLineMetrics(int)
- */
-public void setDescent (int descent) {
- checkLayout();
- if (descent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.descent == descent) return;
- freeRuns();
- this.descent = descent;
-}
-
-/**
- * Sets the default font which will be used by the receiver
- * to draw and measure text. If the
- * argument is null, then a default font appropriate
- * for the platform will be used instead. Note that a text
- * style can override the default font.
- *
- * @param font the new font for the receiver, or null to indicate a default font
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkLayout ();
- if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Font oldFont = this.font;
- if (oldFont == font) return;
- freeRuns();
- this.font = font;
- if (oldFont != null && oldFont.equals(font)) return;
- OS.pango_layout_set_font_description(layout, font != null ? font.handle : device.systemFont.handle);
-}
-
-/**
- * Sets the indent of the receiver. This indent it applied of the first line of
- * each paragraph.
- *
- * @param indent new indent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setIndent (int indent) {
- checkLayout();
- if (indent < 0) return;
- OS.pango_layout_set_indent(layout, indent * OS.PANGO_SCALE);
-}
-
-/**
- * Sets the justification of the receiver. Note that the receiver's
- * width must be set in order to use justification.
- *
- * @param justify new justify
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setJustify (boolean justify) {
- checkLayout();
- OS.pango_layout_set_justify(layout, justify);
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setOrientation(int orientation) {
- checkLayout();
- int mask = SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT;
- orientation &= mask;
- if (orientation == 0) return;
- if ((orientation & SWT.LEFT_TO_RIGHT) != 0) orientation = SWT.LEFT_TO_RIGHT;
- int baseDir = orientation == SWT.RIGHT_TO_LEFT ? OS.PANGO_DIRECTION_RTL : OS.PANGO_DIRECTION_LTR;
- if (OS.pango_context_get_base_dir(context) == baseDir) return;
- OS.pango_context_set_base_dir(context, baseDir);
- OS.pango_layout_context_changed(layout);
- int align = OS.pango_layout_get_alignment(layout);
- if (align != OS.PANGO_ALIGN_CENTER) {
- align = align == OS.PANGO_ALIGN_LEFT ? OS.PANGO_ALIGN_RIGHT : OS.PANGO_ALIGN_LEFT;
- OS.pango_layout_set_alignment(layout, align);
- }
-}
-
-/**
- * Sets the line spacing of the receiver. The line spacing
- * is the space left between lines.
- *
- * @param spacing the new line spacing
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the spacing is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setSpacing (int spacing) {
- checkLayout();
- if (spacing < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.pango_layout_set_spacing(layout, spacing * OS.PANGO_SCALE);
-}
-
-/**
- * Sets the offsets of the receiver's text segments. Text segments are used to
- * override the default behaviour of the bidirectional algorithm.
- * Bidirectional reordering can happen within a text segment but not
- * between two adjacent segments.
- * <p>
- * Each text segment is determined by two consecutive offsets in the
- * <code>segments</code> arrays. The first element of the array should
- * always be zero and the last one should always be equals to length of
- * the text.
- * </p>
- *
- * @param segments the text segments offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setSegments(int[] segments) {
- checkLayout();
- if (this.segments == null && segments == null) return;
- if (this.segments != null && segments !=null) {
- if (this.segments.length == segments.length) {
- int i;
- for (i = 0; i <segments.length; i++) {
- if (this.segments[i] != segments[i]) break;
- }
- if (i == segments.length) return;
- }
- }
- freeRuns();
- this.segments = segments;
-}
-
-/**
- * Sets the style of the receiver for the specified range. Styles previously
- * set for that range will be overwritten. The start and end offsets are
- * inclusive and will be clamped if out of range.
- *
- * @param style the style
- * @param start the start offset
- * @param end the end offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setStyle (TextStyle style, int start, int end) {
- checkLayout();
- int length = text.length();
- if (length == 0) return;
- if (start > end) return;
- start = Math.min(Math.max(0, start), length - 1);
- end = Math.min(Math.max(0, end), length - 1);
-
- /*
- * Bug in Pango. Pango 1.2.2 will cause a segmentation fault if a style
- * is not applied for a whole ligature. The fix is to applied the
- * style for the whole ligature.
- *
- * NOTE that fix only LamAlef ligatures.
- */
- if (start > 0 && isAlef(text.charAt(start)) && isLam(text.charAt(start - 1))) {
- start--;
- }
- if (end < length - 1 && isLam(text.charAt(end)) && isAlef(text.charAt(end + 1))) {
- end++;
- }
-
- int low = -1;
- int high = styles.length;
- while (high - low > 1) {
- int index = (high + low) / 2;
- if (styles[index + 1].start > start) {
- high = index;
- } else {
- low = index;
- }
- }
- if (0 <= high && high < styles.length) {
- StyleItem item = styles[high];
- if (item.start == start && styles[high + 1].start - 1 == end) {
- if (style == null) {
- if (item.style == null) return;
- } else {
- if (style.equals(item.style)) return;
- }
- }
- }
- freeRuns();
- int modifyStart = high;
- int modifyEnd = modifyStart;
- while (modifyEnd < styles.length) {
- if (styles[modifyEnd + 1].start > end) break;
- modifyEnd++;
- }
- if (modifyStart == modifyEnd) {
- int styleStart = styles[modifyStart].start;
- int styleEnd = styles[modifyEnd + 1].start - 1;
- if (styleStart == start && styleEnd == end) {
- styles[modifyStart].style = style;
- return;
- }
- if (styleStart != start && styleEnd != end) {
- StyleItem[] newStyles = new StyleItem[styles.length + 2];
- System.arraycopy(styles, 0, newStyles, 0, modifyStart + 1);
- StyleItem item = new StyleItem();
- item.start = start;
- item.style = style;
- newStyles[modifyStart + 1] = item;
- item = new StyleItem();
- item.start = end + 1;
- item.style = styles[modifyStart].style;
- newStyles[modifyStart + 2] = item;
- System.arraycopy(styles, modifyEnd + 1, newStyles, modifyEnd + 3, styles.length - modifyEnd - 1);
- styles = newStyles;
- return;
- }
- }
- if (start == styles[modifyStart].start) modifyStart--;
- if (end == styles[modifyEnd + 1].start - 1) modifyEnd++;
- int newLength = styles.length + 1 - (modifyEnd - modifyStart - 1);
- StyleItem[] newStyles = new StyleItem[newLength];
- System.arraycopy(styles, 0, newStyles, 0, modifyStart + 1);
- StyleItem item = new StyleItem();
- item.start = start;
- item.style = style;
- newStyles[modifyStart + 1] = item;
- styles[modifyEnd].start = end + 1;
- System.arraycopy(styles, modifyEnd, newStyles, modifyStart + 2, styles.length - modifyEnd);
- styles = newStyles;
-}
-
-/**
- * Sets the receiver's tab list. Each value in the tab list specifies
- * the space in pixels from the origin of the text layout to the respective
- * tab stop. The last tab stop width is repeated continuously.
- *
- * @param tabs the new tab list
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setTabs(int[] tabs) {
- checkLayout();
- if (this.tabs == null && tabs == null) return;
- if (this.tabs!= null && tabs != null) {
- if (this.tabs.length == tabs.length) {
- int i;
- for (i = 0; i <tabs.length; i++) {
- if (this.tabs[i] != tabs[i]) break;
- }
- if (i == tabs.length) return;
- }
- }
- this.tabs = tabs;
- if (tabs == null) {
- OS.pango_layout_set_tabs(layout, device.emptyTab);
- } else {
- int /*long*/ tabArray = OS.pango_tab_array_new(tabs.length, true);
- if (tabArray != 0) {
- for (int i = 0; i < tabs.length; i++) {
- OS.pango_tab_array_set_tab(tabArray, i, OS.PANGO_TAB_LEFT, tabs[i]);
- }
- OS.pango_layout_set_tabs(layout, tabArray);
- OS.pango_tab_array_free(tabArray);
- }
- }
- /*
- * Bug in Pango. A change in the tab stop array is not automatically reflected in the
- * pango layout object because the call pango_layout_set_tabs() does not free the
- * lines cache. The fix to use pango_layout_context_changed() to free the lines cache.
- */
- OS.pango_layout_context_changed(layout);
-}
-
-/**
- * Sets the receiver's text.
- *<p>
- * Note: Setting the text also clears all the styles. This method
- * returns without doing anything if the new text is the same as
- * the current text.
- * </p>
- *
- * @param text the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setText (String text) {
- checkLayout ();
- if (text == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (text.equals(this.text)) return;
- freeRuns();
- this.text = text;
- styles = new StyleItem[2];
- styles[0] = new StyleItem();
- styles[1] = new StyleItem();
- styles[styles.length - 1].start = text.length();
-}
-
-/**
- * Sets the line width of the receiver, which determines how
- * text should be wrapped and aligned. The default value is
- * <code>-1</code> which means wrapping is disabled.
- *
- * @param width the new width
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the width is <code>0</code> or less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAlignment(int)
- */
-public void setWidth (int width) {
- checkLayout ();
- if (width < -1 || width == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- freeRuns();
- if (width == -1) {
- OS.pango_layout_set_width(layout, -1);
- boolean rtl = OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL;
- OS.pango_layout_set_alignment(layout, rtl ? OS.PANGO_ALIGN_RIGHT : OS.PANGO_ALIGN_LEFT);
- } else {
- OS.pango_layout_set_width(layout, width * OS.PANGO_SCALE);
- }
-}
-
-static final boolean isLam(int ch) {
- return ch == 0x0644;
-}
-
-static final boolean isAlef(int ch) {
- switch (ch) {
- case 0x0622:
- case 0x0623:
- case 0x0625:
- case 0x0627:
- case 0x0649:
- case 0x0670:
- case 0x0671:
- case 0x0672:
- case 0x0673:
- case 0x0675:
- return true;
- }
- return false;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "TextLayout {*DISPOSED*}";
- return "TextLayout {" + layout + "}";
-}
-
-/*
- * Translate a client offset to an internal offset
- */
-int translateOffset(int offset) {
- int length = text.length();
- if (length == 0) return offset;
- if (invalidOffsets == null) return offset;
- for (int i = 0; i < invalidOffsets.length; i++) {
- if (offset < invalidOffsets[i]) break;
- offset++;
- }
- return offset;
-}
-
-/*
- * Translate an internal offset to a client offset
- */
-int untranslateOffset(int offset) {
- int length = text.length();
- if (length == 0) return offset;
- if (invalidOffsets == null) return offset;
- for (int i = 0; i < invalidOffsets.length; i++) {
- if (offset == invalidOffsets[i]) {
- offset++;
- continue;
- }
- if (offset < invalidOffsets[i]) {
- return offset - i;
- }
- }
- return offset - invalidOffsets.length;
-}
-
-int validateOffset(int offset, int step) {
- if (invalidOffsets == null) return offset + step;
- int i = step > 0 ? 0 : invalidOffsets.length - 1;
- do {
- offset += step;
- while (0 <= i && i < invalidOffsets.length) {
- if (invalidOffsets[i] == offset) break;
- i += step;
- }
- } while (0 <= i && i < invalidOffsets.length);
- return offset;
-}
-
-int width () {
- int wrapWidth = OS.pango_layout_get_width(layout);
- if (wrapWidth != -1) return OS.PANGO_PIXELS(wrapWidth);
- int[] w = new int[1], h = new int[1];
- OS.pango_layout_get_size(layout, w, h);
- return OS.PANGO_PIXELS(w[0] + OS.pango_layout_get_indent(layout));
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/Converter.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/Converter.java
deleted file mode 100644
index 779baed6f8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/Converter.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal;
-
-
-import org.eclipse.swt.internal.gtk.OS;
-
-/**
- * This class implements the conversions between unicode characters
- * and the <em>platform supported</em> representation for characters.
- * <p>
- * Note that, unicode characters which can not be found in the platform
- * encoding will be converted to an arbitrary platform specific character.
- * </p>
- */
-public final class Converter {
- public static final byte [] NullByteArray = new byte [1];
- public static final byte [] EmptyByteArray = new byte [0];
- public static final char [] EmptyCharArray = new char [0];
-
-/**
- * Returns the default code page for the platform where the
- * application is currently running.
- *
- * @return the default code page
- */
-public static String defaultCodePage () {
- return "UTF8";
-}
-
-public static char [] mbcsToWcs (String codePage, byte [] buffer) {
- int /*long*/ [] items_written = new int /*long*/ [1];
- int /*long*/ ptr = OS.g_utf8_to_utf16 (buffer, buffer.length, null, items_written, null);
- if (ptr == 0) return EmptyCharArray;
- int length = (int)/*64*/items_written [0];
- char [] chars = new char [length];
- OS.memmove (chars, ptr, length * 2);
- OS.g_free (ptr);
- return chars;
-}
-
-public static byte [] wcsToMbcs (String codePage, String string, boolean terminate) {
- int length = string.length ();
- char [] buffer = new char [length];
- string.getChars (0, length, buffer, 0);
- return wcsToMbcs (codePage, buffer, terminate);
-}
-
-public static byte [] wcsToMbcs (String codePage, char [] buffer, boolean terminate) {
- int /*long*/ [] items_read = new int /*long*/ [1], items_written = new int /*long*/ [1];
- /*
- * Note that g_utf16_to_utf8() stops converting
- * when it finds the first NULL.
- */
- int /*long*/ ptr = OS.g_utf16_to_utf8 (buffer, buffer.length, items_read, items_written, null);
- if (ptr == 0) return terminate ? NullByteArray : EmptyByteArray;
- int written = (int)/*64*/items_written [0];
- byte [] bytes = new byte [written + (terminate ? 1 : 0)];
- OS.memmove (bytes, ptr, written);
- OS.g_free (ptr);
- return bytes;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java
deleted file mode 100644
index 41802dc836..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java
+++ /dev/null
@@ -1,836 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface object that
- * issues notification when pressed and released.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>ARROW, CHECK, PUSH, RADIO, TOGGLE, FLAT</dd>
- * <dd>UP, DOWN, LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles ARROW, CHECK, PUSH, RADIO, and TOGGLE
- * may be specified.
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT, and CENTER may be specified.
- * </p><p>
- * Note: Only one of the styles UP, DOWN, LEFT, and RIGHT may be specified
- * when the ARROW style is specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#button">Button snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Button extends Control {
- int /*long*/ boxHandle, labelHandle, imageHandle, arrowHandle, groupHandle;
- boolean selected, grayed;
- ImageList imageList;
- Image image;
- String text;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#ARROW
- * @see SWT#CHECK
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#TOGGLE
- * @see SWT#FLAT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Button (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- style = checkBits (style, SWT.PUSH, SWT.ARROW, SWT.CHECK, SWT.RADIO, SWT.TOGGLE, 0);
- if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) {
- return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0);
- }
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0);
- }
- if ((style & SWT.ARROW) != 0) {
- style |= SWT.NO_FOCUS;
- return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0);
- }
- return style;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected by the user.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- /*
- * Feature in GTK, GtkCheckButton and GtkRadioButton allocate
- * only the minimum size necessary for its child. This causes the child
- * alignment to fail. The fix is to set the child size to the size
- * of the button.
- */
- forceResize ();
- int [] reqWidth = null, reqHeight = null;
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- reqWidth = new int [1];
- reqHeight = new int [1];
- OS.gtk_widget_get_size_request (boxHandle, reqWidth, reqHeight);
- OS.gtk_widget_set_size_request (boxHandle, -1, -1);
- }
- Point size = computeNativeSize (handle, wHint, hHint, changed);
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- OS.gtk_widget_set_size_request (boxHandle, reqWidth [0], reqHeight [0]);
- }
- if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) {
- if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_CAN_DEFAULT) != 0) {
- int /*long*/ [] buffer = new int /*long*/ [1];
- GtkBorder border = new GtkBorder ();
- OS.gtk_widget_style_get (handle, OS.default_border, buffer, 0);
- if (buffer[0] != 0) {
- OS.memmove (border, buffer[0], GtkBorder.sizeof);
- } else {
- /* Use the GTK+ default value of 1 for each. */
- border.left = border.right = border.top = border.bottom = 1;
- }
- if (wHint != SWT.DEFAULT) size.x += border.left + border.right;
- if (hHint != SWT.DEFAULT) size.y += border.top + border.bottom;
- }
- }
- return size;
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- if ((style & (SWT.PUSH | SWT.TOGGLE)) == 0) state |= THEME_BACKGROUND;
- int bits = SWT.ARROW | SWT.TOGGLE | SWT.CHECK | SWT.RADIO | SWT.PUSH;
- fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (fixedHandle, true);
- switch (style & bits) {
- case SWT.ARROW:
- int arrow_type = OS.GTK_ARROW_UP;
- if ((style & SWT.UP) != 0) arrow_type = OS.GTK_ARROW_UP;
- if ((style & SWT.DOWN) != 0) arrow_type = OS.GTK_ARROW_DOWN;
- if ((style & SWT.LEFT) != 0) arrow_type = OS.GTK_ARROW_LEFT;
- if ((style & SWT.RIGHT) != 0) arrow_type = OS.GTK_ARROW_RIGHT;
- handle = OS.gtk_button_new ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- arrowHandle = OS.gtk_arrow_new (arrow_type, OS.GTK_SHADOW_OUT);
- if (arrowHandle == 0) error (SWT.ERROR_NO_HANDLES);
- break;
- case SWT.TOGGLE:
- handle = OS.gtk_toggle_button_new ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- break;
- case SWT.CHECK:
- handle = OS.gtk_check_button_new ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- break;
- case SWT.RADIO:
- /*
- * Feature in GTK. In GTK, radio button must always be part of
- * a radio button group. In a GTK radio group, one button is always
- * selected. This means that it is not possible to have a single
- * radio button that is unselected. This is necessary to allow
- * applications to implement their own radio behavior or use radio
- * buttons outside of radio groups. The fix is to create a hidden
- * radio button for each radio button we create and add them
- * to the same group. This allows the visible button to be
- * unselected.
- */
- groupHandle = OS.gtk_radio_button_new (0);
- if (groupHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.g_object_ref (groupHandle);
- OS.gtk_object_sink (groupHandle);
- handle = OS.gtk_radio_button_new (OS.gtk_radio_button_get_group (groupHandle));
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- break;
- case SWT.PUSH:
- default:
- handle = OS.gtk_button_new ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.GTK_WIDGET_SET_FLAGS(handle, OS.GTK_CAN_DEFAULT);
- break;
- }
- if ((style & SWT.ARROW) != 0) {
- OS.gtk_container_add (handle, arrowHandle);
- } else {
- boxHandle = OS.gtk_hbox_new (false, 4);
- if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES);
- labelHandle = OS.gtk_label_new_with_mnemonic (null);
- if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES);
- imageHandle = OS.gtk_image_new ();
- if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (handle, boxHandle);
- OS.gtk_container_add (boxHandle, imageHandle);
- OS.gtk_container_add (boxHandle, labelHandle);
- }
- OS.gtk_container_add (fixedHandle, handle);
-
- if ((style & SWT.ARROW) != 0) return;
- _setAlignment (style & (SWT.LEFT | SWT.CENTER | SWT.RIGHT));
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- text = "";
-}
-
-void deregister () {
- super.deregister ();
- if (boxHandle != 0) display.removeWidget (boxHandle);
- if (labelHandle != 0) display.removeWidget (labelHandle);
- if (imageHandle != 0) display.removeWidget (imageHandle);
- if (arrowHandle != 0) display.removeWidget (arrowHandle);
-}
-
-int /*long*/ fontHandle () {
- if (labelHandle != 0) return labelHandle;
- return super.fontHandle ();
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is an <code>ARROW</code> button, in
- * which case, the alignment will indicate the direction of
- * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>,
- * <code>UP</code> or <code>DOWN</code>).
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget ();
- if ((style & SWT.ARROW) != 0) {
- if ((style & SWT.UP) != 0) return SWT.UP;
- if ((style & SWT.DOWN) != 0) return SWT.DOWN;
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.UP;
- }
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the widget does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getGrayed () {
- checkWidget();
- if ((style & SWT.CHECK) == 0) return false;
- return grayed;
-}
-
-/**
- * Returns the receiver's image if it has one, or null
- * if it does not.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget ();
- return image;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked. When it is of type <code>TOGGLE</code>,
- * it is selected when it is pushed in. If the receiver is of any other type,
- * this method returns false.
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget ();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false;
- return OS.gtk_toggle_button_get_active (handle);
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set or if the receiver is
- * an <code>ARROW</code> button.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- if ((style & SWT.ARROW) != 0) return "";
- return text;
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_button_press_event (widget, event);
- if (result != 0) return result;
- if ((style & SWT.RADIO) != 0) selected = getSelection ();
- return result;
-}
-
-int /*long*/ gtk_clicked (int /*long*/ widget) {
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) != 0) {
- setSelection (!selected);
- } else {
- selectRadio ();
- }
- } else {
- if ((style & SWT.CHECK) != 0) {
- if (grayed) {
- if (OS.gtk_toggle_button_get_active (handle)) {
- OS.gtk_toggle_button_set_inconsistent (handle, true);
- } else {
- OS.gtk_toggle_button_set_inconsistent (handle, false);
- }
- }
- }
- }
- postEvent (SWT.Selection);
- return 0;
-}
-
-int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_focus_in_event (widget, event);
- // widget could be disposed at this point
- if (handle == 0) return 0;
- if ((style & SWT.PUSH) != 0 && OS.GTK_WIDGET_HAS_DEFAULT (handle)) {
- Decorations menuShell = menuShell ();
- menuShell.defaultButton = this;
- }
- return result;
-}
-
-int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_focus_out_event (widget, event);
- // widget could be disposed at this point
- if (handle == 0) return 0;
- if ((style & SWT.PUSH) != 0 && !OS.GTK_WIDGET_HAS_DEFAULT (handle)) {
- Decorations menuShell = menuShell ();
- if (menuShell.defaultButton == this) {
- menuShell.defaultButton = null;
- }
- }
- return result;
-}
-
-int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_key_press_event (widget, event);
- if (result != 0) return result;
- if ((style & SWT.RADIO) != 0) selected = getSelection ();
- return result;
-}
-
-void hookEvents () {
- super.hookEvents();
- OS.g_signal_connect_closure (handle, OS.clicked, display.closures [CLICKED], false);
- if (labelHandle != 0) {
- OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false);
- }
-}
-
-boolean isDescribedByLabel () {
- return false;
-}
-
-boolean mnemonicHit (char key) {
- if (labelHandle == 0) return false;
- boolean result = super.mnemonicHit (labelHandle, key);
- if (result) setFocus ();
- return result;
-}
-
-boolean mnemonicMatch (char key) {
- if (labelHandle == 0) return false;
- return mnemonicMatch (labelHandle, key);
-}
-
-void register () {
- super.register ();
- if (boxHandle != 0) display.addWidget (boxHandle, this);
- if (labelHandle != 0) display.addWidget (labelHandle, this);
- if (imageHandle != 0) display.addWidget (imageHandle, this);
- if (arrowHandle != 0) display.addWidget (arrowHandle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- boxHandle = imageHandle = labelHandle = arrowHandle = 0;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (groupHandle != 0) OS.g_object_unref (groupHandle);
- groupHandle = 0;
- if (imageList != null) imageList.dispose ();
- imageList = null;
- image = null;
- text = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-void resizeHandle (int width, int height) {
- super.resizeHandle (width, height);
- /*
- * Feature in GTK, GtkCheckButton and GtkRadioButton allocate
- * only the minimum size necessary for its child. This causes the child
- * alignment to fail. The fix is to set the child size to the size
- * of the button.
- */
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- OS.gtk_widget_set_size_request (boxHandle, width, -1);
- }
-}
-
-void selectRadio () {
- /*
- * This code is intentionally commented. When two groups
- * of radio buttons with the same parent are separated by
- * another control, the correct behavior should be that
- * the two groups act independently. This is consistent
- * with radio tool and menu items. The commented code
- * implements this behavior.
- */
-// int index = 0;
-// Control [] children = parent._getChildren ();
-// while (index < children.length && children [index] != this) index++;
-// int i = index - 1;
-// while (i >= 0 && children [i].setRadioSelection (false)) --i;
-// int j = index + 1;
-// while (j < children.length && children [j].setRadioSelection (false)) j++;
-// setSelection (true);
- Control [] children = parent._getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (this != child) child.setRadioSelection (false);
- }
- setSelection (true);
-}
-
-/**
- * Controls how text, images and arrows will be displayed
- * in the receiver. The argument should be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is an <code>ARROW</code> button, in
- * which case, the argument indicates the direction of
- * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>,
- * <code>UP</code> or <code>DOWN</code>).
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget ();
- _setAlignment (alignment);
-}
-
-void _setAlignment (int alignment) {
- if ((style & SWT.ARROW) != 0) {
- if ((style & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT)) == 0) return;
- style &= ~(SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT);
- style |= alignment & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT);
- int arrow_type = OS.GTK_ARROW_UP;
- boolean isRTL = (style & SWT.RIGHT_TO_LEFT) != 0;
- switch (alignment) {
- case SWT.UP: arrow_type = OS.GTK_ARROW_UP; break;
- case SWT.DOWN: arrow_type = OS.GTK_ARROW_DOWN; break;
- case SWT.LEFT: arrow_type = isRTL ? OS.GTK_ARROW_RIGHT : OS.GTK_ARROW_LEFT; break;
- case SWT.RIGHT: arrow_type = isRTL ? OS.GTK_ARROW_LEFT : OS.GTK_ARROW_RIGHT; break;
- }
- OS.gtk_arrow_set (arrowHandle, arrow_type, OS.GTK_SHADOW_OUT);
- return;
- }
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- /* Alignment not honoured when image and text are visible */
- boolean bothVisible = OS.GTK_WIDGET_VISIBLE (labelHandle) && OS.GTK_WIDGET_VISIBLE (imageHandle);
- if (bothVisible) {
- if ((style & (SWT.RADIO | SWT.CHECK)) != 0) alignment = SWT.LEFT;
- if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) alignment = SWT.CENTER;
- }
- if ((alignment & SWT.LEFT) != 0) {
- if (bothVisible) {
- OS.gtk_box_set_child_packing (boxHandle, labelHandle, false, false, 0, OS.GTK_PACK_START);
- OS.gtk_box_set_child_packing (boxHandle, imageHandle, false, false, 0, OS.GTK_PACK_START);
- }
- OS.gtk_misc_set_alignment (labelHandle, 0.0f, 0.5f);
- OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_LEFT);
- OS.gtk_misc_set_alignment (imageHandle, 0.0f, 0.5f);
- return;
- }
- if ((alignment & SWT.CENTER) != 0) {
- if (bothVisible) {
- OS.gtk_box_set_child_packing (boxHandle, labelHandle, true, true, 0, OS.GTK_PACK_END);
- OS.gtk_box_set_child_packing (boxHandle, imageHandle, true, true, 0, OS.GTK_PACK_START);
- OS.gtk_misc_set_alignment (labelHandle, 0f, 0.5f);
- OS.gtk_misc_set_alignment (imageHandle, 1f, 0.5f);
- } else {
- OS.gtk_misc_set_alignment (labelHandle, 0.5f, 0.5f);
- OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_CENTER);
- OS.gtk_misc_set_alignment (imageHandle, 0.5f, 0.5f);
- }
- return;
- }
- if ((alignment & SWT.RIGHT) != 0) {
- if (bothVisible) {
- OS.gtk_box_set_child_packing (boxHandle, labelHandle, false, false, 0, OS.GTK_PACK_END);
- OS.gtk_box_set_child_packing (boxHandle, imageHandle, false, false, 0, OS.GTK_PACK_END);
- }
- OS.gtk_misc_set_alignment (labelHandle, 1.0f, 0.5f);
- OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_RIGHT);
- OS.gtk_misc_set_alignment (imageHandle, 1.0f, 0.5f);
- return;
- }
-}
-
-void setBackgroundColor (GdkColor color) {
- super.setBackgroundColor (color);
- setBackgroundColor(fixedHandle, color);
- if (labelHandle != 0) setBackgroundColor(labelHandle, color);
- if (imageHandle != 0) setBackgroundColor(imageHandle, color);
-}
-
-void setFontDescription (int /*long*/ font) {
- super.setFontDescription (font);
- if (labelHandle != 0) OS.gtk_widget_modify_font (labelHandle, font);
- if (imageHandle != 0) OS.gtk_widget_modify_font (imageHandle, font);
-}
-
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-
-void setForegroundColor (GdkColor color) {
- super.setForegroundColor (color);
- setForegroundColor (fixedHandle, color);
- if (labelHandle != 0) setForegroundColor (labelHandle, color);
- if (imageHandle != 0) setForegroundColor (imageHandle, color);
-}
-
-/**
- * Sets the grayed state of the receiver. This state change
- * only applies if the control was created with the SWT.CHECK
- * style.
- *
- * @param grayed the new grayed state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setGrayed (boolean grayed) {
- checkWidget();
- if ((style & SWT.CHECK) == 0) return;
- this.grayed = grayed;
- if (grayed && OS.gtk_toggle_button_get_active (handle)) {
- OS.gtk_toggle_button_set_inconsistent (handle, true);
- } else {
- OS.gtk_toggle_button_set_inconsistent (handle, false);
- }
-}
-
-/**
- * Sets the receiver's image to the argument, which may be
- * <code>null</code> indicating that no image should be displayed.
- * <p>
- * Note that a Button can display an image and text simultaneously
- * on Windows (starting with XP), GTK+ and OSX. On other platforms,
- * a Button that has an image and text set into it will display the
- * image or text that was set most recently.
- * </p>
- * @param image the image to display on the receiver (may be <code>null</code>)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if ((style & SWT.ARROW) != 0) return;
- if (imageList != null) imageList.dispose ();
- imageList = null;
- if (image != null) {
- if (image.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- imageList = new ImageList ();
- int imageIndex = imageList.add (image);
- int /*long*/ pixbuf = imageList.getPixbuf (imageIndex);
- OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf);
- if (text.length () == 0) OS.gtk_widget_hide (labelHandle);
- OS.gtk_widget_show (imageHandle);
- } else {
- OS.gtk_image_set_from_pixbuf (imageHandle, 0);
- OS.gtk_widget_show (labelHandle);
- OS.gtk_widget_hide (imageHandle);
- }
- this.image = image;
- _setAlignment (style);
-}
-
-void setOrientation () {
- super.setOrientation ();
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- if (boxHandle != 0) OS.gtk_widget_set_direction (boxHandle, OS.GTK_TEXT_DIR_RTL);
- if (labelHandle != 0) OS.gtk_widget_set_direction (labelHandle, OS.GTK_TEXT_DIR_RTL);
- if (imageHandle != 0) OS.gtk_widget_set_direction (imageHandle, OS.GTK_TEXT_DIR_RTL);
- if (arrowHandle != 0) {
- switch (style & (SWT.LEFT | SWT.RIGHT)) {
- case SWT.LEFT: OS.gtk_arrow_set (arrowHandle, OS.GTK_ARROW_RIGHT, OS.GTK_SHADOW_OUT); break;
- case SWT.RIGHT: OS.gtk_arrow_set (arrowHandle, OS.GTK_ARROW_LEFT, OS.GTK_SHADOW_OUT); break;
- }
- }
- }
-}
-
-/**
- * Sets the selection state of the receiver, if it is of type <code>CHECK</code>,
- * <code>RADIO</code>, or <code>TOGGLE</code>.
- *
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked. When it is of type <code>TOGGLE</code>,
- * it is selected when it is pushed in.
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return;
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED);
- OS.gtk_toggle_button_set_active (handle, selected);
- if ((style & SWT.CHECK) != 0) {
- if (selected && grayed) {
- OS.gtk_toggle_button_set_inconsistent (handle, true);
- } else {
- OS.gtk_toggle_button_set_inconsistent (handle, false);
- }
- }
- if ((style & SWT.RADIO) != 0) OS.gtk_toggle_button_set_active (groupHandle, !selected);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED);
-}
-
-/**
- * Sets the receiver's text.
- * <p>
- * This method sets the button label. The label may include
- * the mnemonic character but must not contain line delimiters.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasized in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p><p>
- * Note that a Button can display an image and text simultaneously
- * on Windows (starting with XP), GTK+ and OSX. On other platforms,
- * a Button that has an image and text set into it will display the
- * image or text that was set most recently.
- * </p>
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.ARROW) != 0) return;
- text = string;
- char [] chars = fixMnemonic (string);
- byte [] buffer = Converter.wcsToMbcs (null, chars, true);
- OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer);
- if (image == null) OS.gtk_widget_hide (imageHandle);
- OS.gtk_widget_show (labelHandle);
- _setAlignment (style);
-}
-
-void showWidget () {
- super.showWidget ();
- if (boxHandle != 0) OS.gtk_widget_show (boxHandle);
- if (labelHandle != 0) OS.gtk_widget_show (labelHandle);
- if (arrowHandle != 0) OS.gtk_widget_show (arrowHandle);
-}
-
-int traversalCode (int key, GdkEventKey event) {
- int code = super.traversalCode (key, event);
- if ((style & SWT.ARROW) != 0) code &= ~(SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS);
- if ((style & SWT.RADIO) != 0) code |= SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS;
- return code;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java
deleted file mode 100644
index ea6a1495d8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java
+++ /dev/null
@@ -1,407 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class provide a surface for drawing
- * arbitrary graphics.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * This class may be subclassed by custom control implementors
- * who are building controls that are <em>not</em> constructed
- * from aggregates of other controls. That is, they are either
- * painted using SWT graphics calls or are handled by native
- * methods.
- * </p>
- *
- * @see Composite
- * @see <a href="http://www.eclipse.org/swt/snippets/#canvas">Canvas snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class Canvas extends Composite {
- Caret caret;
- IME ime;
-
-Canvas () {}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Canvas (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Fills the interior of the rectangle specified by the arguments,
- * with the receiver's background.
- *
- * @param gc the gc where the rectangle is to be filled
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void drawBackground (GC gc, int x, int y, int width, int height) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- super.drawBackground (gc, x, y, width, height);
-}
-
-/**
- * Returns the caret.
- * <p>
- * The caret for the control is automatically hidden
- * and shown when the control is painted or resized,
- * when focus is gained or lost and when an the control
- * is scrolled. To avoid drawing on top of the caret,
- * the programmer must hide and show the caret when
- * drawing in the window any other time.
- * </p>
- *
- * @return the caret for the receiver, may be null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Caret getCaret () {
- checkWidget();
- return caret;
-}
-
-Point getIMCaretPos () {
- if (caret == null) return super.getIMCaretPos ();
- return new Point (caret.x, caret.y);
-}
-
-/**
- * Returns the IME.
- *
- * @return the IME
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public IME getIME () {
- checkWidget ();
- return ime;
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) {
- if (ime != null) {
- int /*long*/ result = ime.gtk_button_press_event (widget, event);
- if (result != 0) return result;
- }
- return super.gtk_button_press_event (widget, event);
-}
-
-int /*long*/ gtk_commit (int /*long*/ imcontext, int /*long*/ text) {
- if (ime != null) {
- int /*long*/ result = ime.gtk_commit (imcontext, text);
- if (result != 0) return result;
- }
- return super.gtk_commit (imcontext, text);
-}
-
-int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ event) {
- if ((state & OBSCURED) != 0) return 0;
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- int /*long*/ result = super.gtk_expose_event (widget, event);
- if (isFocus) caret.setFocus ();
- return result;
-}
-
-int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_focus_in_event (widget, event);
- if (caret != null) caret.setFocus ();
- return result;
-}
-
-int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_focus_out_event (widget, event);
- if (caret != null) caret.killFocus ();
- return result;
-}
-
-int /*long*/ gtk_preedit_changed (int /*long*/ imcontext) {
- if (ime != null) {
- int /*long*/ result = ime.gtk_preedit_changed (imcontext);
- if (result != 0) return result;
- }
- return super.gtk_preedit_changed (imcontext);
-}
-
-void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean all, boolean trim) {
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- super.redrawWidget (x, y, width, height, redrawAll, all, trim);
- if (isFocus) caret.setFocus ();
-}
-
-void releaseChildren (boolean destroy) {
- if (caret != null) {
- caret.release (false);
- caret = null;
- }
- if (ime != null) {
- ime.release (false);
- ime = null;
- }
- super.releaseChildren (destroy);
-}
-
-/**
- * Scrolls a rectangular area of the receiver by first copying
- * the source area to the destination and then causing the area
- * of the source which is not covered by the destination to
- * be repainted. Children that intersect the rectangle are
- * optionally moved during the operation. In addition, outstanding
- * paint events are flushed before the source area is copied to
- * ensure that the contents of the canvas are drawn correctly.
- *
- * @param destX the x coordinate of the destination
- * @param destY the y coordinate of the destination
- * @param x the x coordinate of the source
- * @param y the y coordinate of the source
- * @param width the width of the area
- * @param height the height of the area
- * @param all <code>true</code>if children should be scrolled, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) {
- checkWidget();
- if (width <= 0 || height <= 0) return;
- if ((style & SWT.MIRRORED) != 0) {
- int clientWidth = getClientWidth ();
- x = clientWidth - width - x;
- destX = clientWidth - width - destX;
- }
- int deltaX = destX - x, deltaY = destY - y;
- if (deltaX == 0 && deltaY == 0) return;
- if (!isVisible ()) return;
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- int /*long*/ window = paintWindow ();
- int /*long*/ visibleRegion = OS.gdk_drawable_get_visible_region (window);
- GdkRectangle srcRect = new GdkRectangle ();
- srcRect.x = x;
- srcRect.y = y;
- srcRect.width = width;
- srcRect.height = height;
- int /*long*/ copyRegion = OS.gdk_region_rectangle (srcRect);
- OS.gdk_region_intersect(copyRegion, visibleRegion);
- int /*long*/ invalidateRegion = OS.gdk_region_rectangle (srcRect);
- OS.gdk_region_subtract (invalidateRegion, visibleRegion);
- OS.gdk_region_offset (invalidateRegion, deltaX, deltaY);
- GdkRectangle copyRect = new GdkRectangle();
- OS.gdk_region_get_clipbox (copyRegion, copyRect);
- if (copyRect.width != 0 && copyRect.height != 0) {
- update ();
- }
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- if (control.backgroundImage != null) {
- redrawWidget (x, y, width, height, false, false, false);
- redrawWidget (destX, destY, width, height, false, false, false);
- } else {
-// GC gc = new GC (this);
-// gc.copyArea (x, y, width, height, destX, destY);
-// gc.dispose ();
- int /*long*/ gdkGC = OS.gdk_gc_new (window);
- OS.gdk_gc_set_exposures (gdkGC, true);
- OS.gdk_draw_drawable (window, gdkGC, window, copyRect.x, copyRect.y, copyRect.x + deltaX, copyRect.y + deltaY, copyRect.width, copyRect.height);
- OS.g_object_unref (gdkGC);
- boolean disjoint = (destX + width < x) || (x + width < destX) || (destY + height < y) || (y + height < destY);
- if (disjoint) {
- GdkRectangle rect = new GdkRectangle ();
- rect.x = x;
- rect.y = y;
- rect.width = width;
- rect.height = height;
- OS.gdk_region_union_with_rect (invalidateRegion, rect);
- } else {
- GdkRectangle rect = new GdkRectangle ();
- if (deltaX != 0) {
- int newX = destX - deltaX;
- if (deltaX < 0) newX = destX + width;
- rect.x = newX;
- rect.y = y;
- rect.width = Math.abs(deltaX);
- rect.height = height;
- OS.gdk_region_union_with_rect (invalidateRegion, rect);
- }
- if (deltaY != 0) {
- int newY = destY - deltaY;
- if (deltaY < 0) newY = destY + height;
- rect.x = x;
- rect.y = newY;
- rect.width = width;
- rect.height = Math.abs(deltaY);
- OS.gdk_region_union_with_rect (invalidateRegion, rect);
- }
- }
- OS.gdk_window_invalidate_region(window, invalidateRegion, all);
- OS.gdk_region_destroy (visibleRegion);
- OS.gdk_region_destroy (copyRegion);
- OS.gdk_region_destroy (invalidateRegion);
- }
- if (all) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- Rectangle rect = child.getBounds ();
- if (Math.min(x + width, rect.x + rect.width) >= Math.max (x, rect.x) &&
- Math.min(y + height, rect.y + rect.height) >= Math.max (y, rect.y)) {
- child.setLocation (rect.x + deltaX, rect.y + deltaY);
- }
- }
- }
- if (isFocus) caret.setFocus ();
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- int result = super.setBounds (x, y, width, height, move, resize);
- if (isFocus) caret.setFocus ();
- return result;
-}
-
-/**
- * Sets the receiver's caret.
- * <p>
- * The caret for the control is automatically hidden
- * and shown when the control is painted or resized,
- * when focus is gained or lost and when an the control
- * is scrolled. To avoid drawing on top of the caret,
- * the programmer must hide and show the caret when
- * drawing in the window any other time.
- * </p>
- * @param caret the new caret for the receiver, may be null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the caret has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCaret (Caret caret) {
- checkWidget();
- Caret newCaret = caret;
- Caret oldCaret = this.caret;
- this.caret = newCaret;
- if (hasFocus ()) {
- if (oldCaret != null) oldCaret.killFocus ();
- if (newCaret != null) {
- if (newCaret.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- newCaret.setFocus ();
- }
- }
-}
-
-public void setFont (Font font) {
- checkWidget();
- if (caret != null) caret.setFont (font);
- super.setFont (font);
-}
-
-/**
- * Sets the receiver's IME.
- *
- * @param ime the new IME for the receiver, may be null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the IME has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setIME (IME ime) {
- checkWidget ();
- if (ime != null && ime.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- this.ime = ime;
-}
-
-void updateCaret () {
- int /*long*/ imHandle = imHandle ();
- if (imHandle == 0) return;
- GdkRectangle rect = new GdkRectangle ();
- rect.x = caret.x;
- rect.y = caret.y;
- rect.width = caret.width;
- rect.height = caret.height;
- OS.gtk_im_context_set_cursor_location (imHandle, rect);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java
deleted file mode 100644
index 8bfa82fd71..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java
+++ /dev/null
@@ -1,515 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide an i-beam that is typically used
- * as the insertion point for text.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#caret">Caret snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Canvas tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Caret extends Widget {
- Canvas parent;
- int x, y, width, height;
- boolean isVisible, isShowing;
- int blinkRate;
- Image image;
- Font font;
-
- static final int DEFAULT_WIDTH = 1;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Caret (Canvas parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget (0);
-}
-
-boolean blinkCaret () {
- if (!isVisible) return true;
- if (!isShowing) return showCaret ();
- if (blinkRate == 0) return true;
- return hideCaret ();
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- blinkRate = display.getCaretBlinkTime ();
- isVisible = true;
- if (parent.getCaret () == null) {
- parent.setCaret (this);
- }
-}
-
-boolean drawCaret () {
- if (parent == null) return false;
- if (parent.isDisposed ()) return false;
- int /*long*/ window = parent.paintWindow ();
- int /*long*/ gc = OS.gdk_gc_new (window);
- GdkColor color = new GdkColor ();
- color.red = (short) 0xffff;
- color.green = (short) 0xffff;
- color.blue = (short) 0xffff;
- int /*long*/ colormap = OS.gdk_colormap_get_system ();
- OS.gdk_colormap_alloc_color (colormap, color, true, true);
- OS.gdk_gc_set_foreground (gc, color);
- OS.gdk_gc_set_function (gc, OS.GDK_XOR);
- if (image != null && !image.isDisposed() && image.mask == 0) {
- int[] width = new int[1]; int[] height = new int[1];
- OS.gdk_drawable_get_size(image.pixmap, width, height);
- int nX = x;
- if ((parent.style & SWT.MIRRORED) != 0) nX = parent.getClientWidth () - width[0] - nX;
- OS.gdk_draw_drawable(window, gc, image.pixmap, 0, 0, nX, y, width[0], height[0]);
- } else {
- int nWidth = width, nHeight = height;
- if (nWidth <= 0) nWidth = DEFAULT_WIDTH;
- int nX = x;
- if ((parent.style & SWT.MIRRORED) != 0) nX = parent.getClientWidth () - nWidth - nX;
- OS.gdk_draw_rectangle (window, gc, 1, nX, y, nWidth, nHeight);
- }
- OS.g_object_unref (gc);
- OS.gdk_colormap_free_colors (colormap, color, 1);
- return true;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null).
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- if (image != null) {
- Rectangle rect = image.getBounds ();
- return new Rectangle (x, y, rect.width, rect.height);
- } else {
- if (width == 0) {
- return new Rectangle (x, y, DEFAULT_WIDTH, height);
- }
- }
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Font getFont () {
- checkWidget();
- if (font != null) return font;
- return parent.getFont ();
-}
-
-/**
- * Returns the image that the receiver will use to paint the caret.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null).
- *
- * @return the receiver's location
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getLocation () {
- checkWidget();
- return new Point (x, y);
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Canvas</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Canvas getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns a point describing the receiver's size.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- if (image != null) {
- Rectangle rect = image.getBounds ();
- return new Point (rect.width, rect.height);
- } else {
- if (width == 0) {
- return new Point (DEFAULT_WIDTH, height);
- }
- }
- return new Point (width, height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- return isVisible;
-}
-
-boolean hideCaret () {
- if (!isShowing) return true;
- isShowing = false;
- return drawCaret ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return isVisible && parent.isVisible () && parent.hasFocus ();
-}
-
-boolean isFocusCaret () {
- return this == display.currentCaret;
-}
-
-void killFocus () {
- if (display.currentCaret != this) return;
- display.setCurrentCaret (null);
- if (isVisible) hideCaret ();
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (this == parent.getCaret ()) parent.setCaret (null);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (display.currentCaret == this) {
- hideCaret ();
- display.setCurrentCaret (null);
- }
- parent = null;
- image = null;
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the arguments. The <code>x</code> and
- * <code>y</code> arguments are relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (int x, int y, int width, int height) {
- checkWidget();
- if (this.x == x && this.y == y && this.width == width && this.height == height) return;
- boolean isFocus = isFocusCaret ();
- if (isFocus && isVisible) hideCaret ();
- this.x = x; this.y = y;
- this.width = width; this.height = height;
- parent.updateCaret ();
- if (isFocus && isVisible) showCaret ();
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the argument. The <code>x</code> and
- * <code>y</code> fields of the rectangle are relative to
- * the receiver's parent (or its display if its parent is null).
- *
- * @param rect the new bounds for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (Rectangle rect) {
- checkWidget();
- if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (rect.x, rect.y, rect.width, rect.height);
-}
-
-void setFocus () {
- if (display.currentCaret == this) return;
- display.setCurrentCaret (this);
- if (isVisible) showCaret ();
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * to the font specified by the argument, or to the default font for that
- * kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkWidget();
- if (font != null && font.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.font = font;
-}
-
-/**
- * Sets the image that the receiver will use to paint the caret
- * to the image specified by the argument, or to the default
- * which is a filled rectangle if the argument is null
- *
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- boolean isFocus = isFocusCaret ();
- if (isFocus && isVisible) hideCaret ();
- this.image = image;
- if (isFocus && isVisible) showCaret ();
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget();
- setBounds (x, y, width, height);
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the argument which is relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param location the new location for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (Point location) {
- checkWidget();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-/**
- * Sets the receiver's size to the point specified by the arguments.
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (int width, int height) {
- checkWidget();
- setBounds (x, y, width, height);
-}
-
-/**
- * Sets the receiver's size to the point specified by the argument.
- *
- * @param size the new extent for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (Point size) {
- checkWidget();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSize (size.x, size.y);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget();
- if (visible == isVisible) return;
- isVisible = visible;
- if (!isFocusCaret ()) return;
- if (isVisible) {
- showCaret ();
- } else {
- hideCaret ();
- }
-}
-
-boolean showCaret () {
- if (isShowing) return true;
- isShowing = true;
- return drawCaret ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java
deleted file mode 100644
index 257f07af33..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class allow the user to select a color
- * from a predefined set of available colors.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ColorDialog extends Dialog {
- RGB rgb;
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a composite control which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ColorDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ColorDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-/**
- * Returns the currently selected color in the receiver.
- *
- * @return the RGB value for the selected color, may be null
- *
- * @see PaletteData#getRGBs
- */
-public RGB getRGB () {
- return rgb;
-}
-/**
- * Makes the receiver visible and brings it to the front
- * of the display.
- *
- * @return the selected color, or null if the dialog was
- * cancelled, no color was selected, or an error
- * occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public RGB open () {
- byte [] buffer = Converter.wcsToMbcs (null, title, true);
- int /*long*/ handle = OS.gtk_color_selection_dialog_new (buffer);
- Display display = parent != null ? parent.getDisplay (): Display.getCurrent ();
- if (parent != null) {
- int /*long*/ shellHandle = parent.topHandle ();
- OS.gtk_window_set_transient_for (handle, shellHandle);
- int /*long*/ pixbufs = OS.gtk_window_get_icon_list (shellHandle);
- if (pixbufs != 0) {
- OS.gtk_window_set_icon_list (handle, pixbufs);
- OS.g_list_free (pixbufs);
- }
- }
- OS.gtk_window_set_modal (handle, true);
- GtkColorSelectionDialog dialog = new GtkColorSelectionDialog ();
- OS.memmove (dialog, handle);
- GdkColor color = new GdkColor();
- if (rgb != null) {
- color.red = (short)((rgb.red & 0xFF) | ((rgb.red & 0xFF) << 8));
- color.green = (short)((rgb.green & 0xFF) | ((rgb.green & 0xFF) << 8));
- color.blue = (short)((rgb.blue & 0xFF) | ((rgb.blue & 0xFF) << 8));
- OS.gtk_color_selection_set_current_color (dialog.colorsel, color);
- }
- OS.gtk_color_selection_set_has_palette (dialog.colorsel, true);
- display.addIdleProc ();
- Dialog oldModal = null;
- if (OS.gtk_window_get_modal (handle)) {
- oldModal = display.getModalDialog ();
- display.setModalDialog (this);
- }
- int signalId = 0;
- int /*long*/ hookId = 0;
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- signalId = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET());
- hookId = OS.g_signal_add_emission_hook (signalId, 0, display.emissionProc, handle, 0);
- }
- int response = OS.gtk_dialog_run (handle);
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- OS.g_signal_remove_emission_hook (signalId, hookId);
- }
- if (OS.gtk_window_get_modal (handle)) {
- display.setModalDialog (oldModal);
- }
- boolean success = response == OS.GTK_RESPONSE_OK;
- if (success) {
- OS.gtk_color_selection_get_current_color (dialog.colorsel, color);
- int red = (color.red >> 8) & 0xFF;
- int green = (color.green >> 8) & 0xFF;
- int blue = (color.blue >> 8) & 0xFF;
- rgb = new RGB (red, green, blue);
- }
- display.removeIdleProc ();
- OS.gtk_widget_destroy (handle);
- if (!success) return null;
- return rgb;
-}
-/**
- * Sets the receiver's selected color to be the argument.
- *
- * @param rgb the new RGB value for the selected color, may be
- * null to let the platform select a default when
- * open() is called
- * @see PaletteData#getRGBs
- */
-public void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java
deleted file mode 100644
index 6e526d3b05..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java
+++ /dev/null
@@ -1,2241 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are controls that allow the user
- * to choose an item from a list of items, or optionally
- * enter a new value by typing it into an editable text
- * field. Often, <code>Combo</code>s are used in the same place
- * where a single selection <code>List</code> widget could
- * be used but space is limited. A <code>Combo</code> takes
- * less space than a <code>List</code> widget and shows
- * similar information.
- * <p>
- * Note: Since <code>Combo</code>s can contain both a list
- * and an editable text field, it is possible to confuse methods
- * which access one versus the other (compare for example,
- * <code>clearSelection()</code> and <code>deselectAll()</code>).
- * The API documentation is careful to indicate either "the
- * receiver's list" or the "the receiver's text field" to
- * distinguish between the two cases.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>DROP_DOWN, READ_ONLY, SIMPLE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Modify, Selection, Verify</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles DROP_DOWN and SIMPLE may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see List
- * @see <a href="http://www.eclipse.org/swt/snippets/#combo">Combo snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Combo extends Composite {
- int /*long*/ buttonHandle, entryHandle, listHandle, textRenderer, cellHandle, popupHandle;
- int lastEventTime, visibleCount = 5;
- int /*long*/ gdkEventKey = 0;
- int fixStart = -1, fixEnd = -1;
- String [] items = new String [0];
- boolean ignoreSelect, lockText;
-
- /**
- * the operating system limit for the number of characters
- * that the text field in an instance of this class can hold
- */
- public final static int LIMIT;
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0xFFFF;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see SWT#READ_ONLY
- * @see SWT#SIMPLE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Combo (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the argument to the end of the receiver's list.
- *
- * @param string the new item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String,int)
- */
-public void add (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- add (string, items.length);
-}
-
-/**
- * Adds the argument to the receiver's list at the given
- * zero-relative index.
- * <p>
- * Note: To add an item at the end of the list, use the
- * result of calling <code>getItemCount()</code> as the
- * index or use <code>add(String)</code>.
- * </p>
- *
- * @param string the new item
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String)
- */
-public void add (String string, int index) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (!(0 <= index && index <= items.length)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- String [] newItems = new String [items.length + 1];
- System.arraycopy (items, 0, newItems, 0, index);
- newItems [index] = string;
- System.arraycopy (items, index, newItems, index + 1, items.length - index);
- items = newItems;
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- OS.gtk_combo_box_insert_text (handle, index, buffer);
- if ((style & SWT.RIGHT_TO_LEFT) != 0 && popupHandle != 0) {
- OS.gtk_container_forall (popupHandle, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL);
- }
- } else {
- /*
- * Feature in GTK. When the list is empty and the first item
- * is added, the combo box selects that item replacing the
- * text in the entry field. The fix is to avoid this by
- * stopping the "delete" and "insert_text" signal emission.
- */
- ignoreSelect = lockText = true;
- int /*long*/ item = OS.gtk_list_item_new_with_label (buffer);
- int /*long*/ label = OS.gtk_bin_get_child (item);
- setForegroundColor (label, getForegroundColor ());
- OS.gtk_widget_modify_font (label, getFontDescription ());
- OS.gtk_widget_set_direction (label, OS.gtk_widget_get_direction (handle));
- OS.gtk_widget_show (item);
- int /*long*/ items = OS.g_list_append (0, item);
- OS.gtk_list_insert_items (listHandle, items, index);
- ignoreSelect = lockText = false;
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the combo's list selection.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed the combo's text area.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- *
- * @since 3.1
- */
-public void addVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-
-static int checkStyle (int style) {
- /*
- * Feature in Windows. It is not possible to create
- * a combo box that has a border using Windows style
- * bits. All combo boxes draw their own border and
- * do not use the standard Windows border styles.
- * Therefore, no matter what style bits are specified,
- * clear the BORDER bits so that the SWT style will
- * match the Windows widget.
- *
- * The Windows behavior is currently implemented on
- * all platforms.
- */
- style &= ~SWT.BORDER;
-
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- style &= ~(SWT.H_SCROLL | SWT.V_SCROLL);
- style = checkBits (style, SWT.DROP_DOWN, SWT.SIMPLE, 0, 0, 0, 0);
- if ((style & SWT.SIMPLE) != 0) return style & ~SWT.READ_ONLY;
- return style;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Sets the selection in the receiver's text field to an empty
- * selection starting just before the first character. If the
- * text field is editable, this has the effect of placing the
- * i-beam at the start of the text.
- * <p>
- * Note: To clear the selected items in the receiver's list,
- * use <code>deselectAll()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #deselectAll
- */
-public void clearSelection () {
- checkWidget();
- if (entryHandle != 0) {
- int position = OS.gtk_editable_get_position (entryHandle);
- OS.gtk_editable_select_region (entryHandle, position, position);
- }
-}
-
-void clearText () {
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- if ((style & SWT.READ_ONLY) != 0) {
- int index = OS.gtk_combo_box_get_active (handle);
- if (index != -1) {
- int /*long*/ modelHandle = OS.gtk_combo_box_get_model (handle);
- int /*long*/ [] ptr = new int /*long*/ [1];
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- OS.gtk_tree_model_get (modelHandle, iter, 0, ptr, -1);
- OS.g_free (iter);
- if (ptr [0] != 0 && OS.strlen (ptr [0]) > 0) postEvent (SWT.Modify);
- OS.g_free (ptr [0]);
- }
- } else {
- OS.gtk_entry_set_text (entryHandle, new byte[1]);
- }
- OS.gtk_combo_box_set_active (handle, -1);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- }
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- return computeNativeSize (handle, wHint, hHint, changed);
- }
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- int[] w = new int [1], h = new int [1];
- OS.gtk_widget_realize (entryHandle);
- int /*long*/ layout = OS.gtk_entry_get_layout (entryHandle);
- OS.pango_layout_get_size (layout, w, h);
- int xborder = Display.INNER_BORDER, yborder = Display.INNER_BORDER;
- int /*long*/ style = OS.gtk_widget_get_style (entryHandle);
- xborder += OS.gtk_style_get_xthickness (style);
- yborder += OS.gtk_style_get_ythickness (style);
- int [] property = new int [1];
- OS.gtk_widget_style_get (entryHandle, OS.interior_focus, property, 0);
- if (property [0] == 0) {
- OS.gtk_widget_style_get (entryHandle, OS.focus_line_width, property, 0);
- xborder += property [0];
- yborder += property [0];
- }
- int width = OS.PANGO_PIXELS (w [0]) + xborder * 2;
- int height = OS.PANGO_PIXELS (h [0]) + yborder * 2;
-
- GtkRequisition arrowRequesition = new GtkRequisition ();
- OS.gtk_widget_size_request (buttonHandle, arrowRequesition);
- GtkRequisition listRequesition = new GtkRequisition ();
- int /*long*/ listParent = OS.gtk_widget_get_parent (listHandle);
- OS.gtk_widget_size_request (listParent != 0 ? listParent : listHandle, listRequesition);
-
- width = Math.max (listRequesition.width, width) + arrowRequesition.width + 4;
- width = wHint == SWT.DEFAULT ? width : wHint;
- height = hHint == SWT.DEFAULT ? height : hHint;
- return new Point (width, height);
-}
-
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void copy () {
- checkWidget ();
- if (entryHandle != 0) OS.gtk_editable_copy_clipboard (entryHandle);
-}
-
-void createHandle (int index) {
- state |= HANDLE | MENU;
- fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (fixedHandle, true);
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- int /*long*/ oldList = OS.gtk_window_list_toplevels ();
- if ((style & SWT.READ_ONLY) != 0) {
- handle = OS.gtk_combo_box_new_text ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- cellHandle = OS.gtk_bin_get_child (handle);
- if (cellHandle == 0) error (SWT.ERROR_NO_HANDLES);
- } else {
- handle = OS.gtk_combo_box_entry_new_text ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- entryHandle = OS.gtk_bin_get_child (handle);
- if (entryHandle == 0) error (SWT.ERROR_NO_HANDLES);
- }
- popupHandle = findPopupHandle (oldList);
- OS.gtk_container_add (fixedHandle, handle);
- textRenderer = OS.gtk_cell_renderer_text_new ();
- if (textRenderer == 0) error (SWT.ERROR_NO_HANDLES);
- /*
- * Feature in GTK. In order to make a read only combo box the same
- * height as an editable combo box the ypad must be set to 0. In
- * versions 2.4.x of GTK, a pad of 0 will clip some letters. The
- * fix is to set the pad to 1.
- */
- int pad = 0;
- if (OS.GTK_VERSION < OS.VERSION(2, 6, 0)) pad = 1;
- OS.g_object_set (textRenderer, OS.ypad, pad, 0);
- /*
- * Feature in GTK. In version 2.4.9 of GTK, a warning is issued
- * when a call to gtk_cell_layout_clear() is made. The fix is to hide
- * the warning.
- */
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.gtk_cell_layout_clear (handle);
- display.setWarnings (warnings);
- OS.gtk_cell_layout_pack_start (handle, textRenderer, true);
- OS.gtk_cell_layout_set_attributes (handle, textRenderer, OS.text, 0, 0);
-
- /*
- * Feature in GTK. There is no API to query the button
- * handle from a combo box although it is possible to get the
- * text field. The button handle is needed to hook events. The
- * fix is to walk the combo tree and find the first child that is
- * an instance of button.
- */
- OS.gtk_container_forall (handle, display.allChildrenProc, 0);
- if (display.allChildren != 0) {
- int /*long*/ list = display.allChildren;
- while (list != 0) {
- int /*long*/ widget = OS.g_list_data (list);
- if (OS.GTK_IS_BUTTON (widget)) {
- buttonHandle = widget;
- break;
- }
- list = OS.g_list_next (list);
- }
- OS.g_list_free (display.allChildren);
- display.allChildren = 0;
- }
- /*
- * Feature in GTK. By default, read only combo boxes
- * process the RETURN key rather than allowing the
- * default button to process the key. The fix is to
- * clear the GTK_RECEIVES_DEFAULT flag.
- */
- if ((style & SWT.READ_ONLY) != 0 && buttonHandle != 0) {
- OS.GTK_WIDGET_UNSET_FLAGS (buttonHandle, OS.GTK_RECEIVES_DEFAULT);
- }
- } else {
- handle = OS.gtk_combo_new ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (fixedHandle, handle);
- GtkCombo combo = new GtkCombo ();
- OS.memmove (combo, handle);
- entryHandle = combo.entry;
- listHandle = combo.list;
-
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- int /*long*/ parentHandle = 0;
- int /*long*/ temp = listHandle;
- while ((temp = OS.gtk_widget_get_parent(temp)) != 0) {
- parentHandle = temp;
- }
- popupHandle = parentHandle;
- if (popupHandle != 0) {
- int /*long*/ modalGroup = getShell().modalGroup;
- if (modalGroup != 0) {
- OS.gtk_window_group_add_window (modalGroup, popupHandle);
- }
- }
- }
- /*
- * Feature in GTK. There is no API to query the arrow
- * handle from a combo box although it is possible to
- * get the list and text field. The arrow handle is needed
- * to hook events. The fix is to find the first child that is
- * not the entry or list and assume this is the arrow handle.
- */
- int /*long*/ list = OS.gtk_container_get_children (handle);
- if (list != 0) {
- int i = 0, count = OS.g_list_length (list);
- while (i<count) {
- int /*long*/ childHandle = OS.g_list_nth_data (list, i);
- if (childHandle != entryHandle && childHandle != listHandle) {
- buttonHandle = childHandle;
- break;
- }
- i++;
- }
- OS.g_list_free (list);
- }
-
- boolean editable = (style & SWT.READ_ONLY) == 0;
- OS.gtk_editable_set_editable (entryHandle, editable);
- OS.gtk_combo_disable_activate (handle);
- OS.gtk_combo_set_case_sensitive (handle, true);
- }
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void cut () {
- checkWidget ();
- if (entryHandle != 0) OS.gtk_editable_cut_clipboard (entryHandle);
-}
-
-void deregister () {
- super.deregister ();
- if (buttonHandle != 0) display.removeWidget (buttonHandle);
- if (entryHandle != 0) display.removeWidget (entryHandle);
- if (listHandle != 0) display.removeWidget (listHandle);
- int /*long*/ imContext = imContext ();
- if (imContext != 0) display.removeWidget (imContext);
-}
-
-boolean filterKey (int keyval, int /*long*/ event) {
- int time = OS.gdk_event_get_time (event);
- if (time != lastEventTime) {
- lastEventTime = time;
- int /*long*/ imContext = imContext ();
- if (imContext != 0) {
- return OS.gtk_im_context_filter_keypress (imContext, event);
- }
- }
- gdkEventKey = event;
- return false;
-}
-
-int /*long*/ findPopupHandle (int /*long*/ oldList) {
- int /*long*/ hdl = 0;
- int /*long*/ currentList = OS.gtk_window_list_toplevels();
- int /*long*/ oldFromList = oldList;
- int /*long*/ newFromList = currentList;
- boolean isFound;
- while (newFromList != 0) {
- int /*long*/ newToplevel = OS.g_list_data(newFromList);
- isFound = false;
- oldFromList = oldList;
- while (oldFromList != 0) {
- int /*long*/ oldToplevel = OS.g_list_data(oldFromList);
- if (newToplevel == oldToplevel) {
- isFound = true;
- break;
- }
- oldFromList = OS.g_list_next(oldFromList);
- }
- if (!isFound) {
- hdl = newToplevel;
- break;
- }
- newFromList = OS.g_list_next(newFromList);
- }
- OS.g_list_free(oldList);
- OS.g_list_free(currentList);
- return hdl;
-}
-
-void fixModal (int /*long*/ group, int /*long*/ modalGroup) {
- if (popupHandle != 0) {
- if (group != 0) {
- OS.gtk_window_group_add_window (group, popupHandle);
- } else {
- if (modalGroup != 0) {
- OS.gtk_window_group_remove_window (modalGroup, popupHandle);
- }
- }
- }
-}
-
-void fixIM () {
- /*
- * The IM filter has to be called one time for each key press event.
- * When the IM is open the key events are duplicated. The first event
- * is filtered by SWT and the second event is filtered by GTK. In some
- * cases the GTK handler does not run (the widget is destroyed, the
- * application code consumes the event, etc), for these cases the IM
- * filter has to be called by SWT.
- */
- if (gdkEventKey != 0 && gdkEventKey != -1) {
- int /*long*/ imContext = imContext ();
- if (imContext != 0) {
- OS.gtk_im_context_filter_keypress (imContext, gdkEventKey);
- gdkEventKey = -1;
- return;
- }
- }
- gdkEventKey = 0;
-}
-
-int /*long*/ fontHandle () {
- if (entryHandle != 0) return entryHandle;
- return super.fontHandle ();
-}
-
-int /*long*/ focusHandle () {
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if ((style & SWT.READ_ONLY) != 0 && buttonHandle != 0) return buttonHandle;
- }
- if (entryHandle != 0) return entryHandle;
- return super.focusHandle ();
-}
-
-boolean hasFocus () {
- if (super.hasFocus ()) return true;
- if (entryHandle != 0 && OS.GTK_WIDGET_HAS_FOCUS (entryHandle)) return true;
- if (listHandle != 0 && OS.GTK_WIDGET_HAS_FOCUS (listHandle)) return true;
- return false;
-}
-
-void hookEvents () {
- super.hookEvents ();
- if (OS.GTK_VERSION >= OS.VERSION(2, 4, 0)) {
- OS.g_signal_connect_closure (handle, OS.changed, display.closures [CHANGED], true);
- }
-
- if (entryHandle != 0) {
- OS.g_signal_connect_closure (entryHandle, OS.changed, display.closures [CHANGED], true);
- OS.g_signal_connect_closure (entryHandle, OS.insert_text, display.closures [INSERT_TEXT], false);
- OS.g_signal_connect_closure (entryHandle, OS.delete_text, display.closures [DELETE_TEXT], false);
- OS.g_signal_connect_closure (entryHandle, OS.activate, display.closures [ACTIVATE], false);
- OS.g_signal_connect_closure (entryHandle, OS.populate_popup, display.closures [POPULATE_POPUP], false);
- }
- int eventMask = OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_PRESS_MASK |
- OS.GDK_BUTTON_RELEASE_MASK;
- int /*long*/ [] handles = new int /*long*/ [] {buttonHandle, entryHandle, listHandle};
- for (int i=0; i<handles.length; i++) {
- int /*long*/ eventHandle = handles [i];
- if (eventHandle != 0) {
- /* Connect the mouse signals */
- OS.gtk_widget_add_events (eventHandle, eventMask);
- OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false);
- OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT], false);
- OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [MOTION_NOTIFY_EVENT], 0, display.closures [MOTION_NOTIFY_EVENT], false);
- /*
- * Feature in GTK. Events such as mouse move are propagated up
- * the widget hierarchy and are seen by the parent. This is the
- * correct GTK behavior but not correct for SWT. The fix is to
- * hook a signal after and stop the propagation using a negative
- * event number to distinguish this case.
- */
- OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT_INVERSE], true);
- OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT_INVERSE], true);
- OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [MOTION_NOTIFY_EVENT], 0, display.closures [MOTION_NOTIFY_EVENT_INVERSE], true);
-
- /* Connect the event_after signal for both key and mouse */
- if (eventHandle != focusHandle ()) {
- OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [EVENT_AFTER], 0, display.closures [EVENT_AFTER], false);
- }
- }
- }
- int /*long*/ imContext = imContext ();
- if (imContext != 0) {
- OS.g_signal_connect_closure (imContext, OS.commit, display.closures [COMMIT], false);
- int id = OS.g_signal_lookup (OS.commit, OS.gtk_im_context_get_type ());
- int blockMask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID;
- OS.g_signal_handlers_block_matched (imContext, blockMask, id, 0, 0, 0, entryHandle);
- }
-}
-
-int /*long*/ imContext () {
- return entryHandle != 0 ? OS.GTK_ENTRY_IM_CONTEXT (entryHandle) : 0;
-}
-
-/**
- * Deselects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget();
- if (index < 0 || index >= items.length) return;
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if (OS.gtk_combo_box_get_active (handle) == index) {
- clearText ();
- }
- } else {
- ignoreSelect = true;
- int /*long*/ children = OS.gtk_container_get_children (listHandle);
- int /*long*/ item = OS.g_list_nth_data (children, index);
- boolean selected = OS.GTK_WIDGET_STATE (item) == OS.GTK_STATE_SELECTED;
- if (selected) {
- OS.gtk_list_unselect_all (listHandle);
- OS.gtk_entry_set_text (entryHandle, new byte[1]);
- }
- OS.g_list_free (children);
- ignoreSelect = false;
- }
-}
-
-/**
- * Deselects all selected items in the receiver's list.
- * <p>
- * Note: To clear the selection in the receiver's text field,
- * use <code>clearSelection()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #clearSelection
- */
-public void deselectAll () {
- checkWidget();
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- clearText ();
- } else {
- ignoreSelect = true;
- OS.gtk_list_unselect_all (listHandle);
- OS.gtk_entry_set_text (entryHandle, new byte[1]);
- ignoreSelect = false;
- }
-}
-
-boolean dragDetect(int x, int y, boolean filter, boolean[] consume) {
- if (filter && entryHandle != 0) {
- int [] index = new int [1];
- int [] trailing = new int [1];
- int /*long*/ layout = OS.gtk_entry_get_layout (entryHandle);
- OS.pango_layout_xy_to_index (layout, x * OS.PANGO_SCALE, y * OS.PANGO_SCALE, index, trailing);
- int /*long*/ ptr = OS.pango_layout_get_text (layout);
- int position = (int)/*64*/OS.g_utf8_pointer_to_offset (ptr, ptr + index[0]) + trailing[0];
- Point selection = getSelection ();
- if (selection.x <= position && position < selection.y) {
- if (super.dragDetect (x, y, filter, consume)) {
- if (consume != null) consume [0] = true;
- return true;
- }
- }
- return false;
- }
- return super.dragDetect (x, y, filter, consume);
-}
-
-int /*long*/ enterExitHandle () {
- return fixedHandle;
-}
-
-int /*long*/ eventWindow () {
- return paintWindow ();
-}
-
-GdkColor getBackgroundColor () {
- return getBaseColor ();
-}
-
-GdkColor getForegroundColor () {
- return getTextColor ();
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver's list. Throws an exception if the index is out
- * of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getItem (int index) {
- checkWidget();
- if (!(0 <= index && index < items.length)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- return items [index];
-}
-
-/**
- * Returns the number of items contained in the receiver's list.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- return items.length;
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the receiver's list.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget();
- return fontHeight (getFontDescription (), listHandle != 0 ? listHandle : handle);
-}
-
-/**
- * Returns a (possibly empty) array of <code>String</code>s which are
- * the items in the receiver's list.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver's list
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getItems () {
- checkWidget();
- String [] result = new String [items.length];
- System.arraycopy (items, 0, result, 0, items.length);
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver's list is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's list's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getListVisible () {
- checkWidget ();
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- return popupHandle != 0 && OS.GTK_WIDGET_VISIBLE (popupHandle);
- }
- return false;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the orientation of the receiver.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getOrientation () {
- checkWidget();
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-/**
- * Returns a <code>Point</code> whose x coordinate is the
- * character position representing the start of the selection
- * in the receiver's text field, and whose y coordinate is the
- * character position representing the end of the selection.
- * An "empty" selection is indicated by the x and y coordinates
- * having the same value.
- * <p>
- * Indexing is zero based. The range of a selection is from
- * 0..N where N is the number of characters in the widget.
- * </p>
- *
- * @return a point representing the selection start and end
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSelection () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) {
- int length = 0;
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- int index = OS.gtk_combo_box_get_active (handle);
- if (index != -1) length = getItem (index).length ();
- } else {
- int /*long*/ str = OS.gtk_entry_get_text (entryHandle);
- if (str != 0) length = (int)/*64*/OS.g_utf8_strlen (str, -1);
- }
- return new Point (0, length);
- }
- int [] start = new int [1];
- int [] end = new int [1];
- if (entryHandle != 0) {
- OS.gtk_editable_get_selection_bounds (entryHandle, start, end);
- }
- return new Point(start [0], end [0]);
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver's list, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget();
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- return OS.gtk_combo_box_get_active (handle);
- }
- int index = 0, result = -1;
- int /*long*/ children = OS.gtk_container_get_children (listHandle);
- int /*long*/ temp = children;
- while (temp != 0) {
- int /*long*/ item = OS.g_list_data (temp);
- if (OS.GTK_WIDGET_STATE (item) == OS.GTK_STATE_SELECTED) {
- result = index;
- break;
- }
- index++;
- temp = OS.g_list_next (temp);
- }
- OS.g_list_free (children);
- return result;
-}
-
-/**
- * Returns a string containing a copy of the contents of the
- * receiver's text field, or an empty string if there are no
- * contents.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- if (entryHandle != 0) {
- int /*long*/ str = OS.gtk_entry_get_text (entryHandle);
- if (str == 0) return "";
- int length = OS.strlen (str);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, str, length);
- return new String (Converter.mbcsToWcs (null, buffer));
- } else {
- int index = OS.gtk_combo_box_get_active (handle);
- return index != -1 ? getItem (index) : "";
- }
-}
-
-String getText (int start, int stop) {
- /*
- * NOTE: The current implementation uses substring ()
- * which can reference a potentially large character
- * array.
- */
- return getText ().substring (start, stop - 1);
-}
-
-/**
- * Returns the height of the receivers's text field.
- *
- * @return the text height
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTextHeight () {
- checkWidget();
- GtkRequisition requisition = new GtkRequisition ();
- gtk_widget_size_request (handle, requisition);
- return OS.GTK_WIDGET_REQUISITION_HEIGHT (handle);
-}
-
-/**
- * Returns the maximum number of characters that the receiver's
- * text field is capable of holding. If this has not been changed
- * by <code>setTextLimit()</code>, it will be the constant
- * <code>Combo.LIMIT</code>.
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public int getTextLimit () {
- checkWidget();
- int limit = entryHandle != 0 ? OS.gtk_entry_get_max_length (entryHandle) : 0;
- return limit == 0 ? LIMIT : limit;
-}
-
-/**
- * Gets the number of items that are visible in the drop
- * down portion of the receiver's list.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @return the number of items that are visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public int getVisibleItemCount () {
- checkWidget ();
- return visibleCount;
-}
-
-int /*long*/ gtk_activate (int /*long*/ widget) {
- postEvent (SWT.DefaultSelection);
- return 0;
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) {
- /*
- * Feature in GTK. Depending on where the user clicks, GTK prevents
- * the left mouse button event from being propagated. The fix is to
- * send the mouse event from the event_after handler.
- */
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
- if (gdkEvent.type == OS.GDK_BUTTON_PRESS && gdkEvent.button == 1 && (style & SWT.READ_ONLY) != 0) {
- return gtk_button_press_event(widget, event, false);
- }
- }
- return super.gtk_button_press_event (widget, event);
-}
-
-int /*long*/ gtk_changed (int /*long*/ widget) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if (widget == handle) {
- if (entryHandle == 0) {
- sendEvent(SWT.Modify);
- if (isDisposed ()) return 0;
- }
- /*
- * Feature in GTK. GTK emits a changed signal whenever
- * the contents of a combo box are altered by typing or
- * by selecting an item in the list, but the event should
- * only be sent when the list is selected. The fix is to
- * only send out a selection event when there is a selected
- * item.
- *
- * NOTE: This code relies on GTK clearing the selected
- * item and not matching the item as the user types.
- */
- int index = OS.gtk_combo_box_get_active (handle);
- if (index != -1) postEvent (SWT.Selection);
- return 0;
- }
- } else {
- if (!ignoreSelect) {
- int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle);
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, length);
- String text = new String (Converter.mbcsToWcs (null, buffer));
- for (int i = 0; i < items.length; i++) {
- if (items [i].equals (text)) {
- postEvent (SWT.Selection);
- break;
- }
- }
- }
- }
- /*
- * Feature in GTK. When the user types, GTK positions
- * the caret after sending the changed signal. This
- * means that application code that attempts to position
- * the caret during a changed signal will fail. The fix
- * is to post the modify event when the user is typing.
- */
- boolean keyPress = false;
- int /*long*/ eventPtr = OS.gtk_get_current_event ();
- if (eventPtr != 0) {
- GdkEventKey gdkEvent = new GdkEventKey ();
- OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof);
- switch (gdkEvent.type) {
- case OS.GDK_KEY_PRESS:
- keyPress = true;
- break;
- }
- OS.gdk_event_free (eventPtr);
- }
- if (keyPress) {
- postEvent (SWT.Modify);
- } else {
- sendEvent (SWT.Modify);
- }
- return 0;
-}
-
-int /*long*/ gtk_commit (int /*long*/ imContext, int /*long*/ text) {
- if (text == 0) return 0;
- if (!OS.gtk_editable_get_editable (entryHandle)) return 0;
- int length = OS.strlen (text);
- if (length == 0) return 0;
- byte [] buffer = new byte [length];
- OS.memmove (buffer, text, length);
- char [] chars = Converter.mbcsToWcs (null, buffer);
- char [] newChars = sendIMKeyEvent (SWT.KeyDown, null, chars);
- if (newChars == null) return 0;
- /*
- * Feature in GTK. For a GtkEntry, during the insert-text signal,
- * GTK allows the programmer to change only the caret location,
- * not the selection. If the programmer changes the selection,
- * the new selection is lost. The fix is to detect a selection
- * change and set it after the insert-text signal has completed.
- */
- fixStart = fixEnd = -1;
- OS.g_signal_handlers_block_matched (imContext, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, COMMIT);
- int id = OS.g_signal_lookup (OS.commit, OS.gtk_im_context_get_type ());
- int mask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID;
- OS.g_signal_handlers_unblock_matched (imContext, mask, id, 0, 0, 0, entryHandle);
- if (newChars == chars) {
- OS.g_signal_emit_by_name (imContext, OS.commit, text);
- } else {
- buffer = Converter.wcsToMbcs (null, newChars, true);
- OS.g_signal_emit_by_name (imContext, OS.commit, buffer);
- }
- OS.g_signal_handlers_unblock_matched (imContext, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, COMMIT);
- OS.g_signal_handlers_block_matched (imContext, mask, id, 0, 0, 0, entryHandle);
- if (fixStart != -1 && fixEnd != -1) {
- OS.gtk_editable_set_position (entryHandle, fixStart);
- OS.gtk_editable_select_region (entryHandle, fixStart, fixEnd);
- }
- fixStart = fixEnd = -1;
- return 0;
-}
-
-int /*long*/ gtk_delete_text (int /*long*/ widget, int /*long*/ start_pos, int /*long*/ end_pos) {
- if (lockText) {
- OS.gtk_list_unselect_item (listHandle, 0);
- OS.g_signal_stop_emission_by_name (entryHandle, OS.delete_text);
- return 0;
- }
- if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0;
- String newText = verifyText ("", (int)/*64*/start_pos, (int)/*64*/end_pos);
- if (newText == null) {
- OS.g_signal_stop_emission_by_name (entryHandle, OS.delete_text);
- } else {
- if (newText.length () > 0) {
- int [] pos = new int [1];
- pos [0] = (int)/*64*/end_pos;
- byte [] buffer = Converter.wcsToMbcs (null, newText, false);
- OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT);
- OS.gtk_editable_insert_text (entryHandle, buffer, buffer.length, pos);
- OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT);
- OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_editable_set_position (entryHandle, pos [0]);
- }
- }
- return 0;
-}
-
-int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) {
- /*
- * Feature in GTK. Depending on where the user clicks, GTK prevents
- * the left mouse button event from being propagated. The fix is to
- * send the mouse event from the event_after handler.
- *
- * Feature in GTK. When the user clicks anywhere in an editable
- * combo box, a single focus event should be issued, despite the
- * fact that focus might switch between the drop down button and
- * the text field. The fix is to use gtk_combo_box_set_focus_on_click ()
- * to eat all focus events while focus is in the combo box. When the
- * user clicks on the drop down button focus is assigned to the text
- * field.
- */
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- GdkEvent event = new GdkEvent ();
- OS.memmove (event, gdkEvent, GdkEvent.sizeof);
- switch (event.type) {
- case OS.GDK_BUTTON_PRESS: {
- GdkEventButton gdkEventButton = new GdkEventButton ();
- OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof);
- if (gdkEventButton.button == 1) {
- if ((style & SWT.READ_ONLY) != 0 && !sendMouseEvent (SWT.MouseDown, gdkEventButton.button, display.clickCount, 0, false, gdkEventButton.time, gdkEventButton.x_root, gdkEventButton.y_root, false, gdkEventButton.state)) {
- return 1;
- }
- if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) {
- if ((style & SWT.READ_ONLY) == 0 && widget == buttonHandle) {
- OS.gtk_widget_grab_focus (entryHandle);
- }
- }
- }
- break;
- }
- case OS.GDK_FOCUS_CHANGE: {
- if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) {
- if ((style & SWT.READ_ONLY) == 0) {
- GdkEventFocus gdkEventFocus = new GdkEventFocus ();
- OS.memmove (gdkEventFocus, gdkEvent, GdkEventFocus.sizeof);
- if (gdkEventFocus.in != 0) {
- OS.gtk_combo_box_set_focus_on_click (handle, false);
- } else {
- OS.gtk_combo_box_set_focus_on_click (handle, true);
- }
- }
- }
- break;
- }
- }
- }
- return super.gtk_event_after(widget, gdkEvent);
-}
-
-int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) {
- fixIM ();
- return super.gtk_focus_out_event (widget, event);
-}
-
-int /*long*/ gtk_insert_text (int /*long*/ widget, int /*long*/ new_text, int /*long*/ new_text_length, int /*long*/ position) {
- if (lockText) {
- OS.gtk_list_unselect_item (listHandle, 0);
- OS.g_signal_stop_emission_by_name (entryHandle, OS.insert_text);
- return 0;
- }
- if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0;
- if (new_text == 0 || new_text_length == 0) return 0;
- byte [] buffer = new byte [(int)/*64*/new_text_length];
- OS.memmove (buffer, new_text, buffer.length);
- String oldText = new String (Converter.mbcsToWcs (null, buffer));
- int [] pos = new int [1];
- OS.memmove (pos, position, 4);
- if (pos [0] == -1) {
- int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle);
- pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1);
- }
- String newText = verifyText (oldText, pos [0], pos [0]);
- if (newText != oldText) {
- int [] newStart = new int [1], newEnd = new int [1];
- OS.gtk_editable_get_selection_bounds (entryHandle, newStart, newEnd);
- if (newText != null) {
- if (newStart [0] != newEnd [0]) {
- OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT);
- OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_editable_delete_selection (entryHandle);
- OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT);
- OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- }
- byte [] buffer3 = Converter.wcsToMbcs (null, newText, false);
- OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT);
- OS.gtk_editable_insert_text (entryHandle, buffer3, buffer3.length, pos);
- OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT);
- newStart [0] = newEnd [0] = pos [0];
- }
- pos [0] = newEnd [0];
- if (newStart [0] != newEnd [0]) {
- fixStart = newStart [0];
- fixEnd = newEnd [0];
- }
- OS.memmove (position, pos, 4);
- OS.g_signal_stop_emission_by_name (entryHandle, OS.insert_text);
- }
- return 0;
-}
-
-int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_key_press_event (widget, event);
- if (result != 0) fixIM ();
- if (gdkEventKey == -1) result = 1;
- gdkEventKey = 0;
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0) && (style & SWT.READ_ONLY) == 0) {
- GdkEventKey keyEvent = new GdkEventKey ();
- OS.memmove (keyEvent, event, GdkEventKey.sizeof);
- int oldIndex = OS.gtk_combo_box_get_active (handle);
- int newIndex = oldIndex;
- int key = keyEvent.keyval;
- switch (key) {
- case OS.GDK_Down:
- case OS.GDK_KP_Down:
- if (oldIndex != (items.length - 1)) {
- newIndex = oldIndex + 1;
- }
- break;
- case OS.GDK_Up:
- case OS.GDK_KP_Up:
- if (oldIndex != -1 && oldIndex != 0) {
- newIndex = oldIndex - 1;
- }
- break;
- /*
- * Feature in GTK. In gtk_combo_box, the PageUp and PageDown keys
- * go the first and last items in the list rather than scrolling
- * a page at a time. The fix is to emulate this behavior for
- * gtk_combo_box_entry.
- */
- case OS.GDK_Page_Up:
- case OS.GDK_KP_Page_Up:
- newIndex = 0;
- break;
- case OS.GDK_Page_Down:
- case OS.GDK_KP_Page_Down:
- newIndex = items.length - 1;
- break;
- }
- if (newIndex != oldIndex) {
- OS.gtk_combo_box_set_active (handle, newIndex);
- return 1;
- }
- }
- return result;
-}
-
-int /*long*/ gtk_populate_popup (int /*long*/ widget, int /*long*/ menu) {
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- OS.gtk_widget_set_direction (menu, OS.GTK_TEXT_DIR_RTL);
- OS.gtk_container_forall (menu, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL);
- }
- return 0;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param string the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string) {
- checkWidget();
- return indexOf (string, 0);
-}
-
-/**
- * Searches the receiver's list starting at the given,
- * zero-relative index until an item is found that is equal
- * to the argument, and returns the index of that item. If
- * no item is found or the starting index is out of range,
- * returns -1.
- *
- * @param string the search item
- * @param start the zero-relative index at which to begin the search
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string, int start) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (!(0 <= start && start < items.length)) return -1;
- for (int i=start; i<items.length; i++) {
- if (string.equals(items [i])) return i;
- }
- return -1;
-}
-
-boolean isFocusHandle(int widget) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if (buttonHandle != 0 && widget == buttonHandle) return true;
- if (entryHandle != 0 && widget == entryHandle) return true;
- }
- return super.isFocusHandle (widget);
-}
-
-int /*long*/ paintWindow () {
- int /*long*/ childHandle = entryHandle != 0 ? entryHandle : handle;
- OS.gtk_widget_realize (childHandle);
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (childHandle);
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if ((style & SWT.READ_ONLY) != 0) return window;
- }
- int /*long*/ children = OS.gdk_window_get_children (window);
- if (children != 0) window = OS.g_list_data (children);
- OS.g_list_free (children);
- return window;
-}
-
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void paste () {
- checkWidget ();
- if (entryHandle != 0) OS.gtk_editable_paste_clipboard (entryHandle);
-}
-
-int /*long*/ parentingHandle() {
- return fixedHandle;
-}
-
-void register () {
- super.register ();
- if (buttonHandle != 0) display.addWidget (buttonHandle, this);
- if (entryHandle != 0) display.addWidget (entryHandle, this);
- if (listHandle != 0) display.addWidget (listHandle, this);
- int /*long*/ imContext = imContext ();
- if (imContext != 0) display.addWidget (imContext, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- buttonHandle = entryHandle = listHandle = 0;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- textRenderer = 0;
- fixIM ();
-}
-
-/**
- * Removes the item from the receiver's list at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget();
- if (!(0 <= index && index < items.length)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- String [] oldItems = items;
- String [] newItems = new String [oldItems.length - 1];
- System.arraycopy (oldItems, 0, newItems, 0, index);
- System.arraycopy (oldItems, index + 1, newItems, index, oldItems.length - index - 1);
- items = newItems;
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if (OS.gtk_combo_box_get_active (handle) == index) clearText ();
- OS.gtk_combo_box_remove_text (handle, index);
- } else {
- ignoreSelect = true;
- int /*long*/ children = OS.gtk_container_get_children (listHandle);
- int /*long*/ item = OS.g_list_nth_data (children, index);
- boolean selected = OS.GTK_WIDGET_STATE (item) == OS.GTK_STATE_SELECTED;
- int /*long*/ items = OS.g_list_append (0, item);
- OS.gtk_list_remove_items (listHandle, items);
- OS.g_list_free (items);
- OS.g_list_free (children);
- if (selected) {
- OS.gtk_entry_set_text (entryHandle, new byte[1]);
- }
- ignoreSelect = false;
- }
-}
-
-/**
- * Removes the items from the receiver's list which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget();
- if (start > end) return;
- if (!(0 <= start && start <= end && end < items.length)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- String [] oldItems = items;
- String [] newItems = new String [oldItems.length - (end - start + 1)];
- System.arraycopy (oldItems, 0, newItems, 0, start);
- System.arraycopy (oldItems, end + 1, newItems, start, oldItems.length - end - 1);
- items = newItems;
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- int index = OS.gtk_combo_box_get_active (handle);
- if (start <= index && index <= end) clearText();
- for (int i = end; i >= start; i--) {
- OS.gtk_combo_box_remove_text (handle, i);
- }
- } else {
- boolean selected = false;
- ignoreSelect = true;
- int /*long*/ items = 0;
- int /*long*/ children = OS.gtk_container_get_children (listHandle);
- for (int i = start; i <= end; i++) {
- int /*long*/ item = OS.g_list_nth_data (children, i);
- selected |= OS.GTK_WIDGET_STATE (item) == OS.GTK_STATE_SELECTED;
- items = OS.g_list_append (items, item);
- }
- OS.gtk_list_remove_items (listHandle, items);
- OS.g_list_free (items);
- OS.g_list_free (children);
- if (selected) {
- OS.gtk_entry_set_text (entryHandle, new byte[1]);
- }
- ignoreSelect = false;
- }
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * until an item is found that is equal to the argument,
- * and removes that item from the list.
- *
- * @param string the item to remove
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = indexOf (string, 0);
- if (index == -1) error (SWT.ERROR_INVALID_ARGUMENT);
- remove (index);
-}
-
-/**
- * Removes all of the items from the receiver's list and clear the
- * contents of receiver's text field.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget();
- int count = items.length;
- items = new String[0];
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- clearText ();
- for (int i = count - 1; i >= 0; i--) {
- OS.gtk_combo_box_remove_text (handle, i);
- }
- } else {
- ignoreSelect = true;
- OS.gtk_list_clear_items (listHandle, 0, -1);
- OS.gtk_entry_set_text (entryHandle, new byte[1]);
- ignoreSelect = false;
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- *
- * @since 3.1
- */
-public void removeVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget();
- if (index < 0 || index >= items.length) return;
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_combo_box_set_active (handle, index);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- if ((style & SWT.READ_ONLY) != 0) {
- /*
- * Feature in GTK. Read Only combo boxes do not get a chance to send out a
- * Modify event in the gtk_changed callback. The fix is to send a Modify event
- * here.
- */
- sendEvent (SWT.Modify);
- }
- } else {
- ignoreSelect = true;
- OS.gtk_list_select_item (listHandle, index);
- ignoreSelect = false;
- }
-}
-
-void setBackgroundColor (GdkColor color) {
- super.setBackgroundColor (color);
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if (entryHandle != 0) OS.gtk_widget_modify_base (entryHandle, 0, color);
- OS.g_object_set (textRenderer, OS.background_gdk, color, 0);
- } else {
- OS.gtk_widget_modify_base (entryHandle, 0, color);
- if (listHandle != 0) OS.gtk_widget_modify_base (listHandle, 0, color);
- }
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- int newHeight = height;
- if (resize) newHeight = Math.max (getTextHeight (), height);
- return super.setBounds (x, y, width, newHeight, move, resize);
-}
-
-void setFontDescription (int /*long*/ font) {
- super.setFontDescription (font);
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if (entryHandle != 0) OS.gtk_widget_modify_font (entryHandle, font);
- OS.g_object_set (textRenderer, OS.font_desc, font, 0);
- if ((style & SWT.READ_ONLY) != 0) {
- /*
- * Bug in GTK. Setting the font can leave the combo box with an
- * invalid minimum size. The fix is to temporarily change the
- * selected item to force the combo box to resize.
- */
- int index = OS.gtk_combo_box_get_active (handle);
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_combo_box_set_active (handle, -1);
- OS.gtk_combo_box_set_active (handle, index);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- }
- } else {
- OS.gtk_widget_modify_font (entryHandle, font);
- if (listHandle != 0) {
- OS.gtk_widget_modify_font (listHandle, font);
- int /*long*/ itemsList = OS.gtk_container_get_children (listHandle);
- if (itemsList != 0) {
- int count = OS.g_list_length (itemsList);
- for (int i=count - 1; i>=0; i--) {
- int /*long*/ widget = OS.gtk_bin_get_child (OS.g_list_nth_data (itemsList, i));
- OS.gtk_widget_modify_font (widget, font);
- }
- OS.g_list_free (itemsList);
- }
- }
- }
-}
-
-void setForegroundColor (GdkColor color) {
- super.setForegroundColor (color);
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if (entryHandle != 0) setForegroundColor (entryHandle, color);
- OS.g_object_set (textRenderer, OS.foreground_gdk, color, 0);
- } else {
- setForegroundColor (entryHandle, color);
- if (listHandle != 0) {
- setForegroundColor (listHandle, color);
- int /*long*/ itemsList = OS.gtk_container_get_children (listHandle);
- if (itemsList != 0) {
- int count = OS.g_list_length (itemsList);
- for (int i=count - 1; i>=0; i--) {
- int /*long*/ widget = OS.gtk_bin_get_child (OS.g_list_nth_data (itemsList, i));
- setForegroundColor (widget, color);
- }
- OS.g_list_free (itemsList);
- }
- }
- }
-}
-
-/**
- * Sets the text of the item in the receiver's list at the given
- * zero-relative index to the string argument.
- *
- * @param index the index for the item
- * @param string the new text for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItem (int index, String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (!(0 <= index && index < items.length)) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- items [index] = string;
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- OS.gtk_combo_box_remove_text (handle, index);
- OS.gtk_combo_box_insert_text (handle, index, buffer);
- if ((style & SWT.RIGHT_TO_LEFT) != 0 && popupHandle != 0) {
- OS.gtk_container_forall (popupHandle, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL);
- }
- } else {
- ignoreSelect = true;
- int /*long*/ children = OS.gtk_container_get_children (listHandle);
- int /*long*/ item = OS.g_list_nth_data (children, index);
- int /*long*/ label = OS.gtk_bin_get_child (item);
- OS.gtk_label_set_text (label, buffer);
- OS.g_list_free (children);
- ignoreSelect = false;
- }
-}
-
-/**
- * Sets the receiver's list to be the given array of items.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItems (String [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<items.length; i++) {
- if (items [i] == null) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = this.items.length;
- this.items = new String [items.length];
- System.arraycopy (items, 0, this.items, 0, items.length);
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- clearText ();
- for (int i = count - 1; i >= 0; i--) {
- OS.gtk_combo_box_remove_text (handle, i);
- }
- for (int i = 0; i < items.length; i++) {
- String string = items [i];
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- OS.gtk_combo_box_insert_text (handle, i, buffer);
- if ((style & SWT.RIGHT_TO_LEFT) != 0 && popupHandle != 0) {
- OS.gtk_container_forall (popupHandle, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL);
- }
- }
- } else {
- lockText = ignoreSelect = true;
- OS.gtk_list_clear_items (listHandle, 0, -1);
- int /*long*/ font = getFontDescription ();
- GdkColor color = getForegroundColor ();
- int direction = OS.gtk_widget_get_direction (handle);
- int i = 0;
- while (i < items.length) {
- String string = items [i];
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- int /*long*/ item = OS.gtk_list_item_new_with_label (buffer);
- int /*long*/ label = OS.gtk_bin_get_child (item);
- setForegroundColor (label, color);
- OS.gtk_widget_modify_font (label, font);
- OS.gtk_widget_set_direction (label, direction);
- OS.gtk_container_add (listHandle, item);
- OS.gtk_widget_show (item);
- i++;
- }
- lockText = ignoreSelect = false;
- OS.gtk_entry_set_text (entryHandle, new byte[1]);
- }
-}
-
-/**
- * Marks the receiver's list as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setListVisible (boolean visible) {
- checkWidget ();
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if (visible) {
- OS.gtk_combo_box_popup (handle);
- } else {
- OS.gtk_combo_box_popdown (handle);
- }
- }
-}
-
-void setOrientation() {
- super.setOrientation();
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- if (listHandle != 0) OS.gtk_widget_set_direction (listHandle, OS.GTK_TEXT_DIR_RTL);
- if (entryHandle != 0) OS.gtk_widget_set_direction (entryHandle, OS.GTK_TEXT_DIR_RTL);
- if (cellHandle != 0) OS.gtk_widget_set_direction (cellHandle, OS.GTK_TEXT_DIR_RTL);
- }
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- * <p>
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public void setOrientation (int orientation) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- checkWidget();
- int flags = SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT;
- if ((orientation & flags) == 0 || (orientation & flags) == flags) return;
- style &= ~flags;
- style |= orientation & flags;
- int dir = (orientation & SWT.RIGHT_TO_LEFT) != 0 ? OS.GTK_TEXT_DIR_RTL : OS.GTK_TEXT_DIR_LTR;
- OS.gtk_widget_set_direction (fixedHandle, dir);
- OS.gtk_widget_set_direction (handle, dir);
- if (entryHandle != 0) OS.gtk_widget_set_direction (entryHandle, dir);
- if (listHandle != 0) {
- OS.gtk_widget_set_direction (listHandle, dir);
- int /*long*/ itemsList = OS.gtk_container_get_children (listHandle);
- if (itemsList != 0) {
- int count = OS.g_list_length (itemsList);
- for (int i=count - 1; i>=0; i--) {
- int /*long*/ widget = OS.gtk_bin_get_child (OS.g_list_nth_data (itemsList, i));
- OS.gtk_widget_set_direction (widget, dir);
- }
- OS.g_list_free (itemsList);
- }
- }
- if (cellHandle != 0) OS.gtk_widget_set_direction (cellHandle, dir);
- if (popupHandle != 0) OS.gtk_container_forall (popupHandle, display.setDirectionProc, dir);
- }
-}
-
-/**
- * Sets the selection in the receiver's text field to the
- * range specified by the argument whose x coordinate is the
- * start of the selection and whose y coordinate is the end
- * of the selection.
- *
- * @param selection a point representing the new selection start and end
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (Point selection) {
- checkWidget();
- if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.READ_ONLY) != 0) return;
- if (entryHandle != 0) {
- OS.gtk_editable_set_position (entryHandle, selection.x);
- OS.gtk_editable_select_region (entryHandle, selection.x, selection.y);
- }
-}
-
-/**
- * Sets the contents of the receiver's text field to the
- * given string.
- * <p>
- * This call is ignored when the receiver is read only and
- * the given string is not in the receiver's list.
- * </p>
- * <p>
- * Note: The text field in a <code>Combo</code> is typically
- * only capable of displaying a single line of text. Thus,
- * setting the text to a string containing line breaks or
- * other special characters will probably cause it to
- * display incorrectly.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.READ_ONLY) != 0) {
- int index = indexOf (string);
- if (index == -1) return;
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_combo_box_set_active (handle, index);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- /*
- * Feature in GTK. Read Only combo boxes do not get a chance to send out a
- * Modify event in the gtk_changed callback. The fix is to send a Modify event
- * here.
- */
- sendEvent (SWT.Modify);
- return;
- }
- }
- /*
- * Feature in gtk. When text is set in gtk, separate events are fired for the deletion and
- * insertion of the text. This is not wrong, but is inconsistent with other platforms. The
- * fix is to block the firing of these events and fire them ourselves in a consistent manner.
- */
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle);
- string = verifyText (string, 0, (int)/*64*/OS.g_utf8_strlen (ptr, -1));
- if (string == null) return;
- }
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- }
- OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT);
- OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT);
- OS.gtk_entry_set_text (entryHandle, buffer);
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- }
- OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT);
- OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT);
- sendEvent (SWT.Modify);
-}
-
-/**
- * Sets the maximum number of characters that the receiver's
- * text field is capable of holding to be the argument.
- * <p>
- * To reset this value to the default, use <code>setTextLimit(Combo.LIMIT)</code>.
- * Specifying a limit value larger than <code>Combo.LIMIT</code> sets the
- * receiver's limit to <code>Combo.LIMIT</code>.
- * </p>
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public void setTextLimit (int limit) {
- checkWidget();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- if (entryHandle != 0) OS.gtk_entry_set_max_length (entryHandle, limit);
-}
-
-void setToolTipText (Shell shell, String newString) {
- if (entryHandle != 0) shell.setToolTipText (entryHandle, newString);
- if (buttonHandle != 0) shell.setToolTipText (buttonHandle, newString);
-}
-
-/**
- * Sets the number of items that are visible in the drop
- * down portion of the receiver's list.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param count the new number of items to be visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setVisibleItemCount (int count) {
- checkWidget ();
- if (count < 0) return;
- visibleCount = count;
-}
-
-boolean checkSubwindow () {
- return false;
-}
-
-boolean translateTraversal (GdkEventKey keyEvent) {
- int key = keyEvent.keyval;
- switch (key) {
- case OS.GDK_KP_Enter:
- case OS.GDK_Return: {
- int /*long*/ imContext = imContext ();
- if (imContext != 0) {
- int /*long*/ [] preeditString = new int /*long*/ [1];
- OS.gtk_im_context_get_preedit_string (imContext, preeditString, null, null);
- if (preeditString [0] != 0) {
- int length = OS.strlen (preeditString [0]);
- OS.g_free (preeditString [0]);
- if (length != 0) return false;
- }
- }
- }
- }
- return super.translateTraversal (keyEvent);
-}
-
-String verifyText (String string, int start, int end) {
- if (string.length () == 0 && start == end) return null;
- Event event = new Event ();
- event.text = string;
- event.start = start;
- event.end = end;
- int /*long*/ eventPtr = OS.gtk_get_current_event ();
- if (eventPtr != 0) {
- GdkEventKey gdkEvent = new GdkEventKey ();
- OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof);
- switch (gdkEvent.type) {
- case OS.GDK_KEY_PRESS:
- setKeyState (event, gdkEvent);
- break;
- }
- OS.gdk_event_free (eventPtr);
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the verify
- * event. If this happens, answer null to cancel
- * the operation.
- */
- sendEvent (SWT.Verify, event);
- if (!event.doit || isDisposed ()) return null;
- return event.text;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java
deleted file mode 100644
index 62cda3117c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java
+++ /dev/null
@@ -1,1438 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.cairo.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are controls which are capable
- * of containing other controls.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>NO_BACKGROUND, NO_FOCUS, NO_MERGE_PAINTS, NO_REDRAW_RESIZE, NO_RADIO_GROUP, EMBEDDED, DOUBLE_BUFFERED</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: The <code>NO_BACKGROUND</code>, <code>NO_FOCUS</code>, <code>NO_MERGE_PAINTS</code>,
- * and <code>NO_REDRAW_RESIZE</code> styles are intended for use with <code>Canvas</code>.
- * They can be used with <code>Composite</code> if you are drawing your own, but their
- * behavior is undefined if they are used with subclasses of <code>Composite</code> other
- * than <code>Canvas</code>.
- * </p><p>
- * Note: The <code>CENTER</code> style, although undefined for composites, has the
- * same value as <code>EMBEDDED</code> which is used to embed widgets from other
- * widget toolkits into SWT. On some operating systems (GTK, Motif), this may cause
- * the children of this composite to be obscured.
- * </p><p>
- * This class may be subclassed by custom control implementors
- * who are building controls that are constructed from aggregates
- * of other controls.
- * </p>
- *
- * @see Canvas
- * @see <a href="http://www.eclipse.org/swt/snippets/#composite">Composite snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class Composite extends Scrollable {
- public int /*long*/ embeddedHandle;
- int /*long*/ imHandle, socketHandle;
- Layout layout;
- Control[] tabList;
- int layoutCount, backgroundMode;
-
- static final String NO_INPUT_METHOD = "org.eclipse.swt.internal.gtk.noInputMethod"; //$NON-NLS-1$
-
-Composite () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- *
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_FOCUS
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_RADIO_GROUP
- * @see SWT#EMBEDDED
- * @see SWT#DOUBLE_BUFFERED
- * @see Widget#getStyle
- */
-public Composite (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- style &= ~SWT.TRANSPARENT;
- return style;
-}
-
-Control [] _getChildren () {
- int /*long*/ parentHandle = parentingHandle ();
- int /*long*/ list = OS.gtk_container_get_children (parentHandle);
- if (list == 0) return new Control [0];
- int count = OS.g_list_length (list);
- Control [] children = new Control [count];
- int i = 0;
- int /*long*/ temp = list;
- while (temp != 0) {
- int /*long*/ handle = OS.g_list_data (temp);
- if (handle != 0) {
- Widget widget = display.getWidget (handle);
- if (widget != null && widget != this) {
- if (widget instanceof Control) {
- children [i++] = (Control) widget;
- }
- }
- }
- temp = OS.g_list_next (temp);
- }
- OS.g_list_free (list);
- if (i == count) return children;
- Control [] newChildren = new Control [i];
- System.arraycopy (children, 0, newChildren, 0, i);
- return newChildren;
-}
-
-Control [] _getTabList () {
- if (tabList == null) return tabList;
- int count = 0;
- for (int i=0; i<tabList.length; i++) {
- if (!tabList [i].isDisposed ()) count++;
- }
- if (count == tabList.length) return tabList;
- Control [] newList = new Control [count];
- int index = 0;
- for (int i=0; i<tabList.length; i++) {
- if (!tabList [i].isDisposed ()) {
- newList [index++] = tabList [i];
- }
- }
- tabList = newList;
- return tabList;
-}
-
-/**
- * Clears any data that has been cached by a Layout for all widgets that
- * are in the parent hierarchy of the changed control up to and including the
- * receiver. If an ancestor does not have a layout, it is skipped.
- *
- * @param changed an array of controls that changed state and require a recalculation of size
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li>
- * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void changed (Control[] changed) {
- checkWidget ();
- if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<changed.length; i++) {
- Control control = changed [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean ancestor = false;
- Composite composite = control.parent;
- while (composite != null) {
- ancestor = composite == this;
- if (ancestor) break;
- composite = composite.parent;
- }
- if (!ancestor) error (SWT.ERROR_INVALID_PARENT);
- }
- for (int i=0; i<changed.length; i++) {
- Control child = changed [i];
- Composite composite = child.parent;
- while (child != this) {
- if (composite.layout == null || !composite.layout.flushCache (child)) {
- composite.state |= LAYOUT_CHANGED;
- }
- child = composite;
- composite = child.parent;
- }
- }
-}
-
-void checkBuffered () {
- if ((style & SWT.DOUBLE_BUFFERED) == 0 && (style & SWT.NO_BACKGROUND) != 0) {
- return;
- }
- super.checkBuffered();
-}
-
-protected void checkSubclass () {
- /* Do nothing - Subclassing is allowed */
-}
-
-int /*long*/ childStyle () {
- if (scrolledHandle != 0) return 0;
- return super.childStyle ();
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- Point size;
- if (layout != null) {
- if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
- changed |= (state & LAYOUT_CHANGED) != 0;
- size = layout.computeSize (this, wHint, hHint, changed);
- state &= ~LAYOUT_CHANGED;
- } else {
- size = new Point (wHint, hHint);
- }
- } else {
- size = minimumSize (wHint, hHint, changed);
- }
- if (size.x == 0) size.x = DEFAULT_WIDTH;
- if (size.y == 0) size.y = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) size.x = wHint;
- if (hHint != SWT.DEFAULT) size.y = hHint;
- Rectangle trim = computeTrim (0, 0, size.x, size.y);
- return new Point (trim.width, trim.height);
-}
-
-Widget [] computeTabList () {
- Widget result [] = super.computeTabList ();
- if (result.length == 0) return result;
- Control [] list = tabList != null ? _getTabList () : _getChildren ();
- for (int i=0; i<list.length; i++) {
- Control child = list [i];
- Widget [] childList = child.computeTabList ();
- if (childList.length != 0) {
- Widget [] newResult = new Widget [result.length + childList.length];
- System.arraycopy (result, 0, newResult, 0, result.length);
- System.arraycopy (childList, 0, newResult, result.length, childList.length);
- result = newResult;
- }
- }
- return result;
-}
-
-void createHandle (int index) {
- state |= HANDLE | CANVAS;
- boolean scrolled = (style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0;
- if (!scrolled) state |= THEME_BACKGROUND;
- createHandle (index, true, scrolled || (style & SWT.BORDER) != 0);
-}
-
-void createHandle (int index, boolean fixed, boolean scrolled) {
- if (scrolled) {
- if (fixed) {
- fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (fixedHandle, true);
- }
- int /*long*/ vadj = OS.gtk_adjustment_new (0, 0, 100, 1, 10, 10);
- if (vadj == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ hadj = OS.gtk_adjustment_new (0, 0, 100, 1, 10, 10);
- if (hadj == 0) error (SWT.ERROR_NO_HANDLES);
- scrolledHandle = OS.gtk_scrolled_window_new (hadj, vadj);
- if (scrolledHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- }
- handle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (handle == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (handle, true);
- OS.GTK_WIDGET_SET_FLAGS(handle, OS.GTK_CAN_FOCUS);
- if ((style & SWT.EMBEDDED) == 0) {
- if ((state & CANVAS) != 0) {
- /* Prevent an input method context from being created for the Browser widget */
- if (display.getData (NO_INPUT_METHOD) == null) {
- imHandle = OS.gtk_im_multicontext_new ();
- if (imHandle == 0) error (SWT.ERROR_NO_HANDLES);
- }
- }
- }
- if (scrolled) {
- if (fixed) OS.gtk_container_add (fixedHandle, scrolledHandle);
- /*
- * Force the scrolledWindow to have a single child that is
- * not scrolled automatically. Calling gtk_container_add()
- * seems to add the child correctly but cause a warning.
- */
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.gtk_container_add (scrolledHandle, handle);
- display.setWarnings (warnings);
-
- int hsp = (style & SWT.H_SCROLL) != 0 ? OS.GTK_POLICY_ALWAYS : OS.GTK_POLICY_NEVER;
- int vsp = (style & SWT.V_SCROLL) != 0 ? OS.GTK_POLICY_ALWAYS : OS.GTK_POLICY_NEVER;
- OS.gtk_scrolled_window_set_policy (scrolledHandle, hsp, vsp);
- if (hasBorder ()) {
- OS.gtk_scrolled_window_set_shadow_type (scrolledHandle, OS.GTK_SHADOW_ETCHED_IN);
- }
- }
- if ((style & SWT.EMBEDDED) != 0) {
- socketHandle = OS.gtk_socket_new ();
- if (socketHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (handle, socketHandle);
- }
- if ((style & SWT.NO_REDRAW_RESIZE) != 0 && (style & SWT.RIGHT_TO_LEFT) == 0) {
- OS.gtk_widget_set_redraw_on_allocate (handle, false);
- }
- /*
- * Bug in GTK. When a widget is double buffered and the back
- * pixmap is null, the double buffer pixmap is filled with the
- * background of the widget rather than the current contents of
- * the screen. If nothing is drawn during an expose event,
- * the pixels are altered. The fix is to clear double buffering
- * when NO_BACKGROUND is set and DOUBLE_BUFFERED
- * is not explicitly set.
- */
- if ((style & SWT.DOUBLE_BUFFERED) == 0 && (style & SWT.NO_BACKGROUND) != 0) {
- OS.gtk_widget_set_double_buffered (handle, false);
- }
-}
-
-void deregister () {
- super.deregister ();
- if (socketHandle != 0) display.removeWidget (socketHandle);
-}
-
-void drawBackground (GC gc, int x, int y, int width, int height) {
- Control control = findBackgroundControl ();
- if (control != null) {
- GCData data = gc.getGCData ();
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- Cairo.cairo_save (cairo);
- if (control.backgroundImage != null) {
- Point pt = display.map (this, control, 0, 0);
- Cairo.cairo_translate (cairo, -pt.x, -pt.y);
- x += pt.x;
- y += pt.y;
- int /*long*/ xDisplay = OS.GDK_DISPLAY ();
- int /*long*/ xVisual = OS.gdk_x11_visual_get_xvisual (OS.gdk_visual_get_system());
- int /*long*/ drawable = control.backgroundImage.pixmap;
- int /*long*/ xDrawable = OS.GDK_PIXMAP_XID (drawable);
- int [] w = new int [1], h = new int [1];
- OS.gdk_drawable_get_size (drawable, w, h);
- int /*long*/ surface = Cairo.cairo_xlib_surface_create (xDisplay, xDrawable, xVisual, w [0], h [0]);
- if (surface == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ pattern = Cairo.cairo_pattern_create_for_surface (surface);
- if (pattern == 0) error (SWT.ERROR_NO_HANDLES);
- Cairo.cairo_pattern_set_extend (pattern, Cairo.CAIRO_EXTEND_REPEAT);
- if ((data.style & SWT.MIRRORED) != 0) {
- double[] matrix = {-1, 0, 0, 1, 0, 0};
- Cairo.cairo_pattern_set_matrix(pattern, matrix);
- }
- Cairo.cairo_set_source (cairo, pattern);
- Cairo.cairo_surface_destroy (surface);
- Cairo.cairo_pattern_destroy (pattern);
- } else {
- GdkColor color = control.getBackgroundColor ();
- Cairo.cairo_set_source_rgba (cairo, (color.red & 0xFFFF) / (float)0xFFFF, (color.green & 0xFFFF) / (float)0xFFFF, (color.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF);
- }
- Cairo.cairo_rectangle (cairo, x, y, width, height);
- Cairo.cairo_fill (cairo);
- Cairo.cairo_restore (cairo);
- } else {
- int /*long*/ gdkGC = gc.handle;
- GdkGCValues values = new GdkGCValues ();
- OS.gdk_gc_get_values (gdkGC, values);
- if (control.backgroundImage != null) {
- Point pt = display.map (this, control, 0, 0);
- OS.gdk_gc_set_fill (gdkGC, OS.GDK_TILED);
- OS.gdk_gc_set_ts_origin (gdkGC, -pt.x, -pt.y);
- OS.gdk_gc_set_tile (gdkGC, control.backgroundImage.pixmap);
- OS.gdk_draw_rectangle (data.drawable, gdkGC, 1, x, y, width, height);
- OS.gdk_gc_set_fill (gdkGC, values.fill);
- OS.gdk_gc_set_ts_origin (gdkGC, values.ts_x_origin, values.ts_y_origin);
- } else {
- GdkColor color = control.getBackgroundColor ();
- OS.gdk_gc_set_foreground (gdkGC, color);
- OS.gdk_draw_rectangle (data.drawable, gdkGC, 1, x, y, width, height);
- color.pixel = values.foreground_pixel;
- OS.gdk_gc_set_foreground (gdkGC, color);
- }
- }
- } else {
- gc.fillRectangle (x, y, width, height);
- }
-}
-
-void enableWidget (boolean enabled) {
- if ((state & CANVAS) != 0) return;
- super.enableWidget (enabled);
-}
-
-Composite findDeferredControl () {
- return layoutCount > 0 ? this : parent.findDeferredControl ();
-}
-
-Menu [] findMenus (Control control) {
- if (control == this) return new Menu [0];
- Menu result [] = super.findMenus (control);
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- Menu [] menuList = child.findMenus (control);
- if (menuList.length != 0) {
- Menu [] newResult = new Menu [result.length + menuList.length];
- System.arraycopy (result, 0, newResult, 0, result.length);
- System.arraycopy (menuList, 0, newResult, result.length, menuList.length);
- result = newResult;
- }
- }
- return result;
-}
-
-void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) {
- super.fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
- }
-}
-
-void fixModal(int /*long*/ group, int /*long*/ modalGroup) {
- Control[] controls = _getChildren ();
- for (int i = 0; i < controls.length; i++) {
- controls[i].fixModal (group, modalGroup);
- }
-}
-
-void fixStyle () {
- super.fixStyle ();
- if (scrolledHandle == 0) fixStyle (handle);
- Control[] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- children [i].fixStyle ();
- }
-}
-
-void fixTabList (Control control) {
- if (tabList == null) return;
- int count = 0;
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == control) count++;
- }
- if (count == 0) return;
- Control [] newList = null;
- int length = tabList.length - count;
- if (length != 0) {
- newList = new Control [length];
- int index = 0;
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] != control) {
- newList [index++] = tabList [i];
- }
- }
- }
- tabList = newList;
-}
-
-void fixZOrder () {
- if ((state & CANVAS) != 0) return;
- int /*long*/ parentHandle = parentingHandle ();
- int /*long*/ parentWindow = OS.GTK_WIDGET_WINDOW (parentHandle);
- if (parentWindow == 0) return;
- int /*long*/ [] userData = new int /*long*/ [1];
- int /*long*/ windowList = OS.gdk_window_get_children (parentWindow);
- if (windowList != 0) {
- int /*long*/ windows = windowList;
- while (windows != 0) {
- int /*long*/ window = OS.g_list_data (windows);
- if (window != redrawWindow) {
- OS.gdk_window_get_user_data (window, userData);
- if (userData [0] == 0 || OS.G_OBJECT_TYPE (userData [0]) != display.gtk_fixed_get_type ()) {
- OS.gdk_window_lower (window);
- }
- }
- windows = OS.g_list_next (windows);
- }
- OS.g_list_free (windowList);
- }
-}
-
-int /*long*/ focusHandle () {
- if (socketHandle != 0) return socketHandle;
- return super.focusHandle ();
-}
-
-boolean forceFocus (int /*long*/ focusHandle) {
- if (socketHandle != 0) OS.GTK_WIDGET_SET_FLAGS (focusHandle, OS.GTK_CAN_FOCUS);
- boolean result = super.forceFocus (focusHandle);
- if (socketHandle != 0) OS.GTK_WIDGET_UNSET_FLAGS (focusHandle, OS.GTK_CAN_FOCUS);
- return result;
-}
-
-/**
- * Returns the receiver's background drawing mode. This
- * will be one of the following constants defined in class
- * <code>SWT</code>:
- * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>,
- * <code>INHERTIT_FORCE</code>.
- *
- * @return the background mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- *
- * @since 3.2
- */
-public int getBackgroundMode () {
- checkWidget ();
- return backgroundMode;
-}
-
-/**
- * Returns a (possibly empty) array containing the receiver's children.
- * Children are returned in the order that they are drawn. The topmost
- * control appears at the beginning of the array. Subsequent controls
- * draw beneath this control and appear later in the array.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of children, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return an array of children
- *
- * @see Control#moveAbove
- * @see Control#moveBelow
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control [] getChildren () {
- checkWidget();
- return _getChildren ();
-}
-
-int getChildrenCount () {
- /*
- * NOTE: The current implementation will count
- * non-registered children.
- */
- int /*long*/ list = OS.gtk_container_get_children (handle);
- if (list == 0) return 0;
- int count = OS.g_list_length (list);
- OS.g_list_free (list);
- return count;
-}
-
-public Rectangle getClientArea () {
- checkWidget();
- if ((state & CANVAS) != 0) {
- if ((state & ZERO_WIDTH) != 0 && (state & ZERO_HEIGHT) != 0) {
- return new Rectangle (0, 0, 0, 0);
- }
- forceResize ();
- int /*long*/ clientHandle = clientHandle ();
- int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (clientHandle);
- int height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (clientHandle);
- return new Rectangle (0, 0, width, height);
- }
- return super.getClientArea();
-}
-
-int getClientWidth() {
- return (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (clientHandle ());
-}
-
-/**
- * Returns layout which is associated with the receiver, or
- * null if one has not been set.
- *
- * @return the receiver's layout or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Layout getLayout () {
- checkWidget();
- return layout;
-}
-
-/**
- * Returns <code>true</code> if the receiver has deferred
- * the performing of layout, and <code>false</code> otherwise.
- *
- * @return the receiver's deferred layout state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setLayoutDeferred(boolean)
- * @see #isLayoutDeferred()
- *
- * @since 3.1
- */
-public boolean getLayoutDeferred () {
- checkWidget ();
- return layoutCount > 0 ;
-}
-
-/**
- * Gets the (possibly empty) tabbing order for the control.
- *
- * @return tabList the ordered list of controls representing the tab order
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setTabList
- */
-public Control [] getTabList () {
- checkWidget ();
- Control [] tabList = _getTabList ();
- if (tabList == null) {
- int count = 0;
- Control [] list =_getChildren ();
- for (int i=0; i<list.length; i++) {
- if (list [i].isTabGroup ()) count++;
- }
- tabList = new Control [count];
- int index = 0;
- for (int i=0; i<list.length; i++) {
- if (list [i].isTabGroup ()) {
- tabList [index++] = list [i];
- }
- }
- }
- return tabList;
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_button_press_event (widget, event);
- if (result != 0) return result;
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_FOCUS) == 0 && hooksKeys ()) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
- if (gdkEvent.button == 1) {
- if (getChildrenCount () == 0) setFocus ();
- }
- }
- }
- return result;
-}
-
-int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ eventPtr) {
- if ((state & OBSCURED) != 0) return 0;
- if ((state & CANVAS) == 0) {
- return super.gtk_expose_event (widget, eventPtr);
- }
- if ((style & SWT.NO_MERGE_PAINTS) == 0) {
- return super.gtk_expose_event (widget, eventPtr);
- }
- if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0;
- GdkEventExpose gdkEvent = new GdkEventExpose ();
- OS.memmove(gdkEvent, eventPtr, GdkEventExpose.sizeof);
- int /*long*/ [] rectangles = new int /*long*/ [1];
- int [] n_rectangles = new int [1];
- OS.gdk_region_get_rectangles (gdkEvent.region, rectangles, n_rectangles);
- GdkRectangle rect = new GdkRectangle ();
- for (int i=0; i<n_rectangles[0]; i++) {
- Event event = new Event ();
- OS.memmove (rect, rectangles [0] + i * GdkRectangle.sizeof, GdkRectangle.sizeof);
- event.x = rect.x;
- event.y = rect.y;
- event.width = rect.width;
- event.height = rect.height;
- if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.width - event.x;
- int /*long*/ damageRgn = OS.gdk_region_new ();
- OS.gdk_region_union_with_rect (damageRgn, rect);
- GCData data = new GCData ();
- data.damageRgn = damageRgn;
- GC gc = event.gc = GC.gtk_new (this, data);
- OS.gdk_gc_set_clip_region (gc.handle, damageRgn);
- sendEvent (SWT.Paint, event);
- gc.dispose ();
- OS.gdk_region_destroy (damageRgn);
- event.gc = null;
- }
- OS.g_free (rectangles [0]);
- return 0;
-}
-
-int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_key_press_event (widget, event);
- if (result != 0) return result;
- /*
- * Feature in GTK. The default behavior when the return key
- * is pressed is to select the default button. This is not the
- * expected behavior for Composite and its subclasses. The
- * fix is to avoid calling the default handler.
- */
- if ((state & CANVAS) != 0 && socketHandle == 0) {
- GdkEventKey keyEvent = new GdkEventKey ();
- OS.memmove (keyEvent, event, GdkEventKey.sizeof);
- int key = keyEvent.keyval;
- switch (key) {
- case OS.GDK_Return:
- case OS.GDK_KP_Enter: return 1;
- }
- }
- return result;
-}
-
-int /*long*/ gtk_focus (int /*long*/ widget, int /*long*/ directionType) {
- if (widget == socketHandle) return 0;
- return super.gtk_focus (widget, directionType);
-}
-
-int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_focus_in_event (widget, event);
- return (state & CANVAS) != 0 ? 1 : result;
-}
-
-int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_focus_out_event (widget, event);
- return (state & CANVAS) != 0 ? 1 : result;
-}
-
-int /*long*/ gtk_map (int /*long*/ widget) {
- fixZOrder ();
- return 0;
-}
-
-int /*long*/ gtk_realize (int /*long*/ widget) {
- int /*long*/ result = super.gtk_realize (widget);
- if ((style & SWT.NO_BACKGROUND) != 0) {
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (paintHandle ());
- if (window != 0) OS.gdk_window_set_back_pixmap (window, 0, false);
- }
- if (socketHandle != 0) {
- embeddedHandle = OS.gtk_socket_get_id (socketHandle);
- }
- return result;
-}
-
-int /*long*/ gtk_scroll_child (int /*long*/ widget, int /*long*/ scrollType, int /*long*/ horizontal) {
- /* Stop GTK scroll child signal for canvas */
- OS.g_signal_stop_emission_by_name (widget, OS.scroll_child);
- return 1;
-}
-
-int /*long*/ gtk_style_set (int /*long*/ widget, int /*long*/ previousStyle) {
- int /*long*/ result = super.gtk_style_set (widget, previousStyle);
- if ((style & SWT.NO_BACKGROUND) != 0) {
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (paintHandle ());
- if (window != 0) OS.gdk_window_set_back_pixmap (window, 0, false);
- }
- return result;
-}
-
-boolean hasBorder () {
- return (style & SWT.BORDER) != 0;
-}
-
-void hookEvents () {
- super.hookEvents ();
- if ((state & CANVAS) != 0) {
- OS.gtk_widget_add_events (handle, OS.GDK_POINTER_MOTION_HINT_MASK);
- if (scrolledHandle != 0) {
- OS.g_signal_connect_closure (scrolledHandle, OS.scroll_child, display.closures [SCROLL_CHILD], false);
- }
- }
-}
-
-boolean hooksKeys () {
- return hooks (SWT.KeyDown) || hooks (SWT.KeyUp);
-}
-
-int /*long*/ imHandle () {
- return imHandle;
-}
-
-/**
- * Returns <code>true</code> if the receiver or any ancestor
- * up to and including the receiver's nearest ancestor shell
- * has deferred the performing of layouts. Otherwise, <code>false</code>
- * is returned.
- *
- * @return the receiver's deferred layout state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setLayoutDeferred(boolean)
- * @see #getLayoutDeferred()
- *
- * @since 3.1
- */
-public boolean isLayoutDeferred () {
- checkWidget ();
- return findDeferredControl () != null;
-}
-
-boolean isTabGroup() {
- if ((state & CANVAS) != 0) return true;
- return super.isTabGroup();
-}
-
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the receiver does not have a layout, do nothing.
- * <p>
- * This is equivalent to calling <code>layout(true)</code>.
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void layout () {
- checkWidget ();
- layout (true);
-}
-
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the argument is <code>true</code> the layout must not rely
- * on any information it has cached about the immediate children. If it
- * is <code>false</code> the layout may (potentially) optimize the
- * work it is doing by assuming that none of the receiver's
- * children has changed state since the last layout.
- * If the receiver does not have a layout, do nothing.
- * <p>
- * If a child is resized as a result of a call to layout, the
- * resize event will invoke the layout of the child. The layout
- * will cascade down through all child widgets in the receiver's widget
- * tree until a child is encountered that does not resize. Note that
- * a layout due to a resize will not flush any cached information
- * (same as <code>layout(false)</code>).
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void layout (boolean changed) {
- checkWidget ();
- if (layout == null) return;
- layout (changed, false);
-}
-
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the changed argument is <code>true</code> the layout must not rely
- * on any information it has cached about its children. If it
- * is <code>false</code> the layout may (potentially) optimize the
- * work it is doing by assuming that none of the receiver's
- * children has changed state since the last layout.
- * If the all argument is <code>true</code> the layout will cascade down
- * through all child widgets in the receiver's widget tree, regardless of
- * whether the child has changed size. The changed argument is applied to
- * all layouts. If the all argument is <code>false</code>, the layout will
- * <em>not</em> cascade down through all child widgets in the receiver's widget
- * tree. However, if a child is resized as a result of a call to layout, the
- * resize event will invoke the layout of the child. Note that
- * a layout due to a resize will not flush any cached information
- * (same as <code>layout(false)</code>).
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise
- * @param all <code>true</code> if all children in the receiver's widget tree should be laid out, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void layout (boolean changed, boolean all) {
- checkWidget ();
- if (layout == null && !all) return;
- markLayout (changed, all);
- updateLayout (all);
-}
-
-/**
- * Forces a lay out (that is, sets the size and location) of all widgets that
- * are in the parent hierarchy of the changed control up to and including the
- * receiver. The layouts in the hierarchy must not rely on any information
- * cached about the changed control or any of its ancestors. The layout may
- * (potentially) optimize the work it is doing by assuming that none of the
- * peers of the changed control have changed state since the last layout.
- * If an ancestor does not have a layout, skip it.
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed a control that has had a state change which requires a recalculation of its size
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li>
- * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void layout (Control [] changed) {
- checkWidget ();
- if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<changed.length; i++) {
- Control control = changed [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean ancestor = false;
- Composite composite = control.parent;
- while (composite != null) {
- ancestor = composite == this;
- if (ancestor) break;
- composite = composite.parent;
- }
- if (!ancestor) error (SWT.ERROR_INVALID_PARENT);
- }
- int updateCount = 0;
- Composite [] update = new Composite [16];
- for (int i=0; i<changed.length; i++) {
- Control child = changed [i];
- Composite composite = child.parent;
- while (child != this) {
- if (composite.layout != null) {
- composite.state |= LAYOUT_NEEDED;
- if (!composite.layout.flushCache (child)) {
- composite.state |= LAYOUT_CHANGED;
- }
- }
- if (updateCount == update.length) {
- Composite [] newUpdate = new Composite [update.length + 16];
- System.arraycopy (update, 0, newUpdate, 0, update.length);
- update = newUpdate;
- }
- child = update [updateCount++] = composite;
- composite = child.parent;
- }
- }
- for (int i=updateCount-1; i>=0; i--) {
- update [i].updateLayout (false);
- }
-}
-
-void markLayout (boolean changed, boolean all) {
- if (layout != null) {
- state |= LAYOUT_NEEDED;
- if (changed) state |= LAYOUT_CHANGED;
- }
- if (all) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].markLayout (changed, all);
- }
- }
-}
-
-void moveAbove (int /*long*/ child, int /*long*/ sibling) {
- if (child == sibling) return;
- int /*long*/ parentHandle = parentingHandle ();
- GtkFixed fixed = new GtkFixed ();
- OS.memmove (fixed, parentHandle);
- int /*long*/ children = fixed.children;
- if (children == 0) return;
- int /*long*/ [] data = new int /*long*/ [1];
- int /*long*/ [] widget = new int /*long*/ [1];
- int /*long*/ childData = 0, childLink = 0, siblingLink = 0, temp = children;
- while (temp != 0) {
- OS.memmove (data, temp, OS.PTR_SIZEOF);
- OS.memmove (widget, data [0], OS.PTR_SIZEOF);
- if (child == widget [0]) {
- childLink = temp;
- childData = data [0];
- } else if (sibling == widget [0]) {
- siblingLink = temp;
- }
- if (childData != 0 && (sibling == 0 || siblingLink != 0)) break;
- temp = OS.g_list_next (temp);
- }
- children = OS.g_list_remove_link (children, childLink);
- if (siblingLink == 0 || OS.g_list_previous (siblingLink) == 0) {
- OS.g_list_free_1 (childLink);
- children = OS.g_list_prepend (children, childData);
- } else {
- temp = OS.g_list_previous (siblingLink);
- OS.g_list_set_previous (childLink, temp);
- OS.g_list_set_next (temp, childLink);
- OS.g_list_set_next (childLink, siblingLink);
- OS.g_list_set_previous (siblingLink, childLink);
- }
- fixed.children = children;
- OS.memmove (parentHandle, fixed);
-}
-
-void moveBelow (int /*long*/ child, int /*long*/ sibling) {
- if (child == sibling) return;
- int /*long*/ parentHandle = parentingHandle ();
- if (sibling == 0 && parentHandle == fixedHandle) {
- moveAbove (child, scrolledHandle != 0 ? scrolledHandle : handle);
- return;
- }
- GtkFixed fixed = new GtkFixed ();
- OS.memmove (fixed, parentHandle);
- int /*long*/ children = fixed.children;
- if (children == 0) return;
- int /*long*/ [] data = new int /*long*/ [1];
- int /*long*/ [] widget = new int /*long*/ [1];
- int /*long*/ childData = 0, childLink = 0, siblingLink = 0, temp = children;
- while (temp != 0) {
- OS.memmove (data, temp, OS.PTR_SIZEOF);
- OS.memmove (widget, data [0], OS.PTR_SIZEOF);
- if (child == widget [0]) {
- childLink = temp;
- childData = data [0];
- } else if (sibling == widget [0]) {
- siblingLink = temp;
- }
- if (childData != 0 && (sibling == 0 || siblingLink != 0)) break;
- temp = OS.g_list_next (temp);
- }
- children = OS.g_list_remove_link (children, childLink);
- if (siblingLink == 0 || OS.g_list_next (siblingLink) == 0) {
- OS.g_list_free_1 (childLink);
- children = OS.g_list_append (children, childData);
- } else {
- temp = OS.g_list_next (siblingLink);
- OS.g_list_set_next (childLink, temp);
- OS.g_list_set_previous (temp, childLink);
- OS.g_list_set_previous (childLink, siblingLink);
- OS.g_list_set_next (siblingLink, childLink);
- }
- fixed.children = children;
- OS.memmove (parentHandle, fixed);
-}
-
-void moveChildren(int oldWidth) {
- Control[] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- Control child = children[i];
- int /*long*/ topHandle = child.topHandle ();
- int x = OS.GTK_WIDGET_X (topHandle);
- int y = OS.GTK_WIDGET_Y (topHandle);
- int controlWidth = (child.state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle);
- x = oldWidth - controlWidth - x;
- int clientWidth = getClientWidth ();
- x = clientWidth - controlWidth - x;
- if (child.enableWindow != 0) {
- OS.gdk_window_move (child.enableWindow, x, y);
- }
- child.moveHandle (x, y);
- /*
- * Cause a size allocation this widget's topHandle. Note that
- * all calls to gtk_widget_size_allocate() must be preceded by
- * a call to gtk_widget_size_request().
- */
- GtkRequisition requisition = new GtkRequisition ();
- gtk_widget_size_request (topHandle, requisition);
- GtkAllocation allocation = new GtkAllocation ();
- allocation.x = x;
- allocation.y = y;
- allocation.width = OS.GTK_WIDGET_WIDTH (topHandle);
- allocation.height = OS.GTK_WIDGET_HEIGHT (topHandle);
- OS.gtk_widget_size_allocate (topHandle, allocation);
- Control control = child.findBackgroundControl ();
- if (control != null && control.backgroundImage != null) {
- if (child.isVisible ()) child.redrawWidget (0, 0, 0, 0, true, true, true);
- }
- }
-}
-
-Point minimumSize (int wHint, int hHint, boolean changed) {
- Control [] children = _getChildren ();
- int width = 0, height = 0;
- for (int i=0; i<children.length; i++) {
- Rectangle rect = children [i].getBounds ();
- width = Math.max (width, rect.x + rect.width);
- height = Math.max (height, rect.y + rect.height);
- }
- return new Point (width, height);
-}
-
-int /*long*/ parentingHandle () {
- if ((state & CANVAS) != 0) return handle;
- return fixedHandle != 0 ? fixedHandle : handle;
-}
-
-void printWidget (GC gc, int /*long*/ drawable, int depth, int x, int y) {
- Region oldClip = new Region (gc.getDevice ());
- Region newClip = new Region (gc.getDevice ());
- gc.getClipping (oldClip);
- Rectangle rect = getBounds ();
- newClip.add (oldClip);
- newClip.intersect (x, y, rect.width, rect.height);
- gc.setClipping (newClip);
- super.printWidget (gc, drawable, depth, x, y);
- Rectangle clientRect = getClientArea ();
- Point pt = display.map (this, parent, clientRect.x, clientRect.y);
- clientRect.x = x + pt.x - rect.x;
- clientRect.y = y + pt.y - rect.y;
- newClip.intersect (clientRect);
- gc.setClipping (newClip);
- Control [] children = _getChildren ();
- for (int i=children.length-1; i>=0; --i) {
- Control child = children [i];
- if (child.getVisible ()) {
- Point location = child.getLocation ();
- child.printWidget (gc, drawable, depth, x + location.x, y + location.y);
- }
- }
- gc.setClipping (oldClip);
- oldClip.dispose ();
- newClip.dispose ();
-}
-
-void redrawChildren () {
- super.redrawChildren ();
- Control [] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- Control child = children [i];
- if ((child.state & PARENT_BACKGROUND) != 0) {
- child.redrawWidget (0, 0, 0, 0, true, false, true);
- child.redrawChildren ();
- }
- }
-}
-
-void register () {
- super.register ();
- if (socketHandle != 0) display.addWidget (socketHandle, this);
-}
-
-void releaseChildren (boolean destroy) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child != null && !child.isDisposed ()) {
- child.release (false);
- }
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- socketHandle = embeddedHandle = 0;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (imHandle != 0) OS.g_object_unref (imHandle);
- imHandle = 0;
- layout = null;
- tabList = null;
-}
-
-void removeControl (Control control) {
- fixTabList (control);
-}
-
-void resizeHandle (int width, int height) {
- super.resizeHandle (width, height);
- if (socketHandle != 0) OS.gtk_widget_set_size_request (socketHandle, width, height);
-}
-
-/**
- * Sets the background drawing mode to the argument which should
- * be one of the following constants defined in class <code>SWT</code>:
- * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>,
- * <code>INHERIT_FORCE</code>.
- *
- * @param mode the new background mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- *
- * @since 3.2
- */
-public void setBackgroundMode (int mode) {
- checkWidget ();
- backgroundMode = mode;
- Control[] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- children [i].updateBackgroundMode ();
- }
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- int result = super.setBounds (x, y, width, height, move, resize);
- if ((result & RESIZED) != 0 && layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
- return result;
-}
-
-public boolean setFocus () {
- checkWidget();
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.getVisible () && child.setFocus ()) return true;
- }
- return super.setFocus ();
-}
-
-/**
- * Sets the layout which is associated with the receiver to be
- * the argument which may be null.
- *
- * @param layout the receiver's new layout or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLayout (Layout layout) {
- checkWidget();
- this.layout = layout;
-}
-
-/**
- * If the argument is <code>true</code>, causes subsequent layout
- * operations in the receiver or any of its children to be ignored.
- * No layout of any kind can occur in the receiver or any of its
- * children until the flag is set to false.
- * Layout operations that occurred while the flag was
- * <code>true</code> are remembered and when the flag is set to
- * <code>false</code>, the layout operations are performed in an
- * optimized manner. Nested calls to this method are stacked.
- *
- * @param defer the new defer state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #layout(boolean)
- * @see #layout(Control[])
- *
- * @since 3.1
- */
-public void setLayoutDeferred (boolean defer) {
- if (!defer) {
- if (--layoutCount == 0) {
- if ((state & LAYOUT_CHILD) != 0 || (state & LAYOUT_NEEDED) != 0) {
- updateLayout (true);
- }
- }
- } else {
- layoutCount++;
- }
-}
-
-boolean setScrollBarVisible (ScrollBar bar, boolean visible) {
- boolean changed = super.setScrollBarVisible (bar, visible);
- if (changed && layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
- return changed;
-}
-
-boolean setTabGroupFocus (boolean next) {
- if (isTabItem ()) return setTabItemFocus (next);
- boolean takeFocus = (style & SWT.NO_FOCUS) == 0;
- if ((state & CANVAS) != 0) takeFocus = hooksKeys ();
- if (socketHandle != 0) takeFocus = true;
- if (takeFocus && setTabItemFocus (next)) return true;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.isTabItem () && child.setTabItemFocus (next)) return true;
- }
- return false;
-}
-
-boolean setTabItemFocus (boolean next) {
- if (!super.setTabItemFocus (next)) return false;
- if (socketHandle != 0) {
- int direction = next ? OS.GTK_DIR_TAB_FORWARD : OS.GTK_DIR_TAB_BACKWARD;
- OS.GTK_WIDGET_UNSET_FLAGS (socketHandle, OS.GTK_HAS_FOCUS);
- OS.gtk_widget_child_focus (socketHandle, direction);
- OS.GTK_WIDGET_SET_FLAGS (socketHandle, OS.GTK_HAS_FOCUS);
- }
- return true;
-}
-
-/**
- * Sets the tabbing order for the specified controls to
- * match the order that they occur in the argument list.
- *
- * @param tabList the ordered list of controls representing the tab order or null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if a widget in the tabList is null or has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if widget in the tabList is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTabList (Control [] tabList) {
- checkWidget ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- Control control = tabList [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
- Control [] newList = new Control [tabList.length];
- System.arraycopy (tabList, 0, newList, 0, tabList.length);
- tabList = newList;
- }
- this.tabList = tabList;
-}
-
-void showWidget () {
- super.showWidget ();
- if (socketHandle != 0) {
- OS.gtk_widget_show (socketHandle);
- embeddedHandle = OS.gtk_socket_get_id (socketHandle);
- }
- if (scrolledHandle == 0) fixStyle (handle);
-}
-
-boolean checkSubwindow () {
- return true;
-}
-
-boolean translateMnemonic (Event event, Control control) {
- if (super.translateMnemonic (event, control)) return true;
- if (control != null) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.translateMnemonic (event, control)) return true;
- }
- }
- return false;
-}
-
-int traversalCode(int key, GdkEventKey event) {
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_FOCUS) != 0) return 0;
- if (hooksKeys ()) return 0;
- }
- return super.traversalCode (key, event);
-}
-
-boolean translateTraversal (GdkEventKey keyEvent) {
- if (socketHandle != 0) return false;
- return super.translateTraversal (keyEvent);
-}
-
-void updateBackgroundMode () {
- super.updateBackgroundMode ();
- Control [] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- children [i].updateBackgroundMode ();
- }
-}
-
-void updateLayout (boolean all) {
- Composite parent = findDeferredControl ();
- if (parent != null) {
- parent.state |= LAYOUT_CHILD;
- return;
- }
- if ((state & LAYOUT_NEEDED) != 0) {
- boolean changed = (state & LAYOUT_CHANGED) != 0;
- state &= ~(LAYOUT_NEEDED | LAYOUT_CHANGED);
- layout.layout (this, changed);
- }
- if (all) {
- state &= ~LAYOUT_CHILD;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].updateLayout (all);
- }
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
deleted file mode 100644
index dbfbda20e1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
+++ /dev/null
@@ -1,4588 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.accessibility.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.accessibility.gtk.*;
-import org.eclipse.swt.internal.cairo.*;
-import org.eclipse.swt.internal.gtk.*;
-
-/**
- * Control is the abstract superclass of all windowed user interface classes.
- * <p>
- * <dl>
- * <dt><b>Styles:</b>
- * <dd>BORDER</dd>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * <dt><b>Events:</b>
- * <dd>DragDetect, FocusIn, FocusOut, Help, KeyDown, KeyUp, MenuDetect, MouseDoubleClick, MouseDown, MouseEnter,
- * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize, Traverse</dd>
- * </dl>
- * </p><p>
- * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#control">Control snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public abstract class Control extends Widget implements Drawable {
- int /*long*/ fixedHandle;
- int /*long*/ redrawWindow, enableWindow;
- int drawCount;
- Composite parent;
- Cursor cursor;
- Menu menu;
- Image backgroundImage;
- Font font;
- Region region;
- String toolTipText;
- Object layoutData;
- Accessible accessible;
-
- static final String IS_ACTIVE = "org.eclipse.swt.internal.control.isactive"; //$NON-NLS-1$
-
-Control () {
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#LEFT_TO_RIGHT
- * @see SWT#RIGHT_TO_LEFT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Control (Composite parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget (0);
-}
-
-Font defaultFont () {
- return display.getSystemFont ();
-}
-
-void deregister () {
- super.deregister ();
- if (fixedHandle != 0) display.removeWidget (fixedHandle);
- int /*long*/ imHandle = imHandle ();
- if (imHandle != 0) display.removeWidget (imHandle);
-}
-
-boolean drawGripper (int x, int y, int width, int height, boolean vertical) {
- int /*long*/ paintHandle = paintHandle ();
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (paintHandle);
- if (window == 0) return false;
- int orientation = vertical ? OS.GTK_ORIENTATION_HORIZONTAL : OS.GTK_ORIENTATION_VERTICAL;
- if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - width - x;
- OS.gtk_paint_handle (OS.gtk_widget_get_style (paintHandle), window, OS.GTK_STATE_NORMAL, OS.GTK_SHADOW_OUT, null, paintHandle, new byte [1], x, y, width, height, orientation);
- return true;
-}
-
-void enableWidget (boolean enabled) {
- OS.gtk_widget_set_sensitive (handle, enabled);
-}
-
-int /*long*/ enterExitHandle () {
- return eventHandle ();
-}
-
-int /*long*/ eventHandle () {
- return handle;
-}
-
-int /*long*/ eventWindow () {
- int /*long*/ eventHandle = eventHandle ();
- OS.gtk_widget_realize (eventHandle);
- return OS.GTK_WIDGET_WINDOW (eventHandle);
-}
-
-void fixFocus (Control focusControl) {
- Shell shell = getShell ();
- Control control = this;
- while (control != shell && (control = control.parent) != null) {
- if (control.setFocus ()) return;
- }
- shell.setSavedFocus (focusControl);
- int /*long*/ focusHandle = shell.vboxHandle;
- OS.GTK_WIDGET_SET_FLAGS (focusHandle, OS.GTK_CAN_FOCUS);
- OS.gtk_widget_grab_focus (focusHandle);
- OS.GTK_WIDGET_UNSET_FLAGS (focusHandle, OS.GTK_CAN_FOCUS);
-}
-
-void fixStyle () {
- if (fixedHandle != 0) fixStyle (fixedHandle);
-}
-
-void fixStyle (int /*long*/ handle) {
- /*
- * Feature in GTK. Some GTK themes apply a different background to
- * the contents of a GtkNotebook. However, in an SWT TabFolder, the
- * children are not parented below the GtkNotebook widget, and usually
- * have their own GtkFixed. The fix is to look up the correct style
- * for a child of a GtkNotebook and apply its background to any GtkFixed
- * widgets that are direct children of an SWT TabFolder.
- *
- * Note that this has to be when the theme settings changes and that it
- * should not override the application background.
- */
- if ((state & BACKGROUND) != 0) return;
- if ((state & THEME_BACKGROUND) == 0) return;
- int /*long*/ childStyle = parent.childStyle ();
- if (childStyle != 0) {
- GdkColor color = new GdkColor();
- OS.gtk_style_get_bg (childStyle, 0, color);
- setBackgroundColor (color);
- }
-}
-
-int /*long*/ focusHandle () {
- return handle;
-}
-
-int /*long*/ fontHandle () {
- return handle;
-}
-
-boolean hasFocus () {
- return this == display.getFocusControl();
-}
-
-void hookEvents () {
- /* Connect the keyboard signals */
- int /*long*/ focusHandle = focusHandle ();
- int focusMask = OS.GDK_KEY_PRESS_MASK | OS.GDK_KEY_RELEASE_MASK | OS.GDK_FOCUS_CHANGE_MASK;
- OS.gtk_widget_add_events (focusHandle, focusMask);
- OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [POPUP_MENU], 0, display.closures [POPUP_MENU], false);
- OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [SHOW_HELP], 0, display.closures [SHOW_HELP], false);
- OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [KEY_PRESS_EVENT], 0, display.closures [KEY_PRESS_EVENT], false);
- OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [KEY_RELEASE_EVENT], 0, display.closures [KEY_RELEASE_EVENT], false);
- OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [FOCUS], 0, display.closures [FOCUS], false);
- OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [FOCUS_IN_EVENT], 0, display.closures [FOCUS_IN_EVENT], false);
- OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [FOCUS_OUT_EVENT], 0, display.closures [FOCUS_OUT_EVENT], false);
-
- /* Connect the mouse signals */
- int /*long*/ eventHandle = eventHandle ();
- int eventMask = OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_PRESS_MASK | OS.GDK_BUTTON_RELEASE_MASK;
- OS.gtk_widget_add_events (eventHandle, eventMask);
- OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false);
- OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT], false);
- OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [MOTION_NOTIFY_EVENT], 0, display.closures [MOTION_NOTIFY_EVENT], false);
- OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [SCROLL_EVENT], 0, display.closures [SCROLL_EVENT], false);
-
- /* Connect enter/exit signals */
- int /*long*/ enterExitHandle = enterExitHandle ();
- int enterExitMask = OS.GDK_ENTER_NOTIFY_MASK | OS.GDK_LEAVE_NOTIFY_MASK;
- OS.gtk_widget_add_events (enterExitHandle, enterExitMask);
- OS.g_signal_connect_closure_by_id (enterExitHandle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false);
- OS.g_signal_connect_closure_by_id (enterExitHandle, display.signalIds [LEAVE_NOTIFY_EVENT], 0, display.closures [LEAVE_NOTIFY_EVENT], false);
-
- /*
- * Feature in GTK. Events such as mouse move are propagate up
- * the widget hierarchy and are seen by the parent. This is the
- * correct GTK behavior but not correct for SWT. The fix is to
- * hook a signal after and stop the propagation using a negative
- * event number to distinguish this case.
- *
- * The signal is hooked to the fixedHandle to catch events sent to
- * lightweight widgets.
- */
- int /*long*/ blockHandle = fixedHandle != 0 ? fixedHandle : eventHandle;
- OS.g_signal_connect_closure_by_id (blockHandle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT_INVERSE], true);
- OS.g_signal_connect_closure_by_id (blockHandle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT_INVERSE], true);
- OS.g_signal_connect_closure_by_id (blockHandle, display.signalIds [MOTION_NOTIFY_EVENT], 0, display.closures [MOTION_NOTIFY_EVENT_INVERSE], true);
-
- /* Connect the event_after signal for both key and mouse */
- OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [EVENT_AFTER], 0, display.closures [EVENT_AFTER], false);
- if (focusHandle != eventHandle) {
- OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [EVENT_AFTER], 0, display.closures [EVENT_AFTER], false);
- }
-
- /* Connect the paint signal */
- int /*long*/ paintHandle = paintHandle ();
- int paintMask = OS.GDK_EXPOSURE_MASK | OS.GDK_VISIBILITY_NOTIFY_MASK;
- OS.gtk_widget_add_events (paintHandle, paintMask);
- OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [EXPOSE_EVENT], 0, display.closures [EXPOSE_EVENT_INVERSE], false);
- OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [VISIBILITY_NOTIFY_EVENT], 0, display.closures [VISIBILITY_NOTIFY_EVENT], false);
- OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [EXPOSE_EVENT], 0, display.closures [EXPOSE_EVENT], true);
-
- /* Connect the Input Method signals */
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [REALIZE], 0, display.closures [REALIZE], true);
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [UNREALIZE], 0, display.closures [UNREALIZE], false);
- int /*long*/ imHandle = imHandle ();
- if (imHandle != 0) {
- OS.g_signal_connect_closure (imHandle, OS.commit, display.closures [COMMIT], false);
- OS.g_signal_connect_closure (imHandle, OS.preedit_changed, display.closures [PREEDIT_CHANGED], false);
- }
-
- OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [STYLE_SET], 0, display.closures [STYLE_SET], false);
-
- int /*long*/ topHandle = topHandle ();
- OS.g_signal_connect_closure_by_id (topHandle, display.signalIds [MAP], 0, display.closures [MAP], true);
-}
-
-int /*long*/ hoverProc (int /*long*/ widget) {
- int [] x = new int [1], y = new int [1], mask = new int [1];
- OS.gdk_window_get_pointer (0, x, y, mask);
- sendMouseEvent (SWT.MouseHover, 0, /*time*/0, x [0], y [0], false, mask [0]);
- /* Always return zero in order to cancel the hover timer */
- return 0;
-}
-
-int /*long*/ topHandle() {
- if (fixedHandle != 0) return fixedHandle;
- return super.topHandle ();
-}
-
-int /*long*/ paintHandle () {
- int /*long*/ topHandle = topHandle ();
- int /*long*/ paintHandle = handle;
- while (paintHandle != topHandle) {
- if ((OS.GTK_WIDGET_FLAGS (paintHandle) & OS.GTK_NO_WINDOW) == 0) break;
- paintHandle = OS.gtk_widget_get_parent (paintHandle);
- }
- return paintHandle;
-}
-
-int /*long*/ paintWindow () {
- int /*long*/ paintHandle = paintHandle ();
- OS.gtk_widget_realize (paintHandle);
- return OS.GTK_WIDGET_WINDOW (paintHandle);
-}
-
-/**
- * Prints the receiver and all children.
- *
- * @param gc the gc where the drawing occurs
- * @return <code>true</code> if the operation was successful and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean print (GC gc) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- int /*long*/ topHandle = topHandle ();
- OS.gtk_widget_realize (topHandle);
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (topHandle);
- GCData data = gc.getGCData ();
- OS.gdk_window_process_updates (window, true);
- printWidget (gc, data.drawable, OS.gdk_drawable_get_depth (data.drawable), 0, 0);
- return true;
-}
-
-void printWidget (GC gc, int /*long*/ drawable, int depth, int x, int y) {
- boolean obscured = (state & OBSCURED) != 0;
- state &= ~OBSCURED;
- int /*long*/ topHandle = topHandle ();
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (topHandle);
- printWindow (true, this, gc, drawable, depth, window, x, y);
- if (obscured) state |= OBSCURED;
-}
-
-void printWindow (boolean first, Control control, GC gc, int /*long*/ drawable, int depth, int /*long*/ window, int x, int y) {
- if (OS.gdk_drawable_get_depth (window) != depth) return;
- GdkRectangle rect = new GdkRectangle ();
- int [] width = new int [1], height = new int [1];
- OS.gdk_drawable_get_size (window, width, height);
- rect.width = width [0];
- rect.height = height [0];
- OS.gdk_window_begin_paint_rect (window, rect);
- int /*long*/ [] real_drawable = new int /*long*/ [1];
- int [] x_offset = new int [1], y_offset = new int [1];
- OS.gdk_window_get_internal_paint_info (window, real_drawable, x_offset, y_offset);
- int /*long*/ [] userData = new int /*long*/ [1];
- OS.gdk_window_get_user_data (window, userData);
- if (userData [0] != 0) {
- int /*long*/ eventPtr = OS.gdk_event_new (OS.GDK_EXPOSE);
- GdkEventExpose event = new GdkEventExpose ();
- event.type = OS.GDK_EXPOSE;
- event.window = OS.g_object_ref (window);
- event.area_width = rect.width;
- event.area_height = rect.height;
- event.region = OS.gdk_region_rectangle (rect);
- OS.memmove (eventPtr, event, GdkEventExpose.sizeof);
- OS.gtk_widget_send_expose (userData [0], eventPtr);
- OS.gdk_event_free (eventPtr);
- }
- int srcX = x_offset [0], srcY = y_offset [0];
- int destX = x, destY = y, destWidth = width [0], destHeight = height [0];
- if (!first) {
- int [] cX = new int [1], cY = new int [1];
- OS.gdk_window_get_position (window, cX, cY);
- int /*long*/ parentWindow = OS.gdk_window_get_parent (window);
- int [] pW = new int [1], pH = new int [1];
- OS.gdk_drawable_get_size (parentWindow, pW, pH);
- srcX = x_offset [0] - cX [0];
- srcY = y_offset [0] - cY [0];
- destX = x - cX [0];
- destY = y - cY [0];
- destWidth = Math.min (cX [0] + width [0], pW [0]);
- destHeight = Math.min (cY [0] + height [0], pH [0]);
- }
- GCData gcData = gc.getGCData();
- int /*long*/ cairo = gcData.cairo;
- if (cairo != 0) {
- int /*long*/ xDisplay = OS.GDK_DISPLAY();
- int /*long*/ xVisual = OS.gdk_x11_visual_get_xvisual(OS.gdk_visual_get_system());
- int /*long*/ xDrawable = OS.GDK_PIXMAP_XID(real_drawable [0]);
- int /*long*/ surface = Cairo.cairo_xlib_surface_create(xDisplay, xDrawable, xVisual, width [0], height [0]);
- if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Cairo.cairo_save(cairo);
- Cairo.cairo_rectangle(cairo, destX , destY, destWidth, destHeight);
- Cairo.cairo_clip(cairo);
- Cairo.cairo_translate(cairo, destX, destY);
- int /*long*/ pattern = Cairo.cairo_pattern_create_for_surface(surface);
- if (pattern == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Cairo.cairo_pattern_set_filter(pattern, Cairo.CAIRO_FILTER_BEST);
- Cairo.cairo_set_source(cairo, pattern);
- if (gcData.alpha != 0xFF) {
- Cairo.cairo_paint_with_alpha(cairo, gcData.alpha / (float)0xFF);
- } else {
- Cairo.cairo_paint(cairo);
- }
- Cairo.cairo_restore(cairo);
- Cairo.cairo_pattern_destroy(pattern);
- Cairo.cairo_surface_destroy(surface);
- } else {
- OS.gdk_draw_drawable (drawable, gc.handle, real_drawable [0], srcX, srcY, destX, destY, destWidth, destHeight);
- }
- OS.gdk_window_end_paint (window);
- int /*long*/ children = OS.gdk_window_get_children (window);
- if (children != 0) {
- int /*long*/ windows = children;
- while (windows != 0) {
- int /*long*/ child = OS.g_list_data (windows);
- if (OS.gdk_window_is_visible (child)) {
- int /*long*/ [] data = new int /*long*/ [1];
- OS.gdk_window_get_user_data (child, data);
- if (data [0] != 0) {
- Widget widget = display.findWidget (data [0]);
- if (widget == null || widget == control) {
- int [] x_pos = new int [1], y_pos = new int [1];
- OS.gdk_window_get_position (child, x_pos, y_pos);
- printWindow (false, control, gc, drawable, depth, child, x + x_pos [0], y + y_pos [0]);
- }
- }
- }
- windows = OS.g_list_next (windows);
- }
- OS.g_list_free (children);
- }
-}
-
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>preferred size</em> of a control is the size that it would
- * best be displayed at. The width hint and height hint arguments
- * allow the caller to ask a control questions such as "Given a particular
- * width, how high does the control need to be to show all of the contents?"
- * To indicate that the caller does not wish to constrain a particular
- * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
- * </p>
- *
- * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
- * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
- * @return the preferred size of the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Layout
- * @see #getBorderWidth
- * @see #getBounds
- * @see #getSize
- * @see #pack(boolean)
- * @see "computeTrim, getClientArea for controls that implement them"
- */
-public Point computeSize (int wHint, int hHint) {
- return computeSize (wHint, hHint, true);
-}
-
-Widget computeTabGroup () {
- if (isTabGroup()) return this;
- return parent.computeTabGroup ();
-}
-
-Widget[] computeTabList() {
- if (isTabGroup()) {
- if (getVisible() && getEnabled()) {
- return new Widget[] {this};
- }
- }
- return new Widget[0];
-}
-
-Control computeTabRoot () {
- Control[] tabList = parent._getTabList();
- if (tabList != null) {
- int index = 0;
- while (index < tabList.length) {
- if (tabList [index] == this) break;
- index++;
- }
- if (index == tabList.length) {
- if (isTabGroup ()) return this;
- }
- }
- return parent.computeTabRoot ();
-}
-
-void checkBuffered () {
- style |= SWT.DOUBLE_BUFFERED;
-}
-
-void checkBackground () {
- Shell shell = getShell ();
- if (this == shell) return;
- state &= ~PARENT_BACKGROUND;
- Composite composite = parent;
- do {
- int mode = composite.backgroundMode;
- if (mode != SWT.INHERIT_NONE) {
- if (mode == SWT.INHERIT_DEFAULT) {
- Control control = this;
- do {
- if ((control.state & THEME_BACKGROUND) == 0) {
- return;
- }
- control = control.parent;
- } while (control != composite);
- }
- state |= PARENT_BACKGROUND;
- return;
- }
- if (composite == shell) break;
- composite = composite.parent;
- } while (true);
-}
-
-void checkBorder () {
- if (getBorderWidth () == 0) style &= ~SWT.BORDER;
-}
-
-void checkMirrored () {
- if ((style & SWT.RIGHT_TO_LEFT) != 0) style |= SWT.MIRRORED;
-}
-
-int /*long*/ childStyle () {
- return parent.childStyle ();
-}
-
-void createWidget (int index) {
- state |= DRAG_DETECT;
- checkOrientation (parent);
- super.createWidget (index);
- checkBackground ();
- if ((state & PARENT_BACKGROUND) != 0) setBackground ();
- checkBuffered ();
- showWidget ();
- setInitialBounds ();
- setZOrder (null, false, false);
- setRelations ();
- checkMirrored ();
- checkBorder ();
-}
-
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>preferred size</em> of a control is the size that it would
- * best be displayed at. The width hint and height hint arguments
- * allow the caller to ask a control questions such as "Given a particular
- * width, how high does the control need to be to show all of the contents?"
- * To indicate that the caller does not wish to constrain a particular
- * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
- * </p><p>
- * If the changed flag is <code>true</code>, it indicates that the receiver's
- * <em>contents</em> have changed, therefore any caches that a layout manager
- * containing the control may have been keeping need to be flushed. When the
- * control is resized, the changed flag will be <code>false</code>, so layout
- * manager caches can be retained.
- * </p>
- *
- * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
- * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
- * @param changed <code>true</code> if the control's contents have changed, and <code>false</code> otherwise
- * @return the preferred size of the control.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Layout
- * @see #getBorderWidth
- * @see #getBounds
- * @see #getSize
- * @see #pack(boolean)
- * @see "computeTrim, getClientArea for controls that implement them"
- */
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- return computeNativeSize (handle, wHint, hHint, changed);
-}
-
-Point computeNativeSize (int /*long*/ h, int wHint, int hHint, boolean changed) {
- int width = wHint, height = hHint;
- if (wHint == SWT.DEFAULT && hHint == SWT.DEFAULT) {
- GtkRequisition requisition = new GtkRequisition ();
- gtk_widget_size_request (h, requisition);
- width = OS.GTK_WIDGET_REQUISITION_WIDTH (h);
- height = OS.GTK_WIDGET_REQUISITION_HEIGHT (h);
- } else if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
- int [] reqWidth = new int [1], reqHeight = new int [1];
- OS.gtk_widget_get_size_request (h, reqWidth, reqHeight);
- OS.gtk_widget_set_size_request (h, wHint, hHint);
- GtkRequisition requisition = new GtkRequisition ();
- gtk_widget_size_request (h, requisition);
- OS.gtk_widget_set_size_request (h, reqWidth [0], reqHeight [0]);
- width = wHint == SWT.DEFAULT ? requisition.width : wHint;
- height = hHint == SWT.DEFAULT ? requisition.height : hHint;
- }
- return new Point (width, height);
-}
-
-void forceResize () {
- /*
- * Force size allocation on all children of this widget's
- * topHandle. Note that all calls to gtk_widget_size_allocate()
- * must be preceded by a call to gtk_widget_size_request().
- */
- int /*long*/ topHandle = topHandle ();
- GtkRequisition requisition = new GtkRequisition ();
- gtk_widget_size_request (topHandle, requisition);
- GtkAllocation allocation = new GtkAllocation ();
- allocation.x = OS.GTK_WIDGET_X (topHandle);
- allocation.y = OS.GTK_WIDGET_Y (topHandle);
- allocation.width = OS.GTK_WIDGET_WIDTH (topHandle);
- allocation.height = OS.GTK_WIDGET_HEIGHT (topHandle);
- OS.gtk_widget_size_allocate (topHandle, allocation);
-}
-
-/**
- * Returns the accessible object for the receiver.
- * If this is the first time this object is requested,
- * then the object is created and returned.
- *
- * @return the accessible object
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Accessible#addAccessibleListener
- * @see Accessible#addAccessibleControlListener
- *
- * @since 2.0
- */
-public Accessible getAccessible () {
- checkWidget ();
- if (accessible == null) {
- accessible = Accessible.internal_new_Accessible (this);
- }
- return accessible;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null),
- * unless the receiver is a shell. In this case, the location is
- * relative to the display.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- int /*long*/ topHandle = topHandle ();
- int x = OS.GTK_WIDGET_X (topHandle);
- int y = OS.GTK_WIDGET_Y (topHandle);
- int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle);
- int height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (topHandle);
- if ((parent.style & SWT.MIRRORED) != 0) x = parent.getClientWidth () - width - x;
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the argument. The <code>x</code> and
- * <code>y</code> fields of the rectangle are relative to
- * the receiver's parent (or its display if its parent is null).
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param rect the new bounds for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (Rectangle rect) {
- checkWidget ();
- if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (rect.x, rect.y, Math.max (0, rect.width), Math.max (0, rect.height), true, true);
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the arguments. The <code>x</code> and
- * <code>y</code> arguments are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the <code>x</code>
- * and <code>y</code> arguments are relative to the display.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (int x, int y, int width, int height) {
- checkWidget();
- setBounds (x, y, Math.max (0, width), Math.max (0, height), true, true);
-}
-
-void markLayout (boolean changed, boolean all) {
- /* Do nothing */
-}
-
-void modifyStyle (int /*long*/ handle, int /*long*/ style) {
- super.modifyStyle(handle, style);
- /*
- * Bug in GTK. When changing the style of a control that
- * has had a region set on it, the region is lost. The
- * fix is to set the region again.
- */
- if (region != null) OS.gdk_window_shape_combine_region (OS.GTK_WIDGET_WINDOW (topHandle ()), region.handle, 0, 0);
-}
-
-void moveHandle (int x, int y) {
- int /*long*/ topHandle = topHandle ();
- int /*long*/ parentHandle = parent.parentingHandle ();
- /*
- * Feature in GTK. Calling gtk_fixed_move() to move a child causes
- * the whole parent to redraw. This is a performance problem. The
- * fix is temporarily make the parent not visible during the move.
- *
- * NOTE: Because every widget in SWT has an X window, the new and
- * old bounds of the child are correctly redrawn.
- */
- int flags = OS.GTK_WIDGET_FLAGS (parentHandle);
- OS.GTK_WIDGET_UNSET_FLAGS (parentHandle, OS.GTK_VISIBLE);
- OS.gtk_fixed_move (parentHandle, topHandle, x, y);
- if ((flags & OS.GTK_VISIBLE) != 0) {
- OS.GTK_WIDGET_SET_FLAGS (parentHandle, OS.GTK_VISIBLE);
- }
-}
-
-void resizeHandle (int width, int height) {
- int /*long*/ topHandle = topHandle ();
- OS.gtk_widget_set_size_request (topHandle, width, height);
- if (topHandle != handle) OS.gtk_widget_set_size_request (handle, width, height);
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- int /*long*/ topHandle = topHandle ();
- boolean sendMove = move;
- if ((parent.style & SWT.MIRRORED) != 0) {
- int clientWidth = parent.getClientWidth ();
- int oldWidth = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle);
- int oldX = clientWidth - oldWidth - OS.GTK_WIDGET_X (topHandle);
- if (move) {
- sendMove &= x != oldX;
- x = clientWidth - (resize ? width : oldWidth) - x;
- } else {
- move = true;
- x = clientWidth - (resize ? width : oldWidth) - oldX;
- y = OS.GTK_WIDGET_Y (topHandle);
- }
- }
- boolean sameOrigin = true, sameExtent = true;
- if (move) {
- int oldX = OS.GTK_WIDGET_X (topHandle);
- int oldY = OS.GTK_WIDGET_Y (topHandle);
- sameOrigin = x == oldX && y == oldY;
- if (!sameOrigin) {
- if (enableWindow != 0) {
- OS.gdk_window_move (enableWindow, x, y);
- }
- moveHandle (x, y);
- }
- }
- int clientWidth = 0;
- if (resize) {
- int oldWidth = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle);
- int oldHeight = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (topHandle);
- sameExtent = width == oldWidth && height == oldHeight;
- if (!sameExtent && (style & SWT.MIRRORED) != 0) clientWidth = getClientWidth ();
- if (!sameExtent && !(width == 0 && height == 0)) {
- int newWidth = Math.max (1, width);
- int newHeight = Math.max (1, height);
- if (redrawWindow != 0) {
- OS.gdk_window_resize (redrawWindow, newWidth, newHeight);
- }
- if (enableWindow != 0) {
- OS.gdk_window_resize (enableWindow, newWidth, newHeight);
- }
- resizeHandle (newWidth, newHeight);
- }
- }
- if (!sameOrigin || !sameExtent) {
- /*
- * Cause a size allocation this widget's topHandle. Note that
- * all calls to gtk_widget_size_allocate() must be preceded by
- * a call to gtk_widget_size_request().
- */
- GtkRequisition requisition = new GtkRequisition ();
- gtk_widget_size_request (topHandle, requisition);
- GtkAllocation allocation = new GtkAllocation ();
- if (move) {
- allocation.x = x;
- allocation.y = y;
- } else {
- allocation.x = OS.GTK_WIDGET_X (topHandle);
- allocation.y = OS.GTK_WIDGET_Y (topHandle);
- }
- if (resize) {
- allocation.width = width;
- allocation.height = height;
- } else {
- allocation.width = OS.GTK_WIDGET_WIDTH (topHandle);
- allocation.height = OS.GTK_WIDGET_HEIGHT (topHandle);
- }
- OS.gtk_widget_size_allocate (topHandle, allocation);
- }
- /*
- * Bug in GTK. Widgets cannot be sized smaller than 1x1.
- * The fix is to hide zero-sized widgets and show them again
- * when they are resized larger.
- */
- if (!sameExtent) {
- state = (width == 0) ? state | ZERO_WIDTH : state & ~ZERO_WIDTH;
- state = (height == 0) ? state | ZERO_HEIGHT : state & ~ZERO_HEIGHT;
- if ((state & (ZERO_WIDTH | ZERO_HEIGHT)) != 0) {
- if (enableWindow != 0) {
- OS.gdk_window_hide (enableWindow);
- }
- OS.gtk_widget_hide (topHandle);
- } else {
- if ((state & HIDDEN) == 0) {
- if (enableWindow != 0) {
- OS.gdk_window_show_unraised (enableWindow);
- }
- OS.gtk_widget_show (topHandle);
- }
- }
- if ((style & SWT.MIRRORED) != 0) moveChildren (clientWidth);
- }
- int result = 0;
- if (move && !sameOrigin) {
- Control control = findBackgroundControl ();
- if (control != null && control.backgroundImage != null) {
- if (isVisible ()) redrawWidget (0, 0, 0, 0, true, true, true);
- }
- if (sendMove) sendEvent (SWT.Move);
- result |= MOVED;
- }
- if (resize && !sameExtent) {
- sendEvent (SWT.Resize);
- result |= RESIZED;
- }
- return result;
-}
-
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @return the receiver's location
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getLocation () {
- checkWidget();
- int /*long*/ topHandle = topHandle ();
- int x = OS.GTK_WIDGET_X (topHandle);
- int y = OS.GTK_WIDGET_Y (topHandle);
- if ((parent.style & SWT.MIRRORED) != 0) {
- int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle);
- x = parent.getClientWidth () - width - x;
- }
- return new Point (x, y);
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @param location the new location for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (Point location) {
- checkWidget ();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (location.x, location.y, 0, 0, true, false);
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation(int x, int y) {
- checkWidget();
- setBounds (x, y, 0, 0, true, false);
-}
-
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- int /*long*/ topHandle = topHandle ();
- int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle);
- int height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (topHandle);
- return new Point (width, height);
-}
-
-/**
- * Sets the receiver's size to the point specified by the argument.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause them to be
- * set to zero instead.
- * </p>
- *
- * @param size the new size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (Point size) {
- checkWidget ();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (0, 0, Math.max (0, size.x), Math.max (0, size.y), false, true);
-}
-
-/**
- * Sets the shape of the control to the region specified
- * by the argument. When the argument is null, the
- * default shape of the control is restored.
- *
- * @param region the region that defines the shape of the control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setRegion (Region region) {
- checkWidget ();
- if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (topHandle ());
- int /*long*/ shape_region = (region == null) ? 0 : region.handle;
- OS.gdk_window_shape_combine_region (window, shape_region, 0, 0);
- this.region = region;
-}
-
-void setRelations () {
- int /*long*/ parentHandle = parent.parentingHandle ();
- int /*long*/ list = OS.gtk_container_get_children (parentHandle);
- if (list == 0) return;
- int count = OS.g_list_length (list);
- if (count > 1) {
- /*
- * the receiver is the last item in the list, so its predecessor will
- * be the second-last item in the list
- */
- int /*long*/ handle = OS.g_list_nth_data (list, count - 2);
- if (handle != 0) {
- Widget widget = display.getWidget (handle);
- if (widget != null && widget != this) {
- if (widget instanceof Control) {
- Control sibling = (Control)widget;
- sibling.addRelation (this);
- }
- }
- }
- }
- OS.g_list_free (list);
-}
-
-/**
- * Sets the receiver's size to the point specified by the arguments.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (int width, int height) {
- checkWidget();
- setBounds (0, 0, Math.max (0, width), Math.max (0, height), false, true);
-}
-
-
-boolean isActive () {
- return getShell ().getModalShell () == null && display.getModalDialog () == null;
-}
-
-/*
- * Answers a boolean indicating whether a Label that precedes the receiver in
- * a layout should be read by screen readers as the recevier's label.
- */
-boolean isDescribedByLabel () {
- return true;
-}
-
-boolean isFocusHandle (int /*long*/ widget) {
- return widget == focusHandle ();
-}
-
-/**
- * Moves the receiver above the specified control in the
- * drawing order. If the argument is null, then the receiver
- * is moved to the top of the drawing order. The control at
- * the top of the drawing order will not be covered by other
- * controls even if they occupy intersecting areas.
- *
- * @param control the sibling control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveBelow
- * @see Composite#getChildren
- */
-public void moveAbove (Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- }
- setZOrder (control, true, true);
-}
-
-/**
- * Moves the receiver below the specified control in the
- * drawing order. If the argument is null, then the receiver
- * is moved to the bottom of the drawing order. The control at
- * the bottom of the drawing order will be covered by all other
- * controls which occupy intersecting areas.
- *
- * @param control the sibling control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveAbove
- * @see Composite#getChildren
- */
-public void moveBelow (Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- }
- setZOrder (control, false, true);
-}
-
-void moveChildren (int oldWidth) {
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeSize(int, int, boolean)
- */
-public void pack () {
- pack (true);
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- * <p>
- * If the changed flag is <code>true</code>, it indicates that the receiver's
- * <em>contents</em> have changed, therefore any caches that a layout manager
- * containing the control may have been keeping need to be flushed. When the
- * control is resized, the changed flag will be <code>false</code>, so layout
- * manager caches can be retained.
- * </p>
- *
- * @param changed whether or not the receiver's contents have changed
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeSize(int, int, boolean)
- */
-public void pack (boolean changed) {
- setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed));
-}
-
-/**
- * Sets the layout data associated with the receiver to the argument.
- *
- * @param layoutData the new layout data for the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLayoutData (Object layoutData) {
- checkWidget();
- this.layoutData = layoutData;
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in display relative coordinates,
- * to coordinates relative to the receiver.
- * <p>
- * @param x the x coordinate to be translated
- * @param y the y coordinate to be translated
- * @return the translated coordinates
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public Point toControl (int x, int y) {
- checkWidget ();
- int /*long*/ window = eventWindow ();
- int [] origin_x = new int [1], origin_y = new int [1];
- OS.gdk_window_get_origin (window, origin_x, origin_y);
- x -= origin_x [0];
- y -= origin_y [0];
- if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x;
- return new Point (x, y);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in display relative coordinates,
- * to coordinates relative to the receiver.
- * <p>
- * @param point the point to be translated (must not be null)
- * @return the translated coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point toControl (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return toControl (point.x, point.y);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in coordinates relative to
- * the receiver, to display relative coordinates.
- * <p>
- * @param x the x coordinate to be translated
- * @param y the y coordinate to be translated
- * @return the translated coordinates
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public Point toDisplay (int x, int y) {
- checkWidget();
- int /*long*/ window = eventWindow ();
- int [] origin_x = new int [1], origin_y = new int [1];
- OS.gdk_window_get_origin (window, origin_x, origin_y);
- if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x;
- x += origin_x [0];
- y += origin_y [0];
- return new Point (x, y);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in coordinates relative to
- * the receiver, to display relative coordinates.
- * <p>
- * @param point the point to be translated (must not be null)
- * @return the translated coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point toDisplay (Point point) {
- checkWidget();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return toDisplay (point.x, point.y);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize,typedListener);
- addListener (SWT.Move,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when a drag gesture occurs, by sending it
- * one of the messages defined in the <code>DragDetectListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #removeDragDetectListener
- *
- * @since 3.3
- */
-public void addDragDetectListener (DragDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.DragDetect,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control gains or loses focus, by sending
- * it one of the messages defined in the <code>FocusListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see FocusListener
- * @see #removeFocusListener
- */
-public void addFocusListener(FocusListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.FocusIn,typedListener);
- addListener(SWT.FocusOut,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when help events are generated for the control,
- * by sending it one of the messages defined in the
- * <code>HelpListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard, by sending
- * it one of the messages defined in the <code>KeyListener</code>
- * interface.
- * <p>
- * When a key listener is added to a control, the control
- * will take part in widget traversal. By default, all
- * traversal keys (such as the tab key and so on) are
- * delivered to the control. In order for a control to take
- * part in traversal, it should listen for traversal events.
- * Otherwise, the user can traverse into a control but not
- * out. Note that native controls such as table and tree
- * implement key traversal in the operating system. It is
- * not necessary to add traversal listeners for these controls,
- * unless you want to override the default traversal.
- * </p>
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #removeKeyListener
- */
-public void addKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.KeyUp,typedListener);
- addListener(SWT.KeyDown,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the platform-specific context menu trigger
- * has occurred, by sending it one of the messages defined in
- * the <code>MenuDetectListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #removeMenuDetectListener
- *
- * @since 3.3
- */
-public void addMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MenuDetect, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when mouse buttons are pressed and released, by sending
- * it one of the messages defined in the <code>MouseListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseListener
- * @see #removeMouseListener
- */
-public void addMouseListener(MouseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.MouseDown,typedListener);
- addListener(SWT.MouseUp,typedListener);
- addListener(SWT.MouseDoubleClick,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse moves, by sending it one of the
- * messages defined in the <code>MouseMoveListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseMoveListener
- * @see #removeMouseMoveListener
- */
-public void addMouseMoveListener(MouseMoveListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.MouseMove,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse passes or hovers over controls, by sending
- * it one of the messages defined in the <code>MouseTrackListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseTrackListener
- * @see #removeMouseTrackListener
- */
-public void addMouseTrackListener (MouseTrackListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseEnter,typedListener);
- addListener (SWT.MouseExit,typedListener);
- addListener (SWT.MouseHover,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse wheel is scrolled, by sending
- * it one of the messages defined in the
- * <code>MouseWheelListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseWheelListener
- * @see #removeMouseWheelListener
- *
- * @since 3.3
- */
-public void addMouseWheelListener (MouseWheelListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseWheel, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver needs to be painted, by sending it
- * one of the messages defined in the <code>PaintListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see PaintListener
- * @see #removePaintListener
- */
-public void addPaintListener(PaintListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.Paint,typedListener);
-}
-
-void addRelation (Control control) {
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when traversal events occur, by sending it
- * one of the messages defined in the <code>TraverseListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TraverseListener
- * @see #removeTraverseListener
- */
-public void addTraverseListener (TraverseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Traverse,typedListener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when a drag gesture occurs.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @since 3.3
- */
-public void removeDragDetectListener(DragDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.DragDetect, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control gains or loses focus.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see FocusListener
- * @see #addFocusListener
- */
-public void removeFocusListener(FocusListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.FocusIn, listener);
- eventTable.unhook (SWT.FocusOut, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #addKeyListener
- */
-public void removeKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.KeyUp, listener);
- eventTable.unhook (SWT.KeyDown, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the platform-specific context menu trigger has
- * occurred.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #addMenuDetectListener
- *
- * @since 3.3
- */
-public void removeMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MenuDetect, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when mouse buttons are pressed and released.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseListener
- * @see #addMouseListener
- */
-public void removeMouseListener (MouseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseDown, listener);
- eventTable.unhook (SWT.MouseUp, listener);
- eventTable.unhook (SWT.MouseDoubleClick, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse moves.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseMoveListener
- * @see #addMouseMoveListener
- */
-public void removeMouseMoveListener(MouseMoveListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseMove, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse passes or hovers over controls.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseTrackListener
- * @see #addMouseTrackListener
- */
-public void removeMouseTrackListener(MouseTrackListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseEnter, listener);
- eventTable.unhook (SWT.MouseExit, listener);
- eventTable.unhook (SWT.MouseHover, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse wheel is scrolled.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseWheelListener
- * @see #addMouseWheelListener
- *
- * @since 3.3
- */
-public void removeMouseWheelListener (MouseWheelListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseWheel, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver needs to be painted.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see PaintListener
- * @see #addPaintListener
- */
-public void removePaintListener(PaintListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Paint, listener);
-}
-
-/*
- * Remove "Labelled by" relations from the receiver.
- */
-void removeRelation () {
- if (!isDescribedByLabel ()) return; /* there will not be any */
- int /*long*/ accessible = OS.gtk_widget_get_accessible (handle);
- if (accessible == 0) return;
- int /*long*/ set = ATK.atk_object_ref_relation_set (accessible);
- int count = ATK.atk_relation_set_get_n_relations (set);
- for (int i = 0; i < count; i++) {
- int /*long*/ relation = ATK.atk_relation_set_get_relation (set, 0);
- ATK.atk_relation_set_remove (set, relation);
- }
- OS.g_object_unref (set);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when traversal events occur.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TraverseListener
- * @see #addTraverseListener
- */
-public void removeTraverseListener(TraverseListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Traverse, listener);
-}
-
-/**
- * Detects a drag and drop gesture. This method is used
- * to detect a drag gesture when called from within a mouse
- * down listener.
- *
- * <p>By default, a drag is detected when the gesture
- * occurs anywhere within the client area of a control.
- * Some controls, such as tables and trees, override this
- * behavior. In addition to the operating system specific
- * drag gesture, they require the mouse to be inside an
- * item. Custom widget writers can use <code>setDragDetect</code>
- * to disable the default detection, listen for mouse down,
- * and then call <code>dragDetect()</code> from within the
- * listener to conditionally detect a drag.
- * </p>
- *
- * @param event the mouse down event
- *
- * @return <code>true</code> if the gesture occurred, and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT when the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @see #getDragDetect
- * @see #setDragDetect
- *
- * @since 3.3
- */
-public boolean dragDetect (Event event) {
- checkWidget ();
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- return dragDetect (event.button, event.count, event.stateMask, event.x, event.y);
-}
-
-/**
- * Detects a drag and drop gesture. This method is used
- * to detect a drag gesture when called from within a mouse
- * down listener.
- *
- * <p>By default, a drag is detected when the gesture
- * occurs anywhere within the client area of a control.
- * Some controls, such as tables and trees, override this
- * behavior. In addition to the operating system specific
- * drag gesture, they require the mouse to be inside an
- * item. Custom widget writers can use <code>setDragDetect</code>
- * to disable the default detection, listen for mouse down,
- * and then call <code>dragDetect()</code> from within the
- * listener to conditionally detect a drag.
- * </p>
- *
- * @param event the mouse down event
- *
- * @return <code>true</code> if the gesture occurred, and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT when the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @see #getDragDetect
- * @see #setDragDetect
- *
- * @since 3.3
- */
-public boolean dragDetect (MouseEvent event) {
- checkWidget ();
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- return dragDetect (event.button, event.count, event.stateMask, event.x, event.y);
-}
-
-boolean dragDetect (int button, int count, int stateMask, int x, int y) {
- if (button != 1 || count != 1) return false;
- if (!dragDetect (x, y, false, null)) return false;
- return sendDragEvent (button, stateMask, x, y, true);
-}
-
-boolean dragDetect (int x, int y, boolean filter, boolean [] consume) {
- boolean quit = false, dragging = false;
- while (!quit) {
- int /*long*/ eventPtr = 0;
- /*
- * There should be an event on the queue already, but
- * in cases where there isn't one, stop trying after
- * half a second.
- */
- long timeout = System.currentTimeMillis() + 500;
- while (System.currentTimeMillis() < timeout) {
- eventPtr = OS.gdk_event_get ();
- if (eventPtr != 0) {
- break;
- } else {
- try {Thread.sleep(50);} catch (Exception ex) {}
- }
- }
- if (eventPtr == 0) return false;
- switch (OS.GDK_EVENT_TYPE (eventPtr)) {
- case OS.GDK_MOTION_NOTIFY: {
- GdkEventMotion gdkMotionEvent = new GdkEventMotion ();
- OS.memmove (gdkMotionEvent, eventPtr, GdkEventMotion.sizeof);
- if ((gdkMotionEvent.state & OS.GDK_BUTTON1_MASK) != 0) {
- if (OS.gtk_drag_check_threshold (handle, x, y, (int) gdkMotionEvent.x, (int) gdkMotionEvent.y)) {
- dragging = true;
- quit = true;
- }
- } else {
- quit = true;
- }
- int [] newX = new int [1], newY = new int [1];
- OS.gdk_window_get_pointer (gdkMotionEvent.window, newX, newY, null);
- break;
- }
- case OS.GDK_KEY_PRESS:
- case OS.GDK_KEY_RELEASE: {
- GdkEventKey gdkEvent = new GdkEventKey ();
- OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof);
- if (gdkEvent.keyval == OS.GDK_Escape) quit = true;
- break;
- }
- case OS.GDK_BUTTON_RELEASE:
- case OS.GDK_BUTTON_PRESS:
- case OS.GDK_2BUTTON_PRESS:
- case OS.GDK_3BUTTON_PRESS: {
- OS.gdk_event_put (eventPtr);
- quit = true;
- break;
- }
- default:
- OS.gtk_main_do_event (eventPtr);
- }
- OS.gdk_event_free (eventPtr);
- }
- return dragging;
-}
-
-boolean filterKey (int keyval, int /*long*/ event) {
- int /*long*/ imHandle = imHandle ();
- if (imHandle != 0) {
- return OS.gtk_im_context_filter_keypress (imHandle, event);
- }
- return false;
-}
-
-Control findBackgroundControl () {
- if ((state & BACKGROUND) != 0 || backgroundImage != null) return this;
- return (state & PARENT_BACKGROUND) != 0 ? parent.findBackgroundControl () : null;
-}
-
-Menu [] findMenus (Control control) {
- if (menu != null && this != control) return new Menu [] {menu};
- return new Menu [0];
-}
-
-void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) {
- oldShell.fixShell (newShell, this);
- oldDecorations.fixDecorations (newDecorations, this, menus);
-}
-
-int /*long*/ fixedMapProc (int /*long*/ widget) {
- OS.GTK_WIDGET_SET_FLAGS (widget, OS.GTK_MAPPED);
- int /*long*/ widgetList = OS.gtk_container_get_children (widget);
- if (widgetList != 0) {
- int /*long*/ widgets = widgetList;
- while (widgets != 0) {
- int /*long*/ child = OS.g_list_data (widgets);
- if (OS.GTK_WIDGET_VISIBLE (child) && OS.gtk_widget_get_child_visible (child) && !OS.GTK_WIDGET_MAPPED (child)) {
- OS.gtk_widget_map (child);
- }
- widgets = OS.g_list_next (widgets);
- }
- OS.g_list_free (widgetList);
- }
- if ((OS.GTK_WIDGET_FLAGS (widget) & OS.GTK_NO_WINDOW) == 0) {
- OS.gdk_window_show_unraised (OS.GTK_WIDGET_WINDOW (widget));
- }
- return 0;
-}
-
-void fixModal(int /*long*/ group, int /*long*/ modalGroup) {
-}
-
-/**
- * Forces the receiver to have the <em>keyboard focus</em>, causing
- * all keyboard events to be delivered to it.
- *
- * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setFocus
- */
-public boolean forceFocus () {
- checkWidget();
- if (display.focusEvent == SWT.FocusOut) return false;
- Shell shell = getShell ();
- shell.setSavedFocus (this);
- if (!isEnabled () || !isVisible ()) return false;
- shell.bringToTop (false);
- return forceFocus (focusHandle ());
-}
-
-boolean forceFocus (int /*long*/ focusHandle) {
- if (OS.GTK_WIDGET_HAS_FOCUS (focusHandle)) return true;
- /* When the control is zero sized it must be realized */
- OS.gtk_widget_realize (focusHandle);
- OS.gtk_widget_grab_focus (focusHandle);
- Shell shell = getShell ();
- int /*long*/ shellHandle = shell.shellHandle;
- int /*long*/ handle = OS.gtk_window_get_focus (shellHandle);
- while (handle != 0) {
- if (handle == focusHandle) {
- /* Cancel any previous ignoreFocus requests */
- display.ignoreFocus = false;
- return true;
- }
- Widget widget = display.getWidget (handle);
- if (widget != null && widget instanceof Control) {
- return widget == this;
- }
- handle = OS.gtk_widget_get_parent (handle);
- }
- return false;
-}
-
-/**
- * Returns the receiver's background color.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on some versions of Windows the background of a TabFolder,
- * is a gradient rather than a solid color.
- * </p>
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Color getBackground () {
- checkWidget();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- return Color.gtk_new (display, control.getBackgroundColor ());
-}
-
-GdkColor getBackgroundColor () {
- return getBgColor ();
-}
-
-/**
- * Returns the receiver's background image.
- *
- * @return the background image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Image getBackgroundImage () {
- checkWidget ();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- return control.backgroundImage;
-}
-
-GdkColor getBgColor () {
- int /*long*/ fontHandle = fontHandle ();
- OS.gtk_widget_realize (fontHandle);
- GdkColor color = new GdkColor ();
- OS.gtk_style_get_bg (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color);
- return color;
-}
-
-GdkColor getBaseColor () {
- int /*long*/ fontHandle = fontHandle ();
- OS.gtk_widget_realize (fontHandle);
- GdkColor color = new GdkColor ();
- OS.gtk_style_get_base (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color);
- return color;
-}
-
-/**
- * Returns the receiver's border width.
- *
- * @return the border width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getBorderWidth () {
- checkWidget();
- return 0;
-}
-
-int getClientWidth () {
- return 0;
-}
-
-/**
- * Returns the receiver's cursor, or null if it has not been set.
- * <p>
- * When the mouse pointer passes over a control its appearance
- * is changed to match the control's cursor.
- * </p>
- *
- * @return the receiver's cursor or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Cursor getCursor () {
- checkWidget ();
- return cursor;
-}
-
-public Object getData(String key) {
- if (key.equals(IS_ACTIVE)) return new Boolean(isActive ());
- return super.getData(key);
-}
-
-/**
- * Returns <code>true</code> if the receiver is detecting
- * drag gestures, and <code>false</code> otherwise.
- *
- * @return the receiver's drag detect state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public boolean getDragDetect () {
- checkWidget ();
- return (state & DRAG_DETECT) != 0;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget ();
- return (state & DISABLED) == 0;
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Font getFont () {
- checkWidget();
- return font != null ? font : defaultFont ();
-}
-
-int /*long*/ getFontDescription () {
- int /*long*/ fontHandle = fontHandle ();
- OS.gtk_widget_realize (fontHandle);
- return OS.gtk_style_get_font_desc (OS.gtk_widget_get_style (fontHandle));
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Color getForeground () {
- checkWidget();
- return Color.gtk_new (display, getForegroundColor ());
-}
-
-GdkColor getForegroundColor () {
- return getFgColor ();
-}
-
-GdkColor getFgColor () {
- int /*long*/ fontHandle = fontHandle ();
- OS.gtk_widget_realize (fontHandle);
- GdkColor color = new GdkColor ();
- OS.gtk_style_get_fg (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color);
- return color;
-}
-
-Point getIMCaretPos () {
- return new Point (0, 0);
-}
-
-GdkColor getTextColor () {
- int /*long*/ fontHandle = fontHandle ();
- OS.gtk_widget_realize (fontHandle);
- GdkColor color = new GdkColor ();
- OS.gtk_style_get_text (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color);
- return color;
-}
-
-/**
- * Returns layout data which is associated with the receiver.
- *
- * @return the receiver's layout data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Object getLayoutData () {
- checkWidget();
- return layoutData;
-}
-
-/**
- * Returns the receiver's pop up menu if it has one, or null
- * if it does not. All controls may optionally have a pop up
- * menu that is displayed when the user requests one for
- * the control. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pop up
- * menu is platform specific.
- *
- * @return the receiver's menu
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenu () {
- checkWidget();
- return menu;
-}
-
-/**
- * Returns the receiver's monitor.
- *
- * @return the receiver's monitor
- *
- * @since 3.0
- */
-public Monitor getMonitor () {
- checkWidget();
- Monitor monitor = null;
- int /*long*/ screen = OS.gdk_screen_get_default ();
- if (screen != 0) {
- int monitorNumber = OS.gdk_screen_get_monitor_at_window (screen, paintWindow ());
- GdkRectangle dest = new GdkRectangle ();
- OS.gdk_screen_get_monitor_geometry (screen, monitorNumber, dest);
- monitor = new Monitor ();
- monitor.handle = monitorNumber;
- monitor.x = dest.x;
- monitor.y = dest.y;
- monitor.width = dest.width;
- monitor.height = dest.height;
- Rectangle workArea = null;
- if (monitorNumber == 0) workArea = display.getWorkArea ();
- if (workArea != null) {
- monitor.clientX = workArea.x;
- monitor.clientY = workArea.y;
- monitor.clientWidth = workArea.width;
- monitor.clientHeight = workArea.height;
- } else {
- monitor.clientX = monitor.x;
- monitor.clientY = monitor.y;
- monitor.clientWidth = monitor.width;
- monitor.clientHeight = monitor.height;
- }
- } else {
- monitor = display.getPrimaryMonitor ();
- }
- return monitor;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Composite</code>
- * or null when the receiver is a shell that was created with null or
- * a display for a parent.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Composite getParent () {
- checkWidget();
- return parent;
-}
-
-Control [] getPath () {
- int count = 0;
- Shell shell = getShell ();
- Control control = this;
- while (control != shell) {
- count++;
- control = control.parent;
- }
- control = this;
- Control [] result = new Control [count];
- while (control != shell) {
- result [--count] = control;
- control = control.parent;
- }
- return result;
-}
-
-/**
- * Returns the region that defines the shape of the control,
- * or null if the control has the default shape.
- *
- * @return the region that defines the shape of the shell (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public Region getRegion () {
- checkWidget ();
- return region;
-}
-
-/**
- * Returns the receiver's shell. For all controls other than
- * shells, this simply returns the control's nearest ancestor
- * shell. Shells return themselves, even if they are children
- * of other shells.
- *
- * @return the receiver's shell
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getParent
- */
-public Shell getShell() {
- checkWidget();
- return _getShell();
-}
-
-Shell _getShell() {
- return parent._getShell();
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- return (state & HIDDEN) == 0;
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) {
- return gtk_button_press_event (widget, event, true);
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event, boolean sendMouseDown) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
- if (gdkEvent.type == OS.GDK_3BUTTON_PRESS) return 0;
-
- /*
- * When a shell is created with SWT.ON_TOP and SWT.NO_FOCUS,
- * do not activate the shell when the user clicks on the
- * the client area or on the border or a control within the
- * shell that does not take focus.
- */
- Shell shell = _getShell ();
- if (((shell.style & SWT.ON_TOP) != 0) && (((shell.style & SWT.NO_FOCUS) == 0) || ((style & SWT.NO_FOCUS) == 0))) {
- shell.forceActive();
- }
- int /*long*/ result = 0;
- if (gdkEvent.type == OS.GDK_BUTTON_PRESS) {
- display.clickCount = 1;
- int /*long*/ nextEvent = OS.gdk_event_peek ();
- if (nextEvent != 0) {
- int eventType = OS.GDK_EVENT_TYPE (nextEvent);
- if (eventType == OS.GDK_2BUTTON_PRESS) display.clickCount = 2;
- if (eventType == OS.GDK_3BUTTON_PRESS) display.clickCount = 3;
- OS.gdk_event_free (nextEvent);
- }
- boolean dragging = false;
- if ((state & DRAG_DETECT) != 0 && hooks (SWT.DragDetect)) {
- if (gdkEvent.button == 1) {
- boolean [] consume = new boolean [1];
- if (dragDetect ((int) gdkEvent.x, (int) gdkEvent.y, true, consume)) {
- dragging = true;
- if (consume [0]) result = 1;
- }
- if (isDisposed ()) return 1;
- }
- }
- if (sendMouseDown && !sendMouseEvent (SWT.MouseDown, gdkEvent.button, display.clickCount, 0, false, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state)) {
- result = 1;
- }
- if (isDisposed ()) return 1;
- if (dragging) {
- sendDragEvent (gdkEvent.button, gdkEvent.state, (int) gdkEvent.x, (int) gdkEvent.y, false);
- if (isDisposed ()) return 1;
- }
- /*
- * Pop up the context menu in the button press event for widgets
- * that have default operating system menus in order to stop the
- * operating system from displaying the menu if necessary.
- */
- if ((state & MENU) != 0) {
- if (gdkEvent.button == 3) {
- if (showMenu ((int)gdkEvent.x_root, (int)gdkEvent.y_root)) {
- result = 1;
- }
- }
- }
- } else {
- display.clickCount = 2;
- result = sendMouseEvent (SWT.MouseDoubleClick, gdkEvent.button, display.clickCount, 0, false, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
- if (isDisposed ()) return 1;
- }
- if (!shell.isDisposed ()) shell.setActiveControl (this);
- return result;
-}
-
-int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ event) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
- /*
- * Feature in GTK. When button 4, 5, 6, or 7 is released, GTK
- * does not deliver a corresponding GTK event. Button 6 and 7
- * are mapped to buttons 4 and 5 in SWT. The fix is to change
- * the button number of the event to a negative number so that
- * it gets dispatched by GTK. SWT has been modified to look
- * for negative button numbers.
- */
- int button = gdkEvent.button;
- switch (button) {
- case -6: button = 4; break;
- case -7: button = 5; break;
- }
- return sendMouseEvent (SWT.MouseUp, button, display.clickCount, 0, false, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
-}
-
-int /*long*/ gtk_commit (int /*long*/ imcontext, int /*long*/ text) {
- if (text == 0) return 0;
- int length = OS.strlen (text);
- if (length == 0) return 0;
- byte [] buffer = new byte [length];
- OS.memmove (buffer, text, length);
- char [] chars = Converter.mbcsToWcs (null, buffer);
- sendIMKeyEvent (SWT.KeyDown, null, chars);
- return 0;
-}
-
-int /*long*/ gtk_enter_notify_event (int /*long*/ widget, int /*long*/ event) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0)) {
- /*
- * Feature in GTK. Children of a shell will inherit and display the shell's
- * tooltip if they do not have a tooltip of their own. The fix is to use the
- * new tooltip API in GTK 2.12 to null the shell's tooltip when the control
- * being entered does not have any tooltip text set.
- */
- byte [] buffer = null;
- if (toolTipText != null && toolTipText.length() != 0) {
- char [] chars = fixMnemonic (toolTipText, false);
- buffer = Converter.wcsToMbcs (null, chars, true);
- }
- int /*long*/ toolHandle = getShell().handle;
- OS.gtk_widget_set_tooltip_text (toolHandle, buffer);
- }
- if (display.currentControl == this) return 0;
- GdkEventCrossing gdkEvent = new GdkEventCrossing ();
- OS.memmove (gdkEvent, event, GdkEventCrossing.sizeof);
- /*
- * It is possible to send out too many enter/exit events if entering a
- * control through a subwindow. The fix is to return without sending any
- * events if the GdkEventCrossing subwindow field is set and the control
- * requests to check the field.
- */
- if (gdkEvent.subwindow != 0 && checkSubwindow ()) return 0;
- if (gdkEvent.mode != OS.GDK_CROSSING_NORMAL && gdkEvent.mode != OS.GDK_CROSSING_UNGRAB) return 0;
- if ((gdkEvent.state & (OS.GDK_BUTTON1_MASK | OS.GDK_BUTTON2_MASK | OS.GDK_BUTTON3_MASK)) != 0) return 0;
- if (display.currentControl != null && !display.currentControl.isDisposed ()) {
- display.removeMouseHoverTimeout (display.currentControl.handle);
- display.currentControl.sendMouseEvent (SWT.MouseExit, 0, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state);
- }
- if (!isDisposed ()) {
- display.currentControl = this;
- return sendMouseEvent (SWT.MouseEnter, 0, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
- }
- return 0;
-}
-
-boolean checkSubwindow () {
- return false;
-}
-
-int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) {
- GdkEvent event = new GdkEvent ();
- OS.memmove (event, gdkEvent, GdkEvent.sizeof);
- switch (event.type) {
- case OS.GDK_BUTTON_PRESS: {
- if (widget != eventHandle ()) break;
- /*
- * Pop up the context menu in the event_after signal to allow
- * the widget to process the button press. This allows widgets
- * such as GtkTreeView to select items before a menu is shown.
- */
- if ((state & MENU) == 0) {
- GdkEventButton gdkEventButton = new GdkEventButton ();
- OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof);
- if (gdkEventButton.button == 3) {
- showMenu ((int) gdkEventButton.x_root, (int) gdkEventButton.y_root);
- }
- }
- break;
- }
- case OS.GDK_FOCUS_CHANGE: {
- if (!isFocusHandle (widget)) break;
- GdkEventFocus gdkEventFocus = new GdkEventFocus ();
- OS.memmove (gdkEventFocus, gdkEvent, GdkEventFocus.sizeof);
-
- /*
- * Feature in GTK. The GTK combo box popup under some window managers
- * is implemented as a GTK_MENU. When it pops up, it causes the combo
- * box to lose focus when focus is received for the menu. The
- * fix is to check the current grab handle and see if it is a GTK_MENU
- * and ignore the focus event when the menu is both shown and hidden.
- *
- * NOTE: This code runs for all menus.
- */
- Display display = this.display;
- if (gdkEventFocus.in != 0) {
- if (display.ignoreFocus) {
- display.ignoreFocus = false;
- break;
- }
- } else {
- display.ignoreFocus = false;
- int /*long*/ grabHandle = OS.gtk_grab_get_current ();
- if (grabHandle != 0) {
- if (OS.G_OBJECT_TYPE (grabHandle) == OS.GTK_TYPE_MENU ()) {
- display.ignoreFocus = true;
- break;
- }
- }
- }
-
- sendFocusEvent (gdkEventFocus.in != 0 ? SWT.FocusIn : SWT.FocusOut);
- break;
- }
- }
- return 0;
-}
-
-int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ eventPtr) {
- if ((state & OBSCURED) != 0) return 0;
- if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0;
- GdkEventExpose gdkEvent = new GdkEventExpose ();
- OS.memmove(gdkEvent, eventPtr, GdkEventExpose.sizeof);
- Event event = new Event ();
- event.count = gdkEvent.count;
- event.x = gdkEvent.area_x;
- event.y = gdkEvent.area_y;
- event.width = gdkEvent.area_width;
- event.height = gdkEvent.area_height;
- if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.width - event.x;
- GCData data = new GCData ();
- data.damageRgn = gdkEvent.region;
- GC gc = event.gc = GC.gtk_new (this, data);
- OS.gdk_gc_set_clip_region (gc.handle, gdkEvent.region);
- sendEvent (SWT.Paint, event);
- gc.dispose ();
- event.gc = null;
- return 0;
-}
-
-int /*long*/ gtk_focus (int /*long*/ widget, int /*long*/ directionType) {
- /* Stop GTK traversal for every widget */
- return 1;
-}
-
-int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) {
- // widget could be disposed at this point
- if (handle != 0) {
- Control oldControl = display.imControl;
- if (oldControl != this) {
- if (oldControl != null && !oldControl.isDisposed ()) {
- int /*long*/ oldIMHandle = oldControl.imHandle ();
- if (oldIMHandle != 0) OS.gtk_im_context_reset (oldIMHandle);
- }
- }
- if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) {
- int /*long*/ imHandle = imHandle ();
- if (imHandle != 0) OS.gtk_im_context_focus_in (imHandle);
- }
- }
- return 0;
-}
-
-int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) {
- // widget could be disposed at this point
- if (handle != 0) {
- if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) {
- int /*long*/ imHandle = imHandle ();
- if (imHandle != 0) {
- OS.gtk_im_context_focus_out (imHandle);
- }
- }
- }
- return 0;
-}
-
-int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) {
- if (!hasFocus ()) return 0;
- GdkEventKey gdkEvent = new GdkEventKey ();
- OS.memmove (gdkEvent, event, GdkEventKey.sizeof);
-
- if (translateMnemonic (gdkEvent.keyval, gdkEvent)) return 1;
- // widget could be disposed at this point
- if (isDisposed ()) return 0;
-
- if (filterKey (gdkEvent.keyval, event)) return 1;
- // widget could be disposed at this point
- if (isDisposed ()) return 0;
-
- if (translateTraversal (gdkEvent)) return 1;
- // widget could be disposed at this point
- if (isDisposed ()) return 0;
- return super.gtk_key_press_event (widget, event);
-}
-
-int /*long*/ gtk_key_release_event (int /*long*/ widget, int /*long*/ event) {
- if (!hasFocus ()) return 0;
- int /*long*/ imHandle = imHandle ();
- if (imHandle != 0) {
- if (OS.gtk_im_context_filter_keypress (imHandle, event)) return 1;
- }
- return super.gtk_key_release_event (widget, event);
-}
-
-int /*long*/ gtk_leave_notify_event (int /*long*/ widget, int /*long*/ event) {
- if (display.currentControl != this) return 0;
- display.removeMouseHoverTimeout (handle);
- int result = 0;
- if (sendLeaveNotify () || display.getCursorControl () == null) {
- GdkEventCrossing gdkEvent = new GdkEventCrossing ();
- OS.memmove (gdkEvent, event, GdkEventCrossing.sizeof);
- if (gdkEvent.mode != OS.GDK_CROSSING_NORMAL && gdkEvent.mode != OS.GDK_CROSSING_UNGRAB) return 0;
- if ((gdkEvent.state & (OS.GDK_BUTTON1_MASK | OS.GDK_BUTTON2_MASK | OS.GDK_BUTTON3_MASK)) != 0) return 0;
- result = sendMouseEvent (SWT.MouseExit, 0, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
- display.currentControl = null;
- }
- return result;
-}
-
-int /*long*/ gtk_mnemonic_activate (int /*long*/ widget, int /*long*/ arg1) {
- int result = 0;
- int /*long*/ eventPtr = OS.gtk_get_current_event ();
- if (eventPtr != 0) {
- GdkEventKey keyEvent = new GdkEventKey ();
- OS.memmove (keyEvent, eventPtr, GdkEventKey.sizeof);
- if (keyEvent.type == OS.GDK_KEY_PRESS) {
- Control focusControl = display.getFocusControl ();
- int /*long*/ focusHandle = focusControl != null ? focusControl.focusHandle () : 0;
- if (focusHandle != 0) {
- display.mnemonicControl = this;
- OS.gtk_widget_event (focusHandle, eventPtr);
- display.mnemonicControl = null;
- }
- result = 1;
- }
- OS.gdk_event_free (eventPtr);
- }
- return result;
-}
-
-int /*long*/ gtk_motion_notify_event (int /*long*/ widget, int /*long*/ event) {
- GdkEventMotion gdkEvent = new GdkEventMotion ();
- OS.memmove (gdkEvent, event, GdkEventMotion.sizeof);
- if (this == display.currentControl && (hooks (SWT.MouseHover) || filters (SWT.MouseHover))) {
- display.addMouseHoverTimeout (handle);
- }
- double x = gdkEvent.x_root, y = gdkEvent.y_root;
- int state = gdkEvent.state;
- if (gdkEvent.is_hint != 0) {
- int [] pointer_x = new int [1], pointer_y = new int [1], mask = new int [1];
- int /*long*/ window = eventWindow ();
- OS.gdk_window_get_pointer (window, pointer_x, pointer_y, mask);
- x = pointer_x [0];
- y = pointer_y [0];
- state = mask [0];
- }
- int result = sendMouseEvent (SWT.MouseMove, 0, gdkEvent.time, x, y, gdkEvent.is_hint != 0, state) ? 0 : 1;
- return result;
-}
-
-int /*long*/ gtk_popup_menu (int /*long*/ widget) {
- if (!hasFocus()) return 0;
- int [] x = new int [1], y = new int [1];
- OS.gdk_window_get_pointer (0, x, y, null);
- return showMenu (x [0], y [0]) ? 1 : 0;
-}
-
-int /*long*/ gtk_preedit_changed (int /*long*/ imcontext) {
- display.showIMWindow (this);
- return 0;
-}
-
-int /*long*/ gtk_realize (int /*long*/ widget) {
- int /*long*/ imHandle = imHandle ();
- if (imHandle != 0) {
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (paintHandle ());
- OS.gtk_im_context_set_client_window (imHandle, window);
- }
- if (backgroundImage != null) {
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (paintHandle ());
- if (window != 0) OS.gdk_window_set_back_pixmap (window, backgroundImage.pixmap, false);
- }
- return 0;
-}
-
-int /*long*/ gtk_scroll_event (int /*long*/ widget, int /*long*/ eventPtr) {
- GdkEventScroll gdkEvent = new GdkEventScroll ();
- OS.memmove (gdkEvent, eventPtr, GdkEventScroll.sizeof);
- switch (gdkEvent.direction) {
- case OS.GDK_SCROLL_UP:
- return sendMouseEvent (SWT.MouseWheel, 0, 3, SWT.SCROLL_LINE, true, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
- case OS.GDK_SCROLL_DOWN:
- return sendMouseEvent (SWT.MouseWheel, 0, -3, SWT.SCROLL_LINE, true, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
- case OS.GDK_SCROLL_LEFT:
- return sendMouseEvent (SWT.MouseDown, 4, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
- case OS.GDK_SCROLL_RIGHT:
- return sendMouseEvent (SWT.MouseDown, 5, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
- }
- return 0;
-}
-
-int /*long*/ gtk_show_help (int /*long*/ widget, int /*long*/ helpType) {
- if (!hasFocus ()) return 0;
- return sendHelpEvent (helpType) ? 1 : 0;
-}
-
-int /*long*/ gtk_style_set (int /*long*/ widget, int /*long*/ previousStyle) {
- if (backgroundImage != null) {
- setBackgroundPixmap (backgroundImage.pixmap);
- }
- return 0;
-}
-
-int /*long*/ gtk_unrealize (int /*long*/ widget) {
- int /*long*/ imHandle = imHandle ();
- if (imHandle != 0) OS.gtk_im_context_set_client_window (imHandle, 0);
- return 0;
-}
-
-int /*long*/ gtk_visibility_notify_event (int /*long*/ widget, int /*long*/ event) {
- GdkEventVisibility gdkEvent = new GdkEventVisibility ();
- OS.memmove (gdkEvent, event, GdkEventVisibility.sizeof);
- int /*long*/ paintWindow = paintWindow();
- int /*long*/ window = gdkEvent.window;
- if (window == paintWindow) {
- if (gdkEvent.state == OS.GDK_VISIBILITY_FULLY_OBSCURED) {
- state |= OBSCURED;
- } else {
- if ((state & OBSCURED) != 0) {
- int [] width = new int [1], height = new int [1];
- OS.gdk_drawable_get_size (window, width, height);
- GdkRectangle rect = new GdkRectangle ();
- rect.width = width [0];
- rect.height = height [0];
- OS.gdk_window_invalidate_rect (window, rect, false);
- }
- state &= ~OBSCURED;
- }
- }
- return 0;
-}
-
-void gtk_widget_size_request (int /*long*/ widget, GtkRequisition requisition) {
- OS.gtk_widget_size_request (widget, requisition);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Control</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public int /*long*/ internal_new_GC (GCData data) {
- checkWidget ();
- int /*long*/ window = paintWindow ();
- if (window == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- int /*long*/ gdkGC = OS.gdk_gc_new (window);
- if (gdkGC == 0) error (SWT.ERROR_NO_HANDLES);
- if (data != null) {
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) == 0) {
- data.style |= style & (mask | SWT.MIRRORED);
- } else {
- if ((data.style & SWT.RIGHT_TO_LEFT) != 0) {
- data.style |= SWT.MIRRORED;
- }
- }
- data.drawable = window;
- data.device = display;
- data.foreground = getForegroundColor ();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- data.background = control.getBackgroundColor ();
- data.font = font != null ? font : defaultFont ();
- }
- return gdkGC;
-}
-
-int /*long*/ imHandle () {
- return 0;
-}
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Control</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int /*long*/ gdkGC, GCData data) {
- checkWidget ();
- OS.g_object_unref (gdkGC);
-}
-
-/**
- * Returns <code>true</code> if the underlying operating
- * system supports this reparenting, otherwise <code>false</code>
- *
- * @return <code>true</code> if the widget can be reparented, otherwise <code>false</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isReparentable () {
- checkWidget();
- return true;
-}
-boolean isShowing () {
- /*
- * This is not complete. Need to check if the
- * widget is obscurred by a parent or sibling.
- */
- if (!isVisible ()) return false;
- Control control = this;
- while (control != null) {
- Point size = control.getSize ();
- if (size.x == 0 || size.y == 0) {
- return false;
- }
- control = control.parent;
- }
- return true;
-}
-boolean isTabGroup () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == this) return true;
- }
- }
- int code = traversalCode (0, null);
- if ((code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) != 0) return false;
- return (code & (SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_TAB_NEXT)) != 0;
-}
-boolean isTabItem () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == this) return false;
- }
- }
- int code = traversalCode (0, null);
- return (code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) != 0;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * ancestors up to and including the receiver's nearest ancestor
- * shell are enabled. Otherwise, <code>false</code> is returned.
- * A disabled control is typically not selectable from the user
- * interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget ();
- return getEnabled () && parent.isEnabled ();
-}
-
-boolean isFocusAncestor (Control control) {
- while (control != null && control != this && !(control instanceof Shell)) {
- control = control.parent;
- }
- return control == this;
-}
-
-/**
- * Returns <code>true</code> if the receiver has the user-interface
- * focus, and <code>false</code> otherwise.
- *
- * @return the receiver's focus state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isFocusControl () {
- checkWidget();
- Control focusControl = display.focusControl;
- if (focusControl != null && !focusControl.isDisposed ()) {
- return this == focusControl;
- }
- return hasFocus ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * ancestors up to and including the receiver's nearest ancestor
- * shell are visible. Otherwise, <code>false</code> is returned.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return getVisible () && parent.isVisible ();
-}
-
-Decorations menuShell () {
- return parent.menuShell ();
-}
-
-boolean mnemonicHit (char key) {
- return false;
-}
-
-boolean mnemonicMatch (char key) {
- return false;
-}
-
-void register () {
- super.register ();
- if (fixedHandle != 0) display.addWidget (fixedHandle, this);
- int /*long*/ imHandle = imHandle ();
- if (imHandle != 0) display.addWidget (imHandle, this);
-}
-
-/**
- * Causes the entire bounds of the receiver to be marked
- * as needing to be redrawn. The next time a paint request
- * is processed, the control will be completely painted,
- * including the background.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #update()
- * @see PaintListener
- * @see SWT#Paint
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#DOUBLE_BUFFERED
- */
-public void redraw () {
- checkWidget();
- redraw (false);
-}
-
-void redraw (boolean all) {
-// checkWidget();
- if (!OS.GTK_WIDGET_VISIBLE (topHandle ())) return;
- redrawWidget (0, 0, 0, 0, true, all, false);
-}
-
-/**
- * Causes the rectangular area of the receiver specified by
- * the arguments to be marked as needing to be redrawn.
- * The next time a paint request is processed, that area of
- * the receiver will be painted, including the background.
- * If the <code>all</code> flag is <code>true</code>, any
- * children of the receiver which intersect with the specified
- * area will also paint their intersecting areas. If the
- * <code>all</code> flag is <code>false</code>, the children
- * will not be painted.
- *
- * @param x the x coordinate of the area to draw
- * @param y the y coordinate of the area to draw
- * @param width the width of the area to draw
- * @param height the height of the area to draw
- * @param all <code>true</code> if children should redraw, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #update()
- * @see PaintListener
- * @see SWT#Paint
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#DOUBLE_BUFFERED
- */
-public void redraw (int x, int y, int width, int height, boolean all) {
- checkWidget();
- if (!OS.GTK_WIDGET_VISIBLE (topHandle ())) return;
- if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - width - x;
- redrawWidget (x, y, width, height, false, all, false);
-}
-
-void redrawChildren () {
-}
-
-void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean all, boolean trim) {
- if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_REALIZED) == 0) return;
- int /*long*/ window = paintWindow ();
- GdkRectangle rect = new GdkRectangle ();
- if (redrawAll) {
- int [] w = new int [1], h = new int [1];
- OS.gdk_drawable_get_size (window, w, h);
- rect.width = w [0];
- rect.height = h [0];
- } else {
- rect.x = x;
- rect.y = y;
- rect.width = width;
- rect.height = height;
- }
- OS.gdk_window_invalidate_rect (window, rect, all);
-}
-
-void release (boolean destroy) {
- Control next = null, previous = null;
- if (destroy && parent != null) {
- Control[] children = parent._getChildren ();
- int index = 0;
- while (index < children.length) {
- if (children [index] == this) break;
- index++;
- }
- if (0 < index && (index + 1) < children.length) {
- next = children [index + 1];
- previous = children [index - 1];
- }
- }
- super.release (destroy);
- if (destroy) {
- if (previous != null) previous.addRelation (next);
- }
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- fixedHandle = 0;
- parent = null;
-}
-
-void releaseParent () {
- parent.removeControl (this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (display.currentControl == this) display.currentControl = null;
- display.removeMouseHoverTimeout (handle);
- int /*long*/ imHandle = imHandle ();
- if (imHandle != 0) {
- OS.gtk_im_context_reset (imHandle);
- OS.gtk_im_context_set_client_window (imHandle, 0);
- }
- if (enableWindow != 0) {
- OS.gdk_window_set_user_data (enableWindow, 0);
- OS.gdk_window_destroy (enableWindow);
- enableWindow = 0;
- }
- redrawWindow = 0;
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- menu = null;
- cursor = null;
- toolTipText = null;
- layoutData = null;
- accessible = null;
- region = null;
-}
-
-boolean sendDragEvent (int button, int stateMask, int x, int y, boolean isStateMask) {
- Event event = new Event ();
- event.button = button;
- event.x = x;
- event.y = y;
- if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.x;
- if (isStateMask) {
- event.stateMask = stateMask;
- } else {
- setInputState (event, stateMask);
- }
- postEvent (SWT.DragDetect, event);
- if (isDisposed ()) return false;
- return event.doit;
-}
-
-void sendFocusEvent (int type) {
- Shell shell = _getShell ();
- Display display = this.display;
- display.focusControl = this;
- display.focusEvent = type;
- sendEvent (type);
- display.focusControl = null;
- display.focusEvent = SWT.None;
- /*
- * It is possible that the shell may be
- * disposed at this point. If this happens
- * don't send the activate and deactivate
- * events.
- */
- if (!shell.isDisposed ()) {
- switch (type) {
- case SWT.FocusIn:
- shell.setActiveControl (this);
- break;
- case SWT.FocusOut:
- if (shell != display.activeShell) {
- shell.setActiveControl (null);
- }
- break;
- }
- }
-}
-
-boolean sendHelpEvent (int /*long*/ helpType) {
- Control control = this;
- while (control != null) {
- if (control.hooks (SWT.Help)) {
- control.postEvent (SWT.Help);
- return true;
- }
- control = control.parent;
- }
- return false;
-}
-
-boolean sendLeaveNotify() {
- return false;
-}
-
-boolean sendMouseEvent (int type, int button, int time, double x, double y, boolean is_hint, int state) {
- return sendMouseEvent (type, button, 0, 0, false, time, x, y, is_hint, state);
-}
-
-boolean sendMouseEvent (int type, int button, int count, int detail, boolean send, int time, double x, double y, boolean is_hint, int state) {
- if (!hooks (type) && !filters (type)) return true;
- Event event = new Event ();
- event.time = time;
- event.button = button;
- event.detail = detail;
- event.count = count;
- if (is_hint) {
- event.x = (int)x;
- event.y = (int)y;
- } else {
- int /*long*/ window = eventWindow ();
- int [] origin_x = new int [1], origin_y = new int [1];
- OS.gdk_window_get_origin (window, origin_x, origin_y);
- event.x = (int)x - origin_x [0];
- event.y = (int)y - origin_y [0];
- }
- if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.x;
- setInputState (event, state);
- if (send) {
- sendEvent (type, event);
- if (isDisposed ()) return false;
- } else {
- postEvent (type, event);
- }
- return event.doit;
-}
-
-void setBackground () {
- if ((state & PARENT_BACKGROUND) != 0 && (state & BACKGROUND) == 0 && backgroundImage == null) {
- setParentBackground ();
- } else {
- setWidgetBackground ();
- }
- redrawWidget (0, 0, 0, 0, true, false, false);
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the control
- * if the argument is null.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on Windows the background of a Button cannot be changed.
- * </p>
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBackground (Color color) {
- checkWidget();
- if (((state & BACKGROUND) == 0) && color == null) return;
- GdkColor gdkColor = null;
- if (color != null) {
- if (color.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- gdkColor = color.handle;
- }
- boolean set = false;
- if (gdkColor == null) {
- int /*long*/ style = OS.gtk_widget_get_modifier_style (handle);
- set = (OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_NORMAL) & OS.GTK_RC_BG) != 0;
- } else {
- GdkColor oldColor = getBackgroundColor ();
- set = oldColor.pixel != gdkColor.pixel;
- }
- if (set) {
- if (color == null) {
- state &= ~BACKGROUND;
- } else {
- state |= BACKGROUND;
- }
- setBackgroundColor (gdkColor);
- redrawChildren ();
- }
-}
-
-void setBackgroundColor (int /*long*/ handle, GdkColor color) {
- int index = OS.GTK_STATE_NORMAL;
- int /*long*/ style = OS.gtk_widget_get_modifier_style (handle);
- int /*long*/ ptr = OS.gtk_rc_style_get_bg_pixmap_name (style, index);
- if (ptr != 0) OS.g_free (ptr);
- String name = color == null ? "<parent>" : "<none>";
- byte[] buffer = Converter.wcsToMbcs (null, name, true);
- ptr = OS.g_malloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- OS.gtk_rc_style_set_bg_pixmap_name (style, index, ptr);
- OS.gtk_rc_style_set_bg (style, index, color);
- int flags = OS.gtk_rc_style_get_color_flags (style, index);
- flags = (color == null) ? flags & ~OS.GTK_RC_BG : flags | OS.GTK_RC_BG;
- OS.gtk_rc_style_set_color_flags (style, index, flags);
- modifyStyle (handle, style);
-}
-
-void setBackgroundColor (GdkColor color) {
- setBackgroundColor (handle, color);
-}
-
-/**
- * Sets the receiver's background image to the image specified
- * by the argument, or to the default system color for the control
- * if the argument is null. The background image is tiled to fill
- * the available space.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on Windows the background of a Button cannot be changed.
- * </p>
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument is not a bitmap</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setBackgroundImage (Image image) {
- checkWidget ();
- if (image != null && image.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (image == backgroundImage) return;
- this.backgroundImage = image;
- if (backgroundImage != null) {
- setBackgroundPixmap (backgroundImage.pixmap);
- redrawWidget (0, 0, 0, 0, true, false, false);
- } else {
- setWidgetBackground ();
- }
- redrawChildren ();
-}
-
-void setBackgroundPixmap (int /*long*/ pixmap) {
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (paintHandle ());
- if (window != 0) OS.gdk_window_set_back_pixmap (window, backgroundImage.pixmap, false);
-}
-
-/**
- * If the argument is <code>true</code>, causes the receiver to have
- * all mouse events delivered to it until the method is called with
- * <code>false</code> as the argument. Note that on some platforms,
- * a mouse button must currently be down for capture to be assigned.
- *
- * @param capture <code>true</code> to capture the mouse, and <code>false</code> to release it
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCapture (boolean capture) {
- checkWidget();
- /* FIXME !!!!! */
- /*
- if (capture) {
- OS.gtk_widget_grab_focus (handle);
- } else {
- OS.gtk_widget_grab_default (handle);
- }
- */
-}
-/**
- * Sets the receiver's cursor to the cursor specified by the
- * argument, or to the default cursor for that kind of control
- * if the argument is null.
- * <p>
- * When the mouse pointer passes over a control its appearance
- * is changed to match the control's cursor.
- * </p>
- *
- * @param cursor the new cursor (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCursor (Cursor cursor) {
- checkWidget();
- if (cursor != null && cursor.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- this.cursor = cursor;
- setCursor (cursor != null ? cursor.handle : 0);
-}
-
-void setCursor (int /*long*/ cursor) {
- int /*long*/ window = eventWindow ();
- if (window != 0) {
- OS.gdk_window_set_cursor (window, cursor);
- if (!OS.GDK_WINDOWING_X11 ()) {
- OS.gdk_flush ();
- } else {
- int /*long*/ xDisplay = OS.GDK_DISPLAY ();
- OS.XFlush (xDisplay);
- }
- }
-}
-
-/**
- * Sets the receiver's drag detect state. If the argument is
- * <code>true</code>, the receiver will detect drag gestures,
- * otherwise these gestures will be ignored.
- *
- * @param dragDetect the new drag detect state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public void setDragDetect (boolean dragDetect) {
- checkWidget ();
- if (dragDetect) {
- state |= DRAG_DETECT;
- } else {
- state &= ~DRAG_DETECT;
- }
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- if (((state & DISABLED) == 0) == enabled) return;
- Control control = null;
- boolean fixFocus = false;
- if (!enabled) {
- if (display.focusEvent != SWT.FocusOut) {
- control = display.getFocusControl ();
- fixFocus = isFocusAncestor (control);
- }
- }
- if (enabled) {
- state &= ~DISABLED;
- } else {
- state |= DISABLED;
- }
- enableWidget (enabled);
- if (isDisposed ()) return;
- if (enabled) {
- if (enableWindow != 0) {
- OS.gdk_window_set_user_data (enableWindow, 0);
- OS.gdk_window_destroy (enableWindow);
- enableWindow = 0;
- }
- } else {
- OS.gtk_widget_realize (handle);
- int /*long*/ parentHandle = parent.eventHandle ();
- int /*long*/ window = parent.eventWindow ();
- int /*long*/ topHandle = topHandle ();
- GdkWindowAttr attributes = new GdkWindowAttr ();
- attributes.x = OS.GTK_WIDGET_X (topHandle);
- attributes.y = OS.GTK_WIDGET_Y (topHandle);
- attributes.width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle);
- attributes.height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (topHandle);
- attributes.event_mask = (0xFFFFFFFF & ~OS.ExposureMask);
- attributes.wclass = OS.GDK_INPUT_ONLY;
- attributes.window_type = OS.GDK_WINDOW_CHILD;
- enableWindow = OS.gdk_window_new (window, attributes, OS.GDK_WA_X | OS.GDK_WA_Y);
- if (enableWindow != 0) {
- OS.gdk_window_set_user_data (enableWindow, parentHandle);
- if (!OS.GDK_WINDOWING_X11 ()) {
- OS.gdk_window_raise (enableWindow);
- } else {
- int /*long*/ topWindow = OS.GTK_WIDGET_WINDOW (topHandle);
- int /*long*/ xDisplay = OS.gdk_x11_drawable_get_xdisplay (topWindow);
- int /*long*/ xWindow = OS.gdk_x11_drawable_get_xid (enableWindow);
- int xScreen = OS.XDefaultScreen (xDisplay);
- int flags = OS.CWStackMode | OS.CWSibling;
- XWindowChanges changes = new XWindowChanges ();
- changes.sibling = OS.gdk_x11_drawable_get_xid (topWindow);
- changes.stack_mode = OS.Above;
- OS.XReconfigureWMWindow (xDisplay, xWindow, xScreen, flags, changes);
- }
- if (OS.GTK_WIDGET_VISIBLE (topHandle)) OS.gdk_window_show_unraised (enableWindow);
- }
- }
- if (fixFocus) fixFocus (control);
-}
-
-/**
- * Causes the receiver to have the <em>keyboard focus</em>,
- * such that all keyboard events will be delivered to it. Focus
- * reassignment will respect applicable platform constraints.
- *
- * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #forceFocus
- */
-public boolean setFocus () {
- checkWidget();
- if ((style & SWT.NO_FOCUS) != 0) return false;
- return forceFocus ();
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * to the font specified by the argument, or to the default font for that
- * kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkWidget();
- if (((state & FONT) == 0) && font == null) return;
- this.font = font;
- int /*long*/ fontDesc;
- if (font == null) {
- fontDesc = defaultFont ().handle;
- } else {
- if (font.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- fontDesc = font.handle;
- }
- if (font == null) {
- state &= ~FONT;
- } else {
- state |= FONT;
- }
- setFontDescription (fontDesc);
-}
-
-void setFontDescription (int /*long*/ font) {
- OS.gtk_widget_modify_font (handle, font);
-}
-
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the control
- * if the argument is null.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * </p>
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setForeground (Color color) {
- checkWidget();
- if (((state & FOREGROUND) == 0) && color == null) return;
- GdkColor gdkColor = null;
- if (color != null) {
- if (color.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- gdkColor = color.handle;
- }
- boolean set = false;
- if (gdkColor == null) {
- int /*long*/ style = OS.gtk_widget_get_modifier_style (handle);
- set = (OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_NORMAL) & OS.GTK_RC_FG) != 0;
- } else {
- GdkColor oldColor = getForegroundColor ();
- set = oldColor.pixel != gdkColor.pixel;
- }
- if (set) {
- if (color == null) {
- state &= ~FOREGROUND;
- } else {
- state |= FOREGROUND;
- }
- setForegroundColor (gdkColor);
- }
-}
-
-void setForegroundColor (GdkColor color) {
- setForegroundColor (handle, color);
-}
-
-void setInitialBounds () {
- if ((state & ZERO_WIDTH) != 0 && (state & ZERO_HEIGHT) != 0) {
- /*
- * Feature in GTK. On creation, each widget's allocation is
- * initialized to a position of (-1, -1) until the widget is
- * first sized. The fix is to set the value to (0, 0) as
- * expected by SWT.
- */
- int /*long*/ topHandle = topHandle ();
- if ((parent.style & SWT.MIRRORED) != 0) {
- OS.GTK_WIDGET_SET_X (topHandle, parent.getClientWidth ());
- } else {
- OS.GTK_WIDGET_SET_X (topHandle, 0);
- }
- OS.GTK_WIDGET_SET_Y (topHandle, 0);
- } else {
- resizeHandle (1, 1);
- forceResize ();
- }
-}
-
-/**
- * Sets the receiver's pop up menu to the argument.
- * All controls may optionally have a pop up
- * menu that is displayed when the user requests one for
- * the control. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pop up
- * menu is platform specific.
- * <p>
- * Note: Disposing of a control that has a pop up menu will
- * dispose of the menu. To avoid this behavior, set the
- * menu to null before the control is disposed.
- * </p>
- *
- * @param menu the new pop up menu
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenu (Menu menu) {
- checkWidget();
- if (menu != null) {
- if ((menu.style & SWT.POP_UP) == 0) {
- error (SWT.ERROR_MENU_NOT_POP_UP);
- }
- if (menu.parent != menuShell ()) {
- error (SWT.ERROR_INVALID_PARENT);
- }
- }
- this.menu = menu;
-}
-
-void setOrientation () {
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- if (handle != 0) OS.gtk_widget_set_direction (handle, OS.GTK_TEXT_DIR_RTL);
- if (fixedHandle != 0) OS.gtk_widget_set_direction (fixedHandle, OS.GTK_TEXT_DIR_RTL);
- }
-}
-
-/**
- * Changes the parent of the widget to be the one provided if
- * the underlying operating system supports this feature.
- * Returns <code>true</code> if the parent is successfully changed.
- *
- * @param parent the new parent for the control.
- * @return <code>true</code> if the parent is changed and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * <li>ERROR_NULL_ARGUMENT - if the parent is <code>null</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean setParent (Composite parent) {
- checkWidget ();
- if (parent == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (parent.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- if (this.parent == parent) return true;
- if (!isReparentable ()) return false;
- int /*long*/ topHandle = topHandle ();
- int x = OS.GTK_WIDGET_X (topHandle);
- int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle);
- if ((this.parent.style & SWT.MIRRORED) != 0) {
- x = this.parent.getClientWidth () - width - x;
- }
- if ((parent.style & SWT.MIRRORED) != 0) {
- x = parent.getClientWidth () - width - x;
- }
- int y = OS.GTK_WIDGET_Y (topHandle);
- releaseParent ();
- Shell newShell = parent.getShell (), oldShell = getShell ();
- Decorations newDecorations = parent.menuShell (), oldDecorations = menuShell ();
- Menu [] menus = oldShell.findMenus (this);
- if (oldShell != newShell || oldDecorations != newDecorations) {
- fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
- newDecorations.fixAccelGroup ();
- oldDecorations.fixAccelGroup ();
- }
- int /*long*/ newParent = parent.parentingHandle();
- OS.gtk_widget_reparent (topHandle, newParent);
- OS.gtk_fixed_move (newParent, topHandle, x, y);
- this.parent = parent;
- setZOrder (null, false, true);
- return true;
-}
-
-void setParentBackground () {
- setBackgroundColor (handle, null);
- if (fixedHandle != 0) setBackgroundColor (fixedHandle, null);
-}
-
-void setParentWindow (int /*long*/ widget) {
-}
-
-boolean setRadioSelection (boolean value) {
- return false;
-}
-
-/**
- * If the argument is <code>false</code>, causes subsequent drawing
- * operations in the receiver to be ignored. No drawing of any kind
- * can occur in the receiver until the flag is set to true.
- * Graphics operations that occurred while the flag was
- * <code>false</code> are lost. When the flag is set to <code>true</code>,
- * the entire widget is marked as needing to be redrawn. Nested calls
- * to this method are stacked.
- * <p>
- * Note: This operation is a hint and may not be supported on some
- * platforms or for some widgets.
- * </p>
- *
- * @param redraw the new redraw state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #redraw(int, int, int, int, boolean)
- * @see #update()
- */
-public void setRedraw (boolean redraw) {
- checkWidget();
- if (redraw) {
- if (--drawCount == 0) {
- if (redrawWindow != 0) {
- int /*long*/ window = paintWindow ();
- /* Explicitly hiding the window avoids flicker on GTK+ >= 2.6 */
- OS.gdk_window_hide (redrawWindow);
- OS.gdk_window_destroy (redrawWindow);
- OS.gdk_window_set_events (window, OS.gtk_widget_get_events (paintHandle ()));
- redrawWindow = 0;
- }
- }
- } else {
- if (drawCount++ == 0) {
- if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_REALIZED) != 0) {
- int /*long*/ window = paintWindow ();
- Rectangle rect = getBounds ();
- GdkWindowAttr attributes = new GdkWindowAttr ();
- attributes.width = rect.width;
- attributes.height = rect.height;
- attributes.event_mask = OS.GDK_EXPOSURE_MASK;
- attributes.window_type = OS.GDK_WINDOW_CHILD;
- redrawWindow = OS.gdk_window_new (window, attributes, 0);
- if (redrawWindow != 0) {
- int mouseMask = OS.GDK_BUTTON_PRESS_MASK | OS.GDK_BUTTON_RELEASE_MASK |
- OS.GDK_ENTER_NOTIFY_MASK | OS.GDK_LEAVE_NOTIFY_MASK |
- OS.GDK_POINTER_MOTION_MASK | OS.GDK_POINTER_MOTION_HINT_MASK |
- OS.GDK_BUTTON_MOTION_MASK | OS.GDK_BUTTON1_MOTION_MASK |
- OS.GDK_BUTTON2_MOTION_MASK | OS.GDK_BUTTON3_MOTION_MASK;
- OS.gdk_window_set_events (window, OS.gdk_window_get_events (window) & ~mouseMask);
- OS.gdk_window_set_back_pixmap (redrawWindow, 0, false);
- OS.gdk_window_show (redrawWindow);
- }
- }
- }
- }
-}
-
-boolean setTabItemFocus (boolean next) {
- if (!isShowing ()) return false;
- return forceFocus ();
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget();
- setToolTipText (_getShell (), string);
- toolTipText = string;
-}
-
-void setToolTipText (Shell shell, String newString) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0)) {
- /*
- * Feature in GTK. In order to prevent children widgets
- * from inheriting their parent's tooltip, the tooltip is
- * a set on a shell only. In order to force the shell tooltip
- * to update when a new tip string is set, the existing string
- * in the tooltip is set to null, followed by running a query.
- * The real tip text can then be set.
- *
- * Note that this will only run if the control for which the
- * tooltip is being set is the current control (i.e. the control
- * under the pointer).
- */
- if (display.currentControl == this) {
- shell.setToolTipText (shell.handle, eventHandle (), newString);
- }
- } else {
- shell.setToolTipText (eventHandle (), newString);
- }
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget();
- if (((state & HIDDEN) == 0) == visible) return;
- int /*long*/ topHandle = topHandle();
- if (visible) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the show
- * event. If this happens, just return.
- */
- sendEvent (SWT.Show);
- if (isDisposed ()) return;
- state &= ~HIDDEN;
- if ((state & (ZERO_WIDTH | ZERO_HEIGHT)) == 0) {
- if (enableWindow != 0) OS.gdk_window_show_unraised (enableWindow);
- OS.gtk_widget_show (topHandle);
- }
- } else {
- /*
- * Bug in GTK. Invoking gtk_widget_hide() on a widget that has
- * focus causes a focus_out_event to be sent. If the client disposes
- * the widget inside the event, GTK GP's. The fix is to reassign focus
- * before hiding the widget.
- *
- * NOTE: In order to stop the same widget from taking focus,
- * temporarily clear and set the GTK_VISIBLE flag.
- */
- Control control = null;
- boolean fixFocus = false;
- if (display.focusEvent != SWT.FocusOut) {
- control = display.getFocusControl ();
- fixFocus = isFocusAncestor (control);
- }
- state |= HIDDEN;
- if (fixFocus) {
- OS.GTK_WIDGET_UNSET_FLAGS (topHandle, OS.GTK_VISIBLE);
- fixFocus (control);
- if (isDisposed ()) return;
- OS.GTK_WIDGET_SET_FLAGS (topHandle, OS.GTK_VISIBLE);
- }
- OS.gtk_widget_hide (topHandle);
- if (isDisposed ()) return;
- if (enableWindow != 0) OS.gdk_window_hide (enableWindow);
- sendEvent (SWT.Hide);
- }
-}
-
-void setZOrder (Control sibling, boolean above, boolean fixRelations) {
- setZOrder (sibling, above, fixRelations, true);
-}
-
-void setZOrder (Control sibling, boolean above, boolean fixRelations, boolean fixChildren) {
- int index = 0, siblingIndex = 0, oldNextIndex = -1;
- Control[] children = null;
- if (fixRelations) {
- /* determine the receiver's and sibling's indexes in the parent */
- children = parent._getChildren ();
- while (index < children.length) {
- if (children [index] == this) break;
- index++;
- }
- if (sibling != null) {
- while (siblingIndex < children.length) {
- if (children [siblingIndex] == sibling) break;
- siblingIndex++;
- }
- }
- /* remove "Labelled by" relationships that will no longer be valid */
- removeRelation ();
- if (index + 1 < children.length) {
- oldNextIndex = index + 1;
- children [oldNextIndex].removeRelation ();
- }
- if (sibling != null) {
- if (above) {
- sibling.removeRelation ();
- } else {
- if (siblingIndex + 1 < children.length) {
- children [siblingIndex + 1].removeRelation ();
- }
- }
- }
- }
-
- int /*long*/ topHandle = topHandle ();
- int /*long*/ siblingHandle = sibling != null ? sibling.topHandle () : 0;
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (topHandle);
- if (window != 0) {
- int /*long*/ siblingWindow = 0;
- if (sibling != null) {
- if (above && sibling.enableWindow != 0) {
- siblingWindow = enableWindow;
- } else {
- siblingWindow = OS.GTK_WIDGET_WINDOW (siblingHandle);
- }
- }
- int /*long*/ redrawWindow = fixChildren ? parent.redrawWindow : 0;
- if (!OS.GDK_WINDOWING_X11 () || (siblingWindow == 0 && (!above || redrawWindow == 0))) {
- if (above) {
- OS.gdk_window_raise (window);
- if (redrawWindow != 0) OS.gdk_window_raise (redrawWindow);
- if (enableWindow != 0) OS.gdk_window_raise (enableWindow);
- } else {
- if (enableWindow != 0) OS.gdk_window_lower (enableWindow);
- OS.gdk_window_lower (window);
- }
- } else {
- XWindowChanges changes = new XWindowChanges ();
- changes.sibling = OS.gdk_x11_drawable_get_xid (siblingWindow != 0 ? siblingWindow : redrawWindow);
- changes.stack_mode = above ? OS.Above : OS.Below;
- if (redrawWindow != 0 && siblingWindow == 0) changes.stack_mode = OS.Below;
- int /*long*/ xDisplay = OS.gdk_x11_drawable_get_xdisplay (window);
- int /*long*/ xWindow = OS.gdk_x11_drawable_get_xid (window);
- int xScreen = OS.XDefaultScreen (xDisplay);
- int flags = OS.CWStackMode | OS.CWSibling;
- /*
- * Feature in X. If the receiver is a top level, XConfigureWindow ()
- * will fail (with a BadMatch error) for top level shells because top
- * level shells are reparented by the window manager and do not share
- * the same X window parent. This is the correct behavior but it is
- * unexpected. The fix is to use XReconfigureWMWindow () instead.
- * When the receiver is not a top level shell, XReconfigureWMWindow ()
- * behaves the same as XConfigureWindow ().
- */
- OS.XReconfigureWMWindow (xDisplay, xWindow, xScreen, flags, changes);
- if (enableWindow != 0) {
- changes.sibling = OS.gdk_x11_drawable_get_xid (window);
- changes.stack_mode = OS.Above;
- xWindow = OS.gdk_x11_drawable_get_xid (enableWindow);
- OS.XReconfigureWMWindow (xDisplay, xWindow, xScreen, flags, changes);
- }
- }
- }
- if (fixChildren) {
- if (above) {
- parent.moveAbove (topHandle, siblingHandle);
- } else {
- parent.moveBelow (topHandle, siblingHandle);
- }
- }
- /* Make sure that the parent internal windows are on the bottom of the stack */
- if (!above && fixChildren) parent.fixZOrder ();
-
- if (fixRelations) {
- /* determine the receiver's new index in the parent */
- if (sibling != null) {
- if (above) {
- index = siblingIndex - (index < siblingIndex ? 1 : 0);
- } else {
- index = siblingIndex + (siblingIndex < index ? 1 : 0);
- }
- } else {
- if (above) {
- index = 0;
- } else {
- index = children.length - 1;
- }
- }
-
- /* add new "Labelled by" relations as needed */
- children = parent._getChildren ();
- if (0 < index) {
- children [index - 1].addRelation (this);
- }
- if (index + 1 < children.length) {
- addRelation (children [index + 1]);
- }
- if (oldNextIndex != -1) {
- if (oldNextIndex <= index) oldNextIndex--;
- /* the last two conditions below ensure that duplicate relations are not hooked */
- if (0 < oldNextIndex && oldNextIndex != index && oldNextIndex != index + 1) {
- children [oldNextIndex - 1].addRelation (children [oldNextIndex]);
- }
- }
- }
-}
-
-void setWidgetBackground () {
- if (fixedHandle != 0) {
- int /*long*/ style = OS.gtk_widget_get_modifier_style (fixedHandle);
- modifyStyle (fixedHandle, style);
- }
- int /*long*/ style = OS.gtk_widget_get_modifier_style (handle);
- modifyStyle (handle, style);
-}
-
-boolean showMenu (int x, int y) {
- Event event = new Event ();
- event.x = x;
- event.y = y;
- sendEvent (SWT.MenuDetect, event);
- //widget could be disposed at this point
- if (isDisposed ()) return false;
- if (event.doit) {
- if (menu != null && !menu.isDisposed ()) {
- boolean hooksKeys = hooks (SWT.KeyDown) || hooks (SWT.KeyUp);
- menu.createIMMenu (hooksKeys ? imHandle() : 0);
- if (event.x != x || event.y != y) {
- menu.setLocation (event.x, event.y);
- }
- menu.setVisible (true);
- return true;
- }
- }
- return false;
-}
-
-void showWidget () {
- // Comment this line to disable zero-sized widgets
- state |= ZERO_WIDTH | ZERO_HEIGHT;
- int /*long*/ topHandle = topHandle ();
- int /*long*/ parentHandle = parent.parentingHandle ();
- parent.setParentWindow (topHandle);
- OS.gtk_container_add (parentHandle, topHandle);
- if (handle != 0 && handle != topHandle) OS.gtk_widget_show (handle);
- if ((state & (ZERO_WIDTH | ZERO_HEIGHT)) == 0) {
- if (fixedHandle != 0) OS.gtk_widget_show (fixedHandle);
- }
- if (fixedHandle != 0) fixStyle (fixedHandle);
-}
-
-void sort (int [] items) {
- /* Shell Sort from K&R, pg 108 */
- int length = items.length;
- for (int gap=length/2; gap>0; gap/=2) {
- for (int i=gap; i<length; i++) {
- for (int j=i-gap; j>=0; j-=gap) {
- if (items [j] <= items [j + gap]) {
- int swap = items [j];
- items [j] = items [j + gap];
- items [j + gap] = swap;
- }
- }
- }
- }
-}
-
-/**
- * Based on the argument, perform one of the expected platform
- * traversal action. The argument should be one of the constants:
- * <code>SWT.TRAVERSE_ESCAPE</code>, <code>SWT.TRAVERSE_RETURN</code>,
- * <code>SWT.TRAVERSE_TAB_NEXT</code>, <code>SWT.TRAVERSE_TAB_PREVIOUS</code>,
- * <code>SWT.TRAVERSE_ARROW_NEXT</code> and <code>SWT.TRAVERSE_ARROW_PREVIOUS</code>.
- *
- * @param traversal the type of traversal
- * @return true if the traversal succeeded
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean traverse (int traversal) {
- checkWidget ();
- Event event = new Event ();
- event.doit = true;
- event.detail = traversal;
- return traverse (event);
-}
-
-boolean translateMnemonic (Event event, Control control) {
- if (control == this) return false;
- if (!isVisible () || !isEnabled ()) return false;
- event.doit = this == display.mnemonicControl || mnemonicMatch (event.character);
- return traverse (event);
-}
-
-boolean translateMnemonic (int keyval, GdkEventKey gdkEvent) {
- int key = OS.gdk_keyval_to_unicode (keyval);
- if (key < 0x20) return false;
- if (gdkEvent.state == 0) {
- int code = traversalCode (keyval, gdkEvent);
- if ((code & SWT.TRAVERSE_MNEMONIC) == 0) return false;
- } else {
- Shell shell = _getShell ();
- int mask = OS.GDK_CONTROL_MASK | OS.GDK_SHIFT_MASK | OS.GDK_MOD1_MASK;
- if ((gdkEvent.state & mask) != OS.gtk_window_get_mnemonic_modifier (shell.shellHandle)) return false;
- }
- Decorations shell = menuShell ();
- if (shell.isVisible () && shell.isEnabled ()) {
- Event event = new Event ();
- event.detail = SWT.TRAVERSE_MNEMONIC;
- if (setKeyState (event, gdkEvent)) {
- return translateMnemonic (event, null) || shell.translateMnemonic (event, this);
- }
- }
- return false;
-}
-
-boolean translateTraversal (GdkEventKey keyEvent) {
- int detail = SWT.TRAVERSE_NONE;
- int key = keyEvent.keyval;
- int code = traversalCode (key, keyEvent);
- boolean all = false;
- switch (key) {
- case OS.GDK_Escape: {
- all = true;
- detail = SWT.TRAVERSE_ESCAPE;
- break;
- }
- case OS.GDK_KP_Enter:
- case OS.GDK_Return: {
- all = true;
- detail = SWT.TRAVERSE_RETURN;
- break;
- }
- case OS.GDK_ISO_Left_Tab:
- case OS.GDK_Tab: {
- boolean next = (keyEvent.state & OS.GDK_SHIFT_MASK) == 0;
- detail = next ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS;
- break;
- }
- case OS.GDK_Up:
- case OS.GDK_Left:
- case OS.GDK_Down:
- case OS.GDK_Right: {
- boolean next = key == OS.GDK_Down || key == OS.GDK_Right;
- if (parent != null && (parent.style & SWT.MIRRORED) != 0) {
- if (key == OS.GDK_Left || key == OS.GDK_Right) next = !next;
- }
- detail = next ? SWT.TRAVERSE_ARROW_NEXT : SWT.TRAVERSE_ARROW_PREVIOUS;
- break;
- }
- case OS.GDK_Page_Up:
- case OS.GDK_Page_Down: {
- all = true;
- if ((keyEvent.state & OS.GDK_CONTROL_MASK) == 0) return false;
- detail = key == OS.GDK_Page_Down ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS;
- break;
- }
- default:
- return false;
- }
- Event event = new Event ();
- event.doit = (code & detail) != 0;
- event.detail = detail;
- event.time = keyEvent.time;
- if (!setKeyState (event, keyEvent)) return false;
- Shell shell = getShell ();
- Control control = this;
- do {
- if (control.traverse (event)) return true;
- if (!event.doit && control.hooks (SWT.Traverse)) return false;
- if (control == shell) return false;
- control = control.parent;
- } while (all && control != null);
- return false;
-}
-
-int traversalCode (int key, GdkEventKey event) {
- int code = SWT.TRAVERSE_RETURN | SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_PAGE_NEXT | SWT.TRAVERSE_PAGE_PREVIOUS;
- Shell shell = getShell ();
- if (shell.parent != null) code |= SWT.TRAVERSE_ESCAPE;
- return code;
-}
-
-boolean traverse (Event event) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the traverse
- * event. If this happens, return true to stop further
- * event processing.
- */
- sendEvent (SWT.Traverse, event);
- if (isDisposed ()) return true;
- if (!event.doit) return false;
- switch (event.detail) {
- case SWT.TRAVERSE_NONE: return true;
- case SWT.TRAVERSE_ESCAPE: return traverseEscape ();
- case SWT.TRAVERSE_RETURN: return traverseReturn ();
- case SWT.TRAVERSE_TAB_NEXT: return traverseGroup (true);
- case SWT.TRAVERSE_TAB_PREVIOUS: return traverseGroup (false);
- case SWT.TRAVERSE_ARROW_NEXT: return traverseItem (true);
- case SWT.TRAVERSE_ARROW_PREVIOUS: return traverseItem (false);
- case SWT.TRAVERSE_MNEMONIC: return traverseMnemonic (event.character);
- case SWT.TRAVERSE_PAGE_NEXT: return traversePage (true);
- case SWT.TRAVERSE_PAGE_PREVIOUS: return traversePage (false);
- }
- return false;
-}
-
-boolean traverseEscape () {
- return false;
-}
-
-boolean traverseGroup (boolean next) {
- Control root = computeTabRoot ();
- Widget group = computeTabGroup ();
- Widget [] list = root.computeTabList ();
- int length = list.length;
- int index = 0;
- while (index < length) {
- if (list [index] == group) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- if (index == length) return false;
- int start = index, offset = (next) ? 1 : -1;
- while ((index = ((index + offset + length) % length)) != start) {
- Widget widget = list [index];
- if (!widget.isDisposed () && widget.setTabGroupFocus (next)) {
- return true;
- }
- }
- if (group.isDisposed ()) return false;
- return group.setTabGroupFocus (next);
-}
-
-boolean traverseItem (boolean next) {
- Control [] children = parent._getChildren ();
- int length = children.length;
- int index = 0;
- while (index < length) {
- if (children [index] == this) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- if (index == length) return false;
- int start = index, offset = (next) ? 1 : -1;
- while ((index = (index + offset + length) % length) != start) {
- Control child = children [index];
- if (!child.isDisposed () && child.isTabItem ()) {
- if (child.setTabItemFocus (next)) return true;
- }
- }
- return false;
-}
-
-boolean traverseReturn () {
- return false;
-}
-
-boolean traversePage (boolean next) {
- return false;
-}
-
-boolean traverseMnemonic (char key) {
- return mnemonicHit (key);
-}
-
-/**
- * Forces all outstanding paint requests for the widget
- * to be processed before this method returns. If there
- * are no outstanding paint request, this method does
- * nothing.
- * <p>
- * Note: This method does not cause a redraw.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #redraw()
- * @see #redraw(int, int, int, int, boolean)
- * @see PaintListener
- * @see SWT#Paint
- */
-public void update () {
- checkWidget ();
- update (false, true);
-}
-
-void update (boolean all, boolean flush) {
-// checkWidget();
- if (!OS.GTK_WIDGET_VISIBLE (topHandle ())) return;
- if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_REALIZED) == 0) return;
- int /*long*/ window = paintWindow ();
- if (flush) display.flushExposes (window, all);
- OS.gdk_window_process_updates (window, all);
- OS.gdk_flush ();
-}
-
-void updateBackgroundMode () {
- int oldState = state & PARENT_BACKGROUND;
- checkBackground ();
- if (oldState != (state & PARENT_BACKGROUND)) {
- setBackground ();
- }
-}
-
-void updateLayout (boolean all) {
- /* Do nothing */
-}
-
-int /*long*/ windowProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) {
- switch ((int)/*64*/user_data) {
- case EXPOSE_EVENT_INVERSE: {
- if ((OS.GTK_VERSION < OS.VERSION (2, 8, 0)) && ((state & OBSCURED) == 0)) {
- Control control = findBackgroundControl ();
- if (control != null && control.backgroundImage != null) {
- GdkEventExpose gdkEvent = new GdkEventExpose ();
- OS.memmove (gdkEvent, arg0, GdkEventExpose.sizeof);
- int /*long*/ paintWindow = paintWindow();
- int /*long*/ window = gdkEvent.window;
- if (window != paintWindow) break;
- int /*long*/ gdkGC = OS.gdk_gc_new (window);
- OS.gdk_gc_set_clip_region (gdkGC, gdkEvent.region);
- int[] dest_x = new int[1], dest_y = new int[1];
- OS.gtk_widget_translate_coordinates (paintHandle (), control.paintHandle (), 0, 0, dest_x, dest_y);
- OS.gdk_gc_set_fill (gdkGC, OS.GDK_TILED);
- OS.gdk_gc_set_ts_origin (gdkGC, -dest_x [0], -dest_y [0]);
- OS.gdk_gc_set_tile (gdkGC, control.backgroundImage.pixmap);
- OS.gdk_draw_rectangle (window, gdkGC, 1, gdkEvent.area_x, gdkEvent.area_y, gdkEvent.area_width, gdkEvent.area_height);
- OS.g_object_unref (gdkGC);
- }
- }
- break;
- }
- }
- return super.windowProc (handle, arg0, user_data);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java
deleted file mode 100644
index 11248e326d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java
+++ /dev/null
@@ -1,1103 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import java.text.DateFormatSymbols;
-import java.util.Calendar;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.gtk.OS;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify date
- * or time values.
- * <p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>DATE, TIME, CALENDAR, SHORT, MEDIUM, LONG, DROP_DOWN</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles DATE, TIME, or CALENDAR may be specified,
- * and only one of the styles SHORT, MEDIUM, or LONG may be specified.
- * The DROP_DOWN style is a <em>HINT</em>, and it is only valid with the DATE style.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#datetime">DateTime snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.3
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class DateTime extends Composite {
- int day, month, year, hours, minutes, seconds;
-
- static final int MIN_YEAR = 1752; // Gregorian switchover in North America: September 19, 1752
- static final int MAX_YEAR = 9999;
-
- /* Emulated DATE and TIME variables */
- Calendar calendar;
- DateFormatSymbols formatSymbols;
- Button down, up;
- Text text;
- String format;
- Point[] fieldIndices;
- int[] fieldNames;
- int fieldCount, currentField = 0, characterCount = 0;
- boolean ignoreVerify = false;
- static final String DEFAULT_SHORT_DATE_FORMAT = "MM/YYYY";
- static final String DEFAULT_MEDIUM_DATE_FORMAT = "MM/DD/YYYY";
- static final String DEFAULT_LONG_DATE_FORMAT = "MM/DD/YYYY";
- static final String DEFAULT_SHORT_TIME_FORMAT = "HH:MM AM";
- static final String DEFAULT_MEDIUM_TIME_FORMAT = "HH:MM:SS AM";
- static final String DEFAULT_LONG_TIME_FORMAT = "HH:MM:SS AM";
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DATE
- * @see SWT#TIME
- * @see SWT#CALENDAR
- * @see SWT#SHORT
- * @see SWT#MEDIUM
- * @see SWT#LONG
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public DateTime (Composite parent, int style) {
- super (parent, checkStyle (style));
- if ((this.style & SWT.CALENDAR) == 0) {
- /* SWT.DATE and SWT.TIME */
- calendar = Calendar.getInstance();
- formatSymbols = new DateFormatSymbols();
- text = new Text(this, SWT.SINGLE);
- /* disable the native drag and drop for the date/time text field */
- OS.gtk_drag_dest_unset(text.handle);
- if ((this.style & SWT.DATE) != 0) {
- setFormat((this.style & SWT.SHORT) != 0 ? DEFAULT_SHORT_DATE_FORMAT : (this.style & SWT.LONG) != 0 ? DEFAULT_LONG_DATE_FORMAT : DEFAULT_MEDIUM_DATE_FORMAT);
- } else { // SWT.TIME
- setFormat((this.style & SWT.SHORT) != 0 ? DEFAULT_SHORT_TIME_FORMAT : (this.style & SWT.LONG) != 0 ? DEFAULT_LONG_TIME_FORMAT : DEFAULT_MEDIUM_TIME_FORMAT);
- }
- text.setText(getFormattedString(this.style));
- Listener listener = new Listener() {
- public void handleEvent(Event event) {
- switch(event.type) {
- case SWT.KeyDown: onKeyDown(event); break;
- case SWT.FocusIn: onFocusIn(event); break;
- case SWT.FocusOut: onFocusOut(event); break;
- case SWT.MouseDown: onMouseClick(event); break;
- case SWT.MouseUp: onMouseClick(event); break;
- case SWT.Verify: onVerify(event); break;
- }
- }
- };
- text.addListener(SWT.KeyDown, listener);
- text.addListener(SWT.FocusIn, listener);
- text.addListener(SWT.FocusOut, listener);
- text.addListener(SWT.MouseDown, listener);
- text.addListener(SWT.MouseUp, listener);
- text.addListener(SWT.Verify, listener);
- up = new Button(this, SWT.ARROW | SWT.UP);
- //up.setToolTipText(SWT.getMessage ("SWT_Up")); //$NON-NLS-1$
- down = new Button(this, SWT.ARROW | SWT.DOWN);
- //down.setToolTipText(SWT.getMessage ("SWT_Down")); //$NON-NLS-1$
- up.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- incrementField(+1);
- text.setFocus();
- }
- });
- down.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- incrementField(-1);
- text.setFocus();
- }
- });
- addListener(SWT.Resize, new Listener() {
- public void handleEvent(Event event) {
- onResize(event);
- }
- });
- }
-}
-
-static int checkStyle (int style) {
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- style &= ~(SWT.H_SCROLL | SWT.V_SCROLL);
- style = checkBits (style, SWT.DATE, SWT.TIME, SWT.CALENDAR, 0, 0, 0);
- return checkBits (style, SWT.MEDIUM, SWT.SHORT, SWT.LONG, 0, 0, 0);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the control's value.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0;
- if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
- if ((style & SWT.CALENDAR) != 0) {
- // TODO: CALENDAR computeSize
- width = 300;
- height = 200;
- } else {
- /* SWT.DATE and SWT.TIME */
- GC gc = new GC(text);
- Point textSize = gc.stringExtent(getComputeSizeString(style));
- gc.dispose();
- Rectangle trim = text.computeTrim(0, 0, textSize.x, textSize.y);
- Point buttonSize = up.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
- width = trim.width + buttonSize.x;
- height = Math.max(trim.height, buttonSize.y);
- }
- }
- if (width == 0) width = DEFAULT_WIDTH;
- if (height == 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2; height += border * 2;
- return new Point (width, height);
-}
-
-void createHandle (int index) {
- if ((style & SWT.CALENDAR) != 0) {
- state |= HANDLE;
- fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (fixedHandle, true);
- handle = OS.gtk_calendar_new ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (fixedHandle, handle);
- if (OS.GTK_VERSION >= OS.VERSION(2, 4, 0)) {
- OS.gtk_calendar_set_display_options(handle, OS.GTK_CALENDAR_SHOW_HEADING | OS.GTK_CALENDAR_SHOW_DAY_NAMES);
- } else {
- OS.gtk_calendar_display_options(handle, OS.GTK_CALENDAR_SHOW_HEADING | OS.GTK_CALENDAR_SHOW_DAY_NAMES);
- }
- } else {
- super.createHandle(index);
- }
-}
-
-boolean checkSubwindow () {
- return false;
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- if ((style & SWT.CALENDAR) != 0) {
- getDate();
- }
-}
-
-void commitCurrentField() {
- if (characterCount > 0) {
- characterCount = 0;
- int fieldName = fieldNames[currentField];
- int start = fieldIndices[currentField].x;
- int end = fieldIndices[currentField].y;
- String value = text.getText(start, end - 1);
- int s = value.lastIndexOf(' ');
- if (s != -1) value = value.substring(s + 1);
- int newValue = unformattedIntValue(fieldName, value, characterCount == 0, calendar.getActualMaximum(fieldName));
- if (newValue != -1) setTextField(fieldName, newValue, true, true);
- }
-}
-
-String formattedStringValue(int fieldName, int value, boolean adjust) {
- if (fieldName == Calendar.AM_PM) {
- String[] ampm = formatSymbols.getAmPmStrings();
- return ampm[value];
- }
- if (adjust) {
- if (fieldName == Calendar.HOUR && value == 0) {
- return String.valueOf(12);
- }
- if (fieldName == Calendar.MONTH) {
- return String.valueOf(value + 1);
- }
- }
- return String.valueOf(value);
-}
-
-String getComputeSizeString(int style) {
- if ((style & SWT.DATE) != 0) {
- return (style & SWT.SHORT) != 0 ? DEFAULT_SHORT_DATE_FORMAT : (style & SWT.LONG) != 0 ? DEFAULT_LONG_DATE_FORMAT : DEFAULT_MEDIUM_DATE_FORMAT;
- }
- // SWT.TIME
- return (style & SWT.SHORT) != 0 ? DEFAULT_SHORT_TIME_FORMAT : (style & SWT.LONG) != 0 ? DEFAULT_LONG_TIME_FORMAT : DEFAULT_MEDIUM_TIME_FORMAT;
-}
-
-int getFieldIndex(int fieldName) {
- for (int i = 0; i < fieldCount; i++) {
- if (fieldNames[i] == fieldName) {
- return i;
- }
- }
- return -1;
-}
-
-String getFormattedString(int style) {
- if ((style & SWT.TIME) != 0) {
- String[] ampm = formatSymbols.getAmPmStrings();
- int h = calendar.get(Calendar.HOUR); if (h == 0) h = 12;
- int m = calendar.get(Calendar.MINUTE);
- int s = calendar.get(Calendar.SECOND);
- int a = calendar.get(Calendar.AM_PM);
- if ((style & SWT.SHORT) != 0) return "" + (h < 10 ? " " : "") + h + ":" + (m < 10 ? "0" : "") + m + " " + ampm[a];
- return "" + (h < 10 ? " " : "") + h + ":" + (m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s + " " + ampm[a];
- }
- /* SWT.DATE */
- int y = calendar.get(Calendar.YEAR);
- int m = calendar.get(Calendar.MONTH) + 1;
- int d = calendar.get(Calendar.DAY_OF_MONTH);
- if ((style & SWT.SHORT) != 0) return "" + (m < 10 ? " " : "") + m + "/" + y;
- return "" + (m < 10 ? " " : "") + m + "/" + (d < 10 ? " " : "") + d + "/" + y;
-}
-
-void getDate() {
- int [] y = new int [1];
- int [] m = new int [1];
- int [] d = new int [1];
- OS.gtk_calendar_get_date(handle, y, m, d);
- year = y[0];
- month = m[0];
- day = d[0];
-}
-
-/**
- * Returns the receiver's date, or day of the month.
- * <p>
- * The first day of the month is 1, and the last day depends on the month and year.
- * </p>
- *
- * @return a positive integer beginning with 1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getDay () {
- checkWidget ();
- if ((style & SWT.CALENDAR) != 0) {
- getDate();
- return day;
- } else {
- return calendar.get(Calendar.DAY_OF_MONTH);
- }
-}
-
-/**
- * Returns the receiver's hours.
- * <p>
- * Hours is an integer between 0 and 23.
- * </p>
- *
- * @return an integer between 0 and 23
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getHours () {
- checkWidget ();
- if ((style & SWT.CALENDAR) != 0) {
- return hours;
- } else {
- return calendar.get(Calendar.HOUR_OF_DAY);
- }
-}
-
-/**
- * Returns the receiver's minutes.
- * <p>
- * Minutes is an integer between 0 and 59.
- * </p>
- *
- * @return an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinutes () {
- checkWidget ();
- if ((style & SWT.CALENDAR) != 0) {
- return minutes;
- } else {
- return calendar.get(Calendar.MINUTE);
- }
-}
-
-/**
- * Returns the receiver's month.
- * <p>
- * The first month of the year is 0, and the last month is 11.
- * </p>
- *
- * @return an integer between 0 and 11
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMonth () {
- checkWidget ();
- if ((style & SWT.CALENDAR) != 0) {
- getDate();
- return month;
- } else {
- return calendar.get(Calendar.MONTH);
- }
-}
-
-String getNameText() {
- return (style & SWT.TIME) != 0 ? getHours() + ":" + getMinutes() + ":" + getSeconds()
- : (getMonth() + 1) + "/" + getDay() + "/" + getYear();
-}
-
-/**
- * Returns the receiver's seconds.
- * <p>
- * Seconds is an integer between 0 and 59.
- * </p>
- *
- * @return an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSeconds () {
- checkWidget ();
- if ((style & SWT.CALENDAR) != 0) {
- return seconds;
- } else {
- return calendar.get(Calendar.SECOND);
- }
-}
-
-/**
- * Returns the receiver's year.
- * <p>
- * The first year is 1752 and the last year is 9999.
- * </p>
- *
- * @return an integer between 1752 and 9999
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getYear () {
- checkWidget ();
- if ((style & SWT.CALENDAR) != 0) {
- getDate();
- return year;
- } else {
- return calendar.get(Calendar.YEAR);
- }
-}
-
-int /*long*/ gtk_day_selected (int /*long*/ widget) {
- sendSelectionEvent ();
- return 0;
-}
-
-int /*long*/ gtk_day_selected_double_click (int /*long*/ widget) {
- postEvent(SWT.DefaultSelection);
- return 0;
-}
-
-int /*long*/ gtk_month_changed (int /*long*/ widget) {
- sendSelectionEvent ();
- return 0;
-}
-
-void hookEvents () {
- super.hookEvents();
- if ((style & SWT.CALENDAR) != 0) {
- OS.g_signal_connect_closure (handle, OS.day_selected, display.closures [DAY_SELECTED], false);
- OS.g_signal_connect_closure (handle, OS.day_selected_double_click, display.closures [DAY_SELECTED_DOUBLE_CLICK], false);
- OS.g_signal_connect_closure (handle, OS.month_changed, display.closures [MONTH_CHANGED], false);
- }
-}
-
-boolean isValidTime(int fieldName, int value) {
- Calendar validCalendar;
- if ((style & SWT.CALENDAR) != 0) {
- validCalendar = Calendar.getInstance();
- } else {
- validCalendar = calendar;
- }
- int min = validCalendar.getActualMinimum(fieldName);
- int max = validCalendar.getActualMaximum(fieldName);
- return value >= min && value <= max;
-}
-
-boolean isValidDate(int year, int month, int day) {
- if (year < MIN_YEAR || year > MAX_YEAR) return false;
- Calendar valid = Calendar.getInstance();
- valid.set(year, month, day);
- return valid.get(Calendar.YEAR) == year
- && valid.get(Calendar.MONTH) == month
- && valid.get(Calendar.DAY_OF_MONTH) == day;
-}
-
-void incrementField(int amount) {
- int fieldName = fieldNames[currentField];
- int value = calendar.get(fieldName);
- if (fieldName == Calendar.HOUR) {
- int max = calendar.getMaximum(Calendar.HOUR);
- int min = calendar.getMinimum(Calendar.HOUR);
- if ((value == max && amount == 1) || (value == min && amount == -1)) {
- int temp = currentField;
- currentField = getFieldIndex(Calendar.AM_PM);
- setTextField(Calendar.AM_PM, (calendar.get(Calendar.AM_PM) + 1) % 2, true, true);
- currentField = temp;
- }
- }
- setTextField(fieldName, value + amount, true, true);
-}
-
-void onKeyDown(Event event) {
- int fieldName;
- switch (event.keyCode) {
- case SWT.ARROW_RIGHT:
- case SWT.KEYPAD_DIVIDE:
- // a right arrow or a valid separator navigates to the field on the right, with wraping
- selectField((currentField + 1) % fieldCount);
- break;
- case SWT.ARROW_LEFT:
- // navigate to the field on the left, with wrapping
- int index = currentField - 1;
- selectField(index < 0 ? fieldCount - 1 : index);
- break;
- case SWT.ARROW_UP:
- case SWT.KEYPAD_ADD:
- // set the value of the current field to value + 1, with wrapping
- commitCurrentField();
- incrementField(+1);
- break;
- case SWT.ARROW_DOWN:
- case SWT.KEYPAD_SUBTRACT:
- // set the value of the current field to value - 1, with wrapping
- commitCurrentField();
- incrementField(-1);
- break;
- case SWT.HOME:
- // set the value of the current field to its minimum
- fieldName = fieldNames[currentField];
- setTextField(fieldName, calendar.getActualMinimum(fieldName), true, true);
- break;
- case SWT.END:
- // set the value of the current field to its maximum
- fieldName = fieldNames[currentField];
- setTextField(fieldName, calendar.getActualMaximum(fieldName), true, true);
- break;
- case SWT.CR:
- postEvent(SWT.DefaultSelection);
- break;
- default:
- switch (event.character) {
- case '/':
- case ':':
- case '-':
- case '.':
- // a valid separator navigates to the field on the right, with wraping
- selectField((currentField + 1) % fieldCount);
- break;
- }
- }
-}
-
-void onFocusIn(Event event) {
- selectField(currentField);
-}
-
-void onFocusOut(Event event) {
- commitCurrentField();
-}
-
-void onMouseClick(Event event) {
- if (event.button != 1) return;
- Point sel = text.getSelection();
- for (int i = 0; i < fieldCount; i++) {
- if (fieldIndices[i].x <= sel.x && sel.x <= fieldIndices[i].y) {
- selectField(i);
- break;
- }
- }
-}
-
-void onResize(Event event) {
- Rectangle rect = getClientArea ();
- int width = rect.width;
- int height = rect.height;
- Point buttonSize = up.computeSize(SWT.DEFAULT, height);
- int buttonHeight = buttonSize.y / 2;
- text.setBounds(0, 0, width - buttonSize.x, height);
- up.setBounds(width - buttonSize.x, 0, buttonSize.x, buttonHeight);
- down.setBounds(width - buttonSize.x, buttonHeight, buttonSize.x, buttonHeight);
-}
-
-void onVerify(Event event) {
- if (ignoreVerify) return;
- event.doit = false;
- int fieldName = fieldNames[currentField];
- int start = fieldIndices[currentField].x;
- int end = fieldIndices[currentField].y;
- int length = end - start;
- String newText = event.text;
- if (fieldName == Calendar.AM_PM) {
- String[] ampm = formatSymbols.getAmPmStrings();
- if (newText.equalsIgnoreCase(ampm[Calendar.AM].substring(0, 1)) || newText.equalsIgnoreCase(ampm[Calendar.AM])) {
- setTextField(fieldName, Calendar.AM, true, false);
- } else if (newText.equalsIgnoreCase(ampm[Calendar.PM].substring(0, 1)) || newText.equalsIgnoreCase(ampm[Calendar.PM])) {
- setTextField(fieldName, Calendar.PM, true, false);
- }
- return;
- }
- if (characterCount > 0) {
- try {
- Integer.parseInt(newText);
- } catch (NumberFormatException ex) {
- return;
- }
- String value = text.getText(start, end - 1);
- int s = value.lastIndexOf(' ');
- if (s != -1) value = value.substring(s + 1);
- newText = "" + value + newText;
- }
- int newTextLength = newText.length();
- boolean first = characterCount == 0;
- characterCount = (newTextLength < length) ? newTextLength : 0;
- int max = calendar.getActualMaximum(fieldName);
- int min = calendar.getActualMinimum(fieldName);
- int newValue = unformattedIntValue(fieldName, newText, characterCount == 0, max);
- if (newValue == -1) {
- characterCount = 0;
- return;
- }
- if (first && newValue == 0 && length > 1) {
- setTextField(fieldName, newValue, false, false);
- } else if (min <= newValue && newValue <= max) {
- setTextField(fieldName, newValue, characterCount == 0, characterCount == 0);
- } else {
- if (newTextLength >= length) {
- newText = newText.substring(newTextLength - length + 1);
- newValue = unformattedIntValue(fieldName, newText, characterCount == 0, max);
- if (newValue != -1) {
- characterCount = length - 1;
- if (min <= newValue && newValue <= max) {
- setTextField(fieldName, newValue, characterCount == 0, true);
- }
- }
- }
- }
-}
-
-void releaseWidget () {
- super.releaseWidget();
- //TODO: need to do anything here?
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection, listener);
-}
-
-void selectField(int index) {
- if (index != currentField) {
- commitCurrentField();
- }
- final int start = fieldIndices[index].x;
- final int end = fieldIndices[index].y;
- Point pt = text.getSelection();
- if (index == currentField && start == pt.x && end == pt.y) return;
- currentField = index;
- display.asyncExec(new Runnable() {
- public void run() {
- if (!text.isDisposed()) {
- String value = text.getText(start, end - 1);
- int s = value.lastIndexOf(' ');
- if (s == -1) s = start;
- else s = start + s + 1;
- text.setSelection(s, end);
- }
- }
- });
-}
-
-void sendSelectionEvent () {
- int [] y = new int [1];
- int [] m = new int [1];
- int [] d = new int [1];
- OS.gtk_calendar_get_date(handle, y, m, d);
- //TODO: hours, minutes, seconds?
- if (d[0] != day ||
- m[0] != month ||
- y[0] != year) {
- year = y[0];
- month = m[0];
- day = d[0];
- postEvent (SWT.Selection);
- }
-}
-
-public void setBackground(Color color) {
- checkWidget();
- super.setBackground(color);
- if (text != null) text.setBackground(color);
-}
-
-public void setFont(Font font) {
- checkWidget();
- super.setFont(font);
- if (text != null) text.setFont(font);
- redraw();
-}
-
-public void setForeground(Color color) {
- checkWidget();
- super.setForeground(color);
- if (text != null) text.setForeground(color);
-}
-
-/*public*/ void setFormat(String string) {
- checkWidget();
- // TODO: this needs to be locale sensitive
- fieldCount = (style & SWT.DATE) != 0 ? ((style & SWT.SHORT) != 0 ? 2 : 3) : ((style & SWT.SHORT) != 0 ? 3 : 4);
- fieldIndices = new Point[fieldCount];
- fieldNames = new int[fieldCount];
- if ((style & SWT.DATE) != 0) {
- fieldNames[0] = Calendar.MONTH;
- fieldIndices[0] = new Point(0, 2);
- if ((style & SWT.SHORT) != 0) {
- fieldNames[1] = Calendar.YEAR;
- fieldIndices[1] = new Point(3, 7);
- } else {
- fieldNames[1] = Calendar.DAY_OF_MONTH;
- fieldIndices[1] = new Point(3, 5);
- fieldNames[2] = Calendar.YEAR;
- fieldIndices[2] = new Point(6, 10);
- }
- } else { /* SWT.TIME */
- fieldNames[0] = Calendar.HOUR;
- fieldIndices[0] = new Point(0, 2);
- fieldNames[1] = Calendar.MINUTE;
- fieldIndices[1] = new Point(3, 5);
- if ((style & SWT.SHORT) != 0) {
- fieldNames[2] = Calendar.AM_PM;
- fieldIndices[2] = new Point(6, 8);
- } else {
- fieldNames[2] = Calendar.SECOND;
- fieldIndices[2] = new Point(6, 8);
- fieldNames[3] = Calendar.AM_PM;
- fieldIndices[3] = new Point(9, 11);
- }
- }
-}
-
-void setField(int fieldName, int value) {
- if (calendar.get(fieldName) == value) return;
- if (fieldName == Calendar.AM_PM) {
- calendar.roll(Calendar.HOUR_OF_DAY, 12); // TODO: needs more work for setFormat and locale
- }
- calendar.set(fieldName, value);
- postEvent(SWT.Selection);
-}
-
-void setTextField(int fieldName, int value, boolean commit, boolean adjust) {
- if (commit) {
- int max = calendar.getActualMaximum(fieldName);
- int min = calendar.getActualMinimum(fieldName);
- if (fieldName == Calendar.YEAR) {
- max = MAX_YEAR;
- min = MIN_YEAR;
- /* Special case: convert 1 or 2-digit years into reasonable 4-digit years. */
- int currentYear = Calendar.getInstance().get(Calendar.YEAR);
- int currentCentury = (currentYear / 100) * 100;
- if (value < (currentYear + 30) % 100) value += currentCentury;
- else if (value < 100) value += currentCentury - 100;
- }
- if (value > max) value = min; // wrap
- if (value < min) value = max; // wrap
- }
- int start = fieldIndices[currentField].x;
- int end = fieldIndices[currentField].y;
- text.setSelection(start, end);
- String newValue = formattedStringValue(fieldName, value, adjust);
- StringBuffer buffer = new StringBuffer(newValue);
- /* Convert leading 0's into spaces. */
- int prependCount = end - start - buffer.length();
- for (int i = 0; i < prependCount; i++) {
- switch (fieldName) {
- case Calendar.MINUTE:
- case Calendar.SECOND:
- buffer.insert(0, 0);
- break;
- default:
- buffer.insert(0, ' ');
- break;
- }
- }
- newValue = buffer.toString();
- ignoreVerify = true;
- text.insert(newValue);
- ignoreVerify = false;
- selectField(currentField);
- if (commit) setField(fieldName, value);
-}
-
-/**
- * Sets the receiver's year, month, and day in a single operation.
- * <p>
- * This is the recommended way to set the date, because setting the year,
- * month, and day separately may result in invalid intermediate dates.
- * </p>
- *
- * @param year an integer between 1752 and 9999
- * @param month an integer between 0 and 11
- * @param day a positive integer beginning with 1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setDate (int year, int month, int day) {
- checkWidget ();
- if (!isValidDate(year, month, day)) return;
- if ((style & SWT.CALENDAR) != 0) {
- this.year = year;
- this.month = month;
- this.day = day;
- OS.gtk_calendar_select_month(handle, month, year);
- OS.gtk_calendar_select_day(handle, day);
- } else {
- calendar.set(year, month, day);
- updateControl();
- }
-}
-
-/**
- * Sets the receiver's date, or day of the month, to the specified day.
- * <p>
- * The first day of the month is 1, and the last day depends on the month and year.
- * If the specified day is not valid for the receiver's month and year, then it is ignored.
- * </p>
- *
- * @param day a positive integer beginning with 1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDate
- */
-public void setDay (int day) {
- checkWidget ();
- if (!isValidDate(getYear(), getMonth(), day)) return;
- if ((style & SWT.CALENDAR) != 0) {
- this.day = day;
- OS.gtk_calendar_select_day(handle, day);
- } else {
- calendar.set(Calendar.DAY_OF_MONTH, day);
- updateControl();
- }
-}
-
-/**
- * Sets the receiver's hours.
- * <p>
- * Hours is an integer between 0 and 23.
- * </p>
- *
- * @param hours an integer between 0 and 23
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHours (int hours) {
- checkWidget ();
- if (!isValidTime(Calendar.HOUR_OF_DAY, hours)) return;
- if ((style & SWT.CALENDAR) != 0) {
- this.hours = hours;
- } else {
- calendar.set(Calendar.HOUR_OF_DAY, hours);
- updateControl();
- }
-}
-
-/**
- * Sets the receiver's minutes.
- * <p>
- * Minutes is an integer between 0 and 59.
- * </p>
- *
- * @param minutes an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinutes (int minutes) {
- checkWidget ();
- if (!isValidTime(Calendar.MINUTE, minutes)) return;
- if ((style & SWT.CALENDAR) != 0) {
- this.minutes = minutes;
- } else {
- calendar.set(Calendar.MINUTE, minutes);
- updateControl();
- }
-}
-
-/**
- * Sets the receiver's month.
- * <p>
- * The first month of the year is 0, and the last month is 11.
- * If the specified month is not valid for the receiver's day and year, then it is ignored.
- * </p>
- *
- * @param month an integer between 0 and 11
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDate
- */
-public void setMonth (int month) {
- checkWidget ();
- if (!isValidDate(getYear(), month, getDay())) return;
- if ((style & SWT.CALENDAR) != 0) {
- this.month = month;
- OS.gtk_calendar_select_month(handle, month, year);
- } else {
- calendar.set(Calendar.MONTH, month);
- updateControl();
- }
-}
-
-/**
- * Sets the receiver's seconds.
- * <p>
- * Seconds is an integer between 0 and 59.
- * </p>
- *
- * @param seconds an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSeconds (int seconds) {
- checkWidget ();
- if (!isValidTime(Calendar.SECOND, seconds)) return;
- if ((style & SWT.CALENDAR) != 0) {
- this.seconds = seconds;
- } else {
- calendar.set(Calendar.SECOND, seconds);
- updateControl();
- }
-}
-
-/**
- * Sets the receiver's hours, minutes, and seconds in a single operation.
- *
- * @param hours an integer between 0 and 23
- * @param minutes an integer between 0 and 59
- * @param seconds an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setTime (int hours, int minutes, int seconds) {
- checkWidget ();
- if (!isValidTime(Calendar.HOUR_OF_DAY, hours)) return;
- if (!isValidTime(Calendar.MINUTE, minutes)) return;
- if (!isValidTime(Calendar.SECOND, seconds)) return;
- if ((style & SWT.CALENDAR) != 0) {
- this.hours = hours;
- this.minutes = minutes;
- this.seconds = seconds;
- } else {
- calendar.set(Calendar.HOUR_OF_DAY, hours);
- calendar.set(Calendar.MINUTE, minutes);
- calendar.set(Calendar.SECOND, seconds);
- updateControl();
- }
-}
-
-/**
- * Sets the receiver's year.
- * <p>
- * The first year is 1752 and the last year is 9999.
- * If the specified year is not valid for the receiver's day and month, then it is ignored.
- * </p>
- *
- * @param year an integer between 1752 and 9999
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDate
- */
-public void setYear (int year) {
- checkWidget ();
- if (!isValidDate(year, getMonth(), getDay())) return;
- if ((style & SWT.CALENDAR) != 0) {
- this.year = year;
- OS.gtk_calendar_select_month(handle, month, year);
- } else {
- calendar.set(Calendar.YEAR, year);
- updateControl();
- }
-}
-
-int unformattedIntValue(int fieldName, String newText, boolean adjust, int max) {
- int newValue;
- try {
- newValue = Integer.parseInt(newText);
- } catch (NumberFormatException ex) {
- return -1;
- }
- if (fieldName == Calendar.MONTH && adjust) {
- newValue--;
- if (newValue == -1) newValue = max;
- }
- if (fieldName == Calendar.HOUR && adjust) {
- if (newValue == 12) newValue = 0; // TODO: needs more work for setFormat and locale
- }
- return newValue;
-}
-
-public void updateControl() {
- if (text != null) {
- String string = getFormattedString(style);
- ignoreVerify = true;
- text.setText(string);
- ignoreVerify = false;
- }
- redraw();
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java
deleted file mode 100644
index 38ed5a2f6a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java
+++ /dev/null
@@ -1,752 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide the appearance and
- * behavior of <code>Shells</code>, but are not top
- * level shells or dialogs. Class <code>Shell</code>
- * shares a significant amount of code with this class,
- * and is a subclass.
- * <p>
- * IMPORTANT: This class was intended to be abstract and
- * should <em>never</em> be referenced or instantiated.
- * Instead, the class <code>Shell</code> should be used.
- * </p>
- * <p>
- * Instances are always displayed in one of the maximized,
- * minimized or normal states:
- * <ul>
- * <li>
- * When an instance is marked as <em>maximized</em>, the
- * window manager will typically resize it to fill the
- * entire visible area of the display, and the instance
- * is usually put in a state where it can not be resized
- * (even if it has style <code>RESIZE</code>) until it is
- * no longer maximized.
- * </li><li>
- * When an instance is in the <em>normal</em> state (neither
- * maximized or minimized), its appearance is controlled by
- * the style constants which were specified when it was created
- * and the restrictions of the window manager (see below).
- * </li><li>
- * When an instance has been marked as <em>minimized</em>,
- * its contents (client area) will usually not be visible,
- * and depending on the window manager, it may be
- * "iconified" (that is, replaced on the desktop by a small
- * simplified representation of itself), relocated to a
- * distinguished area of the screen, or hidden. Combinations
- * of these changes are also possible.
- * </li>
- * </ul>
- * </p>
- * Note: The styles supported by this class must be treated
- * as <em>HINT</em>s, since the window manager for the
- * desktop on which the instance is visible has ultimate
- * control over the appearance and behavior of decorations.
- * For example, some window managers only support resizable
- * windows and will always assume the RESIZE style, even if
- * it is not set.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * Class <code>SWT</code> provides two "convenience constants"
- * for the most commonly required style combinations:
- * <dl>
- * <dt><code>SHELL_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application top level shell: (that
- * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>)
- * </dd>
- * <dt><code>DIALOG_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application dialog shell: (that
- * is, <code>TITLE | CLOSE | BORDER</code>)
- * </dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see #getMinimized
- * @see #getMaximized
- * @see Shell
- * @see SWT
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Decorations extends Canvas {
- String text;
- Image image;
- Image [] images = new Image [0];
- boolean minimized, maximized;
- Menu menuBar;
- Menu [] menus;
- Control savedFocus;
- Button defaultButton, saveDefault;
- int /*long*/ accelGroup, vboxHandle;
-
-Decorations () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#TOOL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Decorations (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- if ((style & SWT.NO_TRIM) != 0) {
- style &= ~(SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX | SWT.RESIZE | SWT.BORDER);
- }
- if ((style & (SWT.MENU | SWT.MIN | SWT.MAX | SWT.CLOSE)) != 0) {
- style |= SWT.TITLE;
- }
- return style;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void _setImages (Image [] images) {
- if (images != null && images.length > 1) {
- Image [] bestImages = new Image [images.length];
- System.arraycopy (images, 0, bestImages, 0, images.length);
- sort (bestImages);
- images = bestImages;
- }
- int /*long*/ pixbufs = 0;
- if (images != null) {
- for (int i = 0; i < images.length; i++) {
- Image image = images [i];
- int /*long*/ pixbuf = Display.createPixbuf (image);
- pixbufs = OS.g_list_append (pixbufs, pixbuf);
- }
- }
- OS.gtk_window_set_icon_list (topHandle (), pixbufs);
- int /*long*/ [] data = new int /*long*/ [1];
- int /*long*/ temp = pixbufs;
- while (temp != 0) {
- OS.memmove (data, temp, OS.PTR_SIZEOF);
- OS.g_object_unref (data [0]);
- temp = OS.g_list_next (temp);
- }
- if (pixbufs != 0) OS.g_list_free (pixbufs);
-}
-
-void addMenu (Menu menu) {
- if (menus == null) menus = new Menu [4];
- for (int i=0; i<menus.length; i++) {
- if (menus [i] == null) {
- menus [i] = menu;
- return;
- }
- }
- Menu [] newMenus = new Menu [menus.length + 4];
- newMenus [menus.length] = menu;
- System.arraycopy (menus, 0, newMenus, 0, menus.length);
- menus = newMenus;
-}
-
-int compare (ImageData data1, ImageData data2) {
- if (data1.width == data2.width && data1.height == data2.height) {
- int transparent1 = data1.getTransparencyType ();
- int transparent2 = data2.getTransparencyType ();
- if (transparent1 == SWT.TRANSPARENCY_ALPHA) return -1;
- if (transparent2 == SWT.TRANSPARENCY_ALPHA) return 1;
- if (transparent1 == SWT.TRANSPARENCY_MASK) return -1;
- if (transparent2 == SWT.TRANSPARENCY_MASK) return 1;
- if (transparent1 == SWT.TRANSPARENCY_PIXEL) return -1;
- if (transparent2 == SWT.TRANSPARENCY_PIXEL) return 1;
- return 0;
- }
- return data1.width > data2.width || data1.height > data2.height ? -1 : 1;
-}
-
-Widget computeTabGroup () {
- return this;
-}
-
-Control computeTabRoot () {
- return this;
-}
-
-void createAccelGroup () {
- if (accelGroup != 0) return;
- accelGroup = OS.gtk_accel_group_new ();
- if (accelGroup == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- //FIXME - what should we do for Decorations
- int /*long*/ shellHandle = topHandle ();
- OS.gtk_window_add_accel_group (shellHandle, accelGroup);
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- text = "";
-}
-
-void destroyAccelGroup () {
- if (accelGroup == 0) return;
- int /*long*/ shellHandle = topHandle ();
- OS.gtk_window_remove_accel_group (shellHandle, accelGroup);
- //TEMPORARY CODE
-// OS.g_object_unref (accelGroup);
- accelGroup = 0;
-}
-
-void fixAccelGroup () {
- if (menuBar == null) return;
- destroyAccelGroup ();
- createAccelGroup ();
- menuBar.addAccelerators (accelGroup);
-}
-
-void fixDecorations (Decorations newDecorations, Control control, Menu [] menus) {
- if (this == newDecorations) return;
- if (control == savedFocus) savedFocus = null;
- if (control == defaultButton) defaultButton = null;
- if (control == saveDefault) saveDefault = null;
- if (menus == null) return;
- Menu menu = control.menu;
- if (menu != null) {
- int index = 0;
- while (index <menus.length) {
- if (menus [index] == menu) {
- control.setMenu (null);
- return;
- }
- index++;
- }
- menu.fixMenus (newDecorations);
- }
-}
-
-/**
- * Returns the receiver's default button if one had
- * previously been set, otherwise returns null.
- *
- * @return the default button or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDefaultButton(Button)
- */
-public Button getDefaultButton () {
- checkWidget();
- return defaultButton != null ? defaultButton : saveDefault;
-}
-
-/**
- * Returns the receiver's image if it had previously been
- * set using <code>setImage()</code>. The image is typically
- * displayed by the window manager when the instance is
- * marked as iconified, and may also be displayed somewhere
- * in the trim when the instance is in normal or maximized
- * states.
- * <p>
- * Note: This method will return null if called before
- * <code>setImage()</code> is called. It does not provide
- * access to a window manager provided, "default" image
- * even if one exists.
- * </p>
- *
- * @return the image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget ();
- return image;
-}
-
-/**
- * Returns the receiver's images if they had previously been
- * set using <code>setImages()</code>. Images are typically
- * displayed by the window manager when the instance is
- * marked as iconified, and may also be displayed somewhere
- * in the trim when the instance is in normal or maximized
- * states. Depending where the icon is displayed, the platform
- * chooses the icon with the "best" attributes. It is expected
- * that the array will contain the same icon rendered at different
- * sizes, with different depth and transparency attributes.
- *
- * <p>
- * Note: This method will return an empty array if called before
- * <code>setImages()</code> is called. It does not provide
- * access to a window manager provided, "default" image
- * even if one exists.
- * </p>
- *
- * @return the images
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Image [] getImages () {
- checkWidget ();
- if (images == null) return new Image [0];
- Image [] result = new Image [images.length];
- System.arraycopy (images, 0, result, 0, images.length);
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver is currently
- * maximized, and false otherwise.
- * <p>
- *
- * @return the maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMaximized
- */
-public boolean getMaximized () {
- checkWidget();
- return maximized;
-}
-
-/**
- * Returns the receiver's menu bar if one had previously
- * been set, otherwise returns null.
- *
- * @return the menu bar or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenuBar () {
- checkWidget();
- return menuBar;
-}
-
-/**
- * Returns <code>true</code> if the receiver is currently
- * minimized, and false otherwise.
- * <p>
- *
- * @return the minimized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMinimized
- */
-public boolean getMinimized () {
- checkWidget();
- return minimized;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which is the string that the
- * window manager will typically display as the receiver's
- * <em>title</em>. If the text has not previously been set,
- * returns an empty string.
- *
- * @return the text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- return text;
-}
-
-public boolean isReparentable () {
- checkWidget ();
- return false;
-}
-
-boolean isTabGroup () {
- return true;
-}
-
-boolean isTabItem () {
- return false;
-}
-
-Decorations menuShell () {
- return this;
-}
-
-void removeMenu (Menu menu) {
- if (menus == null) return;
- for (int i=0; i<menus.length; i++) {
- if (menus [i] == menu) {
- menus [i] = null;
- return;
- }
- }
-}
-
-void releaseChildren (boolean destroy) {
- if (menuBar != null) {
- menuBar.release (false);
- menuBar = null;
- }
- super.releaseChildren (destroy);
- if (menus != null) {
- for (int i=0; i<menus.length; i++) {
- Menu menu = menus [i];
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- }
- menus = null;
- }
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- vboxHandle = 0;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- image = null;
- images = null;
- savedFocus = null;
- defaultButton = saveDefault = null;
-}
-
-boolean restoreFocus () {
- if (savedFocus != null && savedFocus.isDisposed ()) savedFocus = null;
- boolean restored = savedFocus != null && savedFocus.setFocus ();
- savedFocus = null;
- /*
- * This code is intentionally commented. When no widget
- * has been given focus, some platforms give focus to the
- * default button. Motif doesn't do this.
- */
-// if (restored) return true;
-// if (defaultButton != null && !defaultButton.isDisposed ()) {
-// if (defaultButton.setFocus ()) return true;
-// }
-// return false;
- return restored;
-}
-
-/**
- * If the argument is not null, sets the receiver's default
- * button to the argument, and if the argument is null, sets
- * the receiver's default button to the first button which
- * was set as the receiver's default button (called the
- * <em>saved default button</em>). If no default button had
- * previously been set, or the saved default button was
- * disposed, the receiver's default button will be set to
- * null.
- * <p>
- * The default button is the button that is selected when
- * the receiver is active and the user presses ENTER.
- * </p>
- *
- * @param button the new default button
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the button has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDefaultButton (Button button) {
- checkWidget();
- int /*long*/ buttonHandle = 0;
- if (button != null) {
- if (button.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (button.menuShell () != this) error (SWT.ERROR_INVALID_PARENT);
- buttonHandle = button.handle;
- }
- saveDefault = defaultButton = button;
- OS.gtk_window_set_default (topHandle (), buttonHandle);
-}
-
-/**
- * Sets the receiver's image to the argument, which may
- * be null. The image is typically displayed by the window
- * manager when the instance is marked as iconified, and
- * may also be displayed somewhere in the trim when the
- * instance is in normal or maximized states.
- *
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- this.image = image;
- _setImages (image != null ? new Image [] {image} : null);
-}
-
-/**
- * Sets the receiver's images to the argument, which may
- * be an empty array. Images are typically displayed by the
- * window manager when the instance is marked as iconified,
- * and may also be displayed somewhere in the trim when the
- * instance is in normal or maximized states. Depending where
- * the icon is displayed, the platform chooses the icon with
- * the "best" attributes. It is expected that the array will
- * contain the same icon rendered at different sizes, with
- * different depth and transparency attributes.
- *
- * @param images the new image array
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images is null or has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setImages (Image [] images) {
- checkWidget ();
- if (images == null) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i = 0; i < images.length; i++) {
- if (images [i] == null || images [i].isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.images = images;
- _setImages (images);
-}
-
-/**
- * Sets the maximized state of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the maximized state, and if the argument is
- * <code>false</code> and the receiver was previously maximized,
- * causes the receiver to switch back to either the minimized
- * or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setMaximized(true)</code>
- * and <code>setMinimized(true)</code> will vary by platform. Typically,
- * the behavior will match the platform user's expectations, but not
- * always. This should be avoided if possible.
- * </p>
- *
- * @param maximized the new maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMinimized
- */
-public void setMaximized (boolean maximized) {
- checkWidget();
- this.maximized = maximized;
-}
-
-/**
- * Sets the receiver's menu bar to the argument, which
- * may be null.
- *
- * @param menu the new menu bar
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenuBar (Menu menu) {
- checkWidget();
- if (menuBar == menu) return;
- if (menu != null) {
- if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR);
- if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
- menuBar = menu;
-}
-
-/**
- * Sets the minimized stated of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the minimized state, and if the argument is
- * <code>false</code> and the receiver was previously minimized,
- * causes the receiver to switch back to either the maximized
- * or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setMaximized(true)</code>
- * and <code>setMinimized(true)</code> will vary by platform. Typically,
- * the behavior will match the platform user's expectations, but not
- * always. This should be avoided if possible.
- * </p>
- *
- * @param minimized the new maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMaximized
- */
-public void setMinimized (boolean minimized) {
- checkWidget();
- this.minimized = minimized;
-}
-
-void setSavedFocus (Control control) {
- if (this == control) return;
- savedFocus = control;
-}
-
-/**
- * Sets the receiver's text, which is the string that the
- * window manager will typically display as the receiver's
- * <em>title</em>, to the argument, which must not be null.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- text = string;
-}
-
-void sort (Image [] images) {
- /* Shell Sort from K&R, pg 108 */
- int length = images.length;
- if (length <= 1) return;
- ImageData [] datas = new ImageData [length];
- for (int i = 0; i < length; i++) {
- datas [i] = images [i].getImageData ();
- }
- for (int gap=length/2; gap>0; gap/=2) {
- for (int i=gap; i<length; i++) {
- for (int j=i-gap; j>=0; j-=gap) {
- if (compare (datas [j], datas [j + gap]) >= 0) {
- Image swap = images [j];
- images [j] = images [j + gap];
- images [j + gap] = swap;
- ImageData swapData = datas [j];
- datas [j] = datas [j + gap];
- datas [j + gap] = swapData;
- }
- }
- }
- }
-}
-
-boolean traverseItem (boolean next) {
- return false;
-}
-
-boolean traverseReturn () {
- Button button = defaultButton != null ? defaultButton: saveDefault;
- if (button == null || button.isDisposed ()) return false;
- /*
- * Bug in GTK. When a default button that is disabled is
- * activated using the Enter key, GTK GP's. The fix is to
- * detect this case and stop GTK from processing the Enter
- * key.
- */
- if (!button.isVisible () || !button.isEnabled ()) return true;
- int /*long*/ shellHandle = _getShell ().topHandle ();
- return OS.gtk_window_activate_default (shellHandle);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java
deleted file mode 100644
index 8b31222fad..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java
+++ /dev/null
@@ -1,339 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-
-/**
- * Instances of this class allow the user to navigate
- * the file system and select a directory.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#directorydialog">DirectoryDialog snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class DirectoryDialog extends Dialog {
- String message = "", filterPath = "";
- static final String SEPARATOR = System.getProperty ("file.separator");
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public DirectoryDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public DirectoryDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-/**
- * Returns the path which the dialog will use to filter
- * the directories it shows.
- *
- * @return the filter path
- *
- * @see #setFilterPath
- */
-public String getFilterPath () {
- return filterPath;
-}
-/**
- * Returns the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @return the message
- */
-public String getMessage () {
- return message;
-}
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a string describing the absolute path of the selected directory,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public String open () {
- boolean useChooserDialog = OS.GTK_VERSION >= OS.VERSION (2, 4, 10);
- if (useChooserDialog) {
- return openChooserDialog ();
- } else {
- return openClassicDialog ();
- }
-}
-String openChooserDialog () {
- byte [] titleBytes = Converter.wcsToMbcs (null, title, true);
- int /*long*/ shellHandle = parent.topHandle ();
- Display display = parent != null ? parent.getDisplay (): Display.getCurrent ();
- int /*long*/ handle = 0;
- if (display.getDismissalAlignment() == SWT.RIGHT) {
- handle = OS.gtk_file_chooser_dialog_new (titleBytes, shellHandle, OS.GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, OS.GTK_STOCK_CANCEL (), OS.GTK_RESPONSE_CANCEL, OS.GTK_STOCK_OK (), OS.GTK_RESPONSE_OK, 0);
- } else {
- handle = OS.gtk_file_chooser_dialog_new (titleBytes, shellHandle, OS.GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, OS.GTK_STOCK_OK (), OS.GTK_RESPONSE_OK, OS.GTK_STOCK_CANCEL (), OS.GTK_RESPONSE_CANCEL, 0);
- }
- OS.gtk_window_set_modal (handle, true);
- int /*long*/ pixbufs = OS.gtk_window_get_icon_list (shellHandle);
- if (pixbufs != 0) {
- OS.gtk_window_set_icon_list (handle, pixbufs);
- OS.g_list_free (pixbufs);
- }
- if (filterPath != null && filterPath.length () > 0) {
- StringBuffer stringBuffer = new StringBuffer ();
- /* filename must be a full path */
- if (!filterPath.startsWith (SEPARATOR)) {
- stringBuffer.append (SEPARATOR);
- }
- stringBuffer.append (filterPath);
- byte [] buffer = Converter.wcsToMbcs (null, stringBuffer.toString (), true);
- /*
- * Bug in GTK. GtkFileChooser may crash on GTK versions 2.4.10 to 2.6
- * when setting a file name that is not a true canonical path.
- * The fix is to use the canonical path.
- */
- int /*long*/ ptr = OS.realpath (buffer, null);
- if (ptr != 0) {
- OS.gtk_file_chooser_set_current_folder (handle, ptr);
- OS.g_free (ptr);
- }
- }
- if (message.length () > 0) {
- byte [] buffer = Converter.wcsToMbcs (null, message, true);
- int /*long*/ box = OS.gtk_hbox_new (false, 0);
- if (box == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ label = OS.gtk_label_new (buffer);
- if (label == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (box, label);
- OS.gtk_widget_show (label);
- OS.gtk_label_set_line_wrap (label, true);
- OS.gtk_label_set_justify (label, OS.GTK_JUSTIFY_CENTER);
- OS.gtk_file_chooser_set_extra_widget (handle, box);
- }
- String answer = null;
- display.addIdleProc ();
- Dialog oldModal = null;
- if (OS.gtk_window_get_modal (handle)) {
- oldModal = display.getModalDialog ();
- display.setModalDialog (this);
- }
- int signalId = 0;
- int /*long*/ hookId = 0;
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- signalId = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET());
- hookId = OS.g_signal_add_emission_hook (signalId, 0, display.emissionProc, handle, 0);
- }
- int response = OS.gtk_dialog_run (handle);
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- OS.g_signal_remove_emission_hook (signalId, hookId);
- }
- if (OS.gtk_window_get_modal (handle)) {
- display.setModalDialog (oldModal);
- }
- if (response == OS.GTK_RESPONSE_OK) {
- int /*long*/ path = OS.gtk_file_chooser_get_filename (handle);
- if (path != 0) {
- int /*long*/ utf8Ptr = OS.g_filename_to_utf8 (path, -1, null, null, null);
- OS.g_free (path);
- if (utf8Ptr != 0) {
- int /*long*/ [] items_written = new int /*long*/ [1];
- int /*long*/ utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null);
- OS.g_free (utf8Ptr);
- if (utf16Ptr != 0) {
- int clength = (int)/*64*/items_written [0];
- char [] chars = new char [clength];
- OS.memmove (chars, utf16Ptr, clength * 2);
- OS.g_free (utf16Ptr);
- answer = new String (chars);
- filterPath = answer;
- }
- }
- }
- }
- display.removeIdleProc ();
- OS.gtk_widget_destroy (handle);
- return answer;
-}
-String openClassicDialog () {
- byte [] titleBytes = Converter.wcsToMbcs (null, title, true);
- int /*long*/ handle = OS.gtk_file_selection_new (titleBytes);
- if (parent != null) {
- int /*long*/ shellHandle = parent.topHandle ();
- OS.gtk_window_set_transient_for (handle, shellHandle);
- int /*long*/ pixbufs = OS.gtk_window_get_icon_list (shellHandle);
- if (pixbufs != 0) {
- OS.gtk_window_set_icon_list (handle, pixbufs);
- OS.g_list_free (pixbufs);
- }
- }
- OS.gtk_window_set_modal (handle, true);
- String answer = null;
- if (filterPath != null) {
- String path = filterPath;
- if (path.length () > 0 && !path.endsWith (SEPARATOR)) {
- path += SEPARATOR;
- }
- int length = path.length ();
- char [] buffer = new char [length + 1];
- path.getChars (0, length, buffer, 0);
- int /*long*/ utf8Ptr = OS.g_utf16_to_utf8 (buffer, -1, null, null, null);
- int /*long*/ fileNamePtr = OS.g_filename_from_utf8 (utf8Ptr, -1, null, null, null);
- OS.gtk_file_selection_set_filename (handle, fileNamePtr);
- OS.g_free (utf8Ptr);
- OS.g_free (fileNamePtr);
- }
- GtkFileSelection selection = new GtkFileSelection ();
- OS.memmove (selection, handle);
- OS.gtk_file_selection_hide_fileop_buttons (handle);
- int /*long*/ fileListParent = OS.gtk_widget_get_parent (selection.file_list);
- OS.gtk_widget_hide (selection.file_list);
- OS.gtk_widget_hide (fileListParent);
- if (message.length () > 0) {
- byte [] buffer = Converter.wcsToMbcs (null, message, true);
- int /*long*/ labelHandle = OS.gtk_label_new (buffer);
- OS.gtk_label_set_line_wrap (labelHandle, true);
- OS.gtk_misc_set_alignment (labelHandle, 0.0f, 0.0f);
- OS.gtk_container_add (selection.main_vbox, labelHandle);
- OS.gtk_box_set_child_packing (
- selection.main_vbox, labelHandle, false, false, 0, OS.GTK_PACK_START);
- OS.gtk_widget_show (labelHandle);
- }
- Display display = parent != null ? parent.getDisplay (): Display.getCurrent ();
- display.addIdleProc ();
- Dialog oldModal = null;
- if (OS.gtk_window_get_modal (handle)) {
- oldModal = display.getModalDialog ();
- display.setModalDialog (this);
- }
- int signalId = 0;
- int /*long*/ hookId = 0;
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- signalId = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET());
- hookId = OS.g_signal_add_emission_hook (signalId, 0, display.emissionProc, handle, 0);
- }
- int response = OS.gtk_dialog_run (handle);
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- OS.g_signal_remove_emission_hook (signalId, hookId);
- }
- if (OS.gtk_window_get_modal (handle)) {
- display.setModalDialog (oldModal);
- }
- if (response == OS.GTK_RESPONSE_OK) {
- int /*long*/ fileNamePtr = OS.gtk_file_selection_get_filename (handle);
- int /*long*/ utf8Ptr = OS.g_filename_to_utf8 (fileNamePtr, -1, null, null, null);
- if (utf8Ptr != 0) {
- int /*long*/ [] items_written = new int /*long*/ [1];
- int /*long*/ utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null);
- if (utf16Ptr != 0) {
- int length = (int)/*64*/items_written [0];
- char [] buffer = new char [length];
- OS.memmove (buffer, utf16Ptr, length * 2);
- String osAnswer = new String (buffer);
- if (osAnswer != null) {
- /* remove trailing separator, unless root directory */
- if (!osAnswer.equals (SEPARATOR) && osAnswer.endsWith (SEPARATOR)) {
- osAnswer = osAnswer.substring (0, osAnswer.length () - 1);
- }
- answer = filterPath = osAnswer;
- }
- OS.g_free (utf16Ptr);
- }
- OS.g_free (utf8Ptr);
- }
- }
- display.removeIdleProc ();
- OS.gtk_widget_destroy (handle);
- return answer;
-}
-/**
- * Sets the path that the dialog will use to filter
- * the directories it shows to the argument, which may
- * be null. If the string is null, then the operating
- * system's default filter path will be used.
- * <p>
- * Note that the path string is platform dependent.
- * For convenience, either '/' or '\' can be used
- * as a path separator.
- * </p>
- *
- * @param string the filter path
- */
-public void setFilterPath (String string) {
- filterPath = string;
-}
-/**
- * Sets the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @param string the message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- */
-public void setMessage (String string) {
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- message = string;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
deleted file mode 100644
index 0e1945fe3e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
+++ /dev/null
@@ -1,4212 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are responsible for managing the
- * connection between SWT and the underlying operating
- * system. Their most important function is to implement
- * the SWT event loop in terms of the platform event model.
- * They also provide various methods for accessing information
- * about the operating system, and have overall control over
- * the operating system resources which SWT allocates.
- * <p>
- * Applications which are built with SWT will <em>almost always</em>
- * require only a single display. In particular, some platforms
- * which SWT supports will not allow more than one <em>active</em>
- * display. In other words, some platforms do not support
- * creating a new display if one already exists that has not been
- * sent the <code>dispose()</code> message.
- * <p>
- * In SWT, the thread which creates a <code>Display</code>
- * instance is distinguished as the <em>user-interface thread</em>
- * for that display.
- * </p>
- * The user-interface thread for a particular display has the
- * following special attributes:
- * <ul>
- * <li>
- * The event loop for that display must be run from the thread.
- * </li>
- * <li>
- * Some SWT API methods (notably, most of the public methods in
- * <code>Widget</code> and its subclasses), may only be called
- * from the thread. (To support multi-threaded user-interface
- * applications, class <code>Display</code> provides inter-thread
- * communication methods which allow threads other than the
- * user-interface thread to request that it perform operations
- * on their behalf.)
- * </li>
- * <li>
- * The thread is not allowed to construct other
- * <code>Display</code>s until that display has been disposed.
- * (Note that, this is in addition to the restriction mentioned
- * above concerning platform support for multiple displays. Thus,
- * the only way to have multiple simultaneously active displays,
- * even on platforms which support it, is to have multiple threads.)
- * </li>
- * </ul>
- * Enforcing these attributes allows SWT to be implemented directly
- * on the underlying operating system's event model. This has
- * numerous benefits including smaller footprint, better use of
- * resources, safer memory management, clearer program logic,
- * better performance, and fewer overall operating system threads
- * required. The down side however, is that care must be taken
- * (only) when constructing multi-threaded applications to use the
- * inter-thread communication mechanisms which this class provides
- * when required.
- * </p><p>
- * All SWT API methods which may only be called from the user-interface
- * thread are distinguished in their documentation by indicating that
- * they throw the "<code>ERROR_THREAD_INVALID_ACCESS</code>"
- * SWT exception.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Close, Dispose, Settings</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- * @see #syncExec
- * @see #asyncExec
- * @see #wake
- * @see #readAndDispatch
- * @see #sleep
- * @see Device#dispose
- * @see <a href="http://www.eclipse.org/swt/snippets/#display">Display snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Display extends Device {
-
- /* Events Dispatching and Callback */
- int gdkEventCount;
- int /*long*/ [] gdkEvents;
- Widget [] gdkEventWidgets;
- int [] dispatchEvents;
- Event [] eventQueue;
- int /*long*/ fds;
- int allocated_nfds;
- boolean wake;
- int [] max_priority = new int [1], timeout = new int [1];
- Callback eventCallback, filterCallback;
- int /*long*/ eventProc, filterProc, windowProc2, windowProc3, windowProc4, windowProc5;
- Callback windowCallback2, windowCallback3, windowCallback4, windowCallback5;
- EventTable eventTable, filterTable;
- static String APP_NAME = "SWT"; //$NON-NLS-1$
- static final String DISPATCH_EVENT_KEY = "org.eclipse.swt.internal.gtk.dispatchEvent"; //$NON-NLS-1$
- static final String ADD_WIDGET_KEY = "org.eclipse.swt.internal.addWidget"; //$NON-NLS-1$
- int /*long*/ [] closures;
- int [] signalIds;
- int /*long*/ shellMapProcClosure;
-
- /* Widget Table */
- int [] indexTable;
- int freeSlot;
- int /*long*/ lastHandle;
- Widget lastWidget;
- Widget [] widgetTable;
- final static int GROW_SIZE = 1024;
- static final int SWT_OBJECT_INDEX;
- static final int SWT_OBJECT_INDEX1;
- static final int SWT_OBJECT_INDEX2;
- static {
- byte [] buffer = Converter.wcsToMbcs (null, "SWT_OBJECT_INDEX", true); //$NON-NLS-1$
- SWT_OBJECT_INDEX = OS.g_quark_from_string (buffer);
- buffer = Converter.wcsToMbcs (null, "SWT_OBJECT_INDEX1", true); //$NON-NLS-1$
- SWT_OBJECT_INDEX1 = OS.g_quark_from_string (buffer);
- buffer = Converter.wcsToMbcs (null, "SWT_OBJECT_INDEX2", true); //$NON-NLS-1$
- SWT_OBJECT_INDEX2 = OS.g_quark_from_string (buffer);
- }
-
- /* Modality */
- Shell [] modalShells;
- Dialog modalDialog;
- static final String GET_MODAL_DIALOG = "org.eclipse.swt.internal.gtk.getModalDialog"; //$NON-NLS-1$
- static final String SET_MODAL_DIALOG = "org.eclipse.swt.internal.gtk.setModalDialog"; //$NON-NLS-1$
-
- /* Focus */
- int focusEvent;
- Control focusControl;
- Shell activeShell;
- boolean activePending;
- boolean ignoreActivate, ignoreFocus;
-
- /* Input method resources */
- Control imControl;
- int /*long*/ preeditWindow, preeditLabel;
-
- /* Sync/Async Widget Communication */
- Synchronizer synchronizer = new Synchronizer (this);
- Thread thread;
-
- /* Display Shutdown */
- Runnable [] disposeList;
-
- /* System Tray */
- Tray tray;
-
- /* Timers */
- int [] timerIds;
- Runnable [] timerList;
- Callback timerCallback;
- int /*long*/ timerProc;
- Callback windowTimerCallback;
- int /*long*/ windowTimerProc;
-
- /* Caret */
- Caret currentCaret;
- Callback caretCallback;
- int caretId;
- int /*long*/ caretProc;
-
- /* Mnemonics */
- Control mnemonicControl;
-
- /* Mouse hover */
- int mouseHoverId;
- int /*long*/ mouseHoverHandle, mouseHoverProc;
- Callback mouseHoverCallback;
-
- /* Menu position callback */
- int /*long*/ menuPositionProc;
- Callback menuPositionCallback;
-
- /* Tooltip size allocate callback */
- int /*long*/ sizeAllocateProc;
- Callback sizeAllocateCallback;
- int /*long*/ sizeRequestProc;
- Callback sizeRequestCallback;
-
- /* Shell map callback */
- int /*long*/ shellMapProc;
- Callback shellMapCallback;
-
- /* Idle proc callback */
- int /*long*/ idleProc;
- int idleHandle;
- Callback idleCallback;
- static final String ADD_IDLE_PROC_KEY = "org.eclipse.swt.internal.gtk.addIdleProc"; //$NON-NLS-1$
- static final String REMOVE_IDLE_PROC_KEY = "org.eclipse.swt.internal.gtk.removeIdleProc"; //$NON-NLS-1$
- Object idleLock = new Object();
- boolean idleNeeded;
-
- /* GtkTreeView callbacks */
- int[] treeSelection;
- int treeSelectionLength;
- int /*long*/ treeSelectionProc;
- Callback treeSelectionCallback;
- int /*long*/ cellDataProc;
- Callback cellDataCallback;
-
- /* Set direction callback */
- int /*long*/ setDirectionProc;
- Callback setDirectionCallback;
- static final String GET_DIRECTION_PROC_KEY = "org.eclipse.swt.internal.gtk.getDirectionProc"; //$NON-NLS-1$
-
- /* Set emissionProc callback */
- int /*long*/ emissionProc;
- Callback emissionProcCallback;
- static final String GET_EMISSION_PROC_KEY = "org.eclipse.swt.internal.gtk.getEmissionProc"; //$NON-NLS-1$
-
- /* Get all children callback */
- int /*long*/ allChildrenProc, allChildren;
- Callback allChildrenCallback;
-
- /* Settings callbacks */
- int /*long*/ styleSetProc;
- Callback styleSetCallback;
- int /*long*/ shellHandle;
- boolean settingsChanged, runSettings;
-
- /* Entry focus behaviour */
- boolean entrySelectOnFocus;
-
- /* Enter/Exit events */
- Control currentControl;
-
- /* Flush exposes */
- int /*long*/ checkIfEventProc;
- Callback checkIfEventCallback;
- int /*long*/ flushWindow;
- boolean flushAll;
- GdkRectangle flushRect = new GdkRectangle ();
- XExposeEvent exposeEvent = new XExposeEvent ();
- XVisibilityEvent visibilityEvent = new XVisibilityEvent ();
- int /*long*/ [] flushData = new int /*long*/ [1];
-
- /* System Resources */
- Font systemFont;
- Image errorImage, infoImage, questionImage, warningImage;
- Cursor [] cursors = new Cursor [SWT.CURSOR_HAND + 1];
- Resource [] resources;
- static final int RESOURCE_SIZE = 1 + 4 + SWT.CURSOR_HAND + 1;
-
- /* Colors */
- GdkColor COLOR_WIDGET_DARK_SHADOW, COLOR_WIDGET_NORMAL_SHADOW, COLOR_WIDGET_LIGHT_SHADOW;
- GdkColor COLOR_WIDGET_HIGHLIGHT_SHADOW, COLOR_WIDGET_BACKGROUND, COLOR_WIDGET_FOREGROUND, COLOR_WIDGET_BORDER;
- GdkColor COLOR_LIST_FOREGROUND, COLOR_LIST_BACKGROUND, COLOR_LIST_SELECTION, COLOR_LIST_SELECTION_TEXT;
- GdkColor COLOR_INFO_BACKGROUND, COLOR_INFO_FOREGROUND;
- GdkColor COLOR_TITLE_FOREGROUND, COLOR_TITLE_BACKGROUND, COLOR_TITLE_BACKGROUND_GRADIENT;
- GdkColor COLOR_TITLE_INACTIVE_FOREGROUND, COLOR_TITLE_INACTIVE_BACKGROUND, COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT;
-
- /* Popup Menus */
- Menu [] popups;
-
- /* Click count*/
- int clickCount = 1;
-
- /* Entry inner border */
- static final int INNER_BORDER = 2;
-
- /* Timestamp of the Last Received Events */
- int lastEventTime, lastUserEventTime;
-
- /* Pango layout constructor */
- int /*long*/ pangoLayoutNewProc, pangoLayoutNewDefaultProc;
- Callback pangoLayoutNewCallback;
-
- /* Fixed Subclass */
- static int /*long*/ fixed_type;
- static int /*long*/ fixed_info_ptr;
- static Callback fixedClassInitCallback, fixedMapCallback, fixedSizeAllocateCallback;
- static int /*long*/ fixedClassInitProc, fixedMapProc, fixedSizeAllocateProc, oldFixedSizeAllocateProc;
-
- /* Renderer Subclass */
- static int /*long*/ text_renderer_type, pixbuf_renderer_type, toggle_renderer_type;
- static int /*long*/ text_renderer_info_ptr, pixbuf_renderer_info_ptr, toggle_renderer_info_ptr;
- static Callback rendererClassInitCallback, rendererRenderCallback, rendererGetSizeCallback;
- static int /*long*/ rendererClassInitProc, rendererRenderProc, rendererGetSizeProc;
-
- /* Key Mappings */
- static final int [] [] KeyTable = {
-
- /* Keyboard and Mouse Masks */
- {OS.GDK_Alt_L, SWT.ALT},
- {OS.GDK_Alt_R, SWT.ALT},
- {OS.GDK_Meta_L, SWT.ALT},
- {OS.GDK_Meta_R, SWT.ALT},
- {OS.GDK_Shift_L, SWT.SHIFT},
- {OS.GDK_Shift_R, SWT.SHIFT},
- {OS.GDK_Control_L, SWT.CONTROL},
- {OS.GDK_Control_R, SWT.CONTROL},
-// {OS.GDK_????, SWT.COMMAND},
-// {OS.GDK_????, SWT.COMMAND},
-
- /* Non-Numeric Keypad Keys */
- {OS.GDK_Up, SWT.ARROW_UP},
- {OS.GDK_KP_Up, SWT.ARROW_UP},
- {OS.GDK_Down, SWT.ARROW_DOWN},
- {OS.GDK_KP_Down, SWT.ARROW_DOWN},
- {OS.GDK_Left, SWT.ARROW_LEFT},
- {OS.GDK_KP_Left, SWT.ARROW_LEFT},
- {OS.GDK_Right, SWT.ARROW_RIGHT},
- {OS.GDK_KP_Right, SWT.ARROW_RIGHT},
- {OS.GDK_Page_Up, SWT.PAGE_UP},
- {OS.GDK_KP_Page_Up, SWT.PAGE_UP},
- {OS.GDK_Page_Down, SWT.PAGE_DOWN},
- {OS.GDK_KP_Page_Down, SWT.PAGE_DOWN},
- {OS.GDK_Home, SWT.HOME},
- {OS.GDK_KP_Home, SWT.HOME},
- {OS.GDK_End, SWT.END},
- {OS.GDK_KP_End, SWT.END},
- {OS.GDK_Insert, SWT.INSERT},
- {OS.GDK_KP_Insert, SWT.INSERT},
-
- /* Virtual and Ascii Keys */
- {OS.GDK_BackSpace, SWT.BS},
- {OS.GDK_Return, SWT.CR},
- {OS.GDK_Delete, SWT.DEL},
- {OS.GDK_KP_Delete, SWT.DEL},
- {OS.GDK_Escape, SWT.ESC},
- {OS.GDK_Linefeed, SWT.LF},
- {OS.GDK_Tab, SWT.TAB},
- {OS.GDK_ISO_Left_Tab, SWT.TAB},
-
- /* Functions Keys */
- {OS.GDK_F1, SWT.F1},
- {OS.GDK_F2, SWT.F2},
- {OS.GDK_F3, SWT.F3},
- {OS.GDK_F4, SWT.F4},
- {OS.GDK_F5, SWT.F5},
- {OS.GDK_F6, SWT.F6},
- {OS.GDK_F7, SWT.F7},
- {OS.GDK_F8, SWT.F8},
- {OS.GDK_F9, SWT.F9},
- {OS.GDK_F10, SWT.F10},
- {OS.GDK_F11, SWT.F11},
- {OS.GDK_F12, SWT.F12},
- {OS.GDK_F13, SWT.F13},
- {OS.GDK_F14, SWT.F14},
- {OS.GDK_F15, SWT.F15},
-
- /* Numeric Keypad Keys */
- {OS.GDK_KP_Multiply, SWT.KEYPAD_MULTIPLY},
- {OS.GDK_KP_Add, SWT.KEYPAD_ADD},
- {OS.GDK_KP_Enter, SWT.KEYPAD_CR},
- {OS.GDK_KP_Subtract, SWT.KEYPAD_SUBTRACT},
- {OS.GDK_KP_Decimal, SWT.KEYPAD_DECIMAL},
- {OS.GDK_KP_Divide, SWT.KEYPAD_DIVIDE},
- {OS.GDK_KP_0, SWT.KEYPAD_0},
- {OS.GDK_KP_1, SWT.KEYPAD_1},
- {OS.GDK_KP_2, SWT.KEYPAD_2},
- {OS.GDK_KP_3, SWT.KEYPAD_3},
- {OS.GDK_KP_4, SWT.KEYPAD_4},
- {OS.GDK_KP_5, SWT.KEYPAD_5},
- {OS.GDK_KP_6, SWT.KEYPAD_6},
- {OS.GDK_KP_7, SWT.KEYPAD_7},
- {OS.GDK_KP_8, SWT.KEYPAD_8},
- {OS.GDK_KP_9, SWT.KEYPAD_9},
- {OS.GDK_KP_Equal, SWT.KEYPAD_EQUAL},
-
- /* Other keys */
- {OS.GDK_Caps_Lock, SWT.CAPS_LOCK},
- {OS.GDK_Num_Lock, SWT.NUM_LOCK},
- {OS.GDK_Scroll_Lock, SWT.SCROLL_LOCK},
- {OS.GDK_Pause, SWT.PAUSE},
- {OS.GDK_Break, SWT.BREAK},
- {OS.GDK_Print, SWT.PRINT_SCREEN},
- {OS.GDK_Help, SWT.HELP},
-
- };
-
- /* Multiple Displays. */
- static Display Default;
- static Display [] Displays = new Display [4];
-
- /* Package name */
- static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets."; //$NON-NLS-1$
- /* This code is intentionally commented.
- * ".class" can not be used on CLDC.
- */
-// static {
-// String name = Display.class.getName ();
-// int index = name.lastIndexOf ('.');
-// PACKAGE_NAME = name.substring (0, index + 1);
-// }
-
- /* GTK Version */
- static final int MAJOR = 2;
- static final int MINOR = 2;
- static final int MICRO = 0;
-
- /* Display Data */
- Object data;
- String [] keys;
- Object [] values;
-
- /* Initial Guesses for Shell Trimmings. */
- int borderTrimWidth = 4, borderTrimHeight = 4;
- int resizeTrimWidth = 6, resizeTrimHeight = 6;
- int titleBorderTrimWidth = 5, titleBorderTrimHeight = 28;
- int titleResizeTrimWidth = 6, titleResizeTrimHeight = 29;
- int titleTrimWidth = 0, titleTrimHeight = 23;
- boolean ignoreTrim;
-
- /* Window Manager */
- String windowManager;
-
- /*
- * TEMPORARY CODE. Install the runnable that
- * gets the current display. This code will
- * be removed in the future.
- */
- static {
- DeviceFinder = new Runnable () {
- public void run () {
- Device device = getCurrent ();
- if (device == null) {
- device = getDefault ();
- }
- setDevice (device);
- }
- };
- }
-
-/*
-* TEMPORARY CODE.
-*/
-static void setDevice (Device device) {
- CurrentDevice = device;
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * Note: The resulting display is marked as the <em>current</em>
- * display. If this is the first display which has been
- * constructed since the application started, it is also
- * marked as the <em>default</em> display.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if called from a thread that already created an existing display</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see #getCurrent
- * @see #getDefault
- * @see Widget#checkSubclass
- * @see Shell
- */
-public Display () {
- this (null);
-}
-
-/**
- * Constructs a new instance of this class using the parameter.
- *
- * @param data the device data
- */
-public Display (DeviceData data) {
- super (data);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs anywhere
- * in a widget. The event type is one of the event constants
- * defined in class <code>SWT</code>. When the event does occur,
- * the listener is notified by sending it the <code>handleEvent()</code>
- * message.
- * <p>
- * Setting the type of an event to <code>SWT.None</code> from
- * within the <code>handleEvent()</code> method can be used to
- * change the event type and stop subsequent Java listeners
- * from running. Because event filters run before other listeners,
- * event filters can both block other listeners and set arbitrary
- * fields within an event. For this reason, event filters are both
- * powerful and dangerous. They should generally be avoided for
- * performance, debugging and code maintenance reasons.
- * </p>
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #removeFilter
- * @see #removeListener
- *
- * @since 3.0
- */
-public void addFilter (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (filterTable == null) filterTable = new EventTable ();
- filterTable.hook (eventType, listener);
-}
-
-void addGdkEvent (int /*long*/ event) {
- if (gdkEvents == null) {
- int length = GROW_SIZE;
- gdkEvents = new int /*long*/ [length];
- gdkEventWidgets = new Widget [length];
- gdkEventCount = 0;
- }
- if (gdkEventCount == gdkEvents.length) {
- int length = gdkEventCount + GROW_SIZE;
- int /*long*/ [] newEvents = new int /*long*/ [length];
- System.arraycopy (gdkEvents, 0, newEvents, 0, gdkEventCount);
- gdkEvents = newEvents;
- Widget [] newWidgets = new Widget [length];
- System.arraycopy (gdkEventWidgets, 0, newWidgets, 0, gdkEventCount);
- gdkEventWidgets = newWidgets;
- }
- Widget widget = null;
- int /*long*/ handle = OS.gtk_get_event_widget (event);
- if (handle != 0) {
- do {
- widget = getWidget (handle);
- } while (widget == null && (handle = OS.gtk_widget_get_parent (handle)) != 0);
- }
- gdkEvents [gdkEventCount] = event;
- gdkEventWidgets [gdkEventCount] = widget;
- gdkEventCount++;
-}
-
-void addIdleProc() {
- synchronized (idleLock){
- this.idleNeeded = true;
- if (idleHandle == 0) {
- idleHandle = OS.g_idle_add (idleProc, 0);
- }
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- * When the event does occur in the display, the listener is notified by
- * sending it the <code>handleEvent()</code> message.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #removeListener
- *
- * @since 2.0
- */
-public void addListener (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) eventTable = new EventTable ();
- eventTable.hook (eventType, listener);
-}
-
-int /*long*/ allChildrenProc (int /*long*/ widget, int /*long*/ recurse) {
- allChildren = OS.g_list_append (allChildren, widget);
- if (recurse != 0 && OS.GTK_IS_CONTAINER (widget)) {
- OS.gtk_container_forall (widget, allChildrenProc, recurse);
- }
- return 0;
-}
-
-void addMouseHoverTimeout (int /*long*/ handle) {
- if (mouseHoverId != 0) OS.gtk_timeout_remove (mouseHoverId);
- mouseHoverId = OS.gtk_timeout_add (400, mouseHoverProc, handle);
- mouseHoverHandle = handle;
-}
-
-void addPopup (Menu menu) {
- if (popups == null) popups = new Menu [4];
- int length = popups.length;
- for (int i=0; i<length; i++) {
- if (popups [i] == menu) return;
- }
- int index = 0;
- while (index < length) {
- if (popups [index] == null) break;
- index++;
- }
- if (index == length) {
- Menu [] newPopups = new Menu [length + 4];
- System.arraycopy (popups, 0, newPopups, 0, length);
- popups = newPopups;
- }
- popups [index] = menu;
-}
-
-void addWidget (int /*long*/ handle, Widget widget) {
- if (handle == 0) return;
- if (freeSlot == -1) {
- int length = (freeSlot = indexTable.length) + GROW_SIZE;
- int[] newIndexTable = new int[length];
- Widget[] newWidgetTable = new Widget [length];
- System.arraycopy (indexTable, 0, newIndexTable, 0, freeSlot);
- System.arraycopy (widgetTable, 0, newWidgetTable, 0, freeSlot);
- for (int i = freeSlot; i < length - 1; i++) {
- newIndexTable[i] = i + 1;
- }
- newIndexTable[length - 1] = -1;
- indexTable = newIndexTable;
- widgetTable = newWidgetTable;
- }
- int index = freeSlot + 1;
- OS.g_object_set_qdata (handle, SWT_OBJECT_INDEX, index);
- int oldSlot = freeSlot;
- freeSlot = indexTable[oldSlot];
- indexTable [oldSlot] = -2;
- widgetTable [oldSlot] = widget;
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread at the next
- * reasonable opportunity. The caller of this method continues
- * to run in parallel, and is not notified when the
- * runnable has completed. Specifying <code>null</code> as the
- * runnable simply wakes the user-interface thread when run.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param runnable code to run on the user-interface thread or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #syncExec
- */
-public void asyncExec (Runnable runnable) {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- synchronized (idleLock) {
- if (idleNeeded && idleHandle == 0) {
- //NOTE: calling unlocked function in OS
- idleHandle = OS._g_idle_add (idleProc, 0);
- }
- }
- synchronizer.asyncExec (runnable);
- }
-}
-
-/**
- * Causes the system hardware to emit a short sound
- * (if it supports this capability).
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void beep () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- OS.gdk_beep();
- if (!OS.GDK_WINDOWING_X11 ()) {
- OS.gdk_flush ();
- } else {
- int /*long*/ xDisplay = OS.GDK_DISPLAY ();
- OS.XFlush (xDisplay);
- }
-}
-
-int /*long*/ cellDataProc (int /*long*/ tree_column, int /*long*/ cell, int /*long*/ tree_model, int /*long*/ iter, int /*long*/ data) {
- Widget widget = getWidget (data);
- if (widget == null) return 0;
- return widget.cellDataProc (tree_column, cell, tree_model, iter, data);
-}
-
-protected void checkDevice () {
- if (thread == null) error (SWT.ERROR_WIDGET_DISPOSED);
- if (thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
-}
-
-static void checkDisplay (Thread thread, boolean multiple) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] != null) {
- if (!multiple) SWT.error (SWT.ERROR_NOT_IMPLEMENTED, null, " [multiple displays]"); //$NON-NLS-1$
- if (Displays [i].thread == thread) SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- }
- }
-}
-
-int /*long*/ checkIfEventProc (int /*long*/ display, int /*long*/ xEvent, int /*long*/ userData) {
- int type = OS.X_EVENT_TYPE (xEvent);
- switch (type) {
- case OS.VisibilityNotify:
- case OS.Expose:
- case OS.GraphicsExpose:
- break;
- default:
- return 0;
- }
- int /*long*/ window = OS.gdk_window_lookup (OS.X_EVENT_WINDOW (xEvent));
- if (window == 0) return 0;
- if (flushWindow != 0) {
- if (flushAll) {
- int /*long*/ tempWindow = window;
- do {
- if (tempWindow == flushWindow) break;
- } while ((tempWindow = OS.gdk_window_get_parent (tempWindow)) != 0);
- if (tempWindow != flushWindow) return 0;
- } else {
- if (window != flushWindow) return 0;
- }
- }
- OS.memmove (exposeEvent, xEvent, XExposeEvent.sizeof);
- switch (type) {
- case OS.Expose:
- case OS.GraphicsExpose: {
- flushRect.x = exposeEvent.x;
- flushRect.y = exposeEvent.y;
- flushRect.width = exposeEvent.width;
- flushRect.height = exposeEvent.height;
- OS.gdk_window_invalidate_rect (window, flushRect, true);
- exposeEvent.type = -1;
- OS.memmove (xEvent, exposeEvent, XExposeEvent.sizeof);
- break;
- }
- case OS.VisibilityNotify: {
- OS.memmove (visibilityEvent, xEvent, XVisibilityEvent.sizeof);
- OS.gdk_window_get_user_data (window, flushData);
- int /*long*/ handle = flushData [0];
- Widget widget = handle != 0 ? getWidget (handle) : null;
- if (widget != null && widget instanceof Control) {
- Control control = (Control) widget;
- if (window == control.paintWindow ()) {
- if (visibilityEvent.state == OS.VisibilityFullyObscured) {
- control.state |= Widget.OBSCURED;
- } else {
- control.state &= ~Widget.OBSCURED;
- }
- }
- }
- break;
- }
- }
- return 0;
-}
-
-/**
- * Checks that this class can be subclassed.
- * <p>
- * IMPORTANT: See the comment in <code>Widget.checkSubclass()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- */
-protected void checkSubclass () {
- if (!isValidClass (getClass ())) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void clearModal (Shell shell) {
- if (modalShells == null) return;
- int index = 0, length = modalShells.length;
- while (index < length) {
- if (modalShells [index] == shell) break;
- if (modalShells [index] == null) return;
- index++;
- }
- if (index == length) return;
- System.arraycopy (modalShells, index + 1, modalShells, index, --length - index);
- modalShells [length] = null;
- if (index == 0 && modalShells [0] == null) modalShells = null;
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) shells [i].updateModal ();
-}
-
-/**
- * Requests that the connection between SWT and the underlying
- * operating system be closed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Device#dispose
- *
- * @since 2.0
- */
-public void close () {
- checkDevice ();
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- if (event.doit) dispose ();
-}
-
-/**
- * Creates the device in the operating system. If the device
- * does not have a handle, this method may do nothing depending
- * on the device.
- * <p>
- * This method is called before <code>init</code>.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #init
- */
-protected void create (DeviceData data) {
- checkSubclass ();
- checkDisplay(thread = Thread.currentThread (), false);
- createDisplay (data);
- register (this);
- if (Default == null) Default = this;
-}
-
-void createDisplay (DeviceData data) {
- /* Required for g_main_context_wakeup */
- if (!OS.g_thread_supported ()) {
- OS.g_thread_init (0);
- }
- OS.gtk_set_locale();
- if (!OS.gtk_init_check (new int /*long*/ [] {0}, null)) {
- SWT.error (SWT.ERROR_NO_HANDLES, null, " [gtk_init_check() failed]"); //$NON-NLS-1$
- }
- if (OS.GDK_WINDOWING_X11 ()) xDisplay = OS.GDK_DISPLAY ();
- int /*long*/ ptr = OS.gtk_check_version (MAJOR, MINOR, MICRO);
- if (ptr != 0) {
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, length);
- System.out.println ("***WARNING: " + new String (Converter.mbcsToWcs (null, buffer))); //$NON-NLS-1$
- System.out.println ("***WARNING: SWT requires GTK " + MAJOR+ "." + MINOR + "." + MICRO); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- int major = OS.gtk_major_version (), minor = OS.gtk_minor_version (), micro = OS.gtk_micro_version ();
- System.out.println ("***WARNING: Detected: " + major + "." + minor + "." + micro); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- if (fixed_type == 0) {
- byte [] type_name = Converter.wcsToMbcs (null, "SwtFixed", true); //$NON-NLS-1$
- fixedClassInitCallback = new Callback (getClass (), "fixedClassInitProc", 2); //$NON-NLS-1$
- fixedClassInitProc = fixedClassInitCallback.getAddress ();
- if (fixedClassInitProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- fixedMapCallback = new Callback (getClass (), "fixedMapProc", 1); //$NON-NLS-1$
- fixedMapProc = fixedMapCallback.getAddress ();
- if (fixedMapProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- fixedSizeAllocateCallback = new Callback (getClass (), "fixedSizeAllocateProc", 2); //$NON-NLS-1$
- fixedSizeAllocateProc = fixedSizeAllocateCallback.getAddress ();
- if (fixedSizeAllocateProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- GTypeInfo fixed_info = new GTypeInfo ();
- fixed_info.class_size = (short) OS.GtkFixedClass_sizeof ();
- fixed_info.class_init = fixedClassInitProc;
- fixed_info.instance_size = (short) OS.GtkFixed_sizeof ();
- fixed_info_ptr = OS.g_malloc (GTypeInfo.sizeof);
- OS.memmove (fixed_info_ptr, fixed_info, GTypeInfo.sizeof);
- fixed_type = OS.g_type_register_static (OS.GTK_TYPE_FIXED (), type_name, fixed_info_ptr, 0);
- }
- if (rendererClassInitProc == 0) {
- rendererClassInitCallback = new Callback (getClass (), "rendererClassInitProc", 2); //$NON-NLS-1$
- rendererClassInitProc = rendererClassInitCallback.getAddress ();
- if (rendererClassInitProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- }
- if (rendererRenderProc == 0) {
- rendererRenderCallback = new Callback (getClass (), "rendererRenderProc", 7); //$NON-NLS-1$
- rendererRenderProc = rendererRenderCallback.getAddress ();
- if (rendererRenderProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- }
- if (rendererGetSizeProc == 0) {
- rendererGetSizeCallback = new Callback (getClass (), "rendererGetSizeProc", 7); //$NON-NLS-1$
- rendererGetSizeProc = rendererGetSizeCallback.getAddress ();
- if (rendererGetSizeProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- }
- if (text_renderer_type == 0) {
- GTypeInfo renderer_info = new GTypeInfo ();
- renderer_info.class_size = (short) OS.GtkCellRendererTextClass_sizeof ();
- renderer_info.class_init = rendererClassInitProc;
- renderer_info.instance_size = (short) OS.GtkCellRendererText_sizeof ();
- text_renderer_info_ptr = OS.g_malloc (GTypeInfo.sizeof);
- OS.memmove (text_renderer_info_ptr, renderer_info, GTypeInfo.sizeof);
- byte [] type_name = Converter.wcsToMbcs (null, "SwtTextRenderer", true); //$NON-NLS-1$
- text_renderer_type = OS.g_type_register_static (OS.GTK_TYPE_CELL_RENDERER_TEXT (), type_name, text_renderer_info_ptr, 0);
- }
- if (pixbuf_renderer_type == 0) {
- GTypeInfo renderer_info = new GTypeInfo ();
- renderer_info.class_size = (short) OS.GtkCellRendererPixbufClass_sizeof ();
- renderer_info.class_init = rendererClassInitProc;
- renderer_info.instance_size = (short) OS.GtkCellRendererPixbuf_sizeof ();
- pixbuf_renderer_info_ptr = OS.g_malloc (GTypeInfo.sizeof);
- OS.memmove (pixbuf_renderer_info_ptr, renderer_info, GTypeInfo.sizeof);
- byte [] type_name = Converter.wcsToMbcs (null, "SwtPixbufRenderer", true); //$NON-NLS-1$
- pixbuf_renderer_type = OS.g_type_register_static (OS.GTK_TYPE_CELL_RENDERER_PIXBUF (), type_name, pixbuf_renderer_info_ptr, 0);
- }
- if (toggle_renderer_type == 0) {
- GTypeInfo renderer_info = new GTypeInfo ();
- renderer_info.class_size = (short) OS.GtkCellRendererToggleClass_sizeof ();
- renderer_info.class_init = rendererClassInitProc;
- renderer_info.instance_size = (short) OS.GtkCellRendererToggle_sizeof ();
- toggle_renderer_info_ptr = OS.g_malloc (GTypeInfo.sizeof);
- OS.memmove (toggle_renderer_info_ptr, renderer_info, GTypeInfo.sizeof);
- byte [] type_name = Converter.wcsToMbcs (null, "SwtToggleRenderer", true); //$NON-NLS-1$
- toggle_renderer_type = OS.g_type_register_static (OS.GTK_TYPE_CELL_RENDERER_TOGGLE (), type_name, toggle_renderer_info_ptr, 0);
- }
-
- OS.gtk_widget_set_default_direction (OS.GTK_TEXT_DIR_LTR);
- OS.gdk_rgb_init ();
- byte [] buffer = Converter.wcsToMbcs (null, APP_NAME, true);
- OS.g_set_prgname (buffer);
- OS.gdk_set_program_class (buffer);
- byte [] flatStyle = Converter.wcsToMbcs (null, "style \"swt-flat\" { GtkToolbar::shadow-type = none } widget \"*.swt-toolbar-flat\" style : highest \"swt-flat\"", true); //$NON-NLS-1$
- OS.gtk_rc_parse_string (flatStyle);
-
- /* Initialize the hidden shell */
- shellHandle = OS.gtk_window_new (OS.GTK_WINDOW_TOPLEVEL);
- if (shellHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- OS.gtk_widget_realize (shellHandle);
-
- /* Initialize the filter and event callback */
- eventCallback = new Callback (this, "eventProc", 2); //$NON-NLS-1$
- eventProc = eventCallback.getAddress ();
- if (eventProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- OS.gdk_event_handler_set (eventProc, 0, 0);
- filterCallback = new Callback (this, "filterProc", 3); //$NON-NLS-1$
- filterProc = filterCallback.getAddress ();
- if (filterProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- OS.gdk_window_add_filter (0, filterProc, 0);
-}
-
-Image createImage (String name) {
- int /*long*/ style = OS.gtk_widget_get_default_style ();
- byte[] buffer = Converter.wcsToMbcs (null, name, true);
- int /*long*/ pixbuf = OS.gtk_icon_set_render_icon (
- OS.gtk_icon_factory_lookup_default (buffer), style,
- OS.GTK_TEXT_DIR_NONE, OS.GTK_STATE_NORMAL, OS.GTK_ICON_SIZE_DIALOG, 0, 0);
- if (pixbuf == 0) return null;
- int width = OS.gdk_pixbuf_get_width (pixbuf);
- int height = OS.gdk_pixbuf_get_height (pixbuf);
- int stride = OS.gdk_pixbuf_get_rowstride (pixbuf);
- boolean hasAlpha = OS.gdk_pixbuf_get_has_alpha (pixbuf);
- int /*long*/ pixels = OS.gdk_pixbuf_get_pixels (pixbuf);
- byte [] data = new byte [stride * height];
- OS.memmove (data, pixels, data.length);
- OS.g_object_unref (pixbuf);
- ImageData imageData = null;
- if (hasAlpha) {
- PaletteData palette = new PaletteData (0xFF000000, 0xFF0000, 0xFF00);
- imageData = new ImageData (width, height, 32, palette);
- byte [] alpha = new byte [stride * height];
- for (int y=0; y<height; y++) {
- for (int x=0; x<width; x++) {
- alpha [y*width+x] = data [y*stride+x*4+3];
- data [y*stride+x*4+3] = 0;
- }
- }
- imageData.setAlphas (0, 0, width * height, alpha, 0);
- } else {
- PaletteData palette = new PaletteData (0xFF0000, 0xFF00, 0xFF);
- imageData = new ImageData (width, height, 24, palette);
- }
- imageData.data = data;
- imageData.bytesPerLine = stride;
- return new Image (this, imageData);
-}
-
-static int /*long*/ createPixbuf(Image image) {
- int [] w = new int [1], h = new int [1];
- OS.gdk_drawable_get_size (image.pixmap, w, h);
- int /*long*/ colormap = OS.gdk_colormap_get_system ();
- int /*long*/ pixbuf;
- boolean hasMask = image.mask != 0 && OS.gdk_drawable_get_depth (image.mask) == 1;
- if (hasMask) {
- pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, true, 8, w [0], h [0]);
- if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w [0], h [0]);
- int /*long*/ maskPixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, w [0], h [0]);
- if (maskPixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- OS.gdk_pixbuf_get_from_drawable(maskPixbuf, image.mask, 0, 0, 0, 0, 0, w [0], h [0]);
- int stride = OS.gdk_pixbuf_get_rowstride(pixbuf);
- int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf);
- byte[] line = new byte[stride];
- int maskStride = OS.gdk_pixbuf_get_rowstride(maskPixbuf);
- int /*long*/ maskPixels = OS.gdk_pixbuf_get_pixels(maskPixbuf);
- byte[] maskLine = new byte[maskStride];
- for (int y=0; y<h[0]; y++) {
- int /*long*/ offset = pixels + (y * stride);
- OS.memmove(line, offset, stride);
- int /*long*/ maskOffset = maskPixels + (y * maskStride);
- OS.memmove(maskLine, maskOffset, maskStride);
- for (int x=0; x<w[0]; x++) {
- if (maskLine[x * 3] == 0) {
- line[x * 4 + 3] = 0;
- }
- }
- OS.memmove(offset, line, stride);
- }
- OS.g_object_unref(maskPixbuf);
- } else {
- ImageData data = image.getImageData ();
- boolean hasAlpha = data.getTransparencyType () == SWT.TRANSPARENCY_ALPHA;
- pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, hasAlpha, 8, w [0], h [0]);
- if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w [0], h [0]);
- if (hasAlpha) {
- byte [] alpha = data.alphaData;
- int stride = OS.gdk_pixbuf_get_rowstride (pixbuf);
- int /*long*/ pixels = OS.gdk_pixbuf_get_pixels (pixbuf);
- byte [] line = new byte [stride];
- for (int y = 0; y < h [0]; y++) {
- int /*long*/ offset = pixels + (y * stride);
- OS.memmove (line, offset, stride);
- for (int x = 0; x < w [0]; x++) {
- line [x*4+3] = alpha [y*w [0]+x];
- }
- OS.memmove (offset, line, stride);
- }
- }
- }
- return pixbuf;
-}
-
-static void deregister (Display display) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (display == Displays [i]) Displays [i] = null;
- }
- }
-}
-
-/**
- * Destroys the device in the operating system and releases
- * the device's handle. If the device does not have a handle,
- * this method may do nothing depending on the device.
- * <p>
- * This method is called after <code>release</code>.
- * </p>
- * @see Device#dispose
- * @see #release
- */
-protected void destroy () {
- if (this == Default) Default = null;
- deregister (this);
- destroyDisplay ();
-}
-
-void destroyDisplay () {
-}
-
-int /*long*/ emissionProc (int /*long*/ ihint, int /*long*/ n_param_values, int /*long*/ param_values, int /*long*/ data) {
- if (OS.gtk_widget_get_toplevel (OS.g_value_peek_pointer(param_values)) == data) {
- OS.gtk_widget_set_direction (OS.g_value_peek_pointer(param_values), OS.GTK_TEXT_DIR_RTL);
- }
- return 1;
-}
-
-/**
- * Returns the display which the given thread is the
- * user-interface thread for, or null if the given thread
- * is not a user-interface thread for any display. Specifying
- * <code>null</code> as the thread will return <code>null</code>
- * for the display.
- *
- * @param thread the user-interface thread
- * @return the display for the given thread
- */
-public static Display findDisplay (Thread thread) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- Display display = Displays [i];
- if (display != null && display.thread == thread) {
- return display;
- }
- }
- return null;
- }
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread just before the
- * receiver is disposed. Specifying a <code>null</code> runnable
- * is ignored.
- *
- * @param runnable code to run at dispose time.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void disposeExec (Runnable runnable) {
- checkDevice ();
- if (disposeList == null) disposeList = new Runnable [4];
- for (int i=0; i<disposeList.length; i++) {
- if (disposeList [i] == null) {
- disposeList [i] = runnable;
- return;
- }
- }
- Runnable [] newDisposeList = new Runnable [disposeList.length + 4];
- System.arraycopy (disposeList, 0, newDisposeList, 0, disposeList.length);
- newDisposeList [disposeList.length] = runnable;
- disposeList = newDisposeList;
-}
-
-/**
- * Does whatever display specific cleanup is required, and then
- * uses the code in <code>SWTError.error</code> to handle the error.
- *
- * @param code the descriptive error code
- *
- * @see SWTError#error
- */
-void error (int code) {
- SWT.error (code);
-}
-
-int /*long*/ eventProc (int /*long*/ event, int /*long*/ data) {
- /*
- * Use gdk_event_get_time() rather than event.time or
- * gtk_get_current_event_time(). If the event does not
- * have a time stamp, then the field will contain garbage.
- * Note that calling gtk_get_current_event_time() from
- * outside of gtk_main_do_event() seems to always
- * return zero.
- */
- int time = OS.gdk_event_get_time (event);
- if (time != 0) lastEventTime = time;
-
- int eventType = OS.GDK_EVENT_TYPE (event);
- switch (eventType) {
- case OS.GDK_BUTTON_PRESS:
- case OS.GDK_KEY_PRESS:
- lastUserEventTime = time;
- }
- boolean dispatch = true;
- if (dispatchEvents != null) {
- dispatch = false;
- for (int i = 0; i < dispatchEvents.length; i++) {
- if (eventType == dispatchEvents [i]) {
- dispatch = true;
- break;
- }
- }
- }
- if (!dispatch) {
- addGdkEvent (OS.gdk_event_copy (event));
- return 0;
- }
- OS.gtk_main_do_event (event);
- if (dispatchEvents == null) putGdkEvents ();
- return 0;
-}
-
-/**
- * Given the operating system handle for a widget, returns
- * the instance of the <code>Widget</code> subclass which
- * represents it in the currently running application, if
- * such exists, or null if no matching widget can be found.
- * <p>
- * <b>IMPORTANT:</b> This method should not be called from
- * application code. The arguments are platform-specific.
- * </p>
- *
- * @param handle the handle for the widget
- * @return the SWT widget that the handle represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Widget findWidget (int /*long*/ handle) {
- checkDevice ();
- return getWidget (handle);
-}
-
-/**
- * Given the operating system handle for a widget,
- * and widget-specific id, returns the instance of
- * the <code>Widget</code> subclass which represents
- * the handle/id pair in the currently running application,
- * if such exists, or null if no matching widget can be found.
- * <p>
- * <b>IMPORTANT:</b> This method should not be called from
- * application code. The arguments are platform-specific.
- * </p>
- *
- * @param handle the handle for the widget
- * @param id the id for the subwidget (usually an item)
- * @return the SWT widget that the handle/id pair represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public Widget findWidget (int /*long*/ handle, int /*long*/ id) {
- checkDevice ();
- return null;
-}
-
-/**
- * Given a widget and a widget-specific id, returns the
- * instance of the <code>Widget</code> subclass which represents
- * the widget/id pair in the currently running application,
- * if such exists, or null if no matching widget can be found.
- *
- * @param widget the widget
- * @param id the id for the subwidget (usually an item)
- * @return the SWT subwidget (usually an item) that the widget/id pair represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.3
- */
-public Widget findWidget (Widget widget, int /*long*/ id) {
- checkDevice ();
- return null;
-}
-
-static int /*long*/ fixedClassInitProc (int /*long*/ g_class, int /*long*/ class_data) {
- GtkWidgetClass klass = new GtkWidgetClass ();
- OS.memmove (klass, g_class);
- klass.map = fixedMapProc;
- oldFixedSizeAllocateProc = klass.size_allocate;
- klass.size_allocate = fixedSizeAllocateProc;
- OS.memmove (g_class, klass);
- return 0;
-}
-
-static int /*long*/ fixedMapProc (int /*long*/ handle) {
- Display display = getCurrent ();
- Widget widget = display.getWidget (handle);
- if (widget != null) return widget.fixedMapProc (handle);
- return 0;
-}
-
-static int /*long*/ fixedSizeAllocateProc (int /*long*/ handle, int /*long*/ allocation) {
- Display display = getCurrent ();
- Widget widget = display.getWidget (handle);
- if (widget != null) return widget.fixedSizeAllocateProc (handle, allocation);
- return OS.Call (oldFixedSizeAllocateProc, handle, allocation);
-}
-
-static int /*long*/ rendererClassInitProc (int /*long*/ g_class, int /*long*/ class_data) {
- GtkCellRendererClass klass = new GtkCellRendererClass ();
- OS.memmove (klass, g_class);
- klass.render = rendererRenderProc;
- klass.get_size = rendererGetSizeProc;
- OS.memmove (g_class, klass);
- return 0;
-}
-
-static int /*long*/ rendererGetSizeProc (int /*long*/ cell, int /*long*/ handle, int /*long*/ cell_area, int /*long*/ x_offset, int /*long*/ y_offset, int /*long*/ width, int /*long*/ height) {
- Display display = getCurrent ();
- Widget widget = display.getWidget (handle);
- if (widget != null) return widget.rendererGetSizeProc (cell, handle, cell_area, x_offset, y_offset, width, height);
- return 0;
-}
-
-static int /*long*/ rendererRenderProc (int /*long*/ cell, int /*long*/ window, int /*long*/ handle, int /*long*/ background_area, int /*long*/ cell_area, int /*long*/ expose_area, int /*long*/ flags) {
- Display display = getCurrent ();
- Widget widget = display.getWidget (handle);
- if (widget != null) return widget.rendererRenderProc (cell, window, handle, background_area, cell_area, expose_area, flags);
- return 0;
-}
-
-void flushExposes (int /*long*/ window, boolean all) {
- OS.gdk_flush ();
- OS.gdk_flush ();
- if (OS.GDK_WINDOWING_X11 ()) {
- this.flushWindow = window;
- this.flushAll = all;
- int /*long*/ xDisplay = OS.GDK_DISPLAY ();
- int /*long*/ xEvent = OS.g_malloc (XEvent.sizeof);
- OS.XCheckIfEvent (xDisplay, xEvent, checkIfEventProc, 0);
- OS.g_free (xEvent);
- this.flushWindow = 0;
- }
-}
-
-/**
- * Returns the currently active <code>Shell</code>, or null
- * if no shell belonging to the currently running application
- * is active.
- *
- * @return the active shell or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Shell getActiveShell () {
- checkDevice ();
- return activeShell;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location. Note that
- * on multi-monitor systems the origin can be negative.
- *
- * @return the bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkDevice ();
- return new Rectangle (0, 0, OS.gdk_screen_width (), OS.gdk_screen_height ());
-}
-
-/**
- * Returns the display which the currently running thread is
- * the user-interface thread for, or null if the currently
- * running thread is not a user-interface thread for any display.
- *
- * @return the current display
- */
-public static Display getCurrent () {
- return findDisplay (Thread.currentThread ());
-}
-
-int getCaretBlinkTime () {
-// checkDevice ();
- int /*long*/ settings = OS.gtk_settings_get_default ();
- if (settings == 0) return 500;
- int [] buffer = new int [1];
- OS.g_object_get (settings, OS.gtk_cursor_blink, buffer, 0);
- if (buffer [0] == 0) return 0;
- OS.g_object_get (settings, OS.gtk_cursor_blink_time, buffer, 0);
- if (buffer [0] == 0) return 500;
- /*
- * By experimentation, GTK application don't use the whole
- * blink cycle time. Instead, they divide up the time, using
- * an effective blink rate of about 1/2 the total time.
- */
- return buffer [0] / 2;
-}
-
-/**
- * Returns the control which the on-screen pointer is currently
- * over top of, or null if it is not currently over one of the
- * controls built by the currently running application.
- *
- * @return the control under the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Control getCursorControl () {
- checkDevice();
- int[] x = new int[1], y = new int[1];
- int /*long*/ handle = 0;
- int /*long*/ [] user_data = new int /*long*/ [1];
- int /*long*/ window = OS.gdk_window_at_pointer (x,y);
- if (window != 0) {
- OS.gdk_window_get_user_data (window, user_data);
- handle = user_data [0];
- } else {
- /*
- * Feature in GTK. gdk_window_at_pointer() will not return a window
- * if the pointer is over a foreign embedded window. The fix is to use
- * XQueryPointer to find the containing GDK window.
- */
- if (!OS.GDK_WINDOWING_X11 ()) return null;
- OS.gdk_error_trap_push ();
- int[] unusedInt = new int[1];
- int /*long*/[] unusedPtr = new int /*long*/[1], buffer = new int /*long*/[1];
- int /*long*/ xWindow, xParent = OS.XDefaultRootWindow (xDisplay);
- do {
- if (OS.XQueryPointer (xDisplay, xParent, unusedPtr, buffer, unusedInt, unusedInt, unusedInt, unusedInt, unusedInt) == 0) {
- handle = 0;
- break;
- }
- if ((xWindow = buffer [0]) != 0) {
- xParent = xWindow;
- int /*long*/ gdkWindow = OS.gdk_window_lookup (xWindow);
- if (gdkWindow != 0) {
- OS.gdk_window_get_user_data (gdkWindow, user_data);
- if (user_data[0] != 0) handle = user_data[0];
- }
- }
- } while (xWindow != 0);
- OS.gdk_error_trap_pop ();
- }
- if (handle == 0) return null;
- do {
- Widget widget = getWidget (handle);
- if (widget != null && widget instanceof Control) {
- Control control = (Control) widget;
- if (control.isEnabled ()) return control;
- }
- } while ((handle = OS.gtk_widget_get_parent (handle)) != 0);
- return null;
-}
-
-static GtkBorder getEntryInnerBorder (int /*long*/ handle) {
- GtkBorder gtkBorder = new GtkBorder();
- if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
- int /*long*/ border = OS.gtk_entry_get_inner_border (handle);
- if (border != 0) {
- OS.memmove (gtkBorder, border, GtkBorder.sizeof);
- return gtkBorder;
- }
- int /*long*/ [] borderPtr = new int /*long*/ [1];
- OS.gtk_widget_style_get (handle, OS.inner_border, borderPtr,0);
- if (borderPtr[0] != 0) {
- OS.memmove (gtkBorder, borderPtr[0], GtkBorder.sizeof);
- OS.gtk_border_free(borderPtr[0]);
- return gtkBorder;
- }
- }
- gtkBorder.left = INNER_BORDER;
- gtkBorder.top = INNER_BORDER;
- gtkBorder.right = INNER_BORDER;
- gtkBorder.bottom = INNER_BORDER;
- return gtkBorder;
-}
-
-boolean filterEvent (Event event) {
- if (filterTable != null) filterTable.sendEvent (event);
- return false;
-}
-
-boolean filters (int eventType) {
- if (filterTable == null) return false;
- return filterTable.hooks (eventType);
-}
-
-int /*long*/ filterProc (int /*long*/ xEvent, int /*long*/ gdkEvent, int /*long*/ data) {
- if (data == 0) {
- /*
- * Feature in GTK. When button 4, 5, 6, or 7 is released, GTK
- * does not deliver a corresponding GTK event. Button 6 and 7
- * are mapped to buttons 4 and 5 in SWT. The fix is to change
- * the button number of the event to a negative number so that
- * it gets dispatched by GTK. SWT has been modified to look
- * for negative button numbers.
- */
- XButtonEvent mouseEvent = new XButtonEvent ();
- OS.memmove (mouseEvent, xEvent, 4);
- if (mouseEvent.type == OS.ButtonRelease) {
- OS.memmove (mouseEvent, xEvent, XButtonEvent.sizeof);
- switch (mouseEvent.button) {
- case 6:
- case 7:
- mouseEvent.button = -mouseEvent.button;
- OS.memmove (xEvent, mouseEvent, XButtonEvent.sizeof);
- break;
- }
- }
- }
- Widget widget = getWidget (data);
- if (widget == null) return 0;
- return widget.filterProc (xEvent, gdkEvent, data);
-}
-
-/**
- * Returns the location of the on-screen pointer relative
- * to the top left corner of the screen.
- *
- * @return the cursor location
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point getCursorLocation () {
- checkDevice ();
- int [] x = new int [1], y = new int [1];
- OS.gdk_window_get_pointer (0, x, y, null);
- return new Point (x [0], y [0]);
-}
-
-/**
- * Returns an array containing the recommended cursor sizes.
- *
- * @return the array of cursor sizes
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public Point [] getCursorSizes () {
- checkDevice ();
- return new Point [] {new Point (16, 16), new Point (32, 32)};
-}
-
-/**
- * Returns the application defined property of the receiver
- * with the specified name, or null if it has not been set.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the display is disposed
- * of, it is the application's responsibility to provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param key the name of the property
- * @return the value of the property or null if it has not been set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setData(String, Object)
- * @see #disposeExec(Runnable)
- */
-public Object getData (String key) {
- checkDevice ();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (key.equals (DISPATCH_EVENT_KEY)) {
- return dispatchEvents;
- }
- if (key.equals (GET_MODAL_DIALOG)) {
- return modalDialog;
- }
- if (key.equals (GET_DIRECTION_PROC_KEY)) {
- return new LONG (setDirectionProc);
- }
- if (key.equals (GET_EMISSION_PROC_KEY)) {
- return new LONG (emissionProc);
- }
- if (keys == null) return null;
- for (int i=0; i<keys.length; i++) {
- if (keys [i].equals (key)) return values [i];
- }
- return null;
-}
-
-/**
- * Returns the application defined, display specific data
- * associated with the receiver, or null if it has not been
- * set. The <em>display specific data</em> is a single,
- * unnamed field that is stored with every display.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the display specific data needs to
- * be notified when the display is disposed of, it is the
- * application's responsibility to provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @return the display specific data
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setData(Object)
- * @see #disposeExec(Runnable)
- */
-public Object getData () {
- checkDevice ();
- return data;
-}
-
-/**
- * Returns a point whose x coordinate is the horizontal
- * dots per inch of the display, and whose y coordinate
- * is the vertical dots per inch of the display.
- *
- * @return the horizontal and vertical DPI
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getDPI () {
- checkDevice ();
- int widthMM = OS.gdk_screen_width_mm ();
- int width = OS.gdk_screen_width ();
- int dpi = Compatibility.round (254 * width, widthMM * 10);
- return new Point (dpi, dpi);
-}
-
-int /*long*/ gtk_fixed_get_type () {
- return fixed_type;
-}
-
-int /*long*/ gtk_cell_renderer_text_get_type () {
- return text_renderer_type;
-}
-
-int /*long*/ gtk_cell_renderer_pixbuf_get_type () {
- return pixbuf_renderer_type;
-}
-
-int /*long*/ gtk_cell_renderer_toggle_get_type () {
- return toggle_renderer_type;
-}
-
-/**
- * Returns the default display. One is created (making the
- * thread that invokes this method its user-interface thread)
- * if it did not already exist.
- *
- * @return the default display
- */
-public static Display getDefault () {
- synchronized (Device.class) {
- if (Default == null) Default = new Display ();
- return Default;
- }
-}
-
-static boolean isValidClass (Class clazz) {
- String name = clazz.getName ();
- int index = name.lastIndexOf ('.');
- return name.substring (0, index + 1).equals (PACKAGE_PREFIX);
-}
-
-/**
- * Returns the button dismissal alignment, one of <code>LEFT</code> or <code>RIGHT</code>.
- * The button dismissal alignment is the ordering that should be used when positioning the
- * default dismissal button for a dialog. For example, in a dialog that contains an OK and
- * CANCEL button, on platforms where the button dismissal alignment is <code>LEFT</code>, the
- * button ordering should be OK/CANCEL. When button dismissal alignment is <code>RIGHT</code>,
- * the button ordering should be CANCEL/OK.
- *
- * @return the button dismissal order
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1
- */
-public int getDismissalAlignment () {
- checkDevice ();
- int [] buffer = new int [1];
- if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) {
- int /*long*/ settings = OS.gtk_settings_get_default ();
- OS.g_object_get (settings, OS.gtk_alternative_button_order, buffer, 0);
- }
- return buffer [0] == 1 ? SWT.LEFT : SWT.RIGHT;
-}
-
-/**
- * Returns the longest duration, in milliseconds, between
- * two mouse button clicks that will be considered a
- * <em>double click</em> by the underlying operating system.
- *
- * @return the double click time
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getDoubleClickTime () {
- checkDevice ();
- int /*long*/ settings = OS.gtk_settings_get_default ();
- int [] buffer = new int [1];
- OS.g_object_get (settings, OS.gtk_double_click_time, buffer, 0);
- return buffer [0];
-}
-
-/**
- * Returns the control which currently has keyboard focus,
- * or null if keyboard events are not currently going to
- * any of the controls built by the currently running
- * application.
- *
- * @return the control under the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Control getFocusControl () {
- checkDevice ();
- if (focusControl != null && !focusControl.isDisposed ()) {
- return focusControl;
- }
- if (activeShell == null) return null;
- int /*long*/ shellHandle = activeShell.shellHandle;
- int /*long*/ handle = OS.gtk_window_get_focus (shellHandle);
- if (handle == 0) return null;
- do {
- Widget widget = getWidget (handle);
- if (widget != null && widget instanceof Control) {
- Control control = (Control) widget;
- return control.isEnabled () ? control : null;
- }
- } while ((handle = OS.gtk_widget_get_parent (handle)) != 0);
- return null;
-}
-
-/**
- * Returns true when the high contrast mode is enabled.
- * Otherwise, false is returned.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @return the high contrast mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public boolean getHighContrast () {
- checkDevice ();
- return false;
-}
-
-public int getDepth () {
- checkDevice ();
- GdkVisual visual = new GdkVisual ();
- OS.memmove (visual, OS.gdk_visual_get_system());
- return visual.depth;
-}
-
-/**
- * Returns the maximum allowed depth of icons on this display, in bits per pixel.
- * On some platforms, this may be different than the actual depth of the display.
- *
- * @return the maximum icon depth
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Device#getDepth
- */
-public int getIconDepth () {
- checkDevice ();
- return getDepth ();
-}
-
-/**
- * Returns an array containing the recommended icon sizes.
- *
- * @return the array of icon sizes
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Decorations#setImages(Image[])
- *
- * @since 3.0
- */
-public Point [] getIconSizes () {
- checkDevice ();
- return new Point [] {new Point (16, 16), new Point (32, 32)};
-}
-
-int getLastEventTime () {
- return lastEventTime;
-}
-
-int getMessageCount () {
- return synchronizer.getMessageCount ();
-}
-
-Dialog getModalDialog () {
- return modalDialog;
-}
-
-/**
- * Returns the work area, an EWMH property to store the size
- * and position of the screen not covered by dock and panel
- * windows. See http://freedesktop.org/Standards/wm-spec.
- */
-Rectangle getWorkArea() {
- byte[] name = Converter.wcsToMbcs (null, "_NET_WORKAREA", true); //$NON-NLS-1$
- int /*long*/ atom = OS.gdk_atom_intern (name, true);
- if (atom == OS.GDK_NONE) return null;
- int /*long*/[] actualType = new int /*long*/[1];
- int[] actualFormat = new int[1];
- int[] actualLength = new int[1];
- int /*long*/[] data = new int /*long*/[1];
- if (!OS.gdk_property_get (OS.GDK_ROOT_PARENT (), atom, OS.GDK_NONE, 0, 16, 0, actualType, actualFormat, actualLength, data)) {
- return null;
- }
- Rectangle result = null;
- if (data [0] != 0) {
- if (actualLength [0] == 16) {
- int values [] = new int [4];
- OS.memmove (values, data[0], 16);
- result = new Rectangle (values [0],values [1],values [2],values [3]);
- } else if (actualLength [0] == 32) {
- long values [] = new long [4];
- OS.memmove (values, data[0], 32);
- result = new Rectangle ((int)values [0],(int)values [1],(int)values [2],(int)values [3]);
- }
- OS.g_free (data [0]);
- }
- return result;
-}
-
-/**
- * Returns an array of monitors attached to the device.
- *
- * @return the array of monitors
- *
- * @since 3.0
- */
-public Monitor [] getMonitors () {
- checkDevice ();
- Monitor [] monitors = null;
- Rectangle workArea = getWorkArea();
- int /*long*/ screen = OS.gdk_screen_get_default ();
- if (screen != 0) {
- int monitorCount = OS.gdk_screen_get_n_monitors (screen);
- if (monitorCount > 0) {
- monitors = new Monitor [monitorCount];
- GdkRectangle dest = new GdkRectangle ();
- for (int i = 0; i < monitorCount; i++) {
- OS.gdk_screen_get_monitor_geometry (screen, i, dest);
- Monitor monitor = new Monitor ();
- monitor.handle = i;
- monitor.x = dest.x;
- monitor.y = dest.y;
- monitor.width = dest.width;
- monitor.height = dest.height;
- if (i == 0 && workArea != null) {
- monitor.clientX = workArea.x;
- monitor.clientY = workArea.y;
- monitor.clientWidth = workArea.width;
- monitor.clientHeight = workArea.height;
- } else {
- monitor.clientX = monitor.x;
- monitor.clientY = monitor.y;
- monitor.clientWidth = monitor.width;
- monitor.clientHeight = monitor.height;
- }
- monitors [i] = monitor;
- }
- }
- }
- if (monitors == null) {
- /* No multimonitor support detected, default to one monitor */
- Monitor monitor = new Monitor ();
- Rectangle bounds = getBounds ();
- monitor.x = bounds.x;
- monitor.y = bounds.y;
- monitor.width = bounds.width;
- monitor.height = bounds.height;
- if (workArea != null) {
- monitor.clientX = workArea.x;
- monitor.clientY = workArea.y;
- monitor.clientWidth = workArea.width;
- monitor.clientHeight = workArea.height;
- } else {
- monitor.clientX = monitor.x;
- monitor.clientY = monitor.y;
- monitor.clientWidth = monitor.width;
- monitor.clientHeight = monitor.height;
- }
- monitors = new Monitor [] { monitor };
- }
- return monitors;
-}
-
-/**
- * Returns the primary monitor for that device.
- *
- * @return the primary monitor
- *
- * @since 3.0
- */
-public Monitor getPrimaryMonitor () {
- checkDevice ();
- Monitor [] monitors = getMonitors ();
- return monitors [0];
-}
-
-/**
- * Returns a (possibly empty) array containing all shells which have
- * not been disposed and have the receiver as their display.
- *
- * @return the receiver's shells
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Shell [] getShells () {
- checkDevice ();
- int index = 0;
- Shell [] result = new Shell [16];
- for (int i = 0; i < widgetTable.length; i++) {
- Widget widget = widgetTable [i];
- if (widget != null && widget instanceof Shell) {
- int j = 0;
- while (j < index) {
- if (result [j] == widget) break;
- j++;
- }
- if (j == index) {
- if (index == result.length) {
- Shell [] newResult = new Shell [index + 16];
- System.arraycopy (result, 0, newResult, 0, index);
- result = newResult;
- }
- result [index++] = (Shell) widget;
- }
- }
- }
- if (index == result.length) return result;
- Shell [] newResult = new Shell [index];
- System.arraycopy (result, 0, newResult, 0, index);
- return newResult;
-}
-
-/**
- * Gets the synchronizer used by the display.
- *
- * @return the receiver's synchronizer
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public Synchronizer getSynchronizer () {
- checkDevice ();
- return synchronizer;
-}
-
-/**
- * Returns the thread that has invoked <code>syncExec</code>
- * or null if no such runnable is currently being invoked by
- * the user-interface thread.
- * <p>
- * Note: If a runnable invoked by asyncExec is currently
- * running, this method will return null.
- * </p>
- *
- * @return the receiver's sync-interface thread
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Thread getSyncThread () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- return synchronizer.syncThread;
- }
-}
-
-/**
- * Returns the matching standard color for the given
- * constant, which should be one of the color constants
- * specified in class <code>SWT</code>. Any value other
- * than one of the SWT color constants which is passed
- * in will result in the color black. This color should
- * not be free'd because it was allocated by the system,
- * not the application.
- *
- * @param id the color constant
- * @return the matching color
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT
- */
-public Color getSystemColor (int id) {
- checkDevice ();
- GdkColor gdkColor = null;
- switch (id) {
- case SWT.COLOR_INFO_FOREGROUND: gdkColor = COLOR_INFO_FOREGROUND; break;
- case SWT.COLOR_INFO_BACKGROUND: gdkColor = COLOR_INFO_BACKGROUND; break;
- case SWT.COLOR_TITLE_FOREGROUND: gdkColor = COLOR_TITLE_FOREGROUND; break;
- case SWT.COLOR_TITLE_BACKGROUND: gdkColor = COLOR_TITLE_BACKGROUND; break;
- case SWT.COLOR_TITLE_BACKGROUND_GRADIENT: gdkColor = COLOR_TITLE_BACKGROUND_GRADIENT; break;
- case SWT.COLOR_TITLE_INACTIVE_FOREGROUND: gdkColor = COLOR_TITLE_INACTIVE_FOREGROUND; break;
- case SWT.COLOR_TITLE_INACTIVE_BACKGROUND: gdkColor = COLOR_TITLE_INACTIVE_BACKGROUND; break;
- case SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT: gdkColor = COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT; break;
- case SWT.COLOR_WIDGET_DARK_SHADOW: gdkColor = COLOR_WIDGET_DARK_SHADOW; break;
- case SWT.COLOR_WIDGET_NORMAL_SHADOW: gdkColor = COLOR_WIDGET_NORMAL_SHADOW; break;
- case SWT.COLOR_WIDGET_LIGHT_SHADOW: gdkColor = COLOR_WIDGET_LIGHT_SHADOW; break;
- case SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: gdkColor = COLOR_WIDGET_HIGHLIGHT_SHADOW; break;
- case SWT.COLOR_WIDGET_BACKGROUND: gdkColor = COLOR_WIDGET_BACKGROUND; break;
- case SWT.COLOR_WIDGET_FOREGROUND: gdkColor = COLOR_WIDGET_FOREGROUND; break;
- case SWT.COLOR_WIDGET_BORDER: gdkColor = COLOR_WIDGET_BORDER; break;
- case SWT.COLOR_LIST_FOREGROUND: gdkColor = COLOR_LIST_FOREGROUND; break;
- case SWT.COLOR_LIST_BACKGROUND: gdkColor = COLOR_LIST_BACKGROUND; break;
- case SWT.COLOR_LIST_SELECTION: gdkColor = COLOR_LIST_SELECTION; break;
- case SWT.COLOR_LIST_SELECTION_TEXT: gdkColor = COLOR_LIST_SELECTION_TEXT; break;
- default:
- return super.getSystemColor (id);
- }
- if (gdkColor == null) return super.getSystemColor (SWT.COLOR_BLACK);
- return Color.gtk_new (this, gdkColor);
-}
-
-/**
- * Returns the matching standard platform cursor for the given
- * constant, which should be one of the cursor constants
- * specified in class <code>SWT</code>. This cursor should
- * not be free'd because it was allocated by the system,
- * not the application. A value of <code>null</code> will
- * be returned if the supplied constant is not an SWT cursor
- * constant.
- *
- * @param id the SWT cursor constant
- * @return the corresponding cursor or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT#CURSOR_ARROW
- * @see SWT#CURSOR_WAIT
- * @see SWT#CURSOR_CROSS
- * @see SWT#CURSOR_APPSTARTING
- * @see SWT#CURSOR_HELP
- * @see SWT#CURSOR_SIZEALL
- * @see SWT#CURSOR_SIZENESW
- * @see SWT#CURSOR_SIZENS
- * @see SWT#CURSOR_SIZENWSE
- * @see SWT#CURSOR_SIZEWE
- * @see SWT#CURSOR_SIZEN
- * @see SWT#CURSOR_SIZES
- * @see SWT#CURSOR_SIZEE
- * @see SWT#CURSOR_SIZEW
- * @see SWT#CURSOR_SIZENE
- * @see SWT#CURSOR_SIZESE
- * @see SWT#CURSOR_SIZESW
- * @see SWT#CURSOR_SIZENW
- * @see SWT#CURSOR_UPARROW
- * @see SWT#CURSOR_IBEAM
- * @see SWT#CURSOR_NO
- * @see SWT#CURSOR_HAND
- *
- * @since 3.0
- */
-public Cursor getSystemCursor (int id) {
- checkDevice ();
- if (!(0 <= id && id < cursors.length)) return null;
- if (cursors [id] == null) {
- cursors [id] = new Cursor (this, id);
- }
- return cursors [id];
-}
-
-/**
- * Returns the matching standard platform image for the given
- * constant, which should be one of the icon constants
- * specified in class <code>SWT</code>. This image should
- * not be free'd because it was allocated by the system,
- * not the application. A value of <code>null</code> will
- * be returned either if the supplied constant is not an
- * SWT icon constant or if the platform does not define an
- * image that corresponds to the constant.
- *
- * @param id the SWT icon constant
- * @return the corresponding image or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_QUESTION
- * @see SWT#ICON_WARNING
- * @see SWT#ICON_WORKING
- *
- * @since 3.0
- */
-public Image getSystemImage (int id) {
- checkDevice ();
- switch (id) {
- case SWT.ICON_ERROR:
- if (errorImage == null) {
- errorImage = createImage ("gtk-dialog-error"); //$NON-NLS-1$
- }
- return errorImage;
- case SWT.ICON_INFORMATION:
- case SWT.ICON_WORKING:
- if (infoImage == null) {
- infoImage = createImage ("gtk-dialog-info"); //$NON-NLS-1$
- }
- return infoImage;
- case SWT.ICON_QUESTION:
- if (questionImage == null) {
- questionImage = createImage ("gtk-dialog-question"); //$NON-NLS-1$
- }
- return questionImage;
- case SWT.ICON_WARNING:
- if (warningImage == null) {
- warningImage = createImage ("gtk-dialog-warning"); //$NON-NLS-1$
- }
- return warningImage;
- }
- return null;
-}
-
-void initializeSystemColors () {
- GdkColor gdkColor;
-
- /* Get Tooltip resources */
- int /*long*/ tooltipShellHandle = OS.gtk_window_new (OS.GTK_WINDOW_POPUP);
- if (tooltipShellHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- byte[] gtk_tooltips = Converter.wcsToMbcs (null, "gtk-tooltips", true); //$NON-NLS-1$
- OS.gtk_widget_set_name (tooltipShellHandle, gtk_tooltips);
- OS.gtk_widget_realize (tooltipShellHandle);
- int /*long*/ tooltipStyle = OS.gtk_widget_get_style (tooltipShellHandle);
- gdkColor = new GdkColor();
- OS.gtk_style_get_fg (tooltipStyle, OS.GTK_STATE_NORMAL, gdkColor);
- COLOR_INFO_FOREGROUND = gdkColor;
- gdkColor = new GdkColor();
- OS.gtk_style_get_bg (tooltipStyle, OS.GTK_STATE_NORMAL, gdkColor);
- COLOR_INFO_BACKGROUND = gdkColor;
- OS.gtk_widget_destroy (tooltipShellHandle);
-
- /* Get Shell resources */
- int /*long*/ style = OS.gtk_widget_get_style (shellHandle);
- gdkColor = new GdkColor();
- OS.gtk_style_get_black (style, gdkColor);
- COLOR_WIDGET_DARK_SHADOW = gdkColor;
- gdkColor = new GdkColor();
- OS.gtk_style_get_dark (style, OS.GTK_STATE_NORMAL, gdkColor);
- COLOR_WIDGET_NORMAL_SHADOW = gdkColor;
- gdkColor = new GdkColor();
- OS.gtk_style_get_bg (style, OS.GTK_STATE_NORMAL, gdkColor);
- COLOR_WIDGET_LIGHT_SHADOW = gdkColor;
- gdkColor = new GdkColor();
- OS.gtk_style_get_light (style, OS.GTK_STATE_NORMAL, gdkColor);
- COLOR_WIDGET_HIGHLIGHT_SHADOW = gdkColor;
- gdkColor = new GdkColor();
- OS.gtk_style_get_fg (style, OS.GTK_STATE_NORMAL, gdkColor);
- COLOR_WIDGET_FOREGROUND = gdkColor;
- gdkColor = new GdkColor();
- OS.gtk_style_get_bg (style, OS.GTK_STATE_NORMAL, gdkColor);
- COLOR_WIDGET_BACKGROUND = gdkColor;
- //gdkColor = new GdkColor();
- //OS.gtk_style_get_text (style, OS.GTK_STATE_NORMAL, gdkColor);
- //COLOR_TEXT_FOREGROUND = gdkColor;
- //gdkColor = new GdkColor();
- //OS.gtk_style_get_base (style, OS.GTK_STATE_NORMAL, gdkColor);
- //COLOR_TEXT_BACKGROUND = gdkColor;
- gdkColor = new GdkColor();
- OS.gtk_style_get_text (style, OS.GTK_STATE_NORMAL, gdkColor);
- COLOR_LIST_FOREGROUND = gdkColor;
- gdkColor = new GdkColor();
- OS.gtk_style_get_base (style, OS.GTK_STATE_NORMAL, gdkColor);
- COLOR_LIST_BACKGROUND = gdkColor;
- gdkColor = new GdkColor();
- OS.gtk_style_get_text (style, OS.GTK_STATE_SELECTED, gdkColor);
- COLOR_LIST_SELECTION_TEXT = gdkColor;
- gdkColor = new GdkColor();
- OS.gtk_style_get_base (style, OS.GTK_STATE_SELECTED, gdkColor);
- COLOR_LIST_SELECTION = gdkColor;
- gdkColor = new GdkColor();
- OS.gtk_style_get_bg (style, OS.GTK_STATE_SELECTED, gdkColor);
- COLOR_TITLE_BACKGROUND = gdkColor;
- gdkColor = new GdkColor();
- OS.gtk_style_get_fg (style, OS.GTK_STATE_SELECTED, gdkColor);
- COLOR_TITLE_FOREGROUND = gdkColor;
- gdkColor = new GdkColor();
- OS.gtk_style_get_light (style, OS.GTK_STATE_SELECTED, gdkColor);
- COLOR_TITLE_BACKGROUND_GRADIENT = gdkColor;
- gdkColor = new GdkColor();
- OS.gtk_style_get_bg (style, OS.GTK_STATE_INSENSITIVE, gdkColor);
- COLOR_TITLE_INACTIVE_BACKGROUND = gdkColor;
- gdkColor = new GdkColor();
- OS.gtk_style_get_fg (style, OS.GTK_STATE_INSENSITIVE, gdkColor);
- COLOR_TITLE_INACTIVE_FOREGROUND = gdkColor;
- gdkColor = new GdkColor();
- OS.gtk_style_get_light (style, OS.GTK_STATE_INSENSITIVE, gdkColor);
- COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT = gdkColor;
-}
-
-/**
- * Returns a reasonable font for applications to use.
- * On some platforms, this will match the "default font"
- * or "system font" if such can be found. This font
- * should not be free'd because it was allocated by the
- * system, not the application.
- * <p>
- * Typically, applications which want the default look
- * should simply not set the font on the widgets they
- * create. Widgets are always created with the correct
- * default font for the class of user-interface component
- * they represent.
- * </p>
- *
- * @return a font
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getSystemFont () {
- checkDevice ();
- if (systemFont != null) return systemFont;
- int /*long*/ style = OS.gtk_widget_get_style (shellHandle);
- int /*long*/ defaultFont = OS.pango_font_description_copy (OS.gtk_style_get_font_desc (style));
- return systemFont = Font.gtk_new (this, defaultFont);
-}
-
-/**
- * Returns the single instance of the system tray or null
- * when there is no system tray available for the platform.
- *
- * @return the system tray or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public Tray getSystemTray () {
- checkDevice ();
- if (tray != null) return tray;
- return tray = new Tray (this, SWT.NONE);
-}
-
-/**
- * Returns the user-interface thread for the receiver.
- *
- * @return the receiver's user-interface thread
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Thread getThread () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- return thread;
- }
-}
-
-Widget getWidget (int /*long*/ handle) {
- if (handle == 0) return null;
- if (lastWidget != null && lastHandle == handle) return lastWidget;
- int /*long*/ index = OS.g_object_get_qdata (handle, SWT_OBJECT_INDEX) - 1;
- if (0 <= index && index < widgetTable.length) {
- lastHandle = handle;
- return lastWidget = widgetTable [(int)/*64*/index];
- }
- return null;
-}
-
-int /*long*/ idleProc (int /*long*/ data) {
- boolean result = runAsyncMessages (false);
- if (!result) {
- synchronized (idleLock) {
- idleHandle = 0;
- }
- }
- return result ? 1 : 0;
-}
-
-/**
- * Initializes any internal resources needed by the
- * device.
- * <p>
- * This method is called after <code>create</code>.
- * </p>
- *
- * @see #create
- */
-protected void init () {
- super.init ();
- initializeCallbacks ();
- initializeSubclasses ();
- initializeSystemColors ();
- initializeSystemSettings ();
- initializeWidgetTable ();
- initializeWindowManager ();
-}
-
-void initializeCallbacks () {
- closures = new int /*long*/ [Widget.LAST_SIGNAL];
- signalIds = new int [Widget.LAST_SIGNAL];
-
- /* Cache signals for GtkWidget */
- signalIds [Widget.BUTTON_PRESS_EVENT] = OS.g_signal_lookup (OS.button_press_event, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.BUTTON_RELEASE_EVENT] = OS.g_signal_lookup (OS.button_release_event, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.CONFIGURE_EVENT] = OS.g_signal_lookup (OS.configure_event, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.DELETE_EVENT] = OS.g_signal_lookup (OS.delete_event, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.ENTER_NOTIFY_EVENT] = OS.g_signal_lookup (OS.enter_notify_event, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.EVENT] = OS.g_signal_lookup (OS.event, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.EVENT_AFTER] = OS.g_signal_lookup (OS.event_after, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.EXPOSE_EVENT] = OS.g_signal_lookup (OS.expose_event, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.FOCUS] = OS.g_signal_lookup (OS.focus, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.FOCUS_IN_EVENT] = OS.g_signal_lookup (OS.focus_in_event, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.FOCUS_OUT_EVENT] = OS.g_signal_lookup (OS.focus_out_event, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.GRAB_FOCUS] = OS.g_signal_lookup (OS.grab_focus, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.HIDE] = OS.g_signal_lookup (OS.hide, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.KEY_PRESS_EVENT] = OS.g_signal_lookup (OS.key_press_event, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.KEY_RELEASE_EVENT] = OS.g_signal_lookup (OS.key_release_event, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.LEAVE_NOTIFY_EVENT] = OS.g_signal_lookup (OS.leave_notify_event, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.MAP] = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.MAP_EVENT] = OS.g_signal_lookup (OS.map_event, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.MNEMONIC_ACTIVATE] = OS.g_signal_lookup (OS.mnemonic_activate, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.MOTION_NOTIFY_EVENT] = OS.g_signal_lookup (OS.motion_notify_event, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.POPUP_MENU] = OS.g_signal_lookup (OS.popup_menu, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.REALIZE] = OS.g_signal_lookup (OS.realize, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.SCROLL_EVENT] = OS.g_signal_lookup (OS.scroll_event, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.SHOW] = OS.g_signal_lookup (OS.show, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.SHOW_HELP] = OS.g_signal_lookup (OS.show_help, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.SIZE_ALLOCATE] = OS.g_signal_lookup (OS.size_allocate, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.STYLE_SET] = OS.g_signal_lookup (OS.style_set, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.UNMAP] = OS.g_signal_lookup (OS.unmap, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.UNMAP_EVENT] = OS.g_signal_lookup (OS.unmap_event, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.UNREALIZE] = OS.g_signal_lookup (OS.realize, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.VISIBILITY_NOTIFY_EVENT] = OS.g_signal_lookup (OS.visibility_notify_event, OS.GTK_TYPE_WIDGET ());
- signalIds [Widget.WINDOW_STATE_EVENT] = OS.g_signal_lookup (OS.window_state_event, OS.GTK_TYPE_WIDGET ());
-
- windowCallback2 = new Callback (this, "windowProc", 2); //$NON-NLS-1$
- windowProc2 = windowCallback2.getAddress ();
- if (windowProc2 == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- closures [Widget.ACTIVATE] = OS.g_cclosure_new (windowProc2, Widget.ACTIVATE, 0);
- closures [Widget.ACTIVATE_INVERSE] = OS.g_cclosure_new (windowProc2, Widget.ACTIVATE_INVERSE, 0);
- closures [Widget.CHANGED] = OS.g_cclosure_new (windowProc2, Widget.CHANGED, 0);
- closures [Widget.CLICKED] = OS.g_cclosure_new (windowProc2, Widget.CLICKED, 0);
- closures [Widget.DAY_SELECTED] = OS.g_cclosure_new (windowProc2, Widget.DAY_SELECTED, 0);
- closures [Widget.DAY_SELECTED_DOUBLE_CLICK] = OS.g_cclosure_new (windowProc2, Widget.DAY_SELECTED_DOUBLE_CLICK, 0);
- closures [Widget.HIDE] = OS.g_cclosure_new (windowProc2, Widget.HIDE, 0);
- closures [Widget.GRAB_FOCUS] = OS.g_cclosure_new (windowProc2, Widget.GRAB_FOCUS, 0);
- closures [Widget.MAP] = OS.g_cclosure_new (windowProc2, Widget.MAP, 0);
- closures [Widget.MONTH_CHANGED] = OS.g_cclosure_new (windowProc2, Widget.MONTH_CHANGED, 0);
- closures [Widget.OUTPUT] = OS.g_cclosure_new (windowProc2, Widget.OUTPUT, 0);
- closures [Widget.POPUP_MENU] = OS.g_cclosure_new (windowProc2, Widget.POPUP_MENU, 0);
- closures [Widget.PREEDIT_CHANGED] = OS.g_cclosure_new (windowProc2, Widget.PREEDIT_CHANGED, 0);
- closures [Widget.REALIZE] = OS.g_cclosure_new (windowProc2, Widget.REALIZE, 0);
- closures [Widget.SELECT] = OS.g_cclosure_new (windowProc2, Widget.SELECT, 0);
- closures [Widget.SHOW] = OS.g_cclosure_new (windowProc2, Widget.SHOW, 0);
- closures [Widget.VALUE_CHANGED] = OS.g_cclosure_new (windowProc2, Widget.VALUE_CHANGED, 0);
- closures [Widget.UNMAP] = OS.g_cclosure_new (windowProc2, Widget.UNMAP, 0);
- closures [Widget.UNREALIZE] = OS.g_cclosure_new (windowProc2, Widget.UNREALIZE, 0);
-
- windowCallback3 = new Callback (this, "windowProc", 3); //$NON-NLS-1$
- windowProc3 = windowCallback3.getAddress ();
- if (windowProc3 == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- closures [Widget.BUTTON_PRESS_EVENT] = OS.g_cclosure_new (windowProc3, Widget.BUTTON_PRESS_EVENT, 0);
- closures [Widget.BUTTON_PRESS_EVENT_INVERSE] = OS.g_cclosure_new (windowProc3, Widget.BUTTON_PRESS_EVENT_INVERSE, 0);
- closures [Widget.BUTTON_RELEASE_EVENT] = OS.g_cclosure_new (windowProc3, Widget.BUTTON_RELEASE_EVENT, 0);
- closures [Widget.BUTTON_RELEASE_EVENT_INVERSE] = OS.g_cclosure_new (windowProc3, Widget.BUTTON_RELEASE_EVENT_INVERSE, 0);
- closures [Widget.COMMIT] = OS.g_cclosure_new (windowProc3, Widget.COMMIT, 0);
- closures [Widget.CONFIGURE_EVENT] = OS.g_cclosure_new (windowProc3, Widget.CONFIGURE_EVENT, 0);
- closures [Widget.DELETE_EVENT] = OS.g_cclosure_new (windowProc3, Widget.DELETE_EVENT, 0);
- closures [Widget.ENTER_NOTIFY_EVENT] = OS.g_cclosure_new (windowProc3, Widget.ENTER_NOTIFY_EVENT, 0);
- closures [Widget.EVENT] = OS.g_cclosure_new (windowProc3, Widget.EVENT, 0);
- closures [Widget.EVENT_AFTER] = OS.g_cclosure_new (windowProc3, Widget.EVENT_AFTER, 0);
- closures [Widget.EXPOSE_EVENT] = OS.g_cclosure_new (windowProc3, Widget.EXPOSE_EVENT, 0);
- closures [Widget.EXPOSE_EVENT_INVERSE] = OS.g_cclosure_new (windowProc3, Widget.EXPOSE_EVENT_INVERSE, 0);
- closures [Widget.FOCUS] = OS.g_cclosure_new (windowProc3, Widget.FOCUS, 0);
- closures [Widget.FOCUS_IN_EVENT] = OS.g_cclosure_new (windowProc3, Widget.FOCUS_IN_EVENT, 0);
- closures [Widget.FOCUS_OUT_EVENT] = OS.g_cclosure_new (windowProc3, Widget.FOCUS_OUT_EVENT, 0);
- closures [Widget.KEY_PRESS_EVENT] = OS.g_cclosure_new (windowProc3, Widget.KEY_PRESS_EVENT, 0);
- closures [Widget.KEY_RELEASE_EVENT] = OS.g_cclosure_new (windowProc3, Widget.KEY_RELEASE_EVENT, 0);
- closures [Widget.INPUT] = OS.g_cclosure_new (windowProc3, Widget.INPUT, 0);
- closures [Widget.LEAVE_NOTIFY_EVENT] = OS.g_cclosure_new (windowProc3, Widget.LEAVE_NOTIFY_EVENT, 0);
- closures [Widget.MAP_EVENT] = OS.g_cclosure_new (windowProc3, Widget.MAP_EVENT, 0);
- closures [Widget.MNEMONIC_ACTIVATE] = OS.g_cclosure_new (windowProc3, Widget.MNEMONIC_ACTIVATE, 0);
- closures [Widget.MOTION_NOTIFY_EVENT] = OS.g_cclosure_new (windowProc3, Widget.MOTION_NOTIFY_EVENT, 0);
- closures [Widget.MOTION_NOTIFY_EVENT_INVERSE] = OS.g_cclosure_new (windowProc3, Widget.MOTION_NOTIFY_EVENT_INVERSE, 0);
- closures [Widget.MOVE_FOCUS] = OS.g_cclosure_new (windowProc3, Widget.MOVE_FOCUS, 0);
- closures [Widget.POPULATE_POPUP] = OS.g_cclosure_new (windowProc3, Widget.POPULATE_POPUP, 0);
- closures [Widget.SCROLL_EVENT] = OS.g_cclosure_new (windowProc3, Widget.SCROLL_EVENT, 0);
- closures [Widget.SHOW_HELP] = OS.g_cclosure_new (windowProc3, Widget.SHOW_HELP, 0);
- closures [Widget.SIZE_ALLOCATE] = OS.g_cclosure_new (windowProc3, Widget.SIZE_ALLOCATE, 0);
- closures [Widget.STYLE_SET] = OS.g_cclosure_new (windowProc3, Widget.STYLE_SET, 0);
- closures [Widget.TOGGLED] = OS.g_cclosure_new (windowProc3, Widget.TOGGLED, 0);
- closures [Widget.UNMAP_EVENT] = OS.g_cclosure_new (windowProc3, Widget.UNMAP_EVENT, 0);
- closures [Widget.VISIBILITY_NOTIFY_EVENT] = OS.g_cclosure_new (windowProc3, Widget.VISIBILITY_NOTIFY_EVENT, 0);
- closures [Widget.WINDOW_STATE_EVENT] = OS.g_cclosure_new (windowProc3, Widget.WINDOW_STATE_EVENT, 0);
- closures [Widget.ROW_DELETED] = OS.g_cclosure_new (windowProc3, Widget.ROW_DELETED, 0);
-
- windowCallback4 = new Callback (this, "windowProc", 4); //$NON-NLS-1$
- windowProc4 = windowCallback4.getAddress ();
- if (windowProc4 == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- closures [Widget.DELETE_RANGE] = OS.g_cclosure_new (windowProc4, Widget.DELETE_RANGE, 0);
- closures [Widget.DELETE_TEXT] = OS.g_cclosure_new (windowProc4, Widget.DELETE_TEXT, 0);
- closures [Widget.ROW_ACTIVATED] = OS.g_cclosure_new (windowProc4, Widget.ROW_ACTIVATED, 0);
- closures [Widget.SCROLL_CHILD] = OS.g_cclosure_new (windowProc4, Widget.SCROLL_CHILD, 0);
- closures [Widget.STATUS_ICON_POPUP_MENU] = OS.g_cclosure_new (windowProc4, Widget.STATUS_ICON_POPUP_MENU, 0);
- closures [Widget.SWITCH_PAGE] = OS.g_cclosure_new (windowProc4, Widget.SWITCH_PAGE, 0);
- closures [Widget.TEST_COLLAPSE_ROW] = OS.g_cclosure_new (windowProc4, Widget.TEST_COLLAPSE_ROW, 0);
- closures [Widget.TEST_EXPAND_ROW] = OS.g_cclosure_new (windowProc4, Widget.TEST_EXPAND_ROW, 0);
- closures [Widget.ROW_INSERTED] = OS.g_cclosure_new (windowProc4, Widget.ROW_INSERTED, 0);
-
- windowCallback5 = new Callback (this, "windowProc", 5); //$NON-NLS-1$
- windowProc5 = windowCallback5.getAddress ();
- if (windowProc5 == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- closures [Widget.CHANGE_VALUE] = OS.g_cclosure_new (windowProc5, Widget.CHANGE_VALUE, 0);
- closures [Widget.EXPAND_COLLAPSE_CURSOR_ROW] = OS.g_cclosure_new (windowProc5, Widget.EXPAND_COLLAPSE_CURSOR_ROW, 0);
- closures [Widget.INSERT_TEXT] = OS.g_cclosure_new (windowProc5, Widget.INSERT_TEXT, 0);
- closures [Widget.TEXT_BUFFER_INSERT_TEXT] = OS.g_cclosure_new (windowProc5, Widget.TEXT_BUFFER_INSERT_TEXT, 0);
-
- for (int i = 0; i < Widget.LAST_SIGNAL; i++) {
- if (closures [i] != 0) OS.g_closure_ref (closures [i]);
- }
-
- timerCallback = new Callback (this, "timerProc", 1); //$NON-NLS-1$
- timerProc = timerCallback.getAddress ();
- if (timerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- windowTimerCallback = new Callback (this, "windowTimerProc", 1); //$NON-NLS-1$
- windowTimerProc = windowTimerCallback.getAddress ();
- if (windowTimerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- mouseHoverCallback = new Callback (this, "mouseHoverProc", 1); //$NON-NLS-1$
- mouseHoverProc = mouseHoverCallback.getAddress ();
- if (mouseHoverProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- caretCallback = new Callback(this, "caretProc", 1); //$NON-NLS-1$
- caretProc = caretCallback.getAddress();
- if (caretProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- menuPositionCallback = new Callback(this, "menuPositionProc", 5); //$NON-NLS-1$
- menuPositionProc = menuPositionCallback.getAddress();
- if (menuPositionProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- sizeAllocateCallback = new Callback(this, "sizeAllocateProc", 3); //$NON-NLS-1$
- sizeAllocateProc = sizeAllocateCallback.getAddress();
- if (sizeAllocateProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- sizeRequestCallback = new Callback(this, "sizeRequestProc", 3); //$NON-NLS-1$
- sizeRequestProc = sizeRequestCallback.getAddress();
- if (sizeRequestProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- shellMapCallback = new Callback(this, "shellMapProc", 3); //$NON-NLS-1$
- shellMapProc = shellMapCallback.getAddress();
- if (shellMapProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- shellMapProcClosure = OS.g_cclosure_new (shellMapProc, 0, 0);
- OS.g_closure_ref (shellMapProcClosure);
-
- treeSelectionCallback = new Callback(this, "treeSelectionProc", 4); //$NON-NLS-1$
- treeSelectionProc = treeSelectionCallback.getAddress();
- if (treeSelectionProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- cellDataCallback = new Callback (this, "cellDataProc", 5); //$NON-NLS-1$
- cellDataProc = cellDataCallback.getAddress ();
- if (cellDataProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- setDirectionCallback = new Callback (this, "setDirectionProc", 2); //$NON-NLS-1$
- setDirectionProc = setDirectionCallback.getAddress ();
- if (setDirectionProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- emissionProcCallback = new Callback (this, "emissionProc", 4); //$NON-NLS-1$
- emissionProc = emissionProcCallback.getAddress ();
- if (emissionProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- allChildrenCallback = new Callback (this, "allChildrenProc", 2); //$NON-NLS-1$
- allChildrenProc = allChildrenCallback.getAddress ();
- if (allChildrenProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- checkIfEventCallback = new Callback (this, "checkIfEventProc", 3); //$NON-NLS-1$
- checkIfEventProc = checkIfEventCallback.getAddress ();
- if (checkIfEventProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- idleCallback = new Callback (this, "idleProc", 1); //$NON-NLS-1$
- idleProc = idleCallback.getAddress ();
- if (idleProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-}
-
-void initializeSubclasses () {
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- pangoLayoutNewCallback = new Callback (this, "pangoLayoutNewProc", 3); //$NON-NLS-1$
- pangoLayoutNewProc = pangoLayoutNewCallback.getAddress ();
- if (pangoLayoutNewProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- int /*long*/ pangoLayoutType = OS.PANGO_TYPE_LAYOUT ();
- int /*long*/ pangoLayoutClass = OS.g_type_class_ref (pangoLayoutType);
- pangoLayoutNewDefaultProc = OS.G_OBJECT_CLASS_CONSTRUCTOR (pangoLayoutClass);
- OS.G_OBJECT_CLASS_SET_CONSTRUCTOR (pangoLayoutClass, pangoLayoutNewProc);
- OS.g_type_class_unref (pangoLayoutClass);
- }
-}
-
-void initializeSystemSettings () {
- styleSetCallback = new Callback (this, "styleSetProc", 3); //$NON-NLS-1$
- styleSetProc = styleSetCallback.getAddress ();
- if (styleSetProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- OS.g_signal_connect (shellHandle, OS.style_set, styleSetProc, 0);
-
- /*
- * Feature in GTK. Despite the fact that the
- * gtk-entry-select-on-focus property is a global
- * setting, it is initialized when the GtkEntry
- * is initialized. This means that it cannot be
- * accessed before a GtkEntry is created. The
- * fix is to for the initializaion by creating
- * a temporary GtkEntry.
- */
- int /*long*/ entry = OS.gtk_entry_new ();
- OS.gtk_widget_destroy (entry);
- int [] buffer2 = new int [1];
- int /*long*/ settings = OS.gtk_settings_get_default ();
- OS.g_object_get (settings, OS.gtk_entry_select_on_focus, buffer2, 0);
- entrySelectOnFocus = buffer2 [0] != 0;
-}
-
-void initializeWidgetTable () {
- indexTable = new int [GROW_SIZE];
- widgetTable = new Widget [GROW_SIZE];
- for (int i=0; i<GROW_SIZE-1; i++) indexTable [i] = i + 1;
- indexTable [GROW_SIZE - 1] = -1;
-}
-
-void initializeWindowManager () {
- /* Get the window manager name */
- windowManager = ""; //$NON-NLS-1$
- if (OS.GTK_VERSION >= OS.VERSION (2, 2, 0)) {
- int /*long*/ screen = OS.gdk_screen_get_default ();
- if (screen != 0) {
- int /*long*/ ptr2 = OS.gdk_x11_screen_get_window_manager_name (screen);
- if (ptr2 != 0) {
- int length = OS.strlen (ptr2);
- if (length > 0) {
- byte [] buffer2 = new byte [length];
- OS.memmove (buffer2, ptr2, length);
- windowManager = new String (Converter.mbcsToWcs (null, buffer2));
- }
- }
- }
- }
-}
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Display</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int /*long*/ gdkGC, GCData data) {
- OS.g_object_unref (gdkGC);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Display</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for gc creation</li>
- * </ul>
- */
-public int /*long*/ internal_new_GC (GCData data) {
- if (isDisposed()) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
- int /*long*/ root = OS.GDK_ROOT_PARENT ();
- int /*long*/ gdkGC = OS.gdk_gc_new (root);
- if (gdkGC == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- OS.gdk_gc_set_subwindow (gdkGC, OS.GDK_INCLUDE_INFERIORS);
- if (data != null) {
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) == 0) {
- data.style |= SWT.LEFT_TO_RIGHT;
- }
- data.device = this;
- data.drawable = root;
- data.background = getSystemColor (SWT.COLOR_WHITE).handle;
- data.foreground = getSystemColor (SWT.COLOR_BLACK).handle;
- data.font = getSystemFont ();
- }
- return gdkGC;
-}
-
-boolean isValidThread () {
- return thread == Thread.currentThread ();
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param point to be mapped
- * @return point with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Point map (Control from, Control to, Point point) {
- checkDevice ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return map (from, to, point.x, point.y);
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param x coordinates to be mapped
- * @param y coordinates to be mapped
- * @return point with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Point map (Control from, Control to, int x, int y) {
- checkDevice ();
- if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- Point point = new Point (x, y);
- if (from == to) return point;
- if (from != null) {
- int /*long*/ window = from.eventWindow ();
- int [] origin_x = new int [1], origin_y = new int [1];
- OS.gdk_window_get_origin (window, origin_x, origin_y);
- if ((from.style & SWT.MIRRORED) != 0) point.x = from.getClientWidth () - point.x;
- point.x += origin_x [0];
- point.y += origin_y [0];
- }
- if (to != null) {
- int /*long*/ window = to.eventWindow ();
- int [] origin_x = new int [1], origin_y = new int [1];
- OS.gdk_window_get_origin (window, origin_x, origin_y);
- point.x -= origin_x [0];
- point.y -= origin_y [0];
- if ((to.style & SWT.MIRRORED) != 0) point.x = to.getClientWidth () - point.x;
- }
- return point;
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param rectangle to be mapped
- * @return rectangle with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Rectangle map (Control from, Control to, Rectangle rectangle) {
- checkDevice();
- if (rectangle == null) error (SWT.ERROR_NULL_ARGUMENT);
- return map (from, to, rectangle.x, rectangle.y, rectangle.width, rectangle.height);
-}
-
-static char mbcsToWcs (char ch) {
- int key = ch & 0xFFFF;
- if (key <= 0x7F) return ch;
- byte [] buffer;
- if (key <= 0xFF) {
- buffer = new byte [1];
- buffer [0] = (byte) key;
- } else {
- buffer = new byte [2];
- buffer [0] = (byte) ((key >> 8) & 0xFF);
- buffer [1] = (byte) (key & 0xFF);
- }
- char [] result = Converter.mbcsToWcs (null, buffer);
- if (result.length == 0) return 0;
- return result [0];
-}
-
-int /*long*/ menuPositionProc (int /*long*/ menu, int /*long*/ x, int /*long*/ y, int /*long*/ push_in, int /*long*/ user_data) {
- Widget widget = getWidget (menu);
- if (widget == null) return 0;
- return widget.menuPositionProc (menu, x, y, push_in, user_data);
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param x coordinates to be mapped
- * @param y coordinates to be mapped
- * @param width coordinates to be mapped
- * @param height coordinates to be mapped
- * @return rectangle with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Rectangle map (Control from, Control to, int x, int y, int width, int height) {
- checkDevice();
- if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- Rectangle rect = new Rectangle (x, y, width, height);
- if (from == to) return rect;
- boolean fromRTL = false, toRTL = false;
- if (from != null) {
- int /*long*/ window = from.eventWindow ();
- int [] origin_x = new int [1], origin_y = new int [1];
- OS.gdk_window_get_origin (window, origin_x, origin_y);
- if (fromRTL = (from.style & SWT.MIRRORED) != 0) rect.x = from.getClientWidth() - rect.x;
- rect.x += origin_x [0];
- rect.y += origin_y [0];
- }
- if (to != null) {
- int /*long*/ window = to.eventWindow ();
- int [] origin_x = new int [1], origin_y = new int [1];
- OS.gdk_window_get_origin (window, origin_x, origin_y);
- rect.x -= origin_x [0];
- rect.y -= origin_y [0];
- if (toRTL = (to.style & SWT.MIRRORED) != 0) rect.x = to.getClientWidth () - rect.x;
- }
- if (fromRTL != toRTL) rect.x -= rect.width;
- return rect;
-}
-
-int /*long*/ mouseHoverProc (int /*long*/ handle) {
- Widget widget = getWidget (handle);
- if (widget == null) return 0;
- return widget.hoverProc (handle);
-}
-
-int /*long*/ pangoLayoutNewProc (int /*long*/ type, int /*long*/ n_construct_properties, int /*long*/ construct_properties) {
- int /*long*/ layout = OS.Call (pangoLayoutNewDefaultProc, type, (int)/*64*/n_construct_properties, construct_properties);
- OS.pango_layout_set_auto_dir (layout, false);
- return layout;
-}
-
-/**
- * Generate a low level system event.
- *
- * <code>post</code> is used to generate low level keyboard
- * and mouse events. The intent is to enable automated UI
- * testing by simulating the input from the user. Most
- * SWT applications should never need to call this method.
- * <p>
- * Note that this operation can fail when the operating system
- * fails to generate the event for any reason. For example,
- * this can happen when there is no such key or mouse button
- * or when the system event queue is full.
- * </p>
- * <p>
- * <b>Event Types:</b>
- * <p>KeyDown, KeyUp
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type KeyDown or KeyUp</li>
- * <p> Either one of:
- * <li>(in) character a character that corresponds to a keyboard key</li>
- * <li>(in) keyCode the key code of the key that was typed,
- * as defined by the key code constants in class <code>SWT</code></li>
- * </ul>
- * <p>MouseDown, MouseUp</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseDown or MouseUp
- * <li>(in) button the button that is pressed or released
- * </ul>
- * <p>MouseMove</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseMove
- * <li>(in) x the x coordinate to move the mouse pointer to in screen coordinates
- * <li>(in) y the y coordinate to move the mouse pointer to in screen coordinates
- * </ul>
- * <p>MouseWheel</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseWheel
- * <li>(in) detail either SWT.SCROLL_LINE or SWT.SCROLL_PAGE
- * <li>(in) count the number of lines or pages to scroll
- * </ul>
- * </dl>
- *
- * @param event the event to be generated
- *
- * @return true if the event was generated or false otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public boolean post (Event event) {
- /*
- * Get the operating system lock before synchronizing on the device
- * lock so that the device lock will not be held should another
- * thread already be in the operating system. This avoids deadlock
- * should the other thread need the device lock.
- */
- Lock lock = OS.lock;
- lock.lock();
- try {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (!OS.GDK_WINDOWING_X11()) return false;
- int /*long*/ xDisplay = OS.GDK_DISPLAY ();
- int type = event.type;
- switch (type) {
- case SWT.KeyDown:
- case SWT.KeyUp: {
- int keyCode = 0;
- int /*long*/ keysym = untranslateKey (event.keyCode);
- if (keysym != 0) keyCode = OS.XKeysymToKeycode (xDisplay, keysym);
- if (keyCode == 0) {
- char key = event.character;
- switch (key) {
- case SWT.BS: keysym = OS.GDK_BackSpace; break;
- case SWT.CR: keysym = OS.GDK_Return; break;
- case SWT.DEL: keysym = OS.GDK_Delete; break;
- case SWT.ESC: keysym = OS.GDK_Escape; break;
- case SWT.TAB: keysym = OS.GDK_Tab; break;
- case SWT.LF: keysym = OS.GDK_Linefeed; break;
- default:
- keysym = key;
- }
- keyCode = OS.XKeysymToKeycode (xDisplay, keysym);
- if (keyCode == 0) return false;
- }
- OS.XTestFakeKeyEvent (xDisplay, keyCode, type == SWT.KeyDown, 0);
- return true;
- }
- case SWT.MouseDown:
- case SWT.MouseMove:
- case SWT.MouseUp: {
- if (type == SWT.MouseMove) {
- OS.XTestFakeMotionEvent (xDisplay, -1, event.x, event.y, 0);
- } else {
- int button = event.button;
- switch (button) {
- case 1:
- case 2:
- case 3: break;
- case 4: button = 6; break;
- case 5: button = 7; break;
- default: return false;
- }
- OS.XTestFakeButtonEvent (xDisplay, button, type == SWT.MouseDown, 0);
- }
- return true;
- }
- /*
- * This code is intentionally commented. After posting a
- * mouse wheel event the system may respond unpredictably
- * to subsequent mouse actions.
- */
-// case SWT.MouseWheel: {
-// if (event.count == 0) return false;
-// int button = event.count < 0 ? 5 : 4;
-// OS.XTestFakeButtonEvent (xDisplay, button, type == SWT.MouseWheel, 0);
-// }
- }
- return false;
- }
- } finally {
- lock.unlock();
- }
-}
-
-void postEvent (Event event) {
- /*
- * Place the event at the end of the event queue.
- * This code is always called in the Display's
- * thread so it must be re-enterant but does not
- * need to be synchronized.
- */
- if (eventQueue == null) eventQueue = new Event [4];
- int index = 0;
- int length = eventQueue.length;
- while (index < length) {
- if (eventQueue [index] == null) break;
- index++;
- }
- if (index == length) {
- Event [] newQueue = new Event [length + 4];
- System.arraycopy (eventQueue, 0, newQueue, 0, length);
- eventQueue = newQueue;
- }
- eventQueue [index] = event;
-}
-
-void putGdkEvents () {
- if (gdkEventCount != 0) {
- for (int i = 0; i < gdkEventCount; i++) {
- int /*long*/ event = gdkEvents [i];
- Widget widget = gdkEventWidgets [i];
- if (widget == null || !widget.isDisposed ()) {
- OS.gdk_event_put (event);
- }
- OS.gdk_event_free (event);
- gdkEvents [i] = 0;
- gdkEventWidgets [i] = null;
- }
- gdkEventCount = 0;
- }
-}
-
-/**
- * Reads an event from the operating system's event queue,
- * dispatches it appropriately, and returns <code>true</code>
- * if there is potentially more work to do, or <code>false</code>
- * if the caller can sleep until another event is placed on
- * the event queue.
- * <p>
- * In addition to checking the system event queue, this method also
- * checks if any inter-thread messages (created by <code>syncExec()</code>
- * or <code>asyncExec()</code>) are waiting to be processed, and if
- * so handles them before returning.
- * </p>
- *
- * @return <code>false</code> if the caller can sleep upon return from this method
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li>
- * </ul>
- *
- * @see #sleep
- * @see #wake
- */
-public boolean readAndDispatch () {
- checkDevice ();
- boolean events = false;
- events |= runSettings ();
- events |= runPopups ();
- events |= OS.g_main_context_iteration (0, false);
- if (events) {
- runDeferredEvents ();
- return true;
- }
- return isDisposed () || runAsyncMessages (false);
-}
-
-static void register (Display display) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] == null) {
- Displays [i] = display;
- return;
- }
- }
- Display [] newDisplays = new Display [Displays.length + 4];
- System.arraycopy (Displays, 0, newDisplays, 0, Displays.length);
- newDisplays [Displays.length] = display;
- Displays = newDisplays;
- }
-}
-
-/**
- * Releases any internal resources back to the operating
- * system and clears all fields except the device handle.
- * <p>
- * Disposes all shells which are currently open on the display.
- * After this method has been invoked, all related related shells
- * will answer <code>true</code> when sent the message
- * <code>isDisposed()</code>.
- * </p><p>
- * When a device is destroyed, resources that were acquired
- * on behalf of the programmer need to be returned to the
- * operating system. For example, if the device allocated a
- * font to be used as the system font, this font would be
- * freed in <code>release</code>. Also,to assist the garbage
- * collector and minimize the amount of memory that is not
- * reclaimed when the programmer keeps a reference to a
- * disposed device, all fields except the handle are zero'd.
- * The handle is needed by <code>destroy</code>.
- * </p>
- * This method is called before <code>destroy</code>.
- *
- * @see Device#dispose
- * @see #destroy
- */
-protected void release () {
- sendEvent (SWT.Dispose, new Event ());
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) shell.dispose ();
- }
- if (tray != null) tray.dispose ();
- tray = null;
- while (readAndDispatch ()) {}
- if (disposeList != null) {
- for (int i=0; i<disposeList.length; i++) {
- if (disposeList [i] != null) disposeList [i].run ();
- }
- }
- disposeList = null;
- synchronizer.releaseSynchronizer ();
- synchronizer = null;
- releaseDisplay ();
- super.release ();
-}
-
-void releaseDisplay () {
- windowCallback2.dispose (); windowCallback2 = null;
- windowCallback3.dispose (); windowCallback3 = null;
- windowCallback4.dispose (); windowCallback4 = null;
- windowCallback5.dispose (); windowCallback5 = null;
- windowProc2 = windowProc3 = windowProc4 = windowProc5 = 0;
-
- /* Dispose xfilter callback */
- if (filterProc != 0) {
- OS.gdk_window_remove_filter(0, filterProc, 0);
- }
- filterCallback.dispose(); filterCallback = null;
- filterProc = 0;
-
- /* Dispose checkIfEvent callback */
- checkIfEventCallback.dispose(); checkIfEventCallback = null;
- checkIfEventProc = 0;
-
- /* Dispose preedit window */
- if (preeditWindow != 0) OS.gtk_widget_destroy (preeditWindow);
- imControl = null;
-
- /* Dispose the menu callback */
- menuPositionCallback.dispose (); menuPositionCallback = null;
- menuPositionProc = 0;
-
- /* Dispose the tooltip map callback */
- sizeAllocateCallback.dispose (); sizeAllocateCallback = null;
- sizeAllocateProc = 0;
- sizeRequestCallback.dispose (); sizeRequestCallback = null;
- sizeRequestProc = 0;
-
- /* Dispose the shell map callback */
- shellMapCallback.dispose (); shellMapCallback = null;
- shellMapProc = 0;
-
- /* Dispose the run async messages callback */
- idleCallback.dispose (); idleCallback = null;
- idleProc = 0;
- if (idleHandle != 0) OS.g_source_remove (idleHandle);
- idleHandle = 0;
-
- /* Dispose GtkTreeView callbacks */
- treeSelectionCallback.dispose (); treeSelectionCallback = null;
- treeSelectionProc = 0;
- cellDataCallback.dispose (); cellDataCallback = null;
- cellDataProc = 0;
-
- /* Dispose the set direction callback */
- setDirectionCallback.dispose (); setDirectionCallback = null;
- setDirectionProc = 0;
-
- /* Dispose the emission proc callback */
- emissionProcCallback.dispose (); emissionProcCallback = null;
- emissionProc = 0;
-
- /* Dispose the set direction callback */
- allChildrenCallback.dispose (); allChildrenCallback = null;
- allChildrenProc = 0;
-
- /* Dispose the caret callback */
- if (caretId != 0) OS.gtk_timeout_remove (caretId);
- caretId = 0;
- caretProc = 0;
- caretCallback.dispose ();
- caretCallback = null;
-
- /* Release closures */
- for (int i = 0; i < Widget.LAST_SIGNAL; i++) {
- if (closures [i] != 0) OS.g_closure_unref (closures [i]);
- }
- if (shellMapProcClosure != 0) OS.g_closure_unref (shellMapProcClosure);
-
- /* Dispose the timer callback */
- if (timerIds != null) {
- for (int i=0; i<timerIds.length; i++) {
- if (timerIds [i] != 0) OS.gtk_timeout_remove (timerIds [i]);
- }
- }
- timerIds = null;
- timerList = null;
- timerProc = 0;
- timerCallback.dispose ();
- timerCallback = null;
- windowTimerProc = 0;
- windowTimerCallback.dispose ();
- windowTimerCallback = null;
-
- /* Dispose mouse hover callback */
- if (mouseHoverId != 0) OS.gtk_timeout_remove (mouseHoverId);
- mouseHoverId = 0;
- mouseHoverHandle = mouseHoverProc = 0;
- mouseHoverCallback.dispose ();
- mouseHoverCallback = null;
-
- /* Dispose the default font */
- if (systemFont != null) systemFont.dispose ();
- systemFont = null;
-
- /* Dispose the System Images */
- if (errorImage != null) errorImage.dispose();
- if (infoImage != null) infoImage.dispose();
- if (questionImage != null) questionImage.dispose();
- if (warningImage != null) warningImage.dispose();
- errorImage = infoImage = questionImage = warningImage = null;
-
- /* Release the System Cursors */
- for (int i = 0; i < cursors.length; i++) {
- if (cursors [i] != null) cursors [i].dispose ();
- }
- cursors = null;
-
- /* Release Acquired Resources */
- if (resources != null) {
- for (int i=0; i<resources.length; i++) {
- if (resources [i] != null) resources [i].dispose ();
- }
- resources = null;
- }
-
- /* Release the System Colors */
- COLOR_WIDGET_DARK_SHADOW = COLOR_WIDGET_NORMAL_SHADOW = COLOR_WIDGET_LIGHT_SHADOW =
- COLOR_WIDGET_HIGHLIGHT_SHADOW = COLOR_WIDGET_BACKGROUND = COLOR_WIDGET_BORDER =
- COLOR_LIST_FOREGROUND = COLOR_LIST_BACKGROUND = COLOR_LIST_SELECTION = COLOR_LIST_SELECTION_TEXT =
- COLOR_WIDGET_FOREGROUND = COLOR_TITLE_FOREGROUND = COLOR_TITLE_BACKGROUND = COLOR_TITLE_BACKGROUND_GRADIENT =
- COLOR_TITLE_INACTIVE_FOREGROUND = COLOR_TITLE_INACTIVE_BACKGROUND = COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT =
- COLOR_INFO_BACKGROUND = COLOR_INFO_FOREGROUND = null;
-
- /* Dispose the event callback */
- OS.gdk_event_handler_set (0, 0, 0);
- eventCallback.dispose (); eventCallback = null;
-
- /* Dispose the hidden shell */
- if (shellHandle != 0) OS.gtk_widget_destroy (shellHandle);
- shellHandle = 0;
-
- /* Dispose the settings callback */
- styleSetCallback.dispose(); styleSetCallback = null;
- styleSetProc = 0;
-
- /* Dispose subclass */
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- int /*long*/ pangoLayoutType = OS.PANGO_TYPE_LAYOUT ();
- int /*long*/ pangoLayoutClass = OS.g_type_class_ref (pangoLayoutType);
- OS.G_OBJECT_CLASS_SET_CONSTRUCTOR (pangoLayoutClass, pangoLayoutNewDefaultProc);
- OS.g_type_class_unref (pangoLayoutClass);
- pangoLayoutNewCallback.dispose ();
- pangoLayoutNewCallback = null;
- pangoLayoutNewDefaultProc = pangoLayoutNewProc = 0;
- }
-
- /* Release the sleep resources */
- max_priority = timeout = null;
- if (fds != 0) OS.g_free (fds);
- fds = 0;
-
- /* Release references */
- popups = null;
- thread = null;
- lastWidget = activeShell = null;
- flushData = closures = null;
- indexTable = signalIds = treeSelection = null;
- widgetTable = modalShells = null;
- data = null;
- values = keys = null;
- windowManager = null;
- eventTable = filterTable = null;
- modalDialog = null;
- flushRect = null;
- exposeEvent = null;
- visibilityEvent = null;
- idleLock = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs anywhere in
- * a widget. The event type is one of the event constants defined
- * in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addFilter
- * @see #addListener
- *
- * @since 3.0
- */
-public void removeFilter (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (filterTable == null) return;
- filterTable.unhook (eventType, listener);
- if (filterTable.size () == 0) filterTable = null;
-}
-
-int /*long*/ removeGdkEvent () {
- if (gdkEventCount == 0) return 0;
- int /*long*/ event = gdkEvents [0];
- --gdkEventCount;
- System.arraycopy (gdkEvents, 1, gdkEvents, 0, gdkEventCount);
- System.arraycopy (gdkEventWidgets, 1, gdkEventWidgets, 0, gdkEventCount);
- gdkEvents [gdkEventCount] = 0;
- gdkEventWidgets [gdkEventCount] = null;
- if (gdkEventCount == 0) {
- gdkEvents = null;
- gdkEventWidgets = null;
- }
- return event;
-}
-
-void removeIdleProc () {
- synchronized (idleLock) {
- if (idleHandle != 0) OS.g_source_remove (idleHandle);
- idleNeeded = false;
- idleHandle = 0;
- }
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs. The event type
- * is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener
- *
- * @since 2.0
- */
-public void removeListener (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, listener);
-}
-
-void removeMouseHoverTimeout (int /*long*/ handle) {
- if (handle != mouseHoverHandle) return;
- if (mouseHoverId != 0) OS.gtk_timeout_remove (mouseHoverId);
- mouseHoverId = 0;
- mouseHoverHandle = 0;
-}
-
-void removePopup (Menu menu) {
- if (popups == null) return;
- for (int i=0; i<popups.length; i++) {
- if (popups [i] == menu) {
- popups [i] = null;
- return;
- }
- }
-}
-
-Widget removeWidget (int /*long*/ handle) {
- if (handle == 0) return null;
- lastWidget = null;
- Widget widget = null;
- int index = (int)/*64*/ OS.g_object_get_qdata (handle, SWT_OBJECT_INDEX) - 1;
- if (0 <= index && index < widgetTable.length) {
- widget = widgetTable [index];
- widgetTable [index] = null;
- indexTable [index] = freeSlot;
- freeSlot = index;
- OS.g_object_set_qdata (handle, SWT_OBJECT_INDEX, 0);
- }
- return widget;
-}
-
-boolean runAsyncMessages (boolean all) {
- return synchronizer.runAsyncMessages (all);
-}
-
-boolean runDeferredEvents () {
- boolean run = false;
- /*
- * Run deferred events. This code is always
- * called in the Display's thread so it must
- * be re-enterant but need not be synchronized.
- */
- while (eventQueue != null) {
-
- /* Take an event off the queue */
- Event event = eventQueue [0];
- if (event == null) break;
- int length = eventQueue.length;
- System.arraycopy (eventQueue, 1, eventQueue, 0, --length);
- eventQueue [length] = null;
-
- /* Run the event */
- Widget widget = event.widget;
- if (widget != null && !widget.isDisposed ()) {
- Widget item = event.item;
- if (item == null || !item.isDisposed ()) {
- run = true;
- widget.sendEvent (event);
- }
- }
-
- /*
- * At this point, the event queue could
- * be null due to a recursive invokation
- * when running the event.
- */
- }
-
- /* Clear the queue */
- eventQueue = null;
- return run;
-}
-
-boolean runPopups () {
- if (popups == null) return false;
- boolean result = false;
- while (popups != null) {
- Menu menu = popups [0];
- if (menu == null) break;
- int length = popups.length;
- System.arraycopy (popups, 1, popups, 0, --length);
- popups [length] = null;
- runDeferredEvents ();
- if (!menu.isDisposed ()) menu._setVisible (true);
- result = true;
- }
- popups = null;
- return result;
-}
-
-boolean runSettings () {
- if (!runSettings) return false;
- runSettings = false;
- saveResources ();
- initializeSystemColors ();
- sendEvent (SWT.Settings, null);
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) {
- shell.fixStyle ();
- shell.redraw (true);
- shell.layout (true, true);
- }
- }
- return true;
-}
-
-/**
- * On platforms which support it, sets the application name
- * to be the argument. On Motif, for example, this can be used
- * to set the name used for resource lookup. Specifying
- * <code>null</code> for the name clears it.
- *
- * @param name the new app name or <code>null</code>
- */
-public static void setAppName (String name) {
- APP_NAME = name;
-}
-
-/**
- * Sets the location of the on-screen pointer relative to the top left corner
- * of the screen. <b>Note: It is typically considered bad practice for a
- * program to move the on-screen pointer location.</b>
- *
- * @param x the new x coordinate for the cursor
- * @param y the new y coordinate for the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1
- */
-public void setCursorLocation (int x, int y) {
- checkDevice ();
- if (OS.GDK_WINDOWING_X11 ()) {
- int /*long*/ xDisplay = OS.GDK_DISPLAY ();
- int /*long*/ xWindow = OS.XDefaultRootWindow (xDisplay);
- OS.XWarpPointer (xDisplay, OS.None, xWindow, 0, 0, 0, 0, x, y);
- }
-}
-
-/**
- * Sets the location of the on-screen pointer relative to the top left corner
- * of the screen. <b>Note: It is typically considered bad practice for a
- * program to move the on-screen pointer location.</b>
- *
- * @param point new position
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_NULL_ARGUMENT - if the point is null
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setCursorLocation (Point point) {
- checkDevice ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- setCursorLocation (point.x, point.y);
-}
-
-/**
- * Sets the application defined property of the receiver
- * with the specified name to the given argument.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the display is disposed
- * of, it is the application's responsibility provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param key the name of the property
- * @param value the new value for the property
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getData(String)
- * @see #disposeExec(Runnable)
- */
-public void setData (String key, Object value) {
- checkDevice ();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
-
- if (key.equals (DISPATCH_EVENT_KEY)) {
- if (value == null || value instanceof int []) {
- dispatchEvents = (int []) value;
- if (value == null) putGdkEvents ();
- return;
- }
- }
- if (key.equals (SET_MODAL_DIALOG)) {
- setModalDialog ((Dialog) value);
- return;
- }
- if (key.equals (ADD_WIDGET_KEY)) {
- Object [] data = (Object []) value;
- int /*long*/ handle = ((LONG) data [0]).value;
- Widget widget = (Widget) data [1];
- if (widget != null) {
- addWidget (handle, widget);
- } else {
- removeWidget (handle);
- }
- }
- if (key.equals (ADD_IDLE_PROC_KEY)) {
- addIdleProc ();
- return;
- }
- if (key.equals (REMOVE_IDLE_PROC_KEY)) {
- removeIdleProc ();
- return;
- }
-
- /* Remove the key/value pair */
- if (value == null) {
- if (keys == null) return;
- int index = 0;
- while (index < keys.length && !keys [index].equals (key)) index++;
- if (index == keys.length) return;
- if (keys.length == 1) {
- keys = null;
- values = null;
- } else {
- String [] newKeys = new String [keys.length - 1];
- Object [] newValues = new Object [values.length - 1];
- System.arraycopy (keys, 0, newKeys, 0, index);
- System.arraycopy (keys, index + 1, newKeys, index, newKeys.length - index);
- System.arraycopy (values, 0, newValues, 0, index);
- System.arraycopy (values, index + 1, newValues, index, newValues.length - index);
- keys = newKeys;
- values = newValues;
- }
- return;
- }
-
- /* Add the key/value pair */
- if (keys == null) {
- keys = new String [] {key};
- values = new Object [] {value};
- return;
- }
- for (int i=0; i<keys.length; i++) {
- if (keys [i].equals (key)) {
- values [i] = value;
- return;
- }
- }
- String [] newKeys = new String [keys.length + 1];
- Object [] newValues = new Object [values.length + 1];
- System.arraycopy (keys, 0, newKeys, 0, keys.length);
- System.arraycopy (values, 0, newValues, 0, values.length);
- newKeys [keys.length] = key;
- newValues [values.length] = value;
- keys = newKeys;
- values = newValues;
-}
-
-/**
- * Sets the application defined, display specific data
- * associated with the receiver, to the argument.
- * The <em>display specific data</em> is a single,
- * unnamed field that is stored with every display.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the display specific data needs to
- * be notified when the display is disposed of, it is the
- * application's responsibility provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param data the new display specific data
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getData()
- * @see #disposeExec(Runnable)
- */
-public void setData (Object data) {
- checkDevice ();
- this.data = data;
-}
-
-int /*long*/ setDirectionProc (int /*long*/ widget, int /*long*/ direction) {
- OS.gtk_widget_set_direction (widget, (int)/*64*/ direction);
- if (OS.GTK_IS_MENU_ITEM (widget)) {
- int /*long*/ submenu = OS.gtk_menu_item_get_submenu (widget);
- if (submenu != 0) {
- OS.gtk_widget_set_direction (submenu, (int)/*64*/ direction);
- OS.gtk_container_forall (submenu, setDirectionProc, direction);
- }
- }
- if (OS.GTK_IS_CONTAINER (widget)) {
- OS.gtk_container_forall (widget, setDirectionProc, direction);
- }
- return 0;
-}
-
-void setModalDialog (Dialog modalDailog) {
- this.modalDialog = modalDailog;
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) shells [i].updateModal ();
-}
-
-void setModalShell (Shell shell) {
- if (modalShells == null) modalShells = new Shell [4];
- int index = 0, length = modalShells.length;
- while (index < length) {
- if (modalShells [index] == shell) return;
- if (modalShells [index] == null) break;
- index++;
- }
- if (index == length) {
- Shell [] newModalShells = new Shell [length + 4];
- System.arraycopy (modalShells, 0, newModalShells, 0, length);
- modalShells = newModalShells;
- }
- modalShells [index] = shell;
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) shells [i].updateModal ();
-}
-
-/**
- * Sets the synchronizer used by the display to be
- * the argument, which can not be null.
- *
- * @param synchronizer the new synchronizer for the display (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the synchronizer is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li>
- * </ul>
- */
-public void setSynchronizer (Synchronizer synchronizer) {
- checkDevice ();
- if (synchronizer == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (synchronizer == this.synchronizer) return;
- Synchronizer oldSynchronizer;
- synchronized (Device.class) {
- oldSynchronizer = this.synchronizer;
- this.synchronizer = synchronizer;
- }
- if (oldSynchronizer != null) {
- oldSynchronizer.runAsyncMessages(true);
- }
-}
-
-void showIMWindow (Control control) {
- imControl = control;
- if (preeditWindow == 0) {
- preeditWindow = OS.gtk_window_new (OS.GTK_WINDOW_POPUP);
- if (preeditWindow == 0) error (SWT.ERROR_NO_HANDLES);
- preeditLabel = OS.gtk_label_new (null);
- if (preeditLabel == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (preeditWindow, preeditLabel);
- OS.gtk_widget_show (preeditLabel);
- }
- int /*long*/ [] preeditString = new int /*long*/ [1];
- int /*long*/ [] pangoAttrs = new int /*long*/ [1];
- int /*long*/ imHandle = control.imHandle ();
- OS.gtk_im_context_get_preedit_string (imHandle, preeditString, pangoAttrs, null);
- if (preeditString [0] != 0 && OS.strlen (preeditString [0]) > 0) {
- Control widget = control.findBackgroundControl ();
- if (widget == null) widget = control;
- OS.gtk_widget_modify_bg (preeditWindow, OS.GTK_STATE_NORMAL, widget.getBackgroundColor ());
- widget.setForegroundColor (preeditLabel, control.getForegroundColor());
- OS.gtk_widget_modify_font (preeditLabel, control.getFontDescription ());
- if (pangoAttrs [0] != 0) OS.gtk_label_set_attributes (preeditLabel, pangoAttrs[0]);
- OS.gtk_label_set_text (preeditLabel, preeditString [0]);
- Point point = control.toDisplay (control.getIMCaretPos ());
- OS.gtk_window_move (preeditWindow, point.x, point.y);
- GtkRequisition requisition = new GtkRequisition ();
- OS.gtk_widget_size_request (preeditLabel, requisition);
- OS.gtk_window_resize (preeditWindow, requisition.width, requisition.height);
- OS.gtk_widget_show (preeditWindow);
- } else {
- OS.gtk_widget_hide (preeditWindow);
- }
- if (preeditString [0] != 0) OS.g_free (preeditString [0]);
- if (pangoAttrs [0] != 0) OS.pango_attr_list_unref (pangoAttrs [0]);
-}
-
-/**
- * Causes the user-interface thread to <em>sleep</em> (that is,
- * to be put in a state where it does not consume CPU cycles)
- * until an event is received or it is otherwise awakened.
- *
- * @return <code>true</code> if an event requiring dispatching was placed on the queue.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #wake
- */
-public boolean sleep () {
- checkDevice ();
- if (gdkEventCount == 0) {
- gdkEvents = null;
- gdkEventWidgets = null;
- }
- if (settingsChanged) {
- settingsChanged = false;
- runSettings = true;
- return false;
- }
- if (getMessageCount () != 0) return true;
- if (fds == 0) {
- allocated_nfds = 2;
- fds = OS.g_malloc (OS.GPollFD_sizeof () * allocated_nfds);
- }
- max_priority [0] = timeout [0] = 0;
- int /*long*/ context = OS.g_main_context_default ();
- boolean result = false;
- do {
- if (OS.g_main_context_acquire (context)) {
- result = OS.g_main_context_prepare (context, max_priority);
- int nfds;
- while ((nfds = OS.g_main_context_query (context, max_priority [0], timeout, fds, allocated_nfds)) > allocated_nfds) {
- OS.g_free (fds);
- allocated_nfds = nfds;
- fds = OS.g_malloc (OS.GPollFD_sizeof() * allocated_nfds);
- }
- int /*long*/ poll = OS.g_main_context_get_poll_func (context);
- if (poll != 0) {
- if (nfds > 0 || timeout [0] != 0) {
- /*
- * Bug in GTK. For some reason, g_main_context_wakeup() may
- * fail to wake up the UI thread from the polling function.
- * The fix is to sleep for a maximum of 50 milliseconds.
- */
- if (timeout [0] < 0) timeout [0] = 50;
-
- /* Exit the OS lock to allow other threads to enter GTK */
- Lock lock = OS.lock;
- int count = lock.lock ();
- for (int i = 0; i < count; i++) lock.unlock ();
- try {
- wake = false;
- OS.Call (poll, fds, nfds, timeout [0]);
- } finally {
- for (int i = 0; i < count; i++) lock.lock ();
- lock.unlock ();
- }
- }
- }
- OS.g_main_context_check (context, max_priority [0], fds, nfds);
- OS.g_main_context_release (context);
- }
- } while (!result && getMessageCount () == 0 && !wake);
- wake = false;
- return true;
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread after the specified
- * number of milliseconds have elapsed. If milliseconds is less
- * than zero, the runnable is not executed.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param milliseconds the delay before running the runnable
- * @param runnable code to run on the user-interface thread
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #asyncExec
- */
-public void timerExec (int milliseconds, Runnable runnable) {
- checkDevice ();
- if (runnable == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (timerList == null) timerList = new Runnable [4];
- if (timerIds == null) timerIds = new int [4];
- int index = 0;
- while (index < timerList.length) {
- if (timerList [index] == runnable) break;
- index++;
- }
- if (index != timerList.length) {
- OS.gtk_timeout_remove (timerIds [index]);
- timerList [index] = null;
- timerIds [index] = 0;
- if (milliseconds < 0) return;
- } else {
- if (milliseconds < 0) return;
- index = 0;
- while (index < timerList.length) {
- if (timerList [index] == null) break;
- index++;
- }
- if (index == timerList.length) {
- Runnable [] newTimerList = new Runnable [timerList.length + 4];
- System.arraycopy (timerList, 0, newTimerList, 0, timerList.length);
- timerList = newTimerList;
- int [] newTimerIds = new int [timerIds.length + 4];
- System.arraycopy (timerIds, 0, newTimerIds, 0, timerIds.length);
- timerIds = newTimerIds;
- }
- }
- int timerId = OS.gtk_timeout_add (milliseconds, timerProc, index);
- if (timerId != 0) {
- timerIds [index] = timerId;
- timerList [index] = runnable;
- }
-}
-
-int /*long*/ timerProc (int /*long*/ i) {
- if (timerList == null) return 0;
- int index = (int)/*64*/i;
- if (0 <= index && index < timerList.length) {
- Runnable runnable = timerList [index];
- timerList [index] = null;
- timerIds [index] = 0;
- if (runnable != null) runnable.run ();
- }
- return 0;
-}
-
-int /*long*/ caretProc (int /*long*/ clientData) {
- caretId = 0;
- if (currentCaret == null) {
- return 0;
- }
- if (currentCaret.blinkCaret()) {
- int blinkRate = currentCaret.blinkRate;
- if (blinkRate == 0) return 0;
- caretId = OS.gtk_timeout_add (blinkRate, caretProc, 0);
- } else {
- currentCaret = null;
- }
- return 0;
-}
-
-int /*long*/ sizeAllocateProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) {
- Widget widget = getWidget (user_data);
- if (widget == null) return 0;
- return widget.sizeAllocateProc (handle, arg0, user_data);
-}
-
-int /*long*/ sizeRequestProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) {
- Widget widget = getWidget (user_data);
- if (widget == null) return 0;
- return widget.sizeRequestProc (handle, arg0, user_data);
-}
-
-int /*long*/ treeSelectionProc (int /*long*/ model, int /*long*/ path, int /*long*/ iter, int /*long*/ data) {
- Widget widget = getWidget (data);
- if (widget == null) return 0;
- return widget.treeSelectionProc (model, path, iter, treeSelection, treeSelectionLength++);
-}
-
-void saveResources () {
- int resourceCount = 0;
- if (resources == null) {
- resources = new Resource [RESOURCE_SIZE];
- } else {
- resourceCount = resources.length;
- Resource [] newResources = new Resource [resourceCount + RESOURCE_SIZE];
- System.arraycopy (resources, 0, newResources, 0, resourceCount);
- resources = newResources;
- }
- if (systemFont != null) {
- resources [resourceCount++] = systemFont;
- systemFont = null;
- }
- if (errorImage != null) resources [resourceCount++] = errorImage;
- if (infoImage != null) resources [resourceCount++] = infoImage;
- if (questionImage != null) resources [resourceCount++] = questionImage;
- if (warningImage != null) resources [resourceCount++] = warningImage;
- errorImage = infoImage = questionImage = warningImage = null;
- for (int i=0; i<cursors.length; i++) {
- if (cursors [i] != null) resources [resourceCount++] = cursors [i];
- cursors [i] = null;
- }
- if (resourceCount < RESOURCE_SIZE) {
- Resource [] newResources = new Resource [resourceCount];
- System.arraycopy (resources, 0, newResources, 0, resourceCount);
- resources = newResources;
- }
-}
-
-void sendEvent (int eventType, Event event) {
- if (eventTable == null && filterTable == null) {
- return;
- }
- if (event == null) event = new Event ();
- event.display = this;
- event.type = eventType;
- if (event.time == 0) event.time = getLastEventTime ();
- if (!filterEvent (event)) {
- if (eventTable != null) eventTable.sendEvent (event);
- }
-}
-
-void setCurrentCaret (Caret caret) {
- if (caretId != 0) OS.gtk_timeout_remove(caretId);
- caretId = 0;
- currentCaret = caret;
- if (caret == null) return;
- int blinkRate = currentCaret.blinkRate;
- caretId = OS.gtk_timeout_add (blinkRate, caretProc, 0);
-}
-
-int /*long*/ shellMapProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) {
- Widget widget = getWidget (handle);
- if (widget == null) return 0;
- return widget.shellMapProc (handle, arg0, user_data);
-}
-
-int /*long*/ styleSetProc (int /*long*/ gobject, int /*long*/ arg1, int /*long*/ user_data) {
- settingsChanged = true;
- return 0;
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread at the next
- * reasonable opportunity. The thread which calls this method
- * is suspended until the runnable completes. Specifying <code>null</code>
- * as the runnable simply wakes the user-interface thread.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param runnable code to run on the user-interface thread or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_FAILED_EXEC - if an exception occurred when executing the runnable</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #asyncExec
- */
-public void syncExec (Runnable runnable) {
- Synchronizer synchronizer;
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- synchronizer = this.synchronizer;
- synchronized (idleLock) {
- if (idleNeeded && idleHandle == 0) {
- //NOTE: calling unlocked function in OS
- idleHandle = OS._g_idle_add (idleProc, 0);
- }
- }
- }
- synchronizer.syncExec (runnable);
-}
-
-static int translateKey (int key) {
- for (int i=0; i<KeyTable.length; i++) {
- if (KeyTable [i] [0] == key) return KeyTable [i] [1];
- }
- return 0;
-}
-
-static int untranslateKey (int key) {
- for (int i=0; i<KeyTable.length; i++) {
- if (KeyTable [i] [1] == key) return KeyTable [i] [0];
- }
- return 0;
-}
-
-/**
- * Forces all outstanding paint requests for the display
- * to be processed before this method returns.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Control#update()
- */
-public void update () {
- checkDevice ();
- flushExposes (0, true);
- OS.gdk_window_process_all_updates ();
-}
-
-/**
- * If the receiver's user-interface thread was <code>sleep</code>ing,
- * causes it to be awakened and start running again. Note that this
- * method may be called from any thread.
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #sleep
- */
-public void wake () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- if (thread == Thread.currentThread ()) return;
- wakeThread ();
- }
-}
-
-void wakeThread () {
- OS.g_main_context_wakeup (0);
- wake = true;
-}
-
-static char wcsToMbcs (char ch) {
- int key = ch & 0xFFFF;
- if (key <= 0x7F) return ch;
- byte [] buffer = Converter.wcsToMbcs (null, new char [] {ch}, false);
- if (buffer.length == 1) return (char) buffer [0];
- if (buffer.length == 2) {
- return (char) (((buffer [0] & 0xFF) << 8) | (buffer [1] & 0xFF));
- }
- return 0;
-}
-
-int /*long*/ windowProc (int /*long*/ handle, int /*long*/ user_data) {
- Widget widget = getWidget (handle);
- if (widget == null) return 0;
- return widget.windowProc (handle, user_data);
-}
-
-int /*long*/ windowProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) {
- Widget widget = getWidget (handle);
- if (widget == null) return 0;
- return widget.windowProc (handle, arg0, user_data);
-}
-
-int /*long*/ windowProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ user_data) {
- Widget widget = getWidget (handle);
- if (widget == null) return 0;
- return widget.windowProc (handle, arg0, arg1, user_data);
-}
-
-int /*long*/ windowProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2, int /*long*/ user_data) {
- Widget widget = getWidget (handle);
- if (widget == null) return 0;
- return widget.windowProc (handle, arg0, arg1, arg2, user_data);
-}
-
-int /*long*/ windowTimerProc (int /*long*/ handle) {
- Widget widget = getWidget (handle);
- if (widget == null) return 0;
- return widget.timerProc (handle);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java
deleted file mode 100644
index b3584f8586..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java
+++ /dev/null
@@ -1,728 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class support the layout of selectable
- * expand bar items.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>ExpandItem</code>.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>V_SCROLL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Expand, Collapse</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see ExpandItem
- * @see ExpandEvent
- * @see ExpandListener
- * @see ExpandAdapter
- * @see <a href="http://www.eclipse.org/swt/snippets/#expandbar">ExpandBar snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.2
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ExpandBar extends Composite {
- ExpandItem [] items;
- ExpandItem lastFocus;
- int itemCount;
- int spacing;
- int yCurrentScroll;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#V_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ExpandBar (Composite parent, int style) {
- super (parent, style);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an item in the receiver is expanded or collapsed
- * by sending it one of the messages defined in the <code>ExpandListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ExpandListener
- * @see #removeExpandListener
- */
-public void addExpandListener (ExpandListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Expand, typedListener);
- addListener (SWT.Collapse, typedListener);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- Point size = computeNativeSize (handle, wHint, hHint, changed);
- int border = OS.gtk_container_get_border_width (handle);
- size.x += 2 * border;
- size.y += 2 * border;
- return size;
- } else {
- int height = 0, width = 0;
- if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
- if (itemCount > 0) {
- height += spacing;
- GC gc = new GC (this);
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- height += item.getHeaderHeight ();
- if (item.expanded) height += item.height;
- height += spacing;
- width = Math.max (width, item.getPreferredWidth (gc));
- }
- gc.dispose ();
- }
- }
- if (width == 0) width = DEFAULT_WIDTH;
- if (height == 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- return new Point (width, height);
- }
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (fixedHandle, true);
- handle = OS.gtk_vbox_new (false, 0);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.V_SCROLL) != 0) {
- scrolledHandle = OS.gtk_scrolled_window_new (0, 0);
- if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_scrolled_window_set_policy (scrolledHandle, OS.GTK_POLICY_NEVER, OS.GTK_POLICY_AUTOMATIC);
- OS.gtk_container_add (fixedHandle, scrolledHandle);
- OS.gtk_scrolled_window_add_with_viewport (scrolledHandle, handle);
- int /*long*/ viewport = OS.gtk_bin_get_child (scrolledHandle);
- OS.gtk_viewport_set_shadow_type (viewport, OS.GTK_SHADOW_NONE);
- } else {
- OS.gtk_container_add (fixedHandle, handle);
- }
- OS.gtk_container_set_border_width (handle, 0);
- } else {
- int /*long*/ topHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (topHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (topHandle, true);
- if ((style & SWT.V_SCROLL) != 0) {
- fixedHandle = topHandle;
- scrolledHandle = OS.gtk_scrolled_window_new (0, 0);
- if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
- handle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (handle, true);
- OS.gtk_container_add (fixedHandle, scrolledHandle);
-
- /*
- * Force the scrolledWindow to have a single child that is
- * not scrolled automatically. Calling gtk_container_add()
- * seems to add the child correctly but cause a warning.
- */
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.gtk_container_add (scrolledHandle, handle);
- display.setWarnings (warnings);
- } else {
- handle = topHandle;
- }
- OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS);
- }
-}
-
-void createItem (ExpandItem item, int style, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (itemCount == items.length) {
- ExpandItem [] newItems = new ExpandItem [itemCount + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- System.arraycopy (items, index, items, index + 1, itemCount - index);
- items [index] = item;
- itemCount++;
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- if (lastFocus == null) lastFocus = item;
- }
- item.width = Math.max (0, getClientArea ().width - spacing * 2);
- layoutItems (index, true);
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- items = new ExpandItem [4];
-}
-
-void destroyItem (ExpandItem item) {
- int index = 0;
- while (index < itemCount) {
- if (items [index] == item) break;
- index++;
- }
- if (index == itemCount) return;
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- if (item == lastFocus) {
- int focusIndex = index > 0 ? index - 1 : 1;
- if (focusIndex < itemCount) {
- lastFocus = items [focusIndex];
- lastFocus.redraw ();
- } else {
- lastFocus = null;
- }
- }
- }
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- item.redraw ();
- layoutItems (index, true);
-}
-
-int /*long*/ eventHandle () {
- return OS.GTK_VERSION >= OS.VERSION (2, 4, 0) ? fixedHandle : handle;
-}
-
-boolean forceFocus (int /*long*/ focusHandle) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if (lastFocus != null && lastFocus.setFocus ()) return true;
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- if (item.setFocus ()) return true;
- }
- }
- return super.forceFocus (focusHandle);
-}
-
-boolean hasFocus () {
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- for (int i=0; i<itemCount; i++) {
- ExpandItem item = items [i];
- if (item.hasFocus ()) return true;
- }
- }
- return super.hasFocus();
-}
-
-void hookEvents () {
- super.hookEvents ();
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if (scrolledHandle != 0) {
- OS.g_signal_connect_closure (scrolledHandle, OS.size_allocate, display.closures [SIZE_ALLOCATE], true);
- }
- }
-}
-
-int getBandHeight () {
- if (font == null) return ExpandItem.CHEVRON_SIZE;
- GC gc = new GC (this);
- FontMetrics metrics = gc.getFontMetrics ();
- gc.dispose ();
- return Math.max (ExpandItem.CHEVRON_SIZE, metrics.getHeight ());
-}
-
-GdkColor getForegroundColor () {
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- if ((state & FOREGROUND) == 0) {
- return display.getSystemColor (SWT.COLOR_TITLE_FOREGROUND).handle;
- }
- }
- return super.getForegroundColor ();
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ExpandItem getItem (int index) {
- checkWidget();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- return itemCount;
-}
-
-/**
- * Returns an array of <code>ExpandItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ExpandItem [] getItems () {
- checkWidget ();
- ExpandItem [] result = new ExpandItem [itemCount];
- System.arraycopy (items, 0, result, 0, itemCount);
- return result;
-}
-
-/**
- * Returns the receiver's spacing.
- *
- * @return the spacing
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSpacing () {
- checkWidget ();
- return spacing;
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) {
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
- int x = (int)gdkEvent.x;
- int y = (int)gdkEvent.y;
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items[i];
- boolean hover = item.x <= x && x < (item.x + item.width) && item.y <= y && y < (item.y + getBandHeight ());
- if (hover && item != lastFocus) {
- lastFocus.redraw ();
- lastFocus = item;
- lastFocus.redraw ();
- forceFocus ();
- break;
- }
- }
- }
- return super.gtk_button_press_event (widget, event);
-}
-
-int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ event) {
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- if (lastFocus != null) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
- int x = (int)gdkEvent.x;
- int y = (int)gdkEvent.y;
- boolean hover = lastFocus.x <= x && x < (lastFocus.x + lastFocus.width) && lastFocus.y <= y && y < (lastFocus.y + getBandHeight ());
- if (hover) {
- Event ev = new Event ();
- ev.item = lastFocus;
- notifyListeners (lastFocus.expanded ? SWT.Collapse : SWT.Expand, ev);
- lastFocus.expanded = !lastFocus.expanded;
- showItem (lastFocus);
- }
- }
- }
- return super.gtk_button_release_event (widget, event);
-}
-
-int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ eventPtr) {
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- GdkEventExpose gdkEvent = new GdkEventExpose ();
- OS.memmove(gdkEvent, eventPtr, GdkEventExpose.sizeof);
- GCData data = new GCData ();
- data.damageRgn = gdkEvent.region;
- GC gc = GC.gtk_new (this, data);
- OS.gdk_gc_set_clip_region (gc.handle, gdkEvent.region);
- boolean hasFocus = isFocusControl ();
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- item.drawItem (gc, hasFocus && item == lastFocus);
- }
- gc.dispose ();
- }
- return super.gtk_expose_event (widget, eventPtr);
-}
-
-int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) {
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- if (lastFocus != null) lastFocus.redraw ();
- }
- return super.gtk_focus_in_event(widget, event);
-}
-
-int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) {
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- if (lastFocus != null) lastFocus.redraw ();
- }
- return super.gtk_focus_out_event (widget, event);
-}
-
-int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if (!hasFocus ()) return 0;
- int /*long*/ result = super.gtk_key_press_event (widget, event);
- if (result != 0) return result;
- int index = 0;
- while (index < itemCount) {
- if (items [index].hasFocus ()) break;
- index++;
- }
- GdkEventKey gdkEvent = new GdkEventKey ();
- OS.memmove (gdkEvent, event, GdkEventKey.sizeof);
- boolean next = false;
- switch (gdkEvent.keyval) {
- case OS.GDK_Up:
- case OS.GDK_Left: next = false; break;
- case OS.GDK_Down:
- case OS.GDK_Right: next = true; break;
- default: return result;
- }
- int start = index, offset = next ? 1 : -1;
- while ((index = (index + offset + itemCount) % itemCount) != start) {
- ExpandItem item = items [index];
- if (item.setFocus ()) return result;
- }
- return result;
- } else {
- if (lastFocus != null) {
- GdkEventKey keyEvent = new GdkEventKey ();
- OS.memmove (keyEvent, event, GdkEventKey.sizeof);
- switch (keyEvent.keyval) {
- case OS.GDK_Return:
- case OS.GDK_space:
- Event ev = new Event ();
- ev.item = lastFocus;
- sendEvent (lastFocus.expanded ? SWT.Collapse :SWT.Expand, ev);
- lastFocus.expanded = !lastFocus.expanded;
- showItem (lastFocus);
- break;
- case OS.GDK_Up:
- case OS.GDK_KP_Up: {
- int focusIndex = indexOf (lastFocus);
- if (focusIndex > 0) {
- lastFocus.redraw ();
- lastFocus = items [focusIndex - 1];
- lastFocus.redraw ();
- }
- break;
- }
- case OS.GDK_Down:
- case OS.GDK_KP_Down: {
- int focusIndex = indexOf (lastFocus);
- if (focusIndex < itemCount - 1) {
- lastFocus.redraw ();
- lastFocus = items [focusIndex + 1];
- lastFocus.redraw ();
- }
- break;
- }
- }
- }
- }
- return super.gtk_key_press_event (widget, event);
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (ExpandItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i = 0; i < itemCount; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-
-void layoutItems (int index, boolean setScrollbar) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- if (item != null) item.resizeControl (yCurrentScroll);
- }
- } else {
- if (index < itemCount) {
- int y = spacing - yCurrentScroll;
- for (int i = 0; i < index; i++) {
- ExpandItem item = items [i];
- if (item.expanded) y += item.height;
- y += item.getHeaderHeight() + spacing;
- }
- for (int i = index; i < itemCount; i++) {
- ExpandItem item = items [i];
- item.setBounds (spacing, y, 0, 0, true, false);
- if (item.expanded) y += item.height;
- y += item.getHeaderHeight() + spacing;
- }
- }
- if (setScrollbar) setScrollbar ();
- }
-}
-
-int /*long*/ gtk_size_allocate (int /*long*/ widget, int /*long*/ allocation) {
- int /*long*/ result = super.gtk_size_allocate (widget, allocation);
- layoutItems (0, false);
- return result;
-}
-
-int /*long*/ parentingHandle () {
- return OS.GTK_VERSION >= OS.VERSION (2, 4, 0) ? fixedHandle : handle;
-}
-
-void releaseChildren (boolean destroy) {
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- super.releaseChildren (destroy);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when items in the receiver are expanded or collapsed.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ExpandListener
- * @see #addExpandListener
- */
-public void removeExpandListener (ExpandListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Expand, listener);
- eventTable.unhook (SWT.Collapse, listener);
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- int result = super.setBounds (x, y, width, height, move, resize);
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- if (resize) {
- if ((style & SWT.V_SCROLL) != 0) {
- setScrollbar ();
- } else {
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- int newWidth = Math.max (0, getClientArea ().width - spacing * 2);
- if (item.width != newWidth) {
- item.setBounds (0, 0, newWidth, item.height, false, true);
- }
- }
- }
- }
- }
- return result;
-}
-
-void setFontDescription (int /*long*/ font) {
- super.setFontDescription (font);
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- for (int i = 0; i < itemCount; i++) {
- items[i].setFontDescription (font);
- }
- layoutItems (0, true);
- }
-}
-
-void setForegroundColor (GdkColor color) {
- super.setForegroundColor (color);
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- for (int i = 0; i < itemCount; i++) {
- items[i].setForegroundColor (color);
- }
- }
-}
-
-void setScrollbar () {
- if (itemCount == 0) return;
- if ((style & SWT.V_SCROLL) == 0) return;
- int height = getClientArea ().height;
- ExpandItem item = items [itemCount - 1];
- int maxHeight = item.y + getBandHeight () + spacing;
- if (item.expanded) maxHeight += item.height;
- int /*long*/ adjustmentHandle = OS.gtk_scrolled_window_get_vadjustment (scrolledHandle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, adjustmentHandle);
- yCurrentScroll = (int)adjustment.value;
-
- //claim bottom free space
- if (yCurrentScroll > 0 && height > maxHeight) {
- yCurrentScroll = Math.max (0, yCurrentScroll + maxHeight - height);
- layoutItems (0, false);
- }
- maxHeight += yCurrentScroll;
- adjustment.value = Math.min (yCurrentScroll, maxHeight);
- adjustment.upper = maxHeight;
- adjustment.page_size = height;
- OS.memmove (adjustmentHandle, adjustment);
- OS.gtk_adjustment_changed (adjustmentHandle);
- int policy = maxHeight > height ? OS.GTK_POLICY_ALWAYS : OS.GTK_POLICY_NEVER;
- OS.gtk_scrolled_window_set_policy (scrolledHandle, OS.GTK_POLICY_NEVER, policy);
- int width = OS.GTK_WIDGET_WIDTH (fixedHandle) - spacing * 2;
- if (policy == OS.GTK_POLICY_ALWAYS) {
- int /*long*/ vHandle = OS.GTK_SCROLLED_WINDOW_VSCROLLBAR (scrolledHandle);
- GtkRequisition requisition = new GtkRequisition ();
- OS.gtk_widget_size_request (vHandle, requisition);
- width -= requisition.width;
- }
- width = Math.max (0, width);
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item2 = items[i];
- item2.setBounds (0, 0, width, item2.height, false, true);
- }
-}
-
-/**
- * Sets the receiver's spacing. Spacing specifies the number of pixels allocated around
- * each item.
- *
- * @param spacing the spacing around each item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSpacing (int spacing) {
- checkWidget ();
- if (spacing < 0) return;
- if (spacing == this.spacing) return;
- this.spacing = spacing;
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- OS.gtk_box_set_spacing (handle, spacing);
- OS.gtk_container_set_border_width (handle, spacing);
- } else {
- if ((style & SWT.V_SCROLL) == 0) {
- int width = Math.max (0, getClientArea ().width - spacing * 2);
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- if (item.width != width) item.setBounds (0, 0, width, item.height, false, true);
- }
- }
- layoutItems (0, true);
- redraw ();
- }
-}
-
-void showItem (ExpandItem item) {
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setVisible (item.expanded);
- }
- item.redraw ();
- int index = indexOf (item);
- layoutItems (index + 1, true);
-}
-
-void updateScrollBarValue (ScrollBar bar) {
- yCurrentScroll = bar.getSelection();
- layoutItems (0, false);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java
deleted file mode 100644
index e141b605cb..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java
+++ /dev/null
@@ -1,631 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a expandable item in a expand bar.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see ExpandBar
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.2
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ExpandItem extends Item {
- ExpandBar parent;
- Control control;
- ImageList imageList;
- int /*long*/ clientHandle, boxHandle, labelHandle, imageHandle;
- boolean expanded;
- int x, y, width, height;
- int imageHeight, imageWidth;
- static final int TEXT_INSET = 6;
- static final int BORDER = 1;
- static final int CHEVRON_SIZE = 24;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ExpandItem (ExpandBar parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget (parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent, a
- * style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ExpandItem (ExpandBar parent, int style, int index) {
- super (parent, style);
- this.parent = parent;
- createWidget (index);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createHandle (int index) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- state |= HANDLE;
- handle = OS.gtk_expander_new (null);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- clientHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (clientHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (handle, clientHandle);
- boxHandle = OS.gtk_hbox_new (false, 4);
- if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES);
- labelHandle = OS.gtk_label_new (null);
- if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES);
- imageHandle = OS.gtk_image_new ();
- if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (boxHandle, imageHandle);
- OS.gtk_container_add (boxHandle, labelHandle);
- OS.gtk_expander_set_label_widget (handle, boxHandle);
- OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS);
- }
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- showWidget (index);
- parent.createItem (this, style, index);
-}
-
-void deregister() {
- super.deregister();
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- display.removeWidget (clientHandle);
- display.removeWidget (boxHandle);
- display.removeWidget (labelHandle);
- display.removeWidget (imageHandle);
- }
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- super.destroyWidget ();
-}
-
-void drawChevron (GC gc, int x, int y) {
- int [] polyline1, polyline2;
- if (expanded) {
- int px = x + 4 + 5;
- int py = y + 4 + 7;
- polyline1 = new int [] {
- px,py, px+1,py, px+1,py-1, px+2,py-1, px+2,py-2, px+3,py-2, px+3,py-3,
- px+3,py-2, px+4,py-2, px+4,py-1, px+5,py-1, px+5,py, px+6,py};
- py += 4;
- polyline2 = new int [] {
- px,py, px+1,py, px+1,py-1, px+2,py-1, px+2,py-2, px+3,py-2, px+3,py-3,
- px+3,py-2, px+4,py-2, px+4,py-1, px+5,py-1, px+5,py, px+6,py};
- } else {
- int px = x + 4 + 5;
- int py = y + 4 + 4;
- polyline1 = new int[] {
- px,py, px+1,py, px+1,py+1, px+2,py+1, px+2,py+2, px+3,py+2, px+3,py+3,
- px+3,py+2, px+4,py+2, px+4,py+1, px+5,py+1, px+5,py, px+6,py};
- py += 4;
- polyline2 = new int [] {
- px,py, px+1,py, px+1,py+1, px+2,py+1, px+2,py+2, px+3,py+2, px+3,py+3,
- px+3,py+2, px+4,py+2, px+4,py+1, px+5,py+1, px+5,py, px+6,py};
- }
- gc.setForeground (display.getSystemColor (SWT.COLOR_TITLE_FOREGROUND));
- gc.drawPolyline (polyline1);
- gc.drawPolyline (polyline2);
-}
-
-void drawItem (GC gc, boolean drawFocus) {
- int headerHeight = parent.getBandHeight ();
- Display display = getDisplay ();
- gc.setForeground (display.getSystemColor (SWT.COLOR_TITLE_BACKGROUND));
- gc.setBackground (display.getSystemColor (SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
- gc.fillGradientRectangle (x, y, width, headerHeight, true);
- if (expanded) {
- gc.setForeground (display.getSystemColor (SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
- gc.drawLine (x, y + headerHeight, x, y + headerHeight + height - 1);
- gc.drawLine (x, y + headerHeight + height - 1, x + width - 1, y + headerHeight + height - 1);
- gc.drawLine (x + width - 1, y + headerHeight + height - 1, x + width - 1, y + headerHeight);
- }
- int drawX = x;
- if (image != null) {
- drawX += ExpandItem.TEXT_INSET;
- if (imageHeight > headerHeight) {
- gc.drawImage (image, drawX, y + headerHeight - imageHeight);
- } else {
- gc.drawImage (image, drawX, y + (headerHeight - imageHeight) / 2);
- }
- drawX += imageWidth;
- }
- if (text.length() > 0) {
- drawX += ExpandItem.TEXT_INSET;
- Point size = gc.stringExtent (text);
- gc.setForeground (parent.getForeground ());
- gc.drawString (text, drawX, y + (headerHeight - size.y) / 2, true);
- }
- int chevronSize = ExpandItem.CHEVRON_SIZE;
- drawChevron (gc, x + width - chevronSize, y + (headerHeight - chevronSize) / 2);
- if (drawFocus) {
- gc.drawFocus (x + 1, y + 1, width - 2, headerHeight - 2);
- }
-}
-
-/**
- * Returns the control that is shown when the item is expanded.
- * If no control has been set, return <code>null</code>.
- *
- * @return the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget ();
- return control;
-}
-
-/**
- * Returns <code>true</code> if the receiver is expanded,
- * and false otherwise.
- *
- * @return the expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getExpanded () {
- checkWidget ();
- return expanded;
-}
-
-/**
- * Returns the height of the receiver's header
- *
- * @return the height of the header
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getHeaderHeight () {
- checkWidget ();
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- return OS.GTK_WIDGET_HEIGHT (handle) - (expanded ? height : 0);
- }
- return Math.max (parent.getBandHeight (), imageHeight);
-}
-
-/**
- * Gets the height of the receiver.
- *
- * @return the height
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getHeight () {
- checkWidget ();
- return height;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>ExpandBar</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ExpandBar getParent () {
- checkWidget();
- return parent;
-}
-
-int getPreferredWidth (GC gc) {
- int width = ExpandItem.TEXT_INSET * 2 + ExpandItem.CHEVRON_SIZE;
- if (image != null) {
- width += ExpandItem.TEXT_INSET + imageWidth;
- }
- if (text.length() > 0) {
- width += gc.stringExtent (text).x;
- }
- return width;
-}
-
-int /*long*/ gtk_activate (int /*long*/ widget) {
- Event event = new Event ();
- event.item = this;
- int type = OS.gtk_expander_get_expanded (handle) ? SWT.Collapse : SWT.Expand;
- parent.sendEvent (type, event);
- return 0;
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) {
- setFocus ();
- return 0;
-}
-
-int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) {
- OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS);
- parent.lastFocus = this;
- return 0;
-}
-
-int /*long*/ gtk_size_allocate (int /*long*/ widget, int /*long*/ allocation) {
- parent.layoutItems (0, false);
- return 0;
-}
-
-int /*long*/ gtk_enter_notify_event (int /*long*/ widget, int /*long*/ event) {
- parent.gtk_enter_notify_event(widget, event);
- return 0;
-}
-
-boolean hasFocus () {
- return OS.GTK_WIDGET_HAS_FOCUS (handle);
-}
-
-void hookEvents () {
- super.hookEvents ();
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- OS.g_signal_connect_closure (handle, OS.activate, display.closures [ACTIVATE], false);
- OS.g_signal_connect_closure (handle, OS.activate, display.closures [ACTIVATE_INVERSE], true);
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false);
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [FOCUS_OUT_EVENT], 0, display.closures [FOCUS_OUT_EVENT], false);
- OS.g_signal_connect_closure (clientHandle, OS.size_allocate, display.closures [SIZE_ALLOCATE], true);
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false);
- }
-}
-
-void redraw () {
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- int headerHeight = parent.getBandHeight ();
- if (imageHeight > headerHeight) {
- parent.redraw (x + ExpandItem.TEXT_INSET, y + headerHeight - imageHeight, imageWidth, imageHeight, false);
- }
- parent.redraw (x, y, width, headerHeight + height, false);
- }
-}
-
-void register () {
- super.register ();
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- display.addWidget (clientHandle, this);
- display.addWidget (boxHandle, this);
- display.addWidget (labelHandle, this);
- display.addWidget (imageHandle, this);
- }
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- clientHandle = boxHandle = labelHandle = imageHandle = 0;
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (imageList != null) imageList.dispose ();
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if (parent.lastFocus == this) parent.lastFocus = null;
- }
- imageList = null;
- control = null;
-}
-
-void resizeControl (int yScroll) {
- if (control != null && !control.isDisposed ()) {
- boolean visible = OS.gtk_expander_get_expanded (handle);
- if (visible) {
- int x = OS.GTK_WIDGET_X (clientHandle);
- int y = OS.GTK_WIDGET_Y (clientHandle);
- if (x != -1 && y != -1) {
- int width = OS.GTK_WIDGET_WIDTH (clientHandle);
- int height = OS.GTK_WIDGET_HEIGHT (clientHandle);
- int [] property = new int [1];
- OS.gtk_widget_style_get (handle, OS.focus_line_width, property, 0);
- y += property [0] * 2;
- height -= property [0] * 2;
-
- /*
- * Feature in GTK. When the ExpandBar is resize too small the control
- * shows up on top of the vertical scrollbar. This happen because the
- * GtkExpander does not set the size of child smaller than the request
- * size of its parent and because the control is not parented in the
- * hierarchy of the GtkScrolledWindow.
- * The fix is calculate the width ourselves when the scrollbar is visible.
- */
- ScrollBar vBar = parent.verticalBar;
- if (vBar != null) {
- if (OS.GTK_WIDGET_VISIBLE (vBar.handle)) {
- width = OS.GTK_WIDGET_WIDTH (parent.scrolledHandle) - parent.vScrollBarWidth () - 2 * parent.spacing;
- }
- }
- control.setBounds (x, y - yScroll, width, Math.max (0, height), true, true);
- }
- }
- control.setVisible (visible);
- }
-}
-
-void setBounds (int x, int y, int width, int height, boolean move, boolean size) {
- redraw ();
- int headerHeight = parent.getBandHeight ();
- if (move) {
- if (imageHeight > headerHeight) {
- y += (imageHeight - headerHeight);
- }
- this.x = x;
- this.y = y;
- redraw ();
- }
- if (size) {
- this.width = width;
- this.height = height;
- redraw ();
- }
- if (control != null && !control.isDisposed ()) {
- if (move) control.setLocation (x + BORDER, y + headerHeight);
- if (size) control.setSize (Math.max (0, width - 2 * BORDER), Math.max (0, height - BORDER));
- }
-}
-
-/**
- * Sets the control that is shown when the item is expanded.
- *
- * @param control the new control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget ();
- if (control != null) {
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- if (this.control == control) return;
- this.control = control;
- if (control != null) {
- control.setVisible (expanded);
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- int headerHeight = parent.getBandHeight ();
- control.setBounds (x + BORDER, y + headerHeight, Math.max (0, width - 2 * BORDER), Math.max (0, height - BORDER));
- }
- }
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- parent.layoutItems (0, true);
- }
-}
-
-/**
- * Sets the expanded state of the receiver.
- *
- * @param expanded the new expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setExpanded (boolean expanded) {
- checkWidget ();
- this.expanded = expanded;
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- OS.gtk_expander_set_expanded (handle, expanded);
- parent.layoutItems (0, true);
- } else {
- parent.showItem (this);
- }
-}
-
-boolean setFocus () {
- if (!OS.gtk_widget_get_child_visible (handle)) return false;
- OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS);
- OS.gtk_widget_grab_focus (handle);
- boolean result = OS.gtk_widget_is_focus (handle);
- if (!result) OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS);
- return result;
-}
-
-void setFontDescription (int /*long*/ font) {
- OS.gtk_widget_modify_font (handle, font);
- if (labelHandle != 0) OS.gtk_widget_modify_font (labelHandle, font);
- if (imageHandle != 0) OS.gtk_widget_modify_font (imageHandle, font);
-}
-
-void setForegroundColor (GdkColor color) {
- setForegroundColor (handle, color);
- if (labelHandle != 0) setForegroundColor (labelHandle, color);
- if (imageHandle != 0) setForegroundColor (imageHandle, color);
-}
-
-/**
- * Sets the height of the receiver. This is height of the item when it is expanded,
- * excluding the height of the header.
- *
- * @param height the new height
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHeight (int height) {
- checkWidget ();
- if (height < 0) return;
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- this.height = height;
- OS.gtk_widget_set_size_request (clientHandle, -1, height);
- parent.layoutItems (0, false);
- } else {
- setBounds (0, 0, width, height, false, true);
- if (expanded) parent.layoutItems (parent.indexOf (this) + 1, true);
- }
-}
-
-public void setImage (Image image) {
- super.setImage (image);
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- if (imageList != null) imageList.dispose ();
- imageList = null;
- if (image != null) {
- if (image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- imageList = new ImageList ();
- int imageIndex = imageList.add (image);
- int /*long*/ pixbuf = imageList.getPixbuf (imageIndex);
- OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf);
- if (text.length () == 0) OS.gtk_widget_hide (labelHandle);
- OS.gtk_widget_show (imageHandle);
- } else {
- OS.gtk_image_set_from_pixbuf (imageHandle, 0);
- OS.gtk_widget_show (labelHandle);
- OS.gtk_widget_hide (imageHandle);
- }
- } else {
- int oldImageHeight = imageHeight;
- if (image != null) {
- Rectangle bounds = image.getBounds ();
- imageHeight = bounds.height;
- imageWidth = bounds.width;
- } else {
- imageHeight = imageWidth = 0;
- }
- if (oldImageHeight != imageHeight) {
- parent.layoutItems (parent.indexOf (this), true);
- } else {
- redraw ();
- }
- }
-}
-
-void setOrientation() {
- super.setOrientation ();
- if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) {
- OS.gtk_widget_set_direction (handle, OS.GTK_TEXT_DIR_RTL);
- OS.gtk_container_forall (handle, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL);
- }
-}
-
-public void setText (String string) {
- super.setText (string);
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- OS.gtk_label_set_text (labelHandle, buffer);
- } else {
- redraw ();
- }
-}
-
-void showWidget (int index) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- OS.gtk_widget_show (handle);
- OS.gtk_widget_show (clientHandle);
- OS.gtk_container_add (parent.handle, handle);
- OS.gtk_box_set_child_packing (parent.handle, handle, false, false, 0, OS.GTK_PACK_START);
- if (boxHandle != 0) OS.gtk_widget_show (boxHandle);
- if (labelHandle != 0) OS.gtk_widget_show (labelHandle);
- }
-}
-
-int /*long*/ windowProc (int /*long*/ handle, int /*long*/ user_data) {
- switch ((int)/*64*/user_data) {
- case ACTIVATE_INVERSE: {
- expanded = OS.gtk_expander_get_expanded (handle);
- parent.layoutItems (0, false);
- return 0;
- }
- }
- return super.windowProc (handle, user_data);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java
deleted file mode 100644
index 6cbca2156c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java
+++ /dev/null
@@ -1,731 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-
-/**
- * Instances of this class allow the user to navigate
- * the file system and select or enter a file name.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SAVE, OPEN, MULTI</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles SAVE and OPEN may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#filedialog">FileDialog snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class FileDialog extends Dialog {
- String [] filterNames = new String [0];
- String [] filterExtensions = new String [0];
- String filterPath = "";
- String fileName = "";
- String[] fileNames = new String [0];
- String fullPath = "";
- int filterIndex = -1;
- boolean overwrite = false;
- boolean uriMode;
- int /*long*/ handle;
- static final char SEPARATOR = System.getProperty ("file.separator").charAt (0);
- static final char EXTENSION_SEPARATOR = ';';
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FileDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SAVE
- * @see SWT#OPEN
- * @see SWT#MULTI
- */
-public FileDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-String computeResultChooserDialog () {
- /* MULTI is only valid if the native dialog's action is Open */
- fullPath = null;
- if ((style & (SWT.SAVE | SWT.MULTI)) == SWT.MULTI) {
- int /*long*/ list = 0;
- if (uriMode) {
- list = OS.gtk_file_chooser_get_uris (handle);
- } else {
- list = OS.gtk_file_chooser_get_filenames (handle);
- }
- int listLength = OS.g_slist_length (list);
- fileNames = new String [listLength];
- int /*long*/ current = list;
- int writePos = 0;
- for (int i = 0; i < listLength; i++) {
- int /*long*/ name = OS.g_slist_data (current);
- int /*long*/ utf8Ptr = 0;
- if (uriMode) {
- utf8Ptr = name;
- } else {
- utf8Ptr = OS.g_filename_to_utf8 (name, -1, null, null, null);
- OS.g_free (name);
- }
- if (utf8Ptr != 0) {
- int /*long*/ [] items_written = new int /*long*/ [1];
- int /*long*/ utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null);
- OS.g_free (utf8Ptr);
- if (utf16Ptr != 0) {
- int clength = (int)/*64*/items_written [0];
- char [] chars = new char [clength];
- OS.memmove (chars, utf16Ptr, clength * 2);
- OS.g_free (utf16Ptr);
- fullPath = new String (chars);
- fileNames [writePos++] = fullPath.substring (fullPath.lastIndexOf (SEPARATOR) + 1);
- }
- }
- current = OS.g_slist_next (current);
- }
- if (writePos != 0 && writePos != listLength) {
- String [] validFileNames = new String [writePos];
- System.arraycopy (fileNames, 0, validFileNames, 0, writePos);
- fileNames = validFileNames;
- }
- OS.g_slist_free (list);
- } else {
- int /*long*/ utf8Ptr = 0;
- if (uriMode) {
- utf8Ptr = OS.gtk_file_chooser_get_uri (handle);
- } else {
- int /*long*/ path = OS.gtk_file_chooser_get_filename (handle);
- if (path != 0) {
- utf8Ptr = OS.g_filename_to_utf8 (path, -1, null, null, null);
- OS.g_free (path);
- }
- }
- if (utf8Ptr != 0) {
- int /*long*/ [] items_written = new int /*long*/ [1];
- int /*long*/ utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null);
- OS.g_free (utf8Ptr);
- if (utf16Ptr != 0) {
- int clength = (int)/*64*/items_written [0];
- char [] chars = new char [clength];
- OS.memmove (chars, utf16Ptr, clength * 2);
- OS.g_free (utf16Ptr);
- fullPath = new String (chars);
- fileNames = new String [1];
- fileNames[0] = fullPath.substring (fullPath.lastIndexOf (SEPARATOR) + 1);
- }
- }
- }
- filterIndex = -1;
- int /*long*/ filter = OS.gtk_file_chooser_get_filter (handle);
- if (filter != 0) {
- int /*long*/ filterNamePtr = OS.gtk_file_filter_get_name (filter);
- if (filterNamePtr != 0) {
- int length = OS.strlen (filterNamePtr);
- byte[] buffer = new byte [length];
- OS.memmove (buffer, filterNamePtr, length);
- //OS.g_free (filterNamePtr); //GTK owns this pointer - do not free
- String filterName = new String (Converter.mbcsToWcs (null, buffer));
- for (int i = 0; i < filterExtensions.length; i++) {
- if (filterNames.length > 0) {
- if (filterNames[i].equals(filterName)) {
- filterIndex = i;
- break;
- }
- } else {
- if (filterExtensions[i].equals(filterName)) {
- filterIndex = i;
- break;
- }
- }
- }
- }
- }
- if (fullPath != null) {
- int separatorIndex = fullPath.lastIndexOf (SEPARATOR);
- fileName = fullPath.substring (separatorIndex + 1);
- filterPath = fullPath.substring (0, separatorIndex);
- }
- return fullPath;
-}
-String computeResultClassicDialog () {
- filterIndex = -1;
- GtkFileSelection selection = new GtkFileSelection ();
- OS.memmove (selection, handle);
- int /*long*/ entry = selection.selection_entry;
- int /*long*/ entryText = OS.gtk_entry_get_text (entry);
- int entryLength = OS.strlen (entryText);
- if (entryLength == 0) {
- int /*long*/ fileList = selection.file_list;
- int /*long*/ listSelection = OS.gtk_tree_view_get_selection (fileList);
- int /*long*/[] model = new int /*long*/[1];
- int /*long*/ selectedList = OS.gtk_tree_selection_get_selected_rows (listSelection, model);
- if (selectedList == 0) return null;
- int listLength = OS.g_list_length (selectedList);
- if (listLength == 0) {
- OS.g_list_free (selectedList);
- return null;
- }
- int /*long*/ path = OS.g_list_nth_data (selectedList, 0);
- int /*long*/ [] ptr = new int /*long*/[1];
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (OS.gtk_tree_model_get_iter (model [0], iter, path)) {
- OS.gtk_tree_model_get (model [0], iter, 0, ptr, -1);
- }
- OS.g_free (iter);
- for (int i = 0; i < listLength; i++) {
- OS.gtk_tree_path_free (OS.g_list_nth_data (selectedList, i));
- }
- OS.g_list_free (selectedList);
- if (ptr [0] == 0) return null;
- int length = OS.strlen (ptr [0]);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr [0], length);
- OS.g_free (ptr [0]);
- OS.gtk_entry_set_text (entry, buffer);
- }
-
- int /*long*/ fileNamePtr = OS.gtk_file_selection_get_filename (handle);
- int /*long*/ utf8Ptr = OS.g_filename_to_utf8 (fileNamePtr, -1, null, null, null);
- int /*long*/ [] items_written = new int /*long*/ [1];
- int /*long*/ utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null);
- entryLength = (int)/*64*/items_written [0];
- char [] buffer = new char [entryLength];
- OS.memmove (buffer, utf16Ptr, entryLength * 2);
- String osAnswer = new String (buffer);
- OS.g_free (utf16Ptr);
- OS.g_free (utf8Ptr);
-
- if (osAnswer == null) return null;
- int separatorIndex = osAnswer.lastIndexOf (SEPARATOR);
- if (separatorIndex+1 == osAnswer.length ()) return null;
-
- String answer = fullPath = osAnswer;
- fileName = fullPath.substring (separatorIndex+1);
- filterPath = fullPath.substring (0, separatorIndex);
- if ((style & SWT.MULTI) == 0) {
- fileNames = new String[] {fileName};
- } else {
- int /*long*/ namesPtr = OS.gtk_file_selection_get_selections (handle);
- int /*long*/ namesPtr1 = namesPtr;
- int /*long*/ [] namePtr = new int /*long*/ [1];
- OS.memmove (namePtr, namesPtr1, OS.PTR_SIZEOF);
- int length = 0;
- while (namePtr[0] != 0) {
- length++;
- namesPtr1+=OS.PTR_SIZEOF;
- OS.memmove(namePtr, namesPtr1, OS.PTR_SIZEOF);
- }
- fileNames = new String [length];
- namePtr = new int /*long*/ [length];
- OS.memmove (namePtr, namesPtr, length * OS.PTR_SIZEOF);
- for (int i = 0; i < length; i++) {
- utf8Ptr = OS.g_filename_to_utf8 (namePtr [i], -1, null, null, null);
- items_written = new int /*long*/ [1];
- utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null);
- buffer = new char [(int)/*64*/items_written [0]];
- OS.memmove (buffer, utf16Ptr, items_written [0] * 2);
- String name = new String (buffer);
- fileNames [i] = name.substring (name.lastIndexOf (SEPARATOR) + 1);
- OS.g_free (utf16Ptr);
- OS.g_free (utf8Ptr);
- }
- OS.g_strfreev (namesPtr);
- }
- return answer;
-}
-/**
- * Returns the path of the first file that was
- * selected in the dialog relative to the filter path, or an
- * empty string if no such file has been selected.
- *
- * @return the relative path of the file
- */
-public String getFileName () {
- return fileName;
-}
-/**
- * Returns a (possibly empty) array with the paths of all files
- * that were selected in the dialog relative to the filter path.
- *
- * @return the relative paths of the files
- */
-public String [] getFileNames () {
- return fileNames;
-}
-/**
- * Returns the file extensions which the dialog will
- * use to filter the files it shows.
- *
- * @return the file extensions filter
- */
-public String [] getFilterExtensions () {
- return filterExtensions;
-}
-/**
- * Get the 0-based index of the file extension filter
- * which was selected by the user, or -1 if no filter
- * was selected.
- * <p>
- * This is an index into the FilterExtensions array and
- * the FilterNames array.
- * </p>
- *
- * @return index the file extension filter index
- *
- * @see #getFilterExtensions
- * @see #getFilterNames
- *
- * @since 3.4
- */
-public int getFilterIndex () {
- return filterIndex;
-}
-/**
- * Returns the names that describe the filter extensions
- * which the dialog will use to filter the files it shows.
- *
- * @return the list of filter names
- */
-public String [] getFilterNames () {
- return filterNames;
-}
-/**
- * Returns the directory path that the dialog will use, or an empty
- * string if this is not set. File names in this path will appear
- * in the dialog, filtered according to the filter extensions.
- *
- * @return the directory path string
- *
- * @see #setFilterExtensions
- */
-public String getFilterPath () {
- return filterPath;
-}
-/**
- * Returns the flag that the dialog will use to
- * determine whether to prompt the user for file
- * overwrite if the selected file already exists.
- *
- * @return true if the dialog will prompt for file overwrite, false otherwise
- *
- * @since 3.4
- */
-public boolean getOverwrite () {
- return overwrite;
-}
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a string describing the absolute path of the first selected file,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public String open () {
- boolean useChooserDialog = OS.GTK_VERSION >= OS.VERSION (2, 4, 10);
- if (useChooserDialog) {
- return openChooserDialog ();
- } else {
- return openClassicDialog ();
- }
-}
-String openChooserDialog () {
- byte [] titleBytes = Converter.wcsToMbcs (null, title, true);
- int action = (style & SWT.SAVE) != 0 ?
- OS.GTK_FILE_CHOOSER_ACTION_SAVE :
- OS.GTK_FILE_CHOOSER_ACTION_OPEN;
- int /*long*/ shellHandle = parent.topHandle ();
- Display display = parent != null ? parent.getDisplay (): Display.getCurrent ();
- if (display.getDismissalAlignment() == SWT.RIGHT) {
- handle = OS.gtk_file_chooser_dialog_new (titleBytes, shellHandle, action, OS.GTK_STOCK_CANCEL (), OS.GTK_RESPONSE_CANCEL, OS.GTK_STOCK_OK (), OS.GTK_RESPONSE_OK, 0);
- } else {
- handle = OS.gtk_file_chooser_dialog_new (titleBytes, shellHandle, action, OS.GTK_STOCK_OK (), OS.GTK_RESPONSE_OK, OS.GTK_STOCK_CANCEL (), OS.GTK_RESPONSE_CANCEL, 0);
- }
- OS.gtk_window_set_modal (handle, true);
- int /*long*/ pixbufs = OS.gtk_window_get_icon_list (shellHandle);
- if (pixbufs != 0) {
- OS.gtk_window_set_icon_list (handle, pixbufs);
- OS.g_list_free (pixbufs);
- }
- if (uriMode) {
- OS.gtk_file_chooser_set_local_only (handle, false);
- }
- presetChooserDialog ();
- display.addIdleProc ();
- String answer = null;
- Dialog oldModal = null;
- if (OS.gtk_window_get_modal (handle)) {
- oldModal = display.getModalDialog ();
- display.setModalDialog (this);
- }
- int signalId = 0;
- int /*long*/ hookId = 0;
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- signalId = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET());
- hookId = OS.g_signal_add_emission_hook (signalId, 0, display.emissionProc, handle, 0);
- }
- int response = OS.gtk_dialog_run (handle);
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- OS.g_signal_remove_emission_hook (signalId, hookId);
- }
- if (OS.gtk_window_get_modal (handle)) {
- display.setModalDialog (oldModal);
- }
- if (response == OS.GTK_RESPONSE_OK) {
- answer = computeResultChooserDialog ();
- }
- display.removeIdleProc ();
- OS.gtk_widget_destroy (handle);
- return answer;
-}
-String openClassicDialog () {
- byte [] titleBytes = Converter.wcsToMbcs (null, title, true);
- handle = OS.gtk_file_selection_new (titleBytes);
- if (parent != null) {
- int /*long*/ shellHandle = parent.topHandle ();
- OS.gtk_window_set_transient_for (handle, shellHandle);
- int /*long*/ pixbufs = OS.gtk_window_get_icon_list (shellHandle);
- if (pixbufs != 0) {
- OS.gtk_window_set_icon_list (handle, pixbufs);
- OS.g_list_free (pixbufs);
- }
- }
- OS.gtk_window_set_modal (handle, true);
- presetClassicDialog ();
- Display display = parent != null ? parent.getDisplay (): Display.getCurrent ();
- display.addIdleProc ();
- String answer = null;
- Dialog oldModal = null;
- if (OS.gtk_window_get_modal (handle)) {
- oldModal = display.getModalDialog ();
- display.setModalDialog (this);
- }
- int signalId = 0;
- int /*long*/ hookId = 0;
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- signalId = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET());
- hookId = OS.g_signal_add_emission_hook (signalId, 0, display.emissionProc, handle, 0);
- }
- int response = OS.gtk_dialog_run (handle);
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- OS.g_signal_remove_emission_hook (signalId, hookId);
- }
- if (OS.gtk_window_get_modal (handle)) {
- display.setModalDialog (oldModal);
- }
- if (response == OS.GTK_RESPONSE_OK) {
- answer = computeResultClassicDialog ();
- }
- display.removeIdleProc ();
- OS.gtk_widget_destroy (handle);
- return answer;
-}
-void presetChooserDialog () {
- /* MULTI is only valid if the native dialog's action is Open */
- if ((style & (SWT.SAVE | SWT.MULTI)) == SWT.MULTI) {
- OS.gtk_file_chooser_set_select_multiple (handle, true);
- }
- if (filterPath == null) filterPath = "";
- if (fileName == null) fileName = "";
- if ((style & SWT.SAVE) != 0) {
- if (filterPath.length () > 0) {
- if (uriMode) {
- byte [] buffer = Converter.wcsToMbcs (null, filterPath, true);
- OS.gtk_file_chooser_set_current_folder_uri (handle, buffer);
- } else {
- /* filename must be a full path */
- byte [] buffer = Converter.wcsToMbcs (null, SEPARATOR + filterPath, true);
-
- /*
- * Bug in GTK. GtkFileChooser may crash on GTK versions 2.4.10 to 2.6
- * when setting a file name that is not a true canonical path.
- * The fix is to use the canonical path.
- */
- int /*long*/ ptr = OS.realpath (buffer, null);
- OS.gtk_file_chooser_set_current_folder (handle, ptr);
- OS.g_free (ptr);
- }
- }
- if (fileName.length () > 0) {
- byte [] buffer = Converter.wcsToMbcs (null, fileName, true);
- OS.gtk_file_chooser_set_current_name (handle, buffer);
- }
- } else {
- StringBuffer stringBuffer = new StringBuffer();
- if (filterPath.length () > 0) {
- if (!uriMode) {
- /* filename must be a full path */
- stringBuffer.append(SEPARATOR);
- }
- stringBuffer.append(filterPath);
- stringBuffer.append(SEPARATOR);
- }
- if (fileName.length () > 0) {
- stringBuffer.append(fileName);
- }
- byte [] buffer = Converter.wcsToMbcs (null, stringBuffer.toString(), true);
- if (uriMode) {
- OS.gtk_file_chooser_set_uri (handle, buffer);
- } else {
- /*
- * Bug in GTK. GtkFileChooser may crash on GTK versions 2.4.10 to 2.6
- * when setting a file name that is not a true canonical path.
- * The fix is to use the canonical path.
- */
- int /*long*/ ptr = OS.realpath (buffer, null);
- if (ptr != 0) {
- OS.gtk_file_chooser_set_filename (handle, ptr);
- OS.g_free (ptr);
- }
- }
- }
-
- /* Set overwrite mode */
- if ((style & SWT.SAVE) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 8, 0)) {
- OS.gtk_file_chooser_set_do_overwrite_confirmation (handle, overwrite);
- }
- }
-
- /* Set the extension filters */
- if (filterNames == null) filterNames = new String [0];
- if (filterExtensions == null) filterExtensions = new String [0];
- int /*long*/ initialFilter = 0;
- for (int i = 0; i < filterExtensions.length; i++) {
- if (filterExtensions [i] != null) {
- int /*long*/ filter = OS.gtk_file_filter_new ();
- if (filterNames.length > i && filterNames [i] != null) {
- byte [] name = Converter.wcsToMbcs (null, filterNames [i], true);
- OS.gtk_file_filter_set_name (filter, name);
- } else {
- byte [] name = Converter.wcsToMbcs (null, filterExtensions [i], true);
- OS.gtk_file_filter_set_name (filter, name);
- }
- int start = 0;
- int index = filterExtensions [i].indexOf (EXTENSION_SEPARATOR);
- while (index != -1) {
- String current = filterExtensions [i].substring (start, index);
- byte [] filterString = Converter.wcsToMbcs (null, current, true);
- OS.gtk_file_filter_add_pattern (filter, filterString);
- start = index + 1;
- index = filterExtensions [i].indexOf (EXTENSION_SEPARATOR, start);
- }
- String current = filterExtensions [i].substring (start);
- byte [] filterString = Converter.wcsToMbcs (null, current, true);
- OS.gtk_file_filter_add_pattern (filter, filterString);
- OS.gtk_file_chooser_add_filter (handle, filter);
- if (i == filterIndex) {
- initialFilter = filter;
- }
- }
- }
- if (initialFilter != 0) {
- OS.gtk_file_chooser_set_filter(handle, initialFilter);
- }
- fullPath = null;
- fileNames = new String [0];
-}
-void presetClassicDialog () {
- OS.gtk_file_selection_set_select_multiple(handle, (style & SWT.MULTI) != 0);
-
- /* Calculate the fully-specified file name and convert to bytes */
- StringBuffer stringBuffer = new StringBuffer ();
- if (filterPath == null) {
- filterPath = "";
- } else {
- if (filterPath.length () > 0) {
- stringBuffer.append (filterPath);
- if (filterPath.charAt (filterPath.length () - 1) != SEPARATOR) {
- stringBuffer.append (SEPARATOR);
- }
- }
- }
- if (fileName == null) {
- fileName = "";
- } else {
- stringBuffer.append (fileName);
- }
- fullPath = stringBuffer.toString ();
- int length = fullPath.length ();
- char [] buffer = new char [length + 1];
- fullPath.getChars (0, length, buffer, 0);
- int /*long*/ utf8Ptr = OS.g_utf16_to_utf8 (buffer, -1, null, null, null);
- int /*long*/ fileNamePtr = OS.g_filename_from_utf8 (utf8Ptr, -1, null, null, null);
- OS.gtk_file_selection_set_filename (handle, fileNamePtr);
- OS.g_free (utf8Ptr);
- OS.g_free (fileNamePtr);
-
- if (filterNames == null) filterNames = new String [0];
- if (filterExtensions == null) filterExtensions = new String [0];
- fullPath = null;
- fileNames = new String [0];
-}
-/**
- * Set the initial filename which the dialog will
- * select by default when opened to the argument,
- * which may be null. The name will be prefixed with
- * the filter path when one is supplied.
- *
- * @param string the file name
- */
-public void setFileName (String string) {
- fileName = string;
-}
-/**
- * Set the file extensions which the dialog will
- * use to filter the files it shows to the argument,
- * which may be null.
- * <p>
- * The strings are platform specific. For example, on
- * some platforms, an extension filter string is typically
- * of the form "*.extension", where "*.*" matches all files.
- * For filters with multiple extensions, use semicolon as
- * a separator, e.g. "*.jpg;*.png".
- * </p>
- *
- * @param extensions the file extension filter
- *
- * @see #setFilterNames to specify the user-friendly
- * names corresponding to the extensions
- */
-public void setFilterExtensions (String [] extensions) {
- filterExtensions = extensions;
-}
-/**
- * Set the 0-based index of the file extension filter
- * which the dialog will use initially to filter the files
- * it shows to the argument.
- * <p>
- * This is an index into the FilterExtensions array and
- * the FilterNames array.
- * </p>
- *
- * @param index the file extension filter index
- *
- * @see #setFilterExtensions
- * @see #setFilterNames
- *
- * @since 3.4
- */
-public void setFilterIndex (int index) {
- filterIndex = index;
-}
-/**
- * Sets the names that describe the filter extensions
- * which the dialog will use to filter the files it shows
- * to the argument, which may be null.
- * <p>
- * Each name is a user-friendly short description shown for
- * its corresponding filter. The <code>names</code> array must
- * be the same length as the <code>extensions</code> array.
- * </p>
- *
- * @param names the list of filter names, or null for no filter names
- *
- * @see #setFilterExtensions
- */
-public void setFilterNames (String [] names) {
- filterNames = names;
-}
-/**
- * Sets the directory path that the dialog will use
- * to the argument, which may be null. File names in this
- * path will appear in the dialog, filtered according
- * to the filter extensions. If the string is null,
- * then the operating system's default filter path
- * will be used.
- * <p>
- * Note that the path string is platform dependent.
- * For convenience, either '/' or '\' can be used
- * as a path separator.
- * </p>
- *
- * @param string the directory path
- *
- * @see #setFilterExtensions
- */
-public void setFilterPath (String string) {
- filterPath = string;
-}
-
-/**
- * Sets the flag that the dialog will use to
- * determine whether to prompt the user for file
- * overwrite if the selected file already exists.
- *
- * @param overwrite true if the dialog will prompt for file overwrite, false otherwise
- *
- * @since 3.4
- */
-public void setOverwrite (boolean overwrite) {
- this.overwrite = overwrite;
-}
-/* Sets URI Mode.
- *
- * When the FileDialog is in URI mode it returns
- * a URI (instead of a file name) for the following
- * methods: open() and getFilterPath().
- * The input argment for setFilterPath() should also
- * be a URI.
- */
-/*public*/ void setURIMode (boolean uriMode) {
- this.uriMode = uriMode;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java
deleted file mode 100644
index d2c7d32698..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java
+++ /dev/null
@@ -1,243 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class allow the user to select a font
- * from all available fonts in the system.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class FontDialog extends Dialog {
- FontData fontData;
- RGB rgb;
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FontDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FontDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-/**
- * Returns a FontData object describing the font that was
- * selected in the dialog, or null if none is available.
- *
- * @return the FontData for the selected font, or null
- * @deprecated use #getFontList ()
- */
-public FontData getFontData () {
- return fontData;
-}
-
-/**
- * Returns a FontData set describing the font that was
- * selected in the dialog, or null if none is available.
- *
- * @return the FontData for the selected font, or null
- * @since 2.1.1
- */
-public FontData [] getFontList () {
- if (fontData == null) return null;
- FontData [] result = new FontData [1];
- result [0] = fontData;
- return result;
-}
-
-/**
- * Returns an RGB describing the color that was selected
- * in the dialog, or null if none is available.
- *
- * @return the RGB value for the selected color, or null
- *
- * @see PaletteData#getRGBs
- *
- * @since 2.1
- */
-public RGB getRGB () {
- return rgb;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a FontData object describing the font that was selected,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public FontData open () {
- int /*long*/ handle;
- byte [] titleBytes;
- titleBytes = Converter.wcsToMbcs (null, title, true);
- Display display = parent != null ? parent.getDisplay (): Display.getCurrent ();
- handle = OS.gtk_font_selection_dialog_new (titleBytes);
- if (parent!=null) {
- int /*long*/ shellHandle = parent.topHandle ();
- OS.gtk_window_set_transient_for(handle, shellHandle);
- int /*long*/ pixbufs = OS.gtk_window_get_icon_list (shellHandle);
- if (pixbufs != 0) {
- OS.gtk_window_set_icon_list (handle, pixbufs);
- OS.g_list_free (pixbufs);
- }
- }
- OS.gtk_window_set_modal (handle, true);
- if (fontData != null) {
- Font font = new Font (display, fontData);
- int /*long*/ fontName = OS.pango_font_description_to_string (font.handle);
- int length = OS.strlen (fontName);
- byte [] buffer = new byte [length + 1];
- OS.memmove (buffer, fontName, length);
- font.dispose();
- OS.g_free (fontName);
- OS.gtk_font_selection_dialog_set_font_name (handle, buffer);
- }
- display.addIdleProc ();
- Dialog oldModal = null;
- if (OS.gtk_window_get_modal (handle)) {
- oldModal = display.getModalDialog ();
- display.setModalDialog (this);
- }
- int signalId = 0;
- int /*long*/ hookId = 0;
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- signalId = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET());
- hookId = OS.g_signal_add_emission_hook (signalId, 0, display.emissionProc, handle, 0);
- }
- int response = OS.gtk_dialog_run (handle);
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- OS.g_signal_remove_emission_hook (signalId, hookId);
- }
- if (OS.gtk_window_get_modal (handle)) {
- display.setModalDialog (oldModal);
- }
- boolean success = response == OS.GTK_RESPONSE_OK;
- if (success) {
- int /*long*/ fontName = OS.gtk_font_selection_dialog_get_font_name (handle);
- int length = OS.strlen (fontName);
- byte [] buffer = new byte [length + 1];
- OS.memmove (buffer, fontName, length);
- OS.g_free (fontName);
- int /*long*/ fontDesc = OS.pango_font_description_from_string (buffer);
- Font font = Font.gtk_new (display, fontDesc);
- fontData = font.getFontData () [0];
- OS.pango_font_description_free (fontDesc);
- }
- display.removeIdleProc ();
- OS.gtk_widget_destroy(handle);
- if (!success) return null;
- return fontData;
-}
-/**
- * Sets a FontData object describing the font to be
- * selected by default in the dialog, or null to let
- * the platform choose one.
- *
- * @param fontData the FontData to use initially, or null
- * @deprecated use #setFontList (FontData [])
- */
-public void setFontData (FontData fontData) {
- this.fontData = fontData;
-}
-
-/**
- * Sets the set of FontData objects describing the font to
- * be selected by default in the dialog, or null to let
- * the platform choose one.
- *
- * @param fontData the set of FontData objects to use initially, or null
- * to let the platform select a default when open() is called
- *
- * @see Font#getFontData
- *
- * @since 2.1.1
- */
-public void setFontList (FontData [] fontData) {
- if (fontData != null && fontData.length > 0) {
- this.fontData = fontData [0];
- } else {
- this.fontData = null;
- }
-}
-/**
- * Sets the RGB describing the color to be selected by default
- * in the dialog, or null to let the platform choose one.
- *
- * @param rgb the RGB value to use initially, or null to let
- * the platform select a default when open() is called
- *
- * @see PaletteData#getRGBs
- *
- * @since 2.1
- */
-public void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java
deleted file mode 100644
index f2b75d007c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java
+++ /dev/null
@@ -1,292 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide an etched border
- * with an optional title.
- * <p>
- * Shadow styles are hints and may not be honoured
- * by the platform. To create a group with the
- * default shadow style for the platform, do not
- * specify a shadow style.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SHADOW_ETCHED_IN, SHADOW_ETCHED_OUT, SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the above styles may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Group extends Composite {
- int /*long*/ clientHandle, labelHandle;
- String text = "";
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SHADOW_ETCHED_IN
- * @see SWT#SHADOW_ETCHED_OUT
- * @see SWT#SHADOW_IN
- * @see SWT#SHADOW_OUT
- * @see SWT#SHADOW_NONE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Group (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-int /*long*/ clientHandle () {
- return clientHandle;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- Point size = super.computeSize(wHint, hHint, changed);
- int width = computeNativeSize (handle, SWT.DEFAULT, SWT.DEFAULT, false).x;
- size.x = Math.max (size.x, width);
- return size;
-}
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- forceResize ();
- int clientX = OS.GTK_WIDGET_X (clientHandle);
- int clientY = OS.GTK_WIDGET_Y (clientHandle);
- x -= clientX;
- y -= clientY;
- width += clientX + clientX;
- height += clientX + clientY;
- return new Rectangle (x, y, width, height);
-}
-
-void createHandle(int index) {
- state |= HANDLE | THEME_BACKGROUND;
- fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (fixedHandle, true);
- handle = OS.gtk_frame_new (null);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- labelHandle = OS.gtk_label_new (null);
- if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.g_object_ref (labelHandle);
- OS.gtk_object_sink (labelHandle);
- clientHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (clientHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (fixedHandle, handle);
- OS.gtk_container_add (handle, clientHandle);
- if ((style & SWT.SHADOW_IN) != 0) {
- OS.gtk_frame_set_shadow_type (handle, OS.GTK_SHADOW_IN);
- }
- if ((style & SWT.SHADOW_OUT) != 0) {
- OS.gtk_frame_set_shadow_type (handle, OS.GTK_SHADOW_OUT);
- }
- if ((style & SWT.SHADOW_ETCHED_IN) != 0) {
- OS.gtk_frame_set_shadow_type (handle, OS.GTK_SHADOW_ETCHED_IN);
- }
- if ((style & SWT.SHADOW_ETCHED_OUT) != 0) {
- OS.gtk_frame_set_shadow_type (handle, OS.GTK_SHADOW_ETCHED_OUT);
- }
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (clientHandle);
- display.removeWidget (labelHandle);
-}
-
-void enableWidget (boolean enabled) {
- OS.gtk_widget_set_sensitive (labelHandle, enabled);
-}
-
-int /*long*/ eventHandle () {
- return fixedHandle;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which is the string that the
- * is used as the <em>title</em>. If the text has not previously
- * been set, returns an empty string.
- *
- * @return the text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- return text;
-}
-
-void hookEvents () {
- super.hookEvents();
- if (labelHandle != 0) {
- OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false);
- }
-}
-
-boolean mnemonicHit (char key) {
- if (labelHandle == 0) return false;
- boolean result = super.mnemonicHit (labelHandle, key);
- if (result) setFocus ();
- return result;
-}
-
-boolean mnemonicMatch (char key) {
- if (labelHandle == 0) return false;
- return mnemonicMatch (labelHandle, key);
-}
-
-int /*long*/ parentingHandle() {
- return fixedHandle;
-}
-
-void register () {
- super.register ();
- display.addWidget (clientHandle, this);
- display.addWidget (labelHandle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- clientHandle = labelHandle = 0;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (labelHandle != 0) OS.g_object_unref (labelHandle);
- text = null;
-}
-
-void setBackgroundColor (GdkColor color) {
- super.setBackgroundColor (color);
- setBackgroundColor(fixedHandle, color);
-}
-
-void setFontDescription (int /*long*/ font) {
- super.setFontDescription (font);
- OS.gtk_widget_modify_font (labelHandle, font);
-}
-
-void setForegroundColor (GdkColor color) {
- super.setForegroundColor (color);
- setForegroundColor (labelHandle, color);
-}
-
-void setOrientation () {
- super.setOrientation ();
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- OS.gtk_widget_set_direction (labelHandle, OS.GTK_TEXT_DIR_RTL);
- }
-}
-
-/**
- * Sets the receiver's text, which is the string that will
- * be displayed as the receiver's <em>title</em>, to the argument,
- * which may not be null. The string may include the mnemonic character.
- * </p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, focus is assigned
- * to the first child of the group. On most platforms, the
- * mnemonic appears underlined but may be emphasised in a
- * platform specific manner. The mnemonic indicator character
- * '&amp;' can be escaped by doubling it in the string, causing
- * a single '&amp;' to be displayed.
- * </p>
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- text = string;
- char [] chars = fixMnemonic (string);
- byte [] buffer = Converter.wcsToMbcs (null, chars, true);
- OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer);
- if (string.length () != 0) {
- if (OS.gtk_frame_get_label_widget (handle) == 0) {
- OS.gtk_frame_set_label_widget (handle, labelHandle);
- }
- } else {
- OS.gtk_frame_set_label_widget (handle, 0);
- }
-}
-
-void showWidget () {
- super.showWidget ();
- if (clientHandle != 0) OS.gtk_widget_show (clientHandle);
- if (labelHandle != 0) OS.gtk_widget_show (labelHandle);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/IME.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/IME.java
deleted file mode 100644
index cc0036e7c9..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/IME.java
+++ /dev/null
@@ -1,443 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-
-
-/**
- * Instances of this class represent input method editors.
- * These are typically in-line pre-edit text areas that allow
- * the user to compose characters from Far Eastern languages
- * such as Japanese, Chinese or Korean.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>ImeComposition</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.4
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class IME extends Widget {
- Canvas parent;
- int caretOffset;
- int startOffset;
- int commitCount;
- String text;
- int [] ranges;
- TextStyle [] styles;
- boolean inComposition;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-IME () {
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a canvas control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public IME (Canvas parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget ();
-}
-
-void createWidget () {
- text = "";
- startOffset = -1;
- if (parent.getIME () == null) {
- parent.setIME (this);
- }
-}
-
-/**
- * Returns the offset of the caret from the start of the document.
- * The caret is within the current composition.
- *
- * @return the caret offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretOffset () {
- checkWidget ();
- return startOffset + caretOffset;
-}
-
-/**
- * Returns the commit count of the composition. This is the
- * number of characters that have been composed. When the
- * commit count is equal to the length of the composition
- * text, then the in-line edit operation is complete.
- *
- * @return the commit count
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see IME#getText
- */
-public int getCommitCount () {
- checkWidget ();
- return commitCount;
-}
-
-/**
- * Returns the offset of the composition from the start of the document.
- * This is the start offset of the composition within the document and
- * in not changed by the input method editor itself during the in-line edit
- * session.
- *
- * @return the offset of the composition
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCompositionOffset () {
- checkWidget ();
- return startOffset;
-}
-
-/**
- * Returns the ranges for the style that should be applied during the
- * in-line edit session.
- * <p>
- * The ranges array contains start and end pairs. Each pair refers to
- * the corresponding style in the styles array. For example, the pair
- * that starts at ranges[n] and ends at ranges[n+1] uses the style
- * at styles[n/2] returned by <code>getStyles()</code>.
- * </p>
- * @return the ranges for the styles
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see IME#getStyles
- */
-public int [] getRanges () {
- checkWidget ();
- if (ranges == null) return new int [0];
- int [] result = new int [ranges.length];
- for (int i = 0; i < result.length; i++) {
- result [i] = ranges [i] + startOffset;
- }
- return result;
-}
-
-/**
- * Returns the styles for the ranges.
- * <p>
- * The ranges array contains start and end pairs. Each pair refers to
- * the corresponding style in the styles array. For example, the pair
- * that starts at ranges[n] and ends at ranges[n+1] uses the style
- * at styles[n/2].
- * </p>
- *
- * @return the ranges for the styles
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see IME#getRanges
- */
-public TextStyle [] getStyles () {
- checkWidget ();
- if (styles == null) return new TextStyle [0];
- TextStyle [] result = new TextStyle [styles.length];
- System.arraycopy (styles, 0, result, 0, styles.length);
- return result;
-}
-
-/**
- * Returns the composition text.
- * <p>
- * The text for an IME is the characters in the widget that
- * are in the current composition. When the commit count is
- * equal to the length of the composition text, then the
- * in-line edit operation is complete.
- * </p>
- *
- * @return the widget text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-/**
- * Returns <code>true</code> if the caret should be wide, and
- * <code>false</code> otherwise. In some languages, for example
- * Korean, the caret is typically widened to the width of the
- * current character in the in-line edit session.
- *
- * @return the wide caret state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getWideCaret () {
- checkWidget ();
- return false;
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) {
- if (!isInlineEnabled ()) return 0;
- int /*long*/ imHandle = imHandle ();
- if (imHandle != 0) OS.gtk_im_context_reset (imHandle);
- return 0;
-}
-
-int /*long*/ gtk_commit (int /*long*/ imcontext, int /*long*/ textPtr) {
- if (!isInlineEnabled ()) return 0;
- boolean doit = true;
- ranges = null;
- styles = null;
- caretOffset = commitCount = 0;
- if (textPtr != 0 && inComposition) {
- int length = OS.strlen (textPtr);
- if (length != 0) {
- byte [] buffer = new byte [length];
- OS.memmove (buffer, textPtr, length);
- char [] chars = Converter.mbcsToWcs (null, buffer);
- Event event = new Event();
- event.detail = SWT.COMPOSITION_CHANGED;
- event.start = startOffset;
- event.end = startOffset + text.length ();
- event.text = text = chars != null ? new String (chars) : "";
- commitCount = text.length();
- sendEvent (SWT.ImeComposition, event);
- doit = event.doit;
- text = "";
- startOffset = -1;
- commitCount = 0;
- }
- }
- inComposition = false;
- return doit ? 0 : 1;
-}
-
-int /*long*/ gtk_preedit_changed (int /*long*/ imcontext) {
- if (!isInlineEnabled ()) return 0;
- ranges = null;
- styles = null;
- commitCount = 0;
- int /*long*/ imHandle = imHandle ();
- int /*long*/ [] preeditString = new int /*long*/ [1];
- int /*long*/ [] pangoAttrs = new int /*long*/ [1];
- int [] cursorPos = new int [1];
- OS.gtk_im_context_get_preedit_string (imHandle, preeditString, pangoAttrs, cursorPos);
- caretOffset = cursorPos [0];
- char [] chars = null;
- if (preeditString [0] != 0) {
- int length = OS.strlen (preeditString [0]);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, preeditString [0], length);
- chars = Converter.mbcsToWcs (null, buffer);
- if (pangoAttrs [0] != 0) {
- int count = 0;
- int /*long*/ iterator = OS.pango_attr_list_get_iterator (pangoAttrs [0]);
- while (OS.pango_attr_iterator_next (iterator)) count++;
- OS.pango_attr_iterator_destroy (iterator);
- ranges = new int [count * 2];
- styles = new TextStyle [count];
- iterator = OS.pango_attr_list_get_iterator (pangoAttrs [0]);
- PangoAttrColor attrColor = new PangoAttrColor ();
- PangoAttrInt attrInt = new PangoAttrInt ();
- int [] start = new int [1];
- int [] end = new int [1];
- for (int i = 0; i < count; i++) {
- OS.pango_attr_iterator_range (iterator, start, end);
- ranges [i * 2] = (int)/*64*/OS.g_utf8_pointer_to_offset (preeditString [0], preeditString [0] + start [0]);
- ranges [i * 2 + 1] = (int)/*64*/OS.g_utf8_pointer_to_offset (preeditString [0], preeditString [0] + end [0]) - 1;
- styles [i] = new TextStyle (null, null, null);
- int /*long*/ attr = OS.pango_attr_iterator_get (iterator, OS.PANGO_ATTR_FOREGROUND);
- if (attr != 0) {
- OS.memmove (attrColor, attr, PangoAttrColor.sizeof);
- GdkColor color = new GdkColor ();
- color.red = attrColor.color_red;
- color.green = attrColor.color_green;
- color.blue = attrColor.color_blue;
- styles [i].foreground = Color.gtk_new (display, color);
- }
- attr = OS.pango_attr_iterator_get (iterator, OS.PANGO_ATTR_BACKGROUND);
- if (attr != 0) {
- OS.memmove (attrColor, attr, PangoAttrColor.sizeof);
- GdkColor color = new GdkColor ();
- color.red = attrColor.color_red;
- color.green = attrColor.color_green;
- color.blue = attrColor.color_blue;
- styles [i].background = Color.gtk_new (display, color);
- }
- attr = OS.pango_attr_iterator_get (iterator, OS.PANGO_ATTR_UNDERLINE);
- if (attr != 0) {
- OS.memmove (attrInt, attr, PangoAttrInt.sizeof);
- styles [i].underline = attrInt.value != OS.PANGO_UNDERLINE_NONE;;
- styles [i].underlineStyle = SWT.UNDERLINE_SINGLE;
- switch (attrInt.value) {
- case OS.PANGO_UNDERLINE_DOUBLE:
- styles [i].underlineStyle = SWT.UNDERLINE_DOUBLE;
- break;
- case OS.PANGO_UNDERLINE_ERROR:
- styles [i].underlineStyle = SWT.UNDERLINE_ERROR;
- break;
- }
- if (styles [i].underline) {
- attr = OS.pango_attr_iterator_get(iterator, OS.PANGO_ATTR_UNDERLINE_COLOR);
- if (attr != 0) {
- OS.memmove (attrColor, attr, PangoAttrColor.sizeof);
- GdkColor color = new GdkColor ();
- color.red = attrColor.color_red;
- color.green = attrColor.color_green;
- color.blue = attrColor.color_blue;
- styles [i].underlineColor = Color.gtk_new (display, color);
- }
- }
- }
- OS.pango_attr_iterator_next (iterator);
- }
- OS.pango_attr_iterator_destroy (iterator);
- OS.pango_attr_list_unref (pangoAttrs [0]);
- }
- OS.g_free (preeditString [0]);
- }
- if (chars != null) {
- if (text.length() == 0) {
- /*
- * Bug in GTK. In Solaris, the IME sends multiple
- * preedit_changed signals with an empty text.
- * This behavior is not correct for SWT and can
- * cause the editor to replace its current selection
- * with an empty string. The fix is to ignore any
- * preedit_changed signals with an empty text when
- * the preedit buffer is already empty.
- */
- if (chars.length == 0) return 0;
- startOffset = -1;
- }
- int end = startOffset + text.length();
- if (startOffset == -1) {
- Event event = new Event ();
- event.detail = SWT.COMPOSITION_SELECTION;
- sendEvent (SWT.ImeComposition, event);
- startOffset = event.start;
- end = event.end;
- }
- inComposition = true;
- Event event = new Event ();
- event.detail = SWT.COMPOSITION_CHANGED;
- event.start = startOffset;
- event.end = end;
- event.text = text = chars != null ? new String (chars) : "";
- sendEvent (SWT.ImeComposition, event);
- }
- return 1;
-}
-
-int /*long*/ imHandle () {
- return parent.imHandle ();
-}
-
-boolean isInlineEnabled () {
- return hooks (SWT.ImeComposition);
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (this == parent.getIME ()) parent.setIME (null);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
- text = null;
- styles = null;
- ranges = null;
-}
-
-/**
- * Sets the offset of the composition from the start of the document.
- * This is the start offset of the composition within the document and
- * in not changed by the input method editor itself during the in-line edit
- * session but may need to be changed by clients of the IME. For example,
- * if during an in-line edit operation, a text editor inserts characters
- * above the IME, then the IME must be informed that the composition
- * offset has changed.
- *
- * @param offset the offset of the composition
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCompositionOffset (int offset) {
- checkWidget ();
- if (offset < 0) return;
- if (startOffset != -1) {
- startOffset = offset;
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ImageList.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ImageList.java
deleted file mode 100644
index cab405e065..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ImageList.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
-class ImageList {
- int /*long*/ [] pixbufs;
- int width = -1, height = -1;
- Image [] images;
-
-public ImageList() {
- images = new Image [4];
- pixbufs = new int /*long*/ [4];
-}
-
-public int add (Image image) {
- int index = 0;
- while (index < images.length) {
- if (images [index] != null) {
- if (images [index].isDisposed ()) {
- OS.g_object_unref (pixbufs [index]);
- images [index] = null;
- pixbufs [index] = 0;
- }
- }
- if (images [index] == null) break;
- index++;
- }
- if (index == images.length) {
- Image [] newImages = new Image [images.length + 4];
- System.arraycopy (images, 0, newImages, 0, images.length);
- images = newImages;
- int /*long*/ [] newPixbufs = new int /*long*/ [pixbufs.length + 4];
- System.arraycopy (pixbufs, 0, newPixbufs, 0, pixbufs.length);
- pixbufs = newPixbufs;
- }
- set (index, image);
- return index;
-}
-
-public void dispose () {
- if (pixbufs == null) return;
- for (int index=0; index<pixbufs.length; index++) {
- if (pixbufs [index] != 0) OS.g_object_unref (pixbufs [index]);
- }
- images = null;
- pixbufs = null;
-}
-
-public Image get (int index) {
- return images [index];
-}
-
-int /*long*/ getPixbuf (int index) {
- return pixbufs [index];
-}
-
-public int indexOf (Image image) {
- if (image == null) return -1;
- for (int index=0; index<images.length; index++) {
- if (image == images [index]) return index;
- }
- return -1;
-}
-
-int indexOf (int /*long*/ pixbuf) {
- if (pixbuf == 0) return -1;
- for (int index=0; index<images.length; index++) {
- if (pixbuf == pixbufs [index]) return index;
- }
- return -1;
-}
-
-public boolean isDisposed () {
- return images == null;
-}
-
-public void put (int index, Image image) {
- int count = images.length;
- if (!(0 <= index && index < count)) return;
- if (image != null) {
- set (index, image);
- } else {
- images [index] = null;
- if (pixbufs [index] != 0) OS.g_object_unref (pixbufs [index]);
- pixbufs [index] = 0;
- }
-}
-
-public void remove (Image image) {
- if (image == null) return;
- for (int index=0; index<images.length; index++) {
- if (image == images [index]){
- OS.g_object_unref (pixbufs [index]);
- images [index] = null;
- pixbufs [index] = 0;
- }
- }
-}
-
-void set (int index, Image image) {
- int [] w = new int [1], h = new int [1];
- OS.gdk_drawable_get_size (image.pixmap, w, h);
- int /*long*/ pixbuf = Display.createPixbuf (image);
- if (width == -1 || height == -1) {
- width = w [0];
- height = h [0];
- }
- if (w [0] != width || h [0] != height) {
- int /*long*/ scaledPixbuf = OS.gdk_pixbuf_scale_simple(pixbuf, width, height, OS.GDK_INTERP_BILINEAR);
- OS.g_object_unref (pixbuf);
- pixbuf = scaledPixbuf;
- }
- int /*long*/ oldPixbuf = pixbufs [index];
- if (oldPixbuf != 0) {
- if (images [index] == image) {
- OS.gdk_pixbuf_copy_area (pixbuf, 0, 0, width, height, oldPixbuf, 0, 0);
- OS.g_object_unref (pixbuf);
- pixbuf = oldPixbuf;
- } else {
- OS.g_object_unref (oldPixbuf);
- }
- }
- pixbufs [index] = pixbuf;
- images [index] = image;
-}
-
-public int size () {
- int result = 0;
- for (int index=0; index<images.length; index++) {
- if (images [index] != null) {
- if (images [index].isDisposed ()) {
- OS.g_object_unref (pixbufs [index]);
- images [index] = null;
- pixbufs [index] = 0;
- }
- if (images [index] != null) result++;
- }
- }
- return result;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java
deleted file mode 100644
index 82ec5be7ad..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java
+++ /dev/null
@@ -1,589 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a non-selectable
- * user interface object that displays a string or image.
- * When SEPARATOR is specified, displays a single
- * vertical or horizontal line.
- * <p>
- * Shadow styles are hints and may not be honored
- * by the platform. To create a separator label
- * with the default shadow style for the platform,
- * do not specify a shadow style.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SEPARATOR, HORIZONTAL, VERTICAL</dd>
- * <dd>SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd>
- * <dd>CENTER, LEFT, RIGHT, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of SHADOW_IN, SHADOW_OUT and SHADOW_NONE may be specified.
- * SHADOW_NONE is a HINT. Only one of HORIZONTAL and VERTICAL may be specified.
- * Only one of CENTER, LEFT and RIGHT may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#label">Label snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Label extends Control {
- int /*long*/ frameHandle, labelHandle, imageHandle;
- ImageList imageList;
- Image image;
- String text;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SEPARATOR
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#SHADOW_IN
- * @see SWT#SHADOW_OUT
- * @see SWT#SHADOW_NONE
- * @see SWT#CENTER
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#WRAP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Label (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- if ((style & SWT.SEPARATOR) != 0) {
- style = checkBits (style, SWT.VERTICAL, SWT.HORIZONTAL, 0, 0, 0, 0);
- return checkBits (style, SWT.SHADOW_OUT, SWT.SHADOW_IN, SWT.SHADOW_NONE, 0, 0, 0);
- }
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-
-void addRelation (Control control) {
- if (!control.isDescribedByLabel ()) return;
- if (labelHandle == 0) return;
- int /*long*/ accessible = OS.gtk_widget_get_accessible (labelHandle);
- int /*long*/ controlAccessible = OS.gtk_widget_get_accessible (control.handle);
- if (accessible != 0 && controlAccessible != 0) {
- OS.atk_object_add_relationship (controlAccessible, OS.ATK_RELATION_LABELLED_BY, accessible);
- }
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- if ((style & SWT.SEPARATOR) != 0) {
- if ((style & SWT.HORIZONTAL) != 0) {
- if (wHint == SWT.DEFAULT) wHint = DEFAULT_WIDTH;
- } else {
- if (hHint == SWT.DEFAULT) hHint = DEFAULT_HEIGHT;
- }
- }
- Point size;
- /*
- * Feature in GTK. GTK has a predetermined maximum width for wrapping text.
- * The fix is to use pango layout directly instead of the label size request
- * to calculate its preferred size.
- */
- boolean fixWrap = labelHandle != 0 && (style & SWT.WRAP) != 0 && (OS.GTK_WIDGET_FLAGS (labelHandle) & OS.GTK_VISIBLE) != 0;
- if (fixWrap || frameHandle != 0) forceResize ();
- if (fixWrap) {
- int /*long*/ labelLayout = OS.gtk_label_get_layout (labelHandle);
- int pangoWidth = OS.pango_layout_get_width (labelLayout);
- if (wHint != SWT.DEFAULT) {
- OS.pango_layout_set_width (labelLayout, wHint * OS.PANGO_SCALE);
- } else {
- OS.pango_layout_set_width (labelLayout, -1);
- }
- int [] w = new int [1], h = new int [1];
- OS.pango_layout_get_size (labelLayout, w, h);
- OS.pango_layout_set_width (labelLayout, pangoWidth);
- if (frameHandle != 0) {
- int [] labelWidth = new int [1], labelHeight = new int [1];
- OS.gtk_widget_get_size_request (labelHandle, labelWidth, labelHeight);
- OS.gtk_widget_set_size_request (labelHandle, 1, 1);
- size = computeNativeSize (frameHandle, -1, -1, changed);
- OS.gtk_widget_set_size_request (labelHandle, labelWidth [0], labelHeight [0]);
- size.x = size.x - 1;
- size.y = size.y - 1;
- } else {
- size = new Point (0,0);
- }
- size.x += wHint == SWT.DEFAULT ? OS.PANGO_PIXELS(w [0]) : wHint;
- size.y += hHint == SWT.DEFAULT ? OS.PANGO_PIXELS(h [0]) : hHint;
- } else {
- if (frameHandle != 0) {
- int [] reqWidth = new int [1], reqHeight = new int [1];
- OS.gtk_widget_get_size_request (handle, reqWidth, reqHeight);
- OS.gtk_widget_set_size_request (handle, wHint, hHint);
- size = computeNativeSize (frameHandle, -1, -1, changed);
- OS.gtk_widget_set_size_request (handle, reqWidth [0], reqHeight [0]);
- } else {
- size = computeNativeSize (handle, wHint, hHint, changed);
- }
- }
- /*
- * Feature in GTK. Instead of using the font height to determine
- * the preferred height of the widget, GTK uses the text metrics.
- * The fix is to ensure that the preferred height is at least as
- * tall as the font height.
- *
- * NOTE: This work around does not fix the case when there are
- * muliple lines of text.
- */
- if (hHint == SWT.DEFAULT && labelHandle != 0) {
- int /*long*/ layout = OS.gtk_label_get_layout (labelHandle);
- int /*long*/ context = OS.pango_layout_get_context (layout);
- int /*long*/ lang = OS.pango_context_get_language (context);
- int /*long*/ font = getFontDescription ();
- int /*long*/ metrics = OS.pango_context_get_metrics (context, font, lang);
- int ascent = OS.PANGO_PIXELS (OS.pango_font_metrics_get_ascent (metrics));
- int descent = OS.PANGO_PIXELS (OS.pango_font_metrics_get_descent (metrics));
- OS.pango_font_metrics_unref (metrics);
- int fontHeight = ascent + descent;
- int [] buffer = new int [1];
- OS.g_object_get (labelHandle, OS.ypad, buffer, 0);
- fontHeight += 2 * buffer [0];
- if (frameHandle != 0) {
- int /*long*/ style = OS.gtk_widget_get_style (frameHandle);
- fontHeight += 2 * OS.gtk_style_get_ythickness (style);
- fontHeight += 2 * OS.gtk_container_get_border_width (frameHandle);
- }
- size.y = Math.max (size.y, fontHeight);
- }
- return size;
-}
-
-void createHandle (int index) {
- state |= HANDLE | THEME_BACKGROUND;
- fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (fixedHandle, true);
- if ((style & SWT.SEPARATOR) != 0) {
- if ((style & SWT.HORIZONTAL)!= 0) {
- handle = OS.gtk_hseparator_new ();
- } else {
- handle = OS.gtk_vseparator_new ();
- }
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- } else {
- handle = OS.gtk_hbox_new (false, 0);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- labelHandle = OS.gtk_label_new_with_mnemonic (null);
- if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES);
- imageHandle = OS.gtk_image_new ();
- if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (handle, labelHandle);
- OS.gtk_container_add (handle, imageHandle);
- }
- if ((style & SWT.BORDER) != 0) {
- frameHandle = OS.gtk_frame_new (null);
- if (frameHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (fixedHandle, frameHandle);
- OS.gtk_container_add (frameHandle, handle);
- OS.gtk_frame_set_shadow_type (frameHandle, OS.GTK_SHADOW_ETCHED_IN);
- } else {
- OS.gtk_container_add (fixedHandle, handle);
- }
- if ((style & SWT.SEPARATOR) != 0) return;
- if ((style & SWT.WRAP) != 0) {
- OS.gtk_label_set_line_wrap (labelHandle, true);
- if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
- OS.gtk_label_set_line_wrap_mode (labelHandle, OS.PANGO_WRAP_WORD_CHAR);
- }
- }
- setAlignment ();
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- text = "";
-}
-
-void deregister () {
- super.deregister ();
- if (frameHandle != 0) display.removeWidget (frameHandle);
- if (labelHandle != 0) display.removeWidget (labelHandle);
- if (imageHandle != 0) display.removeWidget (imageHandle);
-}
-
-int /*long*/ eventHandle () {
- return fixedHandle;
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is a <code>SEPARATOR</code> label, in
- * which case, <code>NONE</code> is returned.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return 0;
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-public int getBorderWidth () {
- checkWidget();
- if (frameHandle != 0) {
- return OS.gtk_style_get_xthickness (OS.gtk_widget_get_style (frameHandle));
- }
- return 0;
-}
-
-/**
- * Returns the receiver's image if it has one, or null
- * if it does not.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget ();
- return image;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set or if the receiver is
- * a <code>SEPARATOR</code> label.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return "";
- return text;
-}
-
-void hookEvents () {
- super.hookEvents();
- if (labelHandle != 0) {
- OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false);
- }
-}
-
-boolean isDescribedByLabel () {
- return false;
-}
-
-boolean mnemonicHit (char key) {
- if (labelHandle == 0) return false;
- boolean result = super.mnemonicHit (labelHandle, key);
- if (result) {
- Composite control = this.parent;
- while (control != null) {
- Control [] children = control._getChildren ();
- int index = 0;
- while (index < children.length) {
- if (children [index] == this) break;
- index++;
- }
- index++;
- if (index < children.length) {
- if (children [index].setFocus ()) return result;
- }
- control = control.parent;
- }
- }
- return result;
-}
-
-boolean mnemonicMatch (char key) {
- if (labelHandle == 0) return false;
- return mnemonicMatch (labelHandle, key);
-}
-
-void register () {
- super.register ();
- if (frameHandle != 0) display.addWidget (frameHandle, this);
- if (labelHandle != 0) display.addWidget (labelHandle, this);
- if (imageHandle != 0) display.addWidget (imageHandle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- frameHandle = imageHandle = labelHandle = 0;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (imageList != null) imageList.dispose ();
- imageList = null;
- image = null;
- text = null;
-}
-
-void resizeHandle (int width, int height) {
- OS.gtk_widget_set_size_request (fixedHandle, width, height);
- OS.gtk_widget_set_size_request (frameHandle != 0 ? frameHandle : handle, width, height);
-}
-
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>. If the receiver is a <code>SEPARATOR</code>
- * label, the argument is ignored and the alignment is not changed.
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return;
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- setAlignment ();
-}
-
-void setAlignment () {
- if ((style & SWT.LEFT) != 0) {
- OS.gtk_misc_set_alignment (labelHandle, 0.0f, 0.0f);
- OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_LEFT);
- OS.gtk_misc_set_alignment (imageHandle, 0.0f, 0.5f);
- return;
- }
- if ((style & SWT.CENTER) != 0) {
- OS.gtk_misc_set_alignment (labelHandle, 0.5f, 0.0f);
- OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_CENTER);
- OS.gtk_misc_set_alignment (imageHandle, 0.5f, 0.5f);
- return;
- }
- if ((style & SWT.RIGHT) != 0) {
- OS.gtk_misc_set_alignment (labelHandle, 1.0f, 0.0f);
- OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_RIGHT);
- OS.gtk_misc_set_alignment (imageHandle, 1.0f, 0.5f);
- return;
- }
-}
-
-void setBackgroundColor (GdkColor color) {
- super.setBackgroundColor (color);
- setBackgroundColor(fixedHandle, color);
- if (labelHandle != 0) setBackgroundColor(labelHandle, color);
- if (imageHandle != 0) setBackgroundColor(imageHandle, color);
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- /*
- * Bug in GTK. For some reason, when the label is
- * wrappable and its container is resized, it does not
- * cause the label to be wrapped. The fix is to
- * determine the size that will wrap the label
- * and expilictly set that size to force the label
- * to wrap.
- *
- * This part of the fix causes the label to be
- * resized to the preferred size but it still
- * won't draw properly.
- */
- boolean fixWrap = resize && labelHandle != 0 && (style & SWT.WRAP) != 0;
- if (fixWrap) OS.gtk_widget_set_size_request (labelHandle, -1, -1);
- int result = super.setBounds (x, y, width, height, move, resize);
- /*
- * Bug in GTK. For some reason, when the label is
- * wrappable and its container is resized, it does not
- * cause the label to be wrapped. The fix is to
- * determine the size that will wrap the label
- * and expilictly set that size to force the label
- * to wrap.
- *
- * This part of the fix forces the label to be
- * resized so that it will draw wrapped.
- */
- if (fixWrap) {
- int labelWidth = OS.GTK_WIDGET_WIDTH (handle);
- int labelHeight = OS.GTK_WIDGET_HEIGHT (handle);
- OS.gtk_widget_set_size_request (labelHandle, labelWidth, labelHeight);
- /*
- * Bug in GTK. Setting the size request should invalidate the label's
- * layout, but it does not. The fix is to resize the label directly.
- */
- GtkRequisition requisition = new GtkRequisition ();
- OS.gtk_widget_size_request (labelHandle, requisition);
- GtkAllocation allocation = new GtkAllocation ();
- allocation.x = OS.GTK_WIDGET_X (labelHandle);
- allocation.y = OS.GTK_WIDGET_Y (labelHandle);
- allocation.width = labelWidth;
- allocation.height = labelHeight;
- OS.gtk_widget_size_allocate (labelHandle, allocation);
- }
- return result;
-}
-
-void setFontDescription (int /*long*/ font) {
- super.setFontDescription (font);
- if (labelHandle != 0) OS.gtk_widget_modify_font (labelHandle, font);
- if (imageHandle != 0) OS.gtk_widget_modify_font (imageHandle, font);
-}
-
-void setForegroundColor (GdkColor color) {
- super.setForegroundColor (color);
- setForegroundColor (fixedHandle, color);
- if (labelHandle != 0) setForegroundColor (labelHandle, color);
- if (imageHandle != 0) setForegroundColor (imageHandle, color);
-}
-
-void setOrientation () {
- super.setOrientation ();
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- if (labelHandle != 0) OS.gtk_widget_set_direction (labelHandle, OS.GTK_TEXT_DIR_RTL);
- if (imageHandle != 0) OS.gtk_widget_set_direction (imageHandle, OS.GTK_TEXT_DIR_RTL);
- }
-}
-
-/**
- * Sets the receiver's image to the argument, which may be
- * null indicating that no image should be displayed.
- *
- * @param image the image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return;
- this.image = image;
- if (imageList != null) imageList.dispose ();
- imageList = null;
- if (image != null) {
- imageList = new ImageList ();
- int imageIndex = imageList.add (image);
- int /*long*/ pixbuf = imageList.getPixbuf (imageIndex);
- OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf);
- OS.gtk_widget_hide (labelHandle);
- OS.gtk_widget_show (imageHandle);
- } else {
- OS.gtk_image_set_from_pixbuf (imageHandle, 0);
- OS.gtk_widget_show (labelHandle);
- OS.gtk_widget_hide (imageHandle);
- }
-}
-
-/**
- * Sets the receiver's text.
- * <p>
- * This method sets the widget label. The label may include
- * the mnemonic character and line delimiters.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, focus is assigned
- * to the control that follows the label. On most platforms,
- * the mnemonic appears underlined but may be emphasised in a
- * platform specific manner. The mnemonic indicator character
- * '&amp;' can be escaped by doubling it in the string, causing
- * a single '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- text = string;
- char [] chars = fixMnemonic (string);
- byte [] buffer = Converter.wcsToMbcs (null, chars, true);
- OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer);
- OS.gtk_widget_hide (imageHandle);
- OS.gtk_widget_show (labelHandle);
-}
-
-void showWidget () {
- super.showWidget ();
- if (frameHandle != 0) OS.gtk_widget_show (frameHandle);
- if (labelHandle != 0) OS.gtk_widget_show (labelHandle);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java
deleted file mode 100644
index 265b3dcd9c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java
+++ /dev/null
@@ -1,740 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.accessibility.*;
-
-/**
- * Instances of this class represent a selectable
- * user interface object that displays a text with
- * links.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#link">Link snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Link extends Control {
- String text;
- TextLayout layout;
- Color linkColor, disabledColor;
- Point [] offsets;
- Point selection;
- String [] ids;
- int [] mnemonics;
- int focusIndex;
-
- static final RGB LINK_FOREGROUND = new RGB (0, 51, 153);
- static final RGB LINK_DISABLED_FOREGROUND = new RGB (172, 168, 153);
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Link (Composite parent, int style) {
- super (parent, style);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected by the user.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- int width, height;
- int layoutWidth = layout.getWidth ();
- //TEMPORARY CODE
- if (wHint == 0) {
- layout.setWidth (1);
- Rectangle rect = layout.getBounds ();
- width = 0;
- height = rect.height;
- } else {
- layout.setWidth (wHint);
- Rectangle rect = layout.getBounds ();
- width = rect.width;
- height = rect.height;
- }
- layout.setWidth (layoutWidth);
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2;
- height += border * 2;
- return new Point (width, height);
-}
-
-void createHandle(int index) {
- state |= HANDLE | THEME_BACKGROUND;
- handle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (handle == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (handle, true);
- OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS);
- layout = new TextLayout (display);
- layout.setOrientation((style & SWT.RIGHT_TO_LEFT) != 0? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT);
- linkColor = new Color (display, LINK_FOREGROUND);
- disabledColor = new Color (display, LINK_DISABLED_FOREGROUND);
- offsets = new Point [0];
- ids = new String [0];
- mnemonics = new int [0];
- selection = new Point (-1, -1);
- focusIndex = -1;
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- layout.setFont (getFont ());
- text = "";
- initAccessible ();
-}
-
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- if (isDisposed ()) return;
- TextStyle linkStyle = new TextStyle (null, enabled ? linkColor : disabledColor, null);
- linkStyle.underline = true;
- for (int i = 0; i < offsets.length; i++) {
- Point point = offsets [i];
- layout.setStyle (linkStyle, point.x, point.y);
- }
- redraw ();
-}
-
-void fixStyle () {
- fixStyle (handle);
-}
-
-void initAccessible () {
- Accessible accessible = getAccessible ();
- accessible.addAccessibleListener (new AccessibleAdapter () {
- public void getName (AccessibleEvent e) {
- e.result = parse (text);
- }
- });
-
- accessible.addAccessibleControlListener (new AccessibleControlAdapter () {
- public void getChildAtPoint (AccessibleControlEvent e) {
- e.childID = ACC.CHILDID_SELF;
- }
-
- public void getLocation (AccessibleControlEvent e) {
- Rectangle rect = display.map (getParent (), null, getBounds ());
- e.x = rect.x;
- e.y = rect.y;
- e.width = rect.width;
- e.height = rect.height;
- }
-
- public void getChildCount (AccessibleControlEvent e) {
- e.detail = 0;
- }
-
- public void getRole (AccessibleControlEvent e) {
- e.detail = ACC.ROLE_LINK;
- }
-
- public void getState (AccessibleControlEvent e) {
- e.detail = ACC.STATE_FOCUSABLE;
- if (hasFocus ()) e.detail |= ACC.STATE_FOCUSED;
- }
-
- public void getDefaultAction (AccessibleControlEvent e) {
- e.result = SWT.getMessage ("SWT_Press"); //$NON-NLS-1$
- }
-
- public void getSelection (AccessibleControlEvent e) {
- if (hasFocus ()) e.childID = ACC.CHILDID_SELF;
- }
-
- public void getFocus (AccessibleControlEvent e) {
- if (hasFocus ()) e.childID = ACC.CHILDID_SELF;
- }
- });
-}
-
-String getNameText () {
- return getText ();
-}
-
-Rectangle [] getRectangles (int linkIndex) {
- int lineCount = layout.getLineCount ();
- Rectangle [] rects = new Rectangle [lineCount];
- int [] lineOffsets = layout.getLineOffsets ();
- Point point = offsets [linkIndex];
- int lineStart = 1;
- while (point.x > lineOffsets [lineStart]) lineStart++;
- int lineEnd = 1;
- while (point.y > lineOffsets [lineEnd]) lineEnd++;
- int index = 0;
- if (lineStart == lineEnd) {
- rects [index++] = layout.getBounds (point.x, point.y);
- } else {
- rects [index++] = layout.getBounds (point.x, lineOffsets [lineStart]-1);
- rects [index++] = layout.getBounds (lineOffsets [lineEnd-1], point.y);
- if (lineEnd - lineStart > 1) {
- for (int i = lineStart; i < lineEnd - 1; i++) {
- rects [index++] = layout.getLineBounds (i);
- }
- }
- }
- if (rects.length != index) {
- Rectangle [] tmp = new Rectangle [index];
- System.arraycopy (rects, 0, tmp, 0, index);
- rects = tmp;
- }
- return rects;
-}
-
-int getClientWidth () {
- return (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (handle);
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_button_press_event (widget, event);
- if (result != 0) return result;
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
- if (gdkEvent.button == 1 && gdkEvent.type == OS.GDK_BUTTON_PRESS) {
- if (focusIndex != -1) setFocus ();
- int x = (int) gdkEvent.x;
- int y = (int) gdkEvent.y;
- if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x;
- int offset = layout.getOffset (x, y, null);
- int oldSelectionX = selection.x;
- int oldSelectionY = selection.y;
- selection.x = offset;
- selection.y = -1;
- if (oldSelectionX != -1 && oldSelectionY != -1) {
- if (oldSelectionX > oldSelectionY) {
- int temp = oldSelectionX;
- oldSelectionX = oldSelectionY;
- oldSelectionY = temp;
- }
- Rectangle rect = layout.getBounds (oldSelectionX, oldSelectionY);
- redraw (rect.x, rect.y, rect.width, rect.height, false);
- }
- for (int j = 0; j < offsets.length; j++) {
- Rectangle [] rects = getRectangles (j);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rect = rects [i];
- if (rect.contains (x, y)) {
- focusIndex = j;
- redraw ();
- return result;
- }
- }
- }
- }
- return result;
-}
-
-int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_button_release_event (widget, event);
- if (result != 0) return result;
- if (focusIndex == -1) return result;
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
- if (gdkEvent.button == 1) {
- int x = (int) gdkEvent.x;
- int y = (int) gdkEvent.y;
- if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x;
- Rectangle [] rects = getRectangles (focusIndex);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rect = rects [i];
- if (rect.contains (x, y)) {
- Event ev = new Event ();
- ev.text = ids [focusIndex];
- sendEvent (SWT.Selection, ev);
- return result;
- }
- }
- }
- return result;
-}
-
-int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) {
- int /*long*/ result = super.gtk_event_after (widget, gdkEvent);
- GdkEvent event = new GdkEvent ();
- OS.memmove (event, gdkEvent, GdkEvent.sizeof);
- switch (event.type) {
- case OS.GDK_FOCUS_CHANGE:
- redraw ();
- break;
- }
- return result;
-}
-
-int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ eventPtr) {
- if ((state & OBSCURED) != 0) return 0;
- GdkEventExpose gdkEvent = new GdkEventExpose ();
- OS.memmove (gdkEvent, eventPtr, GdkEventExpose.sizeof);
- GCData data = new GCData ();
- data.damageRgn = gdkEvent.region;
- GC gc = GC.gtk_new (this, data);
- OS.gdk_gc_set_clip_region (gc.handle, gdkEvent.region);
- int selStart = selection.x;
- int selEnd = selection.y;
- if (selStart > selEnd) {
- selStart = selection.y;
- selEnd = selection.x;
- }
- // temporary code to disable text selection
- selStart = selEnd = -1;
- if ((state & DISABLED) != 0) gc.setForeground (disabledColor);
- layout.draw (gc, 0, 0, selStart, selEnd, null, null);
- if (hasFocus () && focusIndex != -1) {
- Rectangle [] rects = getRectangles (focusIndex);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rect = rects [i];
- gc.drawFocus (rect.x, rect.y, rect.width, rect.height);
- }
- }
- if (hooks (SWT.Paint) || filters (SWT.Paint)) {
- Event event = new Event ();
- event.count = gdkEvent.count;
- event.x = gdkEvent.area_x;
- event.y = gdkEvent.area_y;
- event.width = gdkEvent.area_width;
- event.height = gdkEvent.area_height;
- if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.width - event.x;
- event.gc = gc;
- sendEvent (SWT.Paint, event);
- event.gc = null;
- }
- gc.dispose ();
- return 0;
-}
-
-int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ eventPtr) {
- int /*long*/ result = super.gtk_key_press_event (widget, eventPtr);
- if (result != 0) return result;
- if (focusIndex == -1) return result;
- GdkEventKey gdkEvent = new GdkEventKey ();
- OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof);
- switch (gdkEvent.keyval) {
- case OS.GDK_Return:
- case OS.GDK_KP_Enter:
- case OS.GDK_space:
- Event event = new Event ();
- event.text = ids [focusIndex];
- sendEvent (SWT.Selection, event);
- break;
- case OS.GDK_Tab:
- if (focusIndex < offsets.length - 1) {
- focusIndex++;
- redraw ();
- }
- break;
- case OS.GDK_ISO_Left_Tab:
- if (focusIndex > 0) {
- focusIndex--;
- redraw ();
- }
- break;
- }
- return result;
-}
-
-int /*long*/ gtk_motion_notify_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_motion_notify_event (widget, event);
- if (result != 0) return result;
- GdkEventMotion gdkEvent = new GdkEventMotion ();
- OS.memmove (gdkEvent, event, GdkEventMotion.sizeof);
- int x = (int) gdkEvent.x;
- int y = (int) gdkEvent.y;
- if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x;
- if ((gdkEvent.state & OS.GDK_BUTTON1_MASK) != 0) {
- int oldSelection = selection.y;
- selection.y = layout.getOffset (x, y, null);
- if (selection.y != oldSelection) {
- int newSelection = selection.y;
- if (oldSelection > newSelection) {
- int temp = oldSelection;
- oldSelection = newSelection;
- newSelection = temp;
- }
- Rectangle rect = layout.getBounds (oldSelection, newSelection);
- redraw (rect.x, rect.y, rect.width, rect.height, false);
- }
- } else {
- for (int j = 0; j < offsets.length; j++) {
- Rectangle [] rects = getRectangles (j);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rect = rects [i];
- if (rect.contains (x, y)) {
- setCursor (display.getSystemCursor (SWT.CURSOR_HAND));
- return result;
- }
- }
- }
- setCursor (null);
- }
- return result;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (layout != null) layout.dispose ();
- layout = null;
- if (linkColor != null) linkColor.dispose ();
- linkColor = null;
- if (disabledColor != null) disabledColor.dispose ();
- disabledColor = null;
- offsets = null;
- ids = null;
- mnemonics = null;
- text = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection, listener);
-}
-
-String parse (String string) {
- int length = string.length ();
- offsets = new Point [length / 4];
- ids = new String [length / 4];
- mnemonics = new int [length / 4 + 1];
- StringBuffer result = new StringBuffer ();
- char [] buffer = new char [length];
- string.getChars (0, string.length (), buffer, 0);
- int index = 0, state = 0, linkIndex = 0;
- int start = 0, tagStart = 0, linkStart = 0, endtagStart = 0, refStart = 0;
- while (index < length) {
- char c = Character.toLowerCase (buffer [index]);
- switch (state) {
- case 0:
- if (c == '<') {
- tagStart = index;
- state++;
- }
- break;
- case 1:
- if (c == 'a') state++;
- break;
- case 2:
- switch (c) {
- case 'h':
- state = 7;
- break;
- case '>':
- linkStart = index + 1;
- state++;
- break;
- default:
- if (Character.isWhitespace(c)) break;
- else state = 13;
- }
- break;
- case 3:
- if (c == '<') {
- endtagStart = index;
- state++;
- }
- break;
- case 4:
- state = c == '/' ? state + 1 : 3;
- break;
- case 5:
- state = c == 'a' ? state + 1 : 3;
- break;
- case 6:
- if (c == '>') {
- mnemonics [linkIndex] = parseMnemonics (buffer, start, tagStart, result);
- int offset = result.length ();
- parseMnemonics (buffer, linkStart, endtagStart, result);
- offsets [linkIndex] = new Point (offset, result.length () - 1);
- if (ids [linkIndex] == null) {
- ids [linkIndex] = new String (buffer, linkStart, endtagStart - linkStart);
- }
- linkIndex++;
- start = tagStart = linkStart = endtagStart = refStart = index + 1;
- state = 0;
- } else {
- state = 3;
- }
- break;
- case 7:
- state = c == 'r' ? state + 1 : 0;
- break;
- case 8:
- state = c == 'e' ? state + 1 : 0;
- break;
- case 9:
- state = c == 'f' ? state + 1 : 0;
- break;
- case 10:
- state = c == '=' ? state + 1 : 0;
- break;
- case 11:
- if (c == '"') {
- state++;
- refStart = index + 1;
- } else {
- state = 0;
- }
- break;
- case 12:
- if (c == '"') {
- ids[linkIndex] = new String (buffer, refStart, index - refStart);
- state = 2;
- }
- break;
- case 13:
- if (Character.isWhitespace (c)) {
- state = 0;
- } else if (c == '='){
- state++;
- }
- break;
- case 14:
- state = c == '"' ? state + 1 : 0;
- break;
- case 15:
- if (c == '"') state = 2;
- break;
- default:
- state = 0;
- break;
- }
- index++;
- }
- if (start < length) {
- int tmp = parseMnemonics (buffer, start, tagStart, result);
- int mnemonic = parseMnemonics (buffer, Math.max (tagStart, linkStart), length, result);
- if (mnemonic == -1) mnemonic = tmp;
- mnemonics [linkIndex] = mnemonic;
- } else {
- mnemonics [linkIndex] = -1;
- }
- if (offsets.length != linkIndex) {
- Point [] newOffsets = new Point [linkIndex];
- System.arraycopy (offsets, 0, newOffsets, 0, linkIndex);
- offsets = newOffsets;
- String [] newIDs = new String [linkIndex];
- System.arraycopy (ids, 0, newIDs, 0, linkIndex);
- ids = newIDs;
- int [] newMnemonics = new int [linkIndex + 1];
- System.arraycopy (mnemonics, 0, newMnemonics, 0, linkIndex + 1);
- mnemonics = newMnemonics;
- }
- return result.toString ();
-}
-
-int parseMnemonics (char[] buffer, int start, int end, StringBuffer result) {
- int mnemonic = -1, index = start;
- while (index < end) {
- if (buffer [index] == '&') {
- if (index + 1 < end && buffer [index + 1] == '&') {
- result.append (buffer [index]);
- index++;
- } else {
- mnemonic = result.length();
- }
- } else {
- result.append (buffer [index]);
- }
- index++;
- }
- return mnemonic;
-}
-
-int setBounds(int x, int y, int width, int height, boolean move, boolean resize) {
- int result = super.setBounds (x, y, width,height, move, resize);
- if ((result & RESIZED) != 0) {
- layout.setWidth (width > 0 ? width : -1);
- redraw ();
- }
- return result;
-}
-
-void setFontDescription (int /*long*/ font) {
- super.setFontDescription (font);
- layout.setFont (Font.gtk_new (display, font));
-}
-
-/**
- * Sets the receiver's text.
- * <p>
- * The string can contain both regular text and hyperlinks. A hyperlink
- * is delimited by an anchor tag, &lt;A&gt; and &lt;/A&gt;. Within an
- * anchor, a single HREF attribute is supported. When a hyperlink is
- * selected, the text field of the selection event contains either the
- * text of the hyperlink or the value of its HREF, if one was specified.
- * In the rare case of identical hyperlinks within the same string, the
- * HREF attribute can be used to distinguish between them. The string may
- * include the mnemonic character and line delimiters. The only delimiter
- * the HREF attribute supports is the quotation mark (").
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (string.equals (text)) return;
- text = string;
- layout.setText (parse (string));
- focusIndex = offsets.length > 0 ? 0 : -1;
- selection.x = selection.y = -1;
- boolean enabled = (state & DISABLED) == 0;
- TextStyle linkStyle = new TextStyle (null, enabled ? linkColor : disabledColor, null);
- linkStyle.underline = true;
- int [] bidiSegments = new int [offsets.length*2];
- for (int i = 0; i < offsets.length; i++) {
- Point point = offsets [i];
- layout.setStyle (linkStyle, point.x, point.y);
- bidiSegments[i*2] = point.x;
- bidiSegments[i*2+1] = point.y+1;
- }
- layout.setSegments (bidiSegments);
- TextStyle mnemonicStyle = new TextStyle (null, null, null);
- mnemonicStyle.underline = true;
- for (int i = 0; i < mnemonics.length; i++) {
- int mnemonic = mnemonics [i];
- if (mnemonic != -1) {
- layout.setStyle (mnemonicStyle, mnemonic, mnemonic);
- }
- }
- redraw ();
-}
-
-void showWidget () {
- super.showWidget ();
- fixStyle (handle);
-}
-
-int traversalCode (int key, GdkEventKey event) {
- if (offsets.length == 0) return 0;
- int bits = super.traversalCode (key, event);
- if (key == OS.GDK_Tab && focusIndex < offsets.length - 1) {
- return bits & ~SWT.TRAVERSE_TAB_NEXT;
- }
- if (key == OS.GDK_ISO_Left_Tab && focusIndex > 0) {
- return bits & ~SWT.TRAVERSE_TAB_PREVIOUS;
- }
- return bits;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java
deleted file mode 100644
index b1df97fd18..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java
+++ /dev/null
@@ -1,1594 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface
- * object that displays a list of strings and issues notification
- * when a string is selected. A list may be single or multi select.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection</dd>
- * </dl>
- * <p>
- * Note: Only one of SINGLE and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#list">List snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class List extends Scrollable {
- int /*long*/ modelHandle;
-
- static final int TEXT_COLUMN = 0;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public List (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the argument to the end of the receiver's list.
- *
- * @param string the new item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String,int)
- */
-public void add (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (iter == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- OS.gtk_list_store_append (modelHandle, iter);
- OS.gtk_list_store_set (modelHandle, iter, TEXT_COLUMN, buffer, -1);
- OS.g_free (iter);
-}
-
-/**
- * Adds the argument to the receiver's list at the given
- * zero-relative index.
- * <p>
- * Note: To add an item at the end of the list, use the
- * result of calling <code>getItemCount()</code> as the
- * index or use <code>add(String)</code>.
- * </p>
- *
- * @param string the new item
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String)
- */
-public void add (String string, int index) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = OS.gtk_tree_model_iter_n_children (modelHandle, 0);
- if (!(0 <= index && index <= count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (iter == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- /*
- * Feature in GTK. It is much faster to append to a list store
- * than to insert at the end using gtk_list_store_insert().
- */
- if (index == count) {
- OS.gtk_list_store_append (modelHandle, iter);
- } else {
- OS.gtk_list_store_insert (modelHandle, iter, index);
- }
- OS.gtk_list_store_set (modelHandle, iter, TEXT_COLUMN, buffer, -1);
- OS.g_free (iter);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the selection changes.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (fixedHandle, true);
- scrolledHandle = OS.gtk_scrolled_window_new (0, 0);
- if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
- /*
- * Columns:
- * 0 - text
- */
- int /*long*/ [] types = new int /*long*/ [] {OS.G_TYPE_STRING ()};
- modelHandle = OS.gtk_list_store_newv (types.length, types);
- if (modelHandle == 0) error (SWT.ERROR_NO_HANDLES);
- handle = OS.gtk_tree_view_new_with_model (modelHandle);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ textRenderer = OS.gtk_cell_renderer_text_new ();
- if (textRenderer == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ columnHandle = OS.gtk_tree_view_column_new ();
- if (columnHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_tree_view_column_pack_start (columnHandle, textRenderer, true);
- OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.text, TEXT_COLUMN);
- OS.gtk_tree_view_insert_column (handle, columnHandle, index);
- OS.gtk_container_add (fixedHandle, scrolledHandle);
- OS.gtk_container_add (scrolledHandle, handle);
-
- int mode = (style & SWT.MULTI) != 0 ? OS.GTK_SELECTION_MULTIPLE : OS.GTK_SELECTION_BROWSE;
- int /*long*/ selectionHandle = OS.gtk_tree_view_get_selection (handle);
- OS.gtk_tree_selection_set_mode (selectionHandle, mode);
- OS.gtk_tree_view_set_headers_visible (handle, false);
- int hsp = (style & SWT.H_SCROLL) != 0 ? OS.GTK_POLICY_AUTOMATIC : OS.GTK_POLICY_NEVER;
- int vsp = (style & SWT.V_SCROLL) != 0 ? OS.GTK_POLICY_AUTOMATIC : OS.GTK_POLICY_NEVER;
- OS.gtk_scrolled_window_set_policy (scrolledHandle, hsp, vsp);
- if ((style & SWT.BORDER) != 0) OS.gtk_scrolled_window_set_shadow_type (scrolledHandle, OS.GTK_SHADOW_ETCHED_IN);
- /*
- * Bug in GTK. When a treeview is the child of an override shell,
- * and if the user has ever invokes the interactive search field,
- * and the treeview is disposed on a focus out event, it segment
- * faults. The fix is to disable the search field in an override
- * shell.
- */
- if ((getShell ().style & SWT.ON_TOP) != 0) {
- /*
- * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE)
- * would prevent the user from being able to type in text to search the tree.
- * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive
- * search. This meant that even if FALSE was passed to enable_search, the user
- * can still bring up the search pop up using the keybinding. GTK also introduced
- * the notion of passing a -1 to gtk_set_search_column to disable searching
- * (including the search key binding). The fix is to use the right calls
- * for the right version.
- */
- if (OS.GTK_VERSION >= OS.VERSION (2, 6, 5)) {
- OS.gtk_tree_view_set_search_column (handle, -1);
- } else {
- OS.gtk_tree_view_set_enable_search (handle, false);
- }
- }
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- Point size = computeNativeSize (handle, wHint, hHint, changed);
- Rectangle trim = computeTrim (0, 0, size.x, size.y);
- size.x = trim.width;
- size.y = trim.height;
- return size;
-}
-
-void deregister() {
- super.deregister ();
- display.removeWidget (OS.gtk_tree_view_get_selection (handle));
-}
-
-/**
- * Deselects the item at the given zero-relative index in the receiver.
- * If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget();
- if (!(0 <= index && index < OS.gtk_tree_model_iter_n_children (modelHandle, 0))) return;
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- OS.gtk_tree_selection_unselect_iter (selection, iter);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_free (iter);
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. The range of the
- * indices is inclusive. Indices that are out of range are ignored.
- *
- * @param start the start index of the items to deselect
- * @param end the end index of the items to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int start, int end) {
- checkWidget();
- if (start < 0 && end < 0) return;
- int count = OS.gtk_tree_model_iter_n_children (modelHandle, 0);
- if (start >= count && end >= count) return;
- start = Math.min (count - 1, Math.max (0, start));
- end = Math.min (count - 1, Math.max (0, end));
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- for (int index=start; index<=end; index++) {
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- OS.gtk_tree_selection_unselect_iter (selection, iter);
- }
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_free (iter);
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. Indices that are out
- * of range and duplicate indices are ignored.
- *
- * @param indices the array of indices for the items to deselect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int [] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- int count = OS.gtk_tree_model_iter_n_children (modelHandle, 0);
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- for (int i=0; i<indices.length; i++) {
- int index = indices [i];
- if (index < 0 || index > count - 1) continue;
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- OS.gtk_tree_selection_unselect_iter (selection, iter);
- }
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_free (iter);
-}
-
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll () {
- checkWidget();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_selection_unselect_all (selection);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
-}
-
-boolean dragDetect (int x, int y, boolean filter, boolean [] consume) {
- boolean selected = false;
- if (filter) {
- int /*long*/ [] path = new int /*long*/ [1];
- if (OS.gtk_tree_view_get_path_at_pos (handle, x, y, path, null, null, null)) {
- if (path [0] != 0) {
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- if (OS.gtk_tree_selection_path_is_selected (selection, path [0])) selected = true;
- OS.gtk_tree_path_free (path [0]);
- }
- } else {
- return false;
- }
- }
- boolean dragDetect = super.dragDetect (x, y, filter, consume);
- if (dragDetect && selected && consume != null) consume [0] = true;
- return dragDetect;
-}
-
-int /*long*/ eventWindow () {
- return paintWindow ();
-}
-
-GdkColor getBackgroundColor () {
- return getBaseColor ();
-}
-
-/**
- * Returns the zero-relative index of the item which currently
- * has the focus in the receiver, or -1 if no item has focus.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getFocusIndex () {
- checkWidget();
- int /*long*/ [] path = new int /*long*/ [1];
- OS.gtk_tree_view_get_cursor (handle, path, null);
- if (path [0] == 0) return -1;
- int /*long*/ indices = OS.gtk_tree_path_get_indices (path [0]);
- int [] index = new int []{-1};
- if (indices != 0) OS.memmove (index, indices, 4);
- OS.gtk_tree_path_free (path [0]);
- return index [0];
-}
-
-GdkColor getForegroundColor () {
- return getTextColor ();
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getItem (int index) {
- checkWidget();
- if (!(0 <= index && index < OS.gtk_tree_model_iter_n_children (modelHandle, 0))) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int /*long*/ [] ptr = new int /*long*/ [1];
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- OS.gtk_tree_model_get (modelHandle, iter, 0, ptr, -1);
- OS.g_free (iter);
- if (ptr [0] == 0) return null;
- int length = OS.strlen (ptr [0]);
- byte[] buffer2 = new byte [length];
- OS.memmove (buffer2, ptr [0], length);
- OS.g_free (ptr [0]);
- return new String (Converter.mbcsToWcs (null, buffer2));
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- return OS.gtk_tree_model_iter_n_children (modelHandle, 0);
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the list.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget();
- int itemCount = OS.gtk_tree_model_iter_n_children (modelHandle, 0);
- int /*long*/ column = OS.gtk_tree_view_get_column (handle, 0);
- if (itemCount == 0) {
- int [] w = new int [1], h = new int [1];
- OS.gtk_tree_view_column_cell_get_size (column, null, null, null, w, h);
- return h [0];
- } else {
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- OS.gtk_tree_model_get_iter_first (modelHandle, iter);
- OS.gtk_tree_view_column_cell_set_cell_data (column, modelHandle, iter, false, false);
- int [] w = new int [1], h = new int [1];
- OS.gtk_tree_view_column_cell_get_size (column, null, null, null, w, h);
- OS.g_free (iter);
- return h [0];
- }
-}
-
-/**
- * Returns a (possibly empty) array of <code>String</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver's list
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getItems () {
- checkWidget();
- int count = OS.gtk_tree_model_iter_n_children (modelHandle, 0);
- int /*long*/ [] ptr = new int /*long*/ [1];
- String [] result = new String [count];
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- for (int index=0; index<count; index++) {
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- OS.gtk_tree_model_get (modelHandle, iter, 0, ptr, -1);
- if (ptr [0] != 0) {
- int length = OS.strlen (ptr [0]);
- byte[] buffer = new byte [length];
- OS.memmove (buffer, ptr [0], length);
- OS.g_free (ptr [0]);
- result [index] = new String (Converter.mbcsToWcs (null, buffer));
- }
- }
- OS.g_free (iter);
- return result;
-}
-
-/**
- * Returns an array of <code>String</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getSelection () {
- checkWidget();
- int [] indices = getSelectionIndices ();
- String [] result = new String [indices.length];
- for (int i=0; i<indices.length; i++) {
- result [i] = getItem (indices [i]);
- }
- return result;
-}
-
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) {
- display.treeSelectionLength = 0;
- display.treeSelection = null;
- OS.gtk_tree_selection_selected_foreach (selection, display.treeSelectionProc, handle);
- return display.treeSelectionLength;
- }
- return OS.gtk_tree_selection_count_selected_rows (selection);
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item or -1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) {
- int itemCount = OS.gtk_tree_model_iter_n_children (modelHandle, 0);
- display.treeSelectionLength = 0;
- display.treeSelection = new int [itemCount];
- OS.gtk_tree_selection_selected_foreach (selection, display.treeSelectionProc, handle);
- if (display.treeSelectionLength == 0) return -1;
- return display.treeSelection [0];
- }
- /*
- * Bug in GTK. gtk_tree_selection_get_selected_rows() segmentation faults
- * in versions smaller than 2.2.4 if the model is NULL. The fix is
- * to give a valid pointer instead.
- */
- int /*long*/ [] model = OS.GTK_VERSION < OS.VERSION (2, 2, 4) ? new int /*long*/ [1] : null;
- int /*long*/ list = OS.gtk_tree_selection_get_selected_rows (selection, model);
- if (list != 0) {
- int count = OS.g_list_length (list);
- int [] index = new int [1];
- for (int i=0; i<count; i++) {
- int /*long*/ data = OS.g_list_nth_data (list, i);
- int /*long*/ indices = OS.gtk_tree_path_get_indices (data);
- if (indices != 0) {
- OS.memmove (index, indices, 4);
- break;
- }
- }
- OS.g_list_free (list);
- return index [0];
- }
- return -1;
-}
-
-/**
- * Returns the zero-relative indices of the items which are currently
- * selected in the receiver. The order of the indices is unspecified.
- * The array is empty if no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return the array of indices of the selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int [] getSelectionIndices () {
- checkWidget();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) {
- int itemCount = OS.gtk_tree_model_iter_n_children (modelHandle, 0);
- display.treeSelectionLength = 0;
- display.treeSelection = new int [itemCount];
- OS.gtk_tree_selection_selected_foreach (selection, display.treeSelectionProc, handle);
- if (display.treeSelectionLength == display.treeSelection.length) return display.treeSelection;
- int [] result = new int [display.treeSelectionLength];
- System.arraycopy (display.treeSelection, 0, result, 0, display.treeSelectionLength);
- return result;
- }
- /*
- * Bug in GTK. gtk_tree_selection_get_selected_rows() segmentation faults
- * in versions smaller than 2.2.4 if the model is NULL. The fix is
- * to give a valid pointer instead.
- */
- int /*long*/ [] model = OS.GTK_VERSION < OS.VERSION (2, 2, 4) ? new int /*long*/ [1] : null;
- int /*long*/ list = OS.gtk_tree_selection_get_selected_rows (selection, model);
- if (list != 0) {
- int count = OS.g_list_length (list);
- int [] treeSelection = new int [count];
- int length = 0;
- for (int i=0; i<count; i++) {
- int /*long*/ data = OS.g_list_nth_data (list, i);
- int /*long*/ indices = OS.gtk_tree_path_get_indices (data);
- if (indices != 0) {
- int [] index = new int [1];
- OS.memmove (index, indices, 4);
- treeSelection [length] = index [0];
- length++;
- }
- }
- OS.g_list_free (list);
- int [] result = new int [length];
- System.arraycopy (treeSelection, 0, result, 0, length);
- return result;
- }
- return new int [0];
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items are
- * scrolled or new items are added or removed.
- *
- * @return the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget();
- int /*long*/ [] path = new int /*long*/ [1];
- OS.gtk_widget_realize (handle);
- if (!OS.gtk_tree_view_get_path_at_pos (handle, 1, 1, path, null, null, null)) return 0;
- if (path [0] == 0) return 0;
- int /*long*/ indices = OS.gtk_tree_path_get_indices (path[0]);
- int[] index = new int [1];
- if (indices != 0) OS.memmove (index, indices, 4);
- OS.gtk_tree_path_free (path [0]);
- return index [0];
-}
-
-int /*long*/ gtk_changed (int /*long*/ widget) {
- postEvent (SWT.Selection);
- return 0;
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_button_press_event (widget, event);
- if (result != 0) return result;
- /*
- * Feature in GTK. In a multi-select list view, when multiple items are already
- * selected, the selection state of the item is toggled and the previous selection
- * is cleared. This is not the desired behaviour when bringing up a popup menu.
- * Also, when an item is reselected with the right button, the tree view issues
- * an unwanted selection event. The workaround is to detect that case and not
- * run the default handler when the item is already part of the current selection.
- */
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
- int button = gdkEvent.button;
- if (button == 3 && gdkEvent.type == OS.GDK_BUTTON_PRESS) {
- int /*long*/ [] path = new int /*long*/ [1];
- if (OS.gtk_tree_view_get_path_at_pos (handle, (int)gdkEvent.x, (int)gdkEvent.y, path, null, null, null)) {
- if (path [0] != 0) {
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- if (OS.gtk_tree_selection_path_is_selected (selection, path [0])) result = 1;
- OS.gtk_tree_path_free (path [0]);
- }
- }
- }
-
- /*
- * Feature in GTK. When the user clicks in a single selection GtkTreeView
- * and there are no selected items, the first item is selected automatically
- * before the click is processed, causing two selection events. The is fix
- * is the set the cursor item to be same as the clicked item to stop the
- * widget from automatically selecting the first item.
- */
- if ((style & SWT.SINGLE) != 0 && getSelectionCount () == 0) {
- int /*long*/ [] path = new int /*long*/ [1];
- if (OS.gtk_tree_view_get_path_at_pos (handle, (int)gdkEvent.x, (int)gdkEvent.y, path, null, null, null)) {
- if (path [0] != 0) {
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_view_set_cursor (handle, path [0], 0, false);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_path_free (path [0]);
- }
- }
- }
- /*
- * Bug in GTK. GTK segments fault, if the GtkTreeView widget is
- * not in focus and all items in the widget are disposed before
- * it finishes processing a button press. The fix is to give
- * focus to the widget before it starts processing the event.
- */
- if (!OS.GTK_WIDGET_HAS_FOCUS (handle)) {
- OS.gtk_widget_grab_focus (handle);
- }
- return result;
-}
-
-int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_key_press_event (widget, event);
- if (result != 0) return result;
- if (OS.GTK_VERSION < OS.VERSION (2, 2 ,0)) {
- /*
- * Feature in GTK 2.0.x. When an item is default selected using
- * the return key, GTK does not issue notification. The fix is
- * to issue this notification when the return key is pressed.
- */
- GdkEventKey keyEvent = new GdkEventKey ();
- OS.memmove (keyEvent, event, GdkEventKey.sizeof);
- int key = keyEvent.keyval;
- switch (key) {
- case OS.GDK_Return:
- case OS.GDK_KP_Enter: {
- postEvent (SWT.DefaultSelection);
- break;
- }
- }
- }
- return result;
-}
-
-int /*long*/ gtk_popup_menu (int /*long*/ widget) {
- int /*long*/ result = super.gtk_popup_menu (widget);
- /*
- * Bug in GTK. The context menu for the typeahead in GtkTreeViewer
- * opens in the bottom right corner of the screen when Shift+F10
- * is pressed and the typeahead window was not visible. The fix is
- * to prevent the context menu from opening by stopping the default
- * handler.
- *
- * NOTE: The bug only happens in GTK 2.6.5 and lower.
- */
- return OS.GTK_VERSION < OS.VERSION (2, 6, 5) ? 1 : result;
-}
-
-int /*long*/ gtk_row_activated (int /*long*/ tree, int /*long*/ path, int /*long*/ column) {
- postEvent (SWT.DefaultSelection);
- return 0;
-}
-
-void hookEvents () {
- super.hookEvents();
- int /*long*/ selection = OS.gtk_tree_view_get_selection(handle);
- OS.g_signal_connect_closure (selection, OS.changed, display.closures [CHANGED], false);
- OS.g_signal_connect_closure (handle, OS.row_activated, display.closures [ROW_ACTIVATED], false);
-}
-
-/**
- * Gets the index of an item.
- * <p>
- * The list is searched starting at 0 until an
- * item is found that is equal to the search item.
- * If no item is found, -1 is returned. Indexing
- * is zero based.
- *
- * @param string the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string) {
- checkWidget();
- return indexOf (string, 0);
-}
-
-/**
- * Searches the receiver's list starting at the given,
- * zero-relative index until an item is found that is equal
- * to the argument, and returns the index of that item. If
- * no item is found or the starting index is out of range,
- * returns -1.
- *
- * @param string the search item
- * @param start the zero-relative index at which to start the search
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string, int start) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- String [] items = getItems ();
- for (int i=start; i<items.length; i++) {
- if (items [i].equals (string)) return i;
- }
- return -1;
-}
-
-/**
- * Returns <code>true</code> if the item is selected,
- * and <code>false</code> otherwise. Indices out of
- * range are ignored.
- *
- * @param index the index of the item
- * @return the selection state of the item at the index
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isSelected (int index) {
- checkWidget();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- byte [] buffer = Converter.wcsToMbcs (null, Integer.toString (index), true);
- int /*long*/ path = OS.gtk_tree_path_new_from_string (buffer);
- boolean answer = OS.gtk_tree_selection_path_is_selected (selection, path);
- OS.gtk_tree_path_free (path);
- return answer;
-}
-
-int /*long*/ paintWindow () {
- OS.gtk_widget_realize (handle);
- return OS.gtk_tree_view_get_bin_window (handle);
-}
-
-void register () {
- super.register ();
- display.addWidget (OS.gtk_tree_view_get_selection (handle), this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (modelHandle != 0) OS.g_object_unref (modelHandle);
- modelHandle = 0;
-}
-
-/**
- * Removes the item from the receiver at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget();
- if (!(0 <= index && index < OS.gtk_tree_model_iter_n_children (modelHandle, 0))) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_list_store_remove (modelHandle, iter);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_free (iter);
-}
-
-/**
- * Removes the items from the receiver which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget();
- if (start > end) return;
- int count = OS.gtk_tree_model_iter_n_children (modelHandle, 0);
- if (!(0 <= start && start <= end && end < count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- for (int index=end; index>=start; index--) {
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- OS.gtk_list_store_remove (modelHandle, iter);
- }
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_free (iter);
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * until an item is found that is equal to the argument,
- * and removes that item from the list.
- *
- * @param string the item to remove
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = indexOf (string, 0);
- if (index == -1) error (SWT.ERROR_INVALID_ARGUMENT);
- remove (index);
-}
-
-/**
- * Removes the items from the receiver at the given
- * zero-relative indices.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int [] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- int [] newIndices = new int [indices.length];
- System.arraycopy (indices, 0, newIndices, 0, indices.length);
- sort (newIndices);
- int start = newIndices [newIndices.length - 1], end = newIndices [0];
- int count = getItemCount();
- if (!(0 <= start && start <= end && end < count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- int last = -1;
- for (int i=0; i<newIndices.length; i++) {
- int index = newIndices [i];
- if (index != last) {
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- OS.gtk_list_store_remove (modelHandle, iter);
- last = index;
- }
- }
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_free (iter);
-}
-
-/**
- * Removes all of the items from the receiver.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_list_store_clear (modelHandle);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget();
- if (!(0 <= index && index < OS.gtk_tree_model_iter_n_children (modelHandle, 0))) return;
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- OS.gtk_tree_selection_select_iter (selection, iter);
- if ((style & SWT.SINGLE) != 0) {
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter);
- OS.gtk_tree_view_set_cursor (handle, path, 0, false);
- OS.gtk_tree_path_free (path);
- }
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_free (iter);
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If an item in the given range is not selected, it is selected.
- * If an item in the given range was already selected, it remains selected.
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#setSelection(int,int)
- */
-public void select (int start, int end) {
- checkWidget ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- int count = OS.gtk_tree_model_iter_n_children (modelHandle, 0);
- if (count == 0 || start >= count) return;
- start = Math.max (0, start);
- end = Math.min (end, count - 1);
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- for (int index=start; index<=end; index++) {
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- OS.gtk_tree_selection_select_iter (selection, iter);
- if ((style & SWT.SINGLE) != 0) {
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter);
- OS.gtk_tree_view_set_cursor (handle, path, 0, false);
- OS.gtk_tree_path_free (path);
- }
- }
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_free (iter);
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If the item at a given index is not selected, it is selected.
- * If the item at a given index was already selected, it remains selected.
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- *
- * @param indices the array of indices for the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#setSelection(int[])
- */
-public void select (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- int count = OS.gtk_tree_model_iter_n_children (modelHandle, 0);
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- for (int i=0; i<length; i++) {
- int index = indices [i];
- if (!(0 <= index && index < count)) continue;
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- OS.gtk_tree_selection_select_iter (selection, iter);
- if ((style & SWT.SINGLE) != 0) {
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter);
- OS.gtk_tree_view_set_cursor (handle, path, 0, false);
- OS.gtk_tree_path_free (path);
- }
- }
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_free (iter);
-}
-
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return;
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_selection_select_all (selection);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
-}
-
-void selectFocusIndex (int index) {
- /*
- * Note that this method both selects and sets the focus to the
- * specified index, so any previous selection in the list will be lost.
- * gtk does not provide a way to just set focus to a specified list item.
- */
- int count = OS.gtk_tree_model_iter_n_children (modelHandle, 0);
- if (!(0 <= index && index < count)) return;
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter);
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_view_set_cursor (handle, path, 0, false);
- /*
- * Bug in GTK. For some reason, when an event loop is run from
- * within a key pressed handler and a dialog is displayed that
- * contains a GtkTreeView, gtk_tree_view_set_cursor() does
- * not set the cursor or select the item. The fix is to select the
- * item with gtk_tree_selection_select_iter() as well.
- *
- * NOTE: This happens in GTK 2.2.1 and is fixed in GTK 2.2.4.
- */
- OS.gtk_tree_selection_select_iter (selection, iter);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_path_free (path);
- OS.g_free (iter);
-}
-
-void setBackgroundColor (GdkColor color) {
- super.setBackgroundColor (color);
- OS.gtk_widget_modify_base (handle, 0, color);
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- int result = super.setBounds (x, y, width, height, move, resize);
- /*
- * Bug on GTK. The tree view sometimes does not get a paint
- * event or resizes to a one pixel square when resized in a new
- * shell that is not visible after any event loop has been run. The
- * problem is intermittent. It doesn't seem to happen the first time
- * a new shell is created. The fix is to ensure the tree view is realized
- * after it has been resized.
- */
- OS.gtk_widget_realize (handle);
- /*
- * Bug in GTK. An empty GtkTreeView fails to repaint the focus rectangle
- * correctly when resized on versions before 2.6.0. The fix is to force
- * the widget to redraw.
- */
- if (OS.GTK_VERSION < OS.VERSION (2, 6, 0) && OS.gtk_tree_model_iter_n_children (modelHandle, 0) == 0) {
- redraw (false);
- }
- return result;
-}
-
-/**
- * Sets the text of the item in the receiver's list at the given
- * zero-relative index to the string argument.
- *
- * @param index the index for the item
- * @param string the new text for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItem (int index, String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (!(0 <= index && index < OS.gtk_tree_model_iter_n_children (modelHandle, 0))) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- OS.gtk_list_store_set (modelHandle, iter, TEXT_COLUMN, buffer, -1);
- OS.g_free (iter);
-}
-
-/**
- * Sets the receiver's items to be the given array of items.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItems (String [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<items.length; i++) {
- if (items [i] == null) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_list_store_clear (modelHandle);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (iter == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- for (int i=0; i<items.length; i++) {
- String string = items [i];
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- OS.gtk_list_store_append (modelHandle, iter);
- OS.gtk_list_store_set (modelHandle, iter, TEXT_COLUMN, buffer, -1);
- }
- OS.g_free (iter);
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains selected.
- * The current selection is first cleared, then the new item is selected.
- * Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @see List#deselectAll()
- * @see List#select(int)
- */
-public void setSelection (int index) {
- checkWidget ();
- deselectAll ();
- selectFocusIndex (index);
- showSelection ();
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- *
- * @param start the start index of the items to select
- * @param end the end index of the items to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int,int)
- */
-public void setSelection (int start, int end) {
- checkWidget ();
- deselectAll ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- int count = OS.gtk_tree_model_iter_n_children (modelHandle, 0);
- if (count == 0 || start >= count) return;
- start = Math.max (0, start);
- end = Math.min (end, count - 1);
- selectFocusIndex (start);
- if ((style & SWT.MULTI) != 0) {
- select (start, end);
- }
- showSelection ();
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- *
- * @param indices the indices of the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int[])
- */
-public void setSelection(int[] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- selectFocusIndex (indices [0]);
- if ((style & SWT.MULTI) != 0) {
- select (indices);
- }
- showSelection ();
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int[])
- * @see List#setSelection(int[])
- */
-public void setSelection (String [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = items.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- boolean first = true;
- for (int i = 0; i < length; i++) {
- int index = 0;
- String string = items [i];
- if (string != null) {
- while ((index = indexOf (string, index)) != -1) {
- if ((style & SWT.MULTI) != 0) {
- if (first) {
- first = false;
- selectFocusIndex (index);
- } else {
- select (index);
- }
- } else {
- selectFocusIndex (index);
- break;
- }
- index++;
- }
- }
- }
- showSelection ();
-}
-
-/**
- * Sets the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items
- * are scrolled or new items are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget();
- if (!(0 <= index && index < OS.gtk_tree_model_iter_n_children (modelHandle, 0))) return;
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter);
- OS.gtk_tree_view_scroll_to_cell (handle, path, 0, true, 0, 0);
- if (OS.GTK_VERSION < OS.VERSION (2, 8, 0)) {
- /*
- * Bug in GTK. According to the documentation, gtk_tree_view_scroll_to_cell
- * should vertically scroll the cell to the top if use_align is true and row_align is 0.
- * However, prior to version 2.8 it does not scroll at all. The fix is to determine
- * the new location and use gtk_tree_view_scroll_to_point.
- * If the widget is a pinhead, calling gtk_tree_view_scroll_to_point
- * will have no effect. Therefore, it is still neccessary to call
- * gtk_tree_view_scroll_to_cell.
- */
- OS.gtk_widget_realize (handle);
- GdkRectangle cellRect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (handle, path, 0, cellRect);
- int[] tx = new int[1], ty = new int[1];
- OS.gtk_tree_view_widget_to_tree_coords(handle, cellRect.x, cellRect.y, tx, ty);
- OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0]);
- }
- OS.gtk_tree_path_free (path);
- OS.g_free (iter);
-}
-
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void showSelection () {
- checkWidget();
- int index = getSelectionIndex ();
- if (index == -1) return;
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter);
- /*
- * This code intentionally commented.
- * Bug in GTK. According to the documentation, gtk_tree_view_scroll_to_cell
- * should scroll the minimum amount to show the cell if use_align is false.
- * However, what actually happens is the cell is scrolled to the top.
- * The fix is to determine the new location and use gtk_tree_view_scroll_to_point.
- * If the widget is a pinhead, calling gtk_tree_view_scroll_to_point
- * will have no effect. Therefore, it is still neccessary to
- * call gtk_tree_view_scroll_to_cell.
- */
-// OS.gtk_tree_view_scroll_to_cell (handle, path, 0, false, 0, 0);
- OS.gtk_widget_realize (handle);
- GdkRectangle visibleRect = new GdkRectangle ();
- OS.gtk_tree_view_get_visible_rect (handle, visibleRect);
- GdkRectangle cellRect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (handle, path, 0, cellRect);
- int[] tx = new int[1], ty = new int[1];
- OS.gtk_tree_view_widget_to_tree_coords(handle, cellRect.x, cellRect.y, tx, ty);
- if (ty[0] < visibleRect.y ) {
- OS.gtk_tree_view_scroll_to_cell (handle, path, 0, true, 0f, 0f);
- OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0]);
- } else {
- int height = Math.min (visibleRect.height, cellRect.height);
- if (ty[0] + height > visibleRect.y + visibleRect.height) {
- OS.gtk_tree_view_scroll_to_cell (handle, path, 0, true, 1f, 0f);
- ty[0] += cellRect.height - visibleRect.height;
- OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0]);
- }
- }
- OS.gtk_tree_path_free (path);
- OS.g_free (iter);
-}
-
-int /*long*/ treeSelectionProc (int /*long*/ model, int /*long*/ path, int /*long*/ iter, int[] selection, int length) {
- if (selection != null) {
- int /*long*/ indices = OS.gtk_tree_path_get_indices (path);
- if (indices != 0) {
- int [] index = new int [1];
- OS.memmove (index, indices, 4);
- selection [length] = index [0];
- }
- }
- return 0;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java
deleted file mode 100644
index 5e042a67b5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java
+++ /dev/null
@@ -1,981 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are user interface objects that contain
- * menu items.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BAR, DROP_DOWN, POP_UP, NO_RADIO_GROUP</dd>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Help, Hide, Show </dd>
- * </dl>
- * <p>
- * Note: Only one of BAR, DROP_DOWN and POP_UP may be specified.
- * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#menu">Menu snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Menu extends Widget {
- int x, y;
- boolean hasLocation;
- MenuItem cascade, selectedItem;
- Decorations parent;
- int /*long*/ imItem, imSeparator, imHandle;
- ImageList imageList;
-
-/**
- * Constructs a new instance of this class given its parent,
- * and sets the style for the instance so that the instance
- * will be a popup menu on the given parent's shell.
- * <p>
- * After constructing a menu, it can be set into its parent
- * using <code>parent.setMenu(menu)</code>. In this case, the parent may
- * be any control in the same widget tree as the parent.
- * </p>
- *
- * @param parent a control which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#POP_UP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Control parent) {
- this (checkNull (parent).menuShell (), SWT.POP_UP);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Decorations</code>) and a style value
- * describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * After constructing a menu or menuBar, it can be set into its parent
- * using <code>parent.setMenu(menu)</code> or <code>parent.setMenuBar(menuBar)</code>.
- * </p>
- *
- * @param parent a decorations control which will be the parent of the new instance (cannot be null)
- * @param style the style of menu to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BAR
- * @see SWT#DROP_DOWN
- * @see SWT#POP_UP
- * @see SWT#NO_RADIO_GROUP
- * @see SWT#LEFT_TO_RIGHT
- * @see SWT#RIGHT_TO_LEFT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Decorations parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (0);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>) and sets the style
- * for the instance so that the instance will be a drop-down
- * menu on the given parent's parent.
- * <p>
- * After constructing a drop-down menu, it can be set into its parentMenu
- * using <code>parentMenu.setMenu(menu)</code>.
- * </p>
- *
- * @param parentMenu a menu which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Menu parentMenu) {
- this (checkNull (parentMenu).parent, SWT.DROP_DOWN);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>MenuItem</code>) and sets the style
- * for the instance so that the instance will be a drop-down
- * menu on the given parent's parent menu.
- * <p>
- * After constructing a drop-down menu, it can be set into its parentItem
- * using <code>parentItem.setMenu(menu)</code>.
- * </p>
- *
- * @param parentItem a menu item which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (MenuItem parentItem) {
- this (checkNull (parentItem).parent);
-}
-
-static Control checkNull (Control control) {
- if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return control;
-}
-
-static Menu checkNull (Menu menu) {
- if (menu == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return menu;
-}
-
-static MenuItem checkNull (MenuItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0);
-}
-
-void _setVisible (boolean visible) {
- if (visible == OS.GTK_WIDGET_MAPPED (handle)) return;
- if (visible) {
- sendEvent (SWT.Show);
- if (getItemCount () != 0) {
- if ((OS.GTK_VERSION >= OS.VERSION (2, 8, 0))) {
- /*
- * Feature in GTK. ON_TOP shells will send out
- * SWT.Deactivate whenever a context menu is shown.
- * The fix is to prevent the menu from taking focus
- * when it is being shown in an ON_TOP shell.
- */
- if ((parent._getShell ().style & SWT.ON_TOP) != 0) {
- OS.gtk_menu_shell_set_take_focus (handle, false);
- }
- }
- int /*long*/ address = hasLocation ? display.menuPositionProc: 0;
- /*
- * Bug in GTK. The timestamp passed into gtk_menu_popup is used
- * to perform an X pointer grab. It cannot be zero, else the grab
- * will fail. The fix is to ensure that the timestamp of the last
- * event processed is used.
- */
- OS.gtk_menu_popup (handle, 0, 0, address, 0, 0, display.getLastEventTime ());
- } else {
- sendEvent (SWT.Hide);
- }
- } else {
- OS.gtk_menu_popdown (handle);
- }
-}
-
-void addAccelerators (int /*long*/ accelGroup) {
- MenuItem [] items = getItems ();
- for (int i = 0; i < items.length; i++) {
- MenuItem item = items[i];
- item.addAccelerators (accelGroup);
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when menus are hidden or shown, by sending it
- * one of the messages defined in the <code>MenuListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuListener
- * @see #removeMenuListener
- */
-public void addMenuListener (MenuListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Hide,typedListener);
- addListener (SWT.Show,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when help events are generated for the control,
- * by sending it one of the messages defined in the
- * <code>HelpListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- if ((style & SWT.BAR) != 0) {
- handle = OS.gtk_menu_bar_new ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ vboxHandle = parent.vboxHandle;
- OS.gtk_container_add (vboxHandle, handle);
- OS.gtk_box_set_child_packing (vboxHandle, handle, false, true, 0, OS.GTK_PACK_START);
- } else {
- handle = OS.gtk_menu_new ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- }
-}
-
-void createIMMenu (int /*long*/ imHandle) {
- if (this.imHandle == imHandle) return;
- this.imHandle = imHandle;
- if (imHandle == 0) {
- if (imItem != 0) {
- OS.gtk_widget_destroy (imItem);
- imItem = 0;
- }
- if (imSeparator != 0) {
- OS.gtk_widget_destroy (imSeparator);
- imSeparator = 0;
- }
- return;
- }
- if (imSeparator == 0) {
- imSeparator = OS.gtk_separator_menu_item_new ();
- OS.gtk_widget_show (imSeparator);
- OS.gtk_menu_shell_insert (handle, imSeparator, -1);
- }
- if (imItem == 0) {
- byte[] buffer = Converter.wcsToMbcs (null, SWT.getMessage("SWT_InputMethods"), true);
- imItem = OS.gtk_image_menu_item_new_with_label (buffer);
- OS.gtk_widget_show (imItem);
- OS.gtk_menu_shell_insert (handle, imItem, -1);
- }
- int /*long*/ imSubmenu = OS.gtk_menu_new ();
- OS.gtk_im_multicontext_append_menuitems (imHandle, imSubmenu);
- OS.gtk_menu_item_set_submenu (imItem, imSubmenu);
-}
-
-void createWidget (int index) {
- checkOrientation (parent);
- super.createWidget (index);
- parent.addMenu (this);
-}
-
-void fixMenus (Decorations newParent) {
- MenuItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- items [i].fixMenus (newParent);
- }
- parent.removeMenu (this);
- newParent.addMenu (this);
- this.parent = newParent;
-}
-
-/*public*/ Rectangle getBounds () {
- checkWidget();
- if (!OS.GTK_WIDGET_MAPPED (handle)) {
- return new Rectangle (0, 0, 0, 0);
- }
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (handle);
- int [] origin_x = new int [1], origin_y = new int [1];
- OS.gdk_window_get_origin (window, origin_x, origin_y);
- int x = origin_x [0] + OS.GTK_WIDGET_X (handle);
- int y = origin_y [0] + OS.GTK_WIDGET_Y (handle);
- int width = OS.GTK_WIDGET_WIDTH (handle);
- int height = OS.GTK_WIDGET_HEIGHT (handle);
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the default menu item or null if none has
- * been previously set.
- *
- * @return the default menu item.
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getDefaultItem () {
- checkWidget();
- return null;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled menu is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- return OS.GTK_WIDGET_SENSITIVE (handle);
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getItem (int index) {
- checkWidget();
- int /*long*/ list = OS.gtk_container_get_children (handle);
- if (list == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- int count = OS.g_list_length (list);
- if (imSeparator != 0) count--;
- if (imItem != 0) count--;
- if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
- int /*long*/ data = OS.g_list_nth_data (list, index);
- OS.g_list_free (list);
- if (data == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- return (MenuItem) display.getWidget (data);
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- int /*long*/ list = OS.gtk_container_get_children (handle);
- if (list == 0) return 0;
- int count = OS.g_list_length (list);
- OS.g_list_free (list);
- if (imSeparator != 0) count--;
- if (imItem != 0) count--;
- return count;
-}
-
-/**
- * Returns a (possibly empty) array of <code>MenuItem</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem [] getItems () {
- checkWidget();
- int /*long*/ list = OS.gtk_container_get_children (handle);
- if (list == 0) return new MenuItem [0];
- int count = OS.g_list_length (list);
- if (imSeparator != 0) count--;
- if (imItem != 0) count--;
- MenuItem [] items = new MenuItem [count];
- int index = 0;
- for (int i=0; i<count; i++) {
- int /*long*/ data = OS.g_list_nth_data (list, i);
- MenuItem item = (MenuItem) display.getWidget (data);
- if (item != null) items [index++] = item;
- }
- OS.g_list_free (list);
- if (index != items.length) {
- MenuItem [] newItems = new MenuItem[index];
- System.arraycopy(items, 0, newItems, 0, index);
- items = newItems;
- }
- return items;
-}
-
-String getNameText () {
- String result = "";
- MenuItem [] items = getItems ();
- int length = items.length;
- if (length > 0) {
- for (int i=0; i<length-1; i++) {
- result = result + items [i].getNameText() + ", ";
- }
- result = result + items [length-1].getNameText ();
- }
- return result;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Decorations</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Decorations getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>MenuItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getParentItem () {
- checkWidget();
- return cascade;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>Menu</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getParentMenu () {
- checkWidget();
- if (cascade == null) return null;
- return cascade.getParent ();
-}
-
-/**
- * Returns the receiver's shell. For all controls other than
- * shells, this simply returns the control's nearest ancestor
- * shell. Shells return themselves, even if they are children
- * of other shells.
- *
- * @return the receiver's shell
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getParent
- */
-public Shell getShell () {
- checkWidget();
- return parent.getShell ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- if ((style & SWT.POP_UP) != 0) {
- Menu [] popups = display.popups;
- if (popups != null) {
- for (int i=0; i<popups.length; i++) {
- if (popups [i] == this) return true;
- }
- }
- }
- return OS.GTK_WIDGET_MAPPED (handle);
-}
-
-int /*long*/ gtk_hide (int /*long*/ widget) {
- if ((style & SWT.POP_UP) != 0) {
- if (display.activeShell != null) display.activeShell = getShell ();
- }
- if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) {
- sendEvent (SWT.Hide);
- } else {
- /*
- * Bug in GTK. In GTK 2.4 and earlier
- * a crash could occur if a menu item
- * was disposed within gtk_hide. The
- * workaroud is to post the event instead
- * of send it on these platforms
- */
- postEvent (SWT.Hide);
- }
- return 0;
-}
-
-int /*long*/ gtk_show (int /*long*/ widget) {
- if ((style & SWT.POP_UP) != 0) {
- if (display.activeShell != null) display.activeShell = getShell ();
- return 0;
- }
- sendEvent (SWT.Show);
- return 0;
-}
-
-
-int /*long*/ gtk_show_help (int /*long*/ widget, int /*long*/ helpType) {
- if (sendHelpEvent (helpType)) {
- OS.gtk_menu_shell_deactivate (handle);
- return 1;
- }
- return 0;
-}
-
-void hookEvents () {
- super.hookEvents ();
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [SHOW], 0, display.closures [SHOW], false);
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [HIDE], 0, display.closures [HIDE], false);
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [SHOW_HELP], 0, display.closures [SHOW_HELP], false);
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (MenuItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- MenuItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled menu is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- Menu parentMenu = getParentMenu ();
- if (parentMenu == null) {
- return getEnabled () && parent.isEnabled ();
- }
- return getEnabled () && parentMenu.isEnabled ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return getVisible ();
-}
-
-int /*long*/ menuPositionProc (int /*long*/ menu, int /*long*/ x, int /*long*/ y, int /*long*/ push_in, int /*long*/ user_data) {
- /*
- * Feature in GTK. The menu position function sets the position of the
- * top-left pixel of the menu. If the menu would be off-screen, GTK will
- * add a scroll arrow at the bottom and position the first menu entry at
- * the specified position. The fix is to flip the menu location to be
- * completely inside the screen.
- *
- * NOTE: This code doesn't work for multiple monitors.
- */
- GtkRequisition requisition = new GtkRequisition ();
- OS.gtk_widget_size_request (menu, requisition);
- int screenHeight = OS.gdk_screen_height ();
- int reqy = this.y;
- if (reqy + requisition.height > screenHeight) {
- reqy = Math.max (0, reqy - requisition.height);
- }
- int screenWidth = OS.gdk_screen_width ();
- int reqx = this.x;
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- if (reqx - requisition.width >= 0) reqx -= requisition.width;
- } else {
- if (reqx + requisition.width > screenWidth) reqx -= requisition.width;
- }
- if (x != 0) OS.memmove (x, new int [] {reqx}, 4);
- if (y != 0) OS.memmove (y, new int [] {reqy}, 4);
- if (push_in != 0) OS.memmove (push_in, new int [] {1}, 4);
- return 0;
-}
-
-void releaseChildren (boolean destroy) {
- MenuItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- super.releaseChildren (destroy);
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (cascade != null) cascade.setMenu (null);
- if ((style & SWT.BAR) != 0 && this == parent.menuBar) {
- parent.setMenuBar (null);
- } else {
- if ((style & SWT.POP_UP) != 0) {
- display.removePopup (this);
- }
- }
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (parent != null) parent.removeMenu (this);
- parent = null;
- cascade = null;
- imItem = imSeparator = imHandle = 0;
- if (imageList != null) imageList.dispose ();
- imageList = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the menu events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuListener
- * @see #addMenuListener
- */
-public void removeMenuListener (MenuListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Hide, listener);
- eventTable.unhook (SWT.Show, listener);
-}
-
-void removeAccelerators (int /*long*/ accelGroup) {
- MenuItem [] items = getItems ();
- for (int i = 0; i < items.length; i++) {
- MenuItem item = items[i];
- item.removeAccelerators (accelGroup);
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-
-boolean sendHelpEvent (int /*long*/ helpType) {
- if (selectedItem != null && !selectedItem.isDisposed()) {
- if (selectedItem.hooks (SWT.Help)) {
- selectedItem.postEvent (SWT.Help);
- return true;
- }
- }
- if (hooks (SWT.Help)) {
- postEvent (SWT.Help);
- return true;
- }
- return parent.sendHelpEvent (helpType);
-}
-
-/**
- * Sets the default menu item to the argument or removes
- * the default emphasis when the argument is <code>null</code>.
- *
- * @param item the default menu item or null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the menu item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDefaultItem (MenuItem item) {
- checkWidget();
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled menu is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- if (enabled) {
- OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_SENSITIVE);
- } else {
- OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_SENSITIVE);
- }
-}
-
-/**
- * Sets the location of the receiver, which must be a popup,
- * to the point specified by the arguments which are relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p><p>
- * Note that the platform window manager ultimately has control
- * over the location of popup menus.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget();
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- this.x = x;
- this.y = y;
- hasLocation = true;
-}
-
-/**
- * Sets the location of the receiver, which must be a popup,
- * to the point specified by the argument which is relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p><p>
- * Note that the platform window manager ultimately has control
- * over the location of popup menus.
- * </p>
- *
- * @param location the new location for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void setLocation (Point location) {
- checkWidget();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-void setOrientation() {
- if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) {
- if (handle != 0) OS.gtk_widget_set_direction (handle, OS.GTK_TEXT_DIR_RTL);
- }
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget();
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- if (visible) {
- display.addPopup (this);
- } else {
- display.removePopup (this);
- _setVisible (false);
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java
deleted file mode 100644
index d676e46e4a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java
+++ /dev/null
@@ -1,883 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that issues notification when pressed and released.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>CHECK, CASCADE, PUSH, RADIO, SEPARATOR</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Arm, Help, Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR
- * may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class MenuItem extends Item {
- Menu parent, menu;
- int /*long*/ groupHandle;
- int accelerator;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a menu control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#CHECK
- * @see SWT#CASCADE
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public MenuItem (Menu parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a menu control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#CHECK
- * @see SWT#CASCADE
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public MenuItem (Menu parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- int count = parent.getItemCount ();
- if (!(0 <= index && index <= count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- createWidget (index);
-}
-
-void addAccelerator (int /*long*/ accelGroup) {
- updateAccelerator (accelGroup, true);
-}
-
-void addAccelerators (int /*long*/ accelGroup) {
- addAccelerator (accelGroup);
- if (menu != null) menu.addAccelerators (accelGroup);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the arm events are generated for the control, by sending
- * it one of the messages defined in the <code>ArmListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ArmListener
- * @see #removeArmListener
- */
-public void addArmListener (ArmListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Arm, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the help events are generated for the control, by sending
- * it one of the messages defined in the <code>HelpListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the menu item is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the stateMask field of the event object is valid.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the menu item is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.CASCADE, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- byte [] buffer = new byte [1];
- int bits = SWT.CHECK | SWT.RADIO | SWT.PUSH | SWT.SEPARATOR;
- switch (style & bits) {
- case SWT.SEPARATOR:
- handle = OS.gtk_separator_menu_item_new ();
- break;
- case SWT.RADIO:
- /*
- * Feature in GTK. In GTK, radio button must always be part of
- * a radio button group. In a GTK radio group, one button is always
- * selected. This means that it is not possible to have a single
- * radio button that is unselected. This is necessary to allow
- * applications to implement their own radio behavior or use radio
- * buttons outside of radio groups. The fix is to create a hidden
- * radio button for each radio button we create and add them
- * to the same group. This allows the visible button to be
- * unselected.
- */
- groupHandle = OS.gtk_radio_menu_item_new (0);
- if (groupHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.g_object_ref (groupHandle);
- OS.gtk_object_sink (groupHandle);
- int /*long*/ group = OS.gtk_radio_menu_item_get_group (groupHandle);
- handle = OS.gtk_radio_menu_item_new_with_label (group, buffer);
- break;
- case SWT.CHECK:
- handle = OS.gtk_check_menu_item_new_with_label (buffer);
- break;
- case SWT.PUSH:
- default:
- handle = OS.gtk_image_menu_item_new_with_label (buffer);
- break;
- }
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.SEPARATOR) == 0) {
- int /*long*/ label = OS.gtk_bin_get_child (handle);
- OS.gtk_accel_label_set_accel_widget (label, 0);
- }
- int /*long*/ parentHandle = parent.handle;
- boolean enabled = OS.GTK_WIDGET_SENSITIVE (parentHandle);
- if (!enabled) OS.GTK_WIDGET_SET_FLAGS (parentHandle, OS.GTK_SENSITIVE);
- OS.gtk_menu_shell_insert (parentHandle, handle, index);
- if (!enabled) OS.GTK_WIDGET_UNSET_FLAGS (parentHandle, OS.GTK_SENSITIVE);
- OS.gtk_widget_show (handle);
-}
-
-void fixMenus (Decorations newParent) {
- if (menu != null) menu.fixMenus (newParent);
-}
-
-/**
- * Returns the widget accelerator. An accelerator is the bit-wise
- * OR of zero or more modifier masks and a key. Examples:
- * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
- * The default value is zero, indicating that the menu item does
- * not have an accelerator.
- *
- * @return the accelerator or 0
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAccelerator () {
- checkWidget();
- return accelerator;
-}
-
-int /*long*/ getAccelGroup () {
- Menu menu = parent;
- while (menu != null && menu.cascade != null) {
- menu = menu.cascade.parent;
- }
- if (menu == null) return 0;
- Decorations shell = menu.parent;
- return shell.menuBar == menu ? shell.accelGroup : 0;
-}
-
-/*public*/ Rectangle getBounds () {
- checkWidget();
- if (!OS.GTK_WIDGET_MAPPED (handle)) {
- return new Rectangle (0, 0, 0, 0);
- }
- int x = OS.GTK_WIDGET_X (handle);
- int y = OS.GTK_WIDGET_Y (handle);
- int width = OS.GTK_WIDGET_WIDTH (handle);
- int height = OS.GTK_WIDGET_HEIGHT (handle);
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled menu item is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- return OS.GTK_WIDGET_SENSITIVE (handle);
-}
-
-/**
- * Returns the receiver's cascade menu if it has one or null
- * if it does not. Only <code>CASCADE</code> menu items can have
- * a pull down menu. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pull down
- * menu is platform specific.
- *
- * @return the receiver's menu
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenu () {
- checkWidget();
- return menu;
-}
-
-String getNameText () {
- if ((style & SWT.SEPARATOR) != 0) return "|";
- return super.getNameText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Menu</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked.
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
- return OS.gtk_check_menu_item_get_active(handle);
-}
-
-int /*long*/ gtk_activate (int /*long*/ widget) {
- if ((style & SWT.CASCADE) != 0 && menu != null) return 0;
- /*
- * Bug in GTK. When an ancestor menu is disabled and
- * the user types an accelerator key, GTK delivers the
- * the activate signal even though the menu item cannot
- * be invoked using the mouse. The fix is to ignore
- * activate signals when an ancestor menu is disabled.
- */
- if (!isEnabled ()) return 0;
- Event event = new Event ();
- int /*long*/ ptr = OS.gtk_get_current_event ();
- if (ptr != 0) {
- GdkEvent gdkEvent = new GdkEvent ();
- OS.memmove (gdkEvent, ptr, GdkEvent.sizeof);
- switch (gdkEvent.type) {
- case OS.GDK_KEY_PRESS:
- case OS.GDK_KEY_RELEASE:
- case OS.GDK_BUTTON_PRESS:
- case OS.GDK_2BUTTON_PRESS:
- case OS.GDK_BUTTON_RELEASE: {
- int [] state = new int [1];
- OS.gdk_event_get_state (ptr, state);
- setInputState (event, state [0]);
- break;
- }
- }
- OS.gdk_event_free (ptr);
- }
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) {
- selectRadio ();
- }
- }
- postEvent (SWT.Selection, event);
- return 0;
-}
-
-int /*long*/ gtk_select (int /*long*/ item) {
- parent.selectedItem = this;
- sendEvent (SWT.Arm);
- return 0;
-}
-
-int /*long*/ gtk_show_help (int /*long*/ widget, int /*long*/ helpType) {
- boolean handled = hooks (SWT.Help);
- if (handled) {
- postEvent (SWT.Help);
- } else {
- handled = parent.sendHelpEvent (helpType);
- }
- if (handled) {
- OS.gtk_menu_shell_deactivate (parent.handle);
- return 1;
- }
- return 0;
-}
-
-void hookEvents () {
- super.hookEvents ();
- OS.g_signal_connect_closure (handle, OS.activate, display.closures [ACTIVATE], false);
- OS.g_signal_connect_closure (handle, OS.select, display.closures [SELECT], false);
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [SHOW_HELP], 0, display.closures [SHOW_HELP], false);
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled menu item is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- return getEnabled () && parent.isEnabled ();
-}
-
-void releaseChildren (boolean destroy) {
- if (menu != null) {
- menu.release (false);
- menu = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (menu != null) {
- if (menu.selectedItem == this) menu.selectedItem = null;
- menu.dispose ();
- }
- menu = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- int /*long*/ accelGroup = getAccelGroup ();
- if (accelGroup != 0) removeAccelerator (accelGroup);
- if (groupHandle != 0) OS.g_object_unref (groupHandle);
- groupHandle = 0;
- accelerator = 0;
- parent = null;
-}
-
-void removeAccelerator (int /*long*/ accelGroup) {
- updateAccelerator (accelGroup, false);
-}
-
-void removeAccelerators (int /*long*/ accelGroup) {
- removeAccelerator (accelGroup);
- if (menu != null) menu.removeAccelerators (accelGroup);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the arm events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ArmListener
- * @see #addArmListener
- */
-public void removeArmListener (ArmListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Arm, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-void selectRadio () {
- int index = 0;
- MenuItem [] items = parent.getItems ();
- while (index < items.length && items [index] != this) index++;
- int i = index - 1;
- while (i >= 0 && items [i].setRadioSelection (false)) --i;
- int j = index + 1;
- while (j < items.length && items [j].setRadioSelection (false)) j++;
- setSelection (true);
-}
-/**
- * Sets the widget accelerator. An accelerator is the bit-wise
- * OR of zero or more modifier masks and a key. Examples:
- * <code>SWT.MOD1 | SWT.MOD2 | 'T', SWT.MOD3 | SWT.F2</code>.
- * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
- * The default value is zero, indicating that the menu item does
- * not have an accelerator.
- *
- * @param accelerator an integer that is the bit-wise OR of masks and a key
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAccelerator (int accelerator) {
- checkWidget();
- if (this.accelerator == accelerator) return;
- int /*long*/ accelGroup = getAccelGroup ();
- if (accelGroup != 0) removeAccelerator (accelGroup);
- this.accelerator = accelerator;
- if (accelGroup != 0) addAccelerator (accelGroup);
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled menu item is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- if (OS.GTK_WIDGET_SENSITIVE (handle) == enabled) return;
- int /*long*/ accelGroup = getAccelGroup ();
- if (accelGroup != 0) removeAccelerator (accelGroup);
- OS.gtk_widget_set_sensitive (handle, enabled);
- if (accelGroup != 0) addAccelerator (accelGroup);
-}
-
-/**
- * Sets the image the receiver will display to the argument.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept (for example, Windows NT).
- * Furthermore, some platforms (such as GTK), cannot display both
- * a check box and an image at the same time. Instead, they hide
- * the image and display the check box.
- * </p>
- *
- * @param image the image to display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return;
- super.setImage (image);
- if (!OS.GTK_IS_IMAGE_MENU_ITEM (handle)) return;
- if (image != null) {
- ImageList imageList = parent.imageList;
- if (imageList == null) imageList = parent.imageList = new ImageList ();
- int imageIndex = imageList.indexOf (image);
- if (imageIndex == -1) {
- imageIndex = imageList.add (image);
- } else {
- imageList.put (imageIndex, image);
- }
- int /*long*/ pixbuf = imageList.getPixbuf (imageIndex);
- int /*long*/ imageHandle = OS.gtk_image_new_from_pixbuf (pixbuf);
- OS.gtk_image_menu_item_set_image (handle, imageHandle);
- OS.gtk_widget_show (imageHandle);
- } else {
- OS.gtk_image_menu_item_set_image (handle, 0);
- }
-}
-
-/**
- * Sets the receiver's pull down menu to the argument.
- * Only <code>CASCADE</code> menu items can have a
- * pull down menu. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pull down
- * menu is platform specific.
- * <p>
- * Note: Disposing of a menu item that has a pull down menu
- * will dispose of the menu. To avoid this behavior, set the
- * menu to null before the menu item is disposed.
- * </p>
- *
- * @param menu the new pull down menu
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_MENU_NOT_DROP_DOWN - if the menu is not a drop down menu</li>
- * <li>ERROR_MENUITEM_NOT_CASCADE - if the menu item is not a <code>CASCADE</code></li>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenu (Menu menu) {
- checkWidget ();
-
- /* Check to make sure the new menu is valid */
- if ((style & SWT.CASCADE) == 0) {
- error (SWT.ERROR_MENUITEM_NOT_CASCADE);
- }
- if (menu != null) {
- if ((menu.style & SWT.DROP_DOWN) == 0) {
- error (SWT.ERROR_MENU_NOT_DROP_DOWN);
- }
- if (menu.parent != parent.parent) {
- error (SWT.ERROR_INVALID_PARENT);
- }
- }
-
- /* Assign the new menu */
- Menu oldMenu = this.menu;
- if (oldMenu == menu) return;
- int /*long*/ accelGroup = getAccelGroup ();
- if (accelGroup != 0) removeAccelerators (accelGroup);
- if (oldMenu != null) {
- oldMenu.cascade = null;
- /*
- * Add a reference to the menu we are about
- * to replace or GTK will destroy it.
- */
- OS.g_object_ref (oldMenu.handle);
- OS.gtk_menu_item_remove_submenu (handle);
- }
- if ((this.menu = menu) != null) {
- menu.cascade = this;
- OS.gtk_menu_item_set_submenu (handle, menu.handle);
- }
- if (accelGroup != 0) addAccelerators (accelGroup);
-}
-
-void setOrientation() {
- if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) {
- if (handle != 0) {
- OS.gtk_widget_set_direction (handle, OS.GTK_TEXT_DIR_RTL);
- OS.gtk_container_forall (handle, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL);
- }
- }
-}
-
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-
-/**
- * Sets the selection state of the receiver.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked.
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, ACTIVATE);
- OS.gtk_check_menu_item_set_active (handle, selected);
- if ((style & SWT.RADIO) != 0) OS.gtk_check_menu_item_set_active (groupHandle, !selected);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, ACTIVATE);
-}
-
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character and accelerator text.
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- * <p>
- * Accelerator text is indicated by the '\t' character.
- * On platforms that support accelerator text, the text
- * that follows the '\t' character is displayed to the user,
- * typically indicating the key stroke that will cause
- * the item to become selected. On most platforms, the
- * accelerator text appears right aligned in the menu.
- * Setting the accelerator text does not install the
- * accelerator key sequence. The accelerator key sequence
- * is installed using #setAccelerator.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setAccelerator
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- if (text.equals (string)) return;
- super.setText (string);
- String accelString = "";
- int index = string.indexOf ('\t');
- if (index != -1) {
- boolean isRTL = (parent.style & SWT.RIGHT_TO_LEFT) != 0;
- accelString = (isRTL? "" : " ") + string.substring (index+1, string.length()) + (isRTL? " " : "");
- string = string.substring (0, index);
- }
- char [] chars = fixMnemonic (string);
- byte [] buffer = Converter.wcsToMbcs (null, chars, true);
- int /*long*/ label = OS.gtk_bin_get_child (handle);
- OS.gtk_label_set_text_with_mnemonic (label, buffer);
- buffer = Converter.wcsToMbcs (null, accelString, true);
- int /*long*/ ptr = OS.g_malloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- int /*long*/ oldPtr = OS.GTK_ACCEL_LABEL_GET_ACCEL_STRING (label);
- OS.GTK_ACCEL_LABEL_SET_ACCEL_STRING (label, ptr);
- if (oldPtr != 0) OS.g_free (oldPtr);
-}
-
-void updateAccelerator (int /*long*/ accelGroup, boolean add) {
- if (accelerator == 0 || !getEnabled ()) return;
- if ((accelerator & SWT.COMMAND) != 0) return;
- int mask = 0;
- if ((accelerator & SWT.ALT) != 0) mask |= OS.GDK_MOD1_MASK;
- if ((accelerator & SWT.SHIFT) != 0) mask |= OS.GDK_SHIFT_MASK;
- if ((accelerator & SWT.CONTROL) != 0) mask |= OS.GDK_CONTROL_MASK;
- int keysym = accelerator & SWT.KEY_MASK;
- int newKey = Display.untranslateKey (keysym);
- if (newKey != 0) {
- keysym = newKey;
- } else {
- switch (keysym) {
- case '\r': keysym = OS.GDK_Return; break;
- default: keysym = Display.wcsToMbcs ((char) keysym);
- }
- }
- /* When accel_key is zero, it causes GTK warnings */
- if (keysym != 0) {
- if (add) {
- OS.gtk_widget_add_accelerator (handle, OS.activate, accelGroup, keysym, mask, OS.GTK_ACCEL_VISIBLE);
- } else {
- OS.gtk_widget_remove_accelerator (handle, accelGroup, keysym, mask);
- }
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MessageBox.java
deleted file mode 100644
index 3d1cfd10e4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MessageBox.java
+++ /dev/null
@@ -1,238 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-
-/**
- * Instances of this class are used to inform or warn the user.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, ICON_WARNING, ICON_WORKING</dd>
- * <dd>OK, OK | CANCEL</dd>
- * <dd>YES | NO, YES | NO | CANCEL</dd>
- * <dd>RETRY | CANCEL</dd>
- * <dd>ABORT | RETRY | IGNORE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION, ICON_QUESTION,
- * ICON_WARNING and ICON_WORKING may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class MessageBox extends Dialog {
-
- String message = "";
- int /*long*/ handle;
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public MessageBox (Shell parent) {
- this (parent, SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_QUESTION
- * @see SWT#ICON_WARNING
- * @see SWT#ICON_WORKING
- * @see SWT#OK
- * @see SWT#CANCEL
- * @see SWT#YES
- * @see SWT#NO
- * @see SWT#ABORT
- * @see SWT#RETRY
- * @see SWT#IGNORE
- */
-public MessageBox (Shell parent, int style) {
- super (parent, checkStyle (parent, checkStyle (style)));
- checkSubclass ();
-}
-
-/**
- * Returns the dialog's message, or an empty string if it does not have one.
- * The message is a description of the purpose for which the dialog was opened.
- * This message will be visible in the dialog while it is open.
- *
- * @return the message
- */
-public String getMessage () {
- return message;
-}
-
-/**
- * Sets the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @param string the message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- */
-public void setMessage (String string) {
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- message = string;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return the ID of the button that was selected to dismiss the
- * message box (e.g. SWT.OK, SWT.CANCEL, etc.)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public int open () {
- int /*long*/ parentHandle = (parent != null) ? parent.topHandle() : 0;
- int dialogFlags = OS.GTK_DIALOG_DESTROY_WITH_PARENT;
- if ((style & (SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- dialogFlags |= OS.GTK_DIALOG_MODAL;
- }
- int messageType = OS.GTK_MESSAGE_INFO;
- if ((style & (SWT.ICON_WARNING)) != 0) messageType = OS.GTK_MESSAGE_WARNING;
- if ((style & (SWT.ICON_QUESTION)) != 0) messageType = OS.GTK_MESSAGE_QUESTION;
- if ((style & (SWT.ICON_ERROR)) != 0) messageType = OS.GTK_MESSAGE_ERROR;
-
- byte [] buffer = Converter.wcsToMbcs (null, fixPercent (message), true);
- handle = OS.gtk_message_dialog_new(parentHandle, dialogFlags, messageType, 0, buffer);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (parentHandle != 0) {
- int /*long*/ pixbufs = OS.gtk_window_get_icon_list (parentHandle);
- if (pixbufs != 0) {
- OS.gtk_window_set_icon_list (handle, pixbufs);
- OS.g_list_free (pixbufs);
- }
- }
- Display display = parent != null ? parent.getDisplay (): Display.getCurrent ();
- createButtons (display.getDismissalAlignment ());
- buffer = Converter.wcsToMbcs(null, title, true);
- OS.gtk_window_set_title(handle,buffer);
- display.addIdleProc ();
- Dialog oldModal = null;
- if (OS.gtk_window_get_modal (handle)) {
- oldModal = display.getModalDialog ();
- display.setModalDialog (this);
- }
- int signalId = 0;
- int /*long*/ hookId = 0;
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- signalId = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET());
- hookId = OS.g_signal_add_emission_hook (signalId, 0, display.emissionProc, handle, 0);
- }
- int response = OS.gtk_dialog_run (handle);
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- OS.g_signal_remove_emission_hook (signalId, hookId);
- }
- if (OS.gtk_window_get_modal (handle)) {
- display.setModalDialog (oldModal);
- }
- display.removeIdleProc ();
- OS.gtk_widget_destroy (handle);
- return response;
-}
-
-private void createButtons (int alignment) {
- if (alignment == SWT.LEFT) {
- if ((style & SWT.OK) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, "gtk-ok", true), SWT.OK);
- if ((style & SWT.ABORT) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, SWT.getMessage("SWT_Abort"), true), SWT.ABORT);
- if ((style & SWT.RETRY) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, SWT.getMessage("SWT_Retry"), true), SWT.RETRY);
- if ((style & SWT.YES) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, "gtk-yes", true), SWT.YES);
- if ((style & SWT.NO) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, "gtk-no", true), SWT.NO);
- if ((style & SWT.IGNORE) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, SWT.getMessage("SWT_Ignore"), true), SWT.IGNORE);
- if ((style & SWT.CANCEL) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, "gtk-cancel", true), SWT.CANCEL);
- } else {
- if ((style & SWT.CANCEL) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, "gtk-cancel", true), SWT.CANCEL);
- if ((style & SWT.OK) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, "gtk-ok", true), SWT.OK);
- if ((style & SWT.NO) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, "gtk-no", true), SWT.NO);
- if ((style & SWT.YES) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, "gtk-yes", true), SWT.YES);
- if ((style & SWT.IGNORE) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, SWT.getMessage("SWT_Ignore"), true), SWT.IGNORE);
- if ((style & SWT.RETRY) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, SWT.getMessage("SWT_Retry"), true), SWT.RETRY);
- if ((style & SWT.ABORT) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, SWT.getMessage("SWT_Abort"), true), SWT.ABORT);
- }
-}
-
-private static int checkStyle (int style) {
- int mask = (SWT.YES | SWT.NO | SWT.OK | SWT.CANCEL | SWT.ABORT | SWT.RETRY | SWT.IGNORE);
- int bits = style & mask;
- if (bits == SWT.OK || bits == SWT.CANCEL || bits == (SWT.OK | SWT.CANCEL)) return style;
- if (bits == SWT.YES || bits == SWT.NO || bits == (SWT.YES | SWT.NO) || bits == (SWT.YES | SWT.NO | SWT.CANCEL)) return style;
- if (bits == (SWT.RETRY | SWT.CANCEL) || bits == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) return style;
- style = (style & ~mask) | SWT.OK;
- return style;
-}
-
-char[] fixPercent (String string) {
- int length = string.length ();
- char [] text = new char [length];
- string.getChars (0, length, text, 0);
- int i = 0, j = 0;
- char [] result = new char [length * 2];
- while (i < length) {
- switch (text [i]) {
- case '%':
- result [j++] = '%';
- break;
- }
- result [j++] = text [i++];
- }
- return result;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ProgressBar.java
deleted file mode 100644
index 34f3886d1f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ProgressBar.java
+++ /dev/null
@@ -1,302 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gtk.*;
-
-/**
- * Instances of the receiver represent an unselectable
- * user interface object that is used to display progress,
- * typically in the form of a bar.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SMOOTH, HORIZONTAL, VERTICAL, INDETERMINATE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#progressbar">ProgressBar snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ProgressBar extends Control {
- int timerId, minimum = 0, maximum = 100, selection = 0;
- static final int DELAY = 100;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SMOOTH
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#INDETERMINATE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ProgressBar (Composite parent, int style) {
- super (parent, checkStyle(style));
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (fixedHandle, true);
- handle = OS.gtk_progress_bar_new ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (fixedHandle, handle);
- int orientation = (style & SWT.VERTICAL) != 0 ? OS.GTK_PROGRESS_BOTTOM_TO_TOP : OS.GTK_PROGRESS_LEFT_TO_RIGHT;
- OS.gtk_progress_bar_set_orientation (handle, orientation);
- if ((style & SWT.INDETERMINATE) != 0) {
- timerId = OS.gtk_timeout_add (DELAY, display.windowTimerProc, handle);
- }
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget ();
- return maximum;
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget ();
- return minimum;
-}
-
-/**
- * Returns the single 'selection' that is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget ();
- return selection;
-}
-
-/**
- * Returns the state of the receiver. The value will be one of:
- * <ul>
- * <li>{@link SWT#NORMAL}</li>
- * <li>{@link SWT#ERROR}</li>
- * <li>{@link SWT#PAUSED}</li>
- * </ul>
- *
- * @return the state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public int getState () {
- checkWidget ();
- return SWT.NORMAL;
-}
-
-int /*long*/ gtk_realize (int /*long*/ widget) {
- int /*long*/ result = super.gtk_realize (widget);
- if (result != 0) return result;
- /*
- * Bug in GTK. When a progress bar has been unrealized after being
- * realized at least once, gtk_progress_bar_set_fraction() GP's. The
- * fix is to update the progress bar state only when realized and restore
- * the state when the progress bar becomes realized.
- */
- updateBar (selection, minimum, maximum);
- return 0;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (timerId != 0) OS.gtk_timeout_remove (timerId);
- timerId = 0;
-}
-
-void setParentBackground () {
- /*
- * Bug in GTK. For some reason, some theme managers will crash
- * when the progress bar is inheriting the background from a parent.
- * The fix is to stop inheriting the background. This is acceptable
- * since progress bars do not use the inherited background.
- */
-}
-
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget ();
- if (value <= minimum) return;
- maximum = value;
- selection = Math.min (selection, maximum);
- updateBar (selection, minimum, maximum);
-}
-
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is negative or is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be nonnegative and less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget ();
- if (value < 0 || value >= maximum) return;
- minimum = value;
- selection = Math.max (selection, minimum);
- updateBar (selection, minimum, maximum);
-}
-
-/**
- * Sets the single 'selection' that is the receiver's
- * position to the argument which must be greater than or equal
- * to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget ();
- selection = Math.max (minimum, Math.min (maximum, value));
- updateBar (selection, minimum, maximum);
-}
-
-/**
- * Sets the state of the receiver. The state must be one of these values:
- * <ul>
- * <li>{@link SWT#NORMAL}</li>
- * <li>{@link SWT#ERROR}</li>
- * <li>{@link SWT#PAUSED}</li>
- * </ul>
- *
- * @param state the new state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setState (int state) {
- checkWidget ();
- //NOT IMPLEMENTED
-}
-
-int /*long*/ timerProc (int /*long*/ widget) {
- if (isVisible ()) OS.gtk_progress_bar_pulse (handle);
- return 1;
-}
-
-void updateBar (int selection, int minimum, int maximum) {
- /*
- * Bug in GTK. When a progress bar has been unrealized after being
- * realized at least once, gtk_progress_bar_set_fraction() GP's. The
- * fix is to update the progress bar state only when realized and restore
- * the state when the progress bar becomes realized.
- */
- if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_REALIZED) == 0) return;
-
- double fraction = minimum == maximum ? 1 : (double)(selection - minimum) / (maximum - minimum);
- OS.gtk_progress_bar_set_fraction (handle, fraction);
- /*
- * Feature in GTK. The progress bar does
- * not redraw right away when a value is
- * changed. This is not strictly incorrect
- * but unexpected. The fix is to force all
- * outstanding redraws to be delivered.
- */
- int /*long*/ window = paintWindow ();
- OS.gdk_window_process_updates (window, false);
- OS.gdk_flush ();
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java
deleted file mode 100644
index 4c5d29ce0a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java
+++ /dev/null
@@ -1,441 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of the receiver represent a selectable user interface object
- * that allows the user to drag a rubber banded outline of the sash within
- * the parent control.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL, SMOOTH</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#sash">Sash snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Sash extends Control {
- boolean dragging;
- int startX, startY, lastX, lastY;
- int /*long*/ defaultCursor;
-
- private final static int INCREMENT = 1;
- private final static int PAGE_INCREMENT = 9;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#SMOOTH
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Sash (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the x, y, width, and height fields of the event object are valid.
- * If the receiver is being dragged, the event object detail field contains the value <code>SWT.DRAG</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += DEFAULT_WIDTH; height += 3;
- } else {
- width += 3; height += DEFAULT_HEIGHT;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-
-void createHandle (int index) {
- state |= HANDLE | THEME_BACKGROUND;
- handle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (handle, true);
- OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS);
- int type = (style & SWT.VERTICAL) != 0 ? OS.GDK_SB_H_DOUBLE_ARROW : OS.GDK_SB_V_DOUBLE_ARROW;
- defaultCursor = OS.gdk_cursor_new (type);
-}
-
-void drawBand (int x, int y, int width, int height) {
- if ((style & SWT.SMOOTH) != 0) return;
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (parent.paintHandle());
- if (window == 0) return;
- byte [] bits = {-86, 85, -86, 85, -86, 85, -86, 85};
- int /*long*/ stipplePixmap = OS.gdk_bitmap_create_from_data (window, bits, 8, 8);
- int /*long*/ gc = OS.gdk_gc_new (window);
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- GdkColor color = new GdkColor ();
- OS.gdk_color_white (colormap, color);
- OS.gdk_gc_set_foreground (gc, color);
- OS.gdk_gc_set_stipple (gc, stipplePixmap);
- OS.gdk_gc_set_subwindow (gc, OS.GDK_INCLUDE_INFERIORS);
- OS.gdk_gc_set_fill (gc, OS.GDK_STIPPLED);
- OS.gdk_gc_set_function (gc, OS.GDK_XOR);
- OS.gdk_draw_rectangle (window, gc, 1, x, y, width, height);
- OS.g_object_unref (stipplePixmap);
- OS.g_object_unref (gc);
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ eventPtr) {
- int /*long*/ result = super.gtk_button_press_event (widget, eventPtr);
- if (result != 0) return result;
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, eventPtr, GdkEventButton.sizeof);
- int button = gdkEvent.button;
- if (button != 1) return 0;
- if (gdkEvent.type == OS.GDK_2BUTTON_PRESS) return 0;
- if (gdkEvent.type == OS.GDK_3BUTTON_PRESS) return 0;
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (widget);
- int [] origin_x = new int [1], origin_y = new int [1];
- OS.gdk_window_get_origin (window, origin_x, origin_y);
- startX = (int) (gdkEvent.x_root - origin_x [0]);
- startY = (int) (gdkEvent.y_root - origin_y [0]);
- int x = OS.GTK_WIDGET_X (handle);
- int y = OS.GTK_WIDGET_Y (handle);
- int width = OS.GTK_WIDGET_WIDTH (handle);
- int height = OS.GTK_WIDGET_HEIGHT (handle);
- lastX = x;
- lastY = y;
- Event event = new Event ();
- event.time = gdkEvent.time;
- event.x = lastX;
- event.y = lastY;
- event.width = width;
- event.height = height;
- if ((style & SWT.SMOOTH) == 0) {
- event.detail = SWT.DRAG;
- }
- if ((parent.style & SWT.MIRRORED) != 0) event.x = parent.getClientWidth () - width - event.x;
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return 0;
- if (event.doit) {
- dragging = true;
- lastX = event.x;
- lastY = event.y;
- if ((parent.style & SWT.MIRRORED) != 0) lastX = parent.getClientWidth () - width - lastX;
- parent.update (true, (style & SWT.SMOOTH) == 0);
- drawBand (lastX, event.y, width, height);
- if ((style & SWT.SMOOTH) != 0) {
- setBounds (event.x, event.y, width, height);
- // widget could be disposed at this point
- }
- }
- return result;
-}
-
-int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ eventPtr) {
- int /*long*/ result = super.gtk_button_release_event (widget, eventPtr);
- if (result != 0) return result;
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, eventPtr, GdkEventButton.sizeof);
- int button = gdkEvent.button;
- if (button != 1) return 0;
- if (!dragging) return 0;
- dragging = false;
- int width = OS.GTK_WIDGET_WIDTH (handle);
- int height = OS.GTK_WIDGET_HEIGHT (handle);
- Event event = new Event ();
- event.time = gdkEvent.time;
- event.x = lastX;
- event.y = lastY;
- event.width = width;
- event.height = height;
- drawBand (lastX, lastY, width, height);
- if ((parent.style & SWT.MIRRORED) != 0) event.x = parent.getClientWidth () - width - event.x;
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return result;
- if (event.doit) {
- if ((style & SWT.SMOOTH) != 0) {
- setBounds (event.x, event.y, width, height);
- // widget could be disposed at this point
- }
- }
- return result;
-}
-
-int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_focus_in_event (widget, event);
- if (result != 0) return result;
- // widget could be disposed at this point
- if (handle != 0) {
- lastX = OS.GTK_WIDGET_X (handle);
- lastY = OS.GTK_WIDGET_Y (handle);
- }
- return 0;
-}
-
-int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ eventPtr) {
- int /*long*/ result = super.gtk_key_press_event (widget, eventPtr);
- if (result != 0) return result;
- GdkEventKey gdkEvent = new GdkEventKey ();
- OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof);
- int keyval = gdkEvent.keyval;
- switch (keyval) {
- case OS.GDK_Left:
- case OS.GDK_Right:
- case OS.GDK_Up:
- case OS.GDK_Down:
- int xChange = 0, yChange = 0;
- int stepSize = PAGE_INCREMENT;
- if ((gdkEvent.state & OS.GDK_CONTROL_MASK) != 0) stepSize = INCREMENT;
- if ((style & SWT.VERTICAL) != 0) {
- if (keyval == OS.GDK_Up || keyval == OS.GDK_Down) break;
- xChange = keyval == OS.GDK_Left ? -stepSize : stepSize;
- } else {
- if (keyval == OS.GDK_Left ||keyval == OS.GDK_Right) break;
- yChange = keyval == OS.GDK_Up ? -stepSize : stepSize;
- }
-
- int width = OS.GTK_WIDGET_WIDTH (handle);
- int height = OS.GTK_WIDGET_HEIGHT (handle);
- int parentBorder = 0;
- int parentWidth = OS.GTK_WIDGET_WIDTH (parent.handle);
- int parentHeight = OS.GTK_WIDGET_HEIGHT (parent.handle);
- int newX = lastX, newY = lastY;
- if ((style & SWT.VERTICAL) != 0) {
- newX = Math.min (Math.max (0, lastX + xChange - parentBorder - startX), parentWidth - width);
- } else {
- newY = Math.min (Math.max (0, lastY + yChange - parentBorder - startY), parentHeight - height);
- }
- if (newX == lastX && newY == lastY) return result;
-
- /* Ensure that the pointer image does not change */
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (handle);
- int grabMask = OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_RELEASE_MASK;
- int /*long*/ gdkCursor = cursor != null ? cursor.handle : defaultCursor;
- int ptrGrabResult = OS.gdk_pointer_grab (window, false, grabMask, window, gdkCursor, OS.GDK_CURRENT_TIME);
-
- /* The event must be sent because its doit flag is used. */
- Event event = new Event ();
- event.time = gdkEvent.time;
- event.x = newX;
- event.y = newY;
- event.width = width;
- event.height = height;
- if ((parent.style & SWT.MIRRORED) != 0) event.x = parent.getClientWidth () - width - event.x;
- sendEvent (SWT.Selection, event);
- if (ptrGrabResult == OS.GDK_GRAB_SUCCESS) OS.gdk_pointer_ungrab (OS.GDK_CURRENT_TIME);
- if (isDisposed ()) break;
-
- if (event.doit) {
- lastX = event.x;
- lastY = event.y;
- if ((parent.style & SWT.MIRRORED) != 0) lastX = parent.getClientWidth () - width - lastX;
- if ((style & SWT.SMOOTH) != 0) {
- setBounds (event.x, event.y, width, height);
- if (isDisposed ()) break;
- }
- int cursorX = event.x, cursorY = event.y;
- if ((style & SWT.VERTICAL) != 0) {
- cursorY += height / 2;
- } else {
- cursorX += width / 2;
- }
- display.setCursorLocation (parent.toDisplay (cursorX, cursorY));
- }
- break;
- }
-
- return result;
-}
-
-int /*long*/ gtk_motion_notify_event (int /*long*/ widget, int /*long*/ eventPtr) {
- int /*long*/ result = super.gtk_motion_notify_event (widget, eventPtr);
- if (result != 0) return result;
- if (!dragging) return 0;
- GdkEventMotion gdkEvent = new GdkEventMotion ();
- OS.memmove (gdkEvent, eventPtr, GdkEventButton.sizeof);
- int eventX, eventY, eventState;
- if (gdkEvent.is_hint != 0) {
- int [] pointer_x = new int [1], pointer_y = new int [1], mask = new int [1];
- OS.gdk_window_get_pointer (gdkEvent.window, pointer_x, pointer_y, mask);
- eventX = pointer_x [0];
- eventY = pointer_y [0];
- eventState = mask [0];
- } else {
- int [] origin_x = new int [1], origin_y = new int [1];
- OS.gdk_window_get_origin (gdkEvent.window, origin_x, origin_y);
- eventX = (int) (gdkEvent.x_root - origin_x [0]);
- eventY = (int) (gdkEvent.y_root - origin_y [0]);
- eventState = gdkEvent.state;
- }
- if ((eventState & OS.GDK_BUTTON1_MASK) == 0) return 0;
- int x = OS.GTK_WIDGET_X (handle);
- int y = OS.GTK_WIDGET_Y (handle);
- int width = OS.GTK_WIDGET_WIDTH (handle);
- int height = OS.GTK_WIDGET_HEIGHT (handle);
- int parentBorder = 0;
- int parentWidth = OS.GTK_WIDGET_WIDTH (parent.handle);
- int parentHeight = OS.GTK_WIDGET_HEIGHT (parent.handle);
- int newX = lastX, newY = lastY;
- if ((style & SWT.VERTICAL) != 0) {
- newX = Math.min (Math.max (0, eventX + x - startX - parentBorder), parentWidth - width);
- } else {
- newY = Math.min (Math.max (0, eventY + y - startY - parentBorder), parentHeight - height);
- }
- if (newX == lastX && newY == lastY) return 0;
- drawBand (lastX, lastY, width, height);
-
- Event event = new Event ();
- event.time = gdkEvent.time;
- event.x = newX;
- event.y = newY;
- event.width = width;
- event.height = height;
- if ((style & SWT.SMOOTH) == 0) {
- event.detail = SWT.DRAG;
- }
- if ((parent.style & SWT.MIRRORED) != 0) event.x = parent.getClientWidth() - width - event.x;
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return 0;
- if (event.doit) {
- lastX = event.x;
- lastY = event.y;
- if ((parent.style & SWT.MIRRORED) != 0) lastX = parent.getClientWidth () - width - lastX;
- }
- parent.update (true, (style & SWT.SMOOTH) == 0);
- drawBand (lastX, lastY, width, height);
- if ((style & SWT.SMOOTH) != 0) {
- setBounds (event.x, lastY, width, height);
- // widget could be disposed at this point
- }
- return result;
-}
-
-int /*long*/ gtk_realize (int /*long*/ widget) {
- setCursor (cursor != null ? cursor.handle : 0);
- return super.gtk_realize (widget);
-}
-
-void hookEvents () {
- super.hookEvents ();
- OS.gtk_widget_add_events (handle, OS.GDK_POINTER_MOTION_HINT_MASK);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (defaultCursor != 0) OS.gdk_cursor_destroy (defaultCursor);
- defaultCursor = 0;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-void setCursor (int /*long*/ cursor) {
- super.setCursor (cursor != 0 ? cursor : defaultCursor);
-}
-
-int traversalCode (int key, GdkEventKey event) {
- return 0;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java
deleted file mode 100644
index 47e6ebbf5c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java
+++ /dev/null
@@ -1,377 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of the receiver represent a selectable user
- * interface object that present a range of continuous
- * numeric values.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#scale">Scale snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Scale extends Control {
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Scale (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the receiver's value.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- Point size = computeNativeSize(handle, wHint, hHint, changed);
- if ((style & SWT.HORIZONTAL) != 0) {
- if (wHint == SWT.DEFAULT) size.x = 2 * size.x;
- } else {
- if (hHint == SWT.DEFAULT) size.y = 2 * size.y;
- }
- return size;
-}
-
-void createHandle (int index) {
- state |= HANDLE | THEME_BACKGROUND;
- fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (fixedHandle, true);
- int /*long*/ hAdjustment = OS.gtk_adjustment_new (0, 0, 100, 1, 10, 0);
- if (hAdjustment == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.HORIZONTAL) != 0) {
- handle = OS.gtk_hscale_new (hAdjustment);
- } else {
- handle = OS.gtk_vscale_new (hAdjustment);
- }
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (fixedHandle, handle);
- OS.gtk_scale_set_digits (handle, 0);
- OS.gtk_scale_set_draw_value (handle, false);
-}
-
-void hookEvents () {
- super.hookEvents ();
- OS.g_signal_connect_closure (handle, OS.value_changed, display.closures [VALUE_CHANGED], false);
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- return (int) adjustment.step_increment;
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- return (int) adjustment.upper;
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- return (int) adjustment.lower;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- return (int) adjustment.page_increment;
-}
-
-/**
- * Returns the 'selection', which is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- return (int) adjustment.value;
-}
-
-int /*long*/ gtk_value_changed (int /*long*/ adjustment) {
- postEvent (SWT.Selection);
- return 0;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param increment the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_range_set_increments (handle, value, getPageIncrement ());
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget ();
- int minimum = getMinimum();
- if (value <= minimum) return;
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_range_set_range (handle, minimum, value);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is negative or is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be nonnegative and less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget ();
- if (value < 0) return;
- int maximum = getMaximum ();
- if (value >= maximum) return;
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_range_set_range (handle, value, maximum);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param pageIncrement the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_range_set_increments (handle, getIncrement (), value);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the 'selection', which is the receiver's value,
- * to the argument which must be greater than or equal to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget ();
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_range_set_value (handle, value);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java
deleted file mode 100644
index b2fcd24553..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java
+++ /dev/null
@@ -1,768 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that represent a range of positive, numeric values.
- * <p>
- * At any given moment, a given scroll bar will have a
- * single 'selection' that is considered to be its
- * value, which is constrained to be within the range of
- * values the scroll bar represents (that is, between its
- * <em>minimum</em> and <em>maximum</em> values).
- * </p><p>
- * Typically, scroll bars will be made up of five areas:
- * <ol>
- * <li>an arrow button for decrementing the value</li>
- * <li>a page decrement area for decrementing the value by a larger amount</li>
- * <li>a <em>thumb</em> for modifying the value by mouse dragging</li>
- * <li>a page increment area for incrementing the value by a larger amount</li>
- * <li>an arrow button for incrementing the value</li>
- * </ol>
- * Based on their style, scroll bars are either <code>HORIZONTAL</code>
- * (which have a left facing button for decrementing the value and a
- * right facing button for incrementing it) or <code>VERTICAL</code>
- * (which have an upward facing button for decrementing the value
- * and a downward facing buttons for incrementing it).
- * </p><p>
- * On some platforms, the size of the scroll bar's thumb can be
- * varied relative to the magnitude of the range of values it
- * represents (that is, relative to the difference between its
- * maximum and minimum values). Typically, this is used to
- * indicate some proportional value such as the ratio of the
- * visible area of a document to the total amount of space that
- * it would take to display it. SWT supports setting the thumb
- * size even if the underlying platform does not, but in this
- * case the appearance of the scroll bar will not change.
- * </p><p>
- * Scroll bars are created by specifying either <code>H_SCROLL</code>,
- * <code>V_SCROLL</code> or both when creating a <code>Scrollable</code>.
- * They are accessed from the <code>Scrollable</code> using
- * <code>getHorizontalBar</code> and <code>getVerticalBar</code>.
- * </p><p>
- * Note: Scroll bars are not Controls. On some platforms, scroll bars
- * that appear as part of some standard controls such as a text or list
- * have no operating system resources and are not children of the control.
- * For this reason, scroll bars are treated specially. To create a control
- * that looks like a scroll bar but has operating system resources, use
- * <code>Slider</code>.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see Slider
- * @see Scrollable
- * @see Scrollable#getHorizontalBar
- * @see Scrollable#getVerticalBar
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ScrollBar extends Widget {
- Scrollable parent;
- int /*long*/ adjustmentHandle;
- int detail;
- boolean dragSent;
-
-ScrollBar () {
-}
-
-/**
-* Creates a new instance of the widget.
-*/
-ScrollBar (Scrollable parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (0);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values:
- * <code>SWT.NONE</code> - for the end of a drag.
- * <code>SWT.DRAG</code>.
- * <code>SWT.HOME</code>.
- * <code>SWT.END</code>.
- * <code>SWT.ARROW_DOWN</code>.
- * <code>SWT.ARROW_UP</code>.
- * <code>SWT.PAGE_DOWN</code>.
- * <code>SWT.PAGE_UP</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-void deregister () {
- super.deregister ();
- if (adjustmentHandle != 0) display.removeWidget (adjustmentHandle);
-}
-
-void destroyHandle () {
- super.destroyWidget ();
-}
-
-void destroyWidget () {
- parent.destroyScrollBar (this);
- releaseHandle ();
- //parent.sendEvent (SWT.Resize);
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget ();
- if (handle != 0) return OS.GTK_WIDGET_SENSITIVE (handle);
- return true;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget ();
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, adjustmentHandle);
- return (int) adjustment.step_increment;
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget ();
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, adjustmentHandle);
- return (int) adjustment.upper;
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget ();
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, adjustmentHandle);
- return (int) adjustment.lower;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget ();
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, adjustmentHandle);
- return (int) adjustment.page_increment;
-}
-
-/**
- * Returns the receiver's parent, which must be a Scrollable.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Scrollable getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the single 'selection' that is the receiver's value.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget ();
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, adjustmentHandle);
- return (int) adjustment.value;
-}
-
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget ();
- if (handle == 0) return new Point (0,0);
- GtkRequisition requisition = new GtkRequisition ();
- OS.gtk_widget_size_request (handle, requisition);
- return new Point (requisition.width, requisition.height);
-}
-
-/**
- * Returns the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values.
- *
- * @return the thumb value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ScrollBar
- */
-public int getThumb () {
- checkWidget ();
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, adjustmentHandle);
- return (int) adjustment.page_size;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- int /*long*/ scrolledHandle = parent.scrolledHandle;
- int [] hsp = new int [1], vsp = new int [1];
- OS.gtk_scrolled_window_get_policy (scrolledHandle, hsp, vsp);
- if ((style & SWT.HORIZONTAL) != 0) {
- return hsp [0] != OS.GTK_POLICY_NEVER;
- } else {
- return vsp [0] != OS.GTK_POLICY_NEVER;
- }
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ eventPtr) {
- int /*long*/ result = super.gtk_button_press_event (widget, eventPtr);
- if (result != 0) return result;
- detail = OS.GTK_SCROLL_NONE;
- dragSent = false;
- return result;
-}
-
-int /*long*/ gtk_change_value (int /*long*/ widget, int /*long*/ scroll, int /*long*/ value1, int /*long*/ value2) {
- detail = (int)/*64*/scroll;
- return 0;
-}
-
-int /*long*/ gtk_value_changed (int /*long*/ adjustment) {
- Event event = new Event ();
- dragSent = detail == OS.GTK_SCROLL_JUMP;
- switch (detail) {
- case OS.GTK_SCROLL_NONE: event.detail = SWT.NONE; break;
- case OS.GTK_SCROLL_JUMP: event.detail = SWT.DRAG; break;
- case OS.GTK_SCROLL_START: event.detail = SWT.HOME; break;
- case OS.GTK_SCROLL_END: event.detail = SWT.END; break;
- case OS.GTK_SCROLL_PAGE_DOWN:
- case OS.GTK_SCROLL_PAGE_RIGHT:
- case OS.GTK_SCROLL_PAGE_FORWARD: event.detail = SWT.PAGE_DOWN; break;
- case OS.GTK_SCROLL_PAGE_UP:
- case OS.GTK_SCROLL_PAGE_LEFT:
- case OS.GTK_SCROLL_PAGE_BACKWARD: event.detail = SWT.PAGE_UP; break;
- case OS.GTK_SCROLL_STEP_DOWN:
- case OS.GTK_SCROLL_STEP_RIGHT:
- case OS.GTK_SCROLL_STEP_FORWARD: event.detail = SWT.ARROW_DOWN; break;
- case OS.GTK_SCROLL_STEP_UP:
- case OS.GTK_SCROLL_STEP_LEFT:
- case OS.GTK_SCROLL_STEP_BACKWARD: event.detail = SWT.ARROW_UP; break;
- }
- detail = OS.GTK_SCROLL_NONE;
- if (!dragSent) detail = OS.GTK_SCROLL_NONE;
- postEvent (SWT.Selection, event);
- parent.updateScrollBarValue (this);
- return 0;
-}
-
-int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) {
- GdkEvent gtkEvent = new GdkEvent ();
- OS.memmove (gtkEvent, gdkEvent, GdkEvent.sizeof);
- switch (gtkEvent.type) {
- case OS.GDK_BUTTON_RELEASE: {
- GdkEventButton gdkEventButton = new GdkEventButton ();
- OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof);
- if (gdkEventButton.button == 1 && detail == SWT.DRAG) {
- if (!dragSent) {
- Event event = new Event ();
- event.detail = SWT.DRAG;
- postEvent (SWT.Selection, event);
- }
- postEvent (SWT.Selection);
- }
- detail = OS.GTK_SCROLL_NONE;
- dragSent = false;
- break;
- }
- }
- return super.gtk_event_after (widget, gdkEvent);
-}
-
-void hookEvents () {
- super.hookEvents ();
- if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) {
- OS.g_signal_connect_closure (handle, OS.change_value, display.closures [CHANGE_VALUE], false);
- }
- OS.g_signal_connect_closure (adjustmentHandle, OS.value_changed, display.closures [VALUE_CHANGED], false);
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [EVENT_AFTER], 0, display.closures [EVENT_AFTER], false);
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false);
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget ();
- return getEnabled () && getParent ().getEnabled ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget ();
- return getVisible () && getParent ().isVisible ();
-}
-
-void register () {
- super.register ();
- if (adjustmentHandle != 0) display.addWidget (adjustmentHandle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (parent.horizontalBar == this) parent.horizontalBar = null;
- if (parent.verticalBar == this) parent.verticalBar = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- //parent = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget ();
- if (handle != 0) OS.gtk_widget_set_sensitive (handle, enabled);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, adjustmentHandle);
- adjustment.step_increment = (float) value;
- OS.memmove (adjustmentHandle, adjustment);
- OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_adjustment_changed (adjustmentHandle);
- OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the maximum. If this value is negative or less than or
- * equal to the minimum, the value is ignored. If necessary, first
- * the thumb and then the selection are adjusted to fit within the
- * new range.
- *
- * @param value the new maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget ();
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, adjustmentHandle);
- int minimum = (int) adjustment.lower;
- if (value <= minimum) return;
- adjustment.upper = value;
- adjustment.page_size = Math.min ((int)adjustment.page_size, value - minimum);
- adjustment.value = Math.min ((int)adjustment.value, (int)(value - adjustment.page_size));
- OS.memmove (adjustmentHandle, adjustment);
- OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_adjustment_changed (adjustmentHandle);
- OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the minimum value. If this value is negative or greater
- * than or equal to the maximum, the value is ignored. If necessary,
- * first the thumb and then the selection are adjusted to fit within
- * the new range.
- *
- * @param value the new minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget ();
- if (value < 0) return;
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, adjustmentHandle);
- int maximum = (int) adjustment.upper;
- if (value >= maximum) return;
- adjustment.lower = value;
- adjustment.page_size = Math.min ((int)adjustment.page_size, maximum - value);
- adjustment.value = Math.max ((int)adjustment.value, value);
- OS.memmove (adjustmentHandle, adjustment);
- OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_adjustment_changed (adjustmentHandle);
- OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-void setOrientation () {
- super.setOrientation ();
- if ((parent.style & SWT.MIRRORED) != 0) {
- if ((parent.state & CANVAS) != 0) {
- if ((style & SWT.HORIZONTAL) != 0) {
- OS.gtk_range_set_inverted (handle, true);
- }
- }
- }
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, adjustmentHandle);
- adjustment.page_increment = (float) value;
- OS.memmove (adjustmentHandle, adjustment);
- OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_adjustment_changed (adjustmentHandle);
- OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the single <em>selection</em> that is the receiver's
- * value to the argument which must be greater than or equal
- * to zero.
- *
- * @param selection the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget ();
- value = Math.min (value, getMaximum() - getThumb());
- OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_adjustment_set_value (adjustmentHandle, value);
- OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values. This new
- * value will be ignored if it is less than one, and will be
- * clamped if it exceeds the receiver's current range.
- *
- * @param value the new thumb value, which must be at least one and not
- * larger than the size of the current range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setThumb (int value) {
- checkWidget ();
- if (value < 1) return;
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, adjustmentHandle);
- value = (int) Math.min (value, (int)(adjustment.upper - adjustment.lower));
- adjustment.page_size = (double) value;
- adjustment.value = Math.min ((int)adjustment.value, (int)(adjustment.upper - value));
- OS.memmove (adjustmentHandle, adjustment);
- OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_adjustment_changed (adjustmentHandle);
- OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, thumb, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param thumb the new thumb value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- checkWidget ();
- if (minimum < 0) return;
- if (maximum < 0) return;
- if (thumb < 1) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- thumb = Math.min (thumb, maximum - minimum);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, adjustmentHandle);
- adjustment.lower = minimum;
- adjustment.upper = maximum;
- adjustment.step_increment = increment;
- adjustment.page_increment = pageIncrement;
- adjustment.page_size = thumb;
- adjustment.value = Math.min (Math.max (selection, minimum), maximum - thumb);
- OS.memmove (adjustmentHandle, adjustment);
- OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_adjustment_changed (adjustmentHandle);
- OS.gtk_adjustment_value_changed (adjustmentHandle);
- OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- if (parent.setScrollBarVisible (this, visible)) {
- sendEvent (visible ? SWT.Show : SWT.Hide);
- parent.sendEvent (SWT.Resize);
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java
deleted file mode 100644
index ab3304558a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java
+++ /dev/null
@@ -1,384 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * This class is the abstract superclass of all classes which
- * represent controls that have standard scroll bars.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>H_SCROLL, V_SCROLL</dd>
- * <dt><b>Events:</b>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public abstract class Scrollable extends Control {
- int /*long*/ scrolledHandle;
- ScrollBar horizontalBar, verticalBar;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Scrollable () {}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#H_SCROLL
- * @see SWT#V_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Scrollable (Composite parent, int style) {
- super (parent, style);
-}
-
-int /*long*/ clientHandle () {
- return handle;
-}
-
-/**
- * Given a desired <em>client area</em> for the receiver
- * (as described by the arguments), returns the bounding
- * rectangle which would be required to produce that client
- * area.
- * <p>
- * In other words, it returns a rectangle such that, if the
- * receiver's bounds were set to that rectangle, the area
- * of the receiver which is capable of displaying data
- * (that is, not covered by the "trimmings") would be the
- * rectangle described by the arguments (relative to the
- * receiver's parent).
- * </p>
- *
- * @param x the desired x coordinate of the client area
- * @param y the desired y coordinate of the client area
- * @param width the desired width of the client area
- * @param height the desired height of the client area
- * @return the required bounds to produce the given client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getClientArea
- */
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- int border = 0;
- if (fixedHandle != 0) border += OS.gtk_container_get_border_width (fixedHandle);
- if (scrolledHandle != 0) border += OS.gtk_container_get_border_width (scrolledHandle);
- int trimX = x - border, trimY = y - border;
- int trimWidth = width + (border * 2), trimHeight = height + (border * 2);
- trimHeight += hScrollBarWidth ();
- trimWidth += vScrollBarWidth ();
- if (scrolledHandle != 0) {
- if (OS.gtk_scrolled_window_get_shadow_type (scrolledHandle) != OS.GTK_SHADOW_NONE) {
- int /*long*/ style = OS.gtk_widget_get_style (scrolledHandle);
- int xthickness = OS.gtk_style_get_xthickness (style);
- int ythickness = OS.gtk_style_get_ythickness (style);
- trimX -= xthickness;
- trimY -= ythickness;
- trimWidth += xthickness * 2;
- trimHeight += ythickness * 2;
- }
- }
- return new Rectangle (trimX, trimY, trimWidth, trimHeight);
-}
-
-ScrollBar createScrollBar (int style) {
- if (scrolledHandle == 0) return null;
- ScrollBar bar = new ScrollBar ();
- bar.parent = this;
- bar.style = style;
- bar.display = display;
- bar.state |= HANDLE;
- if ((style & SWT.H_SCROLL) != 0) {
- bar.handle = OS.GTK_SCROLLED_WINDOW_HSCROLLBAR (scrolledHandle);
- bar.adjustmentHandle = OS.gtk_scrolled_window_get_hadjustment (scrolledHandle);
- } else {
- bar.handle = OS.GTK_SCROLLED_WINDOW_VSCROLLBAR (scrolledHandle);
- bar.adjustmentHandle = OS.gtk_scrolled_window_get_vadjustment (scrolledHandle);
- }
- bar.setOrientation();
- bar.hookEvents ();
- bar.register ();
- return bar;
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- if ((style & SWT.H_SCROLL) != 0) horizontalBar = createScrollBar (SWT.H_SCROLL);
- if ((style & SWT.V_SCROLL) != 0) verticalBar = createScrollBar (SWT.V_SCROLL);
-}
-
-void deregister () {
- super.deregister ();
- if (scrolledHandle != 0) display.removeWidget (scrolledHandle);
-}
-
-void destroyScrollBar (ScrollBar bar) {
- setScrollBarVisible (bar, false);
- //This code is intentionally commented
- //bar.destroyHandle ();
-}
-
-public int getBorderWidth () {
- checkWidget();
- int border = 0;
- if (fixedHandle != 0) border += OS.gtk_container_get_border_width (fixedHandle);
- if (scrolledHandle != 0) {
- border += OS.gtk_container_get_border_width (scrolledHandle);
- if (OS.gtk_scrolled_window_get_shadow_type (scrolledHandle) != OS.GTK_SHADOW_NONE) {
- border += OS.gtk_style_get_xthickness (OS.gtk_widget_get_style (scrolledHandle));
- }
- }
- return border;
-}
-
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data (that is,
- * not covered by the "trimmings").
- *
- * @return the client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeTrim
- */
-public Rectangle getClientArea () {
- checkWidget ();
- forceResize ();
- int /*long*/ clientHandle = clientHandle ();
- int x = OS.GTK_WIDGET_X (clientHandle);
- int y = OS.GTK_WIDGET_Y (clientHandle);
- int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (clientHandle);
- int height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (clientHandle);
- return new Rectangle (x, y, width, height);
-}
-/**
- * Returns the receiver's horizontal scroll bar if it has
- * one, and null if it does not.
- *
- * @return the horizontal scroll bar (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ScrollBar getHorizontalBar () {
- checkWidget ();
- return horizontalBar;
-}
-/**
- * Returns the receiver's vertical scroll bar if it has
- * one, and null if it does not.
- *
- * @return the vertical scroll bar (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ScrollBar getVerticalBar () {
- checkWidget ();
- return verticalBar;
-}
-
-int /*long*/ gtk_scroll_event (int /*long*/ widget, int /*long*/ eventPtr) {
- int /*long*/ result = super.gtk_scroll_event (widget, eventPtr);
-
- /*
- * Feature in GTK. Scrolled windows do not scroll if the scrollbars
- * are hidden. This is not a bug, but is inconsistent with other platforms.
- * The fix is to set the adjustment values directly.
- */
- if ((state & CANVAS) != 0) {
- ScrollBar scrollBar;
- GdkEventScroll gdkEvent = new GdkEventScroll ();
- OS.memmove (gdkEvent, eventPtr, GdkEventScroll.sizeof);
- if (gdkEvent.direction == OS.GDK_SCROLL_UP || gdkEvent.direction == OS.GDK_SCROLL_DOWN) {
- scrollBar = verticalBar;
- } else {
- scrollBar = horizontalBar;
- }
- if (scrollBar != null && !OS.GTK_WIDGET_VISIBLE (scrollBar.handle) && scrollBar.getEnabled()) {
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, scrollBar.adjustmentHandle);
- /* Calculate wheel delta to match GTK+ 2.4 and higher */
- int wheel_delta = (int) Math.pow(adjustment.page_size, 2.0 / 3.0);
- if (gdkEvent.direction == OS.GDK_SCROLL_UP || gdkEvent.direction == OS.GDK_SCROLL_LEFT)
- wheel_delta = -wheel_delta;
- int value = (int) Math.max(adjustment.lower,
- Math.min(adjustment.upper - adjustment.page_size, adjustment.value + wheel_delta));
- OS.gtk_adjustment_set_value (scrollBar.adjustmentHandle, value);
- return 1;
- }
- }
- return result;
-}
-
-int hScrollBarWidth() {
- if (horizontalBar==null) return 0;
- int /*long*/ hBarHandle = OS.GTK_SCROLLED_WINDOW_HSCROLLBAR(scrolledHandle);
- if (hBarHandle==0) return 0;
- GtkRequisition requisition = new GtkRequisition();
- OS.gtk_widget_size_request(hBarHandle, requisition);
- int spacing = OS.GTK_SCROLLED_WINDOW_SCROLLBAR_SPACING(scrolledHandle);
- return requisition.height + spacing;
-}
-
-boolean sendLeaveNotify () {
- return scrolledHandle != 0;
-}
-
-void setOrientation () {
- super.setOrientation ();
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- if (scrolledHandle != 0) {
- OS.gtk_widget_set_direction (scrolledHandle, OS.GTK_TEXT_DIR_RTL);
- }
- }
-}
-
-boolean setScrollBarVisible (ScrollBar bar, boolean visible) {
- if (scrolledHandle == 0) return false;
- int [] hsp = new int [1], vsp = new int [1];
- OS.gtk_scrolled_window_get_policy (scrolledHandle, hsp, vsp);
- int policy = visible ? OS.GTK_POLICY_ALWAYS : OS.GTK_POLICY_NEVER;
- if ((bar.style & SWT.HORIZONTAL) != 0) {
- if (hsp [0] == policy) return false;
- hsp [0] = policy;
- } else {
- if (vsp [0] == policy) return false;
- vsp [0] = policy;
- }
- OS.gtk_scrolled_window_set_policy (scrolledHandle, hsp [0], vsp [0]);
- return true;
-}
-
-void redrawBackgroundImage () {
-}
-
-void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean all, boolean trim) {
- super.redrawWidget (x, y, width, height, redrawAll, all, trim);
- if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_REALIZED) == 0) return;
- if (!trim) return;
- int /*long*/ topHandle = topHandle (), paintHandle = paintHandle ();
- if (topHandle == paintHandle) return;
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (topHandle);
- GdkRectangle rect = new GdkRectangle ();
- if (redrawAll) {
- rect.width = OS.GTK_WIDGET_WIDTH (topHandle);
- rect.height = OS.GTK_WIDGET_HEIGHT (topHandle);
- } else {
- int [] destX = new int [1], destY = new int [1];
- OS.gtk_widget_translate_coordinates (paintHandle, topHandle, x, y, destX, destY);
- rect.x = destX [0];
- rect.y = destY [0];
- rect.width = width;
- rect.height = height;
- }
- OS.gdk_window_invalidate_rect (window, rect, all);
-}
-
-void register () {
- super.register ();
- if (scrolledHandle != 0) display.addWidget (scrolledHandle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- scrolledHandle = 0;
-}
-
-void releaseChildren (boolean destroy) {
- if (horizontalBar != null) {
- horizontalBar.release (false);
- horizontalBar = null;
- }
- if (verticalBar != null) {
- verticalBar.release (false);
- verticalBar = null;
- }
- super.releaseChildren (destroy);
-}
-
-void resizeHandle (int width, int height) {
- if (fixedHandle != 0) OS.gtk_widget_set_size_request (fixedHandle, width, height);
- OS.gtk_widget_set_size_request (scrolledHandle != 0 ? scrolledHandle : handle, width, height);
-}
-
-void showWidget () {
- super.showWidget ();
- if (scrolledHandle != 0) OS.gtk_widget_show (scrolledHandle);
-}
-
-int /*long*/ topHandle () {
- if (fixedHandle != 0) return fixedHandle;
- if (scrolledHandle != 0) return scrolledHandle;
- return super.topHandle ();
-}
-
-void updateScrollBarValue (ScrollBar bar) {
- redrawBackgroundImage ();
-}
-
-int vScrollBarWidth() {
- if (verticalBar == null) return 0;
- int /*long*/ vBarHandle = OS.GTK_SCROLLED_WINDOW_VSCROLLBAR(scrolledHandle);
- if (vBarHandle == 0) return 0;
- GtkRequisition requisition = new GtkRequisition();
- OS.gtk_widget_size_request (vBarHandle, requisition);
- int spacing = OS.GTK_SCROLLED_WINDOW_SCROLLBAR_SPACING(scrolledHandle);
- return requisition.width + spacing;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
deleted file mode 100644
index 9e3a131b63..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
+++ /dev/null
@@ -1,2195 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent the "windows"
- * which the desktop or "window manager" is managing.
- * Instances that do not have a parent (that is, they
- * are built using the constructor, which takes a
- * <code>Display</code> as the argument) are described
- * as <em>top level</em> shells. Instances that do have
- * a parent are described as <em>secondary</em> or
- * <em>dialog</em> shells.
- * <p>
- * Instances are always displayed in one of the maximized,
- * minimized or normal states:
- * <ul>
- * <li>
- * When an instance is marked as <em>maximized</em>, the
- * window manager will typically resize it to fill the
- * entire visible area of the display, and the instance
- * is usually put in a state where it can not be resized
- * (even if it has style <code>RESIZE</code>) until it is
- * no longer maximized.
- * </li><li>
- * When an instance is in the <em>normal</em> state (neither
- * maximized or minimized), its appearance is controlled by
- * the style constants which were specified when it was created
- * and the restrictions of the window manager (see below).
- * </li><li>
- * When an instance has been marked as <em>minimized</em>,
- * its contents (client area) will usually not be visible,
- * and depending on the window manager, it may be
- * "iconified" (that is, replaced on the desktop by a small
- * simplified representation of itself), relocated to a
- * distinguished area of the screen, or hidden. Combinations
- * of these changes are also possible.
- * </li>
- * </ul>
- * </p><p>
- * The <em>modality</em> of an instance may be specified using
- * style bits. The modality style bits are used to determine
- * whether input is blocked for other shells on the display.
- * The <code>PRIMARY_MODAL</code> style allows an instance to block
- * input to its parent. The <code>APPLICATION_MODAL</code> style
- * allows an instance to block input to every other shell in the
- * display. The <code>SYSTEM_MODAL</code> style allows an instance
- * to block input to all shells, including shells belonging to
- * different applications.
- * </p><p>
- * Note: The styles supported by this class are treated
- * as <em>HINT</em>s, since the window manager for the
- * desktop on which the instance is visible has ultimate
- * control over the appearance and behavior of decorations
- * and modality. For example, some window managers only
- * support resizable windows and will always assume the
- * RESIZE style, even if it is not set. In addition, if a
- * modality style is not supported, it is "upgraded" to a
- * more restrictive modality style that is supported. For
- * example, if <code>PRIMARY_MODAL</code> is not supported,
- * it would be upgraded to <code>APPLICATION_MODAL</code>.
- * A modality style may also be "downgraded" to a less
- * restrictive style. For example, most operating systems
- * no longer support <code>SYSTEM_MODAL</code> because
- * it can freeze up the desktop, so this is typically
- * downgraded to <code>APPLICATION_MODAL</code>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL, SHEET</dd>
- * <dd>APPLICATION_MODAL, MODELESS, PRIMARY_MODAL, SYSTEM_MODAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Activate, Close, Deactivate, Deiconify, Iconify</dd>
- * </dl>
- * Class <code>SWT</code> provides two "convenience constants"
- * for the most commonly required style combinations:
- * <dl>
- * <dt><code>SHELL_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application top level shell: (that
- * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>)
- * </dd>
- * <dt><code>DIALOG_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application dialog shell: (that
- * is, <code>TITLE | CLOSE | BORDER</code>)
- * </dd>
- * </dl>
- * </p>
- * <p>
- * Note: Only one of the styles APPLICATION_MODAL, MODELESS,
- * PRIMARY_MODAL and SYSTEM_MODAL may be specified.
- * </p><p>
- * IMPORTANT: This class is not intended to be subclassed.
- * </p>
- *
- * @see Decorations
- * @see SWT
- * @see <a href="http://www.eclipse.org/swt/snippets/#shell">Shell snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class Shell extends Decorations {
- int /*long*/ shellHandle, tooltipsHandle, tooltipWindow, group, modalGroup;
- boolean mapped, moved, resized, opened, fullScreen, showWithParent, modified, center;
- int oldX, oldY, oldWidth, oldHeight;
- int minWidth, minHeight;
- Control lastActive;
- ToolTip [] toolTips;
-
- static final int MAXIMUM_TRIM = 128;
-
-/**
- * Constructs a new instance of this class. This is equivalent
- * to calling <code>Shell((Display) null)</code>.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell () {
- this ((Display) null);
-}
-/**
- * Constructs a new instance of this class given only the style
- * value describing its behavior and appearance. This is equivalent
- * to calling <code>Shell((Display) null, style)</code>.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#TOOL
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (int style) {
- this ((Display) null, style);
-}
-
-/**
- * Constructs a new instance of this class given only the display
- * to create it on. It is created with style <code>SWT.SHELL_TRIM</code>.
- * <p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the shell on
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell (Display display) {
- this (display, SWT.SHELL_TRIM);
-}
-/**
- * Constructs a new instance of this class given the display
- * to create it on and a style value describing its behavior
- * and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the shell on
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#TOOL
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (Display display, int style) {
- this (display, null, style, 0, false);
-}
-
-Shell (Display display, Shell parent, int style, int /*long*/ handle, boolean embedded) {
- super ();
- checkSubclass ();
- if (display == null) display = Display.getCurrent ();
- if (display == null) display = Display.getDefault ();
- if (!display.isValidThread ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- if (parent != null && parent.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.center = parent != null && (style & SWT.SHEET) != 0;
- this.style = checkStyle (parent, style);
- this.parent = parent;
- this.display = display;
- if (handle != 0) {
- if (embedded) {
- this.handle = handle;
- } else {
- shellHandle = handle;
- state |= FOREIGN_HANDLE;
- }
- }
- createWidget (0);
-}
-
-/**
- * Constructs a new instance of this class given only its
- * parent. It is created with style <code>SWT.DIALOG_TRIM</code>.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the parent is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell (Shell parent) {
- this (parent, SWT.DIALOG_TRIM);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the parent is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#TOOL
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (Shell parent, int style) {
- this (parent != null ? parent.display : null, parent, style, 0, false);
-}
-
-public static Shell gtk_new (Display display, int /*long*/ handle) {
- return new Shell (display, null, SWT.NO_TRIM, handle, true);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new shell
- * that is not embedded.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Shell</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param display the display for the shell
- * @param handle the handle for the shell
- * @return a new shell object containing the specified display and handle
- *
- * @since 3.3
- */
-public static Shell internal_new (Display display, int /*long*/ handle) {
- return new Shell (display, null, SWT.NO_TRIM, handle, false);
-}
-
-static int checkStyle (Shell parent, int style) {
- style = Decorations.checkStyle (style);
- style &= ~SWT.TRANSPARENT;
- if ((style & SWT.ON_TOP) != 0) style &= ~SWT.SHELL_TRIM;
- int mask = SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.PRIMARY_MODAL;
- if ((style & SWT.SHEET) != 0) {
- style &= ~SWT.SHEET;
- style |= parent == null ? SWT.SHELL_TRIM : SWT.DIALOG_TRIM;
- if ((style & mask) == 0) {
- style |= parent == null ? SWT.APPLICATION_MODAL : SWT.PRIMARY_MODAL;
- }
- }
- int bits = style & ~mask;
- if ((style & SWT.SYSTEM_MODAL) != 0) return bits | SWT.SYSTEM_MODAL;
- if ((style & SWT.APPLICATION_MODAL) != 0) return bits | SWT.APPLICATION_MODAL;
- if ((style & SWT.PRIMARY_MODAL) != 0) return bits | SWT.PRIMARY_MODAL;
- return bits;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when operations are performed on the receiver,
- * by sending the listener one of the messages defined in the
- * <code>ShellListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ShellListener
- * @see #removeShellListener
- */
-public void addShellListener (ShellListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Close,typedListener);
- addListener (SWT.Iconify,typedListener);
- addListener (SWT.Deiconify,typedListener);
- addListener (SWT.Activate, typedListener);
- addListener (SWT.Deactivate, typedListener);
-}
-
-void addToolTip (ToolTip toolTip) {
- if (toolTips == null) toolTips = new ToolTip [4];
- for (int i=0; i<toolTips.length; i++) {
- if (toolTips [i] == null) {
- toolTips [i] = toolTip;
- return;
- }
- }
- ToolTip [] newToolTips = new ToolTip [toolTips.length + 4];
- newToolTips [toolTips.length] = toolTip;
- System.arraycopy (toolTips, 0, newToolTips, 0, toolTips.length);
- toolTips = newToolTips;
-}
-
-void adjustTrim () {
- if (display.ignoreTrim) return;
- int width = OS.GTK_WIDGET_WIDTH (shellHandle);
- int height = OS.GTK_WIDGET_HEIGHT (shellHandle);
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle);
- GdkRectangle rect = new GdkRectangle ();
- OS.gdk_window_get_frame_extents (window, rect);
- int trimWidth = Math.max (0, rect.width - width);
- int trimHeight = Math.max (0, rect.height - height);
- /*
- * Bug in GTK. gdk_window_get_frame_extents() fails for various window
- * managers, causing a large incorrect value to be returned as the trim.
- * The fix is to ignore the returned trim values if they are too large.
- */
- if (trimWidth > MAXIMUM_TRIM || trimHeight > MAXIMUM_TRIM) {
- display.ignoreTrim = true;
- return;
- }
- boolean hasTitle = false, hasResize = false, hasBorder = false;
- if ((style & SWT.NO_TRIM) == 0) {
- hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0;
- hasResize = (style & SWT.RESIZE) != 0;
- hasBorder = (style & SWT.BORDER) != 0;
- }
- if (hasTitle) {
- if (hasResize) {
- display.titleResizeTrimWidth = trimWidth;
- display.titleResizeTrimHeight = trimHeight;
- return;
- }
- if (hasBorder) {
- display.titleBorderTrimWidth = trimWidth;
- display.titleBorderTrimHeight = trimHeight;
- return;
- }
- display.titleTrimWidth = trimWidth;
- display.titleTrimHeight = trimHeight;
- return;
- }
- if (hasResize) {
- display.resizeTrimWidth = trimWidth;
- display.resizeTrimHeight = trimHeight;
- return;
- }
- if (hasBorder) {
- display.borderTrimWidth = trimWidth;
- display.borderTrimHeight = trimHeight;
- return;
- }
-}
-
-void bringToTop (boolean force) {
- if (!OS.GTK_WIDGET_VISIBLE (shellHandle)) return;
- Display display = this.display;
- Shell activeShell = display.activeShell;
- if (activeShell == this) return;
- if (!force) {
- if (activeShell == null) return;
- if (!display.activePending) {
- int /*long*/ focusHandle = OS.gtk_window_get_focus (activeShell.shellHandle);
- if (focusHandle != 0 && !OS.GTK_WIDGET_HAS_FOCUS (focusHandle)) return;
- }
- }
- /*
- * Bug in GTK. When a shell that is not managed by the window
- * manage is given focus, GTK gets stuck in "focus follows pointer"
- * mode when the pointer is within the shell and its parent when
- * the shell is hidden or disposed. The fix is to use XSetInputFocus()
- * to assign focus when ever the active shell has not managed by
- * the window manager.
- *
- * NOTE: This bug is fixed in GTK+ 2.6.8 and above.
- */
- boolean xFocus = false;
- if (activeShell != null) {
- if (OS.GTK_VERSION < OS.VERSION (2, 6, 8)) {
- xFocus = activeShell.isUndecorated ();
- }
- display.activeShell = null;
- display.activePending = true;
- }
- /*
- * Feature in GTK. When the shell is an override redirect
- * window, gdk_window_focus() does not give focus to the
- * window. The fix is to use XSetInputFocus() to force
- * the focus.
- */
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle);
- if ((xFocus || (style & SWT.ON_TOP) != 0) && OS.GDK_WINDOWING_X11 ()) {
- int /*long*/ xDisplay = OS.gdk_x11_drawable_get_xdisplay (window);
- int /*long*/ xWindow = OS.gdk_x11_drawable_get_xid (window);
- OS.gdk_error_trap_push ();
- /* Use CurrentTime instead of the last event time to ensure that the shell becomes active */
- OS.XSetInputFocus (xDisplay, xWindow, OS.RevertToParent, OS.CurrentTime);
- OS.gdk_error_trap_pop ();
- } else {
- /*
- * Bug in metacity. Calling gdk_window_focus() with a timestamp more
- * recent than the last user interaction time can cause windows not
- * to come forward in versions > 2.10.0. The fix is to use the last
- * user event time.
- */
- if (display.windowManager.toLowerCase ().equals ("metacity")) {
- OS.gdk_window_focus (window, display.lastUserEventTime);
- } else {
- OS.gdk_window_focus (window, OS.GDK_CURRENT_TIME);
- }
- }
- display.activeShell = this;
- display.activePending = true;
-}
-
-void center () {
- if (parent == null) return;
- Rectangle rect = getBounds ();
- Rectangle parentRect = display.map (parent, null, parent.getClientArea());
- int x = Math.max (parentRect.x, parentRect.x + (parentRect.width - rect.width) / 2);
- int y = Math.max (parentRect.y, parentRect.y + (parentRect.height - rect.height) / 2);
- Rectangle monitorRect = parent.getMonitor ().getClientArea();
- if (x + rect.width > monitorRect.x + monitorRect.width) {
- x = Math.max (monitorRect.x, monitorRect.x + monitorRect.width - rect.width);
- } else {
- x = Math.max (x, monitorRect.x);
- }
- if (y + rect.height > monitorRect.y + monitorRect.height) {
- y = Math.max (monitorRect.y, monitorRect.y + monitorRect.height - rect.height);
- } else {
- y = Math.max (y, monitorRect.y);
- }
- setLocation (x, y);
-}
-
-void checkBorder () {
- /* Do nothing */
-}
-
-void checkOpen () {
- if (!opened) resized = false;
-}
-
-int /*long*/ childStyle () {
- return 0;
-}
-
-/**
- * Requests that the window manager close the receiver in
- * the same way it would be closed when the user clicks on
- * the "close box" or performs some other platform specific
- * key or mouse combination that indicates the window
- * should be removed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#Close
- * @see #dispose
- */
-public void close () {
- checkWidget ();
- closeWidget ();
-}
-void closeWidget () {
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- if (event.doit && !isDisposed ()) dispose ();
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- Rectangle trim = super.computeTrim (x, y, width, height);
- int border = 0;
- if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) {
- border = OS.gtk_container_get_border_width (shellHandle);
- }
- int trimWidth = trimWidth (), trimHeight = trimHeight ();
- trim.x -= (trimWidth / 2) + border;
- trim.y -= trimHeight - (trimWidth / 2) + border;
- trim.width += trimWidth + border * 2;
- trim.height += trimHeight + border * 2;
- if (menuBar != null) {
- forceResize ();
- int menuBarHeight = OS.GTK_WIDGET_HEIGHT (menuBar.handle);
- trim.y -= menuBarHeight;
- trim.height += menuBarHeight;
- }
- return trim;
-}
-
-void createHandle (int index) {
- state |= HANDLE | CANVAS;
- if (shellHandle == 0) {
- if (handle == 0) {
- int type = OS.GTK_WINDOW_TOPLEVEL;
- if ((style & SWT.ON_TOP) != 0) type = OS.GTK_WINDOW_POPUP;
- shellHandle = OS.gtk_window_new (type);
- } else {
- shellHandle = OS.gtk_plug_new (handle);
- }
- if (shellHandle == 0) error (SWT.ERROR_NO_HANDLES);
- if (parent != null) {
- OS.gtk_window_set_transient_for (shellHandle, parent.topHandle ());
- OS.gtk_window_set_destroy_with_parent (shellHandle, true);
- if (!isUndecorated ()) {
- OS.gtk_window_set_type_hint (shellHandle, OS.GDK_WINDOW_TYPE_HINT_DIALOG);
- } else {
- if (OS.GTK_VERSION >= OS.VERSION (2, 2, 0)) {
- OS.gtk_window_set_skip_taskbar_hint (shellHandle, true);
- }
- }
- }
- /*
- * Feature in GTK. The window size must be set when the window
- * is created or it will not be allowed to be resized smaller that the
- * initial size by the user. The fix is to set the size to zero.
- */
- if ((style & SWT.RESIZE) != 0) {
- OS.gtk_widget_set_size_request (shellHandle, 0, 0);
- OS.gtk_window_set_resizable (shellHandle, true);
- } else {
- OS.gtk_window_set_resizable (shellHandle, false);
- }
- vboxHandle = OS.gtk_vbox_new (false, 0);
- if (vboxHandle == 0) error (SWT.ERROR_NO_HANDLES);
- createHandle (index, false, true);
- OS.gtk_container_add (vboxHandle, scrolledHandle);
- OS.gtk_box_set_child_packing (vboxHandle, scrolledHandle, true, true, 0, OS.GTK_PACK_END);
- OS.gtk_window_set_title (shellHandle, new byte [1]);
- if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) {
- OS.gtk_container_set_border_width (shellHandle, 1);
- GdkColor color = new GdkColor ();
- OS.gtk_style_get_black (OS.gtk_widget_get_style (shellHandle), color);
- OS.gtk_widget_modify_bg (shellHandle, OS.GTK_STATE_NORMAL, color);
- }
- } else {
- vboxHandle = OS.gtk_bin_get_child (shellHandle);
- if (vboxHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ children = OS.gtk_container_get_children (vboxHandle);
- if (OS.g_list_length (children) > 0) {
- scrolledHandle = OS.g_list_data (children);
- }
- OS.g_list_free (children);
- if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
- handle = OS.gtk_bin_get_child (scrolledHandle);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- }
- group = OS.gtk_window_group_new ();
- if (group == 0) error (SWT.ERROR_NO_HANDLES);
- /*
- * Feature in GTK. Realizing the shell triggers a size allocate event,
- * which may be confused for a resize event from the window manager if
- * received too late. The fix is to realize the window during creation
- * to avoid confusion.
- */
- OS.gtk_widget_realize (shellHandle);
-}
-
-int /*long*/ filterProc (int /*long*/ xEvent, int /*long*/ gdkEvent, int /*long*/ data2) {
- int eventType = OS.X_EVENT_TYPE (xEvent);
- if (eventType != OS.FocusOut && eventType != OS.FocusIn) return 0;
- XFocusChangeEvent xFocusEvent = new XFocusChangeEvent();
- OS.memmove (xFocusEvent, xEvent, XFocusChangeEvent.sizeof);
- switch (eventType) {
- case OS.FocusIn:
- if (xFocusEvent.mode == OS.NotifyNormal || xFocusEvent.mode == OS.NotifyWhileGrabbed) {
- switch (xFocusEvent.detail) {
- case OS.NotifyNonlinear:
- case OS.NotifyNonlinearVirtual:
- case OS.NotifyAncestor:
- if (tooltipsHandle != 0) OS.gtk_tooltips_enable (tooltipsHandle);
- display.activeShell = this;
- display.activePending = false;
- sendEvent (SWT.Activate);
- break;
- }
- }
- break;
- case OS.FocusOut:
- if (xFocusEvent.mode == OS.NotifyNormal || xFocusEvent.mode == OS.NotifyWhileGrabbed) {
- switch (xFocusEvent.detail) {
- case OS.NotifyNonlinear:
- case OS.NotifyNonlinearVirtual:
- case OS.NotifyVirtual:
- if (tooltipsHandle != 0) OS.gtk_tooltips_disable (tooltipsHandle);
- Display display = this.display;
- sendEvent (SWT.Deactivate);
- setActiveControl (null);
- if (display.activeShell == this) {
- display.activeShell = null;
- display.activePending = false;
- }
- break;
- }
- }
- break;
- }
- return 0;
-}
-
-Control findBackgroundControl () {
- return (state & BACKGROUND) != 0 || backgroundImage != null ? this : null;
-}
-
-Composite findDeferredControl () {
- return layoutCount > 0 ? this : null;
-}
-
-boolean hasBorder () {
- return false;
-}
-
-void hookEvents () {
- super.hookEvents ();
- OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [KEY_PRESS_EVENT], 0, display.closures [KEY_PRESS_EVENT], false);
- OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [WINDOW_STATE_EVENT], 0, display.closures [WINDOW_STATE_EVENT], false);
- OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [SIZE_ALLOCATE], 0, display.closures [SIZE_ALLOCATE], false);
- OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [CONFIGURE_EVENT], 0, display.closures [CONFIGURE_EVENT], false);
- OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [DELETE_EVENT], 0, display.closures [DELETE_EVENT], false);
- OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [MAP_EVENT], 0, display.shellMapProcClosure, false);
- OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false);
- OS.g_signal_connect_closure (shellHandle, OS.move_focus, display.closures [MOVE_FOCUS], false);
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle);
- OS.gdk_window_add_filter (window, display.filterProc, shellHandle);
-}
-
-public boolean isEnabled () {
- checkWidget ();
- return getEnabled ();
-}
-
-boolean isUndecorated () {
- return
- (style & (SWT.SHELL_TRIM | SWT.BORDER)) == SWT.NONE ||
- (style & (SWT.NO_TRIM | SWT.ON_TOP)) != 0;
-}
-
-public boolean isVisible () {
- checkWidget();
- return getVisible ();
-}
-
-void register () {
- super.register ();
- display.addWidget (shellHandle, this);
-}
-
-void releaseParent () {
- /* Do nothing */
-}
-
-int /*long*/ topHandle () {
- return shellHandle;
-}
-
-void fixActiveShell () {
- if (display.activeShell == this) {
- Shell shell = null;
- if (parent != null && parent.isVisible ()) shell = parent.getShell ();
- if (shell == null && isUndecorated ()) {
- Shell [] shells = display.getShells ();
- for (int i = 0; i < shells.length; i++) {
- if (shells [i] != null && shells [i].isVisible ()) {
- shell = shells [i];
- break;
- }
- }
- }
- if (shell != null) shell.bringToTop (false);
- }
-}
-
-void fixShell (Shell newShell, Control control) {
- if (this == newShell) return;
- if (control == lastActive) setActiveControl (null);
- String toolTipText = control.toolTipText;
- if (toolTipText != null) {
- control.setToolTipText (this, null);
- control.setToolTipText (newShell, toolTipText);
- }
-}
-
-int /*long*/ fixedSizeAllocateProc(int /*long*/ widget, int /*long*/ allocationPtr) {
- int clientWidth = 0;
- if ((style & SWT.MIRRORED) != 0) clientWidth = getClientWidth ();
- int /*long*/ result = super.fixedSizeAllocateProc (widget, allocationPtr);
- if ((style & SWT.MIRRORED) != 0) moveChildren (clientWidth);
- return result;
-}
-
-void fixStyle (int /*long*/ handle) {
-}
-
-void forceResize () {
- forceResize (OS.GTK_WIDGET_WIDTH (vboxHandle), OS.GTK_WIDGET_HEIGHT (vboxHandle));
-}
-
-void forceResize (int width, int height) {
- GtkRequisition requisition = new GtkRequisition ();
- OS.gtk_widget_size_request (vboxHandle, requisition);
- GtkAllocation allocation = new GtkAllocation ();
- int border = OS.gtk_container_get_border_width (shellHandle);
- allocation.x = border;
- allocation.y = border;
- allocation.width = width;
- allocation.height = height;
- OS.gtk_widget_size_allocate (vboxHandle, allocation);
-}
-
-/**
- * Returns the receiver's alpha value. The alpha value
- * is between 0 (transparent) and 255 (opaque).
- *
- * @return the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public int getAlpha () {
- checkWidget ();
- if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0)) {
- if (OS.gtk_widget_is_composited (shellHandle)) {
- return (int) (OS.gtk_window_get_opacity (shellHandle) * 255);
- }
- }
- return 255;
-}
-
-/**
- * Returns <code>true</code> if the receiver is currently
- * in fullscreen state, and false otherwise.
- * <p>
- *
- * @return the fullscreen state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getFullScreen () {
- checkWidget();
- return fullScreen;
-}
-
-public Point getLocation () {
- checkWidget ();
- int [] x = new int [1], y = new int [1];
- OS.gtk_window_get_position (shellHandle, x,y);
- return new Point (x [0], y [0]);
-}
-
-public boolean getMaximized () {
- checkWidget();
- return !fullScreen && super.getMaximized ();
-}
-
-/**
- * Returns a point describing the minimum receiver's size. The
- * x coordinate of the result is the minimum width of the receiver.
- * The y coordinate of the result is the minimum height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Point getMinimumSize () {
- checkWidget ();
- int width = Math.max (1, minWidth + trimWidth ());
- int height = Math.max (1, minHeight + trimHeight ());
- return new Point (width, height);
-}
-
-Shell getModalShell () {
- Shell shell = null;
- Shell [] modalShells = display.modalShells;
- if (modalShells != null) {
- int bits = SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- int index = modalShells.length;
- while (--index >= 0) {
- Shell modal = modalShells [index];
- if (modal != null) {
- if ((modal.style & bits) != 0) {
- Control control = this;
- while (control != null) {
- if (control == modal) break;
- control = control.parent;
- }
- if (control != modal) return modal;
- break;
- }
- if ((modal.style & SWT.PRIMARY_MODAL) != 0) {
- if (shell == null) shell = getShell ();
- if (modal.parent == shell) return modal;
- }
- }
- }
- }
- return null;
-}
-
-/**
- * Gets the receiver's modified state.
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.5
- */
-public boolean getModified () {
- checkWidget ();
- return modified;
-}
-
-public Point getSize () {
- checkWidget ();
- int width = OS.GTK_WIDGET_WIDTH (vboxHandle);
- int height = OS.GTK_WIDGET_HEIGHT (vboxHandle);
- int border = 0;
- if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) {
- border = OS.gtk_container_get_border_width (shellHandle);
- }
- return new Point (width + trimWidth () + 2*border, height + trimHeight () + 2*border);
-}
-
-public boolean getVisible () {
- checkWidget();
- return OS.GTK_WIDGET_VISIBLE (shellHandle);
-}
-
-/**
- * Returns the region that defines the shape of the shell,
- * or null if the shell has the default shape.
- *
- * @return the region that defines the shape of the shell (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public Region getRegion () {
- /* This method is needed for @since 3.0 Javadoc */
- checkWidget ();
- return region;
-}
-
-/**
- * Returns the receiver's input method editor mode. This
- * will be the result of bitwise OR'ing together one or
- * more of the following constants defined in class
- * <code>SWT</code>:
- * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>,
- * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>.
- *
- * @return the IME mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public int getImeInputMode () {
- checkWidget();
- return SWT.NONE;
-}
-
-Shell _getShell () {
- return this;
-}
-/**
- * Returns an array containing all shells which are
- * descendants of the receiver.
- * <p>
- * @return the dialog shells
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Shell [] getShells () {
- checkWidget();
- int count = 0;
- Shell [] shells = display.getShells ();
- for (int i=0; i<shells.length; i++) {
- Control shell = shells [i];
- do {
- shell = shell.getParent ();
- } while (shell != null && shell != this);
- if (shell == this) count++;
- }
- int index = 0;
- Shell [] result = new Shell [count];
- for (int i=0; i<shells.length; i++) {
- Control shell = shells [i];
- do {
- shell = shell.getParent ();
- } while (shell != null && shell != this);
- if (shell == this) {
- result [index++] = shells [i];
- }
- }
- return result;
-}
-
-int /*long*/ gtk_configure_event (int /*long*/ widget, int /*long*/ event) {
- int [] x = new int [1], y = new int [1];
- OS.gtk_window_get_position (shellHandle, x, y);
- if (!moved || oldX != x [0] || oldY != y [0]) {
- moved = true;
- oldX = x [0];
- oldY = y [0];
- sendEvent (SWT.Move);
- // widget could be disposed at this point
- }
- return 0;
-}
-
-int /*long*/ gtk_delete_event (int /*long*/ widget, int /*long*/ event) {
- if (isEnabled()) closeWidget ();
- return 1;
-}
-
-int /*long*/ gtk_enter_notify_event (int /*long*/ widget, int /*long*/ event) {
- if (widget != shellHandle) {
- return super.gtk_enter_notify_event (widget, event);
- }
- return 0;
-}
-
-int /*long*/ gtk_focus (int /*long*/ widget, int /*long*/ directionType) {
- switch ((int)/*64*/directionType) {
- case OS.GTK_DIR_TAB_FORWARD:
- case OS.GTK_DIR_TAB_BACKWARD:
- Control control = display.getFocusControl ();
- if (control != null) {
- if ((control.state & CANVAS) != 0 && (control.style & SWT.EMBEDDED) != 0) {
- int traversal = directionType == OS.GTK_DIR_TAB_FORWARD ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS;
- control.traverse (traversal);
- return 1;
- }
- }
- break;
- }
- return super.gtk_focus (widget, directionType);
-}
-
-int /*long*/ gtk_move_focus (int /*long*/ widget, int /*long*/ directionType) {
- Control control = display.getFocusControl ();
- if (control != null) {
- int /*long*/ focusHandle = control.focusHandle ();
- OS.gtk_widget_child_focus (focusHandle, (int)/*64*/directionType);
- }
- OS.g_signal_stop_emission_by_name (shellHandle, OS.move_focus);
- return 1;
-}
-
-int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) {
- /* Stop menu mnemonics when the shell is disabled */
- if (widget == shellHandle) {
- return (state & DISABLED) != 0 ? 1 : 0;
- }
- return super.gtk_key_press_event (widget, event);
-}
-
-int /*long*/ gtk_size_allocate (int /*long*/ widget, int /*long*/ allocation) {
- int width = OS.GTK_WIDGET_WIDTH (shellHandle);
- int height = OS.GTK_WIDGET_HEIGHT (shellHandle);
- if (!resized || oldWidth != width || oldHeight != height) {
- oldWidth = width;
- oldHeight = height;
- resizeBounds (width, height, true);
- }
- return 0;
-}
-
-int /*long*/ gtk_realize (int /*long*/ widget) {
- int /*long*/ result = super.gtk_realize (widget);
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle);
- if ((style & SWT.SHELL_TRIM) != SWT.SHELL_TRIM) {
- int decorations = 0;
- if ((style & SWT.NO_TRIM) == 0) {
- if ((style & SWT.MIN) != 0) decorations |= OS.GDK_DECOR_MINIMIZE;
- if ((style & SWT.MAX) != 0) decorations |= OS.GDK_DECOR_MAXIMIZE;
- if ((style & SWT.RESIZE) != 0) decorations |= OS.GDK_DECOR_RESIZEH;
- if ((style & SWT.BORDER) != 0) decorations |= OS.GDK_DECOR_BORDER;
- if ((style & SWT.MENU) != 0) decorations |= OS.GDK_DECOR_MENU;
- if ((style & SWT.TITLE) != 0) decorations |= OS.GDK_DECOR_TITLE;
- /*
- * Feature in GTK. Under some Window Managers (Sawmill), in order
- * to get any border at all from the window manager it is necessary to
- * set GDK_DECOR_BORDER. The fix is to force these bits when any
- * kind of border is requested.
- */
- if ((style & SWT.RESIZE) != 0) decorations |= OS.GDK_DECOR_BORDER;
- }
- OS.gdk_window_set_decorations (window, decorations);
- }
- if ((style & SWT.ON_TOP) != 0) {
- OS.gdk_window_set_override_redirect (window, true);
- }
- return result;
-}
-
-int /*long*/ gtk_window_state_event (int /*long*/ widget, int /*long*/ event) {
- GdkEventWindowState gdkEvent = new GdkEventWindowState ();
- OS.memmove (gdkEvent, event, GdkEventWindowState.sizeof);
- minimized = (gdkEvent.new_window_state & OS.GDK_WINDOW_STATE_ICONIFIED) != 0;
- maximized = (gdkEvent.new_window_state & OS.GDK_WINDOW_STATE_MAXIMIZED) != 0;
- fullScreen = (gdkEvent.new_window_state & OS.GDK_WINDOW_STATE_FULLSCREEN) != 0;
- if ((gdkEvent.changed_mask & OS.GDK_WINDOW_STATE_ICONIFIED) != 0) {
- if (minimized) {
- sendEvent (SWT.Iconify);
- } else {
- sendEvent (SWT.Deiconify);
- }
- updateMinimized (minimized);
- }
- return 0;
-}
-
-/**
- * Moves the receiver to the top of the drawing order for
- * the display on which it was created (so that all other
- * shells on that display, which are not the receiver's
- * children will be drawn behind it), marks it visible,
- * sets the focus and asks the window manager to make the
- * shell active.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#setActive
- * @see Shell#forceActive
- */
-public void open () {
- checkWidget ();
- bringToTop (false);
- setVisible (true);
- if (isDisposed ()) return;
- if (!restoreFocus () && !traverseGroup (true)) setFocus ();
-}
-
-public boolean print (GC gc) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- return false;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when operations are performed on the receiver.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ShellListener
- * @see #addShellListener
- */
-public void removeShellListener (ShellListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Close, listener);
- eventTable.unhook (SWT.Iconify,listener);
- eventTable.unhook (SWT.Deiconify,listener);
- eventTable.unhook (SWT.Activate, listener);
- eventTable.unhook (SWT.Deactivate, listener);
-}
-
-void removeTooTip (ToolTip toolTip) {
- if (toolTips == null) return;
- for (int i=0; i<toolTips.length; i++) {
- if (toolTips [i] == toolTip) {
- toolTips [i] = null;
- return;
- }
- }
-}
-
-/**
- * If the receiver is visible, moves it to the top of the
- * drawing order for the display on which it was created
- * (so that all other shells on that display, which are not
- * the receiver's children will be drawn behind it) and asks
- * the window manager to make the shell active
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#open
- * @see Shell#setActive
- */
-public void setActive () {
- checkWidget ();
- bringToTop (false);
-}
-
-void setActiveControl (Control control) {
- if (control != null && control.isDisposed ()) control = null;
- if (lastActive != null && lastActive.isDisposed ()) lastActive = null;
- if (lastActive == control) return;
-
- /*
- * Compute the list of controls to be activated and
- * deactivated by finding the first common parent
- * control.
- */
- Control [] activate = (control == null) ? new Control[0] : control.getPath ();
- Control [] deactivate = (lastActive == null) ? new Control[0] : lastActive.getPath ();
- lastActive = control;
- int index = 0, length = Math.min (activate.length, deactivate.length);
- while (index < length) {
- if (activate [index] != deactivate [index]) break;
- index++;
- }
-
- /*
- * It is possible (but unlikely), that application
- * code could have destroyed some of the widgets. If
- * this happens, keep processing those widgets that
- * are not disposed.
- */
- for (int i=deactivate.length-1; i>=index; --i) {
- if (!deactivate [i].isDisposed ()) {
- deactivate [i].sendEvent (SWT.Deactivate);
- }
- }
- for (int i=activate.length-1; i>=index; --i) {
- if (!activate [i].isDisposed ()) {
- activate [i].sendEvent (SWT.Activate);
- }
- }
-}
-
-/**
- * Sets the receiver's alpha value which must be
- * between 0 (transparent) and 255 (opaque).
- * <p>
- * This operation requires the operating system's advanced
- * widgets subsystem which may not be available on some
- * platforms.
- * </p>
- * @param alpha the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setAlpha (int alpha) {
- checkWidget ();
- if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0)) {
- if (OS.gtk_widget_is_composited (shellHandle)) {
- alpha &= 0xFF;
- OS.gtk_window_set_opacity (shellHandle, alpha / 255f);
- }
- }
-}
-
-void resizeBounds (int width, int height, boolean notify) {
- if (redrawWindow != 0) {
- OS.gdk_window_resize (redrawWindow, width, height);
- }
- if (enableWindow != 0) {
- OS.gdk_window_resize (enableWindow, width, height);
- }
- int border = OS.gtk_container_get_border_width (shellHandle);
- int boxWidth = width - 2*border;
- int boxHeight = height - 2*border;
- OS.gtk_widget_set_size_request (vboxHandle, boxWidth, boxHeight);
- forceResize (boxWidth, boxHeight);
- if (notify) {
- resized = true;
- sendEvent (SWT.Resize);
- if (isDisposed ()) return;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
- }
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- if (fullScreen) setFullScreen (false);
- /*
- * Bug in GTK. When either of the location or size of
- * a shell is changed while the shell is maximized, the
- * shell is moved to (0, 0). The fix is to explicitly
- * unmaximize the shell before setting the bounds to
- * anything different from the current bounds.
- */
- if (getMaximized ()) {
- Rectangle rect = getBounds ();
- boolean sameOrigin = !move || (rect.x == x && rect.y == y);
- boolean sameExtent = !resize || (rect.width == width && rect.height == height);
- if (sameOrigin && sameExtent) return 0;
- setMaximized (false);
- }
- int result = 0;
- if (move) {
- int [] x_pos = new int [1], y_pos = new int [1];
- OS.gtk_window_get_position (shellHandle, x_pos, y_pos);
- OS.gtk_window_move (shellHandle, x, y);
- if (x_pos [0] != x || y_pos [0] != y) {
- moved = true;
- oldX = x;
- oldY = y;
- sendEvent (SWT.Move);
- if (isDisposed ()) return 0;
- result |= MOVED;
- }
- }
- if (resize) {
- width = Math.max (1, Math.max (minWidth, width - trimWidth ()));
- height = Math.max (1, Math.max (minHeight, height - trimHeight ()));
- if ((style & SWT.RESIZE) != 0) OS.gtk_window_resize (shellHandle, width, height);
- boolean changed = width != oldWidth || height != oldHeight;
- if (changed) {
- oldWidth = width;
- oldHeight = height;
- result |= RESIZED;
- }
- resizeBounds (width, height, changed);
- }
- return result;
-}
-
-void setCursor (int /*long*/ cursor) {
- if (enableWindow != 0) {
- OS.gdk_window_set_cursor (enableWindow, cursor);
- if (!OS.GDK_WINDOWING_X11 ()) {
- OS.gdk_flush ();
- } else {
- int /*long*/ xDisplay = OS.GDK_DISPLAY ();
- OS.XFlush (xDisplay);
- }
- }
- super.setCursor (cursor);
-}
-
-public void setEnabled (boolean enabled) {
- checkWidget();
- if (((state & DISABLED) == 0) == enabled) return;
- Display display = this.display;
- Control control = null;
- boolean fixFocus = false;
- if (!enabled) {
- if (display.focusEvent != SWT.FocusOut) {
- control = display.getFocusControl ();
- fixFocus = isFocusAncestor (control);
- }
- }
- if (enabled) {
- state &= ~DISABLED;
- } else {
- state |= DISABLED;
- }
- enableWidget (enabled);
- if (isDisposed ()) return;
- if (enabled) {
- if (enableWindow != 0) {
- OS.gdk_window_set_user_data (enableWindow, 0);
- OS.gdk_window_destroy (enableWindow);
- enableWindow = 0;
- }
- } else {
- int /*long*/ parentHandle = shellHandle;
- OS.gtk_widget_realize (parentHandle);
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (parentHandle);
- Rectangle rect = getBounds ();
- GdkWindowAttr attributes = new GdkWindowAttr ();
- attributes.width = rect.width;
- attributes.height = rect.height;
- attributes.event_mask = (0xFFFFFFFF & ~OS.ExposureMask);
- attributes.wclass = OS.GDK_INPUT_ONLY;
- attributes.window_type = OS.GDK_WINDOW_CHILD;
- enableWindow = OS.gdk_window_new (window, attributes, 0);
- if (enableWindow != 0) {
- if (cursor != null) {
- OS.gdk_window_set_cursor (enableWindow, cursor.handle);
- if (!OS.GDK_WINDOWING_X11 ()) {
- OS.gdk_flush ();
- } else {
- int /*long*/ xDisplay = OS.GDK_DISPLAY ();
- OS.XFlush (xDisplay);
- }
- }
- OS.gdk_window_set_user_data (enableWindow, parentHandle);
- OS.gdk_window_show (enableWindow);
- }
- }
- if (fixFocus) fixFocus (control);
- if (enabled && display.activeShell == this) {
- if (!restoreFocus ()) traverseGroup (false);
- }
-}
-
-/**
- * Sets the full screen state of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the full screen state, and if the argument is
- * <code>false</code> and the receiver was previously switched
- * into full screen state, causes the receiver to switch back
- * to either the maximized or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setFullScreen(true)</code>,
- * <code>setMaximized(true)</code> and <code>setMinimized(true)</code> will
- * vary by platform. Typically, the behavior will match the platform user's
- * expectations, but not always. This should be avoided if possible.
- * </p>
- *
- * @param fullScreen the new fullscreen state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setFullScreen (boolean fullScreen) {
- checkWidget();
- if (fullScreen) {
- OS.gtk_window_fullscreen (shellHandle);
- } else {
- OS.gtk_window_unfullscreen (shellHandle);
- if (maximized) {
- setMaximized (true);
- }
- }
- this.fullScreen = fullScreen;
-}
-
-/**
- * Sets the input method editor mode to the argument which
- * should be the result of bitwise OR'ing together one or more
- * of the following constants defined in class <code>SWT</code>:
- * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>,
- * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>.
- *
- * @param mode the new IME mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public void setImeInputMode (int mode) {
- checkWidget();
-}
-
-void setInitialBounds () {
- if ((state & FOREIGN_HANDLE) != 0) return;
- int width = OS.gdk_screen_width () * 5 / 8;
- int height = OS.gdk_screen_height () * 5 / 8;
- int /*long*/ screen = OS.gdk_screen_get_default ();
- if (screen != 0) {
- if (OS.gdk_screen_get_n_monitors (screen) > 1) {
- int monitorNumber = OS.gdk_screen_get_monitor_at_window (screen, paintWindow ());
- GdkRectangle dest = new GdkRectangle ();
- OS.gdk_screen_get_monitor_geometry (screen, monitorNumber, dest);
- width = dest.width * 5 / 8;
- height = dest.height * 5 / 8;
- }
- }
- if ((style & SWT.RESIZE) != 0) {
- OS.gtk_window_resize (shellHandle, width, height);
- }
- resizeBounds (width, height, false);
-}
-
-public void setMaximized (boolean maximized) {
- checkWidget();
- super.setMaximized (maximized);
- if (maximized) {
- OS.gtk_window_maximize (shellHandle);
- } else {
- OS.gtk_window_unmaximize (shellHandle);
- }
-}
-
-public void setMenuBar (Menu menu) {
- checkWidget();
- if (menuBar == menu) return;
- boolean both = menu != null && menuBar != null;
- if (menu != null) {
- if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR);
- if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
- if (menuBar != null) {
- int /*long*/ menuHandle = menuBar.handle;
- OS.gtk_widget_hide (menuHandle);
- destroyAccelGroup ();
- }
- menuBar = menu;
- if (menuBar != null) {
- int /*long*/ menuHandle = menu.handle;
- OS.gtk_widget_show (menuHandle);
- createAccelGroup ();
- menuBar.addAccelerators (accelGroup);
- }
- int width = OS.GTK_WIDGET_WIDTH (vboxHandle);
- int height = OS.GTK_WIDGET_HEIGHT (vboxHandle);
- resizeBounds (width, height, !both);
-}
-
-public void setMinimized (boolean minimized) {
- checkWidget();
- if (this.minimized == minimized) return;
- super.setMinimized (minimized);
- if (minimized) {
- OS.gtk_window_iconify (shellHandle);
- } else {
- OS.gtk_window_deiconify (shellHandle);
- bringToTop (false);
- }
-}
-
-/**
- * Sets the receiver's minimum size to the size specified by the arguments.
- * If the new minimum size is larger than the current size of the receiver,
- * the receiver is resized to the new minimum size.
- *
- * @param width the new minimum width for the receiver
- * @param height the new minimum height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setMinimumSize (int width, int height) {
- checkWidget ();
- GdkGeometry geometry = new GdkGeometry ();
- minWidth = geometry.min_width = Math.max (width, trimWidth ()) - trimWidth ();
- minHeight = geometry.min_height = Math.max (height, trimHeight ()) - trimHeight ();
- OS.gtk_window_set_geometry_hints (shellHandle, 0, geometry, OS.GDK_HINT_MIN_SIZE);
-}
-
-/**
- * Sets the receiver's minimum size to the size specified by the argument.
- * If the new minimum size is larger than the current size of the receiver,
- * the receiver is resized to the new minimum size.
- *
- * @param size the new minimum size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setMinimumSize (Point size) {
- checkWidget ();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setMinimumSize (size.x, size.y);
-}
-
-/**
- * Sets the receiver's modified state as specified by the argument.
- *
- * @param modified the new modified state for the receiver
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.5
- */
-public void setModified (boolean modified) {
- checkWidget ();
- this.modified = modified;
-}
-
-/**
- * Sets the shape of the shell to the region specified
- * by the argument. When the argument is null, the
- * default shape of the shell is restored. The shell
- * must be created with the style SWT.NO_TRIM in order
- * to specify a region.
- *
- * @param region the region that defines the shape of the shell (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public void setRegion (Region region) {
- checkWidget ();
- if ((style & SWT.NO_TRIM) == 0) return;
- super.setRegion (region);
-}
-
-/*
- * Shells are never labelled by other widgets, so no initialization is needed.
- */
-void setRelations() {
-}
-
-public void setText (String string) {
- super.setText (string);
-
- /*
- * GTK bug 82013. For some reason, if the title string
- * is less than 7 bytes long and is not terminated by
- * a space, some window managers occasionally draw
- * garbage after the last character in the title.
- * The fix is to pad the title.
- */
- int length = string.length ();
- char [] chars = new char [Math.max (6, length) + 1];
- string.getChars (0, length , chars, 0);
- for (int i=length; i<chars.length; i++) chars [i] = ' ';
- byte [] buffer = Converter.wcsToMbcs (null, chars, true);
- OS.gtk_window_set_title (shellHandle, buffer);
-}
-
-public void setVisible (boolean visible) {
- checkWidget();
- int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- if ((style & mask) != 0) {
- if (visible) {
- display.setModalShell (this);
- OS.gtk_window_set_modal (shellHandle, true);
- } else {
- display.clearModal (this);
- OS.gtk_window_set_modal (shellHandle, false);
- }
- } else {
- updateModal ();
- }
- showWithParent = visible;
- if ((OS.GTK_WIDGET_MAPPED (shellHandle) == visible)) return;
- if (visible) {
- if (center && !moved) {
- center ();
- if (isDisposed ()) return;
- }
- sendEvent (SWT.Show);
- if (isDisposed ()) return;
-
- /*
- * In order to ensure that the shell is visible
- * and fully painted, dispatch events such as
- * GDK_MAP and GDK_CONFIGURE, until the GDK_MAP
- * event for the shell is received.
- *
- * Note that if the parent is minimized or withdrawn
- * from the desktop, this should not be done since
- * the shell not will be mapped until the parent is
- * unminimized or shown on the desktop.
- */
- OS.gtk_widget_show (shellHandle);
- if (enableWindow != 0) OS.gdk_window_raise (enableWindow);
- if (!OS.GTK_IS_PLUG (shellHandle)) {
- mapped = false;
- if (isDisposed ()) return;
- display.dispatchEvents = new int [] {
- OS.GDK_EXPOSE,
- OS.GDK_FOCUS_CHANGE,
- OS.GDK_CONFIGURE,
- OS.GDK_MAP,
- OS.GDK_UNMAP,
- OS.GDK_NO_EXPOSE,
- };
- Display display = this.display;
- display.putGdkEvents();
- boolean iconic = false;
- Shell shell = parent != null ? parent.getShell() : null;
- do {
- OS.g_main_context_iteration (0, false);
- if (isDisposed ()) break;
- iconic = minimized || (shell != null && shell.minimized);
- } while (!mapped && !iconic);
- display.dispatchEvents = null;
- if (isDisposed ()) return;
- if (!iconic) {
- update (true, true);
- if (isDisposed ()) return;
- adjustTrim ();
- }
- }
- mapped = true;
-
- if ((style & mask) != 0) {
- OS.gdk_pointer_ungrab (OS.GDK_CURRENT_TIME);
- }
- opened = true;
- if (!moved) {
- moved = true;
- Point location = getLocation();
- oldX = location.x;
- oldY = location.y;
- sendEvent (SWT.Move);
- if (isDisposed ()) return;
- }
- if (!resized) {
- resized = true;
- Point size = getSize ();
- oldWidth = size.x - trimWidth ();
- oldHeight = size.y - trimHeight ();
- sendEvent (SWT.Resize);
- if (isDisposed ()) return;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
- }
- } else {
- fixActiveShell ();
- OS.gtk_widget_hide (shellHandle);
- sendEvent (SWT.Hide);
- }
-}
-
-void setZOrder (Control sibling, boolean above, boolean fixRelations) {
- /*
- * Bug in GTK+. Changing the toplevel window Z-order causes
- * X to send a resize event. Before the shell is mapped, these
- * resize events always have a size of 200x200, causing extra
- * layout work to occur. The fix is to modify the Z-order only
- * if the shell has already been mapped at least once.
- */
- /* Shells are never included in labelled-by relations */
- if (mapped) setZOrder (sibling, above, false, false);
-}
-
-int /*long*/ shellMapProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) {
- mapped = true;
- display.dispatchEvents = null;
- return 0;
-}
-
-void showWidget () {
- if ((state & FOREIGN_HANDLE) != 0) return;
- OS.gtk_container_add (shellHandle, vboxHandle);
- if (scrolledHandle != 0) OS.gtk_widget_show (scrolledHandle);
- if (handle != 0) OS.gtk_widget_show (handle);
- if (vboxHandle != 0) OS.gtk_widget_show (vboxHandle);
-}
-
-int /*long*/ sizeAllocateProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) {
- int offset = 16;
- int [] x = new int [1], y = new int [1];
- OS.gdk_window_get_pointer (0, x, y, null);
- y [0] += offset;
- int /*long*/ screen = OS.gdk_screen_get_default ();
- if (screen != 0) {
- int monitorNumber = OS.gdk_screen_get_monitor_at_point (screen, x[0], y[0]);
- GdkRectangle dest = new GdkRectangle ();
- OS.gdk_screen_get_monitor_geometry (screen, monitorNumber, dest);
- int width = OS.GTK_WIDGET_WIDTH (handle);
- int height = OS.GTK_WIDGET_HEIGHT (handle);
- if (x[0] + width > dest.x + dest.width) {
- x [0] = (dest.x + dest.width) - width;
- }
- if (y[0] + height > dest.y + dest.height) {
- y[0] = (dest.y + dest.height) - height;
- }
- }
- OS.gtk_window_move (handle, x [0], y [0]);
- return 0;
-}
-
-int /*long*/ sizeRequestProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) {
- OS.gtk_widget_hide (handle);
- return 0;
-}
-
-boolean traverseEscape () {
- if (parent == null) return false;
- if (!isVisible () || !isEnabled ()) return false;
- close ();
- return true;
-}
-int trimHeight () {
- if ((style & SWT.NO_TRIM) != 0) return 0;
- if (fullScreen) return 0;
- boolean hasTitle = false, hasResize = false, hasBorder = false;
- hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0;
- hasResize = (style & SWT.RESIZE) != 0;
- hasBorder = (style & SWT.BORDER) != 0;
- if (hasTitle) {
- if (hasResize) return display.titleResizeTrimHeight;
- if (hasBorder) return display.titleBorderTrimHeight;
- return display.titleTrimHeight;
- }
- if (hasResize) return display.resizeTrimHeight;
- if (hasBorder) return display.borderTrimHeight;
- return 0;
-}
-
-int trimWidth () {
- if ((style & SWT.NO_TRIM) != 0) return 0;
- if (fullScreen) return 0;
- boolean hasTitle = false, hasResize = false, hasBorder = false;
- hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0;
- hasResize = (style & SWT.RESIZE) != 0;
- hasBorder = (style & SWT.BORDER) != 0;
- if (hasTitle) {
- if (hasResize) return display.titleResizeTrimWidth;
- if (hasBorder) return display.titleBorderTrimWidth;
- return display.titleTrimWidth;
- }
- if (hasResize) return display.resizeTrimWidth;
- if (hasBorder) return display.borderTrimWidth;
- return 0;
-}
-
-void updateModal () {
- int /*long*/ group = 0;
- if (display.getModalDialog () == null) {
- Shell modal = getModalShell ();
- int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- Composite shell = null;
- if (modal == null) {
- if ((style & mask) != 0) shell = this;
- } else {
- shell = modal;
- }
- while (shell != null) {
- if ((shell.style & mask) == 0) {
- group = shell.getShell ().group;
- break;
- }
- shell = shell.parent;
- }
- }
- if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0) && group == 0) {
- /*
- * Feature in GTK. Starting with GTK version 2.10, GTK
- * doesn't assign windows to a default group. The fix is to
- * get the handle of the default group and add windows to the
- * group.
- */
- group = OS.gtk_window_get_group(0);
- }
- if (group != 0) {
- OS.gtk_window_group_add_window (group, shellHandle);
- } else {
- if (modalGroup != 0) {
- OS.gtk_window_group_remove_window (modalGroup, shellHandle);
- }
- }
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) {
- fixModal (group, modalGroup);
- }
- modalGroup = group;
-}
-
-void updateMinimized (boolean minimized) {
- Shell[] shells = getShells ();
- for (int i = 0; i < shells.length; i++) {
- boolean update = false;
- Shell shell = shells[i];
- while (shell != null && shell != this && !shell.isUndecorated ()) {
- shell = (Shell) shell.getParent ();
- }
- if (shell != null && shell != this) update = true;
- if (update) {
- if (minimized) {
- if (shells[i].isVisible ()) {
- shells[i].showWithParent = true;
- OS.gtk_widget_hide(shells[i].shellHandle);
- }
- } else {
- if (shells[i].showWithParent) {
- shells[i].showWithParent = false;
- OS.gtk_widget_show(shells[i].shellHandle);
- }
- }
- }
- }
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (shellHandle);
-}
-
-public void dispose () {
- /*
- * Note: It is valid to attempt to dispose a widget
- * more than once. If this happens, fail silently.
- */
- if (isDisposed()) return;
- fixActiveShell ();
- OS.gtk_widget_hide (shellHandle);
- super.dispose ();
-}
-
-/**
- * If the receiver is visible, moves it to the top of the
- * drawing order for the display on which it was created
- * (so that all other shells on that display, which are not
- * the receiver's children will be drawn behind it) and forces
- * the window manager to make the shell active.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#open
- * @see Shell#setActive
- */
-public void forceActive () {
- checkWidget ();
- bringToTop (true);
-}
-
-public Rectangle getBounds () {
- checkWidget ();
- int [] x = new int [1], y = new int [1];
- OS.gtk_window_get_position (shellHandle, x, y);
- int width = OS.GTK_WIDGET_WIDTH (vboxHandle);
- int height = OS.GTK_WIDGET_HEIGHT (vboxHandle);
- int border = 0;
- if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) {
- border = OS.gtk_container_get_border_width (shellHandle);
- }
- return new Rectangle (x [0], y [0], width + trimWidth () + 2*border, height + trimHeight () + 2*border);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- shellHandle = 0;
-}
-
-void releaseChildren (boolean destroy) {
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (shell != null && !shell.isDisposed ()) {
- shell.release (false);
- }
- }
- if (toolTips != null) {
- for (int i=0; i<toolTips.length; i++) {
- ToolTip toolTip = toolTips [i];
- if (toolTip != null && !toolTip.isDisposed ()) {
- toolTip.dispose ();
- }
- }
- toolTips = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- destroyAccelGroup ();
- display.clearModal (this);
- if (display.activeShell == this) display.activeShell = null;
- if (tooltipsHandle != 0) OS.g_object_unref (tooltipsHandle);
- tooltipsHandle = 0;
- if (group != 0) OS.g_object_unref (group);
- group = modalGroup = 0;
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle);
- OS.gdk_window_remove_filter(window, display.filterProc, shellHandle);
- lastActive = null;
-}
-
-void setToolTipText (int /*long*/ tipWidget, String string) {
- setToolTipText (tipWidget, tipWidget, string);
-}
-
-void setToolTipText (int /*long*/ rootWidget, int /*long*/ tipWidget, String string) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0)) {
- byte [] buffer = null;
- if (string != null && string.length () > 0) {
- char [] chars = fixMnemonic (string, false);
- buffer = Converter.wcsToMbcs (null, chars, true);
- }
- OS.gtk_widget_set_tooltip_text (rootWidget, null);
- /*
- * Bug in GTK. In GTK 2.12, due to a miscalculation of window
- * coordinates, using gtk_tooltip_trigger_tooltip_query ()
- * to update an existing a tooltip will result in the tooltip
- * being displayed at a wrong position. The fix is to send out
- * 2 fake GDK_MOTION_NOTIFY events (to mimic the GTK call) which
- * contain the proper x and y coordinates.
- */
- int /*long*/ eventPtr = 0;
- int /*long*/ tipWindow = OS.GTK_WIDGET_WINDOW (rootWidget);
- if (tipWindow != 0) {
- int [] x = new int [1], y = new int [1];
- int /*long*/ window = OS.gdk_window_at_pointer (x, y);
- int /*long*/ [] user_data = new int /*long*/ [1];
- if (window != 0) OS.gdk_window_get_user_data (window, user_data);
- if (tipWidget == user_data [0]) {
- eventPtr = OS.gdk_event_new (OS.GDK_MOTION_NOTIFY);
- GdkEventMotion event = new GdkEventMotion ();
- event.type = OS.GDK_MOTION_NOTIFY;
- event.window = OS.g_object_ref (tipWindow);
- event.x = x [0];
- event.y = y [0];
- OS.gdk_window_get_origin (window, x, y);
- event.x_root = event.x + x [0];
- event.y_root = event.y + y [0];
- OS.memmove (eventPtr, event, GdkEventMotion.sizeof);
- OS.gtk_main_do_event (eventPtr);
- }
- }
- OS.gtk_widget_set_tooltip_text (rootWidget, buffer);
- if (eventPtr != 0) {
- OS.gtk_main_do_event (eventPtr);
- OS.gdk_event_free (eventPtr);
- }
- } else {
- byte [] buffer = null;
- if (string != null && string.length () > 0) {
- char [] chars = fixMnemonic (string, false);
- buffer = Converter.wcsToMbcs (null, chars, true);
- }
- if (tooltipsHandle == 0) {
- tooltipsHandle = OS.gtk_tooltips_new ();
- if (tooltipsHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.g_object_ref (tooltipsHandle);
- OS.gtk_object_sink (tooltipsHandle);
- }
-
- /*
- * Feature in GTK. There is no API to position a tooltip.
- * The fix is to connect to the size_allocate signal for
- * the tooltip window and position it before it is mapped.
- *
- * Bug in Solaris-GTK. Invoking gtk_tooltips_force_window()
- * can cause a crash in older versions of GTK. The fix is
- * to avoid this call if the GTK version is older than 2.2.x.
- */
- if (OS.GTK_VERSION >= OS.VERSION (2, 2, 1)) {
- OS.gtk_tooltips_force_window (tooltipsHandle);
- }
- int /*long*/ tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (tooltipsHandle);
- if (tipWindow != 0 && tipWindow != tooltipWindow) {
- OS.g_signal_connect (tipWindow, OS.size_allocate, display.sizeAllocateProc, shellHandle);
- tooltipWindow = tipWindow;
- }
-
- /*
- * Bug in GTK. If the cursor is inside the window when a new
- * tooltip is set and the old tooltip is hidden, the new tooltip
- * is not displayed until the mouse re-enters the window. The
- * fix is force the new tooltip to be active.
- */
- boolean set = true;
- if (tipWindow != 0) {
- if ((OS.GTK_WIDGET_FLAGS (tipWidget) & (OS.GTK_REALIZED | OS.GTK_VISIBLE)) != 0) {
- int [] x = new int [1], y = new int [1];
- int /*long*/ window = OS.gdk_window_at_pointer (x, y);
- if (window != 0) {
- int /*long*/ [] user_data = new int /*long*/ [1];
- OS.gdk_window_get_user_data (window, user_data);
- if (tipWidget == user_data [0]) {
- /*
- * Feature in GTK. Calling gtk_tooltips_set_tip() positions and
- * shows the tooltip. If the tooltip is already visible, moving
- * it to a new location in the size_allocate signal causes flashing.
- * The fix is to hide the tip window in the size_request signal
- * and before the new tooltip is forced to be active.
- */
- set = false;
- int handler_id = OS.g_signal_connect (tipWindow, OS.size_request, display.sizeRequestProc, shellHandle);
- OS.gtk_tooltips_set_tip (tooltipsHandle, tipWidget, buffer, null);
- OS.gtk_widget_hide (tipWindow);
- int /*long*/ data = OS.gtk_tooltips_data_get (tipWidget);
- OS.GTK_TOOLTIPS_SET_ACTIVE (tooltipsHandle, data);
- OS.gtk_tooltips_set_tip (tooltipsHandle, tipWidget, buffer, null);
- if (handler_id != 0) OS.g_signal_handler_disconnect (tipWindow, handler_id);
- }
- }
- }
- }
- if (set) OS.gtk_tooltips_set_tip (tooltipsHandle, tipWidget, buffer, null);
- }
-
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java
deleted file mode 100644
index 61d636b946..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java
+++ /dev/null
@@ -1,614 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that represent a range of positive, numeric values.
- * <p>
- * At any given moment, a given slider will have a
- * single 'selection' that is considered to be its
- * value, which is constrained to be within the range of
- * values the slider represents (that is, between its
- * <em>minimum</em> and <em>maximum</em> values).
- * </p><p>
- * Typically, sliders will be made up of five areas:
- * <ol>
- * <li>an arrow button for decrementing the value</li>
- * <li>a page decrement area for decrementing the value by a larger amount</li>
- * <li>a <em>thumb</em> for modifying the value by mouse dragging</li>
- * <li>a page increment area for incrementing the value by a larger amount</li>
- * <li>an arrow button for incrementing the value</li>
- * </ol>
- * Based on their style, sliders are either <code>HORIZONTAL</code>
- * (which have a left facing button for decrementing the value and a
- * right facing button for incrementing it) or <code>VERTICAL</code>
- * (which have an upward facing button for decrementing the value
- * and a downward facing buttons for incrementing it).
- * </p><p>
- * On some platforms, the size of the slider's thumb can be
- * varied relative to the magnitude of the range of values it
- * represents (that is, relative to the difference between its
- * maximum and minimum values). Typically, this is used to
- * indicate some proportional value such as the ratio of the
- * visible area of a document to the total amount of space that
- * it would take to display it. SWT supports setting the thumb
- * size even if the underlying platform does not, but in this
- * case the appearance of the slider will not change.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see ScrollBar
- * @see <a href="http://www.eclipse.org/swt/snippets/#slider">Slider snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Slider extends Control {
- int detail;
- boolean dragSent;
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Slider (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values:
- * <code>SWT.NONE</code> - for the end of a drag.
- * <code>SWT.DRAG</code>.
- * <code>SWT.HOME</code>.
- * <code>SWT.END</code>.
- * <code>SWT.ARROW_DOWN</code>.
- * <code>SWT.ARROW_UP</code>.
- * <code>SWT.PAGE_DOWN</code>.
- * <code>SWT.PAGE_UP</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (fixedHandle, true);
- int /*long*/ hAdjustment = OS.gtk_adjustment_new (0, 0, 100, 1, 10, 10);
- if (hAdjustment == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.HORIZONTAL) != 0) {
- handle = OS.gtk_hscrollbar_new (hAdjustment);
- } else {
- handle = OS.gtk_vscrollbar_new (hAdjustment);
- }
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- /*
- * Bug in GTK. In GTK 2.10, the buttons on either end of
- * a horizontal slider are created taller then the slider bar
- * when the GTK_CAN_FOCUS flag is set. The fix is not to set
- * the flag for horizontal bars in all versions of 2.10. Note
- * that a bug has been logged with GTK about this issue.
- * (http://bugzilla.gnome.org/show_bug.cgi?id=475909)
- */
- if (OS.GTK_VERSION < OS.VERSION (2, 10, 0) || (style & SWT.VERTICAL) != 0) {
- OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS);
- }
- OS.gtk_container_add (fixedHandle, handle);
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ eventPtr) {
- int /*long*/ result = super.gtk_button_press_event (widget, eventPtr);
- if (result != 0) return result;
- detail = OS.GTK_SCROLL_NONE;
- dragSent = false;
- return result;
-}
-
-int /*long*/ gtk_change_value (int /*long*/ widget, int /*long*/ scroll, int /*long*/ value1, int /*long*/ value2) {
- detail = (int)/*64*/scroll;
- return 0;
-}
-
-int /*long*/ gtk_value_changed (int /*long*/ adjustment) {
- Event event = new Event ();
- dragSent = detail == OS.GTK_SCROLL_JUMP;
- switch (detail) {
- case OS.GTK_SCROLL_NONE: event.detail = SWT.NONE; break;
- case OS.GTK_SCROLL_JUMP: event.detail = SWT.DRAG; break;
- case OS.GTK_SCROLL_START: event.detail = SWT.HOME; break;
- case OS.GTK_SCROLL_END: event.detail = SWT.END; break;
- case OS.GTK_SCROLL_PAGE_DOWN:
- case OS.GTK_SCROLL_PAGE_RIGHT:
- case OS.GTK_SCROLL_PAGE_FORWARD: event.detail = SWT.PAGE_DOWN; break;
- case OS.GTK_SCROLL_PAGE_UP:
- case OS.GTK_SCROLL_PAGE_LEFT:
- case OS.GTK_SCROLL_PAGE_BACKWARD: event.detail = SWT.PAGE_UP; break;
- case OS.GTK_SCROLL_STEP_DOWN:
- case OS.GTK_SCROLL_STEP_RIGHT:
- case OS.GTK_SCROLL_STEP_FORWARD: event.detail = SWT.ARROW_DOWN; break;
- case OS.GTK_SCROLL_STEP_UP:
- case OS.GTK_SCROLL_STEP_LEFT:
- case OS.GTK_SCROLL_STEP_BACKWARD: event.detail = SWT.ARROW_UP; break;
- }
- if (!dragSent) detail = OS.GTK_SCROLL_NONE;
- postEvent (SWT.Selection, event);
- return 0;
-}
-
-int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) {
- GdkEvent gtkEvent = new GdkEvent ();
- OS.memmove (gtkEvent, gdkEvent, GdkEvent.sizeof);
- switch (gtkEvent.type) {
- case OS.GDK_BUTTON_RELEASE: {
- GdkEventButton gdkEventButton = new GdkEventButton ();
- OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof);
- if (gdkEventButton.button == 1 && detail == SWT.DRAG) {
- if (!dragSent) {
- Event event = new Event ();
- event.detail = SWT.DRAG;
- postEvent (SWT.Selection, event);
- }
- postEvent (SWT.Selection);
- }
- detail = OS.GTK_SCROLL_NONE;
- dragSent = false;
- break;
- }
- }
- return super.gtk_event_after (widget, gdkEvent);
-}
-
-void hookEvents () {
- super.hookEvents ();
- if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) {
- OS.g_signal_connect_closure (handle, OS.change_value, display.closures [CHANGE_VALUE], false);
- }
- OS.g_signal_connect_closure (handle, OS.value_changed, display.closures [VALUE_CHANGED], false);
-}
-
-void register () {
- super.register ();
- int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle);
- display.addWidget (hAdjustment, this);
-}
-
-void deregister () {
- super.deregister ();
- int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle);
- display.removeWidget (hAdjustment);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- Point size = computeNativeSize(handle, wHint, hHint, changed);
- if ((style & SWT.HORIZONTAL) != 0) {
- if (wHint == SWT.DEFAULT) size.x = 2 * size.x;
- } else {
- if (hHint == SWT.DEFAULT) size.y = 2 * size.y;
- }
- return size;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- return (int) adjustment.step_increment;
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- return (int) adjustment.upper;
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- return (int) adjustment.lower;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- return (int) adjustment.page_increment;
-}
-
-/**
- * Returns the 'selection', which is the receiver's value.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- return (int) adjustment.value;
-}
-
-/**
- * Returns the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values.
- *
- * @return the thumb value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getThumb () {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- return (int) adjustment.page_size;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_range_set_increments (handle, value, getPageIncrement ());
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the maximum. If this value is negative or less than or
- * equal to the minimum, the value is ignored. If necessary, first
- * the thumb and then the selection are adjusted to fit within the
- * new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- int minimum = (int) adjustment.lower;
- if (value <= minimum) return;
- adjustment.upper = value;
- adjustment.page_size = Math.min ((int)adjustment.page_size, value - minimum);
- adjustment.value = Math.min ((int)adjustment.value, (int)(value - adjustment.page_size));
- OS.memmove (hAdjustment, adjustment);
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_adjustment_changed (hAdjustment);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the minimum value. If this value is negative or greater
- * than or equal to the maximum, the value is ignored. If necessary,
- * first the thumb and then the selection are adjusted to fit within
- * the new range.
- *
- * @param value the new minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget ();
- if (value < 0) return;
- int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- int maximum = (int) adjustment.upper;
- if (value >= maximum) return;
- adjustment.lower = value;
- adjustment.page_size = Math.min ((int)adjustment.page_size, maximum - value);
- adjustment.value = Math.max ((int)adjustment.value, value);
- OS.memmove (hAdjustment, adjustment);
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_adjustment_changed (hAdjustment);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-void setOrientation () {
- super.setOrientation ();
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- if ((style & SWT.HORIZONTAL) != 0) {
- OS.gtk_range_set_inverted (handle, true);
- }
- }
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_range_set_increments (handle, getIncrement (), value);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the 'selection', which is the receiver's
- * value, to the argument which must be greater than or equal
- * to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget ();
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_range_set_value (handle, value);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values. This new
- * value will be ignored if it is less than one, and will be
- * clamped if it exceeds the receiver's current range.
- *
- * @param value the new thumb value, which must be at least one and not
- * larger than the size of the current range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setThumb (int value) {
- checkWidget ();
- if (value < 1) return;
- int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- value = (int) Math.min (value, (int)(adjustment.upper - adjustment.lower));
- adjustment.page_size = (double) value;
- adjustment.value = Math.min ((int)adjustment.value, (int)(adjustment.upper - value));
- OS.memmove (hAdjustment, adjustment);
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_adjustment_changed (hAdjustment);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, thumb, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param thumb the new thumb value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- checkWidget ();
- if (minimum < 0) return;
- if (maximum < 0) return;
- if (thumb < 1) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- thumb = Math.min (thumb, maximum - minimum);
- int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- adjustment.value = Math.min (Math.max (selection, minimum), maximum - thumb);
- adjustment.lower = (double) minimum;
- adjustment.upper = (double) maximum;
- adjustment.page_size = (double) thumb;
- adjustment.step_increment = (double) increment;
- adjustment.page_increment = (double) pageIncrement;
- OS.memmove (hAdjustment, adjustment);
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_adjustment_changed (hAdjustment);
- OS.gtk_adjustment_value_changed (hAdjustment);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java
deleted file mode 100644
index b08c147222..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java
+++ /dev/null
@@ -1,1203 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify numeric
- * values.
- * <p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, Modify, Verify</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#spinner">Spinner snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Spinner extends Composite {
- static final int MIN_ARROW_WIDTH = 6;
- int lastEventTime = 0;
- int /*long*/ gdkEventKey = 0;
- int fixStart = -1, fixEnd = -1;
-
- /**
- * the operating system limit for the number of characters
- * that the text field in an instance of this class can hold
- *
- * @since 3.4
- */
- public final static int LIMIT;
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0x7FFFFFFF;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#READ_ONLY
- * @see SWT#WRAP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Spinner (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is not called for texts.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- */
-void addVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-
-static int checkStyle (int style) {
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- int[] w = new int [1], h = new int [1];
- OS.gtk_widget_realize (handle);
- int /*long*/ layout = OS.gtk_entry_get_layout (handle);
- int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- int digits = OS.gtk_spin_button_get_digits (handle);
- for (int i = 0; i < digits; i++) adjustment.upper *= 10;
- String string = String.valueOf ((int) adjustment.upper);
- if (digits > 0) {
- StringBuffer buffer = new StringBuffer ();
- buffer.append (string);
- buffer.append (getDecimalSeparator ());
- int count = digits - string.length ();
- while (count >= 0) {
- buffer.append ("0");
- count--;
- }
- string = buffer.toString ();
- }
- byte [] buffer1 = Converter.wcsToMbcs (null, string, false);
- int /*long*/ ptr = OS.pango_layout_get_text (layout);
- int length = OS.strlen (ptr);
- byte [] buffer2 = new byte [length];
- OS.memmove (buffer2, ptr, length);
- OS.pango_layout_set_text (layout, buffer1, buffer1.length);
- OS.pango_layout_get_size (layout, w, h);
- OS.pango_layout_set_text (layout, buffer2, buffer2.length);
- int width = OS.PANGO_PIXELS (w [0]);
- int height = OS.PANGO_PIXELS (h [0]);
- width = wHint == SWT.DEFAULT ? width : wHint;
- height = hHint == SWT.DEFAULT ? height : hHint;
- Rectangle trim = computeTrim (0, 0, width, height);
- return new Point (trim.width, trim.height);
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
- int xborder = 0, yborder = 0;
- int /*long*/ style = OS.gtk_widget_get_style (handle);
- if ((this.style & SWT.BORDER) != 0) {
- xborder += OS.gtk_style_get_xthickness (style);
- yborder += OS.gtk_style_get_ythickness (style);
- }
- int [] property = new int [1];
- OS.gtk_widget_style_get (handle, OS.interior_focus, property, 0);
- if (property [0] == 0) {
- OS.gtk_widget_style_get (handle, OS.focus_line_width, property, 0);
- xborder += property [0];
- yborder += property [0];
- }
- int /*long*/ fontDesc = OS.gtk_style_get_font_desc (style);
- int fontSize = OS.pango_font_description_get_size (fontDesc);
- int arrowSize = Math.max (OS.PANGO_PIXELS (fontSize), MIN_ARROW_WIDTH);
- arrowSize = arrowSize - arrowSize % 2;
- Rectangle trim = super.computeTrim (x, y, width, height);
- trim.x -= xborder;
- trim.y -= yborder;
- trim.width += 2 * xborder;
- trim.height += 2 * yborder;
- trim.width += arrowSize + (2 * OS.gtk_style_get_xthickness (style));
- GtkBorder innerBorder = Display.getEntryInnerBorder (handle);
- trim.x -= innerBorder.left;
- trim.y -= innerBorder.top;
- trim.width += innerBorder.left + innerBorder.right;
- trim.height += innerBorder.top + innerBorder.bottom;
- return new Rectangle (trim.x, trim.y, trim.width, trim.height);
-}
-
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void copy () {
- checkWidget ();
- OS.gtk_editable_copy_clipboard (handle);
-}
-
-void createHandle (int index) {
- state |= HANDLE | MENU;
- fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (fixedHandle, true);
- int /*long*/ adjustment = OS.gtk_adjustment_new (0, 0, 100, 1, 10, 0);
- if (adjustment == 0) error (SWT.ERROR_NO_HANDLES);
- handle = OS.gtk_spin_button_new (adjustment, 1, 0);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (fixedHandle, handle);
- OS.gtk_editable_set_editable (handle, (style & SWT.READ_ONLY) == 0);
- OS.gtk_entry_set_has_frame (handle, (style & SWT.BORDER) != 0);
- OS.gtk_spin_button_set_wrap (handle, (style & SWT.WRAP) != 0);
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void cut () {
- checkWidget ();
- OS.gtk_editable_cut_clipboard (handle);
-}
-
-void deregister () {
- super.deregister ();
- int /*long*/ imContext = imContext ();
- if (imContext != 0) display.removeWidget (imContext);
-}
-
-int /*long*/ eventWindow () {
- return paintWindow ();
-}
-
-int /*long*/ enterExitHandle () {
- return fixedHandle;
-}
-
-boolean filterKey (int keyval, int /*long*/ event) {
- int time = OS.gdk_event_get_time (event);
- if (time != lastEventTime) {
- lastEventTime = time;
- int /*long*/ imContext = imContext ();
- if (imContext != 0) {
- return OS.gtk_im_context_filter_keypress (imContext, event);
- }
- }
- gdkEventKey = event;
- return false;
-}
-
-void fixIM () {
- /*
- * The IM filter has to be called one time for each key press event.
- * When the IM is open the key events are duplicated. The first event
- * is filtered by SWT and the second event is filtered by GTK. In some
- * cases the GTK handler does not run (the widget is destroyed, the
- * application code consumes the event, etc), for these cases the IM
- * filter has to be called by SWT.
- */
- if (gdkEventKey != 0 && gdkEventKey != -1) {
- int /*long*/ imContext = imContext ();
- if (imContext != 0) {
- OS.gtk_im_context_filter_keypress (imContext, gdkEventKey);
- gdkEventKey = -1;
- return;
- }
- }
- gdkEventKey = 0;
-}
-
-GdkColor getBackgroundColor () {
- return getBaseColor ();
-}
-
-public int getBorderWidth () {
- checkWidget();
- int /*long*/ style = OS.gtk_widget_get_style (handle);
- if ((this.style & SWT.BORDER) != 0) {
- return OS.gtk_style_get_xthickness (style);
- }
- return 0;
-}
-
-GdkColor getForegroundColor () {
- return getTextColor ();
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down arrows are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- int digits = OS.gtk_spin_button_get_digits (handle);
- double value = adjustment.step_increment;
- for (int i = 0; i < digits; i++) value *= 10;
- return (int) (value > 0 ? value + 0.5 : value - 0.5);
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- int digits = OS.gtk_spin_button_get_digits (handle);
- double value = adjustment.upper;
- for (int i = 0; i < digits; i++) value *= 10;
- return (int) (value > 0 ? value + 0.5 : value - 0.5);
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- int digits = OS.gtk_spin_button_get_digits (handle);
- double value = adjustment.lower;
- for (int i = 0; i < digits; i++) value *= 10;
- return (int) (value > 0 ? value + 0.5 : value - 0.5);
-}
-
-/**
- * Returns the amount that the receiver's position will be
- * modified by when the page up/down keys are pressed.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- int digits = OS.gtk_spin_button_get_digits (handle);
- double value = adjustment.page_increment;
- for (int i = 0; i < digits; i++) value *= 10;
- return (int) (value > 0 ? value + 0.5 : value - 0.5);
-}
-
-/**
- * Returns the <em>selection</em>, which is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- int digits = OS.gtk_spin_button_get_digits (handle);
- double value = adjustment.value;
- for (int i = 0; i < digits; i++) value *= 10;
- return (int) (value > 0 ? value + 0.5 : value - 0.5);
-}
-
-/**
- * Returns a string containing a copy of the contents of the
- * receiver's text field, or an empty string if there are no
- * contents.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public String getText () {
- checkWidget ();
- int /*long*/ str = OS.gtk_entry_get_text (handle);
- if (str == 0) return "";
- int length = OS.strlen (str);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, str, length);
- return new String (Converter.mbcsToWcs (null, buffer));
-}
-
-/**
- * Returns the maximum number of characters that the receiver's
- * text field is capable of holding. If this has not been changed
- * by <code>setTextLimit()</code>, it will be the constant
- * <code>Spinner.LIMIT</code>.
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- *
- * @since 3.4
- */
-public int getTextLimit () {
- checkWidget ();
- int limit = OS.gtk_entry_get_max_length (handle);
- return limit == 0 ? 0xFFFF : limit;
-}
-
-/**
- * Returns the number of decimal places used by the receiver.
- *
- * @return the digits
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getDigits () {
- checkWidget ();
- return OS.gtk_spin_button_get_digits (handle);
-}
-
-String getDecimalSeparator () {
- int /*long*/ ptr = OS.localeconv_decimal_point ();
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, length);
- return new String (Converter.mbcsToWcs (null, buffer));
-}
-
-int /*long*/ gtk_activate (int /*long*/ widget) {
- postEvent (SWT.DefaultSelection);
- return 0;
-}
-
-int /*long*/ gtk_changed (int /*long*/ widget) {
- int /*long*/ str = OS.gtk_entry_get_text (handle);
- int length = OS.strlen (str);
- if (length > 0) {
- int /*long*/ [] endptr = new int /*long*/ [1];
- double value = OS.g_strtod (str, endptr);
- if (endptr [0] == str + length) {
- int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- if (value != adjustment.value && adjustment.lower <= value && value <= adjustment.upper) {
- OS.gtk_spin_button_update (handle);
- }
- }
- }
-
- /*
- * Feature in GTK. When the user types, GTK positions
- * the caret after sending the changed signal. This
- * means that application code that attempts to position
- * the caret during a changed signal will fail. The fix
- * is to post the modify event when the user is typing.
- */
- boolean keyPress = false;
- int /*long*/ eventPtr = OS.gtk_get_current_event ();
- if (eventPtr != 0) {
- GdkEventKey gdkEvent = new GdkEventKey ();
- OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof);
- switch (gdkEvent.type) {
- case OS.GDK_KEY_PRESS:
- keyPress = true;
- break;
- }
- OS.gdk_event_free (eventPtr);
- }
- if (keyPress) {
- postEvent (SWT.Modify);
- } else {
- sendEvent (SWT.Modify);
- }
- return 0;
-}
-
-int /*long*/ gtk_commit (int /*long*/ imContext, int /*long*/ text) {
- if (text == 0) return 0;
- if (!OS.gtk_editable_get_editable (handle)) return 0;
- int length = OS.strlen (text);
- if (length == 0) return 0;
- byte [] buffer = new byte [length];
- OS.memmove (buffer, text, length);
- char [] chars = Converter.mbcsToWcs (null, buffer);
- char [] newChars = sendIMKeyEvent (SWT.KeyDown, null, chars);
- if (newChars == null) return 0;
- /*
- * Feature in GTK. For a GtkEntry, during the insert-text signal,
- * GTK allows the programmer to change only the caret location,
- * not the selection. If the programmer changes the selection,
- * the new selection is lost. The fix is to detect a selection
- * change and set it after the insert-text signal has completed.
- */
- fixStart = fixEnd = -1;
- OS.g_signal_handlers_block_matched (imContext, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, COMMIT);
- int id = OS.g_signal_lookup (OS.commit, OS.gtk_im_context_get_type ());
- int mask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID;
- OS.g_signal_handlers_unblock_matched (imContext, mask, id, 0, 0, 0, handle);
- if (newChars == chars) {
- OS.g_signal_emit_by_name (imContext, OS.commit, text);
- } else {
- buffer = Converter.wcsToMbcs (null, newChars, true);
- OS.g_signal_emit_by_name (imContext, OS.commit, buffer);
- }
- OS.g_signal_handlers_unblock_matched (imContext, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, COMMIT);
- OS.g_signal_handlers_block_matched (imContext, mask, id, 0, 0, 0, handle);
- if (fixStart != -1 && fixEnd != -1) {
- OS.gtk_editable_set_position (handle, fixStart);
- OS.gtk_editable_select_region (handle, fixStart, fixEnd);
- }
- fixStart = fixEnd = -1;
- return 0;
-}
-
-int /*long*/ gtk_delete_text (int /*long*/ widget, int /*long*/ start_pos, int /*long*/ end_pos) {
- if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0;
- String newText = verifyText ("", (int)/*64*/start_pos, (int)/*64*/end_pos);
- if (newText == null) {
- OS.g_signal_stop_emission_by_name (handle, OS.delete_text);
- } else {
- if (newText.length () > 0) {
- int [] pos = new int [1];
- pos [0] = (int)/*64*/end_pos;
- byte [] buffer = Converter.wcsToMbcs (null, newText, false);
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT);
- OS.gtk_editable_insert_text (handle, buffer, buffer.length, pos);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_editable_set_position (handle, pos [0]);
- }
- }
- return 0;
-}
-
-int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) {
- if (cursor != null) setCursor (cursor.handle);
- return super.gtk_event_after (widget, gdkEvent);
-}
-
-int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) {
- fixIM ();
- return super.gtk_focus_out_event (widget, event);
-}
-
-int /*long*/ gtk_insert_text (int /*long*/ widget, int /*long*/ new_text, int /*long*/ new_text_length, int /*long*/ position) {
-// if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0;
- if (new_text == 0 || new_text_length == 0) return 0;
- byte [] buffer = new byte [(int)/*64*/new_text_length];
- OS.memmove (buffer, new_text, buffer.length);
- String oldText = new String (Converter.mbcsToWcs (null, buffer));
- int [] pos = new int [1];
- OS.memmove (pos, position, 4);
- if (pos [0] == -1) {
- int /*long*/ ptr = OS.gtk_entry_get_text (handle);
- pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1);
- }
- String newText = verifyText (oldText, pos [0], pos [0]);
- if (newText != oldText) {
- int [] newStart = new int [1], newEnd = new int [1];
- OS.gtk_editable_get_selection_bounds (handle, newStart, newEnd);
- if (newText != null) {
- if (newStart [0] != newEnd [0]) {
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT);
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_editable_delete_selection (handle);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- }
- byte [] buffer3 = Converter.wcsToMbcs (null, newText, false);
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT);
- OS.gtk_editable_insert_text (handle, buffer3, buffer3.length, pos);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT);
- newStart [0] = newEnd [0] = pos [0];
- }
- pos [0] = newEnd [0];
- if (newStart [0] != newEnd [0]) {
- fixStart = newStart [0];
- fixEnd = newEnd [0];
- }
- OS.memmove (position, pos, 4);
- OS.g_signal_stop_emission_by_name (handle, OS.insert_text);
- }
- return 0;
-}
-
-int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_key_press_event (widget, event);
- if (result != 0) fixIM ();
- if (gdkEventKey == -1) result = 1;
- gdkEventKey = 0;
- return result;
-}
-
-int /*long*/ gtk_populate_popup (int /*long*/ widget, int /*long*/ menu) {
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- OS.gtk_widget_set_direction (menu, OS.GTK_TEXT_DIR_RTL);
- OS.gtk_container_forall (menu, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL);
- }
- return 0;
-}
-
-int /*long*/ gtk_value_changed (int /*long*/ widget) {
- postEvent (SWT.Selection);
- return 0;
-}
-
-void hookEvents () {
- super.hookEvents();
- OS.g_signal_connect_closure (handle, OS.changed, display.closures [CHANGED], true);
- OS.g_signal_connect_closure (handle, OS.insert_text, display.closures [INSERT_TEXT], false);
- OS.g_signal_connect_closure (handle, OS.delete_text, display.closures [DELETE_TEXT], false);
- OS.g_signal_connect_closure (handle, OS.value_changed, display.closures [VALUE_CHANGED], false);
- OS.g_signal_connect_closure (handle, OS.activate, display.closures [ACTIVATE], false);
- OS.g_signal_connect_closure (handle, OS.populate_popup, display.closures [POPULATE_POPUP], false);
- int /*long*/ imContext = imContext ();
- if (imContext != 0) {
- OS.g_signal_connect_closure (imContext, OS.commit, display.closures [COMMIT], false);
- int id = OS.g_signal_lookup (OS.commit, OS.gtk_im_context_get_type ());
- int mask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID;
- OS.g_signal_handlers_block_matched (imContext, mask, id, 0, 0, 0, handle);
- }
-}
-
-int /*long*/ imContext () {
- return OS.GTK_ENTRY_IM_CONTEXT (handle);
-}
-
-int /*long*/ paintWindow () {
- int /*long*/ window = super.paintWindow ();
- int /*long*/ children = OS.gdk_window_get_children (window);
- if (children != 0) window = OS.g_list_data (children);
- OS.g_list_free (children);
- return window;
-}
-
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void paste () {
- checkWidget ();
- OS.gtk_editable_paste_clipboard (handle);
-}
-
-void register () {
- super.register ();
- int /*long*/ imContext = imContext ();
- if (imContext != 0) display.addWidget (imContext, this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- fixIM ();
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- */
-void removeVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-
-void setBackgroundColor (GdkColor color) {
- super.setBackgroundColor (color);
- OS.gtk_widget_modify_base (handle, 0, color);
-}
-
-void setCursor (int /*long*/ cursor) {
- int /*long*/ defaultCursor = 0;
- if (cursor == 0) defaultCursor = OS.gdk_cursor_new (OS.GDK_XTERM);
- super.setCursor (cursor != 0 ? cursor : defaultCursor);
- if (cursor == 0) OS.gdk_cursor_destroy (defaultCursor);
-}
-
-void setFontDescription (int /*long*/ font) {
- super.setFontDescription (font);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down arrows are pressed to
- * the argument, which must be at least one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- double newValue = value;
- int digits = OS.gtk_spin_button_get_digits (handle);
- for (int i = 0; i < digits; i++) newValue /= 10;
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_spin_button_set_increments (handle, newValue, adjustment.page_increment);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- double newValue = value;
- int digits = OS.gtk_spin_button_get_digits (handle);
- for (int i = 0; i < digits; i++) newValue /= 10;
- if (newValue <= adjustment.lower) return;
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_spin_button_set_range (handle, adjustment.lower, newValue);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget ();
- int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- double newValue = value;
- int digits = OS.gtk_spin_button_get_digits (handle);
- for (int i = 0; i < digits; i++) newValue /= 10;
- if (newValue >= adjustment.upper) return;
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_spin_button_set_range (handle, newValue, adjustment.upper);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the amount that the receiver's position will be
- * modified by when the page up/down keys are pressed
- * to the argument, which must be at least one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- double newValue = value;
- int digits = OS.gtk_spin_button_get_digits (handle);
- for (int i = 0; i < digits; i++) newValue /= 10;
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_spin_button_set_increments (handle, adjustment.step_increment, newValue);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the <em>selection</em>, which is the receiver's
- * position, to the argument. If the argument is not within
- * the range specified by minimum and maximum, it will be
- * adjusted to fall within this range.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget ();
- double newValue = value;
- int digits = OS.gtk_spin_button_get_digits (handle);
- for (int i = 0; i < digits; i++) newValue /= 10;
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_spin_button_set_value (handle, newValue);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-/**
- * Sets the maximum number of characters that the receiver's
- * text field is capable of holding to be the argument.
- * <p>
- * To reset this value to the default, use <code>setTextLimit(Spinner.LIMIT)</code>.
- * Specifying a limit value larger than <code>Spinner.LIMIT</code> sets the
- * receiver's limit to <code>Spinner.LIMIT</code>.
- * </p>
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- *
- * @since 3.4
- */
-public void setTextLimit (int limit) {
- checkWidget ();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- OS.gtk_entry_set_max_length (handle, limit);
-}
-
-/**
- * Sets the number of decimal places used by the receiver.
- * <p>
- * The digit setting is used to allow for floating point values in the receiver.
- * For example, to set the selection to a floating point value of 1.37 call setDigits() with
- * a value of 2 and setSelection() with a value of 137. Similarly, if getDigits() has a value
- * of 2 and getSelection() returns 137 this should be interpreted as 1.37. This applies to all
- * numeric APIs.
- * </p>
- *
- * @param value the new digits (must be greater than or equal to zero)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the value is less than zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDigits (int value) {
- checkWidget ();
- if (value < 0) error (SWT.ERROR_INVALID_ARGUMENT);
- int digits = OS.gtk_spin_button_get_digits (handle);
- if (value == digits) return;
- int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- int diff = Math.abs (value - digits);
- int factor = 1;
- for (int i = 0; i < diff; i++) factor *= 10;
- if (digits > value) {
- adjustment.value *= factor;
- adjustment.upper *= factor;
- adjustment.lower *= factor;
- adjustment.step_increment *= factor;
- adjustment.page_increment *= factor;
- } else {
- adjustment.value /= factor;
- adjustment.upper /= factor;
- adjustment.lower /= factor;
- adjustment.step_increment /= factor;
- adjustment.page_increment /= factor;
- }
- OS.memmove (hAdjustment, adjustment);
- OS.gtk_spin_button_set_digits (handle, value);
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, digits, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param digits the new digits value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setValues (int selection, int minimum, int maximum, int digits, int increment, int pageIncrement) {
- checkWidget ();
- if (maximum <= minimum) return;
- if (digits < 0) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- selection = Math.min (Math.max (minimum, selection), maximum);
- double factor = 1;
- for (int i = 0; i < digits; i++) factor *= 10;
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
- OS.gtk_spin_button_set_range (handle, minimum / factor, maximum / factor);
- OS.gtk_spin_button_set_increments (handle, increment / factor, pageIncrement / factor);
- OS.gtk_spin_button_set_value (handle, selection / factor);
- OS.gtk_spin_button_set_digits (handle, digits);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED);
-}
-
-boolean checkSubwindow () {
- return false;
-}
-
-boolean translateTraversal (GdkEventKey keyEvent) {
- int key = keyEvent.keyval;
- switch (key) {
- case OS.GDK_KP_Enter:
- case OS.GDK_Return: {
- int /*long*/ imContext = imContext ();
- if (imContext != 0) {
- int /*long*/ [] preeditString = new int /*long*/ [1];
- OS.gtk_im_context_get_preedit_string (imContext, preeditString, null, null);
- if (preeditString [0] != 0) {
- int length = OS.strlen (preeditString [0]);
- OS.g_free (preeditString [0]);
- if (length != 0) return false;
- }
- }
- }
- }
- return super.translateTraversal (keyEvent);
-}
-
-String verifyText (String string, int start, int end) {
- if (string.length () == 0 && start == end) return null;
- Event event = new Event ();
- event.text = string;
- event.start = start;
- event.end = end;
- int /*long*/ eventPtr = OS.gtk_get_current_event ();
- if (eventPtr != 0) {
- GdkEventKey gdkEvent = new GdkEventKey ();
- OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof);
- switch (gdkEvent.type) {
- case OS.GDK_KEY_PRESS:
- setKeyState (event, gdkEvent);
- break;
- }
- OS.gdk_event_free (eventPtr);
- }
- int index = 0;
- if (OS.gtk_spin_button_get_digits (handle) > 0) {
- String decimalSeparator = getDecimalSeparator ();
- index = string.indexOf (decimalSeparator);
- if (index != -1) {
- string = string.substring (0, index) + string.substring (index + 1);
- }
- index = 0;
- }
- if (string.length () > 0) {
- int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle);
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, hAdjustment);
- if (adjustment.lower < 0 && string.charAt (0) == '-') index++;
- }
- while (index < string.length ()) {
- if (!Character.isDigit (string.charAt (index))) break;
- index++;
- }
- event.doit = index == string.length ();
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the verify
- * event. If this happens, answer null to cancel
- * the operation.
- */
- sendEvent (SWT.Verify, event);
- if (!event.doit || isDisposed ()) return null;
- return event.text;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java
deleted file mode 100644
index 68ddc4b10b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java
+++ /dev/null
@@ -1,733 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class implement the notebook user interface
- * metaphor. It allows the user to select a notebook page from
- * set of pages.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TabItem</code>.
- * <code>Control</code> children are created and then set into a
- * tab item using <code>TabItem#setControl</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>TOP, BOTTOM</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles TOP and BOTTOM may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tabfolder">TabFolder, TabItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TabFolder extends Composite {
- TabItem [] items;
- ImageList imageList;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see SWT#TOP
- * @see SWT#BOTTOM
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabFolder (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- style = checkBits (style, SWT.TOP, SWT.BOTTOM, 0, 0, 0, 0);
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-int /*long*/ childStyle () {
- int /*long*/ rcStyle = OS.gtk_widget_get_modifier_style (handle);
- if ((OS.gtk_rc_style_get_color_flags (rcStyle, 0) & OS.GTK_RC_BG) != 0) return 0;
- OS.gtk_widget_realize (handle);
- return OS.gtk_widget_get_style (handle);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-int /*long*/ clientHandle () {
- int index = OS.gtk_notebook_get_current_page (handle);
- if (index != -1 && items [index] != null) {
- return items [index].pageHandle;
- }
- return handle;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- Point size = super.computeSize (wHint, hHint, changed);
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- boolean scrollable = OS.gtk_notebook_get_scrollable (handle);
- OS.gtk_notebook_set_scrollable (handle, false);
- Point notebookSize = computeNativeSize (handle, wHint, hHint, changed);
- OS.gtk_notebook_set_scrollable (handle, scrollable);
- size.x = Math.max (notebookSize.x, size.x);
- size.y = Math.max (notebookSize.y, size.y);
- return size;
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- forceResize ();
- int /*long*/ clientHandle = clientHandle ();
- int clientX = OS.GTK_WIDGET_X (clientHandle);
- int clientY = OS.GTK_WIDGET_Y (clientHandle);
- x -= clientX;
- y -= clientY;
- width += clientX + clientX;
- if ((style & SWT.BOTTOM) != 0) {
- int parentHeight = OS.GTK_WIDGET_HEIGHT (handle);
- int clientHeight = OS.GTK_WIDGET_HEIGHT (clientHandle);
- height += parentHeight - clientHeight;
- } else {
- height += clientX + clientY;
- }
- return new Rectangle (x, y, width, height);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (fixedHandle, true);
- handle = OS.gtk_notebook_new ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (fixedHandle, handle);
- OS.gtk_notebook_set_scrollable (handle, true);
- OS.gtk_notebook_set_show_tabs (handle, true);
- if ((style & SWT.BOTTOM) != 0) {
- OS.gtk_notebook_set_tab_pos (handle, OS.GTK_POS_BOTTOM);
- }
-}
-
-void createWidget (int index) {
- super.createWidget(index);
- items = new TabItem [4];
-}
-
-void createItem (TabItem item, int index) {
- int /*long*/ list = OS.gtk_container_get_children (handle);
- int itemCount = 0;
- if (list != 0) {
- itemCount = OS.g_list_length (list);
- OS.g_list_free (list);
- }
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (itemCount == items.length) {
- TabItem [] newItems = new TabItem [items.length + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- int /*long*/ boxHandle = OS.gtk_hbox_new (false, 0);
- if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ labelHandle = OS.gtk_label_new_with_mnemonic (null);
- if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ imageHandle = OS.gtk_image_new ();
- if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (boxHandle, imageHandle);
- OS.gtk_container_add (boxHandle, labelHandle);
- int /*long*/ pageHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (pageHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
- OS.gtk_notebook_insert_page (handle, pageHandle, boxHandle, index);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
- OS.gtk_widget_show (boxHandle);
- OS.gtk_widget_show (labelHandle);
- OS.gtk_widget_show (pageHandle);
- item.state |= HANDLE;
- item.handle = boxHandle;
- item.labelHandle = labelHandle;
- item.imageHandle = imageHandle;
- item.pageHandle = pageHandle;
- System.arraycopy (items, index, items, index + 1, itemCount++ - index);
- items [index] = item;
- if ((state & FOREGROUND) != 0) {
- item.setForegroundColor (getForegroundColor());
- }
- if ((state & FONT) != 0) {
- item.setFontDescription (getFontDescription());
- }
- if (itemCount == 1) {
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
- OS.gtk_notebook_set_current_page (handle, 0);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
- Event event = new Event();
- event.item = items[0];
- sendEvent (SWT.Selection, event);
- // the widget could be destroyed at this point
- }
-}
-
-void destroyItem (TabItem item) {
- int index = 0;
- int itemCount = getItemCount();
- while (index < itemCount) {
- if (items [index] == item) break;
- index++;
- }
- if (index == itemCount) error (SWT.ERROR_ITEM_NOT_REMOVED);
- int oldIndex = OS.gtk_notebook_get_current_page (handle);
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
- OS.gtk_notebook_remove_page (handle, index);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- if (index == oldIndex) {
- int newIndex = OS.gtk_notebook_get_current_page (handle);
- if (newIndex != -1) {
- Control control = items [newIndex].getControl ();
- if (control != null && !control.isDisposed ()) {
- control.setBounds (getClientArea());
- control.setVisible (true);
- }
- Event event = new Event ();
- event.item = items [newIndex];
- sendEvent (SWT.Selection, event);
- // the widget could be destroyed at this point
- }
- }
-}
-
-int /*long*/ eventHandle () {
- return handle;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem getItem (int index) {
- checkWidget();
- if (!(0 <= index && index < getItemCount())) error (SWT.ERROR_INVALID_RANGE);
- int /*long*/ list = OS.gtk_container_get_children (handle);
- if (list == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- int itemCount = OS.g_list_length (list);
- OS.g_list_free (list);
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_CANNOT_GET_ITEM);
- return items [index];
-}
-
-/**
- * Returns the tab item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- *
- * @param point the point used to locate the item
- * @return the tab item at the given point, or null if the point is not in a tab item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public TabItem getItem(Point point) {
- checkWidget();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- int /*long*/ list = OS.gtk_container_get_children (handle);
- if (list == 0) return null;
- int itemCount = OS.g_list_length (list);
- OS.g_list_free (list);
- for (int i = 0; i < itemCount; i++) {
- TabItem item = items[i];
- Rectangle rect = item.getBounds();
- if (rect.contains(point)) return item;
- }
- return null;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- int /*long*/ list = OS.gtk_container_get_children (handle);
- if (list == 0) return 0;
- int itemCount = OS.g_list_length (list);
- OS.g_list_free (list);
- return itemCount;
-}
-
-/**
- * Returns an array of <code>TabItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem [] getItems () {
- checkWidget();
- int count = getItemCount ();
- TabItem [] result = new TabItem [count];
- System.arraycopy (items, 0, result, 0, count);
- return result;
-}
-
-/**
- * Returns an array of <code>TabItem</code>s that are currently
- * selected in the receiver. An empty array indicates that no
- * items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem [] getSelection () {
- checkWidget();
- int index = OS.gtk_notebook_get_current_page (handle);
- if (index == -1) return new TabItem [0];
- return new TabItem [] {items [index]};
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget();
- return OS.gtk_notebook_get_current_page (handle);
-}
-
-int /*long*/ gtk_focus (int /*long*/ widget, int /*long*/ directionType) {
- return 0;
-}
-
-int /*long*/ gtk_switch_page (int /*long*/ widget, int /*long*/ page, int /*long*/ page_num) {
- int index = OS.gtk_notebook_get_current_page (handle);
- if (index != -1) {
- Control control = items [index].getControl ();
- if (control != null && !control.isDisposed ()) {
- control.setVisible (false);
- }
- }
- TabItem item = items [(int)/*64*/page_num];
- Control control = item.getControl ();
- if (control != null && !control.isDisposed ()) {
- control.setBounds(getClientArea());
- control.setVisible (true);
- }
- Event event = new Event();
- event.item = item;
- postEvent(SWT.Selection, event);
- return 0;
-}
-
-void hookEvents () {
- super.hookEvents ();
- OS.g_signal_connect_closure (handle, OS.switch_page, display.closures [SWITCH_PAGE], false);
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (TabItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- int /*long*/ list = OS.gtk_container_get_children (handle);
- if (list == 0) return -1;
- int count = OS.g_list_length (list);
- OS.g_list_free (list);
- for (int i=0; i<count; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-
-Point minimumSize (int wHint, int hHint, boolean flushCache) {
- Control [] children = _getChildren ();
- int width = 0, height = 0;
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- int index = 0;
- int count = 0;
- int /*long*/ list = OS.gtk_container_get_children (handle);
- if (list != 0) {
- count = OS.g_list_length (list);
- OS.g_list_free (list);
- }
- while (index < count) {
- if (items [index].control == child) break;
- index++;
- }
- if (index == count) {
- Rectangle rect = child.getBounds ();
- width = Math.max (width, rect.x + rect.width);
- height = Math.max (height, rect.y + rect.height);
- } else {
- Point size = child.computeSize (wHint, hHint, flushCache);
- width = Math.max (width, size.x);
- height = Math.max (height, size.y);
- }
- }
- return new Point (width, height);
-}
-
-boolean mnemonicHit (char key) {
- int itemCount = getItemCount ();
- for (int i=0; i<itemCount; i++) {
- int /*long*/ labelHandle = items [i].labelHandle;
- if (labelHandle != 0 && mnemonicHit (labelHandle, key)) return true;
- }
- return false;
-}
-
-boolean mnemonicMatch (char key) {
- int itemCount = getItemCount ();
- for (int i=0; i<itemCount; i++) {
- int /*long*/ labelHandle = items [i].labelHandle;
- if (labelHandle != 0 && mnemonicHit (labelHandle, key)) return true;
- }
- return false;
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<items.length; i++) {
- TabItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (imageList != null) imageList.dispose ();
- imageList = null;
-}
-
-void removeControl (Control control) {
- super.removeControl (control);
- int count = getItemCount ();
- for (int i=0; i<count; i++) {
- TabItem item = items [i];
- if (item.control == control) item.setControl (null);
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- int result = super.setBounds (x, y, width, height, move, resize);
- if ((result & RESIZED) != 0) {
- int index = getSelectionIndex ();
- if (index != -1) {
- TabItem item = items [index];
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setBounds (getClientArea ());
- }
- }
- }
- return result;
-}
-
-void setFontDescription (int /*long*/ font) {
- super.setFontDescription (font);
- TabItem [] items = getItems ();
- for (int i = 0; i < items.length; i++) {
- if (items[i] != null) {
- items[i].setFontDescription (font);
- }
- }
-}
-
-void setForegroundColor (GdkColor color) {
- super.setForegroundColor (color);
- TabItem [] items = getItems ();
- for (int i = 0; i < items.length; i++) {
- if (items[i] != null) {
- items[i].setForegroundColor (color);
- }
- }
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains selected.
- * The current selection is first cleared, then the new items are
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int index) {
- checkWidget ();
- if (!(0 <= index && index < getItemCount ())) return;
- setSelection (index, false);
-}
-
-void setSelection (int index, boolean notify) {
- if (index < 0) return;
- int oldIndex = OS.gtk_notebook_get_current_page (handle);
- if (oldIndex == index) return;
- if (oldIndex != -1) {
- TabItem item = items [oldIndex];
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setVisible (false);
- }
- }
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
- OS.gtk_notebook_set_current_page (handle, index);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
- int newIndex = OS.gtk_notebook_get_current_page (handle);
- if (newIndex != -1) {
- TabItem item = items [newIndex];
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setBounds (getClientArea ());
- control.setVisible (true);
- }
- if (notify) {
- Event event = new Event ();
- event.item = item;
- sendEvent (SWT.Selection, event);
- }
- }
-}
-
-/**
- * Sets the receiver's selection to the given item.
- * The current selected is first cleared, then the new item is
- * selected.
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection (TabItem item) {
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (new TabItem [] {item});
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selected is first cleared, then the new items are
- * selected.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (TabItem [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (items.length == 0) {
- setSelection (-1, false);
- } else {
- for (int i=items.length-1; i>=0; --i) {
- int index = indexOf (items [i]);
- if (index != -1) setSelection (index, false);
- }
- }
-}
-
-boolean traversePage (final boolean next) {
- if (next) {
- OS.gtk_notebook_next_page (handle);
- } else {
- OS.gtk_notebook_prev_page (handle);
- }
- return true;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java
deleted file mode 100644
index a19d175727..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java
+++ /dev/null
@@ -1,390 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * corresponding to a tab for a page in a tab folder.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tabfolder">TabFolder, TabItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TabItem extends Item {
- int /*long*/ labelHandle, imageHandle, pageHandle;
- Control control;
- TabFolder parent;
- String toolTipText;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>TabFolder</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabItem (TabFolder parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget (parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>TabFolder</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabItem (TabFolder parent, int style, int index) {
- super (parent, style);
- this.parent = parent;
- createWidget (index);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createWidget (int index) {
- parent.createItem (this, index);
- setOrientation ();
- hookEvents ();
- register ();
- text = "";
-}
-
-void deregister() {
- super.deregister ();
- if (labelHandle != 0) display.removeWidget (labelHandle);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public Rectangle getBounds () {
- checkWidget();
- int x = OS.GTK_WIDGET_X (handle);
- int y = OS.GTK_WIDGET_Y (handle);
- int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (handle);
- int height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (handle);
- if ((parent.style & SWT.MIRRORED) != 0) x = parent.getClientWidth () - width - x;
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the control that is used to fill the client area of
- * the tab folder when the user selects the tab item. If no
- * control has been set, return <code>null</code>.
- * <p>
- * @return the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget ();
- return control;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>TabFolder</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabFolder getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-
-int /*long*/ gtk_enter_notify_event (int /*long*/ widget, int /*long*/ event) {
- parent.gtk_enter_notify_event (widget, event);
- return 0;
-}
-
-int /*long*/ gtk_mnemonic_activate (int /*long*/ widget, int /*long*/ arg1) {
- return parent.gtk_mnemonic_activate (widget, arg1);
-}
-
-void hookEvents () {
- super.hookEvents ();
- if (labelHandle != 0) OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false);
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false);
-}
-
-void register () {
- super.register ();
- if (labelHandle != 0) display.addWidget (labelHandle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- pageHandle = labelHandle = imageHandle = 0;
- parent = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- int index = parent.indexOf (this);
- if (index == parent.getSelectionIndex ()) {
- if (control != null) control.setVisible (false);
- }
-}
-
-/**
- * Sets the control that is used to fill the client area of
- * the tab folder when the user selects the tab item.
- * <p>
- * @param control the new control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget ();
- if (control != null) {
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- Control oldControl = this.control, newControl = control;
- this.control = control;
- int index = parent.indexOf (this), selectionIndex = parent.getSelectionIndex();
- if (index != selectionIndex) {
- if (newControl != null) {
- if (selectionIndex != -1) {
- Control selectedControl = parent.getItem(selectionIndex).getControl();
- if (selectedControl == newControl) return;
- }
- newControl.setVisible(false);
- return;
- }
- }
- if (newControl != null) {
- newControl.setBounds (parent.getClientArea ());
- newControl.setVisible (true);
- }
- if (oldControl != null) oldControl.setVisible (false);
-}
-
-void setFontDescription (int /*long*/ font) {
- OS.gtk_widget_modify_font (labelHandle, font);
- OS.gtk_widget_modify_font (imageHandle, font);
-}
-
-void setForegroundColor (GdkColor color) {
- /* Don't set the color in vbox handle (it doesn't draw) */
- setForegroundColor (labelHandle, color);
- setForegroundColor (imageHandle, color);
-}
-
-public void setImage (Image image) {
- checkWidget ();
- super.setImage (image);
- if (image != null) {
- ImageList imageList = parent.imageList;
- if (imageList == null) imageList = parent.imageList = new ImageList ();
- int imageIndex = imageList.indexOf (image);
- if (imageIndex == -1) {
- imageIndex = imageList.add (image);
- } else {
- imageList.put (imageIndex, image);
- }
- int /*long*/ pixbuf = imageList.getPixbuf (imageIndex);
- OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf);
- OS.gtk_widget_show (imageHandle);
- } else {
- OS.gtk_image_set_from_pixbuf (imageHandle, 0);
- OS.gtk_widget_hide (imageHandle);
- }
-}
-
-void setOrientation () {
- if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) {
- if (handle != 0) OS.gtk_widget_set_direction (handle, OS.GTK_TEXT_DIR_RTL);
- if (labelHandle != 0) OS.gtk_widget_set_direction (labelHandle, OS.GTK_TEXT_DIR_RTL);
- if (imageHandle != 0) OS.gtk_widget_set_direction (imageHandle, OS.GTK_TEXT_DIR_RTL);
- if (pageHandle != 0) OS.gtk_widget_set_direction (pageHandle, OS.GTK_TEXT_DIR_RTL);
- }
-}
-
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- char [] chars = fixMnemonic (string);
- byte [] buffer = Converter.wcsToMbcs (null, chars, true);
- OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer);
- if (string.length () != 0) {
- OS.gtk_widget_show (labelHandle);
- } else {
- OS.gtk_widget_hide (labelHandle);
- }
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget ();
- toolTipText = string;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java
deleted file mode 100644
index 451650d509..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java
+++ /dev/null
@@ -1,3543 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class implement a selectable user interface
- * object that displays a list of images and strings and issues
- * notification when selected.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TableItem</code>.
- * </p><p>
- * Style <code>VIRTUAL</code> is used to create a <code>Table</code> whose
- * <code>TableItem</code>s are to be populated by the client on an on-demand basis
- * instead of up-front. This can provide significant performance improvements for
- * tables that are very large or for which <code>TableItem</code> population is
- * expensive (for example, retrieving values from an external source).
- * </p><p>
- * Here is an example of using a <code>Table</code> with style <code>VIRTUAL</code>:
- * <code><pre>
- * final Table table = new Table (parent, SWT.VIRTUAL | SWT.BORDER);
- * table.setItemCount (1000000);
- * table.addListener (SWT.SetData, new Listener () {
- * public void handleEvent (Event event) {
- * TableItem item = (TableItem) event.item;
- * int index = table.indexOf (item);
- * item.setText ("Item " + index);
- * System.out.println (item.getText ());
- * }
- * });
- * </pre></code>
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not normally make sense to add <code>Control</code> children to
- * it, or set a layout on it, unless implementing something like a cell
- * editor.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, HIDE_SELECTION, VIRTUAL, NO_SCROLL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection, SetData, MeasureItem, EraseItem, PaintItem</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles SINGLE, and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Table extends Composite {
- int /*long*/ modelHandle, checkRenderer;
- int itemCount, columnCount, lastIndexOf, sortDirection;
- int /*long*/ ignoreCell;
- TableItem [] items;
- TableColumn [] columns;
- TableItem currentItem;
- TableColumn sortColumn;
- ImageList imageList, headerImageList;
- boolean firstCustomDraw;
- int drawState, drawFlags;
- GdkColor drawForeground;
- boolean ownerDraw, ignoreSize, ignoreAccessibility;
-
- static final int CHECKED_COLUMN = 0;
- static final int GRAYED_COLUMN = 1;
- static final int FOREGROUND_COLUMN = 2;
- static final int BACKGROUND_COLUMN = 3;
- static final int FONT_COLUMN = 4;
- static final int FIRST_COLUMN = FONT_COLUMN + 1;
- static final int CELL_PIXBUF = 0;
- static final int CELL_TEXT = 1;
- static final int CELL_FOREGROUND = 2;
- static final int CELL_BACKGROUND = 3;
- static final int CELL_FONT = 4;
- static final int CELL_TYPES = CELL_FONT + 1;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#CHECK
- * @see SWT#FULL_SELECTION
- * @see SWT#HIDE_SELECTION
- * @see SWT#VIRTUAL
- * @see SWT#NO_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Table (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-void _addListener (int eventType, Listener listener) {
- super._addListener (eventType, listener);
- if (!ownerDraw) {
- switch (eventType) {
- case SWT.MeasureItem:
- case SWT.EraseItem:
- case SWT.PaintItem:
- ownerDraw = true;
- recreateRenderers ();
- break;
- }
- }
-}
-
-TableItem _getItem (int index) {
- if ((style & SWT.VIRTUAL) == 0) return items [index];
- if (items [index] != null) return items [index];
- return items [index] = new TableItem (this, SWT.NONE, index, false);
-}
-
-static int checkStyle (int style) {
- /*
- * Feature in Windows. Even when WS_HSCROLL or
- * WS_VSCROLL is not specified, Windows creates
- * trees and tables with scroll bars. The fix
- * is to set H_SCROLL and V_SCROLL.
- *
- * NOTE: This code appears on all platforms so that
- * applications have consistent scroll bar behavior.
- */
- if ((style & SWT.NO_SCROLL) == 0) {
- style |= SWT.H_SCROLL | SWT.V_SCROLL;
- }
- /* GTK is always FULL_SELECTION */
- style |= SWT.FULL_SELECTION;
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-
-int /*long*/ cellDataProc (int /*long*/ tree_column, int /*long*/ cell, int /*long*/ tree_model, int /*long*/ iter, int /*long*/ data) {
- if (cell == ignoreCell) return 0;
- int /*long*/ path = OS.gtk_tree_model_get_path (tree_model, iter);
- int [] index = new int [1];
- OS.memmove (index, OS.gtk_tree_path_get_indices (path), 4);
- TableItem item = _getItem (index[0]);
- OS.gtk_tree_path_free (path);
- if (item != null) OS.g_object_set_qdata (cell, Display.SWT_OBJECT_INDEX2, item.handle);
- boolean isPixbuf = OS.GTK_IS_CELL_RENDERER_PIXBUF (cell);
- if (!(isPixbuf || OS.GTK_IS_CELL_RENDERER_TEXT (cell))) return 0;
- int modelIndex = -1;
- boolean customDraw = false;
- if (columnCount == 0) {
- modelIndex = Table.FIRST_COLUMN;
- customDraw = firstCustomDraw;
- } else {
- TableColumn column = (TableColumn) display.getWidget (tree_column);
- if (column != null) {
- modelIndex = column.modelIndex;
- customDraw = column.customDraw;
- }
- }
- if (modelIndex == -1) return 0;
- boolean setData = false;
- if ((style & SWT.VIRTUAL) != 0) {
- /*
- * Feature in GTK. On GTK before 2.4, fixed_height_mode is not
- * supported, and the tree asks for the data of all items. The
- * fix is to only provide the data if the row is visible.
- */
- if (OS.GTK_VERSION < OS.VERSION (2, 3, 2)) {
- OS.gtk_widget_realize (handle);
- GdkRectangle visible = new GdkRectangle ();
- OS.gtk_tree_view_get_visible_rect (handle, visible);
- GdkRectangle area = new GdkRectangle ();
- path = OS.gtk_tree_model_get_path (tree_model, iter);
- OS.gtk_tree_view_get_cell_area (handle, path, tree_column, area);
- OS.gtk_tree_path_free (path);
- if (area.y + area.height < 0 || area.y + visible.y > visible.y + visible.height) {
- /* Give an image from the image list to make sure the row has
- * the correct height.
- */
- if (imageList != null && imageList.pixbufs.length > 0) {
- if (isPixbuf) OS.g_object_set (cell, OS.pixbuf, imageList.pixbufs [0], 0);
- }
- return 0;
- }
- }
- if (!item.cached) {
- lastIndexOf = index[0];
- setData = checkData (item);
- }
- }
- int /*long*/ [] ptr = new int /*long*/ [1];
- if (setData) {
- ptr [0] = 0;
- if (isPixbuf) {
- OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_PIXBUF, ptr, -1);
- OS.g_object_set (cell, OS.pixbuf, ptr [0], 0);
- } else {
- OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_TEXT, ptr, -1);
- if (ptr [0] != 0) {
- OS.g_object_set (cell, OS.text, ptr [0], 0);
- OS.g_free (ptr [0]);
- }
- }
- }
- if (customDraw) {
- /*
- * Bug on GTK. Gtk renders the background on top of the checkbox and pixbuf.
- * This only happens in version 2.2.1 and earlier. The fix is not to set the background.
- */
- if (OS.GTK_VERSION > OS.VERSION (2, 2, 1)) {
- if (!ownerDraw) {
- ptr [0] = 0;
- OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_BACKGROUND, ptr, -1);
- if (ptr [0] != 0) {
- OS.g_object_set (cell, OS.cell_background_gdk, ptr [0], 0);
- }
- }
- }
- if (!isPixbuf) {
- ptr [0] = 0;
- OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_FOREGROUND, ptr, -1);
- if (ptr [0] != 0) {
- OS.g_object_set (cell, OS.foreground_gdk, ptr [0], 0);
- }
- ptr [0] = 0;
- OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_FONT, ptr, -1);
- if (ptr [0] != 0) {
- OS.g_object_set (cell, OS.font_desc, ptr [0], 0);
- }
- }
- }
- if (setData) {
- ignoreCell = cell;
- setScrollWidth (tree_column, item);
- ignoreCell = 0;
- }
- return 0;
-}
-
-boolean checkData (TableItem item) {
- if (item.cached) return true;
- if ((style & SWT.VIRTUAL) != 0) {
- item.cached = true;
- Event event = new Event ();
- event.item = item;
- event.index = indexOf (item);
- int mask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID;
- int signal_id = OS.g_signal_lookup (OS.row_changed, OS.gtk_tree_model_get_type ());
- OS.g_signal_handlers_block_matched (modelHandle, mask, signal_id, 0, 0, 0, handle);
- currentItem = item;
- sendEvent (SWT.SetData, event);
- //widget could be disposed at this point
- currentItem = null;
- if (isDisposed ()) return false;
- OS.g_signal_handlers_unblock_matched (modelHandle, mask, signal_id, 0, 0, 0, handle);
- if (item.isDisposed ()) return false;
- }
- return true;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * If the receiver has the <code>SWT.CHECK</code> style and the check selection changes,
- * the event object detail field contains the value <code>SWT.CHECK</code>.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * The item field of the event object is valid for default selection, but the detail field is not used.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-int calculateWidth (int /*long*/ column, int /*long*/ iter) {
- OS.gtk_tree_view_column_cell_set_cell_data (column, modelHandle, iter, false, false);
- /*
- * Bug in GTK. The width calculated by gtk_tree_view_column_cell_get_size()
- * always grows in size regardless of the text or images in the table.
- * The fix is to determine the column width from the cell renderers.
- */
- // Code intentionally commented
- //int [] width = new int [1];
- //OS.gtk_tree_view_column_cell_get_size (column, null, null, null, width, null);
- //return width [0];
-
- int width = 0;
- int [] w = new int [1];
- OS.gtk_widget_style_get(handle, OS.focus_line_width, w, 0);
- width += 2 * w [0];
- int /*long*/ list = OS.gtk_tree_view_column_get_cell_renderers (column);
- if (list == 0) return 0;
- int /*long*/ temp = list;
- while (temp != 0) {
- int /*long*/ renderer = OS.g_list_data (temp);
- if (renderer != 0) {
- OS.gtk_cell_renderer_get_size (renderer, handle, null, null, null, w, null);
- width += w [0];
- }
- temp = OS.g_list_next (temp);
- }
- OS.g_list_free (list);
- if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0) && OS.gtk_tree_view_get_rules_hint (handle)) {
- OS.gtk_widget_style_get (handle, OS.grid_line_width, w, 0) ;
- width += 2 * w [0];
- }
- return width;
-}
-
-/**
- * Clears the item at the given zero-relative index in the receiver.
- * The text, icon and other attributes of the item are set to the default
- * value. If the table was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param index the index of the item to clear
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clear (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- TableItem item = items [index];
- if (item != null) item.clear ();
-}
-
-/**
- * Removes the items from the receiver which are between the given
- * zero-relative start and end indices (inclusive). The text, icon
- * and other attributes of the items are set to their default values.
- * If the table was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param start the start index of the item to clear
- * @param end the end index of the item to clear
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clear (int start, int end) {
- checkWidget ();
- if (start > end) return;
- if (!(0 <= start && start <= end && end < itemCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- if (start == 0 && end == itemCount - 1) {
- clearAll();
- } else {
- for (int i=start; i<=end; i++) {
- TableItem item = items [i];
- if (item != null) item.clear();
- }
- }
-}
-
-/**
- * Clears the items at the given zero-relative indices in the receiver.
- * The text, icon and other attributes of the items are set to their default
- * values. If the table was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clear (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- for (int i=0; i<indices.length; i++) {
- if (!(0 <= indices [i] && indices [i] < itemCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- }
- for (int i=0; i<indices.length; i++) {
- TableItem item = items [indices [i]];
- if (item != null) item.clear();
- }
-}
-
-/**
- * Clears all the items in the receiver. The text, icon and other
- * attributes of the items are set to their default values. If the
- * table was created with the <code>SWT.VIRTUAL</code> style, these
- * attributes are requested again as needed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clearAll () {
- checkWidget ();
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (item != null) item.clear();
- }
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- Point size = computeNativeSize (handle, wHint, hHint, changed);
- Rectangle trim = computeTrim (0, 0, size.x, size.y);
- size.x = trim.width;
- size.y = trim.height;
- return size;
-}
-
-void createColumn (TableColumn column, int index) {
- int modelIndex = FIRST_COLUMN;
- if (columnCount != 0) {
- int modelLength = OS.gtk_tree_model_get_n_columns (modelHandle);
- boolean [] usedColumns = new boolean [modelLength];
- for (int i=0; i<columnCount; i++) {
- int columnIndex = columns [i].modelIndex;
- for (int j = 0; j < CELL_TYPES; j++) {
- usedColumns [columnIndex + j] = true;
- }
- }
- while (modelIndex < modelLength) {
- if (!usedColumns [modelIndex]) break;
- modelIndex++;
- }
- if (modelIndex == modelLength) {
- int /*long*/ oldModel = modelHandle;
- int /*long*/[] types = getColumnTypes (columnCount + 4); // grow by 4 rows at a time
- int /*long*/ newModel = OS.gtk_list_store_newv (types.length, types);
- if (newModel == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ [] ptr = new int /*long*/ [1];
- for (int i=0; i<itemCount; i++) {
- int /*long*/ newItem = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (newItem == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_list_store_append (newModel, newItem);
- TableItem item = items [i];
- if (item != null) {
- int /*long*/ oldItem = item.handle;
- for (int j=0; j<modelLength; j++) {
- OS.gtk_tree_model_get (oldModel, oldItem, j, ptr, -1);
- OS.gtk_list_store_set (newModel, newItem, j, ptr [0], -1);
- if (types [j] == OS.G_TYPE_STRING ()) OS.g_free ((ptr [0]));
- }
- OS.gtk_list_store_remove (oldModel, oldItem);
- OS.g_free (oldItem);
- item.handle = newItem;
- } else {
- OS.g_free (newItem);
- }
- }
- OS.gtk_tree_view_set_model (handle, newModel);
- OS.g_object_unref (oldModel);
- modelHandle = newModel;
- }
- }
- int /*long*/ columnHandle = OS.gtk_tree_view_column_new ();
- if (columnHandle == 0) error (SWT.ERROR_NO_HANDLES);
- if (index == 0 && columnCount > 0) {
- TableColumn checkColumn = columns [0];
- createRenderers (checkColumn.handle, checkColumn.modelIndex, false, checkColumn.style);
- }
- createRenderers (columnHandle, modelIndex, index == 0, column == null ? 0 : column.style);
- /*
- * Use GTK_TREE_VIEW_COLUMN_GROW_ONLY on GTK versions < 2.3.2
- * because fixed_height_mode is not supported.
- */
- boolean useVirtual = (style & SWT.VIRTUAL) != 0 && OS.GTK_VERSION >= OS.VERSION (2, 3, 2);
- if (!useVirtual && columnCount == 0) {
- OS.gtk_tree_view_column_set_sizing (columnHandle, OS.GTK_TREE_VIEW_COLUMN_GROW_ONLY);
- } else {
- OS.gtk_tree_view_column_set_sizing (columnHandle, OS.GTK_TREE_VIEW_COLUMN_FIXED);
- if (columnCount != 0) OS.gtk_tree_view_column_set_visible (columnHandle, false);
- }
- OS.gtk_tree_view_column_set_resizable (columnHandle, true);
- OS.gtk_tree_view_column_set_clickable (columnHandle, true);
- OS.gtk_tree_view_column_set_min_width (columnHandle, 0);
- OS.gtk_tree_view_insert_column (handle, columnHandle, index);
- if (column != null) {
- column.handle = columnHandle;
- column.modelIndex = modelIndex;
- }
- /* Disable searching when using VIRTUAL */
- if ((style & SWT.VIRTUAL) != 0) {
- /*
- * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE)
- * would prevent the user from being able to type in text to search the tree.
- * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive
- * search. This meant that even if FALSE was passed to enable_search, the user
- * can still bring up the search pop up using the keybinding. GTK also introduced
- * the notion of passing a -1 to gtk_set_search_column to disable searching
- * (including the search key binding). The fix is to use the right calls
- * for the right version.
- */
- if (OS.GTK_VERSION >= OS.VERSION (2, 6, 5)) {
- OS.gtk_tree_view_set_search_column (handle, -1);
- } else {
- OS.gtk_tree_view_set_enable_search (handle, false);
- }
- } else {
- /* Set the search column whenever the model changes */
- int firstColumn = columnCount == 0 ? FIRST_COLUMN : columns [0].modelIndex;
- OS.gtk_tree_view_set_search_column (handle, firstColumn + CELL_TEXT);
- }
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (fixedHandle, true);
- scrolledHandle = OS.gtk_scrolled_window_new (0, 0);
- if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ [] types = getColumnTypes (1);
- modelHandle = OS.gtk_list_store_newv (types.length, types);
- if (modelHandle == 0) error (SWT.ERROR_NO_HANDLES);
- handle = OS.gtk_tree_view_new_with_model (modelHandle);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.CHECK) != 0) {
- checkRenderer = OS.gtk_cell_renderer_toggle_new ();
- if (checkRenderer == 0) error (SWT.ERROR_NO_HANDLES);
- OS.g_object_ref (checkRenderer);
- }
- createColumn (null, 0);
- OS.gtk_container_add (fixedHandle, scrolledHandle);
- OS.gtk_container_add (scrolledHandle, handle);
-
- int mode = (style & SWT.MULTI) != 0 ? OS.GTK_SELECTION_MULTIPLE : OS.GTK_SELECTION_BROWSE;
- int /*long*/ selectionHandle = OS.gtk_tree_view_get_selection (handle);
- OS.gtk_tree_selection_set_mode (selectionHandle, mode);
- OS.gtk_tree_view_set_headers_visible (handle, false);
- int hsp = (style & SWT.H_SCROLL) != 0 ? OS.GTK_POLICY_AUTOMATIC : OS.GTK_POLICY_NEVER;
- int vsp = (style & SWT.V_SCROLL) != 0 ? OS.GTK_POLICY_AUTOMATIC : OS.GTK_POLICY_NEVER;
- OS.gtk_scrolled_window_set_policy (scrolledHandle, hsp, vsp);
- if ((style & SWT.BORDER) != 0) OS.gtk_scrolled_window_set_shadow_type (scrolledHandle, OS.GTK_SHADOW_ETCHED_IN);
- /* Disable searching when using VIRTUAL */
- if ((style & SWT.VIRTUAL) != 0) {
- /* The fixed_height_mode property only exists in GTK 2.3.2 and greater */
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2)) {
- OS.g_object_set (handle, OS.fixed_height_mode, true, 0);
- }
- /*
- * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE)
- * would prevent the user from being able to type in text to search the tree.
- * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive
- * search. This meant that even if FALSE was passed to enable_search, the user
- * can still bring up the search pop up using the keybinding. GTK also introduced
- * the notion of passing a -1 to gtk_set_search_column to disable searching
- * (including the search key binding). The fix is to use the right calls
- * for the right version.
- */
- if (OS.GTK_VERSION >= OS.VERSION (2, 6, 5)) {
- OS.gtk_tree_view_set_search_column (handle, -1);
- } else {
- OS.gtk_tree_view_set_enable_search (handle, false);
- }
- }
-}
-
-void createItem (TableColumn column, int index) {
- if (!(0 <= index && index <= columnCount)) error (SWT.ERROR_INVALID_RANGE);
- if (columnCount == 0) {
- column.handle = OS.gtk_tree_view_get_column (handle, 0);
- OS.gtk_tree_view_column_set_sizing (column.handle, OS.GTK_TREE_VIEW_COLUMN_FIXED);
- OS.gtk_tree_view_column_set_visible (column.handle, false);
- column.modelIndex = FIRST_COLUMN;
- createRenderers (column.handle, column.modelIndex, true, column.style);
- column.customDraw = firstCustomDraw;
- firstCustomDraw = false;
- } else {
- createColumn (column, index);
- }
- int /*long*/ boxHandle = OS.gtk_hbox_new (false, 3);
- if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ labelHandle = OS.gtk_label_new_with_mnemonic (null);
- if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ imageHandle = OS.gtk_image_new ();
- if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (boxHandle, imageHandle);
- OS.gtk_container_add (boxHandle, labelHandle);
- OS.gtk_widget_show (boxHandle);
- OS.gtk_widget_show (labelHandle);
- column.labelHandle = labelHandle;
- column.imageHandle = imageHandle;
- OS.gtk_tree_view_column_set_widget (column.handle, boxHandle);
- int /*long*/ widget = OS.gtk_widget_get_parent (boxHandle);
- while (widget != handle) {
- if (OS.GTK_IS_BUTTON (widget)) {
- column.buttonHandle = widget;
- break;
- }
- widget = OS.gtk_widget_get_parent (widget);
- }
- if (columnCount == columns.length) {
- TableColumn [] newColumns = new TableColumn [columns.length + 4];
- System.arraycopy (columns, 0, newColumns, 0, columns.length);
- columns = newColumns;
- }
- System.arraycopy (columns, index, columns, index + 1, columnCount++ - index);
- columns [index] = column;
- if ((state & FONT) != 0) {
- column.setFontDescription (getFontDescription ());
- }
- if (columnCount >= 1) {
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (item != null) {
- Font [] cellFont = item.cellFont;
- if (cellFont != null) {
- Font [] temp = new Font [columnCount];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index, temp, index+1, columnCount-index-1);
- item.cellFont = temp;
- }
- }
- }
- }
- /*
- * Feature in GTK. The tree view does not resize immediately if a table
- * column is created when the table is not visible. If the width of the
- * new column is queried, GTK returns an incorrect value. The fix is to
- * ensure that the columns are resized before any queries.
- */
- if(!isVisible ()) {
- OS.gtk_container_resize_children (handle);
- }
-}
-
-void createItem (TableItem item, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (itemCount == items.length) {
- int length = drawCount <= 0 ? items.length + 4 : Math.max (4, items.length * 3 / 2);
- TableItem [] newItems = new TableItem [length];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- item.handle = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (item.handle == 0) error (SWT.ERROR_NO_HANDLES);
- /*
- * Feature in GTK. It is much faster to append to a list store
- * than to insert at the end using gtk_list_store_insert().
- */
- if (index == itemCount) {
- OS.gtk_list_store_append (modelHandle, item.handle);
- } else {
- OS.gtk_list_store_insert (modelHandle, item.handle, index);
- }
- System.arraycopy (items, index, items, index + 1, itemCount++ - index);
- items [index] = item;
-}
-
-void createRenderers (int /*long*/ columnHandle, int modelIndex, boolean check, int columnStyle) {
- OS.gtk_tree_view_column_clear (columnHandle);
- if ((style & SWT.CHECK) != 0 && check) {
- OS.gtk_tree_view_column_pack_start (columnHandle, checkRenderer, false);
- OS.gtk_tree_view_column_add_attribute (columnHandle, checkRenderer, OS.active, CHECKED_COLUMN);
- /*
- * Feature in GTK. The inconsistent property only exists in GTK 2.2.x.
- */
- if (OS.GTK_VERSION >= OS.VERSION (2, 2, 0)) {
- OS.gtk_tree_view_column_add_attribute (columnHandle, checkRenderer, OS.inconsistent, GRAYED_COLUMN);
- }
- /*
- * Bug in GTK. GTK renders the background on top of the checkbox.
- * This only happens in version 2.2.1 and earlier. The fix is not to set the background.
- */
- if (OS.GTK_VERSION > OS.VERSION (2, 2, 1)) {
- if (!ownerDraw) OS.gtk_tree_view_column_add_attribute (columnHandle, checkRenderer, OS.cell_background_gdk, BACKGROUND_COLUMN);
- }
- if (ownerDraw) {
- OS.gtk_tree_view_column_set_cell_data_func (columnHandle, checkRenderer, display.cellDataProc, handle, 0);
- OS.g_object_set_qdata (checkRenderer, Display.SWT_OBJECT_INDEX1, columnHandle);
- }
- }
- int /*long*/ pixbufRenderer = ownerDraw ? OS.g_object_new (display.gtk_cell_renderer_pixbuf_get_type (), 0) : OS.gtk_cell_renderer_pixbuf_new ();
- if (pixbufRenderer == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ textRenderer = ownerDraw ? OS.g_object_new (display.gtk_cell_renderer_text_get_type (), 0) : OS.gtk_cell_renderer_text_new ();
- if (textRenderer == 0) error (SWT.ERROR_NO_HANDLES);
-
- if (ownerDraw) {
- OS.g_object_set_qdata (pixbufRenderer, Display.SWT_OBJECT_INDEX1, columnHandle);
- OS.g_object_set_qdata (textRenderer, Display.SWT_OBJECT_INDEX1, columnHandle);
- }
-
- /*
- * Feature in GTK. When a tree view column contains only one activatable
- * cell renderer such as a toggle renderer, mouse clicks anywhere in a cell
- * activate that renderer. The workaround is to set a second cell renderer
- * to be activatable.
- */
- if ((style & SWT.CHECK) != 0 && check) {
- OS.g_object_set (pixbufRenderer, OS.mode, OS.GTK_CELL_RENDERER_MODE_ACTIVATABLE, 0);
- }
-
- /* Set alignment */
- if ((columnStyle & SWT.RIGHT) != 0) {
- OS.g_object_set(textRenderer, OS.xalign, 1f, 0);
- OS.gtk_tree_view_column_pack_end (columnHandle, textRenderer, true);
- OS.gtk_tree_view_column_pack_end (columnHandle, pixbufRenderer, false);
- OS.gtk_tree_view_column_set_alignment (columnHandle, 1f);
- } else if ((columnStyle & SWT.CENTER) != 0) {
- OS.g_object_set(textRenderer, OS.xalign, 0.5f, 0);
- OS.gtk_tree_view_column_pack_start (columnHandle, pixbufRenderer, false);
- OS.gtk_tree_view_column_pack_end (columnHandle, textRenderer, true);
- OS.gtk_tree_view_column_set_alignment (columnHandle, 0.5f);
- } else {
- OS.gtk_tree_view_column_pack_start (columnHandle, pixbufRenderer, false);
- OS.gtk_tree_view_column_pack_start (columnHandle, textRenderer, true);
- OS.gtk_tree_view_column_set_alignment (columnHandle, 0f);
- }
-
- /* Add attributes */
- OS.gtk_tree_view_column_add_attribute (columnHandle, pixbufRenderer, OS.pixbuf, modelIndex + CELL_PIXBUF);
- /*
- * Bug on GTK. Gtk renders the background on top of the pixbuf.
- * This only happens in version 2.2.1 and earlier. The fix is not to set the background.
- */
- if (OS.GTK_VERSION > OS.VERSION (2, 2, 1)) {
- if (!ownerDraw) {
- OS.gtk_tree_view_column_add_attribute (columnHandle, pixbufRenderer, OS.cell_background_gdk, BACKGROUND_COLUMN);
- OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.cell_background_gdk, BACKGROUND_COLUMN);
- }
- }
- OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.text, modelIndex + CELL_TEXT);
- OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.foreground_gdk, FOREGROUND_COLUMN);
- OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.font_desc, FONT_COLUMN);
-
- boolean customDraw = firstCustomDraw;
- if (columnCount != 0) {
- for (int i=0; i<columnCount; i++) {
- if (columns [i].handle == columnHandle) {
- customDraw = columns [i].customDraw;
- break;
- }
- }
- }
- if ((style & SWT.VIRTUAL) != 0 || customDraw || ownerDraw) {
- OS.gtk_tree_view_column_set_cell_data_func (columnHandle, textRenderer, display.cellDataProc, handle, 0);
- OS.gtk_tree_view_column_set_cell_data_func (columnHandle, pixbufRenderer, display.cellDataProc, handle, 0);
- }
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- items = new TableItem [4];
- columns = new TableColumn [4];
- itemCount = columnCount = 0;
-}
-
-GdkColor defaultBackground () {
- return display.COLOR_LIST_BACKGROUND;
-}
-
-GdkColor defaultForeground () {
- return display.COLOR_LIST_FOREGROUND;
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (OS.gtk_tree_view_get_selection (handle));
- if (checkRenderer != 0) display.removeWidget (checkRenderer);
- display.removeWidget (modelHandle);
-}
-
-/**
- * Deselects the item at the given zero-relative index in the receiver.
- * If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget();
- if (index < 0 || index >= itemCount) return;
- boolean fixColumn = showFirstColumn ();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_selection_unselect_iter (selection, _getItem (index).handle);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- if (fixColumn) hideFirstColumn ();
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. The range of the
- * indices is inclusive. Indices that are out of range are ignored.
- *
- * @param start the start index of the items to deselect
- * @param end the end index of the items to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int start, int end) {
- checkWidget();
- boolean fixColumn = showFirstColumn ();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- for (int index=start; index<=end; index++) {
- if (index < 0 || index >= itemCount) continue;
- OS.gtk_tree_selection_unselect_iter (selection, _getItem (index).handle);
- }
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- if (fixColumn) hideFirstColumn ();
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. Indices that are out
- * of range and duplicate indices are ignored.
- *
- * @param indices the array of indices for the items to deselect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int [] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- boolean fixColumn = showFirstColumn ();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- for (int i=0; i<indices.length; i++) {
- int index = indices[i];
- if (index < 0 || index >= itemCount) continue;
- OS.gtk_tree_selection_unselect_iter (selection, _getItem (index).handle);
- }
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- if (fixColumn) hideFirstColumn ();
-}
-
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll () {
- checkWidget();
- boolean fixColumn = showFirstColumn ();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_selection_unselect_all (selection);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- if (fixColumn) hideFirstColumn ();
-}
-
-void destroyItem (TableColumn column) {
- int index = 0;
- while (index < columnCount) {
- if (columns [index] == column) break;
- index++;
- }
- if (index == columnCount) return;
- int /*long*/ columnHandle = column.handle;
- if (columnCount == 1) {
- firstCustomDraw = column.customDraw;
- }
- System.arraycopy (columns, index + 1, columns, index, --columnCount - index);
- columns [columnCount] = null;
- OS.gtk_tree_view_remove_column (handle, columnHandle);
- if (columnCount == 0) {
- int /*long*/ oldModel = modelHandle;
- int /*long*/[] types = getColumnTypes (1);
- int /*long*/ newModel = OS.gtk_list_store_newv (types.length, types);
- if (newModel == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ [] ptr = new int /*long*/ [1];
- for (int i=0; i<itemCount; i++) {
- int /*long*/ newItem = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (newItem == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_list_store_append (newModel, newItem);
- TableItem item = items [i];
- if (item != null) {
- int /*long*/ oldItem = item.handle;
- for (int j=0; j<FIRST_COLUMN; j++) {
- OS.gtk_tree_model_get (oldModel, oldItem, j, ptr, -1);
- OS.gtk_list_store_set (newModel, newItem, j, ptr [0], -1);
- }
- OS.gtk_tree_model_get (oldModel, oldItem, column.modelIndex + CELL_PIXBUF, ptr, -1);
- OS.gtk_list_store_set (newModel, newItem, FIRST_COLUMN + CELL_PIXBUF, ptr [0], -1);
- OS.gtk_tree_model_get (oldModel, oldItem, column.modelIndex + CELL_TEXT, ptr, -1);
- OS.gtk_list_store_set (newModel, newItem, FIRST_COLUMN + CELL_TEXT, ptr [0], -1);
- OS.g_free (ptr [0]);
- OS.gtk_tree_model_get (oldModel, oldItem, column.modelIndex + CELL_FOREGROUND, ptr, -1);
- OS.gtk_list_store_set (newModel, newItem, FIRST_COLUMN + CELL_FOREGROUND, ptr [0], -1);
- OS.gtk_tree_model_get (oldModel, oldItem, column.modelIndex + CELL_BACKGROUND, ptr, -1);
- OS.gtk_list_store_set (newModel, newItem, FIRST_COLUMN + CELL_BACKGROUND, ptr [0], -1);
- OS.gtk_tree_model_get (oldModel, oldItem, column.modelIndex + CELL_FONT, ptr, -1);
- OS.gtk_list_store_set (newModel, newItem, FIRST_COLUMN + CELL_FONT, ptr [0], -1);
- OS.gtk_list_store_remove (oldModel, oldItem);
- OS.g_free (oldItem);
- item.handle = newItem;
- } else {
- OS.g_free (newItem);
- }
- }
- OS.gtk_tree_view_set_model (handle, newModel);
- OS.g_object_unref (oldModel);
- modelHandle = newModel;
- createColumn (null, 0);
- } else {
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (item != null) {
- int /*long*/ iter = item.handle;
- int modelIndex = column.modelIndex;
- OS.gtk_list_store_set (modelHandle, iter, modelIndex + CELL_PIXBUF, 0, -1);
- OS.gtk_list_store_set (modelHandle, iter, modelIndex + CELL_TEXT, 0, -1);
- OS.gtk_list_store_set (modelHandle, iter, modelIndex + CELL_FOREGROUND, 0, -1);
- OS.gtk_list_store_set (modelHandle, iter, modelIndex + CELL_BACKGROUND, 0, -1);
- OS.gtk_list_store_set (modelHandle, iter, modelIndex + CELL_FONT, 0, -1);
-
- Font [] cellFont = item.cellFont;
- if (cellFont != null) {
- if (columnCount == 0) {
- item.cellFont = null;
- } else {
- Font [] temp = new Font [columnCount];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index + 1, temp, index, columnCount - index);
- item.cellFont = temp;
- }
- }
- }
- }
- if (index == 0) {
- TableColumn checkColumn = columns [0];
- createRenderers (checkColumn.handle, checkColumn.modelIndex, true, checkColumn.style);
- }
- }
- /* Disable searching when using VIRTUAL */
- if ((style & SWT.VIRTUAL) != 0) {
- /*
- * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE)
- * would prevent the user from being able to type in text to search the tree.
- * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive
- * search. This meant that even if FALSE was passed to enable_search, the user
- * can still bring up the search pop up using the keybinding. GTK also introduced
- * the notion of passing a -1 to gtk_set_search_column to disable searching
- * (including the search key binding). The fix is to use the right calls
- * for the right version.
- */
- if (OS.GTK_VERSION >= OS.VERSION (2, 6, 5)) {
- OS.gtk_tree_view_set_search_column (handle, -1);
- } else {
- OS.gtk_tree_view_set_enable_search (handle, false);
- }
- } else {
- /* Set the search column whenever the model changes */
- int firstColumn = columnCount == 0 ? FIRST_COLUMN : columns [0].modelIndex;
- OS.gtk_tree_view_set_search_column (handle, firstColumn + CELL_TEXT);
- }
-}
-
-void destroyItem (TableItem item) {
- int index = 0;
- while (index < itemCount) {
- if (items [index] == item) break;
- index++;
- }
- if (index == itemCount) return;
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_list_store_remove (modelHandle, item.handle);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- if (itemCount == 0) resetCustomDraw ();
-}
-
-boolean dragDetect (int x, int y, boolean filter, boolean [] consume) {
- boolean selected = false;
- if (filter) {
- int /*long*/ [] path = new int /*long*/ [1];
- if (OS.gtk_tree_view_get_path_at_pos (handle, x, y, path, null, null, null)) {
- if (path [0] != 0) {
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- if (OS.gtk_tree_selection_path_is_selected (selection, path [0])) selected = true;
- OS.gtk_tree_path_free (path [0]);
- }
- } else {
- return false;
- }
- }
- boolean dragDetect = super.dragDetect (x, y, filter, consume);
- if (dragDetect && selected && consume != null) consume [0] = true;
- return dragDetect;
-}
-
-int /*long*/ eventWindow () {
- return paintWindow ();
-}
-
-boolean fixAccessibility () {
- /*
- * Bug in GTK. With GTK 2.12, when assistive technologies is on, the time
- * it takes to add or remove several rows to the model is very long. This
- * happens because the accessible object asks each row for its data, including
- * the rows that are not visible. The the fix is to block the accessible object
- * from receiving row_added and row_removed signals and, at the end, send only
- * a notify signal with the "model" detail.
- *
- * Note: The test bellow has to be updated when the real problem is fixed in
- * the accessible object.
- */
- return OS.GTK_VERSION >= OS.VERSION (2, 12, 0);
-}
-
-void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) {
- super.fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
- for (int i=0; i<columnCount; i++) {
- TableColumn column = columns [i];
- if (column.toolTipText != null) {
- column.setToolTipText(oldShell, null);
- column.setToolTipText(newShell, column.toolTipText);
- }
- }
-}
-
-GdkColor getBackgroundColor () {
- return getBaseColor ();
-}
-
-public Rectangle getClientArea () {
- checkWidget ();
- forceResize ();
- OS.gtk_widget_realize (handle);
- int /*long*/ fixedWindow = OS.GTK_WIDGET_WINDOW (fixedHandle);
- int /*long*/ binWindow = OS.gtk_tree_view_get_bin_window (handle);
- int [] binX = new int [1], binY = new int [1];
- OS.gdk_window_get_origin (binWindow, binX, binY);
- int [] fixedX = new int [1], fixedY = new int [1];
- OS.gdk_window_get_origin (fixedWindow, fixedX, fixedY);
- int /*long*/ clientHandle = clientHandle ();
- int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (clientHandle);
- int height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (clientHandle);
- return new Rectangle (fixedX [0] - binX [0], fixedY [0] - binY [0], width, height);
-}
-
-int getClientWidth () {
- int [] w = new int [1], h = new int [1];
- OS.gtk_widget_realize (handle);
- OS.gdk_drawable_get_size(OS.gtk_tree_view_get_bin_window(handle), w, h);
- return w[0];
-}
-
-/**
- * Returns the column at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- * Columns are returned in the order that they were created.
- * If no <code>TableColumn</code>s were created by the programmer,
- * this method will throw <code>ERROR_INVALID_RANGE</code> despite
- * the fact that a single column of data may be visible in the table.
- * This occurs when the programmer uses the table like a list, adding
- * items but never creating a column.
- *
- * @param index the index of the column to return
- * @return the column at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- */
-public TableColumn getColumn (int index) {
- checkWidget();
- if (!(0 <= index && index < columnCount)) error (SWT.ERROR_INVALID_RANGE);
- return columns [index];
-}
-
-/**
- * Returns the number of columns contained in the receiver.
- * If no <code>TableColumn</code>s were created by the programmer,
- * this value is zero, despite the fact that visually, one column
- * of items may be visible. This occurs when the programmer uses
- * the table like a list, adding items but never creating a column.
- *
- * @return the number of columns
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getColumnCount () {
- checkWidget();
- return columnCount;
-}
-
-int /*long*/[] getColumnTypes (int columnCount) {
- int /*long*/[] types = new int /*long*/ [FIRST_COLUMN + (columnCount * CELL_TYPES)];
- // per row data
- types [CHECKED_COLUMN] = OS.G_TYPE_BOOLEAN ();
- types [GRAYED_COLUMN] = OS.G_TYPE_BOOLEAN ();
- types [FOREGROUND_COLUMN] = OS.GDK_TYPE_COLOR ();
- types [BACKGROUND_COLUMN] = OS.GDK_TYPE_COLOR ();
- types [FONT_COLUMN] = OS.PANGO_TYPE_FONT_DESCRIPTION ();
- // per cell data
- for (int i=FIRST_COLUMN; i<types.length; i+=CELL_TYPES) {
- types [i + CELL_PIXBUF] = OS.GDK_TYPE_PIXBUF ();
- types [i + CELL_TEXT] = OS.G_TYPE_STRING ();
- types [i + CELL_FOREGROUND] = OS.GDK_TYPE_COLOR ();
- types [i + CELL_BACKGROUND] = OS.GDK_TYPE_COLOR ();
- types [i + CELL_FONT] = OS.PANGO_TYPE_FONT_DESCRIPTION ();
- }
- return types;
-}
-
-/**
- * Returns an array of zero-relative integers that map
- * the creation order of the receiver's items to the
- * order in which they are currently being displayed.
- * <p>
- * Specifically, the indices of the returned array represent
- * the current visual order of the items, and the contents
- * of the array represent the creation order of the items.
- * </p><p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the current visual order of the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public int [] getColumnOrder () {
- checkWidget ();
- if (columnCount == 0) return new int [0];
- int /*long*/ list = OS.gtk_tree_view_get_columns (handle);
- if (list == 0) return new int [0];
- int i = 0, count = OS.g_list_length (list);
- int [] order = new int [count];
- int /*long*/ temp = list;
- while (temp != 0) {
- int /*long*/ column = OS.g_list_data (temp);
- if (column != 0) {
- for (int j=0; j<columnCount; j++) {
- if (columns [j].handle == column) {
- order [i++] = j;
- break;
- }
- }
- }
- temp = OS.g_list_next (temp);
- }
- OS.g_list_free (list);
- return order;
-}
-
-/**
- * Returns an array of <code>TableColumn</code>s which are the
- * columns in the receiver. Columns are returned in the order
- * that they were created. If no <code>TableColumn</code>s were
- * created by the programmer, the array is empty, despite the fact
- * that visually, one column of items may be visible. This occurs
- * when the programmer uses the table like a list, adding items but
- * never creating a column.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- */
-public TableColumn [] getColumns () {
- checkWidget();
- TableColumn [] result = new TableColumn [columnCount];
- System.arraycopy (columns, 0, result, 0, columnCount);
- return result;
-}
-
-TableItem getFocusItem () {
- int /*long*/ [] path = new int /*long*/ [1];
- OS.gtk_tree_view_get_cursor (handle, path, null);
- if (path [0] == 0) return null;
- TableItem item = null;
- int /*long*/ indices = OS.gtk_tree_path_get_indices (path [0]);
- if (indices != 0) {
- int [] index = new int []{-1};
- OS.memmove (index, indices, 4);
- item = _getItem (index [0]);
- }
- OS.gtk_tree_path_free (path [0]);
- return item;
-}
-
-GdkColor getForegroundColor () {
- return getTextColor ();
-}
-
-/**
- * Returns the width in pixels of a grid line.
- *
- * @return the width of a grid line in pixels
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getGridLineWidth () {
- checkWidget();
- return 0;
-}
-
-/**
- * Returns the height of the receiver's header
- *
- * @return the height of the header or zero if the header is not visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public int getHeaderHeight () {
- checkWidget ();
- if (!OS.gtk_tree_view_get_headers_visible (handle)) return 0;
- if (columnCount > 0) {
- GtkRequisition requisition = new GtkRequisition ();
- int height = 0;
- for (int i=0; i<columnCount; i++) {
- int /*long*/ buttonHandle = columns [i].buttonHandle;
- if (buttonHandle != 0) {
- OS.gtk_widget_size_request (buttonHandle, requisition);
- height = Math.max (height, requisition.height);
- }
- }
- return height;
- }
- OS.gtk_widget_realize (handle);
- int /*long*/ fixedWindow = OS.GTK_WIDGET_WINDOW (fixedHandle);
- int /*long*/ binWindow = OS.gtk_tree_view_get_bin_window (handle);
- int [] binY = new int [1];
- OS.gdk_window_get_origin (binWindow, null, binY);
- int [] fixedY = new int [1];
- OS.gdk_window_get_origin (fixedWindow, null, fixedY);
- return binY [0] - fixedY [0];
-}
-
-/**
- * Returns <code>true</code> if the receiver's header is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's header's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getHeaderVisible () {
- checkWidget();
- return OS.gtk_tree_view_get_headers_visible (handle);
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem getItem (int index) {
- checkWidget();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- return _getItem (index);
-}
-
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- * <p>
- * The item that is returned represents an item that could be selected by the user.
- * For example, if selection only occurs in items in the first column, then null is
- * returned if the point is outside of the item.
- * Note that the SWT.FULL_SELECTION style hint, which specifies the selection policy,
- * determines the extent of the selection.
- * </p>
- *
- * @param point the point used to locate the item
- * @return the item at the given point, or null if the point is not in a selectable item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem getItem (Point point) {
- checkWidget();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- int /*long*/ [] path = new int /*long*/ [1];
- OS.gtk_widget_realize (handle);
- if (!OS.gtk_tree_view_get_path_at_pos (handle, point.x, point.y, path, null, null, null)) return null;
- if (path [0] == 0) return null;
- int /*long*/ indices = OS.gtk_tree_path_get_indices (path [0]);
- TableItem item = null;
- if (indices != 0) {
- int [] index = new int [1];
- OS.memmove (index, indices, 4);
- item = _getItem (index [0]);
- }
- OS.gtk_tree_path_free (path [0]);
- return item;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return itemCount;
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the receiver.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget();
- if (itemCount == 0) {
- int /*long*/ column = OS.gtk_tree_view_get_column (handle, 0);
- int [] w = new int [1], h = new int [1];
- ignoreSize = true;
- OS.gtk_tree_view_column_cell_get_size (column, null, null, null, w, h);
- ignoreSize = false;
- return h [0];
- } else {
- int height = 0;
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- OS.gtk_tree_model_get_iter_first (modelHandle, iter);
- int columnCount = Math.max (1, this.columnCount);
- for (int i=0; i<columnCount; i++) {
- int /*long*/ column = OS.gtk_tree_view_get_column (handle, i);
- OS.gtk_tree_view_column_cell_set_cell_data (column, modelHandle, iter, false, false);
- int [] w = new int [1], h = new int [1];
- OS.gtk_tree_view_column_cell_get_size (column, null, null, null, w, h);
- height = Math.max (height, h [0]);
- }
- OS.g_free (iter);
- return height;
- }
-}
-
-/**
- * Returns a (possibly empty) array of <code>TableItem</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem [] getItems () {
- checkWidget();
- TableItem [] result = new TableItem [itemCount];
- if ((style & SWT.VIRTUAL) != 0) {
- for (int i=0; i<itemCount; i++) {
- result [i] = _getItem (i);
- }
- } else {
- System.arraycopy (items, 0, result, 0, itemCount);
- }
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver's lines are visible,
- * and <code>false</code> otherwise. Note that some platforms draw
- * grid lines while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the visibility state of the lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getLinesVisible() {
- checkWidget();
- return OS.gtk_tree_view_get_rules_hint (handle);
-}
-
-int /*long*/ getPixbufRenderer (int /*long*/ column) {
- int /*long*/ list = OS.gtk_tree_view_column_get_cell_renderers (column);
- if (list == 0) return 0;
- int count = OS.g_list_length (list);
- int /*long*/ pixbufRenderer = 0;
- int i = 0;
- while (i < count) {
- int /*long*/ renderer = OS.g_list_nth_data (list, i);
- if (OS.GTK_IS_CELL_RENDERER_PIXBUF (renderer)) {
- pixbufRenderer = renderer;
- break;
- }
- i++;
- }
- OS.g_list_free (list);
- return pixbufRenderer;
-}
-
-/**
- * Returns an array of <code>TableItem</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem [] getSelection () {
- checkWidget();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) {
- display.treeSelectionLength = 0;
- display.treeSelection = new int [itemCount];
- OS.gtk_tree_selection_selected_foreach (selection, display.treeSelectionProc, handle);
- TableItem [] result = new TableItem [display.treeSelectionLength];
- for (int i=0; i<result.length; i++) result [i] = _getItem (display.treeSelection [i]);
- return result;
- }
- /*
- * Bug in GTK. gtk_tree_selection_get_selected_rows() segmentation faults
- * in versions smaller than 2.2.4 if the model is NULL. The fix is
- * to give a valid pointer instead.
- */
- int /*long*/ [] model = OS.GTK_VERSION < OS.VERSION (2, 2, 4) ? new int /*long*/ [1] : null;
- int /*long*/ list = OS.gtk_tree_selection_get_selected_rows (selection, model);
- if (list != 0) {
- int count = OS.g_list_length (list);
- int [] treeSelection = new int [count];
- int length = 0;
- for (int i=0; i<count; i++) {
- int /*long*/ data = OS.g_list_nth_data (list, i);
- int /*long*/ indices = OS.gtk_tree_path_get_indices (data);
- if (indices != 0) {
- int [] index = new int [1];
- OS.memmove (index, indices, 4);
- treeSelection [length] = index [0];
- length++;
- }
- }
- OS.g_list_free (list);
- TableItem [] result = new TableItem [length];
- for (int i=0; i<result.length; i++) result [i] = _getItem (treeSelection [i]);
- return result;
- }
- return new TableItem [0];
-}
-
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) {
- display.treeSelectionLength = 0;
- display.treeSelection = null;
- OS.gtk_tree_selection_selected_foreach (selection, display.treeSelectionProc, handle);
- return display.treeSelectionLength;
- }
- return OS.gtk_tree_selection_count_selected_rows (selection);
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget();
- if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) {
- display.treeSelectionLength = 0;
- display.treeSelection = new int [itemCount];
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.gtk_tree_selection_selected_foreach (selection, display.treeSelectionProc, handle);
- if (display.treeSelectionLength == 0) return -1;
- return display.treeSelection [0];
- }
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- /*
- * Bug in GTK. gtk_tree_selection_get_selected_rows() segmentation faults
- * in versions smaller than 2.2.4 if the model is NULL. The fix is
- * to give a valid pointer instead.
- */
- int /*long*/ [] model = OS.GTK_VERSION < OS.VERSION (2, 2, 4) ? new int /*long*/ [1] : null;
- int /*long*/ list = OS.gtk_tree_selection_get_selected_rows (selection, model);
- if (list != 0) {
- int count = OS.g_list_length (list);
- int [] index = new int [1];
- for (int i=0; i<count; i++) {
- int /*long*/ data = OS.g_list_nth_data (list, i);
- int /*long*/ indices = OS.gtk_tree_path_get_indices (data);
- if (indices != 0) {
- OS.memmove (index, indices, 4);
- break;
- }
- }
- OS.g_list_free (list);
- return index [0];
- }
- return -1;
-}
-
-/**
- * Returns the zero-relative indices of the items which are currently
- * selected in the receiver. The order of the indices is unspecified.
- * The array is empty if no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return the array of indices of the selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int [] getSelectionIndices () {
- checkWidget();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) {
- display.treeSelectionLength = 0;
- display.treeSelection = new int [itemCount];
- OS.gtk_tree_selection_selected_foreach (selection, display.treeSelectionProc, handle);
- if (display.treeSelectionLength == display.treeSelection.length) return display.treeSelection;
- int [] result = new int [display.treeSelectionLength];
- System.arraycopy (display.treeSelection, 0, result, 0, display.treeSelectionLength);
- return result;
- }
- /*
- * Bug in GTK. gtk_tree_selection_get_selected_rows() segmentation faults
- * in versions smaller than 2.2.4 if the model is NULL. The fix is
- * to give a valid pointer instead.
- */
- int /*long*/ [] model = OS.GTK_VERSION < OS.VERSION (2, 2, 4) ? new int /*long*/ [1] : null;
- int /*long*/ list = OS.gtk_tree_selection_get_selected_rows (selection, model);
- if (list != 0) {
- int count = OS.g_list_length (list);
- int [] treeSelection = new int [count];
- int length = 0;
- for (int i=0; i<count; i++) {
- int /*long*/ data = OS.g_list_nth_data (list, i);
- int /*long*/ indices = OS.gtk_tree_path_get_indices (data);
- if (indices != 0) {
- int [] index = new int [1];
- OS.memmove (index, indices, 4);
- treeSelection [length] = index [0];
- length++;
- }
- }
- OS.g_list_free (list);
- int [] result = new int [length];
- System.arraycopy (treeSelection, 0, result, 0, length);
- return result;
- }
- return new int [0];
-}
-
-/**
- * Returns the column which shows the sort indicator for
- * the receiver. The value may be null if no column shows
- * the sort indicator.
- *
- * @return the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortColumn(TableColumn)
- *
- * @since 3.2
- */
-public TableColumn getSortColumn () {
- checkWidget ();
- return sortColumn;
-}
-
-/**
- * Returns the direction of the sort indicator for the receiver.
- * The value will be one of <code>UP</code>, <code>DOWN</code>
- * or <code>NONE</code>.
- *
- * @return the sort direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortDirection(int)
- *
- * @since 3.2
- */
-public int getSortDirection () {
- checkWidget ();
- return sortDirection;
-}
-
-int /*long*/ getTextRenderer (int /*long*/ column) {
- int /*long*/ list = OS.gtk_tree_view_column_get_cell_renderers (column);
- if (list == 0) return 0;
- int count = OS.g_list_length (list);
- int /*long*/ textRenderer = 0;
- int i = 0;
- while (i < count) {
- int /*long*/ renderer = OS.g_list_nth_data (list, i);
- if (OS.GTK_IS_CELL_RENDERER_TEXT (renderer)) {
- textRenderer = renderer;
- break;
- }
- i++;
- }
- OS.g_list_free (list);
- return textRenderer;
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items are
- * scrolled or new items are added or removed.
- *
- * @return the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget();
- int /*long*/ [] path = new int /*long*/ [1];
- OS.gtk_widget_realize (handle);
- if (!OS.gtk_tree_view_get_path_at_pos (handle, 1, 1, path, null, null, null)) return 0;
- if (path [0] == 0) return 0;
- int /*long*/ indices = OS.gtk_tree_path_get_indices (path[0]);
- int[] index = new int [1];
- if (indices != 0) OS.memmove (index, indices, 4);
- OS.gtk_tree_path_free (path [0]);
- return index [0];
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
- if (gdkEvent.window != OS.gtk_tree_view_get_bin_window (handle)) return 0;
- int /*long*/ result = super.gtk_button_press_event (widget, event);
- if (result != 0) return result;
- /*
- * Feature in GTK. In a multi-select table view, when multiple items are already
- * selected, the selection state of the item is toggled and the previous selection
- * is cleared. This is not the desired behaviour when bringing up a popup menu.
- * Also, when an item is reselected with the right button, the tree view issues
- * an unwanted selection event. The workaround is to detect that case and not
- * run the default handler when the item is already part of the current selection.
- */
- int button = gdkEvent.button;
- if (button == 3 && gdkEvent.type == OS.GDK_BUTTON_PRESS) {
- int /*long*/ [] path = new int /*long*/ [1];
- if (OS.gtk_tree_view_get_path_at_pos (handle, (int)gdkEvent.x, (int)gdkEvent.y, path, null, null, null)) {
- if (path [0] != 0) {
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- if (OS.gtk_tree_selection_path_is_selected (selection, path [0])) result = 1;
- OS.gtk_tree_path_free (path [0]);
- }
- }
- }
-
- /*
- * Feature in GTK. When the user clicks in a single selection GtkTreeView
- * and there are no selected items, the first item is selected automatically
- * before the click is processed, causing two selection events. The is fix
- * is the set the cursor item to be same as the clicked item to stop the
- * widget from automatically selecting the first item.
- */
- if ((style & SWT.SINGLE) != 0 && getSelectionCount () == 0) {
- int /*long*/ [] path = new int /*long*/ [1];
- if (OS.gtk_tree_view_get_path_at_pos (handle, (int)gdkEvent.x, (int)gdkEvent.y, path, null, null, null)) {
- if (path [0] != 0) {
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_view_set_cursor (handle, path [0], 0, false);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_path_free (path [0]);
- }
- }
- }
- /*
- * Bug in GTK. GTK segments fault, if the GtkTreeView widget is
- * not in focus and all items in the widget are disposed before
- * it finishes processing a button press. The fix is to give
- * focus to the widget before it starts processing the event.
- */
- if (!OS.GTK_WIDGET_HAS_FOCUS (handle)) {
- OS.gtk_widget_grab_focus (handle);
- }
- return result;
-}
-
-int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ window = OS.GDK_EVENT_WINDOW (event);
- if (window != OS.gtk_tree_view_get_bin_window (handle)) return 0;
- return super.gtk_button_release_event (widget, event);
-}
-
-int /*long*/ gtk_changed (int /*long*/ widget) {
- TableItem item = getFocusItem ();
- if (item != null) {
- Event event = new Event ();
- event.item = item;
- postEvent (SWT.Selection, event);
- }
- return 0;
-}
-
-int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ eventPtr) {
- int /*long*/ result = super.gtk_key_press_event (widget, eventPtr);
- if (result != 0) return result;
- if (OS.GTK_VERSION < OS.VERSION (2, 2 ,0)) {
- /*
- * Feature in GTK 2.0.x. When an item is default selected using
- * the return key, GTK does not issue notification. The fix is
- * to issue this notification when the return key is pressed.
- */
- GdkEventKey keyEvent = new GdkEventKey ();
- OS.memmove (keyEvent, eventPtr, GdkEventKey.sizeof);
- int key = keyEvent.keyval;
- switch (key) {
- case OS.GDK_Return:
- case OS.GDK_KP_Enter: {
- Event event = new Event ();
- event.item = getFocusItem ();
- postEvent (SWT.DefaultSelection, event);
- break;
- }
- }
- }
- return result;
-}
-
-int /*long*/ gtk_popup_menu (int /*long*/ widget) {
- int /*long*/ result = super.gtk_popup_menu (widget);
- /*
- * Bug in GTK. The context menu for the typeahead in GtkTreeViewer
- * opens in the bottom right corner of the screen when Shift+F10
- * is pressed and the typeahead window was not visible. The fix is
- * to prevent the context menu from opening by stopping the default
- * handler.
- *
- * NOTE: The bug only happens in GTK 2.6.5 and lower.
- */
- return OS.GTK_VERSION < OS.VERSION (2, 6, 5) ? 1 : result;
-}
-
-int /*long*/ gtk_motion_notify_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ window = OS.GDK_EVENT_WINDOW (event);
- if (window != OS.gtk_tree_view_get_bin_window (handle)) return 0;
- return super.gtk_motion_notify_event (widget, event);
-}
-
-int /*long*/ gtk_row_activated (int /*long*/ tree, int /*long*/ path, int /*long*/ column) {
- TableItem item = null;
- int /*long*/ indices = OS.gtk_tree_path_get_indices (path);
- if (indices != 0) {
- int [] index = new int []{-1};
- OS.memmove (index, indices, 4);
- item = _getItem (index [0]);
- }
- Event event = new Event ();
- event.item = item;
- postEvent (SWT.DefaultSelection, event);
- return 0;
-}
-
-int gtk_row_deleted (int model, int path) {
- if (ignoreAccessibility) {
- OS.g_signal_stop_emission_by_name (model, OS.row_deleted);
- }
- return 0;
-}
-
-int gtk_row_inserted (int model, int path, int iter) {
- if (ignoreAccessibility) {
- OS.g_signal_stop_emission_by_name (model, OS.row_inserted);
- }
- return 0;
-}
-
-int /*long*/ gtk_toggled (int /*long*/ renderer, int /*long*/ pathStr) {
- int /*long*/ path = OS.gtk_tree_path_new_from_string (pathStr);
- if (path == 0) return 0;
- int /*long*/ indices = OS.gtk_tree_path_get_indices (path);
- if (indices != 0) {
- int [] index = new int [1];
- OS.memmove (index, indices, 4);
- TableItem item = _getItem (index [0]);
- item.setChecked (!item.getChecked ());
- Event event = new Event ();
- event.detail = SWT.CHECK;
- event.item = item;
- postEvent (SWT.Selection, event);
- }
- OS.gtk_tree_path_free (path);
- return 0;
-}
-
-void gtk_widget_size_request (int /*long*/ widget, GtkRequisition requisition) {
- /*
- * Bug in GTK. For some reason, gtk_widget_size_request() fails
- * to include the height of the tree view items when there are
- * no columns visible. The fix is to temporarily make one column
- * visible.
- */
- if (columnCount == 0) {
- super.gtk_widget_size_request (widget, requisition);
- return;
- }
- int /*long*/ columns = OS.gtk_tree_view_get_columns (handle), list = columns;
- boolean fixVisible = columns != 0;
- while (list != 0) {
- int /*long*/ column = OS.g_list_data (list);
- if (OS.gtk_tree_view_column_get_visible (column)) {
- fixVisible = false;
- break;
- }
- list = OS.g_list_next (list);
- }
- int /*long*/ columnHandle = 0;
- if (fixVisible) {
- columnHandle = OS.g_list_data (columns);
- OS.gtk_tree_view_column_set_visible (columnHandle, true);
- }
- super.gtk_widget_size_request (widget, requisition);
- if (fixVisible) {
- OS.gtk_tree_view_column_set_visible (columnHandle, false);
- }
- if (columns != 0) OS.g_list_free (columns);
-}
-
-void hideFirstColumn () {
- int /*long*/ firstColumn = OS.gtk_tree_view_get_column (handle, 0);
- OS.gtk_tree_view_column_set_visible (firstColumn, false);
-}
-
-void hookEvents () {
- super.hookEvents ();
- int /*long*/ selection = OS.gtk_tree_view_get_selection(handle);
- OS.g_signal_connect_closure (selection, OS.changed, display.closures [CHANGED], false);
- OS.g_signal_connect_closure (handle, OS.row_activated, display.closures [ROW_ACTIVATED], false);
- if (checkRenderer != 0) {
- OS.g_signal_connect_closure (checkRenderer, OS.toggled, display.closures [TOGGLED], false);
- }
- if (fixAccessibility ()) {
- OS.g_signal_connect_closure (modelHandle, OS.row_inserted, display.closures [ROW_INSERTED], true);
- OS.g_signal_connect_closure (modelHandle, OS.row_deleted, display.closures [ROW_DELETED], true);
- }
-}
-
-/**
- * Searches the receiver's list starting at the first column
- * (index 0) until a column is found that is equal to the
- * argument, and returns the index of that column. If no column
- * is found, returns -1.
- *
- * @param column the search column
- * @return the index of the column
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the column is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (TableColumn column) {
- checkWidget();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<columnCount; i++) {
- if (columns [i] == column) return i;
- }
- return -1;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (TableItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (1 <= lastIndexOf && lastIndexOf < itemCount - 1) {
- if (items [lastIndexOf] == item) return lastIndexOf;
- if (items [lastIndexOf + 1] == item) return ++lastIndexOf;
- if (items [lastIndexOf - 1] == item) return --lastIndexOf;
- }
- if (lastIndexOf < itemCount / 2) {
- for (int i=0; i<itemCount; i++) {
- if (items [i] == item) return lastIndexOf = i;
- }
- } else {
- for (int i=itemCount - 1; i>=0; --i) {
- if (items [i] == item) return lastIndexOf = i;
- }
- }
- return -1;
-}
-
-/**
- * Returns <code>true</code> if the item is selected,
- * and <code>false</code> otherwise. Indices out of
- * range are ignored.
- *
- * @param index the index of the item
- * @return the selection state of the item at the index
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isSelected (int index) {
- checkWidget();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- byte [] buffer = Converter.wcsToMbcs (null, Integer.toString (index), true);
- int /*long*/ path = OS.gtk_tree_path_new_from_string (buffer);
- boolean answer = OS.gtk_tree_selection_path_is_selected (selection, path);
- OS.gtk_tree_path_free (path);
- return answer;
-}
-
-boolean mnemonicHit (char key) {
- for (int i=0; i<columnCount; i++) {
- int /*long*/ labelHandle = columns [i].labelHandle;
- if (labelHandle != 0 && mnemonicHit (labelHandle, key)) return true;
- }
- return false;
-}
-
-boolean mnemonicMatch (char key) {
- for (int i=0; i<columnCount; i++) {
- int /*long*/ labelHandle = columns [i].labelHandle;
- if (labelHandle != 0 && mnemonicMatch (labelHandle, key)) return true;
- }
- return false;
-}
-
-int /*long*/ paintWindow () {
- OS.gtk_widget_realize (handle);
- return OS.gtk_tree_view_get_bin_window (handle);
-}
-
-void recreateRenderers () {
- if (checkRenderer != 0) {
- display.removeWidget (checkRenderer);
- OS.g_object_unref (checkRenderer);
- checkRenderer = ownerDraw ? OS.g_object_new (display.gtk_cell_renderer_toggle_get_type(), 0) : OS.gtk_cell_renderer_toggle_new ();
- if (checkRenderer == 0) error (SWT.ERROR_NO_HANDLES);
- OS.g_object_ref (checkRenderer);
- display.addWidget (checkRenderer, this);
- OS.g_signal_connect_closure (checkRenderer, OS.toggled, display.closures [TOGGLED], false);
- }
- if (columnCount == 0) {
- createRenderers (OS.gtk_tree_view_get_column (handle, 0), Table.FIRST_COLUMN, true, 0);
- } else {
- for (int i = 0; i < columnCount; i++) {
- TableColumn column = columns [i];
- createRenderers (column.handle, column.modelIndex, i == 0, column.style);
- }
- }
-}
-
-void redrawBackgroundImage () {
- Control control = findBackgroundControl ();
- if (control != null && control.backgroundImage != null) {
- redrawWidget (0, 0, 0, 0, true, false, false);
- }
-}
-
-void register () {
- super.register ();
- display.addWidget (OS.gtk_tree_view_get_selection (handle), this);
- if (checkRenderer != 0) display.addWidget (checkRenderer, this);
- display.addWidget (modelHandle, this);
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- }
- if (columns != null) {
- for (int i=0; i<columnCount; i++) {
- TableColumn column = columns [i];
- if (column != null && !column.isDisposed ()) {
- column.release (false);
- }
- }
- columns = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (modelHandle != 0) OS.g_object_unref (modelHandle);
- modelHandle = 0;
- if (checkRenderer != 0) OS.g_object_unref (checkRenderer);
- checkRenderer = 0;
- if (imageList != null) imageList.dispose ();
- if (headerImageList != null) headerImageList.dispose ();
- imageList = headerImageList = null;
- currentItem = null;
-}
-
-/**
- * Removes the item from the receiver at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_ITEM_NOT_REMOVED);
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- TableItem item = items [index];
- boolean disposed = false;
- if (item != null) {
- disposed = item.isDisposed ();
- if (!disposed) {
- OS.memmove (iter, item.handle, OS.GtkTreeIter_sizeof ());
- item.release (false);
- }
- } else {
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- }
- if (!disposed) {
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_list_store_remove (modelHandle, iter);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- }
- OS.g_free (iter);
-}
-
-/**
- * Removes the items from the receiver which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget();
- if (start > end) return;
- if (!(0 <= start && start <= end && end < itemCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (iter == 0) error (SWT.ERROR_NO_HANDLES);
- if (fixAccessibility ()) {
- ignoreAccessibility = true;
- }
- int index = end;
- while (index >= start) {
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- TableItem item = items [index];
- if (item != null && !item.isDisposed ()) item.release (false);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_list_store_remove (modelHandle, iter);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- index--;
- }
- if (fixAccessibility ()) {
- ignoreAccessibility = false;
- OS.g_object_notify (handle, OS.model);
- }
- OS.g_free (iter);
- index = end + 1;
- System.arraycopy (items, index, items, start, itemCount - index);
- for (int i=itemCount-(index-start); i<itemCount; i++) items [i] = null;
- itemCount = itemCount - (index - start);
-}
-
-/**
- * Removes the items from the receiver's list at the given
- * zero-relative indices.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int [] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- int [] newIndices = new int [indices.length];
- System.arraycopy (indices, 0, newIndices, 0, indices.length);
- sort (newIndices);
- int start = newIndices [newIndices.length - 1], end = newIndices [0];
- if (!(0 <= start && start <= end && end < itemCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- int last = -1;
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (iter == 0) error (SWT.ERROR_NO_HANDLES);
- if (fixAccessibility ()) {
- ignoreAccessibility = true;
- }
- for (int i=0; i<newIndices.length; i++) {
- int index = newIndices [i];
- if (index != last) {
- TableItem item = items [index];
- boolean disposed = false;
- if (item != null) {
- disposed = item.isDisposed ();
- if (!disposed) {
- OS.memmove (iter, item.handle, OS.GtkTreeIter_sizeof ());
- item.release (false);
- }
- } else {
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
- }
- if (!disposed) {
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_list_store_remove (modelHandle, iter);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- }
- last = index;
- }
- }
- if (fixAccessibility ()) {
- ignoreAccessibility = false;
- OS.g_object_notify (handle, OS.model);
- }
- OS.g_free (iter);
-}
-
-/**
- * Removes all of the items from the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget();
- int index = itemCount - 1;
- while (index >= 0) {
- TableItem item = items [index];
- if (item != null && !item.isDisposed ()) item.release (false);
- --index;
- }
- items = new TableItem [4];
- itemCount = 0;
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- if (fixAccessibility ()) {
- ignoreAccessibility = true;
- }
- OS.gtk_list_store_clear (modelHandle);
- if (fixAccessibility ()) {
- ignoreAccessibility = false;
- OS.g_object_notify (handle, OS.model);
- }
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
-
- resetCustomDraw ();
- /* Disable searching when using VIRTUAL */
- if ((style & SWT.VIRTUAL) != 0) {
- /*
- * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE)
- * would prevent the user from being able to type in text to search the tree.
- * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive
- * search. This meant that even if FALSE was passed to enable_search, the user
- * can still bring up the search pop up using the keybinding. GTK also introduced
- * the notion of passing a -1 to gtk_set_search_column to disable searching
- * (including the search key binding). The fix is to use the right calls
- * for the right version.
- */
- if (OS.GTK_VERSION >= OS.VERSION (2, 6, 5)){
- OS.gtk_tree_view_set_search_column (handle, -1);
- } else {
- OS.gtk_tree_view_set_enable_search (handle, false);
- }
- } else {
- /* Set the search column whenever the model changes */
- int firstColumn = columnCount == 0 ? FIRST_COLUMN : columns [0].modelIndex;
- OS.gtk_tree_view_set_search_column (handle, firstColumn + CELL_TEXT);
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener(SelectionListener)
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-int /*long*/ rendererGetSizeProc (int /*long*/ cell, int /*long*/ widget, int /*long*/ cell_area, int /*long*/ x_offset, int /*long*/ y_offset, int /*long*/ width, int /*long*/ height) {
- int /*long*/ g_class = OS.g_type_class_peek_parent (OS.G_OBJECT_GET_CLASS (cell));
- GtkCellRendererClass klass = new GtkCellRendererClass ();
- OS.memmove (klass, g_class);
- int /*long*/ result = OS.call (klass.get_size, cell, handle, cell_area, x_offset, y_offset, width, height);
- if (!ignoreSize && OS.GTK_IS_CELL_RENDERER_TEXT (cell)) {
- int /*long*/ iter = OS.g_object_get_qdata (cell, Display.SWT_OBJECT_INDEX2);
- TableItem item = null;
- if (iter != 0) {
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter);
- int [] buffer = new int [1];
- OS.memmove (buffer, OS.gtk_tree_path_get_indices (path), 4);
- int index = buffer [0];
- item = _getItem (index);
- OS.gtk_tree_path_free (path);
- }
- if (item != null) {
- int columnIndex = 0;
- if (columnCount > 0) {
- int /*long*/ columnHandle = OS.g_object_get_qdata (cell, Display.SWT_OBJECT_INDEX1);
- for (int i = 0; i < columnCount; i++) {
- if (columns [i].handle == columnHandle) {
- columnIndex = i;
- break;
- }
- }
- }
- if (hooks (SWT.MeasureItem)) {
- int [] contentWidth = new int [1], contentHeight = new int [1];
- if (width != 0) OS.memmove (contentWidth, width, 4);
- if (height != 0) OS.memmove (contentHeight, height, 4);
- Image image = item.getImage (columnIndex);
- int imageWidth = 0;
- if (image != null) {
- Rectangle bounds = image.getBounds ();
- imageWidth = bounds.width;
- }
- contentWidth [0] += imageWidth;
- GC gc = new GC (this);
- gc.setFont (item.getFont (columnIndex));
- Event event = new Event ();
- event.item = item;
- event.index = columnIndex;
- event.gc = gc;
- event.width = contentWidth [0];
- event.height = contentHeight [0];
- sendEvent (SWT.MeasureItem, event);
- gc.dispose ();
- contentWidth [0] = event.width - imageWidth;
- if (contentHeight [0] < event.height) contentHeight [0] = event.height;
- if (width != 0) OS.memmove (width, contentWidth, 4);
- if (height != 0) OS.memmove (height, contentHeight, 4);
- }
- }
- }
- return result;
-}
-
-int /*long*/ rendererRenderProc (int /*long*/ cell, int /*long*/ window, int /*long*/ widget, int /*long*/ background_area, int /*long*/ cell_area, int /*long*/ expose_area, int /*long*/ flags) {
- TableItem item = null;
- int /*long*/ iter = OS.g_object_get_qdata (cell, Display.SWT_OBJECT_INDEX2);
- if (iter != 0) {
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter);
- int [] buffer = new int [1];
- OS.memmove (buffer, OS.gtk_tree_path_get_indices (path), 4);
- int index = buffer [0];
- item = _getItem (index);
- OS.gtk_tree_path_free (path);
- }
- int /*long*/ columnHandle = OS.g_object_get_qdata (cell, Display.SWT_OBJECT_INDEX1);
- int columnIndex = 0;
- if (columnCount > 0) {
- for (int i = 0; i < columnCount; i++) {
- if (columns [i].handle == columnHandle) {
- columnIndex = i;
- break;
- }
- }
- }
- if (item != null) {
- if (OS.GTK_IS_CELL_RENDERER_TOGGLE (cell) || (OS.GTK_IS_CELL_RENDERER_PIXBUF (cell) && (columnIndex != 0 || (style & SWT.CHECK) == 0))) {
- drawFlags = (int)/*64*/flags;
- drawState = SWT.FOREGROUND;
- int /*long*/ [] ptr = new int /*long*/ [1];
- OS.gtk_tree_model_get (modelHandle, item.handle, Table.BACKGROUND_COLUMN, ptr, -1);
- if (ptr [0] == 0) {
- int modelIndex = columnCount == 0 ? Table.FIRST_COLUMN : columns [columnIndex].modelIndex;
- OS.gtk_tree_model_get (modelHandle, item.handle, modelIndex + Table.CELL_BACKGROUND, ptr, -1);
- }
- if (ptr [0] != 0) drawState |= SWT.BACKGROUND;
- if ((flags & OS.GTK_CELL_RENDERER_SELECTED) != 0) drawState |= SWT.SELECTED;
- if ((flags & OS.GTK_CELL_RENDERER_FOCUSED) != 0) drawState |= SWT.FOCUSED;
-
- GdkRectangle rect = new GdkRectangle ();
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter);
- OS.gtk_tree_view_get_background_area (handle, path, columnHandle, rect);
- OS.gtk_tree_path_free (path);
-
- if ((drawState & SWT.SELECTED) == 0) {
- Control control = findBackgroundControl ();
- if (control != null && control.backgroundImage != null) {
- OS.gdk_window_clear_area (window, rect.x, rect.y, rect.width, rect.height);
- }
- }
-
- if (hooks (SWT.EraseItem)) {
- boolean wasSelected = false;
- if ((drawState & SWT.SELECTED) != 0) {
- wasSelected = true;
- OS.gdk_window_clear_area (window, rect.x, rect.y, rect.width, rect.height);
- }
- GC gc = new GC (this);
- if ((drawState & SWT.SELECTED) != 0) {
- gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION));
- gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT));
- } else {
- gc.setBackground (item.getBackground (columnIndex));
- gc.setForeground (item.getForeground (columnIndex));
- }
- gc.setFont (item.getFont (columnIndex));
- if ((style & SWT.MIRRORED) != 0) rect.x = getClientWidth () - rect.width - rect.x;
- gc.setClipping (rect.x, rect.y, rect.width, rect.height);
- Event event = new Event ();
- event.item = item;
- event.index = columnIndex;
- event.gc = gc;
- event.x = rect.x;
- event.y = rect.y;
- event.width = rect.width;
- event.height = rect.height;
- event.detail = drawState;
- sendEvent (SWT.EraseItem, event);
- drawForeground = null;
- drawState = event.doit ? event.detail : 0;
- drawFlags &= ~(OS.GTK_CELL_RENDERER_FOCUSED | OS.GTK_CELL_RENDERER_SELECTED);
- if ((drawState & SWT.SELECTED) != 0) drawFlags |= OS.GTK_CELL_RENDERER_SELECTED;
- if ((drawState & SWT.FOCUSED) != 0) drawFlags |= OS.GTK_CELL_RENDERER_FOCUSED;
- if ((drawState & SWT.SELECTED) != 0) {
- int /*long*/ style = OS.gtk_widget_get_style (widget);
- //TODO - parity and sorted
- byte[] detail = Converter.wcsToMbcs (null, "cell_odd", true);
- OS.gtk_paint_flat_box (style, window, OS.GTK_STATE_SELECTED, OS.GTK_SHADOW_NONE, rect, widget, detail, rect.x, rect.y, rect.width, rect.height);
- } else {
- if (wasSelected) drawForeground = gc.getForeground ().handle;
- }
- gc.dispose();
- }
- }
- }
- int /*long*/ result = 0;
- if ((drawState & SWT.BACKGROUND) != 0 && (drawState & SWT.SELECTED) == 0) {
- GC gc = new GC (this);
- gc.setBackground (item.getBackground (columnIndex));
- GdkRectangle rect = new GdkRectangle ();
- OS.memmove (rect, background_area, GdkRectangle.sizeof);
- gc.fillRectangle (rect.x, rect.y, rect.width, rect.height);
- gc.dispose ();
- }
- if ((drawState & SWT.FOREGROUND) != 0 || OS.GTK_IS_CELL_RENDERER_TOGGLE (cell)) {
- int /*long*/ g_class = OS.g_type_class_peek_parent (OS.G_OBJECT_GET_CLASS (cell));
- GtkCellRendererClass klass = new GtkCellRendererClass ();
- OS.memmove (klass, g_class);
- if (drawForeground != null && OS.GTK_IS_CELL_RENDERER_TEXT (cell)) {
- OS.g_object_set (cell, OS.foreground_gdk, drawForeground, 0);
- }
- result = OS.call (klass.render, cell, window, handle, background_area, cell_area, expose_area, drawFlags);
- }
- if (item != null) {
- if (OS.GTK_IS_CELL_RENDERER_TEXT (cell)) {
- if (hooks (SWT.PaintItem)) {
- GdkRectangle rect = new GdkRectangle ();
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter);
- OS.gtk_tree_view_get_background_area (handle, path, columnHandle, rect);
- OS.gtk_tree_path_free (path);
- ignoreSize = true;
- int [] contentX = new int [1], contentWidth = new int [1];
- OS.gtk_cell_renderer_get_size (cell, handle, null, null, null, contentWidth, null);
- OS.gtk_tree_view_column_cell_get_position (columnHandle, cell, contentX, null);
- ignoreSize = false;
- Image image = item.getImage (columnIndex);
- int imageWidth = 0;
- if (image != null) {
- Rectangle bounds = image.getBounds ();
- imageWidth = bounds.width;
- }
- contentX [0] -= imageWidth;
- contentWidth [0] += imageWidth;
- GC gc = new GC (this);
- if ((drawState & SWT.SELECTED) != 0) {
- gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION));
- gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT));
- } else {
- gc.setBackground (item.getBackground (columnIndex));
- Color foreground = drawForeground != null ? Color.gtk_new (display, drawForeground) : item.getForeground (columnIndex);
- gc.setForeground (foreground);
- }
- gc.setFont (item.getFont (columnIndex));
- if ((style & SWT.MIRRORED) != 0) rect.x = getClientWidth () - rect.width - rect.x;
- gc.setClipping (rect.x, rect.y, rect.width, rect.height);
- Event event = new Event ();
- event.item = item;
- event.index = columnIndex;
- event.gc = gc;
- event.x = rect.x + contentX [0];
- event.y = rect.y;
- event.width = contentWidth [0];
- event.height = rect.height;
- event.detail = drawState;
- sendEvent (SWT.PaintItem, event);
- gc.dispose();
- }
- }
- }
- return result;
-}
-
-void resetCustomDraw () {
- if ((style & SWT.VIRTUAL) != 0 || ownerDraw) return;
- int end = Math.max (1, columnCount);
- for (int i=0; i<end; i++) {
- boolean customDraw = columnCount != 0 ? columns [i].customDraw : firstCustomDraw;
- if (customDraw) {
- int /*long*/ column = OS.gtk_tree_view_get_column (handle, i);
- int /*long*/ textRenderer = getTextRenderer (column);
- OS.gtk_tree_view_column_set_cell_data_func (column, textRenderer, 0, 0, 0);
- if (columnCount != 0) columns [i].customDraw = false;
- }
- }
- firstCustomDraw = false;
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget();
- if (!(0 <= index && index < itemCount)) return;
- boolean fixColumn = showFirstColumn ();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- TableItem item = _getItem (index);
- OS.gtk_tree_selection_select_iter (selection, item.handle);
- if ((style & SWT.SINGLE) != 0) {
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, item.handle);
- OS.gtk_tree_view_set_cursor (handle, path, 0, false);
- OS.gtk_tree_path_free (path);
- }
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- if (fixColumn) hideFirstColumn ();
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If an item in the given range is not selected, it is selected.
- * If an item in the given range was already selected, it remains selected.
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setSelection(int,int)
- */
-public void select (int start, int end) {
- checkWidget ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- if (itemCount == 0 || start >= itemCount) return;
- start = Math.max (0, start);
- end = Math.min (end, itemCount - 1);
- boolean fixColumn = showFirstColumn ();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- for (int index=start; index<=end; index++) {
- TableItem item = _getItem (index);
- OS.gtk_tree_selection_select_iter (selection, item.handle);
- if ((style & SWT.SINGLE) != 0) {
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, item.handle);
- OS.gtk_tree_view_set_cursor (handle, path, 0, false);
- OS.gtk_tree_path_free (path);
- }
- }
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- if (fixColumn) hideFirstColumn ();
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If the item at a given index is not selected, it is selected.
- * If the item at a given index was already selected, it remains selected.
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- * </p>
- *
- * @param indices the array of indices for the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setSelection(int[])
- */
-public void select (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- boolean fixColumn = showFirstColumn ();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- for (int i=0; i<length; i++) {
- int index = indices [i];
- if (!(0 <= index && index < itemCount)) continue;
- TableItem item = _getItem (index);
- OS.gtk_tree_selection_select_iter (selection, item.handle);
- if ((style & SWT.SINGLE) != 0) {
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, item.handle);
- OS.gtk_tree_view_set_cursor (handle, path, 0, false);
- OS.gtk_tree_path_free (path);
- }
- }
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- if (fixColumn) hideFirstColumn ();
-}
-
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return;
- boolean fixColumn = showFirstColumn ();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_selection_select_all (selection);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- if (fixColumn) hideFirstColumn ();
-}
-
-void selectFocusIndex (int index) {
- /*
- * Note that this method both selects and sets the focus to the
- * specified index, so any previous selection in the list will be lost.
- * gtk does not provide a way to just set focus to a specified list item.
- */
- if (!(0 <= index && index < itemCount)) return;
- TableItem item = _getItem (index);
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, item.handle);
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_view_set_cursor (handle, path, 0, false);
- /*
- * Bug in GTK. For some reason, when an event loop is run from
- * within a key pressed handler and a dialog is displayed that
- * contains a GtkTreeView, gtk_tree_view_set_cursor() does
- * not set the cursor or select the item. The fix is to select the
- * item with gtk_tree_selection_select_iter() as well.
- *
- * NOTE: This happens in GTK 2.2.1 and is fixed in GTK 2.2.4.
- */
- OS.gtk_tree_selection_select_iter (selection, item.handle);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_path_free (path);
-}
-
-void setBackgroundColor (GdkColor color) {
- super.setBackgroundColor (color);
- OS.gtk_widget_modify_base (handle, 0, color);
-}
-
-void setBackgroundPixmap (int /*long*/ pixmap) {
- super.setBackgroundPixmap (pixmap);
- int /*long*/ window = paintWindow ();
- if (window != 0) OS.gdk_window_set_back_pixmap (window, 0, true);
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- int result = super.setBounds (x, y, width, height, move, resize);
- /*
- * Bug on GTK. The tree view sometimes does not get a paint
- * event or resizes to a one pixel square when resized in a new
- * shell that is not visible after any event loop has been run. The
- * problem is intermittent. It doesn't seem to happen the first time
- * a new shell is created. The fix is to ensure the tree view is realized
- * after it has been resized.
- */
- OS.gtk_widget_realize (handle);
- /*
- * Bug in GTK. An empty GtkTreeView fails to repaint the focus rectangle
- * correctly when resized on versions before 2.6.0. The fix is to force
- * the widget to redraw.
- */
- if (OS.GTK_VERSION < OS.VERSION (2, 6, 0) && itemCount == 0) redraw (false);
- return result;
-}
-
-/**
- * Sets the order that the items in the receiver should
- * be displayed in to the given argument which is described
- * in terms of the zero-relative ordering of when the items
- * were added.
- *
- * @param order the new order to display the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item order is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public void setColumnOrder (int [] order) {
- checkWidget ();
- if (order == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (columnCount == 0) {
- if (order.length > 0) error (SWT.ERROR_INVALID_ARGUMENT);
- return;
- }
- if (order.length != columnCount) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean [] seen = new boolean [columnCount];
- for (int i = 0; i<order.length; i++) {
- int index = order [i];
- if (index < 0 || index >= columnCount) error (SWT.ERROR_INVALID_RANGE);
- if (seen [index]) error (SWT.ERROR_INVALID_ARGUMENT);
- seen [index] = true;
- }
- for (int i=0; i<order.length; i++) {
- int /*long*/ column = columns [order [i]].handle;
- int /*long*/ baseColumn = i == 0 ? 0 : columns [order [i-1]].handle;
- OS.gtk_tree_view_move_column_after (handle, column, baseColumn);
- }
-}
-
-void setFontDescription (int /*long*/ font) {
- super.setFontDescription (font);
- TableColumn[] columns = getColumns ();
- for (int i = 0; i < columns.length; i++) {
- if (columns[i] != null) {
- columns[i].setFontDescription (font);
- }
- }
-}
-
-/**
- * Marks the receiver's header as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHeaderVisible (boolean show) {
- checkWidget ();
- OS.gtk_tree_view_set_headers_visible (handle, show);
-}
-
-/**
- * Sets the number of items contained in the receiver.
- *
- * @param count the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setItemCount (int count) {
- checkWidget ();
- count = Math.max (0, count);
- if (count == itemCount) return;
- boolean isVirtual = (style & SWT.VIRTUAL) != 0;
- if (!isVirtual) setRedraw (false);
- remove (count, itemCount - 1);
- int length = Math.max (4, (count + 3) / 4 * 4);
- TableItem [] newItems = new TableItem [length];
- System.arraycopy (items, 0, newItems, 0, itemCount);
- items = newItems;
- if (isVirtual) {
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (iter == 0) error (SWT.ERROR_NO_HANDLES);
- if (fixAccessibility ()) {
- ignoreAccessibility = true;
- }
- for (int i=itemCount; i<count; i++) {
- OS.gtk_list_store_append (modelHandle, iter);
- }
- if (fixAccessibility ()) {
- ignoreAccessibility = false;
- OS.g_object_notify (handle, OS.model);
- }
- OS.g_free (iter);
- itemCount = count;
- } else {
- for (int i=itemCount; i<count; i++) {
- new TableItem (this, SWT.NONE, i, true);
- }
- }
- if (!isVirtual) setRedraw (true);
-}
-
-/**
- * Marks the receiver's lines as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise. Note that some platforms draw grid lines
- * while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLinesVisible (boolean show) {
- checkWidget();
- OS.gtk_tree_view_set_rules_hint (handle, show);
- if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0)) {
- OS.gtk_tree_view_set_grid_lines (handle, show ? OS.GTK_TREE_VIEW_GRID_LINES_VERTICAL : OS.GTK_TREE_VIEW_GRID_LINES_NONE);
- }
-}
-
-void setParentBackground () {
- super.setParentBackground ();
- int /*long*/ window = paintWindow ();
- if (window != 0) OS.gdk_window_set_back_pixmap (window, 0, true);
-}
-
-void setParentWindow (int /*long*/ widget) {
- int /*long*/ window = eventWindow ();
- OS.gtk_widget_set_parent_window (widget, window);
-}
-
-public void setRedraw (boolean redraw) {
- checkWidget();
- super.setRedraw (redraw);
- if (redraw && drawCount == 0) {
- /* Resize the item array to match the item count */
- if (items.length > 4 && items.length - itemCount > 3) {
- int length = Math.max (4, (itemCount + 3) / 4 * 4);
- TableItem [] newItems = new TableItem [length];
- System.arraycopy (items, 0, newItems, 0, itemCount);
- items = newItems;
- }
- }
-}
-
-void setScrollWidth (int /*long*/ column, TableItem item) {
- if (columnCount != 0 || currentItem == item) return;
- /*
- * Use GTK_TREE_VIEW_COLUMN_GROW_ONLY on GTK versions < 2.3.2
- * because fixed_height_mode is not supported.
- */
- if (((style & SWT.VIRTUAL) != 0) && OS.GTK_VERSION < OS.VERSION (2, 3, 2)) return;
- int width = OS.gtk_tree_view_column_get_fixed_width (column);
- int itemWidth = calculateWidth (column, item.handle);
- if (width < itemWidth) {
- OS.gtk_tree_view_column_set_fixed_width (column, itemWidth);
- }
-}
-
-/**
- * Sets the column used by the sort indicator for the receiver. A null
- * value will clear the sort indicator. The current sort column is cleared
- * before the new column is set.
- *
- * @param column the column used by the sort indicator or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the column is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortColumn (TableColumn column) {
- checkWidget ();
- if (column != null && column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (sortColumn != null && !sortColumn.isDisposed()) {
- OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, false);
- }
- sortColumn = column;
- if (sortColumn != null && sortDirection != SWT.NONE) {
- OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, true);
- OS.gtk_tree_view_column_set_sort_order (sortColumn.handle, sortDirection == SWT.DOWN ? 0 : 1);
- }
-}
-
-/**
- * Sets the direction of the sort indicator for the receiver. The value
- * can be one of <code>UP</code>, <code>DOWN</code> or <code>NONE</code>.
- *
- * @param direction the direction of the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortDirection (int direction) {
- checkWidget ();
- if (direction != SWT.UP && direction != SWT.DOWN && direction != SWT.NONE) return;
- sortDirection = direction;
- if (sortColumn == null || sortColumn.isDisposed ()) return;
- if (sortDirection == SWT.NONE) {
- OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, false);
- } else {
- OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, true);
- OS.gtk_tree_view_column_set_sort_order (sortColumn.handle, sortDirection == SWT.DOWN ? 0 : 1);
- }
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * The current selection is first cleared, then the new item is selected.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int)
- */
-public void setSelection (int index) {
- checkWidget ();
- boolean fixColumn = showFirstColumn ();
- deselectAll ();
- selectFocusIndex (index);
- showSelection ();
- if (fixColumn) hideFirstColumn ();
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- * </p>
- *
- * @param start the start index of the items to select
- * @param end the end index of the items to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int,int)
- */
-public void setSelection (int start, int end) {
- checkWidget ();
- deselectAll();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- if (itemCount == 0 || start >= itemCount) return;
- boolean fixColumn = showFirstColumn ();
- start = Math.max (0, start);
- end = Math.min (end, itemCount - 1);
- selectFocusIndex (start);
- if ((style & SWT.MULTI) != 0) {
- select (start, end);
- }
- showSelection ();
- if (fixColumn) hideFirstColumn ();
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- * </p>
- *
- * @param indices the indices of the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int[])
- */
-public void setSelection (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- boolean fixColumn = showFirstColumn ();
- selectFocusIndex (indices [0]);
- if ((style & SWT.MULTI) != 0) {
- select (indices);
- }
- showSelection ();
- if (fixColumn) hideFirstColumn ();
-}
-
-/**
- * Sets the receiver's selection to the given item.
- * The current selection is cleared before the new item is selected.
- * <p>
- * If the item is not in the receiver, then it is ignored.
- * </p>
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection (TableItem item) {
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (new TableItem [] {item});
-}
-
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- * </p>
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the items has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int[])
- * @see Table#setSelection(int[])
- */
-public void setSelection (TableItem [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- boolean fixColumn = showFirstColumn ();
- deselectAll ();
- int length = items.length;
- if (!(length == 0 || ((style & SWT.SINGLE) != 0 && length > 1))) {
- boolean first = true;
- for (int i = 0; i < length; i++) {
- int index = indexOf (items [i]);
- if (index != -1) {
- if (first) {
- first = false;
- selectFocusIndex (index);
- } else {
- select (index);
- }
- }
- }
- showSelection ();
- }
- if (fixColumn) hideFirstColumn ();
-}
-
-/**
- * Sets the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items
- * are scrolled or new items are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget();
- if (!(0 <= index && index < itemCount)) return;
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, _getItem (index).handle);
- OS.gtk_tree_view_scroll_to_cell (handle, path, 0, true, 0f, 0f);
- if (OS.GTK_VERSION < OS.VERSION (2, 8, 0)) {
- /*
- * Bug in GTK. According to the documentation, gtk_tree_view_scroll_to_cell
- * should vertically scroll the cell to the top if use_align is true and row_align is 0.
- * However, prior to version 2.8 it does not scroll at all. The fix is to determine
- * the new location and use gtk_tree_view_scroll_to_point.
- * If the widget is a pinhead, calling gtk_tree_view_scroll_to_point
- * will have no effect. Therefore, it is still neccessary to call
- * gtk_tree_view_scroll_to_cell.
- */
- OS.gtk_widget_realize (handle);
- GdkRectangle cellRect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (handle, path, 0, cellRect);
- int[] tx = new int[1], ty = new int[1];
- OS.gtk_tree_view_widget_to_tree_coords(handle, cellRect.x, cellRect.y, tx, ty);
- OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0]);
- }
- OS.gtk_tree_path_free (path);
-}
-
-/**
- * Shows the column. If the column is already showing in the receiver,
- * this method simply returns. Otherwise, the columns are scrolled until
- * the column is visible.
- *
- * @param column the column to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the column is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the column has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void showColumn (TableColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (column.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (column.parent != this) return;
- /*
- * This code is intentionally commented. According to the
- * documentation, gtk_tree_view_scroll_to_cell should scroll the
- * minimum amount to show the column but instead it scrolls strangely.
- */
- //OS.gtk_tree_view_scroll_to_cell (handle, 0, column.handle, false, 0, 0);
- OS.gtk_widget_realize (handle);
- GdkRectangle cellRect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (handle, 0, column.handle, cellRect);
- GdkRectangle visibleRect = new GdkRectangle ();
- OS.gtk_tree_view_get_visible_rect (handle, visibleRect);
- if (cellRect.x < visibleRect.x) {
- OS.gtk_tree_view_scroll_to_point (handle, cellRect.x, -1);
- } else {
- int width = Math.min (visibleRect.width, cellRect.width);
- if (cellRect.x + width > visibleRect.x + visibleRect.width) {
- int tree_x = cellRect.x + width - visibleRect.width;
- OS.gtk_tree_view_scroll_to_point (handle, tree_x, -1);
- }
- }
-}
-
-boolean showFirstColumn () {
- /*
- * Bug in GTK. If no columns are visible, changing the selection
- * will fail. The fix is to temporarily make a column visible.
- */
- int columnCount = Math.max (1, this.columnCount);
- for (int i=0; i<columnCount; i++) {
- int /*long*/ column = OS.gtk_tree_view_get_column (handle, i);
- if (OS.gtk_tree_view_column_get_visible (column)) return false;
- }
- int /*long*/ firstColumn = OS.gtk_tree_view_get_column (handle, 0);
- OS.gtk_tree_view_column_set_visible (firstColumn, true);
- return true;
-}
-
-/**
- * Shows the item. If the item is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the item is visible.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#showSelection()
- */
-public void showItem (TableItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (item.parent != this) return;
- showItem (item.handle);
-}
-
-void showItem (int /*long*/ iter) {
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter);
- /*
- * This code intentionally commented.
- * Bug in GTK. According to the documentation, gtk_tree_view_scroll_to_cell
- * should scroll the minimum amount to show the cell if use_align is false.
- * However, what actually happens is the cell is scrolled to the top.
- * The fix is to determine the new location and use gtk_tree_view_scroll_to_point.
- * If the widget is a pinhead, calling gtk_tree_view_scroll_to_point
- * will have no effect. Therefore, it is still neccessary to
- * call gtk_tree_view_scroll_to_cell.
- */
-// OS.gtk_tree_view_scroll_to_cell (handle, path, 0, false, 0, 0);
- OS.gtk_widget_realize (handle);
- GdkRectangle visibleRect = new GdkRectangle ();
- OS.gtk_tree_view_get_visible_rect (handle, visibleRect);
- GdkRectangle cellRect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (handle, path, 0, cellRect);
- int[] tx = new int[1], ty = new int[1];
- OS.gtk_tree_view_widget_to_tree_coords(handle, cellRect.x, cellRect.y, tx, ty);
- if (ty[0] < visibleRect.y ) {
- OS.gtk_tree_view_scroll_to_cell (handle, path, 0, true, 0f, 0f);
- OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0]);
- } else {
- int height = Math.min (visibleRect.height, cellRect.height);
- if (ty[0] + height > visibleRect.y + visibleRect.height) {
- OS.gtk_tree_view_scroll_to_cell (handle, path, 0, true, 1f, 0f);
- ty[0] += cellRect.height - visibleRect.height;
- OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0]);
- }
- }
- OS.gtk_tree_path_free (path);
-}
-
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#showItem(TableItem)
- */
-public void showSelection () {
- checkWidget();
- TableItem [] selection = getSelection ();
- if (selection.length == 0) return;
- TableItem item = selection [0];
- showItem (item.handle);
-}
-
-int /*long*/ treeSelectionProc (int /*long*/ model, int /*long*/ path, int /*long*/ iter, int[] selection, int length) {
- if (selection != null) {
- int /*long*/ indices = OS.gtk_tree_path_get_indices (path);
- if (indices != 0) {
- int [] index = new int [1];
- OS.memmove (index, indices, 4);
- selection [(int)/*64*/length] = index [0];
- }
- }
- return 0;
-}
-
-void updateScrollBarValue (ScrollBar bar) {
- super.updateScrollBarValue (bar);
- /*
- * Bug in GTK. Scrolling changes the XWindow position
- * and makes the child widgets appear to scroll even
- * though when queried their position is unchanged.
- * The fix is to queue a resize event for each child to
- * force the position to be corrected.
- */
- int /*long*/ parentHandle = parentingHandle ();
- int /*long*/ list = OS.gtk_container_get_children (parentHandle);
- if (list == 0) return;
- int /*long*/ temp = list;
- while (temp != 0) {
- int /*long*/ widget = OS.g_list_data (temp);
- if (widget != 0) OS.gtk_widget_queue_resize (widget);
- temp = OS.g_list_next (temp);
- }
- OS.g_list_free (list);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java
deleted file mode 100644
index 4a62dfef8c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java
+++ /dev/null
@@ -1,702 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a column in a table widget.
- * <p><dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd> Move, Resize, Selection</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT and CENTER may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TableColumn extends Item {
- int /*long*/ labelHandle, imageHandle, buttonHandle;
- Table parent;
- int modelIndex, lastButton, lastTime, lastX, lastWidth;
- boolean customDraw, useFixedWidth;
- String toolTipText;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableColumn (Table parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (parent.getColumnCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableColumn (Table parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (index);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize,typedListener);
- addListener (SWT.Move,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the column header is selected.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createWidget (int index) {
- parent.createItem (this, index);
- setOrientation ();
- hookEvents ();
- register ();
- text = "";
-}
-
-void deregister() {
- super.deregister ();
- display.removeWidget (handle);
- if (buttonHandle != 0) display.removeWidget (buttonHandle);
- if (labelHandle != 0) display.removeWidget (labelHandle);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget();
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-/**
- * Gets the moveable attribute. A column that is
- * not moveable cannot be reordered by the user
- * by dragging the header but may be reordered
- * by the programmer.
- *
- * @return the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public boolean getMoveable() {
- checkWidget();
- return OS.gtk_tree_view_column_get_reorderable (handle);
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Table</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Table getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Gets the resizable attribute. A column that is
- * not resizable cannot be dragged by the user but
- * may be resized by the programmer.
- *
- * @return the resizable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getResizable () {
- checkWidget();
- return OS.gtk_tree_view_column_get_resizable (handle);
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget();
- if (!OS.gtk_tree_view_column_get_visible (handle)) {
- return 0;
- }
- if (useFixedWidth) return OS.gtk_tree_view_column_get_fixed_width (handle);
- return OS.gtk_tree_view_column_get_width (handle);
-}
-
-int /*long*/ gtk_clicked (int /*long*/ widget) {
- /*
- * There is no API to get a double click on a table column. Normally, when
- * the mouse is double clicked, this is indicated by GDK_2BUTTON_PRESS
- * but the table column sends the click signal on button release. The fix is to
- * test for double click by remembering the last click time and mouse button
- * and testing for the double click interval.
- */
- boolean doubleClick = false;
- boolean postEvent = true;
- int /*long*/ eventPtr = OS.gtk_get_current_event ();
- if (eventPtr != 0) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, eventPtr, GdkEventButton.sizeof);
- OS.gdk_event_free (eventPtr);
- switch (gdkEvent.type) {
- case OS.GDK_BUTTON_RELEASE: {
- int clickTime = display.getDoubleClickTime ();
- int eventTime = gdkEvent.time, eventButton = gdkEvent.button;
- if (lastButton == eventButton && lastTime != 0 && Math.abs (lastTime - eventTime) <= clickTime) {
- doubleClick = true;
- }
- lastTime = eventTime == 0 ? 1: eventTime;
- lastButton = eventButton;
- break;
- }
- case OS.GDK_MOTION_NOTIFY: {
- /*
- * Bug in GTK. Dragging a column in a GtkTreeView causes a clicked
- * signal to be emitted even though the mouse button was never released.
- * The fix to ignore the signal if the current GDK event is a motion notify.
- * The GTK bug was fixed in version 2.6
- */
- if (OS.GTK_VERSION < OS.VERSION (2, 6, 0)) postEvent = false;
- break;
- }
- }
- }
- if (postEvent) postEvent (doubleClick ? SWT.DefaultSelection : SWT.Selection);
- return 0;
-}
-
-int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) {
- GdkEvent event = new GdkEvent ();
- OS.memmove (event, gdkEvent, GdkEvent.sizeof);
- switch (event.type) {
- case OS.GDK_BUTTON_PRESS: {
- GdkEventButton gdkEventButton = new GdkEventButton ();
- OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof);
- if (gdkEventButton.button == 3) {
- parent.showMenu ((int) gdkEventButton.x_root, (int) gdkEventButton.y_root);
- }
- break;
- }
- }
- return 0;
-}
-
-int /*long*/ gtk_mnemonic_activate (int /*long*/ widget, int /*long*/ arg1) {
- return parent.gtk_mnemonic_activate (widget, arg1);
-}
-
-int /*long*/ gtk_size_allocate (int /*long*/ widget, int /*long*/ allocation) {
- useFixedWidth = false;
- int x = OS.GTK_WIDGET_X (widget);
- int width = OS.GTK_WIDGET_WIDTH (widget);
- if (x != lastX) {
- lastX = x;
- sendEvent (SWT.Move);
- }
- if (width != lastWidth) {
- lastWidth = width;
- sendEvent (SWT.Resize);
- }
- return 0;
-}
-
-void hookEvents () {
- super.hookEvents ();
- OS.g_signal_connect_closure (handle, OS.clicked, display.closures [CLICKED], false);
- if (buttonHandle != 0) {
- OS.g_signal_connect_closure_by_id (buttonHandle, display.signalIds [SIZE_ALLOCATE], 0, display.closures [SIZE_ALLOCATE], false);
- OS.g_signal_connect_closure_by_id (buttonHandle, display.signalIds [EVENT_AFTER], 0, display.closures [EVENT_AFTER], false);
- }
- if (labelHandle != 0) OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false);
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void pack () {
- checkWidget();
- int width = 0;
- if (buttonHandle != 0) {
- GtkRequisition requisition = new GtkRequisition ();
- OS.gtk_widget_size_request (buttonHandle, requisition);
- width = requisition.width;
- }
- if ((parent.style & SWT.VIRTUAL) != 0) {
- for (int i=0; i<parent.items.length; i++) {
- TableItem item = parent.items [i];
- if (item != null && item.cached) {
- width = Math.max (width, parent.calculateWidth (handle, item.handle));
- }
- }
- } else {
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (OS.gtk_tree_model_get_iter_first (parent.modelHandle, iter)) {
- do {
- width = Math.max (width, parent.calculateWidth (handle, iter));
- } while (OS.gtk_tree_model_iter_next(parent.modelHandle, iter));
- }
- OS.g_free (iter);
- }
- setWidth(width);
-}
-
-void register () {
- super.register ();
- display.addWidget (handle, this);
- if (buttonHandle != 0) display.addWidget (buttonHandle, this);
- if (labelHandle != 0) display.addWidget (labelHandle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- handle = buttonHandle = labelHandle = imageHandle = 0;
- modelIndex = -1;
- parent = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (parent.sortColumn == this) {
- parent.sortColumn = null;
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>.
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget();
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- int index = parent.indexOf (this);
- if (index == -1 || index == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- parent.createRenderers (handle, modelIndex, index == 0, style);
-}
-
-void setFontDescription (int /*long*/ font) {
- OS.gtk_widget_modify_font (labelHandle, font);
- OS.gtk_widget_modify_font (imageHandle, font);
-}
-
-public void setImage (Image image) {
- checkWidget ();
- super.setImage (image);
- if (image != null) {
- ImageList headerImageList = parent.headerImageList;
- if (headerImageList == null) {
- headerImageList = parent.headerImageList = new ImageList ();
- }
- int imageIndex = headerImageList.indexOf (image);
- if (imageIndex == -1) imageIndex = headerImageList.add (image);
- int /*long*/ pixbuf = headerImageList.getPixbuf (imageIndex);
- OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf);
- OS.gtk_widget_show (imageHandle);
- } else {
- OS.gtk_image_set_from_pixbuf (imageHandle, 0);
- OS.gtk_widget_hide (imageHandle);
- }
-}
-
-/**
- * Sets the resizable attribute. A column that is
- * resizable can be resized by the user dragging the
- * edge of the header. A column that is not resizable
- * cannot be dragged by the user but may be resized
- * by the programmer.
- *
- * @param resizable the resize attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setResizable (boolean resizable) {
- checkWidget();
- OS.gtk_tree_view_column_set_resizable (handle, resizable);
-}
-
-/**
- * Sets the moveable attribute. A column that is
- * moveable can be reordered by the user by dragging
- * the header. A column that is not moveable cannot be
- * dragged by the user but may be reordered
- * by the programmer.
- *
- * @param moveable the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setColumnOrder(int[])
- * @see Table#getColumnOrder()
- * @see TableColumn#getMoveable()
- * @see SWT#Move
- *
- * @since 3.1
- */
-public void setMoveable (boolean moveable) {
- checkWidget();
- OS.gtk_tree_view_column_set_reorderable (handle, moveable);
-}
-
-void setOrientation() {
- if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) {
- if (buttonHandle != 0) {
- OS.gtk_widget_set_direction (buttonHandle, OS.GTK_TEXT_DIR_RTL);
- OS.gtk_container_forall (buttonHandle, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL);
- }
- }
-}
-
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- char [] chars = fixMnemonic (string);
- byte [] buffer = Converter.wcsToMbcs (null, chars, true);
- OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer);
- if (string.length () != 0) {
- OS.gtk_widget_show (labelHandle);
- } else {
- OS.gtk_widget_hide (labelHandle);
- }
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setToolTipText (String string) {
- checkWidget();
- Shell shell = parent._getShell ();
- setToolTipText (shell, string);
- toolTipText = string;
-}
-
-void setToolTipText (Shell shell, String newString) {
- shell.setToolTipText (buttonHandle, newString);
-}
-
-/**
- * Sets the width of the receiver.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int width) {
- checkWidget();
- if (width < 0) return;
- if (width == lastWidth) return;
- if (width > 0) {
- useFixedWidth = true;
- OS.gtk_tree_view_column_set_fixed_width (handle, width);
- }
- /*
- * Bug in GTK. For some reason, calling gtk_tree_view_column_set_visible()
- * when the parent is not realized fails to show the column. The fix is to
- * ensure that the table has been realized.
- */
- if (width != 0) OS.gtk_widget_realize (parent.handle);
- OS.gtk_tree_view_column_set_visible (handle, width != 0);
- lastWidth = width;
- sendEvent (SWT.Resize);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java
deleted file mode 100644
index f34843751d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java
+++ /dev/null
@@ -1,1324 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents an item in a table.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TableItem extends Item {
- Table parent;
- Font font;
- Font[] cellFont;
- boolean cached, grayed;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableItem (Table parent, int style, int index) {
- this (parent, style, index, true);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableItem (Table parent, int style) {
- this (parent, style, checkNull (parent).getItemCount (), true);
-}
-
-
-TableItem (Table parent, int style, int index, boolean create) {
- super (parent, style);
- this.parent = parent;
- if (create) {
- parent.createItem (this, index);
- } else {
- handle = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- OS.gtk_tree_model_iter_nth_child (parent.modelHandle, handle, 0, index);
- }
-}
-
-static Table checkNull (Table control) {
- if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return control;
-}
-
-Color _getBackground () {
- int /*long*/ [] ptr = new int /*long*/ [1];
- OS.gtk_tree_model_get (parent.modelHandle, handle, Table.BACKGROUND_COLUMN, ptr, -1);
- if (ptr [0] == 0) return parent.getBackground ();
- GdkColor gdkColor = new GdkColor ();
- OS.memmove (gdkColor, ptr [0], GdkColor.sizeof);
- return Color.gtk_new (display, gdkColor);
-}
-
-Color _getBackground (int index) {
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count - 1) return _getBackground ();
- int /*long*/ [] ptr = new int /*long*/ [1];
- int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
- OS.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Table.CELL_BACKGROUND, ptr, -1);
- if (ptr [0] == 0) return _getBackground ();
- GdkColor gdkColor = new GdkColor ();
- OS.memmove (gdkColor, ptr [0], GdkColor.sizeof);
- return Color.gtk_new (display, gdkColor);
-}
-
-boolean _getChecked () {
- int /*long*/ [] ptr = new int /*long*/ [1];
- OS.gtk_tree_model_get (parent.modelHandle, handle, Table.CHECKED_COLUMN, ptr, -1);
- return ptr [0] != 0;
-}
-
-Color _getForeground () {
- int /*long*/ [] ptr = new int /*long*/ [1];
- OS.gtk_tree_model_get (parent.modelHandle, handle, Table.FOREGROUND_COLUMN, ptr, -1);
- if (ptr [0] == 0) return parent.getForeground ();
- GdkColor gdkColor = new GdkColor ();
- OS.memmove (gdkColor, ptr [0], GdkColor.sizeof);
- return Color.gtk_new (display, gdkColor);
-}
-
-Color _getForeground (int index) {
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count - 1) return _getForeground ();
- int /*long*/ [] ptr = new int /*long*/ [1];
- int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
- OS.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Table.CELL_FOREGROUND, ptr, -1);
- if (ptr [0] == 0) return _getForeground ();
- GdkColor gdkColor = new GdkColor ();
- OS.memmove (gdkColor, ptr [0], GdkColor.sizeof);
- return Color.gtk_new (display, gdkColor);
-}
-
-Image _getImage (int index) {
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return null;
- int /*long*/ [] ptr = new int /*long*/ [1];
- int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
- OS.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Table.CELL_PIXBUF, ptr, -1);
- if (ptr [0] == 0) return null;
- ImageList imageList = parent.imageList;
- int imageIndex = imageList.indexOf (ptr [0]);
- if (imageIndex == -1) return null;
- return imageList.get (imageIndex);
-}
-
-String _getText (int index) {
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return "";
- int /*long*/ [] ptr = new int /*long*/ [1];
- int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
- OS.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Table.CELL_TEXT, ptr, -1);
- if (ptr [0] == 0) return "";
- int length = OS.strlen (ptr [0]);
- byte[] buffer = new byte [length];
- OS.memmove (buffer, ptr [0], length);
- OS.g_free (ptr [0]);
- return new String (Converter.mbcsToWcs (null, buffer));
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void clear () {
- if (parent.currentItem == this) return;
- if (cached || (parent.style & SWT.VIRTUAL) == 0) {
- int columnCount = OS.gtk_tree_model_get_n_columns (parent.modelHandle);
- for (int i=0; i<columnCount; i++) {
- OS.gtk_list_store_set (parent.modelHandle, handle, i, 0, -1);
- }
- /*
- * Bug in GTK. When using fixed-height-mode,
- * row changes do not cause the row to be repainted. The fix is to
- * invalidate the row when it is cleared.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) {
- redraw ();
- }
- }
- }
- cached = false;
- font = null;
- cellFont = null;
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns the receiver's background color.
- *
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public Color getBackground () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return _getBackground ();
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Rectangle getBounds () {
- // TODO fully test on early and later versions of GTK
- // shifted a bit too far right on later versions of GTK - however, old Tree also had this problem
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int /*long*/ parentHandle = parent.handle;
- int /*long*/ column = OS.gtk_tree_view_get_column (parentHandle, 0);
- if (column == 0) return new Rectangle (0, 0, 0, 0);
- int /*long*/ textRenderer = parent.getTextRenderer (column);
- int /*long*/ pixbufRenderer = parent.getPixbufRenderer (column);
- if (textRenderer == 0 || pixbufRenderer == 0) return new Rectangle (0, 0, 0, 0);
-
- int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- OS.gtk_widget_realize (parentHandle);
-
- boolean isExpander = OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle) > 0;
- boolean isExpanded = OS.gtk_tree_view_row_expanded (parentHandle, path);
- OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, isExpander, isExpanded);
-
- GdkRectangle rect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect);
- OS.gtk_tree_path_free (path);
- if ((parent.getStyle () & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth () - rect.width - rect.x;
- int right = rect.x + rect.width;
-
- int [] x = new int [1], w = new int [1];
- parent.ignoreSize = true;
- OS.gtk_cell_renderer_get_size (textRenderer, parentHandle, null, null, null, w, null);
- parent.ignoreSize = false;
- rect.width = w [0];
- int [] buffer = new int [1];
- if (OS.gtk_tree_view_get_expander_column (parentHandle) == column) {
- OS.gtk_widget_style_get (parentHandle, OS.expander_size, buffer, 0);
- rect.x += buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING;
- }
- OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0);
- int horizontalSeparator = buffer[0];
- rect.x += horizontalSeparator;
-
- if (OS.GTK_VERSION >= OS.VERSION (2, 1, 3)) {
- OS.gtk_tree_view_column_cell_get_position (column, textRenderer, x, null);
- rect.x += x [0];
- } else {
- if ((parent.style & SWT.CHECK) != 0) {
- OS.gtk_cell_renderer_get_size (parent.checkRenderer, parentHandle, null, null, null, w, null);
- rect.x += w [0] + horizontalSeparator;
- }
- OS.gtk_cell_renderer_get_size (pixbufRenderer, parentHandle, null, null, null, w, null);
- rect.x += w [0] + horizontalSeparator;
- }
- if (parent.columnCount > 0) {
- if (rect.x + rect.width > right) {
- rect.width = Math.max (0, right - rect.x);
- }
- }
- int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0;
- return new Rectangle (rect.x, rect.y, width, rect.height + 1);
-}
-
-/**
- * Returns the background color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Color getBackground (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return _getBackground (index);
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent at a column in the table.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding column rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds (int index) {
- checkWidget();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int /*long*/ parentHandle = parent.handle;
- int /*long*/ column = 0;
- if (index >= 0 && index < parent.columnCount) {
- column = parent.columns [index].handle;
- } else {
- column = OS.gtk_tree_view_get_column (parentHandle, index);
- }
- if (column == 0) return new Rectangle (0, 0, 0, 0);
- int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- OS.gtk_widget_realize (parentHandle);
- GdkRectangle rect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect);
- OS.gtk_tree_path_free (path);
- if ((parent.getStyle () & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth () - rect.width - rect.x;
-
- if (index == 0 && (parent.style & SWT.CHECK) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 1, 3)) {
- int [] x = new int [1], w = new int [1];
- OS.gtk_tree_view_column_cell_get_position (column, parent.checkRenderer, x, w);
- rect.x += x [0] + w [0];
- rect.width -= x [0] + w [0];
- } else {
- int [] w = new int [1];
- OS.gtk_cell_renderer_get_size (parent.checkRenderer, parentHandle, null, null, null, w, null);
- int [] buffer = new int [1];
- OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0);
- rect.x += w [0] + buffer [0];
- rect.width -= w [0] + buffer [0];
- }
- }
- int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0;
- return new Rectangle (rect.x, rect.y, width, rect.height + 1);
-}
-
-/**
- * Returns <code>true</code> if the receiver is checked,
- * and false otherwise. When the parent does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the checked state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getChecked () {
- checkWidget();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return _getChecked ();
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information for this item.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return font != null ? font : parent.getFont ();
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information
- * for the specified cell in this item.
- *
- * @param index the column index
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count - 1) return getFont ();
- if (cellFont == null || cellFont [index] == null) return getFont ();
- return cellFont [index];
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public Color getForeground () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return _getForeground ();
-}
-
-/**
- *
- * Returns the foreground color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Color getForeground (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return _getForeground (index);
-}
-
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the parent does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getGrayed () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return grayed;
-}
-
-public Image getImage () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return getImage (0);
-}
-
-/**
- * Returns the image stored at the given column index in the receiver,
- * or null if the image has not been set or if the column does not exist.
- *
- * @param index the column index
- * @return the image stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return _getImage (index);
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of an image at a column in the
- * table. An empty rectangle is returned if index exceeds
- * the index of the table's last column.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding image rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getImageBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int /*long*/ parentHandle = parent.handle;
- int /*long*/ column = 0;
- if (index >= 0 && index < parent.columnCount) {
- column = parent.columns [index].handle;
- } else {
- column = OS.gtk_tree_view_get_column (parentHandle, index);
- }
- if (column == 0) return new Rectangle (0, 0, 0, 0);
- int /*long*/ pixbufRenderer = parent.getPixbufRenderer (column);
- if (pixbufRenderer == 0) return new Rectangle (0, 0, 0, 0);
- GdkRectangle rect = new GdkRectangle ();
- int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- OS.gtk_widget_realize (parentHandle);
- OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect);
- OS.gtk_tree_path_free (path);
- if ((parent.getStyle () & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth () - rect.width - rect.x;
- /*
- * The OS call gtk_cell_renderer_get_size() provides the width of image to be drawn
- * by the cell renderer. If there is no image in the cell, the width is zero. If the table contains
- * images of varying widths, gtk_cell_renderer_get_size() will return the width of the image,
- * not the width of the area in which the image is drawn.
- * New API was added in GTK 2.1.3 for determining the full width of the renderer area.
- * For earlier versions of GTK, the result is only correct if all rows have images of the same
- * width.
- */
- if (OS.GTK_VERSION >= OS.VERSION (2, 1, 3)) {
- int [] x = new int [1], w = new int[1];
- OS.gtk_tree_view_column_cell_get_position (column, pixbufRenderer, x, w);
- rect.x += x [0];
- rect.width = w [0];
- } else {
- int [] w = new int [1];
- OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, false, false);
- OS.gtk_cell_renderer_get_size (pixbufRenderer, parentHandle, null, null, null, w, null);
- rect.width = w [0];
- }
- int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width : 0;
- return new Rectangle (rect.x, rect.y, width, rect.height + 1);
-}
-
-/**
- * Gets the image indent.
- *
- * @return the indent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getImageIndent () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- /* Image indent is not supported on GTK */
- return 0;
-}
-
-String getNameText () {
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (!cached) return "*virtual*"; //$NON-NLS-1$
- }
- return super.getNameText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Table</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Table getParent () {
- checkWidget ();
- return parent;
-}
-
-public String getText () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return getText (0);
-}
-
-/**
- * Returns the text stored at the given column index in the receiver,
- * or empty string if the text has not been set.
- *
- * @param index the column index
- * @return the text stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return _getText (index);
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of the text at a column in the
- * table. An empty rectangle is returned if index exceeds
- * the index of the table's last column.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding text rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Rectangle getTextBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return new Rectangle (0, 0, 0, 0);
- // TODO fully test on early and later versions of GTK
- // shifted a bit too far right on later versions of GTK - however, old Tree also had this problem
- int /*long*/ parentHandle = parent.handle;
- int /*long*/ column = 0;
- if (index >= 0 && index < parent.columnCount) {
- column = parent.columns [index].handle;
- } else {
- column = OS.gtk_tree_view_get_column (parentHandle, index);
- }
- if (column == 0) return new Rectangle (0, 0, 0, 0);
- int /*long*/ textRenderer = parent.getTextRenderer (column);
- int /*long*/ pixbufRenderer = parent.getPixbufRenderer (column);
- if (textRenderer == 0 || pixbufRenderer == 0) return new Rectangle (0, 0, 0, 0);
-
- int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- OS.gtk_widget_realize (parentHandle);
-
- boolean isExpander = OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle) > 0;
- boolean isExpanded = OS.gtk_tree_view_row_expanded (parentHandle, path);
- OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, isExpander, isExpanded);
-
- GdkRectangle rect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect);
- OS.gtk_tree_path_free (path);
- if ((parent.getStyle () & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth () - rect.width - rect.x;
- int right = rect.x + rect.width;
-
- int [] x = new int [1], w = new int [1];
- parent.ignoreSize = true;
- OS.gtk_cell_renderer_get_size (textRenderer, parentHandle, null, null, null, w, null);
- parent.ignoreSize = false;
- int [] buffer = new int [1];
- if (OS.gtk_tree_view_get_expander_column (parentHandle) == column) {
- OS.gtk_widget_style_get (parentHandle, OS.expander_size, buffer, 0);
- rect.x += buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING;
- }
- OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0);
- int horizontalSeparator = buffer[0];
- rect.x += horizontalSeparator;
-
- if (OS.GTK_VERSION >= OS.VERSION (2, 1, 3)) {
- OS.gtk_tree_view_column_cell_get_position (column, textRenderer, x, null);
- rect.x += x [0];
- } else {
- if ((parent.style & SWT.CHECK) != 0) {
- OS.gtk_cell_renderer_get_size (parent.checkRenderer, parentHandle, null, null, null, w, null);
- rect.x += w [0] + horizontalSeparator;
- }
- OS.gtk_cell_renderer_get_size (pixbufRenderer, parentHandle, null, null, null, w, null);
- rect.x += w [0] + horizontalSeparator;
- }
- if (parent.columnCount > 0) {
- if (rect.x + rect.width > right) {
- rect.width = Math.max (0, right - rect.x);
- }
- }
- int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0;
- return new Rectangle (rect.x, rect.y, width, rect.height + 1);
-}
-
-void redraw () {
- if ((OS.GTK_WIDGET_FLAGS (parent.handle) & OS.GTK_REALIZED) != 0) {
- int /*long*/ parentHandle = parent.handle;
- int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- GdkRectangle rect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (parentHandle, path, 0, rect);
- OS.gtk_tree_path_free (path);
- int /*long*/ window = OS.gtk_tree_view_get_bin_window (parentHandle);
- rect.x = 0;
- int [] w = new int [1], h = new int [1];
- OS.gdk_drawable_get_size (window, w, h);
- rect.width = w [0];
- OS.gdk_window_invalidate_rect (window, rect, false);
- }
-}
-
-void releaseHandle () {
- if (handle != 0) OS.g_free (handle);
- handle = 0;
- super.releaseHandle ();
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- font = null;
- cellFont = null;
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setBackground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (_getBackground ().equals (color)) return;
- GdkColor gdkColor = color != null ? color.handle : null;
- OS.gtk_list_store_set (parent.modelHandle, handle, Table.BACKGROUND_COLUMN, gdkColor, -1);
- /*
- * Bug in GTK. When using fixed-height-mode,
- * row changes do not cause the row to be repainted. The fix is to
- * invalidate the row when it is cleared.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) {
- redraw ();
- }
- }
- cached = true;
-}
-
-/**
- * Sets the background color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setBackground (int index, Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (_getBackground (index).equals (color)) return;
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
- GdkColor gdkColor = color != null ? color.handle : null;
- OS.gtk_list_store_set (parent.modelHandle, handle, modelIndex + Table.CELL_BACKGROUND, gdkColor, -1);
- /*
- * Bug in GTK. When using fixed-height-mode,
- * row changes do not cause the row to be repainted. The fix is to
- * invalidate the row when it is cleared.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) {
- redraw ();
- }
- }
- cached = true;
-
- if (color != null) {
- boolean customDraw = (parent.columnCount == 0) ? parent.firstCustomDraw : parent.columns [index].customDraw;
- if (!customDraw) {
- if ((parent.style & SWT.VIRTUAL) == 0) {
- int /*long*/ parentHandle = parent.handle;
- int /*long*/ column = 0;
- if (parent.columnCount > 0) {
- column = parent.columns [index].handle;
- } else {
- column = OS.gtk_tree_view_get_column (parentHandle, index);
- }
- if (column == 0) return;
- int /*long*/ textRenderer = parent.getTextRenderer (column);
- int /*long*/ imageRenderer = parent.getPixbufRenderer (column);
- OS.gtk_tree_view_column_set_cell_data_func (column, textRenderer, display.cellDataProc, parentHandle, 0);
- OS.gtk_tree_view_column_set_cell_data_func (column, imageRenderer, display.cellDataProc, parentHandle, 0);
- }
- if (parent.columnCount == 0) {
- parent.firstCustomDraw = true;
- } else {
- parent.columns [index].customDraw = true;
- }
- }
- }
-}
-
-/**
- * Sets the checked state of the checkbox for this item. This state change
- * only applies if the Table was created with the SWT.CHECK style.
- *
- * @param checked the new checked state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setChecked (boolean checked) {
- checkWidget();
- if ((parent.style & SWT.CHECK) == 0) return;
- if (_getChecked () == checked) return;
- OS.gtk_list_store_set (parent.modelHandle, handle, Table.CHECKED_COLUMN, checked, -1);
- /*
- * GTK+'s "inconsistent" state does not match SWT's concept of grayed. To
- * show checked+grayed differently from unchecked+grayed, we must toggle the
- * grayed state on check and uncheck.
- */
- OS.gtk_list_store_set (parent.modelHandle, handle, Table.GRAYED_COLUMN, !checked ? false : grayed, -1);
- cached = true;
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for this item to the font specified by the argument, or to the default font
- * for that kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (Font font){
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Font oldFont = this.font;
- if (oldFont == font) return;
- this.font = font;
- if (oldFont != null && oldFont.equals (font)) return;
- int /*long*/ fontHandle = font != null ? font.handle : 0;
- OS.gtk_list_store_set (parent.modelHandle, handle, Table.FONT_COLUMN, fontHandle, -1);
- /*
- * Bug in GTK. When using fixed-height-mode,
- * row changes do not cause the row to be repainted. The fix is to
- * invalidate the row when it is cleared.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) {
- redraw ();
- }
- }
- cached = true;
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for the specified cell in this item to the font specified by the
- * argument, or to the default font for that kind of control if the
- * argument is null.
- *
- * @param index the column index
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (int index, Font font) {
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- if (cellFont == null) {
- if (font == null) return;
- cellFont = new Font [count];
- }
- Font oldFont = cellFont [index];
- if (oldFont == font) return;
- cellFont [index] = font;
- if (oldFont != null && oldFont.equals (font)) return;
-
- int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
- int /*long*/ fontHandle = font != null ? font.handle : 0;
- OS.gtk_list_store_set (parent.modelHandle, handle, modelIndex + Table.CELL_FONT, fontHandle, -1);
- /*
- * Bug in GTK. When using fixed-height-mode,
- * row changes do not cause the row to be repainted. The fix is to
- * invalidate the row when it is cleared.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) {
- redraw ();
- }
- }
- cached = true;
-
- if (font != null) {
- boolean customDraw = (parent.columnCount == 0) ? parent.firstCustomDraw : parent.columns [index].customDraw;
- if (!customDraw) {
- if ((parent.style & SWT.VIRTUAL) == 0) {
- int /*long*/ parentHandle = parent.handle;
- int /*long*/ column = 0;
- if (parent.columnCount > 0) {
- column = parent.columns [index].handle;
- } else {
- column = OS.gtk_tree_view_get_column (parentHandle, index);
- }
- if (column == 0) return;
- int /*long*/ textRenderer = parent.getTextRenderer (column);
- int /*long*/ imageRenderer = parent.getPixbufRenderer (column);
- OS.gtk_tree_view_column_set_cell_data_func (column, textRenderer, display.cellDataProc, parentHandle, 0);
- OS.gtk_tree_view_column_set_cell_data_func (column, imageRenderer, display.cellDataProc, parentHandle, 0);
- }
- if (parent.columnCount == 0) {
- parent.firstCustomDraw = true;
- } else {
- parent.columns [index].customDraw = true;
- }
- }
- }
-}
-
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setForeground (Color color){
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (_getForeground ().equals (color)) return;
- GdkColor gdkColor = color != null ? color.handle : null;
- OS.gtk_list_store_set (parent.modelHandle, handle, Table.FOREGROUND_COLUMN, gdkColor, -1);
- /*
- * Bug in GTK. When using fixed-height-mode,
- * row changes do not cause the row to be repainted. The fix is to
- * invalidate the row when it is cleared.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) {
- redraw ();
- }
- }
- cached = true;
-}
-
-/**
- * Sets the foreground color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setForeground (int index, Color color){
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (_getForeground (index).equals (color)) return;
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
- GdkColor gdkColor = color != null ? color.handle : null;
- OS.gtk_list_store_set (parent.modelHandle, handle, modelIndex + Table.CELL_FOREGROUND, gdkColor, -1);
- /*
- * Bug in GTK. When using fixed-height-mode,
- * row changes do not cause the row to be repainted. The fix is to
- * invalidate the row when it is cleared.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) {
- redraw ();
- }
- }
- cached = true;
-
- if (color != null) {
- boolean customDraw = (parent.columnCount == 0) ? parent.firstCustomDraw : parent.columns [index].customDraw;
- if (!customDraw) {
- if ((parent.style & SWT.VIRTUAL) == 0) {
- int /*long*/ parentHandle = parent.handle;
- int /*long*/ column = 0;
- if (parent.columnCount > 0) {
- column = parent.columns [index].handle;
- } else {
- column = OS.gtk_tree_view_get_column (parentHandle, index);
- }
- if (column == 0) return;
- int /*long*/ textRenderer = parent.getTextRenderer (column);
- int /*long*/ imageRenderer = parent.getPixbufRenderer (column);
- OS.gtk_tree_view_column_set_cell_data_func (column, textRenderer, display.cellDataProc, parentHandle, 0);
- OS.gtk_tree_view_column_set_cell_data_func (column, imageRenderer, display.cellDataProc, parentHandle, 0);
- }
- if (parent.columnCount == 0) {
- parent.firstCustomDraw = true;
- } else {
- parent.columns [index].customDraw = true;
- }
- }
- }
-}
-
-/**
- * Sets the grayed state of the checkbox for this item. This state change
- * only applies if the Table was created with the SWT.CHECK style.
- *
- * @param grayed the new grayed state of the checkbox;
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setGrayed (boolean grayed) {
- checkWidget();
- if ((parent.style & SWT.CHECK) == 0) return;
- if (this.grayed == grayed) return;
- this.grayed = grayed;
- /*
- * GTK+'s "inconsistent" state does not match SWT's concept of grayed.
- * Render checked+grayed as "inconsistent", unchecked+grayed as blank.
- */
- int /*long*/ [] ptr = new int /*long*/ [1];
- OS.gtk_tree_model_get (parent.modelHandle, handle, Table.CHECKED_COLUMN, ptr, -1);
- OS.gtk_list_store_set (parent.modelHandle, handle, Table.GRAYED_COLUMN, ptr [0] == 0 ? false : grayed, -1);
- cached = true;
-}
-
-/**
- * Sets the receiver's image at a column.
- *
- * @param index the column index
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (int index, Image image) {
- checkWidget ();
- if (image != null && image.isDisposed ()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (image != null && image.type == SWT.ICON) {
- if (image.equals (_getImage (index))) return;
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- int /*long*/ pixbuf = 0;
- if (image != null) {
- ImageList imageList = parent.imageList;
- if (imageList == null) imageList = parent.imageList = new ImageList ();
- int imageIndex = imageList.indexOf (image);
- if (imageIndex == -1) imageIndex = imageList.add (image);
- pixbuf = imageList.getPixbuf (imageIndex);
- }
- int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
- OS.gtk_list_store_set (parent.modelHandle, handle, modelIndex + Table.CELL_PIXBUF, pixbuf, -1);
- /*
- * Bug in GTK. When using fixed-height-mode,
- * row changes do not cause the row to be repainted. The fix is to
- * invalidate the row when it is cleared.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) {
- redraw ();
- }
- }
- /*
- * Bug in GTK. When in fixed height mode, GTK does not recalculate the cell renderer width
- * when the image is changed in the model. The fix is to force it to recalculate the width if
- * more space is required.
- */
- if ((parent.style & SWT.VIRTUAL) != 0 && parent.currentItem == null) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2)) {
- if (image != null) {
- int /*long*/parentHandle = parent.handle;
- int /*long*/ column = OS.gtk_tree_view_get_column (parentHandle, index);
- int [] w = new int [1];
- int /*long*/ pixbufRenderer = parent.getPixbufRenderer(column);
- OS.gtk_tree_view_column_cell_get_position (column, pixbufRenderer, null, w);
- if (w[0] < image.getBounds().width) {
- /*
- * There is no direct way to clear the cell renderer width so we
- * are relying on the fact that it is done as part of modifying
- * the style.
- */
- int /*long*/ style = OS.gtk_widget_get_modifier_style (parentHandle);
- parent.modifyStyle (parentHandle, style);
- }
- }
- }
- }
- cached = true;
-}
-
-public void setImage (Image image) {
- checkWidget ();
- setImage (0, image);
-}
-
-/**
- * Sets the image for multiple columns in the table.
- *
- * @param images the array of new images
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image [] images) {
- checkWidget ();
- if (images == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<images.length; i++) {
- setImage (i, images [i]);
- }
-}
-
-/**
- * Sets the indent of the first column's image, expressed in terms of the image's width.
- *
- * @param indent the new indent
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @deprecated this functionality is not supported on most platforms
- */
-public void setImageIndent (int indent) {
- checkWidget ();
- if (indent < 0) return;
- /* Image indent is not supported on GTK */
- cached = true;
-}
-
-/**
- * Sets the receiver's text at a column
- *
- * @param index the column index
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (int index, String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (_getText (index).equals (string)) return;
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- byte[] buffer = Converter.wcsToMbcs (null, string, true);
- int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
- OS.gtk_list_store_set (parent.modelHandle, handle, modelIndex + Table.CELL_TEXT, buffer, -1);
- /*
- * Bug in GTK. When using fixed-height-mode,
- * row changes do not cause the row to be repainted. The fix is to
- * invalidate the row when it is cleared.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) {
- redraw ();
- }
- }
- cached = true;
-}
-
-public void setText (String string) {
- checkWidget ();
- setText (0, string);
-}
-
-/**
- * Sets the text for multiple columns in the table.
- *
- * @param strings the array of new strings
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String [] strings) {
- checkWidget ();
- if (strings == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<strings.length; i++) {
- String string = strings [i];
- if (string != null) setText (i, string);
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
deleted file mode 100644
index 0973f06da6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
+++ /dev/null
@@ -1,2152 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify text.
- * Text controls can be either single or multi-line.
- * When a text control is created with a border, the
- * operating system includes a platform specific inset
- * around the contents of the control. When created
- * without a border, an effort is made to remove the
- * inset such that the preferred size of the control
- * is the same size as the contents.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>CENTER, ICON_CANCEL, ICON_SEARCH, LEFT, MULTI, PASSWORD, SEARCH, SINGLE, RIGHT, READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Modify, Verify</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles MULTI and SINGLE may be specified,
- * and only one of the styles LEFT, CENTER, and RIGHT may be specified.
- * </p>
- * <p>
- * Note: The styles ICON_CANCEL and ICON_SEARCH are hints used in combination with SEARCH.
- * When the platform supports the hint, the text control shows these icons. When an icon
- * is selected, a default selection event is sent with the detail field set to one of
- * ICON_CANCEL or ICON_SEARCH. Normally, application code does not need to check the
- * detail. In the case of ICON_CANCEL, the text is cleared before the default selection
- * event is sent causing the application to search for an empty string.
- * </p>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#text">Text snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Text extends Scrollable {
- int /*long*/ bufferHandle;
- int tabs = 8, lastEventTime = 0;
- int /*long*/ gdkEventKey = 0;
- int fixStart = -1, fixEnd = -1;
- boolean doubleClick;
- String message = "";
-
- static final int ITER_SIZEOF = OS.GtkTextIter_sizeof();
- static final int SPACE_FOR_CURSOR = 1;
-
- /**
- * The maximum number of characters that can be entered
- * into a text widget.
- * <p>
- * Note that this value is platform dependent, based upon
- * the native widget implementation.
- * </p>
- */
- public final static int LIMIT;
- /**
- * The delimiter used by multi-line text widgets. When text
- * is queried and from the widget, it will be delimited using
- * this delimiter.
- */
- public final static String DELIMITER;
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0x7FFFFFFF;
- DELIMITER = "\n";
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#READ_ONLY
- * @see SWT#WRAP
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see SWT#PASSWORD
- * @see SWT#SEARCH
- * @see SWT#ICON_SEARCH
- * @see SWT#ICON_CANCEL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Text (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- if ((style & SWT.SEARCH) != 0) {
- style |= SWT.SINGLE | SWT.BORDER;
- style &= ~SWT.PASSWORD;
- /*
- * NOTE: ICON_CANCEL has the same value as H_SCROLL and
- * ICON_SEARCH has the same value as V_SCROLL so they are
- * cleared because SWT.SINGLE is set.
- */
- }
- if ((style & SWT.SINGLE) != 0 && (style & SWT.MULTI) != 0) {
- style &= ~SWT.MULTI;
- }
- style = checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
- if ((style & SWT.SINGLE) != 0) style &= ~(SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP);
- if ((style & SWT.WRAP) != 0) {
- style |= SWT.MULTI;
- style &= ~SWT.H_SCROLL;
- }
- if ((style & SWT.MULTI) != 0) style &= ~SWT.PASSWORD;
- if ((style & (SWT.SINGLE | SWT.MULTI)) != 0) return style;
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) return style | SWT.MULTI;
- return style | SWT.SINGLE;
-}
-
-void createHandle (int index) {
- state |= HANDLE | MENU;
- if ((style & SWT.READ_ONLY) != 0) {
- if ((style & (SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
- state |= THEME_BACKGROUND;
- }
- }
- fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (fixedHandle, true);
- if ((style & SWT.SINGLE) != 0) {
- handle = OS.gtk_entry_new ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (fixedHandle, handle);
- OS.gtk_editable_set_editable (handle, (style & SWT.READ_ONLY) == 0);
- OS.gtk_entry_set_has_frame (handle, (style & SWT.BORDER) != 0);
- OS.gtk_entry_set_visibility (handle, (style & SWT.PASSWORD) == 0);
- float alignment = 0.0f;
- if ((style & SWT.CENTER) != 0) alignment = 0.5f;
- if ((style & SWT.RIGHT) != 0) alignment = 1.0f;
- if (alignment > 0.0f) {
- OS.gtk_entry_set_alignment (handle, alignment);
- }
- } else {
- scrolledHandle = OS.gtk_scrolled_window_new (0, 0);
- if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
- handle = OS.gtk_text_view_new ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- bufferHandle = OS.gtk_text_view_get_buffer (handle);
- if (bufferHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (fixedHandle, scrolledHandle);
- OS.gtk_container_add (scrolledHandle, handle);
- OS.gtk_text_view_set_editable (handle, (style & SWT.READ_ONLY) == 0);
- if ((style & SWT.WRAP) != 0) OS.gtk_text_view_set_wrap_mode (handle, OS.GTK_VERSION < OS.VERSION (2, 4, 0) ? OS.GTK_WRAP_WORD : OS.GTK_WRAP_WORD_CHAR);
- int hsp = (style & SWT.H_SCROLL) != 0 ? OS.GTK_POLICY_ALWAYS : OS.GTK_POLICY_NEVER;
- int vsp = (style & SWT.V_SCROLL) != 0 ? OS.GTK_POLICY_ALWAYS : OS.GTK_POLICY_NEVER;
- OS.gtk_scrolled_window_set_policy (scrolledHandle, hsp, vsp);
- if ((style & SWT.BORDER) != 0) {
- OS.gtk_scrolled_window_set_shadow_type (scrolledHandle, OS.GTK_SHADOW_ETCHED_IN);
- }
- int just = OS.GTK_JUSTIFY_LEFT;
- if ((style & SWT.CENTER) != 0) just = OS.GTK_JUSTIFY_CENTER;
- if ((style & SWT.RIGHT) != 0) just = OS.GTK_JUSTIFY_RIGHT;
- OS.gtk_text_view_set_justification (handle, just);
- }
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- doubleClick = true;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is not called for texts.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text,
- * or when ENTER is pressed in a search text. If the receiver has the <code>SWT.SEARCH | SWT.CANCEL</code> style
- * and the user cancels the search, the event object detail field contains the value <code>SWT.CANCEL</code>.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- */
-public void addVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-
-/**
- * Appends a string.
- * <p>
- * The new text is appended to the text at
- * the end of the widget.
- * </p>
- *
- * @param string the string to be appended
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void append (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, string, false);
- if ((style & SWT.SINGLE) != 0) {
- OS.gtk_editable_insert_text (handle, buffer, buffer.length, new int[]{-1});
- OS.gtk_editable_set_position (handle, -1);
- } else {
- byte [] position = new byte [ITER_SIZEOF];
- OS.gtk_text_buffer_get_end_iter (bufferHandle, position);
- OS.gtk_text_buffer_insert (bufferHandle, position, buffer, buffer.length);
- OS.gtk_text_buffer_place_cursor (bufferHandle, position);
- int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle);
- OS.gtk_text_view_scroll_mark_onscreen (handle, mark);
- }
-}
-
-/**
- * Clears the selection.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void clearSelection () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- int position = OS.gtk_editable_get_position (handle);
- OS.gtk_editable_select_region (handle, position, position);
- } else {
- byte [] position = new byte [ITER_SIZEOF];
- int /*long*/ insertMark = OS.gtk_text_buffer_get_insert (bufferHandle);
- int /*long*/ selectionMark = OS.gtk_text_buffer_get_selection_bound (bufferHandle);
- OS.gtk_text_buffer_get_iter_at_mark (bufferHandle, position, insertMark);
- OS.gtk_text_buffer_move_mark (bufferHandle, selectionMark, position);
- OS.gtk_text_buffer_move_mark (bufferHandle, insertMark, position);
- }
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- int[] w = new int [1], h = new int [1];
- if ((style & SWT.SINGLE) != 0) {
- OS.gtk_widget_realize (handle);
- int /*long*/ layout = OS.gtk_entry_get_layout (handle);
- OS.pango_layout_get_size (layout, w, h);
- } else {
- byte [] start = new byte [ITER_SIZEOF], end = new byte [ITER_SIZEOF];
- OS.gtk_text_buffer_get_bounds (bufferHandle, start, end);
- int /*long*/ text = OS.gtk_text_buffer_get_text (bufferHandle, start, end, true);
- int /*long*/ layout = OS.gtk_widget_create_pango_layout (handle, text);
- OS.g_free (text);
- OS.pango_layout_set_width (layout, wHint * OS.PANGO_SCALE);
- OS.pango_layout_get_size (layout, w, h);
- OS.g_object_unref (layout);
- }
- int width = OS.PANGO_PIXELS (w [0]);
- int height = OS.PANGO_PIXELS (h [0]);
- if ((style & SWT.SINGLE) != 0 && message.length () > 0) {
- byte [] buffer = Converter.wcsToMbcs (null, message, true);
- int /*long*/ layout = OS.gtk_widget_create_pango_layout (handle, buffer);
- OS.pango_layout_get_size (layout, w, h);
- OS.g_object_unref (layout);
- width = Math.max (width, OS.PANGO_PIXELS (w [0]));
- }
- if (width == 0) width = DEFAULT_WIDTH;
- if (height == 0) height = DEFAULT_HEIGHT;
- width = wHint == SWT.DEFAULT ? width : wHint;
- height = hHint == SWT.DEFAULT ? height : hHint;
- Rectangle trim = computeTrim (0, 0, width, height);
- return new Point (trim.width, trim.height);
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
- Rectangle trim = super.computeTrim (x, y, width, height);
- int xborder = 0, yborder = 0;
- if ((style & SWT.SINGLE) != 0) {
- if ((style & SWT.BORDER) != 0) {
- int /*long*/ style = OS.gtk_widget_get_style (handle);
- xborder += OS.gtk_style_get_xthickness (style);
- yborder += OS.gtk_style_get_ythickness (style);
- }
- GtkBorder innerBorder = Display.getEntryInnerBorder (handle);
- trim.x -= innerBorder.left;
- trim.y -= innerBorder.top;
- trim.width += innerBorder.left + innerBorder.right;
- trim.height += innerBorder.top + innerBorder.bottom;
- } else {
- int borderWidth = OS.gtk_container_get_border_width (handle);
- xborder += borderWidth;
- yborder += borderWidth;
- }
- int [] property = new int [1];
- OS.gtk_widget_style_get (handle, OS.interior_focus, property, 0);
- if (property [0] == 0) {
- OS.gtk_widget_style_get (handle, OS.focus_line_width, property, 0);
- xborder += property [0];
- yborder += property [0];
- }
- trim.x -= xborder;
- trim.y -= yborder;
- trim.width += 2 * xborder;
- trim.height += 2 * yborder;
- trim.width += SPACE_FOR_CURSOR;
- return new Rectangle (trim.x, trim.y, trim.width, trim.height);
-}
-
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void copy () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- OS.gtk_editable_copy_clipboard (handle);
- } else {
- int /*long*/ clipboard = OS.gtk_clipboard_get (OS.GDK_NONE);
- OS.gtk_text_buffer_copy_clipboard (bufferHandle, clipboard);
- }
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void cut () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- OS.gtk_editable_cut_clipboard (handle);
- } else {
- int /*long*/ clipboard = OS.gtk_clipboard_get (OS.GDK_NONE);
- OS.gtk_text_buffer_cut_clipboard (bufferHandle, clipboard, OS.gtk_text_view_get_editable (handle));
- }
-}
-
-void deregister () {
- super.deregister ();
- if (bufferHandle != 0) display.removeWidget (bufferHandle);
- int /*long*/ imContext = imContext ();
- if (imContext != 0) display.removeWidget (imContext);
-}
-
-boolean dragDetect (int x, int y, boolean filter, boolean [] consume) {
- if (filter) {
- int start = 0, end = 0;
- if ((style & SWT.SINGLE) != 0) {
- int [] s = new int [1], e = new int [1];
- OS.gtk_editable_get_selection_bounds (handle, s, e);
- start = s [0];
- end = e [0];
- } else {
- byte [] s = new byte [ITER_SIZEOF], e = new byte [ITER_SIZEOF];
- OS.gtk_text_buffer_get_selection_bounds (bufferHandle, s, e);
- start = OS.gtk_text_iter_get_offset (s);
- end = OS.gtk_text_iter_get_offset (e);
- }
- if (start != end) {
- if (end < start) {
- int temp = end;
- end = start;
- start = temp;
- }
- int position = -1;
- if ((style & SWT.SINGLE) != 0) {
- int [] index = new int [1];
- int [] trailing = new int [1];
- int /*long*/ layout = OS.gtk_entry_get_layout (handle);
- OS.pango_layout_xy_to_index (layout, x * OS.PANGO_SCALE, y * OS.PANGO_SCALE, index, trailing);
- int /*long*/ ptr = OS.pango_layout_get_text (layout);
- position = (int)/*64*/OS.g_utf8_pointer_to_offset (ptr, ptr + index[0]) + trailing[0];
- } else {
- byte [] p = new byte [ITER_SIZEOF];
- OS.gtk_text_view_get_iter_at_location (handle, p, x, y);
- position = OS.gtk_text_iter_get_offset (p);
- }
- if (start <= position && position < end) {
- if (super.dragDetect (x, y, filter, consume)) {
- if (consume != null) consume [0] = true;
- return true;
- }
- }
- }
- return false;
- }
- return super.dragDetect (x, y, filter, consume);
-}
-
-int /*long*/ eventWindow () {
- return paintWindow ();
-}
-
-boolean filterKey (int keyval, int /*long*/ event) {
- int time = OS.gdk_event_get_time (event);
- if (time != lastEventTime) {
- lastEventTime = time;
- int /*long*/ imContext = imContext ();
- if (imContext != 0) {
- return OS.gtk_im_context_filter_keypress (imContext, event);
- }
- }
- gdkEventKey = event;
- return false;
-}
-
-void fixIM () {
- /*
- * The IM filter has to be called one time for each key press event.
- * When the IM is open the key events are duplicated. The first event
- * is filtered by SWT and the second event is filtered by GTK. In some
- * cases the GTK handler does not run (the widget is destroyed, the
- * application code consumes the event, etc), for these cases the IM
- * filter has to be called by SWT.
- */
- if (gdkEventKey != 0 && gdkEventKey != -1) {
- int /*long*/ imContext = imContext ();
- if (imContext != 0) {
- OS.gtk_im_context_filter_keypress (imContext, gdkEventKey);
- gdkEventKey = -1;
- return;
- }
- }
- gdkEventKey = 0;
-}
-
-GdkColor getBackgroundColor () {
- return getBaseColor ();
-}
-
-public int getBorderWidth () {
- checkWidget();
- if ((style & SWT.MULTI) != 0) return super.getBorderWidth ();
- int /*long*/ style = OS.gtk_widget_get_style (handle);
- if ((this.style & SWT.BORDER) != 0) {
- return OS.gtk_style_get_xthickness (style);
- }
- return 0;
-}
-
-/**
- * Returns the line number of the caret.
- * <p>
- * The line number of the caret is returned.
- * </p>
- *
- * @return the line number
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretLineNumber () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return 0;
- byte [] position = new byte [ITER_SIZEOF];
- int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle);
- OS.gtk_text_buffer_get_iter_at_mark (bufferHandle, position, mark);
- return OS.gtk_text_iter_get_line (position);
-}
-
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null).
- * <p>
- * The location of the caret is returned.
- * </p>
- *
- * @return a point, the location of the caret
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getCaretLocation () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- int index = OS.gtk_editable_get_position (handle);
- if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) {
- index = OS.gtk_entry_text_index_to_layout_index (handle, index);
- }
- int [] offset_x = new int [1], offset_y = new int [1];
- OS.gtk_entry_get_layout_offsets (handle, offset_x, offset_y);
- int /*long*/ layout = OS.gtk_entry_get_layout (handle);
- PangoRectangle pos = new PangoRectangle ();
- OS.pango_layout_index_to_pos (layout, index, pos);
- int x = offset_x [0] + OS.PANGO_PIXELS (pos.x) - getBorderWidth ();
- int y = offset_y [0] + OS.PANGO_PIXELS (pos.y);
- return new Point (x, y);
- }
- byte [] position = new byte [ITER_SIZEOF];
- int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle);
- OS.gtk_text_buffer_get_iter_at_mark (bufferHandle, position, mark);
- GdkRectangle rect = new GdkRectangle ();
- OS.gtk_text_view_get_iter_location (handle, position, rect);
- int [] x = new int [1];
- int [] y = new int [1];
- OS.gtk_text_view_buffer_to_window_coords (handle, OS.GTK_TEXT_WINDOW_TEXT, rect.x, rect.y, x, y);
- return new Point (x [0], y [0]);
-}
-
-/**
- * Returns the character position of the caret.
- * <p>
- * Indexing is zero based.
- * </p>
- *
- * @return the position of the caret
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretPosition () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- return OS.gtk_editable_get_position (handle);
- }
- byte [] position = new byte [ITER_SIZEOF];
- int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle);
- OS.gtk_text_buffer_get_iter_at_mark (bufferHandle, position, mark);
- return OS.gtk_text_iter_get_offset (position);
-}
-
-/**
- * Returns the number of characters.
- *
- * @return number of characters in the widget
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCharCount () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- int /*long*/ ptr = OS.gtk_entry_get_text (handle);
- return (int)/*64*/OS.g_utf8_strlen (ptr, -1);
- }
- return OS.gtk_text_buffer_get_char_count (bufferHandle);
-}
-
-/**
- * Returns the double click enabled flag.
- * <p>
- * The double click flag enables or disables the
- * default action of the text widget when the user
- * double clicks.
- * </p>
- *
- * @return whether or not double click is enabled
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getDoubleClickEnabled () {
- checkWidget ();
- return doubleClick;
-}
-
-/**
- * Returns the echo character.
- * <p>
- * The echo character is the character that is
- * displayed when the user enters text or the
- * text is changed by the programmer.
- * </p>
- *
- * @return the echo character
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setEchoChar
- */
-public char getEchoChar () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- if (!OS.gtk_entry_get_visibility (handle)) {
- return OS.gtk_entry_get_invisible_char (handle);
- }
- }
- return '\0';
-}
-
-/**
- * Returns the editable state.
- *
- * @return whether or not the receiver is editable
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getEditable () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- return OS.gtk_editable_get_editable (handle);
- }
- return OS.gtk_text_view_get_editable (handle);
-}
-
-GdkColor getForegroundColor () {
- return getTextColor ();
-}
-
-/**
- * Returns the number of lines.
- *
- * @return the number of lines in the widget
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getLineCount () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return 1;
- return OS.gtk_text_buffer_get_line_count (bufferHandle);
-}
-
-/**
- * Returns the line delimiter.
- *
- * @return a string that is the line delimiter
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #DELIMITER
- */
-public String getLineDelimiter () {
- checkWidget ();
- return "\n";
-}
-
-/**
- * Returns the height of a line.
- *
- * @return the height of a row of text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getLineHeight () {
- checkWidget ();
- return fontHeight (getFontDescription (), handle);
-}
-
-/**
- * Returns the widget message. The message text is displayed
- * as a hint for the user, indicating the purpose of the field.
- * <p>
- * Typically this is used in conjunction with <code>SWT.SEARCH</code>.
- * </p>
- *
- * @return the widget message
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public String getMessage () {
- checkWidget ();
- return message;
-}
-
-/**
- * Returns the orientation of the receiver, which will be one of the
- * constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getOrientation () {
- checkWidget();
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-/*public*/ int getPosition (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- int position = -1;
- if ((style & SWT.SINGLE) != 0) {
- int [] index = new int [1];
- int [] trailing = new int [1];
- int /*long*/ layout = OS.gtk_entry_get_layout (handle);
- OS.pango_layout_xy_to_index (layout, point.x * OS.PANGO_SCALE, point.y * OS.PANGO_SCALE, index, trailing);
- int /*long*/ ptr = OS.pango_layout_get_text (layout);
- position = (int)/*64*/OS.g_utf8_pointer_to_offset (ptr, ptr + index[0]) + trailing[0];
- } else {
- byte [] p = new byte [ITER_SIZEOF];
- OS.gtk_text_view_get_iter_at_location (handle, p, point.x, point.y);
- position = OS.gtk_text_iter_get_offset (p);
- }
- return position;
-}
-
-/**
- * Returns a <code>Point</code> whose x coordinate is the
- * character position representing the start of the selected
- * text, and whose y coordinate is the character position
- * representing the end of the selection. An "empty" selection
- * is indicated by the x and y coordinates having the same value.
- * <p>
- * Indexing is zero based. The range of a selection is from
- * 0..N where N is the number of characters in the widget.
- * </p>
- *
- * @return a point representing the selection start and end
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSelection () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- int [] start = new int [1];
- int [] end = new int [1];
- OS.gtk_editable_get_selection_bounds (handle, start, end);
- return new Point (start [0], end [0]);
- }
- byte [] start = new byte [ITER_SIZEOF];
- byte [] end = new byte [ITER_SIZEOF];
- OS.gtk_text_buffer_get_selection_bounds (bufferHandle, start, end);
- return new Point (OS.gtk_text_iter_get_offset (start), OS.gtk_text_iter_get_offset (end));
-}
-
-/**
- * Returns the number of selected characters.
- *
- * @return the number of selected characters.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget ();
- Point selection = getSelection ();
- return Math.abs (selection.y - selection.x);
-}
-
-/**
- * Gets the selected text, or an empty string if there is no current selection.
- *
- * @return the selected text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getSelectionText () {
- checkWidget ();
- Point selection = getSelection ();
- return getText ().substring(selection.x, selection.y);
-}
-
-/**
- * Returns the number of tabs.
- * <p>
- * Tab stop spacing is specified in terms of the
- * space (' ') character. The width of a single
- * tab stop is the pixel width of the spaces.
- * </p>
- *
- * @return the number of tab characters
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTabs () {
- checkWidget ();
- return tabs;
-}
-
-int getTabWidth (int tabs) {
- byte[] buffer = Converter.wcsToMbcs(null, " ", true);
- int /*long*/ layout = OS.gtk_widget_create_pango_layout (handle, buffer);
- int [] width = new int [1];
- int [] height = new int [1];
- OS.pango_layout_get_size (layout, width, height);
- OS.g_object_unref (layout);
- return width [0] * tabs;
-}
-
-/**
- * Returns the widget text.
- * <p>
- * The text for a text widget is the characters in the widget, or
- * an empty string if this has never been set.
- * </p>
- *
- * @return the widget text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- int /*long*/ address;
- if ((style & SWT.SINGLE) != 0) {
- address = OS.gtk_entry_get_text (handle);
- } else {
- byte [] start = new byte [ITER_SIZEOF];
- byte [] end = new byte [ITER_SIZEOF];
- OS.gtk_text_buffer_get_bounds (bufferHandle, start, end);
- address = OS.gtk_text_buffer_get_text (bufferHandle, start, end, true);
- }
- if (address == 0) return "";
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- if ((style & SWT.MULTI) != 0) OS.g_free (address);
- return new String (Converter.mbcsToWcs (null, buffer));
-}
-
-/**
- * Returns a range of text. Returns an empty string if the
- * start of the range is greater than the end.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N-1 where N is
- * the number of characters in the widget.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- * @return the range of text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText (int start, int end) {
- checkWidget ();
- if (!(start <= end && 0 <= end)) return "";
- int /*long*/ address;
- if ((style & SWT.SINGLE) != 0) {
- start = Math.max (0, start);
- address = OS.gtk_editable_get_chars (handle, start, end + 1);
- } else {
- int length = OS.gtk_text_buffer_get_char_count (bufferHandle);
- end = Math.min (end, length - 1);
- if (start > end) return "";
- start = Math.max (0, start);
- byte [] startIter = new byte [ITER_SIZEOF];
- byte [] endIter = new byte [ITER_SIZEOF];
- OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, startIter, start);
- OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, endIter, end + 1);
- address = OS.gtk_text_buffer_get_text (bufferHandle, startIter, endIter, true);
- }
- if (address == 0) error (SWT.ERROR_CANNOT_GET_TEXT);
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- OS.g_free (address);
- return new String (Converter.mbcsToWcs (null, buffer));
-}
-
-/**
- * Returns the maximum number of characters that the receiver is capable of holding.
- * <p>
- * If this has not been changed by <code>setTextLimit()</code>,
- * it will be the constant <code>Text.LIMIT</code>.
- * </p>
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public int getTextLimit () {
- checkWidget ();
- if ((style & SWT.MULTI) != 0) return LIMIT;
- int limit = OS.gtk_entry_get_max_length (handle);
- return limit == 0 ? 0xFFFF : limit;
-}
-
-/**
- * Returns the zero-relative index of the line which is currently
- * at the top of the receiver.
- * <p>
- * This index can change when lines are scrolled or new lines are added or removed.
- * </p>
- *
- * @return the index of the top line
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return 0;
- byte [] position = new byte [ITER_SIZEOF];
- GdkRectangle rect = new GdkRectangle ();
- OS.gtk_text_view_get_visible_rect (handle, rect);
- OS.gtk_text_view_get_line_at_y (handle, position, rect.y, null);
- return OS.gtk_text_iter_get_line (position);
-}
-
-/**
- * Returns the top pixel.
- * <p>
- * The top pixel is the pixel position of the line
- * that is currently at the top of the widget. On
- * some platforms, a text widget can be scrolled by
- * pixels instead of lines so that a partial line
- * is displayed at the top of the widget.
- * </p><p>
- * The top pixel changes when the widget is scrolled.
- * The top pixel does not include the widget trimming.
- * </p>
- *
- * @return the pixel position of the top line
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopPixel () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return 0;
- byte [] position = new byte [ITER_SIZEOF];
- GdkRectangle rect = new GdkRectangle ();
- OS.gtk_text_view_get_visible_rect (handle, rect);
- int [] lineTop = new int[1];
- OS.gtk_text_view_get_line_at_y (handle, position, rect.y, lineTop);
- return lineTop [0];
-}
-
-int /*long*/ gtk_activate (int /*long*/ widget) {
- postEvent (SWT.DefaultSelection);
- return 0;
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_button_press_event (widget, event);
- if (result != 0) return result;
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
- if (!doubleClick) {
- switch (gdkEvent.type) {
- case OS.GDK_2BUTTON_PRESS:
- case OS.GDK_3BUTTON_PRESS:
- return 1;
- }
- }
- return result;
-}
-
-
-int /*long*/ gtk_changed (int /*long*/ widget) {
- /*
- * Feature in GTK. When the user types, GTK positions
- * the caret after sending the changed signal. This
- * means that application code that attempts to position
- * the caret during a changed signal will fail. The fix
- * is to post the modify event when the user is typing.
- */
- boolean keyPress = false;
- int /*long*/ eventPtr = OS.gtk_get_current_event ();
- if (eventPtr != 0) {
- GdkEventKey gdkEvent = new GdkEventKey ();
- OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof);
- switch (gdkEvent.type) {
- case OS.GDK_KEY_PRESS:
- keyPress = true;
- break;
- }
- OS.gdk_event_free (eventPtr);
- }
- if (keyPress) {
- postEvent (SWT.Modify);
- } else {
- sendEvent (SWT.Modify);
- }
- return 0;
-}
-
-int /*long*/ gtk_commit (int /*long*/ imContext, int /*long*/ text) {
- if (text == 0) return 0;
- if ((style & SWT.SINGLE) != 0) {
- if (!OS.gtk_editable_get_editable (handle)) return 0;
- }
- int length = OS.strlen (text);
- if (length == 0) return 0;
- byte [] buffer = new byte [length];
- OS.memmove (buffer, text, length);
- char [] chars = Converter.mbcsToWcs (null, buffer);
- char [] newChars = sendIMKeyEvent (SWT.KeyDown, null, chars);
- if (newChars == null) return 0;
- /*
- * Feature in GTK. For a GtkEntry, during the insert-text signal,
- * GTK allows the programmer to change only the caret location,
- * not the selection. If the programmer changes the selection,
- * the new selection is lost. The fix is to detect a selection
- * change and set it after the insert-text signal has completed.
- */
- fixStart = fixEnd = -1;
- OS.g_signal_handlers_block_matched (imContext, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, COMMIT);
- int id = OS.g_signal_lookup (OS.commit, OS.gtk_im_context_get_type ());
- int mask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID;
- OS.g_signal_handlers_unblock_matched (imContext, mask, id, 0, 0, 0, handle);
- if (newChars == chars) {
- OS.g_signal_emit_by_name (imContext, OS.commit, text);
- } else {
- buffer = Converter.wcsToMbcs (null, newChars, true);
- OS.g_signal_emit_by_name (imContext, OS.commit, buffer);
- }
- OS.g_signal_handlers_unblock_matched (imContext, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, COMMIT);
- OS.g_signal_handlers_block_matched (imContext, mask, id, 0, 0, 0, handle);
- if ((style & SWT.SINGLE) != 0) {
- if (fixStart != -1 && fixEnd != -1) {
- OS.gtk_editable_set_position (handle, fixStart);
- OS.gtk_editable_select_region (handle, fixStart, fixEnd);
- }
- }
- fixStart = fixEnd = -1;
- return 0;
-}
-
-int /*long*/ gtk_delete_range (int /*long*/ widget, int /*long*/ iter1, int /*long*/ iter2) {
- if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0;
- byte [] startIter = new byte [ITER_SIZEOF];
- byte [] endIter = new byte [ITER_SIZEOF];
- OS.memmove (startIter, iter1, startIter.length);
- OS.memmove (endIter, iter2, endIter.length);
- int start = OS.gtk_text_iter_get_offset (startIter);
- int end = OS.gtk_text_iter_get_offset (endIter);
- String newText = verifyText ("", start, end);
- if (newText == null) {
- /* Remember the selection when the text was deleted */
- OS.gtk_text_buffer_get_selection_bounds (bufferHandle, startIter, endIter);
- start = OS.gtk_text_iter_get_offset (startIter);
- end = OS.gtk_text_iter_get_offset (endIter);
- if (start != end) {
- fixStart = start;
- fixEnd = end;
- }
- OS.g_signal_stop_emission_by_name (bufferHandle, OS.delete_range);
- } else {
- if (newText.length () > 0) {
- byte [] buffer = Converter.wcsToMbcs (null, newText, false);
- OS.g_signal_handlers_block_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_signal_handlers_block_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_RANGE);
- OS.gtk_text_buffer_delete (bufferHandle, startIter, endIter);
- OS.g_signal_handlers_unblock_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_RANGE);
- OS.g_signal_handlers_unblock_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_signal_handlers_block_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEXT_BUFFER_INSERT_TEXT);
- OS.gtk_text_buffer_insert (bufferHandle, startIter, buffer, buffer.length);
- OS.g_signal_handlers_unblock_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEXT_BUFFER_INSERT_TEXT);
- OS.g_signal_stop_emission_by_name (bufferHandle, OS.delete_range);
- }
- }
- return 0;
-}
-
-int /*long*/ gtk_delete_text (int /*long*/ widget, int /*long*/ start_pos, int /*long*/ end_pos) {
- if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0;
- String newText = verifyText ("", (int)/*64*/start_pos, (int)/*64*/end_pos);
- if (newText == null) {
- /* Remember the selection when the text was deleted */
- int [] newStart = new int [1], newEnd = new int [1];
- OS.gtk_editable_get_selection_bounds (handle, newStart, newEnd);
- if (newStart [0] != newEnd [0]) {
- fixStart = newStart [0];
- fixEnd = newEnd [0];
- }
- OS.g_signal_stop_emission_by_name (handle, OS.delete_text);
- } else {
- if (newText.length () > 0) {
- int [] pos = new int [1];
- pos [0] = (int)/*64*/end_pos;
- byte [] buffer = Converter.wcsToMbcs (null, newText, false);
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT);
- OS.gtk_editable_insert_text (handle, buffer, buffer.length, pos);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_editable_set_position (handle, pos [0]);
- }
- }
- return 0;
-}
-
-int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) {
- if (cursor != null) setCursor (cursor.handle);
- /*
- * Feature in GTK. The gtk-entry-select-on-focus property is a global
- * setting. Return it to its default value after the GtkEntry has done
- * its focus in processing so that other widgets (such as the combo)
- * use the correct value.
- */
- if ((style & SWT.SINGLE) != 0 && display.entrySelectOnFocus) {
- GdkEvent event = new GdkEvent ();
- OS.memmove (event, gdkEvent, GdkEvent.sizeof);
- switch (event.type) {
- case OS.GDK_FOCUS_CHANGE:
- GdkEventFocus gdkEventFocus = new GdkEventFocus ();
- OS.memmove (gdkEventFocus, gdkEvent, GdkEventFocus.sizeof);
- if (gdkEventFocus.in == 0) {
- int /*long*/ settings = OS.gtk_settings_get_default ();
- OS.g_object_set (settings, OS.gtk_entry_select_on_focus, true, 0);
- }
- break;
- }
- }
- return super.gtk_event_after (widget, gdkEvent);
-}
-
-int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ event) {
- if ((state & OBSCURED) != 0) return 0;
- int /*long*/ result = super.gtk_expose_event (widget, event);
- if ((style & SWT.SINGLE) != 0 && message.length () > 0) {
- int /*long*/ str = OS.gtk_entry_get_text (handle);
- if (!OS.GTK_WIDGET_HAS_FOCUS (handle) && OS.strlen (str) == 0) {
- GdkEventExpose gdkEvent = new GdkEventExpose ();
- OS.memmove (gdkEvent, event, GdkEventExpose.sizeof);
- int /*long*/ window = paintWindow ();
- int [] w = new int [1], h = new int [1];
- OS.gdk_drawable_get_size (window, w, h);
- GtkBorder innerBorder = Display.getEntryInnerBorder (handle);
- int width = w [0] - innerBorder.left - innerBorder.right;
- int height = h [0] - innerBorder.top - innerBorder.bottom;
- int /*long*/ context = OS.gtk_widget_get_pango_context (handle);
- int /*long*/ lang = OS.pango_context_get_language (context);
- int /*long*/ metrics = OS.pango_context_get_metrics (context, getFontDescription (), lang);
- int ascent = OS.PANGO_PIXELS (OS.pango_font_metrics_get_ascent (metrics));
- int descent = OS.PANGO_PIXELS (OS.pango_font_metrics_get_descent (metrics));
- OS.pango_font_metrics_unref (metrics);
- byte [] buffer = Converter.wcsToMbcs (null, message, true);
- int /*long*/ layout = OS.gtk_widget_create_pango_layout (handle, buffer);
- int /*long*/ line = OS.pango_layout_get_line (layout, 0);
- PangoRectangle rect = new PangoRectangle ();
- OS.pango_layout_line_get_extents (line, null, rect);
- rect.y = OS.PANGO_PIXELS (rect.y);
- rect.height = OS.PANGO_PIXELS (rect.height);
- rect.width = OS.PANGO_PIXELS (rect.width);
- int y = (height - ascent - descent) / 2 + ascent + rect.y;
- if (rect.height > height) {
- y = (height - rect.height) / 2;
- } else if (y < 0) {
- y = 0;
- } else if (y + rect.height > height) {
- y = height - rect.height;
- }
- y += innerBorder.top;
- int x = innerBorder.left;
- boolean rtl = (style & SWT.RIGHT_TO_LEFT) != 0;
- int alignment = style & (SWT.LEFT | SWT.CENTER | SWT.RIGHT);
- switch (alignment) {
- case SWT.LEFT: x = rtl ? width - rect.width: innerBorder.left; break;
- case SWT.CENTER: x = (width - rect.width) / 2; break;
- case SWT.RIGHT: x = rtl ? innerBorder.left : width - rect.width; break;
- }
- int /*long*/ gc = OS.gdk_gc_new (window);
- int /*long*/ style = OS.gtk_widget_get_style (handle);
- GdkColor textColor = new GdkColor ();
- OS.gtk_style_get_text (style, OS.GTK_STATE_INSENSITIVE, textColor);
- GdkColor baseColor = new GdkColor ();
- OS.gtk_style_get_base (style, OS.GTK_STATE_NORMAL, baseColor);
- OS.gdk_draw_layout_with_colors (window, gc, x, y, layout, textColor, baseColor);
- OS.g_object_unref (gc);
- OS.g_object_unref (layout);
- }
- }
- return result;
-}
-
-int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) {
- fixIM ();
- return super.gtk_focus_out_event (widget, event);
-}
-
-int /*long*/ gtk_grab_focus (int /*long*/ widget) {
- int /*long*/ result = super.gtk_grab_focus (widget);
- /*
- * Feature in GTK. GtkEntry widgets select their text on focus in,
- * clearing the previous selection. This behavior is controlled by
- * the gtk-entry-select-on-focus property. The fix is to disable
- * this property when a GtkEntry is given focus and restore it after
- * the entry has done focus in processing.
- */
- if ((style & SWT.SINGLE) != 0 && display.entrySelectOnFocus) {
- int /*long*/ settings = OS.gtk_settings_get_default ();
- OS.g_object_set (settings, OS.gtk_entry_select_on_focus, false, 0);
- }
- return result;
-}
-
-int /*long*/ gtk_insert_text (int /*long*/ widget, int /*long*/ new_text, int /*long*/ new_text_length, int /*long*/ position) {
- if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0;
- if (new_text == 0 || new_text_length == 0) return 0;
- byte [] buffer = new byte [(int)/*64*/new_text_length];
- OS.memmove (buffer, new_text, buffer.length);
- String oldText = new String (Converter.mbcsToWcs (null, buffer));
- int [] pos = new int [1];
- OS.memmove (pos, position, 4);
- if (pos [0] == -1) {
- int /*long*/ ptr = OS.gtk_entry_get_text (handle);
- pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1);
- }
- /* Use the selection when the text was deleted */
- int start = pos [0], end = pos [0];
- if (fixStart != -1 && fixEnd != -1) {
- start = pos [0] = fixStart;
- end = fixEnd;
- fixStart = fixEnd = -1;
- }
- String newText = verifyText (oldText, start, end);
- if (newText != oldText) {
- int [] newStart = new int [1], newEnd = new int [1];
- OS.gtk_editable_get_selection_bounds (handle, newStart, newEnd);
- if (newText != null) {
- if (newStart [0] != newEnd [0]) {
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT);
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_editable_delete_selection (handle);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- }
- byte [] buffer3 = Converter.wcsToMbcs (null, newText, false);
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT);
- OS.gtk_editable_insert_text (handle, buffer3, buffer3.length, pos);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT);
- newStart [0] = newEnd [0] = pos [0];
- }
- pos [0] = newEnd [0];
- if (newStart [0] != newEnd [0]) {
- fixStart = newStart [0];
- fixEnd = newEnd [0];
- }
- OS.memmove (position, pos, 4);
- OS.g_signal_stop_emission_by_name (handle, OS.insert_text);
- }
- return 0;
-}
-
-int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ result = super.gtk_key_press_event (widget, event);
- if (result != 0) fixIM ();
- if (gdkEventKey == -1) result = 1;
- gdkEventKey = 0;
- return result;
-}
-
-int /*long*/ gtk_populate_popup (int /*long*/ widget, int /*long*/ menu) {
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- OS.gtk_widget_set_direction (menu, OS.GTK_TEXT_DIR_RTL);
- OS.gtk_container_forall (menu, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL);
- }
- return 0;
-}
-
-int /*long*/ gtk_text_buffer_insert_text (int /*long*/ widget, int /*long*/ iter, int /*long*/ text, int /*long*/ length) {
- if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0;
- byte [] position = new byte [ITER_SIZEOF];
- OS.memmove (position, iter, position.length);
- /* Use the selection when the text was deleted */
- int start = OS.gtk_text_iter_get_offset (position), end = start;
- if (fixStart != -1 && fixEnd != -1) {
- start = fixStart;
- end = fixEnd;
- fixStart = fixEnd = -1;
- }
- byte [] buffer = new byte [(int)/*64*/length];
- OS.memmove (buffer, text, buffer.length);
- String oldText = new String (Converter.mbcsToWcs (null, buffer));
- String newText = verifyText (oldText, start, end);
- if (newText == null) {
- OS.g_signal_stop_emission_by_name (bufferHandle, OS.insert_text);
- } else {
- if (newText != oldText) {
- byte [] buffer1 = Converter.wcsToMbcs (null, newText, false);
- OS.g_signal_handlers_block_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEXT_BUFFER_INSERT_TEXT);
- OS.gtk_text_buffer_insert (bufferHandle, iter, buffer1, buffer1.length);
- OS.g_signal_handlers_unblock_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEXT_BUFFER_INSERT_TEXT);
- OS.g_signal_stop_emission_by_name (bufferHandle, OS.insert_text);
- }
- }
- return 0;
-}
-
-void hookEvents () {
- super.hookEvents();
- if ((style & SWT.SINGLE) != 0) {
- OS.g_signal_connect_closure (handle, OS.changed, display.closures [CHANGED], true);
- OS.g_signal_connect_closure (handle, OS.insert_text, display.closures [INSERT_TEXT], false);
- OS.g_signal_connect_closure (handle, OS.delete_text, display.closures [DELETE_TEXT], false);
- OS.g_signal_connect_closure (handle, OS.activate, display.closures [ACTIVATE], false);
- OS.g_signal_connect_closure (handle, OS.grab_focus, display.closures [GRAB_FOCUS], false);
- OS.g_signal_connect_closure (handle, OS.populate_popup, display.closures [POPULATE_POPUP], false);
- } else {
- OS.g_signal_connect_closure (bufferHandle, OS.changed, display.closures [CHANGED], false);
- OS.g_signal_connect_closure (bufferHandle, OS.insert_text, display.closures [TEXT_BUFFER_INSERT_TEXT], false);
- OS.g_signal_connect_closure (bufferHandle, OS.delete_range, display.closures [DELETE_RANGE], false);
- OS.g_signal_connect_closure (handle, OS.populate_popup, display.closures [POPULATE_POPUP], false);
- }
- int /*long*/ imContext = imContext ();
- if (imContext != 0) {
- OS.g_signal_connect_closure (imContext, OS.commit, display.closures [COMMIT], false);
- int id = OS.g_signal_lookup (OS.commit, OS.gtk_im_context_get_type ());
- int mask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID;
- OS.g_signal_handlers_block_matched (imContext, mask, id, 0, 0, 0, handle);
- }
-}
-
-int /*long*/ imContext () {
- if ((style & SWT.SINGLE) != 0) {
- return OS.gtk_editable_get_editable (handle) ? OS.GTK_ENTRY_IM_CONTEXT (handle) : 0;
- }
- return OS.GTK_TEXTVIEW_IM_CONTEXT (handle);
-}
-
-/**
- * Inserts a string.
- * <p>
- * The old selection is replaced with the new text.
- * </p>
- *
- * @param string the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is <code>null</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void insert (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, string, false);
- if ((style & SWT.SINGLE) != 0) {
- int [] start = new int [1], end = new int [1];
- OS.gtk_editable_get_selection_bounds (handle, start, end);
- OS.gtk_editable_delete_selection (handle);
- OS.gtk_editable_insert_text (handle, buffer, buffer.length, start);
- OS.gtk_editable_set_position (handle, start [0]);
- } else {
- byte [] start = new byte [ITER_SIZEOF];
- byte [] end = new byte [ITER_SIZEOF];
- if (OS.gtk_text_buffer_get_selection_bounds (bufferHandle, start, end)) {
- OS.gtk_text_buffer_delete (bufferHandle, start, end);
- }
- OS.gtk_text_buffer_insert (bufferHandle, start, buffer, buffer.length);
- OS.gtk_text_buffer_place_cursor (bufferHandle, start);
- int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle);
- OS.gtk_text_view_scroll_mark_onscreen (handle, mark);
- }
-}
-
-int /*long*/ paintWindow () {
- if ((style & SWT.SINGLE) != 0) {
- int /*long*/ window = super.paintWindow ();
- int /*long*/ children = OS.gdk_window_get_children (window);
- if (children != 0) window = OS.g_list_data (children);
- OS.g_list_free (children);
- return window;
- }
- OS.gtk_widget_realize (handle);
- return OS.gtk_text_view_get_window (handle, OS.GTK_TEXT_WINDOW_TEXT);
-}
-
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void paste () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- OS.gtk_editable_paste_clipboard (handle);
- } else {
- int /*long*/ clipboard = OS.gtk_clipboard_get (OS.GDK_NONE);
- OS.gtk_text_buffer_paste_clipboard (bufferHandle, clipboard, null, OS.gtk_text_view_get_editable (handle));
- }
-}
-
-void register () {
- super.register ();
- if (bufferHandle != 0) display.addWidget (bufferHandle, this);
- int /*long*/ imContext = imContext ();
- if (imContext != 0) display.addWidget (imContext, this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- fixIM ();
- if (OS.GTK_VERSION < OS.VERSION (2, 6, 0)) {
- /*
- * Bug in GTK. Any text copied into the clipboard will be lost when
- * the GtkTextView is destroyed. The fix is to paste the contents as
- * the widget is being destroyed to reference the text buffer, keeping
- * it around until ownership of the clipboard is lost.
- */
- if ((style & SWT.MULTI) != 0) {
- int /*long*/ clipboard = OS.gtk_clipboard_get (OS.GDK_NONE);
- OS.gtk_text_buffer_paste_clipboard (bufferHandle, clipboard, null, OS.gtk_text_view_get_editable (handle));
- }
- }
- message = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- */
-public void removeVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-
-/**
- * Selects all the text in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- OS.gtk_editable_select_region (handle, 0, -1);
- } else {
- byte [] start = new byte [ITER_SIZEOF];
- byte [] end = new byte [ITER_SIZEOF];
- OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, start, 0);
- OS.gtk_text_buffer_get_end_iter (bufferHandle, end);
- int /*long*/ insertMark = OS.gtk_text_buffer_get_insert (bufferHandle);
- int /*long*/ selectionMark = OS.gtk_text_buffer_get_selection_bound (bufferHandle);
- OS.gtk_text_buffer_move_mark (bufferHandle, selectionMark, start);
- OS.gtk_text_buffer_move_mark (bufferHandle, insertMark, end);
- }
-}
-
-void setBackgroundColor (GdkColor color) {
- super.setBackgroundColor (color);
- OS.gtk_widget_modify_base (handle, 0, color);
-}
-
-void setCursor (int /*long*/ cursor) {
- int /*long*/ defaultCursor = 0;
- if (cursor == 0) defaultCursor = OS.gdk_cursor_new (OS.GDK_XTERM);
- super.setCursor (cursor != 0 ? cursor : defaultCursor);
- if (cursor == 0) OS.gdk_cursor_destroy (defaultCursor);
-}
-
-/**
- * Sets the double click enabled flag.
- * <p>
- * The double click flag enables or disables the
- * default action of the text widget when the user
- * double clicks.
- * </p><p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param doubleClick the new double click flag
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDoubleClickEnabled (boolean doubleClick) {
- checkWidget ();
- this.doubleClick = doubleClick;
-}
-
-/**
- * Sets the echo character.
- * <p>
- * The echo character is the character that is
- * displayed when the user enters text or the
- * text is changed by the programmer. Setting
- * the echo character to '\0' clears the echo
- * character and redraws the original text.
- * If for any reason the echo character is invalid,
- * or if the platform does not allow modification
- * of the echo character, the default echo character
- * for the platform is used.
- * </p>
- *
- * @param echo the new echo character
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEchoChar (char echo) {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- OS.gtk_entry_set_visibility (handle, echo == '\0');
- OS.gtk_entry_set_invisible_char (handle, echo);
- }
-}
-
-/**
- * Sets the editable state.
- *
- * @param editable the new editable state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEditable (boolean editable) {
- checkWidget ();
- style &= ~SWT.READ_ONLY;
- if (!editable) style |= SWT.READ_ONLY;
- if ((style & SWT.SINGLE) != 0) {
- OS.gtk_editable_set_editable (handle, editable);
- } else {
- OS.gtk_text_view_set_editable (handle, editable);
- }
-}
-
-void setFontDescription (int /*long*/ font) {
- super.setFontDescription (font);
- setTabStops (tabs);
-}
-
-/**
- * Sets the widget message. The message text is displayed
- * as a hint for the user, indicating the purpose of the field.
- * <p>
- * Typically this is used in conjunction with <code>SWT.SEARCH</code>.
- * </p>
- *
- * @param message the new message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the message is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public void setMessage (String message) {
- checkWidget ();
- if (message == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.message = message;
- redraw (false);
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public void setOrientation (int orientation) {
- checkWidget();
-}
-
-/**
- * Sets the selection.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * regular array indexing rules.
- * </p>
- *
- * @param start new caret position
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int start) {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- OS.gtk_editable_set_position (handle, start);
- } else {
- byte [] position = new byte [ITER_SIZEOF];
- OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, position, start);
- OS.gtk_text_buffer_place_cursor (bufferHandle, position);
- int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle);
- OS.gtk_text_view_scroll_mark_onscreen (handle, mark);
- }
-}
-
-/**
- * Sets the selection to the range specified
- * by the given start and end indices.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * usual array indexing rules.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int start, int end) {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- OS.gtk_editable_set_position (handle, start);
- OS.gtk_editable_select_region (handle, start, end);
- } else {
- byte [] startIter = new byte [ITER_SIZEOF];
- byte [] endIter = new byte [ITER_SIZEOF];
- OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, startIter, start);
- OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, endIter, end);
- int /*long*/ insertMark = OS.gtk_text_buffer_get_insert (bufferHandle);
- int /*long*/ selectionMark = OS.gtk_text_buffer_get_selection_bound (bufferHandle);
- OS.gtk_text_buffer_move_mark (bufferHandle, selectionMark, startIter);
- OS.gtk_text_buffer_move_mark (bufferHandle, insertMark, endIter);
- }
-}
-
-/**
- * Sets the selection to the range specified
- * by the given point, where the x coordinate
- * represents the start index and the y coordinate
- * represents the end index.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * usual array indexing rules.
- * </p>
- *
- * @param selection the point
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (Point selection) {
- checkWidget ();
- if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (selection.x, selection.y);
-}
-
-/**
- * Sets the number of tabs.
- * <p>
- * Tab stop spacing is specified in terms of the
- * space (' ') character. The width of a single
- * tab stop is the pixel width of the spaces.
- * </p>
- *
- * @param tabs the number of tabs
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTabs (int tabs) {
- checkWidget ();
- if (tabs < 0) return;
- setTabStops (this.tabs = tabs);
-}
-
-void setTabStops (int tabs) {
- if ((style & SWT.SINGLE) != 0) return;
- int tabWidth = getTabWidth (tabs);
- int /*long*/ tabArray = OS.pango_tab_array_new (1, false);
- OS.pango_tab_array_set_tab (tabArray, 0, OS.PANGO_TAB_LEFT, tabWidth);
- OS.gtk_text_view_set_tabs (handle, tabArray);
- OS.pango_tab_array_free (tabArray);
-}
-
-/**
- * Sets the contents of the receiver to the given string. If the receiver has style
- * SINGLE and the argument contains multiple lines of text, the result of this
- * operation is undefined and may vary from platform to platform.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- /*
- * Feature in gtk. When text is set in gtk, separate events are fired for the deletion and
- * insertion of the text. This is not wrong, but is inconsistent with other platforms. The
- * fix is to block the firing of these events and fire them ourselves in a consistent manner.
- */
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- string = verifyText (string, 0, getCharCount ());
- if (string == null) return;
- }
- if ((style & SWT.SINGLE) != 0) {
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT);
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT);
- OS.gtk_entry_set_text (handle, buffer);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT);
- } else {
- byte [] buffer = Converter.wcsToMbcs (null, string, false);
- byte [] position = new byte [ITER_SIZEOF];
- OS.g_signal_handlers_block_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_signal_handlers_block_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_RANGE);
- OS.g_signal_handlers_block_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEXT_BUFFER_INSERT_TEXT);
- OS.gtk_text_buffer_set_text (bufferHandle, buffer, buffer.length);
- OS.g_signal_handlers_unblock_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.g_signal_handlers_unblock_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_RANGE);
- OS.g_signal_handlers_unblock_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEXT_BUFFER_INSERT_TEXT);
- OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, position, 0);
- OS.gtk_text_buffer_place_cursor (bufferHandle, position);
- int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle);
- OS.gtk_text_view_scroll_mark_onscreen (handle, mark);
- }
- sendEvent (SWT.Modify);
-}
-
-/**
- * Sets the maximum number of characters that the receiver
- * is capable of holding to be the argument.
- * <p>
- * Instead of trying to set the text limit to zero, consider
- * creating a read-only text widget.
- * </p><p>
- * To reset this value to the default, use <code>setTextLimit(Text.LIMIT)</code>.
- * Specifying a limit value larger than <code>Text.LIMIT</code> sets the
- * receiver's limit to <code>Text.LIMIT</code>.
- * </p>
- *
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public void setTextLimit (int limit) {
- checkWidget ();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- if ((style & SWT.SINGLE) != 0) OS.gtk_entry_set_max_length (handle, limit);
-}
-
-/**
- * Sets the zero-relative index of the line which is currently
- * at the top of the receiver. This index can change when lines
- * are scrolled or new lines are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- byte [] position = new byte [ITER_SIZEOF];
- OS.gtk_text_buffer_get_iter_at_line (bufferHandle, position, index);
- OS.gtk_text_view_scroll_to_iter (handle, position, 0, true, 0, 0);
-}
-
-/**
- * Shows the selection.
- * <p>
- * If the selection is already showing
- * in the receiver, this method simply returns. Otherwise,
- * lines are scrolled until the selection is visible.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void showSelection () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- int /*long*/ mark = OS.gtk_text_buffer_get_selection_bound (bufferHandle);
- OS.gtk_text_view_scroll_mark_onscreen (handle, mark);
- mark = OS.gtk_text_buffer_get_insert (bufferHandle);
- OS.gtk_text_view_scroll_mark_onscreen (handle, mark);
-}
-
-boolean translateTraversal (GdkEventKey keyEvent) {
- int key = keyEvent.keyval;
- switch (key) {
- case OS.GDK_KP_Enter:
- case OS.GDK_Return: {
- int /*long*/ imContext = imContext ();
- if (imContext != 0) {
- int /*long*/ [] preeditString = new int /*long*/ [1];
- OS.gtk_im_context_get_preedit_string (imContext, preeditString, null, null);
- if (preeditString [0] != 0) {
- int length = OS.strlen (preeditString [0]);
- OS.g_free (preeditString [0]);
- if (length != 0) return false;
- }
- }
- }
- }
- return super.translateTraversal (keyEvent);
-}
-
-int traversalCode (int key, GdkEventKey event) {
- int bits = super.traversalCode (key, event);
- if ((style & SWT.READ_ONLY) != 0) return bits;
- if ((style & SWT.MULTI) != 0) {
- bits &= ~SWT.TRAVERSE_RETURN;
- if (key == OS.GDK_Tab && event != null) {
- boolean next = (event.state & OS.GDK_SHIFT_MASK) == 0;
- if (next && (event.state & OS.GDK_CONTROL_MASK) == 0) {
- bits &= ~(SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS);
- }
- }
- }
- return bits;
-}
-
-String verifyText (String string, int start, int end) {
- if (string.length () == 0 && start == end) return null;
- Event event = new Event ();
- event.text = string;
- event.start = start;
- event.end = end;
- int /*long*/ eventPtr = OS.gtk_get_current_event ();
- if (eventPtr != 0) {
- GdkEventKey gdkEvent = new GdkEventKey ();
- OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof);
- switch (gdkEvent.type) {
- case OS.GDK_KEY_PRESS:
- setKeyState (event, gdkEvent);
- break;
- }
- OS.gdk_event_free (eventPtr);
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the verify
- * event. If this happens, answer null to cancel
- * the operation.
- */
- sendEvent (SWT.Verify, event);
- if (!event.doit || isDisposed ()) return null;
- return event.text;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java
deleted file mode 100644
index 2d7306e76c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java
+++ /dev/null
@@ -1,551 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class support the layout of selectable
- * tool bar items.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>ToolItem</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add <code>Control</code> children to it,
- * or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>FLAT, WRAP, RIGHT, HORIZONTAL, VERTICAL, SHADOW_OUT</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#toolbar">ToolBar, ToolItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolBar extends Composite {
- ToolItem lastFocus;
- ToolItem [] tabItemList;
- ImageList imageList;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#FLAT
- * @see SWT#WRAP
- * @see SWT#RIGHT
- * @see SWT#HORIZONTAL
- * @see SWT#SHADOW_OUT
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass()
- * @see Widget#getStyle()
- */
-public ToolBar (Composite parent, int style) {
- super (parent, checkStyle (style));
- /*
- * Ensure that either of HORIZONTAL or VERTICAL is set.
- * NOTE: HORIZONTAL and VERTICAL have the same values
- * as H_SCROLL and V_SCROLL so it is necessary to first
- * clear these bits to avoid scroll bars and then reset
- * the bits using the original style supplied by the
- * programmer.
- */
- if ((style & SWT.VERTICAL) != 0) {
- this.style |= SWT.VERTICAL;
- } else {
- this.style |= SWT.HORIZONTAL;
- }
- int orientation = (style & SWT.VERTICAL) != 0 ? OS.GTK_ORIENTATION_VERTICAL : OS.GTK_ORIENTATION_HORIZONTAL;
- OS.gtk_toolbar_set_orientation (handle, orientation);
-}
-
-static int checkStyle (int style) {
- /*
- * Feature in GTK. It is not possible to create
- * a toolbar that wraps. Therefore, no matter what
- * style bits are specified, clear the WRAP bits so
- * that the style matches the behavior.
- */
- if ((style & SWT.WRAP) != 0) style &= ~SWT.WRAP;
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createHandle (int index) {
- state |= HANDLE | THEME_BACKGROUND;
- fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (fixedHandle, true);
- handle = OS.gtk_toolbar_new ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (fixedHandle, handle);
- if ((style & SWT.FLAT) != 0) {
- byte [] swt_toolbar_flat = Converter.wcsToMbcs (null, "swt-toolbar-flat", true);
- OS.gtk_widget_set_name (handle, swt_toolbar_flat);
- }
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- return computeNativeSize (handle, wHint, hHint, changed);
-}
-
-Widget computeTabGroup () {
- ToolItem [] items = _getItems ();
- if (tabItemList == null) {
- int i = 0;
- while (i < items.length && items [i].control == null) i++;
- if (i == items.length) return super.computeTabGroup ();
- }
- int index = 0;
- while (index < items.length) {
- if (items[index].hasFocus ()) break;
- index++;
- }
- while (index >= 0) {
- ToolItem item = items [index];
- if (item.isTabGroup ()) return item;
- index--;
- }
- return super.computeTabGroup ();
-}
-
-Widget [] computeTabList () {
- ToolItem [] items = _getItems ();
- if (tabItemList == null) {
- int i = 0;
- while (i < items.length && items [i].control == null) i++;
- if (i == items.length) return super.computeTabList ();
- }
- Widget result [] = {};
- if (!isTabGroup () || !isEnabled () || !isVisible ()) return result;
- ToolItem [] list = tabList != null ? _getTabItemList () : items;
- for (int i=0; i<list.length; i++) {
- ToolItem child = list [i];
- Widget [] childList = child.computeTabList ();
- if (childList.length != 0) {
- Widget [] newResult = new Widget [result.length + childList.length];
- System.arraycopy (result, 0, newResult, 0, result.length);
- System.arraycopy (childList, 0, newResult, result.length, childList.length);
- result = newResult;
- }
- }
- if (result.length == 0) result = new Widget [] {this};
- return result;
-}
-
-int /*long*/ eventHandle () {
- return fixedHandle;
-}
-
-int /*long*/ enterExitHandle() {
- return handle;
-}
-
-void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) {
- super.fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
- ToolItem [] items = getItems ();
- if (toolTipText == null) {
- for (int i = 0; i < items.length; i++) {
- ToolItem item = items [i];
- if (item.toolTipText != null) {
- item.setToolTipText(oldShell, null);
- item.setToolTipText(newShell, item.toolTipText);
- }
- }
- }
-}
-
-boolean forceFocus (int /*long*/ focusHandle) {
- if (lastFocus != null && lastFocus.setFocus ()) return true;
- ToolItem [] items = getItems ();
- for (int i = 0; i < items.length; i++) {
- ToolItem item = items [i];
- if (item.setFocus ()) return true;
- }
- return super.forceFocus (focusHandle);
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem getItem (int index) {
- checkWidget();
- if (!(0 <= index && index < getItemCount())) error (SWT.ERROR_INVALID_RANGE);
- return getItems()[index];
-}
-
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- *
- * @param point the point used to locate the item
- * @return the item at the given point
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem getItem (Point point) {
- checkWidget();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- ToolItem[] items = getItems();
- for (int i=0; i<items.length; i++) {
- if (items[i].getBounds().contains(point)) return items[i];
- }
- return null;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- int /*long*/ list = OS.gtk_container_get_children (handle);
- if (list == 0) return 0;
- int itemCount = OS.g_list_length (list);
- OS.g_list_free (list);
- return itemCount;
-}
-
-/**
- * Returns an array of <code>ToolItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem [] getItems () {
- checkWidget();
- return _getItems ();
-}
-
-ToolItem [] _getItems () {
- int /*long*/ list = OS.gtk_container_get_children (handle);
- if (list == 0) return new ToolItem [0];
- int count = OS.g_list_length (list);
- ToolItem [] items = new ToolItem [count];
- int index = 0;
- for (int i=0; i<count; i++) {
- int /*long*/ data = OS.g_list_nth_data (list, i);
- Widget widget = display.getWidget (data);
- if (widget != null) items [index++] = (ToolItem) widget;
- }
- OS.g_list_free (list);
- if (index != items.length) {
- ToolItem [] newItems = new ToolItem [index];
- System.arraycopy (items, 0, newItems, 0, index);
- items = newItems;
- }
- return items;
-}
-
-/**
- * Returns the number of rows in the receiver. When
- * the receiver has the <code>WRAP</code> style, the
- * number of rows can be greater than one. Otherwise,
- * the number of rows is always one.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getRowCount () {
- checkWidget();
- /* On GTK, toolbars cannot wrap */
- return 1;
-}
-
-ToolItem [] _getTabItemList () {
- if (tabItemList == null) return tabItemList;
- int count = 0;
- for (int i=0; i<tabItemList.length; i++) {
- if (!tabItemList [i].isDisposed ()) count++;
- }
- if (count == tabItemList.length) return tabItemList;
- ToolItem [] newList = new ToolItem [count];
- int index = 0;
- for (int i=0; i<tabItemList.length; i++) {
- if (!tabItemList [i].isDisposed ()) {
- newList [index++] = tabItemList [i];
- }
- }
- tabItemList = newList;
- return tabItemList;
-}
-
-int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ eventPtr) {
- if (!hasFocus ()) return 0;
- int /*long*/ result = super.gtk_key_press_event (widget, eventPtr);
- if (result != 0) return result;
- ToolItem [] items = getItems ();
- int length = items.length;
- int index = 0;
- while (index < length) {
- if (items [index].hasFocus ()) break;
- index++;
- }
- GdkEventKey gdkEvent = new GdkEventKey ();
- OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof);
- boolean next = false;
- switch (gdkEvent.keyval) {
- case OS.GDK_Up:
- case OS.GDK_Left: next = false; break;
- case OS.GDK_Down: {
- if (0 <= index && index < length) {
- ToolItem item = items [index];
- if ((item.style & SWT.DROP_DOWN) != 0) {
- Event event = new Event ();
- event.detail = SWT.ARROW;
- int /*long*/ topHandle = item.topHandle ();
- event.x = OS.GTK_WIDGET_X (topHandle);
- event.y = OS.GTK_WIDGET_Y (topHandle) + OS.GTK_WIDGET_HEIGHT (topHandle);
- if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth() - OS.GTK_WIDGET_WIDTH(topHandle) - event.x;
- item.postEvent (SWT.Selection, event);
- return result;
- }
- }
- //FALL THROUGH
- }
- case OS.GDK_Right: next = true; break;
- default: return result;
- }
- if ((style & SWT.MIRRORED) != 0) next= !next;
- int start = index, offset = next ? 1 : -1;
- while ((index = (index + offset + length) % length) != start) {
- ToolItem item = items [index];
- if (item.setFocus ()) return result;
- }
- return result;
-}
-
-boolean hasFocus () {
- ToolItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item.hasFocus ()) return true;
- }
- return super.hasFocus();
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the tool item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the tool item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (ToolItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- ToolItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- if (item == items[i]) return i;
- }
- return -1;
-}
-
-boolean mnemonicHit (char key) {
- ToolItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- int /*long*/ labelHandle = items [i].labelHandle;
- if (labelHandle != 0 && mnemonicHit (labelHandle, key)) return true;
- }
- return false;
-}
-
-boolean mnemonicMatch (char key) {
- ToolItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- int /*long*/ labelHandle = items [i].labelHandle;
- if (labelHandle != 0 && mnemonicMatch (labelHandle, key)) return true;
- }
- return false;
-}
-
-void relayout () {
- ToolItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null) item.resizeControl ();
- }
-}
-
-void releaseChildren (boolean destroy) {
- ToolItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (imageList != null) imageList.dispose ();
- imageList = null;
-}
-
-void removeControl (Control control) {
- super.removeControl (control);
- ToolItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item.control == control) item.setControl (null);
- }
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- int result = super.setBounds (x, y, width, height, move, resize);
- if ((result & RESIZED) != 0) relayout ();
- return result;
-}
-
-void setFontDescription (int /*long*/ font) {
- super.setFontDescription (font);
- ToolItem [] items = getItems ();
- for (int i = 0; i < items.length; i++) {
- items[i].setFontDescription (font);
- }
- relayout ();
-}
-
-void setForegroundColor (GdkColor color) {
- super.setForegroundColor (color);
- ToolItem [] items = getItems ();
- for (int i = 0; i < items.length; i++) {
- items[i].setForegroundColor (color);
- }
-}
-
-/*public*/ void setTabItemList (ToolItem [] tabList) {
- checkWidget ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- ToolItem item = tabList [i];
- if (item == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (item.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
- ToolItem [] newList = new ToolItem [tabList.length];
- System.arraycopy (tabList, 0, newList, 0, tabList.length);
- tabList = newList;
- }
- this.tabItemList = tabList;
-}
-
-public void setToolTipText (String string) {
- checkWidget();
- super.setToolTipText (string);
- Shell shell = _getShell ();
- ToolItem [] items = getItems ();
- for (int i = 0; i < items.length; i++) {
- String newString = string != null ? null : items [i].toolTipText;
- shell.setToolTipText (items [i].handle, newString);
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java
deleted file mode 100644
index 6013cfc10a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java
+++ /dev/null
@@ -1,1091 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a button in a tool bar.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>PUSH, CHECK, RADIO, SEPARATOR, DROP_DOWN</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles CHECK, PUSH, RADIO, SEPARATOR and DROP_DOWN
- * may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#toolbar">ToolBar, ToolItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolItem extends Item {
- int /*long*/ boxHandle, arrowHandle, arrowBoxHandle, separatorHandle, labelHandle, imageHandle;
- ToolBar parent;
- Control control;
- Image hotImage, disabledImage;
- String toolTipText;
- boolean drawHotImage;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>ToolBar</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#PUSH
- * @see SWT#CHECK
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ToolItem (ToolBar parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>ToolBar</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#PUSH
- * @see SWT#CHECK
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ToolItem (ToolBar parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- int count = parent.getItemCount ();
- if (!(0 <= index && index <= count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- createWidget (index);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called when the mouse is over the arrow portion of a drop-down tool,
- * the event object detail field contains the value <code>SWT.ARROW</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user,
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.DROP_DOWN, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- if ((style & SWT.SEPARATOR) == 0) {
- boxHandle = (parent.style & SWT.RIGHT) != 0 ? OS.gtk_hbox_new (false, 0) : OS.gtk_vbox_new (false, 0);
- if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES);
- labelHandle = OS.gtk_label_new_with_mnemonic (null);
- if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES);
- imageHandle = OS.gtk_image_new ();
- if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (boxHandle, imageHandle);
- OS.gtk_container_add (boxHandle, labelHandle);
- if ((parent.style & SWT.VERTICAL) != 0) {
- // Align text and images to the left
- OS.gtk_box_set_child_packing (boxHandle, imageHandle, false, false, 0, OS.GTK_PACK_START);
- OS.gtk_box_set_child_packing (boxHandle, labelHandle, false, false, 2, OS.GTK_PACK_START);
- }
- }
- int bits = SWT.SEPARATOR | SWT.RADIO | SWT.CHECK | SWT.PUSH | SWT.DROP_DOWN;
- switch (style & bits) {
- case SWT.SEPARATOR:
- handle = OS.gtk_hbox_new (false, 0);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- boolean isVertical = (parent.style & SWT.VERTICAL) != 0;
- separatorHandle = isVertical ? OS.gtk_hseparator_new() : OS.gtk_vseparator_new();
- if (separatorHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_widget_set_size_request (separatorHandle, isVertical ? 15 : 6, isVertical ? 6 : 15);
- OS.gtk_widget_set_size_request (handle, isVertical ? 15 : 6, isVertical ? 6 : 15);
- OS.gtk_container_add (handle, separatorHandle);
- break;
- case SWT.DROP_DOWN:
- handle = OS.gtk_button_new ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- arrowBoxHandle = OS.gtk_hbox_new (false, 0);
- if (arrowBoxHandle == 0) error(SWT.ERROR_NO_HANDLES);
- arrowHandle = OS.gtk_arrow_new (OS.GTK_ARROW_DOWN, OS.GTK_SHADOW_NONE);
- if (arrowHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_widget_set_size_request (arrowHandle, 8, 6);
- OS.gtk_container_add (handle, arrowBoxHandle);
- OS.gtk_container_add (arrowBoxHandle, boxHandle);
- OS.gtk_container_add (arrowBoxHandle, arrowHandle);
- break;
- case SWT.RADIO:
- /*
- * This code is intentionally commented. Because GTK
- * enforces radio behavior in a button group a radio group
- * is not created for each set of contiguous buttons, each
- * radio button will not draw unpressed. The fix is to use
- * toggle buttons instead.
- */
-// handle = OS.gtk_radio_button_new (0);
-// if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-// OS.gtk_toggle_button_set_mode (handle, false);
-// OS.gtk_container_add (handle, boxHandle);
-// break;
- case SWT.CHECK:
- handle = OS.gtk_toggle_button_new ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_toggle_button_set_mode (handle, false);
- OS.gtk_container_add (handle, boxHandle);
- break;
- case SWT.PUSH:
- default:
- handle = OS.gtk_button_new ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (handle, boxHandle);
- break;
- }
- if ((style & SWT.SEPARATOR) == 0) {
- int [] relief = new int [1];
- OS.gtk_widget_style_get (parent.handle, OS.button_relief, relief, 0);
- OS.gtk_button_set_relief (handle, relief [0]);
- }
- OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS);
-// This code is intentionally commented.
-// int /*long*/ fontHandle = parent.fontHandle ();
-// GdkColor color = new GdkColor ();
-// int /*long*/ style = OS.gtk_widget_get_style (fontHandle);
-// OS.gtk_style_get_fg (style, OS.GTK_STATE_NORMAL, color);
-// int /*long*/ font = OS.gtk_style_get_font_desc (style);
-// setForegroundColor (color);
-// setFontDescription (font);
- if ((parent.state & FOREGROUND) != 0) {
- setForegroundColor (parent.getForegroundColor());
- }
- if ((parent.state & FONT) != 0) {
- setFontDescription (parent.getFontDescription());
- }
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- showWidget (index);
- parent.relayout ();
-}
-
-Widget [] computeTabList () {
- if (isTabGroup ()) {
- if (getEnabled ()) {
- if ((style & SWT.SEPARATOR) != 0) {
- if (control != null) return control.computeTabList();
- } else {
- return new Widget [] {this};
- }
- }
- }
- return new Widget [0];
-}
-
-void deregister() {
- super.deregister ();
- if (labelHandle != 0) display.removeWidget (labelHandle);
-}
-
-public void dispose () {
- if (isDisposed ()) return;
- ToolBar parent = this.parent;
- super.dispose ();
- parent.relayout ();
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- parent.forceResize ();
- int /*long*/ topHandle = topHandle ();
- int x, y, width, height;
- /*
- * Bug in GTK. Toolbar items are only allocated their minimum size
- * in versions before 2.4.0. The fix is to use the total size
- * available minus any borders.
- */
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0) && control != null && !control.isDisposed ()) {
- int border = OS.gtk_container_get_border_width (parent.handle);
- byte [] shadowType = Converter.wcsToMbcs (null, "shadow_type", true);
- int [] shadow = new int [1];
- OS.gtk_widget_style_get (parent.handle, shadowType, shadow, 0);
- if (shadow [0] != OS.GTK_SHADOW_NONE) {
- border += OS.gtk_style_get_xthickness (OS.gtk_widget_get_style (parent.handle));
- }
- if ((parent.style & SWT.VERTICAL) != 0) {
- x = border;
- y = OS.GTK_WIDGET_Y (topHandle) + border;
- width = OS.GTK_WIDGET_WIDTH (parent.handle) - border*2;
- height = OS.GTK_WIDGET_HEIGHT (topHandle);
- } else {
- x = OS.GTK_WIDGET_X (topHandle) + border;
- y = border;
- width = OS.GTK_WIDGET_WIDTH (topHandle);
- height = OS.GTK_WIDGET_HEIGHT (parent.handle) - border*2;
- }
- } else {
- x = OS.GTK_WIDGET_X (topHandle);
- y = OS.GTK_WIDGET_Y (topHandle);
- width = OS.GTK_WIDGET_WIDTH (topHandle);
- height = OS.GTK_WIDGET_HEIGHT (topHandle);
- }
- if ((parent.style & SWT.MIRRORED) != 0) x = parent.getClientWidth () - width - x;
- if ((style & SWT.SEPARATOR) != 0 && control != null) height = Math.max (height, 23);
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the control that is used to fill the bounds of
- * the item when the item is a <code>SEPARATOR</code>.
- *
- * @return the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget();
- return control;
-}
-
-/**
- * Returns the receiver's disabled image if it has one, or null
- * if it does not.
- * <p>
- * The disabled image is displayed when the receiver is disabled.
- * </p>
- *
- * @return the receiver's disabled image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getDisabledImage () {
- checkWidget();
- return disabledImage;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- int /*long*/ topHandle = topHandle ();
- return OS.GTK_WIDGET_SENSITIVE (topHandle);
-}
-
-/**
- * Returns the receiver's hot image if it has one, or null
- * if it does not.
- * <p>
- * The hot image is displayed when the mouse enters the receiver.
- * </p>
- *
- * @return the receiver's hot image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getHotImage () {
- checkWidget();
- return hotImage;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>ToolBar</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolBar getParent () {
- checkWidget();
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent;
-}
-
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked (which some platforms draw as a
- * pushed in button). If the receiver is of any other type, this method
- * returns false.
- * </p>
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
- return OS.gtk_toggle_button_get_active (handle);
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget();
- parent.forceResize ();
- int /*long*/ topHandle = topHandle ();
- return OS.GTK_WIDGET_WIDTH (topHandle);
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
- double x = gdkEvent.x;
- gdkEvent.x += OS.GTK_WIDGET_X (handle);
- double y = gdkEvent.y;
- gdkEvent.y += OS.GTK_WIDGET_Y (handle);
- OS.memmove (event, gdkEvent, GdkEventButton.sizeof);
- int /*long*/ result = parent.gtk_button_press_event (widget, event);
- gdkEvent.x = x;
- gdkEvent.y = y;
- OS.memmove (event, gdkEvent, GdkEventButton.sizeof);
- return result;
-}
-
-int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ event) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
- double x = gdkEvent.x;
- gdkEvent.x += OS.GTK_WIDGET_X (handle);
- double y = gdkEvent.y;
- gdkEvent.y += OS.GTK_WIDGET_Y (handle);
- OS.memmove (event, gdkEvent, GdkEventButton.sizeof);
- int /*long*/ result = parent.gtk_button_release_event (widget, event);
- gdkEvent.x = x;
- gdkEvent.y = y;
- OS.memmove(event, gdkEvent, GdkEventButton.sizeof);
- return result;
-}
-
-int /*long*/ gtk_clicked (int /*long*/ widget) {
- Event event = new Event ();
- if ((style & SWT.DROP_DOWN) != 0) {
- int /*long*/ eventPtr = OS.gtk_get_current_event ();
- if (eventPtr != 0) {
- GdkEvent gdkEvent = new GdkEvent ();
- OS.memmove (gdkEvent, eventPtr, GdkEvent.sizeof);
- switch (gdkEvent.type) {
- case OS.GDK_BUTTON_PRESS:
- case OS.GDK_2BUTTON_PRESS:
- case OS.GDK_BUTTON_RELEASE: {
- double [] x_win = new double [1];
- double [] y_win = new double [1];
- OS.gdk_event_get_coords (eventPtr, x_win, y_win);
- int x = OS.GTK_WIDGET_X (arrowHandle) - OS.GTK_WIDGET_X (handle);
- int width = OS.GTK_WIDGET_WIDTH (arrowHandle);
- if ((((parent.style & SWT.RIGHT_TO_LEFT) == 0) && x <= (int)x_win [0])
- || (((parent.style & SWT.RIGHT_TO_LEFT) != 0) && (int)x_win [0] <= x + width)) {
- event.detail = SWT.ARROW;
- int /*long*/ topHandle = topHandle ();
- event.x = OS.GTK_WIDGET_X (topHandle);
- if ((parent.style & SWT.MIRRORED) != 0) event.x = parent.getClientWidth () - OS.GTK_WIDGET_WIDTH (topHandle) - event.x;
- event.y = OS.GTK_WIDGET_Y (topHandle) + OS.GTK_WIDGET_HEIGHT (topHandle);
- }
- break;
- }
- }
- OS.gdk_event_free (eventPtr);
- }
- }
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) {
- selectRadio ();
- }
- }
- postEvent (SWT.Selection, event);
- return 0;
-}
-
-int /*long*/ gtk_enter_notify_event (int /*long*/ widget, int /*long*/ event) {
- parent.gtk_enter_notify_event (widget, event);
- drawHotImage = (parent.style & SWT.FLAT) != 0 && hotImage != null;
- if (drawHotImage && imageHandle != 0) {
- ImageList imageList = parent.imageList;
- if (imageList != null) {
- int index = imageList.indexOf (hotImage);
- if (index != -1) {
- int /*long*/ pixbuf = imageList.getPixbuf (index);
- OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf);
- }
- }
- }
- return 0;
-}
-
-int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) {
- GdkEvent event = new GdkEvent ();
- OS.memmove (event, gdkEvent, GdkEvent.sizeof);
- switch (event.type) {
- case OS.GDK_BUTTON_PRESS: {
- GdkEventButton gdkEventButton = new GdkEventButton ();
- OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof);
- if (gdkEventButton.button == 3) {
- parent.showMenu ((int) gdkEventButton.x_root, (int) gdkEventButton.y_root);
- }
- break;
- }
- }
- return 0;
-}
-
-int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) {
- OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS);
- parent.lastFocus = this;
- return 0;
-}
-
-int /*long*/ gtk_leave_notify_event (int /*long*/ widget, int /*long*/ event) {
- parent.gtk_leave_notify_event (widget, event);
- if (drawHotImage) {
- drawHotImage = false;
- if (imageHandle != 0 && image != null) {
- ImageList imageList = parent.imageList;
- if (imageList != null) {
- int index = imageList.indexOf (image);
- if (index != -1) {
- int /*long*/ pixbuf = imageList.getPixbuf (index);
- OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf);
- }
- }
- }
- }
- return 0;
-}
-
-int /*long*/ gtk_map (int /*long*/ widget) {
- parent.fixZOrder ();
- return 0;
-}
-
-int /*long*/ gtk_mnemonic_activate (int /*long*/ widget, int /*long*/ arg1) {
- return parent.gtk_mnemonic_activate (widget, arg1);
-}
-
-boolean hasFocus () {
- return OS.GTK_WIDGET_HAS_FOCUS (handle);
-}
-
-void hookEvents () {
- super.hookEvents ();
- if ((style & SWT.SEPARATOR) != 0) return;
- OS.g_signal_connect_closure (handle, OS.clicked, display.closures [CLICKED], false);
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false);
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [LEAVE_NOTIFY_EVENT], 0, display.closures [LEAVE_NOTIFY_EVENT], false);
- if (labelHandle != 0) OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false);
-
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [FOCUS_OUT_EVENT], 0, display.closures [FOCUS_OUT_EVENT], false);
-
- /*
- * Feature in GTK. Usually, GTK widgets propagate all events to their
- * parent when they are done their own processing. However, in contrast
- * to other widgets, the buttons that make up the tool items, do not propagate
- * the mouse up/down events. It is interesting to note that they DO propagate
- * mouse motion events. The fix is to explicitly forward mouse up/down events
- * to the parent.
- */
- int mask =
- OS.GDK_EXPOSURE_MASK | OS.GDK_POINTER_MOTION_MASK |
- OS.GDK_BUTTON_PRESS_MASK | OS.GDK_BUTTON_RELEASE_MASK |
- OS.GDK_ENTER_NOTIFY_MASK | OS.GDK_LEAVE_NOTIFY_MASK |
- OS.GDK_KEY_PRESS_MASK | OS.GDK_KEY_RELEASE_MASK |
- OS.GDK_FOCUS_CHANGE_MASK;
- OS.gtk_widget_add_events (handle, mask);
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false);
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT], false);
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [EVENT_AFTER], 0, display.closures[EVENT_AFTER], false);
-
- int /*long*/ topHandle = topHandle ();
- OS.g_signal_connect_closure_by_id (topHandle, display.signalIds [MAP], 0, display.closures [MAP], true);
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-
-boolean isTabGroup () {
- ToolItem [] tabList = parent._getTabItemList ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == this) return true;
- }
- }
- if ((style & SWT.SEPARATOR) != 0) return true;
- int index = parent.indexOf (this);
- if (index == 0) return true;
- ToolItem previous = parent.getItem (index - 1);
- return (previous.getStyle () & SWT.SEPARATOR) != 0;
-}
-
-void register () {
- super.register ();
- if (labelHandle != 0) display.addWidget (labelHandle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- boxHandle = arrowHandle = separatorHandle = labelHandle = imageHandle = 0;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (parent.lastFocus == this) parent.lastFocus = null;
- parent = null;
- control = null;
- hotImage = disabledImage = null;
- toolTipText = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-void resizeControl () {
- if (control != null && !control.isDisposed ()) {
- if (separatorHandle != 0) OS.gtk_widget_hide (separatorHandle);
- /*
- * Set the size and location of the control
- * separately to minimize flashing in the
- * case where the control does not resize
- * to the size that was requested. This
- * case can occur when the control is a
- * combo box.
- */
- Rectangle itemRect = getBounds ();
- control.setSize (itemRect.width, itemRect.height);
- OS.gtk_widget_set_size_request (handle, itemRect.width, itemRect.height);
- Rectangle rect = control.getBounds ();
- rect.x = itemRect.x + (itemRect.width - rect.width) / 2;
- rect.y = itemRect.y + (itemRect.height - rect.height) / 2;
- control.setLocation (rect.x, rect.y);
- } else {
- if (separatorHandle != 0) OS.gtk_widget_show (separatorHandle);
- }
-}
-
-void selectRadio () {
- int index = 0;
- ToolItem [] items = parent.getItems ();
- while (index < items.length && items [index] != this) index++;
- int i = index - 1;
- while (i >= 0 && items [i].setRadioSelection (false)) --i;
- int j = index + 1;
- while (j < items.length && items [j].setRadioSelection (false)) j++;
- setSelection (true);
-}
-
-/**
- * Sets the control that is used to fill the bounds of
- * the item when the item is a <code>SEPARATOR</code>.
- *
- * @param control the new control
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget ();
- if (control != null) {
- if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- if ((style & SWT.SEPARATOR) == 0) return;
- if (this.control == control) return;
- this.control = control;
- parent.relayout ();
-}
-
-/**
- * Sets the receiver's disabled image to the argument, which may be
- * null indicating that no disabled image should be displayed.
- * <p>
- * The disabled image is displayed when the receiver is disabled.
- * </p>
- *
- * @param image the disabled image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDisabledImage (Image image) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return;
- disabledImage = image;
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise.
- * <p>
- * A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- * </p>
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- int /*long*/ topHandle = topHandle ();
- OS.gtk_widget_set_sensitive (topHandle, enabled);
- if (enabled) {
- /*
- * Bug in GTK. GtkButton requires an enter notify before it
- * allows the button to be pressed, but events are dropped when
- * widgets are insensitive. The fix is to hide and show the
- * button if the pointer is within its bounds.
- */
- int [] x = new int [1], y = new int [1];
- OS.gdk_window_get_pointer (parent.paintWindow (), x, y, null);
- if (getBounds ().contains (x [0], y [0])) {
- OS.gtk_widget_hide (handle);
- OS.gtk_widget_show (handle);
- }
- }
-}
-
-boolean setFocus () {
- if ((style & SWT.SEPARATOR) != 0) return false;
- if (!OS.gtk_widget_get_child_visible (handle)) return false;
- OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS);
- OS.gtk_widget_grab_focus (handle);
- boolean result = OS.gtk_widget_is_focus (handle);
- if (!result) OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS);
- return result;
-}
-
-void setFontDescription (int /*long*/ font) {
- OS.gtk_widget_modify_font (handle, font);
- if (labelHandle != 0) OS.gtk_widget_modify_font (labelHandle, font);
- if (imageHandle != 0) OS.gtk_widget_modify_font (imageHandle, font);
-}
-
-void setForegroundColor (GdkColor color) {
- setForegroundColor (handle, color);
- if (labelHandle != 0) setForegroundColor (labelHandle, color);
- if (imageHandle != 0) setForegroundColor (imageHandle, color);
-}
-
-/**
- * Sets the receiver's hot image to the argument, which may be
- * null indicating that no hot image should be displayed.
- * <p>
- * The hot image is displayed when the mouse enters the receiver.
- * </p>
- *
- * @param image the hot image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHotImage (Image image) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return;
- hotImage = image;
- if (image != null) {
- ImageList imageList = parent.imageList;
- if (imageList == null) imageList = parent.imageList = new ImageList ();
- int imageIndex = imageList.indexOf (image);
- if (imageIndex == -1) {
- imageIndex = imageList.add (image);
- } else {
- imageList.put (imageIndex, image);
- }
- }
-}
-
-public void setImage (Image image) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return;
- super.setImage (image);
- if (imageHandle == 0) return;
- if (image != null) {
- ImageList imageList = parent.imageList;
- if (imageList == null) imageList = parent.imageList = new ImageList ();
- int imageIndex = imageList.indexOf (image);
- if (imageIndex == -1) {
- imageIndex = imageList.add (image);
- } else {
- imageList.put (imageIndex, image);
- }
- int /*long*/ pixbuf = imageList.getPixbuf (imageIndex);
- OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf);
- OS.gtk_widget_show (imageHandle);
- } else {
- OS.gtk_image_set_from_pixbuf (imageHandle, 0);
- OS.gtk_widget_hide (imageHandle);
- }
- parent.relayout ();
-}
-
-void setOrientation () {
- if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) {
- if (handle != 0) OS.gtk_widget_set_direction (handle, OS.GTK_TEXT_DIR_RTL);
- if (labelHandle != 0) OS.gtk_widget_set_direction (labelHandle, OS.GTK_TEXT_DIR_RTL);
- if (imageHandle != 0) OS.gtk_widget_set_direction (imageHandle, OS.GTK_TEXT_DIR_RTL);
- if (separatorHandle != 0) OS.gtk_widget_set_direction (separatorHandle, OS.GTK_TEXT_DIR_RTL);
- if (arrowHandle != 0) OS.gtk_widget_set_direction (arrowHandle, OS.GTK_TEXT_DIR_RTL);
- if (boxHandle != 0) OS.gtk_widget_set_direction (boxHandle, OS.GTK_TEXT_DIR_RTL);
- if (arrowBoxHandle != 0) OS.gtk_widget_set_direction (arrowBoxHandle, OS.GTK_TEXT_DIR_RTL);
- }
-}
-
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-
-/**
- * Sets the selection state of the receiver.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked (which some platforms draw as a
- * pushed in button).
- * </p>
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget ();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED);
- OS.gtk_toggle_button_set_active (handle, selected);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED);
-}
-
-boolean setTabItemFocus (boolean next) {
- return setFocus ();
-}
-
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- super.setText (string);
- if (labelHandle == 0) return;
- char [] chars = fixMnemonic (string);
- byte [] buffer = Converter.wcsToMbcs (null, chars, true);
- OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer);
- if (string.length () != 0) {
- OS.gtk_widget_show (labelHandle);
- } else {
- OS.gtk_widget_hide (labelHandle);
- }
- parent.relayout ();
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget();
- if (parent.toolTipText == null) {
- Shell shell = parent._getShell ();
- setToolTipText (shell, string);
- }
- toolTipText = string;
-}
-
-void setToolTipText (Shell shell, String newString) {
- shell.setToolTipText (handle, newString);
-}
-
-/**
- * Sets the width of the receiver, for <code>SEPARATOR</code> ToolItems.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int width) {
- checkWidget();
- if ((style & SWT.SEPARATOR) == 0) return;
- if (width < 0) return;
- boolean isVertical = (parent.style & SWT.VERTICAL) != 0;
- OS.gtk_widget_set_size_request (separatorHandle, width, isVertical ? 6 : 15);
- OS.gtk_widget_set_size_request (handle, width, isVertical ? 6 : 15);
- parent.relayout ();
-}
-
-void showWidget (int index) {
- if (handle != 0) OS.gtk_widget_show (handle);
- if (boxHandle != 0) OS.gtk_widget_show (boxHandle);
- if (separatorHandle != 0) OS.gtk_widget_show (separatorHandle);
- if (arrowBoxHandle != 0) OS.gtk_widget_show (arrowBoxHandle);
- if (arrowHandle != 0) OS.gtk_widget_show (arrowHandle);
- OS.gtk_toolbar_insert_widget (parent.handle, handle, null, null, index);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java
deleted file mode 100644
index a106744329..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java
+++ /dev/null
@@ -1,818 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent popup windows that are used
- * to inform or warn the user.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BALLOON, ICON_ERROR, ICON_INFORMATION, ICON_WARNING</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION,
- * and ICON_WARNING may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tooltips">Tool Tips snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.2
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolTip extends Widget {
- Shell parent;
- String text, message;
- TrayItem item;
- int x, y, timerId;
- int /*long*/ layoutText = 0, layoutMessage = 0;
- int [] borderPolygon;
- boolean spikeAbove, autohide;
-
- static final int BORDER = 5;
- static final int PADDING = 5;
- static final int INSET = 4;
- static final int TIP_HEIGHT = 20;
- static final int IMAGE_SIZE = 16;
- static final int DELAY = 8000;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BALLOON
- * @see SWT#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_WARNING
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ToolTip (Shell parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (0);
- parent.addToolTip (this);
-}
-
-static int checkStyle (int style) {
- int mask = SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING;
- if ((style & mask) == 0) return style;
- return checkBits (style, SWT.ICON_INFORMATION, SWT.ICON_WARNING, SWT.ICON_ERROR, 0, 0, 0);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the receiver is selected.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the receiver is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-void configure () {
- int /*long*/ screen = OS.gdk_screen_get_default ();
- OS.gtk_widget_realize (handle);
- int monitorNumber = OS.gdk_screen_get_monitor_at_window (screen, OS.GTK_WIDGET_WINDOW (handle));
- GdkRectangle dest = new GdkRectangle ();
- OS.gdk_screen_get_monitor_geometry (screen, monitorNumber, dest);
- Point point = getSize (dest.width / 4);
- int w = point.x;
- int h = point.y;
- point = getLocation ();
- int x = point.x;
- int y = point.y;
- OS.gtk_window_resize (handle, w, h + TIP_HEIGHT);
- int[] polyline;
- spikeAbove = dest.height >= y + h + TIP_HEIGHT;
- if (dest.width >= x + w) {
- if (dest.height >= y + h + TIP_HEIGHT) {
- int t = TIP_HEIGHT;
- polyline = new int[] {
- 0, 5+t, 1, 5+t, 1, 3+t, 3, 1+t, 5, 1+t, 5, t,
- 16, t, 16, 0, 35, t,
- w-5, t, w-5, 1+t, w-3, 1+t, w-1, 3+t, w-1, 5+t, w, 5+t,
- w, h-5+t, w-1, h-5+t, w-1, h-3+t, w-2, h-3+t, w-2, h-2+t, w-3, h-2+t, w-3, h-1+t, w-5, h-1+t, w-5, h+t,
- 5, h+t, 5, h-1+t, 3, h-1+t, 3, h-2+t, 2, h-2+t, 2, h-3+t, 1, h-3+t, 1, h-5+t, 0, h-5+t,
- 0, 5+t};
- borderPolygon = new int[] {
- 0, 5+t, 1, 4+t, 1, 3+t, 3, 1+t, 4, 1+t, 5, t,
- 16, t, 16, 1, 35, t,
- w-6, 0+t, w-5, 1+t, w-4, 1+t, w-2, 3+t, w-2, 4+t, w-1, 5+t,
- w-1, h-6+t, w-2, h-5+t, w-2, h-4+t, w-4, h-2+t, w-5, h-2+t, w-6, h-1+t,
- 5, h-1+t, 4, h-2+t, 3, h-2+t, 1, h-4+t, 1, h-5+t, 0, h-6+t,
- 0, 5+t};
- if ((parent.style & SWT.MIRRORED) != 0) {
- x -= w - 36;
- polyline[12] = w-36;
- polyline[14] = w-16;
- polyline[16] = w-15;
- borderPolygon[12] = w-35;
- borderPolygon[14] = borderPolygon[16] = w-16;
- }
- OS.gtk_window_move (handle, Math.max(0, x - 17), y);
- } else {
- polyline = new int[] {
- 0, 5, 1, 5, 1, 3, 3, 1, 5, 1, 5, 0,
- w-5, 0, w-5, 1, w-3, 1, w-1, 3, w-1, 5, w, 5,
- w, h-5, w-1, h-5, w-1, h-3, w-2, h-3, w-2, h-2, w-3, h-2, w-3, h-1, w-5, h-1, w-5, h,
- 35, h, 16, h+TIP_HEIGHT, 16, h,
- 5, h, 5, h-1, 3, h-1, 3, h-2, 2, h-2, 2, h-3, 1, h-3, 1, h-5, 0, h-5,
- 0, 5};
- borderPolygon = new int[] {
- 0, 5, 1, 4, 1, 3, 3, 1, 4, 1, 5, 0,
- w-6, 0, w-5, 1, w-4, 1, w-2, 3, w-2, 4, w-1, 5,
- w-1, h-6, w-2, h-5, w-2, h-4, w-4, h-2, w-5, h-2, w-6, h-1,
- 35, h-1, 17, h+TIP_HEIGHT-2, 17, h-1,
- 5, h-1, 4, h-2, 3, h-2, 1, h-4, 1, h-5, 0, h-6,
- 0, 5};
- if ((parent.style & SWT.MIRRORED) != 0) {
- x -= w - 36;
- polyline [42] = polyline [44] = w-16;
- polyline [46] = w-35;
- borderPolygon[36] = borderPolygon[38] = w-17;
- borderPolygon [40] = w-35;
- }
- OS.gtk_window_move (handle, Math.max(0, x - 17), y - h - TIP_HEIGHT);
- }
- } else {
- if (dest.height >= y + h + TIP_HEIGHT) {
- int t = TIP_HEIGHT;
- polyline = new int[] {
- 0, 5+t, 1, 5+t, 1, 3+t, 3, 1+t, 5, 1+t, 5, t,
- w-35, t, w-16, 0, w-16, t,
- w-5, t, w-5, 1+t, w-3, 1+t, w-1, 3+t, w-1, 5+t, w, 5+t,
- w, h-5+t, w-1, h-5+t, w-1, h-3+t, w-2, h-3+t, w-2, h-2+t, w-3, h-2+t, w-3, h-1+t, w-5, h-1+t, w-5, h+t,
- 5, h+t, 5, h-1+t, 3, h-1+t, 3, h-2+t, 2, h-2+t, 2, h-3+t, 1, h-3+t, 1, h-5+t, 0, h-5+t,
- 0, 5+t};
- borderPolygon = new int[] {
- 0, 5+t, 1, 4+t, 1, 3+t, 3, 1+t, 4, 1+t, 5, t,
- w-35, t, w-17, 2, w-17, t,
- w-6, t, w-5, 1+t, w-4, 1+t, w-2, 3+t, w-2, 4+t, w-1, 5+t,
- w-1, h-6+t, w-2, h-5+t, w-2, h-4+t, w-4, h-2+t, w-5, h-2+t, w-6, h-1+t,
- 5, h-1+t, 4, h-2+t, 3, h-2+t, 1, h-4+t, 1, h-5+t, 0, h-6+t,
- 0, 5+t};
- if ((parent.style & SWT.MIRRORED) != 0) {
- x += w - 35;
- polyline [12] = polyline [14] = 16;
- polyline [16] = 35;
- borderPolygon[12] = borderPolygon[14] = 16;
- borderPolygon [16] = 35;
- }
- OS.gtk_window_move (handle, Math.min(dest.width - w, x - w + 17), y);
- } else {
- polyline = new int[] {
- 0, 5, 1, 5, 1, 3, 3, 1, 5, 1, 5, 0,
- w-5, 0, w-5, 1, w-3, 1, w-1, 3, w-1, 5, w, 5,
- w, h-5, w-1, h-5, w-1, h-3, w-2, h-3, w-2, h-2, w-3, h-2, w-3, h-1, w-5, h-1, w-5, h,
- w-16, h, w-16, h+TIP_HEIGHT, w-35, h,
- 5, h, 5, h-1, 3, h-1, 3, h-2, 2, h-2, 2, h-3, 1, h-3, 1, h-5, 0, h-5,
- 0, 5};
- borderPolygon = new int[] {
- 0, 5, 1, 4, 1, 3, 3, 1, 4, 1, 5, 0,
- w-6, 0, w-5, 1, w-4, 1, w-2, 3, w-2, 4, w-1, 5,
- w-1, h-6, w-2, h-5, w-2, h-4, w-4, h-2, w-5, h-2, w-6, h-1,
- w-17, h-1, w-17, h+TIP_HEIGHT-2, w-36, h-1,
- 5, h-1, 4, h-2, 3, h-2, 1, h-4, 1, h-5, 0, h-6,
- 0, 5};
- if ((parent.style & SWT.MIRRORED) != 0) {
- x += w - 35;
- polyline [42] = 35;
- polyline [44] = polyline [46] = 16;
- borderPolygon[36] = 35;
- borderPolygon[38] = borderPolygon [40] = 17;
- }
- OS.gtk_window_move (handle, Math.min(dest.width - w, x - w + 17), y - h - TIP_HEIGHT);
- }
- }
- int /*long*/ rgn = OS.gdk_region_polygon (polyline, polyline.length / 2, OS.GDK_EVEN_ODD_RULE);
- OS.gtk_widget_realize (handle);
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (handle);
- OS.gdk_window_shape_combine_region (window, rgn, 0, 0);
- OS.gdk_region_destroy (rgn);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- if ((style & SWT.BALLOON) != 0) {
- handle = OS.gtk_window_new (OS.GTK_WINDOW_POPUP);
- Color background = display.getSystemColor (SWT.COLOR_INFO_BACKGROUND);
- OS.gtk_widget_modify_bg (handle, OS.GTK_STATE_NORMAL, background.handle);
- OS.gtk_widget_set_app_paintable (handle, true);
- OS.gtk_window_set_type_hint (handle, OS.GDK_WINDOW_TYPE_HINT_TOOLTIP);
- } else {
- handle = OS.gtk_tooltips_new ();
- if (handle == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- /*
- * Bug in Solaris-GTK. Invoking gtk_tooltips_force_window()
- * can cause a crash in older versions of GTK. The fix is
- * to avoid this call if the GTK version is older than 2.2.x.
- */
- if (OS.GTK_VERSION >= OS.VERSION (2, 2, 1)) {
- OS.gtk_tooltips_force_window (handle);
- }
- OS.g_object_ref (handle);
- OS.gtk_object_sink (handle);
- }
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- text = "";
- message = "";
- x = y = -1;
- autohide = true;
-}
-
-void deregister () {
- super.deregister ();
- if ((style & SWT.BALLOON) == 0) {
- int /*long*/ tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (handle);
- if (tipWindow != 0) display.removeWidget (tipWindow);
- }
-}
-
-void destroyWidget () {
- int /*long*/ topHandle = topHandle ();
- if (parent != null) parent.removeTooTip (this);
- releaseHandle ();
- if (topHandle != 0 && (state & HANDLE) != 0) {
- if ((style & SWT.BALLOON) != 0) {
- OS.gtk_widget_destroy (topHandle);
- } else {
- OS.g_object_unref (topHandle);
- }
- }
-}
-
-/**
- * Returns <code>true</code> if the receiver is automatically
- * hidden by the platform, and <code>false</code> otherwise.
- *
- * @return the receiver's auto hide state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public boolean getAutoHide () {
- checkWidget ();
- return autohide;
-}
-
-Point getLocation () {
- int x = this.x;
- int y = this.y;
- if (item != null) {
- int /*long*/ itemHandle = item.handle;
- if(OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
- GdkRectangle area = new GdkRectangle ();
- OS.gtk_status_icon_get_geometry (itemHandle, 0, area, 0);
- x = area.x + area.width / 2;
- y = area.y + area.height / 2;
- } else {
- OS.gtk_widget_realize (itemHandle);
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (itemHandle);
- int [] px = new int [1], py = new int [1];
- OS.gdk_window_get_origin (window, px, py);
- x = px [0] + OS.GTK_WIDGET_WIDTH (itemHandle) / 2;
- y = py [0] + OS.GTK_WIDGET_HEIGHT (itemHandle) / 2;
- }
- }
- if (x == -1 || y == -1) {
- int [] px = new int [1], py = new int [1];
- OS.gdk_window_get_pointer (0, px, py, null);
- x = px [0];
- y = py [0];
- }
- return new Point(x, y);
-}
-
-/**
- * Returns the receiver's message, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's message
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getMessage () {
- checkWidget ();
- return message;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Shell</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Shell getParent () {
- checkWidget ();
- return parent;
-}
-
-Point getSize (int maxWidth) {
- int textWidth = 0, messageWidth = 0;
- int [] w = new int [1], h = new int [1];
- if (layoutText != 0) {
- OS.pango_layout_set_width (layoutText, -1);
- OS.pango_layout_get_size (layoutText, w, h);
- textWidth = OS.PANGO_PIXELS (w [0]);
- }
- if (layoutMessage != 0) {
- OS.pango_layout_set_width (layoutMessage, -1);
- OS.pango_layout_get_size (layoutMessage, w, h);
- messageWidth = OS.PANGO_PIXELS (w [0]);
- }
- int messageTrim = 2 * INSET + 2 * BORDER + 2 * PADDING;
- boolean hasImage = layoutText != 0 && (style & (SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING)) != 0;
- int textTrim = messageTrim + (hasImage ? IMAGE_SIZE : 0);
- int width = Math.min (maxWidth, Math.max (textWidth + textTrim, messageWidth + messageTrim));
- int textHeight = 0, messageHeight = 0;
- if (layoutText != 0) {
- OS.pango_layout_set_width (layoutText, (maxWidth - textTrim) * OS.PANGO_SCALE);
- OS.pango_layout_get_size (layoutText, w, h);
- textHeight = OS.PANGO_PIXELS (h [0]);
- }
- if (layoutMessage != 0) {
- OS.pango_layout_set_width (layoutMessage, (maxWidth - messageTrim) * OS.PANGO_SCALE);
- OS.pango_layout_get_size (layoutMessage, w, h);
- messageHeight = OS.PANGO_PIXELS (h [0]);
- }
- int height = 2 * BORDER + 2 * PADDING + messageHeight;
- if (layoutText != 0) height += Math.max (IMAGE_SIZE, textHeight) + 2 * PADDING;
- return new Point(width, height);
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- if ((style & SWT.BALLOON) != 0) return OS.GTK_WIDGET_VISIBLE (handle);
- int /*long*/ tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (handle);
- return OS.GTK_WIDGET_VISIBLE (tipWindow);
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) {
- notifyListeners (SWT.Selection, new Event ());
- setVisible (false);
- return 0;
-}
-
-int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ eventPtr) {
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (handle);
- int /*long*/ gdkGC = OS.gdk_gc_new (window);
- OS.gdk_draw_polygon (window, gdkGC, 0, borderPolygon, borderPolygon.length / 2);
- int x = BORDER + PADDING;
- int y = BORDER + PADDING;
- if (spikeAbove) y += TIP_HEIGHT;
- if (layoutText != 0) {
- byte[] buffer = null;
- int id = style & (SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING);
- switch (id) {
- case SWT.ICON_ERROR: buffer = Converter.wcsToMbcs (null, "gtk-dialog-error", true); break;
- case SWT.ICON_INFORMATION: buffer = Converter.wcsToMbcs (null, "gtk-dialog-info", true); break;
- case SWT.ICON_WARNING: buffer = Converter.wcsToMbcs (null, "gtk-dialog-warning", true); break;
- }
- if (buffer != null) {
- int /*long*/ style = OS.gtk_widget_get_default_style ();
- int /*long*/ pixbuf = OS.gtk_icon_set_render_icon (
- OS.gtk_icon_factory_lookup_default (buffer),
- style,
- OS.GTK_TEXT_DIR_NONE,
- OS.GTK_STATE_NORMAL,
- OS.GTK_ICON_SIZE_MENU,
- 0,
- 0);
- OS.gdk_draw_pixbuf (window, gdkGC, pixbuf, 0, 0, x, y, IMAGE_SIZE, IMAGE_SIZE, OS.GDK_RGB_DITHER_NORMAL, 0, 0);
- OS.g_object_unref (pixbuf);
- x += IMAGE_SIZE;
- }
- x += INSET;
- OS.gdk_draw_layout (window, gdkGC, x, y, layoutText);
- int [] w = new int [1], h = new int [1];
- OS.pango_layout_get_size (layoutText, w, h);
- y += 2 * PADDING + Math.max (IMAGE_SIZE, OS.PANGO_PIXELS (h [0]));
- }
- if (layoutMessage != 0) {
- x = BORDER + PADDING + INSET;
- OS.gdk_draw_layout (window, gdkGC, x, y, layoutMessage);
- }
- OS.g_object_unref (gdkGC);
- return 0;
-}
-
-int /*long*/ gtk_size_allocate (int /*long*/ widget, int /*long*/ allocation) {
- Point point = getLocation ();
- int x = point.x;
- int y = point.y;
- int /*long*/ screen = OS.gdk_screen_get_default ();
- OS.gtk_widget_realize (widget);
- int monitorNumber = OS.gdk_screen_get_monitor_at_window (screen, OS.GTK_WIDGET_WINDOW (widget));
- GdkRectangle dest = new GdkRectangle ();
- OS.gdk_screen_get_monitor_geometry (screen, monitorNumber, dest);
- int w = OS.GTK_WIDGET_WIDTH (widget);
- int h = OS.GTK_WIDGET_HEIGHT (widget);
- if (dest.height < y + h) y -= h;
- if (dest.width < x + w) x -= w;
- OS.gtk_window_move (widget, x, y);
- return 0;
-}
-
-void hookEvents () {
- if ((style & SWT.BALLOON) != 0) {
- OS.g_signal_connect_closure (handle, OS.expose_event, display.closures [EXPOSE_EVENT], false);
- OS.gtk_widget_add_events (handle, OS.GDK_BUTTON_PRESS_MASK);
- OS.g_signal_connect_closure (handle, OS.button_press_event, display.closures [BUTTON_PRESS_EVENT], false);
- } else {
- int /*long*/ tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (handle);
- if (tipWindow != 0) {
- OS.g_signal_connect_closure (tipWindow, OS.size_allocate, display.closures [SIZE_ALLOCATE], false);
- OS.gtk_widget_add_events (tipWindow, OS.GDK_BUTTON_PRESS_MASK);
- OS.g_signal_connect_closure (tipWindow, OS.button_press_event, display.closures [BUTTON_PRESS_EVENT], false);
- }
- }
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget ();
- return getVisible ();
-}
-
-void register () {
- super.register ();
- if ((style & SWT.BALLOON) == 0) {
- int /*long*/ tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (handle);
- if (tipWindow != 0) display.addWidget (tipWindow, this);
- }
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (layoutText != 0) OS.g_object_unref (layoutText);
- layoutText = 0;
- if (layoutMessage != 0) OS.g_object_unref (layoutMessage);
- layoutMessage = 0;
- if (timerId != 0) OS.gtk_timeout_remove(timerId);
- timerId = 0;
- text = null;
- message = null;
- borderPolygon = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection, listener);
-}
-
-/**
- * Makes the receiver hide automatically when <code>true</code>,
- * and remain visible when <code>false</code>.
- *
- * @param autoHide the auto hide state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- * @see #setVisible
- */
-public void setAutoHide (boolean autohide) {
- checkWidget ();
- this.autohide = autohide;
- //TODO - update when visible
-}
-
-/**
- * Sets the location of the receiver, which must be a tooltip,
- * to the point specified by the arguments which are relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget ();
- this.x = x;
- this.y = y;
- if ((style & SWT.BALLOON) != 0) {
- if (OS.GTK_WIDGET_VISIBLE (handle)) configure ();
- } else {
- int /*long*/ tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (handle);
- if (OS.GTK_WIDGET_VISIBLE (tipWindow)) {
- OS.gtk_window_move (tipWindow, x, y);
- }
- }
-}
-
-/**
- * Sets the location of the receiver, which must be a tooltip,
- * to the point specified by the argument which is relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p><p>
- * Note that the platform window manager ultimately has control
- * over the location of tooltips.
- * </p>
- *
- * @param location the new location for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (Point location) {
- checkWidget ();
- if (location == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-/**
- * Sets the receiver's message.
- *
- * @param string the new message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMessage (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- message = string;
- if ((style & SWT.BALLOON) == 0) return;
- if (layoutMessage != 0) OS.g_object_unref (layoutMessage);
- layoutMessage = 0;
- if (message.length () != 0) {
- byte [] buffer = Converter.wcsToMbcs (null, message, true);
- layoutMessage = OS.gtk_widget_create_pango_layout (handle, buffer);
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- OS.pango_layout_set_auto_dir (layoutMessage, false);
- }
- OS.pango_layout_set_wrap (layoutMessage, OS.PANGO_WRAP_WORD_CHAR);
- }
- if (OS.GTK_WIDGET_VISIBLE (handle)) configure ();
-}
-
-/**
- * Sets the receiver's text.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- text = string;
- if ((style & SWT.BALLOON) == 0) return;
- if (layoutText != 0) OS.g_object_unref (layoutText);
- layoutText = 0;
- if (text.length () != 0) {
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- layoutText = OS.gtk_widget_create_pango_layout (handle, buffer);
- if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) {
- OS.pango_layout_set_auto_dir (layoutText, false);
- }
- int /*long*/ boldAttr = OS.pango_attr_weight_new (OS.PANGO_WEIGHT_BOLD);
- PangoAttribute attribute = new PangoAttribute ();
- OS.memmove (attribute, boldAttr, PangoAttribute.sizeof);
- attribute.start_index = 0;
- attribute.end_index = buffer.length;
- OS.memmove (boldAttr, attribute, PangoAttribute.sizeof);
- int /*long*/ attrList = OS.pango_attr_list_new ();
- OS.pango_attr_list_insert (attrList, boldAttr);
- OS.pango_layout_set_attributes (layoutText, attrList);
- OS.pango_attr_list_unref (attrList);
- OS.pango_layout_set_wrap (layoutText, OS.PANGO_WRAP_WORD_CHAR);
- }
- if (OS.GTK_WIDGET_VISIBLE (handle)) configure ();
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- if (timerId != 0) OS.gtk_timeout_remove(timerId);
- timerId = 0;
- if (visible) {
- if ((style & SWT.BALLOON) != 0) {
- configure ();
- OS.gtk_widget_show (handle);
- } else {
- int /*long*/ vboxHandle = parent.vboxHandle;
- StringBuffer string = new StringBuffer (text);
- if (text.length () > 0) string.append ("\n\n");
- string.append (message);
- byte [] buffer = Converter.wcsToMbcs (null, string.toString(), true);
- OS.gtk_tooltips_set_tip (handle, vboxHandle, buffer, null);
- int /*long*/ data = OS.gtk_tooltips_data_get (vboxHandle);
- OS.GTK_TOOLTIPS_SET_ACTIVE (handle, data);
- OS.gtk_tooltips_set_tip (handle, vboxHandle, buffer, null);
- }
- if (autohide) timerId = OS.gtk_timeout_add (DELAY, display.windowTimerProc, handle);
- } else {
- if ((style & SWT.BALLOON) != 0) {
- OS.gtk_widget_hide (handle);
- } else {
- int /*long*/ tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (handle);
- OS.gtk_widget_hide (tipWindow);
- }
- }
-}
-
-int /*long*/ timerProc (int /*long*/ widget) {
- if ((style & SWT.BALLOON) != 0) {
- OS.gtk_widget_hide (handle);
- } else {
- int /*long*/ tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (handle);
- OS.gtk_widget_hide (tipWindow);
- }
- return 0;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java
deleted file mode 100644
index e5729d3980..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java
+++ /dev/null
@@ -1,996 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class implement rubber banding rectangles that are
- * drawn onto a parent <code>Composite</code> or <code>Display</code>.
- * These rectangles can be specified to respond to mouse and key events
- * by either moving or resizing themselves accordingly. Trackers are
- * typically used to represent window geometries in a lightweight manner.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, UP, DOWN, RESIZE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Move, Resize</dd>
- * </dl>
- * <p>
- * Note: Rectangle move behavior is assumed unless RESIZE is specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tracker">Tracker snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Tracker extends Widget {
- Composite parent;
- Cursor cursor;
- int /*long*/ lastCursor, window;
- boolean tracking, cancelled, grabbed, stippled;
- Rectangle [] rectangles = new Rectangle [0], proportions = rectangles;
- Rectangle bounds;
- int cursorOrientation = SWT.NONE;
- int oldX, oldY;
-
- final static int STEPSIZE_SMALL = 1;
- final static int STEPSIZE_LARGE = 9;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#RESIZE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Tracker (Composite parent, int style) {
- super (parent, checkStyle(style));
- this.parent = parent;
-}
-
-/**
- * Constructs a new instance of this class given the display
- * to create it on and a style value describing its behavior
- * and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the tracker on the currently active
- * display if there is one. If there is no current display, the
- * tracker is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the tracker on
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#RESIZE
- */
-public Tracker (Display display, int style) {
- if (display == null) display = Display.getCurrent ();
- if (display == null) display = Display.getDefault ();
- if (!display.isValidThread ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- this.style = checkStyle (style);
- this.display = display;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize, typedListener);
- addListener (SWT.Move, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard, by sending
- * it one of the messages defined in the <code>KeyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #removeKeyListener
- */
-public void addKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.KeyUp,typedListener);
- addListener(SWT.KeyDown,typedListener);
-}
-
-Point adjustMoveCursor () {
- if (bounds == null) return null;
- int newX = bounds.x + bounds.width / 2;
- int newY = bounds.y;
-
- Point point = display.map (parent, null, newX, newY);
- display.setCursorLocation (point);
-
- /*
- * The call to XWarpPointer does not always place the pointer on the
- * exact location that is specified, so do a query (below) to get the
- * actual location of the pointer after it has been moved.
- */
- int [] actualX = new int [1], actualY = new int [1], state = new int [1];
- OS.gdk_window_get_pointer (window, actualX, actualY, state);
- return new Point (actualX [0], actualY [0]);
-}
-
-Point adjustResizeCursor () {
- if (bounds == null) return null;
- int newX, newY;
-
- if ((cursorOrientation & SWT.LEFT) != 0) {
- newX = bounds.x;
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- newX = bounds.x + bounds.width;
- } else {
- newX = bounds.x + bounds.width / 2;
- }
-
- if ((cursorOrientation & SWT.UP) != 0) {
- newY = bounds.y;
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- newY = bounds.y + bounds.height;
- } else {
- newY = bounds.y + bounds.height / 2;
- }
-
- Point point = display.map (parent, null, newX, newY);
- display.setCursorLocation (point);
-
- /*
- * The call to XWarpPointer does not always place the pointer on the
- * exact location that is specified, so do a query (below) to get the
- * actual location of the pointer after it has been moved.
- */
- int [] actualX = new int [1], actualY = new int [1], state = new int [1];
- OS.gdk_window_get_pointer (window, actualX, actualY, state);
- return new Point (actualX [0], actualY [0]);
-}
-
-
-/**
- * Stops displaying the tracker rectangles. Note that this is not considered
- * to be a cancelation by the user.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void close () {
- checkWidget();
- tracking = false;
-}
-
-static int checkStyle (int style) {
- if ((style & (SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN)) == 0) {
- style |= SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN;
- }
- return style;
-}
-
-Rectangle computeBounds () {
- if (rectangles.length == 0) return null;
- int xMin = rectangles [0].x;
- int yMin = rectangles [0].y;
- int xMax = rectangles [0].x + rectangles [0].width;
- int yMax = rectangles [0].y + rectangles [0].height;
-
- for (int i = 1; i < rectangles.length; i++) {
- if (rectangles [i].x < xMin) xMin = rectangles [i].x;
- if (rectangles [i].y < yMin) yMin = rectangles [i].y;
- int rectRight = rectangles [i].x + rectangles [i].width;
- if (rectRight > xMax) xMax = rectRight;
- int rectBottom = rectangles [i].y + rectangles [i].height;
- if (rectBottom > yMax) yMax = rectBottom;
- }
-
- return new Rectangle (xMin, yMin, xMax - xMin, yMax - yMin);
-}
-
-Rectangle [] computeProportions (Rectangle [] rects) {
- Rectangle [] result = new Rectangle [rects.length];
- bounds = computeBounds ();
- if (bounds != null) {
- for (int i = 0; i < rects.length; i++) {
- int x = 0, y = 0, width = 0, height = 0;
- if (bounds.width != 0) {
- x = (rects [i].x - bounds.x) * 100 / bounds.width;
- width = rects [i].width * 100 / bounds.width;
- } else {
- width = 100;
- }
- if (bounds.height != 0) {
- y = (rects [i].y - bounds.y) * 100 / bounds.height;
- height = rects [i].height * 100 / bounds.height;
- } else {
- height = 100;
- }
- result [i] = new Rectangle (x, y, width, height);
- }
- }
- return result;
-}
-
-void drawRectangles (Rectangle [] rects) {
- int /*long*/ window = OS.GDK_ROOT_PARENT ();
- if (parent != null) {
- window = OS.GTK_WIDGET_WINDOW (parent.paintHandle());
- }
- if (window == 0) return;
- int /*long*/ gc = OS.gdk_gc_new (window);
- if (gc == 0) return;
- int /*long*/ colormap = OS.gdk_colormap_get_system ();
- GdkColor color = new GdkColor ();
- OS.gdk_color_white (colormap, color);
- OS.gdk_gc_set_foreground (gc, color);
- OS.gdk_gc_set_subwindow (gc, OS.GDK_INCLUDE_INFERIORS);
- OS.gdk_gc_set_function (gc, OS.GDK_XOR);
- for (int i=0; i<rects.length; i++) {
- Rectangle rect = rects [i];
- int x = rect.x;
- if (parent != null && (parent.style & SWT.MIRRORED) != 0) x = parent.getClientWidth () - rect.width - x;
- OS.gdk_draw_rectangle (window, gc, 0, x, rect.y, rect.width, rect.height);
- }
- OS.g_object_unref (gc);
-}
-
-/**
- * Returns the bounds that are being drawn, expressed relative to the parent
- * widget. If the parent is a <code>Display</code> then these are screen
- * coordinates.
- *
- * @return the bounds of the Rectangles being drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle [] getRectangles () {
- checkWidget();
- Rectangle [] result = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- result [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- return result;
-}
-
-/**
- * Returns <code>true</code> if the rectangles are drawn with a stippled line, <code>false</code> otherwise.
- *
- * @return the stippled effect of the rectangles
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getStippled () {
- checkWidget();
- return stippled;
-}
-
-boolean grab () {
- int /*long*/ cursor = this.cursor != null ? this.cursor.handle : 0;
- int result = OS.gdk_pointer_grab (window, false, OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_RELEASE_MASK, window, cursor, OS.GDK_CURRENT_TIME);
- return result == OS.GDK_GRAB_SUCCESS;
-}
-
-int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ event) {
- return gtk_mouse (OS.GDK_BUTTON_RELEASE, widget, event);
-}
-
-int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ eventPtr) {
- int /*long*/ result = super.gtk_key_press_event (widget, eventPtr);
- if (result != 0) return result;
- GdkEventKey keyEvent = new GdkEventKey ();
- OS.memmove (keyEvent, eventPtr, GdkEventKey.sizeof);
- int stepSize = ((keyEvent.state & OS.GDK_CONTROL_MASK) != 0) ? STEPSIZE_SMALL : STEPSIZE_LARGE;
- int xChange = 0, yChange = 0;
- switch (keyEvent.keyval) {
- case OS.GDK_Escape:
- cancelled = true;
- // fallthrough
- case OS.GDK_Return:
- tracking = false;
- break;
- case OS.GDK_Left:
- xChange = -stepSize;
- break;
- case OS.GDK_Right:
- xChange = stepSize;
- break;
- case OS.GDK_Up:
- yChange = -stepSize;
- break;
- case OS.GDK_Down:
- yChange = stepSize;
- break;
- }
- if (xChange != 0 || yChange != 0) {
- Rectangle [] oldRectangles = rectangles;
- Rectangle [] rectsToErase = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- rectsToErase [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- Event event = new Event ();
- event.x = oldX + xChange;
- event.y = oldY + yChange;
- if (parent != null && (parent.style & SWT.MIRRORED) != 0) {
- event.x = parent.getClientWidth () - event.width - event.x;
- }
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (xChange, yChange);
- sendEvent (SWT.Resize, event);
- /*
- * It is possible (but unlikely) that application
- * code could have disposed the widget in the resize
- * event. If this happens return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return 1;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the resize event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (rectsToErase);
- update ();
- drawRectangles (rectangles);
- }
- Point cursorPos = adjustResizeCursor ();
- if (cursorPos != null) {
- oldX = cursorPos.x;
- oldY = cursorPos.y;
- }
- } else {
- moveRectangles (xChange, yChange);
- sendEvent (SWT.Move, event);
- /*
- * It is possible (but unlikely) that application
- * code could have disposed the widget in the move
- * event. If this happens return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return 1;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the move event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (rectsToErase);
- update ();
- drawRectangles (rectangles);
- }
- Point cursorPos = adjustMoveCursor ();
- if (cursorPos != null) {
- oldX = cursorPos.x;
- oldY = cursorPos.y;
- }
- }
- }
- return result;
-}
-
-int /*long*/ gtk_motion_notify_event (int /*long*/ widget, int /*long*/ eventPtr) {
- int /*long*/ cursor = this.cursor != null ? this.cursor.handle : 0;
- if (cursor != lastCursor) {
- ungrab ();
- grabbed = grab ();
- lastCursor = cursor;
- }
- return gtk_mouse (OS.GDK_MOTION_NOTIFY, widget, eventPtr);
-}
-
-int /*long*/ gtk_mouse (int eventType, int /*long*/ widget, int /*long*/ eventPtr) {
- int [] newX = new int [1], newY = new int [1];
- OS.gdk_window_get_pointer (window, newX, newY, null);
- if (oldX != newX [0] || oldY != newY [0]) {
- Rectangle [] oldRectangles = rectangles;
- Rectangle [] rectsToErase = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- rectsToErase [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- Event event = new Event ();
- if (parent == null) {
- event.x = newX [0];
- event.y = newY [0];
- } else {
- Point screenCoord = display.map (parent, null, newX [0], newY [0]);
- event.x = screenCoord.x;
- event.y = screenCoord.y;
- }
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (newX [0] - oldX, newY [0] - oldY);
- sendEvent (SWT.Resize, event);
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the resize
- * event. If this happens, return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return 1;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the resize event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (rectsToErase);
- update ();
- drawRectangles (rectangles);
- }
- Point cursorPos = adjustResizeCursor ();
- if (cursorPos != null) {
- newX [0] = cursorPos.x;
- newY [0] = cursorPos.y;
- }
- } else {
- moveRectangles (newX [0] - oldX, newY [0] - oldY);
- sendEvent (SWT.Move, event);
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the move
- * event. If this happens, return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return 1;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the move event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (rectsToErase);
- update ();
- drawRectangles (rectangles);
- }
- }
- oldX = newX [0];
- oldY = newY [0];
- }
- tracking = eventType != OS.GDK_BUTTON_RELEASE;
- return 0;
-}
-
-void moveRectangles (int xChange, int yChange) {
- if (bounds == null) return;
- if (xChange < 0 && ((style & SWT.LEFT) == 0)) xChange = 0;
- if (xChange > 0 && ((style & SWT.RIGHT) == 0)) xChange = 0;
- if (yChange < 0 && ((style & SWT.UP) == 0)) yChange = 0;
- if (yChange > 0 && ((style & SWT.DOWN) == 0)) yChange = 0;
- if (xChange == 0 && yChange == 0) return;
- if (parent != null && (parent.style & SWT.MIRRORED) != 0) xChange *= -1;
- bounds.x += xChange; bounds.y += yChange;
- for (int i = 0; i < rectangles.length; i++) {
- rectangles [i].x += xChange;
- rectangles [i].y += yChange;
- }
-}
-
-/**
- * Displays the Tracker rectangles for manipulation by the user. Returns when
- * the user has either finished manipulating the rectangles or has cancelled the
- * Tracker.
- *
- * @return <code>true</code> if the user did not cancel the Tracker, <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean open () {
- checkWidget();
- window = OS.GDK_ROOT_PARENT ();
- if (parent != null) {
- window = OS.GTK_WIDGET_WINDOW (parent.paintHandle());
- }
- if (window == 0) return false;
- cancelled = false;
- tracking = true;
- update ();
- drawRectangles (rectangles);
- int [] oldX = new int [1], oldY = new int [1], state = new int [1];
- OS.gdk_window_get_pointer (window, oldX, oldY, state);
-
- /*
- * if exactly one of UP/DOWN is specified as a style then set the cursor
- * orientation accordingly (the same is done for LEFT/RIGHT styles below)
- */
- int vStyle = style & (SWT.UP | SWT.DOWN);
- if (vStyle == SWT.UP || vStyle == SWT.DOWN) {
- cursorOrientation |= vStyle;
- }
- int hStyle = style & (SWT.LEFT | SWT.RIGHT);
- if (hStyle == SWT.LEFT || hStyle == SWT.RIGHT) {
- cursorOrientation |= hStyle;
- }
-
- int mask = OS.GDK_BUTTON1_MASK | OS.GDK_BUTTON2_MASK | OS.GDK_BUTTON3_MASK;
- boolean mouseDown = (state [0] & mask) != 0;
- if (!mouseDown) {
- Point cursorPos = null;
- if ((style & SWT.RESIZE) != 0) {
- cursorPos = adjustResizeCursor ();
- } else {
- cursorPos = adjustMoveCursor ();
- }
- if (cursorPos != null) {
- oldX [0] = cursorPos.x;
- oldY [0] = cursorPos.y;
- }
- }
- this.oldX = oldX [0];
- this.oldY = oldY [0];
-
- grabbed = grab ();
- lastCursor = this.cursor != null ? this.cursor.handle : 0;
-
- /* Tracker behaves like a Dialog with its own OS event loop. */
- GdkEvent gdkEvent = new GdkEvent();
- while (tracking) {
- if (parent != null && parent.isDisposed ()) break;
- int /*long*/ eventPtr;
- while (true) {
- eventPtr = OS.gdk_event_get ();
- if (eventPtr != 0) {
- break;
- } else {
- try { Thread.sleep(50); } catch (Exception ex) {}
- }
- }
- OS.memmove (gdkEvent, eventPtr, GdkEvent.sizeof);
- int /*long*/ widget = OS.gtk_get_event_widget (eventPtr);
- switch (gdkEvent.type) {
- case OS.GDK_MOTION_NOTIFY: gtk_motion_notify_event (widget, eventPtr); break;
- case OS.GDK_BUTTON_RELEASE: gtk_button_release_event (widget, eventPtr); break;
- case OS.GDK_KEY_PRESS: gtk_key_press_event (widget, eventPtr); break;
- case OS.GDK_KEY_RELEASE: gtk_key_release_event (widget, eventPtr); break;
- case OS.GDK_BUTTON_PRESS:
- case OS.GDK_2BUTTON_PRESS:
- case OS.GDK_3BUTTON_PRESS:
- case OS.GDK_ENTER_NOTIFY:
- case OS.GDK_LEAVE_NOTIFY:
- /* Do not dispatch these */
- break;
- case OS.GDK_EXPOSE:
- update ();
- drawRectangles (rectangles);
- OS.gtk_main_do_event (eventPtr);
- drawRectangles (rectangles);
- break;
- default:
- OS.gtk_main_do_event (eventPtr);
- }
- OS.gdk_event_free (eventPtr);
- }
- if (!isDisposed ()) {
- update ();
- drawRectangles (rectangles);
- }
- ungrab ();
- window = 0;
- return !cancelled;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
- rectangles = proportions = null;
- bounds = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Resize, listener);
- eventTable.unhook (SWT.Move, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #addKeyListener
- */
-public void removeKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.KeyUp, listener);
- eventTable.unhook (SWT.KeyDown, listener);
-}
-
-void resizeRectangles (int xChange, int yChange) {
- if (bounds == null) return;
- if (parent != null && (parent.style & SWT.MIRRORED) != 0) xChange *= -1;
- /*
- * If the cursor orientation has not been set in the orientation of
- * this change then try to set it here.
- */
- if (xChange < 0 && ((style & SWT.LEFT) != 0) && ((cursorOrientation & SWT.RIGHT) == 0)) {
- cursorOrientation |= SWT.LEFT;
- }
- if (xChange > 0 && ((style & SWT.RIGHT) != 0) && ((cursorOrientation & SWT.LEFT) == 0)) {
- cursorOrientation |= SWT.RIGHT;
- }
- if (yChange < 0 && ((style & SWT.UP) != 0) && ((cursorOrientation & SWT.DOWN) == 0)) {
- cursorOrientation |= SWT.UP;
- }
- if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) {
- cursorOrientation |= SWT.DOWN;
- }
-
- /*
- * If the bounds will flip about the x or y axis then apply the adjustment
- * up to the axis (ie.- where bounds width/height becomes 0), change the
- * cursor's orientation accordingly, and flip each Rectangle's origin (only
- * necessary for > 1 Rectangles)
- */
- if ((cursorOrientation & SWT.LEFT) != 0) {
- if (xChange > bounds.width) {
- if ((style & SWT.RIGHT) == 0) return;
- cursorOrientation |= SWT.RIGHT;
- cursorOrientation &= ~SWT.LEFT;
- bounds.x += bounds.width;
- xChange -= bounds.width;
- bounds.width = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.x = 100 - proportion.x - proportion.width;
- }
- }
- }
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- if (bounds.width < -xChange) {
- if ((style & SWT.LEFT) == 0) return;
- cursorOrientation |= SWT.LEFT;
- cursorOrientation &= ~SWT.RIGHT;
- xChange += bounds.width;
- bounds.width = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.x = 100 - proportion.x - proportion.width;
- }
- }
- }
- }
- if ((cursorOrientation & SWT.UP) != 0) {
- if (yChange > bounds.height) {
- if ((style & SWT.DOWN) == 0) return;
- cursorOrientation |= SWT.DOWN;
- cursorOrientation &= ~SWT.UP;
- bounds.y += bounds.height;
- yChange -= bounds.height;
- bounds.height = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.y = 100 - proportion.y - proportion.height;
- }
- }
- }
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- if (bounds.height < -yChange) {
- if ((style & SWT.UP) == 0) return;
- cursorOrientation |= SWT.UP;
- cursorOrientation &= ~SWT.DOWN;
- yChange += bounds.height;
- bounds.height = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.y = 100 - proportion.y - proportion.height;
- }
- }
- }
- }
-
- // apply the bounds adjustment
- if ((cursorOrientation & SWT.LEFT) != 0) {
- bounds.x += xChange;
- bounds.width -= xChange;
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- bounds.width += xChange;
- }
- if ((cursorOrientation & SWT.UP) != 0) {
- bounds.y += yChange;
- bounds.height -= yChange;
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- bounds.height += yChange;
- }
-
- Rectangle [] newRects = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle proportion = proportions[i];
- newRects[i] = new Rectangle (
- proportion.x * bounds.width / 100 + bounds.x,
- proportion.y * bounds.height / 100 + bounds.y,
- proportion.width * bounds.width / 100,
- proportion.height * bounds.height / 100);
- }
- rectangles = newRects;
-}
-
-/**
- * Sets the <code>Cursor</code> of the Tracker. If this cursor is <code>null</code>
- * then the cursor reverts to the default.
- *
- * @param newCursor the new <code>Cursor</code> to display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCursor (Cursor value) {
- checkWidget ();
- cursor = value;
-}
-
-/**
- * Specifies the rectangles that should be drawn, expressed relative to the parent
- * widget. If the parent is a Display then these are screen coordinates.
- *
- * @param rectangles the bounds of the rectangles to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of rectangles is null or contains a null rectangle</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setRectangles (Rectangle [] rectangles) {
- checkWidget();
- if (rectangles == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = rectangles.length;
- this.rectangles = new Rectangle [length];
- for (int i = 0; i < length; i++) {
- Rectangle current = rectangles [i];
- if (current == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.rectangles [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- proportions = computeProportions (rectangles);
-}
-
-/**
- * Changes the appearance of the line used to draw the rectangles.
- *
- * @param stippled <code>true</code> if rectangle should appear stippled
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setStippled (boolean stippled) {
- checkWidget();
- this.stippled = stippled;
-}
-
-void ungrab () {
- if (grabbed) OS.gdk_pointer_ungrab (OS.GDK_CURRENT_TIME);
-}
-
-void update () {
- if (parent != null) {
- if (parent.isDisposed ()) return;
- parent.getShell ().update ();
- } else {
- display.update ();
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java
deleted file mode 100644
index 7d1fb1f17b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java
+++ /dev/null
@@ -1,591 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-
-/**
- * Instances of this class represent icons that can be placed on the
- * system tray or task bar status area.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, MenuDetect, Selection</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tray">Tray, TrayItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.0
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TrayItem extends Item {
- Tray parent;
- ToolTip toolTip;
- String toolTipText;
- int /*long*/ imageHandle;
- int /*long*/ tooltipsHandle;
- ImageList imageList;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tray</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TrayItem (Tray parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget (parent.getItemCount ());
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the platform-specific context menu trigger
- * has occurred, by sending it one of the messages defined in
- * the <code>MenuDetectListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #removeMenuDetectListener
- *
- * @since 3.3
- */
-public void addMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MenuDetect, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the receiver is selected
- * <code>widgetDefaultSelected</code> is called when the receiver is double-clicked
- * </p>
- *
- * @param listener the listener which should be notified when the receiver is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- parent.createItem (this, index);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
- handle = OS.gtk_status_icon_new ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- imageHandle = OS.gtk_image_new ();
- OS.gtk_status_icon_set_visible (handle,true);
- } else {
- handle = OS.gtk_plug_new (0);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- imageHandle = OS.gtk_image_new ();
- if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (handle, imageHandle);
- OS.gtk_widget_show (handle);
- OS.gtk_widget_show (imageHandle);
- int /*long*/ id = OS.gtk_plug_get_id (handle);
- int monitor = 0;
- int /*long*/ screen = OS.gdk_screen_get_default ();
- if (screen != 0) {
- monitor = OS.gdk_screen_get_number (screen);
- }
- byte [] trayBuffer = Converter.wcsToMbcs (null, "_NET_SYSTEM_TRAY_S" + monitor, true);
- int /*long*/ trayAtom = OS.gdk_atom_intern (trayBuffer, true);
- int /*long*/ xTrayAtom = OS.gdk_x11_atom_to_xatom (trayAtom);
- int /*long*/ xDisplay = OS.GDK_DISPLAY ();
- int /*long*/ trayWindow = OS.XGetSelectionOwner (xDisplay, xTrayAtom);
- byte [] messageBuffer = Converter.wcsToMbcs (null, "_NET_SYSTEM_TRAY_OPCODE", true);
- int /*long*/ messageAtom = OS.gdk_atom_intern (messageBuffer, true);
- int /*long*/ xMessageAtom = OS.gdk_x11_atom_to_xatom (messageAtom);
- XClientMessageEvent event = new XClientMessageEvent ();
- event.type = OS.ClientMessage;
- event.window = trayWindow;
- event.message_type = xMessageAtom;
- event.format = 32;
- event.data [0] = OS.GDK_CURRENT_TIME;
- event.data [1] = OS.SYSTEM_TRAY_REQUEST_DOCK;
- event.data [2] = id;
- int /*long*/ clientEvent = OS.g_malloc (XClientMessageEvent.sizeof);
- OS.memmove (clientEvent, event, XClientMessageEvent.sizeof);
- OS.XSendEvent (xDisplay, trayWindow, false, OS.NoEventMask, clientEvent);
- OS.g_free (clientEvent);
- }
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (imageHandle);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Tray</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Tray getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's tool tip, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public ToolTip getToolTip () {
- checkWidget ();
- return toolTip;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-
-int /*long*/ gtk_activate (int /*long*/ widget) {
- postEvent (SWT.Selection);
- /*
- * Feature in GTK. GTK will generate a single-click event before sending
- * a double-click event. To know when to send a DefaultSelection, look for
- * the single-click as the current event and for the double-click in the
- * event queue.
- */
- int /*long*/ nextEvent = OS.gdk_event_peek ();
- if (nextEvent != 0) {
- int nextEventType = OS.GDK_EVENT_TYPE (nextEvent);
- int /*long*/ currEvent = OS.gtk_get_current_event ();
- int currEventType = 0;
- if (currEvent != 0) {
- currEventType = OS.GDK_EVENT_TYPE (currEvent);
- OS.gdk_event_free (currEvent);
- }
- OS.gdk_event_free (nextEvent);
- if (currEventType == OS.GDK_BUTTON_PRESS && nextEventType == OS.GDK_2BUTTON_PRESS) {
- postEvent (SWT.DefaultSelection);
- }
- }
- return 0;
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ eventPtr) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, eventPtr, GdkEventButton.sizeof);
- if (gdkEvent.type == OS.GDK_3BUTTON_PRESS) return 0;
- if (gdkEvent.button == 3 && gdkEvent.type == OS.GDK_BUTTON_PRESS) {
- sendEvent (SWT.MenuDetect);
- return 0;
- }
- if (gdkEvent.type == OS.GDK_2BUTTON_PRESS) {
- postEvent (SWT.DefaultSelection);
- } else {
- postEvent (SWT.Selection);
- }
- return 0;
-}
-
-int /*long*/ gtk_size_allocate (int /*long*/ widget, int /*long*/ allocation) {
- if (image != null && image.mask != 0) {
- if (OS.gdk_drawable_get_depth (image.mask) == 1) {
- int xoffset = (int) Math.floor (OS.GTK_WIDGET_X (widget) + ((OS.GTK_WIDGET_WIDTH (widget) - OS.GTK_WIDGET_REQUISITION_WIDTH (widget)) * 0.5) + 0.5);
- int yoffset = (int) Math.floor (OS.GTK_WIDGET_Y (widget) + ((OS.GTK_WIDGET_HEIGHT (widget) - OS.GTK_WIDGET_REQUISITION_HEIGHT (widget)) * 0.5) + 0.5);
- Rectangle b = image.getBounds();
- int /*long*/ gdkImagePtr = OS.gdk_drawable_get_image (image.mask, 0, 0, b.width, b.height);
- if (gdkImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- GdkImage gdkImage = new GdkImage();
- OS.memmove (gdkImage, gdkImagePtr);
- byte[] maskData = new byte [gdkImage.bpl * gdkImage.height];
- OS.memmove (maskData, gdkImage.mem, maskData.length);
- OS.g_object_unref (gdkImagePtr);
- Region region = new Region (display);
- for (int y = 0; y < b.height; y++) {
- for (int x = 0; x < b.width; x++) {
- int index = (y * gdkImage.bpl) + (x >> 3);
- int theByte = maskData [index] & 0xFF;
- int mask = 1 << (x & 0x7);
- if ((theByte & mask) != 0) {
- region.add (xoffset + x, yoffset + y, 1, 1);
- }
- }
- }
- OS.gtk_widget_realize (handle);
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (handle);
- OS.gdk_window_shape_combine_region (window, region.handle, 0, 0);
- region.dispose ();
- }
- }
- return 0;
-}
-
-int /*long*/ gtk_status_icon_popup_menu (int /*long*/ widget, int /*long*/ button, int /*long*/ activate_time) {
- sendEvent (SWT.MenuDetect);
- return 0;
-}
-
-void hookEvents () {
- if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
- OS.g_signal_connect_closure (handle, OS.activate, display.closures [ACTIVATE], false);
- OS.g_signal_connect_closure (handle, OS.popup_menu, display.closures [STATUS_ICON_POPUP_MENU], false);
- } else {
- int eventMask = OS.GDK_BUTTON_PRESS_MASK;
- OS.gtk_widget_add_events (handle, eventMask);
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false);
- OS.g_signal_connect_closure_by_id (imageHandle, display.signalIds [SIZE_ALLOCATE], 0, display.closures [SIZE_ALLOCATE], false);
- }
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and
- * <code>false</code> otherwise.
- *
- * @return the receiver's visibility
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
- return OS.gtk_status_icon_get_visible (handle);
- }
- return OS.GTK_WIDGET_VISIBLE (handle);
-}
-
-void register () {
- super.register ();
- display.addWidget (imageHandle, this);
-}
-
-void releaseHandle () {
- if (handle != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
- OS.g_object_unref (handle);
- } else {
- OS.gtk_widget_destroy (handle);
- }
- }
- handle = imageHandle = 0;
- super.releaseHandle ();
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (tooltipsHandle != 0) OS.g_object_unref (tooltipsHandle);
- tooltipsHandle = 0;
- if (imageList != null) imageList.dispose ();
- imageList = null;
- toolTipText = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the platform-specific context menu trigger has
- * occurred.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #addMenuDetectListener
- *
- * @since 3.3
- */
-public void removeMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MenuDetect, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection, listener);
-}
-
-/**
- * Sets the receiver's image.
- *
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- this.image = image;
- if (image != null) {
- if (imageList == null) imageList = new ImageList ();
- int imageIndex = imageList.indexOf (image);
- if (imageIndex == -1) {
- imageIndex = imageList.add (image);
- } else {
- imageList.put (imageIndex, image);
- }
- int /*long*/ pixbuf = imageList.getPixbuf (imageIndex);
- if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
- OS.gtk_status_icon_set_from_pixbuf (handle, pixbuf);
- OS.gtk_status_icon_set_visible (handle, true);
- } else {
- Rectangle rect = image.getBounds ();
- OS.gtk_widget_set_size_request (handle, rect.width, rect.height);
- OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf);
- OS.gtk_widget_show (imageHandle);
- }
- } else {
- OS.gtk_widget_set_size_request (handle, 1, 1);
- if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
- OS.gtk_status_icon_set_from_pixbuf (handle, 0);
- OS.gtk_status_icon_set_visible (handle, false);
- } else {
- OS.gtk_image_set_from_pixbuf (imageHandle, 0);
- OS.gtk_widget_hide (imageHandle);
- }
- }
-}
-
-/**
- * Sets the receiver's tool tip to the argument, which
- * may be null indicating that no tool tip should be shown.
- *
- * @param toolTip the new tool tip (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setToolTip (ToolTip toolTip) {
- checkWidget ();
- ToolTip oldTip = this.toolTip, newTip = toolTip;
- if (oldTip != null) oldTip.item = null;
- this.toolTip = newTip;
- if (newTip != null) newTip.item = this;
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget ();
- toolTipText = string;
- byte [] buffer = null;
- if (string != null && string.length () > 0) {
- buffer = Converter.wcsToMbcs (null, string, true);
- }
- if (tooltipsHandle == 0) {
- tooltipsHandle = OS.gtk_tooltips_new ();
- if (tooltipsHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.g_object_ref (tooltipsHandle);
- OS.gtk_object_sink (tooltipsHandle);
- }
- if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
- OS.gtk_status_icon_set_tooltip (handle, buffer);
- } else
- OS.gtk_tooltips_set_tip (tooltipsHandle, handle, buffer, null);
-}
-
-/**
- * Makes the receiver visible if the argument is <code>true</code>,
- * and makes it invisible otherwise.
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
- if(OS.gtk_status_icon_get_visible (handle) == visible) return;
- } else {
- if (OS.GTK_WIDGET_VISIBLE (handle) == visible) return;
- }
- if (visible) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the show
- * event. If this happens, just return.
- */
- sendEvent (SWT.Show);
- if (isDisposed ()) return;
- if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
- OS.gtk_status_icon_set_visible (handle, visible);
- } else
- OS.gtk_widget_show (handle);
- } else {
- if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) {
- OS.gtk_status_icon_set_visible (handle, visible);
- } else
- OS.gtk_widget_hide (handle);
- sendEvent (SWT.Hide);
- }
-}
-} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java
deleted file mode 100644
index e6a26ce1b0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java
+++ /dev/null
@@ -1,3385 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class provide a selectable user interface object
- * that displays a hierarchy of items and issues notification when an
- * item in the hierarchy is selected.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TreeItem</code>.
- * </p><p>
- * Style <code>VIRTUAL</code> is used to create a <code>Tree</code> whose
- * <code>TreeItem</code>s are to be populated by the client on an on-demand basis
- * instead of up-front. This can provide significant performance improvements for
- * trees that are very large or for which <code>TreeItem</code> population is
- * expensive (for example, retrieving values from an external source).
- * </p><p>
- * Here is an example of using a <code>Tree</code> with style <code>VIRTUAL</code>:
- * <code><pre>
- * final Tree tree = new Tree(parent, SWT.VIRTUAL | SWT.BORDER);
- * tree.setItemCount(20);
- * tree.addListener(SWT.SetData, new Listener() {
- * public void handleEvent(Event event) {
- * TreeItem item = (TreeItem)event.item;
- * TreeItem parentItem = item.getParentItem();
- * String text = null;
- * if (parentItem == null) {
- * text = "node " + tree.indexOf(item);
- * } else {
- * text = parentItem.getText() + " - " + parentItem.indexOf(item);
- * }
- * item.setText(text);
- * System.out.println(text);
- * item.setItemCount(10);
- * }
- * });
- * </pre></code>
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not normally make sense to add <code>Control</code> children to
- * it, or set a layout on it, unless implementing something like a cell
- * editor.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, VIRTUAL, NO_SCROLL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection, Collapse, Expand, SetData, MeasureItem, EraseItem, PaintItem</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles SINGLE and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Tree extends Composite {
- int /*long*/ modelHandle, checkRenderer;
- int columnCount, sortDirection;
- int /*long*/ ignoreCell;
- TreeItem[] items;
- TreeColumn [] columns;
- TreeColumn sortColumn;
- TreeItem currentItem;
- ImageList imageList, headerImageList;
- boolean firstCustomDraw;
- boolean modelChanged;
- boolean expandAll;
- int drawState, drawFlags;
- GdkColor drawForeground;
- boolean ownerDraw, ignoreSize, ignoreAccessibility;
-
- static final int ID_COLUMN = 0;
- static final int CHECKED_COLUMN = 1;
- static final int GRAYED_COLUMN = 2;
- static final int FOREGROUND_COLUMN = 3;
- static final int BACKGROUND_COLUMN = 4;
- static final int FONT_COLUMN = 5;
- static final int FIRST_COLUMN = FONT_COLUMN + 1;
- static final int CELL_PIXBUF = 0;
- static final int CELL_TEXT = 1;
- static final int CELL_FOREGROUND = 2;
- static final int CELL_BACKGROUND = 3;
- static final int CELL_FONT = 4;
- static final int CELL_TYPES = CELL_FONT + 1;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#CHECK
- * @see SWT#FULL_SELECTION
- * @see SWT#VIRTUAL
- * @see SWT#NO_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Tree (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-void _addListener (int eventType, Listener listener) {
- super._addListener (eventType, listener);
- if (!ownerDraw) {
- switch (eventType) {
- case SWT.MeasureItem:
- case SWT.EraseItem:
- case SWT.PaintItem:
- ownerDraw = true;
- recreateRenderers ();
- break;
- }
- }
-}
-
-TreeItem _getItem (int /*long*/ iter) {
- int id = getId (iter, true);
- if (items [id] != null) return items [id];
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter);
- int depth = OS.gtk_tree_path_get_depth (path);
- int [] indices = new int [depth];
- OS.memmove (indices, OS.gtk_tree_path_get_indices (path), 4*depth);
- int /*long*/ parentIter = 0;
- if (depth > 1) {
- OS.gtk_tree_path_up (path);
- parentIter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- OS.gtk_tree_model_get_iter (modelHandle, parentIter, path);
- }
- items [id] = new TreeItem (this, parentIter, SWT.NONE, indices [indices.length -1], false);
- OS.gtk_tree_path_free (path);
- if (parentIter != 0) OS.g_free (parentIter);
- return items [id];
-}
-
-TreeItem _getItem (int /*long*/ parentIter, int index) {
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- OS.gtk_tree_model_iter_nth_child(modelHandle, iter, parentIter, index);
- int id = getId (iter, true);
- OS.g_free (iter);
- if (items [id] != null) return items [id];
- return items [id] = new TreeItem (this, parentIter, SWT.NONE, index, false);
-}
-
-int getId (int /*long*/ iter, boolean queryModel) {
- if (queryModel) {
- int[] value = new int[1];
- OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, value, -1);
- if (value [0] != -1) return value [0];
- }
- // find next available id
- int id = 0;
- while (id < items.length && items [id] != null) id++;
- if (id == items.length) {
- TreeItem [] newItems = new TreeItem [items.length + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- OS.gtk_tree_store_set (modelHandle, iter, ID_COLUMN, id, -1);
- return id;
-}
-
-static int checkStyle (int style) {
- /*
- * Feature in Windows. Even when WS_HSCROLL or
- * WS_VSCROLL is not specified, Windows creates
- * trees and tables with scroll bars. The fix
- * is to set H_SCROLL and V_SCROLL.
- *
- * NOTE: This code appears on all platforms so that
- * applications have consistent scroll bar behavior.
- */
- if ((style & SWT.NO_SCROLL) == 0) {
- style |= SWT.H_SCROLL | SWT.V_SCROLL;
- }
- /* GTK is always FULL_SELECTION */
- style |= SWT.FULL_SELECTION;
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-
-int /*long*/ cellDataProc (int /*long*/ tree_column, int /*long*/ cell, int /*long*/ tree_model, int /*long*/ iter, int /*long*/ data) {
- if (cell == ignoreCell) return 0;
- TreeItem item = _getItem (iter);
- if (item != null) OS.g_object_set_qdata (cell, Display.SWT_OBJECT_INDEX2, item.handle);
- boolean isPixbuf = OS.GTK_IS_CELL_RENDERER_PIXBUF (cell);
- if (!(isPixbuf || OS.GTK_IS_CELL_RENDERER_TEXT (cell))) return 0;
- int modelIndex = -1;
- boolean customDraw = false;
- if (columnCount == 0) {
- modelIndex = Tree.FIRST_COLUMN;
- customDraw = firstCustomDraw;
- } else {
- TreeColumn column = (TreeColumn) display.getWidget (tree_column);
- if (column != null) {
- modelIndex = column.modelIndex;
- customDraw = column.customDraw;
- }
- }
- if (modelIndex == -1) return 0;
- boolean setData = false;
- if ((style & SWT.VIRTUAL) != 0) {
- /*
- * Feature in GTK. On GTK before 2.4, fixed_height_mode is not
- * supported, and the tree asks for the data of all items. The
- * fix is to only provide the data if the row is visible.
- */
- if (OS.GTK_VERSION < OS.VERSION (2, 3, 2)) {
- int /*long*/ path = OS.gtk_tree_model_get_path (tree_model, iter);
- OS.gtk_widget_realize (handle);
- GdkRectangle visible = new GdkRectangle ();
- OS.gtk_tree_view_get_visible_rect (handle, visible);
- GdkRectangle area = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (handle, path, tree_column, area);
- OS.gtk_tree_path_free (path);
- if (area.y + area.height < 0 || area.y + visible.y > visible.y + visible.height ) {
- /* Give an image from the image list to make sure the row has
- * the correct height.
- */
- if (imageList != null && imageList.pixbufs.length > 0) {
- if (isPixbuf) OS.g_object_set (cell, OS.pixbuf, imageList.pixbufs [0], 0);
- }
- return 0;
- }
- }
- if (!item.cached) {
- //lastIndexOf = index [0];
- setData = checkData (item);
- }
- }
- int /*long*/ [] ptr = new int /*long*/ [1];
- if (setData) {
- if (isPixbuf) {
- ptr [0] = 0;
- OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_PIXBUF, ptr, -1);
- OS.g_object_set (cell, OS.pixbuf, ptr[0], 0);
- } else {
- ptr [0] = 0;
- OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_TEXT, ptr, -1);
- if (ptr [0] != 0) {
- OS.g_object_set (cell, OS.text, ptr[0], 0);
- OS.g_free (ptr[0]);
- }
- }
- }
- if (customDraw) {
- /*
- * Bug on GTK. Gtk renders the background on top of the checkbox and pixbuf.
- * This only happens in version 2.2.1 and earlier. The fix is not to set the background.
- */
- if (OS.GTK_VERSION > OS.VERSION (2, 2, 1)) {
- if (!ownerDraw) {
- ptr [0] = 0;
- OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_BACKGROUND, ptr, -1);
- if (ptr [0] != 0) {
- OS.g_object_set (cell, OS.cell_background_gdk, ptr[0], 0);
- }
- }
- }
- if (!isPixbuf) {
- ptr [0] = 0;
- OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_FOREGROUND, ptr, -1);
- if (ptr [0] != 0) {
- OS.g_object_set (cell, OS.foreground_gdk, ptr[0], 0);
- }
- ptr [0] = 0;
- OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_FONT, ptr, -1);
- if (ptr [0] != 0) {
- OS.g_object_set (cell, OS.font_desc, ptr[0], 0);
- }
- }
- }
- if (setData) {
- ignoreCell = cell;
- setScrollWidth (tree_column, item);
- ignoreCell = 0;
- }
- return 0;
-}
-
-boolean checkData (TreeItem item) {
- if (item.cached) return true;
- if ((style & SWT.VIRTUAL) != 0) {
- item.cached = true;
- TreeItem parentItem = item.getParentItem ();
- Event event = new Event ();
- event.item = item;
- event.index = parentItem == null ? indexOf (item) : parentItem.indexOf (item);
- int mask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID;
- int signal_id = OS.g_signal_lookup (OS.row_changed, OS.gtk_tree_model_get_type ());
- OS.g_signal_handlers_block_matched (modelHandle, mask, signal_id, 0, 0, 0, handle);
- currentItem = item;
- sendEvent (SWT.SetData, event);
- currentItem = null;
- //widget could be disposed at this point
- if (isDisposed ()) return false;
- OS.g_signal_handlers_unblock_matched (modelHandle, mask, signal_id, 0, 0, 0, handle);
- if (item.isDisposed ()) return false;
- }
- return true;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * If the receiver has the <code>SWT.CHECK</code> style and the check selection changes,
- * the event object detail field contains the value <code>SWT.CHECK</code>.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * The item field of the event object is valid for default selection, but the detail field is not used.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an item in the receiver is expanded or collapsed
- * by sending it one of the messages defined in the <code>TreeListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TreeListener
- * @see #removeTreeListener
- */
-public void addTreeListener(TreeListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Expand, typedListener);
- addListener (SWT.Collapse, typedListener);
-}
-
-int calculateWidth (int /*long*/ column, int /*long*/ iter, boolean recurse) {
- OS.gtk_tree_view_column_cell_set_cell_data (column, modelHandle, iter, false, false);
- /*
- * Bug in GTK. The width calculated by gtk_tree_view_column_cell_get_size()
- * always grows in size regardless of the text or images in the table.
- * The fix is to determine the column width from the cell renderers.
- */
- // Code intentionally commented
- //int [] width = new int [1];
- //OS.gtk_tree_view_column_cell_get_size (column, null, null, null, width, null);
- //return width [0];
-
- int width = 0;
- int [] w = new int [1];
- int /*long*/ path = 0;
-
- if (OS.gtk_tree_view_get_expander_column (handle) == column) {
- /* indent */
- GdkRectangle rect = new GdkRectangle ();
- OS.gtk_widget_realize (handle);
- path = OS.gtk_tree_model_get_path (modelHandle, iter);
- OS.gtk_tree_view_get_cell_area (handle, path, column, rect);
- width += rect.x;
- /* expander */
- OS.gtk_widget_style_get (handle, OS.expander_size, w, 0);
- width += w [0] + TreeItem.EXPANDER_EXTRA_PADDING;
- }
- OS.gtk_widget_style_get(handle, OS.focus_line_width, w, 0);
- width += 2 * w [0];
- int /*long*/ list = OS.gtk_tree_view_column_get_cell_renderers (column);
- if (list == 0) return 0;
- int /*long*/ temp = list;
- while (temp != 0) {
- int /*long*/ renderer = OS.g_list_data (temp);
- if (renderer != 0) {
- OS.gtk_cell_renderer_get_size (renderer, handle, null, null, null, w, null);
- width += w [0];
- }
- temp = OS.g_list_next (temp);
- }
- OS.g_list_free (list);
-
- if (recurse) {
- if (path == 0) path = OS.gtk_tree_model_get_path (modelHandle, iter);
- boolean expanded = OS.gtk_tree_view_row_expanded (handle, path);
- if (expanded) {
- int /*long*/ childIter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- boolean valid = OS.gtk_tree_model_iter_children (modelHandle, childIter, iter);
- while (valid) {
- width = Math.max (width, calculateWidth (column, childIter, true));
- valid = OS.gtk_tree_model_iter_next (modelHandle, childIter);
- }
- OS.g_free (childIter);
- }
- }
-
- if (path != 0) OS.gtk_tree_path_free (path);
- if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0) && OS.gtk_tree_view_get_rules_hint (handle)) {
- OS.gtk_widget_style_get (handle, OS.grid_line_width, w, 0) ;
- width += 2 * w [0];
- }
- return width;
-}
-
-/**
- * Clears the item at the given zero-relative index in the receiver.
- * The text, icon and other attributes of the item are set to the default
- * value. If the tree was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param index the index of the item to clear
- * @param all <code>true</code> if all child items of the indexed item should be
- * cleared recursively, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clear(int index, boolean all) {
- checkWidget ();
- clear (0, index, all);
-}
-
-void clear (int /*long*/ parentIter, int index, boolean all) {
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- OS.gtk_tree_model_iter_nth_child(modelHandle, iter, parentIter, index);
- int[] value = new int[1];
- OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, value, -1);
- if (value [0] != -1) {
- TreeItem item = items [value [0]];
- item.clear ();
- }
- if (all) clearAll (all, iter);
- OS.g_free (iter);
-}
-
-/**
- * Clears all the items in the receiver. The text, icon and other
- * attributes of the items are set to their default values. If the
- * tree was created with the <code>SWT.VIRTUAL</code> style, these
- * attributes are requested again as needed.
- *
- * @param all <code>true</code> if all child items should be cleared
- * recursively, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clearAll (boolean all) {
- checkWidget ();
- clearAll (all, 0);
-}
-void clearAll (boolean all, int /*long*/ parentIter) {
- int length = OS.gtk_tree_model_iter_n_children (modelHandle, parentIter);
- if (length == 0) return;
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- boolean valid = OS.gtk_tree_model_iter_children (modelHandle, iter, parentIter);
- int[] value = new int[1];
- while (valid) {
- OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, value, -1);
- if (value [0] != -1) {
- TreeItem item = items [value [0]];
- item.clear ();
- }
- if (all) clearAll (all, iter);
- valid = OS.gtk_tree_model_iter_next (modelHandle, iter);
- }
- OS.g_free (iter);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- Point size = computeNativeSize (handle, wHint, hHint, changed);
- Rectangle trim = computeTrim (0, 0, size.x, size.y);
- size.x = trim.width;
- size.y = trim.height;
- return size;
-}
-
-void copyModel (int /*long*/ oldModel, int oldStart, int /*long*/ newModel, int newStart, int /*long*/ [] types, int /*long*/ oldParent, int /*long*/ newParent, int modelLength) {
- int /*long*/ iter = OS.g_malloc(OS.GtkTreeIter_sizeof ());
- if (OS.gtk_tree_model_iter_children (oldModel, iter, oldParent)) {
- int /*long*/ [] oldItems = new int /*long*/ [OS.gtk_tree_model_iter_n_children (oldModel, oldParent)];
- int oldIndex = 0;
- do {
- int /*long*/ newItem = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (newItem == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_tree_store_append (newModel, newItem, newParent);
- int [] index = new int [1];
- OS.gtk_tree_model_get (oldModel, iter, ID_COLUMN, index, -1);
- TreeItem item = null;
- if (index [0] != -1) {
- item = items [index [0]];
- if (item != null) {
- int /*long*/ oldItem = item.handle;
- oldItems[oldIndex++] = oldItem;
- int /*long*/ [] ptr = new int /*long*/ [1];
- for (int j = 0; j < FIRST_COLUMN; j++) {
- OS.gtk_tree_model_get (oldModel, oldItem, j, ptr, -1);
- OS.gtk_tree_store_set (newModel, newItem, j, ptr [0], -1);
- if (types [j] == OS.G_TYPE_STRING ()) OS.g_free ((ptr [0]));
- }
- for (int j= 0; j<modelLength - FIRST_COLUMN; j++) {
- OS.gtk_tree_model_get (oldModel, oldItem, oldStart + j, ptr, -1);
- OS.gtk_tree_store_set (newModel, newItem, newStart + j, ptr [0], -1);
- if (types [j] == OS.G_TYPE_STRING ()) OS.g_free ((ptr [0]));
- }
- }
- } else {
- OS.gtk_tree_store_set (newModel, newItem, ID_COLUMN, -1, -1);
- }
- // recurse through children
- copyModel(oldModel, oldStart, newModel, newStart, types, iter, newItem, modelLength);
-
- if (item!= null) {
- item.handle = newItem;
- } else {
- OS.g_free (newItem);
- }
- } while (OS.gtk_tree_model_iter_next(oldModel, iter));
- for (int i = 0; i < oldItems.length; i++) {
- int /*long*/ oldItem = oldItems [i];
- if (oldItem != 0) {
- OS.gtk_tree_store_remove (oldModel, oldItem);
- OS.g_free (oldItem);
- }
- }
- }
- OS.g_free (iter);
-}
-
-void createColumn (TreeColumn column, int index) {
-/*
-* Bug in ATK. For some reason, ATK segments fault if
-* the GtkTreeView has a column and does not have items.
-* The fix is to insert the column only when an item is
-* created.
-*/
-
- int modelIndex = FIRST_COLUMN;
- if (columnCount != 0) {
- int modelLength = OS.gtk_tree_model_get_n_columns (modelHandle);
- boolean [] usedColumns = new boolean [modelLength];
- for (int i=0; i<columnCount; i++) {
- int columnIndex = columns [i].modelIndex;
- for (int j = 0; j < CELL_TYPES; j++) {
- usedColumns [columnIndex + j] = true;
- }
- }
- while (modelIndex < modelLength) {
- if (!usedColumns [modelIndex]) break;
- modelIndex++;
- }
- if (modelIndex == modelLength) {
- int /*long*/ oldModel = modelHandle;
- int /*long*/[] types = getColumnTypes (columnCount + 4); // grow by 4 rows at a time
- int /*long*/ newModel = OS.gtk_tree_store_newv (types.length, types);
- if (newModel == 0) error (SWT.ERROR_NO_HANDLES);
- copyModel (oldModel, FIRST_COLUMN, newModel, FIRST_COLUMN, types, (int /*long*/)0, (int /*long*/)0, modelLength);
- OS.gtk_tree_view_set_model (handle, newModel);
- OS.g_object_unref (oldModel);
- modelHandle = newModel;
- }
- }
- int /*long*/ columnHandle = OS.gtk_tree_view_column_new ();
- if (columnHandle == 0) error (SWT.ERROR_NO_HANDLES);
- if (index == 0 && columnCount > 0) {
- TreeColumn checkColumn = columns [0];
- createRenderers (checkColumn.handle, checkColumn.modelIndex, false, checkColumn.style);
- }
- createRenderers (columnHandle, modelIndex, index == 0, column == null ? 0 : column.style);
- /*
- * Use GTK_TREE_VIEW_COLUMN_GROW_ONLY on GTK versions < 2.3.2
- * because fixed_height_mode is not supported.
- */
- boolean useVirtual = (style & SWT.VIRTUAL) != 0 && OS.GTK_VERSION >= OS.VERSION (2, 3, 2);
- if (!useVirtual && columnCount == 0) {
- OS.gtk_tree_view_column_set_sizing (columnHandle, OS.GTK_TREE_VIEW_COLUMN_GROW_ONLY);
- } else {
- OS.gtk_tree_view_column_set_sizing (columnHandle, OS.GTK_TREE_VIEW_COLUMN_FIXED);
- if (columnCount != 0) OS.gtk_tree_view_column_set_visible (columnHandle, false);
- }
- OS.gtk_tree_view_column_set_resizable (columnHandle, true);
- OS.gtk_tree_view_column_set_clickable (columnHandle, true);
- OS.gtk_tree_view_column_set_min_width (columnHandle, 0);
- OS.gtk_tree_view_insert_column (handle, columnHandle, index);
- if (column != null) {
- column.handle = columnHandle;
- column.modelIndex = modelIndex;
- }
- /* Disable searching when using VIRTUAL */
- if ((style & SWT.VIRTUAL) != 0) {
- /*
- * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE)
- * would prevent the user from being able to type in text to search the tree.
- * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive
- * search. This meant that even if FALSE was passed to enable_search, the user
- * can still bring up the search pop up using the keybinding. GTK also introduced
- * the notion of passing a -1 to gtk_set_search_column to disable searching
- * (including the search key binding). The fix is to use the right calls
- * for the right version.
- */
- if (OS.GTK_VERSION >= OS.VERSION (2, 6, 5)) {
- OS.gtk_tree_view_set_search_column (handle, -1);
- } else {
- OS.gtk_tree_view_set_enable_search (handle, false);
- }
- } else {
- /* Set the search column whenever the model changes */
- int firstColumn = columnCount == 0 ? FIRST_COLUMN : columns [0].modelIndex;
- OS.gtk_tree_view_set_search_column (handle, firstColumn + CELL_TEXT);
- }
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
- if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_fixed_set_has_window (fixedHandle, true);
- scrolledHandle = OS.gtk_scrolled_window_new (0, 0);
- if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ [] types = getColumnTypes (1);
- modelHandle = OS.gtk_tree_store_newv (types.length, types);
- if (modelHandle == 0) error (SWT.ERROR_NO_HANDLES);
- handle = OS.gtk_tree_view_new_with_model (modelHandle);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.CHECK) != 0) {
- checkRenderer = OS.gtk_cell_renderer_toggle_new ();
- if (checkRenderer == 0) error (SWT.ERROR_NO_HANDLES);
- OS.g_object_ref (checkRenderer);
- }
- createColumn (null, 0);
- OS.gtk_container_add (fixedHandle, scrolledHandle);
- OS.gtk_container_add (scrolledHandle, handle);
-
- int mode = (style & SWT.MULTI) != 0 ? OS.GTK_SELECTION_MULTIPLE : OS.GTK_SELECTION_BROWSE;
- int /*long*/ selectionHandle = OS.gtk_tree_view_get_selection (handle);
- OS.gtk_tree_selection_set_mode (selectionHandle, mode);
- OS.gtk_tree_view_set_headers_visible (handle, false);
- int hsp = (style & SWT.H_SCROLL) != 0 ? OS.GTK_POLICY_AUTOMATIC : OS.GTK_POLICY_NEVER;
- int vsp = (style & SWT.V_SCROLL) != 0 ? OS.GTK_POLICY_AUTOMATIC : OS.GTK_POLICY_NEVER;
- OS.gtk_scrolled_window_set_policy (scrolledHandle, hsp, vsp);
- if ((style & SWT.BORDER) != 0) OS.gtk_scrolled_window_set_shadow_type (scrolledHandle, OS.GTK_SHADOW_ETCHED_IN);
- /* Disable searching when using VIRTUAL */
- if ((style & SWT.VIRTUAL) != 0) {
- /* The fixed_height_mode property only exists in GTK 2.3.2 and greater */
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2)) {
- OS.g_object_set (handle, OS.fixed_height_mode, true, 0);
- }
- /*
- * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE)
- * would prevent the user from being able to type in text to search the tree.
- * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive
- * search. This meant that even if FALSE was passed to enable_search, the user
- * can still bring up the search pop up using the keybinding. GTK also introduced
- * the notion of passing a -1 to gtk_set_search_column to disable searching
- * (including the search key binding). The fix is to use the right calls
- * for the right version.
- */
- if (OS.GTK_VERSION >= OS.VERSION (2, 6, 5)) {
- OS.gtk_tree_view_set_search_column (handle, -1);
- } else {
- OS.gtk_tree_view_set_enable_search (handle, false);
- };
- }
-}
-
-void createItem (TreeColumn column, int index) {
- if (!(0 <= index && index <= columnCount)) error (SWT.ERROR_INVALID_RANGE);
- if (index == 0) {
- // first column must be left aligned
- column.style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- column.style |= SWT.LEFT;
- }
- if (columnCount == 0) {
- column.handle = OS.gtk_tree_view_get_column (handle, 0);
- OS.gtk_tree_view_column_set_sizing (column.handle, OS.GTK_TREE_VIEW_COLUMN_FIXED);
- OS.gtk_tree_view_column_set_visible (column.handle, false);
- column.modelIndex = FIRST_COLUMN;
- createRenderers (column.handle, column.modelIndex, true, column.style);
- column.customDraw = firstCustomDraw;
- firstCustomDraw = false;
- } else {
- createColumn (column, index);
- }
- int /*long*/ boxHandle = OS.gtk_hbox_new (false, 3);
- if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ labelHandle = OS.gtk_label_new_with_mnemonic (null);
- if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ imageHandle = OS.gtk_image_new ();
- if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_container_add (boxHandle, imageHandle);
- OS.gtk_container_add (boxHandle, labelHandle);
- OS.gtk_widget_show (boxHandle);
- OS.gtk_widget_show (labelHandle);
- column.labelHandle = labelHandle;
- column.imageHandle = imageHandle;
- OS.gtk_tree_view_column_set_widget (column.handle, boxHandle);
- int /*long*/ widget = OS.gtk_widget_get_parent (boxHandle);
- while (widget != handle) {
- if (OS.GTK_IS_BUTTON (widget)) {
- column.buttonHandle = widget;
- break;
- }
- widget = OS.gtk_widget_get_parent (widget);
- }
- if (columnCount == columns.length) {
- TreeColumn [] newColumns = new TreeColumn [columns.length + 4];
- System.arraycopy (columns, 0, newColumns, 0, columns.length);
- columns = newColumns;
- }
- System.arraycopy (columns, index, columns, index + 1, columnCount++ - index);
- columns [index] = column;
- if ((state & FONT) != 0) {
- column.setFontDescription (getFontDescription ());
- }
- if (columnCount >= 1) {
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null) {
- Font [] cellFont = item.cellFont;
- if (cellFont != null) {
- Font [] temp = new Font [columnCount];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index, temp, index+1, columnCount-index-1);
- item.cellFont = temp;
- }
- }
- }
- }
-}
-
-void createItem (TreeItem item, int /*long*/ parentIter, int index) {
- int count = OS.gtk_tree_model_iter_n_children (modelHandle, parentIter);
- if (index == -1) index = count;
- if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
- item.handle = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (item.handle == 0) error(SWT.ERROR_NO_HANDLES);
- /*
- * Feature in GTK. It is much faster to append to a tree store
- * than to insert at the end using gtk_tree_store_insert().
- */
- if (index == count) {
- OS.gtk_tree_store_append (modelHandle, item.handle, parentIter);
- } else {
- OS.gtk_tree_store_insert (modelHandle, item.handle, parentIter, index);
- }
- int id = getId (item.handle, false);
- items [id] = item;
- modelChanged = true;
-}
-
-void createRenderers (int /*long*/ columnHandle, int modelIndex, boolean check, int columnStyle) {
- OS.gtk_tree_view_column_clear (columnHandle);
- if ((style & SWT.CHECK) != 0 && check) {
- OS.gtk_tree_view_column_pack_start (columnHandle, checkRenderer, false);
- OS.gtk_tree_view_column_add_attribute (columnHandle, checkRenderer, OS.active, CHECKED_COLUMN);
- /*
- * Feature in GTK. The inconsistent property only exists in GTK 2.2.x.
- */
- if (OS.GTK_VERSION >= OS.VERSION (2, 2, 0)) {
- OS.gtk_tree_view_column_add_attribute (columnHandle, checkRenderer, OS.inconsistent, GRAYED_COLUMN);
- }
- /*
- * Bug in GTK. GTK renders the background on top of the checkbox.
- * This only happens in version 2.2.1 and earlier. The fix is not to set the background.
- */
- if (OS.GTK_VERSION > OS.VERSION (2, 2, 1)) {
- if (!ownerDraw) OS.gtk_tree_view_column_add_attribute (columnHandle, checkRenderer, OS.cell_background_gdk, BACKGROUND_COLUMN);
- }
- if (ownerDraw) {
- OS.gtk_tree_view_column_set_cell_data_func (columnHandle, checkRenderer, display.cellDataProc, handle, 0);
- OS.g_object_set_qdata (checkRenderer, Display.SWT_OBJECT_INDEX1, columnHandle);
- }
- }
- int /*long*/ pixbufRenderer = ownerDraw ? OS.g_object_new (display.gtk_cell_renderer_pixbuf_get_type (), 0) : OS.gtk_cell_renderer_pixbuf_new ();
- if (pixbufRenderer == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ textRenderer = ownerDraw ? OS.g_object_new (display.gtk_cell_renderer_text_get_type (), 0) : OS.gtk_cell_renderer_text_new ();
- if (textRenderer == 0) error (SWT.ERROR_NO_HANDLES);
-
- if (ownerDraw) {
- OS.g_object_set_qdata (pixbufRenderer, Display.SWT_OBJECT_INDEX1, columnHandle);
- OS.g_object_set_qdata (textRenderer, Display.SWT_OBJECT_INDEX1, columnHandle);
- }
-
- /*
- * Feature in GTK. When a tree view column contains only one activatable
- * cell renderer such as a toggle renderer, mouse clicks anywhere in a cell
- * activate that renderer. The workaround is to set a second cell renderer
- * to be activatable.
- */
- if ((style & SWT.CHECK) != 0 && check) {
- OS.g_object_set (pixbufRenderer, OS.mode, OS.GTK_CELL_RENDERER_MODE_ACTIVATABLE, 0);
- }
-
- /* Set alignment */
- if ((columnStyle & SWT.RIGHT) != 0) {
- OS.g_object_set(textRenderer, OS.xalign, 1f, 0);
- OS.gtk_tree_view_column_pack_end (columnHandle, textRenderer, true);
- OS.gtk_tree_view_column_pack_end (columnHandle, pixbufRenderer, false);
- OS.gtk_tree_view_column_set_alignment (columnHandle, 1f);
- } else if ((columnStyle & SWT.CENTER) != 0) {
- OS.g_object_set(textRenderer, OS.xalign, 0.5f, 0);
- OS.gtk_tree_view_column_pack_start (columnHandle, pixbufRenderer, false);
- OS.gtk_tree_view_column_pack_end (columnHandle, textRenderer, true);
- OS.gtk_tree_view_column_set_alignment (columnHandle, 0.5f);
- } else {
- OS.gtk_tree_view_column_pack_start (columnHandle, pixbufRenderer, false);
- OS.gtk_tree_view_column_pack_start (columnHandle, textRenderer, true);
- OS.gtk_tree_view_column_set_alignment (columnHandle, 0f);
- }
-
- /* Add attributes */
- OS.gtk_tree_view_column_add_attribute (columnHandle, pixbufRenderer, OS.pixbuf, modelIndex + CELL_PIXBUF);
- /*
- * Bug on GTK. Gtk renders the background on top of the pixbuf.
- * This only happens in version 2.2.1 and earlier. The fix is not to set the background.
- */
- if (OS.GTK_VERSION > OS.VERSION (2, 2, 1)) {
- if (!ownerDraw) {
- OS.gtk_tree_view_column_add_attribute (columnHandle, pixbufRenderer, OS.cell_background_gdk, BACKGROUND_COLUMN);
- OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.cell_background_gdk, BACKGROUND_COLUMN);
- }
- }
- OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.text, modelIndex + CELL_TEXT);
- OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.foreground_gdk, FOREGROUND_COLUMN);
- OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.font_desc, FONT_COLUMN);
-
- boolean customDraw = firstCustomDraw;
- if (columnCount != 0) {
- for (int i=0; i<columnCount; i++) {
- if (columns [i].handle == columnHandle) {
- customDraw = columns [i].customDraw;
- break;
- }
- }
- }
- if ((style & SWT.VIRTUAL) != 0 || customDraw || ownerDraw) {
- OS.gtk_tree_view_column_set_cell_data_func (columnHandle, textRenderer, display.cellDataProc, handle, 0);
- OS.gtk_tree_view_column_set_cell_data_func (columnHandle, pixbufRenderer, display.cellDataProc, handle, 0);
- }
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- items = new TreeItem [4];
- columns = new TreeColumn [4];
- columnCount = 0;
-}
-
-GdkColor defaultBackground () {
- return display.COLOR_LIST_BACKGROUND;
-}
-
-GdkColor defaultForeground () {
- return display.COLOR_LIST_FOREGROUND;
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (OS.gtk_tree_view_get_selection (handle));
- if (checkRenderer != 0) display.removeWidget (checkRenderer);
- display.removeWidget (modelHandle);
-}
-
-/**
- * Deselects an item in the receiver. If the item was already
- * deselected, it remains deselected.
- *
- * @param item the item to be deselected
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void deselect (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean fixColumn = showFirstColumn ();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_selection_unselect_iter (selection, item.handle);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- if (fixColumn) hideFirstColumn ();
-}
-
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll() {
- checkWidget();
- boolean fixColumn = showFirstColumn ();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_selection_unselect_all (selection);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- if (fixColumn) hideFirstColumn ();
-}
-
-void destroyItem (TreeColumn column) {
- int index = 0;
- while (index < columnCount) {
- if (columns [index] == column) break;
- index++;
- }
- if (index == columnCount) return;
- int /*long*/ columnHandle = column.handle;
- if (columnCount == 1) {
- firstCustomDraw = column.customDraw;
- }
- System.arraycopy (columns, index + 1, columns, index, --columnCount - index);
- columns [columnCount] = null;
- OS.gtk_tree_view_remove_column (handle, columnHandle);
- if (columnCount == 0) {
- int /*long*/ oldModel = modelHandle;
- int /*long*/[] types = getColumnTypes (1);
- int /*long*/ newModel = OS.gtk_tree_store_newv (types.length, types);
- if (newModel == 0) error (SWT.ERROR_NO_HANDLES);
- copyModel(oldModel, column.modelIndex, newModel, FIRST_COLUMN, types, (int /*long*/)0, (int /*long*/)0, FIRST_COLUMN + CELL_TYPES);
- OS.gtk_tree_view_set_model (handle, newModel);
- OS.g_object_unref (oldModel);
- modelHandle = newModel;
- createColumn (null, 0);
-
- } else {
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null) {
- int /*long*/ iter = item.handle;
- int modelIndex = column.modelIndex;
- OS.gtk_tree_store_set (modelHandle, iter, modelIndex + CELL_PIXBUF, 0, -1);
- OS.gtk_tree_store_set (modelHandle, iter, modelIndex + CELL_TEXT, 0, -1);
- OS.gtk_tree_store_set (modelHandle, iter, modelIndex + CELL_FOREGROUND, 0, -1);
- OS.gtk_tree_store_set (modelHandle, iter, modelIndex + CELL_BACKGROUND, 0, -1);
- OS.gtk_tree_store_set (modelHandle, iter, modelIndex + CELL_FONT, 0, -1);
-
- Font [] cellFont = item.cellFont;
- if (cellFont != null) {
- if (columnCount == 0) {
- item.cellFont = null;
- } else {
- Font [] temp = new Font [columnCount];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index + 1, temp, index, columnCount - index);
- item.cellFont = temp;
- }
- }
- }
- }
- if (index == 0) {
- // first column must be left aligned and must show check box
- TreeColumn firstColumn = columns [0];
- firstColumn.style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- firstColumn.style |= SWT.LEFT;
- createRenderers (firstColumn.handle, firstColumn.modelIndex, true, firstColumn.style);
- }
- }
- /* Disable searching when using VIRTUAL */
- if ((style & SWT.VIRTUAL) != 0) {
- /*
- * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE)
- * would prevent the user from being able to type in text to search the tree.
- * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive
- * search. This meant that even if FALSE was passed to enable_search, the user
- * can still bring up the search pop up using the keybinding. GTK also introduced
- * the notion of passing a -1 to gtk_set_search_column to disable searching
- * (including the search key binding). The fix is to use the right calls
- * for the right version.
- */
- if (OS.GTK_VERSION >= OS.VERSION (2, 6, 5)) {
- OS.gtk_tree_view_set_search_column (handle, -1);
- } else {
- OS.gtk_tree_view_set_enable_search (handle, false);
- }
- } else {
- /* Set the search column whenever the model changes */
- int firstColumn = columnCount == 0 ? FIRST_COLUMN : columns [0].modelIndex;
- OS.gtk_tree_view_set_search_column (handle, firstColumn + CELL_TEXT);
- }
-}
-
-
-void destroyItem (TreeItem item) {
- /*
- * Bug in GTK. GTK segment faults when a root tree item
- * is destroyed when the tree is expanded and the last leaf of
- * the root is selected. This only happens in versions earlier
- * than 2.0.6. The fix is to collapse the tree item being destroyed
- * when it is a root, before it is destroyed.
- */
- if (OS.GTK_VERSION < OS.VERSION (2, 0, 6)) {
- int length = OS.gtk_tree_model_iter_n_children (modelHandle, 0);
- if (length > 0) {
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- boolean valid = OS.gtk_tree_model_iter_children (modelHandle, iter, 0);
- while (valid) {
- if (item.handle == iter) {
- item.setExpanded (false);
- break;
- }
- valid = OS.gtk_tree_model_iter_next (modelHandle, iter);
- }
- OS.g_free (iter);
- }
- }
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_store_remove (modelHandle, item.handle);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- modelChanged = true;
-}
-
-boolean dragDetect (int x, int y, boolean filter, boolean [] consume) {
- boolean selected = false;
- if (filter) {
- int /*long*/ [] path = new int /*long*/ [1];
- if (OS.gtk_tree_view_get_path_at_pos (handle, x, y, path, null, null, null)) {
- if (path [0] != 0) {
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- if (OS.gtk_tree_selection_path_is_selected (selection, path [0])) selected = true;
- OS.gtk_tree_path_free (path [0]);
- }
- } else {
- return false;
- }
- }
- boolean dragDetect = super.dragDetect (x, y, filter, consume);
- if (dragDetect && selected && consume != null) consume [0] = true;
- return dragDetect;
-}
-
-int /*long*/ eventWindow () {
- return paintWindow ();
-}
-
-boolean fixAccessibility () {
- /*
- * Bug in GTK. With GTK 2.12, when assistive technologies is on, the time
- * it takes to add or remove several rows to the model is very long. This
- * happens because the accessible object asks each row for its data, including
- * the rows that are not visible. The the fix is to block the accessible object
- * from receiving row_added and row_removed signals and, at the end, send only
- * a notify signal with the "model" detail.
- *
- * Note: The test bellow has to be updated when the real problem is fixed in
- * the accessible object.
- */
- return OS.GTK_VERSION >= OS.VERSION (2, 12, 0);
-}
-
-void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) {
- super.fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
- for (int i=0; i<columnCount; i++) {
- TreeColumn column = columns [i];
- if (column.toolTipText != null) {
- column.setToolTipText(oldShell, null);
- column.setToolTipText(newShell, column.toolTipText);
- }
- }
-}
-
-GdkColor getBackgroundColor () {
- return getBaseColor ();
-}
-
-public Rectangle getClientArea () {
- checkWidget ();
- forceResize ();
- OS.gtk_widget_realize (handle);
- int /*long*/ fixedWindow = OS.GTK_WIDGET_WINDOW (fixedHandle);
- int /*long*/ binWindow = OS.gtk_tree_view_get_bin_window (handle);
- int [] binX = new int [1], binY = new int [1];
- OS.gdk_window_get_origin (binWindow, binX, binY);
- int [] fixedX = new int [1], fixedY = new int [1];
- OS.gdk_window_get_origin (fixedWindow, fixedX, fixedY);
- int /*long*/ clientHandle = clientHandle ();
- int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (clientHandle);
- int height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (clientHandle);
- return new Rectangle (fixedX [0] - binX [0], fixedY [0] - binY [0], width, height);
-}
-
-int getClientWidth () {
- int [] w = new int [1], h = new int [1];
- OS.gtk_widget_realize (handle);
- OS.gdk_drawable_get_size(OS.gtk_tree_view_get_bin_window(handle), w, h);
- return w[0];
-}
-
-/**
- * Returns the column at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- * Columns are returned in the order that they were created.
- * If no <code>TreeColumn</code>s were created by the programmer,
- * this method will throw <code>ERROR_INVALID_RANGE</code> despite
- * the fact that a single column of data may be visible in the tree.
- * This occurs when the programmer uses the tree like a list, adding
- * items but never creating a column.
- *
- * @param index the index of the column to return
- * @return the column at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public TreeColumn getColumn (int index) {
- checkWidget();
- if (!(0 <= index && index < columnCount)) error (SWT.ERROR_INVALID_RANGE);
- return columns [index];
-}
-
-/**
- * Returns the number of columns contained in the receiver.
- * If no <code>TreeColumn</code>s were created by the programmer,
- * this value is zero, despite the fact that visually, one column
- * of items may be visible. This occurs when the programmer uses
- * the tree like a list, adding items but never creating a column.
- *
- * @return the number of columns
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getColumnCount () {
- checkWidget();
- return columnCount;
-}
-
-/**
- * Returns an array of zero-relative integers that map
- * the creation order of the receiver's items to the
- * order in which they are currently being displayed.
- * <p>
- * Specifically, the indices of the returned array represent
- * the current visual order of the items, and the contents
- * of the array represent the creation order of the items.
- * </p><p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the current visual order of the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
-public int [] getColumnOrder () {
- checkWidget ();
- if (columnCount == 0) return new int [0];
- int /*long*/ list = OS.gtk_tree_view_get_columns (handle);
- if (list == 0) return new int [0];
- int i = 0, count = OS.g_list_length (list);
- int [] order = new int [count];
- int /*long*/ temp = list;
- while (temp != 0) {
- int /*long*/ column = OS.g_list_data (temp);
- if (column != 0) {
- for (int j=0; j<columnCount; j++) {
- if (columns [j].handle == column) {
- order [i++] = j;
- break;
- }
- }
- }
- temp = OS.g_list_next (temp);
- }
- OS.g_list_free (list);
- return order;
-}
-
-int /*long*/[] getColumnTypes (int columnCount) {
- int /*long*/[] types = new int /*long*/ [FIRST_COLUMN + (columnCount * CELL_TYPES)];
- // per row data
- types [ID_COLUMN] = OS.G_TYPE_INT ();
- types [CHECKED_COLUMN] = OS.G_TYPE_BOOLEAN ();
- types [GRAYED_COLUMN] = OS.G_TYPE_BOOLEAN ();
- types [FOREGROUND_COLUMN] = OS.GDK_TYPE_COLOR ();
- types [BACKGROUND_COLUMN] = OS.GDK_TYPE_COLOR ();
- types [FONT_COLUMN] = OS.PANGO_TYPE_FONT_DESCRIPTION ();
- // per cell data
- for (int i=FIRST_COLUMN; i<types.length; i+=CELL_TYPES) {
- types [i + CELL_PIXBUF] = OS.GDK_TYPE_PIXBUF ();
- types [i + CELL_TEXT] = OS.G_TYPE_STRING ();
- types [i + CELL_FOREGROUND] = OS.GDK_TYPE_COLOR ();
- types [i + CELL_BACKGROUND] = OS.GDK_TYPE_COLOR ();
- types [i + CELL_FONT] = OS.PANGO_TYPE_FONT_DESCRIPTION ();
- }
- return types;
-}
-
-/**
- * Returns an array of <code>TreeColumn</code>s which are the
- * columns in the receiver. Columns are returned in the order
- * that they were created. If no <code>TreeColumn</code>s were
- * created by the programmer, the array is empty, despite the fact
- * that visually, one column of items may be visible. This occurs
- * when the programmer uses the tree like a list, adding items but
- * never creating a column.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public TreeColumn [] getColumns () {
- checkWidget();
- TreeColumn [] result = new TreeColumn [columnCount];
- System.arraycopy (columns, 0, result, 0, columnCount);
- return result;
-}
-
-TreeItem getFocusItem () {
- int /*long*/ [] path = new int /*long*/ [1];
- OS.gtk_tree_view_get_cursor (handle, path, null);
- if (path [0] == 0) return null;
- TreeItem item = null;
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (OS.gtk_tree_model_get_iter (modelHandle, iter, path [0])) {
- int [] index = new int [1];
- OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, index, -1);
- if (index [0] != -1) item = items [index [0]]; //TODO should we be creating this item when index is -1?
- }
- OS.g_free (iter);
- OS.gtk_tree_path_free (path [0]);
- return item;
-}
-
-GdkColor getForegroundColor () {
- return getTextColor ();
-}
-
-/**
- * Returns the width in pixels of a grid line.
- *
- * @return the width of a grid line in pixels
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getGridLineWidth () {
- checkWidget();
- return 0;
-}
-
-/**
- * Returns the height of the receiver's header
- *
- * @return the height of the header or zero if the header is not visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getHeaderHeight () {
- checkWidget ();
- if (!OS.gtk_tree_view_get_headers_visible (handle)) return 0;
- if (columnCount > 0) {
- GtkRequisition requisition = new GtkRequisition ();
- int height = 0;
- for (int i=0; i<columnCount; i++) {
- int /*long*/ buttonHandle = columns [i].buttonHandle;
- if (buttonHandle != 0) {
- OS.gtk_widget_size_request (buttonHandle, requisition);
- height = Math.max (height, requisition.height);
- }
- }
- return height;
- }
- OS.gtk_widget_realize (handle);
- int /*long*/ fixedWindow = OS.GTK_WIDGET_WINDOW (fixedHandle);
- int /*long*/ binWindow = OS.gtk_tree_view_get_bin_window (handle);
- int [] binY = new int [1];
- OS.gdk_window_get_origin (binWindow, null, binY);
- int [] fixedY = new int [1];
- OS.gdk_window_get_origin (fixedWindow, null, fixedY);
- return binY [0] - fixedY [0];
-}
-
-/**
- * Returns <code>true</code> if the receiver's header is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's header's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public boolean getHeaderVisible () {
- checkWidget();
- return OS.gtk_tree_view_get_headers_visible (handle);
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public TreeItem getItem (int index) {
- checkWidget();
- if (!(0 <= index && index < OS.gtk_tree_model_iter_n_children (modelHandle, 0))) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- return _getItem (0, index);
-}
-
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- * <p>
- * The item that is returned represents an item that could be selected by the user.
- * For example, if selection only occurs in items in the first column, then null is
- * returned if the point is outside of the item.
- * Note that the SWT.FULL_SELECTION style hint, which specifies the selection policy,
- * determines the extent of the selection.
- * </p>
- *
- * @param point the point used to locate the item
- * @return the item at the given point, or null if the point is not in a selectable item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem getItem (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- int /*long*/ [] path = new int /*long*/ [1];
- OS.gtk_widget_realize (handle);
- int /*long*/ [] columnHandle = new int /*long*/ [1];
- if (!OS.gtk_tree_view_get_path_at_pos (handle, point.x, point.y, path, columnHandle, null, null)) return null;
- if (path [0] == 0) return null;
- TreeItem item = null;
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (OS.gtk_tree_model_get_iter (modelHandle, iter, path [0])) {
- boolean overExpander = false;
- if (OS.gtk_tree_view_get_expander_column (handle) == columnHandle [0]) {
- int [] buffer = new int [1];
- GdkRectangle rect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (handle, path [0], columnHandle [0], rect);
- if (OS.GTK_VERSION < OS.VERSION (2, 8, 18)) {
- OS.gtk_widget_style_get (handle, OS.expander_size, buffer, 0);
- int expanderSize = buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING;
- overExpander = point.x < rect.x + expanderSize;
- } else {
- overExpander = point.x < rect.x;
- }
- }
- if (!overExpander) {
- item = _getItem (iter);
- }
- }
- OS.g_free (iter);
- OS.gtk_tree_path_free (path [0]);
- return item;
-}
-
-/**
- * Returns the number of items contained in the receiver
- * that are direct item children of the receiver. The
- * number that is returned is the number of roots in the
- * tree.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return OS.gtk_tree_model_iter_n_children (modelHandle, 0);
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the tree.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- int itemCount = OS.gtk_tree_model_iter_n_children (modelHandle, 0);
- if (itemCount == 0) {
- int /*long*/ column = OS.gtk_tree_view_get_column (handle, 0);
- int [] w = new int [1], h = new int [1];
- ignoreSize = true;
- OS.gtk_tree_view_column_cell_get_size (column, null, null, null, w, h);
- ignoreSize = false;
- return h [0];
- } else {
- int height = 0;
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- OS.gtk_tree_model_get_iter_first (modelHandle, iter);
- int columnCount = Math.max (1, this.columnCount);
- for (int i=0; i<columnCount; i++) {
- int /*long*/ column = OS.gtk_tree_view_get_column (handle, i);
- OS.gtk_tree_view_column_cell_set_cell_data (column, modelHandle, iter, false, false);
- int [] w = new int [1], h = new int [1];
- OS.gtk_tree_view_column_cell_get_size (column, null, null, null, w, h);
- height = Math.max (height, h [0]);
- }
- OS.g_free (iter);
- return height;
- }
-}
-
-/**
- * Returns a (possibly empty) array of items contained in the
- * receiver that are direct item children of the receiver. These
- * are the roots of the tree.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem [] getItems () {
- checkWidget();
- return getItems (0);
-}
-
-TreeItem [] getItems (int /*long*/ parent) {
- int length = OS.gtk_tree_model_iter_n_children (modelHandle, parent);
- TreeItem[] result = new TreeItem [length];
- if (length == 0) return result;
- if ((style & SWT.VIRTUAL) != 0) {
- for (int i=0; i<length; i++) {
- result [i] = _getItem (parent, i);
- }
- } else {
- int i = 0;
- int[] index = new int [1];
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- boolean valid = OS.gtk_tree_model_iter_children (modelHandle, iter, parent);
- while (valid) {
- OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, index, -1);
- result [i++] = items [index [0]];
- valid = OS.gtk_tree_model_iter_next (modelHandle, iter);
- }
- OS.g_free (iter);
- }
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver's lines are visible,
- * and <code>false</code> otherwise. Note that some platforms draw
- * grid lines while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the visibility state of the lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public boolean getLinesVisible() {
- checkWidget();
- return OS.gtk_tree_view_get_rules_hint (handle);
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>TreeItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem getParentItem () {
- checkWidget ();
- return null;
-}
-
-int /*long*/ getPixbufRenderer (int /*long*/ column) {
- int /*long*/ list = OS.gtk_tree_view_column_get_cell_renderers (column);
- if (list == 0) return 0;
- int count = OS.g_list_length (list);
- int /*long*/ pixbufRenderer = 0;
- int i = 0;
- while (i < count) {
- int /*long*/ renderer = OS.g_list_nth_data (list, i);
- if (OS.GTK_IS_CELL_RENDERER_PIXBUF (renderer)) {
- pixbufRenderer = renderer;
- break;
- }
- i++;
- }
- OS.g_list_free (list);
- return pixbufRenderer;
-}
-
-/**
- * Returns an array of <code>TreeItem</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem[] getSelection () {
- checkWidget();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) {
- display.treeSelectionLength = 0;
- display.treeSelection = new int [items.length];
- OS.gtk_tree_selection_selected_foreach (selection, display.treeSelectionProc, handle);
- TreeItem [] result = new TreeItem [display.treeSelectionLength];
- for (int i=0; i<result.length; i++) result [i] = items [display.treeSelection [i]];
- return result;
- }
- /*
- * Bug in GTK. gtk_tree_selection_get_selected_rows() segmentation faults
- * in versions smaller than 2.2.4 if the model is NULL. The fix is
- * to give a valid pointer instead.
- */
- int /*long*/ [] model = OS.GTK_VERSION < OS.VERSION (2, 2, 4) ? new int /*long*/ [1] : null;
- int /*long*/ list = OS.gtk_tree_selection_get_selected_rows (selection, model);
- if (list != 0) {
- int count = OS.g_list_length (list);
- TreeItem [] treeSelection = new TreeItem [count];
- int length = 0;
- for (int i=0; i<count; i++) {
- int /*long*/ data = OS.g_list_nth_data (list, i);
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (OS.gtk_tree_model_get_iter (modelHandle, iter, data)) {
- treeSelection [length] = _getItem (iter);
- length++;
- }
- OS.g_free (iter);
- }
- OS.g_list_free (list);
- if (length < count) {
- TreeItem [] temp = new TreeItem [length];
- System.arraycopy(treeSelection, 0, temp, 0, length);
- treeSelection = temp;
- }
- return treeSelection;
- }
- return new TreeItem [0];
-}
-
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) {
- display.treeSelectionLength = 0;
- display.treeSelection = null;
- OS.gtk_tree_selection_selected_foreach (selection, display.treeSelectionProc, handle);
- return display.treeSelectionLength;
- }
- return OS.gtk_tree_selection_count_selected_rows (selection);
-}
-
-/**
- * Returns the column which shows the sort indicator for
- * the receiver. The value may be null if no column shows
- * the sort indicator.
- *
- * @return the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortColumn(TreeColumn)
- *
- * @since 3.2
- */
-public TreeColumn getSortColumn () {
- checkWidget ();
- return sortColumn;
-}
-
-/**
- * Returns the direction of the sort indicator for the receiver.
- * The value will be one of <code>UP</code>, <code>DOWN</code>
- * or <code>NONE</code>.
- *
- * @return the sort direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortDirection(int)
- *
- * @since 3.2
- */
-public int getSortDirection () {
- checkWidget ();
- return sortDirection;
-}
-
-int /*long*/ getTextRenderer (int /*long*/ column) {
- int /*long*/ list = OS.gtk_tree_view_column_get_cell_renderers (column);
- if (list == 0) return 0;
- int count = OS.g_list_length (list);
- int /*long*/ textRenderer = 0;
- int i = 0;
- while (i < count) {
- int /*long*/ renderer = OS.g_list_nth_data (list, i);
- if (OS.GTK_IS_CELL_RENDERER_TEXT (renderer)) {
- textRenderer = renderer;
- break;
- }
- i++;
- }
- OS.g_list_free (list);
- return textRenderer;
-}
-
-/**
- * Returns the item which is currently at the top of the receiver.
- * This item can change when items are expanded, collapsed, scrolled
- * or new items are added or removed.
- *
- * @return the item at the top of the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public TreeItem getTopItem () {
- checkWidget ();
- int /*long*/ [] path = new int /*long*/ [1];
- OS.gtk_widget_realize (handle);
- if (!OS.gtk_tree_view_get_path_at_pos (handle, 1, 1, path, null, null, null)) return null;
- if (path [0] == 0) return null;
- TreeItem item = null;
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof());
- if (OS.gtk_tree_model_get_iter (modelHandle, iter, path [0])) {
- item = _getItem (iter);
- }
- OS.g_free (iter);
- OS.gtk_tree_path_free (path [0]);
- return item;
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
- if (gdkEvent.window != OS.gtk_tree_view_get_bin_window (handle)) return 0;
- int /*long*/ result = super.gtk_button_press_event (widget, event);
- if (result != 0) return result;
- /*
- * Feature in GTK. In a multi-select tree view, when multiple items are already
- * selected, the selection state of the item is toggled and the previous selection
- * is cleared. This is not the desired behaviour when bringing up a popup menu.
- * Also, when an item is reselected with the right button, the tree view issues
- * an unwanted selection event. The workaround is to detect that case and not
- * run the default handler when the item is already part of the current selection.
- */
- int button = gdkEvent.button;
- if (button == 3 && gdkEvent.type == OS.GDK_BUTTON_PRESS) {
- int /*long*/ [] path = new int /*long*/ [1];
- if (OS.gtk_tree_view_get_path_at_pos (handle, (int)gdkEvent.x, (int)gdkEvent.y, path, null, null, null)) {
- if (path [0] != 0) {
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- if (OS.gtk_tree_selection_path_is_selected (selection, path [0])) result = 1;
- OS.gtk_tree_path_free (path [0]);
- }
- }
- }
-
- /*
- * Feature in GTK. When the user clicks in a single selection GtkTreeView
- * and there are no selected items, the first item is selected automatically
- * before the click is processed, causing two selection events. The is fix
- * is the set the cursor item to be same as the clicked item to stop the
- * widget from automatically selecting the first item.
- */
- if ((style & SWT.SINGLE) != 0 && getSelectionCount () == 0) {
- int /*long*/ [] path = new int /*long*/ [1];
- if (OS.gtk_tree_view_get_path_at_pos (handle, (int)gdkEvent.x, (int)gdkEvent.y, path, null, null, null)) {
- if (path [0] != 0) {
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_view_set_cursor (handle, path [0], 0, false);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_path_free (path [0]);
- }
- }
- }
- /*
- * Bug in GTK. GTK segments fault, if the GtkTreeView widget is
- * not in focus and all items in the widget are disposed before
- * it finishes processing a button press. The fix is to give
- * focus to the widget before it starts processing the event.
- */
- if (!OS.GTK_WIDGET_HAS_FOCUS (handle)) {
- OS.gtk_widget_grab_focus (handle);
- }
- return result;
-}
-
-int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ window = OS.GDK_EVENT_WINDOW (event);
- if (window != OS.gtk_tree_view_get_bin_window (handle)) return 0;
- return super.gtk_button_release_event (widget, event);
-}
-
-int /*long*/ gtk_changed (int /*long*/ widget) {
- TreeItem item = getFocusItem ();
- if (item != null) {
- Event event = new Event ();
- event.item = item;
- postEvent (SWT.Selection, event);
- }
- return 0;
-}
-
-int /*long*/ gtk_expand_collapse_cursor_row (int /*long*/ widget, int /*long*/ logical, int /*long*/ expand, int /*long*/ open_all) {
- // FIXME - this flag is never cleared. It should be cleared when the expand all operation completes.
- if (expand != 0 && open_all != 0) expandAll = true;
- return 0;
-}
-
-int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ eventPtr) {
- int /*long*/ result = super.gtk_key_press_event (widget, eventPtr);
- if (result != 0) return result;
- if (OS.GTK_VERSION < OS.VERSION (2, 2 ,0)) {
- /*
- * Feature in GTK 2.0.x. When an item is default selected using
- * the return key, GTK does not issue notification. The fix is
- * to issue this notification when the return key is pressed.
- */
- GdkEventKey keyEvent = new GdkEventKey ();
- OS.memmove (keyEvent, eventPtr, GdkEventKey.sizeof);
- int key = keyEvent.keyval;
- switch (key) {
- case OS.GDK_Return:
- case OS.GDK_KP_Enter: {
- Event event = new Event ();
- event.item = getFocusItem ();
- postEvent (SWT.DefaultSelection, event);
- break;
- }
- }
- }
- return result;
-}
-
-int /*long*/ gtk_motion_notify_event (int /*long*/ widget, int /*long*/ event) {
- int /*long*/ window = OS.GDK_EVENT_WINDOW (event);
- if (window != OS.gtk_tree_view_get_bin_window (handle)) return 0;
- return super.gtk_motion_notify_event (widget, event);
-}
-
-int /*long*/ gtk_popup_menu (int /*long*/ widget) {
- int /*long*/ result = super.gtk_popup_menu (widget);
- /*
- * Bug in GTK. The context menu for the typeahead in GtkTreeViewer
- * opens in the bottom right corner of the screen when Shift+F10
- * is pressed and the typeahead window was not visible. The fix is
- * to prevent the context menu from opening by stopping the default
- * handler.
- *
- * NOTE: The bug only happens in GTK 2.6.5 and lower.
- */
- return OS.GTK_VERSION < OS.VERSION (2, 6, 5) ? 1 : result;
-}
-
-int /*long*/ gtk_row_activated (int /*long*/ tree, int /*long*/ path, int /*long*/ column) {
- if (path == 0) return 0;
- TreeItem item = null;
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (OS.gtk_tree_model_get_iter (modelHandle, iter, path)) {
- int [] index = new int [1];
- OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, index, -1);
- item = items [index [0]];
- }
- OS.g_free (iter);
- Event event = new Event ();
- event.item = item;
- postEvent (SWT.DefaultSelection, event);
- return 0;
-}
-
-int gtk_row_deleted (int model, int path) {
- if (ignoreAccessibility) {
- OS.g_signal_stop_emission_by_name (model, OS.row_deleted);
- }
- return 0;
-}
-
-int gtk_row_inserted (int model, int path, int iter) {
- if (ignoreAccessibility) {
- OS.g_signal_stop_emission_by_name (model, OS.row_inserted);
- }
- return 0;
-}
-
-int /*long*/ gtk_test_collapse_row (int /*long*/ tree, int /*long*/ iter, int /*long*/ path) {
- int [] index = new int [1];
- OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, index, -1);
- TreeItem item = items [index [0]];
- Event event = new Event ();
- event.item = item;
- boolean oldModelChanged = modelChanged;
- modelChanged = false;
- sendEvent (SWT.Collapse, event);
- /*
- * Bug in GTK. Collapsing the target row during the test_collapse_row
- * handler will cause a segmentation fault if the animation code is allowed
- * to run. The fix is to block the animation if the row is already
- * collapsed.
- */
- boolean changed = modelChanged || !OS.gtk_tree_view_row_expanded (handle, path);
- modelChanged = oldModelChanged;
- if (isDisposed () || item.isDisposed ()) return 1;
- /*
- * Bug in GTK. Expanding or collapsing a row which has no more
- * children causes the model state to become invalid, causing
- * GTK to give warnings and behave strangely. Other changes to
- * the model can cause expansion to fail when using the multiple
- * expansion keys (such as *). The fix is to stop the expansion
- * if there are model changes.
- *
- * Note: This callback must return 0 for the collapsing
- * animation to occur.
- */
- if (changed) {
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_COLLAPSE_ROW);
- OS.gtk_tree_view_collapse_row (handle, path);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_COLLAPSE_ROW);
- return 1;
- }
- return 0;
-}
-
-int /*long*/ gtk_test_expand_row (int /*long*/ tree, int /*long*/ iter, int /*long*/ path) {
- int [] index = new int [1];
- OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, index, -1);
- TreeItem item = items [index [0]];
- Event event = new Event ();
- event.item = item;
- boolean oldModelChanged = modelChanged;
- modelChanged = false;
- sendEvent (SWT.Expand, event);
- /*
- * Bug in GTK. Expanding the target row during the test_expand_row
- * handler will cause a segmentation fault if the animation code is allowed
- * to run. The fix is to block the animation if the row is already
- * expanded.
- */
- boolean changed = modelChanged || OS.gtk_tree_view_row_expanded (handle, path);
- modelChanged = oldModelChanged;
- if (isDisposed () || item.isDisposed ()) return 1;
- /*
- * Bug in GTK. Expanding or collapsing a row which has no more
- * children causes the model state to become invalid, causing
- * GTK to give warnings and behave strangely. Other changes to
- * the model can cause expansion to fail when using the multiple
- * expansion keys (such as *). The fix is to stop the expansion
- * if there are model changes.
- *
- * Bug in GTK. test-expand-row does not get called for each row
- * in an expand all operation. The fix is to block the initial
- * expansion and only expand a single level.
- *
- * Note: This callback must return 0 for the collapsing
- * animation to occur.
- */
- if (changed || expandAll) {
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_EXPAND_ROW);
- OS.gtk_tree_view_expand_row (handle, path, false);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_EXPAND_ROW);
- return 1;
- }
- return 0;
-}
-
-int /*long*/ gtk_toggled (int /*long*/ renderer, int /*long*/ pathStr) {
- int /*long*/ path = OS.gtk_tree_path_new_from_string (pathStr);
- if (path == 0) return 0;
- TreeItem item = null;
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof());
- if (OS.gtk_tree_model_get_iter (modelHandle, iter, path)) {
- item = _getItem (iter);
- }
- OS.g_free (iter);
- OS.gtk_tree_path_free (path);
- if (item != null) {
- item.setChecked (!item.getChecked ());
- Event event = new Event ();
- event.detail = SWT.CHECK;
- event.item = item;
- postEvent (SWT.Selection, event);
- }
- return 0;
-}
-
-void gtk_widget_size_request (int /*long*/ widget, GtkRequisition requisition) {
- /*
- * Bug in GTK. For some reason, gtk_widget_size_request() fails
- * to include the height of the tree view items when there are
- * no columns visible. The fix is to temporarily make one column
- * visible.
- */
- if (columnCount == 0) {
- super.gtk_widget_size_request (widget, requisition);
- return;
- }
- int /*long*/ columns = OS.gtk_tree_view_get_columns (handle), list = columns;
- boolean fixVisible = columns != 0;
- while (list != 0) {
- int /*long*/ column = OS.g_list_data (list);
- if (OS.gtk_tree_view_column_get_visible (column)) {
- fixVisible = false;
- break;
- }
- list = OS.g_list_next (list);
- }
- int /*long*/ columnHandle = 0;
- if (fixVisible) {
- columnHandle = OS.g_list_data (columns);
- OS.gtk_tree_view_column_set_visible (columnHandle, true);
- }
- super.gtk_widget_size_request (widget, requisition);
- if (fixVisible) {
- OS.gtk_tree_view_column_set_visible (columnHandle, false);
- }
- if (columns != 0) OS.g_list_free (columns);
-}
-
-void hideFirstColumn () {
- int /*long*/ firstColumn = OS.gtk_tree_view_get_column (handle, 0);
- OS.gtk_tree_view_column_set_visible (firstColumn, false);
-}
-
-void hookEvents () {
- super.hookEvents ();
- int /*long*/ selection = OS.gtk_tree_view_get_selection(handle);
- OS.g_signal_connect_closure (selection, OS.changed, display.closures [CHANGED], false);
- OS.g_signal_connect_closure (handle, OS.row_activated, display.closures [ROW_ACTIVATED], false);
- OS.g_signal_connect_closure (handle, OS.test_expand_row, display.closures [TEST_EXPAND_ROW], false);
- OS.g_signal_connect_closure (handle, OS.test_collapse_row, display.closures [TEST_COLLAPSE_ROW], false);
- OS.g_signal_connect_closure (handle, OS.expand_collapse_cursor_row, display.closures [EXPAND_COLLAPSE_CURSOR_ROW], false);
- if (checkRenderer != 0) {
- OS.g_signal_connect_closure (checkRenderer, OS.toggled, display.closures [TOGGLED], false);
- }
- if (fixAccessibility ()) {
- OS.g_signal_connect_closure (modelHandle, OS.row_inserted, display.closures [ROW_INSERTED], true);
- OS.g_signal_connect_closure (modelHandle, OS.row_deleted, display.closures [ROW_DELETED], true);
- }
-}
-
-/**
- * Searches the receiver's list starting at the first column
- * (index 0) until a column is found that is equal to the
- * argument, and returns the index of that column. If no column
- * is found, returns -1.
- *
- * @param column the search column
- * @return the index of the column
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the column is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int indexOf (TreeColumn column) {
- checkWidget();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<columnCount; i++) {
- if (columns [i] == column) return i;
- }
- return -1;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int indexOf (TreeItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- int index = -1;
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, item.handle);
- int depth = OS.gtk_tree_path_get_depth (path);
- if (depth == 1) {
- int /*long*/ indices = OS.gtk_tree_path_get_indices (path);
- if (indices != 0) {
- int[] temp = new int[1];
- OS.memmove (temp, indices, 4);
- index = temp[0];
- }
- }
- OS.gtk_tree_path_free (path);
- return index;
-}
-
-boolean mnemonicHit (char key) {
- for (int i=0; i<columnCount; i++) {
- int /*long*/ labelHandle = columns [i].labelHandle;
- if (labelHandle != 0 && mnemonicHit (labelHandle, key)) return true;
- }
- return false;
-}
-
-boolean mnemonicMatch (char key) {
- for (int i=0; i<columnCount; i++) {
- int /*long*/ labelHandle = columns [i].labelHandle;
- if (labelHandle != 0 && mnemonicMatch (labelHandle, key)) return true;
- }
- return false;
-}
-
-int /*long*/ paintWindow () {
- OS.gtk_widget_realize (handle);
- return OS.gtk_tree_view_get_bin_window (handle);
-}
-
-void recreateRenderers () {
- if (checkRenderer != 0) {
- display.removeWidget (checkRenderer);
- OS.g_object_unref (checkRenderer);
- checkRenderer = ownerDraw ? OS.g_object_new (display.gtk_cell_renderer_toggle_get_type(), 0) : OS.gtk_cell_renderer_toggle_new ();
- if (checkRenderer == 0) error (SWT.ERROR_NO_HANDLES);
- OS.g_object_ref (checkRenderer);
- display.addWidget (checkRenderer, this);
- OS.g_signal_connect_closure (checkRenderer, OS.toggled, display.closures [TOGGLED], false);
- }
- if (columnCount == 0) {
- createRenderers (OS.gtk_tree_view_get_column (handle, 0), Tree.FIRST_COLUMN, true, 0);
- } else {
- for (int i = 0; i < columnCount; i++) {
- TreeColumn column = columns [i];
- createRenderers (column.handle, column.modelIndex, i == 0, column.style);
- }
- }
-}
-
-void redrawBackgroundImage () {
- Control control = findBackgroundControl ();
- if (control != null && control.backgroundImage != null) {
- redrawWidget (0, 0, 0, 0, true, false, false);
- }
-}
-
-void register () {
- super.register ();
- display.addWidget (OS.gtk_tree_view_get_selection (handle), this);
- if (checkRenderer != 0) display.addWidget (checkRenderer, this);
- display.addWidget (modelHandle, this);
-}
-
-void releaseItem (TreeItem item, boolean release) {
- int [] index = new int [1];
- OS.gtk_tree_model_get (modelHandle, item.handle, ID_COLUMN, index, -1);
- if (index [0] == -1) return;
- if (release) item.release (false);
- items [index [0]] = null;
-}
-
-void releaseItems (int /*long*/ parentIter) {
- int[] index = new int [1];
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- boolean valid = OS.gtk_tree_model_iter_children (modelHandle, iter, parentIter);
- while (valid) {
- releaseItems (iter);
- if (!isDisposed ()) {
- OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, index, -1);
- if (index [0] != -1) {
- TreeItem item = items [index [0]];
- if (item != null) releaseItem (item, true);
- }
- }
- valid = OS.gtk_tree_model_iter_next (modelHandle, iter);
- }
- OS.g_free (iter);
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- }
- if (columns != null) {
- for (int i=0; i<columnCount; i++) {
- TreeColumn column = columns [i];
- if (column != null && !column.isDisposed ()) {
- column.release (false);
- }
- }
- columns = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (modelHandle != 0) OS.g_object_unref (modelHandle);
- modelHandle = 0;
- if (checkRenderer != 0) OS.g_object_unref (checkRenderer);
- checkRenderer = 0;
- if (imageList != null) imageList.dispose ();
- if (headerImageList != null) headerImageList.dispose ();
- imageList = headerImageList = null;
- currentItem = null;
-}
-
-void remove (int /*long*/ parentIter, int start, int end) {
- if (start > end) return;
- int itemCount = OS.gtk_tree_model_iter_n_children (modelHandle, parentIter);
- if (!(0 <= start && start <= end && end < itemCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (iter == 0) error (SWT.ERROR_NO_HANDLES);
- if (fixAccessibility ()) {
- ignoreAccessibility = true;
- }
- for (int i = start; i <= end; i++) {
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, parentIter, start);
- int[] value = new int[1];
- OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, value, -1);
- TreeItem item = value [0] != -1 ? items [value [0]] : null;
- if (item != null && !item.isDisposed ()) {
- item.dispose ();
- } else {
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_store_remove (modelHandle, iter);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- }
- }
- if (fixAccessibility ()) {
- ignoreAccessibility = false;
- OS.g_object_notify (handle, OS.model);
- }
- OS.g_free (iter);
-}
-
-/**
- * Removes all of the items from the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget ();
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null && !item.isDisposed ()) item.release (false);
- }
- items = new TreeItem[4];
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- if (fixAccessibility ()) {
- ignoreAccessibility = true;
- }
- OS.gtk_tree_store_clear (modelHandle);
- if (fixAccessibility ()) {
- ignoreAccessibility = false;
- OS.g_object_notify (handle, OS.model);
- }
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
-
- /* Disable searching when using VIRTUAL */
- if ((style & SWT.VIRTUAL) != 0) {
- /*
- * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE)
- * would prevent the user from being able to type in text to search the tree.
- * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive
- * search. This meant that even if FALSE was passed to enable_search, the user
- * can still bring up the search pop up using the keybinding. GTK also introduced
- * the notion of passing a -1 to gtk_set_search_column to disable searching
- * (including the search key binding). The fix is to use the right calls
- * for the right version.
- */
- if (OS.GTK_VERSION >= OS.VERSION (2, 6, 5)) {
- OS.gtk_tree_view_set_search_column (handle, -1);
- } else {
- OS.gtk_tree_view_set_enable_search (handle, false);
- }
- } else {
- /* Set the search column whenever the model changes */
- int firstColumn = columnCount == 0 ? FIRST_COLUMN : columns [0].modelIndex;
- OS.gtk_tree_view_set_search_column (handle, firstColumn + CELL_TEXT);
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when items in the receiver are expanded or collapsed.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TreeListener
- * @see #addTreeListener
- */
-public void removeTreeListener(TreeListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Expand, listener);
- eventTable.unhook (SWT.Collapse, listener);
-}
-
-int /*long*/ rendererGetSizeProc (int /*long*/ cell, int /*long*/ widget, int /*long*/ cell_area, int /*long*/ x_offset, int /*long*/ y_offset, int /*long*/ width, int /*long*/ height) {
- int /*long*/ g_class = OS.g_type_class_peek_parent (OS.G_OBJECT_GET_CLASS (cell));
- GtkCellRendererClass klass = new GtkCellRendererClass ();
- OS.memmove (klass, g_class);
- int /*long*/ result = OS.call (klass.get_size, cell, handle, cell_area, x_offset, y_offset, width, height);
- if (!ignoreSize && OS.GTK_IS_CELL_RENDERER_TEXT (cell)) {
- int /*long*/ iter = OS.g_object_get_qdata (cell, Display.SWT_OBJECT_INDEX2);
- TreeItem item = null;
- if (iter != 0) item = _getItem (iter);
- if (item != null) {
- int columnIndex = 0;
- if (columnCount > 0) {
- int /*long*/ columnHandle = OS.g_object_get_qdata (cell, Display.SWT_OBJECT_INDEX1);
- for (int i = 0; i < columnCount; i++) {
- if (columns [i].handle == columnHandle) {
- columnIndex = i;
- break;
- }
- }
- }
- if (hooks (SWT.MeasureItem)) {
- int [] contentWidth = new int [1], contentHeight = new int [1];
- if (width != 0) OS.memmove (contentWidth, width, 4);
- if (height != 0) OS.memmove (contentHeight, height, 4);
- Image image = item.getImage (columnIndex);
- int imageWidth = 0;
- if (image != null) {
- Rectangle bounds = image.getBounds ();
- imageWidth = bounds.width;
- }
- contentWidth [0] += imageWidth;
- GC gc = new GC (this);
- gc.setFont (item.getFont (columnIndex));
- Event event = new Event ();
- event.item = item;
- event.index = columnIndex;
- event.gc = gc;
- event.width = contentWidth [0];
- event.height = contentHeight [0];
- sendEvent (SWT.MeasureItem, event);
- gc.dispose ();
- contentWidth [0] = event.width - imageWidth;
- if (contentHeight [0] < event.height) contentHeight [0] = event.height;
- if (width != 0) OS.memmove (width, contentWidth, 4);
- if (height != 0) OS.memmove (height, contentHeight, 4);
- }
- }
- }
- return result;
-}
-
-int /*long*/ rendererRenderProc (int /*long*/ cell, int /*long*/ window, int /*long*/ widget, int /*long*/ background_area, int /*long*/ cell_area, int /*long*/ expose_area, int /*long*/ flags) {
- TreeItem item = null;
- int /*long*/ iter = OS.g_object_get_qdata (cell, Display.SWT_OBJECT_INDEX2);
- if (iter != 0) item = _getItem (iter);
- int /*long*/ columnHandle = OS.g_object_get_qdata (cell, Display.SWT_OBJECT_INDEX1);
- int columnIndex = 0;
- if (columnCount > 0) {
- for (int i = 0; i < columnCount; i++) {
- if (columns [i].handle == columnHandle) {
- columnIndex = i;
- break;
- }
- }
- }
- if (item != null) {
- if (OS.GTK_IS_CELL_RENDERER_TOGGLE (cell) || (OS.GTK_IS_CELL_RENDERER_PIXBUF (cell) && (columnIndex != 0 || (style & SWT.CHECK) == 0))) {
- drawFlags = (int)/*64*/flags;
- drawState = SWT.FOREGROUND;
- int /*long*/ [] ptr = new int /*long*/ [1];
- OS.gtk_tree_model_get (modelHandle, item.handle, Tree.BACKGROUND_COLUMN, ptr, -1);
- if (ptr [0] == 0) {
- int modelIndex = columnCount == 0 ? Tree.FIRST_COLUMN : columns [columnIndex].modelIndex;
- OS.gtk_tree_model_get (modelHandle, item.handle, modelIndex + Tree.CELL_BACKGROUND, ptr, -1);
- }
- if (ptr [0] != 0) drawState |= SWT.BACKGROUND;
- if ((flags & OS.GTK_CELL_RENDERER_SELECTED) != 0) drawState |= SWT.SELECTED;
- if ((flags & OS.GTK_CELL_RENDERER_FOCUSED) != 0) drawState |= SWT.FOCUSED;
-
- GdkRectangle rect = new GdkRectangle ();
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter);
- OS.gtk_tree_view_get_background_area (handle, path, columnHandle, rect);
- OS.gtk_tree_path_free (path);
-
- if ((drawState & SWT.SELECTED) == 0) {
- Control control = findBackgroundControl ();
- if (control != null && control.backgroundImage != null) {
- OS.gdk_window_clear_area (window, rect.x, rect.y, rect.width, rect.height);
- }
- }
-
- if (hooks (SWT.EraseItem)) {
- boolean wasSelected = false;
- if ((drawState & SWT.SELECTED) != 0) {
- wasSelected = true;
- OS.gdk_window_clear_area (window, rect.x, rect.y, rect.width, rect.height);
- }
- GC gc = new GC (this);
- if ((drawState & SWT.SELECTED) != 0) {
- gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION));
- gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT));
- } else {
- gc.setBackground (item.getBackground (columnIndex));
- gc.setForeground (item.getForeground (columnIndex));
- }
- gc.setFont (item.getFont (columnIndex));
- if ((style & SWT.MIRRORED) != 0) rect.x = getClientWidth () - rect.width - rect.x;
- gc.setClipping (rect.x, rect.y, rect.width, rect.height);
- Event event = new Event ();
- event.item = item;
- event.index = columnIndex;
- event.gc = gc;
- event.x = rect.x;
- event.y = rect.y;
- event.width = rect.width;
- event.height = rect.height;
- event.detail = drawState;
- sendEvent (SWT.EraseItem, event);
- drawForeground = null;
- drawState = event.doit ? event.detail : 0;
- drawFlags &= ~(OS.GTK_CELL_RENDERER_FOCUSED | OS.GTK_CELL_RENDERER_SELECTED);
- if ((drawState & SWT.SELECTED) != 0) drawFlags |= OS.GTK_CELL_RENDERER_SELECTED;
- if ((drawState & SWT.FOCUSED) != 0) drawFlags |= OS.GTK_CELL_RENDERER_FOCUSED;
- if ((drawState & SWT.SELECTED) != 0) {
- int /*long*/ style = OS.gtk_widget_get_style (widget);
- //TODO - parity and sorted
- byte[] detail = Converter.wcsToMbcs (null, "cell_odd", true);
- OS.gtk_paint_flat_box (style, window, OS.GTK_STATE_SELECTED, OS.GTK_SHADOW_NONE, rect, widget, detail, rect.x, rect.y, rect.width, rect.height);
- } else {
- if (wasSelected) drawForeground = gc.getForeground ().handle;
- }
- gc.dispose();
- }
- }
- }
- int /*long*/ result = 0;
- if ((drawState & SWT.BACKGROUND) != 0 && (drawState & SWT.SELECTED) == 0) {
- GC gc = new GC (this);
- gc.setBackground (item.getBackground (columnIndex));
- GdkRectangle rect = new GdkRectangle ();
- OS.memmove (rect, background_area, GdkRectangle.sizeof);
- gc.fillRectangle (rect.x, rect.y, rect.width, rect.height);
- gc.dispose ();
- }
- if ((drawState & SWT.FOREGROUND) != 0 || OS.GTK_IS_CELL_RENDERER_TOGGLE (cell)) {
- int /*long*/ g_class = OS.g_type_class_peek_parent (OS.G_OBJECT_GET_CLASS (cell));
- GtkCellRendererClass klass = new GtkCellRendererClass ();
- OS.memmove (klass, g_class);
- if (drawForeground != null && OS.GTK_IS_CELL_RENDERER_TEXT (cell)) {
- OS.g_object_set (cell, OS.foreground_gdk, drawForeground, 0);
- }
- result = OS.call (klass.render, cell, window, handle, background_area, cell_area, expose_area, drawFlags);
- }
- if (item != null) {
- if (OS.GTK_IS_CELL_RENDERER_TEXT (cell)) {
- if (hooks (SWT.PaintItem)) {
- GdkRectangle rect = new GdkRectangle ();
- GdkRectangle clipRect = new GdkRectangle ();
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter);
- OS.gtk_tree_view_get_cell_area (handle, path, columnHandle, rect);
- OS.gtk_tree_view_get_background_area (handle, path, columnHandle, clipRect);
- OS.gtk_tree_path_free (path);
- if (OS.GTK_VERSION < OS.VERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (handle) == columnHandle) {
- int [] buffer = new int [1];
- OS.gtk_widget_style_get (handle, OS.expander_size, buffer, 0);
- rect.x += buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING;
- rect.width -= buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING;
- //OS.gtk_widget_style_get (handle, OS.horizontal_separator, buffer, 0);
- //rect.x += buffer[0];
- //rect.width -= buffer [0]; // TODO Is this required for some versions?
- }
- ignoreSize = true;
- int [] contentX = new int [1], contentWidth = new int [1];
- OS.gtk_cell_renderer_get_size (cell, handle, null, null, null, contentWidth, null);
- OS.gtk_tree_view_column_cell_get_position (columnHandle, cell, contentX, null);
- ignoreSize = false;
- Image image = item.getImage (columnIndex);
- int imageWidth = 0;
- if (image != null) {
- Rectangle bounds = image.getBounds ();
- imageWidth = bounds.width;
- }
- contentX [0] -= imageWidth;
- contentWidth [0] += imageWidth;
- GC gc = new GC (this);
- if ((drawState & SWT.SELECTED) != 0) {
- gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION));
- gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT));
- } else {
- gc.setBackground (item.getBackground (columnIndex));
- Color foreground = drawForeground != null ? Color.gtk_new (display, drawForeground) : item.getForeground (columnIndex);
- gc.setForeground (foreground);
- }
- gc.setFont (item.getFont (columnIndex));
- if ((style & SWT.MIRRORED) != 0) {
- rect.x = getClientWidth () - rect.width - rect.x;
- clipRect.x = getClientWidth () - clipRect.width - clipRect.x;
- }
- gc.setClipping (clipRect.x, clipRect.y, clipRect.width, clipRect.height);
- Event event = new Event ();
- event.item = item;
- event.index = columnIndex;
- event.gc = gc;
- event.x = rect.x + contentX [0];
- event.y = rect.y;
- event.width = contentWidth [0];
- event.height = rect.height;
- event.detail = drawState;
- sendEvent (SWT.PaintItem, event);
- gc.dispose();
- }
- }
- }
- return result;
-}
-
-void resetCustomDraw () {
- if ((style & SWT.VIRTUAL) != 0 || ownerDraw) return;
- int end = Math.max (1, columnCount);
- for (int i=0; i<end; i++) {
- boolean customDraw = columnCount != 0 ? columns [i].customDraw : firstCustomDraw;
- if (customDraw) {
- int /*long*/ column = OS.gtk_tree_view_get_column (handle, i);
- int /*long*/ textRenderer = getTextRenderer (column);
- OS.gtk_tree_view_column_set_cell_data_func (column, textRenderer, 0, 0, 0);
- if (columnCount != 0) columns [i].customDraw = false;
- }
- }
- firstCustomDraw = false;
-}
-
-/**
- * Display a mark indicating the point at which an item will be inserted.
- * The drop insert item has a visual hint to show where a dragged item
- * will be inserted when dropped on the tree.
- *
- * @param item the insert item. Null will clear the insertion mark.
- * @param before true places the insert mark above 'item'. false places
- * the insert mark below 'item'.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setInsertMark (TreeItem item, boolean before) {
- checkWidget ();
- if (item == null) {
- OS.gtk_tree_view_set_drag_dest_row(handle, 0, OS.GTK_TREE_VIEW_DROP_BEFORE);
- return;
- }
- if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (item.parent != this) return;
- Rectangle rect = item.getBounds();
- int /*long*/ [] path = new int /*long*/ [1];
- OS.gtk_widget_realize (handle);
- if (!OS.gtk_tree_view_get_path_at_pos(handle, rect.x, rect.y, path, null, null, null)) return;
- if (path [0] == 0) return;
- int position = before ? OS.GTK_TREE_VIEW_DROP_BEFORE : OS.GTK_TREE_VIEW_DROP_AFTER;
- OS.gtk_tree_view_set_drag_dest_row(handle, path[0], position);
- OS.gtk_tree_path_free (path [0]);
-}
-
-void setItemCount (int /*long*/ parentIter, int count) {
- int itemCount = OS.gtk_tree_model_iter_n_children (modelHandle, parentIter);
- if (count == itemCount) return;
- boolean isVirtual = (style & SWT.VIRTUAL) != 0;
- if (!isVirtual) setRedraw (false);
- remove (parentIter, count, itemCount - 1);
- if (isVirtual) {
- if (fixAccessibility ()) {
- ignoreAccessibility = true;
- }
- for (int i=itemCount; i<count; i++) {
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (iter == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_tree_store_append (modelHandle, iter, parentIter);
- OS.gtk_tree_store_set (modelHandle, iter, ID_COLUMN, -1, -1);
- OS.g_free (iter);
- }
- if (fixAccessibility ()) {
- ignoreAccessibility = false;
- OS.g_object_notify (handle, OS.model);
- }
- } else {
- for (int i=itemCount; i<count; i++) {
- new TreeItem (this, parentIter, SWT.NONE, i, true);
- }
- }
- if (!isVirtual) setRedraw (true);
- modelChanged = true;
-}
-
-/**
- * Sets the number of root-level items contained in the receiver.
- *
- * @param count the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setItemCount (int count) {
- checkWidget ();
- count = Math.max (0, count);
- setItemCount (0, count);
-}
-
-/**
- * Selects an item in the receiver. If the item was already
- * selected, it remains selected.
- *
- * @param item the item to be selected
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void select (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean fixColumn = showFirstColumn ();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_selection_select_iter (selection, item.handle);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- if (fixColumn) hideFirstColumn ();
-}
-
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return;
- boolean fixColumn = showFirstColumn ();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_selection_select_all (selection);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- if (fixColumn) hideFirstColumn ();
-}
-
-void setBackgroundColor (GdkColor color) {
- super.setBackgroundColor (color);
- OS.gtk_widget_modify_base (handle, 0, color);
-}
-
-void setBackgroundPixmap (int /*long*/ pixmap) {
- super.setBackgroundPixmap (pixmap);
- int /*long*/ window = paintWindow ();
- if (window != 0) OS.gdk_window_set_back_pixmap (window, 0, true);
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- int result = super.setBounds (x, y, width, height, move, resize);
- /*
- * Bug on GTK. The tree view sometimes does not get a paint
- * event or resizes to a one pixel square when resized in a new
- * shell that is not visible after any event loop has been run. The
- * problem is intermittent. It doesn't seem to happen the first time
- * a new shell is created. The fix is to ensure the tree view is realized
- * after it has been resized.
- */
- OS.gtk_widget_realize (handle);
- /*
- * Bug in GTK. An empty GtkTreeView fails to repaint the focus rectangle
- * correctly when resized on versions before 2.6.0. The fix is to force
- * the widget to redraw.
- */
- if (OS.GTK_VERSION < OS.VERSION (2, 6, 0) && OS.gtk_tree_model_iter_n_children (modelHandle, 0) == 0) {
- redraw (false);
- }
- return result;
-}
-
-/**
- * Sets the order that the items in the receiver should
- * be displayed in to the given argument which is described
- * in terms of the zero-relative ordering of when the items
- * were added.
- *
- * @param order the new order to display the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item order is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
-public void setColumnOrder (int [] order) {
- checkWidget ();
- if (order == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (columnCount == 0) {
- if (order.length > 0) error (SWT.ERROR_INVALID_ARGUMENT);
- return;
- }
- if (order.length != columnCount) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean [] seen = new boolean [columnCount];
- for (int i = 0; i<order.length; i++) {
- int index = order [i];
- if (index < 0 || index >= columnCount) error (SWT.ERROR_INVALID_RANGE);
- if (seen [index]) error (SWT.ERROR_INVALID_ARGUMENT);
- seen [index] = true;
- }
- int /*long*/ baseColumn = 0;
- for (int i=0; i<order.length; i++) {
- int /*long*/ column = columns [order [i]].handle;
- OS.gtk_tree_view_move_column_after (handle, column, baseColumn);
- baseColumn = column;
- }
-}
-
-void setFontDescription (int /*long*/ font) {
- super.setFontDescription (font);
- TreeColumn[] columns = getColumns ();
- for (int i = 0; i < columns.length; i++) {
- if (columns[i] != null) {
- columns[i].setFontDescription (font);
- }
- }
-}
-
-/**
- * Marks the receiver's header as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setHeaderVisible (boolean show) {
- checkWidget ();
- OS.gtk_tree_view_set_headers_visible (handle, show);
-}
-
-/**
- * Marks the receiver's lines as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise. Note that some platforms draw
- * grid lines while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLinesVisible (boolean show) {
- checkWidget();
- OS.gtk_tree_view_set_rules_hint (handle, show);
- if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0)) {
- OS.gtk_tree_view_set_grid_lines (handle, show ? OS.GTK_TREE_VIEW_GRID_LINES_VERTICAL : OS.GTK_TREE_VIEW_GRID_LINES_NONE);
- }
-}
-
-void setParentBackground () {
- super.setParentBackground ();
- int /*long*/ window = paintWindow ();
- if (window != 0) OS.gdk_window_set_back_pixmap (window, 0, true);
-}
-
-void setParentWindow (int /*long*/ widget) {
- int /*long*/ window = eventWindow ();
- OS.gtk_widget_set_parent_window (widget, window);
-}
-
-void setScrollWidth (int /*long*/ column, TreeItem item) {
- if (columnCount != 0 || currentItem == item) return;
- /*
- * Use GTK_TREE_VIEW_COLUMN_GROW_ONLY on GTK versions < 2.3.2
- * because fixed_height_mode is not supported.
- */
- if (((style & SWT.VIRTUAL) != 0) && OS.GTK_VERSION < OS.VERSION (2, 3, 2)) return;
- int width = OS.gtk_tree_view_column_get_fixed_width (column);
- int itemWidth = calculateWidth (column, item.handle, true);
- if (width < itemWidth) {
- OS.gtk_tree_view_column_set_fixed_width (column, itemWidth);
- }
-}
-
-/**
- * Sets the receiver's selection to the given item.
- * The current selection is cleared before the new item is selected.
- * <p>
- * If the item is not in the receiver, then it is ignored.
- * </p>
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (new TreeItem [] {item});
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- * </p>
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the items has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#deselectAll()
- */
-public void setSelection (TreeItem [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = items.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- boolean fixColumn = showFirstColumn ();
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- boolean first = true;
- for (int i = 0; i < length; i++) {
- TreeItem item = items [i];
- if (item == null) continue;
- if (item.isDisposed ()) break;
- if (item.parent != this) continue;
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, item.handle);
- showItem (path, false);
- if (first) {
- OS.gtk_tree_view_set_cursor (handle, path, 0, false);
- }
- OS.gtk_tree_selection_select_iter (selection, item.handle);
- OS.gtk_tree_path_free (path);
- first = false;
- }
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- if (fixColumn) hideFirstColumn ();
-}
-
-/**
- * Sets the column used by the sort indicator for the receiver. A null
- * value will clear the sort indicator. The current sort column is cleared
- * before the new column is set.
- *
- * @param column the column used by the sort indicator or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the column is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortColumn (TreeColumn column) {
- checkWidget ();
- if (column != null && column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (sortColumn != null && !sortColumn.isDisposed()) {
- OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, false);
- }
- sortColumn = column;
- if (sortColumn != null && sortDirection != SWT.NONE) {
- OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, true);
- OS.gtk_tree_view_column_set_sort_order (sortColumn.handle, sortDirection == SWT.DOWN ? 0 : 1);
- }
-}
-
-/**
- * Sets the direction of the sort indicator for the receiver. The value
- * can be one of <code>UP</code>, <code>DOWN</code> or <code>NONE</code>.
- *
- * @param direction the direction of the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortDirection (int direction) {
- checkWidget ();
- if (direction != SWT.UP && direction != SWT.DOWN && direction != SWT.NONE) return;
- sortDirection = direction;
- if (sortColumn == null || sortColumn.isDisposed ()) return;
- if (sortDirection == SWT.NONE) {
- OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, false);
- } else {
- OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, true);
- OS.gtk_tree_view_column_set_sort_order (sortColumn.handle, sortDirection == SWT.DOWN ? 0 : 1);
- }
-}
-
-/**
- * Sets the item which is currently at the top of the receiver.
- * This item can change when items are expanded, collapsed, scrolled
- * or new items are added or removed.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getTopItem()
- *
- * @since 2.1
- */
-public void setTopItem (TreeItem item) {
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (item.parent != this) return;
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, item.handle);
- showItem (path, false);
- OS.gtk_tree_view_scroll_to_cell (handle, path, 0, true, 0f, 0f);
- if (OS.GTK_VERSION < OS.VERSION (2, 8, 0)) {
- /*
- * Bug in GTK. According to the documentation, gtk_tree_view_scroll_to_cell
- * should vertically scroll the cell to the top if use_align is true and row_align is 0.
- * However, prior to version 2.8 it does not scroll at all. The fix is to determine
- * the new location and use gtk_tree_view_scroll_to_point.
- * If the widget is a pinhead, calling gtk_tree_view_scroll_to_point
- * will have no effect. Therefore, it is still neccessary to call
- * gtk_tree_view_scroll_to_cell.
- */
- OS.gtk_widget_realize (handle);
- GdkRectangle cellRect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (handle, path, 0, cellRect);
- int[] tx = new int[1], ty = new int[1];
- OS.gtk_tree_view_widget_to_tree_coords(handle, cellRect.x, cellRect.y, tx, ty);
- OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0]);
- }
- OS.gtk_tree_path_free (path);
-}
-
-/**
- * Shows the column. If the column is already showing in the receiver,
- * this method simply returns. Otherwise, the columns are scrolled until
- * the column is visible.
- *
- * @param column the column to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void showColumn (TreeColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (column.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (column.parent != this) return;
- /*
- * This code is intentionally commented. According to the
- * documentation, gtk_tree_view_scroll_to_cell should scroll the
- * minimum amount to show the column but instead it scrolls strangely.
- */
- //OS.gtk_tree_view_scroll_to_cell (handle, 0, column.handle, false, 0, 0);
- OS.gtk_widget_realize (handle);
- GdkRectangle cellRect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (handle, 0, column.handle, cellRect);
- GdkRectangle visibleRect = new GdkRectangle ();
- OS.gtk_tree_view_get_visible_rect (handle, visibleRect);
- if (cellRect.x < visibleRect.x) {
- OS.gtk_tree_view_scroll_to_point (handle, cellRect.x, -1);
- } else {
- int width = Math.min (visibleRect.width, cellRect.width);
- if (cellRect.x + width > visibleRect.x + visibleRect.width) {
- int tree_x = cellRect.x + width - visibleRect.width;
- OS.gtk_tree_view_scroll_to_point (handle, tree_x, -1);
- }
- }
-}
-
-boolean showFirstColumn () {
- /*
- * Bug in GTK. If no columns are visible, changing the selection
- * will fail. The fix is to temporarily make a column visible.
- */
- int columnCount = Math.max (1, this.columnCount);
- for (int i=0; i<columnCount; i++) {
- int /*long*/ column = OS.gtk_tree_view_get_column (handle, i);
- if (OS.gtk_tree_view_column_get_visible (column)) return false;
- }
- int /*long*/ firstColumn = OS.gtk_tree_view_get_column (handle, 0);
- OS.gtk_tree_view_column_set_visible (firstColumn, true);
- return true;
-}
-
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#showItem(TreeItem)
- */
-public void showSelection () {
- checkWidget();
- TreeItem [] items = getSelection ();
- if (items.length != 0 && items [0] != null) showItem (items [0]);
-}
-
-void showItem (int /*long*/ path, boolean scroll) {
- int depth = OS.gtk_tree_path_get_depth (path);
- if (depth > 1) {
- int [] indices = new int [depth - 1];
- int /*long*/ indicesPtr = OS.gtk_tree_path_get_indices (path);
- OS.memmove (indices, indicesPtr, indices.length * 4);
- int /*long*/ tempPath = OS.gtk_tree_path_new ();
- for (int i=0; i<indices.length; i++) {
- OS.gtk_tree_path_append_index (tempPath, indices [i]);
- OS.gtk_tree_view_expand_row (handle, tempPath, false);
- }
- OS.gtk_tree_path_free (tempPath);
- }
- if (scroll) {
- OS.gtk_widget_realize (handle);
- GdkRectangle cellRect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (handle, path, 0, cellRect);
- boolean isHidden = cellRect.y == 0 && cellRect.height == 0;
- int [] tx = new int [1], ty = new int [1];
- OS.gtk_tree_view_widget_to_tree_coords (handle, cellRect.x, cellRect.y, tx, ty);
- GdkRectangle visibleRect = new GdkRectangle ();
- OS.gtk_tree_view_get_visible_rect (handle, visibleRect);
- if (!isHidden) {
- if (ty[0] < visibleRect.y || ty[0] + cellRect.height > visibleRect.y + visibleRect.height) {
- isHidden = true;
- }
- }
- if (isHidden) {
- /*
- * This code intentionally commented.
- * Bug in GTK. According to the documentation, gtk_tree_view_scroll_to_cell
- * should scroll the minimum amount to show the cell if use_align is false.
- * However, what actually happens is the cell is scrolled to the top.
- * The fix is to determine the new location and use gtk_tree_view_scroll_to_point.
- * If the widget is a pinhead, calling gtk_tree_view_scroll_to_point
- * will have no effect. Therefore, it is still neccessary to
- * call gtk_tree_view_scroll_to_cell.
- */
- // OS.gtk_tree_view_scroll_to_cell (handle, path, 0, depth != 1, 0.5f, 0.0f);
- if (depth != 1) {
- OS.gtk_tree_view_scroll_to_cell (handle, path, 0, true, 0.5f, 0.0f);
- } else {
- if (ty[0] < visibleRect.y ) {
- OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0]);
- } else {
- int height = Math.min (visibleRect.height, cellRect.height);
- if (ty[0] + height > visibleRect.y + visibleRect.height) {
- OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0] + cellRect.height - visibleRect.height);
- }
- }
- }
- }
- }
-}
-
-/**
- * Shows the item. If the item is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled
- * and expanded until the item is visible.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#showSelection()
- */
-public void showItem (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (item.parent != this) return;
- int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, item.handle);
- showItem (path, true);
- OS.gtk_tree_path_free (path);
-}
-
-int /*long*/ treeSelectionProc (int /*long*/ model, int /*long*/ path, int /*long*/ iter, int[] selection, int length) {
- if (selection != null) {
- int [] index = new int [1];
- OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, index, -1);
- selection [(int)/*64*/length] = index [0];
- }
- return 0;
-}
-
-void updateScrollBarValue (ScrollBar bar) {
- super.updateScrollBarValue (bar);
- /*
- * Bug in GTK. Scrolling changes the XWindow position
- * and makes the child widgets appear to scroll even
- * though when queried their position is unchanged.
- * The fix is to queue a resize event for each child to
- * force the position to be corrected.
- */
- int /*long*/ parentHandle = parentingHandle ();
- int /*long*/ list = OS.gtk_container_get_children (parentHandle);
- if (list == 0) return;
- int /*long*/ temp = list;
- while (temp != 0) {
- int /*long*/ widget = OS.g_list_data (temp);
- if (widget != 0) OS.gtk_widget_queue_resize (widget);
- temp = OS.g_list_next (temp);
- }
- OS.g_list_free (list);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java
deleted file mode 100644
index a3b6ee52ff..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java
+++ /dev/null
@@ -1,697 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a column in a tree widget.
- * <p><dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd> Move, Resize, Selection</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT and CENTER may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TreeColumn extends Item {
- int /*long*/ labelHandle, imageHandle, buttonHandle;
- Tree parent;
- int modelIndex, lastButton, lastTime, lastX, lastWidth;
- boolean customDraw, useFixedWidth;
- String toolTipText;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeColumn (Tree parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (parent.getColumnCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeColumn (Tree parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (index);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize,typedListener);
- addListener (SWT.Move,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the column header is selected.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createWidget (int index) {
- parent.createItem (this, index);
- setOrientation ();
- hookEvents ();
- register ();
- text = "";
-}
-
-void deregister() {
- super.deregister ();
- display.removeWidget (handle);
- if (buttonHandle != 0) display.removeWidget (buttonHandle);
- if (labelHandle != 0) display.removeWidget (labelHandle);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget();
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-/**
- * Gets the moveable attribute. A column that is
- * not moveable cannot be reordered by the user
- * by dragging the header but may be reordered
- * by the programmer.
- *
- * @return the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
-public boolean getMoveable() {
- checkWidget();
- return OS.gtk_tree_view_column_get_reorderable (handle);
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Tree</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Tree getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Gets the resizable attribute. A column that is
- * not resizable cannot be dragged by the user but
- * may be resized by the programmer.
- *
- * @return the resizable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getResizable () {
- checkWidget();
- return OS.gtk_tree_view_column_get_resizable (handle);
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget();
- if (!OS.gtk_tree_view_column_get_visible (handle)) {
- return 0;
- }
- if (useFixedWidth) return OS.gtk_tree_view_column_get_fixed_width (handle);
- return OS.gtk_tree_view_column_get_width (handle);
-}
-
-int /*long*/ gtk_clicked (int /*long*/ widget) {
- /*
- * There is no API to get a double click on a table column. Normally, when
- * the mouse is double clicked, this is indicated by GDK_2BUTTON_PRESS
- * but the table column sends the click signal on button release. The fix is to
- * test for double click by remembering the last click time and mouse button
- * and testing for the double click interval.
- */
- boolean doubleClick = false;
- boolean postEvent = true;
- int /*long*/ eventPtr = OS.gtk_get_current_event ();
- if (eventPtr != 0) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, eventPtr, GdkEventButton.sizeof);
- OS.gdk_event_free (eventPtr);
- switch (gdkEvent.type) {
- case OS.GDK_BUTTON_RELEASE: {
- int clickTime = display.getDoubleClickTime ();
- int eventTime = gdkEvent.time, eventButton = gdkEvent.button;
- if (lastButton == eventButton && lastTime != 0 && Math.abs (lastTime - eventTime) <= clickTime) {
- doubleClick = true;
- }
- lastTime = eventTime == 0 ? 1: eventTime;
- lastButton = eventButton;
- break;
- }
- case OS.GDK_MOTION_NOTIFY: {
- /*
- * Bug in GTK. Dragging a column in a GtkTreeView causes a clicked
- * signal to be emitted even though the mouse button was never released.
- * The fix to ignore the signal if the current GDK event is a motion notify.
- * The GTK bug was fixed in version 2.6
- */
- if (OS.GTK_VERSION < OS.VERSION (2, 6, 0)) postEvent = false;
- break;
- }
- }
- }
- if (postEvent) postEvent (doubleClick ? SWT.DefaultSelection : SWT.Selection);
- return 0;
-}
-
-int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) {
- GdkEvent event = new GdkEvent ();
- OS.memmove (event, gdkEvent, GdkEvent.sizeof);
- switch (event.type) {
- case OS.GDK_BUTTON_PRESS: {
- GdkEventButton gdkEventButton = new GdkEventButton ();
- OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof);
- if (gdkEventButton.button == 3) {
- parent.showMenu ((int) gdkEventButton.x_root, (int) gdkEventButton.y_root);
- }
- break;
- }
- }
- return 0;
-}
-
-int /*long*/ gtk_mnemonic_activate (int /*long*/ widget, int /*long*/ arg1) {
- return parent.gtk_mnemonic_activate (widget, arg1);
-}
-
-int /*long*/ gtk_size_allocate (int /*long*/ widget, int /*long*/ allocation) {
- useFixedWidth = false;
- int x = OS.GTK_WIDGET_X (widget);
- int width = OS.GTK_WIDGET_WIDTH (widget);
- if (x != lastX) {
- lastX = x;
- sendEvent (SWT.Move);
- }
- if (width != lastWidth) {
- lastWidth = width;
- sendEvent (SWT.Resize);
- }
- return 0;
-}
-
-void hookEvents () {
- super.hookEvents ();
- OS.g_signal_connect_closure (handle, OS.clicked, display.closures [CLICKED], false);
- if (buttonHandle != 0) {
- OS.g_signal_connect_closure_by_id (buttonHandle, display.signalIds [SIZE_ALLOCATE], 0, display.closures [SIZE_ALLOCATE], false);
- OS.g_signal_connect_closure_by_id (buttonHandle, display.signalIds [EVENT_AFTER], 0, display.closures [EVENT_AFTER], false);
- }
- if (labelHandle != 0) OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false);
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void pack () {
- checkWidget();
- int width = 0;
- if (buttonHandle != 0) {
- GtkRequisition requisition = new GtkRequisition ();
- OS.gtk_widget_size_request (buttonHandle, requisition);
- width = requisition.width;
- }
- if ((parent.style & SWT.VIRTUAL) != 0) {
- //NOT DONE
- } else {
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (OS.gtk_tree_model_get_iter_first (parent.modelHandle, iter)) {
- do {
- width = Math.max (width, parent.calculateWidth (handle, iter, true));
- } while (OS.gtk_tree_model_iter_next(parent.modelHandle, iter));
- }
- OS.g_free (iter);
- }
- setWidth(width);
-}
-
-void register () {
- super.register ();
- display.addWidget (handle, this);
- if (buttonHandle != 0) display.addWidget (buttonHandle, this);
- if (labelHandle != 0) display.addWidget (labelHandle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- handle = buttonHandle = labelHandle = imageHandle = 0;
- modelIndex = -1;
- parent = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (parent.sortColumn == this) {
- parent.sortColumn = null;
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>.
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget();
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- int index = parent.indexOf (this);
- if (index == -1 || index == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- parent.createRenderers (handle, modelIndex, index == 0, style);
-}
-
-void setFontDescription (int /*long*/ font) {
- OS.gtk_widget_modify_font (labelHandle, font);
- OS.gtk_widget_modify_font (imageHandle, font);
-}
-
-public void setImage (Image image) {
- checkWidget ();
- super.setImage (image);
- if (image != null) {
- ImageList headerImageList = parent.headerImageList;
- if (headerImageList == null) {
- headerImageList = parent.headerImageList = new ImageList ();
- }
- int imageIndex = headerImageList.indexOf (image);
- if (imageIndex == -1) imageIndex = headerImageList.add (image);
- int /*long*/ pixbuf = headerImageList.getPixbuf (imageIndex);
- OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf);
- OS.gtk_widget_show (imageHandle);
- } else {
- OS.gtk_image_set_from_pixbuf (imageHandle, 0);
- OS.gtk_widget_hide (imageHandle);
- }
-}
-
-/**
- * Sets the moveable attribute. A column that is
- * moveable can be reordered by the user by dragging
- * the header. A column that is not moveable cannot be
- * dragged by the user but may be reordered
- * by the programmer.
- *
- * @param moveable the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#setColumnOrder(int[])
- * @see Tree#getColumnOrder()
- * @see TreeColumn#getMoveable()
- * @see SWT#Move
- *
- * @since 3.2
- */
-public void setMoveable (boolean moveable) {
- checkWidget();
- OS.gtk_tree_view_column_set_reorderable (handle, moveable);
-}
-
-void setOrientation() {
- if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) {
- if (buttonHandle != 0) {
- OS.gtk_widget_set_direction (buttonHandle, OS.GTK_TEXT_DIR_RTL);
- OS.gtk_container_forall (buttonHandle, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL);
- }
- }
-}
-
-/**
- * Sets the resizable attribute. A column that is
- * not resizable cannot be dragged by the user but
- * may be resized by the programmer.
- *
- * @param resizable the resize attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setResizable (boolean resizable) {
- checkWidget();
- OS.gtk_tree_view_column_set_resizable (handle, resizable);
-}
-
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- char [] chars = fixMnemonic (string);
- byte [] buffer = Converter.wcsToMbcs (null, chars, true);
- OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer);
- if (string.length () != 0) {
- OS.gtk_widget_show (labelHandle);
- } else {
- OS.gtk_widget_hide (labelHandle);
- }
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setToolTipText (String string) {
- checkWidget();
- Shell shell = parent._getShell ();
- setToolTipText (shell, string);
- toolTipText = string;
-}
-
-void setToolTipText (Shell shell, String newString) {
- shell.setToolTipText (buttonHandle, newString);
-}
-
-/**
- * Sets the width of the receiver.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int width) {
- checkWidget();
- if (width < 0) return;
- if (width == lastWidth) return;
- if (width > 0) {
- useFixedWidth = true;
- OS.gtk_tree_view_column_set_fixed_width (handle, width);
- }
- /*
- * Bug in GTK. For some reason, calling gtk_tree_view_column_set_visible()
- * when the parent is not realized fails to show the column. The fix is to
- * ensure that the table has been realized.
- */
- if (width != 0) OS.gtk_widget_realize (parent.handle);
- OS.gtk_tree_view_column_set_visible (handle, width != 0);
- lastWidth = width;
- sendEvent (SWT.Resize);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java
deleted file mode 100644
index 1102499b31..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java
+++ /dev/null
@@ -1,1769 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a hierarchy of tree items in a tree widget.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TreeItem extends Item {
- Tree parent;
- Font font;
- Font[] cellFont;
- boolean cached, grayed;
- static final int EXPANDER_EXTRA_PADDING = 4;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>)
- * and a style value describing its behavior and appearance.
- * The item is added to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (Tree parent, int style) {
- this (checkNull (parent), 0, style, -1, true);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>),
- * a style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (Tree parent, int style, int index) {
- this (checkNull (parent), 0, style, checkIndex (index), true);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>)
- * and a style value describing its behavior and appearance.
- * The item is added to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parentItem a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (TreeItem parentItem, int style) {
- this (checkNull (parentItem).parent, parentItem.handle, style, -1, true);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>),
- * a style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parentItem a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (TreeItem parentItem, int style, int index) {
- this (checkNull (parentItem).parent, parentItem.handle, style, checkIndex (index), true);
-}
-
-TreeItem (Tree parent, int /*long*/ parentIter, int style, int index, boolean create) {
- super (parent, style);
- this.parent = parent;
- if (create) {
- parent.createItem (this, parentIter, index);
- } else {
- handle = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- OS.gtk_tree_model_iter_nth_child (parent.modelHandle, handle, parentIter, index);
- }
-}
-
-static int checkIndex (int index) {
- if (index < 0) SWT.error (SWT.ERROR_INVALID_RANGE);
- return index;
-}
-
-static TreeItem checkNull (TreeItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-
-static Tree checkNull (Tree control) {
- if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return control;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-Color _getBackground () {
- int /*long*/ [] ptr = new int /*long*/ [1];
- OS.gtk_tree_model_get (parent.modelHandle, handle, Tree.BACKGROUND_COLUMN, ptr, -1);
- if (ptr [0] == 0) return parent.getBackground ();
- GdkColor gdkColor = new GdkColor ();
- OS.memmove (gdkColor, ptr [0], GdkColor.sizeof);
- return Color.gtk_new (display, gdkColor);
-}
-
-Color _getBackground (int index) {
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count - 1) return _getBackground ();
- int /*long*/ [] ptr = new int /*long*/ [1];
- int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex;
- OS.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Tree.CELL_BACKGROUND, ptr, -1);
- if (ptr [0] == 0) return _getBackground ();
- GdkColor gdkColor = new GdkColor ();
- OS.memmove (gdkColor, ptr [0], GdkColor.sizeof);
- return Color.gtk_new (display, gdkColor);
-}
-
-boolean _getChecked () {
- int /*long*/ [] ptr = new int /*long*/ [1];
- OS.gtk_tree_model_get (parent.modelHandle, handle, Tree.CHECKED_COLUMN, ptr, -1);
- return ptr [0] != 0;
-}
-
-Color _getForeground () {
- int /*long*/ [] ptr = new int /*long*/ [1];
- OS.gtk_tree_model_get (parent.modelHandle, handle, Tree.FOREGROUND_COLUMN, ptr, -1);
- if (ptr [0] == 0) return parent.getForeground ();
- GdkColor gdkColor = new GdkColor ();
- OS.memmove (gdkColor, ptr [0], GdkColor.sizeof);
- return Color.gtk_new (display, gdkColor);
-}
-
-Color _getForeground (int index) {
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count - 1) return _getForeground ();
- int /*long*/ [] ptr = new int /*long*/ [1];
- int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex;
- OS.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Tree.CELL_FOREGROUND, ptr, -1);
- if (ptr [0] == 0) return _getForeground ();
- GdkColor gdkColor = new GdkColor ();
- OS.memmove (gdkColor, ptr [0], GdkColor.sizeof);
- return Color.gtk_new (display, gdkColor);
-}
-
-Image _getImage (int index) {
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return null;
- int /*long*/ [] ptr = new int /*long*/ [1];
- int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex;
- OS.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Tree.CELL_PIXBUF, ptr, -1);
- if (ptr [0] == 0) return null;
- ImageList imageList = parent.imageList;
- int imageIndex = imageList.indexOf (ptr [0]);
- if (imageIndex == -1) return null;
- return imageList.get (imageIndex);
-}
-
-String _getText (int index) {
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return "";
- int /*long*/ [] ptr = new int /*long*/ [1];
- int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex;
- OS.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Tree.CELL_TEXT, ptr, -1);
- if (ptr [0] == 0) return ""; //$NON-NLS-1$
- int length = OS.strlen (ptr [0]);
- byte[] buffer = new byte [length];
- OS.memmove (buffer, ptr [0], length);
- OS.g_free (ptr [0]);
- return new String (Converter.mbcsToWcs (null, buffer));
-}
-
-void clear () {
- if (parent.currentItem == this) return;
- if (cached || (parent.style & SWT.VIRTUAL) == 0) {
- int columnCount = OS.gtk_tree_model_get_n_columns (parent.modelHandle);
- for (int i=Tree.CHECKED_COLUMN; i<columnCount; i++) {
- OS.gtk_tree_store_set (parent.modelHandle, handle, i, 0, -1);
- }
- /*
- * Bug in GTK. When using fixed-height-mode,
- * row changes do not cause the row to be repainted. The fix is to
- * invalidate the row when it is cleared.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) {
- redraw ();
- }
- }
- }
- cached = false;
- font = null;
- cellFont = null;
-}
-
-/**
- * Clears the item at the given zero-relative index in the receiver.
- * The text, icon and other attributes of the item are set to the default
- * value. If the tree was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param index the index of the item to clear
- * @param all <code>true</code> if all child items of the indexed item should be
- * cleared recursively, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clear (int index, boolean all) {
- checkWidget ();
- parent.clear (handle, index, all);
-}
-
-/**
- * Clears all the items in the receiver. The text, icon and other
- * attributes of the items are set to their default values. If the
- * tree was created with the <code>SWT.VIRTUAL</code> style, these
- * attributes are requested again as needed.
- *
- * @param all <code>true</code> if all child items should be cleared
- * recursively, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clearAll (boolean all) {
- checkWidget ();
- parent.clearAll (all, handle);
-}
-
-void destroyWidget () {
- parent.releaseItem (this, false);
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns the receiver's background color.
- *
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public Color getBackground () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return _getBackground ();
-}
-
-/**
- * Returns the background color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Color getBackground (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return _getBackground (index);
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent at a column in the tree.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding column rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Rectangle getBounds (int index) {
- // TODO fully test on early and later versions of GTK
- checkWidget();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int /*long*/ parentHandle = parent.handle;
- int /*long*/ column = 0;
- if (index >= 0 && index < parent.columnCount) {
- column = parent.columns [index].handle;
- } else {
- column = OS.gtk_tree_view_get_column (parentHandle, index);
- }
- if (column == 0) return new Rectangle (0, 0, 0, 0);
- int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- OS.gtk_widget_realize (parentHandle);
- GdkRectangle rect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect);
- if ((parent.getStyle () & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth () - rect.width - rect.x;
-
- if (OS.GTK_VERSION < OS.VERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) == column) {
- int [] buffer = new int [1];
- OS.gtk_widget_style_get (parentHandle, OS.expander_size, buffer, 0);
- rect.x += buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING;
- rect.width -= buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING;
- OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0);
- rect.x += buffer [0];
- //rect.width -= buffer [0]; // TODO Is this required for some versions?
- }
- /*
- * Bug in GTK. In GTK 2.8.x, the cell area is left aligned even
- * when the widget is mirrored. The fix is to sum up the indentation
- * of the expanders.
- */
- if ((parent.getStyle () & SWT.MIRRORED) != 0 && (OS.GTK_VERSION < OS.VERSION (2, 10, 0))) {
- int depth = OS.gtk_tree_path_get_depth (path);
- int [] expanderSize = new int [1];
- OS.gtk_widget_style_get (parentHandle, OS.expander_size, expanderSize, 0);
- rect.x += depth * (expanderSize[0] + TreeItem.EXPANDER_EXTRA_PADDING);
- }
- OS.gtk_tree_path_free (path);
-
- if (index == 0 && (parent.style & SWT.CHECK) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 1, 3)) {
- int [] x = new int [1], w = new int [1];
- OS.gtk_tree_view_column_cell_get_position (column, parent.checkRenderer, x, w);
- rect.x += x [0] + w [0];
- rect.width -= x [0] + w [0];
- } else {
- int [] w = new int [1];
- OS.gtk_cell_renderer_get_size (parent.checkRenderer, parentHandle, null, null, null, w, null);
- int [] buffer = new int [1];
- OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0);
- rect.x += w [0] + buffer [0];
- rect.width -= w [0] + buffer [0];
- }
- }
- int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0;
- return new Rectangle (rect.x, rect.y, width, rect.height + 1);
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- // TODO fully test on early and later versions of GTK
- // shifted a bit too far right on later versions of GTK - however, old Tree also had this problem
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int /*long*/ parentHandle = parent.handle;
- int /*long*/ column = OS.gtk_tree_view_get_column (parentHandle, 0);
- if (column == 0) return new Rectangle (0, 0, 0, 0);
- int /*long*/ textRenderer = parent.getTextRenderer (column);
- int /*long*/ pixbufRenderer = parent.getPixbufRenderer (column);
- if (textRenderer == 0 || pixbufRenderer == 0) return new Rectangle (0, 0, 0, 0);
-
- int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- OS.gtk_widget_realize (parentHandle);
-
- boolean isExpander = OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle) > 0;
- boolean isExpanded = OS.gtk_tree_view_row_expanded (parentHandle, path);
- OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, isExpander, isExpanded);
-
- GdkRectangle rect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect);
- if ((parent.getStyle () & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth () - rect.width - rect.x;
- int right = rect.x + rect.width;
-
- int [] x = new int [1], w = new int [1];
- parent.ignoreSize = true;
- OS.gtk_cell_renderer_get_size (textRenderer, parentHandle, null, null, null, w, null);
- parent.ignoreSize = false;
- rect.width = w [0];
- int [] buffer = new int [1];
- if (OS.GTK_VERSION < OS.VERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) == column) {
- OS.gtk_widget_style_get (parentHandle, OS.expander_size, buffer, 0);
- rect.x += buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING;
- }
- /*
- * Bug in GTK. In GTK 2.8.x, the cell area is left aligned even
- * when the widget is mirrored. The fix is to sum up the indentation
- * of the expanders.
- */
- if ((parent.getStyle () & SWT.MIRRORED) != 0 && (OS.GTK_VERSION < OS.VERSION (2, 10, 0))) {
- int depth = OS.gtk_tree_path_get_depth (path);
- int [] expanderSize = new int [1];
- OS.gtk_widget_style_get (parentHandle, OS.expander_size, expanderSize, 0);
- rect.x += depth * (expanderSize[0] + TreeItem.EXPANDER_EXTRA_PADDING);
- }
- OS.gtk_tree_path_free (path);
-
- OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0);
- int horizontalSeparator = buffer[0];
- rect.x += horizontalSeparator;
-
- if (OS.GTK_VERSION >= OS.VERSION (2, 1, 3)) {
- OS.gtk_tree_view_column_cell_get_position (column, textRenderer, x, null);
- rect.x += x [0];
- } else {
- if ((parent.style & SWT.CHECK) != 0) {
- OS.gtk_cell_renderer_get_size (parent.checkRenderer, parentHandle, null, null, null, w, null);
- rect.x += w [0] + horizontalSeparator;
- }
- OS.gtk_cell_renderer_get_size (pixbufRenderer, parentHandle, null, null, null, w, null);
- rect.x += w [0] + horizontalSeparator;
- }
- if (parent.columnCount > 0) {
- if (rect.x + rect.width > right) {
- rect.width = Math.max (0, right - rect.x);
- }
- }
- int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0;
- return new Rectangle (rect.x, rect.y, width, rect.height + 1);
-}
-
-/**
- * Returns <code>true</code> if the receiver is checked,
- * and false otherwise. When the parent does not have
- * the <code>CHECK style, return false.
- * <p>
- *
- * @return the checked state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getChecked () {
- checkWidget();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return _getChecked ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is expanded,
- * and false otherwise.
- * <p>
- *
- * @return the expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getExpanded () {
- checkWidget();
- int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- boolean answer = OS.gtk_tree_view_row_expanded (parent.handle, path);
- OS.gtk_tree_path_free (path);
- return answer;
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information for this item.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return font != null ? font : parent.getFont ();
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information
- * for the specified cell in this item.
- *
- * @param index the column index
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Font getFont (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count - 1) return getFont ();
- if (cellFont == null || cellFont [index] == null) return getFont ();
- return cellFont [index];
-}
-
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public Color getForeground () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return _getForeground ();
-}
-
-/**
- *
- * Returns the foreground color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Color getForeground (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return _getForeground (index);
-}
-
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the parent does not have
- * the <code>CHECK style, return false.
- * <p>
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getGrayed () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return grayed;
-}
-
-public Image getImage () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return getImage (0);
-}
-
-/**
- * Returns the image stored at the given column index in the receiver,
- * or null if the image has not been set or if the column does not exist.
- *
- * @param index the column index
- * @return the image stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Image getImage (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return _getImage (index);
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of an image at a column in the
- * tree.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding image rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Rectangle getImageBounds (int index) {
- // TODO fully test on early and later versions of GTK
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int /*long*/ parentHandle = parent.handle;
- int /*long*/ column = 0;
- if (index >= 0 && index < parent.getColumnCount ()) {
- column = parent.columns [index].handle;
- } else {
- column = OS.gtk_tree_view_get_column (parentHandle, index);
- }
- if (column == 0) return new Rectangle (0, 0, 0, 0);
- int /*long*/ pixbufRenderer = parent.getPixbufRenderer (column);
- if (pixbufRenderer == 0) return new Rectangle (0, 0, 0, 0);
- GdkRectangle rect = new GdkRectangle ();
- int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- OS.gtk_widget_realize (parentHandle);
- OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect);
- if ((parent.getStyle () & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth () - rect.width - rect.x;
- if (OS.GTK_VERSION < OS.VERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) == column) {
- int [] buffer = new int [1];
- OS.gtk_widget_style_get (parentHandle, OS.expander_size, buffer, 0);
- rect.x += buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING;
- rect.width -= buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING;
- //OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0);
- //int horizontalSeparator = buffer[0];
- //rect.x += horizontalSeparator;
- }
- /*
- * Bug in GTK. In GTK 2.8.x, the cell area is left aligned even
- * when the widget is mirrored. The fix is to sum up the indentation
- * of the expanders.
- */
- if ((parent.getStyle () & SWT.MIRRORED) != 0 && (OS.GTK_VERSION < OS.VERSION (2, 10, 0))) {
- int depth = OS.gtk_tree_path_get_depth (path);
- int [] expanderSize = new int [1];
- OS.gtk_widget_style_get (parentHandle, OS.expander_size, expanderSize, 0);
- rect.x += depth * (expanderSize[0] + TreeItem.EXPANDER_EXTRA_PADDING);
- }
- OS.gtk_tree_path_free (path);
-
- /*
- * The OS call gtk_cell_renderer_get_size() provides the width of image to be drawn
- * by the cell renderer. If there is no image in the cell, the width is zero. If the table contains
- * images of varying widths, gtk_cell_renderer_get_size() will return the width of the image,
- * not the width of the area in which the image is drawn.
- * New API was added in GTK 2.1.3 for determining the full width of the renderer area.
- * For earlier versions of GTK, the result is only correct if all rows have images of the same
- * width.
- */
- if (OS.GTK_VERSION >= OS.VERSION (2, 1, 3)) {
- int [] x = new int [1], w = new int[1];
- OS.gtk_tree_view_column_cell_get_position (column, pixbufRenderer, x, w);
- rect.x += x [0];
- rect.width = w [0];
- } else {
- int [] w = new int [1];
- OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, false, false);
- OS.gtk_cell_renderer_get_size (pixbufRenderer, parentHandle, null, null, null, w, null);
- rect.width = w [0];
- }
- int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width : 0;
- return new Rectangle (rect.x, rect.y, width, rect.height + 1);
-}
-
-/**
- * Returns the number of items contained in the receiver
- * that are direct item children of the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle);
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public TreeItem getItem (int index) {
- checkWidget();
- if (index < 0) error (SWT.ERROR_INVALID_RANGE);
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int itemCount = OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle);
- if (index >= itemCount) error (SWT.ERROR_INVALID_RANGE);
- return parent._getItem (handle, index);
-}
-
-/**
- * Returns a (possibly empty) array of <code>TreeItem</code>s which
- * are the direct item children of the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem [] getItems () {
- checkWidget();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getItems (handle);
-}
-
-String getNameText () {
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (!cached) return "*virtual*"; //$NON-NLS-1$
- }
- return super.getNameText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Tree</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Tree getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>TreeItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem getParentItem () {
- checkWidget();
- int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- TreeItem item = null;
- int depth = OS.gtk_tree_path_get_depth (path);
- if (depth > 1) {
- OS.gtk_tree_path_up (path);
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (OS.gtk_tree_model_get_iter (parent.modelHandle, iter, path)) {
- item = parent._getItem (iter);
- }
- OS.g_free (iter);
- }
- OS.gtk_tree_path_free (path);
- return item;
-}
-
-public String getText () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return getText (0);
-}
-
-/**
- * Returns the text stored at the given column index in the receiver,
- * or empty string if the text has not been set.
- *
- * @param index the column index
- * @return the text stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public String getText (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return _getText (index);
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of the text at a column in the
- * tree.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding text rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Rectangle getTextBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return new Rectangle (0, 0, 0, 0);
- // TODO fully test on early and later versions of GTK
- // shifted a bit too far right on later versions of GTK - however, old Tree also had this problem
- int /*long*/ parentHandle = parent.handle;
- int /*long*/ column = 0;
- if (index >= 0 && index < parent.columnCount) {
- column = parent.columns [index].handle;
- } else {
- column = OS.gtk_tree_view_get_column (parentHandle, index);
- }
- if (column == 0) return new Rectangle (0, 0, 0, 0);
- int /*long*/ textRenderer = parent.getTextRenderer (column);
- int /*long*/ pixbufRenderer = parent.getPixbufRenderer (column);
- if (textRenderer == 0 || pixbufRenderer == 0) return new Rectangle (0, 0, 0, 0);
-
- int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- OS.gtk_widget_realize (parentHandle);
-
- boolean isExpander = OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle) > 0;
- boolean isExpanded = OS.gtk_tree_view_row_expanded (parentHandle, path);
- OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, isExpander, isExpanded);
-
- GdkRectangle rect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect);
- if ((parent.getStyle () & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth () - rect.width - rect.x;
- int right = rect.x + rect.width;
-
- int [] x = new int [1], w = new int [1];
- parent.ignoreSize = true;
- OS.gtk_cell_renderer_get_size (textRenderer, parentHandle, null, null, null, w, null);
- parent.ignoreSize = false;
- int [] buffer = new int [1];
- if (OS.GTK_VERSION < OS.VERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) == column) {
- OS.gtk_widget_style_get (parentHandle, OS.expander_size, buffer, 0);
- rect.x += buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING;
- }
- /*
- * Bug in GTK. In GTK 2.8.x, the cell area is left aligned even
- * when the widget is mirrored. The fix is to sum up the indentation
- * of the expanders.
- */
- if ((parent.getStyle () & SWT.MIRRORED) != 0 && (OS.GTK_VERSION < OS.VERSION (2, 10, 0))) {
- int depth = OS.gtk_tree_path_get_depth (path);
- int [] expanderSize = new int [1];
- OS.gtk_widget_style_get (parentHandle, OS.expander_size, expanderSize, 0);
- rect.x += depth * (expanderSize[0] + TreeItem.EXPANDER_EXTRA_PADDING);
- }
- OS.gtk_tree_path_free (path);
-
- OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0);
- int horizontalSeparator = buffer[0];
- rect.x += horizontalSeparator;
- if (OS.GTK_VERSION >= OS.VERSION (2, 1, 3)) {
- OS.gtk_tree_view_column_cell_get_position (column, textRenderer, x, null);
- rect.x += x [0];
- } else {
- if ((parent.style & SWT.CHECK) != 0) {
- OS.gtk_cell_renderer_get_size (parent.checkRenderer, parentHandle, null, null, null, w, null);
- rect.x += w [0] + horizontalSeparator;
- }
- OS.gtk_cell_renderer_get_size (pixbufRenderer, parentHandle, null, null, null, w, null);
- rect.x += w [0] + horizontalSeparator;
- }
- if (parent.columnCount > 0) {
- if (rect.x + rect.width > right) {
- rect.width = Math.max (0, right - rect.x);
- }
- }
- int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0;
- return new Rectangle (rect.x, rect.y, width, rect.height + 1);
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int indexOf (TreeItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- int index = -1;
- boolean isParent = false;
- int /*long*/ currentPath = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- int /*long*/ parentPath = OS.gtk_tree_model_get_path (parent.modelHandle, item.handle);
- int depth = OS.gtk_tree_path_get_depth (parentPath);
- if (depth > 1 && OS.gtk_tree_path_up(parentPath)) {
- if (OS.gtk_tree_path_compare(currentPath, parentPath) == 0) isParent = true;
- }
- OS.gtk_tree_path_free (currentPath);
- OS.gtk_tree_path_free (parentPath);
- if (!isParent) return index;
- int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, item.handle);
- if (depth > 1) {
- int /*long*/ indices = OS.gtk_tree_path_get_indices (path);
- if (indices != 0) {
- int[] temp = new int[depth];
- OS.memmove (temp, indices, 4 * temp.length);
- index = temp[temp.length - 1];
- }
- }
- OS.gtk_tree_path_free (path);
- return index;
-}
-
-void redraw () {
- int /*long*/ parentHandle = parent.handle;
- if ((OS.GTK_WIDGET_FLAGS (parentHandle) & OS.GTK_REALIZED) != 0) {
- int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- GdkRectangle rect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (parentHandle, path, 0, rect);
- OS.gtk_tree_path_free (path);
- int /*long*/ window = OS.gtk_tree_view_get_bin_window (parentHandle);
- rect.x = 0;
- int [] w = new int [1], h = new int [1];
- OS.gdk_drawable_get_size (window, w, h);
- rect.width = w [0];
- OS.gdk_window_invalidate_rect (window, rect, false);
- }
-}
-
-void releaseChildren (boolean destroy) {
- if (destroy) {
- parent.releaseItems (handle);
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- if (handle != 0) OS.g_free (handle);
- handle = 0;
- super.releaseHandle ();
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- font = null;
- cellFont = null;
-}
-
-/**
- * Removes all of the items from the receiver.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void removeAll () {
- checkWidget ();
- int /*long*/ modelHandle = parent.modelHandle;
- int length = OS.gtk_tree_model_iter_n_children (modelHandle, handle);
- if (length == 0) return;
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- if (iter == 0) error (SWT.ERROR_NO_HANDLES);
- if (parent.fixAccessibility ()) {
- parent.ignoreAccessibility = true;
- }
- int /*long*/ selection = OS.gtk_tree_view_get_selection (parent.handle);
- int [] value = new int [1];
- while (OS.gtk_tree_model_iter_children (modelHandle, iter, handle)) {
- OS.gtk_tree_model_get (modelHandle, iter, Tree.ID_COLUMN, value, -1);
- TreeItem item = value [0] != -1 ? parent.items [value [0]] : null;
- if (item != null && !item.isDisposed ()) {
- item.dispose ();
- } else {
- OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- OS.gtk_tree_store_remove (modelHandle, iter);
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
- }
- }
- if (parent.fixAccessibility ()) {
- parent.ignoreAccessibility = false;
- OS.g_object_notify (parent.handle, OS.model);
- }
- OS.g_free (iter);
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public void setBackground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (_getBackground ().equals (color)) return;
- GdkColor gdkColor = color != null ? color.handle : null;
- OS.gtk_tree_store_set (parent.modelHandle, handle, Tree.BACKGROUND_COLUMN, gdkColor, -1);
- /*
- * Bug in GTK. When using fixed-height-mode,
- * row changes do not cause the row to be repainted. The fix is to
- * invalidate the row when it is cleared.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) {
- redraw ();
- }
- }
- cached = true;
-}
-
-/**
- * Sets the background color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- *
- */
-public void setBackground (int index, Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (_getBackground (index).equals (color)) return;
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex;
- GdkColor gdkColor = color != null ? color.handle : null;
- OS.gtk_tree_store_set (parent.modelHandle, handle, modelIndex + Tree.CELL_BACKGROUND, gdkColor, -1);
- /*
- * Bug in GTK. When using fixed-height-mode,
- * row changes do not cause the row to be repainted. The fix is to
- * invalidate the row when it is cleared.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) {
- redraw ();
- }
- }
- cached = true;
-
- if (color != null) {
- boolean customDraw = (parent.columnCount == 0) ? parent.firstCustomDraw : parent.columns [index].customDraw;
- if (!customDraw) {
- if ((parent.style & SWT.VIRTUAL) == 0) {
- int /*long*/ parentHandle = parent.handle;
- int /*long*/ column = 0;
- if (parent.columnCount > 0) {
- column = parent.columns [index].handle;
- } else {
- column = OS.gtk_tree_view_get_column (parentHandle, index);
- }
- if (column == 0) return;
- int /*long*/ textRenderer = parent.getTextRenderer (column);
- int /*long*/ imageRenderer = parent.getPixbufRenderer (column);
- OS.gtk_tree_view_column_set_cell_data_func (column, textRenderer, display.cellDataProc, parentHandle, 0);
- OS.gtk_tree_view_column_set_cell_data_func (column, imageRenderer, display.cellDataProc, parentHandle, 0);
- }
- if (parent.columnCount == 0) {
- parent.firstCustomDraw = true;
- } else {
- parent.columns [index].customDraw = true;
- }
- }
- }
-}
-
-/**
- * Sets the checked state of the receiver.
- * <p>
- *
- * @param checked the new checked state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setChecked (boolean checked) {
- checkWidget();
- if ((parent.style & SWT.CHECK) == 0) return;
- if (_getChecked () == checked) return;
- OS.gtk_tree_store_set (parent.modelHandle, handle, Tree.CHECKED_COLUMN, checked, -1);
- /*
- * GTK+'s "inconsistent" state does not match SWT's concept of grayed. To
- * show checked+grayed differently from unchecked+grayed, we must toggle the
- * grayed state on check and uncheck.
- */
- OS.gtk_tree_store_set (parent.modelHandle, handle, Tree.GRAYED_COLUMN, !checked ? false : grayed, -1);
- cached = true;
-}
-
-/**
- * Sets the expanded state of the receiver.
- * <p>
- *
- * @param expanded the new expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setExpanded (boolean expanded) {
- checkWidget();
- int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- if (expanded) {
- OS.g_signal_handlers_block_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_EXPAND_ROW);
- OS.gtk_tree_view_expand_row (parent.handle, path, false);
- OS.g_signal_handlers_unblock_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_EXPAND_ROW);
- } else {
- OS.g_signal_handlers_block_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_COLLAPSE_ROW);
- OS.gtk_widget_realize (parent.handle);
- OS.gtk_tree_view_collapse_row (parent.handle, path);
- OS.g_signal_handlers_unblock_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_COLLAPSE_ROW);
- }
- OS.gtk_tree_path_free (path);
- cached = true;
-}
-
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for this item to the font specified by the argument, or to the default font
- * for that kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (Font font){
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Font oldFont = this.font;
- if (oldFont == font) return;
- this.font = font;
- if (oldFont != null && oldFont.equals (font)) return;
- int /*long*/ fontHandle = font != null ? font.handle : 0;
- OS.gtk_tree_store_set (parent.modelHandle, handle, Tree.FONT_COLUMN, fontHandle, -1);
- /*
- * Bug in GTK. When using fixed-height-mode,
- * row changes do not cause the row to be repainted. The fix is to
- * invalidate the row when it is cleared.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) {
- redraw ();
- }
- }
- cached = true;
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for the specified cell in this item to the font specified by the
- * argument, or to the default font for that kind of control if the
- * argument is null.
- *
- * @param index the column index
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setFont (int index, Font font) {
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- if (cellFont == null) {
- if (font == null) return;
- cellFont = new Font [count];
- }
- Font oldFont = cellFont [index];
- if (oldFont == font) return;
- cellFont [index] = font;
- if (oldFont != null && oldFont.equals (font)) return;
-
- int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex;
- int /*long*/ fontHandle = font != null ? font.handle : 0;
- OS.gtk_tree_store_set (parent.modelHandle, handle, modelIndex + Tree.CELL_FONT, fontHandle, -1);
- /*
- * Bug in GTK. When using fixed-height-mode,
- * row changes do not cause the row to be repainted. The fix is to
- * invalidate the row when it is cleared.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) {
- redraw ();
- }
- }
- cached = true;
-
- if (font != null) {
- boolean customDraw = (parent.columnCount == 0) ? parent.firstCustomDraw : parent.columns [index].customDraw;
- if (!customDraw) {
- if ((parent.style & SWT.VIRTUAL) == 0) {
- int /*long*/ parentHandle = parent.handle;
- int /*long*/ column = 0;
- if (parent.columnCount > 0) {
- column = parent.columns [index].handle;
- } else {
- column = OS.gtk_tree_view_get_column (parentHandle, index);
- }
- if (column == 0) return;
- int /*long*/ textRenderer = parent.getTextRenderer (column);
- int /*long*/ imageRenderer = parent.getPixbufRenderer (column);
- OS.gtk_tree_view_column_set_cell_data_func (column, textRenderer, display.cellDataProc, parentHandle, 0);
- OS.gtk_tree_view_column_set_cell_data_func (column, imageRenderer, display.cellDataProc, parentHandle, 0);
- }
- if (parent.columnCount == 0) {
- parent.firstCustomDraw = true;
- } else {
- parent.columns [index].customDraw = true;
- }
- }
- }
-}
-
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @since 2.0
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public void setForeground (Color color){
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (_getForeground ().equals (color)) return;
- GdkColor gdkColor = color != null ? color.handle : null;
- OS.gtk_tree_store_set (parent.modelHandle, handle, Tree.FOREGROUND_COLUMN, gdkColor, -1);
- /*
- * Bug in GTK. When using fixed-height-mode,
- * row changes do not cause the row to be repainted. The fix is to
- * invalidate the row when it is cleared.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) {
- redraw ();
- }
- }
- cached = true;
-}
-
-/**
- * Sets the foreground color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- *
- */
-public void setForeground (int index, Color color){
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (_getForeground (index).equals (color)) return;
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex;
- GdkColor gdkColor = color != null ? color.handle : null;
- OS.gtk_tree_store_set (parent.modelHandle, handle, modelIndex + Tree.CELL_FOREGROUND, gdkColor, -1);
- /*
- * Bug in GTK. When using fixed-height-mode,
- * row changes do not cause the row to be repainted. The fix is to
- * invalidate the row when it is cleared.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) {
- redraw ();
- }
- }
- cached = true;
-
- if (color != null) {
- boolean customDraw = (parent.columnCount == 0) ? parent.firstCustomDraw : parent.columns [index].customDraw;
- if (!customDraw) {
- if ((parent.style & SWT.VIRTUAL) == 0) {
- int /*long*/ parentHandle = parent.handle;
- int /*long*/ column = 0;
- if (parent.columnCount > 0) {
- column = parent.columns [index].handle;
- } else {
- column = OS.gtk_tree_view_get_column (parentHandle, index);
- }
- if (column == 0) return;
- int /*long*/ textRenderer = parent.getTextRenderer (column);
- int /*long*/ imageRenderer = parent.getPixbufRenderer (column);
- OS.gtk_tree_view_column_set_cell_data_func (column, textRenderer, display.cellDataProc, parentHandle, 0);
- OS.gtk_tree_view_column_set_cell_data_func (column, imageRenderer, display.cellDataProc, parentHandle, 0);
- }
- if (parent.columnCount == 0) {
- parent.firstCustomDraw = true;
- } else {
- parent.columns [index].customDraw = true;
- }
- }
- }
-}
-
-/**
- * Sets the grayed state of the checkbox for this item. This state change
- * only applies if the Tree was created with the SWT.CHECK style.
- *
- * @param grayed the new grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setGrayed (boolean grayed) {
- checkWidget();
- if ((parent.style & SWT.CHECK) == 0) return;
- if (this.grayed == grayed) return;
- this.grayed = grayed;
- /*
- * GTK+'s "inconsistent" state does not match SWT's concept of grayed.
- * Render checked+grayed as "inconsistent", unchecked+grayed as blank.
- */
- int /*long*/ [] ptr = new int /*long*/ [1];
- OS.gtk_tree_model_get (parent.modelHandle, handle, Tree.CHECKED_COLUMN, ptr, -1);
- OS.gtk_tree_store_set (parent.modelHandle, handle, Tree.GRAYED_COLUMN, ptr [0] == 0 ? false : grayed, -1);
- cached = true;
-}
-
-/**
- * Sets the receiver's image at a column.
- *
- * @param index the column index
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setImage (int index, Image image) {
- checkWidget ();
- if (image != null && image.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (image != null && image.type == SWT.ICON) {
- if (image.equals (_getImage (index))) return;
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- int /*long*/ pixbuf = 0;
- if (image != null) {
- ImageList imageList = parent.imageList;
- if (imageList == null) imageList = parent.imageList = new ImageList ();
- int imageIndex = imageList.indexOf (image);
- if (imageIndex == -1) imageIndex = imageList.add (image);
- pixbuf = imageList.getPixbuf (imageIndex);
- }
- int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex;
- OS.gtk_tree_store_set (parent.modelHandle, handle, modelIndex + Tree.CELL_PIXBUF, pixbuf, -1);
- /*
- * Bug in GTK. When using fixed-height-mode,
- * row changes do not cause the row to be repainted. The fix is to
- * invalidate the row when the image changes.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) {
- if (parent.columnCount == 0) {
- redraw ();
- }
- }
- }
- /*
- * Bug in GTK. When using fixed-height-mode, GTK does not recalculate the cell renderer width
- * when the image is changed in the model. The fix is to force it to recalculate the width if
- * more space is required.
- */
- if ((parent.style & SWT.VIRTUAL) != 0 && parent.currentItem == null) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2)) {
- if (image != null) {
- int /*long*/parentHandle = parent.handle;
- int /*long*/ column = OS.gtk_tree_view_get_column (parentHandle, index);
- int [] w = new int [1];
- int /*long*/ pixbufRenderer = parent.getPixbufRenderer(column);
- OS.gtk_tree_view_column_cell_get_position (column, pixbufRenderer, null, w);
- if (w[0] < image.getBounds().width) {
- /*
- * There is no direct way to clear the cell renderer width so we
- * are relying on the fact that it is done as part of modifying
- * the style.
- */
- int /*long*/ style = OS.gtk_widget_get_modifier_style (parentHandle);
- parent.modifyStyle (parentHandle, style);
- }
- }
- }
- }
- cached = true;
-}
-
-public void setImage (Image image) {
- checkWidget ();
- setImage (0, image);
-}
-
-/**
- * Sets the image for multiple columns in the tree.
- *
- * @param images the array of new images
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setImage (Image [] images) {
- checkWidget ();
- if (images == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<images.length; i++) {
- setImage (i, images [i]);
- }
-}
-
-/**
- * Sets the number of child items contained in the receiver.
- *
- * @param count the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setItemCount (int count) {
- checkWidget ();
- count = Math.max (0, count);
- parent.setItemCount (handle, count);
-}
-
-/**
- * Sets the receiver's text at a column
- *
- * @param index the column index
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setText (int index, String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (_getText (index).equals (string)) return;
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- byte[] buffer = Converter.wcsToMbcs (null, string, true);
- int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex;
- OS.gtk_tree_store_set (parent.modelHandle, handle, modelIndex + Tree.CELL_TEXT, buffer, -1);
- /*
- * Bug in GTK. When using fixed-height-mode,
- * row changes do not cause the row to be repainted. The fix is to
- * invalidate the row when the text changes.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) {
- redraw ();
- }
- }
- cached = true;
-}
-
-public void setText (String string) {
- checkWidget ();
- setText (0, string);
-}
-
-/**
- * Sets the text for multiple columns in the tree.
- *
- * @param strings the array of new strings
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setText (String [] strings) {
- checkWidget ();
- if (strings == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<strings.length; i++) {
- String string = strings [i];
- if (string != null) setText (i, string);
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
deleted file mode 100644
index a391ca1933..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
+++ /dev/null
@@ -1,1617 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.events.*;
-
-/**
- * This class is the abstract superclass of all user interface objects.
- * Widgets are created, disposed and issue notification to listeners
- * when events occur which affect them.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Dispose</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation. However, it has not been marked
- * final to allow those outside of the SWT development team to implement
- * patched versions of the class in order to get around specific
- * limitations in advance of when those limitations can be addressed
- * by the team. Any class built using subclassing to access the internals
- * of this class will likely fail to compile or run between releases and
- * may be strongly platform specific. Subclassing should not be attempted
- * without an intimate and detailed understanding of the workings of the
- * hierarchy. No support is provided for user-written classes which are
- * implemented as subclasses of this class.
- * </p>
- *
- * @see #checkSubclass
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class Widget {
- /**
- * the handle to the OS resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
- int style, state;
- Display display;
- EventTable eventTable;
- Object data;
-
- /* Global state flags */
- static final int DISPOSED = 1<<0;
- static final int CANVAS = 1<<1;
- static final int KEYED_DATA = 1<<2;
- static final int HANDLE = 1<<3;
- static final int DISABLED = 1<<4;
- static final int MENU = 1<<5;
- static final int OBSCURED = 1<<6;
- static final int MOVED = 1<<7;
- static final int RESIZED = 1<<8;
- static final int ZERO_WIDTH = 1<<9;
- static final int ZERO_HEIGHT = 1<<10;
- static final int HIDDEN = 1<<11;
- static final int FOREGROUND = 1<<12;
- static final int BACKGROUND = 1<<13;
- static final int FONT = 1<<14;
- static final int PARENT_BACKGROUND = 1<<15;
- static final int THEME_BACKGROUND = 1<<16;
-
- /* A layout was requested on this widget */
- static final int LAYOUT_NEEDED = 1<<17;
-
- /* The preferred size of a child has changed */
- static final int LAYOUT_CHANGED = 1<<18;
-
- /* A layout was requested in this widget hierachy */
- static final int LAYOUT_CHILD = 1<<19;
-
- /* More global state flags */
- static final int RELEASED = 1<<20;
- static final int DISPOSE_SENT = 1<<21;
- static final int FOREIGN_HANDLE = 1<<22;
- static final int DRAG_DETECT = 1<<23;
-
- /* Default size for widgets */
- static final int DEFAULT_WIDTH = 64;
- static final int DEFAULT_HEIGHT = 64;
-
- /* GTK signals data */
- static final int ACTIVATE = 1;
- static final int BUTTON_PRESS_EVENT = 2;
- static final int BUTTON_PRESS_EVENT_INVERSE = 3;
- static final int BUTTON_RELEASE_EVENT = 4;
- static final int BUTTON_RELEASE_EVENT_INVERSE = 5;
- static final int CHANGED = 6;
- static final int CHANGE_VALUE = 7;
- static final int CLICKED = 8;
- static final int COMMIT = 9;
- static final int CONFIGURE_EVENT = 10;
- static final int DELETE_EVENT = 11;
- static final int DELETE_RANGE = 12;
- static final int DELETE_TEXT = 13;
- static final int ENTER_NOTIFY_EVENT = 14;
- static final int EVENT = 15;
- static final int EVENT_AFTER = 16;
- static final int EXPAND_COLLAPSE_CURSOR_ROW = 17;
- static final int EXPOSE_EVENT = 18;
- static final int EXPOSE_EVENT_INVERSE = 19;
- static final int FOCUS = 20;
- static final int FOCUS_IN_EVENT = 21;
- static final int FOCUS_OUT_EVENT = 22;
- static final int GRAB_FOCUS = 23;
- static final int HIDE = 24;
- static final int INPUT = 25;
- static final int INSERT_TEXT = 26;
- static final int KEY_PRESS_EVENT = 27;
- static final int KEY_RELEASE_EVENT = 28;
- static final int LEAVE_NOTIFY_EVENT = 29;
- static final int MAP = 30;
- static final int MAP_EVENT = 31;
- static final int MNEMONIC_ACTIVATE = 32;
- static final int MOTION_NOTIFY_EVENT = 33;
- static final int MOTION_NOTIFY_EVENT_INVERSE = 34;
- static final int MOVE_FOCUS = 35;
- static final int OUTPUT = 36;
- static final int POPULATE_POPUP = 37;
- static final int POPUP_MENU = 38;
- static final int PREEDIT_CHANGED = 39;
- static final int REALIZE = 40;
- static final int ROW_ACTIVATED = 41;
- static final int SCROLL_CHILD = 42;
- static final int SCROLL_EVENT = 43;
- static final int SELECT = 44;
- static final int SHOW = 45;
- static final int SHOW_HELP = 46;
- static final int SIZE_ALLOCATE = 47;
- static final int STYLE_SET = 48;
- static final int SWITCH_PAGE = 49;
- static final int TEST_COLLAPSE_ROW = 50;
- static final int TEST_EXPAND_ROW = 51;
- static final int TEXT_BUFFER_INSERT_TEXT = 52;
- static final int TOGGLED = 53;
- static final int UNMAP = 54;
- static final int UNMAP_EVENT = 55;
- static final int UNREALIZE = 56;
- static final int VALUE_CHANGED = 57;
- static final int VISIBILITY_NOTIFY_EVENT = 58;
- static final int WINDOW_STATE_EVENT = 59;
- static final int ACTIVATE_INVERSE = 60;
- static final int DAY_SELECTED = 61;
- static final int MONTH_CHANGED = 62;
- static final int STATUS_ICON_POPUP_MENU = 63;
- static final int ROW_INSERTED = 64;
- static final int ROW_DELETED = 65;
- static final int DAY_SELECTED_DOUBLE_CLICK = 66;
- static final int LAST_SIGNAL = 67;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Widget () {}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see #checkSubclass
- * @see #getStyle
- */
-public Widget (Widget parent, int style) {
- checkSubclass ();
- checkParent (parent);
- this.style = style;
- display = parent.display;
-}
-
-void _addListener (int eventType, Listener listener) {
- if (eventTable == null) eventTable = new EventTable ();
- eventTable.hook (eventType, listener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs. When the
- * event does occur in the widget, the listener is notified by
- * sending it the <code>handleEvent()</code> message. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #getListeners(int)
- * @see #removeListener(int, Listener)
- * @see #notifyListeners
- */
-public void addListener (int eventType, Listener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- _addListener (eventType, listener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the widget is disposed. When the widget is
- * disposed, the listener is notified by sending it the
- * <code>widgetDisposed()</code> message.
- *
- * @param listener the listener which should be notified when the receiver is disposed
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DisposeListener
- * @see #removeDisposeListener
- */
-public void addDisposeListener (DisposeListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Dispose, typedListener);
-}
-
-int /*long*/ paintWindow () {
- return 0;
-}
-
-static int checkBits (int style, int int0, int int1, int int2, int int3, int int4, int int5) {
- int mask = int0 | int1 | int2 | int3 | int4 | int5;
- if ((style & mask) == 0) style |= int0;
- if ((style & int0) != 0) style = (style & ~mask) | int0;
- if ((style & int1) != 0) style = (style & ~mask) | int1;
- if ((style & int2) != 0) style = (style & ~mask) | int2;
- if ((style & int3) != 0) style = (style & ~mask) | int3;
- if ((style & int4) != 0) style = (style & ~mask) | int4;
- if ((style & int5) != 0) style = (style & ~mask) | int5;
- return style;
-}
-
-int /*long*/ cellDataProc (int /*long*/ tree_column, int /*long*/ cell, int /*long*/ tree_model, int /*long*/ iter, int /*long*/ data) {
- return 0;
-}
-
-void checkOpen () {
- /* Do nothing */
-}
-
-void checkOrientation (Widget parent) {
- style &= ~SWT.MIRRORED;
- if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) {
- if (parent != null) {
- if ((parent.style & SWT.LEFT_TO_RIGHT) != 0) style |= SWT.LEFT_TO_RIGHT;
- if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) style |= SWT.RIGHT_TO_LEFT;
- }
- }
- style = checkBits (style, SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT, 0, 0, 0, 0);
- /* Versions of GTK prior to 2.8 do not render RTL text properly */
- if (OS.GTK_VERSION < OS.VERSION (2, 8, 0)) {
- style &= ~SWT.RIGHT_TO_LEFT;
- style |= SWT.LEFT_TO_RIGHT;
- }
-}
-
-/**
- * Throws an exception if the specified widget can not be
- * used as a parent for the receiver.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- */
-void checkParent (Widget parent) {
- if (parent == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (parent.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- parent.checkWidget ();
- parent.checkOpen ();
-}
-
-/**
- * Checks that this class can be subclassed.
- * <p>
- * The SWT class library is intended to be subclassed
- * only at specific, controlled points (most notably,
- * <code>Composite</code> and <code>Canvas</code> when
- * implementing new widgets). This method enforces this
- * rule unless it is overridden.
- * </p><p>
- * <em>IMPORTANT:</em> By providing an implementation of this
- * method that allows a subclass of a class which does not
- * normally allow subclassing to be created, the implementer
- * agrees to be fully responsible for the fact that any such
- * subclass will likely fail between SWT releases and will be
- * strongly platform specific. No support is provided for
- * user-written classes which are implemented in this fashion.
- * </p><p>
- * The ability to subclass outside of the allowed SWT classes
- * is intended purely to enable those not on the SWT development
- * team to implement patches in order to get around specific
- * limitations in advance of when those limitations can be
- * addressed by the team. Subclassing should not be attempted
- * without an intimate and detailed understanding of the hierarchy.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Throws an <code>SWTException</code> if the receiver can not
- * be accessed by the caller. This may include both checks on
- * the state of the receiver and more generally on the entire
- * execution context. This method <em>should</em> be called by
- * widget implementors to enforce the standard SWT invariants.
- * <p>
- * Currently, it is an error to invoke any method (other than
- * <code>isDisposed()</code>) on a widget that has had its
- * <code>dispose()</code> method called. It is also an error
- * to call widget methods from any thread that is different
- * from the thread that created the widget.
- * </p><p>
- * In future releases of SWT, there may be more or fewer error
- * checks and exceptions may be thrown for different reasons.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-protected void checkWidget () {
- Display display = this.display;
- if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
- if (display.thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if ((state & DISPOSED) != 0) error (SWT.ERROR_WIDGET_DISPOSED);
-}
-
-void createHandle (int index) {
-}
-
-void createWidget (int index) {
- createHandle (index);
- setOrientation ();
- hookEvents ();
- register ();
-}
-
-void deregister () {
- if (handle == 0) return;
- if ((state & HANDLE) != 0) display.removeWidget (handle);
-}
-
-void destroyWidget () {
- int /*long*/ topHandle = topHandle ();
- releaseHandle ();
- if (topHandle != 0 && (state & HANDLE) != 0) {
- OS.gtk_widget_destroy (topHandle);
- }
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the receiver and all its descendants. After this method has
- * been invoked, the receiver and all descendants will answer
- * <code>true</code> when sent the message <code>isDisposed()</code>.
- * Any internal connections between the widgets in the tree will
- * have been removed to facilitate garbage collection.
- * <p>
- * NOTE: This method is not called recursively on the descendants
- * of the receiver. This means that, widget implementers can not
- * detect when a widget is being disposed of by re-implementing
- * this method, but should instead listen for the <code>Dispose</code>
- * event.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #addDisposeListener
- * @see #removeDisposeListener
- * @see #checkWidget
- */
-public void dispose () {
- /*
- * Note: It is valid to attempt to dispose a widget
- * more than once. If this happens, fail silently.
- */
- if (isDisposed ()) return;
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- release (true);
-}
-
-void error (int code) {
- SWT.error (code);
-}
-
-/**
- * Returns the application defined widget data associated
- * with the receiver, or null if it has not been set. The
- * <em>widget data</em> is a single, unnamed field that is
- * stored with every widget.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the widget data needs to be notified
- * when the widget is disposed of, it is the application's
- * responsibility to hook the Dispose event on the widget and
- * do so.
- * </p>
- *
- * @return the widget data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
- * </ul>
- *
- * @see #setData(Object)
- */
-public Object getData () {
- checkWidget();
- return (state & KEYED_DATA) != 0 ? ((Object []) data) [0] : data;
-}
-/**
- * Returns the application defined property of the receiver
- * with the specified name, or null if it has not been set.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the widget is disposed
- * of, it is the application's responsibility to hook the
- * Dispose event on the widget and do so.
- * </p>
- *
- * @param key the name of the property
- * @return the value of the property or null if it has not been set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setData(String, Object)
- */
-public Object getData (String key) {
- checkWidget();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((state & KEYED_DATA) != 0) {
- Object [] table = (Object []) data;
- for (int i=1; i<table.length; i+=2) {
- if (key.equals (table [i])) return table [i+1];
- }
- }
- return null;
-}
-
-/**
- * Returns the <code>Display</code> that is associated with
- * the receiver.
- * <p>
- * A widget's display is either provided when it is created
- * (for example, top level <code>Shell</code>s) or is the
- * same as its parent's display.
- * </p>
- *
- * @return the receiver's display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Display getDisplay () {
- Display display = this.display;
- if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return display;
-}
-
-/**
- * Returns an array of listeners who will be notified when an event
- * of the given type occurs. The event type is one of the event constants
- * defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @return an array of listeners that will be notified when the event occurs
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener(int, Listener)
- * @see #removeListener(int, Listener)
- * @see #notifyListeners
- *
- * @since 3.4
- */
-public Listener[] getListeners (int eventType) {
- checkWidget();
- if (eventTable == null) return new Listener[0];
- return eventTable.getListeners(eventType);
-}
-
-String getName () {
-// String string = getClass ().getName ();
-// int index = string.lastIndexOf ('.');
-// if (index == -1) return string;
- String string = getClass ().getName ();
- int index = string.length ();
- while ((--index > 0) && (string.charAt (index) != '.')) {}
- return string.substring (index + 1, string.length ());
-}
-
-String getNameText () {
- return "";
-}
-
-/**
- * Returns the receiver's style information.
- * <p>
- * Note that the value which is returned by this method <em>may
- * not match</em> the value which was provided to the constructor
- * when the receiver was created. This can occur when the underlying
- * operating system does not support a particular combination of
- * requested styles. For example, if the platform widget used to
- * implement a particular SWT widget always has scroll bars, the
- * result of calling this method would always have the
- * <code>SWT.H_SCROLL</code> and <code>SWT.V_SCROLL</code> bits set.
- * </p>
- *
- * @return the style bits
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getStyle () {
- checkWidget ();
- return style;
-}
-
-
-int /*long*/ gtk_activate (int /*long*/ widget) {
- return 0;
-}
-
-int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int /*long*/ gtk_changed (int /*long*/ widget) {
- return 0;
-}
-
-int /*long*/ gtk_change_value (int /*long*/ widget, int /*long*/ scroll, int /*long*/ value1, int /*long*/ value2) {
- return 0;
-}
-
-int /*long*/ gtk_clicked (int /*long*/ widget) {
- return 0;
-}
-
-int /*long*/ gtk_commit (int /*long*/ imcontext, int /*long*/ text) {
- return 0;
-}
-
-int /*long*/ gtk_configure_event (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int /*long*/ gtk_day_selected (int /*long*/ widget) {
- return 0;
-}
-
-int /*long*/ gtk_day_selected_double_click (int /*long*/ widget) {
- return 0;
-}
-
-int /*long*/ gtk_delete_event (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int /*long*/ gtk_delete_range (int /*long*/ widget, int /*long*/ iter1, int /*long*/ iter2) {
- return 0;
-}
-
-int /*long*/ gtk_delete_text (int /*long*/ widget, int /*long*/ start_pos, int /*long*/ end_pos) {
- return 0;
-}
-
-int /*long*/ gtk_enter_notify_event (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int /*long*/ gtk_event (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int /*long*/ gtk_expand_collapse_cursor_row (int /*long*/ widget, int /*long*/ logical, int /*long*/ expand, int /*long*/ open_all) {
- return 0;
-}
-
-int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int /*long*/ gtk_focus (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int /*long*/ gtk_grab_focus (int /*long*/ widget) {
- return 0;
-}
-
-int /*long*/ gtk_hide (int /*long*/ widget) {
- return 0;
-}
-
-int /*long*/ gtk_input (int /*long*/ widget, int /*long*/ arg1) {
- return 0;
-}
-
-int /*long*/ gtk_insert_text (int /*long*/ widget, int /*long*/ new_text, int /*long*/ new_text_length, int /*long*/ position) {
- return 0;
-}
-
-int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) {
- GdkEventKey gdkEvent = new GdkEventKey ();
- OS.memmove (gdkEvent, event, GdkEventKey.sizeof);
- return sendKeyEvent (SWT.KeyDown, gdkEvent) ? 0 : 1;
-}
-
-int /*long*/ gtk_key_release_event (int /*long*/ widget, int /*long*/ event) {
- GdkEventKey gdkEvent = new GdkEventKey ();
- OS.memmove (gdkEvent, event, GdkEventKey.sizeof);
- return sendKeyEvent (SWT.KeyUp, gdkEvent) ? 0 : 1;
-}
-
-int /*long*/ gtk_leave_notify_event (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int /*long*/ gtk_map (int /*long*/ widget) {
- return 0;
-}
-
-int /*long*/ gtk_map_event (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int /*long*/ gtk_mnemonic_activate (int /*long*/ widget, int /*long*/ arg1) {
- return 0;
-}
-
-int /*long*/ gtk_month_changed (int /*long*/ widget) {
- return 0;
-}
-
-int /*long*/ gtk_motion_notify_event (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int /*long*/ gtk_move_focus (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int /*long*/ gtk_output (int /*long*/ widget) {
- return 0;
-}
-
-int /*long*/ gtk_populate_popup (int /*long*/ widget, int /*long*/ menu) {
- return 0;
-}
-
-int /*long*/ gtk_popup_menu (int /*long*/ widget) {
- return 0;
-}
-
-int /*long*/ gtk_preedit_changed (int /*long*/ imcontext) {
- return 0;
-}
-
-int /*long*/ gtk_realize (int /*long*/ widget) {
- return 0;
-}
-
-int /*long*/ gtk_row_activated (int /*long*/ tree, int /*long*/ path, int /*long*/ column) {
- return 0;
-}
-
-int /*long*/ gtk_row_deleted (int /*long*/ model, int /*long*/ path) {
- return 0;
-}
-
-int /*long*/ gtk_row_inserted (int /*long*/ model, int /*long*/ path, int /*long*/ iter) {
- return 0;
-}
-
-int /*long*/ gtk_scroll_child (int /*long*/ widget, int /*long*/ scrollType, int /*long*/ horizontal) {
- return 0;
-}
-
-int /*long*/ gtk_scroll_event (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int /*long*/ gtk_select (int /*long*/ item) {
- return 0;
-}
-
-int /*long*/ gtk_show (int /*long*/ widget) {
- return 0;
-}
-
-int /*long*/ gtk_show_help (int /*long*/ widget, int /*long*/ helpType) {
- return 0;
-}
-
-int /*long*/ gtk_size_allocate (int /*long*/ widget, int /*long*/ allocation) {
- return 0;
-}
-
-int /*long*/ gtk_status_icon_popup_menu (int /*long*/ handle, int /*long*/ button, int /*long*/ activate_time) {
- return 0;
-}
-
-int /*long*/ gtk_style_set (int /*long*/ widget, int /*long*/ previousStyle) {
- return 0;
-}
-
-int /*long*/ gtk_switch_page (int /*long*/ widget, int /*long*/ page, int /*long*/ page_num) {
- return 0;
-}
-
-int /*long*/ gtk_test_collapse_row (int /*long*/ tree, int /*long*/ iter, int /*long*/ path) {
- return 0;
-}
-
-int /*long*/ gtk_test_expand_row (int /*long*/ tree, int /*long*/ iter, int /*long*/ path) {
- return 0;
-}
-
-int /*long*/ gtk_text_buffer_insert_text (int /*long*/ widget, int /*long*/ iter, int /*long*/ text, int /*long*/ length) {
- return 0;
-}
-
-int /*long*/ gtk_timer () {
- return 0;
-}
-
-int /*long*/ gtk_toggled (int /*long*/ renderer, int /*long*/ pathStr) {
- return 0;
-}
-
-int /*long*/ gtk_unmap (int /*long*/ widget) {
- return 0;
-}
-
-int /*long*/ gtk_unmap_event (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int /*long*/ gtk_unrealize (int /*long*/ widget) {
- return 0;
-}
-
-int /*long*/ gtk_value_changed (int /*long*/ adjustment) {
- return 0;
-}
-
-int /*long*/ gtk_visibility_notify_event (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int /*long*/ gtk_window_state_event (int /*long*/ widget, int /*long*/ event) {
- return 0;
-}
-
-int fontHeight (int /*long*/ font, int /*long*/ widgetHandle) {
- int /*long*/ context = OS.gtk_widget_get_pango_context (widgetHandle);
- int /*long*/ lang = OS.pango_context_get_language (context);
- int /*long*/ metrics = OS.pango_context_get_metrics (context, font, lang);
- int ascent = OS.pango_font_metrics_get_ascent (metrics);
- int descent = OS.pango_font_metrics_get_descent (metrics);
- OS.pango_font_metrics_unref (metrics);
- return OS.PANGO_PIXELS (ascent + descent);
-}
-
-int /*long*/ filterProc(int /*long*/ xEvent, int /*long*/ gdkEvent, int /*long*/ data2) {
- return 0;
-}
-
-boolean filters (int eventType) {
- return display.filters (eventType);
-}
-
-int /*long*/ fixedMapProc (int /*long*/ widget) {
- return 0;
-}
-
-int /*long*/ fixedSizeAllocateProc(int /*long*/ widget, int /*long*/ allocationPtr) {
- return OS.Call (Display.oldFixedSizeAllocateProc, widget, allocationPtr);
-}
-
-char [] fixMnemonic (String string) {
- return fixMnemonic (string, true);
-}
-
-char [] fixMnemonic (String string, boolean replace) {
- int length = string.length ();
- char [] text = new char [length];
- string.getChars (0, length, text, 0);
- int i = 0, j = 0;
- char [] result = new char [length * 2];
- while (i < length) {
- switch (text [i]) {
- case '&':
- if (i + 1 < length && text [i + 1] == '&') {
- result [j++] = text [i++];
- } else {
- if (replace) result [j++] = '_';
- }
- i++;
- break;
- case '_':
- if (replace) result [j++] = '_';
- //FALL THROUGH
- default:
- result [j++] = text [i++];
- }
- }
- return result;
-}
-
-/**
- * Returns <code>true</code> if the widget has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the widget.
- * When a widget has been disposed, it is an error to
- * invoke any other method using the widget.
- * </p>
- *
- * @return <code>true</code> when the widget is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- return (state & DISPOSED) != 0;
-}
-
-/**
- * Returns <code>true</code> if there are any listeners
- * for the specified event type associated with the receiver,
- * and <code>false</code> otherwise. The event type is one of
- * the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event
- * @return true if the event is hooked
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public boolean isListening (int eventType) {
- checkWidget ();
- return hooks (eventType);
-}
-
-boolean isValidThread () {
- return getDisplay ().isValidThread ();
-}
-
-boolean isValidSubclass() {
- return Display.isValidClass(getClass());
-}
-
-void hookEvents () {
-}
-
-/*
- * Returns <code>true</code> if the specified eventType is
- * hooked, and <code>false</code> otherwise. Implementations
- * of SWT can avoid creating objects and sending events
- * when an event happens in the operating system but
- * there are no listeners hooked for the event.
- *
- * @param eventType the event to be checked
- *
- * @return <code>true</code> when the eventType is hooked and <code>false</code> otherwise
- *
- * @see #isListening
- */
-boolean hooks (int eventType) {
- if (eventTable == null) return false;
- return eventTable.hooks (eventType);
-}
-
-int /*long*/ hoverProc (int /*long*/ widget) {
- return 0;
-}
-
-int /*long*/ menuPositionProc (int /*long*/ menu, int /*long*/ x, int /*long*/ y, int /*long*/ push_in, int /*long*/ user_data) {
- return 0;
-}
-
-boolean mnemonicHit (int /*long*/ mnemonicHandle, char key) {
- if (!mnemonicMatch (mnemonicHandle, key)) return false;
- OS.g_signal_handlers_block_matched (mnemonicHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, MNEMONIC_ACTIVATE);
- boolean result = OS.gtk_widget_mnemonic_activate (mnemonicHandle, false);
- OS.g_signal_handlers_unblock_matched (mnemonicHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, MNEMONIC_ACTIVATE);
- return result;
-}
-
-boolean mnemonicMatch (int /*long*/ mnemonicHandle, char key) {
- int keyval1 = OS.gdk_keyval_to_lower (OS.gdk_unicode_to_keyval (key));
- int keyval2 = OS.gdk_keyval_to_lower (OS.gtk_label_get_mnemonic_keyval (mnemonicHandle));
- return keyval1 == keyval2;
-}
-
-void modifyStyle (int /*long*/ handle, int /*long*/ style) {
- OS.gtk_widget_modify_style (handle, style);
-}
-
-/**
- * Notifies all of the receiver's listeners for events
- * of the given type that one such event has occurred by
- * invoking their <code>handleEvent()</code> method. The
- * event type is one of the event constants defined in class
- * <code>SWT</code>.
- *
- * @param eventType the type of event which has occurred
- * @param event the event data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- * @see #addListener
- * @see #getListeners(int)
- * @see #removeListener(int, Listener)
- */
-public void notifyListeners (int eventType, Event event) {
- checkWidget();
- if (event == null) event = new Event ();
- sendEvent (eventType, event);
-}
-
-void postEvent (int eventType) {
- sendEvent (eventType, null, false);
-}
-
-void postEvent (int eventType, Event event) {
- sendEvent (eventType, event, false);
-}
-
-void register () {
- if (handle == 0) return;
- if ((state & HANDLE) != 0) display.addWidget (handle, this);
-}
-
-void release (boolean destroy) {
- if ((state & DISPOSE_SENT) == 0) {
- state |= DISPOSE_SENT;
- sendEvent (SWT.Dispose);
- }
- if ((state & DISPOSED) == 0) {
- releaseChildren (destroy);
- }
- if ((state & RELEASED) == 0) {
- state |= RELEASED;
- if (destroy) {
- releaseParent ();
- releaseWidget ();
- destroyWidget ();
- } else {
- releaseWidget ();
- releaseHandle ();
- }
- }
-}
-
-void releaseChildren (boolean destroy) {
-}
-
-void releaseHandle () {
- handle = 0;
- state |= DISPOSED;
- display = null;
-}
-
-void releaseParent () {
- /* Do nothing */
-}
-
-void releaseWidget () {
- deregister ();
- eventTable = null;
- data = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener
- * @see #getListeners(int)
- * @see #notifyListeners
- */
-public void removeListener (int eventType, Listener handler) {
- checkWidget ();
- if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, handler);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It should never be
- * referenced from application code.
- * </p>
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see #addListener
- */
-protected void removeListener (int eventType, SWTEventListener handler) {
- checkWidget ();
- if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, handler);
-}
-
-int /*long*/ rendererGetSizeProc (int /*long*/ cell, int /*long*/ handle, int /*long*/ cell_area, int /*long*/ x_offset, int /*long*/ y_offset, int /*long*/ width, int /*long*/ height) {
- return 0;
-}
-
-int /*long*/ rendererRenderProc (int /*long*/ cell, int /*long*/ window, int /*long*/ handle, int /*long*/ background_area, int /*long*/ cell_area, int /*long*/ expose_area, int /*long*/ flags) {
- return 0;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the widget is disposed.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DisposeListener
- * @see #addDisposeListener
- */
-public void removeDisposeListener (DisposeListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Dispose, listener);
-}
-
-void sendEvent (Event event) {
- Display display = event.display;
- if (!display.filterEvent (event)) {
- if (eventTable != null) eventTable.sendEvent (event);
- }
-}
-
-void sendEvent (int eventType) {
- sendEvent (eventType, null, true);
-}
-
-void sendEvent (int eventType, Event event) {
- sendEvent (eventType, event, true);
-}
-
-void sendEvent (int eventType, Event event, boolean send) {
- if (eventTable == null && !display.filters (eventType)) {
- return;
- }
- if (event == null) event = new Event ();
- event.type = eventType;
- event.display = display;
- event.widget = this;
- if (event.time == 0) {
- event.time = display.getLastEventTime ();
- }
- if (send) {
- sendEvent (event);
- } else {
- display.postEvent (event);
- }
-}
-
-boolean sendKeyEvent (int type, GdkEventKey keyEvent) {
- int length = keyEvent.length;
- if (keyEvent.string == 0 || OS.g_utf8_strlen (keyEvent.string, length) <= 1) {
- Event event = new Event ();
- event.time = keyEvent.time;
- if (!setKeyState (event, keyEvent)) return true;
- sendEvent (type, event);
- // widget could be disposed at this point
-
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the key
- * events. If this happens, end the processing of
- * the key by returning false.
- */
- if (isDisposed ()) return false;
- return event.doit;
- }
- byte [] buffer = new byte [length];
- OS.memmove (buffer, keyEvent.string, length);
- char [] chars = Converter.mbcsToWcs (null, buffer);
- return sendIMKeyEvent (type, keyEvent, chars) != null;
-}
-
-char [] sendIMKeyEvent (int type, GdkEventKey keyEvent, char [] chars) {
- int index = 0, count = 0, state = 0;
- int /*long*/ ptr = 0;
- if (keyEvent == null) {
- ptr = OS.gtk_get_current_event ();
- if (ptr != 0) {
- keyEvent = new GdkEventKey ();
- OS.memmove (keyEvent, ptr, GdkEventKey.sizeof);
- switch (keyEvent.type) {
- case OS.GDK_KEY_PRESS:
- case OS.GDK_KEY_RELEASE:
- state = keyEvent.state;
- break;
- default:
- keyEvent = null;
- break;
- }
- }
- }
- if (keyEvent == null) {
- int [] buffer = new int [1];
- OS.gtk_get_current_event_state (buffer);
- state = buffer [0];
- }
- while (index < chars.length) {
- Event event = new Event ();
- if (keyEvent != null && chars.length <= 1) {
- setKeyState (event, keyEvent);
- } else {
- setInputState (event, state);
- }
- event.character = chars [index];
- sendEvent (type, event);
-
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the key
- * events. If this happens, end the processing of
- * the key by returning null.
- */
- if (isDisposed ()) {
- if (ptr != 0) OS.gdk_event_free (ptr);
- return null;
- }
- if (event.doit) chars [count++] = chars [index];
- index++;
- }
- if (ptr != 0) OS.gdk_event_free (ptr);
- if (count == 0) return null;
- if (index != count) {
- char [] result = new char [count];
- System.arraycopy (chars, 0, result, 0, count);
- return result;
- }
- return chars;
-}
-
-/**
- * Sets the application defined widget data associated
- * with the receiver to be the argument. The <em>widget
- * data</em> is a single, unnamed field that is stored
- * with every widget.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the widget data needs to be notified
- * when the widget is disposed of, it is the application's
- * responsibility to hook the Dispose event on the widget and
- * do so.
- * </p>
- *
- * @param data the widget data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
- * </ul>
- *
- * @see #getData()
- */
-public void setData (Object data) {
- checkWidget();
- if ((state & KEYED_DATA) != 0) {
- ((Object []) this.data) [0] = data;
- } else {
- this.data = data;
- }
-}
-
-/**
- * Sets the application defined property of the receiver
- * with the specified name to the given value.
- * <p>
- * Applications may associate arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the widget is disposed
- * of, it is the application's responsibility to hook the
- * Dispose event on the widget and do so.
- * </p>
- *
- * @param key the name of the property
- * @param value the new value for the property
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getData(String)
- */
-public void setData (String key, Object value) {
- checkWidget();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = 1;
- Object [] table = null;
- if ((state & KEYED_DATA) != 0) {
- table = (Object []) data;
- while (index < table.length) {
- if (key.equals (table [index])) break;
- index += 2;
- }
- }
- if (value != null) {
- if ((state & KEYED_DATA) != 0) {
- if (index == table.length) {
- Object [] newTable = new Object [table.length + 2];
- System.arraycopy (table, 0, newTable, 0, table.length);
- data = table = newTable;
- }
- } else {
- table = new Object [3];
- table [0] = data;
- data = table;
- state |= KEYED_DATA;
- }
- table [index] = key;
- table [index + 1] = value;
- } else {
- if ((state & KEYED_DATA) != 0) {
- if (index != table.length) {
- int length = table.length - 2;
- if (length == 1) {
- data = table [0];
- state &= ~KEYED_DATA;
- } else {
- Object [] newTable = new Object [length];
- System.arraycopy (table, 0, newTable, 0, index);
- System.arraycopy (table, index + 2, newTable, index, length - index);
- data = newTable;
- }
- }
- }
- }
-}
-
-void setForegroundColor (int /*long*/ handle, GdkColor color) {
- int /*long*/ style = OS.gtk_widget_get_modifier_style (handle);
- OS.gtk_rc_style_set_fg (style, OS.GTK_STATE_NORMAL, color);
- OS.gtk_rc_style_set_fg (style, OS.GTK_STATE_ACTIVE, color);
- OS.gtk_rc_style_set_fg (style, OS.GTK_STATE_PRELIGHT, color);
- int flags = OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_NORMAL);
- flags = (color == null) ? flags & ~OS.GTK_RC_FG: flags | OS.GTK_RC_FG;
- OS.gtk_rc_style_set_color_flags (style, OS.GTK_STATE_NORMAL, flags);
- flags = OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_ACTIVE);
- flags = (color == null) ? flags & ~OS.GTK_RC_FG: flags | OS.GTK_RC_FG;
- OS.gtk_rc_style_set_color_flags (style, OS.GTK_STATE_ACTIVE, flags);
- flags = OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_PRELIGHT);
- flags = (color == null) ? flags & ~OS.GTK_RC_FG: flags | OS.GTK_RC_FG;
- OS.gtk_rc_style_set_color_flags (style, OS.GTK_STATE_PRELIGHT, flags);
-
- OS.gtk_rc_style_set_text (style, OS.GTK_STATE_NORMAL, color);
- OS.gtk_rc_style_set_text (style, OS.GTK_STATE_ACTIVE, color);
- OS.gtk_rc_style_set_text (style, OS.GTK_STATE_PRELIGHT, color);
- flags = OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_NORMAL);
- flags = (color == null) ? flags & ~OS.GTK_RC_TEXT: flags | OS.GTK_RC_TEXT;
- OS.gtk_rc_style_set_color_flags (style, OS.GTK_STATE_NORMAL, flags);
- flags = OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_PRELIGHT);
- flags = (color == null) ? flags & ~OS.GTK_RC_TEXT: flags | OS.GTK_RC_TEXT;
- OS.gtk_rc_style_set_color_flags (style, OS.GTK_STATE_PRELIGHT, flags);
- flags = OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_ACTIVE);
- flags = (color == null) ? flags & ~OS.GTK_RC_TEXT: flags | OS.GTK_RC_TEXT;
- OS.gtk_rc_style_set_color_flags (style, OS.GTK_STATE_ACTIVE, flags);
- modifyStyle (handle, style);
-}
-
-boolean setInputState (Event event, int state) {
- if ((state & OS.GDK_MOD1_MASK) != 0) event.stateMask |= SWT.ALT;
- if ((state & OS.GDK_SHIFT_MASK) != 0) event.stateMask |= SWT.SHIFT;
- if ((state & OS.GDK_CONTROL_MASK) != 0) event.stateMask |= SWT.CONTROL;
- if ((state & OS.GDK_BUTTON1_MASK) != 0) event.stateMask |= SWT.BUTTON1;
- if ((state & OS.GDK_BUTTON2_MASK) != 0) event.stateMask |= SWT.BUTTON2;
- if ((state & OS.GDK_BUTTON3_MASK) != 0) event.stateMask |= SWT.BUTTON3;
- return true;
-}
-
-boolean setKeyState (Event event, GdkEventKey keyEvent) {
- if (keyEvent.string != 0 && OS.g_utf8_strlen (keyEvent.string, keyEvent.length) > 1) return false;
- boolean isNull = false;
- event.keyCode = Display.translateKey (keyEvent.keyval);
- switch (keyEvent.keyval) {
- case OS.GDK_BackSpace: event.character = SWT.BS; break;
- case OS.GDK_Linefeed: event.character = SWT.LF; break;
- case OS.GDK_KP_Enter:
- case OS.GDK_Return: event.character = SWT.CR; break;
- case OS.GDK_KP_Delete:
- case OS.GDK_Delete: event.character = SWT.DEL; break;
- case OS.GDK_Escape: event.character = SWT.ESC; break;
- case OS.GDK_Tab:
- case OS.GDK_ISO_Left_Tab: event.character = SWT.TAB; break;
- default: {
- if (event.keyCode == 0) {
- int [] keyval = new int [1], effective_group= new int [1], level = new int [1], consumed_modifiers = new int [1];
- if (OS.gdk_keymap_translate_keyboard_state(OS.gdk_keymap_get_default (), keyEvent.hardware_keycode, 0, keyEvent.group, keyval, effective_group, level, consumed_modifiers)) {
- event.keyCode = OS.gdk_keyval_to_unicode (keyval [0]);
- }
- }
- int key = keyEvent.keyval;
- if ((keyEvent.state & OS.GDK_CONTROL_MASK) != 0 && (0 <= key && key <= 0x7F)) {
- if ('a' <= key && key <= 'z') key -= 'a' - 'A';
- if (64 <= key && key <= 95) key -= 64;
- event.character = (char) key;
- isNull = keyEvent.keyval == '@' && key == 0;
- } else {
- event.character = (char) OS.gdk_keyval_to_unicode (key);
- }
- }
- }
- if (event.keyCode == 0 && event.character == 0) {
- if (!isNull) return false;
- }
- return setInputState (event, keyEvent.state);
-}
-
-void setOrientation () {
-}
-
-boolean setTabGroupFocus (boolean next) {
- return setTabItemFocus (next);
-}
-
-boolean setTabItemFocus (boolean next) {
- return false;
-}
-
-int /*long*/ shellMapProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) {
- return 0;
-}
-
-int /*long*/ sizeAllocateProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) {
- return 0;
-}
-
-int /*long*/ sizeRequestProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) {
- return 0;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- String string = "*Disposed*";
- if (!isDisposed ()) {
- string = "*Wrong Thread*";
- if (isValidThread ()) string = getNameText ();
- }
- return getName () + " {" + string + "}";
-}
-
-int /*long*/ topHandle () {
- return handle;
-}
-
-int /*long*/ timerProc (int /*long*/ widget) {
- return 0;
-}
-
-int /*long*/ treeSelectionProc (int /*long*/ model, int /*long*/ path, int /*long*/ iter, int [] selection, int length) {
- return 0;
-}
-
-boolean translateTraversal (int event) {
- return false;
-}
-
-int /*long*/ windowProc (int /*long*/ handle, int /*long*/ user_data) {
- switch ((int)/*64*/user_data) {
- case ACTIVATE: return gtk_activate (handle);
- case CHANGED: return gtk_changed (handle);
- case CLICKED: return gtk_clicked (handle);
- case DAY_SELECTED: return gtk_day_selected (handle);
- case DAY_SELECTED_DOUBLE_CLICK: return gtk_day_selected_double_click (handle);
- case HIDE: return gtk_hide (handle);
- case GRAB_FOCUS: return gtk_grab_focus (handle);
- case MAP: return gtk_map (handle);
- case MONTH_CHANGED: return gtk_month_changed (handle);
- case OUTPUT: return gtk_output (handle);
- case POPUP_MENU: return gtk_popup_menu (handle);
- case PREEDIT_CHANGED: return gtk_preedit_changed (handle);
- case REALIZE: return gtk_realize (handle);
- case SELECT: return gtk_select (handle);
- case SHOW: return gtk_show (handle);
- case VALUE_CHANGED: return gtk_value_changed (handle);
- case UNMAP: return gtk_unmap (handle);
- case UNREALIZE: return gtk_unrealize (handle);
- default: return 0;
- }
-}
-
-int /*long*/ windowProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) {
- switch ((int)/*64*/user_data) {
- case EXPOSE_EVENT_INVERSE: {
- GdkEventExpose gdkEvent = new GdkEventExpose ();
- OS.memmove (gdkEvent, arg0, GdkEventExpose.sizeof);
- int /*long*/ paintWindow = paintWindow();
- int /*long*/ window = gdkEvent.window;
- if (window != paintWindow) return 0;
- return (state & OBSCURED) != 0 ? 1 : 0;
- }
- case BUTTON_PRESS_EVENT_INVERSE:
- case BUTTON_RELEASE_EVENT_INVERSE:
- case MOTION_NOTIFY_EVENT_INVERSE: {
- return 1;
- }
- case BUTTON_PRESS_EVENT: return gtk_button_press_event (handle, arg0);
- case BUTTON_RELEASE_EVENT: return gtk_button_release_event (handle, arg0);
- case COMMIT: return gtk_commit (handle, arg0);
- case CONFIGURE_EVENT: return gtk_configure_event (handle, arg0);
- case DELETE_EVENT: return gtk_delete_event (handle, arg0);
- case ENTER_NOTIFY_EVENT: return gtk_enter_notify_event (handle, arg0);
- case EVENT: return gtk_event (handle, arg0);
- case EVENT_AFTER: return gtk_event_after (handle, arg0);
- case EXPOSE_EVENT: return gtk_expose_event (handle, arg0);
- case FOCUS: return gtk_focus (handle, arg0);
- case FOCUS_IN_EVENT: return gtk_focus_in_event (handle, arg0);
- case FOCUS_OUT_EVENT: return gtk_focus_out_event (handle, arg0);
- case KEY_PRESS_EVENT: return gtk_key_press_event (handle, arg0);
- case KEY_RELEASE_EVENT: return gtk_key_release_event (handle, arg0);
- case INPUT: return gtk_input (handle, arg0);
- case LEAVE_NOTIFY_EVENT: return gtk_leave_notify_event (handle, arg0);
- case MAP_EVENT: return gtk_map_event (handle, arg0);
- case MNEMONIC_ACTIVATE: return gtk_mnemonic_activate (handle, arg0);
- case MOTION_NOTIFY_EVENT: return gtk_motion_notify_event (handle, arg0);
- case MOVE_FOCUS: return gtk_move_focus (handle, arg0);
- case POPULATE_POPUP: return gtk_populate_popup (handle, arg0);
- case SCROLL_EVENT: return gtk_scroll_event (handle, arg0);
- case SHOW_HELP: return gtk_show_help (handle, arg0);
- case SIZE_ALLOCATE: return gtk_size_allocate (handle, arg0);
- case STYLE_SET: return gtk_style_set (handle, arg0);
- case TOGGLED: return gtk_toggled (handle, arg0);
- case UNMAP_EVENT: return gtk_unmap_event (handle, arg0);
- case VISIBILITY_NOTIFY_EVENT: return gtk_visibility_notify_event (handle, arg0);
- case WINDOW_STATE_EVENT: return gtk_window_state_event (handle, arg0);
- case ROW_DELETED: return gtk_row_deleted (handle, arg0);
- default: return 0;
- }
-}
-
-int /*long*/ windowProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ user_data) {
- switch ((int)/*64*/user_data) {
- case DELETE_RANGE: return gtk_delete_range (handle, arg0, arg1);
- case DELETE_TEXT: return gtk_delete_text (handle, arg0, arg1);
- case ROW_ACTIVATED: return gtk_row_activated (handle, arg0, arg1);
- case SCROLL_CHILD: return gtk_scroll_child (handle, arg0, arg1);
- case STATUS_ICON_POPUP_MENU: return gtk_status_icon_popup_menu (handle, arg0, arg1);
- case SWITCH_PAGE: return gtk_switch_page (handle, arg0, arg1);
- case TEST_COLLAPSE_ROW: return gtk_test_collapse_row (handle, arg0, arg1);
- case TEST_EXPAND_ROW: return gtk_test_expand_row(handle, arg0, arg1);
- case ROW_INSERTED: return gtk_row_inserted (handle, arg0, arg1);
- default: return 0;
- }
-}
-
-int /*long*/ windowProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2, int /*long*/ user_data) {
- switch ((int)/*64*/user_data) {
- case CHANGE_VALUE: return gtk_change_value (handle, arg0, arg1, arg2);
- case EXPAND_COLLAPSE_CURSOR_ROW: return gtk_expand_collapse_cursor_row (handle, arg0, arg1, arg2);
- case INSERT_TEXT: return gtk_insert_text (handle, arg0, arg1, arg2);
- case TEXT_BUFFER_INSERT_TEXT: return gtk_text_buffer_insert_text (handle, arg0, arg1, arg2);
- default: return 0;
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java
deleted file mode 100755
index b202ed4fa5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java
+++ /dev/null
@@ -1,339 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage the operating system resources that
- * implement SWT's RGB color model. To create a color you can either
- * specify the individual color components as integers in the range
- * 0 to 255 or provide an instance of an <code>RGB</code>.
- * <p>
- * Application code must explicitly invoke the <code>Color.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see RGB
- * @see Device#getSystemColor
- * @see <a href="http://www.eclipse.org/swt/snippets/#color">Color and RGB snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Color extends Resource {
- /**
- * the handle to the OS color resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public XColor handle;
-
-Color(Device device) {
- super(device);
-}
-/**
- * Constructs a new instance of this class given a device and the
- * desired red, green and blue values expressed as ints in the range
- * 0 to 255 (where 0 is black and 255 is full brightness). On limited
- * color devices, the color instance created by this call may not have
- * the same RGB values as the ones specified by the arguments. The
- * RGB values on the returned instance will be the color values of
- * the operating system color.
- * <p>
- * You must dispose the color when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param red the amount of red in the color
- * @param green the amount of green in the color
- * @param blue the amount of blue in the color
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255</li>
- * </ul>
- *
- * @see #dispose
- */
-public Color (Device device, int red, int green, int blue) {
- super(device);
- init(red, green, blue);
- init();
-}
-/**
- * Constructs a new instance of this class given a device and an
- * <code>RGB</code> describing the desired red, green and blue values.
- * On limited color devices, the color instance created by this call
- * may not have the same RGB values as the ones specified by the
- * argument. The RGB values on the returned instance will be the color
- * values of the operating system color.
- * <p>
- * You must dispose the color when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param rgb the RGB values of the desired color
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the rgb argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue components of the argument are not between 0 and 255</li>
- * </ul>
- *
- * @see #dispose
- */
-public Color (Device device, RGB rgb) {
- super(device);
- if (rgb == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(rgb.red, rgb.green, rgb.blue);
- init();
-}
-void destroy() {
- int xDisplay = device.xDisplay;
- int pixel = handle.pixel;
- if (device.colorRefCount != null) {
- /* If this was the last reference, remove the color from the list */
- if (--device.colorRefCount[pixel] == 0) {
- device.xcolors[pixel] = null;
- }
- }
- int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay));
- OS.XFreeColors(xDisplay, colormap, new int[] { pixel }, 1, 0);
- handle = null;
-}
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Color)) return false;
- Color color = (Color)object;
- XColor xColor = color.handle;
- if (handle == xColor) return true;
- return device == color.device && handle.red == xColor.red &&
- handle.green == xColor.green && handle.blue == xColor.blue;
-}
-/**
- * Returns the amount of blue in the color, from 0 to 255.
- *
- * @return the blue component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getBlue () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (handle.blue >> 8) & 0xFF;
-}
-/**
- * Returns the amount of green in the color, from 0 to 255.
- *
- * @return the green component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getGreen () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (handle.green >> 8) & 0xFF;
-}
-/**
- * Returns the amount of red in the color, from 0 to 255.
- *
- * @return the red component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getRed () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (handle.red >> 8) & 0xFF;
-}
-/**
- * Returns an <code>RGB</code> representing the receiver.
- *
- * @return the RGB for the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public RGB getRGB () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return new RGB((handle.red >> 8) & 0xFF, (handle.green >> 8) & 0xFF, (handle.blue >> 8) & 0xFF);
-}
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- if (isDisposed()) return 0;
- return handle.red ^ handle.green ^ handle.blue;
-}
-void init(int red, int green, int blue) {
- if ((red > 255) || (red < 0) ||
- (green > 255) || (green < 0) ||
- (blue > 255) || (blue < 0)) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- XColor xColor = new XColor();
- xColor.red = (short)((red & 0xFF) | ((red & 0xFF) << 8));
- xColor.green = (short)((green & 0xFF) | ((green & 0xFF) << 8));
- xColor.blue = (short)((blue & 0xFF) | ((blue & 0xFF) << 8));
- handle = xColor;
- int xDisplay = device.xDisplay;
- int screen = OS.XDefaultScreen(xDisplay);
- int colormap = OS.XDefaultColormap(xDisplay, screen);
- /* 1. Try to allocate the color */
- if (OS.XAllocColor(xDisplay, colormap, xColor) != 0) {
- if (device.colorRefCount != null) {
- /* Make a copy of the color to put in the colors array */
- XColor colorCopy = new XColor();
- colorCopy.red = xColor.red;
- colorCopy.green = xColor.green;
- colorCopy.blue = xColor.blue;
- colorCopy.pixel = xColor.pixel;
- device.xcolors[colorCopy.pixel] = colorCopy;
- device.colorRefCount[xColor.pixel]++;
- }
- return;
- }
- /*
- * 2. Allocation failed. Query the entire colormap and
- * find the closest match which can be allocated.
- * This should never occur on a truecolor display.
- */
- Visual visual = new Visual();
- OS.memmove(visual, OS.XDefaultVisual(xDisplay, screen), Visual.sizeof);
- int mapEntries = visual.map_entries;
- XColor[] queried = new XColor[mapEntries];
- int[] distances = new int[mapEntries];
- /*
- * Query all colors in the colormap and calculate the distance
- * from each to the desired color.
- */
- for (int i = 0; i < mapEntries; i++) {
- XColor color = new XColor();
- color.pixel = i;
- queried[i] = color;
- OS.XQueryColor(xDisplay, colormap, color);
- int r = red - ((color.red >> 8) & 0xFF);
- int g = green - ((color.green >> 8) & 0xFF);
- int b = blue - ((color.blue >> 8) & 0xFF);
- distances[i] = r*r + g*g + b*b;
- }
- /*
- * Try to allocate closest matching queried color.
- * The allocation can fail if the closest matching
- * color is allocated privately, so go through them
- * in order of increasing distance.
- */
- for (int i = 0; i < mapEntries; i++) {
- int minDist = 0x30000;
- int minIndex = 0;
- for (int j = 0; j < mapEntries; j++) {
- if (distances[j] < minDist) {
- minDist = distances[j];
- minIndex = j;
- }
- }
- XColor queriedColor = queried[minIndex];
- XColor osColor = new XColor();
- osColor.red = queriedColor.red;
- osColor.green = queriedColor.green;
- osColor.blue = queriedColor.blue;
- if (OS.XAllocColor(xDisplay, colormap, osColor) != 0) {
- /* Allocation succeeded. Copy the fields into the handle */
- xColor.red = osColor.red;
- xColor.green = osColor.green;
- xColor.blue = osColor.blue;
- xColor.pixel = osColor.pixel;
- if (device.colorRefCount != null) {
- /* Put osColor in the colors array */
- device.xcolors[osColor.pixel] = osColor;
- device.colorRefCount[osColor.pixel]++;
- }
- return;
- }
- /* The allocation failed; matching color is allocated privately */
- distances[minIndex] = 0x30000;
- }
- /*
- * 3. Couldn't allocate any of the colors in the colormap.
- * This means all colormap entries were allocated privately
- * by other applications. Give up and allocate black.
- */
- XColor osColor = new XColor();
- OS.XAllocColor(xDisplay, colormap, osColor);
- /* Copy the fields into the handle */
- xColor.red = osColor.red;
- xColor.green = osColor.green;
- xColor.blue = osColor.blue;
- xColor.pixel = osColor.pixel;
- if (device.colorRefCount != null) {
- /* Put osColor in the colors array */
- device.xcolors[osColor.pixel] = osColor;
- device.colorRefCount[osColor.pixel]++;
- }
-}
-/**
- * Returns <code>true</code> if the color has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the color.
- * When a color has been disposed, it is an error to
- * invoke any other method using the color.
- *
- * @return <code>true</code> when the color is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == null;
-}
-public static Color motif_new(Device device, XColor xColor) {
- Color color = new Color(device);
- color.handle = xColor;
- return color;
-}
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Color {*DISPOSED*}";
- return "Color {" + getRed() + ", " + getGreen() + ", " + getBlue() + "}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Cursor.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Cursor.java
deleted file mode 100755
index cc3c048e0f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Cursor.java
+++ /dev/null
@@ -1,441 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage operating system resources that
- * specify the appearance of the on-screen pointer. To create a
- * cursor you specify the device and either a simple cursor style
- * describing one of the standard operating system provided cursors
- * or the image and mask data for the desired appearance.
- * <p>
- * Application code must explicitly invoke the <code>Cursor.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>
- * CURSOR_ARROW, CURSOR_WAIT, CURSOR_CROSS, CURSOR_APPSTARTING, CURSOR_HELP,
- * CURSOR_SIZEALL, CURSOR_SIZENESW, CURSOR_SIZENS, CURSOR_SIZENWSE, CURSOR_SIZEWE,
- * CURSOR_SIZEN, CURSOR_SIZES, CURSOR_SIZEE, CURSOR_SIZEW, CURSOR_SIZENE, CURSOR_SIZESE,
- * CURSOR_SIZESW, CURSOR_SIZENW, CURSOR_UPARROW, CURSOR_IBEAM, CURSOR_NO, CURSOR_HAND
- * </dd>
- * </dl>
- * <p>
- * Note: Only one of the above styles may be specified.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#cursor">Cursor snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Cursor extends Resource {
- /**
- * the handle to the OS cursor resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
- static final byte[] APPSTARTING_SRC = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
- 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
- 0x7c, 0x00, 0x00, 0x00, (byte)0xfc, 0x00, 0x00, 0x00, (byte)0xfc, 0x01, 0x00, 0x00,
- (byte)0xfc, 0x3b, 0x00, 0x00, 0x7c, 0x38, 0x00, 0x00, 0x6c, 0x54, 0x00, 0x00,
- (byte)0xc4, (byte)0xdc, 0x00, 0x00, (byte)0xc0, 0x44, 0x00, 0x00, (byte)0x80, 0x39, 0x00, 0x00,
- (byte)0x80, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-
- static final byte[] APPSTARTING_MASK = {
- 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00,
- 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00,
- (byte)0xfe, 0x00, 0x00, 0x00, (byte)0xfe, 0x01, 0x00, 0x00, (byte)0xfe, 0x3b, 0x00, 0x00,
- (byte)0xfe, 0x7f, 0x00, 0x00, (byte)0xfe, 0x7f, 0x00, 0x00, (byte)0xfe, (byte)0xfe, 0x00, 0x00,
- (byte)0xee, (byte)0xff, 0x01, 0x00, (byte)0xe4, (byte)0xff, 0x00, 0x00, (byte)0xc0, 0x7f, 0x00, 0x00,
- (byte)0xc0, 0x7f, 0x00, 0x00, (byte)0x80, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-
-Cursor (Device device) {
- super(device);
-}
-/**
- * Constructs a new cursor given a device and a style
- * constant describing the desired cursor appearance.
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param style the style of cursor to allocate
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - when an unknown style is specified</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- *
- * @see SWT#CURSOR_ARROW
- * @see SWT#CURSOR_WAIT
- * @see SWT#CURSOR_CROSS
- * @see SWT#CURSOR_APPSTARTING
- * @see SWT#CURSOR_HELP
- * @see SWT#CURSOR_SIZEALL
- * @see SWT#CURSOR_SIZENESW
- * @see SWT#CURSOR_SIZENS
- * @see SWT#CURSOR_SIZENWSE
- * @see SWT#CURSOR_SIZEWE
- * @see SWT#CURSOR_SIZEN
- * @see SWT#CURSOR_SIZES
- * @see SWT#CURSOR_SIZEE
- * @see SWT#CURSOR_SIZEW
- * @see SWT#CURSOR_SIZENE
- * @see SWT#CURSOR_SIZESE
- * @see SWT#CURSOR_SIZESW
- * @see SWT#CURSOR_SIZENW
- * @see SWT#CURSOR_UPARROW
- * @see SWT#CURSOR_IBEAM
- * @see SWT#CURSOR_NO
- * @see SWT#CURSOR_HAND
- */
-public Cursor (Device device, int style) {
- super(device);
- int shape = 0;
- switch (style) {
- case SWT.CURSOR_APPSTARTING: break;
- case SWT.CURSOR_ARROW: shape = OS.XC_left_ptr; break;
- case SWT.CURSOR_WAIT: shape = OS.XC_watch; break;
- case SWT.CURSOR_HAND: shape = OS.XC_hand2; break;
- case SWT.CURSOR_CROSS: shape = OS.XC_cross; break;
- case SWT.CURSOR_HELP: shape = OS.XC_question_arrow; break;
- case SWT.CURSOR_SIZEALL: shape = OS.XC_fleur; break;
- case SWT.CURSOR_SIZENESW: shape = OS.XC_sizing; break;
- case SWT.CURSOR_SIZENS: shape = OS.XC_double_arrow; break;
- case SWT.CURSOR_SIZENWSE: shape = OS.XC_sizing; break;
- case SWT.CURSOR_SIZEWE: shape = OS.XC_sb_h_double_arrow; break;
- case SWT.CURSOR_SIZEN: shape = OS.XC_top_side; break;
- case SWT.CURSOR_SIZES: shape = OS.XC_bottom_side; break;
- case SWT.CURSOR_SIZEE: shape = OS.XC_right_side; break;
- case SWT.CURSOR_SIZEW: shape = OS.XC_left_side; break;
- case SWT.CURSOR_SIZENE: shape = OS.XC_top_right_corner; break;
- case SWT.CURSOR_SIZESE: shape = OS.XC_bottom_right_corner; break;
- case SWT.CURSOR_SIZESW: shape = OS.XC_bottom_left_corner; break;
- case SWT.CURSOR_SIZENW: shape = OS.XC_top_left_corner; break;
- case SWT.CURSOR_UPARROW: shape = OS.XC_sb_up_arrow; break;
- case SWT.CURSOR_IBEAM: shape = OS.XC_xterm; break;
- case SWT.CURSOR_NO: shape = OS.XC_X_cursor; break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (shape == 0 && style == SWT.CURSOR_APPSTARTING) {
- handle = createCursor(APPSTARTING_SRC, APPSTARTING_MASK, 32, 32, 2, 2, true);
- } else {
- handle = OS.XCreateFontCursor(this.device.xDisplay, shape);
- }
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-/**
- * Constructs a new cursor given a device, image and mask
- * data describing the desired cursor appearance, and the x
- * and y coordinates of the <em>hotspot</em> (that is, the point
- * within the area covered by the cursor which is considered
- * to be where the on-screen pointer is "pointing").
- * <p>
- * The mask data is allowed to be null, but in this case the source
- * must be an ImageData representing an icon that specifies both
- * color data and mask data.
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param source the color data for the cursor
- * @param mask the mask data for the cursor (or null)
- * @param hotspotX the x coordinate of the cursor's hotspot
- * @param hotspotY the y coordinate of the cursor's hotspot
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the source is null</li>
- * <li>ERROR_NULL_ARGUMENT - if the mask is null and the source does not have a mask</li>
- * <li>ERROR_INVALID_ARGUMENT - if the source and the mask are not the same
- * size, or if the hotspot is outside the bounds of the image</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- */
-public Cursor (Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (mask == null) {
- if (source.getTransparencyType() != SWT.TRANSPARENCY_MASK) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- mask = source.getTransparencyMask();
- }
- /* Check the bounds. Mask must be the same size as source */
- if (mask.width != source.width || mask.height != source.height) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- /* Check the hotspots */
- if (hotspotX >= source.width || hotspotX < 0 ||
- hotspotY >= source.height || hotspotY < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- /* Convert depth to 1 */
- source = ImageData.convertMask(source);
- mask = ImageData.convertMask(mask);
- byte[] sourceData = new byte[source.data.length];
- byte[] maskData = new byte[mask.data.length];
- /* Swap the bits in each byte and convert to appropriate scanline pad */
- byte[] data = source.data;
- for (int i = 0; i < data.length; i++) {
- byte s = data[i];
- sourceData[i] = (byte)(((s & 0x80) >> 7) |
- ((s & 0x40) >> 5) |
- ((s & 0x20) >> 3) |
- ((s & 0x10) >> 1) |
- ((s & 0x08) << 1) |
- ((s & 0x04) << 3) |
- ((s & 0x02) << 5) |
- ((s & 0x01) << 7));
- sourceData[i] = (byte) ~sourceData[i];
- }
- sourceData = ImageData.convertPad(sourceData, source.width, source.height, source.depth, source.scanlinePad, 1);
- data = mask.data;
- for (int i = 0; i < data.length; i++) {
- byte s = data[i];
- maskData[i] = (byte)(((s & 0x80) >> 7) |
- ((s & 0x40) >> 5) |
- ((s & 0x20) >> 3) |
- ((s & 0x10) >> 1) |
- ((s & 0x08) << 1) |
- ((s & 0x04) << 3) |
- ((s & 0x02) << 5) |
- ((s & 0x01) << 7));
- maskData[i] = (byte) ~maskData[i];
- }
- maskData = ImageData.convertPad(maskData, mask.width, mask.height, mask.depth, mask.scanlinePad, 1);
- /* Note that the mask and source are reversed */
- handle = createCursor(maskData, sourceData, source.width, source.height, hotspotX, hotspotY, true);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-/**
- * Constructs a new cursor given a device, image data describing
- * the desired cursor appearance, and the x and y coordinates of
- * the <em>hotspot</em> (that is, the point within the area
- * covered by the cursor which is considered to be where the
- * on-screen pointer is "pointing").
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param source the image data for the cursor
- * @param hotspotX the x coordinate of the cursor's hotspot
- * @param hotspotY the y coordinate of the cursor's hotspot
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the hotspot is outside the bounds of the
- * image</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- *
- * @since 3.0
- */
-public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (hotspotX >= source.width || hotspotX < 0 ||
- hotspotY >= source.height || hotspotY < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- ImageData mask = source.getTransparencyMask();
-
- /* Ensure depth is equal to 1 */
- if (source.depth > 1) {
- /* Create a destination image with no data */
- ImageData newSource = new ImageData(
- source.width, source.height, 1, ImageData.bwPalette(),
- 1, null, 0, null, null, -1, -1, 0, 0, 0, 0, 0);
-
- byte[] newReds = new byte[]{0, (byte)255}, newGreens = newReds, newBlues = newReds;
-
- /* Convert the source to a black and white image of depth 1 */
- PaletteData palette = source.palette;
- if (palette.isDirect) {
- ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, palette.redMask, palette.greenMask, palette.blueMask,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- newSource.data, newSource.depth, newSource.bytesPerLine, newSource.getByteOrder(), 0, 0, newSource.width, newSource.height, newReds, newGreens, newBlues,
- false, false);
- } else {
- RGB[] rgbs = palette.getRGBs();
- int length = rgbs.length;
- byte[] srcReds = new byte[length];
- byte[] srcGreens = new byte[length];
- byte[] srcBlues = new byte[length];
- for (int i = 0; i < rgbs.length; i++) {
- RGB rgb = rgbs[i];
- if (rgb == null) continue;
- srcReds[i] = (byte)rgb.red;
- srcGreens[i] = (byte)rgb.green;
- srcBlues[i] = (byte)rgb.blue;
- }
- ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, srcReds, srcGreens, srcBlues,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- newSource.data, newSource.depth, newSource.bytesPerLine, newSource.getByteOrder(), 0, 0, newSource.width, newSource.height, newReds, newGreens, newBlues,
- false, false);
- }
- source = newSource;
- }
-
- /* Swap the bits in each byte and convert to appropriate scanline pad */
- byte[] sourceData = new byte[source.data.length];
- byte[] maskData = new byte[mask.data.length];
- byte[] data = source.data;
- for (int i = 0; i < data.length; i++) {
- byte s = data[i];
- sourceData[i] = (byte)(((s & 0x80) >> 7) |
- ((s & 0x40) >> 5) |
- ((s & 0x20) >> 3) |
- ((s & 0x10) >> 1) |
- ((s & 0x08) << 1) |
- ((s & 0x04) << 3) |
- ((s & 0x02) << 5) |
- ((s & 0x01) << 7));
- }
- sourceData = ImageData.convertPad(sourceData, source.width, source.height, source.depth, source.scanlinePad, 1);
- data = mask.data;
- for (int i = 0; i < data.length; i++) {
- byte s = data[i];
- maskData[i] = (byte)(((s & 0x80) >> 7) |
- ((s & 0x40) >> 5) |
- ((s & 0x20) >> 3) |
- ((s & 0x10) >> 1) |
- ((s & 0x08) << 1) |
- ((s & 0x04) << 3) |
- ((s & 0x02) << 5) |
- ((s & 0x01) << 7));
- }
- maskData = ImageData.convertPad(maskData, mask.width, mask.height, mask.depth, mask.scanlinePad, 1);
- handle = createCursor(sourceData, maskData, source.width, source.height, hotspotX, hotspotY, false);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-int createCursor(byte[] sourceData, byte[] maskData, int width, int height, int hotspotX, int hotspotY, boolean reverse) {
- int xDisplay = device.xDisplay;
- int drawable = OS.XDefaultRootWindow(xDisplay);
- int sourcePixmap = OS.XCreateBitmapFromData(xDisplay, drawable, sourceData, width, height);
- int maskPixmap = OS.XCreateBitmapFromData(xDisplay, drawable, maskData, width, height);
- int cursor = 0;
- if (sourcePixmap != 0 && maskPixmap != 0) {
- int screenNum = OS.XDefaultScreen(xDisplay);
- XColor foreground = new XColor();
- foreground.pixel = !reverse ? OS.XWhitePixel(xDisplay, screenNum) : OS.XBlackPixel(xDisplay, screenNum);
- if (!reverse) foreground.red = foreground.green = foreground.blue = (short)0xFFFF;
- XColor background = new XColor();
- background.pixel = reverse ? OS.XWhitePixel(xDisplay, screenNum) : OS.XBlackPixel(xDisplay, screenNum);
- if (reverse) background.red = background.green = background.blue = (short)0xFFFF;
- cursor = OS.XCreatePixmapCursor(xDisplay, sourcePixmap, maskPixmap, foreground, background, hotspotX, hotspotY);
- }
- if (sourcePixmap != 0) OS.XFreePixmap(xDisplay, sourcePixmap);
- if (maskPixmap != 0) OS.XFreePixmap(xDisplay, maskPixmap);
- return cursor;
-}
-void destroy() {
- OS.XFreeCursor(device.xDisplay, handle);
- handle = 0;
-}
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Cursor)) return false;
- Cursor cursor = (Cursor)object;
- return device == cursor.device && handle == cursor.handle;
-}
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return handle;
-}
-/**
- * Returns <code>true</code> if the cursor has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the cursor.
- * When a cursor has been disposed, it is an error to
- * invoke any other method using the cursor.
- *
- * @return <code>true</code> when the cursor is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-public static Cursor motif_new(Device device, int handle) {
- Cursor cursor = new Cursor(device);
- cursor.handle = handle;
- return cursor;
-}
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Cursor {*DISPOSED*}";
- return "Cursor {" + handle + "}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java
deleted file mode 100755
index 4587d5ffe2..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java
+++ /dev/null
@@ -1,1021 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-
-/**
- * This class is the abstract superclass of all device objects,
- * such as the Display device and the Printer device. Devices
- * can have a graphics context (GC) created for them, and they
- * can be drawn on by sending messages to the associated GC.
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class Device implements Drawable {
- /**
- * the handle to the X Display
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int xDisplay;
-
- /**
- * whether the XLFD resolution should match the
- * resolution of the device when fonts are created
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- // TEMPORARY CODE
- public boolean setDPI;
-
- /* Debugging */
- public static boolean DEBUG;
- boolean debug = DEBUG;
- boolean tracking = DEBUG;
- Error [] errors;
- Object [] objects;
- Object trackingLock;
-
- /* Arguments for XtOpenDisplay */
- String display_name;
- String application_name;
- String application_class;
-
- /* Colormap and reference count for this display */
- XColor [] xcolors;
- int [] colorRefCount;
-
- /* System Colors */
- Color COLOR_BLACK, COLOR_DARK_RED, COLOR_DARK_GREEN, COLOR_DARK_YELLOW, COLOR_DARK_BLUE;
- Color COLOR_DARK_MAGENTA, COLOR_DARK_CYAN, COLOR_GRAY, COLOR_DARK_GRAY, COLOR_RED;
- Color COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE;
-
- /* System Font */
- Font systemFont;
-
- int shellHandle;
-
- boolean useXRender;
-
- static boolean CAIRO_LOADED;
-
- /* Parsing Tables */
- int tabPointer, crPointer;
- /**
- * parse table mappings for tab and cr
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- // TEMPORARY CODE
- public int tabMapping, crMapping;
-
- /* Xt Warning and Error Handlers */
- boolean warnings = true;
- Callback xtWarningCallback, xtErrorCallback;
- int xtWarningProc, xtErrorProc, xtNullWarningProc, xtNullErrorProc;
-
- /* X Warning and Error Handlers */
- static Callback XErrorCallback, XIOErrorCallback;
- static int XErrorProc, XIOErrorProc, XNullErrorProc, XNullIOErrorProc;
- static Device[] Devices = new Device[4];
-
- /* Initialize X and Xt */
- static {
- /*
- * This code is intentionally commented.
- */
-// OS.XInitThreads ();
-// OS.XtToolkitThreadInitialize ();
- OS.XtToolkitInitialize ();
- }
-
- /*
- * TEMPORARY CODE. When a graphics object is
- * created and the device parameter is null,
- * the current Display is used. This presents
- * a problem because SWT graphics does not
- * reference classes in SWT widgets. The correct
- * fix is to remove this feature. Unfortunately,
- * too many application programs rely on this
- * feature.
- */
- protected static Device CurrentDevice;
- protected static Runnable DeviceFinder;
- static {
- try {
- Class.forName ("org.eclipse.swt.widgets.Display");
- } catch (ClassNotFoundException e) {}
- }
-
-/*
-* TEMPORARY CODE
-*/
-static synchronized Device getDevice () {
- if (DeviceFinder != null) DeviceFinder.run();
- Device device = CurrentDevice;
- CurrentDevice = null;
- return device;
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * You must dispose the device when it is no longer required.
- * </p>
- *
- * @see #create
- * @see #init
- *
- * @since 3.1
- */
-public Device() {
- this(null);
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * You must dispose the device when it is no longer required.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #create
- * @see #init
- * @see DeviceData
- */
-public Device(DeviceData data) {
- synchronized (Device.class) {
- if (data != null) {
- display_name = data.display_name;
- application_name = data.application_name;
- application_class = data.application_class;
- tracking = data.tracking;
- debug = data.debug;
- }
- if (tracking) {
- errors = new Error [128];
- objects = new Object [128];
- trackingLock = new Object ();
- }
- create (data);
- init ();
- register (this);
-
- /* Initialize the system font slot */
- systemFont = getSystemFont ();
- }
-}
-
-void checkCairo() {
- if (CAIRO_LOADED) return;
- try {
- /* Check if cairo is available on the system */
- byte[] buffer = Converter.wcsToMbcs(null, "libcairo.so.2", true);
- int /*long*/ libcairo = OS.dlopen(buffer, OS.RTLD_LAZY);
- if (libcairo != 0) {
- OS.dlclose(libcairo);
- } else {
- try {
- System.loadLibrary("cairo-swt");
- } catch (UnsatisfiedLinkError e) {
- /* Ignore problems loading the fallback library */
- }
- }
- Class.forName("org.eclipse.swt.internal.cairo.Cairo");
- CAIRO_LOADED = true;
- } catch (Throwable t) {
- SWT.error(SWT.ERROR_NO_GRAPHICS_LIBRARY, t, " [Cairo required]");
- }
-}
-
-/**
- * Throws an <code>SWTException</code> if the receiver can not
- * be accessed by the caller. This may include both checks on
- * the state of the receiver and more generally on the entire
- * execution context. This method <em>should</em> be called by
- * device implementors to enforce the standard SWT invariants.
- * <p>
- * Currently, it is an error to invoke any method (other than
- * <code>isDisposed()</code> and <code>dispose()</code>) on a
- * device that has had its <code>dispose()</code> method called.
- * </p><p>
- * In future releases of SWT, there may be more or fewer error
- * checks and exceptions may be thrown for different reasons.
- * <p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-protected void checkDevice () {
- if (xDisplay == 0) SWT.error (SWT.ERROR_DEVICE_DISPOSED);
-}
-
-/**
- * Creates the device in the operating system. If the device
- * does not have a handle, this method may do nothing depending
- * on the device.
- * <p>
- * This method is called before <code>init</code>.
- * </p><p>
- * Subclasses are supposed to reimplement this method and not
- * call the <code>super</code> implementation.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #init
- */
-protected void create (DeviceData data) {
-}
-
-synchronized static void deregister (Device device) {
- for (int i=0; i<Devices.length; i++) {
- if (device == Devices [i]) Devices [i] = null;
- }
-}
-
-/**
- * Destroys the device in the operating system and releases
- * the device's handle. If the device does not have a handle,
- * this method may do nothing depending on the device.
- * <p>
- * This method is called after <code>release</code>.
- * </p><p>
- * Subclasses are supposed to reimplement this method and not
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #dispose
- * @see #release
- */
-protected void destroy () {
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the receiver. After this method has been invoked, the receiver
- * will answer <code>true</code> when sent the message
- * <code>isDisposed()</code>.
- *
- * @see #release
- * @see #destroy
- * @see #checkDevice
- */
-public void dispose () {
- synchronized (Device.class) {
- if (isDisposed()) return;
- checkDevice ();
- release ();
- destroy ();
- deregister (this);
- xDisplay = 0;
- if (tracking) {
- synchronized (trackingLock) {
- objects = null;
- errors = null;
- trackingLock = null;
- }
- }
- }
-}
-
-void dispose_Object (Object object) {
- synchronized (trackingLock) {
- for (int i=0; i<objects.length; i++) {
- if (objects [i] == object) {
- objects [i] = null;
- errors [i] = null;
- return;
- }
- }
- }
-}
-
-static synchronized Device findDevice (int xDisplay) {
- for (int i=0; i<Devices.length; i++) {
- Device device = Devices [i];
- if (device != null && device.xDisplay == xDisplay) {
- return device;
- }
- }
- return null;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location.
- *
- * @return the bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkDevice ();
- int screen = OS.XDefaultScreen (xDisplay);
- int width = OS.XDisplayWidth (xDisplay, screen);
- int height = OS.XDisplayHeight (xDisplay, screen);
- return new Rectangle (0, 0, width, height);
-}
-
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data.
- *
- * @return the client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getBounds
- */
-public Rectangle getClientArea () {
- return getBounds ();
-}
-
-/**
- * Returns the bit depth of the screen, which is the number of
- * bits it takes to represent the number of unique colors that
- * the screen is currently capable of displaying. This number
- * will typically be one of 1, 8, 15, 16, 24 or 32.
- *
- * @return the depth of the screen
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getDepth () {
- checkDevice ();
- int xScreenPtr = OS.XDefaultScreenOfDisplay (xDisplay);
- return OS.XDefaultDepthOfScreen (xScreenPtr);
-}
-
-/**
- * Returns a <code>DeviceData</code> based on the receiver.
- * Modifications made to this <code>DeviceData</code> will not
- * affect the receiver.
- *
- * @return a <code>DeviceData</code> containing the device's data and attributes
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see DeviceData
- */
-public DeviceData getDeviceData () {
- checkDevice ();
- DeviceData data = new DeviceData ();
- data.display_name = display_name;
- data.application_name = application_name;
- data.application_class = application_class;
- data.debug = debug;
- data.tracking = tracking;
- if (tracking) {
- synchronized (trackingLock) {
- int count = 0, length = objects.length;
- for (int i=0; i<length; i++) {
- if (objects [i] != null) count++;
- }
- int index = 0;
- data.objects = new Object [count];
- data.errors = new Error [count];
- for (int i=0; i<length; i++) {
- if (objects [i] != null) {
- data.objects [index] = objects [i];
- data.errors [index] = errors [i];
- index++;
- }
- }
- }
- } else {
- data.objects = new Object [0];
- data.errors = new Error [0];
- }
- return data;
-}
-
-/**
- * Returns a point whose x coordinate is the horizontal
- * dots per inch of the display, and whose y coordinate
- * is the vertical dots per inch of the display.
- *
- * @return the horizontal and vertical DPI
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point getDPI () {
- checkDevice ();
- int xScreenNum = OS.XDefaultScreen (xDisplay);
- int width = OS.XDisplayWidth (xDisplay, xScreenNum);
- int height = OS.XDisplayHeight (xDisplay, xScreenNum);
- int mmX = OS.XDisplayWidthMM (xDisplay, xScreenNum);
- int mmY = OS.XDisplayHeightMM (xDisplay, xScreenNum);
- /* 0.03937 mm/inch */
- double inchesX = mmX * 0.03937;
- double inchesY = mmY * 0.03937;
- int x = (int)((width / inchesX) + 0.5);
- int y = (int)((height / inchesY) + 0.5);
- return new Point (x, y);
-}
-
-/**
- * Returns <code>FontData</code> objects which describe
- * the fonts that match the given arguments. If the
- * <code>faceName</code> is null, all fonts will be returned.
- *
- * @param faceName the name of the font to look for, or null
- * @param scalable if true only scalable fonts are returned, otherwise only non-scalable fonts are returned.
- * @return the matching font data
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontData [] getFontList (String faceName, boolean scalable) {
- checkDevice ();
- String xlfd;
- if (faceName == null) {
- xlfd = "-*-*-*-*-*-*-*-*-*-*-*-*-*-*";
- } else {
- int dashIndex = faceName.indexOf('-');
- if (dashIndex < 0) {
- xlfd = "-*-" + faceName + "-*-*-*-*-*-*-*-*-*-*-*-*";
- } else {
- xlfd = "-" + faceName + "-*-*-*-*-*-*-*-*-*-*-*-*";
- }
- }
- /* Use the character encoding for the default locale */
- byte [] buffer1 = Converter.wcsToMbcs (null, xlfd, true);
- int [] ret = new int [1];
- int listPtr = OS.XListFonts (xDisplay, buffer1, 65535, ret);
- int ptr = listPtr;
- int [] intBuf = new int [1];
- FontData [] fd = new FontData [ret [0]];
- int fdIndex = 0;
- for (int i = 0; i < ret [0]; i++) {
- OS.memmove (intBuf, ptr, 4);
- int charPtr = intBuf [0];
- int length = OS.strlen (charPtr);
- byte [] buffer2 = new byte [length];
- OS.memmove (buffer2, charPtr, length);
- /* Use the character encoding for the default locale */
- char [] chars = Converter.mbcsToWcs (null, buffer2);
- try {
- FontData data = FontData.motif_new (new String (chars));
- boolean isScalable = data.averageWidth == 0 && data.pixels == 0 && data.points == 0;
- if (isScalable == scalable) {
- fd [fdIndex++] = data;
- }
- } catch (Exception e) {
- /* do not add the font to the list */
- }
- ptr += 4;
- }
- OS.XFreeFontNames (listPtr);
- if (fdIndex == ret [0]) return fd;
- FontData [] result = new FontData [fdIndex];
- System.arraycopy (fd, 0, result, 0, fdIndex);
- return result;
-}
-
-/**
- * Returns the matching standard color for the given
- * constant, which should be one of the color constants
- * specified in class <code>SWT</code>. Any value other
- * than one of the SWT color constants which is passed
- * in will result in the color black. This color should
- * not be freed because it was allocated by the system,
- * not the application.
- *
- * @param id the color constant
- * @return the matching color
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT
- */
-public Color getSystemColor (int id) {
- checkDevice ();
- switch (id) {
- case SWT.COLOR_BLACK: return COLOR_BLACK;
- case SWT.COLOR_DARK_RED: return COLOR_DARK_RED;
- case SWT.COLOR_DARK_GREEN: return COLOR_DARK_GREEN;
- case SWT.COLOR_DARK_YELLOW: return COLOR_DARK_YELLOW;
- case SWT.COLOR_DARK_BLUE: return COLOR_DARK_BLUE;
- case SWT.COLOR_DARK_MAGENTA: return COLOR_DARK_MAGENTA;
- case SWT.COLOR_DARK_CYAN: return COLOR_DARK_CYAN;
- case SWT.COLOR_GRAY: return COLOR_GRAY;
- case SWT.COLOR_DARK_GRAY: return COLOR_DARK_GRAY;
- case SWT.COLOR_RED: return COLOR_RED;
- case SWT.COLOR_GREEN: return COLOR_GREEN;
- case SWT.COLOR_YELLOW: return COLOR_YELLOW;
- case SWT.COLOR_BLUE: return COLOR_BLUE;
- case SWT.COLOR_MAGENTA: return COLOR_MAGENTA;
- case SWT.COLOR_CYAN: return COLOR_CYAN;
- case SWT.COLOR_WHITE: return COLOR_WHITE;
- }
- return COLOR_BLACK;
-}
-
-/**
- * Returns a reasonable font for applications to use.
- * On some platforms, this will match the "default font"
- * or "system font" if such can be found. This font
- * should not be freed because it was allocated by the
- * system, not the application.
- * <p>
- * Typically, applications which want the default look
- * should simply not set the font on the widgets they
- * create. Widgets are always created with the correct
- * default font for the class of user-interface component
- * they represent.
- * </p>
- *
- * @return a font
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getSystemFont () {
- checkDevice ();
- return systemFont;
-}
-
-/**
- * Returns <code>true</code> if the underlying window system prints out
- * warning messages on the console, and <code>setWarnings</code>
- * had previously been called with <code>true</code>.
- *
- * @return <code>true</code>if warnings are being handled, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean getWarnings () {
- checkDevice ();
- return _getWarnings();
-}
-
-boolean _getWarnings () {
- return warnings;
-}
-
-/**
- * Initializes any internal resources needed by the
- * device.
- * <p>
- * This method is called after <code>create</code>.
- * </p><p>
- * If subclasses reimplement this method, they must
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #create
- */
-protected void init () {
- if (debug) OS.XSynchronize (xDisplay, true);
-
- int[] event_basep = new int[1], error_basep = new int [1];
- if (OS.XRenderQueryExtension (xDisplay, event_basep, error_basep)) {
- int[] major_versionp = new int[1], minor_versionp = new int [1];
- OS.XRenderQueryVersion (xDisplay, major_versionp, minor_versionp);
- useXRender = major_versionp[0] > 0 || (major_versionp[0] == 0 && minor_versionp[0] >= 8);
- }
-
- /* Create the warning and error callbacks */
- Class clazz = getClass ();
- synchronized (clazz) {
- if (XErrorCallback == null) {
- XErrorCallback = new Callback (clazz, "XErrorProc", 2);
- XNullErrorProc = XErrorCallback.getAddress ();
- if (XNullErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- XErrorProc = OS.XSetErrorHandler (XNullErrorProc);
- }
- if (XIOErrorCallback == null) {
- XIOErrorCallback = new Callback (clazz, "XIOErrorProc", 1);
- XNullIOErrorProc = XIOErrorCallback.getAddress ();
- if (XNullIOErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- XIOErrorProc = OS.XSetIOErrorHandler (XNullIOErrorProc);
- }
- }
- xtWarningCallback = new Callback (this, "xtWarningProc", 1);
- xtNullWarningProc = xtWarningCallback.getAddress ();
- if (xtNullWarningProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- xtErrorCallback = new Callback (this, "xtErrorProc", 1);
- xtNullErrorProc = xtErrorCallback.getAddress ();
- if (xtNullErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- xtWarningProc = OS.XtAppSetWarningHandler (xtContext, xtNullWarningProc);
- xtErrorProc = OS.XtAppSetErrorHandler (xtContext, xtNullErrorProc);
-
- /* Only use palettes for <= 8 bpp default visual */
- int xScreenPtr = OS.XDefaultScreenOfDisplay (xDisplay);
- int defaultDepth = OS.XDefaultDepthOfScreen (xScreenPtr);
- if (defaultDepth <= 8) {
- int numColors = 1 << defaultDepth;
- colorRefCount = new int [numColors];
- xcolors = new XColor [numColors];
- }
-
- /*
- * The following colors are listed in the Windows
- * Programmer's Reference as the colors in the default
- * palette.
- */
- COLOR_BLACK = new Color (this, 0,0,0);
- COLOR_DARK_RED = new Color (this, 0x80,0,0);
- COLOR_DARK_GREEN = new Color (this, 0,0x80,0);
- COLOR_DARK_YELLOW = new Color (this, 0x80,0x80,0);
- COLOR_DARK_BLUE = new Color (this, 0,0,0x80);
- COLOR_DARK_MAGENTA = new Color (this, 0x80,0,0x80);
- COLOR_DARK_CYAN = new Color (this, 0,0x80,0x80);
- COLOR_GRAY = new Color (this, 0xC0,0xC0,0xC0);
- COLOR_DARK_GRAY = new Color (this, 0x80,0x80,0x80);
- COLOR_RED = new Color (this, 0xFF,0,0);
- COLOR_GREEN = new Color (this, 0,0xFF,0);
- COLOR_YELLOW = new Color (this, 0xFF,0xFF,0);
- COLOR_BLUE = new Color (this, 0,0,0xFF);
- COLOR_MAGENTA = new Color (this, 0xFF,0,0xFF);
- COLOR_CYAN = new Color (this, 0,0xFF,0xFF);
- COLOR_WHITE = new Color (this, 0xFF,0xFF,0xFF);
-
- int widgetClass = OS.topLevelShellWidgetClass ();
- shellHandle = OS.XtAppCreateShell (null, null, widgetClass, xDisplay, null, 0);
- if (shellHandle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
-
- /* Create the parsing tables */
- byte[] tabBuffer = {(byte) '\t', 0};
- tabPointer = OS.XtMalloc (tabBuffer.length);
- OS.memmove (tabPointer, tabBuffer, tabBuffer.length);
- int tabString = OS.XmStringComponentCreate(OS.XmSTRING_COMPONENT_TAB, 0, null);
- int [] argList = {
- OS.XmNpattern, tabPointer,
- OS.XmNsubstitute, tabString,
- };
- tabMapping = OS.XmParseMappingCreate(argList, argList.length / 2);
- OS.XmStringFree(tabString);
- byte[] crBuffer = {(byte) '\n', 0};
- crPointer = OS.XtMalloc (crBuffer.length);
- OS.memmove (crPointer, crBuffer, crBuffer.length);
- int crString = OS.XmStringComponentCreate(OS.XmSTRING_COMPONENT_SEPARATOR, 0, null);
- argList = new int[] {
- OS.XmNpattern, crPointer,
- OS.XmNsubstitute, crString,
- };
- crMapping = OS.XmParseMappingCreate(argList, argList.length / 2);
- OS.XmStringFree(crString);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Device</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public abstract int internal_new_GC (GCData data);
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Device</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public abstract void internal_dispose_GC (int handle, GCData data);
-
-/**
- * Returns <code>true</code> if the device has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the device.
- * When a device has been disposed, it is an error to
- * invoke any other method using the device.
- *
- * @return <code>true</code> when the device is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- synchronized (Device.class) {
- return xDisplay == 0;
- }
-}
-
-/**
- * Loads the font specified by a file. The font will be
- * present in the list of fonts available to the application.
- *
- * @param path the font file path
- * @return whether the font was successfully loaded
- *
- * @exception SWTException <ul>
- * <li>ERROR_NULL_ARGUMENT - if path is null</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Font
- *
- * @since 3.3
- */
-public boolean loadFont (String path) {
- checkDevice();
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- //TEMPORARY CODE
- /*if (true)*/ return false;
-// int index = path.lastIndexOf ("/");
-// if (index != -1) path = path.substring (0, index);
-// int [] ndirs = new int [1];
-// int dirs = OS.XGetFontPath (xDisplay, ndirs);
-// int [] ptr = new int [1];
-// for (int i = 0; i < ndirs [0]; i++) {
-// OS.memmove (ptr, dirs + (i * 4), 4);
-// int length = OS.strlen (ptr [0]);
-// byte [] buffer = new byte [length];
-// OS.memmove (buffer, ptr [0], length);
-// if (Converter.mbcsToWcs (null, buffer).equals (path)) {
-// OS.XFreeFontPath (dirs);
-// return true;
-// }
-// }
-// int newDirs = OS.XtMalloc ((ndirs [0] + 1) * 4);
-// int[] dirsBuffer = new int [ndirs [0] + 1];
-// OS.memmove (dirsBuffer, dirs, ndirs [0] * 4);
-// byte[] buffer = Converter.wcsToMbcs (null, path, true);
-// int pathPtr = OS.XtMalloc (buffer.length);
-// OS.memmove (pathPtr, buffer, buffer.length);
-// dirsBuffer [dirsBuffer.length - 1] = pathPtr;
-// OS.memmove (newDirs, dirsBuffer, dirsBuffer.length * 4);
-// OS.XSetFontPath (xDisplay, newDirs, dirsBuffer.length);
-// OS.XFreeFontPath (dirs);
-// OS.XFree (newDirs);
-// OS.XFree (pathPtr);
-// return true;
-}
-
-void new_Object (Object object) {
- synchronized (trackingLock) {
- for (int i=0; i<objects.length; i++) {
- if (objects [i] == null) {
- objects [i] = object;
- errors [i] = new Error ();
- return;
- }
- }
- Object [] newObjects = new Object [objects.length + 128];
- System.arraycopy (objects, 0, newObjects, 0, objects.length);
- newObjects [objects.length] = object;
- objects = newObjects;
- Error [] newErrors = new Error [errors.length + 128];
- System.arraycopy (errors, 0, newErrors, 0, errors.length);
- newErrors [errors.length] = new Error ();
- errors = newErrors;
- }
-}
-
-static synchronized void register (Device device) {
- for (int i=0; i<Devices.length; i++) {
- if (Devices [i] == null) {
- Devices [i] = device;
- return;
- }
- }
- Device [] newDevices = new Device [Devices.length + 4];
- System.arraycopy (Devices, 0, newDevices, 0, Devices.length);
- newDevices [Devices.length] = device;
- Devices = newDevices;
-}
-
-/**
- * Releases any internal resources back to the operating
- * system and clears all fields except the device handle.
- * <p>
- * When a device is destroyed, resources that were acquired
- * on behalf of the programmer need to be returned to the
- * operating system. For example, if the device allocated a
- * font to be used as the system font, this font would be
- * freed in <code>release</code>. Also,to assist the garbage
- * collector and minimize the amount of memory that is not
- * reclaimed when the programmer keeps a reference to a
- * disposed device, all fields except the handle are zero'd.
- * The handle is needed by <code>destroy</code>.
- * </p>
- * This method is called before <code>destroy</code>.
- * </p><p>
- * If subclasses reimplement this method, they must
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #dispose
- * @see #destroy
- */
-protected void release () {
- /* Free the parsing tables */
- OS.XtFree(tabPointer);
- OS.XtFree(crPointer);
- OS.XmParseMappingFree(tabMapping);
- OS.XmParseMappingFree(crMapping);
- tabPointer = crPointer = tabMapping = crMapping = 0;
-
- if (shellHandle != 0) OS.XtDestroyWidget (shellHandle);
- shellHandle = 0;
-
- /*
- * Free the palette. Note that this disposes all colors on
- * the display that were allocated using the Color constructor.
- */
- if (xcolors != null) {
- int xScreen = OS.XDefaultScreen (xDisplay);
- int xColormap = OS.XDefaultColormap (xDisplay, xScreen);
- int [] pixel = new int [1];
- for (int i = 0; i < xcolors.length; i++) {
- XColor color = xcolors [i];
- if (color != null) {
- pixel [0] = color.pixel;
- while (colorRefCount [i] > 0) {
- OS.XFreeColors (xDisplay, xColormap, pixel, 1, 0);
- --colorRefCount [i];
- }
- }
- }
- }
- xcolors = null;
- colorRefCount = null;
-
- if (COLOR_BLACK != null) COLOR_BLACK.dispose();
- if (COLOR_DARK_RED != null) COLOR_DARK_RED.dispose();
- if (COLOR_DARK_GREEN != null) COLOR_DARK_GREEN.dispose();
- if (COLOR_DARK_YELLOW != null) COLOR_DARK_YELLOW.dispose();
- if (COLOR_DARK_BLUE != null) COLOR_DARK_BLUE.dispose();
- if (COLOR_DARK_MAGENTA != null) COLOR_DARK_MAGENTA.dispose();
- if (COLOR_DARK_CYAN != null) COLOR_DARK_CYAN.dispose();
- if (COLOR_GRAY != null) COLOR_GRAY.dispose();
- if (COLOR_DARK_GRAY != null) COLOR_DARK_GRAY.dispose();
- if (COLOR_RED != null) COLOR_RED.dispose();
- if (COLOR_GREEN != null) COLOR_GREEN.dispose();
- if (COLOR_YELLOW != null) COLOR_YELLOW.dispose();
- if (COLOR_BLUE != null) COLOR_BLUE.dispose();
- if (COLOR_MAGENTA != null) COLOR_MAGENTA.dispose();
- if (COLOR_CYAN != null) COLOR_CYAN.dispose();
- if (COLOR_WHITE != null) COLOR_WHITE.dispose();
- COLOR_BLACK = COLOR_DARK_RED = COLOR_DARK_GREEN = COLOR_DARK_YELLOW =
- COLOR_DARK_BLUE = COLOR_DARK_MAGENTA = COLOR_DARK_CYAN = COLOR_GRAY = COLOR_DARK_GRAY = COLOR_RED =
- COLOR_GREEN = COLOR_YELLOW = COLOR_BLUE = COLOR_MAGENTA = COLOR_CYAN = COLOR_WHITE = null;
-
- /* Free the Xt error handler */
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- OS.XtAppSetErrorHandler (xtContext, xtErrorProc);
- xtErrorCallback.dispose (); xtErrorCallback = null;
- xtNullErrorProc = xtErrorProc = 0;
-
- /* Free the Xt Warning handler */
- OS.XtAppSetWarningHandler (xtContext, xtWarningProc);
- xtWarningCallback.dispose (); xtWarningCallback = null;
- xtNullWarningProc = xtWarningProc = 0;
-
- int count = 0;
- for (int i = 0; i < Devices.length; i++){
- if (Devices [i] != null) count++;
- }
- if (count == 1) {
- /* Free the X IO error handler */
- OS.XSetIOErrorHandler (XIOErrorProc);
- XIOErrorCallback.dispose (); XIOErrorCallback = null;
- XNullIOErrorProc = XIOErrorProc = 0;
-
- /* Free the X error handler */
- /*
- * Bug in Motif. For some reason, when a pixmap is
- * set into a button or label, despite the fact that
- * the pixmap is cleared from the widget before it
- * is disposed, Motif still references the pixmap
- * and attempts to dispose it in XtDestroyApplicationContext().
- * The fix is to avoid warnings by leaving our handler
- * and settings warnings to false.
- *
- * NOTE: The warning callback is leaked.
- */
- warnings = false;
-// OS.XSetErrorHandler (XErrorProc);
-// XErrorCallback.dispose (); XErrorCallback = null;
-// XNullErrorProc = XErrorProc = 0;
- }
-}
-
-/**
- * If the underlying window system supports printing warning messages
- * to the console, setting warnings to <code>false</code> prevents these
- * messages from being printed. If the argument is <code>true</code> then
- * message printing is not blocked.
- *
- * @param warnings <code>true</code>if warnings should be printed, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setWarnings (boolean warnings) {
- checkDevice ();
- _setWarnings(warnings);
-}
-
-void _setWarnings (boolean warnings) {
- this.warnings = warnings;
-}
-
-static int XErrorProc (int xDisplay, int xErrorEvent) {
- Device device = findDevice (xDisplay);
- if (device != null) {
- if (device.warnings) {
- if (DEBUG || device.debug) {
- new SWTError ().printStackTrace ();
- }
- OS.Call (XErrorProc, xDisplay, xErrorEvent);
- }
- } else {
- if (DEBUG) new SWTError ().printStackTrace ();
- OS.Call (XErrorProc, xDisplay, xErrorEvent);
- }
- return 0;
-}
-
-static int XIOErrorProc (int xDisplay) {
- Device device = findDevice (xDisplay);
- if (device != null) {
- if (DEBUG || device.debug) {
- new SWTError ().printStackTrace ();
- }
- } else {
- if (DEBUG) new SWTError ().printStackTrace ();
- }
- OS.Call (XIOErrorProc, xDisplay, 0);
- return 0;
-}
-
-int xtErrorProc (int message) {
- if (DEBUG || debug) {
- new SWTError ().printStackTrace ();
- }
- OS.Call (xtErrorProc, message, 0);
- return 0;
-}
-
-int xtWarningProc (int message) {
- if (warnings) {
- if (DEBUG || debug) {
- new SWTError ().printStackTrace ();
- }
- OS.Call (xtWarningProc, message, 0);
- }
- return 0;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/DeviceData.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/DeviceData.java
deleted file mode 100755
index ac1c73cf34..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/DeviceData.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-public class DeviceData {
- /*
- * Motif only fields.
- */
- public String display_name;
- public String application_name;
- public String application_class;
-
- /*
- * Debug fields - may not be honoured
- * on some SWT platforms.
- */
- public boolean debug;
- public boolean tracking;
- public Error [] errors;
- public Object [] objects;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Font.java
deleted file mode 100755
index d5b38499bd..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Font.java
+++ /dev/null
@@ -1,536 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage operating system resources that
- * define how text looks when it is displayed. Fonts may be constructed
- * by providing a device and either name, size and style information
- * or a <code>FontData</code> object which encapsulates this data.
- * <p>
- * Application code must explicitly invoke the <code>Font.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see FontData
- * @see <a href="http://www.eclipse.org/swt/snippets/#font">Font snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Font extends Resource {
- /**
- * the handle to the OS font resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
- /**
- * the code page of the font
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- *
- * @since 2.0
- */
- public String codePage;
-
-Font (Device device) {
- super(device);
-}
-
-/**
- * Constructs a new font given a device and font data
- * which describes the desired font's appearance.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param fd the FontData that describes the desired font (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the fd argument is null</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li>
- * </ul>
- */
-public Font (Device device, FontData fd) {
- super(device);
- if (fd == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(new FontData[] {fd});
- init();
-}
-
-/**
- * Constructs a new font given a device and an array
- * of font data which describes the desired font's
- * appearance.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param fds the array of FontData that describes the desired font (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the fds argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the length of fds is zero</li>
- * <li>ERROR_NULL_ARGUMENT - if any fd in the array is null</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li>
- * </ul>
- *
- * @since 2.1
- */
-public Font (Device device, FontData[] fds) {
- super(device);
- if (fds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (fds.length == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<fds.length; i++) {
- if (fds[i] == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- init(fds);
- init();
-}
-
-/**
- * Constructs a new font given a device, a font name,
- * the height of the desired font in points, and a font
- * style.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param name the name of the font (must not be null)
- * @param height the font height in points
- * @param style a bit or combination of NORMAL, BOLD, ITALIC
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the name argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given arguments</li>
- * </ul>
- */
-public Font (Device device, String name, int height, int style) {
- super(device);
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(new FontData[]{new FontData(name, height, style)});
- init();
-}
-
-/*public*/ Font (Device device, String name, float height, int style) {
- super(device);
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(new FontData[]{new FontData(name, height, style)});
- init();
-}
-
-void destroy() {
- if (handle == device.systemFont.handle) return;
- OS.XmFontListFree (handle);
- handle = 0;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Font)) return false;
- Font font = (Font)object;
- return device == font.device && handle == font.handle;
-}
-
-/**
- * Returns the code page for the specified font list.
- *
- * @return the code page for the font list
- */
-static String getCodePage (int xDisplay, int fontList) {
- int[] buffer = new int[1];
- if (!OS.XmFontListInitFontContext(buffer, fontList)) return null;
- int context = buffer[0];
- XFontStruct fontStruct = new XFontStruct();
- int fontListEntry;
- String codePage = null;
- /* Go through each entry in the font list */
- while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer);
- if (buffer[0] == OS.XmFONT_IS_FONT) {
- /* FontList contains a single font */
- OS.memmove(fontStruct,fontPtr,20 * 4);
- int propPtr = fontStruct.properties;
- for (int i = 0; i < fontStruct.n_properties; i++) {
- /* Look through properties for XAFONT */
- int[] prop = new int[2];
- OS.memmove(prop, propPtr, 8);
- if (prop[0] == OS.XA_FONT) {
- /* Found it, prop[1] points to the string */
- int ptr = OS.XmGetAtomName(xDisplay, prop[1]);
- int length = OS.strlen(ptr);
- byte[] nameBuf = new byte[length];
- OS.memmove(nameBuf, ptr, length);
- /* Use the character encoding for the default locale */
- String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase();
- int start = xlfd.lastIndexOf ('-');
- if (start != -1 && start > 0) {
- start = xlfd.lastIndexOf ('-', start - 1);
- if (start != -1) {
- codePage = xlfd.substring (start + 1, xlfd.length ());
- if (codePage.indexOf ("iso") == 0) {
- if (OS.IsLinux) {
- codePage = "ISO-" + codePage.substring (3, codePage.length ());
- }
- if (OS.IsAIX) {
- codePage = "ISO" + codePage.substring (3, codePage.length ());
- }
- if (OS.IsHPUX) {
- start = codePage.lastIndexOf('-');
- if (start != -1) {
- codePage = codePage.substring (0, start) + codePage.substring (start + 1, codePage.length ());
- }
- }
- }
- }
- }
- OS.XtFree(ptr);
- break;
- }
- propPtr += 8;
- }
- }
- else {
- /* FontList contains a fontSet */
-
- /* Get the font set locale */
- int localePtr = OS.XLocaleOfFontSet(fontPtr);
- int length = OS.strlen (localePtr);
- byte [] locale = new byte [length + 1];
- OS.memmove (locale, localePtr, length);
-
- /* Get code page for the font set locale */
- OS.setlocale (OS.LC_CTYPE, locale);
- int codesetPtr = OS.nl_langinfo (OS.CODESET);
- length = OS.strlen (codesetPtr);
- byte [] codeset = new byte [length];
- OS.memmove (codeset, codesetPtr, length);
- codePage = new String(Converter.mbcsToWcs(null, codeset));
-
- /* Reset the locale */
- OS.setlocale (OS.LC_CTYPE, new byte[1]);
- }
- }
- OS.XmFontListFreeFontContext(context);
- return codePage;
-}
-
-/**
- * Returns an array of <code>FontData</code>s representing the receiver.
- * On Windows, only one FontData will be returned per font. On X however,
- * a <code>Font</code> object <em>may</em> be composed of multiple X
- * fonts. To support this case, we return an array of font data objects.
- *
- * @return an array of font data objects describing the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontData[] getFontData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int xDisplay = device.xDisplay;
- /*
- * Create a font context to iterate over each element in the font list.
- */
- int[] buffer = new int[1];
- if (!OS.XmFontListInitFontContext(buffer, handle)) {
- SWT.error (SWT.ERROR_INVALID_FONT);
- }
- int context = buffer[0];
- XFontStruct fontStruct = new XFontStruct();
- int fontListEntry;
- int[] fontStructPtr = new int[1];
- int[] fontNamePtr = new int[1];
- FontData[] data = new FontData[0];
- try {
- /* Go through each entry in the font list */
- while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer);
- if (buffer[0] == OS.XmFONT_IS_FONT) {
- /* FontList contains a single font */
- OS.memmove(fontStruct,fontPtr,20 * 4);
- int propPtr = fontStruct.properties;
- for (int i = 0; i < fontStruct.n_properties; i++) {
- /* Look through properties for XAFONT */
- int[] prop = new int[2];
- OS.memmove(prop, propPtr, 8);
- if (prop[0] == OS.XA_FONT) {
- /* Found it, prop[1] points to the string */
- int ptr = OS.XmGetAtomName(xDisplay, prop[1]);
- int length = OS.strlen(ptr);
- byte[] nameBuf = new byte[length];
- OS.memmove(nameBuf, ptr, length);
- OS.XtFree(ptr);
- /* Use the character encoding for the default locale */
- String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase();
- /* Add the xlfd to the array */
- FontData[] newData = new FontData[data.length + 1];
- System.arraycopy(data, 0, newData, 0, data.length);
- newData[newData.length - 1] = FontData.motif_new(xlfd);
- data = newData;
- break;
- }
- propPtr += 8;
- }
- }
- else {
- /* FontList contains a fontSet */
- int nFonts = OS.XFontsOfFontSet(fontPtr,fontStructPtr,fontNamePtr);
- int [] fontStructs = new int[nFonts];
- OS.memmove(fontStructs,fontStructPtr[0],nFonts * 4);
- for (int i = 0; i < nFonts; i++) { // Go through each fontStruct in the font set.
- OS.memmove(fontStruct,fontStructs[i],20 * 4);
- int propPtr = fontStruct.properties;
- for (int j = 0; j < fontStruct.n_properties; j++) {
- // Look through properties for XAFONT
- int[] prop = new int[2];
- OS.memmove(prop, propPtr, 8);
- if (prop[0] == OS.XA_FONT) {
- /* Found it, prop[1] points to the string */
- int ptr = OS.XmGetAtomName(xDisplay, prop[1]);
- int length = OS.strlen(ptr);
- byte[] nameBuf = new byte[length];
- OS.memmove(nameBuf, ptr, length);
- OS.XFree(ptr);
- String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase();
- /* Add the xlfd to the array */
- FontData[] newData = new FontData[data.length + 1];
- System.arraycopy(data, 0, newData, 0, data.length);
- try {
- newData[newData.length - 1] = FontData.motif_new(xlfd);
- } catch (Exception e) {
- /*
- * Some font servers, for example, xfstt, do not pass
- * reasonable font properties to the client, so we
- * cannot construct a FontData for these. Try to use
- * the font name instead.
- */
- int[] fontName = new int[1];
- OS.memmove(fontName, fontNamePtr [0] + (i * 4), 4);
- ptr = fontName[0];
- if (ptr != 0) {
- length = OS.strlen(ptr);
- nameBuf = new byte[length];
- OS.memmove(nameBuf, ptr, length);
- xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase();
- newData[newData.length - 1] = FontData.motif_new(xlfd);
- }
- }
- data = newData;
- break;
- }
- propPtr += 8;
- }
- }
- }
- }
- if (data.length == 0) SWT.error (SWT.ERROR_INVALID_FONT);
- } catch (Exception e) {
- /*
- * Some font servers, for example, xfstt, do not pass
- * reasonable font properties to the client, so we
- * cannot construct a FontData for these.
- */
- SWT.error (SWT.ERROR_INVALID_FONT);
- } finally {
- OS.XmFontListFreeFontContext(context);
- }
- return data;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return handle;
-}
-
-void init (FontData[] fds) {
- /* Change current locale if needed. Note: only the first font data is used */
- FontData firstFd = fds[0];
- if (firstFd.lang != null) {
- String lang = firstFd.lang;
- String country = firstFd.country;
- String variant = firstFd.variant;
- String osLocale = lang;
- if (country != null) osLocale += "_" + country;
- if (variant != null) osLocale += "." + variant;
- int length = osLocale.length();
- byte [] buffer = new byte[length + 1];
- for (int i=0; i<length; i++) {
- buffer[i] = (byte)osLocale.charAt(i);
- }
- OS.setlocale (OS.LC_CTYPE, buffer);
- }
-
- int fontType = OS.XmFONT_IS_FONTSET;
- /*
- * Bug in HPUX. If the locale is "C" then FontSets do not work
- * properly. The fix is to detect this case and use a Font struct
- * instead.
- */
- if (OS.IsHPUX) {
- int localePtr = OS.setlocale(OS.LC_CTYPE, null);
- int length = OS.strlen(localePtr);
- byte[] buffer = new byte[length];
- OS.memmove(buffer, localePtr, length);
- if ("C".equals(new String(Converter.mbcsToWcs(null, buffer)))) {
- fontType = OS.XmFONT_IS_FONT;
- }
- }
-
- /* Generate desire font name */
- Point dpi = null;
- if (device.setDPI) dpi = device.getDPI();
- StringBuffer stringBuffer = new StringBuffer();
- for (int i = 0; i < fds.length; i++) {
- if (i != 0) stringBuffer.append(',');
- FontData fd = fds[i];
- int hRes = fd.horizontalResolution, vRes = fd.verticalResolution;
- if (dpi != null) {
- fd.horizontalResolution = dpi.x;
- fd.verticalResolution = dpi.y;
- }
- stringBuffer.append(fd.getXlfd());
- fd.horizontalResolution = hRes;
- fd.verticalResolution = vRes;
- }
-
- /* Append simplified font name */
- FontData newFd = new FontData();
- newFd.points = firstFd.points;
- /*
- * Bug in Motif. In Japanese AIX only, in some cases loading a bold Japanese
- * font takes a very long time (10 minutes) when there are no Japanese bold
- * fonts available. The fix is to wildcard the field weight.
- */
- if (fontType == OS.XmFONT_IS_FONTSET) {
- if (OS.IsAIX && OS.IsDBLocale) {
- stringBuffer.append(',');
- stringBuffer.append(newFd.getXlfd());
- } else {
- newFd.weight = firstFd.weight;
- newFd.slant = firstFd.slant;
- stringBuffer.append(',');
- stringBuffer.append(newFd.getXlfd());
- newFd.weight = null;
- newFd.slant = null;
- stringBuffer.append(',');
- stringBuffer.append(newFd.getXlfd());
- }
- }
-
- /* Load font list entry */
- boolean warnings = device._getWarnings ();
- device._setWarnings (false);
- byte[] buffer = Converter.wcsToMbcs(null, stringBuffer.toString() , true);
- int fontListEntry = OS.XmFontListEntryLoad(device.xDisplay, buffer, fontType, OS.XmFONTLIST_DEFAULT_TAG);
- device._setWarnings (warnings);
- if (fontListEntry != 0) {
- handle = OS.XmFontListAppendEntry(0, fontListEntry);
- OS.XmFontListEntryFree(new int[]{fontListEntry});
- int codesetPtr = OS.nl_langinfo(OS.CODESET);
- int length = OS.strlen(codesetPtr);
- buffer = new byte[length];
- OS.memmove(buffer, codesetPtr, length);
- codePage = new String(Converter.mbcsToWcs(null, buffer));
- } else {
- Font systemFont = device.systemFont;
- handle = systemFont.handle;
- codePage = systemFont.codePage;
- }
-
- /* Reset current locale if needed */
- if (firstFd.lang != null) OS.setlocale(OS.LC_CTYPE, new byte[0]);
-
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
-}
-
-/**
- * Returns <code>true</code> if the font has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the font.
- * When a font has been disposed, it is an error to
- * invoke any other method using the font.
- *
- * @return <code>true</code> when the font is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-public static Font motif_new(Device device, int handle) {
- Font font = new Font(device);
- font.handle = handle;
- font.codePage = getCodePage(device.xDisplay, handle);
- return font;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Font {*DISPOSED*}";
- return "Font {" + handle + "}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java
deleted file mode 100755
index 6f50eb10b8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java
+++ /dev/null
@@ -1,669 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class describe operating system fonts.
- * <p>
- * For platform-independent behaviour, use the get and set methods
- * corresponding to the following properties:
- * <dl>
- * <dt>height</dt><dd>the height of the font in points</dd>
- * <dt>name</dt><dd>the face name of the font, which may include the foundry</dd>
- * <dt>style</dt><dd>A bitwise combination of NORMAL, ITALIC and BOLD</dd>
- * </dl>
- * If extra, platform-dependent functionality is required:
- * <ul>
- * <li>On <em>Windows</em>, the data member of the <code>FontData</code>
- * corresponds to a Windows <code>LOGFONT</code> structure whose fields
- * may be retrieved and modified.</li>
- * <li>On <em>X</em>, the fields of the <code>FontData</code> correspond
- * to the entries in the font's XLFD name and may be retrieved and modified.
- * </ul>
- * Application code does <em>not</em> need to explicitly release the
- * resources managed by each instance when those instances are no longer
- * required, and thus no <code>dispose()</code> method is provided.
- *
- * @see Font
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class FontData {
- /**
- * The company that produced the font
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public String foundry;
- /**
- * The common name of the font
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public String fontFamily;
- /**
- * The weight ("medium", "bold")
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public String weight;
- /**
- * The slant ("o" for oblique, "i" for italic)
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public String slant;
- /**
- * The set width of the font
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public String setWidth;
- /**
- * Additional font styles
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public String addStyle;
- /**
- * The height of the font in pixels
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int pixels;
- /**
- * The height of the font in tenths of a point
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int points;
- /**
- * The horizontal screen resolution for which the font was designed
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int horizontalResolution;
- /**
- * The vertical screen resolution for which the font was designed
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int verticalResolution;
- /**
- * The font spacing ("m" for monospace, "p" for proportional)
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public String spacing;
- /**
- * The average character width for the font
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int averageWidth;
- /**
- * The ISO character set registry
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public String characterSetRegistry;
- /**
- * The ISO character set name
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public String characterSetName;
-
- /**
- * The locales of the font
- */
- String lang, country, variant;
-/**
- * Constructs a new uninitialized font data.
- */
-public FontData () {
-}
-/**
- * Constructs a new FontData given a string representation
- * in the form generated by the <code>FontData.toString</code>
- * method.
- * <p>
- * Note that the representation varies between platforms,
- * and a FontData can only be created from a string that was
- * generated on the same platform.
- * </p>
- *
- * @param string the string representation of a <code>FontData</code> (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument does not represent a valid description</li>
- * </ul>
- *
- * @see #toString
- */
-public FontData(String string) {
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int start = 0;
- int end = string.indexOf('|');
- if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- String version1 = string.substring(start, end);
- try {
- if (Integer.parseInt(version1) != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- String name = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- float height = 0;
- try {
- height = Float.parseFloat(string.substring(start, end));
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int style = 0;
- try {
- style = Integer.parseInt(string.substring(start, end));
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) {
- setName(name);
- setHeight(height);
- setStyle(style);
- return;
- }
- String platform = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) {
- setName(name);
- setHeight(height);
- setStyle(style);
- return;
- }
- String version2 = string.substring(start, end);
-
- if (platform.equals("MOTIF") && version2.equals("1")) {
- start = end + 1;
- end = string.length();
- if (end == -1) {
- setName(name);
- setHeight(height);
- setStyle(style);
- return;
- }
- String xlfd = string.substring(start, end);
- setXlfd(xlfd);
- return;
- }
- setName(name);
- setHeight(height);
- setStyle(style);
-}
-/**
- * Constructs a new font data given a font name,
- * the height of the desired font in points,
- * and a font style.
- *
- * @param name the name of the font (must not be null)
- * @param height the font height in points
- * @param style a bit or combination of NORMAL, BOLD, ITALIC
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - when the font name is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- */
-public FontData (String name, int height, int style) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int dash = name.indexOf('-');
- if (dash != -1) {
- foundry = name.substring(0, dash);
- fontFamily = name.substring(dash + 1);
- } else {
- fontFamily = name;
- }
- points = height * 10;
- weight = (style & SWT.BOLD) != 0 ? "bold" : "medium";
- slant = (style & SWT.ITALIC) != 0 ? "i" : "r";
-}
-/*public*/ FontData (String name, float height, int style) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int dash = name.indexOf('-');
- if (dash != -1) {
- foundry = name.substring(0, dash);
- fontFamily = name.substring(dash + 1);
- } else {
- fontFamily = name;
- }
- points = (int)(height * 10);
- weight = (style & SWT.BOLD) != 0 ? "bold" : "medium";
- slant = (style & SWT.ITALIC) != 0 ? "i" : "r";
-}
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- return (object == this) || ((object instanceof FontData) &&
- getXlfd().equals(((FontData)object).getXlfd()));
-}
-/**
- * Returns the height of the receiver in points.
- *
- * @return the height of this FontData
- *
- * @see #setHeight(int)
- */
-public int getHeight() {
- return points / 10;
-}
-/*public*/ float getHeightF() {
- return points / 10f;
-}
-/**
- * Returns the locale of the receiver.
- * <p>
- * The locale determines which platform character set this
- * font is going to use. Widgets and graphics operations that
- * use this font will convert UNICODE strings to the platform
- * character set of the specified locale.
- * </p>
- * <p>
- * On platforms where there are multiple character sets for a
- * given language/country locale, the variant portion of the
- * locale will determine the character set.
- * </p>
- *
- * @return the <code>String</code> representing a Locale object
- * @since 3.0
- */
-public String getLocale () {
- StringBuffer buffer = new StringBuffer ();
- char sep = '_';
- if (lang != null) {
- buffer.append (lang);
- buffer.append (sep);
- }
- if (country != null) {
- buffer.append (country);
- buffer.append (sep);
- }
- if (variant != null) {
- buffer.append (variant);
- }
-
- String result = buffer.toString ();
- int length = result.length ();
- if (length > 0) {
- if (result.charAt (length - 1) == sep) {
- result = result.substring (0, length - 1);
- }
- }
- return result;
-}
-/**
- * Returns the name of the receiver.
- * On platforms that support font foundries, the return value will
- * be the foundry followed by a dash ("-") followed by the face name.
- *
- * @return the name of this <code>FontData</code>
- *
- * @see #setName
- */
-public String getName() {
- StringBuffer buffer = new StringBuffer();
- if (foundry != null) {
- buffer.append(foundry);
- buffer.append("-");
- }
- if (fontFamily != null) buffer.append(fontFamily);
- return buffer.toString();
-}
-/**
- * Returns the style of the receiver which is a bitwise OR of
- * one or more of the <code>SWT</code> constants NORMAL, BOLD
- * and ITALIC.
- *
- * @return the style of this <code>FontData</code>
- *
- * @see #setStyle
- */
-public int getStyle() {
- int style = 0;
- if (weight != null && weight.equals("bold")) style |= SWT.BOLD;
- if (slant != null && slant.equals("i")) style |= SWT.ITALIC;
- return style;
-}
-String getXlfd() {
- String s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14;
- s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = s9 = s10 = s11 = s12 = s13 = s14 = "*";
-
- if (foundry != null) s1 = foundry;
- if (fontFamily != null) s2 = fontFamily;
- if (weight != null) s3 = weight;
- if (slant != null) s4 = slant;
- if (setWidth != null) s5 = setWidth;
- if (addStyle != null) s6 = addStyle;
- if (pixels != 0) s7 = Integer.toString(pixels);
- if (points != 0) s8 = Integer.toString(points);
- if (horizontalResolution != 0) s9 = Integer.toString(horizontalResolution);
- if (verticalResolution != 0) s10 = Integer.toString(verticalResolution);
- if (spacing != null) s11 = spacing;
- if (averageWidth != 0) s12 = Integer.toString(averageWidth);
- if (characterSetRegistry != null) s13 = characterSetRegistry;
- if (characterSetName != null) s14 = characterSetName;
-
- return "-" + s1+ "-" + s2 + "-" + s3 + "-" + s4 + "-" + s5 + "-" + s6 + "-" + s7 + "-" + s8 + "-"
- + s9 + "-" + s10 + "-" + s11 + "-" + s12 + "-" + s13 + "-" + s14;
-}
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return getXlfd().hashCode();
-}
-public static FontData motif_new(String xlfd) {
- FontData fontData = new FontData();
- fontData.setXlfd(xlfd);
- return fontData;
-}
-/**
- * Sets the height of the receiver. The parameter is
- * specified in terms of points, where a point is one
- * seventy-second of an inch.
- *
- * @param height the height of the <code>FontData</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- *
- * @see #getHeight
- */
-public void setHeight(int height) {
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- points = height * 10;
-}
-/*public*/ void setHeight(float height) {
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- points = (int)(height * 10);
-}
-/**
- * Sets the name of the receiver.
- * <p>
- * Some platforms support font foundries. On these platforms, the name
- * of the font specified in setName() may have one of the following forms:
- * <ol>
- * <li>a face name (for example, "courier")</li>
- * <li>a foundry followed by a dash ("-") followed by a face name (for example, "adobe-courier")</li>
- * </ol>
- * In either case, the name returned from getName() will include the
- * foundry.
- * </p>
- * <p>
- * On platforms that do not support font foundries, only the face name
- * (for example, "courier") is used in <code>setName()</code> and
- * <code>getName()</code>.
- * </p>
- *
- * @param name the name of the font data (must not be null)
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - when the font name is null</li>
- * </ul>
- *
- * @see #getName
- */
-public void setName(String name) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int dash = name.indexOf('-');
- if (dash != -1) {
- foundry = name.substring(0, dash);
- fontFamily = name.substring(dash + 1);
- } else {
- fontFamily = name;
- }
-}
-/**
- * Sets the locale of the receiver.
- * <p>
- * The locale determines which platform character set this
- * font is going to use. Widgets and graphics operations that
- * use this font will convert UNICODE strings to the platform
- * character set of the specified locale.
- * </p>
- * <p>
- * On platforms where there are multiple character sets for a
- * given language/country locale, the variant portion of the
- * locale will determine the character set.
- * </p>
- *
- * @param locale the <code>String</code> representing a Locale object
- * @see java.util.Locale#toString
- */
-public void setLocale(String locale) {
- lang = country = variant = null;
- if (locale != null) {
- char sep = '_';
- int length = locale.length();
- int firstSep, secondSep;
-
- firstSep = locale.indexOf(sep);
- if (firstSep == -1) {
- firstSep = secondSep = length;
- } else {
- secondSep = locale.indexOf(sep, firstSep + 1);
- if (secondSep == -1) secondSep = length;
- }
- if (firstSep > 0) lang = locale.substring(0, firstSep);
- if (secondSep > firstSep + 1) country = locale.substring(firstSep + 1, secondSep);
- if (length > secondSep + 1) variant = locale.substring(secondSep + 1);
- }
-}
-/**
- * Sets the style of the receiver to the argument which must
- * be a bitwise OR of one or more of the <code>SWT</code>
- * constants NORMAL, BOLD and ITALIC. All other style bits are
- * ignored.
- *
- * @param style the new style for this <code>FontData</code>
- *
- * @see #getStyle
- */
-public void setStyle(int style) {
- weight = (style & SWT.BOLD) != 0 ? "bold" : "medium";
- slant = (style & SWT.ITALIC) != 0 ? "i" : "r";
- averageWidth = 0;
-}
-void setXlfd(String xlfd) {
- int start, stop;
- start = 1;
- stop = xlfd.indexOf ("-", start);
- foundry = xlfd.substring(start, stop);
- if (foundry.equals("*")) foundry = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- fontFamily = xlfd.substring(start, stop);
- if (fontFamily.equals("*")) fontFamily = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- weight = xlfd.substring(start, stop);
- if (weight.equals("*")) weight = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- slant = xlfd.substring(start, stop);
- if (slant.equals("*")) slant = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- setWidth = xlfd.substring(start, stop);
- if (setWidth.equals("*")) setWidth = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- addStyle = xlfd.substring(start, stop);
- if (addStyle.equals("*")) addStyle = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- String s = xlfd.substring(start, stop);
- if (!s.equals("") && !s.equals("*"))
- pixels = Integer.parseInt(s);
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- s = xlfd.substring(start, stop);
- if (!s.equals("") && !s.equals("*"))
- points = Integer.parseInt(s);
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- s = xlfd.substring(start, stop);
- if (!s.equals("") && !s.equals("*"))
- horizontalResolution = Integer.parseInt(s);
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- s = xlfd.substring(start, stop);
- if (!s.equals("") && !s.equals("*"))
- verticalResolution = Integer.parseInt(s);
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- spacing = xlfd.substring(start, stop);
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- s = xlfd.substring(start, stop);
- if (!s.equals("") && !s.equals("*")) {
- if (s.startsWith ("~")) {
- s = "-" + s.substring(1);
- }
- averageWidth = Integer.parseInt(s);
- }
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- characterSetRegistry = xlfd.substring(start, stop);
- if (characterSetRegistry.equals("*")) characterSetRegistry = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- characterSetName = xlfd.substring(start);
- if (characterSetName.equals("*")) characterSetName = null;
-}
-/**
- * Returns a string representation of the receiver which is suitable
- * for constructing an equivalent instance using the
- * <code>FontData(String)</code> constructor.
- *
- * @return a string representation of the FontData
- *
- * @see FontData
- */
-public String toString() {
- return "1|" + fontFamily + "|" + getHeightF() + "|" + getStyle() + "|" +
- "MOTIF|1|" + getXlfd();
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontMetrics.java
deleted file mode 100755
index 83b12e5bcb..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontMetrics.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-/**
- * Instances of this class provide measurement information
- * about fonts including ascent, descent, height, leading
- * space between rows, and average character width.
- * <code>FontMetrics</code> are obtained from <code>GC</code>s
- * using the <code>getFontMetrics()</code> method.
- *
- * @see GC#getFontMetrics
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class FontMetrics {
- int ascent, descent, averageCharWidth, leading, height;
-FontMetrics() {
-}
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof FontMetrics)) return false;
- FontMetrics metrics = (FontMetrics)object;
- return ascent == metrics.ascent && descent == metrics.descent &&
- averageCharWidth == metrics.averageCharWidth && leading == metrics.leading &&
- height == metrics.height;
-}
-/**
- * Returns the ascent of the font described by the receiver. A
- * font's <em>ascent</em> is the distance from the baseline to the
- * top of actual characters, not including any of the leading area,
- * measured in pixels.
- *
- * @return the ascent of the font
- */
-public int getAscent() {
- return ascent;
-}
-/**
- * Returns the average character width, measured in pixels,
- * of the font described by the receiver.
- *
- * @return the average character width of the font
- */
-public int getAverageCharWidth() {
- return averageCharWidth;
-}
-/**
- * Returns the descent of the font described by the receiver. A
- * font's <em>descent</em> is the distance from the baseline to the
- * bottom of actual characters, not including any of the leading area,
- * measured in pixels.
- *
- * @return the descent of the font
- */
-public int getDescent() {
- return descent;
-}
-/**
- * Returns the height of the font described by the receiver,
- * measured in pixels. A font's <em>height</em> is the sum of
- * its ascent, descent and leading area.
- *
- * @return the height of the font
- *
- * @see #getAscent
- * @see #getDescent
- * @see #getLeading
- */
-public int getHeight() {
- return height;
-}
-/**
- * Returns the leading area of the font described by the
- * receiver. A font's <em>leading area</em> is the space
- * above its ascent which may include accents or other marks.
- *
- * @return the leading space of the font
- */
-public int getLeading() {
- return leading;
-}
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode() {
- return ascent ^ descent ^ averageCharWidth ^ leading ^ height;
-}
-public static FontMetrics motif_new(int ascent, int descent, int averageCharWidth, int leading, int height) {
- FontMetrics fontMetrics = new FontMetrics();
- fontMetrics.ascent = ascent;
- fontMetrics.descent = descent;
- fontMetrics.averageCharWidth = averageCharWidth;
- fontMetrics.leading = leading;
- fontMetrics.height = height;
- return fontMetrics;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java
deleted file mode 100755
index e5e3c8ca44..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java
+++ /dev/null
@@ -1,4568 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.cairo.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
-/**
- * Class <code>GC</code> is where all of the drawing capabilities that are
- * supported by SWT are located. Instances are used to draw on either an
- * <code>Image</code>, a <code>Control</code>, or directly on a <code>Display</code>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * </dl>
- *
- * <p>
- * The SWT drawing coordinate system is the two-dimensional space with the origin
- * (0,0) at the top left corner of the drawing area and with (x,y) values increasing
- * to the right and downward respectively.
- * </p>
- *
- * <p>
- * The result of drawing on an image that was created with an indexed
- * palette using a color that is not in the palette is platform specific.
- * Some platforms will match to the nearest color while other will draw
- * the color itself. This happens because the allocated image might use
- * a direct palette on platforms that do not support indexed palette.
- * </p>
- *
- * <p>
- * Application code must explicitly invoke the <code>GC.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required. This is <em>particularly</em>
- * important on Windows95 and Windows98 where the operating system has a limited
- * number of device contexts available.
- * </p>
- *
- * <p>
- * Note: Only one of LEFT_TO_RIGHT and RIGHT_TO_LEFT may be specified.
- * </p>
- *
- * @see org.eclipse.swt.events.PaintEvent
- * @see <a href="http://www.eclipse.org/swt/snippets/#gc">GC snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class GC extends Resource {
- /**
- * the handle to the OS device context
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
- Drawable drawable;
- GCData data;
-
- final static int FOREGROUND = 1 << 0;
- final static int BACKGROUND = 1 << 1;
- final static int FONT = 1 << 2;
- final static int LINE_STYLE = 1 << 3;
- final static int LINE_CAP = 1 << 4;
- final static int LINE_JOIN = 1 << 5;
- final static int LINE_WIDTH = 1 << 6;
- final static int LINE_MITERLIMIT = 1 << 7;
- final static int BACKGROUND_BG = 1 << 8;
- final static int FOREGROUND_RGB = 1 << 9;
- final static int BACKGROUND_RGB = 1 << 10;
- final static int DRAW_OFFSET = 1 << 11;
- final static int DRAW = FOREGROUND | LINE_WIDTH | LINE_STYLE | LINE_CAP | LINE_JOIN | LINE_MITERLIMIT | DRAW_OFFSET;
- final static int FILL = BACKGROUND;
-
- static final float[] LINE_DOT = new float[]{1, 1};
- static final float[] LINE_DASH = new float[]{3, 1};
- static final float[] LINE_DASHDOT = new float[]{3, 1, 1, 1};
- static final float[] LINE_DASHDOTDOT = new float[]{3, 1, 1, 1, 1, 1};
- static final float[] LINE_DOT_ZERO = new float[]{3, 3};
- static final float[] LINE_DASH_ZERO = new float[]{18, 6};
- static final float[] LINE_DASHDOT_ZERO = new float[]{9, 6, 3, 6};
- static final float[] LINE_DASHDOTDOT_ZERO = new float[]{9, 3, 3, 3, 3, 3};
-
-GC() {
-}
-/**
- * Constructs a new instance of this class which has been
- * configured to draw on the specified drawable. Sets the
- * foreground color, background color and font in the GC
- * to match those in the drawable.
- * <p>
- * You must dispose the graphics context when it is no longer required.
- * </p>
- * @param drawable the drawable to draw on
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li>
- * <li>ERROR_NULL_ARGUMENT - if there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT
- * - if the drawable is an image that is not a bitmap or an icon
- * - if the drawable is an image or printer that is already selected
- * into another graphics context</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li>
- * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li>
- * </ul>
- */
-public GC(Drawable drawable) {
- this(drawable, 0);
-}
-/**
- * Constructs a new instance of this class which has been
- * configured to draw on the specified drawable. Sets the
- * foreground color, background color and font in the GC
- * to match those in the drawable.
- * <p>
- * You must dispose the graphics context when it is no longer required.
- * </p>
- *
- * @param drawable the drawable to draw on
- * @param style the style of GC to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li>
- * <li>ERROR_NULL_ARGUMENT - if there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT
- * - if the drawable is an image that is not a bitmap or an icon
- * - if the drawable is an image or printer that is already selected
- * into another graphics context</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li>
- * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public GC(Drawable drawable, int style) {
- if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- GCData data = new GCData();
- data.style = checkStyle(style);
- int xGC = drawable.internal_new_GC(data);
- Device device = data.device;
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = data.device = device;
- init(drawable, data, xGC);
- init();
-}
-static void addCairoString(int cairo, String string, float x, float y, Font font) {
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
- GC.setCairoFont(cairo, font);
- cairo_font_extents_t extents = new cairo_font_extents_t();
- Cairo.cairo_font_extents(cairo, extents);
- double baseline = y + extents.ascent;
- Cairo.cairo_move_to(cairo, x, baseline);
- Cairo.cairo_text_path(cairo, buffer);
-}
-static int checkStyle (int style) {
- if ((style & SWT.LEFT_TO_RIGHT) != 0) style &= ~SWT.RIGHT_TO_LEFT;
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-void checkGC (int mask) {
- int state = data.state;
- if ((state & mask) == mask) return;
- state = (state ^ mask) & mask;
- data.state |= mask;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- if ((state & (BACKGROUND | FOREGROUND)) != 0) {
- XColor color;
- Pattern pattern;
- if ((state & FOREGROUND) != 0) {
- color = data.foreground;
- if ((data.state & FOREGROUND_RGB) == 0) {
- OS.XQueryColor (data.display, data.colormap, color);
- data.state |= FOREGROUND_RGB;
- }
- pattern = data.foregroundPattern;
- data.state &= ~BACKGROUND;
- } else {
- color = data.background;
- if ((data.state & BACKGROUND_RGB) == 0) {
- OS.XQueryColor (data.display, data.colormap, color);
- data.state |= BACKGROUND_RGB;
- }
- pattern = data.backgroundPattern;
- data.state &= ~FOREGROUND;
- }
- if (pattern != null) {
- Cairo.cairo_set_source(cairo, pattern.handle);
- } else {
- Cairo.cairo_set_source_rgba(cairo, (color.red & 0xFFFF) / (float)0xFFFF, (color.green & 0xFFFF) / (float)0xFFFF, (color.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF);
- }
- }
- if ((state & FONT) != 0) {
- setCairoFont(cairo, data.font);
- }
- if ((state & LINE_CAP) != 0) {
- int cap_style = 0;
- switch (data.lineCap) {
- case SWT.CAP_ROUND: cap_style = Cairo.CAIRO_LINE_CAP_ROUND; break;
- case SWT.CAP_FLAT: cap_style = Cairo.CAIRO_LINE_CAP_BUTT; break;
- case SWT.CAP_SQUARE: cap_style = Cairo.CAIRO_LINE_CAP_SQUARE; break;
- }
- Cairo.cairo_set_line_cap(cairo, cap_style);
- }
- if ((state & LINE_JOIN) != 0) {
- int join_style = 0;
- switch (data.lineJoin) {
- case SWT.JOIN_MITER: join_style = Cairo.CAIRO_LINE_JOIN_MITER; break;
- case SWT.JOIN_ROUND: join_style = Cairo.CAIRO_LINE_JOIN_ROUND; break;
- case SWT.JOIN_BEVEL: join_style = Cairo.CAIRO_LINE_JOIN_BEVEL; break;
- }
- Cairo.cairo_set_line_join(cairo, join_style);
- }
- if ((state & LINE_WIDTH) != 0) {
- Cairo.cairo_set_line_width(cairo, data.lineWidth == 0 ? 1 : data.lineWidth);
- switch (data.lineStyle) {
- case SWT.LINE_DOT:
- case SWT.LINE_DASH:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- state |= LINE_STYLE;
- }
- }
- if ((state & LINE_STYLE) != 0) {
- float dashesOffset = 0;
- float[] dashes = null;
- float width = data.lineWidth;
- switch (data.lineStyle) {
- case SWT.LINE_SOLID: break;
- case SWT.LINE_DASH: dashes = width != 0 ? LINE_DASH : LINE_DASH_ZERO; break;
- case SWT.LINE_DOT: dashes = width != 0 ? LINE_DOT : LINE_DOT_ZERO; break;
- case SWT.LINE_DASHDOT: dashes = width != 0 ? LINE_DASHDOT : LINE_DASHDOT_ZERO; break;
- case SWT.LINE_DASHDOTDOT: dashes = width != 0 ? LINE_DASHDOTDOT : LINE_DASHDOTDOT_ZERO; break;
- case SWT.LINE_CUSTOM: dashes = data.lineDashes; break;
- }
- if (dashes != null) {
- dashesOffset = data.lineDashesOffset;
- double[] cairoDashes = new double[dashes.length];
- for (int i = 0; i < cairoDashes.length; i++) {
- cairoDashes[i] = width == 0 || data.lineStyle == SWT.LINE_CUSTOM ? dashes[i] : dashes[i] * width;
- }
- Cairo.cairo_set_dash(cairo, cairoDashes, cairoDashes.length, dashesOffset);
- } else {
- Cairo.cairo_set_dash(cairo, null, 0, 0);
- }
- }
- if ((state & LINE_MITERLIMIT) != 0) {
- Cairo.cairo_set_miter_limit(cairo, data.lineMiterLimit);
- }
- if ((state & DRAW_OFFSET) != 0) {
- data.cairoXoffset = data.cairoYoffset = 0;
- double[] matrix = new double[6];
- Cairo.cairo_get_matrix(cairo, matrix);
- double[] dx = new double[]{1};
- double[] dy = new double[]{1};
- Cairo.cairo_user_to_device_distance(cairo, dx, dy);
- double scaling = dx[0];
- if (scaling < 0) scaling = -scaling;
- double strokeWidth = data.lineWidth * scaling;
- if (strokeWidth == 0 || ((int)strokeWidth % 2) == 1) {
- data.cairoXoffset = 0.5 / scaling;
- }
- scaling = dy[0];
- if (scaling < 0) scaling = -scaling;
- strokeWidth = data.lineWidth * scaling;
- if (strokeWidth == 0 || ((int)strokeWidth % 2) == 1) {
- data.cairoYoffset = 0.5 / scaling;
- }
- }
- return;
- }
- int xDisplay = data.display;
- if ((state & (BACKGROUND | FOREGROUND)) != 0) {
- XColor foreground;
- if ((state & FOREGROUND) != 0) {
- foreground = data.foreground;
- data.state &= ~BACKGROUND;
- } else {
- foreground = data.background;
- data.state &= ~FOREGROUND;
- }
- OS.XSetForeground (xDisplay, handle, foreground.pixel);
- }
- if ((state & BACKGROUND_BG) != 0) {
- XColor background = data.background;
- OS.XSetBackground(xDisplay, handle, background.pixel);
- }
- if ((state & (LINE_CAP | LINE_JOIN | LINE_STYLE | LINE_WIDTH)) != 0) {
- int cap_style = 0;
- int join_style = 0;
- int width = (int)data.lineWidth;
- int line_style = 0;
- float[] dashes = null;
- switch (data.lineCap) {
- case SWT.CAP_ROUND: cap_style = OS.CapRound; break;
- case SWT.CAP_FLAT: cap_style = OS.CapButt; break;
- case SWT.CAP_SQUARE: cap_style = OS.CapProjecting; break;
- }
- switch (data.lineJoin) {
- case SWT.JOIN_ROUND: join_style = OS.JoinRound; break;
- case SWT.JOIN_MITER: join_style = OS.JoinMiter; break;
- case SWT.JOIN_BEVEL: join_style = OS.JoinBevel; break;
- }
- switch (data.lineStyle) {
- case SWT.LINE_SOLID: break;
- case SWT.LINE_DASH: dashes = width != 0 ? LINE_DASH : LINE_DASH_ZERO; break;
- case SWT.LINE_DOT: dashes = width != 0 ? LINE_DOT : LINE_DOT_ZERO; break;
- case SWT.LINE_DASHDOT: dashes = width != 0 ? LINE_DASHDOT : LINE_DASHDOT_ZERO; break;
- case SWT.LINE_DASHDOTDOT: dashes = width != 0 ? LINE_DASHDOTDOT : LINE_DASHDOTDOT_ZERO; break;
- case SWT.LINE_CUSTOM: dashes = data.lineDashes; break;
- }
- if (dashes != null) {
- if ((state & LINE_STYLE) != 0) {
- byte[] dash_list = new byte[dashes.length];
- for (int i = 0; i < dash_list.length; i++) {
- dash_list[i] = (byte)(width == 0 || data.lineStyle == SWT.LINE_CUSTOM ? dashes[i] : dashes[i] * width);
- }
- OS.XSetDashes(xDisplay, handle, 0, dash_list, dash_list.length);
- }
- line_style = OS.LineOnOffDash;
- } else {
- line_style = OS.LineSolid;
- }
- OS.XSetLineAttributes(xDisplay, handle, width, line_style, cap_style, join_style);
- }
-}
-int convertRgn(int rgn, double[] matrix) {
- int /*long*/ newRgn = OS.XCreateRegion();
- //TODO - get rectangles from region instead of clip box
- XRectangle rect = new XRectangle();
- OS.XClipBox(rgn, rect);
- short[] pointArray = new short[8];
- double[] x = new double[1], y = new double[1];
- x[0] = rect.x;
- y[0] = rect.y;
- Cairo.cairo_matrix_transform_point(matrix, x, y);
- pointArray[0] = (short)x[0];
- pointArray[1] = (short)y[0];
- x[0] = rect.x + rect.width;
- y[0] = rect.y;
- Cairo.cairo_matrix_transform_point(matrix, x, y);
- pointArray[2] = (short)Math.round(x[0]);
- pointArray[3] = (short)y[0];
- x[0] = rect.x + rect.width;
- y[0] = rect.y + rect.height;
- Cairo.cairo_matrix_transform_point(matrix, x, y);
- pointArray[4] = (short)Math.round(x[0]);
- pointArray[5] = (short)Math.round(y[0]);
- x[0] = rect.x;
- y[0] = rect.y + rect.height;
- Cairo.cairo_matrix_transform_point(matrix, x, y);
- pointArray[6] = (short)x[0];
- pointArray[7] = (short)Math.round(y[0]);
- int /*long*/ polyRgn = OS.XPolygonRegion(pointArray, pointArray.length / 2, OS.EvenOddRule);
- OS.XUnionRegion(newRgn, polyRgn, newRgn);
- OS.XDestroyRegion(polyRgn);
- return newRgn;
-}
-/**
- * Copies a rectangular area of the receiver at the source
- * position onto the receiver at the destination position.
- *
- * @param srcX the x coordinate in the receiver of the area to be copied
- * @param srcY the y coordinate in the receiver of the area to be copied
- * @param width the width of the area to copy
- * @param height the height of the area to copy
- * @param destX the x coordinate in the receiver of the area to copy to
- * @param destY the y coordinate in the receiver of the area to copy to
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void copyArea(int x, int y, int width, int height, int destX, int destY) {
- copyArea(x, y, width, height, destX, destY, true);
-}
-/**
- * Copies a rectangular area of the receiver at the source
- * position onto the receiver at the destination position.
- *
- * @param srcX the x coordinate in the receiver of the area to be copied
- * @param srcY the y coordinate in the receiver of the area to be copied
- * @param width the width of the area to copy
- * @param height the height of the area to copy
- * @param destX the x coordinate in the receiver of the area to copy to
- * @param destY the y coordinate in the receiver of the area to copy to
- * @param paint if <code>true</code> paint events will be generated for old and obscured areas
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void copyArea(int x, int y, int width, int height, int destX, int destY, boolean paint) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width <= 0 || height <= 0) return;
- int deltaX = destX - x, deltaY = destY - y;
- if (deltaX == 0 && deltaY == 0) return;
- int xDisplay = data.display;
- int xDrawable = data.drawable;
- if (data.backgroundImage != null && paint) {
- OS.XClearArea (xDisplay, xDrawable, x, y, width, height, true);
- OS.XClearArea (xDisplay, xDrawable, destX, destY, width, height, true);
- return;
- }
- if (data.image == null && paint) OS.XSetGraphicsExposures (xDisplay, handle, true);
- OS.XCopyArea(xDisplay, xDrawable, xDrawable, handle, x, y, width, height, destX, destY);
- if (data.image == null && paint) {
- OS.XSetGraphicsExposures (xDisplay, handle, false);
- boolean disjoint = (destX + width < x) || (x + width < destX) || (destY + height < y) || (y + height < destY);
- if (disjoint) {
- OS.XClearArea (xDisplay, xDrawable, x, y, width, height, true);
- } else {
- if (deltaX != 0) {
- int newX = destX - deltaX;
- if (deltaX < 0) newX = destX + width;
- OS.XClearArea (xDisplay, xDrawable, newX, y, Math.abs (deltaX), height, true);
- }
- if (deltaY != 0) {
- int newY = destY - deltaY;
- if (deltaY < 0) newY = destY + height;
- OS.XClearArea (xDisplay, xDrawable, x, newY, width, Math.abs (deltaY), true);
- }
- }
- }
-}
-/**
- * Copies a rectangular area of the receiver at the specified
- * position into the image, which must be of type <code>SWT.BITMAP</code>.
- *
- * @param image the image to copy into
- * @param x the x coordinate in the receiver of the area to be copied
- * @param y the y coordinate in the receiver of the area to be copied
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image is not a bitmap or has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void copyArea(Image image, int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Rectangle rect = image.getBounds();
- int xDisplay = data.display;
- int xGC = OS.XCreateGC(xDisplay, image.pixmap, 0, null);
- if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.XSetSubwindowMode (xDisplay, xGC, OS.IncludeInferiors);
- OS.XCopyArea(xDisplay, data.drawable, image.pixmap, xGC, x, y, rect.width, rect.height, 0, 0);
- OS.XFreeGC(xDisplay, xGC);
-}
-void destroy() {
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) Cairo.cairo_destroy(cairo);
- data.cairo = 0;
-
- /* Free resources */
- int clipRgn = data.clipRgn;
- if (clipRgn != 0) OS.XDestroyRegion(clipRgn);
- Image image = data.image;
- if (image != null) {
- image.memGC = null;
- if (image.transparentPixel != -1) image.createMask();
- }
-
- int renderTable = data.renderTable;
- if (renderTable != 0) OS.XmRenderTableFree(renderTable);
- int xmString = data.xmString;
- if (xmString != 0) OS.XmStringFree (xmString);
- int xmText = data.xmText;
- if (xmText != 0) OS.XmStringFree (xmText);
- int xmMnemonic = data.xmMnemonic;
- if (xmMnemonic != 0) OS.XmStringFree (xmMnemonic);
-
- /* Dispose the GC */
- if (drawable != null) drawable.internal_dispose_GC(handle, data);
-
- data.display = data.drawable = data.colormap =
- data.clipRgn = data.renderTable = data.xmString = data.xmText =
- data.xmMnemonic = 0;
- data.font = null;
- drawable = null;
- handle = 0;
- data.image = null;
- data = null;
-}
-/**
- * Draws the outline of a circular or elliptical arc
- * within the specified rectangular area.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees, using the current color.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc to be drawn
- * @param y the y coordinate of the upper-left corner of the arc to be drawn
- * @param width the width of the arc to be drawn
- * @param height the height of the arc to be drawn
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
- if (width == height) {
- if (arcAngle >= 0) {
- Cairo.cairo_arc_negative(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f, width / 2f, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- } else {
- Cairo.cairo_arc(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f, width / 2f, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- }
- } else {
- Cairo.cairo_save(cairo);
- Cairo.cairo_translate(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f);
- Cairo.cairo_scale(cairo, width / 2f, height / 2f);
- if (arcAngle >= 0) {
- Cairo.cairo_arc_negative(cairo, 0, 0, 1, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- } else {
- Cairo.cairo_arc(cairo, 0, 0, 1, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- }
- Cairo.cairo_restore(cairo);
- }
- Cairo.cairo_stroke(cairo);
- return;
- }
- OS.XDrawArc(data.display, data.drawable, handle, x, y, width, height, startAngle * 64, arcAngle * 64);
-}
-/**
- * Draws a rectangle, based on the specified arguments, which has
- * the appearance of the platform's <em>focus rectangle</em> if the
- * platform supports such a notion, and otherwise draws a simple
- * rectangle in the receiver's foreground color.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width of the rectangle
- * @param height the height of the rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void drawFocus (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- /*
- * When the drawable is not a widget, the highlight
- * color is zero.
- */
- int xDisplay = data.display;
- int xDrawable = data.drawable;
- int highlightColor = 0;
- int widget = OS.XtWindowToWidget (xDisplay, xDrawable);
- if (widget != 0) {
- int [] argList = {OS.XmNhighlightColor, 0};
- OS.XtGetValues (widget, argList, argList.length / 2);
- highlightColor = argList [1];
- }
-
- /* Draw the focus rectangle */
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int cairo = data.cairo;
- if (cairo != 0) {
- int lineWidth = 1;
- Cairo.cairo_save(cairo);
- Cairo.cairo_set_line_width(cairo, lineWidth);
- XColor color = new XColor();
- color.pixel = highlightColor;
- OS.XQueryColor (data.display, data.colormap, color);
- Cairo.cairo_set_source_rgba(cairo, (color.red & 0xFFFF) / (float)0xFFFF, (color.green & 0xFFFF) / (float)0xFFFF, (color.blue & 0xFFFF) / (float)0xFFFF, 1);
- Cairo.cairo_rectangle(cairo, x + lineWidth / 2f, y + lineWidth / 2f, width, height);
- Cairo.cairo_stroke(cairo);
- Cairo.cairo_restore(cairo);
- return;
- }
- OS.XSetForeground (xDisplay, handle, highlightColor);
- OS.XDrawRectangle (xDisplay, xDrawable, handle, x, y, width - 1, height - 1);
- data.state &= ~(BACKGROUND | FOREGROUND);
-}
-/**
- * Draws the given image in the receiver at the specified
- * coordinates.
- *
- * @param image the image to draw
- * @param x the x coordinate of where to draw
- * @param y the y coordinate of where to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if the given coordinates are outside the bounds of the image</li>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- */
-public void drawImage(Image image, int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- drawImage(image, 0, 0, -1, -1, x, y, -1, -1, true);
-}
-
-/**
- * Copies a rectangular area from the source image into a (potentially
- * different sized) rectangular area in the receiver. If the source
- * and destination areas are of differing sizes, then the source
- * area will be stretched or shrunk to fit the destination area
- * as it is copied. The copy fails if any part of the source rectangle
- * lies outside the bounds of the source image, or if any of the width
- * or height arguments are negative.
- *
- * @param image the source image
- * @param srcX the x coordinate in the source image to copy from
- * @param srcY the y coordinate in the source image to copy from
- * @param srcWidth the width in pixels to copy from the source
- * @param srcHeight the height in pixels to copy from the source
- * @param destX the x coordinate in the destination to copy to
- * @param destY the y coordinate in the destination to copy to
- * @param destWidth the width in pixels of the destination rectangle
- * @param destHeight the height in pixels of the destination rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if any of the width or height arguments are negative.
- * <li>ERROR_INVALID_ARGUMENT - if the source rectangle is not contained within the bounds of the source image</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- */
-public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (srcWidth == 0 || srcHeight == 0 || destWidth == 0 || destHeight == 0) return;
- if (srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 || destWidth < 0 || destHeight < 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- drawImage(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false);
-}
-void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
- int[] width = new int[1];
- int[] height = new int[1];
- int[] depth = new int[1];
- int[] unused = new int[1];
- OS.XGetGeometry(data.display, srcImage.pixmap, unused, unused, unused, width, height, unused, depth);
- int imgWidth = width[0];
- int imgHeight = height[0];
- if (simple) {
- srcWidth = destWidth = imgWidth;
- srcHeight = destHeight = imgHeight;
- } else {
- simple = srcX == 0 && srcY == 0 &&
- srcWidth == destWidth && destWidth == imgWidth &&
- srcHeight == destHeight && destHeight == imgHeight;
- if (srcX + srcWidth > imgWidth || srcY + srcHeight > imgHeight) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- if (data.alpha != 0) {
- srcImage.createSurface();
- Cairo.cairo_save(cairo);
- Cairo.cairo_rectangle(cairo, destX , destY, destWidth, destHeight);
- Cairo.cairo_clip(cairo);
- Cairo.cairo_translate(cairo, destX - srcX, destY - srcY);
- if (srcWidth != destWidth || srcHeight != destHeight) {
- Cairo.cairo_scale(cairo, destWidth / (float)srcWidth, destHeight / (float)srcHeight);
- }
- int filter = Cairo.CAIRO_FILTER_GOOD;
- switch (data.interpolation) {
- case SWT.DEFAULT: filter = Cairo.CAIRO_FILTER_GOOD; break;
- case SWT.NONE: filter = Cairo.CAIRO_FILTER_NEAREST; break;
- case SWT.LOW: filter = Cairo.CAIRO_FILTER_FAST; break;
- case SWT.HIGH: filter = Cairo.CAIRO_FILTER_BEST; break;
- }
- int /*long*/ pattern = Cairo.cairo_pattern_create_for_surface(srcImage.surface);
- if (pattern == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (srcWidth != destWidth || srcHeight != destHeight) {
- /*
- * Bug in Cairo. When drawing the image streched with an interpolation
- * alghorithm, the edges of the image are faded. This is not a bug, but
- * it is not desired. To avoid the faded edges, it should be possible to
- * use cairo_pattern_set_extend() to set the pattern extend to either
- * CAIRO_EXTEND_REFLECT or CAIRO_EXTEND_PAD, but these are not implemented
- * in some versions of cairo (1.2.x) and have bugs in others (in 1.4.2 it
- * draws with black edges). The fix is to implement CAIRO_EXTEND_REFLECT
- * by creating an image that is 3 times bigger than the original, drawing
- * the original image in every quadrant (with an appropriate transform) and
- * use this image as the pattern.
- *
- * NOTE: For some reaons, it is necessary to use CAIRO_EXTEND_PAD with
- * the image that was created or the edges are still faded.
- */
- if (Cairo.cairo_version () >= Cairo.CAIRO_VERSION_ENCODE(1, 4, 2)) {
- int /*long*/ surface = Cairo.cairo_image_surface_create(Cairo.CAIRO_FORMAT_ARGB32, imgWidth * 3, imgHeight * 3);
- int /*long*/ cr = Cairo.cairo_create(surface);
- Cairo.cairo_set_source_surface(cr, srcImage.surface, imgWidth, imgHeight);
- Cairo.cairo_paint(cr);
- Cairo.cairo_scale(cr, -1, -1);
- Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth, -imgHeight);
- Cairo.cairo_paint(cr);
- Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth * 3, -imgHeight);
- Cairo.cairo_paint(cr);
- Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth, -imgHeight * 3);
- Cairo.cairo_paint(cr);
- Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth * 3, -imgHeight * 3);
- Cairo.cairo_paint(cr);
- Cairo.cairo_scale(cr, 1, -1);
- Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth, imgHeight);
- Cairo.cairo_paint(cr);
- Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth * 3, imgHeight);
- Cairo.cairo_paint(cr);
- Cairo.cairo_scale(cr, -1, -1);
- Cairo.cairo_set_source_surface(cr, srcImage.surface, imgWidth, -imgHeight);
- Cairo.cairo_paint(cr);
- Cairo.cairo_set_source_surface(cr, srcImage.surface, imgWidth, -imgHeight * 3);
- Cairo.cairo_paint(cr);
- Cairo.cairo_destroy(cr);
- int /*long*/ newPattern = Cairo.cairo_pattern_create_for_surface(surface);
- Cairo.cairo_surface_destroy(surface);
- if (newPattern == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Cairo.cairo_pattern_destroy(pattern);
- pattern = newPattern;
- Cairo.cairo_pattern_set_extend(pattern, Cairo.CAIRO_EXTEND_PAD);
- double[] matrix = new double[6];
- Cairo.cairo_matrix_init_translate(matrix, imgWidth, imgHeight);
- Cairo.cairo_pattern_set_matrix(pattern, matrix);
- }
-// Cairo.cairo_pattern_set_extend(pattern, Cairo.CAIRO_EXTEND_REFLECT);
- }
- Cairo.cairo_pattern_set_filter(pattern, filter);
- Cairo.cairo_set_source(cairo, pattern);
- if (data.alpha != 0xFF) {
- Cairo.cairo_paint_with_alpha(cairo, data.alpha / (float)0xFF);
- } else {
- Cairo.cairo_paint(cairo);
- }
- Cairo.cairo_restore(cairo);
- Cairo.cairo_pattern_destroy(pattern);
- }
- return;
- }
- if (srcImage.alpha != -1 || srcImage.alphaData != null) {
- drawImageAlpha(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth[0]);
- } else if (srcImage.transparentPixel != -1 || srcImage.mask != 0) {
- drawImageMask(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth[0]);
- } else {
- drawImage(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth[0]);
- }
-}
-void drawImageAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int depth) {
- /* Simple cases */
- if (srcImage.alpha == 0) return;
- if (srcImage.alpha == 255) {
- drawImage(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth);
- return;
- }
- if (device.useXRender) {
- drawImageXRender(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, srcImage.mask, OS.PictStandardA8);
- return;
- }
-
- /* Check the clipping */
- Rectangle rect = getClipping();
- rect = rect.intersection(new Rectangle(destX, destY, destWidth, destHeight));
- if (rect.isEmpty()) return;
-
- /* Optimization. Recalculate the src and dest rectangles so that
- * only the clipping area is drawn.
- */
- int sx1 = srcX + (((rect.x - destX) * srcWidth) / destWidth);
- int sx2 = srcX + ((((rect.x + rect.width) - destX) * srcWidth) / destWidth);
- int sy1 = srcY + (((rect.y - destY) * srcHeight) / destHeight);
- int sy2 = srcY + ((((rect.y + rect.height) - destY) * srcHeight) / destHeight);
- destX = rect.x;
- destY = rect.y;
- destWidth = rect.width;
- destHeight = rect.height;
- srcX = sx1;
- srcY = sy1;
- srcWidth = Math.max(1, sx2 - sx1);
- srcHeight = Math.max(1, sy2 - sy1);
-
- int xDisplay = data.display;
- int xDrawable = data.drawable;
- int xDestImagePtr = 0, xSrcImagePtr = 0;
- try {
- /* Get the background pixels */
- xDestImagePtr = OS.XGetImage(xDisplay, xDrawable, destX, destY, destWidth, destHeight, OS.AllPlanes, OS.ZPixmap);
- if (xDestImagePtr == 0) return;
- XImage xDestImage = new XImage();
- OS.memmove(xDestImage, xDestImagePtr, XImage.sizeof);
- byte[] destData = new byte[xDestImage.bytes_per_line * xDestImage.height];
- OS.memmove(destData, xDestImage.data, destData.length);
-
- /* Get the foreground pixels */
- xSrcImagePtr = OS.XGetImage(xDisplay, srcImage.pixmap, srcX, srcY, srcWidth, srcHeight, OS.AllPlanes, OS.ZPixmap);
- if (xSrcImagePtr == 0) return;
- XImage xSrcImage = new XImage();
- OS.memmove(xSrcImage, xSrcImagePtr, XImage.sizeof);
- byte[] srcData = new byte[xSrcImage.bytes_per_line * xSrcImage.height];
- OS.memmove(srcData, xSrcImage.data, srcData.length);
-
- /* Compose the pixels */
- if (xSrcImage.depth <= 8) {
- XColor[] xcolors = data.device.xcolors;
- if (xcolors == null) SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- byte[] reds = new byte[xcolors.length];
- byte[] greens = new byte[xcolors.length];
- byte[] blues = new byte[xcolors.length];
- for (int i = 0; i < xcolors.length; i++) {
- XColor color = xcolors[i];
- if (color == null) continue;
- reds[i] = (byte)((color.red >> 8) & 0xFF);
- greens[i] = (byte)((color.green >> 8) & 0xFF);
- blues[i] = (byte)((color.blue >> 8) & 0xFF);
- }
- ImageData.blit(ImageData.BLIT_ALPHA,
- srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, xSrcImage.byte_order, 0, 0, srcWidth, srcHeight, reds, greens, blues,
- srcImage.alpha, srcImage.alphaData, imgWidth, srcX, srcY,
- destData, xDestImage.bits_per_pixel, xDestImage.bytes_per_line, xDestImage.byte_order, 0, 0, destWidth, destHeight, reds, greens, blues,
- false, false);
- } else {
- int srcRedMask = xSrcImage.red_mask;
- int srcGreenMask = xSrcImage.green_mask;
- int srcBlueMask = xSrcImage.blue_mask;
- int destRedMask = xDestImage.red_mask;
- int destGreenMask = xDestImage.green_mask;
- int destBlueMask = xDestImage.blue_mask;
-
- /*
- * Feature in X. XGetImage does not retrieve the RGB masks if the drawable
- * is a Pixmap. The fix is to detect that the masks are not valid and use
- * the default visual masks instead.
- *
- * NOTE: It is safe to use the default Visual masks, since we always
- * create images with these masks.
- */
- int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay));
- Visual xVisual = new Visual();
- OS.memmove(xVisual, visual, Visual.sizeof);
- if (srcRedMask == 0 && srcGreenMask == 0 && srcBlueMask == 0) {
- srcRedMask = xVisual.red_mask;
- srcGreenMask = xVisual.green_mask;
- srcBlueMask = xVisual.blue_mask;
- }
- if (destRedMask == 0 && destGreenMask == 0 && destBlueMask == 0) {
- destRedMask = xVisual.red_mask;
- destGreenMask = xVisual.green_mask;
- destBlueMask = xVisual.blue_mask;
- }
-
- ImageData.blit(ImageData.BLIT_ALPHA,
- srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, xSrcImage.byte_order, 0, 0, srcWidth, srcHeight, srcRedMask, srcGreenMask, srcBlueMask,
- srcImage.alpha, srcImage.alphaData, imgWidth, srcX, srcY,
- destData, xDestImage.bits_per_pixel, xDestImage.bytes_per_line, xDestImage.byte_order, 0, 0, destWidth, destHeight, destRedMask, destGreenMask, destBlueMask,
- false, false);
- }
-
- /* Draw the composed pixels */
- OS.memmove(xDestImage.data, destData, destData.length);
- OS.XPutImage(xDisplay, xDrawable, handle, xDestImagePtr, 0, 0, destX, destY, destWidth, destHeight);
- } finally {
- if (xSrcImagePtr != 0) OS.XDestroyImage(xSrcImagePtr);
- if (xDestImagePtr != 0) OS.XDestroyImage(xDestImagePtr);
- }
-}
-void drawImageMask(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int depth) {
- int xDisplay = data.display;
- int xDrawable = data.drawable;
- /* Generate the mask if necessary. */
- if (srcImage.transparentPixel != -1) srcImage.createMask();
-
- if (device.useXRender) {
- drawImageXRender(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, srcImage.mask, OS.PictStandardA1);
- } else {
- int colorPixmap = 0, maskPixmap = 0;
- int foreground = 0x00000000;
- if (simple || (srcWidth == destWidth && srcHeight == destHeight)) {
- colorPixmap = srcImage.pixmap;
- maskPixmap = srcImage.mask;
- } else {
- /* Stretch the color and mask*/
- int xImagePtr = scalePixmap(xDisplay, srcImage.pixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false);
- if (xImagePtr != 0) {
- int xMaskPtr = scalePixmap(xDisplay, srcImage.mask, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false);
- if (xMaskPtr != 0) {
- /* Create color scaled pixmaps */
- colorPixmap = OS.XCreatePixmap(xDisplay, xDrawable, destWidth, destHeight, depth);
- int tempGC = OS.XCreateGC(xDisplay, colorPixmap, 0, null);
- OS.XPutImage(xDisplay, colorPixmap, tempGC, xImagePtr, 0, 0, 0, 0, destWidth, destHeight);
- OS.XFreeGC(xDisplay, tempGC);
-
- /* Create mask scaled pixmaps */
- maskPixmap = OS.XCreatePixmap(xDisplay, xDrawable, destWidth, destHeight, 1);
- tempGC = OS.XCreateGC(xDisplay, maskPixmap, 0, null);
- OS.XPutImage(xDisplay, maskPixmap, tempGC, xMaskPtr, 0, 0, 0, 0, destWidth, destHeight);
- OS.XFreeGC(xDisplay, tempGC);
-
- OS.XDestroyImage(xMaskPtr);
- }
- OS.XDestroyImage(xImagePtr);
- }
-
- /* Change the source rectangle */
- srcX = srcY = 0;
- srcWidth = destWidth;
- srcHeight = destHeight;
-
- foreground = ~foreground;
- }
-
- /* Do the blts */
- if (colorPixmap != 0 && maskPixmap != 0) {
- XGCValues values = new XGCValues();
- OS.XGetGCValues(xDisplay, handle, OS.GCForeground | OS. GCBackground | OS.GCFunction, values);
- OS.XSetFunction(xDisplay, handle, OS.GXxor);
- OS.XCopyArea(xDisplay, colorPixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY);
- OS.XSetForeground(xDisplay, handle, foreground);
- OS.XSetBackground(xDisplay, handle, ~foreground);
- OS.XSetFunction(xDisplay, handle, OS.GXand);
- OS.XCopyPlane(xDisplay, maskPixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY, 1);
- OS.XSetFunction(xDisplay, handle, OS.GXxor);
- OS.XCopyArea(xDisplay, colorPixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY);
- OS.XSetForeground(xDisplay, handle, values.foreground);
- OS.XSetBackground(xDisplay, handle, values.background);
- OS.XSetFunction(xDisplay, handle, values.function);
- }
-
- /* Destroy scaled pixmaps */
- if (colorPixmap != 0 && srcImage.pixmap != colorPixmap) OS.XFreePixmap(xDisplay, colorPixmap);
- if (maskPixmap != 0 && srcImage.mask != maskPixmap) OS.XFreePixmap(xDisplay, maskPixmap);
- }
-
- /* Destroy the image mask if the there is a GC created on the image */
- if (srcImage.transparentPixel != -1 && srcImage.memGC != null) srcImage.destroyMask();
-}
-void drawImageXRender(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int maskPixmap, int maskType) {
- int drawable = data.drawable;
- int xDisplay = data.display;
- int maskPict = 0;
- if (maskPixmap != 0) {
- int attribCount = 0;
- XRenderPictureAttributes attrib = null;
- if (srcImage.alpha != -1) {
- attribCount = 1;
- attrib = new XRenderPictureAttributes();
- attrib.repeat = true;
- }
- maskPict = OS.XRenderCreatePicture(xDisplay, maskPixmap, OS.XRenderFindStandardFormat(xDisplay, maskType), attribCount, attrib);
- if (maskPict == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- }
- int format = OS.XRenderFindVisualFormat(xDisplay, OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay)));
- int destPict = OS.XRenderCreatePicture(xDisplay, drawable, format, 0, null);
- if (destPict == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int srcPict = OS.XRenderCreatePicture(xDisplay, srcImage.pixmap, format, 0, null);
- if (srcPict == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (srcWidth != destWidth || srcHeight != destHeight) {
- int[] transform = new int[]{(int)(((float)srcWidth / destWidth) * 65536), 0, 0, 0, (int)(((float)srcHeight / destHeight) * 65536), 0, 0, 0, 65536};
- OS.XRenderSetPictureTransform(xDisplay, srcPict, transform);
- if (maskPict != 0) OS.XRenderSetPictureTransform(xDisplay, maskPict, transform);
- srcX *= destWidth / (float)srcWidth;
- srcY *= destHeight / (float)srcHeight;
- }
- int clipping = data.clipRgn;
- if (data.damageRgn != 0) {
- if (clipping == 0) {
- clipping = data.damageRgn;
- } else {
- clipping = OS.XCreateRegion ();
- OS.XUnionRegion(clipping, data.clipRgn, clipping);
- OS.XIntersectRegion(clipping, data.damageRgn, clipping);
- }
- }
- if (clipping != 0) {
- OS.XRenderSetPictureClipRegion(xDisplay, destPict, clipping);
- if (clipping != data.clipRgn && clipping != data.damageRgn) {
- OS.XDestroyRegion(clipping);
- }
- }
- OS.XRenderComposite(xDisplay, maskPict != 0 ? OS.PictOpOver : OS.PictOpSrc, srcPict, maskPict, destPict, srcX, srcY, srcX, srcY, destX, destY, destWidth, destHeight);
- OS.XRenderFreePicture(xDisplay, destPict);
- OS.XRenderFreePicture(xDisplay, srcPict);
- if (maskPict != 0) OS.XRenderFreePicture(xDisplay, maskPict);
-}
-void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int depth) {
- int xDisplay = data.display;
- int xDrawable = data.drawable;
- /* Simple case: no stretching */
- if ((srcWidth == destWidth) && (srcHeight == destHeight)) {
- OS.XCopyArea(xDisplay, srcImage.pixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY);
- return;
- }
- if (device.useXRender) {
- drawImageXRender(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, 0, -1);
- return;
- }
-
- /* Streching case */
- int xImagePtr = scalePixmap(xDisplay, srcImage.pixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false);
- if (xImagePtr != 0) {
- OS.XPutImage(xDisplay, xDrawable, handle, xImagePtr, 0, 0, destX, destY, destWidth, destHeight);
- OS.XDestroyImage(xImagePtr);
- }
-}
-static int scalePixmap(int display, int pixmap, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean flipX, boolean flipY) {
- int xSrcImagePtr = OS.XGetImage(display, pixmap, srcX, srcY, srcWidth, srcHeight, OS.AllPlanes, OS.ZPixmap);
- if (xSrcImagePtr == 0) return 0;
- XImage xSrcImage = new XImage();
- OS.memmove(xSrcImage, xSrcImagePtr, XImage.sizeof);
- byte[] srcData = new byte[xSrcImage.bytes_per_line * xSrcImage.height];
- OS.memmove(srcData, xSrcImage.data, srcData.length);
- OS.XDestroyImage(xSrcImagePtr);
- int xImagePtr = 0;
- int visual = OS.XDefaultVisual(display, OS.XDefaultScreen(display));
- switch (xSrcImage.bits_per_pixel) {
- case 1:
- case 4:
- case 8: {
- int format = xSrcImage.bits_per_pixel == 1 ? OS.XYBitmap : OS.ZPixmap;
- xImagePtr = OS.XCreateImage(display, visual, xSrcImage.depth, format, 0, 0, destWidth, destHeight, xSrcImage.bitmap_pad, 0);
- if (xImagePtr == 0) return 0;
- XImage xImage = new XImage();
- OS.memmove(xImage, xImagePtr, XImage.sizeof);
- int bufSize = xImage.bytes_per_line * xImage.height;
- if (bufSize < 0) {
- OS.XDestroyImage(xImagePtr);
- return 0;
- }
- int bufPtr = OS.XtMalloc(bufSize);
- xImage.data = bufPtr;
- OS.memmove(xImagePtr, xImage, XImage.sizeof);
- byte[] buf = new byte[bufSize];
- int srcOrder = xSrcImage.bits_per_pixel == 1 ? xSrcImage.bitmap_bit_order : xSrcImage.byte_order;
- int destOrder = xImage.bits_per_pixel == 1 ? xImage.bitmap_bit_order : xImage.byte_order;
- ImageData.blit(ImageData.BLIT_SRC,
- srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, srcOrder, 0, 0, srcWidth, srcHeight, null, null, null,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- buf, xImage.bits_per_pixel, xImage.bytes_per_line, destOrder, 0, 0, destWidth, destHeight, null, null, null,
- flipX, flipY);
- OS.memmove(bufPtr, buf, bufSize);
- break;
- }
- case 16:
- case 24:
- case 32: {
- xImagePtr = OS.XCreateImage(display, visual, xSrcImage.depth, OS.ZPixmap, 0, 0, destWidth, destHeight, xSrcImage.bitmap_pad, 0);
- if (xImagePtr == 0) return 0;
- XImage xImage = new XImage();
- OS.memmove(xImage, xImagePtr, XImage.sizeof);
- int bufSize = xImage.bytes_per_line * xImage.height;
- if (bufSize < 0) {
- OS.XDestroyImage(xImagePtr);
- return 0;
- }
- int bufPtr = OS.XtMalloc(bufSize);
- xImage.data = bufPtr;
- OS.memmove(xImagePtr, xImage, XImage.sizeof);
- byte[] buf = new byte[bufSize];
- ImageData.blit(ImageData.BLIT_SRC,
- srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, xSrcImage.byte_order, 0, 0, srcWidth, srcHeight, 0, 0, 0,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, 0, 0, 0,
- flipX, flipY);
- OS.memmove(bufPtr, buf, bufSize);
- break;
- }
- }
- return xImagePtr;
-}
-/**
- * Draws a line, using the foreground color, between the points
- * (<code>x1</code>, <code>y1</code>) and (<code>x2</code>, <code>y2</code>).
- *
- * @param x1 the first point's x coordinate
- * @param y1 the first point's y coordinate
- * @param x2 the second point's x coordinate
- * @param y2 the second point's y coordinate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawLine (int x1, int y1, int x2, int y2) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
- Cairo.cairo_move_to(cairo, x1 + xOffset, y1 + yOffset);
- Cairo.cairo_line_to(cairo, x2 + xOffset, y2 + yOffset);
- Cairo.cairo_stroke(cairo);
- return;
- }
- OS.XDrawLine (data.display, data.drawable, handle, x1, y1, x2, y2);
-}
-/**
- * Draws the outline of an oval, using the foreground color,
- * within the specified rectangular area.
- * <p>
- * The result is a circle or ellipse that fits within the
- * rectangle specified by the <code>x</code>, <code>y</code>,
- * <code>width</code>, and <code>height</code> arguments.
- * </p><p>
- * The oval covers an area that is <code>width + 1</code>
- * pixels wide and <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper left corner of the oval to be drawn
- * @param y the y coordinate of the upper left corner of the oval to be drawn
- * @param width the width of the oval to be drawn
- * @param height the height of the oval to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawOval(int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
- if (width == height) {
- Cairo.cairo_arc_negative(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f, width / 2f, 0, -2 * (float)Compatibility.PI);
- } else {
- Cairo.cairo_save(cairo);
- Cairo.cairo_translate(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f);
- Cairo.cairo_scale(cairo, width / 2f, height / 2f);
- Cairo.cairo_arc_negative(cairo, 0, 0, 1, 0, -2 * (float)Compatibility.PI);
- Cairo.cairo_restore(cairo);
- }
- Cairo.cairo_stroke(cairo);
- return;
- }
- OS.XDrawArc(data.display, data.drawable, handle, x, y, width, height, 0, 23040);
-}
-/**
- * Draws the path described by the parameter.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the path to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- *
- * @since 3.1
- */
-public void drawPath(Path path) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- initCairo();
- checkGC(DRAW);
- int /*long*/ cairo = data.cairo;
- Cairo.cairo_save(cairo);
- double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
- Cairo.cairo_translate(cairo, xOffset, yOffset);
- int /*long*/ copy = Cairo.cairo_copy_path(path.handle);
- if (copy == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Cairo.cairo_append_path(cairo, copy);
- Cairo.cairo_path_destroy(copy);
- Cairo.cairo_stroke(cairo);
- Cairo.cairo_restore(cairo);
-}
-/**
- * Draws a pixel, using the foreground color, at the specified
- * point (<code>x</code>, <code>y</code>).
- * <p>
- * Note that the receiver's line attributes do not affect this
- * operation.
- * </p>
- *
- * @param x the point's x coordinate
- * @param y the point's y coordinate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void drawPoint (int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- Cairo.cairo_rectangle(cairo, x, y, 1, 1);
- Cairo.cairo_fill(cairo);
- return;
- }
- OS.XDrawPoint(data.display, data.drawable, handle, x, y);
-}
-/**
- * Draws the closed polygon which is defined by the specified array
- * of integer coordinates, using the receiver's foreground color. The array
- * contains alternating x and y values which are considered to represent
- * points which are the vertices of the polygon. Lines are drawn between
- * each consecutive pair, and between the first pair and last pair in the
- * array.
- *
- * @param pointArray an array of alternating x and y values which are the vertices of the polygon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT if pointArray is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawPolygon(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(DRAW);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- drawPolyline(cairo, pointArray, true);
- Cairo.cairo_stroke(cairo);
- return;
- }
-
- // Motif does not have a native drawPolygon() call. Instead we ensure
- // that the first and last points are the same and call drawPolyline().
-
- int length = pointArray.length;
-
- // Need at least 3 points to define the polygon. If 2 or fewer points
- // passed in, it is either a line or point so just call drawPolyline().
- // Check what happens when XOR is implemented. We may not be able to
- // do this optimization.
-
- if (length < 4) {
- drawPolyline(pointArray);
- return;
- }
-
- // If first and last points are the same, the polygon is already closed.
- // Just call drawPolyline().
- //
- // Check what happens when XOR is implemented. We may not be able to
- // do this optimization.
-
- if (pointArray[0] == pointArray[length - 2] && (pointArray[1] == pointArray[length - 1])) {
- drawPolyline(pointArray);
- return;
- }
-
- // Grow the list of points by one element and make sure the first and last
- // points are the same. This will close the polygon and we can use the
- // drawPolyline() call.
-
- int newPoints[] = new int[length + 2];
- for (int i = 0; i < length ; i++)
- newPoints[i] = pointArray[i];
- newPoints[length] = pointArray[0];
- newPoints[length + 1] = pointArray[1];
-
- drawPolyline(newPoints);
-}
-/**
- * Draws the polyline which is defined by the specified array
- * of integer coordinates, using the receiver's foreground color. The array
- * contains alternating x and y values which are considered to represent
- * points which are the corners of the polyline. Lines are drawn between
- * each consecutive pair, but not between the first pair and last pair in
- * the array.
- *
- * @param pointArray an array of alternating x and y values which are the corners of the polyline
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawPolyline(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(DRAW);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- drawPolyline(cairo, pointArray, false);
- Cairo.cairo_stroke(cairo);
- return;
- }
- short[] xPoints = new short[pointArray.length];
- for (int i = 0; i<pointArray.length;i++) {
- xPoints[i] = (short) pointArray[i];
- }
- OS.XDrawLines(data.display,data.drawable,handle,xPoints,xPoints.length / 2, OS.CoordModeOrigin);
-}
-void drawPolyline(int /*long*/ cairo, int[] pointArray, boolean close) {
- int count = pointArray.length / 2;
- if (count == 0) return;
- double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
- Cairo.cairo_move_to(cairo, pointArray[0] + xOffset, pointArray[1] + yOffset);
- for (int i = 1, j=2; i < count; i++, j += 2) {
- Cairo.cairo_line_to(cairo, pointArray[j] + xOffset, pointArray[j + 1] + yOffset);
- }
- if (close) Cairo.cairo_close_path(cairo);
-}
-/**
- * Draws the outline of the rectangle specified by the arguments,
- * using the receiver's foreground color. The left and right edges
- * of the rectangle are at <code>x</code> and <code>x + width</code>.
- * The top and bottom edges are at <code>y</code> and <code>y + height</code>.
- *
- * @param x the x coordinate of the rectangle to be drawn
- * @param y the y coordinate of the rectangle to be drawn
- * @param width the width of the rectangle to be drawn
- * @param height the height of the rectangle to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRectangle (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
- Cairo.cairo_rectangle(cairo, x + xOffset, y + yOffset, width, height);
- Cairo.cairo_stroke(cairo);
- return;
- }
- OS.XDrawRectangle (data.display, data.drawable, handle, x, y, width, height);
-}
-/**
- * Draws the outline of the specified rectangle, using the receiver's
- * foreground color. The left and right edges of the rectangle are at
- * <code>rect.x</code> and <code>rect.x + rect.width</code>. The top
- * and bottom edges are at <code>rect.y</code> and
- * <code>rect.y + rect.height</code>.
- *
- * @param rect the rectangle to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRectangle (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- drawRectangle (rect.x, rect.y, rect.width, rect.height);
-}
-/**
- * Draws the outline of the round-cornered rectangle specified by
- * the arguments, using the receiver's foreground color. The left and
- * right edges of the rectangle are at <code>x</code> and <code>x + width</code>.
- * The top and bottom edges are at <code>y</code> and <code>y + height</code>.
- * The <em>roundness</em> of the corners is specified by the
- * <code>arcWidth</code> and <code>arcHeight</code> arguments, which
- * are respectively the width and height of the ellipse used to draw
- * the corners.
- *
- * @param x the x coordinate of the rectangle to be drawn
- * @param y the y coordinate of the rectangle to be drawn
- * @param width the width of the rectangle to be drawn
- * @param height the height of the rectangle to be drawn
- * @param arcWidth the width of the arc
- * @param arcHeight the height of the arc
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- int nx = x;
- int ny = y;
- int nw = width;
- int nh = height;
- int naw = arcWidth;
- int nah = arcHeight;
- if (nw < 0) {
- nw = 0 - nw;
- nx = nx - nw;
- }
- if (nh < 0) {
- nh = 0 - nh;
- ny = ny - nh;
- }
- if (naw < 0) naw = 0 - naw;
- if (nah < 0) nah = 0 - nah;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset;
- if (naw == 0 || nah == 0) {
- Cairo.cairo_rectangle(cairo, x + xOffset, y + yOffset, width, height);
- } else {
- float naw2 = naw / 2f;
- float nah2 = nah / 2f;
- float fw = nw / naw2;
- float fh = nh / nah2;
- Cairo.cairo_save(cairo);
- Cairo.cairo_translate(cairo, nx + xOffset, ny + yOffset);
- Cairo.cairo_scale(cairo, naw2, nah2);
- Cairo.cairo_move_to(cairo, fw - 1, 0);
- Cairo.cairo_arc(cairo, fw - 1, 1, 1, Compatibility.PI + Compatibility.PI/2.0, Compatibility.PI*2.0);
- Cairo.cairo_arc(cairo, fw - 1, fh - 1, 1, 0, Compatibility.PI/2.0);
- Cairo.cairo_arc(cairo, 1, fh - 1, 1, Compatibility.PI/2, Compatibility.PI);
- Cairo.cairo_arc(cairo, 1, 1, 1, Compatibility.PI, 270.0*Compatibility.PI/180.0);
- Cairo.cairo_close_path(cairo);
- Cairo.cairo_restore(cairo);
- }
- Cairo.cairo_stroke(cairo);
- return;
- }
- int naw2 = naw / 2;
- int nah2 = nah / 2;
- int xDisplay = data.display;
- int xDrawable = data.drawable;
- if (nw > naw) {
- if (nh > nah) {
- OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny, naw, nah, 5760, 5760);
- OS.XDrawLine(xDisplay, xDrawable, handle, nx + naw2, ny, nx + nw - naw2, ny);
- OS.XDrawArc(xDisplay, xDrawable, handle, nx + nw - naw, ny, naw, nah, 0, 5760);
- OS.XDrawLine(xDisplay, xDrawable, handle, nx + nw, ny + nah2, nx + nw, ny + nh - nah2);
- OS.XDrawArc(xDisplay, xDrawable, handle, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760);
- OS.XDrawLine(xDisplay,xDrawable,handle, nx + naw2, ny + nh, nx + nw - naw2, ny + nh);
- OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny + nh - nah, naw, nah, 11520, 5760);
- OS.XDrawLine(xDisplay, xDrawable, handle, nx, ny + nah2, nx, ny + nh - nah2);
- } else {
- OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny, naw, nh, 5760, 11520);
- OS.XDrawLine(xDisplay, xDrawable, handle, nx + naw2, ny, nx + nw - naw2, ny);
- OS.XDrawArc(xDisplay, xDrawable, handle, nx + nw - naw, ny, naw, nh, 17280, 11520);
- OS.XDrawLine(xDisplay,xDrawable,handle, nx + naw2, ny + nh, nx + nw - naw2, ny + nh);
- }
- } else {
- if (nh > nah) {
- OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny, nw, nah, 0, 11520);
- OS.XDrawLine(xDisplay, xDrawable, handle, nx + nw, ny + nah2, nx + nw, ny + nh - nah2);
- OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny + nh - nah, nw, nah, 11520, 11520);
- OS.XDrawLine(xDisplay,xDrawable,handle, nx, ny + nah2, nx, ny + nh - nah2);
- } else {
- OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny, nw, nh, 0, 23040);
- }
- }
-}
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. No tab expansion or carriage return processing
- * will be performed. The background of the rectangular area where
- * the string is being drawn will be filled with the receiver's
- * background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawString (String string, int x, int y) {
- drawString(string, x, y, false);
-}
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. No tab expansion or carriage return processing
- * will be performed. If <code>isTransparent</code> is <code>true</code>,
- * then the background of the rectangular area where the string is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawString (String string, int x, int y, boolean isTransparent) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (string.length() == 0) return;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- //TODO - honor isTransparent
- checkGC(FOREGROUND | FONT);
- cairo_font_extents_t extents = new cairo_font_extents_t();
- Cairo.cairo_font_extents(cairo, extents);
- double baseline = y + extents.ascent;
- Cairo.cairo_move_to(cairo, x, baseline);
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
- Cairo.cairo_show_text(cairo, buffer);
- Cairo.cairo_new_path(cairo);
- return;
- }
- setString(string);
- checkGC(FOREGROUND | FONT | BACKGROUND_BG);
- if (isTransparent) {
- OS.XmStringDraw (data.display, data.drawable, data.font.handle, data.xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
- } else {
- OS.XmStringDrawImage (data.display, data.drawable, data.font.handle, data.xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
- }
-}
-void createRenderTable() {
- int fontList = data.font.handle;
- /* Get the width of the tabs */
- byte[] buffer = {(byte)' ', 0};
- int xmString = OS.XmStringCreate(buffer, OS.XmFONTLIST_DEFAULT_TAG);
- int tabWidth = OS.XmStringWidth(fontList, xmString) * 8;
- OS.XmStringFree(xmString);
-
- /* Create the tab list */
- int [] tabs = new int[16];
- int tab = OS.XmTabCreate(tabWidth, (byte) OS.XmPIXELS, (byte) OS.XmRELATIVE, (byte) OS.XmALIGNMENT_BEGINNING, null);
- for (int i = 0; i < tabs.length; i++) tabs[i] = tab;
- int tabList = OS.XmTabListInsertTabs(0, tabs, tabs.length, 0);
-
- /* Create a font context to iterate over the elements in the font list */
- int[] fontBuffer = new int[1];
- if (!OS.XmFontListInitFontContext(fontBuffer, fontList)) {
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- int context = fontBuffer[0], fontListEntry = 0;
- int[] renditions = new int[4]; int renditionCount = 0;
-
- /* Create a rendition for each entry in the font list */
- while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, fontBuffer);
- int fontType = (fontBuffer [0] == 0) ? OS.XmFONT_IS_FONT : OS.XmFONT_IS_FONTSET;
- if (fontPtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int [] argList = {
- OS.XmNtabList, tabList,
- OS.XmNfont, fontPtr,
- OS.XmNfontType, fontType,
- };
- int rendition = OS.XmRenditionCreate(data.device.shellHandle, OS.XmFONTLIST_DEFAULT_TAG, argList, argList.length / 2);
- renditions[renditionCount++] = rendition;
- if (renditionCount == renditions.length) {
- int[] newArray = new int[renditions.length + 4];
- System.arraycopy(newArray, 0, renditions, 0, renditionCount);
- renditions = newArray;
- }
- }
- OS.XmFontListFreeFontContext(context);
- OS.XmTabFree(tab);
- OS.XmTabListFree(tabList);
-
- /* Create the render table from the renditions */
- data.renderTable = OS.XmRenderTableAddRenditions(0, renditions, renditionCount, OS.XmMERGE_REPLACE);
- for (int i = 0; i < renditionCount; i++) OS.XmRenditionFree(renditions[i]);
-}
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion and carriage return processing
- * are performed. The background of the rectangular area where
- * the text is being drawn will be filled with the receiver's
- * background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText (String string, int x, int y) {
- drawText(string, x, y, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
-}
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion and carriage return processing
- * are performed. If <code>isTransparent</code> is <code>true</code>,
- * then the background of the rectangular area where the text is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText (String string, int x, int y, boolean isTransparent) {
- int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB;
- if (isTransparent) flags |= SWT.DRAW_TRANSPARENT;
- drawText(string, x, y, flags);
-}
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion, line delimiter and mnemonic
- * processing are performed according to the specified flags. If
- * <code>flags</code> includes <code>DRAW_TRANSPARENT</code>,
- * then the background of the rectangular area where the text is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- * <p>
- * The parameter <code>flags</code> may be a combination of:
- * <dl>
- * <dt><b>DRAW_DELIMITER</b></dt>
- * <dd>draw multiple lines</dd>
- * <dt><b>DRAW_TAB</b></dt>
- * <dd>expand tabs</dd>
- * <dt><b>DRAW_MNEMONIC</b></dt>
- * <dd>underline the mnemonic character</dd>
- * <dt><b>DRAW_TRANSPARENT</b></dt>
- * <dd>transparent background</dd>
- * </dl>
- * </p>
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param flags the flags specifying how to process the text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText (String string, int x, int y, int flags) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (string.length() == 0) return;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- //TODO - honor flags
- checkGC(FOREGROUND | FONT);
- cairo_font_extents_t extents = new cairo_font_extents_t();
- Cairo.cairo_font_extents(cairo, extents);
- double baseline = y + extents.ascent;
- Cairo.cairo_move_to(cairo, x, baseline);
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
- Cairo.cairo_show_text(cairo, buffer);
- Cairo.cairo_new_path(cairo);
- return;
- }
- setText(string, flags);
- checkGC(FOREGROUND | FONT | BACKGROUND_BG);
- int xDisplay = data.display;
- int xDrawable = data.drawable;
- if (data.image != null) OS.XtRegisterDrawable (xDisplay, xDrawable, data.device.shellHandle);
- int xmMnemonic = data.xmMnemonic;
- if (xmMnemonic != 0) {
- OS.XmStringDrawUnderline(xDisplay, xDrawable, data.renderTable, data.xmText, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null, xmMnemonic);
- } else {
- if ((flags & SWT.DRAW_TRANSPARENT) != 0) {
- OS.XmStringDraw(xDisplay, xDrawable, data.renderTable, data.xmText, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
- } else {
- OS.XmStringDrawImage(xDisplay, xDrawable, data.renderTable, data.xmText, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
- }
- }
- if (data.image != null) OS.XtUnregisterDrawable (xDisplay, xDrawable);
-}
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof GC)) return false;
- return handle == ((GC)object).handle;
-}
-/**
- * Fills the interior of a circular or elliptical arc within
- * the specified rectangular area, with the receiver's background
- * color.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees, using the current color.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc to be filled
- * @param y the y coordinate of the upper-left corner of the arc to be filled
- * @param width the width of the arc to be filled
- * @param height the height of the arc to be filled
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawArc
- */
-public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- if (width == height) {
- if (arcAngle >= 0) {
- Cairo.cairo_arc_negative(cairo, x + width / 2f, y + height / 2f, width / 2f, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- } else {
- Cairo.cairo_arc(cairo, x + width / 2f, y + height / 2f, width / 2f, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- }
- Cairo.cairo_line_to(cairo, x + width / 2f, y + height / 2f);
- } else {
- Cairo.cairo_save(cairo);
- Cairo.cairo_translate(cairo, x + width / 2f, y + height / 2f);
- Cairo.cairo_scale(cairo, width / 2f, height / 2f);
- if (arcAngle >= 0) {
- Cairo.cairo_arc_negative(cairo, 0, 0, 1, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- } else {
- Cairo.cairo_arc(cairo, 0, 0, 1, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- }
- Cairo.cairo_line_to(cairo, 0, 0);
- Cairo.cairo_restore(cairo);
- }
- Cairo.cairo_fill(cairo);
- return;
- }
- OS.XFillArc(data.display, data.drawable, handle, x, y, width, height, startAngle * 64, arcAngle * 64);
-}
-
-/**
- * Fills the interior of the specified rectangle with a gradient
- * sweeping from left to right or top to bottom progressing
- * from the receiver's foreground color to its background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled, may be negative
- * (inverts direction of gradient if horizontal)
- * @param height the height of the rectangle to be filled, may be negative
- * (inverts direction of gradient if vertical)
- * @param vertical if true sweeps from top to bottom, else
- * sweeps from left to right
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if ((width == 0) || (height == 0)) return;
-
- RGB backgroundRGB, foregroundRGB;
- backgroundRGB = getBackground().getRGB();
- foregroundRGB = getForeground().getRGB();
-
- RGB fromRGB, toRGB;
- fromRGB = foregroundRGB;
- toRGB = backgroundRGB;
- boolean swapColors = false;
- if (width < 0) {
- x += width; width = -width;
- if (! vertical) swapColors = true;
- }
- if (height < 0) {
- y += height; height = -height;
- if (vertical) swapColors = true;
- }
- if (swapColors) {
- fromRGB = backgroundRGB;
- toRGB = foregroundRGB;
- }
- if (fromRGB.equals(toRGB)) {
- fillRectangle(x, y, width, height);
- return;
- }
- /* X Window deals with a virtually limitless array of color formats
- * but we only distinguish between paletted and direct modes
- */
- int xDisplay = data.display;
- int xScreenNum = OS.XDefaultScreen(xDisplay);
- final int xScreen = OS.XDefaultScreenOfDisplay(xDisplay);
- final int xVisual = OS.XDefaultVisual(xDisplay, xScreenNum);
- Visual visual = new Visual();
- OS.memmove(visual, xVisual, Visual.sizeof);
- final int depth = OS.XDefaultDepthOfScreen(xScreen);
- final boolean directColor = (depth > 8);
-
- // This code is intentionally commented since elsewhere in SWT we
- // assume that depth <= 8 means we are in a paletted mode though
- // this is not always the case.
- //final boolean directColor = (visual.c_class == OS.TrueColor) || (visual.c_class == OS.DirectColor);
-
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- int /*long*/ pattern;
- if (vertical) {
- pattern = Cairo.cairo_pattern_create_linear (0.0, 0.0, 0.0, 1.0);
- } else {
- pattern = Cairo.cairo_pattern_create_linear (0.0, 0.0, 1.0, 0.0);
- }
- Cairo.cairo_pattern_add_color_stop_rgba (pattern, 0, fromRGB.red / 255f, fromRGB.green / 255f, fromRGB.blue / 255f, data.alpha / 255f);
- Cairo.cairo_pattern_add_color_stop_rgba (pattern, 1, toRGB.red / 255f, toRGB.green / 255f, toRGB.blue / 255f, data.alpha / 255f);
- Cairo.cairo_save(cairo);
- Cairo.cairo_translate(cairo, x, y);
- Cairo.cairo_scale(cairo, width, height);
- Cairo.cairo_rectangle(cairo, 0, 0, 1, 1);
- Cairo.cairo_set_source(cairo, pattern);
- Cairo.cairo_fill(cairo);
- Cairo.cairo_restore(cairo);
- Cairo.cairo_pattern_destroy(pattern);
- return;
- }
- final int redBits, greenBits, blueBits;
- if (directColor) {
- // RGB mapped display
- redBits = getChannelWidth(visual.red_mask);
- greenBits = getChannelWidth(visual.green_mask);
- blueBits = getChannelWidth(visual.blue_mask);
- } else {
- // Index display
- redBits = greenBits = blueBits = 0;
- }
- ImageData.fillGradientRectangle(this, data.device,
- x, y, width, height, vertical, fromRGB, toRGB,
- redBits, greenBits, blueBits);
-}
-
-/**
- * Computes the required channel width (depth) from a mask.
- */
-static int getChannelWidth(int mask) {
- int width = 0;
- while (mask != 0) {
- width += (mask & 1);
- mask >>>= 1;
- }
- return width;
-}
-
-/**
- * Fills the interior of an oval, within the specified
- * rectangular area, with the receiver's background
- * color.
- *
- * @param x the x coordinate of the upper left corner of the oval to be filled
- * @param y the y coordinate of the upper left corner of the oval to be filled
- * @param width the width of the oval to be filled
- * @param height the height of the oval to be filled
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawOval
- */
-public void fillOval (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- if (width == height) {
- Cairo.cairo_arc_negative(cairo, x + width / 2f, y + height / 2f, width / 2f, 0, 2 * (float)Compatibility.PI);
- } else {
- Cairo.cairo_save(cairo);
- Cairo.cairo_translate(cairo, x + width / 2f, y + height / 2f);
- Cairo.cairo_scale(cairo, width / 2f, height / 2f);
- Cairo.cairo_arc_negative(cairo, 0, 0, 1, 0, 2 * (float)Compatibility.PI);
- Cairo.cairo_restore(cairo);
- }
- Cairo.cairo_fill(cairo);
- return;
- }
- OS.XFillArc (data.display, data.drawable, handle, x, y, width, height, 0, 23040);
-}
-/**
- * Fills the path described by the parameter.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the path to fill
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- *
- * @since 3.1
- */
-public void fillPath (Path path) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- initCairo();
- checkGC(FILL);
- int /*long*/ cairo = data.cairo;
- int /*long*/ copy = Cairo.cairo_copy_path(path.handle);
- if (copy == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Cairo.cairo_append_path(cairo, copy);
- Cairo.cairo_path_destroy(copy);
- Cairo.cairo_fill(cairo);
-}
-/**
- * Fills the interior of the closed polygon which is defined by the
- * specified array of integer coordinates, using the receiver's
- * background color. The array contains alternating x and y values
- * which are considered to represent points which are the vertices of
- * the polygon. Lines are drawn between each consecutive pair, and
- * between the first pair and last pair in the array.
- *
- * @param pointArray an array of alternating x and y values which are the vertices of the polygon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT if pointArray is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawPolygon
- */
-public void fillPolygon(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(FILL);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- drawPolyline(cairo, pointArray, true);
- Cairo.cairo_fill(cairo);
- return;
- }
- short[] xPoints = new short[pointArray.length];
- for (int i = 0; i<pointArray.length;i++) {
- xPoints[i] = (short) pointArray[i];
- }
- OS.XFillPolygon(data.display, data.drawable, handle,xPoints, xPoints.length / 2, OS.Complex, OS.CoordModeOrigin);
-}
-/**
- * Fills the interior of the rectangle specified by the arguments,
- * using the receiver's background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillRectangle (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- Cairo.cairo_rectangle(cairo, x, y, width, height);
- Cairo.cairo_fill(cairo);
- return;
- }
- OS.XFillRectangle (data.display, data.drawable, handle, x, y, width, height);
-}
-/**
- * Fills the interior of the specified rectangle, using the receiver's
- * background color.
- *
- * @param rect the rectangle to be filled
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillRectangle (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- fillRectangle(rect.x, rect.y, rect.width, rect.height);
-}
-/**
- * Fills the interior of the round-cornered rectangle specified by
- * the arguments, using the receiver's background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- * @param arcWidth the width of the arc
- * @param arcHeight the height of the arc
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRoundRectangle
- */
-public void fillRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- int nx = x;
- int ny = y;
- int nw = width;
- int nh = height;
- int naw = arcWidth;
- int nah = arcHeight;
- if (nw < 0) {
- nw = 0 - nw;
- nx = nx - nw;
- }
- if (nh < 0) {
- nh = 0 - nh;
- ny = ny -nh;
- }
- if (naw < 0) naw = 0 - naw;
- if (nah < 0) nah = 0 - nah;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- if (naw == 0 || nah == 0) {
- Cairo.cairo_rectangle(cairo, x, y, width, height);
- } else {
- float naw2 = naw / 2f;
- float nah2 = nah / 2f;
- float fw = nw / naw2;
- float fh = nh / nah2;
- Cairo.cairo_save(cairo);
- Cairo.cairo_translate(cairo, nx, ny);
- Cairo.cairo_scale(cairo, naw2, nah2);
- Cairo.cairo_move_to(cairo, fw - 1, 0);
- Cairo.cairo_arc(cairo, fw - 1, 1, 1, Compatibility.PI + Compatibility.PI/2.0, Compatibility.PI*2.0);
- Cairo.cairo_arc(cairo, fw - 1, fh - 1, 1, 0, Compatibility.PI/2.0);
- Cairo.cairo_arc(cairo, 1, fh - 1, 1, Compatibility.PI/2, Compatibility.PI);
- Cairo.cairo_arc(cairo, 1, 1, 1, Compatibility.PI, 270.0*Compatibility.PI/180.0);
- Cairo.cairo_close_path(cairo);
- Cairo.cairo_restore(cairo);
- }
- Cairo.cairo_fill(cairo);
- return;
- }
- int naw2 = naw / 2;
- int nah2 = nah / 2;
- int xDisplay = data.display;
- int xDrawable = data.drawable;
- if (nw > naw) {
- if (nh > nah) {
- OS.XFillArc(xDisplay, xDrawable, handle, nx, ny, naw, nah, 5760, 5760);
- OS.XFillRectangle(xDisplay, xDrawable, handle, nx + naw2, ny, nw - naw2 * 2, nah2);
- OS.XFillArc(xDisplay, xDrawable, handle, nx + nw - naw, ny, naw, nah, 0, 5760);
- OS.XFillRectangle(xDisplay, xDrawable, handle, nx, ny + nah2, nw, nh - nah2 * 2);
- OS.XFillArc(xDisplay, xDrawable, handle, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760);
- OS.XFillRectangle(xDisplay, xDrawable, handle, nx + naw2, ny + nh - nah2, nw - naw2 * 2, nah2);
- OS.XFillArc(xDisplay, xDrawable, handle, nx, ny + nh - nah, naw, nah, 11520, 5760);
- } else {
- OS.XFillArc(xDisplay, xDrawable, handle, nx, ny, naw, nh, 5760, 11520);
- OS.XFillRectangle(xDisplay, xDrawable, handle, nx + naw2, ny, nw - naw2 * 2, nh);
- OS.XFillArc(xDisplay, xDrawable, handle, nx + nw - naw, ny, naw, nh, 17280, 11520);
- }
- } else {
- if (nh > nah) {
- OS.XFillArc(xDisplay, xDrawable, handle, nx, ny, nw, nah, 0, 11520);
- OS.XFillRectangle(xDisplay, xDrawable, handle, nx, ny + nah2, nw, nh - nah2 * 2);
- OS.XFillArc(xDisplay, xDrawable, handle, nx, ny + nh - nah, nw, nah, 11520, 11520);
- } else {
- OS.XFillArc(xDisplay, xDrawable, handle, nx, ny, nw, nh, 0, 23040);
- }
- }
-}
-char fixMnemonic(char[] text) {
- char mnemonic=0;
- int i=0, j=0;
- while (i < text.length) {
- if ((text [j++] = text [i++]) == '&') {
- if (i == text.length) {continue;}
- if (text [i] == '&') {i++; continue;}
- if (mnemonic == 0) mnemonic = text [i];
- j--;
- }
- }
- while (j < text.length) text [j++] = 0;
- return mnemonic;
-}
-/**
- * Returns the <em>advance width</em> of the specified character in
- * the font which is currently selected into the receiver.
- * <p>
- * The advance width is defined as the horizontal distance the cursor
- * should move after printing the character in the selected font.
- * </p>
- *
- * @param ch the character to measure
- * @return the distance in the x direction to move past the character before painting the next
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getAdvanceWidth(char ch) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FONT);
- int fontList = data.font.handle;
- byte[] charBuffer = Converter.wcsToMbcs(getCodePage (), new char[] { ch }, false);
- int val = charBuffer[0] & 0xFF;
- /* Create a font context to iterate over each element in the font list */
- int[] buffer = new int[1];
- if (!OS.XmFontListInitFontContext(buffer, fontList)) {
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- int context = buffer[0];
- XFontStruct fontStruct = new XFontStruct();
- XCharStruct charStruct = new XCharStruct();
- int fontListEntry;
- int[] fontStructPtr = new int[1];
- int[] fontNamePtr = new int[1];
- /* Go through each entry in the font list. */
- while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer);
- if (buffer[0] == 0) {
- OS.memmove(fontStruct, fontPtr, XFontStruct.sizeof);
- /* FontList contains a single font */
- if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) {
- /* Single byte fontStruct */
- if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) {
- /* The font contains the character */
- int charWidth = 0;
- int perCharPtr = fontStruct.per_char;
- if (perCharPtr == 0) {
- /*
- * If perCharPtr is 0 then all glyphs in the font have
- * the same width as the font's maximum width.
- */
- charWidth = fontStruct.max_bounds_width;
- } else {
- OS.memmove(charStruct, perCharPtr + ((val - fontStruct.min_char_or_byte2) * XCharStruct.sizeof), XCharStruct.sizeof);
- charWidth = charStruct.width;
- }
- if (charWidth != 0) {
- OS.XmFontListFreeFontContext(context);
- return charWidth;
- }
- }
- } else {
- /* Double byte fontStruct */
- int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
- int row = 0;
- if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1;
- int col = charBuffer[0] - fontStruct.min_char_or_byte2;
- if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) {
- /* The font contains the character */
- int charWidth = 0;
- int perCharPtr = fontStruct.per_char;
- if (perCharPtr == 0) {
- /*
- * If perCharPtr is 0 then all glyphs in the font have
- * the same width as the font's maximum width.
- */
- charWidth = fontStruct.max_bounds_width;
- } else {
- int offset = row * charsPerRow + col;
- OS.memmove(charStruct, perCharPtr + offset * XCharStruct.sizeof, XCharStruct.sizeof);
- charWidth = charStruct.width;
- }
- if (charWidth != 0) {
- OS.XmFontListFreeFontContext(context);
- return charWidth;
- }
- }
- }
- } else {
- /* FontList contains a fontSet */
- int nFonts = OS.XFontsOfFontSet(fontPtr, fontStructPtr, fontNamePtr);
- int [] fontStructs = new int[nFonts];
- OS.memmove(fontStructs, fontStructPtr[0], nFonts * 4);
- /* Go through each fontStruct in the font set */
- for (int i = 0; i < nFonts; i++) {
- OS.memmove(fontStruct, fontStructs[i], XFontStruct.sizeof);
- if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) {
- /* Single byte fontStruct */
- if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) {
- /* The font contains the character */
- int charWidth = 0;
- int perCharPtr = fontStruct.per_char;
- if (perCharPtr == 0) {
- /*
- * If perCharPtr is 0 then all glyphs in the font have
- * the same width as the font's maximum width.
- */
- charWidth = fontStruct.max_bounds_width;
- } else {
- OS.memmove(charStruct, perCharPtr + ((val - fontStruct.min_char_or_byte2) * XCharStruct.sizeof), XCharStruct.sizeof);
- charWidth = charStruct.width;
- }
- if (charWidth != 0) {
- OS.XmFontListFreeFontContext(context);
- return charWidth;
- }
- }
- } else {
- /* Double byte fontStruct */
- int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
- int row = 0;
- if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1;
- int col = charBuffer[0] - fontStruct.min_char_or_byte2;
- if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) {
- /* The font contains the character */
- int charWidth = 0;
- int perCharPtr = fontStruct.per_char;
- if (perCharPtr == 0) {
- /*
- * If perCharPtr is 0 then all glyphs in the font have
- * the same width as the font's maximum width.
- */
- charWidth = fontStruct.max_bounds_width;
- } else {
- int offset = row * charsPerRow + col;
- OS.memmove(charStruct, perCharPtr + offset * XCharStruct.sizeof, XCharStruct.sizeof);
- charWidth = charStruct.width;
- }
- if (charWidth != 0) {
- OS.XmFontListFreeFontContext(context);
- return charWidth;
- }
- }
- }
- }
- }
- }
- OS.XmFontListFreeFontContext(context);
- return stringExtent(new String(new char[]{ch})).x;
-}
-/**
- * Returns <code>true</code> if receiver is using the operating system's
- * advanced graphics subsystem. Otherwise, <code>false</code> is returned
- * to indicate that normal graphics are in use.
- * <p>
- * Advanced graphics may not be installed for the operating system. In this
- * case, <code>false</code> is always returned. Some operating system have
- * only one graphics subsystem. If this subsystem supports advanced graphics,
- * then <code>true</code> is always returned. If any graphics operation such
- * as alpha, antialias, patterns, interpolation, paths, clipping or transformation
- * has caused the receiver to switch from regular to advanced graphics mode,
- * <code>true</code> is returned. If the receiver has been explicitly switched
- * to advanced mode and this mode is supported, <code>true</code> is returned.
- * </p>
- *
- * @return the advanced value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public boolean getAdvanced() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.cairo != 0;
-}
-/**
- * Returns the receiver's alpha value. The alpha value
- * is between 0 (transparent) and 255 (opaque).
- *
- * @return the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getAlpha() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.alpha;
-}
-/**
- * Returns the receiver's anti-aliasing setting value, which will be
- * one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code>. Note that this controls anti-aliasing for all
- * <em>non-text drawing</em> operations.
- *
- * @return the anti-aliasing setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getTextAntialias
- *
- * @since 3.1
- */
-public int getAntialias() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.cairo == 0) return SWT.DEFAULT;
- int antialias = Cairo.cairo_get_antialias(data.cairo);
- switch (antialias) {
- case Cairo.CAIRO_ANTIALIAS_DEFAULT: return SWT.DEFAULT;
- case Cairo.CAIRO_ANTIALIAS_NONE: return SWT.OFF;
- case Cairo.CAIRO_ANTIALIAS_GRAY:
- case Cairo.CAIRO_ANTIALIAS_SUBPIXEL: return SWT.ON;
- }
- return SWT.DEFAULT;
-}
-/**
- * Returns the background color.
- *
- * @return the receiver's background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getBackground() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- XColor color = data.background;
- if ((data.state & BACKGROUND_RGB) == 0) {
- OS.XQueryColor(data.display, data.colormap, color);
- data.state |= BACKGROUND_RGB;
- }
- return Color.motif_new(data.device, color);
-}
-/**
- * Returns the background pattern. The default value is
- * <code>null</code>.
- *
- * @return the receiver's background pattern
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Pattern
- *
- * @since 3.1
- */
-public Pattern getBackgroundPattern() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.backgroundPattern;
-}
-/**
- * Returns the width of the specified character in the font
- * selected into the receiver.
- * <p>
- * The width is defined as the space taken up by the actual
- * character, not including the leading and tailing whitespace
- * or overhang.
- * </p>
- *
- * @param ch the character to measure
- * @return the width of the character
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getCharWidth(char ch) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FONT);
- int fontList = data.font.handle;
- byte[] charBuffer = Converter.wcsToMbcs(getCodePage (), new char[] { ch }, false);
- int val = charBuffer[0] & 0xFF;
- /* Create a font context to iterate over each element in the font list */
- int[] buffer = new int[1];
- if (!OS.XmFontListInitFontContext(buffer, fontList)) {
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- int context = buffer[0];
- XFontStruct fontStruct = new XFontStruct();
- XCharStruct charStruct = new XCharStruct();
- int fontListEntry;
- int[] fontStructPtr = new int[1];
- int[] fontNamePtr = new int[1];
- /* Go through each entry in the font list. */
- while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer);
- if (buffer[0] == 0) {
- OS.memmove(fontStruct, fontPtr, XFontStruct.sizeof);
- /* FontList contains a single font */
- if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) {
- /* Single byte fontStruct */
- if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) {
- /* The font contains the character */
- int charWidth = 0;
- int lBearing = 0;
- int rBearing = 0;
- int perCharPtr = fontStruct.per_char;
- if (perCharPtr == 0) {
- /*
- * If perCharPtr is 0 then all glyphs in the font have
- * the same width and left/right bearings as the font.
- */
- charWidth = fontStruct.max_bounds_width;
- lBearing = fontStruct.min_bounds_lbearing;
- rBearing = fontStruct.max_bounds_rbearing;
- } else {
- OS.memmove(charStruct, perCharPtr + ((val - fontStruct.min_char_or_byte2) * XCharStruct.sizeof), XCharStruct.sizeof);
- charWidth = charStruct.width;
- lBearing = charStruct.lbearing;
- rBearing = charStruct.rbearing;
- }
- if (charWidth != 0) {
- OS.XmFontListFreeFontContext(context);
- return rBearing - lBearing;
- }
- }
- } else {
- /* Double byte fontStruct */
- int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
- int row = 0;
- if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1;
- int col = charBuffer[0] - fontStruct.min_char_or_byte2;
- if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) {
- /* The font contains the character */
- int charWidth = 0;
- int lBearing = 0;
- int rBearing = 0;
- int perCharPtr = fontStruct.per_char;
- if (perCharPtr == 0) {
- /*
- * If perCharPtr is 0 then all glyphs in the font have
- * the same width and left/right bearings as the font.
- */
- charWidth = fontStruct.max_bounds_width;
- lBearing = fontStruct.min_bounds_lbearing;
- rBearing = fontStruct.max_bounds_rbearing;
- } else {
- int offset = row * charsPerRow + col;
- OS.memmove(charStruct, perCharPtr + offset * XCharStruct.sizeof, XCharStruct.sizeof);
- charWidth = charStruct.width;
- lBearing = charStruct.lbearing;
- rBearing = charStruct.rbearing;
- }
- if (charWidth != 0) {
- OS.XmFontListFreeFontContext(context);
- return rBearing - lBearing;
- }
- }
- }
- } else {
- /* FontList contains a fontSet */
- int nFonts = OS.XFontsOfFontSet(fontPtr, fontStructPtr, fontNamePtr);
- int [] fontStructs = new int[nFonts];
- OS.memmove(fontStructs, fontStructPtr[0], nFonts * 4);
- /* Go through each fontStruct in the font set */
- for (int i = 0; i < nFonts; i++) {
- OS.memmove(fontStruct, fontStructs[i], XFontStruct.sizeof);
- if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) {
- /* Single byte fontStruct */
- if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) {
- /* The font contains the character */
- int charWidth = 0;
- int lBearing = 0;
- int rBearing = 0;
- int perCharPtr = fontStruct.per_char;
- if (perCharPtr == 0) {
- /*
- * If perCharPtr is 0 then all glyphs in the font have
- * the same width and left/right bearings as the font.
- */
- charWidth = fontStruct.max_bounds_width;
- lBearing = fontStruct.min_bounds_lbearing;
- rBearing = fontStruct.max_bounds_rbearing;
- } else {
- OS.memmove(charStruct, perCharPtr + ((val - fontStruct.min_char_or_byte2) * XCharStruct.sizeof), XCharStruct.sizeof);
- charWidth = charStruct.width;
- lBearing = charStruct.lbearing;
- rBearing = charStruct.rbearing;
- }
- if (charWidth != 0) {
- OS.XmFontListFreeFontContext(context);
- return rBearing - lBearing;
- }
- }
- } else {
- /* Double byte fontStruct */
- int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
- int row = 0;
- if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1;
- int col = charBuffer[0] - fontStruct.min_char_or_byte2;
- if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) {
- /* The font contains the character */
- int charWidth = 0;
- int lBearing = 0;
- int rBearing = 0;
- int perCharPtr = fontStruct.per_char;
- if (perCharPtr == 0) {
- /*
- * If perCharPtr is 0 then all glyphs in the font have
- * the same width and left/right bearings as the font.
- */
- charWidth = fontStruct.max_bounds_width;
- lBearing = fontStruct.min_bounds_lbearing;
- rBearing = fontStruct.max_bounds_rbearing;
- } else {
- int offset = row * charsPerRow + col;
- OS.memmove(charStruct, perCharPtr + offset * XCharStruct.sizeof, XCharStruct.sizeof);
- charWidth = charStruct.width;
- lBearing = charStruct.lbearing;
- rBearing = charStruct.rbearing;
- }
- if (charWidth != 0) {
- OS.XmFontListFreeFontContext(context);
- return rBearing - lBearing;
- }
- }
- }
- }
- }
- }
- OS.XmFontListFreeFontContext(context);
- return stringExtent(new String(new char[]{ch})).x;
-}
-/**
- * Returns the bounding rectangle of the receiver's clipping
- * region. If no clipping region is set, the return value
- * will be a rectangle which covers the entire bounds of the
- * object the receiver is drawing on.
- *
- * @return the bounding rectangle of the clipping region
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getClipping() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- /* Calculate visible bounds in device space */
- int x = 0, y = 0, width = 0, height = 0;
- int[] w = new int[1], h = new int[1], unused = new int[1];
- OS.XGetGeometry(data.display, data.drawable, unused, unused, unused, w, h, unused, unused);
- width = w[0];
- height = h[0];
- /* Intersect visible bounds with clipping in device space and then convert then to user space */
- int cairo = data.cairo;
- int clipRgn = data.clipRgn;
- int damageRgn = data.damageRgn;
- if (clipRgn != 0 || damageRgn != 0 || cairo != 0) {
- int rgn = OS.XCreateRegion ();
- XRectangle rect = new XRectangle();
- rect.width = (short)width;
- rect.height = (short)height;
- OS.XUnionRectWithRegion(rect, rgn, rgn);
- if (damageRgn != 0) {
- OS.XIntersectRegion (damageRgn, rgn, rgn);
- }
- /* Intersect visible bounds with clipping */
- if (clipRgn != 0) {
- /* Convert clipping to device space if needed */
- if (data.clippingTransform != null) {
- clipRgn = convertRgn(clipRgn, data.clippingTransform);
- OS.XIntersectRegion(rgn, clipRgn, rgn);
- OS.XDestroyRegion(clipRgn);
- } else {
- OS.XIntersectRegion(rgn, clipRgn, rgn);
- }
- }
- /* Convert to user space */
- if (cairo != 0) {
- double[] matrix = new double[6];
- Cairo.cairo_get_matrix(cairo, matrix);
- Cairo.cairo_matrix_invert(matrix);
- clipRgn = convertRgn(rgn, matrix);
- OS.XDestroyRegion(rgn);
- rgn = clipRgn;
- }
- OS.XClipBox(rgn, rect);
- OS.XDestroyRegion(rgn);
- x = rect.x;
- y = rect.y;
- width = rect.width;
- height = rect.height;
- }
- return new Rectangle(x, y, width, height);
-}
-/**
- * Sets the region managed by the argument to the current
- * clipping region of the receiver.
- *
- * @param region the region to fill with the clipping region
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the region is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the region is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getClipping(Region region) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int clipping = region.handle;
- OS.XSubtractRegion (clipping, clipping, clipping);
- int /*long*/ cairo = data.cairo;
- int clipRgn = data.clipRgn;
- if (clipRgn == 0) {
- int[] width = new int[1], height = new int[1], unused = new int[1];
- OS.XGetGeometry(data.display, data.drawable, unused, unused, unused, width, height, unused, unused);
- XRectangle rect = new XRectangle();
- rect.x = 0;
- rect.y = 0;
- rect.width = (short)width[0];
- rect.height = (short)height[0];
- OS.XUnionRectWithRegion(rect, clipping, clipping);
- } else {
- /* Convert clipping to device space if needed */
- if (data.clippingTransform != null) {
- int rgn = convertRgn(clipRgn, data.clippingTransform);
- OS.XUnionRegion(clipping, rgn, clipping);
- OS.XDestroyRegion(rgn);
- } else {
- OS.XUnionRegion(clipping, clipRgn, clipping);
- }
- }
- if (data.damageRgn != 0) {
- OS.XIntersectRegion(clipping, data.damageRgn, clipping);
- }
- /* Convert to user space */
- if (cairo != 0) {
- double[] matrix = new double[6];
- Cairo.cairo_get_matrix(cairo, matrix);
- Cairo.cairo_matrix_invert(matrix);
- int rgn = convertRgn(clipping, matrix);
- OS.XSubtractRegion(clipping, clipping, clipping);
- OS.XUnionRegion(clipping, rgn, clipping);
- OS.XDestroyRegion(rgn);
- }
-}
-String getCodePage () {
- return data.font.codePage;
-}
-/**
- * Returns the receiver's fill rule, which will be one of
- * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>.
- *
- * @return the receiver's fill rule
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getFillRule() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- XGCValues values = new XGCValues();
- OS.XGetGCValues(data.display, handle, OS.GCFillRule, values);
- return values.fill_rule == OS.WindingRule ? SWT.FILL_WINDING : SWT.FILL_EVEN_ODD;
-}
-/**
- * Returns the font currently being used by the receiver
- * to draw and measure text.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getFont () {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return Font.motif_new(data.device, data.font.handle);
-}
-int getFontHeight () {
- int fontList = data.font.handle;
- /* Create a font context to iterate over each element in the font list */
- int [] buffer = new int [1];
- if (!OS.XmFontListInitFontContext (buffer, fontList)) {
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- int context = buffer [0];
-
- /* Values discovering during iteration */
- int height = 0;
- XFontStruct fontStruct = new XFontStruct ();
- int fontListEntry;
- int [] fontStructPtr = new int [1];
- int [] fontNamePtr = new int [1];
-
- /* Go through each entry in the font list. */
- while ((fontListEntry = OS.XmFontListNextEntry (context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer);
- if (buffer [0] == 0) {
- /* FontList contains a single font */
- OS.memmove (fontStruct, fontPtr, XFontStruct.sizeof);
- int fontHeight = fontStruct.ascent + fontStruct.descent;
- height = Math.max(height, fontHeight);
- } else {
- /* FontList contains a fontSet */
- int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr);
- int [] fontStructs = new int [nFonts];
- OS.memmove (fontStructs, fontStructPtr [0], nFonts * 4);
-
- /* Go through each fontStruct in the font set */
- for (int i=0; i<nFonts; i++) {
- OS.memmove (fontStruct, fontStructs[i], XFontStruct.sizeof);
- int fontHeight = fontStruct.ascent + fontStruct.descent;
- height = Math.max(height, fontHeight);
- }
- }
- }
-
- OS.XmFontListFreeFontContext (context);
- return height;
-}
-/**
- * Returns a FontMetrics which contains information
- * about the font currently being used by the receiver
- * to draw and measure text.
- *
- * @return font metrics for the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontMetrics getFontMetrics() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FONT);
- int xDisplay = data.display;
- Font font = data.font;
- int fontList = font.handle;
- /* Create a font context to iterate over each element in the font list */
- int[] buffer = new int[1];
- if (!OS.XmFontListInitFontContext(buffer, fontList)) {
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- int context = buffer[0];
- /* Values discovering during iteration */
- int ascent = 0;
- int descent = 0;
- int averageCharWidth = 0, numAverageCharWidth = 0;
- int leading = 0;
- int height = 0;
-
- XFontStruct fontStruct = new XFontStruct();
- int fontListEntry;
- int[] fontStructPtr = new int[1];
- int[] fontNamePtr = new int[1];
- /* Go through each entry in the font list. */
- while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer);
- if (buffer[0] == 0) {
- /* FontList contains a single font */
- OS.memmove(fontStruct, fontPtr, XFontStruct.sizeof);
- ascent = Math.max(ascent, fontStruct.ascent);
- descent = Math.max(descent, fontStruct.descent);
- int fontHeight = fontStruct.ascent + fontStruct.descent;
- height = Math.max(height, fontHeight);
- /* Calculate average character width */
- int propPtr = fontStruct.properties;
- for (int i = 0; i < fontStruct.n_properties; i++) {
- /* Look through properties for XAFONT */
- int[] prop = new int[2];
- OS.memmove(prop, propPtr, 8);
- if (prop[0] == OS.XA_FONT) {
- /* Found it, prop[1] points to the string */
- int ptr = OS.XmGetAtomName(xDisplay, prop[1]);
- int length = OS.strlen(ptr);
- byte[] nameBuf = new byte[length];
- OS.memmove(nameBuf, ptr, length);
- OS.XFree(ptr);
- String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase();
- int avg = 0;
- try {
- avg = FontData.motif_new(xlfd).averageWidth / 10;
- } catch (Exception e) {
- // leave avg unchanged so that it will be computed below
- }
- if (avg == 0) {
- /*
- * Not all fonts have average character width encoded
- * in the xlfd. This one doesn't, so do it the hard
- * way by averaging all the character widths.
- */
- int perCharPtr = fontStruct.per_char;
- if (perCharPtr == 0) {
- /*
- * If perCharPtr is 0 then all glyphs in the font have
- * the same width as the font's maximum width. So no
- * averaging is required.
- */
- averageCharWidth = fontStruct.max_bounds_width;
- } else {
- int sum = 0, count = 0;
- int cols = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
- XCharStruct struct = new XCharStruct();
- for (int index = 0; index < cols; index++) {
- OS.memmove(struct, perCharPtr + (index * XCharStruct.sizeof), XCharStruct.sizeof);
- int w = struct.width;
- if (w != 0) {
- sum += w;
- count++;
- }
- }
- averageCharWidth += sum / count;
- }
- } else {
- /* Average character width was in the xlfd */
- averageCharWidth += avg;
- }
- numAverageCharWidth++;
- break;
- }
- propPtr += 8;
- }
- } else {
- /* FontList contains a fontSet */
- int nFonts = OS.XFontsOfFontSet(fontPtr, fontStructPtr, fontNamePtr);
- int [] fontStructs = new int[nFonts];
- OS.memmove(fontStructs, fontStructPtr[0], nFonts * 4);
- /* Go through each fontStruct in the font set */
- for (int i = 0; i < nFonts; i++) {
- OS.memmove(fontStruct, fontStructs[i], XFontStruct.sizeof);
- ascent = Math.max(ascent, fontStruct.ascent);
- descent = Math.max(descent, fontStruct.descent);
- int fontHeight = fontStruct.ascent + fontStruct.descent;
- height = Math.max(height, fontHeight);
- /* Calculate average character width */
- int propPtr = fontStruct.properties;
- for (int j = 0; j < fontStruct.n_properties; j++) {
- /* Look through properties for XAFONT */
- int[] prop = new int[2];
- OS.memmove(prop, propPtr, 8);
- if (prop[0] == OS.XA_FONT) {
- /* Found it, prop[1] points to the string */
- int ptr = OS.XmGetAtomName(xDisplay, prop[1]);
- int length = OS.strlen(ptr);
- byte[] nameBuf = new byte[length];
- OS.memmove(nameBuf, ptr, length);
- OS.XFree(ptr);
- String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase();
- int avg = 0;
- try {
- avg = FontData.motif_new(xlfd).averageWidth / 10;
- } catch (Exception e) {
- /*
- * Some font servers, for example, xfstt, do not pass
- * reasonable font properties to the client, so we
- * cannot construct a FontData for these. Use the font
- * name instead.
- */
- int[] fontName = new int[1];
- OS.memmove(fontName, fontNamePtr [0] + (i * 4), 4);
- ptr = fontName[0];
- if (ptr != 0 ) {
- length = OS.strlen(ptr);
- nameBuf = new byte[length];
- OS.memmove(nameBuf, ptr, length);
- xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase();
- try {
- avg = FontData.motif_new(xlfd).averageWidth / 10;
- } catch (Exception ex) {
- // leave avg unchanged (0) so that it will be computed below
- }
- }
- }
- if (avg == 0) {
- /*
- * Not all fonts have average character width encoded
- * in the xlfd. This one doesn't, so do it the hard
- * way by averaging all the character widths.
- */
- int perCharPtr = fontStruct.per_char;
- if (perCharPtr == 0) {
- /*
- * If perCharPtr is 0 then all glyphs in the font have
- * the same width as the font's maximum width. So no
- * averaging is required.
- */
- averageCharWidth = fontStruct.max_bounds_width;
- } else {
- int sum = 0, count = 0;
- int cols = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
- XCharStruct struct = new XCharStruct();
- for (int index = 0; index < cols; index++) {
- OS.memmove(struct, perCharPtr + (index * XCharStruct.sizeof), XCharStruct.sizeof);
- int w = struct.width;
- if (w != 0) {
- sum += w;
- count++;
- }
- }
- averageCharWidth += sum / count;
- }
- } else {
- /* Average character width was in the xlfd */
- averageCharWidth += avg;
- }
- numAverageCharWidth++;
- break;
- }
- propPtr += 8;
- }
- }
- }
- }
- OS.XmFontListFreeFontContext(context);
- return FontMetrics.motif_new(ascent, descent, averageCharWidth / numAverageCharWidth, leading, height);
-}
-/**
- * Returns the receiver's foreground color.
- *
- * @return the color used for drawing foreground things
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getForeground() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- XColor color = data.foreground;
- if ((data.state & FOREGROUND_RGB) == 0) {
- OS.XQueryColor(data.display, data.colormap, color);
- data.state |= FOREGROUND_RGB;
- }
- return Color.motif_new(data.device, color);
-}
-/**
- * Returns the foreground pattern. The default value is
- * <code>null</code>.
- *
- * @return the receiver's foreground pattern
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Pattern
- *
- * @since 3.1
- */
-public Pattern getForegroundPattern() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.foregroundPattern;
-}
-/**
- * Returns the GCData.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>GC</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @return the receiver's GCData
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see GCData
- *
- * @since 3.2
- * @noreference This method is not intended to be referenced by clients.
- */
-public GCData getGCData() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data;
-}
-/**
- * Returns the receiver's interpolation setting, which will be one of
- * <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>,
- * <code>SWT.LOW</code> or <code>SWT.HIGH</code>.
- *
- * @return the receiver's interpolation setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getInterpolation() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.interpolation;
-}
-/**
- * Returns the receiver's line attributes.
- *
- * @return the line attributes used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.3
- */
-public LineAttributes getLineAttributes() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float[] dashes = null;
- if (data.lineDashes != null) {
- dashes = new float[data.lineDashes.length];
- System.arraycopy(data.lineDashes, 0, dashes, 0, dashes.length);
- }
- return new LineAttributes(data.lineWidth, data.lineCap, data.lineJoin, data.lineStyle, dashes, data.lineDashesOffset, data.lineMiterLimit);
-}
-/**
- * Returns the receiver's line cap style, which will be one
- * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>,
- * or <code>SWT.CAP_SQUARE</code>.
- *
- * @return the cap style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getLineCap() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineCap;
-}
-/**
- * Returns the receiver's line dash style. The default value is
- * <code>null</code>.
- *
- * @return the line dash style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int[] getLineDash() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineDashes == null) return null;
- int[] lineDashes = new int[data.lineDashes.length];
- for (int i = 0; i < lineDashes.length; i++) {
- lineDashes[i] = (int)data.lineDashes[i];
- }
- return lineDashes;
-}
-/**
- * Returns the receiver's line join style, which will be one
- * of the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>,
- * or <code>SWT.JOIN_BEVEL</code>.
- *
- * @return the join style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getLineJoin() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineJoin;
-}
-/**
- * Returns the receiver's line style, which will be one
- * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
- * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or
- * <code>SWT.LINE_DASHDOTDOT</code>.
- *
- * @return the style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineStyle() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineStyle;
-}
-/**
- * Returns the width that will be used when drawing lines
- * for all of the figure drawing operations (that is,
- * <code>drawLine</code>, <code>drawRectangle</code>,
- * <code>drawPolyline</code>, and so forth.
- *
- * @return the receiver's line width
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineWidth() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (int)data.lineWidth;
-}
-/**
- * Returns the receiver's style information.
- * <p>
- * Note that the value which is returned by this method <em>may
- * not match</em> the value which was provided to the constructor
- * when the receiver was created. This can occur when the underlying
- * operating system does not support a particular combination of
- * requested styles.
- * </p>
- *
- * @return the style bits
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getStyle () {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.style;
-}
-/**
- * Returns the receiver's text drawing anti-aliasing setting value,
- * which will be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code>. Note that this controls anti-aliasing
- * <em>only</em> for text drawing operations.
- *
- * @return the anti-aliasing setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getAntialias
- *
- * @since 3.1
- */
-public int getTextAntialias() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.cairo == 0) return SWT.DEFAULT;
- int /*long*/ options = Cairo.cairo_font_options_create();
- Cairo.cairo_get_font_options(data.cairo, options);
- int antialias = Cairo.cairo_font_options_get_antialias(options);
- Cairo.cairo_font_options_destroy(options);
- switch (antialias) {
- case Cairo.CAIRO_ANTIALIAS_DEFAULT: return SWT.DEFAULT;
- case Cairo.CAIRO_ANTIALIAS_NONE: return SWT.OFF;
- case Cairo.CAIRO_ANTIALIAS_GRAY:
- case Cairo.CAIRO_ANTIALIAS_SUBPIXEL: return SWT.ON;
- }
- return SWT.DEFAULT;
-}
-/**
- * Sets the parameter to the transform that is currently being
- * used by the receiver.
- *
- * @param transform the destination to copy the transform into
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Transform
- *
- * @since 3.1
- */
-public void getTransform(Transform transform) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transform == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- Cairo.cairo_get_matrix(cairo, transform.handle);
- } else {
- transform.setElements(1, 0, 0, 1, 0, 0);
- }
-}
-/**
- * Returns <code>true</code> if this GC is drawing in the mode
- * where the resulting color in the destination is the
- * <em>exclusive or</em> of the color values in the source
- * and the destination, and <code>false</code> if it is
- * drawing in the mode where the destination color is being
- * replaced with the source color value.
- *
- * @return <code>true</code> true if the receiver is in XOR mode, and false otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean getXORMode() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- XGCValues values = new XGCValues ();
- OS.XGetGCValues (data.display, handle, OS.GCFunction, values);
- return values.function == OS.GXxor;
-}
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #equals
- */
-public int hashCode () {
- return handle;
-}
-void init(Drawable drawable, GCData data, int xGC) {
- if (data.foreground != null) data.state &= ~(FOREGROUND | FOREGROUND_RGB);
- if (data.background != null) data.state &= ~(BACKGROUND | BACKGROUND_BG | BACKGROUND_RGB);
- if (data.font != null) data.state &= ~FONT;
- Image image = data.image;
- if (image != null) {
- image.memGC = this;
- /*
- * The transparent pixel mask might change when drawing on
- * the image. Destroy it so that it is regenerated when
- * necessary.
- */
- if (image.transparentPixel != -1) image.destroyMask();
- }
- this.drawable = drawable;
- this.data = data;
- handle = xGC;
-}
-void initCairo() {
- data.device.checkCairo();
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) return;
- int xDisplay = data.display;
- int xDrawable = data.drawable;
- int xVisual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay));
- int[] width = new int[1], height = new int[1], unused = new int[1];
- OS.XGetGeometry(xDisplay, xDrawable, unused, unused, unused, width, height, unused, unused);
- int /*long*/ surface = Cairo.cairo_xlib_surface_create(xDisplay, xDrawable, xVisual, width[0], height[0]);
- if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- data.cairo = cairo = Cairo.cairo_create(surface);
- Cairo.cairo_surface_destroy(surface);
- if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Cairo.cairo_set_fill_rule(cairo, Cairo.CAIRO_FILL_RULE_EVEN_ODD);
- data.state &= ~(BACKGROUND | FOREGROUND | FONT | LINE_WIDTH | LINE_CAP | LINE_JOIN | LINE_STYLE | DRAW_OFFSET);
- setCairoClip(data.damageRgn, data.clipRgn);
-}
-/**
- * Returns <code>true</code> if the receiver has a clipping
- * region set into it, and <code>false</code> otherwise.
- * If this method returns false, the receiver will draw on all
- * available space in the destination. If it returns true,
- * it will draw only in the area that is covered by the region
- * that can be accessed with <code>getClipping(region)</code>.
- *
- * @return <code>true</code> if the GC has a clipping region, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean isClipped() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.clipRgn != 0;
-}
-/**
- * Returns <code>true</code> if the GC has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the GC.
- * When a GC has been disposed, it is an error to
- * invoke any other method using the GC.
- *
- * @return <code>true</code> when the GC is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-boolean isIdentity(double[] matrix) {
- if (matrix == null) return true;
- return matrix[0] == 1 && matrix[1] == 0 && matrix[2] == 0 && matrix[3] == 1 && matrix[4] == 0 && matrix[5] == 0;
-}
-/**
- * Sets the receiver to always use the operating system's advanced graphics
- * subsystem for all graphics operations if the argument is <code>true</code>.
- * If the argument is <code>false</code>, the advanced graphics subsystem is
- * no longer used, advanced graphics state is cleared and the normal graphics
- * subsystem is used from now on.
- * <p>
- * Normally, the advanced graphics subsystem is invoked automatically when
- * any one of the alpha, antialias, patterns, interpolation, paths, clipping
- * or transformation operations in the receiver is requested. When the receiver
- * is switched into advanced mode, the advanced graphics subsystem performs both
- * advanced and normal graphics operations. Because the two subsystems are
- * different, their output may differ. Switching to advanced graphics before
- * any graphics operations are performed ensures that the output is consistent.
- * </p><p>
- * Advanced graphics may not be installed for the operating system. In this
- * case, this operation does nothing. Some operating system have only one
- * graphics subsystem, so switching from normal to advanced graphics does
- * nothing. However, switching from advanced to normal graphics will always
- * clear the advanced graphics state, even for operating systems that have
- * only one graphics subsystem.
- * </p>
- *
- * @param advanced the new advanced graphics state
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAlpha
- * @see #setAntialias
- * @see #setBackgroundPattern
- * @see #setClipping(Path)
- * @see #setForegroundPattern
- * @see #setLineAttributes
- * @see #setInterpolation
- * @see #setTextAntialias
- * @see #setTransform
- * @see #getAdvanced
- *
- * @since 3.1
- */
-public void setAdvanced(boolean advanced) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (advanced && data.cairo != 0) return;
- if (advanced) {
- try {
- initCairo();
- } catch (SWTException e) {}
- } else {
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) Cairo.cairo_destroy(cairo);
- data.cairo = 0;
- data.interpolation = SWT.DEFAULT;
- data.backgroundPattern = data.foregroundPattern = null;
- data.state = 0;
- setClipping(0);
- }
-}
-/**
- * Sets the receiver's alpha value which must be
- * between 0 (transparent) and 255 (opaque).
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param alpha the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setAlpha(int alpha) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.cairo == 0 && (alpha & 0xff) == 0xff) return;
- initCairo();
- data.alpha = alpha & 0xff;
- data.state &= ~(BACKGROUND | FOREGROUND | BACKGROUND_BG);
-}
-/**
- * Sets the receiver's anti-aliasing value to the parameter,
- * which must be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code>
- * or <code>SWT.ON</code>. Note that this controls anti-aliasing for all
- * <em>non-text drawing</em> operations.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param antialias the anti-aliasing setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.OFF</code> or <code>SWT.ON</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- * @see #setTextAntialias
- *
- * @since 3.1
- */
-public void setAntialias(int antialias) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.cairo == 0 && antialias == SWT.DEFAULT) return;
- int mode = 0;
- switch (antialias) {
- case SWT.DEFAULT: mode = Cairo.CAIRO_ANTIALIAS_DEFAULT; break;
- case SWT.OFF: mode = Cairo.CAIRO_ANTIALIAS_NONE; break;
- case SWT.ON: mode = Cairo.CAIRO_ANTIALIAS_GRAY;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- initCairo();
- int /*long*/ cairo = data.cairo;
- Cairo.cairo_set_antialias(cairo, mode);
-}
-/**
- * Invokes platform specific functionality to allocate a new graphics context.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>GC</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param drawable the Drawable for the receiver.
- * @param data the data for the receiver.
- *
- * @return a new <code>GC</code>
- */
-public static GC motif_new(Drawable drawable, GCData data) {
- GC gc = new GC();
- int xGC = drawable.internal_new_GC(data);
- gc.device = data.device;
- gc.init(drawable, data, xGC);
- return gc;
-}
-/**
- * Invokes platform specific functionality to wrap a graphics context.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>GC</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param xGC the X Windows graphics context.
- * @param data the data for the receiver.
- *
- * @return a new <code>GC</code>
- */
-public static GC motif_new(int xGC, GCData data) {
- GC gc = new GC();
- gc.device = data.device;
- gc.init(null, data, xGC);
- return gc;
-}
-/**
- * Sets the background color. The background color is used
- * for fill operations and as the background color when text
- * is drawn.
- *
- * @param color the new background color for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setBackground (Color color) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.background = color.handle;
- data.backgroundPattern = null;
- data.state &= ~(BACKGROUND | BACKGROUND_BG);
- data.state |= BACKGROUND_RGB;
-}
-/**
- * Sets the background pattern. The default value is <code>null</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param pattern the new background pattern
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Pattern
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setBackgroundPattern(Pattern pattern) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.cairo == 0 && pattern == null) return;
- initCairo();
- if (data.backgroundPattern == pattern) return;
- data.backgroundPattern = pattern;
- data.state &= ~BACKGROUND;
-}
-static void setCairoFont(int /*long*/ cairo, Font font) {
- //TODO - use X font instead of loading new one???
- FontData[] fds = font.getFontData();
- FontData fd = fds[0];
- int style = fd.getStyle();
- int slant = Cairo.CAIRO_FONT_SLANT_NORMAL;
- if ((style & SWT.ITALIC) != 0) slant = Cairo.CAIRO_FONT_SLANT_ITALIC;
- int weight = Cairo.CAIRO_FONT_WEIGHT_NORMAL;
- if ((style & SWT.BOLD) != 0) weight = Cairo.CAIRO_FONT_WEIGHT_BOLD;
- String name = fd.getName();
- int index = name.indexOf('-');
- if (index != -1) name = name.substring(index + 1);
- byte[] buffer = Converter.wcsToMbcs(null, name, true);
- Cairo.cairo_select_font_face(cairo, buffer, slant, weight);
- Cairo.cairo_set_font_size(cairo, fd.getHeight());
-}
-static void setCairoRegion(int /*long*/ cairo, int /*long*/ rgn) {
- //TODO - get rectangles from region instead of clip box
- XRectangle rect = new XRectangle();
- OS.XClipBox(rgn, rect);
- Cairo.cairo_rectangle(cairo, rect.x, rect.y, rect.width, rect.height);
-}
-static void setCairoPatternColor(int /*long*/ pattern, int offset, Color c, int alpha) {
- XColor color = c.handle;
- double aa = (alpha & 0xFF) / (double)0xFF;
- double red = ((color.red & 0xFFFF) / (double)0xFFFF);
- double green = ((color.green & 0xFFFF) / (double)0xFFFF);
- double blue = ((color.blue & 0xFFFF) / (double)0xFFFF);
- Cairo.cairo_pattern_add_color_stop_rgba(pattern, offset, red, green, blue, aa);
-}
-void setCairoClip(int /*long*/ damageRgn, int /*long*/ clipRgn) {
- int /*long*/ cairo = data.cairo;
- Cairo.cairo_reset_clip(cairo);
- if (damageRgn != 0) {
- double[] matrix = new double[6];
- Cairo.cairo_get_matrix(cairo, matrix);
- Cairo.cairo_identity_matrix(cairo);
- setCairoRegion(cairo, damageRgn);
- Cairo.cairo_clip(cairo);
- Cairo.cairo_set_matrix(cairo, matrix);
- }
- if (clipRgn != 0) {
- setCairoRegion(cairo, clipRgn);
- Cairo.cairo_clip(cairo);
- }
-}
-void setClipping(int clipRgn) {
- int /*long*/ cairo = data.cairo;
- if (clipRgn == 0) {
- if (data.clipRgn != 0) {
- OS.XDestroyRegion (data.clipRgn);
- data.clipRgn = 0;
- }
- if (cairo != 0) {
- data.clippingTransform = null;
- setCairoClip(data.damageRgn, 0);
- } else {
- if (data.damageRgn == 0) {
- OS.XSetClipMask (data.display, handle, OS.None);
- } else {
- OS.XSetRegion (data.display, handle, data.damageRgn);
- }
- }
- } else {
- if (data.clipRgn == 0) data.clipRgn = OS.XCreateRegion ();
- OS.XSubtractRegion (data.clipRgn, data.clipRgn, data.clipRgn);
- OS.XUnionRegion (clipRgn, data.clipRgn, data.clipRgn);
- if (cairo != 0) {
- if (data.clippingTransform == null) data.clippingTransform = new double[6];
- Cairo.cairo_get_matrix(cairo, data.clippingTransform);
- setCairoClip(data.damageRgn, clipRgn);
- } else {
- int clipping = clipRgn;
- if (data.damageRgn != 0) {
- clipping = OS.XCreateRegion();
- OS.XUnionRegion(clipping, clipRgn, clipping);
- OS.XIntersectRegion(clipping, data.damageRgn, clipping);
- }
- OS.XSetRegion (data.display, handle, clipping);
- if (clipping != clipRgn) OS.XDestroyRegion(clipping);
- }
- }
-}
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the rectangular area specified
- * by the arguments.
- *
- * @param x the x coordinate of the clipping rectangle
- * @param y the y coordinate of the clipping rectangle
- * @param width the width of the clipping rectangle
- * @param height the height of the clipping rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- XRectangle rect = new XRectangle ();
- rect.x = (short) x;
- rect.y = (short) y;
- rect.width = (short) Math.max (0, width);
- rect.height = (short) Math.max (0, height);
- int clipRgn = OS.XCreateRegion();
- OS.XUnionRectWithRegion(rect, clipRgn, clipRgn);
- setClipping(clipRgn);
- OS.XDestroyRegion(clipRgn);
-}
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the path specified
- * by the argument.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the clipping path.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the path has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setClipping(Path path) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path != null && path.isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- setClipping(0);
- if (path != null) {
- initCairo();
- int /*long*/ cairo = data.cairo;
- int /*long*/ copy = Cairo.cairo_copy_path(path.handle);
- if (copy == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Cairo.cairo_append_path(cairo, copy);
- Cairo.cairo_path_destroy(copy);
- Cairo.cairo_clip(cairo);
- Cairo.cairo_new_path(cairo);
- }
-}
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the rectangular area specified
- * by the argument. Specifying <code>null</code> for the
- * rectangle reverts the receiver's clipping area to its
- * original value.
- *
- * @param rect the clipping rectangle or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping (Rectangle rect) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) {
- setClipping(0);
- } else {
- setClipping (rect.x, rect.y, rect.width, rect.height);
- }
-}
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the region specified
- * by the argument. Specifying <code>null</code> for the
- * region reverts the receiver's clipping area to its
- * original value.
- *
- * @param region the clipping region or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping (Region region) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region != null && region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- setClipping(region != null ? region.handle : 0);
-}
-/**
- * Sets the receiver's fill rule to the parameter, which must be one of
- * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>.
- *
- * @param rule the new fill rule
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of <code>SWT.FILL_EVEN_ODD</code>
- * or <code>SWT.FILL_WINDING</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setFillRule(int rule) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int mode = OS.EvenOddRule, cairo_mode = Cairo.CAIRO_FILL_RULE_EVEN_ODD;
- switch (rule) {
- case SWT.FILL_WINDING:
- mode = OS.WindingRule; cairo_mode = Cairo.CAIRO_FILL_RULE_WINDING; break;
- case SWT.FILL_EVEN_ODD:
- mode = OS.EvenOddRule; cairo_mode = Cairo.CAIRO_FILL_RULE_EVEN_ODD; break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- OS.XSetFillRule(data.display, handle, mode);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- Cairo.cairo_set_fill_rule(cairo, cairo_mode);
- }
-}
-/**
- * Sets the font which will be used by the receiver
- * to draw and measure text to the argument. If the
- * argument is null, then a default font appropriate
- * for the platform will be used instead.
- *
- * @param font the new font for the receiver, or null to indicate a default font
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setFont (Font font) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.font = font != null ? font : data.device.systemFont;
- data.state &= ~FONT;
- if (data.renderTable != 0) OS.XmRenderTableFree(data.renderTable);
- data.renderTable = 0;
- data.stringWidth = data.stringHeight = data.textWidth = data.textHeight = -1;
-}
-/**
- * Sets the foreground color. The foreground color is used
- * for drawing operations including when text is drawn.
- *
- * @param color the new foreground color for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setForeground (Color color) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.foreground = color.handle;
- data.foregroundPattern = null;
- data.state &= ~FOREGROUND;
- data.state |= FOREGROUND_RGB;
-}
-/**
- * Sets the foreground pattern. The default value is <code>null</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param pattern the new foreground pattern
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Pattern
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setForegroundPattern(Pattern pattern) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.cairo == 0 && pattern == null) return;
- initCairo();
- if (data.foregroundPattern == pattern) return;
- data.foregroundPattern = pattern;
- data.state &= ~FOREGROUND;
-}
-/**
- * Sets the receiver's interpolation setting to the parameter, which
- * must be one of <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>,
- * <code>SWT.LOW</code> or <code>SWT.HIGH</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param interpolation the new interpolation setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.NONE</code>, <code>SWT.LOW</code> or <code>SWT.HIGH</code>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setInterpolation(int interpolation) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.cairo == 0 && interpolation == SWT.DEFAULT) return;
- switch (interpolation) {
- case SWT.DEFAULT:
- case SWT.NONE:
- case SWT.LOW:
- case SWT.HIGH:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- initCairo();
- data.interpolation = interpolation;
-}
-/**
- * Sets the receiver's line attributes.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param attributes the line attributes
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the attributes is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if any of the line attributes is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see LineAttributes
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.3
- */
-public void setLineAttributes(LineAttributes attributes) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (attributes == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int mask = 0;
- float lineWidth = attributes.width;
- if (lineWidth != data.lineWidth) {
- mask |= LINE_WIDTH | DRAW_OFFSET;
- }
- int lineStyle = attributes.style;
- if (lineStyle != data.lineStyle) {
- mask |= LINE_STYLE;
- switch (lineStyle) {
- case SWT.LINE_SOLID:
- case SWT.LINE_DASH:
- case SWT.LINE_DOT:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- break;
- case SWT.LINE_CUSTOM:
- if (attributes.dash == null) lineStyle = SWT.LINE_SOLID;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- int join = attributes.join;
- if (join != data.lineJoin) {
- mask |= LINE_JOIN;
- switch (join) {
- case SWT.CAP_ROUND:
- case SWT.CAP_FLAT:
- case SWT.CAP_SQUARE:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- int cap = attributes.cap;
- if (cap != data.lineCap) {
- mask |= LINE_CAP;
- switch (cap) {
- case SWT.JOIN_MITER:
- case SWT.JOIN_ROUND:
- case SWT.JOIN_BEVEL:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- float[] dashes = attributes.dash;
- float[] lineDashes = data.lineDashes;
- if (dashes != null && dashes.length > 0) {
- boolean changed = lineDashes == null || lineDashes.length != dashes.length;
- for (int i = 0; i < dashes.length; i++) {
- float dash = dashes[i];
- if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (!changed && lineDashes[i] != dash) changed = true;
- }
- if (changed) {
- float[] newDashes = new float[dashes.length];
- System.arraycopy(dashes, 0, newDashes, 0, dashes.length);
- dashes = newDashes;
- mask |= LINE_STYLE;
- } else {
- dashes = lineDashes;
- }
- } else {
- if (lineDashes != null && lineDashes.length > 0) {
- mask |= LINE_STYLE;
- } else {
- dashes = lineDashes;
- }
- }
- float dashOffset = attributes.dashOffset;
- if (dashOffset != data.lineDashesOffset) {
- mask |= LINE_STYLE;
- }
- float miterLimit = attributes.miterLimit;
- if (miterLimit != data.lineMiterLimit) {
- mask |= LINE_MITERLIMIT;
- }
- initCairo();
- if (mask == 0) return;
- data.lineWidth = lineWidth;
- data.lineStyle = lineStyle;
- data.lineCap = cap;
- data.lineJoin = join;
- data.lineDashes = dashes;
- data.lineDashesOffset = dashOffset;
- data.lineMiterLimit = miterLimit;
- data.state &= ~mask;
-}
-/**
- * Sets the receiver's line cap style to the argument, which must be one
- * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>,
- * or <code>SWT.CAP_SQUARE</code>.
- *
- * @param cap the cap style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineCap(int cap) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineCap == cap) return;
- switch (cap) {
- case SWT.CAP_ROUND:
- case SWT.CAP_FLAT:
- case SWT.CAP_SQUARE:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineCap = cap;
- data.state &= ~LINE_CAP;
-}
-/**
- * Sets the receiver's line dash style to the argument. The default
- * value is <code>null</code>. If the argument is not <code>null</code>,
- * the receiver's line style is set to <code>SWT.LINE_CUSTOM</code>, otherwise
- * it is set to <code>SWT.LINE_SOLID</code>.
- *
- * @param dashes the dash style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if any of the values in the array is less than or equal 0</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineDash(int[] dashes) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float[] lineDashes = data.lineDashes;
- if (dashes != null && dashes.length > 0) {
- boolean changed = data.lineStyle != SWT.LINE_CUSTOM || lineDashes == null || lineDashes.length != dashes.length;
- for (int i = 0; i < dashes.length; i++) {
- int dash = dashes[i];
- if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (!changed && lineDashes[i] != dash) changed = true;
- }
- if (!changed) return;
- data.lineDashes = new float[dashes.length];
- for (int i = 0; i < dashes.length; i++) {
- data.lineDashes[i] = dashes[i];
- }
- data.lineStyle = SWT.LINE_CUSTOM;
- } else {
- if (data.lineStyle == SWT.LINE_SOLID && (lineDashes == null || lineDashes.length == 0)) return;
- data.lineDashes = null;
- data.lineStyle = SWT.LINE_SOLID;
- }
- data.state &= ~LINE_STYLE;
-}
-/**
- * Sets the receiver's line join style to the argument, which must be one
- * of the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>,
- * or <code>SWT.JOIN_BEVEL</code>.
- *
- * @param join the join style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineJoin(int join) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineJoin == join) return;
- switch (join) {
- case SWT.JOIN_MITER:
- case SWT.JOIN_ROUND:
- case SWT.JOIN_BEVEL:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineJoin = join;
- data.state &= ~LINE_JOIN;
-}
-/**
- * Sets the receiver's line style to the argument, which must be one
- * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
- * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or
- * <code>SWT.LINE_DASHDOTDOT</code>.
- *
- * @param lineStyle the style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setLineStyle(int lineStyle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineStyle == lineStyle) return;
- switch (lineStyle) {
- case SWT.LINE_SOLID:
- case SWT.LINE_DASH:
- case SWT.LINE_DOT:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- break;
- case SWT.LINE_CUSTOM:
- if (data.lineDashes == null) lineStyle = SWT.LINE_SOLID;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineStyle = lineStyle;
- data.state &= ~LINE_STYLE;
-}
-/**
- * Sets the width that will be used when drawing lines
- * for all of the figure drawing operations (that is,
- * <code>drawLine</code>, <code>drawRectangle</code>,
- * <code>drawPolyline</code>, and so forth.
- * <p>
- * Note that line width of zero is used as a hint to
- * indicate that the fastest possible line drawing
- * algorithms should be used. This means that the
- * output may be different from line width one.
- * </p>
- *
- * @param lineWidth the width of a line
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setLineWidth(int lineWidth) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineWidth == lineWidth) return;
- data.lineWidth = lineWidth;
- data.state &= ~(LINE_WIDTH | DRAW_OFFSET);
-}
-void setString(String string) {
- if (string == data.string) return;
- if (data.xmString != 0) OS.XmStringFree(data.xmString);
- byte[] buffer = Converter.wcsToMbcs(getCodePage (), string, true);
- data.xmString = OS.XmStringCreate(buffer, OS.XmFONTLIST_DEFAULT_TAG);
- data.string = string;
- data.stringWidth = data.stringHeight = -1;
-}
-void setText(String string, int flags) {
- if (data.renderTable == 0) createRenderTable();
- if (string == data.text && (flags & ~SWT.DRAW_TRANSPARENT) == (data.drawFlags & ~SWT.DRAW_TRANSPARENT)) {
- return;
- }
- if (data.xmText != 0) OS.XmStringFree(data.xmText);
- if (data.xmMnemonic != 0) OS.XmStringFree(data.xmMnemonic);
- char mnemonic = 0;
- int tableLength = 0;
- Device device = data.device;
- int[] parseTable = new int[2];
- char[] text = new char[string.length()];
- string.getChars(0, text.length, text, 0);
- if ((flags & SWT.DRAW_DELIMITER) != 0) parseTable[tableLength++] = device.crMapping;
- if ((flags & SWT.DRAW_TAB) != 0) parseTable[tableLength++] = device.tabMapping;
- if ((flags & SWT.DRAW_MNEMONIC) != 0) mnemonic = fixMnemonic(text);
- String codePage = getCodePage();
- byte[] buffer = Converter.wcsToMbcs(codePage, text, true);
- data.xmText = OS.XmStringParseText(buffer, 0, OS.XmFONTLIST_DEFAULT_TAG, OS.XmCHARSET_TEXT, parseTable, tableLength, 0);
- if (mnemonic != 0) {
- byte [] buffer1 = Converter.wcsToMbcs(codePage, new char[]{mnemonic}, true);
- data.xmMnemonic = OS.XmStringCreate (buffer1, OS.XmFONTLIST_DEFAULT_TAG);
- } else {
- data.xmMnemonic = 0;
- }
- data.text = string;
- data.textWidth = data.textHeight = -1;
- data.drawFlags = flags;
-}
-/**
- * Sets the receiver's text anti-aliasing value to the parameter,
- * which must be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code>
- * or <code>SWT.ON</code>. Note that this controls anti-aliasing only
- * for all <em>text drawing</em> operations.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param antialias the anti-aliasing setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.OFF</code> or <code>SWT.ON</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- * @see #setAntialias
- *
- * @since 3.1
- */
-public void setTextAntialias(int antialias) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.cairo == 0 && antialias == SWT.DEFAULT) return;
- int mode = 0;
- switch (antialias) {
- case SWT.DEFAULT: mode = Cairo.CAIRO_ANTIALIAS_DEFAULT; break;
- case SWT.OFF: mode = Cairo.CAIRO_ANTIALIAS_NONE; break;
- case SWT.ON: mode = Cairo.CAIRO_ANTIALIAS_GRAY;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- initCairo();
- int /*long*/ options = Cairo.cairo_font_options_create();
- Cairo.cairo_font_options_set_antialias(options, mode);
- Cairo.cairo_set_font_options(data.cairo, options);
- Cairo.cairo_font_options_destroy(options);
-}
-/**
- * Sets the transform that is currently being used by the receiver. If
- * the argument is <code>null</code>, the current transform is set to
- * the identity transform.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param transform the transform to set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Transform
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setTransform(Transform transform) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transform != null && transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.cairo == 0 && transform == null) return;
- initCairo();
- int /*long*/ cairo = data.cairo;
- if (transform != null) {
- Cairo.cairo_set_matrix(cairo, transform.handle);
- } else {
- Cairo.cairo_identity_matrix(cairo);
- }
- data.state &= ~DRAW_OFFSET;
-}
-/**
- * If the argument is <code>true</code>, puts the receiver
- * in a drawing mode where the resulting color in the destination
- * is the <em>exclusive or</em> of the color values in the source
- * and the destination, and if the argument is <code>false</code>,
- * puts the receiver in a drawing mode where the destination color
- * is replaced with the source color value.
- * <p>
- * Note that this mode in fundamentally unsupportable on certain
- * platforms, notably Carbon (Mac OS X). Clients that want their
- * code to run on all platforms need to avoid this method.
- * </p>
- *
- * @param xor if <code>true</code>, then <em>xor</em> mode is used, otherwise <em>source copy</em> mode is used
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @deprecated this functionality is not supported on some platforms
- */
-public void setXORMode(boolean xor) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.XSetFunction(data.display, handle, xor ? OS.GXxor : OS.GXcopy);
-}
-/**
- * Returns the extent of the given string. No tab
- * expansion or carriage return processing will be performed.
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point stringExtent(String string) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- checkGC(FONT);
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
- cairo_font_extents_t font_extents = new cairo_font_extents_t();
- Cairo.cairo_font_extents(cairo, font_extents);
- cairo_text_extents_t extents = new cairo_text_extents_t();
- Cairo.cairo_text_extents(cairo, buffer, extents);
- return new Point((int)extents.width, (int)font_extents.height);
- }
- setString(string);
- checkGC(FONT);
- if (data.stringWidth != -1) return new Point(data.stringWidth, data.stringHeight);
- int width, height;
- if (string.length() == 0) {
- width = 0;
- height = getFontHeight();
- } else {
- int fontList = data.font.handle;
- int xmString = data.xmString;
- width = OS.XmStringWidth(fontList, xmString);
- height = OS.XmStringHeight(fontList, xmString);
- }
- return new Point(data.stringWidth = width, data.stringHeight = height);
-}
-/**
- * Returns the extent of the given string. Tab expansion and
- * carriage return processing are performed.
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point textExtent(String string) {
- return textExtent(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
-}
-/**
- * Returns the extent of the given string. Tab expansion, line
- * delimiter and mnemonic processing are performed according to
- * the specified flags, which can be a combination of:
- * <dl>
- * <dt><b>DRAW_DELIMITER</b></dt>
- * <dd>draw multiple lines</dd>
- * <dt><b>DRAW_TAB</b></dt>
- * <dd>expand tabs</dd>
- * <dt><b>DRAW_MNEMONIC</b></dt>
- * <dd>underline the mnemonic character</dd>
- * <dt><b>DRAW_TRANSPARENT</b></dt>
- * <dd>transparent background</dd>
- * </dl>
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @param flags the flags specifying how to process the text
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point textExtent(String string, int flags) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- //TODO - honor flags
- checkGC(FONT);
- byte[] buffer = Converter.wcsToMbcs(null, string, true);
- cairo_font_extents_t font_extents = new cairo_font_extents_t();
- Cairo.cairo_font_extents(cairo, font_extents);
- cairo_text_extents_t extents = new cairo_text_extents_t();
- Cairo.cairo_text_extents(cairo, buffer, extents);
- return new Point((int)extents.width, (int)font_extents.height);
- }
- setText(string, flags);
- checkGC(FONT);
- if (data.textWidth != -1) return new Point(data.textWidth, data.textHeight);
- int width, height;
- if (string.length() == 0) {
- width = 0;
- height = getFontHeight();
- } else {
- int fontList = data.font.handle;
- int xmText = data.xmText;
- width = OS.XmStringWidth(fontList, xmText);
- height = OS.XmStringHeight(fontList, xmText);
- }
- return new Point(data.textWidth = width, data.textHeight = height);
-}
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "GC {*DISPOSED*}";
- return "GC {" + handle + "}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GCData.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GCData.java
deleted file mode 100755
index 8d6836cd9a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GCData.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.motif.*;
-
-/**
- * Instances of this class are descriptions of GCs in terms
- * of unallocated platform-specific data fields.
- * <p>
- * <b>IMPORTANT:</b> This class is <em>not</em> part of the public
- * API for SWT. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms, and should never be called from application code.
- * </p>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noinstantiate This class is not intended to be instantiated by clients.
- */
-public final class GCData {
- public Device device;
- public int style, state = -1;
- public XColor foreground;
- public XColor background;
- public Pattern foregroundPattern;
- public Pattern backgroundPattern;
- public Font font;
- public int clipRgn;
- public int lineStyle = SWT.LINE_SOLID;
- public float lineWidth;
- public int lineCap = SWT.CAP_FLAT;
- public int lineJoin = SWT.JOIN_MITER;
- public float[] lineDashes;
- public float lineDashesOffset;
- public float lineMiterLimit = 10;
- public int alpha = 0xFF;
- public int interpolation = SWT.DEFAULT;
-
- public int renderTable;
- public int damageRgn;
- public int colormap;
- public Image backgroundImage;
- public Image image;
- public int display;
- public int drawable;
- public int /*long*/ cairo;
- public double cairoXoffset, cairoYoffset;
- public double[] clippingTransform;
- public String string;
- public int stringWidth = -1;
- public int stringHeight = -1;
- public int xmString;
- public String text;
- public int textWidth = -1;
- public int textHeight = -1;
- public int xmText, xmMnemonic;
- public int drawFlags;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java
deleted file mode 100755
index 6aa4d87995..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java
+++ /dev/null
@@ -1,1429 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.cairo.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import java.io.*;
-
-/**
- * Instances of this class are graphics which have been prepared
- * for display on a specific device. That is, they are ready
- * to paint using methods such as <code>GC.drawImage()</code>
- * and display on widgets with, for example, <code>Button.setImage()</code>.
- * <p>
- * If loaded from a file format that supports it, an
- * <code>Image</code> may have transparency, meaning that certain
- * pixels are specified as being transparent when drawn. Examples
- * of file formats that support transparency are GIF and PNG.
- * </p><p>
- * There are two primary ways to use <code>Images</code>.
- * The first is to load a graphic file from disk and create an
- * <code>Image</code> from it. This is done using an <code>Image</code>
- * constructor, for example:
- * <pre>
- * Image i = new Image(device, "C:\\graphic.bmp");
- * </pre>
- * A graphic file may contain a color table specifying which
- * colors the image was intended to possess. In the above example,
- * these colors will be mapped to the closest available color in
- * SWT. It is possible to get more control over the mapping of
- * colors as the image is being created, using code of the form:
- * <pre>
- * ImageData data = new ImageData("C:\\graphic.bmp");
- * RGB[] rgbs = data.getRGBs();
- * // At this point, rgbs contains specifications of all
- * // the colors contained within this image. You may
- * // allocate as many of these colors as you wish by
- * // using the Color constructor Color(RGB), then
- * // create the image:
- * Image i = new Image(device, data);
- * </pre>
- * <p>
- * Applications which require even greater control over the image
- * loading process should use the support provided in class
- * <code>ImageLoader</code>.
- * </p><p>
- * Application code must explicitly invoke the <code>Image.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see Color
- * @see ImageData
- * @see ImageLoader
- * @see <a href="http://www.eclipse.org/swt/snippets/#image">Image snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, ImageAnalyzer</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Image extends Resource implements Drawable {
- /**
- * specifies whether the receiver is a bitmap or an icon
- * (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int type;
-
- /**
- * The handle to the OS pixmap resource.
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int pixmap;
-
- /**
- * The handle to the OS mask resource.
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int mask;
-
- int /*long*/ surface;
-
- /**
- * specifies the transparent pixel
- */
- int transparentPixel = -1;
-
- /**
- * The GC the image is currently selected in.
- */
- GC memGC;
-
- /**
- * The alpha data of the image.
- */
- byte[] alphaData;
-
- /**
- * The global alpha value to be used for every pixel.
- */
- int alpha = -1;
-
- /**
- * The width of the image.
- */
- int width = -1;
-
- /**
- * The height of the image.
- */
- int height = -1;
-
- /**
- * Specifies the default scanline padding.
- */
- static final int DEFAULT_SCANLINE_PAD = 4;
-
-Image(Device device) {
- super(device);
-}
-/**
- * Constructs an empty instance of this class with the
- * specified width and height. The result may be drawn upon
- * by creating a GC and using any of its drawing operations,
- * as shown in the following example:
- * <pre>
- * Image i = new Image(device, width, height);
- * GC gc = new GC(i);
- * gc.drawRectangle(0, 0, 50, 50);
- * gc.dispose();
- * </pre>
- * <p>
- * Note: Some platforms may have a limitation on the size
- * of image that can be created (size depends on width, height,
- * and depth). For example, Windows 95, 98, and ME do not allow
- * images larger than 16M.
- * </p>
- *
- * @param device the device on which to create the image
- * @param width the width of the new image
- * @param height the height of the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - if either the width or height is negative or zero</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, int width, int height) {
- super(device);
- init(width, height);
- init();
-}
-/**
- * Constructs a new instance of this class based on the
- * provided image, with an appearance that varies depending
- * on the value of the flag. The possible flag values are:
- * <dl>
- * <dt><b>{@link SWT#IMAGE_COPY}</b></dt>
- * <dd>the result is an identical copy of srcImage</dd>
- * <dt><b>{@link SWT#IMAGE_DISABLE}</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>disabled</em> look</dd>
- * <dt><b>{@link SWT#IMAGE_GRAY}</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>gray scale</em> look</dd>
- * </dl>
- *
- * @param device the device on which to create the image
- * @param srcImage the image to use as the source
- * @param flag the style, either <code>IMAGE_COPY</code>, <code>IMAGE_DISABLE</code> or <code>IMAGE_GRAY</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if srcImage is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the flag is not one of <code>IMAGE_COPY</code>, <code>IMAGE_DISABLE</code> or <code>IMAGE_GRAY</code></li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon, or is otherwise in an invalid state</li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the image is not supported</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, Image srcImage, int flag) {
- super(device);
- device = this.device;
- if (srcImage == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (srcImage.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int xDisplay = device.xDisplay;
- this.type = srcImage.type;
- this.mask = 0;
- int[] unused = new int[1];
- int[] w = new int[1];
- int[] h = new int[1];
- OS.XGetGeometry(xDisplay, srcImage.pixmap, unused, unused, unused, w, h, unused, unused);
- int width = w[0];
- int height = h[0];
- int drawable = OS.XDefaultRootWindow(xDisplay);
- /* Don't create the mask here if flag is SWT.IMAGE_GRAY. See below.*/
- if (flag != SWT.IMAGE_GRAY && ((srcImage.type == SWT.ICON && srcImage.mask != 0) || srcImage.transparentPixel != -1)) {
- /* Generate the mask if necessary. */
- if (srcImage.transparentPixel != -1) srcImage.createMask();
- int mask = OS.XCreatePixmap(xDisplay, drawable, width, height, 1);
- int gc = OS.XCreateGC(xDisplay, mask, 0, null);
- OS.XCopyArea(xDisplay, srcImage.mask, mask, gc, 0, 0, width, height, 0, 0);
- OS.XFreeGC(xDisplay, gc);
- this.mask = mask;
- /* Destroy the image mask if the there is a GC created on the image */
- if (srcImage.transparentPixel != -1 && srcImage.memGC != null) srcImage.destroyMask();
- }
- switch (flag) {
- case SWT.IMAGE_COPY:
- int[] depth = new int[1];
- OS.XGetGeometry(xDisplay, srcImage.pixmap, unused, unused, unused, unused, unused, unused, depth);
- int pixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, depth[0]);
- int gc = OS.XCreateGC(xDisplay, pixmap, 0, null);
- OS.XCopyArea(xDisplay, srcImage.pixmap, pixmap, gc, 0, 0, width, height, 0, 0);
- OS.XFreeGC(xDisplay, gc);
- this.pixmap = pixmap;
- transparentPixel = srcImage.transparentPixel;
- alpha = srcImage.alpha;
- if (srcImage.alphaData != null) {
- alphaData = new byte[srcImage.alphaData.length];
- System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length);
- }
- createAlphaMask(width, height);
- break;
- case SWT.IMAGE_DISABLE:
- /* Get src image data */
- XImage srcXImage = new XImage();
- int srcXImagePtr = OS.XGetImage(xDisplay, srcImage.pixmap, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap);
- OS.memmove(srcXImage, srcXImagePtr, XImage.sizeof);
- byte[] srcData = new byte[srcXImage.bytes_per_line * srcXImage.height];
- OS.memmove(srcData, srcXImage.data, srcData.length);
- /* Create destination image */
- int destPixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, srcXImage.depth);
- int visualPtr = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay));
- int screenDepth = OS.XDefaultDepthOfScreen(OS.XDefaultScreenOfDisplay(xDisplay));
- int destXImagePtr = OS.XCreateImage(xDisplay, visualPtr, screenDepth, OS.ZPixmap, 0, 0, width, height, srcXImage.bitmap_pad, 0);
- XImage destXImage = new XImage();
- OS.memmove(destXImage, destXImagePtr, XImage.sizeof);
- int bufSize = destXImage.bytes_per_line * destXImage.height;
- int bufPtr = OS.XtMalloc(bufSize);
- destXImage.data = bufPtr;
- OS.memmove(destXImagePtr, destXImage, XImage.sizeof);
- byte[] destData = new byte[bufSize];
- /* Find the colors to map to */
- Color zeroColor = device.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
- Color oneColor = device.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
- int zeroPixel = zeroColor.handle.pixel;
- int onePixel = oneColor.handle.pixel;
- switch (srcXImage.bits_per_pixel) {
- case 1:
- /*
- * Nothing we can reasonably do here except copy
- * the bitmap; we can't make it a higher color depth.
- * Short-circuit the rest of the code and return.
- */
- gc = OS.XCreateGC(xDisplay, drawable, 0, null);
- pixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, 1);
- OS.XCopyArea(xDisplay, srcImage.pixmap, pixmap, gc, 0, 0, width, height, 0, 0);
- OS.XDestroyImage(srcXImagePtr);
- OS.XDestroyImage(destXImagePtr);
- OS.XFreeGC(xDisplay, gc);
- return;
- case 4:
- SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- break;
- case 8:
- int index = 0;
- int srcPixel, r, g, b;
- XColor[] colors = new XColor[256];
- int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay));
- for (int y = 0; y < srcXImage.height; y++) {
- for (int x = 0; x < srcXImage.bytes_per_line; x++) {
- srcPixel = srcData[index + x] & 0xFF;
- /* Get the RGB values of srcPixel */
- if (colors[srcPixel] == null) {
- XColor color = new XColor();
- color.pixel = srcPixel;
- OS.XQueryColor(xDisplay, colormap, color);
- colors[srcPixel] = color;
- }
- XColor xColor = colors[srcPixel];
- r = (xColor.red >> 8) & 0xFF;
- g = (xColor.green >> 8) & 0xFF;
- b = (xColor.blue >> 8) & 0xFF;
- /* See if the rgb maps to 0 or 1 */
- if ((r * r + g * g + b * b) < 98304) {
- /* Map down to 0 */
- destData[index + x] = (byte)zeroPixel;
- } else {
- /* Map up to 1 */
- destData[index + x] = (byte)onePixel;
- }
- }
- index += srcXImage.bytes_per_line;
- }
- break;
- case 16:
- index = 0;
- /* Get masks */
- Visual visual = new Visual();
- OS.memmove(visual, visualPtr, Visual.sizeof);
- int redMask = visual.red_mask;
- int greenMask = visual.green_mask;
- int blueMask = visual.blue_mask;
- /* Calculate mask shifts */
- int[] shift = new int[1];
- getOffsetForMask(16, redMask, srcXImage.byte_order, shift);
- int rShift = 24 - shift[0];
- getOffsetForMask(16, greenMask, srcXImage.byte_order, shift);
- int gShift = 24 - shift[0];
- getOffsetForMask(16, blueMask, srcXImage.byte_order, shift);
- int bShift = 24 - shift[0];
- byte zeroLow = (byte)(zeroPixel & 0xFF);
- byte zeroHigh = (byte)((zeroPixel >> 8) & 0xFF);
- byte oneLow = (byte)(onePixel & 0xFF);
- byte oneHigh = (byte)((onePixel >> 8) & 0xFF);
- for (int y = 0; y < srcXImage.height; y++) {
- int xIndex = 0;
- for (int x = 0; x < srcXImage.bytes_per_line; x += 2) {
- srcPixel = ((srcData[index + xIndex + 1] & 0xFF) << 8) | (srcData[index + xIndex] & 0xFF);
- r = (srcPixel & redMask) << rShift >> 16;
- g = (srcPixel & greenMask) << gShift >> 16;
- b = (srcPixel & blueMask) << bShift >> 16;
- /* See if the rgb maps to 0 or 1 */
- if ((r * r + g * g + b * b) < 98304) {
- /* Map down to 0 */
- destData[index + xIndex] = zeroLow;
- destData[index + xIndex + 1] = zeroHigh;
- } else {
- /* Map up to 1 */
- destData[index + xIndex] = oneLow;
- destData[index + xIndex + 1] = oneHigh;
- }
- xIndex += srcXImage.bits_per_pixel / 8;
- }
- index += srcXImage.bytes_per_line;
- }
- break;
- case 24:
- case 32:
- index = 0;
- /* Get masks */
- visual = new Visual();
- OS.memmove(visual, visualPtr, Visual.sizeof);
- redMask = visual.red_mask;
- greenMask = visual.green_mask;
- blueMask = visual.blue_mask;
- /* Calculate mask shifts */
- shift = new int[1];
- getOffsetForMask(srcXImage.bits_per_pixel, redMask, srcXImage.byte_order, shift);
- rShift = shift[0];
- getOffsetForMask(srcXImage.bits_per_pixel, greenMask, srcXImage.byte_order, shift);
- gShift = shift[0];
- getOffsetForMask(srcXImage.bits_per_pixel, blueMask, srcXImage.byte_order, shift);
- bShift = shift[0];
- byte zeroR = (byte)zeroColor.getRed();
- byte zeroG = (byte)zeroColor.getGreen();
- byte zeroB = (byte)zeroColor.getBlue();
- byte oneR = (byte)oneColor.getRed();
- byte oneG = (byte)oneColor.getGreen();
- byte oneB = (byte)oneColor.getBlue();
- for (int y = 0; y < srcXImage.height; y++) {
- int xIndex = 0;
- for (int x = 0; x < srcXImage.width; x++) {
- r = srcData[index + xIndex + rShift] & 0xFF;
- g = srcData[index + xIndex + gShift] & 0xFF;
- b = srcData[index + xIndex + bShift] & 0xFF;
- /* See if the rgb maps to 0 or 1 */
- if ((r * r + g * g + b * b) < 98304) {
- /* Map down to 0 */
- destData[index + xIndex + rShift] = zeroR;
- destData[index + xIndex + gShift] = zeroG;
- destData[index + xIndex + bShift] = zeroB;
- } else {
- /* Map up to 1 */
- destData[index + xIndex + rShift] = oneR;
- destData[index + xIndex + gShift] = oneG;
- destData[index + xIndex + bShift] = oneB;
- }
- xIndex += destXImage.bits_per_pixel / 8;
- }
- index += srcXImage.bytes_per_line;
- }
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- OS.memmove(destXImage.data, destData, destData.length);
- gc = OS.XCreateGC(xDisplay, destPixmap, 0, null);
- OS.XPutImage(xDisplay, destPixmap, gc, destXImagePtr, 0, 0, 0, 0, width, height);
- OS.XDestroyImage(destXImagePtr);
- OS.XDestroyImage(srcXImagePtr);
- OS.XFreeGC(xDisplay, gc);
- alpha = srcImage.alpha;
- if (srcImage.alphaData != null) {
- alphaData = new byte[srcImage.alphaData.length];
- System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length);
- }
- createAlphaMask(width, height);
- this.pixmap = destPixmap;
- break;
- case SWT.IMAGE_GRAY:
- ImageData data = srcImage.getImageData();
- PaletteData palette = data.palette;
- ImageData newData = data;
- if (!palette.isDirect) {
- /* Convert the palette entries to gray. */
- RGB [] rgbs = palette.getRGBs();
- for (int i=0; i<rgbs.length; i++) {
- if (data.transparentPixel != i) {
- RGB color = rgbs [i];
- int red = color.red;
- int green = color.green;
- int blue = color.blue;
- int intensity = (red+red+green+green+green+green+green+blue) >> 3;
- color.red = color.green = color.blue = intensity;
- }
- }
- newData.palette = new PaletteData(rgbs);
- } else {
- /* Create a 8 bit depth image data with a gray palette. */
- RGB[] rgbs = new RGB[256];
- for (int i=0; i<rgbs.length; i++) {
- rgbs[i] = new RGB(i, i, i);
- }
- newData = new ImageData(width, height, 8, new PaletteData(rgbs));
- newData.alpha = data.alpha;
- newData.alphaData = data.alphaData;
- newData.maskData = data.maskData;
- newData.maskPad = data.maskPad;
- if (data.transparentPixel != -1) newData.transparentPixel = 254;
-
- /* Convert the pixels. */
- int[] scanline = new int[width];
- int redMask = palette.redMask;
- int greenMask = palette.greenMask;
- int blueMask = palette.blueMask;
- int redShift = palette.redShift;
- int greenShift = palette.greenShift;
- int blueShift = palette.blueShift;
- for (int y=0; y<height; y++) {
- int offset = y * newData.bytesPerLine;
- data.getPixels(0, y, width, scanline, 0);
- for (int x=0; x<width; x++) {
- int pixel = scanline[x];
- if (pixel != data.transparentPixel) {
- int red = pixel & redMask;
- red = (redShift < 0) ? red >>> -redShift : red << redShift;
- int green = pixel & greenMask;
- green = (greenShift < 0) ? green >>> -greenShift : green << greenShift;
- int blue = pixel & blueMask;
- blue = (blueShift < 0) ? blue >>> -blueShift : blue << blueShift;
- int intensity = (red+red+green+green+green+green+green+blue) >> 3;
- if (newData.transparentPixel == intensity) intensity = 255;
- newData.data[offset] = (byte)intensity;
- } else {
- newData.data[offset] = (byte)254;
- }
- offset++;
- }
- }
- }
- init (newData);
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- init();
-}
-/**
- * Constructs an empty instance of this class with the
- * width and height of the specified rectangle. The result
- * may be drawn upon by creating a GC and using any of its
- * drawing operations, as shown in the following example:
- * <pre>
- * Image i = new Image(device, boundsRectangle);
- * GC gc = new GC(i);
- * gc.drawRectangle(0, 0, 50, 50);
- * gc.dispose();
- * </pre>
- * <p>
- * Note: Some platforms may have a limitation on the size
- * of image that can be created (size depends on width, height,
- * and depth). For example, Windows 95, 98, and ME do not allow
- * images larger than 16M.
- * </p>
- *
- * @param device the device on which to create the image
- * @param bounds a rectangle specifying the image's width and height (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the bounds rectangle is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, Rectangle bounds) {
- super(device);
- if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(bounds.width, bounds.height);
- init();
-}
-/**
- * Constructs an instance of this class from the given
- * <code>ImageData</code>.
- *
- * @param device the device on which to create the image
- * @param data the image data to create the image from (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the image data is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the ImageData is not supported</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, ImageData image) {
- super(device);
- init(image);
- init();
-}
-/**
- * Constructs an instance of this class, whose type is
- * <code>SWT.ICON</code>, from the two given <code>ImageData</code>
- * objects. The two images must be the same size. Pixel transparency
- * in either image will be ignored.
- * <p>
- * The mask image should contain white wherever the icon is to be visible,
- * and black wherever the icon is to be transparent. In addition,
- * the source image should contain black wherever the icon is to be
- * transparent.
- * </p>
- *
- * @param device the device on which to create the icon
- * @param source the color data for the icon
- * @param mask the mask data for the icon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if either the source or mask is null </li>
- * <li>ERROR_INVALID_ARGUMENT - if source and mask are different sizes</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, ImageData source, ImageData mask) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (mask == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (source.width != mask.width || source.height != mask.height) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- mask = ImageData.convertMask(mask);
- ImageData image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad, source.data);
- image.maskPad = mask.scanlinePad;
- image.maskData = mask.data;
- init(image);
- init();
-}
-/**
- * Constructs an instance of this class by loading its representation
- * from the specified input stream. Throws an error if an error
- * occurs while loading the image, or if the result is an image
- * of an unsupported type. Application code is still responsible
- * for closing the input stream.
- * <p>
- * This constructor is provided for convenience when loading a single
- * image only. If the stream contains multiple images, only the first
- * one will be loaded. To load multiple images, use
- * <code>ImageLoader.load()</code>.
- * </p><p>
- * This constructor may be used to load a resource as follows:
- * </p>
- * <pre>
- * static Image loadImage (Display display, Class clazz, String string) {
- * InputStream stream = clazz.getResourceAsStream (string);
- * if (stream == null) return null;
- * Image image = null;
- * try {
- * image = new Image (display, stream);
- * } catch (SWTException ex) {
- * } finally {
- * try {
- * stream.close ();
- * } catch (IOException ex) {}
- * }
- * return image;
- * }
- * </pre>
- *
- * @param device the device on which to create the image
- * @param stream the input stream to load the image from
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the stream is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from the stream</li>
- * <li>ERROR_INVALID_IMAGE - if the image stream contains invalid data </li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the image stream describes an image with an unsupported depth</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, InputStream stream) {
- super(device);
- init(new ImageData(stream));
- init();
-}
-/**
- * Constructs an instance of this class by loading its representation
- * from the file with the specified name. Throws an error if an error
- * occurs while loading the image, or if the result is an image
- * of an unsupported type.
- * <p>
- * This constructor is provided for convenience when loading
- * a single image only. If the specified file contains
- * multiple images, only the first one will be used.
- *
- * @param device the device on which to create the image
- * @param filename the name of the file to load the image from
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the file name is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from the file</li>
- * <li>ERROR_INVALID_IMAGE - if the image file contains invalid data </li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the image file describes an image with an unsupported depth</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, String filename) {
- super(device);
- init(new ImageData(filename));
- init();
-}
-void createAlphaMask(int width, int height) {
- if (device.useXRender && (alpha != -1 || alphaData != null)) {
- int xDisplay = device.xDisplay;
- int drawable = OS.XDefaultRootWindow(xDisplay);
- mask = OS.XCreatePixmap(xDisplay, drawable, alpha != -1 ? 1 : width, alpha != -1 ? 1 : height, 8);
- if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int gc = OS.XCreateGC(xDisplay, mask, 0, null);
- if (alpha != -1) {
- OS.XSetForeground(xDisplay, gc, (alpha & 0xFF) << 8 | (alpha & 0xFF));
- OS.XFillRectangle(xDisplay, mask, gc, 0, 0, 1, 1);
- } else {
- int imagePtr = OS.XGetImage(xDisplay, mask, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap);
- XImage xImage = new XImage();
- OS.memmove(xImage, imagePtr, XImage.sizeof);
- if (xImage.bytes_per_line == width) {
- OS.memmove(xImage.data, alphaData, alphaData.length);
- } else {
- byte[] line = new byte[xImage.bytes_per_line];
- for (int y = 0; y < height; y++) {
- System.arraycopy(alphaData, width * y, line, 0, width);
- OS.memmove(xImage.data + (xImage.bytes_per_line * y), line, xImage.bytes_per_line);
- }
- }
- OS.XPutImage(xDisplay, mask, gc, imagePtr, 0, 0, 0, 0, width, height);
- OS.XDestroyImage(imagePtr);
- }
- OS.XFreeGC(xDisplay, gc);
- }
-}
-/**
- * Create the receiver's mask if necessary.
- */
-void createMask() {
- if (mask != 0) return;
- int xDisplay = device.xDisplay;
- int drawable = OS.XDefaultRootWindow(xDisplay);
- int screenDepth = OS.XDefaultDepthOfScreen(OS.XDefaultScreenOfDisplay(xDisplay));
- int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay));
- ImageData maskImage = getImageData().getTransparencyMask();
- int maskPixmap = OS.XCreatePixmap(xDisplay, drawable, maskImage.width, maskImage.height, 1);
- XColor[] xcolors = device.xcolors;
- int gc = OS.XCreateGC(xDisplay, maskPixmap, 0, null);
- Image.putImage(maskImage, 0, 0, maskImage.width, maskImage.height, 0, 0, maskImage.width, maskImage.height, xDisplay, visual, screenDepth, xcolors, null, true, maskPixmap, gc);
- OS.XFreeGC(xDisplay, gc);
- this.mask = maskPixmap;
-}
-void createSurface() {
- if (surface != 0) return;
- int [] unused = new int [1]; int [] width = new int [1]; int [] height = new int [1];
- OS.XGetGeometry (device.xDisplay, pixmap, unused, unused, unused, width, height, unused, unused);
- int xDisplay = device.xDisplay;
- int xDrawable = pixmap;
- int xVisual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay));
- surface = Cairo.cairo_xlib_surface_create(xDisplay, xDrawable, xVisual, width[0], height[0]);
-}
-void destroy() {
- if (memGC != null) memGC.dispose();
- int xDisplay = device.xDisplay;
- if (pixmap != 0) OS.XFreePixmap (xDisplay, pixmap);
- if (mask != 0) OS.XFreePixmap (xDisplay, mask);
- if (surface != 0) Cairo.cairo_surface_destroy(surface);
- surface = pixmap = mask = 0;
- memGC = null;
-}
-/**
- * Destroy the receiver's mask if it exists.
- */
-void destroyMask() {
- if (mask == 0) return;
- OS.XFreePixmap (device.xDisplay, mask);
- mask = 0;
-}
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Image)) return false;
- Image image = (Image)object;
- return device == image.device && pixmap == image.pixmap;
-}
-/**
- * Returns the color to which to map the transparent pixel, or null if
- * the receiver has no transparent pixel.
- * <p>
- * There are certain uses of Images that do not support transparency
- * (for example, setting an image into a button or label). In these cases,
- * it may be desired to simulate transparency by using the background
- * color of the widget to paint the transparent pixels of the image.
- * Use this method to check which color will be used in these cases
- * in place of transparency. This value may be set with setBackground().
- * <p>
- *
- * @return the background color of the image, or null if there is no transparency in the image
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getBackground() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transparentPixel == -1) return null;
- XColor xColor = new XColor();
- xColor.pixel = transparentPixel;
- int xDisplay = device.xDisplay;
- int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay));
- OS.XQueryColor(xDisplay, colormap, xColor);
- return Color.motif_new(device, xColor);
-}
-/**
- * Returns the bounds of the receiver. The rectangle will always
- * have x and y values of 0, and the width and height of the
- * image.
- *
- * @return a rectangle specifying the image's bounds
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li>
- * </ul>
- */
-public Rectangle getBounds () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width != -1 && height != -1) {
- return new Rectangle(0, 0, width, height);
- }
- int [] unused = new int [1]; int [] w = new int [1]; int [] h = new int [1];
- OS.XGetGeometry (device.xDisplay, pixmap, unused, unused, unused, w, h, unused, unused);
- return new Rectangle(0, 0, width = w [0], height = h [0]);
-}
-/**
- * Returns an <code>ImageData</code> based on the receiver
- * Modifications made to this <code>ImageData</code> will not
- * affect the Image.
- *
- * @return an <code>ImageData</code> containing the image's data and attributes
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li>
- * </ul>
- *
- * @see ImageData
- */
-public ImageData getImageData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Rectangle srcBounds = getBounds();
- int width = srcBounds.width;
- int height = srcBounds.height;
- int xDisplay = device.xDisplay;
- int xSrcImagePtr = OS.XGetImage(xDisplay, pixmap, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap);
- if (xSrcImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- XImage xSrcImage = new XImage();
- OS.memmove(xSrcImage, xSrcImagePtr, XImage.sizeof);
-
- /* Get the data and palette of the source image. */
- PaletteData palette = null;
- int length = xSrcImage.bytes_per_line * xSrcImage.height;
- byte[] srcData = new byte[length];
- OS.memmove(srcData, xSrcImage.data, length);
- switch (xSrcImage.bits_per_pixel) {
- case 1:
- palette = new PaletteData(new RGB[] {
- new RGB(0, 0, 0),
- new RGB(255, 255, 255)
- });
- break;
- case 4:
- /*
- * We currently don't run on a 4-bit server, so 4-bit images
- * should not exist.
- */
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- case 8:
- /* Normalize the pixels in the source image data (by making the
- * pixel values sequential starting at pixel 0). Reserve normalized
- * pixel 0 so that it maps to real pixel 0. This assumes pixel 0 is
- * always used in the image.
- */
- byte[] normPixel = new byte[256];
- for (int index = 0; index < normPixel.length; index++) {
- normPixel[index] = 0;
- }
- int numPixels = 1;
- int index = 0;
- for (int y = 0; y < xSrcImage.height; y++) {
- for (int x = 0; x < xSrcImage.bytes_per_line; x++) {
- int srcPixel = srcData[index + x] & 0xFF;
- if (srcPixel != 0 && normPixel[srcPixel] == 0) {
- normPixel[srcPixel] = (byte)numPixels++;
- }
- srcData[index + x] = normPixel[srcPixel];
- }
- index += xSrcImage.bytes_per_line;
- }
-
- /* Create a palette with only the RGB values used in the image. */
- int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay));
- RGB[] rgbs = new RGB[numPixels];
- XColor color = new XColor();
- for (int srcPixel = 0; srcPixel < normPixel.length; srcPixel++) {
- /* If the pixel value was used in the image, get its RGB values. */
- if (srcPixel == 0 || normPixel[srcPixel] != 0) {
- color.pixel = srcPixel;
- OS.XQueryColor(xDisplay, colormap, color);
- int rgbIndex = normPixel[srcPixel] & 0xFF;
- rgbs[rgbIndex] = new RGB((color.red >> 8) & 0xFF, (color.green >> 8) & 0xFF, (color.blue >> 8) & 0xFF);
- }
- }
- palette = new PaletteData(rgbs);
- break;
- case 16:
- /* Byte swap the data if necessary */
- if (xSrcImage.byte_order == OS.MSBFirst) {
- for (int i = 0; i < srcData.length; i += 2) {
- byte b = srcData[i];
- srcData[i] = srcData[i+1];
- srcData[i+1] = b;
- }
- }
- break;
- case 24:
- break;
- case 32:
- /* Byte swap the data if necessary */
- if (xSrcImage.byte_order == OS.LSBFirst) {
- for (int i = 0; i < srcData.length; i += 4) {
- byte b = srcData[i];
- srcData[i] = srcData[i+3];
- srcData[i+3] = b;
- b = srcData[i+1];
- srcData[i+1] = srcData[i+2];
- srcData[i+2] = b;
- }
- }
- break;
- default:
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- }
- if (palette == null) {
- /*
- * For some reason, the XImage does not have the mask information.
- * We must get it from the defualt visual.
- */
- int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay));
- Visual v = new Visual();
- OS.memmove(v, visual, Visual.sizeof);
- palette = new PaletteData(v.red_mask, v.green_mask, v.blue_mask);
- }
- ImageData data = new ImageData(width, height, xSrcImage.bits_per_pixel, palette, 4, srcData);
- if (transparentPixel == -1 && type == SWT.ICON && mask != 0) {
- /* Get the icon mask data */
- int xMaskPtr = OS.XGetImage(xDisplay, mask, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap);
- if (xMaskPtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- XImage xMask = new XImage();
- OS.memmove(xMask, xMaskPtr, XImage.sizeof);
- byte[] maskData = new byte[xMask.bytes_per_line * xMask.height];
- OS.memmove(maskData, xMask.data, maskData.length);
- OS.XDestroyImage(xMaskPtr);
- int maskPad = xMask.bitmap_pad / 8;
- /* Make mask scanline pad equals to 2 */
- data.maskPad = 2;
- maskData = ImageData.convertPad(maskData, width, height, 1, maskPad, data.maskPad);
- /* Bit swap the mask data if necessary */
- if (xMask.bitmap_bit_order == OS.LSBFirst) {
- for (int i = 0; i < maskData.length; i++) {
- byte b = maskData[i];
- maskData[i] = (byte)(((b & 0x01) << 7) | ((b & 0x02) << 5) |
- ((b & 0x04) << 3) | ((b & 0x08) << 1) | ((b & 0x10) >> 1) |
- ((b & 0x20) >> 3) | ((b & 0x40) >> 5) | ((b & 0x80) >> 7));
- }
- }
- data.maskData = maskData;
- }
- data.transparentPixel = transparentPixel;
- data.alpha = alpha;
- if (alpha == -1 && alphaData != null) {
- data.alphaData = new byte[alphaData.length];
- System.arraycopy(alphaData, 0, data.alphaData, 0, alphaData.length);
- }
- OS.XDestroyImage(xSrcImagePtr);
- return data;
-}
-/**
- * Get the offset for the given mask.
- *
- * For 24 and 32-bit masks, the offset indicates which byte holds the
- * data for the given mask (indexed from 0).
- * For example, in 0x0000FF00, the byte offset is 1.
- *
- * For 16-bit masks, the offset indicates which bit holds the most significant
- * data for the given mask (indexed from 1).
- * For example, in 0x7E0, the bit offset is 11.
- *
- * The different semantics are necessary because 24- and 32-bit images
- * have their color components aligned on byte boundaries, and 16-bit images
- * do not.
- */
-static boolean getOffsetForMask(int bitspp, int mask, int byteOrder, int[] poff) {
- if (bitspp % 8 != 0) {
- return false;
- }
- switch (mask) {
- /* 24-bit and 32-bit masks */
- case 0x000000FF:
- poff[0] = 0;
- break;
- case 0x0000FF00:
- poff[0] = 1;
- break;
- case 0x00FF0000:
- poff[0] = 2;
- break;
- case 0xFF000000:
- poff[0] = 3;
- break;
- /* 16-bit masks */
- case 0x001F:
- poff[0] = 5;
- break;
- case 0x03E0:
- poff[0] = 10;
- break;
- case 0x07E0:
- poff[0] = 11;
- break;
- case 0x7C00:
- poff[0] = 15;
- break;
- case 0xF800:
- poff[0] = 16;
- break;
- default:
- return false;
- }
- if (bitspp == 16) {
- return true;
- }
- if (poff[0] >= bitspp / 8) {
- return false;
- }
- if (byteOrder == OS.MSBFirst) {
- poff[0] = (bitspp/8 - 1) - poff[0];
- }
- return true;
-}
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return pixmap;
-}
-void init(int width, int height) {
- if (width <= 0 || height <= 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- /* Create the pixmap */
- this.type = SWT.BITMAP;
- int xDisplay = device.xDisplay;
- int screen = OS.XDefaultScreenOfDisplay(xDisplay);
- int depth = OS.XDefaultDepthOfScreen(screen);
- int screenNum = OS.XDefaultScreen(xDisplay);
- int drawable = OS.XDefaultRootWindow(xDisplay);
- int pixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, depth);
- if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- /* Fill the bitmap with white */
- int xGC = OS.XCreateGC(xDisplay, drawable, 0, null);
- OS.XSetForeground(xDisplay, xGC, OS.XWhitePixel(xDisplay, screenNum));
- OS.XFillRectangle(xDisplay, pixmap, xGC, 0, 0, width, height);
- OS.XFreeGC(xDisplay, xGC);
- this.pixmap = pixmap;
-}
-void init(ImageData image) {
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int xDisplay = device.xDisplay;
- int drawable = OS.XDefaultRootWindow(xDisplay);
- int screenDepth = OS.XDefaultDepthOfScreen(OS.XDefaultScreenOfDisplay(xDisplay));
- int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay));
- int pixmap = OS.XCreatePixmap(xDisplay, drawable, image.width, image.height, screenDepth);
- if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int gc = OS.XCreateGC(xDisplay, pixmap, 0, null);
- int[] transPixel = null;
- if (image.transparentPixel != -1) transPixel = new int[]{image.transparentPixel};
- int error = putImage(image, 0, 0, image.width, image.height, 0, 0, image.width, image.height, xDisplay, visual, screenDepth, device.xcolors, transPixel, false, pixmap, gc);
- OS.XFreeGC(xDisplay, gc);
- if (error != 0) {
- OS.XFreePixmap (xDisplay, pixmap);
- SWT.error(error);
- }
- if (image.getTransparencyType() == SWT.TRANSPARENCY_MASK || image.transparentPixel != -1) {
- if (image.transparentPixel != -1) transparentPixel = transPixel[0];
- ImageData maskImage = image.getTransparencyMask();
- int mask = OS.XCreatePixmap(xDisplay, drawable, image.width, image.height, 1);
- gc = OS.XCreateGC(xDisplay, mask, 0, null);
- error = putImage(maskImage, 0, 0, maskImage.width, maskImage.height, 0, 0, maskImage.width, maskImage.height, xDisplay, visual, screenDepth, device.xcolors, null, true, mask, gc);
- OS.XFreeGC(xDisplay, gc);
- if (error != 0) {
- OS.XFreePixmap (xDisplay, pixmap);
- OS.XFreePixmap (xDisplay, mask);
- SWT.error(error);
- }
- this.mask = mask;
- if (image.getTransparencyType() == SWT.TRANSPARENCY_MASK) {
- this.type = SWT.ICON;
- } else {
- this.type = SWT.BITMAP;
- }
- } else {
- this.type = SWT.BITMAP;
- this.mask = 0;
- this.alpha = image.alpha;
- if (image.alpha == -1 && image.alphaData != null) {
- this.alphaData = new byte[image.alphaData.length];
- System.arraycopy(image.alphaData, 0, this.alphaData, 0, alphaData.length);
- }
- createAlphaMask(image.width, image.height);
- }
- this.pixmap = pixmap;
-}
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public int internal_new_GC (GCData data) {
- if (pixmap == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (type != SWT.BITMAP || memGC != null) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int xDisplay = device.xDisplay;
- int xGC = OS.XCreateGC (xDisplay, pixmap, 0, null);
- if (xGC == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- if (data != null) {
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) == 0) {
- data.style |= SWT.LEFT_TO_RIGHT;
- }
- data.device = device;
- data.display = xDisplay;
- data.drawable = pixmap;
- data.background = device.COLOR_WHITE.handle;
- data.foreground = device.COLOR_BLACK.handle;
- data.font = device.systemFont;
- data.colormap = OS.XDefaultColormap (xDisplay, OS.XDefaultScreen (xDisplay));
- data.image = this;
- }
- return xGC;
-}
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int gc, GCData data) {
- int xDisplay = 0;
- if (data != null) xDisplay = data.display;
- if (xDisplay == 0 && device != null) xDisplay = device.xDisplay;
- if (xDisplay == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- OS.XFreeGC(xDisplay, gc);
-}
-/**
- * Returns <code>true</code> if the image has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the image.
- * When an image has been disposed, it is an error to
- * invoke any other method using the image.
- *
- * @return <code>true</code> when the image is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return pixmap == 0;
-}
-public static Image motif_new(Device device, int type, int pixmap, int mask) {
- Image image = new Image(device);
- image.type = type;
- image.pixmap = pixmap;
- image.mask = mask;
- return image;
-}
-/**
- * Put a device-independent image of any depth into a drawable of any depth,
- * stretching if necessary.
- */
-static int putImage(ImageData image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, int display, int visual, int screenDepth, XColor[] xcolors, int[] transparentPixel, boolean isMask, int drawable, int gc) {
- PaletteData palette = image.palette;
- if (!(((image.depth == 1 || image.depth == 2 || image.depth == 4 || image.depth == 8) && !palette.isDirect) ||
- ((image.depth == 8) || (image.depth == 16 || image.depth == 24 || image.depth == 32) && palette.isDirect)))
- return SWT.ERROR_UNSUPPORTED_DEPTH;
-
- boolean flipX = destWidth < 0;
- boolean flipY = destHeight < 0;
- if (flipX) {
- destWidth = -destWidth;
- destX = destX - destWidth;
- }
- if (flipY) {
- destHeight = -destHeight;
- destY = destY - destHeight;
- }
- byte[] srcReds = null, srcGreens = null, srcBlues = null;
- if (!palette.isDirect) {
- RGB[] rgbs = palette.getRGBs();
- int length = rgbs.length;
- srcReds = new byte[length];
- srcGreens = new byte[length];
- srcBlues = new byte[length];
- for (int i = 0; i < rgbs.length; i++) {
- RGB rgb = rgbs[i];
- if (rgb == null) continue;
- srcReds[i] = (byte)rgb.red;
- srcGreens[i] = (byte)rgb.green;
- srcBlues[i] = (byte)rgb.blue;
- }
- }
- byte[] destReds = null, destGreens = null, destBlues = null;
- int destRedMask = 0, destGreenMask = 0, destBlueMask = 0;
- final boolean screenDirect;
- if (screenDepth <= 8) {
- if (xcolors == null) return SWT.ERROR_UNSUPPORTED_DEPTH;
- destReds = new byte[xcolors.length];
- destGreens = new byte[xcolors.length];
- destBlues = new byte[xcolors.length];
- for (int i = 0; i < xcolors.length; i++) {
- XColor color = xcolors[i];
- if (color == null) continue;
- destReds[i] = (byte)((color.red >> 8) & 0xFF);
- destGreens[i] = (byte)((color.green >> 8) & 0xFF);
- destBlues[i] = (byte)((color.blue >> 8) & 0xFF);
- }
- screenDirect = false;
- } else {
- Visual xVisual = new Visual();
- OS.memmove(xVisual, visual, Visual.sizeof);
- destRedMask = xVisual.red_mask;
- destGreenMask = xVisual.green_mask;
- destBlueMask = xVisual.blue_mask;
- screenDirect = true;
- }
- if (transparentPixel != null) {
- int transRed = 0, transGreen = 0, transBlue = 0;
- if (palette.isDirect) {
- RGB rgb = palette.getRGB(transparentPixel[0]);
- transRed = rgb.red;
- transGreen = rgb.green;
- transBlue = rgb.blue;
- } else {
- RGB[] rgbs = palette.getRGBs();
- if (transparentPixel[0] < rgbs.length) {
- RGB rgb = rgbs[transparentPixel[0]];
- transRed = rgb.red;
- transGreen = rgb.green;
- transBlue = rgb.blue;
- }
- }
- transparentPixel[0] = ImageData.closestMatch(screenDepth, (byte)transRed, (byte)transGreen, (byte)transBlue,
- destRedMask, destGreenMask, destBlueMask, destReds, destGreens, destBlues);
- }
-
- /* Depth 1 */
- if (image.depth == 1) {
- int xImagePtr = OS.XCreateImage(display, visual, 1, OS.XYBitmap, 0, 0, destWidth, destHeight, image.scanlinePad * 8, 0);
- if (xImagePtr == 0) return SWT.ERROR_NO_HANDLES;
- XImage xImage = new XImage();
- OS.memmove(xImage, xImagePtr, XImage.sizeof);
- int bufSize = xImage.bytes_per_line * xImage.height;
- int bufPtr = OS.XtMalloc(bufSize);
- xImage.data = bufPtr;
- OS.memmove(xImagePtr, xImage, XImage.sizeof);
- byte[] buf = new byte[bufSize];
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, null, null, null,
- ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY,
- buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.bitmap_bit_order, 0, 0, destWidth, destHeight, null, null, null,
- flipX, flipY);
- OS.memmove(xImage.data, buf, bufSize);
-
- int foreground = 1, background = 0;
- if (!isMask) {
- foreground = 0;
- if (srcReds.length > 1) {
- foreground = ImageData.closestMatch(screenDepth, srcReds[1], srcGreens[1], srcBlues[1],
- destRedMask, destGreenMask, destBlueMask, destReds, destGreens, destBlues);
- }
- if (srcReds.length > 0) {
- background = ImageData.closestMatch(screenDepth, srcReds[0], srcGreens[0], srcBlues[0],
- destRedMask, destGreenMask, destBlueMask, destReds, destGreens, destBlues);
- }
- }
- XGCValues values = new XGCValues();
- OS.XGetGCValues(display, gc, OS.GCForeground | OS.GCBackground, values);
- OS.XSetForeground(display, gc, foreground);
- OS.XSetBackground(display, gc, background);
- OS.XPutImage(display, drawable, gc, xImagePtr, 0, 0, destX, destY, destWidth, destHeight);
- OS.XSetForeground(display, gc, values.foreground);
- OS.XSetBackground(display, gc, values.background);
- OS.XDestroyImage(xImagePtr);
- return 0;
- }
-
- /* Depths other than 1 */
- int xImagePtr = OS.XCreateImage(display, visual, screenDepth, OS.ZPixmap, 0, 0, destWidth, destHeight, image.scanlinePad * 8, 0);
- if (xImagePtr == 0) return SWT.ERROR_NO_HANDLES;
- XImage xImage = new XImage();
- OS.memmove(xImage, xImagePtr, XImage.sizeof);
- int bufSize = xImage.bytes_per_line * xImage.height;
- int bufPtr = OS.XtMalloc(bufSize);
- xImage.data = bufPtr;
- OS.memmove(xImagePtr, xImage, XImage.sizeof);
- byte[] buf = new byte[bufSize];
- if (palette.isDirect) {
- if (screenDirect) {
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, palette.redMask, palette.greenMask, palette.blueMask,
- ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY,
- buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, xImage.red_mask, xImage.green_mask, xImage.blue_mask,
- flipX, flipY);
- } else {
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, palette.redMask, palette.greenMask, palette.blueMask,
- ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY,
- buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, destReds, destGreens, destBlues,
- flipX, flipY);
- }
- } else {
- if (screenDirect) {
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, srcReds, srcGreens, srcBlues,
- ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY,
- buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, xImage.red_mask, xImage.green_mask, xImage.blue_mask,
- flipX, flipY);
- } else {
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, srcReds, srcGreens, srcBlues,
- ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY,
- buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, destReds, destGreens, destBlues,
- flipX, flipY);
- }
- }
- OS.memmove(xImage.data, buf, bufSize);
- OS.XPutImage(display, drawable, gc, xImagePtr, 0, 0, destX, destY, destWidth, destHeight);
- OS.XDestroyImage(xImagePtr);
- return 0;
-}
-/**
- * Sets the color to which to map the transparent pixel.
- * <p>
- * There are certain uses of <code>Images</code> that do not support
- * transparency (for example, setting an image into a button or label).
- * In these cases, it may be desired to simulate transparency by using
- * the background color of the widget to paint the transparent pixels
- * of the image. This method specifies the color that will be used in
- * these cases. For example:
- * <pre>
- * Button b = new Button();
- * image.setBackground(b.getBackground());
- * b.setImage(image);
- * </pre>
- * </p><p>
- * The image may be modified by this operation (in effect, the
- * transparent regions may be filled with the supplied color). Hence
- * this operation is not reversible and it is not legal to call
- * this function twice or with a null argument.
- * </p><p>
- * This method has no effect if the receiver does not have a transparent
- * pixel value.
- * </p>
- *
- * @param color the color to use when a transparent pixel is specified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setBackground(Color color) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (transparentPixel == -1) return;
- /* Generate the mask if necessary. */
- if (mask == 0) createMask();
- Rectangle bounds = getBounds();
- int[] unused = new int[1];
- int[] depth = new int[1];
- int xDisplay = device.xDisplay;
- OS.XGetGeometry(xDisplay, pixmap, unused, unused, unused, unused, unused, unused, depth);
- int drawable = OS.XDefaultRootWindow(xDisplay);
- int tempPixmap = OS.XCreatePixmap(xDisplay, drawable, bounds.width, bounds.height, depth[0]);
- int xGC = OS.XCreateGC(xDisplay, tempPixmap, 0, null);
- OS.XSetForeground(xDisplay, xGC, color.handle.pixel);
- OS.XFillRectangle(xDisplay, tempPixmap, xGC, 0, 0, bounds.width, bounds.height);
- OS.XSetClipMask(xDisplay, xGC, mask);
- OS.XCopyArea(xDisplay, pixmap, tempPixmap, xGC, 0, 0, bounds.width, bounds.height, 0, 0);
- OS.XSetClipMask(xDisplay, xGC, OS.None);
- OS.XCopyArea(xDisplay, tempPixmap, pixmap, xGC, 0, 0, bounds.width, bounds.height, 0, 0);
- OS.XFreePixmap(xDisplay, tempPixmap);
- OS.XFreeGC(xDisplay, xGC);
- /* Destroy the receiver's mask if the there is a GC created on it */
- if (memGC != null) destroyMask();
-}
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Image {*DISPOSED*}";
- return "Image {" + pixmap + "}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java
deleted file mode 100755
index 8aaaefb757..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java
+++ /dev/null
@@ -1,561 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class represent areas of an x-y coordinate
- * system that are aggregates of the areas covered by a number
- * of polygons.
- * <p>
- * Application code must explicitly invoke the <code>Region.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Region extends Resource {
- /**
- * the OS resource for the region
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
-/**
- * Constructs a new empty region.
- *
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
- * </ul>
- */
-public Region () {
- this(null);
-}
-/**
- * Constructs a new empty region.
- * <p>
- * You must dispose the region when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the region
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
- * </ul>
- *
- * @see #dispose
- *
- * @since 3.0
- */
-public Region (Device device) {
- super(device);
- handle = OS.XCreateRegion ();
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-Region (Device device, int handle) {
- super(device);
- this.handle = handle;
-}
-/**
- * Adds the given polygon to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param pointArray points that describe the polygon to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
-*
- */
-public void add (int[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- short[] points = new short[pointArray.length];
- for (int i = 0; i < pointArray.length; i++) {
- points[i] = (short)pointArray[i];
- }
- int polyRgn = OS.XPolygonRegion(points, points.length / 2, OS.EvenOddRule);
- OS.XUnionRegion(handle, polyRgn, handle);
- OS.XDestroyRegion(polyRgn);
-}
-/**
- * Adds the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void add (Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- add (rect.x, rect.y, rect.width, rect.height);
-}
-/**
- * Adds the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void add (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- XRectangle xRect = new XRectangle();
- xRect.x = (short)x;
- xRect.y = (short)y;
- xRect.width = (short)width;
- xRect.height = (short)height;
- OS.XUnionRectWithRegion(xRect, handle, handle);
-}
-/**
- * Adds all of the polygons which make up the area covered
- * by the argument to the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to merge
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void add (Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.XUnionRegion(handle, region.handle, handle);
-}
-/**
- * Returns <code>true</code> if the point specified by the
- * arguments is inside the area specified by the receiver,
- * and <code>false</code> otherwise.
- *
- * @param x the x coordinate of the point to test for containment
- * @param y the y coordinate of the point to test for containment
- * @return <code>true</code> if the region contains the point and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains (int x, int y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return OS.XPointInRegion(handle, x, y);
-}
-/**
- * Returns <code>true</code> if the given point is inside the
- * area specified by the receiver, and <code>false</code>
- * otherwise.
- *
- * @param pt the point to test for containment
- * @return <code>true</code> if the region contains the point and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains (Point pt) {
- if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return contains(pt.x, pt.y);
-}
-void destroy() {
- OS.XDestroyRegion(handle);
- handle = 0;
-}
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (this == object) return true;
- if (!(object instanceof Region)) return false;
- Region region = (Region)object;
- return handle == region.handle;
-}
-/**
- * Returns a rectangle which represents the rectangular
- * union of the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @return a bounding rectangle for the region
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#union
- */
-public Rectangle getBounds() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- XRectangle rect = new XRectangle();
- OS.XClipBox(handle, rect);
- return new Rectangle(rect.x, rect.y, rect.width, rect.height);
-}
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return handle;
-}
-/**
- * Intersects the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to intersect with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void intersect (Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- intersect(rect.x, rect.y, rect.width, rect.height);
-}
-/**
- * Intersects the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void intersect (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int rectRgn = OS.XCreateRegion();
- XRectangle xRect = new XRectangle();
- xRect.x = (short)x;
- xRect.y = (short)y;
- xRect.width = (short)width;
- xRect.height = (short)height;
- OS.XUnionRectWithRegion(xRect, rectRgn, rectRgn);
- OS.XIntersectRegion(handle, rectRgn, handle);
- OS.XDestroyRegion(rectRgn);
-}
-/**
- * Intersects all of the polygons which make up the area covered
- * by the argument to the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to intersect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void intersect (Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.XIntersectRegion(handle, region.handle, handle);
-}
-/**
- * Returns <code>true</code> if the rectangle described by the
- * arguments intersects with any of the polygons the receiver
- * maintains to describe its area, and <code>false</code> otherwise.
- *
- * @param x the x coordinate of the origin of the rectangle
- * @param y the y coordinate of the origin of the rectangle
- * @param width the width of the rectangle
- * @param height the height of the rectangle
- * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#intersects(Rectangle)
- */
-public boolean intersects (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return OS.XRectInRegion (handle, x, y, width, height) != OS.RectangleOut;
-}
-/**
- * Returns <code>true</code> if the given rectangle intersects
- * with any of the polygons the receiver maintains to describe
- * its area and <code>false</code> otherwise.
- *
- * @param rect the rectangle to test for intersection
- * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#intersects(Rectangle)
- */
-public boolean intersects (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return intersects(rect.x, rect.y, rect.width, rect.height);
-}
-/**
- * Returns <code>true</code> if the region has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the region.
- * When a region has been disposed, it is an error to
- * invoke any other method using the region.
- *
- * @return <code>true</code> when the region is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-/**
- * Returns <code>true</code> if the receiver does not cover any
- * area in the (x, y) coordinate plane, and <code>false</code> if
- * the receiver does cover some area in the plane.
- *
- * @return <code>true</code> if the receiver is empty, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean isEmpty () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return OS.XEmptyRegion(handle);
-}
-public static Region motif_new(Device device, int handle) {
- return new Region(device, handle);
-}
-/**
- * Subtracts the given polygon from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param pointArray points that describe the polygon to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract (int[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- short[] points = new short[pointArray.length];
- for (int i = 0; i < pointArray.length; i++) {
- points[i] = (short)pointArray[i];
- }
- int polyRgn = OS.XPolygonRegion(points, points.length / 2, OS.EvenOddRule);
- OS.XSubtractRegion(handle, polyRgn, handle);
- OS.XDestroyRegion(polyRgn);
-}
-/**
- * Subtracts the given rectangle from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to subtract from the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract (Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- subtract (rect.x, rect.y, rect.width, rect.height);
-}
-/**
- * Subtracts the given rectangle from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void subtract (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int rectRgn = OS.XCreateRegion();
- XRectangle xRect = new XRectangle();
- xRect.x = (short)x;
- xRect.y = (short)y;
- xRect.width = (short)width;
- xRect.height = (short)height;
- OS.XUnionRectWithRegion(xRect, rectRgn, rectRgn);
- OS.XSubtractRegion(handle, rectRgn, handle);
- OS.XDestroyRegion(rectRgn);
-}
-/**
- * Subtracts all of the polygons which make up the area covered
- * by the argument from the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to subtract
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract (Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.XSubtractRegion(handle, region.handle, handle);
-}
-/**
- * Translate all of the polygons the receiver maintains to describe
- * its area by the specified point.
- *
- * @param x the x coordinate of the point to translate
- * @param y the y coordinate of the point to translate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void translate (int x, int y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.XOffsetRegion (handle, x, y);
-}
-/**
- * Translate all of the polygons the receiver maintains to describe
- * its area by the specified point.
- *
- * @param pt the point to translate
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void translate (Point pt) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- translate (pt.x, pt.y);
-}
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Region {*DISPOSED*}";
- return "Region {" + handle + "}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/TextLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/TextLayout.java
deleted file mode 100644
index a03a44526c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/TextLayout.java
+++ /dev/null
@@ -1,1935 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
-/**
- * <code>TextLayout</code> is a graphic object that represents
- * styled text.
- * <p>
- * Instances of this class provide support for drawing, cursor
- * navigation, hit testing, text wrapping, alignment, tab expansion
- * line breaking, etc. These are aspects required for rendering internationalized text.
- * </p><p>
- * Application code must explicitly invoke the <code>TextLayout#dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#textlayout">TextLayout, TextStyle snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: CustomControlExample, StyledText tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.0
- */
-public final class TextLayout extends Resource {
- Font font;
- String text;
- int lineSpacing;
- int ascent, descent;
- int alignment;
- int wrapWidth;
- int orientation;
- int indent;
- boolean justify;
- int[] tabs;
- int[] segments;
- StyleItem[] styles;
-
- StyleItem[][] runs;
- int[] lineOffset, lineY, lineWidth;
- int defaultAscent, defaultDescent;
-
- static final RGB LINK_FOREGROUND = new RGB (0, 51, 153);
-
- static class StyleItem {
- TextStyle style;
- int start, length, width, height, baseline;
- boolean lineBreak, softBreak, tab;
-
- public String toString () {
- return "StyleItem {" + start + ", " + style + "}";
- }
- }
-
-/**
- * Constructs a new instance of this class on the given device.
- * <p>
- * You must dispose the text layout when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the text layout
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- *
- * @see #dispose()
- */
-public TextLayout (Device device) {
- super(device);
- wrapWidth = ascent = descent = -1;
- lineSpacing = 0;
- orientation = SWT.LEFT_TO_RIGHT;
- XFontStruct fontStruct = getFontHeigth(this.device.getSystemFont());
- defaultAscent = fontStruct.ascent;
- defaultDescent = fontStruct.descent;
- styles = new StyleItem[2];
- styles[0] = new StyleItem();
- styles[1] = new StyleItem();
- text = ""; //$NON-NLS-1$
- init();
-}
-
-void checkLayout () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-int stringWidth (StyleItem run, char[] ch) {
- if (ch.length == 0) return 0;
- Font font = getItemFont(run);
- int fontList = font.handle;
- byte[] buffer = Converter.wcsToMbcs(font.codePage, ch, true);
- int xmString = OS.XmStringCreateLocalized(buffer);
- int width = OS.XmStringWidth(fontList, xmString);
- OS.XmStringFree(xmString);
- return width;
-}
-
-void computeRuns () {
- if (runs != null) return;
- StyleItem[] allRuns = itemize();
- for (int i=0; i<allRuns.length-1; i++) {
- StyleItem run = allRuns[i];
- place(run);
- }
- int lineWidth = 0, lineStart = 0, lineCount = 1;
- for (int i=0; i<allRuns.length - 1; i++) {
- StyleItem run = allRuns[i];
- if (run.length == 1) {
- char ch = text.charAt(run.start);
- switch (ch) {
- case '\t': {
- run.tab = true;
- run.baseline = 0;
- if (tabs == null) break;
- int tabsLength = tabs.length, j;
- for (j = 0; j < tabsLength; j++) {
- if (tabs[j] > lineWidth) {
- run.width = tabs[j] - lineWidth;
- break;
- }
- }
- if (j == tabsLength) {
- int tabX = tabs[tabsLength-1];
- int lastTabWidth = tabsLength > 1 ? tabs[tabsLength-1] - tabs[tabsLength-2] : tabs[0];
- if (lastTabWidth > 0) {
- while (tabX <= lineWidth) tabX += lastTabWidth;
- run.width = tabX - lineWidth;
- }
- }
- break;
- }
- case '\n':
- run.lineBreak = true;
- run.baseline = run.width = 0;
- break;
- case '\r':
- run.lineBreak = true;
- run.baseline = run.width = 0;
- StyleItem next = allRuns[i + 1];
- if (next.length != 0 && text.charAt(next.start) == '\n') {
- run.length += 1;
- i++;
- }
- break;
- }
- }
- if (wrapWidth != -1 && lineWidth + run.width > wrapWidth && !run.tab) {
- int start = 0;
- char[] chars = new char[run.length];
- text.getChars(run.start, run.start + run.length, chars, 0);
- if (!(run.style != null && run.style.metrics != null)) {
- int width = 0, maxWidth = wrapWidth - lineWidth;
- char[] buffer = new char[1];
- buffer[0] = chars[start];
- int charWidth = stringWidth(run, buffer);
- while (width + charWidth < maxWidth) {
- width += charWidth;
- start++;
- buffer[0] = chars[start];
- charWidth = stringWidth(run, buffer);
- }
- }
- int firstStart = start;
- int firstIndice = i;
- while (i >= lineStart) {
- chars = new char[run.length];
- text.getChars(run.start, run.start + run.length, chars, 0);
- while(start >= 0) {
- if (Compatibility.isSpaceChar(chars[start]) || Compatibility.isWhitespace(chars[start])) break;
- start--;
- }
- if (start >= 0 || i == lineStart) break;
- run = allRuns[--i];
- start = run.length - 1;
- }
- if (start == 0 && i != lineStart) {
- run = allRuns[--i];
- } else if (start <= 0 && i == lineStart) {
- i = firstIndice;
- run = allRuns[i];
- start = Math.max(1, firstStart);
- }
- chars = new char[run.length];
- text.getChars(run.start, run.start + run.length, chars, 0);
- while (start < run.length) {
- if (!Compatibility.isWhitespace(chars[start])) break;
- start++;
- }
- if (0 < start && start < run.length) {
- StyleItem newRun = new StyleItem();
- newRun.start = run.start + start;
- newRun.length = run.length - start;
- newRun.style = run.style;
- run.length = start;
- place (run);
- place (newRun);
- StyleItem[] newAllRuns = new StyleItem[allRuns.length + 1];
- System.arraycopy(allRuns, 0, newAllRuns, 0, i + 1);
- System.arraycopy(allRuns, i + 1, newAllRuns, i + 2, allRuns.length - i - 1);
- allRuns = newAllRuns;
- allRuns[i + 1] = newRun;
- }
- if (i != allRuns.length - 2) {
- run.softBreak = run.lineBreak = true;
- }
- }
- lineWidth += run.width;
- if (run.lineBreak) {
- lineStart = i + 1;
- lineWidth = 0;
- lineCount++;
- }
- }
- lineWidth = 0;
- runs = new StyleItem[lineCount][];
- lineOffset = new int[lineCount + 1];
- lineY = new int[lineCount + 1];
- this.lineWidth = new int[lineCount];
- int lineRunCount = 0, line = 0;
- int ascent = Math.max(defaultAscent, this.ascent);
- int descent = Math.max(defaultDescent, this.descent);
- StyleItem[] lineRuns = new StyleItem[allRuns.length];
- XFontStruct fontStruct;
- for (int i=0; i<allRuns.length; i++) {
- StyleItem run = allRuns[i];
- lineRuns[lineRunCount++] = run;
- lineWidth += run.width;
- if (run.style != null ) {
- int runAscent = defaultAscent;
- int runDescent = defaultDescent;
- if (run.style.metrics != null) {
- GlyphMetrics metrics = run.style.metrics;
- runAscent = metrics.ascent;
- runDescent = metrics.descent;
- } else if (run.style.font != null) {
- fontStruct = getFontHeigth(run.style.font);
- runAscent = fontStruct.ascent;
- runDescent = fontStruct.descent;
- }
- ascent = Math.max(ascent, runAscent + run.style.rise);
- descent = Math.max(descent, runDescent - run.style.rise);
- if (run.style.rise != 0) {
- run.baseline += run.style.rise;
- }
- }
- if (run.lineBreak || i == allRuns.length - 1) {
- runs[line] = new StyleItem[lineRunCount];
- System.arraycopy(lineRuns, 0, runs[line], 0, lineRunCount);
- StyleItem lastRun = runs[line][lineRunCount - 1];
- this.lineWidth[line] = lineWidth;
- line++;
- lineY[line] = lineY[line - 1] + ascent + descent + lineSpacing;
- lineOffset[line] = lastRun.start + lastRun.length;
- lineRunCount = lineWidth = 0;
- ascent = Math.max(defaultAscent, this.ascent);
- descent = Math.max(defaultDescent, this.descent);
- }
- }
-}
-
-void destroy() {
- freeRuns();
- font = null;
- text = null;
- tabs = null;
- styles = null;
- lineOffset = null;
- lineY = null;
- lineWidth = null;
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- *
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- */
-public void draw (GC gc, int x, int y) {
- draw(gc, x, y, -1, -1, null, null);
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- *
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param selectionStart the offset where the selections starts, or -1 indicating no selection
- * @param selectionEnd the offset where the selections ends, or -1 indicating no selection
- * @param selectionForeground selection foreground, or NULL to use the system default color
- * @param selectionBackground selection background, or NULL to use the system default color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- */
-public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground) {
- draw(gc, x, y, selectionStart, selectionEnd, selectionForeground, selectionBackground, 0);
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- * <p>
- * The parameter <code>flags</code> can include one of <code>SWT.DELIMITER_SELECTION</code>
- * or <code>SWT.FULL_SELECTION</code> to specify the selection behavior on all lines except
- * for the last line, and can also include <code>SWT.LAST_LINE_SELECTION</code> to extend
- * the specified selection behavior to the last line.
- * </p>
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param selectionStart the offset where the selections starts, or -1 indicating no selection
- * @param selectionEnd the offset where the selections ends, or -1 indicating no selection
- * @param selectionForeground selection foreground, or NULL to use the system default color
- * @param selectionBackground selection background, or NULL to use the system default color
- * @param flags drawing options
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- *
- * @since 3.3
- */
-public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags) {
- checkLayout();
- computeRuns();
- if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (selectionForeground != null && selectionForeground.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (selectionBackground != null && selectionBackground.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- gc.checkGC(GC.FOREGROUND);
- int length = text.length();
- if (length == 0 && flags == 0) return;
- boolean hasSelection = selectionStart <= selectionEnd && selectionStart != -1 && selectionEnd != -1;
- if (hasSelection || (flags & SWT.LAST_LINE_SELECTION) != 0) {
- selectionStart = Math.min(Math.max(0, selectionStart), length - 1);
- selectionEnd = Math.min(Math.max(0, selectionEnd), length - 1);
- if (selectionForeground == null) selectionForeground = device.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
- if (selectionBackground == null) selectionBackground = device.getSystemColor(SWT.COLOR_LIST_SELECTION);
- }
- final Color foreground = gc.getForeground();
- final Color background = gc.getBackground();
- final Font gcFont = gc.getFont();
- Color linkColor = null;
- Rectangle clip = gc.getClipping();
- for (int line=0; line<runs.length; line++) {
- int drawX = x + getLineIndent(line);
- int drawY = y + lineY[line];
- StyleItem[] lineRuns = runs[line];
- int lineHeight = lineY[line+1] - lineY[line];
- if (flags != 0 && (hasSelection || (flags & SWT.LAST_LINE_SELECTION) != 0)) {
- boolean extent = false;
- if (line == runs.length - 1 && (flags & SWT.LAST_LINE_SELECTION) != 0) {
- extent = true;
- } else {
- StyleItem run = lineRuns[lineRuns.length - 1];
- if (run.lineBreak && !run.softBreak) {
- if (selectionStart <= run.start && run.start <= selectionEnd) extent = true;
- } else {
- int endOffset = run.start + run.length - 1;
- if (selectionStart <= endOffset && endOffset < selectionEnd && (flags & SWT.FULL_SELECTION) != 0) {
- extent = true;
- }
- }
- }
- if (extent) {
- gc.setBackground(selectionBackground);
- int width = (flags & SWT.FULL_SELECTION) != 0 ? 0x7fffffff : lineHeight / 3;
- gc.fillRectangle(drawX + lineWidth[line], drawY, width, lineHeight);
- }
- }
- if (drawX > clip.x + clip.width) continue;
- if (drawX + lineWidth[line] < clip.x) continue;
- int baseline = Math.max(0, this.ascent);
- for (int i = 0; i < lineRuns.length; i++) {
- baseline = Math.max(baseline, lineRuns[i].baseline);
- }
- for (int i = 0; i < lineRuns.length; i++) {
- StyleItem run = lineRuns[i];
- if (run.length == 0) continue;
- if (drawX > clip.x + clip.width) break;
- if (drawX + run.width >= clip.x) {
- if (!run.lineBreak || run.softBreak) {
- String string = text.substring(run.start, run.start + run.length);
- int drawRunY = drawY + (baseline - run.baseline);
- int end = run.start + run.length - 1;
- gc.setFont(getItemFont(run));
- boolean fullSelection = hasSelection && selectionStart <= run.start && selectionEnd >= end;
- TextStyle style = run.style;
- if (fullSelection) {
- gc.setBackground(selectionBackground);
- gc.fillRectangle(drawX, drawY, run.width, lineHeight);
- if (!run.tab && !(style != null && style.metrics != null)) {
- gc.setForeground(selectionForeground);
- gc.drawString(string, drawX, drawRunY, true);
- drawLines(gc, run, drawX, drawRunY, run.width);
- }
- } else {
- if (style != null && style.background != null) {
- Color bg = style.background;
- gc.setBackground(bg);
- gc.fillRectangle(drawX, drawRunY, run.width, run.height);
- }
- if (!run.tab) {
- Color fg = foreground;
- if (style != null) {
- if (style.foreground != null) {
- fg = style.foreground;
- } else {
- if (style.underline && style.underlineStyle == SWT.UNDERLINE_LINK) {
- if (linkColor == null) {
- linkColor = new Color(device, LINK_FOREGROUND);
- }
- fg = linkColor;
- }
- }
- }
- if (!(style != null && style.metrics != null)) {
- gc.setForeground(fg);
- gc.drawString(string, drawX, drawRunY, true);
- drawLines(gc, run, drawX, drawRunY, run.width);
- }
- boolean partialSelection = hasSelection && !(selectionStart > end || run.start > selectionEnd);
- if (partialSelection) {
- int selStart = Math.max(selectionStart, run.start);
- int selEnd = Math.min(selectionEnd, end);
- string = text.substring(run.start, selStart);
- int selX = drawX + gc.stringExtent(string).x;
- string = text.substring(selStart, selEnd + 1);
- int selWidth = gc.stringExtent(string).x;
- gc.setBackground(selectionBackground);
- gc.fillRectangle(selX, drawY, selWidth, lineHeight);
- if (fg != selectionForeground && !(style != null && style.metrics != null)) {
- gc.setForeground(selectionForeground);
- gc.drawString(string, selX, drawRunY, true);
- drawLines(gc, run, selX, drawRunY, selWidth);
- }
- }
- }
- }
- drawBorder(gc, lineRuns, i, drawX, drawY, lineHeight, foreground);
- }
- }
- drawX += run.width;
- }
- }
- gc.setForeground(foreground);
- gc.setBackground(background);
- gc.setFont(gcFont);
- if (linkColor != null) linkColor.dispose();
-}
-
-void drawBorder(GC gc, StyleItem[] line, int index, int x, int y, int lineHeight, Color color) {
- StyleItem run = line[index];
- TextStyle style = run.style;
- if (style == null) return;
- if (style.borderStyle != SWT.NONE && (index + 1 >= line.length || !style.isAdherentBorder(line[index + 1].style))) {
- int width = run.width;
- for (int i = index; i > 0 && style.isAdherentBorder(line[i - 1].style); i--) {
- x -= line[i - 1].width;
- width += line[i - 1].width;
- }
- if (style.borderColor != null) {
- color = style.borderColor;
- } else {
- if (style.foreground != null) {
- color = style.foreground;
- }
- }
- gc.setForeground(color);
- int lineStyle = gc.getLineStyle();
- int[] dashes = null;
- if (lineStyle == SWT.LINE_CUSTOM) {
- dashes = gc.getLineDash();
- }
- switch (style.borderStyle) {
- case SWT.BORDER_SOLID:
- gc.setLineStyle(SWT.LINE_SOLID);
- break;
- case SWT.BORDER_DASH:
- gc.setLineStyle(SWT.LINE_DASH);
- break;
- case SWT.BORDER_DOT:
- gc.setLineStyle(SWT.LINE_DOT);
- break;
- }
- gc.drawRectangle(x, y, width - 1, lineHeight - 1);
- gc.setLineStyle(lineStyle);
- if (dashes != null) {
- gc.setLineDash(dashes);
- }
- }
-}
-
-void drawLines(GC gc, StyleItem run, int x, int y, int width) {
- TextStyle style = run.style;
- if (style == null) return;
- if (style.underline) {
- int underlineY = y + run.baseline + 1 - style.rise;
- if (style.underlineColor != null) {
- gc.setForeground(style.underlineColor);
- }
- switch (style.underlineStyle) {
- case SWT.UNDERLINE_SQUIGGLE:
- case SWT.UNDERLINE_ERROR:
- int squigglyThickness = 1;
- int squigglyHeight = 2 * squigglyThickness;
- int squigglyY = Math.min(underlineY, y + run.height - squigglyHeight - 1);
- int[] points = computePolyline(x, squigglyY, x + width, squigglyY + squigglyHeight);
- gc.drawPolyline(points);
- break;
- case SWT.UNDERLINE_DOUBLE:
- gc.drawLine (x, underlineY + 2, x + width, underlineY + 2);
- //FALLTHROU
- case SWT.UNDERLINE_LINK:
- case SWT.UNDERLINE_SINGLE:
- gc.drawLine (x, underlineY, x + width, underlineY);
- }
- }
- if (style.strikeout) {
- int strikeoutY = y + run.height - run.height/2 - 1;
- if (style.strikeoutColor != null) {
- gc.setForeground(style.strikeoutColor);
- }
- gc.drawLine (x, strikeoutY, x + width, strikeoutY);
- }
-}
-
-int[] computePolyline(int left, int top, int right, int bottom) {
- int height = bottom - top; // can be any number
- int width = 2 * height; // must be even
- int peaks = (right - left) / width;
- if (peaks == 0 && right - left > 2) {
- peaks = 1;
- }
- int length = ((2 * peaks) + 1) * 2;
- if (length < 0) return new int[0];
-
- int[] coordinates = new int[length];
- for (int i = 0; i < peaks; i++) {
- int index = 4 * i;
- coordinates[index] = left + (width * i);
- coordinates[index+1] = bottom;
- coordinates[index+2] = coordinates[index] + width / 2;
- coordinates[index+3] = top;
- }
- coordinates[length-2] = Math.min(Math.max(0, right - 1), left + (width * peaks));
- coordinates[length-1] = bottom;
- return coordinates;
-}
-
-void freeRuns() {
- runs = null;
-}
-
-/**
- * Returns the receiver's horizontal text alignment, which will be one
- * of <code>SWT.LEFT</code>, <code>SWT.CENTER</code> or
- * <code>SWT.RIGHT</code>.
- *
- * @return the alignment used to positioned text horizontally
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getAlignment () {
- checkLayout();
- return alignment;
-}
-
-/**
- * Returns the ascent of the receiver.
- *
- * @return the ascent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getDescent()
- * @see #setDescent(int)
- * @see #setAscent(int)
- * @see #getLineMetrics(int)
- */
-public int getAscent () {
- checkLayout();
- return ascent;
-}
-
-/**
- * Returns the bounds of the receiver. The width returned is either the
- * width of the longest line or the width set using {@link TextLayout#setWidth(int)}.
- * To obtain the text bounds of a line use {@link TextLayout#getLineBounds(int)}.
- *
- * @return the bounds of the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setWidth(int)
- * @see #getLineBounds(int)
- */
-public Rectangle getBounds () {
- checkLayout();
- computeRuns();
- int width = 0;
- if (wrapWidth != -1) {
- width = wrapWidth;
- } else {
- for (int line=0; line<runs.length; line++) {
- width = Math.max(width, lineWidth[line] + getLineIndent(line));
- }
- }
- return new Rectangle (0, 0, width, lineY[lineY.length - 1]);
-}
-
-/**
- * Returns the bounds for the specified range of characters. The
- * bounds is the smallest rectangle that encompasses all characters
- * in the range. The start and end offsets are inclusive and will be
- * clamped if out of range.
- *
- * @param start the start offset
- * @param end the end offset
- * @return the bounds of the character range
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds (int start, int end) {
- checkLayout();
- computeRuns();
- int length = text.length();
- if (length == 0) return new Rectangle(0, 0, 0, 0);
- if (start > end) return new Rectangle(0, 0, 0, 0);
- start = Math.min(Math.max(0, start), length - 1);
- end = Math.min(Math.max(0, end), length - 1);
- int startLine = getLineIndex(start);
- int endLine = getLineIndex(end);
-
- Rectangle rect = new Rectangle(0, 0, 0, 0);
- rect.y = lineY[startLine];
- rect.height = lineY[endLine + 1] - rect.y - lineSpacing;
- if (startLine == endLine) {
- rect.x = getLocation(start, false).x;
- rect.width = getLocation(end, true).x - rect.x;
- } else {
- while (startLine <= endLine) {
- rect.width = Math.max(rect.width, lineWidth[startLine++]);
- }
- }
- return rect;
-}
-
-/**
- * Returns the descent of the receiver.
- *
- * @return the descent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getAscent()
- * @see #setAscent(int)
- * @see #setDescent(int)
- * @see #getLineMetrics(int)
- */
-public int getDescent () {
- checkLayout();
- return descent;
-}
-
-/**
- * Returns the default font currently being used by the receiver
- * to draw and measure text.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getFont () {
- checkLayout();
- return font;
-}
-
-XFontStruct getFontHeigth(Font font) {
- int fontList = font.handle;
- int [] buffer = new int [1];
- if (!OS.XmFontListInitFontContext (buffer, fontList)) {
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- int context = buffer [0];
- int ascent = 0, descent = 0;
- XFontStruct fontStruct = new XFontStruct ();
- int fontListEntry;
- int [] fontStructPtr = new int [1];
- int [] fontNamePtr = new int [1];
- while ((fontListEntry = OS.XmFontListNextEntry (context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer);
- if (buffer [0] == 0) {
- OS.memmove (fontStruct, fontPtr, XFontStruct.sizeof);
- ascent = Math.max(ascent, fontStruct.ascent);
- descent = Math.max(descent, fontStruct.descent);
- } else {
- int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr);
- int [] fontStructs = new int [nFonts];
- OS.memmove (fontStructs, fontStructPtr [0], nFonts * 4);
- for (int i=0; i<nFonts; i++) {
- OS.memmove (fontStruct, fontStructs[i], XFontStruct.sizeof);
- ascent = Math.max(ascent, fontStruct.ascent);
- descent = Math.max(descent, fontStruct.descent);
- }
- }
- }
- OS.XmFontListFreeFontContext (context);
- fontStruct.ascent = ascent;
- fontStruct.descent = descent;
- return fontStruct;
-}
-
-/**
-* Returns the receiver's indent.
-*
-* @return the receiver's indent
-*
-* @exception SWTException <ul>
-* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
-* </ul>
-*
-* @since 3.2
-*/
-public int getIndent () {
- checkLayout();
- return indent;
-}
-
-/**
-* Returns the receiver's justification.
-*
-* @return the receiver's justification
-*
-* @exception SWTException <ul>
-* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
-* </ul>
-*
-* @since 3.2
-*/
-public boolean getJustify () {
- checkLayout();
- return justify;
-}
-
-/**
- * Returns the embedding level for the specified character offset. The
- * embedding level is usually used to determine the directionality of a
- * character in bidirectional text.
- *
- * @param offset the character offset
- * @return the embedding level
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- */
-public int getLevel (int offset) {
- checkLayout();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- return 0;
-}
-
-/**
- * Returns the line offsets. Each value in the array is the
- * offset for the first character in a line except for the last
- * value, which contains the length of the text.
- *
- * @return the line offsets
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getLineOffsets () {
- checkLayout();
- computeRuns();
- int[] offsets = new int[lineOffset.length];
- System.arraycopy(lineOffset, 0, offsets, 0, offsets.length);
- return offsets;
-}
-
-/**
- * Returns the bounds of the line for the specified line index.
- *
- * @param lineIndex the line index
- * @return the line bounds
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getLineBounds(int lineIndex) {
- checkLayout();
- computeRuns();
- if (!(0 <= lineIndex && lineIndex < runs.length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- int x = getLineIndent(lineIndex);
- int y = lineY[lineIndex];
- int width = lineWidth[lineIndex];
- int height = lineY[lineIndex + 1] - y - lineSpacing;
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the receiver's line count. This includes lines caused
- * by wrapping.
- *
- * @return the line count
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineCount () {
- checkLayout();
- computeRuns();
- return runs.length;
-}
-
-int getLineIndent (int lineIndex) {
- int lineIndent = 0;
- if (lineIndex == 0) {
- lineIndent = indent;
- } else {
- StyleItem[] previousLine = runs[lineIndex - 1];
- StyleItem previousRun = previousLine[previousLine.length - 1];
- if (previousRun.lineBreak && !previousRun.softBreak) {
- lineIndent = indent;
- }
- }
- if (wrapWidth != -1) {
- boolean partialLine = true;
-// if (justify) {
-// StyleItem[] lineRun = runs[lineIndex];
-// if (lineRun[lineRun.length - 1].softBreak) {
-// partialLine = false;
-// }
-// }
- if (partialLine) {
- int lineWidth = this.lineWidth[lineIndex] + lineIndent;
- switch (alignment) {
- case SWT.CENTER: lineIndent += (wrapWidth - lineWidth) / 2; break;
- case SWT.RIGHT: lineIndent += wrapWidth - lineWidth; break;
- }
- }
- }
- return lineIndent;
-}
-
-/**
- * Returns the index of the line that contains the specified
- * character offset.
- *
- * @param offset the character offset
- * @return the line index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineIndex (int offset) {
- checkLayout();
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- for (int line=0; line<runs.length; line++) {
- if (lineOffset[line + 1] > offset) {
- return line;
- }
- }
- return runs.length - 1;
-}
-
-/**
- * Returns the font metrics for the specified line index.
- *
- * @param lineIndex the line index
- * @return the font metrics
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontMetrics getLineMetrics (int lineIndex) {
- checkLayout();
- computeRuns();
- if (!(0 <= lineIndex && lineIndex < runs.length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- int ascent = Math.max(defaultAscent, this.ascent);
- int descent = Math.max(defaultDescent, this.descent);
- if (text.length() != 0) {
- GC gc = new GC(device);
- StyleItem[] lineRuns = runs[lineIndex];
- for (int i = 0; i < lineRuns.length; i++) {
- StyleItem run = lineRuns[i];
- if (run.style != null) {
- int runAscent = 0;
- int runDescent = 0;
- if (run.style.metrics != null) {
- GlyphMetrics glyphMetrics = run.style.metrics;
- runAscent = glyphMetrics.ascent;
- runDescent = glyphMetrics.descent;
- } else if (run.style.font != null) {
- gc.setFont(run.style.font);
- FontMetrics metrics = gc.getFontMetrics();
- runAscent = metrics.getAscent();
- runDescent = metrics.getDescent();
- }
- ascent = Math.max(ascent, runAscent + run.style.rise);
- descent = Math.max(descent, runDescent - run.style.rise);
- }
- }
- gc.dispose();
- }
- return FontMetrics.motif_new(ascent, descent, 0, 0, ascent + descent);
-}
-
-/**
- * Returns the location for the specified character offset. The
- * <code>trailing</code> argument indicates whether the offset
- * corresponds to the leading or trailing edge of the cluster.
- *
- * @param offset the character offset
- * @param trailing the trailing flag
- * @return the location of the character offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getOffset(Point, int[])
- * @see #getOffset(int, int, int[])
- */
-public Point getLocation (int offset, boolean trailing) {
- checkLayout();
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- int line;
- for (line=0; line<runs.length; line++) {
- if (lineOffset[line + 1] > offset) break;
- }
- line = Math.min(line, runs.length - 1);
- StyleItem[] lineRuns = runs[line];
- Point result = null;
- if (offset == length) {
- result = new Point(lineWidth[line], lineY[line]);
- } else {
- int width = 0;
- for (int i=0; i<lineRuns.length; i++) {
- StyleItem run = lineRuns[i];
- int end = run.start + run.length;
- if (run.start <= offset && offset < end) {
- if (run.tab) {
- if (trailing || offset == length) width += run.width;
- } else {
- if (trailing) offset++;
- if (run.style != null && run.style.metrics != null) {
- GlyphMetrics metrics = run.style.metrics;
- width += metrics.width * (offset - run.start);
- } else {
- char[] chars = new char[offset - run.start];
- text.getChars(run.start, offset, chars, 0);
- width += stringWidth(run, chars);
- }
- }
- result = new Point(width, lineY[line]);
- break;
- }
- width += run.width;
- }
- }
- if (result == null) result = new Point(0, 0);
- result.x += getLineIndent(line);
- return result;
-}
-
-Font getItemFont(StyleItem item) {
- if (item.style != null && item.style.font != null) {
- return item.style.font;
- }
- if (this.font != null) {
- return this.font;
- }
- return device.systemFont;
-}
-
-/**
- * Returns the next offset for the specified offset and movement
- * type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>,
- * <code>SWT.MOVEMENT_CLUSTER</code>, <code>SWT.MOVEMENT_WORD</code>,
- * <code>SWT.MOVEMENT_WORD_END</code> or <code>SWT.MOVEMENT_WORD_START</code>.
- *
- * @param offset the start offset
- * @param movement the movement type
- * @return the next offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getPreviousOffset(int, int)
- */
-public int getNextOffset (int offset, int movement) {
- checkLayout();
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- if (offset == length) return length;
- if ((movement & (SWT.MOVEMENT_CHAR | SWT.MOVEMENT_CLUSTER)) != 0) return offset + 1;
- int lineEnd = 0;
- for (int i=1; i<lineOffset.length; i++) {
- if (lineOffset[i] > offset) {
- lineEnd = Math.max(lineOffset[i - 1], lineOffset[i] - 1);
- if (i == runs.length) lineEnd++;
- break;
- }
- }
- boolean previousSpaceChar = !Compatibility.isLetterOrDigit(text.charAt(offset));
- offset++;
- while (offset < lineEnd) {
- boolean spaceChar = !Compatibility.isLetterOrDigit(text.charAt(offset));
- if (movement == SWT.MOVEMENT_WORD || movement == SWT.MOVEMENT_WORD_END) {
- if (spaceChar && !previousSpaceChar) break;
- }
- if (movement == SWT.MOVEMENT_WORD_START) {
- if (!spaceChar && previousSpaceChar) break;
- }
- previousSpaceChar = spaceChar;
- offset++;
- }
- return offset;
-}
-
-/**
- * Returns the character offset for the specified point.
- * For a typical character, the trailing argument will be filled in to
- * indicate whether the point is closer to the leading edge (0) or
- * the trailing edge (1). When the point is over a cluster composed
- * of multiple characters, the trailing argument will be filled with the
- * position of the character in the cluster that is closest to
- * the point.
- *
- * @param point the point
- * @param trailing the trailing buffer
- * @return the character offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getLocation(int, boolean)
- */
-public int getOffset (Point point, int[] trailing) {
- checkLayout();
- if (point == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return getOffset (point.x, point.y, trailing);
-}
-
-/**
- * Returns the character offset for the specified point.
- * For a typical character, the trailing argument will be filled in to
- * indicate whether the point is closer to the leading edge (0) or
- * the trailing edge (1). When the point is over a cluster composed
- * of multiple characters, the trailing argument will be filled with the
- * position of the character in the cluster that is closest to
- * the point.
- *
- * @param x the x coordinate of the point
- * @param y the y coordinate of the point
- * @param trailing the trailing buffer
- * @return the character offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getLocation(int, boolean)
- */
-public int getOffset (int x, int y, int[] trailing) {
- checkLayout();
- computeRuns();
- if (trailing != null && trailing.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int line;
- int lineCount = runs.length;
- for (line=0; line<lineCount; line++) {
- if (lineY[line + 1] > y) break;
- }
- line = Math.min(line, runs.length - 1);
- x -= getLineIndent(line);
- if (x >= lineWidth[line]) x = lineWidth[line] - 1;
- if (x < 0) x = 0;
- StyleItem[] lineRuns = runs[line];
- int width = 0;
- for (int i = 0; i < lineRuns.length; i++) {
- StyleItem run = lineRuns[i];
- if (run.lineBreak && !run.softBreak) return run.start;
- if (width + run.width > x) {
- if (run.style != null && run.style.metrics != null) {
- int xRun = x - width;
- GlyphMetrics metrics = run.style.metrics;
- if (metrics.width > 0) {
- if (trailing != null) {
- trailing[0] = (xRun % metrics.width < metrics.width / 2) ? 0 : 1;
- }
- return run.start + xRun / metrics.width;
- }
- }
- if (run.tab) {
- if (trailing != null) {
- trailing[0] = x < (width + run.width / 2) ? 0 : 1;
- }
- return run.start;
- }
- int offset = 0;
- char[] buffer = new char[1];
- char[] chars = new char[run.length];
- text.getChars(run.start, run.start + run.length, chars, 0);
- for (offset = 0; offset < chars.length; offset++) {
- buffer[0] = chars[offset];
- int charWidth = stringWidth(run, buffer);
- if (width + charWidth > x) {
- if (trailing != null) {
- trailing[0] = x < (width + charWidth / 2) ? 0 : 1;
- }
- break;
- }
- width += charWidth;
- }
- return run.start + offset;
- }
- width += run.width;
- }
- if (trailing != null) trailing[0] = 0;
- return lineOffset[line + 1];
-}
-
-/**
- * Returns the orientation of the receiver.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getOrientation () {
- checkLayout();
- return orientation;
-}
-
-/**
- * Returns the previous offset for the specified offset and movement
- * type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>,
- * <code>SWT.MOVEMENT_CLUSTER</code> or <code>SWT.MOVEMENT_WORD</code>,
- * <code>SWT.MOVEMENT_WORD_END</code> or <code>SWT.MOVEMENT_WORD_START</code>.
- *
- * @param offset the start offset
- * @param movement the movement type
- * @return the previous offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getNextOffset(int, int)
- */
-public int getPreviousOffset (int offset, int movement) {
- checkLayout();
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- if (offset == 0) return 0;
- if ((movement & (SWT.MOVEMENT_CHAR | SWT.MOVEMENT_CLUSTER)) != 0) return offset - 1;
- int lineStart = 0;
- for (int i=0; i<lineOffset.length-1; i++) {
- int lineEnd = lineOffset[i+1];
- if (i == runs.length - 1) lineEnd++;
- if (lineEnd > offset) {
- lineStart = lineOffset[i];
- break;
- }
- }
- offset--;
- boolean previousSpaceChar = !Compatibility.isLetterOrDigit(text.charAt(offset));
- while (lineStart < offset) {
- boolean spaceChar = !Compatibility.isLetterOrDigit(text.charAt(offset - 1));
- if (movement == SWT.MOVEMENT_WORD_END) {
- if (!spaceChar && previousSpaceChar) break;
- }
- if (movement == SWT.MOVEMENT_WORD || movement == SWT.MOVEMENT_WORD_START) {
- if (spaceChar && !previousSpaceChar) break;
- }
- offset--;
- previousSpaceChar = spaceChar;
- }
- return offset;
-}
-
-/**
- * Gets the ranges of text that are associated with a <code>TextStyle</code>.
- *
- * @return the ranges, an array of offsets representing the start and end of each
- * text style.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getStyles()
- *
- * @since 3.2
- */
-public int[] getRanges () {
- checkLayout();
- int[] result = new int[styles.length * 2];
- int count = 0;
- for (int i=0; i<styles.length - 1; i++) {
- if (styles[i].style != null) {
- result[count++] = styles[i].start;
- result[count++] = styles[i + 1].start - 1;
- }
- }
- if (count != result.length) {
- int[] newResult = new int[count];
- System.arraycopy(result, 0, newResult, 0, count);
- result = newResult;
- }
- return result;
-}
-
-/**
- * Returns the text segments offsets of the receiver.
- *
- * @return the text segments offsets
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getSegments() {
- checkLayout();
- return segments;
-}
-
-/**
- * Returns the line spacing of the receiver.
- *
- * @return the line spacing
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getSpacing () {
- checkLayout();
- return lineSpacing;
-}
-
-/**
- * Gets the style of the receiver at the specified character offset.
- *
- * @param offset the text offset
- * @return the style or <code>null</code> if not set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public TextStyle getStyle (int offset) {
- checkLayout();
- int length = text.length();
- if (!(0 <= offset && offset < length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- for (int i=1; i<styles.length; i++) {
- StyleItem item = styles[i];
- if (item.start > offset) {
- return styles[i - 1].style;
- }
- }
- return null;
-}
-
-/**
- * Gets all styles of the receiver.
- *
- * @return the styles
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getRanges()
- *
- * @since 3.2
- */
-public TextStyle[] getStyles () {
- checkLayout();
- TextStyle[] result = new TextStyle[styles.length];
- int count = 0;
- for (int i=0; i<styles.length; i++) {
- if (styles[i].style != null) {
- result[count++] = styles[i].style;
- }
- }
- if (count != result.length) {
- TextStyle[] newResult = new TextStyle[count];
- System.arraycopy(result, 0, newResult, 0, count);
- result = newResult;
- }
- return result;
-}
-
-/**
- * Returns the tab list of the receiver.
- *
- * @return the tab list
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getTabs () {
- checkLayout();
- return tabs;
-}
-
-/**
- * Gets the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public String getText () {
- checkLayout();
- return text;
-}
-
-/**
- * Returns the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getWidth () {
- checkLayout();
- return wrapWidth;
-}
-
-/**
- * Returns <code>true</code> if the text layout has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the text layout.
- * When a text layout has been disposed, it is an error to
- * invoke any other method using the text layout.
- * </p>
- *
- * @return <code>true</code> when the text layout is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- return device == null;
-}
-
-/*
- * Itemize the receiver text, create run for
- */
-StyleItem[] itemize () {
- int length = text.length();
- if (length == 0) {
- return new StyleItem[]{new StyleItem(), new StyleItem()};
- }
- int runCount = 0, start = 0;
- StyleItem[] runs = new StyleItem[length];
- char[] chars = text.toCharArray();
- for (int i = 0; i<length; i++) {
- char ch = chars[i];
- if (ch == '\t' || ch == '\r' || ch == '\n') {
- if (i != start) {
- StyleItem item = new StyleItem();
- item.start = start;
- runs[runCount++] = item;
- }
- StyleItem item = new StyleItem();
- item.start = i;
- runs[runCount++] = item;
- start = i + 1;
- }
- }
- char lastChar = chars[length - 1];
- if (!(lastChar == '\t' || lastChar == '\r' || lastChar == '\n')) {
- StyleItem item = new StyleItem();
- item.start = start;
- runs[runCount++] = item;
- }
- if (runCount != length) {
- StyleItem[] newRuns = new StyleItem[runCount];
- System.arraycopy(runs, 0, newRuns, 0, runCount);
- runs = newRuns;
- }
- runs = merge(runs, runCount);
- return runs;
-}
-
-/*
- * Merge styles ranges and script items
- */
-StyleItem[] merge (StyleItem[] items, int itemCount) {
- int length = text.length();
- int count = 0, start = 0, end = length, itemIndex = 0, styleIndex = 0;
- StyleItem[] runs = new StyleItem[itemCount + styles.length];
- while (start < end) {
- StyleItem item = new StyleItem();
- item.start = start;
- item.style = styles[styleIndex].style;
- runs[count++] = item;
- int itemLimit = itemIndex + 1 < items.length ? items[itemIndex + 1].start : length;
- int styleLimit = styleIndex + 1 < styles.length ? styles[styleIndex + 1].start : length;
- if (styleLimit <= itemLimit) {
- styleIndex++;
- start = styleLimit;
- }
- if (itemLimit <= styleLimit) {
- itemIndex++;
- start = itemLimit;
- }
- item.length = start - item.start;
- }
- StyleItem item = new StyleItem();
- item.start = end;
- runs[count++] = item;
- if (runs.length != count) {
- StyleItem[] result = new StyleItem[count];
- System.arraycopy(runs, 0, result, 0, count);
- return result;
- }
- return runs;
-}
-
-void place (StyleItem run) {
- if (run.length == 0) return;
- if (run.style != null && run.style.metrics != null) {
- GlyphMetrics glyphMetrics = run.style.metrics;
- run.width = glyphMetrics.width * run.length;
- run.baseline = glyphMetrics.ascent;
- run.height = glyphMetrics.ascent + glyphMetrics.descent;
- } else {
- char[] chars = new char[run.length];
- text.getChars(run.start, run.start + run.length, chars, 0);
- Font font = getItemFont(run);
- int fontList = font.handle;
- byte[] buffer = Converter.wcsToMbcs(font.codePage, chars, true);
- short[] width = new short[1], height = new short[1];
- int xmString = OS.XmStringCreateLocalized(buffer);
- OS.XmStringExtent(fontList, xmString, width, height);
- run.width = width[0] & 0xFFFF;
- run.height = height[0] & 0xFFFF;
- run.baseline = OS.XmStringBaseline(fontList, xmString);
- OS.XmStringFree(xmString);
- }
-}
-
-/**
- * Sets the text alignment for the receiver. The alignment controls
- * how a line of text is positioned horizontally. The argument should
- * be one of <code>SWT.LEFT</code>, <code>SWT.RIGHT</code> or <code>SWT.CENTER</code>.
- * <p>
- * The default alignment is <code>SWT.LEFT</code>. Note that the receiver's
- * width must be set in order to use <code>SWT.RIGHT</code> or <code>SWT.CENTER</code>
- * alignment.
- * </p>
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setWidth(int)
- */
-public void setAlignment (int alignment) {
- checkLayout();
- int mask = SWT.LEFT | SWT.CENTER | SWT.RIGHT;
- alignment &= mask;
- if (alignment == 0) return;
- if ((alignment & SWT.LEFT) != 0) alignment = SWT.LEFT;
- if ((alignment & SWT.RIGHT) != 0) alignment = SWT.RIGHT;
- freeRuns();
- this.alignment = alignment;
-}
-
-/**
- * Sets the ascent of the receiver. The ascent is distance in pixels
- * from the baseline to the top of the line and it is applied to all
- * lines. The default value is <code>-1</code> which means that the
- * ascent is calculated from the line fonts.
- *
- * @param ascent the new ascent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the ascent is less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setDescent(int)
- * @see #getLineMetrics(int)
- */
-public void setAscent (int ascent) {
- checkLayout();
- if (ascent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.ascent == ascent) return;
- freeRuns();
- this.ascent = ascent;
-}
-
-/**
- * Sets the descent of the receiver. The descent is distance in pixels
- * from the baseline to the bottom of the line and it is applied to all
- * lines. The default value is <code>-1</code> which means that the
- * descent is calculated from the line fonts.
- *
- * @param descent the new descent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the descent is less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAscent(int)
- * @see #getLineMetrics(int)
- */
-public void setDescent (int descent) {
- checkLayout();
- if (descent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.descent == descent) return;
- freeRuns();
- this.descent = descent;
-}
-
-/**
- * Sets the default font which will be used by the receiver
- * to draw and measure text. If the
- * argument is null, then a default font appropriate
- * for the platform will be used instead. Note that a text
- * style can override the default font.
- *
- * @param font the new font for the receiver, or null to indicate a default font
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkLayout ();
- if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Font oldFont = this.font;
- if (oldFont == font) return;
- this.font = font;
- if (oldFont != null && oldFont.equals(font)) return;
- freeRuns();
- XFontStruct fontStruct = getFontHeigth(font != null ? font : device.systemFont);
- defaultAscent = fontStruct.ascent;
- defaultDescent = fontStruct.descent;
-}
-
-/**
- * Sets the indent of the receiver. This indent it applied of the first line of
- * each paragraph.
- *
- * @param indent new indent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setIndent (int indent) {
- checkLayout();
- if (indent < 0) return;
- if (this.indent == indent) return;
- freeRuns();
- this.indent = indent;
-}
-
-/**
- * Sets the justification of the receiver. Note that the receiver's
- * width must be set in order to use justification.
- *
- * @param justify new justify
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setJustify (boolean justify) {
- checkLayout();
- if (this.justify == justify) return;
- freeRuns();
- this.justify = justify;
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setOrientation (int orientation) {
- checkLayout();
- int mask = SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT;
- orientation &= mask;
- if (orientation == 0) return;
- if ((orientation & SWT.LEFT_TO_RIGHT) != 0) orientation = SWT.LEFT_TO_RIGHT;
- this.orientation = orientation;
-}
-
-/**
- * Sets the line spacing of the receiver. The line spacing
- * is the space left between lines.
- *
- * @param spacing the new line spacing
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the spacing is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setSpacing (int spacing) {
- checkLayout();
- if (spacing < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.lineSpacing == spacing) return;
- freeRuns();
- this.lineSpacing = spacing;
-}
-
-/**
- * Sets the offsets of the receiver's text segments. Text segments are used to
- * override the default behaviour of the bidirectional algorithm.
- * Bidirectional reordering can happen within a text segment but not
- * between two adjacent segments.
- * <p>
- * Each text segment is determined by two consecutive offsets in the
- * <code>segments</code> arrays. The first element of the array should
- * always be zero and the last one should always be equals to length of
- * the text.
- * </p>
- *
- * @param segments the text segments offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setSegments(int[] segments) {
- checkLayout();
- if (this.segments == null && segments == null) return;
- if (this.segments != null && segments !=null) {
- if (this.segments.length == segments.length) {
- int i;
- for (i = 0; i <segments.length; i++) {
- if (this.segments[i] != segments[i]) break;
- }
- if (i == segments.length) return;
- }
- }
- freeRuns();
- this.segments = segments;
-}
-
-/**
- * Sets the style of the receiver for the specified range. Styles previously
- * set for that range will be overwritten. The start and end offsets are
- * inclusive and will be clamped if out of range.
- *
- * @param style the style
- * @param start the start offset
- * @param end the end offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setStyle (TextStyle style, int start, int end) {
- checkLayout();
- int length = text.length();
- if (length == 0) return;
- if (start > end) return;
- start = Math.min(Math.max(0, start), length - 1);
- end = Math.min(Math.max(0, end), length - 1);
- int low = -1;
- int high = styles.length;
- while (high - low > 1) {
- int index = (high + low) / 2;
- if (styles[index + 1].start > start) {
- high = index;
- } else {
- low = index;
- }
- }
- if (0 <= high && high < styles.length) {
- StyleItem item = styles[high];
- if (item.start == start && styles[high + 1].start - 1 == end) {
- if (style == null) {
- if (item.style == null) return;
- } else {
- if (style.equals(item.style)) return;
- }
- }
- }
- freeRuns();
- int modifyStart = high;
- int modifyEnd = modifyStart;
- while (modifyEnd < styles.length) {
- if (styles[modifyEnd + 1].start > end) break;
- modifyEnd++;
- }
- if (modifyStart == modifyEnd) {
- int styleStart = styles[modifyStart].start;
- int styleEnd = styles[modifyEnd + 1].start - 1;
- if (styleStart == start && styleEnd == end) {
- styles[modifyStart].style = style;
- return;
- }
- if (styleStart != start && styleEnd != end) {
- StyleItem[] newStyles = new StyleItem[styles.length + 2];
- System.arraycopy(styles, 0, newStyles, 0, modifyStart + 1);
- StyleItem item = new StyleItem();
- item.start = start;
- item.style = style;
- newStyles[modifyStart + 1] = item;
- item = new StyleItem();
- item.start = end + 1;
- item.style = styles[modifyStart].style;
- newStyles[modifyStart + 2] = item;
- System.arraycopy(styles, modifyEnd + 1, newStyles, modifyEnd + 3, styles.length - modifyEnd - 1);
- styles = newStyles;
- return;
- }
- }
- if (start == styles[modifyStart].start) modifyStart--;
- if (end == styles[modifyEnd + 1].start - 1) modifyEnd++;
- int newLength = styles.length + 1 - (modifyEnd - modifyStart - 1);
- StyleItem[] newStyles = new StyleItem[newLength];
- System.arraycopy(styles, 0, newStyles, 0, modifyStart + 1);
- StyleItem item = new StyleItem();
- item.start = start;
- item.style = style;
- newStyles[modifyStart + 1] = item;
- styles[modifyEnd].start = end + 1;
- System.arraycopy(styles, modifyEnd, newStyles, modifyStart + 2, styles.length - modifyEnd);
- styles = newStyles;
-}
-
-/**
- * Sets the receiver's tab list. Each value in the tab list specifies
- * the space in pixels from the origin of the text layout to the respective
- * tab stop. The last tab stop width is repeated continuously.
- *
- * @param tabs the new tab list
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setTabs (int[] tabs) {
- checkLayout();
- if (this.tabs == null && tabs == null) return;
- if (this.tabs != null && tabs !=null) {
- if (this.tabs.length == tabs.length) {
- int i;
- for (i = 0; i <tabs.length; i++) {
- if (this.tabs[i] != tabs[i]) break;
- }
- if (i == tabs.length) return;
- }
- }
- freeRuns();
- this.tabs = tabs;
-}
-
-/**
- * Sets the receiver's text.
- *<p>
- * Note: Setting the text also clears all the styles. This method
- * returns without doing anything if the new text is the same as
- * the current text.
- * </p>
- *
- * @param text the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setText (String text) {
- checkLayout();
- if (text == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (text.equals(this.text)) return;
- freeRuns();
- this.text = text;
- styles = new StyleItem[2];
- styles[0] = new StyleItem();
- styles[1] = new StyleItem();
- styles[1].start = text.length();
-}
-
-/**
- * Sets the line width of the receiver, which determines how
- * text should be wrapped and aligned. The default value is
- * <code>-1</code> which means wrapping is disabled.
- *
- * @param width the new width
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the width is <code>0</code> or less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAlignment(int)
- */
-public void setWidth (int width) {
- checkLayout();
- if (width < -1 || width == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.wrapWidth == width) return;
- freeRuns();
- this.wrapWidth = width;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "TextLayout {*DISPOSED*}";
- return "TextLayout {}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java
deleted file mode 100755
index 83b07b22ed..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java
+++ /dev/null
@@ -1,405 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal;
-
-
-import org.eclipse.swt.internal.motif.*;
-
-/**
- * This class implements the conversions between unicode characters
- * and the <em>platform supported</em> representation for characters.
- * <p>
- * Note that, unicode characters which can not be found in the platform
- * encoding will be converted to an arbitrary platform specific character.
- * </p>
- */
-
-public final class Converter {
-
- static final byte [] NULL_BYTE_ARRAY = new byte [1];
- static final byte [] EMPTY_BYTE_ARRAY = new byte [0];
- static final char [] EMPTY_CHAR_ARRAY = new char [0];
-
- static String CodePage;
- static final byte[] UCS2;
- static final byte[] UTF8;
-
- static final Object LOCK = new Object ();
-
- /* Converter cache */
- static boolean LastMbcsToUCS2Failed, LastUCS2ToMbcsFailed;
- static String LastMbcsToUCS2CodePage;
- static String LastUCS2ToMbcsCodePage;
- static int LastUCS2ToMbcs = -1;
- static int LastUTF8ToMbcs = -1;
- static int LastMbcsToUCS2 = -1;
- static int LastMbcsToUTF8 = -1;
- static int UTF8ToUCS2 = -1;
- static int UCS2ToUTF8 = -1;
-
- /* Buffers cache */
- static int BufferSize;
- static int MbcsBuffer, Ucs2Buffer, Utf8Buffer;
-
- static {
- if (OS.IsHPUX) {
- UCS2 = getAsciiBytes("ucs2");
- UTF8 = getAsciiBytes("utf8");
- } else {
- UCS2 = getAsciiBytes("UCS-2");
- UTF8 = getAsciiBytes("UTF-8");
- }
-
- int length, item = OS.nl_langinfo (OS.CODESET);
- if (item != 0 && (length = OS.strlen (item)) > 0) {
- byte [] buffer = new byte [length];
- OS.memmove (buffer, item, length);
- CodePage = new String (buffer);
- if (OS.IsSunOS) {
- if (length > 3 && CodePage.indexOf ("ISO") == 0) {
- CodePage = CodePage.substring (3, length);
- }
- }
- } else {
- if (OS.IsLinux) CodePage = "ISO-8859-1";
- else if (OS.IsAIX) CodePage = "ISO8859-1";
- else if (OS.IsSunOS) CodePage = "8859-1";
- else if (OS.IsHPUX) CodePage = "iso88591";
- else CodePage = "iso8859_1";
- }
-
- /*
- * The buffers can hold up to 512 unicode characters when converting
- * from UCS-2 to any MBCS (including UTF-8). And they can hold
- * at least 512 MBCS characters when converting from any MBCS to
- * UCS-2.
- */
- BufferSize = 512;
- Ucs2Buffer = OS.XtMalloc (BufferSize * 2);
- Utf8Buffer = OS.XtMalloc (BufferSize * 6);
- MbcsBuffer = OS.XtMalloc (BufferSize * 6);
- }
-
-/**
- * Returns the default code page for the platform where the
- * application is currently running.
- *
- * @return the default code page
- */
-public static String defaultCodePage () {
- return CodePage;
-}
-
-static byte[] getAsciiBytes (String str) {
- int length = str.length ();
- byte [] buffer = new byte [length + 1];
- for (int i=0; i<length; i++) {
- buffer [i] = (byte)str.charAt (i);
- }
- return buffer;
-}
-
-static String getAsciiString (byte [] buffer) {
- int length = buffer.length;
- char [] chars = new char [length];
- for (int i=0; i<length; i++) {
- chars [i] = (char)buffer [i];
- }
- return new String (chars);
-}
-
-/**
- * Converts an array of bytes representing the platform's encoding,
- * in the given code page, of some character data into an array of
- * matching unicode characters.
- *
- * @param codePage the code page to use for conversion
- * @param buffer the array of bytes to be converted
- * @return the unicode conversion
- */
-public static char [] mbcsToWcs (String codePage, byte [] buffer) {
-
- /* Check for the simple cases */
- if (buffer == null) {
- return EMPTY_CHAR_ARRAY;
- }
- int length = buffer.length;
- if (length == 0) {
- return EMPTY_CHAR_ARRAY;
- }
-
- /*
- * Optimize for English ASCII encoding. If no conversion is
- * performed, it is safe to return any object that will also not
- * be converted if this routine is called again with the result.
- * This ensures that double conversion will not be performed
- * on the same bytes. Note that this relies on the fact that
- * lead bytes are never in the range 0..0x7F.
- */
- char [] wideCharStr = new char [length];
- for (int i=0; i<length; i++) {
- if ((buffer [i] & 0xFF) <= 0x7F) {
- wideCharStr [i] = (char) buffer [i]; // all bytes <= 0x7F, so no ((char) (buffer[i]&0xFF)) needed
- } else {
- synchronized (LOCK) {
- /*
- * Feature in Solaris. Some Solaris machines do not provide an iconv
- * decoder/encoder that converts directly from/to any MBCS encoding to/from
- * USC-2. The fix is to convert to UTF-8 enconding first and them
- * convert to UCS-2.
- */
- String cp = codePage != null ? codePage : CodePage;
- if (cp != LastMbcsToUCS2CodePage && !cp.equals (LastMbcsToUCS2CodePage)) {
- if (LastMbcsToUCS2 != -1) OS.iconv_close (LastMbcsToUCS2);
- if (LastMbcsToUTF8 != -1) OS.iconv_close (LastMbcsToUTF8);
- LastMbcsToUCS2 = LastMbcsToUTF8 = -1;
- LastMbcsToUCS2CodePage = cp;
- LastMbcsToUCS2Failed = false;
- }
- int cd = LastMbcsToUCS2;
- if (cd == -1 && !LastMbcsToUCS2Failed) {
- cd = LastMbcsToUCS2 = OS.iconv_open (UCS2, getAsciiBytes (cp));
- }
- if (cd == -1) {
- LastMbcsToUCS2Failed = true;
- cd = UTF8ToUCS2;
- if (cd == -1) cd = UTF8ToUCS2 = OS.iconv_open (UCS2, UTF8);
- if (cd == -1) return EMPTY_CHAR_ARRAY;
- cd = LastMbcsToUTF8;
- if (cd == -1) cd = LastMbcsToUTF8 = OS.iconv_open (UTF8, getAsciiBytes (cp));
- }
- if (cd == -1) return EMPTY_CHAR_ARRAY;
- boolean utf8 = cd == LastMbcsToUTF8;
- int inByteCount = length;
- int outByteCount = utf8 ? length * 6 : length * 2;
- int ptr1 = 0, ptr2 = 0, ptr3 = 0;
- if (length <= BufferSize) {
- ptr1 = MbcsBuffer;
- ptr2 = Utf8Buffer;
- ptr3 = Ucs2Buffer;
- } else {
- ptr1 = OS.XtMalloc (inByteCount);
- if (utf8) ptr2 = OS.XtMalloc (length * 6);
- ptr3 = OS.XtMalloc (length * 2);
- }
- int ptr = utf8 ? ptr2 : ptr3;
- int [] inBuffer = {ptr1};
- int [] inBytesLeft = {inByteCount};
- int [] outBuffer = {ptr};
- int [] outBytesLeft = {outByteCount};
- OS.memmove (ptr1, buffer, inByteCount);
- OS.iconv (cd, inBuffer, inBytesLeft, outBuffer, outBytesLeft);
- outByteCount = outBuffer [0] - ptr;
- if (utf8) {
- cd = UTF8ToUCS2;
- inByteCount = outByteCount;
- outByteCount = length * 2;
- inBuffer[0] = ptr2;
- inBytesLeft[0] = inByteCount;
- outBuffer[0] = ptr3;
- outBytesLeft [0]= outByteCount;
- OS.iconv (cd, inBuffer, inBytesLeft, outBuffer, outBytesLeft);
- outByteCount = outBuffer [0] - ptr3;
- }
- wideCharStr = new char [outByteCount / 2];
- OS.memmove (wideCharStr, ptr3, outByteCount);
- if (ptr1 != 0 && ptr1 != MbcsBuffer) OS.XtFree (ptr1);
- if (ptr2 != 0 && ptr2 != Utf8Buffer) OS.XtFree (ptr2);
- if (ptr3 != 0 && ptr3 != Ucs2Buffer) OS.XtFree (ptr3);
- }
- return wideCharStr;
- }
- }
- return wideCharStr;
-}
-
-/**
- * Free any cached resources.
- */
-public static void release () {
- synchronized (LOCK) {
- if (Ucs2Buffer != 0) OS.XtFree (Ucs2Buffer);
- if (Utf8Buffer != 0) OS.XtFree (Utf8Buffer);
- if (MbcsBuffer != 0) OS.XtFree (MbcsBuffer);
- if (LastUCS2ToMbcs != -1) OS.iconv_close (LastUCS2ToMbcs);
- if (LastUTF8ToMbcs != -1) OS.iconv_close (LastUTF8ToMbcs);
- if (LastMbcsToUCS2 != -1) OS.iconv_close (LastMbcsToUCS2);
- if (LastMbcsToUTF8 != -1) OS.iconv_close (LastMbcsToUTF8);
- if (UTF8ToUCS2 != -1) OS.iconv_close (UTF8ToUCS2);
- if (UCS2ToUTF8 != -1) OS.iconv_close (UCS2ToUTF8);
- LastUCS2ToMbcs = LastUTF8ToMbcs = LastMbcsToUCS2 = LastMbcsToUTF8 = UTF8ToUCS2 = UCS2ToUTF8 -1;
- Ucs2Buffer = Utf8Buffer = MbcsBuffer = 0;
- }
-}
-
-/**
- * Converts an array of chars (containing unicode data) to an array
- * of bytes representing the platform's encoding, of those characters
- * in the given code page.
- *
- * @param codePage the code page to use for conversion
- * @param buffer the array of chars to be converted
- * @return the platform encoding
- */
-public static byte [] wcsToMbcs (String codePage, char [] buffer) {
- return wcsToMbcs (codePage, buffer, false);
-}
-
-/**
- * Converts an array of chars (containing unicode data) to an array
- * of bytes representing the platform's encoding, of those characters
- * in the given code page. If the termination flag is true, the resulting
- * byte data will be null (zero) terminated.
- *
- * @param codePage the code page to use for conversion
- * @param buffer the array of chars to be converted
- * @param terminate <code>true</code> if the result should be null terminated and false otherwise.
- * @return the platform encoding
- */
-public static byte [] wcsToMbcs (String codePage, char [] buffer, boolean terminate) {
-
- /* Check for the simple cases */
- if (buffer == null) {
- return (terminate) ? NULL_BYTE_ARRAY : EMPTY_BYTE_ARRAY;
- }
- int length = buffer.length;
- if (length == 0) {
- return (terminate) ? NULL_BYTE_ARRAY : EMPTY_BYTE_ARRAY;
- }
-
- /*
- * Optimize for English ASCII encoding. This optimization
- * relies on the fact that lead bytes can never be in the
- * range 0..0x7F.
- */
- byte [] mbcs = new byte [(terminate) ? length + 1 : length];
- for (int i=0; i<length; i++) {
- if ((buffer [i] & 0xFFFF) <= 0x7F) {
- mbcs [i] = (byte) buffer [i];
- } else {
- synchronized (LOCK) {
- /*
- * Feature in Solaris. Some Solaris machines do not provide an iconv
- * decoder/encoder that converts directly from/to any MBCS encoding to/from
- * USC-2. The fix is to convert to UTF-8 enconding first and them
- * convert to UCS-2.
- */
- String cp = codePage != null ? codePage : CodePage;
- if (cp != LastUCS2ToMbcsCodePage && !cp.equals (LastUCS2ToMbcsCodePage)) {
- if (LastUCS2ToMbcs != -1) OS.iconv_close (LastUCS2ToMbcs);
- if (LastUTF8ToMbcs != -1) OS.iconv_close (LastUTF8ToMbcs);
- LastUCS2ToMbcs = LastUTF8ToMbcs = -1;
- LastUCS2ToMbcsCodePage = cp;
- }
- int cd = LastUCS2ToMbcs;
- if (cd == -1 && !LastUCS2ToMbcsFailed) {
- cd = LastUCS2ToMbcs = OS.iconv_open (getAsciiBytes (cp), UCS2);
- }
- if (cd == -1) {
- LastUCS2ToMbcsFailed = true;
- cd = LastUTF8ToMbcs;
- if (cd == -1) cd = LastUTF8ToMbcs = OS.iconv_open (getAsciiBytes (cp), UTF8);
- if (cd == -1) return (terminate) ? NULL_BYTE_ARRAY : EMPTY_BYTE_ARRAY;
- cd = UCS2ToUTF8;
- if (cd == -1) cd = UCS2ToUTF8 = OS.iconv_open (UTF8, UCS2);
- }
- if (cd == -1) return (terminate) ? NULL_BYTE_ARRAY : EMPTY_BYTE_ARRAY;
- boolean utf8 = cd == UCS2ToUTF8;
- int inByteCount = length * 2;
- int outByteCount = length * 6;
- int ptr1 = 0, ptr2 = 0, ptr3 = 0;
- if (length <= BufferSize) {
- ptr1 = Ucs2Buffer;
- ptr2 = Utf8Buffer;
- ptr3 = MbcsBuffer;
- } else {
- ptr1 = OS.XtMalloc (inByteCount);
- if (utf8) ptr2 = OS.XtMalloc (outByteCount);
- ptr3 = OS.XtMalloc (outByteCount);
- }
- int ptr = utf8 ? ptr2 : ptr3;
- int [] inBuffer = {ptr1};
- int [] inBytesLeft = {inByteCount};
- int [] outBuffer = {ptr};
- int [] outBytesLeft = {outByteCount};
- OS.memmove (ptr1, buffer, inByteCount);
- while (inBytesLeft [0] > 0) {
- OS.iconv (cd, inBuffer, inBytesLeft, outBuffer, outBytesLeft);
- if (inBytesLeft [0] != 0) {
- inBuffer [0] += 2;
- inBytesLeft [0] -= 2;
- }
- }
- outByteCount = outBuffer [0] - ptr;
- if (utf8) {
- cd = LastUTF8ToMbcs;
- inByteCount = outByteCount;
- outByteCount = length * 6;
- inBuffer[0] = ptr2;
- inBytesLeft[0] = inByteCount;
- outBuffer[0] = ptr3;
- outBytesLeft [0]= outByteCount;
- OS.iconv (cd, inBuffer, inBytesLeft, outBuffer, outBytesLeft);
- outByteCount = outBuffer [0] - ptr3;
- }
- mbcs = new byte [terminate ? outByteCount + 1 : outByteCount];
- OS.memmove (mbcs, ptr3, outByteCount);
- if (ptr1 != 0 && ptr1 != Ucs2Buffer) OS.XtFree (ptr1);
- if (ptr2 != 0 && ptr2 != Utf8Buffer) OS.XtFree (ptr2);
- if (ptr3 != 0 && ptr3 != MbcsBuffer) OS.XtFree (ptr3);
- }
- return mbcs;
- }
- }
- return mbcs;
-}
-
-/**
- * Converts a String (containing unicode data) to an array
- * of bytes representing the platform's encoding, of those characters
- * in the given code page.
- *
- * @param codePage the code page to use for conversion
- * @param string the string to be converted
- * @return the platform encoding
- */
-public static byte [] wcsToMbcs (String codePage, String string) {
- return wcsToMbcs (codePage, string, false);
-}
-
-/**
- * Converts a String (containing unicode data) to an array
- * of bytes representing the platform's encoding, of those characters
- * in the given code page. If the termination flag is true, the resulting
- * byte data will be null (zero) terminated.
- *
- * @param codePage the code page to use for conversion
- * @param string the string to be converted
- * @param terminate <code>true</code> if the result should be null terminated and false otherwise.
- * @return the platform encoding
- */
-public static byte [] wcsToMbcs (String codePage, String string, boolean terminate) {
- if (terminate) {
- if (string == null) return NULL_BYTE_ARRAY;
- int count = string.length ();
- char [] buffer = new char [count + 1];
- string.getChars (0, count, buffer, 0);
- return wcsToMbcs (codePage, buffer, false);
- } else {
- if (string == null) return EMPTY_BYTE_ARRAY;
- int count = string.length ();
- char [] buffer = new char [count];
- string.getChars (0, count, buffer, 0);
- return wcsToMbcs (codePage, buffer, false);
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java
deleted file mode 100755
index 2c10e59b0b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java
+++ /dev/null
@@ -1,859 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface object that
- * issues notification when pressed and released.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>ARROW, CHECK, PUSH, RADIO, TOGGLE, FLAT</dd>
- * <dd>UP, DOWN, LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles ARROW, CHECK, PUSH, RADIO, and TOGGLE
- * may be specified.
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT, and CENTER may be specified.
- * </p><p>
- * Note: Only one of the styles UP, DOWN, LEFT, and RIGHT may be specified
- * when the ARROW style is specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#button">Button snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Button extends Control {
- String text = "";
- Image image, bitmap, disabled;
- boolean grayed;
- static final byte [] ARM_AND_ACTIVATE;
- static {
- String name = "ArmAndActivate";
- int length = name.length();
- char [] unicode = new char [length];
- name.getChars (0, length, unicode, 0);
- byte [] buffer = new byte [length + 1];
- for (int i = 0; i < length; i++) {
- buffer[i] = (byte) unicode[i];
- }
- ARM_AND_ACTIVATE = buffer;
- }
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#ARROW
- * @see SWT#CHECK
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#TOGGLE
- * @see SWT#FLAT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Button (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-void _setImage (Image image) {
- int labelPixmap = OS.XmUNSPECIFIED_PIXMAP;
- int labelInsensitivePixmap = OS.XmUNSPECIFIED_PIXMAP;
- if (bitmap != null) bitmap.dispose ();
- if (disabled != null) disabled.dispose ();
- bitmap = disabled = null;
- if (image != null) {
- if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- switch (image.type) {
- case SWT.BITMAP:
- ImageData data;
- if (image.mask == 0 && (data = image.getImageData ()).alpha == -1 && data.alphaData == null && data.transparentPixel == -1) {
- labelPixmap = image.pixmap;
- disabled = new Image (display, image, SWT.IMAGE_DISABLE);
- labelInsensitivePixmap = disabled.pixmap;
- break;
- }
- //FALL THROUGH
- case SWT.ICON:
- Rectangle rect = image.getBounds ();
- bitmap = new Image (display, rect.width, rect.height);
- GC gc = new GC (bitmap);
- gc.setBackground (getBackground ());
- gc.fillRectangle (rect);
- gc.drawImage (image, 0, 0);
- gc.dispose ();
- labelPixmap = bitmap.pixmap;
- disabled = new Image (display, bitmap, SWT.IMAGE_DISABLE);
- labelInsensitivePixmap = disabled.pixmap;
- break;
- default:
- error (SWT.ERROR_NOT_IMPLEMENTED);
- }
- }
- int [] argList = {
- OS.XmNlabelType, image == null ? OS.XmSTRING : OS.XmPIXMAP,
- OS.XmNlabelPixmap, labelPixmap,
- OS.XmNlabelInsensitivePixmap, labelInsensitivePixmap,
- };
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-void _setText (String string) {
- char [] text = new char [string.length ()];
- string.getChars (0, text.length, text, 0);
- int mnemonic = fixMnemonic (text);
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), text, true);
- int xmString = OS.XmStringParseText (
- buffer,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- if (xmString == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- if (mnemonic == 0) mnemonic = OS.XK_VoidSymbol;
- int [] argList = {
- OS.XmNlabelType, OS.XmSTRING,
- OS.XmNlabelString, xmString,
- OS.XmNmnemonic, mnemonic,
- };
- OS.XtSetValues (handle, argList, argList.length / 2);
- if (xmString != 0) OS.XmStringFree (xmString);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected by the user.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-static int checkStyle (int style) {
- style = checkBits (style, SWT.PUSH, SWT.ARROW, SWT.CHECK, SWT.RADIO, SWT.TOGGLE, 0);
- if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) {
- return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0);
- }
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0);
- }
- if ((style & SWT.ARROW) != 0) {
- style |= SWT.NO_FOCUS;
- return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0);
- }
- return style;
-}
-void click () {
- int event = OS.XtMalloc (XEvent.sizeof);
- OS.XtCallActionProc (handle, ARM_AND_ACTIVATE, event, null, 0);
- OS.XtFree (event);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- if ((style & SWT.ARROW) != 0) {
- width += display.scrolledMarginX;
- height += display.scrolledMarginY;
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
- }
- XtWidgetGeometry result = new XtWidgetGeometry ();
- result.request_mode = OS.CWWidth | OS.CWHeight;
- int [] argList2 = {OS.XmNrecomputeSize, 1};
- OS.XtSetValues(handle, argList2, argList2.length / 2);
- OS.XtQueryGeometry (handle, null, result);
- int [] argList3 = {OS.XmNrecomputeSize, 0};
- OS.XtSetValues(handle, argList3, argList3.length / 2);
- width += result.width;
- height += result.height;
- /*
- * Feature in Motif. If a button's labelType is XmSTRING but it
- * has no label set into it yet, recomputing the size will
- * not take into account the height of the font, as we would
- * like it to. Take care of this case.
- */
- int [] argList = {OS.XmNlabelType, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] == OS.XmSTRING) {
- int [] argList1 = {OS.XmNlabelString, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int xmString = argList1 [1];
- if (xmString != 0) {
- if (OS.XmStringEmpty (xmString)) {
- int xmString2 = OS.XmStringCreateLocalized (new byte[]{' ', '\0'});
- if (xmString2 != 0) {
- height += OS.XmStringHeight (font.handle, xmString2);
- OS.XmStringFree(xmString2);
- }
- }
- OS.XmStringFree (xmString);
- }
- }
- if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) {
- int [] argList4 = new int [] {
- OS.XmNmarginLeft, 0,
- OS.XmNmarginRight, 0,
- OS.XmNmarginTop, 0,
- OS.XmNmarginBottom, 0,
- };
- OS.XtGetValues (handle, argList4, argList4.length / 2);
- if (wHint != SWT.DEFAULT) width = wHint + argList4 [1] + argList4 [3] + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + argList4 [5] + argList4 [7] + (border * 2);
- }
- return new Point (width, height);
-}
-void createHandle (int index) {
- if ((style & SWT.PUSH) == 0) state |= THEME_BACKGROUND;
- int borderWidth = (style & SWT.BORDER) != 0 ? 1 : 0;
- int parentHandle = parent.handle;
-
- /* ARROW button */
- if ((style & SWT.ARROW) != 0) {
- int alignment = OS.XmARROW_UP;
- if ((style & SWT.UP) != 0) alignment = OS.XmARROW_UP;
- if ((style & SWT.DOWN) != 0) alignment = OS.XmARROW_DOWN;
- if ((style & SWT.LEFT) != 0) alignment = OS.XmARROW_LEFT;
- if ((style & SWT.RIGHT) != 0) alignment = OS.XmARROW_RIGHT;
- int [] argList = {
- OS.XmNtraversalOn, 0,
- OS.XmNarrowDirection, alignment,
- OS.XmNborderWidth, borderWidth,
- OS.XmNancestorSensitive, 1,
- };
- handle = OS.XmCreateArrowButton (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.FLAT) != 0) {
- int [] argList1 = {OS.XmNbottomShadowColor, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int [] argList2 = {
- OS.XmNshadowThickness, 1,
- OS.XmNtopShadowColor, argList1 [1],
- };
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- }
- return;
- }
-
- /* Compute alignment */
- int alignment = OS.XmALIGNMENT_BEGINNING;
- if ((style & SWT.CENTER) != 0) alignment = OS.XmALIGNMENT_CENTER;
- if ((style & SWT.RIGHT) != 0) alignment = OS.XmALIGNMENT_END;
-
- /* TOGGLE button */
- if ((style & SWT.TOGGLE) != 0) {
- /*
- * Bug in Motif. When XmNindicatorOn is set to false,
- * Motif doesn't reset the shadow thickness to give a
- * push button look. The fix is to set the shadow
- * thickness when ever this resource is changed.
- */
- int thickness = display.buttonShadowThickness;
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNrecomputeSize, 0,
- OS.XmNindicatorOn, 0,
- OS.XmNshadowThickness, (style & SWT.FLAT) != 0 ? 1 : thickness,
- OS.XmNalignment, alignment,
- OS.XmNborderWidth, borderWidth,
- };
- handle = OS.XmCreateToggleButton (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.FLAT) != 0) {
- int [] argList1 = {OS.XmNbottomShadowColor, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int [] argList2 = {OS.XmNtopShadowColor, argList1 [1]};
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- }
- return;
- }
-
- /* CHECK or RADIO button */
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- /*
- * Bug in Motif. For some reason, a toggle button
- * with XmNindicatorType XmONE_OF_MANY must have this
- * value set at creation or the highlight color will
- * not be correct. The fix is to set these values
- * on create.
- */
- int indicatorType = OS.XmONE_OF_MANY;
- if ((style & SWT.CHECK) != 0) indicatorType = OS.XmN_OF_MANY;
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNrecomputeSize, 0,
- OS.XmNindicatorType, indicatorType,
- OS.XmNalignment, alignment,
- OS.XmNborderWidth, borderWidth,
- };
- handle = OS.XmCreateToggleButton (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- return;
- }
-
- /* PUSH button */
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNrecomputeSize, 0,
- OS.XmNalignment, alignment,
- OS.XmNborderWidth, borderWidth,
- /*
- * This code is intentionally commented. On some
- * platforms, the standard behavior is that push
- * buttons are tab groups, traversed with the tab
- * key. On Motif, push buttons are tab items,
- * that are traversed with the arrow keys. This
- * behavior is unspecifed so the line remains
- * commented.
- */
-// OS.XmNnavigationType, OS.XmTAB_GROUP,
- };
- handle = OS.XmCreatePushButton (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.FLAT) != 0) {
- int [] argList1 = {OS.XmNbottomShadowColor, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int [] argList2 = {
- OS.XmNshadowThickness, 1,
- OS.XmNtopShadowColor, argList1 [1],
- };
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- }
-}
-void createWidget (int index) {
- super.createWidget (index);
- if ((style & SWT.PUSH) == 0) return;
- if (getShell ().parent == null) return;
- int [] argList = new int [] {OS.XmNdefaultButtonShadowThickness, 1};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-int defaultBackground () {
- return display.buttonBackground;
-}
-Font defaultFont () {
- return display.buttonFont;
-}
-int defaultForeground () {
- return display.buttonForeground;
-}
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is an <code>ARROW</code> button, in
- * which case, the alignment will indicate the direction of
- * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>,
- * <code>UP</code> or <code>DOWN</code>).
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget();
- if ((style & SWT.ARROW) != 0) {
- int [] argList = {OS.XmNarrowDirection, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int direction = argList [1];
- if (direction == OS.XmARROW_UP) return SWT.UP;
- if (direction == OS.XmARROW_DOWN) return SWT.DOWN;
- if (direction == OS.XmARROW_LEFT) return SWT.LEFT;
- if (direction == OS.XmARROW_RIGHT) return SWT.RIGHT;
- return SWT.UP;
- }
- int [] argList = {OS.XmNalignment, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int alignment = argList [1];
- if (alignment == OS.XmALIGNMENT_BEGINNING) return SWT.LEFT;
- if (alignment == OS.XmALIGNMENT_CENTER) return SWT.CENTER;
- if (alignment == OS.XmALIGNMENT_END)return SWT.RIGHT;
- return SWT.CENTER;
-}
-boolean getDefault () {
- if ((style & SWT.PUSH) == 0) return false;
-// int [] argList = {OS.XmNshowAsDefault, 0};
-// OS.XtGetValues (handle, argList, argList.length / 2);
-// return argList [1] != 0;
- return this == menuShell ().defaultButton;
-}
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the widget does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getGrayed () {
- checkWidget();
- if ((style & SWT.CHECK) == 0) return false;
- return grayed;
-}
-/**
- * Returns the receiver's image if it has one, or null
- * if it does not.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-String getNameText () {
- return getText ();
-}
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked. When it is of type <code>TOGGLE</code>,
- * it is selected when it is pushed in. If the receiver is of any other type,
- * this method returns false.
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false;
- int [] argList = {OS.XmNset, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] != OS.XmUNSET;
-}
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set or if the receiver is
- * an <code>ARROW</code> button.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- if ((style & SWT.ARROW) != 0) return "";
- return text;
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) != 0) {
- OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
- } else {
- OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK);
- }
-
-}
-boolean mnemonicHit (char key) {
- if (!setFocus ()) return false;
- click ();
- return true;
-}
-boolean mnemonicMatch (char key) {
- char mnemonic = findMnemonic (getText ());
- if (mnemonic == '\0') return false;
- return Character.toUpperCase (key) == Character.toUpperCase (mnemonic);
-}
-void releaseWidget () {
- super.releaseWidget ();
- int [] argList = {
- OS.XmNlabelPixmap, OS.XmUNSPECIFIED_PIXMAP,
- OS.XmNlabelInsensitivePixmap, OS.XmUNSPECIFIED_PIXMAP,
- };
- OS.XtSetValues (handle, argList, argList.length / 2);
- if (bitmap != null) bitmap.dispose ();
- if (disabled != null) disabled.dispose ();
- image = bitmap = disabled = null;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-void selectRadio () {
- /*
- * This code is intentionally commented. When two groups
- * of radio buttons with the same parent are separated by
- * another control, the correct behavior should be that
- * the two groups act independently. This is consistent
- * with radio tool and menu items. The commented code
- * implements this behavior.
- */
-// int index = 0;
-// Control [] children = parent._getChildren ();
-// while (index < children.length && children [index] != this) index++;
-// int i = index - 1;
-// while (i >= 0 && children [i].setRadioSelection (false)) --i;
-// int j = index + 1;
-// while (j < children.length && children [j].setRadioSelection (false)) j++;
-// setSelection (true);
- Control [] children = parent._getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (this != child) child.setRadioSelection (false);
- }
- setSelection (true);
-}
-/**
- * Controls how text, images and arrows will be displayed
- * in the receiver. The argument should be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is an <code>ARROW</code> button, in
- * which case, the argument indicates the direction of
- * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>,
- * <code>UP</code> or <code>DOWN</code>).
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget();
- if ((style & SWT.ARROW) != 0) {
- int [] argList = {OS.XmNarrowDirection, OS.XmARROW_UP};
- if ((alignment & SWT.UP) != 0) argList [1] = OS.XmARROW_UP;
- if ((alignment & SWT.DOWN) != 0) argList [1] = OS.XmARROW_DOWN;
- if ((alignment & SWT.LEFT) != 0) argList [1] = OS.XmARROW_LEFT;
- if ((alignment & SWT.RIGHT) != 0) argList [1] = OS.XmARROW_RIGHT;
- OS.XtSetValues (handle, argList, argList.length / 2);
- return;
- }
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- int [] argList = {OS.XmNalignment, OS.XmALIGNMENT_BEGINNING};
- if ((alignment & SWT.CENTER) != 0) argList [1] = OS.XmALIGNMENT_CENTER;
- if ((alignment & SWT.RIGHT) != 0) argList [1] = OS.XmALIGNMENT_END;
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- if ((style & SWT.FLAT) != 0) {
- int [] argList1 = {OS.XmNbottomShadowColor, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int [] argList2 = {OS.XmNtopShadowColor, argList1 [1]};
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- }
- int [] argList = {OS.XmNlabelType, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] == OS.XmPIXMAP) _setImage (image);
-}
-
-void setDefault (boolean value) {
- if ((style & SWT.PUSH) == 0) return;
- if (getShell ().parent == null) return;
- int [] argList = {OS.XmNshowAsDefault, (value ? 1 : 0)};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-public void setFont (Font font) {
- checkWidget();
-
- /*
- * Bug in Motif. Setting the font in a button widget that does
- * not have a non-empty string causes GP on UTF-8 locale.
- * The fix is to set a non-empty string, change the font,
- * and restore the empty string at the end.
- */
- int [] argList1 = {OS.XmNlabelString, 0, OS.XmNlabelType, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- boolean fixString = OS.IsDBLocale && OS.XmStringEmpty (argList1 [1]);
- if (fixString) {
- byte[] buffer = Converter.wcsToMbcs (getCodePage (), "string", true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- int [] argList2 = {
- OS.XmNlabelType, OS.XmSTRING,
- OS.XmNlabelString, xmString,
- };
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- OS.XmStringFree (xmString);
- }
- super.setFont (font);
- if (fixString) OS.XtSetValues (handle, argList1, argList1.length / 2);
-}
-/**
- * Sets the grayed state of the receiver. This state change
- * only applies if the control was created with the SWT.CHECK
- * style.
- *
- * @param grayed the new grayed state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setGrayed (boolean grayed) {
- checkWidget();
- if ((style & SWT.CHECK) == 0) return;
- this.grayed = grayed;
-}
-/**
- * Sets the receiver's image to the argument, which may be
- * <code>null</code> indicating that no image should be displayed.
- * <p>
- * Note that a Button can display an image and text simultaneously
- * on Windows (starting with XP), GTK+ and OSX. On other platforms,
- * a Button that has an image and text set into it will display the
- * image or text that was set most recently.
- * </p>
- * @param image the image to display on the receiver (may be <code>null</code>)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.ARROW) != 0) return;
- this.image = image;
- /* This code is intentionally commented*/
-// if (image == null || text.length () != 0) {
-// _setText (text);
-// return;
-// }
- _setImage (image);
-}
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-/**
- * Sets the selection state of the receiver, if it is of type <code>CHECK</code>,
- * <code>RADIO</code>, or <code>TOGGLE</code>.
- *
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked. When it is of type <code>TOGGLE</code>,
- * it is selected when it is pushed in.
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return;
- int [] argList = {OS.XmNset, selected ? OS.XmSET : OS.XmUNSET};
- OS.XtSetValues (handle, argList, argList.length / 2);
- updateShadows ();
-}
-/**
- * Sets the receiver's text.
- * <p>
- * This method sets the button label. The label may include
- * the mnemonic character but must not contain line delimiters.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasized in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p><p>
- * Note that a Button can display an image and text simultaneously
- * on Windows (starting with XP), GTK+ and OSX. On other platforms,
- * a Button that has an image and text set into it will display the
- * image or text that was set most recently.
- * </p>
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.ARROW) != 0) return;
- /*
- * Feature in Motif. Motif does not optimize the case
- * when the same text is set into a button causing
- * it to flash. The fix is to test for equality and
- * do nothing.
- */
- if (text.equals (string)) return;
- text = string;
- /* This code is intentionally commented*/
-// if (text.length () == 0 && image != null) {
-// _setImage (image);
-// return;
-// }
- _setText (string);
-}
-int traversalCode (int key, XKeyEvent xEvent) {
- return super.traversalCode (key, xEvent) | SWT.TRAVERSE_MNEMONIC;
-}
-void updateShadows () {
- if ((style & SWT.FLAT) != 0 && (style & SWT.TOGGLE) != 0) {
- int [] argList1 = {OS.XmNset, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int pixel = argList1 [1] == OS.XmUNSET ? display.compositeBottomShadow : display.compositeTopShadow;
- int [] argList2 = {OS.XmNtopShadowColor, pixel};
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- }
-}
-int xFocusIn (XFocusChangeEvent xEvent) {
- super.xFocusIn (xEvent);
- // widget could be disposed at this point
- if (handle == 0) return 0;
- if ((style & SWT.PUSH) != 0) {
- menuShell ().setDefaultButton (this, false);
- }
- return 0;
-}
-int xFocusOut (XFocusChangeEvent xEvent) {
- super.xFocusOut (xEvent);
- // widget could be disposed at this point
- if (handle == 0) return 0;
- if ((style & SWT.PUSH) != 0 && getDefault ()) {
- menuShell ().setDefaultButton (null, false);
- }
- return 0;
-}
-int XmNactivateCallback (int w, int client_data, int call_data) {
- postEvent (SWT.Selection);
- return 0;
-}
-int XmNvalueChangedCallback (int w, int client_data, int call_data) {
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) {
- selectRadio ();
- }
- }
- updateShadows ();
- postEvent (SWT.Selection);
- return 0;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java
deleted file mode 100755
index 439c284228..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java
+++ /dev/null
@@ -1,329 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide a surface for drawing
- * arbitrary graphics.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * This class may be subclassed by custom control implementors
- * who are building controls that are <em>not</em> constructed
- * from aggregates of other controls. That is, they are either
- * painted using SWT graphics calls or are handled by native
- * methods.
- * </p>
- *
- * @see Composite
- * @see <a href="http://www.eclipse.org/swt/snippets/#canvas">Canvas snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class Canvas extends Composite {
- Caret caret;
- IME ime;
-
-Canvas () {
- /* Do nothing */
-}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Canvas (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-/**
- * Fills the interior of the rectangle specified by the arguments,
- * with the receiver's background.
- *
- * @param gc the gc where the rectangle is to be filled
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void drawBackground (GC gc, int x, int y, int width, int height) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- super.drawBackground (gc, x, y, width, height);
-}
-/**
- * Returns the caret.
- * <p>
- * The caret for the control is automatically hidden
- * and shown when the control is painted or resized,
- * when focus is gained or lost and when an the control
- * is scrolled. To avoid drawing on top of the caret,
- * the programmer must hide and show the caret when
- * drawing in the window any other time.
- * </p>
- *
- * @return the caret for the receiver, may be null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Caret getCaret () {
- checkWidget();
- return caret;
-}
-/**
- * Returns the IME.
- *
- * @return the IME
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public IME getIME () {
- checkWidget ();
- return ime;
-}
-Caret getIMCaret () {
- return caret;
-}
-void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean allChildren, boolean trim) {
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- super.redrawWidget (x, y, width, height, redrawAll, allChildren, trim);
- if (isFocus) caret.setFocus ();
-}
-
-void releaseChildren (boolean destroy) {
- if (caret != null) {
- caret.release (false);
- caret = null;
- }
- if (ime != null) {
- ime.release (false);
- ime = null;
- }
- super.releaseChildren (destroy);
-}
-
-/**
- * Scrolls a rectangular area of the receiver by first copying
- * the source area to the destination and then causing the area
- * of the source which is not covered by the destination to
- * be repainted. Children that intersect the rectangle are
- * optionally moved during the operation. In addition, outstanding
- * paint events are flushed before the source area is copied to
- * ensure that the contents of the canvas are drawn correctly.
- *
- * @param destX the x coordinate of the destination
- * @param destY the y coordinate of the destination
- * @param x the x coordinate of the source
- * @param y the y coordinate of the source
- * @param width the width of the area
- * @param height the height of the area
- * @param all <code>true</code>if children should be scrolled, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) {
- checkWidget();
- if (width <= 0 || height <= 0) return;
- int deltaX = destX - x, deltaY = destY - y;
- if (deltaX == 0 && deltaY == 0) return;
- if (!isVisible ()) return;
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (Math.min(x + width, argList [1]) >= Math.max (x, 0) && Math.min(y + height, 0 + argList [3]) >= Math.max (y, 0)) {
- int xEvent = OS.XtMalloc (XEvent.sizeof);
- OS.XSync (xDisplay, false);
- OS.XSync (xDisplay, false);
- while (OS.XCheckWindowEvent (xDisplay, xWindow, OS.ExposureMask, xEvent)) {
- OS.XtDispatchEvent (xEvent);
- }
- OS.XtFree (xEvent);
- }
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- if (control.backgroundImage != null) {
- redrawWidget (x, y, width, height, false, false, false);
- redrawWidget (destX, destY, width, height, false, false, false);
- } else {
- int xGC = OS.XCreateGC (xDisplay, xWindow, 0, null);
- OS.XCopyArea (xDisplay, xWindow, xWindow, xGC, x, y, width, height, destX, destY);
- OS.XFreeGC (xDisplay, xGC);
- boolean disjoint = (destX + width < x) || (x + width < destX) || (destY + height < y) || (y + height < destY);
- if (disjoint) {
- OS.XClearArea (xDisplay, xWindow, x, y, width, height, true);
- } else {
- if (deltaX != 0) {
- int newX = destX - deltaX;
- if (deltaX < 0) newX = destX + width;
- OS.XClearArea (xDisplay, xWindow, newX, y, Math.abs (deltaX), height, true);
- }
- if (deltaY != 0) {
- int newY = destY - deltaY;
- if (deltaY < 0) newY = destY + height;
- OS.XClearArea (xDisplay, xWindow, x, newY, width, Math.abs (deltaY), true);
- }
- }
- }
- if (all) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- Rectangle rect = child.getBounds ();
- if (Math.min(x + width, rect.x + rect.width) >= Math.max (x, rect.x) &&
- Math.min(y + height, rect.y + rect.height) >= Math.max (y, rect.y)) {
- child.setLocation (rect.x + deltaX, rect.y + deltaY);
- }
- }
- }
- if (isFocus) caret.setFocus ();
-}
-/**
- * Sets the receiver's caret.
- * <p>
- * The caret for the control is automatically hidden
- * and shown when the control is painted or resized,
- * when focus is gained or lost and when an the control
- * is scrolled. To avoid drawing on top of the caret,
- * the programmer must hide and show the caret when
- * drawing in the window any other time.
- * </p>
- * @param caret the new caret for the receiver, may be null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the caret has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCaret (Caret caret) {
- checkWidget();
- Caret newCaret = caret;
- Caret oldCaret = this.caret;
- this.caret = newCaret;
- if (hasFocus ()) {
- if (oldCaret != null) oldCaret.killFocus ();
- if (newCaret != null) {
- if (newCaret.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- newCaret.setFocus ();
- }
- }
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- boolean changed = super.setBounds (x, y, width, height, move, resize);
- if (isFocus) caret.setFocus ();
- return changed;
-}
-public void setFont (Font font) {
- checkWidget();
- if (caret != null) caret.setFont (font);
- super.setFont (font);
-}
-/**
- * Sets the receiver's IME.
- *
- * @param ime the new IME for the receiver, may be null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the IME has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setIME (IME ime) {
- checkWidget ();
- if (ime != null && ime.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- this.ime = ime;
-}
-int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) {
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- int result = super.XExposure (w, client_data, call_data, continue_to_dispatch);
- if (isFocus) caret.setFocus ();
- return result;
-}
-int xFocusIn (XFocusChangeEvent xEvent) {
- int result = super.xFocusIn (xEvent);
- if (caret != null) caret.setFocus ();
- return result;
-}
-int xFocusOut (XFocusChangeEvent xEvent) {
- int result = super.xFocusOut (xEvent);
- if (caret != null) caret.killFocus ();
- return result;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java
deleted file mode 100755
index f875f34b10..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java
+++ /dev/null
@@ -1,480 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide an i-beam that is typically used
- * as the insertion point for text.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#caret">Caret snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Canvas tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Caret extends Widget {
- Canvas parent;
- int x, y, width, height;
- boolean isVisible, isShowing;
- int blinkRate;
- Image image;
- Font font;
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Caret (Canvas parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget (0);
-}
-boolean blinkCaret () {
- if (!isVisible) return true;
- if (!isShowing) return showCaret ();
- if (blinkRate == 0) return true;
- return hideCaret ();
-}
-void createWidget (int index) {
- super.createWidget (index);
- blinkRate = display.getCaretBlinkTime ();
- isVisible = true;
- if (parent.getCaret () == null) {
- parent.setCaret (this);
- }
-}
-boolean drawCaret () {
- if (parent == null) return false;
- if (parent.isDisposed ()) return false;
- int handle = parent.handle;
- int window = OS.XtWindow (handle);
- if (window == 0) return false;
- int xDisplay = OS.XtDisplay (handle);
- int gc = OS.XCreateGC (xDisplay, window, 0, null);
- int color;
- if (OS.IsSunOS) {
- int foreground = parent.getForegroundPixel ();
- Control control = parent.findBackgroundControl ();
- if (control == null) control = parent;
- int background = control.getBackgroundPixel ();
- color = foreground ^ background;
- } else {
- int screenNum = OS.XDefaultScreen (xDisplay);
- color = OS.XWhitePixel(xDisplay, screenNum);
- }
- OS.XSetForeground (xDisplay, gc, color);
- OS.XSetFunction (xDisplay, gc, OS.GXxor);
- if (image != null && !image.isDisposed() && image.mask == 0) {
- int [] unused = new int [1]; int [] width = new int [1]; int [] height = new int [1];
- OS.XGetGeometry (xDisplay, image.pixmap, unused, unused, unused, width, height, unused, unused);
- OS.XCopyArea(xDisplay, image.pixmap, window, gc, 0, 0, width[0], height[0], x, y);
- } else {
- int nWidth = width, nHeight = height;
- if (nWidth <= 0) nWidth = 1;
- OS.XFillRectangle (xDisplay, window, gc, x, y, nWidth, nHeight);
- }
- OS.XFreeGC (xDisplay, gc);
- return true;
-}
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null).
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- if (image != null) {
- Rectangle rect = image.getBounds ();
- return new Rectangle (x, y, rect.width, rect.height);
- }
- return new Rectangle (x, y, width, height);
-}
-/**
- * Returns the font that the receiver will use to paint textual information.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Font getFont () {
- checkWidget();
- if (font != null) return font;
- return parent.getFont ();
-}
-/**
- * Returns the image that the receiver will use to paint the caret.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null).
- *
- * @return the receiver's location
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getLocation () {
- checkWidget();
- return new Point (x, y);
-}
-/**
- * Returns the receiver's parent, which must be a <code>Canvas</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Canvas getParent () {
- checkWidget();
- return parent;
-}
-/**
- * Returns a point describing the receiver's size.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- if (image != null) {
- Rectangle rect = image.getBounds ();
- return new Point (rect.width, rect.height);
- }
- return new Point (width, height);
-}
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- return isVisible;
-}
-boolean hideCaret () {
- if (!isShowing) return true;
- isShowing = false;
- return drawCaret ();
-}
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return isVisible && parent.isVisible () && parent.hasFocus ();
-}
-boolean isFocusCaret () {
- return this == display.currentCaret;
-}
-void killFocus () {
- if (display.currentCaret != this) return;
- display.setCurrentCaret (null);
- if (isVisible) hideCaret ();
-}
-void releaseParent () {
- super.releaseParent ();
- if (this == parent.getCaret ()) parent.setCaret (null);
-}
-void releaseWidget () {
- super.releaseWidget ();
- if (display.currentCaret == this) {
- hideCaret ();
- display.setCurrentCaret (null);
- }
- parent = null;
- image = null;
-}
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the arguments. The <code>x</code> and
- * <code>y</code> arguments are relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (int x, int y, int width, int height) {
- checkWidget();
- if (this.x == x && this.y == y && this.width == width && this.height == height) return;
- boolean isFocus = isFocusCaret ();
- if (isFocus && isVisible) hideCaret ();
- this.x = x; this.y = y;
- this.width = width; this.height = height;
- if (isVisible) parent.updateIM ();
- if (isFocus && isVisible) showCaret ();
-}
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the argument. The <code>x</code> and
- * <code>y</code> fields of the rectangle are relative to
- * the receiver's parent (or its display if its parent is null).
- *
- * @param rect the new bounds for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (Rectangle rect) {
- checkWidget();
- if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (rect.x, rect.y, rect.width, rect.height);
-}
-void setFocus () {
- if (display.currentCaret == this) return;
- display.setCurrentCaret (this);
- if (isVisible) showCaret ();
-}
-/**
- * Sets the font that the receiver will use to paint textual information
- * to the font specified by the argument, or to the default font for that
- * kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkWidget();
- if (font != null && font.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.font = font;
- if (isVisible) parent.updateIM ();
-}
-/**
- * Sets the image that the receiver will use to paint the caret
- * to the image specified by the argument, or to the default
- * which is a filled rectangle if the argument is null
- *
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- boolean isFocus = isFocusCaret ();
- if (isFocus && isVisible) hideCaret ();
- this.image = image;
- if (isFocus && isVisible) showCaret ();
-}
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget();
- setBounds (x, y, width, height);
-}
-/**
- * Sets the receiver's location to the point specified by
- * the argument which is relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param location the new location for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (Point location) {
- checkWidget();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-/**
- * Sets the receiver's size to the point specified by the arguments.
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (int width, int height) {
- checkWidget();
- setBounds (x, y, width, height);
-}
-/**
- * Sets the receiver's size to the point specified by the argument.
- *
- * @param size the new extent for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (Point size) {
- checkWidget();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSize (size.x, size.y);
-}
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget();
- if (visible == isVisible) return;
- isVisible = visible;
- if (!isFocusCaret ()) return;
- if (isVisible) {
- showCaret ();
- } else {
- hideCaret ();
- }
-}
-boolean showCaret () {
- if (isShowing) return true;
- isShowing = true;
- return drawCaret ();
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java
deleted file mode 100755
index 51be4bfc3f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java
+++ /dev/null
@@ -1,466 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.layout.*;
-
-/**
- * Instances of this class allow the user to select a color
- * from a predefined set of available colors.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ColorDialog extends Dialog {
- private static final int COLORSWATCH_SIZE_DEPTH4 = 40;
- private static final int COLORSWATCH_SIZE_DEPTH8 = 15;
- private static final int COLORSWATCH_SIZE_DEPTH16 = 10;
- private static final int COLORSWATCH_BORDER = 1; // border between each color pad
-
- private Shell shell; // the dialog shell
- private Canvas colorsCanvas;
- private Label sampleLabel, selectionLabel;
- private Canvas sampleCanvas, selectionCanvas;
- private Button okButton, cancelButton;
- private int colorChooserWidth, colorChooserHeight;
-
- private boolean okSelected;
- private RGB rgb;
- private int colorSwatchExtent; // the size of each color square
- private Color colorGrid[][]; // the colors displayed in the dialog
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a composite control which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ColorDialog(Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ColorDialog(Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-void createChildren() {
- Shell dialog = shell;
- GridLayout layout = new GridLayout (2, false);
- dialog.setLayout(layout);
-
- colorChooserWidth = colorSwatchExtent * colorGrid.length - 1;
- colorChooserHeight = colorSwatchExtent * colorGrid[0].length - 1;
- colorsCanvas = new Canvas(dialog, SWT.BORDER);
- GridData data = new GridData ();
- data.widthHint = colorChooserWidth;
- data.heightHint = colorChooserHeight;
- colorsCanvas.setLayoutData(data);
-
- Composite buttonsGroup = new Composite (dialog, SWT.NONE);
- buttonsGroup.setLayout(new GridLayout());
- buttonsGroup.setLayoutData(new GridData(GridData.BEGINNING));
- createOkCancel(buttonsGroup);
-
- Composite bottomGroup = new Composite (dialog,SWT.NONE);
- layout = new GridLayout(2, true);
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- bottomGroup.setLayout(layout);
- bottomGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
-
- createSampleGroup(bottomGroup);
- createSelectionGroup(bottomGroup);
-}
-void createOkCancel(Composite parent) {
- okButton = new Button(parent, SWT.PUSH);
- okButton.setText(SWT.getMessage("SWT_OK"));
- shell.setDefaultButton(okButton);
- GridData data = new GridData(GridData.FILL_HORIZONTAL);
- okButton.setLayoutData(data);
-
- cancelButton = new Button(parent, SWT.PUSH);
- cancelButton.setText(SWT.getMessage("SWT_Cancel"));
- data = new GridData(GridData.FILL_HORIZONTAL);
- cancelButton.setLayoutData(data);
-}
-void createSampleGroup(Composite parent) {
- Group sampleGroup = new Group(parent, SWT.NULL);
- GridData data = new GridData(GridData.FILL_BOTH);
- data.grabExcessHorizontalSpace = true;
- sampleGroup.setLayout(new GridLayout());
- sampleGroup.setLayoutData(data);
- sampleGroup.setText(SWT.getMessage("SWT_Sample"));
-
- sampleLabel = new Label(sampleGroup, SWT.CENTER | SWT.BORDER);
- sampleLabel.setAlignment(SWT.CENTER);
- sampleLabel.setText(SWT.getMessage("SWT_A_Sample_Text"));
- data = new GridData(GridData.FILL_HORIZONTAL);
- sampleLabel.setLayoutData(data);
-
- sampleCanvas = new Canvas(sampleGroup, SWT.BORDER);
- data = new GridData(GridData.FILL_HORIZONTAL);
- data.heightHint = 15;
- sampleCanvas.setLayoutData(data);
-}
-void createSelectionGroup(Composite parent) {
- Group selectionGroup = new Group(parent, SWT.NULL);
- GridData data = new GridData(GridData.FILL_BOTH);
- data.grabExcessHorizontalSpace = true;
- selectionGroup.setLayout(new GridLayout());
- selectionGroup.setLayoutData(data);
- selectionGroup.setText(SWT.getMessage("SWT_Selection"));
-
- selectionLabel = new Label(selectionGroup, SWT.CENTER | SWT.BORDER);
- selectionLabel.setAlignment(SWT.CENTER);
- selectionLabel.setText(SWT.getMessage("SWT_Current_Selection"));
- data = new GridData(GridData.FILL_HORIZONTAL);
- data.grabExcessHorizontalSpace = true;
- selectionLabel.setLayoutData(data);
-
- selectionCanvas = new Canvas(selectionGroup, SWT.BORDER);
- data = new GridData(GridData.FILL_HORIZONTAL);
- data.grabExcessHorizontalSpace = true;
- data.heightHint = 15;
- selectionCanvas.setLayoutData(data);
-}
-void disposeColors() {
- for (int row = 0; row < colorGrid.length; row++) {
- for (int column = 0; column < colorGrid[row].length; column++) {
- colorGrid[row][column].dispose();
- }
- }
-}
-void drawColor(int xIndex, int yIndex, Color color, GC gc) {
- int colorExtent = colorSwatchExtent - COLORSWATCH_BORDER;
- gc.setBackground(color);
- gc.fillRectangle(
- xIndex * colorSwatchExtent,
- yIndex * colorSwatchExtent,
- colorExtent, colorExtent);
-}
-/**
- * Returns the currently selected color in the receiver.
- *
- * @return the RGB value for the selected color, may be null
- *
- * @see PaletteData#getRGBs
- */
-public RGB getRGB() {
- return rgb;
-}
-void handleEvents(Event event) {
- if (event.type == SWT.Paint) {
- paint(event);
- }
- else
- if (event.type == SWT.MouseDown) {
- mouseDown(event);
- }
- else
- if (event.type == SWT.MouseMove) {
- mouseMove(event);
- }
- else
- if (event.type == SWT.Selection) {
- if (event.widget == okButton) {
- okSelected = true;
- shell.setVisible(false);
- }
- else
- if (event.widget == cancelButton) {
- okSelected = false;
- shell.setVisible(false);
- }
- }
-}
-void initialize4BitColors() {
- Display display = shell.display;
-
- colorGrid[0][0] = new Color(display, 0, 0, 0);
- colorGrid[0][1] = new Color(display, 255, 255, 255);
- colorGrid[1][0] = new Color(display, 128, 128, 128);
- colorGrid[1][1] = new Color(display, 192, 192, 192);
-
- colorGrid[2][0] = new Color(display, 0, 0, 128);
- colorGrid[2][1] = new Color(display, 0, 0, 255);
- colorGrid[3][0] = new Color(display, 0, 128, 128);
- colorGrid[3][1] = new Color(display, 0, 255, 255);
-
- colorGrid[4][0] = new Color(display, 0, 128, 0);
- colorGrid[4][1] = new Color(display, 0, 255, 0);
- colorGrid[5][0] = new Color(display, 128, 128, 0);
- colorGrid[5][1] = new Color(display, 255, 255, 0);
-
- colorGrid[6][0] = new Color(display, 128, 0, 0);
- colorGrid[6][1] = new Color(display, 255, 0, 0);
- colorGrid[7][0] = new Color(display, 128, 0, 128);
- colorGrid[7][1] = new Color(display, 255, 0, 255);
-}
-void initialize8BitColors() {
- Display display = shell.display;
- int numRows = colorGrid[0].length;
- int iterationStep = 64;
- int row = 0, column = 0;
- int red, green, blue;
- // run the loops from 0 to 256 inclusive since this is easiest for the step
- // size, then adjust the 256 case to the proper 255 value when needed
- for (red = 0; red <= 256; red += iterationStep) {
- for (blue = 0; blue <= 256; blue += iterationStep) {
- for (green = 0; green <= 256; green += iterationStep) {
- if (row == numRows) {
- row = 0;
- column++;
- }
- if (red == 256) red = 255;
- if (blue == 256) blue = 255;
- if (green == 256) green = 255;
- colorGrid[column][row++] = new Color(display, red, green, blue);
- }
- }
- }
-}
-void initialize16BitColors() {
- Display display = shell.display;
- int numRows = colorGrid[0].length;
- int iterationStep = 51;
- int row = 0, column = 0;
- int red, green, blue;
-
- for (red = 0; red <= 255; red += iterationStep) {
- for (blue = 0; blue <= 255; blue += iterationStep) {
- if (blue == iterationStep && column < 20) { // evenly distribute 256 colors on 32 columns
- blue += iterationStep;
- }
- for (green = 0; green <= 255; green += iterationStep) {
- if (row == 2 || row == 5) { // evenly distribute 256 colors on 8 rows
- colorGrid[column][row++] = new Color(display, red, green - iterationStep / 2, blue);
- }
- if (row == numRows) {
- row = 0;
- column++;
- }
- colorGrid[column][row++] = new Color(display, red, green, blue);
- }
- }
- }
-}
-void initializeWidgets() {
- Display display = shell.display;
- if (rgb != null) {
- Color selectionColor = new Color(display, rgb);
- selectionCanvas.setBackground(selectionColor);
- selectionLabel.setBackground(selectionColor);
- selectionColor.dispose();
- }
-}
-void installListeners() {
- Listener listener = new Listener() {
- public void handleEvent(Event event) {handleEvents(event);}
- };
- okButton.addListener(SWT.Selection, listener);
- cancelButton.addListener(SWT.Selection, listener);
- colorsCanvas.addListener(SWT.Paint, listener);
- colorsCanvas.addListener(SWT.MouseDown, listener);
- colorsCanvas.addListener(SWT.MouseMove, listener);
-}
-void mouseDown(Event event) {
- int swatchExtent = colorSwatchExtent;
- Color color = colorGrid[event.x / swatchExtent][event.y / swatchExtent];
- selectionCanvas.setBackground(color);
- selectionLabel.setBackground(color);
-}
-void mouseMove(Event event) {
- int swatchExtent = colorSwatchExtent;
- // adjust for events received from moving over the Canvas' border
- if (!(0 <= event.x && event.x <= colorChooserWidth)) return;
- if (!(0 <= event.y && event.y <= colorChooserHeight)) return;
- int xgrid = Math.min(colorGrid.length - 1, event.x / swatchExtent);
- int ygrid = Math.min(colorGrid[0].length - 1, event.y / swatchExtent);
- Color color = colorGrid[xgrid][ygrid];
- sampleCanvas.setBackground(color);
- sampleLabel.setBackground(color);
-}
-/**
- * Makes the receiver visible and brings it to the front
- * of the display.
- *
- * @return the selected color, or null if the dialog was
- * cancelled, no color was selected, or an error
- * occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public RGB open() {
- shell = new Shell(parent, getStyle() | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
- Display display = shell.display;
- setColorDepth(display.getDepth());
- createChildren();
- installListeners();
- openModal();
- if (okSelected) {
- Color selectionColor = selectionCanvas.getBackground();
- rgb = new RGB(
- selectionColor.getRed(),
- selectionColor.getGreen(),
- selectionColor.getBlue());
- }
- disposeColors();
- if (shell.isDisposed() == false) {
- shell.dispose();
- }
- if (!okSelected) return null;
- return rgb;
-}
-/**
- * Open the receiver and set its size to the size calculated by
- * the layout manager.
- */
-void openDialog() {
- Shell dialog = shell;
-
- // Start everything off by setting the shell size to its computed size.
- Point pt = dialog.computeSize(-1, -1, false);
-
- // Ensure that the width of the shell fits the display.
- Display display = dialog.display;
- Rectangle displayRect = display.getBounds();
- int widthLimit = displayRect.width * 7 / 8;
- int heightLimit = displayRect.height * 7 / 8;
- if (pt.x > widthLimit) {
- pt = dialog.computeSize (widthLimit, -1, false);
- }
-
- /*
- * If the parent is visible then center this dialog on it,
- * otherwise center this dialog on the parent's monitor
- */
- Rectangle parentBounds = null;
- if (parent.isVisible ()) {
- parentBounds = getParent ().getBounds ();
- } else {
- parentBounds = parent.getMonitor ().getBounds ();
- }
- int originX = (parentBounds.width - pt.x) / 2 + parentBounds.x;
- originX = Math.max (originX, 0);
- originX = Math.min (originX, widthLimit - pt.x);
- int originY = (parentBounds.height - pt.y) / 2 + parentBounds.y;
- originY = Math.max (originY, 0);
- originY = Math.min (originY, heightLimit - pt.y);
- dialog.setBounds (originX, originY, pt.x, pt.y);
-
- String title = getText ();
- if (title.length () == 0) title = SWT.getMessage ("SWT_ColorDialog_Title");
- shell.setText(title);
-
- dialog.open();
-}
-void openModal() {
- Display display = shell.display;
- initializeWidgets();
- openDialog();
- while (shell.isDisposed() == false && shell.getVisible() == true) {
- if (display.readAndDispatch() == false) {
- display.sleep();
- }
- }
-}
-void paint(Event event) {
- for (int column = 0; column < colorGrid.length; column++) {
- for (int row = 0; row < colorGrid[0].length; row++) {
- drawColor(column, row, colorGrid[column][row], event.gc);
- }
- }
-}
-void setColorDepth(int bits) {
- if (bits == 4) {
- colorSwatchExtent = COLORSWATCH_SIZE_DEPTH4;
- colorGrid = new Color[8][2];
- initialize4BitColors();
- return;
- }
- if (bits == 8) {
- colorSwatchExtent = COLORSWATCH_SIZE_DEPTH8;
- colorGrid = new Color[25][5];
- initialize8BitColors();
- return;
- }
- // default case: 16, 24 or 32 bits
- colorSwatchExtent = COLORSWATCH_SIZE_DEPTH16;
- colorGrid = new Color[32][8];
- initialize16BitColors();
-}
-/**
- * Sets the receiver's selected color to be the argument.
- *
- * @param rgb the new RGB value for the selected color, may be
- * null to let the platform select a default when
- * open() is called
- * @see PaletteData#getRGBs
- */
-public void setRGB(RGB rgb) {
- this.rgb = rgb;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java
deleted file mode 100755
index 8ad4709e7a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java
+++ /dev/null
@@ -1,1726 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are controls that allow the user
- * to choose an item from a list of items, or optionally
- * enter a new value by typing it into an editable text
- * field. Often, <code>Combo</code>s are used in the same place
- * where a single selection <code>List</code> widget could
- * be used but space is limited. A <code>Combo</code> takes
- * less space than a <code>List</code> widget and shows
- * similar information.
- * <p>
- * Note: Since <code>Combo</code>s can contain both a list
- * and an editable text field, it is possible to confuse methods
- * which access one versus the other (compare for example,
- * <code>clearSelection()</code> and <code>deselectAll()</code>).
- * The API documentation is careful to indicate either "the
- * receiver's list" or the "the receiver's text field" to
- * distinguish between the two cases.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>DROP_DOWN, READ_ONLY, SIMPLE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Modify, Selection, Verify</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles DROP_DOWN and SIMPLE may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see List
- * @see <a href="http://www.eclipse.org/swt/snippets/#combo">Combo snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Combo extends Composite {
- int visibleCount = 5;
-
- /**
- * the operating system limit for the number of characters
- * that the text field in an instance of this class can hold
- */
- public static final int LIMIT;
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0x7FFFFFFF;
- }
-
- boolean ignoreSelect;
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see SWT#READ_ONLY
- * @see SWT#SIMPLE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Combo (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-/**
- * Adds the argument to the end of the receiver's list.
- *
- * @param string the new item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String,int)
- */
-public void add (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
-
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- OS.XmComboBoxAddItem(handle, xmString, -1, false);
- OS.XmStringFree (xmString);
-}
-/**
- * Adds the argument to the receiver's list at the given
- * zero-relative index.
- * <p>
- * Note: To add an item at the end of the list, use the
- * result of calling <code>getItemCount()</code> as the
- * index or use <code>add(String)</code>.
- * </p>
- *
- * @param string the new item
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String)
- */
-public void add (String string, int index) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (index == -1) error (SWT.ERROR_INVALID_RANGE);
-
- /*
- * Feature in Motif. When an index is out of range,
- * the list widget adds the item at the end. This
- * behavior is not wrong but it is unwanted. The
- * fix is to check the range before adding the item.
- */
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= index && index <= argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- OS.XmComboBoxAddItem(handle, xmString, index + 1, false);
- OS.XmStringFree (xmString);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the combo's list selection.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed the combo's text area.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- *
- * @since 3.1
- */
-public void addVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-static int checkStyle (int style) {
- /*
- * Feature in Windows. It is not possible to create
- * a combo box that has a border using Windows style
- * bits. All combo boxes draw their own border and
- * do not use the standard Windows border styles.
- * Therefore, no matter what style bits are specified,
- * clear the BORDER bits so that the SWT style will
- * match the Windows widget.
- *
- * The Windows behavior is currently implemented on
- * all platforms.
- */
- style &= ~SWT.BORDER;
-
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- style &= ~(SWT.H_SCROLL | SWT.V_SCROLL);
- style = checkBits (style, SWT.DROP_DOWN, SWT.SIMPLE, 0, 0, 0, 0);
- if ((style & SWT.SIMPLE) != 0) return style & ~SWT.READ_ONLY;
- return style;
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-/**
- * Sets the selection in the receiver's text field to an empty
- * selection starting just before the first character. If the
- * text field is editable, this has the effect of placing the
- * i-beam at the start of the text.
- * <p>
- * Note: To clear the selected items in the receiver's list,
- * use <code>deselectAll()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #deselectAll
- */
-public void clearSelection () {
- checkWidget();
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmTextClearSelection (argList[1], OS.XtLastTimestampProcessed (xDisplay));
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int [] argList = {
- OS.XmNlist, 0,
- OS.XmNtextField, 0,
- OS.XmNitemCount, 0,
- OS.XmNmarginWidth, 0,
- OS.XmNshadowThickness, 0,
- OS.XmNhighlightThickness, 0,
- OS.XmNarrowSize, 0,
- OS.XmNarrowSpacing, 0,
- };
- OS.XtGetValues(handle, argList, argList.length / 2);
- XtWidgetGeometry result = new XtWidgetGeometry ();
- result.request_mode = OS.CWWidth;
- OS.XtQueryGeometry (argList[1], null, result);
- int width = result.width, height = getTextHeight();
- int[] argList2 = {OS.XmNmarginWidth, 0, OS.XmNshadowThickness, 0};
- OS.XtGetValues(argList[3], argList2, argList2.length / 2);
- if ((style & SWT.READ_ONLY) == 0) width += (2 * argList[7]);
- if ((style & SWT.DROP_DOWN) != 0) {
- width += argList[13] + argList[15];
- } else {
- int itemCount = (argList[5] == 0) ? 5 : argList[5];
- height += (getItemHeight () * itemCount);
- }
- width += (2 * argList[9])
- + (2 * argList[11])
- + (2 * argList2[1])
- + (2 * argList2[3]);
- if (argList[5] == 0) width = DEFAULT_WIDTH;
- if (hHint != SWT.DEFAULT) height = hHint;
- if (wHint != SWT.DEFAULT) width = wHint;
- Rectangle rect = computeTrim (0, 0, width, height);
- return new Point (rect.width, rect.height);
-}
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void copy () {
- checkWidget();
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmTextCopy (argList [1], OS.XtLastTimestampProcessed (xDisplay));
-}
-void createHandle (int index) {
- /*
- * Feature in Motif. When items are added or removed
- * from a combo, it may request and be granted, a new
- * preferred size. This behavior is unwanted. The fix
- * is to create a parent for the list that will disallow
- * geometry requests.
- */
- int parentHandle = parent.handle;
- int [] argList1 = {OS.XmNancestorSensitive, 1};
- formHandle = OS.XmCreateForm (parentHandle, null, argList1, argList1.length / 2);
- if (formHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int comboBoxType = OS.XmDROP_DOWN_COMBO_BOX;
- if ((style & SWT.SIMPLE) != 0) {
- comboBoxType = OS.XmCOMBO_BOX;
- } else if ((style & SWT.READ_ONLY) != 0) {
- comboBoxType = OS.XmDROP_DOWN_LIST;
- }
- int [] argList2 = {
- OS.XmNcomboBoxType, comboBoxType,
- OS.XmNtopAttachment, OS.XmATTACH_FORM,
- OS.XmNbottomAttachment, OS.XmATTACH_FORM,
- OS.XmNleftAttachment, OS.XmATTACH_FORM,
- OS.XmNrightAttachment, OS.XmATTACH_FORM,
- OS.XmNresizable, 0,
- };
- handle = OS.XmCreateComboBox (formHandle, null, argList2, argList2.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- int [] argList3 = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList3, argList3.length / 2);
- int textHandle = argList3 [1];
- int [] argList4 = {OS.XmNverifyBell, 0};
- OS.XtSetValues (textHandle, argList4, argList4.length / 2);
- /*
- * Feature in Motif. The Combo widget is created with a default
- * drop target. This is inconsistent with other platforms.
- * To be consistent, disable the default drop target.
- */
- OS.XmDropSiteUnregister (textHandle);
-}
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void cut () {
- checkWidget();
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmTextCut (argList [1], OS.XtLastTimestampProcessed (xDisplay));
-}
-/**
- * Deselects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget();
- if (index == -1) return;
- int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
-
- if (OS.XmListPosSelected (argList[3], index + 1)) {
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetString (argList[1], new byte[1]);
- display.setWarnings (warnings);
- OS.XmListDeselectAllItems (argList[3]);
- }
-}
-/**
- * Deselects all selected items in the receiver's list.
- * <p>
- * Note: To clear the selection in the receiver's text field,
- * use <code>clearSelection()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #clearSelection
- */
-public void deselectAll () {
- checkWidget();
- int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetString (argList[1], new byte[1]);
- display.setWarnings(warnings);
- OS.XmListDeselectAllItems (argList[3]);
-}
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver's list. Throws an exception if the index is out
- * of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getItem (int index) {
- checkWidget();
- int [] argList = {OS.XmNitemCount, 0, OS.XmNitems, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= index && index < argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- if (argList [3] == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- int ptr = argList [3] + (index * 4);
- int [] buffer1 = new int [1];
- OS.memmove (buffer1, ptr, 4);
- ptr = buffer1 [0];
- int [] table = new int [] {display.tabMapping, display.crMapping};
- int address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- table,
- table.length,
- OS.XmOUTPUT_ALL);
- if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- OS.XtFree (address);
- return decodeString(new String (Converter.mbcsToWcs (getCodePage (), buffer)));
-}
-/**
- * Returns the number of items contained in the receiver's list.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the receiver's list.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget();
- int [] listHandleArgs = {OS.XmNlist, 0};
- OS.XtGetValues (handle, listHandleArgs, listHandleArgs.length / 2);
- int [] argList = {OS.XmNlistSpacing, 0, OS.XmNhighlightThickness, 0, OS.XmNfontList, 0};
- OS.XtGetValues (listHandleArgs[1], argList, argList.length / 2);
- int spacing = argList [1], highlight = argList [3], fontList = argList [5];
- /* Result is from empirical analysis on Linux and AIX */
- return getFontHeight (fontList) + spacing + (2 * highlight);
-}
-/**
- * Returns a (possibly empty) array of <code>String</code>s which are
- * the items in the receiver's list.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver's list
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getItems () {
- checkWidget();
- int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int items = argList [1], itemCount = argList [3];
- int [] buffer1 = new int [1];
- String [] result = new String [itemCount];
- String codePage = getCodePage ();
- for (int i = 0; i < itemCount; i++) {
- OS.memmove (buffer1, items, 4);
- int ptr = buffer1 [0];
- int [] table = new int [] {display.tabMapping, display.crMapping};
- int address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- table,
- table.length,
- OS.XmOUTPUT_ALL);
- if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- OS.XtFree (address);
- result[i] = decodeString(new String (Converter.mbcsToWcs (codePage, buffer)));
- items += 4;
- }
- return result;
-}
-/**
- * Returns <code>true</code> if the receiver's list is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's list's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getListVisible () {
- checkWidget ();
- int[] argList1 = new int[] {OS.XmNlist, 0, OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int xtParent = OS.XtParent (argList1 [1]);
- while (xtParent != 0 && !OS.XtIsSubclass (xtParent, OS.shellWidgetClass ())) {
- xtParent = OS.XtParent (xtParent);
- }
- if (xtParent != 0) {
- int xDisplay = OS.XtDisplay (xtParent);
- if (xDisplay == 0) return false;
- int xWindow = OS.XtWindow (xtParent);
- if (xWindow == 0) return false;
- XWindowAttributes attributes = new XWindowAttributes ();
- OS.XGetWindowAttributes (xDisplay, xWindow, attributes);
- return attributes.map_state == OS.IsViewable;
- }
- return false;
-}
-int getMinimumHeight () {
- return getTextHeight ();
-}
-String getNameText () {
- return getText ();
-}
-/**
- * Returns the orientation of the receiver.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getOrientation () {
- checkWidget();
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-/**
- * Returns a <code>Point</code> whose x coordinate is the
- * character position representing the start of the selection
- * in the receiver's text field, and whose y coordinate is the
- * character position representing the end of the selection.
- * An "empty" selection is indicated by the x and y coordinates
- * having the same value.
- * <p>
- * Indexing is zero based. The range of a selection is from
- * 0..N where N is the number of characters in the widget.
- * </p>
- *
- * @return a point representing the selection start and end
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSelection () {
- checkWidget();
- int [] start = new int [1], end = new int [1];
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmTextGetSelectionPosition (argList[1], start, end);
- if (start [0] == end [0]) {
- start [0] = end [0] = OS.XmTextGetInsertionPosition (argList[1]);
- }
- return new Point (start [0], end [0]);
-}
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver's list, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget();
- int [] argList = {OS.XmNlist, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
-
- int index = OS.XmListGetKbdItemPos (argList[1]);
- if (OS.XmListPosSelected (argList[1], index)) return index - 1;
- int [] count = new int [1], positions = new int [1];
- if (!OS.XmListGetSelectedPos (argList[1], positions, count)) return -1;
- if (count [0] == 0) return -1;
- int address = positions [0];
- int [] indices = new int [1];
- OS.memmove (indices, address, 4);
- OS.XtFree (address);
- return indices [0] - 1;
-}
-/**
- * Returns a string containing a copy of the contents of the
- * receiver's text field, or an empty string if there are no
- * contents.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
-
- int ptr = OS.XmTextGetString (argList[1]);
- if (ptr == 0) return "";
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, length);
- OS.XtFree (ptr);
- return decodeString(new String (Converter.mbcsToWcs (getCodePage (), buffer)));
-}
-/**
- * Returns the height of the receivers's text field.
- *
- * @return the text height
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTextHeight () {
- checkWidget();
- if ((style & SWT.DROP_DOWN) != 0) {
- /*
- * Bug in MOTIF. For some reason, XtQueryGeometry ()
- * returns the wrong height when the combo is not realized.
- * The fix is to force the combo to be realized by forcing
- * the shell to be realized.
- */
- if (!OS.XtIsRealized (handle)) getShell ().realizeWidget ();
- XtWidgetGeometry result = new XtWidgetGeometry ();
- result.request_mode = OS.CWHeight;
- OS.XtQueryGeometry (handle, null, result);
- return result.height;
- } else {
- /* Calculate text field height. */
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int [] argList2 = {OS.XmNmarginHeight, 0};
- OS.XtGetValues (argList[1], argList2, argList2.length / 2);
- int height = getFontHeight (font.handle);
- XRectangle rect = new XRectangle ();
- OS.XmWidgetGetDisplayRect (argList[1], rect);
- height += (rect.y * 2) + (2 * argList2[1]);
-
- /* Add in combo box margins. */
- int [] argList3 = {OS.XmNmarginHeight, 0, OS.XmNshadowThickness, 0, OS.XmNhighlightThickness, 0};
- OS.XtGetValues(handle, argList3, argList3.length / 2);
- height += (2 * argList3[1]) + (2 * argList3[3]) + (2 * argList3[5]);
-
- return height;
- }
-}
-/**
- * Returns the maximum number of characters that the receiver's
- * text field is capable of holding. If this has not been changed
- * by <code>setTextLimit()</code>, it will be the constant
- * <code>Combo.LIMIT</code>.
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public int getTextLimit () {
- checkWidget();
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return OS.XmTextGetMaxLength (argList[1]);
-}
-/**
- * Gets the number of items that are visible in the drop
- * down portion of the receiver's list.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @return the number of items that are visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public int getVisibleItemCount () {
- checkWidget ();
- if ((style & SWT.SIMPLE) != 0) return visibleCount;
- int [] argList = new int [] {OS.XmNvisibleItemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- int [] argList = {OS.XmNlist, 0, OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int listHandle = argList [1];
- int textHandle = argList [3];
- OS.XtAddCallback (listHandle, OS.XmNbrowseSelectionCallback, windowProc, BROWSE_SELECTION_CALLBACK);
- OS.XtAddEventHandler (listHandle, OS.KeyPressMask, false, windowProc, KEY_PRESS);
- OS.XtAddEventHandler (listHandle, OS.KeyReleaseMask, false, windowProc, KEY_RELEASE);
- OS.XtAddCallback (textHandle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK);
- OS.XtAddCallback (textHandle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
- OS.XtAddCallback (textHandle, OS.XmNmodifyVerifyCallback, windowProc, MODIFY_VERIFY_CALLBACK);
- OS.XtAddEventHandler (textHandle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS);
- OS.XtAddEventHandler (textHandle, OS.ButtonReleaseMask, false, windowProc, BUTTON_RELEASE);
- OS.XtAddEventHandler (textHandle, OS.EnterWindowMask, false, windowProc, ENTER_WINDOW);
- OS.XtAddEventHandler (textHandle, OS.LeaveWindowMask, false, windowProc, LEAVE_WINDOW);
- OS.XtAddEventHandler (textHandle, OS.KeyPressMask, false, windowProc, KEY_PRESS);
- OS.XtAddEventHandler (textHandle, OS.KeyReleaseMask, false, windowProc, KEY_RELEASE);
- OS.XtInsertEventHandler (textHandle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail);
-}
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param string the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
-
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) return -1;
-
- int [] argList = {OS.XmNlist, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
-
- int index = OS.XmListItemPos (argList[1], xmString);
- OS.XmStringFree (xmString);
- return index - 1;
-}
-/**
- * Searches the receiver's list starting at the given,
- * zero-relative index until an item is found that is equal
- * to the argument, and returns the index of that item. If
- * no item is found or the starting index is out of range,
- * returns -1.
- *
- * @param string the search item
- * @param start the zero-relative index at which to begin the search
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string, int start) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int items = argList [1], itemCount = argList [3];
- if (!((0 <= start) && (start < itemCount))) return -1;
- byte [] buffer1 = Converter.wcsToMbcs (getCodePage (), encodeString(string), true);
- int xmString = OS.XmStringCreateLocalized (buffer1);
- if (xmString == 0) return -1;
- int index = start;
- items += start * 4;
- int [] buffer2 = new int [1];
- while (index < itemCount) {
- OS.memmove (buffer2, items, 4);
- if (OS.XmStringCompare (buffer2 [0], xmString)) break;
- items += 4; index++;
- }
- OS.XmStringFree (xmString);
- if (index == itemCount) return -1;
- return index;
-}
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void paste () {
- checkWidget();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmTextFieldPaste (argList [1]);
- display.setWarnings (warnings);
-}
-/**
- * Removes the item from the receiver's list at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget();
- if (index == -1) error (SWT.ERROR_INVALID_RANGE);
- /*
- * Feature in Motif. An index out of range is handled
- * correctly by the list widget but causes an unwanted
- * Xm Warning. The fix is to check the range before
- * deleting an item.
- */
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= index && index < argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- if (argList [1] == 1) {
- removeAll ();
- } else {
- OS.XmComboBoxDeletePos (handle, index + 1);
- }
-}
-/**
- * Removes the items from the receiver's list which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget();
- if (start > end) return;
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= start && start <= end && end < argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- if (argList [1] == (end - start + 1)) {
- removeAll ();
- } else {
- for (int i = start; i <= end; i++) {
- OS.XmComboBoxDeletePos (handle, start + 1);
- }
- }
-}
-void register () {
- super.register ();
- int [] argList = {OS.XmNlist, 0, OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- display.addWidget (argList[1], this);
- display.addWidget (argList[3], this);
-}
-void releaseWidget () {
- super.releaseWidget ();
- if (display.focusedCombo == this) display.focusedCombo = null;
- /*
- * Bug in Motif. Disposing a Combo while its list is visible
- * causes Motif to crash. The fix is to hide the drop down
- * list before disposing the Combo.
- */
- if ((style & SWT.DROP_DOWN) != 0) {
- int[] argList = new int[] {OS.XmNlist, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int xtParent = OS.XtParent (argList [1]);
- while (xtParent != 0 && !OS.XtIsSubclass (xtParent, OS.shellWidgetClass ())) {
- xtParent = OS.XtParent (xtParent);
- }
- if (xtParent != 0) OS.XtPopdown (xtParent);
- }
-}
-/**
- * Searches the receiver's list starting at the first item
- * until an item is found that is equal to the argument,
- * and removes that item from the list.
- *
- * @param string the item to remove
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
- int [] argList = {OS.XmNlist, 0, OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int index = OS.XmListItemPos (argList[1], xmString);
- OS.XmStringFree (xmString);
- if (index == 0) error (SWT.ERROR_INVALID_ARGUMENT);
- if (argList [3] == 1) {
- removeAll ();
- } else {
- OS.XmComboBoxDeletePos (handle, index);
- }
-}
-/**
- * Removes all of the items from the receiver's list and clear the
- * contents of receiver's text field.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget();
- int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0, OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetString (argList[1], new byte[1]);
- display.setWarnings(warnings);
- OS.XmListDeselectAllItems (argList[3]);
- for (int i = 0; i < argList[5]; i++) {
- OS.XmComboBoxDeletePos(handle, 1);
- }
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- *
- * @since 3.1
- */
-public void removeVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-/**
- * Selects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget();
- if (index == -1) {
- int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetString (argList[1], new byte[1]);
- display.setWarnings (warnings);
- OS.XmListDeselectAllItems (argList[3]);
- } else {
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= index && index < argList [1])) return;
- int [] argList2 = {OS.XmNselectedPosition, index};
- ignoreSelect = true;
- OS.XtSetValues(handle, argList2, argList2.length / 2);
- ignoreSelect = false;
- }
-}
-void sendFocusEvent (int type) {
- Display display = this.display;
- Control focusedCombo = display.focusedCombo;
- if (type == SWT.FocusIn && focusedCombo != this) {
- super.sendFocusEvent (type);
- if (!isDisposed ()) display.focusedCombo = this;
- }
-}
-boolean sendIMKeyEvent (int type, XKeyEvent xEvent) {
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return super.sendIMKeyEvent (type, xEvent, argList [1]);
-}
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- int [] argList1 = {OS.XmNtextField, 0, OS.XmNlist, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int text = argList1 [1], list = argList1 [3];
- int [] argList2 = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0};
- OS.XtGetValues (text, argList2, argList2.length / 2);
- OS.XmChangeColor (text, pixel);
- OS.XtSetValues (text, argList2, argList2.length / 2);
- int [] argList3 = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0};
- OS.XtGetValues (list, argList3, argList3.length / 2);
- OS.XmChangeColor (list, pixel);
- OS.XtSetValues (list, argList3, argList3.length / 2);
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- checkWidget();
- int newHeight = (resize && (style & SWT.DROP_DOWN) != 0) ? getTextHeight() : height;
- return super.setBounds (x, y, width, newHeight, move, resize);
-}
-public void setFont (Font font) {
- checkWidget();
-
- /*
- * Bug in Motif. Setting the font in a combo widget that does
- * not have any items causes a GP on UTF-8 locale.
- * The fix is to add an item, change the font, then
- * remove the added item at the end.
- */
- int [] argList1 = {OS.XmNitems, 0, OS.XmNitemCount, 0,};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- boolean fixString = OS.IsDBLocale && argList1 [3] == 0;
- if (fixString) {
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), "string", true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- OS.XmComboBoxAddItem (handle, xmString, -1, false);
- OS.XmStringFree (xmString);
- }
- super.setFont (font);
- if (fixString) OS.XtSetValues (handle, argList1, argList1.length / 2);
-
- /*
- * Bug in Motif. When a font is set in a combo box after the widget
- * is realized, the combo box does not lay out properly. For example,
- * the drop down arrow may be positioned in the middle of the text
- * field or may be invisible, positioned outside the bounds of the
- * widget. The fix is to detect these cases and force the combo box
- * to be laid out properly by temporarily growing and then shrinking
- * the widget.
- *
- * NOTE: This problem also occurs for simple combo boxes.
- */
- if (OS.XtIsRealized (handle)) {
- int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList2, argList2.length / 2);
- OS.XtResizeWidget (handle, argList2 [1], argList2 [3] + 1, argList2 [5]);
- OS.XtResizeWidget (handle, argList2 [1], argList2 [3], argList2 [5]);
- }
-}
-void setForegroundPixel (int pixel) {
- int [] argList1 = {OS.XmNtextField, 0, OS.XmNlist, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int [] argList2 = {OS.XmNforeground, pixel};
- OS.XtSetValues (argList1 [1], argList2, argList2.length / 2);
- OS.XtSetValues (argList1 [3], argList2, argList2.length / 2);
- super.setForegroundPixel (pixel);
-}
-/**
- * Sets the text of the item in the receiver's list at the given
- * zero-relative index to the string argument.
- *
- * @param index the index for the item
- * @param string the new text for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItem (int index, String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (index == -1) error (SWT.ERROR_INVALID_RANGE);
- int [] argList = {OS.XmNlist, 0, OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= index && index < argList [3])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- boolean isSelected = OS.XmListPosSelected (argList[1], index + 1);
- OS.XmListReplaceItemsPosUnselected (argList[1], new int [] {xmString}, 1, index + 1);
- if (isSelected) OS.XmListSelectPos (argList[1], index + 1, false);
- OS.XmStringFree (xmString);
-}
-/**
- * Sets the receiver's list to be the given array of items.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItems (String [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<items.length; i++) {
- if (items [i] == null) error (SWT.ERROR_INVALID_ARGUMENT);
- }
-
- if (items.length == 0) {
- removeAll();
- return;
- }
-
- int index = 0;
- int [] table = new int [items.length];
- String codePage = getCodePage ();
- while (index < items.length) {
- String string = items [index];
- byte [] buffer = Converter.wcsToMbcs (codePage, encodeString(string), true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) break;
- table [index++] = xmString;
- }
- int ptr = OS.XtMalloc (index * 4);
- OS.memmove (ptr, table, index * 4);
- int [] argList1 = {OS.XmNitems, ptr, OS.XmNitemCount, index};
- OS.XtSetValues (handle, argList1, argList1.length / 2);
- for (int i=0; i<index; i++) OS.XmStringFree (table [i]);
- OS.XtFree (ptr);
- if (index < items.length) error (SWT.ERROR_ITEM_NOT_ADDED);
-
- int [] argList2 = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList2, argList2.length / 2);
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetString (argList2[1], new byte[1]);
- display.setWarnings(warnings);
- int [] argList3 = {OS.XmNlist, 0};
- OS.XtGetValues (handle, argList3, argList3.length / 2);
- int [] argList4 = {OS.XmNselectedItemCount, 0, OS.XmNselectedItems, 0};
- OS.XtSetValues (argList3 [1], argList4, argList4.length / 2);
-}
-/**
- * Marks the receiver's list as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setListVisible (boolean visible) {
- checkWidget ();
- if ((style & SWT.DROP_DOWN) != 0) {
- int[] argList1 = new int[] {OS.XmNlist, 0, OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int xtParent = OS.XtParent (argList1 [1]);
- while (xtParent != 0 && !OS.XtIsSubclass (xtParent, OS.shellWidgetClass ())) {
- xtParent = OS.XtParent (xtParent);
- }
- if (xtParent != 0) {
- if (visible) {
- int [] argList2 = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (argList1 [3], argList2, argList2.length / 2);
- int x = argList2 [1], y = argList2 [3] + argList2 [7] + argList2 [9];
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (handle, (short) x, (short) y, root_x, root_y);
- OS.XtMoveWidget (xtParent, root_x [0], root_y [0]);
- OS.XtPopup (xtParent, OS.XtGrabNone);
- } else {
- // This code is intentionally commented
- //OS.XtPopdown (xtParent);
- }
- }
- }
-}
-/**
- * Sets the orientation of the receiver, which must be one
- * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- * <p>
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public void setOrientation (int orientation) {
- checkWidget();
-}
-/**
- * Sets the selection in the receiver's text field to the
- * range specified by the argument whose x coordinate is the
- * start of the selection and whose y coordinate is the end
- * of the selection.
- *
- * @param selection a point representing the new selection start and end
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (Point selection) {
- checkWidget();
- if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
-
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
-
- /* Clear the highlight before setting the selection. */
- int position = OS.XmTextGetLastPosition (argList[1]);
-
- /*
- * Bug in MOTIF. XmTextSetSelection () fails to set the
- * selection when the receiver is not realized. The fix
- * is to force the receiver to be realized by forcing the
- * shell to be realized. If the receiver is realized before
- * the shell, MOTIF fails to draw the text widget and issues
- * lots of X BadDrawable errors.
- */
- if (!OS.XtIsRealized (handle)) getShell ().realizeWidget ();
-
- /* Set the selection. */
- int xDisplay = OS.XtDisplay (argList[1]);
- if (xDisplay == 0) return;
- int nStart = Math.min (Math.max (Math.min (selection.x, selection.y), 0), position);
- int nEnd = Math.min (Math.max (Math.max (selection.x, selection.y), 0), position);
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetSelection (argList[1], nStart, nEnd, OS.XtLastTimestampProcessed (xDisplay));
-
- /* Force the i-beam to follow the highlight/selection. */
- OS.XmTextSetInsertionPosition (argList[1], nEnd);
- display.setWarnings(warnings);
-}
-/**
- * Sets the contents of the receiver's text field to the
- * given string.
- * <p>
- * This call is ignored when the receiver is read only and
- * the given string is not in the receiver's list.
- * </p>
- * <p>
- * Note: The text field in a <code>Combo</code> is typically
- * only capable of displaying a single line of text. Thus,
- * setting the text to a string containing line breaks or
- * other special characters will probably cause it to
- * display incorrectly.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
-
- /*
- * The read-only and non-read-only cases must be handled
- * separately here because the platform will allow the
- * text of a read-only combo to be set to any value,
- * regardless of whether it appears in the combo's item
- * list or not.
- */
- if ((style & SWT.READ_ONLY) != 0) {
- int index = indexOf (string);
- if (index != -1) select (index);
- } else {
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) return;
- int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int index = OS.XmListItemPos (argList[3], xmString);
- if (index > 0) {
- /* The list contains the item. */
- OS.XmComboBoxSelectItem(handle, xmString);
- } else {
- /* The list does not contain the item. */
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetString (argList[1], buffer);
- OS.XmTextSetInsertionPosition (argList[1], 0);
- display.setWarnings(warnings);
- }
- OS.XmStringFree (xmString);
- }
-}
-/**
- * Sets the maximum number of characters that the receiver's
- * text field is capable of holding to be the argument.
- * <p>
- * To reset this value to the default, use <code>setTextLimit(Combo.LIMIT)</code>.
- * Specifying a limit value larger than <code>Combo.LIMIT</code> sets the
- * receiver's limit to <code>Combo.LIMIT</code>.
- * </p>
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public void setTextLimit (int limit) {
- checkWidget();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmTextSetMaxLength (argList[1], limit);
-}
-/**
- * Sets the number of items that are visible in the drop
- * down portion of the receiver's list.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param count the new number of items to be visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setVisibleItemCount (int count) {
- checkWidget ();
- if (count < 0) return;
- this.visibleCount = count;
- /*
- * But in Motif. Setting the XmNvisibleItemCount resource
- * for the combo box after it has been realized causes the
- * widget to layout badly, sometimes moving the drop down
- * arrow part of the combo box outside of the bounds.
- * The fix is to set the XmNvisibleItemCount resource on
- * the list instead.
- */
- int [] argList1 = new int [] {OS.XmNlist, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int [] argList2 = {OS.XmNvisibleItemCount, count};
- OS.XtSetValues (argList1 [1], argList2, argList2.length / 2);
-}
-void deregister () {
- super.deregister ();
- int [] argList = {OS.XmNlist, 0, OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- display.removeWidget (argList[1]);
- display.removeWidget (argList[3]);
-}
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- int [] argList = {
- OS.XmNlist, 0,
- OS.XmNtextField, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- enableHandle (enabled, argList [1]);
- enableHandle (enabled, argList [3]);
-}
-/**
- * Bug in Motif.
- * Empty strings in the combo will cause GPFs if a) they
- * are the only items in the combo or b) if they are
- * included in an array which is set as the value of the
- * combo's items resource. To protect against these GPFs,
- * make sure that no empty strings are added to the combo.
- * The solution is to add a space to empty strings or
- * strings which are all spaces. This space is removed
- * when answering the text of items which are all spaces.
- */
-String encodeString(String string) {
- for (int i = 0; i < string.length(); i++) {
- if (string.charAt(i) != ' ') {
- return string;
- }
- }
- return string + ' ';
-}
-/**
- * Bug in Motif.
- * Empty strings in the combo will cause GPFs if a) they
- * are the only items in the combo or b) if they are
- * included in an array which is set as the value of the
- * combo's items resource. To protect against these GPFs,
- * make sure that no empty strings are added to the combo.
- * The solution is to add a space to empty strings or
- * strings which include only spaces. A space is removed
- * when answering the text of items which are all spaces.
- */
-String decodeString(String string) {
- if (string.length() == 0) return string;
-
- for (int i = 0; i < string.length(); i++) {
- if (string.charAt(i) != ' ') {
- return string;
- }
- }
- return string.substring(0, string.length() - 1);
-}
-int XmNactivateCallback (int w, int client_data, int call_data) {
- postEvent (SWT.DefaultSelection);
- return 0;
-}
-int XmNbrowseSelectionCallback (int w, int client_data, int call_data) {
- /*
- * Bug in MOTIF. If items have been added and removed from a
- * combo then users are able to select an empty drop-down item
- * in the combo once and force a resulting callback. In such
- * cases we want to eat this callback so that listeners are not
- * notified.
- */
- if (ignoreSelect || getSelectionIndex() == -1) return 0;
- postEvent (SWT.Selection);
- return 0;
-}
-int XmNmodifyVerifyCallback (int w, int client_data, int call_data) {
- int result = super.XmNmodifyVerifyCallback (w, client_data, call_data);
- if (result != 0) return result;
- if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return result;
- XmTextVerifyCallbackStruct textVerify = new XmTextVerifyCallbackStruct ();
- OS.memmove (textVerify, call_data, XmTextVerifyCallbackStruct.sizeof);
- XmTextBlockRec textBlock = new XmTextBlockRec ();
- OS.memmove (textBlock, textVerify.text, XmTextBlockRec.sizeof);
- byte [] buffer = new byte [textBlock.length];
- OS.memmove (buffer, textBlock.ptr, textBlock.length);
- String codePage = getCodePage ();
- String text = new String (Converter.mbcsToWcs (codePage, buffer));
- Event event = new Event ();
- if (textVerify.event != 0) {
- XKeyEvent xEvent = new XKeyEvent ();
- OS.memmove (xEvent, textVerify.event, XKeyEvent.sizeof);
- event.time = xEvent.time;
- setKeyState (event, xEvent);
- }
- event.start = textVerify.startPos;
- event.end = textVerify.endPos;
- event.doit = textVerify.doit == 1;
- event.text = text;
- sendEvent (SWT.Verify, event);
- String newText = event.text;
- textVerify.doit = (byte) ((event.doit && newText != null) ? 1 : 0);
- if (newText != null && newText != text) {
- OS.XtFree(textBlock.ptr);
- byte [] buffer2 = Converter.wcsToMbcs (codePage, newText, true);
- int length = buffer2.length;
- int ptr = OS.XtMalloc (length);
- OS.memmove (ptr, buffer2, length);
- textBlock.ptr = ptr;
- textBlock.length = buffer2.length - 1;
- OS.memmove (textVerify.text, textBlock, XmTextBlockRec.sizeof);
- }
- OS.memmove (call_data, textVerify, XmTextVerifyCallbackStruct.sizeof);
- return result;
-}
-int XmNvalueChangedCallback (int w, int client_data, int call_data) {
- sendEvent (SWT.Modify);
- return 0;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java
deleted file mode 100755
index e026007d46..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java
+++ /dev/null
@@ -1,1565 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.cairo.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are controls which are capable
- * of containing other controls.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>NO_BACKGROUND, NO_FOCUS, NO_MERGE_PAINTS, NO_REDRAW_RESIZE, NO_RADIO_GROUP, EMBEDDED, DOUBLE_BUFFERED</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: The <code>NO_BACKGROUND</code>, <code>NO_FOCUS</code>, <code>NO_MERGE_PAINTS</code>,
- * and <code>NO_REDRAW_RESIZE</code> styles are intended for use with <code>Canvas</code>.
- * They can be used with <code>Composite</code> if you are drawing your own, but their
- * behavior is undefined if they are used with subclasses of <code>Composite</code> other
- * than <code>Canvas</code>.
- * </p><p>
- * Note: The <code>CENTER</code> style, although undefined for composites, has the
- * same value as <code>EMBEDDED</code> which is used to embed widgets from other
- * widget toolkits into SWT. On some operating systems (GTK, Motif), this may cause
- * the children of this composite to be obscured.
- * </p><p>
- * This class may be subclassed by custom control implementors
- * who are building controls that are constructed from aggregates
- * of other controls.
- * </p>
- *
- * @see Canvas
- * @see <a href="http://www.eclipse.org/swt/snippets/#composite">Composite snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class Composite extends Scrollable {
- Layout layout;
- public int embeddedHandle;
- int focusHandle, damagedRegion, clientWindow;
- Control [] tabList;
- int layoutCount, backgroundMode;
-
- static byte [] _XEMBED_INFO = Converter.wcsToMbcs (null, "_XEMBED_INFO", true);
- static byte[] _XEMBED = Converter.wcsToMbcs (null, "_XEMBED", true);
-
-Composite () {
- /* Do nothing */
-}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- *
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_FOCUS
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_RADIO_GROUP
- * @see SWT#EMBEDDED
- * @see SWT#DOUBLE_BUFFERED
- * @see Widget#getStyle
- */
-public Composite (Composite parent, int style) {
- super (parent, style);
-}
-static int checkStyle (int style) {
- style &= ~SWT.TRANSPARENT;
- return style;
-}
-Control [] _getChildren () {
- int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int ptr = argList [1], count = argList [3];
- if (count == 0 || ptr == 0) return new Control [0];
- int [] handles = new int [count];
- OS.memmove (handles, ptr, count * 4);
- int length = focusHandle != 0 ? count - 1 : count;
- Control [] children = new Control [length];
- int i = 0, j = 0;
- while (i < count) {
- int handle = handles [i];
- if (handle != 0) {
- Widget widget = display.getWidget (handle);
- if (widget != null && widget != this) {
- if (widget instanceof Control) {
- children [j++] = (Control) widget;
- }
- }
- }
- i++;
- }
- if (j == length) return children;
- Control [] newChildren = new Control [j];
- System.arraycopy (children, 0, newChildren, 0, j);
- return newChildren;
-}
-Control [] _getTabList () {
- if (tabList == null) return tabList;
- int count = 0;
- for (int i=0; i<tabList.length; i++) {
- if (!tabList [i].isDisposed ()) count++;
- }
- if (count == tabList.length) return tabList;
- Control [] newList = new Control [count];
- int index = 0;
- for (int i=0; i<tabList.length; i++) {
- if (!tabList [i].isDisposed ()) {
- newList [index++] = tabList [i];
- }
- }
- tabList = newList;
- return tabList;
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- Point size;
- if (layout != null) {
- if ((wHint == SWT.DEFAULT) || (hHint == SWT.DEFAULT)) {
- changed |= (state & LAYOUT_CHANGED) != 0;
- size = layout.computeSize (this, wHint, hHint, changed);
- state &= ~LAYOUT_CHANGED;
- } else {
- size = new Point (wHint, hHint);
- }
- } else {
- size = minimumSize (wHint, hHint, changed);
- }
- if (size.x == 0) size.x = DEFAULT_WIDTH;
- if (size.y == 0) size.y = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) size.x = wHint;
- if (hHint != SWT.DEFAULT) size.y = hHint;
- Rectangle trim = computeTrim (0, 0, size.x, size.y);
- return new Point (trim.width, trim.height);
-}
-Control [] computeTabList () {
- Control result [] = super.computeTabList ();
- if (result.length == 0) return result;
- Control [] list = tabList != null ? _getTabList () : _getChildren ();
- for (int i=0; i<list.length; i++) {
- Control child = list [i];
- Control [] childList = child.computeTabList ();
- if (childList.length != 0) {
- Control [] newResult = new Control [result.length + childList.length];
- System.arraycopy (result, 0, newResult, 0, result.length);
- System.arraycopy (childList, 0, newResult, result.length, childList.length);
- result = newResult;
- }
- }
- return result;
-}
-/**
- * Clears any data that has been cached by a Layout for all widgets that
- * are in the parent hierarchy of the changed control up to and including the
- * receiver. If an ancestor does not have a layout, it is skipped.
- *
- * @param changed an array of controls that changed state and require a recalculation of size
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li>
- * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void changed (Control[] changed) {
- checkWidget ();
- if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<changed.length; i++) {
- Control control = changed [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean ancestor = false;
- Composite composite = control.parent;
- while (composite != null) {
- ancestor = composite == this;
- if (ancestor) break;
- composite = composite.parent;
- }
- if (!ancestor) error (SWT.ERROR_INVALID_PARENT);
- }
- for (int i=0; i<changed.length; i++) {
- Control child = changed [i];
- Composite composite = child.parent;
- while (child != this) {
- if (composite.layout == null || !composite.layout.flushCache (child)) {
- composite.state |= LAYOUT_CHANGED;
- }
- child = composite;
- composite = child.parent;
- }
- }
-}
-void checkBuffered () {
- if ((state & CANVAS) == 0) {
- super.checkBuffered ();
- }
-}
-protected void checkSubclass () {
- /* Do nothing - Subclassing is allowed */
-}
-void createHandle (int index) {
- state |= CANVAS;
- boolean scroll = (style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0;
- if (!scroll) state |= THEME_BACKGROUND;
- createHandle (index, parent.handle, scroll);
-}
-void createHandle (int index, int parentHandle, boolean scrolled) {
- if (scrolled) {
- int [] argList = {OS.XmNancestorSensitive, 1};
- scrolledHandle = OS.XmCreateMainWindow (parentHandle, null, argList, argList.length / 2);
- if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
- }
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) {
- int [] argList1 = {
- OS.XmNmarginWidth, 3,
- OS.XmNmarginHeight, 3,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNshadowType, OS.XmSHADOW_IN,
- OS.XmNshadowThickness, hasBorder () ? display.buttonShadowThickness : 0,
- };
- formHandle = OS.XmCreateForm (scrolledHandle, null, argList1, argList1.length / 2);
- if (formHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int [] argList2 = {
- OS.XmNtopAttachment, OS.XmATTACH_FORM,
- OS.XmNbottomAttachment, OS.XmATTACH_FORM,
- OS.XmNleftAttachment, OS.XmATTACH_FORM,
- OS.XmNrightAttachment, OS.XmATTACH_FORM,
- OS.XmNresizable, 0,
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNtraversalOn, (style & SWT.NO_FOCUS) != 0 ? 0 : 1,
- };
- handle = OS.XmCreateDrawingArea (formHandle, null, argList2, argList2.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- } else {
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNborderWidth, hasBorder () ? 1 : 0,
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNtraversalOn, (style & SWT.NO_FOCUS) != 0 ? 0 : 1,
- };
- if (scrolledHandle != 0) parentHandle = scrolledHandle;
- handle = OS.XmCreateDrawingArea (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- }
- int [] argList = {OS.XmNtraversalOn, 0};
- focusHandle = OS.XmCreateDrawingArea (handle, null, argList, argList.length / 2);
- if (focusHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int [] argList1 = {OS.XmNforeground, 0, OS.XmNbackground, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- if (formHandle != 0) OS.XtSetValues (formHandle, argList1, argList1.length / 2);
-}
-int defaultBackground () {
- return display.compositeBackground;
-}
-int defaultForeground () {
- return display.compositeForeground;
-}
-void deregister () {
- super.deregister ();
- if (focusHandle != 0) display.removeWidget (focusHandle);
-}
-void drawBackground (GC gc, int x, int y, int width, int height) {
- Control control = findBackgroundControl ();
- if (control != null) {
- GCData data = gc.getGCData ();
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- Cairo.cairo_save (cairo);
- if (control.backgroundImage != null) {
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (handle, (short) 0, (short) 0, root_x, root_y);
- short [] control_x = new short [1], control_y = new short [1];
- OS.XtTranslateCoords (control.handle, (short) 0, (short) 0, control_x, control_y);
- int tileX = root_x[0] - control_x[0], tileY = root_y[0] - control_y[0];
- Cairo.cairo_translate (cairo, -tileX, -tileY);
- x += tileX;
- y += tileY;
- int xDisplay = OS.XtDisplay (handle);
- int xVisual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay));
- int xDrawable = control.backgroundImage.pixmap;
- int [] unused = new int [1]; int [] w = new int [1]; int [] h = new int [1];
- OS.XGetGeometry (xDisplay, xDrawable, unused, unused, unused, w, h, unused, unused);
- int /*long*/ surface = Cairo.cairo_xlib_surface_create (xDisplay, xDrawable, xVisual, w [0], h [0]);
- if (surface == 0) error (SWT.ERROR_NO_HANDLES);
- int /*long*/ pattern = Cairo.cairo_pattern_create_for_surface (surface);
- if (pattern == 0) error (SWT.ERROR_NO_HANDLES);
- Cairo.cairo_pattern_set_extend (pattern, Cairo.CAIRO_EXTEND_REPEAT);
- Cairo.cairo_set_source (cairo, pattern);
- Cairo.cairo_surface_destroy (surface);
- Cairo.cairo_pattern_destroy (pattern);
- } else {
- XColor color = getXColor (control.getBackgroundPixel ());
- Cairo.cairo_set_source_rgba (cairo, (color.red & 0xFFFF) / (float)0xFFFF, (color.green & 0xFFFF) / (float)0xFFFF, (color.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF);
- }
- Cairo.cairo_rectangle (cairo, x, y, width, height);
- Cairo.cairo_fill (cairo);
- Cairo.cairo_restore (cairo);
- } else {
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xGC = gc.handle;
- XGCValues values = new XGCValues();
- if (control.backgroundImage != null) {
- OS.XGetGCValues (xDisplay, xGC, OS.GCFillStyle | OS.GCTile | OS.GCTileStipXOrigin | OS.GCTileStipYOrigin, values);
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (handle, (short) 0, (short) 0, root_x, root_y);
- short [] control_x = new short [1], control_y = new short [1];
- OS.XtTranslateCoords (control.handle, (short) 0, (short) 0, control_x, control_y);
- int tileX = root_x[0] - control_x[0], tileY = root_y[0] - control_y[0];
- OS.XSetFillStyle (xDisplay, xGC, OS.FillTiled);
- OS.XSetTSOrigin (xDisplay, xGC, -tileX, -tileY);
- OS.XSetTile (xDisplay, xGC, control.backgroundImage.pixmap);
- OS.XFillRectangle (data.display, data.drawable, xGC, x, y, width, height);
- OS.XSetFillStyle (xDisplay, xGC, values.fill_style);
- OS.XSetTSOrigin (xDisplay, xGC, values.ts_x_origin, values.ts_y_origin);
- } else {
- OS.XGetGCValues (xDisplay, xGC, OS.GCForeground, values);
- OS.XSetForeground (xDisplay, xGC, control.getBackgroundPixel ());
- OS.XFillRectangle (data.display, data.drawable, xGC, x, y, width, height);
- OS.XSetForeground (xDisplay, xGC, values.foreground);
- }
- }
- } else {
- gc.fillRectangle (x, y, width, height);
- }
-}
-Composite findDeferredControl () {
- return layoutCount > 0 ? this : parent.findDeferredControl ();
-}
-void fixTabList (Control control) {
- if (tabList == null) return;
- int count = 0;
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == control) count++;
- }
- if (count == 0) return;
- Control [] newList = null;
- int length = tabList.length - count;
- if (length != 0) {
- newList = new Control [length];
- int index = 0;
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] != control) {
- newList [index++] = tabList [i];
- }
- }
- }
- tabList = newList;
-}
-int focusHandle () {
- if (focusHandle == 0) return super.focusHandle ();
- return focusHandle;
-}
-int focusProc (int w, int client_data, int call_data, int continue_to_dispatch) {
- XFocusChangeEvent xEvent = new XFocusChangeEvent ();
- OS.memmove (xEvent, call_data, XFocusChangeEvent.sizeof);
- int handle = OS.XtWindowToWidget (xEvent.display, xEvent.window);
- Shell shell = getShell ();
- if (handle != shell.shellHandle) {
- return super.XFocusChange (w, client_data, call_data, continue_to_dispatch);
- }
- if (xEvent.mode != OS.NotifyNormal) return 0;
- switch (xEvent.detail) {
- case OS.NotifyNonlinear:
- case OS.NotifyNonlinearVirtual: {
- switch (xEvent.type) {
- case OS.FocusIn:
- sendClientEvent (OS.CurrentTime, OS.XEMBED_WINDOW_ACTIVATE, 0, 0, 0);
- break;
- case OS.FocusOut:
- sendClientEvent (OS.CurrentTime, OS.XEMBED_WINDOW_DEACTIVATE, 0, 0, 0);
- break;
- }
- }
- }
- return 0;
-}
-boolean fowardKeyEvent (int event) {
- if (clientWindow == 0) return false;
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- XKeyEvent xEvent = new XKeyEvent ();
- OS.memmove (xEvent, event, XKeyEvent.sizeof);
- xEvent.window = clientWindow;
- int newEvent = OS.XtMalloc (XEvent.sizeof);
- OS.memmove (newEvent, xEvent, XKeyEvent.sizeof);
- int xDisplay = OS.XtDisplay (handle);
- OS.XSendEvent (xDisplay, clientWindow, false, 0, newEvent);
- OS.XSync (xDisplay, false);
- OS.XtFree (newEvent);
- display.setWarnings (warnings);
- return true;
-}
-/**
- * Returns the receiver's background drawing mode. This
- * will be one of the following constants defined in class
- * <code>SWT</code>:
- * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>,
- * <code>INHERTIT_FORCE</code>.
- *
- * @return the background mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- *
- * @since 3.2
- */
-public int getBackgroundMode () {
- checkWidget ();
- return backgroundMode;
-}
-/**
- * Returns a (possibly empty) array containing the receiver's children.
- * Children are returned in the order that they are drawn. The topmost
- * control appears at the beginning of the array. Subsequent controls
- * draw beneath this control and appear later in the array.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of children, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return an array of children
- *
- * @see Control#moveAbove
- * @see Control#moveBelow
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control [] getChildren () {
- checkWidget();
- return _getChildren ();
-}
-public Rectangle getClientArea () {
- checkWidget();
- /*
- * Bug in Motif. For some reason, if a form has not been realized,
- * calling XtResizeWidget () on the form does not lay out properly.
- * The fix is to force the widget to be realized by forcing the shell
- * to be realized.
- */
- if (formHandle != 0) {
- if (!OS.XtIsRealized (handle)) getShell ().realizeWidget ();
- }
- return super.getClientArea ();
-}
-int getChildrenCount () {
- /*
- * NOTE: The current implementation will count
- * non-registered children.
- */
- int [] argList = {OS.XmNnumChildren, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (focusHandle != 0) return Math.max (0, argList [1] - 1);
- return argList [1];
-}
-/**
- * Returns layout which is associated with the receiver, or
- * null if one has not been set.
- *
- * @return the receiver's layout or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Layout getLayout () {
- checkWidget();
- return layout;
-}
-/**
- * Returns <code>true</code> if the receiver has deferred
- * the performing of layout, and <code>false</code> otherwise.
- *
- * @return the receiver's deferred layout state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setLayoutDeferred(boolean)
- * @see #isLayoutDeferred()
- *
- * @since 3.1
- */
-public boolean getLayoutDeferred () {
- checkWidget ();
- return layoutCount > 0 ;
-}
-/**
- * Gets the (possibly empty) tabbing order for the control.
- *
- * @return tabList the ordered list of controls representing the tab order
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setTabList
- */
-public Control [] getTabList () {
- checkWidget ();
- Control [] tabList = _getTabList ();
- if (tabList == null) {
- int count = 0;
- Control [] list =_getChildren ();
- for (int i=0; i<list.length; i++) {
- if (list [i].isTabGroup ()) count++;
- }
- tabList = new Control [count];
- int index = 0;
- for (int i=0; i<list.length; i++) {
- if (list [i].isTabGroup ()) {
- tabList [index++] = list [i];
- }
- }
- }
- return tabList;
-}
-boolean hasBorder () {
- return (style & SWT.BORDER) != 0;
-}
-void hookEvents () {
- super.hookEvents ();
- if ((state & CANVAS) != 0) {
- OS.XtInsertEventHandler (handle, 0, true, display.windowProc, NON_MASKABLE, OS.XtListTail);
- }
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) {
- int focusProc = display.focusProc;
- int windowProc = display.windowProc;
- OS.XtInsertEventHandler (handle, OS.StructureNotifyMask | OS.SubstructureNotifyMask, false, windowProc, STRUCTURE_NOTIFY, OS.XtListTail);
- OS.XtInsertEventHandler (handle, OS.PropertyChangeMask, false, windowProc, PROPERTY_CHANGE, OS.XtListTail);
- OS.XtInsertEventHandler (handle, 0, true, windowProc, NON_MASKABLE, OS.XtListTail);
- Shell shell = getShell ();
- OS.XtInsertEventHandler (shell.shellHandle, OS.FocusChangeMask, false, focusProc, handle, OS.XtListTail);
- }
-}
-
-boolean hooksKeys () {
- return hooks (SWT.KeyDown) || hooks (SWT.KeyUp);
-}
-/**
- * Returns <code>true</code> if the receiver or any ancestor
- * up to and including the receiver's nearest ancestor shell
- * has deferred the performing of layouts. Otherwise, <code>false</code>
- * is returned.
- *
- * @return the receiver's deferred layout state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setLayoutDeferred(boolean)
- * @see #getLayoutDeferred()
- *
- * @since 3.1
- */
-public boolean isLayoutDeferred () {
- checkWidget ();
- return findDeferredControl () != null;
-}
-boolean isTabGroup () {
- if ((state & CANVAS) != 0) return true;
- return super.isTabGroup ();
-}
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the receiver does not have a layout, do nothing.
- * <p>
- * This is equivalent to calling <code>layout(true)</code>.
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void layout () {
- checkWidget ();
- layout (true);
-}
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the argument is <code>true</code> the layout must not rely
- * on any information it has cached about the immediate children. If it
- * is <code>false</code> the layout may (potentially) optimize the
- * work it is doing by assuming that none of the receiver's
- * children has changed state since the last layout.
- * If the receiver does not have a layout, do nothing.
- * <p>
- * If a child is resized as a result of a call to layout, the
- * resize event will invoke the layout of the child. The layout
- * will cascade down through all child widgets in the receiver's widget
- * tree until a child is encountered that does not resize. Note that
- * a layout due to a resize will not flush any cached information
- * (same as <code>layout(false)</code>).
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void layout (boolean changed) {
- checkWidget ();
- if (layout == null) return;
- layout (changed, false);
-}
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the changed argument is <code>true</code> the layout must not rely
- * on any information it has cached about its children. If it
- * is <code>false</code> the layout may (potentially) optimize the
- * work it is doing by assuming that none of the receiver's
- * children has changed state since the last layout.
- * If the all argument is <code>true</code> the layout will cascade down
- * through all child widgets in the receiver's widget tree, regardless of
- * whether the child has changed size. The changed argument is applied to
- * all layouts. If the all argument is <code>false</code>, the layout will
- * <em>not</em> cascade down through all child widgets in the receiver's widget
- * tree. However, if a child is resized as a result of a call to layout, the
- * resize event will invoke the layout of the child. Note that
- * a layout due to a resize will not flush any cached information
- * (same as <code>layout(false)</code>).
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise
- * @param all <code>true</code> if all children in the receiver's widget tree should be laid out, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void layout (boolean changed, boolean all) {
- checkWidget ();
- if (layout == null && !all) return;
- markLayout (changed, all);
- updateLayout (all);
-}
-/**
- * Forces a lay out (that is, sets the size and location) of all widgets that
- * are in the parent hierarchy of the changed control up to and including the
- * receiver. The layouts in the hierarchy must not rely on any information
- * cached about the changed control or any of its ancestors. The layout may
- * (potentially) optimize the work it is doing by assuming that none of the
- * peers of the changed control have changed state since the last layout.
- * If an ancestor does not have a layout, skip it.
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed a control that has had a state change which requires a recalculation of its size
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li>
- * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void layout (Control [] changed) {
- checkWidget ();
- if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<changed.length; i++) {
- Control control = changed [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean ancestor = false;
- Composite composite = control.parent;
- while (composite != null) {
- ancestor = composite == this;
- if (ancestor) break;
- composite = composite.parent;
- }
- if (!ancestor) error (SWT.ERROR_INVALID_PARENT);
- }
- int updateCount = 0;
- Composite [] update = new Composite [16];
- for (int i=0; i<changed.length; i++) {
- Control child = changed [i];
- Composite composite = child.parent;
- while (child != this) {
- if (composite.layout != null) {
- composite.state |= LAYOUT_NEEDED;
- if (!composite.layout.flushCache (child)) {
- composite.state |= LAYOUT_CHANGED;
- }
- }
- if (updateCount == update.length) {
- Composite [] newUpdate = new Composite [update.length + 16];
- System.arraycopy (update, 0, newUpdate, 0, update.length);
- update = newUpdate;
- }
- child = update [updateCount++] = composite;
- composite = child.parent;
- }
- }
- for (int i=updateCount-1; i>=0; i--) {
- update [i].updateLayout (false);
- }
-}
-void manageChildren () {
- if (focusHandle != 0) {
- OS.XtSetMappedWhenManaged (focusHandle, false);
- OS.XtManageChild (focusHandle);
- }
- super.manageChildren ();
- if (focusHandle != 0) {
- OS.XtConfigureWidget(focusHandle, 0, 0, 1, 1, 0);
- OS.XtSetMappedWhenManaged (focusHandle, true);
- }
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) {
- Shell shell = getShell ();
- shell.createFocusProxy ();
- if (!OS.XtIsRealized (handle)) shell.realizeWidget ();
- int xDisplay = OS.XtDisplay (handle);
- OS.XSync (xDisplay, false);
- embeddedHandle = OS.XtWindow (handle);
- }
-}
-void markLayout (boolean changed, boolean all) {
- if (layout != null) {
- state |= LAYOUT_NEEDED;
- if (changed) state |= LAYOUT_CHANGED;
- }
- if (all) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].markLayout (changed, all);
- }
- }
-}
-Point minimumSize (int wHint, int hHint, boolean changed) {
- Control [] children = _getChildren ();
- int width = 0, height = 0;
- for (int i=0; i<children.length; i++) {
- Rectangle rect = children [i].getBounds ();
- width = Math.max (width, rect.x + rect.width);
- height = Math.max (height, rect.y + rect.height);
- }
- return new Point (width, height);
-}
-void moveAbove (int handle1, int handle2) {
- if (handle1 == handle2) return;
- int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int ptr = argList [1], count = argList [3];
- if (count == 0 || ptr == 0) return;
- int [] handles = new int [count];
- OS.memmove (handles, ptr, count * 4);
- if (handle2 == 0) handle2 = handles [0];
- int i = 0, index1 = -1, index2 = -1;
- while (i < count) {
- int handle = handles [i];
- if (handle == handle1) index1 = i;
- if (handle == handle2) index2 = i;
- if (index1 != -1 && index2 != -1) break;
- i++;
- }
- if (index1 == -1 || index2 == -1) return;
- if (index1 == index2) return;
- if (index1 < index2) {
- System.arraycopy (handles, index1 + 1, handles, index1, index2 - index1 - 1);
- handles [index2 - 1] = handle1;
- } else {
- System.arraycopy (handles, index2, handles, index2 + 1, index1 - index2);
- handles [index2] = handle1;
- }
- OS.memmove (ptr, handles, count * 4);
-}
-void moveBelow (int handle1, int handle2) {
- if (handle1 == handle2) return;
- int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int ptr = argList [1], count = argList [3];
- if (count == 0 || ptr == 0) return;
- int [] handles = new int [count];
- OS.memmove (handles, ptr, count * 4);
- if (handle2 == 0) handle2 = handles [count - 1];
- int i = 0, index1 = -1, index2 = -1;
- while (i < count) {
- int handle = handles [i];
- if (handle == handle1) index1 = i;
- if (handle == handle2) index2 = i;
- if (index1 != -1 && index2 != -1) break;
- i++;
- }
- if (index1 == -1 || index2 == -1) return;
- if (index1 == index2) return;
- if (index1 < index2) {
- System.arraycopy (handles, index1 + 1, handles, index1, index2 - index1);
- handles [index2] = handle1;
- } else {
- System.arraycopy (handles, index2 + 1, handles, index2 + 2, index1 - index2 - 1);
- handles [index2 + 1] = handle1;
- }
- OS.memmove (ptr, handles, count * 4);
-}
-void propagateChildren (boolean enabled) {
- super.propagateChildren (enabled);
- Control [] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- Control child = children [i];
- if (child.getEnabled ()) {
- child.propagateChildren (enabled);
- }
- }
-}
-void realizeChildren () {
- super.realizeChildren ();
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].realizeChildren ();
- }
- /*
- * Feature in Motif. XmProcessTraversal() will not give focus to
- * a widget that is obscured so the focus handle must be inside the
- * client area of the parent. This means that it is visible as a
- * single pixel widget in the parent. The fix is to unmap the
- * focus handle so that it will be traversed by XmProcessTraversal()
- * and will accept focus but will not be visible in the parent.
- */
- if (focusHandle != 0) OS.XtUnmapWidget (focusHandle);
- if ((state & CANVAS) != 0) {
- if ((style & (SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND)) != 0 || (style & SWT.NO_REDRAW_RESIZE) == 0) {
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- int flags = 0;
- XSetWindowAttributes attributes = new XSetWindowAttributes ();
- if ((style & (SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED)) != 0) {
- flags |= OS.CWBackPixmap;
- attributes.background_pixmap = OS.None;
- }
- if ((style & SWT.NO_REDRAW_RESIZE) == 0) {
- flags |= OS.CWBitGravity;
- attributes.bit_gravity = OS.ForgetGravity;
- }
- if (flags != 0) {
- OS.XChangeWindowAttributes (xDisplay, xWindow, flags, attributes);
- }
- }
- }
-}
-void redrawChildren () {
- super.redrawChildren ();
- Control [] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- Control child = children [i];
- if ((child.state & PARENT_BACKGROUND) != 0) {
- child.redrawWidget (0, 0, 0, 0, true, false, true);
- child.redrawChildren ();
- }
- }
-}
-void register () {
- super.register ();
- if (focusHandle != 0) display.addWidget (focusHandle, this);
-}
-void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean allChildren, boolean trim) {
- super.redrawWidget (x, y, width, height, redrawAll, allChildren, trim);
- if (!allChildren) return;
- Control [] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- Control child = children [i];
- Point location = child.getClientLocation ();
- child.redrawWidget (x - location.x, y - location.y, width, height, redrawAll, allChildren, true);
- }
-}
-void release (boolean destroy) {
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) {
- Shell shell = getShell ();
- int focusProc = display.focusProc;
- OS.XtRemoveEventHandler (shell.shellHandle, OS.FocusChangeMask, false, focusProc, handle);
- if (clientWindow != 0) {
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- int xDisplay = OS.XtDisplay (handle);
- OS.XUnmapWindow (xDisplay, clientWindow);
- OS.XReparentWindow (xDisplay, clientWindow, OS.XDefaultRootWindow (xDisplay), 0, 0);
- OS.XSync (xDisplay, false);
- display.setWarnings (warnings);
- }
- setClientWindow (0);
- }
- super.release (destroy);
-}
-void releaseChildren (boolean destroy) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child != null && !child.isDisposed ()) {
- child.release (false);
- }
- }
- super.releaseChildren (destroy);
-}
-void releaseHandle () {
- super.releaseHandle ();
- focusHandle = embeddedHandle = 0;
-}
-void releaseWidget () {
- super.releaseWidget ();
- layout = null;
- tabList = null;
- if (damagedRegion != 0) OS.XDestroyRegion (damagedRegion);
- damagedRegion = 0;
-}
-void removeControl (Control control) {
- fixTabList (control);
-}
-void resizeClientWindow () {
- if (clientWindow == 0) return;
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int xDisplay = OS.XtDisplay (handle);
- OS.XMoveResizeWindow (xDisplay, clientWindow, 0, 0, Math.max(1, argList [1]), Math.max(1, argList [3]));
- display.setWarnings (warnings);
-}
-void sendClientEvent (int time, int message, int detail, int data1, int data2) {
- if (clientWindow == 0) return;
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- int xDisplay = OS.XtDisplay (handle);
- XClientMessageEvent xEvent = new XClientMessageEvent ();
- xEvent.type = OS.ClientMessage;
- xEvent.window = clientWindow;
- xEvent.message_type = OS.XInternAtom (xDisplay, _XEMBED, false);
- xEvent.format = 32;
- xEvent.data [0] = time != 0 ? time : OS.XtLastTimestampProcessed (xDisplay);
- xEvent.data [1] = message;
- xEvent.data [2] = detail;
- xEvent.data [3] = data1;
- xEvent.data [4] = data2;
- int event = OS.XtMalloc (XEvent.sizeof);
- OS.memmove (event, xEvent, XClientMessageEvent.sizeof);
- OS.XSendEvent (xDisplay, clientWindow, false, 0, event);
- OS.XSync (xDisplay, false);
- OS.XtFree (event);
- display.setWarnings (warnings);
-}
-/**
- * Sets the background drawing mode to the argument which should
- * be one of the following constants defined in class <code>SWT</code>:
- * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>,
- * <code>INHERIT_FORCE</code>.
- *
- * @param mode the new background mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- *
- * @since 3.2
- */
-public void setBackgroundMode (int mode) {
- checkWidget ();
- backgroundMode = mode;
- Control[] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- children [i].updateBackgroundMode ();
- }
-}
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- if ((state & CANVAS) != 0) {
- if ((style & (SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED)) != 0) {
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- XSetWindowAttributes attributes = new XSetWindowAttributes ();
- attributes.background_pixmap = OS.None;
- OS.XChangeWindowAttributes (xDisplay, xWindow, OS.CWBackPixmap, attributes);
- }
- }
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- boolean changed = super.setBounds (x, y, width, height, move, resize);
- if (changed && resize) {
- if (focusHandle != 0) {
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XtConfigureWidget (focusHandle, 0, 0, argList [1], argList [3], 0);
- }
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) {
- resizeClientWindow ();
- }
- }
- return changed;
-}
-void setClientWindow (int window) {
- if (focusHandle != 0) {
- if (window == OS.XtWindow (focusHandle)) return;
- }
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- int xDisplay = OS.XtDisplay (handle);
- if (window != 0) {
- if (clientWindow == 0) {
- clientWindow = window;
- sendClientEvent (0, OS.XEMBED_EMBEDDED_NOTIFY, 0, 0, 0);
- OS.XtRegisterDrawable (xDisplay, clientWindow, handle);
- OS.XSelectInput (xDisplay, clientWindow, OS.PropertyChangeMask);
- updateMapped ();
- resizeClientWindow ();
- Shell shell = getShell ();
- if (shell == display.getActiveShell ()) {
- shell.bringToTop (true);
- sendClientEvent (0, OS.XEMBED_WINDOW_ACTIVATE, 0, 0, 0);
- if (this == display.getFocusControl ()) {
- sendClientEvent (0, OS.XEMBED_FOCUS_IN, OS.XEMBED_FOCUS_CURRENT, 0, 0);
- }
- }
- }
- } else {
- if (clientWindow != 0) OS.XtUnregisterDrawable (xDisplay, clientWindow);
- clientWindow = 0;
- }
- display.setWarnings (warnings);
-}
-public boolean setFocus () {
- checkWidget ();
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.setFocus ()) return true;
- }
- return super.setFocus ();
-}
-public void setFont (Font font) {
- checkWidget();
- super.setFont (font);
- if ((state & CANVAS) != 0) {
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- OS.XClearArea (xDisplay, xWindow, 0, 0, 0, 0, true);
- }
-}
-void setForegroundPixel (int pixel) {
- super.setForegroundPixel (pixel);
- if ((state & CANVAS) != 0) {
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- OS.XClearArea (xDisplay, xWindow, 0, 0, 0, 0, true);
- }
-}
-/**
- * Sets the layout which is associated with the receiver to be
- * the argument which may be null.
- *
- * @param layout the receiver's new layout or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLayout (Layout layout) {
- checkWidget();
- this.layout = layout;
-}
-/**
- * If the argument is <code>true</code>, causes subsequent layout
- * operations in the receiver or any of its children to be ignored.
- * No layout of any kind can occur in the receiver or any of its
- * children until the flag is set to false.
- * Layout operations that occurred while the flag was
- * <code>true</code> are remembered and when the flag is set to
- * <code>false</code>, the layout operations are performed in an
- * optimized manner. Nested calls to this method are stacked.
- *
- * @param defer the new defer state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #layout(boolean)
- * @see #layout(Control[])
- *
- * @since 3.1
- */
-public void setLayoutDeferred (boolean defer) {
- if (!defer) {
- if (--layoutCount == 0) {
- if ((state & LAYOUT_CHILD) != 0 || (state & LAYOUT_NEEDED) != 0) {
- updateLayout (true);
- }
- }
- } else {
- layoutCount++;
- }
-}
-/**
- * Sets the tabbing order for the specified controls to
- * match the order that they occur in the argument list.
- *
- * @param tabList the ordered list of controls representing the tab order or null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if a widget in the tabList is null or has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if widget in the tabList is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTabList (Control [] tabList) {
- checkWidget ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- Control control = tabList [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
- Control [] newList = new Control [tabList.length];
- System.arraycopy (tabList, 0, newList, 0, tabList.length);
- tabList = newList;
- }
- this.tabList = tabList;
-}
-void setParentBackground () {
- super.setParentBackground ();
- if (scrolledHandle != 0) setParentBackground (scrolledHandle);
- if (formHandle != 0) setParentBackground (formHandle);
-}
-boolean setScrollBarVisible (ScrollBar bar, boolean visible) {
- boolean changed = super.setScrollBarVisible (bar, visible);
- if (changed && layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
- return changed;
-}
-boolean setTabGroupFocus (boolean next) {
- if (isTabItem ()) return setTabItemFocus (next);
- boolean takeFocus = (style & SWT.NO_FOCUS) == 0;
- if ((state & CANVAS) != 0) {
- takeFocus = hooksKeys ();
- if ((style & SWT.EMBEDDED) != 0) takeFocus = true;
- }
- if (takeFocus && setTabItemFocus (next)) return true;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.isTabItem () && child.setTabItemFocus (next)) return true;
- }
- return false;
-}
-boolean setTabItemFocus (boolean next) {
- if (!super.setTabItemFocus (next)) return false;
- if (handle != 0) {
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) {
- int detail = next ? OS.XEMBED_FOCUS_FIRST : OS.XEMBED_FOCUS_LAST;
- sendClientEvent (0, OS.XEMBED_FOCUS_IN, detail, 0, 0);
- }
- }
- return true;
-}
-int traversalCode (int key, XKeyEvent xEvent) {
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_FOCUS) != 0) return 0;
- if (hooksKeys ()) return 0;
- }
- return super.traversalCode (key, xEvent);
-}
-boolean translateMnemonic (Event event, Control control) {
- if (super.translateMnemonic (event, control)) return true;
- if (control != null) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.translateMnemonic (event, control)) return true;
- }
- }
- return false;
-}
-boolean translateTraversal (int key, XKeyEvent xEvent) {
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) return false;
- return super.translateTraversal (key, xEvent);
-}
-void updateBackgroundMode () {
- super.updateBackgroundMode ();
- Control [] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- children [i].updateBackgroundMode ();
- }
-}
-void updateLayout (boolean all) {
- Composite parent = findDeferredControl ();
- if (parent != null) {
- parent.state |= LAYOUT_CHILD;
- return;
- }
- if ((state & LAYOUT_NEEDED) != 0) {
- boolean changed = (state & LAYOUT_CHANGED) != 0;
- state &= ~(LAYOUT_NEEDED | LAYOUT_CHANGED);
- layout.layout (this, changed);
- }
- if (all) {
- state &= ~LAYOUT_CHILD;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].updateLayout (all);
- }
- }
-}
-int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XButtonPress (w, client_data, call_data, continue_to_dispatch);
- if (result != 0) return result;
-
- /* Set focus for a canvas with no children */
- if ((state & CANVAS) != 0) {
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- if ((style & SWT.NO_FOCUS) == 0 && hooksKeys ()) {
- if (xEvent.button == 1) {
- if (getChildrenCount () == 0) setFocus ();
- }
- }
- /*
- * Bug in Motif. On Solaris 8 only, stopping the other event
- * handlers from being invoked after a menu has been displayed
- * causes a segment fault. The fix is to not stop the event for
- * button 3.
- */
- if (xEvent.button != 3) {
- OS.memmove (continue_to_dispatch, new int [1], 4);
- }
- return 1;
- }
- return result;
-}
-int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) {
- if ((state & CANVAS) == 0) {
- return super.XExposure (w, client_data, call_data, continue_to_dispatch);
- }
- if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0;
- if (damagedRegion == 0) damagedRegion = OS.XCreateRegion ();
- OS.XtAddExposureToRegion (call_data, damagedRegion);
- if ((style & SWT.NO_MERGE_PAINTS) == 0) {
- XExposeEvent xEvent = new XExposeEvent ();
- OS.memmove (xEvent, call_data, XExposeEvent.sizeof);
- int exposeCount = xEvent.count;
- if (exposeCount == 0) {
- if (OS.XEventsQueued (xEvent.display, OS.QueuedAfterReading) != 0) {
- int xEvent1 = OS.XtMalloc (XEvent.sizeof);
- display.exposeCount = display.lastExpose = 0;
- int checkExposeProc = display.checkExposeProc;
- OS.XCheckIfEvent (xEvent.display, xEvent1, checkExposeProc, xEvent.window);
- exposeCount = display.exposeCount;
- int lastExpose = display.lastExpose;
- if (exposeCount != 0 && lastExpose != 0) {
- XExposeEvent xExposeEvent = display.xExposeEvent;
- OS.memmove (xExposeEvent, lastExpose, XExposeEvent.sizeof);
- xExposeEvent.count = 0;
- OS.memmove (lastExpose, xExposeEvent, XExposeEvent.sizeof);
- }
- OS.XtFree (xEvent1);
- }
- }
- if (exposeCount != 0) return 0;
- }
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return 0;
- int damageRgn = damagedRegion;
- damagedRegion = 0;
- GCData data = new GCData ();
- data.damageRgn = damageRgn;
- GC gc = GC.motif_new (this, data);
- OS.XSetRegion (xDisplay, gc.handle, damageRgn);
- XRectangle rect = new XRectangle ();
- OS.XClipBox (damageRgn, rect);
- GC paintGC = null;
- Image image = null;
- if ((style & SWT.DOUBLE_BUFFERED) != 0) {
- Rectangle client = getClientArea ();
- int width = Math.max (1, Math.min (client.width, rect.x + rect.width));
- int height = Math.max (1, Math.min (client.height, rect.y + rect.height));
- image = new Image (display, width, height);
- paintGC = gc;
- GCData imageGCData = new GCData ();
- imageGCData.damageRgn = damageRgn;
- gc = GC.motif_new (image, imageGCData);
- gc.setForeground (getForeground ());
- gc.setBackground (getBackground ());
- gc.setFont (getFont ());
- if ((style & SWT.NO_BACKGROUND) != 0) {
- /* This code is intentionaly commented because it is too slow to copy bits from the screen */
-// paintGC.copyArea(image, 0, 0);
- } else {
- drawBackground (gc, 0, 0, width, height);
- }
- }
- Event event = new Event ();
- event.x = rect.x;
- event.y = rect.y;
- event.width = rect.width;
- event.height = rect.height;
- event.gc = gc;
- sendEvent (SWT.Paint, event);
- event.gc = null;
- if ((style & SWT.DOUBLE_BUFFERED) != 0) {
- gc.dispose ();
- if (!isDisposed ()) {
- paintGC.drawImage (image, 0, 0);
- }
- image.dispose ();
- gc = paintGC;
- }
- gc.dispose ();
- OS.XDestroyRegion (damageRgn);
- return 0;
-}
-int xFocusIn (XFocusChangeEvent xEvent) {
- int result = super.xFocusIn (xEvent);
- if (handle != 0) {
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) {
- sendClientEvent (0, OS.XEMBED_FOCUS_IN, OS.XEMBED_FOCUS_CURRENT, 0, 0);
- }
- }
- return result;
-}
-int xFocusOut (XFocusChangeEvent xEvent) {
- int result = super.xFocusOut (xEvent);
- if (handle != 0) {
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) {
- sendClientEvent (0, OS.XEMBED_FOCUS_OUT, 0, 0, 0);
- }
- }
- return result;
-}
-int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XKeyPress (w, client_data, call_data, continue_to_dispatch);
- if (result == 0) {
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) {
- if (fowardKeyEvent (call_data)) return 0;
- }
- }
- return result;
-}
-int XKeyRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XKeyRelease (w, client_data, call_data, continue_to_dispatch);
- if (result == 0) {
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) {
- if (fowardKeyEvent (call_data)) return 0;
- }
- }
- return result;
-}
-int XNonMaskable (int w, int client_data, int call_data, int continue_to_dispatch) {
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) {
- XEvent xEvent = new XEvent ();
- OS.memmove (xEvent, call_data, XEvent.sizeof);
- if (xEvent.type == OS.ClientMessage) {
- XClientMessageEvent xClientEvent = new XClientMessageEvent ();
- OS.memmove (xClientEvent, call_data, XClientMessageEvent.sizeof);
- int xDisplay = OS.XtDisplay (handle);
- if (xClientEvent.message_type == OS.XInternAtom (xDisplay, _XEMBED, false)) {
- int type = xClientEvent.data [1];
- switch (type) {
- case OS.XEMBED_REQUEST_FOCUS: {
- setFocus ();
- break;
- }
- case OS.XEMBED_FOCUS_PREV: {
- traverse (SWT.TRAVERSE_TAB_PREVIOUS);
- break;
- }
- case OS.XEMBED_FOCUS_NEXT: {
- traverse (SWT.TRAVERSE_TAB_NEXT);
- break;
- }
- }
- }
- return 0;
- }
- }
- if ((state & CANVAS) != 0) {
- XEvent xEvent = new XEvent ();
- OS.memmove (xEvent, call_data, XEvent.sizeof);
- if (xEvent.type == OS.GraphicsExpose) {
- return XExposure (w, client_data, call_data, continue_to_dispatch);
- }
- }
- return 0;
-}
-int XPropertyChange (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XPropertyChange (w, client_data, call_data, continue_to_dispatch);
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) {
- XPropertyEvent xPropertyEvent = new XPropertyEvent ();
- OS.memmove(xPropertyEvent, call_data, XPropertyEvent.sizeof);
- if (xPropertyEvent.window == clientWindow) {
- int atom = xPropertyEvent.atom;
- int xDisplay = xPropertyEvent.display;
- if (atom == OS.XInternAtom (xDisplay, _XEMBED_INFO, false)) {
- updateMapped ();
- }
- }
- }
- return result;
-}
-int XStructureNotify (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XStructureNotify (w, client_data, call_data, continue_to_dispatch);
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) {
- XEvent xEvent = new XEvent ();
- OS.memmove (xEvent, call_data, XEvent.sizeof);
- switch (xEvent.type) {
- case OS.ReparentNotify: {
- XReparentEvent xReparentEvent = new XReparentEvent ();
- OS.memmove (xReparentEvent, call_data, XReparentEvent.sizeof);
- if (clientWindow == 0) setClientWindow (xReparentEvent.window);
- break;
- }
- case OS.CreateNotify: {
- XCreateWindowEvent xCreateEvent = new XCreateWindowEvent ();
- OS.memmove (xCreateEvent, call_data, XCreateWindowEvent.sizeof);
- if (clientWindow == 0) setClientWindow (xCreateEvent.window);
- break;
- }
- case OS.DestroyNotify: {
- XDestroyWindowEvent xDestroyEvent = new XDestroyWindowEvent ();
- OS.memmove (xDestroyEvent, call_data, XDestroyWindowEvent.sizeof);
- if (xDestroyEvent.window == clientWindow) setClientWindow (0);
- break;
- }
- case OS.ConfigureNotify: {
- XConfigureEvent xConfigureEvent = new XConfigureEvent ();
- OS.memmove (xConfigureEvent, call_data, XConfigureEvent.sizeof);
- if (xConfigureEvent.window == clientWindow) resizeClientWindow ();
- break;
- }
- }
- }
- return result;
-}
-void updateMapped () {
- if (clientWindow == 0) return;
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- int xDisplay = OS.XtDisplay (handle);
- int prop = OS.XInternAtom (xDisplay, _XEMBED_INFO, false);
- int [] type = new int [1], format = new int [1];
- int [] nitems = new int [1], bytes_after = new int [1], data = new int [1];
- if (OS.XGetWindowProperty (xDisplay, clientWindow, prop, 0, 2, false, prop, type, format, nitems, bytes_after, data) == 0) {
- if (type [0] == prop) {
- if (nitems [0] >= 2) {
- int [] buffer = new int [2];
- OS.memmove (buffer, data [0], buffer.length * 4);
- int flags = buffer [1];
- if ((flags & OS.XEMBED_MAPPED) != 0) {
- OS.XMapWindow (xDisplay, clientWindow);
- } else {
- OS.XUnmapWindow (xDisplay, clientWindow);
- }
- }
- }
- }
- if (data [0] != 0) OS.XFree (data [0]);
- display.setWarnings (warnings);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java
deleted file mode 100755
index 0a10bccddb..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java
+++ /dev/null
@@ -1,3761 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.accessibility.*;
-
-/**
- * Control is the abstract superclass of all windowed user interface classes.
- * <p>
- * <dl>
- * <dt><b>Styles:</b>
- * <dd>BORDER</dd>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * <dt><b>Events:</b>
- * <dd>DragDetect, FocusIn, FocusOut, Help, KeyDown, KeyUp, MenuDetect, MouseDoubleClick, MouseDown, MouseEnter,
- * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize, Traverse</dd>
- * </dl>
- * </p><p>
- * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#control">Control snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public abstract class Control extends Widget implements Drawable {
- int drawCount, redrawWindow;
- Composite parent;
- Cursor cursor;
- Menu menu;
- Image backgroundImage;
- Font font;
- Region region;
- String toolTipText;
- Object layoutData;
- Accessible accessible;
-
-Control () {
- /* Do nothing */
-}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#LEFT_TO_RIGHT
- * @see SWT#RIGHT_TO_LEFT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Control (Composite parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget (0);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize,typedListener);
- addListener (SWT.Move,typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when a drag gesture occurs, by sending it
- * one of the messages defined in the <code>DragDetectListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #removeDragDetectListener
- *
- * @since 3.3
- */
-public void addDragDetectListener (DragDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.DragDetect,typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control gains or loses focus, by sending
- * it one of the messages defined in the <code>FocusListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see FocusListener
- * @see #removeFocusListener
- */
-public void addFocusListener(FocusListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.FocusIn,typedListener);
- addListener(SWT.FocusOut,typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when help events are generated for the control,
- * by sending it one of the messages defined in the
- * <code>HelpListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard, by sending
- * it one of the messages defined in the <code>KeyListener</code>
- * interface.
- * <p>
- * When a key listener is added to a control, the control
- * will take part in widget traversal. By default, all
- * traversal keys (such as the tab key and so on) are
- * delivered to the control. In order for a control to take
- * part in traversal, it should listen for traversal events.
- * Otherwise, the user can traverse into a control but not
- * out. Note that native controls such as table and tree
- * implement key traversal in the operating system. It is
- * not necessary to add traversal listeners for these controls,
- * unless you want to override the default traversal.
- * </p>
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #removeKeyListener
- */
-public void addKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.KeyUp,typedListener);
- addListener(SWT.KeyDown,typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the platform-specific context menu trigger
- * has occurred, by sending it one of the messages defined in
- * the <code>MenuDetectListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #removeMenuDetectListener
- *
- * @since 3.3
- */
-public void addMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MenuDetect, typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when mouse buttons are pressed and released, by sending
- * it one of the messages defined in the <code>MouseListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseListener
- * @see #removeMouseListener
- */
-public void addMouseListener(MouseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.MouseDown,typedListener);
- addListener(SWT.MouseUp,typedListener);
- addListener(SWT.MouseDoubleClick,typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse moves, by sending it one of the
- * messages defined in the <code>MouseMoveListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseMoveListener
- * @see #removeMouseMoveListener
- */
-public void addMouseMoveListener(MouseMoveListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.MouseMove,typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse passes or hovers over controls, by sending
- * it one of the messages defined in the <code>MouseTrackListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseTrackListener
- * @see #removeMouseTrackListener
- */
-public void addMouseTrackListener (MouseTrackListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseEnter,typedListener);
- addListener (SWT.MouseExit,typedListener);
- addListener (SWT.MouseHover,typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse wheel is scrolled, by sending
- * it one of the messages defined in the
- * <code>MouseWheelListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseWheelListener
- * @see #removeMouseWheelListener
- *
- * @since 3.3
- */
-public void addMouseWheelListener (MouseWheelListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseWheel, typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver needs to be painted, by sending it
- * one of the messages defined in the <code>PaintListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see PaintListener
- * @see #removePaintListener
- */
-public void addPaintListener(PaintListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.Paint,typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when traversal events occur, by sending it
- * one of the messages defined in the <code>TraverseListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TraverseListener
- * @see #removeTraverseListener
- */
-public void addTraverseListener (TraverseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Traverse,typedListener);
-}
-int borderHandle () {
- return topHandle ();
-}
-void checkBackground () {
- Shell shell = getShell ();
- if (this == shell) return;
- state &= ~PARENT_BACKGROUND;
- Composite composite = parent;
- do {
- int mode = composite.backgroundMode;
- if (mode != 0) {
- if (mode == SWT.INHERIT_DEFAULT) {
- Control control = this;
- do {
- if ((control.state & THEME_BACKGROUND) == 0) {
- return;
- }
- control = control.parent;
- } while (control != composite);
- }
- state |= PARENT_BACKGROUND;
- return;
- }
- if (composite == shell) break;
- composite = composite.parent;
- } while (true);
-}
-void checkBuffered () {
- style &= ~SWT.DOUBLE_BUFFERED;
-}
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>preferred size</em> of a control is the size that it would
- * best be displayed at. The width hint and height hint arguments
- * allow the caller to ask a control questions such as "Given a particular
- * width, how high does the control need to be to show all of the contents?"
- * To indicate that the caller does not wish to constrain a particular
- * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
- * </p>
- *
- * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
- * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
- * @return the preferred size of the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Layout
- * @see #getBorderWidth
- * @see #getBounds
- * @see #getSize
- * @see #pack(boolean)
- * @see "computeTrim, getClientArea for controls that implement them"
- */
-public Point computeSize (int wHint, int hHint) {
- return computeSize (wHint, hHint, true);
-}
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>preferred size</em> of a control is the size that it would
- * best be displayed at. The width hint and height hint arguments
- * allow the caller to ask a control questions such as "Given a particular
- * width, how high does the control need to be to show all of the contents?"
- * To indicate that the caller does not wish to constrain a particular
- * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
- * </p><p>
- * If the changed flag is <code>true</code>, it indicates that the receiver's
- * <em>contents</em> have changed, therefore any caches that a layout manager
- * containing the control may have been keeping need to be flushed. When the
- * control is resized, the changed flag will be <code>false</code>, so layout
- * manager caches can be retained.
- * </p>
- *
- * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
- * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
- * @param changed <code>true</code> if the control's contents have changed, and <code>false</code> otherwise
- * @return the preferred size of the control.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Layout
- * @see #getBorderWidth
- * @see #getBounds
- * @see #getSize
- * @see #pack(boolean)
- * @see "computeTrim, getClientArea for controls that implement them"
- */
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = DEFAULT_WIDTH;
- int height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2;
- height += border * 2;
- return new Point (width, height);
-}
-
-Control computeTabGroup () {
- if (isTabGroup ()) return this;
- return parent.computeTabGroup ();
-}
-
-Control computeTabRoot () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- int index = 0;
- while (index < tabList.length) {
- if (tabList [index] == this) break;
- index++;
- }
- if (index == tabList.length) {
- if (isTabGroup ()) return this;
- }
- }
- return parent.computeTabRoot ();
-}
-
-Control [] computeTabList () {
- if (isTabGroup ()) {
- if (getVisible () && getEnabled ()) {
- return new Control [] {this};
- }
- }
- return new Control [0];
-}
-
-void createWidget (int index) {
- state |= DRAG_DETECT;
- checkOrientation (parent);
- super.createWidget (index);
- checkBackground ();
- checkBuffered ();
- setParentTraversal ();
- overrideTranslations ();
-
- /*
- * Register for the IME. This is necessary on single byte
- * platforms as well as double byte platforms in order to
- * get composed characters. For example, accented characters
- * on a German locale.
- */
- if (!hasIMSupport()) {
- OS.XmImRegister (handle, 0);
- int focusHandle = focusHandle ();
- if (handle != focusHandle) {
- OS.XmImRegister (focusHandle, 0);
- }
- }
-
- /*
- * Feature in MOTIF. When a widget is created before the
- * parent has been realized, the widget is created behind
- * all siblings in the Z-order. When a widget is created
- * after the parent has been realized, it is created in
- * front of all siblings. This is not incorrect but is
- * unexpected. The fix is to force all widgets to always
- * be created behind their siblings.
- */
- int topHandle = topHandle ();
- if (OS.XtIsRealized (topHandle) && !OS.XtIsSubclass (topHandle, OS.shellWidgetClass ())) {
- int window = OS.XtWindow (topHandle);
- if (window != 0) {
- int display = OS.XtDisplay (topHandle);
- if (display != 0) OS.XLowerWindow (display, window);
- }
- /*
- * Make sure that the widget has been properly realized
- * because the widget was created after the parent
- * has been realized. This is not part of the fix
- * for Z-order in the code above.
- */
- realizeChildren ();
- }
-
- /*
- * Bug in Motif. Under certain circumstances, when a
- * text widget is created as a child of another control
- * that has drag and drop, starting a drag in the text
- * widget causes a protection fault. The fix is to
- * disable the built in drag and drop for all widgets
- * by overriding the drag start traslation.
- */
- OS.XtOverrideTranslations (handle, display.dragTranslations);
-
- /*
- * Feature in Motif. When the XmNfontList resource is set for
- * a widget, Motif creates a copy of the fontList and disposes
- * the copy when the widget is disposed. This means that when
- * the programmer queries the font, not only will the handle be
- * different but the font will be unexpectedly disposed when
- * the widget is disposed. This can cause GP's when the font
- * is set in another widget. The fix is to cache the font that
- * the programmer provides. The initial value of the cache is
- * the default font for the widget.
- */
- font = defaultFont ();
-}
-int defaultBackground () {
- return display.defaultBackground;
-}
-Font defaultFont () {
- return display.defaultFont;
-}
-int defaultForeground () {
- return display.defaultForeground;
-}
-/**
- * Detects a drag and drop gesture. This method is used
- * to detect a drag gesture when called from within a mouse
- * down listener.
- *
- * <p>By default, a drag is detected when the gesture
- * occurs anywhere within the client area of a control.
- * Some controls, such as tables and trees, override this
- * behavior. In addition to the operating system specific
- * drag gesture, they require the mouse to be inside an
- * item. Custom widget writers can use <code>setDragDetect</code>
- * to disable the default detection, listen for mouse down,
- * and then call <code>dragDetect()</code> from within the
- * listener to conditionally detect a drag.
- * </p>
- *
- * @param event the mouse down event
- *
- * @return <code>true</code> if the gesture occurred, and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT when the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @see #getDragDetect
- * @see #setDragDetect
- *
- * @since 3.3
- */
-public boolean dragDetect (Event event) {
- checkWidget ();
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- return dragDetect (event.button, event.count, event.stateMask, event.x, event.y);
-}
-/**
- * Detects a drag and drop gesture. This method is used
- * to detect a drag gesture when called from within a mouse
- * down listener.
- *
- * <p>By default, a drag is detected when the gesture
- * occurs anywhere within the client area of a control.
- * Some controls, such as tables and trees, override this
- * behavior. In addition to the operating system specific
- * drag gesture, they require the mouse to be inside an
- * item. Custom widget writers can use <code>setDragDetect</code>
- * to disable the default detection, listen for mouse down,
- * and then call <code>dragDetect()</code> from within the
- * listener to conditionally detect a drag.
- * </p>
- *
- * @param event the mouse down event
- *
- * @return <code>true</code> if the gesture occurred, and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT when the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @see #getDragDetect
- * @see #setDragDetect
- *
- * @since 3.3
- */
-public boolean dragDetect (MouseEvent event) {
- checkWidget ();
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- return dragDetect (event.button, event.count, event.stateMask, event.x, event.y);
-}
-boolean dragDetect (int button, int count, int stateMask, int x, int y) {
- if (button != 2 || count != 1) return false;
- if (!dragDetect (x, y, false, null)) return false;
- return sendDragEvent (button, stateMask, x, y, true);
-}
-boolean dragDetect (int x, int y, boolean force, boolean [] consume) {
- return true;
-}
-boolean drawGripper (int x, int y, int width, int height, boolean vertical) {
- return false;
-}
-void enableWidget (boolean enabled) {
- enableHandle (enabled, handle);
-}
-Control findBackgroundControl () {
- if ((state & BACKGROUND) != 0 || backgroundImage != null) return this;
- return (state & PARENT_BACKGROUND) != 0 ? parent.findBackgroundControl () : null;
-}
-char findMnemonic (String string) {
- int index = 0;
- int length = string.length ();
- do {
- while (index < length && string.charAt (index) != '&') index++;
- if (++index >= length) return '\0';
- if (string.charAt (index) != '&') return string.charAt (index);
- index++;
- } while (index < length);
- return '\0';
-}
-void fixFocus (Control focusControl) {
- Shell shell = getShell ();
- Control control = this;
- while (control != shell && (control = control.parent) != null) {
- if (control.setFocus ()) return;
- }
- shell.setSavedFocus (focusControl);
-}
-int focusHandle () {
- return handle;
-}
-int fontHandle () {
- return handle;
-}
-/**
- * Forces the receiver to have the <em>keyboard focus</em>, causing
- * all keyboard events to be delivered to it.
- *
- * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setFocus
- */
-public boolean forceFocus () {
- checkWidget();
- if (display.focusEvent == SWT.FocusOut) return false;
- Decorations shell = menuShell ();
- shell.setSavedFocus (this);
- shell.bringToTop (false);
- int focusHandle = focusHandle ();
- if (handle != focusHandle) {
- int [] argList1 = {OS.XmNnumChildren, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- if (argList1 [1] > 1) {
- int [] argList = new int [] {OS.XmNtraversalOn, 0};
- OS.XtGetValues (focusHandle, argList, argList.length / 2);
- if (argList [1] == 0) {
- argList [1] = 1;
- OS.XtSetValues (focusHandle, argList, argList.length / 2);
- overrideTranslations ();
- }
- } else {
- focusHandle = handle;
- }
- }
- int [] argList = new int [] {OS.XmNtraversalOn, 0};
- OS.XtGetValues (focusHandle, argList, argList.length / 2);
- boolean force = argList [1] == 0;
- if (force) {
- state |= FOCUS_FORCED;
- argList [1] = 1;
- OS.XtSetValues (focusHandle, argList, argList.length / 2);
- overrideTranslations ();
- }
- if (XmProcessTraversal (focusHandle, OS.XmTRAVERSE_CURRENT)) return true;
- if (force) {
- state &= ~FOCUS_FORCED;
- argList [1] = 0;
- OS.XtSetValues (focusHandle, argList, argList.length / 2);
- }
- return false;
-}
-
-/**
- * Returns the accessible object for the receiver.
- * If this is the first time this object is requested,
- * then the object is created and returned.
- *
- * @return the accessible object
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Accessible#addAccessibleListener
- * @see Accessible#addAccessibleControlListener
- *
- * @since 2.0
- */
-public Accessible getAccessible () {
- checkWidget ();
- if (accessible == null) {
- accessible = Accessible.internal_new_Accessible (this);
- }
- return accessible;
-}
-
-/**
- * Returns the receiver's background color.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on some versions of Windows the background of a TabFolder,
- * is a gradient rather than a solid color.
- * </p>
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Color getBackground () {
- checkWidget();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- return Color.motif_new (display, getXColor (control.getBackgroundPixel ()));
-}
-/**
- * Returns the receiver's background image.
- *
- * @return the background image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Image getBackgroundImage () {
- checkWidget ();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- return control.backgroundImage;
-}
-int getBackgroundPixel () {
- int [] argList = {OS.XmNbackground, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the receiver's border width.
- *
- * @return the border width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getBorderWidth () {
- checkWidget();
- int borderHandle = borderHandle ();
- int [] argList = {OS.XmNborderWidth, 0};
- OS.XtGetValues (borderHandle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null),
- * unless the receiver is a shell. In this case, the location is
- * relative to the display.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- int topHandle = topHandle ();
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (topHandle, argList, argList.length / 2);
- int borders = argList [9] * 2;
- return new Rectangle ((short) argList [1], (short) argList [3], argList [5] + borders, argList [7] + borders);
-}
-Point getClientLocation () {
- short [] handle_x = new short [1], handle_y = new short [1];
- OS.XtTranslateCoords (handle, (short) 0, (short) 0, handle_x, handle_y);
- short [] topHandle_x = new short [1], topHandle_y = new short [1];
- OS.XtTranslateCoords (parent.handle, (short) 0, (short) 0, topHandle_x, topHandle_y);
- return new Point (handle_x [0] - topHandle_x [0], handle_y [0] - topHandle_y [0]);
-}
-String getCodePage () {
- return font.codePage;
-}
-/**
- * Returns the receiver's cursor, or null if it has not been set.
- * <p>
- * When the mouse pointer passes over a control its appearance
- * is changed to match the control's cursor.
- * </p>
- *
- * @return the receiver's cursor or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Cursor getCursor () {
- checkWidget ();
- return cursor;
-}
-/**
- * Returns <code>true</code> if the receiver is detecting
- * drag gestures, and <code>false</code> otherwise.
- *
- * @return the receiver's drag detect state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public boolean getDragDetect () {
- checkWidget ();
- return (state & DRAG_DETECT) != 0;
-}
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- int [] argList = {OS.XmNsensitive, 0};
- OS.XtGetValues (topHandle (), argList, argList.length / 2);
- return argList [1] != 0;
-}
-/**
- * Returns the font that the receiver will use to paint textual information.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Font getFont () {
- checkWidget();
- return font;
-}
-
-int getFontAscent (int font) {
-
- /* Create a font context to iterate over each element in the font list */
- int [] buffer = new int [1];
- if (!OS.XmFontListInitFontContext (buffer, font)) {
- error (SWT.ERROR_NO_HANDLES);
- }
- int context = buffer [0];
-
- /* Values discovering during iteration */
- int ascent = 0;
- XFontStruct fontStruct = new XFontStruct ();
- int fontListEntry;
- int [] fontStructPtr = new int [1];
- int [] fontNamePtr = new int [1];
-
- /* Go through each entry in the font list. */
- while ((fontListEntry = OS.XmFontListNextEntry (context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer);
- if (buffer [0] == 0) {
- /* FontList contains a single font */
- OS.memmove (fontStruct, fontPtr, XFontStruct.sizeof);
- if (fontStruct.ascent > ascent) ascent = fontStruct.ascent;
- } else {
- /* FontList contains a fontSet */
- int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr);
- int [] fontStructs = new int [nFonts];
- OS.memmove (fontStructs, fontStructPtr [0], nFonts * 4);
-
- /* Go through each fontStruct in the font set */
- for (int i=0; i<nFonts; i++) {
- OS.memmove (fontStruct, fontStructs[i], XFontStruct.sizeof);
- if (fontStruct.ascent > ascent) ascent = fontStruct.ascent;
- }
- }
- }
-
- OS.XmFontListFreeFontContext (context);
- return ascent;
-}
-
-int getFontHeight (int font) {
-
- /* Create a font context to iterate over each element in the font list */
- int [] buffer = new int [1];
- if (!OS.XmFontListInitFontContext (buffer, font)) {
- error (SWT.ERROR_NO_HANDLES);
- }
- int context = buffer [0];
-
- /* Values discovering during iteration */
- int height = 0;
- XFontStruct fontStruct = new XFontStruct ();
- int fontListEntry;
- int [] fontStructPtr = new int [1];
- int [] fontNamePtr = new int [1];
-
- /* Go through each entry in the font list. */
- while ((fontListEntry = OS.XmFontListNextEntry (context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer);
- if (buffer [0] == 0) {
- /* FontList contains a single font */
- OS.memmove (fontStruct, fontPtr, XFontStruct.sizeof);
- int fontHeight = fontStruct.ascent + fontStruct.descent;
- if (fontHeight > height) height = fontHeight;
- } else {
- /* FontList contains a fontSet */
- int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr);
- int [] fontStructs = new int [nFonts];
- OS.memmove (fontStructs, fontStructPtr [0], nFonts * 4);
-
- /* Go through each fontStruct in the font set */
- for (int i=0; i<nFonts; i++) {
- OS.memmove (fontStruct, fontStructs[i], XFontStruct.sizeof);
- int fontHeight = fontStruct.ascent + fontStruct.descent;
- if (fontHeight > height) height = fontHeight;
- }
- }
- }
-
- OS.XmFontListFreeFontContext (context);
- return height;
-}
-//int getFontList () {
-// int fontHandle = fontHandle ();
-// int [] argList = {OS.XmNfontList, 0};
-// OS.XtGetValues (fontHandle, argList, argList.length / 2);
-// if (argList [1] != 0) return argList [1];
-// if (fontList == 0) fontList = defaultFont ();
-// return fontList;
-//}
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Color getForeground () {
- checkWidget();
- return Color.motif_new (display, getXColor (getForegroundPixel ()));
-}
-int getForegroundPixel () {
- int [] argList = {OS.XmNforeground, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-Caret getIMCaret () {
- return null;
-}
-/**
- * Returns layout data which is associated with the receiver.
- *
- * @return the receiver's layout data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Object getLayoutData () {
- checkWidget();
- return layoutData;
-}
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @return the receiver's location
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getLocation () {
- checkWidget();
- int topHandle = topHandle ();
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0};
- OS.XtGetValues (topHandle, argList, argList.length / 2);
- return new Point ((short) argList [1], (short) argList [3]);
-}
-/**
- * Returns the receiver's pop up menu if it has one, or null
- * if it does not. All controls may optionally have a pop up
- * menu that is displayed when the user requests one for
- * the control. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pop up
- * menu is platform specific.
- *
- * @return the receiver's menu
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenu () {
- checkWidget();
- return menu;
-}
-int getMinimumHeight () {
- return 0;
-}
-/**
- * Returns the receiver's monitor.
- *
- * @return the receiver's monitor
- *
- * @since 3.0
- */
-public Monitor getMonitor () {
- checkWidget();
- Monitor [] monitors = display.getMonitors ();
- if (monitors.length == 1) return monitors [0];
- int index = -1, value = -1;
- Rectangle bounds = getBounds ();
- if (this != getShell ()) {
- bounds = display.map (this.parent, null, bounds);
- }
- for (int i=0; i<monitors.length; i++) {
- Rectangle rect = bounds.intersection (monitors [i].getBounds ());
- int area = rect.width * rect.height;
- if (area > 0 && area > value) {
- index = i;
- value = area;
- }
- }
- if (index >= 0) return monitors [index];
- int centerX = bounds.x + bounds.width / 2, centerY = bounds.y + bounds.height / 2;
- for (int i=0; i<monitors.length; i++) {
- Rectangle rect = monitors [i].getBounds ();
- int x = centerX < rect.x ? rect.x - centerX : centerX > rect.x + rect.width ? centerX - rect.x - rect.width : 0;
- int y = centerY < rect.y ? rect.y - centerY : centerY > rect.y + rect.height ? centerY - rect.y - rect.height : 0;
- int distance = x * x + y * y;
- if (index == -1 || distance < value) {
- index = i;
- value = distance;
- }
- }
- return monitors [index];
-}
-int getNavigationType () {
- int [] argList = {OS.XmNnavigationType, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the receiver's parent, which must be a <code>Composite</code>
- * or null when the receiver is a shell that was created with null or
- * a display for a parent.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Composite getParent () {
- checkWidget();
- return parent;
-}
-Control [] getPath () {
- int count = 0;
- Shell shell = getShell ();
- Control control = this;
- while (control != shell) {
- count++;
- control = control.parent;
- }
- control = this;
- Control [] result = new Control [count];
- while (control != shell) {
- result [--count] = control;
- control = control.parent;
- }
- return result;
-}
-/**
- * Returns the region that defines the shape of the control,
- * or null if the control has the default shape.
- *
- * @return the region that defines the shape of the shell (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public Region getRegion () {
- checkWidget ();
- return region;
-}
-/**
- * Returns the receiver's shell. For all controls other than
- * shells, this simply returns the control's nearest ancestor
- * shell. Shells return themselves, even if they are children
- * of other shells.
- *
- * @return the receiver's shell
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getParent
- */
-public Shell getShell () {
- checkWidget();
- return parent.getShell ();
-}
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- int topHandle = topHandle ();
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (topHandle, argList, argList.length / 2);
- int borders = argList [5] * 2;
- return new Point (argList [1] + borders, argList [3] + borders);
-}
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- int topHandle = topHandle ();
- int [] argList = {OS.XmNmappedWhenManaged, 0};
- OS.XtGetValues (topHandle, argList, argList.length / 2);
- return argList [1] != 0;
-}
-XColor getXColor (int pixel) {
- int display = OS.XtDisplay (handle);
- if (display == 0) return null;
- int [] argList = {OS.XmNcolormap, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int colormap = argList [1];
- if (colormap == 0) return null;
- XColor color = new XColor ();
- color.pixel = pixel;
- OS.XQueryColor (display, colormap, color);
- return color;
-}
-boolean hasFocus () {
- return this == display.getFocusControl ();
-}
-/**
- * Returns true if the widget has native IM support
- */
-boolean hasIMSupport() {
- return false;
-}
-void hookEvents () {
- int windowProc = display.windowProc;
- OS.XtAddEventHandler (handle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS);
- OS.XtAddEventHandler (handle, OS.ButtonReleaseMask, false, windowProc, BUTTON_RELEASE);
- OS.XtAddEventHandler (handle, OS.PointerMotionMask, false, windowProc, POINTER_MOTION);
- OS.XtAddEventHandler (handle, OS.EnterWindowMask, false, windowProc, ENTER_WINDOW);
- OS.XtAddEventHandler (handle, OS.LeaveWindowMask, false, windowProc, LEAVE_WINDOW);
- OS.XtInsertEventHandler (handle, OS.ExposureMask, false, windowProc, EXPOSURE, OS.XtListTail);
- OS.XtAddCallback (handle, OS.XmNhelpCallback, windowProc, HELP_CALLBACK);
- OS.XtAddEventHandler (handle, OS.KeyPressMask, false, windowProc, KEY_PRESS);
- OS.XtAddEventHandler (handle, OS.KeyReleaseMask, false, windowProc, KEY_RELEASE);
- OS.XtInsertEventHandler (handle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail);
- int focusHandle = focusHandle ();
- if (handle != focusHandle) {
- OS.XtAddEventHandler (focusHandle, OS.KeyPressMask, false, windowProc, KEY_PRESS);
- OS.XtAddEventHandler (focusHandle, OS.KeyReleaseMask, false, windowProc, KEY_RELEASE);
- OS.XtInsertEventHandler (focusHandle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail);
- }
-}
-int hoverProc (int id) {
- return hoverProc (id, true);
-}
-int hoverProc (int id, boolean showTip) {
- if (showTip) display.showToolTip (handle, toolTipText);
- sendMouseEvent (SWT.MouseHover);
- return 0;
-}
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Control</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public int internal_new_GC (GCData data) {
- checkWidget();
- if (!OS.XtIsRealized (handle)) {
- Shell shell = getShell ();
- shell.realizeWidget ();
- }
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int xGC = OS.XCreateGC (xDisplay, xWindow, 0, null);
- if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.XSetGraphicsExposures (xDisplay, xGC, false);
- if (data != null) {
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) == 0) {
- data.style |= style & (mask | SWT.MIRRORED);
- }
- data.device = display;
- data.display = xDisplay;
- data.drawable = xWindow;
- XColor foreground = new XColor ();
- foreground.pixel = getForegroundPixel ();
- data.foreground = foreground;
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- XColor background = new XColor ();
- background.pixel = control.getBackgroundPixel ();
- data.background = background;
- data.backgroundImage = control.backgroundImage;
- data.font = font;
- int [] argList = {OS.XmNcolormap, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- data.colormap = argList [1];
- }
- return xGC;
-}
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Control</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int xGC, GCData data) {
- checkWidget ();
- int xDisplay = 0;
- if (data != null) xDisplay = data.display;
- if (xDisplay == 0 && handle != 0) xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.XFreeGC (xDisplay, xGC);
-}
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * ancestors up to and including the receiver's nearest ancestor
- * shell are enabled. Otherwise, <code>false</code> is returned.
- * A disabled control is typically not selectable from the user
- * interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-boolean isFocusAncestor (Control control) {
- while (control != null && control != this && !(control instanceof Shell)) {
- control = control.parent;
- }
- return control == this;
-}
-/**
- * Returns <code>true</code> if the receiver has the user-interface
- * focus, and <code>false</code> otherwise.
- *
- * @return the receiver's focus state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isFocusControl () {
- checkWidget();
- return hasFocus ();
-}
-/**
- * Returns <code>true</code> if the underlying operating
- * system supports this reparenting, otherwise <code>false</code>
- *
- * @return <code>true</code> if the widget can be reparented, otherwise <code>false</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isReparentable () {
- checkWidget();
- return false;
-}
-boolean isShowing () {
- /*
- * This is not complete. Need to check if the
- * widget is obscurred by a parent or sibling.
- */
- if (!isVisible ()) return false;
- Control control = this;
- while (control != null) {
- Point size = control.getSize ();
- if (size.x == 1 || size.y == 1) {
- return false;
- }
- control = control.parent;
- }
- return true;
-}
-boolean isTabGroup () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == this) return true;
- }
- }
- int code = traversalCode (0, null);
- if ((code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) != 0) return false;
- return (code & (SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_TAB_NEXT)) != 0;
-}
-boolean isTabItem () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == this) return false;
- }
- }
- int code = traversalCode (0, null);
- return (code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) != 0;
-}
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * ancestors up to and including the receiver's nearest ancestor
- * shell are visible. Otherwise, <code>false</code> is returned.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return getVisible () && parent.isVisible ();
-}
-void manageChildren () {
- OS.XtSetMappedWhenManaged (handle, false);
- OS.XtManageChild (handle);
- int [] argList3 = {OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList3, argList3.length / 2);
- OS.XtResizeWidget (handle, 1, 1, argList3 [1]);
- OS.XtSetMappedWhenManaged (handle, true);
-}
-void markLayout (boolean changed, boolean all) {
- /* Do nothing */
-}
-Decorations menuShell () {
- return parent.menuShell ();
-}
-boolean mnemonicHit (char key) {
- return false;
-}
-boolean mnemonicMatch (char key) {
- return false;
-}
-/**
- * Moves the receiver above the specified control in the
- * drawing order. If the argument is null, then the receiver
- * is moved to the top of the drawing order. The control at
- * the top of the drawing order will not be covered by other
- * controls even if they occupy intersecting areas.
- *
- * @param control the sibling control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveBelow
- * @see Composite#getChildren
- */
-public void moveAbove (Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- }
- setZOrder (control, true);
-}
-/**
- * Moves the receiver below the specified control in the
- * drawing order. If the argument is null, then the receiver
- * is moved to the bottom of the drawing order. The control at
- * the bottom of the drawing order will be covered by all other
- * controls which occupy intersecting areas.
- *
- * @param control the sibling control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveAbove
- * @see Composite#getChildren
- */
-public void moveBelow (Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- }
- setZOrder (control, false);
-}
-void overrideTranslations () {
- OS.XtOverrideTranslations (handle, display.tabTranslations);
- OS.XtOverrideTranslations (handle, display.arrowTranslations);
- int focusHandle = focusHandle ();
- if (handle != focusHandle) {
- OS.XtOverrideTranslations (focusHandle, display.tabTranslations);
- OS.XtOverrideTranslations (focusHandle, display.arrowTranslations);
- }
-}
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeSize(int, int, boolean)
- */
-public void pack () {
- checkWidget();
- pack (true);
-}
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- * <p>
- * If the changed flag is <code>true</code>, it indicates that the receiver's
- * <em>contents</em> have changed, therefore any caches that a layout manager
- * containing the control may have been keeping need to be flushed. When the
- * control is resized, the changed flag will be <code>false</code>, so layout
- * manager caches can be retained.
- * </p>
- *
- * @param changed whether or not the receiver's contents have changed
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeSize(int, int, boolean)
- */
-public void pack (boolean changed) {
- checkWidget();
- setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed));
-}
-void propagateChildren (boolean enabled) {
- propagateWidget (enabled);
-}
-void propagateWidget (boolean enabled) {
- int xCursor = enabled && cursor != null ? cursor.handle : OS.None;
- propagateHandle (enabled, handle, xCursor);
-}
-/**
- * Prints the receiver and all children.
- *
- * @param gc the gc where the drawing occurs
- * @return <code>true</code> if the operation was successful and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean print (GC gc) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- return false;
-}
-void realizeChildren () {
- if (isEnabled ()) {
- if (cursor != null) {
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- OS.XDefineCursor (xDisplay, xWindow, cursor.handle);
- OS.XFlush (xDisplay);
- }
- } else {
- propagateWidget (false);
- }
- if ((state & PARENT_BACKGROUND) != 0) {
- setParentBackground ();
- }
-}
-/**
- * Causes the entire bounds of the receiver to be marked
- * as needing to be redrawn. The next time a paint request
- * is processed, the control will be completely painted,
- * including the background.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #update()
- * @see PaintListener
- * @see SWT#Paint
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#DOUBLE_BUFFERED
- */
-public void redraw () {
- checkWidget();
- redrawWidget (0, 0, 0, 0, true, false, false);
-}
-/**
- * Causes the rectangular area of the receiver specified by
- * the arguments to be marked as needing to be redrawn.
- * The next time a paint request is processed, that area of
- * the receiver will be painted, including the background.
- * If the <code>all</code> flag is <code>true</code>, any
- * children of the receiver which intersect with the specified
- * area will also paint their intersecting areas. If the
- * <code>all</code> flag is <code>false</code>, the children
- * will not be painted.
- *
- * @param x the x coordinate of the area to draw
- * @param y the y coordinate of the area to draw
- * @param width the width of the area to draw
- * @param height the height of the area to draw
- * @param all <code>true</code> if children should redraw, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #update()
- * @see PaintListener
- * @see SWT#Paint
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#DOUBLE_BUFFERED
- */
-public void redraw (int x, int y, int width, int height, boolean all) {
- checkWidget ();
- if (width > 0 && height > 0) {
- redrawWidget (x, y, width, height, false, all, false);
- }
-}
-void redrawChildren () {
-}
-void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean allChildren, boolean trim) {
- redrawHandle (x, y, width, height, redrawAll, handle);
-}
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
-}
-void releaseParent () {
- parent.removeControl (this);
-}
-void releaseWidget () {
- super.releaseWidget ();
- /*
- * Restore the default font for the widget in case the
- * application disposes the widget font in the dispose
- * callback. If a font is disposed while it is still
- * in use in the widget, Motif GP's.
- */
- int fontList = defaultFont ().handle;
- if (font.handle != fontList) {
- int fontHandle = fontHandle ();
- int [] argList2 = {OS.XmNfontList, fontList};
- OS.XtSetValues (fontHandle, argList2, argList2.length / 2);
- OS.XmImSetValues (fontHandle, argList2, argList2.length / 2);
- }
- display.releaseToolTipHandle (handle);
- toolTipText = null;
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- menu = null;
- cursor = null;
- if (!hasIMSupport()) {
- OS.XmImUnregister (handle);
- int focusHandle = focusHandle ();
- if (handle != focusHandle) {
- OS.XmImUnregister (focusHandle);
- }
- }
- layoutData = null;
- region = null;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when a drag gesture occurs.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @since 3.3
- */
-public void removeDragDetectListener(DragDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.DragDetect, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control gains or loses focus.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see FocusListener
- * @see #addFocusListener
- */
-public void removeFocusListener(FocusListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.FocusIn, listener);
- eventTable.unhook(SWT.FocusOut, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #addKeyListener
- */
-public void removeKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.KeyUp, listener);
- eventTable.unhook(SWT.KeyDown, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the platform-specific context menu trigger has
- * occurred.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #addMenuDetectListener
- *
- * @since 3.3
- */
-public void removeMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MenuDetect, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when mouse buttons are pressed and released.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseListener
- * @see #addMouseListener
- */
-public void removeMouseListener(MouseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.MouseDown, listener);
- eventTable.unhook(SWT.MouseUp, listener);
- eventTable.unhook(SWT.MouseDoubleClick, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse moves.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseMoveListener
- * @see #addMouseMoveListener
- */
-public void removeMouseMoveListener(MouseMoveListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.MouseMove, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse passes or hovers over controls.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseTrackListener
- * @see #addMouseTrackListener
- */
-public void removeMouseTrackListener(MouseTrackListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseEnter, listener);
- eventTable.unhook (SWT.MouseExit, listener);
- eventTable.unhook (SWT.MouseHover, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse wheel is scrolled.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseWheelListener
- * @see #addMouseWheelListener
- *
- * @since 3.3
- */
-public void removeMouseWheelListener (MouseWheelListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseWheel, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver needs to be painted.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see PaintListener
- * @see #addPaintListener
- */
-public void removePaintListener(PaintListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Paint, listener);
-}/**
- * Removes the listener from the collection of listeners who will
- * be notified when traversal events occur.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TraverseListener
- * @see #addTraverseListener
- */
-public void removeTraverseListener(TraverseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Traverse, listener);
-}
-boolean sendDragEvent (int button, int stateMask, int x, int y, boolean isStateMask) {
- Event event = new Event ();
- event.button = button;
- event.x = x;
- event.y = y;
- if (isStateMask) {
- event.stateMask = stateMask;
- } else {
- setInputState (event, stateMask);
- }
- postEvent (SWT.DragDetect, event);
- if (isDisposed ()) return false;
- return event.doit;
-}
-void sendFocusEvent (int type) {
- Display display = this.display;
- if (type == SWT.FocusIn) {
- Control focusedCombo = display.focusedCombo;
- display.focusedCombo = null;
- if (focusedCombo != null && focusedCombo != this && !focusedCombo.isDisposed ()) {
- display.sendFocusEvent (focusedCombo, SWT.FocusOut);
- }
- }
- display.sendFocusEvent (this, type);
-}
-void sendHelpEvent (int callData) {
- Control control = this;
- while (control != null) {
- if (control.hooks (SWT.Help)) {
- control.postEvent (SWT.Help);
- return;
- }
- control = control.parent;
- }
-}
-boolean sendMouseEvent (int type) {
- if (!hooks (type) && !filters (type)) return true;
- int xDisplay = OS.XtDisplay (handle), xWindow = OS.XtWindow (handle);
- int [] windowX = new int [1], windowY = new int [1], mask = new int [1], unused = new int [1];
- OS.XQueryPointer (xDisplay, xWindow, unused, unused, unused, unused, windowX, windowY, mask);
- return sendMouseEvent (type, 0, 0, 0, false, 0, windowX [0], windowY [0], mask [0]);
-}
-boolean sendMouseEvent (int type, int button, int count, int detail, boolean send, int time, int x, int y, int state) {
-// if (!hooks (type) && !filters (type)) return true;
- Event event = new Event ();
- event.time = time;
- event.button = button;
- event.count = count;
- event.detail = detail;
- event.x = x;
- event.y = y;
- setInputState (event, state);
- if (send) {
- sendEvent (type, event);
- if (isDisposed ()) return false;
- } else {
- postEvent (type, event);
- }
- return event.doit;
-}
-boolean sendMouseEvent (int type, XButtonEvent xEvent) {
- int button = xEvent.button;
- switch (button) {
- case 4:
- case 5:
- /* Use MouseDown button 4 and 5 to emulated MouseWheel */
- if (type != SWT.MouseDown) return true;
- type = SWT.MouseWheel;
- if (!hooks (type) && !filters (type)) return true;
- short [] x_root = new short [1], y_root = new short [1];
- OS.XtTranslateCoords (handle, (short) 0, (short) 0, x_root, y_root);
- int x = xEvent.x_root - x_root [0], y = xEvent.y_root - y_root [0];
- int count = button == 4 ? 3 : -3;
- Control control = this;
- Shell shell = getShell ();
- do {
- if (!control.sendMouseEvent (type, 0, count, SWT.SCROLL_LINE, true, xEvent.time, x, y, xEvent.state)) {
- return false;
- }
- if (control == shell) break;
- control = control.parent;
- OS.XtTranslateCoords (control.handle, (short) 0, (short) 0, x_root, y_root);
- x = xEvent.x_root - x_root [0];
- y = xEvent.y_root - y_root [0];
- } while (control != null);
- return true;
- case 6:
- button = 4;
- break;
- case 7:
- button = 5;
- break;
- }
- if (!hooks (type) && !filters (type)) return true;
- short [] x_root = new short [1], y_root = new short [1];
- OS.XtTranslateCoords (handle, (short) 0, (short) 0, x_root, y_root);
- int x = xEvent.x_root - x_root [0], y = xEvent.y_root - y_root [0];
- return sendMouseEvent (type, button, display.clickCount, 0, false, xEvent.time, x, y, xEvent.state);
-}
-boolean sendMouseEvent (int type, XCrossingEvent xEvent) {
- if (!hooks (type) && !filters (type)) return true;
- short [] x_root = new short [1], y_root = new short [1];
- OS.XtTranslateCoords (handle, (short) 0, (short) 0, x_root, y_root);
- int x = xEvent.x_root - x_root [0], y = xEvent.y_root - y_root [0];
- return sendMouseEvent (type, 0, 0, 0, false, xEvent.time, x, y, xEvent.state);
-}
-boolean sendMouseEvent (int type, XMotionEvent xEvent) {
- if (!hooks (type) && !filters (type)) return true;
- short [] x_root = new short [1], y_root = new short [1];
- OS.XtTranslateCoords (handle, (short) 0, (short) 0, x_root, y_root);
- int x = xEvent.x_root - x_root [0], y = xEvent.y_root - y_root [0];
- return sendMouseEvent (type, 0, 0, 0, false, xEvent.time, x, y, xEvent.state);
-}
-void setBackground () {
- if ((state & PARENT_BACKGROUND) != 0 && (state & BACKGROUND) == 0 && backgroundImage == null) {
- setParentBackground ();
- } else {
- if (backgroundImage != null) {
- int [] argList = {OS.XmNbackgroundPixmap, backgroundImage.pixmap};
- OS.XtSetValues (handle, argList, argList.length / 2);
- } else {
- /* Ensure the resource value changes, otherwise XtSetValues() does nothing */
- int pixel = getBackgroundPixel ();
- setBackgroundPixel (pixel + 1);
- setBackgroundPixel (pixel);
- }
- }
- redrawWidget (0, 0, 0, 0, true, false, false);
-}
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the control
- * if the argument is null.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on Windows the background of a Button cannot be changed.
- * </p>
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBackground (Color color) {
- checkWidget();
- if (color == null) {
- state &= ~BACKGROUND;
- setBackgroundPixel (defaultBackground ());
- } else {
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- state |= BACKGROUND;
- setBackgroundPixel (color.handle.pixel);
- }
- if ((state & PARENT_BACKGROUND) != 0 && (state & BACKGROUND) == 0 && backgroundImage == null) {
- setParentBackground ();
- redrawWidget (0, 0, 0, 0, true, false, false);
- }
- redrawChildren ();
-}
-/**
- * Sets the receiver's background image to the image specified
- * by the argument, or to the default system color for the control
- * if the argument is null. The background image is tiled to fill
- * the available space.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on Windows the background of a Button cannot be changed.
- * </p>
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument is not a bitmap</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setBackgroundImage (Image image) {
- checkWidget ();
- if (image != null && image.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (image == backgroundImage) return;
- this.backgroundImage = image;
- int pixmap = image != null ? image.pixmap : OS.XmUNSPECIFIED_PIXMAP;
- int [] argList = {OS.XmNbackgroundPixmap, pixmap};
- OS.XtSetValues (handle, argList, argList.length / 2);
- if ((state & PARENT_BACKGROUND) != 0 && (state & BACKGROUND) == 0 && backgroundImage == null) {
- setParentBackground ();
- redrawWidget (0, 0, 0, 0, true, false, false);
- }
- redrawChildren ();
-}
-void setBackgroundPixel (int pixel) {
- int [] argList = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmChangeColor (handle, pixel);
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- int topHandle = topHandle ();
- if (move && resize) {
- int [] argList = {
- OS.XmNx, 0, /* 1 */
- OS.XmNy, 0, /* 3 */
- OS.XmNwidth, 0, /* 5 */
- OS.XmNheight, 0, /* 7 */
- OS.XmNborderWidth, 0, /* 9 */
- };
- OS.XtGetValues (topHandle, argList, argList.length / 2);
- /*
- * Feature in Motif. Motif will not allow a window
- * to have a zero width or zero height. The fix is
- * to ensure these values are never zero.
- */
- width = Math.max (width - (argList [9] * 2), 1);
- height = Math.max (height - (argList [9] * 2), 1);
- boolean sameOrigin = (x == (short) argList [1]) && (y == (short) argList [3]);
- boolean sameExtent = (width == argList [5]) && (height == argList [7]);
- if (sameOrigin && sameExtent) return false;
- if (redrawWindow != 0) {
- int xDisplay = OS.XtDisplay (handle);
- OS.XResizeWindow (xDisplay, redrawWindow, width, height);
- }
- OS.XtConfigureWidget (topHandle, x, y, width, height, argList [9]);
- updateIM ();
- if (!sameOrigin) {
- Control control = findBackgroundControl ();
- if (control != null && control.backgroundImage != null) {
- if (isVisible ()) redrawWidget (0, 0, 0, 0, true, true, true);
- }
- sendEvent (SWT.Move);
- }
- if (!sameExtent) sendEvent (SWT.Resize);
- return true;
- }
- if (move) {
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0};
- OS.XtGetValues (topHandle, argList, argList.length / 2);
- if (x == (short) argList [1] && y == (short) argList [3]) return false;
- OS.XtMoveWidget (topHandle, x, y);
- Control control = findBackgroundControl ();
- if (control != null && control.backgroundImage != null) {
- if (isVisible ()) redrawWidget (0, 0, 0, 0, true, true, true);
- }
- sendEvent (SWT.Move);
- return true;
- }
- if (resize) {
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (topHandle, argList, argList.length / 2);
- /*
- * Feature in Motif. Motif will not allow a window
- * to have a zero width or zero height. The fix is
- * to ensure these values are never zero.
- */
- width = Math.max (width - (argList [5] * 2), 1);
- height = Math.max (height - (argList [5] * 2), 1);
- if (width == argList [1] && height == argList [3]) return false;
- if (redrawWindow != 0) {
- int xDisplay = OS.XtDisplay (handle);
- OS.XResizeWindow (xDisplay, redrawWindow, width, height);
- }
- OS.XtResizeWidget (topHandle, width, height, argList [5]);
- updateIM ();
- sendEvent (SWT.Resize);
- return true;
- }
- return false;
-}
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the arguments. The <code>x</code> and
- * <code>y</code> arguments are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the <code>x</code>
- * and <code>y</code> arguments are relative to the display.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (int x, int y, int width, int height) {
- checkWidget();
- setBounds (x, y, Math.max (0, width), Math.max (0, height), true, true);
-}
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the argument. The <code>x</code> and
- * <code>y</code> fields of the rectangle are relative to
- * the receiver's parent (or its display if its parent is null).
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param rect the new bounds for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (Rectangle rect) {
- checkWidget ();
- if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (rect.x, rect.y, rect.width, rect.height);
-}
-/**
- * If the argument is <code>true</code>, causes the receiver to have
- * all mouse events delivered to it until the method is called with
- * <code>false</code> as the argument. Note that on some platforms,
- * a mouse button must currently be down for capture to be assigned.
- *
- * @param capture <code>true</code> to capture the mouse, and <code>false</code> to release it
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCapture (boolean capture) {
- checkWidget();
- int display = OS.XtDisplay (handle);
- if (display == 0) return;
- if (capture) {
- int window = OS.XtWindow (handle);
- if (window == 0) return;
- OS.XGrabPointer (
- display,
- window,
- 0,
- OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask,
- OS.GrabModeAsync,
- OS.GrabModeAsync,
- OS.None,
- OS.None,
- OS.CurrentTime);
- } else {
- OS.XUngrabPointer (display, OS.CurrentTime);
- }
-}
-/**
- * Sets the receiver's cursor to the cursor specified by the
- * argument, or to the default cursor for that kind of control
- * if the argument is null.
- * <p>
- * When the mouse pointer passes over a control its appearance
- * is changed to match the control's cursor.
- * </p>
- *
- * @param cursor the new cursor (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCursor (Cursor cursor) {
- checkWidget();
- if (cursor != null && cursor.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- this.cursor = cursor;
- if (!isEnabled ()) {
- if (this != getShell ()) return;
- }
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- if (cursor == null) {
- OS.XUndefineCursor (xDisplay, xWindow);
- } else {
- if (cursor.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.XDefineCursor (xDisplay, xWindow, cursor.handle);
- }
- OS.XFlush (xDisplay);
-}
-/**
- * Sets the receiver's drag detect state. If the argument is
- * <code>true</code>, the receiver will detect drag gestures,
- * otherwise these gestures will be ignored.
- *
- * @param dragDetect the new drag detect state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public void setDragDetect (boolean dragDetect) {
- checkWidget ();
- if (dragDetect) {
- state |= DRAG_DETECT;
- } else {
- state &= ~DRAG_DETECT;
- }
-}
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- if (enabled == getEnabled ()) return;
- Control control = null;
- boolean fixFocus = false;
- if (!enabled) {
- if (display.focusEvent != SWT.FocusOut) {
- control = display.getFocusControl ();
- fixFocus = isFocusAncestor (control);
- }
- }
- enableWidget (enabled);
- if (fixFocus) fixFocus (control);
- if (!enabled || (isEnabled () && enabled)) {
- propagateChildren (enabled);
- }
-}
-/**
- * Causes the receiver to have the <em>keyboard focus</em>,
- * such that all keyboard events will be delivered to it. Focus
- * reassignment will respect applicable platform constraints.
- *
- * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #forceFocus
- */
-public boolean setFocus () {
- checkWidget();
- if ((style & SWT.NO_FOCUS) != 0) return false;
- return forceFocus ();
-}
-/**
- * Sets the font that the receiver will use to paint textual information
- * to the font specified by the argument, or to the default font for that
- * kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkWidget();
- if (font == null) font = defaultFont ();
- if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.font = font;
-
- /*
- * Feature in Motif. Setting the font in a widget
- * can cause the widget to automatically resize in
- * the OS. This behavior is unwanted. The fix is
- * to force the widget to resize to original size
- * after every font change.
- */
- int [] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
-
- /* Set the font list */
- int fontHandle = fontHandle ();
- int [] argList2 = {OS.XmNfontList, font.handle};
- OS.XtSetValues (fontHandle, argList2, argList2.length / 2);
- updateIM ();
-
- /*
- * Feature in Motif. When XtSetValues() is used to restore the width and
- * height of the widget, the new width and height are sometimes ignored.
- * The fix is to use XtResizeWidget().
- */
- OS.XtResizeWidget (handle, argList1 [1], argList1 [3], argList1 [5]);
-}
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the control
- * if the argument is null.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * </p>
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setForeground (Color color) {
- checkWidget();
- if (color == null) {
- state &= ~FOREGROUND;
- setForegroundPixel (defaultForeground ());
- } else {
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- state |= FOREGROUND;
- setForegroundPixel (color.handle.pixel);
- }
-}
-void setForegroundPixel (int pixel) {
- int [] argList = {OS.XmNforeground, pixel};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * Sets the layout data associated with the receiver to the argument.
- *
- * @param layoutData the new layout data for the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLayoutData (Object layoutData) {
- checkWidget();
- this.layoutData = layoutData;
-}
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget();
- setBounds (x, y, 0, 0, true, false);
-}
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @param location the new location for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (Point location) {
- checkWidget ();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (location.x, location.y, 0, 0, true, false);
-}
-/**
- * Sets the receiver's pop up menu to the argument.
- * All controls may optionally have a pop up
- * menu that is displayed when the user requests one for
- * the control. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pop up
- * menu is platform specific.
- * <p>
- * Note: Disposing of a control that has a pop up menu will
- * dispose of the menu. To avoid this behavior, set the
- * menu to null before the control is disposed.
- * </p>
- *
- * @param menu the new pop up menu
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenu (Menu menu) {
- checkWidget();
- if (menu != null) {
- if (menu.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.POP_UP) == 0) {
- error (SWT.ERROR_MENU_NOT_POP_UP);
- }
- if (menu.parent != menuShell ()) {
- error (SWT.ERROR_INVALID_PARENT);
- }
- }
- this.menu = menu;
-}
-/**
- * Changes the parent of the widget to be the one provided if
- * the underlying operating system supports this feature.
- * Returns <code>true</code> if the parent is successfully changed.
- *
- * @param parent the new parent for the control.
- * @return <code>true</code> if the parent is changed and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * <li>ERROR_NULL_ARGUMENT - if the parent is <code>null</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean setParent (Composite parent) {
- checkWidget();
- if (parent.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return false;
-}
-void setParentBackground () {
- setParentBackground (handle);
-}
-void setParentBackground (int widget) {
- int xDisplay = OS.XtDisplay (widget);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (widget);
- if (xWindow == 0) return;
- OS.XSetWindowBackgroundPixmap (xDisplay, xWindow, OS.ParentRelative);
-}
-void setParentTraversal () {
- /*
- * When the parent was created with NO_FOCUS, XmNtraversalOn was
- * set to false disallowing focus in the parent and all children.
- * In order to allow the new child to take focus like other platforms,
- * set XmNtraversalOn to true in the parent.
- */
- if ((parent.style & SWT.NO_FOCUS) != 0) {
- int parentHandle = parent.handle;
- int [] argList = {OS.XmNtraversalOn, 0};
- OS.XtGetValues (parentHandle, argList, argList.length / 2);
- if (argList [1] == 0) {
- argList [1] = 1;
- OS.XtSetValues (parentHandle, argList, argList.length / 2);
- parent.overrideTranslations ();
- }
- }
-}
-boolean setRadioSelection (boolean value) {
- return false;
-}
-/**
- * If the argument is <code>false</code>, causes subsequent drawing
- * operations in the receiver to be ignored. No drawing of any kind
- * can occur in the receiver until the flag is set to true.
- * Graphics operations that occurred while the flag was
- * <code>false</code> are lost. When the flag is set to <code>true</code>,
- * the entire widget is marked as needing to be redrawn. Nested calls
- * to this method are stacked.
- * <p>
- * Note: This operation is a hint and may not be supported on some
- * platforms or for some widgets.
- * </p>
- *
- * @param redraw the new redraw state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #redraw(int, int, int, int, boolean)
- * @see #update()
- */
-public void setRedraw (boolean redraw) {
- checkWidget();
- if (redraw) {
- if (--drawCount == 0) {
- if (redrawWindow != 0) {
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- OS.XDestroyWindow (xDisplay, redrawWindow);
- OS.XSelectInput (xDisplay, xWindow, OS.XtBuildEventMask (handle));
- redrawWindow = 0;
- }
- }
- } else {
- if (drawCount++ == 0) {
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- Rectangle rect = getBounds();
- XSetWindowAttributes attributes = new XSetWindowAttributes ();
- attributes.background_pixmap = OS.None;
- attributes.event_mask = OS.ExposureMask;
- int mask = OS.CWDontPropagate | OS.CWEventMask | OS.CWBackPixmap;
- redrawWindow = OS.XCreateWindow (xDisplay, xWindow, 0, 0, rect.width, rect.height,
- 0,OS.CopyFromParent, OS.CopyFromParent, OS.CopyFromParent, mask, attributes);
- if (redrawWindow != 0) {
- int mouseMask = OS.ButtonPressMask | OS.ButtonReleaseMask |
- OS.LeaveWindowMask | OS.PointerMotionMask |
- OS.PointerMotionMask | OS.PointerMotionHintMask |
- OS.ButtonMotionMask | OS.Button1MotionMask | OS.Button2MotionMask |
- OS.Button3MotionMask | OS.Button4MotionMask | OS.Button5MotionMask;
- OS.XSelectInput (xDisplay, xWindow, OS.XtBuildEventMask (handle) & ~mouseMask);
- OS.XRaiseWindow (xDisplay, redrawWindow);
- OS.XMapWindow (xDisplay, redrawWindow);
- }
- }
- }
-}
-/**
- * Sets the shape of the control to the region specified
- * by the argument. When the argument is null, the
- * default shape of the control is restored.
- *
- * @param region the region that defines the shape of the control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setRegion (Region region) {
- checkWidget ();
- if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- int topHandle = topHandle ();
- Shell shell = getShell ();
- if (!OS.XtIsRealized (topHandle)) shell.realizeWidget ();
- int xDisplay = OS.XtDisplay (topHandle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (topHandle);
- if (xWindow == 0) return;
- if (region != null) {
- OS.XShapeCombineRegion (xDisplay, xWindow, OS.ShapeBounding, 0, 0, region.handle, OS.ShapeSet);
- } else {
- OS.XShapeCombineMask (xDisplay, xWindow, OS.ShapeBounding, 0, 0, 0, OS.ShapeSet);
- }
- this.region = region;
-}
-boolean setTabGroupFocus (boolean next) {
- return setTabItemFocus (next);
-}
-boolean setTabItemFocus (boolean next) {
- if (!isShowing ()) return false;
- return forceFocus ();
-}
-/**
- * Sets the receiver's size to the point specified by the arguments.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (int width, int height) {
- checkWidget();
- setBounds (0, 0, Math.max (0, width), Math.max (0, height), false, true);
-}
-/**
- * Sets the receiver's size to the point specified by the argument.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause them to be
- * set to zero instead.
- * </p>
- *
- * @param size the new size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (Point size) {
- checkWidget();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (0, 0, size.x, size.y, false, true);
-}
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget();
- display.setToolTipText (handle, toolTipText = string);
-}
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget();
- int topHandle = topHandle ();
- int [] argList = {OS.XmNmappedWhenManaged, 0};
- OS.XtGetValues (topHandle, argList, argList.length / 2);
- if ((argList [1] != 0) == visible) return;
- Control control = null;
- boolean fixFocus = false;
- if (!visible) {
- if (display.focusEvent != SWT.FocusOut) {
- control = display.getFocusControl ();
- fixFocus = isFocusAncestor (control);
- }
- }
- OS.XtSetMappedWhenManaged (topHandle, visible);
- if (fixFocus) fixFocus (control);
- /*
- * It is possible (but unlikely) that application code could
- * have disposed the widget in the FocusOut event that is
- * triggered by invoking fixFocus() if the widget being hidden
- * has focus. If this happens, just return;
- */
- if (isDisposed ()) return;
- sendEvent (visible ? SWT.Show : SWT.Hide);
-}
-void setZOrder (Control control, boolean above) {
- setZOrder (control, above, true);
-}
-void setZOrder (Control control, boolean above, boolean fixChildren) {
- /*
- * Feature in Xt. We cannot use XtMakeGeometryRequest() to
- * restack widgets because this call can fail under certain
- * conditions. For example, XtMakeGeometryRequest() answers
- * XtGeometryNo when attempting to bring a child widget that
- * is larger than the parent widget to the front. The fix
- * is to use X calls instead.
- */
- int topHandle1 = topHandle ();
- int display = OS.XtDisplay (topHandle1);
- if (display == 0) return;
- if (!OS.XtIsRealized (topHandle1)) {
- Shell shell = this.getShell ();
- shell.realizeWidget ();
- }
- int window1 = OS.XtWindow (topHandle1);
- if (window1 == 0) return;
- int redrawWindow = fixChildren ? parent.redrawWindow : 0;
- if (control == null && (!above || redrawWindow == 0)) {
- if (above) {
- OS.XRaiseWindow (display, window1);
- if (fixChildren) parent.moveAbove (topHandle1, 0);
- } else {
- OS.XLowerWindow (display, window1);
- if (fixChildren) parent.moveBelow (topHandle1, 0);
- }
- return;
- }
- int window2, topHandle2 = 0;
- if (control != null) {
- topHandle2 = control.topHandle ();
- if (display != OS.XtDisplay (topHandle2)) return;
- if (!OS.XtIsRealized (topHandle2)) {
- Shell shell = control.getShell ();
- shell.realizeWidget ();
- }
- window2 = OS.XtWindow (topHandle2);
- } else {
- window2 = redrawWindow;
- }
- if (window2 == 0) return;
- XWindowChanges struct = new XWindowChanges ();
- struct.sibling = window2;
- struct.stack_mode = above ? OS.Above : OS.Below;
- if (window2 == redrawWindow) struct.stack_mode = OS.Below;
- /*
- * Feature in X. If the receiver is a top level, XConfigureWindow ()
- * will fail (with a BadMatch error) for top level shells because top
- * level shells are reparented by the window manager and do not share
- * the same X window parent. This is the correct behavior but it is
- * unexpected. The fix is to use XReconfigureWMWindow () instead.
- * When the receiver is not a top level shell, XReconfigureWMWindow ()
- * behaves the same as XConfigureWindow ().
- */
- int screen = OS.XDefaultScreen (display);
- int flags = OS.CWStackMode | OS.CWSibling;
- OS.XReconfigureWMWindow (display, window1, screen, flags, struct);
- if (above) {
- if (fixChildren) parent.moveAbove (topHandle1, topHandle2);
- } else {
- if (fixChildren) parent.moveBelow (topHandle1, topHandle2);
- }
-}
-void showMenu (int x, int y) {
- Event event = new Event ();
- event.x = x;
- event.y = y;
- sendEvent (SWT.MenuDetect, event);
- if (event.doit) {
- if (menu != null && !menu.isDisposed ()) {
- if (event.x != x || event.y != y) {
- menu.setLocation (event.x, event.y);
- }
- menu.setVisible (true);
- }
- }
-}
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in display relative coordinates,
- * to coordinates relative to the receiver.
- * <p>
- * @param x the x coordinate to be translated
- * @param y the y coordinate to be translated
- * @return the translated coordinates
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public Point toControl (int x, int y) {
- checkWidget();
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (handle, (short) 0, (short) 0, root_x, root_y);
- return new Point (x - root_x [0], y - root_y [0]);
-}
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in display relative coordinates,
- * to coordinates relative to the receiver.
- * <p>
- * @param point the point to be translated (must not be null)
- * @return the translated coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point toControl (Point point) {
- checkWidget();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return toControl (point.x, point.y);
-}
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in coordinates relative to
- * the receiver, to display relative coordinates.
- * <p>
- * @param x the x coordinate to be translated
- * @param y the y coordinate to be translated
- * @return the translated coordinates
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public Point toDisplay (int x, int y) {
- checkWidget();
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (handle, (short) x, (short) y, root_x, root_y);
- return new Point (root_x [0], root_y [0]);
-}
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in coordinates relative to
- * the receiver, to display relative coordinates.
- * <p>
- * @param point the point to be translated (must not be null)
- * @return the translated coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point toDisplay (Point point) {
- checkWidget();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return toDisplay (point.x, point.y);
-}
-boolean translateAccelerator (char key, int keysym, XKeyEvent xEvent, boolean doit) {
- return menuShell ().translateAccelerator (key, keysym, xEvent, doit);
-}
-boolean translateMnemonic (Event event, Control control) {
- if (control == this) return false;
- if (!isVisible () || !isEnabled ()) return false;
- event.doit = mnemonicMatch (event.character);
- return traverse (event);
-}
-boolean translateMnemonic (char key, int keysym, XKeyEvent xEvent) {
- if (key < 0x20) return false;
- if (xEvent.state == 0) {
- int code = traversalCode (key, xEvent);
- if ((code & SWT.TRAVERSE_MNEMONIC) == 0) return false;
- } else {
- int mask = OS.ControlMask | OS.ShiftMask | OS.Mod1Mask;
- if ((xEvent.state & mask) != OS.Mod1Mask) return false;
- }
- Decorations shell = menuShell ();
- if (shell.isVisible () && shell.isEnabled ()) {
- Event event = new Event();
- event.time = xEvent.time;
- event.detail = SWT.TRAVERSE_MNEMONIC;
- event.character = key;
- event.keyCode = keysym;
- if (setInputState (event, xEvent.state)) {
- return translateMnemonic (event, null) || shell.translateMnemonic (event, this);
- }
- }
- return false;
-}
-boolean translateTraversal (int key, XKeyEvent xEvent) {
- int detail = SWT.TRAVERSE_NONE;
- int code = traversalCode (key, xEvent);
- boolean all = false;
- switch (key) {
- case OS.XK_Escape: {
- all = true;
- detail = SWT.TRAVERSE_ESCAPE;
- break;
- }
- case OS.XK_KP_Enter:
- case OS.XK_Return: {
- all = true;
- detail = SWT.TRAVERSE_RETURN;
- break;
- }
- case OS.XK_Tab: {
- boolean next = (xEvent.state & OS.ShiftMask) == 0;
- detail = next ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS;
- break;
- }
- case OS.XK_Up:
- case OS.XK_Left:
- case OS.XK_Down:
- case OS.XK_Right: {
- boolean next = key == OS.XK_Down || key == OS.XK_Right;
- detail = next ? SWT.TRAVERSE_ARROW_NEXT : SWT.TRAVERSE_ARROW_PREVIOUS;
- break;
- }
- case OS.XK_Page_Up:
- case OS.XK_Page_Down: {
- all = true;
- if ((xEvent.state & OS.ControlMask) == 0) return false;
- detail = key == OS.XK_Page_Down ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS;
- break;
- }
- default:
- return false;
- }
- Event event = new Event ();
- event.doit = (code & detail) != 0;
- event.detail = detail;
- event.time = xEvent.time;
- if (!setKeyState (event, xEvent)) return false;
- Shell shell = getShell ();
- Control control = this;
- do {
- if (control.traverse (event)) return true;
- if (!event.doit && control.hooks (SWT.Traverse)) return false;
- if (control == shell) return false;
- control = control.parent;
- } while (all && control != null);
- return false;
-}
-int traversalCode (int key, XKeyEvent xEvent) {
- int [] argList = new int [] {OS.XmNtraversalOn, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] == 0) return 0;
- int code = SWT.TRAVERSE_RETURN | SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_PAGE_NEXT | SWT.TRAVERSE_PAGE_PREVIOUS;
- Shell shell = getShell ();
- if (shell.parent != null) code |= SWT.TRAVERSE_ESCAPE;
- if (getNavigationType () == OS.XmNONE) {
- code |= SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS;
- }
- return code;
-}
-boolean traverse (Event event) {
- sendEvent (SWT.Traverse, event);
- if (isDisposed ()) return true;
- if (!event.doit) return false;
- switch (event.detail) {
- case SWT.TRAVERSE_NONE: return true;
- case SWT.TRAVERSE_ESCAPE: return traverseEscape ();
- case SWT.TRAVERSE_RETURN: return traverseReturn ();
- case SWT.TRAVERSE_TAB_NEXT: return traverseGroup (true);
- case SWT.TRAVERSE_TAB_PREVIOUS: return traverseGroup (false);
- case SWT.TRAVERSE_ARROW_NEXT: return traverseItem (true);
- case SWT.TRAVERSE_ARROW_PREVIOUS: return traverseItem (false);
- case SWT.TRAVERSE_MNEMONIC: return traverseMnemonic (event.character);
- case SWT.TRAVERSE_PAGE_NEXT: return traversePage (true);
- case SWT.TRAVERSE_PAGE_PREVIOUS: return traversePage (false);
- }
- return false;
-}
-/**
- * Based on the argument, perform one of the expected platform
- * traversal action. The argument should be one of the constants:
- * <code>SWT.TRAVERSE_ESCAPE</code>, <code>SWT.TRAVERSE_RETURN</code>,
- * <code>SWT.TRAVERSE_TAB_NEXT</code>, <code>SWT.TRAVERSE_TAB_PREVIOUS</code>,
- * <code>SWT.TRAVERSE_ARROW_NEXT</code> and <code>SWT.TRAVERSE_ARROW_PREVIOUS</code>.
- *
- * @param traversal the type of traversal
- * @return true if the traversal succeeded
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean traverse (int traversal) {
- checkWidget();
- Event event = new Event ();
- event.doit = true;
- event.detail = traversal;
- return traverse (event);
-}
-boolean traverseEscape () {
- return false;
-}
-boolean traverseGroup (boolean next) {
- Control root = computeTabRoot ();
- Control group = computeTabGroup ();
- Control [] list = root.computeTabList ();
- int length = list.length;
- int index = 0;
- while (index < length) {
- if (list [index] == group) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- if (index == length) return false;
- int start = index, offset = (next) ? 1 : -1;
- while ((index = ((index + offset + length) % length)) != start) {
- Control control = list [index];
- if (!control.isDisposed () && control.setTabGroupFocus (next)) {
- return true;
- }
- }
- if (group.isDisposed ()) return false;
- return group.setTabGroupFocus (next);
-}
-boolean traverseItem (boolean next) {
- Control [] children = parent._getChildren ();
- int length = children.length;
- int index = 0;
- while (index < length) {
- if (children [index] == this) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- if (index == length) return false;
- int start = index, offset = (next) ? 1 : -1;
- while ((index = (index + offset + length) % length) != start) {
- Control child = children [index];
- if (!child.isDisposed () && child.isTabItem ()) {
- if (child.setTabItemFocus (next)) return true;
- }
- }
- return false;
-}
-boolean traversePage (boolean next) {
- return false;
-}
-boolean traverseMnemonic (char key) {
- return mnemonicHit (key);
-}
-boolean traverseReturn () {
- return false;
-}
-/**
- * Forces all outstanding paint requests for the widget
- * to be processed before this method returns. If there
- * are no outstanding paint request, this method does
- * nothing.
- * <p>
- * Note: This method does not cause a redraw.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #redraw()
- * @see #redraw(int, int, int, int, boolean)
- * @see PaintListener
- * @see SWT#Paint
- */
-public void update () {
- checkWidget();
- update (false);
-}
-void update (boolean all) {
-// checkWidget();
- if (all) {
- display.update ();
- } else {
- int display = OS.XtDisplay (handle);
- if (display == 0) return;
- int window = OS.XtWindow (handle);
- if (window == 0) return;
- int event = OS.XtMalloc (XEvent.sizeof);
- OS.XSync (display, false);
- OS.XSync (display, false);
- while (OS.XCheckWindowEvent (display, window, OS.ExposureMask, event)) {
- OS.XtDispatchEvent (event);
- }
- OS.XtFree (event);
- }
-}
-void updateBackgroundMode () {
- int oldState = state & PARENT_BACKGROUND;
- checkBackground ();
- if (oldState != (state & PARENT_BACKGROUND)) {
- setBackground ();
- }
-}
-void updateIM () {
- if (!OS.IsDBLocale) return;
- if (!hasFocus ()) return;
- int[] argList2;
- int ptr1 = 0, ptr2 = 0;
- if (hasIMSupport ()) {
- argList2 = new int[]{
- OS.XmNfontList, font.handle,
-// OS.XmNforeground, getForegroundPixel (),
-// OS.XmNbackground, getBackgroundPixel (),
- };
- } else {
- int x = 0, y = 0;
- Font font = this.font;
- Caret caret = getIMCaret ();
- if (caret != null) {
- x += caret.x + (caret.width <= 0 ? 2 : caret.width);
- y += caret.y;
- if (caret.font != null) font = caret.font;
- }
- y += getFontAscent (font.handle);
- short [] point = new short[]{(short) x, (short) y};
- ptr1 = OS.XtMalloc (4);
- OS.memmove (ptr1, point, 4);
- int [] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- short [] rect = new short[]{0, 0, (short) argList1 [1], (short) argList1 [3]};
- ptr2 = OS.XtMalloc (8);
- OS.memmove (ptr2, rect, 8);
- /*
- * Feature in Motif. The XmNarea resource has to be set after
- * the XmNspotLocation.
- */
- argList2 = new int[]{
- OS.XmNfontList, font.handle,
-// OS.XmNforeground, getForegroundPixel (),
-// OS.XmNbackground, getBackgroundPixel (),
- OS.XmNspotLocation, ptr1,
- OS.XmNarea, ptr2,
- };
- }
- OS.XmImSetValues (handle, argList2, argList2.length / 2);
- int focusHandle = focusHandle ();
- if (handle != focusHandle) {
- OS.XmImSetValues (focusHandle, argList2, argList2.length / 2);
- }
- if (ptr1 != 0) OS.XtFree (ptr1);
- if (ptr2 != 0) OS.XtFree (ptr2);
-}
-void updateLayout (boolean all) {
- /* Do nothing */
-}
-int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- Display display = this.display;
- display.hideToolTip ();
- Shell shell = getShell ();
- /*
- * When a shell is created with SWT.ON_TOP and SWT.NO_FOCUS,
- * do not activate the shell when the user clicks on the
- * the client area or on the border or a control within the
- * shell that does not take focus.
- */
- if (((shell.style & SWT.ON_TOP) != 0) && (((shell.style & SWT.NO_FOCUS) == 0) || ((style & SWT.NO_FOCUS) == 0))) {
- shell.forceActive();
- }
- boolean dispatch = true, dragging = false;
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- int clickTime = display.getDoubleClickTime ();
- int lastTime = display.lastTime, eventTime = xEvent.time;
- int lastButton = display.lastButton, eventButton = xEvent.button;
- if (lastButton == eventButton && lastTime != 0 && Math.abs (lastTime - eventTime) <= clickTime) {
- display.clickCount++;
- } else {
- display.clickCount = 1;
- }
- display.lastTime = eventTime == 0 ? 1 : eventTime;
- display.lastButton = eventButton;
- if (xEvent.button == 2) {
- if ((state & DRAG_DETECT) != 0 && hooks (SWT.DragDetect)) {
- boolean [] consume = new boolean [1];
- if (dragDetect (xEvent.x, xEvent.y, true, consume)) {
- dragging = true;
- dispatch = !consume [0];
- }
- if (isDisposed ()) return 1;
- }
- }
- if (!sendMouseEvent (SWT.MouseDown, xEvent)) dispatch = false;
- if (isDisposed ()) return 1;
- if (display.clickCount == 2) {
- if (!sendMouseEvent (SWT.MouseDoubleClick, xEvent)) dispatch = false;
- if (isDisposed ()) return 1;
- // widget could be disposed at this point
- }
- if (dragging) {
- sendDragEvent (xEvent.button, xEvent.state, xEvent.x, xEvent.y, false);
- if (isDisposed ()) return 1;
- }
- if (xEvent.button == 3) {
- if (menu != null || hooks (SWT.MenuDetect)) {
- if (!isFocusControl ()) setFocus ();
- }
- showMenu (xEvent.x_root, xEvent.y_root);
- if (isDisposed ()) return 1;
- }
- if (!shell.isDisposed ()) shell.setActiveControl (this);
- if (!dispatch) {
- OS.memmove (continue_to_dispatch, new int [1], 4);
- return 1;
- }
- return 0;
-}
-int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- display.hideToolTip ();
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- if (!sendMouseEvent (SWT.MouseUp, xEvent)) {
- OS.memmove (continue_to_dispatch, new int [1], 4);
- return 1;
- }
- return 0;
-}
-int XEnterWindow (int w, int client_data, int call_data, int continue_to_dispatch) {
- XCrossingEvent xEvent = new XCrossingEvent ();
- OS.memmove (xEvent, call_data, XCrossingEvent.sizeof);
- if (xEvent.mode != OS.NotifyNormal && xEvent.mode != OS.NotifyUngrab) return 0;
- if ((xEvent.state & (OS.Button1Mask | OS.Button2Mask | OS.Button3Mask)) != 0) return 0;
- if (xEvent.subwindow != 0) return 0;
- if (!sendMouseEvent (SWT.MouseEnter, xEvent)) {
- OS.memmove (continue_to_dispatch, new int [1], 4);
- return 1;
- }
- return 0;
-}
-int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) {
- if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0;
- XExposeEvent xEvent = new XExposeEvent ();
- OS.memmove (xEvent, call_data, XExposeEvent.sizeof);
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return 0;
- int damageRgn = OS.XCreateRegion ();
- OS.XtAddExposureToRegion (call_data, damageRgn);
- Event event = new Event ();
- event.count = xEvent.count;
- event.x = xEvent.x;
- event.y = xEvent.y;
- event.width = xEvent.width;
- event.height = xEvent.height;
- GCData data = new GCData();
- data.damageRgn = damageRgn;
- GC gc = event.gc = GC.motif_new(this, data);
- OS.XSetRegion (xDisplay, gc.handle, damageRgn);
- sendEvent (SWT.Paint, event);
- event.gc = null;
- gc.dispose ();
- OS.XDestroyRegion(damageRgn);
- return 0;
-}
-int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatch) {
-
- /* Get the focus change event */
- XFocusChangeEvent xEvent = new XFocusChangeEvent ();
- OS.memmove (xEvent, call_data, XFocusChangeEvent.sizeof);
-
- /* Ignore focus changes caused by grabbing and ungrabing */
- if (xEvent.mode != OS.NotifyNormal) return 0;
-
- /* Only process focus callbacks between windows */
- if (xEvent.detail != OS.NotifyAncestor &&
- xEvent.detail != OS.NotifyInferior &&
- xEvent.detail != OS.NotifyNonlinear) return 0;
-
- /* Process the focus change for the widget */
- Display display = this.display;
- Shell shell = getShell ();
- switch (xEvent.type) {
- case OS.FocusIn:
- xFocusIn (xEvent);
- // widget could be disposed at this point
-
- /*
- * It is possible that the shell may be
- * disposed at this point. If this happens
- * don't send the activate and deactivate
- * events.
- */
- if (!shell.isDisposed ()) {
- shell.setActiveControl (this);
- }
- break;
- case OS.FocusOut:
- xFocusOut (xEvent);
- // widget could be disposed at this point
-
- /*
- * It is possible that the shell may be
- * disposed at this point. If this happens
- * don't send the activate and deactivate
- * events.
- */
- if (!shell.isDisposed ()) {
- if (shell != display.getActiveShell ()) {
- shell.setActiveControl (null);
- }
- }
- break;
- }
- return 0;
-}
-int xFocusIn (XFocusChangeEvent xEvent) {
- /*
- * Bug in Motif. For some reason, when the widget font is
- * not the default font and the widget loses focus, the
- * X input method segment faults. A BadFont (invalid font
- * parameter) error is printed. This problem also happens
- * to XmText and XmTextField. The fix is to change the
- * X input method font back to the default font when the
- * widget loses focus and restore it when the widget gets
- * focus.
- */
- updateIM ();
- if (!hasIMSupport ()) {
- int focusHandle = OS.XtWindowToWidget (xEvent.display, xEvent.window);
- OS.XmImSetFocusValues (focusHandle, null, 0);
- }
- sendFocusEvent (SWT.FocusIn);
- return 0;
-}
-int xFocusOut (XFocusChangeEvent xEvent) {
- int focusHandle = OS.XtWindowToWidget (xEvent.display, xEvent.window);
- if (!hasIMSupport ()) OS.XmImUnsetFocus (focusHandle);
-
- /*
- * Bug in Motif. For some reason, when the widget font is
- * not the default font and the widget loses focus, the
- * X input method segment faults. A BadFont (invalid font
- * parameter) error is printed. This problem also happens
- * to XmText and XmTextField. The fix is to change the
- * X input method font back to the default font when the
- * widget loses focus and restore it when the widget gets
- * focus.
- *
- * NOTE: On AIX, changing the IM font when focus is lost because
- * the shell was resized by the user causes the ConfigureNotify
- * event for the shell to be lost. The event is not in the
- * event queue and therefore not dispatched. The fix is to avoid
- * the workaround for AIX.
- */
- if (!OS.IsAIX) {
- int fontList = defaultFont ().handle;
- if (font.handle != fontList) {
- int [] argList2 = {OS.XmNfontList, fontList};
- OS.XmImSetValues (focusHandle, argList2, argList2.length / 2);
- }
- }
-
- sendFocusEvent (SWT.FocusOut);
-
- /* Restore XmNtraversalOn if it was focus was forced */
- if (handle == 0) return 0;
- if ((style & SWT.NO_FOCUS) != 0) {
- int [] argList = new int [] {OS.XmNtraversalOn, 0};
- OS.XtGetValues (focusHandle, argList, argList.length / 2);
- if (argList [1] != 0 && (state & FOCUS_FORCED) != 0) {
- argList [1] = 0;
- OS.XtSetValues (focusHandle, argList, argList.length / 2);
- }
- }
- return 0;
-}
-int XKeyRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- XKeyEvent xEvent = new XKeyEvent ();
- OS.memmove (xEvent, call_data, XKeyEvent.sizeof);
- if (menu != null && xEvent.state == OS.ShiftMask) {
- byte [] buffer = new byte [1];
- int [] keysym = new int [1];
- OS.XLookupString (xEvent, buffer, buffer.length, keysym, null);
- if (keysym [0] == OS.XK_F10) {
- showMenu (xEvent.x_root, xEvent.y_root);
- }
- }
- return super.XKeyRelease (w, client_data, call_data, continue_to_dispatch);
-}
-int XLeaveWindow (int w, int client_data, int call_data, int continue_to_dispatch) {
- display.removeMouseHoverTimeOut ();
- display.hideToolTip ();
- XCrossingEvent xEvent = new XCrossingEvent ();
- OS.memmove (xEvent, call_data, XCrossingEvent.sizeof);
- if (xEvent.mode != OS.NotifyNormal && xEvent.mode != OS.NotifyUngrab) return 0;
- if ((xEvent.state & (OS.Button1Mask | OS.Button2Mask | OS.Button3Mask)) != 0) return 0;
- if (xEvent.subwindow != 0) return 0;
- if (!sendMouseEvent (SWT.MouseExit, xEvent)) {
- OS.memmove (continue_to_dispatch, new int [1], 4);
- return 1;
- }
- return 0;
-}
-int XmNhelpCallback (int w, int client_data, int call_data) {
- sendHelpEvent (call_data);
- return 0;
-}
-int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) {
- display.addMouseHoverTimeOut (handle);
- XMotionEvent xEvent = new XMotionEvent ();
- OS.memmove (xEvent, call_data, XMotionEvent.sizeof);
- if (!sendMouseEvent (SWT.MouseMove, xEvent)) {
- OS.memmove (continue_to_dispatch, new int [1], 4);
- return 1;
- }
- return 0;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java
deleted file mode 100755
index 5c0b2ba927..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java
+++ /dev/null
@@ -1,797 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide the appearance and
- * behavior of <code>Shells</code>, but are not top
- * level shells or dialogs. Class <code>Shell</code>
- * shares a significant amount of code with this class,
- * and is a subclass.
- * <p>
- * IMPORTANT: This class was intended to be abstract and
- * should <em>never</em> be referenced or instantiated.
- * Instead, the class <code>Shell</code> should be used.
- * </p>
- * <p>
- * Instances are always displayed in one of the maximized,
- * minimized or normal states:
- * <ul>
- * <li>
- * When an instance is marked as <em>maximized</em>, the
- * window manager will typically resize it to fill the
- * entire visible area of the display, and the instance
- * is usually put in a state where it can not be resized
- * (even if it has style <code>RESIZE</code>) until it is
- * no longer maximized.
- * </li><li>
- * When an instance is in the <em>normal</em> state (neither
- * maximized or minimized), its appearance is controlled by
- * the style constants which were specified when it was created
- * and the restrictions of the window manager (see below).
- * </li><li>
- * When an instance has been marked as <em>minimized</em>,
- * its contents (client area) will usually not be visible,
- * and depending on the window manager, it may be
- * "iconified" (that is, replaced on the desktop by a small
- * simplified representation of itself), relocated to a
- * distinguished area of the screen, or hidden. Combinations
- * of these changes are also possible.
- * </li>
- * </ul>
- * </p>
- * Note: The styles supported by this class must be treated
- * as <em>HINT</em>s, since the window manager for the
- * desktop on which the instance is visible has ultimate
- * control over the appearance and behavior of decorations.
- * For example, some window managers only support resizable
- * windows and will always assume the RESIZE style, even if
- * it is not set.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * Class <code>SWT</code> provides two "convenience constants"
- * for the most commonly required style combinations:
- * <dl>
- * <dt><code>SHELL_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application top level shell: (that
- * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>)
- * </dd>
- * <dt><code>DIALOG_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application dialog shell: (that
- * is, <code>TITLE | CLOSE | BORDER</code>)
- * </dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see #getMinimized
- * @see #getMaximized
- * @see Shell
- * @see SWT
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Decorations extends Canvas {
- String label;
- Image image;
- Image [] images = new Image [0];
- int dialogHandle;
- boolean minimized, maximized;
- Menu menuBar;
- Menu [] menus;
- Control savedFocus;
- Button defaultButton, saveDefault;
-Decorations () {
- /* Do nothing */
-}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#TOOL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Decorations (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-void _setImages (Image [] images) {
- if (images != null && images.length > 1) {
- Image [] bestImages = new Image [images.length];
- System.arraycopy (images, 0, bestImages, 0, images.length);
- sort (bestImages);
- images = bestImages;
- }
- Image icon = images != null && images.length > 0 ? icon = images [0] : null;
- int pixmap = 0, mask = 0;
- if (icon != null) {
- switch (icon.type) {
- case SWT.BITMAP:
- pixmap = icon.pixmap;
- break;
- case SWT.ICON:
- pixmap = icon.pixmap;
- mask = icon.mask;
- break;
- }
- }
- int [] argList = {
- OS.XmNiconPixmap, pixmap,
- OS.XmNiconMask, mask,
- };
- int topHandle = topHandle ();
- OS.XtSetValues (topHandle, argList, argList.length / 2);
-}
-
-void addMenu (Menu menu) {
- if (menus == null) menus = new Menu [4];
- for (int i=0; i<menus.length; i++) {
- if (menus [i] == null) {
- menus [i] = menu;
- return;
- }
- }
- Menu [] newMenus = new Menu [menus.length + 4];
- newMenus [menus.length] = menu;
- System.arraycopy (menus, 0, newMenus, 0, menus.length);
- menus = newMenus;
-}
-void bringToTop (boolean force) {
- moveAbove (null);
-}
-static int checkStyle (int style) {
- if ((style & SWT.NO_TRIM) != 0) {
- style &= ~(SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX | SWT.RESIZE | SWT.BORDER);
- }
- if ((style & (SWT.MENU | SWT.MIN | SWT.MAX | SWT.CLOSE)) != 0) {
- style |= SWT.TITLE;
- }
- return style;
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-int compare (ImageData data1, ImageData data2) {
- int transparent1 = data1.getTransparencyType ();
- int transparent2 = data2.getTransparencyType ();
- if (transparent1 != transparent2) {
- if (transparent1 == SWT.TRANSPARENCY_ALPHA) return 1;
- if (transparent2 == SWT.TRANSPARENCY_ALPHA) return -1;
- }
- if (data1.width == data2.width && data1.height == data2.height) {
- if (transparent1 == SWT.TRANSPARENCY_MASK) return -1;
- if (transparent2 == SWT.TRANSPARENCY_MASK) return 1;
- if (transparent1 == SWT.TRANSPARENCY_PIXEL) return -1;
- if (transparent2 == SWT.TRANSPARENCY_PIXEL) return 1;
- return 0;
- }
- return data1.width > data2.width || data1.height > data2.height ? -1 : 1;
-}
-
-Control computeTabGroup () {
- return this;
-}
-
-Control computeTabRoot () {
- return this;
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- Rectangle trim = super.computeTrim (x, y, width, height);
- if (menuBar != null) {
- XtWidgetGeometry request = new XtWidgetGeometry ();
- XtWidgetGeometry result = new XtWidgetGeometry ();
- request.request_mode = OS.CWWidth;
- request.width = trim.width;
- OS.XtQueryGeometry (menuBar.handle, request, result);
- trim.height += result.height;
- }
- return trim;
-}
-void createHandle (int index) {
- state |= CANVAS;
- createHandle (index, parent.handle, true);
-}
-void createWidget (int index) {
- super.createWidget (index);
- label = "";
-}
-int dialogHandle () {
- if (dialogHandle != 0) return dialogHandle;
- return dialogHandle = OS.XmCreateDialogShell (handle, null, null, 0);
-}
-/**
- * Returns the receiver's default button if one had
- * previously been set, otherwise returns null.
- *
- * @return the default button or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDefaultButton(Button)
- */
-public Button getDefaultButton () {
- checkWidget();
- return defaultButton;
-}
-/**
- * Returns the receiver's image if it had previously been
- * set using <code>setImage()</code>. The image is typically
- * displayed by the window manager when the instance is
- * marked as iconified, and may also be displayed somewhere
- * in the trim when the instance is in normal or maximized
- * states.
- * <p>
- * Note: This method will return null if called before
- * <code>setImage()</code> is called. It does not provide
- * access to a window manager provided, "default" image
- * even if one exists.
- * </p>
- *
- * @return the image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-/**
- * Returns the receiver's images if they had previously been
- * set using <code>setImages()</code>. Images are typically
- * displayed by the window manager when the instance is
- * marked as iconified, and may also be displayed somewhere
- * in the trim when the instance is in normal or maximized
- * states. Depending where the icon is displayed, the platform
- * chooses the icon with the "best" attributes. It is expected
- * that the array will contain the same icon rendered at different
- * sizes, with different depth and transparency attributes.
- *
- * <p>
- * Note: This method will return an empty array if called before
- * <code>setImages()</code> is called. It does not provide
- * access to a window manager provided, "default" image
- * even if one exists.
- * </p>
- *
- * @return the images
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Image [] getImages () {
- checkWidget ();
- if (images == null) return new Image [0];
- Image [] result = new Image [images.length];
- System.arraycopy (images, 0, result, 0, images.length);
- return result;
-}
-/**
- * Returns <code>true</code> if the receiver is currently
- * maximized, and false otherwise.
- * <p>
- *
- * @return the maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMaximized
- */
-public boolean getMaximized () {
- checkWidget();
- return maximized;
-}
-/**
- * Returns the receiver's menu bar if one had previously
- * been set, otherwise returns null.
- *
- * @return the menu bar or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenuBar () {
- checkWidget();
- return menuBar;
-}
-/**
- * Returns <code>true</code> if the receiver is currently
- * minimized, and false otherwise.
- * <p>
- *
- * @return the minimized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMinimized
- */
-public boolean getMinimized () {
- checkWidget();
- return minimized;
-}
-String getNameText () {
- return getText ();
-}
-/**
- * Returns the receiver's text, which is the string that the
- * window manager will typically display as the receiver's
- * <em>title</em>. If the text has not previously been set,
- * returns an empty string.
- *
- * @return the text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- return label;
-}
-boolean isTabGroup () {
- return true;
-}
-boolean isTabItem () {
- return false;
-}
-Decorations menuShell () {
- return this;
-}
-void propagateWidget (boolean enabled) {
- super.propagateWidget (enabled);
- int [] argList = {OS.XmNmenuBar, 0};
- OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
- if (argList [1] != 0) propagateHandle (enabled, argList [1], OS.None);
-}
-void releaseChildren (boolean destroy) {
- if (menuBar != null) {
- menuBar.release (false);
- menuBar = null;
- }
- super.releaseChildren (destroy);
- if (menus != null) {
- for (int i=0; i<menus.length; i++) {
- Menu menu = menus [i];
- if (menu != null && !menu.isDisposed ()) {
- menu.release (false);
- }
- }
- menus = null;
- }
-}
-void releaseHandle () {
- super.releaseHandle ();
- dialogHandle = 0;
-}
-void releaseWidget () {
- super.releaseWidget ();
- image = null;
- images = null;
- savedFocus = null;
- defaultButton = saveDefault = null;
- label = null;
-}
-boolean restoreFocus () {
- if (savedFocus != null && savedFocus.isDisposed ()) savedFocus = null;
- boolean restored = savedFocus != null && savedFocus.setFocus ();
- savedFocus = null;
- /*
- * This code is intentionally commented. When no widget
- * has been given focus, some platforms give focus to the
- * default button. Motif doesn't do this.
- */
-// if (restored) return true;
-// if (defaultButton != null && !defaultButton.isDisposed ()) {
-// if (defaultButton.setFocus ()) return true;
-// }
-// return false;
- return restored;
-}
-void removeMenu (Menu menu) {
- if (menus == null) return;
- for (int i=0; i<menus.length; i++) {
- if (menus [i] == menu) {
- menus [i] = null;
- return;
- }
- }
-}
-/**
- * If the argument is not null, sets the receiver's default
- * button to the argument, and if the argument is null, sets
- * the receiver's default button to the first button which
- * was set as the receiver's default button (called the
- * <em>saved default button</em>). If no default button had
- * previously been set, or the saved default button was
- * disposed, the receiver's default button will be set to
- * null.
- * <p>
- * The default button is the button that is selected when
- * the receiver is active and the user presses ENTER.
- * </p>
- *
- * @param button the new default button
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the button has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDefaultButton (Button button) {
- checkWidget();
- if (button != null) {
- if (button.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (button.menuShell () != this) error(SWT.ERROR_INVALID_PARENT);
- }
- setDefaultButton (button, true);
-}
-void setDefaultButton (Button button, boolean save) {
- if (button == null) {
- if (defaultButton == saveDefault) {
- if (save) saveDefault = null;
- return;
- }
- } else {
- if ((button.style & SWT.PUSH) == 0) return;
- if (button == defaultButton) return;
- }
- if (defaultButton != null) {
- if (!defaultButton.isDisposed ()) defaultButton.setDefault (false);
- }
- if ((defaultButton = button) == null) defaultButton = saveDefault;
- if (defaultButton != null) {
- if (!defaultButton.isDisposed ()) defaultButton.setDefault (true);
- }
- if (save) saveDefault = defaultButton;
- if (saveDefault != null && saveDefault.isDisposed ()) saveDefault = null;
-}
-/**
- * Sets the receiver's image to the argument, which may
- * be null. The image is typically displayed by the window
- * manager when the instance is marked as iconified, and
- * may also be displayed somewhere in the trim when the
- * instance is in normal or maximized states.
- *
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- this.image = image;
- _setImages (image != null ? new Image [] {image} : null);
-}
-
-/**
- * Sets the receiver's images to the argument, which may
- * be an empty array. Images are typically displayed by the
- * window manager when the instance is marked as iconified,
- * and may also be displayed somewhere in the trim when the
- * instance is in normal or maximized states. Depending where
- * the icon is displayed, the platform chooses the icon with
- * the "best" attributes. It is expected that the array will
- * contain the same icon rendered at different sizes, with
- * different depth and transparency attributes.
- *
- * @param images the new image array
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images is null or has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setImages (Image [] images) {
- checkWidget ();
- if (images == null) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i = 0; i < images.length; i++) {
- if (images [i] == null || images [i].isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.images = images;
- _setImages (images);
-}
-
-/**
- * Sets the maximized state of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the maximized state, and if the argument is
- * <code>false</code> and the receiver was previously maximized,
- * causes the receiver to switch back to either the minimized
- * or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setMaximized(true)</code>
- * and <code>setMinimized(true)</code> will vary by platform. Typically,
- * the behavior will match the platform user's expectations, but not
- * always. This should be avoided if possible.
- * </p>
- *
- * @param maximized the new maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMinimized
- */
-public void setMaximized (boolean maximized) {
- checkWidget();
- this.maximized = maximized;
-}
-/**
- * Sets the receiver's menu bar to the argument, which
- * may be null.
- *
- * @param menu the new menu bar
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenuBar (Menu menu) {
- checkWidget();
- if (menuBar == menu) return;
- if (menu != null) {
- if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR);
- if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
-
- /* Ensure the new menu bar is correctly enabled */
- if (menuBar != null) {
- if (!isEnabled () && menuBar.getEnabled ()) {
- propagateHandle (true, menuBar.handle, OS.None);
- }
- menuBar.removeAccelerators ();
- }
- if (menu != null) {
- if (!isEnabled ()) {
- propagateHandle (false, menu.handle, OS.None);
- }
- menu.addAccelerators ();
- }
-
- /* Save the old client area */
- int [] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
-
- /*
- * Bug in Motif. When a XmMainWindowSetAreas () is used
- * to replace an existing menu, both menus must be managed
- * before the call to XmMainWindowSetAreas () or the new
- * menu will not be laid out properly.
- */
- int newHandle = (menu != null) ? menu.handle : 0;
- int oldHandle = (menuBar != null) ? menuBar.handle : 0;
- menuBar = menu;
- int hHandle = (horizontalBar != null) ? horizontalBar.handle : 0;
- int vHandle = (verticalBar != null) ? verticalBar.handle : 0;
- if (newHandle != 0) {
- OS.XtSetMappedWhenManaged (newHandle, false);
- OS.XtManageChild (newHandle);
- }
- int clientHandle = formHandle != 0 ? formHandle : handle;
- OS.XmMainWindowSetAreas (scrolledHandle, newHandle, 0, hHandle, vHandle, clientHandle);
- if (oldHandle != 0) OS.XtUnmanageChild (oldHandle);
- if (newHandle != 0) {
- OS.XtSetMappedWhenManaged (newHandle, true);
- }
-
- /*
- * Bug in Motif. When a menu bar is removed after the
- * main window has been realized, the main window does
- * not layout the new menu bar or the work window.
- * The fix is to force a layout by temporarily resizing
- * the main window.
- */
- if (newHandle == 0 && OS.XtIsRealized (scrolledHandle)) {
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
- OS.XtResizeWidget (scrolledHandle, argList [1] + 1, argList [3], argList [5]);
- OS.XtResizeWidget (scrolledHandle, argList [1], argList [3], argList [5]);
- }
-
- /*
- * Compare the old client area with the new client area.
- * If the client area has changed, send a resize event
- * and layout.
- */
- int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList2, argList2.length / 2);
- if (argList1 [1] != argList2 [1] || argList1 [3] != argList2 [3]) {
- sendEvent (SWT.Resize);
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
- }
-}
-/**
- * Sets the minimized stated of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the minimized state, and if the argument is
- * <code>false</code> and the receiver was previously minimized,
- * causes the receiver to switch back to either the maximized
- * or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setMaximized(true)</code>
- * and <code>setMinimized(true)</code> will vary by platform. Typically,
- * the behavior will match the platform user's expectations, but not
- * always. This should be avoided if possible.
- * </p>
- *
- * @param minimized the new maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMaximized
- */
-public void setMinimized (boolean minimized) {
- checkWidget();
- this.minimized = minimized;
-}
-void setSavedFocus (Control control) {
- if (this == control) return;
- savedFocus = control;
-}
-/**
- * Sets the receiver's text, which is the string that the
- * window manager will typically display as the receiver's
- * <em>title</em>, to the argument, which must not be null.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- label = string;
-}
-void sort (Image [] images) {
- /* Shell Sort from K&R, pg 108 */
- int length = images.length;
- if (length <= 1) return;
- ImageData [] datas = new ImageData [length];
- for (int i = 0; i < length; i++) {
- datas [i] = images [i].getImageData ();
- }
- for (int gap=length/2; gap>0; gap/=2) {
- for (int i=gap; i<length; i++) {
- for (int j=i-gap; j>=0; j-=gap) {
- if (compare (datas [j], datas [j + gap]) >= 0) {
- Image swap = images [j];
- images [j] = images [j + gap];
- images [j + gap] = swap;
- ImageData swapData = datas [j];
- datas [j] = datas [j + gap];
- datas [j + gap] = swapData;
- }
- }
- }
- }
-}
-boolean translateAccelerator (char key, int keysym, XKeyEvent xEvent, boolean doit) {
- if (menuBar == null || !menuBar.getEnabled ()) return false;
- int accelerator = Display.translateKey (keysym);
- if (accelerator == 0) accelerator = key;
- if (accelerator == 0) return false;
- if ((xEvent.state & OS.Mod1Mask) != 0) accelerator |= SWT.ALT;
- if ((xEvent.state & OS.ShiftMask) != 0) accelerator |= SWT.SHIFT;
- if ((xEvent.state & OS.ControlMask) != 0) accelerator |= SWT.CONTROL;
- return menuBar.translateAccelerator (accelerator, doit);
-}
-boolean traverseItem (boolean next) {
- return false;
-}
-boolean traverseReturn () {
- if (defaultButton == null || defaultButton.isDisposed ()) return false;
- if (!defaultButton.isVisible () || !defaultButton.isEnabled ()) return false;
- defaultButton.click ();
- return true;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java
deleted file mode 100755
index 9d38b2ac95..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java
+++ /dev/null
@@ -1,347 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class allow the user to navigate
- * the file system and select a directory.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#directorydialog">DirectoryDialog snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class DirectoryDialog extends Dialog {
- String filterPath = ""; //$NON-NLS-1$
- boolean cancel = true;
- String message = ""; //$NON-NLS-1$
- static final String SEPARATOR = System.getProperty ("file.separator"); //$NON-NLS-1$
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public DirectoryDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public DirectoryDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-int activate (int widget, int client, int call) {
- cancel = client == OS.XmDIALOG_CANCEL_BUTTON;
- OS.XtUnmanageChild (widget);
- return 0;
-}
-/**
- * Returns the path which the dialog will use to filter
- * the directories it shows.
- *
- * @return the filter path
- *
- * @see #setFilterPath
- */
-public String getFilterPath () {
- return filterPath;
-}
-/**
- * Returns the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @return the message
- */
-public String getMessage () {
- return message;
-}
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a string describing the absolute path of the selected directory,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public String open () {
- /* Compute the dialog title */
- /*
- * Feature in Motif. It is not possible to set a shell
- * title to an empty string. The fix is to set the title
- * to be a single space.
- */
- String string = title;
- if (string.length () == 0) string = " "; //$NON-NLS-1$
-
- /* Use the character encoding for the default locale */
- byte [] buffer1 = Converter.wcsToMbcs (null, string, true);
- int xmStringPtr1 = OS.XmStringParseText (
- buffer1,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
-
- /* Compute the filter */
- /* Use the character encoding for the default locale */
- byte [] buffer2 = Converter.wcsToMbcs (null, "*", true); //$NON-NLS-1$
- int xmStringPtr2 = OS.XmStringParseText (
- buffer2,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
-
- /* Compute the filter path */
- if (filterPath == null) filterPath = ""; //$NON-NLS-1$
- /* Use the character encoding for the default locale */
- byte [] buffer3 = Converter.wcsToMbcs (null, filterPath, true);
- int xmStringPtr3 = OS.XmStringParseText (
- buffer3,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
-
- /* Use the character encoding for the default locale */
- byte [] buffer7 = Converter.wcsToMbcs (null, SWT.getMessage ("SWT_Selection"), true);
- int xmStringPtr4 = OS.XmStringParseText (
- buffer7,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
-
- /* Create the dialog */
- boolean defaultPos = parent.isVisible ();
- Display display = parent.display;
- int [] argList1 = {
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNdialogStyle, OS.XmDIALOG_PRIMARY_APPLICATION_MODAL,
- OS.XmNwidth, OS.XDisplayWidth (display.xDisplay, OS.XDefaultScreen (display.xDisplay)) * 4 / 9,
- OS.XmNdialogTitle, xmStringPtr1,
- OS.XmNpattern, xmStringPtr2,
- OS.XmNdirectory, xmStringPtr3,
- OS.XmNpathMode, OS.XmPATH_MODE_FULL,
- OS.XmNfilterLabelString, xmStringPtr4,
- OS.XmNdefaultPosition, defaultPos ? 1 : 0,
- };
-
- /*
- * Bug in AIX. The dialog does not respond to input, if the parent
- * is not realized. The fix is to realize the parent.
- */
- if (OS.IsAIX) parent.realizeWidget ();
- int parentHandle = parent.shellHandle;
- /*
- * Feature in Linux. For some reason, the XmCreateFileSelectionDialog()
- * will not accept NULL for the widget name. This works fine on the other
- * Motif platforms and in the other XmCreate calls on Linux. The fix is
- * to pass in a NULL terminated string, not a NULL pointer.
- */
- byte [] name = new byte [] {0};
- int dialog = OS.XmCreateFileSelectionDialog (parentHandle, name, argList1, argList1.length / 2);
- int child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_HELP_BUTTON);
- if (child != 0) OS.XtUnmanageChild (child);
- child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST);
- if (child != 0) {
- int parent2 = OS.XtParent(child);
- if (parent2 !=0) OS.XtUnmanageChild (parent2);
- }
- child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST_LABEL);
- if (child != 0) OS.XtUnmanageChild (child);
- child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_TEXT);
- if (child != 0) OS.XtUnmanageChild (child);
- child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_SELECTION_LABEL);
- if (child != 0) OS.XtUnmanageChild (child);
- OS.XmStringFree (xmStringPtr1);
- OS.XmStringFree (xmStringPtr2);
- OS.XmStringFree (xmStringPtr3);
- OS.XmStringFree (xmStringPtr4);
-
- /* Add label widget for message text. */
- /* Use the character encoding for the default locale */
- byte [] buffer4 = Converter.wcsToMbcs (null, message, true);
- int xmString1 = OS.XmStringGenerate(buffer4, null, OS.XmCHARSET_TEXT, null);
- int [] argList2 = {
- OS.XmNlabelType, OS.XmSTRING,
- OS.XmNlabelString, xmString1
- };
- int textArea = OS.XmCreateLabel(dialog, name, argList2, argList2.length/2);
- OS.XtManageChild(textArea);
- OS.XmStringFree (xmString1);
-
- /* Hook the callbacks. */
- Callback callback = new Callback (this, "activate", 3); //$NON-NLS-1$
- int address = callback.getAddress ();
- if (address == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- OS.XtAddCallback (dialog, OS.XmNokCallback, address, OS.XmDIALOG_OK_BUTTON);
- OS.XtAddCallback (dialog, OS.XmNcancelCallback, address, OS.XmDIALOG_CANCEL_BUTTON);
-
- /* Open the dialog and dispatch events. */
- cancel = true;
- if (!defaultPos) {
- OS.XtRealizeWidget (dialog);
- int[] argList3 = new int[] {
- OS.XmNwidth, 0,
- OS.XmNheight, 0,
- };
- OS.XtGetValues (dialog, argList3, argList3.length / 2);
- Monitor monitor = parent.getMonitor ();
- Rectangle bounds = monitor.getBounds ();
- int x = bounds.x + (bounds.width - argList3 [1]) / 2;
- int y = bounds.y + (bounds.height - argList3 [3]) / 2;
- int[] argList4 = new int[] {
- OS.XmNx, x,
- OS.XmNy, y,
- };
- OS.XtSetValues (dialog, argList4, argList4.length / 2);
- }
- OS.XtManageChild (dialog);
-
- /* Should be a pure OS message loop (no SWT AppContext) */
- while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog))
- if (!display.readAndDispatch ()) display.sleep ();
-
- /* Set the new path, file name and filter. */
- String directoryPath=""; //$NON-NLS-1$
- if (!cancel) {
- int [] argList5 = {OS.XmNdirMask, 0};
- OS.XtGetValues (dialog, argList5, argList5.length / 2);
- int xmString3 = argList5 [1];
- int [] table = new int [] {display.tabMapping, display.crMapping};
- int ptr = OS.XmStringUnparse (
- xmString3,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- table,
- table.length,
- OS.XmOUTPUT_ALL);
- if (ptr != 0) {
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, length);
- OS.XtFree (ptr);
- /* Use the character encoding for the default locale */
- directoryPath = new String (Converter.mbcsToWcs (null, buffer));
- }
- OS.XmStringFree (xmString3);
- int length = directoryPath.length ();
- if (directoryPath.charAt (length - 1) == '*') {
- directoryPath = directoryPath.substring (0, length - 1);
- length--;
- }
- if (directoryPath.endsWith (SEPARATOR) && !directoryPath.equals (SEPARATOR)) {
- directoryPath = directoryPath.substring (0, length - 1);
- }
- filterPath = directoryPath;
- }
-
- /* Destroy the dialog and update the display. */
- if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog);
- callback.dispose ();
-
- if (cancel) return null;
- return directoryPath;
-}
-/**
- * Sets the path that the dialog will use to filter
- * the directories it shows to the argument, which may
- * be null. If the string is null, then the operating
- * system's default filter path will be used.
- * <p>
- * Note that the path string is platform dependent.
- * For convenience, either '/' or '\' can be used
- * as a path separator.
- * </p>
- *
- * @param string the filter path
- */
-public void setFilterPath (String string) {
- filterPath = string;
-}
-/**
- * Sets the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @param string the message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- */
-public void setMessage (String string) {
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- message = string;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java
deleted file mode 100755
index 0f8d1f1021..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java
+++ /dev/null
@@ -1,3830 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are responsible for managing the
- * connection between SWT and the underlying operating
- * system. Their most important function is to implement
- * the SWT event loop in terms of the platform event model.
- * They also provide various methods for accessing information
- * about the operating system, and have overall control over
- * the operating system resources which SWT allocates.
- * <p>
- * Applications which are built with SWT will <em>almost always</em>
- * require only a single display. In particular, some platforms
- * which SWT supports will not allow more than one <em>active</em>
- * display. In other words, some platforms do not support
- * creating a new display if one already exists that has not been
- * sent the <code>dispose()</code> message.
- * <p>
- * In SWT, the thread which creates a <code>Display</code>
- * instance is distinguished as the <em>user-interface thread</em>
- * for that display.
- * </p>
- * The user-interface thread for a particular display has the
- * following special attributes:
- * <ul>
- * <li>
- * The event loop for that display must be run from the thread.
- * </li>
- * <li>
- * Some SWT API methods (notably, most of the public methods in
- * <code>Widget</code> and its subclasses), may only be called
- * from the thread. (To support multi-threaded user-interface
- * applications, class <code>Display</code> provides inter-thread
- * communication methods which allow threads other than the
- * user-interface thread to request that it perform operations
- * on their behalf.)
- * </li>
- * <li>
- * The thread is not allowed to construct other
- * <code>Display</code>s until that display has been disposed.
- * (Note that, this is in addition to the restriction mentioned
- * above concerning platform support for multiple displays. Thus,
- * the only way to have multiple simultaneously active displays,
- * even on platforms which support it, is to have multiple threads.)
- * </li>
- * </ul>
- * Enforcing these attributes allows SWT to be implemented directly
- * on the underlying operating system's event model. This has
- * numerous benefits including smaller footprint, better use of
- * resources, safer memory management, clearer program logic,
- * better performance, and fewer overall operating system threads
- * required. The down side however, is that care must be taken
- * (only) when constructing multi-threaded applications to use the
- * inter-thread communication mechanisms which this class provides
- * when required.
- * </p><p>
- * All SWT API methods which may only be called from the user-interface
- * thread are distinguished in their documentation by indicating that
- * they throw the "<code>ERROR_THREAD_INVALID_ACCESS</code>"
- * SWT exception.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Close, Dispose, Settings</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- * @see #syncExec
- * @see #asyncExec
- * @see #wake
- * @see #readAndDispatch
- * @see #sleep
- * @see Device#dispose
- * @see <a href="http://www.eclipse.org/swt/snippets/#display">Display snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Display extends Device {
-
- /* Motif Only Public Fields */
- public int xEvent;
- int lastSerial;
-
- /* Windows, Events and Callbacks */
- Callback windowCallback;
- int windowProc, shellHandle;
- static String APP_NAME = "SWT"; //$NON-NLS-1$
- static final String SHELL_HANDLE_KEY = "org.eclipse.swt.internal.motif.shellHandle"; //$NON-NLS-1$
- byte [] displayName, appName, appClass;
- Event [] eventQueue;
- XKeyEvent keyEvent = new XKeyEvent ();
- EventTable eventTable, filterTable;
-
- /* Widget Table */
- int freeSlot = 0;
- int [] indexTable, userData;
- Shell [] shellTable;
- Widget [] widgetTable;
- static final int GROW_SIZE = 1024;
-
- /* Focus */
- int focusEvent;
- boolean postFocusOut;
- Combo focusedCombo;
-
- /* Default Fonts, Colors, Insets, Widths and Heights. */
- Font defaultFont;
- Font listFont, textFont, buttonFont, labelFont;
- int buttonBackground, buttonForeground, buttonShadowThickness;
- int compositeBackground, compositeForeground;
- int compositeTopShadow, compositeBottomShadow, compositeBorder;
- int listBackground, listForeground, listSelect, textBackground, textForeground;
- int labelBackground, labelForeground;
- int scrolledInsetX, scrolledInsetY, scrolledMarginX, scrolledMarginY;
- int defaultBackground, defaultForeground;
- int textHighlightThickness, blinkRate;
-
- /* System Colors */
- XColor COLOR_WIDGET_DARK_SHADOW, COLOR_WIDGET_NORMAL_SHADOW, COLOR_WIDGET_LIGHT_SHADOW;
- XColor COLOR_WIDGET_HIGHLIGHT_SHADOW, COLOR_WIDGET_FOREGROUND, COLOR_WIDGET_BACKGROUND, COLOR_WIDGET_BORDER;
- XColor COLOR_LIST_FOREGROUND, COLOR_LIST_BACKGROUND, COLOR_LIST_SELECTION, COLOR_LIST_SELECTION_TEXT;
- Color COLOR_INFO_BACKGROUND;
-
- /* Popup Menus */
- Menu [] popups;
-
- /* System Images and Masks */
- int errorPixmap, infoPixmap, questionPixmap, warningPixmap, workingPixmap;
- int errorMask, infoMask, questionMask, warningMask, workingMask;
-
- /* System Cursors */
- Cursor [] cursors = new Cursor [SWT.CURSOR_HAND + 1];
-
- /* Initial Guesses for Shell Trimmings. */
- int leftBorderWidth = 2, rightBorderWidth = 2;
- int topBorderHeight = 2, bottomBorderHeight = 2;
- int leftResizeWidth = 3, rightResizeWidth = 3;
- int topResizeHeight = 3, bottomResizeHeight = 3;
- int leftTitleBorderWidth = 3, rightTitleBorderWidth = 2;
- int topTitleBorderHeight = 26, bottomTitleBorderHeight = 2;
- int leftTitleResizeWidth = 3, rightTitleResizeWidth = 3;
- int topTitleResizeHeight = 26, bottomTitleResizeHeight = 3;
- int leftTitleWidth = 0, rightTitleWidth = 0;
- int topTitleHeight = 23, bottomTitleHeight = 0;
- boolean ignoreTrim;
-
- /* Sync/Async Widget Communication */
- Synchronizer synchronizer = new Synchronizer (this);
- Thread thread;
-
- /* Display Shutdown */
- Runnable [] disposeList;
-
- /* System Tray */
- Tray tray;
-
- /* Timers */
- int [] timerIds;
- Runnable [] timerList;
- Callback timerCallback;
- int timerProc;
-
- /* Widget Timers */
- Callback windowTimerCallback;
- int windowTimerProc;
-
- /* Key Mappings. */
- static int [] [] KeyTable = {
-
- /* Keyboard and Mouse Masks */
- {OS.XK_Alt_L, SWT.ALT},
- {OS.XK_Alt_R, SWT.ALT},
- {OS.XK_Meta_L, SWT.ALT},
- {OS.XK_Meta_R, SWT.ALT},
- {OS.XK_Shift_L, SWT.SHIFT},
- {OS.XK_Shift_R, SWT.SHIFT},
- {OS.XK_Control_L, SWT.CONTROL},
- {OS.XK_Control_R, SWT.CONTROL},
-// {OS.XP_????, SWT.COMMAND},
-// {OS.XP_????, SWT.COMMAND},
-
- /* Non-Numeric Keypad Keys */
- {OS.XK_Up, SWT.ARROW_UP},
- {OS.XK_KP_Up, SWT.ARROW_UP},
- {OS.XK_Down, SWT.ARROW_DOWN},
- {OS.XK_KP_Down, SWT.ARROW_DOWN},
- {OS.XK_Left, SWT.ARROW_LEFT},
- {OS.XK_KP_Left, SWT.ARROW_LEFT},
- {OS.XK_Right, SWT.ARROW_RIGHT},
- {OS.XK_KP_Right, SWT.ARROW_RIGHT},
- {OS.XK_Page_Up, SWT.PAGE_UP},
- {OS.XK_KP_Page_Up, SWT.PAGE_UP},
- {OS.XK_Page_Down, SWT.PAGE_DOWN},
- {OS.XK_KP_Page_Down,SWT.PAGE_DOWN},
- {OS.XK_Home, SWT.HOME},
- {OS.XK_KP_Home, SWT.HOME},
- {OS.XK_End, SWT.END},
- {OS.XK_KP_End, SWT.END},
- {OS.XK_Insert, SWT.INSERT},
- {OS.XK_KP_Insert, SWT.INSERT},
-
- /* Virtual and Ascii Keys */
- {OS.XK_BackSpace, SWT.BS},
- {OS.XK_Return, SWT.CR},
- {OS.XK_Delete, SWT.DEL},
- {OS.XK_KP_Delete, SWT.DEL},
- {OS.XK_Escape, SWT.ESC},
- {OS.XK_Linefeed, SWT.LF},
- {OS.XK_Tab, SWT.TAB},
- {OS.XK_ISO_Left_Tab,SWT.TAB},
-
- /* Functions Keys */
- {OS.XK_F1, SWT.F1},
- {OS.XK_F2, SWT.F2},
- {OS.XK_F3, SWT.F3},
- {OS.XK_F4, SWT.F4},
- {OS.XK_F5, SWT.F5},
- {OS.XK_F6, SWT.F6},
- {OS.XK_F7, SWT.F7},
- {OS.XK_F8, SWT.F8},
- {OS.XK_F9, SWT.F9},
- {OS.XK_F10, SWT.F10},
- {OS.XK_F11, SWT.F11},
- {OS.XK_F12, SWT.F12},
- {OS.XK_F13, SWT.F13},
- {OS.XK_F14, SWT.F14},
- {OS.XK_F15, SWT.F15},
-
- /* Numeric Keypad Keys */
- {OS.XK_KP_Multiply, SWT.KEYPAD_MULTIPLY},
- {OS.XK_KP_Add, SWT.KEYPAD_ADD},
- {OS.XK_KP_Enter, SWT.KEYPAD_CR},
- {OS.XK_KP_Subtract, SWT.KEYPAD_SUBTRACT},
- {OS.XK_KP_Decimal, SWT.KEYPAD_DECIMAL},
- {OS.XK_KP_Divide, SWT.KEYPAD_DIVIDE},
- {OS.XK_KP_0, SWT.KEYPAD_0},
- {OS.XK_KP_1, SWT.KEYPAD_1},
- {OS.XK_KP_2, SWT.KEYPAD_2},
- {OS.XK_KP_3, SWT.KEYPAD_3},
- {OS.XK_KP_4, SWT.KEYPAD_4},
- {OS.XK_KP_5, SWT.KEYPAD_5},
- {OS.XK_KP_6, SWT.KEYPAD_6},
- {OS.XK_KP_7, SWT.KEYPAD_7},
- {OS.XK_KP_8, SWT.KEYPAD_8},
- {OS.XK_KP_9, SWT.KEYPAD_9},
- {OS.XK_KP_Equal, SWT.KEYPAD_EQUAL},
-
- /* Other keys */
- {OS.XK_Caps_Lock, SWT.CAPS_LOCK},
- {OS.XK_Num_Lock, SWT.NUM_LOCK},
- {OS.XK_Scroll_Lock, SWT.SCROLL_LOCK},
- {OS.XK_Pause, SWT.PAUSE},
- {OS.XK_Break, SWT.BREAK},
- {OS.XK_Print, SWT.PRINT_SCREEN},
- {OS.XK_Help, SWT.HELP},
-
- };
- static String numLock;
-
- /* Multiple Displays. */
- static Display Default;
- static Display [] Displays = new Display [4];
-
- /* Double Click */
- int lastTime, lastButton, clickCount = 1;
-
- /* Current caret */
- Caret currentCaret;
- Callback caretCallback;
- int caretID, caretProc;
-
- /* Workaround for GP when disposing a display */
- static boolean DisplayDisposed;
-
- /* Package Name */
- static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets."; //$NON-NLS-1$
- /*
- * This code is intentionally commented. In order
- * to support CLDC, .class cannot be used because
- * it does not compile on some Java compilers when
- * they are targeted for CLDC.
- */
-// static {
-// String name = Display.class.getName ();
-// int index = name.lastIndexOf ('.');
-// PACKAGE_PREFIX = name.substring (0, index + 1);
-// }
-
- /* Mouse Hover */
- Callback mouseHoverCallback;
- int mouseHoverID, mouseHoverProc;
- int mouseHoverHandle, toolTipHandle;
-
- /* Xt Translations */
- int dragTranslations;
- int arrowTranslations, tabTranslations;
-
- /* Check Expose Proc */
- Callback checkExposeCallback;
- int checkExposeProc, exposeCount, lastExpose;
- XExposeEvent xExposeEvent = new XExposeEvent ();
-
- /* Check Resize Proc */
- Callback checkResizeCallback;
- int checkResizeProc, resizeWidth, resizeHeight, resizeCount, resizeWindow;
- XConfigureEvent xConfigureEvent = new XConfigureEvent ();
-
- /* Focus Proc */
- Callback focusCallback;
- int focusProc;
-
- /* Wake and Sleep */
- Callback wakeCallback;
- int wakeProc, read_fd, write_fd, inputID;
- byte [] wake_buffer = new byte [1];
- int [] timeout = new int [2];
- byte [] fd_set;
-
- /* Display Data */
- Object data;
- String [] keys;
- Object [] values;
-
- /*
- * TEMPORARY CODE. Install the runnable that
- * gets the current display. This code will
- * be removed in the future.
- */
- static {
- DeviceFinder = new Runnable () {
- public void run () {
- Device device = getCurrent ();
- if (device == null) {
- device = getDefault ();
- }
- setDevice (device);
- }
- };
- }
-
-/*
-* TEMPORARY CODE.
-*/
-static void setDevice (Device device) {
- CurrentDevice = device;
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * Note: The resulting display is marked as the <em>current</em>
- * display. If this is the first display which has been
- * constructed since the application started, it is also
- * marked as the <em>default</em> display.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if called from a thread that already created an existing display</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see #getCurrent
- * @see #getDefault
- * @see Widget#checkSubclass
- * @see Shell
- */
-public Display () {
- this (null);
-}
-/**
- * Constructs a new instance of this class using the parameter.
- *
- * @param data the device data
- */
-public Display (DeviceData data) {
- super (checkNull (data));
-}
-static DeviceData checkNull (DeviceData data) {
- if (data == null) data = new DeviceData ();
- if (data.application_name == null) {
- data.application_name = APP_NAME;
- }
- if (data.application_class == null) {
- data.application_class = APP_NAME;
- }
- return data;
-}
-protected void checkDevice () {
- if (thread == null) error (SWT.ERROR_WIDGET_DISPOSED);
- if (thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
-}
-void addMouseHoverTimeOut (int handle) {
- if (mouseHoverID != 0) OS.XtRemoveTimeOut (mouseHoverID);
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- mouseHoverID = OS.XtAppAddTimeOut (xtContext, 400, mouseHoverProc, handle);
- mouseHoverHandle = handle;
-}
-void addWidget (int handle, Widget widget) {
- if (handle == 0) return;
- if (OS.XtIsSubclass (handle, OS.shellWidgetClass ())) {
- for (int i=0; i<shellTable.length; i++) {
- if (shellTable [i] == null) {
- shellTable [i] = (Shell) widget;
- return;
- }
- }
- Shell [] newShells = new Shell [shellTable.length + GROW_SIZE / 8];
- System.arraycopy (shellTable, 0, newShells, 0, shellTable.length);
- newShells [shellTable.length] = (Shell) widget;
- shellTable = newShells;
- return;
- }
- if (freeSlot == -1) {
- int length = (freeSlot = indexTable.length) + GROW_SIZE;
- int [] newIndexTable = new int [length];
- Widget [] newWidgetTable = new Widget [length];
- System.arraycopy (indexTable, 0, newIndexTable, 0, freeSlot);
- System.arraycopy (widgetTable, 0, newWidgetTable, 0, freeSlot);
- for (int i=freeSlot; i<length-1; i++) {
- newIndexTable [i] = i + 1;
- }
- newIndexTable [length - 1] = -1;
- indexTable = newIndexTable;
- widgetTable = newWidgetTable;
- }
- userData [1] = freeSlot + 1;
- OS.XtSetValues (handle, userData, userData.length / 2);
- int oldSlot = freeSlot;
- freeSlot = indexTable [oldSlot];
- indexTable [oldSlot] = -2;
- widgetTable [oldSlot] = widget;
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs anywhere
- * in a widget. The event type is one of the event constants
- * defined in class <code>SWT</code>. When the event does occur,
- * the listener is notified by sending it the <code>handleEvent()</code>
- * message.
- * <p>
- * Setting the type of an event to <code>SWT.None</code> from
- * within the <code>handleEvent()</code> method can be used to
- * change the event type and stop subsequent Java listeners
- * from running. Because event filters run before other listeners,
- * event filters can both block other listeners and set arbitrary
- * fields within an event. For this reason, event filters are both
- * powerful and dangerous. They should generally be avoided for
- * performance, debugging and code maintenance reasons.
- * </p>
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #removeFilter
- * @see #removeListener
- *
- * @since 3.0
- */
-public void addFilter (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (filterTable == null) filterTable = new EventTable ();
- filterTable.hook (eventType, listener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- * When the event does occur in the display, the listener is notified by
- * sending it the <code>handleEvent()</code> message.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #removeListener
- *
- * @since 2.0
- */
-public void addListener (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) eventTable = new EventTable ();
- eventTable.hook (eventType, listener);
-}
-void addPopup (Menu menu) {
- if (popups == null) popups = new Menu [4];
- int length = popups.length;
- for (int i=0; i<length; i++) {
- if (popups [i] == menu) return;
- }
- int index = 0;
- while (index < length) {
- if (popups [index] == null) break;
- index++;
- }
- if (index == length) {
- Menu [] newPopups = new Menu [length + 4];
- System.arraycopy (popups, 0, newPopups, 0, length);
- popups = newPopups;
- }
- popups [index] = menu;
-}
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread at the next
- * reasonable opportunity. The caller of this method continues
- * to run in parallel, and is not notified when the
- * runnable has completed. Specifying <code>null</code> as the
- * runnable simply wakes the user-interface thread when run.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param runnable code to run on the user-interface thread or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #syncExec
- */
-public void asyncExec (Runnable runnable) {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- synchronizer.asyncExec (runnable);
- }
-}
-/**
- * Causes the system hardware to emit a short sound
- * (if it supports this capability).
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void beep () {
- checkDevice ();
- OS.XBell (xDisplay, 100);
- OS.XFlush (xDisplay);
-}
-int caretProc (int clientData, int id) {
- caretID = 0;
- if (currentCaret == null) return 0;
- if (currentCaret.blinkCaret ()) {
- int blinkRate = currentCaret.blinkRate;
- if (blinkRate == 0) return 0;
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- caretID = OS.XtAppAddTimeOut (xtContext, blinkRate, caretProc, 0);
- } else {
- currentCaret = null;
- }
- return 0;
-}
-
-int checkExposeProc (int display, int event, int window) {
- OS.memmove (xExposeEvent, event, XExposeEvent.sizeof);
- if (xExposeEvent.window != window) return 0;
- switch (xExposeEvent.type) {
- case OS.Expose:
- case OS.GraphicsExpose:
- exposeCount++;
- lastExpose = event;
- xExposeEvent.count = 1;
- OS.memmove (event, xExposeEvent, XExposeEvent.sizeof);
- break;
- }
- return 0;
-}
-int checkResizeProc (int display, int event, int arg) {
- OS.memmove (xConfigureEvent, event, XConfigureEvent.sizeof);
- if (xConfigureEvent.window != resizeWindow) return 0;
- switch (xConfigureEvent.type) {
- case OS.ConfigureNotify:
- int width = xConfigureEvent.width;
- int height = xConfigureEvent.height;
- if (width != resizeWidth || height != resizeHeight) {
- resizeCount++;
- }
- break;
- }
- return 0;
-}
-static void checkDisplay (Thread thread, boolean multiple) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] != null) {
- if (!multiple) SWT.error (SWT.ERROR_NOT_IMPLEMENTED, null, " [multiple displays]"); //$NON-NLS-1$
- if (Displays [i].thread == thread) SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- }
- }
-}
-/**
- * Checks that this class can be subclassed.
- * <p>
- * IMPORTANT: See the comment in <code>Widget.checkSubclass()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- */
-protected void checkSubclass () {
- if (!Display.isValidClass (getClass ())) {
- error (SWT.ERROR_INVALID_SUBCLASS);
- }
-}
-/**
- * Requests that the connection between SWT and the underlying
- * operating system be closed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Device#dispose
- *
- * @since 2.0
- */
-public void close () {
- checkDevice ();
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- if (event.doit) dispose ();
-}
-String convertToLf(String text) {
- char Cr = '\r';
- char Lf = '\n';
- int length = text.length ();
- if (length == 0) return text;
-
- /* Check for an LF or CR/LF. Assume the rest of the string
- * is formated that way. This will not work if the string
- * contains mixed delimiters. */
- int i = text.indexOf (Lf, 0);
- if (i == -1 || i == 0) return text;
- if (text.charAt (i - 1) != Cr) return text;
-
- /* The string is formatted with CR/LF.
- * Create a new string with the LF line delimiter. */
- i = 0;
- StringBuffer result = new StringBuffer ();
- while (i < length) {
- int j = text.indexOf (Cr, i);
- if (j == -1) j = length;
- String s = text.substring (i, j);
- result.append (s);
- i = j + 2;
- result.append (Lf);
- }
- return result.toString ();
-}
-/**
- * Creates the device in the operating system. If the device
- * does not have a handle, this method may do nothing depending
- * on the device.
- * <p>
- * This method is called before <code>init</code>.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #init
- */
-protected void create (DeviceData data) {
- checkSubclass ();
- checkDisplay (thread = Thread.currentThread (), true);
- createDisplay (data);
- register (this);
- if (Default == null) Default = this;
-}
-void createDisplay (DeviceData data) {
- /* Create the AppContext */
- xEvent = OS.XtMalloc (XEvent.sizeof);
-
- int dpy = 0;
- if (Default == null) {
- int xtContext = OS.__XtDefaultAppContext ();
- int [] dpy_return = new int [1];
- int [] num_dpy_return = new int [1];
- OS.XtGetDisplays (xtContext, dpy_return, num_dpy_return);
- if (num_dpy_return [0] > 0) {
- OS.memmove (dpy_return, dpy_return [0], 4);
- dpy = dpy_return [0];
- }
- }
-
- if (dpy != 0) {
- xDisplay = dpy;
- } else {
- int [] argc = new int [] {0};
- int xtContext = OS.XtCreateApplicationContext ();
- OS.XtSetLanguageProc (xtContext, 0, 0);
-
- /*
- * Feature in Linux. On some DBCS Linux platforms, the default
- * font is not be properly initialized to contain a font set.
- * This causes the IME to fail. The fix is to set a fallback
- * resource with an appropriated font to ensure a font set is
- * found.
- */
- int ptr1 = 0, ptr2 = 0;
- if (OS.IsLinux && OS.IsDBLocale) {
- String resource = "*fontList: -*-*-medium-r-*-*-*-120-*-*-*-*-*-*:"; //$NON-NLS-1$
- byte [] buffer = Converter.wcsToMbcs (null, resource, true);
- ptr1 = OS.XtMalloc (buffer.length);
- if (ptr1 != 0) OS.memmove (ptr1, buffer, buffer.length);
- int [] spec = new int[]{ptr1, 0};
- ptr2 = OS.XtMalloc (spec.length * 4);
- if (ptr2 != 0)OS.memmove (ptr2, spec, spec.length * 4);
- OS.XtAppSetFallbackResources(xtContext, ptr2);
- }
-
- /* Compute the display name, application name and class */
- String display_name = null;
- String application_name = APP_NAME;
- String application_class = APP_NAME;
- if (data != null) {
- if (data.display_name != null) display_name = data.display_name;
- if (data.application_name != null) application_name = data.application_name;
- if (data.application_class != null) application_class = data.application_class;
- }
- /* Use the character encoding for the default locale */
- if (display_name != null) displayName = Converter.wcsToMbcs (null, display_name, true);
- if (application_name != null) appName = Converter.wcsToMbcs (null, application_name, true);
- if (application_class != null) appClass = Converter.wcsToMbcs (null, application_class, true);
-
- /* Create the XDisplay */
- xDisplay = OS.XtOpenDisplay (xtContext, displayName, appName, appClass, 0, 0, argc, 0);
- DisplayDisposed = false;
-
- if (ptr2 != 0) {
- OS.XtAppSetFallbackResources (xtContext, 0);
- OS.XtFree (ptr2);
- }
- if (ptr1 != 0) OS.XtFree (ptr1);
- }
-}
-int createMask (int pixmap) {
- if (pixmap == 0) return 0;
- int [] unused = new int [1]; int [] width = new int [1]; int [] height = new int [1];
- OS.XGetGeometry (xDisplay, pixmap, unused, unused, unused, width, height, unused, unused);
- int mask = OS.XCreatePixmap (xDisplay, pixmap, width [0], height [0], 1);
- int gc = OS.XCreateGC (xDisplay, mask, 0, null);
- if (OS.IsSunOS) {
- OS.XSetBackground (xDisplay, gc, 0);
- OS.XSetForeground (xDisplay, gc, 1);
- }
- OS.XCopyPlane (xDisplay, pixmap, mask, gc, 0, 0, width [0], height [0], 0, 0, 1);
- OS.XFreeGC (xDisplay, gc);
- return mask;
-}
-int createPixmap (String name) {
- int screen = OS.XDefaultScreenOfDisplay (xDisplay);
- int fgPixel = OS.XBlackPixel (xDisplay, OS.XDefaultScreen (xDisplay));
- int bgPixel = OS.XWhitePixel (xDisplay, OS.XDefaultScreen (xDisplay));
- byte[] buffer = Converter.wcsToMbcs (null, name, true);
- int pixmap = OS.XmGetPixmap (screen, buffer, fgPixel, bgPixel);
- if (pixmap == OS.XmUNSPECIFIED_PIXMAP) {
- buffer = Converter.wcsToMbcs (null, "default_" + name, true); //$NON-NLS-1$
- pixmap = OS.XmGetPixmap (screen, buffer, fgPixel, bgPixel);
- if (pixmap == OS.XmUNSPECIFIED_PIXMAP) {
- if (OS.IsSunOS) {
- buffer = Converter.wcsToMbcs (null, "/usr/dt/share/include/bitmaps/" + name, true); //$NON-NLS-1$
- pixmap = OS.XmGetPixmap (screen, buffer, fgPixel, bgPixel);
- if (pixmap == OS.XmUNSPECIFIED_PIXMAP) pixmap = 0;
- } else {
- pixmap = 0;
- }
- }
- }
- return pixmap;
-}
-static void deregister (Display display) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (display == Displays [i]) Displays [i] = null;
- }
- }
-}
-/**
- * Destroys the device in the operating system and releases
- * the device's handle. If the device does not have a handle,
- * this method may do nothing depending on the device.
- * <p>
- * This method is called after <code>release</code>.
- * </p>
- * @see Device#dispose
- * @see #release
- */
-protected void destroy () {
- if (this == Default) Default = null;
- deregister (this);
- destroyDisplay ();
-}
-void destroyDisplay () {
- /*
- * Bug in Motif. For some reason, XtAppCreateShell GP's when called
- * after an application context has been destroyed. The fix is to
- * destroy the default XmDisplay associated with the X Display for
- * the application context. The following code fragment GP's without
- * this work around:
- *
- * OS.XtToolkitInitialize();
- * int xContext = OS.XtCreateApplicationContext();
- * int xDisplay = OS.XtOpenDisplay(xContext, null, null, null, 0, 0, new int[1], 0);
- * OS.XtAppCreateShell(null, null, OS.topLevelShellWidgetClass(), xDisplay, null, 0);
- * //OS.XtDestroyWidget (OS.XmGetXmDisplay (xDisplay));
- * OS.XtDestroyApplicationContext(xContext);
- * xContext = OS.XtCreateApplicationContext();
- * xDisplay = OS.XtOpenDisplay(xContext, null, null, null, 0, 0, new int[1], 0);
- * OS.XtAppCreateShell(null, null, OS.topLevelShellWidgetClass(), xDisplay, null, 0);
- * OS.XtDestroyApplicationContext(xContext);
- */
- if (!OS.IsSunOS) {
- OS.XtDestroyWidget (OS.XmGetXmDisplay (xDisplay));
- }
-
- /*
- * Destroy AppContext (this destroys the display)
- */
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- OS.XtDestroyApplicationContext (xtContext);
- DisplayDisposed = true;
-}
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread just before the
- * receiver is disposed. Specifying a <code>null</code> runnable
- * is ignored.
- *
- * @param runnable code to run at dispose time.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void disposeExec (Runnable runnable) {
- checkDevice ();
- if (disposeList == null) disposeList = new Runnable [4];
- for (int i=0; i<disposeList.length; i++) {
- if (disposeList [i] == null) {
- disposeList [i] = runnable;
- return;
- }
- }
- Runnable [] newDisposeList = new Runnable [disposeList.length + 4];
- System.arraycopy (disposeList, 0, newDisposeList, 0, disposeList.length);
- newDisposeList [disposeList.length] = runnable;
- disposeList = newDisposeList;
-}
-void error (int code) {
- SWT.error(code);
-}
-boolean filterEvent (Event event) {
- if (filterTable != null) filterTable.sendEvent (event);
- return false;
-}
-boolean filters (int eventType) {
- if (filterTable == null) return false;
- return filterTable.hooks (eventType);
-}
-boolean filterEvent (int event) {
-
- /* Check the event and find the widget */
- OS.memmove (keyEvent, event, XKeyEvent.sizeof);
- if (keyEvent.type != OS.KeyPress) return false;
- if (keyEvent.keycode == 0) return false;
- int xWindow = keyEvent.window;
- if (xWindow == 0) return false;
- int handle = OS.XtWindowToWidget (xDisplay, xWindow);
- if (handle == 0) return false;
- handle = OS.XmGetFocusWidget (handle);
- if (handle == 0) return false;
- Widget widget = getWidget (handle);
- if (widget == null) return false;
-
- /* Get the unaffected character and keysym */
- char key = 0;
- byte [] buffer = new byte [5];
- int [] keysym = new int [1];
- int oldState = keyEvent.state;
- keyEvent.state = 0;
- int length = OS.XLookupString (keyEvent, buffer, buffer.length, keysym, null);
- keyEvent.state = oldState;
- fixKey (keysym, buffer, 0);
- if (length != 0) {
- char [] result = Converter.mbcsToWcs (null, buffer);
- if (result.length != 0) key = result [0];
- }
- keysym [0] &= 0xFFFF;
-
- /*
- * Bug in AIX. If XFilterEvent() is called for every key event, accelerators
- * do not work. XFilterEvent() is needed on AIX to invoke the default button.
- * The fix is to call XFilterEvent() only for return keys. This means that an
- * accelerator that is only a return key will not work.
- */
- if (keysym [0] == OS.XK_Return || keysym [0] == OS.XK_KP_Enter) {
- /*
- * Bug in Linux. If XFilter() is called more than once for the same
- * event, it causes an infinite loop. The fix to remember the serial
- * number and never call XFilterEvent() twice for the same event.
- */
- if (keyEvent.serial != lastSerial) {
- if (OS.XFilterEvent (event, OS.XtWindow (handle))) return true;
- lastSerial = keyEvent.serial;
- }
- }
-
- /*
- * Bug in Solaris. When accelerators are set more
- * than once in the same menu bar, the time it takes
- * to set the accelerator increases exponentially.
- * The fix is to implement our own accelerator table
- * on Solaris.
- */
- if (OS.IsSunOS) {
- /* Ignore modifiers. */
- switch (keysym [0]) {
- case OS.XK_Control_L:
- case OS.XK_Control_R:
- case OS.XK_Alt_L:
- case OS.XK_Alt_R:
- case OS.XK_Meta_L:
- case OS.XK_Meta_R:
- case OS.XK_Shift_L:
- case OS.XK_Shift_R: break;
- default:
- if (widget.translateAccelerator (key, keysym [0], keyEvent, true)) {
- return true;
- }
- }
- }
-
- /* Check for a mnemonic key */
- if (key != 0) {
- if (widget.translateMnemonic (key, keysym [0], keyEvent)) return true;
- }
-
- /* Check for a traversal key */
- switch (keysym [0]) {
- case OS.XK_Escape:
- case OS.XK_Tab:
- case OS.XK_KP_Enter:
- case OS.XK_Return:
- case OS.XK_Up:
- case OS.XK_Down:
- case OS.XK_Left:
- case OS.XK_Right:
- case OS.XK_Page_Up:
- case OS.XK_Page_Down:
- /*
- * If a traversal key has been assigned as an accelerator,
- * allow the accelerator to run, not the traversal key.
- */
- if (!OS.IsSunOS) {
- if (widget.translateAccelerator (key, keysym [0], keyEvent, true)) {
- return true;
- }
- }
- if (widget.translateTraversal (keysym [0], keyEvent)) return true;
- }
-
- /* Answer false because the event was not processed */
- return false;
-}
-/**
- * Given the operating system handle for a widget, returns
- * the instance of the <code>Widget</code> subclass which
- * represents it in the currently running application, if
- * such exists, or null if no matching widget can be found.
- * <p>
- * <b>IMPORTANT:</b> This method should not be called from
- * application code. The arguments are platform-specific.
- * </p>
- *
- * @param handle the handle for the widget
- * @return the SWT widget that the handle represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Widget findWidget (int handle) {
- checkDevice ();
- return getWidget (handle);
-}
-/**
- * Given the operating system handle for a widget,
- * and widget-specific id, returns the instance of
- * the <code>Widget</code> subclass which represents
- * the handle/id pair in the currently running application,
- * if such exists, or null if no matching widget can be found.
- * <p>
- * <b>IMPORTANT:</b> This method should not be called from
- * application code. The arguments are platform-specific.
- * </p>
- *
- * @param handle the handle for the widget
- * @param id the id for the subwidget (usually an item)
- * @return the SWT widget that the handle/id pair represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public Widget findWidget (int handle, int id) {
- checkDevice ();
- return null;
-}
-/**
- * Given a widget and a widget-specific id, returns the
- * instance of the <code>Widget</code> subclass which represents
- * the widget/id pair in the currently running application,
- * if such exists, or null if no matching widget can be found.
- *
- * @param widget the widget
- * @param id the id for the subwidget (usually an item)
- * @return the SWT subwidget (usually an item) that the widget/id pair represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.3
- */
-public Widget findWidget (Widget widget, int id) {
- checkDevice ();
- return null;
-}
-boolean fixKey (int[] keysym, byte[] buffer, int state) {
- /*
- * Bug in MOTIF. On Solaris only, XK_F11 and XK_F12 are not
- * translated correctly by XLookupString(). They are mapped
- * to SunXK_F36 and SunXK_F37 respectively. The fix is to
- * look for these values (and others) and explicitly correct
- * them.
- */
- if (OS.IsSunOS && keysym [0] != 0) {
- switch (keysym [0]) {
- case OS.SunXK_F36:
- keysym [0] = OS.XK_F11;
- buffer [0] = 0;
- break;
- case OS.SunXK_F37:
- keysym [0] = OS.XK_F12;
- buffer [0] = 0;
- break;
- case OS.XK_R1: keysym [0] = OS.XK_Pause; break;
- case OS.XK_R2: keysym [0] = OS.XK_Print; break;
- case OS.XK_R3: keysym [0] = OS.XK_Scroll_Lock; break;
- case OS.XK_R4: keysym [0] = OS.XK_KP_Subtract; break;
- case OS.XK_R5: keysym [0] = OS.XK_KP_Divide; break;
- case OS.XK_R6: keysym [0] = OS.XK_KP_Multiply; break;
- case OS.XK_R7: keysym [0] = OS.XK_KP_Home; break;
- case OS.XK_R9: keysym [0] = OS.XK_KP_Page_Up; break;
- case OS.XK_R13: keysym [0] = OS.XK_KP_End; break;
- case OS.XK_R15: keysym [0] = OS.XK_KP_Page_Down; break;
- }
- /*
- * Bug in MOTIF. On Solaris only, there is garbage in the
- * high 16-bits for Keysyms such as XK_Down. Since Keysyms
- * must be 16-bits to fit into a Character, mask away the
- * high 16-bits on all platforms.
- */
- keysym [0] &= 0xFFFF;
- }
-
- /*
- * Bug in Motif. On HP-UX only, Shift+F9, Shift+F10, Shift+F11
- * and Shift+F12 are not translated correctly by XLookupString().
- * The fix is to look for these values (and others) explicitly
- * and correct them.
- */
- if (OS.IsHPUX && keysym [0] != 0) {
- switch (keysym [0]) {
- case OS.XK_KP_F1: keysym [0] = OS.XK_F9; break;
- case OS.XK_KP_F2: keysym [0] = OS.XK_F10; break;
- case OS.XK_KP_F3: keysym [0] = OS.XK_F11; break;
- case OS.XK_KP_F4: keysym [0] = OS.XK_F12; break;
- case OS.hpXK_BackTab: keysym [0] = OS.XK_ISO_Left_Tab; break;
- }
- }
-
- /*
- * Bug in Motif. There are some keycodes for which
- * XLookupString() does not translate the character.
- * Some of examples are Shift+Tab and Ctrl+Space.
- */
- switch (keysym [0]) {
- case OS.XK_KP_Delete: buffer [0] = 0x7f; break;
- case OS.XK_ISO_Left_Tab: buffer [0] = '\t'; break;
- case OS.XK_space: buffer [0] = ' '; break;
- }
-
- /*
- * Feature in MOTIF. For some reason, XLookupString() fails
- * to translate both the keysym and the character when the
- * control key is down. For example, Ctrl+2 has the correct
- * keysym value (50) but no character value, while Ctrl+/ has
- * the keysym value (2F) but an invalid character value
- * (1F). It seems that Motif is applying the algorithm to
- * convert a character to a control character for characters
- * that are not valid control characters. The fix is to test
- * for 7-bit ASCII keysym values that fall outside of the
- * the valid control character range and use the keysym value
- * as the character, not the incorrect value that XLookupString()
- * returns. Even though lower case values are not strictly
- * valid control characters, they are included in the range.
- *
- * Some other cases include Ctrl+3..Ctr+8, Ctrl+[.
- */
- boolean isNull = false;
- int key = keysym [0];
- if ((state & OS.ControlMask) != 0) {
- if (0 <= key && key <= 0x7F) {
- if ('a' <= key && key <= 'z') key -= 'a' - 'A';
- if (!(64 <= key && key <= 95)) buffer [0] = (byte) key;
- isNull = key == '@' && buffer [0] == 0;
- } else {
- switch (keysym [0]) {
- case OS.XK_KP_0: buffer [0] = '0'; break;
- case OS.XK_KP_1: buffer [0] = '1'; break;
- case OS.XK_KP_2: buffer [0] = '2'; break;
- case OS.XK_KP_3: buffer [0] = '3'; break;
- case OS.XK_KP_4: buffer [0] = '4'; break;
- case OS.XK_KP_5: buffer [0] = '5'; break;
- case OS.XK_KP_6: buffer [0] = '6'; break;
- case OS.XK_KP_7: buffer [0] = '7'; break;
- case OS.XK_KP_8: buffer [0] = '8'; break;
- case OS.XK_KP_9: buffer [0] = '9'; break;
- }
- }
- }
- return isNull;
-}
-int focusProc (int w, int client_data, int call_data, int continue_to_dispatch) {
- Widget widget = getWidget (client_data);
- if (widget == null) return 0;
- return widget.focusProc (w, client_data, call_data, continue_to_dispatch);
-}
-/**
- * Returns the currently active <code>Shell</code>, or null
- * if no shell belonging to the currently running application
- * is active.
- *
- * @return the active shell or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Shell getActiveShell () {
- checkDevice ();
- int [] buffer1 = new int [1], buffer2 = new int [1];
- OS.XGetInputFocus (xDisplay, buffer1, buffer2);
- int xWindow = buffer1 [0];
- if (xWindow == 0) return null;
- int handle = OS.XtWindowToWidget (xDisplay, xWindow);
- if (handle == 0) return null;
- do {
- if (OS.XtIsSubclass (handle, OS.shellWidgetClass ())) {
- Widget widget = getWidget (handle);
- if (widget instanceof Shell) return (Shell) widget;
- return null;
- }
- } while ((handle = OS.XtParent (handle)) != 0);
- return null;
-}
-/**
- * Returns the display which the currently running thread is
- * the user-interface thread for, or null if the currently
- * running thread is not a user-interface thread for any display.
- *
- * @return the current display
- */
-public static Display getCurrent () {
- return findDisplay (Thread.currentThread ());
-}
-/**
- * Returns the display which the given thread is the
- * user-interface thread for, or null if the given thread
- * is not a user-interface thread for any display. Specifying
- * <code>null</code> as the thread will return <code>null</code>
- * for the display.
- *
- * @param thread the user-interface thread
- * @return the display for the given thread
- */
-public static Display findDisplay (Thread thread) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- Display display = Displays [i];
- if (display != null && display.thread == thread) {
- return display;
- }
- }
- return null;
- }
-}
-int getCaretBlinkTime () {
-// checkDevice ();
- return blinkRate;
-}
-/**
- * Returns the control which the on-screen pointer is currently
- * over top of, or null if it is not currently over one of the
- * controls built by the currently running application.
- *
- * @return the control under the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Control getCursorControl () {
- checkDevice ();
- int [] unused = new int [1], buffer = new int [1];
- int xWindow, xParent = OS.XDefaultRootWindow (xDisplay);
- do {
- if (OS.XQueryPointer (xDisplay, xParent, unused, buffer, unused, unused, unused, unused, unused) == 0) {
- return null;
- }
- if ((xWindow = buffer [0]) != 0) xParent = xWindow;
- } while (xWindow != 0);
- int handle = OS.XtWindowToWidget (xDisplay, xParent);
- if (handle == 0) return null;
- do {
- Widget widget = getWidget (handle);
- if (widget != null && widget instanceof Control) {
- Control control = (Control) widget;
- if (control.isEnabled ()) return control;
- }
- } while ((handle = OS.XtParent (handle)) != 0);
- return null;
-}
-/**
- * Returns the location of the on-screen pointer relative
- * to the top left corner of the screen.
- *
- * @return the cursor location
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point getCursorLocation () {
- checkDevice ();
- int window = OS.XDefaultRootWindow (xDisplay);
- int [] rootX = new int [1], rootY = new int [1], unused = new int [1];
- OS.XQueryPointer (xDisplay, window, unused, unused, rootX, rootY, unused, unused, unused);
- return new Point (rootX [0], rootY [0]);
-}
-/**
- * Returns an array containing the recommended cursor sizes.
- *
- * @return the array of cursor sizes
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public Point [] getCursorSizes() {
- checkDevice ();
- int xDrawable = OS.XDefaultRootWindow (xDisplay);
- int [] width_return = new int [1], height_return = new int [1];
- OS.XQueryBestCursor (xDisplay, xDrawable, 16, 16, width_return, height_return);
- Point pt = new Point (width_return [0], height_return [0]);
- OS.XQueryBestCursor (xDisplay, xDrawable, 32, 32, width_return, height_return);
- return pt.x == width_return [0] && pt.y == height_return [0] ?
- new Point [] {pt} : new Point [] {pt, new Point (width_return [0], height_return [0])};
-}
-/**
- * Returns the default display. One is created (making the
- * thread that invokes this method its user-interface thread)
- * if it did not already exist.
- *
- * @return the default display
- */
-public static Display getDefault () {
- synchronized (Device.class) {
- if (Default == null) Default = new Display ();
- return Default;
- }
-}
-/**
- * Returns the application defined property of the receiver
- * with the specified name, or null if it has not been set.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the display is disposed
- * of, it is the application's responsibility to provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param key the name of the property
- * @return the value of the property or null if it has not been set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setData(String, Object)
- * @see #disposeExec(Runnable)
- */
-public Object getData (String key) {
- checkDevice ();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (key.equals (SHELL_HANDLE_KEY)) {
- return new Integer(shellHandle);
- }
- if (keys == null) return null;
- for (int i=0; i<keys.length; i++) {
- if (keys [i].equals (key)) return values [i];
- }
- return null;
-}
-/**
- * Returns the application defined, display specific data
- * associated with the receiver, or null if it has not been
- * set. The <em>display specific data</em> is a single,
- * unnamed field that is stored with every display.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the display specific data needs to
- * be notified when the display is disposed of, it is the
- * application's responsibility to provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @return the display specific data
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setData(Object)
- * @see #disposeExec(Runnable)
- */
-public Object getData () {
- checkDevice ();
- return data;
-}
-/**
- * Returns the button dismissal alignment, one of <code>LEFT</code> or <code>RIGHT</code>.
- * The button dismissal alignment is the ordering that should be used when positioning the
- * default dismissal button for a dialog. For example, in a dialog that contains an OK and
- * CANCEL button, on platforms where the button dismissal alignment is <code>LEFT</code>, the
- * button ordering should be OK/CANCEL. When button dismissal alignment is <code>RIGHT</code>,
- * the button ordering should be CANCEL/OK.
- *
- * @return the button dismissal order
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1
- */
-public int getDismissalAlignment () {
- checkDevice ();
- return SWT.LEFT;
-}
-/**
- * Returns the longest duration, in milliseconds, between
- * two mouse button clicks that will be considered a
- * <em>double click</em> by the underlying operating system.
- *
- * @return the double click time
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getDoubleClickTime () {
- checkDevice ();
- return OS.XtGetMultiClickTime (xDisplay);
-}
-/**
- * Returns the control which currently has keyboard focus,
- * or null if keyboard events are not currently going to
- * any of the controls built by the currently running
- * application.
- *
- * @return the control under the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Control getFocusControl () {
- checkDevice ();
- int [] buffer1 = new int [1], buffer2 = new int [1];
- OS.XGetInputFocus (xDisplay, buffer1, buffer2);
- int xWindow = buffer1 [0];
- if (xWindow == 0) return null;
- int handle = OS.XtWindowToWidget (xDisplay, xWindow);
- if (handle == 0) return null;
- handle = OS.XmGetFocusWidget (handle);
- if (handle == 0) return null;
- do {
- Widget widget = getWidget (handle);
- if (widget != null && widget instanceof Control) {
- Control control = (Control) widget;
- return control.isEnabled () ? control : null;
- }
- } while ((handle = OS.XtParent (handle)) != 0);
- return null;
-}
-/**
- * Returns true when the high contrast mode is enabled.
- * Otherwise, false is returned.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @return the high contrast mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public boolean getHighContrast () {
- checkDevice ();
- return false;
-}
-/**
- * Returns the maximum allowed depth of icons on this display, in bits per pixel.
- * On some platforms, this may be different than the actual depth of the display.
- *
- * @return the maximum icon depth
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Device#getDepth
- */
-public int getIconDepth () {
- return getDepth ();
-}
-/**
- * Returns an array containing the recommended icon sizes.
- *
- * @return the array of icon sizes
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Decorations#setImages(Image[])
- *
- * @since 3.0
- */
-public Point [] getIconSizes () {
- checkDevice ();
- int w = OS.XDefaultRootWindow (xDisplay);
- int [] size_list_return = new int [1];
- int [] count_return = new int [1];
- Point min, max;
- int status = OS.XGetIconSizes (xDisplay, w, size_list_return, count_return);
- if (status != 0 && count_return [0] > 0) {
- XIconSize iconSize = new XIconSize ();
- OS.memmove (iconSize, size_list_return [0], XIconSize.sizeof);
- min = new Point (iconSize.min_width, iconSize.min_height);
- max = new Point (iconSize.max_width, iconSize.max_height);
- OS.XFree (size_list_return [0]);
- } else {
- min = new Point (16, 16);
- max = new Point (32, 32);
- }
- return new Point [] {min, max};
-}
-int getLastEventTime () {
-// checkDevice ();
- return OS.XtLastTimestampProcessed (xDisplay);
-}
-int getMessageCount () {
- return synchronizer.getMessageCount ();
-}
-/**
- * Returns an array of monitors attached to the device.
- *
- * @return the array of monitors
- *
- * @since 3.0
- */
-public Monitor [] getMonitors () {
- checkDevice ();
- Monitor [] monitors = null;
- if (OS.IsLinux) {
- boolean result = OS.XineramaIsActive (xDisplay);
- if (result) {
- int [] number = new int [1];
- int ptr = OS.XineramaQueryScreens (xDisplay, number);
- int monitorCount = number [0];
- if (ptr != 0 && monitorCount > 0) {
- monitors = new Monitor [monitorCount];
- XineramaScreenInfo info = new XineramaScreenInfo ();
- int address = ptr;
- for (int i = 0; i < monitorCount; i++) {
- Monitor monitor = new Monitor ();
- OS.memmove (info, address, XineramaScreenInfo.sizeof);
- address += XineramaScreenInfo.sizeof;
- monitor.handle = info.screen_number;
- monitor.x = info.x_org;
- monitor.y = info.y_org;
- monitor.width = info.width;
- monitor.height = info.height;
- monitor.clientX = monitor.x;
- monitor.clientY = monitor.y;
- monitor.clientWidth = monitor.width;
- monitor.clientHeight = monitor.height;
- monitors [i] = monitor;
- }
- }
- if (ptr != 0) OS.XFree (ptr);
- }
- }
- if (monitors == null) {
- /* No multimonitor support detected, default to one monitor */
- Monitor monitor = new Monitor ();
- Rectangle bounds = getBounds ();
- monitor.x = bounds.x;
- monitor.y = bounds.y;
- monitor.width = bounds.width;
- monitor.height = bounds.height;
- monitor.clientX = monitor.x;
- monitor.clientY = monitor.y;
- monitor.clientWidth = monitor.width;
- monitor.clientHeight = monitor.height;
- monitors = new Monitor [] { monitor };
- }
- return monitors;
-}
-/**
- * Returns the primary monitor for that device.
- *
- * @return the primary monitor
- *
- * @since 3.0
- */
-public Monitor getPrimaryMonitor () {
- checkDevice ();
- Monitor monitor = null;
- if (OS.IsLinux) {
- boolean result = OS.XineramaIsActive (xDisplay);
- if (result) {
- int[] number = new int [1];
- /* Assume first monitor returned is the primary one */
- int ptr = OS.XineramaQueryScreens (xDisplay, number);
- int monitorCount = number [0];
- if (ptr != 0 && monitorCount >= 1) {
- monitor = new Monitor ();
- XineramaScreenInfo info = new XineramaScreenInfo ();
- OS.memmove (info, ptr, XineramaScreenInfo.sizeof);
- monitor.handle = info.screen_number;
- monitor.x = info.x_org;
- monitor.y = info.y_org;
- monitor.width = info.width;
- monitor.height = info.height;
- monitor.clientX = monitor.x;
- monitor.clientY = monitor.y;
- monitor.clientWidth = monitor.width;
- monitor.clientHeight = monitor.height;
- }
- if (ptr != 0) OS.XFree (ptr);
- }
- }
- if (monitor == null) {
- /* No multimonitor support detected, default to one monitor */
- monitor = new Monitor ();
- Rectangle bounds = getBounds ();
- monitor.x = bounds.x;
- monitor.y = bounds.y;
- monitor.width = bounds.width;
- monitor.height = bounds.height;
- monitor.clientX = monitor.x;
- monitor.clientY = monitor.y;
- monitor.clientWidth = monitor.width;
- monitor.clientHeight = monitor.height;
- }
- return monitor;
-}
-/**
- * Returns a (possibly empty) array containing all shells which have
- * not been disposed and have the receiver as their display.
- *
- * @return the receiver's shells
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Shell [] getShells () {
- checkDevice ();
- int length = 0;
- for (int i=0; i<shellTable.length; i++) {
- if (shellTable [i] != null) length++;
- }
- int index = 0;
- Shell [] result = new Shell [length];
- for (int i=0; i<shellTable.length; i++) {
- Shell widget = shellTable [i];
- if (widget != null) result [index++] = widget;
- }
- return result;
-}
-/**
- * Gets the synchronizer used by the display.
- *
- * @return the receiver's synchronizer
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public Synchronizer getSynchronizer () {
- checkDevice ();
- return synchronizer;
-}
-/**
- * Returns the thread that has invoked <code>syncExec</code>
- * or null if no such runnable is currently being invoked by
- * the user-interface thread.
- * <p>
- * Note: If a runnable invoked by asyncExec is currently
- * running, this method will return null.
- * </p>
- *
- * @return the receiver's sync-interface thread
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Thread getSyncThread () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- return synchronizer.syncThread;
- }
-}
-/**
- * Returns the matching standard color for the given
- * constant, which should be one of the color constants
- * specified in class <code>SWT</code>. Any value other
- * than one of the SWT color constants which is passed
- * in will result in the color black. This color should
- * not be free'd because it was allocated by the system,
- * not the application.
- *
- * @param id the color constant
- * @return the matching color
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT
- */
-public Color getSystemColor (int id) {
- checkDevice ();
- XColor xColor = null;
- switch (id) {
- case SWT.COLOR_INFO_FOREGROUND: return super.getSystemColor (SWT.COLOR_BLACK);
- case SWT.COLOR_INFO_BACKGROUND: return COLOR_INFO_BACKGROUND;
- case SWT.COLOR_TITLE_FOREGROUND: return super.getSystemColor (SWT.COLOR_WHITE);
- case SWT.COLOR_TITLE_BACKGROUND: return super.getSystemColor (SWT.COLOR_DARK_BLUE);
- case SWT.COLOR_TITLE_BACKGROUND_GRADIENT: return super.getSystemColor (SWT.COLOR_BLUE);
- case SWT.COLOR_TITLE_INACTIVE_FOREGROUND: return super.getSystemColor (SWT.COLOR_BLACK);
- case SWT.COLOR_TITLE_INACTIVE_BACKGROUND: return super.getSystemColor (SWT.COLOR_DARK_GRAY);
- case SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT: return super.getSystemColor (SWT.COLOR_GRAY);
- case SWT.COLOR_WIDGET_DARK_SHADOW: xColor = COLOR_WIDGET_DARK_SHADOW; break;
- case SWT.COLOR_WIDGET_NORMAL_SHADOW: xColor = COLOR_WIDGET_NORMAL_SHADOW; break;
- case SWT.COLOR_WIDGET_LIGHT_SHADOW: xColor = COLOR_WIDGET_LIGHT_SHADOW; break;
- case SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: xColor = COLOR_WIDGET_HIGHLIGHT_SHADOW; break;
- case SWT.COLOR_WIDGET_BACKGROUND: xColor = COLOR_WIDGET_BACKGROUND; break;
- case SWT.COLOR_WIDGET_FOREGROUND: xColor = COLOR_WIDGET_FOREGROUND; break;
- case SWT.COLOR_WIDGET_BORDER: xColor = COLOR_WIDGET_BORDER; break;
- case SWT.COLOR_LIST_FOREGROUND: xColor = COLOR_LIST_FOREGROUND; break;
- case SWT.COLOR_LIST_BACKGROUND: xColor = COLOR_LIST_BACKGROUND; break;
- case SWT.COLOR_LIST_SELECTION: xColor = COLOR_LIST_SELECTION; break;
- case SWT.COLOR_LIST_SELECTION_TEXT: xColor = COLOR_LIST_SELECTION_TEXT; break;
- default:
- return super.getSystemColor (id);
- }
- if (xColor == null) return super.getSystemColor (SWT.COLOR_BLACK);
- return Color.motif_new (this, xColor);
-}
-/**
- * Returns the matching standard platform cursor for the given
- * constant, which should be one of the cursor constants
- * specified in class <code>SWT</code>. This cursor should
- * not be free'd because it was allocated by the system,
- * not the application. A value of <code>null</code> will
- * be returned if the supplied constant is not an SWT cursor
- * constant.
- *
- * @param id the SWT cursor constant
- * @return the corresponding cursor or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT#CURSOR_ARROW
- * @see SWT#CURSOR_WAIT
- * @see SWT#CURSOR_CROSS
- * @see SWT#CURSOR_APPSTARTING
- * @see SWT#CURSOR_HELP
- * @see SWT#CURSOR_SIZEALL
- * @see SWT#CURSOR_SIZENESW
- * @see SWT#CURSOR_SIZENS
- * @see SWT#CURSOR_SIZENWSE
- * @see SWT#CURSOR_SIZEWE
- * @see SWT#CURSOR_SIZEN
- * @see SWT#CURSOR_SIZES
- * @see SWT#CURSOR_SIZEE
- * @see SWT#CURSOR_SIZEW
- * @see SWT#CURSOR_SIZENE
- * @see SWT#CURSOR_SIZESE
- * @see SWT#CURSOR_SIZESW
- * @see SWT#CURSOR_SIZENW
- * @see SWT#CURSOR_UPARROW
- * @see SWT#CURSOR_IBEAM
- * @see SWT#CURSOR_NO
- * @see SWT#CURSOR_HAND
- *
- * @since 3.0
- */
-public Cursor getSystemCursor (int id) {
- checkDevice ();
- if (!(0 <= id && id < cursors.length)) return null;
- if (cursors [id] == null) {
- cursors [id] = new Cursor (this, id);
- }
- return cursors [id];
-}
-/**
- * Returns a reasonable font for applications to use.
- * On some platforms, this will match the "default font"
- * or "system font" if such can be found. This font
- * should not be free'd because it was allocated by the
- * system, not the application.
- * <p>
- * Typically, applications which want the default look
- * should simply not set the font on the widgets they
- * create. Widgets are always created with the correct
- * default font for the class of user-interface component
- * they represent.
- * </p>
- *
- * @return a font
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getSystemFont () {
- checkDevice ();
- return defaultFont;
-}
-/**
- * Returns the matching standard platform image for the given
- * constant, which should be one of the icon constants
- * specified in class <code>SWT</code>. This image should
- * not be free'd because it was allocated by the system,
- * not the application. A value of <code>null</code> will
- * be returned either if the supplied constant is not an
- * SWT icon constant or if the platform does not define an
- * image that corresponds to the constant.
- *
- * @param id the SWT icon constant
- * @return the corresponding image or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_QUESTION
- * @see SWT#ICON_WARNING
- * @see SWT#ICON_WORKING
- *
- * @since 3.0
- */
-public Image getSystemImage (int style) {
- checkDevice ();
- int imagePixmap = 0, maskPixmap = 0;
- switch (style) {
- case SWT.ICON_ERROR:
- if (errorPixmap == 0) {
- errorPixmap = createPixmap ("xm_error"); //$NON-NLS-1$
- errorMask = createMask (errorPixmap);
- }
- imagePixmap = errorPixmap;
- maskPixmap = errorMask;
- break;
- case SWT.ICON_INFORMATION:
- if (infoPixmap == 0) {
- infoPixmap = createPixmap ("xm_information"); //$NON-NLS-1$
- infoMask = createMask (infoPixmap);
- }
- imagePixmap = infoPixmap;
- maskPixmap = infoMask;
- break;
- case SWT.ICON_QUESTION:
- if (questionPixmap == 0) {
- questionPixmap = createPixmap ("xm_question"); //$NON-NLS-1$
- questionMask = createMask (questionPixmap);
- }
- imagePixmap = questionPixmap;
- maskPixmap = questionMask;
- break;
- case SWT.ICON_WARNING:
- if (warningPixmap == 0) {
- warningPixmap = createPixmap ("xm_warning"); //$NON-NLS-1$
- warningMask = createMask (warningPixmap);
- }
- imagePixmap = warningPixmap;
- maskPixmap = warningMask;
- break;
- case SWT.ICON_WORKING:
- if (workingPixmap == 0) {
- workingPixmap = createPixmap ("xm_working"); //$NON-NLS-1$
- workingMask = createMask (workingPixmap);
- }
- imagePixmap = workingPixmap;
- maskPixmap = workingMask;
- break;
- }
- if (imagePixmap == 0) return null;
- return Image.motif_new (this, SWT.ICON, imagePixmap, maskPixmap);
-}
-/**
- * Returns the single instance of the system tray or null
- * when there is no system tray available for the platform.
- *
- * @return the system tray or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public Tray getSystemTray () {
- checkDevice ();
- return null;
-}
-/**
- * Returns the user-interface thread for the receiver.
- *
- * @return the receiver's user-interface thread
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Thread getThread () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- return thread;
- }
-}
-Widget getWidget (int handle) {
- if (handle == 0) return null;
- if (OS.XtIsSubclass (handle, OS.shellWidgetClass ())) {
- for (int i=0; i<shellTable.length; i++) {
- Widget shell = shellTable [i];
- if (shell != null && shell.topHandle () == handle) return shell;
- }
- return null;
- }
- userData [1] = 0;
- OS.XtGetValues (handle, userData, userData.length / 2);
- if (userData [1] == 0) return null;
- int index = userData [1] - 1;
- if (0 <= index && index < widgetTable.length) return widgetTable [index];
- return null;
-}
-void hideToolTip () {
- if (toolTipHandle != 0) {
- int shellHandle = OS.XtParent(toolTipHandle);
- OS.XtDestroyWidget(shellHandle);
- }
- toolTipHandle = 0;
-}
-/**
- * Initializes any internal resources needed by the
- * device.
- * <p>
- * This method is called after <code>create</code>.
- * </p>
- *
- * @see #create
- */
-protected void init () {
- super.init ();
- initializeDisplay ();
- initializeButton ();
- initializeComposite ();
- initializeDialog ();
- initializeLabel ();
- initializeList ();
- initializeScrollBar ();
- initializeText ();
- initializeSystemColors ();
- initializeDefaults ();
- initializeTranslations ();
- initializeWidgetTable ();
- initializeNumLock ();
- initializePixmaps ();
-}
-void initializeButton () {
-
- int shellHandle, widgetHandle;
- int widgetClass = OS.topLevelShellWidgetClass ();
-
- /* Get the push button information */
- shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
-
- /*
- * Bug in Motif. When running on UTF-8, Motif becomes unstable and
- * GP's some time later when a button widget is created with empty
- * text. The fix is to create the button with a non-empty string.
- */
- byte [] buffer = Converter.wcsToMbcs(null, "string", true); //$NON-NLS-1$
- widgetHandle = OS.XmCreatePushButton (shellHandle, buffer, null, 0);
- OS.XtManageChild (widgetHandle);
- OS.XtSetMappedWhenManaged (shellHandle, false);
- OS.XtRealizeWidget (shellHandle);
- int [] argList = {
- OS.XmNforeground, 0, /* 1 */
- OS.XmNbackground, 0, /* 3 */
- OS.XmNshadowThickness, 0, /* 5 */
- OS.XmNfontList, 0, /* 7 */
- };
- OS.XtGetValues (widgetHandle, argList, argList.length / 2);
- buttonForeground = argList [1]; buttonBackground = argList [3];
- buttonShadowThickness = argList [5];
- /*
- * Feature in Motif. Querying the font list from the widget and
- * then destroying the shell (and the widget) could cause the
- * font list to be freed as well. The fix is to make a copy of
- * the font list, then to free it when the display is disposed.
- */
-
- buttonFont = Font.motif_new (this, OS.XmFontListCopy (argList [7]));
- OS.XtDestroyWidget (shellHandle);
-}
-void initializeComposite () {
- int widgetClass = OS.topLevelShellWidgetClass ();
- int shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
- int scrolledHandle = OS.XmCreateMainWindow (shellHandle, null, null, 0);
- int [] argList1 = {OS.XmNorientation, OS.XmHORIZONTAL};
- int hScrollHandle = OS.XmCreateScrollBar (scrolledHandle, null, argList1, argList1.length / 2);
- OS.XtManageChild (hScrollHandle);
- int [] argList2 = {OS.XmNorientation, OS.XmVERTICAL};
- int vScrollHandle = OS.XmCreateScrollBar (scrolledHandle, null, argList2, argList2.length / 2);
- OS.XtManageChild (vScrollHandle);
- OS.XtManageChild (scrolledHandle);
- int [] argList5 = {
- OS.XmNmarginWidth, 3,
- OS.XmNmarginHeight, 3,
- };
- int formHandle = OS.XmCreateForm (scrolledHandle, null, argList5, argList5.length / 2);
- OS.XtManageChild (formHandle);
- int [] argList6 = {
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNtopAttachment, OS.XmATTACH_FORM,
- OS.XmNbottomAttachment, OS.XmATTACH_FORM,
- OS.XmNleftAttachment, OS.XmATTACH_FORM,
- OS.XmNrightAttachment, OS.XmATTACH_FORM,
- };
- int widgetHandle = OS.XmCreateDrawingArea (formHandle, null, argList6, argList6.length / 2);
- OS.XtManageChild (widgetHandle);
- OS.XmMainWindowSetAreas (scrolledHandle, 0, 0, hScrollHandle, vScrollHandle, formHandle);
- OS.XtSetMappedWhenManaged (shellHandle, false);
- int screen = OS.XDefaultScreen (xDisplay);
- OS.XtResizeWidget (shellHandle, OS.XDisplayWidth (xDisplay, screen), OS.XDisplayHeight (xDisplay, screen), 0);
- OS.XtRealizeWidget (shellHandle);
- int [] argList3 = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (scrolledHandle, argList3, argList3.length / 2);
- int [] argList8 = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (formHandle, argList8, argList8.length / 2);
- int [] argList4 = {
- OS.XmNx, 0, /* 1 */
- OS.XmNy, 0, /* 3 */
- OS.XmNwidth, 0, /* 5 */
- OS.XmNheight, 0, /* 7 */
- OS.XmNforeground, 0, /* 9 */
- OS.XmNbackground, 0, /* 11 */
- OS.XmNtopShadowColor, 0, /* 13 */
- OS.XmNbottomShadowColor, 0, /* 15 */
- OS.XmNborderColor, 0, /* 17 */
- };
- OS.XtGetValues (widgetHandle, argList4, argList4.length / 2);
- scrolledInsetX = argList4 [1] + argList8 [1];
- scrolledInsetY = argList4 [3] + argList8 [3];
- scrolledMarginX = argList3 [1] - argList8 [1] - argList4 [1] - argList4 [5];
- scrolledMarginY = argList3 [3] - argList8 [3] - argList4 [3] - argList4 [7];
- compositeForeground = argList4 [9]; compositeBackground = argList4 [11];
- compositeTopShadow = argList4 [13]; compositeBottomShadow = argList4 [15];
- compositeBorder = argList4 [17];
- OS.XtDestroyWidget (shellHandle);
-}
-void initializeDefaults () {
- defaultFont = labelFont;
- defaultForeground = compositeForeground;
- defaultBackground = compositeBackground;
-}
-void initializeDialog () {
- //int shellHandle, widgetHandle;
- //int widgetClass = OS.topLevelShellWidgetClass ();
- //shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
- //widgetHandle = OS.XmCreateDialogShell (shellHandle, null, null, 0);
- //OS.XtSetMappedWhenManaged (shellHandle, false);
- //OS.XtRealizeWidget (shellHandle);
- //int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0};
- //OS.XtGetValues (widgetHandle, argList, argList.length / 2);
- //dialogForeground = argList [1]; dialogBackground = argList [3];
- //OS.XtDestroyWidget (shellHandle);
-}
-void initializeDisplay () {
-
- /* Create the callbacks */
- focusCallback = new Callback (this, "focusProc", 4); //$NON-NLS-1$
- focusProc = focusCallback.getAddress ();
- if (focusProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- windowCallback = new Callback (this, "windowProc", 4); //$NON-NLS-1$
- windowProc = windowCallback.getAddress ();
- if (windowProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- windowTimerCallback = new Callback (this, "windowTimerProc", 2); //$NON-NLS-1$
- windowTimerProc = windowTimerCallback.getAddress ();
- if (windowTimerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- timerCallback = new Callback (this, "timerProc", 2); //$NON-NLS-1$
- timerProc = timerCallback.getAddress ();
- if (timerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- caretCallback = new Callback (this, "caretProc", 2); //$NON-NLS-1$
- caretProc = caretCallback.getAddress ();
- if (caretProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- mouseHoverCallback = new Callback (this, "mouseHoverProc", 2); //$NON-NLS-1$
- mouseHoverProc = mouseHoverCallback.getAddress ();
- if (mouseHoverProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- checkExposeCallback = new Callback (this, "checkExposeProc", 3); //$NON-NLS-1$
- checkExposeProc = checkExposeCallback.getAddress ();
- if (checkExposeProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- checkResizeCallback = new Callback (this, "checkResizeProc", 3); //$NON-NLS-1$
- checkResizeProc = checkResizeCallback.getAddress ();
- if (checkResizeProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- wakeCallback = new Callback (this, "wakeProc", 3); //$NON-NLS-1$
- wakeProc = wakeCallback.getAddress ();
- if (wakeProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- /* Create and install the pipe used to wake up from sleep */
- int [] filedes = new int [2];
- if (OS.pipe (filedes) != 0) error (SWT.ERROR_NO_HANDLES);
- read_fd = filedes [0];
- write_fd = filedes [1];
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- inputID = OS.XtAppAddInput (xtContext, read_fd, OS.XtInputReadMask, wakeProc, 0);
- fd_set = new byte [OS.fd_set_sizeof ()];
-
- /*
- * Use dynamic Drag and Drop Protocol styles.
- * Preregistered protocol is not supported.
- */
- int xmDisplay = OS.XmGetXmDisplay (xDisplay);
- int [] args = new int [] {
- OS.XmNenableThinThickness, 1,
- OS.XmNdragInitiatorProtocolStyle, OS.XmDRAG_DYNAMIC,
- OS.XmNdragReceiverProtocolStyle, OS.XmDRAG_DYNAMIC,
- };
- OS.XtSetValues (xmDisplay, args, args.length / 2);
-
- /* Create the hidden Override shell parent */
- int xScreen = OS.XDefaultScreen (xDisplay);
- int widgetClass = OS.topLevelShellWidgetClass ();
- shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
- OS.XtSetMappedWhenManaged (shellHandle, false);
- OS.XtResizeWidget (shellHandle, OS.XDisplayWidth (xDisplay, xScreen), OS.XDisplayHeight (xDisplay, xScreen), 0);
- OS.XtRealizeWidget (shellHandle);
-}
-void initializeLabel () {
- int shellHandle, widgetHandle;
- int widgetClass = OS.topLevelShellWidgetClass ();
- shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
-
- /*
- * Bug in Motif. When running on UTF-8, Motif becomes unstable and
- * GP's some time later when a label widget is created with empty
- * text. The fix is to create the label with a non-empty string.
- */
- byte [] buffer = Converter.wcsToMbcs(null, "string", true); //$NON-NLS-1$
- widgetHandle = OS.XmCreateLabel (shellHandle, buffer, null, 0);
- OS.XtManageChild (widgetHandle);
- OS.XtSetMappedWhenManaged (shellHandle, false);
- OS.XtRealizeWidget (shellHandle);
- int [] argList2 = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNfontList, 0};
- OS.XtGetValues (widgetHandle, argList2, argList2.length / 2);
- labelForeground = argList2 [1]; labelBackground = argList2 [3];
- /*
- * Feature in Motif. Querying the font list from the widget and
- * then destroying the shell (and the widget) could cause the
- * font list to be freed as well. The fix is to make a copy of
- * the font list, then to free it when the display is disposed.
- */
-
- labelFont = Font.motif_new (this, OS.XmFontListCopy (argList2 [5]));
- OS.XtDestroyWidget (shellHandle);
-}
-void initializeList () {
- int shellHandle, widgetHandle;
- int widgetClass = OS.topLevelShellWidgetClass ();
- shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
- widgetHandle = OS.XmCreateScrolledList (shellHandle, new byte [1], null, 0);
- OS.XtManageChild (widgetHandle);
- OS.XtSetMappedWhenManaged (shellHandle, false);
- OS.XtRealizeWidget (shellHandle);
- int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNfontList, 0, OS.XmNselectColor, 0, OS.XmNhighlightColor, 0};
- OS.XtGetValues (widgetHandle, argList, argList.length / 2);
- listForeground = argList [1];
- listBackground = argList [3];
-
- /*
- * Feature in Motif. Querying the font list from the widget and
- * then destroying the shell (and the widget) could cause the
- * font list to be freed as well. The fix is to make a copy of
- * the font list, then to free it when the display is disposed.
- */
-
- listFont = Font.motif_new (this, OS.XmFontListCopy (argList [5]));
-
- /*
- * Feature in Motif. If the value of resource XmNselectColor is
- * XmDEFAULT_SELECT_COLOR then querying for this resource gives
- * the value of the selection color to use, which is between the
- * background and bottom shadow colors. If the resource value
- * that is returned is XmDEFAULT_SELECT_COLOR, and not the color,
- * since there is no API to query the color, use the list foreground
- * color.
- */
- int selectColor = (byte) argList [7];
- switch (selectColor) {
- case OS.XmDEFAULT_SELECT_COLOR:
- case OS.XmREVERSED_GROUND_COLORS:
- listSelect = listForeground;
- break;
- case OS.XmHIGHLIGHT_COLOR:
- listSelect = argList [9];
- break;
- default:
- listSelect = argList [7]; // the middle color to use
- }
- OS.XtDestroyWidget (shellHandle);
-}
-
-void initializeNumLock () {
- int numLockCode = OS.XKeysymToKeycode (xDisplay, OS.XK_Num_Lock);
- int keymapHandle = OS.XGetModifierMapping (xDisplay);
- XModifierKeymap keymap = new XModifierKeymap ();
- OS.memmove (keymap, keymapHandle, XModifierKeymap.sizeof);
- for (int i = 0; i < 8 * keymap.max_keypermod; i++) {
- byte [] keymapCode = new byte [1];
- OS.memmove (keymapCode, keymap.modifiermap + i, 1);
- if (keymapCode [0] == numLockCode) {
- int modIndex = i / keymap.max_keypermod;
- switch (modIndex) {
- case OS.Mod1MapIndex: numLock = "Mod1"; break; //$NON-NLS-1$
- case OS.Mod2MapIndex: numLock = "Mod2"; break; //$NON-NLS-1$
- case OS.Mod3MapIndex: numLock = "Mod3"; break; //$NON-NLS-1$
- case OS.Mod4MapIndex: numLock = "Mod4"; break; //$NON-NLS-1$
- case OS.Mod5MapIndex: numLock = "Mod5"; break; //$NON-NLS-1$
- default: numLock = "Mod2"; //$NON-NLS-1$
- }
- break;
- }
- }
- OS.XFreeModifiermap (keymapHandle);
-}
-void initializePixmaps () {
- /*
- * Feature in Motif. The system pixmaps are initially installed the first
- * time a system dialog is created, so create and destroy a system dialog
- * in order to make these pixmaps available.
- */
- int dialog = OS.XmCreateErrorDialog (shellHandle, null, null, 0);
- OS.XtDestroyWidget (dialog);
-}
-void initializeScrollBar () {
- //int shellHandle, widgetHandle;
- //int widgetClass = OS.topLevelShellWidgetClass ();
- //shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
- //widgetHandle = OS.XmCreateScrollBar (shellHandle, null, null, 0);
- //OS.XtManageChild (widgetHandle);
- //OS.XtSetMappedWhenManaged (shellHandle, false);
- //OS.XtRealizeWidget (shellHandle);
- //int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0};
- //OS.XtGetValues (widgetHandle, argList, argList.length / 2);
- //scrollBarForeground = argList [1]; scrollBarBackground = argList [3];
- //OS.XtDestroyWidget (shellHandle);
-}
-void initializeSystemColors () {
- int [] argList = {OS.XmNcolormap, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- int colormap = argList [1];
-
- COLOR_WIDGET_DARK_SHADOW = new XColor();
- COLOR_WIDGET_DARK_SHADOW.pixel = compositeBottomShadow;
- OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_DARK_SHADOW);
-
- COLOR_WIDGET_NORMAL_SHADOW = new XColor();
- COLOR_WIDGET_NORMAL_SHADOW.pixel = compositeBottomShadow;
- OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_NORMAL_SHADOW);
-
- COLOR_WIDGET_LIGHT_SHADOW = new XColor();
- COLOR_WIDGET_LIGHT_SHADOW.pixel = compositeTopShadow;
- OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_LIGHT_SHADOW);
-
- COLOR_WIDGET_HIGHLIGHT_SHADOW = new XColor();
- COLOR_WIDGET_HIGHLIGHT_SHADOW.pixel = compositeTopShadow;
- OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_HIGHLIGHT_SHADOW);
-
- COLOR_WIDGET_FOREGROUND = new XColor();
- COLOR_WIDGET_FOREGROUND.pixel = textForeground;
- OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_FOREGROUND);
-
- COLOR_WIDGET_BACKGROUND = new XColor();
- COLOR_WIDGET_BACKGROUND.pixel = compositeBackground;
- OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_BACKGROUND);
-
- COLOR_WIDGET_BORDER = new XColor();
- COLOR_WIDGET_BORDER.pixel = compositeBorder;
- OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_BORDER);
-
- COLOR_LIST_FOREGROUND = new XColor();
- COLOR_LIST_FOREGROUND.pixel = listForeground;
- OS.XQueryColor (xDisplay, colormap, COLOR_LIST_FOREGROUND);
-
- COLOR_LIST_BACKGROUND = new XColor();
- COLOR_LIST_BACKGROUND.pixel = listBackground;
- OS.XQueryColor (xDisplay, colormap, COLOR_LIST_BACKGROUND);
-
- COLOR_LIST_SELECTION = new XColor();
- COLOR_LIST_SELECTION.pixel = listSelect;
- OS.XQueryColor (xDisplay, colormap, COLOR_LIST_SELECTION);
-
- COLOR_LIST_SELECTION_TEXT = new XColor();
- COLOR_LIST_SELECTION_TEXT.pixel = listBackground;
- OS.XQueryColor (xDisplay, colormap, COLOR_LIST_SELECTION_TEXT);
-
- COLOR_INFO_BACKGROUND = new Color (this, 0xFF, 0xFF, 0xE1);
-}
-void initializeText () {
- int shellHandle, widgetHandle;
- int widgetClass = OS.topLevelShellWidgetClass ();
- shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
- widgetHandle = OS.XmCreateScrolledText (shellHandle, new byte [1], null, 0);
- OS.XtManageChild (widgetHandle);
- OS.XtSetMappedWhenManaged (shellHandle, false);
- OS.XtRealizeWidget (shellHandle);
- int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNfontList, 0, OS.XmNhighlightThickness, 0, OS.XmNblinkRate, 0};
- OS.XtGetValues (widgetHandle, argList, argList.length / 2);
- textForeground = argList [1];
- textBackground = argList [3];
- textHighlightThickness = argList[7];
- blinkRate = argList[9];
- /*
- * Feature in Motif. Querying the font list from the widget and
- * then destroying the shell (and the widget) could cause the
- * font list to be freed as well. The fix is to make a copy of
- * the font list, then to free it when the display is disposed.
- */
-
- textFont = Font.motif_new (this, OS.XmFontListCopy (argList [5]));
- OS.XtDestroyWidget (shellHandle);
-
-}
-void initializeTranslations () {
- byte [] buffer1 = Converter.wcsToMbcs (null, "<Key>osfUp:\n<Key>osfDown:\n<Key>osfLeft:\n<Key>osfRight:\0"); //$NON-NLS-1$
- arrowTranslations = OS.XtParseTranslationTable (buffer1);
- byte [] buffer2 = Converter.wcsToMbcs (null, "~Meta ~Alt <Key>Tab:\nShift ~Meta ~Alt <Key>Tab:\0"); //$NON-NLS-1$
- tabTranslations = OS.XtParseTranslationTable (buffer2);
- byte [] buffer3 = Converter.wcsToMbcs (null, "<Btn2Down>:\0"); //$NON-NLS-1$
- dragTranslations = OS.XtParseTranslationTable (buffer3);
-}
-void initializeWidgetTable () {
- userData = new int [] {OS.XmNuserData, 0};
- indexTable = new int [GROW_SIZE];
- shellTable = new Shell [GROW_SIZE / 8];
- widgetTable = new Widget [GROW_SIZE];
- for (int i=0; i<GROW_SIZE-1; i++) indexTable [i] = i + 1;
- indexTable [GROW_SIZE - 1] = -1;
-}
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Display</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for gc creation</li>
- * </ul>
- */
-public int internal_new_GC (GCData data) {
- if (isDisposed()) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
- int xDrawable = OS.XDefaultRootWindow (xDisplay);
- int xGC = OS.XCreateGC (xDisplay, xDrawable, 0, null);
- if (xGC == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- OS.XSetSubwindowMode (xDisplay, xGC, OS.IncludeInferiors);
- if (data != null) {
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) == 0) {
- data.style |= SWT.LEFT_TO_RIGHT;
- }
- data.device = this;
- data.display = xDisplay;
- data.drawable = xDrawable;
- data.background = getSystemColor (SWT.COLOR_WHITE).handle;
- data.foreground = getSystemColor (SWT.COLOR_BLACK).handle;
- data.font = defaultFont;
- data.colormap = OS.XDefaultColormap (xDisplay, OS.XDefaultScreen (xDisplay));
- }
- return xGC;
-}
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Display</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int gc, GCData data) {
- OS.XFreeGC(xDisplay, gc);
-}
-boolean isValidThread () {
- return thread == Thread.currentThread ();
-}
-static boolean isValidClass (Class clazz) {
- String name = clazz.getName ();
- int index = name.lastIndexOf ('.');
- return name.substring (0, index + 1).equals (PACKAGE_PREFIX);
-}
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param point to be mapped
- * @return point with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Point map (Control from, Control to, Point point) {
- checkDevice ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return map (from, to, point.x, point.y);
-}
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param x coordinates to be mapped
- * @param y coordinates to be mapped
- * @return point with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Point map (Control from, Control to, int x, int y) {
- checkDevice ();
- if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- Point point = new Point (x, y);
- if (from == to) return point;
- if (from != null) {
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (from.handle, (short) x, (short) y, root_x, root_y);
- point.x = root_x [0];
- point.y = root_y [0];
- }
- if (to != null) {
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (to.handle, (short) 0, (short) 0, root_x, root_y);
- point.x -= root_x [0];
- point.y -= root_y [0];
- }
- return point;
-}
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param rectangle to be mapped
- * @return rectangle with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Rectangle map (Control from, Control to, Rectangle rectangle) {
- checkDevice();
- if (rectangle == null) error (SWT.ERROR_NULL_ARGUMENT);
- return map (from, to, rectangle.x, rectangle.y, rectangle.width, rectangle.height);
-}
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param x coordinates to be mapped
- * @param y coordinates to be mapped
- * @param width coordinates to be mapped
- * @param height coordinates to be mapped
- * @return rectangle with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Rectangle map (Control from, Control to, int x, int y, int width, int height) {
- checkDevice();
- if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- Rectangle rect = new Rectangle (x, y, width, height);
- if (from == to) return rect;
- if (from != null) {
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (from.handle, (short) x, (short) y, root_x, root_y);
- rect.x = root_x [0];
- rect.y = root_y [0];
- }
- if (to != null) {
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (to.handle, (short) 0, (short) 0, root_x, root_y);
- rect.x -= root_x [0];
- rect.y -= root_y [0];
- }
- return rect;
-}
-int mouseHoverProc (int handle, int id) {
- mouseHoverID = mouseHoverHandle = 0;
- Widget widget = getWidget (handle);
- if (widget == null) return 0;
- return widget.hoverProc (id);
-}
-/**
- * Generate a low level system event.
- *
- * <code>post</code> is used to generate low level keyboard
- * and mouse events. The intent is to enable automated UI
- * testing by simulating the input from the user. Most
- * SWT applications should never need to call this method.
- * <p>
- * Note that this operation can fail when the operating system
- * fails to generate the event for any reason. For example,
- * this can happen when there is no such key or mouse button
- * or when the system event queue is full.
- * </p>
- * <p>
- * <b>Event Types:</b>
- * <p>KeyDown, KeyUp
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type KeyDown or KeyUp</li>
- * <p> Either one of:
- * <li>(in) character a character that corresponds to a keyboard key</li>
- * <li>(in) keyCode the key code of the key that was typed,
- * as defined by the key code constants in class <code>SWT</code></li>
- * </ul>
- * <p>MouseDown, MouseUp</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseDown or MouseUp
- * <li>(in) button the button that is pressed or released
- * </ul>
- * <p>MouseMove</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseMove
- * <li>(in) x the x coordinate to move the mouse pointer to in screen coordinates
- * <li>(in) y the y coordinate to move the mouse pointer to in screen coordinates
- * </ul>
- * <p>MouseWheel</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseWheel
- * <li>(in) detail either SWT.SCROLL_LINE or SWT.SCROLL_PAGE
- * <li>(in) count the number of lines or pages to scroll
- * </ul>
- * </dl>
- *
- * @param event the event to be generated
- *
- * @return true if the event was generated or false otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public boolean post (Event event) {
- /*
- * Get the operating system lock before synchronizing on the device
- * lock so that the device lock will not be held should another
- * thread already be in the operating system. This avoids deadlock
- * should the other thread need the device lock.
- */
- Lock lock = OS.lock;
- lock.lock();
- try {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- int type = event.type;
- switch (type) {
- case SWT.KeyDown :
- case SWT.KeyUp : {
- int keyCode = 0;
- int keysym = untranslateKey (event.keyCode);
- if (keysym != 0) keyCode = OS.XKeysymToKeycode (xDisplay, keysym);
- if (keyCode == 0) {
- char key = event.character;
- switch (key) {
- case SWT.BS: keysym = OS.XK_BackSpace; break;
- case SWT.CR: keysym = OS.XK_Return; break;
- case SWT.DEL: keysym = OS.XK_Delete; break;
- case SWT.ESC: keysym = OS.XK_Escape; break;
- case SWT.TAB: keysym = OS.XK_Tab; break;
- case SWT.LF: keysym = OS.XK_Linefeed; break;
- default:
- keysym = key;
- }
- keyCode = OS.XKeysymToKeycode (xDisplay, keysym);
- if (keyCode == 0) return false;
- }
- OS.XTestFakeKeyEvent (xDisplay, keyCode, type == SWT.KeyDown, 0);
- return true;
- }
- case SWT.MouseDown :
- case SWT.MouseMove :
- case SWT.MouseUp : {
- if (type == SWT.MouseMove) {
- OS.XTestFakeMotionEvent (xDisplay, -1, event.x, event.y, 0);
- return true;
- } else {
- int button = event.button;
- if (button < 1 || button > 3) return false;
- OS.XTestFakeButtonEvent (xDisplay, button, type == SWT.MouseDown, 0);
- return true;
- }
- }
- }
- return false;
- }
- } finally {
- lock.unlock();
- }
-}
-void postEvent (Event event) {
- /*
- * Place the event at the end of the event queue.
- * This code is always called in the Display's
- * thread so it must be re-enterant but does not
- * need to be synchronized.
- */
- if (eventQueue == null) eventQueue = new Event [4];
- int index = 0;
- int length = eventQueue.length;
- while (index < length) {
- if (eventQueue [index] == null) break;
- index++;
- }
- if (index == length) {
- Event [] newQueue = new Event [length + 4];
- System.arraycopy (eventQueue, 0, newQueue, 0, length);
- eventQueue = newQueue;
- }
- eventQueue [index] = event;
-}
-/**
- * Reads an event from the operating system's event queue,
- * dispatches it appropriately, and returns <code>true</code>
- * if there is potentially more work to do, or <code>false</code>
- * if the caller can sleep until another event is placed on
- * the event queue.
- * <p>
- * In addition to checking the system event queue, this method also
- * checks if any inter-thread messages (created by <code>syncExec()</code>
- * or <code>asyncExec()</code>) are waiting to be processed, and if
- * so handles them before returning.
- * </p>
- *
- * @return <code>false</code> if the caller can sleep upon return from this method
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li>
- * </ul>
- *
- * @see #sleep
- * @see #wake
- */
-public boolean readAndDispatch () {
- checkDevice ();
- boolean events = runPopups ();
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- int status = OS.XtAppPending (xtContext);
- if (status != 0) {
- events |= true;
- if ((status & OS.XtIMTimer) != 0) {
- OS.XtAppProcessEvent (xtContext, OS.XtIMTimer);
- status = OS.XtAppPending (xtContext);
- }
- if ((status & OS.XtIMAlternateInput) != 0) {
- OS.XtAppProcessEvent (xtContext, OS.XtIMAlternateInput);
- status = OS.XtAppPending (xtContext);
- }
- if ((status & OS.XtIMXEvent) != 0) {
- OS.XtAppNextEvent (xtContext, xEvent);
- if (!filterEvent (xEvent)) OS.XtDispatchEvent (xEvent);
- }
- }
- if (events) {
- runDeferredEvents ();
- return true;
- }
- return isDisposed () || runAsyncMessages (false);
-}
-static void register (Display display) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] == null) {
- Displays [i] = display;
- return;
- }
- }
- Display [] newDisplays = new Display [Displays.length + 4];
- System.arraycopy (Displays, 0, newDisplays, 0, Displays.length);
- newDisplays [Displays.length] = display;
- Displays = newDisplays;
- }
-}
-/**
- * Releases any internal resources back to the operating
- * system and clears all fields except the device handle.
- * <p>
- * Disposes all shells which are currently open on the display.
- * After this method has been invoked, all related related shells
- * will answer <code>true</code> when sent the message
- * <code>isDisposed()</code>.
- * </p><p>
- * When a device is destroyed, resources that were acquired
- * on behalf of the programmer need to be returned to the
- * operating system. For example, if the device allocated a
- * font to be used as the system font, this font would be
- * freed in <code>release</code>. Also,to assist the garbage
- * collector and minimize the amount of memory that is not
- * reclaimed when the programmer keeps a reference to a
- * disposed device, all fields except the handle are zero'd.
- * The handle is needed by <code>destroy</code>.
- * </p>
- * This method is called before <code>destroy</code>.
- *
- * @see Device#dispose
- * @see #destroy
- */
-protected void release () {
- sendEvent (SWT.Dispose, new Event ());
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) shell.dispose ();
- }
- if (tray != null) tray.dispose ();
- tray = null;
- while (readAndDispatch ()) {}
- if (disposeList != null) {
- for (int i=0; i<disposeList.length; i++) {
- if (disposeList [i] != null) disposeList [i].run ();
- }
- }
- disposeList = null;
- synchronizer.releaseSynchronizer ();
- synchronizer = null;
- releaseDisplay ();
- super.release ();
-}
-void releaseDisplay () {
- /* destroy the System Images */
- int screen = OS.XDefaultScreenOfDisplay (xDisplay);
- if (errorPixmap != 0) {
- OS.XmDestroyPixmap (screen, errorPixmap);
- OS.XFreePixmap (xDisplay, errorMask);
- }
- if (infoPixmap != 0) {
- OS.XmDestroyPixmap (screen, infoPixmap);
- OS.XFreePixmap (xDisplay, infoMask);
- }
- if (questionPixmap != 0) {
- OS.XmDestroyPixmap (screen, questionPixmap);
- OS.XFreePixmap (xDisplay, questionMask);
- }
- if (warningPixmap != 0) {
- OS.XmDestroyPixmap (screen, warningPixmap);
- OS.XFreePixmap (xDisplay, warningMask);
- }
- if (workingPixmap != 0) {
- OS.XmDestroyPixmap (screen, workingPixmap);
- OS.XFreePixmap (xDisplay, workingMask);
- }
- errorPixmap = infoPixmap = questionPixmap = warningPixmap = workingPixmap = 0;
- errorMask = infoMask = questionMask = warningMask = workingMask = 0;
-
- /* Release the System Cursors */
- for (int i = 0; i < cursors.length; i++) {
- if (cursors [i] != null) cursors [i].dispose ();
- }
- cursors = null;
-
- /* Destroy the hidden Override shell parent */
- if (shellHandle != 0) {
- if (!OS.IsSunOS) {
- OS.XtDestroyWidget (shellHandle);
- }
- shellHandle = 0;
- }
-
- /* Dispose the caret callback */
- if (caretID != 0) OS.XtRemoveTimeOut (caretID);
- caretID = caretProc = 0;
- caretCallback.dispose ();
- caretCallback = null;
-
- /* Dispose the timer callback */
- if (timerIds != null) {
- for (int i=0; i<timerIds.length; i++) {
- if (timerIds [i] != 0) OS.XtRemoveTimeOut (timerIds [i]);
- }
- }
- timerIds = null;
- timerList = null;
- timerProc = 0;
- timerCallback.dispose ();
- timerCallback = null;
-
- /* Dispose the window timer callback */
- windowTimerProc = 0;
- windowTimerCallback.dispose ();
- windowTimerCallback = null;
-
- /* Dispose the mouse hover callback */
- if (mouseHoverID != 0) OS.XtRemoveTimeOut (mouseHoverID);
- mouseHoverID = mouseHoverProc = mouseHoverHandle = toolTipHandle = 0;
- mouseHoverCallback.dispose ();
- mouseHoverCallback = null;
-
- /* Dispose window, expose and resize callbacks */
- windowCallback.dispose (); windowCallback = null;
- checkExposeCallback.dispose (); checkExposeCallback = null;
- checkExposeProc = 0;
- checkResizeCallback.dispose (); checkResizeCallback = null;
- checkResizeProc = 0;
-
- /* Dispose the wake callback, id and pipe */
- if (inputID != 0) OS.XtRemoveInput (inputID);
- wakeCallback.dispose (); wakeCallback = null;
- wakeProc = 0;
- OS.close (read_fd);
- OS.close (write_fd);
-
- focusCallback.dispose (); focusCallback = null;
- focusProc = 0;
-
- /* Free the font lists */
- if (buttonFont != null) {
- OS.XmFontListFree (buttonFont.handle);
- buttonFont.handle = 0;
- }
- if (labelFont != null) {
- OS.XmFontListFree (labelFont.handle);
- labelFont.handle = 0;
- }
- if (textFont != null) {
- OS.XmFontListFree (textFont.handle);
- textFont.handle = 0;
- }
- if (listFont != null) {
- OS.XmFontListFree (listFont.handle);
- listFont.handle = 0;
- }
- listFont = textFont = labelFont = buttonFont = null;
- defaultFont = null;
-
- /* Free the translations (no documentation describes how to do this) */
- //OS.XtFree (arrowTranslations);
- //OS.XtFree (tabTranslations);
- //OS.XtFree (dragTranslations);
-
- if (xEvent != 0) OS.XtFree(xEvent);
- xEvent = 0;
-
- /* Release references */
- thread = null;
- buttonBackground = buttonForeground = 0;
- defaultBackground = defaultForeground = 0;
- COLOR_WIDGET_DARK_SHADOW = COLOR_WIDGET_NORMAL_SHADOW = COLOR_WIDGET_LIGHT_SHADOW =
- COLOR_WIDGET_HIGHLIGHT_SHADOW = COLOR_WIDGET_FOREGROUND = COLOR_WIDGET_BACKGROUND = COLOR_WIDGET_BORDER =
- COLOR_LIST_FOREGROUND = COLOR_LIST_BACKGROUND = COLOR_LIST_SELECTION = COLOR_LIST_SELECTION_TEXT = null;
- COLOR_INFO_BACKGROUND = null;
-
- popups = null;
- focusedCombo = null;
- displayName = appName = appClass = wake_buffer = fd_set = null;
- keyEvent = null;
- eventTable = filterTable = null;
- indexTable = userData = timeout = null;
- widgetTable = shellTable = null;
- xExposeEvent = null;
- xConfigureEvent = null;
- data = null;
- values = keys = null;
-}
-void releaseToolTipHandle (int handle) {
- if (mouseHoverHandle == handle) removeMouseHoverTimeOut ();
- if (toolTipHandle != 0) {
- int shellHandle = OS.XtParent(toolTipHandle);
- int shellParent = OS.XtParent(shellHandle);
- if (handle == shellParent) toolTipHandle = 0;
- }
-}
-void removeMouseHoverTimeOut () {
- if (mouseHoverID != 0) OS.XtRemoveTimeOut (mouseHoverID);
- mouseHoverID = mouseHoverHandle = 0;
-}
-Widget removeWidget (int handle) {
- if (handle == 0) return null;
- if (OS.XtIsSubclass (handle, OS.shellWidgetClass ())) {
- for (int i=0; i<shellTable.length; i++) {
- Widget shell = shellTable [i];
- if (shell != null && shell.topHandle () == handle) {
- shellTable [i] = null;
- return shell;
- }
- }
- return null;
- }
- userData [1] = 0;
- Widget widget = null;
- OS.XtGetValues (handle, userData, userData.length / 2);
- int index = userData [1] - 1;
- if (0 <= index && index < widgetTable.length) {
- widget = widgetTable [index];
- widgetTable [index] = null;
- indexTable [index] = freeSlot;
- freeSlot = index;
- userData [1] = 0;
- OS.XtSetValues (handle, userData, userData.length / 2);
- }
- return widget;
-}
-void removePopup (Menu menu) {
- if (popups == null) return;
- for (int i=0; i<popups.length; i++) {
- if (popups [i] == menu) {
- popups [i] = null;
- return;
- }
- }
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs anywhere in
- * a widget. The event type is one of the event constants defined
- * in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addFilter
- * @see #addListener
- *
- * @since 3.0
- */
-public void removeFilter (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (filterTable == null) return;
- filterTable.unhook (eventType, listener);
- if (filterTable.size () == 0) filterTable = null;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs. The event type
- * is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener
- *
- * @since 2.0
- */
-public void removeListener (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, listener);
-}
-boolean runAsyncMessages (boolean all) {
- return synchronizer.runAsyncMessages (all);
-}
-boolean runDeferredEvents () {
- boolean run = false;
- /*
- * Run deferred events. This code is always
- * called in the Display's thread so it must
- * be re-enterant but need not be synchronized.
- */
- while (eventQueue != null) {
-
- /* Take an event off the queue */
- Event event = eventQueue [0];
- if (event == null) break;
- int length = eventQueue.length;
- System.arraycopy (eventQueue, 1, eventQueue, 0, --length);
- eventQueue [length] = null;
-
- /* Run the event */
- Widget widget = event.widget;
- if (widget != null && !widget.isDisposed ()) {
- Widget item = event.item;
- if (item == null || !item.isDisposed ()) {
- run = true;
- widget.sendEvent (event);
- }
- }
-
- /*
- * At this point, the event queue could
- * be null due to a recursive invokation
- * when running the event.
- */
- }
-
- /* Clear the queue */
- eventQueue = null;
- return run;
-}
-boolean runFocusOutEvents () {
- if (eventQueue == null) return false;
- Event [] focusQueue = null;
- int index = 0, count = 0, length = eventQueue.length;
- while (index < length) {
- Event event = eventQueue [index];
- if (event != null && event.type == SWT.FocusOut) {
- if (focusQueue == null) focusQueue = new Event [length];
- focusQueue [count++] = event;
- System.arraycopy (eventQueue, index + 1, eventQueue, index, --length - index);
- eventQueue [length] = null;
- } else {
- index++;
- }
- }
- if (focusQueue == null) return false;
- for (int i=0; i<count; i++) {
- Event event = focusQueue [i];
- Widget widget = event.widget;
- if (widget != null && !widget.isDisposed ()) {
- Widget item = event.item;
- if (item == null || !item.isDisposed ()) {
- widget.sendEvent (event);
- }
- }
- }
- return true;
-}
-boolean runPopups () {
- if (popups == null) return false;
- boolean result = false;
- while (popups != null) {
- Menu menu = popups [0];
- if (menu == null) break;
- int length = popups.length;
- System.arraycopy (popups, 1, popups, 0, --length);
- popups [length] = null;
- runDeferredEvents ();
- if (!menu.isDisposed ()) menu._setVisible (true);
- result = true;
- }
- popups = null;
- return result;
-}
-void sendEvent (int eventType, Event event) {
- if (eventTable == null && filterTable == null) {
- return;
- }
- if (event == null) event = new Event ();
- event.display = this;
- event.type = eventType;
- if (event.time == 0) event.time = getLastEventTime ();
- if (!filterEvent (event)) {
- if (eventTable != null) eventTable.sendEvent (event);
- }
-}
-void sendFocusEvent (Control control, int type) {
- if (type == SWT.FocusIn) {
- focusEvent = SWT.FocusIn;
- control.sendEvent (SWT.FocusIn);
- focusEvent = SWT.None;
- } else {
- if (postFocusOut) {
- control.postEvent (SWT.FocusOut);
- } else {
- focusEvent = SWT.FocusOut;
- control.sendEvent (SWT.FocusOut);
- focusEvent = SWT.None;
- }
- }
-}
-/**
- * Sets the location of the on-screen pointer relative to the top left corner
- * of the screen. <b>Note: It is typically considered bad practice for a
- * program to move the on-screen pointer location.</b>
- *
- * @param x the new x coordinate for the cursor
- * @param y the new y coordinate for the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1
- */
-public void setCursorLocation (int x, int y) {
- checkDevice ();
- int xWindow = OS.XDefaultRootWindow (xDisplay);
- OS.XWarpPointer (xDisplay, OS.None, xWindow, 0, 0, 0, 0, x, y);
-}
-/**
- * Sets the location of the on-screen pointer relative to the top left corner
- * of the screen. <b>Note: It is typically considered bad practice for a
- * program to move the on-screen pointer location.</b>
- *
- * @param point new position
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_NULL_ARGUMENT - if the point is null
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setCursorLocation (Point point) {
- checkDevice ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- setCursorLocation (point.x, point.y);
-}
-/**
- * On platforms which support it, sets the application name
- * to be the argument. On Motif, for example, this can be used
- * to set the name used for resource lookup. Specifying
- * <code>null</code> for the name clears it.
- *
- * @param name the new app name or <code>null</code>
- */
-public static void setAppName (String name) {
- APP_NAME = name;
-}
-void setCurrentCaret (Caret caret) {
- if (caretID != 0) OS.XtRemoveTimeOut (caretID);
- caretID = 0;
- currentCaret = caret;
- if (currentCaret != null) {
- int blinkRate = currentCaret.blinkRate;
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- caretID = OS.XtAppAddTimeOut (xtContext, blinkRate, caretProc, 0);
- }
-}
-/**
- * Sets the application defined property of the receiver
- * with the specified name to the given argument.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the display is disposed
- * of, it is the application's responsibility provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param key the name of the property
- * @param value the new value for the property
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getData(String)
- * @see #disposeExec(Runnable)
- */
-public void setData (String key, Object value) {
- checkDevice ();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
-
- /* Remove the key/value pair */
- if (value == null) {
- if (keys == null) return;
- int index = 0;
- while (index < keys.length && !keys [index].equals (key)) index++;
- if (index == keys.length) return;
- if (keys.length == 1) {
- keys = null;
- values = null;
- } else {
- String [] newKeys = new String [keys.length - 1];
- Object [] newValues = new Object [values.length - 1];
- System.arraycopy (keys, 0, newKeys, 0, index);
- System.arraycopy (keys, index + 1, newKeys, index, newKeys.length - index);
- System.arraycopy (values, 0, newValues, 0, index);
- System.arraycopy (values, index + 1, newValues, index, newValues.length - index);
- keys = newKeys;
- values = newValues;
- }
- return;
- }
-
- /* Add the key/value pair */
- if (keys == null) {
- keys = new String [] {key};
- values = new Object [] {value};
- return;
- }
- for (int i=0; i<keys.length; i++) {
- if (keys [i].equals (key)) {
- values [i] = value;
- return;
- }
- }
- String [] newKeys = new String [keys.length + 1];
- Object [] newValues = new Object [values.length + 1];
- System.arraycopy (keys, 0, newKeys, 0, keys.length);
- System.arraycopy (values, 0, newValues, 0, values.length);
- newKeys [keys.length] = key;
- newValues [values.length] = value;
- keys = newKeys;
- values = newValues;
-}
-/**
- * Sets the application defined, display specific data
- * associated with the receiver, to the argument.
- * The <em>display specific data</em> is a single,
- * unnamed field that is stored with every display.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the display specific data needs to
- * be notified when the display is disposed of, it is the
- * application's responsibility provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param data the new display specific data
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getData()
- * @see #disposeExec(Runnable)
- */
-public void setData (Object data) {
- checkDevice ();
- this.data = data;
-}
-/**
- * Sets the synchronizer used by the display to be
- * the argument, which can not be null.
- *
- * @param synchronizer the new synchronizer for the display (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the synchronizer is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li>
- * </ul>
- */
-public void setSynchronizer (Synchronizer synchronizer) {
- checkDevice ();
- if (synchronizer == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (synchronizer == this.synchronizer) return;
- Synchronizer oldSynchronizer;
- synchronized (Device.class) {
- oldSynchronizer = this.synchronizer;
- this.synchronizer = synchronizer;
- }
- if (oldSynchronizer != null) {
- oldSynchronizer.runAsyncMessages(true);
- }
-}
-void setToolTipText (int handle, String toolTipText) {
- if (toolTipHandle == 0) return;
- int shellHandle = OS.XtParent (toolTipHandle);
- int shellParent = OS.XtParent (shellHandle);
- if (handle != shellParent) return;
- showToolTip (handle, toolTipText);
-}
-void showToolTip (int handle, String toolTipText) {
- int shellHandle = 0;
- if (toolTipText == null) toolTipText = ""; //$NON-NLS-1$
- char [] text = new char [toolTipText.length ()];
- toolTipText.getChars (0, text.length, text, 0);
- Widget.fixMnemonic (text);
- /* Use the character encoding for the default locale */
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- if (toolTipHandle != 0) {
- shellHandle = OS.XtParent (toolTipHandle);
- int shellParent = OS.XtParent (shellHandle);
- if (handle != shellParent) return;
- int xmString = OS.XmStringGenerate (buffer, null, OS.XmCHARSET_TEXT, null);
- int [] argList = {OS.XmNlabelString, xmString};
- OS.XtSetValues (toolTipHandle, argList, argList.length / 2);
- if (xmString != 0) OS.XmStringFree (xmString);
- } else {
- int widgetClass = OS.overrideShellWidgetClass ();
- int [] argList1 = {
- OS.XmNmwmDecorations, 0,
- OS.XmNborderWidth, 1,
- OS.XmNallowShellResize, 1,
- };
- shellHandle = OS.XtCreatePopupShell (null, widgetClass, handle, argList1, argList1.length / 2);
- Color infoForeground = getSystemColor (SWT.COLOR_INFO_FOREGROUND);
- Color infoBackground = getSystemColor (SWT.COLOR_INFO_BACKGROUND);
- int foregroundPixel = infoForeground.handle.pixel;
- int backgroundPixel = infoBackground.handle.pixel;
- int [] argList2 = {
- OS.XmNforeground, foregroundPixel,
- OS.XmNbackground, backgroundPixel,
- OS.XmNalignment, OS.XmALIGNMENT_BEGINNING,
- };
- toolTipHandle = OS.XmCreateLabel (shellHandle, buffer, argList2, argList2.length / 2);
- OS.XtManageChild (toolTipHandle);
- }
- if (toolTipText == null || toolTipText.length () == 0) {
- OS.XtPopdown (shellHandle);
- } else {
- /*
- * Feature in X. There is no way to query the size of a cursor.
- * The fix is to use the default cursor size which is 16x16.
- */
- int xWindow = OS.XDefaultRootWindow (xDisplay);
- int [] rootX = new int [1], rootY = new int [1], unused = new int [1], mask = new int [1];
- OS.XQueryPointer (xDisplay, xWindow, unused, unused, rootX, rootY, unused, unused, mask);
- int x = rootX [0] + 16, y = rootY [0] + 16;
-
- /*
- * Ensure that the tool tip is on the screen.
- */
- int screen = OS.XDefaultScreen (xDisplay);
- int width = OS.XDisplayWidth (xDisplay, screen);
- int height = OS.XDisplayHeight (xDisplay, screen);
- int [] argList4 = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (toolTipHandle, argList4, argList4.length / 2);
- x = Math.max (0, Math.min (x, width - argList4 [1]));
- y = Math.max (0, Math.min (y, height - argList4 [3]));
- OS.XtMoveWidget (shellHandle, x, y);
- int flags = OS.Button1Mask | OS.Button2Mask | OS.Button3Mask;
- if ((mask [0] & flags) == 0) OS.XtPopup (shellHandle, OS.XtGrabNone);
- }
-}
-/**
- * Causes the user-interface thread to <em>sleep</em> (that is,
- * to be put in a state where it does not consume CPU cycles)
- * until an event is received or it is otherwise awakened.
- *
- * @return <code>true</code> if an event requiring dispatching was placed on the queue.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #wake
- */
-public boolean sleep () {
- checkDevice ();
- if (getMessageCount () != 0) return true;
-
- /*
- * This code is intentionally commented.
- */
-// boolean result;
-// int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
-// do {
-// /*
-// * Bug in Xt. Under certain circumstances Xt waits
-// * forever looking for X events, ignoring alternate
-// * inputs. The fix is to never sleep forever.
-// */
-// //int sleepID = OS.XtAppAddTimeOut (xtContext, 50, 0, 0);
-// result = OS.XtAppPeekEvent (xtContext, xEvent);
-// //if (sleepID != 0) OS.XtRemoveTimeOut (sleepID);
-// } while (!result && getMessageCount () == 0 && OS.XtAppPending (xtContext) == 0);
-// return result;
-
- /* Wait for input */
- int result, status;
- boolean workProc = true;
- int display_fd = OS.ConnectionNumber (xDisplay);
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- int max_fd = display_fd > read_fd ? display_fd : read_fd;
- do {
- OS.FD_ZERO (fd_set);
- OS.FD_SET (display_fd, fd_set);
- OS.FD_SET (read_fd, fd_set);
- timeout [0] = 0;
- timeout [1] = 50000;
- /* Exit the OS lock to allow other threads to enter Motif */
- Lock lock = OS.lock;
- int count = lock.lock ();
- for (int i = 0; i < count; i++) lock.unlock ();
- try {
- result = OS.select (max_fd + 1, fd_set, null, null, timeout);
- } finally {
- for (int i = 0; i < count; i++) lock.lock ();
- lock.unlock ();
- }
- /*
- * Force Xt work procs that were added by native
- * widgets to run by calling XtAppProcessEvent().
- * Ensure that XtAppProcessEvent() does not block
- * by adding a time out.
- */
- status = OS.XtAppPending (xtContext);
- if (workProc && status == 0) {
- workProc = false;
- OS.XtAppAddTimeOut (xtContext, 1, 0, 0);
- OS.XtAppProcessEvent (xtContext, OS.XtIMTimer);
- }
- } while (result == 0 && getMessageCount () == 0 && status == 0);
- return OS.FD_ISSET (display_fd, fd_set);
-}
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread at the next
- * reasonable opportunity. The thread which calls this method
- * is suspended until the runnable completes. Specifying <code>null</code>
- * as the runnable simply wakes the user-interface thread.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param runnable code to run on the user-interface thread or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_FAILED_EXEC - if an exception occurred when executing the runnable</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #asyncExec
- */
-public void syncExec (Runnable runnable) {
- Synchronizer synchronizer;
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- synchronizer = this.synchronizer;
- }
- synchronizer.syncExec (runnable);
-}
-int textWidth (String string, Font font) {
- if (string.length () == 0) return 0;
- int fontList = font.handle;
- String codePage = font.codePage;
- byte [] textBuffer = Converter.wcsToMbcs (codePage, string, true);
- int xmString = OS.XmStringGenerate (textBuffer, null, OS.XmCHARSET_TEXT, null);
- int width = OS.XmStringWidth (fontList, xmString);
- OS.XmStringFree (xmString);
- return width;
-}
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread after the specified
- * number of milliseconds have elapsed. If milliseconds is less
- * than zero, the runnable is not executed.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param milliseconds the delay before running the runnable
- * @param runnable code to run on the user-interface thread
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #asyncExec
- */
-public void timerExec (int milliseconds, Runnable runnable) {
- checkDevice ();
- if (runnable == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (timerList == null) timerList = new Runnable [4];
- if (timerIds == null) timerIds = new int [4];
- int index = 0;
- while (index < timerList.length) {
- if (timerList [index] == runnable) break;
- index++;
- }
- if (index != timerList.length) {
- OS.XtRemoveTimeOut (timerIds [index]);
- timerList [index] = null;
- timerIds [index] = 0;
- if (milliseconds < 0) return;
- } else {
- if (milliseconds < 0) return;
- index = 0;
- while (index < timerList.length) {
- if (timerList [index] == null) break;
- index++;
- }
- if (index == timerList.length) {
- Runnable [] newTimerList = new Runnable [timerList.length + 4];
- System.arraycopy (timerList, 0, newTimerList, 0, timerList.length);
- timerList = newTimerList;
- int [] newTimerIds = new int [timerIds.length + 4];
- System.arraycopy (timerIds, 0, newTimerIds, 0, timerIds.length);
- timerIds = newTimerIds;
- }
- }
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- int timerId = OS.XtAppAddTimeOut (xtContext, milliseconds, timerProc, index);
- if (timerId != 0) {
- timerIds [index] = timerId;
- timerList [index] = runnable;
- }
-}
-int timerProc (int index, int id) {
- if (timerList == null) return 0;
- if (0 <= index && index < timerList.length) {
- Runnable runnable = timerList [index];
- timerList [index] = null;
- timerIds [index] = 0;
- if (runnable != null) runnable.run ();
- }
- return 0;
-}
-static int translateKey (int key) {
- for (int i=0; i<KeyTable.length; i++) {
- if (KeyTable [i] [0] == key) return KeyTable [i] [1];
- }
- return 0;
-}
-static int untranslateKey (int key) {
- for (int i=0; i<KeyTable.length; i++) {
- if (KeyTable [i] [1] == key) return KeyTable [i] [0];
- }
- return 0;
-}
-/**
- * Forces all outstanding paint requests for the display
- * to be processed before this method returns.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Control#update()
- */
-public void update () {
- checkDevice ();
- int event = OS.XtMalloc (XEvent.sizeof);
- int mask = OS.ExposureMask | OS.ResizeRedirectMask |
- OS.StructureNotifyMask | OS.SubstructureNotifyMask |
- OS.SubstructureRedirectMask;
- OS.XSync (xDisplay, false);
- OS.XSync (xDisplay, false);
- while (OS.XCheckMaskEvent (xDisplay, mask, event)) OS.XtDispatchEvent (event);
- OS.XtFree (event);
-}
-/**
- * If the receiver's user-interface thread was <code>sleep</code>ing,
- * causes it to be awakened and start running again. Note that this
- * method may be called from any thread.
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #sleep
- */
-public void wake () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- if (thread == Thread.currentThread ()) return;
- wakeThread ();
- }
-}
-void wakeThread () {
- /* Write a single byte to the wake up pipe */
- while (OS.write (write_fd, wake_buffer, 1) != 1) {/* empty */}
-}
-int wakeProc (int closure, int source, int id) {
- /* Read a single byte from the wake up pipe */
- while (OS.read (read_fd, wake_buffer, 1) != 1) {/* empty */}
- return 0;
-}
-static int wcsToMbcs (char ch) {
- return wcsToMbcs (ch, null);
-}
-static int wcsToMbcs (char ch, String codePage) {
- int key = ch & 0xFFFF;
- if (key <= 0x7F) return ch;
- byte [] buffer = Converter.wcsToMbcs (codePage, new char [] {ch}, false);
- if (buffer.length == 1) return (char) buffer [0];
- if (buffer.length == 2) {
- return (char) (((buffer [0] & 0xFF) << 8) | (buffer [1] & 0xFF));
- }
- return 0;
-}
-int windowTimerProc (int handle, int id) {
- Widget widget = getWidget (handle);
- if (widget == null) return 0;
- return widget.timerProc (id);
-}
-int windowProc (int w, int client_data, int call_data, int continue_to_dispatch) {
- Widget widget = getWidget (w);
- if (widget == null) return 0;
- return widget.windowProc (w, client_data, call_data, continue_to_dispatch);
-}
-String wrapText (String text, Font font, int width) {
- String Lf = "\n"; //$NON-NLS-1$
- text = convertToLf (text);
- int length = text.length ();
- if (width <= 0 || length == 0 || length == 1) return text;
- StringBuffer result = new StringBuffer ();
- int lineStart = 0, lineEnd = 0;
- while (lineStart < length) {
- lineEnd = text.indexOf (Lf, lineStart);
- boolean noLf = lineEnd == -1;
- if (noLf) lineEnd = length;
- int nextStart = lineEnd + Lf.length ();
- while (lineEnd > lineStart + 1 && Compatibility.isWhitespace (text.charAt (lineEnd - 1))) {
- lineEnd--;
- }
- int wordStart = lineStart, wordEnd = lineStart;
- int i = lineStart;
- while (i < lineEnd) {
- int lastStart = wordStart, lastEnd = wordEnd;
- wordStart = i;
- while (i < lineEnd && !Compatibility.isWhitespace (text.charAt (i))) {
- i++;
- }
- wordEnd = i - 1;
- String line = text.substring (lineStart, wordEnd + 1);
- int lineWidth = textWidth (line, font);
- while (i < lineEnd && Compatibility.isWhitespace (text.charAt (i))) {
- i++;
- }
- if (lineWidth > width) {
- if (lastStart == wordStart) {
- while (wordStart < wordEnd) {
- line = text.substring (lineStart, wordStart + 1);
- lineWidth = textWidth (line, font);
- if (lineWidth >= width) break;
- wordStart++;
- }
- if (wordStart == lastStart) wordStart++;
- lastEnd = wordStart - 1;
- }
- line = text.substring (lineStart, lastEnd + 1);
- result.append (line); result.append (Lf);
- i = wordStart; lineStart = wordStart; wordEnd = wordStart;
- }
- }
- if (lineStart < lineEnd) {
- result.append (text.substring (lineStart, lineEnd));
- }
- if (!noLf) {
- result.append (Lf);
- }
- lineStart = nextStart;
- }
- return result.toString ();
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java
deleted file mode 100755
index 363448ab89..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java
+++ /dev/null
@@ -1,650 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class allow the user to navigate
- * the file system and select or enter a file name.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SAVE, OPEN, MULTI</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles SAVE and OPEN may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#filedialog">FileDialog snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class FileDialog extends Dialog {
- int dialog;
- String [] filterNames = new String [0];
- String [] filterExtensions = new String [0];
- String [] fileNames = new String [0];
- String fileName = ""; //$NON-NLS-1$
- String filterPath = ""; //$NON-NLS-1$
- String fullPath;
- int filterIndex = -1;
- boolean overwrite = false;
- static final String FILTER = "*"; //$NON-NLS-1$
- static final char SEPARATOR = System.getProperty ("file.separator").charAt (0); //$NON-NLS-1$
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FileDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SAVE
- * @see SWT#OPEN
- * @see SWT#MULTI
- */
-public FileDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-int cancelPressed (int widget, int client, int call) {
- OS.XtUnmanageChild (widget);
- return 0;
-}
-/**
- * Returns the path of the first file that was
- * selected in the dialog relative to the filter path, or an
- * empty string if no such file has been selected.
- *
- * @return the relative path of the file
- */
-public String getFileName () {
- return fileName;
-}
-
-/**
- * Returns a (possibly empty) array with the paths of all files
- * that were selected in the dialog relative to the filter path.
- *
- * @return the relative paths of the files
- */
-public String [] getFileNames () {
- return fileNames;
-}
-
-/**
- * Returns the file extensions which the dialog will
- * use to filter the files it shows.
- *
- * @return the file extensions filter
- */
-public String [] getFilterExtensions () {
- return filterExtensions;
-}
-
-/**
- * Get the 0-based index of the file extension filter
- * which was selected by the user, or -1 if no filter
- * was selected.
- * <p>
- * This is an index into the FilterExtensions array and
- * the FilterNames array.
- * </p>
- *
- * @return index the file extension filter index
- *
- * @see #getFilterExtensions
- * @see #getFilterNames
- *
- * @since 3.4
- */
-public int getFilterIndex () {
- return filterIndex;
-}
-
-/**
- * Returns the names that describe the filter extensions
- * which the dialog will use to filter the files it shows.
- *
- * @return the list of filter names
- */
-public String [] getFilterNames () {
- return filterNames;
-}
-
-/**
- * Returns the directory path that the dialog will use, or an empty
- * string if this is not set. File names in this path will appear
- * in the dialog, filtered according to the filter extensions.
- *
- * @return the directory path string
- *
- * @see #setFilterExtensions
- */
-public String getFilterPath () {
- return filterPath;
-}
-
-/**
- * Returns the flag that the dialog will use to
- * determine whether to prompt the user for file
- * overwrite if the selected file already exists.
- *
- * @return true if the dialog will prompt for file overwrite, false otherwise
- *
- * @since 3.4
- */
-public boolean getOverwrite () {
- return overwrite;
-}
-
-int itemSelected (int widget, int client, int call) {
- /* this callback will only be hooked if the dialog style is MULTI */
- int fileList = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST);
- if (fileList == 0) return 0;
- int selectionText = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_TEXT);
- if (selectionText == 0) return 0;
-
- int [] argList = {OS.XmNselectedItems, 0, OS.XmNselectedItemCount, 0};
- OS.XtGetValues (fileList, argList, argList.length / 2);
- int items = argList [1], itemCount = argList [3];
- int ptr = 0;
- if (itemCount == 0) {
- int [] argList2 = {OS.XmNdirectory, 0};
- OS.XtGetValues (dialog, argList2, argList2.length / 2);
- ptr = argList2 [1];
- } else {
- int [] buffer = new int [1];
- OS.memmove (buffer, items, 4);
- ptr = buffer [0];
- }
- if (ptr == 0) return 0;
- Display display = parent.getDisplay ();
- int [] table = new int [] {display.tabMapping, display.crMapping};
- int address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- table,
- table.length,
- OS.XmOUTPUT_ALL);
- if (itemCount == 0) OS.XmStringFree (ptr);
- if (address == 0) return 0;
- int length = OS.strlen (address);
- byte [] buffer = new byte [length + 1];
- OS.memmove (buffer, address, length);
- OS.XtFree (address);
-
- OS.XmTextSetString (selectionText, buffer);
- OS.XmTextSetInsertionPosition (selectionText, OS.XmTextGetLastPosition (selectionText));
- return 0;
-}
-
-int okPressed (int widget, int client, int call) {
- String fullPath = null, fileName = null;
- String [] fileNames = null;
-
- int [] argList = {OS.XmNdirSpec, 0, OS.XmNdirectory, 0};
- OS.XtGetValues (dialog, argList, argList.length / 2);
-
- int xmString1 = argList [1];
- Display display = parent.getDisplay ();
- int [] table = new int [] {display.tabMapping, display.crMapping};
- int ptr = OS.XmStringUnparse (
- xmString1,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- table,
- table.length,
- OS.XmOUTPUT_ALL);
- if (ptr != 0) {
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, length);
- OS.XtFree (ptr);
- /* Use the character encoding for the default locale */
- fullPath = new String (Converter.mbcsToWcs (null, buffer)).trim();
- }
- OS.XmStringFree (xmString1);
-
- filterIndex = filterExtensions == null || filterExtensions.length == 0 ? -1 : 0;
- if ((style & SWT.MULTI) != 0) {
- int fileList = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST);
- if (fileList == 0) return 0;
- int [] argList2 = {OS.XmNselectedItems, 0, OS.XmNselectedItemCount, 0};
- OS.XtGetValues (fileList, argList2, argList2.length / 2);
- int items = argList2 [1], itemCount = argList2 [3];
- int [] buffer1 = new int [1];
- fileNames = new String [itemCount];
- boolean match = false;
- for (int i = 0; i < itemCount; i++) {
- OS.memmove (buffer1, items, 4);
- ptr = buffer1 [0];
- int address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- table,
- table.length,
- OS.XmOUTPUT_ALL);
- if (address != 0) {
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- OS.XtFree (address);
- /* Use the character encoding for the default locale */
- String fullFilename = new String (Converter.mbcsToWcs (null, buffer));
- int index = fullFilename.lastIndexOf (SEPARATOR);
- fileNames [i] = fullFilename.substring (index + 1, fullFilename.length ());
- if (fullFilename.equals (fullPath)) match = true;
- }
- items += 4;
- }
- if (match) {
- fileName = fileNames [0];
- } else {
- /* The user has modified the text field such that it doesn't match any
- * of the selected files, so use this value instead
- */
- int index = fullPath.lastIndexOf (SEPARATOR);
- fileName = fullPath.substring (index + 1, fullPath.length ());
- fileNames = new String [] {fileName};
- }
- } else {
- int index = fullPath.lastIndexOf (SEPARATOR);
- fileName = fullPath.substring (index + 1, fullPath.length ());
- fileNames = new String [] {fileName};
- }
-
- // if no file selected then go into the current directory
- if (fileName.equals("")) { //$NON-NLS-1$
- int [] argList1 = {OS.XmNdirMask, 0};
- OS.XtGetValues (dialog, argList1, argList1.length / 2);
- int directoryHandle = argList1[1];
- int [] argList2 = {OS.XmNpattern,directoryHandle};
- OS.XtSetValues (dialog, argList2, argList2.length / 2);
- OS.XmStringFree (directoryHandle);
- return 0;
- }
-
- int xmString2 = argList [3];
- ptr = OS.XmStringUnparse (
- xmString2,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- table,
- table.length,
- OS.XmOUTPUT_ALL);
- if (ptr != 0) {
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, length);
- OS.XtFree (ptr);
- /* Use the character encoding for the default locale */
- filterPath = new String (Converter.mbcsToWcs (null, buffer));
- }
- OS.XmStringFree (xmString2);
- int length = filterPath.length ();
- if (length > 0) {
- if (filterPath.charAt (length - 1) == SEPARATOR) {
- filterPath = filterPath.substring (0, length - 1);
- }
- }
-
- this.fullPath = fullPath;
- this.fileName = fileName;
- this.fileNames = fileNames;
- OS.XtUnmanageChild (widget);
- return 0;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a string describing the absolute path of the first selected file,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public String open () {
- /* Compute the dialog title */
- /*
- * Feature in Motif. It is not possible to set a shell
- * title to an empty string. The fix is to set the title
- * to be a single space.
- */
- String string = title;
- if (string.length () == 0) string = " "; //$NON-NLS-1$
- /* Use the character encoding for the default locale */
- byte [] buffer1 = Converter.wcsToMbcs (null, string, true);
- int xmStringPtr1 = OS.XmStringParseText (
- buffer1,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
-
- fullPath = null;
- fileNames = new String [0];
-
- /* Compute the filter */
- String mask = FILTER;
- if (filterExtensions == null) filterExtensions = new String [0];
- if (filterNames == null) filterNames = new String [0];
- if (filterExtensions.length != 0) {
- /* Motif does not support multiple filters, so ignore them
- * if there are more than one, or if there is a ; separator.
- */
- if (filterExtensions.length == 1) {
- String filter = filterExtensions [0];
- if (filter.indexOf (';', 0) == -1) mask = filter;
- }
- }
- /* Use the character encoding for the default locale */
- byte [] buffer2 = Converter.wcsToMbcs (null, mask, true);
- int xmStringPtr2 = OS.XmStringParseText (
- buffer2,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
-
- /* Compute the filter path */
- if (filterPath == null) filterPath = ""; //$NON-NLS-1$
- int length = filterPath.length ();
- if (length == 0 || filterPath.charAt (length - 1) != SEPARATOR) {
- filterPath += SEPARATOR;
- }
- /* Use the character encoding for the default locale */
- byte [] buffer3 = Converter.wcsToMbcs (null, filterPath, true);
- int xmStringPtr3 = OS.XmStringParseText (
- buffer3,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
-
- /* Create the dialog */
- boolean defaultPos = parent.isVisible ();
- Display display = parent.display;
- int [] argList1 = {
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNdialogStyle, OS.XmDIALOG_PRIMARY_APPLICATION_MODAL,
- OS.XmNwidth, OS.XDisplayWidth (display.xDisplay, OS.XDefaultScreen (display.xDisplay)) * 4 / 9,
- OS.XmNpathMode, OS.XmPATH_MODE_FULL,
- OS.XmNdialogTitle, xmStringPtr1,
- OS.XmNpattern, xmStringPtr2,
- OS.XmNdirMask, xmStringPtr3,
- OS.XmNdefaultPosition, defaultPos ? 1 : 0,
- };
- /*
- * Bug in AIX. The dialog does not respond to input, if the parent
- * is not realized. The fix is to realize the parent.
- */
- if (OS.IsAIX) parent.realizeWidget ();
- int parentHandle = parent.shellHandle;
- /*
- * Feature in Linux. For some reason, the XmCreateFileSelectionDialog()
- * will not accept NULL for the widget name. This works fine on the other
- * Motif platforms and in the other XmCreate calls on Linux. The fix is
- * to pass in a NULL terminated string, not a NULL pointer.
- */
- byte [] name = new byte [] {0};
- dialog = OS.XmCreateFileSelectionDialog (parentHandle, name, argList1, argList1.length / 2);
- int child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_HELP_BUTTON);
- if (child != 0) OS.XtUnmanageChild (child);
- OS.XmStringFree (xmStringPtr1);
- OS.XmStringFree (xmStringPtr2);
- OS.XmStringFree (xmStringPtr3);
-
- /*
- * Can override the selection text field if necessary now that
- * its initial value has been computed by the platform dialog.
- */
- if (fileName != null && fileName.length() > 0) {
- /* Use the character encoding for the default locale */
- byte [] buffer4 = Converter.wcsToMbcs (null, fileName, true);
- int xmStringPtr4 = OS.XmStringParseText (
- buffer4,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- int [] argList2 = {OS.XmNdirSpec, 0};
- OS.XtGetValues (dialog, argList2, argList2.length / 2);
- int oldDirSpec = argList2 [1];
- int newDirSpec = OS.XmStringConcat (oldDirSpec, xmStringPtr4);
- argList2 [1] = newDirSpec;
- OS.XtSetValues (dialog, argList2, argList2.length / 2);
- OS.XmStringFree (xmStringPtr4);
- OS.XmStringFree (oldDirSpec);
- OS.XmStringFree (newDirSpec);
- }
-
- /* Hook the callbacks. */
- Callback cancelCallback = new Callback (this, "cancelPressed", 3); //$NON-NLS-1$
- int cancelAddress = cancelCallback.getAddress ();
- if (cancelAddress == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- OS.XtAddCallback (dialog, OS.XmNcancelCallback, cancelAddress, 0);
- Callback okCallback = new Callback (this, "okPressed", 3); //$NON-NLS-1$
- int okAddress = okCallback.getAddress ();
- if (okAddress == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- OS.XtAddCallback (dialog, OS.XmNokCallback, okAddress, 0);
- Callback selectCallback = null;
- if ((style & SWT.MULTI) != 0) {
- child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST);
- if (child != 0) {
- int [] argList3 = {OS.XmNselectionPolicy, OS.XmEXTENDED_SELECT};
- OS.XtSetValues(child, argList3, argList3.length / 2);
- selectCallback = new Callback (this, "itemSelected", 3); //$NON-NLS-1$
- int selectAddress = selectCallback.getAddress ();
- if (selectAddress == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- OS.XtAddCallback (child, OS.XmNextendedSelectionCallback, selectAddress, 0);
- }
- }
-
- if (!defaultPos) {
- OS.XtRealizeWidget (dialog);
- int[] argList4 = new int[] {
- OS.XmNwidth, 0,
- OS.XmNheight, 0,
- };
- OS.XtGetValues (dialog, argList4, argList4.length / 2);
- Monitor monitor = parent.getMonitor ();
- Rectangle bounds = monitor.getBounds ();
- int x = bounds.x + (bounds.width - argList4 [1]) / 2;
- int y = bounds.y + (bounds.height - argList4 [3]) / 2;
- int[] argList5 = new int[] {
- OS.XmNx, x,
- OS.XmNy, y,
- };
- OS.XtSetValues (dialog, argList5, argList5.length / 2);
- }
- OS.XtManageChild (dialog);
-
- // Should be a pure OS message loop (no SWT AppContext)
- while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog))
- if (!display.readAndDispatch ()) display.sleep ();
-
- /* Destroy the dialog and update the display. */
- if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog);
- okCallback.dispose ();
- cancelCallback.dispose ();
- if (selectCallback != null) selectCallback.dispose ();
- return fullPath;
-}
-
-/**
- * Set the initial filename which the dialog will
- * select by default when opened to the argument,
- * which may be null. The name will be prefixed with
- * the filter path when one is supplied.
- *
- * @param string the file name
- */
-public void setFileName (String string) {
- fileName = string;
-}
-
-/**
- * Set the file extensions which the dialog will
- * use to filter the files it shows to the argument,
- * which may be null.
- * <p>
- * The strings are platform specific. For example, on
- * some platforms, an extension filter string is typically
- * of the form "*.extension", where "*.*" matches all files.
- * For filters with multiple extensions, use semicolon as
- * a separator, e.g. "*.jpg;*.png".
- * </p>
- *
- * @param extensions the file extension filter
- *
- * @see #setFilterNames to specify the user-friendly
- * names corresponding to the extensions
- */
-public void setFilterExtensions (String [] extensions) {
- filterExtensions = extensions;
-}
-
-/**
- * Set the 0-based index of the file extension filter
- * which the dialog will use initially to filter the files
- * it shows to the argument.
- * <p>
- * This is an index into the FilterExtensions array and
- * the FilterNames array.
- * </p>
- *
- * @param index the file extension filter index
- *
- * @see #setFilterExtensions
- * @see #setFilterNames
- *
- * @since 3.4
- */
-public void setFilterIndex (int index) {
- filterIndex = index;
-}
-
-/**
- * Sets the names that describe the filter extensions
- * which the dialog will use to filter the files it shows
- * to the argument, which may be null.
- * <p>
- * Each name is a user-friendly short description shown for
- * its corresponding filter. The <code>names</code> array must
- * be the same length as the <code>extensions</code> array.
- * </p>
- *
- * @param names the list of filter names, or null for no filter names
- *
- * @see #setFilterExtensions
- */
-public void setFilterNames (String [] names) {
- filterNames = names;
-}
-
-/**
- * Sets the directory path that the dialog will use
- * to the argument, which may be null. File names in this
- * path will appear in the dialog, filtered according
- * to the filter extensions. If the string is null,
- * then the operating system's default filter path
- * will be used.
- * <p>
- * Note that the path string is platform dependent.
- * For convenience, either '/' or '\' can be used
- * as a path separator.
- * </p>
- *
- * @param string the directory path
- *
- * @see #setFilterExtensions
- */
-public void setFilterPath (String string) {
- filterPath = string;
-}
-
-/**
- * Sets the flag that the dialog will use to
- * determine whether to prompt the user for file
- * overwrite if the selected file already exists.
- *
- * @param overwrite true if the dialog will prompt for file overwrite, false otherwise
- *
- * @since 3.4
- */
-public void setOverwrite (boolean overwrite) {
-// this.overwrite = overwrite;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java
deleted file mode 100755
index 7107e8e7f6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java
+++ /dev/null
@@ -1,1176 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.layout.*;
-
-import java.util.*;
-
-/**
- * Instances of this class allow the user to select a font
- * from all available fonts in the system.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class FontDialog extends Dialog {
- private FontData [] fontData;
- private FontData currentFontData;
- private Font sampleFont; // the displayed sample font
- private Color sampleColor; // the displayed sample color
- private RGB rgb;
- private boolean okSelected = false;
- private boolean ignoreEvents = false;
- /*
- * Table containing all available fonts as FontData objects.
- * The table is structured as a series of embedded Hashtables as follows:
- * <br>characterRegistryName -> faceName -> extendedStyle -> size -> style
- */
- private Hashtable characterSets = new Hashtable ();
-
- // widgets
- private Shell shell;
- private List fontSetList;
- private List charSetList, faceNameList, extStyleList;
- private List fontStyleList, fontSizeList;
- private Label sampleLabel;
- private Button upButton, downButton, newButton, removeButton;
- private Button okButton, cancelButton, colorButton;
-
- // constants
- private static final String TEXT_SAMPLE = "AaBbYyZz";
- private static String SCALABLE_SIZES [];
- private static final int DEFAULT_SIZE = 14;
- private static final String DEFAULT_STYLE = "medium";
- private static final Integer SCALABLE_KEY = new Integer (0);
- private static final int LIST_WIDTH = 200;
- private static final int EXTSTYLE_WIDTH = 150;
- private static final int LIST_HEIGHT = 150;
- private static final int SAMPLE_HEIGHT = 75;
- private static final String PREFIX_ISO8859 = "iso8859";
- private static final String PREFIX_ISO646 = "iso646";
- private static final String PREFIX_UNICODE = "ucs";
- private static final String PREFIX_JAPANESE = "jis";
- private static final String PREFIX_SIMPLIFIEDCHINESE = "gb";
- private static final String PREFIX_TRADITIONALCHINESE = "cns";
- private static final String PREFIX_KOREAN = "ks";
- private static final String [] ISO_CHARSETS = new String [] {
- "", // 0 undefined
- SWT.getMessage ("SWT_Charset_Western"),
- SWT.getMessage ("SWT_Charset_EastEuropean"),
- SWT.getMessage ("SWT_Charset_SouthEuropean"),
- SWT.getMessage ("SWT_Charset_NorthEuropean"),
- SWT.getMessage ("SWT_Charset_Cyrillic"),
- SWT.getMessage ("SWT_Charset_Arabic"),
- SWT.getMessage ("SWT_Charset_Greek"),
- SWT.getMessage ("SWT_Charset_Hebrew"),
- SWT.getMessage ("SWT_Charset_Turkish"),
- SWT.getMessage ("SWT_Charset_Nordic"),
- SWT.getMessage ("SWT_Charset_Thai"),
- "", // 12 undefined
- SWT.getMessage ("SWT_Charset_BalticRim"),
- SWT.getMessage ("SWT_Charset_Celtic"),
- SWT.getMessage ("SWT_Charset_Euro"),
- SWT.getMessage ("SWT_Charset_Romanian")
- };
-
- static {
- SCALABLE_SIZES = new String [69];
- for (int i = 0; i < 69; i++) {
- SCALABLE_SIZES [i] = String.valueOf (i + 4);
- }
- }
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FontDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FontDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-/**
- * Add the fonts found in 'fonts' to the list of fonts.
- * Fonts are stored by character set and face name. For each character
- * set/face name combination there is one FontExtStyles object that
- * captures the different extended styles and the sizes and styles
- * available for that extended style.
- */
-void addFonts (FontData fonts []) {
- for (int i = 0; i < fonts.length; i++) {
- FontData font = fonts [i];
- String charSetName = getTranslatedCharSet (font, true);
- Hashtable charSet = (Hashtable) characterSets.get (charSetName);
- if (charSet == null) {
- charSet = new Hashtable (9);
- characterSets.put (charSetName, charSet);
- }
-
- String faceName = getTranslatedFaceName (font);
- Hashtable faceSet = (Hashtable) charSet.get (faceName);
- if (faceSet == null) {
- faceSet = new Hashtable (9);
- charSet.put (faceName, faceSet);
- }
-
- String extStyleName = font.addStyle;
- Hashtable extStyleSet = (Hashtable) faceSet.get (extStyleName);
- if (extStyleSet == null) {
- extStyleSet = new Hashtable (9);
- faceSet.put (extStyleName, extStyleSet);
- }
-
- Integer sizeValue = new Integer (font.getHeight ());
- Hashtable sizeSet = (Hashtable) extStyleSet.get (sizeValue);
- if (sizeSet == null) {
- sizeSet = new Hashtable (9);
- extStyleSet.put (sizeValue, sizeSet);
- }
-
- String style = font.weight;
- sizeSet.put (style,font);
- }
-}
-
-void centerListIndex (List list, int index) {
- int visibleItems = list.getSize ().y / list.getItemHeight ();
- int topIndex = Math.max (0, index - visibleItems / 2);
- list.setTopIndex (topIndex);
-}
-
-FontData copyFontData (FontData data) {
- FontData result = new FontData ();
- result.addStyle = data.addStyle;
- result.averageWidth = data.averageWidth;
- result.characterSetName = data.characterSetName;
- result.characterSetRegistry = data.characterSetRegistry;
- result.fontFamily = data.fontFamily;
- result.foundry = data.foundry;
- result.horizontalResolution = data.horizontalResolution;
- result.pixels = data.pixels;
- result.points = data.points;
- result.setWidth = data.setWidth;
- result.slant = data.slant;
- result.spacing = data.spacing;
- result.verticalResolution = data.verticalResolution;
- result.weight = data.weight;
- return result;
-}
-
-void createButtons (Composite parent) {
- int buttonAlignment = GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING;
- okButton = new Button (parent, SWT.PUSH);
- okButton.setText (SWT.getMessage ("SWT_OK"));
- okButton.setLayoutData (new GridData (buttonAlignment));
- shell.setDefaultButton (okButton);
-
- cancelButton = new Button (parent, SWT.PUSH);
- cancelButton.setText (SWT.getMessage ("SWT_Cancel"));
- cancelButton.setLayoutData (new GridData (buttonAlignment));
-
- colorButton = new Button (parent, SWT.PUSH);
- colorButton.setText (SWT.getMessage ("SWT_Color"));
- colorButton.setLayoutData (new GridData (buttonAlignment));
-}
-
-void createControls (Composite parent) {
- Composite composite = new Composite (parent, SWT.NONE);
- GridLayout layout = new GridLayout ();
- layout.numColumns = 2;
- composite.setLayout (layout);
-
- Composite controls = new Composite (composite, SWT.NONE);
- layout = new GridLayout ();
- layout.marginHeight = layout.marginWidth = 0;
- layout.numColumns = 3;
- controls.setLayout (layout);
-
- // labels row (1)
- new Label (controls, SWT.NONE).setText (SWT.getMessage ("SWT_Character_set") + ":");
- new Label (controls, SWT.NONE).setText (SWT.getMessage ("SWT_Font") + ":");
- new Label (controls, SWT.NONE).setText (SWT.getMessage ("SWT_Extended_style") + ":");
-
- // lists row (2)
- charSetList = new List (controls, SWT.V_SCROLL | SWT.BORDER);
- GridData gridData = new GridData (GridData.FILL_HORIZONTAL);
- gridData.heightHint = LIST_HEIGHT;
- gridData.widthHint = LIST_WIDTH;
- charSetList.setLayoutData (gridData);
-
- faceNameList = new List (controls, SWT.V_SCROLL | SWT.BORDER);
- gridData = new GridData (GridData.FILL_HORIZONTAL);
- gridData.heightHint = LIST_HEIGHT;
- gridData.widthHint = LIST_WIDTH;
- faceNameList.setLayoutData (gridData);
-
- extStyleList = new List (controls, SWT.V_SCROLL | SWT.MULTI | SWT.BORDER);
- gridData = new GridData (GridData.FILL_HORIZONTAL);
- gridData.heightHint = LIST_HEIGHT;
- gridData.widthHint = EXTSTYLE_WIDTH;
- extStyleList.setLayoutData (gridData);
-
- // labels row (3)
- new Label (controls, SWT.NONE).setText (SWT.getMessage ("SWT_Size") + ":");
- new Label (controls, SWT.NONE).setText (SWT.getMessage ("SWT_Style") + ":");
- new Label (controls, SWT.NONE); // filler
-
- // lists row (4)
- fontSizeList = new List (controls, SWT.V_SCROLL | SWT.BORDER);
- gridData = new GridData (GridData.FILL_HORIZONTAL);
- gridData.heightHint = LIST_HEIGHT;
- gridData.widthHint = LIST_WIDTH;
- fontSizeList.setLayoutData (gridData);
-
- fontStyleList = new List (controls, SWT.V_SCROLL | SWT.BORDER);
- gridData = new GridData (GridData.FILL_HORIZONTAL);
- gridData.heightHint = LIST_HEIGHT;
- gridData.widthHint = LIST_WIDTH;
- fontStyleList.setLayoutData (gridData);
-
- new Label (controls, SWT.NONE); // filler
-
- // font sets group
- Group fontSetGroup = new Group (controls, SWT.NONE);
- fontSetGroup.setText(SWT.getMessage ("SWT_FontSet"));
- layout = new GridLayout ();
- layout.numColumns = 2;
- fontSetGroup.setLayout (layout);
- GridData data = new GridData (GridData.FILL_BOTH);
- data.horizontalSpan = 3;
- fontSetGroup.setLayoutData (data);
-
- fontSetList = new List (fontSetGroup, SWT.V_SCROLL | SWT.BORDER);
- data = new GridData (GridData.FILL_BOTH);
- data.grabExcessHorizontalSpace = true;
- fontSetList.setLayoutData (data);
-
- Composite buttonsGroup = new Composite (fontSetGroup, SWT.NONE);
- layout = new GridLayout ();
- layout.numColumns = 3;
- layout.makeColumnsEqualWidth = false;
- layout.marginHeight = layout.marginWidth = 0;
- layout.horizontalSpacing = layout.verticalSpacing = 0;
- buttonsGroup.setLayout (layout);
-
- Composite upDownButtonsGroup = new Composite (buttonsGroup, SWT.NONE);
- layout = new GridLayout ();
- layout.marginHeight = layout.marginWidth = 0;
- layout.horizontalSpacing = layout.verticalSpacing = 0;
- upDownButtonsGroup.setLayout(layout);
-
- int buttonAlignment = GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING;
- upButton = new Button (upDownButtonsGroup, SWT.PUSH);
- upButton.setLayoutData (new GridData (buttonAlignment));
- upButton.setText (SWT.getMessage ("SWT_Up"));
- downButton = new Button (upDownButtonsGroup, SWT.PUSH);
- downButton.setLayoutData (new GridData (buttonAlignment));
- downButton.setText (SWT.getMessage ("SWT_Down"));
-
- new Label (buttonsGroup, SWT.SEPARATOR | SWT.VERTICAL);
-
- Composite newRemoveButtonsGroup = new Composite (buttonsGroup, SWT.NONE);
- layout = new GridLayout ();
- layout.marginHeight = layout.marginWidth = 0;
- layout.horizontalSpacing = layout.verticalSpacing = 0;
- newRemoveButtonsGroup.setLayout(layout);
-
- newButton = new Button (newRemoveButtonsGroup, SWT.PUSH);
- newButton.setLayoutData (new GridData (buttonAlignment));
- newButton.setText (SWT.getMessage ("SWT_NewFont"));
- removeButton = new Button (newRemoveButtonsGroup, SWT.PUSH);
- removeButton.setLayoutData (new GridData (buttonAlignment));
- removeButton.setText (SWT.getMessage ("SWT_Remove"));
-
- // font sample group
- Group sampleGroup = new Group (controls, SWT.NONE);
- sampleGroup.setText (SWT.getMessage ("SWT_Sample"));
- gridData = new GridData ();
- gridData.heightHint = SAMPLE_HEIGHT;
- gridData.horizontalSpan = 3;
- gridData.horizontalAlignment = GridData.FILL;
- sampleGroup.setLayoutData (gridData);
- layout = new GridLayout ();
- layout.marginWidth = 10;
- layout.marginHeight = 10;
- sampleGroup.setLayout (layout);
-
- sampleLabel = new Label (sampleGroup, SWT.CENTER);
- sampleLabel.setText (TEXT_SAMPLE);
- gridData = new GridData ();
- gridData.grabExcessHorizontalSpace = true;
- gridData.grabExcessVerticalSpace = true;
- gridData.verticalAlignment = GridData.FILL;
- gridData.horizontalAlignment = GridData.FILL;
- sampleLabel.setLayoutData (gridData);
-
- Composite okCancelGroup = new Composite (composite, SWT.NONE);
- layout = new GridLayout ();
- layout.marginHeight = layout.marginWidth = layout.verticalSpacing = 0;
- okCancelGroup.setLayout (layout);
- okCancelGroup.setLayoutData (new GridData (GridData.VERTICAL_ALIGN_BEGINNING));
- createButtons (okCancelGroup);
-}
-
-Hashtable getExtStyles (String charsetName, String faceName) {
- Hashtable faces = getFaces (charsetName);
- if (faces == null) return null;
- return (Hashtable) faces.get (faceName);
-}
-
-Hashtable getFaces (String charsetName) {
- return (Hashtable) getFonts ().get (charsetName);
-}
-
-/**
- * Returns a FontData object describing the font that was
- * selected in the dialog, or null if none is available.
- *
- * @return the FontData for the selected font, or null
- * @deprecated use #getFontList ()
- */
-public FontData getFontData () {
- if (fontData != null && fontData.length > 0) {
- return fontData [0];
- }
- return null;
-
-}
-
-FontData getFontData (String charsetName, String faceName, String extStyle, int size, String style) {
- Hashtable styles = getStyles (charsetName, faceName, extStyle, size);
- if (styles == null) return null;
- return (FontData) styles.get (style);
-}
-
-/**
- * Returns a FontData set describing the font that was
- * selected in the dialog, or null if none is available.
- *
- * @return the FontData for the selected font, or null
- * @since 2.1.1
- */
-public FontData [] getFontList () {
- return fontData;
-}
-
-/**
- * Returns the collection of fonts that are displayed by the
- * receiver.
- * See the class definition for an explanation of the structure
- * of the returned Hashtable.
- */
-Hashtable getFonts () {
- return characterSets;
-}
-
-String getListSelection (List list) {
- String [] selection = list.getSelection ();
- if (selection.length > 0) return selection [0];
- return "";
-}
-
-/**
- * Returns an RGB describing the color that was selected
- * in the dialog, or null if none is available.
- *
- * @return the RGB value for the selected color, or null
- *
- * @see PaletteData#getRGBs
- *
- * @since 2.1
- */
-public RGB getRGB () {
- return rgb;
-}
-
-/**
- * Returns a FontData object that can be used to load the selected
- * font.
- */
-FontData getSelectionFontData () {
- String charSetName = getListSelection (charSetList);
- String faceName = getListSelection (faceNameList);
- String extStyle = getListSelection (extStyleList);
- int size = DEFAULT_SIZE;
- try {
- size = Integer.valueOf (getListSelection (fontSizeList)).intValue ();
- if (size < 1) size = DEFAULT_SIZE;
- } catch (NumberFormatException e) {
- /*
- * This block is purposely left empty since a default
- * value is already specified above.
- */
- }
- String style = getListSelection (fontStyleList);
- FontData result = getFontData (charSetName, faceName, extStyle, size, style);
-
- if (result != null) {
- result = copyFontData (result);
- } else {
- /*
- * One or more of the dialog's widgets contain custom typed values.
- * Create a FontData that mirrors these values so that the Font created
- * below will try to find the best match.
- */
- result = new FontData ();
- result.characterSetRegistry = charSetName;
- result.setName (faceName);
- result.addStyle = extStyle;
- result.weight = style;
- }
- result.setHeight (size);
- return result;
-}
-
-Hashtable getSizes (String charsetName, String faceName, String extStyle) {
- Hashtable extStyles = getExtStyles (charsetName, faceName);
- if (extStyles == null) return null;
- return (Hashtable) extStyles.get (extStyle);
-}
-
-Hashtable getStyles (String charsetName, String faceName, String extStyle, int size) {
- Hashtable sizes = getSizes (charsetName, faceName, extStyle);
- if (sizes == null) return null;
- Hashtable result = (Hashtable) sizes.get (new Integer (size));
- if (result == null)
- result = (Hashtable) sizes.get (SCALABLE_KEY);
- return result;
-}
-
-/**
- * Returns the character set found in 'fontData' prefixed
- * with a string explaining the character set.
- */
-String getTranslatedCharSet (FontData fontData, boolean includeDescription) {
- String characterSet = fontData.characterSetRegistry;
- String translatedCharSet = null;
-
- if (characterSet.startsWith (PREFIX_ISO8859)) {
- int charSetName = 1;
- try {
- charSetName = Integer.valueOf (fontData.characterSetName).intValue ();
- } catch (NumberFormatException e) {
- /*
- * This block is purposely left empty since a default
- * value is already specified above.
- */
- }
- characterSet = PREFIX_ISO8859 + "-" + charSetName;
- if (charSetName < ISO_CHARSETS.length) {
- translatedCharSet = ISO_CHARSETS [charSetName];
- }
- }
- else
- if (characterSet.startsWith (PREFIX_ISO646)) {
- translatedCharSet = SWT.getMessage("SWT_Charset_ASCII");
- }
- else
- if (characterSet.startsWith (PREFIX_UNICODE)) {
- translatedCharSet = SWT.getMessage("SWT_Charset_Unicode");
- }
- else
- if (characterSet.startsWith (PREFIX_JAPANESE)) {
- translatedCharSet = SWT.getMessage("SWT_Charset_Japanese");
- }
- else
- if (characterSet.startsWith (PREFIX_SIMPLIFIEDCHINESE)) {
- translatedCharSet = SWT.getMessage("SWT_Charset_SimplifiedChinese");
- }
- else
- if (characterSet.startsWith (PREFIX_TRADITIONALCHINESE)) {
- translatedCharSet = SWT.getMessage("SWT_Charset_TraditionalChinese");
- }
- else
- if (characterSet.startsWith (PREFIX_KOREAN)) {
- translatedCharSet = SWT.getMessage("SWT_Charset_Korean");
- }
- if (includeDescription && translatedCharSet != null) {
- translatedCharSet = characterSet + " (" + translatedCharSet + ')';
- }
- else {
- translatedCharSet = characterSet;
- }
- return translatedCharSet;
-}
-
-/**
- * Returns the face name as specified in FontData.familyName followed by
- * the foundry set in parantheses if available.
- * We display the face name first so that the list sorts the fonts by
- * face name, not by foundry. Users generally want to select fonts based
- * on the face name and not by foundry. Once they've found the desired
- * face name in the list they can compare the font variations from
- * different foundries if available.
- */
-String getTranslatedFaceName (FontData fontData) {
- StringBuffer faceNameBuffer;
-
- if (fontData.foundry != null && fontData.foundry.length () > 0) {
- faceNameBuffer = new StringBuffer (fontData.fontFamily);
- faceNameBuffer.append (" (");
- faceNameBuffer.append (fontData.foundry);
- faceNameBuffer.append (')');
- }
- else {
- faceNameBuffer = new StringBuffer (fontData.getName ());
- }
- return faceNameBuffer.toString ();
-}
-
-/**
- * Handle the events the receiver is listening to.
- * List selections cause the downstream lists to be initialized
- * with font data and the sample text to be updated.
- */
-void handleEvent (Event event) {
- if (ignoreEvents) return;
- if (event.widget instanceof List) {
- List list = (List) event.widget;
- String text = getListSelection (list);
- int oldSelectIndex = ((Integer)list.getData ()).intValue ();
- int newSelectIndex = list.indexOf (text);
- if (oldSelectIndex != newSelectIndex || newSelectIndex == -1) {
- ignoreEvents = true;
- if (list == charSetList) initFaceNameList ();
- else if (list == faceNameList) initExtStyleList ();
- else if (list == extStyleList) initSizeList ();
- else if (list == fontSizeList) initStyleList ();
- else if (event.widget == fontSetList) {
- currentFontData = fontData [fontSetList.getSelectionIndex ()];
- setFontControls (currentFontData);
- updateButtonEnablements ();
- }
-
- updateSampleFont ();
- updateFontList ();
- list.setData (new Integer (newSelectIndex));
- if (newSelectIndex != -1) {
- list.select (newSelectIndex);
- }
- ignoreEvents = false;
- }
- return;
- }
-
- if (event.widget instanceof Button) {
- if (event.widget == okButton) {
- okSelected = true;
- shell.close ();
- }
- else if (event.widget == cancelButton) {
- okSelected = false;
- shell.close ();
- }
- else if (event.widget == colorButton) {
- ColorDialog colorDialog = new ColorDialog (shell, SWT.NONE);
- colorDialog.setRGB (rgb);
- RGB newRgb = colorDialog.open ();
- if (newRgb != null) {
- rgb = newRgb;
- updateSampleColor ();
- }
- }
- else if (event.widget == newButton) {
- FontData [] newFontData = new FontData [fontData.length + 1];
- System.arraycopy (fontData, 0, newFontData, 0, fontData.length);
- FontData source = fontData [fontSetList.getSelectionIndex ()];
- FontData newFd = copyFontData (source);
- newFontData [newFontData.length - 1] = newFd;
- this.fontData = newFontData;
- updateFontList ();
- fontSetList.select (newFontData.length - 1);
- fontSetList.setData (new Integer (newFontData.length - 1));
- fontSetList.showSelection();
- updateButtonEnablements ();
- }
- else if (event.widget == removeButton) {
- int selectionIndex = fontSetList.getSelectionIndex ();
- FontData [] newFontData = new FontData [fontData.length - 1];
- System.arraycopy (fontData, 0, newFontData, 0, selectionIndex);
- System.arraycopy (fontData, selectionIndex + 1, newFontData, selectionIndex, newFontData.length - selectionIndex);
- fontData = newFontData;
- updateFontList ();
- updateButtonEnablements ();
- setFontControls (fontData [fontSetList.getSelectionIndex ()]);
- }
- else if (event.widget == upButton) {
- int selectionIndex = fontSetList.getSelectionIndex ();
- FontData temp = fontData [selectionIndex];
- fontData [selectionIndex] = fontData [selectionIndex - 1];
- fontData [selectionIndex - 1] = temp;
- fontSetList.select (selectionIndex - 1);
- fontSetList.setData (new Integer (selectionIndex - 1));
- updateFontList ();
- updateButtonEnablements ();
- }
- else if (event.widget == downButton) {
- int selectionIndex = fontSetList.getSelectionIndex ();
- FontData temp = fontData [selectionIndex];
- fontData [selectionIndex] = fontData [selectionIndex + 1];
- fontData [selectionIndex + 1] = temp;
- fontSetList.select (selectionIndex + 1);
- fontSetList.setData (new Integer (selectionIndex + 1));
- updateFontList ();
- updateButtonEnablements ();
- }
- }
-}
-
-void hookListeners () {
- Listener listener = new Listener () {
- public void handleEvent (Event event) {
- FontDialog.this.handleEvent (event);
- }
- };
- okButton.addListener (SWT.Selection, listener);
- cancelButton.addListener (SWT.Selection, listener);
- colorButton.addListener (SWT.Selection, listener);
- charSetList.addListener (SWT.Selection, listener);
- faceNameList.addListener (SWT.Selection, listener);
- fontStyleList.addListener (SWT.Selection, listener);
- extStyleList.addListener (SWT.Selection, listener);
- fontSizeList.addListener (SWT.Selection, listener);
- newButton.addListener (SWT.Selection, listener);
- removeButton.addListener (SWT.Selection, listener);
- upButton.addListener (SWT.Selection, listener);
- downButton.addListener (SWT.Selection, listener);
- fontSetList.addListener (SWT.Selection, listener);
-}
-
-/**
- * Initialize the extended styles list with the extended styles
- * available for the selected font.
- * Downstream lists are initialized as well (style and size).
- */
-void initExtStyleList () {
- String oldSelect = getListSelection (extStyleList);
- extStyleList.removeAll ();
-
- String characterSet = getListSelection (charSetList);
- String faceName = getListSelection (faceNameList);
- Hashtable extStyles = getExtStyles (characterSet, faceName);
- setItemsSorted (extStyleList, extStyles);
-
- int selectIndex = extStyleList.indexOf (oldSelect);
- extStyleList.select (selectIndex);
- extStyleList.setData (new Integer (selectIndex));
- centerListIndex (extStyleList, selectIndex);
- initSizeList ();
-}
-
-/**
- * Initialize the face name list with all font names
- * available in the selected character set.
- * Downstream lists are initialized as well (extended style).
- */
-void initFaceNameList () {
- String oldSelect = getListSelection (faceNameList);
- faceNameList.removeAll ();
- String charSetText = getListSelection (charSetList);
- if (charSetText.length () == 0) return;
-
- Hashtable faceNames = getFaces (charSetText);
- setItemsSorted (faceNameList, faceNames);
-
- int selectIndex = faceNameList.indexOf (oldSelect);
- selectIndex = Math.max (0, selectIndex);
- faceNameList.select (selectIndex);
- faceNameList.setData (new Integer (selectIndex));
- centerListIndex (faceNameList, selectIndex);
- initExtStyleList ();
-}
-
-/**
- * Initialize the widgets of the receiver with the data of
- * all installed fonts. If the user specified a default font
- * preselect that font in the lists.
- */
-void initFonts () {
- Display display = shell.display;
- // get all fonts available on the current display
- addFonts (display.getFontList (null, false));
- addFonts (display.getFontList (null, true));
- setItemsSorted (charSetList, getFonts ());
- if (fontData != null) {
- // verify that the initial font data is a valid font
- Font font = new Font (display, fontData);
- fontData = font.getFontData ();
- currentFontData = fontData [0];
- font.dispose ();
- } else {
- fontData = display.textFont.getFontData ();
- currentFontData = fontData [0];
- }
-}
-
-/**
- * Initialize the size list with the sizes the selected font
- * is available in. If the selected font is scalable a selection
- * of preset sizes is used.
- */
-void initSizeList () {
- String oldSelect = getListSelection (fontSizeList);
- fontSizeList.removeAll ();
-
- String characterSet = getListSelection (charSetList);
- String faceName = getListSelection (faceNameList);
- String extStyle = getListSelection (extStyleList);
- Hashtable sizes = getSizes (characterSet, faceName, extStyle);
- if (sizes != null) {
- if (sizes.get (SCALABLE_KEY) == null) {
- /*
- * Font is not scalable so just present the provided sizes.
- */
- setSizeItemsSorted (sizes.keys ());
- } else {
- /*
- * Font is scalable so present the provided sizes and scalable
- * sizes for selection.
- */
- Vector allSizes = new Vector ();
- /*
- * Add the scalable sizes.
- */
- for (int i = 0; i < SCALABLE_SIZES.length; i++) {
- allSizes.addElement (Integer.valueOf (SCALABLE_SIZES [i]));
- }
- /*
- * Add the provided sizes.
- */
- Enumeration providedSizes = sizes.keys ();
- while (providedSizes.hasMoreElements ()) {
- Integer size = (Integer) providedSizes.nextElement ();
- if (!size.equals (SCALABLE_KEY) && !allSizes.contains (size)) {
- allSizes.addElement (size);
- }
- }
- setSizeItemsSorted (allSizes.elements ());
- }
- }
-
- int selectIndex = fontSizeList.indexOf (oldSelect);
- if (selectIndex == -1) {
- selectIndex = fontSizeList.indexOf (String.valueOf (DEFAULT_SIZE));
- }
- selectIndex = Math.max (0, selectIndex);
- fontSizeList.select (selectIndex);
- fontSizeList.setData (new Integer (selectIndex));
- centerListIndex (fontSizeList, selectIndex);
- initStyleList ();
-}
-
-/**
- * Initialize the styles list with the styles the selected font
- * is available in.
- */
-void initStyleList () {
- String oldSelect = getListSelection (fontStyleList);
- fontStyleList.removeAll ();
-
- String characterSet = getListSelection (charSetList);
- String faceName = getListSelection (faceNameList);
- String extStyle = getListSelection (extStyleList);
- try {
- int size = Integer.valueOf (getListSelection (fontSizeList)).intValue ();
- if (size > 0) {
- Hashtable styles = getStyles (characterSet, faceName, extStyle, size);
- setItemsSorted (fontStyleList, styles);
- }
- } catch (NumberFormatException e) {
- // fall through
- }
-
- int selectIndex = fontStyleList.indexOf (oldSelect);
- if (selectIndex == -1) {
- selectIndex = fontStyleList.indexOf (String.valueOf (DEFAULT_STYLE));
- }
- selectIndex = Math.max (0, selectIndex);
- fontStyleList.select (selectIndex);
- fontStyleList.setData (new Integer (selectIndex));
- centerListIndex (fontStyleList, selectIndex);
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a FontData object describing the font that was selected,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public FontData open () {
- shell = new Shell (getParent (), getStyle () | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
- shell.setLayout (new GridLayout ());
- createControls (shell);
-
- FontData [] originalFontData = fontData;
- RGB originalRGB = rgb;
- initFonts ();
- openDialog ();
- setFontControls (currentFontData);
- updateSampleFont ();
- updateSampleColor ();
- updateFontList ();
- fontSetList.select (0);
- fontSetList.setData (new Integer (0));
- updateButtonEnablements ();
- hookListeners ();
- Display display = shell.display;
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
- }
-
- FontData result = null;
- if (okSelected) {
- result = fontData [0];
- } else {
- fontData = originalFontData;
- rgb = originalRGB;
- }
- if (sampleFont != null) sampleFont.dispose ();
- sampleFont = null;
- if (sampleColor != null) sampleColor.dispose ();
- sampleColor = null;
- return result;
-}
-
-/**
- * Open the receiver and set its size to the size calculated by
- * the layout manager.
- */
-void openDialog () {
- // Start everything off by setting the shell size to its computed size.
- Point pt = shell.computeSize (SWT.DEFAULT, SWT.DEFAULT, false);
-
- // Ensure that the width of the shell fits the display.
- Display display = shell.display;
- Rectangle displayRect = display.getBounds ();
- int widthLimit = displayRect.width * 7 / 8;
- int heightLimit = displayRect.height * 7 / 8;
- if (pt.x > widthLimit) {
- pt = shell.computeSize (widthLimit, SWT.DEFAULT, false);
- }
-
- /*
- * If the parent is visible then center this dialog on it,
- * otherwise center this dialog on the parent's monitor
- */
- Rectangle parentBounds = null;
- if (parent.isVisible ()) {
- parentBounds = getParent ().getBounds ();
- } else {
- parentBounds = parent.getMonitor ().getBounds ();
- }
- int originX = (parentBounds.width - pt.x) / 2 + parentBounds.x;
- originX = Math.max (originX, 0);
- originX = Math.min (originX, widthLimit - pt.x);
- int originY = (parentBounds.height - pt.y) / 2 + parentBounds.y;
- originY = Math.max (originY, 0);
- originY = Math.min (originY, heightLimit - pt.y);
- shell.setBounds (originX, originY, pt.x, pt.y);
-
- String title = getText ();
- if (title.length () == 0) title = SWT.getMessage ("SWT_FontDialog_Title");
- shell.setText (title);
-
- // Open the window.
- shell.open ();
-}
-
-/**
- * Initialize the lists with the data of the preselected
- * font specified by the user.
- */
-void setFontControls (FontData fontData) {
- ignoreEvents = true;
- String characterSet = getTranslatedCharSet (fontData, true);
- String faceName = getTranslatedFaceName (fontData);
- charSetList.select (new String[] {characterSet});
- int index = charSetList.indexOf (characterSet);
- charSetList.setData (new Integer (index));
- if (index != -1) centerListIndex (charSetList, index);
-
- initFaceNameList ();
- faceNameList.select (new String[] {faceName});
- index = faceNameList.indexOf (faceName);
- faceNameList.setData (new Integer (index));
- if (index != -1) centerListIndex (faceNameList, index);
-
- initExtStyleList ();
- extStyleList.select (new String[] {fontData.addStyle});
- index = extStyleList.indexOf (fontData.addStyle);
- extStyleList.setData (new Integer (index));
- if (index != -1) centerListIndex (extStyleList, index);
-
- initSizeList ();
- String value = String.valueOf (fontData.getHeight ());
- fontSizeList.select (new String[] {value});
- index = fontSizeList.indexOf (value);
- fontSizeList.setData (new Integer (index));
- if (index != -1) centerListIndex (fontSizeList, index);
-
- initStyleList ();
- fontStyleList.select (new String[] {fontData.weight});
- index = fontStyleList.indexOf (fontData.weight);
- fontStyleList.setData (new Integer (index));
- if (index != -1) centerListIndex (fontStyleList, index);
- ignoreEvents = false;
-}
-
-/**
- * Sets a FontData object describing the font to be
- * selected by default in the dialog, or null to let
- * the platform choose one.
- *
- * @param fontData the FontData to use initially, or null
- * @deprecated use #setFontList (FontData [])
- */
-public void setFontData (FontData fontData) {
- if (fontData == null) {
- this.fontData = null;
- } else {
- this.fontData = new FontData [1];
- this.fontData [0] = fontData;
- }
-}
-
-/**
- * Sets the set of FontData objects describing the font to
- * be selected by default in the dialog, or null to let
- * the platform choose one.
- *
- * @param fontData the set of FontData objects to use initially, or null
- * to let the platform select a default when open() is called
- *
- * @see Font#getFontData
- *
- * @since 2.1.1
- */
-public void setFontList (FontData [] fontData) {
- this.fontData = fontData;
-}
-
-/**
- * Set the contents of 'list' to the keys of 'items'.
- * Keys are sorted in ascending order first and have to be Strings.
- */
-void setItemsSorted (List list, Hashtable items) {
- if (items == null) return;
- Enumeration itemKeys = items.keys ();
- String [] sortedItems = new String [items.size ()];
- int index = 0;
- while (itemKeys.hasMoreElements ()) {
- String item = (String) itemKeys.nextElement ();
- if (item.length () != 0) sortedItems [index++] = item;
- }
- if (index != sortedItems.length) {
- String [] newItems = new String [index];
- System.arraycopy (sortedItems, 0, newItems, 0, index);
- sortedItems = newItems;
- }
- sort (sortedItems);
- list.setItems (sortedItems);
-}
-
-/**
- * Sets the RGB describing the color to be selected by default
- * in the dialog, or null to let the platform choose one.
- *
- * @param rgb the RGB value to use initially, or null to let
- * the platform select a default when open() is called
- *
- * @see PaletteData#getRGBs
- *
- * @since 2.1
- */
-public void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-
-/**
- * Set the contents of the size list to the keys of 'items'.
- * Keys are sorted in ascending order first and have to be Integers.
- */
-void setSizeItemsSorted (Enumeration itemsEnum) {
- Vector items = new Vector ();
- while (itemsEnum.hasMoreElements ()) {
- items.addElement (itemsEnum.nextElement ());
- }
- Integer [] sortedItems = new Integer [items.size ()];
- items.copyInto (sortedItems);
- sort (sortedItems);
- String [] sortedItemStrings = new String [items.size ()];
- for (int i = 0; i < sortedItemStrings.length; i++) {
- sortedItemStrings [i] = String.valueOf (sortedItems [i].intValue ());
- }
- fontSizeList.setItems (sortedItemStrings);
-}
-
-/**
- * Sort 'items' in ascending order.
- */
-void sort (Integer [] items) {
- /* Shell Sort from K&R, pg 108 */
- int length = items.length;
- for (int gap = length / 2; gap > 0; gap /= 2) {
- for (int i = gap; i < length; i++) {
- for (int j = i - gap; j >= 0; j -= gap) {
- if (items [j].intValue () > items [j + gap].intValue ()) {
- Integer swap = items [j];
- items [j] = items [j + gap];
- items [j + gap] = swap;
- }
- }
- }
- }
-}
-
-/**
- * Sort 'items' in ascending order.
- */
-void sort (String items []) {
- /* Shell Sort from K&R, pg 108 */
- int length = items.length;
- for (int gap = length / 2; gap > 0; gap /= 2) {
- for (int i = gap; i < length; i++) {
- for (int j = i - gap; j >= 0; j -= gap) {
- if (items [j].compareTo (items [j + gap]) > 0) {
- String swap = items [j];
- items [j] = items [j + gap];
- items [j + gap] = swap;
- }
- }
- }
- }
-}
-
-void updateButtonEnablements () {
- removeButton.setEnabled (fontSetList.getItemCount () > 1);
- upButton.setEnabled (fontSetList.getSelectionIndex () > 0);
- downButton.setEnabled (fontSetList.getSelectionIndex () < fontSetList.getItemCount () - 1);
-}
-
-void updateFontList () {
- int selectionIndex = fontSetList.getSelectionIndex ();
- int topIndex = Math.max (0, fontSetList.getTopIndex ());
- String [] items = new String [fontData.length];
- for (int i = 0; i < fontData.length; i++) {
- StringBuffer buffer = new StringBuffer ();
- buffer.append (i);
- buffer.append (": ");
- buffer.append (getTranslatedCharSet (fontData [i], false));
- buffer.append ("-");
- buffer.append (getTranslatedFaceName (fontData [i]));
- buffer.append ("-");
- if (!fontData [i].addStyle.equals ("")) {
- buffer.append (fontData [i].addStyle);
- buffer.append ("-");
- }
- buffer.append (fontData [i].getHeight ());
- buffer.append ("-");
- buffer.append (fontData [i].weight);
- items [i] = buffer.toString ();
- }
- fontSetList.setItems (items);
- if (selectionIndex >= items.length) selectionIndex--;
- fontSetList.select (selectionIndex);
- fontSetList.setData (new Integer (selectionIndex));
- fontSetList.setTopIndex (topIndex);
- fontSetList.showSelection ();
-}
-
-void updateSampleColor () {
- if (rgb == null) {
- rgb = new RGB (0, 0, 0);
- }
- if (sampleColor != null) {
- if (sampleColor.getRGB ().equals (rgb)) return;
- sampleColor.dispose ();
- }
- sampleColor = new Color (parent.display, rgb);
- sampleLabel.setForeground (sampleColor);
-}
-
-/**
- * Set the font of the sample text to the selected font.
- * Display an error in place of the sample text if the selected
- * font could not be loaded.
- */
-void updateSampleFont () {
- FontData selectionFontData = getSelectionFontData ();
- /*
- * sampleFont may not be the same as the one specified in selectionFontData.
- * This happens when selectionFontData specifies a font alias.
- */
- if (sampleFont != null) sampleFont.dispose ();
- int selectionIndex = Math.max (0, fontSetList.getSelectionIndex ());
- fontData [selectionIndex] = selectionFontData;
- sampleFont = new Font (shell.display, selectionFontData);
- sampleLabel.setFont (sampleFont);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java
deleted file mode 100755
index ce900951f8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java
+++ /dev/null
@@ -1,348 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class provide an etched border
- * with an optional title.
- * <p>
- * Shadow styles are hints and may not be honoured
- * by the platform. To create a group with the
- * default shadow style for the platform, do not
- * specify a shadow style.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SHADOW_ETCHED_IN, SHADOW_ETCHED_OUT, SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the above styles may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Group extends Composite {
- int labelHandle;
- String text = "";
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SHADOW_ETCHED_IN
- * @see SWT#SHADOW_ETCHED_OUT
- * @see SWT#SHADOW_IN
- * @see SWT#SHADOW_OUT
- * @see SWT#SHADOW_NONE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Group (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- Point size = super.computeSize (wHint, hHint, changed);
- if (OS.XtIsManaged (labelHandle)) {
- int [] argList = {
- OS.XmNshadowThickness, 0,
- OS.XmNmarginWidth, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int thickness = argList [1];
- int marginWidth = argList [3];
- int borderWidth = getBorderWidth ();
- int [] argList2 = {OS.XmNchildHorizontalSpacing, 0};
- OS.XtGetValues (labelHandle, argList2, argList2.length / 2);
- XtWidgetGeometry result = new XtWidgetGeometry ();
- OS.XtQueryGeometry (labelHandle, null, result);
- int titleWidth = result.width + 2 * (argList2 [1] + marginWidth + thickness + borderWidth);
- size.x = Math.max (size.x, titleWidth);
- }
- return size;
-}
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- int trimX, trimY, trimWidth, trimHeight;
- int [] argList = {
- OS.XmNshadowThickness, 0,
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int thickness = argList [1];
- int marginWidth = argList [3];
- int marginHeight = argList [5];
- int borderWidth = getBorderWidth ();
- trimX = x - marginWidth - thickness - borderWidth;
- trimY = y - marginHeight - thickness - borderWidth;
- trimWidth = width + ((marginWidth + thickness + borderWidth) * 2);
- trimHeight = height + ((marginHeight + thickness + borderWidth) * 2);
- if (OS.XtIsManaged (labelHandle)) {
- int [] argList2 = {OS.XmNy, 0, OS.XmNheight, 0};
- OS.XtGetValues (labelHandle, argList2, argList2.length / 2);
- int titleHeight = ((short) argList2 [1]) + argList2 [3];
- trimY = y - titleHeight;
- trimHeight = height + titleHeight + (marginHeight + thickness + borderWidth);
- }
- return new Rectangle (trimX, trimY, trimWidth, trimHeight);
-}
-void createHandle (int index) {
- state |= THEME_BACKGROUND;
- /*
- * Feature in Motif. When a widget is managed or unmanaged,
- * it may request and be granted, a new size in the OS. This
- * behavior is unwanted. The fix is to create a parent for
- * the list that will disallow geometry requests.
- */
- int border = (style & SWT.BORDER) != 0 ? 1 : 0;
- int [] argList1 = {
- OS.XmNancestorSensitive, 1,
- OS.XmNborderWidth, border,
- };
- int parentHandle = parent.handle;
- formHandle = OS.XmCreateForm (parentHandle, null, argList1, argList1.length / 2);
- if (formHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int [] argList2 = {
- OS.XmNshadowType, shadowType (),
- OS.XmNtopAttachment, OS.XmATTACH_FORM,
- OS.XmNbottomAttachment, OS.XmATTACH_FORM,
- OS.XmNleftAttachment, OS.XmATTACH_FORM,
- OS.XmNrightAttachment, OS.XmATTACH_FORM,
- OS.XmNresizable, 0,
- };
- handle = OS.XmCreateFrame (formHandle, null, argList2, argList2.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- int [] argList3 = {OS.XmNframeChildType, OS.XmFRAME_TITLE_CHILD};
- labelHandle = OS.XmCreateLabel (handle, null, argList3, argList3.length / 2);
- if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int [] argList4 = {OS.XmNforeground, 0, OS.XmNbackground, 0};
- OS.XtGetValues (handle, argList4, argList4.length / 2);
- OS.XtSetValues (labelHandle, argList4, argList4.length / 2);
-}
-void deregister () {
- super.deregister ();
- display.removeWidget (labelHandle);
-}
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- enableHandle (enabled, labelHandle);
-}
-int fontHandle () {
- return labelHandle;
-}
-public Rectangle getClientArea () {
- checkWidget();
- /*
- * Bug in Motif. For some reason, if a form has not been realized,
- * calling XtResizeWidget () on the form does not lay out properly.
- * The fix is to force the widget to be realized by forcing the shell
- * to be realized.
- */
- if (!OS.XtIsRealized (handle)) getShell ().realizeWidget ();
- int [] argList = {
- OS.XmNwidth, 0,
- OS.XmNheight, 0,
- OS.XmNshadowThickness, 0,
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int thickness = argList [5];
- int marginWidth = argList [7];
- int marginHeight = argList [9];
- int borderWidth = getBorderWidth ();
- int x = marginWidth + thickness + borderWidth;
- int y = marginHeight + thickness + borderWidth;
- int width = argList [1] - ((marginWidth + thickness + borderWidth) * 2);
- int height = argList [3] - ((marginHeight + thickness + borderWidth) * 2);
- if (OS.XtIsManaged (labelHandle)) {
- int [] argList2 = {OS.XmNy, 0, OS.XmNheight, 0};
- OS.XtGetValues (labelHandle, argList2, argList2.length / 2);
- y = ((short) argList2 [1]) + argList2 [3];
- height = argList [3] - y - (marginHeight + thickness + borderWidth);
- }
- return new Rectangle (x, y, width, height);
-}
-/**
- * Returns the receiver's text, which is the string that the
- * is used as the <em>title</em>. If the text has not previously
- * been set, returns an empty string.
- *
- * @return the text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- return text;
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- OS.XtAddEventHandler (labelHandle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS);
- OS.XtAddEventHandler (labelHandle, OS.ButtonReleaseMask, false, windowProc, BUTTON_RELEASE);
- OS.XtAddEventHandler (labelHandle, OS.PointerMotionMask, false, windowProc, POINTER_MOTION);
-}
-boolean mnemonicHit (char key) {
- return setFocus ();
-}
-boolean mnemonicMatch (char key) {
- char mnemonic = findMnemonic (getText ());
- if (mnemonic == '\0') return false;
- return Character.toUpperCase (key) == Character.toUpperCase (mnemonic);
-}
-void propagateWidget (boolean enabled) {
- super.propagateWidget (enabled);
- propagateHandle (enabled, labelHandle, OS.None);
-}
-void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean allChildren, boolean trim) {
- super.redrawWidget (x, y, width, height, redrawAll, allChildren, trim);
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (handle, (short) x, (short) y, root_x, root_y);
- short [] label_x = new short [1], label_y = new short [1];
- OS.XtTranslateCoords (labelHandle, (short) 0, (short) 0, label_x, label_y);
- redrawHandle (root_x [0] - label_x [0], root_y [0] - label_y [0], width, height, redrawAll, labelHandle);
-}
-void register () {
- super.register ();
- display.addWidget (labelHandle, this);
-}
-void releaseHandle () {
- super.releaseHandle ();
- labelHandle = 0;
-}
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- int [] argList = {OS.XmNforeground, 0};
- OS.XtGetValues (labelHandle, argList, argList.length / 2);
- OS.XmChangeColor (labelHandle, pixel);
- OS.XtSetValues (labelHandle, argList, argList.length / 2);
-}
-void setForegroundPixel (int pixel) {
- int [] argList = {OS.XmNforeground, pixel};
- OS.XtSetValues (labelHandle, argList, argList.length / 2);
- super.setForegroundPixel (pixel);
-}
-void setParentBackground () {
- super.setParentBackground ();
- if (labelHandle != 0) setParentBackground (labelHandle);
-}
-/**
- * Sets the receiver's text, which is the string that will
- * be displayed as the receiver's <em>title</em>, to the argument,
- * which may not be null. The string may include the mnemonic character.
- * </p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, focus is assigned
- * to the first child of the group. On most platforms, the
- * mnemonic appears underlined but may be emphasised in a
- * platform specific manner. The mnemonic indicator character
- * '&amp;' can be escaped by doubling it in the string, causing
- * a single '&amp;' to be displayed.
- * </p>
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- text = string;
- char [] text = new char [string.length ()];
- string.getChars (0, text.length, text, 0);
- int mnemonic = fixMnemonic (text);
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), text, true);
- int xmString = OS.XmStringParseText (
- buffer,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- if (xmString == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- if (mnemonic == 0) mnemonic = OS.XK_VoidSymbol;
- int [] argList = {
- OS.XmNlabelType, OS.XmSTRING,
- OS.XmNlabelString, xmString,
- OS.XmNmnemonic, mnemonic,
- };
- OS.XtSetValues (labelHandle, argList, argList.length / 2);
- if (xmString != 0) OS.XmStringFree (xmString);
- if (string.length () == 0) {
- OS.XtUnmanageChild (labelHandle);
- } else {
- OS.XtManageChild (labelHandle);
- }
-}
-int shadowType () {
- if ((style & SWT.SHADOW_IN) != 0) return OS.XmSHADOW_IN;
- if ((style & SWT.SHADOW_OUT) != 0) return OS.XmSHADOW_OUT;
- if ((style & SWT.SHADOW_ETCHED_IN) != 0) return OS.XmSHADOW_ETCHED_IN;
- if ((style & SWT.SHADOW_ETCHED_OUT) != 0) return OS.XmSHADOW_ETCHED_OUT;
- return OS.XmSHADOW_ETCHED_IN;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java
deleted file mode 100755
index 1a53672046..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java
+++ /dev/null
@@ -1,643 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a non-selectable
- * user interface object that displays a string or image.
- * When SEPARATOR is specified, displays a single
- * vertical or horizontal line.
- * <p>
- * Shadow styles are hints and may not be honored
- * by the platform. To create a separator label
- * with the default shadow style for the platform,
- * do not specify a shadow style.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SEPARATOR, HORIZONTAL, VERTICAL</dd>
- * <dd>SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd>
- * <dd>CENTER, LEFT, RIGHT, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of SHADOW_IN, SHADOW_OUT and SHADOW_NONE may be specified.
- * SHADOW_NONE is a HINT. Only one of HORIZONTAL and VERTICAL may be specified.
- * Only one of CENTER, LEFT and RIGHT may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#label">Label snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Label extends Control {
- int formHandle;
- String text = "";
- Image image, bitmap, disabled;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SEPARATOR
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#SHADOW_IN
- * @see SWT#SHADOW_OUT
- * @see SWT#SHADOW_NONE
- * @see SWT#CENTER
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#WRAP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Label (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- if ((style & SWT.SEPARATOR) != 0) {
- style = checkBits (style, SWT.VERTICAL, SWT.HORIZONTAL, 0, 0, 0, 0);
- return checkBits (style, SWT.SHADOW_OUT, SWT.SHADOW_IN, SWT.SHADOW_NONE, 0, 0, 0);
- }
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-void _setText (String string) {
- /*
- * Bug in Motif. The widget will not receive mouse events, if the
- * label string is empty. The fix is to detect that and set a single
- * space instead.
- */
- if (string.length () == 0) string = " ";
-
- /* Strip out mnemonic marker symbols, and remember the mnemonic. */
- char [] unicode = new char [string.length ()];
- string.getChars (0, unicode.length, unicode, 0);
- int mnemonic = fixMnemonic (unicode);
-
- /* Wrap the text if necessary, and convert to mbcs. */
- byte [] buffer = null;
- if ((style & SWT.WRAP) != 0) {
- int [] argList = {
- OS.XmNwidth, 0, /* 1 */
- OS.XmNmarginWidth, 0, /* 3 */
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int width = argList [1] - argList [3] * 2;
- if (mnemonic != 0) string = new String (unicode);
- string = display.wrapText (string, font, width);
- buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- } else {
- buffer = Converter.wcsToMbcs (getCodePage (), unicode, true);
- }
-
- int xmString = OS.XmStringGenerate(buffer, null, OS.XmCHARSET_TEXT, null);
- if (xmString == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
-
- /*
- * Bug in Solaris. If a mnemonic is defined to be a character
- * that appears in a string in a position that follows a '\n',
- * Solaris segment faults. For example, a label with text
- * "Hello\nthe&re" would GP since "r" appears after '\n'.
- *
- * The fix is to remove mnemonics from labels that contain
- * '\n', which is fine since such labels generally just act
- * as descriptive texts anyways.
- */
- if (mnemonic == 0 || string.indexOf ('\n') != -1) {
- mnemonic = OS.XK_VoidSymbol;
- }
- int [] argList = {
- OS.XmNlabelType, OS.XmSTRING,
- OS.XmNlabelString, xmString,
- OS.XmNmnemonic, mnemonic,
- };
- OS.XtSetValues (handle, argList, argList.length / 2);
- if (xmString != 0) OS.XmStringFree (xmString);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- if ((style & SWT.SEPARATOR) != 0) {
- if ((style & SWT.HORIZONTAL) != 0) {
- width += DEFAULT_WIDTH; height += 3;
- } else {
- width += 3; height += DEFAULT_HEIGHT;
- }
- if (wHint != SWT.DEFAULT) width = wHint + border * 2;
- if (hHint != SWT.DEFAULT) height = hHint + border * 2;
- return new Point (width, height);
- }
- int [] argList1 = {OS.XmNlabelType, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int labelType = argList1 [1];
- if (labelType == OS.XmSTRING && (style & SWT.WRAP) != 0) {
- /* If we are wrapping text, calculate the height based on wHint. */
- int [] argList2 = {
- OS.XmNmarginTop, 0, /* 1 */
- OS.XmNmarginBottom, 0, /* 3 */
- OS.XmNmarginHeight, 0, /* 5 */
- OS.XmNmarginWidth, 0, /* 7 */
- OS.XmNmarginLeft, 0, /* 9 */
- OS.XmNmarginRight, 0, /* 11 */
- };
- OS.XtGetValues (handle, argList2, argList2.length / 2);
- String string = text;
- if (wHint != SWT.DEFAULT) {
- string = display.wrapText (string, font, wHint - (argList2 [7] * 2) - argList2 [9] - argList2 [11]);
- }
- GC gc = new GC (this);
- Point extent = gc.textExtent (string);
- gc.dispose ();
- height = extent.y + argList2 [1] + argList2 [3] + (argList2 [5] * 2) + (border * 2);
- if (wHint == SWT.DEFAULT) {
- width += extent.x + (argList2 [7] * 2) + argList2 [9] + argList2 [11];
- }
- } else {
- /* If we are not wrapping, ask the widget for its geometry. */
- XtWidgetGeometry result = new XtWidgetGeometry ();
- result.request_mode = OS.CWWidth | OS.CWHeight;
- OS.XtQueryGeometry (handle, null, result);
- width += result.width;
- height += result.height;
- }
-
- /*
- * Feature in Motif. If a label's labelType is XmSTRING but
- * the label string is empty, recomputing the size will
- * not take into account the height of the font, as we would
- * like it to. Take care of this case.
- *
- * Note: When the label string is empty a single space is set
- * into the widget. So the preferred height is computed properly.
- * Just make sure the preferred width is zero.
- */
- if (labelType == OS.XmSTRING && text.length () == 0) {
- width = 0;
- }
- if (wHint != SWT.DEFAULT) {
- int [] argList3 = {
- OS.XmNmarginWidth, 0, /* 1 */
- OS.XmNmarginLeft, 0, /* 3 */
- OS.XmNmarginRight, 0, /* 5 */
- };
- OS.XtGetValues (handle, argList3, argList3.length / 2);
- width = wHint + (border * 2) + (argList3 [1] * 2) + argList3 [3] + argList3 [5];
- }
- if (hHint != SWT.DEFAULT) {
- int [] argList4 = {
- OS.XmNmarginHeight, 0, /* 1 */
- OS.XmNmarginTop, 0, /* 3 */
- OS.XmNmarginBottom, 0, /* 5 */
- };
- OS.XtGetValues (handle, argList4, argList4.length / 2);
- height = hHint + (border * 2) + (argList4 [1] * 2) + argList4 [3] + argList4 [5];
- }
- return new Point (width, height);
-}
-void createHandle (int index) {
- state |= THEME_BACKGROUND;
- int parentHandle = parent.handle;
- int borderWidth = (style & SWT.BORDER) != 0 ? 1 : 0;
- if ((style & SWT.SEPARATOR) != 0) {
- int separatorType = separatorType ();
- int orientation = (style & SWT.HORIZONTAL) != 0 ? OS.XmHORIZONTAL : OS.XmVERTICAL;
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNborderWidth, borderWidth,
- OS.XmNorientation, orientation,
- OS.XmNseparatorType, separatorType,
- };
- handle = OS.XmCreateSeparator (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- return;
- }
- int [] argList1 = {
- OS.XmNancestorSensitive, 1,
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNborderWidth, borderWidth,
- };
- formHandle = OS.XmCreateForm (parentHandle, null, argList1, argList1.length / 2);
- if (formHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int alignment = OS.XmALIGNMENT_BEGINNING;
- if ((style & SWT.CENTER) != 0) alignment = OS.XmALIGNMENT_CENTER;
- if ((style & SWT.RIGHT) != 0) alignment = OS.XmALIGNMENT_END;
- int [] argList2 = {
- OS.XmNalignment, alignment,
- OS.XmNtopAttachment, OS.XmATTACH_FORM,
- OS.XmNleftAttachment, OS.XmATTACH_FORM,
- OS.XmNrightAttachment, OS.XmATTACH_FORM,
- };
- /*
- * Bug in Motif. The widget will not receive mouse events, if the
- * label string is empty. The fix is to initialize it to a space.
- */
- byte [] buffer = {(byte) ' ', 0};
- handle = OS.XmCreateLabel (formHandle, buffer, argList2, argList2.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- int [] argList3 = {OS.XmNbackground, 0};
- OS.XtGetValues (handle, argList3, argList3.length / 2);
- OS.XtSetValues (formHandle, argList3, argList3.length / 2);
-}
-int defaultBackground () {
- return display.labelBackground;
-}
-Font defaultFont () {
- return display.labelFont;
-}
-int defaultForeground () {
- return display.labelForeground;
-}
-void deregister () {
- super.deregister ();
- if (formHandle != 0) display.removeWidget (formHandle);
-}
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- if (formHandle != 0) enableHandle (enabled, formHandle);
-}
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is a <code>SEPARATOR</code> label, in
- * which case, <code>NONE</code> is returned.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return SWT.LEFT;
- int [] argList = {OS.XmNalignment, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int alignment = argList [1];
- if (alignment == OS.XmALIGNMENT_BEGINNING) return SWT.LEFT;
- if (alignment == OS.XmALIGNMENT_CENTER) return SWT.CENTER;
- if (alignment == OS.XmALIGNMENT_END)return SWT.RIGHT;
- return SWT.LEFT;
-}
-/**
- * Returns the receiver's image if it has one, or null
- * if it does not.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-String getNameText () {
- return getText ();
-}
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set or if the receiver is
- * a <code>SEPARATOR</code> label.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return "";
- return text;
-}
-void hookEvents () {
- super.hookEvents ();
- if (formHandle != 0) {
- int windowProc = display.windowProc;
- OS.XtAddEventHandler (formHandle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS);
- OS.XtAddEventHandler (formHandle, OS.ButtonReleaseMask, false, windowProc, BUTTON_RELEASE);
- OS.XtAddEventHandler (formHandle, OS.PointerMotionMask, false, windowProc, POINTER_MOTION);
- OS.XtAddEventHandler (formHandle, OS.EnterWindowMask, false, windowProc, ENTER_WINDOW);
- OS.XtAddEventHandler (formHandle, OS.LeaveWindowMask, false, windowProc, LEAVE_WINDOW);
- OS.XtInsertEventHandler (formHandle, OS.ExposureMask, false, windowProc, EXPOSURE, OS.XtListTail);
- }
-}
-void manageChildren () {
- if (formHandle != 0) {
- OS.XtSetMappedWhenManaged (formHandle, false);
- OS.XtManageChild (formHandle);
- }
- super.manageChildren ();
- if (formHandle != 0) {
- int [] argList = {OS.XmNborderWidth, 0};
- OS.XtGetValues (formHandle, argList, argList.length / 2);
- OS.XtResizeWidget (formHandle, 1, 1, argList [1]);
- OS.XtSetMappedWhenManaged (formHandle, true);
- }
-}
-boolean mnemonicHit (char key) {
- Composite control = this.parent;
- while (control != null) {
- Control [] children = control._getChildren ();
- int index = 0;
- while (index < children.length) {
- if (children [index] == this) break;
- index++;
- }
- index++;
- if (index < children.length) {
- if (children [index].setFocus ()) return true;
- }
- control = control.parent;
- }
- return false;
-}
-boolean mnemonicMatch (char key) {
- char mnemonic = findMnemonic (getText ());
- if (mnemonic == '\0') return false;
- return Character.toUpperCase (key) == Character.toUpperCase (mnemonic);
-}
-void propagateWidget (boolean enabled) {
- super.propagateWidget (enabled);
- if (formHandle != 0) propagateHandle (enabled, formHandle, OS.None);
-}
-void realizeChildren () {
- super.realizeChildren ();
- setBitGravity ();
-}
-void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean allChildren, boolean trim) {
- super.redrawWidget (x, y, width, height, redrawAll, allChildren, trim);
- if (formHandle != 0) {
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (handle, (short) x, (short) y, root_x, root_y);
- short [] label_x = new short [1], label_y = new short [1];
- OS.XtTranslateCoords (formHandle, (short) 0, (short) 0, label_x, label_y);
- redrawHandle (root_x [0] - label_x [0], root_y [0] - label_y [0], width, height, redrawAll, formHandle);
- }
-}
-void register () {
- super.register ();
- if (formHandle != 0) display.addWidget (formHandle, this);
-}
-void releaseHandle () {
- super.releaseHandle ();
- formHandle = 0;
-}
-void releaseWidget () {
- super.releaseWidget ();
- int [] argList = {
- OS.XmNlabelPixmap, OS.XmUNSPECIFIED_PIXMAP,
- OS.XmNlabelInsensitivePixmap, OS.XmUNSPECIFIED_PIXMAP,
- };
- OS.XtSetValues (handle, argList, argList.length / 2);
- if (bitmap != null) bitmap.dispose ();
- if (disabled != null) disabled.dispose ();
- image = bitmap = disabled = null;
-}
-int separatorType () {
- if ((style & (SWT.SHADOW_IN)) != 0) return OS.XmSHADOW_ETCHED_IN;
- if ((style & (SWT.SHADOW_OUT)) != 0) return OS.XmSHADOW_ETCHED_OUT;
- return OS.XmSINGLE_LINE;
-}
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>. If the receiver is a <code>SEPARATOR</code>
- * label, the argument is ignored and the alignment is not changed.
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return;
- int [] argList = {OS.XmNalignment, OS.XmALIGNMENT_BEGINNING};
- if ((alignment & SWT.CENTER) != 0) argList [1] = OS.XmALIGNMENT_CENTER;
- if ((alignment & SWT.RIGHT) != 0) argList [1] = OS.XmALIGNMENT_END;
- OS.XtSetValues (handle, argList, argList.length / 2);
- setBitGravity ();
-}
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- if (formHandle != 0) {
- int [] argList1 = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0};
- OS.XtGetValues (formHandle, argList1, argList1.length / 2);
- OS.XmChangeColor (formHandle, pixel);
- OS.XtSetValues (formHandle, argList1, argList1.length / 2);
- }
- int [] argList2 = {OS.XmNlabelType, 0};
- OS.XtGetValues (handle, argList2, argList2.length / 2);
- if (argList2 [1] == OS.XmPIXMAP) setBitmap (image);
-}
-void setBitGravity () {
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- int flags = OS.CWBitGravity;
- XSetWindowAttributes attributes = new XSetWindowAttributes ();
- attributes.bit_gravity = (style & SWT.LEFT) != 0 ? OS.NorthWestGravity : OS.ForgetGravity;
- OS.XChangeWindowAttributes (xDisplay, xWindow, flags, attributes);
-}
-void setBitmap (Image image) {
- int labelPixmap = OS.XmUNSPECIFIED_PIXMAP;
- int labelInsensitivePixmap = OS.XmUNSPECIFIED_PIXMAP;
- if (bitmap != null) bitmap.dispose ();
- if (disabled != null) disabled.dispose ();
- bitmap = disabled = null;
- if (image != null) {
- if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- switch (image.type) {
- case SWT.BITMAP:
- ImageData data;
- if (image.mask == 0 && (data = image.getImageData ()).alpha == -1 && data.alphaData == null && data.transparentPixel == -1) {
- labelPixmap = image.pixmap;
- disabled = new Image (display, image, SWT.IMAGE_DISABLE);
- labelInsensitivePixmap = disabled.pixmap;
- break;
- }
- //FALL THROUGH
- case SWT.ICON:
- Rectangle rect = image.getBounds ();
- bitmap = new Image (display, rect.width, rect.height);
- GC gc = new GC (bitmap);
- gc.setBackground (getBackground ());
- gc.fillRectangle (rect);
- gc.drawImage (image, 0, 0);
- gc.dispose ();
- labelPixmap = bitmap.pixmap;
- disabled = new Image (display, bitmap, SWT.IMAGE_DISABLE);
- labelInsensitivePixmap = disabled.pixmap;
- break;
- default:
- error (SWT.ERROR_NOT_IMPLEMENTED);
- }
- }
- int [] argList = {
- OS.XmNlabelType, image == null ? OS.XmSTRING : OS.XmPIXMAP,
- OS.XmNlabelPixmap, labelPixmap,
- OS.XmNlabelInsensitivePixmap, labelInsensitivePixmap,
- };
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- boolean changed = super.setBounds (x, y, width, height, move, resize);
- if (changed && resize && (style & SWT.WRAP) != 0) {
- int [] argList = {OS.XmNlabelType, 0,};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] == OS.XmSTRING) _setText (text);
- }
- return changed;
-}
-public void setFont (Font font) {
- checkWidget();
-
- /*
- * Bug in Motif. Setting the font in a label widget that does
- * not have a non-empty string causes GP on UTF-8 locale.
- * The fix is to set a non-empty string, change the font,
- * and restore the empty string at the end.
- */
- int [] argList1 = {OS.XmNlabelString, 0, OS.XmNlabelType, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- boolean fixString = OS.IsDBLocale && OS.XmStringEmpty (argList1 [1]);
- if (fixString) {
- byte[] buffer = Converter.wcsToMbcs (getCodePage (), "string", true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- int [] argList2 = {
- OS.XmNlabelType, OS.XmSTRING,
- OS.XmNlabelString, xmString,
- };
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- OS.XmStringFree (xmString);
- }
- super.setFont (font);
- if (fixString) OS.XtSetValues (handle, argList1, argList1.length / 2);
- if ((style & SWT.WRAP) != 0) {
- int [] argList = {OS.XmNlabelType, 0,};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] == OS.XmSTRING) _setText (text);
- }
-}
-/**
- * Sets the receiver's image to the argument, which may be
- * null indicating that no image should be displayed.
- *
- * @param image the image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return;
- setBitmap (this.image = image);
-}
-void setParentBackground () {
- super.setParentBackground ();
- if (formHandle != 0) setParentBackground (formHandle);
-}
-/**
- * Sets the receiver's text.
- * <p>
- * This method sets the widget label. The label may include
- * the mnemonic character and line delimiters.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, focus is assigned
- * to the control that follows the label. On most platforms,
- * the mnemonic appears underlined but may be emphasised in a
- * platform specific manner. The mnemonic indicator character
- * '&amp;' can be escaped by doubling it in the string, causing
- * a single '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- /*
- * Feature in Motif. Motif does not optimize the case
- * when the same text is set into a label causing
- * it to flash. The fix is to test for equality and
- * do nothing.
- */
- if (text.equals (string)) return;
- _setText (text = string);
-}
-int topHandle () {
- if (formHandle != 0) return formHandle;
- return handle;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Link.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Link.java
deleted file mode 100644
index 8d82436f87..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Link.java
+++ /dev/null
@@ -1,660 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable
- * user interface object that displays a text with
- * links.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#link">Link snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Link extends Control {
- String text;
- TextLayout layout;
- Color linkColor, disabledColor;
- Point [] offsets;
- Point selection;
- String [] ids;
- int [] mnemonics;
- int focusIndex;
-
- static final RGB LINK_FOREGROUND = new RGB (0, 51, 153);
- static final RGB LINK_DISABLED_FOREGROUND = new RGB (172, 168, 153);
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Link (Composite parent, int style) {
- super (parent, style);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected by the user.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- int width, height;
- int layoutWidth = layout.getWidth ();
- //TEMPORARY CODE
- if (wHint == 0) {
- layout.setWidth (1);
- Rectangle rect = layout.getBounds ();
- width = 0;
- height = rect.height;
- } else {
- layout.setWidth (wHint);
- Rectangle rect = layout.getBounds ();
- width = rect.width;
- height = rect.height;
- }
- layout.setWidth (layoutWidth);
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2;
- height += border * 2;
- return new Point (width, height);
-}
-void createHandle (int index) {
- state |= THEME_BACKGROUND;
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0,
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNtraversalOn, 0,
- };
- handle = OS.XmCreateDrawingArea (parent.handle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- layout = new TextLayout (display);
- linkColor = new Color (display, LINK_FOREGROUND);
- disabledColor = new Color (display, LINK_DISABLED_FOREGROUND);
- offsets = new Point [0];
- ids = new String [0];
- mnemonics = new int [0];
- selection = new Point (-1, -1);
- focusIndex = -1;
-}
-void createWidget (int index) {
- super.createWidget (index);
- text = "";
- //TODO - accessibility
-}
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- TextStyle linkStyle = new TextStyle (null, enabled ? linkColor : disabledColor, null);
- linkStyle.underline = true;
- for (int i = 0; i < offsets.length; i++) {
- Point point = offsets [i];
- layout.setStyle (linkStyle, point.x, point.y);
- }
- redraw ();
-}
-String getNameText () {
- return getText ();
-}
-Rectangle [] getRectangles (int linkIndex) {
- int lineCount = layout.getLineCount ();
- Rectangle [] rects = new Rectangle [lineCount];
- int [] lineOffsets = layout.getLineOffsets ();
- Point point = offsets [linkIndex];
- int lineStart = 1;
- while (point.x > lineOffsets [lineStart]) lineStart++;
- int lineEnd = 1;
- while (point.y > lineOffsets [lineEnd]) lineEnd++;
- int index = 0;
- if (lineStart == lineEnd) {
- rects [index++] = layout.getBounds (point.x, point.y);
- } else {
- rects [index++] = layout.getBounds (point.x, lineOffsets [lineStart]-1);
- rects [index++] = layout.getBounds (lineOffsets [lineEnd-1], point.y);
- if (lineEnd - lineStart > 1) {
- for (int i = lineStart; i < lineEnd - 1; i++) {
- rects [index++] = layout.getLineBounds (i);
- }
- }
- }
- if (rects.length != index) {
- Rectangle [] tmp = new Rectangle [index];
- System.arraycopy (rects, 0, tmp, 0, index);
- rects = tmp;
- }
- return rects;
-}
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-void releaseWidget () {
- super.releaseWidget ();
- if (layout != null) layout.dispose ();
- layout = null;
- if (linkColor != null) linkColor.dispose ();
- linkColor = null;
- if (disabledColor != null) disabledColor.dispose ();
- disabledColor = null;
- offsets = null;
- ids = null;
- mnemonics = null;
- text = null;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection, listener);
-}
-String parse (String string) {
- int length = string.length ();
- offsets = new Point [length / 4];
- ids = new String [length / 4];
- mnemonics = new int [length / 4 + 1];
- StringBuffer result = new StringBuffer ();
- char [] buffer = new char [length];
- string.getChars (0, string.length (), buffer, 0);
- int index = 0, state = 0, linkIndex = 0;
- int start = 0, tagStart = 0, linkStart = 0, endtagStart = 0, refStart = 0;
- while (index < length) {
- char c = Character.toLowerCase (buffer [index]);
- switch (state) {
- case 0:
- if (c == '<') {
- tagStart = index;
- state++;
- }
- break;
- case 1:
- if (c == 'a') state++;
- break;
- case 2:
- switch (c) {
- case 'h':
- state = 7;
- break;
- case '>':
- linkStart = index + 1;
- state++;
- break;
- default:
- if (Character.isWhitespace(c)) break;
- else state = 13;
- }
- break;
- case 3:
- if (c == '<') {
- endtagStart = index;
- state++;
- }
- break;
- case 4:
- state = c == '/' ? state + 1 : 3;
- break;
- case 5:
- state = c == 'a' ? state + 1 : 3;
- break;
- case 6:
- if (c == '>') {
- mnemonics [linkIndex] = parseMnemonics (buffer, start, tagStart, result);
- int offset = result.length ();
- parseMnemonics (buffer, linkStart, endtagStart, result);
- offsets [linkIndex] = new Point (offset, result.length () - 1);
- if (ids [linkIndex] == null) {
- ids [linkIndex] = new String (buffer, linkStart, endtagStart - linkStart);
- }
- linkIndex++;
- start = tagStart = linkStart = endtagStart = refStart = index + 1;
- state = 0;
- } else {
- state = 3;
- }
- break;
- case 7:
- state = c == 'r' ? state + 1 : 0;
- break;
- case 8:
- state = c == 'e' ? state + 1 : 0;
- break;
- case 9:
- state = c == 'f' ? state + 1 : 0;
- break;
- case 10:
- state = c == '=' ? state + 1 : 0;
- break;
- case 11:
- if (c == '"') {
- state++;
- refStart = index + 1;
- } else {
- state = 0;
- }
- break;
- case 12:
- if (c == '"') {
- ids[linkIndex] = new String (buffer, refStart, index - refStart);
- state = 2;
- }
- break;
- case 13:
- if (Character.isWhitespace (c)) {
- state = 0;
- } else if (c == '='){
- state++;
- }
- break;
- case 14:
- state = c == '"' ? state + 1 : 0;
- break;
- case 15:
- if (c == '"') state = 2;
- break;
- default:
- state = 0;
- break;
- }
- index++;
- }
- if (start < length) {
- int tmp = parseMnemonics (buffer, start, tagStart, result);
- int mnemonic = parseMnemonics (buffer, Math.max (tagStart, linkStart), length, result);
- if (mnemonic == -1) mnemonic = tmp;
- mnemonics [linkIndex] = mnemonic;
- } else {
- mnemonics [linkIndex] = -1;
- }
- if (offsets.length != linkIndex) {
- Point [] newOffsets = new Point [linkIndex];
- System.arraycopy (offsets, 0, newOffsets, 0, linkIndex);
- offsets = newOffsets;
- String [] newIDs = new String [linkIndex];
- System.arraycopy (ids, 0, newIDs, 0, linkIndex);
- ids = newIDs;
- int [] newMnemonics = new int [linkIndex + 1];
- System.arraycopy (mnemonics, 0, newMnemonics, 0, linkIndex + 1);
- mnemonics = newMnemonics;
- }
- return result.toString ();
-}
-int parseMnemonics (char[] buffer, int start, int end, StringBuffer result) {
- int mnemonic = -1, index = start;
- while (index < end) {
- if (buffer [index] == '&') {
- if (index + 1 < end && buffer [index + 1] == '&') {
- result.append (buffer [index]);
- index++;
- } else {
- mnemonic = result.length();
- }
- } else {
- result.append (buffer [index]);
- }
- index++;
- }
- return mnemonic;
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- boolean changed = super.setBounds (x, y, width,height, move, resize);
- if (changed && resize) {
- layout.setWidth (width > 0 ? width : -1);
- redraw ();
- }
- return changed;
-}
-public void setFont (Font font) {
- super.setFont (font);
- layout.setFont (this.font);
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- OS.XClearArea (xDisplay, xWindow, 0, 0, 0, 0, true);
-}
-void setForegroundPixel (int pixel) {
- super.setForegroundPixel (pixel);
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- OS.XClearArea (xDisplay, xWindow, 0, 0, 0, 0, true);
-}
-/**
- * Sets the receiver's text.
- * <p>
- * The string can contain both regular text and hyperlinks. A hyperlink
- * is delimited by an anchor tag, &lt;A&gt; and &lt;/A&gt;. Within an
- * anchor, a single HREF attribute is supported. When a hyperlink is
- * selected, the text field of the selection event contains either the
- * text of the hyperlink or the value of its HREF, if one was specified.
- * In the rare case of identical hyperlinks within the same string, the
- * HREF attribute can be used to distinguish between them. The string may
- * include the mnemonic character and line delimiters. The only delimiter
- * the HREF attribute supports is the quotation mark (").
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (string.equals (text)) return;
- text = string;
- layout.setText (parse (string));
- focusIndex = offsets.length > 0 ? 0 : -1;
- selection.x = selection.y = -1;
- int [] argList = new int [] {OS.XmNtraversalOn, offsets.length > 0 ? 1 : 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
- int [] argList1 = {OS.XmNsensitive, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- boolean enabled = argList1 [1] != 0;
- TextStyle linkStyle = new TextStyle (null, enabled ? linkColor : disabledColor, null);
- linkStyle.underline = true;
- for (int i = 0; i < offsets.length; i++) {
- Point point = offsets [i];
- layout.setStyle (linkStyle, point.x, point.y);
- }
- TextStyle mnemonicStyle = new TextStyle (null, null, null);
- mnemonicStyle.underline = true;
- for (int i = 0; i < mnemonics.length; i++) {
- int mnemonic = mnemonics [i];
- if (mnemonic != -1) {
- layout.setStyle (mnemonicStyle, mnemonic, mnemonic);
- }
- }
- redraw ();
-}
-int traversalCode (int key, XKeyEvent event) {
- if (offsets.length == 0) return 0;
- int bits = super.traversalCode (key, event);
- if (event != null && key == OS.XK_Tab) {
- boolean next = (event.state & OS.ShiftMask) == 0;
- if (next && focusIndex < offsets.length - 1) {
- return bits & ~SWT.TRAVERSE_TAB_NEXT;
- }
- if (!next && focusIndex > 0) {
- return bits & ~SWT.TRAVERSE_TAB_PREVIOUS;
- }
- }
- return bits;
-}
-int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XButtonPress (w, client_data, call_data, continue_to_dispatch);
- if (result != 0) return result;
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- if (xEvent.button == 1) {
- int offset = layout.getOffset (xEvent.x, xEvent.y, null);
- int oldSelectionX = selection.x;
- int oldSelectionY = selection.y;
- selection.x = offset;
- selection.y = -1;
- if (oldSelectionX != -1 && oldSelectionY != -1) {
- if (oldSelectionX > oldSelectionY) {
- int temp = oldSelectionX;
- oldSelectionX = oldSelectionY;
- oldSelectionY = temp;
- }
- Rectangle rect = layout.getBounds (oldSelectionX, oldSelectionY);
- redraw (rect.x, rect.y, rect.width, rect.height, false);
- }
- for (int j = 0; j < offsets.length; j++) {
- Rectangle [] rects = getRectangles (j);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rect = rects [i];
- if (rect.contains (xEvent.x, xEvent.y)) {
- focusIndex = j;
- redraw ();
- return result;
- }
- }
- }
- }
- return result;
-}
-int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XButtonRelease (w, client_data, call_data, continue_to_dispatch);
- if (result != 0) return result;
- if (focusIndex == -1) return result;
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- if (xEvent.button == 1) {
- Rectangle [] rects = getRectangles (focusIndex);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rect = rects [i];
- if (rect.contains (xEvent.x, xEvent.y)) {
- Event event = new Event ();
- event.text = ids [focusIndex];
- notifyListeners (SWT.Selection, event);
- return result;
- }
- }
- }
- return result;
-}
-int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) {
- XExposeEvent xEvent = new XExposeEvent ();
- OS.memmove (xEvent, call_data, XExposeEvent.sizeof);
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return 0;
- int damageRgn = OS.XCreateRegion ();
- OS.XtAddExposureToRegion (call_data, damageRgn);
- GCData data = new GCData ();
- data.damageRgn = damageRgn;
- GC gc = GC.motif_new (this, data);
- OS.XSetRegion (xDisplay, gc.handle, damageRgn);
- int selStart = selection.x;
- int selEnd = selection.y;
- if (selStart > selEnd) {
- selStart = selection.y;
- selEnd = selection.x;
- }
- // temporary code to disable text selection
- selStart = selEnd = -1;
- int [] argList = {OS.XmNsensitive, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] == 0) gc.setForeground (disabledColor);
- layout.draw (gc, 0, 0, selStart, selEnd, null, null);
- if (hasFocus () && focusIndex != -1) {
- Rectangle [] rects = getRectangles (focusIndex);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rect = rects [i];
- gc.drawFocus (rect.x, rect.y, rect.width, rect.height);
- }
- }
- gc.dispose ();
- OS.XDestroyRegion (damageRgn);
- return super.XExposure (w, client_data, call_data, continue_to_dispatch);
-}
-int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XFocusChange (w, client_data, call_data, continue_to_dispatch);
- redraw ();
- return result;
-}
-int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XKeyPress (w, client_data, call_data, continue_to_dispatch);
- if (result != 0) return result;
- if (focusIndex == -1) return result;
- XKeyEvent xEvent = new XKeyEvent ();
- OS.memmove (xEvent, call_data, XKeyEvent.sizeof);
- int [] keysym = new int [1];
- OS.XLookupString (xEvent, null, 0, keysym, null);
- keysym [0] &= 0xFFFF;
- switch (keysym [0]) {
- case OS.XK_space:
- case OS.XK_Return:
- case OS.XK_KP_Enter:
- Event event = new Event ();
- event.text = ids [focusIndex];
- sendEvent (SWT.Selection, event);
- break;
- case OS.XK_Tab:
- if (focusIndex < offsets.length - 1) {
- focusIndex++;
- redraw ();
- OS.memmove (continue_to_dispatch, new int [1], 4);
- return 1;
- }
- break;
- case OS.XK_ISO_Left_Tab:
- if (focusIndex > 0) {
- focusIndex--;
- redraw ();
- OS.memmove (continue_to_dispatch, new int [1], 4);
- return 1;
- }
- break;
- }
- return result;
-}
-int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XPointerMotion (w, client_data, call_data, continue_to_dispatch);
- if (result != 0) return result;
- XMotionEvent xEvent = new XMotionEvent ();
- OS.memmove (xEvent, call_data, XMotionEvent.sizeof);
- if ((xEvent.state & OS.Button1Mask) != 0) {
- int oldSelection = selection.y;
- selection.y = layout.getOffset (xEvent.x, xEvent.y, null);
- if (selection.y != oldSelection) {
- int newSelection = selection.y;
- if (oldSelection > newSelection) {
- int temp = oldSelection;
- oldSelection = newSelection;
- newSelection = temp;
- }
- Rectangle rect = layout.getBounds (oldSelection, newSelection);
- redraw (rect.x, rect.y, rect.width, rect.height, false);
- }
- return result;
- }
- for (int j = 0; j < offsets.length; j++) {
- Rectangle [] rects = getRectangles (j);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rect = rects [i];
- if (rect.contains (xEvent.x, xEvent.y)) {
- setCursor (display.getSystemCursor (SWT.CURSOR_HAND));
- return result;
- }
- }
- }
- setCursor (null);
- return result;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java
deleted file mode 100755
index 16b42b1466..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java
+++ /dev/null
@@ -1,1567 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-
-/**
- * Instances of this class represent a selectable user interface
- * object that displays a list of strings and issues notification
- * when a string is selected. A list may be single or multi select.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection</dd>
- * </dl>
- * <p>
- * Note: Only one of SINGLE and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#list">List snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class List extends Scrollable {
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public List (Composite parent, int style) {
- /*
- * Feature in Motif. It is not possible to create
- * scrolled list that will never show the vertical
- * scroll bar. Therefore, not matter what style
- * bits are specified, set the V_SCROLL bits to
- * match the widget Motif creates.
- */
- super (parent, checkStyle (style | SWT.V_SCROLL));
-}
-/**
- * Adds the argument to the end of the receiver's list.
- *
- * @param string the new item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String,int)
- */
-public void add (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- OS.XmListAddItemUnselected (handle, xmString, 0);
- OS.XmStringFree (xmString);
-}
-/**
- * Adds the argument to the receiver's list at the given
- * zero-relative index.
- * <p>
- * Note: To add an item at the end of the list, use the
- * result of calling <code>getItemCount()</code> as the
- * index or use <code>add(String)</code>.
- * </p>
- *
- * @param string the new item
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String)
- */
-public void add (String string, int index) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (index == -1) error (SWT.ERROR_INVALID_RANGE);
- /*
- * Feature in Motif. When an index is out of range,
- * the list widget adds the item at the end. This
- * behavior is not wrong but it is unwanted. The
- * fix is to check the range before adding the item.
- */
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= index && index <= argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- OS.XmListAddItemUnselected (handle, xmString, index + 1);
- OS.XmStringFree (xmString);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the selection changes.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-static int checkStyle (int style) {
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- XtWidgetGeometry result = new XtWidgetGeometry ();
- result.request_mode = OS.CWWidth;
- OS.XtQueryGeometry (handle, null, result);
- int width = result.width, height = 0;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- if (hHint == SWT.DEFAULT || wHint == SWT.DEFAULT) {
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int count = argList [1];
- if (hHint == SWT.DEFAULT) {
- if (count == 0) {
- height = DEFAULT_HEIGHT;
- } else {
- height = getItemHeight () * count;
- }
- }
- if (wHint == SWT.DEFAULT && count == 0) {
- width = DEFAULT_WIDTH;
- }
- }
- Rectangle rect = computeTrim (0, 0, width, height);
- return new Point (rect.width, rect.height);
-}
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- int border = getBorderWidth ();
- int trimX = x - border;
- int trimY = y - border;
- int trimWidth = width + (border * 2);
- int trimHeight = height + (border * 2);
- if (horizontalBar != null) {
- int [] argList = {OS.XmNheight, 0};
- OS.XtGetValues (horizontalBar.handle, argList, argList.length / 2);
- /*
- * Motif adds four pixels between the bottom of the
- * list and the horizontal scroll bar. Add those now.
- */
- trimHeight += argList [1] + 4;
- trimY -= display.scrolledInsetY;
- if (verticalBar != null) {
- trimX -= display.scrolledInsetX;
- }
- }
- if (verticalBar != null) {
- int [] argList = {OS.XmNwidth, 0};
- OS.XtGetValues (verticalBar.handle, argList, argList.length / 2);
- trimWidth += argList [1];
- trimX -= display.scrolledInsetX;
- if (horizontalBar != null) {
- trimY -= display.scrolledInsetY;
- }
- }
- int [] argList = {
- OS.XmNhighlightThickness, 0, /* 1 */
- OS.XmNshadowThickness, 0, /* 3 */
- OS.XmNlistMarginWidth, 0, /* 5 */
- OS.XmNlistMarginHeight, 0 /* 7 */
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int thickness = argList [1] + (argList [3] * 2);
- trimWidth += thickness + argList [5] + 1;
- trimHeight += thickness + argList [7] + 1;
- trimX -= argList [1] + argList [3] + argList [5];
- trimY -= argList [1] + argList [3] + argList [7];
- return new Rectangle (trimX, trimY, trimWidth, trimHeight);
-}
-void createHandle (int index) {
- /*
- * Feature in Motif. When items are added or removed
- * from a list, it may request and be granted, a new
- * preferred size. This behavior is unwanted. The fix
- * is to create a parent for the list that will disallow
- * geometry requests.
- */
- int parentHandle = parent.handle;
- int [] argList1 = {OS.XmNancestorSensitive, 1};
- formHandle = OS.XmCreateForm (parentHandle, null, argList1, argList1.length / 2);
- if (formHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int selectionPolicy = OS.XmBROWSE_SELECT, listSizePolicy = OS.XmCONSTANT;
- if ((style & SWT.MULTI) != 0) {
- selectionPolicy = OS.XmEXTENDED_SELECT;
- if ((style & SWT.SIMPLE) != 0) selectionPolicy = OS.XmMULTIPLE_SELECT;
- }
- if ((style & SWT.H_SCROLL) == 0) listSizePolicy = OS.XmVARIABLE;
- int [] argList2 = {
- OS.XmNlistSizePolicy, listSizePolicy,
- OS.XmNselectionPolicy, selectionPolicy,
- OS.XmNtopAttachment, OS.XmATTACH_FORM,
- OS.XmNbottomAttachment, OS.XmATTACH_FORM,
- OS.XmNleftAttachment, OS.XmATTACH_FORM,
- OS.XmNrightAttachment, OS.XmATTACH_FORM,
- OS.XmNresizable, 0,
-// OS.XmNmatchBehavior, OS.XmNONE,
- };
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
- handle = OS.XmCreateList (formHandle, null, argList2, argList2.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- } else {
- handle = OS.XmCreateScrolledList (formHandle, new byte [1], argList2, argList2.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- scrolledHandle = OS.XtParent (handle);
- }
- if ((style & SWT.BORDER) == 0) {
- int [] argList3 = new int [] {OS.XmNshadowThickness, 0};
- OS.XtSetValues (handle, argList3, argList3.length / 2);
- }
-}
-ScrollBar createScrollBar (int type) {
- return createStandardBar (type);
-}
-int defaultBackground () {
- return display.listBackground;
-}
-Font defaultFont () {
- return display.listFont;
-}
-int defaultForeground () {
- return display.listForeground;
-}
-/**
- * Deselects the item at the given zero-relative index in the receiver.
- * If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget();
- /*
- * Note: We rely on the fact that XmListDeselectPos ()
- * fails silently when the indices are out of range.
- */
- if (index != -1) OS.XmListDeselectPos (handle, index + 1);
-}
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. The range of the
- * indices is inclusive. Indices that are out of range are ignored.
- *
- * @param start the start index of the items to deselect
- * @param end the end index of the items to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int start, int end) {
- checkWidget();
- if (start > end) return;
- /*
- * Note: We rely on the fact that XmListDeselectPos ()
- * fails silently when the indices are out of range.
- */
- for (int i=start; i<=end; i++) {
- int index = i + 1;
- if (index != 0) OS.XmListDeselectPos (handle, index);
- }
-}
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. Indices that are out
- * of range and duplicate indices are ignored.
- *
- * @param indices the array of indices for the items to deselect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int [] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- /*
- * Note: We rely on the fact that XmListDeselectPos ()
- * fails silently when the indices are out of range.
- */
- for (int i=0; i<indices.length; i++) {
- int index = indices [i] + 1;
- if (index != 0) OS.XmListDeselectPos (handle, index);
- }
-}
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll () {
- checkWidget();
- OS.XmListDeselectAllItems (handle);
-}
-/**
- * Returns the zero-relative index of the item which currently
- * has the focus in the receiver, or -1 if no item has focus.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getFocusIndex () {
- checkWidget();
- return OS.XmListGetKbdItemPos (handle) - 1;
-}
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getItem (int index) {
- checkWidget();
- int [] argList = {OS.XmNitemCount, 0, OS.XmNitems, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= index && index < argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- if (argList [3] == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- int ptr = argList [3] + (index * 4);
- int [] buffer1 = new int [1];
- OS.memmove (buffer1, ptr, 4);
- ptr = buffer1 [0];
- int [] table = new int [] {display.tabMapping, display.crMapping};
- int address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- table,
- table.length,
- OS.XmOUTPUT_ALL);
- if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- OS.XtFree (address);
- return new String (Converter.mbcsToWcs (getCodePage (), buffer));
-}
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the list.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget();
- int [] argList = {
- OS.XmNlistSpacing, 0,
- OS.XmNhighlightThickness, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int spacing = argList [1], highlight = argList [3];
-
- /* Result is from empirical analysis on Linux and AIX */
- return getFontHeight (font.handle) + spacing + highlight + 1;
-}
-/**
- * Returns a (possibly empty) array of <code>String</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver's list
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getItems () {
- checkWidget();
- int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int items = argList [1], itemCount = argList [3];
- int [] buffer1 = new int [1];
- String [] result = new String [itemCount];
- String codePage = getCodePage ();
- for (int i=0; i<itemCount; i++) {
- OS.memmove (buffer1, items, 4);
- int ptr = buffer1 [0];
- int [] table = new int [] {display.tabMapping, display.crMapping};
- int address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- table,
- table.length,
- OS.XmOUTPUT_ALL);
- if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- OS.XtFree (address);
- result[i] = new String (Converter.mbcsToWcs (codePage, buffer));
- items += 4;
- }
- return result;
-}
-/**
- * Returns an array of <code>String</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getSelection () {
- checkWidget();
- int [] argList = {OS.XmNselectedItems, 0, OS.XmNselectedItemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int items = argList [1], itemCount = argList [3];
- int [] buffer1 = new int [1];
- String [] result = new String [itemCount];
- String codePage = getCodePage ();
- for (int i=0; i<itemCount; i++) {
- OS.memmove (buffer1, items, 4);
- int ptr = buffer1 [0];
- int[] table = new int[] {display.tabMapping, display.crMapping};
- int address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- table,
- table.length,
- OS.XmOUTPUT_ALL);
- if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- OS.XtFree (address);
- result[i] = new String (Converter.mbcsToWcs (codePage, buffer));
- items += 4;
- }
- return result;
-}
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget();
- int [] argList = {OS.XmNselectedItemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item or -1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget();
- int index = OS.XmListGetKbdItemPos (handle);
- if (OS.XmListPosSelected (handle, index)) return index - 1;
- int [] count = new int [1], positions = new int [1];
- if (!OS.XmListGetSelectedPos (handle, positions, count)) return -1;
- if (count [0] == 0) return -1;
- int address = positions [0];
- int [] indices = new int [1];
- OS.memmove (indices, address, 4);
- OS.XtFree (address);
- return indices [0] - 1;
-}
-/**
- * Returns the zero-relative indices of the items which are currently
- * selected in the receiver. The order of the indices is unspecified.
- * The array is empty if no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return the array of indices of the selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int [] getSelectionIndices () {
- checkWidget();
- int [] count = new int [1], positions = new int [1];
- OS.XmListGetSelectedPos (handle, positions, count);
- int [] result = new int [count [0]];
- OS.memmove (result, positions [0], count [0] * 4);
- if (positions [0] != 0) OS.XtFree (positions [0]);
- for (int i=0; i<result.length; i++) --result [i];
- return result;
-}
-/**
- * Returns the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items are
- * scrolled or new items are added or removed.
- *
- * @return the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget();
- int [] argList = {OS.XmNtopItemPosition, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] - 1;
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- OS.XtAddCallback (handle, OS.XmNbrowseSelectionCallback, windowProc, BROWSE_SELECTION_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNextendedSelectionCallback, windowProc, EXTENDED_SELECTION_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNmultipleSelectionCallback, windowProc, MULTIPLE_SELECTION_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNdefaultActionCallback, windowProc, DEFAULT_ACTION_CALLBACK);
-}
-/**
- * Gets the index of an item.
- * <p>
- * The list is searched starting at 0 until an
- * item is found that is equal to the search item.
- * If no item is found, -1 is returned. Indexing
- * is zero based.
- *
- * @param string the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) return -1;
- int index = OS.XmListItemPos (handle, xmString);
- OS.XmStringFree (xmString);
- return index - 1;
-}
-/**
- * Searches the receiver's list starting at the given,
- * zero-relative index until an item is found that is equal
- * to the argument, and returns the index of that item. If
- * no item is found or the starting index is out of range,
- * returns -1.
- *
- * @param string the search item
- * @param start the zero-relative index at which to start the search
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string, int start) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int items = argList [1], itemCount = argList [3];
- if (!((0 <= start) && (start < itemCount))) return -1;
- byte [] buffer1 = Converter.wcsToMbcs (getCodePage (), string, true);
- int xmString = OS.XmStringCreateLocalized (buffer1);
- if (xmString == 0) return -1;
- int index = start;
- items += start * 4;
- int [] buffer2 = new int [1];
- while (index < itemCount) {
- OS.memmove (buffer2, items, 4);
- if (OS.XmStringCompare (buffer2 [0], xmString)) break;
- items += 4; index++;
- }
- OS.XmStringFree (xmString);
- if (index == itemCount) return -1;
- return index;
-}
-/**
- * Returns <code>true</code> if the item is selected,
- * and <code>false</code> otherwise. Indices out of
- * range are ignored.
- *
- * @param index the index of the item
- * @return the selection state of the item at the index
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isSelected (int index) {
- checkWidget();
- if (index == -1) return false;
- return OS.XmListPosSelected (handle, index + 1);
-}
-void overrideTranslations () {
- OS.XtOverrideTranslations (handle, display.tabTranslations);
-}
-/**
- * Removes the item from the receiver at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget();
- if (index == -1) error (SWT.ERROR_INVALID_RANGE);
- /*
- * Feature in Motif. An index out of range handled
- * correctly by the list widget but causes an unwanted
- * Xm Warning. The fix is to check the range before
- * deleting an item.
- */
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= index && index < argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- OS.XmListDeletePos (handle, index + 1);
-}
-/**
- * Removes the items from the receiver which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget();
- if (start > end) return;
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= start && start <= end && end < argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int count = end - start + 1;
- OS.XmListDeleteItemsPos (handle, count, start + 1);
-}
-/**
- * Searches the receiver's list starting at the first item
- * until an item is found that is equal to the argument,
- * and removes that item from the list.
- *
- * @param string the item to remove
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
- int index = OS.XmListItemPos (handle, xmString);
- OS.XmStringFree (xmString);
- if (index == 0) error (SWT.ERROR_INVALID_ARGUMENT);
- OS.XmListDeletePos (handle, index);
-}
-/**
- * Removes the items from the receiver at the given
- * zero-relative indices.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int [] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int [] newIndices = new int [indices.length];
- for (int i=0; i<indices.length; i++) {
- if (!(0 <= indices [i] && indices [i] < argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- newIndices [i] = indices [i] + 1;
- }
- OS.XmListDeletePositions (handle, newIndices, newIndices.length);
-}
-/**
- * Removes all of the items from the receiver.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget();
- OS.XmListDeselectAllItems (handle);
- OS.XmListDeleteAllItems (handle);
- /*
- * Bug in AIX. When all list items are deleted
- * from a scrolled list that is currently showing a
- * horizontal scroll bar, the horizontal scroll bar
- * is hidden, but the list does not grow to take up
- * the space once occupied by the bar. The fix is
- * of force a resize of the list.
- */
- if ((style & SWT.H_SCROLL) != 0) OS.XtResizeWindow (handle);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-/**
- * Selects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget();
- if (index == -1) return;
- if (OS.XmListPosSelected (handle, index + 1)) return;
- /*
- * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos ()
- * in a XmEXTENDED_SELECT list widget will add the index to the selected
- * indices. The observed behavior does not match the spec. The fix is
- * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT
- * and then switch it back because XmListSelectPost () works as specified
- * for XmMULTIPLE_SELECT list widgets.
- */
- int [] argList = {OS.XmNselectionPolicy, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int oldPolicy = argList [1];
- if (oldPolicy == OS.XmEXTENDED_SELECT) {
- argList [1] = OS.XmMULTIPLE_SELECT;
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
- /*
- * Note: We rely on the fact that XmListSelectPos ()
- * fails silently when the indices are out of range.
- */
- OS.XmListSelectPos (handle, index + 1, false);
- if (oldPolicy == OS.XmEXTENDED_SELECT) {
- argList [1] = OS.XmEXTENDED_SELECT;
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
-}
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If an item in the given range is not selected, it is selected.
- * If an item in the given range was already selected, it remains selected.
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#setSelection(int,int)
- */
-public void select (int start, int end) {
- checkWidget ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int count = argList[1];
- if (count == 0 || start >= count) return;
- start = Math.max (0, start);
- end = Math.min (end, count - 1);
- if ((style & SWT.SINGLE) != 0) {
- OS.XmListSelectPos (handle, start + 1, false);
- return;
- }
- /*
- * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos ()
- * in a XmEXTENDED_SELECT list widget will add the index to the selected
- * indices. The observed behavior does not match the spec. The fix is
- * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT
- * and then switch it back because XmListSelectPos () works as specified
- * for XmMULTIPLE_SELECT list widgets.
- */
- argList = new int[] {OS.XmNselectionPolicy, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int oldPolicy = argList [1];
- if (oldPolicy == OS.XmEXTENDED_SELECT) {
- argList [1] = OS.XmMULTIPLE_SELECT;
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
- /*
- * Note: XmListSelectPos () fails silently when the indices are out of range.
- */
- for (int i=start; i<=end; i++) {
- int index = i + 1;
- if (!OS.XmListPosSelected (handle, index)) {
- OS.XmListSelectPos (handle, index, false);
- }
- }
- if (oldPolicy == OS.XmEXTENDED_SELECT) {
- argList [1] = OS.XmEXTENDED_SELECT;
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
-}
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If the item at a given index is not selected, it is selected.
- * If the item at a given index was already selected, it remains selected.
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- *
- * @param indices the array of indices for the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#setSelection(int[])
- */
-public void select (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- if ((style & SWT.SINGLE) != 0) {
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int count = argList [1];
- int index = indices [0];
- if (0 <= index && index < count) {
- select (index);
- }
- return;
- }
- /*
- * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos ()
- * in a XmEXTENDED_SELECT list widget will add the index to the selected
- * indices. The observed behavior does not match the spec. The fix is
- * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT
- * and then switch it back because XmListSelectPos () works as specified
- * for XmMULTIPLE_SELECT list widgets.
- */
- int [] argList = {OS.XmNselectionPolicy, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int oldPolicy = argList [1];
- if (oldPolicy == OS.XmEXTENDED_SELECT) {
- argList [1] = OS.XmMULTIPLE_SELECT;
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
- /*
- * Note: We rely on the fact that XmListSelectPos ()
- * fails silently when the indices are out of range.
- */
- for (int i=0; i<length; i++) {
- int index = indices [i] + 1;
- if ((index != 0) && !OS.XmListPosSelected (handle, index)) {
- OS.XmListSelectPos (handle, index, false);
- }
- }
- if (oldPolicy == OS.XmEXTENDED_SELECT) {
- argList [1] = OS.XmEXTENDED_SELECT;
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
-}
-void select (String [] items) {
- checkWidget();
- int [] table = new int [items.length];
- String codePage = getCodePage ();
- for (int i=0; i<items.length; i++) {
- String string = items [i];
- byte [] buffer = Converter.wcsToMbcs (codePage, string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- table [i] = xmString;
- }
- int ptr = OS.XtMalloc (items.length * 4);
- OS.memmove (ptr, table, items.length * 4);
- int [] argList = {OS.XmNselectedItems, ptr, OS.XmNselectedItemCount, table.length};
- OS.XtSetValues (handle, argList, argList.length / 2);
- for (int i=0; i<table.length; i++) OS.XmStringFree (table [i]);
- OS.XtFree (ptr);
- OS.XmListUpdateSelectedList (handle);
-}
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return;
- /*
- * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos ()
- * in a XmEXTENDED_SELECT list widget will add the index to the selected
- * indices. The observed behavior does not match the spec. The fix is
- * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT
- * and then switch it back because XmListSelectPos () works as specified
- * for XmMULTIPLE_SELECT list widgets.
- */
- int [] argList = {OS.XmNselectionPolicy, 0, OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int oldPolicy = argList [1];
- if (oldPolicy == OS.XmEXTENDED_SELECT) {
- argList [1] = OS.XmMULTIPLE_SELECT;
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
- for (int i=0; i<argList[3]; i++) {
- int index = i + 1;
- if (!OS.XmListPosSelected (handle, index)) {
- OS.XmListSelectPos (handle, index, false);
- }
- }
- if (oldPolicy == OS.XmEXTENDED_SELECT) {
- argList [1] = OS.XmEXTENDED_SELECT;
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- boolean changed = super.setBounds (x, y, width, height, move, resize);
- /*
- * Bug in AIX. When the receiver has a vertical scroll bar
- * that is currently not visible and no horizontal scroll bar
- * and is resized to be smaller in both the width and height
- * and goes from the state where the width of the longest item
- * is smaller than the width of the list to the state where the
- * width of the longest item is longer than the width of the
- * list, the list hides the vertical scroll bar and leaves a
- * blank space where it should be. This often happens when a
- * shell containing a list that matches the above criteria is
- * maximized and then restored. This is just one of a number
- * of repeatable cases where the scrolled window hides the
- * scroll bars but does not resize the list. The fix is to
- * detect these cases and force the scroll bars to be laid
- * out properly by growing and then shrinking the scrolled
- * window.
- */
-
- /* Grow and shrink the scrolled window by one pixel */
- if (changed && scrolledHandle != 0) {
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
- OS.XtResizeWidget (scrolledHandle, argList [1] + 1, argList [3], argList [5]);
- OS.XtResizeWidget (scrolledHandle, argList [1], argList [3], argList [5]);
- }
- return changed;
-}
-void setFocusIndex (int index) {
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int count = argList [1];
- if (!(0 <= index && index < count)) return;
- OS.XmListSetKbdItemPos (handle, index + 1);
-}
-public void setFont (Font font) {
- checkWidget ();
-
- /*
- * Bug in Motif. Setting the font in a list widget that does
- * not have any items causes a GP on UTF-8 locale.
- * The fix is to add an item, change the font, then
- * remove the added item at the end.
- */
- int [] argList1 = {OS.XmNitems, 0, OS.XmNitemCount, 0,};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- boolean fixString = OS.IsDBLocale && argList1 [3] == 0;
- if (fixString) {
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), "string", true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- OS.XmListAddItemUnselected (handle, xmString, -1);
- OS.XmStringFree (xmString);
- }
- super.setFont (font);
- if (fixString) OS.XtSetValues (handle, argList1, argList1.length / 2);
-}
-/**
- * Sets the text of the item in the receiver's list at the given
- * zero-relative index to the string argument.
- *
- * @param index the index for the item
- * @param string the new text for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItem (int index, String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (index == -1) error (SWT.ERROR_INVALID_RANGE);
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= index && index < argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- boolean isSelected = OS.XmListPosSelected (handle, index + 1);
- OS.XmListReplaceItemsPosUnselected (handle, new int [] {xmString}, 1, index + 1);
- if (isSelected) OS.XmListSelectPos (handle, index + 1, false);
- OS.XmStringFree (xmString);
-}
-/**
- * Sets the receiver's items to be the given array of items.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItems (String [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<items.length; i++) {
- if (items [i] == null) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- /*
- * Bug in AIX. When all list items are replaced
- * in a scrolled list that is currently showing a
- * horizontal scroll bar, the horizontal scroll bar
- * is hidden, but the list does not grow to take up
- * the space once occupied by the bar. The fix is
- * of force the horizontal bar to be recomputed by
- * removing all items and resizing the list.
- */
- OS.XmListSetPos (handle, 0);
- OS.XmListDeselectAllItems (handle);
- if ((style & SWT.H_SCROLL) != 0) {
- OS.XmListDeleteAllItems (handle);
- }
- int index = 0;
- int [] table = new int [items.length];
- String codePage = getCodePage ();
- while (index < items.length) {
- String string = items [index];
- byte [] buffer = Converter.wcsToMbcs (codePage, string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) break;
- table [index++] = xmString;
- }
- int ptr = OS.XtMalloc (index * 4);
- OS.memmove (ptr, table, index * 4);
- int [] argList = {OS.XmNitems, ptr, OS.XmNitemCount, index};
- OS.XtSetValues (handle, argList, argList.length / 2);
- for (int i=0; i<index; i++) OS.XmStringFree (table [i]);
- OS.XtFree (ptr);
- /*
- * Bug in Motif. Resize the list to work around
- * the horizontal scroll bar display bug described
- * above.
- */
- if ((style & SWT.H_SCROLL) != 0) {
- OS.XtResizeWindow (handle);
- }
- if (index < items.length) error (SWT.ERROR_ITEM_NOT_ADDED);
-}
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains selected.
- * The current selection is first cleared, then the new item is selected.
- * Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @see List#deselectAll()
- * @see List#select(int)
- */
-public void setSelection (int index) {
- checkWidget();
- deselectAll ();
- select (index);
- showSelection ();
- if ((style & SWT.MULTI) != 0) {
- if (0 <= index) setFocusIndex (index);
- }
-}
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- *
- * @param start the start index of the items to select
- * @param end the end index of the items to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int,int)
- */
-public void setSelection (int start, int end) {
- checkWidget ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) {
- deselectAll ();
- return;
- }
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int count = argList[1];
- if (count == 0 || start >= count) {
- deselectAll ();
- return;
- }
- start = Math.max (0, start);
- end = Math.min (end, count - 1);
- if ((style & SWT.MULTI) != 0) deselectAll ();
- select (start, end);
- showSelection ();
- if ((style & SWT.MULTI) != 0) {
- setFocusIndex (start);
- }
-}
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- *
- * @param indices the indices of the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int[])
- */
-public void setSelection(int[] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- select (indices);
- showSelection ();
- if ((style & SWT.MULTI) != 0) {
- int focusIndex = indices [0];
- if (0 <= focusIndex) setFocusIndex (focusIndex);
- }
-}
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int[])
- * @see List#setSelection(int[])
- */
-public void setSelection (String [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = items.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) {
- deselectAll ();
- return;
- }
- String codePage = getCodePage ();
- if ((style & SWT.SINGLE) != 0) {
- String string = items [0];
- if (string != null) {
- byte [] buffer = Converter.wcsToMbcs (codePage, string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString != 0) {
- int index = OS.XmListItemPos (handle, xmString);
- if (index != 0) OS.XmListSelectPos (handle, index, false);
- OS.XmStringFree (xmString);
- if (index != 0 && OS.XmListPosSelected (handle, index)) {
- showSelection ();
- return;
- }
- }
- }
- deselectAll ();
- return;
- }
- deselectAll ();
- int count = 0;
- int [] table = new int [length];
- for (int i=0; i<length; i++) {
- String string = items [i];
- if (string != null) {
- byte [] buffer = Converter.wcsToMbcs (codePage, string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString != 0) table [count++] = xmString;
- }
- }
- int ptr = OS.XtMalloc (count * 4);
- OS.memmove (ptr, table, count * 4);
- int [] argList = {OS.XmNselectedItems, ptr, OS.XmNselectedItemCount, count};
- OS.XtSetValues (handle, argList, argList.length / 2);
- boolean focusSet = false;
- for (int i = 0; i < count; i++) {
- if (!focusSet) {
- int index = OS.XmListItemPos (handle, table [i]);
- if (index > 0) {
- focusSet = true;
- setFocusIndex (index - 1);
- }
- }
- OS.XmStringFree (table [i]);
- }
- OS.XtFree (ptr);
- OS.XmListUpdateSelectedList (handle);
- showSelection ();
-}
-/**
- * Sets the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items
- * are scrolled or new items are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget();
- int [] argList = {OS.XmNitemCount, 0, OS.XmNvisibleItemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int newIndex = Math.max (1, Math.min (index + 1, argList [1]));
- int lastIndex = Math.max (1, argList [1] - argList [3] + 1);
- if (newIndex > lastIndex) newIndex = lastIndex;
- OS.XmListSetPos (handle, newIndex);
-}
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void showSelection () {
- checkWidget();
- int [] buffer = new int [1], positions = new int [1];
- if (!OS.XmListGetSelectedPos (handle, positions, buffer)) return;
- if (buffer [0] == 0) return;
- int address = positions [0];
- int [] indices = new int [1];
- OS.memmove (indices, address, 4);
- OS.XtFree (address);
- int index = indices [0];
- int [] argList = {
- OS.XmNtopItemPosition, 0,
- OS.XmNvisibleItemCount, 0,
- OS.XmNitemCount, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int topIndex = argList [1], visibleCount = argList [3], count = argList [5];
- int bottomIndex = Math.min (topIndex + visibleCount - 1, count);
- if ((topIndex <= index) && (index <= bottomIndex)) return;
- int lastIndex = Math.max (1, count - visibleCount + 1);
- int newTop = Math.min (Math.max (index - (visibleCount / 2), 1), lastIndex);
- OS.XmListSetPos (handle, newTop);
-}
-int topHandle () {
- /*
- * Normally, when a composite has both a form handle
- * and a scrolled handle, the scrolled handle is the
- * parent of the form handle. In the case of a list,
- * both handles are present but the form handle is
- * parent of the scrolled handle and therefore is
- * the top handle of the list.
- */
- return formHandle;
-}
-int XmNbrowseSelectionCallback (int w, int client_data, int call_data) {
- postEvent (SWT.Selection);
- return 0;
-}
-int XmNdefaultActionCallback (int w, int client_data, int call_data) {
- postEvent (SWT.DefaultSelection);
- return 0;
-}
-int XmNextendedSelectionCallback (int w, int client_data, int call_data) {
- postEvent (SWT.Selection);
- return 0;
-}
-int XmNmultipleSelectionCallback (int w, int client_data, int call_data) {
- postEvent (SWT.Selection);
- return 0;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java
deleted file mode 100755
index a9c5f18866..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java
+++ /dev/null
@@ -1,913 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are user interface objects that contain
- * menu items.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BAR, DROP_DOWN, POP_UP, NO_RADIO_GROUP</dd>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Help, Hide, Show </dd>
- * </dl>
- * <p>
- * Note: Only one of BAR, DROP_DOWN and POP_UP may be specified.
- * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#menu">Menu snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Menu extends Widget {
- boolean hasLocation;
- MenuItem cascade, defaultItem;
- Decorations parent;
-/**
- * Constructs a new instance of this class given its parent,
- * and sets the style for the instance so that the instance
- * will be a popup menu on the given parent's shell.
- * <p>
- * After constructing a menu, it can be set into its parent
- * using <code>parent.setMenu(menu)</code>. In this case, the parent may
- * be any control in the same widget tree as the parent.
- * </p>
- *
- * @param parent a control which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#POP_UP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Control parent) {
- this (checkNull(parent).menuShell (), SWT.POP_UP);
-}
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Decorations</code>) and a style value
- * describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * After constructing a menu or menuBar, it can be set into its parent
- * using <code>parent.setMenu(menu)</code> or <code>parent.setMenuBar(menuBar)</code>.
- * </p>
- *
- * @param parent a decorations control which will be the parent of the new instance (cannot be null)
- * @param style the style of menu to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BAR
- * @see SWT#DROP_DOWN
- * @see SWT#POP_UP
- * @see SWT#NO_RADIO_GROUP
- * @see SWT#LEFT_TO_RIGHT
- * @see SWT#RIGHT_TO_LEFT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Decorations parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (0);
-}
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>) and sets the style
- * for the instance so that the instance will be a drop-down
- * menu on the given parent's parent.
- * <p>
- * After constructing a drop-down menu, it can be set into its parentMenu
- * using <code>parentMenu.setMenu(menu)</code>.
- * </p>
- *
- * @param parentMenu a menu which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Menu parentMenu) {
- this (checkNull(parentMenu).parent, SWT.DROP_DOWN);
-}
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>MenuItem</code>) and sets the style
- * for the instance so that the instance will be a drop-down
- * menu on the given parent's parent menu.
- * <p>
- * After constructing a drop-down menu, it can be set into its parentItem
- * using <code>parentItem.setMenu(menu)</code>.
- * </p>
- *
- * @param parentItem a menu item which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (MenuItem parentItem) {
- this (checkNull(parentItem).parent);
-}
-void _setVisible (boolean visible) {
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- if (visible) {
- sendEvent (SWT.Show);
- if (getItemCount () != 0) {
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XDefaultRootWindow (xDisplay);
- if (xWindow == 0) return;
- int [] rootX = new int [1], rootY = new int [1], unused = new int [1], mask = new int [1];
- if (OS.XQueryPointer (xDisplay, xWindow, unused, unused, rootX, rootY, unused, unused, mask) == 0) {
- return;
- }
- if (!hasLocation) {
- /*
- * Bug in Motif. For some reason, when a menu is popped up
- * under the mouse, the menu will not highlight until the
- * mouse exits and then enters the menu again. The fix is
- * to pop the menu up outside the current mouse position
- * causing highlighting to work properly when the user
- * waits for the menu to appear.
- */
- rootX[0] += 1; rootY[0] += 1;
- int [] argList = {OS.XmNx, rootX [0], OS.XmNy, rootY [0]};
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
- /*
- * Feature in Motif. If an X grab is active, then
- * the menu pops us but issues and error message an
- * fails to grab the pointer. The fix is to ensure
- * that no grab is active before showing the menu.
- */
- OS.XUngrabPointer (xDisplay, OS.CurrentTime);
- OS.XtManageChild (handle);
- /*
- * Feature in Motif. There is no API to force the menu
- * to accept keyboard traversal when popped up using
- * XtManageChild. The fix is to call undocumented API
- * to do this.
- */
- int flags = OS.Button1Mask | OS.Button2Mask | OS.Button3Mask;
- if ((mask [0] & flags) == 0) OS._XmSetMenuTraversal (handle, true);
- } else {
- sendEvent (SWT.Hide);
- }
- } else {
- OS.XtUnmanageChild (handle);
- }
-}
-void addAccelerators () {
- MenuItem [] items = getItems ();
- for (int i = 0; i < items.length; i++) {
- MenuItem item = items[i];
- item.addAccelerators ();
- }
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when help events are generated for the control,
- * by sending it one of the messages defined in the
- * <code>HelpListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when menus are hidden or shown, by sending it
- * one of the messages defined in the <code>MenuListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuListener
- * @see #removeMenuListener
- */
-public void addMenuListener(MenuListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.Hide,typedListener);
- addListener(SWT.Show,typedListener);
-}
-static int checkStyle (int style) {
- return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0);
-}
-static Control checkNull (Control control) {
- if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return control;
-}
-static Menu checkNull (Menu menu) {
- if (menu == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return menu;
-}
-static MenuItem checkNull (MenuItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-void createHandle (int index) {
- /*
- * Bug in Motif. For some reason, creating a menu after any application context
- * and shell have been destroyed will segment fault unless a new application
- * context and shell have been created in the current thread. The fix is to
- * detect this case and create and destroy a temporary application context and
- * shell.
- */
- int xDisplay = 0, shellHandle = 0;
- if (Display.DisplayDisposed) {
- int [] argc = new int [] {0};
- int xtContext = OS.XtCreateApplicationContext ();
- xDisplay = OS.XtOpenDisplay (xtContext, null, null, null, 0, 0, argc, 0);
- shellHandle = OS.XtAppCreateShell (null, null, OS.topLevelShellWidgetClass (), xDisplay, null, 0);
- }
-
- /* BAR menu */
- if ((style & SWT.BAR) != 0) {
- int parentHandle = parent.scrolledHandle;
- int [] argList = {OS.XmNancestorSensitive, 1};
- handle = OS.XmCreateMenuBar (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- return;
- }
-
- /* POPUP and PULLDOWN menus */
-
- /*
- * Bug in Motif. When an existing popup menu is destroyed just
- * before creating a new popup menu and the new menu is managed,
- * the cursor changes to the menu cursor but the new menu is not
- * displayed. Also, Motif fails to show a popup menu when the
- * mouse is released. Both problems stem from the fact that the
- * popup menu is in the widget tree of a visible shell. The fix
- * is to create all popup menus as children of a hidden dialog
- * shell. Menus created this way are automatically destroyed
- * when the shell is destroyed.
- */
- byte [] buffer = new byte [1];
- int [] argList = {OS.XmNancestorSensitive, 1};
- if ((style & SWT.POP_UP) != 0) {
- int parentHandle = parent.dialogHandle ();
- handle = OS.XmCreatePopupMenu (parentHandle, buffer, argList, argList.length / 2);
- } else {
- /*
- * Bug in Linux. For some reason, when the parent of the pulldown
- * menu is not the main window handle, XtDestroyWidget() occasionally
- * segment faults when the shell is destroyed. The fix is to ensure
- * that the parent is the main window.
- */
- int parentHandle = parent.scrolledHandle;
- handle = OS.XmCreatePulldownMenu (parentHandle, buffer, argList, argList.length / 2);
- }
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-
- /* Workaround for bug in Motif */
- if (Display.DisplayDisposed) {
- if (shellHandle != 0) OS.XtDestroyWidget (shellHandle);
- if (xDisplay != 0) {
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- OS.XtDestroyApplicationContext (xtContext);
- }
- }
-}
-void createWidget (int index) {
- checkOrientation (parent);
- super.createWidget (index);
- parent.addMenu (this);
-}
-/*public*/ Rectangle getBounds () {
- checkWidget();
- if (!OS.XtIsManaged (handle)) return new Rectangle (0, 0, 0, 0);
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int x = argList [1], y = argList [3];
- if ((style & SWT.BAR) != 0) {
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (handle, (short) x, (short) x, root_x, root_y);
- x = root_x [0];
- y = root_y [0];
- }
- return new Rectangle (x, y, argList [5], argList [7]);
-}
-/**
- * Returns the default menu item or null if none has
- * been previously set.
- *
- * @return the default menu item.
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getDefaultItem () {
- checkWidget();
- return defaultItem;
-}
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled menu is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- int [] argList = {OS.XmNsensitive, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] != 0;
-}
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getItem (int index) {
- checkWidget();
- int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- int [] handles = new int [argList [3]];
- OS.memmove (handles, argList [1], argList[3] * 4);
- int i = 0, count = 0;
- while (i < argList [3]) {
- if (OS.XtIsManaged (handles [i])) {
- if (index == count) break;
- count++;
- }
- i++;
- }
- if (index != count) error (SWT.ERROR_INVALID_RANGE);
- Widget widget = display.getWidget (handles [i]);
- if (!(widget instanceof MenuItem)) error (SWT.ERROR_CANNOT_GET_ITEM);
- return (MenuItem) widget;
-}
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] == 0 || argList [3] == 0) return 0;
- int [] handles = new int [argList [3]];
- OS.memmove (handles, argList [1], argList [3] * 4);
- int count = 0;
- for (int i=0; i<argList [3]; i++) {
- if (OS.XtIsManaged (handles [i])) count++;
- }
- return count;
-}
-/**
- * Returns a (possibly empty) array of <code>MenuItem</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem [] getItems () {
- checkWidget();
- int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int ptr = argList [1], count = argList [3];
- if (count == 0 || ptr == 0) return new MenuItem [0];
- int [] handles = new int [count];
- OS.memmove (handles, ptr, count * 4);
- MenuItem [] items = new MenuItem [count];
- int i = 0, j = 0;
- while (i < count) {
- Widget item = display.getWidget (handles [i]);
- if (item != null) items [j++] = (MenuItem) item;
- i++;
- }
- if (i == j) return items;
- MenuItem [] newItems = new MenuItem [j];
- System.arraycopy (items, 0, newItems, 0, j);
- return newItems;
-}
-String getNameText () {
- String result = "";
- MenuItem [] items = getItems ();
- int length = items.length;
- if (length > 0) {
- for (int i=0; i<length-1; i++) {
- result = result + items [i].getNameText() + ", ";
- }
- result = result + items [length-1].getNameText ();
- }
- return result;
-}
-/**
- * Returns the receiver's parent, which must be a <code>Decorations</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Decorations getParent () {
- checkWidget();
- return parent;
-}
-/**
- * Returns the receiver's parent item, which must be a
- * <code>MenuItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getParentItem () {
- checkWidget();
- return cascade;
-}
-/**
- * Returns the receiver's parent item, which must be a
- * <code>Menu</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getParentMenu () {
- checkWidget();
- if (cascade != null) return cascade.parent;
- return null;
-}
-/**
- * Returns the receiver's shell. For all controls other than
- * shells, this simply returns the control's nearest ancestor
- * shell. Shells return themselves, even if they are children
- * of other shells.
- *
- * @return the receiver's shell
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getParent
- */
-public Shell getShell () {
- checkWidget();
- return parent.getShell ();
-}
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- if ((style & SWT.POP_UP) != 0) {
- Menu [] popups = display.popups;
- if (popups != null) {
- for (int i=0; i<popups.length; i++) {
- if (popups [i] == this) return true;
- }
- }
- }
- return OS.XtIsManaged (handle);
-}
-void hookEvents () {
- int windowProc = display.windowProc;
- OS.XtAddCallback (handle, OS.XmNhelpCallback, windowProc, HELP_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNmapCallback, windowProc, MAP_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNunmapCallback, windowProc, UNMAP_CALLBACK);
-}
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (MenuItem item) {
- checkWidget();
- int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int [] handles = new int [argList [3]];
- OS.memmove (handles, argList [1], handles.length * 4);
- int index = 0;
- for (int i=0; i<handles.length; i++) {
- if (OS.XtIsManaged (handles [i])) {
- if (handles [i] == item.handle) return index;
- index++;
- }
- }
- return -1;
-}
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled menu is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- Menu parentMenu = getParentMenu ();
- if (parentMenu == null) {
- return getEnabled () && parent.isEnabled ();
- }
- return getEnabled () && parentMenu.isEnabled ();
-}
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return getVisible ();
-}
-void releaseChildren (boolean destroy) {
- MenuItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- super.releaseChildren (destroy);
-}
-void releaseParent () {
- super.releaseParent ();
- if (cascade != null) cascade.setMenu (null);
- if ((style & SWT.BAR) != 0 && this == parent.menuBar) parent.setMenuBar (null);
-}
-void releaseWidget () {
- super.releaseWidget ();
- if (parent != null) parent.removeMenu (this);
- parent = null;
- cascade = defaultItem = null;
-}
-void removeAccelerators () {
- MenuItem [] items = getItems ();
- for (int i = 0; i < items.length; i++) {
- MenuItem item = items[i];
- item.removeAccelerators ();
- }
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the menu events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuListener
- * @see #addMenuListener
- */
-public void removeMenuListener(MenuListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Hide, listener);
- eventTable.unhook(SWT.Show, listener);
-}
-void sendHelpEvent (int callData) {
- if (hooks (SWT.Help)) {
- postEvent (SWT.Help);
- return;
- }
- parent.sendHelpEvent (callData);
-}
-/**
- * Sets the default menu item to the argument or removes
- * the default emphasis when the argument is <code>null</code>.
- *
- * @param item the default menu item or null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the menu item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDefaultItem (MenuItem item) {
- checkWidget();
- if (item != null && item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- defaultItem = item;
-}
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled menu is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * Sets the location of the receiver, which must be a popup,
- * to the point specified by the arguments which are relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p><p>
- * Note that the platform window manager ultimately has control
- * over the location of popup menus.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget();
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- int [] argList = {OS.XmNx, x, OS.XmNy, y};
- OS.XtSetValues (handle, argList, argList.length / 2);
- hasLocation = true;
-}
-/**
- * Sets the location of the receiver, which must be a popup,
- * to the point specified by the argument which is relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p><p>
- * Note that the platform window manager ultimately has control
- * over the location of popup menus.
- * </p>
- *
- * @param location the new location for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void setLocation (Point location) {
- checkWidget();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget();
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- if (visible) {
- display.addPopup (this);
- } else {
- display.removePopup (this);
- _setVisible (false);
- }
-}
-boolean translateAccelerator (int accel, boolean doit) {
- if (!getEnabled ()) return false;
- MenuItem [] items = getItems ();
- for (int i = 0; i < items.length; i++) {
- MenuItem item = items [i];
- if (item.translateAccelerator (accel, doit)) return true;
- }
- return false;
-}
-int XmNhelpCallback (int w, int client_data, int call_data) {
- sendHelpEvent (call_data);
- return 0;
-}
-int XmNmapCallback (int w, int client_data, int call_data) {
- if ((style & SWT.POP_UP) != 0) return 0;
- sendEvent (SWT.Show);
- return 0;
-}
-int XmNunmapCallback (int w, int client_data, int call_data) {
- sendEvent (SWT.Hide);
- return 0;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java
deleted file mode 100755
index 592f9042de..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java
+++ /dev/null
@@ -1,984 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that issues notification when pressed and released.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>CHECK, CASCADE, PUSH, RADIO, SEPARATOR</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Arm, Help, Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR
- * may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class MenuItem extends Item {
- int accelerator;
- Menu parent, menu;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a menu control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#CHECK
- * @see SWT#CASCADE
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public MenuItem (Menu parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (OS.XmLAST_POSITION);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a menu control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#CHECK
- * @see SWT#CASCADE
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public MenuItem (Menu parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- if (index == OS.XmLAST_POSITION) error (SWT.ERROR_INVALID_RANGE);
- createWidget (index);
-}
-void addAccelerator () {
- if (accelerator == 0 || !getEnabled ()) return;
- if ((accelerator & SWT.COMMAND) != 0) return;
- /*
- * Bug in Solaris. When accelerators are set more
- * than once in the same menu bar, the time it takes
- * to set the accelerator increases exponentially.
- * The fix is to implement our own accelerator table
- * on Solaris.
- */
- if (OS.IsSunOS) return;
- String ctrl, alt, shift;
- ctrl = alt = shift = "";
- if ((accelerator & SWT.ALT) != 0) alt = "Meta ";
- if ((accelerator & SWT.SHIFT) != 0) shift = "Shift ";
- if ((accelerator & SWT.CONTROL) != 0) ctrl = "Ctrl ";
- int keysym = accelerator & SWT.KEY_MASK;
- int newKey = Display.untranslateKey (keysym);
- if (newKey != 0) {
- keysym = newKey;
- } else {
- keysym = Display.wcsToMbcs ((char) keysym);
- }
- /*
- * Feature in Motif. Motif does not activate an accelerator
- * when the CapsLock, NumLock and NumLock+CapsLock keys are pressed.
- * In order to activate accelerators when these keys are pressed,
- * it is necessary to look for all of these key sequences. The fix
- * is to add these modifiers to the accelerator.
- */
- String key = ctrl + alt + shift + "<Key>" + keysymName (keysym);
- String allKeys = key + ",Lock " + key;
- String numLock = Display.numLock;
- if (numLock != null) {
- allKeys += "," + numLock + " " + key + ",Lock " + numLock + " " + key;
- }
- /* Use the character encoding for the default locale */
- byte [] buffer = Converter.wcsToMbcs (null, allKeys, true);
- int ptr = OS.XtMalloc (buffer.length);
- if (ptr != 0) OS.memmove (ptr, buffer, buffer.length);
-
- int [] argList = {OS.XmNaccelerator, ptr};
- OS.XtSetValues (handle, argList, argList.length / 2);
- if (ptr != 0) OS.XtFree (ptr);
-}
-void addAccelerators () {
- addAccelerator ();
- if (menu != null) menu.addAccelerators ();
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the arm events are generated for the control, by sending
- * it one of the messages defined in the <code>ArmListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ArmListener
- * @see #removeArmListener
- */
-public void addArmListener (ArmListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Arm, typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the help events are generated for the control, by sending
- * it one of the messages defined in the <code>HelpListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the menu item is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the stateMask field of the event object is valid.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the menu item is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-static int checkStyle (int style) {
- return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.CASCADE, 0);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-void createHandle (int index) {
- int parentHandle = parent.handle;
- int [] argList1 = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
- OS.XtGetValues (parentHandle, argList1, argList1.length / 2);
- if (index != OS.XmLAST_POSITION && argList1 [1] != 0) {
- int [] handles = new int [argList1 [3]];
- OS.memmove (handles, argList1 [1], argList1 [3] * 4);
- int i = 0, count = 0;
- while (i < argList1 [3]) {
- if (OS.XtIsManaged (handles [i])) {
- if (index == count) break;
- count++;
- }
- i++;
- }
- if (index != count) error (SWT.ERROR_INVALID_RANGE);
- index = i;
- }
- if ((style & SWT.SEPARATOR) != 0) {
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNorientation, (parent.style & SWT.BAR) != 0 ? OS.XmVERTICAL : OS.XmHORIZONTAL,
- OS.XmNpositionIndex, index,
- };
- handle = OS.XmCreateSeparatorGadget (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- return;
- }
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNpositionIndex, index,
- };
- if ((style & SWT.PUSH) != 0) {
- handle = OS.XmCreatePushButtonGadget (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- return;
- }
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- handle = OS.XmCreateToggleButtonGadget (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- int indicatorType = OS.XmONE_OF_MANY;
- if ((style & SWT.CHECK) != 0) indicatorType = OS.XmN_OF_MANY;
- int [] argList2 = {OS.XmNindicatorType, indicatorType};
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- return;
- }
- handle = OS.XmCreateCascadeButtonGadget (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-void destroyWidget () {
- /*
- * Feature in Motif. When a popup menu item
- * is destroyed, the menu does not recompute
- * the menu size until the next time the menu
- * is managed. This means that the user can
- * watch the menu get updated as new items are
- * added and old ones deleted. The fix is to
- * unmanaged the item before destroying it to
- * force the menu to recompute the menu size.
- */
- OS.XtUnmanageChild (handle);
- super.destroyWidget ();
-}
-/**
- * Returns the widget accelerator. An accelerator is the bit-wise
- * OR of zero or more modifier masks and a key. Examples:
- * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
- * The default value is zero, indicating that the menu item does
- * not have an accelerator.
- *
- * @return the accelerator or 0
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAccelerator () {
- checkWidget();
- return accelerator;
-}
-/*public*/ Rectangle getBounds () {
- checkWidget();
- if (!OS.XtIsManaged (handle)) return new Rectangle (0, 0, 0, 0);
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return new Rectangle ((short) argList [1], (short) argList [3], argList [5], argList [7]);
-}
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled menu item is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- int [] argList = {OS.XmNsensitive, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] != 0;
-}
-/**
- * Returns the receiver's cascade menu if it has one or null
- * if it does not. Only <code>CASCADE</code> menu items can have
- * a pull down menu. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pull down
- * menu is platform specific.
- *
- * @return the receiver's menu
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenu () {
- checkWidget();
- return menu;
-}
-String getNameText () {
- if ((style & SWT.SEPARATOR) != 0) return "|";
- return super.getNameText ();
-}
-/**
- * Returns the receiver's parent, which must be a <code>Menu</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getParent () {
- checkWidget();
- return parent;
-}
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked.
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
- int [] argList = {OS.XmNset, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] != OS.XmUNSET;
-}
-void hookEvents () {
- if ((style & SWT.SEPARATOR) != 0) return;
- int windowProc = display.windowProc;
- OS.XtAddCallback (handle, OS.XmNhelpCallback, windowProc, HELP_CALLBACK);
- if ((style & SWT.CASCADE) != 0) {
- OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNcascadingCallback, windowProc, CASCADING_CALLBACK);
- } else {
- OS.XtAddCallback (handle, OS.XmNarmCallback, windowProc, ARM_CALLBACK);
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
- } else {
- OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK);
- }
- }
-}
-boolean isAccelActive () {
- Menu menu = parent;
- while (menu != null && menu.cascade != null) {
- menu = menu.cascade.parent;
- }
- if (menu == null) return false;
- Decorations shell = menu.parent;
- return shell.menuBar == menu;
-}
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled menu item is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- return getEnabled () && parent.isEnabled ();
-}
-String keysymName (int keysym) {
- switch (keysym) {
- case SWT.BS: return "BackSpace";
- case SWT.TAB: return "Tab";
- /*
- * Bug in Motif. For some reason, the XmNaccelerator
- * resource will not accept XK_Linefeed and prints Xt
- * warnings. The fix is to use XK_Return instead.
- */
-// case SWT.LF:
-// case OS.XK_Linefeed: return "Linefeed";
- case SWT.LF:
- case OS.XK_Linefeed:
- case SWT.CR: return "Return";
- case SWT.ESC: return "Escape";
- case SWT.DEL: return "Delete";
- }
- if (('0' <= keysym && keysym <= '9') ||
- ('a' <= keysym && keysym <= 'z') ||
- ('A' <= keysym && keysym <= 'Z')) {
- return new String (new char [] {(char) keysym});
- }
- /*
- * Note that XKeysymToString returns a value in a static
- * area which must not be modified or freed.
- */
- int ptr = OS.XKeysymToString (keysym);
- if (ptr == 0) return "";
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, buffer.length);
- /* Use the character encoding for the default locale */
- return new String (Converter.mbcsToWcs (null, buffer));
-}
-void manageChildren () {
- OS.XtManageChild (handle);
-}
-void releaseChildren (boolean destroy) {
- if (menu != null) {
- menu.release (false);
- menu = null;
- }
- super.releaseChildren (destroy);
-}
-void releaseParent () {
- super.releaseParent ();
- if (menu != null) menu.dispose ();
- menu = null;
-}
-void releaseWidget () {
- super.releaseWidget ();
- accelerator = 0;
- if (this == parent.defaultItem) {
- parent.defaultItem = null;
- }
- parent = null;
-}
-void removeAccelerator () {
- if (accelerator == 0) return;
- /*
- * Bug in Solaris. When accelerators are set more
- * than once in the same menu bar, the time it takes
- * to set the accelerator increases exponentially.
- * The fix is to implement our own accelerator table
- * on Solaris.
- */
- if (OS.IsSunOS) return;
- int [] argList = {OS.XmNaccelerator, 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-void removeAccelerators () {
- removeAccelerator ();
- if (menu != null) menu.removeAccelerators ();
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the arm events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ArmListener
- * @see #addArmListener
- */
-public void removeArmListener (ArmListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Arm, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-void selectRadio () {
- int index = 0;
- MenuItem [] items = parent.getItems ();
- while (index < items.length && items [index] != this) index++;
- int i = index - 1;
- while (i >= 0 && items [i].setRadioSelection (false)) --i;
- int j = index + 1;
- while (j < items.length && items [j].setRadioSelection (false)) j++;
- setSelection (true);
-}
-/**
- * Sets the widget accelerator. An accelerator is the bit-wise
- * OR of zero or more modifier masks and a key. Examples:
- * <code>SWT.MOD1 | SWT.MOD2 | 'T', SWT.MOD3 | SWT.F2</code>.
- * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
- * The default value is zero, indicating that the menu item does
- * not have an accelerator.
- *
- * @param accelerator an integer that is the bit-wise OR of masks and a key
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAccelerator (int accelerator) {
- checkWidget();
- if (this.accelerator == accelerator) return;
- this.accelerator = accelerator;
- if (isAccelActive ()) {
- if (accelerator != 0) {
- addAccelerator ();
- } else {
- removeAccelerator ();
- }
- }
-}
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled menu item is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- if (getEnabled () == enabled) return;
- int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
- if (isAccelActive ()) {
- if (enabled) {
- addAccelerator ();
- } else {
- removeAccelerator ();
- }
- }
-}
-/**
- * Sets the receiver's pull down menu to the argument.
- * Only <code>CASCADE</code> menu items can have a
- * pull down menu. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pull down
- * menu is platform specific.
- * <p>
- * Note: Disposing of a menu item that has a pull down menu
- * will dispose of the menu. To avoid this behavior, set the
- * menu to null before the menu item is disposed.
- * </p>
- *
- * @param menu the new pull down menu
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_MENU_NOT_DROP_DOWN - if the menu is not a drop down menu</li>
- * <li>ERROR_MENUITEM_NOT_CASCADE - if the menu item is not a <code>CASCADE</code></li>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenu (Menu menu) {
- checkWidget();
- /* Check to make sure the new menu is valid */
- if ((style & SWT.CASCADE) == 0) {
- error (SWT.ERROR_MENUITEM_NOT_CASCADE);
- }
- if (menu != null) {
- if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.DROP_DOWN) == 0) {
- error (SWT.ERROR_MENU_NOT_DROP_DOWN);
- }
- if (menu.parent != parent.parent) {
- error (SWT.ERROR_INVALID_PARENT);
- }
- }
-
- /* Assign the new menu */
- Menu oldMenu = this.menu;
- if (oldMenu == menu) return;
-
- /*
- * Bug in Motif. When XmNsubMenuId is set and the
- * previous menu has accelerators, the time it takes
- * to add any new accelerators increases exponentially.
- * The fix is to remove the accelerators from the previous
- * menu before setting the new one.
- */
- boolean isActive = isAccelActive ();
- if (isActive) removeAccelerators ();
-
- if (oldMenu != null) oldMenu.cascade = null;
- this.menu = menu;
-
- /* Set the new menu in the OS */
- int menuHandle = 0;
- if (menu != null) {
- menu.cascade = this;
- menuHandle = menu.handle;
- }
- int [] argList = {OS.XmNsubMenuId, menuHandle};
- OS.XtSetValues (handle, argList, argList.length / 2);
-
- if (isActive) addAccelerators ();
-}
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-/**
- * Sets the selection state of the receiver.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked.
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
- int [] argList = {OS.XmNset, selected ? OS.XmSET : OS.XmUNSET};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character and accelerator text.
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- * <p>
- * Accelerator text is indicated by the '\t' character.
- * On platforms that support accelerator text, the text
- * that follows the '\t' character is displayed to the user,
- * typically indicating the key stroke that will cause
- * the item to become selected. On most platforms, the
- * accelerator text appears right aligned in the menu.
- * Setting the accelerator text does not install the
- * accelerator key sequence. The accelerator key sequence
- * is installed using #setAccelerator.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setAccelerator
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- /*
- * Feature in Motif. Motif does not optimize the case
- * when the same text is set into a menu item causing
- * it to flash. The fix is to test for equality and
- * do nothing.
- */
- if (text.equals (string)) return;
- super.setText (string);
- if ((style & (SWT.ARROW | SWT.SEPARATOR)) != 0) return;
-
- /*
- * Bug in Linux. In certain contexts setting the label of a
- * CHECK or RADIO menu item to the empty string can cause a
- * GP. The fix is to set the menu label to a space in such
- * cases since it displays equivalently.
- */
- if (OS.IsLinux && (style & (SWT.CHECK | SWT.RADIO)) != 0) {
- if (string.length () == 0) string = " ";
- }
- char [] text = new char [string.length ()];
- string.getChars (0, text.length, text, 0);
- boolean accel = false;
- int i=0, j=0, mnemonic=0;
- while (i < text.length) {
- if (text [i] == '\t') {accel = true; break;}
- if ((text [j++] = text [i++]) == '&') {
- if (i == text.length) {continue;}
- if (text [i] == '&') {i++; continue;}
- if (mnemonic == 0) mnemonic = text [i];
- j--;
- }
- }
- int xmString2 = 0;
- if (accel && ++i < text.length) {
- char [] accelText = new char [text.length - i];
- System.arraycopy (text, i, accelText, 0, accelText.length);
- /* Use the character encoding for the default locale */
- byte [] buffer2 = Converter.wcsToMbcs (null, accelText, true);
- xmString2 = OS.XmStringParseText (
- buffer2,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- if (xmString2 == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- } else {
- /*
- * Bug in linux. In some versions of linux motif setting a menu item's
- * accelerator to NULL will cause a GP. The workaround is to instead
- * set these accelerators to a functionally equivalent non-null value.
- */
- xmString2 = OS.XmStringGenerate (new byte[1], null, OS.XmCHARSET_TEXT, null);
- if (xmString2 == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- }
- while (j < text.length) text [j++] = 0;
- /* Use the character encoding for the default locale */
- byte [] buffer1 = Converter.wcsToMbcs (null, text, true);
- int xmString1 = OS.XmStringParseText (
- buffer1,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- if (xmString1 == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- if (mnemonic == 0) mnemonic = OS.XK_VoidSymbol;
- int [] argList = {
- OS.XmNlabelString, xmString1,
- OS.XmNmnemonic, mnemonic,
- OS.XmNacceleratorText, xmString2,
- };
- OS.XtSetValues (handle, argList, argList.length / 2);
- if (xmString1 != 0) OS.XmStringFree (xmString1);
- if (xmString2 != 0) OS.XmStringFree (xmString2);
-}
-boolean translateAccelerator (int accel, boolean doit) {
- if (!getEnabled ()) return false;
- if (menu != null) return menu.translateAccelerator (accel, doit);
- int accelerator = this.accelerator;
- if ((accelerator & SWT.KEYCODE_BIT) == 0) {
- int key = accelerator & SWT.KEY_MASK;
- if ('A' <= key && key <= 'Z') {
- key += 'a' - 'A';
- }
- int mods = accelerator & SWT.MODIFIER_MASK;
- accelerator = mods | key;
- }
- if (accelerator == accel) {
- if (doit) postEvent (SWT.Selection);
- return true;
- }
- return false;
-}
-int XmNactivateCallback (int w, int client_data, int call_data) {
- if ((style & SWT.CASCADE) != 0) {
- sendEvent (SWT.Arm);
- }
- if (!isEnabled ()) return 0;
- XmAnyCallbackStruct struct = new XmAnyCallbackStruct ();
- OS.memmove (struct, call_data, XmAnyCallbackStruct.sizeof);
- Event event = new Event ();
- if (struct.event != 0) {
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, struct.event, XButtonEvent.sizeof);
- event.time = xEvent.time;
- switch (xEvent.type) {
- case OS.ButtonPress:
- case OS.ButtonRelease:
- case OS.KeyPress:
- case OS.KeyRelease:
- setInputState (event, xEvent.state);
- break;
- }
- }
- postEvent (SWT.Selection, event);
- return 0;
-}
-int XmNarmCallback (int w, int client_data, int call_data) {
- sendEvent (SWT.Arm);
- return 0;
-}
-int XmNcascadingCallback (int w, int client_data, int call_data) {
- /*
- * Bug in Motif. When XmNlabelString is set as a result of
- * an XmNcascadingCallback after the callback has returned,
- * Motif measures the new string properly but does not draw
- * it. The fix is to send rather than post the SWT.Arm event.
- */
- sendEvent (SWT.Arm);
- return 0;
-}
-int XmNhelpCallback (int w, int client_data, int call_data) {
- if (hooks (SWT.Help)) {
- postEvent (SWT.Help);
- return 0;
- }
- parent.sendHelpEvent (call_data);
- return 0;
-}
-int XmNvalueChangedCallback (int w, int client_data, int call_data) {
- if (!isEnabled ()) return 0;
- XmAnyCallbackStruct struct = new XmAnyCallbackStruct ();
- OS.memmove (struct, call_data, XmAnyCallbackStruct.sizeof);
- Event event = new Event ();
- if (struct.event != 0) {
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, struct.event, XButtonEvent.sizeof);
- event.time = xEvent.time;
- switch (xEvent.type) {
- case OS.ButtonPress:
- case OS.ButtonRelease:
- case OS.KeyPress:
- case OS.KeyRelease:
- setInputState (event, xEvent.state);
- break;
- }
- }
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) {
- selectRadio ();
- }
- }
- postEvent (SWT.Selection, event);
- return 0;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java
deleted file mode 100755
index a8d37cdb22..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java
+++ /dev/null
@@ -1,436 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are used to inform or warn the user.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, ICON_WARNING, ICON_WORKING</dd>
- * <dd>OK, OK | CANCEL</dd>
- * <dd>YES | NO, YES | NO | CANCEL</dd>
- * <dd>RETRY | CANCEL</dd>
- * <dd>ABORT | RETRY | IGNORE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION, ICON_QUESTION,
- * ICON_WARNING and ICON_WORKING may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class MessageBox extends Dialog {
- int button;
- String message = ""; //$NON-NLS-1$
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public MessageBox (Shell parent) {
- this (parent, SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_QUESTION
- * @see SWT#ICON_WARNING
- * @see SWT#ICON_WORKING
- * @see SWT#OK
- * @see SWT#CANCEL
- * @see SWT#YES
- * @see SWT#NO
- * @see SWT#ABORT
- * @see SWT#RETRY
- * @see SWT#IGNORE
- */
-public MessageBox (Shell parent, int style) {
- super (parent, checkStyle (parent, checkStyle (style)));
- checkSubclass ();
-}
-int activate (int widget, int client, int call) {
- OS.XtUnmanageChild (widget);
- button = client;
- return 0;
-}
-static int checkStyle (int style) {
- int mask = (SWT.YES | SWT.NO | SWT.OK | SWT.CANCEL | SWT.ABORT | SWT.RETRY | SWT.IGNORE);
- int bits = style & mask;
- if (bits == SWT.OK || bits == SWT.CANCEL || bits == (SWT.OK | SWT.CANCEL)) return style;
- if (bits == SWT.YES || bits == SWT.NO || bits == (SWT.YES | SWT.NO) || bits == (SWT.YES | SWT.NO | SWT.CANCEL)) return style;
- if (bits == (SWT.RETRY | SWT.CANCEL) || bits == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) return style;
- style = (style & ~mask) | SWT.OK;
- return style;
-}
-int createHandle (int parentHandle, int [] argList) {
- if ((style & SWT.ICON_ERROR) != 0) return OS.XmCreateErrorDialog (parentHandle, null, argList, argList.length / 2);
- if ((style & SWT.ICON_INFORMATION) != 0) return OS.XmCreateInformationDialog (parentHandle, null, argList, argList.length / 2);
- if ((style & SWT.ICON_QUESTION) != 0) return OS.XmCreateQuestionDialog (parentHandle, null, argList, argList.length / 2);
- if ((style & SWT.ICON_WARNING) != 0) return OS.XmCreateWarningDialog (parentHandle, null, argList, argList.length / 2);
- if ((style & SWT.ICON_WORKING) != 0) return OS.XmCreateWorkingDialog (parentHandle, null, argList, argList.length / 2);
- return OS.XmCreateMessageDialog (parentHandle, null, argList, argList.length / 2);
-}
-
-/**
- * Returns the dialog's message, or an empty string if it does not have one.
- * The message is a description of the purpose for which the dialog was opened.
- * This message will be visible in the dialog while it is open.
- *
- * @return the message
- */
-public String getMessage () {
- return message;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return the ID of the button that was selected to dismiss the
- * message box (e.g. SWT.OK, SWT.CANCEL, etc.)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public int open () {
- /* Compute the dialog title */
- /*
- * Feature in Motif. It is not possible to set a shell
- * title to an empty string. The fix is to set the title
- * to be a single space.
- */
- String string = title;
- if (string.length () == 0) string = " "; //$NON-NLS-1$
- /* Use the character encoding for the default locale */
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- int xmStringPtr = OS.XmStringParseText (
- buffer,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- /*
- * Feature in Motif. The modal values are only hints
- * to the window manager. For example Enlightenment treats all modes
- * as SWT.APPLICATION_MODAL. The generic Motif
- * Window Manager honours all modes.
- */
- int dialogStyle = OS.XmDIALOG_MODELESS;
- if ((style & SWT.PRIMARY_MODAL) != 0) dialogStyle = OS.XmDIALOG_PRIMARY_APPLICATION_MODAL;
- if ((style & SWT.APPLICATION_MODAL) != 0) dialogStyle = OS.XmDIALOG_FULL_APPLICATION_MODAL;
- if ((style & SWT.SYSTEM_MODAL) != 0) dialogStyle = OS.XmDIALOG_SYSTEM_MODAL;
- if (dialogStyle == OS.XmDIALOG_MODELESS) {
- dialogStyle = OS.XmDIALOG_PRIMARY_APPLICATION_MODAL;
- }
- boolean defaultPos = parent.isVisible ();
- int [] argList = {
- OS.XmNnoResize, 1,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNdialogStyle, dialogStyle,
- OS.XmNdialogTitle, xmStringPtr,
- OS.XmNdefaultPosition, defaultPos ? 1 : 0,
- };
- int parentHandle = parent.shellHandle;
- int dialog = createHandle (parentHandle, argList);
- if (dialog == 0) error (SWT.ERROR_NO_HANDLES);
- OS.XmStringFree (xmStringPtr);
- setMessage (dialog);
- setButtons (dialog);
-
- /* Hook the callbacks. */
- Callback callback = new Callback (this, "activate", 3); //$NON-NLS-1$
- int address = callback.getAddress ();
- if (address == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- OS.XtAddCallback (dialog, OS.XmNokCallback, address, OS.XmDIALOG_OK_BUTTON);
- OS.XtAddCallback (dialog, OS.XmNcancelCallback, address, OS.XmDIALOG_CANCEL_BUTTON);
- OS.XtAddCallback (dialog, OS.XmNhelpCallback, address, OS.XmDIALOG_HELP_BUTTON);
-
- /* Open the dialog and dispatch events. */
- if (!defaultPos) {
- OS.XtRealizeWidget (dialog);
- int[] argList1 = new int[] {
- OS.XmNwidth, 0,
- OS.XmNheight, 0,
- };
- OS.XtGetValues (dialog, argList1, argList1.length / 2);
- Monitor monitor = parent.getMonitor ();
- Rectangle bounds = monitor.getBounds ();
- int x = bounds.x + (bounds.width - argList1 [1]) / 2;
- int y = bounds.y + (bounds.height - argList1 [3]) / 2;
- int[] argList2 = new int[] {
- OS.XmNx, x,
- OS.XmNy, y,
- };
- OS.XtSetValues (dialog, argList2, argList2.length / 2);
- }
- OS.XtManageChild (dialog);
-
- // Should be a pure OS message loop (no SWT AppContext)
- Display display = parent.display;
- while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog))
- if (!display.readAndDispatch()) display.sleep ();
-
- /* Destroy the dialog and update the display. */
- if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog);
- callback.dispose ();
-
- if ((style & (SWT.YES | SWT.NO | SWT.CANCEL)) == (SWT.YES | SWT.NO | SWT.CANCEL)) {
- if (button == OS.XmDIALOG_OK_BUTTON) return SWT.YES;
- if (button == OS.XmDIALOG_CANCEL_BUTTON) return SWT.NO;
- return SWT.CANCEL;
- }
- if ((style & (SWT.YES | SWT.NO)) == (SWT.YES | SWT.NO)) {
- return (button == OS.XmDIALOG_OK_BUTTON) ? SWT.YES : SWT.NO;
- }
- if ((style & (SWT.OK | SWT.CANCEL)) == (SWT.OK | SWT.CANCEL)) {
- return (button == OS.XmDIALOG_OK_BUTTON) ? SWT.OK : SWT.CANCEL;
- }
- if ((style & SWT.OK) == SWT.OK) return SWT.OK;
- if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) {
- return (button == OS.XmDIALOG_OK_BUTTON) ? SWT.RETRY : SWT.CANCEL;
- }
- if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) {
- if (button == OS.XmDIALOG_OK_BUTTON) return SWT.ABORT;
- if (button == OS.XmDIALOG_CANCEL_BUTTON) return SWT.RETRY;
- return SWT.IGNORE;
- }
- return SWT.CANCEL;
-}
-void setButtons (int dialogHandle) {
-
- /* Get the button children */
- OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_OK_BUTTON);
- int cancel = OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_CANCEL_BUTTON);
- int help = OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_HELP_BUTTON);
- OS.XtUnmanageChild (help);
-
- /* Set the button labels */
- if ((style & (SWT.OK | SWT.CANCEL)) == (SWT.OK | SWT.CANCEL)) return;
- if ((style & SWT.OK) == SWT.OK) {
- OS.XtUnmanageChild (cancel);
- return;
- }
- if ((style & (SWT.YES | SWT.NO | SWT.CANCEL)) == (SWT.YES | SWT.NO | SWT.CANCEL)) {
- OS.XtManageChild (help);
- /* Use the character encoding for the default locale */
- byte [] buffer1 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Yes"), true); //$NON-NLS-1$
- int xmString1 = OS.XmStringParseText (
- buffer1,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- /* Use the character encoding for the default locale */
- byte [] buffer2 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_No"), true); //$NON-NLS-1$
- int xmString2 = OS.XmStringParseText (
- buffer2,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- /* Use the character encoding for the default locale */
- byte [] buffer3 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Cancel"), true); //$NON-NLS-1$
- int xmString3 = OS.XmStringParseText (
- buffer3,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2, OS.XmNhelpLabelString, xmString3};
- OS.XtSetValues (dialogHandle, argList, argList.length / 2);
- OS.XmStringFree (xmString1); OS.XmStringFree (xmString2); OS.XmStringFree (xmString3);
- return;
- }
- if ((style & (SWT.YES | SWT.NO)) == (SWT.YES | SWT.NO)) {
- /* Use the character encoding for the default locale */
- byte [] buffer1 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Yes"), true); //$NON-NLS-1$
- int xmString1 = OS.XmStringParseText (
- buffer1,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- /* Use the character encoding for the default locale */
- byte [] buffer2 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_No"), true); //$NON-NLS-1$
- int xmString2 = OS.XmStringParseText (
- buffer2,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2};
- OS.XtSetValues (dialogHandle, argList, argList.length / 2);
- OS.XmStringFree (xmString1); OS.XmStringFree (xmString2);
- return;
- }
- if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) {
- /* Use the character encoding for the default locale */
- byte [] buffer1 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Retry"), true); //$NON-NLS-1$
- int xmString1 = OS.XmStringParseText (
- buffer1,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- /* Use the character encoding for the default locale */
- byte [] buffer2 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Cancel"), true); //$NON-NLS-1$
- int xmString2 = OS.XmStringParseText (
- buffer2,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2};
- OS.XtSetValues (dialogHandle, argList, argList.length / 2);
- OS.XmStringFree (xmString1); OS.XmStringFree (xmString2);
- return;
- }
- if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) {
- OS.XtManageChild (help);
- /* Use the character encoding for the default locale */
- byte [] buffer1 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Abort"), true); //$NON-NLS-1$
- int xmString1 = OS.XmStringParseText (
- buffer1,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- /* Use the character encoding for the default locale */
- byte [] buffer2 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Retry"), true); //$NON-NLS-1$
- int xmString2 = OS.XmStringParseText (
- buffer2,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- /* Use the character encoding for the default locale */
- byte [] buffer3 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Ignore"), true); //$NON-NLS-1$
- int xmString3 = OS.XmStringParseText (
- buffer3,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2, OS.XmNhelpLabelString, xmString3};
- OS.XtSetValues (dialogHandle, argList, argList.length / 2);
- OS.XmStringFree (xmString1); OS.XmStringFree (xmString2); OS.XmStringFree (xmString3);
- return;
- }
-}
-void setMessage (int dialogHandle) {
- String text = message;
- int label = OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_MESSAGE_LABEL);
- if (label != 0) {
- int [] argList = {OS.XmNfontList, 0};
- OS.XtGetValues (label, argList, argList.length / 2);
- int fontList = argList [1];
- if (fontList != 0) {
- Display display = parent.display;
- int xDisplay = display.xDisplay;
- int screen = OS.XDefaultScreen (xDisplay);
- int width = OS.XDisplayWidth (xDisplay, screen);
- Font font = Font.motif_new (display, fontList);
- text = display.wrapText (message, font, width * 3 / 5);
- }
- }
- /* Use the character encoding for the default locale */
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- int xmString = OS.XmStringGenerate(buffer, null, OS.XmCHARSET_TEXT, null);
- int [] argList = {OS.XmNmessageString, xmString};
- OS.XtSetValues (dialogHandle, argList, argList.length / 2);
- OS.XmStringFree (xmString);
-}
-
-/**
- * Sets the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @param string the message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- */
-public void setMessage (String string) {
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- message = string;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java
deleted file mode 100755
index e537ea4a53..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java
+++ /dev/null
@@ -1,422 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of the receiver represent an unselectable
- * user interface object that is used to display progress,
- * typically in the form of a bar.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SMOOTH, HORIZONTAL, VERTICAL, INDETERMINATE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#progressbar">ProgressBar snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ProgressBar extends Control {
- int timerId;
- static final int DELAY = 100;
- int foreground;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SMOOTH
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#INDETERMINATE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ProgressBar (Composite parent, int style) {
- /*
- * Feature in Motif. If you set the progress bar's value to 0,
- * the thumb does not disappear. In order to make this happen,
- * we hide the widget when the value is set to zero by changing
- * its colors to render it invisible, which means that it
- * would not visible unless a border is present. The fix is to
- * always ensure that there is a border, which will be drawn
- * even when the value is 0.
- */
- super (parent, checkStyle (style | SWT.BORDER));
-}
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- int hScroll = display.scrolledMarginX;
- int vScroll = display.scrolledMarginY;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += hScroll * 10;
- height += vScroll;
- } else {
- width += hScroll;
- height += vScroll * 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-void createHandle (int index) {
- int background = defaultBackground ();
- int parentHandle = parent.handle;
- int [] argList = {
- OS.XmNshowArrows, 0,
- OS.XmNsliderSize, 1,
- OS.XmNtraversalOn, 0,
- OS.XmNtroughColor, background,
- OS.XmNtopShadowColor, background,
- OS.XmNbottomShadowColor, background,
- OS.XmNforeground, background,
- OS.XmNshadowThickness, 1,
- OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0,
- OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL,
- OS.XmNprocessingDirection, ((style & SWT.H_SCROLL) != 0) ? OS.XmMAX_ON_RIGHT : OS.XmMAX_ON_TOP,
- OS.XmNancestorSensitive, 1,
- OS.XmNsliderVisual, OS.XmFOREGROUND_COLOR,
- };
- handle = OS.XmCreateScrollBar (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.INDETERMINATE) != 0) createTimer ();
-}
-void createWidget (int index) {
- super.createWidget (index);
- foreground = defaultForeground ();
-}
-void createTimer () {
- int xDisplay = display.xDisplay;
- int windowTimerProc = display.windowTimerProc;
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- timerId = OS.XtAppAddTimeOut (xtContext, DELAY, windowTimerProc, handle);
-}
-void destroyTimer () {
- if (timerId != 0) OS.XtRemoveTimeOut (timerId);
- timerId = 0;
-}
-int getForegroundPixel () {
- return foreground == -1 ? super.getForegroundPixel () : foreground;
-}
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget();
- int [] argList = {OS.XmNmaximum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget();
- int [] argList = {OS.XmNminimum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the single 'selection' that is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget();
- int [] argList = {
- OS.XmNminimum, 0,
- OS.XmNsliderSize, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int minimum = argList [1], sliderSize = argList [3];
- return minimum + (foreground != -1 ? 0 : sliderSize);
-}
-/**
- * Returns the state of the receiver. The value will be one of:
- * <ul>
- * <li>{@link SWT#NORMAL}</li>
- * <li>{@link SWT#ERROR}</li>
- * <li>{@link SWT#PAUSED}</li>
- * </ul>
- *
- * @return the state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public int getState () {
- checkWidget ();
- return SWT.NORMAL;
-}
-void releaseWidget () {
- super.releaseWidget ();
- destroyTimer ();
-}
-void setBackgroundPixel (int pixel) {
- checkWidget();
- super.setBackgroundPixel (pixel);
- if (foreground != -1) super.setForegroundPixel (pixel);
-}
-void setForegroundPixel (int pixel) {
- checkWidget();
- if (foreground == -1) {
- super.setForegroundPixel (pixel);
- } else {
- foreground = pixel;
- }
-}
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget();
- if (value < 0) return;
- int [] argList = {OS.XmNmaximum, value, OS.XmNvalue, 0};
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is negative or is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be nonnegative and less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget();
- if (value < 0) return;
- int [] argList = {
- OS.XmNminimum, 0,
- OS.XmNmaximum, 0,
- OS.XmNsliderSize, 0,
- OS.XmNvalue, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int minimum = argList [1];
- int maximum = argList [3];
- int sliderSize = argList [5];
-
- if (value >= maximum) return;
- int selection = sliderSize + minimum;
- if (value > selection) selection = value;
- argList [1] = value;
- argList [7] = value;
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
- setThumb(selection - value);
-}
-/**
- * Sets the single 'selection' that is the receiver's
- * position to the argument which must be greater than or equal
- * to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget();
- int [] argList = {
- OS.XmNminimum, 0,
- OS.XmNmaximum, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int minimum = argList [1];
- int maximum = argList [3];
-
- int selection = value;
- if (selection < minimum) selection = minimum;
- if (selection > maximum) selection = maximum;
- setThumb(selection - minimum);
- update ();
-}
-/**
- * Sets the state of the receiver. The state must be one of these values:
- * <ul>
- * <li>{@link SWT#NORMAL}</li>
- * <li>{@link SWT#ERROR}</li>
- * <li>{@link SWT#PAUSED}</li>
- * </ul>
- *
- * @param state the new state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setState (int state) {
- checkWidget ();
- //NOT IMPLEMENTED
-}
-void setThumb (int sliderSize) {
- int [] argList1 = new int [] {
- OS.XmNtroughColor, 0,
- OS.XmNminimum, 0,
- };
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int troughColor = argList1 [1];
- if (sliderSize == 0) {
- if (foreground == -1) {
- foreground = getForegroundPixel ();
- super.setForegroundPixel (troughColor);
- }
- } else {
- if (foreground != -1) {
- super.setForegroundPixel (foreground);
- foreground = -1;
- }
- }
- int [] argList2 = new int [] {
- OS.XmNsliderSize, sliderSize == 0 ? 1 : sliderSize,
- OS.XmNvalue, argList1 [3]
- };
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- display.setWarnings (warnings);
-}
-int timerProc (int id) {
- int minimum = getMinimum ();
- int range = getMaximum () - minimum + 1;
- int value = getSelection () - minimum + 1;
- setSelection (minimum + (value % range));
- createTimer ();
- return 0;
-}
-int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XButtonPress (w, client_data, call_data, continue_to_dispatch);
- int [] argList = {OS.XmNsensitive, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] != 0) {
- OS.memmove (continue_to_dispatch, new int [1], 4);
- return 1;
- }
- return result;
-}
-int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XButtonRelease (w, client_data, call_data, continue_to_dispatch);
- int [] argList = {OS.XmNsensitive, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] != 0) {
- OS.memmove (continue_to_dispatch, new int [1], 4);
- return 1;
- }
- return result;
-}
-int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XKeyPress (w, client_data, call_data, continue_to_dispatch);
- int [] argList = {OS.XmNsensitive, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] != 0) {
- OS.memmove (continue_to_dispatch, new int [1], 4);
- return 1;
- }
- return result;
-}
-int XKeyRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XKeyRelease (w, client_data, call_data, continue_to_dispatch);
- int [] argList = {OS.XmNsensitive, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] != 0) {
- OS.memmove (continue_to_dispatch, new int [1], 4);
- return 1;
- }
- return result;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java
deleted file mode 100755
index 711f9c34b5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java
+++ /dev/null
@@ -1,446 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of the receiver represent a selectable user interface object
- * that allows the user to drag a rubber banded outline of the sash within
- * the parent control.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL, SMOOTH</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#sash">Sash snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Sash extends Control {
- boolean dragging;
- int startX, startY, lastX, lastY;
- int cursor;
- private final static int INCREMENT = 1;
- private final static int PAGE_INCREMENT = 9;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#SMOOTH
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Sash (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the x, y, width, and height fields of the event object are valid.
- * If the receiver is being dragged, the event object detail field contains the value <code>SWT.DRAG</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += DEFAULT_WIDTH; height += 3;
- } else {
- width += 3; height += DEFAULT_HEIGHT;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-void createHandle (int index) {
- state |= THEME_BACKGROUND;
- int border = (style & SWT.BORDER) != 0 ? 1 : 0;
- int [] argList = {
- OS.XmNborderWidth, border,
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNancestorSensitive, 1,
- OS.XmNtraversalOn, 0,
- };
- int parentHandle = parent.handle;
- handle = OS.XmCreateDrawingArea (parentHandle, null, argList, argList.length / 2);
-}
-void drawBand (int x, int y, int width, int height) {
- if ((style & SWT.SMOOTH) != 0) return;
- int display = OS.XtDisplay (parent.handle);
- if (display == 0) return;
- int window = OS.XtWindow (parent.handle);
- if (window == 0) return;
- int foreground = parent.getForegroundPixel ();
- Control control = parent.findBackgroundControl ();
- if (control == null) control = parent;
- int background = control.getBackgroundPixel ();
- int color = foreground ^ background;
- byte [] bits = {-86, 85, -86, 85, -86, 85, -86, 85};
- int stipplePixmap = OS.XCreateBitmapFromData (display, window, bits, 8, 8);
- int gc = OS.XCreateGC (display, window, 0, null);
- OS.XSetForeground (display, gc, color);
- OS.XSetStipple (display, gc, stipplePixmap);
- OS.XSetSubwindowMode (display, gc, OS.IncludeInferiors);
- OS.XSetFillStyle (display, gc, OS.FillStippled);
- OS.XSetFunction (display, gc, OS.GXxor);
- OS.XFillRectangle (display, window, gc, x, y, width, height);
- OS.XFreePixmap (display, stipplePixmap);
- OS.XFreeGC (display, gc);
-}
-void propagateWidget (boolean enabled) {
- int xCursor = enabled && super.cursor != null ? super.cursor.handle : cursor;
- propagateHandle (enabled, handle, xCursor);
-}
-void realizeChildren () {
- super.realizeChildren ();
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- if ((style & SWT.HORIZONTAL) != 0) {
- cursor = OS.XCreateFontCursor (xDisplay, OS.XC_sb_v_double_arrow);
- } else {
- cursor = OS.XCreateFontCursor (xDisplay, OS.XC_sb_h_double_arrow);
- }
- if (super.cursor == null && isEnabled ()) {
- OS.XDefineCursor (xDisplay, xWindow, cursor);
- OS.XFlush (xDisplay);
- }
-}
-void releaseWidget () {
- super.releaseWidget ();
- if (cursor != 0) {
- int display = OS.XtDisplay (handle);
- if (display != 0) OS.XFreeCursor (display, cursor);
- }
- cursor = 0;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-public void setCursor (Cursor cursor) {
- checkWidget();
- super.setCursor (cursor);
- if (cursor == null && this.cursor != 0) {
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- OS.XDefineCursor (xDisplay, xWindow, this.cursor);
- OS.XFlush (xDisplay);
- }
-}
-public boolean setFocus () {
- checkWidget();
- return forceFocus ();
-}
-int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XButtonPress (w, client_data, call_data, continue_to_dispatch);
- if (result != 0) return result;
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- if (xEvent.button != 1) return result;
- short [] x_root = new short [1], y_root = new short [1];
- OS.XtTranslateCoords (handle, (short) 0, (short) 0, x_root, y_root);
- startX = xEvent.x_root - x_root [0];
- startY = xEvent.y_root - y_root [0];
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int border = argList [9], width = argList [5] + (border * 2), height = argList [7] + (border * 2);
- lastX = ((short) argList [1]) - border; lastY = ((short) argList [3]) - border;
- Event event = new Event ();
- event.time = xEvent.time;
- event.x = lastX;
- event.y = lastY;
- event.width = width;
- event.height = height;
- if ((style & SWT.SMOOTH) == 0) {
- event.detail = SWT.DRAG;
- }
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return result;
- if (event.doit) {
- dragging = true;
- lastX = event.x;
- lastY = event.y;
- parent.update (true);
- drawBand (event.x, event.y, width, height);
- if ((style & SWT.SMOOTH) != 0) {
- setBounds (event.x, event.y, width, height);
- // widget could be disposed at this point
- }
- }
- return result;
-}
-int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XButtonRelease (w, client_data, call_data, continue_to_dispatch);
- if (result != 0) return result;
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- if (xEvent.button != 1) return result;
- if (!dragging) return result;
- dragging = false;
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int border = argList [5];
- int width = argList [1] + (border * 2), height = argList [3] + (border * 2);
- Event event = new Event ();
- event.time = xEvent.time;
- event.x = lastX;
- event.y = lastY;
- event.width = width;
- event.height = height;
- drawBand (lastX, lastY, width, height);
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return result;
- if (event.doit) {
- if ((style & SWT.SMOOTH) != 0) {
- setBounds (event.x, event.y, width, height);
- // widget could be disposed at this point
- }
- }
- return result;
-}
-int xFocusIn (XFocusChangeEvent xEvent) {
- int result = super.xFocusIn (xEvent);
- if (handle == 0) return result;
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- lastX = argList [1];
- lastY = argList [3];
- return result;
-}
-int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XKeyPress (w, client_data, call_data, continue_to_dispatch);
- if (result != 0) return result;
- XKeyEvent xEvent = new XKeyEvent ();
- OS.memmove (xEvent, call_data, XKeyEvent.sizeof);
- byte [] buffer = new byte [1];
- int [] keysym = new int [1];
- OS.XLookupString (xEvent, buffer, buffer.length, keysym, null);
-
- switch (keysym [0]) {
- case OS.XK_Left:
- case OS.XK_Right:
- case OS.XK_Up:
- case OS.XK_Down:
- int xChange = 0, yChange = 0;
- int stepSize = PAGE_INCREMENT;
- if ((xEvent.state & OS.ControlMask) != 0) stepSize = INCREMENT;
- if ((style & SWT.VERTICAL) != 0) {
- if (keysym [0] == OS.XK_Up || keysym [0] == OS.XK_Down) break;
- xChange = keysym [0] == OS.XK_Left ? -stepSize : stepSize;
- } else {
- if (keysym [0] == OS.XK_Left || keysym [0] == OS.XK_Right) break;
- yChange = keysym [0] == OS.XK_Up ? -stepSize : stepSize;
- }
-
- int [] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int border = argList1 [5];
- int width = argList1 [1] + (border * 2), height = argList1 [3] + (border * 2);
- int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (parent.handle, argList2, argList2.length / 2);
- int parentBorder = argList2 [5];
- int parentWidth = argList2 [1] + (parentBorder * 2);
- int parentHeight = argList2 [3] + (parentBorder * 2);
- int newX = lastX, newY = lastY;
- if ((style & SWT.VERTICAL) != 0) {
- newX = Math.min (Math.max (0, lastX + xChange - parentBorder - startX), parentWidth - width);
- } else {
- newY = Math.min (Math.max (0, lastY + yChange - parentBorder - startY), parentHeight - height);
- }
- if (newX == lastX && newY == lastY) return result;
-
- /* Ensure that the pointer image does not change */
- int xDisplay = display.xDisplay;
- int xWindow = OS.XtWindow (parent.handle);
- int ptrGrabResult = OS.XGrabPointer (
- xDisplay,
- xWindow,
- 1,
- OS.None,
- OS.GrabModeAsync,
- OS.GrabModeAsync,
- OS.None,
- cursor,
- OS.CurrentTime);
-
- Event event = new Event ();
- event.time = xEvent.time;
- event.x = newX;
- event.y = newY;
- event.width = width;
- event.height = height;
- sendEvent (SWT.Selection, event);
- if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime);
- if (isDisposed ()) break;
-
- if (event.doit) {
- lastX = event.x;
- lastY = event.y;
- if ((style & SWT.SMOOTH) != 0) {
- setBounds (event.x, event.y, width, height);
- if (isDisposed ()) break;
- }
- int cursorX = event.x, cursorY = event.y;
- if ((style & SWT.VERTICAL) != 0) {
- cursorY += height / 2;
- } else {
- cursorX += width / 2;
- }
- OS.XWarpPointer (xDisplay, OS.None, xWindow, 0, 0, 0, 0, cursorX, cursorY);
- }
- break;
- }
-
- return result;
-}
-int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XPointerMotion (w, client_data, call_data, continue_to_dispatch);
- if (result != 0) return result;
- XMotionEvent xEvent = new XMotionEvent ();
- OS.memmove (xEvent, call_data, XMotionEvent.sizeof);
- if (!dragging || (xEvent.state & OS.Button1Mask) == 0) return result;
- short [] x_root = new short [1], y_root = new short [1];
- OS.XtTranslateCoords (handle, (short) 0, (short) 0, x_root, y_root);
- int eventX = xEvent.x_root - x_root [0], eventY = xEvent.y_root - y_root [0];
- int [] argList1 = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int border = argList1 [9], x = ((short) argList1 [1]) - border, y = ((short) argList1 [3]) - border;
- int width = argList1 [5] + (border * 2), height = argList1 [7] + (border * 2);
- int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (parent.handle, argList2, argList2.length / 2);
- int parentBorder = argList2 [5];
- int parentWidth = argList2 [1] + (parentBorder * 2);
- int parentHeight = argList2 [3] + (parentBorder * 2);
- int newX = lastX, newY = lastY;
- if ((style & SWT.VERTICAL) != 0) {
- newX = Math.min (Math.max (0, eventX + x - startX - parentBorder), parentWidth - width);
- } else {
- newY = Math.min (Math.max (0, eventY + y - startY - parentBorder), parentHeight - height);
- }
- if (newX == lastX && newY == lastY) return result;
- drawBand (lastX, lastY, width, height);
- Event event = new Event ();
- event.time = xEvent.time;
- event.x = newX;
- event.y = newY;
- event.width = width;
- event.height = height;
- if ((style & SWT.SMOOTH) == 0) {
- event.detail = SWT.DRAG;
- }
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return result;
- if (event.doit) {
- lastX = event.x;
- lastY = event.y;
- }
- parent.update (true);
- drawBand (lastX, lastY, width, height);
- if ((style & SWT.SMOOTH) != 0) {
- setBounds (lastX, lastY, width, height);
- // widget could be disposed at this point
- }
- return result;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java
deleted file mode 100755
index bd9f4ef40d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java
+++ /dev/null
@@ -1,385 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of the receiver represent a selectable user
- * interface object that present a range of continuous
- * numeric values.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#scale">Scale snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Scale extends Control {
- int scrollHandle;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Scale (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the receiver's value.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- int hScroll = display.scrolledMarginX;
- int vScroll = display.scrolledMarginY;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += hScroll * 10;
- height += vScroll;
- } else {
- width += hScroll;
- height += vScroll * 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-void createHandle (int index) {
- state |= THEME_BACKGROUND;
- int [] argList = {
- OS.XmNtitleString, 0,
- OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0,
- OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL,
- OS.XmNprocessingDirection, ((style & SWT.H_SCROLL) != 0) ? OS.XmMAX_ON_RIGHT : OS.XmMAX_ON_BOTTOM,
- OS.XmNancestorSensitive, 1,
- };
- int parentHandle = parent.handle;
- handle = OS.XmCreateScale (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- byte[] scrollbar = Converter.wcsToMbcs (null, "Scrollbar\0");
- scrollHandle = OS.XtNameToWidget (handle, scrollbar);
-}
-void deregister () {
- super.deregister ();
- if (scrollHandle != 0) display.removeWidget (scrollHandle);
-}
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget();
- return 1;
-}
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget();
- int [] argList = {OS.XmNmaximum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget();
- int [] argList = {OS.XmNminimum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget();
- int [] argList = {OS.XmNscaleMultiple, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the 'selection', which is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget();
- int [] argList = {OS.XmNvalue, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, DRAG_CALLBACK);
- if (scrollHandle != 0) {
- OS.XtAddEventHandler (scrollHandle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS);
- OS.XtAddEventHandler (scrollHandle, OS.ButtonReleaseMask, false, windowProc, BUTTON_RELEASE);
- OS.XtAddEventHandler (scrollHandle, OS.EnterWindowMask, false, windowProc, ENTER_WINDOW);
- OS.XtAddEventHandler (scrollHandle, OS.LeaveWindowMask, false, windowProc, LEAVE_WINDOW);
- OS.XtAddEventHandler (scrollHandle, OS.KeyPressMask, false, windowProc, KEY_PRESS);
- OS.XtAddEventHandler (scrollHandle, OS.KeyReleaseMask, false, windowProc, KEY_RELEASE);
- OS.XtInsertEventHandler (scrollHandle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail);
- }
-}
-void overrideTranslations () {
- OS.XtOverrideTranslations (handle, display.tabTranslations);
-}
-void register () {
- super.register ();
- if (scrollHandle != 0) display.addWidget (scrollHandle, this);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param increment the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int increment) {
- checkWidget();
-}
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget();
- if (value < 0) return;
- int [] argList = {OS.XmNmaximum, value};
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is negative or is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be nonnegative and less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget();
- if (value < 0) return;
- int [] argList = {OS.XmNminimum, value};
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param pageIncrement the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int pageIncrement) {
- checkWidget();
- if (pageIncrement < 1) return;
- int [] argList = {OS.XmNscaleMultiple, pageIncrement};
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the 'selection', which is the receiver's value,
- * to the argument which must be greater than or equal to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int selection) {
- checkWidget();
- int [] argList = {OS.XmNvalue, selection};
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-int XmNdragCallback (int w, int client_data, int call_data) {
- postEvent (SWT.Selection);
- return 0;
-}
-int XmNvalueChangedCallback (int w, int client_data, int call_data) {
- postEvent (SWT.Selection);
- return 0;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java
deleted file mode 100755
index f7756ac77a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java
+++ /dev/null
@@ -1,728 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that represent a range of positive, numeric values.
- * <p>
- * At any given moment, a given scroll bar will have a
- * single 'selection' that is considered to be its
- * value, which is constrained to be within the range of
- * values the scroll bar represents (that is, between its
- * <em>minimum</em> and <em>maximum</em> values).
- * </p><p>
- * Typically, scroll bars will be made up of five areas:
- * <ol>
- * <li>an arrow button for decrementing the value</li>
- * <li>a page decrement area for decrementing the value by a larger amount</li>
- * <li>a <em>thumb</em> for modifying the value by mouse dragging</li>
- * <li>a page increment area for incrementing the value by a larger amount</li>
- * <li>an arrow button for incrementing the value</li>
- * </ol>
- * Based on their style, scroll bars are either <code>HORIZONTAL</code>
- * (which have a left facing button for decrementing the value and a
- * right facing button for incrementing it) or <code>VERTICAL</code>
- * (which have an upward facing button for decrementing the value
- * and a downward facing buttons for incrementing it).
- * </p><p>
- * On some platforms, the size of the scroll bar's thumb can be
- * varied relative to the magnitude of the range of values it
- * represents (that is, relative to the difference between its
- * maximum and minimum values). Typically, this is used to
- * indicate some proportional value such as the ratio of the
- * visible area of a document to the total amount of space that
- * it would take to display it. SWT supports setting the thumb
- * size even if the underlying platform does not, but in this
- * case the appearance of the scroll bar will not change.
- * </p><p>
- * Scroll bars are created by specifying either <code>H_SCROLL</code>,
- * <code>V_SCROLL</code> or both when creating a <code>Scrollable</code>.
- * They are accessed from the <code>Scrollable</code> using
- * <code>getHorizontalBar</code> and <code>getVerticalBar</code>.
- * </p><p>
- * Note: Scroll bars are not Controls. On some platforms, scroll bars
- * that appear as part of some standard controls such as a text or list
- * have no operating system resources and are not children of the control.
- * For this reason, scroll bars are treated specially. To create a control
- * that looks like a scroll bar but has operating system resources, use
- * <code>Slider</code>.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see Slider
- * @see Scrollable
- * @see Scrollable#getHorizontalBar
- * @see Scrollable#getVerticalBar
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ScrollBar extends Widget {
- Scrollable parent;
- boolean dragSent = false;
-ScrollBar () {
- /* Do Nothing */
-}
-ScrollBar (Scrollable parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (0);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values:
- * <code>SWT.NONE</code> - for the end of a drag.
- * <code>SWT.DRAG</code>.
- * <code>SWT.HOME</code>.
- * <code>SWT.END</code>.
- * <code>SWT.ARROW_DOWN</code>.
- * <code>SWT.ARROW_UP</code>.
- * <code>SWT.PAGE_DOWN</code>.
- * <code>SWT.PAGE_UP</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-void createHandle (int index) {
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0,
- OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL,
- OS.XmNtraversalOn, 0,
- };
- int parentHandle = parent.scrolledHandle;
- handle = OS.XmCreateScrollBar (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-void destroyHandle () {
- super.destroyWidget ();
-}
-void destroyWidget () {
- parent.destroyScrollBar (this);
- releaseHandle ();
- //parent.sendEvent (SWT.Resize);
-}
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- int [] argList = {OS.XmNsensitive, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] != 0;
-}
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget();
- int [] argList = {OS.XmNincrement, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget();
- int [] argList = {OS.XmNmaximum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget();
- int [] argList = {OS.XmNminimum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget();
- int [] argList = {OS.XmNpageIncrement, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the receiver's parent, which must be a Scrollable.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Scrollable getParent () {
- checkWidget();
- return parent;
-}
-/**
- * Returns the single 'selection' that is the receiver's value.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget();
- int [] argList = {OS.XmNvalue, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int borders = argList [5] * 2;
- return new Point (argList [1] + borders, argList [3] + borders);
-}
-/**
- * Returns the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values.
- *
- * @return the thumb value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ScrollBar
- */
-public int getThumb () {
- checkWidget();
- int [] argList = {OS.XmNsliderSize, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- return OS.XtIsManaged (handle);
-}
-void hookEvents () {
- int windowProc = display.windowProc;
- OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, DRAG_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNtoBottomCallback, windowProc, TO_BOTTOM_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNtoTopCallback, windowProc, TO_TOP_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNincrementCallback, windowProc, INCREMENT_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNdecrementCallback, windowProc, DECREMENT_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNpageIncrementCallback, windowProc, PAGE_INCREMENT_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNpageDecrementCallback, windowProc, PAGE_DECREMENT_CALLBACK);
- OS.XtAddEventHandler (handle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS);
-}
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return getVisible () && parent.isVisible ();
-}
-void manageChildren () {
- /*
- * Feature in Motif. Hiding or showing a scroll bar
- * can cause the widget to automatically resize in
- * the OS. This behavior is unwanted. The fix is
- * to force the widget to resize to original size.
- */
- int scrolledHandle = parent.scrolledHandle;
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- if (scrolledHandle != 0) {
- OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
- }
- OS.XtManageChild (handle);
- /*
- * Feature in Motif. When XtSetValues() is used to restore the width and
- * height of the widget, the new width and height are sometimes ignored.
- * The fix is to use XtResizeWidget().
- */
- if (scrolledHandle != 0) {
- OS.XtResizeWidget (scrolledHandle, argList [1], argList [3], argList [5]);
- }
-}
-void propagateWidget (boolean enabled) {
- propagateHandle (enabled, handle, OS.None);
-}
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
-}
-void releaseParent () {
- super.releaseParent ();
- if (parent.horizontalBar == this) parent.horizontalBar = null;
- if (parent.verticalBar == this) parent.verticalBar = null;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-void sendScrollEvent (int detail) {
- Event event = new Event ();
- event.detail = detail;
- sendEvent (SWT.Selection, event);
- /*
- * Feature in Motif. When a scroll bar is selected,
- * it does not make the shell active. The fix is to
- * make the shell active.
- */
- Shell shell = parent.getShell ();
- shell.bringToTop (true);
-}
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- int [] argList = {OS.XmNincrement, value};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * Sets the maximum. If this value is negative or less than or
- * equal to the minimum, the value is ignored. If necessary, first
- * the thumb and then the selection are adjusted to fit within the
- * new range.
- *
- * @param value the new maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget();
- if (value < 0) return;
- int [] argList = {OS.XmNmaximum, value};
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the minimum value. If this value is negative or greater
- * than or equal to the maximum, the value is ignored. If necessary,
- * first the thumb and then the selection are adjusted to fit within
- * the new range.
- *
- * @param value the new minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget();
- if (value < 0) return;
- int [] argList = {
- OS.XmNminimum, 0,
- OS.XmNmaximum, 0,
- OS.XmNsliderSize, 0,
- };
- /*
- * Feature in Motif. For some reason, when minimium
- * is set to be greater than or equal to maximum, Motif
- * does not set the minimum. Instead, the value is
- * changed and the minimum stays the same. This behavior
- * differs from setting the maximum where the slider size
- * is always decreased to make room for the new maximum.
- * The fix is to decrease the slider to make room for
- * the new minimum.
- */
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [3] - value - argList [5] < 0) {
- argList [5] = argList [3] - value;
- }
- argList [1] = value;
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- int [] argList = {OS.XmNpageIncrement, value};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * Sets the single <em>selection</em> that is the receiver's
- * value to the argument which must be greater than or equal
- * to zero.
- *
- * @param selection the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int selection) {
- checkWidget();
- int [] argList = {OS.XmNvalue, selection};
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values. This new
- * value will be ignored if it is less than one, and will be
- * clamped if it exceeds the receiver's current range.
- *
- * @param value the new thumb value, which must be at least one and not
- * larger than the size of the current range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setThumb (int value) {
- checkWidget();
- if (value < 1) return;
- int [] argList = {OS.XmNminimum, 0, OS.XmNmaximum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- value = Math.min (value, argList [3] - argList [1]);
- int [] argList2 = {OS.XmNsliderSize, value};
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, thumb, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param thumb the new thumb value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- checkWidget();
- if (minimum < 0) return;
- if (maximum < 0) return;
- if (thumb < 1) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- thumb = Math.min (thumb, maximum - minimum);
- int [] argList = {
- OS.XmNvalue, selection,
- OS.XmNminimum, minimum,
- OS.XmNmaximum, maximum,
- OS.XmNsliderSize, thumb,
- OS.XmNincrement, increment,
- OS.XmNpageIncrement, pageIncrement,
- };
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget();
- if (parent.setScrollBarVisible (this, visible)) {
- sendEvent (visible ? SWT.Show : SWT.Hide);
- parent.sendEvent (SWT.Resize);
- }
-}
-int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XButtonPress (w, client_data, call_data, continue_to_dispatch);
- if (result != 0) return result;
- dragSent = false;
- return result;
-}
-int XmNdecrementCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.ARROW_UP);
- return 0;
-}
-int XmNdragCallback (int w, int client_data, int call_data) {
- dragSent = true;
- sendScrollEvent (SWT.DRAG);
- return 0;
-}
-int XmNincrementCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.ARROW_DOWN);
- return 0;
-}
-int XmNpageDecrementCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.PAGE_UP);
- return 0;
-}
-int XmNpageIncrementCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.PAGE_DOWN);
- return 0;
-}
-int XmNtoBottomCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.END);
- return 0;
-}
-int XmNtoTopCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.HOME);
- return 0;
-}
-int XmNvalueChangedCallback (int w, int client_data, int call_data) {
- if (!dragSent){
- sendScrollEvent (SWT.DRAG);
- dragSent = false;
- }
- sendScrollEvent (SWT.NONE);
- return 0;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java
deleted file mode 100755
index bd8cc53cbc..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java
+++ /dev/null
@@ -1,363 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * This class is the abstract superclass of all classes which
- * represent controls that have standard scroll bars.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>H_SCROLL, V_SCROLL</dd>
- * <dt><b>Events:</b>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public abstract class Scrollable extends Control {
- int scrolledHandle, formHandle;
- ScrollBar horizontalBar, verticalBar;
-Scrollable () {
- /* Do nothing */
-}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#H_SCROLL
- * @see SWT#V_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Scrollable (Composite parent, int style) {
- super (parent, style);
-}
-/**
- * Given a desired <em>client area</em> for the receiver
- * (as described by the arguments), returns the bounding
- * rectangle which would be required to produce that client
- * area.
- * <p>
- * In other words, it returns a rectangle such that, if the
- * receiver's bounds were set to that rectangle, the area
- * of the receiver which is capable of displaying data
- * (that is, not covered by the "trimmings") would be the
- * rectangle described by the arguments (relative to the
- * receiver's parent).
- * </p>
- *
- * @param x the desired x coordinate of the client area
- * @param y the desired y coordinate of the client area
- * @param width the desired width of the client area
- * @param height the desired height of the client area
- * @return the required bounds to produce the given client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getClientArea
- */
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- int border = getBorderWidth ();
- int trimX = x - border, trimY = y - border;
- int trimWidth = width + (border * 2), trimHeight = height + (border * 2);
- if (horizontalBar != null) {
- trimY -= display.scrolledInsetY;
- trimHeight += display.scrolledInsetY + display.scrolledMarginY;
- if (verticalBar == null) {
- trimX -= display.scrolledInsetX;
- trimWidth += display.scrolledInsetX * 2;
- trimHeight -= display.scrolledInsetY * 2;
- }
- }
- if (verticalBar != null) {
- trimX -= display.scrolledInsetX;
- trimWidth += display.scrolledInsetX + display.scrolledMarginX;
- if (horizontalBar == null) {
- trimY -= display.scrolledInsetY;
- trimHeight += display.scrolledInsetY * 2;
- trimWidth -= display.scrolledInsetX * 2;
- }
- }
- return new Rectangle (trimX, trimY, trimWidth, trimHeight);
-}
-ScrollBar createScrollBar (int type) {
- return new ScrollBar (this, type);
-}
-ScrollBar createStandardBar (int style) {
- if (scrolledHandle == 0) return null;
- ScrollBar bar = new ScrollBar ();
- bar.parent = this;
- bar.style = style;
- bar.display = display;
- int [] argList = {OS.XmNhorizontalScrollBar, 0, OS.XmNverticalScrollBar, 0};
- OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
- if (style == SWT.H_SCROLL) bar.handle = argList [1];
- if (style == SWT.V_SCROLL) bar.handle = argList [3];
- bar.hookEvents ();
- bar.register ();
- return bar;
-}
-void createWidget (int index) {
- super.createWidget (index);
- if ((style & SWT.H_SCROLL) != 0) horizontalBar = createScrollBar (SWT.H_SCROLL);
- if ((style & SWT.V_SCROLL) != 0) verticalBar = createScrollBar (SWT.V_SCROLL);
-}
-void destroyScrollBar (ScrollBar bar) {
- setScrollBarVisible (bar, false);
- if ((state & CANVAS) != 0) bar.destroyHandle ();
-}
-void deregister () {
- super.deregister ();
- if (formHandle != 0) display.removeWidget (formHandle);
- if (scrolledHandle != 0) display.removeWidget (scrolledHandle);
-}
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- if (formHandle != 0) enableHandle (enabled, formHandle);
- if (scrolledHandle != 0) enableHandle (enabled, scrolledHandle);
-}
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data (that is,
- * not covered by the "trimmings").
- *
- * @return the client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeTrim
- */
-public Rectangle getClientArea () {
- checkWidget();
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return new Rectangle (0, 0, argList [1], argList [3]);
-}
-/**
- * Returns the receiver's horizontal scroll bar if it has
- * one, and null if it does not.
- *
- * @return the horizontal scroll bar (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ScrollBar getHorizontalBar () {
- checkWidget();
- return horizontalBar;
-}
-/**
- * Returns the receiver's vertical scroll bar if it has
- * one, and null if it does not.
- *
- * @return the vertical scroll bar (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ScrollBar getVerticalBar () {
- checkWidget();
- return verticalBar;
-}
-void manageChildren () {
- if (scrolledHandle != 0) {
- OS.XtSetMappedWhenManaged (scrolledHandle, false);
- OS.XtManageChild (scrolledHandle);
- }
- if (formHandle != 0) {
- OS.XtSetMappedWhenManaged (formHandle, false);
- OS.XtManageChild (formHandle);
- }
- super.manageChildren ();
- if (formHandle != 0) {
- int [] argList = {OS.XmNborderWidth, 0};
- OS.XtGetValues (formHandle, argList, argList.length / 2);
- OS.XtResizeWidget (formHandle, 1, 1, argList [1]);
- OS.XtSetMappedWhenManaged (formHandle, true);
- }
- if (scrolledHandle != 0) {
- int [] argList = {OS.XmNborderWidth, 0};
- OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
- OS.XtResizeWidget (scrolledHandle, 1, 1, argList [1]);
- OS.XtSetMappedWhenManaged (scrolledHandle, true);
- }
-}
-void propagateWidget (boolean enabled) {
- super.propagateWidget (enabled);
- if (formHandle != 0) propagateHandle (enabled, formHandle, OS.None);
- if (scrolledHandle != 0) {
- propagateHandle (enabled, scrolledHandle, OS.None);
- if (horizontalBar != null) horizontalBar.propagateWidget (enabled);
- if (verticalBar != null) verticalBar.propagateWidget (enabled);
- }
-}
-void register () {
- super.register ();
- if (formHandle != 0) display.addWidget (formHandle, this);
- if (scrolledHandle != 0) display.addWidget (scrolledHandle, this);
-}
-void releaseChildren (boolean destroy) {
- if (horizontalBar != null) {
- horizontalBar.release (false);
- horizontalBar = null;
- }
- if (verticalBar != null) {
- verticalBar.release (false);
- verticalBar = null;
- }
- super.releaseChildren (destroy);
-}
-void releaseHandle () {
- super.releaseHandle ();
- scrolledHandle = formHandle = 0;
-}
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- /*
- * Uncomment this code to force scrollbars to change color.
- */
-// if (scrolledHandle != 0) {
-// int [] argList1 = {
-// OS.XmNhorizontalScrollBar, 0,
-// OS.XmNverticalScrollBar, 0,
-// };
-// OS.XtGetValues (scrolledHandle, argList1, argList1.length / 2);
-// if (argList1 [1] != 0) OS.XmChangeColor (argList1 [1], pixel);
-// if (argList1 [3] != 0) OS.XmChangeColor (argList1 [3], pixel);
-// }
-}
-void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean allChildren, boolean trim) {
- super.redrawWidget (x, y, width, height, redrawAll, allChildren, trim);
- if (!trim) return;
- if (formHandle == 0 && scrolledHandle == 0) return;
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (handle, (short) x, (short) y, root_x, root_y);
- if (formHandle != 0) {
- short [] form_x = new short [1], form_y = new short [1];
- OS.XtTranslateCoords (formHandle, (short) 0, (short) 0, form_x, form_y);
- redrawHandle (root_x [0] - form_x [0], root_y [0] - form_y [0], width, height, redrawAll, formHandle);
- }
- if (scrolledHandle != 0) {
- short [] scrolled_x = new short [1], scrolled_y = new short [1];
- OS.XtTranslateCoords (scrolledHandle, (short) 0, (short) 0, scrolled_x, scrolled_y);
- redrawHandle (root_x [0] - scrolled_x [0], root_y [0] - scrolled_y [0], width, height, redrawAll, scrolledHandle);
- if (horizontalBar != null && horizontalBar.getVisible ()) {
- int horizontalHandle = horizontalBar.handle;
- short [] hscroll_x = new short [1], hscroll_y = new short [1];
- OS.XtTranslateCoords (horizontalHandle, (short) 0, (short) 0, hscroll_x, hscroll_y);
- redrawHandle (root_x [0] - hscroll_x [0], root_y [0] - hscroll_y [0], width, height, redrawAll, horizontalHandle);
- }
- if (verticalBar != null && verticalBar.getVisible ()) {
- int verticalHandle = verticalBar.handle;
- short [] vscroll_x = new short [1], vscroll_y = new short [1];
- OS.XtTranslateCoords (verticalHandle, (short) 0, (short) 0, vscroll_x, vscroll_y);
- redrawHandle (root_x [0] - vscroll_x [0], root_y [0] - vscroll_y [0], width, height, redrawAll, verticalHandle);
- }
- }
-}
-boolean setScrollBarVisible (ScrollBar bar, boolean visible) {
- if (scrolledHandle == 0) return false;
- int barHandle = bar.handle;
- boolean managed = OS.XtIsManaged (barHandle);
- if (managed == visible) return false;
-
- /*
- * Feature in Motif. Hiding or showing a scroll bar
- * can cause the widget to automatically resize in
- * the OS. This behavior is unwanted. The fix is
- * to force the widget to resize to original size.
- */
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
-
- int [] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
-
- /* Hide or show the scroll bar */
- if (visible) {
- OS.XtManageChild (barHandle);
- } else {
- OS.XtUnmanageChild (barHandle);
- }
- if ((state & CANVAS) != 0) {
- if (formHandle != 0) {
- boolean showBorder = (style & SWT.BORDER) != 0;
- int margin = showBorder || visible ? 3 : 0;
- if ((bar.style & SWT.V_SCROLL) != 0) {
- int [] argList2 = new int [] {OS.XmNmarginWidth, margin};
- OS.XtSetValues (formHandle, argList2, argList2.length/2);
- }
- if ((bar.style & SWT.H_SCROLL) != 0) {
- int [] argList2 = new int [] {OS.XmNmarginHeight, margin};
- OS.XtSetValues (formHandle, argList2, argList2.length/2);
- }
- }
- }
-
- /*
- * Feature in Motif. When XtSetValues() is used to restore the width and
- * height of the widget, the new width and height are sometimes ignored.
- * The fix is to use XtResizeWidget().
- */
- OS.XtResizeWidget (scrolledHandle, argList [1], argList [3], argList [5]);
-
- bar.sendEvent (visible ? SWT.Show : SWT.Hide);
- int [] argList3 = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList3, argList3.length / 2);
- return argList1 [1] != argList3 [1] || argList1 [3] != argList3 [3];
-}
-int topHandle () {
- if (scrolledHandle != 0) return scrolledHandle;
- if (formHandle != 0) return formHandle;
- return handle;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java
deleted file mode 100755
index 942cee0886..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java
+++ /dev/null
@@ -1,2093 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent the "windows"
- * which the desktop or "window manager" is managing.
- * Instances that do not have a parent (that is, they
- * are built using the constructor, which takes a
- * <code>Display</code> as the argument) are described
- * as <em>top level</em> shells. Instances that do have
- * a parent are described as <em>secondary</em> or
- * <em>dialog</em> shells.
- * <p>
- * Instances are always displayed in one of the maximized,
- * minimized or normal states:
- * <ul>
- * <li>
- * When an instance is marked as <em>maximized</em>, the
- * window manager will typically resize it to fill the
- * entire visible area of the display, and the instance
- * is usually put in a state where it can not be resized
- * (even if it has style <code>RESIZE</code>) until it is
- * no longer maximized.
- * </li><li>
- * When an instance is in the <em>normal</em> state (neither
- * maximized or minimized), its appearance is controlled by
- * the style constants which were specified when it was created
- * and the restrictions of the window manager (see below).
- * </li><li>
- * When an instance has been marked as <em>minimized</em>,
- * its contents (client area) will usually not be visible,
- * and depending on the window manager, it may be
- * "iconified" (that is, replaced on the desktop by a small
- * simplified representation of itself), relocated to a
- * distinguished area of the screen, or hidden. Combinations
- * of these changes are also possible.
- * </li>
- * </ul>
- * </p><p>
- * The <em>modality</em> of an instance may be specified using
- * style bits. The modality style bits are used to determine
- * whether input is blocked for other shells on the display.
- * The <code>PRIMARY_MODAL</code> style allows an instance to block
- * input to its parent. The <code>APPLICATION_MODAL</code> style
- * allows an instance to block input to every other shell in the
- * display. The <code>SYSTEM_MODAL</code> style allows an instance
- * to block input to all shells, including shells belonging to
- * different applications.
- * </p><p>
- * Note: The styles supported by this class are treated
- * as <em>HINT</em>s, since the window manager for the
- * desktop on which the instance is visible has ultimate
- * control over the appearance and behavior of decorations
- * and modality. For example, some window managers only
- * support resizable windows and will always assume the
- * RESIZE style, even if it is not set. In addition, if a
- * modality style is not supported, it is "upgraded" to a
- * more restrictive modality style that is supported. For
- * example, if <code>PRIMARY_MODAL</code> is not supported,
- * it would be upgraded to <code>APPLICATION_MODAL</code>.
- * A modality style may also be "downgraded" to a less
- * restrictive style. For example, most operating systems
- * no longer support <code>SYSTEM_MODAL</code> because
- * it can freeze up the desktop, so this is typically
- * downgraded to <code>APPLICATION_MODAL</code>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL, SHEET</dd>
- * <dd>APPLICATION_MODAL, MODELESS, PRIMARY_MODAL, SYSTEM_MODAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Activate, Close, Deactivate, Deiconify, Iconify</dd>
- * </dl>
- * Class <code>SWT</code> provides two "convenience constants"
- * for the most commonly required style combinations:
- * <dl>
- * <dt><code>SHELL_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application top level shell: (that
- * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>)
- * </dd>
- * <dt><code>DIALOG_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application dialog shell: (that
- * is, <code>TITLE | CLOSE | BORDER</code>)
- * </dd>
- * </dl>
- * </p>
- * <p>
- * Note: Only one of the styles APPLICATION_MODAL, MODELESS,
- * PRIMARY_MODAL and SYSTEM_MODAL may be specified.
- * </p><p>
- * IMPORTANT: This class is not intended to be subclassed.
- * </p>
- *
- * @see Decorations
- * @see SWT
- * @see <a href="http://www.eclipse.org/swt/snippets/#shell">Shell snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class Shell extends Decorations {
- int shellHandle, focusProxy;
- boolean reparented, realized, moved, resized, opened, modified, center;
- int oldX, oldY, oldWidth, oldHeight;
- Control lastActive;
-
- static final int MAXIMUM_TRIM = 128;
- static final byte [] WM_DELETE_WINDOW = Converter.wcsToMbcs(null, "WM_DELETE_WINDOW\0");
- static final byte [] _NET_WM_STATE = Converter.wcsToMbcs(null, "_NET_WM_STATE\0");
- static final byte [] _NET_WM_STATE_MAXIMIZED_VERT = Converter.wcsToMbcs(null, "_NET_WM_STATE_MAXIMIZED_VERT\0");
- static final byte [] _NET_WM_STATE_MAXIMIZED_HORZ = Converter.wcsToMbcs(null, "_NET_WM_STATE_MAXIMIZED_HORZ\0");
- static final byte [] _NET_WM_STATE_FULLSCREEN = Converter.wcsToMbcs(null, "_NET_WM_STATE_FULLSCREEN\0");
-/**
- * Constructs a new instance of this class. This is equivalent
- * to calling <code>Shell((Display) null)</code>.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell () {
- this ((Display) null);
-}
-/**
- * Constructs a new instance of this class given only the style
- * value describing its behavior and appearance. This is equivalent
- * to calling <code>Shell((Display) null, style)</code>.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#TOOL
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (int style) {
- this ((Display) null, style);
-}
-/**
- * Constructs a new instance of this class given only the display
- * to create it on. It is created with style <code>SWT.SHELL_TRIM</code>.
- * <p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the shell on
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell (Display display) {
- this (display, SWT.SHELL_TRIM);
-}
-/**
- * Constructs a new instance of this class given the display
- * to create it on and a style value describing its behavior
- * and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the shell on
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#TOOL
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (Display display, int style) {
- this (display, null, style, 0, false);
-}
-Shell (Display display, Shell parent, int style, int handle, boolean embedded) {
- super ();
- checkSubclass ();
- if (display == null) display = Display.getCurrent ();
- if (display == null) display = Display.getDefault ();
- if (!display.isValidThread ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- if (parent != null && parent.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.center = parent != null && (style & SWT.SHEET) != 0;
- this.style = checkStyle (parent, style);
- this.parent = parent;
- this.display = display;
- if (handle != 0) {
- if (embedded) {
- this.handle = handle;
- } else {
- this.shellHandle = handle;
- state |= FOREIGN_HANDLE;
- }
- }
- createWidget (0);
-}
-/**
- * Constructs a new instance of this class given only its
- * parent. It is created with style <code>SWT.DIALOG_TRIM</code>.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the parent is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell (Shell parent) {
- this (parent, SWT.DIALOG_TRIM);
-}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the parent is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#TOOL
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (Shell parent, int style) {
- this (parent != null ? parent.display : null, parent, style, 0, false);
-}
-
-static int checkStyle (Shell parent, int style) {
- style = Decorations.checkStyle (style);
- style &= ~SWT.TRANSPARENT;
- if ((style & SWT.ON_TOP) != 0) style &= ~SWT.SHELL_TRIM;
- int mask = SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.PRIMARY_MODAL;
- if ((style & SWT.SHEET) != 0) {
- style &= ~SWT.SHEET;
- style |= parent == null ? SWT.SHELL_TRIM : SWT.DIALOG_TRIM;
- if ((style & mask) == 0) {
- style |= parent == null ? SWT.APPLICATION_MODAL : SWT.PRIMARY_MODAL;
- }
- }
- int bits = style & ~mask;
- if ((style & SWT.SYSTEM_MODAL) != 0) return bits | SWT.SYSTEM_MODAL;
- if ((style & SWT.APPLICATION_MODAL) != 0) return bits | SWT.APPLICATION_MODAL;
- if ((style & SWT.PRIMARY_MODAL) != 0) return bits | SWT.PRIMARY_MODAL;
- return bits;
-}
-
-public static Shell motif_new (Display display, int handle) {
- return new Shell (display, null, SWT.NO_TRIM, handle, true);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new shell
- * that is not embedded.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Shell</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param display the display for the shell
- * @param handle the handle for the shell
- * @return a new shell object containing the specified display and handle
- *
- * @since 3.3
- */
-public static Shell internal_new (Display display, int handle) {
- return new Shell (display, null, SWT.NO_TRIM, handle, false);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when operations are performed on the receiver,
- * by sending the listener one of the messages defined in the
- * <code>ShellListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ShellListener
- * @see #removeShellListener
- */
-public void addShellListener(ShellListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.Activate,typedListener);
- addListener(SWT.Close,typedListener);
- addListener(SWT.Deactivate,typedListener);
- addListener(SWT.Iconify,typedListener);
- addListener(SWT.Deiconify,typedListener);
-}
-void adjustTrim () {
- if (display.ignoreTrim) return;
- if (OS.XtIsSubclass (shellHandle, OS.overrideShellWidgetClass ())) {
- return;
- }
- int [] argList = {OS.XmNoverrideRedirect, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- if (argList [1] != 0) return;
-
- /* Query the trim insets */
- int shellWindow = OS.XtWindow (shellHandle);
- if (shellWindow == 0) return;
- int xDisplay = OS.XtDisplay (shellHandle);
- if (xDisplay == 0) return;
-
- /* Find the direct child of the root window */
- int [] unused = new int [1];
- int [] rootWindow = new int [1];
- int [] parent = new int [1];
- int [] ptr = new int [1];
- int trimWindow = shellWindow;
- OS.XQueryTree (xDisplay, trimWindow, rootWindow, parent, ptr, unused);
- if (ptr [0] != 0) OS.XFree (ptr [0]);
- if (parent [0] == 0) return;
- while (parent [0] != rootWindow [0]) {
- trimWindow = parent [0];
- OS.XQueryTree (xDisplay, trimWindow, unused, parent, ptr, unused);
- if (ptr [0] != 0) OS.XFree (ptr [0]);
- if (parent [0] == 0) return;
- }
-
- /*
- * Translate the coordinates of the shell window to the
- * coordinates of the direct child of the root window
- */
- if (shellWindow == trimWindow) return;
-
- /* Query the border width of the direct child of the root window */
- int [] trimBorder = new int [1];
- int [] trimWidth = new int [1];
- int [] trimHeight = new int [1];
- int [] trimX = new int [1];
- int [] trimY = new int [1];
- OS.XGetGeometry (xDisplay, trimWindow, unused, trimX, trimY, trimWidth, trimHeight, trimBorder, unused);
-
- /* Query the border width of the direct child of the shell window */
- int [] shellBorder = new int [1];
- int [] shellWidth = new int [1];
- int [] shellHeight = new int [1];
- OS.XGetGeometry (xDisplay, shellWindow, unused, unused, unused, shellWidth, shellHeight, shellBorder, unused);
-
- /* Query the trim-adjusted position of the inner window */
- short [] inner_x = new short [1], inner_y = new short [1];
- OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, inner_x, inner_y);
-
- /* Calculate the trim */
- int width = (trimWidth [0] + (trimBorder [0] * 2)) - (shellWidth [0] + (shellBorder [0] * 2));
- int height = (trimHeight [0] + (trimBorder [0] * 2)) - (shellHeight [0] + (shellBorder [0] * 2));
- int leftInset = inner_x [0] - trimX [0];
- int topInset = inner_y [0] - trimY [0];
-
- /*
- * Depending on the window manager, the algorithm to compute the window
- * trim sometimes chooses the wrong X window, causing a large incorrect
- * value to be calculated. The fix is to ignore the trim values if they
- * are too large.
- */
- if (width > MAXIMUM_TRIM || height > MAXIMUM_TRIM) {
- display.ignoreTrim = true;
- return;
- }
-
- /* Update the trim guesses to match the query */
- boolean hasTitle = false, hasResize = false, hasBorder = false;
- if ((style & SWT.NO_TRIM) == 0) {
- hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0;
- hasResize = (style & SWT.RESIZE) != 0;
- hasBorder = (style & SWT.BORDER) != 0;
- }
- if (hasTitle) {
- if (hasResize) {
- display.leftTitleResizeWidth = leftInset;
- display.rightTitleResizeWidth = width - leftInset;
- display.topTitleResizeHeight = topInset;
- display.bottomTitleResizeHeight = height - topInset;
- return;
- }
- if (hasBorder) {
- display.leftTitleBorderWidth = leftInset;
- display.rightTitleBorderWidth = width - leftInset;
- display.topTitleBorderHeight = topInset;
- display.bottomTitleBorderHeight = height - topInset;
- return;
- }
- display.leftTitleWidth = leftInset;
- display.rightTitleWidth = width - leftInset;
- display.topTitleHeight = topInset;
- display.bottomTitleHeight = height - topInset;
- return;
- }
- if (hasResize) {
- display.leftResizeWidth = leftInset;
- display.rightResizeWidth = width - leftInset;
- display.topResizeHeight = topInset;
- display.bottomResizeHeight = height - topInset;
- return;
- }
- if (hasBorder) {
- display.leftBorderWidth = leftInset;
- display.rightBorderWidth = width - leftInset;
- display.topBorderHeight = topInset;
- display.bottomBorderHeight = height - topInset;
- return;
- }
-}
-int borderHandle () {
- return handle;
-}
-void bringToTop (boolean force) {
- /*
- * Feature in X. Calling XSetInputFocus() when the
- * widget is not viewable causes an X bad match error.
- * The fix is to call XSetInputFocus() when the widget
- * is viewable.
- */
- if (minimized) return;
- if (!isVisible ()) return;
- int xDisplay = OS.XtDisplay (shellHandle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (focusProxy != 0 ? focusProxy : shellHandle);
- if (xWindow == 0) return;
- if (!force) {
- int [] buffer1 = new int [1], buffer2 = new int [1];
- OS.XGetInputFocus (xDisplay, buffer1, buffer2);
- if (buffer1 [0] == 0) return;
- int handle = OS.XtWindowToWidget (xDisplay, buffer1 [0]);
- if (handle == 0) return;
- }
- int shellWindow = OS.XtWindow (shellHandle);
- if (shellWindow != 0) OS.XRaiseWindow (xDisplay, shellWindow);
- OS.XSetInputFocus (xDisplay, xWindow, OS.RevertToParent, OS.CurrentTime);
-}
-void center () {
- if (parent == null) return;
- Rectangle rect = getBounds ();
- Rectangle parentRect = display.map (parent, null, parent.getClientArea());
- int x = Math.max (parentRect.x, parentRect.x + (parentRect.width - rect.width) / 2);
- int y = Math.max (parentRect.y, parentRect.y + (parentRect.height - rect.height) / 2);
- Rectangle monitorRect = parent.getMonitor ().getClientArea();
- if (x + rect.width > monitorRect.x + monitorRect.width) {
- x = Math.max (monitorRect.x, monitorRect.x + monitorRect.width - rect.width);
- } else {
- x = Math.max (x, monitorRect.x);
- }
- if (y + rect.height > monitorRect.y + monitorRect.height) {
- y = Math.max (monitorRect.y, monitorRect.y + monitorRect.height - rect.height);
- } else {
- y = Math.max (y, monitorRect.y);
- }
- setLocation (x, y);
-}
-void checkOpen () {
- if (!opened) resized = false;
-}
-/**
- * Requests that the window manager close the receiver in
- * the same way it would be closed when the user clicks on
- * the "close box" or performs some other platform specific
- * key or mouse combination that indicates the window
- * should be removed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#Close
- * @see #dispose
- */
-public void close () {
- checkWidget();
- closeWidget ();
-}
-void closeWidget () {
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- if (event.doit && !isDisposed ()) dispose ();
-}
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- Rectangle trim = super.computeTrim (x, y, width, height);
- /*
- * Feature in Motif. There is no way to get the single pixel border
- * surrounding a TopLevelShell or a TransientShell. Attempts to set a
- * border on either the shell handle or the main window handle fail.
- * The fix is to set the border on the client area. Therefore, the
- * border must be added back into the trim.
- */
- int border = 0;
- if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) {
- int [] argList = {OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- border = argList [1];
- }
- trim.x -= trimLeft () + border;
- trim.y -= trimTop () + border;
- trim.width += trimWidth () + (border * 2);
- trim.height += trimHeight () + imeHeight () + (border * 2);
- return trim;
-}
-void createFocusProxy () {
- if (focusProxy != 0) return;
- int [] argList = {OS.XmNx, -1, OS.XmNy, -1, OS.XmNwidth, 1, OS.XmNheight, 1};
- focusProxy = OS.XmCreateDrawingArea (scrolledHandle, null, argList, argList.length / 2);
- if (focusProxy == 0) error (SWT.ERROR_NO_HANDLES);
- OS.XtSetMappedWhenManaged (focusProxy, false);
- OS.XtManageChild (focusProxy);
- OS.XtSetMappedWhenManaged (focusProxy, true);
-}
-void createHandle (int index) {
- state |= CANVAS;
- if (shellHandle == 0) {
- int decorations = 0;
- if ((style & SWT.NO_TRIM) == 0) {
- if ((style & SWT.MIN) != 0) decorations |= OS.MWM_DECOR_MINIMIZE;
- if ((style & SWT.MAX) != 0) decorations |= OS.MWM_DECOR_MAXIMIZE;
- if ((style & SWT.RESIZE) != 0) decorations |= OS.MWM_DECOR_RESIZEH;
- if ((style & SWT.BORDER) != 0) decorations |= OS.MWM_DECOR_BORDER;
- if ((style & SWT.MENU) != 0) decorations |= OS.MWM_DECOR_MENU;
- if ((style & SWT.TITLE) != 0) decorations |= OS.MWM_DECOR_TITLE;
- /*
- * Feature in Motif. Under some Window Managers (Sawmill), in order
- * to get any border at all from the window manager it is necessary
- * to set MWM_DECOR_BORDER. The fix is to force these bits when any
- * kind of border is requested.
- */
- if ((style & SWT.RESIZE) != 0) decorations |= OS.MWM_DECOR_BORDER;
- }
-
- /*
- * Note: Motif treats the modal values as hints to the Window Manager.
- * For example, Enlightenment treats all modes except for SWT.MODELESS
- * as SWT.APPLICATION_MODAL. The Motif Window Manager honours all modes.
- */
- int inputMode = OS.MWM_INPUT_MODELESS;
- if ((style & SWT.PRIMARY_MODAL) != 0) inputMode = OS.MWM_INPUT_PRIMARY_APPLICATION_MODAL;
- if ((style & SWT.APPLICATION_MODAL) != 0) inputMode = OS.MWM_INPUT_FULL_APPLICATION_MODAL;
- if ((style & SWT.SYSTEM_MODAL) != 0) inputMode = OS.MWM_INPUT_SYSTEM_MODAL;
-
- /*
- * Bug in Motif. For some reason, if the title string
- * length is not a multiple of 4, Motif occasionally
- * draws garbage after the last character in the title.
- * The fix is to pad the title.
- */
- byte [] buffer = {(byte)' ', 0, 0, 0};
- int ptr = OS.XtMalloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- int [] argList1 = {
- OS.XmNmwmInputMode, inputMode,
- OS.XmNmwmDecorations, decorations,
- OS.XmNoverrideRedirect, (style & SWT.ON_TOP) != 0 ? 1 : 0,
- OS.XmNtitle, ptr,
- };
-
- /*
- * Feature in Motif. On some Window Managers, when a top level
- * shell is created with no decorations, the Window Manager does
- * not reparent the window regardless of the XmNoverrideRedirect
- * resource. The fix is to treat the window as if it has been
- * reparented by the Window Manager despite the fact that this
- * has not really happened.
- */
- if (isUndecorated ()) {
- reparented = true;
- }
-
- /*
- * Feature in Motif. When a top level shell has no parent and is
- * application modal, Motif does not honour the modality. The fix
- * is to create the shell as a child of a hidden shell handle, the
- * same way that XmNoverrideRedirect shells without parents are
- * created.
- */
- byte [] appClass = display.appClass;
- if (parent == null && (style & SWT.ON_TOP) == 0 && inputMode != OS.MWM_INPUT_FULL_APPLICATION_MODAL) {
- int xDisplay = display.xDisplay;
- int widgetClass = OS.applicationShellWidgetClass ();
- shellHandle = OS.XtAppCreateShell (display.appName, appClass, widgetClass, xDisplay, argList1, argList1.length / 2);
- } else {
- int widgetClass = OS.transientShellWidgetClass ();
-// if ((style & SWT.ON_TOP) != 0) {
-// widgetClass = OS.OverrideShellWidgetClass ();
-// }
- int parentHandle = display.shellHandle;
- if (parent != null) parentHandle = parent.handle;
- shellHandle = OS.XtCreatePopupShell (appClass, widgetClass, parentHandle, argList1, argList1.length / 2);
- }
- OS.XtFree (ptr);
- if (shellHandle == 0) error (SWT.ERROR_NO_HANDLES);
- if (handle != 0) {
- OS.XtSetMappedWhenManaged (shellHandle, false);
- OS.XtRealizeWidget (shellHandle);
- OS.XtSetMappedWhenManaged (shellHandle, true);
- int xDisplay = display.xDisplay;
- int xWindow = OS.XtWindow (shellHandle);
- if (xWindow == 0) error (SWT.ERROR_NO_HANDLES);
- /*
- * NOTE: The embedded parent handle must be realized
- * before embedding and cannot be realized here because
- * the handle belongs to another thread.
- */
- OS.XReparentWindow (xDisplay, xWindow, handle, 0, 0);
- handle = 0;
- }
-
- /* Create scrolled handle */
- createHandle (index, shellHandle, true);
- } else {
- int [] buffer = new int [1];
- int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- if (argList [3] < 1) error (SWT.ERROR_NO_HANDLES);
- OS.memmove (buffer, argList [1], 4);
- scrolledHandle = buffer [0];
- if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
- argList [1] = argList [3] = 0;
- OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
- if (argList [3] < 4) error (SWT.ERROR_NO_HANDLES);
- OS.memmove (buffer, argList [1] + (argList [3] - 1) * 4, 4);
- handle = buffer [0];
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- }
-
- /*
- * Feature in Motif. There is no way to get the single pixel
- * border surrounding a TopLevelShell or a TransientShell.
- * Attempts to set a border on either the shell handle
- * or the main window handle fail. The fix is to set the border
- * on the client area.
- */
- if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) {
- int [] argList2 = {OS.XmNborderWidth, 1};
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- }
-
- /*
- * Feature in Motif. There is no Motif API to negotiate for the
- * status line. The fix is to force the status line to appear
- * by creating a hidden text widget. This is much safer than
- * using X API because this may conflict with Motif.
- *
- * Note that XmNtraversalOn must be set to FALSE or the shell
- * will not take focus when the user clicks on it.
- */
- if ((style & SWT.ON_TOP) == 0) {
- int [] argList3 = {OS.XmNtraversalOn, 0};
- int textHandle = OS.XmCreateTextField (handle, null, argList3, argList3.length / 2);
- if (textHandle == 0) error (SWT.ERROR_NO_HANDLES);
- }
-}
-void deregister () {
- super.deregister ();
- display.removeWidget (shellHandle);
-}
-void destroyWidget () {
- /*
- * Hide the shell before calling XtDestroyWidget ()
- * so that the shell will disappear without having
- * to dispatch events. Otherwise, the user will be
- * able to interact with the trimmings between the
- * time that the shell is destroyed and the next
- * event is dispatched.
- */
- if (OS.XtIsRealized (shellHandle)) {
- if (OS.XtIsTopLevelShell (shellHandle)) {
- OS.XtUnmapWidget (shellHandle);
- } else {
- OS.XtPopdown (shellHandle);
- }
- }
- super.destroyWidget ();
-}
-
-public void dispose () {
- /*
- * Note: It is valid to attempt to dispose a widget
- * more than once. If this happens, fail silently.
- */
- if (isDisposed()) return;
-
- /*
- * This code is intentionally commented. On some
- * platforms, the owner window is repainted right
- * away when the dialog window exits. This behavior
- * is currently unspecified.
- */
-// if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
-// Display oldDisplay = display;
-
- /*
- * Feature in Motif. When the active shell is disposed,
- * Motif assigns focus temporarily to the root window
- * unless it has previously been told to do otherwise.
- * The fix is to make the parent be the active top level
- * shell when the child shell is disposed.
- */
- if (parent != null) {
- Shell activeShell = display.getActiveShell ();
- if (activeShell == this) {
- Shell shell = parent.getShell ();
- shell.bringToTop (false);
- }
- }
- super.dispose ();
-
- /*
- * This code intentionally commented.
- */
-// if (oldDisplay != null) oldDisplay.update ();
-}
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- enableHandle (enabled, shellHandle);
-}
-Control findBackgroundControl () {
- return (state & BACKGROUND) != 0 || backgroundImage != null ? this : null;
-}
-Composite findDeferredControl () {
- return layoutCount > 0 ? this : null;
-}
-/**
- * If the receiver is visible, moves it to the top of the
- * drawing order for the display on which it was created
- * (so that all other shells on that display, which are not
- * the receiver's children will be drawn behind it) and forces
- * the window manager to make the shell active.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#open
- * @see Shell#setActive
- */
-public void forceActive () {
- checkWidget ();
- bringToTop (true);
-}
-/**
- * Returns the receiver's alpha value. The alpha value
- * is between 0 (transparent) and 255 (opaque).
- *
- * @return the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public int getAlpha () {
- checkWidget ();
- return 255;
-}
-public int getBorderWidth () {
- checkWidget();
- int [] argList = {OS.XmNborderWidth, 0};
- OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
- return argList [1];
-}
-public Rectangle getBounds () {
- checkWidget();
- Rectangle bounds = new Rectangle (0, 0, 0, 0);
- getBounds (null, null, bounds);
- return bounds;
-}
-void getBounds(Point location, Point size, Rectangle bounds) {
- int x = 0, y = 0;
- if (location != null || bounds != null) {
- /*
- * Bug in Motif. For some reason, XtTranslateCoords() returns different
- * values depending on whether XtMoveWidget() or XtConfigureWidget() has
- * been called. This only happens after the shell has been realized.
- * The fix is to use XTranslateCoordinates() instead.
- */
- if (OS.XtIsRealized (shellHandle)) {
- int xDisplay = OS.XtDisplay (shellHandle);
- int xWindow = OS.XtWindow (shellHandle);
- int[] root_x = new int[1], root_y = new int[1], child = new int[1];
- /* Flush outstanding move and resize requests */
- OS.XSync (xDisplay, false);
- OS.XTranslateCoordinates (xDisplay, xWindow, OS.XDefaultRootWindow (xDisplay), 0, 0, root_x, root_y, child);
- x = root_x [0];
- y = root_y [0];
- } else {
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, root_x, root_y);
- x = root_x [0];
- y = root_y [0];
- }
- if (reparented) {
- x -= trimLeft ();
- y -= trimTop ();
- }
- }
- int width = 0, height = 0;
- if (size != null || bounds != null) {
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- int border = argList [5];
- int trimWidth = trimWidth (), trimHeight = trimHeight ();
- width = argList [1] + trimWidth + (border * 2);
- height = argList [3] + trimHeight + (border * 2);
- }
- if (location != null) {
- location.x = x;
- location.y = y;
- }
- if (size != null) {
- size.x = width;
- size.y = height;
- }
- if (bounds != null) {
- bounds.x = x;
- bounds.y = y;
- bounds.width = width;
- bounds.height = height;
- }
-}
-/**
- * Returns <code>true</code> if the receiver is currently
- * in fullscreen state, and false otherwise.
- * <p>
- *
- * @return the fullscreen state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getFullScreen () {
- checkWidget();
- int xDisplay = OS.XtDisplay (shellHandle);
- int xWindow = OS.XtWindow (shellHandle);
- if (xWindow != 0) {
- int property = OS.XInternAtom (xDisplay, _NET_WM_STATE, true);
- if (property != 0) {
- int[] type = new int[1], format = new int[1], nitems = new int[1], bytes_after = new int[1], atoms = new int[1];
- OS.XGetWindowProperty (xDisplay, xWindow, property, 0, Integer.MAX_VALUE, false, OS.XA_ATOM, type, format, nitems, bytes_after, atoms);
- boolean result = false;
- if (type [0] != OS.None) {
- int fullScreen = OS.XInternAtom (xDisplay, _NET_WM_STATE_FULLSCREEN, true);
- if (fullScreen != 0) {
- int[] atom = new int[1];
- for (int i=0; i<nitems [0]; i++) {
- OS.memmove(atom, atoms [0] + i * 4, 4);
- if (atom [0] == fullScreen) {
- result = true;
- break;
- }
- }
- }
- }
- if (atoms [0] != 0) OS.XFree (atoms [0]);
- return result;
- }
- }
- return false;
-}
-/**
- * Returns the receiver's input method editor mode. This
- * will be the result of bitwise OR'ing together one or
- * more of the following constants defined in class
- * <code>SWT</code>:
- * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>,
- * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>.
- *
- * @return the IME mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public int getImeInputMode () {
- checkWidget();
- return SWT.NONE;
-}
-public Point getLocation () {
- checkWidget();
- Point location = new Point (0, 0);
- getBounds (location, null, null);
- return location;
-}
-public boolean getMaximized () {
- checkWidget();
- int xDisplay = OS.XtDisplay (shellHandle);
- int xWindow = OS.XtWindow (shellHandle);
- if (xWindow != 0) {
- int property = OS.XInternAtom (xDisplay, _NET_WM_STATE, true);
- if (property != 0) {
- int[] type = new int[1], format = new int[1], nitems = new int[1], bytes_after = new int[1], atoms = new int[1];
- OS.XGetWindowProperty (xDisplay, xWindow, property, 0, Integer.MAX_VALUE, false, OS.XA_ATOM, type, format, nitems, bytes_after, atoms);
- boolean result = false;
- if (type [0] != OS.None) {
- int maximizedHorz = OS.XInternAtom (xDisplay, _NET_WM_STATE_MAXIMIZED_HORZ, true);
- int maximizedVert = OS.XInternAtom (xDisplay, _NET_WM_STATE_MAXIMIZED_VERT, true);
- if (maximizedHorz != 0 && maximizedVert != 0) {
- int[] atom = new int[1];
- for (int i=0; i<nitems [0]; i++) {
- OS.memmove(atom, atoms [0] + i * 4, 4);
- if (atom [0] == maximizedHorz || atom [0] == maximizedVert) {
- result = true;
- break;
- }
- }
- }
- }
- if (atoms [0] != 0) OS.XFree (atoms [0]);
- return result;
- }
- }
- return super.getMaximized ();
-}
-/**
- * Returns a point describing the minimum receiver's size. The
- * x coordinate of the result is the minimum width of the receiver.
- * The y coordinate of the result is the minimum height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Point getMinimumSize () {
- checkWidget ();
- int [] argList = {OS.XmNminWidth, 0, OS.XmNminHeight, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- int width = Math.max (1, Math.max (0, argList [1]) + trimWidth ());
- int height = Math.max (1, Math.max (0, argList [3]) + trimHeight ());
- return new Point (width, height);
-}
-/**
- * Gets the receiver's modified state.
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.5
- */
-public boolean getModified () {
- checkWidget ();
- return modified;
-}
-/**
- * Returns the region that defines the shape of the shell,
- * or null if the shell has the default shape.
- *
- * @return the region that defines the shape of the shell (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public Region getRegion () {
- /* This method is needed for the @since 3.0 Javadoc */
- checkWidget ();
- return region;
-}
-public Shell getShell () {
- checkWidget();
- return this;
-}
-/**
- * Returns an array containing all shells which are
- * descendants of the receiver.
- * <p>
- * @return the dialog shells
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Shell [] getShells () {
- checkWidget();
- int count = 0;
- Shell [] shells = display.getShells ();
- for (int i=0; i<shells.length; i++) {
- Control shell = shells [i];
- do {
- shell = shell.parent;
- } while (shell != null && shell != this);
- if (shell == this) count++;
- }
- int index = 0;
- Shell [] result = new Shell [count];
- for (int i=0; i<shells.length; i++) {
- Control shell = shells [i];
- do {
- shell = shell.parent;
- } while (shell != null && shell != this);
- if (shell == this) {
- result [index++] = shells [i];
- }
- }
- return result;
-}
-public Point getSize () {
- checkWidget();
- Point size = new Point (0, 0);
- getBounds (null, size, null);
- return size;
-}
-public boolean getVisible () {
- checkWidget();
- if (!OS.XtIsRealized (handle)) return false;
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return false;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return false;
- XWindowAttributes attributes = new XWindowAttributes ();
- OS.XGetWindowAttributes (xDisplay, xWindow, attributes);
- if (attributes.map_state == OS.IsViewable && reparented) return true;
- int [] argList = {OS.XmNmappedWhenManaged, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- return minimized && attributes.map_state == OS.IsUnviewable && argList [1] != 0;
-}
-boolean hasBorder () {
- return false;
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- OS.XtInsertEventHandler (shellHandle, OS.StructureNotifyMask, false, windowProc, STRUCTURE_NOTIFY, OS.XtListTail);
- if (OS.XtIsSubclass (shellHandle, OS.overrideShellWidgetClass ())) return;
- OS.XtInsertEventHandler (shellHandle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail);
- int [] argList = {OS.XmNdeleteResponse, OS.XmDO_NOTHING};
- OS.XtSetValues (shellHandle, argList, argList.length / 2);
- int xDisplay = OS.XtDisplay (shellHandle);
- if (xDisplay != 0) {
- int atom = OS.XmInternAtom (xDisplay, WM_DELETE_WINDOW, false);
- OS.XmAddWMProtocolCallback (shellHandle, atom, windowProc, DELETE_WINDOW);
- }
-}
-int imeHeight () {
- if (!OS.IsDBLocale) return 0;
- int [] argList1 = {OS.XmNheight, 0};
- OS.XtGetValues (shellHandle, argList1, argList1.length / 2);
- int [] argList2 = {OS.XmNheight, 0};
- OS.XtGetValues (scrolledHandle, argList2, argList2.length / 2);
- return argList1 [1] - argList2 [1];
-}
-public boolean isEnabled () {
- checkWidget();
- return getEnabled ();
-}
-boolean isModal () {
- checkWidget();
- int [] argList = {OS.XmNmwmInputMode, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- return (argList [1] != -1 && argList [1] != OS.MWM_INPUT_MODELESS);
-}
-boolean isUndecorated () {
- return
- (style & (SWT.SHELL_TRIM | SWT.BORDER)) == SWT.NONE ||
- (style & (SWT.NO_TRIM | SWT.ON_TOP)) != 0;
-}
-public boolean isVisible () {
- checkWidget();
- return getVisible ();
-}
-void manageChildren () {
- if ((state & FOREIGN_HANDLE) != 0) return;
- OS.XtSetMappedWhenManaged (shellHandle, false);
- super.manageChildren ();
- int width = 0, height = 0;
- if (OS.IsLinux) {
- Monitor monitor = getMonitor ();
- Rectangle rect = monitor.getClientArea ();
- width = rect.width * 5 / 8;
- height = rect.height * 5 / 8;
- } else {
- int xDisplay = OS.XtDisplay (shellHandle);
- if (xDisplay == 0) return;
- width = OS.XDisplayWidth (xDisplay, OS.XDefaultScreen (xDisplay)) * 5 / 8;
- height = OS.XDisplayHeight (xDisplay, OS.XDefaultScreen (xDisplay)) * 5 / 8;
- }
- OS.XtResizeWidget (shellHandle, width, height, 0);
-}
-/**
- * Moves the receiver to the top of the drawing order for
- * the display on which it was created (so that all other
- * shells on that display, which are not the receiver's
- * children will be drawn behind it), marks it visible,
- * sets the focus and asks the window manager to make the
- * shell active.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#setActive
- * @see Shell#forceActive
- */
-public void open () {
- checkWidget();
- bringToTop (false);
- setVisible (true);
- if (isDisposed ()) return;
- if (!restoreFocus () && !traverseGroup (true)) setFocus ();
-}
-public boolean print (GC gc) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- return false;
-}
-void propagateWidget (boolean enabled) {
- super.propagateWidget (enabled);
- /* Allow the busy cursor to be displayed in a disabled shell */
- int xCursor = cursor != null && !enabled ? cursor.handle : OS.None;
- propagateHandle (enabled, shellHandle, xCursor);
-}
-void realizeWidget () {
- if (realized) return;
- OS.XtRealizeWidget (shellHandle);
- realizeChildren ();
- realized = true;
-}
-void register () {
- super.register ();
- display.addWidget (shellHandle, this);
-}
-void releaseChildren (boolean destroy) {
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (shell != null && !shell.isDisposed ()) {
- shell.release (false);
- }
- }
- super.releaseChildren (destroy);
-}
-void releaseHandle () {
- super.releaseHandle ();
- shellHandle = 0;
-}
-void releaseParent () {
- /* Do nothing */
-}
-void releaseWidget () {
- super.releaseWidget ();
- lastActive = null;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when operations are performed on the receiver.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ShellListener
- * @see #addShellListener
- */
-public void removeShellListener(ShellListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Activate, listener);
- eventTable.unhook(SWT.Close, listener);
- eventTable.unhook(SWT.Deactivate, listener);
- eventTable.unhook(SWT.Iconify,listener);
- eventTable.unhook(SWT.Deiconify,listener);
-}
-
-/**
- * If the receiver is visible, moves it to the top of the
- * drawing order for the display on which it was created
- * (so that all other shells on that display, which are not
- * the receiver's children will be drawn behind it) and asks
- * the window manager to make the shell active
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#open
- * @see Shell#setActive
- */
-public void setActive () {
- checkWidget ();
- bringToTop (false);
-}
-
-void setActiveControl (Control control) {
- if (control != null && control.isDisposed ()) control = null;
- if (lastActive != null && lastActive.isDisposed ()) lastActive = null;
- if (lastActive == control) return;
-
- /*
- * Compute the list of controls to be activated and
- * deactivated by finding the first common parent
- * control.
- */
- Control [] activate = (control == null) ? new Control[0] : control.getPath ();
- Control [] deactivate = (lastActive == null) ? new Control[0] : lastActive.getPath ();
- lastActive = control;
- int index = 0, length = Math.min (activate.length, deactivate.length);
- while (index < length) {
- if (activate [index] != deactivate [index]) break;
- index++;
- }
-
- /*
- * It is possible (but unlikely), that application
- * code could have destroyed some of the widgets. If
- * this happens, keep processing those widgets that
- * are not disposed.
- */
- for (int i=deactivate.length-1; i>=index; --i) {
- if (!deactivate [i].isDisposed ()) {
- if (display.postFocusOut) {
- deactivate [i].postEvent (SWT.Deactivate);
- } else {
- deactivate [i].sendEvent (SWT.Deactivate);
- }
- }
- }
- for (int i=activate.length-1; i>=index; --i) {
- if (!activate [i].isDisposed ()) {
- activate [i].sendEvent (SWT.Activate);
- }
- }
-}
-/**
- * Sets the receiver's alpha value which must be
- * between 0 (transparent) and 255 (opaque).
- * <p>
- * This operation requires the operating system's advanced
- * widgets subsystem which may not be available on some
- * platforms.
- * </p>
- * @param alpha the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setAlpha (int alpha) {
- checkWidget ();
- /* Not implemented */
-}
-/**
- * Sets the input method editor mode to the argument which
- * should be the result of bitwise OR'ing together one or more
- * of the following constants defined in class <code>SWT</code>:
- * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>,
- * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>.
- *
- * @param mode the new IME mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public void setImeInputMode (int mode) {
- checkWidget();
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- /*
- * Bug in Motif. When a shell that is maximized is resized to
- * the same size, when the shell is unmaximized, the origin of
- * the shell is moved to (0, 0). The fix is to detect this case
- * and avoid resizing the shell.
- *
- * NOTE: When only the size is changed, the shell moves to (0, 0).
- * When only the location is changed, the shell is not moved. There
- * is no fix for these problems at this time.
- */
- if (getMaximized ()) {
- Rectangle rect = getBounds ();
- boolean sameOrigin = !move || (rect.x == x && rect.y == y);
- boolean sameExtent = !resize || (rect.width == width && rect.height == height);
- if (sameOrigin && sameExtent) return false;
- }
- if (resize) {
- int [] argList = {OS.XmNminWidth, 0, OS.XmNminHeight, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- /*
- * Feature in Motif. Motif will not allow a window
- * to have a zero width or zero height. The fix is
- * to ensure these values are never zero.
- */
- width = Math.max (1, Math.max (argList [1], width - trimWidth ()));
- height = Math.max (1, Math.max (argList [3], height - trimHeight ()));
- updateResizable (width, height);
- }
- if (move && resize) {
- OS.XtConfigureWidget (shellHandle, x, y, width, height, 0);
- } else {
- if (move) OS.XtMoveWidget (shellHandle, x, y);
- if (resize) OS.XtResizeWidget (shellHandle, width, height, 0);
- }
- if (redrawWindow != 0) {
- int xDisplay = OS.XtDisplay (handle);
- OS.XResizeWindow (xDisplay, redrawWindow, width, height);
- }
- if (move && (oldX != x || oldY != y)) {
- moved = true;
- oldX = x + trimLeft ();
- oldY = y + trimTop ();
- sendEvent (SWT.Move);
- if (isDisposed ()) return false;
- }
- if (resize && (width != oldWidth || height != oldHeight)) {
- resized = true;
- oldWidth = width;
- oldHeight = height;
- sendEvent (SWT.Resize);
- if (isDisposed ()) return false;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
- }
- return move || resize;
-}
-public void setEnabled (boolean enabled) {
- checkWidget ();
- if (enabled == getEnabled ()) return;
- super.setEnabled (enabled);
- if (enabled && this == display.getActiveShell ()) {
- if (!restoreFocus ()) traverseGroup (false);
- }
-}
-/**
- * Sets the full screen state of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the full screen state, and if the argument is
- * <code>false</code> and the receiver was previously switched
- * into full screen state, causes the receiver to switch back
- * to either the maximized or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setFullScreen(true)</code>,
- * <code>setMaximized(true)</code> and <code>setMinimized(true)</code> will
- * vary by platform. Typically, the behavior will match the platform user's
- * expectations, but not always. This should be avoided if possible.
- * </p>
- *
- * @param fullScreen the new fullscreen state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setFullScreen (boolean fullScreen) {
- checkWidget();
- if (!OS.XtIsRealized (handle)) realizeWidget ();
- int xDisplay = OS.XtDisplay (shellHandle);
- int xWindow = OS.XtWindow (shellHandle);
- if (xWindow == 0) return;
- int property = OS.XInternAtom (xDisplay, _NET_WM_STATE, true);
- if (property == 0) return;
- int atom = OS.XInternAtom (xDisplay, _NET_WM_STATE_FULLSCREEN, true);
- if (atom == 0) return;
- XClientMessageEvent xEvent = new XClientMessageEvent ();
- xEvent.type = OS.ClientMessage;
- xEvent.send_event = 1;
- xEvent.display = xDisplay;
- xEvent.window = xWindow;
- xEvent.message_type = property;
- xEvent.format = 32;
- xEvent.data [0] = fullScreen ? 1 : 0;
- xEvent.data [1] = atom;
- XWindowAttributes attributes = new XWindowAttributes ();
- OS.XGetWindowAttributes (xDisplay, xWindow, attributes);
- int rootWindow = OS.XRootWindowOfScreen (attributes.screen);
- int event = OS.XtMalloc (XEvent.sizeof);
- OS.memmove (event, xEvent, XClientMessageEvent.sizeof);
- OS.XSendEvent (xDisplay, rootWindow, false, OS.SubstructureRedirectMask|OS.SubstructureNotifyMask, event);
- OS.XSync (xDisplay, false);
- OS.XtFree (event);
-}
-public void setMaximized (boolean maximized) {
- checkWidget();
- super.setMaximized (maximized);
- if (!OS.XtIsRealized (handle)) realizeWidget ();
- int xDisplay = OS.XtDisplay (shellHandle);
- int xWindow = OS.XtWindow (shellHandle);
- if (xWindow == 0) return;
- int property = OS.XInternAtom (xDisplay, _NET_WM_STATE, true);
- if (property == 0) return;
- int hMaxAtom = OS.XInternAtom (xDisplay, _NET_WM_STATE_MAXIMIZED_HORZ, true);
- int vMaxAtom = OS.XInternAtom (xDisplay, _NET_WM_STATE_MAXIMIZED_VERT, true);
- if (hMaxAtom == 0 || vMaxAtom == 0) return;
- XClientMessageEvent xEvent = new XClientMessageEvent ();
- xEvent.type = OS.ClientMessage;
- xEvent.send_event = 1;
- xEvent.display = xDisplay;
- xEvent.window = xWindow;
- xEvent.message_type = property;
- xEvent.format = 32;
- xEvent.data [0] = maximized ? 1 : 0;
- xEvent.data [1] = hMaxAtom;
- xEvent.data [2] = vMaxAtom;
- XWindowAttributes attributes = new XWindowAttributes ();
- OS.XGetWindowAttributes (xDisplay, xWindow, attributes);
- int rootWindow = OS.XRootWindowOfScreen (attributes.screen);
- int event = OS.XtMalloc (XEvent.sizeof);
- OS.memmove (event, xEvent, XClientMessageEvent.sizeof);
- OS.XSendEvent (xDisplay, rootWindow, false, OS.SubstructureRedirectMask|OS.SubstructureNotifyMask, event);
- OS.XSync (xDisplay, false);
- OS.XtFree (event);
-}
-public void setMinimized (boolean minimized) {
- checkWidget();
- if (minimized == this.minimized) return;
-
- /*
- * Bug in MOTIF. For some reason, the receiver does not keep the
- * value of the XmNiconic resource up to date when the user minimizes
- * and restores the window. As a result, a window that is minimized
- * by the user and then restored by the programmer is not restored.
- * This happens because the XmNiconic resource is unchanged when the
- * window is minimized by the user and subsequent attempts to set the
- * resource fail because the new value of the resource is the same as
- * the old value. The fix is to force XmNiconic to be up to date
- * before setting the desired value.
- */
- int [] argList = {
- OS.XmNiconic, 0,
- OS.XmNinitialState, 0,
- };
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- if ((argList [1] != 0) != this.minimized) {
- argList [1] = this.minimized ? 1 : 0;
- OS.XtSetValues (shellHandle, argList, argList.length / 2);
- }
-
- /* Minimize or restore the shell */
- super.setMinimized (minimized);
- argList [1] = minimized ? 1 : 0;
- argList [3] = minimized ? OS.IconicState : OS.NormalState;
- OS.XtSetValues (shellHandle, argList, argList.length / 2);
-
- /* Force the XWindowAttributes to be up to date */
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay != 0) OS.XSync (xDisplay, false);
-
- /* Make the restored shell be the active shell */
- if (!minimized) {
- int [] argList2 = {OS.XmNmappedWhenManaged, 0};
- OS.XtGetValues (shellHandle, argList2, argList2.length / 2);
- if (argList2 [1] != 0) {
- do {
- display.update ();
- } while (!isVisible ());
- setActive ();
- }
- }
-}
-/**
- * Sets the receiver's minimum size to the size specified by the arguments.
- * If the new minimum size is larger than the current size of the receiver,
- * the receiver is resized to the new minimum size.
- *
- * @param width the new minimum width for the receiver
- * @param height the new minimum height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setMinimumSize (int width, int height) {
- checkWidget ();
- int [] argList = {
- OS.XmNminWidth, Math.max (width, trimWidth ()) - trimWidth (),
- OS.XmNminHeight, Math.max (height, trimHeight ()) - trimHeight (),
- };
- OS.XtSetValues (shellHandle, argList, argList.length / 2);
-}
-/**
- * Sets the receiver's minimum size to the size specified by the argument.
- * If the new minimum size is larger than the current size of the receiver,
- * the receiver is resized to the new minimum size.
- *
- * @param size the new minimum size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setMinimumSize (Point size) {
- checkWidget ();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setMinimumSize (size.x, size.y);
-}
-/**
- * Sets the receiver's modified state as specified by the argument.
- *
- * @param modified the new modified state for the receiver
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.5
- */
-public void setModified (boolean modified) {
- checkWidget ();
- this.modified = modified;
-}
-void setParentTraversal () {
- /* Do nothing - Child shells do not affect the traversal of their parent shell */
-}
-/**
- * Sets the shape of the shell to the region specified
- * by the argument. When the argument is null, the
- * default shape of the shell is restored. The shell
- * must be created with the style SWT.NO_TRIM in order
- * to specify a region.
- *
- * @param region the region that defines the shape of the shell (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public void setRegion (Region region) {
- checkWidget ();
- if ((style & SWT.NO_TRIM) == 0) return;
- if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- super.setRegion (region);
-}
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
-
- /*
- * Feature in Motif. It is not possible to set a shell
- * title to an empty string. The fix is to set the title
- * to be a single space.
- */
- /* Use the character encoding for the default locale */
- if (string.length () == 0) string = " ";
- byte [] buffer1 = Converter.wcsToMbcs (null, string, true);
-
- /*
- * Bug in Motif. For some reason, if the title string
- * length is not a multiple of 4, Motif occasionally
- * draws garbage after the last character in the title.
- * The fix is to pad the title.
- */
- byte [] buffer2 = buffer1;
- int length = buffer1.length - 1;
- if ((length % 4) != 0) {
- buffer2 = new byte [(length + 3) / 4 * 4];
- System.arraycopy (buffer1, 0, buffer2, 0, length);
- }
-
- /* Set the title for the shell */
- int ptr = OS.XtMalloc (buffer2.length + 1);
- OS.memmove (ptr, buffer2, buffer2.length);
- int [] argList = {OS.XmNtitle, ptr, OS.XmNiconName, ptr};
- OS.XtSetValues (shellHandle, argList, argList.length / 2);
- OS.XtFree (ptr);
-}
-public void setVisible (boolean visible) {
- checkWidget();
- realizeWidget ();
-
- /* Show the shell */
- if (visible) {
- if (center && !moved) {
- center ();
- if (isDisposed ()) return;
- }
- sendEvent (SWT.Show);
- if (isDisposed ()) return;
-
- /* Map the widget */
- OS.XtSetMappedWhenManaged (shellHandle, true);
- if (OS.XtIsTopLevelShell (shellHandle)) {
- OS.XtMapWidget (shellHandle);
- } else {
- OS.XtPopup (shellHandle, OS.XtGrabNone);
- }
-
- /*
- * Force the shell to be fully exposed before returning.
- * This ensures that the shell coordinates are correct
- * when queried directly after showing the shell.
- *
- * Note that if the parent is minimized or withdrawn
- * from the desktop, this should not be done since
- * the shell will not be mapped until the parent is
- * unminimized or shown on the desktop.
- */
- boolean iconic = false;
- Shell shell = parent != null ? parent.getShell() : null;
- do {
- display.update ();
- if (isDisposed ()) return;
- iconic = minimized || (shell != null && shell.minimized);
- } while (!isVisible () && !iconic);
- if (!iconic) adjustTrim ();
-
- int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.APPLICATION_MODAL;
- if ((style & mask) != 0) {
- OS.XUngrabPointer (display.xDisplay, OS.CurrentTime);
- }
- opened = true;
- if (!moved) {
- moved = true;
- Point location = getLocation ();
- oldX = location.x + trimLeft ();
- oldY = location.x + trimTop ();
- sendEvent (SWT.Move);
- if (isDisposed ()) return;
- }
- if (!resized) {
- resized = true;
- Point size = getSize ();
- oldWidth = size.x - trimWidth ();
- oldHeight = size.y - trimHeight ();
- sendEvent (SWT.Resize);
- if (isDisposed ()) return;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
- }
- } else {
- /*
- * Feature in Motif. When the active shell is disposed,
- * some window managers place focus in a temporary window.
- * The fix is to make the parent be the active top level
- * shell when the child shell is hidden.
- */
- if (parent != null) {
- Shell activeShell = display.getActiveShell ();
- if (activeShell == this) {
- Shell shell = parent.getShell ();
- shell.bringToTop (false);
- }
- }
-
- /* Hide the shell */
- OS.XtSetMappedWhenManaged (shellHandle, false);
- if (OS.XtIsTopLevelShell (shellHandle)) {
- OS.XtUnmapWidget (shellHandle);
- } else {
- OS.XtPopdown (shellHandle);
- }
-
- /* If the shell is iconified, hide the icon */
- int xDisplay = OS.XtDisplay (shellHandle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (shellHandle);
- if (xWindow == 0) return;
- OS.XWithdrawWindow (xDisplay, xWindow, OS.XDefaultScreen (xDisplay));
-
- sendEvent (SWT.Hide);
- }
-}
-void setZOrder (Control control, boolean above) {
- setZOrder (control, above, false);
-}
-int topHandle () {
- return shellHandle;
-}
-boolean traverseEscape () {
- if (parent == null) return false;
- if (!isVisible () || !isEnabled ()) return false;
- close ();
- return true;
-}
-int trimHeight () {
- if ((style & SWT.NO_TRIM) != 0) return 0;
- boolean hasTitle = false, hasResize = false, hasBorder = false;
- hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0;
- hasResize = (style & SWT.RESIZE) != 0;
- hasBorder = (style & SWT.BORDER) != 0;
- if (hasTitle) {
- if (hasResize) {
- return display.topTitleResizeHeight + display.bottomTitleResizeHeight;
- }
- if (hasBorder) {
- return display.topTitleBorderHeight + display.bottomTitleBorderHeight;
- }
- return display.topTitleHeight + display.bottomTitleHeight;
- }
- if (hasResize) {
- return display.topResizeHeight + display.bottomResizeHeight;
- }
- if (hasBorder) {
- return display.topBorderHeight + display.bottomBorderHeight;
- }
- return 0;
-}
-int trimLeft () {
- if ((style & SWT.NO_TRIM) != 0) return 0;
- boolean hasTitle = false, hasResize = false, hasBorder = false;
- hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0;
- hasResize = (style & SWT.RESIZE) != 0;
- hasBorder = (style & SWT.BORDER) != 0;
- if (hasTitle) {
- if (hasResize) return display.leftTitleResizeWidth;
- if (hasBorder) return display.leftTitleBorderWidth;
- return display.leftTitleWidth;
- }
- if (hasResize) return display.leftResizeWidth;
- if (hasBorder) return display.leftBorderWidth;
- return 0;
-}
-int trimTop () {
- if ((style & SWT.NO_TRIM) != 0) return 0;
- boolean hasTitle = false, hasResize = false, hasBorder = false;
- hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0;
- hasResize = (style & SWT.RESIZE) != 0;
- hasBorder = (style & SWT.BORDER) != 0;
- if (hasTitle) {
- if (hasResize) return display.topTitleResizeHeight;
- if (hasBorder) return display.topTitleBorderHeight;
- return display.topTitleHeight;
- }
- if (hasResize) return display.topResizeHeight;
- if (hasBorder) return display.topBorderHeight;
- return 0;
-}
-int trimWidth () {
- if ((style & SWT.NO_TRIM) != 0) return 0;
- boolean hasTitle = false, hasResize = false, hasBorder = false;
- hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0;
- hasResize = (style & SWT.RESIZE) != 0;
- hasBorder = (style & SWT.BORDER) != 0;
- if (hasTitle) {
- if (hasResize) {
- return display.leftTitleResizeWidth + display.rightTitleResizeWidth;
- }
- if (hasBorder) {
- return display.leftTitleBorderWidth + display.rightTitleBorderWidth;
- }
- return display.leftTitleWidth + display.rightTitleWidth;
- }
- if (hasResize) {
- return display.leftResizeWidth + display.rightResizeWidth;
- }
- if (hasBorder) {
- return display.leftBorderWidth + display.rightBorderWidth;
- }
- return 0;
-}
-void updateResizable (int width, int height) {
- if ((style & SWT.RESIZE) != 0) return;
- if (!OS.XtIsRealized (shellHandle)) return;
- XSizeHints hints = new XSizeHints ();
- hints.flags = OS.PMinSize | OS.PMaxSize | OS.PPosition;
- hints.min_width = hints.max_width = width;
- hints.min_height = hints.max_height = height;
- OS.XSetWMNormalHints (OS.XtDisplay (shellHandle), OS.XtWindow (shellHandle), hints);
-}
-int WM_DELETE_WINDOW (int w, int client_data, int call_data) {
- if (!isEnabled ()) return 0;
- Control widget = parent;
- while (widget != null && !(widget.getShell ().isModal ())) {
- widget = widget.parent;
- }
- if (widget == null) {
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (shell != this && shell.isModal () && shell.isVisible ()) {
- shell.bringToTop (false);
- return 0;
- }
- }
- }
- closeWidget ();
- return 0;
-}
-int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatch) {
- XFocusChangeEvent xEvent = new XFocusChangeEvent ();
- OS.memmove (xEvent, call_data, XFocusChangeEvent.sizeof);
- int handle = OS.XtWindowToWidget (xEvent.display, xEvent.window);
- if (handle != shellHandle) {
- return super.XFocusChange (w, client_data, call_data, continue_to_dispatch);
- }
- if (xEvent.mode != OS.NotifyNormal) return 0;
- if (xEvent.type == OS.FocusIn && xEvent.detail == OS.NotifyInferior) {
- if (focusProxy != 0) {
- int xWindow = OS.XtWindow (focusProxy);
- int xDisplay = OS.XtDisplay (focusProxy);
- OS.XSetInputFocus (xDisplay, xWindow, OS.RevertToParent, OS.CurrentTime);
- }
- }
- switch (xEvent.detail) {
- case OS.NotifyNonlinear:
- case OS.NotifyNonlinearVirtual: {
- switch (xEvent.type) {
- case OS.FocusIn:
- if (display.postFocusOut) {
- postEvent (SWT.Activate);
- } else {
- sendEvent (SWT.Activate);
- }
- break;
- case OS.FocusOut:
- Display display = this.display;
- if (display.postFocusOut) {
- postEvent (SWT.Deactivate);
- } else {
- sendEvent (SWT.Deactivate);
- }
- Control focusedCombo = display.focusedCombo;
- display.focusedCombo = null;
- if (focusedCombo != null && focusedCombo != this && !focusedCombo.isDisposed ()) {
- display.sendFocusEvent (focusedCombo, SWT.FocusOut);
- }
- break;
- }
- }
- }
- return 0;
-}
-int XStructureNotify (int w, int client_data, int call_data, int continue_to_dispatch) {
- XConfigureEvent xEvent = new XConfigureEvent ();
- OS.memmove (xEvent, call_data, XConfigureEvent.sizeof);
- int handle = OS.XtWindowToWidget (xEvent.display, xEvent.window);
- if (handle != shellHandle) {
- return super.XStructureNotify (w, client_data, call_data, continue_to_dispatch);
- }
- switch (xEvent.type) {
- case OS.ReparentNotify: {
- reparented = true;
- adjustTrim ();
- break;
- }
- case OS.ConfigureNotify:
- int [] root_x = new int [1], root_y = new int [1], child = new int [1];
- OS.XTranslateCoordinates (xEvent.display, xEvent.window, OS.XDefaultRootWindow (xEvent.display), 0, 0, root_x, root_y, child);
- if (!moved || oldX != root_x [0] || oldY != root_y [0]) {
- moved = true;
- oldX = root_x [0];
- oldY = root_y [0];
- sendEvent (SWT.Move);
- if (isDisposed ()) return 0;
- }
- updateResizable (xEvent.width, xEvent.height);
- if (!resized || oldWidth != xEvent.width || oldHeight != xEvent.height) {
- int xEvent1 = OS.XtMalloc (XEvent.sizeof);
- display.resizeWindow = xEvent.window;
- display.resizeWidth = xEvent.width;
- display.resizeHeight = xEvent.height;
- display.resizeCount = 0;
- int checkResizeProc = display.checkResizeProc;
- OS.XCheckIfEvent (xEvent.display, xEvent1, checkResizeProc, 0);
- OS.XtFree (xEvent1);
- if (display.resizeCount == 0) {
- resized = true;
- oldWidth = xEvent.width;
- oldHeight = xEvent.height;
- sendEvent (SWT.Resize);
- if (isDisposed ()) return 0;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
- }
- }
- return 0;
- case OS.UnmapNotify:
- int [] argList = {OS.XmNmappedWhenManaged, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- if (argList [1] != 0) {
- minimized = true;
- sendEvent (SWT.Iconify);
- }
- return 0;
- case OS.MapNotify:
- if (minimized) {
- minimized = false;
- sendEvent (SWT.Deiconify);
- }
- return 0;
- }
- return 0;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java
deleted file mode 100755
index 0ac37fc1cc..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java
+++ /dev/null
@@ -1,553 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that represent a range of positive, numeric values.
- * <p>
- * At any given moment, a given slider will have a
- * single 'selection' that is considered to be its
- * value, which is constrained to be within the range of
- * values the slider represents (that is, between its
- * <em>minimum</em> and <em>maximum</em> values).
- * </p><p>
- * Typically, sliders will be made up of five areas:
- * <ol>
- * <li>an arrow button for decrementing the value</li>
- * <li>a page decrement area for decrementing the value by a larger amount</li>
- * <li>a <em>thumb</em> for modifying the value by mouse dragging</li>
- * <li>a page increment area for incrementing the value by a larger amount</li>
- * <li>an arrow button for incrementing the value</li>
- * </ol>
- * Based on their style, sliders are either <code>HORIZONTAL</code>
- * (which have a left facing button for decrementing the value and a
- * right facing button for incrementing it) or <code>VERTICAL</code>
- * (which have an upward facing button for decrementing the value
- * and a downward facing buttons for incrementing it).
- * </p><p>
- * On some platforms, the size of the slider's thumb can be
- * varied relative to the magnitude of the range of values it
- * represents (that is, relative to the difference between its
- * maximum and minimum values). Typically, this is used to
- * indicate some proportional value such as the ratio of the
- * visible area of a document to the total amount of space that
- * it would take to display it. SWT supports setting the thumb
- * size even if the underlying platform does not, but in this
- * case the appearance of the slider will not change.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see ScrollBar
- * @see <a href="http://www.eclipse.org/swt/snippets/#slider">Slider snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Slider extends Control {
- boolean dragSent = false;
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Slider (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values:
- * <code>SWT.NONE</code> - for the end of a drag.
- * <code>SWT.DRAG</code>.
- * <code>SWT.HOME</code>.
- * <code>SWT.END</code>.
- * <code>SWT.ARROW_DOWN</code>.
- * <code>SWT.ARROW_UP</code>.
- * <code>SWT.PAGE_DOWN</code>.
- * <code>SWT.PAGE_UP</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- int hScroll = display.scrolledMarginX;
- int vScroll = display.scrolledMarginY;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += hScroll * 10;
- height += vScroll;
- } else {
- width += hScroll;
- height += vScroll * 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-void createHandle (int index) {
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNhighlightThickness, display.textHighlightThickness,
- OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0,
- OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL,
- OS.XmNtraversalOn, 1,
- };
- int parentHandle = parent.handle;
- handle = OS.XmCreateScrollBar (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget();
- int [] argList = {OS.XmNincrement, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget();
- int [] argList = {OS.XmNmaximum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget();
- int [] argList = {OS.XmNminimum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget();
- int [] argList = {OS.XmNpageIncrement, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the 'selection', which is the receiver's value.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget();
- int [] argList = {OS.XmNvalue, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values.
- *
- * @return the thumb value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getThumb () {
- checkWidget();
- int [] argList = {OS.XmNsliderSize, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, DRAG_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNtoBottomCallback, windowProc, TO_BOTTOM_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNtoTopCallback, windowProc, TO_TOP_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNincrementCallback, windowProc, INCREMENT_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNdecrementCallback, windowProc, DECREMENT_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNpageIncrementCallback, windowProc, PAGE_INCREMENT_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNpageDecrementCallback, windowProc, PAGE_DECREMENT_CALLBACK);
-}
-void overrideTranslations () {
- OS.XtOverrideTranslations (handle, display.tabTranslations);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-void sendScrollEvent (int detail) {
- Event event = new Event ();
- event.detail = detail;
- postEvent (SWT.Selection, event);
-}
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- int [] argList = {OS.XmNincrement, value};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * Sets the maximum. If this value is negative or less than or
- * equal to the minimum, the value is ignored. If necessary, first
- * the thumb and then the selection are adjusted to fit within the
- * new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget();
- if (value < 0) return;
- int [] argList = {OS.XmNmaximum, value};
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the minimum value. If this value is negative or greater
- * than or equal to the maximum, the value is ignored. If necessary,
- * first the thumb and then the selection are adjusted to fit within
- * the new range.
- *
- * @param value the new minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget();
- if (value < 0) return;
- int [] argList = {
- OS.XmNminimum, 0,
- OS.XmNmaximum, 0,
- OS.XmNsliderSize, 0,
- };
- /*
- * Feature in Motif. For some reason, when minimium
- * is set to be greater than or equal to maximum, Motif
- * does not set the minimum. Instead, the value is
- * changed and the minimum stays the same. This behavior
- * differs from setting the maximum where the slider size
- * is always decreased to make room for the new maximum.
- * The fix is to decrease the slider to make room for
- * the new minimum.
- */
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [3] - value - argList [5] < 0) {
- argList [5] = argList [3] - value;
- }
- argList [1] = value;
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- int [] argList = {OS.XmNpageIncrement, value};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * Sets the 'selection', which is the receiver's
- * value, to the argument which must be greater than or equal
- * to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget();
- int [] argList = {OS.XmNvalue, value};
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values. This new
- * value will be ignored if it is less than one, and will be
- * clamped if it exceeds the receiver's current range.
- *
- * @param value the new thumb value, which must be at least one and not
- * larger than the size of the current range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setThumb (int value) {
- checkWidget();
- if (value < 1) return;
- int [] argList = {OS.XmNminimum, 0, OS.XmNmaximum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- value = Math.min (value, argList [3] - argList [1]);
- int [] argList2 = {OS.XmNsliderSize, value};
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, thumb, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param thumb the new thumb value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- checkWidget();
- if (minimum < 0) return;
- if (maximum < 0) return;
- if (thumb < 1) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- thumb = Math.min (thumb, maximum - minimum);
- int [] argList = {
- OS.XmNvalue, selection,
- OS.XmNminimum, minimum,
- OS.XmNmaximum, maximum,
- OS.XmNsliderSize, thumb,
- OS.XmNincrement, increment,
- OS.XmNpageIncrement, pageIncrement,
- };
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XButtonPress (w, client_data, call_data, continue_to_dispatch);
- if (result != 0) return result;
- dragSent = false;
- return result;
-}
-int XmNdecrementCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.ARROW_UP);
- return 0;
-}
-int XmNdragCallback (int w, int client_data, int call_data) {
- dragSent = true;
- sendScrollEvent (SWT.DRAG);
- return 0;
-}
-int XmNincrementCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.ARROW_DOWN);
- return 0;
-}
-int XmNpageDecrementCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.PAGE_UP);
- return 0;
-}
-int XmNpageIncrementCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.PAGE_DOWN);
- return 0;
-}
-int XmNtoBottomCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.END);
- return 0;
-}
-int XmNtoTopCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.HOME);
- return 0;
-}
-int XmNvalueChangedCallback (int w, int client_data, int call_data) {
- if (!dragSent){
- sendScrollEvent (SWT.DRAG);
- dragSent = false;
- }
- sendScrollEvent (SWT.NONE);
- return 0;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Spinner.java
deleted file mode 100644
index f81af4c4ea..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Spinner.java
+++ /dev/null
@@ -1,1039 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify numeric
- * values.
- * <p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, Modify, Verify</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#spinner">Spinner snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Spinner extends Composite {
- /**
- * the operating system limit for the number of characters
- * that the text field in an instance of this class can hold
- *
- * @since 3.4
- */
- public static final int LIMIT;
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0x7FFFFFFF;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#READ_ONLY
- * @see SWT#WRAP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Spinner (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is not called for texts.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- */
-void addVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-static int checkStyle (int style) {
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- int width = wHint;
- int height = hHint;
- if (wHint == SWT.DEFAULT) {
- width = DEFAULT_WIDTH;
- int [] argList = {
- OS.XmNmaximumValue, 0,
- OS.XmNdecimalPoints, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- String string = String.valueOf (argList [1]);
- if (argList [3] > 0) {
- StringBuffer buffer = new StringBuffer ();
- buffer.append (string);
- buffer.append (getDecimalSeparator ());
- int count = argList [3] - string.length ();
- while (count >= 0) {
- buffer.append ("0");
- count--;
- }
- string = buffer.toString ();
- }
- byte [] buffer = Converter.wcsToMbcs (getCodePage(), string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- int fontList = font.handle;
- width = OS.XmStringWidth (fontList, xmString);
- OS.XmStringFree (xmString);
- }
- if (hHint == SWT.DEFAULT) {
- height = getFontHeight (font.handle);
- }
- Rectangle trim = computeTrim (0, 0, width, height);
- if (hHint == SWT.DEFAULT) {
- int [] argList = {OS.XmNarrowSize, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- trim.height = Math.max (trim.height, argList [1] * 2);
- }
- return new Point (trim.width, trim.height);
-}
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
- int [] argList1 = {
- OS.XmNtextField, 0,
- OS.XmNarrowSize, 0,
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int [] argList2 = {
- OS.XmNshadowThickness, 0,
- OS.XmNhighlightThickness, 0};
- OS.XtGetValues (argList1 [1], argList2, argList2.length / 2);
- XRectangle rect = new XRectangle ();
- OS.XmWidgetGetDisplayRect (argList1 [1], rect);
- x -= argList1 [5] + argList2 [1] + argList2 [3] + rect.x;
- y -= argList1 [7] + argList2 [1] + argList2 [3] + rect.y;
- width += (argList1 [5] + argList2 [1] + argList2 [3] + rect.x) * 2 + argList1 [3];
- height += (argList1 [7] + argList2 [1] + argList2 [3] + rect.y) * 2;
- return new Rectangle (x, y, width, height);
-}
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void copy () {
- checkWidget ();
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmTextCopy (argList [1], OS.XtLastTimestampProcessed (xDisplay));
-}
-void createHandle (int index) {
- int [] argList1 = {
- OS.XmNcolumns, 2,
- OS.XmNdecimalPoints, 0,
- OS.XmNincrementValue, 1,
- OS.XmNminimumValue, 0,
- OS.XmNmaximumValue, 100,
- OS.XmNspinBoxChildType, OS.XmNUMERIC,
- OS.XmNeditable, (style & SWT.READ_ONLY) != 0 ? 0 : 1,
- OS.XmNshadowThickness, 0,
- OS.XmNancestorSensitive, 1,
- };
- int parentHandle = parent.handle;
- handle = OS.XmCreateSimpleSpinBox (parentHandle, null, argList1, argList1.length / 2);
- int [] argList2 = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList2, argList2.length / 2);
- int textHandle = argList2 [1];
- int [] argList3 = {
- OS.XmNverifyBell, 0,
- OS.XmNcursorPositionVisible, (style & SWT.READ_ONLY) != 0 ? 0 : 1,
- };
- OS.XtSetValues (textHandle, argList3, argList3.length / 2);
- if ((style & SWT.BORDER) == 0) {
- int [] argList4 = new int [] {
- /*
- * Bug in Motif. Setting the margin width to zero for
- * a single line text field causes the field to draw
- * garbage when the caret is placed at the start of
- * the widget. The fix is to not set the margin width.
- */
-// OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0,
- OS.XmNshadowThickness, 0,
- };
- OS.XtSetValues (textHandle, argList4, argList4.length / 2);
- }
- /*
- * Feature in Motif. The Spinner widget is created with a default
- * drop target. This is inconsistent with other platforms.
- * To be consistent, disable the default drop target.
- */
- OS.XmDropSiteUnregister (textHandle);
-}
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void cut () {
- checkWidget ();
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmTextCut (argList [1], OS.XtLastTimestampProcessed (xDisplay));
-}
-void deregister () {
- super.deregister ();
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- display.removeWidget (argList[1]);
-}
-int fontHandle () {
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the number of decimal places used by the receiver.
- *
- * @return the digits
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getDigits () {
- checkWidget ();
- int [] argList = {OS.XmNdecimalPoints, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-String getDecimalSeparator () {
- int ptr = OS.localeconv_decimal_point ();
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, length);
- return new String (Converter.mbcsToWcs (null, buffer));
-}
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down arrows are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget ();
- int [] argList = {OS.XmNincrementValue, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget ();
- int [] argList = {OS.XmNmaximumValue, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget ();
- int [] argList = {OS.XmNminimumValue, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the amount that the receiver's position will be
- * modified by when the page up/down keys are pressed.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget ();
- return 1;
-}
-/**
- * Returns the <em>selection</em>, which is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget ();
- int [] argList = {OS.XmNposition, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns a string containing a copy of the contents of the
- * receiver's text field, or an empty string if there are no
- * contents.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public String getText () {
- checkWidget();
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
-
- int ptr = OS.XmTextGetString (argList[1]);
- if (ptr == 0) return "";
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, length);
- OS.XtFree (ptr);
- return new String (Converter.mbcsToWcs (getCodePage (), buffer));
-}
-/**
- * Returns the maximum number of characters that the receiver's
- * text field is capable of holding. If this has not been changed
- * by <code>setTextLimit()</code>, it will be the constant
- * <code>Spinner.LIMIT</code>.
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- *
- * @since 3.4
- */
-public int getTextLimit () {
- checkWidget();
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return OS.XmTextGetMaxLength (argList[1]);
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int textHandle = argList [1];
- OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNmodifyVerifyCallback, windowProc, MODIFY_VERIFY_CALLBACK);
- OS.XtAddCallback (textHandle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK);
- OS.XtAddCallback (textHandle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
- OS.XtAddCallback (textHandle, OS.XmNmodifyVerifyCallback, windowProc, MODIFY_VERIFY_CALLBACK);
- OS.XtAddEventHandler (textHandle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS);
- OS.XtAddEventHandler (textHandle, OS.ButtonReleaseMask, false, windowProc, BUTTON_RELEASE);
- OS.XtAddEventHandler (textHandle, OS.EnterWindowMask, false, windowProc, ENTER_WINDOW);
- OS.XtAddEventHandler (textHandle, OS.LeaveWindowMask, false, windowProc, LEAVE_WINDOW);
- OS.XtAddEventHandler (textHandle, OS.KeyPressMask, false, windowProc, KEY_PRESS);
- OS.XtAddEventHandler (textHandle, OS.KeyReleaseMask, false, windowProc, KEY_RELEASE);
- OS.XtInsertEventHandler (textHandle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail);
-}
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void paste () {
- checkWidget ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmTextFieldPaste (argList [1]);
- display.setWarnings (warnings);
-}
-void register () {
- super.register ();
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- display.addWidget (argList [1], this);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- */
-void removeVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- int [] argList1 = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int textHandle = argList1 [1];
- int [] argList2 = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0};
- OS.XtGetValues (textHandle, argList2, argList2.length / 2);
- OS.XmChangeColor (textHandle, pixel);
- OS.XtSetValues (textHandle, argList2, argList2.length / 2);
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- /*
- * Feature in Motif. Setting the bounds of a XmSimpleSpinBox
- * does not update the size of the inner XmTextFied. The fix
- * is to update its size programmatically.
- */
- if (resize) {
- int [] argList1 = {
- OS.XmNtextField, 0,
- OS.XmNarrowSize, 0,
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (argList1 [1], argList2, argList2.length / 2);
- int textWidth = Math.max (width - argList1 [3] - 2 * argList1 [5], 0);
- int textHeight = Math.max (height - 2 * argList1 [7], 0);
- if (textWidth != argList2 [1] || textHeight != argList2 [3]) {
- OS.XtResizeWidget (argList1 [1], textWidth, textHeight, argList2 [5]);
- }
- }
- return super.setBounds (x, y, width, height, move, resize);
-}
-/**
- * Sets the number of decimal places used by the receiver.
- * <p>
- * The digit setting is used to allow for floating point values in the receiver.
- * For example, to set the selection to a floating point value of 1.37 call setDigits() with
- * a value of 2 and setSelection() with a value of 137. Similarly, if getDigits() has a value
- * of 2 and getSelection() returns 137 this should be interpreted as 1.37. This applies to all
- * numeric APIs.
- * </p>
- *
- * @param value the new digits (must be greater than or equal to zero)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the value is less than zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDigits (int value) {
- checkWidget ();
- if (value < 0) error (SWT.ERROR_INVALID_ARGUMENT);
- int [] argList1 = {OS.XmNposition, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int [] argList2 = {OS.XmNdecimalPoints, value, OS.XmNposition, argList1 [1]};
- OS.XtSetValues (handle, argList2, argList2.length / 2);
-}
-void setForegroundPixel (int pixel) {
- int [] argList1 = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int [] argList2 = {OS.XmNforeground, pixel};
- OS.XtSetValues (argList1 [1], argList2, argList2.length / 2);
- super.setForegroundPixel (pixel);
-}
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down arrows are pressed to
- * the argument, which must be at least one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- int [] argList = {OS.XmNincrementValue, value};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget ();
- int [] argList1 = {OS.XmNminimumValue, 0, OS.XmNposition, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- if (value <= argList1 [1]) return;
- int position = argList1 [3];
- if (value < position) position = value;
- int [] argList2 = {OS.XmNposition, position, OS.XmNmaximumValue, value};
- OS.XtSetValues (handle, argList2, argList2.length / 2);
-}
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget ();
- int [] argList1 = {OS.XmNmaximumValue, 0, OS.XmNposition, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- if (value >= argList1 [1]) return;
- int position = argList1 [3];
- if (value > position) position = value;
- int [] argList2 = {OS.XmNposition, position, OS.XmNminimumValue, value};
- OS.XtSetValues (handle, argList2, argList2.length / 2);
-}
-/**
- * Sets the amount that the receiver's position will be
- * modified by when the page up/down keys are pressed
- * to the argument, which must be at least one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
-}
-/**
- * Sets the <em>selection</em>, which is the receiver's
- * position, to the argument. If the argument is not within
- * the range specified by minimum and maximum, it will be
- * adjusted to fall within this range.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget ();
- int [] argList = {OS.XmNmaximumValue, 0, OS.XmNminimumValue, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- value = Math.min (Math.max (argList [3], value), argList [1]);
- int [] argList1 = {OS.XmNposition, value};
- OS.XtSetValues (handle, argList1, argList1.length / 2);
-}
-/**
- * Sets the maximum number of characters that the receiver's
- * text field is capable of holding to be the argument.
- * <p>
- * To reset this value to the default, use <code>setTextLimit(Spinner.LIMIT)</code>.
- * Specifying a limit value larger than <code>Spinner.LIMIT</code> sets the
- * receiver's limit to <code>Spinner.LIMIT</code>.
- * </p>
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- *
- * @since 3.4
- */
-public void setTextLimit (int limit) {
- checkWidget();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmTextSetMaxLength (argList[1], limit);
-}
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, digits, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param digits the new digits value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setValues (int selection, int minimum, int maximum, int digits, int increment, int pageIncrement) {
- checkWidget ();
- if (maximum <= minimum) return;
- if (digits < 0) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- selection = Math.min (Math.max (minimum, selection), maximum);
- int [] argList = {
- OS.XmNposition, selection,
- OS.XmNmaximumValue, maximum,
- OS.XmNminimumValue, minimum,
- OS.XmNincrementValue, increment,
- OS.XmNdecimalPoints, digits};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-
-void updateText () {
- int [] argList = {
- OS.XmNtextField, 0, /* 1 */
- OS.XmNminimumValue, 0, /* 3 */
- OS.XmNmaximumValue, 0, /* 5 */
- OS.XmNposition, 0, /* 7 */
- OS.XmNdecimalPoints, 0 /* 9 */};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int ptr = OS.XmTextGetString (argList [1]);
- int position = argList [7];
- int digits = argList [9];
- if (ptr != 0) {
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, length);
- OS.XtFree (ptr);
- String string = new String (Converter.mbcsToWcs (getCodePage (), buffer));
- try {
- int value;
- if (digits > 0) {
- String decimalSeparator = getDecimalSeparator ();
- int index = string.indexOf (decimalSeparator);
- if (index != -1) {
- int startIndex = string.startsWith ("+") || string.startsWith ("-") ? 1 : 0;
- String wholePart = startIndex != index ? string.substring (startIndex, index) : "0";
- String decimalPart = string.substring (index + 1);
- if (decimalPart.length () > digits) {
- decimalPart = decimalPart.substring (0, digits);
- } else {
- int i = digits - decimalPart.length ();
- for (int j = 0; j < i; j++) {
- decimalPart = decimalPart + "0";
- }
- }
- int wholeValue = Integer.parseInt (wholePart);
- int decimalValue = Integer.parseInt (decimalPart);
- for (int i = 0; i < digits; i++) wholeValue *= 10;
- value = wholeValue + decimalValue;
- if (string.startsWith ("-")) value = -value;
- } else {
- value = Integer.parseInt (string);
- for (int i = 0; i < digits; i++) value *= 10;
- }
- } else {
- value = Integer.parseInt (string);
- }
- if (argList [3] <= value && value <= argList [5]) {
- position = value;
- }
- } catch (NumberFormatException e) {
- }
- }
- if (position == argList [7]) {
- String string;
- if (digits == 0) {
- string = String.valueOf (position);
- } else {
- string = String.valueOf (Math.abs (position));
- String decimalSeparator = getDecimalSeparator ();
- int index = string.length () - digits;
- StringBuffer buffer = new StringBuffer ();
- if (position < 0) buffer.append ("-");
- if (index > 0) {
- buffer.append (string.substring (0, index));
- buffer.append (decimalSeparator);
- buffer.append (string.substring (index));
- } else {
- buffer.append ("0");
- buffer.append (decimalSeparator);
- while (index++ < 0) buffer.append ("0");
- buffer.append (string);
- }
- string = buffer.toString ();
- }
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetString (argList [1], buffer);
- display.setWarnings (warnings);
- } else {
- int [] argList2 = {OS.XmNposition, position};
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- }
-}
-int XmNactivateCallback (int w, int client_data, int call_data) {
- postEvent (SWT.DefaultSelection);
- updateText ();
- return 0;
-}
-int xFocusOut (XFocusChangeEvent xEvent) {
- updateText ();
- return super.xFocusOut (xEvent);
-}
-int XmNmodifyVerifyCallback (int w, int client_data, int call_data) {
- if (w == handle) {
- if ((style & SWT.WRAP) == 0) {
- XmSpinBoxCallbackStruct struct = new XmSpinBoxCallbackStruct ();
- OS.memmove (struct, call_data, XmSpinBoxCallbackStruct.sizeof);
- if (struct.crossed_boundary != 0) {
- struct.doit = (byte) 0;
- OS.memmove (call_data, struct, XmSpinBoxCallbackStruct.sizeof);
- }
- }
- return 0;
- }
- int result = super.XmNmodifyVerifyCallback (w, client_data, call_data);
- if (result != 0) return result;
-
- /*
- * Feature in Motif. When XtManageChild() is called for
- * a text widget that has just been created, the contents
- * are assigned and an XmNmodifyVerifyCallback is sent.
- * When this happens, the widget has not been fully
- * initialized null pointer exceptions can occur. The
- * fix is to check for this case and avoid the callback.
- * Note that application code could never have seen it
- * in the first place.
- */
- if (font == null) return result;
-
-// if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return result;
- XmTextVerifyCallbackStruct textVerify = new XmTextVerifyCallbackStruct ();
- OS.memmove (textVerify, call_data, XmTextVerifyCallbackStruct.sizeof);
- XmTextBlockRec textBlock = new XmTextBlockRec ();
- OS.memmove (textBlock, textVerify.text, XmTextBlockRec.sizeof);
- byte [] buffer = new byte [textBlock.length];
- OS.memmove (buffer, textBlock.ptr, textBlock.length);
- String codePage = getCodePage ();
- String text = new String (Converter.mbcsToWcs (codePage, buffer));
- Event event = new Event ();
- if (textVerify.event != 0) {
- XKeyEvent xEvent = new XKeyEvent ();
- OS.memmove (xEvent, textVerify.event, XKeyEvent.sizeof);
- event.time = xEvent.time;
- setKeyState (event, xEvent);
- }
- event.start = textVerify.startPos;
- event.end = textVerify.endPos;
- event.text = text;
- String string = text;
- int index = 0;
- int [] argList = {OS.XmNdecimalPoints, 0, OS.XmNminimumValue, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] > 0) {
- String decimalSeparator = getDecimalSeparator ();
- index = string.indexOf (decimalSeparator);
- if (index != -1) {
- string = string.substring (0, index) + string.substring (index + 1);
- }
- index = 0;
- }
- if (string.length () > 0) {
- if (argList [3] < 0 && string.charAt (0) == '-') index++;
- }
- while (index < string.length ()) {
- if (!Character.isDigit (string.charAt (index))) break;
- index++;
- }
- event.doit = index == string.length ();
- sendEvent (SWT.Verify, event);
- String newText = event.text;
- textVerify.doit = (byte) ((event.doit && newText != null) ? 1 : 0);
- if (newText != null && newText != text) {
- OS.XtFree(textBlock.ptr);
- byte [] buffer2 = Converter.wcsToMbcs (codePage, newText, true);
- int length = buffer2.length;
- int ptr = OS.XtMalloc (length);
- OS.memmove (ptr, buffer2, length);
- textBlock.ptr = ptr;
- textBlock.length = buffer2.length - 1;
- OS.memmove (textVerify.text, textBlock, XmTextBlockRec.sizeof);
- }
- OS.memmove (call_data, textVerify, XmTextVerifyCallbackStruct.sizeof);
- return result;
-}
-int XmNvalueChangedCallback (int w, int client_data, int call_data) {
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (w == argList [1]) {
- sendEvent (SWT.Modify);
- } else {
- XmAnyCallbackStruct struct = new XmAnyCallbackStruct ();
- OS.memmove (struct, call_data, XmAnyCallbackStruct.sizeof);
- if (struct.reason == OS.XmCR_OK) {
- postEvent (SWT.Selection);
- }
- }
- return 0;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java
deleted file mode 100755
index bb1201790a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java
+++ /dev/null
@@ -1,1739 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify text.
- * Text controls can be either single or multi-line.
- * When a text control is created with a border, the
- * operating system includes a platform specific inset
- * around the contents of the control. When created
- * without a border, an effort is made to remove the
- * inset such that the preferred size of the control
- * is the same size as the contents.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>CENTER, ICON_CANCEL, ICON_SEARCH, LEFT, MULTI, PASSWORD, SEARCH, SINGLE, RIGHT, READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Modify, Verify</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles MULTI and SINGLE may be specified,
- * and only one of the styles LEFT, CENTER, and RIGHT may be specified.
- * </p>
- * <p>
- * Note: The styles ICON_CANCEL and ICON_SEARCH are hints used in combination with SEARCH.
- * When the platform supports the hint, the text control shows these icons. When an icon
- * is selected, a default selection event is sent with the detail field set to one of
- * ICON_CANCEL or ICON_SEARCH. Normally, application code does not need to check the
- * detail. In the case of ICON_CANCEL, the text is cleared before the default selection
- * event is sent causing the application to search for an empty string.
- * </p>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#text">Text snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Text extends Scrollable {
- char echoCharacter;
- boolean ignoreChange;
- String hiddenText, message;
- int drawCount;
- Color disabledColor;
-
- static final boolean IsGB18030;
- /**
- * The maximum number of characters that can be entered
- * into a text widget.
- * <p>
- * Note that this value is platform dependent, based upon
- * the native widget implementation.
- * </p>
- */
- public static final int LIMIT;
- /**
- * The delimiter used by multi-line text widgets. When text
- * is queried and from the widget, it will be delimited using
- * this delimiter.
- */
- public static final String DELIMITER;
-
- static final RGB MSG_FOREGROUND = new RGB (172, 168, 153);
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0x7FFFFFFF;
- DELIMITER = "\n";
- IsGB18030 = Converter.defaultCodePage ().endsWith ("18030");
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#READ_ONLY
- * @see SWT#WRAP
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see SWT#PASSWORD
- * @see SWT#SEARCH
- * @see SWT#ICON_SEARCH
- * @see SWT#ICON_CANCEL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Text (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is not called for texts.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text,
- * or when ENTER is pressed in a search text. If the receiver has the <code>SWT.SEARCH | SWT.CANCEL</code> style
- * and the user cancels the search, the event object detail field contains the value <code>SWT.CANCEL</code>.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- */
-public void addVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-/**
- * Appends a string.
- * <p>
- * The new text is appended to the text at
- * the end of the widget.
- * </p>
- *
- * @param string the string to be appended
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void append (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int position = OS.XmTextGetLastPosition (handle);
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetInsertionPosition (handle, position);
- OS.XmTextInsert (handle, position, buffer);
- position = OS.XmTextGetLastPosition (handle);
- OS.XmTextSetInsertionPosition (handle, position);
- display.setWarnings(warnings);
-}
-static int checkStyle (int style) {
- if ((style & SWT.SEARCH) != 0) {
- style |= SWT.SINGLE | SWT.BORDER;
- style &= ~SWT.PASSWORD;
- /*
- * NOTE: ICON_CANCEL has the same value as H_SCROLL and
- * ICON_SEARCH has the same value as V_SCROLL so they are
- * cleared because SWT.SINGLE is set.
- */
- }
- if ((style & SWT.SINGLE) != 0 && (style & SWT.MULTI) != 0) {
- style &= ~SWT.MULTI;
- }
- style = checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
- if ((style & SWT.SINGLE) != 0) style &= ~(SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP);
- if ((style & SWT.WRAP) != 0) {
- style |= SWT.MULTI;
- style &= ~SWT.H_SCROLL;
- }
- if ((style & SWT.MULTI) != 0) style &= ~SWT.PASSWORD;
- if ((style & (SWT.SINGLE | SWT.MULTI)) != 0) return style;
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) return style | SWT.MULTI;
- return style | SWT.SINGLE;
-}
-/**
- * Clears the selection.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void clearSelection () {
- checkWidget();
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- OS.XmTextClearSelection (handle, OS.XtLastTimestampProcessed (xDisplay));
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = wHint;
- int height = hHint;
- if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
- int ptr = OS.XmTextGetString (handle);
- if (ptr == 0) return new Point (0, 0);
- int size = OS.strlen (ptr);
- if (size == 0) {
- if (hHint == SWT.DEFAULT) {
- if ((style & SWT.SINGLE) != 0) {
- height = getLineHeight ();
- } else {
- height = DEFAULT_HEIGHT;
- }
- }
- if (wHint == SWT.DEFAULT) {
- width = DEFAULT_WIDTH;
- }
- } else {
- byte [] buffer = new byte [size + 1];
- OS.memmove (buffer, ptr, size);
- boolean wrap = (style & SWT.MULTI) != 0 && (style & SWT.WRAP) != 0;
- if (wrap && wHint != SWT.DEFAULT) {
- char[] chars = Converter.mbcsToWcs (getCodePage (), buffer);
- String text = new String (chars);
- String wrapped = display.wrapText (text, font, wHint);
- buffer = Converter.wcsToMbcs (getCodePage (), wrapped, true);
- }
- int xmString;
- if ((style & SWT.SINGLE) != 0) {
- xmString = OS.XmStringParseText (
- buffer,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- } else {
- xmString = OS.XmStringGenerate (
- buffer,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null);
- }
- int fontList = font.handle;
- if (hHint == SWT.DEFAULT) {
- if ((style & SWT.SINGLE) != 0) {
- height = getLineHeight ();
- } else {
- height = OS.XmStringHeight (fontList, xmString);
- }
- }
- if (wHint == SWT.DEFAULT) width = OS.XmStringWidth (fontList, xmString);
- OS.XmStringFree (xmString);
- }
- OS.XtFree (ptr);
- if ((style & SWT.SINGLE) != 0 && message.length () > 0) {
- if (wHint == SWT.DEFAULT) {
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), message, true);
- int xmString = OS.XmStringGenerate (
- buffer,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null);
- int fontList = font.handle;
- width = Math.max (width, OS.XmStringWidth (fontList, xmString));
- OS.XmStringFree (xmString);
- }
- }
- }
- Rectangle trim = computeTrim (0, 0, width, height);
- return new Point (trim.width, trim.height);
-}
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- if (horizontalBar != null) {
- int [] argList1 = {OS.XmNheight, 0};
- OS.XtGetValues (horizontalBar.handle, argList1, argList1.length / 2);
- height += argList1 [1] + 4;
- }
- if (verticalBar != null) {
- int [] argList1 = {OS.XmNwidth, 0};
- OS.XtGetValues (verticalBar.handle, argList1, argList1.length / 2);
- width += argList1 [1] + 4;
- }
- if ((style & SWT.MULTI) != 0) height+=4;
- XRectangle rect = new XRectangle ();
- OS.XmWidgetGetDisplayRect (handle, rect);
- x -= rect.x;
- y -= rect.y;
- width += rect.x * 2;
- height += rect.y * 2;
- int shadow = 0, highlight = 0;
- if ((style & SWT.MULTI) != 0 || (style & SWT.BORDER) != 0) {
- int [] argList = new int [] {
- OS.XmNshadowThickness, 0,
- OS.XmNhighlightThickness, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- shadow = argList [1];
- highlight = argList [3];
- }
- x -= shadow + highlight;
- y -= shadow + highlight;
- width += (shadow + highlight) * 2;
- height += (shadow + highlight) * 2;
- return new Rectangle (x, y, width, height);
-}
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void copy () {
- checkWidget();
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- OS.XmTextCopy (handle, OS.XtLastTimestampProcessed (xDisplay));
-}
-void createHandle (int index) {
- int [] argList1 = {
- OS.XmNverifyBell, 0,
- OS.XmNeditMode, (style & SWT.SINGLE) != 0 ? OS.XmSINGLE_LINE_EDIT : OS.XmMULTI_LINE_EDIT,
- OS.XmNscrollHorizontal, (style & SWT.H_SCROLL) != 0 ? 1 : 0,
- OS.XmNscrollVertical, (style & SWT.V_SCROLL) != 0 ? 1 : 0,
- OS.XmNwordWrap, !IsGB18030 && (style & SWT.WRAP) != 0 ? 1: 0,
- OS.XmNeditable, (style & SWT.READ_ONLY) != 0 ? 0 : 1,
- OS.XmNcursorPositionVisible, (style & SWT.READ_ONLY) != 0 ? 0 : 1,
-// OS.XmNmarginWidth, 3,
-// OS.XmNmarginHeight, 1,
- OS.XmNancestorSensitive, 1,
- };
- int parentHandle = parent.handle;
- if ((style & SWT.SINGLE) != 0) {
- handle = OS.XmCreateTextField (parentHandle, null, argList1, argList1.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- int [] argList2 = new int [] {OS.XmNcursorPositionVisible, 0};
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- } else {
- handle = OS.XmCreateScrolledText (parentHandle, new byte [1], argList1, argList1.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- scrolledHandle = OS.XtParent (handle);
- }
- if ((style & SWT.BORDER) == 0) {
- int [] argList3 = new int [] {
- /*
- * Bug in Motif. Setting the margin width to zero for
- * a single line text field causes the field to draw
- * garbage when the caret is placed at the start of
- * the widget. The fix is to not set the margin width.
- */
-// OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0,
- OS.XmNshadowThickness, 0,
- };
- OS.XtSetValues (handle, argList3, argList3.length / 2);
- }
- /*
- * Feature in Motif. The Text widget is created with a default
- * drop target. This is inconsistent with other platforms.
- * To be consistent, disable the default drop target.
- */
- OS.XmDropSiteUnregister (handle);
-}
-ScrollBar createScrollBar (int type) {
- return createStandardBar (type);
-}
-void createWidget (int index) {
- super.createWidget (index);
- hiddenText = message = "";
- if ((style & SWT.PASSWORD) != 0) setEchoChar ('*');
- if ((style & SWT.SINGLE) != 0) {
- disabledColor = new Color (display, MSG_FOREGROUND);
- }
-}
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void cut () {
- checkWidget();
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- OS.XmTextCut (handle, OS.XtLastTimestampProcessed (xDisplay));
-}
-int defaultBackground () {
- return display.textBackground;
-}
-Font defaultFont () {
- return display.textFont;
-}
-int defaultForeground () {
- return display.textForeground;
-}
-boolean dragDetect (int x, int y, boolean filter, boolean [] consume) {
- if (filter) {
- int [] start = new int [1], end = new int [1];
- OS.XmTextGetSelectionPosition (handle, start, end);
- if (start [0] != end [0]) {
- int pos = OS.XmTextXYToPos(handle, (short) x, (short) y);
- if (start [0] <= pos && pos < end [0]) {
- if (super.dragDetect (x, y, filter, consume)) {
- if (consume != null) consume [0] = true;
- return true;
- }
- }
- }
- return false;
- }
- return super.dragDetect (x, y, filter, consume);
-}
-/**
- * Returns the line number of the caret.
- * <p>
- * The line number of the caret is returned.
- * </p>
- *
- * @return the line number
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretLineNumber () {
- checkWidget();
- return getLineNumber (OS.XmTextGetInsertionPosition (handle));
-}
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null).
- * <p>
- * The location of the caret is returned.
- * </p>
- *
- * @return a point, the location of the caret
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getCaretLocation () {
- checkWidget();
- int position;
- position = OS.XmTextGetInsertionPosition (handle);
- short [] x = new short [1], y = new short [1];
- OS.XmTextPosToXY (handle, position, x, y);
- return new Point (x [0], y [0] - getFontAscent (font.handle));
-}
-/**
- * Returns the character position of the caret.
- * <p>
- * Indexing is zero based.
- * </p>
- *
- * @return the position of the caret
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretPosition () {
- checkWidget();
- return OS.XmTextGetInsertionPosition (handle);
-}
-/**
- * Returns the number of characters.
- *
- * @return number of characters in the widget
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCharCount () {
- checkWidget();
- return OS.XmTextGetLastPosition (handle);
-}
-/**
- * Returns the double click enabled flag.
- * <p>
- * The double click flag enables or disables the
- * default action of the text widget when the user
- * double clicks.
- * </p>
- *
- * @return whether or not double click is enabled
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getDoubleClickEnabled () {
- checkWidget();
- int [] argList = {OS.XmNselectionArrayCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] != 1;
-}
-/**
- * Returns the echo character.
- * <p>
- * The echo character is the character that is
- * displayed when the user enters text or the
- * text is changed by the programmer.
- * </p>
- *
- * @return the echo character
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setEchoChar
- */
-public char getEchoChar () {
- checkWidget();
- return echoCharacter;
-}
-/**
- * Returns the editable state.
- *
- * @return whether or not the receiver is editable
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getEditable () {
- checkWidget();
- /*
- * Bug in MOTIF. For some reason, when XmTextGetEditable () is called
- * from inside an XmNvalueChangedCallback or XmNModifyVerifyCallback,
- * it always returns TRUE. Calls to XmTextGetEditable () outside of
- * these callbacks return the correct value. The fix is to query the
- * resource directly instead of using the convenience function.
- */
- int [] argList = {OS.XmNeditable, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] != 0;
-}
-/**
- * Returns the number of lines.
- *
- * @return the number of lines in the widget
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getLineCount () {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return 1;
- int lastChar = echoCharacter != '\0' ? hiddenText.length () : OS.XmTextGetLastPosition (handle);
- return getLineNumber (lastChar) + 1;
-}
-/**
- * Returns the line delimiter.
- *
- * @return a string that is the line delimiter
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #DELIMITER
- */
-public String getLineDelimiter () {
- checkWidget();
- return "\n";
-}
-/**
- * Returns the height of a line.
- *
- * @return the height of a row of text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getLineHeight () {
- checkWidget();
- return getFontHeight (font.handle);
-}
-int getLineNumber (int position) {
- if (position == 0) return 0;
- int count = 0, start = 0, page = 1024;
- char [] buffer = new char [page + 1];
- /*
- * Bug in Linux. For some reason, XmTextGetSubstringWcs () does
- * not copy wchar_t characters into the buffer. Instead, it
- * copies 4 bytes per character. This does not happen on other
- * platforms such as AIX. The fix is to call XmTextGetSubstring ()
- * instead on Linux and rely on the fact that Metrolink Motif 1.2
- * does not support multibyte locales.
- */
- byte [] buffer1 = null;
- if (OS.IsLinux) buffer1 = new byte [page + 1];
- int end = ((position + page - 1) / page) * page;
- while (start < end) {
- int length = page;
- if (start + page > position) length = position - start;
- if (echoCharacter != '\0') {
- hiddenText.getChars (start, start + length, buffer, 0);
- } else {
- if (OS.IsLinux) {
- OS.XmTextGetSubstring (handle, start, length, buffer1.length, buffer1);
- for (int i=0; i<length; i++) buffer [i] = (char) buffer1 [i];
- } else {
- OS.XmTextGetSubstringWcs (handle, start, length, buffer.length, buffer);
- }
- }
- for (int i=0; i<length; i++) {
- if (buffer [i] == '\n') count++;
- }
- start += page;
- }
- return count;
-}
-/**
- * Returns the widget message. The message text is displayed
- * as a hint for the user, indicating the purpose of the field.
- * <p>
- * Typically this is used in conjunction with <code>SWT.SEARCH</code>.
- * </p>
- *
- * @return the widget message
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public String getMessage () {
- checkWidget ();
- return message;
-}
-int getNavigationType () {
- /*
- * Bug in Motif. On Solaris only, the implementation
- * of XtGetValues for XmText does not check for a zero
- * pointer in the arg list and GP's. The fix is to
- * allocate and free memory for the arg list value.
- */
- if ((style & SWT.SINGLE) != 0) {
- return super.getNavigationType ();
- }
- int ptr = OS.XtMalloc (4);
- if (ptr == 0) return OS.XmNONE;
- int [] argList = {OS.XmNnavigationType, ptr};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int [] buffer = new int [1];
- OS.memmove (buffer, ptr, 4);
- OS.XtFree (ptr);
- return buffer [0];
-}
-/**
- * Returns the orientation of the receiver, which will be one of the
- * constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getOrientation () {
- checkWidget();
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-/*public*/ int getPosition (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return OS.XmTextXYToPos(handle, (short) point.x, (short) point.y);
-}
-/**
- * Returns a <code>Point</code> whose x coordinate is the
- * character position representing the start of the selected
- * text, and whose y coordinate is the character position
- * representing the end of the selection. An "empty" selection
- * is indicated by the x and y coordinates having the same value.
- * <p>
- * Indexing is zero based. The range of a selection is from
- * 0..N where N is the number of characters in the widget.
- * </p>
- *
- * @return a point representing the selection start and end
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSelection () {
- checkWidget();
- int [] start = new int [1], end = new int [1];
- OS.XmTextGetSelectionPosition (handle, start, end);
- if (start [0] == end [0]) {
- start [0] = end [0] = OS.XmTextGetInsertionPosition (handle);
- }
- return new Point (start [0], end [0]);
-}
-/**
- * Returns the number of selected characters.
- *
- * @return the number of selected characters.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget();
- int [] start = new int [1], end = new int [1];
- OS.XmTextGetSelectionPosition (handle, start, end);
- return end [0] - start [0];
-}
-/**
- * Gets the selected text, or an empty string if there is no current selection.
- *
- * @return the selected text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getSelectionText () {
- checkWidget();
- if (echoCharacter != '\0') {
- Point selection = getSelection ();
- return getText (selection.x, selection.y);
- }
- int ptr = OS.XmTextGetSelection (handle);
- if (ptr == 0) return "";
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, length);
- OS.XtFree (ptr);
- return new String (Converter.mbcsToWcs (getCodePage (), buffer));
-}
-/**
- * Returns the number of tabs.
- * <p>
- * Tab stop spacing is specified in terms of the
- * space (' ') character. The width of a single
- * tab stop is the pixel width of the spaces.
- * </p>
- *
- * @return the number of tab characters
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTabs () {
- checkWidget();
- /* Tabs are not supported in MOTIF. */
- return 8;
-}
-/**
- * Returns the widget text.
- * <p>
- * The text for a text widget is the characters in the widget, or
- * an empty string if this has never been set.
- * </p>
- *
- * @return the widget text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- if (echoCharacter != '\0') return hiddenText;
- int ptr = OS.XmTextGetString (handle);
- if (ptr == 0) return "";
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, length);
- OS.XtFree (ptr);
- return new String (Converter.mbcsToWcs (getCodePage (), buffer));
-}
-/**
- * Returns a range of text. Returns an empty string if the
- * start of the range is greater than the end.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N-1 where N is
- * the number of characters in the widget.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- * @return the range of text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText (int start, int end) {
- checkWidget();
- if (!(start <= end && 0 <= end)) return "";
- boolean hasEcho = echoCharacter != '\0';
- int length = hasEcho ? hiddenText.length () : OS.XmTextGetLastPosition (handle);
- if (length == 0) return "";
- end = Math.min (end, length - 1);
- if (start > end) return "";
- start = Math.max (0, start);
- if (hasEcho) return hiddenText.substring (start, end + 1);
- int numChars = end - start + 1;
- int bufLength = numChars * OS.MB_CUR_MAX () + 1;
- byte [] buffer = new byte [bufLength];
- int code = OS.XmTextGetSubstring (handle, start, numChars, bufLength, buffer);
- switch (code) {
- case OS.XmCOPY_FAILED:
- case OS.XmCOPY_TRUNCATED:
- error (SWT.ERROR_CANNOT_GET_TEXT);
- }
- char [] unicode = Converter.mbcsToWcs (getCodePage (), buffer);
- return new String (unicode, 0, numChars);
-}
-/**
- * Returns the maximum number of characters that the receiver is capable of holding.
- * <p>
- * If this has not been changed by <code>setTextLimit()</code>,
- * it will be the constant <code>Text.LIMIT</code>.
- * </p>
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public int getTextLimit () {
- checkWidget();
- return OS.XmTextGetMaxLength (handle);
-}
-/**
- * Returns the zero-relative index of the line which is currently
- * at the top of the receiver.
- * <p>
- * This index can change when lines are scrolled or new lines are added or removed.
- * </p>
- *
- * @return the index of the top line
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return 0;
- if (scrolledHandle == 0) return 0;
- int [] argList1 = {OS.XmNverticalScrollBar, 0};
- OS.XtGetValues (scrolledHandle, argList1, argList1.length / 2);
- if (argList1 [1] == 0) return 0;
- int [] argList2 = {OS.XmNvalue, 0};
- OS.XtGetValues (argList1 [1], argList2, argList2.length / 2);
- return argList2 [1];
-}
-/**
- * Returns the top pixel.
- * <p>
- * The top pixel is the pixel position of the line
- * that is currently at the top of the widget. On
- * some platforms, a text widget can be scrolled by
- * pixels instead of lines so that a partial line
- * is displayed at the top of the widget.
- * </p><p>
- * The top pixel changes when the widget is scrolled.
- * The top pixel does not include the widget trimming.
- * </p>
- *
- * @return the pixel position of the top line
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopPixel () {
- checkWidget();
- return getTopIndex () * getLineHeight ();
-}
-boolean hasIMSupport() {
- return true;
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNmodifyVerifyCallback, windowProc, MODIFY_VERIFY_CALLBACK);
-}
-int inputContext () {
- /* Answer zero. The text widget uses the default MOTIF input context. */
- return 0;
-}
-/**
- * Inserts a string.
- * <p>
- * The old selection is replaced with the new text.
- * </p>
- *
- * @param string the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is <code>null</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void insert (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int [] start = new int [1], end = new int [1];
- OS.XmTextGetSelectionPosition (handle, start, end);
- if (start [0] == end [0]) {
- start [0] = end [0] = OS.XmTextGetInsertionPosition (handle);
- }
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextReplace (handle, start [0], end [0], buffer);
- int position = start [0] + Math.max (0, buffer.length - 1);
- OS.XmTextSetInsertionPosition (handle, position);
- display.setWarnings (warnings);
-}
-void overrideTranslations () {
- if ((style & SWT.SINGLE) != 0) {
- OS.XtOverrideTranslations (handle, display.tabTranslations);
- }
-}
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void paste () {
- checkWidget();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- /*
- * Bug in Motif. Despite the fact that the documentation
- * claims that XmText functions work for XmTextFields, when
- * a text field is passed to XmTextPaste, Motif segment faults.
- * The fix is to call XmTextFieldPaste instead.
- */
- if ((style & SWT.SINGLE) != 0) {
- OS.XmTextFieldPaste (handle);
- } else {
- OS.XmTextPaste (handle);
- }
- display.setWarnings (warnings);
-}
-void releaseWidget () {
- super.releaseWidget ();
- hiddenText = message = null;
- if (disabledColor != null) disabledColor.dispose ();
- disabledColor = null;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- */
-public void removeVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-boolean sendIMKeyEvent (int type, XKeyEvent xEvent) {
- return super.sendIMKeyEvent (type, xEvent, handle);
-}
-/**
- * Selects all the text in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget();
- /* Clear the highlight before setting the selection. */
- int position = OS.XmTextGetLastPosition (handle);
-// OS.XmTextSetHighlight (handle, 0, position, OS.XmHIGHLIGHT_NORMAL);
-
- /*
- * Bug in MOTIF. XmTextSetSelection () fails to set the
- * selection when the receiver is not realized. The fix
- * is to force the receiver to be realized by forcing the
- * shell to be realized. If the receiver is realized before
- * the shell, MOTIF fails to draw the text widget and issues
- * lots of X BadDrawable errors.
- */
- if (!OS.XtIsRealized (handle)) getShell ().realizeWidget ();
-
- /* Set the selection. */
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetSelection (handle, 0, position, OS.XtLastTimestampProcessed (xDisplay));
-
- /* Force the i-beam to follow the highlight/selection. */
- OS.XmTextSetInsertionPosition (handle, 0);
- display.setWarnings (warnings);
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- /*
- * Bug in Motif. For some reason an Xm warning is
- * output whenever a Text widget's caret is beyond
- * the visible region during a resize. The fix is
- * to temporarily turn off warnings below.
- */
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- boolean changed = super.setBounds (x, y, width, height, move, resize);
- display.setWarnings(warnings);
- return changed;
-}
-/**
- * Sets the double click enabled flag.
- * <p>
- * The double click flag enables or disables the
- * default action of the text widget when the user
- * double clicks.
- * </p><p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param doubleClick the new double click flag
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDoubleClickEnabled (boolean doubleClick) {
- checkWidget();
- int [] argList = {OS.XmNselectionArrayCount, doubleClick ? 4 : 1};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * Sets the echo character.
- * <p>
- * The echo character is the character that is
- * displayed when the user enters text or the
- * text is changed by the programmer. Setting
- * the echo character to '\0' clears the echo
- * character and redraws the original text.
- * If for any reason the echo character is invalid,
- * or if the platform does not allow modification
- * of the echo character, the default echo character
- * for the platform is used.
- * </p>
- *
- * @param echo the new echo character
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEchoChar (char echo) {
- checkWidget();
- if ((style & SWT.MULTI) != 0) return;
- if (echoCharacter == echo) return;
- String newText;
- if (echo == 0) {
- newText = hiddenText;
- hiddenText = "";
- } else {
- newText = hiddenText = getText();
- }
- echoCharacter = echo;
- Point selection = getSelection();
- boolean oldValue = ignoreChange;
- ignoreChange = true;
- setText(newText);
- setSelection(selection);
- ignoreChange = oldValue;
-}
-/**
- * Sets the editable state.
- *
- * @param editable the new editable state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEditable (boolean editable) {
- checkWidget();
- OS.XmTextSetEditable (handle, editable);
- style &= ~SWT.READ_ONLY;
- if (!editable) style |= SWT.READ_ONLY;
- if ((style & SWT.MULTI) != 0) return;
- int [] argList = {OS.XmNcursorPositionVisible, editable && hasFocus () ? 1 : 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * Sets the widget message. The message text is displayed
- * as a hint for the user, indicating the purpose of the field.
- * <p>
- * Typically this is used in conjunction with <code>SWT.SEARCH</code>.
- * </p>
- *
- * @param message the new message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the message is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public void setMessage (String message) {
- checkWidget ();
- if (message == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.message = message;
- redrawHandle (0, 0, 0, 0, true, handle);
-}
-/**
- * Sets the orientation of the receiver, which must be one
- * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public void setOrientation (int orientation) {
- checkWidget();
-}
-public void setRedraw (boolean redraw) {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return;
- if (redraw) {
- if (--drawCount == 0) OS.XmTextEnableRedisplay(handle);
- } else {
- if (drawCount++ == 0) OS.XmTextDisableRedisplay(handle);
- }
-}
-/**
- * Sets the selection.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * regular array indexing rules.
- * </p>
- *
- * @param start new caret position
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int start) {
- checkWidget();
- /* Clear the selection and highlight before moving the i-beam. */
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int position = OS.XmTextGetLastPosition (handle);
- int nStart = Math.min (Math.max (start, 0), position);
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
-// OS.XmTextSetHighlight (handle, 0, position, OS.XmHIGHLIGHT_NORMAL);
- OS.XmTextClearSelection (handle, OS.XtLastTimestampProcessed (xDisplay));
-
- /* Set the i-beam position. */
- OS.XmTextSetInsertionPosition (handle, nStart);
- display.setWarnings (warnings);
-}
-/**
- * Sets the selection to the range specified
- * by the given start and end indices.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * usual array indexing rules.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int start, int end) {
- checkWidget();
- /* Clear the highlight before setting the selection. */
- int position = OS.XmTextGetLastPosition (handle);
-// OS.XmTextSetHighlight (handle, 0, position, OS.XmHIGHLIGHT_NORMAL);
-
- /*
- * Bug in MOTIF. XmTextSetSelection () fails to set the
- * selection when the receiver is not realized. The fix
- * is to force the receiver to be realized by forcing the
- * shell to be realized. If the receiver is realized before
- * the shell, MOTIF fails to draw the text widget and issues
- * lots of X BadDrawable errors.
- */
- if (!OS.XtIsRealized (handle)) getShell ().realizeWidget ();
-
- /* Set the selection. */
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- start = Math.min (Math.max (start, 0), position);
- end = Math.min (Math.max (end, 0), position);
- int nStart = Math.min (start, end), nEnd = Math.max (start, end);
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetSelection (handle, nStart, nEnd, OS.XtLastTimestampProcessed (xDisplay));
-
- /* Force the i-beam to follow the highlight/selection. */
- if (start > end) {
- OS.XmTextSetInsertionPosition (handle, nStart);
- } else {
- OS.XmTextSetInsertionPosition (handle, nEnd);
- }
- display.setWarnings (warnings);
-}
-/**
- * Sets the selection to the range specified
- * by the given point, where the x coordinate
- * represents the start index and the y coordinate
- * represents the end index.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * usual array indexing rules.
- * </p>
- *
- * @param selection the point
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (Point selection) {
- checkWidget();
- if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (selection.x, selection.y);
-}
-/**
- * Sets the number of tabs.
- * <p>
- * Tab stop spacing is specified in terms of the
- * space (' ') character. The width of a single
- * tab stop is the pixel width of the spaces.
- * </p>
- *
- * @param tabs the number of tabs
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTabs (int tabs) {
- checkWidget();
- /* Do nothing. Tabs are not supported in MOTIF. */
-}
-/**
- * Sets the contents of the receiver to the given string. If the receiver has style
- * SINGLE and the argument contains multiple lines of text, the result of this
- * operation is undefined and may vary from platform to platform.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetString (handle, buffer);
- OS.XmTextSetInsertionPosition (handle, 0);
- display.setWarnings(warnings);
-}
-/**
- * Sets the maximum number of characters that the receiver
- * is capable of holding to be the argument.
- * <p>
- * Instead of trying to set the text limit to zero, consider
- * creating a read-only text widget.
- * </p><p>
- * To reset this value to the default, use <code>setTextLimit(Text.LIMIT)</code>.
- * Specifying a limit value larger than <code>Text.LIMIT</code> sets the
- * receiver's limit to <code>Text.LIMIT</code>.
- * </p>
- *
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public void setTextLimit (int limit) {
- checkWidget();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- OS.XmTextSetMaxLength (handle, limit);
-}
-/**
- * Sets the zero-relative index of the line which is currently
- * at the top of the receiver. This index can change when lines
- * are scrolled or new lines are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return;
- if (scrolledHandle == 0) return;
- int [] argList1 = {OS.XmNverticalScrollBar, 0};
- OS.XtGetValues (scrolledHandle, argList1, argList1.length / 2);
- if (argList1 [1] == 0) return;
- int [] argList2 = {OS.XmNvalue, 0};
- OS.XtGetValues (argList1 [1], argList2, argList2.length / 2);
- OS.XmTextScroll (handle, index - argList2 [1]);
-}
-/**
- * Shows the selection.
- * <p>
- * If the selection is already showing
- * in the receiver, this method simply returns. Otherwise,
- * lines are scrolled until the selection is visible.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void showSelection () {
- checkWidget();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- int position = OS.XmTextGetInsertionPosition (handle);
- OS.XmTextShowPosition (handle, position);
- display.setWarnings (warnings);
-}
-int traversalCode (int key, XKeyEvent xEvent) {
- int bits = super.traversalCode (key, xEvent);
- if ((style & SWT.READ_ONLY) != 0) return bits;
- if ((style & SWT.MULTI) != 0) {
- bits &= ~SWT.TRAVERSE_RETURN;
- if (key == OS.XK_Tab && xEvent != null) {
- boolean next = (xEvent.state & OS.ShiftMask) == 0;
- if (next && (xEvent.state & OS.ControlMask) == 0) {
- bits &= ~(SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS);
- }
- }
- }
- return bits;
-}
-int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) {
- if ((style & SWT.SINGLE) != 0 && message.length () > 0) {
- if (!hasFocus () && OS.XmTextGetLastPosition (handle) == 0) {
- /*
- * Feature in Motif. XmText fills its background during exposure
- * without respecting the damage clipping. This erases all previous
- * paints. The fix is always to draw the entire content ignoring
- * the damage.
- */
- int [] argList = new int [] {
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0,
- OS.XmNshadowThickness, 0,
- OS.XmNhighlightThickness, 0,
- OS.XmNwidth, 0,
- OS.XmNheight, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int marginWidth = argList [1] + argList[5] + argList[7];
- int marginHeight = argList [3] + argList[5] + argList[7];
- Rectangle rect = new Rectangle (marginWidth, marginHeight, argList [9] - 2 * marginWidth, argList [11] - 2 * marginHeight);
- GCData data = new GCData ();
- GC gc = GC.motif_new (this, data);
- gc.setForeground (disabledColor);
- gc.setClipping (rect);
- gc.drawString (message, rect.x, rect.y, true);
- gc.dispose ();
- }
- }
- return super.XExposure (w, client_data, call_data, continue_to_dispatch);
-}
-int xFocusIn (XFocusChangeEvent xEvent) {
- super.xFocusIn (xEvent);
- // widget could be disposed at this point
- if (handle == 0) return 0;
- if ((style & (SWT.READ_ONLY | SWT.SINGLE)) != 0) {
- int [] argList = {OS.XmNcursorPositionVisible, 1};
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
- if ((style & SWT.SEARCH) != 0) {
- redrawHandle (0, 0, 0, 0, true, handle);
- }
- return 0;
-}
-int xFocusOut (XFocusChangeEvent xEvent) {
- super.xFocusOut (xEvent);
- // widget could be disposed at this point
- if (handle == 0) return 0;
- if ((style & (SWT.READ_ONLY | SWT.SINGLE)) != 0) {
- int [] argList = {OS.XmNcursorPositionVisible, 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
- if ((style & SWT.SEARCH) != 0) {
- redrawHandle (0, 0, 0, 0, true, handle);
- }
- return 0;
-}
-int XmNactivateCallback (int w, int client_data, int call_data) {
- postEvent (SWT.DefaultSelection);
- return 0;
-}
-int XmNmodifyVerifyCallback (int w, int client_data, int call_data) {
- int result = super.XmNmodifyVerifyCallback (w, client_data, call_data);
- if (result != 0) return result;
- if (echoCharacter == '\0' && !hooks (SWT.Verify) && !filters (SWT.Verify)) return result;
- XmTextVerifyCallbackStruct textVerify = new XmTextVerifyCallbackStruct ();
- OS.memmove (textVerify, call_data, XmTextVerifyCallbackStruct.sizeof);
- XmTextBlockRec textBlock = new XmTextBlockRec ();
- OS.memmove (textBlock, textVerify.text, XmTextBlockRec.sizeof);
- byte [] buffer = new byte [textBlock.length];
- OS.memmove (buffer, textBlock.ptr, textBlock.length);
- String codePage = getCodePage ();
- String text = new String (Converter.mbcsToWcs (codePage, buffer));
- String newText = text;
- if (!ignoreChange) {
- Event event = new Event ();
- if (textVerify.event != 0) {
- XKeyEvent xEvent = new XKeyEvent ();
- OS.memmove (xEvent, textVerify.event, XKeyEvent.sizeof);
- event.time = xEvent.time;
- setKeyState (event, xEvent);
- }
- event.start = textVerify.startPos;
- event.end = textVerify.endPos;
- event.doit = textVerify.doit == 1;
- event.text = text;
- sendEvent (SWT.Verify, event);
- newText = event.text;
- textVerify.doit = (byte) ((event.doit && newText != null) ? 1 : 0);
- }
- if (newText != null) {
- if (echoCharacter != '\0' && (textVerify.doit != 0)) {
- String prefix = hiddenText.substring (0, textVerify.startPos);
- String suffix = hiddenText.substring (textVerify.endPos, hiddenText.length ());
- hiddenText = prefix + newText + suffix;
- char [] charBuffer = new char [newText.length ()];
- for (int i=0; i<charBuffer.length; i++) {
- charBuffer [i] = echoCharacter;
- }
- newText = new String (charBuffer);
- }
- if (newText != text) {
- OS.XtFree(textBlock.ptr);
- byte [] buffer2 = Converter.wcsToMbcs (codePage, newText, true);
- int length = buffer2.length;
- int ptr = OS.XtMalloc (length);
- OS.memmove (ptr, buffer2, length);
- textBlock.ptr = ptr;
- textBlock.length = buffer2.length - 1;
- OS.memmove (textVerify.text, textBlock, XmTextBlockRec.sizeof);
- }
- }
- OS.memmove (call_data, textVerify, XmTextVerifyCallbackStruct.sizeof);
- return result;
-}
-int XmNvalueChangedCallback (int w, int client_data, int call_data) {
- if (!ignoreChange) sendEvent (SWT.Modify);
- return 0;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java
deleted file mode 100755
index a9d66b0d96..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java
+++ /dev/null
@@ -1,517 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class support the layout of selectable
- * tool bar items.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>ToolItem</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add <code>Control</code> children to it,
- * or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>FLAT, WRAP, RIGHT, HORIZONTAL, VERTICAL, SHADOW_OUT</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#toolbar">ToolBar, ToolItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolBar extends Composite {
- int drawCount, itemCount;
- ToolItem [] items;
- ToolItem lastFocus;
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#FLAT
- * @see SWT#WRAP
- * @see SWT#RIGHT
- * @see SWT#HORIZONTAL
- * @see SWT#SHADOW_OUT
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass()
- * @see Widget#getStyle()
- */
-public ToolBar (Composite parent, int style) {
- super (parent, checkStyle (style));
-
- /*
- * Ensure that either HORIZONTAL or VERTICAL is set.
- * NOTE: HORIZONTAL and VERTICAL have the same values
- * as H_SCROLL and V_SCROLL so it is necessary to first
- * clear these bits to avoid scroll bars and then reset
- * the bits using the original style supplied by the
- * programmer.
- */
- if ((style & SWT.VERTICAL) != 0) {
- this.style |= SWT.VERTICAL;
- } else {
- this.style |= SWT.HORIZONTAL;
- }
-}
-static int checkStyle (int style) {
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = wHint, height = hHint;
- if (wHint == SWT.DEFAULT) width = 0x7FFFFFFF;
- if (hHint == SWT.DEFAULT) height = 0x7FFFFFFF;
- int [] result = layout (width, height, false);
- int border = getBorderWidth () * 2;
- Point extent = new Point (result [1], result [2]);
- if (wHint != SWT.DEFAULT) extent.x = wHint;
- if (hHint != SWT.DEFAULT) extent.y = hHint;
- extent.x += border;
- extent.y += border;
- return extent;
-}
-void createHandle (int index) {
- super.createHandle (index);
- state &= ~CANVAS;
-}
-void createItem (ToolItem item, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (itemCount == items.length) {
- ToolItem [] newItems = new ToolItem [itemCount + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- item.createWidget (index);
- System.arraycopy (items, index, items, index + 1, itemCount++ - index);
- items [index] = item;
- relayout ();
-}
-void createWidget (int index) {
- super.createWidget (index);
- items = new ToolItem [4];
- itemCount = 0;
-}
-void destroyItem (ToolItem item) {
- int index = 0;
- while (index < itemCount) {
- if (items [index] == item) break;
- index++;
- }
- if (index == itemCount) return;
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
-}
-public boolean forceFocus () {
- checkWidget ();
- if (display.focusEvent == SWT.FocusOut) return false;
- Decorations shell = menuShell ();
- shell.setSavedFocus (this);
- shell.bringToTop (false);
- if (lastFocus != null && lastFocus.setFocus ()) return true;
- for (int i = 0; i < itemCount; i++) {
- ToolItem item = items [i];
- if (item.setFocus ()) return true;
- }
- return super.forceFocus ();
-}
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem getItem (int index) {
- checkWidget();
- if (0 <= index && index < itemCount) return items [index];
- error (SWT.ERROR_INVALID_RANGE);
- return null;
-}
-
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- *
- * @param point the point used to locate the item
- * @return the item at the given point
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem getItem (Point pt) {
- checkWidget();
- if (pt == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<itemCount; i++) {
- Rectangle rect = items [i].getBounds ();
- if (rect.contains (pt)) return items [i];
- }
- return null;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- return itemCount;
-}
-/**
- * Returns an array of <code>ToolItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem [] getItems () {
- checkWidget();
- ToolItem [] result = new ToolItem [itemCount];
- System.arraycopy (items, 0, result, 0, itemCount);
- return result;
-}
-/**
- * Returns the number of rows in the receiver. When
- * the receiver has the <code>WRAP</code> style, the
- * number of rows can be greater than one. Otherwise,
- * the number of rows is always one.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getRowCount () {
- checkWidget();
- Rectangle rect = getClientArea ();
- return layout (rect.width, rect.height, false) [0];
-}
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the tool item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the tool item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (ToolItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<itemCount; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-int [] layoutHorizontal (int width, int height, boolean resize) {
- int xSpacing = 0, ySpacing = (style & SWT.NO_FOCUS) != 0 ? 4 : 2;
- int marginWidth = 0, marginHeight = 0;
- int x = marginWidth, y = marginHeight;
- int maxX = 0, rows = 1;
- boolean wrap = (style & SWT.WRAP) != 0;
- int itemHeight = 0;
- Point [] sizes = new Point [itemCount];
- GC gc = new GC (this);
- for (int i=0; i<itemCount; i++) {
- Point size = sizes [i] = items [i].computeSize (gc);
- itemHeight = Math.max (itemHeight, size.y);
- }
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- Point size = sizes [i];
- if (wrap && i != 0 && x + size.x > width) {
- rows++;
- x = marginWidth;
- y += ySpacing + itemHeight;
- }
- if (resize) {
- item.setBounds (x, y, size.x, itemHeight);
- boolean visible = x + size.x <= width && y + itemHeight <= height;
- item.setVisible (visible);
- Control control = item.control;
- if (control != null) {
- int controlY = y + (itemHeight - size.y) / 2;
- control.setBounds (x, controlY, size.x, itemHeight - (controlY - y));
- }
- }
- x += xSpacing + size.x;
- maxX = Math.max (maxX, x);
- }
- gc.dispose ();
- return new int [] {rows, maxX, y + itemHeight};
-}
-int [] layoutVertical (int width, int height, boolean resize) {
- int xSpacing = (style & SWT.NO_FOCUS) != 0 ? 4 : 2, ySpacing = 0;
- int marginWidth = 0, marginHeight = 0;
- int x = marginWidth, y = marginHeight;
- int maxY = 0, cols = 1;
- boolean wrap = (style & SWT.WRAP) != 0;
- int itemWidth = 0;
- Point [] sizes = new Point [itemCount];
- GC gc = new GC (this);
- for (int i=0; i<itemCount; i++) {
- Point size = sizes [i] = items [i].computeSize (gc);
- itemWidth = Math.max (itemWidth, size.x);
- }
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- Point size = sizes [i];
- if (wrap && i != 0 && y + size.y > height) {
- cols++;
- x += xSpacing + itemWidth;
- y = marginHeight;
- }
- if (resize) {
- item.setBounds (x, y, itemWidth, size.y);
- boolean visible = x + itemWidth <= width && y + size.y <= height;
- item.setVisible (visible);
- Control control = item.control;
- if (control != null) {
- int controlX = x + (itemWidth - size.x) / 2;
- control.setBounds (controlX, y, itemWidth - (controlX - x), size.y);
- }
- }
- y += ySpacing + size.y;
- maxY = Math.max (maxY, y);
- }
- return new int [] {cols, x + itemWidth, maxY};
-}
-int [] layout (int nWidth, int nHeight, boolean resize) {
- if ((style & SWT.VERTICAL) != 0) {
- return layoutVertical (nWidth, nHeight, resize);
- } else {
- return layoutHorizontal (nWidth, nHeight, resize);
- }
-}
-boolean mnemonicHit (char key) {
- for (int i = 0; i < itemCount; i++) {
- ToolItem item = items [i];
- char mnemonic = findMnemonic (item.getText ());
- if (mnemonic != '\0') {
- if (Character.toUpperCase (key) == Character.toUpperCase (mnemonic)) {
- XmProcessTraversal (item.handle, OS.XmTRAVERSE_CURRENT);
- item.click (false, 0);
- return true;
- }
- }
- }
- return false;
-}
-boolean mnemonicMatch (char key) {
- for (int i = 0; i < itemCount; i++) {
- ToolItem item = items [i];
- if (item.getEnabled ()) {
- char mnemonic = findMnemonic (item.getText ());
- if (mnemonic != '\0') {
- if (Character.toUpperCase (key) == Character.toUpperCase (mnemonic)) {
- return true;
- }
- }
- }
- }
- return false;
-}
-void propagateWidget (boolean enabled) {
- super.propagateWidget (enabled);
- for (int i=0; i<itemCount; i++) {
- items [i].propagateWidget (enabled);
- }
-}
-void realizeChildren () {
- super.realizeChildren ();
- if (items != null) {
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.realizeChildren ();
- }
- }
- }
-}
-void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean allChildren, boolean trim) {
- super.redrawWidget (x, y, width, height, redrawAll, allChildren, trim);
- if (items != null) {
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.redrawWidget (x, y, width, height, redrawAll, allChildren, true);
- }
- }
- }
-}
-void relayout () {
- if (drawCount > 0) return;
- Rectangle rect = getClientArea ();
- layout (rect.width, rect.height, true);
-}
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- }
- super.releaseChildren (destroy);
-}
-void removeControl (Control control) {
- super.removeControl (control);
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- if (item.control == control) item.setControl (null);
- }
-}
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- for (int i=0; i<itemCount; i++) {
- items[i].setBackgroundPixel (pixel);
- }
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- boolean changed = super.setBounds (x, y, width, height, move, resize);
- if (changed && resize) relayout ();
- return changed;
-}
-public void setFont (Font font) {
- checkWidget();
- super.setFont (font);
- relayout ();
-}
-void setForegroundPixel (int pixel) {
- super.setForegroundPixel (pixel);
- for (int i = 0; i < itemCount; i++) {
- items[i].setForegroundPixel (pixel);
- }
-}
-public void setRedraw (boolean redraw) {
- checkWidget();
- if (redraw) {
- if (--drawCount == 0) relayout();
- } else {
- drawCount++;
- }
-}
-boolean setTabItemFocus (boolean next) {
- int index = 0;
- while (index < itemCount) {
- ToolItem item = items [index];
- if ((item.style & SWT.SEPARATOR) == 0) {
- if (item.getEnabled ()) break;
- }
- index++;
- }
- if (index == itemCount) return false;
- return super.setTabItemFocus (next);
-}
-int traversalCode (int key, XKeyEvent xEvent) {
- return super.traversalCode (key, xEvent) | SWT.TRAVERSE_MNEMONIC;
-}
-int xFocusIn (XFocusChangeEvent xEvent) {
- int newFocus = OS.XmGetFocusWidget (handle);
- if (newFocus != focusHandle ()) {
- for (int i = 0; i < itemCount; i++) {
- if (items [i].handle == newFocus) {
- lastFocus = items [i];
- break;
- }
- }
- }
- return super.xFocusIn (xEvent);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java
deleted file mode 100755
index 9908c4690e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java
+++ /dev/null
@@ -1,1164 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a button in a tool bar.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>PUSH, CHECK, RADIO, SEPARATOR, DROP_DOWN</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles CHECK, PUSH, RADIO, SEPARATOR and DROP_DOWN
- * may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#toolbar">ToolBar, ToolItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolItem extends Item {
- ToolBar parent;
- Image hotImage, disabledImage;
- String toolTipText;
- Control control;
- int width = DEFAULT_SEPARATOR_WIDTH;
- boolean set;
-
- static final int DEFAULT_WIDTH = 24;
- static final int DEFAULT_HEIGHT = 22;
- static final int DEFAULT_SEPARATOR_WIDTH = 8;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>ToolBar</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#PUSH
- * @see SWT#CHECK
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ToolItem (ToolBar parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>ToolBar</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#PUSH
- * @see SWT#CHECK
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ToolItem (ToolBar parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called when the mouse is over the arrow portion of a drop-down tool,
- * the event object detail field contains the value <code>SWT.ARROW</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user,
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-static int checkStyle (int style) {
- return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.DROP_DOWN, 0);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-void createHandle (int index) {
- int parentHandle = parent.handle;
- if ((style & SWT.SEPARATOR) != 0) {
- int orientation = (parent.style & SWT.HORIZONTAL) != 0 ? OS.XmVERTICAL : OS.XmHORIZONTAL;
- int [] argList = {
- OS.XmNheight, orientation == OS.XmVERTICAL ? DEFAULT_HEIGHT : DEFAULT_SEPARATOR_WIDTH,
- OS.XmNwidth, orientation == OS.XmHORIZONTAL ? DEFAULT_WIDTH : DEFAULT_SEPARATOR_WIDTH,
- OS.XmNancestorSensitive, 1,
- OS.XmNpositionIndex, index,
- OS.XmNorientation, orientation,
- OS.XmNseparatorType, (parent.style & SWT.FLAT) != 0 ? OS.XmSHADOW_ETCHED_IN : OS.XmSHADOW_ETCHED_OUT,
- };
- handle = OS.XmCreateSeparator (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- return;
- }
- int [] argList = {
- OS.XmNwidth, DEFAULT_WIDTH,
- OS.XmNheight, DEFAULT_HEIGHT,
- OS.XmNrecomputeSize, 0,
- OS.XmNhighlightThickness, (parent.style & SWT.NO_FOCUS) != 0 ? 0 : 1,
- OS.XmNmarginWidth, 2,
- OS.XmNmarginHeight, 1,
- OS.XmNtraversalOn, (parent.style & SWT.NO_FOCUS) != 0 ? 0 : 1,
- OS.XmNpositionIndex, index,
- OS.XmNshadowType, OS.XmSHADOW_OUT,
- OS.XmNancestorSensitive, 1,
- };
- handle = OS.XmCreateDrawnButton (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- Control control = parent.findBackgroundControl ();
- if (control == null) control = parent;
- setBackgroundPixel (parent.getBackgroundPixel ());
-}
-
-void click (boolean dropDown, int state) {
- if ((style & SWT.RADIO) != 0) {
- selectRadio ();
- } else {
- if ((style & SWT.CHECK) != 0) setSelection(!set);
- }
- Event event = new Event ();
- if ((style & SWT.DROP_DOWN) != 0) {
- if (dropDown) {
- event.detail = SWT.ARROW;
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- event.x = (short) argList [1];
- event.y = (short) argList [3] + (short) argList [5];
- }
- }
- if (state != 0) setInputState (event, state);
- postEvent (SWT.Selection, event);
-}
-
-Point computeSize (GC gc) {
- int width = 0, height = 0;
- if ((style & SWT.SEPARATOR) != 0) {
- if ((parent.style & SWT.HORIZONTAL) != 0) {
- width = getWidth ();
- height = DEFAULT_HEIGHT;
- } else {
- width = DEFAULT_WIDTH;
- height = getWidth ();
- }
- if (control != null) {
- height = Math.max (height, control.getMinimumHeight ());
- }
- return new Point(width, height);
- }
- int [] argList = {
- OS.XmNmarginHeight, 0,
- OS.XmNmarginWidth, 0,
- OS.XmNshadowThickness, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int marginHeight = argList [1], marginWidth = argList [3];
- int shadowThickness = argList [5];
- if ((parent.style & SWT.FLAT) != 0) {
- shadowThickness = Math.min (2, display.buttonShadowThickness);
- }
- if (text.length() != 0 || image != null) {
- int textWidth = 0, textHeight = 0;
- if (text.length () != 0) {
- int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC;
- Point textExtent = gc.textExtent (text, flags);
- textWidth = textExtent.x;
- textHeight = textExtent.y;
- }
- int imageWidth = 0, imageHeight = 0;
- if (image != null) {
- Rectangle rect = image.getBounds ();
- imageWidth = rect.width;
- imageHeight = rect.height;
- }
- if ((parent.style & SWT.RIGHT) != 0) {
- width = imageWidth + textWidth;
- height = Math.max (imageHeight, textHeight);
- if (imageWidth != 0 && textWidth != 0) width += 2;
- } else {
- height = imageHeight + textHeight;
- if (imageHeight != 0 && textHeight != 0) height += 2;
- width = Math.max (imageWidth, textWidth);
- }
- } else {
- width = DEFAULT_WIDTH;
- height = DEFAULT_HEIGHT;
- }
- if ((style & SWT.DROP_DOWN) != 0) {
- width += 12;
- }
- if (width != 0) {
- width += (marginWidth + shadowThickness) * 2 + 2;
- } else {
- width = DEFAULT_WIDTH;
- }
- if (height != 0) {
- height += (marginHeight + shadowThickness) * 2 + 2;
- } else {
- height = DEFAULT_HEIGHT;
- }
- return new Point (width, height);
-}
-void createWidget (int index) {
- super.createWidget (index);
- int topHandle = topHandle ();
- if (OS.XtIsRealized (topHandle)) {
- /*
- * Make sure that the widget has been properly realized
- * because the widget was created after the parent
- * has been realized.
- */
- realizeChildren ();
- }
-}
-void destroyWidget () {
- parent.destroyItem (this);
- super.destroyWidget ();
-}
-public void dispose () {
- if (isDisposed()) return;
- ToolBar parent = this.parent;
- super.dispose ();
- parent.relayout ();
-}
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return new Rectangle ((short) argList [1], (short) argList [3], argList [5], argList [7]);
-}
-/**
- * Returns the control that is used to fill the bounds of
- * the item when the item is a <code>SEPARATOR</code>.
- *
- * @return the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget();
- return control;
-}
-/**
- * Returns the receiver's disabled image if it has one, or null
- * if it does not.
- * <p>
- * The disabled image is displayed when the receiver is disabled.
- * </p>
- *
- * @return the receiver's disabled image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getDisabledImage () {
- checkWidget();
- return disabledImage;
-}
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- int [] argList = {OS.XmNsensitive, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] != 0;
-}
-/**
- * Returns the receiver's hot image if it has one, or null
- * if it does not.
- * <p>
- * The hot image is displayed when the mouse enters the receiver.
- * </p>
- *
- * @return the receiver's hot image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getHotImage () {
- checkWidget();
- return hotImage;
-}
-/**
- * Returns the receiver's parent, which must be a <code>ToolBar</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolBar getParent () {
- checkWidget();
- return parent;
-}
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked (which some platforms draw as a
- * pushed in button). If the receiver is of any other type, this method
- * returns false.
- * </p>
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
- return set;
-}
-/**
- * Returns the receiver's tool tip text, or null if it has not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget();
- return width;
-}
-boolean hasCursor () {
- int [] unused = new int [1], buffer = new int [1];
- int xDisplay = OS.XtDisplay (handle);
- int xWindow, xParent = OS.XDefaultRootWindow (xDisplay);
- do {
- if (OS.XQueryPointer (
- xDisplay, xParent, unused, buffer,
- unused, unused, unused, unused, unused) == 0) return false;
- if ((xWindow = buffer [0]) != 0) xParent = xWindow;
- } while (xWindow != 0);
- return handle == OS.XtWindowToWidget (xDisplay, xParent);
-}
-void hookEvents () {
- super.hookEvents ();
- if ((style & SWT.SEPARATOR) != 0) return;
- int windowProc = display.windowProc;
- OS.XtAddEventHandler (handle, OS.KeyPressMask, false, windowProc, KEY_PRESS);
- OS.XtAddEventHandler (handle, OS.KeyReleaseMask, false, windowProc, KEY_RELEASE);
- OS.XtAddEventHandler (handle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS);
- OS.XtAddEventHandler (handle, OS.ButtonReleaseMask, false, windowProc, BUTTON_RELEASE);
- OS.XtAddEventHandler (handle, OS.PointerMotionMask, false, windowProc, POINTER_MOTION);
- OS.XtAddEventHandler (handle, OS.EnterWindowMask, false, windowProc, ENTER_WINDOW);
- OS.XtAddEventHandler (handle, OS.LeaveWindowMask, false, windowProc, LEAVE_WINDOW);
- OS.XtAddCallback (handle, OS.XmNexposeCallback, windowProc, EXPOSURE_CALLBACK);
- OS.XtInsertEventHandler (handle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail);
-}
-int hoverProc (int id) {
- boolean showTip = toolTipText != null;
- parent.hoverProc (id, !showTip);
- if (showTip) {
- display.showToolTip (handle, toolTipText);
- }
- return 0;
-}
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-void manageChildren () {
- OS.XtManageChild (handle);
-}
-void realizeChildren () {
- if ((parent.state & PARENT_BACKGROUND) != 0) {
- setParentBackground ();
- }
-}
-void redraw () {
- int display = OS.XtDisplay (handle);
- if (display == 0) return;
- int window = OS.XtWindow (handle);
- if (window == 0) return;
- OS.XClearArea (display, window, 0, 0, 0, 0, true);
-}
-void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean allChildren, boolean trim) {
- redrawHandle (x, y, width, height, redrawAll, handle);
-}
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
-}
-void releaseWidget () {
- super.releaseWidget ();
- display.releaseToolTipHandle (handle);
- if (parent.lastFocus == this) parent.lastFocus = null;
- control = null;
- toolTipText = null;
- image = disabledImage = hotImage = null;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Selection, listener);
- eventTable.unhook(SWT.DefaultSelection,listener);
-}
-void selectRadio () {
- int index = 0;
- ToolItem [] items = parent.getItems ();
- while (index < items.length && items [index] != this) index++;
- int i = index - 1;
- while (i >= 0 && items [i].setRadioSelection (false)) --i;
- int j = index + 1;
- while (j < items.length && items [j].setRadioSelection (false)) j++;
- setSelection (true);
-}
-void setBackgroundPixel(int pixel) {
- int [] argList = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmChangeColor (handle, pixel);
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-void setBounds (int x, int y, int width, int height) {
- /*
- * Feature in Motif. Motif will not allow a window
- * to have a zero width or zero height. The fix is
- * to ensure these values are never zero.
- */
- int newWidth = Math.max (width, 1), newHeight = Math.max (height, 1);
- OS.XtConfigureWidget (handle, x, y, newWidth, newHeight, 0);
-}
-/**
- * Sets the control that is used to fill the bounds of
- * the item when the item is a <code>SEPARATOR</code>.
- *
- * @param control the new control
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- if ((style & SWT.SEPARATOR) == 0) return;
- if (this.control == control) return;
- this.control = control;
- int [] argList = {
- OS.XmNseparatorType, control == null ? ((parent.style & SWT.FLAT) != 0 ? OS.XmSHADOW_ETCHED_IN : OS.XmSHADOW_ETCHED_OUT) : OS.XmNO_LINE,
- };
- OS.XtSetValues (handle, argList, argList.length / 2);
- if (control != null && !control.isDisposed ()) {
- /*
- * It is possible that the control was created with a
- * z-order below that of the current tool item. In this
- * case, the control is not visible because it is
- * obscured by the tool item. The fix is to move the
- * control above this tool item in the z-order.
- * The code below is similar to the code found in
- * setZOrder.
- */
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- if (!OS.XtIsRealized (handle)) {
- Shell shell = parent.getShell ();
- shell.realizeWidget ();
- }
- int topHandle1 = control.topHandle ();
- int window1 = OS.XtWindow (topHandle1);
- if (window1 == 0) return;
- int topHandle2 = this.topHandle ();
- int window2 = OS.XtWindow (topHandle2);
- if (window2 == 0) return;
- XWindowChanges struct = new XWindowChanges ();
- struct.sibling = window2;
- struct.stack_mode = OS.Above;
- int screen = OS.XDefaultScreen (xDisplay);
- int flags = OS.CWStackMode | OS.CWSibling;
- OS.XReconfigureWMWindow (xDisplay, window1, screen, flags, struct);
- }
- parent.relayout ();
-}
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise.
- * <p>
- * A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- * </p>
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-void setForegroundPixel(int pixel) {
- int [] argList = {OS.XmNforeground, pixel};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * Sets the receiver's disabled image to the argument, which may be
- * null indicating that no disabled image should be displayed.
- * <p>
- * The disabled image is displayed when the receiver is disabled.
- * </p>
- *
- * @param image the disabled image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDisabledImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- disabledImage = image;
- if (!getEnabled ()) redraw ();
-}
-boolean setFocus () {
- if ((style & SWT.SEPARATOR) != 0) return false;
- return XmProcessTraversal (handle, OS.XmTRAVERSE_CURRENT);
-}
-/**
- * Sets the receiver's hot image to the argument, which may be
- * null indicating that no hot image should be displayed.
- * <p>
- * The hot image is displayed when the mouse enters the receiver.
- * </p>
- *
- * @param image the hot image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHotImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- hotImage = image;
- if ((parent.style & SWT.FLAT) != 0) redraw ();
-}
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- super.setImage (image);
- parent.relayout();
- redraw ();
-}
-void setParentBackground () {
- parent.setParentBackground (handle);
-}
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-/**
- * Sets the selection state of the receiver.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked (which some platforms draw as a
- * pushed in button).
- * </p>
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
- if (selected == set) return;
- set = selected;
- setDrawPressed (set);
-}
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- super.setText (string);
- parent.relayout();
- redraw ();
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
-}
-void setVisible (boolean visible) {
- OS.XtSetMappedWhenManaged (handle, visible);
-}
-/**
- * Sets the width of the receiver, for <code>SEPARATOR</code> ToolItems.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int width) {
- checkWidget();
- if ((style & SWT.SEPARATOR) == 0) return;
- if (width < 0 || this.width == width) return;
- this.width = width;
- parent.relayout();
-}
-void setDrawPressed (boolean value) {
- int shadowType = value ? OS.XmSHADOW_IN : OS.XmSHADOW_OUT;
- int [] argList = {OS.XmNshadowType, shadowType};
- OS.XtSetValues(handle, argList, argList.length / 2);
-}
-boolean translateAccelerator (char key, int keysym, XKeyEvent xEvent, boolean doit) {
- return parent.translateAccelerator (key, keysym, xEvent, doit);
-}
-boolean translateMnemonic (char key, int keysym, XKeyEvent xEvent) {
- return parent.translateMnemonic (key, keysym, xEvent);
-}
-boolean translateTraversal (int key, XKeyEvent xEvent) {
- return parent.translateTraversal (key, xEvent);
-}
-void propagateWidget (boolean enabled) {
- propagateHandle (enabled, handle, OS.None);
-}
-int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- display.hideToolTip ();
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- /*
- * Forward the mouse event to the parent.
- * This is necessary so that mouse listeners
- * in the parent will be called, despite the
- * fact that the event did not really occur
- * in X in the parent. This is done to be
- * compatible with Windows.
- */
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- xEvent.window = OS.XtWindow (parent.handle);
- xEvent.x += argList [1]; xEvent.y += argList [3];
- OS.memmove (call_data, xEvent, XButtonEvent.sizeof);
- int result = parent.XButtonPress (w, client_data, call_data, continue_to_dispatch);
- xEvent.x -= argList [1]; xEvent.y -= argList [3];
- if (result == 0 && xEvent.button == 1) {
- if (!set) setDrawPressed (!set);
- }
- return result;
-}
-int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- display.hideToolTip();
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- /*
- * Forward the mouse event to the parent.
- * This is necessary so that mouse listeners
- * in the parent will be called, despite the
- * fact that the event did not really occur
- * in X in the parent. This is done to be
- * compatible with Windows.
- */
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- xEvent.window = OS.XtWindow (parent.handle);
- xEvent.x += argList [1]; xEvent.y += argList [3];
- OS.memmove (call_data, xEvent, XButtonEvent.sizeof);
- int result = parent.XButtonRelease (w, client_data, call_data, continue_to_dispatch);
- xEvent.x -= argList [1]; xEvent.y -= argList [3];
- if (result == 0 && xEvent.button == 1) {
- int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList2, argList2.length / 2);
- int width = argList2 [1], height = argList2 [3];
- if (0 <= xEvent.x && xEvent.x < width && 0 <= xEvent.y && xEvent.y < height) {
- click (xEvent.x > width - 12, xEvent.state);
- }
- setDrawPressed (set);
- }
- return result;
-}
-int XEnterWindow (int w, int client_data, int call_data, int continue_to_dispatch) {
- XCrossingEvent xEvent = new XCrossingEvent ();
- OS.memmove (xEvent, call_data, XCrossingEvent.sizeof);
- if ((xEvent.state & OS.Button1Mask) != 0) {
- setDrawPressed (!set);
- } else {
- if ((parent.style & SWT.FLAT) != 0) redraw ();
- }
- return 0;
-}
-int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatch) {
- /*
- * Forward the focus event to the parent.
- * This is necessary so that focus listeners
- * in the parent will be called, despite the
- * fact that the event did not really occur
- * in X in the parent. This is done to be
- * compatible with Windows.
- */
- XFocusChangeEvent xEvent = new XFocusChangeEvent ();
- OS.memmove (xEvent, call_data, XFocusChangeEvent.sizeof);
- xEvent.window = OS.XtWindow (parent.handle);
-// OS.memmove (call_data, xEvent, XFocusChangeEvent.sizeof);
- parent.XFocusChange (w, client_data, call_data, continue_to_dispatch);
- return 0;
-}
-int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = 0;
- XKeyEvent xEvent = new XKeyEvent ();
- OS.memmove (xEvent, call_data, XKeyEvent.sizeof);
- int [] keysym = new int [1];
- OS.XLookupString (xEvent, null, 0, keysym, null);
- keysym [0] &= 0xFFFF;
- switch (keysym [0]) {
- case OS.XK_space:
- click (false, xEvent.state);
- result = 1;
- break;
- case OS.XK_Down:
- if ((style & SWT.DROP_DOWN) != 0) {
- click (true, xEvent.state);
- result = 1;
- }
- break;
- }
- /*
- * Forward the key event to the parent.
- * This is necessary so that key listeners
- * in the parent will be called, despite the
- * fact that the event did not really occur
- * in X in the parent. This is done to be
- * compatible with Windows.
- */
- xEvent.window = OS.XtWindow (parent.handle);
-// OS.memmove (callData, xEvent, XKeyEvent.sizeof);
- parent.XKeyPress (w, client_data, call_data, continue_to_dispatch);
- if (result == 1) {
- OS.memmove (continue_to_dispatch, new int [1], 4);
- }
- return result;
-}
-int XKeyRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- XKeyEvent xEvent = new XKeyEvent ();
- OS.memmove (xEvent, call_data, XKeyEvent.sizeof);
-
- /*
- * Forward the key event to the parent.
- * This is necessary so that key listeners
- * in the parent will be called, despite the
- * fact that the event did not really occur
- * in X in the parent. This is done to be
- * compatible with Windows.
- */
- xEvent.window = OS.XtWindow (parent.handle);
-// OS.memmove (callData, xEvent, XKeyEvent.sizeof);
- parent.XKeyRelease (w, client_data, call_data, continue_to_dispatch);
- return 0;
-}
-int XLeaveWindow (int w, int client_data, int call_data, int continue_to_dispatch) {
- display.removeMouseHoverTimeOut ();
- display.hideToolTip ();
- XCrossingEvent xEvent = new XCrossingEvent ();
- OS.memmove (xEvent, call_data, XCrossingEvent.sizeof);
- if ((xEvent.state & OS.Button1Mask) != 0) {
- setDrawPressed (set);
- } else {
- if ((parent.style & SWT.FLAT) != 0) redraw ();
- }
- return 0;
-}
-int XmNexposureCallback (int w, int client_data, int call_data) {
- if ((style & SWT.SEPARATOR) != 0) return 0;
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return 0;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return 0;
- int [] argList = {
- OS.XmNcolormap, 0,
- OS.XmNwidth, 0,
- OS.XmNheight, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int width = argList [3], height = argList [5];
-
- Image currentImage = image;
- boolean enabled = getEnabled();
-
- if ((parent.style & SWT.FLAT) != 0) {
- boolean hasCursor = hasCursor ();
-
- /* Set the shadow thickness */
- int thickness = 0;
- if (set || (hasCursor && enabled)) {
- thickness = Math.min (2, display.buttonShadowThickness);
- }
- argList = new int [] {OS.XmNshadowThickness, thickness};
- OS.XtSetValues (handle, argList, argList.length / 2);
-
- /* Determine if hot image should be used */
- if (enabled && hasCursor && hotImage != null) {
- currentImage = hotImage;
- }
- }
-
- GCData data = new GCData ();
- data.device = display;
- data.display = xDisplay;
- data.drawable = xWindow;
- data.font = parent.font;
- data.colormap = argList [1];
- int xGC = OS.XCreateGC (xDisplay, xWindow, 0, null);
- if (xGC == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- GC gc = GC.motif_new (xGC, data);
-
- XmAnyCallbackStruct cb = new XmAnyCallbackStruct ();
- OS.memmove (cb, call_data, XmAnyCallbackStruct.sizeof);
- if (cb.event != 0) {
- XExposeEvent xEvent = new XExposeEvent ();
- OS.memmove (xEvent, cb.event, XExposeEvent.sizeof);
- Rectangle rect = new Rectangle (xEvent.x, xEvent.y, xEvent.width, xEvent.height);
- gc.setClipping (rect);
- }
-
- if (!enabled) {
- currentImage = disabledImage;
- if (currentImage == null && image != null) {
- currentImage = new Image (display, image, SWT.IMAGE_DISABLE);
- }
- Color disabledColor = display.getSystemColor (SWT.COLOR_WIDGET_NORMAL_SHADOW);
- gc.setForeground (disabledColor);
- } else {
- gc.setForeground (parent.getForeground ());
- }
- gc.setBackground (parent.getBackground ());
-
- int textX = 0, textY = 0, textWidth = 0, textHeight = 0;
- if (text.length () != 0) {
- int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC;
- Point textExtent = gc.textExtent (text, flags);
- textWidth = textExtent.x;
- textHeight = textExtent.y;
- }
- int imageX = 0, imageY = 0, imageWidth = 0, imageHeight = 0;
- if (currentImage != null) {
- Rectangle imageBounds = currentImage.getBounds ();
- imageWidth = imageBounds.width;
- imageHeight = imageBounds.height;
- }
-
- int spacing = 0;
- if (textWidth != 0 && imageWidth != 0) spacing = 2;
- if ((parent.style & SWT.RIGHT) != 0) {
- imageX = (width - imageWidth - textWidth - spacing) / 2;
- imageY = (height - imageHeight) / 2;
- textX = spacing + imageX + imageWidth;
- textY = (height - textHeight) / 2;
- } else {
- imageX = (width - imageWidth) / 2;
- imageY = (height - imageHeight - textHeight - spacing) / 2;
- textX = (width - textWidth) / 2;
- textY = spacing + imageY + imageHeight;
- }
-
- if ((style & SWT.DROP_DOWN) != 0) {
- textX -= 6; imageX -=6;
- }
- if (textWidth > 0) {
- int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC | SWT.DRAW_TRANSPARENT;
- gc.drawText(text, textX, textY, flags);
- }
- if (imageWidth > 0) gc.drawImage(currentImage, imageX, imageY);
- if ((style & SWT.DROP_DOWN) != 0) {
- int startX = width - 12, startY = (height - 2) / 2;
- int [] arrow = {startX, startY, startX + 3, startY + 3, startX + 6, startY};
- gc.setBackground (parent.getForeground ());
- gc.fillPolygon (arrow);
- gc.drawPolygon (arrow);
- }
- gc.dispose ();
- OS.XFreeGC (xDisplay, xGC);
-
- if (!enabled && disabledImage == null) {
- if (currentImage != null) currentImage.dispose ();
- }
- return 0;
-}
-int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) {
- display.addMouseHoverTimeOut (handle);
-
- /*
- * Forward the mouse event to the parent.
- * This is necessary so that mouse listeners
- * in the parent will be called, despite the
- * fact that the event did not really occur
- * in X in the parent. This is done to be
- * compatible with Windows.
- */
- XMotionEvent xEvent = new XMotionEvent ();
- OS.memmove (xEvent, call_data, XMotionEvent.sizeof);
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- xEvent.window = OS.XtWindow (parent.handle);
- xEvent.x += argList [1]; xEvent.y += argList [3];
- /*
- * This code is intentionally commented.
- * Currently, the implementation of the
- * mouse move code in the parent interferes
- * with tool tips for tool items.
- */
-// OS.memmove (callData, xEvent, XButtonEvent.sizeof);
-// parent.XPointerMotion (w, client_data, call_data, continue_to_dispatch);
- if (!parent.sendMouseEvent (SWT.MouseMove, xEvent)) {
- OS.memmove (continue_to_dispatch, new int [1], 4);
- return 1;
- }
- return 0;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java
deleted file mode 100755
index b7d096f337..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java
+++ /dev/null
@@ -1,983 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class implement rubber banding rectangles that are
- * drawn onto a parent <code>Composite</code> or <code>Display</code>.
- * These rectangles can be specified to respond to mouse and key events
- * by either moving or resizing themselves accordingly. Trackers are
- * typically used to represent window geometries in a lightweight manner.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, UP, DOWN, RESIZE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Move, Resize</dd>
- * </dl>
- * <p>
- * Note: Rectangle move behavior is assumed unless RESIZE is specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tracker">Tracker snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Tracker extends Widget {
- Composite parent;
- boolean tracking, cancelled, stippled;
- Rectangle [] rectangles = new Rectangle [0], proportions = rectangles;
- Rectangle bounds;
- int cursorOrientation = SWT.NONE;
- Cursor cursor;
- int window, oldX, oldY;
-
- final static int STEPSIZE_SMALL = 1;
- final static int STEPSIZE_LARGE = 9;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#RESIZE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Tracker (Composite parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
-}
-
-/**
- * Constructs a new instance of this class given the display
- * to create it on and a style value describing its behavior
- * and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the tracker on the currently active
- * display if there is one. If there is no current display, the
- * tracker is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the tracker on
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#RESIZE
- */
-public Tracker (Display display, int style) {
- if (display == null) display = Display.getCurrent ();
- if (display == null) display = Display.getDefault ();
- if (!display.isValidThread ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- this.style = checkStyle (style);
- this.display = display;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize, typedListener);
- addListener (SWT.Move, typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard, by sending
- * it one of the messages defined in the <code>KeyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #removeKeyListener
- */
-public void addKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.KeyUp,typedListener);
- addListener(SWT.KeyDown,typedListener);
-}
-
-Point adjustMoveCursor () {
- if (bounds == null) return null;
- final int unused[] = new int[1];
- int actualX[] = new int[1];
- int actualY[] = new int[1];
-
- int newX = bounds.x + bounds.width / 2;
- int newY = bounds.y;
-
- int xDisplay = display.xDisplay;
- OS.XWarpPointer (xDisplay, OS.None, window, 0, 0, 0, 0, newX, newY);
- /*
- * The call to XWarpPointer does not always place the pointer on the
- * exact location that is specified, so do a query (below) to get the
- * actual location of the pointer after it has been moved.
- */
- OS.XQueryPointer (xDisplay, window, unused, unused, actualX, actualY, unused, unused, unused);
- return new Point (actualX[0], actualY[0]);
-}
-Point adjustResizeCursor () {
- if (bounds == null) return null;
- int newX, newY;
-
- if ((cursorOrientation & SWT.LEFT) != 0) {
- newX = bounds.x;
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- newX = bounds.x + bounds.width;
- } else {
- newX = bounds.x + bounds.width / 2;
- }
-
- if ((cursorOrientation & SWT.UP) != 0) {
- newY = bounds.y;
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- newY = bounds.y + bounds.height;
- } else {
- newY = bounds.y + bounds.height / 2;
- }
-
- final int unused[] = new int[1];
- int actualX[] = new int[1];
- int actualY[] = new int[1];
- int xDisplay = display.xDisplay;
- OS.XWarpPointer (xDisplay, 0, window, 0, 0, 0, 0, newX, newY);
- /*
- * The call to XWarpPointer does not always place the pointer on the
- * exact location that is specified, so do a query (below) to get the
- * actual location of the pointer after it has been moved.
- */
- OS.XQueryPointer (xDisplay, window, unused, unused, actualX, actualY, unused, unused, unused);
- return new Point (actualX[0], actualY[0]);
-}
-static int checkStyle (int style) {
- if ((style & (SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN)) == 0) {
- style |= SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN;
- }
- return style;
-}
-/**
- * Stops displaying the tracker rectangles. Note that this is not considered
- * to be a cancelation by the user.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void close () {
- checkWidget ();
- tracking = false;
-}
-Rectangle computeBounds () {
- if (rectangles.length == 0) return null;
- int xMin = rectangles [0].x;
- int yMin = rectangles [0].y;
- int xMax = rectangles [0].x + rectangles [0].width;
- int yMax = rectangles [0].y + rectangles [0].height;
-
- for (int i = 1; i < rectangles.length; i++) {
- if (rectangles [i].x < xMin) xMin = rectangles [i].x;
- if (rectangles [i].y < yMin) yMin = rectangles [i].y;
- int rectRight = rectangles [i].x + rectangles [i].width;
- if (rectRight > xMax) xMax = rectRight;
- int rectBottom = rectangles [i].y + rectangles [i].height;
- if (rectBottom > yMax) yMax = rectBottom;
- }
-
- return new Rectangle (xMin, yMin, xMax - xMin, yMax - yMin);
-}
-
-Rectangle [] computeProportions (Rectangle [] rects) {
- Rectangle [] result = new Rectangle [rects.length];
- bounds = computeBounds ();
- if (bounds != null) {
- for (int i = 0; i < rects.length; i++) {
- int x = 0, y = 0, width = 0, height = 0;
- if (bounds.width != 0) {
- x = (rects [i].x - bounds.x) * 100 / bounds.width;
- width = rects [i].width * 100 / bounds.width;
- } else {
- width = 100;
- }
- if (bounds.height != 0) {
- y = (rects [i].y - bounds.y) * 100 / bounds.height;
- height = rects [i].height * 100 / bounds.height;
- } else {
- height = 100;
- }
- result [i] = new Rectangle (x, y, width, height);
- }
- }
- return result;
-}
-
-void drawRectangles (Rectangle [] rects, boolean stippled) {
- int xDisplay = display.xDisplay;
- int color = OS.XWhitePixel (xDisplay, 0);
- int xWindow = OS.XDefaultRootWindow (xDisplay);
- if (parent != null) {
- xWindow = OS.XtWindow (parent.handle);
- if (xWindow == 0) return;
- int foreground = parent.getForegroundPixel ();
- Control control = parent.findBackgroundControl ();
- if (control == null) control = parent;
- int background = control.getBackgroundPixel ();
- color = foreground ^ background;
- }
- int gc = OS.XCreateGC (xDisplay, xWindow, 0, null);
- OS.XSetForeground (xDisplay, gc, color);
- OS.XSetSubwindowMode (xDisplay, gc, OS.IncludeInferiors);
- OS.XSetFunction (xDisplay, gc, OS.GXxor);
- int stipplePixmap = 0;
- if (stippled) {
- byte [] bits = {-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0};
- stipplePixmap = OS.XCreateBitmapFromData (xDisplay, xWindow, bits, 8, 8);
- OS.XSetStipple (xDisplay, gc, stipplePixmap);
- OS.XSetFillStyle (xDisplay, gc, OS.FillStippled);
- OS.XSetLineAttributes (xDisplay, gc, 3, OS.LineSolid, OS.CapButt, OS.JoinMiter);
- }
- for (int i=0; i<rects.length; i++) {
- Rectangle rect = rects [i];
- OS.XDrawRectangle (xDisplay, xWindow, gc, rect.x, rect.y, rect.width, rect.height);
- }
- if (stippled) {
- OS.XFreePixmap (xDisplay, stipplePixmap);
- }
- OS.XFreeGC (xDisplay, gc);
-}
-/**
- * Returns the bounds that are being drawn, expressed relative to the parent
- * widget. If the parent is a <code>Display</code> then these are screen
- * coordinates.
- *
- * @return the bounds of the Rectangles being drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle [] getRectangles () {
- checkWidget();
- Rectangle [] result = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- result [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- return result;
-}
-/**
- * Returns <code>true</code> if the rectangles are drawn with a stippled line, <code>false</code> otherwise.
- *
- * @return the stippled effect of the rectangles
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getStippled () {
- checkWidget ();
- return stippled;
-}
-
-void moveRectangles (int xChange, int yChange) {
- if (bounds == null) return;
- if (xChange < 0 && ((style & SWT.LEFT) == 0)) xChange = 0;
- if (xChange > 0 && ((style & SWT.RIGHT) == 0)) xChange = 0;
- if (yChange < 0 && ((style & SWT.UP) == 0)) yChange = 0;
- if (yChange > 0 && ((style & SWT.DOWN) == 0)) yChange = 0;
- if (xChange == 0 && yChange == 0) return;
- bounds.x += xChange; bounds.y += yChange;
- for (int i = 0; i < rectangles.length; i++) {
- rectangles [i].x += xChange;
- rectangles [i].y += yChange;
- }
-}
-
-/**
- * Displays the Tracker rectangles for manipulation by the user. Returns when
- * the user has either finished manipulating the rectangles or has cancelled the
- * Tracker.
- *
- * @return <code>true</code> if the user did not cancel the Tracker, <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean open () {
- checkWidget ();
- int xDisplay = display.xDisplay;
- window = OS.XDefaultRootWindow (xDisplay);
- if (parent != null) {
- window = OS.XtWindow (parent.handle);
- if (window == 0) return false;
- }
- cancelled = false;
- tracking = true;
- update ();
- drawRectangles (rectangles, stippled);
- int [] oldX = new int [1], oldY = new int [1];
- int [] unused = new int [1], mask = new int [1];
- OS.XQueryPointer (xDisplay, window, unused, unused, oldX, oldY, unused, unused, mask);
-
- /*
- * If exactly one of UP/DOWN is specified as a style then set the cursor
- * orientation accordingly (the same is done for LEFT/RIGHT styles below).
- */
- int vStyle = style & (SWT.UP | SWT.DOWN);
- if (vStyle == SWT.UP || vStyle == SWT.DOWN) {
- cursorOrientation |= vStyle;
- }
- int hStyle = style & (SWT.LEFT | SWT.RIGHT);
- if (hStyle == SWT.LEFT || hStyle == SWT.RIGHT) {
- cursorOrientation |= hStyle;
- }
-
- int mouseMasks = OS.Button1Mask | OS.Button2Mask | OS.Button3Mask;
- boolean mouseDown = (mask [0] & mouseMasks) != 0;
- if (!mouseDown) {
- Point cursorPos = null;
- if ((style & SWT.RESIZE) != 0) {
- cursorPos = adjustResizeCursor ();
- } else {
- cursorPos = adjustMoveCursor ();
- }
- if (cursorPos != null) {
- oldX [0] = cursorPos.x;
- oldY [0] = cursorPos.y;
- }
- }
- this.oldX = oldX [0];
- this.oldY = oldY [0];
-
- int ptrGrabResult = OS.XGrabPointer (xDisplay, window, 0,
- OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask,
- OS.GrabModeAsync, OS.GrabModeAsync, OS.None, OS.None, OS.CurrentTime);
- int kbdGrabResult = OS.XGrabKeyboard (xDisplay, window, 0,
- OS.GrabModeAsync, OS.GrabModeAsync, OS.CurrentTime);
-
- /* Tracker behaves like a Dialog with its own OS event loop. */
- XAnyEvent anyEvent = new XAnyEvent();
- int xEvent = OS.XtMalloc (XEvent.sizeof);
- int dispatch = OS.XtMalloc (4);
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- while (tracking) {
- if (parent != null && parent.isDisposed ()) break;
- OS.XtAppNextEvent (xtContext, xEvent);
- OS.memmove (anyEvent, xEvent, XAnyEvent.sizeof);
- int widget = OS.XtWindowToWidget (anyEvent.display, anyEvent.window);
- switch (anyEvent.type) {
- case OS.MotionNotify: XPointerMotion (widget, 0, xEvent, dispatch); break;
- case OS.ButtonRelease: XButtonRelease (widget, 0, xEvent, dispatch); break;
- case OS.KeyPress: XKeyPress (widget, 0, xEvent, dispatch); break;
- case OS.KeyRelease: XKeyRelease (widget, 0, xEvent, dispatch); break;
- case OS.ButtonPress:
- case OS.EnterNotify:
- case OS.LeaveNotify:
- /* Do not dispatch these */
- break;
- case OS.Expose:
- update ();
- drawRectangles (rectangles, stippled);
- OS.XtDispatchEvent (xEvent);
- drawRectangles (rectangles, stippled);
- break;
- default:
- OS.XtDispatchEvent (xEvent);
- }
- }
- if (xEvent != 0) OS.XtFree (xEvent);
- if (dispatch != 0) OS.XtFree (dispatch);
- if (!isDisposed()) {
- update ();
- drawRectangles (rectangles, stippled);
- }
- if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime);
- if (kbdGrabResult == OS.GrabSuccess) OS.XUngrabKeyboard (xDisplay, OS.CurrentTime);
- window = 0;
- return !cancelled;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Resize, listener);
- eventTable.unhook (SWT.Move, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #addKeyListener
- */
-public void removeKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.KeyUp, listener);
- eventTable.unhook(SWT.KeyDown, listener);
-}
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
- rectangles = proportions = null;
- bounds = null;
-}
-void resizeRectangles (int xChange, int yChange) {
- if (bounds == null) return;
- /*
- * If the cursor orientation has not been set in the orientation of
- * this change then try to set it here.
- */
- if (xChange < 0 && ((style & SWT.LEFT) != 0) && ((cursorOrientation & SWT.RIGHT) == 0)) {
- cursorOrientation |= SWT.LEFT;
- }
- if (xChange > 0 && ((style & SWT.RIGHT) != 0) && ((cursorOrientation & SWT.LEFT) == 0)) {
- cursorOrientation |= SWT.RIGHT;
- }
- if (yChange < 0 && ((style & SWT.UP) != 0) && ((cursorOrientation & SWT.DOWN) == 0)) {
- cursorOrientation |= SWT.UP;
- }
- if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) {
- cursorOrientation |= SWT.DOWN;
- }
-
- /*
- * If the bounds will flip about the x or y axis then apply the adjustment
- * up to the axis (ie.- where bounds width/height becomes 0), change the
- * cursor's orientation accordingly, and flip each Rectangle's origin (only
- * necessary for > 1 Rectangles)
- */
- if ((cursorOrientation & SWT.LEFT) != 0) {
- if (xChange > bounds.width) {
- if ((style & SWT.RIGHT) == 0) return;
- cursorOrientation |= SWT.RIGHT;
- cursorOrientation &= ~SWT.LEFT;
- bounds.x += bounds.width;
- xChange -= bounds.width;
- bounds.width = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.x = 100 - proportion.x - proportion.width;
- }
- }
- }
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- if (bounds.width < -xChange) {
- if ((style & SWT.LEFT) == 0) return;
- cursorOrientation |= SWT.LEFT;
- cursorOrientation &= ~SWT.RIGHT;
- xChange += bounds.width;
- bounds.width = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.x = 100 - proportion.x - proportion.width;
- }
- }
- }
- }
- if ((cursorOrientation & SWT.UP) != 0) {
- if (yChange > bounds.height) {
- if ((style & SWT.DOWN) == 0) return;
- cursorOrientation |= SWT.DOWN;
- cursorOrientation &= ~SWT.UP;
- bounds.y += bounds.height;
- yChange -= bounds.height;
- bounds.height = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.y = 100 - proportion.y - proportion.height;
- }
- }
- }
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- if (bounds.height < -yChange) {
- if ((style & SWT.UP) == 0) return;
- cursorOrientation |= SWT.UP;
- cursorOrientation &= ~SWT.DOWN;
- yChange += bounds.height;
- bounds.height = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.y = 100 - proportion.y - proportion.height;
- }
- }
- }
- }
-
- // apply the bounds adjustment
- if ((cursorOrientation & SWT.LEFT) != 0) {
- bounds.x += xChange;
- bounds.width -= xChange;
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- bounds.width += xChange;
- }
- if ((cursorOrientation & SWT.UP) != 0) {
- bounds.y += yChange;
- bounds.height -= yChange;
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- bounds.height += yChange;
- }
-
- Rectangle [] newRects = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle proportion = proportions[i];
- newRects[i] = new Rectangle (
- proportion.x * bounds.width / 100 + bounds.x,
- proportion.y * bounds.height / 100 + bounds.y,
- proportion.width * bounds.width / 100,
- proportion.height * bounds.height / 100);
- }
- rectangles = newRects;
-}
-
-/**
- * Sets the <code>Cursor</code> of the Tracker. If this cursor is <code>null</code>
- * then the cursor reverts to the default.
- *
- * @param newCursor the new <code>Cursor</code> to display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCursor (Cursor value) {
- checkWidget ();
- cursor = value;
-}
-/**
- * Specifies the rectangles that should be drawn, expressed relative to the parent
- * widget. If the parent is a Display then these are screen coordinates.
- *
- * @param rectangles the bounds of the rectangles to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of rectangles is null or contains a null rectangle</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setRectangles (Rectangle [] rectangles) {
- checkWidget ();
- if (rectangles == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.rectangles = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- if (current == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.rectangles [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- proportions = computeProportions (rectangles);
-}
-/**
- * Changes the appearance of the line used to draw the rectangles.
- *
- * @param stippled <code>true</code> if rectangle should appear stippled
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setStippled (boolean stippled) {
- checkWidget ();
- this.stippled = stippled;
-}
-void update () {
- if (parent != null) {
- if (parent.isDisposed ()) return;
- parent.getShell ().update ();
- } else {
- display.update ();
- }
-}
-int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- return xMouse (OS.ButtonRelease, w, client_data, call_data, continue_to_dispatch);
-}
-
-int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XKeyPress (w, client_data, call_data, continue_to_dispatch);
- if (result != 0) return result;
- XKeyEvent keyEvent = new XKeyEvent ();
- OS.memmove (keyEvent, call_data, XKeyEvent.sizeof);
- if (keyEvent.keycode != 0) {
- int [] keysym = new int [1];
- OS.XLookupString (keyEvent, null, 0, keysym, null);
- keysym [0] &= 0xFFFF;
- int xChange = 0, yChange = 0;
- int stepSize = ((keyEvent.state & OS.ControlMask) != 0) ? STEPSIZE_SMALL : STEPSIZE_LARGE;
- switch (keysym [0]) {
- case OS.XK_KP_Enter:
- case OS.XK_Return:
- tracking = false;
- /* Eat the subsequent KeyRelease event */
- OS.XtAppNextEvent (OS.XtDisplayToApplicationContext (keyEvent.display), call_data);
- break;
- case OS.XK_Escape:
- tracking = false;
- cancelled = true;
- /* Eat the subsequent KeyRelease event */
- OS.XtAppNextEvent (OS.XtDisplayToApplicationContext (keyEvent.display), call_data);
- break;
- case OS.XK_Left:
- xChange = -stepSize;
- break;
- case OS.XK_Right:
- xChange = stepSize;
- break;
- case OS.XK_Up:
- yChange = -stepSize;
- break;
- case OS.XK_Down:
- yChange = stepSize;
- break;
- }
- if (xChange != 0 || yChange != 0) {
- Rectangle [] oldRectangles = rectangles;
- boolean oldStippled = stippled;
- Rectangle [] rectsToErase = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- rectsToErase [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- Event event = new Event ();
- event.x = oldX + xChange;
- event.y = oldY + yChange;
- Point cursorPos;
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (xChange, yChange);
- sendEvent (SWT.Resize, event);
- /*
- * It is possible (but unlikely) that application code
- * could have disposed the widget in the resize event.
- * If this happens then return false to indicate that
- * the move failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return 1;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the resize event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (rectsToErase, oldStippled);
- update ();
- drawRectangles (rectangles, stippled);
- }
- cursorPos = adjustResizeCursor ();
- } else {
- moveRectangles (xChange, yChange);
- sendEvent (SWT.Move, event);
- /*
- * It is possible (but unlikely) that application code
- * could have disposed the widget in the move event.
- * If this happens then return false to indicate that
- * the move failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return 1;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the move event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (rectsToErase, oldStippled);
- update ();
- drawRectangles (rectangles, stippled);
- }
- cursorPos = adjustMoveCursor ();
- }
- if (cursorPos != null) {
- oldX = cursorPos.x;
- oldY = cursorPos.y;
- }
- }
- }
- return result;
-}
-
-int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) {
- if (cursor != null) {
- int xDisplay = display.xDisplay;
- OS.XChangeActivePointerGrab (xDisplay,
- OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask,
- cursor.handle, OS.CurrentTime);
- }
- return xMouse (OS.MotionNotify, w, client_data, call_data, continue_to_dispatch);
-}
-
-int xMouse (int type, int w, int client_data, int call_data, int continue_to_dispatch) {
- int xDisplay = display.xDisplay;
- int [] newX = new int [1], newY = new int [1], unused = new int [1];
- OS.XQueryPointer (xDisplay, window, unused, unused, newX, newY, unused, unused, unused);
- if (oldX != newX [0] || oldY != newY [0]) {
- Rectangle [] oldRectangles = rectangles;
- boolean oldStippled = stippled;
- Rectangle [] rectsToErase = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- rectsToErase [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- Event event = new Event ();
- event.x = newX [0];
- event.y = newY [0];
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (newX [0] - oldX, newY [0] - oldY);
- sendEvent (SWT.Resize, event);
- /*
- * It is possible (but unlikely) that application code
- * could have disposed the widget in the resize event.
- * If this happens then return false to indicate that
- * the move failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return 1;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the resize event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (rectsToErase, oldStippled);
- update ();
- drawRectangles (rectangles, stippled);
- }
- Point cursorPos = adjustResizeCursor ();
- if (cursorPos != null) {
- newX [0] = cursorPos.x;
- newY [0] = cursorPos.y;
- }
- } else {
- moveRectangles (newX [0] - oldX, newY [0] - oldY);
- sendEvent (SWT.Move, event);
- /*
- * It is possible (but unlikely) that application code
- * could have disposed the widget in the move event.
- * If this happens then return false to indicate that
- * the move failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return 1;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the move event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (rectsToErase, oldStippled);
- update ();
- drawRectangles (rectangles, stippled);
- }
- }
- oldX = newX [0];
- oldY = newY [0];
- }
- tracking = type != OS.ButtonRelease;
- return 0;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java
deleted file mode 100755
index de1353482c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java
+++ /dev/null
@@ -1,1260 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
-/**
- * This class is the abstract superclass of all user interface objects.
- * Widgets are created, disposed and issue notification to listeners
- * when events occur which affect them.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Dispose</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation. However, it has not been marked
- * final to allow those outside of the SWT development team to implement
- * patched versions of the class in order to get around specific
- * limitations in advance of when those limitations can be addressed
- * by the team. Any class built using subclassing to access the internals
- * of this class will likely fail to compile or run between releases and
- * may be strongly platform specific. Subclassing should not be attempted
- * without an intimate and detailed understanding of the workings of the
- * hierarchy. No support is provided for user-written classes which are
- * implemented as subclasses of this class.
- * </p>
- *
- * @see #checkSubclass
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class Widget {
- /**
- * the handle to the OS resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
- int style, state;
- Display display;
- EventTable eventTable;
- Object data;
-
- /* Global state flags */
- static final int DISPOSED = 1<<0;
- static final int CANVAS = 1<<1;
- static final int KEYED_DATA = 1<<2;
- static final int FOCUS_FORCED = 1<<3;
- static final int BACKGROUND = 1<<4;
- static final int FOREGROUND = 1<<5;
- static final int PARENT_BACKGROUND = 1<<6;
- static final int THEME_BACKGROUND = 1<<7;
-
- /* A layout was requested on this widget */
- static final int LAYOUT_NEEDED = 1<<8;
-
- /* The preferred size of a child has changed */
- static final int LAYOUT_CHANGED = 1<<9;
-
- /* A layout was requested in this widget hierachy */
- static final int LAYOUT_CHILD = 1<<10;
-
- /* More global state flags */
- static final int RELEASED = 1<<11;
- static final int DISPOSE_SENT = 1<<12;
- static final int FOREIGN_HANDLE = 1<<13;
- static final int DRAG_DETECT = 1<<14;
-
- /* Default size for widgets */
- static final int DEFAULT_WIDTH = 64;
- static final int DEFAULT_HEIGHT = 64;
-
- /* Events and Callback constants */
- static final int BUTTON_PRESS = 1;
- static final int BUTTON_RELEASE = 2;
- static final int EXPOSURE = 3;
- static final int ENTER_WINDOW = 4;
- static final int FOCUS_CHANGE = 5;
- static final int KEY_PRESS = 6;
- static final int KEY_RELEASE = 7;
- static final int LEAVE_WINDOW = 8;
- static final int ACTIVATE_CALLBACK = 9;
- static final int ARM_CALLBACK = 10;
- static final int BROWSE_SELECTION_CALLBACK = 11;
- static final int CASCADING_CALLBACK = 12;
- static final int DECREMENT_CALLBACK = 13;
- static final int DEFAULT_ACTION_CALLBACK = 14;
- static final int DRAG_CALLBACK = 15;
- static final int EXTENDED_SELECTION_CALLBACK = 16;
- static final int HELP_CALLBACK = 17;
- static final int INCREMENT_CALLBACK = 18;
- static final int MODIFY_VERIFY_CALLBACK = 19;
- static final int PAGE_DECREMENT_CALLBACK = 20;
- static final int PAGE_INCREMENT_CALLBACK = 21;
- static final int TO_BOTTOM_CALLBACK = 22;
- static final int TO_TOP_CALLBACK = 23;
- static final int VALUE_CHANGED_CALLBACK = 24;
- static final int NON_MASKABLE = 25;
- static final int POINTER_MOTION = 26;
- static final int STRUCTURE_NOTIFY = 27;
- static final int MAP_CALLBACK = 28;
- static final int UNMAP_CALLBACK = 29;
- static final int DELETE_WINDOW = 30;
- static final int EXPOSURE_CALLBACK = 31;
- static final int MULTIPLE_SELECTION_CALLBACK = 32;
- static final int PROPERTY_CHANGE = 33;
-
-Widget () {
- /* Do nothing */
-}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see #checkSubclass
- * @see #getStyle
- */
-public Widget (Widget parent, int style) {
- checkSubclass ();
- checkParent (parent);
- this.style = style;
- display = parent.display;
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs. When the
- * event does occur in the widget, the listener is notified by
- * sending it the <code>handleEvent()</code> message. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #getListeners(int)
- * @see #removeListener(int, Listener)
- * @see #notifyListeners
- */
-public void addListener (int eventType, Listener handler) {
- checkWidget();
- if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) eventTable = new EventTable ();
- eventTable.hook (eventType, handler);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the widget is disposed. When the widget is
- * disposed, the listener is notified by sending it the
- * <code>widgetDisposed()</code> message.
- *
- * @param listener the listener which should be notified when the receiver is disposed
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DisposeListener
- * @see #removeDisposeListener
- */
-public void addDisposeListener (DisposeListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Dispose, typedListener);
-}
-static int checkBits (int style, int int0, int int1, int int2, int int3, int int4, int int5) {
- int mask = int0 | int1 | int2 | int3 | int4 | int5;
- if ((style & mask) == 0) style |= int0;
- if ((style & int0) != 0) style = (style & ~mask) | int0;
- if ((style & int1) != 0) style = (style & ~mask) | int1;
- if ((style & int2) != 0) style = (style & ~mask) | int2;
- if ((style & int3) != 0) style = (style & ~mask) | int3;
- if ((style & int4) != 0) style = (style & ~mask) | int4;
- if ((style & int5) != 0) style = (style & ~mask) | int5;
- return style;
-}
-void checkOpen () {
- /* Do nothing */
-}
-void checkOrientation (Widget parent) {
- style &= ~SWT.MIRRORED;
- if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) {
- if (parent != null) {
- if ((parent.style & SWT.LEFT_TO_RIGHT) != 0) style |= SWT.LEFT_TO_RIGHT;
- if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) style |= SWT.RIGHT_TO_LEFT;
- }
- }
- style = checkBits (style, SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT, 0, 0, 0, 0);
-}
-void checkParent (Widget parent) {
- if (parent == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (parent.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- parent.checkWidget ();
- parent.checkOpen ();
-}
-/**
- * Checks that this class can be subclassed.
- * <p>
- * The SWT class library is intended to be subclassed
- * only at specific, controlled points (most notably,
- * <code>Composite</code> and <code>Canvas</code> when
- * implementing new widgets). This method enforces this
- * rule unless it is overridden.
- * </p><p>
- * <em>IMPORTANT:</em> By providing an implementation of this
- * method that allows a subclass of a class which does not
- * normally allow subclassing to be created, the implementer
- * agrees to be fully responsible for the fact that any such
- * subclass will likely fail between SWT releases and will be
- * strongly platform specific. No support is provided for
- * user-written classes which are implemented in this fashion.
- * </p><p>
- * The ability to subclass outside of the allowed SWT classes
- * is intended purely to enable those not on the SWT development
- * team to implement patches in order to get around specific
- * limitations in advance of when those limitations can be
- * addressed by the team. Subclassing should not be attempted
- * without an intimate and detailed understanding of the hierarchy.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-/**
- * Throws an <code>SWTException</code> if the receiver can not
- * be accessed by the caller. This may include both checks on
- * the state of the receiver and more generally on the entire
- * execution context. This method <em>should</em> be called by
- * widget implementors to enforce the standard SWT invariants.
- * <p>
- * Currently, it is an error to invoke any method (other than
- * <code>isDisposed()</code>) on a widget that has had its
- * <code>dispose()</code> method called. It is also an error
- * to call widget methods from any thread that is different
- * from the thread that created the widget.
- * </p><p>
- * In future releases of SWT, there may be more or fewer error
- * checks and exceptions may be thrown for different reasons.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-protected void checkWidget () {
- Display display = this.display;
- if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
- if (display.thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if ((state & DISPOSED) != 0) error (SWT.ERROR_WIDGET_DISPOSED);
-}
-void createHandle (int index) {
- /* Do nothing */
-}
-void createWidget (int index) {
- createHandle (index);
- hookEvents ();
- register ();
- manageChildren ();
-}
-void deregister () {
- if (handle == 0) return;
- display.removeWidget (handle);
-}
-void destroyWidget () {
- int topHandle = topHandle ();
- releaseHandle ();
- if (topHandle != 0) {
- OS.XtDestroyWidget (topHandle);
- }
-}
-/**
- * Disposes of the operating system resources associated with
- * the receiver and all its descendants. After this method has
- * been invoked, the receiver and all descendants will answer
- * <code>true</code> when sent the message <code>isDisposed()</code>.
- * Any internal connections between the widgets in the tree will
- * have been removed to facilitate garbage collection.
- * <p>
- * NOTE: This method is not called recursively on the descendants
- * of the receiver. This means that, widget implementers can not
- * detect when a widget is being disposed of by re-implementing
- * this method, but should instead listen for the <code>Dispose</code>
- * event.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #addDisposeListener
- * @see #removeDisposeListener
- * @see #checkWidget
- */
-public void dispose () {
- /*
- * Note: It is valid to attempt to dispose a widget
- * more than once. If this happens, fail silently.
- */
- if (isDisposed ()) return;
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- release (true);
-}
-void enableHandle (boolean enabled, int widgetHandle) {
- int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
- OS.XtSetValues (widgetHandle, argList, argList.length / 2);
-}
-void error (int code) {
- SWT.error(code);
-}
-boolean filters (int eventType) {
- return display.filters (eventType);
-}
-static char fixMnemonic (char [] buffer) {
- int i=0, j=0;
- char mnemonic=0;
- while (i < buffer.length) {
- if ((buffer [j++] = buffer [i++]) == '&') {
- if (i == buffer.length) {continue;}
- if (buffer [i] == '&') {i++; continue;}
- if (mnemonic == 0) mnemonic = buffer [i];
- j--;
- }
- }
- while (j < buffer.length) buffer [j++] = 0;
- return mnemonic;
-}
-int focusProc (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-String getCodePage () {
- return null;
-}
-/**
- * Returns the application defined widget data associated
- * with the receiver, or null if it has not been set. The
- * <em>widget data</em> is a single, unnamed field that is
- * stored with every widget.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the widget data needs to be notified
- * when the widget is disposed of, it is the application's
- * responsibility to hook the Dispose event on the widget and
- * do so.
- * </p>
- *
- * @return the widget data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
- * </ul>
- *
- * @see #setData(Object)
- */
-public Object getData () {
- checkWidget();
- return (state & KEYED_DATA) != 0 ? ((Object []) data) [0] : data;
-}
-
-/**
- * Returns the application defined property of the receiver
- * with the specified name, or null if it has not been set.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the widget is disposed
- * of, it is the application's responsibility to hook the
- * Dispose event on the widget and do so.
- * </p>
- *
- * @param key the name of the property
- * @return the value of the property or null if it has not been set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setData(String, Object)
- */
-public Object getData (String key) {
- checkWidget();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((state & KEYED_DATA) != 0) {
- Object [] table = (Object []) data;
- for (int i=1; i<table.length; i+=2) {
- if (key.equals (table [i])) return table [i+1];
- }
- }
- return null;
-}
-
-/**
- * Returns the <code>Display</code> that is associated with
- * the receiver.
- * <p>
- * A widget's display is either provided when it is created
- * (for example, top level <code>Shell</code>s) or is the
- * same as its parent's display.
- * </p>
- *
- * @return the receiver's display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Display getDisplay () {
- Display display = this.display;
- if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return display;
-}
-/**
- * Returns an array of listeners who will be notified when an event
- * of the given type occurs. The event type is one of the event constants
- * defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @return an array of listeners that will be notified when the event occurs
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener(int, Listener)
- * @see #removeListener(int, Listener)
- * @see #notifyListeners
- *
- * @since 3.4
- */
-public Listener[] getListeners (int eventType) {
- checkWidget();
- if (eventTable == null) return new Listener[0];
- return eventTable.getListeners(eventType);
-}
-String getName () {
- String string = getClass ().getName ();
- int index = string.lastIndexOf ('.');
- if (index == -1) return string;
- return string.substring (index + 1, string.length ());
-}
-String getNameText () {
- return "";
-}
-/**
- * Returns the receiver's style information.
- * <p>
- * Note that the value which is returned by this method <em>may
- * not match</em> the value which was provided to the constructor
- * when the receiver was created. This can occur when the underlying
- * operating system does not support a particular combination of
- * requested styles. For example, if the platform widget used to
- * implement a particular SWT widget always has scroll bars, the
- * result of calling this method would always have the
- * <code>SWT.H_SCROLL</code> and <code>SWT.V_SCROLL</code> bits set.
- * </p>
- *
- * @return the style bits
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getStyle () {
- checkWidget();
- return style;
-}
-void hookEvents () {
- /* Do nothing */
-}
-boolean hooks (int eventType) {
- if (eventTable == null) return false;
- return eventTable.hooks (eventType);
-}
-/**
- * Returns <code>true</code> if the widget has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the widget.
- * When a widget has been disposed, it is an error to
- * invoke any other method using the widget.
- * </p>
- *
- * @return <code>true</code> when the widget is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- return (state & DISPOSED) != 0;
-}
-/**
- * Returns <code>true</code> if there are any listeners
- * for the specified event type associated with the receiver,
- * and <code>false</code> otherwise. The event type is one of
- * the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event
- * @return true if the event is hooked
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public boolean isListening (int eventType) {
- checkWidget();
- return hooks (eventType);
-}
-boolean isValidSubclass () {
- return Display.isValidClass (getClass ());
-}
-boolean isValidThread () {
- return getDisplay ().isValidThread ();
-}
-void manageChildren () {
- /* Do nothing */
-}
-/**
- * Notifies all of the receiver's listeners for events
- * of the given type that one such event has occurred by
- * invoking their <code>handleEvent()</code> method. The
- * event type is one of the event constants defined in class
- * <code>SWT</code>.
- *
- * @param eventType the type of event which has occurred
- * @param event the event data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- * @see #addListener
- * @see #getListeners(int)
- * @see #removeListener(int, Listener)
- */
-public void notifyListeners (int eventType, Event event) {
- checkWidget();
- if (event == null) event = new Event ();
- sendEvent (eventType, event);
-}
-void postEvent (int eventType) {
- sendEvent (eventType, null, false);
-}
-void postEvent (int eventType, Event event) {
- sendEvent (eventType, event, false);
-}
-void propagateHandle (boolean enabled, int widgetHandle, int cursor) {
- int xDisplay = OS.XtDisplay (widgetHandle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (widgetHandle);
- if (xWindow == 0) return;
- /*
- * Get the event mask from the widget. The event mask
- * returned by XtBuildEventMask () includes the masks
- * associated with all callbacks and event handlers
- * that have been hooked on the widget.
- */
- int event_mask = OS.XtBuildEventMask (widgetHandle);
- int do_not_propagate_mask =
- OS.KeyPressMask | OS.KeyReleaseMask | OS.ButtonPressMask |
- OS.ButtonReleaseMask | OS.PointerMotionMask;
- if (!enabled) {
- /*
- * Attempting to propogate EnterWindowMask and LeaveWindowMask
- * causes an X error so these must be specially cleared out from
- * the event mask, not included in the propogate mask.
- */
- event_mask &= ~(do_not_propagate_mask | OS.EnterWindowMask | OS.LeaveWindowMask);
- do_not_propagate_mask = 0;
- }
- int mask = OS.CWDontPropagate | OS.CWEventMask | OS.CWCursor;
- XSetWindowAttributes attributes = new XSetWindowAttributes ();
- attributes.event_mask = event_mask;
- attributes.do_not_propagate_mask = do_not_propagate_mask;
- attributes.cursor = cursor;
- OS.XChangeWindowAttributes (xDisplay, xWindow, mask, attributes);
-}
-void redrawHandle (int x, int y, int width, int height, boolean redrawAll, int widgetHandle) {
- int display = OS.XtDisplay (widgetHandle);
- if (display == 0) return;
- int window = OS.XtWindow (widgetHandle);
- if (window == 0) return;
- if (redrawAll) {
- OS.XClearArea (display, window, 0, 0, 0, 0, true);
- } else {
- if (width > 0 && height > 0) {
- int [] argList = {
- OS.XmNwidth, 0, /* 1 */
- OS.XmNheight, 0, /* 3 */
- };
- OS.XtGetValues (widgetHandle, argList, argList.length / 2);
- if ((x < argList [1]) && (y < argList [3]) && (x + width > 0) && (y + height > 0)) {
- OS.XClearArea (display, window, x, y, width, height, true);
- }
- }
- }
-}
-void register () {
- if (handle == 0) return;
- display.addWidget (handle, this);
-}
-void release (boolean destroy) {
- if ((state & DISPOSE_SENT) == 0) {
- state |= DISPOSE_SENT;
- sendEvent (SWT.Dispose);
- }
- if ((state & DISPOSED) == 0) {
- releaseChildren (destroy);
- }
- if ((state & RELEASED) == 0) {
- state |= RELEASED;
- if (destroy) {
- releaseParent ();
- releaseWidget ();
- destroyWidget ();
- } else {
- releaseWidget ();
- releaseHandle ();
- }
- }
-}
-void releaseChildren (boolean destroy) {
-}
-void releaseHandle () {
- handle = 0;
- state |= DISPOSED;
- display = null;
-}
-void releaseParent () {
- /* Do nothing */
-}
-void releaseWidget () {
- deregister ();
- eventTable = null;
- data = null;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener
- * @see #getListeners(int)
- * @see #notifyListeners
- */
-public void removeListener (int eventType, Listener handler) {
- checkWidget();
- if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, handler);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It should never be
- * referenced from application code.
- * </p>
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see #addListener
- */
-protected void removeListener (int eventType, SWTEventListener handler) {
- checkWidget();
- if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, handler);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the widget is disposed.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DisposeListener
- * @see #addDisposeListener
- */
-public void removeDisposeListener (DisposeListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Dispose, listener);
-}
-boolean setInputState (Event event, int state) {
- if ((state & OS.Mod1Mask) != 0) event.stateMask |= SWT.ALT;
- if ((state & OS.ShiftMask) != 0) event.stateMask |= SWT.SHIFT;
- if ((state & OS.ControlMask) != 0) event.stateMask |= SWT.CONTROL;
- if ((state & OS.Button1Mask) != 0) event.stateMask |= SWT.BUTTON1;
- if ((state & OS.Button2Mask) != 0) event.stateMask |= SWT.BUTTON2;
- if ((state & OS.Button3Mask) != 0) event.stateMask |= SWT.BUTTON3;
- return true;
-}
-boolean setKeyState (Event event, XKeyEvent xEvent) {
- if (xEvent.keycode == 0) return false;
- byte [] buffer = new byte [5];
- int [] keysym = new int [1];
- OS.XLookupString (xEvent, buffer, buffer.length, keysym, null);
- boolean isNull = display.fixKey (keysym, buffer, xEvent.state);
- if (keysym [0] != 0) {
- event.keyCode = Display.translateKey (keysym [0]);
- }
- if (event.keyCode == 0) {
- byte [] buffer1 = new byte [5];
- int [] keysym1 = new int [1];
- int oldState = xEvent.state;
- xEvent.state = 0;
- OS.XLookupString (xEvent, buffer1, buffer1.length, keysym1, null);
- xEvent.state = oldState;
- if (buffer1 [0] != 0) {
- char [] result = Converter.mbcsToWcs (null, buffer1);
- if (result.length != 0) event.keyCode = result [0];
- }
- }
- if (buffer [0] != 0) {
- char [] result = Converter.mbcsToWcs (null, buffer);
- if (result.length != 0) event.character = result [0];
- }
- if (event.keyCode == 0 && event.character == 0) {
- if (!isNull) return false;
- }
- return setInputState (event, xEvent.state);
-}
-void sendEvent (Event event) {
- Display display = event.display;
- if (!display.filterEvent (event)) {
- if (eventTable != null) eventTable.sendEvent (event);
- }
-}
-void sendEvent (int eventType) {
- sendEvent (eventType, null, true);
-}
-void sendEvent (int eventType, Event event) {
- sendEvent (eventType, event, true);
-}
-void sendEvent (int eventType, Event event, boolean send) {
- if (eventTable == null && !display.filters (eventType)) {
- return;
- }
- if (event == null) event = new Event ();
- event.type = eventType;
- event.display = display;
- event.widget = this;
- if (event.time == 0) {
- event.time = display.getLastEventTime ();
- }
- if (send) {
- sendEvent (event);
- } else {
- display.postEvent (event);
- }
-}
-boolean sendIMKeyEvent (int type, XKeyEvent xEvent) {
- return sendIMKeyEvent (type, xEvent, 0);
-}
-boolean sendIMKeyEvent (int type, XKeyEvent xEvent, int textHandle) {
- /*
- * Bug in Motif. On Linux only, XmImMbLookupString () does not return
- * XBufferOverflow as the status if the buffer is too small. The fix
- * is to pass a large buffer.
- */
- byte [] buffer = new byte [512];
- int [] status = new int [1], unused = new int [1];
- int focusHandle = OS.XtWindowToWidget (xEvent.display, xEvent.window);
- int length = OS.XmImMbLookupString (focusHandle, xEvent, buffer, buffer.length, unused, status);
- if (status [0] == OS.XBufferOverflow) {
- buffer = new byte [length];
- length = OS.XmImMbLookupString (focusHandle, xEvent, buffer, length, unused, status);
- }
- if (length == 0) return true;
-
- /* Convert from MBCS to UNICODE and send the event */
- /* Use the character encoding for the default locale */
- char [] chars = Converter.mbcsToWcs (null, buffer);
- int index = 0, count = 0;
- while (index < chars.length) {
- if (chars [index] == 0) {
- chars [count] = 0;
- break;
- }
- Event event = new Event ();
- event.time = xEvent.time;
- event.character = chars [index];
- setInputState (event, xEvent.state);
- sendEvent (type, event);
- // widget could be disposed at this point
-
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the key
- * events. If this happens, end the processing of
- * the key by returning false.
- */
- if (isDisposed ()) return false;
- if (event.doit) chars [count++] = chars [index];
- index++;
- }
- if (count == 0) return false;
- if (textHandle != 0) {
- /*
- * Bug in Motif. On Solaris and Linux, XmImMbLookupString() clears
- * the characters from the IME. This causes the characters to be
- * stolen from the text widget. The fix is to detect that the IME
- * has been cleared and use XmTextInsert() to insert the stolen
- * characters. This problem does not happen on AIX.
- */
- byte [] testBuffer = new byte [5];
- int testLength = OS.XmImMbLookupString (textHandle, xEvent, testBuffer, testBuffer.length, unused, unused);
- if (testLength == 0 || index != count) {
- int [] start = new int [1], end = new int [1];
- OS.XmTextGetSelectionPosition (textHandle, start, end);
- if (start [0] == end [0]) {
- start [0] = end [0] = OS.XmTextGetInsertionPosition (textHandle);
- }
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- if (index != count) {
- buffer = Converter.wcsToMbcs (getCodePage (), chars, true);
- }
- OS.XmTextReplace (textHandle, start [0], end [0], buffer);
- int position = start [0] + count;
- OS.XmTextSetInsertionPosition (textHandle, position);
- display.setWarnings (warnings);
- return false;
- }
- }
- return true;
-}
-boolean sendKeyEvent (int type, XKeyEvent xEvent) {
- Event event = new Event ();
- event.time = xEvent.time;
- if (!setKeyState (event, xEvent)) return true;
- Widget control = this;
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_FOCUS) != 0) {
- control = display.getFocusControl ();
- }
- }
- if (control != null) {
- control.sendEvent (type, event);
- // widget could be disposed at this point
-
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the key
- * events. If this happens, end the processing of
- * the key by returning false.
- */
- if (isDisposed ()) return false;
- }
- return event.doit;
-}
-/**
- * Sets the application defined widget data associated
- * with the receiver to be the argument. The <em>widget
- * data</em> is a single, unnamed field that is stored
- * with every widget.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the widget data needs to be notified
- * when the widget is disposed of, it is the application's
- * responsibility to hook the Dispose event on the widget and
- * do so.
- * </p>
- *
- * @param data the widget data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
- * </ul>
- *
- * @see #getData()
- */
-public void setData (Object data) {
- checkWidget();
- if ((state & KEYED_DATA) != 0) {
- ((Object []) this.data) [0] = data;
- } else {
- this.data = data;
- }
-}
-
-/**
- * Sets the application defined property of the receiver
- * with the specified name to the given value.
- * <p>
- * Applications may associate arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the widget is disposed
- * of, it is the application's responsibility to hook the
- * Dispose event on the widget and do so.
- * </p>
- *
- * @param key the name of the property
- * @param value the new value for the property
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getData(String)
- */
-public void setData (String key, Object value) {
- checkWidget();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = 1;
- Object [] table = null;
- if ((state & KEYED_DATA) != 0) {
- table = (Object []) data;
- while (index < table.length) {
- if (key.equals (table [index])) break;
- index += 2;
- }
- }
- if (value != null) {
- if ((state & KEYED_DATA) != 0) {
- if (index == table.length) {
- Object [] newTable = new Object [table.length + 2];
- System.arraycopy (table, 0, newTable, 0, table.length);
- data = table = newTable;
- }
- } else {
- table = new Object [3];
- table [0] = data;
- data = table;
- state |= KEYED_DATA;
- }
- table [index] = key;
- table [index + 1] = value;
- } else {
- if ((state & KEYED_DATA) != 0) {
- if (index != table.length) {
- int length = table.length - 2;
- if (length == 1) {
- data = table [0];
- state &= ~KEYED_DATA;
- } else {
- Object [] newTable = new Object [length];
- System.arraycopy (table, 0, newTable, 0, index);
- System.arraycopy (table, index + 2, newTable, index, length - index);
- data = newTable;
- }
- }
- }
- }
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- String string = "*Disposed*";
- if (!isDisposed ()) {
- string = "*Wrong Thread*";
- if (isValidThread ()) string = getNameText ();
- }
- return getName () + " {" + string + "}";
-}
-int topHandle () {
- return handle;
-}
-boolean translateAccelerator (char key, int keysym, XKeyEvent xEvent, boolean doit) {
- return false;
-}
-boolean translateMnemonic (char key, int keysym, XKeyEvent xEvent) {
- return false;
-}
-boolean translateTraversal (int key, XKeyEvent xEvent) {
- return false;
-}
-boolean XmProcessTraversal (int widget, int direction) {
- /*
- * Bug in Motif. When XtDestroyWidget() is called from
- * within a FocusOut event handler, Motif GP's. The fix
- * is to post focus events and run them when the handler
- * has returned.
- */
- Display display = this.display;
- boolean oldFocusOut = display.postFocusOut;
- display.postFocusOut = true;
- boolean result = OS.XmProcessTraversal (widget, direction);
- display.postFocusOut = oldFocusOut;
- if (!display.postFocusOut) {
- display.focusEvent = SWT.FocusOut;
- display.runFocusOutEvents ();
- display.focusEvent = SWT.None;
- }
- return result;
-}
-int hoverProc (int widget) {
- return 0;
-}
-int timerProc (int id) {
- return 0;
-}
-int windowProc (int w, int client_data, int call_data, int continue_to_dispatch) {
- switch (client_data) {
- case BUTTON_PRESS: return XButtonPress (w, client_data, call_data, continue_to_dispatch);
- case BUTTON_RELEASE: return XButtonRelease (w, client_data, call_data, continue_to_dispatch);
- case ENTER_WINDOW: return XEnterWindow (w, client_data, call_data, continue_to_dispatch);
- case EXPOSURE: return XExposure (w, client_data, call_data, continue_to_dispatch);
- case FOCUS_CHANGE: return XFocusChange (w, client_data, call_data, continue_to_dispatch);
- case KEY_PRESS: return XKeyPress (w, client_data, call_data, continue_to_dispatch);
- case KEY_RELEASE: return XKeyRelease (w, client_data, call_data, continue_to_dispatch);
- case LEAVE_WINDOW: return XLeaveWindow (w, client_data, call_data, continue_to_dispatch);
- case PROPERTY_CHANGE: return XPropertyChange (w, client_data, call_data, continue_to_dispatch);
- case ACTIVATE_CALLBACK: return XmNactivateCallback (w, client_data, call_data);
- case ARM_CALLBACK: return XmNarmCallback (w, client_data, call_data);
- case BROWSE_SELECTION_CALLBACK: return XmNbrowseSelectionCallback (w, client_data, call_data);
- case CASCADING_CALLBACK: return XmNcascadingCallback (w, client_data, call_data);
- case DECREMENT_CALLBACK: return XmNdecrementCallback (w, client_data, call_data);
- case DEFAULT_ACTION_CALLBACK: return XmNdefaultActionCallback (w, client_data, call_data);
- case DRAG_CALLBACK: return XmNdragCallback (w, client_data, call_data);
- case EXTENDED_SELECTION_CALLBACK: return XmNextendedSelectionCallback (w, client_data, call_data);
- case HELP_CALLBACK: return XmNhelpCallback (w, client_data, call_data);
- case INCREMENT_CALLBACK: return XmNincrementCallback (w, client_data, call_data);
- case MODIFY_VERIFY_CALLBACK: return XmNmodifyVerifyCallback (w, client_data, call_data);
- case MULTIPLE_SELECTION_CALLBACK: return XmNmultipleSelectionCallback (w, client_data, call_data);
- case PAGE_DECREMENT_CALLBACK: return XmNpageDecrementCallback (w, client_data, call_data);
- case PAGE_INCREMENT_CALLBACK: return XmNpageIncrementCallback (w, client_data, call_data);
- case TO_BOTTOM_CALLBACK: return XmNtoBottomCallback (w, client_data, call_data);
- case TO_TOP_CALLBACK: return XmNtoTopCallback (w, client_data, call_data);
- case VALUE_CHANGED_CALLBACK: return XmNvalueChangedCallback (w, client_data, call_data);
- case NON_MASKABLE: return XNonMaskable (w, client_data, call_data, continue_to_dispatch);
- case POINTER_MOTION : return XPointerMotion (w, client_data, call_data, continue_to_dispatch);
- case STRUCTURE_NOTIFY: return XStructureNotify (w, client_data, call_data, continue_to_dispatch);
- case MAP_CALLBACK: return XmNmapCallback (w, client_data, call_data);
- case UNMAP_CALLBACK: return XmNunmapCallback (w, client_data, call_data);
- case DELETE_WINDOW: return WM_DELETE_WINDOW (w, client_data, call_data);
- case EXPOSURE_CALLBACK: return XmNexposureCallback (w, client_data, call_data);
- }
- return 0;
-}
-int WM_DELETE_WINDOW (int w, int client_data, int call_data) {
- return 0;
-}
-int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XEnterWindow (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- XKeyEvent xEvent = new XKeyEvent ();
- OS.memmove (xEvent, call_data, XKeyEvent.sizeof);
- boolean doit = true;
- if (xEvent.keycode != 0) {
- doit = sendKeyEvent (SWT.KeyDown, xEvent);
- } else {
- doit = sendIMKeyEvent (SWT.KeyDown, xEvent);
- }
- if (!doit) {
- OS.memmove (continue_to_dispatch, new int [1], 4);
- return 1;
- }
- return 0;
-}
-int XKeyRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- XKeyEvent xEvent = new XKeyEvent ();
- OS.memmove (xEvent, call_data, XKeyEvent.sizeof);
- if (!sendKeyEvent (SWT.KeyUp, xEvent)) {
- OS.memmove (continue_to_dispatch, new int [1], 4);
- return 1;
- }
- return 0;
-}
-int XLeaveWindow (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XPropertyChange (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XmNactivateCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNarmCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNbrowseSelectionCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNcascadingCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNdecrementCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNdefaultActionCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNdragCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNexposureCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNextendedSelectionCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNhelpCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNincrementCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNmapCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNmodifyVerifyCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNmultipleSelectionCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNpageDecrementCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNpageIncrementCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNtoBottomCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNtoTopCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNunmapCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNvalueChangedCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XNonMaskable (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XStructureNotify (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Color.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Color.java
deleted file mode 100755
index 2459e50106..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Color.java
+++ /dev/null
@@ -1,238 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage the operating system resources that
- * implement SWT's RGB color model. To create a color you can either
- * specify the individual color components as integers in the range
- * 0 to 255 or provide an instance of an <code>RGB</code>.
- * <p>
- * Application code must explicitly invoke the <code>Color.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see RGB
- * @see Device#getSystemColor
- * @see <a href="http://www.eclipse.org/swt/snippets/#color">Color and RGB snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Color extends Resource {
-
- /**
- * the handle to the OS color resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
-Color(Device device) {
- super(device);
-}
-
-/**
- * Constructs a new instance of this class given a device and the
- * desired red, green and blue values expressed as ints in the range
- * 0 to 255 (where 0 is black and 255 is full brightness). On limited
- * color devices, the color instance created by this call may not have
- * the same RGB values as the ones specified by the arguments. The
- * RGB values on the returned instance will be the color values of
- * the operating system color.
- * <p>
- * You must dispose the color when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param red the amount of red in the color
- * @param green the amount of green in the color
- * @param blue the amount of blue in the color
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255</li>
- * </ul>
- *
- * @see #dispose
- */
-public Color (Device device, int red, int green, int blue) {
- super(device);
- init(red, green, blue);
- init();
-}
-
-/**
- * Constructs a new instance of this class given a device and an
- * <code>RGB</code> describing the desired red, green and blue values.
- * On limited color devices, the color instance created by this call
- * may not have the same RGB values as the ones specified by the
- * argument. The RGB values on the returned instance will be the color
- * values of the operating system color.
- * <p>
- * You must dispose the color when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param rgb the RGB values of the desired color
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the rgb argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue components of the argument are not between 0 and 255</li>
- * </ul>
- *
- * @see #dispose
- */
-public Color (Device device, RGB rgb) {
- super(device);
- if (rgb == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(rgb.red, rgb.green, rgb.blue);
- init();
-}
-
-void destroy() {
- handle = -1;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Color)) return false;
- Color color = (Color) object;
- return device == color.device && (handle & 0xFFFFFF) == (color.handle & 0xFFFFFF);
-}
-
-/**
- * Returns the amount of blue in the color, from 0 to 255.
- *
- * @return the blue component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getBlue () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return handle & 0xFF;
-}
-
-/**
- * Returns the amount of green in the color, from 0 to 255.
- *
- * @return the green component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getGreen () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (handle & 0xFF00) >> 8;
-}
-
-/**
- * Returns the amount of red in the color, from 0 to 255.
- *
- * @return the red component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getRed () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (handle & 0xFF0000) >> 16;
-}
-
-/**
- * Returns an <code>RGB</code> representing the receiver.
- *
- * @return the RGB for the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public RGB getRGB () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return new RGB((handle & 0xFF0000) >> 16, (handle & 0xFF00) >> 8, handle & 0xFF);
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return handle;
-}
-
-void init(int red, int green, int blue) {
- if (red > 255 || red < 0 || green > 255 || green < 0 || blue > 255 || blue < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- handle = (blue & 0xFF) | ((green & 0xFF) << 8) | ((red & 0xFF) << 16);
-}
-
-/**
- * Returns <code>true</code> if the color has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the color.
- * When a color has been disposed, it is an error to
- * invoke any other method using the color.
- *
- * @return <code>true</code> when the color is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == -1;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Color {*DISPOSED*}";
- return "Color {" + getRed() + ", " + getGreen() + ", " + getBlue() + "}";
-}
-
-public static Color photon_new(Device device, int handle) {
- Color color = new Color(device);
- color.handle = handle;
- return color;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Cursor.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Cursor.java
deleted file mode 100755
index aa75bdbe01..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Cursor.java
+++ /dev/null
@@ -1,464 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage operating system resources that
- * specify the appearance of the on-screen pointer. To create a
- * cursor you specify the device and either a simple cursor style
- * describing one of the standard operating system provided cursors
- * or the image and mask data for the desired appearance.
- * <p>
- * Application code must explicitly invoke the <code>Cursor.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>
- * CURSOR_ARROW, CURSOR_WAIT, CURSOR_CROSS, CURSOR_APPSTARTING, CURSOR_HELP,
- * CURSOR_SIZEALL, CURSOR_SIZENESW, CURSOR_SIZENS, CURSOR_SIZENWSE, CURSOR_SIZEWE,
- * CURSOR_SIZEN, CURSOR_SIZES, CURSOR_SIZEE, CURSOR_SIZEW, CURSOR_SIZENE, CURSOR_SIZESE,
- * CURSOR_SIZESW, CURSOR_SIZENW, CURSOR_UPARROW, CURSOR_IBEAM, CURSOR_NO, CURSOR_HAND
- * </dd>
- * </dl>
- * <p>
- * Note: Only one of the above styles may be specified.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#cursor">Cursor snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Cursor extends Resource {
-
- /**
- * the type to the OS cursor resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int type;
-
- /**
- * the handle to the OS cursor resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int bitmap;
-
-Cursor(Device device) {
- super(device);
-}
-
-/**
- * Constructs a new cursor given a device and a style
- * constant describing the desired cursor appearance.
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param style the style of cursor to allocate
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - when an unknown style is specified</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- *
- * @see SWT#CURSOR_ARROW
- * @see SWT#CURSOR_WAIT
- * @see SWT#CURSOR_CROSS
- * @see SWT#CURSOR_APPSTARTING
- * @see SWT#CURSOR_HELP
- * @see SWT#CURSOR_SIZEALL
- * @see SWT#CURSOR_SIZENESW
- * @see SWT#CURSOR_SIZENS
- * @see SWT#CURSOR_SIZENWSE
- * @see SWT#CURSOR_SIZEWE
- * @see SWT#CURSOR_SIZEN
- * @see SWT#CURSOR_SIZES
- * @see SWT#CURSOR_SIZEE
- * @see SWT#CURSOR_SIZEW
- * @see SWT#CURSOR_SIZENE
- * @see SWT#CURSOR_SIZESE
- * @see SWT#CURSOR_SIZESW
- * @see SWT#CURSOR_SIZENW
- * @see SWT#CURSOR_UPARROW
- * @see SWT#CURSOR_IBEAM
- * @see SWT#CURSOR_NO
- * @see SWT#CURSOR_HAND
- */
-public Cursor(Device device, int style) {
- super(device);
- switch (style) {
- case SWT.CURSOR_ARROW: type = OS.Ph_CURSOR_POINTER; break;
- case SWT.CURSOR_WAIT: type = OS.Ph_CURSOR_CLOCK; break;
- case SWT.CURSOR_HAND: type = OS.Ph_CURSOR_FINGER; break;
- case SWT.CURSOR_CROSS: type = OS.Ph_CURSOR_CROSSHAIR; break;
- case SWT.CURSOR_APPSTARTING: type = OS.Ph_CURSOR_POINT_WAIT; break;
- case SWT.CURSOR_HELP: type = OS.Ph_CURSOR_QUESTION_POINT; break;
- case SWT.CURSOR_SIZEALL: type = OS.Ph_CURSOR_MOVE; break;
- case SWT.CURSOR_SIZENESW: type = OS.Ph_CURSOR_MOVE; break;
- case SWT.CURSOR_SIZENS: type = OS.Ph_CURSOR_DRAG_VERTICAL; break;
- case SWT.CURSOR_SIZENWSE: type = OS.Ph_CURSOR_MOVE; break;
- case SWT.CURSOR_SIZEWE: type = OS.Ph_CURSOR_DRAG_HORIZONTAL; break;
- case SWT.CURSOR_SIZEN: type = OS.Ph_CURSOR_DRAG_TOP; break;
- case SWT.CURSOR_SIZES: type = OS.Ph_CURSOR_DRAG_BOTTOM; break;
- case SWT.CURSOR_SIZEE: type = OS.Ph_CURSOR_DRAG_RIGHT; break;
- case SWT.CURSOR_SIZEW: type = OS.Ph_CURSOR_DRAG_LEFT; break;
- case SWT.CURSOR_SIZENE: type = OS.Ph_CURSOR_DRAG_TR; break;
- case SWT.CURSOR_SIZESE: type = OS.Ph_CURSOR_DRAG_BR; break;
- case SWT.CURSOR_SIZESW: type = OS.Ph_CURSOR_DRAG_BL; break;
- case SWT.CURSOR_SIZENW: type = OS.Ph_CURSOR_DRAG_TL; break;
- case SWT.CURSOR_UPARROW: type = OS.Ph_CURSOR_FINGER; break;
- case SWT.CURSOR_IBEAM: type = OS.Ph_CURSOR_INSERT; break;
- case SWT.CURSOR_NO: type = OS.Ph_CURSOR_DONT; break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (type == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new cursor given a device, image and mask
- * data describing the desired cursor appearance, and the x
- * and y coordinates of the <em>hotspot</em> (that is, the point
- * within the area covered by the cursor which is considered
- * to be where the on-screen pointer is "pointing").
- * <p>
- * The mask data is allowed to be null, but in this case the source
- * must be an ImageData representing an icon that specifies both
- * color data and mask data.
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param source the color data for the cursor
- * @param mask the mask data for the cursor (or null)
- * @param hotspotX the x coordinate of the cursor's hotspot
- * @param hotspotY the y coordinate of the cursor's hotspot
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the source is null</li>
- * <li>ERROR_NULL_ARGUMENT - if the mask is null and the source does not have a mask</li>
- * <li>ERROR_INVALID_ARGUMENT - if the source and the mask are not the same
- * size, or if the hotspot is outside the bounds of the image</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- */
-public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (mask == null) {
- if (source.getTransparencyType() != SWT.TRANSPARENCY_MASK) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- mask = source.getTransparencyMask();
- }
- /* Check the bounds. Mask must be the same size as source */
- if (mask.width != source.width || mask.height != source.height) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- /* Check the hotspots */
- if (hotspotX >= source.width || hotspotX < 0 ||
- hotspotY >= source.height || hotspotY < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- /* Convert to depth 1 */
- mask = ImageData.convertMask(mask);
- source = ImageData.convertMask(source);
- type = OS.Ph_CURSOR_BITMAP;
-
- short w = (short)source.width;
- short h = (short)source.height;
- ImageData mask1 = new ImageData(w, h, 1, source.palette);
- ImageData mask2 = new ImageData(w, h, 1, mask.palette);
- for (int y=0; y<h; y++) {
- for (int x=0; x<w; x++) {
- int mask1_pixel, src_pixel = source.getPixel(x, y);
- int mask2_pixel, mask_pixel = mask.getPixel(x, y);
- if (src_pixel == 0 && mask_pixel == 0) {
- // BLACK
- mask1_pixel = 0;
- mask2_pixel = 1;
- } else if (src_pixel == 0 && mask_pixel == 1) {
- // WHITE - cursor color
- mask1_pixel = 1;
- mask2_pixel = 0;
- } else if (src_pixel == 1 && mask_pixel == 0) {
- // SCREEN
- mask1_pixel = 0;
- mask2_pixel = 0;
- } else {
- /*
- * Feature in Photon. It is not possible to have
- * the reverse screen case using the Photon support.
- * Reverse screen will be the same as screen.
- */
- // REVERSE SCREEN -> SCREEN
- mask1_pixel = 0;
- mask2_pixel = 0;
- }
- mask1.setPixel(x, y, mask1_pixel);
- mask2.setPixel(x, y, mask2_pixel);
- }
- }
-
- PhCursorDef_t cursor = new PhCursorDef_t();
- cursor.size1_x = w;
- cursor.size1_y = h;
- cursor.offset1_x = (short)-hotspotX;
- cursor.offset1_y = (short)-hotspotY;
- cursor.bytesperline1 = (byte)mask1.bytesPerLine;
- cursor.color1 = OS.Ph_CURSOR_DEFAULT_COLOR;
- cursor.size2_x = w;
- cursor.size2_y = h;
- cursor.offset2_x = (short)-hotspotX;
- cursor.offset2_y = (short)-hotspotY;
- cursor.bytesperline2 = (byte)mask2.bytesPerLine;
- cursor.color2 = 0x000000;
- int mask1Size = cursor.bytesperline1 * cursor.size1_y;
- int mask2Size = cursor.bytesperline2 * cursor.size2_y;
- bitmap = OS.malloc(PhCursorDef_t.sizeof + mask1Size + mask2Size);
- if (bitmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.memmove(bitmap, cursor, PhCursorDef_t.sizeof);
- OS.memmove(bitmap + PhCursorDef_t.sizeof, mask1.data, mask1Size);
- OS.memmove(bitmap + PhCursorDef_t.sizeof + mask1Size, mask2.data, mask2Size);
- init();
-}
-
-/**
- * Constructs a new cursor given a device, image data describing
- * the desired cursor appearance, and the x and y coordinates of
- * the <em>hotspot</em> (that is, the point within the area
- * covered by the cursor which is considered to be where the
- * on-screen pointer is "pointing").
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param source the image data for the cursor
- * @param hotspotX the x coordinate of the cursor's hotspot
- * @param hotspotY the y coordinate of the cursor's hotspot
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the hotspot is outside the bounds of the
- * image</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- *
- * @since 3.0
- */
-public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (hotspotX >= source.width || hotspotX < 0 ||
- hotspotY >= source.height || hotspotY < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- ImageData mask = source.getTransparencyMask();
-
- /* Ensure depth is equal to 1 */
- if (source.depth > 1) {
- /* Create a destination image with no data */
- ImageData newSource = new ImageData(
- source.width, source.height, 1, ImageData.bwPalette(),
- 1, null, 0, null, null, -1, -1, 0, 0, 0, 0, 0);
-
- byte[] newReds = new byte[]{0, (byte)255}, newGreens = newReds, newBlues = newReds;
-
- /* Convert the source to a black and white image of depth 1 */
- PaletteData palette = source.palette;
- if (palette.isDirect) {
- ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, palette.redMask, palette.greenMask, palette.blueMask,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- newSource.data, newSource.depth, newSource.bytesPerLine, newSource.getByteOrder(), 0, 0, newSource.width, newSource.height, newReds, newGreens, newBlues,
- false, false);
- } else {
- RGB[] rgbs = palette.getRGBs();
- int length = rgbs.length;
- byte[] srcReds = new byte[length];
- byte[] srcGreens = new byte[length];
- byte[] srcBlues = new byte[length];
- for (int i = 0; i < rgbs.length; i++) {
- RGB rgb = rgbs[i];
- if (rgb == null) continue;
- srcReds[i] = (byte)rgb.red;
- srcGreens[i] = (byte)rgb.green;
- srcBlues[i] = (byte)rgb.blue;
- }
- ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, srcReds, srcGreens, srcBlues,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- newSource.data, newSource.depth, newSource.bytesPerLine, newSource.getByteOrder(), 0, 0, newSource.width, newSource.height, newReds, newGreens, newBlues,
- false, false);
- }
- source = newSource;
- }
- type = OS.Ph_CURSOR_BITMAP;
-
- short w = (short)source.width;
- short h = (short)source.height;
- ImageData mask1 = new ImageData(w, h, 1, source.palette);
- ImageData mask2 = new ImageData(w, h, 1, mask.palette);
- for (int y=0; y<h; y++) {
- for (int x=0; x<w; x++) {
- int mask1_pixel, src_pixel = source.getPixel(x, y);
- int mask2_pixel, mask_pixel = mask.getPixel(x, y);
- if (src_pixel == 0 && mask_pixel == 1) {
- // BLACK
- mask1_pixel = 0;
- mask2_pixel = 1;
- } else if (src_pixel == 1 && mask_pixel == 1) {
- // WHITE - cursor color
- mask1_pixel = 1;
- mask2_pixel = 0;
- } else if (src_pixel == 0 && mask_pixel == 0) {
- // SCREEN
- mask1_pixel = 0;
- mask2_pixel = 0;
- } else {
- /*
- * Feature in Photon. It is not possible to have
- * the reverse screen case using the Photon support.
- * Reverse screen will be the same as screen.
- */
- // REVERSE SCREEN -> SCREEN
- mask1_pixel = 0;
- mask2_pixel = 0;
- }
- mask1.setPixel(x, y, mask1_pixel);
- mask2.setPixel(x, y, mask2_pixel);
- }
- }
-
- PhCursorDef_t cursor = new PhCursorDef_t();
- cursor.size1_x = w;
- cursor.size1_y = h;
- cursor.offset1_x = (short)-hotspotX;
- cursor.offset1_y = (short)-hotspotY;
- cursor.bytesperline1 = (byte)mask1.bytesPerLine;
- cursor.color1 = OS.Ph_CURSOR_DEFAULT_COLOR;
- cursor.size2_x = w;
- cursor.size2_y = h;
- cursor.offset2_x = (short)-hotspotX;
- cursor.offset2_y = (short)-hotspotY;
- cursor.bytesperline2 = (byte)mask2.bytesPerLine;
- cursor.color2 = 0x000000;
- int mask1Size = cursor.bytesperline1 * cursor.size1_y;
- int mask2Size = cursor.bytesperline2 * cursor.size2_y;
- bitmap = OS.malloc(PhCursorDef_t.sizeof + mask1Size + mask2Size);
- if (bitmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.memmove(bitmap, cursor, PhCursorDef_t.sizeof);
- OS.memmove(bitmap + PhCursorDef_t.sizeof, mask1.data, mask1Size);
- OS.memmove(bitmap + PhCursorDef_t.sizeof + mask1Size, mask2.data, mask2Size);
- init();
-}
-
-void destroy() {
- if (type == OS.Ph_CURSOR_BITMAP && bitmap != 0) {
- OS.free(bitmap);
- }
- type = bitmap = 0;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Cursor)) return false;
- Cursor cursor = (Cursor) object;
- return device == cursor.device && type == cursor.type &&
- bitmap == cursor.bitmap;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return bitmap ^ type;
-}
-
-/**
- * Returns <code>true</code> if the cursor has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the cursor.
- * When a cursor has been disposed, it is an error to
- * invoke any other method using the cursor.
- *
- * @return <code>true</code> when the cursor is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return type == 0;
-}
-
-public static Cursor photon_new(Device device, int type, int bitmap) {
- Cursor cursor = new Cursor(device);
- cursor.type = type;
- cursor.bitmap = bitmap;
- return cursor;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Cursor {*DISPOSED*}";
- return "Cursor {" + type + "," + bitmap + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Device.java
deleted file mode 100755
index c7db383959..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Device.java
+++ /dev/null
@@ -1,627 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-
-/**
- * This class is the abstract superclass of all device objects,
- * such as the Display device and the Printer device. Devices
- * can have a graphics context (GC) created for them, and they
- * can be drawn on by sending messages to the associated GC.
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class Device implements Drawable {
-
- /* Debugging */
- public static boolean DEBUG;
- boolean debug = DEBUG;
- boolean tracking = DEBUG;
- Error [] errors;
- Object [] objects;
- Object trackingLock;
-
- boolean disposed;
-
- Font systemFont;
-
- /*
- * TEMPORARY CODE. When a graphics object is
- * created and the device parameter is null,
- * the current Display is used. This presents
- * a problem because SWT graphics does not
- * reference classes in SWT widgets. The correct
- * fix is to remove this feature. Unfortunately,
- * too many application programs rely on this
- * feature.
- */
- protected static Device CurrentDevice;
- protected static Runnable DeviceFinder;
- static {
- try {
- Class.forName ("org.eclipse.swt.widgets.Display");
- } catch (ClassNotFoundException e) {}
- }
-
-static synchronized Device getDevice () {
- if (DeviceFinder != null) DeviceFinder.run();
- Device device = CurrentDevice;
- CurrentDevice = null;
- return device;
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * You must dispose the device when it is no longer required.
- * </p>
- *
- * @see #create
- * @see #init
- *
- * @since 3.1
- */
-public Device() {
- this(null);
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * You must dispose the device when it is no longer required.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #create
- * @see #init
- * @see DeviceData
- */
-public Device(DeviceData data) {
- synchronized (Device.class) {
- if (data != null) {
- debug = data.debug;
- tracking = data.tracking;
- }
- if (tracking) {
- errors = new Error [128];
- objects = new Object [128];
- trackingLock = new Object ();
- }
- create (data);
- init ();
- }
-}
-
-/**
- * Throws an <code>SWTException</code> if the receiver can not
- * be accessed by the caller. This may include both checks on
- * the state of the receiver and more generally on the entire
- * execution context. This method <em>should</em> be called by
- * device implementors to enforce the standard SWT invariants.
- * <p>
- * Currently, it is an error to invoke any method (other than
- * <code>isDisposed()</code> and <code>dispose()</code>) on a
- * device that has had its <code>dispose()</code> method called.
- * </p><p>
- * In future releases of SWT, there may be more or fewer error
- * checks and exceptions may be thrown for different reasons.
- * <p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-protected void checkDevice () {
- if (disposed) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
-}
-
-/**
- * Creates the device in the operating system. If the device
- * does not have a handle, this method may do nothing depending
- * on the device.
- * <p>
- * This method is called before <code>init</code>.
- * </p><p>
- * Subclasses are supposed to reimplement this method and not
- * call the <code>super</code> implementation.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #init
- */
-protected void create (DeviceData data) {
-}
-
-/**
- * Destroys the device in the operating system and releases
- * the device's handle. If the device does not have a handle,
- * this method may do nothing depending on the device.
- * <p>
- * This method is called after <code>release</code>.
- * </p><p>
- * Subclasses are supposed to reimplement this method and not
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #dispose
- * @see #release
- */
-protected void destroy () {
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the receiver. After this method has been invoked, the receiver
- * will answer <code>true</code> when sent the message
- * <code>isDisposed()</code>.
- *
- * @see #release
- * @see #destroy
- * @see #checkDevice
- */
-public void dispose () {
- synchronized (Device.class) {
- if (isDisposed()) return;
- checkDevice ();
- release ();
- destroy ();
- disposed = true;
- if (tracking) {
- synchronized (trackingLock) {
- objects = null;
- errors = null;
- trackingLock = null;
- }
- }
- }
-}
-
-void dispose_Object (Object object) {
- synchronized (trackingLock) {
- for (int i=0; i<objects.length; i++) {
- if (objects [i] == object) {
- objects [i] = null;
- errors [i] = null;
- return;
- }
- }
- }
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location.
- *
- * @return the bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkDevice ();
- PhRect_t rect = new PhRect_t ();
- OS.PhWindowQueryVisible (OS.Ph_QUERY_CONSOLE, 0, OS.PhInputGroup (0), rect);
- int width = rect.lr_x - rect.ul_x + 1;
- int height = rect.lr_y - rect.ul_y + 1;
- return new Rectangle (rect.ul_x, rect.ul_y, width, height);
-}
-
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data.
- *
- * @return the client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getBounds
- */
-public Rectangle getClientArea () {
- checkDevice ();
- PhRect_t rect = new PhRect_t ();
- OS.PhWindowQueryVisible (OS.Ph_QUERY_WORKSPACE, 0, OS.PhInputGroup (0), rect);
- int width = rect.lr_x - rect.ul_x + 1;
- int height = rect.lr_y - rect.ul_y + 1;
- return new Rectangle (rect.ul_x, rect.ul_y, width, height);
-}
-
-/**
- * Returns the bit depth of the screen, which is the number of
- * bits it takes to represent the number of unique colors that
- * the screen is currently capable of displaying. This number
- * will typically be one of 1, 8, 15, 16, 24 or 32.
- *
- * @return the depth of the screen
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getDepth () {
- checkDevice ();
- PgDisplaySettings_t settings = new PgDisplaySettings_t ();
- OS.PgGetVideoMode (settings);
- PgVideoModeInfo_t mode_info = new PgVideoModeInfo_t ();
- OS.PgGetVideoModeInfo ((short) settings.mode, mode_info);
- return mode_info.bits_per_pixel;
-}
-
-/**
- * Returns a <code>DeviceData</code> based on the receiver.
- * Modifications made to this <code>DeviceData</code> will not
- * affect the receiver.
- *
- * @return a <code>DeviceData</code> containing the device's data and attributes
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see DeviceData
- */
-public DeviceData getDeviceData () {
- checkDevice();
- DeviceData data = new DeviceData ();
- data.debug = debug;
- data.tracking = tracking;
- if (tracking) {
- synchronized (trackingLock) {
- int count = 0, length = objects.length;
- for (int i=0; i<length; i++) {
- if (objects [i] != null) count++;
- }
- int index = 0;
- data.objects = new Object [count];
- data.errors = new Error [count];
- for (int i=0; i<length; i++) {
- if (objects [i] != null) {
- data.objects [index] = objects [i];
- data.errors [index] = errors [i];
- index++;
- }
- }
- }
- } else {
- data.objects = new Object [0];
- data.errors = new Error [0];
- }
- return data;
-}
-
-/**
- * Returns a point whose x coordinate is the horizontal
- * dots per inch of the display, and whose y coordinate
- * is the vertical dots per inch of the display.
- *
- * @return the horizontal and vertical DPI
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point getDPI () {
- checkDevice ();
- //NOT DONE
- return new Point (96, 96);
-}
-
-/**
- * Returns <code>FontData</code> objects which describe
- * the fonts that match the given arguments. If the
- * <code>faceName</code> is null, all fonts will be returned.
- *
- * @param faceName the name of the font to look for, or null
- * @param scalable if true only scalable fonts are returned, otherwise only non-scalable fonts are returned.
- * @return the matching font data
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontData [] getFontList (String faceName, boolean scalable) {
- checkDevice ();
- int flags = OS.PHFONT_FIXED | OS.PHFONT_PROP | OS.PHFONT_DONT_SHOW_LEGACY;
- flags |= scalable ? OS.PHFONT_SCALABLE : OS.PHFONT_BITMAP;
- int nfonts = OS.PfQueryFonts(OS.PHFONT_ALL_SYMBOLS, flags, 0, 0);
- if (nfonts <= 0) return new FontData[0];
- int list_ptr = OS.malloc(nfonts * FontDetails.sizeof);
- nfonts = OS.PfQueryFonts(OS.PHFONT_ALL_SYMBOLS, flags, list_ptr, nfonts);
- int ptr = list_ptr;
- int nFds = 0;
- FontData[] fds = new FontData[faceName != null ? 4 : nfonts];
- FontDetails details = new FontDetails();
- for (int i = 0; i < nfonts; i++) {
- OS.memmove(details, ptr, FontDetails.sizeof);
- char[] chars = Converter.mbcsToWcs(null, details.desc);
- int index = 0;
- while (index < chars.length) {
- if (chars[index] == 0) break;
- index++;
- }
- String name = new String(chars, 0, index);
- if (faceName == null || Compatibility.equalsIgnoreCase(faceName, name)) {
- int size;
- if (details.losize == 0 && details.hisize == 0) size = 9; // This value was taken from the PhAB editor
- else size = details.losize;
- flags = details.flags & ~(OS.PHFONT_INFO_PROP | OS.PHFONT_INFO_FIXED);
- while (flags != 0) {
- int style;
- if ((flags & OS.PHFONT_INFO_PLAIN) != 0) {
- style = SWT.NORMAL;
- flags &= ~OS.PHFONT_INFO_PLAIN;
- } else if ((flags & OS.PHFONT_INFO_BOLD) != 0) {
- style = SWT.BOLD;
- flags &= ~OS.PHFONT_INFO_BOLD;
- } else if ((flags & OS.PHFONT_INFO_ITALIC) != 0) {
- style = SWT.ITALIC;
- flags &= ~OS.PHFONT_INFO_ITALIC;
- } else if ((flags & OS.PHFONT_INFO_BLDITC) != 0) {
- style = SWT.BOLD | SWT.ITALIC;
- flags &= ~OS.PHFONT_INFO_BLDITC;
- } else break;
- if (nFds == fds.length) {
- FontData[] newFds = new FontData[fds.length + nfonts];
- System.arraycopy(fds, 0, newFds, 0, nFds);
- fds = newFds;
- }
- fds[nFds++] = new FontData(name, size, style);
- }
- }
- ptr += FontDetails.sizeof;
- }
- OS.free(list_ptr);
-
- if (nFds == fds.length) return fds;
-
- FontData[] result = new FontData[nFds];
- System.arraycopy(fds, 0, result, 0, nFds);
- return result;
-}
-
-/**
- * Returns the matching standard color for the given
- * constant, which should be one of the color constants
- * specified in class <code>SWT</code>. Any value other
- * than one of the SWT color constants which is passed
- * in will result in the color black. This color should
- * not be freed because it was allocated by the system,
- * not the application.
- *
- * @param id the color constant
- * @return the matching color
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT
- */
-public Color getSystemColor (int id) {
- checkDevice ();
- int color = 0x000000;
- switch (id) {
- case SWT.COLOR_BLACK: color = 0x000000; break;
- case SWT.COLOR_DARK_RED: color = 0x800000; break;
- case SWT.COLOR_DARK_GREEN: color = 0x008000; break;
- case SWT.COLOR_DARK_YELLOW: color = 0x808000; break;
- case SWT.COLOR_DARK_BLUE: color = 0x000080; break;
- case SWT.COLOR_DARK_MAGENTA: color = 0x800080; break;
- case SWT.COLOR_DARK_CYAN: color = 0x008080; break;
- case SWT.COLOR_GRAY: color = 0x808080; break;
- case SWT.COLOR_DARK_GRAY: color = 0x404040; break;
- case SWT.COLOR_RED: color = 0xFF0000; break;
- case SWT.COLOR_GREEN: color = 0x00FF00; break;
- case SWT.COLOR_YELLOW: color = 0xFFFF00; break;
- case SWT.COLOR_BLUE: color = 0x0000FF; break;
- case SWT.COLOR_MAGENTA: color = 0xFF00FF; break;
- case SWT.COLOR_CYAN: color = 0x00FFFF; break;
- case SWT.COLOR_WHITE: color = 0xFFFFFF; break;
- }
- return Color.photon_new (this, color);
-}
-
-/**
- * Returns a reasonable font for applications to use.
- * On some platforms, this will match the "default font"
- * or "system font" if such can be found. This font
- * should not be freed because it was allocated by the
- * system, not the application.
- * <p>
- * Typically, applications which want the default look
- * should simply not set the font on the widgets they
- * create. Widgets are always created with the correct
- * default font for the class of user-interface component
- * they represent.
- * </p>
- *
- * @return a font
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getSystemFont () {
- checkDevice ();
- return systemFont;
-}
-
-/**
- * Returns <code>true</code> if the underlying window system prints out
- * warning messages on the console, and <code>setWarnings</code>
- * had previously been called with <code>true</code>.
- *
- * @return <code>true</code>if warnings are being handled, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean getWarnings () {
- checkDevice ();
- return false;
-}
-
-/**
- * Initializes any internal resources needed by the
- * device.
- * <p>
- * This method is called after <code>create</code>.
- * </p><p>
- * If subclasses reimplement this method, they must
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #create
- */
-protected void init () {
- /* Initialize the system font slot */
- systemFont = getSystemFont ();
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Device</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public abstract int internal_new_GC (GCData data);
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Device</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public abstract void internal_dispose_GC (int handle, GCData data);
-
-/**
- * Returns <code>true</code> if the device has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the device.
- * When a device has been disposed, it is an error to
- * invoke any other method using the device.
- *
- * @return <code>true</code> when the device is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- synchronized (Device.class) {
- return disposed;
- }
-}
-
-/**
- * Loads the font specified by a file. The font will be
- * present in the list of fonts available to the application.
- *
- * @param path the font file path
- * @return whether the font was successfully loaded
- *
- * @exception SWTException <ul>
- * <li>ERROR_NULL_ARGUMENT - if path is null</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Font
- *
- * @since 3.3
- */
-public boolean loadFont (String path) {
- checkDevice();
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return false;
-}
-
-void new_Object (Object object) {
- synchronized (trackingLock) {
- for (int i=0; i<objects.length; i++) {
- if (objects [i] == null) {
- objects [i] = object;
- errors [i] = new Error ();
- return;
- }
- }
- Object [] newObjects = new Object [objects.length + 128];
- System.arraycopy (objects, 0, newObjects, 0, objects.length);
- newObjects [objects.length] = object;
- objects = newObjects;
- Error [] newErrors = new Error [errors.length + 128];
- System.arraycopy (errors, 0, newErrors, 0, errors.length);
- newErrors [errors.length] = new Error ();
- errors = newErrors;
- }
-}
-
-/**
- * Releases any internal resources back to the operating
- * system and clears all fields except the device handle.
- * <p>
- * When a device is destroyed, resources that were acquired
- * on behalf of the programmer need to be returned to the
- * operating system. For example, if the device allocated a
- * font to be used as the system font, this font would be
- * freed in <code>release</code>. Also,to assist the garbage
- * collector and minimize the amount of memory that is not
- * reclaimed when the programmer keeps a reference to a
- * disposed device, all fields except the handle are zero'd.
- * The handle is needed by <code>destroy</code>.
- * </p>
- * This method is called before <code>destroy</code>.
- * </p><p>
- * If subclasses reimplement this method, they must
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #dispose
- * @see #destroy
- */
-protected void release () {
-}
-
-/**
- * If the underlying window system supports printing warning messages
- * to the console, setting warnings to <code>false</code> prevents these
- * messages from being printed. If the argument is <code>true</code> then
- * message printing is not blocked.
- *
- * @param warnings <code>true</code>if warnings should be printed, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setWarnings (boolean warnings) {
- checkDevice ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/DeviceData.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/DeviceData.java
deleted file mode 100755
index 9b95c99718..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/DeviceData.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-public class DeviceData {
- /*
- * Debug fields - may not be honoured
- * on some SWT platforms.
- */
- public boolean debug;
- public boolean tracking;
- public Error [] errors;
- public Object [] objects;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Font.java
deleted file mode 100755
index b3cece7cd1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Font.java
+++ /dev/null
@@ -1,265 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage operating system resources that
- * define how text looks when it is displayed. Fonts may be constructed
- * by providing a device and either name, size and style information
- * or a <code>FontData</code> object which encapsulates this data.
- * <p>
- * Application code must explicitly invoke the <code>Font.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see FontData
- * @see <a href="http://www.eclipse.org/swt/snippets/#font">Font snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Font extends Resource {
-
- /**
- * the handle to the OS font resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public byte[] handle;
-
-Font(Device device) {
- super(device);
-}
-
-/**
- * Constructs a new font given a device and font data
- * which describes the desired font's appearance.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param fd the FontData that describes the desired font (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the fd argument is null</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li>
- * </ul>
- */
-public Font(Device device, FontData fd) {
- super(device);
- if (fd == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(fd.getName(), fd.getHeight(), fd.getStyle(), fd.stem);
- init();
-}
-
-/**
- * Constructs a new font given a device and an array
- * of font data which describes the desired font's
- * appearance.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param fds the array of FontData that describes the desired font (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the fds argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the length of fds is zero</li>
- * <li>ERROR_NULL_ARGUMENT - if any fd in the array is null</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li>
- * </ul>
- *
- * @since 2.1
- */
-public Font(Device device, FontData[] fds) {
- super(device);
- if (fds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (fds.length == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<fds.length; i++) {
- if (fds[i] == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- FontData fd = fds[0];
- init(fd.getName(), fd.getHeight(), fd.getStyle(), fd.stem);
- init();
-}
-/**
- * Constructs a new font given a device, a font name,
- * the height of the desired font in points, and a font
- * style.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param name the name of the font (must not be null)
- * @param height the font height in points
- * @param style a bit or combination of NORMAL, BOLD, ITALIC
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the name argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given arguments</li>
- * </ul>
- */
-public Font(Device device, String name, int height, int style) {
- super(device);
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(name, height, style, null);
- init();
-}
-
-void destroy() {
- handle = null;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals(Object object) {
- if (object == this) return true;
- if (!(object instanceof Font)) return false;
- byte[] h = ((Font)object).handle;
- if (h == handle) return true;
- if (h == null || handle == null) return false;
- if (h.length != handle.length) return false;
- for (int i=0; i<h.length; i++) {
- if (handle[i] != h[i]) return false;
- if (handle[i] == 0) break;
- }
- return true;
-}
-
-/**
- * Returns an array of <code>FontData</code>s representing the receiver.
- * On Windows, only one FontData will be returned per font. On X however,
- * a <code>Font</code> object <em>may</em> be composed of multiple X
- * fonts. To support this case, we return an array of font data objects.
- *
- * @return an array of font data objects describing the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontData[] getFontData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return new FontData[]{new FontData(handle)};
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- if (handle == null) return 0;
- return handle.hashCode();
-}
-
-/**
- * Returns <code>true</code> if the font has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the font.
- * When a font has been disposed, it is an error to
- * invoke any other method using the font.
- *
- * @return <code>true</code> when the font is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == null;
-}
-
-void init(String name, int height, int style, byte[] stem) {
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (stem != null) {
- handle = stem;
- } else {
- byte[] description = Converter.wcsToMbcs(null, name, true);
- int osStyle = 0;
- if ((style & SWT.BOLD) != 0) osStyle |= OS.PF_STYLE_BOLD;
- if ((style & SWT.ITALIC) != 0) osStyle |= OS.PF_STYLE_ITALIC;
- byte[] buffer = new byte[OS.MAX_FONT_TAG];
- if (OS.PfGenerateFontName(description, osStyle, height, buffer) != 0) handle = buffer;
- if (handle == null) {
- byte[] defaultFont = device.systemFont.handle;
- int fontID = OS.PfDecomposeStemToID(defaultFont);
- if (fontID != 0) {
- int desc = OS.PfFontDescription(fontID);
- int length = OS.strlen(desc);
- byte[] defaultFontName = new byte[length + 1];
- OS.memmove(defaultFontName, desc, length);
- OS.PfFreeFont(fontID);
- if (OS.PfGenerateFontName(defaultFontName, osStyle, height, buffer) != 0) handle = buffer;
- }
- if (handle == null) handle = defaultFont;
- }
- }
- if (handle == null)SWT.error(SWT.ERROR_NO_HANDLES);
-}
-
-public static Font photon_new(Device device, byte[] stem) {
- Font font = new Font(device);
- font.init(null, 0, 0, stem);
- return font;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Font {*DISPOSED*}";
- int index = 0;
- while (index < handle.length) {
- if (handle[index] == 0) break;
- index++;
- }
- String text = new String(handle, 0, index);
- return "Font {" + text + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/FontData.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/FontData.java
deleted file mode 100755
index 4eac8a32b3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/FontData.java
+++ /dev/null
@@ -1,456 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class describe operating system fonts.
- * <p>
- * For platform-independent behaviour, use the get and set methods
- * corresponding to the following properties:
- * <dl>
- * <dt>height</dt><dd>the height of the font in points</dd>
- * <dt>name</dt><dd>the face name of the font, which may include the foundry</dd>
- * <dt>style</dt><dd>A bitwise combination of NORMAL, ITALIC and BOLD</dd>
- * </dl>
- * If extra, platform-dependent functionality is required:
- * <ul>
- * <li>On <em>Windows</em>, the data member of the <code>FontData</code>
- * corresponds to a Windows <code>LOGFONT</code> structure whose fields
- * may be retrieved and modified.</li>
- * <li>On <em>X</em>, the fields of the <code>FontData</code> correspond
- * to the entries in the font's XLFD name and may be retrieved and modified.
- * </ul>
- * Application code does <em>not</em> need to explicitly release the
- * resources managed by each instance when those instances are no longer
- * required, and thus no <code>dispose()</code> method is provided.
- *
- * @see Font
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class FontData {
-
- /**
- * the font name
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public String name;
-
- /**
- * The height of the font data in points
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int height;
-
- /**
- * the font style
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int style;
-
- /**
- * A Photon stem
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public byte[] stem;
-
- /**
- * The locales of the font
- */
- String lang, country, variant;
-
-FontData(byte[] stem) {
- this.stem = stem;
- int fontID = OS.PfDecomposeStemToID(stem);
- if (fontID != 0) {
- int desc = OS.PfFontDescription(fontID);
- int size = OS.PfFontSize(fontID);
- int flags = OS.PfFontFlags(fontID);
- int length = OS.strlen(desc);
- byte[] buffer = new byte[length];
- OS.memmove(buffer, desc, length);
- name = new String(Converter.mbcsToWcs(null, buffer));
- height = size;
- style = SWT.NORMAL;
- if ((flags & OS.PF_STYLE_BOLD) != 0) style |= SWT.BOLD;
- if ((flags & OS.PF_STYLE_ITALIC) != 0) style |= SWT.ITALIC;
- OS.PfFreeFont(fontID);
- }
-}
-
-/**
- * Constructs a new uninitialized font data.
- */
-public FontData() {
- this("", 12, SWT.NORMAL);
-}
-
-/**
- * Constructs a new FontData given a string representation
- * in the form generated by the <code>FontData.toString</code>
- * method.
- * <p>
- * Note that the representation varies between platforms,
- * and a FontData can only be created from a string that was
- * generated on the same platform.
- * </p>
- *
- * @param string the string representation of a <code>FontData</code> (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument does not represent a valid description</li>
- * </ul>
- *
- * @see #toString
- */
-public FontData(String string) {
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int start = 0;
- int end = string.indexOf('|');
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- String version1 = string.substring(start, end);
- try {
- if (Integer.parseInt(version1) != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- String name = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int height = 0;
- try {
- height = Integer.parseInt(string.substring(start, end));
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int style = 0;
- try {
- style = Integer.parseInt(string.substring(start, end));
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- setName(name);
- setHeight(height);
- setStyle(style);
- if (end == -1) return;
- String platform = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- String version2 = string.substring(start, end);
-
- if (platform.equals("PHOTON") && version2.equals("1")) {
- return;
- }
-}
-
-/**
- * Constructs a new font data given a font name,
- * the height of the desired font in points,
- * and a font style.
- *
- * @param name the name of the font (must not be null)
- * @param height the font height in points
- * @param style a bit or combination of NORMAL, BOLD, ITALIC
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - when the font name is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- */
-public FontData(String name, int height, int style) {
- setName(name);
- setHeight(height);
- setStyle(style);
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof FontData)) return false;
- FontData data = (FontData)object;
- return name.equals(data.name) && height == data.height && style == data.style;
-}
-
-/**
- * Returns the height of the receiver in points.
- *
- * @return the height of this FontData
- *
- * @see #setHeight(int)
- */
-public int getHeight() {
- return height;
-}
-
-/**
- * Returns the locale of the receiver.
- * <p>
- * The locale determines which platform character set this
- * font is going to use. Widgets and graphics operations that
- * use this font will convert UNICODE strings to the platform
- * character set of the specified locale.
- * </p>
- * <p>
- * On platforms where there are multiple character sets for a
- * given language/country locale, the variant portion of the
- * locale will determine the character set.
- * </p>
- *
- * @return the <code>String</code> representing a Locale object
- * @since 3.0
- */
-public String getLocale () {
- StringBuffer buffer = new StringBuffer ();
- char sep = '_';
- if (lang != null) {
- buffer.append (lang);
- buffer.append (sep);
- }
- if (country != null) {
- buffer.append (country);
- buffer.append (sep);
- }
- if (variant != null) {
- buffer.append (variant);
- }
-
- String result = buffer.toString ();
- int length = result.length ();
- if (length > 0) {
- if (result.charAt (length - 1) == sep) {
- result = result.substring (0, length - 1);
- }
- }
- return result;
-}
-
-/**
- * Returns the name of the receiver.
- * On platforms that support font foundries, the return value will
- * be the foundry followed by a dash ("-") followed by the face name.
- *
- * @return the name of this <code>FontData</code>
- *
- * @see #setName
- */
-public String getName() {
- return name;
-}
-
-/**
- * Returns the style of the receiver which is a bitwise OR of
- * one or more of the <code>SWT</code> constants NORMAL, BOLD
- * and ITALIC.
- *
- * @return the style of this <code>FontData</code>
- *
- * @see #setStyle
- */
-public int getStyle() {
- return style;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return name.hashCode() ^ height ^ style;
-}
-
-/**
- * Sets the height of the receiver. The parameter is
- * specified in terms of points, where a point is one
- * seventy-second of an inch.
- *
- * @param height the height of the <code>FontData</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- *
- * @see #getHeight
- */
-public void setHeight(int height) {
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.height = height;
- this.stem = null;
-}
-
-/**
- * Sets the name of the receiver.
- * <p>
- * Some platforms support font foundries. On these platforms, the name
- * of the font specified in setName() may have one of the following forms:
- * <ol>
- * <li>a face name (for example, "courier")</li>
- * <li>a foundry followed by a dash ("-") followed by a face name (for example, "adobe-courier")</li>
- * </ol>
- * In either case, the name returned from getName() will include the
- * foundry.
- * </p>
- * <p>
- * On platforms that do not support font foundries, only the face name
- * (for example, "courier") is used in <code>setName()</code> and
- * <code>getName()</code>.
- * </p>
- *
- * @param name the name of the font data (must not be null)
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - when the font name is null</li>
- * </ul>
- *
- * @see #getName
- */
-public void setName(String name) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.name = name;
- this.stem = null;
-}
-
-/**
- * Sets the locale of the receiver.
- * <p>
- * The locale determines which platform character set this
- * font is going to use. Widgets and graphics operations that
- * use this font will convert UNICODE strings to the platform
- * character set of the specified locale.
- * </p>
- * <p>
- * On platforms where there are multiple character sets for a
- * given language/country locale, the variant portion of the
- * locale will determine the character set.
- * </p>
- *
- * @param locale the <code>String</code> representing a Locale object
- * @see java.util.Locale#toString
- */
-public void setLocale(String locale) {
- lang = country = variant = null;
- if (locale != null) {
- char sep = '_';
- int length = locale.length();
- int firstSep, secondSep;
-
- firstSep = locale.indexOf(sep);
- if (firstSep == -1) {
- firstSep = secondSep = length;
- } else {
- secondSep = locale.indexOf(sep, firstSep + 1);
- if (secondSep == -1) secondSep = length;
- }
- if (firstSep > 0) lang = locale.substring(0, firstSep);
- if (secondSep > firstSep + 1) country = locale.substring(firstSep + 1, secondSep);
- if (length > secondSep + 1) variant = locale.substring(secondSep + 1);
- }
-}
-
-/**
- * Sets the style of the receiver to the argument which must
- * be a bitwise OR of one or more of the <code>SWT</code>
- * constants NORMAL, BOLD and ITALIC. All other style bits are
- * ignored.
- *
- * @param style the new style for this <code>FontData</code>
- *
- * @see #getStyle
- */
-public void setStyle(int style) {
- this.style = style;
- this.stem = null;
-}
-
-/**
- * Returns a string representation of the receiver which is suitable
- * for constructing an equivalent instance using the
- * <code>FontData(String)</code> constructor.
- *
- * @return a string representation of the FontData
- *
- * @see FontData
- */
-public String toString() {
- StringBuffer buffer = new StringBuffer();
- buffer.append("1|");
- buffer.append(getName());
- buffer.append("|");
- buffer.append(getHeight());
- buffer.append("|");
- buffer.append(getStyle());
- buffer.append("|");
- buffer.append("PHOTON|1|");
- return buffer.toString();
-}
-
-public static FontData photon_new(byte[] stem) {
- return new FontData(stem);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/FontMetrics.java
deleted file mode 100755
index d21e6e4d60..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/FontMetrics.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.photon.*;
-
-/**
- * Instances of this class provide measurement information
- * about fonts including ascent, descent, height, leading
- * space between rows, and average character width.
- * <code>FontMetrics</code> are obtained from <code>GC</code>s
- * using the <code>getFontMetrics()</code> method.
- *
- * @see GC#getFontMetrics
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class FontMetrics {
-
- /**
- * On Windows, handle is a Win32 TEXTMETRIC struct
- * On Photon, handle is a Photon FontQueryInfo struct
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public FontQueryInfo handle;
-
-FontMetrics() {
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof FontMetrics)) return false;
- FontQueryInfo info = ((FontMetrics)object).handle;
- if (info == handle) return true;
- if (info == null || handle == null) return false;
- if (handle.size == info.size &&
- handle.style == info.style &&
- handle.ascender == info.ascender &&
- handle.descender == info.descender &&
- handle.width == info.width &&
- handle.lochar == info.lochar &&
- handle.hichar == info.hichar &&
- handle.desc.length == info.desc.length &&
- handle.font.length == info.font.length)
- {
- for (int i = handle.desc.length - 1; i >= 0; i--) {
- if (handle.desc[i] != info.desc[i]) return false;
- }
- for (int i = handle.font.length - 1; i >= 0; i--) {
- if (handle.font[i] != info.font[i]) return false;
- }
- return true;
- }
- return false;
-}
-
-/**
- * Returns the ascent of the font described by the receiver. A
- * font's <em>ascent</em> is the distance from the baseline to the
- * top of actual characters, not including any of the leading area,
- * measured in pixels.
- *
- * @return the ascent of the font
- */
-public int getAscent() {
- return -handle.ascender;
-}
-
-/**
- * Returns the average character width, measured in pixels,
- * of the font described by the receiver.
- *
- * @return the average character width of the font
- */
-public int getAverageCharWidth() {
- if ((handle.style & OS.PHFONT_INFO_FIXED) != 0) return handle.width;
- return handle.width / 3;
-}
-
-/**
- * Returns the descent of the font described by the receiver. A
- * font's <em>descent</em> is the distance from the baseline to the
- * bottom of actual characters, not including any of the leading area,
- * measured in pixels.
- *
- * @return the descent of the font
- */
-public int getDescent() {
- return handle.descender;
-}
-
-/**
- * Returns the height of the font described by the receiver,
- * measured in pixels. A font's <em>height</em> is the sum of
- * its ascent, descent and leading area.
- *
- * @return the height of the font
- *
- * @see #getAscent
- * @see #getDescent
- * @see #getLeading
- */
-public int getHeight() {
- return -handle.ascender + handle.descender;
-}
-
-/**
- * Returns the leading area of the font described by the
- * receiver. A font's <em>leading area</em> is the space
- * above its ascent which may include accents or other marks.
- *
- * @return the leading space of the font
- */
-public int getLeading() {
- return 0;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode() {
- if (handle == null) return 0;
- return handle.size ^ handle.style ^ handle.ascender ^
- handle.descender ^ handle.width ^
- handle.lochar ^ handle.hichar ^ handle.font.hashCode() ^
- handle.desc.hashCode();
-}
-
-public static FontMetrics internal_new(int ascent, int descent, int aveCharWidth, int leading, int height) {
- FontQueryInfo info = new FontQueryInfo();
- info.ascender = (short)-ascent;
- info.descender = (short)descent;
- info.style = OS.PHFONT_INFO_FIXED;
- info.width = (short)aveCharWidth;
- return photon_new(info);
-}
-
-public static FontMetrics photon_new(FontQueryInfo handle) {
- FontMetrics fontMetrics = new FontMetrics();
- fontMetrics.handle = handle;
- return fontMetrics;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/GC.java
deleted file mode 100755
index ea5c82634b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/GC.java
+++ /dev/null
@@ -1,3655 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-
-/**
- * Class <code>GC</code> is where all of the drawing capabilities that are
- * supported by SWT are located. Instances are used to draw on either an
- * <code>Image</code>, a <code>Control</code>, or directly on a <code>Display</code>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * </dl>
- *
- * <p>
- * The SWT drawing coordinate system is the two-dimensional space with the origin
- * (0,0) at the top left corner of the drawing area and with (x,y) values increasing
- * to the right and downward respectively.
- * </p>
- *
- * <p>
- * The result of drawing on an image that was created with an indexed
- * palette using a color that is not in the palette is platform specific.
- * Some platforms will match to the nearest color while other will draw
- * the color itself. This happens because the allocated image might use
- * a direct palette on platforms that do not support indexed palette.
- * </p>
- *
- * <p>
- * Application code must explicitly invoke the <code>GC.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required. This is <em>particularly</em>
- * important on Windows95 and Windows98 where the operating system has a limited
- * number of device contexts available.
- * </p>
- *
- * <p>
- * Note: Only one of LEFT_TO_RIGHT and RIGHT_TO_LEFT may be specified.
- * </p>
- *
- * @see org.eclipse.swt.events.PaintEvent
- * @see <a href="http://www.eclipse.org/swt/snippets/#gc">GC snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class GC extends Resource {
- /**
- * the handle to the OS device context
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
- Drawable drawable;
- GCData data;
-
- int dirtyBits;
-
- static final int DefaultBack = 0xffffff;
- static final int DefaultFore = 0x000000;
- static final byte[][] DashList = {
- { }, // SWT.LINE_SOLID
- { 18, 6 }, // SWT.LINE_DASH
- { 3, 3 }, // SWT.LINE_DOT
- { 9, 6, 3, 6 }, // SWT.LINE_DASHDOT
- { 9, 3, 3, 3, 3, 3 } // SWT.LINE_DASHDOTDOT
- };
- // Photon Draw Buffer Size for off screen drawing.
- static int DrawBufferSize = 48 * 1024;
-
- static final int DIRTY_BACKGROUND = 1 << 0;
- static final int DIRTY_FOREGROUND = 1 << 1;
- static final int DIRTY_CLIPPING = 1 << 2;
- static final int DIRTY_FONT = 1 << 3;
- static final int DIRTY_LINESTYLE = 1 << 4;
- static final int DIRTY_LINEWIDTH = 1 << 5;
- static final int DIRTY_LINECAP = 1 << 6;
- static final int DIRTY_LINEJOIN = 1 << 7;
- static final int DIRTY_XORMODE = 1 << 8;
-
-GC() {
-}
-
-/**
- * Constructs a new instance of this class which has been
- * configured to draw on the specified drawable. Sets the
- * foreground color, background color and font in the GC
- * to match those in the drawable.
- * <p>
- * You must dispose the graphics context when it is no longer required.
- * </p>
- * @param drawable the drawable to draw on
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li>
- * <li>ERROR_NULL_ARGUMENT - if there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT
- * - if the drawable is an image that is not a bitmap or an icon
- * - if the drawable is an image or printer that is already selected
- * into another graphics context</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li>
- * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li>
- * </ul>
- */
-public GC(Drawable drawable) {
- this(drawable, 0);
-}
-
-/**
- * Constructs a new instance of this class which has been
- * configured to draw on the specified drawable. Sets the
- * foreground color, background color and font in the GC
- * to match those in the drawable.
- * <p>
- * You must dispose the graphics context when it is no longer required.
- * </p>
- *
- * @param drawable the drawable to draw on
- * @param style the style of GC to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li>
- * <li>ERROR_NULL_ARGUMENT - if there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT
- * - if the drawable is an image that is not a bitmap or an icon
- * - if the drawable is an image or printer that is already selected
- * into another graphics context</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li>
- * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public GC(Drawable drawable, int style) {
- int flags = OS.PtEnter(0);
- try {
- if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- GCData data = new GCData ();
- data.style = checkStyle(style);
- int hDC = drawable.internal_new_GC (data);
- Device device = data.device;
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = data.device = device;
- init (drawable, data, hDC);
- init();
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-static int checkStyle (int style) {
- if ((style & SWT.LEFT_TO_RIGHT) != 0) style &= ~SWT.RIGHT_TO_LEFT;
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-/**
- * Copies a rectangular area of the receiver at the specified
- * position into the image, which must be of type <code>SWT.BITMAP</code>.
- *
- * @param image the image to copy into
- * @param x the x coordinate in the receiver of the area to be copied
- * @param y the y coordinate in the receiver of the area to be copied
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image is not a bitmap or has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void copyArea(Image image, int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int flags = OS.PtEnter(0);
- try {
- Rectangle bounds = image.getBounds();
- int memImage = 0;
- PhRect_t rect = new PhRect_t();
- rect.ul_x = (short)x; rect.ul_y = (short)y;
- rect.lr_x = (short)(x + bounds.width - 1); rect.lr_y = (short)(y + bounds.height - 1);
- boolean sharedMem = true;
- int rid = data.rid;
- int widget = data.widget;
- if (rid == OS.Ph_DEV_RID) {
- memImage = OS.PgShmemCreate(OS.PgReadScreenSize(rect), null);
- if (memImage != 0) memImage = OS.PgReadScreen(rect, memImage);
- } else if (widget != 0) {
- short [] widget_x = new short [1], widget_y = new short [1];
- OS.PtGetAbsPosition(widget, widget_x, widget_y);
- rect.ul_x += widget_x[0];
- rect.ul_y += widget_y[0];
- rect.lr_x += widget_y[0];
- rect.lr_y += widget_y[0];
- memImage = OS.PgShmemCreate(OS.PgReadScreenSize(rect), null);
- if (memImage != 0) memImage = OS.PgReadScreen(rect, memImage);
- } else if (data.image != null) {
- memImage = OS.PiCropImage(data.image.handle, rect, 0);
- sharedMem = false;
- }
- if (memImage == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- PhImage_t phImage = new PhImage_t();
- OS.memmove(phImage, memImage, PhImage_t.sizeof);
- PhPoint_t trans = new PhPoint_t();
- PhPoint_t pos = new PhPoint_t();
- PhDim_t scale = new PhDim_t();
- scale.w = (short)bounds.width;
- scale.h = (short)bounds.height;
- int mc = OS.PmMemCreateMC(image.handle, scale, trans);
- int prevContext = OS.PmMemStart(mc);
- OS.PgSetDrawBufferSize(DrawBufferSize);
- if (phImage.palette != 0) OS.PgSetPalette(phImage.palette, 0, (short)0, (short)phImage.colors, OS.Pg_PALSET_SOFT, 0);
- OS.PgDrawImage(phImage.image, phImage.type, pos, scale, phImage.bpl, 0);
- if (phImage.palette != 0) OS.PgSetPalette(0, 0, (short)0, (short)-1, 0, 0);
- OS.PmMemFlush(mc, image.handle);
- OS.PmMemStop(mc);
- OS.PmMemReleaseMC(mc);
- OS.PhDCSetCurrent(prevContext);
- if (sharedMem) {
- OS.PgShmemDestroy(memImage);
- } else {
- phImage.flags = (byte)OS.Ph_RELEASE_IMAGE_ALL;
- OS.memmove(memImage, phImage, PhImage_t.sizeof);
- OS.PhReleaseImage(memImage);
- OS.free(memImage);
- }
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Copies a rectangular area of the receiver at the source
- * position onto the receiver at the destination position.
- *
- * @param srcX the x coordinate in the receiver of the area to be copied
- * @param srcY the y coordinate in the receiver of the area to be copied
- * @param width the width of the area to copy
- * @param height the height of the area to copy
- * @param destX the x coordinate in the receiver of the area to copy to
- * @param destY the y coordinate in the receiver of the area to copy to
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void copyArea(int x, int y, int width, int height, int destX, int destY) {
- copyArea(x, y, width, height, destX, destY, true);
-}
-/**
- * Copies a rectangular area of the receiver at the source
- * position onto the receiver at the destination position.
- *
- * @param srcX the x coordinate in the receiver of the area to be copied
- * @param srcY the y coordinate in the receiver of the area to be copied
- * @param width the width of the area to copy
- * @param height the height of the area to copy
- * @param destX the x coordinate in the receiver of the area to copy to
- * @param destY the y coordinate in the receiver of the area to copy to
- * @param paint if <code>true</code> paint events will be generated for old and obscured areas
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void copyArea(int x, int y, int width, int height, int destX, int destY, boolean paint) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width == 0 || height == 0) return;
- int deltaX = destX - x, deltaY = destY - y;
- if (deltaX == 0 && deltaY == 0) return;
-
- int flags = OS.PtEnter(0);
- try {
- boolean overlaps = (destX < x + width) && (destY < y + height) &&
- (destX + width > x) && (destY + height > y);
- int widget = data.widget;
- Image image = data.image;
- if (image != null) {
- int drawImage = image.handle;
- PhImage_t phDrawImage = new PhImage_t();
- OS.memmove(phDrawImage, drawImage, PhImage_t.sizeof);
- if (overlaps) {
- PhPoint_t trans = new PhPoint_t();
- PhDim_t scale = new PhDim_t();
- scale.w = (short)width;
- scale.h = (short)height;
- PhPoint_t pos = new PhPoint_t();
- pos.x = (short)-x;
- pos.y = (short)-y;
- PhDim_t dim = new PhDim_t();
- dim.w = (short)Math.min(phDrawImage.size_w, x + width);
- dim.h = (short)Math.min(phDrawImage.size_h, y + height);
- /* Feature on Photon - It is only possible to draw on images of
- type Pg_IMAGE_PALETTE_BYTE and Pg_IMAGE_DIRECT_888.
- */
- int type = OS.Pg_IMAGE_PALETTE_BYTE;
- if ((phDrawImage.type & OS.Pg_IMAGE_CLASS_MASK) == OS.Pg_IMAGE_CLASS_DIRECT) {
- type = OS.Pg_IMAGE_DIRECT_888;
- }
- int memImage = OS.PhCreateImage(null, (short)width, (short)height, type, phDrawImage.palette, phDrawImage.colors, 0);
- int mc = OS.PmMemCreateMC(memImage, scale, trans);
- int prevContext = OS.PmMemStart(mc);
- OS.PgSetDrawBufferSize(DrawBufferSize);
- if (phDrawImage.palette != 0) OS.PgSetPalette(phDrawImage.palette, 0, (short)0, (short)phDrawImage.colors, OS.Pg_PALSET_SOFT, 0);
- OS.PgDrawImage(phDrawImage.image, phDrawImage.type, pos, dim, phDrawImage.bpl, 0);
- if (phDrawImage.palette != 0) OS.PgSetPalette(0, 0, (short)0, (short)-1, 0, 0);
- OS.PmMemFlush(mc, memImage);
- OS.PmMemStop(mc);
- OS.PmMemReleaseMC(mc);
- OS.PhDCSetCurrent(prevContext);
- x = (short)0;
- y = (short)0;
- drawImage = memImage;
- OS.memmove(phDrawImage, drawImage, PhImage_t.sizeof);
- phDrawImage.flags = (byte)OS.Ph_RELEASE_IMAGE_ALL;
- OS.memmove(drawImage, phDrawImage, PhImage_t.sizeof);
- }
- PhPoint_t pos = new PhPoint_t();
- pos.x = (short)(destX - x);
- pos.y = (short)(destY - y);
- PhRect_t clip = new PhRect_t();
- clip.ul_x = (short)destX;
- clip.ul_y = (short)destY;
- clip.lr_x = (short)(destX + width - 1);
- clip.lr_y = (short)(destY + height - 1);
- PhDim_t dim = new PhDim_t();
- dim.w = (short)Math.min(phDrawImage.size_w, x + width);
- dim.h = (short)Math.min(phDrawImage.size_h, y + height);
- int prevContext = setGC();
- setGCTranslation();
- setGCClipping();
- OS.PgSetUserClip(clip);
- if (phDrawImage.palette != 0) OS.PgSetPalette(phDrawImage.palette, 0, (short)0, (short)phDrawImage.colors, OS.Pg_PALSET_SOFT, 0);
- OS.PgDrawImage(phDrawImage.image, phDrawImage.type, pos, dim, phDrawImage.bpl, 0);
- if (phDrawImage.palette != 0) OS.PgSetPalette(0, 0, (short)0, (short)-1, 0, 0);
- OS.PgSetUserClip(null);
- unsetGC(prevContext);
- if (drawImage != image.handle) {
- OS.PhReleaseImage(drawImage);
- OS.free(drawImage);
- }
- } else if (widget != 0) {
- PhRect_t rect = new PhRect_t();
- rect.ul_x = (short)x;
- rect.ul_y = (short)y;
- rect.lr_x = (short)(x + width - 1);
- rect.lr_y = (short)(y + height - 1);
- PhPoint_t delta = new PhPoint_t();
- delta.x = (short)deltaX;
- delta.y = (short)deltaY;
- int visibleTiles = getClipping(widget, data.topWidget, true, true, null);
- if ( visibleTiles == 0 )
- OS.PtBlit(widget, rect, delta);
- else {
- int srcTile = OS.PhGetTile();
- OS.memmove(srcTile, rect, PhRect_t.sizeof);
- OS.PtClippedBlit(widget, srcTile, delta, visibleTiles);
- OS.PhFreeTiles(srcTile);;
- OS.PhFreeTiles(visibleTiles);
- }
- }
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-void destroy() {
- int flags = OS.PtEnter(0);
- try {
- int clipRects = data.clipRects;
- if (clipRects != 0) {
- OS.free(clipRects);
- data.clipRects = data.clipRectsCount = 0;
- }
- Image image = data.image;
- if (image != null) {
- flushImage();
- /* Regenerate the mask if necessary */
- if (image.transparentPixel != -1) {
- PhImage_t phImage = new PhImage_t ();
- OS.memmove(phImage, image.handle, PhImage_t.sizeof);
- if (phImage.mask_bm == 0) {
- createMask(image.handle, phImage.type, image.transparentPixel);
- }
- }
- image.memGC = null;
- }
-
- /*
- * Dispose the HDC.
- */
- drawable.internal_dispose_GC(handle, data);
- drawable = null;
- handle = 0;
- data.image = null;
- data.font = null;
- data.rid = data.widget = data.topWidget = 0;
- data = null;
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Draws the outline of a circular or elliptical arc
- * within the specified rectangular area.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees, using the current color.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc to be drawn
- * @param y the y coordinate of the upper-left corner of the arc to be drawn
- * @param width the width of the arc to be drawn
- * @param height the height of the arc to be drawn
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawArc (int x, int y, int width, int height, int startAngle, int arcAngle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- if (startAngle > 0) {
- if (arcAngle > 0) {
- //No need to modify start angle.
- arcAngle += startAngle;
- } else {
- int newStartAngle;
- int newStopAngle = startAngle;
- if (startAngle > Math.abs(arcAngle)) {
- newStartAngle = startAngle - Math.abs(arcAngle);
- } else {
- newStartAngle = startAngle + 360 - Math.abs(arcAngle);
- }
- startAngle = newStartAngle;
- arcAngle = newStopAngle;
- }
- } else {
- if (arcAngle > 0) {
- arcAngle = arcAngle + startAngle;
- startAngle = 360 - Math.abs(startAngle);
- } else {
- int newStopAngle = 360 + startAngle;
- startAngle = newStopAngle - Math.abs(arcAngle);
- arcAngle = newStopAngle;
- }
- }
- startAngle = (int) (startAngle * 65536 / 360);
- arcAngle = (int) (arcAngle * 65536 / 360);
-
- PhPoint_t center = new PhPoint_t();
- center.x = (short)(x + (width / 2));
- center.y = (short)(y + (height / 2));
- PhPoint_t radii = new PhPoint_t();
- radii.x = (short)(width / 2);
- radii.y = (short)(height / 2);
-
- int flags = OS.PtEnter(0);
- try {
- int prevContext = setGC();
- setGCTranslation();
- setGCClipping();
- OS.PgDrawArc(center, radii, startAngle, arcAngle, OS.Pg_ARC | OS.Pg_DRAW_STROKE);
- unsetGC(prevContext);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Draws a rectangle, based on the specified arguments, which has
- * the appearance of the platform's <em>focus rectangle</em> if the
- * platform supports such a notion, and otherwise draws a simple
- * rectangle in the receiver's foreground color.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width of the rectangle
- * @param height the height of the rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void drawFocus (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int flags = OS.PtEnter(0);
- try {
- int prevContext = setGC();
- setGCTranslation();
- setGCClipping();
- if (width < 0) width -= width;
- if (height < 0) height -= height;
- OS.PgSetStrokeColor(0x9098F8);
- OS.PgDrawIRect(x, y, x + width - 1, y + height - 1, OS.Pg_DRAW_STROKE);
- OS.PgSetStrokeColor(data.foreground);
- unsetGC(prevContext);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Draws the given image in the receiver at the specified
- * coordinates.
- *
- * @param image the image to draw
- * @param x the x coordinate of where to draw
- * @param y the y coordinate of where to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if the given coordinates are outside the bounds of the image</li>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- */
-public void drawImage(Image image, int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- drawImage(image, 0, 0, -1, -1, x, y, -1, -1, true);
-}
-
-/**
- * Copies a rectangular area from the source image into a (potentially
- * different sized) rectangular area in the receiver. If the source
- * and destination areas are of differing sizes, then the source
- * area will be stretched or shrunk to fit the destination area
- * as it is copied. The copy fails if any part of the source rectangle
- * lies outside the bounds of the source image, or if any of the width
- * or height arguments are negative.
- *
- * @param image the source image
- * @param srcX the x coordinate in the source image to copy from
- * @param srcY the y coordinate in the source image to copy from
- * @param srcWidth the width in pixels to copy from the source
- * @param srcHeight the height in pixels to copy from the source
- * @param destX the x coordinate in the destination to copy to
- * @param destY the y coordinate in the destination to copy to
- * @param destWidth the width in pixels of the destination rectangle
- * @param destHeight the height in pixels of the destination rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if any of the width or height arguments are negative.
- * <li>ERROR_INVALID_ARGUMENT - if the source rectangle is not contained within the bounds of the source image</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- */
-public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (srcWidth == 0 || srcHeight == 0 || destWidth == 0 || destHeight == 0) return;
- if (srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 || destWidth < 0 || destHeight < 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (image == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- drawImage(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false);
-}
-void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
- int flags = OS.PtEnter(0);
- try {
- if (image.memGC != null) image.memGC.flushImage();
- int drawImage = image.handle;
- PhImage_t phDrawImage = new PhImage_t();
- OS.memmove(phDrawImage, drawImage, PhImage_t.sizeof);
- int imgWidth = phDrawImage.size_w;
- int imgHeight = phDrawImage.size_h;
- if (simple) {
- srcWidth = destWidth = imgWidth;
- srcHeight = destHeight = imgHeight;
- } else {
- simple = srcX == 0 && srcY == 0 &&
- srcWidth == destWidth && destWidth == imgWidth &&
- srcHeight == destHeight && destHeight == imgHeight;
- if (srcX + srcWidth > imgWidth || srcY + srcHeight > imgHeight) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- if (srcWidth != destWidth || srcHeight != destHeight) {
- drawImage = scaleImage(image, phDrawImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight);
- if (drawImage == 0) return;
- srcX = (short)0;
- srcY = (short)0;
- srcWidth = (short)destWidth;
- srcHeight = (short)destHeight;
- OS.memmove(phDrawImage, drawImage, PhImage_t.sizeof);
- }
- PhPoint_t pos = new PhPoint_t();
- pos.x = (short)(destX - srcX);
- pos.y = (short)(destY - srcY);
- PhDim_t dim = new PhDim_t();
- dim.w = (short)Math.min(phDrawImage.size_w, srcX + srcWidth);
- dim.h = (short)Math.min(phDrawImage.size_h, srcY + srcHeight);
- PhRect_t clip = new PhRect_t();
- clip.ul_x = (short)destX;
- clip.ul_y = (short)destY;
- clip.lr_x = (short)(destX + destWidth - 1);
- clip.lr_y = (short)(destY + destHeight - 1);
- int prevContext = setGC();
- setGCTranslation();
- setGCClipping();
- OS.PgSetDrawMode(data.xorMode ? OS.Pg_DrawModeDSx : OS.Pg_DrawModeS);
- dirtyBits |= DIRTY_XORMODE;
- OS.PgSetUserClip(clip);
- if (phDrawImage.palette != 0) OS.PgSetPalette(phDrawImage.palette, 0, (short)0, (short)phDrawImage.colors, OS.Pg_PALSET_SOFT, 0);
- if (phDrawImage.alpha != 0) {
- drawImageAlpha(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, phDrawImage, drawImage, pos, dim);
- } else if (image.transparentPixel != -1) {
- drawImageTransparent(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, phDrawImage, drawImage, pos, dim);
- } else if (phDrawImage.mask_bm != 0) {
- drawImageMask(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, phDrawImage, drawImage, pos, dim);
- } else {
- drawImage(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, phDrawImage, drawImage, pos, dim);
- }
- if (phDrawImage.palette != 0) OS.PgSetPalette(0, 0, (short)0, (short)-1, 0, 0);
- OS.PgSetUserClip(null);
- unsetGC(prevContext);
- if (drawImage != image.handle) {
- phDrawImage.flags = (byte)OS.Ph_RELEASE_IMAGE_ALL;
- OS.memmove(drawImage, phDrawImage, PhImage_t.sizeof);
- OS.PhReleaseImage(drawImage);
- OS.free(drawImage);
- }
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-void drawImageAlpha(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, PhImage_t phImage, int imgHandle, PhPoint_t pos, PhDim_t dim) {
- PgAlpha_t phAlpha = new PgAlpha_t();
- OS.memmove(phAlpha, phImage.alpha, PgAlpha_t.sizeof);
- if ((phAlpha.alpha_op & OS.Pg_ALPHA_OP_SRC_GLOBAL) != 0) {
- OS.PgSetAlpha(phAlpha.alpha_op, null, 0, phAlpha.src_global_alpha, phAlpha.dest_global_alpha);
- OS.PgAlphaOn();
- OS.PgDrawImage(phImage.image, phImage.type, pos, dim, phImage.bpl, 0);
- OS.PgAlphaOff();
- return;
- }
-
- /*
- * Feature/Bug in Photon - When drawing images with alpha blending
- * enabled, there is a limitation in the size of the alpha map.
- * This limitation is probably related to the draw buffer size and
- * it seems to be worse when drawing to a memory context. The
- * fix/workaround is to draw the image line by line.
- */
- PgMap_t imageMap = new PgMap_t();
- OS.memmove(imageMap, phImage.alpha + 4, PgMap_t.sizeof);
- PgMap_t lineMap = new PgMap_t();
- lineMap.dim_w = imageMap.dim_w;
- lineMap.dim_h = 1;
- /*
- * Feature in Photon - The alpha map set in a graphics context by
- * PgSetAlpha is freed when the graphics context is destroyed.
- */
- lineMap.map = OS.malloc(lineMap.dim_w);
- OS.PgSetAlpha(phAlpha.alpha_op, lineMap, 0, phAlpha.src_global_alpha, phAlpha.dest_global_alpha);
- OS.PgAlphaOn();
- pos.y = (short)(destY);
- int end = dim.h;
- dim.h = (short)1;
- for (int y=srcY; y<end; y+=lineMap.dim_h) {
- OS.memmove(lineMap.map, imageMap.map + (imageMap.dim_w * y), lineMap.dim_w);
- /*
- * Bug in Photon - When drawing an image to a memory context created by
- * PmMemCreateMC at a negative position, the alpha map is not offset.
- */
- if (data.image != null && pos.x < 0) {
- OS.memmove(lineMap.map, lineMap.map - pos.x, lineMap.dim_w + pos.x);
- }
- OS.PgDrawImage(phImage.image + (phImage.bpl * y), phImage.type, pos, dim, phImage.bpl, 0);
- /*
- * Flushing is necessary in order to change the alpha map.
- */
- if (data.image != null) OS.PmMemFlush(handle, data.image.handle);
- else OS.PgFlush();
- pos.y += lineMap.dim_h;
- }
- OS.PgAlphaOff();
-}
-void drawImageTransparent(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, PhImage_t phImage, int imgHandle, PhPoint_t pos, PhDim_t dim) {
- /* Generate the mask if necessary */
- if (phImage.mask_bm == 0) {
- createMask(imgHandle, phImage.type, image.transparentPixel);
- OS.memmove(phImage, imgHandle, PhImage_t.sizeof);
- }
- OS.PgDrawTImage(phImage.image, phImage.type, pos, dim, phImage.bpl, 0, phImage.mask_bm, phImage.mask_bpl);
- /* Destroy the mask if there is a GC created on the image */
- if (image.memGC != null && image.handle == imgHandle) {
- OS.free(phImage.mask_bm);
- phImage.mask_bm = 0;
- phImage.mask_bpl = 0;
- OS.memmove(imgHandle, phImage, PhImage_t.sizeof);
- }
-}
-void drawImageMask(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, PhImage_t phImage, int imgHandle, PhPoint_t pos, PhDim_t dim) {
- OS.PgDrawTImage(phImage.image, phImage.type, pos, dim, phImage.bpl, 0, phImage.mask_bm, phImage.mask_bpl);
-}
-void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, PhImage_t phImage, int imgHandle, PhPoint_t pos, PhDim_t dim) {
- OS.PgDrawImage(phImage.image, phImage.type, pos, dim, phImage.bpl, 0);
-}
-static void createMask(int image, int type, int transparent) {
- if ((type & OS.Pg_IMAGE_CLASS_MASK) == OS.Pg_IMAGE_CLASS_PALETTE) {
- transparent = (transparent & 0xFF) | OS.Pg_INDEX_COLOR;
- } else {
- switch (type) {
- case OS.Pg_IMAGE_DIRECT_888:
- transparent = ((transparent & 0xFF) << 16) | (transparent & 0xFF00) | ((transparent & 0xFF0000) >> 16);
- break;
- case OS.Pg_IMAGE_DIRECT_8888:
- transparent = ((transparent & 0xFF00) << 8) | ((transparent & 0xFF0000) >> 8) | ((transparent & 0xFF000000) >> 24);
- break;
- case OS.Pg_IMAGE_DIRECT_565:
- transparent = ((transparent & 0xF800) << 8) | ((transparent & 0x7E0) << 5) | ((transparent & 0x1F) << 3);
- break;
- case OS.Pg_IMAGE_DIRECT_555:
- transparent = ((transparent & 0x7C00) << 9) | ((transparent & 0x3E0) << 6) | ((transparent & 0x1F) << 3);
- break;
- case OS.Pg_IMAGE_DIRECT_444:
- transparent = ((transparent & 0xF00) << 12) | ((transparent & 0xF0) << 8) | ((transparent & 0xF) << 4);
- break;
- }
- }
- OS.PhMakeTransBitmap(image, transparent);
-}
-static int scaleImage(Image image, PhImage_t phImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) {
- PhPoint_t trans = new PhPoint_t();
- PhDim_t scale = new PhDim_t();
- scale.w = (short)srcWidth;
- scale.h = (short)srcHeight;
- PhPoint_t pos = new PhPoint_t();
- pos.x = (short)-srcX;
- pos.y = (short)-srcY;
- PhDim_t dim = new PhDim_t();
- dim.w = (short)Math.min(phImage.size_w, srcX + srcWidth);
- dim.h = (short)Math.min(phImage.size_h, srcY + srcHeight);
- /*
- * Feature on Photon - It is only possible to draw on images of
- * type Pg_IMAGE_PALETTE_BYTE and Pg_IMAGE_DIRECT_888.
- */
- int type = OS.Pg_IMAGE_PALETTE_BYTE;
- if ((phImage.type & OS.Pg_IMAGE_CLASS_MASK) == OS.Pg_IMAGE_CLASS_DIRECT) {
- type = OS.Pg_IMAGE_DIRECT_888;
- }
- /* Scale the image */
- int memImage = OS.PhCreateImage(null, (short)destWidth, (short)destHeight, type, phImage.palette, phImage.colors, 0);
- if (memImage == 0) return 0;
- int mc = OS.PmMemCreateMC(memImage, scale, trans);
- if (mc == 0) {
- Image.destroyImage(memImage);
- return 0;
- }
- int prevContext = OS.PmMemStart(mc);
- OS.PgSetDrawBufferSize(DrawBufferSize);
- if (phImage.palette != 0) OS.PgSetPalette(phImage.palette, 0, (short)0, (short)phImage.colors, OS.Pg_PALSET_SOFT, 0);
- OS.PgDrawImage(phImage.image, phImage.type, pos, dim, phImage.bpl, 0);
- if (phImage.palette != 0) OS.PgSetPalette(0, 0, (short)0, (short)-1, 0, 0);
- OS.PmMemFlush(mc, memImage);
- OS.PmMemStop(mc);
- OS.PmMemReleaseMC(mc);
- OS.PhDCSetCurrent(prevContext);
-
- PhImage_t phMemImage = new PhImage_t();
- OS.memmove(phMemImage, memImage, PhImage_t.sizeof);
- if (image.transparentPixel != -1) {
- /* Generate the mask if it was created originally */
- if (phImage.mask_bm != 0) {
- createMask(memImage, phImage.type, image.transparentPixel);
- }
- } else if (phImage.mask_bm != 0) {
- /* Scale the mask */
- int[] palette = new int[2];
- palette[0] = 0x000000;
- palette[1] = 0xffffff;
- int palettePtr = OS.malloc(palette.length * 4);
- OS.memmove(palettePtr, palette, palette.length * 4);
- /*
- * Feature on Photon - It is only possible to draw on images of
- * type Pg_IMAGE_PALETTE_BYTE and Pg_IMAGE_DIRECT_888.
- */
- int maskImage = OS.PhCreateImage(null, (short)destWidth, (short)destHeight, OS.Pg_IMAGE_PALETTE_BYTE, palettePtr, palette.length, 0);
- if (maskImage == 0) {
- Image.destroyImage(memImage);
- return 0;
- }
- mc = OS.PmMemCreateMC(maskImage, scale, trans);
- if (mc == 0) {
- Image.destroyImage(maskImage);
- Image.destroyImage(memImage);
- return 0;
- }
- prevContext = OS.PmMemStart(mc);
- OS.PgSetDrawBufferSize(DrawBufferSize);
- OS.PgSetFillColor(palette[0]);
- OS.PgSetTextColor(palette[1]);
- OS.PgDrawBitmap(phImage.mask_bm, OS.Pg_BACK_FILL, pos, dim, phImage.mask_bpl, 0);
- OS.PmMemFlush(mc, maskImage);
- OS.PmMemStop(mc);
- OS.PmMemReleaseMC(mc);
- OS.PhDCSetCurrent(prevContext);
- OS.free(palettePtr);
-
- /* Transfer the mask to the scaled image */
- OS.PhMakeTransBitmap(maskImage, 0 | OS.Pg_INDEX_COLOR);
- PhImage_t phMaskImage = new PhImage_t();
- OS.memmove(phMaskImage, maskImage, PhImage_t.sizeof);
- phMemImage.mask_bm = phMaskImage.mask_bm;
- phMemImage.mask_bpl = phMaskImage.mask_bpl;
- OS.memmove(memImage, phMemImage, PhImage_t.sizeof);
-
- /* Release the temporary image but not the mask data */
- phMaskImage.mask_bm = 0;
- phMaskImage.mask_bpl = 0;
- phMaskImage.flags = (byte)OS.Ph_RELEASE_IMAGE_ALL;
- OS.memmove(maskImage, phMaskImage, PhImage_t.sizeof);
- OS.PhReleaseImage(maskImage);
- OS.free(maskImage);
- } else if (phImage.alpha != 0) {
- PgAlpha_t alpha = new PgAlpha_t();
- OS.memmove(alpha, phImage.alpha, PgAlpha_t.sizeof);
- int alphaPtr = OS.malloc(PgAlpha_t.sizeof);
- if (alphaPtr == 0) {
- Image.destroyImage(memImage);
- return 0;
- }
-
- /* Scale alpha data */
- if (alpha.src_alpha_map_map != 0) {
- int[] palette = new int[256];
- for (int i = 0; i < palette.length; i++) {
- palette[i] = i;
- }
- int palettePtr = OS.malloc(palette.length * 4);
- OS.memmove(palettePtr, palette, palette.length * 4);
- /*
- * Feature on Photon - It is only possible to draw on images of
- * type Pg_IMAGE_PALETTE_BYTE and Pg_IMAGE_DIRECT_888.
- */
- int alphaImage = OS.PhCreateImage(null, (short)destWidth, (short)destHeight, OS.Pg_IMAGE_PALETTE_BYTE, palettePtr, palette.length, 0);
- if (alphaImage == 0) {
- OS.free(palettePtr);
- OS.free(alphaPtr);
- Image.destroyImage(memImage);
- return 0;
- }
- mc = OS.PmMemCreateMC(alphaImage, scale, trans);
- if (mc == 0) {
- OS.free(palettePtr);
- OS.free(alphaPtr);
- Image.destroyImage(alphaImage);
- Image.destroyImage(memImage);
- return 0;
- }
- prevContext = OS.PmMemStart(mc);
- OS.PgSetPalette(palettePtr, 0, (short)0, (short)palette.length, OS.Pg_PALSET_SOFT, 0);
- OS.PgDrawImage(alpha.src_alpha_map_map, OS.Pg_IMAGE_PALETTE_BYTE, pos, dim, alpha.src_alpha_map_bpl, 0);
- OS.PgSetPalette(0, 0, (short)0, (short)-1, 0, 0);
- OS.PmMemFlush(mc, alphaImage);
- OS.PmMemStop(mc);
- OS.PmMemReleaseMC(mc);
- OS.PhDCSetCurrent(prevContext);
- OS.free(palettePtr);
-
- /* Transfer the image to the scaled image alpha data*/
- PhImage_t phAlphaImage = new PhImage_t();
- OS.memmove(phAlphaImage, alphaImage, PhImage_t.sizeof);
- alpha.src_alpha_map_bpl = (short)phAlphaImage.bpl;
- alpha.src_alpha_map_dim_w = (short)phAlphaImage.bpl;
- alpha.src_alpha_map_dim_h = (short)phAlphaImage.size_h;
- alpha.src_alpha_map_map = phAlphaImage.image;
-
- /* Release the temporary image but not the image data */
- phAlphaImage.image = 0;
- phAlphaImage.bpl = 0;
- phAlphaImage.flags = (byte)OS.Ph_RELEASE_IMAGE_ALL;
- OS.memmove(alphaImage, phAlphaImage, PhImage_t.sizeof);
- OS.PhReleaseImage(alphaImage);
- OS.free(alphaImage);
- }
-
- OS.memmove(alphaPtr, alpha, PgAlpha_t.sizeof);
- phMemImage.alpha = alphaPtr;
- OS.memmove(memImage, phMemImage, PhImage_t.sizeof);
- }
- return memImage;
-}
-
-/**
- * Draws a line, using the foreground color, between the points
- * (<code>x1</code>, <code>y1</code>) and (<code>x2</code>, <code>y2</code>).
- *
- * @param x1 the first point's x coordinate
- * @param y1 the first point's y coordinate
- * @param x2 the second point's x coordinate
- * @param y2 the second point's y coordinate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawLine (int x1, int y1, int x2, int y2) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int flags = OS.PtEnter(0);
- try {
- int prevContext = setGC();
- setGCTranslation();
- setGCClipping();
- OS.PgDrawILine(x1, y1, x2, y2);
- unsetGC(prevContext);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Draws the outline of an oval, using the foreground color,
- * within the specified rectangular area.
- * <p>
- * The result is a circle or ellipse that fits within the
- * rectangle specified by the <code>x</code>, <code>y</code>,
- * <code>width</code>, and <code>height</code> arguments.
- * </p><p>
- * The oval covers an area that is <code>width + 1</code>
- * pixels wide and <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper left corner of the oval to be drawn
- * @param y the y coordinate of the upper left corner of the oval to be drawn
- * @param width the width of the oval to be drawn
- * @param height the height of the oval to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawOval (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- PhPoint_t center = new PhPoint_t();
- center.x = (short)x; center.y = (short)y;
- PhPoint_t radii = new PhPoint_t();
- // Don't subtract one, so that the bottom/right edges are drawn
- radii.x = (short)(x + width); radii.y = (short)(y + height);
-
- int flags = OS.PtEnter(0);
- try {
- int prevContext = setGC();
- setGCTranslation();
- setGCClipping();
- OS.PgDrawEllipse(center, radii, OS.Pg_DRAW_STROKE | OS.Pg_EXTENT_BASED);
- unsetGC(prevContext);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Draws the path described by the parameter.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the path to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- *
- * @since 3.1
- */
-public void drawPath(Path path) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-}
-
-/**
- * Draws a pixel, using the foreground color, at the specified
- * point (<code>x</code>, <code>y</code>).
- * <p>
- * Note that the receiver's line attributes do not affect this
- * operation.
- * </p>
- *
- * @param x the point's x coordinate
- * @param y the point's y coordinate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void drawPoint (int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int flags = OS.PtEnter(0);
- try {
- int prevContext = setGC();
- setGCTranslation();
- setGCClipping();
- OS.PgDrawIPixel(x, y);
- unsetGC(prevContext);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Draws the closed polygon which is defined by the specified array
- * of integer coordinates, using the receiver's foreground color. The array
- * contains alternating x and y values which are considered to represent
- * points which are the vertices of the polygon. Lines are drawn between
- * each consecutive pair, and between the first pair and last pair in the
- * array.
- *
- * @param pointArray an array of alternating x and y values which are the vertices of the polygon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT if pointArray is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawPolygon(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
-
- short[] points = new short[pointArray.length];
- for (int i = pointArray.length - 1; i >= 0; i--) {
- points[i] = (short)pointArray[i];
- }
-
- int flags = OS.PtEnter(0);
- try {
- int prevContext = setGC();
- setGCTranslation();
- setGCClipping();
- OS.PgDrawPolygon(points, pointArray.length / 2, new PhPoint_t(), OS.Pg_DRAW_STROKE | OS.Pg_CLOSED);
- unsetGC(prevContext);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Draws the polyline which is defined by the specified array
- * of integer coordinates, using the receiver's foreground color. The array
- * contains alternating x and y values which are considered to represent
- * points which are the corners of the polyline. Lines are drawn between
- * each consecutive pair, but not between the first pair and last pair in
- * the array.
- *
- * @param pointArray an array of alternating x and y values which are the corners of the polyline
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawPolyline(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
-
- short[] points = new short[pointArray.length];
- for (int i = pointArray.length - 1; i >= 0; i--) {
- points[i] = (short)pointArray[i];
- }
-
- int flags = OS.PtEnter(0);
- try {
- int prevContext = setGC();
- setGCTranslation();
- setGCClipping();
- OS.PgDrawPolygon(points, pointArray.length / 2, new PhPoint_t(), OS.Pg_DRAW_STROKE);
- unsetGC(prevContext);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Draws the outline of the rectangle specified by the arguments,
- * using the receiver's foreground color. The left and right edges
- * of the rectangle are at <code>x</code> and <code>x + width</code>.
- * The top and bottom edges are at <code>y</code> and <code>y + height</code>.
- *
- * @param x the x coordinate of the rectangle to be drawn
- * @param y the y coordinate of the rectangle to be drawn
- * @param width the width of the rectangle to be drawn
- * @param height the height of the rectangle to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRectangle (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int flags = OS.PtEnter(0);
- try {
- int prevContext = setGC();
- setGCTranslation();
- setGCClipping();
- // Don't subtract one, so that the bottom/right edges are drawn
- OS.PgDrawIRect(x, y, x + width, y + height, OS.Pg_DRAW_STROKE);
- unsetGC(prevContext);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Draws the outline of the specified rectangle, using the receiver's
- * foreground color. The left and right edges of the rectangle are at
- * <code>rect.x</code> and <code>rect.x + rect.width</code>. The top
- * and bottom edges are at <code>rect.y</code> and
- * <code>rect.y + rect.height</code>.
- *
- * @param rect the rectangle to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRectangle (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- drawRectangle (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Draws the outline of the round-cornered rectangle specified by
- * the arguments, using the receiver's foreground color. The left and
- * right edges of the rectangle are at <code>x</code> and <code>x + width</code>.
- * The top and bottom edges are at <code>y</code> and <code>y + height</code>.
- * The <em>roundness</em> of the corners is specified by the
- * <code>arcWidth</code> and <code>arcHeight</code> arguments, which
- * are respectively the width and height of the ellipse used to draw
- * the corners.
- *
- * @param x the x coordinate of the rectangle to be drawn
- * @param y the y coordinate of the rectangle to be drawn
- * @param width the width of the rectangle to be drawn
- * @param height the height of the rectangle to be drawn
- * @param arcWidth the width of the arc
- * @param arcHeight the height of the arc
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- PhRect_t rect = new PhRect_t();
- rect.ul_x = (short)x; rect.ul_y = (short)y;
- // Don't subtract one, so that the bottom/right edges are drawn
- rect.lr_x = (short)(x + width); rect.lr_y = (short)(y + height);
- PhPoint_t radii = new PhPoint_t();
- radii.x = (short)(arcWidth / 2); radii.y = (short)(arcHeight / 2);
-
- int flags = OS.PtEnter(0);
- try {
- int prevContext = setGC();
- setGCTranslation();
- setGCClipping();
- OS.PgDrawRoundRect(rect, radii, OS.Pg_DRAW_STROKE);
- unsetGC(prevContext);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. No tab expansion or carriage return processing
- * will be performed. The background of the rectangular area where
- * the string is being drawn will be filled with the receiver's
- * background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawString (String string, int x, int y) {
- drawString(string, x, y, false);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. No tab expansion or carriage return processing
- * will be performed. If <code>isTransparent</code> is <code>true</code>,
- * then the background of the rectangular area where the string is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawString (String string, int x, int y, boolean isTransparent) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
-
- int drawFlags = OS.Pg_TEXT_LEFT | OS.Pg_TEXT_TOP;
- if (!isTransparent) drawFlags |= OS.Pg_BACK_FILL;
- byte[] buffer = Converter.wcsToMbcs(null, string, false);
-
- int flags = OS.PtEnter(0);
- try {
- int prevContext = setGC();
- setGCTranslation();
- setGCClipping();
- PhPoint_t pos = new PhPoint_t();
- pos.x = (short)x;
- pos.y = (short)y;
- if (!data.xorMode) {
- OS.PgDrawText(buffer, buffer.length, pos, drawFlags);
- } else {
- if (isTransparent) {
- Font font = data.font;
- PhRect_t rect = new PhRect_t();
- OS.PfExtentText(rect, null, font.handle, buffer, buffer.length);
- short width = (short)(rect.lr_x - rect.ul_x + 1);
- short height = (short)(rect.lr_y - rect.ul_y + 1);
- int image = OS.PhCreateImage(null, width, height, OS.Pg_IMAGE_DIRECT_888, 0, 0, 0);
- PhDim_t dim = new PhDim_t();
- dim.w = width;
- dim.h = height;
- PhPoint_t point = new PhPoint_t();
- int pmMC = OS.PmMemCreateMC(image, dim, point);
- if (pmMC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int prevCont = OS.PmMemStart(pmMC);
- OS.PgSetTextColor(data.foreground);
- OS.PgSetFont(font.handle);
- pos.x = pos.y = (short)0;
- OS.PgDrawText(buffer, buffer.length, pos, drawFlags);
- OS.PmMemFlush(pmMC, image);
- OS.PmMemStop(pmMC);
- OS.PhDCSetCurrent(prevCont);
- OS.PmMemReleaseMC(pmMC);
- point.x = (short)x;
- point.y = (short)y;
- PhImage_t phImage = new PhImage_t();
- OS.memmove(phImage, image, PhImage_t.sizeof);
- OS.PgSetDrawMode(OS.Pg_DrawModeDSx);
- dirtyBits |= DIRTY_XORMODE;
- OS.PgDrawImage(phImage.image, phImage.type, point, dim, phImage.bpl, 0);
- phImage.flags = (byte)OS.Ph_RELEASE_IMAGE_ALL;
- OS.memmove(image, phImage, PhImage_t.sizeof);
- OS.PhReleaseImage(image);
- OS.free(image);
- } else {
- OS.PgSetTextXORColor(data.foreground, data.background);
- OS.PgSetDrawMode(OS.Pg_DrawModeS);
- OS.PgDrawText(buffer, buffer.length, pos, drawFlags);
- dirtyBits |= DIRTY_XORMODE | DIRTY_FOREGROUND;
- }
- }
- unsetGC(prevContext);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion and carriage return processing
- * are performed. The background of the rectangular area where
- * the text is being drawn will be filled with the receiver's
- * background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText (String string, int x, int y) {
- drawText(string, x, y, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion and carriage return processing
- * are performed. If <code>isTransparent</code> is <code>true</code>,
- * then the background of the rectangular area where the text is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText (String string, int x, int y, boolean isTransparent) {
- int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB;
- if (isTransparent) flags |= SWT.DRAW_TRANSPARENT;
- drawText(string, x, y, flags);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion, line delimiter and mnemonic
- * processing are performed according to the specified flags. If
- * <code>flags</code> includes <code>DRAW_TRANSPARENT</code>,
- * then the background of the rectangular area where the text is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- * <p>
- * The parameter <code>flags</code> may be a combination of:
- * <dl>
- * <dt><b>DRAW_DELIMITER</b></dt>
- * <dd>draw multiple lines</dd>
- * <dt><b>DRAW_TAB</b></dt>
- * <dd>expand tabs</dd>
- * <dt><b>DRAW_MNEMONIC</b></dt>
- * <dd>underline the mnemonic character</dd>
- * <dt><b>DRAW_TRANSPARENT</b></dt>
- * <dd>transparent background</dd>
- * </dl>
- * </p>
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param flags the flags specifying how to process the text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText (String string, int x, int y, int flags) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if ((flags & ~SWT.DRAW_TRANSPARENT) == 0) {
- drawString(string, x, y, (flags & SWT.DRAW_TRANSPARENT) != 0);
- } else {
- drawText(string, x, y, flags, true);
- }
-}
-
-Point drawText(String text, int x, int y, int flags, boolean draw) {
- /* NOT DONE - inline code for performance */
-
- int length = text.length();
- char[] buffer = new char[length];
- text.getChars(0, length, buffer, 0);
-
- /* NOT DONE - tabstops */
- int spaceWidth = stringExtent(" ").x;
- int tabWidth = spaceWidth *8 + 1;
-
- boolean transparent = (flags & SWT.DRAW_TRANSPARENT) != 0;
- int mnemonic = -1;
- int start = 0, i = 0, j = 0;
- int initialX = x, initialY = y;
- int maxX = x, maxY = y;
- while (i < length) {
- char c = buffer[j] = buffer[i];
- switch (c) {
- case '\t': {
- if ((flags & SWT.DRAW_TAB) == 0) break;
- String string = new String(buffer, start, j - start);
- if (draw) drawString(string, x, y, transparent);
- Point extent = stringExtent(string);
- x += extent.x + tabWidth;
- maxX = Math.max(x, maxX);
- maxY = Math.max(y + extent.y, maxY);
- start = j + 1;
- break;
- }
- case '\n': {
- if ((flags & SWT.DRAW_DELIMITER) == 0) break;
- String string = new String(buffer, start, j - start);
- if (draw) drawString(string, x, y, transparent);
- Point extent = stringExtent(string);
- maxX = Math.max(x + extent.x, maxX);
- x = initialX;
- y += extent.y;
- maxY = Math.max(y, maxY);
- start = j + 1;
- break;
- }
- case '&': {
- if ((flags & SWT.DRAW_MNEMONIC) == 0) break;
- if (i + 1 == length) break;
- if (buffer[i + 1] == '&') {i++; break;}
- if (mnemonic == -1) {
- mnemonic = i + 1;
- String string = new String(buffer, start, j - start);
- if (draw) drawString(string, x, y, transparent);
- Point extent = stringExtent(string);
- x += extent.x;
- start = mnemonic;
- string = new String(buffer, start, 1);
- if (draw) drawString(string, x, y, transparent);
- extent = stringExtent(string);
- int underlineY = y + extent.y - 1;
- if (draw) drawLine(x, underlineY, x + extent.x, underlineY);
- x += extent.x;
- maxX = Math.max(x, maxX);
- maxY = Math.max(y + extent.y, maxY);
- start = j + 1;
- }
- j--;
- break;
- }
- }
- j++;
- i++;
- }
- if (start != j) {
- String string = new String(buffer, start, j - start);
- if (draw) drawString(string, x, y, transparent);
- Point extent = stringExtent(string);
- maxX = Math.max(x + extent.x, maxX);
- maxY = Math.max(y + extent.y, maxY);
- }
- return new Point(maxX - initialX, maxY - initialY);
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- return (object == this) || ((object instanceof GC) && (handle == ((GC)object).handle));
-}
-
-/**
- * Fills the interior of a circular or elliptical arc within
- * the specified rectangular area, with the receiver's background
- * color.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees, using the current color.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc to be filled
- * @param y the y coordinate of the upper-left corner of the arc to be filled
- * @param width the width of the arc to be filled
- * @param height the height of the arc to be filled
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawArc
- */
-public void fillArc (int x, int y, int width, int height, int startAngle, int arcAngle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- if (startAngle > 0) {
- if (arcAngle > 0) {
- //No need to modify start angle.
- arcAngle += startAngle;
- } else {
- int newStartAngle;
- int newStopAngle = startAngle;
- if (startAngle > Math.abs(arcAngle)) {
- newStartAngle = startAngle - Math.abs(arcAngle);
- } else {
- newStartAngle = startAngle + 360 - Math.abs(arcAngle);
- }
- startAngle = newStartAngle;
- arcAngle = newStopAngle;
- }
- } else {
- if (arcAngle > 0) {
- arcAngle = arcAngle + startAngle;
- startAngle = 360 - Math.abs(startAngle);
- } else {
- int newStopAngle = 360 + startAngle;
- startAngle = newStopAngle - Math.abs(arcAngle);
- arcAngle = newStopAngle;
- }
- }
- startAngle = (int) (startAngle * 65536 / 360);
- arcAngle = (int) (arcAngle * 65536 / 360);
-
- PhPoint_t center = new PhPoint_t();
- center.x = (short)(x + (width / 2));
- center.y = (short)(y + (height / 2));
- PhPoint_t radii = new PhPoint_t();
- radii.x = (short)(width / 2);
- radii.y = (short)(height / 2);
-
- int flags = OS.PtEnter(0);
- try {
- int prevContext = setGC();
- setGCTranslation();
- setGCClipping();
- OS.PgDrawArc(center, radii, startAngle, arcAngle, OS.Pg_ARC_PIE | OS.Pg_DRAW_FILL);
- unsetGC(prevContext);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Fills the interior of the specified rectangle with a gradient
- * sweeping from left to right or top to bottom progressing
- * from the receiver's foreground color to its background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled, may be negative
- * (inverts direction of gradient if horizontal)
- * @param height the height of the rectangle to be filled, may be negative
- * (inverts direction of gradient if vertical)
- * @param vertical if true sweeps from top to bottom, else
- * sweeps from left to right
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if ((width == 0) || (height == 0)) return;
- int fromColor = data.foreground;
- int toColor = data.background;
- boolean swapColors = false;
- if (width < 0) {
- x += width; width = -width;
- if (! vertical) swapColors = true;
- }
- if (height < 0) {
- y += height; height = -height;
- if (vertical) swapColors = true;
- }
- if (swapColors) {
- final int t = toColor;
- toColor = fromColor;
- fromColor = t;
- }
- if (fromColor == toColor) {
- fillRectangle(x, y, width, height);
- return;
- }
- PhPoint_t upperLeft = new PhPoint_t();
- upperLeft.x = (short)x;
- upperLeft.y = (short)y;
- PhPoint_t lowerRight = new PhPoint_t();
- lowerRight.x = (short)(x + width - 1);
- lowerRight.y = (short)(y + height - 1);
- int flags = OS.PtEnter(0);
- try {
- int prevContext = setGC();
- setGCTranslation();
- setGCClipping();
- OS.PgDrawGradient(upperLeft, lowerRight,
- vertical ? OS.Pg_GRAD_VERTICAL : OS.Pg_GRAD_HORIZONTAL, OS.Pg_GRAD_LINEAR,
- vertical ? height : width, fromColor, toColor, 0, 0, 0, null);
- unsetGC(prevContext);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Fills the interior of an oval, within the specified
- * rectangular area, with the receiver's background
- * color.
- *
- * @param x the x coordinate of the upper left corner of the oval to be filled
- * @param y the y coordinate of the upper left corner of the oval to be filled
- * @param width the width of the oval to be filled
- * @param height the height of the oval to be filled
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawOval
- */
-public void fillOval (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- PhPoint_t center = new PhPoint_t();
- center.x = (short)x; center.y = (short)y;
- PhPoint_t radii = new PhPoint_t();
- radii.x = (short)(x + width);
- radii.y = (short)(y + height);
-
- int flags = OS.PtEnter(0);
- try {
- int prevContext = setGC();
- setGCTranslation();
- setGCClipping();
- OS.PgDrawEllipse(center, radii, OS.Pg_DRAW_FILL | OS.Pg_EXTENT_BASED);
- unsetGC(prevContext);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Fills the path described by the parameter.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the path to fill
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- *
- * @since 3.1
- */
-public void fillPath (Path path) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-}
-
-/**
- * Fills the interior of the closed polygon which is defined by the
- * specified array of integer coordinates, using the receiver's
- * background color. The array contains alternating x and y values
- * which are considered to represent points which are the vertices of
- * the polygon. Lines are drawn between each consecutive pair, and
- * between the first pair and last pair in the array.
- *
- * @param pointArray an array of alternating x and y values which are the vertices of the polygon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT if pointArray is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawPolygon
- */
-public void fillPolygon(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
-
- short[] points = new short[pointArray.length];
- for (int i = pointArray.length - 1; i >= 0; i--) {
- points[i] = (short)pointArray[i];
- }
-
- int flags = OS.PtEnter(0);
- try {
- int prevContext = setGC();
- setGCTranslation();
- setGCClipping();
- OS.PgDrawPolygon(points, pointArray.length / 2, new PhPoint_t(), OS.Pg_DRAW_FILL | OS.Pg_CLOSED);
- unsetGC(prevContext);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Fills the interior of the rectangle specified by the arguments,
- * using the receiver's background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillRectangle (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width == 0 || height == 0) return;
- int flags = OS.PtEnter(0);
- try {
- int prevContext = setGC();
- setGCTranslation();
- setGCClipping();
- OS.PgDrawIRect(x, y, x + width - 1, y + height - 1, OS.Pg_DRAW_FILL);
- unsetGC(prevContext);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Fills the interior of the specified rectangle, using the receiver's
- * background color.
- *
- * @param rect the rectangle to be filled
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillRectangle (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- fillRectangle (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Fills the interior of the round-cornered rectangle specified by
- * the arguments, using the receiver's background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- * @param arcWidth the width of the arc
- * @param arcHeight the height of the arc
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRoundRectangle
- */
-public void fillRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- PhRect_t rect = new PhRect_t();
- rect.ul_x = (short)x; rect.ul_y = (short)y;
- rect.lr_x = (short)(x + width - 1); rect.lr_y = (short)(y + height - 1);
- PhPoint_t radii = new PhPoint_t();
- radii.x = (short)(arcWidth / 2); radii.y = (short)(arcHeight / 2);
-
- int flags = OS.PtEnter(0);
- try {
- int prevContext = setGC();
- setGCTranslation();
- setGCClipping();
- OS.PgDrawRoundRect(rect, radii, OS.Pg_DRAW_FILL);
- unsetGC(prevContext);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Force outstanding drawing commands to be processed.
- */
-void flushImage () {
- Image image = data.image;
- if (image == null) return;
- int prevContext = OS.PmMemStart(handle);
- OS.PmMemFlush(handle, image.handle);
- OS.PmMemStop(handle);
- OS.PhDCSetCurrent(prevContext);
-}
-
-/**
- * Returns the <em>advance width</em> of the specified character in
- * the font which is currently selected into the receiver.
- * <p>
- * The advance width is defined as the horizontal distance the cursor
- * should move after printing the character in the selected font.
- * </p>
- *
- * @param ch the character to measure
- * @return the distance in the x direction to move past the character before painting the next
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getAdvanceWidth(char ch) {
- return getCharWidth(ch);
-}
-
-/**
- * Returns <code>true</code> if receiver is using the operating system's
- * advanced graphics subsystem. Otherwise, <code>false</code> is returned
- * to indicate that normal graphics are in use.
- * <p>
- * Advanced graphics may not be installed for the operating system. In this
- * case, <code>false</code> is always returned. Some operating system have
- * only one graphics subsystem. If this subsystem supports advanced graphics,
- * then <code>true</code> is always returned. If any graphics operation such
- * as alpha, antialias, patterns, interpolation, paths, clipping or transformation
- * has caused the receiver to switch from regular to advanced graphics mode,
- * <code>true</code> is returned. If the receiver has been explicitly switched
- * to advanced mode and this mode is supported, <code>true</code> is returned.
- * </p>
- *
- * @return the advanced value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public boolean getAdvanced() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return false;
-}
-
-/**
- * Returns the receiver's alpha value. The alpha value
- * is between 0 (transparent) and 255 (opaque).
- *
- * @return the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getAlpha() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return 0xFF;
-}
-
-/**
- * Returns the receiver's anti-aliasing setting value, which will be
- * one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code>. Note that this controls anti-aliasing for all
- * <em>non-text drawing</em> operations.
- *
- * @return the anti-aliasing setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getTextAntialias
- *
- * @since 3.1
- */
-public int getAntialias() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return SWT.DEFAULT;
-}
-
-/**
- * Returns the background color.
- *
- * @return the receiver's background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getBackground() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return Color.photon_new(data.device, data.background);
-}
-
-/**
- * Returns the background pattern. The default value is
- * <code>null</code>.
- *
- * @return the receiver's background pattern
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Pattern
- *
- * @since 3.1
- */
-public Pattern getBackgroundPattern() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return null;
-}
-
-/**
- * Returns the width of the specified character in the font
- * selected into the receiver.
- * <p>
- * The width is defined as the space taken up by the actual
- * character, not including the leading and tailing whitespace
- * or overhang.
- * </p>
- *
- * @param ch the character to measure
- * @return the width of the character
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getCharWidth(char ch) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- String string = new String(new char[] {ch});
- Point point = stringExtent(string);
- return point.x;
-}
-
-/**
- * Returns the bounding rectangle of the receiver's clipping
- * region. If no clipping region is set, the return value
- * will be a rectangle which covers the entire bounds of the
- * object the receiver is drawing on.
- *
- * @return the bounding rectangle of the clipping region
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getClipping() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int flags = OS.PtEnter(0);
- try {
- PhRect_t rect = new PhRect_t();
- int rid = data.rid;
- int widget = data.widget;
- Image image = data.image;
- if (rid == OS.Ph_DEV_RID) {
- OS.PhRegionQuery (rid, null, rect, 0, 0);
- } else if (widget != 0) {
- OS.PtWidgetCanvas(widget, rect);
- } else if (image != null) {
- PhImage_t img = new PhImage_t();
- OS.memmove(img, image.handle, PhImage_t.sizeof);
- rect.lr_x = (short)(img.size_w - 1);
- rect.lr_y = (short)(img.size_h - 1);
- }
- int clipRects = data.clipRects;
- if (clipRects != 0) {
- int clipRectsCount = data.clipRectsCount;
- int clip_ptr = OS.malloc(PhRect_t.sizeof);
- OS.memmove(clip_ptr, clipRects, PhRect_t.sizeof);
- for (int i = 1; i < clipRectsCount; i++) {
- OS.PhRectUnion (clip_ptr, clipRects + (i * PhRect_t.sizeof));
- }
- int rect_ptr = OS.malloc(PhRect_t.sizeof);
- OS.memmove(rect_ptr, rect, PhRect_t.sizeof);
- boolean intersect = OS.PhRectIntersect(rect_ptr, clip_ptr) != 0;
- OS.memmove(rect, rect_ptr, PhRect_t.sizeof);
- OS.free(rect_ptr);
- OS.free(clip_ptr);
- if (!intersect) return new Rectangle(0, 0, 0, 0);
- }
- int width = rect.lr_x - rect.ul_x + 1;
- int height = rect.lr_y - rect.ul_y + 1;
- return new Rectangle(rect.ul_x, rect.ul_y, width, height);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Sets the region managed by the argument to the current
- * clipping region of the receiver.
- *
- * @param region the region to fill with the clipping region
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the region is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the region is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getClipping (Region region) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int flags = OS.PtEnter(0);
- try {
- if (region.handle != 0 && region.handle != Region.EMPTY_REGION) {
- OS.PhFreeTiles(region.handle);
- }
- int clipRects = data.clipRects;
- if (clipRects != 0) {
- region.handle = OS.PhRectsToTiles(clipRects, data.clipRectsCount);
- } else {
- region.handle = OS.PhGetTile();
- PhRect_t rect = new PhRect_t ();
- int rid = data.rid;
- int widget = data.widget;
- Image image = data.image;
- if (rid == OS.Ph_DEV_RID) {
- OS.PhRegionQuery (rid, null, rect, 0, 0);
- } else if (widget != 0) {
- OS.PtWidgetCanvas(widget, rect);
- } else if (image != null) {
- PhImage_t img = new PhImage_t();
- OS.memmove(img, image.handle, PhImage_t.sizeof);
- rect.lr_x = (short)(img.size_w - 1);
- rect.lr_y = (short)(img.size_h - 1);
- }
- OS.memmove(region.handle, rect, PhRect_t.sizeof);
- }
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Returns the receiver's fill rule, which will be one of
- * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>.
- *
- * @return the receiver's fill rule
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getFillRule() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- //TODO - implement fill rule
- return SWT.FILL_EVEN_ODD;
-}
-
-/**
- * Returns the font currently being used by the receiver
- * to draw and measure text.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getFont () {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.font;
-}
-
-/**
- * Returns a FontMetrics which contains information
- * about the font currently being used by the receiver
- * to draw and measure text.
- *
- * @return font metrics for the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontMetrics getFontMetrics() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- FontQueryInfo info = new FontQueryInfo();
- OS.PfQueryFontInfo(data.font.handle, info);
- return FontMetrics.photon_new(info);
-}
-
-/**
- * Returns the receiver's foreground color.
- *
- * @return the color used for drawing foreground things
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getForeground() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return Color.photon_new(data.device, data.foreground);
-}
-
-/**
- * Returns the foreground pattern. The default value is
- * <code>null</code>.
- *
- * @return the receiver's foreground pattern
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Pattern
- *
- * @since 3.1
- */
-public Pattern getForegroundPattern() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return null;
-}
-
-/**
- * Returns the GCData.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>GC</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @return the receiver's GCData
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see GCData
- *
- * @since 3.2
- * @noreference This method is not intended to be referenced by clients.
- */
-public GCData getGCData() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data;
-}
-
-/**
- * Returns the receiver's interpolation setting, which will be one of
- * <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>,
- * <code>SWT.LOW</code> or <code>SWT.HIGH</code>.
- *
- * @return the receiver's interpolation setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getInterpolation() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return SWT.DEFAULT;
-}
-
-/**
- * Returns the receiver's line attributes.
- *
- * @return the line attributes used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.3
- */
-public LineAttributes getLineAttributes() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float[] dashes = null;
- if (data.dashes != null) {
- dashes = new float[data.dashes.length];
- for (int i = 0; i < dashes.length; i++) {
- dashes[i] = data.dashes[i];
- }
- }
- return new LineAttributes(data.lineWidth, data.lineCap, data.lineJoin, data.lineStyle, dashes, 0, 10);
-}
-
-/**
- * Returns the receiver's line cap style, which will be one
- * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>,
- * or <code>SWT.CAP_SQUARE</code>.
- *
- * @return the cap style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getLineCap() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineCap;
-}
-
-/**
- * Returns the receiver's line dash style. The default value is
- * <code>null</code>.
- *
- * @return the line dash style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int[] getLineDash() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- byte[] dashList = data.dashes;
- if (dashList == null) return null;
- int[] dashes = new int[dashList.length];
- for (int i = 0; i < dashes.length; i++) {
- dashes[i] = dashList[i] & 0xFF;
- }
- return dashes;
-}
-
-/**
- * Returns the receiver's line join style, which will be one
- * of the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>,
- * or <code>SWT.JOIN_BEVEL</code>.
- *
- * @return the join style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getLineJoin() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineJoin;
-}
-
-/**
- * Returns the receiver's line style, which will be one
- * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
- * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or
- * <code>SWT.LINE_DASHDOTDOT</code>.
- *
- * @return the style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineStyle() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineStyle;
-}
-
-/**
- * Returns the width that will be used when drawing lines
- * for all of the figure drawing operations (that is,
- * <code>drawLine</code>, <code>drawRectangle</code>,
- * <code>drawPolyline</code>, and so forth.
- *
- * @return the receiver's line width
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineWidth() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineWidth;
-}
-
-/**
- * Returns the receiver's style information.
- * <p>
- * Note that the value which is returned by this method <em>may
- * not match</em> the value which was provided to the constructor
- * when the receiver was created. This can occur when the underlying
- * operating system does not support a particular combination of
- * requested styles.
- * </p>
- *
- * @return the style bits
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getStyle () {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.style;
-}
-
-/**
- * Returns the receiver's text drawing anti-aliasing setting value,
- * which will be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code>. Note that this controls anti-aliasing
- * <em>only</em> for text drawing operations.
- *
- * @return the anti-aliasing setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getAntialias
- *
- * @since 3.1
- */
-public int getTextAntialias() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return SWT.DEFAULT;
-}
-
-/**
- * Sets the parameter to the transform that is currently being
- * used by the receiver.
- *
- * @param transform the destination to copy the transform into
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Transform
- *
- * @since 3.1
- */
-public void getTransform(Transform transform) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transform == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-}
-
-/**
- * Returns <code>true</code> if this GC is drawing in the mode
- * where the resulting color in the destination is the
- * <em>exclusive or</em> of the color values in the source
- * and the destination, and <code>false</code> if it is
- * drawing in the mode where the destination color is being
- * replaced with the source color value.
- *
- * @return <code>true</code> true if the receiver is in XOR mode, and false otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean getXORMode() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.xorMode;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #equals
- */
-public int hashCode () {
- return handle;
-}
-
-void init(Drawable drawable, GCData data, int context) {
- if (data.foreground == -1) data.foreground = DefaultFore;
- if (data.background == -1) data.background = DefaultBack;
- if (data.font == null) data.font = data.device.systemFont;
- dirtyBits = DIRTY_FOREGROUND | DIRTY_BACKGROUND | DIRTY_FONT;
-
- Image image = data.image;
- if (image != null) {
- image.memGC = this;
- int prevContext = OS.PmMemStart(context);
- OS.PgSetDrawBufferSize(DrawBufferSize);
- OS.PmMemStop(context);
- OS.PhDCSetCurrent(prevContext);
-
- /*
- * Destroy the mask when it is generated from a transparent
- * pixel since drawing on the image might change the mask.
- */
- if (image.transparentPixel != -1) {
- PhImage_t phImage = new PhImage_t ();
- OS.memmove(phImage, image.handle, PhImage_t.sizeof);
- if (phImage.mask_bm != 0) {
- OS.free(phImage.mask_bm);
- phImage.mask_bm = 0;
- phImage.mask_bpl = 0;
- OS.memmove(image.handle, phImage, PhImage_t.sizeof);
- }
- }
- }
- this.drawable = drawable;
- this.data = data;
- handle = context;
-}
-
-/**
- * Returns <code>true</code> if the receiver has a clipping
- * region set into it, and <code>false</code> otherwise.
- * If this method returns false, the receiver will draw on all
- * available space in the destination. If it returns true,
- * it will draw only in the area that is covered by the region
- * that can be accessed with <code>getClipping(region)</code>.
- *
- * @return <code>true</code> if the GC has a clipping region, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean isClipped() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.clipRects != 0;
-}
-
-/**
- * Returns <code>true</code> if the GC has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the GC.
- * When a GC has been disposed, it is an error to
- * invoke any other method using the GC.
- *
- * @return <code>true</code> when the GC is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Sets the receiver to always use the operating system's advanced graphics
- * subsystem for all graphics operations if the argument is <code>true</code>.
- * If the argument is <code>false</code>, the advanced graphics subsystem is
- * no longer used, advanced graphics state is cleared and the normal graphics
- * subsystem is used from now on.
- * <p>
- * Normally, the advanced graphics subsystem is invoked automatically when
- * any one of the alpha, antialias, patterns, interpolation, paths, clipping
- * or transformation operations in the receiver is requested. When the receiver
- * is switched into advanced mode, the advanced graphics subsystem performs both
- * advanced and normal graphics operations. Because the two subsystems are
- * different, their output may differ. Switching to advanced graphics before
- * any graphics operations are performed ensures that the output is consistent.
- * </p><p>
- * Advanced graphics may not be installed for the operating system. In this
- * case, this operation does nothing. Some operating system have only one
- * graphics subsystem, so switching from normal to advanced graphics does
- * nothing. However, switching from advanced to normal graphics will always
- * clear the advanced graphics state, even for operating systems that have
- * only one graphics subsystem.
- * </p>
- *
- * @param advanced the new advanced graphics state
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAlpha
- * @see #setAntialias
- * @see #setBackgroundPattern
- * @see #setClipping(Path)
- * @see #setForegroundPattern
- * @see #setLineAttributes
- * @see #setInterpolation
- * @see #setTextAntialias
- * @see #setTransform
- * @see #getAdvanced
- *
- * @since 3.1
- */
-public void setAdvanced(boolean advanced) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (!advanced) {
- setAlpha(0xFF);
- setAntialias(SWT.DEFAULT);
- setBackgroundPattern(null);
- setClipping((Rectangle)null);
- setForegroundPattern(null);
- setInterpolation(SWT.DEFAULT);
- setTextAntialias(SWT.DEFAULT);
- setTransform(null);
- }
-}
-
-/**
- * Sets the receiver's alpha value which must be
- * between 0 (transparent) and 255 (opaque).
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param alpha the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setAlpha(int alpha) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-/**
- * Sets the receiver's anti-aliasing value to the parameter,
- * which must be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code>
- * or <code>SWT.ON</code>. Note that this controls anti-aliasing for all
- * <em>non-text drawing</em> operations.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param antialias the anti-aliasing setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.OFF</code> or <code>SWT.ON</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- * @see #setTextAntialias
- *
- * @since 3.1
- */
-public void setAntialias(int antialias) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (antialias) {
- case SWT.DEFAULT: break;
- case SWT.OFF: break;
- case SWT.ON:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-}
-
-/**
- * Sets the background color. The background color is used
- * for fill operations and as the background color when text
- * is drawn.
- *
- * @param color the new background color for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setBackground (Color color) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.background = color.handle;
- dirtyBits |= DIRTY_BACKGROUND;
-}
-
-/**
- * Sets the background pattern. The default value is <code>null</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param pattern the new background pattern
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Pattern
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setBackgroundPattern (Pattern pattern) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pattern == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the rectangular area specified
- * by the arguments.
- *
- * @param x the x coordinate of the clipping rectangle
- * @param y the y coordinate of the clipping rectangle
- * @param width the width of the clipping rectangle
- * @param height the height of the clipping rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int clipRects = data.clipRects;
- if (clipRects != 0)
- OS.free(clipRects);
- clipRects = OS.malloc(PhRect_t.sizeof);
- int clipRectsCount = 1;
- PhRect_t rect = new PhRect_t();
- rect.ul_x = (short)x;
- rect.ul_y = (short)y;
- rect.lr_x = (short)(x + width - 1);
- rect.lr_y = (short)(y + height - 1);
- OS.memmove(clipRects, rect, PhRect_t.sizeof);
- data.clipRects = clipRects;
- data.clipRectsCount = clipRectsCount;
- dirtyBits |= DIRTY_CLIPPING;
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the path specified
- * by the argument.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the clipping path.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the path has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setClipping(Path path) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path != null && path.isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the rectangular area specified
- * by the argument. Specifying <code>null</code> for the
- * rectangle reverts the receiver's clipping area to its
- * original value.
- *
- * @param rect the clipping rectangle or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping (Rectangle rect) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) {
- int clipRects = data.clipRects;
- if (clipRects != 0)
- OS.free(clipRects);
- data.clipRects = data.clipRectsCount = 0;
- dirtyBits |= DIRTY_CLIPPING;
- } else {
- setClipping (rect.x, rect.y, rect.width, rect.height);
- }
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the region specified
- * by the argument. Specifying <code>null</code> for the
- * region reverts the receiver's clipping area to its
- * original value.
- *
- * @param region the clipping region or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping (Region region) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region != null && region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int clipRects = data.clipRects;
- int clipRectsCount = data.clipRectsCount;
- if (clipRects != 0)
- OS.free(clipRects);
- if (region == null || region.handle == 0) {
- clipRects = clipRectsCount = 0;
- } else if (region.handle == Region.EMPTY_REGION) {
- clipRects = OS.malloc(PhRect_t.sizeof);
- OS.memset(clipRects, 0, PhRect_t.sizeof);
- clipRectsCount = 1;
- } else {
- int[] clip_rects_count = new int[1];
- clipRects = OS.PhTilesToRects(region.handle, clip_rects_count);
- clipRectsCount = clip_rects_count[0];
- }
- data.clipRects = clipRects;
- data.clipRectsCount = clipRectsCount;
- dirtyBits |= DIRTY_CLIPPING;
-}
-
-/**
- * Sets the receiver's fill rule to the parameter, which must be one of
- * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>.
- *
- * @param rule the new fill rule
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of <code>SWT.FILL_EVEN_ODD</code>
- * or <code>SWT.FILL_WINDING</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setFillRule(int rule) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (rule) {
- case SWT.FILL_WINDING:
- case SWT.FILL_EVEN_ODD:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- //TODO - implement fill rule
-}
-
-/**
- * Sets the font which will be used by the receiver
- * to draw and measure text to the argument. If the
- * argument is null, then a default font appropriate
- * for the platform will be used instead.
- *
- * @param font the new font for the receiver, or null to indicate a default font
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setFont (Font font) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.font = font == null ? data.device.systemFont : font;
- dirtyBits |= DIRTY_FONT;
-}
-
-/**
- * Sets the foreground color. The foreground color is used
- * for drawing operations including when text is drawn.
- *
- * @param color the new foreground color for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setForeground (Color color) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.foreground = color.handle;
- dirtyBits |= DIRTY_FOREGROUND;
-}
-
-/**
- * Sets the receiver's interpolation setting to the parameter, which
- * must be one of <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>,
- * <code>SWT.LOW</code> or <code>SWT.HIGH</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param interpolation the new interpolation setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.NONE</code>, <code>SWT.LOW</code> or <code>SWT.HIGH</code>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setInterpolation(int interpolation) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (interpolation) {
- case SWT.DEFAULT:
- case SWT.NONE:
- case SWT.LOW:
- case SWT.HIGH:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-}
-
-/**
- * Sets the foreground pattern. The default value is <code>null</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param pattern the new foreground pattern
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Pattern
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setForegroundPattern (Pattern pattern) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pattern == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-}
-
-/**
- * Sets the receiver's line attributes.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param attributes the line attributes
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the attributes is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if any of the line attributes is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see LineAttributes
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.3
- */
-public void setLineAttributes(LineAttributes attributes) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (attributes == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- //TODO - implement setLineAttributes
-}
-
-/**
- * Sets the receiver's line cap style to the argument, which must be one
- * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>,
- * or <code>SWT.CAP_SQUARE</code>.
- *
- * @param cap the cap style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineCap(int cap) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (cap) {
- case SWT.CAP_ROUND:
- case SWT.CAP_FLAT:
- case SWT.CAP_SQUARE:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineCap = cap;
- dirtyBits |= DIRTY_LINECAP;
-}
-
-/**
- * Sets the receiver's line dash style to the argument. The default
- * value is <code>null</code>. If the argument is not <code>null</code>,
- * the receiver's line style is set to <code>SWT.LINE_CUSTOM</code>, otherwise
- * it is set to <code>SWT.LINE_SOLID</code>.
- *
- * @param dashes the dash style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if any of the values in the array is less than or equal 0</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineDash(int[] dashes) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (dashes != null && dashes.length != 0) {
- byte[] dashList = new byte[dashes.length];
- for (int i = 0; i < dashes.length; i++) {
- dashList[i] = (byte)dashes[i];
- }
- data.dashes = dashList;
- data.lineStyle = SWT.LINE_CUSTOM;
- } else {
- data.dashes = null;
- data.lineStyle = SWT.LINE_SOLID;
- }
- dirtyBits |= DIRTY_LINESTYLE;
-}
-
-/**
- * Sets the receiver's line join style to the argument, which must be one
- * of the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>,
- * or <code>SWT.JOIN_BEVEL</code>.
- *
- * @param join the join style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineJoin(int join) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (join) {
- case SWT.JOIN_MITER:
- case SWT.JOIN_ROUND:
- case SWT.JOIN_BEVEL:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineJoin = join;
- dirtyBits |= DIRTY_LINEJOIN;
-}
-
-/**
- * Sets the receiver's line style to the argument, which must be one
- * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
- * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or
- * <code>SWT.LINE_DASHDOTDOT</code>.
- *
- * @param lineStyle the style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setLineStyle(int lineStyle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (lineStyle) {
- case SWT.LINE_SOLID:
- case SWT.LINE_DASH:
- case SWT.LINE_DOT:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- break;
- case SWT.LINE_CUSTOM:
- if (data.dashes == null) lineStyle = SWT.LINE_SOLID;
- break;
- default:
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- return;
- }
- data.lineStyle = lineStyle;
- dirtyBits |= DIRTY_LINESTYLE;
-}
-
-/**
- * Sets the width that will be used when drawing lines
- * for all of the figure drawing operations (that is,
- * <code>drawLine</code>, <code>drawRectangle</code>,
- * <code>drawPolyline</code>, and so forth.
- * <p>
- * Note that line width of zero is used as a hint to
- * indicate that the fastest possible line drawing
- * algorithms should be used. This means that the
- * output may be different from line width one.
- * </p>
- *
- * @param lineWidth the width of a line
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setLineWidth(int lineWidth) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- data.lineWidth = lineWidth;
- dirtyBits |= DIRTY_LINEWIDTH;
-}
-
-int setGC() {
- int result = 0;
- if (data.image != null) result = OS.PmMemStart(handle);
- else if (data.rid == OS.Ph_DEV_RID || data.widget != 0) result = OS.PgSetGC(handle);
- else return result;
-
- if (dirtyBits != 0) {
- if ((dirtyBits & DIRTY_BACKGROUND) != 0) {
- OS.PgSetFillColor(data.background);
- }
- if ((dirtyBits & DIRTY_FOREGROUND) != 0) {
- int foreColor = data.foreground;
- OS.PgSetStrokeColor(foreColor);
- OS.PgSetTextColor(foreColor);
- }
- if ((dirtyBits & DIRTY_FONT) != 0) {
- Font font = data.font;
- OS.PfLoadMetrics(font.handle);
- OS.PgSetFont(font.handle);
- }
- if ((dirtyBits & DIRTY_CLIPPING) != 0) {
- OS.PgSetMultiClip(data.clipRectsCount, data.clipRects);
- }
- if ((dirtyBits & DIRTY_LINECAP) != 0) {
- int cap_style = 0;
- switch (data.lineCap) {
- case SWT.CAP_ROUND:cap_style = OS.Pg_ROUND_CAP; break;
- case SWT.CAP_FLAT:cap_style = OS.Pg_BUTT_CAP; break;
- case SWT.CAP_SQUARE:cap_style = OS.Pg_SQUARE_CAP; break;
- }
- OS.PgSetStrokeCap(cap_style);
- }
- if ((dirtyBits & DIRTY_LINEJOIN) != 0) {
- int join_style = 0;
- switch (data.lineJoin) {
- case SWT.JOIN_ROUND:join_style = OS.Pg_ROUND_JOIN; break;
- case SWT.JOIN_MITER:join_style = OS.Pg_MITER_JOIN; break;
- case SWT.JOIN_BEVEL:join_style = OS.Pg_BEVEL_JOIN; break;
- }
- OS.PgSetStrokeJoin(join_style);
- }
- if ((dirtyBits & DIRTY_LINESTYLE) != 0) {
- byte[] dashList = null;
- switch (data.lineStyle) {
- case SWT.LINE_SOLID: dashList = DashList[0]; break;
- case SWT.LINE_DASH: dashList = DashList[1]; break;
- case SWT.LINE_DOT: dashList = DashList[2]; break;
- case SWT.LINE_DASHDOT: dashList = DashList[3]; break;
- case SWT.LINE_DASHDOTDOT: dashList = DashList[4]; break;
- case SWT.LINE_CUSTOM: dashList = data.dashes; break;
- }
- OS.PgSetStrokeDash(dashList, dashList.length, 0x10000);
- }
- if ((dirtyBits & DIRTY_LINEWIDTH) != 0) {
- OS.PgSetStrokeWidth(data.lineWidth);
- }
- if ((dirtyBits & DIRTY_XORMODE) != 0) {
- OS.PgSetDrawMode(data.xorMode ? OS.Pg_DRAWMODE_XOR : OS.Pg_DRAWMODE_OPAQUE);
- }
- dirtyBits = 0;
- }
- return result;
-}
-
-void setGCClipping() {
- int rid = data.rid;
- int widget = data.widget;
- if(OS.QNX_MAJOR >= 6 && OS.QNX_MINOR >= 3)
- {
- if(widget > 0)
- {
- int visibleTiles = OS.PtGetVisibleTiles(widget);
- if(data.clipRects != 0)
- {
- int gcClip = OS.PhRectsToTiles(data.clipRects, data.clipRectsCount);
- PhPoint_t pt = new PhPoint_t();
- PhRect_t tran_rect = new PhRect_t();
- OS.PtWidgetExtent(widget, tran_rect);
- OS.PtWidgetOffset(widget, pt);
- pt.x += tran_rect.ul_x;
- pt.y += tran_rect.ul_y;
- OS.PhTranslateTiles(gcClip, pt);
- int inter = OS.PhIntersectTilings(visibleTiles, gcClip, new short[1]);
- if(inter != 0)
- {
- OS.PgSetMultiClipTiles(inter);
- OS.free(inter);
- }
- OS.free(gcClip);
- } else
- {
- OS.PgSetMultiClipTiles(visibleTiles);
- }
- OS.free(visibleTiles);
- }
- return;
- }
- if(rid == 1)
- OS.PgSetRegion(rid);
- else
- if(widget != 0)
- OS.PgSetRegion(OS.PtWidgetRid(widget));
- else
- if(data.image != null)
- return;
- if(widget == 0)
- return;
- OS.PgSetMultiClip(data.clipRectsCount, data.clipRects);
- int clip_tile = getClipping(widget, data.topWidget, true, true, null);
- int clip_rects_count[] = new int[1];
- int clip_rects = OS.PhTilesToRects(clip_tile, clip_rects_count);
- OS.PhFreeTiles(clip_tile);
- if(clip_rects_count[0] == 0)
- {
- clip_rects_count[0] = 1;
- OS.free(clip_rects);
- clip_rects = OS.malloc(8);
- OS.memset(clip_rects, 0, 8);
- }
- OS.PgSetClipping((short)clip_rects_count[0], clip_rects);
- OS.free(clip_rects);
-}
-
-void setGCTranslation() {
- PhPoint_t pt = new PhPoint_t ();
- PhRect_t tran_rect = new PhRect_t();
- if (data.widget <= 0 ) return;
- OS.PtWidgetExtent(data.widget, tran_rect) ;
- OS.PtWidgetOffset(data.widget, pt);
- pt.x += tran_rect.ul_x;
- pt.y += tran_rect.ul_y;
- OS.PgSetTranslation(pt,0);
-}
-
-int getClipping(int widget, int topWidget, boolean clipChildren, boolean clipSiblings, int[] child_tiles) {
- if(OS.QNX_MAJOR >= 6 && OS.QNX_MINOR >= 3)
- if(widget > 0)
- {
- int visTiles = OS.PtGetVisibleTiles(widget);
- PhPoint_t pt = new PhPoint_t();
- PhRect_t tranRect = new PhRect_t();
- OS.PtWidgetExtent(widget, tranRect);
- OS.PtWidgetOffset(widget, pt);
- pt.x += tranRect.ul_x;
- pt.y += tranRect.ul_y;
- int tranPoint = OS.malloc(4);
- OS.memmove(tranPoint, pt, 4);
- OS.PhDeTranslateTiles(visTiles, tranPoint);
- return visTiles;
- } else
- {
- return 0;
- }
- int child_tile = 0;
- int widget_tile = OS.PhGetTile();
- PhRect_t rect = new PhRect_t();
- int args[] = {
- 1006, 0, 0, 2015, 0, 0
- };
- if(clipSiblings && OS.PtWidgetClass(topWidget) != OS.PtWindow())
- {
- for(int temp_widget = topWidget; (temp_widget = OS.PtWidgetBrotherInFront(temp_widget)) != 0;)
- if(OS.PtWidgetIsRealized(temp_widget))
- {
- int tile = OS.PhGetTile();
- if(child_tile == 0)
- child_tile = tile;
- else
- child_tile = OS.PhAddMergeTiles(tile, child_tile, null);
- OS.PtWidgetExtent(temp_widget, tile);
- args[1] = args[4] = 0;
- OS.PtGetResources(temp_widget, args.length / 3, args);
- if((args[1] & 0x100) != 0)
- {
- int basic_flags = args[4];
- OS.memmove(rect, tile, 8);
- if((basic_flags & 1) != 0)
- rect.ul_y++;
- if((basic_flags & 2) != 0)
- rect.lr_y--;
- if((basic_flags & 8) != 0)
- rect.ul_x++;
- if((basic_flags & 4) != 0)
- rect.lr_x--;
- OS.memmove(tile, rect, 8);
- }
- }
-
- OS.PtWidgetCanvas(topWidget, widget_tile);
- OS.PhDeTranslateTiles(child_tile, widget_tile);
- }
- if(clipChildren)
- {
- for(int temp_widget = OS.PtWidgetChildBack(widget); temp_widget != 0; temp_widget = OS.PtWidgetBrotherInFront(temp_widget))
- if(OS.PtWidgetIsRealized(temp_widget))
- {
- int tile = OS.PhGetTile();
- if(child_tile == 0)
- child_tile = tile;
- else
- child_tile = OS.PhAddMergeTiles(tile, child_tile, null);
- OS.PtWidgetExtent(temp_widget, tile);
- args[1] = args[4] = 0;
- OS.PtGetResources(temp_widget, args.length / 3, args);
- if((args[1] & 0x100) != 0)
- {
- int basic_flags = args[4];
- OS.memmove(rect, tile, 8);
- if((basic_flags & 1) != 0)
- rect.ul_y++;
- if((basic_flags & 2) != 0)
- rect.lr_y--;
- if((basic_flags & 8) != 0)
- rect.ul_x++;
- if((basic_flags & 4) != 0)
- rect.lr_x--;
- OS.memmove(tile, rect, 8);
- }
- }
-
- }
- OS.PtWidgetCanvas(widget, widget_tile);
- OS.PhDeTranslateTiles(widget_tile, widget_tile);
- if(child_tile != 0)
- {
- if(child_tiles != null)
- child_tiles[0] = OS.PhIntersectTilings(widget_tile, child_tile, new short[1]);
- int clip_tile = OS.PhClipTilings(widget_tile, child_tile, null);
- OS.PhFreeTiles(child_tile);
- return clip_tile;
- } else
- {
- return widget_tile;
- }
-}
-
-/**
- * Sets the receiver's text anti-aliasing value to the parameter,
- * which must be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code>
- * or <code>SWT.ON</code>. Note that this controls anti-aliasing only
- * for all <em>text drawing</em> operations.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param antialias the anti-aliasing setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.OFF</code> or <code>SWT.ON</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- * @see #setAntialias
- *
- * @since 3.1
- */
-public void setTextAntialias(int antialias) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (antialias) {
- case SWT.DEFAULT: break;
- case SWT.OFF: break;
- case SWT.ON: break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-}
-
-/**
- * Sets the transform that is currently being used by the receiver. If
- * the argument is <code>null</code>, the current transform is set to
- * the identity transform.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param transform the transform to set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Transform
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setTransform(Transform transform) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transform != null && transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-}
-
-/**
- * If the argument is <code>true</code>, puts the receiver
- * in a drawing mode where the resulting color in the destination
- * is the <em>exclusive or</em> of the color values in the source
- * and the destination, and if the argument is <code>false</code>,
- * puts the receiver in a drawing mode where the destination color
- * is replaced with the source color value.
- * <p>
- * Note that this mode in fundamentally unsupportable on certain
- * platforms, notably Carbon (Mac OS X). Clients that want their
- * code to run on all platforms need to avoid this method.
- * </p>
- *
- * @param xor if <code>true</code>, then <em>xor</em> mode is used, otherwise <em>source copy</em> mode is used
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @deprecated this functionality is not supported on some platforms
- */
-public void setXORMode(boolean xor) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- data.xorMode = xor;
- dirtyBits |= DIRTY_XORMODE;
-}
-
-/**
- * Returns the extent of the given string. No tab
- * expansion or carriage return processing will be performed.
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point stringExtent(String string) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- PhRect_t rect = new PhRect_t();
- int size = string.length();
- char[] buffer = new char[size];
- string.getChars(0, size, buffer, 0);
-
- int flags = OS.PtEnter(0);
- try {
- OS.PfExtentWideText(rect, null, data.font.handle, buffer, size * 2);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-
- int width;
- if (size == 0) width = 0;
- else width = rect.lr_x - (rect.ul_x < 0 ? rect.ul_x : 0) + 1;
- int height = rect.lr_y - rect.ul_y + 1;
- return new Point(width, height);
-}
-
-/**
- * Returns the extent of the given string. Tab expansion and
- * carriage return processing are performed.
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point textExtent(String string) {
- return textExtent(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
-}
-
-/**
- * Returns the extent of the given string. Tab expansion, line
- * delimiter and mnemonic processing are performed according to
- * the specified flags, which can be a combination of:
- * <dl>
- * <dt><b>DRAW_DELIMITER</b></dt>
- * <dd>draw multiple lines</dd>
- * <dt><b>DRAW_TAB</b></dt>
- * <dd>expand tabs</dd>
- * <dt><b>DRAW_MNEMONIC</b></dt>
- * <dd>underline the mnemonic character</dd>
- * <dt><b>DRAW_TRANSPARENT</b></dt>
- * <dd>transparent background</dd>
- * </dl>
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @param flags the flags specifying how to process the text
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point textExtent(String string, int flags) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if ((flags & ~SWT.DRAW_TRANSPARENT) == 0 || string.length() == 0) {
- return stringExtent(string);
- } else {
- return drawText(string, 0, 0, flags, false);
- }
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "GC {*DISPOSED*}";
- return "GC {" + handle + "}";
-}
-
-void unsetGC(int prevContext) {
- Image image = data.image;
- if (image != null) {
-// OS.PmMemFlush(handle, image.handle);
- OS.PmMemStop(handle);
- OS.PhDCSetCurrent(prevContext);
- } else if (data.rid == OS.Ph_DEV_RID || data.widget != 0) {
- OS.PgSetGC(prevContext);
-// OS.PgFlush();
- }
-}
-
-public static GC photon_new(Drawable drawable, GCData data) {
- GC gc = new GC();
- int context = drawable.internal_new_GC(data);
- gc.device = data.device;
- gc.init(drawable, data, context);
- return gc;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/GCData.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/GCData.java
deleted file mode 100755
index 04aa2aa616..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/GCData.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class are descriptions of GCs in terms
- * of unallocated platform-specific data fields.
- * <p>
- * <b>IMPORTANT:</b> This class is <em>not</em> part of the public
- * API for SWT. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms, and should never be called from application code.
- * </p>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noinstantiate This class is not intended to be instantiated by clients.
- */
-public final class GCData {
- public Device device;
- public int style;
- public Image image;
- public int rid;
- public int widget, topWidget;
- public int foreground = -1;
- public int background = -1;
- public Font font;
- public boolean xorMode;
- public int lineStyle = SWT.LINE_SOLID;
- public int lineCap = SWT.CAP_FLAT;
- public int lineJoin = SWT.JOIN_MITER;
- public int lineWidth = 1;
- public byte[] dashes;
- public int clipRectsCount;
- public int clipRects;
- public boolean paint;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Image.java
deleted file mode 100755
index 756a8d0493..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Image.java
+++ /dev/null
@@ -1,1046 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import java.io.*;
-
-/**
- * Instances of this class are graphics which have been prepared
- * for display on a specific device. That is, they are ready
- * to paint using methods such as <code>GC.drawImage()</code>
- * and display on widgets with, for example, <code>Button.setImage()</code>.
- * <p>
- * If loaded from a file format that supports it, an
- * <code>Image</code> may have transparency, meaning that certain
- * pixels are specified as being transparent when drawn. Examples
- * of file formats that support transparency are GIF and PNG.
- * </p><p>
- * There are two primary ways to use <code>Images</code>.
- * The first is to load a graphic file from disk and create an
- * <code>Image</code> from it. This is done using an <code>Image</code>
- * constructor, for example:
- * <pre>
- * Image i = new Image(device, "C:\\graphic.bmp");
- * </pre>
- * A graphic file may contain a color table specifying which
- * colors the image was intended to possess. In the above example,
- * these colors will be mapped to the closest available color in
- * SWT. It is possible to get more control over the mapping of
- * colors as the image is being created, using code of the form:
- * <pre>
- * ImageData data = new ImageData("C:\\graphic.bmp");
- * RGB[] rgbs = data.getRGBs();
- * // At this point, rgbs contains specifications of all
- * // the colors contained within this image. You may
- * // allocate as many of these colors as you wish by
- * // using the Color constructor Color(RGB), then
- * // create the image:
- * Image i = new Image(device, data);
- * </pre>
- * <p>
- * Applications which require even greater control over the image
- * loading process should use the support provided in class
- * <code>ImageLoader</code>.
- * </p><p>
- * Application code must explicitly invoke the <code>Image.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see Color
- * @see ImageData
- * @see ImageLoader
- * @see <a href="http://www.eclipse.org/swt/snippets/#image">Image snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, ImageAnalyzer</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Image extends Resource implements Drawable {
-
- /**
- * specifies whether the receiver is a bitmap or an icon
- * (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int type;
-
- /**
- * the handle to the OS image resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
- /**
- * specifies the transparent pixel
- */
- int transparentPixel = -1;
-
- /**
- * the GC which is drawing on the image
- */
- GC memGC;
-
- /**
- * specifies the default scanline padding
- */
- static final int DEFAULT_SCANLINE_PAD = 4;
-
-Image (Device device) {
- super(device);
-}
-
-/**
- * Constructs an empty instance of this class with the
- * specified width and height. The result may be drawn upon
- * by creating a GC and using any of its drawing operations,
- * as shown in the following example:
- * <pre>
- * Image i = new Image(device, width, height);
- * GC gc = new GC(i);
- * gc.drawRectangle(0, 0, 50, 50);
- * gc.dispose();
- * </pre>
- * <p>
- * Note: Some platforms may have a limitation on the size
- * of image that can be created (size depends on width, height,
- * and depth). For example, Windows 95, 98, and ME do not allow
- * images larger than 16M.
- * </p>
- *
- * @param device the device on which to create the image
- * @param width the width of the new image
- * @param height the height of the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - if either the width or height is negative or zero</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, int width, int height) {
- super(device);
- init(width, height);
- init();
-}
-
-/**
- * Constructs a new instance of this class based on the
- * provided image, with an appearance that varies depending
- * on the value of the flag. The possible flag values are:
- * <dl>
- * <dt><b>{@link SWT#IMAGE_COPY}</b></dt>
- * <dd>the result is an identical copy of srcImage</dd>
- * <dt><b>{@link SWT#IMAGE_DISABLE}</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>disabled</em> look</dd>
- * <dt><b>{@link SWT#IMAGE_GRAY}</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>gray scale</em> look</dd>
- * </dl>
- *
- * @param device the device on which to create the image
- * @param srcImage the image to use as the source
- * @param flag the style, either <code>IMAGE_COPY</code>, <code>IMAGE_DISABLE</code> or <code>IMAGE_GRAY</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if srcImage is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the flag is not one of <code>IMAGE_COPY</code>, <code>IMAGE_DISABLE</code> or <code>IMAGE_GRAY</code></li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon, or is otherwise in an invalid state</li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the image is not supported</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, Image srcImage, int flag) {
- super(device);
- if (srcImage == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (srcImage.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- switch (flag) {
- case SWT.IMAGE_COPY:
- case SWT.IMAGE_DISABLE:
- this.type = srcImage.type;
- int srcHandle = srcImage.handle;
- int newHandle = OS.PiDuplicateImage (srcHandle, 0);
- if (newHandle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (flag == SWT.IMAGE_COPY) {
- /*
- * Bug in Photon. The image returned by PiDuplicateImage might
- * have the same mask_bm/alpha as the original image. The fix
- * is to detect this case and copy mask_bm/alpha if necessary.
- */
- PhImage_t phImage = new PhImage_t();
- OS.memmove (phImage, srcHandle, PhImage_t.sizeof);
- PhImage_t newPhImage = new PhImage_t();
- OS.memmove(newPhImage, newHandle, PhImage_t.sizeof);
- if (newPhImage.mask_bm != 0 && phImage.mask_bm == newPhImage.mask_bm) {
- int length = newPhImage.mask_bpl * newPhImage.size_h;
- int ptr = OS.malloc(length);
- OS.memmove(ptr, newPhImage.mask_bm, length);
- newPhImage.mask_bm = ptr;
- }
- if (newPhImage.alpha != 0 && phImage.alpha == newPhImage.alpha) {
- PgAlpha_t alpha = new PgAlpha_t();
- OS.memmove(alpha, phImage.alpha, PgAlpha_t.sizeof);
- if (alpha.src_alpha_map_map != 0) {
- int length = alpha.src_alpha_map_bpl * alpha.src_alpha_map_dim_h;
- int ptr = OS.malloc(length);
- OS.memmove(ptr, alpha.src_alpha_map_map, length);
- alpha.src_alpha_map_map = ptr;
- }
- int ptr = OS.malloc(PgAlpha_t.sizeof);
- OS.memmove(ptr, alpha, PgAlpha_t.sizeof);
- newPhImage.alpha = ptr;
- }
- OS.memmove(newHandle, newPhImage, PhImage_t.sizeof);
- transparentPixel = srcImage.transparentPixel;
- } else {
- PhImage_t phImage = new PhImage_t();
- OS.PhMakeGhostBitmap(newHandle);
- OS.memmove (phImage, newHandle, PhImage_t.sizeof);
- phImage.mask_bm = phImage.ghost_bitmap;
- phImage.mask_bpl = phImage.ghost_bpl;
- phImage.ghost_bitmap = 0;
- phImage.ghost_bpl = 0;
- phImage.alpha = 0;
- OS.memmove (newHandle, phImage, PhImage_t.sizeof);
- }
- handle = newHandle;
- break;
- case SWT.IMAGE_GRAY:
- Rectangle r = srcImage.getBounds();
- ImageData data = srcImage.getImageData();
- PaletteData palette = data.palette;
- ImageData newData = data;
- if (!palette.isDirect) {
- /* Convert the palette entries to gray. */
- RGB [] rgbs = palette.getRGBs();
- for (int i=0; i<rgbs.length; i++) {
- if (data.transparentPixel != i) {
- RGB color = rgbs [i];
- int red = color.red;
- int green = color.green;
- int blue = color.blue;
- int intensity = (red+red+green+green+green+green+green+blue) >> 3;
- color.red = color.green = color.blue = intensity;
- }
- }
- newData.palette = new PaletteData(rgbs);
- } else {
- /* Create a 8 bit depth image data with a gray palette. */
- RGB[] rgbs = new RGB[256];
- for (int i=0; i<rgbs.length; i++) {
- rgbs[i] = new RGB(i, i, i);
- }
- newData = new ImageData(r.width, r.height, 8, new PaletteData(rgbs));
- newData.alpha = data.alpha;
- newData.alphaData = data.alphaData;
- newData.maskData = data.maskData;
- newData.maskPad = data.maskPad;
- if (data.transparentPixel != -1) newData.transparentPixel = 254;
-
- /* Convert the pixels. */
- int[] scanline = new int[r.width];
- int redMask = palette.redMask;
- int greenMask = palette.greenMask;
- int blueMask = palette.blueMask;
- int redShift = palette.redShift;
- int greenShift = palette.greenShift;
- int blueShift = palette.blueShift;
- for (int y=0; y<r.height; y++) {
- int offset = y * newData.bytesPerLine;
- data.getPixels(0, y, r.width, scanline, 0);
- for (int x=0; x<r.width; x++) {
- int pixel = scanline[x];
- if (pixel != data.transparentPixel) {
- int red = pixel & redMask;
- red = (redShift < 0) ? red >>> -redShift : red << redShift;
- int green = pixel & greenMask;
- green = (greenShift < 0) ? green >>> -greenShift : green << greenShift;
- int blue = pixel & blueMask;
- blue = (blueShift < 0) ? blue >>> -blueShift : blue << blueShift;
- int intensity = (red+red+green+green+green+green+green+blue) >> 3;
- if (newData.transparentPixel == intensity) intensity = 255;
- newData.data[offset] = (byte)intensity;
- } else {
- newData.data[offset] = (byte)254;
- }
- offset++;
- }
- }
- }
- init (newData);
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- init();
-}
-
-/**
- * Constructs an empty instance of this class with the
- * width and height of the specified rectangle. The result
- * may be drawn upon by creating a GC and using any of its
- * drawing operations, as shown in the following example:
- * <pre>
- * Image i = new Image(device, boundsRectangle);
- * GC gc = new GC(i);
- * gc.drawRectangle(0, 0, 50, 50);
- * gc.dispose();
- * </pre>
- * <p>
- * Note: Some platforms may have a limitation on the size
- * of image that can be created (size depends on width, height,
- * and depth). For example, Windows 95, 98, and ME do not allow
- * images larger than 16M.
- * </p>
- *
- * @param device the device on which to create the image
- * @param bounds a rectangle specifying the image's width and height (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the bounds rectangle is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, Rectangle bounds) {
- super(device);
- if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(bounds.width, bounds.height);
- init();
-}
-
-/**
- * Constructs an instance of this class from the given
- * <code>ImageData</code>.
- *
- * @param device the device on which to create the image
- * @param data the image data to create the image from (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the image data is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the ImageData is not supported</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, ImageData data) {
- super(device);
- init(data);
- init();
-}
-
-/**
- * Constructs an instance of this class, whose type is
- * <code>SWT.ICON</code>, from the two given <code>ImageData</code>
- * objects. The two images must be the same size. Pixel transparency
- * in either image will be ignored.
- * <p>
- * The mask image should contain white wherever the icon is to be visible,
- * and black wherever the icon is to be transparent. In addition,
- * the source image should contain black wherever the icon is to be
- * transparent.
- * </p>
- *
- * @param device the device on which to create the icon
- * @param source the color data for the icon
- * @param mask the mask data for the icon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if either the source or mask is null </li>
- * <li>ERROR_INVALID_ARGUMENT - if source and mask are different sizes</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, ImageData source, ImageData mask) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (mask == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (source.width != mask.width || source.height != mask.height) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- mask = ImageData.convertMask(mask);
- ImageData image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad, source.data);
- image.maskPad = mask.scanlinePad;
- image.maskData = mask.data;
- init(image);
- init();
-}
-
-/**
- * Constructs an instance of this class by loading its representation
- * from the specified input stream. Throws an error if an error
- * occurs while loading the image, or if the result is an image
- * of an unsupported type. Application code is still responsible
- * for closing the input stream.
- * <p>
- * This constructor is provided for convenience when loading a single
- * image only. If the stream contains multiple images, only the first
- * one will be loaded. To load multiple images, use
- * <code>ImageLoader.load()</code>.
- * </p><p>
- * This constructor may be used to load a resource as follows:
- * </p>
- * <pre>
- * static Image loadImage (Display display, Class clazz, String string) {
- * InputStream stream = clazz.getResourceAsStream (string);
- * if (stream == null) return null;
- * Image image = null;
- * try {
- * image = new Image (display, stream);
- * } catch (SWTException ex) {
- * } finally {
- * try {
- * stream.close ();
- * } catch (IOException ex) {}
- * }
- * return image;
- * }
- * </pre>
- *
- * @param device the device on which to create the image
- * @param stream the input stream to load the image from
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the stream is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from the stream</li>
- * <li>ERROR_INVALID_IMAGE - if the image stream contains invalid data </li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the image stream describes an image with an unsupported depth</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image (Device device, InputStream stream) {
- super(device);
- init(new ImageData(stream));
- init();
-}
-
-/**
- * Constructs an instance of this class by loading its representation
- * from the file with the specified name. Throws an error if an error
- * occurs while loading the image, or if the result is an image
- * of an unsupported type.
- * <p>
- * This constructor is provided for convenience when loading
- * a single image only. If the specified file contains
- * multiple images, only the first one will be used.
- *
- * @param device the device on which to create the image
- * @param filename the name of the file to load the image from
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the file name is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from the file</li>
- * <li>ERROR_INVALID_IMAGE - if the image file contains invalid data </li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the image file describes an image with an unsupported depth</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image (Device device, String filename) {
- super(device);
- init(new ImageData(filename));
- init();
-}
-
-void destroy() {
- if (memGC != null) memGC.dispose();
- destroyImage(handle);
- handle = 0;
- memGC = null;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Image)) return false;
- Image image = (Image) object;
- return device == image.device && handle == image.handle;
-}
-
-/**
- * Returns the color to which to map the transparent pixel, or null if
- * the receiver has no transparent pixel.
- * <p>
- * There are certain uses of Images that do not support transparency
- * (for example, setting an image into a button or label). In these cases,
- * it may be desired to simulate transparency by using the background
- * color of the widget to paint the transparent pixels of the image.
- * Use this method to check which color will be used in these cases
- * in place of transparency. This value may be set with setBackground().
- * <p>
- *
- * @return the background color of the image, or null if there is no transparency in the image
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getBackground() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transparentPixel == -1) return null;
-
- PhImage_t phImage = new PhImage_t();
- OS.memmove(phImage, handle, PhImage_t.sizeof);
- int color = 0;
- if ((phImage.type & OS.Pg_IMAGE_CLASS_MASK) == OS.Pg_IMAGE_CLASS_PALETTE) {
- int phPalette = phImage.palette;
- if (phPalette == 0 || transparentPixel > phImage.colors) return null;
- int[] pgColor = new int[1];
- OS.memmove(pgColor, phPalette + (transparentPixel * 4), 4);
- color = pgColor[0];
- } else {
- switch (phImage.type) {
- case OS.Pg_IMAGE_DIRECT_888:
- color = ((transparentPixel & 0xFF) << 16) | (transparentPixel & 0xFF00) | ((transparentPixel & 0xFF0000) >> 16);
- break;
- case OS.Pg_IMAGE_DIRECT_8888:
- color = ((transparentPixel & 0xFF00) << 8) | ((transparentPixel & 0xFF0000) >> 8) | ((transparentPixel & 0xFF000000) >> 24);
- break;
- case OS.Pg_IMAGE_DIRECT_565:
- color = ((transparentPixel & 0xF800) << 8) | ((transparentPixel & 0x7E0) << 5) | ((transparentPixel & 0x1F) << 3);
- break;
- case OS.Pg_IMAGE_DIRECT_555:
- color = ((transparentPixel & 0x7C00) << 9) | ((transparentPixel & 0x3E0) << 6) | ((transparentPixel & 0x1F) << 3);
- break;
- case OS.Pg_IMAGE_DIRECT_444:
- color = ((transparentPixel & 0xF00) << 12) | ((transparentPixel & 0xF0) << 8) | ((transparentPixel & 0xF) << 4);
- break;
- default:
- return null;
- }
- }
- return Color.photon_new(device, color);
-}
-
-/**
- * Returns the bounds of the receiver. The rectangle will always
- * have x and y values of 0, and the width and height of the
- * image.
- *
- * @return a rectangle specifying the image's bounds
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li>
- * </ul>
- */
-public Rectangle getBounds() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- PhImage_t image = new PhImage_t();
- OS.memmove(image, handle, PhImage_t.sizeof);
- return new Rectangle(0, 0, image.size_w, image.size_h);
-}
-
-/**
- * Returns an <code>ImageData</code> based on the receiver
- * Modifications made to this <code>ImageData</code> will not
- * affect the Image.
- *
- * @return an <code>ImageData</code> containing the image's data and attributes
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li>
- * </ul>
- *
- * @see ImageData
- */
-public ImageData getImageData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (memGC != null) memGC.flushImage();
- PhImage_t phImage = new PhImage_t();
- OS.memmove(phImage, handle, PhImage_t.sizeof);
- int depth = 0;
- PaletteData palette = null;
- switch (phImage.type) {
- case OS.Pg_IMAGE_DIRECT_555:
- depth = 16;
- palette = new PaletteData(0x7C00,0x3E0,0x1F);
- break;
- case OS.Pg_IMAGE_DIRECT_565:
- depth = 16;
- palette = new PaletteData(0xF800,0x7E0,0x1F);
- break;
- case OS.Pg_IMAGE_DIRECT_444:
- depth = 16;
- palette = new PaletteData(0xF00,0xF0,0xF);
- break;
- case OS.Pg_IMAGE_DIRECT_888:
- depth = 24;
- palette = new PaletteData(0xFF,0xFF00,0xFF0000);
- break;
- case OS.Pg_IMAGE_DIRECT_8888:
- depth = 32;
- palette = new PaletteData(0xFF00,0xFF0000,0xFF000000);
- break;
- case -1:
- depth = 1;
- palette = new PaletteData(new RGB[] {new RGB(0,0,0), new RGB(255,255,255)});
- break;
- case OS.Pg_IMAGE_PALETTE_NIBBLE:
- case OS.Pg_IMAGE_PALETTE_BYTE:
- depth = phImage.type == OS.Pg_IMAGE_PALETTE_BYTE ? 8 : 4;
- RGB[] rgbs = new RGB[phImage.colors];
- int[] colors = new int[phImage.colors];
- OS.memmove(colors, phImage.palette, colors.length * 4);
- for (int i = 0; i < rgbs.length; i++) {
- int rgb = colors[i];
- rgbs[i] = new RGB((rgb & 0xFF0000) >> 16, (rgb & 0xFF00) >> 8, rgb & 0xFF);
- }
- palette = new PaletteData(rgbs);
- break;
- default:
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- }
-
- int scanLinePad, bpl = phImage.bpl;
- int width = phImage.size_w, height = phImage.size_h;
- int dataBytesPerLine = (width * depth + 7) / 8;
- for (scanLinePad = 1; scanLinePad < 128; scanLinePad++) {
- int calcBpl = (dataBytesPerLine + (scanLinePad - 1)) / scanLinePad * scanLinePad;
- if (bpl == calcBpl) break;
- }
- byte[] data = new byte[height * bpl];
- OS.memmove(data, phImage.image, data.length);
-
- ImageData imageData = new ImageData(width, height, depth, palette, scanLinePad, data);
-
- if (transparentPixel != -1) {
- imageData.transparentPixel = transparentPixel;
- } else if (phImage.mask_bm != 0) {
- imageData.maskData = new byte[height * phImage.mask_bpl];
- OS.memmove(imageData.maskData, phImage.mask_bm, imageData.maskData.length);
- imageData.maskPad = 2;
- } else if (phImage.alpha != 0) {
- PgAlpha_t alpha = new PgAlpha_t();
- OS.memmove(alpha, phImage.alpha, PgAlpha_t.sizeof);
- imageData.alpha = alpha.src_global_alpha;
- if ((alpha.alpha_op & OS.Pg_ALPHA_OP_SRC_MAP) != 0 && alpha.src_alpha_map_map != 0) {
- int length = alpha.src_alpha_map_dim_w * alpha.src_alpha_map_dim_h;
- imageData.alphaData = new byte[length];
- OS.memmove(imageData.alphaData, alpha.src_alpha_map_map, length);
- }
- }
-
- return imageData;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return handle;
-}
-
-void init(int width, int height) {
- if (width <= 0 || height <= 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.type = SWT.BITMAP;
-
- handle = OS.PhCreateImage(null, (short)width, (short)height, OS.Pg_IMAGE_DIRECT_888, 0, 0, 0);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
-}
-
-void init(ImageData i) {
- if (i == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
-
- /*
- * Feature in Photon. Photon does not support 2-bit depth images and
- * memory contexts can not be created on 1 & 4-bit depth images. The
- * fix is to create 8-bit depth images instead.
- */
- if ((i.depth == 1 || i.depth == 2 || i.depth == 4) && !i.palette.isDirect) {
- ImageData img = new ImageData(i.width, i.height, 8, i.palette);
- ImageData.blit(ImageData.BLIT_SRC,
- i.data, i.depth, i.bytesPerLine, img.getByteOrder(), 0, 0, i.width, i.height, null, null, null,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- img.data, img.depth, img.bytesPerLine, img.getByteOrder(), 0, 0, img.width, img.height, null, null, null,
- false, false);
- img.transparentPixel = i.transparentPixel;
- img.maskPad = i.maskPad;
- img.maskData = i.maskData;
- img.alpha = i.alpha;
- img.alphaData = i.alphaData;
- i = img;
- }
-
- int type = 0;
- int[] phPalette = null;
- if (!i.palette.isDirect) {
- switch (i.depth) {
- case 4: type = OS.Pg_IMAGE_PALETTE_NIBBLE; break;
- case 8: type = OS.Pg_IMAGE_PALETTE_BYTE; break;
- default: SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- }
- RGB[] rgbs = i.palette.getRGBs();
- phPalette = new int[rgbs.length];
- for (int j=0; j<rgbs.length; j++) {
- RGB rgb = rgbs[j];
- phPalette[j] = ((rgb.red & 0xFF) << 16) | ((rgb.green & 0xFF) << 8) | (rgb.blue & 0xFF);
- }
- } else {
- final PaletteData palette = i.palette;
- final int redMask = palette.redMask;
- final int greenMask = palette.greenMask;
- final int blueMask = palette.blueMask;
- int newDepth = i.depth;
- int newOrder = ImageData.MSB_FIRST;
- PaletteData newPalette = null;
-
- switch (i.depth) {
- case 8:
- newDepth = 16;
- newOrder = ImageData.LSB_FIRST;
- newPalette = new PaletteData(0xF800, 0x7E0, 0x1F);
- type = OS.Pg_IMAGE_DIRECT_565;
- break;
- case 16:
- newOrder = ImageData.LSB_FIRST;
- if (redMask == 0x7C00 && greenMask == 0x3E0 && blueMask == 0x1F) {
- type = OS.Pg_IMAGE_DIRECT_555;
- } else if (redMask == 0xF800 && greenMask == 0x7E0 && blueMask == 0x1F) {
- type = OS.Pg_IMAGE_DIRECT_565;
- } else if (redMask == 0xF00 && greenMask == 0xF0 && blueMask == 0xF) {
- type = OS.Pg_IMAGE_DIRECT_444;
- } else {
- type = OS.Pg_IMAGE_DIRECT_565;
- newPalette = new PaletteData(0xF800, 0x7E0, 0x1F);
- }
- break;
- case 24:
- if (redMask == 0xFF && greenMask == 0xFF00 && blueMask == 0xFF0000) {
- type = OS.Pg_IMAGE_DIRECT_888;
- } else {
- type = OS.Pg_IMAGE_DIRECT_888;
- newPalette = new PaletteData(0xFF, 0xFF00, 0xFF0000);
- }
- break;
- case 32:
- if (redMask == 0xFF00 && greenMask == 0xFF0000 && blueMask == 0xFF000000) {
- type = OS.Pg_IMAGE_DIRECT_8888;
- } else {
- type = OS.Pg_IMAGE_DIRECT_8888;
- newPalette = new PaletteData(0xFF00, 0xFF0000, 0xFF000000);
- }
- break;
- default:
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- }
- if (newPalette != null) {
- ImageData img = new ImageData(i.width, i.height, newDepth, newPalette);
- ImageData.blit(ImageData.BLIT_SRC,
- i.data, i.depth, i.bytesPerLine, i.getByteOrder(), 0, 0, i.width, i.height, redMask, greenMask, blueMask,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- img.data, img.depth, img.bytesPerLine, newOrder, 0, 0, img.width, img.height, newPalette.redMask, newPalette.greenMask, newPalette.blueMask,
- false, false);
- if (i.transparentPixel != -1) {
- img.transparentPixel = newPalette.getPixel(palette.getRGB(i.transparentPixel));
- }
- img.maskPad = i.maskPad;
- img.maskData = i.maskData;
- img.alpha = i.alpha;
- img.alphaData = i.alphaData;
- i = img;
- }
- }
- int handle = OS.malloc(PhImage_t.sizeof);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- PhImage_t phImage = new PhImage_t();
- phImage.type = type;
- phImage.flags = (byte)OS.Ph_RELEASE_IMAGE_ALL;
- int size = i.data.length;
- int ptr = OS.malloc(size);
- if (ptr == 0) {
- OS.free(handle);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- OS.memmove(ptr, i.data, size);
- phImage.image = ptr;
- phImage.size_w = (short)i.width;
- phImage.size_h = (short)i.height;
- phImage.bpl = i.bytesPerLine;
- if (phPalette != null) {
- size = phPalette.length * 4;
- ptr = OS.malloc(size);
- if (ptr == 0) {
- OS.free(phImage.image);
- OS.free(handle);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- OS.memmove(ptr, phPalette, size);
- phImage.palette = ptr;
- phImage.colors = phPalette.length;
- }
- if (i.getTransparencyType() == SWT.TRANSPARENCY_MASK) {
- this.type = SWT.ICON;
- int maskBpl = (i.width * 1 + 7) / 8;
- maskBpl = (maskBpl + (i.maskPad - 1)) / i.maskPad * i.maskPad;
- size = maskBpl * i.height;
- ptr = OS.malloc(size);
- if (ptr == 0) {
- if (phImage.palette != 0) OS.free(phImage.palette);
- OS.free(phImage.image);
- OS.free(handle);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- OS.memmove(ptr, i.maskData, size);
- phImage.mask_bm = ptr;
- phImage.mask_bpl = maskBpl;
- } else {
- this.type = SWT.BITMAP;
- if (i.transparentPixel != -1) {
- /*
- * The PhImage_t field transparent can not used to store the
- * transparent pixel because it is overwritten when a GC is
- * created on the image.
- */
- transparentPixel = i.transparentPixel;
- } else if (i.alpha != -1 || i.alphaData != null) {
- PgAlpha_t alpha = new PgAlpha_t();
- alpha.alpha_op = i.alpha != -1 ? OS.Pg_ALPHA_OP_SRC_GLOBAL : OS.Pg_ALPHA_OP_SRC_MAP;
- alpha.alpha_op |= OS.Pg_BLEND_SRC_SRC_ALPHA | OS.Pg_BLEND_DST_ONE_MINUS_SRC_ALPHA;
- alpha.src_global_alpha = (byte)i.alpha;
- if (i.alpha == -1 && i.alphaData != null) {
- ptr = OS.malloc(i.alphaData.length);
- if (ptr == 0) {
- if (phImage.palette != 0) OS.free(phImage.palette);
- OS.free(phImage.image);
- OS.free(handle);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- OS.memmove(ptr, i.alphaData, i.alphaData.length);
- alpha.src_alpha_map_bpl = (short)i.width;
- alpha.src_alpha_map_dim_w = (short)i.width;
- alpha.src_alpha_map_dim_h = (short)i.height;
- alpha.src_alpha_map_map = ptr;
- }
- ptr = OS.malloc(PgAlpha_t.sizeof);
- if (ptr == 0) {
- if (alpha.src_alpha_map_map != 0) OS.free(alpha.src_alpha_map_map);
- if (phImage.palette != 0) OS.free(phImage.palette);
- OS.free(phImage.image);
- OS.free(handle);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- OS.memmove(ptr, alpha, PgAlpha_t.sizeof);
- phImage.alpha = ptr;
- }
- }
- OS.memmove(handle, phImage, PhImage_t.sizeof);
- this.handle = handle;
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public int internal_new_GC (GCData data) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- /*
- * Create a new GC that can draw into the image.
- * Only supported for bitmaps.
- */
- if (type != SWT.BITMAP || memGC != null) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- PhImage_t phImage = new PhImage_t();
- OS.memmove(phImage, handle, PhImage_t.sizeof);
- PhDim_t dim = new PhDim_t();
- dim.w = phImage.size_w;
- dim.h = phImage.size_h;
- PhPoint_t trans = new PhPoint_t();
- int pmMC = OS.PmMemCreateMC(handle, dim, trans);
- if (pmMC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) == 0) {
- data.style |= SWT.LEFT_TO_RIGHT;
- }
-
- data.device = device;
- data.image = this;
- return pmMC;
-}
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int pmMC, GCData data) {
- OS.PmMemReleaseMC(pmMC);
-}
-
-/**
- * Returns <code>true</code> if the image has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the image.
- * When an image has been disposed, it is an error to
- * invoke any other method using the image.
- *
- * @return <code>true</code> when the image is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Sets the color to which to map the transparent pixel.
- * <p>
- * There are certain uses of <code>Images</code> that do not support
- * transparency (for example, setting an image into a button or label).
- * In these cases, it may be desired to simulate transparency by using
- * the background color of the widget to paint the transparent pixels
- * of the image. This method specifies the color that will be used in
- * these cases. For example:
- * <pre>
- * Button b = new Button();
- * image.setBackground(b.getBackground());
- * b.setImage(image);
- * </pre>
- * </p><p>
- * The image may be modified by this operation (in effect, the
- * transparent regions may be filled with the supplied color). Hence
- * this operation is not reversible and it is not legal to call
- * this function twice or with a null argument.
- * </p><p>
- * This method has no effect if the receiver does not have a transparent
- * pixel value.
- * </p>
- *
- * @param color the color to use when a transparent pixel is specified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setBackground(Color color) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (transparentPixel == -1) return;
-
- PhImage_t phImage = new PhImage_t();
- OS.memmove(phImage, handle, PhImage_t.sizeof);
- int phPalette = phImage.palette;
- if (phPalette == 0 || transparentPixel > phImage.colors) return;
- int[] pgColor = new int[]{ color.handle };
- OS.memmove(phPalette + (transparentPixel * 4), pgColor, 4);
-}
-
-static void destroyImage(int image) {
- if (image == 0) return;
- PhImage_t phImage = new PhImage_t();
- OS.memmove(phImage, image, PhImage_t.sizeof);
- phImage.flags = (byte)OS.Ph_RELEASE_IMAGE_ALL;
- OS.memmove(image, phImage, PhImage_t.sizeof);
- OS.PhReleaseImage(image);
- OS.free(image);
-}
-
-public static Image photon_new(Device device, int type, int handle) {
- Image image = new Image(device);
- image.type = type;
- image.handle = handle;
- return image;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Image {*DISPOSED*}";
- return "Image {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Region.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Region.java
deleted file mode 100755
index 1540cb3f41..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Region.java
+++ /dev/null
@@ -1,638 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class represent areas of an x-y coordinate
- * system that are aggregates of the areas covered by a number
- * of polygons.
- * <p>
- * Application code must explicitly invoke the <code>Region.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class Region extends Resource {
-
- /**
- * the OS resource for the region
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
- static int EMPTY_REGION = -1;
-
-/**
- * Constructs a new empty region.
- *
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
- * </ul>
- */
-public Region () {
- this(null);
-}
-/**
- * Constructs a new empty region.
- * <p>
- * You must dispose the region when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the region
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
- * </ul>
- *
- * @see #dispose
- *
- * @since 3.0
- */
-public Region (Device device) {
- super(device);
- handle = EMPTY_REGION;
- init();
-}
-
-Region(Device device, int handle) {
- super(device);
- this.handle = handle;
-}
-
-/**
- * Adds the given polygon to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param pointArray points that describe the polygon to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
-*
- */
-public void add (int[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- // TODO
-}
-
-/**
- * Adds the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void add (Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- add (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Adds the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void add (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (handle == 0) return;
- int tile_ptr = OS.PhGetTile();
- PhTile_t tile = new PhTile_t();
- tile.rect_ul_x = (short)x;
- tile.rect_ul_y = (short)y;
- tile.rect_lr_x = (short)(x + width - 1);
- tile.rect_lr_y = (short)(y + height - 1);
- OS.memmove(tile_ptr, tile, PhTile_t.sizeof);
- if (handle == EMPTY_REGION) handle = tile_ptr;
- else handle = OS.PhAddMergeTiles (handle, tile_ptr, null);
-}
-
-/**
- * Adds all of the polygons which make up the area covered
- * by the argument to the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to merge
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void add (Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (handle == 0) return;
- if (region.handle == EMPTY_REGION) return;
- int copy = OS.PhCopyTiles(region.handle);
- if (handle == EMPTY_REGION) handle = copy;
- else handle = OS.PhAddMergeTiles (handle, copy, null);
-}
-
-/**
- * Returns <code>true</code> if the point specified by the
- * arguments is inside the area specified by the receiver,
- * and <code>false</code> otherwise.
- *
- * @param x the x coordinate of the point to test for containment
- * @param y the y coordinate of the point to test for containment
- * @return <code>true</code> if the region contains the point and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains (int x, int y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (handle == 0 || handle == EMPTY_REGION) return false;
- int tile_ptr = OS.PhGetTile();
- PhTile_t tile = new PhTile_t();
- tile.rect_ul_x = tile.rect_lr_x = (short)x;
- tile.rect_ul_y = tile.rect_lr_y = (short)y;
- OS.memmove(tile_ptr, tile, PhTile_t.sizeof);
- int intersection = OS.PhIntersectTilings (tile_ptr, handle, null);
- boolean result = intersection != 0;
- OS.PhFreeTiles(tile_ptr);
- OS.PhFreeTiles(intersection);
- return result;
-}
-
-/**
- * Returns <code>true</code> if the given point is inside the
- * area specified by the receiver, and <code>false</code>
- * otherwise.
- *
- * @param pt the point to test for containment
- * @return <code>true</code> if the region contains the point and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains (Point pt) {
- if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return contains(pt.x, pt.y);
-}
-
-void destroy() {
- if (handle != EMPTY_REGION) OS.PhFreeTiles (handle);
- handle = 0;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (this == object) return true;
- if (!(object instanceof Region)) return false;
- Region region = (Region)object;
- return handle == region.handle;
-}
-
-/**
- * Returns a rectangle which represents the rectangular
- * union of the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @return a bounding rectangle for the region
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#union
- */
-public Rectangle getBounds() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (handle == 0 || handle == EMPTY_REGION) return new Rectangle(0, 0, 0, 0);
- PhTile_t tile = new PhTile_t();
- int temp_tile;
- int rect_ptr = OS.malloc(PhRect_t.sizeof);
- OS.memmove(rect_ptr, handle, PhRect_t.sizeof);
- OS.memmove(tile, handle, PhTile_t.sizeof);
- while ((temp_tile = tile.next) != 0) {
- OS.PhRectUnion (rect_ptr, temp_tile);
- OS.memmove(tile, temp_tile, PhTile_t.sizeof);
- }
- PhRect_t rect = new PhRect_t();
- OS.memmove(rect, rect_ptr, PhRect_t.sizeof);
- OS.free(rect_ptr);
- int width = rect.lr_x - rect.ul_x + 1;
- int height = rect.lr_y - rect.ul_y + 1;
- return new Rectangle(rect.ul_x, rect.ul_y, width, height);
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return handle;
-}
-
-/**
- * Intersects the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to intersect with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void intersect (Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- intersect (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Intersects the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void intersect (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (handle == 0 || handle == EMPTY_REGION) return;
- int tile_ptr = OS.PhGetTile();
- PhTile_t tile = new PhTile_t();
- tile.rect_ul_x = (short)x;
- tile.rect_ul_y = (short)y;
- tile.rect_lr_x = (short)(x + width - 1);
- tile.rect_lr_y = (short)(y + height - 1);
- OS.memmove(tile_ptr, tile, PhTile_t.sizeof);
- int intersection = OS.PhIntersectTilings(handle, tile_ptr, null);
- OS.PhFreeTiles(tile_ptr);
- OS.PhFreeTiles(handle);
- handle = intersection;
- if (handle == 0) handle = EMPTY_REGION;
-}
-
-/**
- * Intersects all of the polygons which make up the area covered
- * by the argument to the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to intersect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void intersect (Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (handle == 0 || handle == EMPTY_REGION) return;
- int intersection = 0;
- if (region.handle != EMPTY_REGION) intersection = OS.PhIntersectTilings(handle, region.handle, null);
- OS.PhFreeTiles(handle);
- handle = intersection;
- if (handle == 0) handle = EMPTY_REGION;
-}
-
-/**
- * Returns <code>true</code> if the rectangle described by the
- * arguments intersects with any of the polygons the receiver
- * maintains to describe its area, and <code>false</code> otherwise.
- *
- * @param x the x coordinate of the origin of the rectangle
- * @param y the y coordinate of the origin of the rectangle
- * @param width the width of the rectangle
- * @param height the height of the rectangle
- * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#intersects(Rectangle)
- */
-public boolean intersects (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (handle == 0 || handle == EMPTY_REGION) return false;
- int tile_ptr = OS.PhGetTile();
- PhTile_t tile = new PhTile_t();
- tile.rect_ul_x = (short)x;
- tile.rect_ul_y = (short)y;
- tile.rect_lr_x = (short)(x + width - 1);
- tile.rect_lr_y = (short)(y + height - 1);
- OS.memmove(tile_ptr, tile, PhTile_t.sizeof);
- int intersection = OS.PhIntersectTilings (tile_ptr, handle, null);
- boolean result = intersection != 0;
- OS.PhFreeTiles(tile_ptr);
- OS.PhFreeTiles(intersection);
- return result;
-}
-
-/**
- * Returns <code>true</code> if the given rectangle intersects
- * with any of the polygons the receiver maintains to describe
- * its area and <code>false</code> otherwise.
- *
- * @param rect the rectangle to test for intersection
- * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#intersects(Rectangle)
- */
-public boolean intersects (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return intersects(rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Returns <code>true</code> if the region has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the region.
- * When a region has been disposed, it is an error to
- * invoke any other method using the region.
- *
- * @return <code>true</code> when the region is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns <code>true</code> if the receiver does not cover any
- * area in the (x, y) coordinate plane, and <code>false</code> if
- * the receiver does cover some area in the plane.
- *
- * @return <code>true</code> if the receiver is empty, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean isEmpty () {
- return getBounds().isEmpty();
-
-}
-
-public static Region photon_new(Device device, int handle) {
- return new Region(device, handle);
-}
-
-/**
- * Subtracts the given polygon from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param pointArray points that describe the polygon to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract (int[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- // TODO
-}
-
-/**
- * Subtracts the given rectangle from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to subtract from the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract (Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- subtract (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Subtracts the given rectangle from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void subtract (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (handle == 0 || handle == EMPTY_REGION) return;
- int tile_ptr = OS.PhGetTile();
- PhTile_t tile = new PhTile_t();
- tile.rect_ul_x = (short)x;
- tile.rect_ul_y = (short)y;
- tile.rect_lr_x = (short)(x + width - 1);
- tile.rect_lr_y = (short)(y + height - 1);
- OS.memmove(tile_ptr, tile, PhTile_t.sizeof);
- handle = OS.PhClipTilings(handle, tile_ptr, null);
- OS.PhFreeTiles(tile_ptr);
- if (handle == 0) handle = EMPTY_REGION;
-}
-
-/**
- * Subtracts all of the polygons which make up the area covered
- * by the argument from the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to subtract
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract (Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (handle == 0 || handle == EMPTY_REGION) return;
- if (region.handle == EMPTY_REGION) return;
- handle = OS.PhClipTilings(handle, region.handle, null);
- if (handle == 0) handle = EMPTY_REGION;
-}
-
-/**
- * Translate all of the polygons the receiver maintains to describe
- * its area by the specified point.
- *
- * @param x the x coordinate of the point to translate
- * @param y the y coordinate of the point to translate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void translate (int x, int y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (handle == 0 || handle == EMPTY_REGION) return;
- PhPoint_t pt = new PhPoint_t();
- pt.x = (short)x;
- pt.y = (short)y;
- OS.PhTranslateTiles (handle, pt);
-}
-
-/**
- * Translate all of the polygons the receiver maintains to describe
- * its area by the specified point.
- *
- * @param pt the point to translate
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void translate (Point pt) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- translate (pt.x, pt.y);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Region {*DISPOSED*}";
- return "Region {" + handle + "}";
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/internal/Converter.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/internal/Converter.java
deleted file mode 100755
index bde2826420..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/internal/Converter.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal;
-
-import java.io.UnsupportedEncodingException;
-
-
-/**
- * This class implements the conversions between unicode characters
- * and the <em>platform supported</em> representation for characters.
- * <p>
- * Note that, unicode characters which can not be found in the platform
- * encoding will be converted to an arbitrary platform specific character.
- * </p>
- */
-
-public final class Converter {
- public static final byte [] NullByteArray = new byte [1];
- public static final byte [] EmptyByteArray = new byte [0];
- public static final char [] EmptyCharArray = new char [0];
-/**
- * Returns the default code page for the platform where the
- * application is currently running.
- *
- * @return the default code page
- */
-public static String defaultCodePage () {
- return "UTF8";
-}
-public static char [] mbcsToWcs (String codePage, byte [] buffer) {
- try {
- return new String (buffer, defaultCodePage ()).toCharArray ();
- } catch (UnsupportedEncodingException e) {
- return EmptyCharArray;
- }
-}
-public static byte [] wcsToMbcs (String codePage, String string, boolean terminate) {
- try {
- if (!terminate) return string.getBytes (defaultCodePage ());
- byte [] buffer1 = string.getBytes (defaultCodePage ());
- byte [] buffer2 = new byte [buffer1.length + 1];
- System.arraycopy (buffer1, 0, buffer2, 0, buffer1.length);
- return buffer2;
- } catch (UnsupportedEncodingException e) {
- return terminate ? NullByteArray : EmptyByteArray;
- }
-}
-public static byte [] wcsToMbcs (String codePage, char [] buffer, boolean terminate) {
- try {
- if (!terminate) return new String (buffer).getBytes (defaultCodePage ());
- byte [] buffer1 = new String (buffer).getBytes (defaultCodePage ());
- byte [] buffer2 = new byte [buffer1.length + 1];
- System.arraycopy (buffer1, 0, buffer2, 0, buffer1.length);
- return buffer2;
- } catch (UnsupportedEncodingException e) {
- return terminate ? NullByteArray : EmptyByteArray;
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Button.java
deleted file mode 100755
index 291029074d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Button.java
+++ /dev/null
@@ -1,662 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface object that
- * issues notification when pressed and released.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>ARROW, CHECK, PUSH, RADIO, TOGGLE, FLAT</dd>
- * <dd>UP, DOWN, LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles ARROW, CHECK, PUSH, RADIO, and TOGGLE
- * may be specified.
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT, and CENTER may be specified.
- * </p><p>
- * Note: Only one of the styles UP, DOWN, LEFT, and RIGHT may be specified
- * when the ARROW style is specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#button">Button snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Button extends Control {
- String text = "";
- Image image;
- boolean grayed;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#ARROW
- * @see SWT#CHECK
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#TOGGLE
- * @see SWT#FLAT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Button (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- style = checkBits (style, SWT.PUSH, SWT.ARROW, SWT.CHECK, SWT.RADIO, SWT.TOGGLE, 0);
- if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) {
- return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0);
- }
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0);
- }
- if ((style & SWT.ARROW) != 0) {
- style |= SWT.NO_FOCUS;
- return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0);
- }
- return style;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected by the user.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-void click () {
- click (handle);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- if ((style & SWT.ARROW) != 0) {
- if (wHint != SWT.DEFAULT) width += wHint;
- else width = 17;
- if (hHint != SWT.DEFAULT) height += hHint;
- else height = 17;
- return new Point (width, height);
- }
- PhDim_t dim = new PhDim_t();
- if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidget (handle);
- OS.PtWidgetPreferredSize(handle, dim);
- width = dim.w; height = dim.h;
- if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) {
- int [] args = {
- OS.Pt_ARG_MARGIN_LEFT, 0, 0, // 1
- OS.Pt_ARG_MARGIN_RIGHT, 0, 0, // 4
- OS.Pt_ARG_MARGIN_TOP, 0, 0, // 7
- OS.Pt_ARG_MARGIN_BOTTOM, 0, 0, // 10
-// OS.Pt_ARG_MARGIN_WIDTH, 0, 0, // 13
-// OS.Pt_ARG_MARGIN_HEIGHT, 0, 0, // 16
- };
- OS.PtGetResources (handle, args.length / 3, args);
- PhArea_t area = new PhArea_t ();
- area.size_w = (short) wHint;
- area.size_h = (short) hHint;
-
- /*
- * This code is intentionally commented. Bug compatible with Windows.
- */
-// PhRect_t rect = new PhRect_t ();
-// rect.lr_x = (short) (wHint - 1);
-// rect.lr_y = (short) (hHint - 1);
-// OS.PtSetAreaFromWidgetCanvas (handle, rect, area);
- if (wHint != SWT.DEFAULT) {
- width = area.size_w + /*(args [13] * 2)*/ + args [1] + args [4];
- }
- if (hHint != SWT.DEFAULT) {
- height = area.size_h + /*(args [16] * 2)*/ + args [7] + args [10];
- }
- }
- return new Point (width, height);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- int parentHandle = parent.parentingHandle ();
-
- /* ARROW button */
- if ((style & SWT.ARROW) != 0) {
- int [] args = {
- OS.Pt_ARG_FLAGS, 0, OS.Pt_GETS_FOCUS,
- OS.Pt_ARG_BASIC_FLAGS, OS.Pt_HORIZONTAL_GRADIENT, OS.Pt_STATIC_GRADIENT | OS.Pt_HORIZONTAL_GRADIENT,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (display.PtButton, parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- return;
- }
-
- /* Compute alignment */
- int alignment = OS.Pt_LEFT;
- if ((style & SWT.CENTER) != 0) alignment = OS.Pt_CENTER;
- if ((style & SWT.RIGHT) != 0) alignment = OS.Pt_RIGHT;
-
- /* CHECK or RADIO button */
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- int [] args = {
- OS.Pt_ARG_HORIZONTAL_ALIGNMENT, alignment, 0,
- OS.Pt_ARG_INDICATOR_TYPE, (style & SWT.CHECK) != 0 ? OS.Pt_N_OF_MANY : OS.Pt_ONE_OF_MANY, 0,
- OS.Pt_ARG_FILL_COLOR, display.WIDGET_BACKGROUND, 0,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
-
- handle = OS.PtCreateWidget (display.PtToggleButton, parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- return;
- }
-
- /* PUSH or TOGGLE button */
- int [] args = {
- OS.Pt_ARG_FLAGS, (style & SWT.TOGGLE) != 0 ? OS.Pt_TOGGLE : 0, OS.Pt_TOGGLE,
- OS.Pt_ARG_HORIZONTAL_ALIGNMENT, alignment, 0,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (display.PtButton, parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-
-void drawWidget (int widget, int damage) {
- super.drawWidget (widget, damage);
- if ((style & SWT.ARROW) != 0) {
- PhRect_t rect = new PhRect_t ();
- OS.PtCalcCanvas (handle, rect);
- int flags = 0;
- if ((style & SWT.RIGHT) != 0) flags = 2;
- if ((style & SWT.LEFT) != 0) flags = 1;
- if ((style & SWT.DOWN) != 0) flags = 8;
- if ((style & SWT.UP) != 0) flags = 4;
- OS.PgDrawArrow (rect, (short)0, 0x000000, flags);
- }
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is an <code>ARROW</code> button, in
- * which case, the alignment will indicate the direction of
- * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>,
- * <code>UP</code> or <code>DOWN</code>).
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget();
- if ((style & SWT.ARROW) != 0) {
- if ((style & SWT.UP) != 0) return SWT.UP;
- if ((style & SWT.DOWN) != 0) return SWT.DOWN;
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.UP;
- }
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-boolean getDefault () {
- if ((style & SWT.PUSH) == 0) return false;
- int [] args = {OS.Pt_ARG_BEVEL_CONTRAST, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1] == 100;
-}
-
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the widget does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getGrayed () {
- checkWidget();
- if ((style & SWT.CHECK) == 0) return false;
- return grayed;
-}
-
-/**
- * Returns the receiver's image if it has one, or null
- * if it does not.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked. When it is of type <code>TOGGLE</code>,
- * it is selected when it is pushed in. If the receiver is of any other type,
- * this method returns false.
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false;
- return (OS.PtWidgetFlags (handle) & OS.Pt_SET) != 0;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set or if the receiver is
- * an <code>ARROW</code> button.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- if ((style & SWT.ARROW) != 0) return "";
- return text;
-}
-
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- OS.PtAddCallback (handle, OS.Pt_CB_ACTIVATE, windowProc, OS.Pt_CB_ACTIVATE);
-}
-
-int hotkeyProc (int widget, int data, int info) {
- if (setFocus ()) click ();
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_ACTIVATE (int widget, int info) {
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) {
- selectRadio ();
- }
- }
- postEvent (SWT.Selection);
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_GOT_FOCUS (int widget, int info) {
- int result = super.Pt_CB_GOT_FOCUS (widget, info);
- // widget could be disposed at this point
- if (handle == 0) return result;
- if ((style & SWT.PUSH) == 0) return result;
- getShell ().setDefaultButton (this, false);
- return result;
-}
-
-int Pt_CB_LOST_FOCUS (int widget, int info) {
- int result = super.Pt_CB_LOST_FOCUS (widget, info);
- // widget could be disposed at this point
- if (handle == 0) return result;
- if ((style & SWT.PUSH) == 0) return result;
- if (getDefault ()) {
- getShell ().setDefaultButton (null, false);
- }
- return result;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- image = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-void selectRadio () {
- /*
- * This code is intentionally commented. When two groups
- * of radio buttons with the same parent are separated by
- * another control, the correct behavior should be that
- * the two groups act independently. This is consistent
- * with radio tool and menu items. The commented code
- * implements this behavior.
- */
-// int index = 0;
-// Control [] children = parent._getChildren ();
-// while (index < children.length && children [index] != this) index++;
-// int i = index - 1;
-// while (i >= 0 && children [i].setRadioSelection (false)) --i;
-// int j = index + 1;
-// while (j < children.length && children [j].setRadioSelection (false)) j++;
-// setSelection (true);
- Control [] children = parent._getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (this != child) child.setRadioSelection (false);
- }
- setSelection (true);
-}
-
-/**
- * Controls how text, images and arrows will be displayed
- * in the receiver. The argument should be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is an <code>ARROW</code> button, in
- * which case, the argument indicates the direction of
- * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>,
- * <code>UP</code> or <code>DOWN</code>).
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget();
- if ((style & SWT.ARROW) != 0) {
- if ((style & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT)) == 0) return;
- style &= ~(SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT);
- style |= alignment & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT);
- OS.PtDamageWidget (handle);
- return;
- }
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- int align = OS.Pt_LEFT;
- if ((style & SWT.CENTER) != 0) align = OS.Pt_CENTER;
- if ((style & SWT.RIGHT) != 0) align = OS.Pt_RIGHT;
- OS.PtSetResource (handle, OS.Pt_ARG_HORIZONTAL_ALIGNMENT, align, 0);
-}
-
-void setDefault (boolean value) {
- if ((style & SWT.PUSH) == 0) return;
- if (getShell ().parent == null) return;
- OS.PtSetResource (handle, OS.Pt_ARG_BEVEL_CONTRAST, value ? 100 : 20, 0);
-}
-
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-
-/**
- * Sets the selection state of the receiver, if it is of type <code>CHECK</code>,
- * <code>RADIO</code>, or <code>TOGGLE</code>.
- *
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked. When it is of type <code>TOGGLE</code>,
- * it is selected when it is pushed in.
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return;
- OS.PtSetResource (handle, OS.Pt_ARG_FLAGS, selected ? OS.Pt_SET : 0, OS.Pt_SET);
-}
-
-/**
- * Sets the grayed state of the receiver. This state change
- * only applies if the control was created with the SWT.CHECK
- * style.
- *
- * @param grayed the new grayed state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setGrayed (boolean grayed) {
- checkWidget ();
- if ((style & SWT.CHECK) == 0) return;
- this.grayed = grayed;
-}
-
-/**
- * Sets the receiver's image to the argument, which may be
- * <code>null</code> indicating that no image should be displayed.
- * <p>
- * Note that a Button can display an image and text simultaneously
- * on Windows (starting with XP), GTK+ and OSX. On other platforms,
- * a Button that has an image and text set into it will display the
- * image or text that was set most recently.
- * </p>
- * @param image the image to display on the receiver (may be <code>null</code>)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if ((style & SWT.ARROW) != 0) return;
- this.image = image;
- int imageHandle = 0;
- if (image != null) {
- if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- imageHandle = copyPhImage (image.handle);
- }
- int [] args = {
- OS.Pt_ARG_LABEL_IMAGE, imageHandle, 0,
- OS.Pt_ARG_LABEL_TYPE, OS.Pt_IMAGE, 0
- };
- OS.PtSetResources (handle, args.length / 3, args);
- if (imageHandle != 0) OS.free (imageHandle);
-}
-
-/**
- * Sets the receiver's text.
- * <p>
- * This method sets the button label. The label may include
- * the mnemonic character but must not contain line delimiters.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasized in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p><p>
- * Note that a Button can display an image and text simultaneously
- * on Windows (starting with XP), GTK+ and OSX. On other platforms,
- * a Button that has an image and text set into it will display the
- * image or text that was set most recently.
- * </p>
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.ARROW) != 0) return;
- text = string;
- char [] text = new char [string.length ()];
- string.getChars (0, text.length, text, 0);
- char mnemonic = fixMnemonic (text);
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- int ptr1 = OS.malloc (buffer.length);
- OS.memmove (ptr1, buffer, buffer.length);
- int ptr2 = 0;
- if (mnemonic != 0) {
- byte [] buffer2 = Converter.wcsToMbcs (null, new char []{mnemonic}, true);
- ptr2 = OS.malloc (buffer2.length);
- OS.memmove (ptr2, buffer2, buffer2.length);
- }
- replaceMnemonic (mnemonic, true, true);
- int [] args = {
- OS.Pt_ARG_TEXT_STRING, ptr1, 0,
- OS.Pt_ARG_LABEL_TYPE, OS.Pt_Z_STRING, 0,
- OS.Pt_ARG_ACCEL_KEY, ptr2, 0,
- };
- OS.PtSetResources (handle, args.length / 3, args);
- OS.free (ptr1);
- OS.free (ptr2);
-}
-
-int traversalCode (int key_sym, PhKeyEvent_t ke) {
- int code = super.traversalCode (key_sym, ke);
- if ((style & SWT.RADIO) != 0) code |= SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS;
- return code;
-}
-
-int widgetClass () {
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) return OS.PtToggleButton ();
- return OS.PtButton ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Canvas.java
deleted file mode 100755
index acd420000a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Canvas.java
+++ /dev/null
@@ -1,310 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide a surface for drawing
- * arbitrary graphics.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * This class may be subclassed by custom control implementors
- * who are building controls that are <em>not</em> constructed
- * from aggregates of other controls. That is, they are either
- * painted using SWT graphics calls or are handled by native
- * methods.
- * </p>
- *
- * @see Composite
- * @see <a href="http://www.eclipse.org/swt/snippets/#canvas">Canvas snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class Canvas extends Composite {
- Caret caret;
- IME ime;
-
-Canvas () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Canvas (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Returns the caret.
- * <p>
- * The caret for the control is automatically hidden
- * and shown when the control is painted or resized,
- * when focus is gained or lost and when an the control
- * is scrolled. To avoid drawing on top of the caret,
- * the programmer must hide and show the caret when
- * drawing in the window any other time.
- * </p>
- *
- * @return the caret for the receiver, may be null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Caret getCaret () {
- checkWidget();
- return caret;
-}
-
-/**
- * Returns the IME.
- *
- * @return the IME
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public IME getIME () {
- checkWidget ();
- return ime;
-}
-
-int Pt_CB_GOT_FOCUS (int widget, int info) {
- int result = super.Pt_CB_GOT_FOCUS (widget, info);
- if (caret != null) caret.setFocus ();
- return result;
-}
-
-int Pt_CB_LOST_FOCUS (int widget, int info) {
- int result = super.Pt_CB_LOST_FOCUS (widget, info);
- if (caret != null) caret.killFocus ();
- return result;
-}
-
-/**
- * Fills the interior of the rectangle specified by the arguments,
- * with the receiver's background.
- *
- * @param gc the gc where the rectangle is to be filled
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void drawBackground (GC gc, int x, int y, int width, int height) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- super.drawBackground (gc, x, y, width, height);
-}
-
-int drawProc (int widget, int damage) {
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- int result = super.drawProc (widget, damage);
- if (isFocus) caret.setFocus ();
- return result;
-}
-
-public void redraw () {
- checkWidget();
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- super.redraw ();
- if (isFocus) caret.setFocus ();
-}
-
-public void redraw (int x, int y, int width, int height, boolean all) {
- checkWidget();
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- super.redraw (x, y, width, height, all);
- if (isFocus) caret.setFocus ();
-}
-
-void releaseChildren (boolean destroy) {
- if (caret != null) {
- caret.release (false);
- caret = null;
- }
- if (ime != null) {
- ime.release (false);
- ime = null;
- }
- super.releaseChildren (destroy);
-}
-
-/**
- * Scrolls a rectangular area of the receiver by first copying
- * the source area to the destination and then causing the area
- * of the source which is not covered by the destination to
- * be repainted. Children that intersect the rectangle are
- * optionally moved during the operation. In addition, outstanding
- * paint events are flushed before the source area is copied to
- * ensure that the contents of the canvas are drawn correctly.
- *
- * @param destX the x coordinate of the destination
- * @param destY the y coordinate of the destination
- * @param x the x coordinate of the source
- * @param y the y coordinate of the source
- * @param width the width of the area
- * @param height the height of the area
- * @param all <code>true</code>if children should be scrolled, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) {
- checkWidget();
- if (width <= 0 || height <= 0) return;
- int deltaX = destX - x, deltaY = destY - y;
- if (deltaX == 0 && deltaY == 0) return;
- if (!isVisible ()) return;
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- GC gc = new GC (this);
- gc.copyArea (x, y, width, height, destX, destY);
- gc.dispose ();
- if (all) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- Rectangle rect = child.getBounds ();
- if (Math.min(x + width, rect.x + rect.width) >= Math.max (x, rect.x) &&
- Math.min(y + height, rect.y + rect.height) >= Math.max (y, rect.y)) {
- child.setLocation (rect.x + deltaX, rect.y + deltaY);
- }
- }
- }
- if (isFocus) caret.setFocus ();
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- checkWidget();
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- int result = super.setBounds (x, y, width, height, move, resize, events);
- if (isFocus) caret.setFocus ();
- return result;
-}
-
-/**
- * Sets the receiver's caret.
- * <p>
- * The caret for the control is automatically hidden
- * and shown when the control is painted or resized,
- * when focus is gained or lost and when an the control
- * is scrolled. To avoid drawing on top of the caret,
- * the programmer must hide and show the caret when
- * drawing in the window any other time.
- * </p>
- * @param caret the new caret for the receiver, may be null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the caret has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCaret (Caret caret) {
- checkWidget();
- Caret newCaret = caret;
- Caret oldCaret = this.caret;
- this.caret = newCaret;
- if (isFocusControl ()) {
- if (oldCaret != null) oldCaret.killFocus ();
- if (newCaret != null) {
- if (newCaret.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- newCaret.setFocus ();
- }
- }
-}
-
-public void setFont (Font font) {
- checkWidget();
- if (caret != null) caret.setFont (font);
- super.setFont (font);
-}
-
-/**
- * Sets the receiver's IME.
- *
- * @param ime the new IME for the receiver, may be null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the IME has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setIME (IME ime) {
- checkWidget ();
- if (ime != null && ime.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- this.ime = ime;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Caret.java
deleted file mode 100755
index dae8448165..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Caret.java
+++ /dev/null
@@ -1,515 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide an i-beam that is typically used
- * as the insertion point for text.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#caret">Caret snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Canvas tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Caret extends Widget {
- Canvas parent;
- int x, y, width, height;
- boolean isVisible, isShowing;
- int blinkRate = 0;
- Image image;
- Font font;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-// int blinkRate = 500;
-
-public Caret (Canvas parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget (0);
-}
-
-boolean blinkCaret () {
- if (!isVisible) return true;
- if (!isShowing) return showCaret ();
- if (blinkRate == 0) return true;
- return hideCaret ();
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- isVisible = true;
- if (parent.getCaret () == null) {
- parent.setCaret (this);
- }
-}
-
-boolean drawCaret () {
- if (parent == null) return false;
- if (parent.isDisposed ()) return false;
- int handle = parent.handle;
- if (!OS.PtWidgetIsRealized (handle)) return false;
- int phGC = OS.PgCreateGC (0); // NOTE: PgCreateGC ignores the parameter
- if (phGC == 0) return false;
- int prevContext = OS.PgSetGC (phGC);
- PhPoint_t pt = new PhPoint_t ();
- PhRect_t tran_rect = new PhRect_t();
- int disjoint = OS.PtFindDisjoint( handle );
- if( disjoint != 0 )
- OS.PgSetRegion( OS.PtWidgetRid( disjoint ) );
- OS.PtWidgetExtent(handle, tran_rect) ;
- OS.PtWidgetOffset(handle, pt);
- pt.x += tran_rect.ul_x;
- pt.y += tran_rect.ul_y;
- OS.PgSetTranslation(pt,0);
- int clip = OS.PtGetVisibleTiles(handle);
- if ( clip > 0 )
- OS.PgSetMultiClipTiles(clip);
- OS.PgSetDrawMode (OS.Pg_DrawModeDSx);
- OS.PgSetFillColor (0xFFFFFF);
- int nWidth = width, nHeight = height;
- if (image != null) {
- Rectangle rect = image.getBounds ();
- nWidth = rect.width;
- nHeight = rect.height;
- }
- if (nWidth <= 0) nWidth = 2;
- OS.PgDrawIRect (x, y, x + nWidth - 1, y + nHeight - 1, OS.Pg_DRAW_FILL);
- OS.PgSetGC (prevContext);
- OS.PgDestroyGC (phGC);
- OS.PhFreeTiles(clip);
- return true;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null).
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- if (image != null) {
- Rectangle rect = image.getBounds ();
- return new Rectangle (x, y, rect.width, rect.height);
- }
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Font getFont () {
- checkWidget();
- if (font != null) return font;
- return parent.getFont ();
-}
-
-/**
- * Returns the image that the receiver will use to paint the caret.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null).
- *
- * @return the receiver's location
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getLocation () {
- checkWidget();
- return new Point (x, y);
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Canvas</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Canvas getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns a point describing the receiver's size.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- if (image != null) {
- Rectangle rect = image.getBounds ();
- return new Point (rect.width, rect.height);
- }
- return new Point (width, height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- return isVisible;
-}
-
-boolean hideCaret () {
- if (!isShowing) return true;
- isShowing = false;
- return drawCaret ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return isVisible && parent.isVisible () && parent.hasFocus ();
-}
-
-boolean isFocusCaret () {
-// Display display = getDisplay ();
-// return this == display.currentCaret;
- return parent.hasFocus ();
-}
-
-void killFocus () {
-// Display display = getDisplay ();
-// if (display.currentCaret != this) return;
-// display.setCurrentCaret (null);
- if (isVisible) hideCaret ();
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (this == parent.getCaret ()) parent.setCaret (null);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
-// Display display = getDisplay ();
-// if (display.currentCaret == this) {
- hideCaret ();
-// display.setCurrentCaret (null);
-// }
- parent = null;
- image = null;
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the arguments. The <code>x</code> and
- * <code>y</code> arguments are relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (int x, int y, int width, int height) {
- checkWidget();
- if (this.x == x && this.y == y && this.width == width && this.height == height) return;
- boolean isFocus = isFocusCaret ();
- if (isFocus && isVisible) hideCaret ();
- this.x = x; this.y = y;
- this.width = width; this.height = height;
- if (isFocus && isVisible) showCaret ();
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the argument. The <code>x</code> and
- * <code>y</code> fields of the rectangle are relative to
- * the receiver's parent (or its display if its parent is null).
- *
- * @param rect the new bounds for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (Rectangle rect) {
- checkWidget();
- if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (rect.x, rect.y, rect.width, rect.height);
-}
-
-void setFocus () {
-// Display display = getDisplay ();
-// if (display.currentCaret == this) return;
-// display.setCurrentCaret (this);
- if (isVisible) showCaret ();
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * to the font specified by the argument, or to the default font for that
- * kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkWidget();
- if (font != null && font.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.font = font;
-}
-
-/**
- * Sets the image that the receiver will use to paint the caret
- * to the image specified by the argument, or to the default
- * which is a filled rectangle if the argument is null
- *
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- boolean isFocus = isFocusCaret ();
- if (isFocus && isVisible) hideCaret ();
- this.image = image;
- if (isFocus && isVisible) showCaret ();
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget();
- setBounds (x, y, width, height);
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the argument which is relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param location the new location for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (Point location) {
- checkWidget();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-/**
- * Sets the receiver's size to the point specified by the arguments.
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (int width, int height) {
- checkWidget();
- setBounds (x, y, width, height);
-}
-
-/**
- * Sets the receiver's size to the point specified by the argument.
- *
- * @param size the new extent for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (Point size) {
- checkWidget();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSize (size.x, size.y);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget();
- if (visible == isVisible) return;
- isVisible = visible;
- if (!isFocusCaret ()) return;
- if (isVisible) {
- showCaret ();
- } else {
- hideCaret ();
- }
-}
-
-boolean showCaret () {
- if (isShowing) return true;
- isShowing = true;
- return drawCaret ();
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ColorDialog.java
deleted file mode 100755
index 225a5743a6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ColorDialog.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class allow the user to select a color
- * from a predefined set of available colors.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ColorDialog extends Dialog {
- RGB rgb;
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a composite control which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ColorDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ColorDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-/**
- * Returns the currently selected color in the receiver.
- *
- * @return the RGB value for the selected color, may be null
- *
- * @see PaletteData#getRGBs
- */
-public RGB getRGB () {
- return rgb;
-}
-
-/**
- * Makes the receiver visible and brings it to the front
- * of the display.
- *
- * @return the selected color, or null if the dialog was
- * cancelled, no color was selected, or an error
- * occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public RGB open () {
- int parentHandle = 0;
- if (parent != null && OS.PtWidgetIsRealized(parent.shellHandle)) {
- parentHandle = parent.shellHandle;
- }
- byte[] title = null;
- if (this.title != null) title = Converter.wcsToMbcs (null, this.title, true);
- PtColorSelectInfo_t info = new PtColorSelectInfo_t();
- info.flags = (short) OS.Pt_COLORSELECT_MODAL;
- if (rgb != null) info.rgb = (rgb. blue & 0xFF) | ((rgb.green & 0xFF) << 8) | ((rgb.red & 0xFF) << 16);
- rgb = null;
-
- OS.PtColorSelect(parentHandle, title, info);
-
- if ((info.flags & OS.Pt_COLORSELECT_ACCEPT) != 0) {
- int color = info.rgb;
- rgb = new RGB ((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, color & 0xFF);
- }
- return rgb;
-}
-
-/**
- * Sets the receiver's selected color to be the argument.
- *
- * @param rgb the new RGB value for the selected color, may be
- * null to let the platform select a default when
- * open() is called
- * @see PaletteData#getRGBs
- */
-public void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Combo.java
deleted file mode 100755
index 8fc948adb5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Combo.java
+++ /dev/null
@@ -1,1400 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are controls that allow the user
- * to choose an item from a list of items, or optionally
- * enter a new value by typing it into an editable text
- * field. Often, <code>Combo</code>s are used in the same place
- * where a single selection <code>List</code> widget could
- * be used but space is limited. A <code>Combo</code> takes
- * less space than a <code>List</code> widget and shows
- * similar information.
- * <p>
- * Note: Since <code>Combo</code>s can contain both a list
- * and an editable text field, it is possible to confuse methods
- * which access one versus the other (compare for example,
- * <code>clearSelection()</code> and <code>deselectAll()</code>).
- * The API documentation is careful to indicate either "the
- * receiver's list" or the "the receiver's text field" to
- * distinguish between the two cases.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>DROP_DOWN, READ_ONLY, SIMPLE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Modify, Selection, Verify</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles DROP_DOWN and SIMPLE may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see List
- * @see <a href="http://www.eclipse.org/swt/snippets/#combo">Combo snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Combo extends Composite {
- /**
- * the operating system limit for the number of characters
- * that the text field in an instance of this class can hold
- */
- public static final int LIMIT;
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0x7FFFFFFF;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see SWT#READ_ONLY
- * @see SWT#SIMPLE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Combo (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- /*
- * Feature in Windows. It is not possible to create
- * a combo box that has a border using Windows style
- * bits. All combo boxes draw their own border and
- * do not use the standard Windows border styles.
- * Therefore, no matter what style bits are specified,
- * clear the BORDER bits so that the SWT style will
- * match the Windows widget.
- *
- * The Windows behavior is currently implemented on
- * all platforms.
- */
- style &= ~SWT.BORDER;
-
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- style &= ~(SWT.H_SCROLL | SWT.V_SCROLL);
- style = checkBits (style, SWT.DROP_DOWN, SWT.SIMPLE, 0, 0, 0, 0);
- if ((style & SWT.SIMPLE) != 0) return style & ~SWT.READ_ONLY;
- return style;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- //NOT DONE: this only works with a DROP_DOWN combo
- if ((style & SWT.SIMPLE) != 0) return new Point(100, 100);
- PhDim_t dim = new PhDim_t();
- if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidgetFamily (handle);
- OS.PtWidgetPreferredSize(handle, dim);
- int width = dim.w;
- int height = dim.h;
- int textWidget = OS.PtWidgetChildBack(handle);
- OS.PtWidgetPreferredSize(textWidget, dim);
- height += dim.h;
- PhRect_t rect = new PhRect_t ();
- PhArea_t area = new PhArea_t ();
- OS.PtSetAreaFromWidgetCanvas (textWidget, rect, area);
- width += area.size_w;
-
- /* Calculate maximum text width */
- int [] args = new int [] {
- OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0, // 1
- OS.Pt_ARG_ITEMS, 0, 0, // 4
- OS.Pt_ARG_TEXT_FONT, 0, 0, // 7
- OS.Pt_ARG_TEXT_STRING, 0, 0, // 10
- };
- OS.PtGetResources (handle, args.length / 3, args);
- int maxWidth = 0;
- rect = new PhRect_t();
- int str = args [10];
- int font = args [7];
- if (str != 0) {
- int length = OS.strlen (str);
- if (length > 0) {
- OS.PfExtentText(rect, null, font, str, length);
- maxWidth = Math.max(maxWidth, rect.lr_x - rect.ul_x + 1);
- }
- }
- int count = args [1];
- int [] buffer = new int [1];
- for (int i = 0; i < count; i++) {
- OS.memmove (buffer, args [4] + (i * 4), 4);
- str = buffer [0];
- int length = OS.strlen (str);
- if (length > 0) {
- OS.PfExtentText(rect, null, font, str, length);
- maxWidth = Math.max(maxWidth, rect.lr_x - rect.ul_x + 1);
- }
- }
- if (maxWidth == 0) maxWidth = DEFAULT_WIDTH;
- int [] args1 = new int [] {
- OS.Pt_ARG_MARGIN_WIDTH, 0, 0, // 1
- OS.Pt_ARG_MARGIN_LEFT, 0, 0, // 4
- OS.Pt_ARG_MARGIN_RIGHT, 0, 0, // 7
- };
- OS.PtGetResources (textWidget, args1.length / 3, args1);
- maxWidth += args1 [1] + args1 [4] + args1 [7];
-
- width += maxWidth;
-
- if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) {
- rect = new PhRect_t ();
- area = new PhArea_t ();
- rect.lr_x = (short) (wHint - 1);
- rect.lr_y = (short) (hHint - 1);
- OS.PtSetAreaFromWidgetCanvas (handle, rect, area);
- if (wHint != SWT.DEFAULT) width = area.size_w;
- if (hHint != SWT.DEFAULT) height = area.size_h;
- }
- return new Point(width, height);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- int clazz = display.PtComboBox;
- int parentHandle = parent.parentingHandle ();
- int textFlags = (style & SWT.READ_ONLY) != 0 ? 0 : OS.Pt_EDITABLE;
- int [] args = {
- OS.Pt_ARG_TEXT_FLAGS, textFlags, OS.Pt_EDITABLE,
- OS.Pt_ARG_CBOX_MAX_VISIBLE_COUNT, 5, 0,
- OS.Pt_ARG_CBOX_FLAGS, (style & SWT.SIMPLE) != 0 ? OS.Pt_COMBOBOX_STATIC: 0, OS.Pt_COMBOBOX_STATIC,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (clazz, parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-
-/**
- * Deselects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget();
- int [] args = new int [] {OS.Pt_ARG_CBOX_SELECTION_ITEM, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- if (args [1] == index) {
- args = new int [] {
- OS.Pt_ARG_TEXT_STRING, 0, 0,
- OS.Pt_ARG_CBOX_SELECTION_ITEM, 0, 0
- };
- OS.PtSetResources (handle, args.length / 3, args);
- }
-}
-
-/**
- * Deselects all selected items in the receiver's list.
- * <p>
- * Note: To clear the selection in the receiver's text field,
- * use <code>clearSelection()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #clearSelection
- */
-public void deselectAll () {
- checkWidget();
- int [] args = new int [] {
- OS.Pt_ARG_TEXT_STRING, 0, 0,
- OS.Pt_ARG_CBOX_SELECTION_ITEM, 0, 0
- };
- OS.PtSetResources (handle, args.length / 3, args);
-}
-
-/**
- * Adds the argument to the end of the receiver's list.
- *
- * @param string the new item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String,int)
- */
-public void add (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- int ptr = OS.malloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- OS.PtListAddItems (handle, new int [] {ptr}, 1, 0);
- OS.free (ptr);
-}
-
-/**
- * Adds the argument to the receiver's list at the given
- * zero-relative index.
- * <p>
- * Note: To add an item at the end of the list, use the
- * result of calling <code>getItemCount()</code> as the
- * index or use <code>add(String)</code>.
- * </p>
- *
- * @param string the new item
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String)
- */
-public void add (String string, int index) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (index == -1) error (SWT.ERROR_INVALID_RANGE);
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- int ptr = OS.malloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- int result = OS.PtListAddItems (handle, new int [] {ptr}, 1, index + 1);
- OS.free (ptr);
- if (result != 0) {
- int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- if (0 <= index && index <= args [1]) error (SWT.ERROR_ITEM_NOT_ADDED);
- error (SWT.ERROR_INVALID_RANGE);
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the combo's list selection.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed the combo's text area.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- *
- * @since 3.1
- */
-public void addVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Sets the selection in the receiver's text field to an empty
- * selection starting just before the first character. If the
- * text field is editable, this has the effect of placing the
- * i-beam at the start of the text.
- * <p>
- * Note: To clear the selected items in the receiver's list,
- * use <code>deselectAll()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #deselectAll
- */
-public void clearSelection () {
- checkWidget();
- OS.PtTextSetSelection (handle, new int [] {0}, new int [] {0});
-}
-
-
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void copy () {
- checkWidget();
- int [] start = new int [1], end = new int [1];
- int length = OS.PtTextGetSelection (handle, start, end);
- if (length <= 0) return;
- int [] args = {OS.Pt_ARG_TEXT_STRING, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- byte[] buffer = new byte[length + 1];
- OS.memmove (buffer, args [1] + start [0], length);
- int ig = OS.PhInputGroup (0);
- OS.PhClipboardCopyString((short)ig, buffer);
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void cut () {
- checkWidget();
- int [] start = new int [1], end = new int [1];
- int length = OS.PtTextGetSelection (handle, start, end);
- if (length <= 0) return;
- int [] args = {OS.Pt_ARG_TEXT_STRING, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- byte[] buffer = new byte[length + 1];
- OS.memmove (buffer, args [1] + start [0], length);
- int ig = OS.PhInputGroup (0);
- OS.PhClipboardCopyString((short)ig, buffer);
- buffer = new byte[0];
- OS.PtTextModifyText (handle, start [0], end [0], start [0], buffer, buffer.length);
-}
-
-byte [] defaultFont () {
- return display.TEXT_FONT;
-}
-
-void deregister () {
- super.deregister ();
- int child = OS.PtWidgetChildBack (handle);
- WidgetTable.remove (child);
-}
-
-int focusHandle () {
-
- /*
- * Fetuare in Photon. The combo box does not receive
- * Pt_CB_GOT_FOCUS and Pt_CB_LOST_FOCUS callbacks itself.
- * Only the internal PtText receives them. The fix is to
- * add these callbacks in the internal PtText.
- */
- return OS.PtWidgetChildBack (handle);
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver's list. Throws an exception if the index is out
- * of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getItem (int index) {
- checkWidget();
- int [] args = new int [] {
- OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0,
- OS.Pt_ARG_ITEMS, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- if (!(0 <= index && index < args [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int [] items = new int [1];
- OS.memmove (items, args [4] + (index * 4), 4);
- int length = OS.strlen (items [0]);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, items [0], length);
- char [] unicode = Converter.mbcsToWcs (null, buffer);
- return new String (unicode);
-}
-
-/**
- * Returns the number of items contained in the receiver's list.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the receiver's list.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget();
- //NOT DONE - NOT NEEDED
- return 0;
-}
-
-/**
- * Returns a (possibly empty) array of <code>String</code>s which are
- * the items in the receiver's list.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver's list
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getItems () {
- checkWidget();
- int [] args = new int [] {
- OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0,
- OS.Pt_ARG_ITEMS, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- int [] items = new int [args [1]];
- OS.memmove (items, args [4], args [1] * 4);
- String [] result = new String [args [1]];
- for (int i=0; i<args [1]; i++) {
- int length = OS.strlen (items [i]);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, items [i], length);
- char [] unicode = Converter.mbcsToWcs (null, buffer);
- result [i] = new String (unicode);
- }
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver's list is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's list's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getListVisible () {
- checkWidget ();
- return false;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the orientation of the receiver.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getOrientation () {
- checkWidget();
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-/**
- * Returns a <code>Point</code> whose x coordinate is the
- * character position representing the start of the selection
- * in the receiver's text field, and whose y coordinate is the
- * character position representing the end of the selection.
- * An "empty" selection is indicated by the x and y coordinates
- * having the same value.
- * <p>
- * Indexing is zero based. The range of a selection is from
- * 0..N where N is the number of characters in the widget.
- * </p>
- *
- * @return a point representing the selection start and end
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSelection () {
- checkWidget();
- if (((style & SWT.DROP_DOWN) != 0) && ((style & SWT.READ_ONLY) != 0)) {
- int [] args = {OS.Pt_ARG_TEXT_STRING, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- int length = 0;
- if (args [1] != 0) length = OS.strlen (args [1]);
- return new Point (0, length);
- }
-// if (textVerify != null) {
-// return new Point (textVerify.start_pos, textVerify.end_pos);
-// }
- int [] start = new int [1], end = new int [1];
- OS.PtTextGetSelection (handle, start, end);
- if (start [0] == -1) {
- int [] args = {OS.Pt_ARG_CURSOR_POSITION, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- start [0] = end [0] = args [1];
- }
- return new Point (start [0], end [0]);
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver's list, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget();
- int [] args = new int [] {
- OS.Pt_ARG_LIST_SEL_COUNT, 0, 0,
- OS.Pt_ARG_SELECTION_INDEXES, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- if (args [1] == 0) return -1;
- short [] buffer = new short [1];
- OS.memmove (buffer, args [4], 2);
- return buffer [0] - 1;
-}
-
-/**
- * Returns a string containing a copy of the contents of the
- * receiver's text field, or an empty string if there are no
- * contents.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- int [] args = {OS.Pt_ARG_TEXT_STRING, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- if (args [1] == 0) return "";
- int length = OS.strlen (args [1]);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, args [1], length);
- char [] unicode = Converter.mbcsToWcs (null, buffer);
- return new String (unicode);
-}
-
-/**
- * Returns the height of the receivers's text field.
- *
- * @return the text height
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTextHeight () {
- checkWidget();
- //NOT DONE - Only works for DROP_DOWN
- PhDim_t dim = new PhDim_t();
- if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidgetFamily (handle);
- OS.PtWidgetPreferredSize(handle, dim);
- int height = dim.h;
- int text = OS.PtWidgetChildBack(handle);
- OS.PtWidgetPreferredSize(text, dim);
- height += dim.h;
- return height;
-}
-
-/**
- * Returns the maximum number of characters that the receiver's
- * text field is capable of holding. If this has not been changed
- * by <code>setTextLimit()</code>, it will be the constant
- * <code>Combo.LIMIT</code>.
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public int getTextLimit () {
- checkWidget();
- int [] args = new int [] {OS.Pt_ARG_MAX_LENGTH, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Gets the number of items that are visible in the drop
- * down portion of the receiver's list.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @return the number of items that are visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public int getVisibleItemCount () {
- checkWidget ();
- int [] args = new int [] {OS.Pt_ARG_CBOX_MAX_VISIBLE_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-boolean hasFocus () {
- return OS.PtIsFocused (handle) != 0;
-}
-
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- OS.PtAddCallback (handle, OS.Pt_CB_SELECTION, windowProc, OS.Pt_CB_SELECTION);
- OS.PtAddCallback (handle, OS.Pt_CB_TEXT_CHANGED, windowProc, OS.Pt_CB_TEXT_CHANGED);
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param string the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string) {
- checkWidget();
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- return OS.PtListItemPos (handle, buffer) - 1;
-}
-
-/**
- * Searches the receiver's list starting at the given,
- * zero-relative index until an item is found that is equal
- * to the argument, and returns the index of that item. If
- * no item is found or the starting index is out of range,
- * returns -1.
- *
- * @param string the search item
- * @param start the zero-relative index at which to begin the search
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string, int start) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (start == 0) return indexOf(string);
- int [] args = new int [] {
- OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0,
- OS.Pt_ARG_ITEMS, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- int count = args [1];
- if (!(0 <= start && start < count)) return -1;
- int [] item = new int [1];
- for (int index=start; index<count; index++) {
- OS.memmove (item, args [4] + (index * 4), 4);
- int length = OS.strlen (item [0]);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, item [0], length);
- if (string.equals(new String (Converter.mbcsToWcs (null, buffer)))) return index;
- }
- return -1;
-}
-
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void paste () {
- checkWidget();
- int ig = OS.PhInputGroup (0);
- int ptr = OS.PhClipboardPasteString((short)ig);
- if (ptr == 0) return;
- int length = OS.strlen (ptr);
- int [] start = new int [1], end = new int [1];
- OS.PtTextGetSelection (handle, start, end);
- if (start [0] == -1) {
- int [] args = {OS.Pt_ARG_CURSOR_POSITION, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- start [0] = end [0] = args [1];
- }
- OS.PtTextModifyText (handle, start [0], end [0], end [0], ptr, length);
- OS.free(ptr);
-}
-
-int Pt_CB_SELECTION (int widget, int info) {
- if (info == 0) return OS.Pt_CONTINUE;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.reason_subtype == OS.Pt_LIST_SELECTION_FINAL) {
- postEvent(SWT.Selection);
- }
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_TEXT_CHANGED (int widget, int info) {
- sendEvent (SWT.Modify);
- return OS.Pt_CONTINUE;
-}
-
-void register () {
- super.register ();
- int child = OS.PtWidgetChildBack (handle);
- WidgetTable.put (child, this);
-}
-
-/**
- * Removes the items from the receiver's list which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget();
- if (start > end) return;
- int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- if (!(0 <= start && start <= end && end < args [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int count = end - start + 1;
- int result = OS.PtListDeleteItemPos (handle, count, start + 1);
- if (result != 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
- if ((style & SWT.READ_ONLY) !=0) {
- if (args [1] == count) OS.PtSetResource (handle, OS.Pt_ARG_TEXT_STRING, 0, 0);
- }
-}
-
-/**
- * Removes the item from the receiver's list at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget();
- int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- if (!(0 <= index && index < args [1])) error (SWT.ERROR_INVALID_RANGE);
- int result = OS.PtListDeleteItemPos (handle, 1, index + 1);
- if (result != 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
- if ((style & SWT.READ_ONLY) !=0) {
- if (args [1] == 1) OS.PtSetResource (handle, OS.Pt_ARG_TEXT_STRING, 0, 0);
- }
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * until an item is found that is equal to the argument,
- * and removes that item from the list.
- *
- * @param string the item to remove
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (String string) {
- checkWidget();
- int index = indexOf (string, 0);
- if (index == -1) error (SWT.ERROR_ITEM_NOT_REMOVED);
- remove (index);
-}
-
-/**
- * Removes all of the items from the receiver's list and clear the
- * contents of receiver's text field.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget();
- OS.PtListDeleteAllItems (handle);
- OS.PtSetResource (handle, OS.Pt_ARG_TEXT_STRING, 0, 0);
- sendEvent (SWT.Modify);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- *
- * @since 3.1
- */
-public void removeVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget();
- if (index < 0) return;
- OS.PtSetResource (handle, OS.Pt_ARG_CBOX_SELECTION_ITEM, index + 1, 0);
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- checkWidget();
- int newHeight = (resize && (style & SWT.DROP_DOWN) != 0) ? getTextHeight() : height;
- return super.setBounds (x, y, width, newHeight, move, resize, events);
-}
-
-/**
- * Sets the text of the item in the receiver's list at the given
- * zero-relative index to the string argument.
- *
- * @param index the index for the item
- * @param string the new text for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItem (int index, String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- if (!(0 <= index && index < args [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- int ptr = OS.malloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- OS.PtListReplaceItemPos (handle, new int [] {ptr}, 1, index + 1);
- OS.free (ptr);
-}
-
-/**
- * Sets the receiver's list to be the given array of items.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItems (String [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<items.length; i++) {
- if (items [i] == null) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- OS.PtListDeleteAllItems (handle);
- int[] itemsPtr = new int [items.length];
- for (int i=0; i<itemsPtr.length; i++) {
- byte [] buffer = Converter.wcsToMbcs (null, items [i], true);
- int ptr = OS.malloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- itemsPtr [i] = ptr;
- }
- OS.PtListAddItems (handle, itemsPtr, itemsPtr.length, 0);
- for (int i=0; i<itemsPtr.length; i++) {
- OS.free (itemsPtr [i]);
- }
- OS.PtSetResource (handle, OS.Pt_ARG_TEXT_STRING, 0, 0);
- sendEvent (SWT.Modify);
-}
-
-/**
- * Marks the receiver's list as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setListVisible (boolean visible) {
- checkWidget ();
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- * <p>
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public void setOrientation (int orientation) {
- checkWidget();
-}
-
-/**
- * Sets the selection in the receiver's text field to the
- * range specified by the argument whose x coordinate is the
- * start of the selection and whose y coordinate is the end
- * of the selection.
- *
- * @param selection a point representing the new selection start and end
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (Point selection) {
- checkWidget();
- if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
- OS.PtTextSetSelection (handle, new int [] {selection.x}, new int [] {selection.y});
-}
-
-/**
- * Sets the contents of the receiver's text field to the
- * given string.
- * <p>
- * This call is ignored when the receiver is read only and
- * the given string is not in the receiver's list.
- * </p>
- * <p>
- * Note: The text field in a <code>Combo</code> is typically
- * only capable of displaying a single line of text. Thus,
- * setting the text to a string containing line breaks or
- * other special characters will probably cause it to
- * display incorrectly.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- if ((style & SWT.READ_ONLY) != 0) {
- int index = OS.PtListItemPos(handle, buffer);
- if (index > 0) {
- OS.PtSetResource (handle, OS.Pt_ARG_CBOX_SELECTION_ITEM, index, 0);
- sendEvent (SWT.Modify);
- }
- return;
- }
- int ptr = OS.malloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- OS.PtSetResource (handle, OS.Pt_ARG_TEXT_STRING, ptr, 0);
- OS.free (ptr);
- sendEvent (SWT.Modify);
-}
-
-/**
- * Sets the maximum number of characters that the receiver's
- * text field is capable of holding to be the argument.
- * <p>
- * To reset this value to the default, use <code>setTextLimit(Combo.LIMIT)</code>.
- * Specifying a limit value larger than <code>Combo.LIMIT</code> sets the
- * receiver's limit to <code>Combo.LIMIT</code>.
- * </p>
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public void setTextLimit (int limit) {
- checkWidget();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- OS.PtSetResource (handle, OS.Pt_ARG_MAX_LENGTH, limit, 0);
-}
-
-int traversalCode (int key_sym, PhKeyEvent_t ke) {
- int code = super.traversalCode (key_sym, ke);
- if ((style & SWT.READ_ONLY) == 0) {
- if (key_sym == OS.Pk_Up || key_sym == OS.Pk_Down) {
- code &= ~(SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS);
- }
- }
- return code;
-}
-
-/**
- * Sets the number of items that are visible in the drop
- * down portion of the receiver's list.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param count the new number of items to be visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setVisibleItemCount (int visibleCount) {
- checkWidget ();
- if (visibleCount < 0) return;
- OS.PtSetResource (handle, OS.Pt_ARG_CBOX_MAX_VISIBLE_COUNT, visibleCount, 0);
-}
-
-boolean translateTraversal (int key_sym, PhKeyEvent_t phEvent) {
- boolean translated = super.translateTraversal (key_sym, phEvent);
- if (!translated && key_sym == OS.Pk_Return) {
- postEvent (SWT.DefaultSelection);
- return false;
- }
- return translated;
-}
-
-int widgetClass () {
- return OS.PtComboBox ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Composite.java
deleted file mode 100755
index e87c651833..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Composite.java
+++ /dev/null
@@ -1,1165 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are controls which are capable
- * of containing other controls.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>NO_BACKGROUND, NO_FOCUS, NO_MERGE_PAINTS, NO_REDRAW_RESIZE, NO_RADIO_GROUP, EMBEDDED, DOUBLE_BUFFERED</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: The <code>NO_BACKGROUND</code>, <code>NO_FOCUS</code>, <code>NO_MERGE_PAINTS</code>,
- * and <code>NO_REDRAW_RESIZE</code> styles are intended for use with <code>Canvas</code>.
- * They can be used with <code>Composite</code> if you are drawing your own, but their
- * behavior is undefined if they are used with subclasses of <code>Composite</code> other
- * than <code>Canvas</code>.
- * </p><p>
- * Note: The <code>CENTER</code> style, although undefined for composites, has the
- * same value as <code>EMBEDDED</code> which is used to embed widgets from other
- * widget toolkits into SWT. On some operating systems (GTK, Motif), this may cause
- * the children of this composite to be obscured.
- * </p><p>
- * This class may be subclassed by custom control implementors
- * who are building controls that are constructed from aggregates
- * of other controls.
- * </p>
- *
- * @see Canvas
- * @see <a href="http://www.eclipse.org/swt/snippets/#composite">Composite snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class Composite extends Scrollable {
- Layout layout;
- Control [] tabList;
- int cornerHandle;
- int layoutCount, backgroundMode;
-
-Composite () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- *
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_FOCUS
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_RADIO_GROUP
- * @see SWT#EMBEDDED
- * @see SWT#DOUBLE_BUFFERED
- * @see Widget#getStyle
- */
-public Composite (Composite parent, int style) {
- super (parent, style);
-}
-
-static int checkStyle (int style) {
- style &= SWT.TRANSPARENT;
- return style;
-}
-
-Control [] _getChildren () {
- int count = 0;
- int parentHandle = parentingHandle ();
- int child = OS.PtWidgetChildFront (parentHandle);
- while (child != 0) {
- child = OS.PtWidgetBrotherBehind (child);
- count++;
- }
- Control [] children = new Control [count];
- int i = 0, j = 0;
- child = OS.PtWidgetChildFront (parentHandle);
- while (i < count) {
- Widget widget = WidgetTable.get (child);
- if (widget != null && widget != this) {
- if (widget instanceof Control) {
- children [j++] = (Control) widget;
- }
- }
- i++;
- child = OS.PtWidgetBrotherBehind (child);
- }
- if (i == j) return children;
- Control [] newChildren = new Control [j];
- System.arraycopy (children, 0, newChildren, 0, j);
- return newChildren;
-}
-
-Control [] _getTabList () {
- if (tabList == null) return tabList;
- int count = 0;
- for (int i=0; i<tabList.length; i++) {
- if (!tabList [i].isDisposed ()) count++;
- }
- if (count == tabList.length) return tabList;
- Control [] newList = new Control [count];
- int index = 0;
- for (int i=0; i<tabList.length; i++) {
- if (!tabList [i].isDisposed ()) {
- newList [index++] = tabList [i];
- }
- }
- tabList = newList;
- return tabList;
-}
-
-/**
- * Clears any data that has been cached by a Layout for all widgets that
- * are in the parent hierarchy of the changed control up to and including the
- * receiver. If an ancestor does not have a layout, it is skipped.
- *
- * @param changed an array of controls that changed state and require a recalculation of size
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li>
- * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void changed (Control[] changed) {
- checkWidget ();
- if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<changed.length; i++) {
- Control control = changed [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean ancestor = false;
- Composite composite = control.parent;
- while (composite != null) {
- ancestor = composite == this;
- if (ancestor) break;
- composite = composite.parent;
- }
- if (!ancestor) error (SWT.ERROR_INVALID_PARENT);
- }
- for (int i=0; i<changed.length; i++) {
- Control child = changed [i];
- Composite composite = child.parent;
- while (child != this) {
- if (composite.layout == null || !composite.layout.flushCache (child)) {
- composite.state |= LAYOUT_CHANGED;
- }
- child = composite;
- composite = child.parent;
- }
- }
-}
-
-protected void checkSubclass () {
- /* Do nothing - Subclassing is allowed */
-}
-
-Control [] computeTabList () {
- Control result [] = super.computeTabList ();
- if (result.length == 0) return result;
- Control [] list = tabList != null ? _getTabList () : _getChildren ();
- for (int i=0; i<list.length; i++) {
- Control child = list [i];
- Control [] childList = child.computeTabList ();
- if (childList.length != 0) {
- Control [] newResult = new Control [result.length + childList.length];
- System.arraycopy (result, 0, newResult, 0, result.length);
- System.arraycopy (childList, 0, newResult, result.length, childList.length);
- result = newResult;
- }
- }
- return result;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- Point size;
- if (layout != null) {
- if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
- changed |= (state & LAYOUT_CHANGED) != 0;
- size = layout.computeSize (this, wHint, hHint, changed);
- state &= ~LAYOUT_CHANGED;
- } else {
- size = new Point (wHint, hHint);
- }
- } else {
- size = minimumSize ();
- }
- if (size.x == 0) size.x = DEFAULT_WIDTH;
- if (size.y == 0) size.y = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) size.x = wHint;
- if (hHint != SWT.DEFAULT) size.y = hHint;
- Rectangle trim = computeTrim (0, 0, size.x, size.y);
- return new Point (trim.width, trim.height);
-}
-
-void createHandle (int index) {
- state |= HANDLE | GRAB | CANVAS;
- int parentHandle = parent.parentingHandle ();
- createScrolledHandle (parentHandle);
-}
-
-void createScrollBars () {
- if (scrolledHandle == 0) return;
- if ((style & SWT.H_SCROLL) != 0) {
- horizontalBar = new ScrollBar (this, SWT.HORIZONTAL);
- }
- if ((style & SWT.V_SCROLL) != 0) {
- verticalBar = new ScrollBar (this, SWT.VERTICAL);
- }
-}
-
-byte [] defaultFont () {
- return display.TITLE_FONT;
-}
-
-void createScrolledHandle (int parentHandle) {
- int etches = OS.Pt_ALL_ETCHES | OS.Pt_ALL_OUTLINES;
- int [] args = new int [] {
- OS.Pt_ARG_FLAGS, hasBorder () ? OS.Pt_HIGHLIGHTED : 0, OS.Pt_HIGHLIGHTED,
- OS.Pt_ARG_BASIC_FLAGS, hasBorder () ? etches : 0, etches,
- OS.Pt_ARG_CONTAINER_FLAGS, 0, OS.Pt_ENABLE_CUA | OS.Pt_ENABLE_CUA_ARROWS,
- OS.Pt_ARG_FILL_COLOR, OS.Pg_TRANSPARENT, 0,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- scrolledHandle = OS.PtCreateWidget (OS.PtContainer (), parentHandle, args.length / 3, args);
- if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.H_SCROLL) != 0 && (style & SWT.V_SCROLL) != 0) {
- etches = OS.Pt_TOP_OUTLINE | OS.Pt_LEFT_OUTLINE;
- args = new int [] {
- OS.Pt_ARG_FLAGS, OS.Pt_HIGHLIGHTED, OS.Pt_HIGHLIGHTED,
- OS.Pt_ARG_BASIC_FLAGS, etches, etches,
- OS.Pt_ARG_WIDTH, display.SCROLLBAR_WIDTH, 0,
- OS.Pt_ARG_HEIGHT, display.SCROLLBAR_HEIGHT, 0,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- cornerHandle = OS.PtCreateWidget (OS.PtContainer (), scrolledHandle, args.length / 3, args);
- }
- int clazz = display.PtContainer;
- args = new int [] {
- OS.Pt_ARG_FLAGS, OS.Pt_SELECTABLE | OS.Pt_SELECT_NOREDRAW, OS.Pt_SELECTABLE | OS.Pt_SELECT_NOREDRAW,
- OS.Pt_ARG_CONTAINER_FLAGS, 0, OS.Pt_ENABLE_CUA | OS.Pt_ENABLE_CUA_ARROWS,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (clazz, scrolledHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- createScrollBars ();
-}
-
-void drawBackground (GC gc, int x, int y, int width, int height) {
- Color oldColor = gc.getBackground();
- gc.setBackground(getBackground());
- gc.fillRectangle(x, y, width, height);
- gc.setBackground(oldColor);
-}
-
-void drawWidget (int widget, int damage) {
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_BACKGROUND) == 0) {
-
- /*
- * Note that QNX 6.2.1 provides full widget hierarchy clipping in paint.
- */
- if (!(OS.QNX_MAJOR > 6 || (OS.QNX_MAJOR == 6 && (OS.QNX_MINOR > 2 || (OS.QNX_MINOR == 2 && OS.QNX_MICRO >= 1))))) {
- /* Get the clipping tiles for children and siblings */
- int clip_tile = getClipping (handle, topHandle (), true, true);
- if (clip_tile == 0) return;
-
- /* Translate the clipping to the current GC coordinates */
- short [] abs_x = new short [1], abs_y = new short [1];
- OS.PtGetAbsPosition (handle, abs_x, abs_y);
- short [] dis_abs_x = new short [1], dis_abs_y = new short [1];
- OS.PtGetAbsPosition (OS.PtFindDisjoint (handle), dis_abs_x, dis_abs_y);
- PhPoint_t delta = new PhPoint_t ();
- delta.x = (short) (abs_x [0] - dis_abs_x [0]);
- delta.y = (short) (abs_y [0] - dis_abs_y [0]);
- OS.PhTranslateTiles(clip_tile, delta);
-
- /* Set the clipping */
- int[] clip_rects_count = new int [1];
- int clip_rects = OS.PhTilesToRects (clip_tile, clip_rects_count);
- OS.PhFreeTiles (clip_tile);
- if (clip_rects_count [0] == 0) {
- clip_rects_count [0] = 1;
- OS.free (clip_rects);
- clip_rects = OS.malloc (PhRect_t.sizeof);
- OS.memset(clip_rects, 0, PhRect_t.sizeof);
- }
- OS.PgSetMultiClip (clip_rects_count[0], clip_rects);
- OS.free (clip_rects);
- }
-
- /* Draw the widget */
- super.drawWidget (widget, damage);
-
- if (!(OS.QNX_MAJOR > 6 || (OS.QNX_MAJOR == 6 && (OS.QNX_MINOR > 2 || (OS.QNX_MINOR == 2 && OS.QNX_MICRO >= 1))))) {
- /* Reset the clipping */
- OS.PgSetMultiClip (0, 0);
- }
- }
- } else {
- super.drawWidget (widget, damage);
- }
-}
-
-Composite findDeferredControl () {
- return layoutCount > 0 ? this : parent.findDeferredControl ();
-}
-
-void fixTabList (Control control) {
- if (tabList == null) return;
- int count = 0;
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == control) count++;
- }
- if (count == 0) return;
- Control [] newList = null;
- int length = tabList.length - count;
- if (length != 0) {
- newList = new Control [length];
- int index = 0;
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] != control) {
- newList [index++] = tabList [i];
- }
- }
- }
- tabList = newList;
-}
-
-public boolean forceFocus () {
- checkWidget();
- if ((state & CANVAS) == 0) return super.forceFocus ();
- /*
- * Bug in Photon. PtContainerGiveFocus() is supposed to give
- * focus to the widget even if the widget's Pt_GET_FOCUS flag
- * is not set. This does not happen when the widget is a
- * PtContainer. The fix is to set the flag before calling it.
- */
- int flags = OS.PtWidgetFlags (handle);
- OS.PtSetResource (handle, OS.Pt_ARG_FLAGS, OS.Pt_GETS_FOCUS, OS.Pt_GETS_FOCUS);
- boolean result = super.forceFocus ();
- OS.PtSetResource (handle, OS.Pt_ARG_FLAGS, flags, OS.Pt_GETS_FOCUS);
- return result;
-}
-
-public Rectangle getClientArea () {
- checkWidget();
- if (scrolledHandle == 0) return super.getClientArea ();
- PhArea_t area = new PhArea_t ();
- OS.PtWidgetArea (handle, area);
- return new Rectangle (area.pos_x, area.pos_y, area.size_w, area.size_h);
-}
-
-int getClipping(int widget, int topWidget, boolean clipChildren, boolean clipSiblings) {
- int child_tile = 0;
- int widget_tile = OS.PhGetTile(); // NOTE: PhGetTile native initializes the tile
-
- PhRect_t rect = new PhRect_t ();
- int args [] = {OS.Pt_ARG_FLAGS, 0, 0, OS.Pt_ARG_BASIC_FLAGS, 0, 0};
-
- /* Get the rectangle of all siblings in front of the widget */
- if (clipSiblings && OS.PtWidgetClass(topWidget) != OS.PtWindow()) {
- int temp_widget = topWidget;
- while ((temp_widget = OS.PtWidgetBrotherInFront(temp_widget)) != 0) {
- if (OS.PtWidgetIsRealized(temp_widget)) {
- int tile = OS.PhGetTile();
- if (child_tile == 0) child_tile = tile;
- else child_tile = OS.PhAddMergeTiles(tile, child_tile, null);
- OS.PtWidgetExtent(temp_widget, tile); // NOTE: tile->rect
- args [1] = args [4] = 0;
- OS.PtGetResources(temp_widget, args.length / 3, args);
- if ((args [1] & OS.Pt_HIGHLIGHTED) != 0) {
- int basic_flags = args [4];
- OS.memmove(rect, tile, PhRect_t.sizeof);
- if ((basic_flags & OS.Pt_TOP_ETCH) != 0) rect.ul_y++;
- if ((basic_flags & OS.Pt_BOTTOM_ETCH) != 0) rect.lr_y--;
- if ((basic_flags & OS.Pt_RIGHT_ETCH) != 0) rect.ul_x++;
- if ((basic_flags & OS.Pt_LEFT_ETCH) != 0) rect.lr_x--;
- OS.memmove(tile, rect, PhRect_t.sizeof);
- }
- }
- }
- /* Translate the siblings rectangles to the widget's coordinates */
- OS.PtWidgetCanvas(topWidget, widget_tile); // NOTE: widget_tile->rect
- OS.PhDeTranslateTiles(child_tile, widget_tile); // NOTE: widget_tile->rect.ul
- }
-
- /* Get the rectangle of the widget's children */
- if (clipChildren) {
- int temp_widget = OS.PtWidgetChildBack(widget);
- while (temp_widget != 0) {
- if (OS.PtWidgetIsRealized(temp_widget)) {
- int tile = OS.PhGetTile();
- if (child_tile == 0) child_tile = tile;
- else child_tile = OS.PhAddMergeTiles(tile, child_tile, null);
- OS.PtWidgetExtent(temp_widget, tile); // NOTE: tile->rect
- args [1] = args [4] = 0;
- OS.PtGetResources(temp_widget, args.length / 3, args);
- if ((args [1] & OS.Pt_HIGHLIGHTED) != 0) {
- int basic_flags = args [4];
- OS.memmove(rect, tile, PhRect_t.sizeof);
- if ((basic_flags & OS.Pt_TOP_ETCH) != 0) rect.ul_y++;
- if ((basic_flags & OS.Pt_BOTTOM_ETCH) != 0) rect.lr_y--;
- if ((basic_flags & OS.Pt_RIGHT_ETCH) != 0) rect.ul_x++;
- if ((basic_flags & OS.Pt_LEFT_ETCH) != 0) rect.lr_x--;
- OS.memmove(tile, rect, PhRect_t.sizeof);
- }
- }
- temp_widget = OS.PtWidgetBrotherInFront(temp_widget);
- }
- }
-
- /* Get the widget's rectangle */
- OS.PtWidgetCanvas(widget, widget_tile); // NOTE: widget_tile->rect
- OS.PhDeTranslateTiles(widget_tile, widget_tile); // NOTE: widget_tile->rect.ul
-
- /* Clip the widget's rectangle from the child/siblings rectangle's */
- if (child_tile != 0) {
- int clip_tile = OS.PhClipTilings(widget_tile, child_tile, null);
- OS.PhFreeTiles(child_tile);
- return clip_tile;
- }
- return widget_tile;
-}
-
-/**
- * Returns the receiver's background drawing mode. This
- * will be one of the following constants defined in class
- * <code>SWT</code>:
- * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>,
- * <code>INHERTIT_FORCE</code>.
- *
- * @return the background mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- *
- * @since 3.2
- */
-public int getBackgroundMode () {
- checkWidget ();
- return backgroundMode;
-}
-
-/**
- * Returns a (possibly empty) array containing the receiver's children.
- * Children are returned in the order that they are drawn. The topmost
- * control appears at the beginning of the array. Subsequent controls
- * draw beneath this control and appear later in the array.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of children, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return an array of children
- *
- * @see Control#moveAbove
- * @see Control#moveBelow
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control [] getChildren () {
- checkWidget();
- return _getChildren ();
-}
-
-int getChildrenCount () {
- int count = 0;
- int parentHandle = parentingHandle ();
- int child = OS.PtWidgetChildFront (parentHandle);
- while (child != 0) {
- child = OS.PtWidgetBrotherBehind (child);
- count++;
- }
- return count;
-}
-
-/**
- * Returns layout which is associated with the receiver, or
- * null if one has not been set.
- *
- * @return the receiver's layout or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Layout getLayout () {
- checkWidget();
- return layout;
-}
-
-/**
- * Returns <code>true</code> if the receiver has deferred
- * the performing of layout, and <code>false</code> otherwise.
- *
- * @return the receiver's deferred layout state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setLayoutDeferred(boolean)
- * @see #isLayoutDeferred()
- *
- * @since 3.1
- */
-public boolean getLayoutDeferred () {
- checkWidget ();
- return layoutCount > 0 ;
-}
-
-boolean hasBorder () {
- return (style & SWT.BORDER) != 0;
-}
-
-boolean hasFocus () {
- return OS.PtIsFocused (handle) == 2;
-}
-
-boolean hooksKeys () {
- return hooks (SWT.KeyDown) || hooks (SWT.KeyUp);
-}
-
-/**
- * Returns <code>true</code> if the receiver or any ancestor
- * up to and including the receiver's nearest ancestor shell
- * has deferred the performing of layouts. Otherwise, <code>false</code>
- * is returned.
- *
- * @return the receiver's deferred layout state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setLayoutDeferred(boolean)
- * @see #getLayoutDeferred()
- *
- * @since 3.1
- */
-public boolean isLayoutDeferred () {
- checkWidget ();
- return findDeferredControl () != null;
-}
-
-/**
- * Gets the (possibly empty) tabbing order for the control.
- *
- * @return tabList the ordered list of controls representing the tab order
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setTabList
- */
-public Control [] getTabList () {
- checkWidget ();
- Control [] tabList = _getTabList ();
- if (tabList == null) {
- int count = 0;
- Control [] list =_getChildren ();
- for (int i=0; i<list.length; i++) {
- if (list [i].isTabGroup ()) count++;
- }
- tabList = new Control [count];
- int index = 0;
- for (int i=0; i<list.length; i++) {
- if (list [i].isTabGroup ()) {
- tabList [index++] = list [i];
- }
- }
- }
- return tabList;
-}
-
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the receiver does not have a layout, do nothing.
- * <p>
- * This is equivalent to calling <code>layout(true)</code>.
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void layout () {
- checkWidget ();
- layout (true);
-}
-
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the argument is <code>true</code> the layout must not rely
- * on any information it has cached about the immediate children. If it
- * is <code>false</code> the layout may (potentially) optimize the
- * work it is doing by assuming that none of the receiver's
- * children has changed state since the last layout.
- * If the receiver does not have a layout, do nothing.
- * <p>
- * If a child is resized as a result of a call to layout, the
- * resize event will invoke the layout of the child. The layout
- * will cascade down through all child widgets in the receiver's widget
- * tree until a child is encountered that does not resize. Note that
- * a layout due to a resize will not flush any cached information
- * (same as <code>layout(false)</code>).
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void layout (boolean changed) {
- checkWidget ();
- if (layout == null) return;
- layout (changed, false);
-}
-
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the changed argument is <code>true</code> the layout must not rely
- * on any information it has cached about its children. If it
- * is <code>false</code> the layout may (potentially) optimize the
- * work it is doing by assuming that none of the receiver's
- * children has changed state since the last layout.
- * If the all argument is <code>true</code> the layout will cascade down
- * through all child widgets in the receiver's widget tree, regardless of
- * whether the child has changed size. The changed argument is applied to
- * all layouts. If the all argument is <code>false</code>, the layout will
- * <em>not</em> cascade down through all child widgets in the receiver's widget
- * tree. However, if a child is resized as a result of a call to layout, the
- * resize event will invoke the layout of the child. Note that
- * a layout due to a resize will not flush any cached information
- * (same as <code>layout(false)</code>).
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise
- * @param all <code>true</code> if all children in the receiver's widget tree should be laid out, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void layout (boolean changed, boolean all) {
- checkWidget ();
- if (layout == null && !all) return;
- markLayout (changed, all);
- updateLayout (all);
-}
-
-/**
- * Forces a lay out (that is, sets the size and location) of all widgets that
- * are in the parent hierarchy of the changed control up to and including the
- * receiver. The layouts in the hierarchy must not rely on any information
- * cached about the changed control or any of its ancestors. The layout may
- * (potentially) optimize the work it is doing by assuming that none of the
- * peers of the changed control have changed state since the last layout.
- * If an ancestor does not have a layout, skip it.
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed a control that has had a state change which requires a recalculation of its size
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li>
- * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void layout (Control [] changed) {
- checkWidget ();
- if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<changed.length; i++) {
- Control control = changed [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean ancestor = false;
- Composite composite = control.parent;
- while (composite != null) {
- ancestor = composite == this;
- if (ancestor) break;
- composite = composite.parent;
- }
- if (!ancestor) error (SWT.ERROR_INVALID_PARENT);
- }
- int updateCount = 0;
- Composite [] update = new Composite [16];
- for (int i=0; i<changed.length; i++) {
- Control child = changed [i];
- Composite composite = child.parent;
- while (child != this) {
- if (composite.layout != null) {
- composite.state |= LAYOUT_NEEDED;
- if (!composite.layout.flushCache (child)) {
- composite.state |= LAYOUT_CHANGED;
- }
- }
- if (updateCount == update.length) {
- Composite [] newUpdate = new Composite [update.length + 16];
- System.arraycopy (update, 0, newUpdate, 0, update.length);
- update = newUpdate;
- }
- child = update [updateCount++] = composite;
- composite = child.parent;
- }
- }
- for (int i=updateCount-1; i>=0; i--) {
- update [i].updateLayout (false);
- }
-}
-
-void markLayout (boolean changed, boolean all) {
- if (layout != null) {
- state |= LAYOUT_NEEDED;
- if (changed) state |= LAYOUT_CHANGED;
- }
- if (all) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].markLayout (changed, all);
- }
- }
-}
-
-Point minimumSize () {
- Control [] children = _getChildren ();
- int width = 0, height = 0;
- for (int i=0; i<children.length; i++) {
- Rectangle rect = children [i].getBounds ();
- width = Math.max (width, rect.x + rect.width);
- height = Math.max (height, rect.y + rect.height);
- }
- return new Point (width, height);
-}
-
-void moveToBack (int child) {
- OS.PtWidgetToBack (child);
-}
-
-int parentingHandle () {
- return handle;
-}
-
-int Ph_EV_BUT_PRESS (int widget, int info) {
- int result = super.Ph_EV_BUT_PRESS (widget, info);
- if (result != OS.Pt_CONTINUE)return result;
- if ((state & CANVAS) != 0) {
- /* Set focus for a CANVAS with no children */
- if ((style & SWT.NO_FOCUS) == 0 && hooksKeys ()) {
- if (OS.PtWidgetChildFront (handle) == 0) {
- if (info == 0) return OS.Pt_END;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.event == 0) return OS.Pt_END;
- PhEvent_t ev = new PhEvent_t ();
- OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
- int data = OS.PhGetData (cbinfo.event);
- if (data == 0) return OS.Pt_END;
- PhPointerEvent_t pe = new PhPointerEvent_t ();
- OS.memmove (pe, data, PhPointerEvent_t.sizeof);
- if (pe.buttons == OS.Ph_BUTTON_SELECT) setFocus ();
- }
- }
- }
- return result;
-}
-
-int Pt_CB_OUTBOUND (int widget, int info) {
- if ((state & CANVAS) != 0) {
- if (info == 0) return OS.Pt_END;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.event == 0) return OS.Pt_END;
- PhEvent_t ev = new PhEvent_t ();
- OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
- int data = OS.PhGetData (cbinfo.event);
- if (data == 0) return OS.Pt_END;
- PhPointerEvent_t pe = new PhPointerEvent_t ();
- OS.memmove (pe, data, PhPointerEvent_t.sizeof);
-
- /* Grab pointer */
- PhRect_t rect = new PhRect_t ();
- PhPoint_t pos = new PhPoint_t ();
- pos.x = pe.pos_x;
- pos.y = pe.pos_y;
- rect.ul_x = rect.lr_x = (short) (pos.x + ev.translation_x);
- rect.ul_y = rect.lr_y = (short) (pos.y + ev.translation_y);
- int rid = OS.PtWidgetRid (handle);
- int input_group = OS.PhInputGroup (0);
- int flags = OS.Ph_DRAG_KEY_MOTION | OS.Ph_DRAG_TRACK | OS.Ph_TRACK_DRAG;
- OS.PhInitDrag (rid, flags, rect, null, input_group, null, null, null, pos, null);
-
- /* Post drag detect event */
- Event event = new Event ();
- event.x = display.dragStartX;
- event.y = display.dragStartY;
- postEvent (SWT.DragDetect, event);
- }
- return OS.Pt_CONTINUE;
-}
-
-void releaseChildren (boolean destroy) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child != null && !child.isDisposed ()) {
- child.release (false);
- }
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- cornerHandle = 0;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- layout = null;
- tabList = null;
-}
-
-void removeControl (Control control) {
- fixTabList (control);
-}
-
-void resizeClientArea () {
- int [] args = {OS.Pt_ARG_WIDTH, 0, 0, OS.Pt_ARG_HEIGHT, 0, 0};
- OS.PtGetResources (scrolledHandle, args.length / 3, args);
- resizeClientArea (args [1], args [4], true);
-}
-
-void resizeClientArea (int width, int height, boolean events) {
- if (scrolledHandle == 0) return;
-
- /* Calculate the insets */
- int [] args = {
- OS.Pt_ARG_BASIC_FLAGS, 0, 0,
- OS.Pt_ARG_BEVEL_WIDTH, 0, 0,
- };
- OS.PtGetResources (scrolledHandle, args.length / 3, args);
- int flags = args [1];
- int bevel = args [4];
- int top = 0, left = 0, right = 0, bottom = 0;
- if ((flags & OS.Pt_TOP_ETCH) != 0) top++;
- if ((flags & OS.Pt_TOP_OUTLINE) != 0) top++;
- if ((flags & OS.Pt_TOP_INLINE) != 0) top++;
- if ((flags & OS.Pt_TOP_BEVEL) != 0) top += bevel;
- if ((flags & OS.Pt_BOTTOM_ETCH) != 0) bottom++;
- if ((flags & OS.Pt_BOTTOM_OUTLINE) != 0) bottom++;
- if ((flags & OS.Pt_BOTTOM_INLINE) != 0) bottom++;
- if ((flags & OS.Pt_BOTTOM_BEVEL) != 0) bottom += bevel;
- if ((flags & OS.Pt_RIGHT_ETCH) != 0) right++;
- if ((flags & OS.Pt_RIGHT_OUTLINE) != 0) right++;
- if ((flags & OS.Pt_RIGHT_INLINE) != 0) right++;
- if ((flags & OS.Pt_RIGHT_BEVEL) != 0) right += bevel;
- if ((flags & OS.Pt_LEFT_ETCH) != 0) left++;
- if ((flags & OS.Pt_LEFT_OUTLINE) != 0) left++;
- if ((flags & OS.Pt_LEFT_INLINE) != 0) left++;
- if ((flags & OS.Pt_LEFT_BEVEL) != 0) left += bevel;
-
- int clientWidth = width - (left + right);
- int clientHeight = height - (top + bottom);
-
- int vBarWidth = 0, hBarHeight = 0;
- boolean isVisibleHBar = horizontalBar != null && horizontalBar.getVisible ();
- boolean isVisibleVBar = verticalBar != null && verticalBar.getVisible ();
- if (isVisibleHBar) {
- args = new int [] {OS.Pt_ARG_HEIGHT, 0, 0};
- OS.PtGetResources (horizontalBar.handle, args.length / 3, args);
- clientHeight -= (hBarHeight = args [1]);
- }
- if (isVisibleVBar) {
- args = new int [] {OS.Pt_ARG_WIDTH, 0, 0};
- OS.PtGetResources (verticalBar.handle, args.length / 3, args);
- clientWidth -= (vBarWidth = args [1]);
- }
- if (isVisibleHBar) {
- horizontalBar.setBounds (0, clientHeight, clientWidth, hBarHeight);
- }
- if (isVisibleVBar) {
- verticalBar.setBounds (clientWidth, 0, vBarWidth, clientHeight);
- }
- args = new int [] {
- OS.Pt_ARG_WIDTH, Math.max (clientWidth, 0), 0,
- OS.Pt_ARG_HEIGHT, Math.max (clientHeight, 0), 0,
- };
- OS.PtSetResources (handle, args.length / 3, args);
- if (cornerHandle != 0) {
- PhPoint_t pt = new PhPoint_t ();
- pt.x = (short) clientWidth;
- pt.y = (short) clientHeight;
- int ptr = OS.malloc (PhPoint_t.sizeof);
- OS.memmove (ptr, pt, PhPoint_t.sizeof);
- OS.PtSetResource (cornerHandle, OS.Pt_ARG_POS, ptr, 0);
- OS.free (ptr);
- }
-
- if (events) {
- sendEvent (SWT.Resize);
- }
-}
-
-/**
- * Sets the background drawing mode to the argument which should
- * be one of the following constants defined in class <code>SWT</code>:
- * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>,
- * <code>INHERIT_FORCE</code>.
- *
- * @param mode the new background mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- *
- * @since 3.2
- */
-public void setBackgroundMode (int mode) {
- checkWidget ();
- backgroundMode = mode;
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- int result = super.setBounds (x, y, width, height, move, resize, false);
- if ((result & MOVED) != 0) {
- if (events) sendEvent (SWT.Move);
- }
- if ((result & RESIZED) != 0) {
- resizeClientArea (width, height, false);
- if (events) sendEvent (SWT.Resize);
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
- }
- return result;
-}
-
-public boolean setFocus () {
- checkWidget();
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.getVisible () && child.setFocus ()) return true;
- }
- return super.setFocus ();
-}
-
-/**
- * Sets the layout which is associated with the receiver to be
- * the argument which may be null.
- *
- * @param layout the receiver's new layout or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLayout (Layout layout) {
- checkWidget();
- this.layout = layout;
-}
-
-/**
- * If the argument is <code>true</code>, causes subsequent layout
- * operations in the receiver or any of its children to be ignored.
- * No layout of any kind can occur in the receiver or any of its
- * children until the flag is set to false.
- * Layout operations that occurred while the flag was
- * <code>true</code> are remembered and when the flag is set to
- * <code>false</code>, the layout operations are performed in an
- * optimized manner. Nested calls to this method are stacked.
- *
- * @param defer the new defer state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #layout(boolean)
- * @see #layout(Control[])
- *
- * @since 3.1
- */
-public void setLayoutDeferred (boolean defer) {
- if (!defer) {
- if (--layoutCount == 0) {
- if ((state & LAYOUT_CHILD) != 0 || (state & LAYOUT_NEEDED) != 0) {
- updateLayout (true);
- }
- }
- } else {
- layoutCount++;
- }
-}
-
-boolean setTabGroupFocus () {
- if (isTabItem ()) return setTabItemFocus ();
- boolean takeFocus = (style & SWT.NO_FOCUS) == 0;
- if ((state & CANVAS) != 0) takeFocus = hooksKeys ();
- if (takeFocus && setTabItemFocus ()) return true;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.isTabItem () && child.setTabItemFocus ()) return true;
- }
- return false;
-}
-
-/**
- * Sets the tabbing order for the specified controls to
- * match the order that they occur in the argument list.
- *
- * @param tabList the ordered list of controls representing the tab order or null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if a widget in the tabList is null or has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if widget in the tabList is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTabList (Control [] tabList) {
- checkWidget ();
- if (tabList == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<tabList.length; i++) {
- Control control = tabList [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
- this.tabList = tabList;
-}
-
-int traversalCode (int key_sym, PhKeyEvent_t ke) {
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_FOCUS) != 0) return 0;
- if (hooksKeys ()) return 0;
- }
- return super.traversalCode (key_sym, ke);
-}
-
-void updateLayout (boolean all) {
- Composite parent = findDeferredControl ();
- if (parent != null) {
- parent.state |= LAYOUT_CHILD;
- return;
- }
- if ((state & LAYOUT_NEEDED) != 0) {
- boolean changed = (state & LAYOUT_CHANGED) != 0;
- state &= ~(LAYOUT_NEEDED | LAYOUT_CHANGED);
- layout.layout (this, changed);
- }
- if (all) {
- state &= ~LAYOUT_CHILD;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].updateLayout (all);
- }
- }
-}
-
-int widgetClass () {
- if ((state & CANVAS) != 0) return OS.PtContainer ();
- return super.widgetClass ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Control.java
deleted file mode 100755
index 2a58676f3f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Control.java
+++ /dev/null
@@ -1,3286 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.accessibility.*;
-
-/**
- * Control is the abstract superclass of all windowed user interface classes.
- * <p>
- * <dl>
- * <dt><b>Styles:</b>
- * <dd>BORDER</dd>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * <dt><b>Events:</b>
- * <dd>DragDetect, FocusIn, FocusOut, Help, KeyDown, KeyUp, MenuDetect, MouseDoubleClick, MouseDown, MouseEnter,
- * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize, Traverse</dd>
- * </dl>
- * </p><p>
- * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#control">Control snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public abstract class Control extends Widget implements Drawable {
- Composite parent;
- Cursor cursor;
- Font font;
- Menu menu;
- Object layoutData;
- String toolTipText;
- Image backgroundImage;
- Region region;
- int toolTipHandle;
- Accessible accessible;
-
-Control () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#LEFT_TO_RIGHT
- * @see SWT#RIGHT_TO_LEFT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Control (Composite parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget (0);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize,typedListener);
- addListener (SWT.Move,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when a drag gesture occurs, by sending it
- * one of the messages defined in the <code>DragDetectListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #removeDragDetectListener
- *
- * @since 3.3
- */
-public void addDragDetectListener (DragDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.DragDetect,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control gains or loses focus, by sending
- * it one of the messages defined in the <code>FocusListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see FocusListener
- * @see #removeFocusListener
- */
-public void addFocusListener (FocusListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.FocusIn,typedListener);
- addListener (SWT.FocusOut,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when help events are generated for the control,
- * by sending it one of the messages defined in the
- * <code>HelpListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard, by sending
- * it one of the messages defined in the <code>KeyListener</code>
- * interface.
- * <p>
- * When a key listener is added to a control, the control
- * will take part in widget traversal. By default, all
- * traversal keys (such as the tab key and so on) are
- * delivered to the control. In order for a control to take
- * part in traversal, it should listen for traversal events.
- * Otherwise, the user can traverse into a control but not
- * out. Note that native controls such as table and tree
- * implement key traversal in the operating system. It is
- * not necessary to add traversal listeners for these controls,
- * unless you want to override the default traversal.
- * </p>
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #removeKeyListener
- */
-public void addKeyListener (KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.KeyUp,typedListener);
- addListener (SWT.KeyDown,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the platform-specific context menu trigger
- * has occurred, by sending it one of the messages defined in
- * the <code>MenuDetectListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #removeMenuDetectListener
- *
- * @since 3.3
- */
-public void addMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MenuDetect, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when mouse buttons are pressed and released, by sending
- * it one of the messages defined in the <code>MouseListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseListener
- * @see #removeMouseListener
- */
-public void addMouseListener (MouseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseDown,typedListener);
- addListener (SWT.MouseUp,typedListener);
- addListener (SWT.MouseDoubleClick,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse moves, by sending it one of the
- * messages defined in the <code>MouseMoveListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseMoveListener
- * @see #removeMouseMoveListener
- */
-public void addMouseMoveListener (MouseMoveListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseMove,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse passes or hovers over controls, by sending
- * it one of the messages defined in the <code>MouseTrackListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseTrackListener
- * @see #removeMouseTrackListener
- */
-public void addMouseTrackListener (MouseTrackListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseEnter,typedListener);
- addListener (SWT.MouseExit,typedListener);
- addListener (SWT.MouseHover,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse wheel is scrolled, by sending
- * it one of the messages defined in the
- * <code>MouseWheelListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseWheelListener
- * @see #removeMouseWheelListener
- *
- * @since 3.3
- */
-public void addMouseWheelListener (MouseWheelListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseWheel, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver needs to be painted, by sending it
- * one of the messages defined in the <code>PaintListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see PaintListener
- * @see #removePaintListener
- */
-public void addPaintListener (PaintListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Paint,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when traversal events occur, by sending it
- * one of the messages defined in the <code>TraverseListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TraverseListener
- * @see #removeTraverseListener
- */
-public void addTraverseListener (TraverseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Traverse,typedListener);
-}
-
-/**
- * Forces the receiver to have the <em>keyboard focus</em>, causing
- * all keyboard events to be delivered to it.
- *
- * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setFocus
- */
-public boolean forceFocus () {
- checkWidget();
- /*
- * Bug in Photon. Photon will stop sending key
- * events, if a menu is up and focus is given to
- * a widget by calling PtContainerGiveFocus(). The
- * fix is to detect when a menu is up and avoid
- * calling this function.
- */
- Shell shell = getShell ();
- if (shell.activeMenu != null) return false;
- shell.bringToTop (false);
- OS.PtContainerGiveFocus (handle, null);
- return hasFocus ();
-}
-
-void checkBuffered () {
- style &= ~SWT.DOUBLE_BUFFERED;
-}
-
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>preferred size</em> of a control is the size that it would
- * best be displayed at. The width hint and height hint arguments
- * allow the caller to ask a control questions such as "Given a particular
- * width, how high does the control need to be to show all of the contents?"
- * To indicate that the caller does not wish to constrain a particular
- * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
- * </p>
- *
- * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
- * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
- * @return the preferred size of the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Layout
- * @see #getBorderWidth
- * @see #getBounds
- * @see #getSize
- * @see #pack(boolean)
- * @see "computeTrim, getClientArea for controls that implement them"
- */
-public Point computeSize (int wHint, int hHint) {
- return computeSize (wHint, hHint, true);
-}
-
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>preferred size</em> of a control is the size that it would
- * best be displayed at. The width hint and height hint arguments
- * allow the caller to ask a control questions such as "Given a particular
- * width, how high does the control need to be to show all of the contents?"
- * To indicate that the caller does not wish to constrain a particular
- * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
- * </p><p>
- * If the changed flag is <code>true</code>, it indicates that the receiver's
- * <em>contents</em> have changed, therefore any caches that a layout manager
- * containing the control may have been keeping need to be flushed. When the
- * control is resized, the changed flag will be <code>false</code>, so layout
- * manager caches can be retained.
- * </p>
- *
- * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
- * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
- * @param changed <code>true</code> if the control's contents have changed, and <code>false</code> otherwise
- * @return the preferred size of the control.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Layout
- * @see #getBorderWidth
- * @see #getBounds
- * @see #getSize
- * @see #pack(boolean)
- * @see "computeTrim, getClientArea for controls that implement them"
- */
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = DEFAULT_WIDTH;
- int height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2;
- height += border * 2;
- return new Point (width, height);
-}
-
-Control computeTabGroup () {
- if (isTabGroup ()) return this;
- return parent.computeTabGroup ();
-}
-
-Control computeTabRoot () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- int index = 0;
- while (index < tabList.length) {
- if (tabList [index] == this) break;
- index++;
- }
- if (index == tabList.length) {
- if (isTabGroup ()) return this;
- }
- }
- return parent.computeTabRoot ();
-}
-
-Control [] computeTabList () {
- if (isTabGroup ()) {
- if (getVisible () && getEnabled ()) {
- return new Control [] {this};
- }
- }
- return new Control [0];
-}
-
-void createWidget (int index) {
- checkOrientation (parent);
- super.createWidget (index);
- checkBuffered ();
- setZOrder ();
- realizeWidget ();
- setDefaultFont ();
-}
-
-int defaultBackground () {
- return display.WIDGET_BACKGROUND;
-}
-
-byte [] defaultFont () {
- return display.TEXT_FONT;
-}
-
-int defaultForeground () {
- return display.WIDGET_FOREGROUND;
-}
-
-boolean drawGripper (int x, int y, int width, int height, boolean vertical) {
- return false;
-}
-
-/**
- * Detects a drag and drop gesture. This method is used
- * to detect a drag gesture when called from within a mouse
- * down listener.
- *
- * <p>By default, a drag is detected when the gesture
- * occurs anywhere within the client area of a control.
- * Some controls, such as tables and trees, override this
- * behavior. In addition to the operating system specific
- * drag gesture, they require the mouse to be inside an
- * item. Custom widget writers can use <code>setDragDetect</code>
- * to disable the default detection, listen for mouse down,
- * and then call <code>dragDetect()</code> from within the
- * listener to conditionally detect a drag.
- * </p>
- *
- * @param event the mouse down event
- *
- * @return <code>true</code> if the gesture occurred, and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT when the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @see #getDragDetect
- * @see #setDragDetect
- *
- * @since 3.3
- */
-public boolean dragDetect (Event event) {
- checkWidget ();
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- return dragDetect (event.button, event.count, event.stateMask, event.x, event.y);
-}
-
-/**
- * Detects a drag and drop gesture. This method is used
- * to detect a drag gesture when called from within a mouse
- * down listener.
- *
- * <p>By default, a drag is detected when the gesture
- * occurs anywhere within the client area of a control.
- * Some controls, such as tables and trees, override this
- * behavior. In addition to the operating system specific
- * drag gesture, they require the mouse to be inside an
- * item. Custom widget writers can use <code>setDragDetect</code>
- * to disable the default detection, listen for mouse down,
- * and then call <code>dragDetect()</code> from within the
- * listener to conditionally detect a drag.
- * </p>
- *
- * @param event the mouse down event
- *
- * @return <code>true</code> if the gesture occurred, and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT when the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @see #getDragDetect
- * @see #setDragDetect
- *
- * @since 3.3
- */
-public boolean dragDetect (MouseEvent event) {
- checkWidget ();
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- return dragDetect (event.button, event.count, event.stateMask, event.x, event.y);
-}
-
-boolean dragDetect (int button, int count, int stateMask, int x, int y) {
- //TODO - not implemented
- return false;
-}
-
-int drawProc (int widget, int damage) {
- if (widget <=0) return OS.Pt_CONTINUE;
- drawWidget (widget, damage );
- if (!hooks(SWT.Paint) && !filters (SWT.Paint)) return OS.Pt_CONTINUE;
- /* Send the paint event */
- PhPoint_t pt = new PhPoint_t ();
- PhRect_t widRect = new PhRect_t();
- OS.PtWidgetExtent(widget, widRect) ;
- OS.PtWidgetOffset(widget, pt);
- pt.x += widRect.ul_x;
- pt.y += widRect.ul_y;
- damage = OS.PhCopyTiles( damage );
- PhTile_t tile = new PhTile_t ();
- OS.memmove (tile, damage, PhTile_t.sizeof);
- int transPoint = OS.malloc ( PhPoint_t.sizeof);
- OS.memmove(transPoint, pt, PhPoint_t.sizeof);
- OS.PhDeTranslateTiles(damage, transPoint);
- OS.free(transPoint);
- OS.memmove (tile, damage, PhTile_t.sizeof);
- boolean noMerge = (style & SWT.NO_MERGE_PAINTS) != 0 && (state & CANVAS) != 0;
- if (tile.next != 0 && noMerge)
- {
- OS.memmove (tile, tile.next, PhTile_t.sizeof);
- while (tile.next != 0)
- {
- Event event = new Event ();
- event.width = tile.rect_lr_x - tile.rect_ul_x + 1;
- event.height = tile.rect_lr_y - tile.rect_ul_y + 1;
- event.x = tile.rect_ul_x;
- event.y = tile.rect_ul_y;
- GC gc = event.gc = new GC (this);
- gc.setClipping(event.x, event.y, event.width, event.height);
- sendEvent (SWT.Paint, event);
- if (isDisposed ()) break;
- gc.dispose ();
- event.gc = null;
- if ( tile.next != 0 )
- OS.memmove (tile, tile.next, PhTile_t.sizeof);
- }
- }
- else
- {
- int rect1 = OS.malloc (PhRect_t.sizeof);
- int rect2 = OS.malloc (PhRect_t.sizeof);
- OS.memmove (rect1, tile, PhRect_t.sizeof);
- OS.memmove (rect2, widRect, PhRect_t.sizeof);
- int inter = OS.PhRectIntersect(rect1, rect2);
- if ( inter == 1 )
- {
- OS.memmove(widRect, rect1, PhRect_t.sizeof);
- Event event = new Event ();
- event.x = widRect.ul_x;
- event.y = widRect.ul_y;
- event.width = widRect.lr_x - widRect.ul_x + 1;
- event.height = widRect.lr_y - widRect.ul_y + 1;
- GC gc = event.gc = new GC (this);
- gc.setClipping(event.x, event.y, event.width, event.height );
- sendEvent (SWT.Paint, event);
- gc.dispose ();
- event.gc = null;
- }
- OS.free(rect1);
- OS.free(rect2);
- }
- OS.PhFreeTiles( damage );
- return OS.Pt_CONTINUE;
-}
-
-void drawWidget (int widget, int damage) {
- int widgetClass = widgetClass ();
- if (widgetClass != 0) OS.PtSuperClassDraw (widgetClass, handle, damage);
-}
-
-void enableWidget (boolean enabled) {
- int topHandle = topHandle ();
- int flags = enabled ? 0 : OS.Pt_BLOCKED | OS.Pt_GHOST;
- OS.PtSetResource (topHandle, OS.Pt_ARG_FLAGS, flags, OS.Pt_BLOCKED | OS.Pt_GHOST);
-}
-
-/**
- * Returns the accessible object for the receiver.
- * If this is the first time this object is requested,
- * then the object is created and returned.
- *
- * @return the accessible object
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Accessible#addAccessibleListener
- * @see Accessible#addAccessibleControlListener
- *
- * @since 2.0
- */
-public Accessible getAccessible () {
- checkWidget ();
- if (accessible == null) {
- accessible = Accessible.internal_new_Accessible (this);
- }
- return accessible;
-}
-
-/**
- * Returns the receiver's background color.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on some versions of Windows the background of a TabFolder,
- * is a gradient rather than a solid color.
- * </p>
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Color getBackground () {
- checkWidget();
- int [] args = {OS.Pt_ARG_FILL_COLOR, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return Color.photon_new (display, args [1]);
-}
-
-/**
- * Returns the receiver's background image.
- *
- * @return the background image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Image getBackgroundImage () {
- checkWidget ();
- return backgroundImage;
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Font getFont () {
- checkWidget();
- if (font != null) return font;
- int [] args = {
- OS.Pt_ARG_TEXT_FONT, 0, 0,
- OS.Pt_ARG_LIST_FONT, 0, 0,
- OS.Pt_ARG_TITLE_FONT, 0, 0,
- OS.Pt_ARG_GAUGE_FONT, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- byte [] font;
- int ptr = args [1];
- if (ptr == 0) ptr = args [4];
- if (ptr == 0) ptr = args [7];
- if (ptr == 0) ptr = args [11];
- if (ptr == 0) {
- font = defaultFont ();
- } else {
- int length = OS.strlen (ptr);
- font = new byte [length + 1];
- OS.memmove (font, ptr, length);
- }
- return Font.photon_new (display, font);
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Color getForeground () {
- checkWidget();
- int [] args = {OS.Pt_ARG_COLOR, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return Color.photon_new (display, args [1]);
-}
-
-/**
- * Returns the receiver's border width.
- *
- * @return the border width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getBorderWidth () {
- checkWidget();
- int topHandle = topHandle ();
- int [] args = {
- OS.Pt_ARG_BASIC_FLAGS, 0, 0,
- OS.Pt_ARG_FLAGS, 0, 0,
-// OS.Pt_ARG_BEVEL_WIDTH, 0, 0,
- };
- OS.PtGetResources (topHandle, args.length / 3, args);
- if ((args [4] & OS.Pt_HIGHLIGHTED) == 0) return 0;
- int border = 0;
- int flags = args [1];
- if ((flags & OS.Pt_ALL_ETCHES) != 0) border++;
- if ((flags & OS.Pt_ALL_OUTLINES) != 0) border++;
- if ((flags & OS.Pt_ALL_INLINES) != 0) border++;
-// if ((flags & OS.Pt_ALL_BEVELS) != 0) border += args [7];
- return border;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null),
- * unless the receiver is a shell. In this case, the location is
- * relative to the display.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- int topHandle = topHandle ();
- PhArea_t area = new PhArea_t ();
- OS.PtWidgetArea (topHandle, area);
- return new Rectangle (area.pos_x, area.pos_y, area.size_w, area.size_h);
-}
-
-/**
- * Returns the receiver's cursor, or null if it has not been set.
- * <p>
- * When the mouse pointer passes over a control its appearance
- * is changed to match the control's cursor.
- * </p>
- *
- * @return the receiver's cursor or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Cursor getCursor () {
- checkWidget ();
- return cursor;
-}
-
-/**
- * Returns <code>true</code> if the receiver is detecting
- * drag gestures, and <code>false</code> otherwise.
- *
- * @return the receiver's drag detect state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public boolean getDragDetect () {
- checkWidget ();
- //TODO - not implemented
- return true;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget ();
- return (state & DISABLED) == 0;
-}
-
-/**
- * Returns layout data which is associated with the receiver.
- *
- * @return the receiver's layout data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Object getLayoutData () {
- checkWidget();
- return layoutData;
-}
-
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @return the receiver's location
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getLocation () {
- checkWidget();
- int topHandle = topHandle ();
- PhArea_t area = new PhArea_t ();
- OS.PtWidgetArea (topHandle, area);
- return new Point (area.pos_x, area.pos_y);
-}
-
-/**
- * Returns the receiver's pop up menu if it has one, or null
- * if it does not. All controls may optionally have a pop up
- * menu that is displayed when the user requests one for
- * the control. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pop up
- * menu is platform specific.
- *
- * @return the receiver's menu
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenu () {
- checkWidget();
- return menu;
-}
-
-/**
- * Returns the receiver's monitor.
- *
- * @return the receiver's monitor
- *
- * @since 3.0
- */
-public Monitor getMonitor () {
- checkWidget();
- Monitor [] monitors = display.getMonitors ();
- if (monitors.length == 1) return monitors [0];
- int index = -1, value = -1;
- Rectangle bounds = getBounds ();
- if (this != getShell ()) {
- bounds = display.map (this.parent, null, bounds);
- }
- for (int i=0; i<monitors.length; i++) {
- Rectangle rect = bounds.intersection (monitors [i].getBounds ());
- int area = rect.width * rect.height;
- if (area > 0 && area > value) {
- index = i;
- value = area;
- }
- }
- if (index >= 0) return monitors [index];
- int centerX = bounds.x + bounds.width / 2, centerY = bounds.y + bounds.height / 2;
- for (int i=0; i<monitors.length; i++) {
- Rectangle rect = monitors [i].getBounds ();
- int x = centerX < rect.x ? rect.x - centerX : centerX > rect.x + rect.width ? centerX - rect.x - rect.width : 0;
- int y = centerY < rect.y ? rect.y - centerY : centerY > rect.y + rect.height ? centerY - rect.y - rect.height : 0;
- int distance = x * x + y * y;
- if (index == -1 || distance < value) {
- index = i;
- value = distance;
- }
- }
- return monitors [index];
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Composite</code>
- * or null when the receiver is a shell that was created with null or
- * a display for a parent.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Composite getParent () {
- checkWidget();
- return parent;
-}
-
-Control [] getPath () {
- int count = 0;
- Shell shell = getShell ();
- Control control = this;
- while (control != shell) {
- count++;
- control = control.parent;
- }
- control = this;
- Control [] result = new Control [count];
- while (control != shell) {
- result [--count] = control;
- control = control.parent;
- }
- return result;
-}
-
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- int topHandle = topHandle ();
- PhArea_t area = new PhArea_t ();
- OS.PtWidgetArea (topHandle, area);
- return new Point (area.size_w, area.size_h);
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-
-/**
- * Returns the region that defines the shape of the control,
- * or null if the control has the default shape.
- *
- * @return the region that defines the shape of the shell (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public Region getRegion () {
- checkWidget ();
- return region;
-}
-
-/**
- * Returns the receiver's shell. For all controls other than
- * shells, this simply returns the control's nearest ancestor
- * shell. Shells return themselves, even if they are children
- * of other shells.
- *
- * @return the receiver's shell
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getParent
- */
-public Shell getShell () {
- checkWidget();
- return parent.getShell ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- int topHandle = topHandle ();
- return (OS.PtWidgetFlags (topHandle) & OS.Pt_DELAY_REALIZE) == 0;
-}
-
-boolean hasFocus () {
- return OS.PtIsFocused (handle) != 0;
-}
-
-void hookEvents () {
- int windowProc = display.windowProc;
- int focusHandle = focusHandle ();
- OS.PtAddFilterCallback (handle, OS.Ph_EV_KEY, windowProc, OS.Ph_EV_KEY);
- OS.PtAddEventHandler (handle, OS.Ph_EV_BUT_PRESS, windowProc, OS.Ph_EV_BUT_PRESS);
- OS.PtAddEventHandler (handle, OS.Ph_EV_BUT_RELEASE, windowProc, OS.Ph_EV_BUT_RELEASE);
- OS.PtAddEventHandler (handle, OS.Ph_EV_PTR_MOTION, windowProc, OS.Ph_EV_PTR_MOTION);
- OS.PtAddEventHandler (handle, OS.Ph_EV_BOUNDARY, windowProc, OS.Ph_EV_BOUNDARY);
- if ((state & GRAB) != 0) {
- OS.PtAddEventHandler (handle, OS.Ph_EV_DRAG, windowProc, OS.Ph_EV_DRAG);
- OS.PtAddCallback (handle, OS.Pt_CB_OUTBOUND, windowProc, OS.Pt_CB_OUTBOUND);
- }
- OS.PtAddCallback (focusHandle, OS.Pt_CB_GOT_FOCUS, windowProc, OS.Pt_CB_GOT_FOCUS);
- OS.PtAddCallback (focusHandle, OS.Pt_CB_LOST_FOCUS, windowProc, OS.Pt_CB_LOST_FOCUS);
-}
-
-int focusHandle () {
- return handle;
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Control</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public int internal_new_GC (GCData data) {
- checkWidget();
- int phGC = OS.PgCreateGC(0); // NOTE: PgCreateGC ignores the parameter
- if (phGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
-
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) == 0) {
- data.style |= style & (mask | SWT.MIRRORED);
- }
- int [] args = {OS.Pt_ARG_COLOR, 0, 0, OS.Pt_ARG_FILL_COLOR, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- data.device = display;
- data.widget = handle;
- int disjoint = OS.PtFindDisjoint( handle );
- if( disjoint != 0 )
- OS.PgSetRegion( OS.PtWidgetRid( disjoint ) );
- data.topWidget = topHandle ();
- data.foreground = args [1];
- data.background = args [4];
- data.font = getFont ();
- return phGC;
-}
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Control</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int phGC, GCData data) {
- checkWidget ();
- OS.PgDestroyGC(phGC);
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * ancestors up to and including the receiver's nearest ancestor
- * shell are enabled. Otherwise, <code>false</code> is returned.
- * A disabled control is typically not selectable from the user
- * interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-
-/**
- * Returns <code>true</code> if the receiver has the user-interface
- * focus, and <code>false</code> otherwise.
- *
- * @return the receiver's focus state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isFocusControl () {
- checkWidget();
- return hasFocus ();
-}
-
-/**
- * Returns <code>true</code> if the underlying operating
- * system supports this reparenting, otherwise <code>false</code>
- *
- * @return <code>true</code> if the widget can be reparented, otherwise <code>false</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isReparentable () {
- checkWidget();
- return false;
-}
-
-boolean isShowing () {
- /*
- * This is not complete. Need to check if the
- * widget is obscurred by a parent or sibling.
- */
- if (!isVisible ()) return false;
- Control control = this;
- while (control != null) {
- Point size = control.getSize ();
- if (size.x == 0 || size.y == 0) {
- return false;
- }
- control = control.parent;
- }
- return true;
- /*
- * Check to see if current damage is included.
- */
-// if (!OS.IsWindowVisible (handle)) return false;
-// int flags = OS.DCX_CACHE | OS.DCX_CLIPCHILDREN | OS.DCX_CLIPSIBLINGS;
-// int hDC = OS.GetDCEx (handle, 0, flags);
-// int result = OS.GetClipBox (hDC, new RECT ());
-// OS.ReleaseDC (handle, hDC);
-// return result != OS.NULLREGION;
-}
-
-boolean isTabGroup () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == this) return true;
- }
- }
- int code = traversalCode (0, null);
- if ((code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) != 0) return false;
- return (code & (SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_TAB_NEXT)) != 0;
-}
-
-boolean isTabItem () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == this) return false;
- }
- }
- int code = traversalCode (0, null);
- return (code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) != 0;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * ancestors up to and including the receiver's nearest ancestor
- * shell are visible. Otherwise, <code>false</code> is returned.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return OS.PtWidgetIsRealized (handle);
-}
-
-void markLayout (boolean changed, boolean all) {
- /* Do nothing */
-}
-
-Decorations menuShell () {
- return parent.menuShell ();
-}
-
-/**
- * Moves the receiver above the specified control in the
- * drawing order. If the argument is null, then the receiver
- * is moved to the top of the drawing order. The control at
- * the top of the drawing order will not be covered by other
- * controls even if they occupy intersecting areas.
- *
- * @param control the sibling control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveBelow
- * @see Composite#getChildren
- */
-public void moveAbove (Control control) {
- checkWidget();
- int topHandle1 = topHandle ();
- if (control == null) {
- OS.PtWidgetToFront (topHandle1);
- OS.PtWindowToFront (topHandle1);
- return;
- }
- if (control.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- int topHandle2 = control.topHandle ();
- OS.PtWidgetInsert (topHandle1, topHandle2, 0);
-}
-
-/**
- * Moves the receiver below the specified control in the
- * drawing order. If the argument is null, then the receiver
- * is moved to the bottom of the drawing order. The control at
- * the bottom of the drawing order will be covered by all other
- * controls which occupy intersecting areas.
- *
- * @param control the sibling control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveAbove
- * @see Composite#getChildren
- */
-public void moveBelow (Control control) {
- checkWidget();
- int topHandle1 = topHandle ();
- if (control == null) {
- if (parent != null) parent.moveToBack (topHandle1);
- OS.PtWindowToBack (topHandle1);
- return;
- }
- if (control.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- int topHandle2 = control.topHandle ();
- OS.PtWidgetInsert (topHandle1, topHandle2, 1);
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeSize(int, int, boolean)
- */
-public void pack () {
- checkWidget();
- pack (true);
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- * <p>
- * If the changed flag is <code>true</code>, it indicates that the receiver's
- * <em>contents</em> have changed, therefore any caches that a layout manager
- * containing the control may have been keeping need to be flushed. When the
- * control is resized, the changed flag will be <code>false</code>, so layout
- * manager caches can be retained.
- * </p>
- *
- * @param changed whether or not the receiver's contents have changed
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeSize(int, int, boolean)
- */
-public void pack (boolean changed) {
- checkWidget();
- setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed));
-}
-
-/**
- * Prints the receiver and all children.
- *
- * @param gc the gc where the drawing occurs
- * @return <code>true</code> if the operation was successful and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean print (GC gc) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- return false;
-}
-
-int Ph_EV_BOUNDARY (int widget, int info) {
- if (info == 0) return OS.Pt_END;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.event == 0) return OS.Pt_END;
- PhEvent_t ev = new PhEvent_t ();
- OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
- int data = OS.PhGetData (cbinfo.event);
- if (data == 0) return OS.Pt_END;
- PhPointerEvent_t pe = new PhPointerEvent_t ();
- OS.memmove (pe, data, PhPointerEvent_t.sizeof);
- switch ((int) ev.subtype) {
- case OS.Ph_EV_PTR_ENTER:
- case OS.Ph_EV_PTR_ENTER_FROM_CHILD:{
- Event event = new Event ();
- event.time = ev.timestamp;
- setMouseState (event, SWT.MouseEnter, pe, ev);
- sendEvent (SWT.MouseEnter, event);
- break;
- }
- case OS.Ph_EV_PTR_LEAVE:
- case OS.Ph_EV_PTR_LEAVE_TO_CHILD: {
- Event event = new Event ();
- event.time = ev.timestamp;
- setMouseState (event, SWT.MouseExit, pe, ev);
- sendEvent (SWT.MouseExit, event);
- break;
- }
- case OS.Ph_EV_PTR_STEADY: {
- Event event = new Event ();
- event.time = ev.timestamp;
- setMouseState (event, SWT.MouseHover, pe, ev);
- postEvent (SWT.MouseHover, event);
- destroyToolTip (toolTipHandle);
- toolTipHandle = createToolTip (toolTipText, handle, getFont ().handle);
- break;
- }
- case OS.Ph_EV_PTR_UNSTEADY:
- destroyToolTip (toolTipHandle);
- toolTipHandle = 0;
- break;
- }
- return OS.Pt_END;
-}
-
-int Ph_EV_BUT_PRESS (int widget, int info) {
- if (info == 0) return OS.Pt_END;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.event == 0) return OS.Pt_END;
- PhEvent_t ev = new PhEvent_t ();
- OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
- if ((ev.processing_flags & OS.Ph_FAKE_EVENT) != 0) {
- return OS.Pt_CONTINUE;
- }
- ev.processing_flags |= OS.Ph_CONSUMED;
- OS.memmove (cbinfo.event, ev, PhEvent_t.sizeof);
- int data = OS.PhGetData (cbinfo.event);
- if (data == 0) return OS.Pt_END;
- PhPointerEvent_t pe = new PhPointerEvent_t ();
- OS.memmove (pe, data, PhPointerEvent_t.sizeof);
- Event event = new Event ();
- event.count = pe.click_count;
- event.time = ev.timestamp;
- setMouseState (event, SWT.MouseDown, pe, ev);
- postEvent (SWT.MouseDown, event);
- if (pe.click_count == 2) {
- Event clickEvent = new Event ();
- clickEvent.count = pe.click_count;
- clickEvent.time = ev.timestamp;
- setMouseState (clickEvent, SWT.MouseDoubleClick, pe, ev);
- postEvent (SWT.MouseDoubleClick, clickEvent);
- }
- if (event.button == 3) {
- Event menuEvent = new Event ();
- menuEvent.x = pe.pos_x;
- menuEvent.y = pe.pos_y;
- sendEvent (SWT.MenuDetect, menuEvent);
- if (menuEvent.doit) {
- if (menu != null && !menu.isDisposed ()) {
- if (menuEvent.x != event.x || menuEvent.y != event.y) {
- menu.setLocation (menuEvent.x, menuEvent.y);
- }
- menu.setVisible (true);
- }
- }
- }
- display.dragStartX = pe.pos_x + ev.translation_x;
- display.dragStartY = pe.pos_y + ev.translation_y;
- /*
- * It is possible that the shell may be
- * disposed at this point. If this happens
- * don't send the activate and deactivate
- * events.
- */
- Shell shell = getShell ();
- if (!shell.isDisposed ()) {
- shell.setActiveControl (this);
- }
- return OS.Pt_CONTINUE;
-}
-
-int Ph_EV_BUT_RELEASE (int widget, int info) {
- if (info == 0) return OS.Pt_END;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.event == 0) return OS.Pt_END;
- PhEvent_t ev = new PhEvent_t ();
- OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
- if ((ev.processing_flags & OS.Ph_FAKE_EVENT) != 0) {
- return OS.Pt_CONTINUE;
- }
- ev.processing_flags |= OS.Ph_CONSUMED;
- OS.memmove (cbinfo.event, ev, PhEvent_t.sizeof);
- if (ev.subtype != OS.Ph_EV_RELEASE_PHANTOM) {
- return OS.Pt_CONTINUE;
- }
- int data = OS.PhGetData (cbinfo.event);
- if (data == 0) return OS.Pt_END;
- PhPointerEvent_t pe = new PhPointerEvent_t ();
- OS.memmove (pe, data, PhPointerEvent_t.sizeof);
- Event event = new Event ();
- event.count = pe.click_count;
- event.time = ev.timestamp;
- setMouseState (event, SWT.MouseUp, pe, ev);
- postEvent (SWT.MouseUp, event);
- return OS.Pt_CONTINUE;
-}
-
-int Ph_EV_DRAG (int widget, int info) {
- if (info == 0) return OS.Pt_END;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.event == 0) return OS.Pt_END;
- PhEvent_t ev = new PhEvent_t ();
- OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
- if ((ev.processing_flags & OS.Ph_FAKE_EVENT) != 0) {
- return OS.Pt_CONTINUE;
- }
- if (ev.subtype != OS.Ph_EV_DRAG_MOTION_EVENT) {
- return OS.Pt_CONTINUE;
- }
- int data = OS.PhGetData (cbinfo.event);
- if (data == 0) return OS.Pt_END;
- PhPointerEvent_t pe = new PhPointerEvent_t ();
- OS.memmove (pe, data, PhPointerEvent_t.sizeof);
- Event event = new Event ();
- event.time = ev.timestamp;
- setMouseState (event, SWT.MouseMove, pe, ev);
- postEvent (SWT.MouseMove, event);
- return OS.Pt_CONTINUE;
-}
-
-int Ph_EV_KEY (int widget, int info) {
- if (!hasFocus ()) return OS.Pt_PROCESS;
- if (info == 0) return OS.Pt_PROCESS;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.event == 0) return OS.Pt_PROCESS;
- PhEvent_t ev = new PhEvent_t ();
- OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
- if ((ev.processing_flags & OS.Ph_FAKE_EVENT) != 0) {
- return OS.Pt_PROCESS;
- }
- int data = OS.PhGetData (cbinfo.event);
- if (data == 0) return OS.Pt_PROCESS;
- PhKeyEvent_t ke = new PhKeyEvent_t ();
- OS.memmove (ke, data, PhKeyEvent_t.sizeof);
-
- /*
- * Feature in Photon. When the user presses certain keys
- * (such as the arrow keys), Photon sends 2 event for one
- * key press. The first event has only the scan code while
- * the second has the keysym and other information. This
- * also happens for key release. The fix is to ignore the
- * first event.
- */
- if (ke.key_flags == OS.Pk_KF_Scan_Valid) {
- return OS.Pt_PROCESS;
- }
-
- /* Ignore repeating modifier keys */
- if ((ke.key_flags & OS.Pk_KF_Key_Repeat) != 0) {
- if ((ke.key_flags & OS.Pk_KF_Sym_Valid) != 0) {
- switch (ke.key_sym) {
- case OS.Pk_Alt_L:
- case OS.Pk_Alt_R:
- case OS.Pk_Control_L:
- case OS.Pk_Control_R:
- case OS.Pk_Shift_L:
- case OS.Pk_Shift_R:
- return OS.Pt_PROCESS;
- }
- }
- }
-
- /* Determine event type */
- int type = SWT.KeyUp;
- if ((ke.key_flags & (OS.Pk_KF_Key_Down | OS.Pk_KF_Key_Repeat)) != 0) {
- type = SWT.KeyDown;
- }
-
- /* Determine if this is a traverse event */
- if (type == SWT.KeyDown) {
- /*
- * Fetuare in Photon. The key_sym value is not valid when Ctrl
- * or Alt is pressed. The fix is to detect this case and try to
- * use the key_cap value.
- */
- int key = ke.key_sym;
- if ((ke.key_flags & OS.Pk_KF_Sym_Valid) == 0) {
- key = 0;
- if ((ke.key_flags & OS.Pk_KF_Cap_Valid) != 0) {
- if (ke.key_cap == OS.Pk_Tab && (ke.key_mods & OS.Pk_KM_Ctrl) != 0) {
- key = OS.Pk_Tab;
- }
- }
- }
-
- switch (key) {
- case OS.Pk_Escape:
- case OS.Pk_Return:
- case OS.Pk_KP_Tab:
- case OS.Pk_Tab:
- case OS.Pk_Up:
- case OS.Pk_Down:
- case OS.Pk_Left:
- case OS.Pk_Right:
- case OS.Pk_Pg_Up:
- case OS.Pk_Pg_Down: {
- if (key != OS.Pk_Return) {
- ev.processing_flags |= OS.Ph_NOT_CUAKEY;
- OS.memmove (cbinfo.event, ev, PhEvent_t.sizeof);
- }
- if (translateTraversal (key, ke)) {
- ev.processing_flags |= OS.Ph_CONSUMED;
- OS.memmove (cbinfo.event, ev, PhEvent_t.sizeof);
- return OS.Pt_PROCESS;
- }
- // widget could be disposed at this point
- if (isDisposed ()) return OS.Pt_CONSUME;
- }
- }
- }
-
- Event event = new Event ();
- event.time = ev.timestamp;
- if (!setKeyState (event, type, ke)) return OS.Pt_PROCESS;
- if (type == SWT.KeyDown) {
- display.lastKey = event.keyCode;
- display.lastAscii = event.character;
- } else {
- if (event.keyCode == 0) event.keyCode = display.lastKey;
- if (event.character == 0) event.character = (char) display.lastAscii;
- }
- sendEvent (type, event);
- // widget could be disposed at this point
- if (isDisposed ()) return OS.Pt_CONSUME;
- return event.doit ? OS.Pt_PROCESS :OS.Pt_CONSUME;
-}
-
-int Ph_EV_PTR_MOTION (int widget, int info) {
- if (info == 0) return OS.Pt_END;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.event == 0) return OS.Pt_END;
- PhEvent_t ev = new PhEvent_t ();
- OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
- if ((ev.processing_flags & OS.Ph_FAKE_EVENT) != 0) {
- return OS.Pt_CONTINUE;
- }
- ev.processing_flags |= OS.Ph_CONSUMED;
- OS.memmove (cbinfo.event, ev, PhEvent_t.sizeof);
- if (ev.type == OS.Ph_EV_PTR_MOTION_BUTTON) {
- if ((state & CANVAS) != 0) return OS.Pt_CONTINUE;
- }
- int data = OS.PhGetData (cbinfo.event);
- if (data == 0) return OS.Pt_END;
- PhPointerEvent_t pe = new PhPointerEvent_t ();
- OS.memmove (pe, data, PhPointerEvent_t.sizeof);
- Event event = new Event ();
- event.time = ev.timestamp;
- setMouseState (event, SWT.MouseMove, pe, ev);
- postEvent (SWT.MouseMove, event);
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_GOT_FOCUS (int widget, int info) {
- Shell shell = getShell ();
- sendEvent (SWT.FocusIn);
- if (isDisposed ()) return OS.Pt_CONTINUE;
-
- /*
- * It is possible that the shell may be
- * disposed at this point. If this happens
- * don't send the activate and deactivate
- * events.
- */
- if (!shell.isDisposed ()) {
- shell.setActiveControl (this);
- }
-
- /*
- * Feature in Photon. Cannot return Pt_END
- * or the text widget will not take focus.
- */
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_LOST_FOCUS (int widget, int info) {
- Shell shell = getShell ();
- sendEvent (SWT.FocusOut);
- if (isDisposed ()) return OS.Pt_CONTINUE;
-
- /*
- * It is possible that the shell may be
- * disposed at this point. If this happens
- * don't send the activate and deactivate
- * events.
- */
- if (!shell.isDisposed ()) {
- Display display = shell.display;
- Control control = display.getFocusControl ();
- if (control == null || shell != control.getShell () ) {
- shell.setActiveControl (null);
- }
- }
-
- /*
- * Feature in Photon. Cannot return Pt_END
- * or the text widget will not take focus.
- */
- return OS.Pt_CONTINUE;
-}
-
-void realizeWidget() {
- int parentHandle = parent.handle;
- if (OS.PtWidgetIsRealized (parentHandle)) {
- OS.PtRealizeWidget (topHandle ());
- }
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- parent.removeControl (this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (toolTipHandle != 0) destroyToolTip (toolTipHandle);
- toolTipHandle = 0;
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- menu = null;
- cursor = null;
- layoutData = null;
- region = null;
-}
-
-/**
- * Causes the entire bounds of the receiver to be marked
- * as needing to be redrawn. The next time a paint request
- * is processed, the control will be completely painted,
- * including the background.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #update()
- * @see PaintListener
- * @see SWT#Paint
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#DOUBLE_BUFFERED
- */
-public void redraw () {
- checkWidget();
- OS.PtDamageWidget (handle);
-}
-
-/**
- * Causes the rectangular area of the receiver specified by
- * the arguments to be marked as needing to be redrawn.
- * The next time a paint request is processed, that area of
- * the receiver will be painted, including the background.
- * If the <code>all</code> flag is <code>true</code>, any
- * children of the receiver which intersect with the specified
- * area will also paint their intersecting areas. If the
- * <code>all</code> flag is <code>false</code>, the children
- * will not be painted.
- *
- * @param x the x coordinate of the area to draw
- * @param y the y coordinate of the area to draw
- * @param width the width of the area to draw
- * @param height the height of the area to draw
- * @param all <code>true</code> if children should redraw, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #update()
- * @see PaintListener
- * @see SWT#Paint
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#DOUBLE_BUFFERED
- */
-public void redraw (int x, int y, int width, int height, boolean allChildren) {
- checkWidget ();
- if (width <= 0 || height <= 0) return;
- PhRect_t rect = new PhRect_t ();
- rect.ul_x = (short) x;
- rect.ul_y = (short) y;
- rect.lr_x = (short) (x + width - 1);
- rect.lr_y = (short) (y + height - 1);
- OS.PtDamageExtent (handle, rect);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when a drag gesture occurs.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @since 3.3
- */
-public void removeDragDetectListener(DragDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.DragDetect, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control gains or loses focus.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see FocusListener
- * @see #addFocusListener
- */
-public void removeFocusListener(FocusListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.FocusIn, listener);
- eventTable.unhook (SWT.FocusOut, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #addKeyListener
- */
-public void removeKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.KeyUp, listener);
- eventTable.unhook (SWT.KeyDown, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the platform-specific context menu trigger has
- * occurred.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #addMenuDetectListener
- *
- * @since 3.3
- */
-public void removeMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MenuDetect, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when mouse buttons are pressed and released.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseListener
- * @see #addMouseListener
- */
-public void removeMouseListener (MouseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseDown, listener);
- eventTable.unhook (SWT.MouseUp, listener);
- eventTable.unhook (SWT.MouseDoubleClick, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse moves.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseMoveListener
- * @see #addMouseMoveListener
- */
-public void removeMouseMoveListener(MouseMoveListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseMove, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse passes or hovers over controls.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseTrackListener
- * @see #addMouseTrackListener
- */
-public void removeMouseTrackListener(MouseTrackListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseEnter, listener);
- eventTable.unhook (SWT.MouseExit, listener);
- eventTable.unhook (SWT.MouseHover, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse wheel is scrolled.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseWheelListener
- * @see #addMouseWheelListener
- *
- * @since 3.3
- */
-public void removeMouseWheelListener (MouseWheelListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseWheel, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver needs to be painted.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see PaintListener
- * @see #addPaintListener
- */
-public void removePaintListener(PaintListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Paint, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when traversal events occur.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TraverseListener
- * @see #addTraverseListener
- */
-public void removeTraverseListener(TraverseListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Traverse, listener);
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- int topHandle = topHandle ();
- PhArea_t area = new PhArea_t ();
- OS.PtWidgetArea (topHandle, area);
- width = Math.max (width, 0);
- height = Math.max (height, 0);
- boolean sameOrigin = x == area.pos_x && y == area.pos_y;
- boolean sameExtent = width == area.size_w && height == area.size_h;
- if (move && resize) {
- if (sameOrigin && sameExtent) return 0;
- area.pos_x = (short) x;
- area.pos_y = (short) y;
- area.size_w = (short) width;
- area.size_h = (short) height;
- int ptr = OS.malloc (PhArea_t.sizeof);
- OS.memmove (ptr, area, PhArea_t.sizeof);
- OS.PtSetResource (topHandle, OS.Pt_ARG_AREA, ptr, 0);
- OS.free (ptr);
- } else {
- if (move) {
- if (sameOrigin) return 0;
- PhPoint_t pt = new PhPoint_t ();
- pt.x = (short) x;
- pt.y = (short) y;
- int ptr = OS.malloc (PhPoint_t.sizeof);
- OS.memmove (ptr, pt, PhPoint_t.sizeof);
- OS.PtSetResource (topHandle, OS.Pt_ARG_POS, ptr, 0);
- OS.free (ptr);
- } else if (resize) {
- if (sameExtent) return 0;
- int [] args = {
- OS.Pt_ARG_WIDTH, width, 0,
- OS.Pt_ARG_HEIGHT, height, 0,
- };
- OS.PtSetResources (topHandle, args.length / 3, args);
- }
- }
- if (!OS.PtWidgetIsRealized (topHandle)) {
- OS.PtExtentWidgetFamily (topHandle);
- }
- int result = 0;
- if (move && !sameOrigin) {
- sendEvent (SWT.Move);
- result |= MOVED;
- }
- if (resize && !sameExtent) {
- sendEvent (SWT.Resize);
- result |= RESIZED;
- }
- return result;
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the arguments. The <code>x</code> and
- * <code>y</code> arguments are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the <code>x</code>
- * and <code>y</code> arguments are relative to the display.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (int x, int y, int width, int height) {
- checkWidget();
- setBounds (x, y, width, height, true, true, true);
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the argument. The <code>x</code> and
- * <code>y</code> fields of the rectangle are relative to
- * the receiver's parent (or its display if its parent is null).
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param rect the new bounds for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (Rectangle rect) {
- if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * If the argument is <code>true</code>, causes the receiver to have
- * all mouse events delivered to it until the method is called with
- * <code>false</code> as the argument. Note that on some platforms,
- * a mouse button must currently be down for capture to be assigned.
- *
- * @param capture <code>true</code> to capture the mouse, and <code>false</code> to release it
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCapture (boolean capture) {
- checkWidget();
-}
-
-/**
- * Sets the receiver's cursor to the cursor specified by the
- * argument, or to the default cursor for that kind of control
- * if the argument is null.
- * <p>
- * When the mouse pointer passes over a control its appearance
- * is changed to match the control's cursor.
- * </p>
- *
- * @param cursor the new cursor (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCursor (Cursor cursor) {
- checkWidget();
- int type = OS.Ph_CURSOR_INHERIT;
- int bitmap = 0;
- if (cursor != null) {
- if (cursor.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- type = cursor.type;
- bitmap = cursor.bitmap;
- }
- this.cursor = cursor;
- int [] args = new int []{
- OS.Pt_ARG_CURSOR_TYPE, type, 0,
- OS.Pt_ARG_BITMAP_CURSOR, bitmap, 0,
- };
- OS.PtSetResources (handle, args.length / 3, args);
-
- /*
- * Bug in Photon. For some reason, the widget cursor will
- * not change, when the new cursor is a bitmap cursor, if
- * the flag Ph_CURSOR_NO_INHERIT is reset. The fix is to reset
- * this flag after changing the cursor type to Ph_CURSOR_BITMAP.
- */
- if (type == OS.Ph_CURSOR_BITMAP) {
- type &= ~OS.Ph_CURSOR_NO_INHERIT;
- OS.PtSetResource (handle, OS.Pt_ARG_CURSOR_TYPE, type, 0);
- }
-}
-
-/**
- * Sets the receiver's drag detect state. If the argument is
- * <code>true</code>, the receiver will detect drag gestures,
- * otherwise these gestures will be ignored.
- *
- * @param dragDetect the new drag detect state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public void setDragDetect (boolean dragDetect) {
- checkWidget ();
- //TODO - not implemented
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget ();
- if (enabled) {
- if ((state & DISABLED) == 0) return;
- state &= ~DISABLED;
- } else {
- if ((state & DISABLED) != 0) return;
- state |= DISABLED;
- }
- enableWidget (enabled);
-}
-
-/**
- * Causes the receiver to have the <em>keyboard focus</em>,
- * such that all keyboard events will be delivered to it. Focus
- * reassignment will respect applicable platform constraints.
- *
- * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #forceFocus
- */
-public boolean setFocus () {
- checkWidget();
- if ((style & SWT.NO_FOCUS) != 0) return false;
- return forceFocus ();
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the control
- * if the argument is null.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on Windows the background of a Button cannot be changed.
- * </p>
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBackground (Color color) {
- checkWidget();
- int pixel;
- if (color == null) {
- pixel = defaultBackground ();
- } else {
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- pixel = color.handle;
- }
- setBackgroundPixel (pixel);
-}
-
-/**
- * Sets the receiver's background image to the image specified
- * by the argument, or to the default system color for the control
- * if the argument is null. The background image is tiled to fill
- * the available space.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on Windows the background of a Button cannot be changed.
- * </p>
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument is not a bitmap</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setBackgroundImage (Image image) {
- checkWidget ();
- if (image != null) {
- if (image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (image.type != SWT.BITMAP) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (backgroundImage == image) return;
- backgroundImage = image;
-}
-
-void setBackgroundPixel (int pixel) {
- OS.PtSetResource (handle, OS.Pt_ARG_FILL_COLOR, pixel, 0);
-}
-
-void setDefaultFont () {
- if (display.defaultFont != null) setFont (defaultFont ());
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * to the font specified by the argument, or to the default font for that
- * kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkWidget();
- byte[] buffer;
- if (font != null) {
- if (font.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- buffer = font.handle;
- } else {
- buffer = defaultFont ();
- }
- this.font = font;
- setFont (buffer);
-}
-
-void setFont (byte [] font) {
- int ptr = OS.malloc (font.length);
- OS.memmove (ptr, font, font.length);
- setFont (ptr);
- OS.free (ptr);
-}
-
-void setFont (int font) {
- int [] args = {
- OS.Pt_ARG_TEXT_FONT, font, 0,
- OS.Pt_ARG_LIST_FONT, font, 0,
- OS.Pt_ARG_TITLE_FONT, font, 0,
- OS.Pt_ARG_GAUGE_FONT, font, 0,
- };
- OS.PtSetResources (handle, args.length / 3, args);
-}
-
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the control
- * if the argument is null.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * </p>
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setForeground (Color color) {
- checkWidget();
- int pixel;
- if (color == null) {
- pixel = defaultForeground ();
- } else {
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- pixel = color.handle;
- }
- setForegroundPixel (pixel);
-}
-
-void setForegroundPixel (int pixel) {
- OS.PtSetResource (handle, OS.Pt_ARG_COLOR, pixel, 0);
-}
-
-/**
- * Sets the layout data associated with the receiver to the argument.
- *
- * @param layoutData the new layout data for the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLayoutData (Object layoutData) {
- checkWidget();
- this.layoutData = layoutData;
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget();
- setBounds (x, y, 0, 0, true, false, true);
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @param location the new location for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (Point location) {
- checkWidget();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-/**
- * Sets the receiver's pop up menu to the argument.
- * All controls may optionally have a pop up
- * menu that is displayed when the user requests one for
- * the control. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pop up
- * menu is platform specific.
- * <p>
- * Note: Disposing of a control that has a pop up menu will
- * dispose of the menu. To avoid this behavior, set the
- * menu to null before the control is disposed.
- * </p>
- *
- * @param menu the new pop up menu
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenu (Menu menu) {
- checkWidget();
- int flags = 0;
- if (menu != null) {
- if (menu.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- flags = OS.Pt_MENUABLE;
- }
- OS.PtSetResource (handle, OS.Pt_ARG_FLAGS, flags, OS.Pt_ALL_BUTTONS | OS.Pt_MENUABLE);
- this.menu = menu;
-}
-
-/**
- * Changes the parent of the widget to be the one provided if
- * the underlying operating system supports this feature.
- * Returns <code>true</code> if the parent is successfully changed.
- *
- * @param parent the new parent for the control.
- * @return <code>true</code> if the parent is changed and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * <li>ERROR_NULL_ARGUMENT - if the parent is <code>null</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean setParent (Composite parent) {
- checkWidget();
- if (parent.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return false;
-}
-
-/**
- * Sets the receiver's size to the point specified by the argument.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause them to be
- * set to zero instead.
- * </p>
- *
- * @param size the new size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (Point size) {
- checkWidget();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSize (size.x, size.y);
-}
-
-boolean setTabGroupFocus () {
- return setTabItemFocus ();
-}
-
-boolean setTabItemFocus () {
- if (!isShowing ()) return false;
- return forceFocus ();
-}
-
-boolean setRadioSelection (boolean value) {
- return false;
-}
-
-/**
- * If the argument is <code>false</code>, causes subsequent drawing
- * operations in the receiver to be ignored. No drawing of any kind
- * can occur in the receiver until the flag is set to true.
- * Graphics operations that occurred while the flag was
- * <code>false</code> are lost. When the flag is set to <code>true</code>,
- * the entire widget is marked as needing to be redrawn. Nested calls
- * to this method are stacked.
- * <p>
- * Note: This operation is a hint and may not be supported on some
- * platforms or for some widgets.
- * </p>
- *
- * @param redraw the new redraw state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #redraw(int, int, int, int, boolean)
- * @see #update()
- */
-public void setRedraw (boolean redraw) {
- checkWidget();
- if (redraw) {
- OS.PtContainerRelease (handle);
- } else {
- OS.PtContainerHold (handle);
- }
-}
-
-/**
- * Sets the shape of the control to the region specified
- * by the argument. When the argument is null, the
- * default shape of the control is restored.
- *
- * @param region the region that defines the shape of the control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setRegion (Region region) {
- checkWidget ();
- if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- // TODO implement setRegion
- this.region = region;
-}
-/**
- * Sets the receiver's size to the point specified by the arguments.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (int width, int height) {
- checkWidget();
- setBounds (0, 0, width, height, false, true, true);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- int topHandle = topHandle ();
- int oldFlags = OS.PtWidgetFlags (topHandle);
- int flags = visible ? 0 : OS.Pt_DELAY_REALIZE;
- OS.PtSetResource (topHandle, OS.Pt_ARG_FLAGS, flags, OS.Pt_DELAY_REALIZE);
- if ((oldFlags & OS.Pt_DELAY_REALIZE) == flags) return;
- if (visible) {
- sendEvent (SWT.Show);
- if (isDisposed ()) return;
- OS.PtRealizeWidget (topHandle);
- } else {
- OS.PtUnrealizeWidget (topHandle);
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the FocusOut
- * event that is triggered by PtUnrealizeWidget if the widget
- * being hidden has focus. If this happens, just return.
- */
- if (isDisposed ()) return;
- sendEvent(SWT.Hide);
- }
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
-}
-
-void setZOrder() {
- if (parent != null) parent.moveToBack (topHandle ());
-}
-
-void sort (int [] items) {
- /* Shell Sort from K&R, pg 108 */
- int length = items.length;
- for (int gap=length/2; gap>0; gap/=2) {
- for (int i=gap; i<length; i++) {
- for (int j=i-gap; j>=0; j-=gap) {
- if (items [j] <= items [j + gap]) {
- int swap = items [j];
- items [j] = items [j + gap];
- items [j + gap] = swap;
- }
- }
- }
- }
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in display relative coordinates,
- * to coordinates relative to the receiver.
- * <p>
- * @param x the x coordinate to be translated
- * @param y the y coordinate to be translated
- * @return the translated coordinates
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public Point toControl (int x, int y) {
- checkWidget();
- short [] position_x = new short [1], position_y = new short [1];
- OS.PtGetAbsPosition (handle, position_x, position_y);
- return new Point (x - position_x [0], y - position_y [0]);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in display relative coordinates,
- * to coordinates relative to the receiver.
- * <p>
- * @param point the point to be translated (must not be null)
- * @return the translated coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point toControl (Point point) {
- checkWidget();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return toControl (point.x, point.y);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in coordinates relative to
- * the receiver, to display relative coordinates.
- * <p>
- * @param x the x coordinate to be translated
- * @param y the y coordinate to be translated
- * @return the translated coordinates
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public Point toDisplay (int x, int y) {
- checkWidget();
- short [] position_x = new short [1], position_y = new short [1];
- OS.PtGetAbsPosition (handle, position_x, position_y);
- return new Point (x + position_x [0], y + position_y [0]);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in coordinates relative to
- * the receiver, to display relative coordinates.
- * <p>
- * @param point the point to be translated (must not be null)
- * @return the translated coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point toDisplay (Point point) {
- checkWidget();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return toDisplay (point.x, point.y);
-}
-
-boolean translateTraversal (int key_sym, PhKeyEvent_t phEvent) {
- int detail = SWT.TRAVERSE_NONE;
- int code = traversalCode (key_sym, phEvent);
- boolean all = false;
- switch (key_sym) {
- case OS.Pk_Escape: {
- all = true;
- detail = SWT.TRAVERSE_ESCAPE;
- break;
- }
- case OS.Pk_Return: {
- all = true;
- detail = SWT.TRAVERSE_RETURN;
- break;
- }
- case OS.Pk_Tab:
- case OS.Pk_KP_Tab: {
- boolean next = (phEvent.key_mods & OS.Pk_KM_Shift) == 0;
- detail = next ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS;
- break;
- }
- case OS.Pk_Up:
- case OS.Pk_Left: {
- detail = SWT.TRAVERSE_ARROW_PREVIOUS;
- break;
- }
- case OS.Pk_Down:
- case OS.Pk_Right: {
- detail = SWT.TRAVERSE_ARROW_NEXT;
- break;
- }
- case OS.Pk_Pg_Down:
- case OS.Pk_Pg_Up: {
- all = true;
- if ((phEvent.key_mods & OS.Pk_KM_Ctrl) == 0) return false;
- detail = key_sym == OS.Pk_Pg_Down ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS;
- break;
- }
- default:
- return false;
- }
- Event event = new Event ();
- event.doit = (code & detail) != 0;
- event.detail = detail;
- if (!setKeyState (event, SWT.Traverse, phEvent)) return false;
- Shell shell = getShell ();
- Control control = this;
- do {
- if (control.traverse (event)) return true;
- if (!event.doit && control.hooks (SWT.Traverse)) {
- return false;
- }
- if (control == shell) return false;
- control = control.parent;
- } while (all && control != null);
- return false;
-}
-
-int traversalCode (int key_sym, PhKeyEvent_t ke) {
-// if ((OS.PtWidgetFlags (handle) & OS.Pt_GETS_FOCUS) == 0) return 0;
- int code = SWT.TRAVERSE_RETURN | SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS;
- Shell shell = getShell ();
- if (shell.parent != null) code |= SWT.TRAVERSE_ESCAPE;
- return code;
-}
-
-boolean traverse (Event event) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the traverse
- * event. If this happens, return true to stop further
- * event processing.
- */
- sendEvent (SWT.Traverse, event);
- if (isDisposed ()) return true;
- if (!event.doit) return false;
- switch (event.detail) {
- case SWT.TRAVERSE_NONE: return true;
- case SWT.TRAVERSE_ESCAPE: return traverseEscape ();
- case SWT.TRAVERSE_RETURN: return traverseReturn ();
- case SWT.TRAVERSE_TAB_NEXT: return traverseGroup (true);
- case SWT.TRAVERSE_TAB_PREVIOUS: return traverseGroup (false);
- case SWT.TRAVERSE_ARROW_NEXT: return traverseItem (true);
- case SWT.TRAVERSE_ARROW_PREVIOUS: return traverseItem (false);
- case SWT.TRAVERSE_MNEMONIC: return traverseMnemonic (event.character);
- case SWT.TRAVERSE_PAGE_NEXT: return traversePage (true);
- case SWT.TRAVERSE_PAGE_PREVIOUS: return traversePage (false);
- }
- return false;
-}
-
-/**
- * Based on the argument, perform one of the expected platform
- * traversal action. The argument should be one of the constants:
- * <code>SWT.TRAVERSE_ESCAPE</code>, <code>SWT.TRAVERSE_RETURN</code>,
- * <code>SWT.TRAVERSE_TAB_NEXT</code>, <code>SWT.TRAVERSE_TAB_PREVIOUS</code>,
- * <code>SWT.TRAVERSE_ARROW_NEXT</code> and <code>SWT.TRAVERSE_ARROW_PREVIOUS</code>.
- *
- * @param traversal the type of traversal
- * @return true if the traversal succeeded
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean traverse (int traversal) {
- checkWidget ();
- Event event = new Event ();
- event.doit = true;
- event.detail = traversal;
- return traverse (event);
-}
-
-boolean traverseEscape () {
- return false;
-}
-
-boolean traverseGroup (boolean next) {
- Control root = computeTabRoot ();
- Control group = computeTabGroup ();
- Control [] list = root.computeTabList ();
- int length = list.length;
- int index = 0;
- while (index < length) {
- if (list [index] == group) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- if (index == length) return false;
- int start = index, offset = (next) ? 1 : -1;
- while ((index = ((index + offset + length) % length)) != start) {
- Control control = list [index];
- if (!control.isDisposed () && control.setTabGroupFocus ()) {
- return true;
- }
- }
- if (group.isDisposed ()) return false;
- return group.setTabGroupFocus ();
-}
-
-boolean traverseItem (boolean next) {
- Control [] children = parent._getChildren ();
- int length = children.length;
- int index = 0;
- while (index < length) {
- if (children [index] == this) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- if (index == length) return false;
- int start = index, offset = (next) ? 1 : -1;
- while ((index = (index + offset + length) % length) != start) {
- Control child = children [index];
- if (!child.isDisposed () && child.isTabItem ()) {
- if (child.setTabItemFocus ()) return true;
- }
- }
- return false;
-}
-
-boolean traversePage (boolean next) {
- return false;
-}
-
-boolean traverseMnemonic (char key) {
-// return mnemonicHit (key);
- return false;
-}
-
-boolean traverseReturn () {
- return false;
-}
-
-/**
- * Forces all outstanding paint requests for the widget
- * to be processed before this method returns. If there
- * are no outstanding paint request, this method does
- * nothing.
- * <p>
- * Note: This method does not cause a redraw.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #redraw()
- * @see #redraw(int, int, int, int, boolean)
- * @see PaintListener
- * @see SWT#Paint
- */
-public void update () {
- checkWidget();
- OS.PtFlush ();
-}
-
-void updateLayout (boolean all) {
- /* Do nothing */
-}
-
-int widgetClass () {
- return 0;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Decorations.java
deleted file mode 100755
index cab73999ad..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Decorations.java
+++ /dev/null
@@ -1,634 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide the appearance and
- * behavior of <code>Shells</code>, but are not top
- * level shells or dialogs. Class <code>Shell</code>
- * shares a significant amount of code with this class,
- * and is a subclass.
- * <p>
- * IMPORTANT: This class was intended to be abstract and
- * should <em>never</em> be referenced or instantiated.
- * Instead, the class <code>Shell</code> should be used.
- * </p>
- * <p>
- * Instances are always displayed in one of the maximized,
- * minimized or normal states:
- * <ul>
- * <li>
- * When an instance is marked as <em>maximized</em>, the
- * window manager will typically resize it to fill the
- * entire visible area of the display, and the instance
- * is usually put in a state where it can not be resized
- * (even if it has style <code>RESIZE</code>) until it is
- * no longer maximized.
- * </li><li>
- * When an instance is in the <em>normal</em> state (neither
- * maximized or minimized), its appearance is controlled by
- * the style constants which were specified when it was created
- * and the restrictions of the window manager (see below).
- * </li><li>
- * When an instance has been marked as <em>minimized</em>,
- * its contents (client area) will usually not be visible,
- * and depending on the window manager, it may be
- * "iconified" (that is, replaced on the desktop by a small
- * simplified representation of itself), relocated to a
- * distinguished area of the screen, or hidden. Combinations
- * of these changes are also possible.
- * </li>
- * </ul>
- * </p>
- * Note: The styles supported by this class must be treated
- * as <em>HINT</em>s, since the window manager for the
- * desktop on which the instance is visible has ultimate
- * control over the appearance and behavior of decorations.
- * For example, some window managers only support resizable
- * windows and will always assume the RESIZE style, even if
- * it is not set.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * Class <code>SWT</code> provides two "convenience constants"
- * for the most commonly required style combinations:
- * <dl>
- * <dt><code>SHELL_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application top level shell: (that
- * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>)
- * </dd>
- * <dt><code>DIALOG_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application dialog shell: (that
- * is, <code>TITLE | CLOSE | BORDER</code>)
- * </dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see #getMinimized
- * @see #getMaximized
- * @see Shell
- * @see SWT
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Decorations extends Canvas {
- Menu menuBar;
- Menu [] menus;
- String text = "";
- Image image;
- Image [] images = new Image [0];
- Button defaultButton, saveDefault;
-
-Decorations () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#TOOL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Decorations (Composite parent, int style) {
- super (parent, style);
-}
-
-static int checkStyle (int style) {
- if ((style & SWT.NO_TRIM) != 0) {
- style &= ~(SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX | SWT.RESIZE | SWT.BORDER);
- }
- if ((style & (SWT.MENU | SWT.MIN | SWT.MAX | SWT.CLOSE)) != 0) {
- style |= SWT.TITLE;
- }
- return style;
-}
-
-void add (Menu menu) {
- if (menus == null) menus = new Menu [4];
- for (int i=0; i<menus.length; i++) {
- if (menus [i] == null) {
- menus [i] = menu;
- return;
- }
- }
- Menu [] newMenus = new Menu [menus.length + 4];
- newMenus [menus.length] = menu;
- System.arraycopy (menus, 0, newMenus, 0, menus.length);
- menus = newMenus;
-}
-
-void bringToTop (boolean force) {
- moveAbove (null);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-Control computeTabGroup () {
- return this;
-}
-
-Control computeTabRoot () {
- return this;
-}
-
-/**
- * Returns the receiver's default button if one had
- * previously been set, otherwise returns null.
- *
- * @return the default button or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDefaultButton(Button)
- */
-public Button getDefaultButton () {
- checkWidget();
- return defaultButton;
-}
-
-/**
- * Returns the receiver's image if it had previously been
- * set using <code>setImage()</code>. The image is typically
- * displayed by the window manager when the instance is
- * marked as iconified, and may also be displayed somewhere
- * in the trim when the instance is in normal or maximized
- * states.
- * <p>
- * Note: This method will return null if called before
- * <code>setImage()</code> is called. It does not provide
- * access to a window manager provided, "default" image
- * even if one exists.
- * </p>
- *
- * @return the image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-
-/**
- * Returns the receiver's images if they had previously been
- * set using <code>setImages()</code>. Images are typically
- * displayed by the window manager when the instance is
- * marked as iconified, and may also be displayed somewhere
- * in the trim when the instance is in normal or maximized
- * states. Depending where the icon is displayed, the platform
- * chooses the icon with the "best" attributes. It is expected
- * that the array will contain the same icon rendered at different
- * sizes, with different depth and transparency attributes.
- *
- * <p>
- * Note: This method will return an empty array if called before
- * <code>setImages()</code> is called. It does not provide
- * access to a window manager provided, "default" image
- * even if one exists.
- * </p>
- *
- * @return the images
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Image [] getImages () {
- checkWidget ();
- if (images == null) return new Image [0];
- Image [] result = new Image [images.length];
- System.arraycopy (images, 0, result, 0, images.length);
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver is currently
- * maximized, and false otherwise.
- * <p>
- *
- * @return the maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMaximized
- */
-public boolean getMaximized () {
- checkWidget();
- return false;
-}
-
-/**
- * Returns <code>true</code> if the receiver is currently
- * minimized, and false otherwise.
- * <p>
- *
- * @return the minimized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMinimized
- */
-public boolean getMinimized () {
- checkWidget();
- return false;
-}
-
-/**
- * Returns the receiver's menu bar if one had previously
- * been set, otherwise returns null.
- *
- * @return the menu bar or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenuBar () {
- checkWidget();
- return menuBar;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which is the string that the
- * window manager will typically display as the receiver's
- * <em>title</em>. If the text has not previously been set,
- * returns an empty string.
- *
- * @return the text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- return text;
-}
-
-boolean hasBorder () {
- return false;
-}
-
-boolean isTabGroup () {
- return true;
-}
-
-boolean isTabItem () {
- return false;
-}
-
-Decorations menuShell () {
- return this;
-}
-
-void releaseChildren (boolean destroy) {
- if (menuBar != null) {
- menuBar.release (false);
- menuBar = null;
- }
- super.releaseChildren (destroy);
- if (menus != null) {
- for (int i=0; i<menus.length; i++) {
- Menu menu = menus [i];
- if (menu != null && !menu.isDisposed ()) {
- menu.release (false);
- }
- }
- menus = null;
- }
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- image = null;
- images = null;
- defaultButton = saveDefault = null;
- text = null;
-}
-
-void remove (Menu menu) {
- if (menus == null) return;
- for (int i=0; i<menus.length; i++) {
- if (menus [i] == menu) {
- menus [i] = null;
- return;
- }
- }
-}
-
-void resizeBounds (int width, int height) {
- int menuHeight = 0;
- if (menuBar != null) {
- PhDim_t dim = new PhDim_t ();
- int menuHandle = menuBar.handle;
- if (!OS.PtWidgetIsRealized (menuHandle)) {
- OS.PtExtentWidgetFamily (menuHandle);
- }
- OS.PtWidgetPreferredSize (menuHandle, dim);
- menuHeight = dim.h;
- OS.PtSetResource (menuHandle, OS.Pt_ARG_HEIGHT, menuHeight, 0);
- height = height - menuHeight;
- }
- PhArea_t area = new PhArea_t ();
- area.pos_y = (short) menuHeight;
- area.size_w = (short) Math.max (width, 0);
- area.size_h = (short) Math.max (height ,0);
- int ptr = OS.malloc (PhArea_t.sizeof);
- OS.memmove (ptr, area, PhArea_t.sizeof);
- OS.PtSetResource (scrolledHandle, OS.Pt_ARG_AREA, ptr, 0);
- OS.free (ptr);
- resizeClientArea (width, height, false);
-}
-
-/**
- * If the argument is not null, sets the receiver's default
- * button to the argument, and if the argument is null, sets
- * the receiver's default button to the first button which
- * was set as the receiver's default button (called the
- * <em>saved default button</em>). If no default button had
- * previously been set, or the saved default button was
- * disposed, the receiver's default button will be set to
- * null.
- * <p>
- * The default button is the button that is selected when
- * the receiver is active and the user presses ENTER.
- * </p>
- *
- * @param button the new default button
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the button has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDefaultButton (Button button) {
- checkWidget();
- if (button != null) {
- if (button.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (button.menuShell () != this) error (SWT.ERROR_INVALID_PARENT);
- }
- setDefaultButton (button, true);
-}
-void setDefaultButton (Button button, boolean save) {
- if (button == null) {
- if (defaultButton == saveDefault) {
- if (save) saveDefault = null;
- return;
- }
- } else {
- if ((button.style & SWT.PUSH) == 0) return;
- if (button == defaultButton) return;
- }
- if (defaultButton != null) {
- if (!defaultButton.isDisposed ()) defaultButton.setDefault (false);
- }
- if ((defaultButton = button) == null) defaultButton = saveDefault;
- if (defaultButton != null) {
- if (!defaultButton.isDisposed ()) defaultButton.setDefault (true);
- }
- if (save) saveDefault = defaultButton;
- if (saveDefault != null && saveDefault.isDisposed ()) saveDefault = null;
-}
-
-/**
- * Sets the receiver's image to the argument, which may
- * be null. The image is typically displayed by the window
- * manager when the instance is marked as iconified, and
- * may also be displayed somewhere in the trim when the
- * instance is in normal or maximized states.
- *
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- this.image = image;
-}
-
-/**
- * Sets the receiver's images to the argument, which may
- * be an empty array. Images are typically displayed by the
- * window manager when the instance is marked as iconified,
- * and may also be displayed somewhere in the trim when the
- * instance is in normal or maximized states. Depending where
- * the icon is displayed, the platform chooses the icon with
- * the "best" attributes. It is expected that the array will
- * contain the same icon rendered at different sizes, with
- * different depth and transparency attributes.
- *
- * @param images the new image array
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images is null or has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setImages (Image [] images) {
- checkWidget();
- if (images == null) error(SWT.ERROR_INVALID_ARGUMENT);
- for (int i = 0; i < images.length; i++) {
- if (images [i] == null || images [i].isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.images = images;
-}
-
-/**
- * Sets the maximized state of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the maximized state, and if the argument is
- * <code>false</code> and the receiver was previously maximized,
- * causes the receiver to switch back to either the minimized
- * or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setMaximized(true)</code>
- * and <code>setMinimized(true)</code> will vary by platform. Typically,
- * the behavior will match the platform user's expectations, but not
- * always. This should be avoided if possible.
- * </p>
- *
- * @param maximized the new maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMinimized
- */
-public void setMaximized (boolean maximized) {
- checkWidget();
-}
-
-/**
- * Sets the receiver's menu bar to the argument, which
- * may be null.
- *
- * @param menu the new menu bar
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenuBar (Menu menu) {
- checkWidget();
- if (menu != null && menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- //NOT DONE
-}
-
-/**
- * Sets the minimized stated of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the minimized state, and if the argument is
- * <code>false</code> and the receiver was previously minimized,
- * causes the receiver to switch back to either the maximized
- * or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setMaximized(true)</code>
- * and <code>setMinimized(true)</code> will vary by platform. Typically,
- * the behavior will match the platform user's expectations, but not
- * always. This should be avoided if possible.
- * </p>
- *
- * @param minimized the new maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMaximized
- */
-public void setMinimized (boolean minimized) {
- checkWidget();
-}
-
-/**
- * Sets the receiver's text, which is the string that the
- * window manager will typically display as the receiver's
- * <em>title</em>, to the argument, which must not be null.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- text = string;
-}
-
-boolean traverseReturn () {
- if (defaultButton == null || defaultButton.isDisposed ()) return false;
- if (!defaultButton.isVisible () || !defaultButton.isEnabled ()) return false;
- defaultButton.click ();
- return true;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/DirectoryDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/DirectoryDialog.java
deleted file mode 100755
index 4b48d8b5ce..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/DirectoryDialog.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class allow the user to navigate
- * the file system and select a directory.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#directorydialog">DirectoryDialog snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class DirectoryDialog extends Dialog {
- String message = "", filterPath = "";
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public DirectoryDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public DirectoryDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-/**
- * Returns the path which the dialog will use to filter
- * the directories it shows.
- *
- * @return the filter path
- *
- * @see #setFilterPath
- */
-public String getFilterPath () {
- return filterPath;
-}
-
-/**
- * Returns the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @return the message
- */
-public String getMessage () {
- return message;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a string describing the absolute path of the selected directory,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public String open () {
- int parentHandle = 0;
- if (parent != null && OS.PtWidgetIsRealized(parent.shellHandle)) {
- parentHandle = parent.shellHandle;
- }
- byte [] title = null;
- if (this.title != null) title = Converter.wcsToMbcs (null, this.title, true);
- byte [] root_dir = null;
- if (filterPath != null) {
- root_dir = Converter.wcsToMbcs (null, filterPath, true);
- }
- byte [] file_spec = null;
- int flags = OS.Pt_FSR_NO_FCHECK | OS.Pt_FSR_NO_SELECT_FILES | OS.Pt_FSR_SELECT_DIRS;
- PtFileSelectionInfo_t info = new PtFileSelectionInfo_t ();
- OS.PtFileSelection (parentHandle, null, title, root_dir, file_spec, null, null, null, info, flags);
- if (info.ret == OS.Pt_FSDIALOG_BTN2) return null;
- int length = 0;
- while (length < info.path.length && info.path [length] != 0) length++;
- byte [] path = new byte [length];
- System.arraycopy (info.path, 0, path, 0, length);
- return filterPath = new String (Converter.mbcsToWcs (null, path));
-}
-
-/**
- * Sets the path that the dialog will use to filter
- * the directories it shows to the argument, which may
- * be null. If the string is null, then the operating
- * system's default filter path will be used.
- * <p>
- * Note that the path string is platform dependent.
- * For convenience, either '/' or '\' can be used
- * as a path separator.
- * </p>
- *
- * @param string the filter path
- */
-public void setFilterPath (String string) {
- filterPath = string;
-}
-
-/**
- * Sets the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @param string the message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- */
-public void setMessage (String string) {
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- message = string;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java
deleted file mode 100755
index f94fb76b3c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java
+++ /dev/null
@@ -1,2737 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are responsible for managing the
- * connection between SWT and the underlying operating
- * system. Their most important function is to implement
- * the SWT event loop in terms of the platform event model.
- * They also provide various methods for accessing information
- * about the operating system, and have overall control over
- * the operating system resources which SWT allocates.
- * <p>
- * Applications which are built with SWT will <em>almost always</em>
- * require only a single display. In particular, some platforms
- * which SWT supports will not allow more than one <em>active</em>
- * display. In other words, some platforms do not support
- * creating a new display if one already exists that has not been
- * sent the <code>dispose()</code> message.
- * <p>
- * In SWT, the thread which creates a <code>Display</code>
- * instance is distinguished as the <em>user-interface thread</em>
- * for that display.
- * </p>
- * The user-interface thread for a particular display has the
- * following special attributes:
- * <ul>
- * <li>
- * The event loop for that display must be run from the thread.
- * </li>
- * <li>
- * Some SWT API methods (notably, most of the public methods in
- * <code>Widget</code> and its subclasses), may only be called
- * from the thread. (To support multi-threaded user-interface
- * applications, class <code>Display</code> provides inter-thread
- * communication methods which allow threads other than the
- * user-interface thread to request that it perform operations
- * on their behalf.)
- * </li>
- * <li>
- * The thread is not allowed to construct other
- * <code>Display</code>s until that display has been disposed.
- * (Note that, this is in addition to the restriction mentioned
- * above concerning platform support for multiple displays. Thus,
- * the only way to have multiple simultaneously active displays,
- * even on platforms which support it, is to have multiple threads.)
- * </li>
- * </ul>
- * Enforcing these attributes allows SWT to be implemented directly
- * on the underlying operating system's event model. This has
- * numerous benefits including smaller footprint, better use of
- * resources, safer memory management, clearer program logic,
- * better performance, and fewer overall operating system threads
- * required. The down side however, is that care must be taken
- * (only) when constructing multi-threaded applications to use the
- * inter-thread communication mechanisms which this class provides
- * when required.
- * </p><p>
- * All SWT API methods which may only be called from the user-interface
- * thread are distinguished in their documentation by indicating that
- * they throw the "<code>ERROR_THREAD_INVALID_ACCESS</code>"
- * SWT exception.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Close, Dispose, Settings</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- * @see #syncExec
- * @see #asyncExec
- * @see #wake
- * @see #readAndDispatch
- * @see #sleep
- * @see Device#dispose
- * @see <a href="http://www.eclipse.org/swt/snippets/#display">Display snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Display extends Device {
-
- /* TEMPORARY CODE FOR EMULATED TABLE */
- int textHighlightThickness = 0;
-
- /* TEMPORARY CODE FOR EMBEDDED */
- public boolean embedded;
-
- /* Photon Only Public Fields */
- public int app_context;
-// public int phEventSize = PhEvent_t.sizeof + 1024;
-// public int phEvent = OS.malloc (phEventSize);
-
- /* Deferred Events */
- Event [] eventQueue;
- EventTable eventTable, filterTable;
-
- /* Events Dispatching and Callback */
- Callback windowCallback, drawCallback, workCallback, inputCallback, hotkeyCallback;
- int windowProc, drawProc, workProc, inputProc, hotkeyProc, input, pulse;
- boolean idle;
-
- /* Sync/Async Widget Communication */
- Synchronizer synchronizer = new Synchronizer (this);
- Thread thread;
-
- /* Display Shutdown */
- Runnable [] disposeList;
-
- /* System Tray */
- Tray tray;
-
- /* Drag origin */
- int dragStartX, dragStartY;
-
- /* Timers */
- int [] timerIds;
- Runnable [] timerList;
- Callback timerCallback;
- int timerProc, timerHandle;
-
- /* Keyboard */
- int lastKey, lastAscii;
-
- /* Key Mappings. */
- private static final int [] [] KeyTable = {
-
- /* Keyboard and Mouse Masks */
- {OS.Pk_Alt_L, SWT.ALT},
- {OS.Pk_Alt_R, SWT.ALT},
- {OS.Pk_Shift_L, SWT.SHIFT},
- {OS.Pk_Shift_R, SWT.SHIFT},
- {OS.Pk_Control_L, SWT.CONTROL},
- {OS.Pk_Control_R, SWT.CONTROL},
-// {OS.Pk_????, SWT.COMMAND},
-// {OS.Pk_????, SWT.COMMAND},
-
-// {OS.VK_LBUTTON, SWT.BUTTON1},
-// {OS.VK_MBUTTON, SWT.BUTTON3},
-// {OS.VK_RBUTTON, SWT.BUTTON2},
-
- /* Non-Numeric Keypad Keys */
- {OS.Pk_Up, SWT.ARROW_UP},
- {OS.Pk_Down, SWT.ARROW_DOWN},
- {OS.Pk_Left, SWT.ARROW_LEFT},
- {OS.Pk_Right, SWT.ARROW_RIGHT},
- {OS.Pk_Prior, SWT.PAGE_UP},
- {OS.Pk_Next, SWT.PAGE_DOWN},
- {OS.Pk_Home, SWT.HOME},
- {OS.Pk_End, SWT.END},
- {OS.Pk_Insert, SWT.INSERT},
-
- /* Virtual and Ascii Keys */
- {OS.Pk_BackSpace, SWT.BS},
- {OS.Pk_Return, SWT.CR},
- {OS.Pk_Delete, SWT.DEL},
- {OS.Pk_Escape, SWT.ESC},
- {OS.Pk_Linefeed, SWT.LF},
- {OS.Pk_Tab, SWT.TAB},
- {OS.Pk_KP_Tab, SWT.TAB},
-
- /* Functions Keys */
- {OS.Pk_F1, SWT.F1},
- {OS.Pk_F2, SWT.F2},
- {OS.Pk_F3, SWT.F3},
- {OS.Pk_F4, SWT.F4},
- {OS.Pk_F5, SWT.F5},
- {OS.Pk_F6, SWT.F6},
- {OS.Pk_F7, SWT.F7},
- {OS.Pk_F8, SWT.F8},
- {OS.Pk_F9, SWT.F9},
- {OS.Pk_F10, SWT.F10},
- {OS.Pk_F11, SWT.F11},
- {OS.Pk_F12, SWT.F12},
- {OS.Pk_F13, SWT.F13},
- {OS.Pk_F14, SWT.F14},
- {OS.Pk_F15, SWT.F15},
-
- /* Numeric Keypad Keys */
- {OS.Pk_KP_Multiply, SWT.KEYPAD_MULTIPLY},
- {OS.Pk_KP_Add, SWT.KEYPAD_ADD},
- {OS.Pk_KP_Enter, SWT.KEYPAD_CR},
- {OS.Pk_KP_Subtract, SWT.KEYPAD_SUBTRACT},
- {OS.Pk_KP_Decimal, SWT.KEYPAD_DECIMAL},
- {OS.Pk_KP_Divide, SWT.KEYPAD_DIVIDE},
- {OS.Pk_KP_0, SWT.KEYPAD_0},
- {OS.Pk_KP_1, SWT.KEYPAD_1},
- {OS.Pk_KP_2, SWT.KEYPAD_2},
- {OS.Pk_KP_3, SWT.KEYPAD_3},
- {OS.Pk_KP_4, SWT.KEYPAD_4},
- {OS.Pk_KP_5, SWT.KEYPAD_5},
- {OS.Pk_KP_6, SWT.KEYPAD_6},
- {OS.Pk_KP_7, SWT.KEYPAD_7},
- {OS.Pk_KP_8, SWT.KEYPAD_8},
- {OS.Pk_KP_9, SWT.KEYPAD_9},
- {OS.Pk_KP_Equal, SWT.KEYPAD_EQUAL},
-
- /* Other keys */
- {OS.Pk_Caps_Lock, SWT.CAPS_LOCK},
- {OS.Pk_Num_Lock, SWT.NUM_LOCK},
- {OS.Pk_Scroll_Lock, SWT.SCROLL_LOCK},
- {OS.Pk_Pause, SWT.PAUSE},
- {OS.Pk_Break, SWT.BREAK},
- {OS.Pk_Print, SWT.PRINT_SCREEN},
- {OS.Pk_Help, SWT.HELP},
-
- };
-
- /* Multiple Displays. */
- static Display Default;
- static Display [] Displays = new Display [4];
-
- /* Window Classes */
- int ClassesPtr;
- int PtButton;
- int PtList;
- int PtLabel;
- int PtToggleButton;
- int PtComboBox;
- int PtText;
- int PtMultiText;
- int PtScrollbar;
- int PtContainer;
- int PtProgress;
- int PtPanelGroup;
- int PtSlider;
- int PtSeparator;
- int PtToolbar;
- int PtNumericInteger;
-
- /* Colors */
- int WIDGET_DARK_SHADOW, WIDGET_NORMAL_SHADOW, WIDGET_LIGHT_SHADOW;
- int WIDGET_HIGHLIGHT_SHADOW, WIDGET_BACKGROUND, WIDGET_FOREGROUND, WIDGET_BORDER;
- int LIST_FOREGROUND, LIST_BACKGROUND, LIST_SELECTION, LIST_SELECTION_TEXT;
- int INFO_FOREGROUND, INFO_BACKGROUND, TEXT_FOREGROUND, TEXT_BACKGROUND;
-
- /* Fonts */
- byte [] defaultFont;
- byte [] TEXT_FONT, LIST_FONT, TITLE_FONT, GAUGE_FONT, GROUP_FONT;
-
- /* System Cursors */
- Cursor [] cursors = new Cursor [SWT.CURSOR_HAND + 1];
-
- /* Images */
- int nullImage;
-
- /* ScrollBars */
- int SCROLLBAR_WIDTH;
- int SCROLLBAR_HEIGHT;
- int SCROLLBAR_VERTICAL_BASIC_FLAGS;
- int SCROLLBAR_HORIZONTAL_BASIC_FLAGS;
-
- /* Package name */
- static final String PACKAGE_NAME;
- static {
- String name = Display.class.getName ();
- int index = name.lastIndexOf ('.');
- PACKAGE_NAME = name.substring (0, index + 1);
- }
-
- /* Photon Draw Buffer - shared by all widgets */
- static int DrawBufferSize = 1024 * 48;
-
- /* Display Data */
- Object data;
- String [] keys;
- Object [] values;
-
- /*
- * TEMPORARY CODE. Install the runnable that
- * gets the current display. This code will
- * be removed in the future.
- */
- static {
- DeviceFinder = new Runnable () {
- public void run () {
- Device device = getCurrent ();
- if (device == null) {
- device = getDefault ();
- }
- setDevice (device);
- }
- };
- }
-
-/*
-* TEMPORARY CODE.
-*/
-static void setDevice (Device device) {
- CurrentDevice = device;
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * Note: The resulting display is marked as the <em>current</em>
- * display. If this is the first display which has been
- * constructed since the application started, it is also
- * marked as the <em>default</em> display.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if called from a thread that already created an existing display</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see #getCurrent
- * @see #getDefault
- * @see Widget#checkSubclass
- * @see Shell
- */
-public Display () {
- this (null);
-}
-
-/**
- * Constructs a new instance of this class using the parameter.
- *
- * @param data the device data
- */
-public Display (DeviceData data) {
- super (data);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs anywhere
- * in a widget. The event type is one of the event constants
- * defined in class <code>SWT</code>. When the event does occur,
- * the listener is notified by sending it the <code>handleEvent()</code>
- * message.
- * <p>
- * Setting the type of an event to <code>SWT.None</code> from
- * within the <code>handleEvent()</code> method can be used to
- * change the event type and stop subsequent Java listeners
- * from running. Because event filters run before other listeners,
- * event filters can both block other listeners and set arbitrary
- * fields within an event. For this reason, event filters are both
- * powerful and dangerous. They should generally be avoided for
- * performance, debugging and code maintenance reasons.
- * </p>
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #removeFilter
- * @see #removeListener
- *
- * @since 3.0
- */
-public void addFilter (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (filterTable == null) filterTable = new EventTable ();
- filterTable.hook (eventType, listener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- * When the event does occur in the display, the listener is notified by
- * sending it the <code>handleEvent()</code> message.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #removeListener
- *
- * @since 2.0
- */
-public void addListener (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) eventTable = new EventTable ();
- eventTable.hook (eventType, listener);
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread at the next
- * reasonable opportunity. The caller of this method continues
- * to run in parallel, and is not notified when the
- * runnable has completed. Specifying <code>null</code> as the
- * runnable simply wakes the user-interface thread when run.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param runnable code to run on the user-interface thread or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #syncExec
- */
-public void asyncExec (Runnable runnable) {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- synchronizer.asyncExec (runnable);
- }
-}
-
-/**
- * Causes the system hardware to emit a short sound
- * (if it supports this capability).
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void beep () {
- checkDevice ();
- OS.PtBeep ();
-}
-
-protected void checkDevice () {
- if (thread == null) error (SWT.ERROR_WIDGET_DISPOSED);
- if (thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
-}
-
-static void checkDisplay (Thread thread, boolean multiple) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] != null) {
- if (!multiple) SWT.error (SWT.ERROR_NOT_IMPLEMENTED, null, " [multiple displays]");
- if (Displays [i].thread == thread) SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- }
- }
-}
-
-/**
- * Checks that this class can be subclassed.
- * <p>
- * IMPORTANT: See the comment in <code>Widget.checkSubclass()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- */
-protected void checkSubclass () {
- if (!isValidClass (getClass ())) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Requests that the connection between SWT and the underlying
- * operating system be closed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Device#dispose
- *
- * @since 2.0
- */
-public void close () {
- checkDevice ();
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- if (event.doit) dispose ();
-}
-
-String convertToLf (String text) {
- int length = text.length ();
- if (length == 0) return text;
-
- /* Check for an LF or CR/LF. Assume the rest of the string
- * is formated that way. This will not work if the string
- * contains mixed delimiters. */
- int i = text.indexOf ('\n', 0);
- if (i == -1 || i == 0) return text;
- if (text.charAt (i - 1) != '\r') return text;
-
- /* The string is formatted with CR/LF.
- * Create a new string with the LF line delimiter. */
- i = 0;
- StringBuffer result = new StringBuffer ();
- while (i < length) {
- int j = text.indexOf ('\r', i);
- if (j == -1) j = length;
- String s = text.substring (i, j);
- result.append (s);
- i = j + 2;
- result.append ('\n');
- }
- return result.toString ();
-}
-
-/**
- * Creates the device in the operating system. If the device
- * does not have a handle, this method may do nothing depending
- * on the device.
- * <p>
- * This method is called before <code>init</code>.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #init
- */
-protected void create (DeviceData data) {
- checkSubclass ();
- checkDisplay (thread = Thread.currentThread (), false);
- createDisplay (data);
- register (this);
- if (Default == null) Default = this;
-}
-
-void createDisplay (DeviceData data) {
- OS.PtInit (null);
- OS.PgSetDrawBufferSize (DrawBufferSize);
- app_context = OS.PtCreateAppContext ();
-}
-
-static void deregister (Display display) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (display == Displays [i]) Displays [i] = null;
- }
- }
-}
-
-/**
- * Destroys the device in the operating system and releases
- * the device's handle. If the device does not have a handle,
- * this method may do nothing depending on the device.
- * <p>
- * This method is called after <code>release</code>.
- * </p>
- * @see Device#dispose
- * @see #release
- */
-protected void destroy () {
- if (this == Default) Default = null;
- deregister (this);
- destroyDisplay ();
-}
-
-void destroyDisplay () {
- // NEED to destroy app_context ???
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread just before the
- * receiver is disposed. Specifying a <code>null</code> runnable
- * is ignored.
- *
- * @param runnable code to run at dispose time.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void disposeExec (Runnable runnable) {
- checkDevice ();
- if (disposeList == null) disposeList = new Runnable [4];
- for (int i=0; i<disposeList.length; i++) {
- if (disposeList [i] == null) {
- disposeList [i] = runnable;
- return;
- }
- }
- Runnable [] newDisposeList = new Runnable [disposeList.length + 4];
- System.arraycopy (disposeList, 0, newDisposeList, 0, disposeList.length);
- newDisposeList [disposeList.length] = runnable;
- disposeList = newDisposeList;
-}
-
-int drawProc (int handle, int damage) {
- /*
- * Feature in Photon. On QNX 6.2, if a widget is damaged, PtBlit() will
- * call its draw function before blitting pixels. This is not wrong
- * but it is unwanted, since the callback might happen in a thread other
- * than the display thread. The fix is to detect that the callback happened
- * in the wrong thread and return right away.
- */
- //TEMPORARY CODE
- if (thread != Thread.currentThread()) return 0;
- Widget widget = WidgetTable.get (handle);
- if (widget == null) return 0;
- return widget.drawProc (handle, damage);
-}
-
-void error (int code) {
- SWT.error(code);
-}
-
-/**
- * Returns the display which the given thread is the
- * user-interface thread for, or null if the given thread
- * is not a user-interface thread for any display. Specifying
- * <code>null</code> as the thread will return <code>null</code>
- * for the display.
- *
- * @param thread the user-interface thread
- * @return the display for the given thread
- */
-public static Display findDisplay (Thread thread) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- Display display = Displays [i];
- if (display != null && display.thread == thread) {
- return display;
- }
- }
- return null;
- }
-}
-
-boolean filterEvent (Event event) {
- if (filterTable != null) filterTable.sendEvent (event);
- return false;
-}
-
-boolean filters (int eventType) {
- if (filterTable == null) return false;
- return filterTable.hooks (eventType);
-}
-
-/**
- * Given the operating system handle for a widget, returns
- * the instance of the <code>Widget</code> subclass which
- * represents it in the currently running application, if
- * such exists, or null if no matching widget can be found.
- * <p>
- * <b>IMPORTANT:</b> This method should not be called from
- * application code. The arguments are platform-specific.
- * </p>
- *
- * @param handle the handle for the widget
- * @return the SWT widget that the handle represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Widget findWidget (int handle) {
- checkDevice ();
- return WidgetTable.get (handle);
-}
-
-/**
- * Given the operating system handle for a widget,
- * and widget-specific id, returns the instance of
- * the <code>Widget</code> subclass which represents
- * the handle/id pair in the currently running application,
- * if such exists, or null if no matching widget can be found.
- * <p>
- * <b>IMPORTANT:</b> This method should not be called from
- * application code. The arguments are platform-specific.
- * </p>
- *
- * @param handle the handle for the widget
- * @param id the id for the subwidget (usually an item)
- * @return the SWT widget that the handle/id pair represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public Widget findWidget (int handle, int id) {
- checkDevice ();
- return null;
-}
-
-/**
- * Given a widget and a widget-specific id, returns the
- * instance of the <code>Widget</code> subclass which represents
- * the widget/id pair in the currently running application,
- * if such exists, or null if no matching widget can be found.
- *
- * @param widget the widget
- * @param id the id for the subwidget (usually an item)
- * @return the SWT subwidget (usually an item) that the widget/id pair represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.3
- */
-public Widget findWidget (Widget widget, int id) {
- checkDevice ();
- return null;
-}
-
-/**
- * Returns the currently active <code>Shell</code>, or null
- * if no shell belonging to the currently running application
- * is active.
- *
- * @return the active shell or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Shell getActiveShell () {
- checkDevice ();
- int handle = 0;
- while ((handle = OS.PtNextTopLevelWidget (handle)) != 0) {
- int state = OS.PtWindowGetState (handle);
- if (state != -1 && (state & OS.Ph_WM_STATE_ISFOCUS) != 0) {
- Widget widget = WidgetTable.get (handle);
- if (widget instanceof Shell) return (Shell) widget;
- }
- }
- return null;
-}
-
-/**
- * Returns the control which the on-screen pointer is currently
- * over top of, or null if it is not currently over one of the
- * controls built by the currently running application.
- *
- * @return the control under the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Control getCursorControl () {
- checkDevice ();
- int ig = OS.PhInputGroup (0);
- PhCursorInfo_t info = new PhCursorInfo_t ();
- OS.PhQueryCursor ((short) ig, info);
- PhRect_t rect = new PhRect_t ();
- rect.ul_x = rect.lr_x = info.pos_x;
- rect.ul_y = rect.lr_y = info.pos_y;
- int handle = 0;
- //DOESN'T WORK WHEN SHELLS OVERLAP (NEED Z ORDER)
- while ((handle = OS.PtNextTopLevelWidget (handle)) != 0) {
- int child = handle, parent = 0;
- short [] x = new short [1], y = new short [1];
- do {
- OS.PtGetAbsPosition (child, x, y);
- rect.ul_x = rect.lr_x = (short) (info.pos_x - x [0]);
- rect.ul_y = rect.lr_y = (short) (info.pos_y - y [0]);
- if ((child = OS.PtHit (child, 1, rect)) == 0) break;
- parent = child;
- if (OS.PtWidgetIsClassMember (child, OS.PtContainer ()) == 0) break;
- } while (child != 0);
- if (parent != 0) {
- do {
- Widget widget = WidgetTable.get (parent);
- if (widget != null && widget instanceof Control) {
- Control control = (Control) widget;
- if (control.getEnabled ()) return control;
- return control;
- }
- } while ((parent = OS.PtWidgetParent (parent)) != 0);
- }
- }
- return null;
-}
-
-/**
- * Returns an array containing the recommended cursor sizes.
- *
- * @return the array of cursor sizes
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public Point [] getCursorSizes () {
- checkDevice ();
- return new Point [] {new Point (16, 16), new Point (32, 32)};
-}
-
-/**
- * Returns the location of the on-screen pointer relative
- * to the top left corner of the screen.
- *
- * @return the cursor location
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point getCursorLocation () {
- checkDevice ();
- int ig = OS.PhInputGroup (0);
- PhCursorInfo_t info = new PhCursorInfo_t ();
- OS.PhQueryCursor ((short)ig, info);
- return new Point (info.pos_x, info.pos_y);
-}
-
-/**
- * Returns the display which the currently running thread is
- * the user-interface thread for, or null if the currently
- * running thread is not a user-interface thread for any display.
- *
- * @return the current display
- */
-public static Display getCurrent () {
- return findDisplay (Thread.currentThread ());
-}
-
-/**
- * Returns the default display. One is created (making the
- * thread that invokes this method its user-interface thread)
- * if it did not already exist.
- *
- * @return the default display
- */
-public static Display getDefault () {
- synchronized (Device.class) {
- if (Default == null) Default = new Display ();
- return Default;
- }
-}
-
-/**
- * On platforms which support it, sets the application name
- * to be the argument. On Motif, for example, this can be used
- * to set the name used for resource lookup. Specifying
- * <code>null</code> for the name clears it.
- *
- * @param name the new app name or <code>null</code>
- */
-public static void setAppName (String name) {
- /* Do nothing */
-}
-
-/**
- * Returns the button dismissal alignment, one of <code>LEFT</code> or <code>RIGHT</code>.
- * The button dismissal alignment is the ordering that should be used when positioning the
- * default dismissal button for a dialog. For example, in a dialog that contains an OK and
- * CANCEL button, on platforms where the button dismissal alignment is <code>LEFT</code>, the
- * button ordering should be OK/CANCEL. When button dismissal alignment is <code>RIGHT</code>,
- * the button ordering should be CANCEL/OK.
- *
- * @return the button dismissal order
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1
- */
-public int getDismissalAlignment () {
- checkDevice ();
- return SWT.RIGHT;
-}
-
-/**
- * Returns the longest duration, in milliseconds, between
- * two mouse button clicks that will be considered a
- * <em>double click</em> by the underlying operating system.
- *
- * @return the double click time
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getDoubleClickTime () {
- checkDevice ();
- //NOT DONE
- return 250;
-}
-
-/**
- * Returns the control which currently has keyboard focus,
- * or null if keyboard events are not currently going to
- * any of the controls built by the currently running
- * application.
- *
- * @return the control under the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Control getFocusControl () {
- checkDevice ();
- int handle = 0;
- while ((handle = OS.PtNextTopLevelWidget (handle)) != 0) {
- int state = OS.PtWindowGetState (handle);
- if (state != -1 && (state & OS.Ph_WM_STATE_ISFOCUS) != 0) {
- int focusHandle = OS.PtContainerFindFocus (handle);
- if (focusHandle != 0) {
- Widget widget = WidgetTable.get (focusHandle);
- if (widget instanceof Control) return (Control) widget;
- }
- return null;
- }
- }
- return null;
-}
-
-int getLastEventTime () {
- return (int) System.currentTimeMillis ();
-}
-
-/**
- * Returns true when the high contrast mode is enabled.
- * Otherwise, false is returned.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @return the high contrast mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public boolean getHighContrast () {
- checkDevice ();
- return false;
-}
-
-/**
- * Returns the maximum allowed depth of icons on this display, in bits per pixel.
- * On some platforms, this may be different than the actual depth of the display.
- *
- * @return the maximum icon depth
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Device#getDepth
- */
-public int getIconDepth () {
- return getDepth ();
-}
-
-/**
- * Returns an array containing the recommended icon sizes.
- *
- * @return the array of icon sizes
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Decorations#setImages(Image[])
- *
- * @since 3.0
- */
-public Point [] getIconSizes () {
- checkDevice ();
- return new Point [] {new Point (15, 15), new Point (43, 43)};
-}
-
-int getMessageCount () {
- return synchronizer.getMessageCount ();
-}
-
-/**
- * Returns an array of monitors attached to the device.
- *
- * @return the array of monitors
- *
- * @since 3.0
- */
-public Monitor [] getMonitors () {
- checkDevice ();
- int cnt = OS.PhQueryRids (0, 0, 0, OS.Ph_GRAFX_REGION, 0, 0, null, null, 0);
- int [] rids = new int [cnt];
- cnt = OS.PhQueryRids (0, 0, 0, OS.Ph_GRAFX_REGION, 0, 0, null, rids, rids.length);
- PhRect_t rect = new PhRect_t ();
- Monitor [] monitors = new Monitor [cnt];
- for (int i = 0; i < cnt; i++) {
- Monitor monitor = new Monitor ();
- monitor.handle = rids [i];
- OS.PhWindowQueryVisible (OS.Ph_QUERY_CONSOLE, rids [i], OS.PhInputGroup (0), rect);
- monitor.x = rect.ul_x;
- monitor.y = rect.ul_y;
- monitor.width = rect.lr_x - rect.ul_x + 1;
- monitor.height = rect.lr_y - rect.ul_y + 1;
- OS.PhWindowQueryVisible (OS.Ph_QUERY_WORKSPACE, rids [i], OS.PhInputGroup (0), rect);
- monitor.clientX = rect.ul_x;
- monitor.clientY = rect.ul_y;
- monitor.clientWidth = rect.lr_x - rect.ul_x + 1;
- monitor.clientHeight = rect.lr_y - rect.ul_y + 1;
- monitors [i] = monitor;
- }
- return monitors;
-}
-
-/**
- * Returns the primary monitor for that device.
- *
- * @return the primary monitor
- *
- * @since 3.0
- */
-public Monitor getPrimaryMonitor () {
- checkDevice ();
- /*
- * Note. Photon does not define a primary monitor.
- * The workaround is to arbitrarily return the first
- * monitor whose coordinates are (0, 0), or the first
- * monitor returned by getMonitors().
- */
- Monitor [] monitors = getMonitors ();
- if (monitors.length == 1) return monitors [0];
- for (int i = 0; i < monitors.length; i++) {
- Monitor monitor = monitors [i];
- if (monitor.x == 0 && monitor.y == 0) return monitor;
- }
- return monitors [0];
-}
-
-/**
- * Returns a (possibly empty) array containing all shells which have
- * not been disposed and have the receiver as their display.
- *
- * @return the receiver's shells
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Shell [] getShells () {
- checkDevice ();
- /*
- * NOTE: Need to check that the shells that belong
- * to another display have not been disposed by the
- * other display's thread as the shells list is being
- * processed.
- */
- int count = 0;
- Shell [] shells = WidgetTable.shells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed () && this == shell.display) {
- count++;
- }
- }
- if (count == shells.length) return shells;
- int index = 0;
- Shell [] result = new Shell [count];
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed () && this == shell.display) {
- result [index++] = shell;
- }
- }
- return result;
-}
-
-/**
- * Returns the matching standard color for the given
- * constant, which should be one of the color constants
- * specified in class <code>SWT</code>. Any value other
- * than one of the SWT color constants which is passed
- * in will result in the color black. This color should
- * not be free'd because it was allocated by the system,
- * not the application.
- *
- * @param id the color constant
- * @return the matching color
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT
- */
-public Color getSystemColor (int id) {
- checkDevice ();
- int color = 0x000000;
- switch (id) {
- case SWT.COLOR_INFO_FOREGROUND: color = INFO_FOREGROUND; break;
- case SWT.COLOR_INFO_BACKGROUND: color = INFO_BACKGROUND; break;
- case SWT.COLOR_TITLE_FOREGROUND: color = 0xFFFFFF; break;
- case SWT.COLOR_TITLE_BACKGROUND: color = 0x5281D5; break;
- case SWT.COLOR_TITLE_BACKGROUND_GRADIENT: color = 0x74A3FF; break;
- case SWT.COLOR_TITLE_INACTIVE_FOREGROUND: color = 0x000000; break;
- case SWT.COLOR_TITLE_INACTIVE_BACKGROUND: color = 0xABBBD3; break;
- case SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT: color = 0xCDDDFF; break;
- case SWT.COLOR_WIDGET_DARK_SHADOW: color = WIDGET_DARK_SHADOW; break;
- case SWT.COLOR_WIDGET_NORMAL_SHADOW: color = WIDGET_NORMAL_SHADOW; break;
- case SWT.COLOR_WIDGET_LIGHT_SHADOW: color = WIDGET_LIGHT_SHADOW; break;
- case SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: color = WIDGET_HIGHLIGHT_SHADOW; break;
- case SWT.COLOR_WIDGET_BACKGROUND: color = WIDGET_BACKGROUND; break;
- case SWT.COLOR_WIDGET_FOREGROUND: color = WIDGET_FOREGROUND; break;
- case SWT.COLOR_WIDGET_BORDER: color = WIDGET_BORDER; break;
- case SWT.COLOR_LIST_FOREGROUND: color = LIST_FOREGROUND; break;
- case SWT.COLOR_LIST_BACKGROUND: color = LIST_BACKGROUND; break;
- case SWT.COLOR_LIST_SELECTION: color = LIST_SELECTION; break;
- case SWT.COLOR_LIST_SELECTION_TEXT: color = LIST_SELECTION_TEXT; break;
- default:
- return super.getSystemColor (id);
- }
- return Color.photon_new (this, color);
-}
-
-/**
- * Returns the matching standard platform cursor for the given
- * constant, which should be one of the cursor constants
- * specified in class <code>SWT</code>. This cursor should
- * not be free'd because it was allocated by the system,
- * not the application. A value of <code>null</code> will
- * be returned if the supplied constant is not an SWT cursor
- * constant.
- *
- * @param id the SWT cursor constant
- * @return the corresponding cursor or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT#CURSOR_ARROW
- * @see SWT#CURSOR_WAIT
- * @see SWT#CURSOR_CROSS
- * @see SWT#CURSOR_APPSTARTING
- * @see SWT#CURSOR_HELP
- * @see SWT#CURSOR_SIZEALL
- * @see SWT#CURSOR_SIZENESW
- * @see SWT#CURSOR_SIZENS
- * @see SWT#CURSOR_SIZENWSE
- * @see SWT#CURSOR_SIZEWE
- * @see SWT#CURSOR_SIZEN
- * @see SWT#CURSOR_SIZES
- * @see SWT#CURSOR_SIZEE
- * @see SWT#CURSOR_SIZEW
- * @see SWT#CURSOR_SIZENE
- * @see SWT#CURSOR_SIZESE
- * @see SWT#CURSOR_SIZESW
- * @see SWT#CURSOR_SIZENW
- * @see SWT#CURSOR_UPARROW
- * @see SWT#CURSOR_IBEAM
- * @see SWT#CURSOR_NO
- * @see SWT#CURSOR_HAND
- *
- * @since 3.0
- */
-public Cursor getSystemCursor (int id) {
- checkDevice ();
- if (!(0 <= id && id < cursors.length)) return null;
- if (cursors [id] == null) {
- cursors [id] = new Cursor (this, id);
- }
- return cursors [id];
-}
-
-/**
- * Returns a reasonable font for applications to use.
- * On some platforms, this will match the "default font"
- * or "system font" if such can be found. This font
- * should not be free'd because it was allocated by the
- * system, not the application.
- * <p>
- * Typically, applications which want the default look
- * should simply not set the font on the widgets they
- * create. Widgets are always created with the correct
- * default font for the class of user-interface component
- * they represent.
- * </p>
- *
- * @return a font
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getSystemFont () {
- checkDevice ();
- byte [] font = defaultFont != null ? defaultFont : TEXT_FONT;
- return Font.photon_new (this, font);
-}
-
-/**
- * Returns the matching standard platform image for the given
- * constant, which should be one of the icon constants
- * specified in class <code>SWT</code>. This image should
- * not be free'd because it was allocated by the system,
- * not the application. A value of <code>null</code> will
- * be returned either if the supplied constant is not an
- * SWT icon constant or if the platform does not define an
- * image that corresponds to the constant.
- *
- * @param id the SWT icon constant
- * @return the corresponding image or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_QUESTION
- * @see SWT#ICON_WARNING
- * @see SWT#ICON_WORKING
- *
- * @since 3.0
- */
-public Image getSystemImage (int id) {
- checkDevice ();
- return null;
-}
-
-/**
- * Returns the single instance of the system tray or null
- * when there is no system tray available for the platform.
- *
- * @return the system tray or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public Tray getSystemTray () {
- checkDevice ();
- return null;
-}
-
-/**
- * Gets the synchronizer used by the display.
- *
- * @return the receiver's synchronizer
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public Synchronizer getSynchronizer () {
- checkDevice ();
- return synchronizer;
-}
-
-/**
- * Returns the thread that has invoked <code>syncExec</code>
- * or null if no such runnable is currently being invoked by
- * the user-interface thread.
- * <p>
- * Note: If a runnable invoked by asyncExec is currently
- * running, this method will return null.
- * </p>
- *
- * @return the receiver's sync-interface thread
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Thread getSyncThread () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- return synchronizer.syncThread;
- }
-}
-
-/**
- * Returns the user-interface thread for the receiver.
- *
- * @return the receiver's user-interface thread
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Thread getThread () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- return thread;
- }
-}
-
-int hotkeyProc (int handle, int data, int info) {
- Widget widget = WidgetTable.get (handle);
- if (widget == null) return OS.Pt_CONTINUE;
- return widget.hotkeyProc (handle, data, info);
-}
-
-/**
- * Initializes any internal resources needed by the
- * device.
- * <p>
- * This method is called after <code>create</code>.
- * </p>
- *
- * @see #create
- */
-protected void init () {
- super.init ();
- initializeDisplay ();
- initializeWidgetClasses ();
- initializeWidgetColors ();
- initializeWidgetFonts ();
- initializeScrollbars ();
- initializeImages ();
-}
-
-void initializeDisplay () {
- windowCallback = new Callback (this, "windowProc", 3);
- windowProc = windowCallback.getAddress ();
- if (windowProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- drawCallback = new Callback (this, "drawProc", 2);
- drawProc = drawCallback.getAddress ();
- if (drawProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- workCallback = new Callback (this, "workProc", 1);
- workProc = workCallback.getAddress ();
- if (workProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- inputCallback = new Callback (this, "inputProc", 4);
- inputProc = inputCallback.getAddress ();
- if (inputProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- timerCallback = new Callback (this, "timerProc", 3);
- timerProc = timerCallback.getAddress ();
- if (timerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- hotkeyCallback = new Callback (this, "hotkeyProc", 3);
- hotkeyProc = hotkeyCallback.getAddress ();
- if (hotkeyProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- pulse = OS.PtAppCreatePulse (app_context, -1);
- input = OS.PtAppAddInput (app_context, pulse, inputProc, 0);
- int [] args = {
- OS.Pt_ARG_REGION_OPAQUE, 0, ~0,
- OS.Pt_ARG_FILL_COLOR, OS.Pg_TRANSPARENT, 0,
- OS.Pt_ARG_REGION_SENSE, OS.Ph_EV_TIMER, ~0,
- };
- OS.PtSetParentWidget (0);
- timerHandle = OS.PtCreateWidget (OS.PtRegion (), 0, args.length / 3, args);
- if (timerHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.PtRealizeWidget (timerHandle);
-}
-
-void initializeScrollbars () {
- OS.PtSetParentWidget (0);
- int shellHandle = OS.PtCreateWidget (OS.PtWindow (), 0, 0, null);
- int textHandle = OS.PtCreateWidget (OS.PtMultiText (), shellHandle, 0, null);
- int child = OS.PtWidgetChildFront (textHandle);
- while (child != 0) {
- if (OS.PtWidgetClass (child) == OS.PtScrollbar ()) {
- int [] args = new int [] {
- OS.Pt_ARG_ORIENTATION, 0, 0,
- OS.Pt_ARG_WIDTH, 0, 0,
- OS.Pt_ARG_HEIGHT, 0, 0,
- OS.Pt_ARG_BASIC_FLAGS, 0, 0,
- };
- OS.PtGetResources (child, args.length / 3, args);
- switch (args [1]) {
- case OS.Pt_HORIZONTAL:
- SCROLLBAR_HEIGHT = args [7];
- SCROLLBAR_HORIZONTAL_BASIC_FLAGS = args [10];
- break;
- case OS.Pt_VERTICAL:
- SCROLLBAR_WIDTH = args [4];
- SCROLLBAR_VERTICAL_BASIC_FLAGS = args [10];
- break;
- }
- }
- child = OS.PtWidgetBrotherBehind (child);
- }
- OS.PtDestroyWidget (shellHandle);
-}
-
-void initializeWidgetClasses () {
- int [] args = {OS.Pt_SET_DRAW_F, drawProc, 0};
- int [] buffer = {
- OS.PtCreateWidgetClass (OS.PtButton (), 0, args.length / 3, args), 0, 0,
- OS.PtCreateWidgetClass (OS.PtList (), 0, args.length / 3, args), 0, 0,
- OS.PtCreateWidgetClass (OS.PtLabel (), 0, args.length / 3, args), 0, 0,
- OS.PtCreateWidgetClass (OS.PtWindow (), 0, args.length / 3, args), 0, 0,
- OS.PtCreateWidgetClass (OS.PtToggleButton (), 0, args.length / 3, args), 0, 0,
- OS.PtCreateWidgetClass (OS.PtComboBox (), 0, args.length / 3, args), 0, 0,
- OS.PtCreateWidgetClass (OS.PtText (), 0, args.length / 3, args), 0, 0,
- OS.PtCreateWidgetClass (OS.PtMultiText (), 0, args.length / 3, args), 0, 0,
- OS.PtCreateWidgetClass (OS.PtScrollbar (), 0, args.length / 3, args), 0, 0,
- OS.PtCreateWidgetClass (OS.PtScrollContainer (), 0, args.length / 3, args), 0, 0,
- OS.PtCreateWidgetClass (OS.PtScrollArea (), 0, args.length / 3, args), 0, 0,
- OS.PtCreateWidgetClass (OS.PtContainer (), 0, args.length / 3, args), 0, 0,
- OS.PtCreateWidgetClass (OS.PtProgress (), 0, args.length / 3, args), 0, 0,
- OS.PtCreateWidgetClass (OS.PtPanelGroup (), 0, args.length / 3, args), 0, 0,
- OS.PtCreateWidgetClass (OS.PtPane (), 0, args.length / 3, args), 0, 0,
- OS.PtCreateWidgetClass (OS.PtSlider (), 0, args.length / 3, args), 0, 0,
- OS.PtCreateWidgetClass (OS.PtSeparator (), 0, args.length / 3, args), 0, 0,
- OS.PtCreateWidgetClass (OS.PtToolbar (), 0, args.length / 3, args), 0, 0,
- OS.PtCreateWidgetClass (OS.PtNumericInteger (), 0, args.length / 3, args), 0, 0,
- };
- ClassesPtr = OS.malloc (buffer.length * 4);
- OS.memmove (ClassesPtr, buffer, buffer.length * 4);
- PtButton = ClassesPtr;
- PtList = ClassesPtr + 12;
- PtLabel = ClassesPtr + 24;
- //PtWindow = ClassesPtr + 36;
- PtToggleButton = ClassesPtr + 48;
- PtComboBox = ClassesPtr + 60;
- PtText = ClassesPtr + 72;
- PtMultiText = ClassesPtr + 84;
- PtScrollbar = ClassesPtr + 96;
- //PtScrollContainer = ClassesPtr + 108;
- //PtScrollArea = ClassesPtr + 120;
- PtContainer = ClassesPtr + 132;
- PtProgress = ClassesPtr + 144;
- PtPanelGroup = ClassesPtr + 156;
- //PtPane = ClassesPtr + 168;
- PtSlider = ClassesPtr + 180;
- PtSeparator = ClassesPtr + 192;
- PtToolbar = ClassesPtr + 204;
- PtNumericInteger = ClassesPtr + 216;
-}
-
-void initializeWidgetColors () {
- OS.PtSetParentWidget (0);
- int [] args = {
- OS.Pt_ARG_WINDOW_STATE, OS.Ph_WM_STATE_ISHIDDEN, ~0,
- };
- int shellHandle = OS.PtCreateWidget (OS.PtWindow (), 0, args.length / 3, args);
- args = new int [] {
- OS.Pt_ARG_COLOR, 0, 0,
- OS.Pt_ARG_FILL_COLOR, 0, 0,
- };
- OS.PtGetResources (shellHandle, args.length / 3, args);
- WIDGET_FOREGROUND = args [1];
- WIDGET_BACKGROUND = args [4];
-
- int listHandle = OS.PtCreateWidget (OS.PtList (), shellHandle, 0, null);
- args = new int [] {
- OS.Pt_ARG_COLOR, 0, 0,
- OS.Pt_ARG_FILL_COLOR, 0, 0,
- OS.Pt_ARG_SELECTION_FILL_COLOR, 0, 0,
- OS.Pt_ARG_SELECTION_TEXT_COLOR, 0, 0,
- };
- OS.PtGetResources (listHandle, args.length / 3, args);
- LIST_FOREGROUND = args [1];
- LIST_BACKGROUND = args [4];
- LIST_SELECTION = args [7];
- LIST_SELECTION_TEXT = args [10];
-
- int textHandle = OS.PtCreateWidget (OS.PtText (), shellHandle, 0, null);
- args = new int [] {
- OS.Pt_ARG_COLOR, 0, 0,
- OS.Pt_ARG_FILL_COLOR, 0, 0,
- };
- OS.PtGetResources (textHandle, args.length / 3, args);
- TEXT_FOREGROUND = args [1];
- TEXT_BACKGROUND = args [4];
-
- /*
- * Feature in Photon. The values of Pt_ARG_DARK_BEVEL_COLOR and
- * Pt_ARG_LIGHT_BEVEL_COLOR are not initialized until the widget
- * is realized. The fix is to realize the shell without displaying
- * it.
- */
- int buttonHandle = OS.PtCreateWidget (OS.PtButton (), shellHandle, 0, null);
- OS.PtRealizeWidget(shellHandle);
- args = new int [] {
- OS.Pt_ARG_OUTLINE_COLOR, 0, 0,
- OS.Pt_ARG_OUTLINE_COLOR, 0, 0,
- OS.Pt_ARG_DARK_BEVEL_COLOR, 0, 0,
- OS.Pt_ARG_BEVEL_COLOR, 0, 0,
- OS.Pt_ARG_LIGHT_BEVEL_COLOR, 0, 0,
- OS.Pt_ARG_BALLOON_COLOR, 0, 0,
- OS.Pt_ARG_BALLOON_FILL_COLOR, 0, 0,
- };
- OS.PtGetResources (buttonHandle, args.length / 3, args);
- WIDGET_BORDER = args [1];
- WIDGET_DARK_SHADOW = args [4];
- WIDGET_NORMAL_SHADOW = args [7];
- WIDGET_LIGHT_SHADOW = args [10];
- WIDGET_HIGHLIGHT_SHADOW = args [13];
- INFO_FOREGROUND = args [16];
- INFO_BACKGROUND = args [19];
-
- OS.PtDestroyWidget (shellHandle);
-}
-
-void initializeWidgetFonts () {
- String property = System.getProperty ("swt.system.font");
- if (property != null) {
- defaultFont = Converter.wcsToMbcs (null, property, true);
- TEXT_FONT = LIST_FONT = GAUGE_FONT = TITLE_FONT = defaultFont;
- GROUP_FONT = Converter.wcsToMbcs (null, property + "b", true);
- return;
- }
- OS.PtSetParentWidget (0);
-
- int shellHandle = OS.PtCreateWidget (OS.PtWindow (), 0, 0, null);
- int [] args = new int [] {OS.Pt_ARG_TITLE_FONT, 0, 0};
- OS.PtGetResources (shellHandle, args.length / 3, args);
- int length = OS.strlen (args [1]);
- GROUP_FONT = TITLE_FONT = new byte [length + 1];
- OS.memmove (TITLE_FONT, args [1], length);
-
- int listHandle = OS.PtCreateWidget (OS.PtList (), shellHandle, 0, null);
- args = new int [] {OS.Pt_ARG_LIST_FONT, 0, 0};
- OS.PtGetResources (listHandle, args.length / 3, args);
- length = OS.strlen (args [1]);
- LIST_FONT = new byte [length + 1];
- OS.memmove (LIST_FONT, args [1], length);
-
- int textHandle = OS.PtCreateWidget (OS.PtText (), shellHandle, 0, null);
- args = new int [] {OS.Pt_ARG_TEXT_FONT, 0, 0};
- OS.PtGetResources (textHandle, args.length / 3, args);
- length = OS.strlen (args [1]);
- TEXT_FONT = new byte [length + 1];
- OS.memmove (TEXT_FONT, args [1], length);
-
- int scrollHandle = OS.PtCreateWidget (OS.PtScrollbar (), shellHandle, 0, null);
- args = new int [] {OS.Pt_ARG_GAUGE_FONT, 0, 0};
- OS.PtGetResources (scrollHandle, args.length / 3, args);
- length = OS.strlen (args [1]);
- GAUGE_FONT = new byte [length + 1];
- OS.memmove (GAUGE_FONT, args [1], length);
-
- OS.PtDestroyWidget (shellHandle);
-}
-
-void initializeImages () {
- nullImage = OS.PhCreateImage (null, (short) 1, (short) 1, OS.Pg_IMAGE_DIRECT_888, 0, 0, 0);
- if (nullImage == 0) SWT.error (SWT.ERROR_NO_HANDLES);
-}
-
-int inputProc (int data, int rcvid, int message, int size) {
- if (embedded) {
- runDeferredEvents ();
- if (runAsyncMessages (false)) wakeThread ();
- }
- return OS.Pt_CONTINUE;
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Display</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for gc creation</li>
- * </ul>
- */
-public int internal_new_GC (GCData data) {
- if (isDisposed()) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
- int phGC = OS.PgCreateGC(0); // NOTE: PgCreateGC ignores the parameter
- if (phGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) == 0) {
- data.style |= SWT.LEFT_TO_RIGHT;
- }
-
- data.device = this;
- data.rid = OS.Ph_DEV_RID;
- return phGC;
-}
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Display</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int phGC, GCData data) {
- OS.PgDestroyGC(phGC);
-}
-
-boolean isValidThread () {
- return thread == Thread.currentThread ();
-}
-
-/**
- * Returns the application defined property of the receiver
- * with the specified name, or null if it has not been set.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the display is disposed
- * of, it is the application's responsibility to provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param key the name of the property
- * @return the value of the property or null if it has not been set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setData(String, Object)
- * @see #disposeExec(Runnable)
- */
-public Object getData (String key) {
- checkDevice ();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (keys == null) return null;
- for (int i=0; i<keys.length; i++) {
- if (keys [i].equals (key)) return values [i];
- }
- return null;
-}
-
-/**
- * Returns the application defined, display specific data
- * associated with the receiver, or null if it has not been
- * set. The <em>display specific data</em> is a single,
- * unnamed field that is stored with every display.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the display specific data needs to
- * be notified when the display is disposed of, it is the
- * application's responsibility to provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @return the display specific data
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setData(Object)
- * @see #disposeExec(Runnable)
- */
-public Object getData () {
- checkDevice ();
- return data;
-}
-static boolean isValidClass (Class clazz) {
- String name = clazz.getName ();
- int index = name.lastIndexOf ('.');
- return name.substring (0, index + 1).equals (PACKAGE_NAME);
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param point to be mapped
- * @return point with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Point map (Control from, Control to, Point point) {
- checkDevice ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return map (from, to, point.x, point.y);
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param x coordinates to be mapped
- * @param y coordinates to be mapped
- * @return point with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Point map (Control from, Control to, int x, int y) {
- checkDevice ();
- if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- Point point = new Point (x, y);
- if (from == to) return point;
- if (from != null) {
- short [] position_x = new short [1], position_y = new short [1];
- OS.PtGetAbsPosition (from.handle, position_x, position_y);
- point.x += position_x [0];
- point.y += position_y [0];
- }
- if (to != null) {
- short [] position_x = new short [1], position_y = new short [1];
- OS.PtGetAbsPosition (to.handle, position_x, position_y);
- point.x -= position_x [0];
- point.y -= position_y [0];
- }
- return point;
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param rectangle to be mapped
- * @return rectangle with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Rectangle map (Control from, Control to, Rectangle rectangle) {
- checkDevice ();
- if (rectangle == null) error (SWT.ERROR_NULL_ARGUMENT);
- return map (from, to, rectangle.x, rectangle.y, rectangle.width, rectangle.height);
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param x coordinates to be mapped
- * @param y coordinates to be mapped
- * @param width coordinates to be mapped
- * @param height coordinates to be mapped
- * @return rectangle with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Rectangle map (Control from, Control to, int x, int y, int width, int height) {
- checkDevice ();
- if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- Rectangle rect = new Rectangle (x, y, width, height);
- if (from == to) return rect;
- if (from != null) {
- short [] position_x = new short [1], position_y = new short [1];
- OS.PtGetAbsPosition (from.handle, position_x, position_y);
- rect.x += position_x [0];
- rect.y += position_y [0];
- }
- if (to != null) {
- short [] position_x = new short [1], position_y = new short [1];
- OS.PtGetAbsPosition (to.handle, position_x, position_y);
- rect.x -= position_x [0];
- rect.y -= position_y [0];
- }
- return rect;
-}
-
-/**
- * Generate a low level system event.
- *
- * <code>post</code> is used to generate low level keyboard
- * and mouse events. The intent is to enable automated UI
- * testing by simulating the input from the user. Most
- * SWT applications should never need to call this method.
- * <p>
- * Note that this operation can fail when the operating system
- * fails to generate the event for any reason. For example,
- * this can happen when there is no such key or mouse button
- * or when the system event queue is full.
- * </p>
- * <p>
- * <b>Event Types:</b>
- * <p>KeyDown, KeyUp
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type KeyDown or KeyUp</li>
- * <p> Either one of:
- * <li>(in) character a character that corresponds to a keyboard key</li>
- * <li>(in) keyCode the key code of the key that was typed,
- * as defined by the key code constants in class <code>SWT</code></li>
- * </ul>
- * <p>MouseDown, MouseUp</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseDown or MouseUp
- * <li>(in) button the button that is pressed or released
- * </ul>
- * <p>MouseMove</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseMove
- * <li>(in) x the x coordinate to move the mouse pointer to in screen coordinates
- * <li>(in) y the y coordinate to move the mouse pointer to in screen coordinates
- * </ul>
- * <p>MouseWheel</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseWheel
- * <li>(in) detail either SWT.SCROLL_LINE or SWT.SCROLL_PAGE
- * <li>(in) count the number of lines or pages to scroll
- * </ul>
- * </dl>
- *
- * @param event the event to be generated
- *
- * @return true if the event was generated or false otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public boolean post (Event event) {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- return false;
- }
-}
-
-void postEvent (Event event) {
- /*
- * Place the event at the end of the event queue.
- * This code is always called in the Display's
- * thread so it must be re-enterant but does not
- * need to be synchronized.
- */
- if (eventQueue == null) eventQueue = new Event [4];
- int index = 0;
- int length = eventQueue.length;
- while (index < length) {
- if (eventQueue [index] == null) break;
- index++;
- }
- if (index == length) {
- Event [] newQueue = new Event [length + 4];
- System.arraycopy (eventQueue, 0, newQueue, 0, length);
- eventQueue = newQueue;
- }
- eventQueue [index] = event;
- if (embedded) wakeThread ();
-}
-
-/**
- * Reads an event from the operating system's event queue,
- * dispatches it appropriately, and returns <code>true</code>
- * if there is potentially more work to do, or <code>false</code>
- * if the caller can sleep until another event is placed on
- * the event queue.
- * <p>
- * In addition to checking the system event queue, this method also
- * checks if any inter-thread messages (created by <code>syncExec()</code>
- * or <code>asyncExec()</code>) are waiting to be processed, and if
- * so handles them before returning.
- * </p>
- *
- * @return <code>false</code> if the caller can sleep upon return from this method
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li>
- * </ul>
- *
- * @see #sleep
- * @see #wake
- */
-public boolean readAndDispatch () {
- checkDevice ();
- idle = false;
- OS.PtRelease ();
- OS.PtHold ();
- int id = OS.PtAppAddWorkProc (app_context, workProc, 0);
- OS.PtAppProcessEvent (app_context);
- OS.PtAppRemoveWorkProc (app_context, id);
- boolean result = true;
- if (idle) {
- result = runAsyncMessages (false);
- } else {
- runDeferredEvents ();
- }
- OS.PtRelease ();
- OS.PtHold ();
- return isDisposed () || result;
-}
-
-static void register (Display display) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] == null) {
- Displays [i] = display;
- return;
- }
- }
- Display [] newDisplays = new Display [Displays.length + 4];
- System.arraycopy (Displays, 0, newDisplays, 0, Displays.length);
- newDisplays [Displays.length] = display;
- Displays = newDisplays;
- }
-}
-
-/**
- * Releases any internal resources back to the operating
- * system and clears all fields except the device handle.
- * <p>
- * Disposes all shells which are currently open on the display.
- * After this method has been invoked, all related related shells
- * will answer <code>true</code> when sent the message
- * <code>isDisposed()</code>.
- * </p><p>
- * When a device is destroyed, resources that were acquired
- * on behalf of the programmer need to be returned to the
- * operating system. For example, if the device allocated a
- * font to be used as the system font, this font would be
- * freed in <code>release</code>. Also,to assist the garbage
- * collector and minimize the amount of memory that is not
- * reclaimed when the programmer keeps a reference to a
- * disposed device, all fields except the handle are zero'd.
- * The handle is needed by <code>destroy</code>.
- * </p>
- * This method is called before <code>destroy</code>.
- *
- * @see Device#dispose
- * @see #destroy
- */
-protected void release () {
- sendEvent (SWT.Dispose, new Event ());
- Shell [] shells = WidgetTable.shells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) {
- if (this == shell.display) shell.dispose ();
- }
- }
- if (tray != null) tray.dispose ();
- tray = null;
- while (readAndDispatch ()) {}
- if (disposeList != null) {
- for (int i=0; i<disposeList.length; i++) {
- if (disposeList [i] != null) disposeList [i].run ();
- }
- }
- disposeList = null;
- synchronizer.releaseSynchronizer ();
- synchronizer = null;
- releaseDisplay ();
- super.release ();
-}
-
-void releaseDisplay () {
-
- OS.PtDestroyWidget (timerHandle);
-
- /* Free the classes array */
- OS.free (ClassesPtr);
-
- /* Free pulses and input proc */
- OS.PtAppRemoveInput (app_context, input);
- OS.PtAppDeletePulse (app_context, pulse);
-
- /* Free the timers */
- if (timerIds != null) {
- for (int i=0; i<timerIds.length; i++) {
- if (timerIds [i] != 0) OS.PtDestroyWidget (timerIds [i]);
- }
- }
- timerIds = null;
- timerList = null;
- timerProc = 0;
- timerCallback.dispose ();
- timerCallback = null;
-
- /* Free the window proc */
- windowCallback.dispose ();
- windowCallback = null;
-
- /* Free callbacks */
- drawCallback.dispose();
- drawCallback = null;
- workCallback.dispose();
- workCallback = null;
- inputCallback.dispose();
- inputCallback = null;
- hotkeyCallback.dispose();
- hotkeyCallback = null;
-
- if (nullImage != 0) {
- PhImage_t phImage = new PhImage_t();
- OS.memmove(phImage, nullImage, PhImage_t.sizeof);
- phImage.flags = (byte)OS.Ph_RELEASE_IMAGE_ALL;
- OS.memmove(nullImage, phImage, PhImage_t.sizeof);
- OS.PhReleaseImage(nullImage);
- OS.free(nullImage);
- nullImage = 0;
- }
-
- /* Release the System Cursors */
- for (int i = 0; i < cursors.length; i++) {
- if (cursors [i] != null) cursors [i].dispose ();
- }
- cursors = null;
-
- /* Release references */
- thread = null;
- data = null;
- keys = null;
- values = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs anywhere in
- * a widget. The event type is one of the event constants defined
- * in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addFilter
- * @see #addListener
- *
- * @since 3.0
- */
-public void removeFilter (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (filterTable == null) return;
- filterTable.unhook (eventType, listener);
- if (filterTable.size () == 0) filterTable = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs. The event type
- * is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener
- *
- * @since 2.0
- */
-public void removeListener (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, listener);
-}
-
-boolean runAsyncMessages (boolean all) {
- return synchronizer.runAsyncMessages (all);
-}
-
-boolean runDeferredEvents () {
- boolean run = false;
- /*
- * Run deferred events. This code is always
- * called in the Display's thread so it must
- * be re-enterant but need not be synchronized.
- */
- while (eventQueue != null) {
-
- /* Take an event off the queue */
- Event event = eventQueue [0];
- if (event == null) break;
- int length = eventQueue.length;
- System.arraycopy (eventQueue, 1, eventQueue, 0, --length);
- eventQueue [length] = null;
-
- /* Run the event */
- Widget widget = event.widget;
- if (widget != null && !widget.isDisposed ()) {
- Widget item = event.item;
- if (item == null || !item.isDisposed ()) {
- run = true;
- widget.sendEvent (event);
- }
- }
-
- /*
- * At this point, the event queue could
- * be null due to a recursive invokation
- * when running the event.
- */
- }
-
- /* Clear the queue */
- eventQueue = null;
- return run;
-}
-
-void sendEvent (int eventType, Event event) {
- if (eventTable == null && filterTable == null) {
- return;
- }
- if (event == null) event = new Event ();
- event.display = this;
- event.type = eventType;
- if (event.time == 0) event.time = getLastEventTime ();
- if (!filterEvent (event)) {
- if (eventTable != null) eventTable.sendEvent (event);
- }
-}
-
-/**
- * Sets the location of the on-screen pointer relative to the top left corner
- * of the screen. <b>Note: It is typically considered bad practice for a
- * program to move the on-screen pointer location.</b>
- *
- * @param x the new x coordinate for the cursor
- * @param y the new y coordinate for the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1
- */
-public void setCursorLocation (int x, int y) {
- checkDevice ();
- OS.PhMoveCursorAbs (OS.PhInputGroup (0), x, y);
-}
-
-/**
- * Sets the location of the on-screen pointer relative to the top left corner
- * of the screen. <b>Note: It is typically considered bad practice for a
- * program to move the on-screen pointer location.</b>
- *
- * @param point new position
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_NULL_ARGUMENT - if the point is null
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setCursorLocation (Point point) {
- checkDevice ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- setCursorLocation (point.x, point.y);
-}
-
-/**
- * Sets the application defined property of the receiver
- * with the specified name to the given argument.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the display is disposed
- * of, it is the application's responsibility provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param key the name of the property
- * @param value the new value for the property
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getData(String)
- * @see #disposeExec(Runnable)
- */
-public void setData (String key, Object value) {
- checkDevice ();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
-
- /* Remove the key/value pair */
- if (value == null) {
- if (keys == null) return;
- int index = 0;
- while (index < keys.length && !keys [index].equals (key)) index++;
- if (index == keys.length) return;
- if (keys.length == 1) {
- keys = null;
- values = null;
- } else {
- String [] newKeys = new String [keys.length - 1];
- Object [] newValues = new Object [values.length - 1];
- System.arraycopy (keys, 0, newKeys, 0, index);
- System.arraycopy (keys, index + 1, newKeys, index, newKeys.length - index);
- System.arraycopy (values, 0, newValues, 0, index);
- System.arraycopy (values, index + 1, newValues, index, newValues.length - index);
- keys = newKeys;
- values = newValues;
- }
- return;
- }
-
- /* Add the key/value pair */
- if (keys == null) {
- keys = new String [] {key};
- values = new Object [] {value};
- return;
- }
- for (int i=0; i<keys.length; i++) {
- if (keys [i].equals (key)) {
- values [i] = value;
- return;
- }
- }
- String [] newKeys = new String [keys.length + 1];
- Object [] newValues = new Object [values.length + 1];
- System.arraycopy (keys, 0, newKeys, 0, keys.length);
- System.arraycopy (values, 0, newValues, 0, values.length);
- newKeys [keys.length] = key;
- newValues [values.length] = value;
- keys = newKeys;
- values = newValues;
-}
-
-/**
- * Sets the application defined, display specific data
- * associated with the receiver, to the argument.
- * The <em>display specific data</em> is a single,
- * unnamed field that is stored with every display.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the display specific data needs to
- * be notified when the display is disposed of, it is the
- * application's responsibility provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param data the new display specific data
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getData()
- * @see #disposeExec(Runnable)
- */
-public void setData (Object data) {
- checkDevice ();
- this.data = data;
-}
-
-/**
- * Sets the synchronizer used by the display to be
- * the argument, which can not be null.
- *
- * @param synchronizer the new synchronizer for the display (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the synchronizer is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li>
- * </ul>
- */
-public void setSynchronizer (Synchronizer synchronizer) {
- checkDevice ();
- if (synchronizer == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (synchronizer == this.synchronizer) return;
- Synchronizer oldSynchronizer;
- synchronized (Device.class) {
- oldSynchronizer = this.synchronizer;
- this.synchronizer = synchronizer;
- }
- if (oldSynchronizer != null) {
- oldSynchronizer.runAsyncMessages(true);
- }
-}
-
-/**
- * Causes the user-interface thread to <em>sleep</em> (that is,
- * to be put in a state where it does not consume CPU cycles)
- * until an event is received or it is otherwise awakened.
- *
- * @return <code>true</code> if an event requiring dispatching was placed on the queue.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #wake
- */
-public boolean sleep () {
- checkDevice ();
- if (getMessageCount () != 0) return true;
- OS.PtFlush ();
- OS.PtHold ();
- OS.PtAppProcessEvent (app_context);
- runDeferredEvents ();
- OS.PtRelease ();
- return true;
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread at the next
- * reasonable opportunity. The thread which calls this method
- * is suspended until the runnable completes. Specifying <code>null</code>
- * as the runnable simply wakes the user-interface thread.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param runnable code to run on the user-interface thread or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_FAILED_EXEC - if an exception occurred when executing the runnable</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #asyncExec
- */
-public void syncExec (Runnable runnable) {
- Synchronizer synchronizer;
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- synchronizer = this.synchronizer;
- }
- synchronizer.syncExec (runnable);
-}
-
-int textWidth (String string, byte[] font) {
- if (string.length () == 0) return 0;
- byte [] textBuffer = Converter.wcsToMbcs (null, string, false);
- PhRect_t rect = new PhRect_t ();
- OS.PfExtentText(rect, null, font, textBuffer, textBuffer.length);
- if (rect.lr_x == rect.ul_x) return 0;
- return rect.lr_x - rect.ul_x + 1;
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread after the specified
- * number of milliseconds have elapsed. If milliseconds is less
- * than zero, the runnable is not executed.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param milliseconds the delay before running the runnable
- * @param runnable code to run on the user-interface thread
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #asyncExec
- */
-public void timerExec (int milliseconds, Runnable runnable) {
- checkDevice ();
- if (runnable == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (timerList == null) timerList = new Runnable [4];
- if (timerIds == null) timerIds = new int [4];
- int index = 0;
- while (index < timerList.length) {
- if (timerList [index] == runnable) break;
- index++;
- }
- if (index != timerList.length) {
- OS.PtDestroyWidget (timerIds [index]);
- timerList [index] = null;
- timerIds [index] = 0;
- if (milliseconds < 0) return;
- } else {
- if (milliseconds < 0) return;
- index = 0;
- while (index < timerList.length) {
- if (timerList [index] == null) break;
- index++;
- }
- if (index == timerList.length) {
- Runnable [] newTimerList = new Runnable [timerList.length + 4];
- System.arraycopy (timerList, 0, newTimerList, 0, timerList.length);
- timerList = newTimerList;
- int [] newTimerIds = new int [timerIds.length + 4];
- System.arraycopy (timerIds, 0, newTimerIds, 0, timerIds.length);
- timerIds = newTimerIds;
- }
- }
- int [] args = {OS.Pt_ARG_TIMER_INITIAL, milliseconds, 0};
- int timerId = OS.PtCreateWidget (OS.PtTimer (), timerHandle, args.length / 3, args);
- if (timerId != 0) {
- OS.PtRealizeWidget (timerId);
- OS.PtAddCallback (timerId, OS.Pt_CB_TIMER_ACTIVATE, timerProc, index);
- timerIds [index] = timerId;
- timerList [index] = runnable;
- }
-}
-
-int timerProc (int handle, int index, int info) {
- if (timerList == null) return 0;
- if (0 <= index && index < timerList.length) {
- int timerId = timerIds [index];
- Runnable runnable = timerList [index];
- timerList [index] = null;
- timerIds [index] = 0;
- if (runnable != null) runnable.run ();
- OS.PtDestroyWidget (timerId);
- }
- return 0;
-}
-
-static int translateKey (int key) {
- for (int i=0; i<KeyTable.length; i++) {
- if (KeyTable [i] [0] == key) return KeyTable [i] [1];
- }
- return 0;
-}
-
-static int untranslateKey (int key) {
- for (int i=0; i<KeyTable.length; i++) {
- if (KeyTable [i] [1] == key) return KeyTable [i] [0];
- }
- return 0;
-}
-
-/**
- * Forces all outstanding paint requests for the display
- * to be processed before this method returns.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Control#update()
- */
-public void update() {
- checkDevice ();
- Shell[] shells = WidgetTable.shells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed () && this == shell.display) {
- shell.update ();
- }
- }
-}
-
-/**
- * If the receiver's user-interface thread was <code>sleep</code>ing,
- * causes it to be awakened and start running again. Note that this
- * method may be called from any thread.
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #sleep
- */
-public void wake () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- if (thread == Thread.currentThread ()) return;
- wakeThread ();
- }
-}
-
-void wakeThread () {
-// int flags = OS.PtEnter (0);
- OS.PtAppPulseTrigger (app_context, pulse);
-// if (flags >= 0) OS.PtLeave (flags);
-}
-
-int windowProc (int handle, int data, int info) {
- Widget widget = WidgetTable.get (handle);
- if (widget == null) return OS.Pt_CONTINUE;
- return widget.windowProc (handle, data, info);
-}
-
-int workProc (int data) {
- idle = true;
- return OS.Pt_CONTINUE;
-}
-
-String wrapText (String text, byte[] font, int width) {
- text = convertToLf (text);
- int length = text.length ();
- if (width <= 0 || length == 0 || length == 1) return text;
- StringBuffer result = new StringBuffer ();
- int lineStart = 0, lineEnd = 0;
- while (lineStart < length) {
- lineEnd = text.indexOf ('\n', lineStart);
- boolean noLf = lineEnd == -1;
- if (noLf) lineEnd = length;
- int nextStart = lineEnd + 1;
- while (lineEnd > lineStart + 1 && Compatibility.isWhitespace (text.charAt (lineEnd - 1))) {
- lineEnd--;
- }
- int wordStart = lineStart, wordEnd = lineStart;
- int i = lineStart;
- while (i < lineEnd) {
- int lastStart = wordStart, lastEnd = wordEnd;
- wordStart = i;
- while (i < lineEnd && !Compatibility.isWhitespace (text.charAt (i))) {
- i++;
- }
- wordEnd = i - 1;
- String line = text.substring (lineStart, wordEnd + 1);
- int lineWidth = textWidth (line, font);
- while (i < lineEnd && Compatibility.isWhitespace (text.charAt (i))) {
- i++;
- }
- if (lineWidth > width) {
- if (lastStart == wordStart) {
- while (wordStart < wordEnd) {
- line = text.substring (lineStart, wordStart + 1);
- lineWidth = textWidth (line, font);
- if (lineWidth >= width) break;
- wordStart++;
- }
- if (wordStart == lastStart) wordStart++;
- lastEnd = wordStart - 1;
- }
- line = text.substring (lineStart, lastEnd + 1);
- result.append (line); result.append ('\n');
- i = wordStart; lineStart = wordStart; wordEnd = wordStart;
- }
- }
- if (lineStart < lineEnd) {
- result.append (text.substring (lineStart, lineEnd));
- }
- if (!noLf) {
- result.append ('\n');
- }
- lineStart = nextStart;
- }
- return result.toString ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/FileDialog.java
deleted file mode 100755
index 09559bb192..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/FileDialog.java
+++ /dev/null
@@ -1,369 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class allow the user to navigate
- * the file system and select or enter a file name.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SAVE, OPEN, MULTI</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles SAVE and OPEN may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#filedialog">FileDialog snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class FileDialog extends Dialog {
- String [] filterNames = new String [0];
- String [] filterExtensions = new String [0];
- String filterPath = "", fileName = "";
- int filterIndex = -1;
- boolean overwrite = false;
- static final String FILTER = "*";
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FileDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SAVE
- * @see SWT#OPEN
- * @see SWT#MULTI
- */
-public FileDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-/**
- * Returns the path of the first file that was
- * selected in the dialog relative to the filter path, or an
- * empty string if no such file has been selected.
- *
- * @return the relative path of the file
- */
-public String getFileName () {
- return fileName;
-}
-
-/**
- * Returns a (possibly empty) array with the paths of all files
- * that were selected in the dialog relative to the filter path.
- *
- * @return the relative paths of the files
- */
-public String [] getFileNames () {
- if (fileName.length () == 0) return new String [0];
- return new String [] {fileName};
-}
-
-/**
- * Returns the file extensions which the dialog will
- * use to filter the files it shows.
- *
- * @return the file extensions filter
- */
-public String [] getFilterExtensions () {
- return filterExtensions;
-}
-
-/**
- * Get the 0-based index of the file extension filter
- * which was selected by the user, or -1 if no filter
- * was selected.
- * <p>
- * This is an index into the FilterExtensions array and
- * the FilterNames array.
- * </p>
- *
- * @return index the file extension filter index
- *
- * @see #getFilterExtensions
- * @see #getFilterNames
- *
- * @since 3.4
- */
-public int getFilterIndex () {
- return filterIndex;
-}
-
-/**
- * Returns the names that describe the filter extensions
- * which the dialog will use to filter the files it shows.
- *
- * @return the list of filter names
- */
-public String [] getFilterNames () {
- return filterNames;
-}
-
-/**
- * Returns the directory path that the dialog will use, or an empty
- * string if this is not set. File names in this path will appear
- * in the dialog, filtered according to the filter extensions.
- *
- * @return the directory path string
- *
- * @see #setFilterExtensions
- */
-public String getFilterPath () {
- return filterPath;
-}
-
-/**
- * Returns the flag that the dialog will use to
- * determine whether to prompt the user for file
- * overwrite if the selected file already exists.
- *
- * @return true if the dialog will prompt for file overwrite, false otherwise
- *
- * @since 3.4
- */
-public boolean getOverwrite () {
- return overwrite;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a string describing the absolute path of the first selected file,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public String open () {
- int parentHandle = 0;
- if (parent != null && OS.PtWidgetIsRealized(parent.shellHandle)) {
- parentHandle = parent.shellHandle;
- }
- byte [] title = null;
- if (this.title != null) title = Converter.wcsToMbcs (null, this.title, true);
- byte [] root_dir = null;
- if (filterPath != null) {
- root_dir = Converter.wcsToMbcs (null, filterPath, true);
- }
-
- /* Compute the filter */
- String mask = FILTER;
- /*
- * Photon does not support filter names.
- */
- if (filterNames == null) filterNames = new String [0];
- /*
- * Photon supports only one filter with multiple patterns
- * separated by commas.
- */
- if (filterExtensions == null) filterExtensions = new String [0];
- if (filterExtensions.length > 0) {
- String comma = ",";
- mask = comma;
- for (int i=0; i<filterExtensions.length; i++) {
- String ext = filterExtensions [i];
- int length = ext.length();
- int end, start = 0;
- do {
- end = ext.indexOf(';', start);
- if (end < 0) end = length;
- String subExt = ext.substring(start, end).trim();
- if (subExt.length() > 0) {
- subExt += comma;
- if (mask.indexOf(comma + subExt) == -1) mask += subExt;
- }
- start = end + 1;
- } while (end < length);
- }
- mask = mask.substring(1, Math.max(1, mask.length() - 1));
- }
- byte [] file_spec = Converter.wcsToMbcs (null, mask, true);
- byte [] btn1_text = null;
- if ((style & SWT.SAVE) != 0) {
- btn1_text = Converter.wcsToMbcs(null, SWT.getMessage("SWT_Save"), true);
- }
- int flags = OS.Pt_FSR_NO_FCHECK;
- PtFileSelectionInfo_t info = new PtFileSelectionInfo_t ();
- OS.PtFileSelection (parentHandle, null, title, root_dir, file_spec, btn1_text, null, null, info, flags);
- if (info.ret == OS.Pt_FSDIALOG_BTN2) return null;
- int length = 0;
- while (length < info.path.length && info.path [length] != 0) length++;
- byte [] path = new byte [length];
- System.arraycopy (info.path, 0, path, 0, length);
- String fullPath = new String (Converter.mbcsToWcs (null, path));
- length = fullPath.length ();
- if (length != 0) {
- int index = length - 1;
- while (index >= 0 && (fullPath.charAt (index) != '/')) --index;
- fileName = fullPath.substring (index + 1, length);
- filterPath = fullPath.substring (0, index);
- filterIndex = filterExtensions == null || filterExtensions.length == 0 ? -1 : 0;
- }
- return fullPath;
-}
-
-/**
- * Set the initial filename which the dialog will
- * select by default when opened to the argument,
- * which may be null. The name will be prefixed with
- * the filter path when one is supplied.
- *
- * @param string the file name
- */
-public void setFileName (String string) {
- fileName = string;
-}
-
-/**
- * Set the file extensions which the dialog will
- * use to filter the files it shows to the argument,
- * which may be null.
- * <p>
- * The strings are platform specific. For example, on
- * some platforms, an extension filter string is typically
- * of the form "*.extension", where "*.*" matches all files.
- * For filters with multiple extensions, use semicolon as
- * a separator, e.g. "*.jpg;*.png".
- * </p>
- *
- * @param extensions the file extension filter
- *
- * @see #setFilterNames to specify the user-friendly
- * names corresponding to the extensions
- */
-public void setFilterExtensions (String [] extensions) {
- filterExtensions = extensions;
-}
-
-/**
- * Set the 0-based index of the file extension filter
- * which the dialog will use initially to filter the files
- * it shows to the argument.
- * <p>
- * This is an index into the FilterExtensions array and
- * the FilterNames array.
- * </p>
- *
- * @param index the file extension filter index
- *
- * @see #setFilterExtensions
- * @see #setFilterNames
- *
- * @since 3.4
- */
-public void setFilterIndex (int index) {
- filterIndex = index;
-}
-
-/**
- * Sets the names that describe the filter extensions
- * which the dialog will use to filter the files it shows
- * to the argument, which may be null.
- * <p>
- * Each name is a user-friendly short description shown for
- * its corresponding filter. The <code>names</code> array must
- * be the same length as the <code>extensions</code> array.
- * </p>
- *
- * @param names the list of filter names, or null for no filter names
- *
- * @see #setFilterExtensions
- */
-public void setFilterNames (String [] names) {
- filterNames = names;
-}
-
-/**
- * Sets the directory path that the dialog will use
- * to the argument, which may be null. File names in this
- * path will appear in the dialog, filtered according
- * to the filter extensions. If the string is null,
- * then the operating system's default filter path
- * will be used.
- * <p>
- * Note that the path string is platform dependent.
- * For convenience, either '/' or '\' can be used
- * as a path separator.
- * </p>
- *
- * @param string the directory path
- *
- * @see #setFilterExtensions
- */
-public void setFilterPath (String string) {
- filterPath = string;
-}
-
-/**
- * Sets the flag that the dialog will use to
- * determine whether to prompt the user for file
- * overwrite if the selected file already exists.
- *
- * @param overwrite true if the dialog will prompt for file overwrite, false otherwise
- *
- * @since 3.4
- */
-public void setOverwrite (boolean overwrite) {
- //this.overwrite = overwrite;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/FontDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/FontDialog.java
deleted file mode 100755
index cc914ff2c2..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/FontDialog.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class allow the user to select a font
- * from all available fonts in the system.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class FontDialog extends Dialog {
- FontData fontData;
- RGB rgb;
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FontDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FontDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-/**
- * Returns a FontData object describing the font that was
- * selected in the dialog, or null if none is available.
- *
- * @return the FontData for the selected font, or null
- * @deprecated use #getFontList ()
- */
-public FontData getFontData () {
- return fontData;
-}
-/**
- * Returns a FontData set describing the font that was
- * selected in the dialog, or null if none is available.
- *
- * @return the FontData for the selected font, or null
- * @since 2.1.1
- */
-public FontData [] getFontList () {
- if (fontData == null) return null;
- FontData [] result = new FontData [1];
- result [0] = fontData;
- return result;
-}
-/**
- * Returns an RGB describing the color that was selected
- * in the dialog, or null if none is available.
- *
- * @return the RGB value for the selected color, or null
- *
- * @see PaletteData#getRGBs
- *
- * @since 2.1
- */
-public RGB getRGB () {
- return rgb;
-}
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a FontData object describing the font that was selected,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public FontData open () {
- int parentHandle = 0;
- if (parent != null && OS.PtWidgetIsRealized(parent.shellHandle)) {
- parentHandle = parent.shellHandle;
- }
- byte [] title = null;
- if (this.title != null) title = Converter.wcsToMbcs (null, this.title, true);
-
- byte[] font = null;
- if (fontData != null) {
- if (fontData.stem != null) {
- font = fontData.stem;
- } else {
- byte[] description = Converter.wcsToMbcs(null, fontData.getName(), true);
- int osStyle = 0, style = fontData.getStyle();
- if ((style & SWT.BOLD) != 0) osStyle |= OS.PF_STYLE_BOLD;
- if ((style & SWT.ITALIC) != 0) osStyle |= OS.PF_STYLE_ITALIC;
- int size = fontData.getHeight();
- byte [] buffer = new byte[OS.MAX_FONT_TAG];
- if (OS.PfGenerateFontName(description, osStyle, size, buffer) != 0) font = buffer;
- }
- fontData = null;
- }
-
- int flags = OS.PHFONT_ALL_FONTS | OS.PHFONT_DONT_SHOW_LEGACY;
- int fontPtr = OS.PtFontSelection (parentHandle, null, title, font, OS.PHFONT_ALL_SYMBOLS, flags, null);
-
- if (fontPtr != 0) {
- int length = OS.strlen (fontPtr);
- font = new byte [length + 1];
- OS.memmove (font, fontPtr, length);
- fontData = FontData.photon_new (font);
- }
- return fontData;
-}
-/**
- * Sets a FontData object describing the font to be
- * selected by default in the dialog, or null to let
- * the platform choose one.
- *
- * @param fontData the FontData to use initially, or null
- * @deprecated use #setFontList (FontData [])
- */
-public void setFontData (FontData fontData) {
- this.fontData = fontData;
-}
-/**
- * Sets the set of FontData objects describing the font to
- * be selected by default in the dialog, or null to let
- * the platform choose one.
- *
- * @param fontData the set of FontData objects to use initially, or null
- * to let the platform select a default when open() is called
- *
- * @see Font#getFontData
- *
- * @since 2.1.1
- */
-public void setFontList (FontData [] fontData) {
- if (fontData != null && fontData.length > 0) {
- this.fontData = fontData [0];
- } else {
- this.fontData = null;
- }
-}
-/**
- * Sets the RGB describing the color to be selected by default
- * in the dialog, or null to let the platform choose one.
- *
- * @param rgb the RGB value to use initially, or null to let
- * the platform select a default when open() is called
- *
- * @see PaletteData#getRGBs
- *
- * @since 2.1
- */
-public void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Group.java
deleted file mode 100755
index 2abdc6a410..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Group.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide an etched border
- * with an optional title.
- * <p>
- * Shadow styles are hints and may not be honoured
- * by the platform. To create a group with the
- * default shadow style for the platform, do not
- * specify a shadow style.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SHADOW_ETCHED_IN, SHADOW_ETCHED_OUT, SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the above styles may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Group extends Composite {
- String text = "";
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SHADOW_ETCHED_IN
- * @see SWT#SHADOW_ETCHED_OUT
- * @see SWT#SHADOW_IN
- * @see SWT#SHADOW_OUT
- * @see SWT#SHADOW_NONE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Group (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- Point titleSize = getTitleSize();
- Point size;
- if (layout != null) {
- changed |= (state & LAYOUT_CHANGED) != 0;
- size = layout.computeSize (this, wHint, hHint, changed);
- state &= ~LAYOUT_CHANGED;
- } else {
- size = minimumSize ();
- }
- int width = size.x; int height = size.y;
- if (width == 0) width = DEFAULT_WIDTH;
- if (height == 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- Rectangle trim = computeTrim (0, 0, width, height);
- width = Math.max (trim.width, titleSize.x + 6);
- height = trim.height + titleSize.y;
- return new Point (width, height);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- int clazz = display.PtContainer;
- int parentHandle = parent.parentingHandle ();
- int [] args = {
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (clazz, parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-
-byte [] defaultFont () {
- return display.GROUP_FONT;
-}
-
-/**
- * Returns the receiver's text, which is the string that the
- * is used as the <em>title</em>. If the text has not previously
- * been set, returns an empty string.
- *
- * @return the text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- return text;
-}
-
-Point getTitleSize() {
- int width = 0, height = 0;
- int [] args = {
- OS.Pt_ARG_TITLE, 0, 0,
- OS.Pt_ARG_TITLE_FONT, 0, 0,
- OS.Pt_ARG_CONTAINER_FLAGS, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- if ((OS.Pt_ARG_CONTAINER_FLAGS & OS.Pt_SHOW_TITLE) != 0) {
- PhRect_t rect = new PhRect_t();
- int str = args [1];
- if (str != 0) {
- int length = OS.strlen (str);
- if (length > 0) {
- OS.PfExtentText(rect, null, args [4], str, length);
- }
- }
- int inset = 4;
- width = inset + rect.lr_x - rect.ul_x + 1;
- height = inset + rect.lr_y - rect.ul_y + 1;
- }
- return new Point(width, height);
-}
-
-/**
- * Sets the receiver's text, which is the string that will
- * be displayed as the receiver's <em>title</em>, to the argument,
- * which may not be null. The string may include the mnemonic character.
- * </p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, focus is assigned
- * to the first child of the group. On most platforms, the
- * mnemonic appears underlined but may be emphasised in a
- * platform specific manner. The mnemonic indicator character
- * '&amp;' can be escaped by doubling it in the string, causing
- * a single '&amp;' to be displayed.
- * </p>
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- text = string;
- int flags = OS.Pt_SHOW_TITLE | OS.Pt_ETCH_TITLE_AREA;
- char [] text = new char [string.length ()];
- string.getChars (0, text.length, text, 0);
- fixMnemonic (text);
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- int ptr = OS.malloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- int [] args = {
- OS.Pt_ARG_TITLE, ptr, 0,
- OS.Pt_ARG_CONTAINER_FLAGS, string.length () == 0 ? 0 : flags, flags,
- };
- OS.PtSetResources (handle, args.length / 3, args);
- OS.free (ptr);
-}
-
-int widgetClass () {
- return OS.PtContainer ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Label.java
deleted file mode 100755
index e1b7191c87..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Label.java
+++ /dev/null
@@ -1,464 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a non-selectable
- * user interface object that displays a string or image.
- * When SEPARATOR is specified, displays a single
- * vertical or horizontal line.
- * <p>
- * Shadow styles are hints and may not be honored
- * by the platform. To create a separator label
- * with the default shadow style for the platform,
- * do not specify a shadow style.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SEPARATOR, HORIZONTAL, VERTICAL</dd>
- * <dd>SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd>
- * <dd>CENTER, LEFT, RIGHT, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of SHADOW_IN, SHADOW_OUT and SHADOW_NONE may be specified.
- * SHADOW_NONE is a HINT. Only one of HORIZONTAL and VERTICAL may be specified.
- * Only one of CENTER, LEFT and RIGHT may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#label">Label snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Label extends Control {
- String text = "";
- Image image;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SEPARATOR
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#SHADOW_IN
- * @see SWT#SHADOW_OUT
- * @see SWT#SHADOW_NONE
- * @see SWT#CENTER
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#WRAP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Label (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- if ((style & SWT.SEPARATOR) != 0) {
- style = checkBits (style, SWT.VERTICAL, SWT.HORIZONTAL, 0, 0, 0, 0);
- return checkBits (style, SWT.SHADOW_OUT, SWT.SHADOW_IN, SWT.SHADOW_NONE, 0, 0, 0);
- }
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) {
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += DEFAULT_WIDTH; height += 3;
- } else {
- width += 3; height += DEFAULT_HEIGHT;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
- }
-
- if ((style & SWT.WRAP) != 0) {
- int [] args = {
- OS.Pt_ARG_LABEL_TYPE, 0, 0, // 1
- OS.Pt_ARG_TEXT_FONT, 0, 0, // 4
- OS.Pt_ARG_LINE_SPACING, 0, 0, // 7
- OS.Pt_ARG_MARGIN_WIDTH, 0, 0, // 10
- OS.Pt_ARG_MARGIN_HEIGHT, 0, 0, // 13
- OS.Pt_ARG_MARGIN_LEFT, 0, 0, // 16
- OS.Pt_ARG_MARGIN_RIGHT, 0, 0, // 19
- OS.Pt_ARG_MARGIN_TOP, 0, 0, // 22
- OS.Pt_ARG_MARGIN_BOTTOM, 0, 0, // 25
- };
- OS.PtGetResources (handle, args.length / 3, args);
- /* If we are wrapping text, calculate the height based on wHint. */
- if (args [1] == OS.Pt_Z_STRING) {
- int width = wHint, height = hHint;
- if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
- int length = OS.strlen (args [4]);
- byte [] font = new byte [length + 1];
- OS.memmove (font, args [4], length);
- String string = text;
- if (wHint != SWT.DEFAULT) {
- string = display.wrapText (text, font, wHint);
- }
- byte [] buffer = Converter.wcsToMbcs (null, string, false);
- PhRect_t rect = new PhRect_t ();
- OS.PgExtentMultiText (rect, null, font, buffer, buffer.length, args [7]);
- if (wHint == SWT.DEFAULT) width = rect.lr_x - rect.ul_x + 1;
- if (hHint == SWT.DEFAULT) height = rect.lr_y - rect.ul_y + 1;
- }
- PhArea_t area = new PhArea_t ();
- PhRect_t rect = new PhRect_t ();
- OS.PtSetAreaFromWidgetCanvas (handle, rect, area);
- width += (area.size_w - 1) + (args [10] * 2) + args [16] + args [19];
- height += (area.size_h - 1) + (args [13] * 2) + args [22] + args [25];
- return new Point (width, height);
- }
- }
-
- PhDim_t dim = new PhDim_t();
- if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidget (handle);
- OS.PtWidgetPreferredSize(handle, dim);
- int width = dim.w, height = dim.h;
- if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) {
- int [] args = {
- OS.Pt_ARG_MARGIN_WIDTH, 0, 0, // 1
- OS.Pt_ARG_MARGIN_HEIGHT, 0, 0, // 4
- OS.Pt_ARG_MARGIN_LEFT, 0, 0, // 7
- OS.Pt_ARG_MARGIN_RIGHT, 0, 0, // 10
- OS.Pt_ARG_MARGIN_TOP, 0, 0, // 13
- OS.Pt_ARG_MARGIN_BOTTOM, 0, 0, // 16
- };
- OS.PtGetResources (handle, args.length / 3, args);
- PhRect_t rect = new PhRect_t ();
- PhArea_t area = new PhArea_t ();
- rect.lr_x = (short) (wHint - 1);
- rect.lr_y = (short) (hHint - 1);
- OS.PtSetAreaFromWidgetCanvas (handle, rect, area);
- if (wHint != SWT.DEFAULT) {
- width = area.size_w + (args [1] * 2) + args [7] + args [10];
- }
- if (hHint != SWT.DEFAULT) {
- height = area.size_h + (args [4] * 2) + args [13] + args [16];
- }
- }
- return new Point (width, height);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- int parentHandle = parent.parentingHandle ();
-
- if ((style & SWT.SEPARATOR) != 0) {
- int clazz = display.PtSeparator;
- int orientation = (style & SWT.HORIZONTAL) != 0 ? OS.Pt_SEP_HORIZONTAL : OS.Pt_SEP_VERTICAL;
- int type = OS.Pt_ETCHED_IN;
- if ((style & (SWT.SHADOW_OUT)) != 0) type = OS.Pt_ETCHED_OUT;
- int [] args = {
- OS.Pt_ARG_SEP_FLAGS, orientation, OS.Pt_SEP_VERTICAL | OS.Pt_SEP_HORIZONTAL,
- OS.Pt_ARG_SEP_TYPE, type, 0,
- OS.Pt_ARG_FILL_COLOR, display.WIDGET_BACKGROUND, 0,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (clazz, parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- return;
- }
-
- int clazz = display.PtLabel;
- int alignment = OS.Pt_LEFT;
- if ((style & SWT.CENTER) != 0) alignment = OS.Pt_CENTER;
- if ((style & SWT.RIGHT) != 0) alignment = OS.Pt_RIGHT;
- int verticalAlign = (style & SWT.WRAP) != 0 ? OS.Pt_TOP : OS.Pt_CENTER;
- boolean hasBorder = (style & SWT.BORDER) != 0;
- int [] args = {
- OS.Pt_ARG_FLAGS, hasBorder ? OS.Pt_HIGHLIGHTED : 0, OS.Pt_HIGHLIGHTED,
- OS.Pt_ARG_HORIZONTAL_ALIGNMENT, alignment, 0,
- OS.Pt_ARG_VERTICAL_ALIGNMENT, verticalAlign, 0,
- OS.Pt_ARG_FILL_COLOR, display.WIDGET_BACKGROUND, 0,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (clazz, parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is a <code>SEPARATOR</code> label, in
- * which case, <code>NONE</code> is returned.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return 0;
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-/**
- * Returns the receiver's image if it has one, or null
- * if it does not.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set or if the receiver is
- * a <code>SEPARATOR</code> label.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return "";
- return text;
-}
-
-int hotkeyProc (int widget, int data, int info) {
- Composite control = this.parent;
- while (control != null) {
- Control [] children = control._getChildren ();
- int index = 0;
- while (index < children.length) {
- if (children [index] == this) break;
- index++;
- }
- index++;
- if (index < children.length) {
- if (children [index].setFocus ()) return OS.Pt_CONTINUE;
- }
- control = control.parent;
- }
- return OS.Pt_CONTINUE;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- image = null;
- text = null;
-}
-
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>. If the receiver is a <code>SEPARATOR</code>
- * label, the argument is ignored and the alignment is not changed.
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return;
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- int align = OS.Pt_LEFT;
- if ((style & SWT.CENTER) != 0) align = OS.Pt_CENTER;
- if ((style & SWT.RIGHT) != 0) align = OS.Pt_RIGHT;
- OS.PtSetResource (handle, OS.Pt_ARG_HORIZONTAL_ALIGNMENT, align, 0);
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- int result = super.setBounds (x, y, width, height, move, resize, events);
- if ((result & RESIZED) != 0 && (style & SWT.WRAP) != 0) setText (text);
- return result;
-}
-
-public void setFont (Font font) {
- super.setFont (font);
- if ((style & SWT.WRAP) != 0) setText (text);
-}
-
-/**
- * Sets the receiver's image to the argument, which may be
- * null indicating that no image should be displayed.
- *
- * @param image the image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return;
- this.image = image;
- int imageHandle = 0;
- if (image != null) {
- if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- imageHandle = copyPhImage (image.handle);
- }
- int [] args = {
- OS.Pt_ARG_LABEL_IMAGE, imageHandle, 0,
- OS.Pt_ARG_LABEL_TYPE, OS.Pt_IMAGE, 0
- };
- OS.PtSetResources (handle, args.length / 3, args);
- if (imageHandle != 0) OS.free (imageHandle);
-}
-
-/**
- * Sets the receiver's text.
- * <p>
- * This method sets the widget label. The label may include
- * the mnemonic character and line delimiters.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, focus is assigned
- * to the control that follows the label. On most platforms,
- * the mnemonic appears underlined but may be emphasised in a
- * platform specific manner. The mnemonic indicator character
- * '&amp;' can be escaped by doubling it in the string, causing
- * a single '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- text = string;
- char [] text = new char [string.length ()];
- string.getChars (0, text.length, text, 0);
- char mnemonic = fixMnemonic (text);
- /* Wrap the text if necessary, and convert to mbcs. */
- byte [] buffer;
- if ((style & SWT.WRAP) != 0) {
- int [] args = {
- OS.Pt_ARG_TEXT_FONT, 0, 0, // 1
- OS.Pt_ARG_WIDTH, 0, 0, // 4
- OS.Pt_ARG_MARGIN_WIDTH, 0, 0, // 7
- OS.Pt_ARG_MARGIN_LEFT, 0, 0, // 10
- OS.Pt_ARG_MARGIN_RIGHT, 0, 0, // 13
- };
- OS.PtGetResources (handle, args.length / 3, args);
- int length = OS.strlen (args [1]);
- byte [] font = new byte [length + 1];
- OS.memmove (font, args [1], length);
- int border = 0;
- if ((style & SWT.BORDER) != 0) border = 2;
- int width = args [4];
- width -= (args [7] * 2) + args [10] + args [13] + border * 2;
- string = display.wrapText (new String (text), font, width);
- buffer = Converter.wcsToMbcs (null, string, true);
- } else {
- buffer = Converter.wcsToMbcs (null, text, true);
- }
- int ptr1 = OS.malloc (buffer.length);
- OS.memmove (ptr1, buffer, buffer.length);
- int ptr2 = 0;
- if (mnemonic != 0) {
- byte [] buffer2 = Converter.wcsToMbcs (null, new char []{mnemonic}, true);
- ptr2 = OS.malloc (buffer2.length);
- OS.memmove (ptr2, buffer2, buffer2.length);
- }
- replaceMnemonic (mnemonic, true, true);
- int [] args = {
- OS.Pt_ARG_TEXT_STRING, ptr1, 0,
- OS.Pt_ARG_LABEL_TYPE, OS.Pt_Z_STRING, 0,
- OS.Pt_ARG_ACCEL_KEY, ptr2, 0,
- };
- OS.PtSetResources (handle, args.length / 3, args);
- OS.free (ptr1);
- OS.free (ptr2);
-}
-
-int traversalCode (int key_sym, PhKeyEvent_t ke) {
- return 0;
-}
-
-int widgetClass () {
- if ((style & SWT.SEPARATOR) != 0) return OS.PtSeparator ();
- return OS.PtLabel ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Link.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Link.java
deleted file mode 100644
index 4864a59b91..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Link.java
+++ /dev/null
@@ -1,680 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable
- * user interface object that displays a text with
- * links.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#link">Link snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Link extends Control {
- String text;
- TextLayout layout;
- Color linkColor, disabledColor;
- Point [] offsets;
- Point selection;
- String [] ids;
- int [] mnemonics;
- int focusIndex;
-
- static final RGB LINK_FOREGROUND = new RGB (0, 51, 153);
- static final RGB LINK_DISABLED_FOREGROUND = new RGB (172, 168, 153);
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Link (Composite parent, int style) {
- super (parent, style);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected by the user.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- int width, height;
- int layoutWidth = layout.getWidth ();
- //TEMPORARY CODE
- if (wHint == 0) {
- layout.setWidth (1);
- Rectangle rect = layout.getBounds ();
- width = 0;
- height = rect.height;
- } else {
- layout.setWidth (wHint);
- Rectangle rect = layout.getBounds ();
- width = rect.width;
- height = rect.height;
- }
- layout.setWidth (layoutWidth);
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2;
- height += border * 2;
- return new Point (width, height);
-}
-
-void createHandle (int index) {
- SWT.error(SWT.ERROR_NOT_IMPLEMENTED);//tmp code
- state |= HANDLE;
- int clazz = display.PtContainer;
- int parentHandle = parent.parentingHandle ();
- int [] args = {
- OS.Pt_ARG_FLAGS, 0, OS.Pt_GETS_FOCUS,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (clazz, parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-
- layout = new TextLayout (display);
- linkColor = new Color (display, LINK_FOREGROUND);
- disabledColor = new Color (display, LINK_DISABLED_FOREGROUND);
- offsets = new Point [0];
- ids = new String [0];
- mnemonics = new int [0];
- selection = new Point (-1, -1);
- focusIndex = -1;
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- text = "";
- //TODO accessibility
-}
-
-void drawWidget(int widget, int damage) {
- //super.drawWidget(widget, damage);
- int selStart = selection.x;
- int selEnd = selection.y;
- if (selStart > selEnd) {
- selStart = selection.y;
- selEnd = selection.x;
- }
- // temporary code to disable text selection
- selStart = selEnd = -1;
- GCData data = new GCData();
- if (OS.QNX_MAJOR > 6 || (OS.QNX_MAJOR == 6 && (OS.QNX_MINOR > 2 || (OS.QNX_MINOR == 2 && OS.QNX_MICRO >= 1)))) {
- data.paint = true;
- }
- GC gc = GC.photon_new (this, data);
- //set clipping on the GC?
- if ((state & DISABLED) != 0) gc.setForeground (disabledColor);
- layout.draw (gc, 0, 0, selStart, selEnd, null, null);
- if (hasFocus () && focusIndex != -1) {
- Rectangle [] rects = getRectangles (focusIndex);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rectangle = rects [i];
- gc.drawFocus (rectangle.x, rectangle.y, rectangle.width, rectangle.height);
- }
- }
- gc.dispose ();
-}
-
-String getNameText () {
- return getText ();
-}
-
-Rectangle [] getRectangles (int linkIndex) {
- int lineCount = layout.getLineCount ();
- Rectangle [] rects = new Rectangle [lineCount];
- int [] lineOffsets = layout.getLineOffsets ();
- Point point = offsets [linkIndex];
- int lineStart = 1;
- while (point.x > lineOffsets [lineStart]) lineStart++;
- int lineEnd = 1;
- while (point.y > lineOffsets [lineEnd]) lineEnd++;
- int index = 0;
- if (lineStart == lineEnd) {
- rects [index++] = layout.getBounds (point.x, point.y);
- } else {
- rects [index++] = layout.getBounds (point.x, lineOffsets [lineStart]-1);
- rects [index++] = layout.getBounds (lineOffsets [lineEnd-1], point.y);
- if (lineEnd - lineStart > 1) {
- for (int i = lineStart; i < lineEnd - 1; i++) {
- rects [index++] = layout.getLineBounds (i);
- }
- }
- }
- if (rects.length != index) {
- Rectangle [] tmp = new Rectangle [index];
- System.arraycopy (rects, 0, tmp, 0, index);
- rects = tmp;
- }
- return rects;
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- TextStyle linkStyle = new TextStyle (null, enabled ? linkColor : disabledColor, null);
- linkStyle.underline = true;
- for (int i = 0; i < offsets.length; i++) {
- Point point = offsets [i];
- layout.setStyle (linkStyle, point.x, point.y);
- }
- redraw ();
-}
-
-String parse (String string) {
- int length = string.length ();
- offsets = new Point [length / 4];
- ids = new String [length / 4];
- mnemonics = new int [length / 4 + 1];
- StringBuffer result = new StringBuffer ();
- char [] buffer = new char [length];
- string.getChars (0, string.length (), buffer, 0);
- int index = 0, state = 0, linkIndex = 0;
- int start = 0, tagStart = 0, linkStart = 0, endtagStart = 0, refStart = 0;
- while (index < length) {
- char c = Character.toLowerCase (buffer [index]);
- switch (state) {
- case 0:
- if (c == '<') {
- tagStart = index;
- state++;
- }
- break;
- case 1:
- if (c == 'a') state++;
- break;
- case 2:
- switch (c) {
- case 'h':
- state = 7;
- break;
- case '>':
- linkStart = index + 1;
- state++;
- break;
- default:
- if (Character.isWhitespace(c)) break;
- else state = 13;
- }
- break;
- case 3:
- if (c == '<') {
- endtagStart = index;
- state++;
- }
- break;
- case 4:
- state = c == '/' ? state + 1 : 3;
- break;
- case 5:
- state = c == 'a' ? state + 1 : 3;
- break;
- case 6:
- if (c == '>') {
- mnemonics [linkIndex] = parseMnemonics (buffer, start, tagStart, result);
- int offset = result.length ();
- parseMnemonics (buffer, linkStart, endtagStart, result);
- offsets [linkIndex] = new Point (offset, result.length () - 1);
- if (ids [linkIndex] == null) {
- ids [linkIndex] = new String (buffer, linkStart, endtagStart - linkStart);
- }
- linkIndex++;
- start = tagStart = linkStart = endtagStart = refStart = index + 1;
- state = 0;
- } else {
- state = 3;
- }
- break;
- case 7:
- state = c == 'r' ? state + 1 : 0;
- break;
- case 8:
- state = c == 'e' ? state + 1 : 0;
- break;
- case 9:
- state = c == 'f' ? state + 1 : 0;
- break;
- case 10:
- state = c == '=' ? state + 1 : 0;
- break;
- case 11:
- if (c == '"') {
- state++;
- refStart = index + 1;
- } else {
- state = 0;
- }
- break;
- case 12:
- if (c == '"') {
- ids[linkIndex] = new String (buffer, refStart, index - refStart);
- state = 2;
- }
- break;
- case 13:
- if (Character.isWhitespace (c)) {
- state = 0;
- } else if (c == '='){
- state++;
- }
- break;
- case 14:
- state = c == '"' ? state + 1 : 0;
- break;
- case 15:
- if (c == '"') state = 2;
- break;
- default:
- state = 0;
- break;
- }
- index++;
- }
- if (start < length) {
- int tmp = parseMnemonics (buffer, start, tagStart, result);
- int mnemonic = parseMnemonics (buffer, Math.max (tagStart, linkStart), length, result);
- if (mnemonic == -1) mnemonic = tmp;
- mnemonics [linkIndex] = mnemonic;
- } else {
- mnemonics [linkIndex] = -1;
- }
- if (offsets.length != linkIndex) {
- Point [] newOffsets = new Point [linkIndex];
- System.arraycopy (offsets, 0, newOffsets, 0, linkIndex);
- offsets = newOffsets;
- String [] newIDs = new String [linkIndex];
- System.arraycopy (ids, 0, newIDs, 0, linkIndex);
- ids = newIDs;
- int [] newMnemonics = new int [linkIndex + 1];
- System.arraycopy (mnemonics, 0, newMnemonics, 0, linkIndex + 1);
- mnemonics = newMnemonics;
- }
- return result.toString ();
-}
-
-int parseMnemonics (char[] buffer, int start, int end, StringBuffer result) {
- int mnemonic = -1, index = start;
- while (index < end) {
- if (buffer [index] == '&') {
- if (index + 1 < end && buffer [index + 1] == '&') {
- result.append (buffer [index]);
- index++;
- } else {
- mnemonic = result.length();
- }
- } else {
- result.append (buffer [index]);
- }
- index++;
- }
- return mnemonic;
-}
-
-int Ph_EV_BUT_PRESS (int widget, int info) {
- int result = super.Ph_EV_BUT_PRESS (widget, info);
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- PhEvent_t ev = new PhEvent_t ();
- OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
- int data = OS.PhGetData (cbinfo.event);
- PhPointerEvent_t pe = new PhPointerEvent_t ();
- OS.memmove (pe, data, PhPointerEvent_t.sizeof);
- if (pe.buttons != OS.Ph_BUTTON_SELECT) return result;
-
- if (focusIndex != -1) setFocus ();
- int x = pe.pos_x + ev.translation_x;
- int y = pe.pos_y + ev.translation_y;
- int offset = layout.getOffset (x, y, null);
- int oldSelectionX = selection.x;
- int oldSelectionY = selection.y;
- selection.x = offset;
- selection.y = -1;
- if (oldSelectionX != -1 && oldSelectionY != -1) {
- if (oldSelectionX > oldSelectionY) {
- int temp = oldSelectionX;
- oldSelectionX = oldSelectionY;
- oldSelectionY = temp;
- }
- Rectangle rect = layout.getBounds (oldSelectionX, oldSelectionY);
- redraw (rect.x, rect.y, rect.width, rect.height, false);
- }
- for (int j = 0; j < offsets.length; j++) {
- Rectangle [] rects = getRectangles (j);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rect = rects [i];
- if (rect.contains (x, y)) {
- if (j != focusIndex) {
- focusIndex = j;
- redraw ();
- }
- return result;
- }
- }
- }
- return result;
-}
-
-int Ph_EV_BUT_RELEASE (int widget, int info) {
- int result = super.Ph_EV_BUT_PRESS (widget, info);
- if (focusIndex == -1) return result;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- PhEvent_t ev = new PhEvent_t ();
- OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
- int data = OS.PhGetData (cbinfo.event);
- PhPointerEvent_t pe = new PhPointerEvent_t ();
- OS.memmove (pe, data, PhPointerEvent_t.sizeof);
- if (pe.buttons != OS.Ph_BUTTON_SELECT) return result;
-
- int x = pe.pos_x + ev.translation_x;
- int y = pe.pos_y + ev.translation_y;
- Rectangle [] rects = getRectangles (focusIndex);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rect = rects [i];
- if (rect.contains (x, y)) {
- Event event = new Event ();
- event.text = ids [focusIndex];
- sendEvent (SWT.Selection, event);
- return result;
- }
- }
- return result;
-}
-
-int Ph_EV_DRAG (int widget, int info) {
- int result = super.Ph_EV_DRAG (widget, info);
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- PhEvent_t ev = new PhEvent_t ();
- OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
- int data = OS.PhGetData (cbinfo.event);
- PhPointerEvent_t pe = new PhPointerEvent_t ();
- OS.memmove (pe, data, PhPointerEvent_t.sizeof);
- int x = pe.pos_x + ev.translation_x;
- int y = pe.pos_y + ev.translation_y;
-
-// if (pe.buttons != OS.Ph_BUTTON_SELECT) return result;//??
- if ((pe.button_state & OS.Ph_BUTTON_SELECT) != 0) {
- int oldSelection = selection.y;
- selection.y = layout.getOffset (x, y, null);
- if (selection.y != oldSelection) {
- int newSelection = selection.y;
- if (oldSelection > newSelection) {
- int temp = oldSelection;
- oldSelection = newSelection;
- newSelection = temp;
- }
- Rectangle rect = layout.getBounds (oldSelection, newSelection);
- redraw (rect.x, rect.y, rect.width, rect.height, false);
- }
- } else {
- for (int j = 0; j < offsets.length; j++) {
- Rectangle [] rects = getRectangles (j);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rect = rects [i];
- if (rect.contains (x, y)) {
- setCursor (display.getSystemCursor (SWT.CURSOR_HAND));
- return result;
- }
- }
- }
- setCursor (null);
- }
- return result;
-}
-
-int Pt_CB_GOT_FOCUS (int widget, int info) {
- int result = super.Pt_CB_GOT_FOCUS (widget, info);
- redraw ();
- return result;
-}
-
-int Pt_CB_LOST_FOCUS (int widget, int info) {
- int result = super.Pt_CB_LOST_FOCUS (widget, info);
- redraw ();
- return result;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (layout != null) layout.dispose ();
- layout = null;
- if (linkColor != null) linkColor.dispose ();
- linkColor = null;
- if (disabledColor != null) disabledColor.dispose ();
- disabledColor = null;
- offsets = null;
- ids = null;
- mnemonics = null;
- text = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection, listener);
-}
-
-int setBounds(int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- int result = super.setBounds(x, y, width, height, move, resize, events);
- if ((result & RESIZED) != 0) {
- layout.setWidth (width > 0 ? width : -1);
- }
- return result;
-}
-
-public void setFont (Font font) {
- super.setFont (font);
- layout.setFont (font);
-}
-
-/**
- * Sets the receiver's text.
- * <p>
- * The string can contain both regular text and hyperlinks. A hyperlink
- * is delimited by an anchor tag, &lt;A&gt; and &lt;/A&gt;. Within an
- * anchor, a single HREF attribute is supported. When a hyperlink is
- * selected, the text field of the selection event contains either the
- * text of the hyperlink or the value of its HREF, if one was specified.
- * In the rare case of identical hyperlinks within the same string, the
- * HREF attribute can be used to distinguish between them. The string may
- * include the mnemonic character and line delimiters. The only delimiter
- * the HREF attribute supports is the quotation mark (").
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (string.equals (text)) return;
- text = string;
- layout.setText (parse (string));
- focusIndex = offsets.length > 0 ? 0 : -1;
- selection.x = selection.y = -1;
- boolean enabled = (state & DISABLED) == 0;
- TextStyle linkStyle = new TextStyle (null, enabled ? linkColor : disabledColor, null);
- linkStyle.underline = true;
- for (int i = 0; i < offsets.length; i++) {
- Point point = offsets [i];
- layout.setStyle (linkStyle, point.x, point.y);
- }
- TextStyle mnemonicStyle = new TextStyle (null, null, null);
- mnemonicStyle.underline = true;
- for (int i = 0; i < mnemonics.length; i++) {
- int mnemonic = mnemonics [i];
- if (mnemonic != -1) {
- layout.setStyle (mnemonicStyle, mnemonic, mnemonic);
- }
- }
- redraw ();
-}
-
-boolean translateTraversal (int key_sym, PhKeyEvent_t phEvent) {
- boolean translated = super.translateTraversal (key_sym, phEvent);
- if (translated) return translated;
- if (focusIndex == -1) return translated;
- if (phEvent != null) {
- switch (key_sym) {
- case OS.Pk_Return:
- Event event = new Event ();
- event.text = ids [focusIndex];
- sendEvent (SWT.Selection, event);
- break;
- case OS.Pk_Tab:
- boolean next = (phEvent.key_mods & OS.Pk_KM_Shift) == 0;
- if (next) {
- if (focusIndex < offsets.length - 1) {
- focusIndex++;
- redraw ();
- }
- } else {
- if (focusIndex > 0) {
- focusIndex--;
- redraw ();
- }
- }
- break;
- }
- }
- return translated;
-}
-
-int traversalCode (int key_sym, PhKeyEvent_t ke) {
- if (offsets.length == 0) return 0;
- int code = super.traversalCode (key_sym, ke);
- if (key_sym == OS.Pk_Tab && ke != null) {
- boolean next = (ke.key_mods & OS.Pk_KM_Shift) == 0;
- if (next && focusIndex < offsets.length - 1) {
- return code & ~SWT.TRAVERSE_TAB_NEXT;
- }
- if (!next && focusIndex > 0) {
- return code & ~SWT.TRAVERSE_TAB_PREVIOUS;
- }
- }
- return code;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/List.java
deleted file mode 100755
index 48b66e5b7f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/List.java
+++ /dev/null
@@ -1,1259 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface
- * object that displays a list of strings and issues notification
- * when a string is selected. A list may be single or multi select.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection</dd>
- * </dl>
- * <p>
- * Note: Only one of SINGLE and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#list">List snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class List extends Scrollable {
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public List (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-
-/**
- * Adds the argument to the end of the receiver's list.
- *
- * @param string the new item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String,int)
- */
-public void add (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- int ptr = OS.malloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- OS.PtListAddItems (handle, new int [] {ptr}, 1, 0);
- OS.free (ptr);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the selection changes.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the argument to the receiver's list at the given
- * zero-relative index.
- * <p>
- * Note: To add an item at the end of the list, use the
- * result of calling <code>getItemCount()</code> as the
- * index or use <code>add(String)</code>.
- * </p>
- *
- * @param string the new item
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String)
- */
-public void add (String string, int index) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (index == -1) error (SWT.ERROR_INVALID_RANGE);
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- int ptr = OS.malloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- int result = OS.PtListAddItems (handle, new int [] {ptr}, 1, index + 1);
- OS.free (ptr);
- if (result != 0) {
- int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- if (0 <= index && index <= args [1]) error (SWT.ERROR_ITEM_NOT_ADDED);
- error (SWT.ERROR_INVALID_RANGE);
- }
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
-
- int [] args = new int [] {
- OS.Pt_ARG_WIDTH, 0, 0,
- OS.Pt_ARG_HEIGHT, 0, 0,
- OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- int resizeFlags = OS.Pt_RESIZE_X_ALWAYS | OS.Pt_RESIZE_Y_ALWAYS;
- OS.PtSetResource (handle, OS.Pt_ARG_RESIZE_FLAGS, resizeFlags, OS.Pt_RESIZE_XY_BITS);
- if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidgetFamily (handle);
- PhDim_t dim = new PhDim_t ();
- OS.PtWidgetPreferredSize (handle, dim);
- int width = dim.w, height = dim.h;
- OS.PtSetResource (handle, OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS);
- OS.PtSetResources (handle, args.length / 3, args);
- if (args [7] <= 0) {
- width += DEFAULT_WIDTH;
- height += DEFAULT_HEIGHT;
- }
-
- if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) {
- PhRect_t rect = new PhRect_t ();
- PhArea_t area = new PhArea_t ();
- rect.lr_x = (short) (wHint - 1);
- rect.lr_y = (short) (hHint - 1);
- OS.PtSetAreaFromWidgetCanvas (handle, rect, area);
- ScrollBar scroll;
- if (wHint != SWT.DEFAULT) {
- width = area.size_w;
- if ((scroll = getVerticalBar()) != null) width += scroll.getSize ().x;
- }
- if (hHint != SWT.DEFAULT) {
- height = area.size_h;
- if ((scroll = getHorizontalBar()) != null) height += scroll.getSize ().y;
- }
- }
- return new Point(width, height);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- int clazz = display.PtList;
- int parentHandle = parent.parentingHandle ();
- int mode = OS.Pt_SELECTION_MODE_SINGLE | OS.Pt_SELECTION_MODE_AUTO;
- if ((style & SWT.MULTI) != 0) {
- if ((style & SWT.SIMPLE) != 0) {
- mode = OS.Pt_SELECTION_MODE_MULTIPLE | OS.Pt_SELECTION_MODE_NOCLEAR
- | OS.Pt_SELECTION_MODE_TOGGLE | OS.Pt_SELECTION_MODE_NOMOVE;
- } else {
- mode = OS.Pt_SELECTION_MODE_MULTIPLE | OS.Pt_SELECTION_MODE_AUTO;
- }
- }
- mode |= OS.Pt_SELECTION_MODE_NOFOCUS;
- boolean hasBorder = (style & SWT.BORDER) != 0;
- int listFlags = OS.Pt_LIST_SCROLLBAR_ALWAYS | OS.Pt_LIST_SCROLLBAR_AS_REQUIRED;
- int [] args = {
- OS.Pt_ARG_FLAGS, hasBorder ? OS.Pt_HIGHLIGHTED : 0, OS.Pt_HIGHLIGHTED,
- OS.Pt_ARG_SELECTION_MODE, mode, 0,
- OS.Pt_ARG_FLAGS, OS.Pt_SELECTABLE | OS.Pt_SELECT_NOREDRAW, OS.Pt_SELECTABLE | OS.Pt_SELECT_NOREDRAW,
- OS.Pt_ARG_LIST_FLAGS, (style & SWT.V_SCROLL) != 0 ? OS.Pt_LIST_SCROLLBAR_AS_REQUIRED : 0, listFlags,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (clazz, parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- createStandardScrollBars ();
-}
-
-int defaultBackground () {
- return display.LIST_BACKGROUND;
-}
-
-byte [] defaultFont () {
- return display.LIST_FONT;
-}
-
-int defaultForeground () {
- return display.LIST_FOREGROUND;
-}
-
-/**
- * Deselects the item at the given zero-relative index in the receiver.
- * If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget();
- if (index < 0) return;
- OS.PtListUnselectPos (handle, index + 1);
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. The range of the
- * indices is inclusive. Indices that are out of range are ignored.
- *
- * @param start the start index of the items to deselect
- * @param end the end index of the items to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int start, int end) {
- checkWidget();
- if (start > end) return;
- if ((style & SWT.SINGLE) != 0) {
- int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- int count = args [1];
- int index = Math.min (count - 1, end);
- if (index >= start) deselect (index);
- return;
- }
- for (int i=start; i<=end; i++) {
- OS.PtListUnselectPos (handle, i + 1);
- }
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. Indices that are out
- * of range and duplicate indices are ignored.
- *
- * @param indices the array of indices for the items to deselect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int [] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- for (int i=0; i<indices.length; i++) {
- int index = indices [i];
- if (index != -1) {
- OS.PtListUnselectPos (handle, index + 1);
- }
- }
-}
-
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll () {
- checkWidget();
- int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- int count = args [1];
- for (int i=0; i<count; i++) {
- OS.PtListUnselectPos (handle, i + 1);
- }
-}
-
-/**
- * Returns the zero-relative index of the item which currently
- * has the focus in the receiver, or -1 if no item has focus.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getFocusIndex () {
- return getSelectionIndex ();
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getItem (int index) {
- checkWidget();
- int [] args = new int [] {
- OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0,
- OS.Pt_ARG_ITEMS, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- if (!(0 <= index && index < args [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int [] items = new int [1];
- OS.memmove (items, args [4] + (index * 4), 4);
- int length = OS.strlen (items [0]);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, items [0], length);
- char [] unicode = Converter.mbcsToWcs (null, buffer);
- return new String (unicode);
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the list.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget();
- int [] args = new int [] {
- OS.Pt_ARG_LIST_TOTAL_HEIGHT, 0, 0,
- OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0,
- OS.Pt_ARG_LIST_FONT, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- if (args [4] == 0) {
- int ptr = OS.malloc(1);
- OS.memset(ptr, 0, 1);
- PhRect_t rect = new PhRect_t ();
- OS.PfExtentText(rect, null, args [7], ptr, 1);
- OS.free(ptr);
- int inset = 4;
- return inset + (rect.lr_y - rect.ul_y + 1);
- }
- return args [1] / args [4];
-}
-
-/**
- * Returns a (possibly empty) array of <code>String</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver's list
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getItems () {
- checkWidget();
- int [] args = new int [] {
- OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0,
- OS.Pt_ARG_ITEMS, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- int [] items = new int [args [1]];
- OS.memmove (items, args [4], args [1] * 4);
- String [] result = new String [args [1]];
- for (int i=0; i<args [1]; i++) {
- int length = OS.strlen (items [i]);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, items [i], length);
- char [] unicode = Converter.mbcsToWcs (null, buffer);
- result [i] = new String (unicode);
- }
- return result;
-
-}
-
-/**
- * Returns an array of <code>String</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getSelection () {
- checkWidget();
- int [] indices = getSelectionIndices ();
- String [] result = new String [indices.length];
- for (int i=0; i<indices.length; i++) {
- result [i] = getItem (indices [i]);
- }
- return result;
-}
-
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget();
- int [] args = new int [] {OS.Pt_ARG_LIST_SEL_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item or -1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget();
- int [] args = new int [] {
- OS.Pt_ARG_LIST_SEL_COUNT, 0, 0,
- OS.Pt_ARG_SELECTION_INDEXES, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- if (args [1] == 0) return -1;
- short [] buffer = new short [1];
- OS.memmove (buffer, args [4], 2);
- return buffer [0] - 1;
-}
-
-/**
- * Returns the zero-relative indices of the items which are currently
- * selected in the receiver. The order of the indices is unspecified.
- * The array is empty if no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return the array of indices of the selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int [] getSelectionIndices () {
- checkWidget();
- int [] args = new int [] {
- OS.Pt_ARG_LIST_SEL_COUNT, 0, 0,
- OS.Pt_ARG_SELECTION_INDEXES, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- short [] indices = new short [args [1]];
- OS.memmove (indices, args [4], args [1] * 2);
- int [] result = new int [args [1]];
- for (int i=0; i<args [1]; i++) {
- result [i] = indices [i] - 1;
- }
- return result;
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items are
- * scrolled or new items are added or removed.
- *
- * @return the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget();
- int [] args = new int [] {OS.Pt_ARG_TOP_ITEM_POS, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1] - 1;
-}
-
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- OS.PtAddCallback (handle, OS.Pt_CB_SELECTION, windowProc, OS.Pt_CB_SELECTION);
- OS.PtAddCallback (handle, OS.Pt_CB_ACTIVATE, windowProc, OS.Pt_CB_ACTIVATE);
-}
-
-/**
- * Gets the index of an item.
- * <p>
- * The list is searched starting at 0 until an
- * item is found that is equal to the search item.
- * If no item is found, -1 is returned. Indexing
- * is zero based.
- *
- * @param string the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- return OS.PtListItemPos (handle, buffer) - 1;
-}
-
-/**
- * Searches the receiver's list starting at the given,
- * zero-relative index until an item is found that is equal
- * to the argument, and returns the index of that item. If
- * no item is found or the starting index is out of range,
- * returns -1.
- *
- * @param string the search item
- * @param start the zero-relative index at which to start the search
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string, int start) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (start == 0) return indexOf(string);
- int [] args = new int [] {
- OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0,
- OS.Pt_ARG_ITEMS, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- int count = args [1];
- if (!(0 <= start && start < count)) return -1;
- int [] item = new int [1];
- for (int index=start; index<count; index++) {
- OS.memmove (item, args [4] + (index * 4), 4);
- int length = OS.strlen (item [0]);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, item [0], length);
- if (string.equals(new String (Converter.mbcsToWcs (null, buffer)))) return index;
- }
- return -1;
-}
-
-/**
- * Returns <code>true</code> if the item is selected,
- * and <code>false</code> otherwise. Indices out of
- * range are ignored.
- *
- * @param index the index of the item
- * @return the selection state of the item at the index
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isSelected (int index) {
- checkWidget();
- int [] args = new int [] {
- OS.Pt_ARG_LIST_SEL_COUNT, 0, 0,
- OS.Pt_ARG_SELECTION_INDEXES, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- short [] buffer = new short [1];
- for (int i=0; i<args [1]; i++) {
- OS.memmove (buffer, args [4] + (i * 2), 2);
- if (buffer [0] == index + 1) return true;
- }
- return false;
-}
-
-int Pt_CB_ACTIVATE (int widget, int info) {
- if (info == 0) return OS.Pt_END;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.cbdata == 0) return OS.Pt_END;
- int[] click_count = new int [1];
- OS.memmove(click_count, cbinfo.cbdata, 4);
- if (click_count [0] > 1) postEvent (SWT.DefaultSelection);
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_SELECTION (int widget, int info) {
- postEvent (SWT.Selection);
- return OS.Pt_CONTINUE;
-}
-
-/**
- * Removes the item from the receiver at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget();
- int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- if (!(0 <= index && index < args [1])) error (SWT.ERROR_INVALID_RANGE);
- int result = OS.PtListDeleteItemPos (handle, 1, index + 1);
- if (result != 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * until an item is found that is equal to the argument,
- * and removes that item from the list.
- *
- * @param string the item to remove
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (String string) {
- checkWidget();
- int index = indexOf (string, 0);
- if (index == -1) error (SWT.ERROR_INVALID_ARGUMENT);
- remove (index);
-}
-
-/**
- * Removes the items from the receiver at the given
- * zero-relative indices.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int [] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- int [] newIndices = new int [indices.length];
- System.arraycopy (indices, 0, newIndices, 0, indices.length);
- sort (newIndices);
- int start = newIndices [newIndices.length - 1], end = newIndices [0];
- int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- int count = args [1];
- if (!(0 <= start && start <= end && end < count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int last = -1;
- for (int i=0; i<newIndices.length; i++ ) {
- int index = newIndices [i];
- if (last != index) {
- int result = OS.PtListDeleteItemPos (handle, 1, index + 1);
- if (result != 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
- last = index;
- }
- }
-}
-
-/**
- * Removes the items from the receiver which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget();
- if (start > end) return;
- int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- if (!(0 <= start && start <= end && end < args [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int count = end - start + 1;
- int result = OS.PtListDeleteItemPos (handle, count, start + 1);
- if (result != 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
-}
-
-/**
- * Removes all of the items from the receiver.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget();
- OS.PtListDeleteAllItems (handle);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If an item in the given range is not selected, it is selected.
- * If an item in the given range was already selected, it remains selected.
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#setSelection(int,int)
- */
-public void select (int start, int end) {
- checkWidget ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- int count = args [1];
- if (count == 0 || start >= count) return;
- start = Math.max (0, start);
- end = Math.min (end, count - 1);
- if ((style & SWT.SINGLE) != 0) {
- select (start);
- return;
- }
- int gotoIndex = -1;
- for (int index=end; index>=start; index--) {
- gotoIndex = index;
- OS.PtListSelectPos (handle, index + 1);
- }
- if (gotoIndex != -1) OS.PtListGotoPos (handle, gotoIndex + 1);
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If the item at a given index is not selected, it is selected.
- * If the item at a given index was already selected, it remains selected.
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- *
- * @param indices the array of indices for the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#setSelection(int[])
- */
-public void select (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- int count = args [1];
- int gotoIndex = -1;
- for (int i=0; i<length; i++) {
- int index = indices [i];
- if (0 <= index && index < count) {
- gotoIndex = index;
- OS.PtListSelectPos (handle, index + 1);
- }
- }
- if (gotoIndex != -1) OS.PtListGotoPos (handle, gotoIndex + 1);
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget();
- if (index < 0) return;
- int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- if (index < args [1]) {
- OS.PtListSelectPos (handle, index + 1);
- OS.PtListGotoPos (handle, index + 1);
- }
-}
-
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return;
- int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- int count = args [1];
- for (int i=0; i<count; i++) {
- OS.PtListSelectPos (handle, i + 1);
- }
-}
-
-/**
- * Sets the text of the item in the receiver's list at the given
- * zero-relative index to the string argument.
- *
- * @param index the index for the item
- * @param string the new text for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItem (int index, String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- if (!(0 <= index && index < args [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- int ptr = OS.malloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- OS.PtListReplaceItemPos (handle, new int [] {ptr}, 1, index + 1);
- OS.free (ptr);
-}
-
-/**
- * Sets the receiver's items to be the given array of items.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItems (String [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<items.length; i++) {
- if (items [i] == null) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- OS.PtListDeleteAllItems (handle);
- int[] itemsPtr = new int [items.length];
- for (int i=0; i<itemsPtr.length; i++) {
- byte [] buffer = Converter.wcsToMbcs (null, items [i], true);
- int ptr = OS.malloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- itemsPtr [i] = ptr;
- }
- OS.PtListAddItems (handle, itemsPtr, itemsPtr.length, 0);
- for (int i=0; i<itemsPtr.length; i++) {
- OS.free (itemsPtr [i]);
- }
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- *
- * @param start the start index of the items to select
- * @param end the end index of the items to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int,int)
- */
-public void setSelection (int start, int end) {
- checkWidget ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) {
- deselectAll ();
- return;
- }
- int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- int count = args [1];
- if (count == 0 || start >= count) {
- deselectAll ();
- return;
- }
- start = Math.max (0, start);
- end = Math.min (end, count - 1);
- if ((style & SWT.MULTI) != 0) deselectAll ();
- select (start, end);
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains selected.
- * The current selection is first cleared, then the new item is selected.
- * Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @see List#deselectAll()
- * @see List#select(int)
- */
-public void setSelection (int index) {
- if ((style & SWT.MULTI) != 0) deselectAll ();
- select (index);
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- *
- * @param indices the indices of the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int[])
- */
-public void setSelection(int[] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- select (indices);
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int[])
- * @see List#setSelection(int[])
- */
-public void setSelection (String [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = items.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) {
- deselectAll ();
- return;
- }
- if ((style & SWT.MULTI) != 0) deselectAll ();
- for (int i=length-1; i>=0; --i) {
- int index = 0;
- String string = items [i];
- if (string != null) {
- while ((index = indexOf (string, index)) != -1) {
- select (index);
- if ((style & SWT.SINGLE) != 0) return;
- index++;
- }
- }
- }
- if ((style & SWT.SINGLE) != 0) deselectAll ();
-}
-
-/**
- * Sets the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items
- * are scrolled or new items are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget();
- OS.PtSetResource (handle, OS.Pt_ARG_TOP_ITEM_POS, index + 1, 0);
-}
-
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void showSelection () {
- checkWidget();
- int [] args = new int [] {
- OS.Pt_ARG_LIST_SEL_COUNT, 0, 0,
- OS.Pt_ARG_SELECTION_INDEXES, 0, 0,
- OS.Pt_ARG_TOP_ITEM_POS, 0, 0,
- OS.Pt_ARG_VISIBLE_COUNT, 0, 0,
- OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0
- };
- OS.PtGetResources (handle, args.length / 3, args);
- if (args [1] == 0) return;
- short [] buffer = new short [1];
- OS.memmove (buffer, args [4], 2);
- int index = buffer [0] - 1;
- int topIndex = args [7] - 1, visibleCount = args [10], count = args [13];
- int bottomIndex = Math.min (topIndex + visibleCount - 1, count);
- if ((topIndex <= index) && (index <= bottomIndex)) return;
- int lastIndex = Math.max (1, count - visibleCount + 1);
- int newTop = Math.min (Math.max (index - (visibleCount / 2), 1), lastIndex);
- OS.PtSetResource (handle, OS.Pt_ARG_TOP_ITEM_POS, newTop, 0);
-}
-
-int widgetClass () {
- return OS.PtList ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Menu.java
deleted file mode 100755
index 6234527894..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Menu.java
+++ /dev/null
@@ -1,844 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are user interface objects that contain
- * menu items.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BAR, DROP_DOWN, POP_UP, NO_RADIO_GROUP</dd>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Help, Hide, Show </dd>
- * </dl>
- * <p>
- * Note: Only one of BAR, DROP_DOWN and POP_UP may be specified.
- * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#menu">Menu snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Menu extends Widget {
- int x, y;
- boolean hasLocation;
- Decorations parent;
- MenuItem cascade, defaultItem;
-
-/**
- * Constructs a new instance of this class given its parent,
- * and sets the style for the instance so that the instance
- * will be a popup menu on the given parent's shell.
- * <p>
- * After constructing a menu, it can be set into its parent
- * using <code>parent.setMenu(menu)</code>. In this case, the parent may
- * be any control in the same widget tree as the parent.
- * </p>
- *
- * @param parent a control which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#POP_UP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Control parent) {
- this (checkNull (parent).menuShell (), SWT.POP_UP);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Decorations</code>) and a style value
- * describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * After constructing a menu or menuBar, it can be set into its parent
- * using <code>parent.setMenu(menu)</code> or <code>parent.setMenuBar(menuBar)</code>.
- * </p>
- *
- * @param parent a decorations control which will be the parent of the new instance (cannot be null)
- * @param style the style of menu to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BAR
- * @see SWT#DROP_DOWN
- * @see SWT#POP_UP
- * @see SWT#NO_RADIO_GROUP
- * @see SWT#LEFT_TO_RIGHT
- * @see SWT#RIGHT_TO_LEFT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Decorations parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (0);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>) and sets the style
- * for the instance so that the instance will be a drop-down
- * menu on the given parent's parent.
- * <p>
- * After constructing a drop-down menu, it can be set into its parentMenu
- * using <code>parentMenu.setMenu(menu)</code>.
- * </p>
- *
- * @param parentMenu a menu which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Menu parentMenu) {
- this (checkNull (parentMenu).parent, SWT.DROP_DOWN);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>MenuItem</code>) and sets the style
- * for the instance so that the instance will be a drop-down
- * menu on the given parent's parent menu.
- * <p>
- * After constructing a drop-down menu, it can be set into its parentItem
- * using <code>parentItem.setMenu(menu)</code>.
- * </p>
- *
- * @param parentItem a menu item which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (MenuItem parentItem) {
- this (checkNull (parentItem).parent);
-}
-
-static Control checkNull (Control control) {
- if (control == null) error (SWT.ERROR_NULL_ARGUMENT);
- return control;
-}
-
-static Menu checkNull (Menu menu) {
- if (menu == null) error (SWT.ERROR_NULL_ARGUMENT);
- return menu;
-}
-
-static MenuItem checkNull (MenuItem item) {
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when help events are generated for the control,
- * by sending it one of the messages defined in the
- * <code>HelpListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when menus are hidden or shown, by sending it
- * one of the messages defined in the <code>MenuListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuListener
- * @see #removeMenuListener
- */
-public void addMenuListener (MenuListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Hide,typedListener);
- addListener (SWT.Show,typedListener);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- int parentHandle = parent.topHandle ();
- if ((style & SWT.BAR) != 0) {
- int [] args = {
- OS.Pt_ARG_FLAGS, 0, OS.Pt_GETS_FOCUS,
- OS.Pt_ARG_FLAGS, OS.Pt_DELAY_REALIZE, OS.Pt_DELAY_REALIZE,
- };
- handle = OS.PtCreateWidget (OS.PtMenuBar (), parentHandle, args.length / 3, args);
- } else {
- handle = OS.PtCreateWidget (OS.PtMenu (), parentHandle, 0, null);
- }
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-
-void createWidget (int index) {
- checkOrientation (parent);
- super.createWidget (index);
- parent.add (this);
-}
-
-/**
- * Returns the default menu item or null if none has
- * been previously set.
- *
- * @return the default menu item.
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getDefaultItem () {
- checkWidget();
- return defaultItem;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled menu is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget ();
- int topHandle = topHandle ();
- return (OS.PtWidgetFlags (topHandle) & OS.Pt_BLOCKED) == 0;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- int count = 0;
- int child = OS.PtWidgetChildBack (handle);
- if (child != 0 && (style & SWT.BAR) != 0) child = OS.PtWidgetChildBack (child);
- while (child != 0) {
- child = OS.PtWidgetBrotherInFront (child);
- count++;
- }
- return count;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getItem (int index) {
- checkWidget();
- if (index < 0) error (SWT.ERROR_INVALID_RANGE);
- int i = 0;
- int child = OS.PtWidgetChildBack (handle);
- if (child != 0 && (style & SWT.BAR) != 0) child = OS.PtWidgetChildBack (child);
- while (child != 0) {
- Widget widget = WidgetTable.get (child);
- if (widget != null && widget instanceof MenuItem) {
- if (i++ == index) return (MenuItem) widget;
- }
- child = OS.PtWidgetBrotherInFront (child);
- }
- error (SWT.ERROR_INVALID_RANGE);
- return null;
-}
-
-/**
- * Returns a (possibly empty) array of <code>MenuItem</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem [] getItems () {
- checkWidget();
- int count = 0;
- int child = OS.PtWidgetChildBack (handle);
- if (child != 0 && (style & SWT.BAR) != 0) child = OS.PtWidgetChildBack (child);
- while (child != 0) {
- child = OS.PtWidgetBrotherInFront (child);
- count++;
- }
- MenuItem [] items = new MenuItem [count];
- int i = 0, j = 0;
- child = OS.PtWidgetChildBack (handle);
- if (child != 0 && (style & SWT.BAR) != 0) child = OS.PtWidgetChildBack (child);
- while (i < count) {
- Widget widget = WidgetTable.get (child);
- if (widget != null && widget instanceof MenuItem) {
- items [j++] = (MenuItem) widget;
- }
- i++;
- child = OS.PtWidgetBrotherInFront (child);
- }
- if (i == j) return items;
- MenuItem [] newItems = new MenuItem [j];
- System.arraycopy (items, 0, newItems, 0, j);
- return newItems;
-}
-
-String getNameText () {
- String result = "";
- MenuItem [] items = getItems ();
- int length = items.length;
- if (length > 0) {
- for (int i=0; i<length-1; i++) {
- result = result + items [i].getNameText() + ", ";
- }
- result = result + items [length-1].getNameText ();
- }
- return result;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Decorations</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Decorations getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>MenuItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getParentItem () {
- checkWidget();
- return cascade;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>Menu</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getParentMenu () {
- checkWidget();
- if (cascade != null) return cascade.parent;
- return null;
-}
-
-/**
- * Returns the receiver's shell. For all controls other than
- * shells, this simply returns the control's nearest ancestor
- * shell. Shells return themselves, even if they are children
- * of other shells.
- *
- * @return the receiver's shell
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getParent
- */
-public Shell getShell () {
- checkWidget();
- return parent.getShell ();
-}
-
-/*public*/ Point getSize () {
- checkWidget();
- PhArea_t area = new PhArea_t ();
- OS.PtWidgetArea (handle, area);
- return new Point (area.size_w, area.size_h);
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- return OS.PtWidgetIsRealized (handle);
-}
-
-void hookEvents () {
- int windowProc = display.windowProc;
- OS.PtAddCallback (handle, OS.Pt_CB_REALIZED, windowProc, OS.Pt_CB_REALIZED);
- OS.PtAddCallback (handle, OS.Pt_CB_UNREALIZED, windowProc, OS.Pt_CB_UNREALIZED);
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (MenuItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- int i = 0;
- int child = OS.PtWidgetChildBack (handle);
- if (child != 0 && (style & SWT.BAR) != 0) child = OS.PtWidgetChildBack (child);
- while (child != 0) {
- Widget widget = WidgetTable.get (child);
- if (item == widget) return i;
- if (widget != null && widget instanceof MenuItem) i++;
- child = OS.PtWidgetBrotherInFront (child);
- }
- return -1;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled menu is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- Menu parentMenu = getParentMenu ();
- if (parentMenu == null) {
- return getEnabled () && parent.isEnabled ();
- }
- return getEnabled () && parentMenu.isEnabled ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return getVisible ();
-}
-
-int Pt_CB_REALIZED (int widget, int info) {
- if ((style & SWT.BAR) == 0) {
- Shell shell = getShell ();
- shell.activeMenu = this;
- }
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_UNREALIZED (int widget, int info) {
- if (cascade != null) {
- OS.PtSetResource (handle, OS.Pt_ARG_MENU_FLAGS, 0, OS.Pt_MENU_CHILD);
- int shellHandle = parent.topHandle ();
- OS.PtReParentWidget (handle, shellHandle);
- }
- sendEvent (SWT.Hide);
- Shell shell = getShell ();
- if (shell.activeMenu == this) {
- shell.activeMenu = null;
- if (cascade != null) {
- Menu parent = cascade.parent;
- if (parent != null && (parent.style & SWT.BAR) == 0) {
- if (OS.PtWidgetIsRealized (parent.handle)) {
- shell.activeMenu = parent;
- }
- }
- }
- }
- return OS.Pt_CONTINUE;
-}
-
-void releaseChildren (boolean destroy) {
- MenuItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- super.releaseChildren (destroy);
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (cascade != null) cascade.setMenu (null);
- if ((style & SWT.BAR) != 0 && this == parent.menuBar) {
- parent.setMenuBar (null);
- }
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (parent != null) parent.remove (this);
- parent = null;
- cascade = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the menu events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuListener
- * @see #addMenuListener
- */
-public void removeMenuListener (MenuListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Hide, listener);
- eventTable.unhook (SWT.Show, listener);
-}
-
-/**
- * Sets the default menu item to the argument or removes
- * the default emphasis when the argument is <code>null</code>.
- *
- * @param item the default menu item or null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the menu item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDefaultItem (MenuItem item) {
- checkWidget();
- if (item != null && item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- defaultItem = item;
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled menu is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget ();
- int topHandle = topHandle ();
- int flags = enabled ? 0 : OS.Pt_BLOCKED | OS.Pt_GHOST;
- OS.PtSetResource (topHandle, OS.Pt_ARG_FLAGS, flags, OS.Pt_BLOCKED | OS.Pt_GHOST);
-}
-
-/**
- * Sets the location of the receiver, which must be a popup,
- * to the point specified by the arguments which are relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p><p>
- * Note that the platform window manager ultimately has control
- * over the location of popup menus.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget();
- this.x = x;
- this.y = y;
- hasLocation = true;
-}
-
-/**
- * Sets the location of the receiver, which must be a popup,
- * to the point specified by the argument which is relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p><p>
- * Note that the platform window manager ultimately has control
- * over the location of popup menus.
- * </p>
- *
- * @param location the new location for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void setLocation (Point location) {
- checkWidget();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget();
- if ((style & SWT.POP_UP) == 0) return;
- if (visible == OS.PtWidgetIsRealized (handle)) return;
- if (visible) {
- display.runDeferredEvents ();
- sendEvent (SWT.Show);
- if (getItemCount () != 0) {
- PhPoint_t pt = new PhPoint_t ();
- pt.x = (short) x;
- pt.y = (short) y;
- if (!hasLocation) {
- int ig = OS.PhInputGroup (0);
- PhCursorInfo_t info = new PhCursorInfo_t ();
- OS.PhQueryCursor ((short) ig, info);
- pt.x = info.last_press_x;
- pt.y = info.last_press_y;
- }
- int ptr = OS.malloc (PhPoint_t.sizeof);
- OS.memmove (ptr, pt, PhPoint_t.sizeof);
- OS.PtSetResource (handle, OS.Pt_ARG_POS, ptr, 0);
- OS.free (ptr);
- OS.PtRealizeWidget (handle);
- } else {
- sendEvent (SWT.Hide);
- }
- } else {
- OS.PtUnrealizeWidget(handle);
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MenuItem.java
deleted file mode 100755
index e2f942200c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MenuItem.java
+++ /dev/null
@@ -1,921 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that issues notification when pressed and released.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>CHECK, CASCADE, PUSH, RADIO, SEPARATOR</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Arm, Help, Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR
- * may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class MenuItem extends Item {
- Menu parent, menu;
- int accelerator;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a menu control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#CHECK
- * @see SWT#CASCADE
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public MenuItem (Menu parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a menu control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#CHECK
- * @see SWT#CASCADE
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public MenuItem (Menu parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (index);
-}
-
-void addAccelerator () {
- if (accelerator == 0) return;
- int keyMods = 0;
- if ((accelerator & SWT.ALT) != 0) keyMods |= OS.Pk_KM_Alt;
- if ((accelerator & SWT.SHIFT) != 0) keyMods |= OS.Pk_KM_Shift;
- if ((accelerator & SWT.CONTROL) != 0) keyMods |= OS.Pk_KM_Ctrl;
- int key = (accelerator & ~(SWT.ALT | SWT.SHIFT | SWT.CONTROL));
- int keyCode = Display.untranslateKey (key);
- if (keyCode != 0) key = keyCode;
- else key = Character.toLowerCase ((char)key);
- Shell shell = parent.getShell ();
- OS.PtAddHotkeyHandler(shell.shellHandle, key, keyMods, (short)0, handle, display.hotkeyProc);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the arm events are generated for the control, by sending
- * it one of the messages defined in the <code>ArmListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ArmListener
- * @see #removeArmListener
- */
-public void addArmListener (ArmListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Arm, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the help events are generated for the control, by sending
- * it one of the messages defined in the <code>HelpListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the menu item is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the stateMask field of the event object is valid.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the menu item is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.CASCADE, 0);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- int count = parent.getItemCount();
- if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
- int parentHandle = parent.handle;
- if ((style & SWT.SEPARATOR) != 0) {
- handle = OS.PtCreateWidget (OS.PtSeparator (), parentHandle, 0, null);
- } else if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- int [] args = {
- OS.Pt_ARG_INDICATOR_TYPE, (style & SWT.CHECK) != 0 ? OS.Pt_N_OF_MANY : OS.Pt_ONE_OF_MANY, 0
- };
- handle = OS.PtCreateWidget (OS.PtToggleButton (), parentHandle, args.length / 3, args);
- } else {
- handle = OS.PtCreateWidget (OS.PtMenuButton (), parentHandle, 0, null);
- }
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if (index != count) {
- int i = 0;
- int child = OS.PtWidgetChildBack (parentHandle);
- /*
- * Feature in Photon. Menu bars have an extra widget which
- * is the parent of all menu items. PtValidParent() can not be
- * used, since it does not return that widget.
- */
- if (child != 0 && (parent.style & SWT.BAR) != 0) child = OS.PtWidgetChildBack (child);
- while (i != index && child != 0) {
- child = OS.PtWidgetBrotherInFront (child);
- i++;
- }
- OS.PtWidgetInsert (topHandle (), child, 1);
- }
- if (OS.PtWidgetIsRealized (parentHandle)) {
- OS.PtRealizeWidget (topHandle ());
- }
-}
-
-/**
- * Returns the widget accelerator. An accelerator is the bit-wise
- * OR of zero or more modifier masks and a key. Examples:
- * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
- * The default value is zero, indicating that the menu item does
- * not have an accelerator.
- *
- * @return the accelerator or 0
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAccelerator () {
- checkWidget();
- return accelerator;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled menu item is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget ();
- /*
- * Bug in Photon. The Pt_BLOCKED flag of a menu item is cleared
- * when its parent menu is realized. The fix is to remember
- * the menu item state and reset it when the menu item is
- * realized.
- */
-// int topHandle = topHandle ();
-// return (OS.PtWidgetFlags (topHandle) & OS.Pt_BLOCKED) == 0;
- return (state & DISABLED) == 0;
-}
-
-/**
- * Returns the receiver's cascade menu if it has one or null
- * if it does not. Only <code>CASCADE</code> menu items can have
- * a pull down menu. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pull down
- * menu is platform specific.
- *
- * @return the receiver's menu
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenu () {
- checkWidget();
- return menu;
-}
-
-String getNameText () {
- if ((style & SWT.SEPARATOR) != 0) return "|";
- return super.getNameText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Menu</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked.
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false;
- return (OS.PtWidgetFlags (handle) & OS.Pt_SET) != 0;
-}
-
-void hookEvents () {
- if ((style & SWT.SEPARATOR) != 0) return;
- int windowProc = display.windowProc;
- if ((style & SWT.CASCADE) != 0) {
- OS.PtAddCallback (handle, OS.Pt_CB_ARM, windowProc, OS.Pt_CB_ARM);
- }
- OS.PtAddCallback (handle, OS.Pt_CB_ACTIVATE, windowProc, OS.Pt_CB_ACTIVATE);
- if ((parent.style & SWT.BAR) == 0) {
- OS.PtAddCallback (handle, OS.Pt_CB_REALIZED, windowProc, OS.Pt_CB_REALIZED);
- }
-}
-
-int hotkeyProc (int widget, int data, int info) {
- showMenu ();
- return OS.Pt_CONTINUE;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled menu item is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- return getEnabled () && parent.isEnabled ();
-}
-
-int Pt_CB_ACTIVATE (int widget, int info) {
- if ((style & SWT.CASCADE) != 0 && menu != null) {
- return OS.Pt_CONTINUE;
- }
- Event event = new Event ();
- if (info != 0) {
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.event != 0) {
- PhEvent_t ev = new PhEvent_t ();
- OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
- int data = OS.PhGetData (cbinfo.event);
- if (data != 0) {
- switch (ev.type) {
- case OS.Ph_EV_KEY:
- PhKeyEvent_t ke = new PhKeyEvent_t ();
- OS.memmove (ke, data, PhKeyEvent_t.sizeof);
- setInputState (event, SWT.Selection, ke.key_mods, ke.button_state);
- break;
- case OS.Ph_EV_BUT_PRESS:
- case OS.Ph_EV_BUT_RELEASE:
- PhPointerEvent_t pe = new PhPointerEvent_t ();
- OS.memmove (pe, data, PhPointerEvent_t.sizeof);
- setInputState (event, SWT.Selection, pe.key_mods, pe.button_state);
- break;
- }
- }
- }
- }
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) {
- selectRadio ();
- }
- }
- postEvent (SWT.Selection, event);
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_ARM (int widget, int info) {
- sendEvent (SWT.Arm);
- showMenu ();
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_REALIZED (int widget, int info) {
- /*
- * Bug in Photon. The Pt_BLOCKED flag of a menu item is cleared
- * when its parent menu is realized. The fix is to remember
- * the menu item state and reset it when the menu item is
- * realized.
- */
- int topHandle = topHandle ();
- int flags = (state & DISABLED) != 0 ? OS.Pt_BLOCKED | OS.Pt_GHOST : 0;
- OS.PtSetResource (topHandle, OS.Pt_ARG_FLAGS, flags, OS.Pt_BLOCKED | OS.Pt_GHOST);
- return OS.Pt_CONTINUE;
-}
-
-void releaseChildren (boolean destroy) {
- if (menu != null && !menu.isDisposed ()) {
- menu.release (false);
- menu = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (menu != null) menu.dispose ();
- menu = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (accelerator != 0) removeAccelerator ();
- accelerator = 0;
- parent = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the arm events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ArmListener
- * @see #addArmListener
- */
-public void removeArmListener (ArmListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Arm, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-
-void removeAccelerator () {
- if (accelerator == 0) return;
- int keyMods = 0;
- if ((accelerator & SWT.ALT) != 0) keyMods |= OS.Pk_KM_Alt;
- if ((accelerator & SWT.SHIFT) != 0) keyMods |= OS.Pk_KM_Shift;
- if ((accelerator & SWT.CONTROL) != 0) keyMods |= OS.Pk_KM_Ctrl;
- int key = (accelerator & ~(SWT.ALT | SWT.SHIFT | SWT.CONTROL));
- int keyCode = Display.untranslateKey (key);
- if (keyCode != 0) key = keyCode;
- else key = Character.toLowerCase ((char)key);
- Shell shell = parent.getShell ();
- OS.PtRemoveHotkeyHandler(shell.shellHandle, key, keyMods, (short)0, handle, display.hotkeyProc);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-void selectRadio () {
- int index = 0;
- MenuItem [] items = parent.getItems ();
- while (index < items.length && items [index] != this) index++;
- int i = index - 1;
- while (i >= 0 && items [i].setRadioSelection (false)) --i;
- int j = index + 1;
- while (j < items.length && items [j].setRadioSelection (false)) j++;
- setSelection (true);
-}
-
-/**
- * Sets the widget accelerator. An accelerator is the bit-wise
- * OR of zero or more modifier masks and a key. Examples:
- * <code>SWT.MOD1 | SWT.MOD2 | 'T', SWT.MOD3 | SWT.F2</code>.
- * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
- * The default value is zero, indicating that the menu item does
- * not have an accelerator.
- *
- * @param accelerator an integer that is the bit-wise OR of masks and a key
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAccelerator (int accelerator) {
- checkWidget();
- if (this.accelerator == accelerator) return;
- removeAccelerator ();
- this.accelerator = accelerator;
- addAccelerator ();
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled menu item is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget ();
- if (enabled) {
- state &= ~DISABLED;
- } else {
- state |= DISABLED;
- }
- int topHandle = topHandle ();
- int flags = (state & DISABLED) != 0 ? OS.Pt_BLOCKED | OS.Pt_GHOST : 0;
- OS.PtSetResource (topHandle, OS.Pt_ARG_FLAGS, flags, OS.Pt_BLOCKED | OS.Pt_GHOST);
-}
-
-/**
- * Sets the image the receiver will display to the argument.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept (for example, Windows NT).
- * Furthermore, some platforms (such as GTK), cannot display both
- * a check box and an image at the same time. Instead, they hide
- * the image and display the check box.
- * </p>
- *
- * @param image the image to display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return;
- if (this.image == image) return;
- super.setImage (image);
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) return;
- int imageHandle = 0;
- int type = OS.Pt_Z_STRING;
- if (image != null) {
- imageHandle = copyPhImage (image.handle);
- if (text.length () != 0) type = OS.Pt_TEXT_IMAGE;
- else type = OS.Pt_IMAGE;
- } else {
- /*
- * Bug in Photon. Photon will segment fault, if Pt_ARG_LABEL_IMAGE
- * is set to NULL. This means that after setting an image into a
- * PtMenuButton, it can never be removed. The fix is to set it to
- * a small blank image.
- */
- imageHandle = copyPhImage (display.nullImage);
- }
- int [] args = {
- OS.Pt_ARG_LABEL_IMAGE, imageHandle, 0,
- OS.Pt_ARG_LABEL_TYPE, type, 0,
- };
- OS.PtSetResources (handle, args.length / 3, args);
- if (imageHandle != 0) OS.free (imageHandle);
- /*
- * Bug on Photon. When a the text is set on a menu
- * item that is realized, the menu item does not resize
- * to show the new text. The fix is to force the item
- * to recalculate the size.
- */
- if (OS.PtWidgetIsRealized (handle)) OS.PtExtentWidgetFamily (parent.handle);
-}
-
-/**
- * Sets the receiver's pull down menu to the argument.
- * Only <code>CASCADE</code> menu items can have a
- * pull down menu. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pull down
- * menu is platform specific.
- * <p>
- * Note: Disposing of a menu item that has a pull down menu
- * will dispose of the menu. To avoid this behavior, set the
- * menu to null before the menu item is disposed.
- * </p>
- *
- * @param menu the new pull down menu
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_MENU_NOT_DROP_DOWN - if the menu is not a drop down menu</li>
- * <li>ERROR_MENUITEM_NOT_CASCADE - if the menu item is not a <code>CASCADE</code></li>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenu (Menu menu) {
- checkWidget();
- if ((style & SWT.CASCADE) == 0) {
- error (SWT.ERROR_MENUITEM_NOT_CASCADE);
- }
- if (menu != null) {
- if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.DROP_DOWN) == 0) {
- error (SWT.ERROR_MENU_NOT_DROP_DOWN);
- }
- if (menu.parent != parent.parent) {
- error (SWT.ERROR_INVALID_PARENT);
- }
- }
- Menu oldMenu = this.menu;
- if (oldMenu == menu) return;
- this.menu = menu;
- if (oldMenu != null) {
- oldMenu.cascade = null;
- if ((parent.style & SWT.BAR) == 0) {
- OS.PtSetResource (handle, OS.Pt_ARG_BUTTON_TYPE, OS.Pt_MENU_TEXT, 0);
- }
- }
- if (menu != null) {
- menu.cascade = this;
- if ((parent.style & SWT.BAR) == 0) {
- OS.PtSetResource (handle, OS.Pt_ARG_BUTTON_TYPE, OS.Pt_MENU_RIGHT, 0);
- }
- }
-}
-
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-/**
- * Sets the selection state of the receiver.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked.
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return;
- OS.PtSetResource (handle, OS.Pt_ARG_FLAGS, selected ? OS.Pt_SET : 0, OS.Pt_SET);
-}
-
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character and accelerator text.
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- * <p>
- * Accelerator text is indicated by the '\t' character.
- * On platforms that support accelerator text, the text
- * that follows the '\t' character is displayed to the user,
- * typically indicating the key stroke that will cause
- * the item to become selected. On most platforms, the
- * accelerator text appears right aligned in the menu.
- * Setting the accelerator text does not install the
- * accelerator key sequence. The accelerator key sequence
- * is installed using #setAccelerator.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setAccelerator
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- char [] text = new char [string.length ()];
- string.getChars (0, text.length, text, 0);
- boolean accel = false;
- int i=0, j=0;
- char mnemonic=0;
- while (i < text.length) {
- if (text [i] == '\t') {accel = true; break;}
- if ((text [j++] = text [i++]) == '&') {
- if (i == text.length) {continue;}
- if (text [i] == '&') {i++; continue;}
- if (mnemonic == 0) mnemonic = text [i];
- j--;
- }
- }
- int keyMods = 0;
- byte [] buffer2 = new byte [1];
- if (accel && ++i < text.length) {
- int start = i;
-// while (i < text.length) {
-// if (text [i] == '+') {
-// String str = new String (text, start, i - start);
-// if (str.equals ("Ctrl")) keyMods |= OS.Pk_KM_Ctrl;
-// if (str.equals ("Shift")) keyMods |= OS.Pk_KM_Shift;
-// if (str.equals ("Alt")) keyMods |= OS.Pk_KM_Alt;
-// start = i + 1;
-// }
-// i++;
-// }
- if (start < text.length) {
- char [] accelText = new char [text.length - start];
- System.arraycopy (text, start, accelText, 0, accelText.length);
- buffer2 = Converter.wcsToMbcs (null, accelText, true);
- }
- }
- while (j < text.length) text [j++] = 0;
- byte [] buffer1 = Converter.wcsToMbcs (null, text, true);
- int ptr1 = OS.malloc (buffer1.length);
- OS.memmove (ptr1, buffer1, buffer1.length);
- int ptr2 = OS.malloc (buffer2.length);
- OS.memmove (ptr2, buffer2, buffer2.length);
- int ptr3 = 0;
- if (mnemonic != 0) {
- byte [] buffer3 = Converter.wcsToMbcs (null, new char []{mnemonic}, true);
- ptr3 = OS.malloc (buffer3.length);
- OS.memmove (ptr3, buffer3, buffer3.length);
- }
- if ((parent.style & SWT.BAR) != 0) {
- replaceMnemonic (mnemonic, false, true);
- }
- int type = OS.Pt_Z_STRING;
- if ((style & SWT.PUSH) != 0) {
- if (image != null) type = OS.Pt_TEXT_IMAGE;
- }
- int [] args = {
- OS.Pt_ARG_TEXT_STRING, ptr1, 0,
- OS.Pt_ARG_ACCEL_TEXT, ptr2, 0,
- OS.Pt_ARG_MODIFIER_KEYS, keyMods, keyMods,
- OS.Pt_ARG_ACCEL_KEY, ptr3, 0,
- OS.Pt_ARG_LABEL_TYPE, type, 0,
- };
- OS.PtSetResources (handle, args.length / 3, args);
- OS.free (ptr1);
- OS.free (ptr2);
- OS.free (ptr3);
- /*
- * Bug on Photon. When a the text is set on a menu
- * item that is realized, the menu item does not resize
- * to show the new text. The fix is to force the item
- * to recalculate the size.
- */
- if (OS.PtWidgetIsRealized (handle)) OS.PtExtentWidgetFamily (parent.handle);
-}
-
-void showMenu() {
- if (menu == null) return;
- int menuHandle = menu.handle;
- if (!OS.PtWidgetIsRealized (menuHandle)) {
- if ((parent.style & SWT.BAR) == 0) {
- OS.PtSetResource (menuHandle, OS.Pt_ARG_MENU_FLAGS, OS.Pt_MENU_CHILD, OS.Pt_MENU_CHILD);
- }
- OS.PtReParentWidget (menuHandle, handle);
-
- /*
- * Bug in Photon. PtPositionMenu does not position the menu
- * properly when the menu is a direct child a menu bar item.
- * The fix is to position the menu ourselfs.
- */
- if ((parent.style & SWT.BAR) != 0) {
- PhPoint_t pt = new PhPoint_t ();
- short [] x = new short [1], y = new short [1];
- OS.PtGetAbsPosition (handle, x, y);
- pt.x = x [0];
- pt.y = y [0];
- int [] args = {OS.Pt_ARG_HEIGHT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- pt.y += args [1];
- int ptr = OS.malloc (PhPoint_t.sizeof);
- OS.memmove (ptr, pt, PhPoint_t.sizeof);
- OS.PtSetResource (menuHandle, OS.Pt_ARG_POS, ptr, 0);
- OS.free (ptr);
- } else {
- OS.PtPositionMenu (menuHandle, null);
- }
-
- menu.sendEvent (SWT.Show);
- OS.PtRealizeWidget (menuHandle);
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MessageBox.java
deleted file mode 100755
index 3f5de9a94c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MessageBox.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class are used to inform or warn the user.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, ICON_WARNING, ICON_WORKING</dd>
- * <dd>OK, OK | CANCEL</dd>
- * <dd>YES | NO, YES | NO | CANCEL</dd>
- * <dd>RETRY | CANCEL</dd>
- * <dd>ABORT | RETRY | IGNORE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION, ICON_QUESTION,
- * ICON_WARNING and ICON_WORKING may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class MessageBox extends Dialog {
- String message = "";
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public MessageBox (Shell parent) {
- this (parent, SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL);
-}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_QUESTION
- * @see SWT#ICON_WARNING
- * @see SWT#ICON_WORKING
- * @see SWT#OK
- * @see SWT#CANCEL
- * @see SWT#YES
- * @see SWT#NO
- * @see SWT#ABORT
- * @see SWT#RETRY
- * @see SWT#IGNORE
- */
-public MessageBox (Shell parent, int style) {
- super (parent, checkStyle (parent, checkStyle (style)));
- checkSubclass ();
-}
-static int checkStyle (int style) {
- int mask = (SWT.YES | SWT.NO | SWT.OK | SWT.CANCEL | SWT.ABORT | SWT.RETRY | SWT.IGNORE);
- int bits = style & mask;
- if (bits == SWT.OK || bits == SWT.CANCEL || bits == (SWT.OK | SWT.CANCEL)) return style;
- if (bits == SWT.YES || bits == SWT.NO || bits == (SWT.YES | SWT.NO) || bits == (SWT.YES | SWT.NO | SWT.CANCEL)) return style;
- if (bits == (SWT.RETRY | SWT.CANCEL) || bits == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) return style;
- style = (style & ~mask) | SWT.OK;
- return style;
-}
-/**
- * Returns the dialog's message, or an empty string if it does not have one.
- * The message is a description of the purpose for which the dialog was opened.
- * This message will be visible in the dialog while it is open.
- *
- * @return the message
- */
-public String getMessage () {
- return message;
-}
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return the ID of the button that was selected to dismiss the
- * message box (e.g. SWT.OK, SWT.CANCEL, etc.)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public int open () {
- String[] buttons = null;
- if ((style & SWT.OK) == SWT.OK) {
- buttons = new String[]{SWT.getMessage ("SWT_OK")};
- }
- if ((style & (SWT.OK | SWT.CANCEL)) == (SWT.OK | SWT.CANCEL)) {
- buttons = new String[]{SWT.getMessage ("SWT_OK"), SWT.getMessage ("SWT_Cancel")};
- }
- if ((style & (SWT.YES | SWT.NO)) == (SWT.YES | SWT.NO)) {
- buttons = new String[]{SWT.getMessage ("SWT_Yes"), SWT.getMessage ("SWT_No")};
- }
- if ((style & (SWT.YES | SWT.NO | SWT.CANCEL)) == (SWT.YES | SWT.NO | SWT.CANCEL)){
- buttons = new String[]{SWT.getMessage ("SWT_Yes"), SWT.getMessage ("SWT_No"), SWT.getMessage ("SWT_Cancel")};
- }
- if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) {
- buttons = new String[]{SWT.getMessage ("SWT_Retry"), SWT.getMessage ("SWT_Cancel")};
- }
- if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) {
- buttons = new String[]{SWT.getMessage ("SWT_Abort"), SWT.getMessage ("SWT_Retry"), SWT.getMessage ("SWT_Cancel")};
- }
- if (buttons == null) buttons = new String[]{SWT.getMessage ("SWT_OK")};
-
- int phImage = 0;
-// int iconBits = 0;
-// if ((style & SWT.ICON_ERROR) != 0) iconBits = OS.MB_ICONERROR;
-// if ((style & SWT.ICON_INFORMATION) != 0) iconBits = OS.MB_ICONINFORMATION;
-// if ((style & SWT.ICON_QUESTION) != 0) iconBits = OS.MB_ICONQUESTION;
-// if ((style & SWT.ICON_WARNING) != 0) iconBits = OS.MB_ICONWARNING;
-// if ((style & SWT.ICON_WORKING) != 0) iconBits = OS.MB_ICONINFORMATION;
-
- int parentHandle = 0;
- if (parent != null && OS.PtWidgetIsRealized(parent.shellHandle)) {
- parentHandle = parent.shellHandle;
- }
- byte [] title = null;
- if (this.title != null) title = Converter.wcsToMbcs (null, this.title, true);
- byte [] message = null;
- message = Converter.wcsToMbcs (null, this.message, true);
-
- int[] buttonsPtr = new int [buttons.length];
- for (int i=0; i<buttons.length; i++) {
- byte[] text = Converter.wcsToMbcs (null, buttons [i], true);
- int textPtr = OS.malloc (text.length);
- OS.memmove (textPtr, text, text.length);
- buttonsPtr [i] = textPtr;
- }
-
- int button = OS.PtAlert (parentHandle, null, title, phImage, message, null, buttons.length, buttonsPtr, null, 0, buttons.length, OS.Pt_MODAL);
-
- for (int i=0; i<buttons.length; i++) {
- OS.free (buttonsPtr [i]);
- }
-
- if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) {
- if (button == 1) return SWT.ABORT;
- if (button == 2) return SWT.RETRY;
- return SWT.IGNORE;
- }
- if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) {
- return (button == 1) ? SWT.RETRY : SWT.CANCEL;
- }
- if ((style & (SWT.YES | SWT.NO | SWT.CANCEL)) == (SWT.YES | SWT.NO | SWT.CANCEL)) {
- if (button == 1) return SWT.YES;
- if (button == 2) return SWT.NO;
- return SWT.CANCEL;
- }
- if ((style & (SWT.YES | SWT.NO)) == (SWT.YES | SWT.NO)) {
- return (button == 1) ? SWT.YES : SWT.NO;
- }
- if ((style & (SWT.OK | SWT.CANCEL)) == (SWT.OK | SWT.CANCEL)) {
- return (button == 1) ? SWT.OK : SWT.CANCEL;
- }
- if ((style & SWT.OK) == SWT.OK && button == 1) return SWT.OK;
- return SWT.CANCEL;
-}
-/**
- * Sets the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @param string the message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- */
-public void setMessage (String string) {
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- message = string;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ProgressBar.java
deleted file mode 100755
index 575bc28393..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ProgressBar.java
+++ /dev/null
@@ -1,292 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of the receiver represent an unselectable
- * user interface object that is used to display progress,
- * typically in the form of a bar.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SMOOTH, HORIZONTAL, VERTICAL, INDETERMINATE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#progressbar">ProgressBar snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ProgressBar extends Control {
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SMOOTH
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#INDETERMINATE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ProgressBar (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-/*
-* Not done - check Windows
-*/
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = wHint, height = hHint;
- if ((style & SWT.HORIZONTAL) != 0) {
- if (width == SWT.DEFAULT) {
- width = 64;
-// width = getMaximum() - getMinimum() + 1;
- }
- if (height == SWT.DEFAULT) height = 15;
- } else {
- if (height == SWT.DEFAULT) {
- height = 64;
-// height = getMaximum() - getMinimum() + 1;
- }
- if (width == SWT.DEFAULT) width = 15;
- }
- PhRect_t rect = new PhRect_t ();
- PhArea_t area = new PhArea_t ();
- rect.lr_x = (short) (width - 1);
- rect.lr_y = (short) (height - 1);
- OS.PtSetAreaFromWidgetCanvas (handle, rect, area);
- width = area.size_w;
- height = area.size_h;
- return new Point (width, height);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- int clazz = display.PtProgress;
- int parentHandle = parent.parentingHandle ();
- int gaugeFlags = (style & SWT.INDETERMINATE) != 0 ? OS.Pt_GAUGE_INDETERMINATE : 0;
- int [] args = {
- OS.Pt_ARG_FLAGS, 0, OS.Pt_GETS_FOCUS,
- OS.Pt_ARG_GAUGE_FLAGS, gaugeFlags, OS.Pt_GAUGE_INDETERMINATE,
- OS.Pt_ARG_ORIENTATION, (style & SWT.HORIZONTAL) != 0 ? OS.Pt_HORIZONTAL : OS.Pt_VERTICAL, 0,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (clazz, parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-
-byte [] defaultFont () {
- return display.GAUGE_FONT;
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget();
- int [] args = {OS.Pt_ARG_MAXIMUM, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget();
- int [] args = {OS.Pt_ARG_MINIMUM, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the single 'selection' that is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget();
- int [] args = {OS.Pt_ARG_GAUGE_VALUE, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the state of the receiver. The value will be one of:
- * <ul>
- * <li>{@link SWT#NORMAL}</li>
- * <li>{@link SWT#ERROR}</li>
- * <li>{@link SWT#PAUSED}</li>
- * </ul>
- *
- * @return the state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public int getState () {
- checkWidget ();
- return SWT.NORMAL;
-}
-
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget();
- int minimum = getMinimum();
- if (0 <= minimum && minimum < value) {
- OS.PtSetResource (handle, OS.Pt_ARG_MAXIMUM, value, 0);
- }
-}
-
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is negative or is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be nonnegative and less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget();
- int maximum = getMaximum();
- if (0 <= value && value < maximum) {
- OS.PtSetResource (handle, OS.Pt_ARG_MINIMUM, value, 0);
- }
-}
-
-/**
- * Sets the single 'selection' that is the receiver's
- * position to the argument which must be greater than or equal
- * to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget();
- OS.PtSetResource (handle, OS.Pt_ARG_GAUGE_VALUE, value, 0);
-}
-
-/**
- * Sets the state of the receiver. The state must be one of these values:
- * <ul>
- * <li>{@link SWT#NORMAL}</li>
- * <li>{@link SWT#ERROR}</li>
- * <li>{@link SWT#PAUSED}</li>
- * </ul>
- *
- * @param state the new state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setState (int state) {
- checkWidget ();
- //NOT IMPLEMENTED
-}
-
-int traversalCode (int key_sym, PhKeyEvent_t ke) {
- return 0;
-}
-
-int widgetClass () {
- return OS.PtProgress ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Sash.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Sash.java
deleted file mode 100755
index f6af35eff8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Sash.java
+++ /dev/null
@@ -1,422 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of the receiver represent a selectable user interface object
- * that allows the user to drag a rubber banded outline of the sash within
- * the parent control.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL, SMOOTH</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#sash">Sash snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Sash extends Control {
- boolean dragging;
- int startX, startY, lastX, lastY;
- final static int INCREMENT = 1;
- final static int PAGE_INCREMENT = 9;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#SMOOTH
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Sash (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the x, y, width, and height fields of the event object are valid.
- * If the receiver is being dragged, the event object detail field contains the value <code>SWT.DRAG</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += DEFAULT_WIDTH; height += 3;
- } else {
- width += 3; height += DEFAULT_HEIGHT;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-
-void createHandle (int index) {
- state |= GRAB | HANDLE;
- int clazz = display.PtContainer;
- int parentHandle = parent.parentingHandle ();
- int cursor = ((style & SWT.HORIZONTAL) != 0) ? OS.Ph_CURSOR_DRAG_VERTICAL : OS.Ph_CURSOR_DRAG_HORIZONTAL;
- int [] args = {
- OS.Pt_ARG_FLAGS, 0, OS.Pt_GETS_FOCUS,
- OS.Pt_ARG_CURSOR_TYPE, cursor, 0,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (clazz, parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-
-byte [] defaultFont () {
- return display.TITLE_FONT;
-}
-
-void drawBand (int x, int y, int width, int height) {
- if (parent == null) return;
- if (parent.isDisposed ()) return;
- int parentHandle = parent.handle;
- if (!OS.PtWidgetIsRealized (parentHandle)) return;
- int phGC = OS.PgCreateGC (0); // NOTE: PgCreateGC ignores the parameter
- if (phGC == 0) return;
- int [] args = {OS.Pt_ARG_COLOR, 0, 0, OS.Pt_ARG_FILL_COLOR, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- int foreground = args [1];
- int background = args [4];
- int color = foreground ^ ~background;
- int prevContext = OS.PgSetGC (phGC);
- int disjoint = OS.PtFindDisjoint( handle );
- if( disjoint != 0 )
- OS.PgSetRegion( OS.PtWidgetRid( disjoint ) );
- PhPoint_t pt = new PhPoint_t ();
-// PhRect_t tran_rect = new PhRect_t();
- if (parentHandle <= 0) return;
- OS.PtWidgetOffset(parentHandle, pt);
- OS.PgSetTranslation(pt,0);
- OS.PgSetDrawMode (OS.Pg_DrawModeDSx);
- OS.PgSetFillColor (color);
- OS.PgDrawIRect (x, y, x + width - 1, y + height - 1, OS.Pg_DRAW_FILL);
- OS.PgSetGC (prevContext);
- OS.PgDestroyGC (phGC);
-}
-
-int Ph_EV_BUT_PRESS (int widget, int info) {
- int result = super.Ph_EV_BUT_PRESS (widget, info);
- if (result != OS.Pt_CONTINUE)return result;
- processMouse (info);
- return result;
-}
-
-int Ph_EV_BUT_RELEASE (int widget, int info) {
- int result = super.Ph_EV_BUT_RELEASE (widget, info);
- if (result != OS.Pt_CONTINUE)return result;
- processMouse (info);
- return result;
-}
-
-int Ph_EV_DRAG (int widget, int info) {
- int result = super.Ph_EV_DRAG (widget, info);
- if (result != OS.Pt_CONTINUE)return result;
- processMouse (info);
- return result;
-}
-
-int Ph_EV_PTR_MOTION (int widget, int info) {
- int result = super.Ph_EV_PTR_MOTION (widget, info);
- if (result != OS.Pt_CONTINUE)return result;
- processMouse (info);
- return result;
-}
-
-void processMouse (int info) {
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- PhEvent_t ev = new PhEvent_t ();
- OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
- int data = OS.PhGetData (cbinfo.event);
- PhPointerEvent_t pe = new PhPointerEvent_t ();
- OS.memmove (pe, data, PhPointerEvent_t.sizeof);
- if (pe.buttons != OS.Ph_BUTTON_SELECT) return;
-
- int x = pe.pos_x + ev.translation_x;
- int y = pe.pos_y + ev.translation_y;
- PhArea_t area = new PhArea_t ();
- OS.PtWidgetArea (handle, area);
- Event event = new Event ();
- int width = event.width = area.size_w;
- int height = event.height = area.size_h;
- switch (ev.type) {
- case OS.Ph_EV_BUT_PRESS:
- PhRect_t rect = new PhRect_t ();
- PhPoint_t pos = new PhPoint_t();
- pos.x = pe.pos_x;
- pos.y = pe.pos_y;
- rect.ul_x = rect.lr_x = (short) (pos.x + ev.translation_x);
- rect.ul_y = rect.lr_y = (short) (pos.y + ev.translation_y);
- int rid = OS.PtWidgetRid (handle);
-// int input_group = OS.PhInputGroup (cbinfo.event);
- int input_group = OS.PhInputGroup (0);
- OS.PhInitDrag (rid, OS.Ph_DRAG_KEY_MOTION | OS.Ph_DRAG_TRACK | OS.Ph_TRACK_DRAG, rect, null, input_group, null, null, null, pos, null);
-
- /* Compute the banding rectangle */
- startX = x;
- startY = y;
- lastX = area.pos_x;
- lastY = area.pos_y;
-
- /* The event must be sent because doit flag is used */
- event.x = lastX; event.y = lastY;
- event.detail = SWT.DRAG;
-
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the selection
- * event. If this happens, end the processing of the
- * Windows message by returning zero as the result of
- * the window proc.
- */
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return;
-
- /* Draw the banding rectangle */
- if (event.doit) {
- dragging = true;
- menuShell ().bringToTop (true);
- OS.PtFlush ();
- drawBand (lastX = event.x, lastY = event.y, width, height);
- }
- break;
- case OS.Ph_EV_BUT_RELEASE:
- if (ev.subtype != OS.Ph_EV_RELEASE_PHANTOM) {
- return;
- }
- /* Compute the banding rectangle */
- if (!dragging) return;
- dragging = false;
-
- /* The event must be sent because doit flag is used */
- event.x = lastX; event.y = lastY;
- drawBand (lastX, lastY, width, height);
- sendEvent (SWT.Selection, event);
- // widget could be disposed at this point
- break;
- case OS.Ph_EV_PTR_MOTION_BUTTON:
- case OS.Ph_EV_PTR_MOTION_NOBUTTON:
- case OS.Ph_EV_DRAG:
- if (ev.subtype != OS.Ph_EV_DRAG_MOTION_EVENT) {
- return;
- }
- if (!dragging) return;
-
- /* Compute the banding rectangle */
- x += area.pos_x;
- y += area.pos_y;
- Rectangle r = parent.getClientArea ();
- int clientWidth = r.width;
- int clientHeight = r.height;
- int newX = lastX, newY = lastY;
- if ((style & SWT.VERTICAL) != 0) {
- newX = Math.min (Math.max (0, x - startX), clientWidth - width);
- } else {
- newY = Math.min (Math.max (0, y - startY), clientHeight - height);
- }
- if ((newX == lastX) && (newY == lastY)) return;
- drawBand (lastX, lastY, width, height);
-
- /* The event must be sent because doit flag is used */
- event.x = newX; event.y = newY;
- event.detail = SWT.DRAG;
-
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the selection
- * event. If this happens, end the processing of the
- * Windows message by returning zero as the result of
- * the window proc.
- */
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return;
-
- /* Draw the banding rectangle */
- if (event.doit) {
- lastX = event.x; lastY = event.y;
- OS.PtFlush ();
- drawBand (lastX, lastY, width, height);
- }
- break;
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-int traversalCode (int key_sym, PhKeyEvent_t ke) {
- return 0;
-}
-
-boolean translateTraversal (int key_sym, PhKeyEvent_t phEvent) {
- boolean result = super.translateTraversal (key_sym, phEvent);
- if (!result) {
- switch (key_sym) {
- case OS.Pk_Left:
- case OS.Pk_Right:
- case OS.Pk_Up:
- case OS.Pk_Down:
-
- /* Calculate the new x or y position */
- if ((phEvent.button_state & OS.Ph_BUTTON_SELECT) != 0) return result;
- int step = (phEvent.key_mods & OS.Pk_KM_Ctrl) != 0 ? INCREMENT : PAGE_INCREMENT;
- int x = 0, y = 0;
- if ((style & SWT.VERTICAL) != 0) {
- if (key_sym == OS.Pk_Up || key_sym == OS.Pk_Down) break;
- x = key_sym == OS.Pk_Left ? -step : step;
- } else {
- if (key_sym == OS.Pk_Left || key_sym == OS.Pk_Right) break;
- y = key_sym == OS.Pk_Up ? -step : step;
- }
- PhArea_t area = new PhArea_t ();
- OS.PtWidgetArea (handle, area);
- x += area.pos_x;
- y += area.pos_y;
- int width = area.size_w;
- int height = area.size_h;
- Rectangle r = parent.getClientArea ();
- int clientWidth = r.width;
- int clientHeight = r.height;
- int newX = lastX, newY = lastY;
- if ((style & SWT.VERTICAL) != 0) {
- newX = Math.min (Math.max (0, x - startX), clientWidth - width);
- } else {
- newY = Math.min (Math.max (0, y - startY), clientHeight - height);
- }
- if (newX == lastX && newY == lastY) return result;
-
- /* The event must be sent because doit flag is used */
- Event event = new Event ();
- event.x = newX; event.y = newY;
- event.width = width; event.height = height;
-
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the selection
- * event. If this happens, end the processing of the
- * Windows message by returning zero as the result of
- * the window proc.
- */
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return true;
- if (event.doit) {
- OS.PtWidgetArea (handle, area);
- int cursorX = area.size_w / 2, cursorY = area.size_h / 2;
- short [] absX = new short [1], absY = new short [1];
- OS.PtGetAbsPosition (handle, absX, absY);
- OS.PhMoveCursorAbs (OS.PhInputGroup (0), cursorX + absX [0], cursorY + absY [0]);
- }
- return result;
- }
- }
- return result;
-}
-
-int widgetClass () {
- return OS.PtContainer ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Scale.java
deleted file mode 100755
index a53bcc02f4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Scale.java
+++ /dev/null
@@ -1,378 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of the receiver represent a selectable user
- * interface object that present a range of continuous
- * numeric values.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#scale">Scale snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Scale extends Control {
-
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Scale (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the receiver's value.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- PhDim_t dim = new PhDim_t();
- if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidget (handle);
- OS.PtWidgetPreferredSize(handle, dim);
- /*
- * Feature in Photon. The preferred size of PtSlider is only the
- * handle size. Add extra space for the rest.
- */
- int width, height;
- if ((style & SWT.HORIZONTAL) != 0) {
- width = dim.w * 7; height = dim.h * 2;
- } else {
- width = dim.w * 2; height = dim.h * 7;
- }
- if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) {
- PhRect_t rect = new PhRect_t ();
- PhArea_t area = new PhArea_t ();
- rect.lr_x = (short) (wHint - 1);
- rect.lr_y = (short) (hHint - 1);
- OS.PtSetAreaFromWidgetCanvas (handle, rect, area);
- if (wHint != SWT.DEFAULT) width = area.size_w;
- if (hHint != SWT.DEFAULT) height = area.size_h;
- }
- return new Point (width, height);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- int clazz = display.PtSlider;
- int parentHandle = parent.parentingHandle ();
- int [] args = {
- OS.Pt_ARG_MAXIMUM, 100, 0,
- OS.Pt_ARG_PAGE_INCREMENT, 10, 0,
- OS.Pt_ARG_SLIDER_SIZE, 10, 0,
- OS.Pt_ARG_ORIENTATION, (style & SWT.HORIZONTAL) != 0 ? OS.Pt_HORIZONTAL : OS.Pt_VERTICAL, 0,
- OS.Pt_ARG_FILL_COLOR, display.WIDGET_BACKGROUND, 0,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (clazz, parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-
-byte [] defaultFont () {
- return display.GAUGE_FONT;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget();
- int [] args = {OS.Pt_ARG_INCREMENT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget();
- int [] args = {OS.Pt_ARG_MAXIMUM, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget();
- int [] args = {OS.Pt_ARG_MINIMUM, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget();
- int [] args = {OS.Pt_ARG_PAGE_INCREMENT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the 'selection', which is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget();
- int [] args = {OS.Pt_ARG_GAUGE_VALUE, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- OS.PtAddCallback (handle, OS.Pt_CB_SLIDER_MOVE, windowProc, OS.Pt_CB_SLIDER_MOVE);
-}
-
-int Pt_CB_SLIDER_MOVE (int widget, int info) {
- if (info == 0) return OS.Pt_CONTINUE;
- sendEvent(SWT.Selection);
- return OS.Pt_CONTINUE;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param increment the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget();
- OS.PtSetResource (handle, OS.Pt_ARG_INCREMENT, value, 0);
-}
-
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget();
- OS.PtSetResource (handle, OS.Pt_ARG_MAXIMUM, value, 0);
-}
-
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is negative or is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be nonnegative and less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget();
- OS.PtSetResource (handle, OS.Pt_ARG_MINIMUM, value, 0);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param pageIncrement the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget();
- OS.PtSetResource (handle, OS.Pt_ARG_PAGE_INCREMENT, value, 0);
-}
-
-/**
- * Sets the 'selection', which is the receiver's value,
- * to the argument which must be greater than or equal to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget();
- OS.PtSetResource (handle, OS.Pt_ARG_GAUGE_VALUE, value, 0);
-}
-
-int widgetClass () {
- return OS.PtSlider ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ScrollBar.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ScrollBar.java
deleted file mode 100755
index e92f951cd6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ScrollBar.java
+++ /dev/null
@@ -1,725 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that represent a range of positive, numeric values.
- * <p>
- * At any given moment, a given scroll bar will have a
- * single 'selection' that is considered to be its
- * value, which is constrained to be within the range of
- * values the scroll bar represents (that is, between its
- * <em>minimum</em> and <em>maximum</em> values).
- * </p><p>
- * Typically, scroll bars will be made up of five areas:
- * <ol>
- * <li>an arrow button for decrementing the value</li>
- * <li>a page decrement area for decrementing the value by a larger amount</li>
- * <li>a <em>thumb</em> for modifying the value by mouse dragging</li>
- * <li>a page increment area for incrementing the value by a larger amount</li>
- * <li>an arrow button for incrementing the value</li>
- * </ol>
- * Based on their style, scroll bars are either <code>HORIZONTAL</code>
- * (which have a left facing button for decrementing the value and a
- * right facing button for incrementing it) or <code>VERTICAL</code>
- * (which have an upward facing button for decrementing the value
- * and a downward facing buttons for incrementing it).
- * </p><p>
- * On some platforms, the size of the scroll bar's thumb can be
- * varied relative to the magnitude of the range of values it
- * represents (that is, relative to the difference between its
- * maximum and minimum values). Typically, this is used to
- * indicate some proportional value such as the ratio of the
- * visible area of a document to the total amount of space that
- * it would take to display it. SWT supports setting the thumb
- * size even if the underlying platform does not, but in this
- * case the appearance of the scroll bar will not change.
- * </p><p>
- * Scroll bars are created by specifying either <code>H_SCROLL</code>,
- * <code>V_SCROLL</code> or both when creating a <code>Scrollable</code>.
- * They are accessed from the <code>Scrollable</code> using
- * <code>getHorizontalBar</code> and <code>getVerticalBar</code>.
- * </p><p>
- * Note: Scroll bars are not Controls. On some platforms, scroll bars
- * that appear as part of some standard controls such as a text or list
- * have no operating system resources and are not children of the control.
- * For this reason, scroll bars are treated specially. To create a control
- * that looks like a scroll bar but has operating system resources, use
- * <code>Slider</code>.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see Slider
- * @see Scrollable
- * @see Scrollable#getHorizontalBar
- * @see Scrollable#getVerticalBar
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ScrollBar extends Widget {
- Scrollable parent;
-
-ScrollBar (Scrollable parent, int style, int handle) {
- super (parent, checkStyle (style));
- this.parent = parent;
- this.handle = handle;
- state |= HANDLE;
- createWidget (0);
-}
-
-ScrollBar (Scrollable parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (0);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values:
- * <code>SWT.NONE</code> - for the end of a drag.
- * <code>SWT.DRAG</code>.
- * <code>SWT.HOME</code>.
- * <code>SWT.END</code>.
- * <code>SWT.ARROW_DOWN</code>.
- * <code>SWT.ARROW_UP</code>.
- * <code>SWT.PAGE_DOWN</code>.
- * <code>SWT.PAGE_UP</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- if (handle != 0) return;
- int parentHandle = parent.scrolledHandle;
- int orientation, sizeArg, size, basicFlags;
- if ((style & SWT.HORIZONTAL) != 0) {
- orientation = OS.Pt_HORIZONTAL;
- sizeArg = OS.Pt_ARG_HEIGHT;
- size = display.SCROLLBAR_HEIGHT;
- basicFlags = display.SCROLLBAR_HORIZONTAL_BASIC_FLAGS;
- } else {
- orientation = OS.Pt_VERTICAL;
- sizeArg = OS.Pt_ARG_WIDTH;
- size = display.SCROLLBAR_WIDTH;
- basicFlags = display.SCROLLBAR_VERTICAL_BASIC_FLAGS;
- }
- int [] args = {
- sizeArg, size, 0,
- OS.Pt_ARG_MAXIMUM, 99, 0,
- OS.Pt_ARG_PAGE_INCREMENT, 10, 0,
- OS.Pt_ARG_SLIDER_SIZE, 10, 0,
- OS.Pt_ARG_BASIC_FLAGS, basicFlags, ~0,
- OS.Pt_ARG_ORIENTATION, orientation, 0,
- OS.Pt_ARG_FLAGS, 0, OS.Pt_GETS_FOCUS,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (OS.PtScrollbar (), parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget ();
- int topHandle = topHandle ();
- return (OS.PtWidgetFlags (topHandle) & OS.Pt_BLOCKED) == 0;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget();
- int [] args = {OS.Pt_ARG_INCREMENT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget();
- int [] args = {OS.Pt_ARG_MINIMUM, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget();
- int [] args = {OS.Pt_ARG_MAXIMUM, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1] + 1;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget();
- int [] args = {OS.Pt_ARG_PAGE_INCREMENT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the receiver's parent, which must be a Scrollable.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Scrollable getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns the single 'selection' that is the receiver's value.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget();
- int [] args = {OS.Pt_ARG_GAUGE_VALUE, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- int [] args = {OS.Pt_ARG_WIDTH, 0, 0, OS.Pt_ARG_HEIGHT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return new Point (args [1], args [4]);
-}
-
-/**
- * Returns the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values.
- *
- * @return the thumb value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ScrollBar
- */
-public int getThumb () {
- checkWidget();
- int [] args = {OS.Pt_ARG_SLIDER_SIZE, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- int topHandle = topHandle ();
- return (OS.PtWidgetFlags (topHandle) & OS.Pt_DELAY_REALIZE) == 0;
-}
-
-void hookEvents () {
- int windowProc = display.windowProc;
- OS.PtAddCallback (handle, OS.Pt_CB_SCROLL_MOVE, windowProc, OS.Pt_CB_SCROLL_MOVE);
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return OS.PtWidgetIsRealized (handle);
-}
-
-int Pt_CB_SCROLL_MOVE (int widget, int info) {
- if (info == 0) return OS.Pt_CONTINUE;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.cbdata == 0) return OS.Pt_CONTINUE;
- PtScrollbarCallback_t cb = new PtScrollbarCallback_t ();
- OS.memmove (cb, cbinfo.cbdata, PtScrollbarCallback_t.sizeof);
- Event event = new Event ();
- switch (cb.action) {
- case OS.Pt_SCROLL_DRAGGED:
- event.detail = SWT.DRAG;
- break;
- case OS.Pt_SCROLL_TO_MIN:
- event.detail = SWT.HOME;
- break;
- case OS.Pt_SCROLL_TO_MAX:
- event.detail = SWT.END;
- break;
- case OS.Pt_SCROLL_INCREMENT:
- event.detail = SWT.ARROW_DOWN;
- break;
- case OS.Pt_SCROLL_DECREMENT :
- event.detail = SWT.ARROW_UP;
- break;
- case OS.Pt_SCROLL_PAGE_DECREMENT:
- event.detail = SWT.PAGE_UP;
- break;
- case OS.Pt_SCROLL_PAGE_INCREMENT:
- event.detail = SWT.PAGE_DOWN;
- break;
- }
- sendEvent(SWT.Selection, event);
- return OS.Pt_CONTINUE;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (parent.horizontalBar == this) parent.horizontalBar = null;
- if (parent.verticalBar == this) parent.verticalBar = null;
-}
-
-void setBounds (int x, int y, int width, int height) {
- PhArea_t area = new PhArea_t ();
- area.pos_x = (short) x;
- area.pos_y = (short) y;
- area.size_w = (short) (Math.max (width, 0));
- area.size_h = (short) (Math.max (height, 0));
- int ptr = OS.malloc (PhArea_t.sizeof);
- OS.memmove (ptr, area, PhArea_t.sizeof);
- OS.PtSetResource (handle, OS.Pt_ARG_AREA, ptr, 0);
- OS.free (ptr);
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget ();
- int topHandle = topHandle ();
- int flags = enabled ? 0 : OS.Pt_BLOCKED | OS.Pt_GHOST;
- OS.PtSetResource (topHandle, OS.Pt_ARG_FLAGS, flags, OS.Pt_BLOCKED | OS.Pt_GHOST);
-}
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget();
- OS.PtSetResource (handle, OS.Pt_ARG_INCREMENT, value, 0);
-}
-
-/**
- * Sets the maximum. If this value is negative or less than or
- * equal to the minimum, the value is ignored. If necessary, first
- * the thumb and then the selection are adjusted to fit within the
- * new range.
- *
- * @param value the new maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget();
- int [] args = {
- OS.Pt_ARG_MAXIMUM, 0, 0,
- OS.Pt_ARG_MINIMUM, 0, 0,
- OS.Pt_ARG_SLIDER_SIZE, 0, 0,
- OS.Pt_ARG_GAUGE_VALUE, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- int minimum = args [4];
- if (value <= minimum) return;
- int thumb = args [7];
- thumb = Math.min (thumb, value - minimum);
- int selection = args [10];
- selection = Math.min (selection, value - thumb);
- args [1] = value - 1;
- args [7] = thumb;
- args [10] = selection;
- OS.PtSetResources (handle, args.length / 3, args);
-}
-
-/**
- * Sets the minimum value. If this value is negative or greater
- * than or equal to the maximum, the value is ignored. If necessary,
- * first the thumb and then the selection are adjusted to fit within
- * the new range.
- *
- * @param value the new minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget();
- if (value < 0) return;
- int [] args = {
- OS.Pt_ARG_MAXIMUM, 0, 0,
- OS.Pt_ARG_MINIMUM, 0, 0,
- OS.Pt_ARG_SLIDER_SIZE, 0, 0,
- OS.Pt_ARG_GAUGE_VALUE, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- int maximum = args [1] + 1;
- if (value >= maximum) return;
- int thumb = args [7];
- thumb = Math.min (thumb, maximum - value);
- int selection = args [10];
- selection = Math.max (selection, value);
- args [4] = value;
- args [7] = thumb;
- args [10] = selection;
- OS.PtSetResources (handle, args.length / 3, args);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget();
- OS.PtSetResource (handle, OS.Pt_ARG_PAGE_INCREMENT, value, 0);
-}
-
-/**
- * Sets the single <em>selection</em> that is the receiver's
- * value to the argument which must be greater than or equal
- * to zero.
- *
- * @param selection the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget();
- OS.PtSetResource (handle, OS.Pt_ARG_GAUGE_VALUE, value, 0);
-}
-
-/**
- * Sets the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values. This new
- * value will be ignored if it is less than one, and will be
- * clamped if it exceeds the receiver's current range.
- *
- * @param value the new thumb value, which must be at least one and not
- * larger than the size of the current range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setThumb (int value) {
- checkWidget();
- if (value < 1) return;
- int [] args = {OS.Pt_ARG_MINIMUM, 0, 0, OS.Pt_ARG_MAXIMUM, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- int minimum = args [1];
- int maximum = args [4] + 1;
- value = Math.min (value, maximum - minimum);
- OS.PtSetResource (handle, OS.Pt_ARG_SLIDER_SIZE, value, 0);
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, thumb, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param thumb the new thumb value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- checkWidget();
- if (minimum < 0) return;
- if (maximum < 0) return;
- if (thumb < 1) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- thumb = Math.min (thumb, maximum - minimum);
- int [] args = {
- OS.Pt_ARG_MAXIMUM, maximum - 1, 0,
- OS.Pt_ARG_MINIMUM, minimum, 0,
- OS.Pt_ARG_SLIDER_SIZE, thumb, 0,
- OS.Pt_ARG_GAUGE_VALUE, selection, 0,
- OS.Pt_ARG_INCREMENT, increment, 0,
- OS.Pt_ARG_PAGE_INCREMENT, pageIncrement, 0,
- };
- OS.PtSetResources (handle, args.length / 3, args);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- int topHandle = topHandle ();
- int oldFlags = OS.PtWidgetFlags (topHandle);
- int flags = visible ? 0 : OS.Pt_DELAY_REALIZE;
- OS.PtSetResource (topHandle, OS.Pt_ARG_FLAGS, flags, OS.Pt_DELAY_REALIZE);
- if ((oldFlags & OS.Pt_DELAY_REALIZE) == flags) return;
- parent.resizeClientArea ();
- if (visible) {
- sendEvent (SWT.Show);
- OS.PtRealizeWidget (topHandle);
- } else {
- OS.PtUnrealizeWidget (topHandle);
- sendEvent(SWT.Hide);
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Scrollable.java
deleted file mode 100755
index 22cc818e63..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Scrollable.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * This class is the abstract superclass of all classes which
- * represent controls that have standard scroll bars.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>H_SCROLL, V_SCROLL</dd>
- * <dt><b>Events:</b>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public abstract class Scrollable extends Control {
- int scrolledHandle;
- ScrollBar horizontalBar, verticalBar;
-
-Scrollable () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#H_SCROLL
- * @see SWT#V_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Scrollable (Composite parent, int style) {
- super (parent, style);
-}
-
-void createStandardScrollBars () {
- /* Search the handle to find the scroll bars */
- int child = OS.PtWidgetChildFront (handle);
- while (child != 0) {
- if (OS.PtWidgetClass (child) == OS.PtScrollbar ()) {
- int [] args = {OS.Pt_ARG_ORIENTATION, 0, 0};
- OS.PtGetResources (child, args.length / 3, args);
- switch (args [1]) {
- case OS.Pt_HORIZONTAL:
- if ((style & SWT.H_SCROLL) != 0) {
- horizontalBar = new ScrollBar (this, SWT.HORIZONTAL, child);
- }
- break;
- case OS.Pt_VERTICAL:
- if ((style & SWT.V_SCROLL) != 0) {
- verticalBar = new ScrollBar (this, SWT.VERTICAL, child);
- }
- break;
- }
- }
- child = OS.PtWidgetBrotherBehind (child);
- }
-}
-
-void deregister () {
- super.deregister ();
- if (scrolledHandle != 0) WidgetTable.remove (scrolledHandle);
-}
-
-/**
- * Given a desired <em>client area</em> for the receiver
- * (as described by the arguments), returns the bounding
- * rectangle which would be required to produce that client
- * area.
- * <p>
- * In other words, it returns a rectangle such that, if the
- * receiver's bounds were set to that rectangle, the area
- * of the receiver which is capable of displaying data
- * (that is, not covered by the "trimmings") would be the
- * rectangle described by the arguments (relative to the
- * receiver's parent).
- * </p>
- *
- * @param x the desired x coordinate of the client area
- * @param y the desired y coordinate of the client area
- * @param width the desired width of the client area
- * @param height the desired height of the client area
- * @return the required bounds to produce the given client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getClientArea
- */
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- PhRect_t rect = new PhRect_t ();
- PhArea_t area = new PhArea_t ();
- rect.ul_x = (short) x;
- rect.ul_y = (short) y;
- rect.lr_x = (short) (x + width - 1);
- rect.lr_y = (short) (y + height - 1);
- OS.PtSetAreaFromWidgetCanvas (scrolledHandle != 0 ? scrolledHandle : handle, rect, area);
- if (horizontalBar != null) {
- Point size = horizontalBar.getSize ();
- area.size_h += size.y;
- }
- if (verticalBar != null) {
- Point size = verticalBar.getSize ();
- area.size_w += size.x;
- }
- return new Rectangle (area.pos_x, area.pos_y, area.size_w, area.size_h);
-}
-
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data (that is,
- * not covered by the "trimmings").
- *
- * @return the client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeTrim
- */
-public Rectangle getClientArea () {
- checkWidget();
- PhRect_t rect = new PhRect_t ();
- int validParent = OS.PtValidParent (handle, OS.PtContainer ());
- if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidgetFamily (handle);
- OS.PtCalcCanvas (validParent, rect);
- int width = rect.lr_x - rect.ul_x + 1;
- int height = rect.lr_y - rect.ul_y + 1;
- return new Rectangle (0, 0, width, height);
-}
-
-/**
- * Returns the receiver's horizontal scroll bar if it has
- * one, and null if it does not.
- *
- * @return the horizontal scroll bar (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ScrollBar getHorizontalBar () {
- checkWidget();
- return horizontalBar;
-}
-
-/**
- * Returns the receiver's vertical scroll bar if it has
- * one, and null if it does not.
- *
- * @return the vertical scroll bar (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ScrollBar getVerticalBar () {
- checkWidget();
- return verticalBar;
-}
-
-boolean isTabGroup () {
- if ((state & CANVAS) != 0) return true;
- return super.isTabGroup ();
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- scrolledHandle = 0;
-}
-
-void resizeClientArea () {
- /* Do nothing */
-}
-
-void releaseChildren (boolean destroy) {
- if (horizontalBar != null) {
- horizontalBar.release (false);
- horizontalBar = null;
- }
- if (verticalBar != null) {
- verticalBar.release (false);
- verticalBar = null;
- }
- super.releaseChildren (destroy);
-}
-
-void register () {
- super.register ();
- if (scrolledHandle != 0) WidgetTable.put (scrolledHandle, this);
-}
-
-int topHandle () {
- if (scrolledHandle == 0) return handle;
- return scrolledHandle;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Shell.java
deleted file mode 100755
index e66164f526..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Shell.java
+++ /dev/null
@@ -1,1426 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent the "windows"
- * which the desktop or "window manager" is managing.
- * Instances that do not have a parent (that is, they
- * are built using the constructor, which takes a
- * <code>Display</code> as the argument) are described
- * as <em>top level</em> shells. Instances that do have
- * a parent are described as <em>secondary</em> or
- * <em>dialog</em> shells.
- * <p>
- * Instances are always displayed in one of the maximized,
- * minimized or normal states:
- * <ul>
- * <li>
- * When an instance is marked as <em>maximized</em>, the
- * window manager will typically resize it to fill the
- * entire visible area of the display, and the instance
- * is usually put in a state where it can not be resized
- * (even if it has style <code>RESIZE</code>) until it is
- * no longer maximized.
- * </li><li>
- * When an instance is in the <em>normal</em> state (neither
- * maximized or minimized), its appearance is controlled by
- * the style constants which were specified when it was created
- * and the restrictions of the window manager (see below).
- * </li><li>
- * When an instance has been marked as <em>minimized</em>,
- * its contents (client area) will usually not be visible,
- * and depending on the window manager, it may be
- * "iconified" (that is, replaced on the desktop by a small
- * simplified representation of itself), relocated to a
- * distinguished area of the screen, or hidden. Combinations
- * of these changes are also possible.
- * </li>
- * </ul>
- * </p><p>
- * The <em>modality</em> of an instance may be specified using
- * style bits. The modality style bits are used to determine
- * whether input is blocked for other shells on the display.
- * The <code>PRIMARY_MODAL</code> style allows an instance to block
- * input to its parent. The <code>APPLICATION_MODAL</code> style
- * allows an instance to block input to every other shell in the
- * display. The <code>SYSTEM_MODAL</code> style allows an instance
- * to block input to all shells, including shells belonging to
- * different applications.
- * </p><p>
- * Note: The styles supported by this class are treated
- * as <em>HINT</em>s, since the window manager for the
- * desktop on which the instance is visible has ultimate
- * control over the appearance and behavior of decorations
- * and modality. For example, some window managers only
- * support resizable windows and will always assume the
- * RESIZE style, even if it is not set. In addition, if a
- * modality style is not supported, it is "upgraded" to a
- * more restrictive modality style that is supported. For
- * example, if <code>PRIMARY_MODAL</code> is not supported,
- * it would be upgraded to <code>APPLICATION_MODAL</code>.
- * A modality style may also be "downgraded" to a less
- * restrictive style. For example, most operating systems
- * no longer support <code>SYSTEM_MODAL</code> because
- * it can freeze up the desktop, so this is typically
- * downgraded to <code>APPLICATION_MODAL</code>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL, SHEET</dd>
- * <dd>APPLICATION_MODAL, MODELESS, PRIMARY_MODAL, SYSTEM_MODAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Activate, Close, Deactivate, Deiconify, Iconify</dd>
- * </dl>
- * Class <code>SWT</code> provides two "convenience constants"
- * for the most commonly required style combinations:
- * <dl>
- * <dt><code>SHELL_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application top level shell: (that
- * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>)
- * </dd>
- * <dt><code>DIALOG_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application dialog shell: (that
- * is, <code>TITLE | CLOSE | BORDER</code>)
- * </dd>
- * </dl>
- * </p>
- * <p>
- * Note: Only one of the styles APPLICATION_MODAL, MODELESS,
- * PRIMARY_MODAL and SYSTEM_MODAL may be specified.
- * </p><p>
- * IMPORTANT: This class is not intended to be subclassed.
- * </p>
- *
- * @see Decorations
- * @see SWT
- * @see <a href="http://www.eclipse.org/swt/snippets/#shell">Shell snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class Shell extends Decorations {
- int shellHandle;
- Menu activeMenu;
- int blockedList;
- Control lastActive;
- boolean modified;
-
-/**
- * Constructs a new instance of this class. This is equivalent
- * to calling <code>Shell((Display) null)</code>.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell () {
- this ((Display) null);
-}
-
-/**
- * Constructs a new instance of this class given only the style
- * value describing its behavior and appearance. This is equivalent
- * to calling <code>Shell((Display) null, style)</code>.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#TOOL
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (int style) {
- this ((Display) null, style);
-}
-
-/**
- * Constructs a new instance of this class given only the display
- * to create it on. It is created with style <code>SWT.SHELL_TRIM</code>.
- * <p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the shell on
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell (Display display) {
- this (display, SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX | SWT.RESIZE);
-}
-
-/**
- * Constructs a new instance of this class given the display
- * to create it on and a style value describing its behavior
- * and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the shell on
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#TOOL
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (Display display, int style) {
- this (display, null, style, 0);
-}
-
-Shell (Display display, Shell parent, int style, int handle) {
- super ();
- if (display == null) display = Display.getCurrent ();
- if (display == null) display = Display.getDefault ();
- if (!display.isValidThread ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- if (parent != null && parent.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.style = checkStyle (style);
- this.parent = parent;
- this.display = display;
- this.handle = handle;
- createWidget (0);
-}
-
-/**
- * Constructs a new instance of this class given only its
- * parent. It is created with style <code>SWT.DIALOG_TRIM</code>.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the parent is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell (Shell parent) {
- this (parent, SWT.DIALOG_TRIM);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the parent is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#TOOL
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (Shell parent, int style) {
- this (parent != null ? parent.display : null, parent, style, 0);
-}
-
-public static Shell photon_new (Display display, int handle) {
- return new Shell (display, null, SWT.NO_TRIM, handle);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when operations are performed on the receiver,
- * by sending the listener one of the messages defined in the
- * <code>ShellListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ShellListener
- * @see #removeShellListener
- */
-public void addShellListener (ShellListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Close,typedListener);
- addListener (SWT.Iconify,typedListener);
- addListener (SWT.Deiconify,typedListener);
- addListener (SWT.Activate, typedListener);
- addListener (SWT.Deactivate, typedListener);
-}
-
-void bringToTop (boolean force) {
- if (!force) {
- if (display.getActiveShell () == null) return;
- }
- OS.PtWindowToFront (shellHandle);
-}
-
-static int checkStyle (int style) {
- style = Decorations.checkStyle (style);
- style &= ~SWT.TRANSPARENT;
- int mask = SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.PRIMARY_MODAL;
- int bits = style & ~mask;
- if ((style & SWT.SYSTEM_MODAL) != 0) return bits | SWT.SYSTEM_MODAL;
- if ((style & SWT.APPLICATION_MODAL) != 0) return bits | SWT.APPLICATION_MODAL;
- if ((style & SWT.PRIMARY_MODAL) != 0) return bits | SWT.PRIMARY_MODAL;
- return bits;
-}
-
-void closeWidget () {
- Event event = new Event ();
- event.time = (int) System.currentTimeMillis ();
- sendEvent (SWT.Close, event);
- if (event.doit && !isDisposed ()) dispose ();
-}
-
-/**
- * Requests that the window manager close the receiver in
- * the same way it would be closed when the user clicks on
- * the "close box" or performs some other platform specific
- * key or mouse combination that indicates the window
- * should be removed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#Close
- * @see #dispose
- */
-public void close () {
- checkWidget();
- closeWidget ();
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- int [] args = {OS.Pt_ARG_WINDOW_RENDER_FLAGS, 0, 0};
- OS.PtGetResources (shellHandle, args.length / 3, args);
- int flags = args [1];
- int [] left = new int [1], top = new int [1];
- int [] right = new int [1], bottom = new int [1];
- OS.PtFrameSize (flags, 0, left, top, right, bottom);
- int trimX = x - left [0];
- int trimY = y - top [0];
- int trimWidth = width + left [0] + right [0];
- int trimHeight = height + top [0] + bottom [0];
- if (menuBar != null) {
- PhDim_t dim = new PhDim_t ();
- int menuHandle = menuBar.handle;
- if (!OS.PtWidgetIsRealized (menuHandle)) {
- OS.PtExtentWidgetFamily (menuHandle);
- }
- OS.PtWidgetPreferredSize (menuHandle, dim);
- trimHeight += dim.h;
- trimY -= dim.h;
- }
- return new Rectangle (trimX, trimY, trimWidth, trimHeight);
-}
-
-void createHandle (int index) {
- state |= HANDLE | GRAB | CANVAS;
- if (handle != 0) {
- int clazz = display.PtContainer;
- int [] args = {
- OS.Pt_ARG_FILL_COLOR, OS.Pg_TRANSPARENT, 0,
- OS.Pt_ARG_CONTAINER_FLAGS, OS.Pt_HOTKEYS_FIRST, OS.Pt_HOTKEYS_FIRST,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- shellHandle = OS.PtCreateWidget (clazz, handle, args.length / 3, args);
- if (shellHandle == 0) error (SWT.ERROR_NO_HANDLES);
- } else {
- int parentHandle = 0;
- if (parent != null) parentHandle = parent.topHandle ();
- Monitor monitor = getMonitor ();
- Rectangle rect = monitor.getClientArea ();
- int width = rect.width * 5 / 8;
- int height = rect.height * 5 / 8;
- int decorations = 0;
- int flags =
- OS.Ph_WM_RENDER_MIN | OS.Ph_WM_RENDER_MAX | OS.Ph_WM_RENDER_RESIZE |
- OS.Ph_WM_RENDER_BORDER | OS.Ph_WM_RENDER_MENU | OS.Ph_WM_RENDER_MIN |
- OS.Ph_WM_RENDER_TITLE;
- if ((style & SWT.NO_TRIM) == 0) {
- if ((style & SWT.MIN) != 0) decorations |= OS.Ph_WM_RENDER_MIN;
- if ((style & SWT.MAX) != 0) decorations |= OS.Ph_WM_RENDER_MAX;
- if ((style & SWT.RESIZE) != 0) {
- decorations |= OS.Ph_WM_RENDER_BORDER | OS.Ph_WM_RENDER_RESIZE;
- }
- if ((style & SWT.BORDER) != 0) decorations |= OS.Ph_WM_RENDER_BORDER;
- if ((style & SWT.MENU) != 0) decorations |= OS.Ph_WM_RENDER_MENU;
- if ((style & SWT.TITLE) != 0) decorations |= OS.Ph_WM_RENDER_TITLE;
- }
- int notifyFlags =
- OS.Ph_WM_ICON | OS.Ph_WM_FOCUS |
- OS.Ph_WM_MOVE | OS.Ph_WM_RESIZE;
- int windowState = OS.Ph_WM_STATE_ISFOCUS;
- if ((style & SWT.ON_TOP) != 0) windowState = OS.Ph_WM_STATE_ISFRONT;
- int titlePtr = OS.malloc (1);
- OS.memset(titlePtr, 0, 1);
- int [] args = {
- OS.Pt_ARG_WIDTH, width, 0,
- OS.Pt_ARG_HEIGHT, height, 0,
- OS.Pt_ARG_WINDOW_TITLE, titlePtr, 0,
- OS.Pt_ARG_WINDOW_RENDER_FLAGS, decorations, flags,
- OS.Pt_ARG_WINDOW_MANAGED_FLAGS, 0, OS.Ph_WM_CLOSE,
- OS.Pt_ARG_WINDOW_NOTIFY_FLAGS, notifyFlags, notifyFlags,
- OS.Pt_ARG_WINDOW_STATE, windowState, ~0,
- OS.Pt_ARG_FLAGS, OS.Pt_DELAY_REALIZE, OS.Pt_DELAY_REALIZE,
- OS.Pt_ARG_FILL_COLOR, OS.Pg_TRANSPARENT, 0,
- OS.Pt_ARG_CONTAINER_FLAGS, OS.Pt_HOTKEYS_FIRST, OS.Pt_HOTKEYS_FIRST,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- OS.PtSetParentWidget (parentHandle);
- shellHandle = OS.PtCreateWidget (OS.PtWindow (), parentHandle, args.length / 3, args);
- OS.free (titlePtr);
- if (shellHandle == 0) error (SWT.ERROR_NO_HANDLES);
- }
- createScrolledHandle (shellHandle);
- if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.RESIZE)) == 0) {
- int [] args = {
- OS.Pt_ARG_FLAGS, OS.Pt_HIGHLIGHTED, OS.Pt_HIGHLIGHTED,
- OS.Pt_ARG_BASIC_FLAGS, OS.Pt_ALL_OUTLINES, ~0,
- };
- OS.PtSetResources (scrolledHandle, args.length / 3, args);
- }
- int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX;
- if ((style & SWT.NO_TRIM) != 0 || (style & trim) == 0) {
- OS.PtSetResource (shellHandle, OS.Pt_ARG_MIN_WIDTH, 0, 0);
- }
- OS.PtSetResource (shellHandle, OS.Pt_ARG_MIN_HEIGHT, 0, 0);
- int [] args = new int [] {OS.Pt_ARG_WIDTH, 0, 0, OS.Pt_ARG_HEIGHT, 0, 0};
- OS.PtGetResources (shellHandle, args.length / 3, args);
- resizeBounds (args [1], args [4]);
-}
-
-void deregister () {
- super.deregister ();
- WidgetTable.remove (shellHandle);
-}
-
-Composite findDeferredControl () {
- return layoutCount > 0 ? this : null;
-}
-
-/**
- * If the receiver is visible, moves it to the top of the
- * drawing order for the display on which it was created
- * (so that all other shells on that display, which are not
- * the receiver's children will be drawn behind it) and forces
- * the window manager to make the shell active.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#open
- * @see Shell#setActive
- */
-public void forceActive () {
- checkWidget ();
- bringToTop (true);
-}
-
-/**
- * Returns the receiver's alpha value. The alpha value
- * is between 0 (transparent) and 255 (opaque).
- *
- * @return the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public int getAlpha () {
- checkWidget ();
- return 255;
-}
-
-public Rectangle getBounds () {
- checkWidget();
- PhArea_t area = new PhArea_t ();
- OS.PtWidgetArea (shellHandle, area);
- int width = area.size_w, height = area.size_h;
- int [] args = {OS.Pt_ARG_WINDOW_RENDER_FLAGS, 0, 0};
- OS.PtGetResources (shellHandle, args.length / 3, args);
- int flags = args [1];
- int [] left = new int [1], top = new int [1];
- int [] right = new int [1], bottom = new int [1];
- OS.PtFrameSize (flags, 0, left, top, right, bottom);
- width += left [0] + right [0];
- height += top [0] + bottom [0];
- return new Rectangle (area.pos_x, area.pos_y, width, height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is currently
- * in fullscreen state, and false otherwise.
- * <p>
- *
- * @return the fullscreen state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getFullScreen () {
- checkWidget();
- return false;
-}
-
-/**
- * Returns the receiver's input method editor mode. This
- * will be the result of bitwise OR'ing together one or
- * more of the following constants defined in class
- * <code>SWT</code>:
- * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>,
- * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>.
- *
- * @return the IME mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public int getImeInputMode () {
- checkWidget();
- return 0;
-}
-
-public boolean isEnabled () {
- checkWidget();
- return getEnabled ();
-}
-
-public Point getLocation () {
- checkWidget();
- //NOT DONE - shell location is 0,0 when queried before event loop
- return super.getLocation ();
-}
-
-public boolean getMaximized () {
- checkWidget();
- int state = OS.PtWindowGetState (shellHandle);
- if (state != -1) return (state & (OS.Ph_WM_STATE_ISMAX | OS.Ph_WM_STATE_ISMAXING)) != 0;
- int [] args = {OS.Pt_ARG_WINDOW_STATE, 0, OS.Ph_WM_STATE_ISMAX};
- OS.PtGetResources (shellHandle, args.length / 3, args);
- return (args [1] & OS.Ph_WM_STATE_ISMAX) != 0;
-}
-
-public boolean getMinimized () {
- checkWidget();
- int state = OS.PtWindowGetState (shellHandle);
- if (state != -1) return (state & OS.Ph_WM_STATE_ISICONIFIED) != 0;
- int [] args = {OS.Pt_ARG_WINDOW_STATE, 0, OS.Ph_WM_STATE_ISICONIFIED};
- OS.PtGetResources (shellHandle, args.length / 3, args);
- return (args [1] & OS.Ph_WM_STATE_ISICONIFIED) != 0;
-}
-
-/**
- * Returns a point describing the minimum receiver's size. The
- * x coordinate of the result is the minimum width of the receiver.
- * The y coordinate of the result is the minimum height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Point getMinimumSize () {
- checkWidget();
- int [] args = {OS.Pt_ARG_WINDOW_RENDER_FLAGS, 0, 0};
- OS.PtGetResources (shellHandle, args.length / 3, args);
- int flags = args [1];
- int [] left = new int [1], top = new int [1];
- int [] right = new int [1], bottom = new int [1];
- OS.PtFrameSize (flags, 0, left, top, right, bottom);
- args = new int [] {
- OS.Pt_ARG_MIN_WIDTH, 0, 0,
- OS.Pt_ARG_MIN_HEIGHT, 0, 0,
- };
- OS.PtGetResources (shellHandle, args.length / 3, args);
- return new Point (args [1] + left [0] + right [0], args [4] + top [0] + bottom [0]);
-}
-
-/**
- * Gets the receiver's modified state.
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.5
- */
-public boolean getModified () {
- checkWidget ();
- return modified;
-}
-
-/**
- * Returns the region that defines the shape of the shell,
- * or null if the shell has the default shape.
- *
- * @return the region that defines the shape of the shell (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public Region getRegion () {
- /* This method is needed for the @since 3.0 Javadoc */
- checkWidget ();
- return region;
-}
-
-public Shell getShell () {
- checkWidget();
- return this;
-}
-
-/**
- * Returns an array containing all shells which are
- * descendants of the receiver.
- * <p>
- * @return the dialog shells
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Shell [] getShells () {
- checkWidget();
- int count = 0;
- Shell [] shells = display.getShells ();
- for (int i=0; i<shells.length; i++) {
- Control shell = shells [i];
- do {
- shell = shell.parent;
- } while (shell != null && shell != this);
- if (shell == this) count++;
- }
- int index = 0;
- Shell [] result = new Shell [count];
- for (int i=0; i<shells.length; i++) {
- Control shell = shells [i];
- do {
- shell = shell.parent;
- } while (shell != null && shell != this);
- if (shell == this) {
- result [index++] = shells [i];
- }
- }
- return result;
-}
-
-public Point getSize () {
- checkWidget();
- int [] args = {
- OS.Pt_ARG_WINDOW_RENDER_FLAGS, 0, 0,
- OS.Pt_ARG_WIDTH, 0, 0,
- OS.Pt_ARG_HEIGHT, 0, 0,
- };
- OS.PtGetResources (shellHandle, args.length / 3, args);
- int flags = args [1];
- int [] left = new int [1], top = new int [1];
- int [] right = new int [1], bottom = new int [1];
- OS.PtFrameSize (flags, 0, left, top, right, bottom);
- int width = args [4] + left [0] + right [0];
- int height = args [7] + top [0] + bottom [0];
- return new Point (width, height);
-}
-
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- OS.PtAddCallback (shellHandle, OS.Pt_CB_WINDOW, windowProc, OS.Pt_CB_WINDOW);
- OS.PtAddCallback (shellHandle, OS.Pt_CB_RESIZE, windowProc, OS.Pt_CB_RESIZE);
-}
-
-int hotkeyProc (int w, int data, int info) {
- if (data != 0) {
- Widget widget = WidgetTable.get (data);
- if (widget instanceof MenuItem) {
- MenuItem item = (MenuItem) widget;
- if (item.isEnabled ()) item.Pt_CB_ACTIVATE (data, info);
- }
- }
- return OS.Pt_CONTINUE;
-}
-
-/**
- * Moves the receiver to the top of the drawing order for
- * the display on which it was created (so that all other
- * shells on that display, which are not the receiver's
- * children will be drawn behind it), marks it visible,
- * sets the focus and asks the window manager to make the
- * shell active.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#setActive
- * @see Shell#forceActive
- */
-public void open () {
- checkWidget();
- setVisible (true);
- if (isDisposed ()) return;
- traverseGroup (true);
-}
-
-public boolean print (GC gc) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- return false;
-}
-
-int Pt_CB_RESIZE (int widget, int info) {
- if (info == 0) return OS.Pt_CONTINUE;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.cbdata == 0) return OS.Pt_CONTINUE;
- int [] args = {OS.Pt_ARG_WIDTH, 0, 0, OS.Pt_ARG_HEIGHT, 0, 0};
- OS.PtGetResources (shellHandle, args.length / 3, args);
- resizeBounds (args [1], args [4]);
- sendEvent(SWT.Resize);
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_WINDOW (int widget, int info) {
- if (info == 0) return OS.Pt_CONTINUE;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.cbdata == 0) return OS.Pt_CONTINUE;
- PhWindowEvent_t we = new PhWindowEvent_t ();
- OS.memmove (we, cbinfo.cbdata, PhWindowEvent_t.sizeof);
- switch (we.event_f) {
- case OS.Ph_WM_CLOSE:
- closeWidget ();
- break;
- case OS.Ph_WM_ICON:
- if ((we.state_f & OS.Ph_WM_STATE_ISICONIFIED) != 0) {
- sendEvent (SWT.Iconify);
- } else {
- sendEvent (SWT.Deiconify);
- }
- break;
- case OS.Ph_WM_FOCUS:
- switch ((int) we.event_state) {
- case OS.Ph_WM_EVSTATE_FOCUS: sendEvent (SWT.Activate); break;
- case OS.Ph_WM_EVSTATE_FOCUSLOST: sendEvent (SWT.Deactivate); break;
- }
- break;
- case OS.Ph_WM_MOVE:
- sendEvent (SWT.Move);
- break;
- }
- return OS.Pt_CONTINUE;
-}
-
-void register () {
- super.register ();
- WidgetTable.put (shellHandle, this);
-}
-
-void realizeWidget() {
- /* Do nothing */
-}
-
-void releaseParent () {
- /* Do nothing */
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- shellHandle = 0;
-}
-
-void releaseChildren (boolean destroy) {
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (shell != null && !shell.isDisposed ()) {
- /*
- * Feature in Photon. A shell may have child shells that have been
- * temporarily reparented to NULL because they were shown without
- * showing the parent. In this case, Photon will not destroy the
- * child shells because they are not in the widget hierarchy.
- * The fix is to detect this case and destroy the shells.
- */
- if (shell.parent != null && OS.PtWidgetParent (shell.shellHandle) == 0) {
- shell.dispose ();
- } else {
- shell.release (false);
- }
- }
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (blockedList != 0) OS.PtUnblockWindows (blockedList);
- blockedList = 0;
- lastActive = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when operations are performed on the receiver.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ShellListener
- * @see #addShellListener
- */
-public void removeShellListener (ShellListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Close, listener);
- eventTable.unhook (SWT.Iconify,listener);
- eventTable.unhook (SWT.Deiconify,listener);
- eventTable.unhook (SWT.Activate, listener);
- eventTable.unhook (SWT.Deactivate, listener);
-}
-
-/**
- * If the receiver is visible, moves it to the top of the
- * drawing order for the display on which it was created
- * (so that all other shells on that display, which are not
- * the receiver's children will be drawn behind it) and asks
- * the window manager to make the shell active
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#open
- * @see Shell#setActive
- */
-public void setActive () {
- checkWidget ();
- bringToTop (false);
-}
-
-void setActiveControl (Control control) {
- if (control != null && control.isDisposed ()) control = null;
- if (lastActive != null && lastActive.isDisposed ()) lastActive = null;
- if (lastActive == control) return;
-
- /*
- * Compute the list of controls to be activated and
- * deactivated by finding the first common parent
- * control.
- */
- Control [] activate = (control == null) ? new Control[0] : control.getPath ();
- Control [] deactivate = (lastActive == null) ? new Control[0] : lastActive.getPath ();
- lastActive = control;
- int index = 0, length = Math.min (activate.length, deactivate.length);
- while (index < length) {
- if (activate [index] != deactivate [index]) break;
- index++;
- }
-
- /*
- * It is possible (but unlikely), that application
- * code could have destroyed some of the widgets. If
- * this happens, keep processing those widgets that
- * are not disposed.
- */
- for (int i=deactivate.length-1; i>=index; --i) {
- if (!deactivate [i].isDisposed ()) {
- deactivate [i].sendEvent (SWT.Deactivate);
- }
- }
- for (int i=activate.length-1; i>=index; --i) {
- if (!activate [i].isDisposed ()) {
- activate [i].sendEvent (SWT.Activate);
- }
- }
-}
-
-/**
- * Sets the receiver's alpha value which must be
- * between 0 (transparent) and 255 (opaque).
- * <p>
- * This operation requires the operating system's advanced
- * widgets subsystem which may not be available on some
- * platforms.
- * </p>
- * @param alpha the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setAlpha (int alpha) {
- checkWidget ();
- /*Not implemented */
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- checkWidget();
- if (OS.PtWidgetClass (shellHandle) != OS.PtWindow ()) {
- int result = super.setBounds (x, y, width, height, move, resize, events);
- if ((result & RESIZED) != 0) resizeBounds (width, height);
- return result;
- }
-
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
-
- if (resize) {
- /* Get the trimings */
- int [] args = {OS.Pt_ARG_WINDOW_RENDER_FLAGS, 0, 0};
- OS.PtGetResources (shellHandle, args.length / 3, args);
- int flags = args [1];
- int [] left = new int [1], top = new int [1];
- int [] right = new int [1], bottom = new int [1];
- OS.PtFrameSize (flags, 0, left, top, right, bottom);
- width = Math.max (width - left [0] - right [0], 0);
- height = Math.max (height - top [0] - bottom [0], 0);
- }
-
- PhArea_t oldArea = new PhArea_t ();
- OS.PtWidgetArea (shellHandle, oldArea);
-
- if (move && resize) {
- PhArea_t area = new PhArea_t ();
- area.pos_x = (short) x;
- area.pos_y = (short) y;
- area.size_w = (short) width;
- area.size_h = (short) height;
- int ptr = OS.malloc (PhArea_t.sizeof);
- OS.memmove (ptr, area, PhArea_t.sizeof);
- OS.PtSetResource (shellHandle, OS.Pt_ARG_AREA, ptr, 0);
- OS.free (ptr);
- } else {
- if (move) {
- PhPoint_t pt = new PhPoint_t ();
- pt.x = (short) x;
- pt.y = (short) y;
- int ptr = OS.malloc (PhPoint_t.sizeof);
- OS.memmove (ptr, pt, PhPoint_t.sizeof);
- OS.PtSetResource (shellHandle, OS.Pt_ARG_POS, ptr, 0);
- OS.free (ptr);
- } else if (resize) {
- int [] args = {
- OS.Pt_ARG_WIDTH, width, 0,
- OS.Pt_ARG_HEIGHT, height, 0,
- };
- OS.PtSetResources (shellHandle, args.length / 3, args);
- }
- }
-
- /*
- * Feature in Photon. The shell does not issue WM_SIZE
- * event notificatoin until it is realized. The fix is
- * to detect size changes and send the events.
- */
- if (!OS.PtWidgetIsRealized (shellHandle)) {
- PhArea_t newArea = new PhArea_t ();
- OS.PtWidgetArea (shellHandle, newArea);
- boolean sameOrigin = oldArea.pos_x == newArea.pos_x && oldArea.pos_y == newArea.pos_y;
- boolean sameExtent = oldArea.size_w == newArea.size_w && oldArea.size_h == newArea.size_h;
- if (!sameOrigin & move) sendEvent (SWT.Move);
- if (!sameExtent & resize) {
- resizeBounds (newArea.size_w, newArea.size_h);
- sendEvent(SWT.Resize);
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false);
- }
- }
- }
-
- if (isFocus) caret.setFocus ();
-
- /* Always return 0 */
- return 0;
-}
-
-/**
- * Sets the full screen state of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the full screen state, and if the argument is
- * <code>false</code> and the receiver was previously switched
- * into full screen state, causes the receiver to switch back
- * to either the maximized or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setFullScreen(true)</code>,
- * <code>setMaximized(true)</code> and <code>setMinimized(true)</code> will
- * vary by platform. Typically, the behavior will match the platform user's
- * expectations, but not always. This should be avoided if possible.
- * </p>
- *
- * @param fullScreen the new fullscreen state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setFullScreen (boolean fullScreen) {
- checkWidget();
-}
-
-/**
- * Sets the input method editor mode to the argument which
- * should be the result of bitwise OR'ing together one or more
- * of the following constants defined in class <code>SWT</code>:
- * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>,
- * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>.
- *
- * @param mode the new IME mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public void setImeInputMode (int mode) {
- checkWidget();
-}
-
-public void setMaximized (boolean maximized) {
- checkWidget();
- int bits = 0;
- if (maximized) bits = OS.Ph_WM_STATE_ISMAX;
- OS.PtSetResource (shellHandle, OS.Pt_ARG_WINDOW_STATE, bits, OS.Ph_WM_STATE_ISMAX);
- if (OS.PtWidgetIsRealized (shellHandle)) {
- PhWindowEvent_t event = new PhWindowEvent_t ();
- event.rid = OS.PtWidgetRid (shellHandle);
- event.event_f = maximized ? OS.Ph_WM_MAX : OS.Ph_WM_RESTORE;
- OS.PtForwardWindowEvent (event);
- }
-}
-
-public void setMenuBar (Menu menu) {
- checkWidget();
- if (menuBar == menu) return;
- if (menu != null) {
- if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR);
- if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
- if (menuBar != null) {
- int menuHandle = menuBar.handle;
- OS.PtSetResource (menuHandle, OS.Pt_ARG_FLAGS, OS.Pt_DELAY_REALIZE, OS.Pt_DELAY_REALIZE);
- OS.PtUnrealizeWidget (menuBar.handle);
- }
- menuBar = menu;
- int [] args = {OS.Pt_ARG_WIDTH, 0, 0, OS.Pt_ARG_HEIGHT, 0, 0};
- OS.PtGetResources (shellHandle, args.length / 3, args);
- int width = args [1], height = args [4];
- if (menuBar != null) {
- int menuHandle = menu.handle;
- args = new int [] {
- OS.Pt_ARG_WIDTH, width, 0,
- OS.Pt_ARG_FLAGS, 0, OS.Pt_DELAY_REALIZE,
- };
- OS.PtSetResources (menuHandle, args.length / 3, args);
- OS.PtRealizeWidget (menuHandle);
- }
- resizeBounds (width, height);
-}
-
-public void setMinimized (boolean minimized) {
- checkWidget();
- int bits = 0;
- if (minimized) bits = OS.Ph_WM_STATE_ISICONIFIED;
- OS.PtSetResource (shellHandle, OS.Pt_ARG_WINDOW_STATE, bits, OS.Ph_WM_STATE_ISICONIFIED);
- if (OS.PtWidgetIsRealized (shellHandle)) {
- PhWindowEvent_t event = new PhWindowEvent_t ();
- event.rid = OS.PtWidgetRid (shellHandle);
- event.event_f = OS.Ph_WM_HIDE;
- event.event_state = (short) (minimized ? OS.Ph_WM_EVSTATE_HIDE : OS.Ph_WM_EVSTATE_UNHIDE);
- OS.PtForwardWindowEvent (event);
- }
-}
-
-/**
- * Sets the receiver's modified state as specified by the argument.
- *
- * @param modified the new modified state for the receiver
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.5
- */
-public void setModified (boolean modified) {
- checkWidget ();
- this.modified = modified;
-}
-
-/**
- * Sets the shape of the shell to the region specified
- * by the argument. When the argument is null, the
- * default shape of the shell is restored. The shell
- * must be created with the style SWT.NO_TRIM in order
- * to specify a region.
- *
- * @param region the region that defines the shape of the shell (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public void setRegion (Region region) {
- checkWidget ();
- if ((style & SWT.NO_TRIM) == 0) return;
- super.setRegion (region);
-}
-
-/**
- * Sets the receiver's minimum size to the size specified by the arguments.
- * If the new minimum size is larger than the current size of the receiver,
- * the receiver is resized to the new minimum size.
- *
- * @param width the new minimum width for the receiver
- * @param height the new minimum height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setMinimumSize (int width, int height) {
- checkWidget();
- int [] args = {OS.Pt_ARG_WINDOW_RENDER_FLAGS, 0, 0};
- OS.PtGetResources (shellHandle, args.length / 3, args);
- int flags = args [1];
- int [] left = new int [1], top = new int [1];
- int [] right = new int [1], bottom = new int [1];
- OS.PtFrameSize (flags, 0, left, top, right, bottom);
- width = Math.max (width - left [0] - right [0], 0);
- height = Math.max (height - top [0] - bottom [0], 0);
- args = new int [] {
- OS.Pt_ARG_MIN_WIDTH, width, 0,
- OS.Pt_ARG_MIN_HEIGHT, height, 0,
- };
- OS.PtSetResources (shellHandle, args.length / 3, args);
-}
-
-/**
- * Sets the receiver's minimum size to the size specified by the argument.
- * If the new minimum size is larger than the current size of the receiver,
- * the receiver is resized to the new minimum size.
- *
- * @param size the new minimum size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setMinimumSize (Point size) {
- checkWidget();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setMinimumSize (size.x, size.y);
-}
-
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- text = string;
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- int ptr = OS.malloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- OS.PtSetResource (shellHandle, OS.Pt_ARG_WINDOW_TITLE, ptr, 0);
- OS.free (ptr);
-}
-
-public void setVisible (boolean visible) {
- checkWidget();
- if (visible == OS.PtWidgetIsRealized (shellHandle)) return;
-
- /*
- * Feature in Photon. It is not possible to show a PtWindow
- * whose parent is not realized. The fix is to temporarily
- * reparent the child shell to NULL and then realize the child
- * shell.
- */
- if (parent != null) {
- Shell shell = parent.getShell ();
- int parentHandle = shell.shellHandle;
- if (!OS.PtWidgetIsRealized (parentHandle)) {
- OS.PtReParentWidget (shellHandle, visible ? OS.Pt_NO_PARENT : parentHandle);
- }
- }
-
- if (visible) {
- int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- switch (style & mask) {
- case SWT.PRIMARY_MODAL:
- if (parent != null) {
- int parentHandle = parent.getShell ().shellHandle;
- blockedList = OS.PtBlockWindow (parentHandle, (short) 0, 0);
- }
- break;
- case SWT.APPLICATION_MODAL:
- case SWT.SYSTEM_MODAL:
- blockedList = OS.PtBlockAllWindows (shellHandle, (short) 0, 0);
- break;
- }
- } else {
- if (blockedList != 0) OS.PtUnblockWindows (blockedList);
- blockedList = 0;
- }
-
- int flags = visible ? 0 : OS.Pt_DELAY_REALIZE;
- OS.PtSetResource (shellHandle, OS.Pt_ARG_FLAGS, flags, OS.Pt_DELAY_REALIZE);
- if (visible) {
- sendEvent (SWT.Show);
- if (isDisposed ()) return;
- OS.PtRealizeWidget (shellHandle);
- } else {
- OS.PtUnrealizeWidget (shellHandle);
- sendEvent(SWT.Hide);
- if (isDisposed ()) return;
- }
-
- /*
- * Feature in Photon. When a shell is shown, it may have child
- * shells that have been temporarily reparented to NULL because
- * the child was shown before the parent. The fix is to reparent
- * the child shells back to the correct parent.
- */
- if (visible) {
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- int childHandle = shells [i].shellHandle;
- if (OS.PtWidgetParent (childHandle) == 0) {
- OS.PtReParentWidget (childHandle, shellHandle);
- }
- }
- }
-
- OS.PtSyncWidget (shellHandle);
- OS.PtFlush ();
-}
-
-int topHandle () {
- return shellHandle;
-}
-
-boolean traverseEscape () {
- if (parent == null) return false;
- if (!isVisible () || !isEnabled ()) return false;
- close ();
- return true;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Slider.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Slider.java
deleted file mode 100755
index 8de4424e49..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Slider.java
+++ /dev/null
@@ -1,559 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that represent a range of positive, numeric values.
- * <p>
- * At any given moment, a given slider will have a
- * single 'selection' that is considered to be its
- * value, which is constrained to be within the range of
- * values the slider represents (that is, between its
- * <em>minimum</em> and <em>maximum</em> values).
- * </p><p>
- * Typically, sliders will be made up of five areas:
- * <ol>
- * <li>an arrow button for decrementing the value</li>
- * <li>a page decrement area for decrementing the value by a larger amount</li>
- * <li>a <em>thumb</em> for modifying the value by mouse dragging</li>
- * <li>a page increment area for incrementing the value by a larger amount</li>
- * <li>an arrow button for incrementing the value</li>
- * </ol>
- * Based on their style, sliders are either <code>HORIZONTAL</code>
- * (which have a left facing button for decrementing the value and a
- * right facing button for incrementing it) or <code>VERTICAL</code>
- * (which have an upward facing button for decrementing the value
- * and a downward facing buttons for incrementing it).
- * </p><p>
- * On some platforms, the size of the slider's thumb can be
- * varied relative to the magnitude of the range of values it
- * represents (that is, relative to the difference between its
- * maximum and minimum values). Typically, this is used to
- * indicate some proportional value such as the ratio of the
- * visible area of a document to the total amount of space that
- * it would take to display it. SWT supports setting the thumb
- * size even if the underlying platform does not, but in this
- * case the appearance of the slider will not change.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see ScrollBar
- * @see <a href="http://www.eclipse.org/swt/snippets/#slider">Slider snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Slider extends Control {
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Slider (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values:
- * <code>SWT.NONE</code> - for the end of a drag.
- * <code>SWT.DRAG</code>.
- * <code>SWT.HOME</code>.
- * <code>SWT.END</code>.
- * <code>SWT.ARROW_DOWN</code>.
- * <code>SWT.ARROW_UP</code>.
- * <code>SWT.PAGE_DOWN</code>.
- * <code>SWT.PAGE_UP</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int border = getBorderWidth () * 2;
- int width = display.SCROLLBAR_WIDTH + border, height = width * 5;
- if ((style & SWT.HORIZONTAL) != 0) {
- height = display.SCROLLBAR_HEIGHT + border; width = height * 5;
- }
- if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) {
- PhRect_t rect = new PhRect_t ();
- PhArea_t area = new PhArea_t ();
- rect.lr_x = (short) (wHint - 1);
- rect.lr_y = (short) (hHint - 1);
- OS.PtSetAreaFromWidgetCanvas (handle, rect, area);
- if (wHint != SWT.DEFAULT) width = area.size_w;
- if (hHint != SWT.DEFAULT) height = area.size_h;
- }
- return new Point (width, height);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- int clazz = display.PtScrollbar;
- int parentHandle = parent.parentingHandle ();
- int [] args = {
- OS.Pt_ARG_MAXIMUM, 99, 0,
- OS.Pt_ARG_PAGE_INCREMENT, 10, 0,
- OS.Pt_ARG_SLIDER_SIZE, 10, 0,
- OS.Pt_ARG_ORIENTATION, (style & SWT.HORIZONTAL) != 0 ? OS.Pt_HORIZONTAL : OS.Pt_VERTICAL, 0,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (clazz, parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-
-byte [] defaultFont () {
- return display.GAUGE_FONT;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget();
- int [] args = {OS.Pt_ARG_INCREMENT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget();
- int [] args = {OS.Pt_ARG_MINIMUM, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget();
- int [] args = {OS.Pt_ARG_MAXIMUM, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1] + 1;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget();
- int [] args = {OS.Pt_ARG_PAGE_INCREMENT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the 'selection', which is the receiver's value.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget();
- int [] args = {OS.Pt_ARG_GAUGE_VALUE, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-public Point getSize () {
- checkWidget();
- int [] args = {OS.Pt_ARG_WIDTH, 0, 0, OS.Pt_ARG_HEIGHT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return new Point (args [1], args [4]);
-}
-
-/**
- * Returns the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values.
- *
- * @return the thumb value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getThumb () {
- checkWidget();
- int [] args = {OS.Pt_ARG_SLIDER_SIZE, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- OS.PtAddCallback (handle, OS.Pt_CB_SCROLL_MOVE, windowProc, OS.Pt_CB_SCROLL_MOVE);
-}
-
-int Pt_CB_SCROLL_MOVE (int widget, int info) {
- if (info == 0) return OS.Pt_CONTINUE;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.cbdata == 0) return OS.Pt_CONTINUE;
- PtScrollbarCallback_t cb = new PtScrollbarCallback_t ();
- OS.memmove (cb, cbinfo.cbdata, PtScrollbarCallback_t.sizeof);
- Event event = new Event ();
- switch (cb.action) {
- case OS.Pt_SCROLL_DRAGGED:
- event.detail = SWT.DRAG;
- break;
- case OS.Pt_SCROLL_TO_MIN:
- event.detail = SWT.HOME;
- break;
- case OS.Pt_SCROLL_TO_MAX:
- event.detail = SWT.END;
- break;
- case OS.Pt_SCROLL_INCREMENT:
- event.detail = SWT.ARROW_DOWN;
- break;
- case OS.Pt_SCROLL_DECREMENT :
- event.detail = SWT.ARROW_UP;
- break;
- case OS.Pt_SCROLL_PAGE_DECREMENT:
- event.detail = SWT.PAGE_UP;
- break;
- case OS.Pt_SCROLL_PAGE_INCREMENT:
- event.detail = SWT.PAGE_DOWN;
- break;
- }
- sendEvent(SWT.Selection, event);
- return OS.Pt_CONTINUE;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget();
- OS.PtSetResource (handle, OS.Pt_ARG_INCREMENT, value, 0);
-}
-
-/**
- * Sets the maximum. If this value is negative or less than or
- * equal to the minimum, the value is ignored. If necessary, first
- * the thumb and then the selection are adjusted to fit within the
- * new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget();
- int [] args = {
- OS.Pt_ARG_MAXIMUM, 0, 0,
- OS.Pt_ARG_MINIMUM, 0, 0,
- OS.Pt_ARG_SLIDER_SIZE, 0, 0,
- OS.Pt_ARG_GAUGE_VALUE, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- int minimum = args [4];
- if (value <= minimum) return;
- int thumb = args [7];
- thumb = Math.min (thumb, value - minimum);
- int selection = args [10];
- selection = Math.min (selection, value - thumb);
- args [1] = value - 1;
- args [7] = thumb;
- args [10] = selection;
- OS.PtSetResources (handle, args.length / 3, args);
-}
-
-/**
- * Sets the minimum value. If this value is negative or greater
- * than or equal to the maximum, the value is ignored. If necessary,
- * first the thumb and then the selection are adjusted to fit within
- * the new range.
- *
- * @param value the new minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget();
- if (value < 0) return;
- int [] args = {
- OS.Pt_ARG_MAXIMUM, 0, 0,
- OS.Pt_ARG_MINIMUM, 0, 0,
- OS.Pt_ARG_SLIDER_SIZE, 0, 0,
- OS.Pt_ARG_GAUGE_VALUE, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- int maximum = args [1] + 1;
- if (value >= maximum) return;
- int thumb = args [7];
- thumb = Math.min (thumb, maximum - value);
- int selection = args [10];
- selection = Math.max (selection, value);
- args [4] = value;
- args [7] = thumb;
- args [10] = selection;
- OS.PtSetResources (handle, args.length / 3, args);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget();
- OS.PtSetResource (handle, OS.Pt_ARG_PAGE_INCREMENT, value, 0);
-}
-
-/**
- * Sets the 'selection', which is the receiver's
- * value, to the argument which must be greater than or equal
- * to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget();
- OS.PtSetResource (handle, OS.Pt_ARG_GAUGE_VALUE, value, 0);
-}
-
-/**
- * Sets the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values. This new
- * value will be ignored if it is less than one, and will be
- * clamped if it exceeds the receiver's current range.
- *
- * @param value the new thumb value, which must be at least one and not
- * larger than the size of the current range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setThumb (int value) {
- checkWidget();
- if (value < 1) return;
- int [] args = {OS.Pt_ARG_MINIMUM, 0, 0, OS.Pt_ARG_MAXIMUM, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- int minimum = args [1];
- int maximum = args [4] + 1;
- value = Math.min (value, maximum - minimum);
- OS.PtSetResource (handle, OS.Pt_ARG_SLIDER_SIZE, value, 0);
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, thumb, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param thumb the new thumb value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- checkWidget();
- if (minimum < 0) return;
- if (maximum < 0) return;
- if (thumb < 1) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- thumb = Math.min (thumb, maximum - minimum);
- int [] args = {
- OS.Pt_ARG_MAXIMUM, maximum - 1, 0,
- OS.Pt_ARG_MINIMUM, minimum, 0,
- OS.Pt_ARG_SLIDER_SIZE, thumb, 0,
- OS.Pt_ARG_GAUGE_VALUE, selection, 0,
- OS.Pt_ARG_INCREMENT, increment, 0,
- OS.Pt_ARG_PAGE_INCREMENT, pageIncrement, 0,
- };
- OS.PtSetResources (handle, args.length / 3, args);
-}
-
-int widgetClass () {
- return OS.PtScrollbar ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Spinner.java
deleted file mode 100644
index e8e5d1ad1a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Spinner.java
+++ /dev/null
@@ -1,824 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify numeric
- * values.
- * <p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, Modify, Verify</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#spinner">Spinner snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Spinner extends Composite {
- /**
- * the operating system limit for the number of characters
- * that the text field in an instance of this class can hold
- *
- * @since 3.4
- */
- public static final int LIMIT;
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0x7FFF;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#READ_ONLY
- * @see SWT#WRAP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Spinner (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- int parentHandle = parent.parentingHandle ();
- boolean hasBorder = (style & SWT.BORDER) != 0;
- int textFlags = (style & SWT.READ_ONLY) != 0 ? 0 : OS.Pt_EDITABLE;
- boolean wrap = (style & SWT.WRAP) != 0;
- int [] args = new int [] {
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- OS.Pt_ARG_NUMERIC_INCREMENT, 1, 0,
- OS.Pt_ARG_NUMERIC_MIN, 0, 0,
- OS.Pt_ARG_NUMERIC_MAX, 100, 0,
- OS.Pt_ARG_TEXT_FLAGS, textFlags, OS.Pt_EDITABLE,
- OS.Pt_ARG_FLAGS, hasBorder ? OS.Pt_HIGHLIGHTED : 0, OS.Pt_HIGHLIGHTED,
- OS.Pt_ARG_NUMERIC_FLAGS, wrap ? OS.Pt_NUMERIC_WRAP : 0, OS.Pt_NUMERIC_WRAP,
- };
- handle = OS.PtCreateWidget (display.PtNumericInteger, parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is not called for texts.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- */
-void addVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int [] args = new int [] {
- OS.Pt_ARG_TEXT_FONT, 0, 0,
- OS.Pt_ARG_NUMERIC_MAX, 0, 0,
- OS.Pt_ARG_NUMERIC_UPDOWN_WIDTH, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- int width = wHint;
- int height = hHint;
- if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
- int ptr = args [1];
- int length = OS.strlen (ptr);
- byte [] font = new byte [length + 1];
- OS.memmove (font, ptr, length);
- String string = String.valueOf (args [4]);
- PhRect_t rect = new PhRect_t ();
- int size = string.length ();
- char [] buffer = new char [size];
- string.getChars (0, size, buffer, 0);
- OS.PfExtentWideText (rect, null, font, buffer, size * 2);
- if (wHint == SWT.DEFAULT) width = rect.lr_x - rect.ul_x + 1;
- if (hHint == SWT.DEFAULT) height = rect.lr_y - rect.ul_y + 1;
- }
- Rectangle trim = computeTrim (0, 0, width, height);
- if (hHint == SWT.DEFAULT) {
- trim.height = Math.max (trim.height, args [7] * 2);
- }
- return new Point (trim.width, trim.height);
-}
-
-public Rectangle computeTrim(int x, int y, int width, int height) {
- int border = getBorderWidth ();
- x -= border;
- y -= border;
- width += 2 * border;
- height += 2 * border;
- int [] args = new int [] {
- OS.Pt_ARG_NUMERIC_SPACING, 0, 0, // 1
- OS.Pt_ARG_NUMERIC_UPDOWN_WIDTH, 0, 0, // 4
-// OS.Pt_ARG_NUMERIC_TEXT_BORDER, 0, 0, // 7
- };
- OS.PtGetResources (handle, args.length / 3, args);
-
- /*
- * Note: Pt_ARG_NUMERIC_TEXT_BORDER is defined in the
- * documentation (default value 2) but is not defined
- * in the include files on QNX 6.2.1.
- */
- int textBorder = 2;
- width += args [1] + args [4] + 2 * textBorder;
- height += 2 * textBorder;
- int textHandle = OS.PtWidgetChildBack (handle);
- args = new int [] {
- OS.Pt_ARG_MARGIN_WIDTH, 0, 0, // 1
- OS.Pt_ARG_MARGIN_LEFT, 0, 0, // 4
- OS.Pt_ARG_MARGIN_RIGHT, 0, 0, // 7
- OS.Pt_ARG_TEXT_CURSOR_WIDTH, 0, 0, // 10
- };
- OS.PtGetResources (textHandle, args.length / 3, args);
- width += args [1] + args [4] + args [7] + args [10];
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void copy () {
- checkWidget ();
- int textHandle = OS.PtWidgetChildBack (handle);
- if (textHandle != 0) {
- int [] start = new int [1], end = new int [1];
- int length = OS.PtTextGetSelection (textHandle, start, end);
- if (length <= 0) return;
- int [] args = {OS.Pt_ARG_TEXT_STRING, 0, 0};
- OS.PtGetResources (textHandle, args.length / 3, args);
- byte[] buffer = new byte[length + 1];
- OS.memmove (buffer, args [1] + start [0], length);
- int ig = OS.PhInputGroup (0);
- OS.PhClipboardCopyString((short)ig, buffer);
- }
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void cut () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- int textHandle = OS.PtWidgetChildBack (handle);
- if (textHandle != 0) {
- int [] start = new int [1], end = new int [1];
- int length = OS.PtTextGetSelection (textHandle, start, end);
- if (length <= 0) return;
- int [] args = {OS.Pt_ARG_TEXT_STRING, 0, 0};
- OS.PtGetResources (textHandle, args.length / 3, args);
- byte[] buffer = new byte[length + 1];
- OS.memmove (buffer, args [1] + start [0], length);
- int ig = OS.PhInputGroup (0);
- OS.PhClipboardCopyString((short)ig, buffer);
- buffer = new byte[0];
- OS.PtTextModifyText (textHandle, start [0], end [0], start [0], buffer, buffer.length);
- }
-}
-
-void deregister () {
- super.deregister ();
- int textHandle = OS.PtWidgetChildBack (handle);
- WidgetTable.remove (textHandle);
-}
-
-int defaultBackground () {
- return display.TEXT_BACKGROUND;
-}
-
-int defaultForeground () {
- return display.TEXT_FOREGROUND;
-}
-
-/**
- * Returns the number of decimal places used by the receiver.
- *
- * @return the digits
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getDigits () {
- checkWidget ();
- return 0;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down arrows are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget ();
- int [] args = {OS.Pt_ARG_NUMERIC_INCREMENT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget ();
- int [] args = {OS.Pt_ARG_NUMERIC_MAX, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget ();
- int [] args = {OS.Pt_ARG_NUMERIC_MIN, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the amount that the receiver's position will be
- * modified by when the page up/down keys are pressed.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget ();
- return 0;
-}
-
-/**
- * Returns the <em>selection</em>, which is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget ();
- int [] args = {OS.Pt_ARG_NUMERIC_VALUE, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns a string containing a copy of the contents of the
- * receiver's text field, or an empty string if there are no
- * contents.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public String getText () {
- checkWidget ();
- return "";
-}
-
-/**
- * Returns the maximum number of characters that the receiver's
- * text field is capable of holding. If this has not been changed
- * by <code>setTextLimit()</code>, it will be the constant
- * <code>Spinner.LIMIT</code>.
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- *
- * @since 3.4
- */
-public int getTextLimit () {
- checkWidget ();
- return LIMIT;
-}
-
-boolean hasFocus () {
- return OS.PtIsFocused (handle) != 0;
-}
-
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- OS.PtAddCallback (handle, OS.Pt_CB_NUMERIC_CHANGED, windowProc, OS.Pt_CB_NUMERIC_CHANGED);
-}
-
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void paste () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- int textHandle = OS.PtWidgetChildBack (handle);
- if (textHandle != 0) {
- int ig = OS.PhInputGroup (0);
- int ptr = OS.PhClipboardPasteString((short)ig);
- if (ptr == 0) return;
- int length = OS.strlen (ptr);
- int [] start = new int [1], end = new int [1];
- OS.PtTextGetSelection (textHandle, start, end);
- if (start [0] == -1) {
- int [] args = {OS.Pt_ARG_CURSOR_POSITION, 0, 0};
- OS.PtGetResources (textHandle, args.length / 3, args);
- start [0] = end [0] = args [1];
- }
- OS.PtTextModifyText (textHandle, start [0], end [0], end [0], ptr, length);
- OS.free(ptr);
- }
-}
-
-int Pt_CB_NUMERIC_CHANGED (int widget, int info) {
- if (info == 0) return OS.Pt_END;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.event == 0) return OS.Pt_END;
- switch (cbinfo.reason_subtype) {
- case OS.Pt_NUMERIC_CHANGED:
- sendEvent (SWT.Modify);
- break;
- case OS.Pt_NUMERIC_UPDOWN_ACTIVATE:
- case OS.Pt_NUMERIC_UPDOWN_REPEAT:
- sendEvent (SWT.Selection);
- break;
- }
- return OS.Pt_CONTINUE;
-}
-
-void register () {
- super.register ();
- int textHandle = OS.PtWidgetChildBack (handle);
- WidgetTable.put (textHandle, this);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- */
-void removeVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-
-/**
- * Sets the number of decimal places used by the receiver.
- * <p>
- * The digit setting is used to allow for floating point values in the receiver.
- * For example, to set the selection to a floating point value of 1.37 call setDigits() with
- * a value of 2 and setSelection() with a value of 137. Similarly, if getDigits() has a value
- * of 2 and getSelection() returns 137 this should be interpreted as 1.37. This applies to all
- * numeric APIs.
- * </p>
- *
- * @param value the new digits (must be greater than or equal to zero)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the value is less than zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDigits (int value) {
- checkWidget ();
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down arrows are pressed to
- * the argument, which must be at least one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- OS.PtSetResource (handle, OS.Pt_ARG_NUMERIC_INCREMENT, value, 0);
-}
-
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget ();
- if (value < 0) return;
- OS.PtSetResource (handle, OS.Pt_ARG_NUMERIC_MAX, value, 0);
-}
-
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget ();
- if (value < 0) return;
- OS.PtSetResource (handle, OS.Pt_ARG_NUMERIC_MIN, value, 0);
-}
-
-/**
- * Sets the amount that the receiver's position will be
- * modified by when the page up/down keys are pressed
- * to the argument, which must be at least one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
-}
-
-/**
- * Sets the <em>selection</em>, which is the receiver's
- * position, to the argument. If the argument is not within
- * the range specified by minimum and maximum, it will be
- * adjusted to fall within this range.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget ();
- OS.PtSetResource (handle, OS.Pt_ARG_NUMERIC_VALUE, value, 0);
-}
-
-/**
- * Sets the maximum number of characters that the receiver's
- * text field is capable of holding to be the argument.
- * <p>
- * To reset this value to the default, use <code>setTextLimit(Spinner.LIMIT)</code>.
- * Specifying a limit value larger than <code>Spinner.LIMIT</code> sets the
- * receiver's limit to <code>Spinner.LIMIT</code>.
- * </p>
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- *
- * @since 3.4
- */
-public void setTextLimit (int limit) {
- checkWidget ();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, digits, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param digits the new digits value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setValues (int selection, int minimum, int maximum, int digits, int increment, int pageIncrement) {
- checkWidget ();
- if (minimum < 0) return;
- if (maximum <= minimum) return;
- if (digits < 0) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- selection = Math.min (Math.max (minimum, selection), maximum);
- int [] args = new int [] {
- OS.Pt_ARG_NUMERIC_INCREMENT, increment, 0,
- OS.Pt_ARG_NUMERIC_MIN, minimum, 0,
- OS.Pt_ARG_NUMERIC_MAX, maximum, 0,
- OS.Pt_ARG_NUMERIC_VALUE, selection, 0
- };
- OS.PtSetResources (handle, args.length / 3, args);
-}
-
-boolean translateTraversal (int key_sym, PhKeyEvent_t phEvent) {
- boolean translated = super.translateTraversal (key_sym, phEvent);
- if (!translated && key_sym == OS.Pk_Return) {
- postEvent (SWT.DefaultSelection);
- return false;
- }
- return translated;
-}
-
-int widgetClass () {
- return OS.PtNumericInteger ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/TabFolder.java
deleted file mode 100755
index 35c64ff915..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/TabFolder.java
+++ /dev/null
@@ -1,756 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.widgets.TabItem;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class implement the notebook user interface
- * metaphor. It allows the user to select a notebook page from
- * set of pages.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TabItem</code>.
- * <code>Control</code> children are created and then set into a
- * tab item using <code>TabItem#setControl</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>TOP, BOTTOM</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles TOP and BOTTOM may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tabfolder">TabFolder, TabItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TabFolder extends Composite {
- int parentingHandle;
- TabItem [] items;
- int itemCount, currentIndex = OS.Pt_PG_INVALID;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see SWT#TOP
- * @see SWT#BOTTOM
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabFolder (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- style = checkBits (style, SWT.TOP, SWT.BOTTOM, 0, 0, 0, 0);
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- PhDim_t dim = new PhDim_t();
- if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidget (handle);
- OS.PtWidgetPreferredSize(handle, dim);
- int width = dim.w, height = dim.h;
- Point size;
- if (layout != null) {
- changed |= (state & LAYOUT_CHANGED) != 0;
- size = layout.computeSize (this, wHint, hHint, changed);
- state &= ~LAYOUT_CHANGED;
- } else {
- size = minimumSize (wHint, hHint, changed);
- }
- if (size.x == 0) size.x = DEFAULT_WIDTH;
- if (size.y == 0) size.y = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) size.x = wHint;
- if (hHint != SWT.DEFAULT) size.y = hHint;
- width = Math.max (width, size.x);
- height = Math.max (height, size.y);
- Rectangle trim = computeTrim (0, 0, width, height);
- width = trim.width; height = trim.height;
- return new Point (width, height);
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- PhDim_t dim = new PhDim_t();
- if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidget (handle);
- OS.PtWidgetPreferredSize(handle, dim);
- int [] args = {
- OS.Pt_ARG_MARGIN_BOTTOM, 0, 0, // 1
- OS.Pt_ARG_MARGIN_TOP, 0, 0, // 4
- OS.Pt_ARG_MARGIN_RIGHT, 0, 0, // 7
- OS.Pt_ARG_MARGIN_LEFT, 0, 0, // 10
-// OS.Pt_ARG_BASIC_FLAGS, 0, 0, // 13
- };
- OS.PtGetResources(handle, args.length / 3, args);
- int trimX = x - args [10];
- int trimY;
- if ((style & SWT.BOTTOM) != 0) {
- trimY = y - args [4];
- } else {
- trimY = y - (dim.h - args [1]);
- }
- int trimWidth = width + args [7] + args [10];
- int trimHeight = height + dim.h;
- return new Rectangle (trimX, trimY, trimWidth, trimHeight);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- int parentHandle = parent.parentingHandle ();
- int [] args = {
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- parentingHandle = OS.PtCreateWidget (OS.PtContainer (), parentHandle, args.length / 3, args);
- if (parentingHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int clazz = display.PtPanelGroup;
- args = new int []{
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- OS.Pt_ARG_PG_FLAGS, (style & SWT.BOTTOM) != 0 ? OS.Pt_PG_SELECTOR_ON_BOTTOM : 0, OS.Pt_PG_SELECTOR_ON_BOTTOM,
- };
- handle = OS.PtCreateWidget (clazz, parentingHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- items = new TabItem [4];
-}
-
-void createItem (TabItem item, int index) {
- int count = itemCount;
- if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
- if (count == items.length) {
- TabItem [] newItems = new TabItem [items.length + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- int [] args = {OS.Pt_ARG_PG_PANEL_TITLES, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- int oldPtr = args [1];
- int newPtr = OS.malloc ((count + 1) * 4);
- if (newPtr == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- int j = 0;
- int [] str = new int [1];
- int [] address = new int [1];
- for (int i=0; i<=count; i++) {
- if (i == index) {
- str [0] = OS.malloc (1);
- OS.memset(str [0], 0, 1);
- } else {
- OS.memmove (address, oldPtr + (j++ * 4), 4);
- str [0] = OS.strdup (address [0]);
- }
- if (str [0] == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- OS.memmove (newPtr + (i * 4), str, 4);
- }
- OS.PtSetResource (handle, OS.Pt_ARG_PG_PANEL_TITLES, newPtr, count + 1);
- for (int i=0; i<=count; i++) {
- OS.memmove (address, newPtr + (i * 4), 4);
- OS.free (address [0]);
- }
- OS.free (newPtr);
- System.arraycopy (items, index, items, index + 1, count - index);
- items [index] = item;
- itemCount++;
-}
-
-void deregister () {
- super.deregister ();
- if (parentingHandle != 0) WidgetTable.remove (parentingHandle);
-}
-
-void destroyItem (TabItem item) {
- int count = itemCount;
- int index = 0;
- while (index < count) {
- if (items [index] == item) break;
- index++;
- }
- int [] args = {OS.Pt_ARG_PG_PANEL_TITLES, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- int oldPtr = args [1];
- int newPtr = OS.malloc ((count - 1) * 4);
- if (newPtr == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- int j = 0;
- int [] str = new int [1];
- int [] address = new int [1];
- for (int i=0; i<count; i++) {
- if (i == index) continue;
- OS.memmove (address, oldPtr + (i * 4), 4);
- str [0] = OS.strdup (address [0]);
- if (str [0] == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- OS.memmove (newPtr + (j++ * 4), str, 4);
- }
- OS.PtSetResource (handle, OS.Pt_ARG_PG_PANEL_TITLES, newPtr, count - 1);
- for (int i=0; i<count-1; i++) {
- OS.memmove (address, newPtr + (i * 4), 4);
- OS.free (address [0]);
- }
- OS.free (newPtr);
- if (index != count) {
- System.arraycopy (items, index + 1, items, index, --count - index);
- }
- items [count] = null;
- itemCount--;
-}
-
-public Rectangle getClientArea () {
- checkWidget();
- PhArea_t area = new PhArea_t ();
- if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidgetFamily (handle);
- int clientHandle = OS.PtWidgetChildBack (handle);
- OS.PtWidgetArea (clientHandle, area);
-
- int args[] = {
- OS.Pt_ARG_MARGIN_RIGHT, 0, 0,
- OS.Pt_ARG_MARGIN_BOTTOM, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
-
- PhArea_t parentArea = new PhArea_t();
- OS.PtWidgetArea(handle, parentArea);
- int deltaX = area.pos_x - parentArea.pos_x;
- int deltaY = area.pos_y - parentArea.pos_y;
- area.size_w = (short) (parentArea.size_w - ( deltaX + args[1]));
- area.size_h = (short) (parentArea.size_h - ( deltaY + args [4]));
-
- return new Rectangle (area.pos_x, area.pos_y, area.size_w, area.size_h);
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem getItem (int index) {
- checkWidget();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-
-/**
- * Returns the tab item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- *
- * @param point the point used to locate the item
- * @return the tab item at the given point, or null if the point is not in a tab item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public TabItem getItem (Point point) {
- checkWidget();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int index = 0; index < itemCount; index++) {
- TabItem item = items[index];
- Rectangle bounds = item.getBounds();
- if (bounds.contains(point)) return item;
- }
- return null;
-}
-
-/**
- * Returns an array of <code>TabItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem [] getItems () {
- checkWidget();
- TabItem [] result = new TabItem [itemCount];
- System.arraycopy (items, 0, result, 0, result.length);
- return result;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- return itemCount;
-}
-
-/**
- * Returns an array of <code>TabItem</code>s that are currently
- * selected in the receiver. An empty array indicates that no
- * items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem [] getSelection () {
- checkWidget();
- int index = getSelectionIndex ();
- if (index == -1) return new TabItem [0];
- return new TabItem [] {items [index]};
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget();
- int index;
- if (currentIndex != OS.Pt_PG_INVALID && !OS.PtWidgetIsRealized (handle)) {
- index = currentIndex;
- } else {
- int [] args = {OS.Pt_ARG_PG_CURRENT_INDEX, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- index = args [1];
- }
- return index == OS.Pt_PG_INVALID ? -1 : index;
-}
-
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- OS.PtAddCallback (handle, OS.Pt_CB_PG_PANEL_SWITCHING, windowProc, OS.Pt_CB_PG_PANEL_SWITCHING);
- OS.PtAddCallback (handle, OS.Pt_CB_REALIZED, windowProc, OS.Pt_CB_REALIZED);
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (TabItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<itemCount; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-
-Point minimumSize (int wHint, int hHint, boolean flushCache) {
- Control [] children = _getChildren ();
- int width = 0, height = 0;
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- int index = 0;
- while (index < itemCount) {
- if (items [index].control == child) break;
- index++;
- }
- if (index == itemCount) {
- Rectangle rect = child.getBounds ();
- width = Math.max (width, rect.x + rect.width);
- height = Math.max (height, rect.y + rect.height);
- } else {
- Point size = child.computeSize (wHint, hHint, flushCache);
- width = Math.max (width, size.x);
- height = Math.max (height, size.y);
- }
- }
- return new Point (width, height);
-}
-
-void moveToBack (int child) {
- OS.PtWidgetInsert (child, handle, 0);
-}
-
-int parentingHandle () {
- return parentingHandle;
-}
-
-int Pt_CB_PG_PANEL_SWITCHING (int widget, int info) {
- if (info == 0) return OS.Pt_CONTINUE;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- short[] oldIndex = new short[1];
- short[] newIndex = new short[1];
- OS.memmove(oldIndex, cbinfo.cbdata + 8, 2);
- OS.memmove(newIndex, cbinfo.cbdata + 10, 2);
- Control oldControl = null;
- int index = oldIndex [0];
- TabItem oldItem = items [index];
- if (0 <= index && index < itemCount) oldControl = oldItem.control;
- Control newControl = null;
- index = newIndex [0];
- TabItem newItem = items [index];
- if (0 <= index && index < itemCount) newControl = newItem.control;
- if (oldControl != null && !oldControl.isDisposed()) oldControl.setVisible (false);
- if (newControl != null && !newControl.isDisposed()) {
- newControl.setBounds (getClientArea ());
- newControl.setVisible (true);
- }
- Event event = new Event ();
- event.item = newItem;
- postEvent (SWT.Selection, event);
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_REALIZED (int widget, int info) {
- int result = super.Pt_CB_REALIZED (widget, info);
- if (currentIndex != OS.Pt_PG_INVALID) {
- if (info == 0) return OS.Pt_END;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.reason == OS.Pt_CB_REALIZED) {
- setSelection (currentIndex, false);
- currentIndex = OS.Pt_PG_INVALID;
- }
- }
- return result;
-}
-
-void register () {
- super.register ();
- if (parentingHandle != 0) WidgetTable.put (parentingHandle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parentingHandle = 0;
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<itemCount; i++) {
- TabItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- itemCount = 0;
- items = null;
- }
- super.releaseChildren (destroy);
-}
-
-void removeControl (Control control) {
- super.removeControl (control);
- for (int i=0; i<itemCount; i++) {
- TabItem item = items [i];
- if (item.control == control) item.setControl (null);
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- int result = super.setBounds (x, y, width, height, move, resize, events);
- if ((result & RESIZED) != 0) {
- int [] args = {OS.Pt_ARG_WIDTH, 0, 0, OS.Pt_ARG_HEIGHT, 0, 0};
- OS.PtGetResources (parentingHandle, args.length / 3, args);
- OS.PtSetResources (handle, args.length / 3, args);
- int index = getSelectionIndex ();
- if (index != -1) {
- TabItem item = items [index];
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setBounds (getClientArea ());
- }
- }
- }
- return result;
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains selected.
- * The current selection is first cleared, then the new items are
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int index) {
- checkWidget();
- if (!(0 <= index && index < itemCount)) return;
- setSelection (index, false);
-}
-
-void setSelection (int index, boolean notify) {
- int [] args = {OS.Pt_ARG_PG_CURRENT_INDEX, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- int oldIndex = args [1];
- if (oldIndex != OS.Pt_PG_INVALID) {
- TabItem item = items [oldIndex];
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setVisible (false);
- }
- }
- if (index == -1) index = OS.Pt_PG_INVALID;
- OS.PtSetResource (handle, OS.Pt_ARG_PG_CURRENT_INDEX, index, 0);
- args [1] = 0;
- OS.PtGetResources (handle, args.length / 3, args);
- int newIndex = args [1];
- /*
- * Bug in Photon. Pt_ARG_PG_CURRENT_INDEX cannot be set if
- * the widget is not realized. The fix is to remember the current
- * index and reset it when the widget is realized.
- */
- if (!OS.PtWidgetIsRealized (handle)) {
- newIndex = currentIndex = index;
- }
- if (newIndex != OS.Pt_PG_INVALID) {
- TabItem item = items [newIndex];
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setBounds (getClientArea ());
- control.setVisible (true);
- }
- if (notify) {
- Event event = new Event ();
- event.item = item;
- postEvent (SWT.Selection, event);
- }
- }
-}
-
-/**
- * Sets the receiver's selection to the given item.
- * The current selected is first cleared, then the new item is
- * selected.
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection (TabItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (new TabItem [] {item});
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selected is first cleared, then the new items are
- * selected.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (TabItem [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (items.length == 0) {
- setSelection (-1, false);
- } else {
- for (int i=items.length-1; i>=0; --i) {
- int index = indexOf (items [i]);
- if (index != -1) setSelection (index, false);
- }
- }
-}
-
-boolean traversePage (boolean next) {
- int count = getItemCount ();
- if (count == 0) return false;
- int index = getSelectionIndex ();
- if (index == -1) {
- index = 0;
- } else {
- int offset = next ? 1 : -1;
- index = (index + offset + count) % count;
- }
- setSelection (index, true);
- return true;
-}
-
-int topHandle () {
- return parentingHandle;
-}
-
-int widgetClass () {
- return OS.PtPanelGroup ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/TabItem.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/TabItem.java
deleted file mode 100755
index dc914c6ac4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/TabItem.java
+++ /dev/null
@@ -1,344 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * corresponding to a tab for a page in a tab folder.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tabfolder">TabFolder, TabItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TabItem extends Item {
- TabFolder parent;
- Control control;
- String toolTipText;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>TabFolder</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabItem (TabFolder parent, int style) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>TabFolder</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabItem (TabFolder parent, int style, int index) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public Rectangle getBounds() {
- //TODO: Need to provide implementation for photon.
- checkWidget();
- return new Rectangle (0, 0, 0, 0);
-}
-
-/**
- * Returns the control that is used to fill the client area of
- * the tab folder when the user selects the tab item. If no
- * control has been set, return <code>null</code>.
- * <p>
- * @return the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget();
- return control;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>TabFolder</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabFolder getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- int index = parent.indexOf (this);
- if (index == parent.getSelectionIndex ()) {
- if (control != null) control.setVisible (false);
- }
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- control = null;
- toolTipText = null;
-}
-
-/**
- * Sets the control that is used to fill the client area of
- * the tab folder when the user selects the tab item.
- * <p>
- * @param control the new control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- if (this.control != null && this.control.isDisposed ()) {
- this.control = null;
- }
- Control oldControl = this.control, newControl = control;
- this.control = control;
- int index = parent.indexOf (this), selectionIndex = parent.getSelectionIndex();
- if (index != selectionIndex) {
- if (newControl != null) {
- if (selectionIndex != -1) {
- Control selectedControl = parent.getItem(selectionIndex).getControl();
- if (selectedControl == newControl) return;
- }
- newControl.setVisible(false);
- return;
- }
- }
- if (newControl != null) {
- newControl.setBounds (parent.getClientArea ());
- newControl.setVisible (true);
- }
- if (oldControl != null) oldControl.setVisible (false);
-}
-
-public void setImage (Image image) {
- checkWidget();
- //NOT SUPPORTED
-}
-
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- char [] text = new char [string.length ()];
- string.getChars (0, text.length, text, 0);
- fixMnemonic (text);
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- int index = parent.indexOf (this);
- int [] args = {OS.Pt_ARG_PG_PANEL_TITLES, 0, 0};
- OS.PtGetResources (parent.handle, args.length / 3, args);
- int count = args [2];
- int oldPtr = args [1];
- int newPtr = OS.malloc (count * 4);
- int [] str = new int [1];
- int [] address = new int [1];
- for (int i=0; i<count; i++) {
- if (i == index) {
- str [0] = OS.malloc (buffer.length);
- OS.memmove (str [0], buffer, buffer.length);
- } else {
- OS.memmove (address, oldPtr + (i * 4), 4);
- str [0] = OS.strdup (address [0]);
- }
- OS.memmove (newPtr + (i * 4), str, 4);
- }
- OS.PtSetResource (parent.handle, OS.Pt_ARG_PG_PANEL_TITLES, newPtr, count);
- for (int i=0; i<count; i++) {
- OS.memmove (address, newPtr + (i * 4), 4);
- OS.free (address [0]);
- }
- OS.free (newPtr);
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Text.java
deleted file mode 100755
index 4fdf962a41..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Text.java
+++ /dev/null
@@ -1,1615 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify text.
- * Text controls can be either single or multi-line.
- * When a text control is created with a border, the
- * operating system includes a platform specific inset
- * around the contents of the control. When created
- * without a border, an effort is made to remove the
- * inset such that the preferred size of the control
- * is the same size as the contents.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>CENTER, ICON_CANCEL, ICON_SEARCH, LEFT, MULTI, PASSWORD, SEARCH, SINGLE, RIGHT, READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Modify, Verify</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles MULTI and SINGLE may be specified,
- * and only one of the styles LEFT, CENTER, and RIGHT may be specified.
- * </p>
- * <p>
- * Note: The styles ICON_CANCEL and ICON_SEARCH are hints used in combination with SEARCH.
- * When the platform supports the hint, the text control shows these icons. When an icon
- * is selected, a default selection event is sent with the detail field set to one of
- * ICON_CANCEL or ICON_SEARCH. Normally, application code does not need to check the
- * detail. In the case of ICON_CANCEL, the text is cleared before the default selection
- * event is sent causing the application to search for an empty string.
- * </p>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#text">Text snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Text extends Scrollable {
- char echoCharacter;
- boolean ignoreChange;
- String hiddenText, message;
- int tabs, lastModifiedText;
- PtTextCallback_t textVerify;
-
- /**
- * The maximum number of characters that can be entered
- * into a text widget.
- * <p>
- * Note that this value is platform dependent, based upon
- * the native widget implementation.
- * </p>
- */
- public static final int LIMIT;
- /**
- * The delimiter used by multi-line text widgets. When text
- * is queried and from the widget, it will be delimited using
- * this delimiter.
- */
- public static final String DELIMITER;
- static final char PASSWORD = '*';
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0x7FFFFFFF;
- DELIMITER = "\n";
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#READ_ONLY
- * @see SWT#WRAP
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see SWT#PASSWORD
- * @see SWT#SEARCH
- * @see SWT#ICON_SEARCH
- * @see SWT#ICON_CANCEL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Text (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- if ((style & SWT.SEARCH) != 0) {
- style |= SWT.SINGLE | SWT.BORDER;
- style &= ~SWT.PASSWORD;
- }
- style &= ~SWT.SEARCH;
- if ((style & SWT.SINGLE) != 0 && (style & SWT.MULTI) != 0) {
- style &= ~SWT.MULTI;
- }
- style = checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
- if ((style & SWT.SINGLE) != 0) style &= ~(SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP);
- if ((style & SWT.WRAP) != 0) {
- style |= SWT.MULTI;
- style &= ~SWT.H_SCROLL;
- }
- if ((style & SWT.MULTI) != 0) style &= ~SWT.PASSWORD;
- if ((style & (SWT.SINGLE | SWT.MULTI)) != 0) return style;
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) return style | SWT.MULTI;
- return style | SWT.SINGLE;
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
-
- int [] args = new int [] {OS.Pt_ARG_WIDTH, 0, 0, OS.Pt_ARG_HEIGHT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- boolean wrap = (style & SWT.WRAP) != 0;
- if (wrap) {
- if (wHint == SWT.DEFAULT) {
- OS.PtSetResource (handle, OS.Pt_ARG_MULTITEXT_WRAP_FLAGS, OS.Pt_EMT_NEWLINE, ~0);
- } else {
- OS.PtSetResource (handle, OS.Pt_ARG_WIDTH, wHint, 0);
- }
- }
- int resizeFlags = OS.Pt_RESIZE_X_ALWAYS | OS.Pt_RESIZE_Y_ALWAYS;
- OS.PtSetResource (handle, OS.Pt_ARG_RESIZE_FLAGS, resizeFlags, OS.Pt_RESIZE_XY_BITS);
- if ((style & SWT.MULTI) != 0 || !OS.PtWidgetIsRealized (handle)) OS.PtExtentWidgetFamily (handle);
- PhDim_t dim = new PhDim_t ();
- OS.PtWidgetPreferredSize (handle, dim);
- int width = dim.w, height = dim.h;
- OS.PtSetResource (handle, OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS);
- if (wrap) {
- if (wHint == SWT.DEFAULT) {
- int wrapFlags = OS.Pt_EMT_WORD | OS.Pt_EMT_CHAR | OS.Pt_EMT_NEWLINE;
- OS.PtSetResource (handle, OS.Pt_ARG_MULTITEXT_WRAP_FLAGS, wrapFlags, ~0);
- }
- }
- OS.PtSetResources (handle, args.length / 3, args);
-
- ScrollBar scroll;
- int scrollWidth = (scroll = getVerticalBar ()) != null ? scroll.getSize ().x : 0;
- int scrollHeight = (scroll = getHorizontalBar ()) != null ? scroll.getSize ().y : 0;
- width += scrollWidth;
- if (!wrap) height += scrollHeight;
-
- if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) {
- PhRect_t rect = new PhRect_t ();
- PhArea_t area = new PhArea_t ();
- rect.lr_x = (short) (wHint - 1);
- rect.lr_y = (short) (hHint - 1);
- OS.PtSetAreaFromWidgetCanvas (handle, rect, area);
- if (wHint != SWT.DEFAULT) width = area.size_w + scrollWidth;
- if (hHint != SWT.DEFAULT) height = area.size_h + scrollHeight;
- }
- return new Point(width, height);
-}
-/**
- * Clears the selection.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void clearSelection () {
- checkWidget();
- int [] position = {0};
- if ((style & SWT.SINGLE) != 0) {
- int [] args = {OS.Pt_ARG_CURSOR_POSITION, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- position [0] = args [1];
- }
- OS.PtTextSetSelection (handle, position, position);
-}
-void createHandle (int index) {
- state |= HANDLE;
- int parentHandle = parent.parentingHandle ();
- boolean hasBorder = (style & SWT.BORDER) != 0;
- int textFlags = (style & SWT.READ_ONLY) != 0 ? 0 : OS.Pt_EDITABLE;
- if ((style & SWT.SINGLE) != 0) {
- int clazz = display.PtText;
- int [] args = {
- OS.Pt_ARG_FLAGS, hasBorder ? OS.Pt_HIGHLIGHTED : 0, OS.Pt_HIGHLIGHTED,
- OS.Pt_ARG_FLAGS, OS.Pt_CALLBACKS_ACTIVE, OS.Pt_CALLBACKS_ACTIVE,
- OS.Pt_ARG_TEXT_FLAGS, textFlags, OS.Pt_EDITABLE,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (clazz, parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- return;
- }
- int clazz = display.PtMultiText;
- int wrapFlags = (style & SWT.WRAP) != 0 ? OS.Pt_EMT_WORD | OS.Pt_EMT_CHAR : 0;
- int [] args = {
- OS.Pt_ARG_FLAGS, hasBorder ? OS.Pt_HIGHLIGHTED : 0, OS.Pt_HIGHLIGHTED,
- OS.Pt_ARG_FLAGS, OS.Pt_CALLBACKS_ACTIVE, OS.Pt_CALLBACKS_ACTIVE,
- OS.Pt_ARG_TEXT_FLAGS, textFlags, OS.Pt_EDITABLE,
- OS.Pt_ARG_MULTITEXT_WRAP_FLAGS, wrapFlags, OS.Pt_EMT_WORD | OS.Pt_EMT_CHAR,
- OS.Pt_ARG_SCROLLBAR_X_DISPLAY, (style & SWT.H_SCROLL) != 0 ? OS.Pt_ALWAYS : OS.Pt_NEVER, 0,
- OS.Pt_ARG_SCROLLBAR_Y_DISPLAY, (style & SWT.V_SCROLL) != 0 ? OS.Pt_ALWAYS : OS.Pt_NEVER, 0,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (clazz, parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- createStandardScrollBars ();
-}
-
-void createWidget (int index) {
- super.createWidget (index);
-// doubleClick = true;
- setTabStops (tabs = 8);
- hiddenText = message = "";
- if ((style & SWT.PASSWORD) != 0) setEchoChar (PASSWORD);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is not called for texts.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text,
- * or when ENTER is pressed in a search text. If the receiver has the <code>SWT.SEARCH | SWT.CANCEL</code> style
- * and the user cancels the search, the event object detail field contains the value <code>SWT.CANCEL</code>.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- */
-public void addVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-
-/**
- * Appends a string.
- * <p>
- * The new text is appended to the text at
- * the end of the widget.
- * </p>
- *
- * @param string the string to be appended
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void append (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, string, false);
- OS.PtTextModifyText (handle, 0, 0, -1, buffer, buffer.length);
-}
-
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void copy () {
- checkWidget();
- int [] start = new int [1], end = new int [1];
- int length = OS.PtTextGetSelection (handle, start, end);
- if (length <= 0) return;
- int [] args = {OS.Pt_ARG_TEXT_STRING, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- byte[] buffer = new byte[length + 1];
- OS.memmove (buffer, args [1] + start [0], length);
- int ig = OS.PhInputGroup (0);
- OS.PhClipboardCopyString((short)ig, buffer);
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void cut () {
- checkWidget();
- int [] start = new int [1], end = new int [1];
- int length = OS.PtTextGetSelection (handle, start, end);
- if (length <= 0) return;
- int [] args = {OS.Pt_ARG_TEXT_STRING, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- byte[] buffer = new byte[length + 1];
- OS.memmove (buffer, args [1] + start [0], length);
- int ig = OS.PhInputGroup (0);
- OS.PhClipboardCopyString((short)ig, buffer);
- buffer = new byte[0];
- OS.PtTextModifyText (handle, start [0], end [0], start [0], buffer, buffer.length);
-}
-
-void deregister () {
- super.deregister ();
-
- /*
- * Bug in Photon. Even though the Pt_CB_GOT_FOCUS callback
- * is added to the multi-line text, the widget parameter
- * in the callback is a child of the multi-line text. The fix
- * is to register that child so that the lookup in the widget
- * table will find the muti-line text.
- */
- if ((style & SWT.MULTI) == 0) return;
- int child = OS.PtWidgetChildBack (handle);
- WidgetTable.remove (child);
-}
-
-int defaultBackground () {
- return display.TEXT_BACKGROUND;
-}
-
-int defaultForeground () {
- return display.TEXT_FOREGROUND;
-}
-
-/**
- * Returns the line number of the caret.
- * <p>
- * The line number of the caret is returned.
- * </p>
- *
- * @return the line number
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretLineNumber () {
- checkWidget();
- //NOT DONE - NOT NEEDED
- return 0;
-}
-
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null).
- * <p>
- * The location of the caret is returned.
- * </p>
- *
- * @return a point, the location of the caret
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getCaretLocation () {
- checkWidget();
- //NOT DONE - NOT NEEDED
- return null;
-}
-
-/**
- * Returns the character position of the caret.
- * <p>
- * Indexing is zero based.
- * </p>
- *
- * @return the position of the caret
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretPosition () {
- checkWidget();
- int [] args = {OS.Pt_ARG_CURSOR_POSITION, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the number of characters.
- *
- * @return number of characters in the widget
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCharCount () {
- checkWidget();
- int [] args = {OS.Pt_ARG_TEXT_STRING, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- if (args [1] == 0) return 0;
- return OS.strlen (args [1]);
-}
-
-/**
- * Returns the double click enabled flag.
- * <p>
- * The double click flag enables or disables the
- * default action of the text widget when the user
- * double clicks.
- * </p>
- *
- * @return whether or not double click is enabled
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getDoubleClickEnabled () {
- checkWidget();
- //NOT DONE - NOT NEEDED
- return false;
-}
-
-/**
- * Returns the echo character.
- * <p>
- * The echo character is the character that is
- * displayed when the user enters text or the
- * text is changed by the programmer.
- * </p>
- *
- * @return the echo character
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setEchoChar
- */
-public char getEchoChar () {
- checkWidget();
- return echoCharacter;
-}
-
-/**
- * Returns the editable state.
- *
- * @return whether or not the receiver is editable
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getEditable () {
- checkWidget();
- int [] args = {OS.Pt_ARG_TEXT_FLAGS, 0, 0};
- OS.PtGetResources(handle, args.length / 3, args);
- return (args [1] & OS.Pt_EDITABLE) != 0;
-}
-
-/**
- * Returns the number of lines.
- *
- * @return the number of lines in the widget
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getLineCount () {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return 1;
- int [] args = {OS.Pt_ARG_MULTITEXT_NUM_LINES, 0, 0};
- OS.PtGetResources(handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the line delimiter.
- *
- * @return a string that is the line delimiter
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #DELIMITER
- */
-public String getLineDelimiter () {
- checkWidget();
- return "\n";
-}
-
-/**
- * Returns the height of a line.
- *
- * @return the height of a row of text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getLineHeight () {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) {
- PhDim_t dim = new PhDim_t ();
- if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidget (handle);
- OS.PtWidgetPreferredSize (handle, dim);
- PhRect_t extent = new PhRect_t ();
- OS.PtWidgetExtent(handle, extent);
- PhRect_t canvas = new PhRect_t ();
- OS.PtWidgetCanvas (handle, canvas);
- int topBorder = canvas.ul_y - extent.ul_y;
- int bottomBorder = extent.lr_y - canvas.lr_y;
- return dim.h - topBorder - bottomBorder;
- }
- int ptr = OS.malloc (20);
- int [] args = {
- OS.Pt_ARG_MULTITEXT_QUERY_LINE, ptr, 1,
- OS.Pt_ARG_MULTITEXT_LINE_SPACING, 0, 0
- };
- OS.PtGetResources (handle, args.length / 3, args);
- int [] line = new int [1];
- OS.memmove (line, args [1] + 8, 4);
- PhRect_t extent = new PhRect_t ();
- OS.memmove (extent, line [0] + 10, 8);
- OS.free(ptr);
- return extent.lr_y - extent.ul_y + 1 + args [4];
-}
-
-/**
- * Returns the widget message. The message text is displayed
- * as a hint for the user, indicating the purpose of the field.
- * <p>
- * Typically this is used in conjunction with <code>SWT.SEARCH</code>.
- * </p>
- *
- * @return the widget message
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public String getMessage () {
- checkWidget ();
- return message;
-}
-
-String getNameText () {
- if ((style & SWT.SINGLE) != 0) return getText ();
- return getText (0, Math.min(getCharCount () - 1, 10));
-}
-
-/**
- * Returns the orientation of the receiver, which will be one of the
- * constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getOrientation () {
- checkWidget();
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-/**
- * Returns a <code>Point</code> whose x coordinate is the
- * character position representing the start of the selected
- * text, and whose y coordinate is the character position
- * representing the end of the selection. An "empty" selection
- * is indicated by the x and y coordinates having the same value.
- * <p>
- * Indexing is zero based. The range of a selection is from
- * 0..N where N is the number of characters in the widget.
- * </p>
- *
- * @return a point representing the selection start and end
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSelection () {
- checkWidget();
- if (textVerify != null) {
- return new Point (textVerify.start_pos, textVerify.end_pos);
- }
- int [] start = new int [1], end = new int [1];
- OS.PtTextGetSelection (handle, start, end);
- if (start [0] == -1) {
- int [] args = {OS.Pt_ARG_CURSOR_POSITION, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- start [0] = end [0] = args [1];
- }
- return new Point (start [0], end [0]);
-}
-
-/**
- * Returns the number of selected characters.
- *
- * @return the number of selected characters.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget();
- Point selection = getSelection ();
- return selection.y - selection.x;
-}
-
-/**
- * Gets the selected text, or an empty string if there is no current selection.
- *
- * @return the selected text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getSelectionText () {
- checkWidget();
- /*
- * NOTE: The current implementation uses substring ()
- * which can reference a potentially large character
- * array.
- */
- Point selection = getSelection ();
- return getText ().substring (selection.x, selection.y);
-}
-
-/**
- * Returns the number of tabs.
- * <p>
- * Tab stop spacing is specified in terms of the
- * space (' ') character. The width of a single
- * tab stop is the pixel width of the spaces.
- * </p>
- *
- * @return the number of tab characters
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTabs () {
- checkWidget();
- return tabs;
-}
-
-int getTabWidth (int tabs) {
- int [] args = new int [] {OS.Pt_ARG_TEXT_FONT, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- PhRect_t rect = new PhRect_t ();
- int ptr = OS.malloc (1);
- OS.memmove (ptr, new byte [] {' '}, 1);
- OS.PfExtentText(rect, null, args [1], ptr, 1);
- OS.free (ptr);
- int width = rect.lr_x - rect.ul_x + 1;
- return width * tabs;
-}
-
-/**
- * Returns a range of text. Returns an empty string if the
- * start of the range is greater than the end.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N-1 where N is
- * the number of characters in the widget.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- * @return the range of text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText (int start, int end) {
- checkWidget ();
- if (!(start <= end && 0 <= end)) return "";
- String text = getText ();
- int length = text.length ();
- end = Math.min (end, length - 1);
- if (start > end) return "";
- start = Math.max (0, start);
- /*
- * NOTE: The current implementation uses substring ()
- * which can reference a potentially large character
- * array.
- */
- //NOT DONE - use OS in SINGLE text
- return text.substring (start, end + 1);
-}
-
-/**
- * Returns the widget text.
- * <p>
- * The text for a text widget is the characters in the widget, or
- * an empty string if this has never been set.
- * </p>
- *
- * @return the widget text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- if (echoCharacter != '\0') return hiddenText;
- int [] args = {OS.Pt_ARG_TEXT_STRING, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- if (args [1] == 0) return "";
- int length = OS.strlen (args [1]);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, args [1], length);
- char [] unicode = Converter.mbcsToWcs (null, buffer);
- return new String (unicode);
-}
-
-/**
- * Returns the maximum number of characters that the receiver is capable of holding.
- * <p>
- * If this has not been changed by <code>setTextLimit()</code>,
- * it will be the constant <code>Text.LIMIT</code>.
- * </p>
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public int getTextLimit () {
- checkWidget();
- int [] args = new int [] {OS.Pt_ARG_MAX_LENGTH, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- return args [1];
-}
-
-/**
- * Returns the zero-relative index of the line which is currently
- * at the top of the receiver.
- * <p>
- * This index can change when lines are scrolled or new lines are added or removed.
- * </p>
- *
- * @return the index of the top line
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return 0;
- int [] args = {OS.Pt_ARG_MULTITEXT_TOP_LINE, 0, 0};
- OS.PtGetResources(handle, args.length / 3, args);
- return args [1] - 1;
-}
-
-/**
- * Returns the top pixel.
- * <p>
- * The top pixel is the pixel position of the line
- * that is currently at the top of the widget. On
- * some platforms, a text widget can be scrolled by
- * pixels instead of lines so that a partial line
- * is displayed at the top of the widget.
- * </p><p>
- * The top pixel changes when the widget is scrolled.
- * The top pixel does not include the widget trimming.
- * </p>
- *
- * @return the pixel position of the top line
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopPixel () {
- checkWidget();
- //NOT DONE - NOT NEEDED
- return 0;
-}
-
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- OS.PtAddCallback (handle, OS.Pt_CB_MODIFY_VERIFY, windowProc, OS.Pt_CB_MODIFY_VERIFY);
- OS.PtAddCallback (handle, OS.Pt_CB_TEXT_CHANGED, windowProc, OS.Pt_CB_TEXT_CHANGED);
-}
-
-/**
- * Inserts a string.
- * <p>
- * The old selection is replaced with the new text.
- * </p>
- *
- * @param string the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is <code>null</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void insert (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, string, false);
- int [] start = new int [1], end = new int [1];
- OS.PtTextGetSelection (handle, start, end);
- if (start [0] == -1) {
- int [] args = {OS.Pt_ARG_CURSOR_POSITION, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- start [0] = end [0] = args [1];
- }
- OS.PtTextModifyText (handle, start [0], end [0], start [0], buffer, buffer.length);
-}
-
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void paste () {
- checkWidget();
- int ig = OS.PhInputGroup (0);
- int ptr = OS.PhClipboardPasteString((short)ig);
- if (ptr == 0) return;
- int length = OS.strlen (ptr);
- int [] start = new int [1], end = new int [1];
- OS.PtTextGetSelection (handle, start, end);
- if (start [0] == -1) {
- int [] args = {OS.Pt_ARG_CURSOR_POSITION, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- start [0] = end [0] = args [1];
- }
- OS.PtTextModifyText (handle, start [0], end [0], end [0], ptr, length);
- OS.free(ptr);
-}
-
-int Ph_EV_BOUNDARY (int widget, int info) {
- /*
- * Bug in Photon. PtMultiText reports boundary events for
- * the internal (hidden) child widget. This makes it appear as
- * though the pointer leaves as soon as it enters the widget
- * area. The fix is to filter out these theser events.
- */
- if ((style & SWT.MULTI) != 0) {
- if (info == 0) return OS.Pt_END;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.event == 0) return OS.Pt_END;
- PhEvent_t ev = new PhEvent_t ();
- OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
- switch ((int) ev.subtype) {
- case OS.Ph_EV_PTR_ENTER_FROM_CHILD:
- case OS.Ph_EV_PTR_LEAVE_TO_CHILD:
- return OS.Pt_CONTINUE;
- }
- }
- return super.Ph_EV_BOUNDARY (widget, info);
-}
-
-int Pt_CB_GOT_FOCUS (int widget, int info) {
-
- /*
- * Bug in Photon. Even though the Pt_CB_GOT_FOCUS callback
- * is added to the multi-line text, the widget parameter
- * in the callback is a child of the multi-line text. The fix
- * is to register that child so that the lookup in the widget
- * table will find the muti-line text and avoid multiple
- * Pt_CB_LOST_FOCUS callbacks.
- */
- if ((style & SWT.MULTI) != 0) {
- if (widget != handle) return OS.Pt_CONTINUE;
- }
- return super.Pt_CB_GOT_FOCUS (widget, info);
-}
-
-int Pt_CB_MODIFY_VERIFY (int widget, int info) {
- if (lastModifiedText != 0) {
- OS.free (lastModifiedText);
- lastModifiedText = 0;
- }
- if (echoCharacter == '\0' && !hooks (SWT.Verify) && !filters (SWT.Verify)) return 0;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- PtTextCallback_t textVerify = new PtTextCallback_t ();
- OS.memmove (textVerify, cbinfo.cbdata, PtTextCallback_t.sizeof);
- byte [] buffer = new byte [textVerify.length];
- OS.memmove (buffer, textVerify.text, buffer.length);
- String text = new String (Converter.mbcsToWcs (null, buffer));
- String newText = text;
- if (!ignoreChange) {
- Event event = new Event ();
- event.start = textVerify.start_pos;
- event.end = textVerify.end_pos;
- event.doit = textVerify.doit != 0;
- event.text = text;
- if (cbinfo.event != 0) {
- int data = OS.PhGetData (cbinfo.event);
- if (data != 0) {
- PhKeyEvent_t ke = new PhKeyEvent_t ();
- OS.memmove (ke, data, PhKeyEvent_t.sizeof);
- if ((ke.key_flags & (OS.Pk_KF_Key_Down | OS.Pk_KF_Key_Repeat)) != 0) {
- setKeyState (event, SWT.Verify, ke);
- }
- }
- }
- sendEvent (SWT.Verify, event);
- newText = event.text;
- textVerify.doit = (event.doit && newText != null) ? 1 : 0;
- }
- if (newText != null) {
- if (echoCharacter != '\0' && (textVerify.doit != 0)) {
- String prefix = hiddenText.substring (0, textVerify.start_pos);
- String suffix = hiddenText.substring (textVerify.end_pos, hiddenText.length ());
- hiddenText = prefix + newText + suffix;
- char [] charBuffer = new char [newText.length ()];
- for (int i=0; i<charBuffer.length; i++) {
- charBuffer [i] = echoCharacter;
- }
- newText = new String (charBuffer);
- }
- if (newText != text) {
- byte [] buffer2 = Converter.wcsToMbcs (null, newText, true);
- int length = buffer2.length - 1;
- if (length == textVerify.length) {
- OS.memmove(textVerify.text, buffer2, length);
- } else {
- int ptr = OS.malloc (length);
- OS.memmove (ptr, buffer2, length);
- textVerify.new_insert += length - textVerify.length;
- textVerify.text = ptr;
- textVerify.length = length;
- lastModifiedText = ptr;
- }
- }
- }
- OS.memmove (cbinfo.cbdata, textVerify, PtTextCallback_t.sizeof);
- textVerify = null;
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_TEXT_CHANGED (int widget, int info) {
- if (lastModifiedText != 0) {
- OS.free (lastModifiedText);
- lastModifiedText = 0;
- }
- if (!ignoreChange) sendEvent (SWT.Modify);
- return OS.Pt_CONTINUE;
-}
-
-void register () {
- super.register ();
-
- /*
- * Bug in Photon. Even though the Pt_CB_GOT_FOCUS callback
- * is added to the multi-line text, the widget parameter
- * in the callback is a child of the multi-line text. The fix
- * is to register that child so that the lookup in the widget
- * table will find the muti-line text.
- */
- if ((style & SWT.MULTI) == 0) return;
- int child = OS.PtWidgetChildBack (handle);
- WidgetTable.put (child, this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (lastModifiedText != 0) OS.free (lastModifiedText);
- lastModifiedText = 0;
- hiddenText = message = null;
- textVerify = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- */
-public void removeVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-
-/**
- * Selects all the text in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget();
- OS.PtTextSetSelection (handle, new int [] {0}, new int [] {0x7FFFFFFF});
-}
-
-/**
- * Sets the echo character.
- * <p>
- * The echo character is the character that is
- * displayed when the user enters text or the
- * text is changed by the programmer. Setting
- * the echo character to '\0' clears the echo
- * character and redraws the original text.
- * If for any reason the echo character is invalid,
- * or if the platform does not allow modification
- * of the echo character, the default echo character
- * for the platform is used.
- * </p>
- *
- * @param echo the new echo character
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEchoChar (char echo) {
- checkWidget();
- if ((style & SWT.MULTI) != 0) return;
- if (echoCharacter == echo) return;
- String newText;
- if (echo == 0) {
- newText = hiddenText;
- hiddenText = "";
- } else {
- newText = hiddenText = getText();
- }
- echoCharacter = echo;
- Point selection = getSelection();
- boolean oldValue = ignoreChange;
- ignoreChange = true;
- setText(newText);
- setSelection(selection.x, selection.y);
- ignoreChange = oldValue;
-}
-
-/**
- * Sets the double click enabled flag.
- * <p>
- * The double click flag enables or disables the
- * default action of the text widget when the user
- * double clicks.
- * </p><p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param doubleClick the new double click flag
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDoubleClickEnabled (boolean doubleClick) {
- checkWidget();
- //NOT DONE - NOT NEEDED
-}
-
-/**
- * Sets the editable state.
- *
- * @param editable the new editable state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEditable (boolean editable) {
- checkWidget();
- style &= ~SWT.READ_ONLY;
- if (!editable) style |= SWT.READ_ONLY;
- int flags = editable ? OS.Pt_EDITABLE : 0;
- OS.PtSetResource (handle, OS.Pt_ARG_TEXT_FLAGS, flags, OS.Pt_EDITABLE);
-}
-
-public void setFont (Font font) {
- super.setFont (font);
- setTabStops (tabs);
-}
-
-/**
- * Sets the widget message. The message text is displayed
- * as a hint for the user, indicating the purpose of the field.
- * <p>
- * Typically this is used in conjunction with <code>SWT.SEARCH</code>.
- * </p>
- *
- * @param message the new message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the message is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public void setMessage (String message) {
- checkWidget ();
- if (message == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.message = message;
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public void setOrientation (int orientation) {
- checkWidget();
-}
-
-/**
- * Sets the selection.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * regular array indexing rules.
- * </p>
- *
- * @param start new caret position
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int position) {
- checkWidget();
- OS.PtSetResource (handle, OS.Pt_ARG_CURSOR_POSITION, position, 0);
-
- /*
- * Feature in Photon. On a single-line text, the selection is
- * not cleared when setting the cursor position. The fix is to
- * set the selection start and end values to the specified
- * position.
- */
- if ((style & SWT.SINGLE) != 0) {
- int [] selection = {position};
- OS.PtTextSetSelection (handle, selection, selection);
- }
-}
-
-/**
- * Sets the selection to the range specified
- * by the given point, where the x coordinate
- * represents the start index and the y coordinate
- * represents the end index.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * usual array indexing rules.
- * </p>
- *
- * @param selection the point
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (Point selection) {
- checkWidget();
- if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (selection.x, selection.y);
-}
-
-/**
- * Sets the selection to the range specified
- * by the given start and end indices.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * usual array indexing rules.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int start, int end) {
- checkWidget();
- OS.PtTextSetSelection (handle, new int [] {start}, new int [] {end});
-
- /*
- * Feature in Photon. On a multi-line text, the caret position
- * is not changed with the selection start and end values are
- * the same. The fix is to detect this case and change the
- * cursor position.
- */
- if ((style & SWT.MULTI) != 0 && start == end) {
- OS.PtSetResource (handle, OS.Pt_ARG_CURSOR_POSITION, start, 0);
- }
-}
-
-/**
- * Sets the number of tabs.
- * <p>
- * Tab stop spacing is specified in terms of the
- * space (' ') character. The width of a single
- * tab stop is the pixel width of the spaces.
- * </p>
- *
- * @param tabs the number of tabs
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTabs (int tabs) {
- checkWidget();
- if (tabs < 0) return;
- setTabStops (this.tabs = tabs);
-}
-
-void setTabStops (int tabs) {
- if ((style & SWT.SINGLE) != 0) return;
- int tabsWidth = getTabWidth (tabs);
- int ptr = OS.malloc (4);
- OS.memmove (ptr, new int [] {tabsWidth}, 4);
- OS.PtSetResource (handle, OS.Pt_ARG_MULTITEXT_TABS, ptr, 1);
- OS.free (ptr);
-}
-
-/**
- * Sets the contents of the receiver to the given string. If the receiver has style
- * SINGLE and the argument contains multiple lines of text, the result of this
- * operation is undefined and may vary from platform to platform.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- int ptr = OS.malloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- OS.PtSetResource (handle, OS.Pt_ARG_TEXT_STRING, ptr, 0);
- OS.free (ptr);
-}
-
-/**
- * Sets the maximum number of characters that the receiver
- * is capable of holding to be the argument.
- * <p>
- * Instead of trying to set the text limit to zero, consider
- * creating a read-only text widget.
- * </p><p>
- * To reset this value to the default, use <code>setTextLimit(Text.LIMIT)</code>.
- * Specifying a limit value larger than <code>Text.LIMIT</code> sets the
- * receiver's limit to <code>Text.LIMIT</code>.
- * </p>
- *
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public void setTextLimit (int limit) {
- checkWidget();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- OS.PtSetResource (handle, OS.Pt_ARG_MAX_LENGTH, limit, 0);
-}
-
-/**
- * Sets the zero-relative index of the line which is currently
- * at the top of the receiver. This index can change when lines
- * are scrolled or new lines are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return;
- OS.PtSetResource (handle, OS.Pt_ARG_MULTITEXT_TOP_LINE, index + 1, 0);
-}
-
-/**
- * Shows the selection.
- * <p>
- * If the selection is already showing
- * in the receiver, this method simply returns. Otherwise,
- * lines are scrolled until the selection is visible.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void showSelection () {
- checkWidget();
- //NOT DONE - NOT NEEDED
-}
-
-int traversalCode (int key_sym, PhKeyEvent_t ke) {
- int code = super.traversalCode (key_sym, ke);
- if ((style & SWT.READ_ONLY) != 0) return code;
- if ((style & SWT.MULTI) != 0) {
- code &= ~SWT.TRAVERSE_RETURN;
- if (key_sym == OS.Pk_Tab && ke != null) {
- if ((ke.key_mods & OS.Pk_KM_Ctrl) == 0) {
- code &= ~(SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS);
- }
- }
- }
- return code;
-}
-
-boolean translateTraversal (int key_sym, PhKeyEvent_t phEvent) {
- boolean translated = super.translateTraversal (key_sym, phEvent);
- if ((style & SWT.SINGLE) != 0 && !translated && key_sym == OS.Pk_Return) {
- postEvent (SWT.DefaultSelection);
- return false;
- }
- return translated;
-}
-
-int widgetClass () {
- if ((style & SWT.SINGLE) != 0) return OS.PtText ();
- return OS.PtMultiText ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolBar.java
deleted file mode 100755
index 823bff5614..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolBar.java
+++ /dev/null
@@ -1,490 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class support the layout of selectable
- * tool bar items.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>ToolItem</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add <code>Control</code> children to it,
- * or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>FLAT, WRAP, RIGHT, HORIZONTAL, VERTICAL, SHADOW_OUT</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#toolbar">ToolBar, ToolItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolBar extends Composite {
- int parentingHandle;
- int itemCount;
- ToolItem [] items;
- ToolItem lastFocus;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#FLAT
- * @see SWT#WRAP
- * @see SWT#RIGHT
- * @see SWT#HORIZONTAL
- * @see SWT#SHADOW_OUT
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass()
- * @see Widget#getStyle()
- */
-public ToolBar (Composite parent, int style) {
- super (parent, checkStyle (style));
-
- /*
- * Ensure that either of HORIZONTAL or VERTICAL is set.
- * NOTE: HORIZONTAL and VERTICAL have the same values
- * as H_SCROLL and V_SCROLL so it is necessary to first
- * clear these bits to avoid scroll bars and then reset
- * the bits using the original style supplied by the
- * programmer.
- */
- if ((style & SWT.VERTICAL) != 0) {
- this.style |= SWT.VERTICAL;
- } else {
- this.style |= SWT.HORIZONTAL;
- }
- int orientation = (style & SWT.VERTICAL) == 0 ? OS.Pt_HORIZONTAL : OS.Pt_VERTICAL;
- OS.PtSetResource (handle, OS.Pt_ARG_ORIENTATION, orientation, 0);
-}
-
-static int checkStyle (int style) {
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-Control [] _getChildren () {
- Control [] children = super._getChildren ();
- int count = 0;
- for (int i=0; i<itemCount; i++) {
- if (items [i].control != null) count++;
- }
- if (count == 0) return children;
- Control [] newChildren = new Control [children.length + count];
- System.arraycopy (children, 0, newChildren, 0, children.length);
- int index = children.length;
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- if (item.control != null) newChildren [index++] = item.control;
- }
- return newChildren;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- if (layout != null) {
- return super.computeSize (wHint, hHint, changed);
- }
- PhDim_t dim = new PhDim_t();
- if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidgetFamily (handle);
- OS.PtWidgetPreferredSize(handle, dim);
- int width = dim.w, height = dim.h;
- if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) {
- PhRect_t rect = new PhRect_t ();
- PhArea_t area = new PhArea_t ();
- rect.lr_x = (short) (wHint - 1);
- rect.lr_y = (short) (hHint - 1);
- OS.PtSetAreaFromWidgetCanvas (handle, rect, area);
- if (wHint != SWT.DEFAULT) width = area.size_w;
- if (hHint != SWT.DEFAULT) height = area.size_h;
- }
- return new Point(width, height);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- int parentHandle = parent.parentingHandle ();
- int [] args = {
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- parentingHandle = OS.PtCreateWidget (OS.PtContainer (), parentHandle, args.length / 3, args);
- if (parentingHandle == 0) error (SWT.ERROR_NO_HANDLES);
- args = new int [] {
- OS.Pt_ARG_FLAGS, (style & SWT.NO_FOCUS) != 0 ? 0 : OS.Pt_GETS_FOCUS, OS.Pt_GETS_FOCUS,
- OS.Pt_ARG_FLAGS, hasBorder () ? OS.Pt_HIGHLIGHTED : 0, OS.Pt_HIGHLIGHTED,
- OS.Pt_ARG_TOOLBAR_FLAGS, 0, OS.Pt_TOOLBAR_DRAGGABLE | OS.Pt_TOOLBAR_END_SEPARATOR,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (display.PtToolbar, parentingHandle, args.length / 3, args);
- if ((style & SWT.FLAT) != 0) {
- OS.PtSetResource (handle, OS.Pt_ARG_BASIC_FLAGS, OS.Pt_FLAT_FILL, OS.Pt_FLAT_FILL);
- }
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-
-void createItem (ToolItem item, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (itemCount == items.length) {
- ToolItem [] newItems = new ToolItem [itemCount + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- item.createWidget (index);
- System.arraycopy (items, index, items, index + 1, itemCount++ - index);
- items [index] = item;
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- items = new ToolItem [4];
- itemCount = 0;
-}
-
-void deregister () {
- super.deregister ();
- if (parentingHandle != 0) WidgetTable.remove (parentingHandle);
-}
-
-void destroyItem (ToolItem item) {
- int index = 0;
- while (index < itemCount) {
- if (items [index] == item) break;
- index++;
- }
- if (index == itemCount) return;
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
-}
-
-public boolean forceFocus () {
- checkWidget();
- if (lastFocus != null && lastFocus.setFocus ()) return true;
- for (int i = 0; i < itemCount; i++) {
- ToolItem item = items [i];
- if (item.setFocus ()) return true;
- }
- return super.forceFocus ();
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget();
- return itemCount;
-}
-
-/**
- * Returns an array of <code>ToolItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem [] getItems () {
- checkWidget();
- ToolItem [] result = new ToolItem [itemCount];
- System.arraycopy (items, 0, result, 0, itemCount);
- return result;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem getItem (int index) {
- checkWidget();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- *
- * @param point the point used to locate the item
- * @return the item at the given point
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem getItem (Point pt) {
- checkWidget();
- if (pt == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<itemCount; i++) {
- Rectangle rect = items [i].getBounds ();
- if (rect.contains (pt)) return items [i];
- }
- return null;
-}
-
-/**
- * Returns the number of rows in the receiver. When
- * the receiver has the <code>WRAP</code> style, the
- * number of rows can be greater than one. Otherwise,
- * the number of rows is always one.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getRowCount () {
- checkWidget();
- return 1;
-}
-
-boolean hasFocus () {
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- if (item.hasFocus ()) return true;
- }
- return super.hasFocus();
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the tool item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the tool item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (ToolItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<itemCount; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-
-void moveToBack (int child) {
- OS.PtWidgetInsert (child, handle, 0);
-}
-
-int parentingHandle () {
- return parentingHandle;
-}
-
-int Ph_EV_BOUNDARY (int widget, int info) {
- if (info == 0) return OS.Pt_END;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.event == 0) return OS.Pt_END;
- PhEvent_t ev = new PhEvent_t ();
- OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
- switch ((int) ev.subtype) {
- case OS.Ph_EV_PTR_ENTER_FROM_CHILD:
- case OS.Ph_EV_PTR_LEAVE_TO_CHILD:
- return OS.Pt_CONTINUE;
- }
- return super.Ph_EV_BOUNDARY (widget, info);
-}
-
-void register () {
- super.register ();
- if (parentingHandle != 0) WidgetTable.put (parentingHandle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parentingHandle = 0;
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- itemCount = 0;
- }
- super.releaseChildren (destroy);
-}
-
-void removeControl (Control control) {
- super.removeControl (control);
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- if (item.control == control) item.setControl (null);
- }
-}
-
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- for (int i = 0; i < itemCount; i++) {
- ToolItem item = items[i];
- item.setBackgroundPixel (pixel);
- }
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- int result = super.setBounds (x, y, width, height, move, resize, events);
- if ((result & RESIZED) != 0) {
- int [] args = {OS.Pt_ARG_WIDTH, 0, 0, OS.Pt_ARG_HEIGHT, 0, 0};
- OS.PtGetResources (parentingHandle, args.length / 3, args);
- OS.PtSetResources (handle, args.length / 3, args);
- }
- return result;
-}
-
-void setFont (int font) {
- super.setFont (font);
- for (int i = 0; i < itemCount; i++) {
- ToolItem item = items[i];
- item.setFont (font);
- }
-}
-
-void setForegroundPixel (int pixel) {
- super.setForegroundPixel (pixel);
- for (int i = 0; i < itemCount; i++) {
- ToolItem item = items[i];
- item.setForegroundPixel (pixel);
- }
-}
-
-int topHandle () {
- return parentingHandle;
-}
-
-boolean translateTraversal (int key_sym, PhKeyEvent_t phEvent) {
- boolean result = super.translateTraversal (key_sym, phEvent);
- if (result) return result;
- boolean next = false;
- switch (key_sym) {
- case OS.Pk_Up:
- case OS.Pk_Left: next = false; break;
- case OS.Pk_Down:
- case OS.Pk_Right: next = true; break;
- default: return false;
- }
- int length = itemCount;
- int index = 0;
- while (index < length) {
- if (items [index].hasFocus ()) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- int start = index, offset = (next) ? 1 : -1;
- while ((index = (index + offset + length) % length) != start) {
- ToolItem item = items [index];
- if (item.setFocus ()) return false;
- }
- return false;
-}
-
-int widgetClass () {
- return OS.PtToolbar ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolItem.java
deleted file mode 100755
index ee265148db..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolItem.java
+++ /dev/null
@@ -1,967 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a button in a tool bar.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>PUSH, CHECK, RADIO, SEPARATOR, DROP_DOWN</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles CHECK, PUSH, RADIO, SEPARATOR and DROP_DOWN
- * may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#toolbar">ToolBar, ToolItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolItem extends Item {
- ToolBar parent;
- Control control;
- String toolTipText;
- int toolTipHandle;
- Image hotImage, disabledImage;
- int button, arrow;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>ToolBar</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#PUSH
- * @see SWT#CHECK
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ToolItem (ToolBar parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>ToolBar</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#PUSH
- * @see SWT#CHECK
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ToolItem (ToolBar parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called when the mouse is over the arrow portion of a drop-down tool,
- * the event object detail field contains the value <code>SWT.ARROW</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user,
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.DROP_DOWN, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void click () {
- click (handle);
-}
-
-int createArrowImage () {
- short width = 5;
- short height = 4;
- int image = OS.PhCreateImage(null, width, height, OS.Pg_IMAGE_DIRECT_888, 0, 0, 0);
- if (image == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- PhDim_t dim = new PhDim_t();
- dim.w = width;
- dim.h = height;
- int mc = OS.PmMemCreateMC(image, dim, new PhPoint_t());
- if (mc == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int prevContext = OS.PmMemStart(mc);
- OS.PgSetFillColor(0xFFFFFF);
- OS.PgDrawIRect(0, 0, width, height, OS.Pg_DRAW_FILL);
- OS.PgSetStrokeColor(0x000000);
- OS.PgSetFillColor(0x000000);
- short [] points = {(short)0, (short)1, (short)2, (short)3, (short)4, (short)1};
- OS.PgDrawPolygon(points, points.length / 2, new PhPoint_t(), OS.Pg_DRAW_FILL | OS.Pg_DRAW_STROKE | OS.Pg_CLOSED);
- OS.PmMemFlush(mc, image);
- OS.PmMemStop(mc);
- OS.PmMemReleaseMC(mc);
- OS.PhDCSetCurrent(prevContext);
- OS.PhMakeTransBitmap(image, 0xFFFFFF);
- return image;
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- int count = parent.getItemCount();
- if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
- int parentHandle = parent.handle;
-
- if ((style & SWT.SEPARATOR) != 0) {
- int [] args = {
-// OS.Pt_ARG_SEP_FLAGS, OS.Pt_SEP_VERTICAL, OS.Pt_SEP_VERTICAL | OS.Pt_SEP_HORIZONTAL,
-// OS.Pt_ARG_SEP_TYPE, OS.Pt_NOLINE, 0,
- OS.Pt_ARG_WIDTH, 2, 0,
- OS.Pt_ARG_RESIZE_FLAGS, OS.Pt_RESIZE_Y_ALWAYS, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (OS.PtContainer (), parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- } else if ((style & SWT.DROP_DOWN) != 0) {
- int [] args = {
- OS.Pt_ARG_GROUP_ORIENTATION, OS.Pt_GROUP_HORIZONTAL, 0,
- OS.Pt_ARG_GROUP_FLAGS, OS.Pt_GROUP_EQUAL_SIZE_VERTICAL, OS.Pt_GROUP_EQUAL_SIZE_VERTICAL,
- };
- handle = OS.PtCreateWidget (OS.PtGroup (), parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- boolean rightAligned = (parent.style & SWT.RIGHT) != 0;
- args = new int [] {
- OS.Pt_ARG_LABEL_TYPE, 0, 0,
- OS.Pt_ARG_FLAGS, 0, OS.Pt_GETS_FOCUS,
- OS.Pt_ARG_BALLOON_POSITION, rightAligned ? OS.Pt_BALLOON_RIGHT : OS.Pt_BALLOON_BOTTOM, 0,
- OS.Pt_ARG_BASIC_FLAGS, 0, OS.Pt_RIGHT_ETCH | OS.Pt_RIGHT_OUTLINE,
- };
- button = OS.PtCreateWidget (OS.PtButton (), handle, args.length / 3, args);
- if (button == 0) error (SWT.ERROR_NO_HANDLES);
- int arrowImage = createArrowImage ();
- args = new int [] {
- OS.Pt_ARG_FLAGS, 0, OS.Pt_GETS_FOCUS,
- OS.Pt_ARG_LABEL_IMAGE, arrowImage, 0,
- OS.Pt_ARG_LABEL_TYPE, OS.Pt_IMAGE, 0,
- OS.Pt_ARG_MARGIN_WIDTH, 1, 0,
- OS.Pt_ARG_BASIC_FLAGS, 0, OS.Pt_LEFT_ETCH | OS.Pt_LEFT_OUTLINE,
- };
- arrow = OS.PtCreateWidget (OS.PtButton (), handle, args.length / 3, args);
- OS.free (arrowImage);
- if (arrow == 0) error (SWT.ERROR_NO_HANDLES);
- } else {
- boolean rightAligned = (parent.style & SWT.RIGHT) != 0;
- boolean toggle = (style & (SWT.CHECK | SWT.RADIO)) != 0;
- int [] args = {
- OS.Pt_ARG_LABEL_TYPE, 0, 0,
- OS.Pt_ARG_FLAGS, 0, OS.Pt_GETS_FOCUS,
- OS.Pt_ARG_BALLOON_POSITION, rightAligned ? OS.Pt_BALLOON_RIGHT : OS.Pt_BALLOON_BOTTOM, 0,
- OS.Pt_ARG_FLAGS, toggle ? OS.Pt_TOGGLE : 0, OS.Pt_TOGGLE,
- };
- handle = button = OS.PtCreateWidget (OS.PtButton (), parentHandle, args.length / 3, args);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- }
- if (index != count) {
- int i = 0;
- int child = OS.PtWidgetChildBack (parentHandle);
- /*
- * Feature in Photon. Tool bars have an extra widget which
- * is the parent of all tool items. PtValidParent() can not be
- * used, since it does not return that widget.
- */
- if (child != 0) child = OS.PtWidgetChildBack (child);
- while (i != index && child != 0) {
- child = OS.PtWidgetBrotherInFront (child);
- i++;
- }
- OS.PtWidgetInsert (topHandle (), child, 1);
- }
- if (OS.PtWidgetIsRealized (parentHandle)) {
- OS.PtRealizeWidget (topHandle ());
- }
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- setDefaultFont ();
-}
-
-void deregister () {
- super.deregister ();
- if ((style & SWT.DROP_DOWN) != 0) {
- WidgetTable.remove (button);
- WidgetTable.remove (arrow);
- }
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- super.destroyWidget ();
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- int topHandle = topHandle ();
- PhArea_t area = new PhArea_t ();
- OS.PtWidgetArea (topHandle, area);
- int x = area.pos_x, y = area.pos_y;
- int width = area.size_w, height = area.size_h;
- /* Check if the item is scrolled */
- int child = OS.PtWidgetChildBack (parent.handle);
- if (child != 0) {
- OS.PtWidgetArea (child, area);
- x += area.pos_x;
- y += area.pos_y;
- }
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the control that is used to fill the bounds of
- * the item when the item is a <code>SEPARATOR</code>.
- *
- * @return the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget();
- return control;
-}
-
-/**
- * Returns the receiver's disabled image if it has one, or null
- * if it does not.
- * <p>
- * The disabled image is displayed when the receiver is disabled.
- * </p>
- *
- * @return the receiver's disabled image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getDisabledImage () {
- checkWidget();
- return disabledImage;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget ();
- int topHandle = topHandle ();
- return (OS.PtWidgetFlags (topHandle) & OS.Pt_BLOCKED) == 0;
-}
-
-/**
- * Returns the receiver's hot image if it has one, or null
- * if it does not.
- * <p>
- * The hot image is displayed when the mouse enters the receiver.
- * </p>
- *
- * @return the receiver's hot image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getHotImage () {
- checkWidget();
- return hotImage;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>ToolBar</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolBar getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked (which some platforms draw as a
- * pushed in button). If the receiver is of any other type, this method
- * returns false.
- * </p>
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false;
- return (OS.PtWidgetFlags (handle) & OS.Pt_SET) != 0;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget();
- int topHandle = topHandle ();
- int [] args = {OS.Pt_ARG_WIDTH, 0, 0};
- OS.PtGetResources (topHandle, args.length / 3, args);
- return args [1];
-}
-
-boolean hasFocus () {
- return OS.PtIsFocused (handle) != 0;
-}
-
-void hookEvents () {
- super.hookEvents ();
- if ((style & SWT.SEPARATOR) != 0) return;
- int windowProc = display.windowProc;
- OS.PtAddEventHandler (handle, OS.Ph_EV_BOUNDARY, windowProc, OS.Ph_EV_BOUNDARY);
- OS.PtAddCallback (button, OS.Pt_CB_ACTIVATE, windowProc, OS.Pt_CB_ACTIVATE);
- if ((style & SWT.DROP_DOWN) != 0) {
- OS.PtAddCallback (arrow, OS.Pt_CB_ACTIVATE, windowProc, OS.Pt_CB_ACTIVATE);
- }
- OS.PtAddCallback (handle, OS.Pt_CB_LOST_FOCUS, windowProc, OS.Pt_CB_LOST_FOCUS);
-}
-
-int hotkeyProc (int widget, int data, int info) {
- if (setFocus ()) click ();
- return OS.Pt_CONTINUE;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-
-int Ph_EV_BOUNDARY (int widget, int info) {
- if (info == 0) return OS.Pt_END;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.event == 0) return OS.Pt_END;
- PhEvent_t ev = new PhEvent_t ();
- OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
- switch ((int) ev.subtype) {
- case OS.Ph_EV_PTR_STEADY:
- int [] args = {OS.Pt_ARG_TEXT_FONT, 0, 0};
- OS.PtGetResources (button, args.length / 3, args);
- int length = OS.strlen (args [1]);
- byte [] font = new byte [length + 1];
- OS.memmove (font, args [1], length);
- destroyToolTip (toolTipHandle);
- toolTipHandle = createToolTip (toolTipText, button, font);
- break;
- case OS.Ph_EV_PTR_UNSTEADY:
- destroyToolTip (toolTipHandle);
- toolTipHandle = 0;
- break;
- }
- return OS.Pt_END;
-}
-
-int Pt_CB_ACTIVATE (int widget, int info) {
- Event event = new Event ();
- if (widget == arrow) {
- event.detail = SWT.ARROW;
- int topHandle = topHandle ();
- PhArea_t area = new PhArea_t ();
- OS.PtWidgetArea (topHandle, area);
- event.x = area.pos_x;
- event.y = area.pos_y + area.size_h;
- } else {
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) {
- selectRadio ();
- }
- }
- }
- postEvent (SWT.Selection, event);
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_LOST_FOCUS (int widget, int info) {
- parent.lastFocus = this;
- return OS.Pt_CONTINUE;
-}
-
-void register () {
- super.register ();
- if ((style & SWT.DROP_DOWN) != 0) {
- WidgetTable.put (button, this);
- WidgetTable.put (arrow, this);
- }
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- arrow = button = 0;
- parent = null;
-}
-
-void releaseWidget () {
- // reparent the control back to the toolbar
- if (control != null) setControl (null);
- super.releaseWidget ();
- if (toolTipHandle != 0) destroyToolTip (toolTipHandle);
- if (parent.lastFocus == this) parent.lastFocus = null;
- toolTipHandle = 0;
- control = null;
- hotImage = null;
- disabledImage = null;
- toolTipText = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-void selectRadio () {
- int index = 0;
- ToolItem [] items = parent.getItems ();
- while (index < items.length && items [index] != this) index++;
- int i = index - 1;
- while (i >= 0 && items [i].setRadioSelection (false)) --i;
- int j = index + 1;
- while (j < items.length && items [j].setRadioSelection (false)) j++;
- setSelection (true);
-}
-
-void setBackgroundPixel (int pixel) {
- OS.PtSetResource (handle, OS.Pt_ARG_FILL_COLOR, pixel, 0);
- if ((style & SWT.DROP_DOWN) != 0) {
- OS.PtSetResource (button, OS.Pt_ARG_FILL_COLOR, pixel, 0);
- OS.PtSetResource (arrow, OS.Pt_ARG_FILL_COLOR, pixel, 0);
- }
-}
-
-/**
- * Sets the control that is used to fill the bounds of
- * the item when the item is a <code>SEPARATOR</code>.
- *
- * @param control the new control
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- if ((style & SWT.SEPARATOR) == 0) return;
- Control oldControl = this.control;
- this.control = control;
- if (oldControl != null) {
- OS.PtReParentWidget(oldControl.handle, parent.parentingHandle ());
- }
- if (control != null && !control.isDisposed ()) {
- OS.PtReParentWidget(control.handle, handle);
- control.setBounds (getBounds ());
- }
-}
-
-void setDefaultFont () {
- if (display.defaultFont != null) setFont (parent.defaultFont ());
-}
-
-/**
- * Sets the receiver's disabled image to the argument, which may be
- * null indicating that no disabled image should be displayed.
- * <p>
- * The disabled image is displayed when the receiver is disabled.
- * </p>
- *
- * @param image the disabled image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDisabledImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- disabledImage = image;
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise.
- * <p>
- * A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- * </p>
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget ();
- int topHandle = topHandle ();
- int flags = enabled ? 0 : OS.Pt_BLOCKED | OS.Pt_GHOST;
- OS.PtSetResource (topHandle, OS.Pt_ARG_FLAGS, flags, OS.Pt_BLOCKED | OS.Pt_GHOST);
- if ((style & SWT.DROP_DOWN) != 0) {
- OS.PtSetResource (button, OS.Pt_ARG_FLAGS, flags, OS.Pt_BLOCKED | OS.Pt_GHOST);
- OS.PtSetResource (arrow, OS.Pt_ARG_FLAGS, flags, OS.Pt_BLOCKED | OS.Pt_GHOST);
- }
-}
-
-boolean setFocus () {
- if ((style & SWT.SEPARATOR) != 0) return false;
- int focusHandle = (style & SWT.DROP_DOWN) != 0 ? button : handle;
- /*
- * Bug in Photon. Photon will stop sending key
- * events, if a menu is up and focus is given to
- * a widget by calling PtContainerGiveFocus(). The
- * fix is to detect when a menu is up and avoid
- * calling this function.
- */
- Shell shell = parent.getShell ();
- if (shell.activeMenu != null) return false;
- OS.PtContainerGiveFocus (focusHandle, null);
- return OS.PtIsFocused(focusHandle) != 0;
-}
-
-void setFont (byte [] font) {
- int ptr = OS.malloc (font.length);
- OS.memmove (ptr, font, font.length);
- setFont (ptr);
- OS.free (ptr);
-}
-
-void setFont (int font) {
- int [] args = {
- OS.Pt_ARG_TEXT_FONT, font, 0,
- OS.Pt_ARG_LIST_FONT, font, 0,
- OS.Pt_ARG_TITLE_FONT, font, 0,
- OS.Pt_ARG_GAUGE_FONT, font, 0,
- };
- OS.PtSetResources (handle, args.length / 3, args);
- if ((style & SWT.DROP_DOWN) != 0) {
- OS.PtSetResources (button, args.length / 3, args);
- OS.PtSetResources (arrow, args.length / 3, args);
- }
-}
-
-void setForegroundPixel (int pixel) {
- OS.PtSetResource (handle, OS.Pt_ARG_COLOR, pixel, 0);
- if ((style & SWT.DROP_DOWN) != 0) {
- OS.PtSetResource (button, OS.Pt_ARG_COLOR, pixel, 0);
- OS.PtSetResource (arrow, OS.Pt_ARG_COLOR, pixel, 0);
- }
-}
-
-/**
- * Sets the receiver's hot image to the argument, which may be
- * null indicating that no hot image should be displayed.
- * <p>
- * The hot image is displayed when the mouse enters the receiver.
- * </p>
- *
- * @param image the hot image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHotImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
-
- /* TEMPORARY CODE: remove when when FLAT tool bars are implemented */
- if ((parent.style & SWT.FLAT) != 0) setImage (image);
-
- hotImage = image;
-}
-
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- super.setImage (image);
-
- /* TEMPORARY CODE: remove when when FLAT tool bars are implemented */
- if ((parent.style & SWT.FLAT) != 0 && hotImage != null) return;
-
- int imageHandle = 0;
- int type = OS.Pt_Z_STRING;
- if (image != null) {
- imageHandle = copyPhImage (image.handle);
- if(text.length() != 0) type = OS.Pt_TEXT_IMAGE;
- else type = OS.Pt_IMAGE;
- }
- int [] args = {
- OS.Pt_ARG_LABEL_IMAGE, imageHandle, 0,
- OS.Pt_ARG_LABEL_TYPE, type, 0
- };
- OS.PtSetResources (button, args.length / 3, args);
- if (imageHandle != 0) OS.free (imageHandle);
-
- /*
- * Bug on Photon. When a the text/image is set on a
- * DROP_DOWN item that is realized, the item does not resize
- * to show the new text/image. The fix is to force the item
- * to recalculate the size.
- */
- if ((style & SWT.DROP_DOWN) != 0) {
- if (OS.PtWidgetIsRealized (handle)) {
- OS.PtExtentWidget (handle);
- }
- }
-}
-
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-
-/**
- * Sets the selection state of the receiver.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked (which some platforms draw as a
- * pushed in button).
- * </p>
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return;
- OS.PtSetResource (handle, OS.Pt_ARG_FLAGS, selected ? OS.Pt_SET : 0, OS.Pt_SET);
-}
-
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- super.setText (string);
- char [] text = new char [string.length ()];
- string.getChars (0, text.length, text, 0);
- char mnemonic = fixMnemonic (text);
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- int ptr1 = OS.malloc (buffer.length);
- OS.memmove (ptr1, buffer, buffer.length);
- int ptr2 = 0;
- if (mnemonic != 0) {
- byte [] buffer2 = Converter.wcsToMbcs (null, new char []{mnemonic}, true);
- ptr2 = OS.malloc (buffer2.length);
- OS.memmove (ptr2, buffer2, buffer2.length);
- }
- replaceMnemonic (mnemonic, true, true);
- int type = OS.Pt_Z_STRING;
- if (image != null) type = OS.Pt_TEXT_IMAGE;
- int [] args = {
- OS.Pt_ARG_TEXT_STRING, ptr1, 0,
- OS.Pt_ARG_LABEL_TYPE, type, 0,
- OS.Pt_ARG_ACCEL_KEY, ptr2, 0,
- };
- OS.PtSetResources (button, args.length / 3, args);
- OS.free (ptr1);
- OS.free (ptr2);
-
- /*
- * Bug on Photon. When a the text/image is set on a
- * DROP_DOWN item that is realized, the item does not resize
- * to show the new text/image. The fix is to force the item
- * to recalculate the size.
- */
- if ((style & SWT.DROP_DOWN) != 0) {
- if (OS.PtWidgetIsRealized (handle)) {
- OS.PtExtentWidget (handle);
- }
- }
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
-}
-
-/**
- * Sets the width of the receiver, for <code>SEPARATOR</code> ToolItems.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int width) {
- checkWidget();
- if ((style & SWT.SEPARATOR) == 0) return;
- if (width < 0) return;
- int topHandle = topHandle ();
- OS.PtSetResource (topHandle, OS.Pt_ARG_WIDTH, width, 0);
- if (control != null && !control.isDisposed ()) {
- control.setBounds (getBounds ());
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Tracker.java
deleted file mode 100755
index 0ea5d78fdc..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Tracker.java
+++ /dev/null
@@ -1,1057 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class implement rubber banding rectangles that are
- * drawn onto a parent <code>Composite</code> or <code>Display</code>.
- * These rectangles can be specified to respond to mouse and key events
- * by either moving or resizing themselves accordingly. Trackers are
- * typically used to represent window geometries in a lightweight manner.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, UP, DOWN, RESIZE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Move, Resize</dd>
- * </dl>
- * <p>
- * Note: Rectangle move behavior is assumed unless RESIZE is specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tracker">Tracker snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Tracker extends Widget {
- Composite parent;
- boolean tracking, stippled;
- Rectangle [] rectangles = new Rectangle [0], proportions = rectangles;
- Rectangle bounds;
- int resizeCursor;
- Cursor clientCursor;
- int cursorOrientation = SWT.NONE;
-
- /*
- * The following values mirror step sizes on Windows
- */
- final static int STEPSIZE_SMALL = 1;
- final static int STEPSIZE_LARGE = 9;
-
-/**
- * Constructs a new instance of this class given the display
- * to create it on and a style value describing its behavior
- * and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the tracker on the currently active
- * display if there is one. If there is no current display, the
- * tracker is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the tracker on
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#RESIZE
- */
-public Tracker (Display display, int style) {
- if (display == null) display = Display.getCurrent ();
- if (display == null) display = Display.getDefault ();
- if (!display.isValidThread ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- this.style = checkStyle (style);
- this.display = display;
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#RESIZE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Tracker (Composite parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize, typedListener);
- addListener (SWT.Move, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard, by sending
- * it one of the messages defined in the <code>KeyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #removeKeyListener
- */
-public void addKeyListener (KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.KeyUp,typedListener);
- addListener (SWT.KeyDown,typedListener);
-}
-
-Point adjustMoveCursor () {
- if (bounds == null) return null;
- int newX = bounds.x + bounds.width / 2;
- int newY = bounds.y;
- /*
- * Convert to screen coordinates iff needed
- */
- if (parent != null) {
- short [] x = new short [1], y = new short [1];
- OS.PtGetAbsPosition (parent.handle, x, y);
- newX += x [0];
- newY += y [0];
- }
- OS.PhMoveCursorAbs(OS.PhInputGroup (0), newX, newY);
- return new Point (newX, newY);
-}
-
-Point adjustResizeCursor () {
- if (bounds == null) return null;
- int newX, newY;
-
- if ((cursorOrientation & SWT.LEFT) != 0) {
- newX = bounds.x;
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- newX = bounds.x + bounds.width;
- } else {
- newX = bounds.x + bounds.width / 2;
- }
-
- if ((cursorOrientation & SWT.UP) != 0) {
- newY = bounds.y;
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- newY = bounds.y + bounds.height;
- } else {
- newY = bounds.y + bounds.height / 2;
- }
-
- /*
- * Convert to screen coordinates iff needed
- */
- if (parent != null) {
- short [] x = new short [1], y = new short [1];
- OS.PtGetAbsPosition (parent.handle, x, y);
- newX += x [0];
- newY += y [0];
- }
- OS.PhMoveCursorAbs(OS.PhInputGroup (0), newX, newY);
-
- /*
- * If the client has not provided a custom cursor then determine
- * the appropriate resize cursor.
- */
- if (clientCursor == null) {
- int newCursor = 0;
- switch (cursorOrientation) {
- case SWT.UP:
- newCursor = OS.Ph_CURSOR_DRAG_TOP;
- break;
- case SWT.DOWN:
- newCursor = OS.Ph_CURSOR_DRAG_BOTTOM;
- break;
- case SWT.LEFT:
- newCursor = OS.Ph_CURSOR_DRAG_LEFT;
- break;
- case SWT.RIGHT:
- newCursor = OS.Ph_CURSOR_DRAG_RIGHT;
- break;
- case SWT.LEFT | SWT.UP:
- newCursor = OS.Ph_CURSOR_DRAG_TL;
- break;
- case SWT.RIGHT | SWT.DOWN:
- newCursor = OS.Ph_CURSOR_DRAG_BR;
- break;
- case SWT.LEFT | SWT.DOWN:
- newCursor = OS.Ph_CURSOR_DRAG_BL;
- break;
- case SWT.RIGHT | SWT.UP:
- newCursor = OS.Ph_CURSOR_DRAG_TR;
- break;
- default:
- newCursor = OS.Ph_CURSOR_MOVE;
- break;
- }
- resizeCursor = newCursor;
- }
-
- return new Point (newX, newY);
-}
-
-static int checkStyle (int style) {
- if ((style & (SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN)) == 0) {
- style |= SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN;
- }
- return style;
-}
-
-/**
- * Stops displaying the tracker rectangles. Note that this is not considered
- * to be a cancelation by the user.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void close () {
- checkWidget();
- tracking = false;
-}
-
-Rectangle computeBounds () {
- if (rectangles.length == 0) return null;
- int xMin = rectangles [0].x;
- int yMin = rectangles [0].y;
- int xMax = rectangles [0].x + rectangles [0].width;
- int yMax = rectangles [0].y + rectangles [0].height;
-
- for (int i = 1; i < rectangles.length; i++) {
- if (rectangles [i].x < xMin) xMin = rectangles [i].x;
- if (rectangles [i].y < yMin) yMin = rectangles [i].y;
- int rectRight = rectangles [i].x + rectangles [i].width;
- if (rectRight > xMax) xMax = rectRight;
- int rectBottom = rectangles [i].y + rectangles [i].height;
- if (rectBottom > yMax) yMax = rectBottom;
- }
-
- return new Rectangle (xMin, yMin, xMax - xMin, yMax - yMin);
-}
-
-Rectangle [] computeProportions (Rectangle [] rects) {
- Rectangle [] result = new Rectangle [rects.length];
- bounds = computeBounds ();
- if (bounds != null) {
- for (int i = 0; i < rects.length; i++) {
- int x = 0, y = 0, width = 0, height = 0;
- if (bounds.width != 0) {
- x = (rects [i].x - bounds.x) * 100 / bounds.width;
- width = rects [i].width * 100 / bounds.width;
- } else {
- width = 100;
- }
- if (bounds.height != 0) {
- y = (rects [i].y - bounds.y) * 100 / bounds.height;
- height = rects [i].height * 100 / bounds.height;
- } else {
- height = 100;
- }
- result [i] = new Rectangle (x, y, width, height);
- }
- }
- return result;
-}
-
-void drawRectangles (Rectangle [] rects, boolean stippled) {
- int rid = OS.Ph_DEV_RID;
- if (parent != null) rid = OS.PtWidgetRid (parent.handle);
-
- int phGC = OS.PgCreateGC (0);
- if (phGC == 0) return;
- int prevContext = OS.PgSetGC (phGC);
- OS.PgSetRegion (rid);
- OS.PgSetDrawMode (OS.Pg_DrawModeDSx);
- OS.PgSetFillColor (0xffffff);
-
- int bandWidth = 0;
- if (stippled) {
- bandWidth = 2;
- OS.PgSetFillTransPat (OS.Pg_PAT_HALF);
- }
- for (int i=0; i<rects.length; i++) {
- Rectangle r = rects [i];
- int x1 = r.x;
- int y1 = r.y;
- int x2 = r.x + r.width;
- int y2 = r.y + r.height;
- OS.PgDrawIRect(x1, y1, x2, y1 + bandWidth, OS.Pg_DRAW_FILL);
- OS.PgDrawIRect(x1, y1 + bandWidth + 1, x1 + bandWidth, y2 - bandWidth - 1, OS.Pg_DRAW_FILL);
- OS.PgDrawIRect(x2 - bandWidth, y1 + bandWidth + 1, x2, y2 - bandWidth - 1, OS.Pg_DRAW_FILL);
- OS.PgDrawIRect(x1, y2 - bandWidth, x2, y2, OS.Pg_DRAW_FILL);
- }
- OS.PgSetGC (prevContext);
- OS.PgDestroyGC (phGC);
-}
-
-/**
- * Returns the bounds that are being drawn, expressed relative to the parent
- * widget. If the parent is a <code>Display</code> then these are screen
- * coordinates.
- *
- * @return the bounds of the Rectangles being drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle [] getRectangles () {
- checkWidget();
- Rectangle [] result = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- result [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- return result;
-}
-
-/**
- * Returns <code>true</code> if the rectangles are drawn with a stippled line, <code>false</code> otherwise.
- *
- * @return the stippled effect of the rectangles
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getStippled () {
- checkWidget();
- return stippled;
-}
-
-void moveRectangles (int xChange, int yChange) {
- if (bounds == null) return;
- if (xChange < 0 && ((style & SWT.LEFT) == 0)) xChange = 0;
- if (xChange > 0 && ((style & SWT.RIGHT) == 0)) xChange = 0;
- if (yChange < 0 && ((style & SWT.UP) == 0)) yChange = 0;
- if (yChange > 0 && ((style & SWT.DOWN) == 0)) yChange = 0;
- if (xChange == 0 && yChange == 0) return;
- bounds.x += xChange; bounds.y += yChange;
- for (int i = 0; i < rectangles.length; i++) {
- rectangles [i].x += xChange;
- rectangles [i].y += yChange;
- }
-}
-
-/**
- * Displays the Tracker rectangles for manipulation by the user. Returns when
- * the user has either finished manipulating the rectangles or has cancelled the
- * Tracker.
- *
- * @return <code>true</code> if the user did not cancel the Tracker, <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean open () {
- checkWidget();
-
- int input_group = OS.PhInputGroup (0);
- PhCursorInfo_t info = new PhCursorInfo_t ();
- OS.PhQueryCursor ((short)input_group, info);
-
- if ((style & SWT.MENU) == 0) {
- /*
- * This code is intentionally commented. Tracking can happen through
- * the keyboard.
- */
-// if ((info.button_state & OS.Ph_BUTTON_SELECT) == 0) return false;
- }
-
- int region = 0;
- if (info.dragger == 0) {
- PhRect_t rect = new PhRect_t ();
- OS.PhWindowQueryVisible (OS.Ph_QUERY_CONSOLE, 0, OS.PhInputGroup (0), rect);
- int sense = OS.Ph_EV_DRAG | OS.Ph_EV_KEY | OS.Ph_EV_BUT_PRESS |
- OS.Ph_EV_BUT_RELEASE | OS.Ph_EV_PTR_MOTION;
- int [] args = {
- OS.Pt_ARG_WIDTH, rect.lr_x - rect.ul_x + 1, 0,
- OS.Pt_ARG_HEIGHT, rect.lr_y - rect.ul_y + 1, 0,
- OS.Pt_ARG_REGION_OPAQUE, 0, ~0,
- OS.Pt_ARG_REGION_SENSE, sense, ~0,
- OS.Pt_ARG_REGION_FLAGS, OS.Ph_FORCE_BOUNDARY, OS.Ph_FORCE_BOUNDARY,
- OS.Pt_ARG_FILL_COLOR, OS.Pg_TRANSPARENT, 0,
- };
- region = OS.PtCreateWidget (OS.PtRegion (), OS.Pt_NO_PARENT, args.length / 3, args);
- OS.PtRealizeWidget (region);
-
- rect = new PhRect_t ();
- int rid = OS.PtWidgetRid (region);
- OS.PhInitDrag (rid, OS.Ph_DRAG_KEY_MOTION | OS.Ph_TRACK_DRAG, rect, null, input_group, null, null, null, null, null);
- }
-
- int oldX = info.pos_x, oldY = info.pos_y;
- int size = PhEvent_t.sizeof + 1024;
- int buffer = OS.malloc (size);
- PhEvent_t phEvent = new PhEvent_t ();
- Event event = new Event ();
-
- // if exactly one of UP/DOWN is specified as a style then set the cursor
- // orientation accordingly (the same is done for LEFT/RIGHT styles below)
- int vStyle = style & (SWT.UP | SWT.DOWN);
- if (vStyle == SWT.UP || vStyle == SWT.DOWN) {
- cursorOrientation |= vStyle;
- }
- int hStyle = style & (SWT.LEFT | SWT.RIGHT);
- if (hStyle == SWT.LEFT || hStyle == SWT.RIGHT) {
- cursorOrientation |= hStyle;
- }
-
- update ();
- drawRectangles (rectangles, stippled);
- Point cursorPos = null;
- if ((style & SWT.MENU) == 0) {
- oldX = info.pos_x;
- oldY = info.pos_y;
- } else {
- if ((style & SWT.RESIZE) != 0) {
- cursorPos = adjustResizeCursor ();
- } else {
- cursorPos = adjustMoveCursor ();
- }
- if (cursorPos != null) {
- oldX = cursorPos.x;
- oldY = cursorPos.y;
- }
- }
-
- tracking = true;
- boolean cancelled = false;
- while (tracking && !cancelled) {
- if (parent != null && parent.isDisposed ()) break;
- int result = OS.PhEventNext (buffer, size);
- switch (result) {
- case OS.Ph_EVENT_MSG: break;
- case OS.Ph_RESIZE_MSG:
- size = OS.PhGetMsgSize (buffer);
- OS.free (buffer);
- buffer = OS.malloc (size);
- continue;
- }
- OS.memmove (phEvent, buffer, PhEvent_t.sizeof);
- if (phEvent.type == OS.Ph_EV_DRAG) {
- switch (phEvent.subtype) {
- case OS.Ph_EV_DRAG_MOTION_EVENT: {
- int data = OS.PhGetData (buffer);
- if (data == 0) break;
- PhPointerEvent_t pe = new PhPointerEvent_t ();
- OS.memmove (pe, data, PhPointerEvent_t.sizeof);
- int newX = pe.pos_x;
- int newY = pe.pos_y;
- if (newX != oldX || newY != oldY) {
- Rectangle [] oldRectangles = rectangles;
- boolean oldStippled = stippled;
- Rectangle [] rectsToErase = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- rectsToErase [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- event.x = newX;
- event.y = newY;
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (newX - oldX, newY - oldY);
- sendEvent (SWT.Resize, event);
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the move
- * event. If this happens, return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- break;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the resize event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (rectsToErase, oldStippled);
- update ();
- drawRectangles (rectangles, stippled);
- }
- cursorPos = adjustResizeCursor ();
- if (cursorPos != null) {
- newX = cursorPos.x;
- newY = cursorPos.y;
- }
- } else {
- moveRectangles (newX - oldX, newY - oldY);
- sendEvent (SWT.Move, event);
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the move
- * event. If this happens, return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- break;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the move event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (rectsToErase, oldStippled);
- update ();
- drawRectangles (rectangles, stippled);
- }
- }
- oldX = newX; oldY = newY;
- }
- break;
- }
- case OS.Ph_EV_DRAG_KEY_EVENT: {
- int data = OS.PhGetData (buffer);
- if (data == 0) break;
- PhKeyEvent_t ke = new PhKeyEvent_t ();
- OS.memmove (ke, data, PhKeyEvent_t.sizeof);
- if ((ke.key_flags & OS.Pk_KF_Sym_Valid) != 0) {
- int stepSize = (ke.key_mods & OS.Pk_KM_Ctrl) != 0 ? STEPSIZE_SMALL : STEPSIZE_LARGE;
- int xChange = 0, yChange = 0;
- switch (ke.key_sym) {
- case OS.Pk_Escape:
- cancelled = true;
- tracking = false;
- break;
- case OS.Pk_Return:
- tracking = false;
- break;
- case OS.Pk_Left:
- xChange = -stepSize;
- break;
- case OS.Pk_Right:
- xChange = stepSize;
- break;
- case OS.Pk_Up:
- yChange = -stepSize;
- break;
- case OS.Pk_Down:
- yChange = stepSize;
- break;
- }
- if (xChange != 0 || yChange != 0) {
- Rectangle [] oldRectangles = rectangles;
- boolean oldStippled = stippled;
- Rectangle [] rectsToErase = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- rectsToErase [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- int newX = oldX + xChange;
- int newY = oldY + yChange;
- event.x = newX;
- event.y = newY;
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (xChange, yChange);
- sendEvent (SWT.Resize, event);
- /*
- * It is possible (but unlikely) that application
- * code could have disposed the widget in the move
- * event. If this happens return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- break;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the resize event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (rectsToErase, oldStippled);
- update ();
- drawRectangles (rectangles, stippled);
- }
- cursorPos = adjustResizeCursor ();
- } else {
- moveRectangles (xChange, yChange);
- sendEvent (SWT.Move, event);
- /*
- * It is possible (but unlikely) that application
- * code could have disposed the widget in the move
- * event. If this happens return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- break;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the move event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (rectsToErase, oldStippled);
- update ();
- drawRectangles (rectangles, stippled);
- }
- cursorPos = adjustMoveCursor ();
- }
- if (cursorPos != null) {
- oldX = cursorPos.x;
- oldY = cursorPos.y;
- }
- }
- }
- break;
- }
- case OS.Ph_EV_DRAG_COMPLETE: {
- tracking = false;
- break;
- }
- }
- if (phEvent.collector_handle != 0) {
- setCursor (phEvent.collector_handle);
- }
- /*
- * Don't dispatch mouse and key events in general, EXCEPT once this
- * tracker has finished its work.
- */
- if (tracking && !cancelled) continue;
-
- }
- OS.PtEventHandler (buffer);
- }
- OS.free (buffer);
- if (!isDisposed ()) {
- update ();
- drawRectangles (rectangles, stippled);
- }
- tracking = false;
- if (region != 0) OS.PtDestroyWidget (region);
- return !cancelled;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
- rectangles = proportions = null;
- bounds = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Resize, listener);
- eventTable.unhook (SWT.Move, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #addKeyListener
- */
-public void removeKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.KeyUp, listener);
- eventTable.unhook (SWT.KeyDown, listener);
-}
-
-void resizeRectangles (int xChange, int yChange) {
- if (bounds == null) return;
- /*
- * If the cursor orientation has not been set in the orientation of
- * this change then try to set it here.
- */
- if (xChange < 0 && ((style & SWT.LEFT) != 0) && ((cursorOrientation & SWT.RIGHT) == 0)) {
- cursorOrientation |= SWT.LEFT;
- }
- if (xChange > 0 && ((style & SWT.RIGHT) != 0) && ((cursorOrientation & SWT.LEFT) == 0)) {
- cursorOrientation |= SWT.RIGHT;
- }
- if (yChange < 0 && ((style & SWT.UP) != 0) && ((cursorOrientation & SWT.DOWN) == 0)) {
- cursorOrientation |= SWT.UP;
- }
- if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) {
- cursorOrientation |= SWT.DOWN;
- }
-
- /*
- * If the bounds will flip about the x or y axis then apply the adjustment
- * up to the axis (ie.- where bounds width/height becomes 0), change the
- * cursor's orientation accordingly, and flip each Rectangle's origin (only
- * necessary for > 1 Rectangles)
- */
- if ((cursorOrientation & SWT.LEFT) != 0) {
- if (xChange > bounds.width) {
- if ((style & SWT.RIGHT) == 0) return;
- cursorOrientation |= SWT.RIGHT;
- cursorOrientation &= ~SWT.LEFT;
- bounds.x += bounds.width;
- xChange -= bounds.width;
- bounds.width = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.x = 100 - proportion.x - proportion.width;
- }
- }
- }
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- if (bounds.width < -xChange) {
- if ((style & SWT.LEFT) == 0) return;
- cursorOrientation |= SWT.LEFT;
- cursorOrientation &= ~SWT.RIGHT;
- xChange += bounds.width;
- bounds.width = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.x = 100 - proportion.x - proportion.width;
- }
- }
- }
- }
- if ((cursorOrientation & SWT.UP) != 0) {
- if (yChange > bounds.height) {
- if ((style & SWT.DOWN) == 0) return;
- cursorOrientation |= SWT.DOWN;
- cursorOrientation &= ~SWT.UP;
- bounds.y += bounds.height;
- yChange -= bounds.height;
- bounds.height = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.y = 100 - proportion.y - proportion.height;
- }
- }
- }
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- if (bounds.height < -yChange) {
- if ((style & SWT.UP) == 0) return;
- cursorOrientation |= SWT.UP;
- cursorOrientation &= ~SWT.DOWN;
- yChange += bounds.height;
- bounds.height = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.y = 100 - proportion.y - proportion.height;
- }
- }
- }
- }
-
- // apply the bounds adjustment
- if ((cursorOrientation & SWT.LEFT) != 0) {
- bounds.x += xChange;
- bounds.width -= xChange;
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- bounds.width += xChange;
- }
- if ((cursorOrientation & SWT.UP) != 0) {
- bounds.y += yChange;
- bounds.height -= yChange;
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- bounds.height += yChange;
- }
-
- Rectangle [] newRects = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle proportion = proportions[i];
- newRects[i] = new Rectangle (
- proportion.x * bounds.width / 100 + bounds.x,
- proportion.y * bounds.height / 100 + bounds.y,
- proportion.width * bounds.width / 100,
- proportion.height * bounds.height / 100);
- }
- rectangles = newRects;
-}
-
-/**
- * Sets the <code>Cursor</code> of the Tracker. If this cursor is <code>null</code>
- * then the cursor reverts to the default.
- *
- * @param newCursor the new <code>Cursor</code> to display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCursor (Cursor cursor) {
- checkWidget();
- if (cursor != null && cursor.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- clientCursor = cursor;
-}
-
-void setCursor (int cursorHandle) {
- if (cursorHandle == 0) return;
- int type = 0;
- int bitmap = 0;
- if (clientCursor != null) {
- type = clientCursor.type;
- bitmap = clientCursor.bitmap;
- } else if (resizeCursor != 0) {
- type = resizeCursor;
- }
- int [] args = new int []{
- OS.Pt_ARG_CURSOR_TYPE, type, 0,
- OS.Pt_ARG_BITMAP_CURSOR, bitmap, 0,
- };
- OS.PtSetResources (cursorHandle, args.length / 3, args);
-
- /*
- * Bug in Photon. For some reason, the widget cursor will
- * not change, when the new cursor is a bitmap cursor, if
- * the flag Ph_CURSOR_NO_INHERIT is reset. The fix is to reset
- * this flag after changing the cursor type to Ph_CURSOR_BITMAP.
- */
- if (type == OS.Ph_CURSOR_BITMAP) {
- type &= ~OS.Ph_CURSOR_NO_INHERIT;
- OS.PtSetResource (cursorHandle, OS.Pt_ARG_CURSOR_TYPE, type, 0);
- }
-}
-
-/**
- * Specifies the rectangles that should be drawn, expressed relative to the parent
- * widget. If the parent is a Display then these are screen coordinates.
- *
- * @param rectangles the bounds of the rectangles to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of rectangles is null or contains a null rectangle</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setRectangles (Rectangle [] rectangles) {
- checkWidget();
- if (rectangles == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.rectangles = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- if (current == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.rectangles [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- proportions = computeProportions (rectangles);
-}
-
-/**
- * Changes the appearance of the line used to draw the rectangles.
- *
- * @param stippled <code>true</code> if rectangle should appear stippled
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setStippled (boolean stippled) {
- checkWidget();
- this.stippled = stippled;
-}
-
-void update () {
- if (parent != null) {
- if (parent.isDisposed ()) return;
- parent.getShell ().update ();
- } else {
- display.update ();
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Widget.java
deleted file mode 100755
index 19b0c5f24a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Widget.java
+++ /dev/null
@@ -1,1274 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
-/**
- * This class is the abstract superclass of all user interface objects.
- * Widgets are created, disposed and issue notification to listeners
- * when events occur which affect them.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Dispose</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation. However, it has not been marked
- * final to allow those outside of the SWT development team to implement
- * patched versions of the class in order to get around specific
- * limitations in advance of when those limitations can be addressed
- * by the team. Any class built using subclassing to access the internals
- * of this class will likely fail to compile or run between releases and
- * may be strongly platform specific. Subclassing should not be attempted
- * without an intimate and detailed understanding of the workings of the
- * hierarchy. No support is provided for user-written classes which are
- * implemented as subclasses of this class.
- * </p>
- *
- * @see #checkSubclass
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class Widget {
- /**
- * the handle to the resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
- int style, state;
- Display display;
- EventTable eventTable;
- Object data;
-
- /* Global state flags */
- static final int DISPOSED = 1 << 0;
- static final int CANVAS = 1 << 1;
- static final int KEYED_DATA = 1 << 2;
- static final int HANDLE = 1 << 3;
- static final int DISABLED = 1 << 4;
- static final int MOVED = 1 << 5;
- static final int RESIZED = 1 << 6;
- static final int GRAB = 1 << 7;
-
- /* A layout was requested on this widget */
- static final int LAYOUT_NEEDED = 1 << 8;
-
- /* The preferred size of a child has changed */
- static final int LAYOUT_CHANGED = 1 << 9;
-
- /* A layout was requested in this widget hierachy */
- static final int LAYOUT_CHILD = 1 << 10;
-
- /* More global state flags */
- static final int RELEASED = 1<<11;
- static final int DISPOSE_SENT = 1<<12;
-
- /* Default size for widgets */
- static final int DEFAULT_WIDTH = 64;
- static final int DEFAULT_HEIGHT = 64;
-
-Widget () {
- /* Do nothing */
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see #checkSubclass
- * @see #getStyle
- */
-public Widget (Widget parent, int style) {
- checkSubclass ();
- checkParent (parent);
- this.style = style;
- display = parent.display;
-}
-
-static int checkBits (int style, int int0, int int1, int int2, int int3, int int4, int int5) {
- int mask = int0 | int1 | int2 | int3 | int4 | int5;
- if ((style & mask) == 0) style |= int0;
- if ((style & int0) != 0) style = (style & ~mask) | int0;
- if ((style & int1) != 0) style = (style & ~mask) | int1;
- if ((style & int2) != 0) style = (style & ~mask) | int2;
- if ((style & int3) != 0) style = (style & ~mask) | int3;
- if ((style & int4) != 0) style = (style & ~mask) | int4;
- if ((style & int5) != 0) style = (style & ~mask) | int5;
- return style;
-}
-
-void checkOrientation (Widget parent) {
- style &= ~SWT.MIRRORED;
- if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) {
- if (parent != null) {
- if ((parent.style & SWT.LEFT_TO_RIGHT) != 0) style |= SWT.LEFT_TO_RIGHT;
- if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) style |= SWT.RIGHT_TO_LEFT;
- }
- }
- style = checkBits (style, SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT, 0, 0, 0, 0);
-}
-
-void checkParent (Widget parent) {
- if (parent == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (parent.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- parent.checkWidget ();
-}
-
-/**
- * Checks that this class can be subclassed.
- * <p>
- * The SWT class library is intended to be subclassed
- * only at specific, controlled points (most notably,
- * <code>Composite</code> and <code>Canvas</code> when
- * implementing new widgets). This method enforces this
- * rule unless it is overridden.
- * </p><p>
- * <em>IMPORTANT:</em> By providing an implementation of this
- * method that allows a subclass of a class which does not
- * normally allow subclassing to be created, the implementer
- * agrees to be fully responsible for the fact that any such
- * subclass will likely fail between SWT releases and will be
- * strongly platform specific. No support is provided for
- * user-written classes which are implemented in this fashion.
- * </p><p>
- * The ability to subclass outside of the allowed SWT classes
- * is intended purely to enable those not on the SWT development
- * team to implement patches in order to get around specific
- * limitations in advance of when those limitations can be
- * addressed by the team. Subclassing should not be attempted
- * without an intimate and detailed understanding of the hierarchy.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Throws an <code>SWTException</code> if the receiver can not
- * be accessed by the caller. This may include both checks on
- * the state of the receiver and more generally on the entire
- * execution context. This method <em>should</em> be called by
- * widget implementors to enforce the standard SWT invariants.
- * <p>
- * Currently, it is an error to invoke any method (other than
- * <code>isDisposed()</code>) on a widget that has had its
- * <code>dispose()</code> method called. It is also an error
- * to call widget methods from any thread that is different
- * from the thread that created the widget.
- * </p><p>
- * In future releases of SWT, there may be more or fewer error
- * checks and exceptions may be thrown for different reasons.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-protected void checkWidget () {
- Display display = this.display;
- if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
- if (display.thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if ((state & DISPOSED) != 0) error (SWT.ERROR_WIDGET_DISPOSED);
-}
-
-int copyPhImage(int image) {
- if (image == 0) return 0;
- int newImage = OS.PiDuplicateImage (image, 0);
-
- /*
- * Bug in Photon. The image returned by PiDuplicateImage might
- * have the same mask_bm/alpha as the original image. The fix
- * is to detect this case and copy mask_bm/alpha if necessary.
- */
- PhImage_t phImage = new PhImage_t();
- OS.memmove (phImage, image, PhImage_t.sizeof);
- PhImage_t newPhImage = new PhImage_t();
- OS.memmove(newPhImage, newImage, PhImage_t.sizeof);
- if (newPhImage.mask_bm != 0 && phImage.mask_bm == newPhImage.mask_bm) {
- int length = newPhImage.mask_bpl * newPhImage.size_h;
- int ptr = OS.malloc(length);
- OS.memmove(ptr, newPhImage.mask_bm, length);
- newPhImage.mask_bm = ptr;
- }
- if (newPhImage.alpha != 0 && phImage.alpha == newPhImage.alpha) {
- PgAlpha_t alpha = new PgAlpha_t();
- OS.memmove(alpha, phImage.alpha, PgAlpha_t.sizeof);
- if (alpha.src_alpha_map_map != 0) {
- int length = alpha.src_alpha_map_bpl * alpha.src_alpha_map_dim_h;
- int ptr = OS.malloc(length);
- OS.memmove(ptr, alpha.src_alpha_map_map, length);
- alpha.src_alpha_map_map = ptr;
- }
- int ptr = OS.malloc(PgAlpha_t.sizeof);
- OS.memmove(ptr, alpha, PgAlpha_t.sizeof);
- newPhImage.alpha = ptr;
- }
- OS.memmove(newImage, newPhImage, PhImage_t.sizeof);
- return newImage;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs. When the
- * event does occur in the widget, the listener is notified by
- * sending it the <code>handleEvent()</code> message. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #getListeners(int)
- * @see #removeListener(int, Listener)
- * @see #notifyListeners
- */
-public void addListener (int eventType, Listener handler) {
- checkWidget();
- if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) eventTable = new EventTable ();
- eventTable.hook (eventType, handler);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the widget is disposed. When the widget is
- * disposed, the listener is notified by sending it the
- * <code>widgetDisposed()</code> message.
- *
- * @param listener the listener which should be notified when the receiver is disposed
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DisposeListener
- * @see #removeDisposeListener
- */
-public void addDisposeListener (DisposeListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Dispose, typedListener);
-}
-
-void click (int widget) {
- int rid = OS.PtWidgetRid (widget);
- if (rid == 0) return;
- PhEvent_t event = new PhEvent_t ();
- event.emitter_rid = rid;
- event.emitter_handle = widget;
- event.collector_rid = rid;
- event.collector_handle = widget;
- event.flags = (short) OS.Ph_EVENT_DIRECT;
- event.processing_flags = (short) OS.Ph_FAKE_EVENT;
- event.type = OS.Ph_EV_BUT_PRESS;
- event.num_rects = 1;
- PhPointerEvent_t pe = new PhPointerEvent_t ();
- pe.click_count = 1;
- pe.buttons = (short) OS.Ph_BUTTON_SELECT;
- PhRect_t rect = new PhRect_t ();
- int ptr = OS.malloc (PhEvent_t.sizeof + PhPointerEvent_t.sizeof + PhRect_t.sizeof);
- OS.memmove (ptr, event, PhEvent_t.sizeof);
- OS.memmove (ptr + PhEvent_t.sizeof, rect, PhRect_t.sizeof);
- OS.memmove (ptr + PhEvent_t.sizeof + PhRect_t.sizeof, pe, PhPointerEvent_t.sizeof);
- OS.PtSendEventToWidget (widget, ptr);
- OS.PtFlush ();
- event.type = OS.Ph_EV_BUT_RELEASE;
- event.subtype = (short) OS.Ph_EV_RELEASE_REAL;
- OS.memmove (ptr, event, PhEvent_t.sizeof);
- OS.memmove (ptr + PhEvent_t.sizeof, rect, PhRect_t.sizeof);
- OS.memmove (ptr + PhEvent_t.sizeof + PhRect_t.sizeof, pe, PhPointerEvent_t.sizeof);
- OS.PtSendEventToWidget (widget, ptr);
- OS.free (ptr);
-}
-
-void createHandle (int index) {
- /* Do nothing */
-}
-
-int createToolTip (String string, int handle, byte [] font) {
- if (string == null || string.length () == 0 || handle == 0) {
- return 0;
- }
-
- int shellHandle = OS.PtFindDisjoint (handle);
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- int fill = display.INFO_BACKGROUND;
- int text_color = display.INFO_FOREGROUND;
- int toolTipHandle = OS.PtInflateBalloon (shellHandle, handle, OS.Pt_BALLOON_RIGHT, buffer, font, fill, text_color);
-
- /*
- * Feature in Photon. The position of the inflated balloon
- * is relative to the widget position and not to the cursor
- * position. The fix is to re-position the balloon.
- */
- int ig = OS.PhInputGroup (0);
- PhCursorInfo_t info = new PhCursorInfo_t ();
- OS.PhQueryCursor ((short)ig, info);
- short [] absX = new short [1], absY = new short [1];
- OS.PtGetAbsPosition (shellHandle, absX, absY);
- int x = info.pos_x - absX [0] + 16;
- int y = info.pos_y - absY [0] + 16;
- PhArea_t shellArea = new PhArea_t ();
- OS.PtWidgetArea (shellHandle, shellArea);
- PhArea_t toolTipArea = new PhArea_t ();
- OS.PtWidgetArea (toolTipHandle, toolTipArea);
- x = Math.max (0, Math.min (x, shellArea.size_w - toolTipArea.size_w));
- y = Math.max (0, Math.min (y, shellArea.size_h - toolTipArea.size_h));
- PhPoint_t pt = new PhPoint_t ();
- pt.x = (short) x;
- pt.y = (short) y;
- int ptr = OS.malloc (PhPoint_t.sizeof);
- OS.memmove (ptr, pt, PhPoint_t.sizeof);
- OS.PtSetResource (toolTipHandle, OS.Pt_ARG_POS, ptr, 0);
- OS.free (ptr);
-
- return toolTipHandle;
-}
-
-void createWidget (int index) {
- createHandle (index);
- hookEvents ();
- register ();
-}
-
-void deregister () {
- if (handle == 0) return;
- WidgetTable.remove (handle);
-}
-
-void destroyToolTip (int toolTipHandle) {
- if (toolTipHandle != 0) OS.PtDestroyWidget (toolTipHandle);
-}
-
-void destroyWidget () {
- int topHandle = topHandle ();
- releaseHandle ();
- if (topHandle != 0) {
- OS.PtDestroyWidget (topHandle);
- }
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the receiver and all its descendants. After this method has
- * been invoked, the receiver and all descendants will answer
- * <code>true</code> when sent the message <code>isDisposed()</code>.
- * Any internal connections between the widgets in the tree will
- * have been removed to facilitate garbage collection.
- * <p>
- * NOTE: This method is not called recursively on the descendants
- * of the receiver. This means that, widget implementers can not
- * detect when a widget is being disposed of by re-implementing
- * this method, but should instead listen for the <code>Dispose</code>
- * event.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #addDisposeListener
- * @see #removeDisposeListener
- * @see #checkWidget
- */
-public void dispose () {
- /*
- * Note: It is valid to attempt to dispose a widget
- * more than once. If this happens, fail silently.
- */
- if (isDisposed ()) return;
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- release (true);
-}
-
-int drawProc (int widget, int damage) {
- return OS.Pt_CONTINUE;
-}
-
-static void error (int code) {
- SWT.error(code);
-}
-
-boolean filters (int eventType) {
- return display.filters (eventType);
-}
-
-char fixMnemonic (char [] buffer) {
- int i=0, j=0;
- char mnemonic=0;
- while (i < buffer.length) {
- if ((buffer [j++] = buffer [i++]) == '&') {
- if (i == buffer.length) {continue;}
- if (buffer [i] == '&') {i++; continue;}
- if (mnemonic == 0) mnemonic = buffer [i];
- j--;
- }
- }
- while (j < buffer.length) buffer [j++] = 0;
- return mnemonic;
-}
-
-/**
- * Returns the application defined widget data associated
- * with the receiver, or null if it has not been set. The
- * <em>widget data</em> is a single, unnamed field that is
- * stored with every widget.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the widget data needs to be notified
- * when the widget is disposed of, it is the application's
- * responsibility to hook the Dispose event on the widget and
- * do so.
- * </p>
- *
- * @return the widget data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
- * </ul>
- *
- * @see #setData(Object)
- */
-public Object getData () {
- checkWidget();
- return (state & KEYED_DATA) != 0 ? ((Object []) data) [0] : data;
-}
-
-/**
- * Returns the application defined property of the receiver
- * with the specified name, or null if it has not been set.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the widget is disposed
- * of, it is the application's responsibility to hook the
- * Dispose event on the widget and do so.
- * </p>
- *
- * @param key the name of the property
- * @return the value of the property or null if it has not been set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setData(String, Object)
- */
-public Object getData (String key) {
- checkWidget();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((state & KEYED_DATA) != 0) {
- Object [] table = (Object []) data;
- for (int i=1; i<table.length; i+=2) {
- if (key.equals (table [i])) return table [i+1];
- }
- }
- return null;
-}
-
-/**
- * Returns the <code>Display</code> that is associated with
- * the receiver.
- * <p>
- * A widget's display is either provided when it is created
- * (for example, top level <code>Shell</code>s) or is the
- * same as its parent's display.
- * </p>
- *
- * @return the receiver's display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Display getDisplay () {
- Display display = this.display;
- if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return display;
-}
-
-/**
- * Returns an array of listeners who will be notified when an event
- * of the given type occurs. The event type is one of the event constants
- * defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @return an array of listeners that will be notified when the event occurs
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener(int, Listener)
- * @see #removeListener(int, Listener)
- * @see #notifyListeners
- *
- * @since 3.4
- */
-public Listener[] getListeners (int eventType) {
- checkWidget();
- if (eventTable == null) return new Listener[0];
- return eventTable.getListeners(eventType);
-}
-
-String getName () {
- String string = getClass ().getName ();
- int index = string.length ();
- while (--index > 0 && string.charAt (index) != '.') {/* empty */}
- return string.substring (index + 1, string.length ());
-}
-
-String getNameText () {
- return "";
-}
-
-/**
- * Returns the receiver's style information.
- * <p>
- * Note that the value which is returned by this method <em>may
- * not match</em> the value which was provided to the constructor
- * when the receiver was created. This can occur when the underlying
- * operating system does not support a particular combination of
- * requested styles. For example, if the platform widget used to
- * implement a particular SWT widget always has scroll bars, the
- * result of calling this method would always have the
- * <code>SWT.H_SCROLL</code> and <code>SWT.V_SCROLL</code> bits set.
- * </p>
- *
- * @return the style bits
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getStyle () {
- checkWidget();
- return style;
-}
-
-boolean hooks (int eventType) {
- if (eventTable == null) return false;
- return eventTable.hooks (eventType);
-}
-
-int hotkeyProc (int widget, int data, int info) {
- return OS.Pt_CONTINUE;
-}
-
-void hookEvents () {
- /* Do nothing */
-}
-
-/**
- * Returns <code>true</code> if the widget has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the widget.
- * When a widget has been disposed, it is an error to
- * invoke any other method using the widget.
- * </p>
- *
- * @return <code>true</code> when the widget is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- if (handle != 0) return false;
- if ((state & HANDLE) != 0) return true;
- return (state & DISPOSED) != 0;
-}
-
-boolean isValidSubclass () {
- return Display.isValidClass (getClass ());
-}
-
-/**
- * Returns <code>true</code> if there are any listeners
- * for the specified event type associated with the receiver,
- * and <code>false</code> otherwise. The event type is one of
- * the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event
- * @return true if the event is hooked
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public boolean isListening (int eventType) {
- checkWidget();
- return hooks (eventType);
-}
-
-boolean isValidThread () {
- return getDisplay ().isValidThread ();
-}
-
-/**
- * Notifies all of the receiver's listeners for events
- * of the given type that one such event has occurred by
- * invoking their <code>handleEvent()</code> method. The
- * event type is one of the event constants defined in class
- * <code>SWT</code>.
- *
- * @param eventType the type of event which has occurred
- * @param event the event data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- * @see #addListener
- * @see #getListeners(int)
- * @see #removeListener(int, Listener)
- */
-public void notifyListeners (int eventType, Event event) {
- checkWidget();
- if (event == null) event = new Event ();
- sendEvent (eventType, event);
-}
-
-void postEvent (int eventType) {
- sendEvent (eventType, null, false);
-}
-
-void postEvent (int eventType, Event event) {
- sendEvent (eventType, event, false);
-}
-
-int Ph_EV_BOUNDARY (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Ph_EV_BUT_PRESS (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Ph_EV_BUT_RELEASE (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Ph_EV_DRAG (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Ph_EV_KEY (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Ph_EV_PTR_MOTION (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_ACTIVATE (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_ARM (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_GOT_FOCUS (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_LOST_FOCUS (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_MODIFY_VERIFY (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_NUMERIC_CHANGED (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_OUTBOUND (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_PG_PANEL_SWITCHING (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_REALIZED (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_RESIZE (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_SCROLL_MOVE (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_SLIDER_MOVE (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_SELECTION (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_TEXT_CHANGED (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_TIMER_ACTIVATE (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_UNREALIZED (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-int Pt_CB_WINDOW (int widget, int info) {
- return OS.Pt_CONTINUE;
-}
-
-
-void register () {
- if (handle == 0) return;
- WidgetTable.put (handle, this);
-}
-
-void release (boolean destroy) {
- if ((state & DISPOSE_SENT) == 0) {
- state |= DISPOSE_SENT;
- sendEvent (SWT.Dispose);
- }
- if ((state & DISPOSED) == 0) {
- releaseChildren (destroy);
- }
- if ((state & RELEASED) == 0) {
- state |= RELEASED;
- if (destroy) {
- releaseParent ();
- releaseWidget ();
- destroyWidget ();
- } else {
- releaseWidget ();
- releaseHandle ();
- }
- }
-}
-
-void releaseChildren (boolean destroy) {
-}
-
-void releaseHandle () {
- handle = 0;
- state |= DISPOSED;
- display = null;
-}
-
-void releaseParent () {
- /* Do nothing */
-}
-
-void releaseWidget () {
- deregister ();
- eventTable = null;
- data = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener
- * @see #getListeners(int)
- * @see #notifyListeners
- */
-public void removeListener (int eventType, Listener handler) {
- checkWidget();
- if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, handler);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It should never be
- * referenced from application code.
- * </p>
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see #addListener
- */
-protected void removeListener (int eventType, SWTEventListener handler) {
- checkWidget();
- if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, handler);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the widget is disposed.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DisposeListener
- * @see #addDisposeListener
- */
-public void removeDisposeListener (DisposeListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Dispose, listener);
-}
-
-void replaceMnemonic (int mnemonic, boolean normal, boolean alt) {
- int [] args = {OS.Pt_ARG_ACCEL_KEY, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- if (args [1] != 0) {
- int length = OS.strlen (args [1]);
- if (length > 0) {
- byte [] buffer = new byte [length];
- OS.memmove (buffer, args [1], length);
- char [] accelText = Converter.mbcsToWcs (null, buffer);
- if (accelText.length > 0) {
- char key = Character.toLowerCase (accelText [0]);
- if (normal) {
- //TEMPORARY CODE
-// OS.PtRemoveHotkeyHandler (handle, key, 0, (short)0, handle, display.hotkeyProc);
- }
- if (alt) {
- OS.PtRemoveHotkeyHandler (handle, key, OS.Pk_KM_Alt, (short)0, handle, display.hotkeyProc);
- }
- }
- }
- }
- if (mnemonic == 0) return;
- char key = Character.toLowerCase ((char)mnemonic);
- if (normal) {
- //TEMPORARY CODE
-// OS.PtAddHotkeyHandler (handle, key, 0, (short)0, SWT.Activate, display.windowProc);
- }
- if (alt) {
- OS.PtAddHotkeyHandler (handle, key, OS.Pk_KM_Alt, (short)0, handle, display.hotkeyProc);
- }
-}
-
-void sendEvent (Event event) {
- Display display = event.display;
- if (!display.filterEvent (event)) {
- if (eventTable != null) eventTable.sendEvent (event);
- }
-}
-
-void sendEvent (int eventType) {
- sendEvent (eventType, null, true);
-}
-
-void sendEvent (int eventType, Event event) {
- sendEvent (eventType, event, true);
-}
-
-void sendEvent (int eventType, Event event, boolean send) {
- if (eventTable == null && !display.filters (eventType)) {
- return;
- }
- if (event == null) event = new Event ();
- event.type = eventType;
- event.display = display;
- event.widget = this;
- if (event.time == 0) {
- event.time = display.getLastEventTime ();
- }
- if (send) {
- sendEvent (event);
- } else {
- display.postEvent (event);
- }
-}
-
-/**
- * Sets the application defined widget data associated
- * with the receiver to be the argument. The <em>widget
- * data</em> is a single, unnamed field that is stored
- * with every widget.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the widget data needs to be notified
- * when the widget is disposed of, it is the application's
- * responsibility to hook the Dispose event on the widget and
- * do so.
- * </p>
- *
- * @param data the widget data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
- * </ul>
- *
- * @see #getData()
- */
-public void setData (Object data) {
- checkWidget();
- if ((state & KEYED_DATA) != 0) {
- ((Object []) this.data) [0] = data;
- } else {
- this.data = data;
- }
-}
-
-/**
- * Sets the application defined property of the receiver
- * with the specified name to the given value.
- * <p>
- * Applications may associate arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the widget is disposed
- * of, it is the application's responsibility to hook the
- * Dispose event on the widget and do so.
- * </p>
- *
- * @param key the name of the property
- * @param value the new value for the property
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getData(String)
- */
-public void setData (String key, Object value) {
- checkWidget();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = 1;
- Object [] table = null;
- if ((state & KEYED_DATA) != 0) {
- table = (Object []) data;
- while (index < table.length) {
- if (key.equals (table [index])) break;
- index += 2;
- }
- }
- if (value != null) {
- if ((state & KEYED_DATA) != 0) {
- if (index == table.length) {
- Object [] newTable = new Object [table.length + 2];
- System.arraycopy (table, 0, newTable, 0, table.length);
- data = table = newTable;
- }
- } else {
- table = new Object [3];
- table [0] = data;
- data = table;
- state |= KEYED_DATA;
- }
- table [index] = key;
- table [index + 1] = value;
- } else {
- if ((state & KEYED_DATA) != 0) {
- if (index != table.length) {
- int length = table.length - 2;
- if (length == 1) {
- data = table [0];
- state &= ~KEYED_DATA;
- } else {
- Object [] newTable = new Object [length];
- System.arraycopy (table, 0, newTable, 0, index);
- System.arraycopy (table, index + 2, newTable, index, length - index);
- data = newTable;
- }
- }
- }
- }
-}
-
-boolean setInputState (Event event, int type, int key_mods, int button_state) {
- if ((key_mods & OS.Pk_KM_Alt) != 0) event.stateMask |= SWT.ALT;
- if ((key_mods & OS.Pk_KM_Shift) != 0) event.stateMask |= SWT.SHIFT;
- if ((key_mods & OS.Pk_KM_Ctrl) != 0) event.stateMask |= SWT.CONTROL;
- if ((button_state & OS.Ph_BUTTON_SELECT) != 0) event.stateMask |= SWT.BUTTON1;
- if ((button_state & OS.Ph_BUTTON_ADJUST) != 0) event.stateMask |= SWT.BUTTON2;
- if ((button_state & OS.Ph_BUTTON_MENU) != 0) event.stateMask |= SWT.BUTTON3;
- switch (type) {
- case SWT.MouseDown:
- case SWT.MouseDoubleClick:
- if (event.button == 1) event.stateMask &= ~SWT.BUTTON1;
- if (event.button == 2) event.stateMask &= ~SWT.BUTTON2;
- if (event.button == 3) event.stateMask &= ~SWT.BUTTON3;
- break;
- case SWT.MouseUp:
- if (event.button == 1) event.stateMask |= SWT.BUTTON1;
- if (event.button == 2) event.stateMask |= SWT.BUTTON2;
- if (event.button == 3) event.stateMask |= SWT.BUTTON3;
- break;
- case SWT.KeyDown:
- case SWT.Traverse:
- if (event.keyCode == SWT.ALT) event.stateMask &= ~SWT.ALT;
- if (event.keyCode == SWT.SHIFT) event.stateMask &= ~SWT.SHIFT;
- if (event.keyCode == SWT.CONTROL) event.stateMask &= ~SWT.CONTROL;
- break;
- case SWT.KeyUp:
- if (event.keyCode == SWT.ALT) event.stateMask |= SWT.ALT;
- if (event.keyCode == SWT.SHIFT) event.stateMask |= SWT.SHIFT;
- if (event.keyCode == SWT.CONTROL) event.stateMask |= SWT.CONTROL;
- break;
- }
- return true;
-}
-
-boolean setKeyState (Event event, int type, PhKeyEvent_t ke) {
- int key = 0;
- boolean isNull = false;
- if ((ke.key_flags & OS.Pk_KF_Cap_Valid) != 0) {
- key = ke.key_cap;
- if ((ke.key_mods & OS.Pk_KM_Num_Lock) == 0) {
- switch (key) {
- case OS.Pk_KP_0: key = OS.Pk_Insert; break;
- case OS.Pk_KP_1: key = OS.Pk_End; break;
- case OS.Pk_KP_2: key = OS.Pk_Down; break;
- case OS.Pk_KP_3: key = OS.Pk_Pg_Down; break;
- case OS.Pk_KP_4: key = OS.Pk_Left; break;
- case OS.Pk_KP_5: break;
- case OS.Pk_KP_6: key = OS.Pk_Right; break;
- case OS.Pk_KP_7: key = OS.Pk_Home; break;
- case OS.Pk_KP_8: key = OS.Pk_Up; break;
- case OS.Pk_KP_9: key = OS.Pk_Pg_Up; break;
- case OS.Pk_KP_Decimal: key = OS.Pk_Delete; break;
- }
-
- }
- event.keyCode = Display.translateKey (key);
- }
- switch (key) {
- case OS.Pk_BackSpace: event.character = '\b'; break;
- case OS.Pk_Linefeed: event.character = '\n'; break;
- case OS.Pk_KP_Enter:
- case OS.Pk_Return: event.character = '\r'; break;
- case OS.Pk_Delete: event.character = 0x7F; break;
- case OS.Pk_Escape: event.character = 0x1B; break;
- case OS.Pk_KP_Tab:
- case OS.Pk_Tab: event.character = '\t'; break;
- /* These keys have no mapping in SWT yet */
- case OS.Pk_Clear:
- case OS.Pk_Menu:
- case OS.Pk_Hyper_L:
- case OS.Pk_Hyper_R:
- break;
- default: {
- if (event.keyCode == 0) {
- if ((ke.key_flags & OS.Pk_KF_Cap_Valid) != 0) {
- event.keyCode = ke.key_cap;
- }
- }
- /*
- * Fetuare in Photon. The key_sym value is not valid when Ctrl
- * or Alt is pressed. The fix is to detect this case and try to
- * use the key_cap value.
- */
- if ((ke.key_mods & (OS.Pk_KM_Alt | OS.Pk_KM_Ctrl)) != 0) {
- if (0 <= key && key <= 0x7F) {
- if ((ke.key_mods & OS.Pk_KM_Ctrl) != 0) {
- isNull = key == '@';
- if ('a' <= key && key <= 'z') key -= 'a' - 'A';
- if (64 <= key && key <= 95) key -= 64;
- event.character = (char) key;
- isNull &= key == 0;
- } else {
- if ((ke.key_flags & OS.Pk_KF_Sym_Valid) != 0) {
- event.character = (char) ke.key_sym;
- }
- }
- }
- } else {
- byte [] buffer = new byte [6];
- int length = OS.PhKeyToMb (buffer, ke);
- if (length > 0) {
- char [] unicode = Converter.mbcsToWcs (null, buffer);
- if (unicode.length > 0) event.character = unicode [0];
- }
- }
- }
- }
- if (event.keyCode == 0 && event.character == 0) {
- if (!isNull) return false;
- }
- return setInputState (event, type, ke.key_mods, ke.button_state);
-}
-
-boolean setMouseState(Event event, int type, PhPointerEvent_t pe, PhEvent_t ev) {
- int buttons = pe.buttons;
- event.x = pe.pos_x + ev.translation_x;
- event.y = pe.pos_y + ev.translation_y;
- if (ev.type == OS.Ph_EV_BUT_PRESS || ev.type == OS.Ph_EV_BUT_RELEASE) {
- switch (buttons) {
- case OS.Ph_BUTTON_SELECT: event.button = 1; break;
- case OS.Ph_BUTTON_ADJUST: event.button = 2; break;
- case OS.Ph_BUTTON_MENU: event.button = 3; break;
- }
- }
- return setInputState(event, type, pe.key_mods, pe.button_state);
-}
-
-int topHandle () {
- return handle;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- String string = "*Disposed*";
- if (!isDisposed ()) {
- string = "*Wrong Thread*";
- if (isValidThread ()) string = getNameText ();
- }
- return getName () + " {" + string + "}";
-}
-
-int windowProc (int handle, int data, int info) {
- switch (data) {
- case OS.Ph_EV_BOUNDARY: return Ph_EV_BOUNDARY (handle, info);
- case OS.Ph_EV_BUT_PRESS: return Ph_EV_BUT_PRESS (handle, info);
- case OS.Ph_EV_BUT_RELEASE: return Ph_EV_BUT_RELEASE (handle, info);
- case OS.Ph_EV_DRAG: return Ph_EV_DRAG (handle, info);
- case OS.Ph_EV_KEY: return Ph_EV_KEY (handle, info);
- case OS.Ph_EV_PTR_MOTION: return Ph_EV_PTR_MOTION (handle, info);
- case OS.Pt_CB_ACTIVATE: return Pt_CB_ACTIVATE (handle, info);
- case OS.Pt_CB_ARM: return Pt_CB_ARM (handle, info);
- case OS.Pt_CB_GOT_FOCUS: return Pt_CB_GOT_FOCUS (handle, info);
- case OS.Pt_CB_LOST_FOCUS: return Pt_CB_LOST_FOCUS (handle, info);
- case OS.Pt_CB_MODIFY_VERIFY: return Pt_CB_MODIFY_VERIFY (handle, info);
- case OS.Pt_CB_NUMERIC_CHANGED: return Pt_CB_NUMERIC_CHANGED (handle, info);
- case OS.Pt_CB_OUTBOUND: return Pt_CB_OUTBOUND (handle, info);
- case OS.Pt_CB_PG_PANEL_SWITCHING: return Pt_CB_PG_PANEL_SWITCHING (handle, info);
- case OS.Pt_CB_REALIZED: return Pt_CB_REALIZED (handle, info);
- case OS.Pt_CB_RESIZE: return Pt_CB_RESIZE (handle, info);
- case OS.Pt_CB_SCROLL_MOVE: return Pt_CB_SCROLL_MOVE (handle, info);
- case OS.Pt_CB_SLIDER_MOVE: return Pt_CB_SLIDER_MOVE (handle, info);
- case OS.Pt_CB_SELECTION: return Pt_CB_SELECTION (handle, info);
- case OS.Pt_CB_TEXT_CHANGED: return Pt_CB_TEXT_CHANGED (handle, info);
- case OS.Pt_CB_TIMER_ACTIVATE: return Pt_CB_TIMER_ACTIVATE (handle, info);
- case OS.Pt_CB_UNREALIZED: return Pt_CB_UNREALIZED (handle, info);
- case OS.Pt_CB_WINDOW: return Pt_CB_WINDOW (handle, info);
- }
- return OS.Pt_CONTINUE;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/WidgetTable.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/WidgetTable.java
deleted file mode 100755
index 8898734d6f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/WidgetTable.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.photon.*;
-
-class WidgetTable {
- static int FreeSlot = 0;
- static int GrowSize = 1024;
- static int [] IndexTable = new int [GrowSize];
- static Widget [] WidgetTable = new Widget [GrowSize];
- static int ArgPtr = OS.malloc (4);
- static int [] ArgBuffer = new int [1];
- static int [] GetArgs = new int [] {OS.Pt_ARG_USER_DATA, 0, 0};
- static {
- for (int i=0; i<GrowSize-1; i++) IndexTable [i] = i + 1;
- IndexTable [GrowSize - 1] = -1;
- }
-public static synchronized Widget get (int handle) {
- if (handle == 0) return null;
- GetArgs [1] = 0;
- OS.PtGetResources (handle, GetArgs.length / 3, GetArgs);
- if (GetArgs [1] == 0) return null;
- OS.memmove (ArgBuffer, GetArgs [1], 4);
- if (ArgBuffer [0] == 0) return null;
- int index = ArgBuffer [0] - 1;
- if (0 <= index && index < WidgetTable.length) return WidgetTable [index];
- return null;
-}
-public synchronized static void put(int handle, Widget widget) {
- if (handle == 0) return;
- if (FreeSlot == -1) {
- int length = (FreeSlot = IndexTable.length) + GrowSize;
- int[] newIndexTable = new int[length];
- Widget[] newWidgetTable = new Widget [length];
- System.arraycopy (IndexTable, 0, newIndexTable, 0, FreeSlot);
- System.arraycopy (WidgetTable, 0, newWidgetTable, 0, FreeSlot);
- for (int i = FreeSlot; i < length - 1; i++) {
- newIndexTable[i] = i + 1;
- }
- newIndexTable[length - 1] = -1;
- IndexTable = newIndexTable;
- WidgetTable = newWidgetTable;
- }
- ArgBuffer [0] = FreeSlot + 1;
- OS.memmove (ArgPtr, ArgBuffer, 4);
- OS.PtSetResource (handle, OS.Pt_ARG_USER_DATA, ArgPtr, 4);
- int oldSlot = FreeSlot;
- FreeSlot = IndexTable[oldSlot];
- IndexTable [oldSlot] = -2;
- WidgetTable [oldSlot] = widget;
-}
-public static synchronized Widget remove (int handle) {
- if (handle == 0) return null;
- GetArgs [1] = 0;
- OS.PtGetResources (handle, GetArgs.length / 3, GetArgs);
- if (GetArgs [1] == 0) return null;
- OS.memmove (ArgBuffer, GetArgs [1], 4);
- if (ArgBuffer [0] == 0) return null;
- int index = ArgBuffer [0] - 1;
- Widget widget = null;
- if (0 <= index && index < WidgetTable.length) {
- widget = WidgetTable [index];
- WidgetTable [index] = null;
- IndexTable [index] = FreeSlot;
- FreeSlot = index;
- ArgBuffer [0] = 0;
- OS.memmove (ArgPtr, ArgBuffer, 4);
- OS.PtSetResource (handle, OS.Pt_ARG_USER_DATA, ArgPtr, 4);
- }
- return widget;
-}
-public static synchronized Shell [] shells () {
- int length = 0;
- for (int i=0; i<WidgetTable.length; i++) {
- Widget widget = WidgetTable [i];
- if (widget != null && widget instanceof Shell) length++;
- }
- int index = 0;
- Shell [] result = new Shell [length];
- for (int i=0; i<WidgetTable.length; i++) {
- Widget widget = WidgetTable [i];
- if (widget != null && widget instanceof Shell) {
- int j = 0;
- while (j < index) {
- if (result [j] == widget) break;
- j++;
- }
- if (j == index) result [index++] = (Shell) widget;
- }
- }
- if (index == length) return result;
- Shell [] newResult = new Shell [index];
- System.arraycopy (result, 0, newResult, 0, index);
- return newResult;
-}
-public static synchronized int size () {
- int size = 0;
- for (int i=0; i<WidgetTable.length; i++) {
- if (WidgetTable [i] != null) size++;
- }
- return size;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Color.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Color.java
deleted file mode 100755
index 3603b53a65..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Color.java
+++ /dev/null
@@ -1,325 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage the operating system resources that
- * implement SWT's RGB color model. To create a color you can either
- * specify the individual color components as integers in the range
- * 0 to 255 or provide an instance of an <code>RGB</code>.
- * <p>
- * Application code must explicitly invoke the <code>Color.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see RGB
- * @see Device#getSystemColor
- * @see <a href="http://www.eclipse.org/swt/snippets/#color">Color and RGB snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class Color extends Resource {
-
- /**
- * the handle to the OS color resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Color(Device device) {
- super(device);
-}
-
-/**
- * Constructs a new instance of this class given a device and the
- * desired red, green and blue values expressed as ints in the range
- * 0 to 255 (where 0 is black and 255 is full brightness). On limited
- * color devices, the color instance created by this call may not have
- * the same RGB values as the ones specified by the arguments. The
- * RGB values on the returned instance will be the color values of
- * the operating system color.
- * <p>
- * You must dispose the color when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param red the amount of red in the color
- * @param green the amount of green in the color
- * @param blue the amount of blue in the color
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255</li>
- * </ul>
- *
- * @see #dispose
- */
-public Color (Device device, int red, int green, int blue) {
- super(device);
- init(red, green, blue);
- init();
-}
-
-/**
- * Constructs a new instance of this class given a device and an
- * <code>RGB</code> describing the desired red, green and blue values.
- * On limited color devices, the color instance created by this call
- * may not have the same RGB values as the ones specified by the
- * argument. The RGB values on the returned instance will be the color
- * values of the operating system color.
- * <p>
- * You must dispose the color when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param rgb the RGB values of the desired color
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the rgb argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue components of the argument are not between 0 and 255</li>
- * </ul>
- *
- * @see #dispose
- */
-public Color (Device device, RGB rgb) {
- super(device);
- if (rgb == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(rgb.red, rgb.green, rgb.blue);
- init();
-}
-
-void destroy() {
- /*
- * If this is a palette-based device,
- * Decrease the reference count for this color.
- * If the reference count reaches 0, the slot may
- * be reused when another color is allocated.
- */
- int /*long*/ hPal = device.hPalette;
- if (hPal != 0) {
- int index = OS.GetNearestPaletteIndex(hPal, handle);
- int[] colorRefCount = device.colorRefCount;
- if (colorRefCount[index] > 0) {
- colorRefCount[index]--;
- }
- }
- handle = -1;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Color)) return false;
- Color color = (Color) object;
- return device == color.device && (handle & 0xFFFFFF) == (color.handle & 0xFFFFFF);
-}
-
-/**
- * Returns the amount of blue in the color, from 0 to 255.
- *
- * @return the blue component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getBlue () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (handle & 0xFF0000) >> 16;
-}
-
-/**
- * Returns the amount of green in the color, from 0 to 255.
- *
- * @return the green component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getGreen () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (handle & 0xFF00) >> 8 ;
-}
-
-/**
- * Returns the amount of red in the color, from 0 to 255.
- *
- * @return the red component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getRed () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return handle & 0xFF;
-}
-
-/**
- * Returns an <code>RGB</code> representing the receiver.
- *
- * @return the RGB for the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public RGB getRGB () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return new RGB(handle & 0xFF, (handle & 0xFF00) >> 8, (handle & 0xFF0000) >> 16);
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return handle;
-}
-
-/**
- * Allocates the operating system resources associated
- * with the receiver.
- *
- * @param device the device on which to allocate the color
- * @param red the amount of red in the color
- * @param green the amount of green in the color
- * @param blue the amount of blue in the color
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255</li>
- * </ul>
- *
- * @see #dispose
- */
-void init(int red, int green, int blue) {
- if (red > 255 || red < 0 || green > 255 || green < 0 || blue > 255 || blue < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- handle = (red & 0xFF) | ((green & 0xFF) << 8) | ((blue & 0xFF) << 16);
-
- /* If this is not a palette-based device, return */
- int /*long*/ hPal = device.hPalette;
- if (hPal == 0) return;
-
- int[] colorRefCount = device.colorRefCount;
- /* Add this color to the default palette now */
- /* First find out if the color already exists */
- int index = OS.GetNearestPaletteIndex(hPal, handle);
- /* See if the nearest color actually is the color */
- byte[] entry = new byte[4];
- OS.GetPaletteEntries(hPal, index, 1, entry);
- if ((entry[0] == (byte)red) && (entry[1] == (byte)green) &&
- (entry[2] == (byte)blue)) {
- /* Found the color. Increment the ref count and return */
- colorRefCount[index]++;
- return;
- }
- /* Didn't find the color, allocate it now. Find the first free entry */
- int i = 0;
- while (i < colorRefCount.length) {
- if (colorRefCount[i] == 0) {
- index = i;
- break;
- }
- i++;
- }
- if (i == colorRefCount.length) {
- /* No free entries, use the closest one */
- /* Remake the handle from the actual rgbs */
- handle = (entry[0] & 0xFF) | ((entry[1] & 0xFF) << 8) |
- ((entry[2] & 0xFF) << 16);
- } else {
- /* Found a free entry */
- entry = new byte[] { (byte)(red & 0xFF), (byte)(green & 0xFF), (byte)(blue & 0xFF), 0 };
- OS.SetPaletteEntries(hPal, index, 1, entry);
- }
- colorRefCount[index]++;
-}
-
-/**
- * Returns <code>true</code> if the color has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the color.
- * When a color has been disposed, it is an error to
- * invoke any other method using the color.
- *
- * @return <code>true</code> when the color is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == -1;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Color {*DISPOSED*}"; //$NON-NLS-1$
- return "Color {" + getRed() + ", " + getGreen() + ", " + getBlue() + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-}
-
-/**
- * Invokes platform specific functionality to allocate a new color.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Color</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param handle the handle for the color
- * @return a new color object containing the specified device and handle
- */
-public static Color win32_new(Device device, int handle) {
- Color color = new Color(device);
- color.handle = handle;
- return color;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java
deleted file mode 100755
index 6c5273cc22..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java
+++ /dev/null
@@ -1,460 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage operating system resources that
- * specify the appearance of the on-screen pointer. To create a
- * cursor you specify the device and either a simple cursor style
- * describing one of the standard operating system provided cursors
- * or the image and mask data for the desired appearance.
- * <p>
- * Application code must explicitly invoke the <code>Cursor.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>
- * CURSOR_ARROW, CURSOR_WAIT, CURSOR_CROSS, CURSOR_APPSTARTING, CURSOR_HELP,
- * CURSOR_SIZEALL, CURSOR_SIZENESW, CURSOR_SIZENS, CURSOR_SIZENWSE, CURSOR_SIZEWE,
- * CURSOR_SIZEN, CURSOR_SIZES, CURSOR_SIZEE, CURSOR_SIZEW, CURSOR_SIZENE, CURSOR_SIZESE,
- * CURSOR_SIZESW, CURSOR_SIZENW, CURSOR_UPARROW, CURSOR_IBEAM, CURSOR_NO, CURSOR_HAND
- * </dd>
- * </dl>
- * <p>
- * Note: Only one of the above styles may be specified.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#cursor">Cursor snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class Cursor extends Resource {
-
- /**
- * the handle to the OS cursor resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
-
- boolean isIcon;
-
- /**
- * data used to create a HAND cursor.
- */
- static final byte[] HAND_SOURCE = {
- (byte)0xf9,(byte)0xff,(byte)0xff,(byte)0xff,
- (byte)0xf0,(byte)0xff,(byte)0xff,(byte)0xff,
- (byte)0xf0,(byte)0xff,(byte)0xff,(byte)0xff,
- (byte)0xf0,(byte)0xff,(byte)0xff,(byte)0xff,
- (byte)0xf0,(byte)0x3f,(byte)0xff,(byte)0xff,
- (byte)0xf0,(byte)0x07,(byte)0xff,(byte)0xff,
- (byte)0xf0,(byte)0x03,(byte)0xff,(byte)0xff,
- (byte)0xf0,(byte)0x00,(byte)0xff,(byte)0xff,
-
- (byte)0x10,(byte)0x00,(byte)0x7f,(byte)0xff,
- (byte)0x00,(byte)0x00,(byte)0x7f,(byte)0xff,
- (byte)0x80,(byte)0x00,(byte)0x7f,(byte)0xff,
- (byte)0xc0,(byte)0x00,(byte)0x7f,(byte)0xff,
- (byte)0xe0,(byte)0x00,(byte)0x7f,(byte)0xff,
- (byte)0xf0,(byte)0x00,(byte)0x7f,(byte)0xff,
- (byte)0xf8,(byte)0x00,(byte)0xff,(byte)0xff,
- (byte)0xfc,(byte)0x01,(byte)0xff,(byte)0xff,
-
- (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,
- (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,
- (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,
- (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,
- (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,
- (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,
- (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,
- (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,
-
- (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,
- (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,
- (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,
- (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,
- (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,
- (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,
- (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,
- (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff
- };
- static final byte[] HAND_MASK = {
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x06,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x06,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x06,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x06,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x06,(byte)0xc0,(byte)0x00,(byte)0x00,
- (byte)0x06,(byte)0xd8,(byte)0x00,(byte)0x00,
- (byte)0x06,(byte)0xd8,(byte)0x00,(byte)0x00,
-
- (byte)0x07,(byte)0xdb,(byte)0x00,(byte)0x00,
- (byte)0x67,(byte)0xfb,(byte)0x00,(byte)0x00,
- (byte)0x3f,(byte)0xff,(byte)0x00,(byte)0x00,
- (byte)0x1f,(byte)0xff,(byte)0x00,(byte)0x00,
- (byte)0x0f,(byte)0xff,(byte)0x00,(byte)0x00,
- (byte)0x07,(byte)0xff,(byte)0x00,(byte)0x00,
- (byte)0x03,(byte)0xfe,(byte)0x00,(byte)0x00,
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
-
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
-
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00
- };
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Cursor(Device device) {
- super(device);
-}
-
-/**
- * Constructs a new cursor given a device and a style
- * constant describing the desired cursor appearance.
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param style the style of cursor to allocate
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - when an unknown style is specified</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- *
- * @see SWT#CURSOR_ARROW
- * @see SWT#CURSOR_WAIT
- * @see SWT#CURSOR_CROSS
- * @see SWT#CURSOR_APPSTARTING
- * @see SWT#CURSOR_HELP
- * @see SWT#CURSOR_SIZEALL
- * @see SWT#CURSOR_SIZENESW
- * @see SWT#CURSOR_SIZENS
- * @see SWT#CURSOR_SIZENWSE
- * @see SWT#CURSOR_SIZEWE
- * @see SWT#CURSOR_SIZEN
- * @see SWT#CURSOR_SIZES
- * @see SWT#CURSOR_SIZEE
- * @see SWT#CURSOR_SIZEW
- * @see SWT#CURSOR_SIZENE
- * @see SWT#CURSOR_SIZESE
- * @see SWT#CURSOR_SIZESW
- * @see SWT#CURSOR_SIZENW
- * @see SWT#CURSOR_UPARROW
- * @see SWT#CURSOR_IBEAM
- * @see SWT#CURSOR_NO
- * @see SWT#CURSOR_HAND
- */
-public Cursor(Device device, int style) {
- super(device);
- int /*long*/ lpCursorName = 0;
- switch (style) {
- case SWT.CURSOR_HAND: lpCursorName = OS.IDC_HAND; break;
- case SWT.CURSOR_ARROW: lpCursorName = OS.IDC_ARROW; break;
- case SWT.CURSOR_WAIT: lpCursorName = OS.IDC_WAIT; break;
- case SWT.CURSOR_CROSS: lpCursorName = OS.IDC_CROSS; break;
- case SWT.CURSOR_APPSTARTING: lpCursorName = OS.IDC_APPSTARTING; break;
- case SWT.CURSOR_HELP: lpCursorName = OS.IDC_HELP; break;
- case SWT.CURSOR_SIZEALL: lpCursorName = OS.IDC_SIZEALL; break;
- case SWT.CURSOR_SIZENESW: lpCursorName = OS.IDC_SIZENESW; break;
- case SWT.CURSOR_SIZENS: lpCursorName = OS.IDC_SIZENS; break;
- case SWT.CURSOR_SIZENWSE: lpCursorName = OS.IDC_SIZENWSE; break;
- case SWT.CURSOR_SIZEWE: lpCursorName = OS.IDC_SIZEWE; break;
- case SWT.CURSOR_SIZEN: lpCursorName = OS.IDC_SIZENS; break;
- case SWT.CURSOR_SIZES: lpCursorName = OS.IDC_SIZENS; break;
- case SWT.CURSOR_SIZEE: lpCursorName = OS.IDC_SIZEWE; break;
- case SWT.CURSOR_SIZEW: lpCursorName = OS.IDC_SIZEWE; break;
- case SWT.CURSOR_SIZENE: lpCursorName = OS.IDC_SIZENESW; break;
- case SWT.CURSOR_SIZESE: lpCursorName = OS.IDC_SIZENWSE; break;
- case SWT.CURSOR_SIZESW: lpCursorName = OS.IDC_SIZENESW; break;
- case SWT.CURSOR_SIZENW: lpCursorName = OS.IDC_SIZENWSE; break;
- case SWT.CURSOR_UPARROW: lpCursorName = OS.IDC_UPARROW; break;
- case SWT.CURSOR_IBEAM: lpCursorName = OS.IDC_IBEAM; break;
- case SWT.CURSOR_NO: lpCursorName = OS.IDC_NO; break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- handle = OS.LoadCursor(0, lpCursorName);
- /*
- * IDC_HAND is supported only on Windows 2000 and Windows 98.
- * Create a hand cursor if running in other Windows platforms.
- */
- if (handle == 0 && style == SWT.CURSOR_HAND) {
- int width = OS.GetSystemMetrics(OS.SM_CXCURSOR);
- int height = OS.GetSystemMetrics(OS.SM_CYCURSOR);
- if (width == 32 && height == 32) {
- int /*long*/ hInst = OS.GetModuleHandle(null);
- if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- handle = OS.CreateCursor(hInst, 5, 0, 32, 32, HAND_SOURCE, HAND_MASK);
-
- }
- }
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new cursor given a device, image and mask
- * data describing the desired cursor appearance, and the x
- * and y coordinates of the <em>hotspot</em> (that is, the point
- * within the area covered by the cursor which is considered
- * to be where the on-screen pointer is "pointing").
- * <p>
- * The mask data is allowed to be null, but in this case the source
- * must be an ImageData representing an icon that specifies both
- * color data and mask data.
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param source the color data for the cursor
- * @param mask the mask data for the cursor (or null)
- * @param hotspotX the x coordinate of the cursor's hotspot
- * @param hotspotY the y coordinate of the cursor's hotspot
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the source is null</li>
- * <li>ERROR_NULL_ARGUMENT - if the mask is null and the source does not have a mask</li>
- * <li>ERROR_INVALID_ARGUMENT - if the source and the mask are not the same
- * size, or if the hotspot is outside the bounds of the image</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- */
-public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (mask == null) {
- if (source.getTransparencyType() != SWT.TRANSPARENCY_MASK) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- mask = source.getTransparencyMask();
- }
- /* Check the bounds. Mask must be the same size as source */
- if (mask.width != source.width || mask.height != source.height) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- /* Check the hotspots */
- if (hotspotX >= source.width || hotspotX < 0 ||
- hotspotY >= source.height || hotspotY < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- /* Convert depth to 1 */
- mask = ImageData.convertMask(mask);
- source = ImageData.convertMask(source);
-
- /* Make sure source and mask scanline pad is 2 */
- byte[] sourceData = ImageData.convertPad(source.data, source.width, source.height, source.depth, source.scanlinePad, 2);
- byte[] maskData = ImageData.convertPad(mask.data, mask.width, mask.height, mask.depth, mask.scanlinePad, 2);
-
- /* Create the cursor */
- int /*long*/ hInst = OS.GetModuleHandle(null);
- if (OS.IsWinCE) SWT.error (SWT.ERROR_NOT_IMPLEMENTED);
- handle = OS.CreateCursor(hInst, hotspotX, hotspotY, source.width, source.height, sourceData, maskData);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new cursor given a device, image data describing
- * the desired cursor appearance, and the x and y coordinates of
- * the <em>hotspot</em> (that is, the point within the area
- * covered by the cursor which is considered to be where the
- * on-screen pointer is "pointing").
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param source the image data for the cursor
- * @param hotspotX the x coordinate of the cursor's hotspot
- * @param hotspotY the y coordinate of the cursor's hotspot
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the hotspot is outside the bounds of the
- * image</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- *
- * @since 3.0
- */
-public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- /* Check the hotspots */
- if (hotspotX >= source.width || hotspotX < 0 ||
- hotspotY >= source.height || hotspotY < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- ImageData mask = source.getTransparencyMask();
- int /*long*/ [] result = Image.init(this.device, null, source, mask);
- int /*long*/ hBitmap = result[0];
- int /*long*/ hMask = result[1];
- /* Create the icon */
- ICONINFO info = new ICONINFO();
- info.fIcon = false;
- info.hbmColor = hBitmap;
- info.hbmMask = hMask;
- info.xHotspot = hotspotX;
- info.yHotspot = hotspotY;
- handle = OS.CreateIconIndirect(info);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.DeleteObject(hBitmap);
- OS.DeleteObject(hMask);
- isIcon = true;
- init();
-}
-
-void destroy () {
- /*
- * It is an error in Windows to destroy the current
- * cursor. Check that the cursor that is about to
- * be destroyed is the current cursor. If so, set
- * the current cursor to be IDC_ARROW. Note that
- * Windows shares predefined cursors so the call to
- * LoadCursor() does not leak.
- */
- // TEMPORARY CODE
-// if (OS.GetCursor() == handle) {
-// OS.SetCursor(OS.LoadCursor(0, OS.IDC_ARROW));
-// }
-
- if (isIcon) {
- OS.DestroyIcon(handle);
- } else {
- /*
- * The MSDN states that one should not destroy a shared
- * cursor, that is, one obtained from LoadCursor.
- * However, it does not appear to do any harm, so rather
- * than keep track of how a cursor was created, we just
- * destroy them all. If this causes problems in the future,
- * put the flag back in.
- */
- if (!OS.IsWinCE) OS.DestroyCursor(handle);
- }
- handle = 0;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Cursor)) return false;
- Cursor cursor = (Cursor) object;
- return device == cursor.device && handle == cursor.handle;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return (int)/*64*/handle;
-}
-
-/**
- * Returns <code>true</code> if the cursor has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the cursor.
- * When a cursor has been disposed, it is an error to
- * invoke any other method using the cursor.
- *
- * @return <code>true</code> when the cursor is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Cursor {*DISPOSED*}";
- return "Cursor {" + handle + "}";
-}
-
-/**
- * Invokes platform specific functionality to allocate a new cursor.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Cursor</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param handle the handle for the cursor
- * @return a new cursor object containing the specified device and handle
- */
-public static Cursor win32_new(Device device, int handle) {
- Cursor cursor = new Cursor(device);
- cursor.handle = handle;
- return cursor;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java
deleted file mode 100755
index 7745d9088a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java
+++ /dev/null
@@ -1,972 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gdip.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-
-/**
- * This class is the abstract superclass of all device objects,
- * such as the Display device and the Printer device. Devices
- * can have a graphics context (GC) created for them, and they
- * can be drawn on by sending messages to the associated GC.
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class Device implements Drawable {
-
- /* Debugging */
- public static boolean DEBUG;
- boolean debug = DEBUG;
- boolean tracking = DEBUG;
- Error [] errors;
- Object [] objects;
- Object trackingLock;
-
- /**
- * Palette
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ hPalette = 0;
- int [] colorRefCount;
-
- /* System Font */
- Font systemFont;
-
- /* Font Enumeration */
- int nFonts = 256;
- LOGFONT [] logFonts;
- TEXTMETRIC metrics;
- int[] pixels;
-
- /* Scripts */
- int /*long*/ [] scripts;
-
- /* Advanced Graphics */
- int /*long*/ [] gdipToken;
- int /*long*/ fontCollection;
- String[] loadedFonts;
-
- boolean disposed;
-
- /*
- * TEMPORARY CODE. When a graphics object is
- * created and the device parameter is null,
- * the current Display is used. This presents
- * a problem because SWT graphics does not
- * reference classes in SWT widgets. The correct
- * fix is to remove this feature. Unfortunately,
- * too many application programs rely on this
- * feature.
- */
- protected static Device CurrentDevice;
- protected static Runnable DeviceFinder;
- static {
- try {
- Class.forName ("org.eclipse.swt.widgets.Display"); //$NON-NLS-1$
- } catch (ClassNotFoundException e) {}
- }
-
-/*
-* TEMPORARY CODE.
-*/
-static synchronized Device getDevice () {
- if (DeviceFinder != null) DeviceFinder.run();
- Device device = CurrentDevice;
- CurrentDevice = null;
- return device;
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * You must dispose the device when it is no longer required.
- * </p>
- *
- * @see #create
- * @see #init
- *
- * @since 3.1
- */
-public Device() {
- this(null);
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * You must dispose the device when it is no longer required.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #create
- * @see #init
- * @see DeviceData
- */
-public Device(DeviceData data) {
- synchronized (Device.class) {
- if (data != null) {
- debug = data.debug;
- tracking = data.tracking;
- }
- if (tracking) {
- errors = new Error [128];
- objects = new Object [128];
- trackingLock = new Object ();
- }
- create (data);
- init ();
- }
-}
-
-void addFont (String font) {
- if (loadedFonts == null) loadedFonts = new String [4];
- int length = loadedFonts.length;
- for (int i=0; i<length; i++) {
- if (font.equals(loadedFonts [i])) return;
- }
- int index = 0;
- while (index < length) {
- if (loadedFonts [index] == null) break;
- index++;
- }
- if (index == length) {
- String [] temp = new String [length + 4];
- System.arraycopy (loadedFonts, 0, temp, 0, length);
- loadedFonts = temp;
- }
- loadedFonts [index] = font;
-}
-
-/**
- * Throws an <code>SWTException</code> if the receiver can not
- * be accessed by the caller. This may include both checks on
- * the state of the receiver and more generally on the entire
- * execution context. This method <em>should</em> be called by
- * device implementors to enforce the standard SWT invariants.
- * <p>
- * Currently, it is an error to invoke any method (other than
- * <code>isDisposed()</code> and <code>dispose()</code>) on a
- * device that has had its <code>dispose()</code> method called.
- * </p><p>
- * In future releases of SWT, there may be more or fewer error
- * checks and exceptions may be thrown for different reasons.
- * <p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-protected void checkDevice () {
- if (disposed) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
-}
-
-void checkGDIP() {
- if (gdipToken != null) return;
- int oldErrorMode = 0;
- if (!OS.IsWinCE) oldErrorMode = OS.SetErrorMode (OS.SEM_FAILCRITICALERRORS);
- try {
- int /*long*/ [] token = new int /*long*/ [1];
- GdiplusStartupInput input = new GdiplusStartupInput ();
- input.GdiplusVersion = 1;
- if (Gdip.GdiplusStartup (token, input, 0) == 0) {
- gdipToken = token;
- if (loadedFonts != null) {
- fontCollection = Gdip.PrivateFontCollection_new();
- if (fontCollection == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- for (int i = 0; i < loadedFonts.length; i++) {
- String path = loadedFonts[i];
- if (path == null) break;
- int length = path.length();
- char [] buffer = new char [length + 1];
- path.getChars(0, length, buffer, 0);
- Gdip.PrivateFontCollection_AddFontFile(fontCollection, buffer);
- }
- loadedFonts = null;
- }
- }
- } catch (Throwable t) {
- SWT.error (SWT.ERROR_NO_GRAPHICS_LIBRARY, t, " [GDI+ is required]"); //$NON-NLS-1$
- } finally {
- if (!OS.IsWinCE) OS.SetErrorMode (oldErrorMode);
- }
-}
-
-/**
- * Creates the device in the operating system. If the device
- * does not have a handle, this method may do nothing depending
- * on the device.
- * <p>
- * This method is called before <code>init</code>.
- * </p><p>
- * Subclasses are supposed to reimplement this method and not
- * call the <code>super</code> implementation.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #init
- */
-protected void create (DeviceData data) {
-}
-
-int computePixels(float height) {
- int /*long*/ hDC = internal_new_GC (null);
- int pixels = -(int)(0.5f + (height * OS.GetDeviceCaps(hDC, OS.LOGPIXELSY) / 72f));
- internal_dispose_GC (hDC, null);
- return pixels;
-}
-
-float computePoints(LOGFONT logFont, int /*long*/ hFont) {
- int /*long*/ hDC = internal_new_GC (null);
- int logPixelsY = OS.GetDeviceCaps(hDC, OS.LOGPIXELSY);
- int pixels = 0;
- if (logFont.lfHeight > 0) {
- /*
- * Feature in Windows. If the lfHeight of the LOGFONT structure
- * is positive, the lfHeight measures the height of the entire
- * cell, including internal leading, in logical units. Since the
- * height of a font in points does not include the internal leading,
- * we must subtract the internal leading, which requires a TEXTMETRIC.
- */
- int /*long*/ oldFont = OS.SelectObject(hDC, hFont);
- TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA();
- OS.GetTextMetrics(hDC, lptm);
- OS.SelectObject(hDC, oldFont);
- pixels = logFont.lfHeight - lptm.tmInternalLeading;
- } else {
- pixels = -logFont.lfHeight;
- }
- internal_dispose_GC (hDC, null);
- return pixels * 72f / logPixelsY;
-}
-
-/**
- * Destroys the device in the operating system and releases
- * the device's handle. If the device does not have a handle,
- * this method may do nothing depending on the device.
- * <p>
- * This method is called after <code>release</code>.
- * </p><p>
- * Subclasses are supposed to reimplement this method and not
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #dispose
- * @see #release
- */
-protected void destroy () {
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the receiver. After this method has been invoked, the receiver
- * will answer <code>true</code> when sent the message
- * <code>isDisposed()</code>.
- *
- * @see #release
- * @see #destroy
- * @see #checkDevice
- */
-public void dispose () {
- synchronized (Device.class) {
- if (isDisposed()) return;
- checkDevice ();
- release ();
- destroy ();
- disposed = true;
- if (tracking) {
- synchronized (trackingLock) {
- printErrors ();
- objects = null;
- errors = null;
- trackingLock = null;
- }
- }
- }
-}
-
-void dispose_Object (Object object) {
- synchronized (trackingLock) {
- for (int i=0; i<objects.length; i++) {
- if (objects [i] == object) {
- objects [i] = null;
- errors [i] = null;
- return;
- }
- }
- }
-}
-
-int /*long*/ EnumFontFamProc (int /*long*/ lpelfe, int /*long*/ lpntme, int /*long*/ FontType, int /*long*/ lParam) {
- boolean isScalable = ((int)/*64*/FontType & OS.RASTER_FONTTYPE) == 0;
- boolean scalable = lParam == 1;
- if (isScalable == scalable) {
- /* Add the log font to the list of log fonts */
- if (nFonts == logFonts.length) {
- LOGFONT [] newLogFonts = new LOGFONT [logFonts.length + 128];
- System.arraycopy (logFonts, 0, newLogFonts, 0, nFonts);
- logFonts = newLogFonts;
- int[] newPixels = new int[newLogFonts.length];
- System.arraycopy (pixels, 0, newPixels, 0, nFonts);
- pixels = newPixels;
- }
- LOGFONT logFont = logFonts [nFonts];
- if (logFont == null) logFont = OS.IsUnicode ? (LOGFONT)new LOGFONTW () : new LOGFONTA ();
- OS.MoveMemory (logFont, lpelfe, LOGFONT.sizeof);
- logFonts [nFonts] = logFont;
- if (logFont.lfHeight > 0) {
- /*
- * Feature in Windows. If the lfHeight of the LOGFONT structure
- * is positive, the lfHeight measures the height of the entire
- * cell, including internal leading, in logical units. Since the
- * height of a font in points does not include the internal leading,
- * we must subtract the internal leading, which requires a TEXTMETRIC,
- * which in turn requires font creation.
- */
- OS.MoveMemory(metrics, lpntme, TEXTMETRIC.sizeof);
- pixels[nFonts] = logFont.lfHeight - metrics.tmInternalLeading;
- } else {
- pixels[nFonts] = -logFont.lfHeight;
- }
- nFonts++;
- }
- return 1;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location.
- *
- * @return the bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkDevice ();
- int /*long*/ hDC = internal_new_GC (null);
- int width = OS.GetDeviceCaps (hDC, OS.HORZRES);
- int height = OS.GetDeviceCaps (hDC, OS.VERTRES);
- internal_dispose_GC (hDC, null);
- return new Rectangle (0, 0, width, height);
-}
-
-/**
- * Returns a <code>DeviceData</code> based on the receiver.
- * Modifications made to this <code>DeviceData</code> will not
- * affect the receiver.
- *
- * @return a <code>DeviceData</code> containing the device's data and attributes
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see DeviceData
- */
-public DeviceData getDeviceData () {
- checkDevice();
- DeviceData data = new DeviceData ();
- data.debug = debug;
- data.tracking = tracking;
- if (tracking) {
- synchronized (trackingLock) {
- int count = 0, length = objects.length;
- for (int i=0; i<length; i++) {
- if (objects [i] != null) count++;
- }
- int index = 0;
- data.objects = new Object [count];
- data.errors = new Error [count];
- for (int i=0; i<length; i++) {
- if (objects [i] != null) {
- data.objects [index] = objects [i];
- data.errors [index] = errors [i];
- index++;
- }
- }
- }
- } else {
- data.objects = new Object [0];
- data.errors = new Error [0];
- }
- return data;
-}
-
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data.
- *
- * @return the client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getBounds
- */
-public Rectangle getClientArea () {
- return getBounds ();
-}
-
-/**
- * Returns the bit depth of the screen, which is the number of
- * bits it takes to represent the number of unique colors that
- * the screen is currently capable of displaying. This number
- * will typically be one of 1, 8, 15, 16, 24 or 32.
- *
- * @return the depth of the screen
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getDepth () {
- checkDevice ();
- int /*long*/ hDC = internal_new_GC (null);
- int bits = OS.GetDeviceCaps (hDC, OS.BITSPIXEL);
- int planes = OS.GetDeviceCaps (hDC, OS.PLANES);
- internal_dispose_GC (hDC, null);
- return bits * planes;
-}
-
-/**
- * Returns a point whose x coordinate is the horizontal
- * dots per inch of the display, and whose y coordinate
- * is the vertical dots per inch of the display.
- *
- * @return the horizontal and vertical DPI
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point getDPI () {
- checkDevice ();
- int /*long*/ hDC = internal_new_GC (null);
- int dpiX = OS.GetDeviceCaps (hDC, OS.LOGPIXELSX);
- int dpiY = OS.GetDeviceCaps (hDC, OS.LOGPIXELSY);
- internal_dispose_GC (hDC, null);
- return new Point (dpiX, dpiY);
-}
-
-/**
- * Returns <code>FontData</code> objects which describe
- * the fonts that match the given arguments. If the
- * <code>faceName</code> is null, all fonts will be returned.
- *
- * @param faceName the name of the font to look for, or null
- * @param scalable if true only scalable fonts are returned, otherwise only non-scalable fonts are returned.
- * @return the matching font data
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontData [] getFontList (String faceName, boolean scalable) {
- checkDevice ();
-
- /* Create the callback */
- Callback callback = new Callback (this, "EnumFontFamProc", 4); //$NON-NLS-1$
- int /*long*/ lpEnumFontFamProc = callback.getAddress ();
- if (lpEnumFontFamProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- /* Initialize the instance variables */
- metrics = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA();
- pixels = new int[nFonts];
- logFonts = new LOGFONT [nFonts];
- for (int i=0; i<logFonts.length; i++) {
- logFonts [i] = OS.IsUnicode ? (LOGFONT) new LOGFONTW () : new LOGFONTA ();
- }
- nFonts = 0;
-
- /* Enumerate */
- int offset = 0;
- int /*long*/ hDC = internal_new_GC (null);
- if (faceName == null) {
- /* The user did not specify a face name, so they want all versions of all available face names */
- OS.EnumFontFamilies (hDC, null, lpEnumFontFamProc, scalable ? 1 : 0);
-
- /**
- * For bitmapped fonts, EnumFontFamilies only enumerates once for each font, regardless
- * of how many styles are available. If the user wants bitmapped fonts, enumerate on
- * each face name now.
- */
- offset = nFonts;
- for (int i=0; i<offset; i++) {
- LOGFONT lf = logFonts [i];
- /**
- * Bug in Windows 98. When EnumFontFamiliesEx is called with a specified face name, it
- * should enumerate for each available style of that font. Instead, it only enumerates
- * once. The fix is to call EnumFontFamilies, which works as expected.
- */
- if (OS.IsUnicode) {
- OS.EnumFontFamiliesW (hDC, ((LOGFONTW)lf).lfFaceName, lpEnumFontFamProc, scalable ? 1 : 0);
- } else {
- OS.EnumFontFamiliesA (hDC, ((LOGFONTA)lf).lfFaceName, lpEnumFontFamProc, scalable ? 1 : 0);
- }
- }
- } else {
- /* Use the character encoding for the default locale */
- TCHAR lpFaceName = new TCHAR (0, faceName, true);
- /**
- * Bug in Windows 98. When EnumFontFamiliesEx is called with a specified face name, it
- * should enumerate for each available style of that font. Instead, it only enumerates
- * once. The fix is to call EnumFontFamilies, which works as expected.
- */
- OS.EnumFontFamilies (hDC, lpFaceName, lpEnumFontFamProc, scalable ? 1 : 0);
- }
- int logPixelsY = OS.GetDeviceCaps(hDC, OS.LOGPIXELSY);
- internal_dispose_GC (hDC, null);
-
- /* Create the fontData from the logfonts */
- int count = 0;
- FontData [] result = new FontData [nFonts - offset];
- for (int i=offset; i<nFonts; i++) {
- FontData fd = FontData.win32_new (logFonts [i], pixels [i] * 72f / logPixelsY);
- int j;
- for (j = 0; j < count; j++) {
- if (fd.equals (result [j])) break;
- }
- if (j == count) result [count++] = fd;
- }
- if (count != result.length) {
- FontData [] newResult = new FontData [count];
- System.arraycopy (result, 0, newResult, 0, count);
- result = newResult;
- }
-
- /* Clean up */
- callback.dispose ();
- logFonts = null;
- pixels = null;
- metrics = null;
- return result;
-}
-
-String getLastError () {
- int error = OS.GetLastError();
- if (error == 0) return ""; //$NON-NLS-1$
- return " [GetLastError=0x" + Integer.toHexString(error) + "]"; //$NON-NLS-1$ //$NON-NLS-2$
-}
-
-String getLastErrorText () {
- int error = OS.GetLastError();
- if (error == 0) return ""; //$NON-NLS-1$
- int /*long*/ [] buffer = new int /*long*/ [1];
- int dwFlags = OS.FORMAT_MESSAGE_ALLOCATE_BUFFER | OS.FORMAT_MESSAGE_FROM_SYSTEM | OS.FORMAT_MESSAGE_IGNORE_INSERTS;
- int length = OS.FormatMessage(dwFlags, 0, error, OS.LANG_USER_DEFAULT, buffer, 0, 0);
- if (length == 0) return " [GetLastError=0x" + Integer.toHexString(error) + "]"; //$NON-NLS-1$ //$NON-NLS-2$
- TCHAR buffer1 = new TCHAR(0, length);
- OS.MoveMemory(buffer1, buffer[0], length * TCHAR.sizeof);
- if (buffer[0] != 0) OS.LocalFree(buffer[0]);
- return buffer1.toString(0, length);
-}
-
-/**
- * Returns the matching standard color for the given
- * constant, which should be one of the color constants
- * specified in class <code>SWT</code>. Any value other
- * than one of the SWT color constants which is passed
- * in will result in the color black. This color should
- * not be freed because it was allocated by the system,
- * not the application.
- *
- * @param id the color constant
- * @return the matching color
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT
- */
-public Color getSystemColor (int id) {
- checkDevice ();
- int pixel = 0x00000000;
- switch (id) {
- case SWT.COLOR_WHITE: pixel = 0x00FFFFFF; break;
- case SWT.COLOR_BLACK: pixel = 0x00000000; break;
- case SWT.COLOR_RED: pixel = 0x000000FF; break;
- case SWT.COLOR_DARK_RED: pixel = 0x00000080; break;
- case SWT.COLOR_GREEN: pixel = 0x0000FF00; break;
- case SWT.COLOR_DARK_GREEN: pixel = 0x00008000; break;
- case SWT.COLOR_YELLOW: pixel = 0x0000FFFF; break;
- case SWT.COLOR_DARK_YELLOW: pixel = 0x00008080; break;
- case SWT.COLOR_BLUE: pixel = 0x00FF0000; break;
- case SWT.COLOR_DARK_BLUE: pixel = 0x00800000; break;
- case SWT.COLOR_MAGENTA: pixel = 0x00FF00FF; break;
- case SWT.COLOR_DARK_MAGENTA: pixel = 0x00800080; break;
- case SWT.COLOR_CYAN: pixel = 0x00FFFF00; break;
- case SWT.COLOR_DARK_CYAN: pixel = 0x00808000; break;
- case SWT.COLOR_GRAY: pixel = 0x00C0C0C0; break;
- case SWT.COLOR_DARK_GRAY: pixel = 0x00808080; break;
- }
- return Color.win32_new (this, pixel);
-}
-
-/**
- * Returns a reasonable font for applications to use.
- * On some platforms, this will match the "default font"
- * or "system font" if such can be found. This font
- * should not be freed because it was allocated by the
- * system, not the application.
- * <p>
- * Typically, applications which want the default look
- * should simply not set the font on the widgets they
- * create. Widgets are always created with the correct
- * default font for the class of user-interface component
- * they represent.
- * </p>
- *
- * @return a font
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getSystemFont () {
- checkDevice ();
- int /*long*/ hFont = OS.GetStockObject (OS.SYSTEM_FONT);
- return Font.win32_new (this, hFont);
-}
-
-/**
- * Returns <code>true</code> if the underlying window system prints out
- * warning messages on the console, and <code>setWarnings</code>
- * had previously been called with <code>true</code>.
- *
- * @return <code>true</code>if warnings are being handled, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean getWarnings () {
- checkDevice ();
- return false;
-}
-
-/**
- * Initializes any internal resources needed by the
- * device.
- * <p>
- * This method is called after <code>create</code>.
- * </p><p>
- * If subclasses reimplement this method, they must
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #create
- */
-protected void init () {
- if (debug) {
- if (!OS.IsWinCE) OS.GdiSetBatchLimit(1);
- }
-
- /* Initialize the system font slot */
- systemFont = getSystemFont();
-
- /* Initialize scripts list */
- if (!OS.IsWinCE) {
- int /*long*/ [] ppSp = new int /*long*/ [1];
- int [] piNumScripts = new int [1];
- OS.ScriptGetProperties (ppSp, piNumScripts);
- scripts = new int /*long*/ [piNumScripts [0]];
- OS.MoveMemory (scripts, ppSp [0], scripts.length * OS.PTR_SIZEOF);
- }
-
- /*
- * If we're not on a device which supports palettes,
- * don't create one.
- */
- int /*long*/ hDC = internal_new_GC (null);
- int rc = OS.GetDeviceCaps (hDC, OS.RASTERCAPS);
- int bits = OS.GetDeviceCaps (hDC, OS.BITSPIXEL);
- int planes = OS.GetDeviceCaps (hDC, OS.PLANES);
-
- bits *= planes;
- if ((rc & OS.RC_PALETTE) == 0 || bits != 8) {
- internal_dispose_GC (hDC, null);
- return;
- }
-
- int numReserved = OS.GetDeviceCaps (hDC, OS.NUMRESERVED);
- int numEntries = OS.GetDeviceCaps (hDC, OS.SIZEPALETTE);
-
- if (OS.IsWinCE) {
- /*
- * Feature on WinCE. For some reason, certain 8 bit WinCE
- * devices return 0 for the number of reserved entries in
- * the system palette. Their system palette correctly contains
- * the usual 20 system colors. The workaround is to assume
- * there are 20 reserved system colors instead of 0.
- */
- if (numReserved == 0 && numEntries >= 20) numReserved = 20;
- }
-
- /* Create the palette and reference counter */
- colorRefCount = new int [numEntries];
-
- /* 4 bytes header + 4 bytes per entry * numEntries entries */
- byte [] logPalette = new byte [4 + 4 * numEntries];
-
- /* 2 bytes = special header */
- logPalette [0] = 0x00;
- logPalette [1] = 0x03;
-
- /* 2 bytes = number of colors, LSB first */
- logPalette [2] = 0;
- logPalette [3] = 1;
-
- /*
- * Create a palette which contains the system entries
- * as they are located in the system palette. The
- * MSDN article 'Memory Device Contexts' describes
- * where system entries are located. On an 8 bit
- * display with 20 reserved colors, the system colors
- * will be the first 10 entries and the last 10 ones.
- */
- byte[] lppe = new byte [4 * numEntries];
- OS.GetSystemPaletteEntries (hDC, 0, numEntries, lppe);
- /* Copy all entries from the system palette */
- System.arraycopy (lppe, 0, logPalette, 4, 4 * numEntries);
- /* Lock the indices corresponding to the system entries */
- for (int i = 0; i < numReserved / 2; i++) {
- colorRefCount [i] = 1;
- colorRefCount [numEntries - 1 - i] = 1;
- }
- internal_dispose_GC (hDC, null);
- hPalette = OS.CreatePalette (logPalette);
-}
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Device</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public abstract int /*long*/ internal_new_GC (GCData data);
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Device</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public abstract void /*long*/ internal_dispose_GC (int /*long*/ hDC, GCData data);
-
-/**
- * Returns <code>true</code> if the device has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the device.
- * When a device has been disposed, it is an error to
- * invoke any other method using the device.
- *
- * @return <code>true</code> when the device is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- synchronized (Device.class) {
- return disposed;
- }
-}
-
-/**
- * Loads the font specified by a file. The font will be
- * present in the list of fonts available to the application.
- *
- * @param path the font file path
- * @return whether the font was successfully loaded
- *
- * @exception SWTException <ul>
- * <li>ERROR_NULL_ARGUMENT - if path is null</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Font
- *
- * @since 3.3
- */
-public boolean loadFont (String path) {
- checkDevice();
- if (path == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (OS.IsWinNT && OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- TCHAR lpszFilename = new TCHAR (0, path, true);
- boolean loaded = OS.AddFontResourceEx (lpszFilename, OS.FR_PRIVATE, 0) != 0;
- if (loaded) {
- if (gdipToken != null) {
- if (fontCollection == 0) {
- fontCollection = Gdip.PrivateFontCollection_new();
- if (fontCollection == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- }
- int length = path.length();
- char [] buffer = new char [length + 1];
- path.getChars(0, length, buffer, 0);
- Gdip.PrivateFontCollection_AddFontFile(fontCollection, buffer);
- } else {
- addFont(path);
- }
- }
- return loaded;
- }
- return false;
-}
-
-void new_Object (Object object) {
- synchronized (trackingLock) {
- for (int i=0; i<objects.length; i++) {
- if (objects [i] == null) {
- objects [i] = object;
- errors [i] = new Error ();
- return;
- }
- }
- Object [] newObjects = new Object [objects.length + 128];
- System.arraycopy (objects, 0, newObjects, 0, objects.length);
- newObjects [objects.length] = object;
- objects = newObjects;
- Error [] newErrors = new Error [errors.length + 128];
- System.arraycopy (errors, 0, newErrors, 0, errors.length);
- newErrors [errors.length] = new Error ();
- errors = newErrors;
- }
-}
-
-void printErrors () {
- if (!DEBUG) return;
- if (tracking) {
- synchronized (trackingLock) {
- if (objects == null || errors == null) return;
- int objectCount = 0;
- int colors = 0, cursors = 0, fonts = 0, gcs = 0, images = 0;
- int paths = 0, patterns = 0, regions = 0, textLayouts = 0, transforms = 0;
- for (int i=0; i<objects.length; i++) {
- Object object = objects [i];
- if (object != null) {
- objectCount++;
- if (object instanceof Color) colors++;
- if (object instanceof Cursor) cursors++;
- if (object instanceof Font) fonts++;
- if (object instanceof GC) gcs++;
- if (object instanceof Image) images++;
- if (object instanceof Path) paths++;
- if (object instanceof Pattern) patterns++;
- if (object instanceof Region) regions++;
- if (object instanceof TextLayout) textLayouts++;
- if (object instanceof Transform) transforms++;
- }
- }
- if (objectCount != 0) {
- String string = "Summary: ";
- if (colors != 0) string += colors + " Color(s), ";
- if (cursors != 0) string += cursors + " Cursor(s), ";
- if (fonts != 0) string += fonts + " Font(s), ";
- if (gcs != 0) string += gcs + " GC(s), ";
- if (images != 0) string += images + " Image(s), ";
- if (paths != 0) string += paths + " Path(s), ";
- if (patterns != 0) string += patterns + " Pattern(s), ";
- if (regions != 0) string += regions + " Region(s), ";
- if (textLayouts != 0) string += textLayouts + " TextLayout(s), ";
- if (transforms != 0) string += transforms + " Transforms(s), ";
- if (string.length () != 0) {
- string = string.substring (0, string.length () - 2);
- System.err.println (string);
- }
- for (int i=0; i<errors.length; i++) {
- if (errors [i] != null) errors [i].printStackTrace (System.err);
- }
- }
- }
- }
-}
-
-/**
- * Releases any internal resources back to the operating
- * system and clears all fields except the device handle.
- * <p>
- * When a device is destroyed, resources that were acquired
- * on behalf of the programmer need to be returned to the
- * operating system. For example, if the device allocated a
- * font to be used as the system font, this font would be
- * freed in <code>release</code>. Also,to assist the garbage
- * collector and minimize the amount of memory that is not
- * reclaimed when the programmer keeps a reference to a
- * disposed device, all fields except the handle are zero'd.
- * The handle is needed by <code>destroy</code>.
- * </p>
- * This method is called before <code>destroy</code>.
- * </p><p>
- * If subclasses reimplement this method, they must
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #dispose
- * @see #destroy
- */
-protected void release () {
- if (gdipToken != null) {
- if (fontCollection != 0) {
- Gdip.PrivateFontCollection_delete(fontCollection);
- }
- fontCollection = 0;
- Gdip.GdiplusShutdown (gdipToken[0]);
- }
- gdipToken = null;
- scripts = null;
- if (hPalette != 0) OS.DeleteObject (hPalette);
- hPalette = 0;
- colorRefCount = null;
- logFonts = null;
- nFonts = 0;
-}
-
-/**
- * If the underlying window system supports printing warning messages
- * to the console, setting warnings to <code>false</code> prevents these
- * messages from being printed. If the argument is <code>true</code> then
- * message printing is not blocked.
- *
- * @param warnings <code>true</code>if warnings should be printed, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setWarnings (boolean warnings) {
- checkDevice ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/DeviceData.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/DeviceData.java
deleted file mode 100755
index 9b95c99718..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/DeviceData.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-public class DeviceData {
- /*
- * Debug fields - may not be honoured
- * on some SWT platforms.
- */
- public boolean debug;
- public boolean tracking;
- public Error [] errors;
- public Object [] objects;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Font.java
deleted file mode 100755
index 23cc7aa24f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Font.java
+++ /dev/null
@@ -1,258 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage operating system resources that
- * define how text looks when it is displayed. Fonts may be constructed
- * by providing a device and either name, size and style information
- * or a <code>FontData</code> object which encapsulates this data.
- * <p>
- * Application code must explicitly invoke the <code>Font.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see FontData
- * @see <a href="http://www.eclipse.org/swt/snippets/#font">Font snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class Font extends Resource {
-
- /**
- * the handle to the OS font resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Font(Device device) {
- super(device);
-}
-
-/**
- * Constructs a new font given a device and font data
- * which describes the desired font's appearance.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param fd the FontData that describes the desired font (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the fd argument is null</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li>
- * </ul>
- */
-public Font(Device device, FontData fd) {
- super(device);
- init(fd);
- init();
-}
-
-/**
- * Constructs a new font given a device and an array
- * of font data which describes the desired font's
- * appearance.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param fds the array of FontData that describes the desired font (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the fds argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the length of fds is zero</li>
- * <li>ERROR_NULL_ARGUMENT - if any fd in the array is null</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li>
- * </ul>
- *
- * @since 2.1
- */
-public Font(Device device, FontData[] fds) {
- super(device);
- if (fds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (fds.length == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<fds.length; i++) {
- if (fds[i] == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- init(fds[0]);
- init();
-}
-
-/**
- * Constructs a new font given a device, a font name,
- * the height of the desired font in points, and a font
- * style.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param name the name of the font (must not be null)
- * @param height the font height in points
- * @param style a bit or combination of NORMAL, BOLD, ITALIC
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the name argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given arguments</li>
- * </ul>
- */
-public Font(Device device, String name, int height, int style) {
- super(device);
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(new FontData (name, height, style));
- init();
-}
-
-/*public*/ Font(Device device, String name, float height, int style) {
- super(device);
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(new FontData (name, height, style));
- init();
-}
-void destroy() {
- OS.DeleteObject(handle);
- handle = 0;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals(Object object) {
- if (object == this) return true;
- if (!(object instanceof Font)) return false;
- Font font = (Font) object;
- return device == font.device && handle == font.handle;
-}
-
-/**
- * Returns an array of <code>FontData</code>s representing the receiver.
- * On Windows, only one FontData will be returned per font. On X however,
- * a <code>Font</code> object <em>may</em> be composed of multiple X
- * fonts. To support this case, we return an array of font data objects.
- *
- * @return an array of font data objects describing the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontData[] getFontData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- LOGFONT logFont = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA();
- OS.GetObject(handle, LOGFONT.sizeof, logFont);
- return new FontData[] {FontData.win32_new(logFont, device.computePoints(logFont, handle))};
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return (int)/*64*/handle;
-}
-
-void init (FontData fd) {
- if (fd == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- LOGFONT logFont = fd.data;
- int lfHeight = logFont.lfHeight;
- logFont.lfHeight = device.computePixels(fd.height);
- handle = OS.CreateFontIndirect(logFont);
- logFont.lfHeight = lfHeight;
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
-}
-
-/**
- * Returns <code>true</code> if the font has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the font.
- * When a font has been disposed, it is an error to
- * invoke any other method using the font.
- *
- * @return <code>true</code> when the font is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Font {*DISPOSED*}";
- return "Font {" + handle + "}";
-}
-
-/**
- * Invokes platform specific functionality to allocate a new font.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Font</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param handle the handle for the font
- * @return a new font object containing the specified device and handle
- */
-public static Font win32_new(Device device, int /*long*/ handle) {
- Font font = new Font(device);
- font.handle = handle;
- return font;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontData.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontData.java
deleted file mode 100755
index 15e6cb2472..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontData.java
+++ /dev/null
@@ -1,669 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class describe operating system fonts.
- * <p>
- * For platform-independent behaviour, use the get and set methods
- * corresponding to the following properties:
- * <dl>
- * <dt>height</dt><dd>the height of the font in points</dd>
- * <dt>name</dt><dd>the face name of the font, which may include the foundry</dd>
- * <dt>style</dt><dd>A bitwise combination of NORMAL, ITALIC and BOLD</dd>
- * </dl>
- * If extra, platform-dependent functionality is required:
- * <ul>
- * <li>On <em>Windows</em>, the data member of the <code>FontData</code>
- * corresponds to a Windows <code>LOGFONT</code> structure whose fields
- * may be retrieved and modified.</li>
- * <li>On <em>X</em>, the fields of the <code>FontData</code> correspond
- * to the entries in the font's XLFD name and may be retrieved and modified.
- * </ul>
- * Application code does <em>not</em> need to explicitly release the
- * resources managed by each instance when those instances are no longer
- * required, and thus no <code>dispose()</code> method is provided.
- *
- * @see Font
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class FontData {
-
- /**
- * A Win32 LOGFONT struct
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public LOGFONT data;
-
- /**
- * The height of the font data in points
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public float height;
-
- /**
- * The locales of the font
- */
- String lang, country, variant;
-
-/**
- * Constructs a new uninitialized font data.
- */
-public FontData() {
- data = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA();
- // We set the charset field so that
- // wildcard searching will work properly
- // out of the box
- data.lfCharSet = (byte)OS.DEFAULT_CHARSET;
- height = 12;
-}
-
-/**
- * Constructs a new font data given the Windows <code>LOGFONT</code>
- * that it should represent.
- *
- * @param data the <code>LOGFONT</code> for the result
- */
-FontData(LOGFONT data, float height) {
- this.data = data;
- this.height = height;
-}
-
-/**
- * Constructs a new FontData given a string representation
- * in the form generated by the <code>FontData.toString</code>
- * method.
- * <p>
- * Note that the representation varies between platforms,
- * and a FontData can only be created from a string that was
- * generated on the same platform.
- * </p>
- *
- * @param string the string representation of a <code>FontData</code> (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument does not represent a valid description</li>
- * </ul>
- *
- * @see #toString
- */
-public FontData(String string) {
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int start = 0;
- int end = string.indexOf('|');
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- String version1 = string.substring(start, end);
- try {
- if (Integer.parseInt(version1) != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- String name = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- float height = 0;
- try {
- height = Float.parseFloat(string.substring(start, end));
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int style = 0;
- try {
- style = Integer.parseInt(string.substring(start, end));
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- data = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA();
- data.lfCharSet = (byte)OS.DEFAULT_CHARSET;
- setName(name);
- setHeight(height);
- setStyle(style);
- if (end == -1) return;
- String platform = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- String version2 = string.substring(start, end);
-
- if (platform.equals("WINDOWS") && version2.equals("1")) { //$NON-NLS-1$//$NON-NLS-2$
- LOGFONT newData = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA();
- try {
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- newData.lfHeight = Integer.parseInt(string.substring(start, end));
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- newData.lfWidth = Integer.parseInt(string.substring(start, end));
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- newData.lfEscapement = Integer.parseInt(string.substring(start, end));
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- newData.lfOrientation = Integer.parseInt(string.substring(start, end));
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- newData.lfWeight = Integer.parseInt(string.substring(start, end));
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- newData.lfItalic = Byte.parseByte(string.substring(start, end));
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- newData.lfUnderline = Byte.parseByte(string.substring(start, end));
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- newData.lfStrikeOut = Byte.parseByte(string.substring(start, end));
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- newData.lfCharSet = Byte.parseByte(string.substring(start, end));
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- newData.lfOutPrecision = Byte.parseByte(string.substring(start, end));
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- newData.lfClipPrecision = Byte.parseByte(string.substring(start, end));
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- newData.lfQuality = Byte.parseByte(string.substring(start, end));
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- newData.lfPitchAndFamily = Byte.parseByte(string.substring(start, end));
- start = end + 1;
- } catch (NumberFormatException e) {
- setName(name);
- setHeight(height);
- setStyle(style);
- return;
- }
- TCHAR buffer = new TCHAR(0, string.substring(start), false);
- int length = Math.min(OS.LF_FACESIZE - 1, buffer.length());
- if (OS.IsUnicode) {
- char[] lfFaceName = ((LOGFONTW)newData).lfFaceName;
- System.arraycopy(buffer.chars, 0, lfFaceName, 0, length);
- } else {
- byte[] lfFaceName = ((LOGFONTA)newData).lfFaceName;
- System.arraycopy(buffer.bytes, 0, lfFaceName, 0, length);
- }
- data = newData;
- }
-}
-
-/**
- * Constructs a new font data given a font name,
- * the height of the desired font in points,
- * and a font style.
- *
- * @param name the name of the font (must not be null)
- * @param height the font height in points
- * @param style a bit or combination of NORMAL, BOLD, ITALIC
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - when the font name is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- */
-public FontData(String name, int height, int style) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- data = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA();
- setName(name);
- setHeight(height);
- setStyle(style);
- // We set the charset field so that
- // wildcard searching will work properly
- // out of the box
- data.lfCharSet = (byte)OS.DEFAULT_CHARSET;
-}
-
-/*public*/ FontData(String name, float height, int style) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- data = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA();
- setName(name);
- setHeight(height);
- setStyle(style);
- // We set the charset field so that
- // wildcard searching will work properly
- // out of the box
- data.lfCharSet = (byte)OS.DEFAULT_CHARSET;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof FontData)) return false;
- FontData fd = (FontData)object;
- LOGFONT lf = fd.data;
- return data.lfCharSet == lf.lfCharSet &&
- /*
- * This code is intentionally commented. When creating
- * a FontData, lfHeight is not necessarily set. Instead
- * we check the height field which is always set.
- */
-// data.lfHeight == lf.lfHeight &&
- height == fd.height &&
- data.lfWidth == lf.lfWidth &&
- data.lfEscapement == lf.lfEscapement &&
- data.lfOrientation == lf.lfOrientation &&
- data.lfWeight == lf.lfWeight &&
- data.lfItalic == lf.lfItalic &&
- data.lfUnderline == lf.lfUnderline &&
- data.lfStrikeOut == lf.lfStrikeOut &&
- data.lfCharSet == lf.lfCharSet &&
- data.lfOutPrecision == lf.lfOutPrecision &&
- data.lfClipPrecision == lf.lfClipPrecision &&
- data.lfQuality == lf.lfQuality &&
- data.lfPitchAndFamily == lf.lfPitchAndFamily &&
- getName().equals(fd.getName());
-}
-
-int /*long*/ EnumLocalesProc(int /*long*/ lpLocaleString) {
-
- /* Get the locale ID */
- int length = 8;
- TCHAR buffer = new TCHAR(0, length);
- int byteCount = length * TCHAR.sizeof;
- OS.MoveMemory(buffer, lpLocaleString, byteCount);
- int lcid = Integer.parseInt(buffer.toString(0, buffer.strlen ()), 16);
-
- /* Check the language */
- int size = OS.GetLocaleInfo(lcid, OS.LOCALE_SISO639LANGNAME, buffer, length);
- if (size <= 0 || !lang.equals(buffer.toString(0, size - 1))) return 1;
-
- /* Check the country */
- if (country != null) {
- size = OS.GetLocaleInfo(lcid, OS.LOCALE_SISO3166CTRYNAME, buffer, length);
- if (size <= 0 || !country.equals(buffer.toString(0, size - 1))) return 1;
- }
-
- /* Get the charset */
- size = OS.GetLocaleInfo(lcid, OS.LOCALE_IDEFAULTANSICODEPAGE, buffer, length);
- if (size <= 0) return 1;
- int cp = Integer.parseInt(buffer.toString(0, size - 1));
- int [] lpCs = new int[8];
- OS.TranslateCharsetInfo(cp, lpCs, OS.TCI_SRCCODEPAGE);
- data.lfCharSet = (byte)lpCs[0];
-
- return 0;
-}
-
-/**
- * Returns the height of the receiver in points.
- *
- * @return the height of this FontData
- *
- * @see #setHeight(int)
- */
-public int getHeight() {
- return (int)(0.5f + height);
-}
-
-/*public*/ float getHeightF() {
- return height;
-}
-
-/**
- * Returns the locale of the receiver.
- * <p>
- * The locale determines which platform character set this
- * font is going to use. Widgets and graphics operations that
- * use this font will convert UNICODE strings to the platform
- * character set of the specified locale.
- * </p>
- * <p>
- * On platforms where there are multiple character sets for a
- * given language/country locale, the variant portion of the
- * locale will determine the character set.
- * </p>
- *
- * @return the <code>String</code> representing a Locale object
- * @since 3.0
- */
-public String getLocale () {
- StringBuffer buffer = new StringBuffer ();
- char sep = '_';
- if (lang != null) {
- buffer.append (lang);
- buffer.append (sep);
- }
- if (country != null) {
- buffer.append (country);
- buffer.append (sep);
- }
- if (variant != null) {
- buffer.append (variant);
- }
-
- String result = buffer.toString ();
- int length = result.length ();
- if (length > 0) {
- if (result.charAt (length - 1) == sep) {
- result = result.substring (0, length - 1);
- }
- }
- return result;
-}
-
-/**
- * Returns the name of the receiver.
- * On platforms that support font foundries, the return value will
- * be the foundry followed by a dash ("-") followed by the face name.
- *
- * @return the name of this <code>FontData</code>
- *
- * @see #setName
- */
-public String getName() {
- char[] chars;
- if (OS.IsUnicode) {
- chars = ((LOGFONTW)data).lfFaceName;
- } else {
- chars = new char[OS.LF_FACESIZE];
- byte[] bytes = ((LOGFONTA)data).lfFaceName;
- OS.MultiByteToWideChar (OS.CP_ACP, OS.MB_PRECOMPOSED, bytes, bytes.length, chars, chars.length);
- }
- int index = 0;
- while (index < chars.length) {
- if (chars [index] == 0) break;
- index++;
- }
- return new String (chars, 0, index);
-}
-
-/**
- * Returns the style of the receiver which is a bitwise OR of
- * one or more of the <code>SWT</code> constants NORMAL, BOLD
- * and ITALIC.
- *
- * @return the style of this <code>FontData</code>
- *
- * @see #setStyle
- */
-public int getStyle() {
- int style = SWT.NORMAL;
- if (data.lfWeight == 700) style |= SWT.BOLD;
- if (data.lfItalic != 0) style |= SWT.ITALIC;
- return style;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return data.lfCharSet ^ getHeight() ^ data.lfWidth ^ data.lfEscapement ^
- data.lfOrientation ^ data.lfWeight ^ data.lfItalic ^data.lfUnderline ^
- data.lfStrikeOut ^ data.lfCharSet ^ data.lfOutPrecision ^
- data.lfClipPrecision ^ data.lfQuality ^ data.lfPitchAndFamily ^
- getName().hashCode();
-}
-
-/**
- * Sets the height of the receiver. The parameter is
- * specified in terms of points, where a point is one
- * seventy-second of an inch.
- *
- * @param height the height of the <code>FontData</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- *
- * @see #getHeight
- */
-public void setHeight(int height) {
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.height = height;
-}
-
-/*public*/ void setHeight(float height) {
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.height = height;
-}
-
-/**
- * Sets the locale of the receiver.
- * <p>
- * The locale determines which platform character set this
- * font is going to use. Widgets and graphics operations that
- * use this font will convert UNICODE strings to the platform
- * character set of the specified locale.
- * </p>
- * <p>
- * On platforms where there are multiple character sets for a
- * given language/country locale, the variant portion of the
- * locale will determine the character set.
- * </p>
- *
- * @param locale the <code>String</code> representing a Locale object
- * @see java.util.Locale#toString
- */
-public void setLocale(String locale) {
- lang = country = variant = null;
- if (locale != null) {
- char sep = '_';
- int length = locale.length();
- int firstSep, secondSep;
-
- firstSep = locale.indexOf(sep);
- if (firstSep == -1) {
- firstSep = secondSep = length;
- } else {
- secondSep = locale.indexOf(sep, firstSep + 1);
- if (secondSep == -1) secondSep = length;
- }
- if (firstSep > 0) lang = locale.substring(0, firstSep);
- if (secondSep > firstSep + 1) country = locale.substring(firstSep + 1, secondSep);
- if (length > secondSep + 1) variant = locale.substring(secondSep + 1);
- }
- if (lang == null) {
- data.lfCharSet = (byte)OS.DEFAULT_CHARSET;
- } else {
- Callback callback = new Callback (this, "EnumLocalesProc", 1); //$NON-NLS-1$
- int /*long*/ lpEnumLocalesProc = callback.getAddress ();
- if (lpEnumLocalesProc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- OS.EnumSystemLocales(lpEnumLocalesProc, OS.LCID_SUPPORTED);
- callback.dispose ();
- }
-}
-
-/**
- * Sets the name of the receiver.
- * <p>
- * Some platforms support font foundries. On these platforms, the name
- * of the font specified in setName() may have one of the following forms:
- * <ol>
- * <li>a face name (for example, "courier")</li>
- * <li>a foundry followed by a dash ("-") followed by a face name (for example, "adobe-courier")</li>
- * </ol>
- * In either case, the name returned from getName() will include the
- * foundry.
- * </p>
- * <p>
- * On platforms that do not support font foundries, only the face name
- * (for example, "courier") is used in <code>setName()</code> and
- * <code>getName()</code>.
- * </p>
- *
- * @param name the name of the font data (must not be null)
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - when the font name is null</li>
- * </ul>
- *
- * @see #getName
- */
-public void setName(String name) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
-
- /* The field lfFaceName must be NULL terminated */
- TCHAR buffer = new TCHAR(0, name, true);
- int length = Math.min(OS.LF_FACESIZE - 1, buffer.length());
- if (OS.IsUnicode) {
- char[] lfFaceName = ((LOGFONTW)data).lfFaceName;
- for (int i = 0; i < lfFaceName.length; i++) lfFaceName[i] = 0;
- System.arraycopy(buffer.chars, 0, lfFaceName, 0, length);
- } else {
- byte[] lfFaceName = ((LOGFONTA)data).lfFaceName;
- for (int i = 0; i < lfFaceName.length; i++) lfFaceName[i] = 0;
- System.arraycopy(buffer.bytes, 0, lfFaceName, 0, length);
- }
-}
-
-/**
- * Sets the style of the receiver to the argument which must
- * be a bitwise OR of one or more of the <code>SWT</code>
- * constants NORMAL, BOLD and ITALIC. All other style bits are
- * ignored.
- *
- * @param style the new style for this <code>FontData</code>
- *
- * @see #getStyle
- */
-public void setStyle(int style) {
- if ((style & SWT.BOLD) == SWT.BOLD) {
- data.lfWeight = 700;
- } else {
- data.lfWeight = 0;
- }
- if ((style & SWT.ITALIC) == SWT.ITALIC) {
- data.lfItalic = 1;
- } else {
- data.lfItalic = 0;
- }
-}
-
-/**
- * Returns a string representation of the receiver which is suitable
- * for constructing an equivalent instance using the
- * <code>FontData(String)</code> constructor.
- *
- * @return a string representation of the FontData
- *
- * @see FontData
- */
-public String toString() {
- StringBuffer buffer = new StringBuffer(128);
- buffer.append("1|"); //$NON-NLS-1$
- String name = getName();
- buffer.append(name);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(getHeightF());
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(getStyle());
- buffer.append("|"); //$NON-NLS-1$
- buffer.append("WINDOWS|1|"); //$NON-NLS-1$
- buffer.append(data.lfHeight);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(data.lfWidth);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(data.lfEscapement);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(data.lfOrientation);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(data.lfWeight);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(data.lfItalic);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(data.lfUnderline);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(data.lfStrikeOut);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(data.lfCharSet);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(data.lfOutPrecision);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(data.lfClipPrecision);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(data.lfQuality);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(data.lfPitchAndFamily);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(name);
- return buffer.toString();
-}
-
-/**
- * Invokes platform specific functionality to allocate a new font data.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>FontData</code>. It is marked public only so that
- * it can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the <code>LOGFONT</code> for the font data
- * @param height the height of the font data
- * @return a new font data object containing the specified <code>LOGFONT</code> and height
- */
-public static FontData win32_new(LOGFONT data, float height) {
- return new FontData(data, height);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontMetrics.java
deleted file mode 100755
index bfa851cd98..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontMetrics.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.win32.*;
-
-/**
- * Instances of this class provide measurement information
- * about fonts including ascent, descent, height, leading
- * space between rows, and average character width.
- * <code>FontMetrics</code> are obtained from <code>GC</code>s
- * using the <code>getFontMetrics()</code> method.
- *
- * @see GC#getFontMetrics
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class FontMetrics {
-
- /**
- * On Windows, handle is a Win32 TEXTMETRIC struct
- * On Photon, handle is a Photon FontQueryInfo struct
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public TEXTMETRIC handle;
-
-/**
- * Prevents instances from being created outside the package.
- */
-FontMetrics() {
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof FontMetrics)) return false;
- TEXTMETRIC metric = ((FontMetrics)object).handle;
- return handle.tmHeight == metric.tmHeight &&
- handle.tmAscent == metric.tmAscent &&
- handle.tmDescent == metric.tmDescent &&
- handle.tmInternalLeading == metric.tmInternalLeading &&
- handle.tmExternalLeading == metric.tmExternalLeading &&
- handle.tmAveCharWidth == metric.tmAveCharWidth &&
- handle.tmMaxCharWidth == metric.tmMaxCharWidth &&
- handle.tmWeight == metric.tmWeight &&
- handle.tmOverhang == metric.tmOverhang &&
- handle.tmDigitizedAspectX == metric.tmDigitizedAspectX &&
- handle.tmDigitizedAspectY == metric.tmDigitizedAspectY &&
-// handle.tmFirstChar == metric.tmFirstChar &&
-// handle.tmLastChar == metric.tmLastChar &&
-// handle.tmDefaultChar == metric.tmDefaultChar &&
-// handle.tmBreakChar == metric.tmBreakChar &&
- handle.tmItalic == metric.tmItalic &&
- handle.tmUnderlined == metric.tmUnderlined &&
- handle.tmStruckOut == metric.tmStruckOut &&
- handle.tmPitchAndFamily == metric.tmPitchAndFamily &&
- handle.tmCharSet == metric.tmCharSet;
-}
-
-/**
- * Returns the ascent of the font described by the receiver. A
- * font's <em>ascent</em> is the distance from the baseline to the
- * top of actual characters, not including any of the leading area,
- * measured in pixels.
- *
- * @return the ascent of the font
- */
-public int getAscent() {
- return handle.tmAscent - handle.tmInternalLeading;
-}
-
-/**
- * Returns the average character width, measured in pixels,
- * of the font described by the receiver.
- *
- * @return the average character width of the font
- */
-public int getAverageCharWidth() {
- return handle.tmAveCharWidth;
-}
-
-/**
- * Returns the descent of the font described by the receiver. A
- * font's <em>descent</em> is the distance from the baseline to the
- * bottom of actual characters, not including any of the leading area,
- * measured in pixels.
- *
- * @return the descent of the font
- */
-public int getDescent() {
- return handle.tmDescent;
-}
-
-/**
- * Returns the height of the font described by the receiver,
- * measured in pixels. A font's <em>height</em> is the sum of
- * its ascent, descent and leading area.
- *
- * @return the height of the font
- *
- * @see #getAscent
- * @see #getDescent
- * @see #getLeading
- */
-public int getHeight() {
- return handle.tmHeight;
-}
-
-/**
- * Returns the leading area of the font described by the
- * receiver. A font's <em>leading area</em> is the space
- * above its ascent which may include accents or other marks.
- *
- * @return the leading space of the font
- */
-public int getLeading() {
- return handle.tmInternalLeading;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode() {
- return handle.tmHeight ^ handle.tmAscent ^ handle.tmDescent ^
- handle.tmInternalLeading ^ handle.tmExternalLeading ^
- handle.tmAveCharWidth ^ handle.tmMaxCharWidth ^ handle.tmWeight ^
- handle.tmOverhang ^ handle.tmDigitizedAspectX ^ handle.tmDigitizedAspectY ^
-// handle.tmFirstChar ^ handle.tmLastChar ^ handle.tmDefaultChar ^ handle.tmBreakChar ^
- handle.tmItalic ^ handle.tmUnderlined ^ handle.tmStruckOut ^
- handle.tmPitchAndFamily ^ handle.tmCharSet;
-}
-
-/**
- * Invokes platform specific functionality to allocate a new font metrics.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>FontMetrics</code>. It is marked public only so that
- * it can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param handle the <code>TEXTMETRIC</code> containing information about a font
- * @return a new font metrics object containing the specified <code>TEXTMETRIC</code>
- */
-public static FontMetrics win32_new(TEXTMETRIC handle) {
- FontMetrics fontMetrics = new FontMetrics();
- fontMetrics.handle = handle;
- return fontMetrics;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java
deleted file mode 100755
index e08cbf3e48..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java
+++ /dev/null
@@ -1,4979 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gdip.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-
-/**
- * Class <code>GC</code> is where all of the drawing capabilities that are
- * supported by SWT are located. Instances are used to draw on either an
- * <code>Image</code>, a <code>Control</code>, or directly on a <code>Display</code>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * </dl>
- *
- * <p>
- * The SWT drawing coordinate system is the two-dimensional space with the origin
- * (0,0) at the top left corner of the drawing area and with (x,y) values increasing
- * to the right and downward respectively.
- * </p>
- *
- * <p>
- * The result of drawing on an image that was created with an indexed
- * palette using a color that is not in the palette is platform specific.
- * Some platforms will match to the nearest color while other will draw
- * the color itself. This happens because the allocated image might use
- * a direct palette on platforms that do not support indexed palette.
- * </p>
- *
- * <p>
- * Application code must explicitly invoke the <code>GC.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required. This is <em>particularly</em>
- * important on Windows95 and Windows98 where the operating system has a limited
- * number of device contexts available.
- * </p>
- *
- * <p>
- * Note: Only one of LEFT_TO_RIGHT and RIGHT_TO_LEFT may be specified.
- * </p>
- *
- * @see org.eclipse.swt.events.PaintEvent
- * @see <a href="http://www.eclipse.org/swt/snippets/#gc">GC snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class GC extends Resource {
-
- /**
- * the handle to the OS device context
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
-
- Drawable drawable;
- GCData data;
-
- static final int FOREGROUND = 1 << 0;
- static final int BACKGROUND = 1 << 1;
- static final int FONT = 1 << 2;
- static final int LINE_STYLE = 1 << 3;
- static final int LINE_WIDTH = 1 << 4;
- static final int LINE_CAP = 1 << 5;
- static final int LINE_JOIN = 1 << 6;
- static final int LINE_MITERLIMIT = 1 << 7;
- static final int FOREGROUND_TEXT = 1 << 8;
- static final int BACKGROUND_TEXT = 1 << 9;
- static final int BRUSH = 1 << 10;
- static final int PEN = 1 << 11;
- static final int NULL_BRUSH = 1 << 12;
- static final int NULL_PEN = 1 << 13;
- static final int DRAW_OFFSET = 1 << 14;
-
- static final int DRAW = FOREGROUND | LINE_STYLE | LINE_WIDTH | LINE_CAP | LINE_JOIN | LINE_MITERLIMIT | PEN | NULL_BRUSH | DRAW_OFFSET;
- static final int FILL = BACKGROUND | BRUSH | NULL_PEN;
-
- static final float[] LINE_DOT_ZERO = new float[]{3, 3};
- static final float[] LINE_DASH_ZERO = new float[]{18, 6};
- static final float[] LINE_DASHDOT_ZERO = new float[]{9, 6, 3, 6};
- static final float[] LINE_DASHDOTDOT_ZERO = new float[]{9, 3, 3, 3, 3, 3};
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-GC() {
-}
-
-/**
- * Constructs a new instance of this class which has been
- * configured to draw on the specified drawable. Sets the
- * foreground color, background color and font in the GC
- * to match those in the drawable.
- * <p>
- * You must dispose the graphics context when it is no longer required.
- * </p>
- * @param drawable the drawable to draw on
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li>
- * <li>ERROR_NULL_ARGUMENT - if there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT
- * - if the drawable is an image that is not a bitmap or an icon
- * - if the drawable is an image or printer that is already selected
- * into another graphics context</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li>
- * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li>
- * </ul>
- */
-public GC(Drawable drawable) {
- this(drawable, SWT.NONE);
-}
-
-/**
- * Constructs a new instance of this class which has been
- * configured to draw on the specified drawable. Sets the
- * foreground color, background color and font in the GC
- * to match those in the drawable.
- * <p>
- * You must dispose the graphics context when it is no longer required.
- * </p>
- *
- * @param drawable the drawable to draw on
- * @param style the style of GC to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li>
- * <li>ERROR_NULL_ARGUMENT - if there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT
- * - if the drawable is an image that is not a bitmap or an icon
- * - if the drawable is an image or printer that is already selected
- * into another graphics context</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li>
- * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public GC(Drawable drawable, int style) {
- if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- GCData data = new GCData ();
- data.style = checkStyle(style);
- int /*long*/ hDC = drawable.internal_new_GC(data);
- Device device = data.device;
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = data.device = device;
- init (drawable, data, hDC);
- init();
-}
-
-static int checkStyle(int style) {
- if ((style & SWT.LEFT_TO_RIGHT) != 0) style &= ~SWT.RIGHT_TO_LEFT;
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-void checkGC(int mask) {
- int state = data.state;
- if ((state & mask) == mask) return;
- state = (state ^ mask) & mask;
- data.state |= mask;
- int /*long*/ gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- int /*long*/ pen = data.gdipPen;
- float width = data.lineWidth;
- if ((state & FOREGROUND) != 0 || (pen == 0 && (state & (LINE_WIDTH | LINE_STYLE | LINE_MITERLIMIT | LINE_JOIN | LINE_CAP)) != 0)) {
- if (data.gdipFgBrush != 0) Gdip.SolidBrush_delete(data.gdipFgBrush);
- data.gdipFgBrush = 0;
- int /*long*/ brush;
- Pattern pattern = data.foregroundPattern;
- if (pattern != null) {
- brush = pattern.handle;
- if ((data.style & SWT.MIRRORED) != 0) {
- switch (Gdip.Brush_GetType(brush)) {
- case Gdip.BrushTypeTextureFill:
- brush = Gdip.Brush_Clone(brush);
- if (brush == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Gdip.TextureBrush_ScaleTransform(brush, -1, 1, Gdip.MatrixOrderPrepend);
- data.gdipFgBrush = brush;
- }
- }
- } else {
- int foreground = data.foreground;
- int rgb = ((foreground >> 16) & 0xFF) | (foreground & 0xFF00) | ((foreground & 0xFF) << 16);
- int /*long*/ color = Gdip.Color_new(data.alpha << 24 | rgb);
- if (color == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- brush = Gdip.SolidBrush_new(color);
- if (brush == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Gdip.Color_delete(color);
- data.gdipFgBrush = brush;
- }
- if (pen != 0) {
- Gdip.Pen_SetBrush(pen, brush);
- } else {
- pen = data.gdipPen = Gdip.Pen_new(brush, width);
- }
- }
- if ((state & LINE_WIDTH) != 0) {
- Gdip.Pen_SetWidth(pen, width);
- switch (data.lineStyle) {
- case SWT.LINE_CUSTOM:
- state |= LINE_STYLE;
- }
- }
- if ((state & LINE_STYLE) != 0) {
- float[] dashes = null;
- float dashOffset = 0;
- int dashStyle = Gdip.DashStyleSolid;
- switch (data.lineStyle) {
- case SWT.LINE_SOLID: break;
- case SWT.LINE_DOT: dashStyle = Gdip.DashStyleDot; if (width == 0) dashes = LINE_DOT_ZERO; break;
- case SWT.LINE_DASH: dashStyle = Gdip.DashStyleDash; if (width == 0) dashes = LINE_DASH_ZERO; break;
- case SWT.LINE_DASHDOT: dashStyle = Gdip.DashStyleDashDot; if (width == 0) dashes = LINE_DASHDOT_ZERO; break;
- case SWT.LINE_DASHDOTDOT: dashStyle = Gdip.DashStyleDashDotDot; if (width == 0) dashes = LINE_DASHDOTDOT_ZERO; break;
- case SWT.LINE_CUSTOM: {
- if (data.lineDashes != null) {
- dashOffset = data.lineDashesOffset / Math.max (1, width);
- dashes = new float[data.lineDashes.length * 2];
- for (int i = 0; i < data.lineDashes.length; i++) {
- float dash = data.lineDashes[i] / Math.max (1, width);
- dashes[i] = dash;
- dashes[i + data.lineDashes.length] = dash;
- }
- }
- }
- }
- if (dashes != null) {
- Gdip.Pen_SetDashPattern(pen, dashes, dashes.length);
- Gdip.Pen_SetDashStyle(pen, Gdip.DashStyleCustom);
- Gdip.Pen_SetDashOffset(pen, dashOffset);
- } else {
- Gdip.Pen_SetDashStyle(pen, dashStyle);
- }
- }
- if ((state & LINE_MITERLIMIT) != 0) {
- Gdip.Pen_SetMiterLimit(pen, data.lineMiterLimit);
- }
- if ((state & LINE_JOIN) != 0) {
- int joinStyle = 0;
- switch (data.lineJoin) {
- case SWT.JOIN_MITER: joinStyle = Gdip.LineJoinMiter; break;
- case SWT.JOIN_BEVEL: joinStyle = Gdip.LineJoinBevel; break;
- case SWT.JOIN_ROUND: joinStyle = Gdip.LineJoinRound; break;
- }
- Gdip.Pen_SetLineJoin(pen, joinStyle);
- }
- if ((state & LINE_CAP) != 0) {
- int dashCap = Gdip.DashCapFlat, capStyle = 0;
- switch (data.lineCap) {
- case SWT.CAP_FLAT: capStyle = Gdip.LineCapFlat; break;
- case SWT.CAP_ROUND: capStyle = Gdip.LineCapRound; dashCap = Gdip.DashCapRound; break;
- case SWT.CAP_SQUARE: capStyle = Gdip.LineCapSquare; break;
- }
- Gdip.Pen_SetLineCap(pen, capStyle, capStyle, dashCap);
- }
- if ((state & BACKGROUND) != 0) {
- if (data.gdipBgBrush != 0) Gdip.SolidBrush_delete(data.gdipBgBrush);
- data.gdipBgBrush = 0;
- Pattern pattern = data.backgroundPattern;
- if (pattern != null) {
- data.gdipBrush = pattern.handle;
- if ((data.style & SWT.MIRRORED) != 0) {
- switch (Gdip.Brush_GetType(data.gdipBrush)) {
- case Gdip.BrushTypeTextureFill:
- int /*long*/ brush = Gdip.Brush_Clone(data.gdipBrush);
- if (brush == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Gdip.TextureBrush_ScaleTransform(brush, -1, 1, Gdip.MatrixOrderPrepend);
- data.gdipBrush = data.gdipBgBrush = brush;
- }
- }
- } else {
- int background = data.background;
- int rgb = ((background >> 16) & 0xFF) | (background & 0xFF00) | ((background & 0xFF) << 16);
- int /*long*/ color = Gdip.Color_new(data.alpha << 24 | rgb);
- if (color == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ brush = Gdip.SolidBrush_new(color);
- if (brush == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Gdip.Color_delete(color);
- data.gdipBrush = data.gdipBgBrush = brush;
- }
- }
- if ((state & FONT) != 0) {
- Font font = data.font;
- OS.SelectObject(handle, font.handle);
- int /*long*/[] hFont = new int /*long*/[1];
- int /*long*/ gdipFont = createGdipFont(handle, font.handle, gdipGraphics, device.fontCollection, null, hFont);
- if (hFont[0] != 0) {
- OS.SelectObject(handle, hFont[0]);
- if (data.hGDIFont != 0) OS.DeleteObject(data.hGDIFont);
- data.hGDIFont = hFont[0];
- }
- if (data.gdipFont != 0) Gdip.Font_delete(data.gdipFont);
- data.gdipFont = gdipFont;
- }
- if ((state & DRAW_OFFSET) != 0) {
- data.gdipXOffset = data.gdipYOffset = 0;
- int /*long*/ matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0);
- PointF point = new PointF();
- point.X = point.Y = 1;
- Gdip.Graphics_GetTransform(gdipGraphics, matrix);
- Gdip.Matrix_TransformVectors(matrix, point, 1);
- Gdip.Matrix_delete(matrix);
- float scaling = point.X;
- if (scaling < 0) scaling = -scaling;
- float penWidth = data.lineWidth * scaling;
- if (penWidth == 0 || ((int)penWidth % 2) == 1) {
- data.gdipXOffset = 0.5f / scaling;
- }
- scaling = point.Y;
- if (scaling < 0) scaling = -scaling;
- penWidth = data.lineWidth * scaling;
- if (penWidth == 0 || ((int)penWidth % 2) == 1) {
- data.gdipYOffset = 0.5f / scaling;
- }
- }
- return;
- }
- if ((state & (FOREGROUND | LINE_CAP | LINE_JOIN | LINE_STYLE | LINE_WIDTH)) != 0) {
- int color = data.foreground;
- int width = (int)data.lineWidth;
- int[] dashes = null;
- int lineStyle = OS.PS_SOLID;
- switch (data.lineStyle) {
- case SWT.LINE_SOLID: break;
- case SWT.LINE_DASH: lineStyle = OS.PS_DASH; break;
- case SWT.LINE_DOT: lineStyle = OS.PS_DOT; break;
- case SWT.LINE_DASHDOT: lineStyle = OS.PS_DASHDOT; break;
- case SWT.LINE_DASHDOTDOT: lineStyle = OS.PS_DASHDOTDOT; break;
- case SWT.LINE_CUSTOM: {
- if (data.lineDashes != null) {
- lineStyle = OS.PS_USERSTYLE;
- dashes = new int[data.lineDashes.length];
- for (int i = 0; i < dashes.length; i++) {
- dashes[i] = (int)data.lineDashes[i];
- }
- }
- break;
- }
- }
- if ((state & LINE_STYLE) != 0) {
- OS.SetBkMode(handle, data.lineStyle == SWT.LINE_SOLID ? OS.OPAQUE : OS.TRANSPARENT);
- }
- int joinStyle = 0;
- switch (data.lineJoin) {
- case SWT.JOIN_MITER: joinStyle = OS.PS_JOIN_MITER; break;
- case SWT.JOIN_ROUND: joinStyle = OS.PS_JOIN_ROUND; break;
- case SWT.JOIN_BEVEL: joinStyle = OS.PS_JOIN_BEVEL; break;
- }
- int capStyle = 0;
- switch (data.lineCap) {
- case SWT.CAP_ROUND: capStyle = OS.PS_ENDCAP_ROUND; break;
- case SWT.CAP_FLAT: capStyle = OS.PS_ENDCAP_FLAT; break;
- case SWT.CAP_SQUARE: capStyle = OS.PS_ENDCAP_SQUARE;break;
- }
- int style = lineStyle | joinStyle | capStyle;
- /*
- * Feature in Windows. Windows does not honour line styles other then
- * PS_SOLID for pens wider than 1 pixel created with CreatePen(). The fix
- * is to use ExtCreatePen() instead.
- */
- int /*long*/ newPen;
- if (OS.IsWinCE || (width == 0 && lineStyle != OS.PS_USERSTYLE) || style == 0) {
- newPen = OS.CreatePen(style & OS.PS_STYLE_MASK, width, color);
- } else {
- LOGBRUSH logBrush = new LOGBRUSH();
- logBrush.lbStyle = OS.BS_SOLID;
- logBrush.lbColor = color;
- /* Feature in Windows. PS_GEOMETRIC pens cannot have zero width. */
- newPen = OS.ExtCreatePen (style | OS.PS_GEOMETRIC, Math.max(1, width), logBrush, dashes != null ? dashes.length : 0, dashes);
- }
- OS.SelectObject(handle, newPen);
- data.state |= PEN;
- data.state &= ~NULL_PEN;
- if (data.hPen != 0) OS.DeleteObject(data.hPen);
- data.hPen = data.hOldPen = newPen;
- } else if ((state & PEN) != 0) {
- OS.SelectObject(handle, data.hOldPen);
- data.state &= ~NULL_PEN;
- } else if ((state & NULL_PEN) != 0) {
- data.hOldPen = OS.SelectObject(handle, OS.GetStockObject(OS.NULL_PEN));
- data.state &= ~PEN;
- }
- if ((state & BACKGROUND) != 0) {
- int /*long*/ newBrush = OS.CreateSolidBrush(data.background);
- OS.SelectObject(handle, newBrush);
- data.state |= BRUSH;
- data.state &= ~NULL_BRUSH;
- if (data.hBrush != 0) OS.DeleteObject(data.hBrush);
- data.hOldBrush = data.hBrush = newBrush;
- } else if ((state & BRUSH) != 0) {
- OS.SelectObject(handle, data.hOldBrush);
- data.state &= ~NULL_BRUSH;
- } else if ((state & NULL_BRUSH) != 0) {
- data.hOldBrush = OS.SelectObject(handle, OS.GetStockObject(OS.NULL_BRUSH));
- data.state &= ~BRUSH;
- }
- if ((state & BACKGROUND_TEXT) != 0) {
- OS.SetBkColor(handle, data.background);
- }
- if ((state & FOREGROUND_TEXT) != 0) {
- OS.SetTextColor(handle, data.foreground);
- }
- if ((state & FONT) != 0) {
- Font font = data.font;
- OS.SelectObject(handle, font.handle);
- }
-}
-
-/**
- * Copies a rectangular area of the receiver at the specified
- * position into the image, which must be of type <code>SWT.BITMAP</code>.
- *
- * @param image the image to copy into
- * @param x the x coordinate in the receiver of the area to be copied
- * @param y the y coordinate in the receiver of the area to be copied
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image is not a bitmap or has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void copyArea(Image image, int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-
- /* Copy the bitmap area */
- Rectangle rect = image.getBounds();
- int /*long*/ memHdc = OS.CreateCompatibleDC(handle);
- int /*long*/ hOldBitmap = OS.SelectObject(memHdc, image.handle);
- OS.BitBlt(memHdc, 0, 0, rect.width, rect.height, handle, x, y, OS.SRCCOPY);
- OS.SelectObject(memHdc, hOldBitmap);
- OS.DeleteDC(memHdc);
-}
-
-/**
- * Copies a rectangular area of the receiver at the source
- * position onto the receiver at the destination position.
- *
- * @param srcX the x coordinate in the receiver of the area to be copied
- * @param srcY the y coordinate in the receiver of the area to be copied
- * @param width the width of the area to copy
- * @param height the height of the area to copy
- * @param destX the x coordinate in the receiver of the area to copy to
- * @param destY the y coordinate in the receiver of the area to copy to
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY) {
- copyArea(srcX, srcY, width, height, destX, destY, true);
-}
-
-/**
- * Copies a rectangular area of the receiver at the source
- * position onto the receiver at the destination position.
- *
- * @param srcX the x coordinate in the receiver of the area to be copied
- * @param srcY the y coordinate in the receiver of the area to be copied
- * @param width the width of the area to copy
- * @param height the height of the area to copy
- * @param destX the x coordinate in the receiver of the area to copy to
- * @param destY the y coordinate in the receiver of the area to copy to
- * @param paint if <code>true</code> paint events will be generated for old and obscured areas
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-
- /*
- * Feature in WinCE. The function WindowFromDC is not part of the
- * WinCE SDK. The fix is to remember the HWND.
- */
- int /*long*/ hwnd = data.hwnd;
- if (hwnd == 0) {
- OS.BitBlt(handle, destX, destY, width, height, handle, srcX, srcY, OS.SRCCOPY);
- } else {
- RECT lprcClip = null;
- int /*long*/ hrgn = OS.CreateRectRgn(0, 0, 0, 0);
- if (OS.GetClipRgn(handle, hrgn) == 1) {
- lprcClip = new RECT();
- OS.GetRgnBox(hrgn, lprcClip);
- }
- OS.DeleteObject(hrgn);
- RECT lprcScroll = new RECT();
- OS.SetRect(lprcScroll, srcX, srcY, srcX + width, srcY + height);
- int flags = paint ? OS.SW_INVALIDATE | OS.SW_ERASE : 0;
- int res = OS.ScrollWindowEx(hwnd, destX - srcX, destY - srcY, lprcScroll, lprcClip, 0, null, flags);
-
- /*
- * Feature in WinCE. ScrollWindowEx does not accept combined
- * vertical and horizontal scrolling. The fix is to do a
- * BitBlt and invalidate the appropriate source area.
- */
- if (res == 0 && OS.IsWinCE) {
- OS.BitBlt(handle, destX, destY, width, height, handle, srcX, srcY, OS.SRCCOPY);
- if (paint) {
- int deltaX = destX - srcX, deltaY = destY - srcY;
- boolean disjoint = (destX + width < srcX) || (srcX + width < destX) || (destY + height < srcY) || (srcY + height < destY);
- if (disjoint) {
- OS.InvalidateRect(hwnd, lprcScroll, true);
- } else {
- if (deltaX != 0) {
- int newX = destX - deltaX;
- if (deltaX < 0) newX = destX + width;
- OS.SetRect(lprcScroll, newX, srcY, newX + Math.abs(deltaX), srcY + height);
- OS.InvalidateRect(hwnd, lprcScroll, true);
- }
- if (deltaY != 0) {
- int newY = destY - deltaY;
- if (deltaY < 0) newY = destY + height;
- OS.SetRect(lprcScroll, srcX, newY, srcX + width, newY + Math.abs(deltaY));
- OS.InvalidateRect(hwnd, lprcScroll, true);
- }
- }
- }
- }
- }
-}
-static int /*long*/ createGdipFont(int /*long*/ hDC, int /*long*/ hFont, int /*long*/ graphics, int /*long*/ fontCollection, int /*long*/ [] outFamily, int /*long*/[] outFont) {
- int /*long*/ font = Gdip.Font_new(hDC, hFont);
- if (font == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ family = 0;
- if (!Gdip.Font_IsAvailable(font)) {
- Gdip.Font_delete(font);
- LOGFONT logFont = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA();
- OS.GetObject(hFont, LOGFONT.sizeof, logFont);
- int size = Math.abs(logFont.lfHeight);
- int style = Gdip.FontStyleRegular;
- if (logFont.lfWeight == 700) style |= Gdip.FontStyleBold;
- if (logFont.lfItalic != 0) style |= Gdip.FontStyleItalic;
- char[] chars;
- if (OS.IsUnicode) {
- chars = ((LOGFONTW)logFont).lfFaceName;
- } else {
- chars = new char[OS.LF_FACESIZE];
- byte[] bytes = ((LOGFONTA)logFont).lfFaceName;
- OS.MultiByteToWideChar (OS.CP_ACP, OS.MB_PRECOMPOSED, bytes, bytes.length, chars, chars.length);
- }
- int index = 0;
- while (index < chars.length) {
- if (chars [index] == 0) break;
- index++;
- }
- String name = new String (chars, 0, index);
- if (Compatibility.equalsIgnoreCase(name, "Courier")) { //$NON-NLS-1$
- name = "Courier New"; //$NON-NLS-1$
- }
- char[] buffer = new char[name.length() + 1];
- name.getChars(0, name.length(), buffer, 0);
- if (fontCollection != 0) {
- family = Gdip.FontFamily_new(buffer, fontCollection);
- if (!Gdip.FontFamily_IsAvailable(family)) {
- Gdip.FontFamily_delete(family);
- family = Gdip.FontFamily_new(buffer, 0);
- if (!Gdip.FontFamily_IsAvailable(family)) {
- Gdip.FontFamily_delete(family);
- family = 0;
- }
- }
- }
- if (family != 0) {
- font = Gdip.Font_new(family, size, style, Gdip.UnitPixel);
- } else {
- font = Gdip.Font_new(buffer, size, style, Gdip.UnitPixel, 0);
- }
- if (outFont != null && font != 0) {
- int /*long*/ hHeap = OS.GetProcessHeap();
- int /*long*/ pLogFont = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, LOGFONTW.sizeof);
- Gdip.Font_GetLogFontW(font, graphics, pLogFont);
- outFont[0] = OS.CreateFontIndirectW(pLogFont);
- OS.HeapFree(hHeap, 0, pLogFont);
- }
- }
- if (outFamily != null && font != 0) {
- if (family == 0) {
- family = Gdip.FontFamily_new();
- Gdip.Font_GetFamily(font, family);
- }
- outFamily [0] = family;
- } else {
- if (family != 0) Gdip.FontFamily_delete(family);
- }
- if (font == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- return font;
-}
-
-static void destroyGdipBrush(int /*long*/ brush) {
- int type = Gdip.Brush_GetType(brush);
- switch (type) {
- case Gdip.BrushTypeSolidColor:
- Gdip.SolidBrush_delete(brush);
- break;
- case Gdip.BrushTypeHatchFill:
- Gdip.HatchBrush_delete(brush);
- break;
- case Gdip.BrushTypeLinearGradient:
- Gdip.LinearGradientBrush_delete(brush);
- break;
- case Gdip.BrushTypeTextureFill:
- Gdip.TextureBrush_delete(brush);
- break;
- }
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the graphics context. Applications must dispose of all GCs
- * which they allocate.
- *
- * @exception SWTError <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li>
- * </ul>
- */
-void destroy() {
- boolean gdip = data.gdipGraphics != 0;
- disposeGdip();
- if (gdip && (data.style & SWT.MIRRORED) != 0) {
- OS.SetLayout(handle, OS.GetLayout(handle) | OS.LAYOUT_RTL);
- }
-
- /* Select stock pen and brush objects and free resources */
- if (data.hPen != 0) {
- OS.SelectObject(handle, OS.GetStockObject(OS.NULL_PEN));
- OS.DeleteObject(data.hPen);
- data.hPen = 0;
- }
- if (data.hBrush != 0) {
- OS.SelectObject(handle, OS.GetStockObject(OS.NULL_BRUSH));
- OS.DeleteObject(data.hBrush);
- data.hBrush = 0;
- }
-
- /*
- * Put back the original bitmap into the device context.
- * This will ensure that we have not left a bitmap
- * selected in it when we delete the HDC.
- */
- int /*long*/ hNullBitmap = data.hNullBitmap;
- if (hNullBitmap != 0) {
- OS.SelectObject(handle, hNullBitmap);
- data.hNullBitmap = 0;
- }
- Image image = data.image;
- if (image != null) image.memGC = null;
-
- /*
- * Dispose the HDC.
- */
- if (drawable != null) drawable.internal_dispose_GC(handle, data);
- drawable = null;
- handle = 0;
- data.image = null;
- data.ps = null;
- data = null;
-}
-
-void disposeGdip() {
- if (data.gdipPen != 0) Gdip.Pen_delete(data.gdipPen);
- if (data.gdipBgBrush != 0) destroyGdipBrush(data.gdipBgBrush);
- if (data.gdipFgBrush != 0) destroyGdipBrush(data.gdipFgBrush);
- if (data.gdipFont != 0) Gdip.Font_delete(data.gdipFont);
- if (data.hGDIFont != 0) OS.DeleteObject(data.hGDIFont);
- if (data.gdipGraphics != 0) Gdip.Graphics_delete(data.gdipGraphics);
- data.gdipGraphics = data.gdipBrush = data.gdipBgBrush = data.gdipFgBrush =
- data.gdipFont = data.gdipPen = data.hGDIFont = 0;
-}
-
-/**
- * Draws the outline of a circular or elliptical arc
- * within the specified rectangular area.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees, using the current color.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc to be drawn
- * @param y the y coordinate of the upper-left corner of the arc to be drawn
- * @param width the width of the arc to be drawn
- * @param height the height of the arc to be drawn
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawArc (int x, int y, int width, int height, int startAngle, int arcAngle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- int /*long*/ gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend);
- if (width == height) {
- Gdip.Graphics_DrawArc(gdipGraphics, data.gdipPen, x, y, width, height, -startAngle, -arcAngle);
- } else {
- int /*long*/ path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate);
- if (path == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ matrix = Gdip.Matrix_new(width, 0, 0, height, x, y);
- if (matrix == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Gdip.GraphicsPath_AddArc(path, 0, 0, 1, 1, -startAngle, -arcAngle);
- Gdip.GraphicsPath_Transform(path, matrix);
- Gdip.Graphics_DrawPath(gdipGraphics, data.gdipPen, path);
- Gdip.Matrix_delete(matrix);
- Gdip.GraphicsPath_delete(path);
- }
- Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend);
- return;
- }
- if ((data.style & SWT.MIRRORED) != 0) {
- if (data.lineWidth != 0 && data.lineWidth % 2 == 0) x--;
- }
- /*
- * Feature in WinCE. The function Arc is not present in the
- * WinCE SDK. The fix is to emulate arc drawing by using
- * Polyline.
- */
- if (OS.IsWinCE) {
- /* compute arc with a simple linear interpolation */
- if (arcAngle < 0) {
- startAngle += arcAngle;
- arcAngle = -arcAngle;
- }
- if (arcAngle > 360) arcAngle = 360;
- int[] points = new int[(arcAngle + 1) * 2];
- int cteX = 2 * x + width;
- int cteY = 2 * y + height;
- int index = 0;
- for (int i = 0; i <= arcAngle; i++) {
- points[index++] = (Compatibility.cos(startAngle + i, width) + cteX) >> 1;
- points[index++] = (cteY - Compatibility.sin(startAngle + i, height)) >> 1;
- }
- OS.Polyline(handle, points, points.length / 2);
- } else {
- int x1, y1, x2, y2,tmp;
- boolean isNegative;
- if (arcAngle >= 360 || arcAngle <= -360) {
- x1 = x2 = x + width;
- y1 = y2 = y + height / 2;
- } else {
- isNegative = arcAngle < 0;
-
- arcAngle = arcAngle + startAngle;
- if (isNegative) {
- // swap angles
- tmp = startAngle;
- startAngle = arcAngle;
- arcAngle = tmp;
- }
- x1 = Compatibility.cos(startAngle, width) + x + width/2;
- y1 = -1 * Compatibility.sin(startAngle, height) + y + height/2;
-
- x2 = Compatibility.cos(arcAngle, width) + x + width/2;
- y2 = -1 * Compatibility.sin(arcAngle, height) + y + height/2;
- }
- OS.Arc(handle, x, y, x + width + 1, y + height + 1, x1, y1, x2, y2);
- }
-}
-
-/**
- * Draws a rectangle, based on the specified arguments, which has
- * the appearance of the platform's <em>focus rectangle</em> if the
- * platform supports such a notion, and otherwise draws a simple
- * rectangle in the receiver's foreground color.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width of the rectangle
- * @param height the height of the rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void drawFocus (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if ((data.uiState & OS.UISF_HIDEFOCUS) != 0) return;
- data.focusDrawn = true;
- int /*long*/ hdc = handle;
- int state = 0;
- int /*long*/ gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- int /*long*/ clipRgn = 0;
- Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone);
- int /*long*/ rgn = Gdip.Region_new();
- if (rgn == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Gdip.Graphics_GetClip(gdipGraphics, rgn);
- if (!Gdip.Region_IsInfinite(rgn, gdipGraphics)) {
- clipRgn = Gdip.Region_GetHRGN(rgn, gdipGraphics);
- }
- Gdip.Region_delete(rgn);
- Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf);
- float[] lpXform = null;
- int /*long*/ matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0);
- if (matrix == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Gdip.Graphics_GetTransform(gdipGraphics, matrix);
- if (!Gdip.Matrix_IsIdentity(matrix)) {
- lpXform = new float[6];
- Gdip.Matrix_GetElements(matrix, lpXform);
- }
- Gdip.Matrix_delete(matrix);
- hdc = Gdip.Graphics_GetHDC(gdipGraphics);
- state = OS.SaveDC(hdc);
- if (lpXform != null) {
- OS.SetGraphicsMode(hdc, OS.GM_ADVANCED);
- OS.SetWorldTransform(hdc, lpXform);
- }
- if (clipRgn != 0) {
- OS.SelectClipRgn(hdc, clipRgn);
- OS.DeleteObject(clipRgn);
- }
- }
- OS.SetBkColor(hdc, 0xFFFFFF);
- OS.SetTextColor(hdc, 0x000000);
- RECT rect = new RECT();
- OS.SetRect(rect, x, y, x + width, y + height);
- OS.DrawFocusRect(hdc, rect);
- if (gdipGraphics != 0) {
- OS.RestoreDC(hdc, state);
- Gdip.Graphics_ReleaseHDC(gdipGraphics, hdc);
- } else {
- data.state &= ~(BACKGROUND_TEXT | FOREGROUND_TEXT);
- }
-}
-
-/**
- * Draws the given image in the receiver at the specified
- * coordinates.
- *
- * @param image the image to draw
- * @param x the x coordinate of where to draw
- * @param y the y coordinate of where to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if the given coordinates are outside the bounds of the image</li>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- */
-public void drawImage(Image image, int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- drawImage(image, 0, 0, -1, -1, x, y, -1, -1, true);
-}
-
-/**
- * Copies a rectangular area from the source image into a (potentially
- * different sized) rectangular area in the receiver. If the source
- * and destination areas are of differing sizes, then the source
- * area will be stretched or shrunk to fit the destination area
- * as it is copied. The copy fails if any part of the source rectangle
- * lies outside the bounds of the source image, or if any of the width
- * or height arguments are negative.
- *
- * @param image the source image
- * @param srcX the x coordinate in the source image to copy from
- * @param srcY the y coordinate in the source image to copy from
- * @param srcWidth the width in pixels to copy from the source
- * @param srcHeight the height in pixels to copy from the source
- * @param destX the x coordinate in the destination to copy to
- * @param destY the y coordinate in the destination to copy to
- * @param destWidth the width in pixels of the destination rectangle
- * @param destHeight the height in pixels of the destination rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if any of the width or height arguments are negative.
- * <li>ERROR_INVALID_ARGUMENT - if the source rectangle is not contained within the bounds of the source image</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- */
-public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (srcWidth == 0 || srcHeight == 0 || destWidth == 0 || destHeight == 0) return;
- if (srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 || destWidth < 0 || destHeight < 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (image == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- drawImage(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false);
-}
-
-void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
- if (data.gdipGraphics != 0) {
- //TODO - cache bitmap
- int /*long*/ [] gdipImage = srcImage.createGdipImage();
- int /*long*/ img = gdipImage[0];
- int imgWidth = Gdip.Image_GetWidth(img);
- int imgHeight = Gdip.Image_GetHeight(img);
- if (simple) {
- srcWidth = destWidth = imgWidth;
- srcHeight = destHeight = imgHeight;
- } else {
- if (srcX + srcWidth > imgWidth || srcY + srcHeight > imgHeight) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- simple = srcX == 0 && srcY == 0 &&
- srcWidth == destWidth && destWidth == imgWidth &&
- srcHeight == destHeight && destHeight == imgHeight;
- }
- Rect rect = new Rect();
- rect.X = destX;
- rect.Y = destY;
- rect.Width = destWidth;
- rect.Height = destHeight;
- /*
- * Note that if the wrap mode is not WrapModeTileFlipXY, the scaled image
- * is translucent around the borders.
- */
- int /*long*/ attrib = Gdip.ImageAttributes_new();
- Gdip.ImageAttributes_SetWrapMode(attrib, Gdip.WrapModeTileFlipXY);
- if (data.alpha != 0xFF) {
- float[] matrix = new float[]{
- 1,0,0,0,0,
- 0,1,0,0,0,
- 0,0,1,0,0,
- 0,0,0,data.alpha / (float)0xFF,0,
- 0,0,0,0,1,
- };
- Gdip.ImageAttributes_SetColorMatrix(attrib, matrix, Gdip.ColorMatrixFlagsDefault, Gdip.ColorAdjustTypeBitmap);
- }
- int gstate = 0;
- if ((data.style & SWT.MIRRORED) != 0) {
- gstate = Gdip.Graphics_Save(data.gdipGraphics);
- Gdip.Graphics_ScaleTransform(data.gdipGraphics, -1, 1, Gdip.MatrixOrderPrepend);
- Gdip.Graphics_TranslateTransform(data.gdipGraphics, - 2 * destX - destWidth, 0, Gdip.MatrixOrderPrepend);
- }
- Gdip.Graphics_DrawImage(data.gdipGraphics, img, rect, srcX, srcY, srcWidth, srcHeight, Gdip.UnitPixel, attrib, 0, 0);
- if ((data.style & SWT.MIRRORED) != 0) {
- Gdip.Graphics_Restore(data.gdipGraphics, gstate);
- }
- Gdip.ImageAttributes_delete(attrib);
- Gdip.Bitmap_delete(img);
- if (gdipImage[1] != 0) {
- int /*long*/ hHeap = OS.GetProcessHeap ();
- OS.HeapFree(hHeap, 0, gdipImage[1]);
- }
- return;
- }
- switch (srcImage.type) {
- case SWT.BITMAP:
- drawBitmap(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);
- break;
- case SWT.ICON:
- drawIcon(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);
- break;
- }
-}
-
-void drawIcon(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
- int technology = OS.GetDeviceCaps(handle, OS.TECHNOLOGY);
-
- boolean drawIcon = true;
- int flags = OS.DI_NORMAL;
- int offsetX = 0, offsetY = 0;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(5, 1)) {
- if ((OS.GetLayout(handle) & OS.LAYOUT_RTL) != 0) {
- flags |= OS.DI_NOMIRROR;
- /*
- * Bug in Windows. For some reason, DrawIconEx() does not take
- * into account the window origin when the DI_NOMIRROR and
- * LAYOUT_RTL are set. The fix is to set the window origin to
- * (0, 0) and offset the drawing ourselves.
- */
- POINT pt = new POINT();
- OS.GetWindowOrgEx(handle, pt);
- offsetX = pt.x;
- offsetY = pt.y;
- }
- } else {
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
- drawIcon = (OS.GetLayout(handle) & OS.LAYOUT_RTL) == 0;
- }
- }
-
- /* Simple case: no stretching, entire icon */
- if (simple && technology != OS.DT_RASPRINTER && drawIcon) {
- if (offsetX != 0 || offsetY != 0) OS.SetWindowOrgEx(handle, 0, 0, null);
- OS.DrawIconEx(handle, destX - offsetX, destY - offsetY, srcImage.handle, 0, 0, 0, 0, flags);
- if (offsetX != 0 || offsetY != 0) OS.SetWindowOrgEx(handle, offsetX, offsetY, null);
- return;
- }
-
- /* Get the icon info */
- ICONINFO srcIconInfo = new ICONINFO();
- if (OS.IsWinCE) {
- Image.GetIconInfo(srcImage, srcIconInfo);
- } else {
- OS.GetIconInfo(srcImage.handle, srcIconInfo);
- }
-
- /* Get the icon width and height */
- int /*long*/ hBitmap = srcIconInfo.hbmColor;
- if (hBitmap == 0) hBitmap = srcIconInfo.hbmMask;
- BITMAP bm = new BITMAP();
- OS.GetObject(hBitmap, BITMAP.sizeof, bm);
- int iconWidth = bm.bmWidth, iconHeight = bm.bmHeight;
- if (hBitmap == srcIconInfo.hbmMask) iconHeight /= 2;
-
- if (simple) {
- srcWidth = destWidth = iconWidth;
- srcHeight = destHeight = iconHeight;
- }
-
- /* Draw the icon */
- boolean failed = srcX + srcWidth > iconWidth || srcY + srcHeight > iconHeight;
- if (!failed) {
- simple = srcX == 0 && srcY == 0 &&
- srcWidth == destWidth && srcHeight == destHeight &&
- srcWidth == iconWidth && srcHeight == iconHeight;
- if (!drawIcon) {
- drawBitmapMask(srcImage, srcIconInfo.hbmColor, srcIconInfo.hbmMask, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, iconWidth, iconHeight, false);
- } else if (simple && technology != OS.DT_RASPRINTER) {
- /* Simple case: no stretching, entire icon */
- if (offsetX != 0 || offsetY != 0) OS.SetWindowOrgEx(handle, 0, 0, null);
- OS.DrawIconEx(handle, destX - offsetX, destY - offsetY, srcImage.handle, 0, 0, 0, 0, flags);
- if (offsetX != 0 || offsetY != 0) OS.SetWindowOrgEx(handle, offsetX, offsetY, null);
- } else {
- /* Create the icon info and HDC's */
- ICONINFO newIconInfo = new ICONINFO();
- newIconInfo.fIcon = true;
- int /*long*/ srcHdc = OS.CreateCompatibleDC(handle);
- int /*long*/ dstHdc = OS.CreateCompatibleDC(handle);
-
- /* Blt the color bitmap */
- int srcColorY = srcY;
- int /*long*/ srcColor = srcIconInfo.hbmColor;
- if (srcColor == 0) {
- srcColor = srcIconInfo.hbmMask;
- srcColorY += iconHeight;
- }
- int /*long*/ oldSrcBitmap = OS.SelectObject(srcHdc, srcColor);
- newIconInfo.hbmColor = OS.CreateCompatibleBitmap(srcHdc, destWidth, destHeight);
- if (newIconInfo.hbmColor == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ oldDestBitmap = OS.SelectObject(dstHdc, newIconInfo.hbmColor);
- boolean stretch = !simple && (srcWidth != destWidth || srcHeight != destHeight);
- if (stretch) {
- if (!OS.IsWinCE) OS.SetStretchBltMode(dstHdc, OS.COLORONCOLOR);
- OS.StretchBlt(dstHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcColorY, srcWidth, srcHeight, OS.SRCCOPY);
- } else {
- OS.BitBlt(dstHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcColorY, OS.SRCCOPY);
- }
-
- /* Blt the mask bitmap */
- OS.SelectObject(srcHdc, srcIconInfo.hbmMask);
- newIconInfo.hbmMask = OS.CreateBitmap(destWidth, destHeight, 1, 1, null);
- if (newIconInfo.hbmMask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.SelectObject(dstHdc, newIconInfo.hbmMask);
- if (stretch) {
- OS.StretchBlt(dstHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, OS.SRCCOPY);
- } else {
- OS.BitBlt(dstHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcY, OS.SRCCOPY);
- }
-
- if (technology == OS.DT_RASPRINTER) {
- OS.SelectObject(srcHdc, newIconInfo.hbmColor);
- OS.SelectObject(dstHdc, newIconInfo.hbmMask);
- drawBitmapTransparentByClipping(srcHdc, dstHdc, 0, 0, destWidth, destHeight, destX, destY, destWidth, destHeight, true, destWidth, destHeight);
- OS.SelectObject(srcHdc, oldSrcBitmap);
- OS.SelectObject(dstHdc, oldDestBitmap);
- } else {
- OS.SelectObject(srcHdc, oldSrcBitmap);
- OS.SelectObject(dstHdc, oldDestBitmap);
- int /*long*/ hIcon = OS.CreateIconIndirect(newIconInfo);
- if (hIcon == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (offsetX != 0 || offsetY != 0) OS.SetWindowOrgEx(handle, 0, 0, null);
- OS.DrawIconEx(handle, destX - offsetX, destY - offsetY, hIcon, destWidth, destHeight, 0, 0, flags);
- if (offsetX != 0 || offsetY != 0) OS.SetWindowOrgEx(handle, offsetX, offsetY, null);
- OS.DestroyIcon(hIcon);
- }
-
- /* Destroy the new icon src and mask and hdc's*/
- OS.DeleteObject(newIconInfo.hbmMask);
- OS.DeleteObject(newIconInfo.hbmColor);
- OS.DeleteDC(dstHdc);
- OS.DeleteDC(srcHdc);
- }
- }
-
- /* Free icon info */
- OS.DeleteObject(srcIconInfo.hbmMask);
- if (srcIconInfo.hbmColor != 0) {
- OS.DeleteObject(srcIconInfo.hbmColor);
- }
-
- if (failed) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-}
-
-void drawBitmap(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
- BITMAP bm = new BITMAP();
- OS.GetObject(srcImage.handle, BITMAP.sizeof, bm);
- int imgWidth = bm.bmWidth;
- int imgHeight = bm.bmHeight;
- if (simple) {
- srcWidth = destWidth = imgWidth;
- srcHeight = destHeight = imgHeight;
- } else {
- if (srcX + srcWidth > imgWidth || srcY + srcHeight > imgHeight) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- simple = srcX == 0 && srcY == 0 &&
- srcWidth == destWidth && destWidth == imgWidth &&
- srcHeight == destHeight && destHeight == imgHeight;
- }
- boolean mustRestore = false;
- GC memGC = srcImage.memGC;
- if (memGC != null && !memGC.isDisposed()) {
- memGC.flush();
- mustRestore = true;
- GCData data = memGC.data;
- if (data.hNullBitmap != 0) {
- OS.SelectObject(memGC.handle, data.hNullBitmap);
- data.hNullBitmap = 0;
- }
- }
- if (srcImage.alpha != -1 || srcImage.alphaData != null) {
- drawBitmapAlpha(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, bm, imgWidth, imgHeight);
- } else if (srcImage.transparentPixel != -1) {
- drawBitmapTransparent(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, bm, imgWidth, imgHeight);
- } else {
- drawBitmap(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, bm, imgWidth, imgHeight);
- }
- if (mustRestore) {
- int /*long*/ hOldBitmap = OS.SelectObject(memGC.handle, srcImage.handle);
- memGC.data.hNullBitmap = hOldBitmap;
- }
-}
-
-void drawBitmapAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, BITMAP bm, int imgWidth, int imgHeight) {
- /* Simple cases */
- if (srcImage.alpha == 0) return;
- if (srcImage.alpha == 255) {
- drawBitmap(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, bm, imgWidth, imgHeight);
- return;
- }
-
- if (OS.IsWinNT && OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
- BLENDFUNCTION blend = new BLENDFUNCTION();
- blend.BlendOp = OS.AC_SRC_OVER;
- int /*long*/ srcHdc = OS.CreateCompatibleDC(handle);
- int /*long*/ oldSrcBitmap = OS.SelectObject(srcHdc, srcImage.handle);
- if (srcImage.alpha != -1) {
- blend.SourceConstantAlpha = (byte)srcImage.alpha;
- OS.AlphaBlend(handle, destX, destY, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, blend);
- } else {
- int /*long*/ memDib = Image.createDIB(srcWidth, srcHeight, 32);
- if (memDib == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ memHdc = OS.CreateCompatibleDC(handle);
- int /*long*/ oldMemBitmap = OS.SelectObject(memHdc, memDib);
- BITMAP dibBM = new BITMAP();
- OS.GetObject(memDib, BITMAP.sizeof, dibBM);
- OS.BitBlt(memHdc, 0, 0, srcWidth, srcHeight, srcHdc, srcX, srcY, OS.SRCCOPY);
- byte[] srcData = new byte[dibBM.bmWidthBytes * dibBM.bmHeight];
- OS.MoveMemory(srcData, dibBM.bmBits, srcData.length);
- final int apinc = imgWidth - srcWidth;
- int ap = srcY * imgWidth + srcX, sp = 0;
- byte[] alphaData = srcImage.alphaData;
- for (int y = 0; y < srcHeight; ++y) {
- for (int x = 0; x < srcWidth; ++x) {
- int alpha = alphaData[ap++] & 0xff;
- int r = ((srcData[sp + 0] & 0xFF) * alpha) + 128;
- r = (r + (r >> 8)) >> 8;
- int g = ((srcData[sp + 1] & 0xFF) * alpha) + 128;
- g = (g + (g >> 8)) >> 8;
- int b = ((srcData[sp + 2] & 0xFF) * alpha) + 128;
- b = (b + (b >> 8)) >> 8;
- srcData[sp+0] = (byte)r;
- srcData[sp+1] = (byte)g;
- srcData[sp+2] = (byte)b;
- srcData[sp+3] = (byte)alpha;
- sp += 4;
- }
- ap += apinc;
- }
- OS.MoveMemory(dibBM.bmBits, srcData, srcData.length);
- blend.SourceConstantAlpha = (byte)0xff;
- blend.AlphaFormat = OS.AC_SRC_ALPHA;
- OS.AlphaBlend(handle, destX, destY, destWidth, destHeight, memHdc, 0, 0, srcWidth, srcHeight, blend);
- OS.SelectObject(memHdc, oldMemBitmap);
- OS.DeleteDC(memHdc);
- OS.DeleteObject(memDib);
- }
- OS.SelectObject(srcHdc, oldSrcBitmap);
- OS.DeleteDC(srcHdc);
- return;
- }
-
- /* Check clipping */
- Rectangle rect = getClipping();
- rect = rect.intersection(new Rectangle(destX, destY, destWidth, destHeight));
- if (rect.isEmpty()) return;
-
- /*
- * Optimization. Recalculate src and dest rectangles so that
- * only the clipping area is drawn.
- */
- int sx1 = srcX + (((rect.x - destX) * srcWidth) / destWidth);
- int sx2 = srcX + ((((rect.x + rect.width) - destX) * srcWidth) / destWidth);
- int sy1 = srcY + (((rect.y - destY) * srcHeight) / destHeight);
- int sy2 = srcY + ((((rect.y + rect.height) - destY) * srcHeight) / destHeight);
- destX = rect.x;
- destY = rect.y;
- destWidth = rect.width;
- destHeight = rect.height;
- srcX = sx1;
- srcY = sy1;
- srcWidth = Math.max(1, sx2 - sx1);
- srcHeight = Math.max(1, sy2 - sy1);
-
- /* Create resources */
- int /*long*/ srcHdc = OS.CreateCompatibleDC(handle);
- int /*long*/ oldSrcBitmap = OS.SelectObject(srcHdc, srcImage.handle);
- int /*long*/ memHdc = OS.CreateCompatibleDC(handle);
- int /*long*/ memDib = Image.createDIB(Math.max(srcWidth, destWidth), Math.max(srcHeight, destHeight), 32);
- if (memDib == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ oldMemBitmap = OS.SelectObject(memHdc, memDib);
-
- BITMAP dibBM = new BITMAP();
- OS.GetObject(memDib, BITMAP.sizeof, dibBM);
- int sizeInBytes = dibBM.bmWidthBytes * dibBM.bmHeight;
-
- /* Get the background pixels */
- OS.BitBlt(memHdc, 0, 0, destWidth, destHeight, handle, destX, destY, OS.SRCCOPY);
- byte[] destData = new byte[sizeInBytes];
- OS.MoveMemory(destData, dibBM.bmBits, sizeInBytes);
-
- /* Get the foreground pixels */
- OS.BitBlt(memHdc, 0, 0, srcWidth, srcHeight, srcHdc, srcX, srcY, OS.SRCCOPY);
- byte[] srcData = new byte[sizeInBytes];
- OS.MoveMemory(srcData, dibBM.bmBits, sizeInBytes);
-
- /* Merge the alpha channel in place */
- int alpha = srcImage.alpha;
- final boolean hasAlphaChannel = (srcImage.alpha == -1);
- if (hasAlphaChannel) {
- final int apinc = imgWidth - srcWidth;
- final int spinc = dibBM.bmWidthBytes - srcWidth * 4;
- int ap = srcY * imgWidth + srcX, sp = 3;
- byte[] alphaData = srcImage.alphaData;
- for (int y = 0; y < srcHeight; ++y) {
- for (int x = 0; x < srcWidth; ++x) {
- srcData[sp] = alphaData[ap++];
- sp += 4;
- }
- ap += apinc;
- sp += spinc;
- }
- }
-
- /* Scale the foreground pixels with alpha */
- OS.MoveMemory(dibBM.bmBits, srcData, sizeInBytes);
- /*
- * Bug in WinCE and Win98. StretchBlt does not correctly stretch when
- * the source and destination HDCs are the same. The workaround is to
- * stretch to a temporary HDC and blit back into the original HDC.
- * Note that on WinCE StretchBlt correctly compresses the image when the
- * source and destination HDCs are the same.
- */
- if ((OS.IsWinCE && (destWidth > srcWidth || destHeight > srcHeight)) || (!OS.IsWinNT && !OS.IsWinCE)) {
- int /*long*/ tempHdc = OS.CreateCompatibleDC(handle);
- int /*long*/ tempDib = Image.createDIB(destWidth, destHeight, 32);
- if (tempDib == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ oldTempBitmap = OS.SelectObject(tempHdc, tempDib);
- if (!simple && (srcWidth != destWidth || srcHeight != destHeight)) {
- if (!OS.IsWinCE) OS.SetStretchBltMode(memHdc, OS.COLORONCOLOR);
- OS.StretchBlt(tempHdc, 0, 0, destWidth, destHeight, memHdc, 0, 0, srcWidth, srcHeight, OS.SRCCOPY);
- } else {
- OS.BitBlt(tempHdc, 0, 0, destWidth, destHeight, memHdc, 0, 0, OS.SRCCOPY);
- }
- OS.BitBlt(memHdc, 0, 0, destWidth, destHeight, tempHdc, 0, 0, OS.SRCCOPY);
- OS.SelectObject(tempHdc, oldTempBitmap);
- OS.DeleteObject(tempDib);
- OS.DeleteDC(tempHdc);
- } else {
- if (!simple && (srcWidth != destWidth || srcHeight != destHeight)) {
- if (!OS.IsWinCE) OS.SetStretchBltMode(memHdc, OS.COLORONCOLOR);
- OS.StretchBlt(memHdc, 0, 0, destWidth, destHeight, memHdc, 0, 0, srcWidth, srcHeight, OS.SRCCOPY);
- } else {
- OS.BitBlt(memHdc, 0, 0, destWidth, destHeight, memHdc, 0, 0, OS.SRCCOPY);
- }
- }
- OS.MoveMemory(srcData, dibBM.bmBits, sizeInBytes);
-
- /* Compose the pixels */
- final int dpinc = dibBM.bmWidthBytes - destWidth * 4;
- int dp = 0;
- for (int y = 0; y < destHeight; ++y) {
- for (int x = 0; x < destWidth; ++x) {
- if (hasAlphaChannel) alpha = srcData[dp + 3] & 0xff;
- destData[dp] += ((srcData[dp] & 0xff) - (destData[dp] & 0xff)) * alpha / 255;
- destData[dp + 1] += ((srcData[dp + 1] & 0xff) - (destData[dp + 1] & 0xff)) * alpha / 255;
- destData[dp + 2] += ((srcData[dp + 2] & 0xff) - (destData[dp + 2] & 0xff)) * alpha / 255;
- dp += 4;
- }
- dp += dpinc;
- }
-
- /* Draw the composed pixels */
- OS.MoveMemory(dibBM.bmBits, destData, sizeInBytes);
- OS.BitBlt(handle, destX, destY, destWidth, destHeight, memHdc, 0, 0, OS.SRCCOPY);
-
- /* Free resources */
- OS.SelectObject(memHdc, oldMemBitmap);
- OS.DeleteDC(memHdc);
- OS.DeleteObject(memDib);
- OS.SelectObject(srcHdc, oldSrcBitmap);
- OS.DeleteDC(srcHdc);
-}
-
-void drawBitmapTransparentByClipping(int /*long*/ srcHdc, int /*long*/ maskHdc, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight) {
- /* Create a clipping region from the mask */
- int /*long*/ rgn = OS.CreateRectRgn(0, 0, 0, 0);
- for (int y=0; y<imgHeight; y++) {
- for (int x=0; x<imgWidth; x++) {
- if (OS.GetPixel(maskHdc, x, y) == 0) {
- int /*long*/ tempRgn = OS.CreateRectRgn(x, y, x+1, y+1);
- OS.CombineRgn(rgn, rgn, tempRgn, OS.RGN_OR);
- OS.DeleteObject(tempRgn);
- }
- }
- }
- /* Stretch the clipping mask if needed */
- if (destWidth != srcWidth || destHeight != srcHeight) {
- int nBytes = OS.GetRegionData (rgn, 0, null);
- int[] lpRgnData = new int[nBytes / 4];
- OS.GetRegionData (rgn, nBytes, lpRgnData);
- float[] lpXform = new float[] {(float)destWidth/srcWidth, 0, 0, (float)destHeight/srcHeight, 0, 0};
- int /*long*/ tmpRgn = OS.ExtCreateRegion(lpXform, nBytes, lpRgnData);
- OS.DeleteObject(rgn);
- rgn = tmpRgn;
- }
- OS.OffsetRgn(rgn, destX, destY);
- int /*long*/ clip = OS.CreateRectRgn(0, 0, 0, 0);
- int result = OS.GetClipRgn(handle, clip);
- if (result == 1) OS.CombineRgn(rgn, rgn, clip, OS.RGN_AND);
- OS.SelectClipRgn(handle, rgn);
- int rop2 = 0;
- if (!OS.IsWinCE) {
- rop2 = OS.GetROP2(handle);
- } else {
- rop2 = OS.SetROP2 (handle, OS.R2_COPYPEN);
- OS.SetROP2 (handle, rop2);
- }
- int dwRop = rop2 == OS.R2_XORPEN ? OS.SRCINVERT : OS.SRCCOPY;
- if (!simple && (srcWidth != destWidth || srcHeight != destHeight)) {
- int mode = 0;
- if (!OS.IsWinCE) mode = OS.SetStretchBltMode(handle, OS.COLORONCOLOR);
- OS.StretchBlt(handle, destX, destY, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, dwRop);
- if (!OS.IsWinCE) OS.SetStretchBltMode(handle, mode);
- } else {
- OS.BitBlt(handle, destX, destY, destWidth, destHeight, srcHdc, srcX, srcY, dwRop);
- }
- OS.SelectClipRgn(handle, result == 1 ? clip : 0);
- OS.DeleteObject(clip);
- OS.DeleteObject(rgn);
-}
-
-void drawBitmapMask(Image srcImage, int /*long*/ srcColor, int /*long*/ srcMask, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, boolean offscreen) {
- int srcColorY = srcY;
- if (srcColor == 0) {
- srcColor = srcMask;
- srcColorY += imgHeight;
- }
- int /*long*/ srcHdc = OS.CreateCompatibleDC(handle);
- int /*long*/ oldSrcBitmap = OS.SelectObject(srcHdc, srcColor);
- int /*long*/ destHdc = handle;
- int x = destX, y = destY;
- int /*long*/ tempHdc = 0, tempBitmap = 0, oldTempBitmap = 0;
- int oldBkColor = 0, oldTextColor = 0;
- if (offscreen) {
- tempHdc = OS.CreateCompatibleDC(handle);
- tempBitmap = OS.CreateCompatibleBitmap(handle, destWidth, destHeight);
- oldTempBitmap = OS.SelectObject(tempHdc, tempBitmap);
- OS.BitBlt(tempHdc, 0, 0, destWidth, destHeight, handle, destX, destY, OS.SRCCOPY);
- destHdc = tempHdc;
- x = y = 0;
- } else {
- oldBkColor = OS.SetBkColor(handle, 0xFFFFFF);
- oldTextColor = OS.SetTextColor(handle, 0);
- }
- if (!simple && (srcWidth != destWidth || srcHeight != destHeight)) {
- int mode = 0;
- if (!OS.IsWinCE) mode = OS.SetStretchBltMode(handle, OS.COLORONCOLOR);
- OS.StretchBlt(destHdc, x, y, destWidth, destHeight, srcHdc, srcX, srcColorY, srcWidth, srcHeight, OS.SRCINVERT);
- OS.SelectObject(srcHdc, srcMask);
- OS.StretchBlt(destHdc, x, y, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, OS.SRCAND);
- OS.SelectObject(srcHdc, srcColor);
- OS.StretchBlt(destHdc, x, y, destWidth, destHeight, srcHdc, srcX, srcColorY, srcWidth, srcHeight, OS.SRCINVERT);
- if (!OS.IsWinCE) OS.SetStretchBltMode(handle, mode);
- } else {
- OS.BitBlt(destHdc, x, y, destWidth, destHeight, srcHdc, srcX, srcColorY, OS.SRCINVERT);
- OS.SetTextColor(destHdc, 0);
- OS.SelectObject(srcHdc, srcMask);
- OS.BitBlt(destHdc, x, y, destWidth, destHeight, srcHdc, srcX, srcY, OS.SRCAND);
- OS.SelectObject(srcHdc, srcColor);
- OS.BitBlt(destHdc, x, y, destWidth, destHeight, srcHdc, srcX, srcColorY, OS.SRCINVERT);
- }
- if (offscreen) {
- OS.BitBlt(handle, destX, destY, destWidth, destHeight, tempHdc, 0, 0, OS.SRCCOPY);
- OS.SelectObject(tempHdc, oldTempBitmap);
- OS.DeleteDC(tempHdc);
- OS.DeleteObject(tempBitmap);
- } else {
- OS.SetBkColor(handle, oldBkColor);
- OS.SetTextColor(handle, oldTextColor);
- }
- OS.SelectObject(srcHdc, oldSrcBitmap);
- OS.DeleteDC(srcHdc);
-}
-
-void drawBitmapTransparent(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, BITMAP bm, int imgWidth, int imgHeight) {
-
- /* Find the RGB values for the transparent pixel. */
- boolean isDib = bm.bmBits != 0;
- int /*long*/ hBitmap = srcImage.handle;
- int /*long*/ srcHdc = OS.CreateCompatibleDC(handle);
- int /*long*/ oldSrcBitmap = OS.SelectObject(srcHdc, hBitmap);
- byte[] originalColors = null;
- int transparentColor = srcImage.transparentColor;
- if (transparentColor == -1) {
- int transBlue = 0, transGreen = 0, transRed = 0;
- boolean fixPalette = false;
- if (bm.bmBitsPixel <= 8) {
- if (isDib) {
- /* Palette-based DIBSECTION */
- if (OS.IsWinCE) {
- byte[] pBits = new byte[1];
- OS.MoveMemory(pBits, bm.bmBits, 1);
- byte oldValue = pBits[0];
- int mask = (0xFF << (8 - bm.bmBitsPixel)) & 0x00FF;
- pBits[0] = (byte)((srcImage.transparentPixel << (8 - bm.bmBitsPixel)) | (pBits[0] & ~mask));
- OS.MoveMemory(bm.bmBits, pBits, 1);
- int color = OS.GetPixel(srcHdc, 0, 0);
- pBits[0] = oldValue;
- OS.MoveMemory(bm.bmBits, pBits, 1);
- transBlue = (color & 0xFF0000) >> 16;
- transGreen = (color & 0xFF00) >> 8;
- transRed = color & 0xFF;
- } else {
- int maxColors = 1 << bm.bmBitsPixel;
- byte[] oldColors = new byte[maxColors * 4];
- OS.GetDIBColorTable(srcHdc, 0, maxColors, oldColors);
- int offset = srcImage.transparentPixel * 4;
- for (int i = 0; i < oldColors.length; i += 4) {
- if (i != offset) {
- if (oldColors[offset] == oldColors[i] && oldColors[offset+1] == oldColors[i+1] && oldColors[offset+2] == oldColors[i+2]) {
- fixPalette = true;
- break;
- }
- }
- }
- if (fixPalette) {
- byte[] newColors = new byte[oldColors.length];
- transRed = transGreen = transBlue = 0xff;
- newColors[offset] = (byte)transBlue;
- newColors[offset+1] = (byte)transGreen;
- newColors[offset+2] = (byte)transRed;
- OS.SetDIBColorTable(srcHdc, 0, maxColors, newColors);
- originalColors = oldColors;
- } else {
- transBlue = oldColors[offset] & 0xFF;
- transGreen = oldColors[offset+1] & 0xFF;
- transRed = oldColors[offset+2] & 0xFF;
- }
- }
- } else {
- /* Palette-based bitmap */
- int numColors = 1 << bm.bmBitsPixel;
- /* Set the few fields necessary to get the RGB data out */
- BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER();
- bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
- bmiHeader.biPlanes = bm.bmPlanes;
- bmiHeader.biBitCount = bm.bmBitsPixel;
- byte[] bmi = new byte[BITMAPINFOHEADER.sizeof + numColors * 4];
- OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
- if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- OS.GetDIBits(srcHdc, srcImage.handle, 0, 0, 0, bmi, OS.DIB_RGB_COLORS);
- int offset = BITMAPINFOHEADER.sizeof + 4 * srcImage.transparentPixel;
- transRed = bmi[offset + 2] & 0xFF;
- transGreen = bmi[offset + 1] & 0xFF;
- transBlue = bmi[offset] & 0xFF;
- }
- } else {
- /* Direct color image */
- int pixel = srcImage.transparentPixel;
- switch (bm.bmBitsPixel) {
- case 16:
- transBlue = (pixel & 0x1F) << 3;
- transGreen = (pixel & 0x3E0) >> 2;
- transRed = (pixel & 0x7C00) >> 7;
- break;
- case 24:
- transBlue = (pixel & 0xFF0000) >> 16;
- transGreen = (pixel & 0xFF00) >> 8;
- transRed = pixel & 0xFF;
- break;
- case 32:
- transBlue = (pixel & 0xFF000000) >>> 24;
- transGreen = (pixel & 0xFF0000) >> 16;
- transRed = (pixel & 0xFF00) >> 8;
- break;
- }
- }
- transparentColor = transBlue << 16 | transGreen << 8 | transRed;
- if (!fixPalette) srcImage.transparentColor = transparentColor;
- }
-
- if (OS.IsWinCE) {
- /*
- * Note in WinCE. TransparentImage uses the first entry of a palette
- * based image when there are multiple entries that have the same
- * transparent color.
- */
- OS.TransparentImage(handle, destX, destY, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, transparentColor);
- } else if (originalColors == null && OS.IsWinNT && OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
- int mode = OS.SetStretchBltMode(handle, OS.COLORONCOLOR);
- OS.TransparentBlt(handle, destX, destY, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, transparentColor);
- OS.SetStretchBltMode(handle, mode);
- } else {
- /* Create the mask for the source image */
- int /*long*/ maskHdc = OS.CreateCompatibleDC(handle);
- int /*long*/ maskBitmap = OS.CreateBitmap(imgWidth, imgHeight, 1, 1, null);
- int /*long*/ oldMaskBitmap = OS.SelectObject(maskHdc, maskBitmap);
- OS.SetBkColor(srcHdc, transparentColor);
- OS.BitBlt(maskHdc, 0, 0, imgWidth, imgHeight, srcHdc, 0, 0, OS.SRCCOPY);
- if (originalColors != null) OS.SetDIBColorTable(srcHdc, 0, 1 << bm.bmBitsPixel, originalColors);
-
- if (OS.GetDeviceCaps(handle, OS.TECHNOLOGY) == OS.DT_RASPRINTER) {
- /* Most printers do not support BitBlt(), draw the source bitmap transparently using clipping */
- drawBitmapTransparentByClipping(srcHdc, maskHdc, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight);
- } else {
- /* Draw the source bitmap transparently using invert/and mask/invert */
- int /*long*/ tempHdc = OS.CreateCompatibleDC(handle);
- int /*long*/ tempBitmap = OS.CreateCompatibleBitmap(handle, destWidth, destHeight);
- int /*long*/ oldTempBitmap = OS.SelectObject(tempHdc, tempBitmap);
- OS.BitBlt(tempHdc, 0, 0, destWidth, destHeight, handle, destX, destY, OS.SRCCOPY);
- if (!simple && (srcWidth != destWidth || srcHeight != destHeight)) {
- if (!OS.IsWinCE) OS.SetStretchBltMode(tempHdc, OS.COLORONCOLOR);
- OS.StretchBlt(tempHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, OS.SRCINVERT);
- OS.StretchBlt(tempHdc, 0, 0, destWidth, destHeight, maskHdc, srcX, srcY, srcWidth, srcHeight, OS.SRCAND);
- OS.StretchBlt(tempHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, OS.SRCINVERT);
- } else {
- OS.BitBlt(tempHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcY, OS.SRCINVERT);
- OS.BitBlt(tempHdc, 0, 0, destWidth, destHeight, maskHdc, srcX, srcY, OS.SRCAND);
- OS.BitBlt(tempHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcY, OS.SRCINVERT);
- }
- OS.BitBlt(handle, destX, destY, destWidth, destHeight, tempHdc, 0, 0, OS.SRCCOPY);
- OS.SelectObject(tempHdc, oldTempBitmap);
- OS.DeleteDC(tempHdc);
- OS.DeleteObject(tempBitmap);
- }
- OS.SelectObject(maskHdc, oldMaskBitmap);
- OS.DeleteDC(maskHdc);
- OS.DeleteObject(maskBitmap);
- }
- OS.SelectObject(srcHdc, oldSrcBitmap);
- if (hBitmap != srcImage.handle) OS.DeleteObject(hBitmap);
- OS.DeleteDC(srcHdc);
-}
-
-void drawBitmap(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, BITMAP bm, int imgWidth, int imgHeight) {
- int /*long*/ srcHdc = OS.CreateCompatibleDC(handle);
- int /*long*/ oldSrcBitmap = OS.SelectObject(srcHdc, srcImage.handle);
- int rop2 = 0;
- if (!OS.IsWinCE) {
- rop2 = OS.GetROP2(handle);
- } else {
- rop2 = OS.SetROP2 (handle, OS.R2_COPYPEN);
- OS.SetROP2 (handle, rop2);
- }
- int dwRop = rop2 == OS.R2_XORPEN ? OS.SRCINVERT : OS.SRCCOPY;
- if (!simple && (srcWidth != destWidth || srcHeight != destHeight)) {
- int mode = 0;
- if (!OS.IsWinCE) mode = OS.SetStretchBltMode(handle, OS.COLORONCOLOR);
- OS.StretchBlt(handle, destX, destY, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, dwRop);
- if (!OS.IsWinCE) OS.SetStretchBltMode(handle, mode);
- } else {
- OS.BitBlt(handle, destX, destY, destWidth, destHeight, srcHdc, srcX, srcY, dwRop);
- }
- OS.SelectObject(srcHdc, oldSrcBitmap);
- OS.DeleteDC(srcHdc);
-}
-
-/**
- * Draws a line, using the foreground color, between the points
- * (<code>x1</code>, <code>y1</code>) and (<code>x2</code>, <code>y2</code>).
- *
- * @param x1 the first point's x coordinate
- * @param y1 the first point's y coordinate
- * @param x2 the second point's x coordinate
- * @param y2 the second point's y coordinate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawLine (int x1, int y1, int x2, int y2) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- int /*long*/ gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend);
- Gdip.Graphics_DrawLine(gdipGraphics, data.gdipPen, x1, y1, x2, y2);
- Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend);
- return;
- }
- if ((data.style & SWT.MIRRORED) != 0) {
- if (data.lineWidth != 0 && data.lineWidth % 2 == 0) {
- x1--;
- x2--;
- }
- }
- if (OS.IsWinCE) {
- int [] points = new int [] {x1, y1, x2, y2};
- OS.Polyline (handle, points, points.length / 2);
- } else {
- OS.MoveToEx (handle, x1, y1, 0);
- OS.LineTo (handle, x2, y2);
- }
- if (data.lineWidth <= 1) {
- OS.SetPixel (handle, x2, y2, data.foreground);
- }
-}
-
-/**
- * Draws the outline of an oval, using the foreground color,
- * within the specified rectangular area.
- * <p>
- * The result is a circle or ellipse that fits within the
- * rectangle specified by the <code>x</code>, <code>y</code>,
- * <code>width</code>, and <code>height</code> arguments.
- * </p><p>
- * The oval covers an area that is <code>width + 1</code>
- * pixels wide and <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper left corner of the oval to be drawn
- * @param y the y coordinate of the upper left corner of the oval to be drawn
- * @param width the width of the oval to be drawn
- * @param height the height of the oval to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawOval (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- int /*long*/ gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend);
- Gdip.Graphics_DrawEllipse(gdipGraphics, data.gdipPen, x, y, width, height);
- Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend);
- return;
- }
- if ((data.style & SWT.MIRRORED) != 0) {
- if (data.lineWidth != 0 && data.lineWidth % 2 == 0) x--;
- }
- OS.Ellipse(handle, x, y, x + width + 1, y + height + 1);
-}
-
-/**
- * Draws the path described by the parameter.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the path to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- *
- * @since 3.1
- */
-public void drawPath (Path path) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- initGdip();
- checkGC(DRAW);
- int /*long*/ gdipGraphics = data.gdipGraphics;
- Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend);
- Gdip.Graphics_DrawPath(gdipGraphics, data.gdipPen, path.handle);
- Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend);
-}
-
-/**
- * Draws a pixel, using the foreground color, at the specified
- * point (<code>x</code>, <code>y</code>).
- * <p>
- * Note that the receiver's line attributes do not affect this
- * operation.
- * </p>
- *
- * @param x the point's x coordinate
- * @param y the point's y coordinate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void drawPoint (int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.gdipGraphics != 0) {
- checkGC(DRAW);
- Gdip.Graphics_FillRectangle(data.gdipGraphics, getFgBrush(), x, y, 1, 1);
- return;
- }
- OS.SetPixel (handle, x, y, data.foreground);
-}
-
-/**
- * Draws the closed polygon which is defined by the specified array
- * of integer coordinates, using the receiver's foreground color. The array
- * contains alternating x and y values which are considered to represent
- * points which are the vertices of the polygon. Lines are drawn between
- * each consecutive pair, and between the first pair and last pair in the
- * array.
- *
- * @param pointArray an array of alternating x and y values which are the vertices of the polygon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT if pointArray is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawPolygon(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(DRAW);
- int /*long*/ gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend);
- Gdip.Graphics_DrawPolygon(gdipGraphics, data.gdipPen, pointArray, pointArray.length / 2);
- Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend);
- return;
- }
- if ((data.style & SWT.MIRRORED) != 0) {
- if (data.lineWidth != 0 && data.lineWidth % 2 == 0) {
- for (int i = 0; i < pointArray.length; i+=2) {
- pointArray[i]--;
- }
- }
- }
- OS.Polygon(handle, pointArray, pointArray.length / 2);
- if ((data.style & SWT.MIRRORED) != 0) {
- if (data.lineWidth != 0 && data.lineWidth % 2 == 0) {
- for (int i = 0; i < pointArray.length; i+=2) {
- pointArray[i]++;
- }
- }
- }
-}
-
-/**
- * Draws the polyline which is defined by the specified array
- * of integer coordinates, using the receiver's foreground color. The array
- * contains alternating x and y values which are considered to represent
- * points which are the corners of the polyline. Lines are drawn between
- * each consecutive pair, but not between the first pair and last pair in
- * the array.
- *
- * @param pointArray an array of alternating x and y values which are the corners of the polyline
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawPolyline(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(DRAW);
- int /*long*/ gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend);
- Gdip.Graphics_DrawLines(gdipGraphics, data.gdipPen, pointArray, pointArray.length / 2);
- Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend);
- return;
- }
- if ((data.style & SWT.MIRRORED) != 0) {
- if (data.lineWidth != 0 && data.lineWidth % 2 == 0) {
- for (int i = 0; i < pointArray.length; i+=2) {
- pointArray[i]--;
- }
- }
- }
- OS.Polyline(handle, pointArray, pointArray.length / 2);
- int length = pointArray.length;
- if (length >= 2) {
- if (data.lineWidth <= 1) {
- OS.SetPixel (handle, pointArray[length - 2], pointArray[length - 1], data.foreground);
- }
- }
- if ((data.style & SWT.MIRRORED) != 0) {
- if (data.lineWidth != 0 && data.lineWidth % 2 == 0) {
- for (int i = 0; i < pointArray.length; i+=2) {
- pointArray[i]++;
- }
- }
- }
-}
-
-/**
- * Draws the outline of the rectangle specified by the arguments,
- * using the receiver's foreground color. The left and right edges
- * of the rectangle are at <code>x</code> and <code>x + width</code>.
- * The top and bottom edges are at <code>y</code> and <code>y + height</code>.
- *
- * @param x the x coordinate of the rectangle to be drawn
- * @param y the y coordinate of the rectangle to be drawn
- * @param width the width of the rectangle to be drawn
- * @param height the height of the rectangle to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRectangle (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- int /*long*/ gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend);
- Gdip.Graphics_DrawRectangle(gdipGraphics, data.gdipPen, x, y, width, height);
- Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend);
- return;
- }
- if ((data.style & SWT.MIRRORED) != 0) {
- /*
- * Note that Rectangle() subtracts one pixel in MIRRORED mode when
- * the pen was created with CreatePen() and its width is 0 or 1.
- */
- if (data.lineWidth > 1) {
- if ((data.lineWidth % 2) == 1) x++;
- } else {
- if (data.hPen != 0 && OS.GetObject(data.hPen, 0, 0) != LOGPEN.sizeof) {
- x++;
- }
- }
- }
- OS.Rectangle (handle, x, y, x + width + 1, y + height + 1);
-}
-
-/**
- * Draws the outline of the specified rectangle, using the receiver's
- * foreground color. The left and right edges of the rectangle are at
- * <code>rect.x</code> and <code>rect.x + rect.width</code>. The top
- * and bottom edges are at <code>rect.y</code> and
- * <code>rect.y + rect.height</code>.
- *
- * @param rect the rectangle to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRectangle (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- drawRectangle (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Draws the outline of the round-cornered rectangle specified by
- * the arguments, using the receiver's foreground color. The left and
- * right edges of the rectangle are at <code>x</code> and <code>x + width</code>.
- * The top and bottom edges are at <code>y</code> and <code>y + height</code>.
- * The <em>roundness</em> of the corners is specified by the
- * <code>arcWidth</code> and <code>arcHeight</code> arguments, which
- * are respectively the width and height of the ellipse used to draw
- * the corners.
- *
- * @param x the x coordinate of the rectangle to be drawn
- * @param y the y coordinate of the rectangle to be drawn
- * @param width the width of the rectangle to be drawn
- * @param height the height of the rectangle to be drawn
- * @param arcWidth the width of the arc
- * @param arcHeight the height of the arc
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (data.gdipGraphics != 0) {
- drawRoundRectangleGdip(data.gdipGraphics, data.gdipPen, x, y, width, height, arcWidth, arcHeight);
- return;
- }
- if ((data.style & SWT.MIRRORED) != 0) {
- if (data.lineWidth != 0 && data.lineWidth % 2 == 0) x--;
- }
- if (OS.IsWinCE) {
- /*
- * Bug in WinCE PPC. On certain devices, RoundRect does not draw
- * all the pixels. The workaround is to draw a round rectangle
- * using lines and arcs.
- */
- if (width == 0 || height == 0) return;
- if (arcWidth == 0 || arcHeight == 0) {
- drawRectangle(x, y, width, height);
- return;
- }
- if (width < 0) {
- x += width;
- width = -width;
- }
- if (height < 0) {
- y += height;
- height = -height;
- }
- if (arcWidth < 0) arcWidth = -arcWidth;
- if (arcHeight < 0) arcHeight = -arcHeight;
- if (arcWidth > width) arcWidth = width;
- if (arcHeight > height) arcHeight = height;
-
- if (arcWidth < width) {
- drawLine(x+arcWidth/2, y, x+width-arcWidth/2, y);
- drawLine(x+arcWidth/2, y+height, x+width-arcWidth/2, y+height);
- }
- if (arcHeight < height) {
- drawLine(x, y+arcHeight/2, x, y+height-arcHeight/2);
- drawLine(x+width, y+arcHeight/2, x+width, y+height-arcHeight/2);
- }
- if (arcWidth != 0 && arcHeight != 0) {
- drawArc(x, y, arcWidth, arcHeight, 90, 90);
- drawArc(x+width-arcWidth, y, arcWidth, arcHeight, 0, 90);
- drawArc(x+width-arcWidth, y+height-arcHeight, arcWidth, arcHeight, 0, -90);
- drawArc(x, y+height-arcHeight, arcWidth, arcHeight, 180, 90);
- }
- } else {
- OS.RoundRect(handle, x,y,x+width+1,y+height+1, arcWidth, arcHeight);
- }
-}
-
-void drawRoundRectangleGdip (int /*long*/ gdipGraphics, int /*long*/ pen, int x, int y, int width, int height, int arcWidth, int arcHeight) {
- int nx = x;
- int ny = y;
- int nw = width;
- int nh = height;
- int naw = arcWidth;
- int nah = arcHeight;
-
- if (nw < 0) {
- nw = 0 - nw;
- nx = nx - nw;
- }
- if (nh < 0) {
- nh = 0 - nh;
- ny = ny - nh;
- }
- if (naw < 0)
- naw = 0 - naw;
- if (nah < 0)
- nah = 0 - nah;
-
- Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend);
- if (naw == 0 || nah == 0) {
- Gdip.Graphics_DrawRectangle(gdipGraphics, data.gdipPen, x, y, width, height);
- } else {
- int /*long*/ path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate);
- if (path == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (nw > naw) {
- if (nh > nah) {
- Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nah, 0, -90);
- Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nah, -90, -90);
- Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, naw, nah, -180, -90);
- Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny + nh - nah, naw, nah, -270, -90);
- } else {
- Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nh, -270, -180);
- Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nh, -90, -180);
- }
- } else {
- if (nh > nah) {
- Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nah, 0, -180);
- Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, nw, nah, -180, -180);
- } else {
- Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nh, 0, 360);
- }
- }
- Gdip.GraphicsPath_CloseFigure(path);
- Gdip.Graphics_DrawPath(gdipGraphics, pen, path);
- Gdip.GraphicsPath_delete(path);
- }
- Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. No tab expansion or carriage return processing
- * will be performed. The background of the rectangular area where
- * the string is being drawn will be filled with the receiver's
- * background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawString (String string, int x, int y) {
- drawString(string, x, y, false);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. No tab expansion or carriage return processing
- * will be performed. If <code>isTransparent</code> is <code>true</code>,
- * then the background of the rectangular area where the string is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawString (String string, int x, int y, boolean isTransparent) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
-// TCHAR buffer = new TCHAR (getCodePage(), string, false);
- int length = string.length();
- if (length == 0) return;
- char[] buffer = new char [length];
- string.getChars(0, length, buffer, 0);
- int /*long*/ gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- checkGC(FONT | FOREGROUND | (isTransparent ? 0 : BACKGROUND));
- int nGlyphs = (length * 3 / 2) + 16;
- GCP_RESULTS result = new GCP_RESULTS();
- result.lStructSize = GCP_RESULTS.sizeof;
- result.nGlyphs = nGlyphs;
- int /*long*/ hHeap = OS.GetProcessHeap();
- int /*long*/ lpDx = result.lpDx = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, nGlyphs * 4);
- int /*long*/ lpGlyphs = result.lpGlyphs = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, nGlyphs * 2);
- int dwFlags = OS.GCP_GLYPHSHAPE | OS.GCP_REORDER | OS.GCP_LIGATE;
- int /*long*/ hdc = Gdip.Graphics_GetHDC(gdipGraphics);
- int /*long*/ hFont = data.hGDIFont;
- if (hFont == 0 && data.font != null) hFont = data.font.handle;
- int /*long*/ oldFont = 0;
- if (hFont != 0) oldFont = OS.SelectObject(hdc, hFont);
- if ((data.style & SWT.MIRRORED) != 0) OS.SetLayout(hdc, OS.GetLayout(hdc) | OS.LAYOUT_RTL);
- OS.GetCharacterPlacementW(hdc, buffer, length, 0, result, dwFlags);
- if ((data.style & SWT.MIRRORED) != 0) OS.SetLayout(hdc, OS.GetLayout(hdc) & ~OS.LAYOUT_RTL);
- TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA();
- OS.GetTextMetrics(hdc, lptm);
- if (hFont != 0) OS.SelectObject(hdc, oldFont);
- Gdip.Graphics_ReleaseHDC(gdipGraphics, hdc);
- nGlyphs = result.nGlyphs;
- int drawX = x, drawY = y + lptm.tmAscent;
- int[] dx = new int[nGlyphs];
- OS.MoveMemory(dx, result.lpDx, nGlyphs * 4);
- float[] points = new float[dx.length * 2];
- for (int i = 0, j = 0; i < dx.length; i++) {
- points[j++] = drawX;
- points[j++] = drawY;
- drawX += dx[i];
- }
- RectF bounds = null;
- if (!isTransparent || (data.style & SWT.MIRRORED) != 0) {
- bounds = new RectF();
- Gdip.Graphics_MeasureDriverString(gdipGraphics, lpGlyphs, nGlyphs, data.gdipFont, points, 0, 0, bounds);
- if (!isTransparent) {
- Gdip.Graphics_FillRectangle(gdipGraphics, data.gdipBrush, x, y, Math.round(bounds.Width), Math.round(bounds.Height));
- }
- }
- int gstate = 0;
- int /*long*/ brush = getFgBrush();
- if ((data.style & SWT.MIRRORED) != 0) {
- switch (Gdip.Brush_GetType(brush)) {
- case Gdip.BrushTypeLinearGradient:
- Gdip.LinearGradientBrush_ScaleTransform(brush, -1, 1, Gdip.MatrixOrderPrepend);
- Gdip.LinearGradientBrush_TranslateTransform(brush, - 2 * x - bounds.Width, 0, Gdip.MatrixOrderPrepend);
- break;
- case Gdip.BrushTypeTextureFill:
- Gdip.TextureBrush_ScaleTransform(brush, -1, 1, Gdip.MatrixOrderPrepend);
- Gdip.TextureBrush_TranslateTransform(brush, - 2 * x - bounds.Width, 0, Gdip.MatrixOrderPrepend);
- break;
- }
- gstate = Gdip.Graphics_Save(gdipGraphics);
- Gdip.Graphics_ScaleTransform(gdipGraphics, -1, 1, Gdip.MatrixOrderPrepend);
- Gdip.Graphics_TranslateTransform(gdipGraphics, - 2 * x - bounds.Width, 0, Gdip.MatrixOrderPrepend);
- }
- Gdip.Graphics_DrawDriverString(gdipGraphics, lpGlyphs, result.nGlyphs, data.gdipFont, brush, points, 0, 0);
- if ((data.style & SWT.MIRRORED) != 0) {
- switch (Gdip.Brush_GetType(brush)) {
- case Gdip.BrushTypeLinearGradient:
- Gdip.LinearGradientBrush_ResetTransform(brush);
- break;
- case Gdip.BrushTypeTextureFill:
- Gdip.TextureBrush_ResetTransform(brush);
- break;
- }
- Gdip.Graphics_Restore(gdipGraphics, gstate);
- }
- OS.HeapFree(hHeap, 0, lpGlyphs);
- OS.HeapFree(hHeap, 0, lpDx);
- return;
- }
- int rop2 = 0;
- if (OS.IsWinCE) {
- rop2 = OS.SetROP2(handle, OS.R2_COPYPEN);
- OS.SetROP2(handle, rop2);
- } else {
- rop2 = OS.GetROP2(handle);
- }
- checkGC(FONT | FOREGROUND_TEXT | BACKGROUND_TEXT);
- int oldBkMode = OS.SetBkMode(handle, isTransparent ? OS.TRANSPARENT : OS.OPAQUE);
- RECT rect = null;
- SIZE size = null;
- int flags = 0;
- if ((data.style & SWT.MIRRORED) != 0) {
- if (!isTransparent) {
- size = new SIZE();
- OS.GetTextExtentPoint32W(handle, buffer, length, size);
- rect = new RECT ();
- rect.left = x;
- rect.right = x + size.cx;
- rect.top = y;
- rect.bottom = y + size.cy;
- flags = OS.ETO_CLIPPED;
- }
- x--;
- }
- if (rop2 != OS.R2_XORPEN) {
- OS.ExtTextOutW(handle, x, y, flags, rect, buffer, length, null);
- } else {
- int foreground = OS.GetTextColor(handle);
- if (isTransparent) {
- if (size == null) {
- size = new SIZE();
- OS.GetTextExtentPoint32W(handle, buffer, length, size);
- }
- int width = size.cx, height = size.cy;
- int /*long*/ hBitmap = OS.CreateCompatibleBitmap(handle, width, height);
- if (hBitmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ memDC = OS.CreateCompatibleDC(handle);
- int /*long*/ hOldBitmap = OS.SelectObject(memDC, hBitmap);
- OS.PatBlt(memDC, 0, 0, width, height, OS.BLACKNESS);
- OS.SetBkMode(memDC, OS.TRANSPARENT);
- OS.SetTextColor(memDC, foreground);
- OS.SelectObject(memDC, OS.GetCurrentObject(handle, OS.OBJ_FONT));
- OS.ExtTextOutW(memDC, 0, 0, 0, null, buffer, length, null);
- OS.BitBlt(handle, x, y, width, height, memDC, 0, 0, OS.SRCINVERT);
- OS.SelectObject(memDC, hOldBitmap);
- OS.DeleteDC(memDC);
- OS.DeleteObject(hBitmap);
- } else {
- int background = OS.GetBkColor(handle);
- OS.SetTextColor(handle, foreground ^ background);
- OS.ExtTextOutW(handle, x, y, flags, rect, buffer, length, null);
- OS.SetTextColor(handle, foreground);
- }
- }
- OS.SetBkMode(handle, oldBkMode);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion and carriage return processing
- * are performed. The background of the rectangular area where
- * the text is being drawn will be filled with the receiver's
- * background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText (String string, int x, int y) {
- drawText(string, x, y, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion and carriage return processing
- * are performed. If <code>isTransparent</code> is <code>true</code>,
- * then the background of the rectangular area where the text is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText (String string, int x, int y, boolean isTransparent) {
- int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB;
- if (isTransparent) flags |= SWT.DRAW_TRANSPARENT;
- drawText(string, x, y, flags);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion, line delimiter and mnemonic
- * processing are performed according to the specified flags. If
- * <code>flags</code> includes <code>DRAW_TRANSPARENT</code>,
- * then the background of the rectangular area where the text is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- * <p>
- * The parameter <code>flags</code> may be a combination of:
- * <dl>
- * <dt><b>DRAW_DELIMITER</b></dt>
- * <dd>draw multiple lines</dd>
- * <dt><b>DRAW_TAB</b></dt>
- * <dd>expand tabs</dd>
- * <dt><b>DRAW_MNEMONIC</b></dt>
- * <dd>underline the mnemonic character</dd>
- * <dt><b>DRAW_TRANSPARENT</b></dt>
- * <dd>transparent background</dd>
- * </dl>
- * </p>
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param flags the flags specifying how to process the text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText (String string, int x, int y, int flags) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (string.length() == 0) return;
- int /*long*/ gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- checkGC(FONT | FOREGROUND | ((flags & SWT.DRAW_TRANSPARENT) != 0 ? 0 : BACKGROUND));
- int length = string.length();
- char[] buffer = new char [length];
- string.getChars(0, length, buffer, 0);
- PointF pt = new PointF();
- int /*long*/ format = Gdip.StringFormat_Clone(Gdip.StringFormat_GenericTypographic());
- int formatFlags = Gdip.StringFormat_GetFormatFlags(format) | Gdip.StringFormatFlagsMeasureTrailingSpaces;
- if ((data.style & SWT.MIRRORED) != 0) formatFlags |= Gdip.StringFormatFlagsDirectionRightToLeft;
- Gdip.StringFormat_SetFormatFlags(format, formatFlags);
- float[] tabs = (flags & SWT.DRAW_TAB) != 0 ? new float[]{measureSpace(data.gdipFont, format) * 8} : new float[1];
- Gdip.StringFormat_SetTabStops(format, 0, tabs.length, tabs);
- int hotkeyPrefix = (flags & SWT.DRAW_MNEMONIC) != 0 ? Gdip.HotkeyPrefixShow : Gdip.HotkeyPrefixNone;
- if ((flags & SWT.DRAW_MNEMONIC) != 0 && (data.uiState & OS.UISF_HIDEACCEL) != 0) hotkeyPrefix = Gdip.HotkeyPrefixHide;
- Gdip.StringFormat_SetHotkeyPrefix(format, hotkeyPrefix);
- if ((flags & SWT.DRAW_TRANSPARENT) == 0) {
- RectF bounds = new RectF();
- Gdip.Graphics_MeasureString(gdipGraphics, buffer, length, data.gdipFont, pt, format, bounds);
- Gdip.Graphics_FillRectangle(gdipGraphics, data.gdipBrush, x, y, Math.round(bounds.Width), Math.round(bounds.Height));
- }
- int gstate = 0;
- int /*long*/ brush = getFgBrush();
- if ((data.style & SWT.MIRRORED) != 0) {
- switch (Gdip.Brush_GetType(brush)) {
- case Gdip.BrushTypeLinearGradient:
- Gdip.LinearGradientBrush_ScaleTransform(brush, -1, 1, Gdip.MatrixOrderPrepend);
- Gdip.LinearGradientBrush_TranslateTransform(brush, - 2 * x, 0, Gdip.MatrixOrderPrepend);
- break;
- case Gdip.BrushTypeTextureFill:
- Gdip.TextureBrush_ScaleTransform(brush, -1, 1, Gdip.MatrixOrderPrepend);
- Gdip.TextureBrush_TranslateTransform(brush, - 2 * x, 0, Gdip.MatrixOrderPrepend);
- break;
- }
- gstate = Gdip.Graphics_Save(gdipGraphics);
- Gdip.Graphics_ScaleTransform(gdipGraphics, -1, 1, Gdip.MatrixOrderPrepend);
- Gdip.Graphics_TranslateTransform(gdipGraphics, - 2 * x, 0, Gdip.MatrixOrderPrepend);
- }
- pt.X = x;
- pt.Y = y;
- Gdip.Graphics_DrawString(gdipGraphics, buffer, length, data.gdipFont, pt, format, brush);
- if ((data.style & SWT.MIRRORED) != 0) {
- switch (Gdip.Brush_GetType(brush)) {
- case Gdip.BrushTypeLinearGradient:
- Gdip.LinearGradientBrush_ResetTransform(brush);
- break;
- case Gdip.BrushTypeTextureFill:
- Gdip.TextureBrush_ResetTransform(brush);
- break;
- }
- Gdip.Graphics_Restore(gdipGraphics, gstate);
- }
- Gdip.StringFormat_delete(format);
- return;
- }
- TCHAR buffer = new TCHAR(getCodePage(), string, false);
- int length = buffer.length();
- if (length == 0) return;
- RECT rect = new RECT();
- /*
- * Feature in Windows. For some reason DrawText(), the maximum
- * value for the bottom and right coordinates for the RECT that
- * is used to position the text is different on between Windows
- * versions. If this value is larger than the maximum, nothing
- * is drawn. On Windows 98, the limit is 0x7FFF. On Windows CE,
- * NT, and 2000 it is 0x6FFFFFF. And on XP, it is 0x7FFFFFFF.
- * The fix is to use the the smaller limit for Windows 98 and the
- * larger limit on the other Windows platforms.
- */
- int limit = OS.IsWin95 ? 0x7FFF : 0x6FFFFFF;
- OS.SetRect(rect, x, y, limit, limit);
- int uFormat = OS.DT_LEFT;
- if ((flags & SWT.DRAW_DELIMITER) == 0) uFormat |= OS.DT_SINGLELINE;
- if ((flags & SWT.DRAW_TAB) != 0) uFormat |= OS.DT_EXPANDTABS;
- if ((flags & SWT.DRAW_MNEMONIC) == 0) uFormat |= OS.DT_NOPREFIX;
- if ((flags & SWT.DRAW_MNEMONIC) != 0 && (data.uiState & OS.UISF_HIDEACCEL) != 0) {
- uFormat |= OS.DT_HIDEPREFIX;
- }
- int rop2 = 0;
- if (OS.IsWinCE) {
- rop2 = OS.SetROP2(handle, OS.R2_COPYPEN);
- OS.SetROP2(handle, rop2);
- } else {
- rop2 = OS.GetROP2(handle);
- }
- checkGC(FONT | FOREGROUND_TEXT | BACKGROUND_TEXT);
- int oldBkMode = OS.SetBkMode(handle, (flags & SWT.DRAW_TRANSPARENT) != 0 ? OS.TRANSPARENT : OS.OPAQUE);
- if (rop2 != OS.R2_XORPEN) {
- OS.DrawText(handle, buffer, length, rect, uFormat);
- } else {
- int foreground = OS.GetTextColor(handle);
- if ((flags & SWT.DRAW_TRANSPARENT) != 0) {
- OS.DrawText(handle, buffer, buffer.length(), rect, uFormat | OS.DT_CALCRECT);
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- int /*long*/ hBitmap = OS.CreateCompatibleBitmap(handle, width, height);
- if (hBitmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ memDC = OS.CreateCompatibleDC(handle);
- int /*long*/ hOldBitmap = OS.SelectObject(memDC, hBitmap);
- OS.PatBlt(memDC, 0, 0, width, height, OS.BLACKNESS);
- OS.SetBkMode(memDC, OS.TRANSPARENT);
- OS.SetTextColor(memDC, foreground);
- OS.SelectObject(memDC, OS.GetCurrentObject(handle, OS.OBJ_FONT));
- OS.SetRect(rect, 0, 0, 0x7FFF, 0x7FFF);
- OS.DrawText(memDC, buffer, length, rect, uFormat);
- OS.BitBlt(handle, x, y, width, height, memDC, 0, 0, OS.SRCINVERT);
- OS.SelectObject(memDC, hOldBitmap);
- OS.DeleteDC(memDC);
- OS.DeleteObject(hBitmap);
- } else {
- int background = OS.GetBkColor(handle);
- OS.SetTextColor(handle, foreground ^ background);
- OS.DrawText(handle, buffer, length, rect, uFormat);
- OS.SetTextColor(handle, foreground);
- }
- }
- OS.SetBkMode(handle, oldBkMode);
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- return (object == this) || ((object instanceof GC) && (handle == ((GC)object).handle));
-}
-
-/**
- * Fills the interior of a circular or elliptical arc within
- * the specified rectangular area, with the receiver's background
- * color.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees, using the current color.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc to be filled
- * @param y the y coordinate of the upper-left corner of the arc to be filled
- * @param width the width of the arc to be filled
- * @param height the height of the arc to be filled
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawArc
- */
-public void fillArc (int x, int y, int width, int height, int startAngle, int arcAngle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- int /*long*/ gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- if (width == height) {
- Gdip.Graphics_FillPie(gdipGraphics, data.gdipBrush, x, y, width, height, -startAngle, -arcAngle);
- } else {
- int state = Gdip.Graphics_Save(gdipGraphics);
- Gdip.Graphics_TranslateTransform(gdipGraphics, x, y, Gdip.MatrixOrderPrepend);
- Gdip.Graphics_ScaleTransform(gdipGraphics, width, height, Gdip.MatrixOrderPrepend);
- Gdip.Graphics_FillPie(gdipGraphics, data.gdipBrush, 0, 0, 1, 1, -startAngle, -arcAngle);
- Gdip.Graphics_Restore(gdipGraphics, state);
- }
- return;
- }
-
- if ((data.style & SWT.MIRRORED) != 0) x--;
- /*
- * Feature in WinCE. The function Pie is not present in the
- * WinCE SDK. The fix is to emulate it by using Polygon.
- */
- if (OS.IsWinCE) {
- /* compute arc with a simple linear interpolation */
- if (arcAngle < 0) {
- startAngle += arcAngle;
- arcAngle = -arcAngle;
- }
- boolean drawSegments = true;
- if (arcAngle >= 360) {
- arcAngle = 360;
- drawSegments = false;
- }
- int[] points = new int[(arcAngle + 1) * 2 + (drawSegments ? 4 : 0)];
- int cteX = 2 * x + width;
- int cteY = 2 * y + height;
- int index = (drawSegments ? 2 : 0);
- for (int i = 0; i <= arcAngle; i++) {
- points[index++] = (Compatibility.cos(startAngle + i, width) + cteX) >> 1;
- points[index++] = (cteY - Compatibility.sin(startAngle + i, height)) >> 1;
- }
- if (drawSegments) {
- points[0] = points[points.length - 2] = cteX >> 1;
- points[1] = points[points.length - 1] = cteY >> 1;
- }
- OS.Polygon(handle, points, points.length / 2);
- } else {
- int x1, y1, x2, y2,tmp;
- boolean isNegative;
- if (arcAngle >= 360 || arcAngle <= -360) {
- x1 = x2 = x + width;
- y1 = y2 = y + height / 2;
- } else {
- isNegative = arcAngle < 0;
-
- arcAngle = arcAngle + startAngle;
- if (isNegative) {
- // swap angles
- tmp = startAngle;
- startAngle = arcAngle;
- arcAngle = tmp;
- }
- x1 = Compatibility.cos(startAngle, width) + x + width/2;
- y1 = -1 * Compatibility.sin(startAngle, height) + y + height/2;
-
- x2 = Compatibility.cos(arcAngle, width) + x + width/2;
- y2 = -1 * Compatibility.sin(arcAngle, height) + y + height/2;
- }
- OS.Pie(handle, x, y, x + width + 1, y + height + 1, x1, y1, x2, y2);
- }
-}
-
-/**
- * Fills the interior of the specified rectangle with a gradient
- * sweeping from left to right or top to bottom progressing
- * from the receiver's foreground color to its background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled, may be negative
- * (inverts direction of gradient if horizontal)
- * @param height the height of the rectangle to be filled, may be negative
- * (inverts direction of gradient if vertical)
- * @param vertical if true sweeps from top to bottom, else
- * sweeps from left to right
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width == 0 || height == 0) return;
-
- RGB backgroundRGB, foregroundRGB;
- backgroundRGB = getBackground().getRGB();
- foregroundRGB = getForeground().getRGB();
-
- RGB fromRGB, toRGB;
- fromRGB = foregroundRGB;
- toRGB = backgroundRGB;
-
- boolean swapColors = false;
- if (width < 0) {
- x += width; width = -width;
- if (! vertical) swapColors = true;
- }
- if (height < 0) {
- y += height; height = -height;
- if (vertical) swapColors = true;
- }
- if (swapColors) {
- fromRGB = backgroundRGB;
- toRGB = foregroundRGB;
- }
- if (fromRGB.equals(toRGB)) {
- fillRectangle(x, y, width, height);
- return;
- }
- if (data.gdipGraphics != 0) {
- initGdip();
- PointF p1= new PointF(), p2 = new PointF();
- p1.X = x;
- p1.Y = y;
- if (vertical) {
- p2.X = p1.X;
- p2.Y = p1.Y + height;
- } else {
- p2.X = p1.X + width;
- p2.Y = p1.Y;
- }
- int rgb = ((fromRGB.red & 0xFF) << 16) | ((fromRGB.green & 0xFF) << 8) | (fromRGB.blue & 0xFF);
- int /*long*/ fromGpColor = Gdip.Color_new(data.alpha << 24 | rgb);
- if (fromGpColor == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- rgb = ((toRGB.red & 0xFF) << 16) | ((toRGB.green & 0xFF) << 8) | (toRGB.blue & 0xFF);
- int /*long*/ toGpColor = Gdip.Color_new(data.alpha << 24 | rgb);
- if (toGpColor == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ brush = Gdip.LinearGradientBrush_new(p1, p2, fromGpColor, toGpColor);
- Gdip.Graphics_FillRectangle(data.gdipGraphics, brush, x, y, width, height);
- Gdip.LinearGradientBrush_delete(brush);
- Gdip.Color_delete(fromGpColor);
- Gdip.Color_delete(toGpColor);
- return;
- }
- /* Use GradientFill if supported, only on Windows 98, 2000 and newer. */
- /*
- * Bug in Windows: On Windows 2000 when the device is a printer,
- * GradientFill swaps red and blue color components, causing the
- * gradient to be printed in the wrong color. On Windows 98 when
- * the device is a printer, GradientFill does not fill completely
- * to the right edge of the rectangle. The fix is not to use
- * GradientFill for printer devices.
- */
- int rop2 = 0;
- if (OS.IsWinCE) {
- rop2 = OS.SetROP2(handle, OS.R2_COPYPEN);
- OS.SetROP2(handle, rop2);
- } else {
- rop2 = OS.GetROP2(handle);
- }
- if (OS.IsWinNT && rop2 != OS.R2_XORPEN && OS.GetDeviceCaps(handle, OS.TECHNOLOGY) != OS.DT_RASPRINTER) {
- final int /*long*/ hHeap = OS.GetProcessHeap();
- final int /*long*/ pMesh = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, GRADIENT_RECT.sizeof + TRIVERTEX.sizeof * 2);
- if (pMesh == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- final int /*long*/ pVertex = pMesh + GRADIENT_RECT.sizeof;
-
- GRADIENT_RECT gradientRect = new GRADIENT_RECT();
- gradientRect.UpperLeft = 0;
- gradientRect.LowerRight = 1;
- OS.MoveMemory(pMesh, gradientRect, GRADIENT_RECT.sizeof);
-
- TRIVERTEX trivertex = new TRIVERTEX();
- trivertex.x = x;
- trivertex.y = y;
- trivertex.Red = (short)((fromRGB.red << 8) | fromRGB.red);
- trivertex.Green = (short)((fromRGB.green << 8) | fromRGB.green);
- trivertex.Blue = (short)((fromRGB.blue << 8) | fromRGB.blue);
- trivertex.Alpha = -1;
- OS.MoveMemory(pVertex, trivertex, TRIVERTEX.sizeof);
-
- trivertex.x = x + width;
- trivertex.y = y + height;
- trivertex.Red = (short)((toRGB.red << 8) | toRGB.red);
- trivertex.Green = (short)((toRGB.green << 8) | toRGB.green);
- trivertex.Blue = (short)((toRGB.blue << 8) | toRGB.blue);
- trivertex.Alpha = -1;
- OS.MoveMemory(pVertex + TRIVERTEX.sizeof, trivertex, TRIVERTEX.sizeof);
-
- boolean success = OS.GradientFill(handle, pVertex, 2, pMesh, 1, vertical ? OS.GRADIENT_FILL_RECT_V : OS.GRADIENT_FILL_RECT_H);
- OS.HeapFree(hHeap, 0, pMesh);
- if (success) return;
- }
-
- final int depth = OS.GetDeviceCaps(handle, OS.BITSPIXEL);
- final int bitResolution = (depth >= 24) ? 8 : (depth >= 15) ? 5 : 0;
- ImageData.fillGradientRectangle(this, data.device,
- x, y, width, height, vertical, fromRGB, toRGB,
- bitResolution, bitResolution, bitResolution);
-}
-
-/**
- * Fills the interior of an oval, within the specified
- * rectangular area, with the receiver's background
- * color.
- *
- * @param x the x coordinate of the upper left corner of the oval to be filled
- * @param y the y coordinate of the upper left corner of the oval to be filled
- * @param width the width of the oval to be filled
- * @param height the height of the oval to be filled
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawOval
- */
-public void fillOval (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (data.gdipGraphics != 0) {
- Gdip.Graphics_FillEllipse(data.gdipGraphics, data.gdipBrush, x, y, width, height);
- return;
- }
- if ((data.style & SWT.MIRRORED) != 0) x--;
- OS.Ellipse(handle, x, y, x + width + 1, y + height + 1);
-}
-
-/**
- * Fills the path described by the parameter.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the path to fill
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- *
- * @since 3.1
- */
-public void fillPath (Path path) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- initGdip();
- checkGC(FILL);
- int mode = OS.GetPolyFillMode(handle) == OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate;
- Gdip.GraphicsPath_SetFillMode(path.handle, mode);
- Gdip.Graphics_FillPath(data.gdipGraphics, data.gdipBrush, path.handle);
-}
-
-/**
- * Fills the interior of the closed polygon which is defined by the
- * specified array of integer coordinates, using the receiver's
- * background color. The array contains alternating x and y values
- * which are considered to represent points which are the vertices of
- * the polygon. Lines are drawn between each consecutive pair, and
- * between the first pair and last pair in the array.
- *
- * @param pointArray an array of alternating x and y values which are the vertices of the polygon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT if pointArray is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawPolygon
- */
-public void fillPolygon(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(FILL);
- if (data.gdipGraphics != 0) {
- int mode = OS.GetPolyFillMode(handle) == OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate;
- Gdip.Graphics_FillPolygon(data.gdipGraphics, data.gdipBrush, pointArray, pointArray.length / 2, mode);
- return;
- }
- if ((data.style & SWT.MIRRORED) != 0) {
- for (int i = 0; i < pointArray.length; i+=2) {
- pointArray[i]--;
- }
- }
- OS.Polygon(handle, pointArray, pointArray.length / 2);
- if ((data.style & SWT.MIRRORED) != 0) {
- for (int i = 0; i < pointArray.length; i+=2) {
- pointArray[i]++;
- }
- }
-}
-
-/**
- * Fills the interior of the rectangle specified by the arguments,
- * using the receiver's background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillRectangle (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (data.gdipGraphics != 0) {
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- Gdip.Graphics_FillRectangle(data.gdipGraphics, data.gdipBrush, x, y, width, height);
- return;
- }
- int rop2 = 0;
- if (OS.IsWinCE) {
- rop2 = OS.SetROP2(handle, OS.R2_COPYPEN);
- OS.SetROP2(handle, rop2);
- } else {
- rop2 = OS.GetROP2(handle);
- }
- int dwRop = rop2 == OS.R2_XORPEN ? OS.PATINVERT : OS.PATCOPY;
- OS.PatBlt(handle, x, y, width, height, dwRop);
-}
-
-/**
- * Fills the interior of the specified rectangle, using the receiver's
- * background color.
- *
- * @param rect the rectangle to be filled
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillRectangle (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- fillRectangle (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Fills the interior of the round-cornered rectangle specified by
- * the arguments, using the receiver's background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- * @param arcWidth the width of the arc
- * @param arcHeight the height of the arc
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRoundRectangle
- */
-public void fillRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (data.gdipGraphics != 0) {
- fillRoundRectangleGdip(data.gdipGraphics, data.gdipBrush, x, y, width, height, arcWidth, arcHeight);
- return;
- }
- if ((data.style & SWT.MIRRORED) != 0) x--;
- OS.RoundRect(handle, x,y,x+width+1,y+height+1,arcWidth, arcHeight);
-}
-
-void fillRoundRectangleGdip (int /*long*/ gdipGraphics, int /*long*/ brush, int x, int y, int width, int height, int arcWidth, int arcHeight) {
- int nx = x;
- int ny = y;
- int nw = width;
- int nh = height;
- int naw = arcWidth;
- int nah = arcHeight;
-
- if (nw < 0) {
- nw = 0 - nw;
- nx = nx - nw;
- }
- if (nh < 0) {
- nh = 0 - nh;
- ny = ny -nh;
- }
- if (naw < 0)
- naw = 0 - naw;
- if (nah < 0)
- nah = 0 - nah;
-
- if (naw == 0 || nah == 0) {
- Gdip.Graphics_FillRectangle(data.gdipGraphics, data.gdipBrush, x, y, width, height);
- } else {
- int /*long*/ path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate);
- if (path == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (nw > naw) {
- if (nh > nah) {
- Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nah, 0, -90);
- Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nah, -90, -90);
- Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, naw, nah, -180, -90);
- Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny + nh - nah, naw, nah, -270, -90);
- } else {
- Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nh, -270, -180);
- Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nh, -90, -180);
- }
- } else {
- if (nh > nah) {
- Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nah, 0, -180);
- Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, nw, nah, -180, -180);
- } else {
- Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nh, 0, 360);
- }
- }
- Gdip.GraphicsPath_CloseFigure(path);
- Gdip.Graphics_FillPath(gdipGraphics, brush, path);
- Gdip.GraphicsPath_delete(path);
- }
-}
-
-void flush () {
- if (data.gdipGraphics != 0) {
- Gdip.Graphics_Flush(data.gdipGraphics, 0);
- /*
- * Note Flush() does not flush the output to the
- * underline HDC. This is done by calling GetHDC()
- * followed by ReleaseHDC().
- */
- int /*long*/ hdc = Gdip.Graphics_GetHDC(data.gdipGraphics);
- Gdip.Graphics_ReleaseHDC(data.gdipGraphics, hdc);
- }
-}
-
-/**
- * Returns the <em>advance width</em> of the specified character in
- * the font which is currently selected into the receiver.
- * <p>
- * The advance width is defined as the horizontal distance the cursor
- * should move after printing the character in the selected font.
- * </p>
- *
- * @param ch the character to measure
- * @return the distance in the x direction to move past the character before painting the next
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getAdvanceWidth(char ch) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FONT);
- if (OS.IsWinCE) {
- SIZE size = new SIZE();
- OS.GetTextExtentPoint32W(handle, new char[]{ch}, 1, size);
- return size.cx;
- }
- int tch = ch;
- if (ch > 0x7F) {
- TCHAR buffer = new TCHAR(getCodePage(), ch, false);
- tch = buffer.tcharAt(0);
- }
- int[] width = new int[1];
- OS.GetCharWidth(handle, tch, tch, width);
- return width[0];
-}
-
-/**
- * Returns <code>true</code> if receiver is using the operating system's
- * advanced graphics subsystem. Otherwise, <code>false</code> is returned
- * to indicate that normal graphics are in use.
- * <p>
- * Advanced graphics may not be installed for the operating system. In this
- * case, <code>false</code> is always returned. Some operating system have
- * only one graphics subsystem. If this subsystem supports advanced graphics,
- * then <code>true</code> is always returned. If any graphics operation such
- * as alpha, antialias, patterns, interpolation, paths, clipping or transformation
- * has caused the receiver to switch from regular to advanced graphics mode,
- * <code>true</code> is returned. If the receiver has been explicitly switched
- * to advanced mode and this mode is supported, <code>true</code> is returned.
- * </p>
- *
- * @return the advanced value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public boolean getAdvanced() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.gdipGraphics != 0;
-}
-
-/**
- * Returns the receiver's alpha value. The alpha value
- * is between 0 (transparent) and 255 (opaque).
- *
- * @return the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getAlpha() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.alpha;
-}
-
-/**
- * Returns the receiver's anti-aliasing setting value, which will be
- * one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code>. Note that this controls anti-aliasing for all
- * <em>non-text drawing</em> operations.
- *
- * @return the anti-aliasing setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getTextAntialias
- *
- * @since 3.1
- */
-public int getAntialias() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.gdipGraphics == 0) return SWT.DEFAULT;
- int mode = Gdip.Graphics_GetSmoothingMode(data.gdipGraphics);
- switch (mode) {
- case Gdip.SmoothingModeDefault: return SWT.DEFAULT;
- case Gdip.SmoothingModeHighSpeed:
- case Gdip.SmoothingModeNone: return SWT.OFF;
- case Gdip.SmoothingModeAntiAlias:
- case Gdip.SmoothingModeAntiAlias8x8:
- case Gdip.SmoothingModeHighQuality: return SWT.ON;
- }
- return SWT.DEFAULT;
-}
-
-/**
- * Returns the background color.
- *
- * @return the receiver's background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getBackground() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return Color.win32_new(data.device, data.background);
-}
-
-/**
- * Returns the background pattern. The default value is
- * <code>null</code>.
- *
- * @return the receiver's background pattern
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Pattern
- *
- * @since 3.1
- */
-public Pattern getBackgroundPattern() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.backgroundPattern;
-}
-
-/**
- * Returns the width of the specified character in the font
- * selected into the receiver.
- * <p>
- * The width is defined as the space taken up by the actual
- * character, not including the leading and tailing whitespace
- * or overhang.
- * </p>
- *
- * @param ch the character to measure
- * @return the width of the character
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getCharWidth(char ch) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FONT);
-
- /* GetCharABCWidths only succeeds on truetype fonts */
- if (!OS.IsWinCE) {
- int tch = ch;
- if (ch > 0x7F) {
- TCHAR buffer = new TCHAR(getCodePage(), ch, false);
- tch = buffer.tcharAt (0);
- }
- int[] width = new int[3];
- if (OS.GetCharABCWidths(handle, tch, tch, width)) {
- return width[1];
- }
- }
-
- /* It wasn't a truetype font */
- TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA();
- OS.GetTextMetrics(handle, lptm);
- SIZE size = new SIZE();
- OS.GetTextExtentPoint32W(handle, new char[]{ch}, 1, size);
- return size.cx - lptm.tmOverhang;
-}
-
-/**
- * Returns the bounding rectangle of the receiver's clipping
- * region. If no clipping region is set, the return value
- * will be a rectangle which covers the entire bounds of the
- * object the receiver is drawing on.
- *
- * @return the bounding rectangle of the clipping region
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getClipping() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int /*long*/ gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- Rect rect = new Rect();
- Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone);
- Gdip.Graphics_GetVisibleClipBounds(gdipGraphics, rect);
- Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf);
- return new Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
- }
- RECT rect = new RECT();
- OS.GetClipBox(handle, rect);
- return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
-}
-
-/**
- * Sets the region managed by the argument to the current
- * clipping region of the receiver.
- *
- * @param region the region to fill with the clipping region
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the region is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the region is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getClipping (Region region) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- int /*long*/ gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- int /*long*/ rgn = Gdip.Region_new();
- Gdip.Graphics_GetClip(data.gdipGraphics, rgn);
- if (Gdip.Region_IsInfinite(rgn, gdipGraphics)) {
- Rect rect = new Rect();
- Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone);
- Gdip.Graphics_GetVisibleClipBounds(gdipGraphics, rect);
- Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf);
- OS.SetRectRgn(region.handle, rect.X, rect.Y, rect.X + rect.Width, rect.Y + rect.Height);
- } else {
- int /*long*/ matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0);
- int /*long*/ identity = Gdip.Matrix_new(1, 0, 0, 1, 0, 0);
- Gdip.Graphics_GetTransform(gdipGraphics, matrix);
- Gdip.Graphics_SetTransform(gdipGraphics, identity);
- int /*long*/ hRgn = Gdip.Region_GetHRGN(rgn, data.gdipGraphics);
- Gdip.Graphics_SetTransform(gdipGraphics, matrix);
- Gdip.Matrix_delete(identity);
- Gdip.Matrix_delete(matrix);
- if (!OS.IsWinCE) {
- POINT pt = new POINT ();
- OS.GetWindowOrgEx (handle, pt);
- OS.OffsetRgn (hRgn, pt.x, pt.y);
- }
- OS.CombineRgn(region.handle, hRgn, 0, OS.RGN_COPY);
- OS.DeleteObject(hRgn);
- }
- Gdip.Region_delete(rgn);
- return;
- }
- POINT pt = new POINT ();
- if (!OS.IsWinCE) OS.GetWindowOrgEx (handle, pt);
- int result = OS.GetClipRgn (handle, region.handle);
- if (result != 1) {
- RECT rect = new RECT();
- OS.GetClipBox(handle, rect);
- OS.SetRectRgn(region.handle, rect.left, rect.top, rect.right, rect.bottom);
- } else {
- OS.OffsetRgn (region.handle, pt.x, pt.y);
- }
- if (!OS.IsWinCE) {
- int /*long*/ metaRgn = OS.CreateRectRgn (0, 0, 0, 0);
- if (OS.GetMetaRgn (handle, metaRgn) != 0) {
- OS.OffsetRgn (metaRgn, pt.x, pt.y);
- OS.CombineRgn (region.handle, metaRgn, region.handle, OS.RGN_AND);
- }
- OS.DeleteObject(metaRgn);
- int /*long*/ hwnd = data.hwnd;
- if (hwnd != 0 && data.ps != null) {
- int /*long*/ sysRgn = OS.CreateRectRgn (0, 0, 0, 0);
- if (OS.GetRandomRgn (handle, sysRgn, OS.SYSRGN) == 1) {
- if (OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
- if ((OS.GetLayout(handle) & OS.LAYOUT_RTL) != 0) {
- int nBytes = OS.GetRegionData (sysRgn, 0, null);
- int [] lpRgnData = new int [nBytes / 4];
- OS.GetRegionData (sysRgn, nBytes, lpRgnData);
- int /*long*/ newSysRgn = OS.ExtCreateRegion(new float [] {-1, 0, 0, 1, 0, 0}, nBytes, lpRgnData);
- OS.DeleteObject(sysRgn);
- sysRgn = newSysRgn;
- }
- }
- if (OS.IsWinNT) {
- OS.MapWindowPoints(0, hwnd, pt, 1);
- OS.OffsetRgn(sysRgn, pt.x, pt.y);
- }
- OS.CombineRgn (region.handle, sysRgn, region.handle, OS.RGN_AND);
- }
- OS.DeleteObject(sysRgn);
- }
- }
-}
-
-int getCodePage () {
- if (OS.IsUnicode) return OS.CP_ACP;
- int[] lpCs = new int[8];
- int cs = OS.GetTextCharset(handle);
- OS.TranslateCharsetInfo(cs, lpCs, OS.TCI_SRCCHARSET);
- return lpCs[1];
-}
-
-int /*long*/ getFgBrush() {
- return data.foregroundPattern != null ? data.foregroundPattern.handle : data.gdipFgBrush;
-}
-
-/**
- * Returns the receiver's fill rule, which will be one of
- * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>.
- *
- * @return the receiver's fill rule
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getFillRule() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (OS.IsWinCE) return SWT.FILL_EVEN_ODD;
- return OS.GetPolyFillMode(handle) == OS.WINDING ? SWT.FILL_WINDING : SWT.FILL_EVEN_ODD;
-}
-
-/**
- * Returns the font currently being used by the receiver
- * to draw and measure text.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getFont () {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.font;
-}
-
-/**
- * Returns a FontMetrics which contains information
- * about the font currently being used by the receiver
- * to draw and measure text.
- *
- * @return font metrics for the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontMetrics getFontMetrics() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FONT);
- TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA();
- OS.GetTextMetrics(handle, lptm);
- return FontMetrics.win32_new(lptm);
-}
-
-/**
- * Returns the receiver's foreground color.
- *
- * @return the color used for drawing foreground things
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getForeground() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return Color.win32_new(data.device, data.foreground);
-}
-
-/**
- * Returns the foreground pattern. The default value is
- * <code>null</code>.
- *
- * @return the receiver's foreground pattern
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Pattern
- *
- * @since 3.1
- */
-public Pattern getForegroundPattern() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.foregroundPattern;
-}
-
-/**
- * Returns the GCData.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>GC</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @return the receiver's GCData
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see GCData
- *
- * @since 3.2
- * @noreference This method is not intended to be referenced by clients.
- */
-public GCData getGCData() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data;
-}
-
-/**
- * Returns the receiver's interpolation setting, which will be one of
- * <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>,
- * <code>SWT.LOW</code> or <code>SWT.HIGH</code>.
- *
- * @return the receiver's interpolation setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getInterpolation() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.gdipGraphics == 0) return SWT.DEFAULT;
- int mode = Gdip.Graphics_GetInterpolationMode(data.gdipGraphics);
- switch (mode) {
- case Gdip.InterpolationModeDefault: return SWT.DEFAULT;
- case Gdip.InterpolationModeNearestNeighbor: return SWT.NONE;
- case Gdip.InterpolationModeBilinear:
- case Gdip.InterpolationModeLowQuality: return SWT.LOW;
- case Gdip.InterpolationModeBicubic:
- case Gdip.InterpolationModeHighQualityBilinear:
- case Gdip.InterpolationModeHighQualityBicubic:
- case Gdip.InterpolationModeHighQuality: return SWT.HIGH;
- }
- return SWT.DEFAULT;
-}
-
-/**
- * Returns the receiver's line attributes.
- *
- * @return the line attributes used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.3
- */
-public LineAttributes getLineAttributes() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float[] dashes = null;
- if (data.lineDashes != null) {
- dashes = new float[data.lineDashes.length];
- System.arraycopy(data.lineDashes, 0, dashes, 0, dashes.length);
- }
- return new LineAttributes(data.lineWidth, data.lineCap, data.lineJoin, data.lineStyle, dashes, data.lineDashesOffset, data.lineMiterLimit);
-}
-
-/**
- * Returns the receiver's line cap style, which will be one
- * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>,
- * or <code>SWT.CAP_SQUARE</code>.
- *
- * @return the cap style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getLineCap() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineCap;
-}
-
-/**
- * Returns the receiver's line dash style. The default value is
- * <code>null</code>.
- *
- * @return the line dash style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int[] getLineDash() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineDashes == null) return null;
- int[] lineDashes = new int[data.lineDashes.length];
- for (int i = 0; i < lineDashes.length; i++) {
- lineDashes[i] = (int)data.lineDashes[i];
- }
- return lineDashes;
-}
-
-/**
- * Returns the receiver's line join style, which will be one
- * of the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>,
- * or <code>SWT.JOIN_BEVEL</code>.
- *
- * @return the join style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getLineJoin() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineJoin;
-}
-
-/**
- * Returns the receiver's line style, which will be one
- * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
- * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or
- * <code>SWT.LINE_DASHDOTDOT</code>.
- *
- * @return the style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineStyle() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineStyle;
-}
-
-/**
- * Returns the width that will be used when drawing lines
- * for all of the figure drawing operations (that is,
- * <code>drawLine</code>, <code>drawRectangle</code>,
- * <code>drawPolyline</code>, and so forth.
- *
- * @return the receiver's line width
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineWidth() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (int)data.lineWidth;
-}
-
-/**
- * Returns the receiver's style information.
- * <p>
- * Note that the value which is returned by this method <em>may
- * not match</em> the value which was provided to the constructor
- * when the receiver was created. This can occur when the underlying
- * operating system does not support a particular combination of
- * requested styles.
- * </p>
- *
- * @return the style bits
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getStyle () {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.style;
-}
-
-/**
- * Returns the receiver's text drawing anti-aliasing setting value,
- * which will be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code>. Note that this controls anti-aliasing
- * <em>only</em> for text drawing operations.
- *
- * @return the anti-aliasing setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getAntialias
- *
- * @since 3.1
- */
-public int getTextAntialias() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.gdipGraphics == 0) return SWT.DEFAULT;
- int mode = Gdip.Graphics_GetTextRenderingHint(data.gdipGraphics);
- switch (mode) {
- case Gdip.TextRenderingHintSystemDefault: return SWT.DEFAULT;
- case Gdip.TextRenderingHintSingleBitPerPixel:
- case Gdip.TextRenderingHintSingleBitPerPixelGridFit: return SWT.OFF;
- case Gdip.TextRenderingHintAntiAlias:
- case Gdip.TextRenderingHintAntiAliasGridFit:
- case Gdip.TextRenderingHintClearTypeGridFit: return SWT.ON;
- }
- return SWT.DEFAULT;
-}
-
-/**
- * Sets the parameter to the transform that is currently being
- * used by the receiver.
- *
- * @param transform the destination to copy the transform into
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Transform
- *
- * @since 3.1
- */
-public void getTransform(Transform transform) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transform == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int /*long*/ gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- Gdip.Graphics_GetTransform(gdipGraphics, transform.handle);
- int /*long*/ identity = identity();
- Gdip.Matrix_Invert(identity);
- Gdip.Matrix_Multiply(transform.handle, identity, Gdip.MatrixOrderAppend);
- Gdip.Matrix_delete(identity);
- } else {
- transform.setElements(1, 0, 0, 1, 0, 0);
- }
-}
-
-/**
- * Returns <code>true</code> if this GC is drawing in the mode
- * where the resulting color in the destination is the
- * <em>exclusive or</em> of the color values in the source
- * and the destination, and <code>false</code> if it is
- * drawing in the mode where the destination color is being
- * replaced with the source color value.
- *
- * @return <code>true</code> true if the receiver is in XOR mode, and false otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean getXORMode() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int rop2 = 0;
- if (OS.IsWinCE) {
- rop2 = OS.SetROP2 (handle, OS.R2_COPYPEN);
- OS.SetROP2 (handle, rop2);
- } else {
- rop2 = OS.GetROP2(handle);
- }
- return rop2 == OS.R2_XORPEN;
-}
-
-void initGdip() {
- data.device.checkGDIP();
- int /*long*/ gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) return;
- /*
- * Feature in GDI+. The GDI+ clipping set with Graphics->SetClip()
- * is always intersected with the GDI clipping at the time the
- * GDI+ graphics is created. This means that the clipping
- * cannot be reset. The fix is to clear the clipping before
- * the GDI+ graphics is created and reset it afterwards.
- */
- int /*long*/ hRgn = OS.CreateRectRgn(0, 0, 0, 0);
- int result = OS.GetClipRgn(handle, hRgn);
- if (!OS.IsWinCE) {
- POINT pt = new POINT ();
- OS.GetWindowOrgEx (handle, pt);
- OS.OffsetRgn (hRgn, pt.x, pt.y);
- }
- OS.SelectClipRgn(handle, 0);
-
- /*
- * Bug in GDI+. GDI+ does not work when the HDC layout is RTL. There
- * are many issues like pixel corruption, but the most visible problem
- * is that it does not have an effect when drawing to an bitmap. The
- * fix is to clear the bit before creating the GDI+ graphics and install
- * a mirroring matrix ourselves.
- */
- if ((data.style & SWT.MIRRORED) != 0) {
- OS.SetLayout(handle, OS.GetLayout(handle) & ~OS.LAYOUT_RTL);
- }
-
- gdipGraphics = data.gdipGraphics = Gdip.Graphics_new(handle);
- if (gdipGraphics == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Gdip.Graphics_SetPageUnit(gdipGraphics, Gdip.UnitPixel);
- Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf);
- if ((data.style & SWT.MIRRORED) != 0) {
- int /*long*/ matrix = identity();
- Gdip.Graphics_SetTransform(gdipGraphics, matrix);
- Gdip.Matrix_delete(matrix);
- }
- if (result == 1) setClipping(hRgn);
- OS.DeleteObject(hRgn);
- data.state = 0;
- if (data.hPen != 0) {
- OS.SelectObject(handle, OS.GetStockObject(OS.NULL_PEN));
- OS.DeleteObject(data.hPen);
- data.hPen = 0;
- }
- if (data.hBrush != 0) {
- OS.SelectObject(handle, OS.GetStockObject(OS.NULL_BRUSH));
- OS.DeleteObject(data.hBrush);
- data.hBrush = 0;
- }
-}
-
-int /*long*/ identity() {
- if ((data.style & SWT.MIRRORED) != 0) {
- int width = 0;
- int technology = OS.GetDeviceCaps(handle, OS.TECHNOLOGY);
- if (technology == OS.DT_RASPRINTER) {
- width = OS.GetDeviceCaps(handle, OS.PHYSICALWIDTH);
- } else {
- Image image = data.image;
- if (image != null) {
- BITMAP bm = new BITMAP();
- OS.GetObject(image.handle, BITMAP.sizeof, bm);
- width = bm.bmWidth;
- } else {
- int /*long*/ hwnd = OS.IsWinCE ? data.hwnd : OS.WindowFromDC(handle);
- if (hwnd != 0) {
- RECT rect = new RECT();
- OS.GetClientRect(hwnd, rect);
- width = rect.right - rect.left;
- } else {
- int /*long*/ hBitmap = OS.GetCurrentObject(handle, OS.OBJ_BITMAP);
- BITMAP bm = new BITMAP();
- OS.GetObject(hBitmap, BITMAP.sizeof, bm);
- width = bm.bmWidth;
- }
- }
- }
- POINT pt = new POINT ();
- if (!OS.IsWinCE) OS.GetWindowOrgEx (handle, pt);
- return Gdip.Matrix_new(-1, 0, 0, 1, width + 2 * pt.x, 0);
- }
- return Gdip.Matrix_new(1, 0, 0, 1, 0, 0);
-}
-
-void init(Drawable drawable, GCData data, int /*long*/ hDC) {
- int foreground = data.foreground;
- if (foreground != -1) {
- data.state &= ~(FOREGROUND | FOREGROUND_TEXT | PEN);
- } else {
- data.foreground = OS.GetTextColor(hDC);
- }
- int background = data.background;
- if (background != -1) {
- data.state &= ~(BACKGROUND | BACKGROUND_TEXT | BRUSH);
- } else {
- data.background = OS.GetBkColor(hDC);
- }
- data.state &= ~(NULL_BRUSH | NULL_PEN);
- Font font = data.font;
- if (font != null) {
- data.state &= ~FONT;
- } else {
- data.font = Font.win32_new(device, OS.GetCurrentObject(hDC, OS.OBJ_FONT));
- }
- int /*long*/ hPalette = data.device.hPalette;
- if (hPalette != 0) {
- OS.SelectPalette(hDC, hPalette, true);
- OS.RealizePalette(hDC);
- }
- Image image = data.image;
- if (image != null) {
- data.hNullBitmap = OS.SelectObject(hDC, image.handle);
- image.memGC = this;
- }
- int layout = data.layout;
- if (layout != -1) {
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
- int flags = OS.GetLayout(hDC);
- if ((flags & OS.LAYOUT_RTL) != (layout & OS.LAYOUT_RTL)) {
- flags &= ~OS.LAYOUT_RTL;
- OS.SetLayout(hDC, flags | layout);
- }
- if ((data.style & SWT.RIGHT_TO_LEFT) != 0) data.style |= SWT.MIRRORED;
- }
- }
- this.drawable = drawable;
- this.data = data;
- handle = hDC;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #equals
- */
-public int hashCode () {
- return (int)/*64*/handle;
-}
-
-/**
- * Returns <code>true</code> if the receiver has a clipping
- * region set into it, and <code>false</code> otherwise.
- * If this method returns false, the receiver will draw on all
- * available space in the destination. If it returns true,
- * it will draw only in the area that is covered by the region
- * that can be accessed with <code>getClipping(region)</code>.
- *
- * @return <code>true</code> if the GC has a clipping region, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean isClipped() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int /*long*/ gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- int /*long*/ rgn = Gdip.Region_new();
- Gdip.Graphics_GetClip(data.gdipGraphics, rgn);
- boolean isInfinite = Gdip.Region_IsInfinite(rgn, gdipGraphics);
- Gdip.Region_delete(rgn);
- return !isInfinite;
- }
- int /*long*/ region = OS.CreateRectRgn(0, 0, 0, 0);
- int result = OS.GetClipRgn(handle, region);
- OS.DeleteObject(region);
- return result > 0;
-}
-
-/**
- * Returns <code>true</code> if the GC has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the GC.
- * When a GC has been disposed, it is an error to
- * invoke any other method using the GC.
- *
- * @return <code>true</code> when the GC is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-float measureSpace(int /*long*/ font, int /*long*/ format) {
- PointF pt = new PointF();
- RectF bounds = new RectF();
- Gdip.Graphics_MeasureString(data.gdipGraphics, new char[]{' '}, 1, font, pt, format, bounds);
- return bounds.Width;
-}
-
-/**
- * Sets the receiver to always use the operating system's advanced graphics
- * subsystem for all graphics operations if the argument is <code>true</code>.
- * If the argument is <code>false</code>, the advanced graphics subsystem is
- * no longer used, advanced graphics state is cleared and the normal graphics
- * subsystem is used from now on.
- * <p>
- * Normally, the advanced graphics subsystem is invoked automatically when
- * any one of the alpha, antialias, patterns, interpolation, paths, clipping
- * or transformation operations in the receiver is requested. When the receiver
- * is switched into advanced mode, the advanced graphics subsystem performs both
- * advanced and normal graphics operations. Because the two subsystems are
- * different, their output may differ. Switching to advanced graphics before
- * any graphics operations are performed ensures that the output is consistent.
- * </p><p>
- * Advanced graphics may not be installed for the operating system. In this
- * case, this operation does nothing. Some operating system have only one
- * graphics subsystem, so switching from normal to advanced graphics does
- * nothing. However, switching from advanced to normal graphics will always
- * clear the advanced graphics state, even for operating systems that have
- * only one graphics subsystem.
- * </p>
- *
- * @param advanced the new advanced graphics state
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAlpha
- * @see #setAntialias
- * @see #setBackgroundPattern
- * @see #setClipping(Path)
- * @see #setForegroundPattern
- * @see #setLineAttributes
- * @see #setInterpolation
- * @see #setTextAntialias
- * @see #setTransform
- * @see #getAdvanced
- *
- * @since 3.1
- */
-public void setAdvanced(boolean advanced) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (advanced && data.gdipGraphics != 0) return;
- if (advanced) {
- try {
- initGdip();
- } catch (SWTException e) {}
- } else {
- disposeGdip();
- data.alpha = 0xFF;
- data.backgroundPattern = data.foregroundPattern = null;
- data.state = 0;
- setClipping(0);
- if ((data.style & SWT.MIRRORED) != 0) {
- OS.SetLayout(handle, OS.GetLayout(handle) | OS.LAYOUT_RTL);
- }
- }
-}
-
-/**
- * Sets the receiver's anti-aliasing value to the parameter,
- * which must be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code>
- * or <code>SWT.ON</code>. Note that this controls anti-aliasing for all
- * <em>non-text drawing</em> operations.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param antialias the anti-aliasing setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.OFF</code> or <code>SWT.ON</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- * @see #setTextAntialias
- *
- * @since 3.1
- */
-public void setAntialias(int antialias) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.gdipGraphics == 0 && antialias == SWT.DEFAULT) return;
- int mode = 0;
- switch (antialias) {
- case SWT.DEFAULT:
- mode = Gdip.SmoothingModeDefault;
- break;
- case SWT.OFF:
- mode = Gdip.SmoothingModeNone;
- break;
- case SWT.ON:
- mode = Gdip.SmoothingModeAntiAlias;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- initGdip();
- Gdip.Graphics_SetSmoothingMode(data.gdipGraphics, mode);
-}
-
-/**
- * Sets the receiver's alpha value which must be
- * between 0 (transparent) and 255 (opaque).
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param alpha the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setAlpha(int alpha) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.gdipGraphics == 0 && (alpha & 0xFF) == 0xFF) return;
- initGdip();
- data.alpha = alpha & 0xFF;
- data.state &= ~(BACKGROUND | FOREGROUND);
-}
-
-/**
- * Sets the background color. The background color is used
- * for fill operations and as the background color when text
- * is drawn.
- *
- * @param color the new background color for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setBackground (Color color) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.backgroundPattern == null && data.background == color.handle) return;
- data.backgroundPattern = null;
- data.background = color.handle;
- data.state &= ~(BACKGROUND | BACKGROUND_TEXT);
-}
-
-/**
- * Sets the background pattern. The default value is <code>null</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param pattern the new background pattern
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Pattern
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setBackgroundPattern (Pattern pattern) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.gdipGraphics == 0 && pattern == null) return;
- initGdip();
- if (data.backgroundPattern == pattern) return;
- data.backgroundPattern = pattern;
- data.state &= ~BACKGROUND;
-}
-
-void setClipping(int /*long*/ clipRgn) {
- int /*long*/ hRgn = clipRgn;
- int /*long*/ gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- if (hRgn != 0) {
- int /*long*/ region = Gdip.Region_new(hRgn);
- Gdip.Graphics_SetClip(gdipGraphics, region, Gdip.CombineModeReplace);
- Gdip.Region_delete(region);
- } else {
- Gdip.Graphics_ResetClip(gdipGraphics);
- }
- } else {
- POINT pt = null;
- if (hRgn != 0 && !OS.IsWinCE) {
- pt = new POINT();
- OS.GetWindowOrgEx(handle, pt);
- OS.OffsetRgn(hRgn, -pt.x, -pt.y);
- }
- OS.SelectClipRgn(handle, hRgn);
- if (hRgn != 0 && !OS.IsWinCE) {
- OS.OffsetRgn(hRgn, pt.x, pt.y);
- }
- }
- if (hRgn != 0 && hRgn != clipRgn) {
- OS.DeleteObject(hRgn);
- }
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the rectangular area specified
- * by the arguments.
- *
- * @param x the x coordinate of the clipping rectangle
- * @param y the y coordinate of the clipping rectangle
- * @param width the width of the clipping rectangle
- * @param height the height of the clipping rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int /*long*/ hRgn = OS.CreateRectRgn(x, y, x + width, y + height);
- setClipping(hRgn);
- OS.DeleteObject(hRgn);
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the path specified
- * by the argument.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the clipping path.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the path has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setClipping (Path path) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path != null && path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- setClipping(0);
- if (path != null) {
- initGdip();
- int mode = OS.GetPolyFillMode(handle) == OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate;
- Gdip.GraphicsPath_SetFillMode(path.handle, mode);
- Gdip.Graphics_SetClipPath(data.gdipGraphics, path.handle);
- }
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the rectangular area specified
- * by the argument. Specifying <code>null</code> for the
- * rectangle reverts the receiver's clipping area to its
- * original value.
- *
- * @param rect the clipping rectangle or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping (Rectangle rect) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) {
- setClipping(0);
- } else {
- setClipping(rect.x, rect.y, rect.width, rect.height);
- }
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the region specified
- * by the argument. Specifying <code>null</code> for the
- * region reverts the receiver's clipping area to its
- * original value.
- *
- * @param region the clipping region or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping (Region region) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region != null && region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- setClipping(region != null ? region.handle : 0);
-}
-
-/**
- * Sets the receiver's fill rule to the parameter, which must be one of
- * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>.
- *
- * @param rule the new fill rule
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of <code>SWT.FILL_EVEN_ODD</code>
- * or <code>SWT.FILL_WINDING</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setFillRule(int rule) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (OS.IsWinCE) return;
- int mode = OS.ALTERNATE;
- switch (rule) {
- case SWT.FILL_WINDING: mode = OS.WINDING; break;
- case SWT.FILL_EVEN_ODD: mode = OS.ALTERNATE; break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- OS.SetPolyFillMode(handle, mode);
-}
-
-/**
- * Sets the font which will be used by the receiver
- * to draw and measure text to the argument. If the
- * argument is null, then a default font appropriate
- * for the platform will be used instead.
- *
- * @param font the new font for the receiver, or null to indicate a default font
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setFont (Font font) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.font = font != null ? font : data.device.systemFont;
- data.state &= ~FONT;
-}
-
-/**
- * Sets the foreground color. The foreground color is used
- * for drawing operations including when text is drawn.
- *
- * @param color the new foreground color for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setForeground (Color color) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.foregroundPattern == null && color.handle == data.foreground) return;
- data.foregroundPattern = null;
- data.foreground = color.handle;
- data.state &= ~(FOREGROUND | FOREGROUND_TEXT);
-}
-
-/**
- * Sets the foreground pattern. The default value is <code>null</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param pattern the new foreground pattern
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Pattern
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setForegroundPattern (Pattern pattern) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.gdipGraphics == 0 && pattern == null) return;
- initGdip();
- if (data.foregroundPattern == pattern) return;
- data.foregroundPattern = pattern;
- data.state &= ~FOREGROUND;
-}
-
-/**
- * Sets the receiver's interpolation setting to the parameter, which
- * must be one of <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>,
- * <code>SWT.LOW</code> or <code>SWT.HIGH</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param interpolation the new interpolation setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.NONE</code>, <code>SWT.LOW</code> or <code>SWT.HIGH</code>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setInterpolation(int interpolation) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.gdipGraphics == 0 && interpolation == SWT.DEFAULT) return;
- int mode = 0;
- switch (interpolation) {
- case SWT.DEFAULT: mode = Gdip.InterpolationModeDefault; break;
- case SWT.NONE: mode = Gdip.InterpolationModeNearestNeighbor; break;
- case SWT.LOW: mode = Gdip.InterpolationModeLowQuality; break;
- case SWT.HIGH: mode = Gdip.InterpolationModeHighQuality; break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- initGdip();
- Gdip.Graphics_SetInterpolationMode(data.gdipGraphics, mode);
-}
-
-/**
- * Sets the receiver's line attributes.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param attributes the line attributes
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the attributes is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if any of the line attributes is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see LineAttributes
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.3
- */
-public void setLineAttributes(LineAttributes attributes) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (attributes == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int mask = 0;
- float lineWidth = attributes.width;
- if (lineWidth != data.lineWidth) {
- mask |= LINE_WIDTH | DRAW_OFFSET;
- }
- int lineStyle = attributes.style;
- if (lineStyle != data.lineStyle) {
- mask |= LINE_STYLE;
- switch (lineStyle) {
- case SWT.LINE_SOLID:
- case SWT.LINE_DASH:
- case SWT.LINE_DOT:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- break;
- case SWT.LINE_CUSTOM:
- if (attributes.dash == null) lineStyle = SWT.LINE_SOLID;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- int join = attributes.join;
- if (join != data.lineJoin) {
- mask |= LINE_JOIN;
- switch (join) {
- case SWT.CAP_ROUND:
- case SWT.CAP_FLAT:
- case SWT.CAP_SQUARE:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- int cap = attributes.cap;
- if (cap != data.lineCap) {
- mask |= LINE_CAP;
- switch (cap) {
- case SWT.JOIN_MITER:
- case SWT.JOIN_ROUND:
- case SWT.JOIN_BEVEL:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- float[] dashes = attributes.dash;
- float[] lineDashes = data.lineDashes;
- if (dashes != null && dashes.length > 0) {
- boolean changed = lineDashes == null || lineDashes.length != dashes.length;
- for (int i = 0; i < dashes.length; i++) {
- float dash = dashes[i];
- if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (!changed && lineDashes[i] != dash) changed = true;
- }
- if (changed) {
- float[] newDashes = new float[dashes.length];
- System.arraycopy(dashes, 0, newDashes, 0, dashes.length);
- dashes = newDashes;
- mask |= LINE_STYLE;
- } else {
- dashes = lineDashes;
- }
- } else {
- if (lineDashes != null && lineDashes.length > 0) {
- mask |= LINE_STYLE;
- } else {
- dashes = lineDashes;
- }
- }
- float dashOffset = attributes.dashOffset;
- if (dashOffset != data.lineDashesOffset) {
- mask |= LINE_STYLE;
- }
- float miterLimit = attributes.miterLimit;
- if (miterLimit != data.lineMiterLimit) {
- mask |= LINE_MITERLIMIT;
- }
- initGdip();
- if (mask == 0) return;
- data.lineWidth = lineWidth;
- data.lineStyle = lineStyle;
- data.lineCap = cap;
- data.lineJoin = join;
- data.lineDashes = dashes;
- data.lineDashesOffset = dashOffset;
- data.lineMiterLimit = miterLimit;
- data.state &= ~mask;
-}
-
-/**
- * Sets the receiver's line cap style to the argument, which must be one
- * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>,
- * or <code>SWT.CAP_SQUARE</code>.
- *
- * @param cap the cap style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineCap(int cap) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineCap == cap) return;
- switch (cap) {
- case SWT.CAP_ROUND:
- case SWT.CAP_FLAT:
- case SWT.CAP_SQUARE:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineCap = cap;
- data.state &= ~LINE_CAP;
-}
-
-/**
- * Sets the receiver's line dash style to the argument. The default
- * value is <code>null</code>. If the argument is not <code>null</code>,
- * the receiver's line style is set to <code>SWT.LINE_CUSTOM</code>, otherwise
- * it is set to <code>SWT.LINE_SOLID</code>.
- *
- * @param dashes the dash style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if any of the values in the array is less than or equal 0</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineDash(int[] dashes) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float[] lineDashes = data.lineDashes;
- if (dashes != null && dashes.length > 0) {
- boolean changed = data.lineStyle != SWT.LINE_CUSTOM || lineDashes == null || lineDashes.length != dashes.length;
- for (int i = 0; i < dashes.length; i++) {
- int dash = dashes[i];
- if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (!changed && lineDashes[i] != dash) changed = true;
- }
- if (!changed) return;
- data.lineDashes = new float[dashes.length];
- for (int i = 0; i < dashes.length; i++) {
- data.lineDashes[i] = dashes[i];
- }
- data.lineStyle = SWT.LINE_CUSTOM;
- } else {
- if (data.lineStyle == SWT.LINE_SOLID && (lineDashes == null || lineDashes.length == 0)) return;
- data.lineDashes = null;
- data.lineStyle = SWT.LINE_SOLID;
- }
- data.state &= ~LINE_STYLE;
-}
-
-/**
- * Sets the receiver's line join style to the argument, which must be one
- * of the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>,
- * or <code>SWT.JOIN_BEVEL</code>.
- *
- * @param join the join style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineJoin(int join) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineJoin == join) return;
- switch (join) {
- case SWT.JOIN_MITER:
- case SWT.JOIN_ROUND:
- case SWT.JOIN_BEVEL:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineJoin = join;
- data.state &= ~LINE_JOIN;
-}
-
-/**
- * Sets the receiver's line style to the argument, which must be one
- * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
- * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or
- * <code>SWT.LINE_DASHDOTDOT</code>.
- *
- * @param lineStyle the style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setLineStyle(int lineStyle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineStyle == lineStyle) return;
- switch (lineStyle) {
- case SWT.LINE_SOLID:
- case SWT.LINE_DASH:
- case SWT.LINE_DOT:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- break;
- case SWT.LINE_CUSTOM:
- if (data.lineDashes == null) lineStyle = SWT.LINE_SOLID;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineStyle = lineStyle;
- data.state &= ~LINE_STYLE;
-}
-
-/**
- * Sets the width that will be used when drawing lines
- * for all of the figure drawing operations (that is,
- * <code>drawLine</code>, <code>drawRectangle</code>,
- * <code>drawPolyline</code>, and so forth.
- * <p>
- * Note that line width of zero is used as a hint to
- * indicate that the fastest possible line drawing
- * algorithms should be used. This means that the
- * output may be different from line width one.
- * </p>
- *
- * @param lineWidth the width of a line
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setLineWidth(int lineWidth) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineWidth == lineWidth) return;
- data.lineWidth = lineWidth;
- data.state &= ~(LINE_WIDTH | DRAW_OFFSET);
-}
-
-/**
- * If the argument is <code>true</code>, puts the receiver
- * in a drawing mode where the resulting color in the destination
- * is the <em>exclusive or</em> of the color values in the source
- * and the destination, and if the argument is <code>false</code>,
- * puts the receiver in a drawing mode where the destination color
- * is replaced with the source color value.
- * <p>
- * Note that this mode in fundamentally unsupportable on certain
- * platforms, notably Carbon (Mac OS X). Clients that want their
- * code to run on all platforms need to avoid this method.
- * </p>
- *
- * @param xor if <code>true</code>, then <em>xor</em> mode is used, otherwise <em>source copy</em> mode is used
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @deprecated this functionality is not supported on some platforms
- */
-public void setXORMode(boolean xor) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.SetROP2(handle, xor ? OS.R2_XORPEN : OS.R2_COPYPEN);
-}
-
-/**
- * Sets the receiver's text anti-aliasing value to the parameter,
- * which must be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code>
- * or <code>SWT.ON</code>. Note that this controls anti-aliasing only
- * for all <em>text drawing</em> operations.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param antialias the anti-aliasing setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.OFF</code> or <code>SWT.ON</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- * @see #setAntialias
- *
- * @since 3.1
- */
-public void setTextAntialias(int antialias) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.gdipGraphics == 0 && antialias == SWT.DEFAULT) return;
- int textMode = 0;
- switch (antialias) {
- case SWT.DEFAULT:
- textMode = Gdip.TextRenderingHintSystemDefault;
- break;
- case SWT.OFF:
- textMode = Gdip.TextRenderingHintSingleBitPerPixelGridFit;
- break;
- case SWT.ON:
- int[] type = new int[1];
- OS.SystemParametersInfo(OS.SPI_GETFONTSMOOTHINGTYPE, 0, type, 0);
- if (type[0] == OS.FE_FONTSMOOTHINGCLEARTYPE) {
- textMode = Gdip.TextRenderingHintClearTypeGridFit;
- } else {
- textMode = Gdip.TextRenderingHintAntiAliasGridFit;
- }
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- initGdip();
- Gdip.Graphics_SetTextRenderingHint(data.gdipGraphics, textMode);
-}
-
-/**
- * Sets the transform that is currently being used by the receiver. If
- * the argument is <code>null</code>, the current transform is set to
- * the identity transform.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param transform the transform to set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Transform
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setTransform(Transform transform) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transform != null && transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.gdipGraphics == 0 && transform == null) return;
- initGdip();
- int /*long*/ identity = identity();
- if (transform != null) {
- Gdip.Matrix_Multiply(identity, transform.handle, Gdip.MatrixOrderPrepend);
- }
- Gdip.Graphics_SetTransform(data.gdipGraphics, identity);
- Gdip.Matrix_delete(identity);
- data.state &= ~DRAW_OFFSET;
-}
-
-/**
- * Returns the extent of the given string. No tab
- * expansion or carriage return processing will be performed.
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point stringExtent(String string) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- checkGC(FONT);
- int length = string.length();
- int /*long*/ gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- RectF bounds = new RectF();
- char[] buffer;
- if (length != 0) {
- buffer = new char [length];
- string.getChars(0, length, buffer, 0);
- } else {
- buffer = new char[]{' '};
- }
- int nGlyphs = (length * 3 / 2) + 16;
- GCP_RESULTS result = new GCP_RESULTS();
- result.lStructSize = GCP_RESULTS.sizeof;
- result.nGlyphs = nGlyphs;
- int /*long*/ hHeap = OS.GetProcessHeap();
- int /*long*/ lpDx = result.lpDx = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, nGlyphs * 4);
- int /*long*/ lpGlyphs = result.lpGlyphs = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, nGlyphs * 2);
- int dwFlags = OS.GCP_GLYPHSHAPE | OS.GCP_REORDER | OS.GCP_LIGATE;
- int /*long*/ hdc = Gdip.Graphics_GetHDC(gdipGraphics);
- int /*long*/ hFont = data.hGDIFont;
- if (hFont == 0 && data.font != null) hFont = data.font.handle;
- int /*long*/ oldFont = 0;
- if (hFont != 0) oldFont = OS.SelectObject(hdc, hFont);
- if ((data.style & SWT.MIRRORED) != 0) OS.SetLayout(hdc, OS.GetLayout(hdc) | OS.LAYOUT_RTL);
- OS.GetCharacterPlacementW(hdc, buffer, length, 0, result, dwFlags);
- if ((data.style & SWT.MIRRORED) != 0) OS.SetLayout(hdc, OS.GetLayout(hdc) & ~OS.LAYOUT_RTL);
- if (hFont != 0) OS.SelectObject(hdc, oldFont);
- Gdip.Graphics_ReleaseHDC(gdipGraphics, hdc);
- int drawX = 0;
- int[] dx = new int[result.nGlyphs];
- OS.MoveMemory(dx, lpDx, result.nGlyphs * 4);
- float[] points = new float[dx.length * 2];
- for (int i = 0, j = 0; i < dx.length; i++, j += 2) {
- points[j] = drawX;
- drawX += dx[i];
- }
- Gdip.Graphics_MeasureDriverString(gdipGraphics, lpGlyphs, result.nGlyphs, data.gdipFont, points, 0, 0, bounds);
- OS.HeapFree(hHeap, 0, lpGlyphs);
- OS.HeapFree(hHeap, 0, lpDx);
- return new Point(length == 0 ? 0 : Math.round(bounds.Width), Math.round(bounds.Height));
- }
- SIZE size = new SIZE();
- if (length == 0) {
-// OS.GetTextExtentPoint32(handle, SPACE, SPACE.length(), size);
- OS.GetTextExtentPoint32W(handle, new char[]{' '}, 1, size);
- return new Point(0, size.cy);
- } else {
-// TCHAR buffer = new TCHAR (getCodePage(), string, false);
- char[] buffer = new char [length];
- string.getChars(0, length, buffer, 0);
- OS.GetTextExtentPoint32W(handle, buffer, length, size);
- return new Point(size.cx, size.cy);
- }
-}
-
-/**
- * Returns the extent of the given string. Tab expansion and
- * carriage return processing are performed.
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point textExtent(String string) {
- return textExtent(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
-}
-
-/**
- * Returns the extent of the given string. Tab expansion, line
- * delimiter and mnemonic processing are performed according to
- * the specified flags, which can be a combination of:
- * <dl>
- * <dt><b>DRAW_DELIMITER</b></dt>
- * <dd>draw multiple lines</dd>
- * <dt><b>DRAW_TAB</b></dt>
- * <dd>expand tabs</dd>
- * <dt><b>DRAW_MNEMONIC</b></dt>
- * <dd>underline the mnemonic character</dd>
- * <dt><b>DRAW_TRANSPARENT</b></dt>
- * <dd>transparent background</dd>
- * </dl>
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @param flags the flags specifying how to process the text
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point textExtent(String string, int flags) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- checkGC(FONT);
- if (data.gdipGraphics != 0) {
- PointF pt = new PointF();
- RectF bounds = new RectF();
- char[] buffer;
- int length = string.length();
- if (length != 0) {
- buffer = new char [length];
- string.getChars(0, length, buffer, 0);
- } else {
- buffer = new char[]{' '};
- }
- int /*long*/ format = Gdip.StringFormat_Clone(Gdip.StringFormat_GenericTypographic());
- int formatFlags = Gdip.StringFormat_GetFormatFlags(format) | Gdip.StringFormatFlagsMeasureTrailingSpaces;
- if ((data.style & SWT.MIRRORED) != 0) formatFlags |= Gdip.StringFormatFlagsDirectionRightToLeft;
- Gdip.StringFormat_SetFormatFlags(format, formatFlags);
- float[] tabs = (flags & SWT.DRAW_TAB) != 0 ? new float[]{measureSpace(data.gdipFont, format) * 8} : new float[1];
- Gdip.StringFormat_SetTabStops(format, 0, tabs.length, tabs);
- Gdip.StringFormat_SetHotkeyPrefix(format, (flags & SWT.DRAW_MNEMONIC) != 0 ? Gdip.HotkeyPrefixShow : Gdip.HotkeyPrefixNone);
- Gdip.Graphics_MeasureString(data.gdipGraphics, buffer, buffer.length, data.gdipFont, pt, format, bounds);
- Gdip.StringFormat_delete(format);
- return new Point(length == 0 ? 0 : Math.round(bounds.Width), Math.round(bounds.Height));
- }
- if (string.length () == 0) {
- SIZE size = new SIZE();
-// OS.GetTextExtentPoint32(handle, SPACE, SPACE.length(), size);
- OS.GetTextExtentPoint32W(handle, new char [] {' '}, 1, size);
- return new Point(0, size.cy);
- }
- RECT rect = new RECT();
- TCHAR buffer = new TCHAR(getCodePage(), string, false);
- int uFormat = OS.DT_LEFT | OS.DT_CALCRECT;
- if ((flags & SWT.DRAW_DELIMITER) == 0) uFormat |= OS.DT_SINGLELINE;
- if ((flags & SWT.DRAW_TAB) != 0) uFormat |= OS.DT_EXPANDTABS;
- if ((flags & SWT.DRAW_MNEMONIC) == 0) uFormat |= OS.DT_NOPREFIX;
- OS.DrawText(handle, buffer, buffer.length(), rect, uFormat);
- return new Point(rect.right, rect.bottom);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "GC {*DISPOSED*}";
- return "GC {" + handle + "}";
-}
-
-/**
- * Invokes platform specific functionality to allocate a new graphics context.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>GC</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param drawable the Drawable for the receiver.
- * @param data the data for the receiver.
- *
- * @return a new <code>GC</code>
- */
-public static GC win32_new(Drawable drawable, GCData data) {
- GC gc = new GC();
- int /*long*/ hDC = drawable.internal_new_GC(data);
- gc.device = data.device;
- gc.init(drawable, data, hDC);
- return gc;
-}
-
-/**
- * Invokes platform specific functionality to wrap a graphics context.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>GC</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the Windows HDC.
- * @param data the data for the receiver.
- *
- * @return a new <code>GC</code>
- */
-public static GC win32_new(int /*long*/ hDC, GCData data) {
- GC gc = new GC();
- gc.device = data.device;
- data.style |= SWT.LEFT_TO_RIGHT;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- int flags = OS.GetLayout (hDC);
- if ((flags & OS.LAYOUT_RTL) != 0) {
- data.style |= SWT.RIGHT_TO_LEFT | SWT.MIRRORED;
- }
- }
- gc.init(null, data, hDC);
- return gc;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GCData.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GCData.java
deleted file mode 100755
index 8ccb803401..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GCData.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.win32.*;
-
-/**
- * Instances of this class are descriptions of GCs in terms
- * of unallocated platform-specific data fields.
- * <p>
- * <b>IMPORTANT:</b> This class is <em>not</em> part of the public
- * API for SWT. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms, and should never be called from application code.
- * </p>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noinstantiate This class is not intended to be instantiated by clients.
- */
-
-public final class GCData {
- public Device device;
- public int style, state = -1;
- public int foreground = -1;
- public int background = -1;
- public Font font;
- public Pattern foregroundPattern;
- public Pattern backgroundPattern;
- public int lineStyle = SWT.LINE_SOLID;
- public float lineWidth;
- public int lineCap = SWT.CAP_FLAT;
- public int lineJoin = SWT.JOIN_MITER;
- public float lineDashesOffset;
- public float[] lineDashes;
- public float lineMiterLimit = 10;
- public int alpha = 0xFF;
-
- public Image image;
- public int /*long*/ hPen, hOldPen;
- public int /*long*/ hBrush, hOldBrush;
- public int /*long*/ hNullBitmap;
- public int /*long*/ hwnd;
- public PAINTSTRUCT ps;
- public int layout = -1;
- public int /*long*/ gdipGraphics;
- public int /*long*/ gdipPen;
- public int /*long*/ gdipBrush;
- public int /*long*/ gdipFgBrush;
- public int /*long*/ gdipBgBrush;
- public int /*long*/ gdipFont;
- public int /*long*/ hGDIFont;
- public float gdipXOffset, gdipYOffset;
- public int uiState = 0;
- public boolean focusDrawn;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
deleted file mode 100755
index 012f72e537..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
+++ /dev/null
@@ -1,2129 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.gdip.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-
-import java.io.*;
-
-/**
- * Instances of this class are graphics which have been prepared
- * for display on a specific device. That is, they are ready
- * to paint using methods such as <code>GC.drawImage()</code>
- * and display on widgets with, for example, <code>Button.setImage()</code>.
- * <p>
- * If loaded from a file format that supports it, an
- * <code>Image</code> may have transparency, meaning that certain
- * pixels are specified as being transparent when drawn. Examples
- * of file formats that support transparency are GIF and PNG.
- * </p><p>
- * There are two primary ways to use <code>Images</code>.
- * The first is to load a graphic file from disk and create an
- * <code>Image</code> from it. This is done using an <code>Image</code>
- * constructor, for example:
- * <pre>
- * Image i = new Image(device, "C:\\graphic.bmp");
- * </pre>
- * A graphic file may contain a color table specifying which
- * colors the image was intended to possess. In the above example,
- * these colors will be mapped to the closest available color in
- * SWT. It is possible to get more control over the mapping of
- * colors as the image is being created, using code of the form:
- * <pre>
- * ImageData data = new ImageData("C:\\graphic.bmp");
- * RGB[] rgbs = data.getRGBs();
- * // At this point, rgbs contains specifications of all
- * // the colors contained within this image. You may
- * // allocate as many of these colors as you wish by
- * // using the Color constructor Color(RGB), then
- * // create the image:
- * Image i = new Image(device, data);
- * </pre>
- * <p>
- * Applications which require even greater control over the image
- * loading process should use the support provided in class
- * <code>ImageLoader</code>.
- * </p><p>
- * Application code must explicitly invoke the <code>Image.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see Color
- * @see ImageData
- * @see ImageLoader
- * @see <a href="http://www.eclipse.org/swt/snippets/#image">Image snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, ImageAnalyzer</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class Image extends Resource implements Drawable {
-
- /**
- * specifies whether the receiver is a bitmap or an icon
- * (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int type;
-
- /**
- * the handle to the OS image resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
-
- /**
- * specifies the transparent pixel
- */
- int transparentPixel = -1, transparentColor = -1;
-
- /**
- * the GC which is drawing on the image
- */
- GC memGC;
-
- /**
- * the alpha data for the image
- */
- byte[] alphaData;
-
- /**
- * the global alpha value to be used for every pixel
- */
- int alpha = -1;
-
- /**
- * the image data used to create this image if it is a
- * icon. Used only in WinCE
- */
- ImageData data;
-
- /**
- * width of the image
- */
- int width = -1;
-
- /**
- * height of the image
- */
- int height = -1;
-
- /**
- * specifies the default scanline padding
- */
- static final int DEFAULT_SCANLINE_PAD = 4;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Image (Device device) {
- super(device);
-}
-
-/**
- * Constructs an empty instance of this class with the
- * specified width and height. The result may be drawn upon
- * by creating a GC and using any of its drawing operations,
- * as shown in the following example:
- * <pre>
- * Image i = new Image(device, width, height);
- * GC gc = new GC(i);
- * gc.drawRectangle(0, 0, 50, 50);
- * gc.dispose();
- * </pre>
- * <p>
- * Note: Some platforms may have a limitation on the size
- * of image that can be created (size depends on width, height,
- * and depth). For example, Windows 95, 98, and ME do not allow
- * images larger than 16M.
- * </p>
- *
- * @param device the device on which to create the image
- * @param width the width of the new image
- * @param height the height of the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - if either the width or height is negative or zero</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, int width, int height) {
- super(device);
- init(width, height);
- init();
-}
-
-/**
- * Constructs a new instance of this class based on the
- * provided image, with an appearance that varies depending
- * on the value of the flag. The possible flag values are:
- * <dl>
- * <dt><b>{@link SWT#IMAGE_COPY}</b></dt>
- * <dd>the result is an identical copy of srcImage</dd>
- * <dt><b>{@link SWT#IMAGE_DISABLE}</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>disabled</em> look</dd>
- * <dt><b>{@link SWT#IMAGE_GRAY}</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>gray scale</em> look</dd>
- * </dl>
- *
- * @param device the device on which to create the image
- * @param srcImage the image to use as the source
- * @param flag the style, either <code>IMAGE_COPY</code>, <code>IMAGE_DISABLE</code> or <code>IMAGE_GRAY</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if srcImage is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the flag is not one of <code>IMAGE_COPY</code>, <code>IMAGE_DISABLE</code> or <code>IMAGE_GRAY</code></li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon, or is otherwise in an invalid state</li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the image is not supported</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, Image srcImage, int flag) {
- super(device);
- device = this.device;
- if (srcImage == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (srcImage.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Rectangle rect = srcImage.getBounds();
- this.type = srcImage.type;
- switch (flag) {
- case SWT.IMAGE_COPY: {
- switch (type) {
- case SWT.BITMAP:
- /* Get the HDC for the device */
- int /*long*/ hDC = device.internal_new_GC(null);
-
- /* Copy the bitmap */
- int /*long*/ hdcSource = OS.CreateCompatibleDC(hDC);
- int /*long*/ hdcDest = OS.CreateCompatibleDC(hDC);
- int /*long*/ hOldSrc = OS.SelectObject(hdcSource, srcImage.handle);
- BITMAP bm = new BITMAP();
- OS.GetObject(srcImage.handle, BITMAP.sizeof, bm);
- handle = OS.CreateCompatibleBitmap(hdcSource, rect.width, bm.bmBits != 0 ? -rect.height : rect.height);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ hOldDest = OS.SelectObject(hdcDest, handle);
- OS.BitBlt(hdcDest, 0, 0, rect.width, rect.height, hdcSource, 0, 0, OS.SRCCOPY);
- OS.SelectObject(hdcSource, hOldSrc);
- OS.SelectObject(hdcDest, hOldDest);
- OS.DeleteDC(hdcSource);
- OS.DeleteDC(hdcDest);
-
- /* Release the HDC for the device */
- device.internal_dispose_GC(hDC, null);
-
- transparentPixel = srcImage.transparentPixel;
- alpha = srcImage.alpha;
- if (srcImage.alphaData != null) {
- alphaData = new byte[srcImage.alphaData.length];
- System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length);
- }
- break;
- case SWT.ICON:
- if (OS.IsWinCE) {
- init(srcImage.data);
- } else {
- handle = OS.CopyImage(srcImage.handle, OS.IMAGE_ICON, rect.width, rect.height, 0);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- }
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- break;
- }
- case SWT.IMAGE_DISABLE: {
- ImageData data = srcImage.getImageData();
- PaletteData palette = data.palette;
- RGB[] rgbs = new RGB[3];
- rgbs[0] = device.getSystemColor(SWT.COLOR_BLACK).getRGB();
- rgbs[1] = device.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW).getRGB();
- rgbs[2] = device.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND).getRGB();
- ImageData newData = new ImageData(rect.width, rect.height, 8, new PaletteData(rgbs));
- newData.alpha = data.alpha;
- newData.alphaData = data.alphaData;
- newData.maskData = data.maskData;
- newData.maskPad = data.maskPad;
- if (data.transparentPixel != -1) newData.transparentPixel = 0;
-
- /* Convert the pixels. */
- int[] scanline = new int[rect.width];
- int[] maskScanline = null;
- ImageData mask = null;
- if (data.maskData != null) mask = data.getTransparencyMask();
- if (mask != null) maskScanline = new int[rect.width];
- int redMask = palette.redMask;
- int greenMask = palette.greenMask;
- int blueMask = palette.blueMask;
- int redShift = palette.redShift;
- int greenShift = palette.greenShift;
- int blueShift = palette.blueShift;
- for (int y=0; y<rect.height; y++) {
- int offset = y * newData.bytesPerLine;
- data.getPixels(0, y, rect.width, scanline, 0);
- if (mask != null) mask.getPixels(0, y, rect.width, maskScanline, 0);
- for (int x=0; x<rect.width; x++) {
- int pixel = scanline[x];
- if (!((data.transparentPixel != -1 && pixel == data.transparentPixel) || (mask != null && maskScanline[x] == 0))) {
- int red, green, blue;
- if (palette.isDirect) {
- red = pixel & redMask;
- red = (redShift < 0) ? red >>> -redShift : red << redShift;
- green = pixel & greenMask;
- green = (greenShift < 0) ? green >>> -greenShift : green << greenShift;
- blue = pixel & blueMask;
- blue = (blueShift < 0) ? blue >>> -blueShift : blue << blueShift;
- } else {
- red = palette.colors[pixel].red;
- green = palette.colors[pixel].green;
- blue = palette.colors[pixel].blue;
- }
- int intensity = red * red + green * green + blue * blue;
- if (intensity < 98304) {
- newData.data[offset] = (byte)1;
- } else {
- newData.data[offset] = (byte)2;
- }
- }
- offset++;
- }
- }
- init (newData);
- break;
- }
- case SWT.IMAGE_GRAY: {
- ImageData data = srcImage.getImageData();
- PaletteData palette = data.palette;
- ImageData newData = data;
- if (!palette.isDirect) {
- /* Convert the palette entries to gray. */
- RGB [] rgbs = palette.getRGBs();
- for (int i=0; i<rgbs.length; i++) {
- if (data.transparentPixel != i) {
- RGB color = rgbs [i];
- int red = color.red;
- int green = color.green;
- int blue = color.blue;
- int intensity = (red+red+green+green+green+green+green+blue) >> 3;
- color.red = color.green = color.blue = intensity;
- }
- }
- newData.palette = new PaletteData(rgbs);
- } else {
- /* Create a 8 bit depth image data with a gray palette. */
- RGB[] rgbs = new RGB[256];
- for (int i=0; i<rgbs.length; i++) {
- rgbs[i] = new RGB(i, i, i);
- }
- newData = new ImageData(rect.width, rect.height, 8, new PaletteData(rgbs));
- newData.alpha = data.alpha;
- newData.alphaData = data.alphaData;
- newData.maskData = data.maskData;
- newData.maskPad = data.maskPad;
- if (data.transparentPixel != -1) newData.transparentPixel = 254;
-
- /* Convert the pixels. */
- int[] scanline = new int[rect.width];
- int redMask = palette.redMask;
- int greenMask = palette.greenMask;
- int blueMask = palette.blueMask;
- int redShift = palette.redShift;
- int greenShift = palette.greenShift;
- int blueShift = palette.blueShift;
- for (int y=0; y<rect.height; y++) {
- int offset = y * newData.bytesPerLine;
- data.getPixels(0, y, rect.width, scanline, 0);
- for (int x=0; x<rect.width; x++) {
- int pixel = scanline[x];
- if (pixel != data.transparentPixel) {
- int red = pixel & redMask;
- red = (redShift < 0) ? red >>> -redShift : red << redShift;
- int green = pixel & greenMask;
- green = (greenShift < 0) ? green >>> -greenShift : green << greenShift;
- int blue = pixel & blueMask;
- blue = (blueShift < 0) ? blue >>> -blueShift : blue << blueShift;
- int intensity = (red+red+green+green+green+green+green+blue) >> 3;
- if (newData.transparentPixel == intensity) intensity = 255;
- newData.data[offset] = (byte)intensity;
- } else {
- newData.data[offset] = (byte)254;
- }
- offset++;
- }
- }
- }
- init (newData);
- break;
- }
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- init();
-}
-
-/**
- * Constructs an empty instance of this class with the
- * width and height of the specified rectangle. The result
- * may be drawn upon by creating a GC and using any of its
- * drawing operations, as shown in the following example:
- * <pre>
- * Image i = new Image(device, boundsRectangle);
- * GC gc = new GC(i);
- * gc.drawRectangle(0, 0, 50, 50);
- * gc.dispose();
- * </pre>
- * <p>
- * Note: Some platforms may have a limitation on the size
- * of image that can be created (size depends on width, height,
- * and depth). For example, Windows 95, 98, and ME do not allow
- * images larger than 16M.
- * </p>
- *
- * @param device the device on which to create the image
- * @param bounds a rectangle specifying the image's width and height (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the bounds rectangle is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, Rectangle bounds) {
- super(device);
- if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(bounds.width, bounds.height);
- init();
-}
-
-/**
- * Constructs an instance of this class from the given
- * <code>ImageData</code>.
- *
- * @param device the device on which to create the image
- * @param data the image data to create the image from (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the image data is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the ImageData is not supported</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, ImageData data) {
- super(device);
- init(data);
- init();
-}
-
-/**
- * Constructs an instance of this class, whose type is
- * <code>SWT.ICON</code>, from the two given <code>ImageData</code>
- * objects. The two images must be the same size. Pixel transparency
- * in either image will be ignored.
- * <p>
- * The mask image should contain white wherever the icon is to be visible,
- * and black wherever the icon is to be transparent. In addition,
- * the source image should contain black wherever the icon is to be
- * transparent.
- * </p>
- *
- * @param device the device on which to create the icon
- * @param source the color data for the icon
- * @param mask the mask data for the icon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if either the source or mask is null </li>
- * <li>ERROR_INVALID_ARGUMENT - if source and mask are different sizes</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, ImageData source, ImageData mask) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (mask == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (source.width != mask.width || source.height != mask.height) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- mask = ImageData.convertMask(mask);
- init(this.device, this, source, mask);
- init();
-}
-
-/**
- * Constructs an instance of this class by loading its representation
- * from the specified input stream. Throws an error if an error
- * occurs while loading the image, or if the result is an image
- * of an unsupported type. Application code is still responsible
- * for closing the input stream.
- * <p>
- * This constructor is provided for convenience when loading a single
- * image only. If the stream contains multiple images, only the first
- * one will be loaded. To load multiple images, use
- * <code>ImageLoader.load()</code>.
- * </p><p>
- * This constructor may be used to load a resource as follows:
- * </p>
- * <pre>
- * static Image loadImage (Display display, Class clazz, String string) {
- * InputStream stream = clazz.getResourceAsStream (string);
- * if (stream == null) return null;
- * Image image = null;
- * try {
- * image = new Image (display, stream);
- * } catch (SWTException ex) {
- * } finally {
- * try {
- * stream.close ();
- * } catch (IOException ex) {}
- * }
- * return image;
- * }
- * </pre>
- *
- * @param device the device on which to create the image
- * @param stream the input stream to load the image from
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the stream is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from the stream</li>
- * <li>ERROR_INVALID_IMAGE - if the image stream contains invalid data </li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the image stream describes an image with an unsupported depth</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image (Device device, InputStream stream) {
- super(device);
- init(new ImageData(stream));
- init();
-}
-
-/**
- * Constructs an instance of this class by loading its representation
- * from the file with the specified name. Throws an error if an error
- * occurs while loading the image, or if the result is an image
- * of an unsupported type.
- * <p>
- * This constructor is provided for convenience when loading
- * a single image only. If the specified file contains
- * multiple images, only the first one will be used.
- *
- * @param device the device on which to create the image
- * @param filename the name of the file to load the image from
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the file name is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from the file</li>
- * <li>ERROR_INVALID_IMAGE - if the image file contains invalid data </li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the image file describes an image with an unsupported depth</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image (Device device, String filename) {
- super(device);
- if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- initNative(filename);
- if (this.handle == 0) init(new ImageData(filename));
- init();
-}
-
-void initNative(String filename) {
- boolean gdip = true;
- try {
- device.checkGDIP();
- } catch (SWTException e) {
- gdip = false;
- }
- /*
- * Bug in GDI+. For some reason, Bitmap.LockBits() segment faults
- * when loading GIF files in 64-bit Windows. The fix is to not use
- * GDI+ image loading in this case.
- */
- if (gdip && OS.PTR_SIZEOF == 8 && filename.toLowerCase().endsWith(".gif")) gdip = false;
- if (gdip) {
- int length = filename.length();
- char[] chars = new char[length+1];
- filename.getChars(0, length, chars, 0);
- int /*long*/ bitmap = Gdip.Bitmap_new(chars, false);
- if (bitmap != 0) {
- int error = SWT.ERROR_NO_HANDLES;
- int status = Gdip.Image_GetLastStatus(bitmap);
- if (status == 0) {
- if (filename.toLowerCase().endsWith(".ico")) {
- this.type = SWT.ICON;
- int /*long*/[] hicon = new int /*long*/[1];
- status = Gdip.Bitmap_GetHICON(bitmap, hicon);
- this.handle = hicon[0];
- } else {
- this.type = SWT.BITMAP;
- int width = Gdip.Image_GetWidth(bitmap);
- int height = Gdip.Image_GetHeight(bitmap);
- int pixelFormat = Gdip.Image_GetPixelFormat(bitmap);
- switch (pixelFormat) {
- case Gdip.PixelFormat16bppRGB555:
- case Gdip.PixelFormat16bppRGB565:
- this.handle = createDIB(width, height, 16);
- break;
- case Gdip.PixelFormat24bppRGB:
- this.handle = createDIB(width, height, 24);
- break;
- case Gdip.PixelFormat32bppRGB:
- // These will loose either precision or transparency
- case Gdip.PixelFormat16bppGrayScale:
- case Gdip.PixelFormat48bppRGB:
- case Gdip.PixelFormat32bppPARGB:
- case Gdip.PixelFormat64bppARGB:
- case Gdip.PixelFormat64bppPARGB:
- this.handle = createDIB(width, height, 32);
- break;
- }
- if (this.handle != 0) {
- /*
- * This performs better than getting the bits with Bitmap.LockBits(),
- * but it cannot be used when there is transparency.
- */
- int /*long*/ hDC = device.internal_new_GC(null);
- int /*long*/ srcHDC = OS.CreateCompatibleDC(hDC);
- int /*long*/ oldSrcBitmap = OS.SelectObject(srcHDC, this.handle);
- int /*long*/ graphics = Gdip.Graphics_new(srcHDC);
- if (graphics != 0) {
- Rect rect = new Rect();
- rect.Width = width;
- rect.Height = height;
- status = Gdip.Graphics_DrawImage(graphics, bitmap, rect, 0, 0, width, height, Gdip.UnitPixel, 0, 0, 0);
- if (status != 0) {
- error = SWT.ERROR_INVALID_IMAGE;
- OS.DeleteObject(handle);
- this.handle = 0;
- }
- Gdip.Graphics_delete(graphics);
- }
- OS.SelectObject(srcHDC, oldSrcBitmap);
- OS.DeleteDC(srcHDC);
- device.internal_dispose_GC(hDC, null);
- } else {
- int /*long*/ lockedBitmapData = Gdip.BitmapData_new();
- if (lockedBitmapData != 0) {
- status = Gdip.Bitmap_LockBits(bitmap, 0, 0, pixelFormat, lockedBitmapData);
- if (status == 0) {
- BitmapData bitmapData = new BitmapData();
- Gdip.MoveMemory(bitmapData, lockedBitmapData);
- int stride = bitmapData.Stride;
- int /*long*/ pixels = bitmapData.Scan0;
- int depth = 0, scanlinePad = 4, transparentPixel = -1;
- switch (bitmapData.PixelFormat) {
- case Gdip.PixelFormat1bppIndexed: depth = 1; break;
- case Gdip.PixelFormat4bppIndexed: depth = 4; break;
- case Gdip.PixelFormat8bppIndexed: depth = 8; break;
- case Gdip.PixelFormat16bppARGB1555:
- case Gdip.PixelFormat16bppRGB555:
- case Gdip.PixelFormat16bppRGB565: depth = 16; break;
- case Gdip.PixelFormat24bppRGB: depth = 24; break;
- case Gdip.PixelFormat32bppRGB:
- case Gdip.PixelFormat32bppARGB: depth = 32; break;
- }
- if (depth != 0) {
- PaletteData paletteData = null;
- switch (bitmapData.PixelFormat) {
- case Gdip.PixelFormat1bppIndexed:
- case Gdip.PixelFormat4bppIndexed:
- case Gdip.PixelFormat8bppIndexed:
- int paletteSize = Gdip.Image_GetPaletteSize(bitmap);
- int /*long*/ hHeap = OS.GetProcessHeap();
- int /*long*/ palette = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, paletteSize);
- if (palette == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Gdip.Image_GetPalette(bitmap, palette, paletteSize);
- ColorPalette colorPalette = new ColorPalette();
- Gdip.MoveMemory(colorPalette, palette, ColorPalette.sizeof);
- int[] entries = new int[colorPalette.Count];
- OS.MoveMemory(entries, palette + 8, entries.length * 4);
- OS.HeapFree(hHeap, 0, palette);
- RGB[] rgbs = new RGB[colorPalette.Count];
- paletteData = new PaletteData(rgbs);
- for (int i = 0; i < entries.length; i++) {
- if (((entries[i] >> 24) & 0xFF) == 0 && (colorPalette.Flags & Gdip.PaletteFlagsHasAlpha) != 0) {
- transparentPixel = i;
- }
- rgbs[i] = new RGB(((entries[i] & 0xFF0000) >> 16), ((entries[i] & 0xFF00) >> 8), ((entries[i] & 0xFF) >> 0));
- }
- break;
- case Gdip.PixelFormat16bppARGB1555:
- case Gdip.PixelFormat16bppRGB555: paletteData = new PaletteData(0x7C00, 0x3E0, 0x1F); break;
- case Gdip.PixelFormat16bppRGB565: paletteData = new PaletteData(0xF800, 0x7E0, 0x1F); break;
- case Gdip.PixelFormat24bppRGB: paletteData = new PaletteData(0xFF, 0xFF00, 0xFF0000); break;
- case Gdip.PixelFormat32bppRGB:
- case Gdip.PixelFormat32bppARGB: paletteData = new PaletteData(0xFF00, 0xFF0000, 0xFF000000); break;
- }
- byte[] data = new byte[stride * height], alphaData = null;
- OS.MoveMemory(data, pixels, data.length);
- switch (bitmapData.PixelFormat) {
- case Gdip.PixelFormat16bppARGB1555:
- alphaData = new byte[width * height];
- for (int i = 1, j = 0; i < data.length; i += 2, j++) {
- alphaData[j] = (byte)((data[i] & 0x80) != 0 ? 255 : 0);
- }
- break;
- case Gdip.PixelFormat32bppARGB:
- alphaData = new byte[width * height];
- for (int i = 3, j = 0; i < data.length; i += 4, j++) {
- alphaData[j] = data[i];
- }
- break;
- }
- ImageData img = new ImageData(width, height, depth, paletteData, scanlinePad, data);
- img.transparentPixel = transparentPixel;
- img.alphaData = alphaData;
- init(img);
- }
- Gdip.Bitmap_UnlockBits(bitmap, lockedBitmapData);
- } else {
- error = SWT.ERROR_INVALID_IMAGE;
- }
- Gdip.BitmapData_delete(lockedBitmapData);
- }
- }
- }
- }
- Gdip.Bitmap_delete(bitmap);
- if (status == 0) {
- if (this.handle == 0) SWT.error(error);
- }
- }
- }
-}
-
-/**
- * Create a DIB from a DDB without using GetDIBits. Note that
- * the DDB should not be selected into a HDC.
- */
-int /*long*/ createDIBFromDDB(int /*long*/ hDC, int /*long*/ hBitmap, int width, int height) {
-
- /* Determine the DDB depth */
- int bits = OS.GetDeviceCaps (hDC, OS.BITSPIXEL);
- int planes = OS.GetDeviceCaps (hDC, OS.PLANES);
- int depth = bits * planes;
-
- /* Determine the DIB palette */
- boolean isDirect = depth > 8;
- RGB[] rgbs = null;
- if (!isDirect) {
- int numColors = 1 << depth;
- byte[] logPalette = new byte[4 * numColors];
- OS.GetPaletteEntries(device.hPalette, 0, numColors, logPalette);
- rgbs = new RGB[numColors];
- for (int i = 0; i < numColors; i++) {
- rgbs[i] = new RGB(logPalette[i] & 0xFF, logPalette[i + 1] & 0xFF, logPalette[i + 2] & 0xFF);
- }
- }
-
- boolean useBitfields = OS.IsWinCE && (depth == 16 || depth == 32);
- BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER();
- bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
- bmiHeader.biWidth = width;
- bmiHeader.biHeight = -height;
- bmiHeader.biPlanes = 1;
- bmiHeader.biBitCount = (short)depth;
- if (useBitfields) bmiHeader.biCompression = OS.BI_BITFIELDS;
- else bmiHeader.biCompression = OS.BI_RGB;
- byte[] bmi;
- if (isDirect) bmi = new byte[BITMAPINFOHEADER.sizeof + (useBitfields ? 12 : 0)];
- else bmi = new byte[BITMAPINFOHEADER.sizeof + rgbs.length * 4];
- OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
-
- /* Set the rgb colors into the bitmap info */
- int offset = BITMAPINFOHEADER.sizeof;
- if (isDirect) {
- if (useBitfields) {
- int redMask = 0;
- int greenMask = 0;
- int blueMask = 0;
- switch (depth) {
- case 16:
- redMask = 0x7C00;
- greenMask = 0x3E0;
- blueMask = 0x1F;
- /* little endian */
- bmi[offset] = (byte)((redMask & 0xFF) >> 0);
- bmi[offset + 1] = (byte)((redMask & 0xFF00) >> 8);
- bmi[offset + 2] = (byte)((redMask & 0xFF0000) >> 16);
- bmi[offset + 3] = (byte)((redMask & 0xFF000000) >> 24);
- bmi[offset + 4] = (byte)((greenMask & 0xFF) >> 0);
- bmi[offset + 5] = (byte)((greenMask & 0xFF00) >> 8);
- bmi[offset + 6] = (byte)((greenMask & 0xFF0000) >> 16);
- bmi[offset + 7] = (byte)((greenMask & 0xFF000000) >> 24);
- bmi[offset + 8] = (byte)((blueMask & 0xFF) >> 0);
- bmi[offset + 9] = (byte)((blueMask & 0xFF00) >> 8);
- bmi[offset + 10] = (byte)((blueMask & 0xFF0000) >> 16);
- bmi[offset + 11] = (byte)((blueMask & 0xFF000000) >> 24);
- break;
- case 32:
- redMask = 0xFF00;
- greenMask = 0xFF0000;
- blueMask = 0xFF000000;
- /* big endian */
- bmi[offset] = (byte)((redMask & 0xFF000000) >> 24);
- bmi[offset + 1] = (byte)((redMask & 0xFF0000) >> 16);
- bmi[offset + 2] = (byte)((redMask & 0xFF00) >> 8);
- bmi[offset + 3] = (byte)((redMask & 0xFF) >> 0);
- bmi[offset + 4] = (byte)((greenMask & 0xFF000000) >> 24);
- bmi[offset + 5] = (byte)((greenMask & 0xFF0000) >> 16);
- bmi[offset + 6] = (byte)((greenMask & 0xFF00) >> 8);
- bmi[offset + 7] = (byte)((greenMask & 0xFF) >> 0);
- bmi[offset + 8] = (byte)((blueMask & 0xFF000000) >> 24);
- bmi[offset + 9] = (byte)((blueMask & 0xFF0000) >> 16);
- bmi[offset + 10] = (byte)((blueMask & 0xFF00) >> 8);
- bmi[offset + 11] = (byte)((blueMask & 0xFF) >> 0);
- break;
- default:
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- }
- }
- } else {
- for (int j = 0; j < rgbs.length; j++) {
- bmi[offset] = (byte)rgbs[j].blue;
- bmi[offset + 1] = (byte)rgbs[j].green;
- bmi[offset + 2] = (byte)rgbs[j].red;
- bmi[offset + 3] = 0;
- offset += 4;
- }
- }
- int /*long*/[] pBits = new int /*long*/[1];
- int /*long*/ hDib = OS.CreateDIBSection(0, bmi, OS.DIB_RGB_COLORS, pBits, 0, 0);
- if (hDib == 0) SWT.error(SWT.ERROR_NO_HANDLES);
-
- /* Bitblt DDB into DIB */
- int /*long*/ hdcSource = OS.CreateCompatibleDC(hDC);
- int /*long*/ hdcDest = OS.CreateCompatibleDC(hDC);
- int /*long*/ hOldSrc = OS.SelectObject(hdcSource, hBitmap);
- int /*long*/ hOldDest = OS.SelectObject(hdcDest, hDib);
- OS.BitBlt(hdcDest, 0, 0, width, height, hdcSource, 0, 0, OS.SRCCOPY);
- OS.SelectObject(hdcSource, hOldSrc);
- OS.SelectObject(hdcDest, hOldDest);
- OS.DeleteDC(hdcSource);
- OS.DeleteDC(hdcDest);
-
- return hDib;
-}
-
-int /*long*/ [] createGdipImage() {
- switch (type) {
- case SWT.BITMAP: {
- if (alpha != -1 || alphaData != null || transparentPixel != -1) {
- BITMAP bm = new BITMAP();
- OS.GetObject(handle, BITMAP.sizeof, bm);
- int imgWidth = bm.bmWidth;
- int imgHeight = bm.bmHeight;
- int /*long*/ hDC = device.internal_new_GC(null);
- int /*long*/ srcHdc = OS.CreateCompatibleDC(hDC);
- int /*long*/ oldSrcBitmap = OS.SelectObject(srcHdc, handle);
- int /*long*/ memHdc = OS.CreateCompatibleDC(hDC);
- int /*long*/ memDib = createDIB(imgWidth, imgHeight, 32);
- if (memDib == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ oldMemBitmap = OS.SelectObject(memHdc, memDib);
- BITMAP dibBM = new BITMAP();
- OS.GetObject(memDib, BITMAP.sizeof, dibBM);
- int sizeInBytes = dibBM.bmWidthBytes * dibBM.bmHeight;
- OS.BitBlt(memHdc, 0, 0, imgWidth, imgHeight, srcHdc, 0, 0, OS.SRCCOPY);
- byte red = 0, green = 0, blue = 0;
- if (transparentPixel != -1) {
- if (bm.bmBitsPixel <= 8) {
- byte[] color = new byte[4];
- OS.GetDIBColorTable(srcHdc, transparentPixel, 1, color);
- blue = color[0];
- green = color[1];
- red = color[2];
- } else {
- switch (bm.bmBitsPixel) {
- case 16:
- int blueMask = 0x1F;
- int blueShift = ImageData.getChannelShift(blueMask);
- byte[] blues = ImageData.ANY_TO_EIGHT[ImageData.getChannelWidth(blueMask, blueShift)];
- blue = blues[(transparentPixel & blueMask) >> blueShift];
- int greenMask = 0x3E0;
- int greenShift = ImageData.getChannelShift(greenMask);
- byte[] greens = ImageData.ANY_TO_EIGHT[ImageData.getChannelWidth(greenMask, greenShift)];
- green = greens[(transparentPixel & greenMask) >> greenShift];
- int redMask = 0x7C00;
- int redShift = ImageData.getChannelShift(redMask);
- byte[] reds = ImageData.ANY_TO_EIGHT[ImageData.getChannelWidth(redMask, redShift)];
- red = reds[(transparentPixel & redMask) >> redShift];
- break;
- case 24:
- blue = (byte)((transparentPixel & 0xFF0000) >> 16);
- green = (byte)((transparentPixel & 0xFF00) >> 8);
- red = (byte)(transparentPixel & 0xFF);
- break;
- case 32:
- blue = (byte)((transparentPixel & 0xFF000000) >>> 24);
- green = (byte)((transparentPixel & 0xFF0000) >> 16);
- red = (byte)((transparentPixel & 0xFF00) >> 8);
- break;
- }
- }
- }
- OS.SelectObject(srcHdc, oldSrcBitmap);
- OS.SelectObject(memHdc, oldMemBitmap);
- OS.DeleteObject(srcHdc);
- OS.DeleteObject(memHdc);
- byte[] srcData = new byte[sizeInBytes];
- OS.MoveMemory(srcData, dibBM.bmBits, sizeInBytes);
- OS.DeleteObject(memDib);
- device.internal_dispose_GC(hDC, null);
- if (alpha != -1) {
- for (int y = 0, dp = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- srcData[dp + 3] = (byte)alpha;
- dp += 4;
- }
- }
- } else if (alphaData != null) {
- for (int y = 0, dp = 0, ap = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- srcData[dp + 3] = alphaData[ap++];
- dp += 4;
- }
- }
- } else if (transparentPixel != -1) {
- for (int y = 0, dp = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- if (srcData[dp] == blue && srcData[dp + 1] == green && srcData[dp + 2] == red) {
- srcData[dp + 3] = (byte)0;
- } else {
- srcData[dp + 3] = (byte)0xFF;
- }
- dp += 4;
- }
- }
- }
- int /*long*/ hHeap = OS.GetProcessHeap();
- int /*long*/ pixels = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, srcData.length);
- if (pixels == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.MoveMemory(pixels, srcData, sizeInBytes);
- return new int /*long*/ []{Gdip.Bitmap_new(imgWidth, imgHeight, dibBM.bmWidthBytes, Gdip.PixelFormat32bppARGB, pixels), pixels};
- }
- return new int /*long*/ []{Gdip.Bitmap_new(handle, 0), 0};
- }
- case SWT.ICON: {
- /*
- * Bug in GDI+. Creating a new GDI+ Bitmap from a HICON segment faults
- * when the icon width is bigger than the icon height. The fix is to
- * detect this and create a PixelFormat32bppARGB image instead.
- */
- ICONINFO iconInfo = new ICONINFO();
- if (OS.IsWinCE) {
- GetIconInfo(this, iconInfo);
- } else {
- OS.GetIconInfo(handle, iconInfo);
- }
- int /*long*/ hBitmap = iconInfo.hbmColor;
- if (hBitmap == 0) hBitmap = iconInfo.hbmMask;
- BITMAP bm = new BITMAP();
- OS.GetObject(hBitmap, BITMAP.sizeof, bm);
- int imgWidth = bm.bmWidth;
- int imgHeight = hBitmap == iconInfo.hbmMask ? bm.bmHeight / 2 : bm.bmHeight;
- int /*long*/ img = 0, pixels = 0;
- /*
- * Bug in GDI+. Bitmap_new() segments fault if the image width
- * is greater than the image height.
- *
- * Note that it also fails to generated an appropriate alpha
- * channel when the icon depth is 32.
- */
- if (imgWidth > imgHeight || bm.bmBitsPixel == 32) {
- int /*long*/ hDC = device.internal_new_GC(null);
- int /*long*/ srcHdc = OS.CreateCompatibleDC(hDC);
- int /*long*/ oldSrcBitmap = OS.SelectObject(srcHdc, hBitmap);
- int /*long*/ memHdc = OS.CreateCompatibleDC(hDC);
- int /*long*/ memDib = createDIB(imgWidth, imgHeight, 32);
- if (memDib == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ oldMemBitmap = OS.SelectObject(memHdc, memDib);
- BITMAP dibBM = new BITMAP();
- OS.GetObject(memDib, BITMAP.sizeof, dibBM);
- OS.BitBlt(memHdc, 0, 0, imgWidth, imgHeight, srcHdc, 0, hBitmap == iconInfo.hbmMask ? imgHeight : 0, OS.SRCCOPY);
- OS.SelectObject(memHdc, oldMemBitmap);
- OS.DeleteObject(memHdc);
- byte[] srcData = new byte[dibBM.bmWidthBytes * dibBM.bmHeight];
- OS.MoveMemory(srcData, dibBM.bmBits, srcData.length);
- OS.DeleteObject(memDib);
- OS.SelectObject(srcHdc, iconInfo.hbmMask);
- for (int y = 0, dp = 3; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- if (srcData[dp] == 0) {
- if (OS.GetPixel(srcHdc, x, y) != 0) {
- srcData[dp] = (byte)0;
- } else {
- srcData[dp] = (byte)0xFF;
- }
- }
- dp += 4;
- }
- }
- OS.SelectObject(srcHdc, oldSrcBitmap);
- OS.DeleteObject(srcHdc);
- device.internal_dispose_GC(hDC, null);
- int /*long*/ hHeap = OS.GetProcessHeap();
- pixels = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, srcData.length);
- if (pixels == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.MoveMemory(pixels, srcData, srcData.length);
- img = Gdip.Bitmap_new(imgWidth, imgHeight, dibBM.bmWidthBytes, Gdip.PixelFormat32bppARGB, pixels);
- } else {
- img = Gdip.Bitmap_new(handle);
- }
- if (iconInfo.hbmColor != 0) OS.DeleteObject(iconInfo.hbmColor);
- if (iconInfo.hbmMask != 0) OS.DeleteObject(iconInfo.hbmMask);
- return new int /*long*/ []{img, pixels};
- }
- default: SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- return null;
-}
-
-void destroy () {
- if (memGC != null) memGC.dispose();
- if (type == SWT.ICON) {
- if (OS.IsWinCE) data = null;
- OS.DestroyIcon (handle);
- } else {
- OS.DeleteObject (handle);
- }
- handle = 0;
- memGC = null;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Image)) return false;
- Image image = (Image) object;
- return device == image.device && handle == image.handle;
-}
-
-/**
- * Returns the color to which to map the transparent pixel, or null if
- * the receiver has no transparent pixel.
- * <p>
- * There are certain uses of Images that do not support transparency
- * (for example, setting an image into a button or label). In these cases,
- * it may be desired to simulate transparency by using the background
- * color of the widget to paint the transparent pixels of the image.
- * Use this method to check which color will be used in these cases
- * in place of transparency. This value may be set with setBackground().
- * <p>
- *
- * @return the background color of the image, or null if there is no transparency in the image
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getBackground() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transparentPixel == -1) return null;
-
- /* Get the HDC for the device */
- int /*long*/ hDC = device.internal_new_GC(null);
-
- /* Compute the background color */
- BITMAP bm = new BITMAP();
- OS.GetObject(handle, BITMAP.sizeof, bm);
- int /*long*/ hdcMem = OS.CreateCompatibleDC(hDC);
- int /*long*/ hOldObject = OS.SelectObject(hdcMem, handle);
- int red = 0, green = 0, blue = 0;
- if (bm.bmBitsPixel <= 8) {
- if (OS.IsWinCE) {
- byte[] pBits = new byte[1];
- OS.MoveMemory(pBits, bm.bmBits, 1);
- byte oldValue = pBits[0];
- int mask = (0xFF << (8 - bm.bmBitsPixel)) & 0x00FF;
- pBits[0] = (byte)((transparentPixel << (8 - bm.bmBitsPixel)) | (pBits[0] & ~mask));
- OS.MoveMemory(bm.bmBits, pBits, 1);
- int color = OS.GetPixel(hdcMem, 0, 0);
- pBits[0] = oldValue;
- OS.MoveMemory(bm.bmBits, pBits, 1);
- blue = (color & 0xFF0000) >> 16;
- green = (color & 0xFF00) >> 8;
- red = color & 0xFF;
- } else {
- byte[] color = new byte[4];
- OS.GetDIBColorTable(hdcMem, transparentPixel, 1, color);
- blue = color[0] & 0xFF;
- green = color[1] & 0xFF;
- red = color[2] & 0xFF;
- }
- } else {
- switch (bm.bmBitsPixel) {
- case 16:
- blue = (transparentPixel & 0x1F) << 3;
- green = (transparentPixel & 0x3E0) >> 2;
- red = (transparentPixel & 0x7C00) >> 7;
- break;
- case 24:
- blue = (transparentPixel & 0xFF0000) >> 16;
- green = (transparentPixel & 0xFF00) >> 8;
- red = transparentPixel & 0xFF;
- break;
- case 32:
- blue = (transparentPixel & 0xFF000000) >>> 24;
- green = (transparentPixel & 0xFF0000) >> 16;
- red = (transparentPixel & 0xFF00) >> 8;
- break;
- default:
- return null;
- }
- }
- OS.SelectObject(hdcMem, hOldObject);
- OS.DeleteDC(hdcMem);
-
- /* Release the HDC for the device */
- device.internal_dispose_GC(hDC, null);
- return Color.win32_new(device, (blue << 16) | (green << 8) | red);
-}
-
-/**
- * Returns the bounds of the receiver. The rectangle will always
- * have x and y values of 0, and the width and height of the
- * image.
- *
- * @return a rectangle specifying the image's bounds
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li>
- * </ul>
- */
-public Rectangle getBounds() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width != -1 && height != -1) {
- return new Rectangle(0, 0, width, height);
- }
- switch (type) {
- case SWT.BITMAP:
- BITMAP bm = new BITMAP();
- OS.GetObject(handle, BITMAP.sizeof, bm);
- return new Rectangle(0, 0, width = bm.bmWidth, height = bm.bmHeight);
- case SWT.ICON:
- if (OS.IsWinCE) {
- return new Rectangle(0, 0, width = data.width, height = data.height);
- } else {
- ICONINFO info = new ICONINFO();
- OS.GetIconInfo(handle, info);
- int /*long*/ hBitmap = info.hbmColor;
- if (hBitmap == 0) hBitmap = info.hbmMask;
- bm = new BITMAP();
- OS.GetObject(hBitmap, BITMAP.sizeof, bm);
- if (hBitmap == info.hbmMask) bm.bmHeight /= 2;
- if (info.hbmColor != 0) OS.DeleteObject(info.hbmColor);
- if (info.hbmMask != 0) OS.DeleteObject(info.hbmMask);
- return new Rectangle(0, 0, width = bm.bmWidth, height = bm.bmHeight);
- }
- default:
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return null;
- }
-}
-
-/**
- * Returns an <code>ImageData</code> based on the receiver
- * Modifications made to this <code>ImageData</code> will not
- * affect the Image.
- *
- * @return an <code>ImageData</code> containing the image's data and attributes
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li>
- * </ul>
- *
- * @see ImageData
- */
-public ImageData getImageData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- BITMAP bm;
- int depth, width, height;
- switch (type) {
- case SWT.ICON: {
- if (OS.IsWinCE) return data;
- ICONINFO info = new ICONINFO();
- if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- OS.GetIconInfo(handle, info);
- /* Get the basic BITMAP information */
- int /*long*/ hBitmap = info.hbmColor;
- if (hBitmap == 0) hBitmap = info.hbmMask;
- bm = new BITMAP();
- OS.GetObject(hBitmap, BITMAP.sizeof, bm);
- depth = bm.bmPlanes * bm.bmBitsPixel;
- width = bm.bmWidth;
- if (hBitmap == info.hbmMask) bm.bmHeight /= 2;
- height = bm.bmHeight;
- int numColors = 0;
- if (depth <= 8) numColors = 1 << depth;
- /* Create the BITMAPINFO */
- BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER();
- bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
- bmiHeader.biWidth = width;
- bmiHeader.biHeight = -height;
- bmiHeader.biPlanes = 1;
- bmiHeader.biBitCount = (short)depth;
- bmiHeader.biCompression = OS.BI_RGB;
- byte[] bmi = new byte[BITMAPINFOHEADER.sizeof + numColors * 4];
- OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
-
- /* Get the HDC for the device */
- int /*long*/ hDC = device.internal_new_GC(null);
-
- /* Create the DC and select the bitmap */
- int /*long*/ hBitmapDC = OS.CreateCompatibleDC(hDC);
- int /*long*/ hOldBitmap = OS.SelectObject(hBitmapDC, hBitmap);
- /* Select the palette if necessary */
- int /*long*/ oldPalette = 0;
- if (depth <= 8) {
- int /*long*/ hPalette = device.hPalette;
- if (hPalette != 0) {
- oldPalette = OS.SelectPalette(hBitmapDC, hPalette, false);
- OS.RealizePalette(hBitmapDC);
- }
- }
- /* Find the size of the image and allocate data */
- int imageSize;
- /* Call with null lpBits to get the image size */
- if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- OS.GetDIBits(hBitmapDC, hBitmap, 0, height, 0, bmi, OS.DIB_RGB_COLORS);
- OS.MoveMemory(bmiHeader, bmi, BITMAPINFOHEADER.sizeof);
- imageSize = bmiHeader.biSizeImage;
- byte[] data = new byte[imageSize];
- /* Get the bitmap data */
- int /*long*/ hHeap = OS.GetProcessHeap();
- int /*long*/ lpvBits = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, imageSize);
- if (lpvBits == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- OS.GetDIBits(hBitmapDC, hBitmap, 0, height, lpvBits, bmi, OS.DIB_RGB_COLORS);
- OS.MoveMemory(data, lpvBits, imageSize);
- /* Calculate the palette */
- PaletteData palette = null;
- if (depth <= 8) {
- RGB[] rgbs = new RGB[numColors];
- int srcIndex = 40;
- for (int i = 0; i < numColors; i++) {
- rgbs[i] = new RGB(bmi[srcIndex + 2] & 0xFF, bmi[srcIndex + 1] & 0xFF, bmi[srcIndex] & 0xFF);
- srcIndex += 4;
- }
- palette = new PaletteData(rgbs);
- } else if (depth == 16) {
- palette = new PaletteData(0x7C00, 0x3E0, 0x1F);
- } else if (depth == 24) {
- palette = new PaletteData(0xFF, 0xFF00, 0xFF0000);
- } else if (depth == 32) {
- palette = new PaletteData(0xFF00, 0xFF0000, 0xFF000000);
- } else {
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- }
-
- /* Do the mask */
- byte [] maskData = null;
- if (info.hbmColor == 0) {
- /* Do the bottom half of the mask */
- maskData = new byte[imageSize];
- if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- OS.GetDIBits(hBitmapDC, hBitmap, height, height, lpvBits, bmi, OS.DIB_RGB_COLORS);
- OS.MoveMemory(maskData, lpvBits, imageSize);
- } else {
- /* Do the entire mask */
- /* Create the BITMAPINFO */
- bmiHeader = new BITMAPINFOHEADER();
- bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
- bmiHeader.biWidth = width;
- bmiHeader.biHeight = -height;
- bmiHeader.biPlanes = 1;
- bmiHeader.biBitCount = 1;
- bmiHeader.biCompression = OS.BI_RGB;
- bmi = new byte[BITMAPINFOHEADER.sizeof + 8];
- OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
-
- /* First color black, second color white */
- int offset = BITMAPINFOHEADER.sizeof;
- bmi[offset + 4] = bmi[offset + 5] = bmi[offset + 6] = (byte)0xFF;
- bmi[offset + 7] = 0;
- OS.SelectObject(hBitmapDC, info.hbmMask);
- /* Call with null lpBits to get the image size */
- if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- OS.GetDIBits(hBitmapDC, info.hbmMask, 0, height, 0, bmi, OS.DIB_RGB_COLORS);
- OS.MoveMemory(bmiHeader, bmi, BITMAPINFOHEADER.sizeof);
- imageSize = bmiHeader.biSizeImage;
- maskData = new byte[imageSize];
- int /*long*/ lpvMaskBits = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, imageSize);
- if (lpvMaskBits == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- OS.GetDIBits(hBitmapDC, info.hbmMask, 0, height, lpvMaskBits, bmi, OS.DIB_RGB_COLORS);
- OS.MoveMemory(maskData, lpvMaskBits, imageSize);
- OS.HeapFree(hHeap, 0, lpvMaskBits);
- /* Loop to invert the mask */
- for (int i = 0; i < maskData.length; i++) {
- maskData[i] ^= -1;
- }
- /* Make sure mask scanlinePad is 2 */
- int maskPad;
- int bpl = imageSize / height;
- for (maskPad = 1; maskPad < 128; maskPad++) {
- int calcBpl = (((width + 7) / 8) + (maskPad - 1)) / maskPad * maskPad;
- if (calcBpl == bpl) break;
- }
- maskData = ImageData.convertPad(maskData, width, height, 1, maskPad, 2);
- }
- /* Clean up */
- OS.HeapFree(hHeap, 0, lpvBits);
- OS.SelectObject(hBitmapDC, hOldBitmap);
- if (oldPalette != 0) {
- OS.SelectPalette(hBitmapDC, oldPalette, false);
- OS.RealizePalette(hBitmapDC);
- }
- OS.DeleteDC(hBitmapDC);
-
- /* Release the HDC for the device */
- device.internal_dispose_GC(hDC, null);
-
- if (info.hbmColor != 0) OS.DeleteObject(info.hbmColor);
- if (info.hbmMask != 0) OS.DeleteObject(info.hbmMask);
- /* Construct and return the ImageData */
- ImageData imageData = new ImageData(width, height, depth, palette, 4, data);
- imageData.maskData = maskData;
- imageData.maskPad = 2;
- return imageData;
- }
- case SWT.BITMAP: {
- /* Get the basic BITMAP information */
- bm = new BITMAP();
- OS.GetObject(handle, BITMAP.sizeof, bm);
- depth = bm.bmPlanes * bm.bmBitsPixel;
- width = bm.bmWidth;
- height = bm.bmHeight;
- /* Find out whether this is a DIB or a DDB. */
- boolean isDib = (bm.bmBits != 0);
- /* Get the HDC for the device */
- int /*long*/ hDC = device.internal_new_GC(null);
-
- /*
- * Feature in WinCE. GetDIBits is not available in WinCE. The
- * workaround is to create a temporary DIB from the DDB and use
- * the bmBits field of DIBSECTION to retrieve the image data.
- */
- int /*long*/ handle = this.handle;
- if (OS.IsWinCE) {
- if (!isDib) {
- boolean mustRestore = false;
- if (memGC != null && !memGC.isDisposed()) {
- memGC.flush ();
- mustRestore = true;
- GCData data = memGC.data;
- if (data.hNullBitmap != 0) {
- OS.SelectObject(memGC.handle, data.hNullBitmap);
- data.hNullBitmap = 0;
- }
- }
- handle = createDIBFromDDB(hDC, this.handle, width, height);
- if (mustRestore) {
- int /*long*/ hOldBitmap = OS.SelectObject(memGC.handle, this.handle);
- memGC.data.hNullBitmap = hOldBitmap;
- }
- isDib = true;
- }
- }
- DIBSECTION dib = null;
- if (isDib) {
- dib = new DIBSECTION();
- OS.GetObject(handle, DIBSECTION.sizeof, dib);
- }
- /* Calculate number of colors */
- int numColors = 0;
- if (depth <= 8) {
- if (isDib) {
- numColors = dib.biClrUsed;
- } else {
- numColors = 1 << depth;
- }
- }
- /* Create the BITMAPINFO */
- byte[] bmi = null;
- BITMAPINFOHEADER bmiHeader = null;
- if (!isDib) {
- bmiHeader = new BITMAPINFOHEADER();
- bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
- bmiHeader.biWidth = width;
- bmiHeader.biHeight = -height;
- bmiHeader.biPlanes = 1;
- bmiHeader.biBitCount = (short)depth;
- bmiHeader.biCompression = OS.BI_RGB;
- bmi = new byte[BITMAPINFOHEADER.sizeof + numColors * 4];
- OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
- }
-
- /* Create the DC and select the bitmap */
- int /*long*/ hBitmapDC = OS.CreateCompatibleDC(hDC);
- int /*long*/ hOldBitmap = OS.SelectObject(hBitmapDC, handle);
- /* Select the palette if necessary */
- int /*long*/ oldPalette = 0;
- if (!isDib && depth <= 8) {
- int /*long*/ hPalette = device.hPalette;
- if (hPalette != 0) {
- oldPalette = OS.SelectPalette(hBitmapDC, hPalette, false);
- OS.RealizePalette(hBitmapDC);
- }
- }
- /* Find the size of the image and allocate data */
- int imageSize;
- if (isDib) {
- imageSize = dib.biSizeImage;
- } else {
- /* Call with null lpBits to get the image size */
- if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- OS.GetDIBits(hBitmapDC, handle, 0, height, 0, bmi, OS.DIB_RGB_COLORS);
- OS.MoveMemory(bmiHeader, bmi, BITMAPINFOHEADER.sizeof);
- imageSize = bmiHeader.biSizeImage;
- }
- byte[] data = new byte[imageSize];
- /* Get the bitmap data */
- if (isDib) {
- if (OS.IsWinCE && this.handle != handle) {
- /* get image data from the temporary DIB */
- OS.MoveMemory(data, dib.bmBits, imageSize);
- } else {
- OS.MoveMemory(data, bm.bmBits, imageSize);
- }
- } else {
- int /*long*/ hHeap = OS.GetProcessHeap();
- int /*long*/ lpvBits = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, imageSize);
- if (lpvBits == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- OS.GetDIBits(hBitmapDC, handle, 0, height, lpvBits, bmi, OS.DIB_RGB_COLORS);
- OS.MoveMemory(data, lpvBits, imageSize);
- OS.HeapFree(hHeap, 0, lpvBits);
- }
- /* Calculate the palette */
- PaletteData palette = null;
- if (depth <= 8) {
- RGB[] rgbs = new RGB[numColors];
- if (isDib) {
- if (OS.IsWinCE) {
- /*
- * Feature on WinCE. GetDIBColorTable is not supported.
- * The workaround is to set a pixel to the desired
- * palette index and use getPixel to get the corresponding
- * RGB value.
- */
- int red = 0, green = 0, blue = 0;
- byte[] pBits = new byte[1];
- OS.MoveMemory(pBits, bm.bmBits, 1);
- byte oldValue = pBits[0];
- int mask = (0xFF << (8 - bm.bmBitsPixel)) & 0x00FF;
- for (int i = 0; i < numColors; i++) {
- pBits[0] = (byte)((i << (8 - bm.bmBitsPixel)) | (pBits[0] & ~mask));
- OS.MoveMemory(bm.bmBits, pBits, 1);
- int color = OS.GetPixel(hBitmapDC, 0, 0);
- blue = (color & 0xFF0000) >> 16;
- green = (color & 0xFF00) >> 8;
- red = color & 0xFF;
- rgbs[i] = new RGB(red, green, blue);
- }
- pBits[0] = oldValue;
- OS.MoveMemory(bm.bmBits, pBits, 1);
- } else {
- byte[] colors = new byte[numColors * 4];
- OS.GetDIBColorTable(hBitmapDC, 0, numColors, colors);
- int colorIndex = 0;
- for (int i = 0; i < rgbs.length; i++) {
- rgbs[i] = new RGB(colors[colorIndex + 2] & 0xFF, colors[colorIndex + 1] & 0xFF, colors[colorIndex] & 0xFF);
- colorIndex += 4;
- }
- }
- } else {
- int srcIndex = BITMAPINFOHEADER.sizeof;
- for (int i = 0; i < numColors; i++) {
- rgbs[i] = new RGB(bmi[srcIndex + 2] & 0xFF, bmi[srcIndex + 1] & 0xFF, bmi[srcIndex] & 0xFF);
- srcIndex += 4;
- }
- }
- palette = new PaletteData(rgbs);
- } else if (depth == 16) {
- palette = new PaletteData(0x7C00, 0x3E0, 0x1F);
- } else if (depth == 24) {
- palette = new PaletteData(0xFF, 0xFF00, 0xFF0000);
- } else if (depth == 32) {
- palette = new PaletteData(0xFF00, 0xFF0000, 0xFF000000);
- } else {
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- }
- /* Clean up */
- OS.SelectObject(hBitmapDC, hOldBitmap);
- if (oldPalette != 0) {
- OS.SelectPalette(hBitmapDC, oldPalette, false);
- OS.RealizePalette(hBitmapDC);
- }
- if (OS.IsWinCE) {
- if (handle != this.handle) {
- /* free temporary DIB */
- OS.DeleteObject (handle);
- }
- }
- OS.DeleteDC(hBitmapDC);
-
- /* Release the HDC for the device */
- device.internal_dispose_GC(hDC, null);
-
- /* Construct and return the ImageData */
- ImageData imageData = new ImageData(width, height, depth, palette, 4, data);
- imageData.transparentPixel = this.transparentPixel;
- imageData.alpha = alpha;
- if (alpha == -1 && alphaData != null) {
- imageData.alphaData = new byte[alphaData.length];
- System.arraycopy(alphaData, 0, imageData.alphaData, 0, alphaData.length);
- }
- return imageData;
- }
- default:
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return null;
- }
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return (int)/*64*/handle;
-}
-
-void init(int width, int height) {
- if (width <= 0 || height <= 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- type = SWT.BITMAP;
- int /*long*/ hDC = device.internal_new_GC(null);
- handle = OS.CreateCompatibleBitmap(hDC, width, height);
- /*
- * Feature in Windows. CreateCompatibleBitmap() may fail
- * for large images. The fix is to create a DIB section
- * in that case.
- */
- if (handle == 0) {
- int bits = OS.GetDeviceCaps(hDC, OS.BITSPIXEL);
- int planes = OS.GetDeviceCaps(hDC, OS.PLANES);
- int depth = bits * planes;
- if (depth < 16) depth = 16;
- handle = createDIB(width, height, depth);
- }
- if (handle != 0) {
- int /*long*/ memDC = OS.CreateCompatibleDC(hDC);
- int /*long*/ hOldBitmap = OS.SelectObject(memDC, handle);
- OS.PatBlt(memDC, 0, 0, width, height, OS.PATCOPY);
- OS.SelectObject(memDC, hOldBitmap);
- OS.DeleteDC(memDC);
- }
- device.internal_dispose_GC(hDC, null);
- if (handle == 0) {
- SWT.error(SWT.ERROR_NO_HANDLES, null, device.getLastError());
- }
-}
-
-static int /*long*/ createDIB(int width, int height, int depth) {
- BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER();
- bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
- bmiHeader.biWidth = width;
- bmiHeader.biHeight = -height;
- bmiHeader.biPlanes = 1;
- bmiHeader.biBitCount = (short)depth;
- if (OS.IsWinCE) bmiHeader.biCompression = OS.BI_BITFIELDS;
- else bmiHeader.biCompression = OS.BI_RGB;
- byte[] bmi = new byte[BITMAPINFOHEADER.sizeof + (OS.IsWinCE ? 12 : 0)];
- OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
- /* Set the rgb colors into the bitmap info */
- if (OS.IsWinCE) {
- int redMask = 0xFF00;
- int greenMask = 0xFF0000;
- int blueMask = 0xFF000000;
- /* big endian */
- int offset = BITMAPINFOHEADER.sizeof;
- bmi[offset] = (byte)((redMask & 0xFF000000) >> 24);
- bmi[offset + 1] = (byte)((redMask & 0xFF0000) >> 16);
- bmi[offset + 2] = (byte)((redMask & 0xFF00) >> 8);
- bmi[offset + 3] = (byte)((redMask & 0xFF) >> 0);
- bmi[offset + 4] = (byte)((greenMask & 0xFF000000) >> 24);
- bmi[offset + 5] = (byte)((greenMask & 0xFF0000) >> 16);
- bmi[offset + 6] = (byte)((greenMask & 0xFF00) >> 8);
- bmi[offset + 7] = (byte)((greenMask & 0xFF) >> 0);
- bmi[offset + 8] = (byte)((blueMask & 0xFF000000) >> 24);
- bmi[offset + 9] = (byte)((blueMask & 0xFF0000) >> 16);
- bmi[offset + 10] = (byte)((blueMask & 0xFF00) >> 8);
- bmi[offset + 11] = (byte)((blueMask & 0xFF) >> 0);
- }
-
- int /*long*/[] pBits = new int /*long*/[1];
- return OS.CreateDIBSection(0, bmi, OS.DIB_RGB_COLORS, pBits, 0, 0);
-}
-
-/**
- * Feature in WinCE. GetIconInfo is not available in WinCE.
- * The workaround is to cache the object ImageData for images
- * of type SWT.ICON. The bitmaps hbmMask and hbmColor can then
- * be reconstructed by using our version of getIconInfo.
- * This function takes an ICONINFO object and sets the fields
- * hbmMask and hbmColor with the corresponding bitmaps it has
- * created.
- * Note. These bitmaps must be freed - as they would have to be
- * if the regular GetIconInfo had been used.
- */
-static void GetIconInfo(Image image, ICONINFO info) {
- int /*long*/ [] result = init(image.device, null, image.data);
- info.hbmColor = result[0];
- info.hbmMask = result[1];
-}
-
-static int /*long*/ [] init(Device device, Image image, ImageData i) {
- /*
- * BUG in Windows 98:
- * A monochrome DIBSection will display as solid black
- * on Windows 98 machines, even though it contains the
- * correct data. The fix is to convert 1-bit ImageData
- * into 4-bit ImageData before creating the image.
- */
- /* Windows does not support 2-bit images. Convert to 4-bit image. */
- if ((OS.IsWin95 && i.depth == 1 && i.getTransparencyType() != SWT.TRANSPARENCY_MASK) || i.depth == 2) {
- ImageData img = new ImageData(i.width, i.height, 4, i.palette);
- ImageData.blit(ImageData.BLIT_SRC,
- i.data, i.depth, i.bytesPerLine, i.getByteOrder(), 0, 0, i.width, i.height, null, null, null,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- img.data, img.depth, img.bytesPerLine, i.getByteOrder(), 0, 0, img.width, img.height, null, null, null,
- false, false);
- img.transparentPixel = i.transparentPixel;
- img.maskPad = i.maskPad;
- img.maskData = i.maskData;
- img.alpha = i.alpha;
- img.alphaData = i.alphaData;
- i = img;
- }
- /*
- * Windows supports 16-bit mask of (0x7C00, 0x3E0, 0x1F),
- * 24-bit mask of (0xFF0000, 0xFF00, 0xFF) and 32-bit mask
- * (0x00FF0000, 0x0000FF00, 0x000000FF) as documented in
- * MSDN BITMAPINFOHEADER. Make sure the image is
- * Windows-supported.
- */
- /*
- * Note on WinCE. CreateDIBSection requires the biCompression
- * field of the BITMAPINFOHEADER to be set to BI_BITFIELDS for
- * 16 and 32 bit direct images (see MSDN for CreateDIBSection).
- * In this case, the color mask can be set to any value. For
- * consistency, it is set to the same mask used by non WinCE
- * platforms in BI_RGB mode.
- */
- if (i.palette.isDirect) {
- final PaletteData palette = i.palette;
- final int redMask = palette.redMask;
- final int greenMask = palette.greenMask;
- final int blueMask = palette.blueMask;
- int newDepth = i.depth;
- int newOrder = ImageData.MSB_FIRST;
- PaletteData newPalette = null;
-
- switch (i.depth) {
- case 8:
- newDepth = 16;
- newOrder = ImageData.LSB_FIRST;
- newPalette = new PaletteData(0x7C00, 0x3E0, 0x1F);
- break;
- case 16:
- newOrder = ImageData.LSB_FIRST;
- if (!(redMask == 0x7C00 && greenMask == 0x3E0 && blueMask == 0x1F)) {
- newPalette = new PaletteData(0x7C00, 0x3E0, 0x1F);
- }
- break;
- case 24:
- if (!(redMask == 0xFF && greenMask == 0xFF00 && blueMask == 0xFF0000)) {
- newPalette = new PaletteData(0xFF, 0xFF00, 0xFF0000);
- }
- break;
- case 32:
- if (!(redMask == 0xFF00 && greenMask == 0xFF0000 && blueMask == 0xFF000000)) {
- newPalette = new PaletteData(0xFF00, 0xFF0000, 0xFF000000);
- }
- break;
- default:
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- }
- if (newPalette != null) {
- ImageData img = new ImageData(i.width, i.height, newDepth, newPalette);
- ImageData.blit(ImageData.BLIT_SRC,
- i.data, i.depth, i.bytesPerLine, i.getByteOrder(), 0, 0, i.width, i.height, redMask, greenMask, blueMask,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- img.data, img.depth, img.bytesPerLine, newOrder, 0, 0, img.width, img.height, newPalette.redMask, newPalette.greenMask, newPalette.blueMask,
- false, false);
- if (i.transparentPixel != -1) {
- img.transparentPixel = newPalette.getPixel(palette.getRGB(i.transparentPixel));
- }
- img.maskPad = i.maskPad;
- img.maskData = i.maskData;
- img.alpha = i.alpha;
- img.alphaData = i.alphaData;
- i = img;
- }
- }
- /* Construct bitmap info header by hand */
- RGB[] rgbs = i.palette.getRGBs();
- boolean useBitfields = OS.IsWinCE && (i.depth == 16 || i.depth == 32);
- BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER();
- bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
- bmiHeader.biWidth = i.width;
- bmiHeader.biHeight = -i.height;
- bmiHeader.biPlanes = 1;
- bmiHeader.biBitCount = (short)i.depth;
- if (useBitfields) bmiHeader.biCompression = OS.BI_BITFIELDS;
- else bmiHeader.biCompression = OS.BI_RGB;
- bmiHeader.biClrUsed = rgbs == null ? 0 : rgbs.length;
- byte[] bmi;
- if (i.palette.isDirect)
- bmi = new byte[BITMAPINFOHEADER.sizeof + (useBitfields ? 12 : 0)];
- else
- bmi = new byte[BITMAPINFOHEADER.sizeof + rgbs.length * 4];
- OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
- /* Set the rgb colors into the bitmap info */
- int offset = BITMAPINFOHEADER.sizeof;
- if (i.palette.isDirect) {
- if (useBitfields) {
- PaletteData palette = i.palette;
- int redMask = palette.redMask;
- int greenMask = palette.greenMask;
- int blueMask = palette.blueMask;
- /*
- * The color masks must be written based on the
- * endianness of the ImageData.
- */
- if (i.getByteOrder() == ImageData.LSB_FIRST) {
- bmi[offset] = (byte)((redMask & 0xFF) >> 0);
- bmi[offset + 1] = (byte)((redMask & 0xFF00) >> 8);
- bmi[offset + 2] = (byte)((redMask & 0xFF0000) >> 16);
- bmi[offset + 3] = (byte)((redMask & 0xFF000000) >> 24);
- bmi[offset + 4] = (byte)((greenMask & 0xFF) >> 0);
- bmi[offset + 5] = (byte)((greenMask & 0xFF00) >> 8);
- bmi[offset + 6] = (byte)((greenMask & 0xFF0000) >> 16);
- bmi[offset + 7] = (byte)((greenMask & 0xFF000000) >> 24);
- bmi[offset + 8] = (byte)((blueMask & 0xFF) >> 0);
- bmi[offset + 9] = (byte)((blueMask & 0xFF00) >> 8);
- bmi[offset + 10] = (byte)((blueMask & 0xFF0000) >> 16);
- bmi[offset + 11] = (byte)((blueMask & 0xFF000000) >> 24);
- } else {
- bmi[offset] = (byte)((redMask & 0xFF000000) >> 24);
- bmi[offset + 1] = (byte)((redMask & 0xFF0000) >> 16);
- bmi[offset + 2] = (byte)((redMask & 0xFF00) >> 8);
- bmi[offset + 3] = (byte)((redMask & 0xFF) >> 0);
- bmi[offset + 4] = (byte)((greenMask & 0xFF000000) >> 24);
- bmi[offset + 5] = (byte)((greenMask & 0xFF0000) >> 16);
- bmi[offset + 6] = (byte)((greenMask & 0xFF00) >> 8);
- bmi[offset + 7] = (byte)((greenMask & 0xFF) >> 0);
- bmi[offset + 8] = (byte)((blueMask & 0xFF000000) >> 24);
- bmi[offset + 9] = (byte)((blueMask & 0xFF0000) >> 16);
- bmi[offset + 10] = (byte)((blueMask & 0xFF00) >> 8);
- bmi[offset + 11] = (byte)((blueMask & 0xFF) >> 0);
- }
- }
- } else {
- for (int j = 0; j < rgbs.length; j++) {
- bmi[offset] = (byte)rgbs[j].blue;
- bmi[offset + 1] = (byte)rgbs[j].green;
- bmi[offset + 2] = (byte)rgbs[j].red;
- bmi[offset + 3] = 0;
- offset += 4;
- }
- }
- int /*long*/[] pBits = new int /*long*/[1];
- int /*long*/ hDib = OS.CreateDIBSection(0, bmi, OS.DIB_RGB_COLORS, pBits, 0, 0);
- if (hDib == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- /* In case of a scanline pad other than 4, do the work to convert it */
- byte[] data = i.data;
- if (i.scanlinePad != 4 && (i.bytesPerLine % 4 != 0)) {
- data = ImageData.convertPad(data, i.width, i.height, i.depth, i.scanlinePad, 4);
- }
- OS.MoveMemory(pBits[0], data, data.length);
-
- int /*long*/ [] result = null;
- if (i.getTransparencyType() == SWT.TRANSPARENCY_MASK) {
- /* Get the HDC for the device */
- int /*long*/ hDC = device.internal_new_GC(null);
-
- /* Create the color bitmap */
- int /*long*/ hdcSrc = OS.CreateCompatibleDC(hDC);
- OS.SelectObject(hdcSrc, hDib);
- int /*long*/ hBitmap = OS.CreateCompatibleBitmap(hDC, i.width, i.height);
- if (hBitmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ hdcDest = OS.CreateCompatibleDC(hDC);
- OS.SelectObject(hdcDest, hBitmap);
- OS.BitBlt(hdcDest, 0, 0, i.width, i.height, hdcSrc, 0, 0, OS.SRCCOPY);
-
- /* Release the HDC for the device */
- device.internal_dispose_GC(hDC, null);
-
- /* Create the mask. Windows requires icon masks to have a scanline pad of 2. */
- byte[] maskData = ImageData.convertPad(i.maskData, i.width, i.height, 1, i.maskPad, 2);
- int /*long*/ hMask = OS.CreateBitmap(i.width, i.height, 1, 1, maskData);
- if (hMask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.SelectObject(hdcSrc, hMask);
- OS.PatBlt(hdcSrc, 0, 0, i.width, i.height, OS.DSTINVERT);
- OS.DeleteDC(hdcSrc);
- OS.DeleteDC(hdcDest);
- OS.DeleteObject(hDib);
-
- if (image == null) {
- result = new int /*long*/ []{hBitmap, hMask};
- } else {
- /* Create the icon */
- ICONINFO info = new ICONINFO();
- info.fIcon = true;
- info.hbmColor = hBitmap;
- info.hbmMask = hMask;
- int /*long*/ hIcon = OS.CreateIconIndirect(info);
- if (hIcon == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.DeleteObject(hBitmap);
- OS.DeleteObject(hMask);
- image.handle = hIcon;
- image.type = SWT.ICON;
- if (OS.IsWinCE) image.data = i;
- }
- } else {
- if (image == null) {
- result = new int /*long*/ []{hDib};
- } else {
- image.handle = hDib;
- image.type = SWT.BITMAP;
- image.transparentPixel = i.transparentPixel;
- if (image.transparentPixel == -1) {
- image.alpha = i.alpha;
- if (i.alpha == -1 && i.alphaData != null) {
- int length = i.alphaData.length;
- image.alphaData = new byte[length];
- System.arraycopy(i.alphaData, 0, image.alphaData, 0, length);
- }
- }
- }
- }
- return result;
-}
-
-static int /*long*/ [] init(Device device, Image image, ImageData source, ImageData mask) {
- /* Create a temporary image and locate the black pixel */
- ImageData imageData;
- int blackIndex = 0;
- if (source.palette.isDirect) {
- imageData = new ImageData(source.width, source.height, source.depth, source.palette);
- } else {
- RGB black = new RGB(0, 0, 0);
- RGB[] rgbs = source.getRGBs();
- if (source.transparentPixel != -1) {
- /*
- * The source had transparency, so we can use the transparent pixel
- * for black.
- */
- RGB[] newRGBs = new RGB[rgbs.length];
- System.arraycopy(rgbs, 0, newRGBs, 0, rgbs.length);
- if (source.transparentPixel >= newRGBs.length) {
- /* Grow the palette with black */
- rgbs = new RGB[source.transparentPixel + 1];
- System.arraycopy(newRGBs, 0, rgbs, 0, newRGBs.length);
- for (int i = newRGBs.length; i <= source.transparentPixel; i++) {
- rgbs[i] = new RGB(0, 0, 0);
- }
- } else {
- newRGBs[source.transparentPixel] = black;
- rgbs = newRGBs;
- }
- blackIndex = source.transparentPixel;
- imageData = new ImageData(source.width, source.height, source.depth, new PaletteData(rgbs));
- } else {
- while (blackIndex < rgbs.length) {
- if (rgbs[blackIndex].equals(black)) break;
- blackIndex++;
- }
- if (blackIndex == rgbs.length) {
- /*
- * We didn't find black in the palette, and there is no transparent
- * pixel we can use.
- */
- if ((1 << source.depth) > rgbs.length) {
- /* We can grow the palette and add black */
- RGB[] newRGBs = new RGB[rgbs.length + 1];
- System.arraycopy(rgbs, 0, newRGBs, 0, rgbs.length);
- newRGBs[rgbs.length] = black;
- rgbs = newRGBs;
- } else {
- /* No room to grow the palette */
- blackIndex = -1;
- }
- }
- imageData = new ImageData(source.width, source.height, source.depth, new PaletteData(rgbs));
- }
- }
- if (blackIndex == -1) {
- /* There was no black in the palette, so just copy the data over */
- System.arraycopy(source.data, 0, imageData.data, 0, imageData.data.length);
- } else {
- /* Modify the source image to contain black wherever the mask is 0 */
- int[] imagePixels = new int[imageData.width];
- int[] maskPixels = new int[mask.width];
- for (int y = 0; y < imageData.height; y++) {
- source.getPixels(0, y, imageData.width, imagePixels, 0);
- mask.getPixels(0, y, mask.width, maskPixels, 0);
- for (int i = 0; i < imagePixels.length; i++) {
- if (maskPixels[i] == 0) imagePixels[i] = blackIndex;
- }
- imageData.setPixels(0, y, source.width, imagePixels, 0);
- }
- }
- imageData.maskPad = mask.scanlinePad;
- imageData.maskData = mask.data;
- return init(device, image, imageData);
-}
-void init(ImageData i) {
- if (i == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, this, i);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public int /*long*/ internal_new_GC (GCData data) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- /*
- * Create a new GC that can draw into the image.
- * Only supported for bitmaps.
- */
- if (type != SWT.BITMAP || memGC != null) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- /* Create a compatible HDC for the device */
- int /*long*/ hDC = device.internal_new_GC(null);
- int /*long*/ imageDC = OS.CreateCompatibleDC(hDC);
- device.internal_dispose_GC(hDC, null);
- if (imageDC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
-
- if (data != null) {
- /* Set the GCData fields */
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) != 0) {
- data.layout = (data.style & SWT.RIGHT_TO_LEFT) != 0 ? OS.LAYOUT_RTL : 0;
- } else {
- data.style |= SWT.LEFT_TO_RIGHT;
- }
- data.device = device;
- data.image = this;
- data.font = device.systemFont;
- }
- return imageDC;
-}
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int /*long*/ hDC, GCData data) {
- OS.DeleteDC(hDC);
-}
-
-/**
- * Returns <code>true</code> if the image has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the image.
- * When an image has been disposed, it is an error to
- * invoke any other method using the image.
- *
- * @return <code>true</code> when the image is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Sets the color to which to map the transparent pixel.
- * <p>
- * There are certain uses of <code>Images</code> that do not support
- * transparency (for example, setting an image into a button or label).
- * In these cases, it may be desired to simulate transparency by using
- * the background color of the widget to paint the transparent pixels
- * of the image. This method specifies the color that will be used in
- * these cases. For example:
- * <pre>
- * Button b = new Button();
- * image.setBackground(b.getBackground());
- * b.setImage(image);
- * </pre>
- * </p><p>
- * The image may be modified by this operation (in effect, the
- * transparent regions may be filled with the supplied color). Hence
- * this operation is not reversible and it is not legal to call
- * this function twice or with a null argument.
- * </p><p>
- * This method has no effect if the receiver does not have a transparent
- * pixel value.
- * </p>
- *
- * @param color the color to use when a transparent pixel is specified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setBackground(Color color) {
- /*
- * Note. Not implemented on WinCE.
- */
- if (OS.IsWinCE) return;
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (transparentPixel == -1) return;
- transparentColor = -1;
-
- /* Get the HDC for the device */
- int /*long*/ hDC = device.internal_new_GC(null);
-
- /* Change the background color in the image */
- BITMAP bm = new BITMAP();
- OS.GetObject(handle, BITMAP.sizeof, bm);
- int /*long*/ hdcMem = OS.CreateCompatibleDC(hDC);
- OS.SelectObject(hdcMem, handle);
- int maxColors = 1 << bm.bmBitsPixel;
- byte[] colors = new byte[maxColors * 4];
- if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- int numColors = OS.GetDIBColorTable(hdcMem, 0, maxColors, colors);
- int offset = transparentPixel * 4;
- colors[offset] = (byte)color.getBlue();
- colors[offset + 1] = (byte)color.getGreen();
- colors[offset + 2] = (byte)color.getRed();
- if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- OS.SetDIBColorTable(hdcMem, 0, numColors, colors);
- OS.DeleteDC(hdcMem);
-
- /* Release the HDC for the device */
- device.internal_dispose_GC(hDC, null);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Image {*DISPOSED*}";
- return "Image {" + handle + "}";
-}
-
-/**
- * Invokes platform specific functionality to allocate a new image.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param type the type of the image (<code>SWT.BITMAP</code> or <code>SWT.ICON</code>)
- * @param handle the OS handle for the image
- * @return a new image object containing the specified device, type and handle
- */
-public static Image win32_new(Device device, int type, int /*long*/ handle) {
- Image image = new Image(device);
- image.type = type;
- image.handle = handle;
- return image;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Path.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Path.java
deleted file mode 100644
index db666da42b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Path.java
+++ /dev/null
@@ -1,602 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gdip.*;
-import org.eclipse.swt.internal.win32.*;
-
-/**
- * Instances of this class represent paths through the two-dimensional
- * coordinate system. Paths do not have to be continuous, and can be
- * described using lines, rectangles, arcs, cubic or quadratic bezier curves,
- * glyphs, or other paths.
- * <p>
- * Application code must explicitly invoke the <code>Path.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#path">Path, Pattern snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Path extends Resource {
-
- /**
- * the OS resource for the Path
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
-
- PointF currentPoint = new PointF(), startPoint = new PointF();
-
-/**
- * Constructs a new empty Path.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the path
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Path (Device device) {
- super(device);
- this.device.checkGDIP();
- handle = Gdip.GraphicsPath_new(Gdip.FillModeAlternate);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new Path that is a copy of <code>path</code>. If
- * <code>flatness</code> is less than or equal to zero, an unflatten
- * copy of the path is created. Otherwise, it specifies the maximum
- * error between the path and its flatten copy. Smaller numbers give
- * better approximation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the path
- * @param path the path to make a copy
- * @param flatness the flatness value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the path is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the path has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- * @since 3.4
- */
-public Path (Device device, Path path, float flatness) {
- super(device);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- flatness = Math.max(0, flatness);
- handle = Gdip.GraphicsPath_Clone(path.handle);
- if (flatness != 0) Gdip.GraphicsPath_Flatten(handle, 0, flatness);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new Path with the specifed PathData.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the path
- * @param data the data for the path
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the data is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- * @since 3.4
- */
-public Path (Device device, PathData data) {
- this(device);
- if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(data);
-}
-
-/**
- * Adds to the receiver a circular or elliptical arc that lies within
- * the specified rectangular area.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc
- * @param y the y coordinate of the upper-left corner of the arc
- * @param width the width of the arc
- * @param height the height of the arc
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addArc(float x, float y, float width, float height, float startAngle, float arcAngle) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- if (width == height) {
- Gdip.GraphicsPath_AddArc(handle, x, y, width, height, -startAngle, -arcAngle);
- } else {
- int /*long*/ path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate);
- if (path == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ matrix = Gdip.Matrix_new(width, 0, 0, height, x, y);
- if (matrix == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Gdip.GraphicsPath_AddArc(path, 0, 0, 1, 1, -startAngle, -arcAngle);
- Gdip.GraphicsPath_Transform(path, matrix);
- Gdip.GraphicsPath_AddPath(handle, path, true);
- Gdip.Matrix_delete(matrix);
- Gdip.GraphicsPath_delete(path);
- }
- Gdip.GraphicsPath_GetLastPoint(handle, currentPoint);
-}
-
-/**
- * Adds to the receiver the path described by the parameter.
- *
- * @param path the path to add to the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addPath(Path path) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- //TODO - expose connect?
- Gdip.GraphicsPath_AddPath(handle, path.handle, false);
- currentPoint.X = path.currentPoint.X;
- currentPoint.Y = path.currentPoint.Y;
-}
-
-/**
- * Adds to the receiver the rectangle specified by x, y, width and height.
- *
- * @param x the x coordinate of the rectangle to add
- * @param y the y coordinate of the rectangle to add
- * @param width the width of the rectangle to add
- * @param height the height of the rectangle to add
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addRectangle(float x, float y, float width, float height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- RectF rect = new RectF();
- rect.X = x;
- rect.Y = y;
- rect.Width = width;
- rect.Height = height;
- Gdip.GraphicsPath_AddRectangle(handle, rect);
- currentPoint.X = x;
- currentPoint.Y = y;
-}
-
-/**
- * Adds to the receiver the pattern of glyphs generated by drawing
- * the given string using the given font starting at the point (x, y).
- *
- * @param string the text to use
- * @param x the x coordinate of the starting point
- * @param y the y coordinate of the starting point
- * @param font the font to use
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the font is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addString(String string, float x, float y, Font font) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (font == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int length = string.length();
- char[] buffer = new char[length];
- string.getChars(0, length, buffer, 0);
- int /*long*/ hDC = device.internal_new_GC(null);
- int /*long*/ [] family = new int /*long*/ [1];
- int /*long*/ gdipFont = GC.createGdipFont(hDC, font.handle, 0, device.fontCollection, family, null);
- PointF point = new PointF();
- point.X = x - (Gdip.Font_GetSize(gdipFont) / 6);
- point.Y = y;
- int style = Gdip.Font_GetStyle(gdipFont);
- float size = Gdip.Font_GetSize(gdipFont);
- Gdip.GraphicsPath_AddString(handle, buffer, length, family[0], style, size, point, 0);
- Gdip.GraphicsPath_GetLastPoint(handle, currentPoint);
- Gdip.FontFamily_delete(family[0]);
- Gdip.Font_delete(gdipFont);
- device.internal_dispose_GC(hDC, null);
-}
-
-/**
- * Closes the current sub path by adding to the receiver a line
- * from the current point of the path back to the starting point
- * of the sub path.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void close() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Gdip.GraphicsPath_CloseFigure(handle);
- /*
- * Feature in GDI+. CloseFigure() does affect the last
- * point, so GetLastPoint() does not return the starting
- * point of the subpath after calling CloseFigure(). The
- * fix is to remember the subpath starting point and use
- * it instead.
- */
- currentPoint.X = startPoint.X;
- currentPoint.Y = startPoint.Y;
-}
-
-/**
- * Returns <code>true</code> if the specified point is contained by
- * the receiver and false otherwise.
- * <p>
- * If outline is <code>true</code>, the point (x, y) checked for containment in
- * the receiver's outline. If outline is <code>false</code>, the point is
- * checked to see if it is contained within the bounds of the (closed) area
- * covered by the receiver.
- *
- * @param x the x coordinate of the point to test for containment
- * @param y the y coordinate of the point to test for containment
- * @param gc the GC to use when testing for containment
- * @param outline controls whether to check the outline or contained area of the path
- * @return <code>true</code> if the path contains the point and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains(float x, float y, GC gc, boolean outline) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- //TODO - should use GC transformation
- gc.initGdip();
- gc.checkGC(GC.LINE_CAP | GC.LINE_JOIN | GC.LINE_STYLE | GC.LINE_WIDTH);
- int mode = OS.GetPolyFillMode(gc.handle) == OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate;
- Gdip.GraphicsPath_SetFillMode(handle, mode);
- if (outline) {
- return Gdip.GraphicsPath_IsOutlineVisible(handle, x, y, gc.data.gdipPen, gc.data.gdipGraphics);
- } else {
- return Gdip.GraphicsPath_IsVisible(handle, x, y, gc.data.gdipGraphics);
- }
-}
-
-/**
- * Adds to the receiver a cubic bezier curve based on the parameters.
- *
- * @param cx1 the x coordinate of the first control point of the spline
- * @param cy1 the y coordinate of the first control of the spline
- * @param cx2 the x coordinate of the second control of the spline
- * @param cy2 the y coordinate of the second control of the spline
- * @param x the x coordinate of the end point of the spline
- * @param y the y coordinate of the end point of the spline
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Gdip.GraphicsPath_AddBezier(handle, currentPoint.X, currentPoint.Y, cx1, cy1, cx2, cy2, x, y);
- Gdip.GraphicsPath_GetLastPoint(handle, currentPoint);
-}
-
-void destroy() {
- Gdip.GraphicsPath_delete(handle);
- handle = 0;
-}
-
-/**
- * Replaces the first four elements in the parameter with values that
- * describe the smallest rectangle that will completely contain the
- * receiver (i.e. the bounding box).
- *
- * @param bounds the array to hold the result
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the bounding box</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getBounds(float[] bounds) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (bounds.length < 4) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- RectF rect = new RectF();
- Gdip.GraphicsPath_GetBounds(handle, rect, 0, 0);
- bounds[0] = rect.X;
- bounds[1] = rect.Y;
- bounds[2] = rect.Width;
- bounds[3] = rect.Height;
-}
-
-/**
- * Replaces the first two elements in the parameter with values that
- * describe the current point of the path.
- *
- * @param point the array to hold the result
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the end point</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getCurrentPoint(float[] point) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (point == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (point.length < 2) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- point[0] = currentPoint.X;
- point[1] = currentPoint.Y;
-}
-
-/**
- * Returns a device independent representation of the receiver.
- *
- * @return the PathData for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see PathData
- */
-public PathData getPathData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int count = Gdip.GraphicsPath_GetPointCount(handle);
- byte[] gdipTypes = new byte[count];
- float[] points = new float[count * 2];
- Gdip.GraphicsPath_GetPathTypes(handle, gdipTypes, count);
- Gdip.GraphicsPath_GetPathPoints(handle, points, count);
- byte[] types = new byte[count * 2];
- int index = 0, typesIndex = 0;
- while (index < count) {
- byte type = gdipTypes[index];
- boolean close = false;
- switch (type & Gdip.PathPointTypePathTypeMask) {
- case Gdip.PathPointTypeStart:
- types[typesIndex++] = SWT.PATH_MOVE_TO;
- close = (type & Gdip.PathPointTypeCloseSubpath) != 0;
- index += 1;
- break;
- case Gdip.PathPointTypeLine:
- types[typesIndex++] = SWT.PATH_LINE_TO;
- close = (type & Gdip.PathPointTypeCloseSubpath) != 0;
- index += 1;
- break;
- case Gdip.PathPointTypeBezier:
- types[typesIndex++] = SWT.PATH_CUBIC_TO;
- close = (gdipTypes[index + 2] & Gdip.PathPointTypeCloseSubpath) != 0;
- index += 3;
- break;
- default:
- index++;
- }
- if (close) {
- types[typesIndex++] = SWT.PATH_CLOSE;
- }
- }
- if (typesIndex != types.length) {
- byte[] newTypes = new byte[typesIndex];
- System.arraycopy(types, 0, newTypes, 0, typesIndex);
- types = newTypes;
- }
- PathData result = new PathData();
- result.types = types;
- result.points = points;
- return result;
-}
-
-/**
- * Adds to the receiver a line from the current point to
- * the point specified by (x, y).
- *
- * @param x the x coordinate of the end of the line to add
- * @param y the y coordinate of the end of the line to add
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void lineTo(float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Gdip.GraphicsPath_AddLine(handle, currentPoint.X, currentPoint.Y, x, y);
- Gdip.GraphicsPath_GetLastPoint(handle, currentPoint);
-}
-
-void init(PathData data) {
- byte[] types = data.types;
- float[] points = data.points;
- for (int i = 0, j = 0; i < types.length; i++) {
- switch (types[i]) {
- case SWT.PATH_MOVE_TO:
- moveTo(points[j++], points[j++]);
- break;
- case SWT.PATH_LINE_TO:
- lineTo(points[j++], points[j++]);
- break;
- case SWT.PATH_CUBIC_TO:
- cubicTo(points[j++], points[j++], points[j++], points[j++], points[j++], points[j++]);
- break;
- case SWT.PATH_QUAD_TO:
- quadTo(points[j++], points[j++], points[j++], points[j++]);
- break;
- case SWT.PATH_CLOSE:
- close();
- break;
- default:
- dispose();
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
-}
-
-/**
- * Returns <code>true</code> if the Path has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Path.
- * When a Path has been disposed, it is an error to
- * invoke any other method using the Path.
- *
- * @return <code>true</code> when the Path is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Sets the current point of the receiver to the point
- * specified by (x, y). Note that this starts a new
- * sub path.
- *
- * @param x the x coordinate of the new end point
- * @param y the y coordinate of the new end point
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void moveTo(float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Gdip.GraphicsPath_StartFigure(handle);
- currentPoint.X = startPoint.X = x;
- currentPoint.Y = startPoint.Y = y;
-}
-
-/**
- * Adds to the receiver a quadratic curve based on the parameters.
- *
- * @param cx the x coordinate of the control point of the spline
- * @param cy the y coordinate of the control point of the spline
- * @param x the x coordinate of the end point of the spline
- * @param y the y coordinate of the end point of the spline
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void quadTo(float cx, float cy, float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float cx1 = currentPoint.X + 2 * (cx - currentPoint.X) / 3;
- float cy1 = currentPoint.Y + 2 * (cy - currentPoint.Y) / 3;
- float cx2 = cx1 + (x - currentPoint.X) / 3;
- float cy2 = cy1 + (y - currentPoint.Y) / 3;
- Gdip.GraphicsPath_AddBezier(handle, currentPoint.X, currentPoint.Y, cx1, cy1, cx2, cy2, x, y);
- Gdip.GraphicsPath_GetLastPoint(handle, currentPoint);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString() {
- if (isDisposed()) return "Path {*DISPOSED*}";
- return "Path {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Pattern.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Pattern.java
deleted file mode 100644
index 406fcec965..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Pattern.java
+++ /dev/null
@@ -1,250 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gdip.*;
-import org.eclipse.swt.internal.win32.*;
-
-/**
- * Instances of this class represent patterns to use while drawing. Patterns
- * can be specified either as bitmaps or gradients.
- * <p>
- * Application code must explicitly invoke the <code>Pattern.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#path">Path, Pattern snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Pattern extends Resource {
-
- /**
- * the OS resource for the Pattern
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
-
-/**
- * Constructs a new Pattern given an image. Drawing with the resulting
- * pattern will cause the image to be tiled over the resulting area.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the pattern
- * @param image the image that the pattern will draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device, or the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Pattern(Device device, Image image) {
- super(device);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.device.checkGDIP();
- int /*long*/[] gdipImage = image.createGdipImage();
- int /*long*/ img = gdipImage[0];
- int width = Gdip.Image_GetWidth(img);
- int height = Gdip.Image_GetHeight(img);
- handle = Gdip.TextureBrush_new(img, Gdip.WrapModeTile, 0, 0, width, height);
- Gdip.Bitmap_delete(img);
- if (gdipImage[1] != 0) {
- int /*long*/ hHeap = OS.GetProcessHeap ();
- OS.HeapFree(hHeap, 0, gdipImage[1]);
- }
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new Pattern that represents a linear, two color
- * gradient. Drawing with the pattern will cause the resulting area to be
- * tiled with the gradient specified by the arguments.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the pattern
- * @param x1 the x coordinate of the starting corner of the gradient
- * @param y1 the y coordinate of the starting corner of the gradient
- * @param x2 the x coordinate of the ending corner of the gradient
- * @param y2 the y coordinate of the ending corner of the gradient
- * @param color1 the starting color of the gradient
- * @param color2 the ending color of the gradient
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device,
- * or if either color1 or color2 is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either color1 or color2 has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Pattern(Device device, float x1, float y1, float x2, float y2, Color color1, Color color2) {
- this(device, x1, y1, x2, y2, color1, 0xFF, color2, 0xFF);
-}
-
-/**
- * Constructs a new Pattern that represents a linear, two color
- * gradient. Drawing with the pattern will cause the resulting area to be
- * tiled with the gradient specified by the arguments.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the pattern
- * @param x1 the x coordinate of the starting corner of the gradient
- * @param y1 the y coordinate of the starting corner of the gradient
- * @param x2 the x coordinate of the ending corner of the gradient
- * @param y2 the y coordinate of the ending corner of the gradient
- * @param color1 the starting color of the gradient
- * @param alpha1 the starting alpha value of the gradient
- * @param color2 the ending color of the gradient
- * @param alpha2 the ending alpha value of the gradient
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device,
- * or if either color1 or color2 is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either color1 or color2 has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- *
- * @since 3.2
- */
-public Pattern(Device device, float x1, float y1, float x2, float y2, Color color1, int alpha1, Color color2, int alpha2) {
- super(device);
- if (color1 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color1.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (color2 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color2.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.device.checkGDIP();
- int colorRef1 = color1.handle;
- int rgb = ((colorRef1 >> 16) & 0xFF) | (colorRef1 & 0xFF00) | ((colorRef1 & 0xFF) << 16);
- int /*long*/ foreColor = Gdip.Color_new((alpha1 & 0xFF) << 24 | rgb);
- if (x1 == x2 && y1 == y2) {
- handle = Gdip.SolidBrush_new(foreColor);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- } else {
- int colorRef2 = color2.handle;
- rgb = ((colorRef2 >> 16) & 0xFF) | (colorRef2 & 0xFF00) | ((colorRef2 & 0xFF) << 16);
- int /*long*/ backColor = Gdip.Color_new((alpha2 & 0xFF) << 24 | rgb);
- PointF p1 = new PointF();
- p1.X = x1;
- p1.Y = y1;
- PointF p2 = new PointF();
- p2.X = x2;
- p2.Y = y2;
- handle = Gdip.LinearGradientBrush_new(p1, p2, foreColor, backColor);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (alpha1 != 0xFF || alpha2 != 0xFF) {
- int a = (int)((alpha1 & 0xFF) * 0.5f + (alpha2 & 0xFF) * 0.5f);
- int r = (int)(((colorRef1 & 0xFF) >> 0) * 0.5f + ((colorRef2 & 0xFF) >> 0) * 0.5f);
- int g = (int)(((colorRef1 & 0xFF00) >> 8) * 0.5f + ((colorRef2 & 0xFF00) >> 8) * 0.5f);
- int b = (int)(((colorRef1 & 0xFF0000) >> 16) * 0.5f + ((colorRef2 & 0xFF0000) >> 16) * 0.5f);
- int /*long*/ midColor = Gdip.Color_new(a << 24 | r << 16 | g << 8 | b);
- Gdip.LinearGradientBrush_SetInterpolationColors(handle, new int /*long*/ []{foreColor, midColor, backColor}, new float[]{0, 0.5f, 1}, 3);
- Gdip.Color_delete(midColor);
- }
- Gdip.Color_delete(backColor);
- }
- Gdip.Color_delete(foreColor);
- init();
-}
-
-void destroy() {
- int type = Gdip.Brush_GetType(handle);
- switch (type) {
- case Gdip.BrushTypeSolidColor:
- Gdip.SolidBrush_delete(handle);
- break;
- case Gdip.BrushTypeHatchFill:
- Gdip.HatchBrush_delete(handle);
- break;
- case Gdip.BrushTypeLinearGradient:
- Gdip.LinearGradientBrush_delete(handle);
- break;
- case Gdip.BrushTypeTextureFill:
- Gdip.TextureBrush_delete(handle);
- break;
- }
- handle = 0;
-}
-
-/**
- * Returns <code>true</code> if the Pattern has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Pattern.
- * When a Pattern has been disposed, it is an error to
- * invoke any other method using the Pattern.
- *
- * @return <code>true</code> when the Pattern is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString() {
- if (isDisposed()) return "Pattern {*DISPOSED*}";
- return "Pattern {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Region.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Region.java
deleted file mode 100755
index 5c6383328a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Region.java
+++ /dev/null
@@ -1,597 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class represent areas of an x-y coordinate
- * system that are aggregates of the areas covered by a number
- * of polygons.
- * <p>
- * Application code must explicitly invoke the <code>Region.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class Region extends Resource {
-
- /**
- * the OS resource for the region
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
-
-/**
- * Constructs a new empty region.
- *
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
- * </ul>
- */
-public Region () {
- this(null);
-}
-
-/**
- * Constructs a new empty region.
- * <p>
- * You must dispose the region when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the region
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
- * </ul>
- *
- * @see #dispose
- *
- * @since 3.0
- */
-public Region (Device device) {
- super(device);
- handle = OS.CreateRectRgn (0, 0, 0, 0);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new region given a handle to the operating
- * system resources that it should represent.
- *
- * @param handle the handle for the result
- */
-Region(Device device, int handle) {
- super(device);
- this.handle = handle;
-}
-
-/**
- * Adds the given polygon to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param pointArray points that describe the polygon to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
-*
- */
-public void add (int[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- int /*long*/ polyRgn = OS.CreatePolygonRgn(pointArray, pointArray.length / 2, OS.ALTERNATE);
- OS.CombineRgn (handle, handle, polyRgn, OS.RGN_OR);
- OS.DeleteObject (polyRgn);
-}
-
-/**
- * Adds the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void add (Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- add (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Adds the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void add (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int /*long*/ rectRgn = OS.CreateRectRgn (x, y, x + width, y + height);
- OS.CombineRgn (handle, handle, rectRgn, OS.RGN_OR);
- OS.DeleteObject (rectRgn);
-}
-
-/**
- * Adds all of the polygons which make up the area covered
- * by the argument to the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to merge
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void add (Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.CombineRgn (handle, handle, region.handle, OS.RGN_OR);
-}
-
-/**
- * Returns <code>true</code> if the point specified by the
- * arguments is inside the area specified by the receiver,
- * and <code>false</code> otherwise.
- *
- * @param x the x coordinate of the point to test for containment
- * @param y the y coordinate of the point to test for containment
- * @return <code>true</code> if the region contains the point and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains (int x, int y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return OS.PtInRegion (handle, x, y);
-}
-
-/**
- * Returns <code>true</code> if the given point is inside the
- * area specified by the receiver, and <code>false</code>
- * otherwise.
- *
- * @param pt the point to test for containment
- * @return <code>true</code> if the region contains the point and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains (Point pt) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return contains(pt.x, pt.y);
-}
-
-void destroy () {
- OS.DeleteObject(handle);
- handle = 0;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (this == object) return true;
- if (!(object instanceof Region)) return false;
- Region rgn = (Region)object;
- return handle == rgn.handle;
-}
-
-/**
- * Returns a rectangle which represents the rectangular
- * union of the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @return a bounding rectangle for the region
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#union
- */
-public Rectangle getBounds() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- RECT rect = new RECT();
- OS.GetRgnBox(handle, rect);
- return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return (int)/*64*/handle;
-}
-
-/**
- * Intersects the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to intersect with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void intersect (Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- intersect (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Intersects the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void intersect (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int /*long*/ rectRgn = OS.CreateRectRgn (x, y, x + width, y + height);
- OS.CombineRgn (handle, handle, rectRgn, OS.RGN_AND);
- OS.DeleteObject (rectRgn);
-}
-
-/**
- * Intersects all of the polygons which make up the area covered
- * by the argument to the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to intersect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void intersect (Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.CombineRgn (handle, handle, region.handle, OS.RGN_AND);
-}
-
-/**
- * Returns <code>true</code> if the rectangle described by the
- * arguments intersects with any of the polygons the receiver
- * maintains to describe its area, and <code>false</code> otherwise.
- *
- * @param x the x coordinate of the origin of the rectangle
- * @param y the y coordinate of the origin of the rectangle
- * @param width the width of the rectangle
- * @param height the height of the rectangle
- * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#intersects(Rectangle)
- */
-public boolean intersects (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- RECT r = new RECT ();
- OS.SetRect (r, x, y, x + width, y + height);
- return OS.RectInRegion (handle, r);
-}
-
-/**
- * Returns <code>true</code> if the given rectangle intersects
- * with any of the polygons the receiver maintains to describe
- * its area and <code>false</code> otherwise.
- *
- * @param rect the rectangle to test for intersection
- * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#intersects(Rectangle)
- */
-public boolean intersects (Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return intersects(rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Returns <code>true</code> if the region has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the region.
- * When a region has been disposed, it is an error to
- * invoke any other method using the region.
- *
- * @return <code>true</code> when the region is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns <code>true</code> if the receiver does not cover any
- * area in the (x, y) coordinate plane, and <code>false</code> if
- * the receiver does cover some area in the plane.
- *
- * @return <code>true</code> if the receiver is empty, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean isEmpty () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- RECT rect = new RECT ();
- int result = OS.GetRgnBox (handle, rect);
- if (result == OS.NULLREGION) return true;
- return ((rect.right - rect.left) <= 0) || ((rect.bottom - rect.top) <= 0);
-}
-
-/**
- * Subtracts the given polygon from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param pointArray points that describe the polygon to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract (int[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- int /*long*/ polyRgn = OS.CreatePolygonRgn(pointArray, pointArray.length / 2, OS.ALTERNATE);
- OS.CombineRgn (handle, handle, polyRgn, OS.RGN_DIFF);
- OS.DeleteObject (polyRgn);
-}
-
-/**
- * Subtracts the given rectangle from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to subtract from the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract (Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- subtract (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Subtracts the given rectangle from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void subtract (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int /*long*/ rectRgn = OS.CreateRectRgn (x, y, x + width, y + height);
- OS.CombineRgn (handle, handle, rectRgn, OS.RGN_DIFF);
- OS.DeleteObject (rectRgn);
-}
-
-/**
- * Subtracts all of the polygons which make up the area covered
- * by the argument from the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to subtract
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract (Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.CombineRgn (handle, handle, region.handle, OS.RGN_DIFF);
-}
-
-/**
- * Translate all of the polygons the receiver maintains to describe
- * its area by the specified point.
- *
- * @param x the x coordinate of the point to translate
- * @param y the y coordinate of the point to translate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void translate (int x, int y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.OffsetRgn (handle, x, y);
-}
-
-/**
- * Translate all of the polygons the receiver maintains to describe
- * its area by the specified point.
- *
- * @param pt the point to translate
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void translate (Point pt) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- translate (pt.x, pt.y);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Region {*DISPOSED*}";
- return "Region {" + handle + "}";
-}
-
-/**
- * Invokes platform specific functionality to allocate a new region.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Region</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the region
- * @param handle the handle for the region
- * @return a new region object containing the specified device and handle
- */
-public static Region win32_new(Device device, int handle) {
- return new Region(device, handle);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java
deleted file mode 100644
index d4701a120f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java
+++ /dev/null
@@ -1,3328 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gdip.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-
-/**
- * <code>TextLayout</code> is a graphic object that represents
- * styled text.
- * <p>
- * Instances of this class provide support for drawing, cursor
- * navigation, hit testing, text wrapping, alignment, tab expansion
- * line breaking, etc. These are aspects required for rendering internationalized text.
- * </p><p>
- * Application code must explicitly invoke the <code>TextLayout#dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#textlayout">TextLayout, TextStyle snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: CustomControlExample, StyledText tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.0
- */
-public final class TextLayout extends Resource {
- Font font;
- String text, segmentsText;
- int lineSpacing;
- int ascent, descent;
- int alignment;
- int wrapWidth;
- int orientation;
- int indent;
- boolean justify;
- int[] tabs;
- int[] segments;
- StyleItem[] styles;
- int stylesCount;
-
- StyleItem[] allRuns;
- StyleItem[][] runs;
- int[] lineOffset, lineY, lineWidth;
- int /*long*/ mLangFontLink2;
-
- static final char LTR_MARK = '\u200E', RTL_MARK = '\u200F';
- static final int SCRIPT_VISATTR_SIZEOF = 2;
- static final int GOFFSET_SIZEOF = 8;
- static final byte[] CLSID_CMultiLanguage = new byte[16];
- static final byte[] IID_IMLangFontLink2 = new byte[16];
- static {
- OS.IIDFromString("{275c23e2-3747-11d0-9fea-00aa003f8646}\0".toCharArray(), CLSID_CMultiLanguage);
- OS.IIDFromString("{DCCFC162-2B38-11d2-B7EC-00C04F8F5D9A}\0".toCharArray(), IID_IMLangFontLink2);
- }
-
- static final int MERGE_MAX = 512;
- static final int TOO_MANY_RUNS = 1024;
-
- /* IME has a copy of these constants */
- static final int UNDERLINE_IME_DOT = 1 << 16;
- static final int UNDERLINE_IME_DASH = 2 << 16;
- static final int UNDERLINE_IME_THICK = 3 << 16;
-
- class StyleItem {
- TextStyle style;
- int start, length;
- boolean lineBreak, softBreak, tab;
-
- /*Script cache and analysis */
- SCRIPT_ANALYSIS analysis;
- int /*long*/ psc = 0;
-
- /*Shape info (malloc when the run is shaped) */
- int /*long*/ glyphs;
- int glyphCount;
- int /*long*/ clusters;
- int /*long*/ visAttrs;
-
- /*Place info (malloc when the run is placed) */
- int /*long*/ advances;
- int /*long*/ goffsets;
- int width;
- int ascent;
- int descent;
- int leading;
- int x;
- int underlinePos, underlineThickness;
- int strikeoutPos, strikeoutThickness;
-
- /* Justify info (malloc during computeRuns) */
- int /*long*/ justify;
-
- /* ScriptBreak */
- int /*long*/ psla;
-
- int /*long*/ fallbackFont;
-
- void free() {
- int /*long*/ hHeap = OS.GetProcessHeap();
- if (psc != 0) {
- OS.ScriptFreeCache (psc);
- OS.HeapFree(hHeap, 0, psc);
- psc = 0;
- }
- if (glyphs != 0) {
- OS.HeapFree(hHeap, 0, glyphs);
- glyphs = 0;
- glyphCount = 0;
- }
- if (clusters != 0) {
- OS.HeapFree(hHeap, 0, clusters);
- clusters = 0;
- }
- if (visAttrs != 0) {
- OS.HeapFree(hHeap, 0, visAttrs);
- visAttrs = 0;
- }
- if (advances != 0) {
- OS.HeapFree(hHeap, 0, advances);
- advances = 0;
- }
- if (goffsets != 0) {
- OS.HeapFree(hHeap, 0, goffsets);
- goffsets = 0;
- }
- if (justify != 0) {
- OS.HeapFree(hHeap, 0, justify);
- justify = 0;
- }
- if (psla != 0) {
- OS.HeapFree(hHeap, 0, psla);
- psla = 0;
- }
- if (fallbackFont != 0) {
- OS.DeleteObject(fallbackFont);
- fallbackFont = 0;
- }
- width = ascent = descent = x = 0;
- lineBreak = softBreak = false;
- }
- public String toString () {
- return "StyleItem {" + start + ", " + style + "}";
- }
- }
-
-/**
- * Constructs a new instance of this class on the given device.
- * <p>
- * You must dispose the text layout when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the text layout
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- *
- * @see #dispose()
- */
-public TextLayout (Device device) {
- super(device);
- wrapWidth = ascent = descent = -1;
- lineSpacing = 0;
- orientation = SWT.LEFT_TO_RIGHT;
- styles = new StyleItem[2];
- styles[0] = new StyleItem();
- styles[1] = new StyleItem();
- stylesCount = 2;
- text = ""; //$NON-NLS-1$
- int /*long*/[] ppv = new int /*long*/[1];
- OS.OleInitialize(0);
- if (OS.CoCreateInstance(CLSID_CMultiLanguage, 0, OS.CLSCTX_INPROC_SERVER, IID_IMLangFontLink2, ppv) == OS.S_OK) {
- mLangFontLink2 = ppv[0];
- }
- init();
-}
-
-RECT addClipRect(StyleItem run, RECT clipRect, RECT rect, int selectionStart, int selectionEnd) {
- if (rect != null) {
- if (clipRect == null) {
- clipRect = new RECT ();
- OS.SetRect(clipRect, -1, rect.top, -1, rect.bottom);
- }
- boolean isRTL = (orientation & SWT.RIGHT_TO_LEFT) != 0;
- if (run.start <= selectionStart && selectionStart <= run.start + run.length) {
- if (run.analysis.fRTL ^ isRTL) {
- clipRect.right = rect.left;
- } else {
- clipRect.left = rect.left;
- }
- }
- if (run.start <= selectionEnd && selectionEnd <= run.start + run.length) {
- if (run.analysis.fRTL ^ isRTL) {
- clipRect.left = rect.right;
- } else {
- clipRect.right = rect.right;
- }
- }
- }
- return clipRect;
-}
-
-void breakRun(StyleItem run) {
- if (run.psla != 0) return;
- char[] chars = new char[run.length];
- segmentsText.getChars(run.start, run.start + run.length, chars, 0);
- int /*long*/ hHeap = OS.GetProcessHeap();
- run.psla = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, SCRIPT_LOGATTR.sizeof * chars.length);
- if (run.psla == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.ScriptBreak(chars, chars.length, run.analysis, run.psla);
-}
-
-void checkLayout () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-/*
-* Compute the runs: itemize, shape, place, and reorder the runs.
-* Break paragraphs into lines, wraps the text, and initialize caches.
-*/
-void computeRuns (GC gc) {
- if (runs != null) return;
- int /*long*/ hDC = gc != null ? gc.handle : device.internal_new_GC(null);
- int /*long*/ srcHdc = OS.CreateCompatibleDC(hDC);
- allRuns = itemize();
- for (int i=0; i<allRuns.length - 1; i++) {
- StyleItem run = allRuns[i];
- OS.SelectObject(srcHdc, getItemFont(run));
- shape(srcHdc, run);
- }
- SCRIPT_LOGATTR logAttr = new SCRIPT_LOGATTR();
- SCRIPT_PROPERTIES properties = new SCRIPT_PROPERTIES();
- int lineWidth = indent, lineStart = 0, lineCount = 1;
- for (int i=0; i<allRuns.length - 1; i++) {
- StyleItem run = allRuns[i];
- if (tabs != null && run.tab) {
- int tabsLength = tabs.length, j;
- for (j = 0; j < tabsLength; j++) {
- if (tabs[j] > lineWidth) {
- run.width = tabs[j] - lineWidth;
- break;
- }
- }
- if (j == tabsLength) {
- int tabX = tabs[tabsLength-1];
- int lastTabWidth = tabsLength > 1 ? tabs[tabsLength-1] - tabs[tabsLength-2] : tabs[0];
- if (lastTabWidth > 0) {
- while (tabX <= lineWidth) tabX += lastTabWidth;
- run.width = tabX - lineWidth;
- }
- }
- int length = run.length;
- if (length > 1) {
- int stop = j + length - 1;
- if (stop < tabsLength) {
- run.width += tabs[stop] - tabs[j];
- } else {
- if (j < tabsLength) {
- run.width += tabs[tabsLength - 1] - tabs[j];
- length -= (tabsLength - 1) - j;
- }
- int lastTabWidth = tabsLength > 1 ? tabs[tabsLength-1] - tabs[tabsLength-2] : tabs[0];
- run.width += lastTabWidth * (length - 1);
- }
- }
- }
- if (wrapWidth != -1 && lineWidth + run.width > wrapWidth && !run.tab) {
- int start = 0;
- int[] piDx = new int[run.length];
- if (run.style != null && run.style.metrics != null) {
- piDx[0] = run.width;
- } else {
- OS.ScriptGetLogicalWidths(run.analysis, run.length, run.glyphCount, run.advances, run.clusters, run.visAttrs, piDx);
- }
- int width = 0, maxWidth = wrapWidth - lineWidth;
- while (width + piDx[start] < maxWidth) {
- width += piDx[start++];
- }
- int firstStart = start;
- int firstIndice = i;
- while (i >= lineStart) {
- breakRun(run);
- while (start >= 0) {
- OS.MoveMemory(logAttr, run.psla + (start * SCRIPT_LOGATTR.sizeof), SCRIPT_LOGATTR.sizeof);
- if (logAttr.fSoftBreak || logAttr.fWhiteSpace) break;
- start--;
- }
-
- /*
- * Bug in Windows. For some reason Uniscribe sets the fSoftBreak flag for the first letter
- * after a letter with an accent. This cause a break line to be set in the middle of a word.
- * The fix is to detect the case and ignore fSoftBreak forcing the algorithm keep searching.
- */
- if (start == 0 && i != lineStart && !run.tab) {
- if (logAttr.fSoftBreak && !logAttr.fWhiteSpace) {
- OS.MoveMemory(properties, device.scripts[run.analysis.eScript], SCRIPT_PROPERTIES.sizeof);
- int langID = properties.langid;
- StyleItem pRun = allRuns[i - 1];
- OS.MoveMemory(properties, device.scripts[pRun.analysis.eScript], SCRIPT_PROPERTIES.sizeof);
- if (properties.langid == langID || langID == OS.LANG_NEUTRAL || properties.langid == OS.LANG_NEUTRAL) {
- breakRun(pRun);
- OS.MoveMemory(logAttr, pRun.psla + ((pRun.length - 1) * SCRIPT_LOGATTR.sizeof), SCRIPT_LOGATTR.sizeof);
- if (!logAttr.fWhiteSpace) start = -1;
- }
- }
- }
- if (start >= 0 || i == lineStart) break;
- run = allRuns[--i];
- start = run.length - 1;
- }
- if (start == 0 && i != lineStart && !run.tab) {
- run = allRuns[--i];
- } else if (start <= 0 && i == lineStart) {
- if (lineWidth == wrapWidth && firstIndice > 0) {
- i = firstIndice - 1;
- run = allRuns[i];
- start = run.length;
- } else {
- i = firstIndice;
- run = allRuns[i];
- start = Math.max(1, firstStart);
- }
- }
- breakRun(run);
- while (start < run.length) {
- OS.MoveMemory(logAttr, run.psla + (start * SCRIPT_LOGATTR.sizeof), SCRIPT_LOGATTR.sizeof);
- if (!logAttr.fWhiteSpace) break;
- start++;
- }
- if (0 < start && start < run.length) {
- StyleItem newRun = new StyleItem();
- newRun.start = run.start + start;
- newRun.length = run.length - start;
- newRun.style = run.style;
- newRun.analysis = cloneScriptAnalysis(run.analysis);
- run.free();
- run.length = start;
- OS.SelectObject(srcHdc, getItemFont(run));
- run.analysis.fNoGlyphIndex = false;
- shape (srcHdc, run);
- OS.SelectObject(srcHdc, getItemFont(newRun));
- newRun.analysis.fNoGlyphIndex = false;
- shape (srcHdc, newRun);
- StyleItem[] newAllRuns = new StyleItem[allRuns.length + 1];
- System.arraycopy(allRuns, 0, newAllRuns, 0, i + 1);
- System.arraycopy(allRuns, i + 1, newAllRuns, i + 2, allRuns.length - i - 1);
- allRuns = newAllRuns;
- allRuns[i + 1] = newRun;
- }
- if (i != allRuns.length - 2) {
- run.softBreak = run.lineBreak = true;
- }
- }
- lineWidth += run.width;
- if (run.lineBreak) {
- lineStart = i + 1;
- lineWidth = run.softBreak ? 0 : indent;
- lineCount++;
- }
- }
- lineWidth = 0;
- runs = new StyleItem[lineCount][];
- lineOffset = new int[lineCount + 1];
- lineY = new int[lineCount + 1];
- this.lineWidth = new int[lineCount];
- int lineRunCount = 0, line = 0;
- int ascent = Math.max(0, this.ascent);
- int descent = Math.max(0, this.descent);
- StyleItem[] lineRuns = new StyleItem[allRuns.length];
- for (int i=0; i<allRuns.length; i++) {
- StyleItem run = allRuns[i];
- lineRuns[lineRunCount++] = run;
- lineWidth += run.width;
- ascent = Math.max(ascent, run.ascent);
- descent = Math.max(descent, run.descent);
- if (run.lineBreak || i == allRuns.length - 1) {
- /* Update the run metrics if the last run is a hard break. */
- if (lineRunCount == 1 && (i == allRuns.length - 1 || !run.softBreak)) {
- TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA();
- OS.SelectObject(srcHdc, getItemFont(run));
- OS.GetTextMetrics(srcHdc, lptm);
- run.ascent = lptm.tmAscent;
- run.descent = lptm.tmDescent;
- ascent = Math.max(ascent, run.ascent);
- descent = Math.max(descent, run.descent);
- }
- runs[line] = new StyleItem[lineRunCount];
- System.arraycopy(lineRuns, 0, runs[line], 0, lineRunCount);
-
- if (justify && wrapWidth != -1 && run.softBreak && lineWidth > 0) {
- if (line == 0) {
- lineWidth += indent;
- } else {
- StyleItem[] previousLine = runs[line - 1];
- StyleItem previousRun = previousLine[previousLine.length - 1];
- if (previousRun.lineBreak && !previousRun.softBreak) {
- lineWidth += indent;
- }
- }
- int /*long*/ hHeap = OS.GetProcessHeap();
- int newLineWidth = 0;
- for (int j = 0; j < runs[line].length; j++) {
- StyleItem item = runs[line][j];
- int iDx = item.width * wrapWidth / lineWidth;
- if (iDx != item.width) {
- item.justify = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, item.glyphCount * 4);
- if (item.justify == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.ScriptJustify(item.visAttrs, item.advances, item.glyphCount, iDx - item.width, 2, item.justify);
- item.width = iDx;
- }
- newLineWidth += item.width;
- }
- lineWidth = newLineWidth;
- }
- this.lineWidth[line] = lineWidth;
-
- StyleItem lastRun = runs[line][lineRunCount - 1];
- int lastOffset = lastRun.start + lastRun.length;
- runs[line] = reorder(runs[line], i == allRuns.length - 1);
- lastRun = runs[line][lineRunCount - 1];
- if (run.softBreak && run != lastRun) {
- run.softBreak = run.lineBreak = false;
- lastRun.softBreak = lastRun.lineBreak = true;
- }
-
- lineWidth = getLineIndent(line);
- for (int j = 0; j < runs[line].length; j++) {
- runs[line][j].x = lineWidth;
- lineWidth += runs[line][j].width;
- }
- line++;
- lineY[line] = lineY[line - 1] + ascent + descent + lineSpacing;
- lineOffset[line] = lastOffset;
- lineRunCount = lineWidth = 0;
- ascent = Math.max(0, this.ascent);
- descent = Math.max(0, this.descent);
- }
- }
- if (srcHdc != 0) OS.DeleteDC(srcHdc);
- if (gc == null) device.internal_dispose_GC(hDC, null);
-}
-
-void destroy () {
- freeRuns();
- font = null;
- text = null;
- segmentsText = null;
- tabs = null;
- styles = null;
- runs = null;
- lineOffset = null;
- lineY = null;
- lineWidth = null;
- if (mLangFontLink2 != 0) {
- /* Release() */
- OS.VtblCall(2, mLangFontLink2);
- mLangFontLink2 = 0;
- }
- OS.OleUninitialize();
-}
-
-SCRIPT_ANALYSIS cloneScriptAnalysis (SCRIPT_ANALYSIS src) {
- SCRIPT_ANALYSIS dst = new SCRIPT_ANALYSIS();
- dst.eScript = src.eScript;
- dst.fRTL = src.fRTL;
- dst.fLayoutRTL = src.fLayoutRTL;
- dst.fLinkBefore = src.fLinkBefore;
- dst.fLinkAfter = src.fLinkAfter;
- dst.fLogicalOrder = src.fLogicalOrder;
- dst.fNoGlyphIndex = src.fNoGlyphIndex;
- dst.s = new SCRIPT_STATE();
- dst.s.uBidiLevel = src.s.uBidiLevel;
- dst.s.fOverrideDirection = src.s.fOverrideDirection;
- dst.s.fInhibitSymSwap = src.s.fInhibitSymSwap;
- dst.s.fCharShape = src.s.fCharShape;
- dst.s.fDigitSubstitute = src.s.fDigitSubstitute;
- dst.s.fInhibitLigate = src.s.fInhibitLigate;
- dst.s.fDisplayZWG = src.s.fDisplayZWG;
- dst.s.fArabicNumContext = src.s.fArabicNumContext;
- dst.s.fGcpClusters = src.s.fGcpClusters;
- dst.s.fReserved = src.s.fReserved;
- dst.s.fEngineReserved = src.s.fEngineReserved;
- return dst;
-}
-
-int[] computePolyline(int left, int top, int right, int bottom) {
- int height = bottom - top; // can be any number
- int width = 2 * height; // must be even
- int peaks = Compatibility.ceil(right - left, width);
- if (peaks == 0 && right - left > 2) {
- peaks = 1;
- }
- int length = ((2 * peaks) + 1) * 2;
- if (length < 0) return new int[0];
-
- int[] coordinates = new int[length];
- for (int i = 0; i < peaks; i++) {
- int index = 4 * i;
- coordinates[index] = left + (width * i);
- coordinates[index+1] = bottom;
- coordinates[index+2] = coordinates[index] + width / 2;
- coordinates[index+3] = top;
- }
- coordinates[length-2] = left + (width * peaks);
- coordinates[length-1] = bottom;
- return coordinates;
-}
-
-int /*long*/ createGdipBrush(int pixel, int alpha) {
- int argb = ((alpha & 0xFF) << 24) | ((pixel >> 16) & 0xFF) | (pixel & 0xFF00) | ((pixel & 0xFF) << 16);
- int /*long*/ gdiColor = Gdip.Color_new(argb);
- int /*long*/ brush = Gdip.SolidBrush_new(gdiColor);
- Gdip.Color_delete(gdiColor);
- return brush;
-}
-
-int /*long*/ createGdipBrush(Color color, int alpha) {
- return createGdipBrush(color.handle, alpha);
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- *
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- */
-public void draw (GC gc, int x, int y) {
- draw(gc, x, y, -1, -1, null, null);
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- *
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param selectionStart the offset where the selections starts, or -1 indicating no selection
- * @param selectionEnd the offset where the selections ends, or -1 indicating no selection
- * @param selectionForeground selection foreground, or NULL to use the system default color
- * @param selectionBackground selection background, or NULL to use the system default color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- */
-public void draw (GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground) {
- draw(gc, x, y, selectionStart, selectionEnd, selectionForeground, selectionBackground, 0);
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- * <p>
- * The parameter <code>flags</code> can include one of <code>SWT.DELIMITER_SELECTION</code>
- * or <code>SWT.FULL_SELECTION</code> to specify the selection behavior on all lines except
- * for the last line, and can also include <code>SWT.LAST_LINE_SELECTION</code> to extend
- * the specified selection behavior to the last line.
- * </p>
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param selectionStart the offset where the selections starts, or -1 indicating no selection
- * @param selectionEnd the offset where the selections ends, or -1 indicating no selection
- * @param selectionForeground selection foreground, or NULL to use the system default color
- * @param selectionBackground selection background, or NULL to use the system default color
- * @param flags drawing options
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- *
- * @since 3.3
- */
-public void draw (GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags) {
- checkLayout();
- computeRuns(gc);
- if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (selectionForeground != null && selectionForeground.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (selectionBackground != null && selectionBackground.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int length = text.length();
- if (length == 0 && flags == 0) return;
- int /*long*/ hdc = gc.handle;
- Rectangle clip = gc.getClipping();
- GCData data = gc.data;
- int /*long*/ gdipGraphics = data.gdipGraphics;
- int foreground = data.foreground;
- int linkColor = OS.GetSysColor (OS.COLOR_HOTLIGHT);
- int alpha = data.alpha;
- boolean gdip = gdipGraphics != 0;
- int /*long*/ gdipForeground = 0;
- int /*long*/ gdipLinkColor = 0;
- int state = 0;
- if (gdip) {
- gc.checkGC(GC.FOREGROUND);
- gdipForeground = gc.getFgBrush();
- } else {
- state = OS.SaveDC(hdc);
- if ((data.style & SWT.MIRRORED) != 0) {
- OS.SetLayout(hdc, OS.GetLayout(hdc) | OS.LAYOUT_RTL);
- }
- }
- boolean hasSelection = selectionStart <= selectionEnd && selectionStart != -1 && selectionEnd != -1;
- int /*long*/ gdipSelBackground = 0, gdipSelForeground = 0, gdipFont = 0, lastHFont = 0;
- int /*long*/ selBackground = 0;
- int selForeground = 0;
- if (hasSelection || (flags & SWT.LAST_LINE_SELECTION) != 0) {
- int fgSel = selectionForeground != null ? selectionForeground.handle : OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT);
- int bgSel = selectionBackground != null ? selectionBackground.handle : OS.GetSysColor (OS.COLOR_HIGHLIGHT);
- if (gdip) {
- gdipSelBackground = createGdipBrush(bgSel, alpha);
- gdipSelForeground = createGdipBrush(fgSel, alpha);
- } else {
- selBackground = OS.CreateSolidBrush(bgSel);
- selForeground = fgSel;
- }
- if (hasSelection) {
- selectionStart = translateOffset(Math.min(Math.max(0, selectionStart), length - 1));
- selectionEnd = translateOffset(Math.min(Math.max(0, selectionEnd), length - 1));
- }
- }
- RECT rect = new RECT();
- OS.SetBkMode(hdc, OS.TRANSPARENT);
- for (int line=0; line<runs.length; line++) {
- int drawX = x + getLineIndent(line);
- int drawY = y + lineY[line];
- StyleItem[] lineRuns = runs[line];
- int lineHeight = lineY[line+1] - lineY[line] - lineSpacing;
-
- //Draw last line selection
- if (flags != 0 && (hasSelection || (flags & SWT.LAST_LINE_SELECTION) != 0)) {
- boolean extents = false;
- if (line == runs.length - 1 && (flags & SWT.LAST_LINE_SELECTION) != 0) {
- extents = true;
- } else {
- StyleItem run = lineRuns[lineRuns.length - 1];
- if (run.lineBreak && !run.softBreak) {
- if (selectionStart <= run.start && run.start <= selectionEnd) extents = true;
- } else {
- int endOffset = run.start + run.length - 1;
- if (selectionStart <= endOffset && endOffset < selectionEnd && (flags & SWT.FULL_SELECTION) != 0) {
- extents = true;
- }
- }
- }
- if (extents) {
- int width;
- if ((flags & SWT.FULL_SELECTION) != 0) {
- width = OS.IsWin95 ? 0x7FFF : 0x6FFFFFF;
- } else {
- width = lineHeight / 3;
- }
- if (gdip) {
- Gdip.Graphics_FillRectangle(gdipGraphics, gdipSelBackground, drawX + lineWidth[line], drawY, width, lineHeight);
- } else {
- OS.SelectObject(hdc, selBackground);
- OS.PatBlt(hdc, drawX + lineWidth[line], drawY, width, lineHeight, OS.PATCOPY);
- }
- }
- }
- if (drawX > clip.x + clip.width) continue;
- if (drawX + lineWidth[line] < clip.x) continue;
-
- //Draw the background of the runs in the line
- int alignmentX = drawX;
- for (int i = 0; i < lineRuns.length; i++) {
- StyleItem run = lineRuns[i];
- if (run.length == 0) continue;
- if (drawX > clip.x + clip.width) break;
- if (drawX + run.width >= clip.x) {
- if (!run.lineBreak || run.softBreak) {
- OS.SetRect(rect, drawX, drawY, drawX + run.width, drawY + lineHeight);
- if (gdip) {
- drawRunBackgroundGDIP(run, gdipGraphics, rect, selectionStart, selectionEnd, alpha, gdipSelBackground, hasSelection);
- } else {
- drawRunBackground(run, hdc, rect, selectionStart, selectionEnd, selBackground, hasSelection);
- }
- }
- }
- drawX += run.width;
- }
-
- //Draw the text, underline, strikeout, and border of the runs in the line
- int baseline = Math.max(0, this.ascent);
- int lineUnderlinePos = 0;
- for (int i = 0; i < lineRuns.length; i++) {
- baseline = Math.max(baseline, lineRuns[i].ascent);
- lineUnderlinePos = Math.min(lineUnderlinePos, lineRuns[i].underlinePos);
- }
- RECT borderClip = null, underlineClip = null, strikeoutClip = null, pRect = null;
- drawX = alignmentX;
- for (int i = 0; i < lineRuns.length; i++) {
- StyleItem run = lineRuns[i];
- TextStyle style = run.style;
- boolean hasAdorners = style != null && (style.underline || style.strikeout || style.borderStyle != SWT.NONE);
- if (run.length == 0) continue;
- if (drawX > clip.x + clip.width && !hasAdorners) break;
- if (drawX + run.width >= clip.x || hasAdorners) {
- boolean skipTab = run.tab && !hasAdorners;
- if (!skipTab && (!run.lineBreak || run.softBreak) && !(style != null && style.metrics != null)) {
- OS.SetRect(rect, drawX, drawY, drawX + run.width, drawY + lineHeight);
- if (gdip) {
- int /*long*/ hFont = getItemFont(run);
- if (hFont != lastHFont) {
- lastHFont = hFont;
- if (gdipFont != 0) Gdip.Font_delete(gdipFont);
- gdipFont = Gdip.Font_new(hdc, hFont);
- if (gdipFont == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (!Gdip.Font_IsAvailable(gdipFont)) {
- Gdip.Font_delete(gdipFont);
- gdipFont = 0;
- }
- }
- int /*long*/ gdipFg = gdipForeground;
- if (style != null && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK) {
- if (gdipLinkColor == 0) gdipLinkColor = createGdipBrush(linkColor, alpha);
- gdipFg = gdipLinkColor;
- }
- if (gdipFont != 0) {
- pRect = drawRunTextGDIP(gdipGraphics, run, rect, gdipFont, baseline, gdipFg, gdipSelForeground, selectionStart, selectionEnd, alpha);
- } else {
- int fg = style != null && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK ? linkColor : foreground;
- pRect = drawRunTextGDIPRaster(gdipGraphics, run, rect, baseline, fg, selForeground, selectionStart, selectionEnd);
- }
- underlineClip = drawUnderlineGDIP(gdipGraphics, x, drawY + baseline, lineUnderlinePos, drawY + lineHeight, lineRuns, i, gdipFg, gdipSelForeground, underlineClip, pRect, selectionStart, selectionEnd, alpha);
- strikeoutClip = drawStrikeoutGDIP(gdipGraphics, x, drawY + baseline, lineRuns, i, gdipFg, gdipSelForeground, strikeoutClip, pRect, selectionStart, selectionEnd, alpha);
- borderClip = drawBorderGDIP(gdipGraphics, x, drawY, lineHeight, lineRuns, i, gdipFg, gdipSelForeground, borderClip, pRect, selectionStart, selectionEnd, alpha);
- } else {
- int fg = style != null && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK ? linkColor : foreground;
- pRect = drawRunText(hdc, run, rect, baseline, fg, selForeground, selectionStart, selectionEnd);
- underlineClip = drawUnderline(hdc, x, drawY + baseline, lineUnderlinePos, drawY + lineHeight, lineRuns, i, fg, selForeground, underlineClip, pRect, selectionStart, selectionEnd);
- strikeoutClip = drawStrikeout(hdc, x, drawY + baseline, lineRuns, i, fg, selForeground, strikeoutClip, pRect, selectionStart, selectionEnd);
- borderClip = drawBorder(hdc, x, drawY, lineHeight, lineRuns, i, fg, selForeground, borderClip, pRect, selectionStart, selectionEnd);
- }
- }
- }
- drawX += run.width;
- }
- }
- if (gdipSelBackground != 0) Gdip.SolidBrush_delete(gdipSelBackground);
- if (gdipSelForeground != 0) Gdip.SolidBrush_delete(gdipSelForeground);
- if (gdipLinkColor != 0) Gdip.SolidBrush_delete(gdipLinkColor);
- if (gdipFont != 0) Gdip.Font_delete(gdipFont);
- if (state != 0) OS.RestoreDC(hdc, state);
- if (selBackground != 0) OS.DeleteObject (selBackground);
-}
-
-RECT drawBorder(int /*long*/ hdc, int x, int y, int lineHeight, StyleItem[] line, int index, int color, int selectionColor, RECT clipRect, RECT pRect, int selectionStart, int selectionEnd) {
- StyleItem run = line[index];
- TextStyle style = run.style;
- if (style == null) return null;
- if (style.borderStyle == SWT.NONE) return null;
- clipRect = addClipRect(run, clipRect, pRect, selectionStart, selectionEnd);
- if (index + 1 >= line.length || !style.isAdherentBorder(line[index + 1].style)) {
- int left = run.x;
- int start = run.start;
- int end = run.start + run.length - 1;
- for (int i = index; i > 0 && style.isAdherentBorder(line[i - 1].style); i--) {
- left = line[i - 1].x;
- start = Math.min(start, line[i - 1].start);
- end = Math.max(end, line[i - 1].start + line[i - 1].length - 1);
- }
- boolean hasSelection = selectionStart <= selectionEnd && selectionStart != -1 && selectionEnd != -1;
- boolean fullSelection = hasSelection && selectionStart <= start && end <= selectionEnd;
- if (style.borderColor != null) {
- color = style.borderColor.handle;
- clipRect = null;
- } else {
- if (fullSelection) {
- color = selectionColor;
- clipRect = null;
- } else {
- if (style.foreground != null) {
- color = style.foreground.handle;
- }
- }
- }
- int lineWidth = 1;
- int lineStyle = OS.PS_SOLID;
- switch (style.borderStyle) {
- case SWT.BORDER_SOLID: break;
- case SWT.BORDER_DASH: lineStyle = OS.PS_DASH; break;
- case SWT.BORDER_DOT: lineStyle = OS.PS_DOT; break;
- }
- int /*long*/ oldBrush = OS.SelectObject(hdc, OS.GetStockObject(OS.NULL_BRUSH));
- LOGBRUSH logBrush = new LOGBRUSH();
- logBrush.lbStyle = OS.BS_SOLID;
- logBrush.lbColor = /*64*/(int)color;
- int /*long*/ newPen = OS.ExtCreatePen(lineStyle | OS.PS_GEOMETRIC, Math.max(1, lineWidth), logBrush, 0, null);
- int /*long*/ oldPen = OS.SelectObject(hdc, newPen);
- OS.Rectangle(hdc, x + left, y, x + run.x + run.width, y + lineHeight);
- OS.SelectObject(hdc, oldPen);
- OS.DeleteObject(newPen);
- if (clipRect != null) {
- int state = OS.SaveDC(hdc);
- if (clipRect.left == -1) clipRect.left = 0;
- if (clipRect.right == -1) clipRect.right = 0x7ffff;
- OS.IntersectClipRect(hdc, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
- logBrush.lbColor = /*64*/(int)selectionColor;
- int /*long*/ selPen = OS.ExtCreatePen (lineStyle | OS.PS_GEOMETRIC, Math.max(1, lineWidth), logBrush, 0, null);
- oldPen = OS.SelectObject(hdc, selPen);
- OS.Rectangle(hdc, x + left, y, x + run.x + run.width, y + lineHeight);
- OS.RestoreDC(hdc, state);
- OS.SelectObject(hdc, oldPen);
- OS.DeleteObject(selPen);
- }
- OS.SelectObject(hdc, oldBrush);
- return null;
- }
- return clipRect;
-}
-
-RECT drawBorderGDIP(int /*long*/ graphics, int x, int y, int lineHeight, StyleItem[] line, int index, int /*long*/ color, int /*long*/ selectionColor, RECT clipRect, RECT pRect, int selectionStart, int selectionEnd, int alpha) {
- StyleItem run = line[index];
- TextStyle style = run.style;
- if (style == null) return null;
- if (style.borderStyle == SWT.NONE) return null;
- clipRect = addClipRect(run, clipRect, pRect, selectionStart, selectionEnd);
- if (index + 1 >= line.length || !style.isAdherentBorder(line[index + 1].style)) {
- int left = run.x;
- int start = run.start;
- int end = run.start + run.length - 1;
- for (int i = index; i > 0 && style.isAdherentBorder(line[i - 1].style); i--) {
- left = line[i - 1].x;
- start = Math.min(start, line[i - 1].start);
- end = Math.max(end, line[i - 1].start + line[i - 1].length - 1);
- }
- boolean hasSelection = selectionStart <= selectionEnd && selectionStart != -1 && selectionEnd != -1;
- boolean fullSelection = hasSelection && selectionStart <= start && end <= selectionEnd;
- int /*long*/ brush = color;
- if (style.borderColor != null) {
- brush = createGdipBrush(style.borderColor, alpha);
- clipRect = null;
- } else {
- if (fullSelection) {
- brush = selectionColor;
- clipRect = null;
- } else {
- if (style.foreground != null) {
- brush = createGdipBrush(style.foreground, alpha);
- }
- }
- }
- int lineWidth = 1;
- int lineStyle = Gdip.DashStyleSolid;
- switch (style.borderStyle) {
- case SWT.BORDER_SOLID: break;
- case SWT.BORDER_DASH: lineStyle = Gdip.DashStyleDash; break;
- case SWT.BORDER_DOT: lineStyle = Gdip.DashStyleDot; break;
- }
- int /*long*/ pen = Gdip.Pen_new(brush, lineWidth);
- Gdip.Pen_SetDashStyle(pen, lineStyle);
- Gdip.Graphics_SetPixelOffsetMode(graphics, Gdip.PixelOffsetModeNone);
- if (clipRect != null) {
- int gstate = Gdip.Graphics_Save(graphics);
- if (clipRect.left == -1) clipRect.left = 0;
- if (clipRect.right == -1) clipRect.right = 0x7ffff;
- Rect gdipRect = new Rect();
- gdipRect.X = clipRect.left;
- gdipRect.Y = clipRect.top;
- gdipRect.Width = clipRect.right - clipRect.left;
- gdipRect.Height = clipRect.bottom - clipRect.top;
- Gdip.Graphics_SetClip(graphics, gdipRect, Gdip.CombineModeExclude);
- Gdip.Graphics_DrawRectangle(graphics, pen, x + left, y, run.x + run.width - left - 1, lineHeight - 1);
- Gdip.Graphics_Restore(graphics, gstate);
- gstate = Gdip.Graphics_Save(graphics);
- Gdip.Graphics_SetClip(graphics, gdipRect, Gdip.CombineModeIntersect);
- int /*long*/ selPen = Gdip.Pen_new(selectionColor, lineWidth);
- Gdip.Pen_SetDashStyle(selPen, lineStyle);
- Gdip.Graphics_DrawRectangle(graphics, selPen, x + left, y, run.x + run.width - left - 1, lineHeight - 1);
- Gdip.Pen_delete(selPen);
- Gdip.Graphics_Restore(graphics, gstate);
- } else {
- Gdip.Graphics_DrawRectangle(graphics, pen, x + left, y, run.x + run.width - left - 1, lineHeight - 1);
- }
- Gdip.Graphics_SetPixelOffsetMode(graphics, Gdip.PixelOffsetModeHalf);
- Gdip.Pen_delete(pen);
- if (brush != selectionColor && brush != color) Gdip.SolidBrush_delete(brush);
- return null;
- }
- return clipRect;
-}
-
-void drawRunBackground(StyleItem run, int /*long*/ hdc, RECT rect, int selectionStart, int selectionEnd, int /*long*/ selBrush, boolean hasSelection) {
- int end = run.start + run.length - 1;
- boolean fullSelection = hasSelection && selectionStart <= run.start && selectionEnd >= end;
- if (fullSelection) {
- OS.SelectObject(hdc, selBrush);
- OS.PatBlt(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, OS.PATCOPY);
- } else {
- if (run.style != null && run.style.background != null) {
- int bg = run.style.background.handle;
- int /*long*/ hBrush = OS.CreateSolidBrush (bg);
- int /*long*/ oldBrush = OS.SelectObject(hdc, hBrush);
- OS.PatBlt(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, OS.PATCOPY);
- OS.SelectObject(hdc, oldBrush);
- OS.DeleteObject(hBrush);
- }
- boolean partialSelection = hasSelection && !(selectionStart > end || run.start > selectionEnd);
- if (partialSelection) {
- getPartialSelection(run, selectionStart, selectionEnd, rect);
- OS.SelectObject(hdc, selBrush);
- OS.PatBlt(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, OS.PATCOPY);
- }
- }
-}
-
-void drawRunBackgroundGDIP(StyleItem run, int /*long*/ graphics, RECT rect, int selectionStart, int selectionEnd, int alpha, int /*long*/ selBrush, boolean hasSelection) {
- int end = run.start + run.length - 1;
- boolean fullSelection = hasSelection && selectionStart <= run.start && selectionEnd >= end;
- if (fullSelection) {
- Gdip.Graphics_FillRectangle(graphics, selBrush, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
- } else {
- if (run.style != null && run.style.background != null) {
- int /*long*/ brush = createGdipBrush(run.style.background, alpha);
- Gdip.Graphics_FillRectangle(graphics, brush, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
- Gdip.SolidBrush_delete(brush);
- }
- boolean partialSelection = hasSelection && !(selectionStart > end || run.start > selectionEnd);
- if (partialSelection) {
- getPartialSelection(run, selectionStart, selectionEnd, rect);
- if (rect.left > rect.right) {
- int tmp = rect.left;
- rect.left = rect.right;
- rect.right = tmp;
- }
- Gdip.Graphics_FillRectangle(graphics, selBrush, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
- }
- }
-}
-
-RECT drawRunText(int /*long*/ hdc, StyleItem run, RECT rect, int baseline, int color, int selectionColor, int selectionStart, int selectionEnd) {
- int end = run.start + run.length - 1;
- boolean hasSelection = selectionStart <= selectionEnd && selectionStart != -1 && selectionEnd != -1;
- boolean fullSelection = hasSelection && selectionStart <= run.start && selectionEnd >= end;
- boolean partialSelection = hasSelection && !fullSelection && !(selectionStart > end || run.start > selectionEnd);
- int offset = (orientation & SWT.RIGHT_TO_LEFT) != 0 ? -1 : 0;
- int x = rect.left + offset;
- int y = rect.top + (baseline - run.ascent);
- int /*long*/ hFont = getItemFont(run);
- OS.SelectObject(hdc, hFont);
- if (fullSelection) {
- color = selectionColor;
- } else {
- if (run.style != null && run.style.foreground != null) {
- color = run.style.foreground.handle;
- }
- }
- OS.SetTextColor(hdc, color);
- OS.ScriptTextOut(hdc, run.psc, x, y, 0, null, run.analysis , 0, 0, run.glyphs, run.glyphCount, run.advances, run.justify, run.goffsets);
- if (partialSelection) {
- getPartialSelection(run, selectionStart, selectionEnd, rect);
- OS.SetTextColor(hdc, selectionColor);
- OS.ScriptTextOut(hdc, run.psc, x, y, OS.ETO_CLIPPED, rect, run.analysis , 0, 0, run.glyphs, run.glyphCount, run.advances, run.justify, run.goffsets);
- }
- return fullSelection || partialSelection ? rect : null;
-}
-
-RECT drawRunTextGDIP(int /*long*/ graphics, StyleItem run, RECT rect, int /*long*/ gdipFont, int baseline, int /*long*/ color, int /*long*/ selectionColor, int selectionStart, int selectionEnd, int alpha) {
- int end = run.start + run.length - 1;
- boolean hasSelection = selectionStart <= selectionEnd && selectionStart != -1 && selectionEnd != -1;
- boolean fullSelection = hasSelection && selectionStart <= run.start && selectionEnd >= end;
- boolean partialSelection = hasSelection && !fullSelection && !(selectionStart > end || run.start > selectionEnd);
- int drawY = rect.top + baseline;
- int drawX = rect.left;
- int /*long*/ brush = color;
- if (fullSelection) {
- brush = selectionColor;
- } else {
- if (run.style != null && run.style.foreground != null) {
- brush = createGdipBrush(run.style.foreground, alpha);
- }
- }
- int gstate = 0;
- Rect gdipRect = null;
- if (partialSelection) {
- gdipRect = new Rect();
- getPartialSelection(run, selectionStart, selectionEnd, rect);
- gdipRect.X = rect.left;
- gdipRect.Y = rect.top;
- gdipRect.Width = rect.right - rect.left;
- gdipRect.Height = rect.bottom - rect.top;
- gstate = Gdip.Graphics_Save(graphics);
- Gdip.Graphics_SetClip(graphics, gdipRect, Gdip.CombineModeExclude);
- }
- int gstateMirrored = 0;
- boolean isMirrored = (orientation & SWT.RIGHT_TO_LEFT) != 0;
- if (isMirrored) {
- switch (Gdip.Brush_GetType(brush)) {
- case Gdip.BrushTypeLinearGradient:
- Gdip.LinearGradientBrush_ScaleTransform(brush, -1, 1, Gdip.MatrixOrderPrepend);
- Gdip.LinearGradientBrush_TranslateTransform(brush, -2 * drawX - run.width, 0, Gdip.MatrixOrderPrepend);
- break;
- case Gdip.BrushTypeTextureFill:
- Gdip.TextureBrush_ScaleTransform(brush, -1, 1, Gdip.MatrixOrderPrepend);
- Gdip.TextureBrush_TranslateTransform(brush, -2 * drawX - run.width, 0, Gdip.MatrixOrderPrepend);
- break;
- }
- gstateMirrored = Gdip.Graphics_Save(graphics);
- Gdip.Graphics_ScaleTransform(graphics, -1, 1, Gdip.MatrixOrderPrepend);
- Gdip.Graphics_TranslateTransform(graphics, -2 * drawX - run.width, 0, Gdip.MatrixOrderPrepend);
- }
- int[] advances = new int[run.glyphCount];
- float[] points = new float[run.glyphCount * 2];
- OS.memmove(advances, run.justify != 0 ? run.justify : run.advances, run.glyphCount * 4);
- int glyphX = drawX;
- for (int h = 0, j = 0; h < advances.length; h++) {
- points[j++] = glyphX;
- points[j++] = drawY;
- glyphX += advances[h];
- }
- Gdip.Graphics_DrawDriverString(graphics, run.glyphs, run.glyphCount, gdipFont, brush, points, 0, 0);
- if (partialSelection) {
- if (isMirrored) {
- Gdip.Graphics_Restore(graphics, gstateMirrored);
- }
- Gdip.Graphics_Restore(graphics, gstate);
- gstate = Gdip.Graphics_Save(graphics);
- Gdip.Graphics_SetClip(graphics, gdipRect, Gdip.CombineModeIntersect);
- if (isMirrored) {
- gstateMirrored = Gdip.Graphics_Save(graphics);
- Gdip.Graphics_ScaleTransform(graphics, -1, 1, Gdip.MatrixOrderPrepend);
- Gdip.Graphics_TranslateTransform(graphics, -2 * drawX - run.width, 0, Gdip.MatrixOrderPrepend);
- }
- Gdip.Graphics_DrawDriverString(graphics, run.glyphs, run.glyphCount, gdipFont, selectionColor, points, 0, 0);
- Gdip.Graphics_Restore(graphics, gstate);
- }
- if (isMirrored) {
- switch (Gdip.Brush_GetType(brush)) {
- case Gdip.BrushTypeLinearGradient:
- Gdip.LinearGradientBrush_ResetTransform(brush);
- break;
- case Gdip.BrushTypeTextureFill:
- Gdip.TextureBrush_ResetTransform(brush);
- break;
- }
- Gdip.Graphics_Restore(graphics, gstateMirrored);
- }
- if (brush != selectionColor && brush != color) Gdip.SolidBrush_delete(brush);
- return fullSelection || partialSelection ? rect : null;
-}
-
-RECT drawRunTextGDIPRaster(int /*long*/ graphics, StyleItem run, RECT rect, int baseline, int color, int selectionColor, int selectionStart, int selectionEnd) {
- int /*long*/ clipRgn = 0;
- Gdip.Graphics_SetPixelOffsetMode(graphics, Gdip.PixelOffsetModeNone);
- int /*long*/ rgn = Gdip.Region_new();
- if (rgn == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Gdip.Graphics_GetClip(graphics, rgn);
- if (!Gdip.Region_IsInfinite(rgn, graphics)) {
- clipRgn = Gdip.Region_GetHRGN(rgn, graphics);
- }
- Gdip.Region_delete(rgn);
- Gdip.Graphics_SetPixelOffsetMode(graphics, Gdip.PixelOffsetModeHalf);
- float[] lpXform = null;
- int /*long*/ matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0);
- if (matrix == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Gdip.Graphics_GetTransform(graphics, matrix);
- if (!Gdip.Matrix_IsIdentity(matrix)) {
- lpXform = new float[6];
- Gdip.Matrix_GetElements(matrix, lpXform);
- }
- Gdip.Matrix_delete(matrix);
- int /*long*/ hdc = Gdip.Graphics_GetHDC(graphics);
- int state = OS.SaveDC(hdc);
- if (lpXform != null) {
- OS.SetGraphicsMode(hdc, OS.GM_ADVANCED);
- OS.SetWorldTransform(hdc, lpXform);
- }
- if (clipRgn != 0) {
- OS.SelectClipRgn(hdc, clipRgn);
- OS.DeleteObject(clipRgn);
- }
- if ((orientation & SWT.RIGHT_TO_LEFT) != 0) {
- OS.SetLayout(hdc, OS.GetLayout(hdc) | OS.LAYOUT_RTL);
- }
- OS.SetBkMode(hdc, OS.TRANSPARENT);
- RECT pRect = drawRunText(hdc, run, rect, baseline, color, selectionColor, selectionStart, selectionEnd);
- OS.RestoreDC(hdc, state);
- Gdip.Graphics_ReleaseHDC(graphics, hdc);
- return pRect;
-}
-
-RECT drawStrikeout(int /*long*/ hdc, int x, int baseline, StyleItem[] line, int index, int color, int selectionColor, RECT clipRect, RECT pRect, int selectionStart, int selectionEnd) {
- StyleItem run = line[index];
- TextStyle style = run.style;
- if (style == null) return null;
- if (!style.strikeout) return null;
- clipRect = addClipRect(run, clipRect, pRect, selectionStart, selectionEnd);
- if (index + 1 >= line.length || !style.isAdherentStrikeout(line[index + 1].style)) {
- int left = run.x;
- int start = run.start;
- int end = run.start + run.length - 1;
- for (int i = index; i > 0 && style.isAdherentStrikeout(line[i - 1].style); i--) {
- left = line[i - 1].x;
- start = Math.min(start, line[i - 1].start);
- end = Math.max(end, line[i - 1].start + line[i - 1].length - 1);
- }
- boolean hasSelection = selectionStart <= selectionEnd && selectionStart != -1 && selectionEnd != -1;
- boolean fullSelection = hasSelection && selectionStart <= start && end <= selectionEnd;
- if (style.strikeoutColor != null) {
- color = style.strikeoutColor.handle;
- clipRect = null;
- } else {
- if (fullSelection) {
- color = selectionColor;
- clipRect = null;
- } else {
- if (style.foreground != null) {
- color = style.foreground.handle;
- }
- }
- }
- RECT rect = new RECT();
- OS.SetRect(rect, x + left, baseline - run.strikeoutPos, x + run.x + run.width, baseline - run.strikeoutPos + run.strikeoutThickness);
- int /*long*/ brush = OS.CreateSolidBrush(color);
- OS.FillRect(hdc, rect, brush);
- OS.DeleteObject(brush);
- if (clipRect != null) {
- int /*long*/ selBrush = OS.CreateSolidBrush(selectionColor);
- if (clipRect.left == -1) clipRect.left = 0;
- if (clipRect.right == -1) clipRect.right = 0x7ffff;
- OS.SetRect(clipRect, Math.max(rect.left, clipRect.left), rect.top, Math.min(rect.right, clipRect.right), rect.bottom);
- OS.FillRect(hdc, clipRect, selBrush);
- OS.DeleteObject(selBrush);
- }
- return null;
- }
- return clipRect;
-}
-
-RECT drawStrikeoutGDIP(int /*long*/ graphics, int x, int baseline, StyleItem[] line, int index, int /*long*/ color, int /*long*/ selectionColor, RECT clipRect, RECT pRect, int selectionStart, int selectionEnd, int alpha) {
- StyleItem run = line[index];
- TextStyle style = run.style;
- if (style == null) return null;
- if (!style.strikeout) return null;
- clipRect = addClipRect(run, clipRect, pRect, selectionStart, selectionEnd);
- if (index + 1 >= line.length || !style.isAdherentStrikeout(line[index + 1].style)) {
- int left = run.x;
- int start = run.start;
- int end = run.start + run.length - 1;
- for (int i = index; i > 0 && style.isAdherentStrikeout(line[i - 1].style); i--) {
- left = line[i - 1].x;
- start = Math.min(start, line[i - 1].start);
- end = Math.max(end, line[i - 1].start + line[i - 1].length - 1);
- }
- boolean hasSelection = selectionStart <= selectionEnd && selectionStart != -1 && selectionEnd != -1;
- boolean fullSelection = hasSelection && selectionStart <= start && end <= selectionEnd;
- int /*long*/ brush = color;
- if (style.strikeoutColor != null) {
- brush = createGdipBrush(style.strikeoutColor, alpha);
- clipRect = null;
- } else {
- if (fullSelection) {
- color = selectionColor;
- clipRect = null;
- } else {
- if (style.foreground != null) {
- brush = createGdipBrush(style.foreground, alpha);
- }
- }
- }
- if (clipRect != null) {
- int gstate = Gdip.Graphics_Save(graphics);
- if (clipRect.left == -1) clipRect.left = 0;
- if (clipRect.right == -1) clipRect.right = 0x7ffff;
- Rect gdipRect = new Rect();
- gdipRect.X = clipRect.left;
- gdipRect.Y = clipRect.top;
- gdipRect.Width = clipRect.right - clipRect.left;
- gdipRect.Height = clipRect.bottom - clipRect.top;
- Gdip.Graphics_SetClip(graphics, gdipRect, Gdip.CombineModeExclude);
- Gdip.Graphics_FillRectangle(graphics, brush, x + left, baseline - run.strikeoutPos, run.x + run.width - left, run.strikeoutThickness);
- Gdip.Graphics_Restore(graphics, gstate);
- gstate = Gdip.Graphics_Save(graphics);
- Gdip.Graphics_SetClip(graphics, gdipRect, Gdip.CombineModeIntersect);
- Gdip.Graphics_FillRectangle(graphics, selectionColor, x + left, baseline - run.strikeoutPos, run.x + run.width - left, run.strikeoutThickness);
- Gdip.Graphics_Restore(graphics, gstate);
- } else {
- Gdip.Graphics_FillRectangle(graphics, brush, x + left, baseline - run.strikeoutPos, run.x + run.width - left, run.strikeoutThickness);
- }
- if (brush != selectionColor && brush != color) Gdip.SolidBrush_delete(brush);
- return null;
- }
- return clipRect;
-}
-
-RECT drawUnderline(int /*long*/ hdc, int x, int baseline, int lineUnderlinePos, int lineBottom, StyleItem[] line, int index, int color, int selectionColor, RECT clipRect, RECT pRect, int selectionStart, int selectionEnd) {
- StyleItem run = line[index];
- TextStyle style = run.style;
- if (style == null) return null;
- if (!style.underline) return null;
- clipRect = addClipRect(run, clipRect, pRect, selectionStart, selectionEnd);
- if (index + 1 >= line.length || !style.isAdherentUnderline(line[index + 1].style)) {
- int left = run.x;
- int start = run.start;
- int end = run.start + run.length - 1;
- for (int i = index; i > 0 && style.isAdherentUnderline(line[i - 1].style); i--) {
- left = line[i - 1].x;
- start = Math.min(start, line[i - 1].start);
- end = Math.max(end, line[i - 1].start + line[i - 1].length - 1);
- }
- boolean hasSelection = selectionStart <= selectionEnd && selectionStart != -1 && selectionEnd != -1;
- boolean fullSelection = hasSelection && selectionStart <= start && end <= selectionEnd;
- if (style.underlineColor != null) {
- color = style.underlineColor.handle;
- clipRect = null;
- } else {
- if (fullSelection) {
- color = selectionColor;
- clipRect = null;
- } else {
- if (style.foreground != null) {
- color = style.foreground.handle;
- }
- }
- }
- RECT rect = new RECT();
- OS.SetRect(rect, x + left, baseline - lineUnderlinePos, x + run.x + run.width, baseline - lineUnderlinePos + run.underlineThickness);
- if (clipRect != null) {
- if (clipRect.left == -1) clipRect.left = 0;
- if (clipRect.right == -1) clipRect.right = 0x7ffff;
- OS.SetRect(clipRect, Math.max(rect.left, clipRect.left), rect.top, Math.min(rect.right, clipRect.right), rect.bottom);
- }
- switch (style.underlineStyle) {
- case SWT.UNDERLINE_SQUIGGLE:
- case SWT.UNDERLINE_ERROR: {
- int squigglyThickness = 1;
- int squigglyHeight = 2 * squigglyThickness;
- int squigglyY = Math.min(rect.top - squigglyHeight / 2, lineBottom - squigglyHeight - 1);
- int[] points = computePolyline(rect.left, squigglyY, rect.right, squigglyY + squigglyHeight);
- int /*long*/ pen = OS.CreatePen(OS.PS_SOLID, squigglyThickness, color);
- int /*long*/ oldPen = OS.SelectObject(hdc, pen);
- int state = OS.SaveDC(hdc);
- OS.IntersectClipRect(hdc, rect.left, squigglyY, rect.right + 1, squigglyY + squigglyHeight + 1);
- OS.Polyline(hdc, points, points.length / 2);
- int length = points.length;
- if (length >= 2 && squigglyThickness <= 1) {
- OS.SetPixel (hdc, points[length - 2], points[length - 1], color);
- }
- OS.SelectObject(hdc, oldPen);
- OS.DeleteObject(pen);
- OS.RestoreDC(hdc, state);
- if (clipRect != null) {
- pen = OS.CreatePen(OS.PS_SOLID, squigglyThickness, selectionColor);
- oldPen = OS.SelectObject(hdc, pen);
- state = OS.SaveDC(hdc);
- OS.IntersectClipRect(hdc, clipRect.left, squigglyY, clipRect.right + 1, squigglyY + squigglyHeight + 1);
- OS.Polyline(hdc, points, points.length / 2);
- if (length >= 2 && squigglyThickness <= 1) {
- OS.SetPixel (hdc, points[length - 2], points[length - 1], selectionColor);
- }
- OS.SelectObject(hdc, oldPen);
- OS.DeleteObject(pen);
- OS.RestoreDC(hdc, state);
- }
- break;
- }
- case SWT.UNDERLINE_SINGLE:
- case SWT.UNDERLINE_DOUBLE:
- case SWT.UNDERLINE_LINK:
- case UNDERLINE_IME_THICK:
- if (style.underlineStyle == UNDERLINE_IME_THICK) {
- rect.top -= run.underlineThickness;
- if (clipRect != null) clipRect.top -= run.underlineThickness;
- }
- int bottom = style.underlineStyle == SWT.UNDERLINE_DOUBLE ? rect.bottom + run.underlineThickness * 2 : rect.bottom;
- if (bottom > lineBottom) {
- OS.OffsetRect(rect, 0, lineBottom - bottom);
- if (clipRect != null) OS.OffsetRect(clipRect, 0, lineBottom - bottom);
- }
- int /*long*/ brush = OS.CreateSolidBrush(color);
- OS.FillRect(hdc, rect, brush);
- if (style.underlineStyle == SWT.UNDERLINE_DOUBLE) {
- OS.SetRect(rect, rect.left, rect.top + run.underlineThickness * 2, rect.right, rect.bottom + run.underlineThickness * 2);
- OS.FillRect(hdc, rect, brush);
- }
- OS.DeleteObject(brush);
- if (clipRect != null) {
- int /*long*/ selBrush = OS.CreateSolidBrush(selectionColor);
- OS.FillRect(hdc, clipRect, selBrush);
- if (style.underlineStyle == SWT.UNDERLINE_DOUBLE) {
- OS.SetRect(clipRect, clipRect.left, rect.top, clipRect.right, rect.bottom);
- OS.FillRect(hdc, clipRect, selBrush);
- }
- OS.DeleteObject(selBrush);
- }
- break;
- case UNDERLINE_IME_DASH:
- case UNDERLINE_IME_DOT: {
- int penStyle = style.underlineStyle == UNDERLINE_IME_DASH ? OS.PS_DASH : OS.PS_DOT;
- int /*long*/ pen = OS.CreatePen(penStyle, 1, color);
- int /*long*/ oldPen = OS.SelectObject(hdc, pen);
- OS.SetRect(rect, rect.left, baseline + run.descent, rect.right, baseline + run.descent + run.underlineThickness);
- OS.MoveToEx(hdc, rect.left, rect.top, 0);
- OS.LineTo(hdc, rect.right, rect.top);
- OS.SelectObject(hdc, oldPen);
- OS.DeleteObject(pen);
- if (clipRect != null) {
- pen = OS.CreatePen(penStyle, 1, selectionColor);
- oldPen = OS.SelectObject(hdc, pen);
- OS.SetRect(clipRect, clipRect.left, rect.top, clipRect.right, rect.bottom);
- OS.MoveToEx(hdc, clipRect.left, clipRect.top, 0);
- OS.LineTo(hdc, clipRect.right, clipRect.top);
- OS.SelectObject(hdc, oldPen);
- OS.DeleteObject(pen);
- }
- break;
- }
- }
- return null;
- }
- return clipRect;
-}
-
-RECT drawUnderlineGDIP (int /*long*/ graphics, int x, int baseline, int lineUnderlinePos, int lineBottom, StyleItem[] line, int index, int /*long*/ color, int /*long*/ selectionColor, RECT clipRect, RECT pRect, int selectionStart, int selectionEnd, int alpha) {
- StyleItem run = line[index];
- TextStyle style = run.style;
- if (style == null) return null;
- if (!style.underline) return null;
- clipRect = addClipRect(run, clipRect, pRect, selectionStart, selectionEnd);
- if (index + 1 >= line.length || !style.isAdherentUnderline(line[index + 1].style)) {
- int left = run.x;
- int start = run.start;
- int end = run.start + run.length - 1;
- for (int i = index; i > 0 && style.isAdherentUnderline(line[i - 1].style); i--) {
- left = line[i - 1].x;
- start = Math.min(start, line[i - 1].start);
- end = Math.max(end, line[i - 1].start + line[i - 1].length - 1);
- }
- boolean hasSelection = selectionStart <= selectionEnd && selectionStart != -1 && selectionEnd != -1;
- boolean fullSelection = hasSelection && selectionStart <= start && end <= selectionEnd;
- int /*long*/ brush = color;
- if (style.underlineColor != null) {
- brush = createGdipBrush(style.underlineColor, alpha);
- clipRect = null;
- } else {
- if (fullSelection) {
- brush = selectionColor;
- clipRect = null;
- } else {
- if (style.foreground != null) {
- brush = createGdipBrush(style.foreground, alpha);
- }
- }
- }
- RECT rect = new RECT();
- OS.SetRect(rect, x + left, baseline - lineUnderlinePos, x + run.x + run.width, baseline - lineUnderlinePos + run.underlineThickness);
- Rect gdipRect = null;
- if (clipRect != null) {
- if (clipRect.left == -1) clipRect.left = 0;
- if (clipRect.right == -1) clipRect.right = 0x7ffff;
- OS.SetRect(clipRect, Math.max(rect.left, clipRect.left), rect.top, Math.min(rect.right, clipRect.right), rect.bottom);
- gdipRect = new Rect();
- gdipRect.X = clipRect.left;
- gdipRect.Y = clipRect.top;
- gdipRect.Width = clipRect.right - clipRect.left;
- gdipRect.Height = clipRect.bottom - clipRect.top;
- }
- int gstate = 0;
- Gdip.Graphics_SetPixelOffsetMode(graphics, Gdip.PixelOffsetModeNone);
- switch (style.underlineStyle) {
- case SWT.UNDERLINE_SQUIGGLE:
- case SWT.UNDERLINE_ERROR: {
- int squigglyThickness = 1;
- int squigglyHeight = 2 * squigglyThickness;
- int squigglyY = Math.min(rect.top - squigglyHeight / 2, lineBottom - squigglyHeight - 1);
- int[] points = computePolyline(rect.left, squigglyY, rect.right, squigglyY + squigglyHeight);
- int /*long*/ pen = Gdip.Pen_new(brush, squigglyThickness);
- gstate = Gdip.Graphics_Save(graphics);
- if (gdipRect != null) {
- Gdip.Graphics_SetClip(graphics, gdipRect, Gdip.CombineModeExclude);
- } else {
- Rect r = new Rect();
- r.X = rect.left;
- r.Y = squigglyY;
- r.Width = rect.right - rect.left;
- r.Height = squigglyHeight + 1;
- Gdip.Graphics_SetClip(graphics, r, Gdip.CombineModeIntersect);
- }
- Gdip.Graphics_DrawLines(graphics, pen, points, points.length / 2);
- if (gdipRect != null) {
- int /*long*/ selPen = Gdip.Pen_new(selectionColor, squigglyThickness);
- Gdip.Graphics_Restore(graphics, gstate);
- gstate = Gdip.Graphics_Save(graphics);
- Gdip.Graphics_SetClip(graphics, gdipRect, Gdip.CombineModeIntersect);
- Gdip.Graphics_DrawLines(graphics, selPen, points, points.length / 2);
- Gdip.Pen_delete(selPen);
- }
- Gdip.Graphics_Restore(graphics, gstate);
- Gdip.Pen_delete(pen);
- if (gstate != 0) Gdip.Graphics_Restore(graphics, gstate);
- break;
- }
- case SWT.UNDERLINE_SINGLE:
- case SWT.UNDERLINE_DOUBLE:
- case SWT.UNDERLINE_LINK:
- case UNDERLINE_IME_THICK:
- if (style.underlineStyle == UNDERLINE_IME_THICK) {
- rect.top -= run.underlineThickness;
- }
- int bottom = style.underlineStyle == SWT.UNDERLINE_DOUBLE ? rect.bottom + run.underlineThickness * 2 : rect.bottom;
- if (bottom > lineBottom) {
- OS.OffsetRect(rect, 0, lineBottom - bottom);
- }
- if (gdipRect != null) {
- gdipRect.Y = rect.top;
- if (style.underlineStyle == UNDERLINE_IME_THICK) {
- gdipRect.Height = run.underlineThickness * 2;
- }
- if (style.underlineStyle == SWT.UNDERLINE_DOUBLE) {
- gdipRect.Height = run.underlineThickness * 3;
- }
- gstate = Gdip.Graphics_Save(graphics);
- Gdip.Graphics_SetClip(graphics, gdipRect, Gdip.CombineModeExclude);
- }
- Gdip.Graphics_FillRectangle(graphics, brush, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
- if (style.underlineStyle == SWT.UNDERLINE_DOUBLE) {
- Gdip.Graphics_FillRectangle(graphics, brush, rect.left, rect.top + run.underlineThickness * 2, rect.right - rect.left, rect.bottom - rect.top);
- }
- if (gdipRect != null) {
- Gdip.Graphics_Restore(graphics, gstate);
- gstate = Gdip.Graphics_Save(graphics);
- Gdip.Graphics_SetClip(graphics, gdipRect, Gdip.CombineModeIntersect);
- Gdip.Graphics_FillRectangle(graphics, selectionColor, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
- if (style.underlineStyle == SWT.UNDERLINE_DOUBLE) {
- Gdip.Graphics_FillRectangle(graphics, selectionColor, rect.left, rect.top + run.underlineThickness * 2, rect.right - rect.left, rect.bottom - rect.top);
- }
- Gdip.Graphics_Restore(graphics, gstate);
- }
- break;
- case UNDERLINE_IME_DOT:
- case UNDERLINE_IME_DASH: {
- int /*long*/ pen = Gdip.Pen_new(brush, 1);
- int dashStyle = style.underlineStyle == UNDERLINE_IME_DOT ? Gdip.DashStyleDot : Gdip.DashStyleDash;
- Gdip.Pen_SetDashStyle(pen, dashStyle);
- if (gdipRect != null) {
- gstate = Gdip.Graphics_Save(graphics);
- Gdip.Graphics_SetClip(graphics, gdipRect, Gdip.CombineModeExclude);
- }
- Gdip.Graphics_DrawLine(graphics, pen, rect.left, baseline + run.descent, run.width - run.length, baseline + run.descent);
- if (gdipRect != null) {
- Gdip.Graphics_Restore(graphics, gstate);
- gstate = Gdip.Graphics_Save(graphics);
- Gdip.Graphics_SetClip(graphics, gdipRect, Gdip.CombineModeIntersect);
- int /*long*/ selPen = Gdip.Pen_new(brush, 1);
- Gdip.Pen_SetDashStyle(selPen, dashStyle);
- Gdip.Graphics_DrawLine(graphics, selPen, rect.left, baseline + run.descent, run.width - run.length, baseline + run.descent);
- Gdip.Graphics_Restore(graphics, gstate);
- Gdip.Pen_delete(selPen);
- }
- Gdip.Pen_delete(pen);
- break;
- }
- }
- if (brush != selectionColor && brush != color) Gdip.SolidBrush_delete(brush);
- Gdip.Graphics_SetPixelOffsetMode(graphics, Gdip.PixelOffsetModeHalf);
- return null;
- }
- return clipRect;
-}
-
-void freeRuns () {
- if (allRuns == null) return;
- for (int i=0; i<allRuns.length; i++) {
- StyleItem run = allRuns[i];
- run.free();
- }
- allRuns = null;
- runs = null;
- segmentsText = null;
-}
-
-/**
- * Returns the receiver's horizontal text alignment, which will be one
- * of <code>SWT.LEFT</code>, <code>SWT.CENTER</code> or
- * <code>SWT.RIGHT</code>.
- *
- * @return the alignment used to positioned text horizontally
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getAlignment () {
- checkLayout();
- return alignment;
-}
-
-/**
- * Returns the ascent of the receiver.
- *
- * @return the ascent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getDescent()
- * @see #setDescent(int)
- * @see #setAscent(int)
- * @see #getLineMetrics(int)
- */
-public int getAscent () {
- checkLayout();
- return ascent;
-}
-
-/**
- * Returns the bounds of the receiver. The width returned is either the
- * width of the longest line or the width set using {@link TextLayout#setWidth(int)}.
- * To obtain the text bounds of a line use {@link TextLayout#getLineBounds(int)}.
- *
- * @return the bounds of the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setWidth(int)
- * @see #getLineBounds(int)
- */
-public Rectangle getBounds () {
- checkLayout();
- computeRuns(null);
- int width = 0;
- if (wrapWidth != -1) {
- width = wrapWidth;
- } else {
- for (int line=0; line<runs.length; line++) {
- width = Math.max(width, lineWidth[line] + getLineIndent(line));
- }
- }
- return new Rectangle (0, 0, width, lineY[lineY.length - 1]);
-}
-
-/**
- * Returns the bounds for the specified range of characters. The
- * bounds is the smallest rectangle that encompasses all characters
- * in the range. The start and end offsets are inclusive and will be
- * clamped if out of range.
- *
- * @param start the start offset
- * @param end the end offset
- * @return the bounds of the character range
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds (int start, int end) {
- checkLayout();
- computeRuns(null);
- int length = text.length();
- if (length == 0) return new Rectangle(0, 0, 0, 0);
- if (start > end) return new Rectangle(0, 0, 0, 0);
- start = Math.min(Math.max(0, start), length - 1);
- end = Math.min(Math.max(0, end), length - 1);
- start = translateOffset(start);
- end = translateOffset(end);
- int left = 0x7fffffff, right = 0;
- int top = 0x7fffffff, bottom = 0;
- boolean isRTL = (orientation & SWT.RIGHT_TO_LEFT) != 0;
- for (int i = 0; i < allRuns.length - 1; i++) {
- StyleItem run = allRuns[i];
- int runEnd = run.start + run.length;
- if (runEnd <= start) continue;
- if (run.start > end) break;
- int runLead = run.x;
- int runTrail = run.x + run.width;
- if (run.start <= start && start < runEnd) {
- int cx = 0;
- if (run.style != null && run.style.metrics != null) {
- GlyphMetrics metrics = run.style.metrics;
- cx = metrics.width * (start - run.start);
- } else if (!run.tab) {
- int[] piX = new int[1];
- int /*long*/ advances = run.justify != 0 ? run.justify : run.advances;
- OS.ScriptCPtoX(start - run.start, false, run.length, run.glyphCount, run.clusters, run.visAttrs, advances, run.analysis, piX);
- cx = isRTL ? run.width - piX[0] : piX[0];
- }
- if (run.analysis.fRTL ^ isRTL) {
- runTrail = run.x + cx;
- } else {
- runLead = run.x + cx;
- }
- }
- if (run.start <= end && end < runEnd) {
- int cx = run.width;
- if (run.style != null && run.style.metrics != null) {
- GlyphMetrics metrics = run.style.metrics;
- cx = metrics.width * (end - run.start + 1);
- } else if (!run.tab) {
- int[] piX = new int[1];
- int /*long*/ advances = run.justify != 0 ? run.justify : run.advances;
- OS.ScriptCPtoX(end - run.start, true, run.length, run.glyphCount, run.clusters, run.visAttrs, advances, run.analysis, piX);
- cx = isRTL ? run.width - piX[0] : piX[0];
- }
- if (run.analysis.fRTL ^ isRTL) {
- runLead = run.x + cx;
- } else {
- runTrail = run.x + cx;
- }
- }
- int lineIndex = 0;
- while (lineIndex < runs.length && lineOffset[lineIndex + 1] <= run.start) {
- lineIndex++;
- }
- left = Math.min(left, runLead);
- right = Math.max(right, runTrail);
- top = Math.min(top, lineY[lineIndex]);
- bottom = Math.max(bottom, lineY[lineIndex + 1] - lineSpacing);
- }
- return new Rectangle(left, top, right - left, bottom - top);
-}
-
-/**
- * Returns the descent of the receiver.
- *
- * @return the descent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getAscent()
- * @see #setAscent(int)
- * @see #setDescent(int)
- * @see #getLineMetrics(int)
- */
-public int getDescent () {
- checkLayout();
- return descent;
-}
-
-/**
- * Returns the default font currently being used by the receiver
- * to draw and measure text.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getFont () {
- checkLayout();
- return font;
-}
-
-/**
-* Returns the receiver's indent.
-*
-* @return the receiver's indent
-*
-* @exception SWTException <ul>
-* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
-* </ul>
-*
-* @since 3.2
-*/
-public int getIndent () {
- checkLayout();
- return indent;
-}
-
-/**
-* Returns the receiver's justification.
-*
-* @return the receiver's justification
-*
-* @exception SWTException <ul>
-* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
-* </ul>
-*
-* @since 3.2
-*/
-public boolean getJustify () {
- checkLayout();
- return justify;
-}
-
-int /*long*/ getItemFont (StyleItem item) {
- if (item.fallbackFont != 0) return item.fallbackFont;
- if (item.style != null && item.style.font != null) {
- return item.style.font.handle;
- }
- if (this.font != null) {
- return this.font.handle;
- }
- return device.systemFont.handle;
-}
-
-/**
- * Returns the embedding level for the specified character offset. The
- * embedding level is usually used to determine the directionality of a
- * character in bidirectional text.
- *
- * @param offset the character offset
- * @return the embedding level
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- */
-public int getLevel (int offset) {
- checkLayout();
- computeRuns(null);
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- offset = translateOffset(offset);
- for (int i=1; i<allRuns.length; i++) {
- if (allRuns[i].start > offset) {
- return allRuns[i - 1].analysis.s.uBidiLevel;
- }
- }
- return (orientation & SWT.RIGHT_TO_LEFT) != 0 ? 1 : 0;
-}
-
-/**
- * Returns the bounds of the line for the specified line index.
- *
- * @param lineIndex the line index
- * @return the line bounds
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getLineBounds(int lineIndex) {
- checkLayout();
- computeRuns(null);
- if (!(0 <= lineIndex && lineIndex < runs.length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- int x = getLineIndent(lineIndex);
- int y = lineY[lineIndex];
- int width = lineWidth[lineIndex];
- int height = lineY[lineIndex + 1] - y - lineSpacing;
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the receiver's line count. This includes lines caused
- * by wrapping.
- *
- * @return the line count
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineCount () {
- checkLayout();
- computeRuns(null);
- return runs.length;
-}
-
-int getLineIndent (int lineIndex) {
- int lineIndent = 0;
- if (lineIndex == 0) {
- lineIndent = indent;
- } else {
- StyleItem[] previousLine = runs[lineIndex - 1];
- StyleItem previousRun = previousLine[previousLine.length - 1];
- if (previousRun.lineBreak && !previousRun.softBreak) {
- lineIndent = indent;
- }
- }
- if (wrapWidth != -1) {
- boolean partialLine = true;
- if (justify) {
- StyleItem[] lineRun = runs[lineIndex];
- if (lineRun[lineRun.length - 1].softBreak) {
- partialLine = false;
- }
- }
- if (partialLine) {
- int lineWidth = this.lineWidth[lineIndex] + lineIndent;
- switch (alignment) {
- case SWT.CENTER: lineIndent += (wrapWidth - lineWidth) / 2; break;
- case SWT.RIGHT: lineIndent += wrapWidth - lineWidth; break;
- }
- }
- }
- return lineIndent;
-}
-
-/**
- * Returns the index of the line that contains the specified
- * character offset.
- *
- * @param offset the character offset
- * @return the line index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineIndex (int offset) {
- checkLayout();
- computeRuns(null);
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- offset = translateOffset(offset);
- for (int line=0; line<runs.length; line++) {
- if (lineOffset[line + 1] > offset) {
- return line;
- }
- }
- return runs.length - 1;
-}
-
-/**
- * Returns the font metrics for the specified line index.
- *
- * @param lineIndex the line index
- * @return the font metrics
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontMetrics getLineMetrics (int lineIndex) {
- checkLayout();
- computeRuns(null);
- if (!(0 <= lineIndex && lineIndex < runs.length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- int /*long*/ hDC = device.internal_new_GC(null);
- int /*long*/ srcHdc = OS.CreateCompatibleDC(hDC);
- TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA();
- OS.SelectObject(srcHdc, font != null ? font.handle : device.systemFont.handle);
- OS.GetTextMetrics(srcHdc, lptm);
- OS.DeleteDC(srcHdc);
- device.internal_dispose_GC(hDC, null);
-
- int ascent = Math.max(lptm.tmAscent, this.ascent);
- int descent = Math.max(lptm.tmDescent, this.descent);
- int leading = lptm.tmInternalLeading;
- if (text.length() != 0) {
- StyleItem[] lineRuns = runs[lineIndex];
- for (int i = 0; i<lineRuns.length; i++) {
- StyleItem run = lineRuns[i];
- if (run.ascent > ascent) {
- ascent = run.ascent;
- leading = run.leading;
- }
- descent = Math.max(descent, run.descent);
- }
- }
- lptm.tmAscent = ascent;
- lptm.tmDescent = descent;
- lptm.tmHeight = ascent + descent;
- lptm.tmInternalLeading = leading;
- lptm.tmAveCharWidth = 0;
- return FontMetrics.win32_new(lptm);
-}
-
-/**
- * Returns the line offsets. Each value in the array is the
- * offset for the first character in a line except for the last
- * value, which contains the length of the text.
- *
- * @return the line offsets
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getLineOffsets () {
- checkLayout();
- computeRuns(null);
- int[] offsets = new int[lineOffset.length];
- for (int i = 0; i < offsets.length; i++) {
- offsets[i] = untranslateOffset(lineOffset[i]);
- }
- return offsets;
-}
-
-/**
- * Returns the location for the specified character offset. The
- * <code>trailing</code> argument indicates whether the offset
- * corresponds to the leading or trailing edge of the cluster.
- *
- * @param offset the character offset
- * @param trailing the trailing flag
- * @return the location of the character offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getOffset(Point, int[])
- * @see #getOffset(int, int, int[])
- */
-public Point getLocation (int offset, boolean trailing) {
- checkLayout();
- computeRuns(null);
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- length = segmentsText.length();
- offset = translateOffset(offset);
- int line;
- for (line=0; line<runs.length; line++) {
- if (lineOffset[line + 1] > offset) break;
- }
- line = Math.min(line, runs.length - 1);
- if (offset == length) {
- return new Point(getLineIndent(line) + lineWidth[line], lineY[line]);
- }
- int low = -1;
- int high = allRuns.length;
- while (high - low > 1) {
- int index = ((high + low) / 2);
- StyleItem run = allRuns[index];
- if (run.start > offset) {
- high = index;
- } else if (run.start + run.length <= offset) {
- low = index;
- } else {
- int width;
- if (run.style != null && run.style.metrics != null) {
- GlyphMetrics metrics = run.style.metrics;
- width = metrics.width * (offset - run.start + (trailing ? 1 : 0));
- } else if (run.tab) {
- width = (trailing || (offset == length)) ? run.width : 0;
- } else {
- int runOffset = offset - run.start;
- int cChars = run.length;
- int gGlyphs = run.glyphCount;
- int[] piX = new int[1];
- int /*long*/ advances = run.justify != 0 ? run.justify : run.advances;
- OS.ScriptCPtoX(runOffset, trailing, cChars, gGlyphs, run.clusters, run.visAttrs, advances, run.analysis, piX);
- width = (orientation & SWT.RIGHT_TO_LEFT) != 0 ? run.width - piX[0] : piX[0];
- }
- return new Point(run.x + width, lineY[line]);
- }
- }
- return new Point(0, 0);
-}
-
-/**
- * Returns the next offset for the specified offset and movement
- * type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>,
- * <code>SWT.MOVEMENT_CLUSTER</code>, <code>SWT.MOVEMENT_WORD</code>,
- * <code>SWT.MOVEMENT_WORD_END</code> or <code>SWT.MOVEMENT_WORD_START</code>.
- *
- * @param offset the start offset
- * @param movement the movement type
- * @return the next offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getPreviousOffset(int, int)
- */
-public int getNextOffset (int offset, int movement) {
- checkLayout();
- return _getOffset (offset, movement, true);
-}
-
-int _getOffset(int offset, int movement, boolean forward) {
- computeRuns(null);
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- if (forward && offset == length) return length;
- if (!forward && offset == 0) return 0;
- int step = forward ? 1 : -1;
- if ((movement & SWT.MOVEMENT_CHAR) != 0) return offset + step;
- length = segmentsText.length();
- offset = translateOffset(offset);
- SCRIPT_LOGATTR logAttr = new SCRIPT_LOGATTR();
- SCRIPT_PROPERTIES properties = new SCRIPT_PROPERTIES();
- int i = forward ? 0 : allRuns.length - 1;
- offset = validadeOffset(offset, step);
- do {
- StyleItem run = allRuns[i];
- if (run.start <= offset && offset < run.start + run.length) {
- if (run.lineBreak && !run.softBreak) return untranslateOffset(run.start);
- if (run.tab) return untranslateOffset(run.start);
- OS.MoveMemory(properties, device.scripts[run.analysis.eScript], SCRIPT_PROPERTIES.sizeof);
- boolean isComplex = properties.fNeedsCaretInfo || properties.fNeedsWordBreaking;
- if (isComplex) breakRun(run);
- while (run.start <= offset && offset < run.start + run.length) {
- if (isComplex) {
- OS.MoveMemory(logAttr, run.psla + ((offset - run.start) * SCRIPT_LOGATTR.sizeof), SCRIPT_LOGATTR.sizeof);
- }
- switch (movement) {
- case SWT.MOVEMENT_CLUSTER: {
- if (properties.fNeedsCaretInfo) {
- if (!logAttr.fInvalid && logAttr.fCharStop) return untranslateOffset(offset);
- } else {
- return untranslateOffset(offset);
- }
- break;
- }
- case SWT.MOVEMENT_WORD_START:
- case SWT.MOVEMENT_WORD: {
- if (properties.fNeedsWordBreaking) {
- if (!logAttr.fInvalid && logAttr.fWordStop) return untranslateOffset(offset);
- } else {
- if (offset > 0) {
- boolean letterOrDigit = Compatibility.isLetterOrDigit(segmentsText.charAt(offset));
- boolean previousLetterOrDigit = Compatibility.isLetterOrDigit(segmentsText.charAt(offset - 1));
- if (letterOrDigit != previousLetterOrDigit || !letterOrDigit) {
- if (!Compatibility.isWhitespace(segmentsText.charAt(offset))) {
- return untranslateOffset(offset);
- }
- }
- }
- }
- break;
- }
- case SWT.MOVEMENT_WORD_END: {
- if (offset > 0) {
- boolean isLetterOrDigit = Compatibility.isLetterOrDigit(segmentsText.charAt(offset));
- boolean previousLetterOrDigit = Compatibility.isLetterOrDigit(segmentsText.charAt(offset - 1));
- if (!isLetterOrDigit && previousLetterOrDigit) {
- return untranslateOffset(offset);
- }
- }
- break;
- }
- }
- offset = validadeOffset(offset, step);
- }
- }
- i += step;
- } while (0 <= i && i < allRuns.length - 1 && 0 <= offset && offset < length);
- return forward ? text.length() : 0;
-}
-
-/**
- * Returns the character offset for the specified point.
- * For a typical character, the trailing argument will be filled in to
- * indicate whether the point is closer to the leading edge (0) or
- * the trailing edge (1). When the point is over a cluster composed
- * of multiple characters, the trailing argument will be filled with the
- * position of the character in the cluster that is closest to
- * the point.
- *
- * @param point the point
- * @param trailing the trailing buffer
- * @return the character offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getLocation(int, boolean)
- */
-public int getOffset (Point point, int[] trailing) {
- checkLayout();
- if (point == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return getOffset (point.x, point.y, trailing) ;
-}
-
-/**
- * Returns the character offset for the specified point.
- * For a typical character, the trailing argument will be filled in to
- * indicate whether the point is closer to the leading edge (0) or
- * the trailing edge (1). When the point is over a cluster composed
- * of multiple characters, the trailing argument will be filled with the
- * position of the character in the cluster that is closest to
- * the point.
- *
- * @param x the x coordinate of the point
- * @param y the y coordinate of the point
- * @param trailing the trailing buffer
- * @return the character offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getLocation(int, boolean)
- */
-public int getOffset (int x, int y, int[] trailing) {
- checkLayout();
- computeRuns(null);
- if (trailing != null && trailing.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int line;
- int lineCount = runs.length;
- for (line=0; line<lineCount; line++) {
- if (lineY[line + 1] > y) break;
- }
- line = Math.min(line, runs.length - 1);
- StyleItem[] lineRuns = runs[line];
- int lineIndent = getLineIndent(line);
- if (x >= lineIndent + lineWidth[line]) x = lineIndent + lineWidth[line] - 1;
- if (x < lineIndent) x = lineIndent;
- int low = -1;
- int high = lineRuns.length;
- while (high - low > 1) {
- int index = ((high + low) / 2);
- StyleItem run = lineRuns[index];
- if (run.x > x) {
- high = index;
- } else if (run.x + run.width <= x) {
- low = index;
- } else {
- if (run.lineBreak && !run.softBreak) return untranslateOffset(run.start);
- int xRun = x - run.x;
- if (run.style != null && run.style.metrics != null) {
- GlyphMetrics metrics = run.style.metrics;
- if (metrics.width > 0) {
- if (trailing != null) {
- trailing[0] = (xRun % metrics.width < metrics.width / 2) ? 0 : 1;
- }
- return untranslateOffset(run.start + xRun / metrics.width);
- }
- }
- if (run.tab) {
- if (trailing != null) trailing[0] = x < (run.x + run.width / 2) ? 0 : 1;
- return untranslateOffset(run.start);
- }
- int cChars = run.length;
- int cGlyphs = run.glyphCount;
- int[] piCP = new int[1];
- int[] piTrailing = new int[1];
- if ((orientation & SWT.RIGHT_TO_LEFT) != 0) {
- xRun = run.width - xRun;
- }
- int /*long*/ advances = run.justify != 0 ? run.justify : run.advances;
- OS.ScriptXtoCP(xRun, cChars, cGlyphs, run.clusters, run.visAttrs, advances, run.analysis, piCP, piTrailing);
- if (trailing != null) trailing[0] = piTrailing[0];
- return untranslateOffset(run.start + piCP[0]);
- }
- }
- if (trailing != null) trailing[0] = 0;
- if (lineRuns.length == 1) {
- StyleItem run = lineRuns[0];
- if (run.lineBreak && !run.softBreak) return untranslateOffset(run.start);
- }
- return untranslateOffset(lineOffset[line + 1]);
-}
-
-/**
- * Returns the orientation of the receiver.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getOrientation () {
- checkLayout();
- return orientation;
-}
-
-void getPartialSelection(StyleItem run, int selectionStart, int selectionEnd, RECT rect) {
- int end = run.start + run.length - 1;
- int selStart = Math.max(selectionStart, run.start) - run.start;
- int selEnd = Math.min(selectionEnd, end) - run.start;
- int cChars = run.length;
- int gGlyphs = run.glyphCount;
- int[] piX = new int[1];
- int x = rect.left;
- int /*long*/ advances = run.justify != 0 ? run.justify : run.advances;
- OS.ScriptCPtoX(selStart, false, cChars, gGlyphs, run.clusters, run.visAttrs, advances, run.analysis, piX);
- int runX = (orientation & SWT.RIGHT_TO_LEFT) != 0 ? run.width - piX[0] : piX[0];
- rect.left = x + runX;
- OS.ScriptCPtoX(selEnd, true, cChars, gGlyphs, run.clusters, run.visAttrs, advances, run.analysis, piX);
- runX = (orientation & SWT.RIGHT_TO_LEFT) != 0 ? run.width - piX[0] : piX[0];
- rect.right = x + runX;
-}
-
-/**
- * Returns the previous offset for the specified offset and movement
- * type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>,
- * <code>SWT.MOVEMENT_CLUSTER</code> or <code>SWT.MOVEMENT_WORD</code>,
- * <code>SWT.MOVEMENT_WORD_END</code> or <code>SWT.MOVEMENT_WORD_START</code>.
- *
- * @param offset the start offset
- * @param movement the movement type
- * @return the previous offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getNextOffset(int, int)
- */
-public int getPreviousOffset (int offset, int movement) {
- checkLayout();
- return _getOffset (offset, movement, false);
-}
-
-/**
- * Gets the ranges of text that are associated with a <code>TextStyle</code>.
- *
- * @return the ranges, an array of offsets representing the start and end of each
- * text style.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getStyles()
- *
- * @since 3.2
- */
-public int[] getRanges () {
- checkLayout();
- int[] result = new int[stylesCount * 2];
- int count = 0;
- for (int i=0; i<stylesCount - 1; i++) {
- if (styles[i].style != null) {
- result[count++] = styles[i].start;
- result[count++] = styles[i + 1].start - 1;
- }
- }
- if (count != result.length) {
- int[] newResult = new int[count];
- System.arraycopy(result, 0, newResult, 0, count);
- result = newResult;
- }
- return result;
-}
-
-/**
- * Returns the text segments offsets of the receiver.
- *
- * @return the text segments offsets
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getSegments () {
- checkLayout();
- return segments;
-}
-
-String getSegmentsText() {
- if (segments == null) return text;
- int nSegments = segments.length;
- if (nSegments <= 1) return text;
- int length = text.length();
- if (length == 0) return text;
- if (nSegments == 2) {
- if (segments[0] == 0 && segments[1] == length) return text;
- }
- char[] oldChars = new char[length];
- text.getChars(0, length, oldChars, 0);
- char[] newChars = new char[length + nSegments];
- int charCount = 0, segmentCount = 0;
- char separator = orientation == SWT.RIGHT_TO_LEFT ? RTL_MARK : LTR_MARK;
- while (charCount < length) {
- if (segmentCount < nSegments && charCount == segments[segmentCount]) {
- newChars[charCount + segmentCount++] = separator;
- } else {
- newChars[charCount + segmentCount] = oldChars[charCount++];
- }
- }
- if (segmentCount < nSegments) {
- segments[segmentCount] = charCount;
- newChars[charCount + segmentCount++] = separator;
- }
- return new String(newChars, 0, Math.min(charCount + segmentCount, newChars.length));
-}
-
-/**
- * Returns the line spacing of the receiver.
- *
- * @return the line spacing
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getSpacing () {
- checkLayout();
- return lineSpacing;
-}
-
-/**
- * Gets the style of the receiver at the specified character offset.
- *
- * @param offset the text offset
- * @return the style or <code>null</code> if not set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public TextStyle getStyle (int offset) {
- checkLayout();
- int length = text.length();
- if (!(0 <= offset && offset < length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- for (int i=1; i<stylesCount; i++) {
- if (styles[i].start > offset) {
- return styles[i - 1].style;
- }
- }
- return null;
-}
-
-/**
- * Gets all styles of the receiver.
- *
- * @return the styles
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getRanges()
- *
- * @since 3.2
- */
-public TextStyle[] getStyles () {
- checkLayout();
- TextStyle[] result = new TextStyle[stylesCount];
- int count = 0;
- for (int i=0; i<stylesCount; i++) {
- if (styles[i].style != null) {
- result[count++] = styles[i].style;
- }
- }
- if (count != result.length) {
- TextStyle[] newResult = new TextStyle[count];
- System.arraycopy(result, 0, newResult, 0, count);
- result = newResult;
- }
- return result;
-}
-
-/**
- * Returns the tab list of the receiver.
- *
- * @return the tab list
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getTabs () {
- checkLayout();
- return tabs;
-}
-
-/**
- * Gets the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public String getText () {
- checkLayout();
- return text;
-}
-
-/**
- * Returns the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getWidth () {
- checkLayout();
- return wrapWidth;
-}
-
-/**
- * Returns <code>true</code> if the text layout has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the text layout.
- * When a text layout has been disposed, it is an error to
- * invoke any other method using the text layout.
- * </p>
- *
- * @return <code>true</code> when the text layout is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- return device == null;
-}
-
-/*
- * Itemize the receiver text
- */
-StyleItem[] itemize () {
- segmentsText = getSegmentsText();
- int length = segmentsText.length();
- SCRIPT_CONTROL scriptControl = new SCRIPT_CONTROL();
- SCRIPT_STATE scriptState = new SCRIPT_STATE();
- final int MAX_ITEM = length + 1;
-
- if ((orientation & SWT.RIGHT_TO_LEFT) != 0) {
- scriptState.uBidiLevel = 1;
- scriptState.fArabicNumContext = true;
- SCRIPT_DIGITSUBSTITUTE psds = new SCRIPT_DIGITSUBSTITUTE();
- OS.ScriptRecordDigitSubstitution(OS.LOCALE_USER_DEFAULT, psds);
- OS.ScriptApplyDigitSubstitution(psds, scriptControl, scriptState);
- }
-
- int /*long*/ hHeap = OS.GetProcessHeap();
- int /*long*/ pItems = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, MAX_ITEM * SCRIPT_ITEM.sizeof);
- if (pItems == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int[] pcItems = new int[1];
- char[] chars = new char[length];
- segmentsText.getChars(0, length, chars, 0);
- OS.ScriptItemize(chars, length, MAX_ITEM, scriptControl, scriptState, pItems, pcItems);
-// if (hr == E_OUTOFMEMORY) //TODO handle it
-
- StyleItem[] runs = merge(pItems, pcItems[0]);
- OS.HeapFree(hHeap, 0, pItems);
- return runs;
-}
-
-/*
- * Merge styles ranges and script items
- */
-StyleItem[] merge (int /*long*/ items, int itemCount) {
- if (styles.length > stylesCount) {
- StyleItem[] newStyles = new StyleItem[stylesCount];
- System.arraycopy(styles, 0, newStyles, 0, stylesCount);
- styles = newStyles;
- }
- int count = 0, start = 0, end = segmentsText.length(), itemIndex = 0, styleIndex = 0;
- StyleItem[] runs = new StyleItem[itemCount + stylesCount];
- SCRIPT_ITEM scriptItem = new SCRIPT_ITEM();
- int itemLimit = -1;
- int nextItemIndex = 0;
- boolean linkBefore = false;
- boolean merge = itemCount > TOO_MANY_RUNS;
- SCRIPT_PROPERTIES sp = new SCRIPT_PROPERTIES();
- while (start < end) {
- StyleItem item = new StyleItem();
- item.start = start;
- item.style = styles[styleIndex].style;
- runs[count++] = item;
- OS.MoveMemory(scriptItem, items + itemIndex * SCRIPT_ITEM.sizeof, SCRIPT_ITEM.sizeof);
- item.analysis = scriptItem.a;
- scriptItem.a = new SCRIPT_ANALYSIS();
- if (linkBefore) {
- item.analysis.fLinkBefore = true;
- linkBefore = false;
- }
- char ch = segmentsText.charAt(start);
- switch (ch) {
- case '\r':
- case '\n':
- item.lineBreak = true;
- break;
- case '\t':
- item.tab = true;
- break;
- }
- if (itemLimit == -1) {
- nextItemIndex = itemIndex + 1;
- OS.MoveMemory(scriptItem, items + nextItemIndex * SCRIPT_ITEM.sizeof, SCRIPT_ITEM.sizeof);
- itemLimit = scriptItem.iCharPos;
- if (nextItemIndex < itemCount && ch == '\r' && segmentsText.charAt(itemLimit) == '\n') {
- nextItemIndex = itemIndex + 2;
- OS.MoveMemory(scriptItem, items + nextItemIndex * SCRIPT_ITEM.sizeof, SCRIPT_ITEM.sizeof);
- itemLimit = scriptItem.iCharPos;
- }
- if (nextItemIndex < itemCount && merge) {
- if (!item.lineBreak) {
- OS.MoveMemory(sp, device.scripts[item.analysis.eScript], SCRIPT_PROPERTIES.sizeof);
- if (!sp.fComplex || item.tab) {
- for (int i = 0; i < MERGE_MAX; i++) {
- if (nextItemIndex == itemCount) break;
- char c = segmentsText.charAt(itemLimit);
- if (c == '\n' || c == '\r') break;
- if (c == '\t' != item.tab) break;
- OS.MoveMemory(sp, device.scripts[scriptItem.a.eScript], SCRIPT_PROPERTIES.sizeof);
- if (!item.tab && sp.fComplex) break;
- nextItemIndex++;
- OS.MoveMemory(scriptItem, items + nextItemIndex * SCRIPT_ITEM.sizeof, SCRIPT_ITEM.sizeof);
- itemLimit = scriptItem.iCharPos;
- }
- }
- }
- }
- }
-
- int styleLimit = translateOffset(styles[styleIndex + 1].start);
- if (styleLimit <= itemLimit) {
- styleIndex++;
- start = styleLimit;
- if (start < itemLimit && 0 < start && start < end) {
- char pChar = segmentsText.charAt(start - 1);
- char tChar = segmentsText.charAt(start);
- if (Compatibility.isLetter(pChar) && Compatibility.isLetter(tChar)) {
- item.analysis.fLinkAfter = true;
- linkBefore = true;
- }
- }
- }
- if (itemLimit <= styleLimit) {
- itemIndex = nextItemIndex;
- start = itemLimit;
- itemLimit = -1;
- }
- item.length = start - item.start;
- }
- StyleItem item = new StyleItem();
- item.start = end;
- OS.MoveMemory(scriptItem, items + itemCount * SCRIPT_ITEM.sizeof, SCRIPT_ITEM.sizeof);
- item.analysis = scriptItem.a;
- runs[count++] = item;
- if (runs.length != count) {
- StyleItem[] result = new StyleItem[count];
- System.arraycopy(runs, 0, result, 0, count);
- return result;
- }
- return runs;
-}
-
-/*
- * Reorder the run
- */
-StyleItem[] reorder (StyleItem[] runs, boolean terminate) {
- int length = runs.length;
- if (length <= 1) return runs;
- byte[] bidiLevels = new byte[length];
- for (int i=0; i<length; i++) {
- bidiLevels[i] = (byte)(runs[i].analysis.s.uBidiLevel & 0x1F);
- }
- /*
- * Feature in Windows. If the orientation is RTL Uniscribe will
- * resolve the level of line breaks to 1, this can cause the line
- * break to be reorder to the middle of the line. The fix is to set
- * the level to zero to prevent it to be reordered.
- */
- StyleItem lastRun = runs[length - 1];
- if (lastRun.lineBreak && !lastRun.softBreak) {
- bidiLevels[length - 1] = 0;
- }
- int[] log2vis = new int[length];
- OS.ScriptLayout(length, bidiLevels, null, log2vis);
- StyleItem[] result = new StyleItem[length];
- for (int i=0; i<length; i++) {
- result[log2vis[i]] = runs[i];
- }
- if ((orientation & SWT.RIGHT_TO_LEFT) != 0) {
- if (terminate) length--;
- for (int i = 0; i < length / 2 ; i++) {
- StyleItem tmp = result[i];
- result[i] = result[length - i - 1];
- result[length - i - 1] = tmp;
- }
- }
- return result;
-}
-
-/**
- * Sets the text alignment for the receiver. The alignment controls
- * how a line of text is positioned horizontally. The argument should
- * be one of <code>SWT.LEFT</code>, <code>SWT.RIGHT</code> or <code>SWT.CENTER</code>.
- * <p>
- * The default alignment is <code>SWT.LEFT</code>. Note that the receiver's
- * width must be set in order to use <code>SWT.RIGHT</code> or <code>SWT.CENTER</code>
- * alignment.
- * </p>
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setWidth(int)
- */
-public void setAlignment (int alignment) {
- checkLayout();
- int mask = SWT.LEFT | SWT.CENTER | SWT.RIGHT;
- alignment &= mask;
- if (alignment == 0) return;
- if ((alignment & SWT.LEFT) != 0) alignment = SWT.LEFT;
- if ((alignment & SWT.RIGHT) != 0) alignment = SWT.RIGHT;
- if (this.alignment == alignment) return;
- freeRuns();
- this.alignment = alignment;
-}
-
-/**
- * Sets the ascent of the receiver. The ascent is distance in pixels
- * from the baseline to the top of the line and it is applied to all
- * lines. The default value is <code>-1</code> which means that the
- * ascent is calculated from the line fonts.
- *
- * @param ascent the new ascent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the ascent is less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setDescent(int)
- * @see #getLineMetrics(int)
- */
-public void setAscent(int ascent) {
- checkLayout();
- if (ascent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.ascent == ascent) return;
- freeRuns();
- this.ascent = ascent;
-}
-
-/**
- * Sets the descent of the receiver. The descent is distance in pixels
- * from the baseline to the bottom of the line and it is applied to all
- * lines. The default value is <code>-1</code> which means that the
- * descent is calculated from the line fonts.
- *
- * @param descent the new descent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the descent is less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAscent(int)
- * @see #getLineMetrics(int)
- */
-public void setDescent(int descent) {
- checkLayout();
- if (descent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.descent == descent) return;
- freeRuns();
- this.descent = descent;
-}
-
-/**
- * Sets the default font which will be used by the receiver
- * to draw and measure text. If the
- * argument is null, then a default font appropriate
- * for the platform will be used instead. Note that a text
- * style can override the default font.
- *
- * @param font the new font for the receiver, or null to indicate a default font
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkLayout();
- if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Font oldFont = this.font;
- if (oldFont == font) return;
- this.font = font;
- if (oldFont != null && oldFont.equals(font)) return;
- freeRuns();
-}
-
-/**
- * Sets the indent of the receiver. This indent it applied of the first line of
- * each paragraph.
- *
- * @param indent new indent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setIndent (int indent) {
- checkLayout();
- if (indent < 0) return;
- if (this.indent == indent) return;
- freeRuns();
- this.indent = indent;
-}
-
-/**
- * Sets the justification of the receiver. Note that the receiver's
- * width must be set in order to use justification.
- *
- * @param justify new justify
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setJustify (boolean justify) {
- checkLayout();
- if (this.justify == justify) return;
- freeRuns();
- this.justify = justify;
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setOrientation (int orientation) {
- checkLayout();
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- orientation &= mask;
- if (orientation == 0) return;
- if ((orientation & SWT.LEFT_TO_RIGHT) != 0) orientation = SWT.LEFT_TO_RIGHT;
- if (this.orientation == orientation) return;
- this.orientation = orientation;
- freeRuns();
-}
-
-/**
- * Sets the offsets of the receiver's text segments. Text segments are used to
- * override the default behaviour of the bidirectional algorithm.
- * Bidirectional reordering can happen within a text segment but not
- * between two adjacent segments.
- * <p>
- * Each text segment is determined by two consecutive offsets in the
- * <code>segments</code> arrays. The first element of the array should
- * always be zero and the last one should always be equals to length of
- * the text.
- * </p>
- *
- * @param segments the text segments offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setSegments(int[] segments) {
- checkLayout();
- if (this.segments == null && segments == null) return;
- if (this.segments != null && segments != null) {
- if (this.segments.length == segments.length) {
- int i;
- for (i = 0; i <segments.length; i++) {
- if (this.segments[i] != segments[i]) break;
- }
- if (i == segments.length) return;
- }
- }
- freeRuns();
- this.segments = segments;
-}
-
-/**
- * Sets the line spacing of the receiver. The line spacing
- * is the space left between lines.
- *
- * @param spacing the new line spacing
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the spacing is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setSpacing (int spacing) {
- checkLayout();
- if (spacing < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.lineSpacing == spacing) return;
- freeRuns();
- this.lineSpacing = spacing;
-}
-
-/**
- * Sets the style of the receiver for the specified range. Styles previously
- * set for that range will be overwritten. The start and end offsets are
- * inclusive and will be clamped if out of range.
- *
- * @param style the style
- * @param start the start offset
- * @param end the end offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setStyle (TextStyle style, int start, int end) {
- checkLayout();
- int length = text.length();
- if (length == 0) return;
- if (start > end) return;
- start = Math.min(Math.max(0, start), length - 1);
- end = Math.min(Math.max(0, end), length - 1);
- int low = -1;
- int high = stylesCount;
- while (high - low > 1) {
- int index = (high + low) / 2;
- if (styles[index + 1].start > start) {
- high = index;
- } else {
- low = index;
- }
- }
- if (0 <= high && high < stylesCount) {
- StyleItem item = styles[high];
- if (item.start == start && styles[high + 1].start - 1 == end) {
- if (style == null) {
- if (item.style == null) return;
- } else {
- if (style.equals(item.style)) return;
- }
- }
- }
- freeRuns();
- int modifyStart = high;
- int modifyEnd = modifyStart;
- while (modifyEnd < stylesCount) {
- if (styles[modifyEnd + 1].start > end) break;
- modifyEnd++;
- }
- if (modifyStart == modifyEnd) {
- int styleStart = styles[modifyStart].start;
- int styleEnd = styles[modifyEnd + 1].start - 1;
- if (styleStart == start && styleEnd == end) {
- styles[modifyStart].style = style;
- return;
- }
- if (styleStart != start && styleEnd != end) {
- int newLength = stylesCount + 2;
- if (newLength > styles.length) {
- int newSize = Math.min(newLength + 1024, Math.max(64, newLength * 2));
- StyleItem[] newStyles = new StyleItem[newSize];
- System.arraycopy(styles, 0, newStyles, 0, stylesCount);
- styles = newStyles;
- }
- System.arraycopy(styles, modifyEnd + 1, styles, modifyEnd + 3, stylesCount - modifyEnd - 1);
- StyleItem item = new StyleItem();
- item.start = start;
- item.style = style;
- styles[modifyStart + 1] = item;
- item = new StyleItem();
- item.start = end + 1;
- item.style = styles[modifyStart].style;
- styles[modifyStart + 2] = item;
- stylesCount = newLength;
- return;
- }
- }
- if (start == styles[modifyStart].start) modifyStart--;
- if (end == styles[modifyEnd + 1].start - 1) modifyEnd++;
- int newLength = stylesCount + 1 - (modifyEnd - modifyStart - 1);
- if (newLength > styles.length) {
- int newSize = Math.min(newLength + 1024, Math.max(64, newLength * 2));
- StyleItem[] newStyles = new StyleItem[newSize];
- System.arraycopy(styles, 0, newStyles, 0, stylesCount);
- styles = newStyles;
- }
- System.arraycopy(styles, modifyEnd, styles, modifyStart + 2, stylesCount - modifyEnd);
- StyleItem item = new StyleItem();
- item.start = start;
- item.style = style;
- styles[modifyStart + 1] = item;
- styles[modifyStart + 2].start = end + 1;
- stylesCount = newLength;
-}
-
-/**
- * Sets the receiver's tab list. Each value in the tab list specifies
- * the space in pixels from the origin of the text layout to the respective
- * tab stop. The last tab stop width is repeated continuously.
- *
- * @param tabs the new tab list
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setTabs (int[] tabs) {
- checkLayout();
- if (this.tabs == null && tabs == null) return;
- if (this.tabs != null && tabs !=null) {
- if (this.tabs.length == tabs.length) {
- int i;
- for (i = 0; i <tabs.length; i++) {
- if (this.tabs[i] != tabs[i]) break;
- }
- if (i == tabs.length) return;
- }
- }
- freeRuns();
- this.tabs = tabs;
-}
-
-/**
- * Sets the receiver's text.
- *<p>
- * Note: Setting the text also clears all the styles. This method
- * returns without doing anything if the new text is the same as
- * the current text.
- * </p>
- *
- * @param text the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setText (String text) {
- checkLayout();
- if (text == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (text.equals(this.text)) return;
- freeRuns();
- this.text = text;
- styles = new StyleItem[2];
- styles[0] = new StyleItem();
- styles[1] = new StyleItem();
- styles[1].start = text.length();
- stylesCount = 2;
-}
-
-/**
- * Sets the line width of the receiver, which determines how
- * text should be wrapped and aligned. The default value is
- * <code>-1</code> which means wrapping is disabled.
- *
- * @param width the new width
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the width is <code>0</code> or less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAlignment(int)
- */
-public void setWidth (int width) {
- checkLayout();
- if (width < -1 || width == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.wrapWidth == width) return;
- freeRuns();
- this.wrapWidth = width;
-}
-
-boolean shape (int /*long*/ hdc, StyleItem run, char[] chars, int[] glyphCount, int maxGlyphs, SCRIPT_PROPERTIES sp) {
- boolean useCMAPcheck = !sp.fComplex && !run.analysis.fNoGlyphIndex;
- if (useCMAPcheck) {
- short[] glyphs = new short[chars.length];
- if (OS.ScriptGetCMap(hdc, run.psc, chars, chars.length, 0, glyphs) != OS.S_OK) {
- if (run.psc != 0) {
- OS.ScriptFreeCache(run.psc);
- glyphCount[0] = 0;
- OS.MoveMemory(run.psc, new int /*long*/ [1], OS.PTR_SIZEOF);
- }
- return false;
- }
- }
- int hr = OS.ScriptShape(hdc, run.psc, chars, chars.length, maxGlyphs, run.analysis, run.glyphs, run.clusters, run.visAttrs, glyphCount);
- run.glyphCount = glyphCount[0];
- if (useCMAPcheck) return true;
-
- if (hr != OS.USP_E_SCRIPT_NOT_IN_FONT) {
- if (run.analysis.fNoGlyphIndex) return true;
- SCRIPT_FONTPROPERTIES fp = new SCRIPT_FONTPROPERTIES ();
- fp.cBytes = SCRIPT_FONTPROPERTIES.sizeof;
- OS.ScriptGetFontProperties(hdc, run.psc, fp);
- short[] glyphs = new short[glyphCount[0]];
- OS.MoveMemory(glyphs, run.glyphs, glyphs.length * 2);
- int i;
- for (i = 0; i < glyphs.length; i++) {
- if (glyphs[i] == fp.wgDefault) break;
- }
- if (i == glyphs.length) return true;
- }
- if (run.psc != 0) {
- OS.ScriptFreeCache(run.psc);
- glyphCount[0] = 0;
- OS.MoveMemory(run.psc, new int /*long*/ [1], OS.PTR_SIZEOF);
- }
- run.glyphCount = 0;
- return false;
-}
-
-/*
- * Generate glyphs for one Run.
- */
-void shape (final int /*long*/ hdc, final StyleItem run) {
- if (run.tab || run.lineBreak) return;
- if (run.glyphs != 0) return;
- final int[] buffer = new int[1];
- final char[] chars = new char[run.length];
- segmentsText.getChars(run.start, run.start + run.length, chars, 0);
-
- final int maxGlyphs = (chars.length * 3 / 2) + 16;
- int /*long*/ hHeap = OS.GetProcessHeap();
- run.glyphs = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, maxGlyphs * 2);
- if (run.glyphs == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- run.clusters = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, maxGlyphs * 2);
- if (run.clusters == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- run.visAttrs = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, maxGlyphs * SCRIPT_VISATTR_SIZEOF);
- if (run.visAttrs == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- run.psc = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, OS.PTR_SIZEOF);
- if (run.psc == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- final short script = run.analysis.eScript;
- final SCRIPT_PROPERTIES sp = new SCRIPT_PROPERTIES();
- OS.MoveMemory(sp, device.scripts[script], SCRIPT_PROPERTIES.sizeof);
- boolean shapeSucceed = shape(hdc, run, chars, buffer, maxGlyphs, sp);
- if (!shapeSucceed) {
- int /*long*/ hFont = OS.GetCurrentObject(hdc, OS.OBJ_FONT);
- int /*long*/ newFont = 0;
- /*
- * Bug in Uniscribe. In some version of Uniscribe, ScriptStringAnalyse crashes
- * when the character array is too long. The fix is to limit the size of character
- * array to two. Note, limiting the array to only one character would cause surrogate
- * pairs to stop working.
- */
- char[] sampleChars = new char[Math.min(chars.length, 2)];
- SCRIPT_LOGATTR logAttr = new SCRIPT_LOGATTR();
- breakRun(run);
- int count = 0;
- for (int i = 0; i < chars.length; i++) {
- OS.MoveMemory(logAttr, run.psla + (i * SCRIPT_LOGATTR.sizeof), SCRIPT_LOGATTR.sizeof);
- if (!logAttr.fWhiteSpace) {
- sampleChars[count++] = chars[i];
- if (count == sampleChars.length) break;
- }
- }
- if (count > 0) {
- int /*long*/ ssa = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, OS.SCRIPT_STRING_ANALYSIS_sizeof());
- int /*long*/ metaFileDc = OS.CreateEnhMetaFile(hdc, null, null, null);
- int /*long*/ oldMetaFont = OS.SelectObject(metaFileDc, hFont);
- int flags = OS.SSA_METAFILE | OS.SSA_FALLBACK | OS.SSA_GLYPHS | OS.SSA_LINK;
- if (OS.ScriptStringAnalyse(metaFileDc, sampleChars, count, 0, -1, flags, 0, null, null, 0, 0, 0, ssa) == OS.S_OK) {
- OS.ScriptStringOut(ssa, 0, 0, 0, null, 0, 0, false);
- OS.ScriptStringFree(ssa);
- }
- OS.HeapFree(hHeap, 0, ssa);
- OS.SelectObject(metaFileDc, oldMetaFont);
- int /*long*/ metaFile = OS.CloseEnhMetaFile(metaFileDc);
- final EMREXTCREATEFONTINDIRECTW emr = new EMREXTCREATEFONTINDIRECTW();
- class MetaFileEnumProc {
- int /*long*/ metaFileEnumProc (int /*long*/ hDC, int /*long*/ table, int /*long*/ record, int /*long*/ nObj, int /*long*/ lpData) {
- OS.MoveMemory(emr.emr, record, EMR.sizeof);
- switch (emr.emr.iType) {
- case OS.EMR_EXTCREATEFONTINDIRECTW:
- OS.MoveMemory(emr, record, EMREXTCREATEFONTINDIRECTW.sizeof);
- break;
- case OS.EMR_EXTTEXTOUTW:
- return 0;
- }
- return 1;
- }
- };
- MetaFileEnumProc object = new MetaFileEnumProc();
- /* Avoid compiler warnings */
- boolean compilerWarningWorkaround = false;
- if (compilerWarningWorkaround) object.metaFileEnumProc(0, 0, 0, 0, 0);
- Callback callback = new Callback(object, "metaFileEnumProc", 5);
- int /*long*/ address = callback.getAddress();
- if (address == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- OS.EnumEnhMetaFile(0, metaFile, address, 0, null);
- OS.DeleteEnhMetaFile(metaFile);
- callback.dispose();
- newFont = OS.CreateFontIndirectW(emr.elfw.elfLogFont);
- } else {
- /*
- * The run is composed only by white spaces, this happens when a run is split
- * by a visual style. The font fallback for the script can not be determined
- * using only white spaces. The solution is to use the font fallback of the
- * previous or next run of the same script.
- */
- int index = 0;
- while (index < allRuns.length - 1) {
- if (allRuns[index] == run) {
- if (index > 0) {
- StyleItem pRun = allRuns[index - 1];
- if (pRun.fallbackFont != 0 && pRun.analysis.eScript == run.analysis.eScript) {
- LOGFONT logFont = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA();
- OS.GetObject(pRun.fallbackFont, LOGFONT.sizeof, logFont);
- newFont = OS.CreateFontIndirect(logFont);
- }
- }
- if (newFont == 0) {
- if (index + 1 < allRuns.length - 1) {
- StyleItem nRun = allRuns[index + 1];
- if (nRun.analysis.eScript == run.analysis.eScript) {
- shape(hdc, nRun);
- if (nRun.fallbackFont != 0) {
- LOGFONT logFont = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA();
- OS.GetObject(nRun.fallbackFont, LOGFONT.sizeof, logFont);
- newFont = OS.CreateFontIndirect(logFont);
- }
- }
- }
- }
- break;
- }
- index++;
- }
- }
- if (newFont != 0) {
- OS.SelectObject(hdc, newFont);
- if (shapeSucceed = shape(hdc, run, chars, buffer, maxGlyphs, sp)) {
- run.fallbackFont = newFont;
- }
- }
- if (!shapeSucceed) {
- if (!sp.fComplex) {
- run.analysis.fNoGlyphIndex = true;
- if (shapeSucceed = shape(hdc, run, chars, buffer, maxGlyphs, sp)) {
- run.fallbackFont = newFont;
- } else {
- run.analysis.fNoGlyphIndex = false;
- }
- }
- }
- if (!shapeSucceed) {
- if (mLangFontLink2 != 0) {
- int /*long*/[] hNewFont = new int /*long*/[1];
- int[] dwCodePages = new int[1], cchCodePages = new int[1];
- /* GetStrCodePages() */
- OS.VtblCall(4, mLangFontLink2, chars, chars.length, 0, dwCodePages, cchCodePages);
- /* MapFont() */
- if (OS.VtblCall(10, mLangFontLink2, hdc, dwCodePages[0], chars[0], hNewFont) == OS.S_OK) {
- LOGFONT logFont = OS.IsUnicode ? (LOGFONT)new LOGFONTW () : new LOGFONTA ();
- OS.GetObject(hNewFont[0], LOGFONT.sizeof, logFont);
- /* ReleaseFont() */
- OS.VtblCall(8, mLangFontLink2, hNewFont[0]);
- int /*long*/ mLangFont = OS.CreateFontIndirect(logFont);
- int /*long*/ oldFont = OS.SelectObject(hdc, mLangFont);
- if (shapeSucceed = shape(hdc, run, chars, buffer, maxGlyphs, sp)) {
- run.fallbackFont = mLangFont;
- } else {
- OS.SelectObject(hdc, oldFont);
- OS.DeleteObject(mLangFont);
- }
- }
- }
- }
- if (!shapeSucceed) OS.SelectObject(hdc, hFont);
- if (newFont != 0 && newFont != run.fallbackFont) OS.DeleteObject(newFont);
- }
-
- if (!shapeSucceed) {
- /*
- * Shape Failed.
- * Give up and shape the run with the default font.
- * Missing glyphs typically will be represent as black boxes in the text.
- */
- OS.ScriptShape(hdc, run.psc, chars, chars.length, maxGlyphs, run.analysis, run.glyphs, run.clusters, run.visAttrs, buffer);
- run.glyphCount = buffer[0];
- }
- int[] abc = new int[3];
- run.advances = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, run.glyphCount * 4);
- if (run.advances == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- run.goffsets = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, run.glyphCount * GOFFSET_SIZEOF);
- if (run.goffsets == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.ScriptPlace(hdc, run.psc, run.glyphs, run.glyphCount, run.visAttrs, run.analysis, run.advances, run.goffsets, abc);
- run.width = abc[0] + abc[1] + abc[2];
- TextStyle style = run.style;
- if (style != null) {
- OUTLINETEXTMETRIC lotm = null;
- if (style.underline || style.strikeout) {
- lotm = OS.IsUnicode ? (OUTLINETEXTMETRIC)new OUTLINETEXTMETRICW() : new OUTLINETEXTMETRICA();
- if (OS.GetOutlineTextMetrics(hdc, OUTLINETEXTMETRIC.sizeof, lotm) == 0) {
- lotm = null;
- }
- }
- if (style.metrics != null) {
- GlyphMetrics metrics = style.metrics;
- /*
- * Bug in Windows, on a Japanese machine, Uniscribe returns glyphcount
- * equals zero for FFFC (possibly other unicode code points), the fix
- * is to make sure the glyph is at least one pixel wide.
- */
- run.width = metrics.width * Math.max (1, run.glyphCount);
- run.ascent = metrics.ascent;
- run.descent = metrics.descent;
- run.leading = 0;
- } else {
- TEXTMETRIC lptm = null;
- if (lotm != null) {
- lptm = OS.IsUnicode ? (TEXTMETRIC)((OUTLINETEXTMETRICW)lotm).otmTextMetrics : ((OUTLINETEXTMETRICA)lotm).otmTextMetrics;
- } else {
- lptm = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA();
- OS.GetTextMetrics(hdc, lptm);
- }
- run.ascent = lptm.tmAscent;
- run.descent = lptm.tmDescent;
- run.leading = lptm.tmInternalLeading;
- }
- if (lotm != null) {
- run.underlinePos = lotm.otmsUnderscorePosition;
- run.underlineThickness = Math.max(1, lotm.otmsUnderscoreSize);
- run.strikeoutPos = lotm.otmsStrikeoutPosition;
- run.strikeoutThickness = Math.max(1, lotm.otmsStrikeoutSize);
- } else {
- run.underlinePos = 1;
- run.underlineThickness = 1;
- run.strikeoutPos = run.ascent / 2;
- run.strikeoutThickness = 1;
- }
- run.ascent += style.rise;
- run.descent -= style.rise;
- } else {
- TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA();
- OS.GetTextMetrics(hdc, lptm);
- run.ascent = lptm.tmAscent;
- run.descent = lptm.tmDescent;
- run.leading = lptm.tmInternalLeading;
- }
-}
-
-int validadeOffset(int offset, int step) {
- offset += step;
- if (segments != null && segments.length > 2) {
- for (int i = 0; i < segments.length; i++) {
- if (translateOffset(segments[i]) - 1 == offset) {
- offset += step;
- break;
- }
- }
- }
- return offset;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "TextLayout {*DISPOSED*}";
- return "TextLayout {}";
-}
-
-int translateOffset(int offset) {
- if (segments == null) return offset;
- int nSegments = segments.length;
- if (nSegments <= 1) return offset;
- int length = text.length();
- if (length == 0) return offset;
- if (nSegments == 2) {
- if (segments[0] == 0 && segments[1] == length) return offset;
- }
- for (int i = 0; i < nSegments && offset - i >= segments[i]; i++) {
- offset++;
- }
- return offset;
-}
-
-int untranslateOffset(int offset) {
- if (segments == null) return offset;
- int nSegments = segments.length;
- if (nSegments <= 1) return offset;
- int length = text.length();
- if (length == 0) return offset;
- if (nSegments == 2) {
- if (segments[0] == 0 && segments[1] == length) return offset;
- }
- for (int i = 0; i < nSegments && offset > segments[i]; i++) {
- offset--;
- }
- return offset;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Transform.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Transform.java
deleted file mode 100644
index c4236ad294..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Transform.java
+++ /dev/null
@@ -1,369 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gdip.*;
-
-/**
- * Instances of this class represent transformation matrices for
- * points expressed as (x, y) pairs of floating point numbers.
- * <p>
- * Application code must explicitly invoke the <code>Transform.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Transform extends Resource {
-
- /**
- * the OS resource for the Transform
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
-
-/**
- * Constructs a new identity Transform.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform (Device device) {
- this(device, 1, 0, 0, 1, 0, 0);
-}
-
-/**
- * Constructs a new Transform given an array of elements that represent the
- * matrix that describes the transformation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- * @param elements an array of floats that describe the transformation matrix
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device, or the elements array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the elements array is too small to hold the matrix values</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform(Device device, float[] elements) {
- this (device, checkTransform(elements)[0], elements[1], elements[2], elements[3], elements[4], elements[5]);
-}
-
-/**
- * Constructs a new Transform given all of the elements that represent the
- * matrix that describes the transformation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- * @param m11 the first element of the first row of the matrix
- * @param m12 the second element of the first row of the matrix
- * @param m21 the first element of the second row of the matrix
- * @param m22 the second element of the second row of the matrix
- * @param dx the third element of the first row of the matrix
- * @param dy the third element of the second row of the matrix
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform (Device device, float m11, float m12, float m21, float m22, float dx, float dy) {
- super(device);
- this.device.checkGDIP();
- handle = Gdip.Matrix_new(m11, m12, m21, m22, dx, dy);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-static float[] checkTransform(float[] elements) {
- if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return elements;
-}
-
-void destroy() {
- Gdip.Matrix_delete(handle);
- handle = 0;
-}
-
-/**
- * Fills the parameter with the values of the transformation matrix
- * that the receiver represents, in the order {m11, m12, m21, m22, dx, dy}.
- *
- * @param elements array to hold the matrix values
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the matrix values</li>
- * </ul>
- */
-public void getElements(float[] elements) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Gdip.Matrix_GetElements(handle, elements);
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes the
- * identity matrix.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public void identity() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Gdip.Matrix_SetElements(handle, 1, 0, 0, 1, 0, 0);
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes
- * the mathematical inverse of the matrix it previously represented.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_CANNOT_INVERT_MATRIX - if the matrix is not invertible</li>
- * </ul>
- */
-public void invert() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (Gdip.Matrix_Invert(handle) != 0) SWT.error(SWT.ERROR_CANNOT_INVERT_MATRIX);
-}
-
-/**
- * Returns <code>true</code> if the Transform has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Transform.
- * When a Transform has been disposed, it is an error to
- * invoke any other method using the Transform.
- *
- * @return <code>true</code> when the Transform is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns <code>true</code> if the Transform represents the identity matrix
- * and false otherwise.
- *
- * @return <code>true</code> if the receiver is an identity Transform, and <code>false</code> otherwise
- */
-public boolean isIdentity() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return Gdip.Matrix_IsIdentity(handle);
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes the
- * the result of multiplying the matrix it previously represented by the
- * argument.
- *
- * @param matrix the matrix to multiply the receiver by
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- */
-public void multiply(Transform matrix) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (matrix == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (matrix.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Gdip.Matrix_Multiply(handle, matrix.handle, Gdip.MatrixOrderPrepend);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation rotated by the specified angle.
- * The angle is specified in degrees and for the identity transform 0 degrees
- * is at the 3 o'clock position. A positive value indicates a clockwise rotation
- * while a negative value indicates a counter-clockwise rotation.
- *
- * @param angle the angle to rotate the transformation by
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void rotate(float angle) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Gdip.Matrix_Rotate(handle, angle, Gdip.MatrixOrderPrepend);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation scaled by (scaleX, scaleY).
- *
- * @param scaleX the amount to scale in the X direction
- * @param scaleY the amount to scale in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void scale(float scaleX, float scaleY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Gdip.Matrix_Scale(handle, scaleX, scaleY, Gdip.MatrixOrderPrepend);
-}
-
-/**
- * Modifies the receiver to represent a new transformation given all of
- * the elements that represent the matrix that describes that transformation.
- *
- * @param m11 the first element of the first row of the matrix
- * @param m12 the second element of the first row of the matrix
- * @param m21 the first element of the second row of the matrix
- * @param m22 the second element of the second row of the matrix
- * @param dx the third element of the first row of the matrix
- * @param dy the third element of the second row of the matrix
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setElements(float m11, float m12, float m21, float m22, float dx, float dy) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Gdip.Matrix_SetElements(handle, m11, m12, m21, m22, dx, dy);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation sheared by (shearX, shearY).
- *
- * @param shearX the shear factor in the X direction
- * @param shearY the shear factor in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public void shear(float shearX, float shearY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Gdip.Matrix_Shear(handle, shearX, shearY, Gdip.MatrixOrderPrepend);
-}
-
-/**
- * Given an array containing points described by alternating x and y values,
- * modify that array such that each point has been replaced with the result of
- * applying the transformation represented by the receiver to that point.
- *
- * @param pointArray an array of alternating x and y values to be transformed
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void transform(float[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- Gdip.Matrix_TransformPoints(handle, pointArray, pointArray.length / 2);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation translated by (offsetX, offsetY).
- *
- * @param offsetX the distance to translate in the X direction
- * @param offsetY the distance to translate in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void translate(float offsetX, float offsetY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Gdip.Matrix_Translate(handle, offsetX, offsetY, Gdip.MatrixOrderPrepend);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString() {
- if (isDisposed()) return "Transform {*DISPOSED*}";
- float[] elements = new float[6];
- getElements(elements);
- return "Transform {" + elements [0] + "," + elements [1] + "," +elements [2] + "," +elements [3] + "," +elements [4] + "," +elements [5] + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/BidiUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/BidiUtil.java
deleted file mode 100644
index ebd449179e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/BidiUtil.java
+++ /dev/null
@@ -1,642 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal;
-
-
-import java.util.Hashtable;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.widgets.*;
-/*
- * Wraps Win32 API used to bidi enable the StyledText widget.
- */
-public class BidiUtil {
-
- // Keyboard language ids
- public static final int KEYBOARD_NON_BIDI = 0;
- public static final int KEYBOARD_BIDI = 1;
-
- // bidi flag
- static int isBidiPlatform = -1;
-
- // getRenderInfo flag values
- public static final int CLASSIN = 1;
- public static final int LINKBEFORE = 2;
- public static final int LINKAFTER = 4;
-
- // variables used for providing a listener mechanism for keyboard language
- // switching
- static Hashtable languageMap = new Hashtable ();
- static Hashtable keyMap = new Hashtable ();
- static Hashtable oldProcMap = new Hashtable ();
- /*
- * This code is intentionally commented. In order
- * to support CLDC, .class cannot be used because
- * it does not compile on some Java compilers when
- * they are targeted for CLDC.
- */
- // static Callback callback = new Callback (BidiUtil.class, "windowProc", 4);
- static final String CLASS_NAME = "org.eclipse.swt.internal.BidiUtil"; //$NON-NLS-1$
- static Callback callback;
- static {
- try {
- callback = new Callback (Class.forName (CLASS_NAME), "windowProc", 4); //$NON-NLS-1$
- if (callback.getAddress () == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- } catch (ClassNotFoundException e) {}
- }
-
- // GetCharacterPlacement constants
- static final int GCP_REORDER = 0x0002;
- static final int GCP_GLYPHSHAPE = 0x0010;
- static final int GCP_LIGATE = 0x0020;
- static final int GCP_CLASSIN = 0x00080000;
- static final byte GCPCLASS_ARABIC = 2;
- static final byte GCPCLASS_HEBREW = 2;
- static final byte GCPCLASS_LOCALNUMBER = 4;
- static final byte GCPCLASS_LATINNUMBER = 5;
- static final int GCPGLYPH_LINKBEFORE = 0x8000;
- static final int GCPGLYPH_LINKAFTER = 0x4000;
- // ExtTextOut constants
- static final int ETO_CLIPPED = 0x4;
- static final int ETO_GLYPH_INDEX = 0x0010;
- // Windows primary language identifiers
- static final int LANG_ARABIC = 0x01;
- static final int LANG_HEBREW = 0x0d;
- static final int LANG_FARSI = 0x29;
- // code page identifiers
- static final String CD_PG_HEBREW = "1255"; //$NON-NLS-1$
- static final String CD_PG_ARABIC = "1256"; //$NON-NLS-1$
- // ActivateKeyboard constants
- static final int HKL_NEXT = 1;
- static final int HKL_PREV = 0;
-
- /*
- * Public character class constants are the same as Windows
- * platform constants.
- * Saves conversion of class array in getRenderInfo to arbitrary
- * constants for now.
- */
- public static final int CLASS_HEBREW = GCPCLASS_ARABIC;
- public static final int CLASS_ARABIC = GCPCLASS_HEBREW;
- public static final int CLASS_LOCALNUMBER = GCPCLASS_LOCALNUMBER;
- public static final int CLASS_LATINNUMBER = GCPCLASS_LATINNUMBER;
- public static final int REORDER = GCP_REORDER;
- public static final int LIGATE = GCP_LIGATE;
- public static final int GLYPHSHAPE = GCP_GLYPHSHAPE;
-
-/**
- * Adds a language listener. The listener will get notified when the language of
- * the keyboard changes (via Alt-Shift on Win platforms). Do this by creating a
- * window proc for the Control so that the window messages for the Control can be
- * monitored.
- * <p>
- *
- * @param hwnd the handle of the Control that is listening for keyboard language
- * changes
- * @param runnable the code that should be executed when a keyboard language change
- * occurs
- */
-public static void addLanguageListener (int /*long*/ hwnd, Runnable runnable) {
- languageMap.put(new LONG(hwnd), runnable);
- subclass(hwnd);
-}
-public static void addLanguageListener (Control control, Runnable runnable) {
- addLanguageListener(control.handle, runnable);
-}
-/**
- * Proc used for OS.EnumSystemLanguageGroups call during isBidiPlatform test.
- */
-static int /*long*/ EnumSystemLanguageGroupsProc(int /*long*/ lpLangGrpId, int /*long*/ lpLangGrpIdString, int /*long*/ lpLangGrpName, int /*long*/ options, int /*long*/ lParam) {
- if ((int)/*64*/lpLangGrpId == OS.LGRPID_HEBREW) {
- isBidiPlatform = 1;
- return 0;
- }
- if ((int)/*64*/lpLangGrpId == OS.LGRPID_ARABIC) {
- isBidiPlatform = 1;
- return 0;
- }
- return 1;
-}
-/**
- * Wraps the ExtTextOut function.
- * <p>
- *
- * @param gc the gc to use for rendering
- * @param renderBuffer the glyphs to render as an array of characters
- * @param renderDx the width of each glyph in renderBuffer
- * @param x x position to start rendering
- * @param y y position to start rendering
- */
-public static void drawGlyphs(GC gc, char[] renderBuffer, int[] renderDx, int x, int y) {
- int length = renderDx.length;
-
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
- if (OS.GetLayout (gc.handle) != 0) {
- reverse(renderDx);
- renderDx[length-1]--; //fixes bug 40006
- reverse(renderBuffer);
- }
- }
- // render transparently to avoid overlapping segments. fixes bug 40006
- int oldBkMode = OS.SetBkMode(gc.handle, OS.TRANSPARENT);
- OS.ExtTextOutW(gc.handle, x, y, ETO_GLYPH_INDEX , null, renderBuffer, renderBuffer.length, renderDx);
- OS.SetBkMode(gc.handle, oldBkMode);
-}
-/**
- * Return ordering and rendering information for the given text. Wraps the GetFontLanguageInfo
- * and GetCharacterPlacement functions.
- * <p>
- *
- * @param gc the GC to use for measuring of this line, input parameter
- * @param text text that bidi data should be calculated for, input parameter
- * @param order an array of integers representing the visual position of each character in
- * the text array, output parameter
- * @param classBuffer an array of integers representing the type (e.g., ARABIC, HEBREW,
- * LOCALNUMBER) of each character in the text array, input/output parameter
- * @param dx an array of integers representing the pixel width of each glyph in the returned
- * glyph buffer, output parameter
- * @param flags an integer representing rendering flag information, input parameter
- * @param offsets text segments that should be measured and reordered separately, input
- * parameter. See org.eclipse.swt.custom.BidiSegmentEvent for details.
- * @return buffer with the glyphs that should be rendered for the given text
- */
-public static char[] getRenderInfo(GC gc, String text, int[] order, byte[] classBuffer, int[] dx, int flags, int [] offsets) {
- int fontLanguageInfo = OS.GetFontLanguageInfo(gc.handle);
- int /*long*/ hHeap = OS.GetProcessHeap();
- int[] lpCs = new int[8];
- int cs = OS.GetTextCharset(gc.handle);
- boolean isRightOriented = false;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
- isRightOriented = OS.GetLayout(gc.handle) != 0;
- }
- OS.TranslateCharsetInfo(cs, lpCs, OS.TCI_SRCCHARSET);
- TCHAR textBuffer = new TCHAR(lpCs[1], text, false);
- int byteCount = textBuffer.length();
- boolean linkBefore = (flags & LINKBEFORE) == LINKBEFORE;
- boolean linkAfter = (flags & LINKAFTER) == LINKAFTER;
-
- GCP_RESULTS result = new GCP_RESULTS();
- result.lStructSize = GCP_RESULTS.sizeof;
- result.nGlyphs = byteCount;
- int /*long*/ lpOrder = result.lpOrder = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount * 4);
- int /*long*/ lpDx = result.lpDx = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount * 4);
- int /*long*/ lpClass = result.lpClass = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- int /*long*/ lpGlyphs = result.lpGlyphs = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount * 2);
-
- // set required dwFlags
- int dwFlags = 0;
- int glyphFlags = 0;
- // Always reorder. We assume that if we are calling this function we're
- // on a platform that supports bidi. Fixes 20690.
- dwFlags |= GCP_REORDER;
- if ((fontLanguageInfo & GCP_LIGATE) == GCP_LIGATE) {
- dwFlags |= GCP_LIGATE;
- glyphFlags |= 0;
- }
- if ((fontLanguageInfo & GCP_GLYPHSHAPE) == GCP_GLYPHSHAPE) {
- dwFlags |= GCP_GLYPHSHAPE;
- if (linkBefore) {
- glyphFlags |= GCPGLYPH_LINKBEFORE;
- }
- if (linkAfter) {
- glyphFlags |= GCPGLYPH_LINKAFTER;
- }
- }
- byte[] lpGlyphs2;
- if (linkBefore || linkAfter) {
- lpGlyphs2 = new byte[2];
- lpGlyphs2[0]=(byte)glyphFlags;
- lpGlyphs2[1]=(byte)(glyphFlags >> 8);
- }
- else {
- lpGlyphs2 = new byte[] {(byte) glyphFlags};
- }
- OS.MoveMemory(result.lpGlyphs, lpGlyphs2, lpGlyphs2.length);
-
- if ((flags & CLASSIN) == CLASSIN) {
- // set classification values for the substring
- dwFlags |= GCP_CLASSIN;
- OS.MoveMemory(result.lpClass, classBuffer, classBuffer.length);
- }
-
- char[] glyphBuffer = new char[result.nGlyphs];
- int glyphCount = 0;
- for (int i=0; i<offsets.length-1; i++) {
- int offset = offsets [i];
- int length = offsets [i+1] - offsets [i];
-
- // The number of glyphs expected is <= length (segment length);
- // the actual number returned may be less in case of Arabic ligatures.
- result.nGlyphs = length;
- TCHAR textBuffer2 = new TCHAR(lpCs[1], text.substring(offset, offset + length), false);
- OS.GetCharacterPlacement(gc.handle, textBuffer2, textBuffer2.length(), 0, result, dwFlags);
-
- if (dx != null) {
- int [] dx2 = new int [result.nGlyphs];
- OS.MoveMemory(dx2, result.lpDx, dx2.length * 4);
- if (isRightOriented) {
- reverse(dx2);
- }
- System.arraycopy (dx2, 0, dx, glyphCount, dx2.length);
- }
- if (order != null) {
- int [] order2 = new int [length];
- OS.MoveMemory(order2, result.lpOrder, order2.length * 4);
- translateOrder(order2, glyphCount, isRightOriented);
- System.arraycopy (order2, 0, order, offset, length);
- }
- if (classBuffer != null) {
- byte [] classBuffer2 = new byte [length];
- OS.MoveMemory(classBuffer2, result.lpClass, classBuffer2.length);
- System.arraycopy (classBuffer2, 0, classBuffer, offset, length);
- }
- char[] glyphBuffer2 = new char[result.nGlyphs];
- OS.MoveMemory(glyphBuffer2, result.lpGlyphs, glyphBuffer2.length * 2);
- if (isRightOriented) {
- reverse(glyphBuffer2);
- }
- System.arraycopy (glyphBuffer2, 0, glyphBuffer, glyphCount, glyphBuffer2.length);
- glyphCount += glyphBuffer2.length;
-
- // We concatenate successive results of calls to GCP.
- // For Arabic, it is the only good method since the number of output
- // glyphs might be less than the number of input characters.
- // This assumes that the whole line is built by successive adjacent
- // segments without overlapping.
- result.lpOrder += length * 4;
- result.lpDx += length * 4;
- result.lpClass += length;
- result.lpGlyphs += glyphBuffer2.length * 2;
- }
-
- /* Free the memory that was allocated. */
- OS.HeapFree(hHeap, 0, lpGlyphs);
- OS.HeapFree(hHeap, 0, lpClass);
- OS.HeapFree(hHeap, 0, lpDx);
- OS.HeapFree(hHeap, 0, lpOrder);
- return glyphBuffer;
-}
-/**
- * Return bidi ordering information for the given text. Does not return rendering
- * information (e.g., glyphs, glyph distances). Use this method when you only need
- * ordering information. Doing so will improve performance. Wraps the
- * GetFontLanguageInfo and GetCharacterPlacement functions.
- * <p>
- *
- * @param gc the GC to use for measuring of this line, input parameter
- * @param text text that bidi data should be calculated for, input parameter
- * @param order an array of integers representing the visual position of each character in
- * the text array, output parameter
- * @param classBuffer an array of integers representing the type (e.g., ARABIC, HEBREW,
- * LOCALNUMBER) of each character in the text array, input/output parameter
- * @param flags an integer representing rendering flag information, input parameter
- * @param offsets text segments that should be measured and reordered separately, input
- * parameter. See org.eclipse.swt.custom.BidiSegmentEvent for details.
- */
-public static void getOrderInfo(GC gc, String text, int[] order, byte[] classBuffer, int flags, int [] offsets) {
- int fontLanguageInfo = OS.GetFontLanguageInfo(gc.handle);
- int /*long*/ hHeap = OS.GetProcessHeap();
- int[] lpCs = new int[8];
- int cs = OS.GetTextCharset(gc.handle);
- OS.TranslateCharsetInfo(cs, lpCs, OS.TCI_SRCCHARSET);
- TCHAR textBuffer = new TCHAR(lpCs[1], text, false);
- int byteCount = textBuffer.length();
- boolean isRightOriented = false;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
- isRightOriented = OS.GetLayout(gc.handle) != 0;
- }
-
- GCP_RESULTS result = new GCP_RESULTS();
- result.lStructSize = GCP_RESULTS.sizeof;
- result.nGlyphs = byteCount;
- int /*long*/ lpOrder = result.lpOrder = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount * 4);
- int /*long*/ lpClass = result.lpClass = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
-
- // set required dwFlags, these values will affect how the text gets rendered and
- // ordered
- int dwFlags = 0;
- // Always reorder. We assume that if we are calling this function we're
- // on a platform that supports bidi. Fixes 20690.
- dwFlags |= GCP_REORDER;
- if ((fontLanguageInfo & GCP_LIGATE) == GCP_LIGATE) {
- dwFlags |= GCP_LIGATE;
- }
- if ((fontLanguageInfo & GCP_GLYPHSHAPE) == GCP_GLYPHSHAPE) {
- dwFlags |= GCP_GLYPHSHAPE;
- }
- if ((flags & CLASSIN) == CLASSIN) {
- // set classification values for the substring, classification values
- // can be specified on input
- dwFlags |= GCP_CLASSIN;
- OS.MoveMemory(result.lpClass, classBuffer, classBuffer.length);
- }
-
- int glyphCount = 0;
- for (int i=0; i<offsets.length-1; i++) {
- int offset = offsets [i];
- int length = offsets [i+1] - offsets [i];
- // The number of glyphs expected is <= length (segment length);
- // the actual number returned may be less in case of Arabic ligatures.
- result.nGlyphs = length;
- TCHAR textBuffer2 = new TCHAR(lpCs[1], text.substring(offset, offset + length), false);
- OS.GetCharacterPlacement(gc.handle, textBuffer2, textBuffer2.length(), 0, result, dwFlags);
-
- if (order != null) {
- int [] order2 = new int [length];
- OS.MoveMemory(order2, result.lpOrder, order2.length * 4);
- translateOrder(order2, glyphCount, isRightOriented);
- System.arraycopy (order2, 0, order, offset, length);
- }
- if (classBuffer != null) {
- byte [] classBuffer2 = new byte [length];
- OS.MoveMemory(classBuffer2, result.lpClass, classBuffer2.length);
- System.arraycopy (classBuffer2, 0, classBuffer, offset, length);
- }
- glyphCount += result.nGlyphs;
-
- // We concatenate successive results of calls to GCP.
- // For Arabic, it is the only good method since the number of output
- // glyphs might be less than the number of input characters.
- // This assumes that the whole line is built by successive adjacent
- // segments without overlapping.
- result.lpOrder += length * 4;
- result.lpClass += length;
- }
-
- /* Free the memory that was allocated. */
- OS.HeapFree(hHeap, 0, lpClass);
- OS.HeapFree(hHeap, 0, lpOrder);
-}
-/**
- * Return bidi attribute information for the font in the specified gc.
- * <p>
- *
- * @param gc the gc to query
- * @return bitwise OR of the REORDER, LIGATE and GLYPHSHAPE flags
- * defined by this class.
- */
-public static int getFontBidiAttributes(GC gc) {
- int fontStyle = 0;
- int fontLanguageInfo = OS.GetFontLanguageInfo(gc.handle);
- if (((fontLanguageInfo & GCP_REORDER) != 0)) {
- fontStyle |= REORDER;
- }
- if (((fontLanguageInfo & GCP_LIGATE) != 0)) {
- fontStyle |= LIGATE;
- }
- if (((fontLanguageInfo & GCP_GLYPHSHAPE) != 0)) {
- fontStyle |= GLYPHSHAPE;
- }
- return fontStyle;
-}
-/**
- * Return the active keyboard language type.
- * <p>
- *
- * @return an integer representing the active keyboard language (KEYBOARD_BIDI,
- * KEYBOARD_NON_BIDI)
- */
-public static int getKeyboardLanguage() {
- int /*long*/ layout = OS.GetKeyboardLayout(0);
- return isBidiLang(layout) ? KEYBOARD_BIDI : KEYBOARD_NON_BIDI;
-}
-/**
- * Return the languages that are installed for the keyboard.
- * <p>
- *
- * @return integer array with an entry for each installed language
- */
-static int /*long*/[] getKeyboardLanguageList() {
- int maxSize = 10;
- int /*long*/[] tempList = new int /*long*/[maxSize];
- int size = OS.GetKeyboardLayoutList(maxSize, tempList);
- int /*long*/[] list = new int /*long*/[size];
- System.arraycopy(tempList, 0, list, 0, size);
- return list;
-}
-static boolean isBidiLang(int /*long*/ lang) {
- int id = OS.PRIMARYLANGID(OS.LOWORD(lang));
- return id == LANG_ARABIC || id == LANG_HEBREW || id == LANG_FARSI;
-}
-/**
- * Return whether or not the platform supports a bidi language. Determine this
- * by looking at the languages that are installed.
- * <p>
- *
- * @return true if bidi is supported, false otherwise. Always
- * false on Windows CE.
- */
-public static boolean isBidiPlatform() {
- if (OS.IsWinCE) return false;
- if (isBidiPlatform != -1) return isBidiPlatform == 1; // already set
-
- isBidiPlatform = 0;
-
- // The following test is a workaround for bug report 27629. On WinXP,
- // both bidi and complex script (e.g., Thai) languages must be installed
- // at the same time. Since the bidi platform calls do not support
- // double byte characters, there is no way to run Eclipse using the
- // complex script languages on XP, so constrain this test to answer true
- // only if a bidi input language is defined. Doing so will allow complex
- // script languages to work (e.g., one can install bidi and complex script
- // languages, but only install the Thai keyboard).
- if (!isKeyboardBidi()) return false;
-
- Callback callback = null;
- try {
- callback = new Callback (Class.forName (CLASS_NAME), "EnumSystemLanguageGroupsProc", 5); //$NON-NLS-1$
- int /*long*/ lpEnumSystemLanguageGroupsProc = callback.getAddress ();
- if (lpEnumSystemLanguageGroupsProc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- OS.EnumSystemLanguageGroups(lpEnumSystemLanguageGroupsProc, OS.LGRPID_INSTALLED, 0);
- callback.dispose ();
- } catch (ClassNotFoundException e) {
- if (callback != null) callback.dispose();
- }
- if (isBidiPlatform == 1) return true;
- // need to look at system code page for NT & 98 platforms since EnumSystemLanguageGroups is
- // not supported for these platforms
- String codePage = String.valueOf(OS.GetACP());
- if (CD_PG_ARABIC.equals(codePage) || CD_PG_HEBREW.equals(codePage)) {
- isBidiPlatform = 1;
- }
- return isBidiPlatform == 1;
-}
-/**
- * Return whether or not the keyboard supports input of a bidi language. Determine this
- * by looking at the languages that are installed for the keyboard.
- * <p>
- *
- * @return true if bidi is supported, false otherwise.
- */
-public static boolean isKeyboardBidi() {
- int /*long*/[] list = getKeyboardLanguageList();
- for (int i=0; i<list.length; i++) {
- if (isBidiLang(list[i])) {
- return true;
- }
- }
- return false;
-}
-/**
- * Removes the specified language listener.
- * <p>
- *
- * @param hwnd the handle of the Control that is listening for keyboard language changes
- */
-public static void removeLanguageListener (int /*long*/ hwnd) {
- languageMap.remove(new LONG(hwnd));
- unsubclass(hwnd);
-}
-public static void removeLanguageListener (Control control) {
- removeLanguageListener(control.handle);
-}
-/**
- * Switch the keyboard language to the specified language type. We do
- * not distinguish between multiple bidi or multiple non-bidi languages, so
- * set the keyboard to the first language of the given type.
- * <p>
- *
- * @param language integer representing language. One of
- * KEYBOARD_BIDI, KEYBOARD_NON_BIDI.
- */
-public static void setKeyboardLanguage(int language) {
- if (language == getKeyboardLanguage()) return;
- boolean bidi = language == KEYBOARD_BIDI;
- int /*long*/[] list = getKeyboardLanguageList();
- for (int i=0; i<list.length; i++) {
- if (bidi == isBidiLang(list[i])) {
- OS.ActivateKeyboardLayout(list[i], 0);
- return;
- }
- }
-}
-/**
- * Sets the orientation (writing order) of the specified control. Text will
- * be right aligned for right to left writing order.
- * <p>
- *
- * @param hwnd the handle of the Control to change the orientation of
- * @param orientation one of SWT.RIGHT_TO_LEFT or SWT.LEFT_TO_RIGHT
- * @return true if the orientation was changed, false if the orientation
- * could not be changed
- */
-public static boolean setOrientation (int /*long*/ hwnd, int orientation) {
- if (OS.IsWinCE) return false;
- if (OS.WIN32_VERSION < OS.VERSION(4, 10)) return false;
- int bits = OS.GetWindowLong (hwnd, OS.GWL_EXSTYLE);
- if ((orientation & SWT.RIGHT_TO_LEFT) != 0) {
- bits |= OS.WS_EX_LAYOUTRTL;
- } else {
- bits &= ~OS.WS_EX_LAYOUTRTL;
- }
- OS.SetWindowLong (hwnd, OS.GWL_EXSTYLE, bits);
- return true;
-}
-public static boolean setOrientation (Control control, int orientation) {
- return setOrientation(control.handle, orientation);
-}
-/**
- * Override the window proc.
- *
- * @param hwnd control to override the window proc of
- */
-static void subclass(int /*long*/ hwnd) {
- LONG key = new LONG(hwnd);
- if (oldProcMap.get(key) == null) {
- int /*long*/ oldProc = OS.GetWindowLongPtr(hwnd, OS.GWLP_WNDPROC);
- oldProcMap.put(key, new LONG(oldProc));
- OS.SetWindowLongPtr(hwnd, OS.GWLP_WNDPROC, callback.getAddress());
- }
-}
-/**
- * Reverse the character array. Used for right orientation.
- *
- * @param charArray character array to reverse
- */
-static void reverse(char[] charArray) {
- int length = charArray.length;
- for (int i = 0; i <= (length - 1) / 2; i++) {
- char tmp = charArray[i];
- charArray[i] = charArray[length - 1 - i];
- charArray[length - 1 - i] = tmp;
- }
-}
-/**
- * Reverse the integer array. Used for right orientation.
- *
- * @param intArray integer array to reverse
- */
-static void reverse(int[] intArray) {
- int length = intArray.length;
- for (int i = 0; i <= (length - 1) / 2; i++) {
- int tmp = intArray[i];
- intArray[i] = intArray[length - 1 - i];
- intArray[length - 1 - i] = tmp;
- }
-}
-/**
- * Adjust the order array so that it is relative to the start of the line. Also reverse the order array if the orientation
- * is to the right.
- *
- * @param orderArray integer array of order values to translate
- * @param glyphCount number of glyphs that have been processed for the current line
- * @param isRightOriented flag indicating whether or not current orientation is to the right
-*/
-static void translateOrder(int[] orderArray, int glyphCount, boolean isRightOriented) {
- int maxOrder = 0;
- int length = orderArray.length;
- if (isRightOriented) {
- for (int i=0; i<length; i++) {
- maxOrder = Math.max(maxOrder, orderArray[i]);
- }
- }
- for (int i=0; i<length; i++) {
- if (isRightOriented) orderArray[i] = maxOrder - orderArray[i];
- orderArray [i] += glyphCount;
- }
-}
-/**
- * Remove the overridden the window proc.
- *
- * @param hwnd control to remove the window proc override for
- */
-static void unsubclass(int /*long*/ hwnd) {
- LONG key = new LONG(hwnd);
- if (languageMap.get(key) == null && keyMap.get(key) == null) {
- LONG proc = (LONG) oldProcMap.remove(key);
- if (proc == null) return;
- OS.SetWindowLongPtr(hwnd, OS.GWLP_WNDPROC, proc.value);
- }
-}
-/**
- * Window proc to intercept keyboard language switch event (WS_INPUTLANGCHANGE)
- * and widget orientation changes.
- * Run the Control's registered runnable when the keyboard language is switched.
- *
- * @param hwnd handle of the control that is listening for the keyboard language
- * change event
- * @param msg window message
- */
-static int /*long*/ windowProc (int /*long*/ hwnd, int /*long*/ msg, int /*long*/ wParam, int /*long*/ lParam) {
- LONG key = new LONG (hwnd);
- switch ((int)/*64*/msg) {
- case 0x51 /*OS.WM_INPUTLANGCHANGE*/:
- Runnable runnable = (Runnable) languageMap.get (key);
- if (runnable != null) runnable.run ();
- break;
- }
- LONG oldProc = (LONG)oldProcMap.get(key);
- return OS.CallWindowProc (oldProc.value, hwnd, (int)/*64*/msg, wParam, lParam);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ImageList.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ImageList.java
deleted file mode 100644
index e82f7285e8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ImageList.java
+++ /dev/null
@@ -1,459 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.internal;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-public class ImageList {
- int /*long*/ handle;
- int style, refCount;
- Image [] images;
-
-public ImageList (int style) {
- this.style = style;
- int flags = OS.ILC_MASK;
- if (OS.IsWinCE) {
- flags |= OS.ILC_COLOR;
- } else {
- if (OS.COMCTL32_MAJOR >= 6) {
- flags |= OS.ILC_COLOR32;
- } else {
- int /*long*/ hDC = OS.GetDC (0);
- int bits = OS.GetDeviceCaps (hDC, OS.BITSPIXEL);
- int planes = OS.GetDeviceCaps (hDC, OS.PLANES);
- OS.ReleaseDC (0, hDC);
- int depth = bits * planes;
- switch (depth) {
- case 4: flags |= OS.ILC_COLOR4; break;
- case 8: flags |= OS.ILC_COLOR8; break;
- case 16: flags |= OS.ILC_COLOR16; break;
- case 24: flags |= OS.ILC_COLOR24; break;
- case 32: flags |= OS.ILC_COLOR32; break;
- default: flags |= OS.ILC_COLOR; break;
- }
- }
- }
- if ((style & SWT.RIGHT_TO_LEFT) != 0) flags |= OS.ILC_MIRROR;
- handle = OS.ImageList_Create (32, 32, flags, 16, 16);
- images = new Image [4];
-}
-
-public int add (Image image) {
- int count = OS.ImageList_GetImageCount (handle);
- int index = 0;
- while (index < count) {
- if (images [index] != null) {
- if (images [index].isDisposed ()) images [index] = null;
- }
- if (images [index] == null) break;
- index++;
- }
- if (count == 0) {
- Rectangle rect = image.getBounds ();
- OS.ImageList_SetIconSize (handle, rect.width, rect.height);
- }
- set (index, image, count);
- if (index == images.length) {
- Image [] newImages = new Image [images.length + 4];
- System.arraycopy (images, 0, newImages, 0, images.length);
- images = newImages;
- }
- images [index] = image;
- return index;
-}
-
-public int addRef() {
- return ++refCount;
-}
-
-int /*long*/ copyBitmap (int /*long*/ hImage, int width, int height) {
- BITMAP bm = new BITMAP ();
- OS.GetObject (hImage, BITMAP.sizeof, bm);
- int /*long*/ hDC = OS.GetDC (0);
- int /*long*/ hdc1 = OS.CreateCompatibleDC (hDC);
- OS.SelectObject (hdc1, hImage);
- int /*long*/ hdc2 = OS.CreateCompatibleDC (hDC);
- /*
- * Feature in Windows. If a bitmap has a 32-bit depth and any
- * pixel has an alpha value different than zero, common controls
- * version 6.0 assumes that the bitmap should be alpha blended.
- * AlphaBlend() composes the alpha channel of a destination 32-bit
- * depth image with the alpha channel of the source image. This
- * may cause opaque images to draw transparently. The fix is
- * remove the alpha channel of opaque images by down sampling
- * it to 24-bit depth.
- */
- int /*long*/ hBitmap;
- if (bm.bmBitsPixel == 32 && OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER();
- bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
- bmiHeader.biWidth = width;
- bmiHeader.biHeight = -height;
- bmiHeader.biPlanes = 1;
- bmiHeader.biBitCount = (short)24;
- if (OS.IsWinCE) bmiHeader.biCompression = OS.BI_BITFIELDS;
- else bmiHeader.biCompression = OS.BI_RGB;
- byte[] bmi = new byte[BITMAPINFOHEADER.sizeof + (OS.IsWinCE ? 12 : 0)];
- OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
- /* Set the rgb colors into the bitmap info */
- if (OS.IsWinCE) {
- int redMask = 0xFF00;
- int greenMask = 0xFF0000;
- int blueMask = 0xFF000000;
- /* big endian */
- int offset = BITMAPINFOHEADER.sizeof;
- bmi[offset] = (byte)((redMask & 0xFF000000) >> 24);
- bmi[offset + 1] = (byte)((redMask & 0xFF0000) >> 16);
- bmi[offset + 2] = (byte)((redMask & 0xFF00) >> 8);
- bmi[offset + 3] = (byte)((redMask & 0xFF) >> 0);
- bmi[offset + 4] = (byte)((greenMask & 0xFF000000) >> 24);
- bmi[offset + 5] = (byte)((greenMask & 0xFF0000) >> 16);
- bmi[offset + 6] = (byte)((greenMask & 0xFF00) >> 8);
- bmi[offset + 7] = (byte)((greenMask & 0xFF) >> 0);
- bmi[offset + 8] = (byte)((blueMask & 0xFF000000) >> 24);
- bmi[offset + 9] = (byte)((blueMask & 0xFF0000) >> 16);
- bmi[offset + 10] = (byte)((blueMask & 0xFF00) >> 8);
- bmi[offset + 11] = (byte)((blueMask & 0xFF) >> 0);
- }
- int /*long*/[] pBits = new int /*long*/[1];
- hBitmap = OS.CreateDIBSection(0, bmi, OS.DIB_RGB_COLORS, pBits, 0, 0);
- } else {
- hBitmap = OS.CreateCompatibleBitmap (hDC, width, height);
- }
- OS.SelectObject (hdc2, hBitmap);
- if (width != bm.bmWidth || height != bm.bmHeight) {
- if (!OS.IsWinCE) OS.SetStretchBltMode(hdc2, OS.COLORONCOLOR);
- OS.StretchBlt (hdc2, 0, 0, width, height, hdc1, 0, 0, bm.bmWidth, bm.bmHeight, OS.SRCCOPY);
- } else {
- OS.BitBlt (hdc2, 0, 0, width, height, hdc1, 0, 0, OS.SRCCOPY);
- }
- OS.DeleteDC (hdc1);
- OS.DeleteDC (hdc2);
- OS.ReleaseDC (0, hDC);
- return hBitmap;
-}
-
-int /*long*/ copyIcon (int /*long*/ hImage, int width, int height) {
- if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- int /*long*/ hIcon = OS.CopyImage (hImage, OS.IMAGE_ICON, width, height, 0);
- return hIcon != 0 ? hIcon : hImage;
-}
-
-int /*long*/ copyWithAlpha (int /*long*/ hBitmap, int background, byte[] alphaData, int destWidth, int destHeight) {
- BITMAP bm = new BITMAP ();
- OS.GetObject (hBitmap, BITMAP.sizeof, bm);
- int srcWidth = bm.bmWidth;
- int srcHeight = bm.bmHeight;
-
- /* Create resources */
- int /*long*/ hdc = OS.GetDC (0);
- int /*long*/ srcHdc = OS.CreateCompatibleDC (hdc);
- int /*long*/ oldSrcBitmap = OS.SelectObject (srcHdc, hBitmap);
- int /*long*/ memHdc = OS.CreateCompatibleDC (hdc);
- BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER ();
- bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
- bmiHeader.biWidth = srcWidth;
- bmiHeader.biHeight = -srcHeight;
- bmiHeader.biPlanes = 1;
- bmiHeader.biBitCount = 32;
- bmiHeader.biCompression = OS.BI_RGB;
- byte [] bmi = new byte[BITMAPINFOHEADER.sizeof];
- OS.MoveMemory (bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
- int /*long*/ [] pBits = new int /*long*/ [1];
- int /*long*/ memDib = OS.CreateDIBSection (0, bmi, OS.DIB_RGB_COLORS, pBits, 0, 0);
- if (memDib == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- int /*long*/ oldMemBitmap = OS.SelectObject (memHdc, memDib);
-
- BITMAP dibBM = new BITMAP ();
- OS.GetObject (memDib, BITMAP.sizeof, dibBM);
- int sizeInBytes = dibBM.bmWidthBytes * dibBM.bmHeight;
-
- /* Get the foreground pixels */
- OS.BitBlt (memHdc, 0, 0, srcWidth, srcHeight, srcHdc, 0, 0, OS.SRCCOPY);
- byte[] srcData = new byte [sizeInBytes];
- OS.MoveMemory (srcData, dibBM.bmBits, sizeInBytes);
-
- /* Merge the alpha channel in place */
- if (alphaData != null) {
- int spinc = dibBM.bmWidthBytes - srcWidth * 4;
- int ap = 0, sp = 3;
- for (int y = 0; y < srcHeight; ++y) {
- for (int x = 0; x < srcWidth; ++x) {
- srcData [sp] = alphaData [ap++];
- sp += 4;
- }
- sp += spinc;
- }
- } else {
- byte transRed = (byte)(background & 0xFF);
- byte transGreen = (byte)((background >> 8) & 0xFF);
- byte transBlue = (byte)((background >> 16) & 0xFF);
- final int spinc = dibBM.bmWidthBytes - srcWidth * 4;
- int sp = 3;
- for (int y = 0; y < srcHeight; ++y) {
- for (int x = 0; x < srcWidth; ++x) {
- srcData [sp] = (srcData[sp-1] == transRed && srcData[sp-2] == transGreen && srcData[sp-3] == transBlue) ? 0 : (byte)255;
- sp += 4;
- }
- sp += spinc;
- }
- }
- OS.MoveMemory (dibBM.bmBits, srcData, sizeInBytes);
-
- /* Stretch and free resources */
- if (srcWidth != destWidth || srcHeight != destHeight) {
- BITMAPINFOHEADER bmiHeader2 = new BITMAPINFOHEADER ();
- bmiHeader2.biSize = BITMAPINFOHEADER.sizeof;
- bmiHeader2.biWidth = destWidth;
- bmiHeader2.biHeight = -destHeight;
- bmiHeader2.biPlanes = 1;
- bmiHeader2.biBitCount = 32;
- bmiHeader2.biCompression = OS.BI_RGB;
- byte [] bmi2 = new byte[BITMAPINFOHEADER.sizeof];
- OS.MoveMemory (bmi2, bmiHeader2, BITMAPINFOHEADER.sizeof);
- int /*long*/ [] pBits2 = new int /*long*/ [1];
- int /*long*/ memDib2 = OS.CreateDIBSection (0, bmi2, OS.DIB_RGB_COLORS, pBits2, 0, 0);
- int /*long*/ memHdc2 = OS.CreateCompatibleDC (hdc);
- int /*long*/ oldMemBitmap2 = OS.SelectObject (memHdc2, memDib2);
- if (!OS.IsWinCE) OS.SetStretchBltMode(memHdc2, OS.COLORONCOLOR);
- OS.StretchBlt (memHdc2, 0, 0, destWidth, destHeight, memHdc, 0, 0, srcWidth, srcHeight, OS.SRCCOPY);
- OS.SelectObject (memHdc2, oldMemBitmap2);
- OS.DeleteDC (memHdc2);
- OS.SelectObject (memHdc, oldMemBitmap);
- OS.DeleteDC (memHdc);
- OS.DeleteObject (memDib);
- memDib = memDib2;
- } else {
- OS.SelectObject (memHdc, oldMemBitmap);
- OS.DeleteDC (memHdc);
- }
- OS.SelectObject (srcHdc, oldSrcBitmap);
- OS.DeleteDC (srcHdc);
- OS.ReleaseDC (0, hdc);
- return memDib;
-}
-
-int /*long*/ createMaskFromAlpha (ImageData data, int destWidth, int destHeight) {
- int srcWidth = data.width;
- int srcHeight = data.height;
- ImageData mask = ImageData.internal_new (srcWidth, srcHeight, 1,
- new PaletteData(new RGB [] {new RGB (0, 0, 0), new RGB (0xff, 0xff, 0xff)}),
- 2, null, 1, null, null, -1, -1, -1, 0, 0, 0, 0);
- int ap = 0;
- for (int y = 0; y < mask.height; y++) {
- for (int x = 0; x < mask.width; x++) {
- mask.setPixel (x, y, (data.alphaData [ap++] & 0xff) <= 127 ? 1 : 0);
- }
- }
- int /*long*/ hMask = OS.CreateBitmap (srcWidth, srcHeight, 1, 1, mask.data);
- if (srcWidth != destWidth || srcHeight != destHeight) {
- int /*long*/ hdc = OS.GetDC (0);
- int /*long*/ hdc1 = OS.CreateCompatibleDC (hdc);
- OS.SelectObject (hdc1, hMask);
- int /*long*/ hdc2 = OS.CreateCompatibleDC (hdc);
- int /*long*/ hMask2 = OS.CreateBitmap (destWidth, destHeight, 1, 1, null);
- OS.SelectObject (hdc2, hMask2);
- if (!OS.IsWinCE) OS.SetStretchBltMode(hdc2, OS.COLORONCOLOR);
- OS.StretchBlt (hdc2, 0, 0, destWidth, destHeight, hdc1, 0, 0, srcWidth, srcHeight, OS.SRCCOPY);
- OS.DeleteDC (hdc1);
- OS.DeleteDC (hdc2);
- OS.ReleaseDC (0, hdc);
- OS.DeleteObject(hMask);
- hMask = hMask2;
- }
- return hMask;
-}
-
-int /*long*/ createMask (int /*long*/ hBitmap, int destWidth, int destHeight, int background, int transparentPixel) {
- BITMAP bm = new BITMAP ();
- OS.GetObject (hBitmap, BITMAP.sizeof, bm);
- int srcWidth = bm.bmWidth;
- int srcHeight = bm.bmHeight;
- int /*long*/ hMask = OS.CreateBitmap (destWidth, destHeight, 1, 1, null);
- int /*long*/ hDC = OS.GetDC (0);
- int /*long*/ hdc1 = OS.CreateCompatibleDC (hDC);
- if (background != -1) {
- OS.SelectObject (hdc1, hBitmap);
-
- /*
- * If the image has a palette with multiple entries having
- * the same color and one of those entries is the transparentPixel,
- * only the first entry becomes transparent. To avoid this
- * problem, temporarily change the image palette to a palette
- * where the transparentPixel is white and everything else is
- * black.
- */
- boolean isDib = bm.bmBits != 0;
- byte[] originalColors = null;
- if (!OS.IsWinCE && transparentPixel != -1 && isDib && bm.bmBitsPixel <= 8) {
- int maxColors = 1 << bm.bmBitsPixel;
- byte[] oldColors = new byte[maxColors * 4];
- OS.GetDIBColorTable(hdc1, 0, maxColors, oldColors);
- int offset = transparentPixel * 4;
- byte[] newColors = new byte[oldColors.length];
- newColors[offset] = (byte)0xFF;
- newColors[offset+1] = (byte)0xFF;
- newColors[offset+2] = (byte)0xFF;
- OS.SetDIBColorTable(hdc1, 0, maxColors, newColors);
- originalColors = oldColors;
- OS.SetBkColor (hdc1, 0xFFFFFF);
- } else {
- OS.SetBkColor (hdc1, background);
- }
-
- int /*long*/ hdc2 = OS.CreateCompatibleDC (hDC);
- OS.SelectObject (hdc2, hMask);
- if (destWidth != srcWidth || destHeight != srcHeight) {
- if (!OS.IsWinCE) OS.SetStretchBltMode (hdc2, OS.COLORONCOLOR);
- OS.StretchBlt (hdc2, 0, 0, destWidth, destHeight, hdc1, 0, 0, srcWidth, srcHeight, OS.SRCCOPY);
- } else {
- OS.BitBlt (hdc2, 0, 0, destWidth, destHeight, hdc1, 0, 0, OS.SRCCOPY);
- }
- OS.DeleteDC (hdc2);
-
- /* Put back the original palette */
- if (originalColors != null) OS.SetDIBColorTable(hdc1, 0, 1 << bm.bmBitsPixel, originalColors);
- } else {
- int /*long*/ hOldBitmap = OS.SelectObject (hdc1, hMask);
- OS.PatBlt (hdc1, 0, 0, destWidth, destHeight, OS.BLACKNESS);
- OS.SelectObject (hdc1, hOldBitmap);
- }
- OS.ReleaseDC (0, hDC);
- OS.DeleteDC (hdc1);
- return hMask;
-}
-
-public void dispose () {
- if (handle != 0) OS.ImageList_Destroy (handle);
- handle = 0;
- images = null;
-}
-
-public Image get (int index) {
- return images [index];
-}
-
-public int getStyle () {
- return style;
-}
-
-public int /*long*/ getHandle () {
- return handle;
-}
-
-public Point getImageSize() {
- int [] cx = new int [1], cy = new int [1];
- OS.ImageList_GetIconSize (handle, cx, cy);
- return new Point (cx [0], cy [0]);
-}
-
-public int indexOf (Image image) {
- int count = OS.ImageList_GetImageCount (handle);
- for (int i=0; i<count; i++) {
- if (images [i] != null) {
- if (images [i].isDisposed ()) images [i] = null;
- if (images [i] != null && images [i].equals (image)) return i;
- }
- }
- return -1;
-}
-
-public void put (int index, Image image) {
- int count = OS.ImageList_GetImageCount (handle);
- if (!(0 <= index && index < count)) return;
- if (image != null) set(index, image, count);
- images [index] = image;
-}
-
-public void remove (int index) {
- int count = OS.ImageList_GetImageCount (handle);
- if (!(0 <= index && index < count)) return;
- OS.ImageList_Remove (handle, index);
- System.arraycopy (images, index + 1, images, index, --count - index);
- images [index] = null;
-}
-
-public int removeRef() {
- return --refCount;
-}
-
-void set (int index, Image image, int count) {
- int /*long*/ hImage = image.handle;
- int [] cx = new int [1], cy = new int [1];
- OS.ImageList_GetIconSize (handle, cx, cy);
- switch (image.type) {
- case SWT.BITMAP: {
- /*
- * Note that the image size has to match the image list icon size.
- */
- int /*long*/ hBitmap = 0, hMask = 0;
- ImageData data = image.getImageData ();
- switch (data.getTransparencyType ()) {
- case SWT.TRANSPARENCY_ALPHA:
- if (OS.COMCTL32_MAJOR >= 6) {
- hBitmap = copyWithAlpha (hImage, -1, data.alphaData, cx [0], cy [0]);
- } else {
- hBitmap = copyBitmap (hImage, cx [0], cy [0]);
- hMask = createMaskFromAlpha (data, cx [0], cy [0]);
- }
- break;
- case SWT.TRANSPARENCY_PIXEL:
- int background = -1;
- Color color = image.getBackground ();
- if (color != null) background = color.handle;
- hBitmap = copyBitmap (hImage, cx [0], cy [0]);
- hMask = createMask (hImage, cx [0], cy [0], background, data.transparentPixel);
- break;
- case SWT.TRANSPARENCY_NONE:
- default:
- hBitmap = copyBitmap (hImage, cx [0], cy [0]);
- if (index != count) hMask = createMask (hImage, cx [0], cy [0], -1, -1);
- break;
- }
- if (index == count) {
- OS.ImageList_Add (handle, hBitmap, hMask);
- } else {
- /* Note that the mask must always be replaced even for TRANSPARENCY_NONE */
- OS.ImageList_Replace (handle, index, hBitmap, hMask);
- }
- if (hMask != 0) OS.DeleteObject (hMask);
- if (hBitmap != hImage) OS.DeleteObject (hBitmap);
- break;
- }
- case SWT.ICON: {
- if (OS.IsWinCE) {
- OS.ImageList_ReplaceIcon (handle, index == count ? -1 : index, hImage);
- } else {
- int /*long*/ hIcon = copyIcon (hImage, cx [0], cy [0]);
- OS.ImageList_ReplaceIcon (handle, index == count ? -1 : index, hIcon);
- OS.DestroyIcon (hIcon);
- }
- break;
- }
- }
-}
-
-public int size () {
- int result = 0;
- int count = OS.ImageList_GetImageCount (handle);
- for (int i=0; i<count; i++) {
- if (images [i] != null) {
- if (images [i].isDisposed ()) images [i] = null;
- if (images [i] != null) result++;
- }
- }
- return result;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java
deleted file mode 100755
index 130a78aa3c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java
+++ /dev/null
@@ -1,1388 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface object that
- * issues notification when pressed and released.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>ARROW, CHECK, PUSH, RADIO, TOGGLE, FLAT</dd>
- * <dd>UP, DOWN, LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles ARROW, CHECK, PUSH, RADIO, and TOGGLE
- * may be specified.
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT, and CENTER may be specified.
- * </p><p>
- * Note: Only one of the styles UP, DOWN, LEFT, and RIGHT may be specified
- * when the ARROW style is specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#button">Button snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Button extends Control {
- String text = "", message = "";
- Image image, image2, disabledImage;
- ImageList imageList;
- boolean ignoreMouse, grayed;
- static final int MARGIN = 4;
- static final int CHECK_WIDTH, CHECK_HEIGHT;
- static final int ICON_WIDTH = 128, ICON_HEIGHT = 128;
- static /*final*/ boolean COMMAND_LINK = false;
- static final int /*long*/ ButtonProc;
- static final TCHAR ButtonClass = new TCHAR (0, "BUTTON", true);
- static {
- int /*long*/ hBitmap = OS.LoadBitmap (0, OS.OBM_CHECKBOXES);
- if (hBitmap == 0) {
- CHECK_WIDTH = OS.GetSystemMetrics (OS.IsWinCE ? OS.SM_CXSMICON : OS.SM_CXVSCROLL);
- CHECK_HEIGHT = OS.GetSystemMetrics (OS.IsWinCE ? OS.SM_CYSMICON : OS.SM_CYVSCROLL);
- } else {
- BITMAP bitmap = new BITMAP ();
- OS.GetObject (hBitmap, BITMAP.sizeof, bitmap);
- OS.DeleteObject (hBitmap);
- CHECK_WIDTH = bitmap.bmWidth / 4;
- CHECK_HEIGHT = bitmap.bmHeight / 3;
- }
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, ButtonClass, lpWndClass);
- ButtonProc = lpWndClass.lpfnWndProc;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#ARROW
- * @see SWT#CHECK
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#TOGGLE
- * @see SWT#FLAT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Button (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-void _setImage (Image image) {
- if ((style & SWT.COMMAND) != 0) return;
- if (OS.COMCTL32_MAJOR >= 6) {
- if (imageList != null) imageList.dispose ();
- imageList = null;
- if (image != null) {
- imageList = new ImageList (style & SWT.RIGHT_TO_LEFT);
- if (OS.IsWindowEnabled (handle)) {
- imageList.add (image);
- } else {
- if (disabledImage != null) disabledImage.dispose ();
- disabledImage = new Image (display, image, SWT.IMAGE_DISABLE);
- imageList.add (disabledImage);
- }
- BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST ();
- buttonImageList.himl = imageList.getHandle ();
- int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE), newBits = oldBits;
- newBits &= ~(OS.BS_LEFT | OS.BS_CENTER | OS.BS_RIGHT);
- if ((style & SWT.LEFT) != 0) newBits |= OS.BS_LEFT;
- if ((style & SWT.CENTER) != 0) newBits |= OS.BS_CENTER;
- if ((style & SWT.RIGHT) != 0) newBits |= OS.BS_RIGHT;
- if (text.length () == 0) {
- if ((style & SWT.LEFT) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT;
- if ((style & SWT.CENTER) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_CENTER;
- if ((style & SWT.RIGHT) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_RIGHT;
- } else {
- buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT;
- buttonImageList.margin_left = computeLeftMargin ();
- buttonImageList.margin_right = MARGIN;
- newBits &= ~(OS.BS_CENTER | OS.BS_RIGHT);
- newBits |= OS.BS_LEFT;
- }
- if (newBits != oldBits) {
- OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
- OS.InvalidateRect (handle, null, true);
- }
- OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, buttonImageList);
- } else {
- OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, 0);
- }
- /*
- * Bug in Windows. Under certain cirumstances yet to be
- * isolated, BCM_SETIMAGELIST does not redraw the control
- * when a new image is set. The fix is to force a redraw.
- */
- OS.InvalidateRect (handle, null, true);
- } else {
- if (image2 != null) image2.dispose ();
- image2 = null;
- int /*long*/ hImage = 0;
- int imageBits = 0, fImageType = 0;
- if (image != null) {
- switch (image.type) {
- case SWT.BITMAP: {
- Rectangle rect = image.getBounds ();
- ImageData data = image.getImageData ();
- switch (data.getTransparencyType ()) {
- case SWT.TRANSPARENCY_PIXEL:
- if (rect.width <= ICON_WIDTH && rect.height <= ICON_HEIGHT) {
- image2 = new Image (display, data, data.getTransparencyMask ());
- hImage = image2.handle;
- imageBits = OS.BS_ICON;
- fImageType = OS.IMAGE_ICON;
- break;
- }
- //FALL THROUGH
- case SWT.TRANSPARENCY_ALPHA:
- image2 = new Image (display, rect.width, rect.height);
- GC gc = new GC (image2);
- gc.setBackground (getBackground ());
- gc.fillRectangle (rect);
- gc.drawImage (image, 0, 0);
- gc.dispose ();
- hImage = image2.handle;
- imageBits = OS.BS_BITMAP;
- fImageType = OS.IMAGE_BITMAP;
- break;
- case SWT.TRANSPARENCY_NONE:
- hImage = image.handle;
- imageBits = OS.BS_BITMAP;
- fImageType = OS.IMAGE_BITMAP;
- break;
- }
- break;
- }
- case SWT.ICON: {
- hImage = image.handle;
- imageBits = OS.BS_ICON;
- fImageType = OS.IMAGE_ICON;
- break;
- }
- }
- /*
- * Feature in Windows. The button control mirrors its image when the
- * flag WS_EX_LAYOUTRTL is set. This behaviour is not desirable in SWT.
- * The fix is to set a mirrored version of real image in the button.
- */
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- Rectangle rect = image.getBounds ();
- int /*long*/ hDC = OS.GetDC (handle);
- int /*long*/ dstHdc = OS.CreateCompatibleDC (hDC);
- int /*long*/ hBitmap = OS.CreateCompatibleBitmap (hDC, rect.width, rect.height);
- int /*long*/ oldBitmap = OS.SelectObject (dstHdc, hBitmap);
- OS.SetLayout (dstHdc, OS.LAYOUT_RTL);
- if (fImageType == OS.IMAGE_BITMAP) {
- int /*long*/ srcHdc = OS.CreateCompatibleDC (hDC);
- int /*long*/ oldSrcBitmap = OS.SelectObject (srcHdc, hImage);
- OS.SetLayout (dstHdc, 0);
- OS.BitBlt (dstHdc, 0, 0, rect.width, rect.height, srcHdc, 0, 0, OS.SRCCOPY);
- OS.SelectObject (srcHdc, oldSrcBitmap);
- OS.DeleteDC (srcHdc);
- } else {
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- int /*long*/ newBrush = OS.CreateSolidBrush (control.getBackgroundPixel ());
- int /*long*/ oldBrush = OS.SelectObject (dstHdc, newBrush);
- OS.PatBlt (dstHdc, 0, 0, rect.width, rect.height, OS.PATCOPY);
- OS.DrawIconEx (dstHdc, 0, 0, hImage, 0, 0, 0, 0, OS.DI_NORMAL);
- OS.SelectObject (dstHdc, oldBrush);
- OS.DeleteObject (newBrush);
- }
- OS.SelectObject (dstHdc, oldBitmap);
- OS.DeleteDC (dstHdc);
- OS.ReleaseDC (handle, hDC);
- if (image2 != null) image2.dispose ();
- image2 = Image.win32_new (display, SWT.BITMAP, hBitmap);
- imageBits = OS.BS_BITMAP;
- fImageType = OS.IMAGE_BITMAP;
- hImage = hBitmap;
- }
- }
- }
- int newBits = OS.GetWindowLong (handle, OS.GWL_STYLE), oldBits = newBits;
- newBits &= ~(OS.BS_BITMAP | OS.BS_ICON);
- newBits |= imageBits;
- if (newBits != oldBits) OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
- OS.SendMessage (handle, OS.BM_SETIMAGE, fImageType, hImage);
- }
-}
-
-void _setText (String text) {
- int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE), newBits = oldBits;
- if (OS.COMCTL32_MAJOR >= 6) {
- newBits &= ~(OS.BS_LEFT | OS.BS_CENTER | OS.BS_RIGHT);
- if ((style & SWT.LEFT) != 0) newBits |= OS.BS_LEFT;
- if ((style & SWT.CENTER) != 0) newBits |= OS.BS_CENTER;
- if ((style & SWT.RIGHT) != 0) newBits |= OS.BS_RIGHT;
- if (imageList != null) {
- BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST ();
- buttonImageList.himl = imageList.getHandle ();
- if (text.length () == 0) {
- if ((style & SWT.LEFT) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT;
- if ((style & SWT.CENTER) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_CENTER;
- if ((style & SWT.RIGHT) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_RIGHT;
- } else {
- buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT;
- buttonImageList.margin_left = computeLeftMargin ();
- buttonImageList.margin_right = MARGIN;
- newBits &= ~(OS.BS_CENTER | OS.BS_RIGHT);
- newBits |= OS.BS_LEFT;
- }
- OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, buttonImageList);
- }
- } else {
- newBits &= ~(OS.BS_BITMAP | OS.BS_ICON);
- }
- if (newBits != oldBits) {
- OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
- OS.InvalidateRect (handle, null, true);
- }
- /*
- * Bug in Windows. When a Button control is right-to-left and
- * is disabled, the first pixel of the text is clipped. The
- * fix is to add a space to both sides of the text.
- */
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
- text = OS.IsWindowEnabled (handle) ? text : " " + text + " ";
- }
- }
- TCHAR buffer = new TCHAR (getCodePage (), text, true);
- OS.SetWindowText (handle, buffer);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected by the user.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (ButtonProc, hwnd, msg, wParam, lParam);
-}
-
-static int checkStyle (int style) {
- style = checkBits (style, SWT.PUSH, SWT.ARROW, SWT.CHECK, SWT.RADIO, SWT.TOGGLE, COMMAND_LINK ? SWT.COMMAND : 0);
- if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) {
- return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0);
- }
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0);
- }
- if ((style & SWT.ARROW) != 0) {
- style |= SWT.NO_FOCUS;
- return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0);
- }
- return style;
-}
-
-void click () {
- /*
- * Feature in Windows. BM_CLICK sends a fake WM_LBUTTONDOWN and
- * WM_LBUTTONUP in order to click the button. This causes the
- * application to get unexpected mouse events. The fix is to
- * ignore mouse events when they are caused by BM_CLICK.
- */
- ignoreMouse = true;
- OS.SendMessage (handle, OS.BM_CLICK, 0, 0);
- ignoreMouse = false;
-}
-
-int computeLeftMargin () {
- if (OS.COMCTL32_MAJOR < 6) return MARGIN;
- if ((style & (SWT.PUSH | SWT.TOGGLE)) == 0) return MARGIN;
- int margin = 0;
- if (image != null && text.length () != 0) {
- Rectangle bounds = image.getBounds ();
- margin += bounds.width + MARGIN * 2;
- int /*long*/ oldFont = 0;
- int /*long*/ hDC = OS.GetDC (handle);
- int /*long*/ newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- TCHAR buffer = new TCHAR (getCodePage (), text, true);
- RECT rect = new RECT ();
- int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE;
- OS.DrawText (hDC, buffer, -1, rect, flags);
- margin += rect.right - rect.left;
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- OS.GetClientRect (handle, rect);
- margin = Math.max (MARGIN, (rect.right - rect.left - margin) / 2);
- }
- return margin;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0, border = getBorderWidth ();
- if ((style & SWT.ARROW) != 0) {
- if ((style & (SWT.UP | SWT.DOWN)) != 0) {
- width += OS.GetSystemMetrics (OS.SM_CXVSCROLL);
- height += OS.GetSystemMetrics (OS.SM_CYVSCROLL);
- } else {
- width += OS.GetSystemMetrics (OS.SM_CXHSCROLL);
- height += OS.GetSystemMetrics (OS.SM_CYHSCROLL);
- }
- } else {
- if ((style & SWT.COMMAND) != 0) {
- SIZE size = new SIZE ();
- if (wHint != SWT.DEFAULT) {
- size.cx = wHint;
- OS.SendMessage (handle, OS.BCM_GETIDEALSIZE, 0, size);
- width = size.cx;
- height = size.cy;
- } else {
- OS.SendMessage (handle, OS.BCM_GETIDEALSIZE, 0, size);
- width = size.cy;
- height = size.cy;
- size.cy = 0;
- while (size.cy != height) {
- size.cx = width++;
- size.cy = 0;
- OS.SendMessage (handle, OS.BCM_GETIDEALSIZE, 0, size);
- }
- }
- } else {
- int extra = 0;
- boolean hasImage = image != null, hasText = true;
- if (OS.COMCTL32_MAJOR < 6) {
- if ((style & SWT.PUSH) == 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- hasImage = (bits & (OS.BS_BITMAP | OS.BS_ICON)) != 0;
- if (hasImage) hasText = false;
- }
- }
- if (hasImage) {
- if (image != null) {
- Rectangle rect = image.getBounds ();
- width = rect.width;
- if (hasText && text.length () != 0) {
- width += MARGIN * 2;
- }
- height = rect.height;
- extra = MARGIN * 2;
- }
- }
- if (hasText) {
- int /*long*/ oldFont = 0;
- int /*long*/ hDC = OS.GetDC (handle);
- int /*long*/ newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ();
- OS.GetTextMetrics (hDC, lptm);
- int length = text.length ();
- if (length == 0) {
- height = Math.max (height, lptm.tmHeight);
- } else {
- extra = Math.max (MARGIN * 2, lptm.tmAveCharWidth);
- TCHAR buffer = new TCHAR (getCodePage (), text, true);
- RECT rect = new RECT ();
- int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE;
- OS.DrawText (hDC, buffer, -1, rect, flags);
- width += rect.right - rect.left;
- height = Math.max (height, rect.bottom - rect.top);
- }
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- }
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- width += CHECK_WIDTH + extra;
- height = Math.max (height, CHECK_HEIGHT + 3);
- }
- if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) {
- width += 12; height += 10;
- }
- }
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- width += border * 2;
- height += border * 2;
- return new Point (width, height);
-}
-
-void createHandle () {
- /*
- * Feature in Windows. When a button is created,
- * it clears the UI state for all controls in the
- * shell by sending WM_CHANGEUISTATE with UIS_SET,
- * UISF_HIDEACCEL and UISF_HIDEFOCUS to the parent.
- * This is undocumented and unexpected. The fix
- * is to ignore the WM_CHANGEUISTATE, when sent
- * from CreateWindowEx().
- */
- parent.state |= IGNORE_WM_CHANGEUISTATE;
- super.createHandle ();
- parent.state &= ~IGNORE_WM_CHANGEUISTATE;
-
- /* Set the theme background */
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- /*
- * NOTE: On Vista this causes problems when the tab
- * key is pressed for push buttons so disable the
- * theme background drawing for these widgets for
- * now.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION < OS.VERSION (6, 0)) {
- state |= THEME_BACKGROUND;
- } else {
- if ((style & (SWT.PUSH | SWT.TOGGLE)) == 0) {
- state |= THEME_BACKGROUND;
- }
- }
- }
-
- /*
- * Bug in Windows. For some reason, the HBRUSH that
- * is returned from WM_CTRLCOLOR is misaligned when
- * the button uses it to draw. If the brush is a solid
- * color, this does not matter. However, if the brush
- * contains an image, the image is misaligned. The
- * fix is to draw the background in WM_CTRLCOLOR.
- *
- * NOTE: For comctl32.dll 6.0 with themes disabled,
- * drawing in WM_ERASEBKGND will draw on top of the
- * text of the control.
- */
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- if ((style & SWT.RADIO) != 0) state |= DRAW_BACKGROUND;
- }
-
- /*
- * Feature in Windows. Push buttons draw border around
- * the button using the default background color instead
- * of using the color provided by WM_CTRLCOLOR. The fix
- * is to draw the background in WM_CTRLCOLOR.
- *
- * NOTE: On Vista this causes problems when the tab key
- * is pressed for push buttons so disable the fix for now.
- */
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- if (!OS.IsWinCE && OS.WIN32_VERSION < OS.VERSION (6, 0)) {
- if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) {
- state |= DRAW_BACKGROUND;
- }
- }
- }
-}
-
-int defaultBackground () {
- if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) {
- return OS.GetSysColor (OS.COLOR_BTNFACE);
- }
- return super.defaultBackground ();
-}
-
-int defaultForeground () {
- return OS.GetSysColor (OS.COLOR_BTNTEXT);
-}
-
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- /*
- * Bug in Windows. When a button control is right-to-left and
- * is disabled, the first pixel of the text is clipped. The
- * fix is to add a space to both sides of the text.
- */
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- boolean hasImage = (bits & (OS.BS_BITMAP | OS.BS_ICON)) != 0;
- if (!hasImage) {
- String string = enabled ? text : " " + text + " ";
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- OS.SetWindowText (handle, buffer);
- }
- }
- }
- /*
- * Bug in Windows. When a button has the style BS_CHECKBOX
- * or BS_RADIOBUTTON, is checked, and is displaying both an
- * image and some text, when BCM_SETIMAGELIST is used to
- * assign an image list for each of the button states, the
- * button does not draw properly. When the user drags the
- * mouse in and out of the button, it draws using a blank
- * image. The fix is to set the complete image list only
- * when the button is disabled.
- */
- if (OS.COMCTL32_MAJOR >= 6) {
- if (imageList != null) {
- BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST ();
- OS.SendMessage (handle, OS.BCM_GETIMAGELIST, 0, buttonImageList);
- if (imageList != null) imageList.dispose ();
- imageList = new ImageList (style & SWT.RIGHT_TO_LEFT);
- if (OS.IsWindowEnabled (handle)) {
- imageList.add (image);
- } else {
- if (disabledImage != null) disabledImage.dispose ();
- disabledImage = new Image (display, image, SWT.IMAGE_DISABLE);
- imageList.add (disabledImage);
- }
- buttonImageList.himl = imageList.getHandle ();
- OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, buttonImageList);
- /*
- * Bug in Windows. Under certain cirumstances yet to be
- * isolated, BCM_SETIMAGELIST does not redraw the control
- * when an image is set. The fix is to force a redraw.
- */
- OS.InvalidateRect (handle, null, true);
- }
- }
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is an <code>ARROW</code> button, in
- * which case, the alignment will indicate the direction of
- * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>,
- * <code>UP</code> or <code>DOWN</code>).
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget ();
- if ((style & SWT.ARROW) != 0) {
- if ((style & SWT.UP) != 0) return SWT.UP;
- if ((style & SWT.DOWN) != 0) return SWT.DOWN;
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.UP;
- }
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-boolean getDefault () {
- if ((style & SWT.PUSH) == 0) return false;
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- return (bits & OS.BS_DEFPUSHBUTTON) != 0;
-}
-
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the widget does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getGrayed () {
- checkWidget();
- if ((style & SWT.CHECK) == 0) return false;
- return grayed;
-}
-
-/**
- * Returns the receiver's image if it has one, or null
- * if it does not.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget ();
- return image;
-}
-
-/**
- * Returns the widget message. When the widget is created
- * with the style <code>SWT.COMMAND</code>, the message text
- * is displayed to provide further information for the user.
- *
- * @return the widget message
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-/*public*/ String getMessage () {
- checkWidget ();
- return message;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked. When it is of type <code>TOGGLE</code>,
- * it is selected when it is pushed in. If the receiver is of any other type,
- * this method returns false.
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget ();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false;
- int /*long*/ flags = OS.SendMessage (handle, OS.BM_GETCHECK, 0, 0);
- return flags != OS.BST_UNCHECKED;
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set or if the receiver is
- * an <code>ARROW</code> button.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- if ((style & SWT.ARROW) != 0) return "";
- return text;
-}
-
-boolean isTabItem () {
- if ((style & SWT.PUSH) != 0) return isTabGroup ();
- return super.isTabItem ();
-}
-
-boolean mnemonicHit (char ch) {
- if (!setFocus ()) return false;
- /*
- * Feature in Windows. When a radio button gets focus,
- * it selects the button in WM_SETFOCUS. Therefore, it
- * is not necessary to click the button or send events
- * because this has already happened in WM_SETFOCUS.
- */
- if ((style & SWT.RADIO) == 0) click ();
- return true;
-}
-
-boolean mnemonicMatch (char key) {
- char mnemonic = findMnemonic (getText ());
- if (mnemonic == '\0') return false;
- return Character.toUpperCase (key) == Character.toUpperCase (mnemonic);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (imageList != null) imageList.dispose ();
- imageList = null;
- if (disabledImage != null) disabledImage.dispose ();
- disabledImage = null;
- if (image2 != null) image2.dispose ();
- image2 = null;
- text = null;
- image = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-void selectRadio () {
- /*
- * This code is intentionally commented. When two groups
- * of radio buttons with the same parent are separated by
- * another control, the correct behavior should be that
- * the two groups act independently. This is consistent
- * with radio tool and menu items. The commented code
- * implements this behavior.
- */
-// int index = 0;
-// Control [] children = parent._getChildren ();
-// while (index < children.length && children [index] != this) index++;
-// int i = index - 1;
-// while (i >= 0 && children [i].setRadioSelection (false)) --i;
-// int j = index + 1;
-// while (j < children.length && children [j].setRadioSelection (false)) j++;
-// setSelection (true);
- Control [] children = parent._getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (this != child) child.setRadioSelection (false);
- }
- setSelection (true);
-}
-
-/**
- * Controls how text, images and arrows will be displayed
- * in the receiver. The argument should be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is an <code>ARROW</code> button, in
- * which case, the argument indicates the direction of
- * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>,
- * <code>UP</code> or <code>DOWN</code>).
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget ();
- if ((style & SWT.ARROW) != 0) {
- if ((style & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT)) == 0) return;
- style &= ~(SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT);
- style |= alignment & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT);
- OS.InvalidateRect (handle, null, true);
- return;
- }
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE), newBits = oldBits;
- newBits &= ~(OS.BS_LEFT | OS.BS_CENTER | OS.BS_RIGHT);
- if ((style & SWT.LEFT) != 0) newBits |= OS.BS_LEFT;
- if ((style & SWT.CENTER) != 0) newBits |= OS.BS_CENTER;
- if ((style & SWT.RIGHT) != 0) newBits |= OS.BS_RIGHT;
- if (OS.COMCTL32_MAJOR >= 6) {
- if (imageList != null) {
- BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST ();
- buttonImageList.himl = imageList.getHandle ();
- if (text.length () == 0) {
- if ((style & SWT.LEFT) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT;
- if ((style & SWT.CENTER) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_CENTER;
- if ((style & SWT.RIGHT) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_RIGHT;
- } else {
- buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT;
- buttonImageList.margin_left = computeLeftMargin ();
- buttonImageList.margin_right = MARGIN;
- newBits &= ~(OS.BS_CENTER | OS.BS_RIGHT);
- newBits |= OS.BS_LEFT;
- }
- OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, buttonImageList);
- }
- }
- if (newBits != oldBits) {
- OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
- OS.InvalidateRect (handle, null, true);
- }
-}
-
-void setDefault (boolean value) {
- if ((style & SWT.PUSH) == 0) return;
- int /*long*/ hwndShell = menuShell ().handle;
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if (value) {
- bits |= OS.BS_DEFPUSHBUTTON;
- OS.SendMessage (hwndShell, OS.DM_SETDEFID, handle, 0);
- } else {
- bits &= ~OS.BS_DEFPUSHBUTTON;
- OS.SendMessage (hwndShell, OS.DM_SETDEFID, 0, 0);
- }
- OS.SendMessage (handle, OS.BM_SETSTYLE, bits, 1);
-}
-
-boolean setFixedFocus () {
- /*
- * Feature in Windows. When a radio button gets focus,
- * it selects the button in WM_SETFOCUS. The fix is to
- * not assign focus to an unselected radio button.
- */
- if ((style & SWT.RADIO) != 0 && !getSelection ()) return false;
- return super.setFixedFocus ();
-}
-
-/**
- * Sets the receiver's image to the argument, which may be
- * <code>null</code> indicating that no image should be displayed.
- * <p>
- * Note that a Button can display an image and text simultaneously
- * on Windows (starting with XP), GTK+ and OSX. On other platforms,
- * a Button that has an image and text set into it will display the
- * image or text that was set most recently.
- * </p>
- * @param image the image to display on the receiver (may be <code>null</code>)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.ARROW) != 0) return;
- this.image = image;
- /* This code is intentionally commented */
-// if (OS.COMCTL32_MAJOR < 6) {
-// if (image == null || text.length () != 0) {
-// _setText (text);
-// return;
-// }
-// }
- _setImage (image);
-}
-
-/**
- * Sets the grayed state of the receiver. This state change
- * only applies if the control was created with the SWT.CHECK
- * style.
- *
- * @param grayed the new grayed state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setGrayed (boolean grayed) {
- checkWidget ();
- if ((style & SWT.CHECK) == 0) return;
- this.grayed = grayed;
- int /*long*/ flags = OS.SendMessage (handle, OS.BM_GETCHECK, 0, 0);
- if (grayed) {
- if (flags == OS.BST_CHECKED) updateSelection (OS.BST_INDETERMINATE);
- } else {
- if (flags == OS.BST_INDETERMINATE) updateSelection (OS.BST_CHECKED);
- }
-}
-
-/**
- * Sets the widget message. When the widget is created
- * with the style <code>SWT.COMMAND</code>, the message text
- * is displayed to provide further information for the user.
- *
- * @param message the new message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-/*public*/ void setMessage (String message) {
- checkWidget ();
- if (message == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.message = message;
- if (OS.COMCTL32_VERSION >= OS.VERSION (6, 1)) {
- if ((style & SWT.COMMAND) != 0) {
- int length = message.length ();
- char [] chars = new char [length + 1];
- message.getChars(0, length, chars, 0);
- OS.SendMessage (handle, OS.BCM_SETNOTE, 0, chars);
- }
- }
-}
-
-boolean setRadioFocus (boolean tabbing) {
- if ((style & SWT.RADIO) == 0 || !getSelection ()) return false;
- return tabbing ? setTabItemFocus () : setFocus ();
-}
-
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-
-boolean setSavedFocus () {
- /*
- * Feature in Windows. When a radio button gets focus,
- * it selects the button in WM_SETFOCUS. If the previous
- * saved focus widget was a radio button, allowing the shell
- * to automatically restore the focus to the previous radio
- * button will unexpectedly check that button. The fix is to
- * not assign focus to an unselected radio button.
- */
- if ((style & SWT.RADIO) != 0 && !getSelection ()) return false;
- return super.setSavedFocus ();
-}
-
-/**
- * Sets the selection state of the receiver, if it is of type <code>CHECK</code>,
- * <code>RADIO</code>, or <code>TOGGLE</code>.
- *
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked. When it is of type <code>TOGGLE</code>,
- * it is selected when it is pushed in.
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget ();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return;
- int flags = selected ? OS.BST_CHECKED : OS.BST_UNCHECKED;
- if ((style & SWT.CHECK) != 0) {
- if (selected && grayed) flags = OS.BST_INDETERMINATE;
- }
- updateSelection (flags);
-}
-
-/**
- * Sets the receiver's text.
- * <p>
- * This method sets the button label. The label may include
- * the mnemonic character but must not contain line delimiters.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasized in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p><p>
- * Note that a Button can display an image and text simultaneously
- * on Windows (starting with XP), GTK+ and OSX. On other platforms,
- * a Button that has an image and text set into it will display the
- * image or text that was set most recently.
- * </p>
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.ARROW) != 0) return;
- text = string;
- /* This code is intentionally commented */
-// if (OS.COMCTL32_MAJOR < 6) {
-// if (text.length () == 0 && image != null) {
-// _setImage (image);
-// return;
-// }
-// }
- _setText (string);
-}
-
-void updateSelection (int flags) {
- if (flags != OS.SendMessage (handle, OS.BM_GETCHECK, 0, 0)) {
- /*
- * Feature in Windows. When BM_SETCHECK is used
- * to set the checked state of a radio or check
- * button, it sets the WM_TABSTOP style. This
- * is undocumented and unwanted. The fix is
- * to save and restore the window style bits.
- */
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((style & SWT.CHECK) != 0) {
- if (flags == OS.BST_INDETERMINATE) {
- bits &= ~OS.BS_CHECKBOX;
- bits |= OS.BS_3STATE;
- } else {
- bits |= OS.BS_CHECKBOX;
- bits &= ~OS.BS_3STATE;
- }
- if (bits != OS.GetWindowLong (handle, OS.GWL_STYLE)) {
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- }
- }
- OS.SendMessage (handle, OS.BM_SETCHECK, flags, 0);
- if (bits != OS.GetWindowLong (handle, OS.GWL_STYLE)) {
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- }
- }
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle ();
- if ((style & SWT.FLAT) != 0) bits |= OS.BS_FLAT;
- if ((style & SWT.ARROW) != 0) return bits | OS.BS_OWNERDRAW;
- if ((style & SWT.LEFT) != 0) bits |= OS.BS_LEFT;
- if ((style & SWT.CENTER) != 0) bits |= OS.BS_CENTER;
- if ((style & SWT.RIGHT) != 0) bits |= OS.BS_RIGHT;
- if ((style & SWT.PUSH) != 0) return bits | OS.BS_PUSHBUTTON | OS.WS_TABSTOP;
- if ((style & SWT.CHECK) != 0) return bits | OS.BS_CHECKBOX | OS.WS_TABSTOP;
- if ((style & SWT.RADIO) != 0) return bits | OS.BS_RADIOBUTTON;
- if ((style & SWT.TOGGLE) != 0) return bits | OS.BS_PUSHLIKE | OS.BS_CHECKBOX | OS.WS_TABSTOP;
- if ((style & SWT.COMMAND) != 0) return bits | OS.BS_COMMANDLINK | OS.WS_TABSTOP;
- return bits | OS.BS_PUSHBUTTON | OS.WS_TABSTOP;
-}
-
-TCHAR windowClass () {
- return ButtonClass;
-}
-
-int /*long*/ windowProc () {
- return ButtonProc;
-}
-
-
-LRESULT WM_ERASEBKGND (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
- if (result != null) return result;
- /*
- * Bug in Windows. For some reason, the HBRUSH that
- * is returned from WM_CTRLCOLOR is misaligned when
- * the button uses it to draw. If the brush is a solid
- * color, this does not matter. However, if the brush
- * contains an image, the image is misaligned. The
- * fix is to draw the background in WM_ERASEBKGND.
- */
- if (OS.COMCTL32_MAJOR < 6) {
- if ((style & (SWT.RADIO | SWT.CHECK)) != 0) {
- if (findImageControl () != null) {
- drawBackground (wParam);
- return LRESULT.ONE;
- }
- }
- }
- return result;
-}
-
-LRESULT WM_GETDLGCODE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_GETDLGCODE (wParam, lParam);
- if (result != null) return result;
- if ((style & SWT.ARROW) != 0) {
- return new LRESULT (OS.DLGC_STATIC);
- }
- return result;
-}
-
-LRESULT WM_KILLFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_KILLFOCUS (wParam, lParam);
- if ((style & SWT.PUSH) != 0 && getDefault ()) {
- menuShell ().setDefaultButton (null, false);
- }
- return result;
-}
-
-LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- if (ignoreMouse) return null;
- return super.WM_LBUTTONDOWN (wParam, lParam);
-}
-
-LRESULT WM_LBUTTONUP (int /*long*/ wParam, int /*long*/ lParam) {
- if (ignoreMouse) return null;
- return super.WM_LBUTTONUP (wParam, lParam);
-}
-
-LRESULT WM_SETFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. When Windows sets focus to
- * a radio button, it sets the WM_TABSTOP style.
- * This is undocumented and unwanted. The fix is
- * to save and restore the window style bits.
- */
- int bits = 0;
- if ((style & SWT.RADIO) != 0) {
- bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- }
- LRESULT result = super.WM_SETFOCUS (wParam, lParam);
- if ((style & SWT.RADIO) != 0) {
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- }
- if ((style & SWT.PUSH) != 0) {
- menuShell ().setDefaultButton (this, false);
- }
- return result;
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SIZE (wParam, lParam);
- if (result != null) return result;
- if (OS.COMCTL32_MAJOR >= 6) {
- if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) {
- if (imageList != null && text.length () != 0) {
- BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST ();
- OS.SendMessage (handle, OS.BCM_GETIMAGELIST, 0, buttonImageList);
- buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT;
- buttonImageList.margin_left = computeLeftMargin ();
- buttonImageList.margin_right = MARGIN;
- OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, buttonImageList);
- }
- }
- }
- return result;
-}
-
-LRESULT WM_SYSCOLORCHANGE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SYSCOLORCHANGE (wParam, lParam);
- if (result != null) return result;
- if (image2 != null) _setImage (image);
- return result;
-}
-
-LRESULT WM_UPDATEUISTATE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_UPDATEUISTATE (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. When WM_UPDATEUISTATE is sent to
- * a button, it sends WM_CTLCOLORBTN to get the foreground
- * and background. If drawing happens in WM_CTLCOLORBTN,
- * it will overwrite the contents of the control. The
- * fix is draw the button without drawing the background
- * and avoid the button window proc.
- *
- * NOTE: This only happens for radio, check and toggle
- * buttons.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- if ((style & (SWT.RADIO | SWT.CHECK | SWT.TOGGLE)) != 0) {
- boolean redraw = findImageControl () != null;
- if (!redraw) {
- if ((state & THEME_BACKGROUND) != 0) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- redraw = findThemeControl () != null;
- }
- }
- if (!redraw) redraw = findBackgroundControl () != null;
- }
- if (redraw) {
- OS.InvalidateRect (handle, null, false);
- int /*long*/ code = OS.DefWindowProc (handle, OS.WM_UPDATEUISTATE, wParam, lParam);
- return new LRESULT (code);
- }
- }
- }
- /*
- * Feature in Windows. Push and toggle buttons draw directly
- * in WM_UPDATEUISTATE rather than damaging and drawing later
- * in WM_PAINT. This means that clients who hook WM_PAINT
- * expecting to get all the drawing will not. The fix is to
- * redraw the control when paint events are hooked.
- */
- if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) {
- if (hooks (SWT.Paint) || filters (SWT.Paint)) OS.InvalidateRect (handle, null, true);
- }
- return result;
-}
-
-LRESULT wmCommandChild (int /*long*/ wParam, int /*long*/ lParam) {
- int code = OS.HIWORD (wParam);
- switch (code) {
- case OS.BN_CLICKED:
- case OS.BN_DOUBLECLICKED:
- if ((style & (SWT.CHECK | SWT.TOGGLE)) != 0) {
- setSelection (!getSelection ());
- } else {
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) != 0) {
- setSelection (!getSelection ());
- } else {
- selectRadio ();
- }
- }
- }
- postEvent (SWT.Selection);
- }
- return super.wmCommandChild (wParam, lParam);
-}
-
-LRESULT wmColorChild (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Bug in Windows. For some reason, the HBRUSH that
- * is returned from WM_CTRLCOLOR is misaligned when
- * the button uses it to draw. If the brush is a solid
- * color, this does not matter. However, if the brush
- * contains an image, the image is misaligned. The
- * fix is to draw the background in WM_ERASEBKGND.
- */
- LRESULT result = super.wmColorChild (wParam, lParam);
- if (OS.COMCTL32_MAJOR < 6) {
- if ((style & (SWT.RADIO | SWT.CHECK)) != 0) {
- if (findImageControl () != null) {
- OS.SetBkMode (wParam, OS.TRANSPARENT);
- return new LRESULT (OS.GetStockObject (OS.NULL_BRUSH));
- }
- }
- }
- return result;
-}
-
-LRESULT wmDrawChild (int /*long*/ wParam, int /*long*/ lParam) {
- if ((style & SWT.ARROW) == 0) return super.wmDrawChild (wParam, lParam);
- DRAWITEMSTRUCT struct = new DRAWITEMSTRUCT ();
- OS.MoveMemory (struct, lParam, DRAWITEMSTRUCT.sizeof);
- RECT rect = new RECT ();
- OS.SetRect (rect, struct.left, struct.top, struct.right, struct.bottom);
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- int iStateId = OS.ABS_LEFTNORMAL;
- switch (style & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT)) {
- case SWT.UP: iStateId = OS.ABS_UPNORMAL; break;
- case SWT.DOWN: iStateId = OS.ABS_DOWNNORMAL; break;
- case SWT.LEFT: iStateId = OS.ABS_LEFTNORMAL; break;
- case SWT.RIGHT: iStateId = OS.ABS_RIGHTNORMAL; break;
- }
- /*
- * Feature in Windows. On Vista only, DrawThemeBackground()
- * does not mirror the drawing. The fix is switch left to right
- * and right to left.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- if ((style & SWT.MIRRORED) != 0) {
- if ((style & (SWT.LEFT | SWT.RIGHT)) != 0) {
- iStateId = iStateId == OS.ABS_RIGHTNORMAL ? OS.ABS_LEFTNORMAL : OS.ABS_RIGHTNORMAL;
- }
- }
- }
- /*
- * NOTE: The normal, hot, pressed and disabled state is
- * computed relying on the fact that the increment between
- * the direction states is invariant (always separated by 4).
- */
- if (!getEnabled ()) iStateId += OS.ABS_UPDISABLED - OS.ABS_UPNORMAL;
- if ((struct.itemState & OS.ODS_SELECTED) != 0) iStateId += OS.ABS_UPPRESSED - OS.ABS_UPNORMAL;
- OS.DrawThemeBackground (display.hScrollBarTheme (), struct.hDC, OS.SBP_ARROWBTN, iStateId, rect, null);
- } else {
- int uState = OS.DFCS_SCROLLLEFT;
- switch (style & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT)) {
- case SWT.UP: uState = OS.DFCS_SCROLLUP; break;
- case SWT.DOWN: uState = OS.DFCS_SCROLLDOWN; break;
- case SWT.LEFT: uState = OS.DFCS_SCROLLLEFT; break;
- case SWT.RIGHT: uState = OS.DFCS_SCROLLRIGHT; break;
- }
- if (!getEnabled ()) uState |= OS.DFCS_INACTIVE;
- if ((style & SWT.FLAT) == SWT.FLAT) uState |= OS.DFCS_FLAT;
- if ((struct.itemState & OS.ODS_SELECTED) != 0) uState |= OS.DFCS_PUSHED;
- OS.DrawFrameControl (struct.hDC, rect, OS.DFC_SCROLL, uState);
- }
- return null;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Canvas.java
deleted file mode 100755
index 3440be9300..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Canvas.java
+++ /dev/null
@@ -1,490 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide a surface for drawing
- * arbitrary graphics.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * This class may be subclassed by custom control implementors
- * who are building controls that are <em>not</em> constructed
- * from aggregates of other controls. That is, they are either
- * painted using SWT graphics calls or are handled by native
- * methods.
- * </p>
- *
- * @see Composite
- * @see <a href="http://www.eclipse.org/swt/snippets/#canvas">Canvas snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public class Canvas extends Composite {
- Caret caret;
- IME ime;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Canvas () {
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Canvas (Composite parent, int style) {
- super (parent, style);
-}
-
-void clearArea (int x, int y, int width, int height) {
- checkWidget ();
- if (OS.IsWindowVisible (handle)) {
- RECT rect = new RECT ();
- OS.SetRect (rect, x, y, x + width, y + height);
- int /*long*/ hDC = OS.GetDCEx (handle, 0, OS.DCX_CACHE | OS.DCX_CLIPCHILDREN | OS.DCX_CLIPSIBLINGS);
- drawBackground (hDC, rect);
- OS.ReleaseDC (handle, hDC);
- }
-}
-
-/**
- * Fills the interior of the rectangle specified by the arguments,
- * with the receiver's background.
- *
- * @param gc the gc where the rectangle is to be filled
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void drawBackground (GC gc, int x, int y, int width, int height) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- RECT rect = new RECT ();
- OS.SetRect (rect, x, y, x + width, y + height);
- int /*long*/ hDC = gc.handle;
- int pixel = background == -1 ? gc.getBackground ().handle : -1;
- drawBackground (hDC, rect, pixel);
-}
-
-/**
- * Returns the caret.
- * <p>
- * The caret for the control is automatically hidden
- * and shown when the control is painted or resized,
- * when focus is gained or lost and when an the control
- * is scrolled. To avoid drawing on top of the caret,
- * the programmer must hide and show the caret when
- * drawing in the window any other time.
- * </p>
- *
- * @return the caret for the receiver, may be null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Caret getCaret () {
- checkWidget ();
- return caret;
-}
-
-/**
- * Returns the IME.
- *
- * @return the IME
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public IME getIME () {
- checkWidget ();
- return ime;
-}
-
-void releaseChildren (boolean destroy) {
- if (caret != null) {
- caret.release (false);
- caret = null;
- }
- if (ime != null) {
- ime.release (false);
- ime = null;
- }
- super.releaseChildren (destroy);
-}
-
-/**
- * Scrolls a rectangular area of the receiver by first copying
- * the source area to the destination and then causing the area
- * of the source which is not covered by the destination to
- * be repainted. Children that intersect the rectangle are
- * optionally moved during the operation. In addition, outstanding
- * paint events are flushed before the source area is copied to
- * ensure that the contents of the canvas are drawn correctly.
- *
- * @param destX the x coordinate of the destination
- * @param destY the y coordinate of the destination
- * @param x the x coordinate of the source
- * @param y the y coordinate of the source
- * @param width the width of the area
- * @param height the height of the area
- * @param all <code>true</code>if children should be scrolled, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) {
- checkWidget ();
- forceResize ();
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- RECT sourceRect = new RECT ();
- OS.SetRect (sourceRect, x, y, x + width, y + height);
- RECT clientRect = new RECT ();
- OS.GetClientRect (handle, clientRect);
- if (OS.IntersectRect (clientRect, sourceRect, clientRect)) {
- if (OS.IsWinCE) {
- OS.UpdateWindow (handle);
- } else {
- int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, null, 0, flags);
- }
- }
- int deltaX = destX - x, deltaY = destY - y;
- if (findImageControl () != null) {
- if (OS.IsWinCE) {
- OS.InvalidateRect (handle, sourceRect, true);
- } else {
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE;
- if (all) flags |= OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, sourceRect, 0, flags);
- }
- OS.OffsetRect (sourceRect, deltaX, deltaY);
- if (OS.IsWinCE) {
- OS.InvalidateRect (handle, sourceRect, true);
- } else {
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE;
- if (all) flags |= OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, sourceRect, 0, flags);
- }
- } else {
- int flags = OS.SW_INVALIDATE | OS.SW_ERASE;
- /*
- * Feature in Windows. If any child in the widget tree partially
- * intersects the scrolling rectangle, Windows moves the child
- * and copies the bits that intersect the scrolling rectangle but
- * does not redraw the child.
- *
- * Feature in Windows. When any child in the widget tree does not
- * intersect the scrolling rectangle but the parent does intersect,
- * Windows does not move the child. This is the documented (but
- * strange) Windows behavior.
- *
- * The fix is to not use SW_SCROLLCHILDREN and move the children
- * explicitly after scrolling.
- */
-// if (all) flags |= OS.SW_SCROLLCHILDREN;
- OS.ScrollWindowEx (handle, deltaX, deltaY, sourceRect, null, 0, null, flags);
- }
- if (all) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- Rectangle rect = child.getBounds ();
- if (Math.min (x + width, rect.x + rect.width) >= Math.max (x, rect.x) &&
- Math.min (y + height, rect.y + rect.height) >= Math.max (y, rect.y)) {
- child.setLocation (rect.x + deltaX, rect.y + deltaY);
- }
- }
- }
- if (isFocus) caret.setFocus ();
-}
-
-/**
- * Sets the receiver's caret.
- * <p>
- * The caret for the control is automatically hidden
- * and shown when the control is painted or resized,
- * when focus is gained or lost and when an the control
- * is scrolled. To avoid drawing on top of the caret,
- * the programmer must hide and show the caret when
- * drawing in the window any other time.
- * </p>
- * @param caret the new caret for the receiver, may be null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the caret has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCaret (Caret caret) {
- checkWidget ();
- Caret newCaret = caret;
- Caret oldCaret = this.caret;
- this.caret = newCaret;
- if (hasFocus ()) {
- if (oldCaret != null) oldCaret.killFocus ();
- if (newCaret != null) {
- if (newCaret.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- newCaret.setFocus ();
- }
- }
-}
-
-public void setFont (Font font) {
- checkWidget ();
- if (caret != null) caret.setFont (font);
- super.setFont (font);
-}
-
-/**
- * Sets the receiver's IME.
- *
- * @param ime the new IME for the receiver, may be null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the IME has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setIME (IME ime) {
- checkWidget ();
- if (ime != null && ime.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- this.ime = ime;
-}
-
-TCHAR windowClass () {
- if (display.useOwnDC) return display.windowOwnDCClass;
- return super.windowClass ();
-}
-
-int /*long*/ windowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (msg == Display.SWT_RESTORECARET) {
- if ((state & CANVAS) != 0) {
- if (caret != null) {
- caret.killFocus ();
- caret.setFocus ();
- return 1;
- }
- }
- }
- return super.windowProc (hwnd, msg, wParam, lParam);
-}
-
-LRESULT WM_CHAR (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_CHAR (wParam, lParam);
- if (result != null) return result;
- if (caret != null) {
- switch ((int)/*64*/wParam) {
- case SWT.DEL:
- case SWT.BS:
- case SWT.ESC:
- break;
- default: {
- if (OS.GetKeyState (OS.VK_CONTROL) >= 0) {
- int [] value = new int [1];
- if (OS.SystemParametersInfo (OS.SPI_GETMOUSEVANISH, 0, value, 0)) {
- if (value [0] != 0) OS.SetCursor (0);
- }
- }
- }
- }
- }
- return result;
-}
-
-LRESULT WM_IME_COMPOSITION (int /*long*/ wParam, int /*long*/ lParam) {
- if (ime != null) {
- LRESULT result = ime.WM_IME_COMPOSITION (wParam, lParam);
- if (result != null) return result;
- }
-
- /*
- * Bug in Windows. On Korean Windows XP, the IME window
- * for the Korean Input System (MS-IME 2002) always opens
- * in the top left corner of the screen, despite the fact
- * that ImmSetCompositionWindow() was called to position
- * the IME when focus is gained. The fix is to position
- * the IME on every WM_IME_COMPOSITION message.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION == OS.VERSION (5, 1)) {
- if (OS.IsDBLocale) {
- short langID = OS.GetSystemDefaultUILanguage ();
- short primaryLang = OS.PRIMARYLANGID (langID);
- if (primaryLang == OS.LANG_KOREAN) {
- if (caret != null && caret.isFocusCaret ()) {
- POINT ptCurrentPos = new POINT ();
- if (OS.GetCaretPos (ptCurrentPos)) {
- COMPOSITIONFORM lpCompForm = new COMPOSITIONFORM ();
- lpCompForm.dwStyle = OS.CFS_POINT;
- lpCompForm.x = ptCurrentPos.x;
- lpCompForm.y = ptCurrentPos.y;
- int /*long*/ hIMC = OS.ImmGetContext (handle);
- OS.ImmSetCompositionWindow (hIMC, lpCompForm);
- OS.ImmReleaseContext (handle, hIMC);
- }
- }
- }
- }
- }
- return super.WM_IME_COMPOSITION (wParam, lParam);
-}
-
-LRESULT WM_IME_COMPOSITION_START (int /*long*/ wParam, int /*long*/ lParam) {
- if (ime != null) {
- LRESULT result = ime.WM_IME_COMPOSITION_START (wParam, lParam);
- if (result != null) return result;
- }
- return super.WM_IME_COMPOSITION_START (wParam, lParam);
-}
-
-LRESULT WM_IME_ENDCOMPOSITION (int /*long*/ wParam, int /*long*/ lParam) {
- if (ime != null) {
- LRESULT result = ime.WM_IME_ENDCOMPOSITION (wParam, lParam);
- if (result != null) return result;
- }
- return super.WM_IME_ENDCOMPOSITION (wParam, lParam);
-}
-
-LRESULT WM_INPUTLANGCHANGE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_INPUTLANGCHANGE (wParam, lParam);
- if (caret != null && caret.isFocusCaret ()) {
- caret.setIMEFont ();
- caret.resizeIME ();
- }
- return result;
-}
-
-LRESULT WM_KILLFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- if (ime != null) {
- LRESULT result = ime.WM_KILLFOCUS (wParam, lParam);
- if (result != null) return result;
- }
- Caret caret = this.caret;
- LRESULT result = super.WM_KILLFOCUS (wParam, lParam);
- if (caret != null) caret.killFocus ();
- return result;
-}
-
-LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- if (ime != null) {
- LRESULT result = ime.WM_LBUTTONDOWN (wParam, lParam);
- if (result != null) return result;
- }
- return super.WM_LBUTTONDOWN (wParam, lParam);
-}
-
-LRESULT WM_SETFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SETFOCUS (wParam, lParam);
- if (caret != null && caret.isFocusCaret ()) caret.setFocus ();
- return result;
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SIZE (wParam, lParam);
- if (caret != null && caret.isFocusCaret ()) caret.resizeIME ();
- return result;
-}
-
-LRESULT WM_WINDOWPOSCHANGED (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_WINDOWPOSCHANGED (wParam, lParam);
- //if (result != null) return result;
- /*
- * Bug in Windows. When a window with style WS_EX_LAYOUTRTL
- * that contains a caret is resized, Windows does not move the
- * caret in relation to the mirrored origin in the top right.
- * The fix is to hide the caret in WM_WINDOWPOSCHANGING and
- * show the caret in WM_WINDOWPOSCHANGED.
- */
- boolean isFocus = (style & SWT.RIGHT_TO_LEFT) != 0 && caret != null && caret.isFocusCaret ();
- if (isFocus) caret.setFocus ();
- return result;
-}
-
-LRESULT WM_WINDOWPOSCHANGING (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_WINDOWPOSCHANGING (wParam, lParam);
- if (result != null) return result;
- /*
- * Bug in Windows. When a window with style WS_EX_LAYOUTRTL
- * that contains a caret is resized, Windows does not move the
- * caret in relation to the mirrored origin in the top right.
- * The fix is to hide the caret in WM_WINDOWPOSCHANGING and
- * show the caret in WM_WINDOWPOSCHANGED.
- */
- boolean isFocus = (style & SWT.RIGHT_TO_LEFT) != 0 && caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- return result;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java
deleted file mode 100755
index 3423c383a6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java
+++ /dev/null
@@ -1,600 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide an i-beam that is typically used
- * as the insertion point for text.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#caret">Caret snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Canvas tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Caret extends Widget {
- Canvas parent;
- int x, y, width, height;
- boolean moved, resized;
- boolean isVisible;
- Image image;
- Font font;
- LOGFONT oldFont;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Caret (Canvas parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget ();
-}
-
-void createWidget () {
- isVisible = true;
- if (parent.getCaret () == null) {
- parent.setCaret (this);
- }
-}
-
-int /*long*/ defaultFont () {
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hwndIME = OS.ImmGetDefaultIMEWnd (hwnd);
- int /*long*/ hFont = 0;
- if (hwndIME != 0) {
- hFont = OS.SendMessage (hwndIME, OS.WM_GETFONT, 0, 0);
- }
- if (hFont == 0) {
- hFont = OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0);
- }
- if (hFont == 0) return parent.defaultFont ();
- return hFont;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null).
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- if (image != null) {
- Rectangle rect = image.getBounds ();
- return new Rectangle (x, y, rect.width, rect.height);
- } else {
- if (!OS.IsWinCE && width == 0) {
- int [] buffer = new int [1];
- if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) {
- return new Rectangle (x, y, buffer [0], height);
- }
- }
- }
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Font getFont () {
- checkWidget();
- if (font == null) {
- int /*long*/ hFont = defaultFont ();
- return Font.win32_new (display, hFont);
- }
- return font;
-}
-
-/**
- * Returns the image that the receiver will use to paint the caret.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null).
- *
- * @return the receiver's location
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getLocation () {
- checkWidget();
- return new Point (x, y);
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Canvas</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Canvas getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns a point describing the receiver's size.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- if (image != null) {
- Rectangle rect = image.getBounds ();
- return new Point (rect.width, rect.height);
- } else {
- if (!OS.IsWinCE && width == 0) {
- int [] buffer = new int [1];
- if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) {
- return new Point (buffer [0], height);
- }
- }
- }
- return new Point (width, height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- return isVisible;
-}
-
-boolean hasFocus () {
- return parent.handle == OS.GetFocus ();
-}
-
-boolean isFocusCaret () {
- return parent.caret == this && hasFocus ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return isVisible && parent.isVisible () && hasFocus ();
-}
-
-void killFocus () {
- OS.DestroyCaret ();
- restoreIMEFont ();
-}
-
-void move () {
- moved = false;
- if (!OS.SetCaretPos (x, y)) return;
- resizeIME ();
-}
-
-void resizeIME () {
- if (!OS.IsDBLocale) return;
- POINT ptCurrentPos = new POINT ();
- if (!OS.GetCaretPos (ptCurrentPos)) return;
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hIMC = OS.ImmGetContext (hwnd);
- IME ime = parent.getIME ();
- if (ime != null && ime.isInlineEnabled ()) {
- Point size = getSize ();
- CANDIDATEFORM lpCandidate = new CANDIDATEFORM ();
- lpCandidate.dwStyle = OS.CFS_EXCLUDE;
- lpCandidate.ptCurrentPos = ptCurrentPos;
- lpCandidate.rcArea = new RECT ();
- OS.SetRect (lpCandidate.rcArea, ptCurrentPos.x, ptCurrentPos.y, ptCurrentPos.x + size.x, ptCurrentPos.y + size.y);
- OS.ImmSetCandidateWindow (hIMC, lpCandidate);
- } else {
- RECT rect = new RECT ();
- OS.GetClientRect (hwnd, rect);
- COMPOSITIONFORM lpCompForm = new COMPOSITIONFORM ();
- lpCompForm.dwStyle = OS.CFS_RECT;
- lpCompForm.x = ptCurrentPos.x;
- lpCompForm.y = ptCurrentPos.y;
- lpCompForm.left = rect.left;
- lpCompForm.right = rect.right;
- lpCompForm.top = rect.top;
- lpCompForm.bottom = rect.bottom;
- OS.ImmSetCompositionWindow (hIMC, lpCompForm);
- }
- OS.ImmReleaseContext (hwnd, hIMC);
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (this == parent.getCaret ()) parent.setCaret (null);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
- image = null;
- font = null;
- oldFont = null;
-}
-
-void resize () {
- resized = false;
- int /*long*/ hwnd = parent.handle;
- OS.DestroyCaret ();
- int /*long*/ hBitmap = image != null ? image.handle : 0;
- int width = this.width;
- if (!OS.IsWinCE && image == null && width == 0) {
- int [] buffer = new int [1];
- if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) {
- width = buffer [0];
- }
- }
- OS.CreateCaret (hwnd, hBitmap, width, height);
- OS.SetCaretPos (x, y);
- OS.ShowCaret (hwnd);
- move ();
-}
-
-void restoreIMEFont () {
- if (!OS.IsDBLocale) return;
- if (oldFont == null) return;
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hIMC = OS.ImmGetContext (hwnd);
- OS.ImmSetCompositionFont (hIMC, oldFont);
- OS.ImmReleaseContext (hwnd, hIMC);
- oldFont = null;
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the arguments. The <code>x</code> and
- * <code>y</code> arguments are relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (int x, int y, int width, int height) {
- checkWidget();
- boolean samePosition = this.x == x && this.y == y;
- boolean sameExtent = this.width == width && this.height == height;
- if (samePosition && sameExtent) return;
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- if (sameExtent) {
- moved = true;
- if (isVisible && hasFocus ()) move ();
- } else {
- resized = true;
- if (isVisible && hasFocus ()) resize ();
- }
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the argument. The <code>x</code> and
- * <code>y</code> fields of the rectangle are relative to
- * the receiver's parent (or its display if its parent is null).
- *
- * @param rect the new bounds for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (Rectangle rect) {
- if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (rect.x, rect.y, rect.width, rect.height);
-}
-
-void setFocus () {
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hBitmap = 0;
- if (image != null) hBitmap = image.handle;
- int width = this.width;
- if (!OS.IsWinCE && image == null && width == 0) {
- int [] buffer = new int [1];
- if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) {
- width = buffer [0];
- }
- }
- OS.CreateCaret (hwnd, hBitmap, width, height);
- move ();
- setIMEFont ();
- if (isVisible) OS.ShowCaret (hwnd);
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * to the font specified by the argument, or to the default font for that
- * kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkWidget();
- if (font != null && font.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.font = font;
- if (hasFocus ()) setIMEFont ();
-}
-
-/**
- * Sets the image that the receiver will use to paint the caret
- * to the image specified by the argument, or to the default
- * which is a filled rectangle if the argument is null
- *
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.image = image;
- if (isVisible && hasFocus ()) resize ();
-}
-
-void setIMEFont () {
- if (!OS.IsDBLocale) return;
- int /*long*/ hFont = 0;
- if (font != null) hFont = font.handle;
- if (hFont == 0) hFont = defaultFont ();
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hIMC = OS.ImmGetContext (hwnd);
- /* Save the current IME font */
- if (oldFont == null) {
- oldFont = OS.IsUnicode ? (LOGFONT) new LOGFONTW () : new LOGFONTA ();
- if (!OS.ImmGetCompositionFont (hIMC, oldFont)) oldFont = null;
- }
- /* Set new IME font */
- LOGFONT logFont = OS.IsUnicode ? (LOGFONT) new LOGFONTW () : new LOGFONTA ();
- if (OS.GetObject (hFont, LOGFONT.sizeof, logFont) != 0) {
- OS.ImmSetCompositionFont (hIMC, logFont);
- }
- OS.ImmReleaseContext (hwnd, hIMC);
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget();
- if (this.x == x && this.y == y) return;
- this.x = x; this.y = y;
- moved = true;
- if (isVisible && hasFocus ()) move ();
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the argument which is relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param location the new location for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (Point location) {
- checkWidget();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-/**
- * Sets the receiver's size to the point specified by the arguments.
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (int width, int height) {
- checkWidget();
- if (this.width == width && this.height == height) return;
- this.width = width; this.height = height;
- resized = true;
- if (isVisible && hasFocus ()) resize ();
-}
-
-/**
- * Sets the receiver's size to the point specified by the argument.
- *
- * @param size the new extent for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (Point size) {
- checkWidget();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSize (size.x, size.y);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget();
- if (visible == isVisible) return;
- isVisible = visible;
- int /*long*/ hwnd = parent.handle;
- if (OS.GetFocus () != hwnd) return;
- if (!isVisible) {
- OS.HideCaret (hwnd);
- } else {
- if (resized) {
- resize ();
- } else {
- if (moved) move ();
- }
- OS.ShowCaret (hwnd);
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ColorDialog.java
deleted file mode 100755
index 21dad771d7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ColorDialog.java
+++ /dev/null
@@ -1,281 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class allow the user to select a color
- * from a predefined set of available colors.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class ColorDialog extends Dialog {
- Display display;
- int width, height;
- RGB rgb;
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a composite control which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ColorDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ColorDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-int /*long*/ CCHookProc (int /*long*/ hdlg, int /*long*/ uiMsg, int /*long*/ lParam, int /*long*/ lpData) {
- switch ((int)/*64*/uiMsg) {
- case OS.WM_INITDIALOG: {
- RECT rect = new RECT ();
- OS.GetWindowRect (hdlg, rect);
- width = rect.right - rect.left;
- height = rect.bottom - rect.top;
- if (title != null && title.length () != 0) {
- /* Use the character encoding for the default locale */
- TCHAR buffer = new TCHAR (0, title, true);
- OS.SetWindowText (hdlg, buffer);
- }
- break;
- }
- case OS.WM_DESTROY: {
- RECT rect = new RECT ();
- OS.GetWindowRect (hdlg, rect);
- int newWidth = rect.right - rect.left;
- int newHeight = rect.bottom - rect.top;
- if (newWidth < width || newHeight < height) {
- //display.fullOpen = false;
- } else {
- if (newWidth > width || newHeight > height) {
- //display.fullOpen = true;
- }
- }
- break;
- }
- }
- return 0;
-}
-
-/**
- * Returns the currently selected color in the receiver.
- *
- * @return the RGB value for the selected color, may be null
- *
- * @see PaletteData#getRGBs
- */
-public RGB getRGB () {
- return rgb;
-}
-
-/**
- * Makes the receiver visible and brings it to the front
- * of the display.
- *
- * @return the selected color, or null if the dialog was
- * cancelled, no color was selected, or an error
- * occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public RGB open () {
-
- /* Get the owner HWND for the dialog */
- int /*long*/ hwndOwner = parent.handle;
- int /*long*/ hwndParent = parent.handle;
-
- /*
- * Feature in Windows. There is no API to set the orientation of a
- * color dialog. It is always inherited from the parent. The fix is
- * to create a hidden parent and set the orientation in the hidden
- * parent for the dialog to inherit.
- */
- boolean enabled = false;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
- int dialogOrientation = style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
- int parentOrientation = parent.style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
- if (dialogOrientation != parentOrientation) {
- int exStyle = OS.WS_EX_NOINHERITLAYOUT;
- if (dialogOrientation == SWT.RIGHT_TO_LEFT) exStyle |= OS.WS_EX_LAYOUTRTL;
- hwndOwner = OS.CreateWindowEx (
- exStyle,
- Shell.DialogClass,
- null,
- 0,
- OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0,
- hwndParent,
- 0,
- OS.GetModuleHandle (null),
- null);
- enabled = OS.IsWindowEnabled (hwndParent);
- if (enabled) OS.EnableWindow (hwndParent, false);
- }
- }
-
- /* Create the CCHookProc */
- Callback callback = new Callback (this, "CCHookProc", 4); //$NON-NLS-1$
- int /*long*/ lpfnHook = callback.getAddress ();
- if (lpfnHook == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
-
- /* Allocate the Custom Colors */
- display = parent.display;
- if (display.lpCustColors == 0) {
- int /*long*/ hHeap = OS.GetProcessHeap ();
- display.lpCustColors = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, 16 * 4);
- }
-
- /* Open the dialog */
- CHOOSECOLOR lpcc = new CHOOSECOLOR ();
- lpcc.lStructSize = CHOOSECOLOR.sizeof;
- lpcc.Flags = OS.CC_ANYCOLOR | OS.CC_ENABLEHOOK;
- //if (display.fullOpen) lpcc.Flags |= OS.CC_FULLOPEN;
- lpcc.lpfnHook = lpfnHook;
- lpcc.hwndOwner = hwndOwner;
- lpcc.lpCustColors = display.lpCustColors;
- if (rgb != null) {
- lpcc.Flags |= OS.CC_RGBINIT;
- int red = rgb.red & 0xFF;
- int green = (rgb.green << 8) & 0xFF00;
- int blue = (rgb.blue << 16) & 0xFF0000;
- lpcc.rgbResult = red | green | blue;
- }
-
- /* Make the parent shell be temporary modal */
- Dialog oldModal = null;
- if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- oldModal = display.getModalDialog ();
- display.setModalDialog (this);
- }
-
- /* Open the dialog */
- boolean success = OS.ChooseColor (lpcc);
-
- /* Clear the temporary dialog modal parent */
- if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- display.setModalDialog (oldModal);
- }
-
- if (success) {
- int red = lpcc.rgbResult & 0xFF;
- int green = (lpcc.rgbResult >> 8) & 0xFF;
- int blue = (lpcc.rgbResult >> 16) & 0xFF;
- rgb = new RGB (red, green, blue);
- }
-
- /* Free the CCHookProc */
- callback.dispose ();
-
- /* Free the Custom Colors */
- /*
- * This code is intentionally commented. Currently,
- * there is exactly one set of custom colors per display.
- * The memory associated with these colors is released
- * when the display is disposed.
- */
-// if (lpCustColors != 0) OS.HeapFree (hHeap, 0, lpCustColors);
-
- /* Destroy the BIDI orientation window */
- if (hwndParent != hwndOwner) {
- if (enabled) OS.EnableWindow (hwndParent, true);
- OS.SetActiveWindow (hwndParent);
- OS.DestroyWindow (hwndOwner);
- }
-
- /*
- * This code is intentionally commented. On some
- * platforms, the owner window is repainted right
- * away when a dialog window exits. This behavior
- * is currently unspecified.
- */
-// if (hwndOwner != 0) OS.UpdateWindow (hwndOwner);
-
- display = null;
- if (!success) return null;
- return rgb;
-}
-
-/**
- * Sets the receiver's selected color to be the argument.
- *
- * @param rgb the new RGB value for the selected color, may be
- * null to let the platform select a default when
- * open() is called
- * @see PaletteData#getRGBs
- */
-public void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java
deleted file mode 100755
index 694b566adb..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java
+++ /dev/null
@@ -1,2489 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are controls that allow the user
- * to choose an item from a list of items, or optionally
- * enter a new value by typing it into an editable text
- * field. Often, <code>Combo</code>s are used in the same place
- * where a single selection <code>List</code> widget could
- * be used but space is limited. A <code>Combo</code> takes
- * less space than a <code>List</code> widget and shows
- * similar information.
- * <p>
- * Note: Since <code>Combo</code>s can contain both a list
- * and an editable text field, it is possible to confuse methods
- * which access one versus the other (compare for example,
- * <code>clearSelection()</code> and <code>deselectAll()</code>).
- * The API documentation is careful to indicate either "the
- * receiver's list" or the "the receiver's text field" to
- * distinguish between the two cases.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>DROP_DOWN, READ_ONLY, SIMPLE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Modify, Selection, Verify</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles DROP_DOWN and SIMPLE may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see List
- * @see <a href="http://www.eclipse.org/swt/snippets/#combo">Combo snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Combo extends Composite {
- boolean noSelection, ignoreDefaultSelection, ignoreCharacter, ignoreModify, ignoreResize, lockText;
- int scrollWidth, visibleCount = 5;
- int /*long*/ cbtHook;
- /**
- * the operating system limit for the number of characters
- * that the text field in an instance of this class can hold
- */
- public static final int LIMIT;
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = OS.IsWinNT ? 0x7FFFFFFF : 0x7FFF;
- }
-
- /*
- * These are the undocumented control id's for the children of
- * a combo box. Since there are no constants for these values,
- * they may change with different versions of Windows (but have
- * been the same since Windows 3.0).
- */
- static final int CBID_LIST = 1000;
- static final int CBID_EDIT = 1001;
- static /*final*/ int /*long*/ EditProc, ListProc;
-
- static final int /*long*/ ComboProc;
- static final TCHAR ComboClass = new TCHAR (0, "COMBOBOX", true);
- static {
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, ComboClass, lpWndClass);
- ComboProc = lpWndClass.lpfnWndProc;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see SWT#READ_ONLY
- * @see SWT#SIMPLE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Combo (Composite parent, int style) {
- super (parent, checkStyle (style));
- /* This code is intentionally commented */
- //if ((style & SWT.H_SCROLL) != 0) this.style |= SWT.H_SCROLL;
- this.style |= SWT.H_SCROLL;
-}
-
-/**
- * Adds the argument to the end of the receiver's list.
- *
- * @param string the new item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String,int)
- */
-public void add (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- int result = (int)/*64*/OS.SendMessage (handle, OS.CB_ADDSTRING, 0, buffer);
- if (result == OS.CB_ERR) error (SWT.ERROR_ITEM_NOT_ADDED);
- if (result == OS.CB_ERRSPACE) error (SWT.ERROR_ITEM_NOT_ADDED);
- if ((style & SWT.H_SCROLL) != 0) setScrollWidth (buffer, true);
-}
-
-/**
- * Adds the argument to the receiver's list at the given
- * zero-relative index.
- * <p>
- * Note: To add an item at the end of the list, use the
- * result of calling <code>getItemCount()</code> as the
- * index or use <code>add(String)</code>.
- * </p>
- *
- * @param string the new item
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String)
- */
-public void add (String string, int index) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- if (!(0 <= index && index <= count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- int result = (int)/*64*/OS.SendMessage (handle, OS.CB_INSERTSTRING, index, buffer);
- if (result == OS.CB_ERRSPACE || result == OS.CB_ERR) {
- error (SWT.ERROR_ITEM_NOT_ADDED);
- }
- if ((style & SWT.H_SCROLL) != 0) setScrollWidth (buffer, true);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the combo's list selection.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed the combo's text area.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- *
- * @since 3.1
- */
-public void addVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- if (hwnd == handle) {
- switch (msg) {
- case OS.WM_SIZE: {
- ignoreResize = true;
- int /*long*/ result = OS.CallWindowProc (ComboProc, hwnd, msg, wParam, lParam);
- ignoreResize = false;
- return result;
- }
- }
- return OS.CallWindowProc (ComboProc, hwnd, msg, wParam, lParam);
- }
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwnd == hwndText) {
- if (lockText && msg == OS.WM_SETTEXT) return 0;
- return OS.CallWindowProc (EditProc, hwnd, msg, wParam, lParam);
- }
- int /*long*/ hwndList = OS.GetDlgItem (handle, CBID_LIST);
- if (hwnd == hwndList) {
- return OS.CallWindowProc (ListProc, hwnd, msg, wParam, lParam);
- }
- return OS.DefWindowProc (hwnd, msg, wParam, lParam);
-}
-
-int /*long*/ CBTProc (int /*long*/ nCode, int /*long*/ wParam, int /*long*/ lParam) {
- if ((int)/*64*/nCode == OS.HCBT_CREATEWND) {
- TCHAR buffer = new TCHAR (0, 128);
- OS.GetClassName (wParam, buffer, buffer.length ());
- String className = buffer.toString (0, buffer.strlen ());
- if (className.equals ("Edit") || className.equals ("EDIT")) { //$NON-NLS-1$ //$NON-NLS-2$
- int bits = OS.GetWindowLong (wParam, OS.GWL_STYLE);
- OS.SetWindowLong (wParam, OS.GWL_STYLE, bits & ~OS.ES_NOHIDESEL);
- }
- }
- return OS.CallNextHookEx (cbtHook, (int)/*64*/nCode, wParam, lParam);
-}
-
-boolean checkHandle (int /*long*/ hwnd) {
- return hwnd == handle || hwnd == OS.GetDlgItem (handle, CBID_EDIT) || hwnd == OS.GetDlgItem (handle, CBID_LIST);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-static int checkStyle (int style) {
- /*
- * Feature in Windows. It is not possible to create
- * a combo box that has a border using Windows style
- * bits. All combo boxes draw their own border and
- * do not use the standard Windows border styles.
- * Therefore, no matter what style bits are specified,
- * clear the BORDER bits so that the SWT style will
- * match the Windows widget.
- *
- * The Windows behavior is currently implemented on
- * all platforms.
- */
- style &= ~SWT.BORDER;
-
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- style &= ~(SWT.H_SCROLL | SWT.V_SCROLL);
- style = checkBits (style, SWT.DROP_DOWN, SWT.SIMPLE, 0, 0, 0, 0);
- if ((style & SWT.SIMPLE) != 0) return style & ~SWT.READ_ONLY;
- return style;
-}
-
-/**
- * Sets the selection in the receiver's text field to an empty
- * selection starting just before the first character. If the
- * text field is editable, this has the effect of placing the
- * i-beam at the start of the text.
- * <p>
- * Note: To clear the selected items in the receiver's list,
- * use <code>deselectAll()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #deselectAll
- */
-public void clearSelection () {
- checkWidget ();
- OS.SendMessage (handle, OS.CB_SETEDITSEL, 0, -1);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0;
- if (wHint == SWT.DEFAULT) {
- int /*long*/ newFont, oldFont = 0;
- int /*long*/ hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- int count = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- RECT rect = new RECT ();
- int flags = OS.DT_CALCRECT | OS.DT_NOPREFIX;
- if ((style & SWT.READ_ONLY) == 0) flags |= OS.DT_EDITCONTROL;
- int length = OS.GetWindowTextLength (handle);
- int cp = getCodePage ();
- TCHAR buffer = new TCHAR (cp, length + 1);
- OS.GetWindowText (handle, buffer, length + 1);
- OS.DrawText (hDC, buffer, length, rect, flags);
- width = Math.max (width, rect.right - rect.left);
- if ((style & SWT.H_SCROLL) != 0) {
- width = Math.max (width, scrollWidth);
- } else {
- for (int i=0; i<count; i++) {
- length = (int)/*64*/OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, i, 0);
- if (length != OS.CB_ERR) {
- if (length + 1 > buffer.length ()) buffer = new TCHAR (cp, length + 1);
- int result = (int)/*64*/OS.SendMessage (handle, OS.CB_GETLBTEXT, i, buffer);
- if (result != OS.CB_ERR) {
- OS.DrawText (hDC, buffer, length, rect, flags);
- width = Math.max (width, rect.right - rect.left);
- }
- }
- }
- }
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- }
- if (hHint == SWT.DEFAULT) {
- if ((style & SWT.SIMPLE) != 0) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- int itemHeight = (int)/*64*/OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, 0, 0);
- height = count * itemHeight;
- }
- }
- if (width == 0) width = DEFAULT_WIDTH;
- if (height == 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- if ((style & SWT.READ_ONLY) != 0) {
- width += 8;
- } else {
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0) {
- int /*long*/ margins = OS.SendMessage (hwndText, OS.EM_GETMARGINS, 0, 0);
- int marginWidth = OS.LOWORD (margins) + OS.HIWORD (margins);
- width += marginWidth + 3;
- }
- }
- COMBOBOXINFO pcbi = new COMBOBOXINFO ();
- pcbi.cbSize = COMBOBOXINFO.sizeof;
- if (((style & SWT.SIMPLE) == 0) && !OS.IsWinCE && OS.GetComboBoxInfo (handle, pcbi)) {
- width += pcbi.itemLeft + (pcbi.buttonRight - pcbi.buttonLeft);
- height = (pcbi.buttonBottom - pcbi.buttonTop) + pcbi.buttonTop * 2;
- } else {
- int border = OS.GetSystemMetrics (OS.SM_CXEDGE);
- width += OS.GetSystemMetrics (OS.SM_CXVSCROLL) + border * 2;
- int textHeight = (int)/*64*/OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, -1, 0);
- if ((style & SWT.DROP_DOWN) != 0) {
- height = textHeight + 6;
- } else {
- height += textHeight + 10;
- }
- }
- if ((style & SWT.SIMPLE) != 0 && (style & SWT.H_SCROLL) != 0) {
- height += OS.GetSystemMetrics (OS.SM_CYHSCROLL);
- }
- return new Point (width, height);
-}
-
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void copy () {
- checkWidget ();
- OS.SendMessage (handle, OS.WM_COPY, 0, 0);
-}
-
-void createHandle () {
- /*
- * Feature in Windows. When the selection changes in a combo box,
- * Windows draws the selection, even when the combo box does not
- * have focus. Strictly speaking, this is the correct Windows
- * behavior because the combo box sets ES_NOHIDESEL on the text
- * control that it creates. Despite this, it looks strange because
- * Windows also clears the selection and selects all the text when
- * the combo box gets focus. The fix is use the CBT hook to clear
- * the ES_NOHIDESEL style bit when the text control is created.
- */
- if (OS.IsWinCE || (style & (SWT.READ_ONLY | SWT.SIMPLE)) != 0) {
- super.createHandle ();
- } else {
- int threadId = OS.GetCurrentThreadId ();
- Callback cbtCallback = new Callback (this, "CBTProc", 3); //$NON-NLS-1$
- int /*long*/ cbtProc = cbtCallback.getAddress ();
- if (cbtProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- cbtHook = OS.SetWindowsHookEx (OS.WH_CBT, cbtProc, 0, threadId);
- super.createHandle ();
- if (cbtHook != 0) OS.UnhookWindowsHookEx (cbtHook);
- cbtHook = 0;
- cbtCallback.dispose ();
- }
- state &= ~(CANVAS | THEME_BACKGROUND);
-
- /* Get the text and list window procs */
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0 && EditProc == 0) {
- EditProc = OS.GetWindowLongPtr (hwndText, OS.GWLP_WNDPROC);
- }
- int /*long*/ hwndList = OS.GetDlgItem (handle, CBID_LIST);
- if (hwndList != 0 && ListProc == 0) {
- ListProc = OS.GetWindowLongPtr (hwndList, OS.GWLP_WNDPROC);
- }
-
- /*
- * Bug in Windows. If the combo box has the CBS_SIMPLE style,
- * the list portion of the combo box is not drawn correctly the
- * first time, causing pixel corruption. The fix is to ensure
- * that the combo box has been resized more than once.
- */
- if ((style & SWT.SIMPLE) != 0) {
- int flags = OS.SWP_NOZORDER | OS.SWP_DRAWFRAME | OS.SWP_NOACTIVATE;
- SetWindowPos (handle, 0, 0, 0, 0x3FFF, 0x3FFF, flags);
- SetWindowPos (handle, 0, 0, 0, 0, 0, flags);
- }
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void cut () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- OS.SendMessage (handle, OS.WM_CUT, 0, 0);
-}
-
-int defaultBackground () {
- return OS.GetSysColor (OS.COLOR_WINDOW);
-}
-
-void deregister () {
- super.deregister ();
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0) display.removeControl (hwndText);
- int /*long*/ hwndList = OS.GetDlgItem (handle, CBID_LIST);
- if (hwndList != 0) display.removeControl (hwndList);
-}
-
-/**
- * Deselects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget ();
- int selection = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCURSEL, 0, 0);
- if (index != selection) return;
- OS.SendMessage (handle, OS.CB_SETCURSEL, -1, 0);
- sendEvent (SWT.Modify);
- // widget could be disposed at this point
-}
-
-/**
- * Deselects all selected items in the receiver's list.
- * <p>
- * Note: To clear the selection in the receiver's text field,
- * use <code>clearSelection()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #clearSelection
- */
-public void deselectAll () {
- checkWidget ();
- OS.SendMessage (handle, OS.CB_SETCURSEL, -1, 0);
- sendEvent (SWT.Modify);
- // widget could be disposed at this point
-}
-
-boolean dragDetect (int /*long*/ hwnd, int x, int y, boolean filter, boolean [] detect, boolean [] consume) {
- if (filter && (style & SWT.READ_ONLY) == 0) {
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0) {
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.CB_GETEDITSEL, start, end);
- if (start [0] != end [0]) {
- int /*long*/ lParam = OS.MAKELPARAM (x, y);
- int position = OS.LOWORD (OS.SendMessage (hwndText, OS.EM_CHARFROMPOS, 0, lParam));
- if (start [0] <= position && position < end [0]) {
- if (super.dragDetect (hwnd, x, y, filter, detect, consume)) {
- if (consume != null) consume [0] = true;
- return true;
- }
- }
- }
- return false;
- }
- }
- return super.dragDetect (hwnd, x, y, filter, detect, consume);
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver's list. Throws an exception if the index is out
- * of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getItem (int index) {
- checkWidget ();
- int length = (int)/*64*/OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, index, 0);
- if (length != OS.CB_ERR) {
- TCHAR buffer = new TCHAR (getCodePage (), length + 1);
- int result = (int)/*64*/OS.SendMessage (handle, OS.CB_GETLBTEXT, index, buffer);
- if (result != OS.CB_ERR) return buffer.toString (0, length);
- }
- int count = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- if (0 <= index && index < count) error (SWT.ERROR_CANNOT_GET_ITEM);
- error (SWT.ERROR_INVALID_RANGE);
- return "";
-}
-
-/**
- * Returns the number of items contained in the receiver's list.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- if (count == OS.CB_ERR) error (SWT.ERROR_CANNOT_GET_COUNT);
- return count;
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the receiver's list.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- int result = (int)/*64*/OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, 0, 0);
- if (result == OS.CB_ERR) error (SWT.ERROR_CANNOT_GET_ITEM_HEIGHT);
- return result;
-}
-
-/**
- * Returns a (possibly empty) array of <code>String</code>s which are
- * the items in the receiver's list.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver's list
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getItems () {
- checkWidget ();
- int count = getItemCount ();
- String [] result = new String [count];
- for (int i=0; i<count; i++) result [i] = getItem (i);
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver's list is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's list's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getListVisible () {
- checkWidget ();
- if ((style & SWT.DROP_DOWN) != 0) {
- return OS.SendMessage (handle, OS.CB_GETDROPPEDSTATE, 0, 0) != 0;
- }
- return true;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Marks the receiver's list as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setListVisible (boolean visible) {
- checkWidget ();
- OS.SendMessage (handle, OS.CB_SHOWDROPDOWN, visible ? 1 : 0, 0);
-}
-
-/**
- * Returns the orientation of the receiver.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getOrientation () {
- checkWidget();
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-/**
- * Returns a <code>Point</code> whose x coordinate is the
- * character position representing the start of the selection
- * in the receiver's text field, and whose y coordinate is the
- * character position representing the end of the selection.
- * An "empty" selection is indicated by the x and y coordinates
- * having the same value.
- * <p>
- * Indexing is zero based. The range of a selection is from
- * 0..N where N is the number of characters in the widget.
- * </p>
- *
- * @return a point representing the selection start and end
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSelection () {
- checkWidget ();
- if ((style & SWT.DROP_DOWN) != 0 && (style & SWT.READ_ONLY) != 0) {
- return new Point (0, OS.GetWindowTextLength (handle));
- }
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.CB_GETEDITSEL, start, end);
- if (!OS.IsUnicode && OS.IsDBLocale) {
- start [0] = mbcsToWcsPos (start [0]);
- end [0] = mbcsToWcsPos (end [0]);
- }
- return new Point (start [0], end [0]);
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver's list, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget ();
- if (noSelection) return -1;
- return (int)/*64*/OS.SendMessage (handle, OS.CB_GETCURSEL, 0, 0);
-}
-
-/**
- * Returns a string containing a copy of the contents of the
- * receiver's text field, or an empty string if there are no
- * contents.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- int length = OS.GetWindowTextLength (handle);
- if (length == 0) return "";
- TCHAR buffer = new TCHAR (getCodePage (), length + 1);
- OS.GetWindowText (handle, buffer, length + 1);
- return buffer.toString (0, length);
-}
-
-/**
- * Returns the height of the receivers's text field.
- *
- * @return the text height
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTextHeight () {
- checkWidget ();
- COMBOBOXINFO pcbi = new COMBOBOXINFO ();
- pcbi.cbSize = COMBOBOXINFO.sizeof;
- if (((style & SWT.SIMPLE) == 0) && !OS.IsWinCE && OS.GetComboBoxInfo (handle, pcbi)) {
- return (pcbi.buttonBottom - pcbi.buttonTop) + pcbi.buttonTop * 2;
- }
- int result = (int)/*64*/OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, -1, 0);
- if (result == OS.CB_ERR) error (SWT.ERROR_CANNOT_GET_ITEM_HEIGHT);
- return (style & SWT.DROP_DOWN) != 0 ? result + 6 : result + 10;
-}
-
-/**
- * Returns the maximum number of characters that the receiver's
- * text field is capable of holding. If this has not been changed
- * by <code>setTextLimit()</code>, it will be the constant
- * <code>Combo.LIMIT</code>.
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public int getTextLimit () {
- checkWidget ();
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText == 0) return LIMIT;
- return (int)/*64*/OS.SendMessage (hwndText, OS.EM_GETLIMITTEXT, 0, 0) & 0x7FFFFFFF;
-}
-
-/**
- * Gets the number of items that are visible in the drop
- * down portion of the receiver's list.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @return the number of items that are visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public int getVisibleItemCount () {
- checkWidget ();
- return visibleCount;
-}
-
-boolean hasFocus () {
- int /*long*/ hwndFocus = OS.GetFocus ();
- if (hwndFocus == handle) return true;
- if (hwndFocus == 0) return false;
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndFocus == hwndText) return true;
- int /*long*/ hwndList = OS.GetDlgItem (handle, CBID_LIST);
- if (hwndFocus == hwndList) return true;
- return false;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param string the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string) {
- return indexOf (string, 0);
-}
-
-/**
- * Searches the receiver's list starting at the given,
- * zero-relative index until an item is found that is equal
- * to the argument, and returns the index of that item. If
- * no item is found or the starting index is out of range,
- * returns -1.
- *
- * @param string the search item
- * @param start the zero-relative index at which to begin the search
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string, int start) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
-
- /*
- * Bug in Windows. For some reason, CB_FINDSTRINGEXACT
- * will not find empty strings even though it is legal
- * to insert an empty string into a combo. The fix is
- * to search the combo, an item at a time.
- */
- if (string.length () == 0) {
- int count = getItemCount ();
- for (int i=start; i<count; i++) {
- if (string.equals (getItem (i))) return i;
- }
- return -1;
- }
-
- /* Use CB_FINDSTRINGEXACT to search for the item */
- int count = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- if (!(0 <= start && start < count)) return -1;
- int index = start - 1, last = 0;
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- do {
- index = (int)/*64*/OS.SendMessage (handle, OS.CB_FINDSTRINGEXACT, last = index, buffer);
- if (index == OS.CB_ERR || index <= last) return -1;
- } while (!string.equals (getItem (index)));
- return index;
-}
-
-int mbcsToWcsPos (int mbcsPos) {
- if (mbcsPos <= 0) return 0;
- if (OS.IsUnicode) return mbcsPos;
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText == 0) return mbcsPos;
- int mbcsSize = OS.GetWindowTextLengthA (hwndText);
- if (mbcsSize == 0) return 0;
- if (mbcsPos >= mbcsSize) return mbcsSize;
- byte [] buffer = new byte [mbcsSize + 1];
- OS.GetWindowTextA (hwndText, buffer, mbcsSize + 1);
- return OS.MultiByteToWideChar (getCodePage (), OS.MB_PRECOMPOSED, buffer, mbcsPos, null, 0);
-}
-
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void paste () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- OS.SendMessage (handle, OS.WM_PASTE, 0, 0);
-}
-
-void register () {
- super.register ();
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0) display.addControl (hwndText, this);
- int /*long*/ hwndList = OS.GetDlgItem (handle, CBID_LIST);
- if (hwndList != 0) display.addControl (hwndList, this);
-}
-
-/**
- * Removes the item from the receiver's list at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget ();
- remove (index, true);
-}
-
-void remove (int index, boolean notify) {
- TCHAR buffer = null;
- if ((style & SWT.H_SCROLL) != 0) {
- int length = (int)/*64*/OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, index, 0);
- if (length == OS.CB_ERR) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- if (0 <= index && index < count) error (SWT.ERROR_ITEM_NOT_REMOVED);
- error (SWT.ERROR_INVALID_RANGE);
- }
- buffer = new TCHAR (getCodePage (), length + 1);
- int result = (int)/*64*/OS.SendMessage (handle, OS.CB_GETLBTEXT, index, buffer);
- if (result == OS.CB_ERR) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- if (0 <= index && index < count) error (SWT.ERROR_ITEM_NOT_REMOVED);
- error (SWT.ERROR_INVALID_RANGE);
- }
- }
- int length = OS.GetWindowTextLength (handle);
- int code = (int)/*64*/OS.SendMessage (handle, OS.CB_DELETESTRING, index, 0);
- if (code == OS.CB_ERR) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- if (0 <= index && index < count) error (SWT.ERROR_ITEM_NOT_REMOVED);
- error (SWT.ERROR_INVALID_RANGE);
- }
- if ((style & SWT.H_SCROLL) != 0) setScrollWidth (buffer, true);
- if (notify && length != OS.GetWindowTextLength (handle)) {
- sendEvent (SWT.Modify);
- if (isDisposed ()) return;
- }
- /*
- * Bug in Windows. When the combo box is read only
- * with exactly one item that is currently selected
- * and that item is removed, the combo box does not
- * redraw to clear the text area. The fix is to
- * force a redraw.
- */
- if ((style & SWT.READ_ONLY) != 0) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- if (count == 0) OS.InvalidateRect (handle, null, true);
- }
-}
-
-/**
- * Removes the items from the receiver's list which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget ();
- if (start > end) return;
- int count = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- if (!(0 <= start && start <= end && end < count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int textLength = OS.GetWindowTextLength (handle);
- RECT rect = null;
- int /*long*/ hDC = 0, oldFont = 0, newFont = 0;
- int newWidth = 0;
- if ((style & SWT.H_SCROLL) != 0) {
- rect = new RECT ();
- hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- }
- int cp = getCodePage ();
- int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX;
- for (int i=start; i<=end; i++) {
- TCHAR buffer = null;
- if ((style & SWT.H_SCROLL) != 0) {
- int length = (int)/*64*/OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, start, 0);
- if (length == OS.CB_ERR) break;
- buffer = new TCHAR (cp, length + 1);
- int result = (int)/*64*/OS.SendMessage (handle, OS.CB_GETLBTEXT, start, buffer);
- if (result == OS.CB_ERR) break;
- }
- int result = (int)/*64*/OS.SendMessage (handle, OS.CB_DELETESTRING, start, 0);
- if (result == OS.CB_ERR) error (SWT.ERROR_ITEM_NOT_REMOVED);
- if ((style & SWT.H_SCROLL) != 0) {
- OS.DrawText (hDC, buffer, -1, rect, flags);
- newWidth = Math.max (newWidth, rect.right - rect.left);
- }
- }
- if ((style & SWT.H_SCROLL) != 0) {
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- setScrollWidth (newWidth, false);
- }
- if (textLength != OS.GetWindowTextLength (handle)) {
- sendEvent (SWT.Modify);
- if (isDisposed ()) return;
- }
- /*
- * Bug in Windows. When the combo box is read only
- * with exactly one item that is currently selected
- * and that item is removed, the combo box does not
- * redraw to clear the text area. The fix is to
- * force a redraw.
- */
- if ((style & SWT.READ_ONLY) != 0) {
- count = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- if (count == 0) OS.InvalidateRect (handle, null, true);
- }
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * until an item is found that is equal to the argument,
- * and removes that item from the list.
- *
- * @param string the item to remove
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = indexOf (string, 0);
- if (index == -1) error (SWT.ERROR_INVALID_ARGUMENT);
- remove (index);
-}
-
-/**
- * Removes all of the items from the receiver's list and clear the
- * contents of receiver's text field.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget ();
- OS.SendMessage (handle, OS.CB_RESETCONTENT, 0, 0);
- sendEvent (SWT.Modify);
- if (isDisposed ()) return;
- if ((style & SWT.H_SCROLL) != 0) setScrollWidth (0);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- *
- * @since 3.1
- */
-public void removeVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-
-boolean sendKeyEvent (int type, int msg, int /*long*/ wParam, int /*long*/ lParam, Event event) {
- if (!super.sendKeyEvent (type, msg, wParam, lParam, event)) {
- return false;
- }
- if ((style & SWT.READ_ONLY) != 0) return true;
- if (type != SWT.KeyDown) return true;
- if (msg != OS.WM_CHAR && msg != OS.WM_KEYDOWN && msg != OS.WM_IME_CHAR) {
- return true;
- }
- if (event.character == 0) return true;
- if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return true;
- char key = event.character;
- int stateMask = event.stateMask;
-
- /*
- * Disable all magic keys that could modify the text
- * and don't send events when Alt, Shift or Ctrl is
- * pressed.
- */
- switch (msg) {
- case OS.WM_CHAR:
- if (key != 0x08 && key != 0x7F && key != '\r' && key != '\t' && key != '\n') break;
- // FALL THROUGH
- case OS.WM_KEYDOWN:
- if ((stateMask & (SWT.ALT | SWT.SHIFT | SWT.CONTROL)) != 0) return false;
- break;
- }
-
- /*
- * If the left button is down, the text widget refuses the character.
- */
- if (OS.GetKeyState (OS.VK_LBUTTON) < 0) {
- return true;
- }
-
- /* Verify the character */
- String oldText = "";
- int [] start = new int [1], end = new int [1];
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText == 0) return true;
- OS.SendMessage (hwndText, OS.EM_GETSEL, start, end);
- switch (key) {
- case 0x08: /* Bs */
- if (start [0] == end [0]) {
- if (start [0] == 0) return true;
- start [0] = start [0] - 1;
- if (!OS.IsUnicode && OS.IsDBLocale) {
- int [] newStart = new int [1], newEnd = new int [1];
- OS.SendMessage (hwndText, OS.EM_SETSEL, start [0], end [0]);
- OS.SendMessage (hwndText, OS.EM_GETSEL, newStart, newEnd);
- if (start [0] != newStart [0]) start [0] = start [0] - 1;
- }
- start [0] = Math.max (start [0], 0);
- }
- break;
- case 0x7F: /* Del */
- if (start [0] == end [0]) {
- int length = OS.GetWindowTextLength (hwndText);
- if (start [0] == length) return true;
- end [0] = end [0] + 1;
- if (!OS.IsUnicode && OS.IsDBLocale) {
- int [] newStart = new int [1], newEnd = new int [1];
- OS.SendMessage (hwndText, OS.EM_SETSEL, start [0], end [0]);
- OS.SendMessage (hwndText, OS.EM_GETSEL, newStart, newEnd);
- if (end [0] != newEnd [0]) end [0] = end [0] + 1;
- }
- end [0] = Math.min (end [0], length);
- }
- break;
- case '\r': /* Return */
- return true;
- default: /* Tab and other characters */
- if (key != '\t' && key < 0x20) return true;
- oldText = new String (new char [] {key});
- break;
- }
- String newText = verifyText (oldText, start [0], end [0], event);
- if (newText == null) return false;
- if (newText == oldText) return true;
- TCHAR buffer = new TCHAR (getCodePage (), newText, true);
- OS.SendMessage (hwndText, OS.EM_SETSEL, start [0], end [0]);
- OS.SendMessage (hwndText, OS.EM_REPLACESEL, 0, buffer);
- return false;
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- if (0 <= index && index < count) {
- int selection = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCURSEL, 0, 0);
- int code = (int)/*64*/OS.SendMessage (handle, OS.CB_SETCURSEL, index, 0);
- if (code != OS.CB_ERR && code != selection) {
- sendEvent (SWT.Modify);
- // widget could be disposed at this point
- }
- }
-}
-
-void setBackgroundImage (int /*long*/ hBitmap) {
- super.setBackgroundImage (hBitmap);
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0) OS.InvalidateRect (hwndText, null, true);
- int /*long*/ hwndList = OS.GetDlgItem (handle, CBID_LIST);
- if (hwndList != 0) OS.InvalidateRect (hwndList, null, true);
-}
-
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0) OS.InvalidateRect (hwndText, null, true);
- int /*long*/ hwndList = OS.GetDlgItem (handle, CBID_LIST);
- if (hwndList != 0) OS.InvalidateRect (hwndList, null, true);
-}
-
-void setBounds (int x, int y, int width, int height, int flags) {
- /*
- * Feature in Windows. If the combo box has the CBS_DROPDOWN
- * or CBS_DROPDOWNLIST style, Windows uses the height that the
- * programmer sets in SetWindowPos () to control height of the
- * drop down list. When the width is non-zero, Windows remembers
- * this value and sets the height to be the height of the text
- * field part of the combo box. If the width is zero, Windows
- * allows the height to have any value. Therefore, when the
- * programmer sets and then queries the height, the values can
- * be different depending on the width. The problem occurs when
- * the programmer uses computeSize () to determine the preferred
- * height (always the height of the text field) and then uses
- * this value to set the height of the combo box. The result
- * is a combo box with a zero size drop down list. The fix, is
- * to always set the height to show a fixed number of combo box
- * items and ignore the height value that the programmer supplies.
- */
- if ((style & SWT.DROP_DOWN) != 0) {
- height = getTextHeight () + (getItemHeight () * visibleCount) + 2;
- /*
- * Feature in Windows. When a drop down combo box is resized,
- * the combo box resizes the height of the text field and uses
- * the height provided in SetWindowPos () to determine the height
- * of the drop down list. For some reason, the combo box redraws
- * the whole area, not just the text field. The fix is to set the
- * SWP_NOSIZE bits when the height of text field and the drop down
- * list is the same as the requested height.
- *
- * NOTE: Setting the width of a combo box to zero does not update
- * the width of the drop down control rect. If the width of the
- * combo box is zero, then do not set SWP_NOSIZE.
- */
- RECT rect = new RECT ();
- OS.GetWindowRect (handle, rect);
- if (rect.right - rect.left != 0) {
- if (OS.SendMessage (handle, OS.CB_GETDROPPEDCONTROLRECT, 0, rect) != 0) {
- int oldWidth = rect.right - rect.left, oldHeight = rect.bottom - rect.top;
- if (oldWidth == width && oldHeight == height) flags |= OS.SWP_NOSIZE;
- }
- }
- SetWindowPos (handle, 0, x, y, width, height, flags);
- } else {
- super.setBounds (x, y, width, height, flags);
- }
-}
-
-public void setFont (Font font) {
- checkWidget ();
- super.setFont (font);
- if ((style & SWT.H_SCROLL) != 0) setScrollWidth ();
-}
-
-void setForegroundPixel (int pixel) {
- super.setForegroundPixel (pixel);
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0) OS.InvalidateRect (hwndText, null, true);
- int /*long*/ hwndList = OS.GetDlgItem (handle, CBID_LIST);
- if (hwndList != 0) OS.InvalidateRect (hwndList, null, true);
-}
-
-/**
- * Sets the text of the item in the receiver's list at the given
- * zero-relative index to the string argument.
- *
- * @param index the index for the item
- * @param string the new text for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItem (int index, String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int selection = getSelectionIndex ();
- remove (index, false);
- if (isDisposed ()) return;
- add (string, index);
- if (selection != -1) select (selection);
-}
-
-/**
- * Sets the receiver's list to be the given array of items.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItems (String [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<items.length; i++) {
- if (items [i] == null) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- RECT rect = null;
- int /*long*/ hDC = 0, oldFont = 0, newFont = 0;
- int newWidth = 0;
- if ((style & SWT.H_SCROLL) != 0) {
- rect = new RECT ();
- hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- setScrollWidth (0);
- }
- OS.SendMessage (handle, OS.CB_RESETCONTENT, 0, 0);
- int codePage = getCodePage ();
- for (int i=0; i<items.length; i++) {
- String string = items [i];
- TCHAR buffer = new TCHAR (codePage, string, true);
- int code = (int)/*64*/OS.SendMessage (handle, OS.CB_ADDSTRING, 0, buffer);
- if (code == OS.CB_ERR) error (SWT.ERROR_ITEM_NOT_ADDED);
- if (code == OS.CB_ERRSPACE) error (SWT.ERROR_ITEM_NOT_ADDED);
- if ((style & SWT.H_SCROLL) != 0) {
- int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX;
- OS.DrawText (hDC, buffer, -1, rect, flags);
- newWidth = Math.max (newWidth, rect.right - rect.left);
- }
- }
- if ((style & SWT.H_SCROLL) != 0) {
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- setScrollWidth (newWidth + 3);
- }
- sendEvent (SWT.Modify);
- // widget could be disposed at this point
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- * <p>
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public void setOrientation (int orientation) {
- checkWidget();
- if (OS.IsWinCE) return;
- if (OS.WIN32_VERSION < OS.VERSION (4, 10)) return;
- int flags = SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT;
- if ((orientation & flags) == 0 || (orientation & flags) == flags) return;
- style &= ~flags;
- style |= orientation & flags;
- int bits = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- style |= SWT.MIRRORED;
- bits |= OS.WS_EX_LAYOUTRTL;
- } else {
- style &= ~SWT.MIRRORED;
- bits &= ~OS.WS_EX_LAYOUTRTL;
- }
- OS.SetWindowLong (handle, OS.GWL_EXSTYLE, bits);
- int /*long*/ hwndText = 0, hwndList = 0;
- COMBOBOXINFO pcbi = new COMBOBOXINFO ();
- pcbi.cbSize = COMBOBOXINFO.sizeof;
- if (OS.GetComboBoxInfo (handle, pcbi)) {
- hwndText = pcbi.hwndItem;
- hwndList = pcbi.hwndList;
- }
- if (hwndText != 0) {
- int bits1 = OS.GetWindowLong (hwndText, OS.GWL_EXSTYLE);
- int bits2 = OS.GetWindowLong (hwndText, OS.GWL_STYLE);
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- bits1 |= OS.WS_EX_RIGHT | OS.WS_EX_RTLREADING;
- bits2 |= OS.ES_RIGHT;
- } else {
- bits1 &= ~(OS.WS_EX_RIGHT | OS.WS_EX_RTLREADING);
- bits2 &= ~OS.ES_RIGHT;
- }
- OS.SetWindowLong (hwndText, OS.GWL_EXSTYLE, bits1);
- OS.SetWindowLong (hwndText, OS.GWL_STYLE, bits2);
-
- /*
- * Bug in Windows. For some reason, the single line text field
- * portion of the combo box does not redraw to reflect the new
- * style bits. The fix is to force the widget to be resized by
- * temporarily shrinking and then growing the width and height.
- */
- RECT rect = new RECT ();
- OS.GetWindowRect (hwndText, rect);
- int width = rect.right - rect.left, height = rect.bottom - rect.top;
- OS.GetWindowRect (handle, rect);
- int widthCombo = rect.right - rect.left, heightCombo = rect.bottom - rect.top;
- int uFlags = OS.SWP_NOMOVE | OS.SWP_NOZORDER | OS.SWP_NOACTIVATE;
- SetWindowPos (hwndText, 0, 0, 0, width - 1, height - 1, uFlags);
- SetWindowPos (handle, 0, 0, 0, widthCombo - 1, heightCombo - 1, uFlags);
- SetWindowPos (hwndText, 0, 0, 0, width, height, uFlags);
- SetWindowPos (handle, 0, 0, 0, widthCombo, heightCombo, uFlags);
- OS.InvalidateRect (handle, null, true);
- }
- if (hwndList != 0) {
- int bits1 = OS.GetWindowLong (hwndList, OS.GWL_EXSTYLE);
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- bits1 |= OS.WS_EX_LAYOUTRTL;
- } else {
- bits1 &= ~OS.WS_EX_LAYOUTRTL;
- }
- OS.SetWindowLong (hwndList, OS.GWL_EXSTYLE, bits1);
- }
-}
-
-void setScrollWidth () {
- int newWidth = 0;
- RECT rect = new RECT ();
- int /*long*/ newFont, oldFont = 0;
- int /*long*/ hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- int cp = getCodePage ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX;
- for (int i=0; i<count; i++) {
- int length = (int)/*64*/OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, i, 0);
- if (length != OS.CB_ERR) {
- TCHAR buffer = new TCHAR (cp, length + 1);
- int result = (int)/*64*/OS.SendMessage (handle, OS.CB_GETLBTEXT, i, buffer);
- if (result != OS.CB_ERR) {
- OS.DrawText (hDC, buffer, -1, rect, flags);
- newWidth = Math.max (newWidth, rect.right - rect.left);
- }
- }
- }
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- setScrollWidth (newWidth + 3);
-}
-
-void setScrollWidth (int scrollWidth) {
- this.scrollWidth = scrollWidth;
- if ((style & SWT.SIMPLE) != 0) {
- OS.SendMessage (handle, OS.CB_SETHORIZONTALEXTENT, scrollWidth, 0);
- return;
- }
- boolean scroll = false;
- int count = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- if (count > 3) {
- int maxWidth = 0;
- if (OS.IsWinCE || OS.WIN32_VERSION < OS.VERSION (4, 10)) {
- RECT rect = new RECT ();
- OS.SystemParametersInfo (OS.SPI_GETWORKAREA, 0, rect, 0);
- maxWidth = (rect.right - rect.left) / 4;
- } else {
- int /*long*/ hmonitor = OS.MonitorFromWindow (handle, OS.MONITOR_DEFAULTTONEAREST);
- MONITORINFO lpmi = new MONITORINFO ();
- lpmi.cbSize = MONITORINFO.sizeof;
- OS.GetMonitorInfo (hmonitor, lpmi);
- maxWidth = (lpmi.rcWork_right - lpmi.rcWork_left) / 4;
- }
- scroll = scrollWidth > maxWidth;
- }
- /*
- * Feature in Windows. For some reason, in a editable combo box,
- * when CB_SETDROPPEDWIDTH is used to set the width of the drop
- * down list and the current text does not match an item in the
- * list, Windows selects the item that most closely matches the
- * contents of the combo. The fix is to lock the current text
- * by ignoring all WM_SETTEXT messages during processing of
- * CB_SETDROPPEDWIDTH.
- */
- if ((style & SWT.READ_ONLY) == 0) lockText = true;
- if (scroll) {
- OS.SendMessage (handle, OS.CB_SETDROPPEDWIDTH, 0, 0);
- OS.SendMessage (handle, OS.CB_SETHORIZONTALEXTENT, scrollWidth, 0);
- } else {
- scrollWidth += OS.GetSystemMetrics (OS.SM_CYHSCROLL);
- OS.SendMessage (handle, OS.CB_SETDROPPEDWIDTH, scrollWidth, 0);
- OS.SendMessage (handle, OS.CB_SETHORIZONTALEXTENT, 0, 0);
- }
- if ((style & SWT.READ_ONLY) == 0) lockText = false;
-}
-
-void setScrollWidth (TCHAR buffer, boolean grow) {
- RECT rect = new RECT ();
- int /*long*/ newFont, oldFont = 0;
- int /*long*/ hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX;
- OS.DrawText (hDC, buffer, -1, rect, flags);
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- setScrollWidth (rect.right - rect.left, grow);
-}
-
-void setScrollWidth (int newWidth, boolean grow) {
- if (grow) {
- if (newWidth <= scrollWidth) return;
- setScrollWidth (newWidth + 3);
- } else {
- if (newWidth < scrollWidth) return;
- setScrollWidth ();
- }
-}
-
-/**
- * Sets the selection in the receiver's text field to the
- * range specified by the argument whose x coordinate is the
- * start of the selection and whose y coordinate is the end
- * of the selection.
- *
- * @param selection a point representing the new selection start and end
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (Point selection) {
- checkWidget ();
- if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
- int start = selection.x, end = selection.y;
- if (!OS.IsUnicode && OS.IsDBLocale) {
- start = wcsToMbcsPos (start);
- end = wcsToMbcsPos (end);
- }
- int /*long*/ bits = OS.MAKELPARAM (start, end);
- OS.SendMessage (handle, OS.CB_SETEDITSEL, 0, bits);
-}
-
-/**
- * Sets the contents of the receiver's text field to the
- * given string.
- * <p>
- * This call is ignored when the receiver is read only and
- * the given string is not in the receiver's list.
- * </p>
- * <p>
- * Note: The text field in a <code>Combo</code> is typically
- * only capable of displaying a single line of text. Thus,
- * setting the text to a string containing line breaks or
- * other special characters will probably cause it to
- * display incorrectly.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.READ_ONLY) != 0) {
- int index = indexOf (string);
- if (index != -1) select (index);
- return;
- }
- int limit = LIMIT;
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0) {
- limit = (int)/*64*/OS.SendMessage (hwndText, OS.EM_GETLIMITTEXT, 0, 0) & 0x7FFFFFFF;
- }
- if (string.length () > limit) string = string.substring (0, limit);
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- if (OS.SetWindowText (handle, buffer)) {
- sendEvent (SWT.Modify);
- // widget could be disposed at this point
- }
-}
-
-/**
- * Sets the maximum number of characters that the receiver's
- * text field is capable of holding to be the argument.
- * <p>
- * To reset this value to the default, use <code>setTextLimit(Combo.LIMIT)</code>.
- * Specifying a limit value larger than <code>Combo.LIMIT</code> sets the
- * receiver's limit to <code>Combo.LIMIT</code>.
- * </p>
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public void setTextLimit (int limit) {
- checkWidget ();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- OS.SendMessage (handle, OS.CB_LIMITTEXT, limit, 0);
-}
-
-void setToolTipText (Shell shell, String string) {
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- int /*long*/ hwndList = OS.GetDlgItem (handle, CBID_LIST);
- if (hwndText != 0) shell.setToolTipText (hwndText, string);
- if (hwndList != 0) shell.setToolTipText (hwndList, string);
- shell.setToolTipText (handle, string);
-}
-
-/**
- * Sets the number of items that are visible in the drop
- * down portion of the receiver's list.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param count the new number of items to be visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setVisibleItemCount (int count) {
- checkWidget ();
- if (count < 0) return;
- visibleCount = count;
- if ((style & SWT.DROP_DOWN) != 0) {
- forceResize ();
- RECT rect = new RECT ();
- OS.GetWindowRect (handle, rect);
- int flags = OS.SWP_NOMOVE | OS.SWP_NOZORDER | OS.SWP_DRAWFRAME | OS.SWP_NOACTIVATE;
- setBounds (0, 0, rect.right - rect.left, rect.bottom - rect.top, flags);
- }
-}
-
-void subclass () {
- super.subclass ();
- int /*long*/ newProc = display.windowProc;
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0) {
- OS.SetWindowLongPtr (hwndText, OS.GWLP_WNDPROC, newProc);
- }
- int /*long*/ hwndList = OS.GetDlgItem (handle, CBID_LIST);
- if (hwndList != 0) {
- OS.SetWindowLongPtr (hwndList, OS.GWLP_WNDPROC, newProc);
- }
-}
-
-boolean translateTraversal (MSG msg) {
- /*
- * When the combo box is dropped down, allow return
- * to select an item in the list and escape to close
- * the combo box.
- */
- switch ((int)/*64*/(msg.wParam)) {
- case OS.VK_RETURN:
- case OS.VK_ESCAPE:
- if ((style & SWT.DROP_DOWN) != 0) {
- if (OS.SendMessage (handle, OS.CB_GETDROPPEDSTATE, 0, 0) != 0) {
- return false;
- }
- }
- }
- return super.translateTraversal (msg);
-}
-
-boolean traverseEscape () {
- if ((style & SWT.DROP_DOWN) != 0) {
- if (OS.SendMessage (handle, OS.CB_GETDROPPEDSTATE, 0, 0) != 0) {
- OS.SendMessage (handle, OS.CB_SHOWDROPDOWN, 0, 0);
- return true;
- }
- }
- return super.traverseEscape ();
-}
-
-boolean traverseReturn () {
- if ((style & SWT.DROP_DOWN) != 0) {
- if (OS.SendMessage (handle, OS.CB_GETDROPPEDSTATE, 0, 0) != 0) {
- OS.SendMessage (handle, OS.CB_SHOWDROPDOWN, 0, 0);
- return true;
- }
- }
- return super.traverseReturn ();
-}
-
-void unsubclass () {
- super.unsubclass ();
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0 && EditProc != 0) {
- OS.SetWindowLongPtr (hwndText, OS.GWLP_WNDPROC, EditProc);
- }
- int /*long*/ hwndList = OS.GetDlgItem (handle, CBID_LIST);
- if (hwndList != 0 && ListProc != 0) {
- OS.SetWindowLongPtr (hwndList, OS.GWLP_WNDPROC, ListProc);
- }
-}
-
-String verifyText (String string, int start, int end, Event keyEvent) {
- Event event = new Event ();
- event.text = string;
- event.start = start;
- event.end = end;
- if (keyEvent != null) {
- event.character = keyEvent.character;
- event.keyCode = keyEvent.keyCode;
- event.stateMask = keyEvent.stateMask;
- }
- if (!OS.IsUnicode && OS.IsDBLocale) {
- event.start = mbcsToWcsPos (start);
- event.end = mbcsToWcsPos (end);
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the verify
- * event. If this happens, answer null to cancel
- * the operation.
- */
- sendEvent (SWT.Verify, event);
- if (!event.doit || isDisposed ()) return null;
- return event.text;
-}
-
-int wcsToMbcsPos (int wcsPos) {
- if (wcsPos <= 0) return 0;
- if (OS.IsUnicode) return wcsPos;
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText == 0) return wcsPos;
- int mbcsSize = OS.GetWindowTextLengthA (hwndText);
- if (mbcsSize == 0) return 0;
- byte [] buffer = new byte [mbcsSize + 1];
- OS.GetWindowTextA (hwndText, buffer, mbcsSize + 1);
- int mbcsPos = 0, wcsCount = 0;
- while (mbcsPos < mbcsSize) {
- if (wcsPos == wcsCount) break;
- if (OS.IsDBCSLeadByte (buffer [mbcsPos++])) mbcsPos++;
- wcsCount++;
- }
- return mbcsPos;
-}
-
-int widgetExtStyle () {
- return super.widgetExtStyle () & ~OS.WS_EX_NOINHERITLAYOUT;
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle () | OS.CBS_AUTOHSCROLL | OS.CBS_NOINTEGRALHEIGHT | OS.WS_HSCROLL |OS.WS_VSCROLL;
- if ((style & SWT.SIMPLE) != 0) return bits | OS.CBS_SIMPLE;
- if ((style & SWT.READ_ONLY) != 0) return bits | OS.CBS_DROPDOWNLIST;
- return bits | OS.CBS_DROPDOWN;
-}
-
-TCHAR windowClass () {
- return ComboClass;
-}
-
-int /*long*/ windowProc () {
- return ComboProc;
-}
-
-int /*long*/ windowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- if (hwnd != handle) {
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- int /*long*/ hwndList = OS.GetDlgItem (handle, CBID_LIST);
- if ((hwndText != 0 && hwnd == hwndText) || (hwndList != 0 && hwnd == hwndList)) {
- LRESULT result = null;
- switch (msg) {
- /* Keyboard messages */
- case OS.WM_CHAR: result = wmChar (hwnd, wParam, lParam); break;
- case OS.WM_IME_CHAR: result = wmIMEChar (hwnd, wParam, lParam); break;
- case OS.WM_KEYDOWN: result = wmKeyDown (hwnd, wParam, lParam); break;
- case OS.WM_KEYUP: result = wmKeyUp (hwnd, wParam, lParam); break;
- case OS.WM_SYSCHAR: result = wmSysChar (hwnd, wParam, lParam); break;
- case OS.WM_SYSKEYDOWN: result = wmSysKeyDown (hwnd, wParam, lParam); break;
- case OS.WM_SYSKEYUP: result = wmSysKeyUp (hwnd, wParam, lParam); break;
-
- /* Mouse Messages */
- case OS.WM_CAPTURECHANGED: result = wmCaptureChanged (hwnd, wParam, lParam); break;
- case OS.WM_LBUTTONDBLCLK: result = wmLButtonDblClk (hwnd, wParam, lParam); break;
- case OS.WM_LBUTTONDOWN: result = wmLButtonDown (hwnd, wParam, lParam); break;
- case OS.WM_LBUTTONUP: result = wmLButtonUp (hwnd, wParam, lParam); break;
- case OS.WM_MBUTTONDBLCLK: result = wmMButtonDblClk (hwnd, wParam, lParam); break;
- case OS.WM_MBUTTONDOWN: result = wmMButtonDown (hwnd, wParam, lParam); break;
- case OS.WM_MBUTTONUP: result = wmMButtonUp (hwnd, wParam, lParam); break;
- case OS.WM_MOUSEHOVER: result = wmMouseHover (hwnd, wParam, lParam); break;
- case OS.WM_MOUSELEAVE: result = wmMouseLeave (hwnd, wParam, lParam); break;
- case OS.WM_MOUSEMOVE: result = wmMouseMove (hwnd, wParam, lParam); break;
-// case OS.WM_MOUSEWHEEL: result = wmMouseWheel (hwnd, wParam, lParam); break;
- case OS.WM_RBUTTONDBLCLK: result = wmRButtonDblClk (hwnd, wParam, lParam); break;
- case OS.WM_RBUTTONDOWN: result = wmRButtonDown (hwnd, wParam, lParam); break;
- case OS.WM_RBUTTONUP: result = wmRButtonUp (hwnd, wParam, lParam); break;
- case OS.WM_XBUTTONDBLCLK: result = wmXButtonDblClk (hwnd, wParam, lParam); break;
- case OS.WM_XBUTTONDOWN: result = wmXButtonDown (hwnd, wParam, lParam); break;
- case OS.WM_XBUTTONUP: result = wmXButtonUp (hwnd, wParam, lParam); break;
-
- /* Paint messages */
- case OS.WM_PAINT: result = wmPaint (hwnd, wParam, lParam); break;
-
- /* Menu messages */
- case OS.WM_CONTEXTMENU: result = wmContextMenu (hwnd, wParam, lParam); break;
-
- /* Clipboard messages */
- case OS.WM_CLEAR:
- case OS.WM_CUT:
- case OS.WM_PASTE:
- case OS.WM_UNDO:
- case OS.EM_UNDO:
- case OS.WM_SETTEXT:
- if (hwnd == hwndText) {
- result = wmClipboard (hwnd, msg, wParam, lParam);
- }
- break;
- }
- if (result != null) return result.value;
- return callWindowProc (hwnd, msg, wParam, lParam);
- }
- }
- if (msg == OS.CB_SETCURSEL) {
- if ((style & SWT.READ_ONLY) != 0) {
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- String oldText = getText (), newText = null;
- if (wParam == -1) {
- newText = "";
- } else {
- if (0 <= wParam && wParam < getItemCount ()) {
- newText = getItem ((int)/*64*/wParam);
- }
- }
- if (newText != null && !newText.equals (oldText)) {
- int length = OS.GetWindowTextLength (handle);
- oldText = newText;
- newText = verifyText (newText, 0, length, null);
- if (newText == null) return 0;
- if (!newText.equals (oldText)) {
- int index = indexOf (newText);
- if (index != -1 && index != wParam) {
- return callWindowProc (handle, OS.CB_SETCURSEL, index, lParam);
- }
- }
- }
- }
- }
- }
- return super.windowProc (hwnd, msg, wParam, lParam);
-}
-
-LRESULT WM_CTLCOLOR (int /*long*/ wParam, int /*long*/ lParam) {
- return wmColorChild (wParam, lParam);
-}
-
-LRESULT WM_GETDLGCODE (int /*long*/ wParam, int /*long*/ lParam) {
- int /*long*/ code = callWindowProc (handle, OS.WM_GETDLGCODE, wParam, lParam);
- return new LRESULT (code | OS.DLGC_WANTARROWS);
-}
-
-LRESULT WM_KILLFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Bug in Windows. When a combo box that is read only
- * is disposed in CBN_KILLFOCUS, Windows segment faults.
- * The fix is to send focus from WM_KILLFOCUS instead
- * of CBN_KILLFOCUS.
- *
- * NOTE: In version 6 of COMCTL32.DLL, the bug is fixed.
- */
- if ((style & SWT.READ_ONLY) != 0) {
- return super.WM_KILLFOCUS (wParam, lParam);
- }
-
- /*
- * Return NULL - Focus notification is
- * done in WM_COMMAND by CBN_KILLFOCUS.
- */
- return null;
-}
-
-LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. When an editable combo box is dropped
- * down and the text in the entry field partially matches an
- * item in the list, Windows selects the item but doesn't send
- * WM_COMMAND with CBN_SELCHANGE. The fix is to detect that
- * the selection has changed and issue the notification.
- */
- int oldSelection = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCURSEL, 0, 0);
- LRESULT result = super.WM_LBUTTONDOWN (wParam, lParam);
- if (result == LRESULT.ZERO) return result;
- if ((style & SWT.READ_ONLY) == 0) {
- int newSelection = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCURSEL, 0, 0);
- if (oldSelection != newSelection) {
- sendEvent (SWT.Modify);
- if (isDisposed ()) return LRESULT.ZERO;
- sendEvent (SWT.Selection);
- if (isDisposed ()) return LRESULT.ZERO;
- }
- }
- return result;
-}
-
-LRESULT WM_SETFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Return NULL - Focus notification is
- * done by WM_COMMAND with CBN_SETFOCUS.
- */
- return null;
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. When a combo box is resized,
- * the size of the drop down rectangle is specified
- * using the height and then the combo box resizes
- * to be the height of the text field. This causes
- * two WM_SIZE messages to be sent and two SWT.Resize
- * events to be issued. The fix is to ignore the
- * second resize.
- */
- if (ignoreResize) return null;
- /*
- * Bug in Windows. If the combo box has the CBS_SIMPLE style,
- * the list portion of the combo box is not redrawn when the
- * combo box is resized. The fix is to force a redraw when
- * the size has changed.
- */
- if ((style & SWT.SIMPLE) != 0) {
- LRESULT result = super.WM_SIZE (wParam, lParam);
- if (OS.IsWindowVisible (handle)) {
- if (OS.IsWinCE) {
- int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0) OS.InvalidateRect (hwndText, null, true);
- int /*long*/ hwndList = OS.GetDlgItem (handle, CBID_LIST);
- if (hwndList != 0) OS.InvalidateRect (hwndList, null, true);
- } else {
- int uFlags = OS.RDW_ERASE | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, null, 0, uFlags);
- }
- }
- return result;
- }
-
- /*
- * Feature in Windows. When an editable drop down combo box
- * contains text that does not correspond to an item in the
- * list, when the widget is resized, it selects the closest
- * match from the list. The fix is to lock the current text
- * by ignoring all WM_SETTEXT messages during processing of
- * WM_SIZE.
- */
- if ((style & SWT.READ_ONLY) == 0) lockText = true;
- LRESULT result = super.WM_SIZE (wParam, lParam);
- if ((style & SWT.READ_ONLY) == 0) lockText = false;
- /*
- * Feature in Windows. When CB_SETDROPPEDWIDTH is called with
- * a width that is smaller than the current size of the combo
- * box, it is ignored. This the fix is to set the width after
- * the combo box has been resized.
- */
- if ((style & SWT.H_SCROLL) != 0) setScrollWidth (scrollWidth);
- return result;
-}
-
-LRESULT WM_WINDOWPOSCHANGING (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_WINDOWPOSCHANGING (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. When a combo box is resized,
- * the size of the drop down rectangle is specified
- * using the height and then the combo box resizes
- * to be the height of the text field. This causes
- * sibling windows that intersect with the original
- * bounds to redrawn. The fix is to stop the redraw
- * using SWP_NOREDRAW and then damage the combo box
- * text field and the area in the parent where the
- * combo box used to be.
- */
- if (OS.IsWinCE) return result;
- if (!getDrawing ()) return result;
- if (!OS.IsWindowVisible (handle)) return result;
- if (ignoreResize) {
- WINDOWPOS lpwp = new WINDOWPOS ();
- OS.MoveMemory (lpwp, lParam, WINDOWPOS.sizeof);
- if ((lpwp.flags & OS.SWP_NOSIZE) == 0) {
- lpwp.flags |= OS.SWP_NOREDRAW;
- OS.MoveMemory (lParam, lpwp, WINDOWPOS.sizeof);
- OS.InvalidateRect (handle, null, true);
- RECT rect = new RECT ();
- OS.GetWindowRect (handle, rect);
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- if (width != 0 && height != 0) {
- int /*long*/ hwndParent = parent.handle;
- int /*long*/ hwndChild = OS.GetWindow (hwndParent, OS.GW_CHILD);
- OS.MapWindowPoints (0, hwndParent, rect, 2);
- int /*long*/ rgn1 = OS.CreateRectRgn (rect.left, rect.top, rect.right, rect.bottom);
- while (hwndChild != 0) {
- if (hwndChild != handle) {
- OS.GetWindowRect (hwndChild, rect);
- OS.MapWindowPoints (0, hwndParent, rect, 2);
- int /*long*/ rgn2 = OS.CreateRectRgn (rect.left, rect.top, rect.right, rect.bottom);
- OS.CombineRgn (rgn1, rgn1, rgn2, OS.RGN_DIFF);
- OS.DeleteObject (rgn2);
- }
- hwndChild = OS.GetWindow (hwndChild, OS.GW_HWNDNEXT);
- }
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE;
- OS.RedrawWindow (hwndParent, null, rgn1, flags);
- OS.DeleteObject (rgn1);
- }
- }
- }
- return result;
-}
-
-LRESULT wmChar (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- if (ignoreCharacter) return null;
- LRESULT result = super.wmChar (hwnd, wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. For some reason, when the
- * widget is a single line text widget, when the
- * user presses tab, return or escape, Windows beeps.
- * The fix is to look for these keys and not call
- * the window proc.
- *
- * NOTE: This only happens when the drop down list
- * is not visible.
- */
- switch ((int)/*64*/wParam) {
- case SWT.TAB: return LRESULT.ZERO;
- case SWT.CR:
- if (!ignoreDefaultSelection) postEvent (SWT.DefaultSelection);
- ignoreDefaultSelection = false;
- // FALL THROUGH
- case SWT.ESC:
- if ((style & SWT.DROP_DOWN) != 0) {
- if (OS.SendMessage (handle, OS.CB_GETDROPPEDSTATE, 0, 0) == 0) {
- return LRESULT.ZERO;
- }
- }
- }
- return result;
-}
-
-LRESULT wmClipboard (int /*long*/ hwndText, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if ((style & SWT.READ_ONLY) != 0) return null;
- if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return null;
- boolean call = false;
- int [] start = new int [1], end = new int [1];
- String newText = null;
- switch (msg) {
- case OS.WM_CLEAR:
- case OS.WM_CUT:
- OS.SendMessage (hwndText, OS.EM_GETSEL, start, end);
- if (start [0] != end [0]) {
- newText = "";
- call = true;
- }
- break;
- case OS.WM_PASTE:
- OS.SendMessage (hwndText, OS.EM_GETSEL, start, end);
- newText = getClipboardText ();
- break;
- case OS.EM_UNDO:
- case OS.WM_UNDO:
- if (OS.SendMessage (hwndText, OS.EM_CANUNDO, 0, 0) != 0) {
- ignoreModify = true;
- OS.CallWindowProc (EditProc, hwndText, msg, wParam, lParam);
- int length = OS.GetWindowTextLength (hwndText);
- int [] newStart = new int [1], newEnd = new int [1];
- OS.SendMessage (hwndText, OS.EM_GETSEL, newStart, newEnd);
- if (length != 0 && newStart [0] != newEnd [0]) {
- TCHAR buffer = new TCHAR (getCodePage (), length + 1);
- OS.GetWindowText (hwndText, buffer, length + 1);
- newText = buffer.toString (newStart [0], newEnd [0] - newStart [0]);
- } else {
- newText = "";
- }
- OS.CallWindowProc (EditProc, hwndText, msg, wParam, lParam);
- OS.SendMessage (hwndText, OS.EM_GETSEL, start, end);
- ignoreModify = false;
- }
- break;
- case OS.WM_SETTEXT:
- end [0] = OS.GetWindowTextLength (hwndText);
- int length = OS.IsUnicode ? OS.wcslen (lParam) : OS.strlen (lParam);
- TCHAR buffer = new TCHAR (getCodePage (), length);
- int byteCount = buffer.length () * TCHAR.sizeof;
- OS.MoveMemory (buffer, lParam, byteCount);
- newText = buffer.toString (0, length);
- break;
- }
- if (newText != null) {
- String oldText = newText;
- newText = verifyText (newText, start [0], end [0], null);
- if (newText == null) return LRESULT.ZERO;
- if (!newText.equals (oldText)) {
- if (call) {
- OS.CallWindowProc (EditProc, hwndText, msg, wParam, lParam);
- }
- TCHAR buffer = new TCHAR (getCodePage (), newText, true);
- if (msg == OS.WM_SETTEXT) {
- int /*long*/ hHeap = OS.GetProcessHeap ();
- int byteCount = buffer.length () * TCHAR.sizeof;
- int /*long*/ pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (pszText, buffer, byteCount);
- int /*long*/ code = OS.CallWindowProc (EditProc, hwndText, msg, wParam, pszText);
- OS.HeapFree (hHeap, 0, pszText);
- return new LRESULT (code);
- } else {
- OS.SendMessage (hwndText, OS.EM_REPLACESEL, 0, buffer);
- return LRESULT.ZERO;
- }
- }
- }
- return null;
-}
-
-LRESULT wmCommandChild (int /*long*/ wParam, int /*long*/ lParam) {
- int code = OS.HIWORD (wParam);
- switch (code) {
- case OS.CBN_EDITCHANGE:
- if (ignoreModify) break;
- /*
- * Feature in Windows. If the combo box list selection is
- * queried using CB_GETCURSEL before the WM_COMMAND (with
- * CBN_EDITCHANGE) returns, CB_GETCURSEL returns the previous
- * selection in the list. It seems that the combo box sends
- * the WM_COMMAND before it makes the selection in the list box
- * match the entry field. The fix is remember that no selection
- * in the list should exist in this case.
- */
- noSelection = true;
- sendEvent (SWT.Modify);
- if (isDisposed ()) return LRESULT.ZERO;
- noSelection = false;
- break;
- case OS.CBN_SELCHANGE:
- /*
- * Feature in Windows. If the text in an editable combo box
- * is queried using GetWindowText () before the WM_COMMAND
- * (with CBN_SELCHANGE) returns, GetWindowText () returns is
- * the previous text in the combo box. It seems that the combo
- * box sends the WM_COMMAND before it updates the text field to
- * match the list selection. The fix is to force the text field
- * to match the list selection by re-selecting the list item.
- */
- int index = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCURSEL, 0, 0);
- if (index != OS.CB_ERR) {
- OS.SendMessage (handle, OS.CB_SETCURSEL, index, 0);
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the modify
- * event. If this happens, end the processing of the
- * Windows message by returning zero as the result of
- * the window proc.
- */
- sendEvent (SWT.Modify);
- if (isDisposed ()) return LRESULT.ZERO;
- postEvent (SWT.Selection);
- break;
- case OS.CBN_SETFOCUS:
- sendFocusEvent (SWT.FocusIn);
- if (isDisposed ()) return LRESULT.ZERO;
- break;
- case OS.CBN_KILLFOCUS:
- /*
- * Bug in Windows. When a combo box that is read only
- * is disposed in CBN_KILLFOCUS, Windows segment faults.
- * The fix is to send focus from WM_KILLFOCUS instead
- * of CBN_KILLFOCUS.
- *
- * NOTE: In version 6 of COMCTL32.DLL, the bug is fixed.
- */
- if ((style & SWT.READ_ONLY) != 0) break;
- sendFocusEvent (SWT.FocusOut);
- if (isDisposed ()) return LRESULT.ZERO;
- break;
- }
- return super.wmCommandChild (wParam, lParam);
-}
-
-LRESULT wmIMEChar (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
-
- /* Process a DBCS character */
- Display display = this.display;
- display.lastKey = 0;
- display.lastAscii = (int)/*64*/wParam;
- display.lastVirtual = display.lastNull = display.lastDead = false;
- if (!sendKeyEvent (SWT.KeyDown, OS.WM_IME_CHAR, wParam, lParam)) {
- return LRESULT.ZERO;
- }
-
- /*
- * Feature in Windows. The Windows text widget uses
- * two 2 WM_CHAR's to process a DBCS key instead of
- * using WM_IME_CHAR. The fix is to allow the text
- * widget to get the WM_CHAR's but ignore sending
- * them to the application.
- */
- ignoreCharacter = true;
- int /*long*/ result = callWindowProc (hwnd, OS.WM_IME_CHAR, wParam, lParam);
- MSG msg = new MSG ();
- int flags = OS.PM_REMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE;
- while (OS.PeekMessage (msg, hwnd, OS.WM_CHAR, OS.WM_CHAR, flags)) {
- OS.TranslateMessage (msg);
- OS.DispatchMessage (msg);
- }
- ignoreCharacter = false;
-
- sendKeyEvent (SWT.KeyUp, OS.WM_IME_CHAR, wParam, lParam);
- // widget could be disposed at this point
- display.lastKey = display.lastAscii = 0;
- return new LRESULT (result);
-}
-
-LRESULT wmKeyDown (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- if (ignoreCharacter) return null;
- LRESULT result = super.wmKeyDown (hwnd, wParam, lParam);
- if (result != null) return result;
- ignoreDefaultSelection = false;
- if (wParam == OS.VK_RETURN) {
- if ((style & SWT.DROP_DOWN) != 0) {
- if (OS.SendMessage (handle, OS.CB_GETDROPPEDSTATE, 0, 0) != 0) {
- ignoreDefaultSelection = true;
- }
- }
- }
- return result;
-}
-
-LRESULT wmSysKeyDown (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. When an editable combo box is dropped
- * down using Alt+Down and the text in the entry field partially
- * matches an item in the list, Windows selects the item but doesn't
- * send WM_COMMAND with CBN_SELCHANGE. The fix is to detect that
- * the selection has changed and issue the notification.
- */
- int oldSelection = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCURSEL, 0, 0);
- LRESULT result = super.wmSysKeyDown (hwnd, wParam, lParam);
- if (result != null) return result;
- if ((style & SWT.READ_ONLY) == 0) {
- if (wParam == OS.VK_DOWN) {
- int /*long*/ code = callWindowProc (hwnd, OS.WM_SYSKEYDOWN, wParam, lParam);
- int newSelection = (int)/*64*/OS.SendMessage (handle, OS.CB_GETCURSEL, 0, 0);
- if (oldSelection != newSelection) {
- sendEvent (SWT.Modify);
- if (isDisposed ()) return LRESULT.ZERO;
- sendEvent (SWT.Selection);
- if (isDisposed ()) return LRESULT.ZERO;
- }
- return new LRESULT (code);
- }
- }
- return result;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java
deleted file mode 100755
index aefc81663e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java
+++ /dev/null
@@ -1,1760 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are controls which are capable
- * of containing other controls.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>NO_BACKGROUND, NO_FOCUS, NO_MERGE_PAINTS, NO_REDRAW_RESIZE, NO_RADIO_GROUP, EMBEDDED, DOUBLE_BUFFERED</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: The <code>NO_BACKGROUND</code>, <code>NO_FOCUS</code>, <code>NO_MERGE_PAINTS</code>,
- * and <code>NO_REDRAW_RESIZE</code> styles are intended for use with <code>Canvas</code>.
- * They can be used with <code>Composite</code> if you are drawing your own, but their
- * behavior is undefined if they are used with subclasses of <code>Composite</code> other
- * than <code>Canvas</code>.
- * </p><p>
- * Note: The <code>CENTER</code> style, although undefined for composites, has the
- * same value as <code>EMBEDDED</code> which is used to embed widgets from other
- * widget toolkits into SWT. On some operating systems (GTK, Motif), this may cause
- * the children of this composite to be obscured.
- * </p><p>
- * This class may be subclassed by custom control implementors
- * who are building controls that are constructed from aggregates
- * of other controls.
- * </p>
- *
- * @see Canvas
- * @see <a href="http://www.eclipse.org/swt/snippets/#composite">Composite snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public class Composite extends Scrollable {
- Layout layout;
- WINDOWPOS [] lpwp;
- Control [] tabList;
- int layoutCount, backgroundMode;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Composite () {
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- *
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_FOCUS
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_RADIO_GROUP
- * @see SWT#EMBEDDED
- * @see SWT#DOUBLE_BUFFERED
- * @see Widget#getStyle
- */
-public Composite (Composite parent, int style) {
- super (parent, style);
-}
-
-Control [] _getChildren () {
- int count = 0;
- int /*long*/ hwndChild = OS.GetWindow (handle, OS.GW_CHILD);
- if (hwndChild == 0) return new Control [0];
- while (hwndChild != 0) {
- count++;
- hwndChild = OS.GetWindow (hwndChild, OS.GW_HWNDNEXT);
- }
- Control [] children = new Control [count];
- int index = 0;
- hwndChild = OS.GetWindow (handle, OS.GW_CHILD);
- while (hwndChild != 0) {
- Control control = display.getControl (hwndChild);
- if (control != null && control != this) {
- children [index++] = control;
- }
- hwndChild = OS.GetWindow (hwndChild, OS.GW_HWNDNEXT);
- }
- if (count == index) return children;
- Control [] newChildren = new Control [index];
- System.arraycopy (children, 0, newChildren, 0, index);
- return newChildren;
-}
-
-Control [] _getTabList () {
- if (tabList == null) return tabList;
- int count = 0;
- for (int i=0; i<tabList.length; i++) {
- if (!tabList [i].isDisposed ()) count++;
- }
- if (count == tabList.length) return tabList;
- Control [] newList = new Control [count];
- int index = 0;
- for (int i=0; i<tabList.length; i++) {
- if (!tabList [i].isDisposed ()) {
- newList [index++] = tabList [i];
- }
- }
- tabList = newList;
- return tabList;
-}
-
-/**
- * Clears any data that has been cached by a Layout for all widgets that
- * are in the parent hierarchy of the changed control up to and including the
- * receiver. If an ancestor does not have a layout, it is skipped.
- *
- * @param changed an array of controls that changed state and require a recalculation of size
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li>
- * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void changed (Control[] changed) {
- checkWidget ();
- if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<changed.length; i++) {
- Control control = changed [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean ancestor = false;
- Composite composite = control.parent;
- while (composite != null) {
- ancestor = composite == this;
- if (ancestor) break;
- composite = composite.parent;
- }
- if (!ancestor) error (SWT.ERROR_INVALID_PARENT);
- }
- for (int i=0; i<changed.length; i++) {
- Control child = changed [i];
- Composite composite = child.parent;
- while (child != this) {
- if (composite.layout == null || !composite.layout.flushCache (child)) {
- composite.state |= LAYOUT_CHANGED;
- }
- child = composite;
- composite = child.parent;
- }
- }
-}
-
-void checkBuffered () {
- if (OS.IsWinCE || (state & CANVAS) == 0) {
- super.checkBuffered ();
- }
-}
-
-void checkComposited () {
- if ((state & CANVAS) != 0) {
- if ((style & SWT.TRANSPARENT) != 0) {
- int /*long*/ hwndParent = parent.handle;
- int bits = OS.GetWindowLong (hwndParent, OS.GWL_EXSTYLE);
- bits |= OS.WS_EX_COMPOSITED;
- OS.SetWindowLong (hwndParent, OS.GWL_EXSTYLE, bits);
- }
- }
-}
-
-protected void checkSubclass () {
- /* Do nothing - Subclassing is allowed */
-}
-
-Widget [] computeTabList () {
- Widget result [] = super.computeTabList ();
- if (result.length == 0) return result;
- Control [] list = tabList != null ? _getTabList () : _getChildren ();
- for (int i=0; i<list.length; i++) {
- Control child = list [i];
- Widget [] childList = child.computeTabList ();
- if (childList.length != 0) {
- Widget [] newResult = new Widget [result.length + childList.length];
- System.arraycopy (result, 0, newResult, 0, result.length);
- System.arraycopy (childList, 0, newResult, result.length, childList.length);
- result = newResult;
- }
- }
- return result;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- Point size;
- if (layout != null) {
- if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
- changed |= (state & LAYOUT_CHANGED) != 0;
- state &= ~LAYOUT_CHANGED;
- size = layout.computeSize (this, wHint, hHint, changed);
- } else {
- size = new Point (wHint, hHint);
- }
- } else {
- size = minimumSize (wHint, hHint, changed);
- }
- if (size.x == 0) size.x = DEFAULT_WIDTH;
- if (size.y == 0) size.y = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) size.x = wHint;
- if (hHint != SWT.DEFAULT) size.y = hHint;
- Rectangle trim = computeTrim (0, 0, size.x, size.y);
- return new Point (trim.width, trim.height);
-}
-
-/**
- * Copies a rectangular area of the receiver at the specified
- * position using the gc.
- *
- * @param gc the gc where the rectangle is to be filled
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-/*public*/ void copyArea (GC gc, int x, int y, int width, int height) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
-
- //XP only, no GDI+
- //#define PW_CLIENTONLY 0x00000001
- //DCOrg() wrong
- //topHandle wrong for Tree?
- int /*long*/ hDC = gc.handle;
- int nSavedDC = OS.SaveDC (hDC);
- OS.IntersectClipRect (hDC, 0, 0, width, height);
-
- //WRONG PARENT
- POINT lpPoint = new POINT ();
- int /*long*/ hwndParent = OS.GetParent (handle);
- OS.MapWindowPoints (handle, hwndParent, lpPoint, 1);
- RECT rect = new RECT ();
- OS.GetWindowRect (handle, rect);
- POINT lpPoint1 = new POINT (), lpPoint2 = new POINT ();
- x = x + (lpPoint.x - rect.left);
- y = y + (lpPoint.y - rect.top);
- OS.SetWindowOrgEx (hDC, x, y, lpPoint1);
- OS.SetBrushOrgEx (hDC, x, y, lpPoint2);
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.WS_VISIBLE) == 0) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- }
- //NECESSARY?
- OS.RedrawWindow (handle, null, 0, OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN);
- OS.PrintWindow (handle, hDC, 0);//0x00000001);
- if ((bits & OS.WS_VISIBLE) == 0) {
- OS.DefWindowProc(handle, OS.WM_SETREDRAW, 0, 0);
- }
- OS.RestoreDC (hDC, nSavedDC);
-}
-
-void createHandle () {
- super.createHandle ();
- state |= CANVAS;
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
- state |= THEME_BACKGROUND;
- }
- if ((style & SWT.TRANSPARENT) != 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
- bits |= OS.WS_EX_TRANSPARENT;
- OS.SetWindowLong (handle, OS.GWL_EXSTYLE, bits);
- }
-}
-
-Composite findDeferredControl () {
- return layoutCount > 0 ? this : parent.findDeferredControl ();
-}
-
-Menu [] findMenus (Control control) {
- if (control == this) return new Menu [0];
- Menu result [] = super.findMenus (control);
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- Menu [] menuList = child.findMenus (control);
- if (menuList.length != 0) {
- Menu [] newResult = new Menu [result.length + menuList.length];
- System.arraycopy (result, 0, newResult, 0, result.length);
- System.arraycopy (menuList, 0, newResult, result.length, menuList.length);
- result = newResult;
- }
- }
- return result;
-}
-
-void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) {
- super.fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
- }
-}
-
-void fixTabList (Control control) {
- if (tabList == null) return;
- int count = 0;
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == control) count++;
- }
- if (count == 0) return;
- Control [] newList = null;
- int length = tabList.length - count;
- if (length != 0) {
- newList = new Control [length];
- int index = 0;
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] != control) {
- newList [index++] = tabList [i];
- }
- }
- }
- tabList = newList;
-}
-
-/**
- * Returns the receiver's background drawing mode. This
- * will be one of the following constants defined in class
- * <code>SWT</code>:
- * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>,
- * <code>INHERTIT_FORCE</code>.
- *
- * @return the background mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- *
- * @since 3.2
- */
-public int getBackgroundMode () {
- checkWidget ();
- return backgroundMode;
-}
-
-/**
- * Returns a (possibly empty) array containing the receiver's children.
- * Children are returned in the order that they are drawn. The topmost
- * control appears at the beginning of the array. Subsequent controls
- * draw beneath this control and appear later in the array.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of children, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return an array of children
- *
- * @see Control#moveAbove
- * @see Control#moveBelow
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control [] getChildren () {
- checkWidget ();
- return _getChildren ();
-}
-
-int getChildrenCount () {
- /*
- * NOTE: The current implementation will count
- * non-registered children.
- */
- int count = 0;
- int /*long*/ hwndChild = OS.GetWindow (handle, OS.GW_CHILD);
- while (hwndChild != 0) {
- count++;
- hwndChild = OS.GetWindow (hwndChild, OS.GW_HWNDNEXT);
- }
- return count;
-}
-
-/**
- * Returns layout which is associated with the receiver, or
- * null if one has not been set.
- *
- * @return the receiver's layout or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Layout getLayout () {
- checkWidget ();
- return layout;
-}
-
-/**
- * Gets the (possibly empty) tabbing order for the control.
- *
- * @return tabList the ordered list of controls representing the tab order
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setTabList
- */
-public Control [] getTabList () {
- checkWidget ();
- Control [] tabList = _getTabList ();
- if (tabList == null) {
- int count = 0;
- Control [] list =_getChildren ();
- for (int i=0; i<list.length; i++) {
- if (list [i].isTabGroup ()) count++;
- }
- tabList = new Control [count];
- int index = 0;
- for (int i=0; i<list.length; i++) {
- if (list [i].isTabGroup ()) {
- tabList [index++] = list [i];
- }
- }
- }
- return tabList;
-}
-
-boolean hooksKeys () {
- return hooks (SWT.KeyDown) || hooks (SWT.KeyUp);
-}
-
-/**
- * Returns <code>true</code> if the receiver has deferred
- * the performing of layout, and <code>false</code> otherwise.
- *
- * @return the receiver's deferred layout state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setLayoutDeferred(boolean)
- * @see #isLayoutDeferred()
- *
- * @since 3.1
- */
-public boolean getLayoutDeferred () {
- checkWidget ();
- return layoutCount > 0 ;
-}
-
-/**
- * Returns <code>true</code> if the receiver or any ancestor
- * up to and including the receiver's nearest ancestor shell
- * has deferred the performing of layouts. Otherwise, <code>false</code>
- * is returned.
- *
- * @return the receiver's deferred layout state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setLayoutDeferred(boolean)
- * @see #getLayoutDeferred()
- *
- * @since 3.1
- */
-public boolean isLayoutDeferred () {
- checkWidget ();
- return findDeferredControl () != null;
-}
-
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the receiver does not have a layout, do nothing.
- * <p>
- * This is equivalent to calling <code>layout(true)</code>.
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void layout () {
- checkWidget ();
- layout (true);
-}
-
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the argument is <code>true</code> the layout must not rely
- * on any information it has cached about the immediate children. If it
- * is <code>false</code> the layout may (potentially) optimize the
- * work it is doing by assuming that none of the receiver's
- * children has changed state since the last layout.
- * If the receiver does not have a layout, do nothing.
- * <p>
- * If a child is resized as a result of a call to layout, the
- * resize event will invoke the layout of the child. The layout
- * will cascade down through all child widgets in the receiver's widget
- * tree until a child is encountered that does not resize. Note that
- * a layout due to a resize will not flush any cached information
- * (same as <code>layout(false)</code>).
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void layout (boolean changed) {
- checkWidget ();
- if (layout == null) return;
- layout (changed, false);
-}
-
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the changed argument is <code>true</code> the layout must not rely
- * on any information it has cached about its children. If it
- * is <code>false</code> the layout may (potentially) optimize the
- * work it is doing by assuming that none of the receiver's
- * children has changed state since the last layout.
- * If the all argument is <code>true</code> the layout will cascade down
- * through all child widgets in the receiver's widget tree, regardless of
- * whether the child has changed size. The changed argument is applied to
- * all layouts. If the all argument is <code>false</code>, the layout will
- * <em>not</em> cascade down through all child widgets in the receiver's widget
- * tree. However, if a child is resized as a result of a call to layout, the
- * resize event will invoke the layout of the child. Note that
- * a layout due to a resize will not flush any cached information
- * (same as <code>layout(false)</code>).
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise
- * @param all <code>true</code> if all children in the receiver's widget tree should be laid out, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void layout (boolean changed, boolean all) {
- checkWidget ();
- if (layout == null && !all) return;
- markLayout (changed, all);
- updateLayout (true, all);
-}
-
-/**
- * Forces a lay out (that is, sets the size and location) of all widgets that
- * are in the parent hierarchy of the changed control up to and including the
- * receiver. The layouts in the hierarchy must not rely on any information
- * cached about the changed control or any of its ancestors. The layout may
- * (potentially) optimize the work it is doing by assuming that none of the
- * peers of the changed control have changed state since the last layout.
- * If an ancestor does not have a layout, skip it.
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed a control that has had a state change which requires a recalculation of its size
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li>
- * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void layout (Control [] changed) {
- checkWidget ();
- if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<changed.length; i++) {
- Control control = changed [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean ancestor = false;
- Composite composite = control.parent;
- while (composite != null) {
- ancestor = composite == this;
- if (ancestor) break;
- composite = composite.parent;
- }
- if (!ancestor) error (SWT.ERROR_INVALID_PARENT);
- }
- int updateCount = 0;
- Composite [] update = new Composite [16];
- for (int i=0; i<changed.length; i++) {
- Control child = changed [i];
- Composite composite = child.parent;
- while (child != this) {
- if (composite.layout != null) {
- composite.state |= LAYOUT_NEEDED;
- if (!composite.layout.flushCache (child)) {
- composite.state |= LAYOUT_CHANGED;
- }
- }
- if (updateCount == update.length) {
- Composite [] newUpdate = new Composite [update.length + 16];
- System.arraycopy (update, 0, newUpdate, 0, update.length);
- update = newUpdate;
- }
- child = update [updateCount++] = composite;
- composite = child.parent;
- }
- }
- for (int i=updateCount-1; i>=0; i--) {
- update [i].updateLayout (true, false);
- }
-}
-
-void markLayout (boolean changed, boolean all) {
- if (layout != null) {
- state |= LAYOUT_NEEDED;
- if (changed) state |= LAYOUT_CHANGED;
- }
- if (all) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].markLayout (changed, all);
- }
- }
-}
-
-Point minimumSize (int wHint, int hHint, boolean changed) {
- Control [] children = _getChildren ();
- int width = 0, height = 0;
- for (int i=0; i<children.length; i++) {
- Rectangle rect = children [i].getBounds ();
- width = Math.max (width, rect.x + rect.width);
- height = Math.max (height, rect.y + rect.height);
- }
- return new Point (width, height);
-}
-
-boolean redrawChildren () {
- if (!super.redrawChildren ()) return false;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].redrawChildren ();
- }
- return true;
-}
-
-void releaseParent () {
- super.releaseParent ();
- if ((state & CANVAS) != 0) {
- if ((style & SWT.TRANSPARENT) != 0) {
- int /*long*/ hwndParent = parent.handle;
- int /*long*/ hwndChild = OS.GetWindow (hwndParent, OS.GW_CHILD);
- while (hwndChild != 0) {
- if (hwndChild != handle) {
- int bits = OS.GetWindowLong (hwndParent, OS.GWL_EXSTYLE);
- if ((bits & OS.WS_EX_TRANSPARENT) != 0) return;
- }
- hwndChild = OS.GetWindow (hwndChild, OS.GW_HWNDNEXT);
- }
- int bits = OS.GetWindowLong (hwndParent, OS.GWL_EXSTYLE);
- bits &= ~OS.WS_EX_COMPOSITED;
- OS.SetWindowLong (hwndParent, OS.GWL_EXSTYLE, bits);
- }
- }
-}
-
-void releaseChildren (boolean destroy) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child != null && !child.isDisposed ()) {
- child.release (false);
- }
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) {
- int /*long*/ hwndChild = OS.GetWindow (handle, OS.GW_CHILD);
- if (hwndChild != 0) {
- int threadId = OS.GetWindowThreadProcessId (hwndChild, null);
- if (threadId != OS.GetCurrentThreadId ()) {
- OS.ShowWindow (hwndChild, OS.SW_HIDE);
- OS.SetParent (hwndChild, 0);
- }
- }
- }
- layout = null;
- tabList = null;
- lpwp = null;
-}
-
-void removeControl (Control control) {
- fixTabList (control);
- resizeChildren ();
-}
-
-void resizeChildren () {
- if (lpwp == null) return;
- do {
- WINDOWPOS [] currentLpwp = lpwp;
- lpwp = null;
- if (!resizeChildren (true, currentLpwp)) {
- resizeChildren (false, currentLpwp);
- }
- } while (lpwp != null);
-}
-
-boolean resizeChildren (boolean defer, WINDOWPOS [] pwp) {
- if (pwp == null) return true;
- int /*long*/ hdwp = 0;
- if (defer) {
- hdwp = OS.BeginDeferWindowPos (pwp.length);
- if (hdwp == 0) return false;
- }
- for (int i=0; i<pwp.length; i++) {
- WINDOWPOS wp = pwp [i];
- if (wp != null) {
- /*
- * This code is intentionally commented. All widgets that
- * are created by SWT have WS_CLIPSIBLINGS to ensure that
- * application code does not draw outside of the control.
- */
-// int count = parent.getChildrenCount ();
-// if (count > 1) {
-// int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
-// if ((bits & OS.WS_CLIPSIBLINGS) == 0) wp.flags |= OS.SWP_NOCOPYBITS;
-// }
- if (defer) {
- hdwp = DeferWindowPos (hdwp, wp.hwnd, 0, wp.x, wp.y, wp.cx, wp.cy, wp.flags);
- if (hdwp == 0) return false;
- } else {
- SetWindowPos (wp.hwnd, 0, wp.x, wp.y, wp.cx, wp.cy, wp.flags);
- }
- }
- }
- if (defer) return OS.EndDeferWindowPos (hdwp);
- return true;
-}
-
-void resizeEmbeddedHandle(int /*long*/ embeddedHandle, int width, int height) {
- if (embeddedHandle == 0) return;
- int [] processID = new int [1];
- int threadId = OS.GetWindowThreadProcessId (embeddedHandle, processID);
- if (threadId != OS.GetCurrentThreadId ()) {
- if (processID [0] == OS.GetCurrentProcessId ()) {
- if (display.msgHook == 0) {
- if (!OS.IsWinCE) {
- display.getMsgCallback = new Callback (display, "getMsgProc", 3);
- display.getMsgProc = display.getMsgCallback.getAddress ();
- if (display.getMsgProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- display.msgHook = OS.SetWindowsHookEx (OS.WH_GETMESSAGE, display.getMsgProc, OS.GetLibraryHandle(), threadId);
- OS.PostThreadMessage (threadId, OS.WM_NULL, 0, 0);
- }
- }
- }
- int flags = OS.SWP_NOZORDER | OS.SWP_DRAWFRAME | OS.SWP_NOACTIVATE | OS.SWP_ASYNCWINDOWPOS;
- OS.SetWindowPos (embeddedHandle, 0, 0, 0, width, height, flags);
- }
-}
-
-void sendResize () {
- setResizeChildren (false);
- super.sendResize ();
- if (isDisposed ()) return;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false, false);
- }
- setResizeChildren (true);
-}
-
-/**
- * Sets the background drawing mode to the argument which should
- * be one of the following constants defined in class <code>SWT</code>:
- * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>,
- * <code>INHERIT_FORCE</code>.
- *
- * @param mode the new background mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- *
- * @since 3.2
- */
-public void setBackgroundMode (int mode) {
- checkWidget ();
- backgroundMode = mode;
- Control [] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- children [i].updateBackgroundMode ();
- }
-}
-
-void setBounds (int x, int y, int width, int height, int flags, boolean defer) {
- if (display.resizeCount > Display.RESIZE_LIMIT) {
- defer = false;
- }
- if (!defer && (state & CANVAS) != 0) {
- state &= ~(RESIZE_OCCURRED | MOVE_OCCURRED);
- state |= RESIZE_DEFERRED | MOVE_DEFERRED;
- }
- super.setBounds (x, y, width, height, flags, defer);
- if (!defer && (state & CANVAS) != 0) {
- boolean wasMoved = (state & MOVE_OCCURRED) != 0;
- boolean wasResized = (state & RESIZE_OCCURRED) != 0;
- state &= ~(RESIZE_DEFERRED | MOVE_DEFERRED);
- if (wasMoved && !isDisposed ()) sendMove ();
- if (wasResized && !isDisposed ()) sendResize ();
- }
-}
-
-boolean setFixedFocus () {
- checkWidget ();
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.setRadioFocus (false)) return true;
- }
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.setFixedFocus ()) return true;
- }
- return super.setFixedFocus ();
-}
-
-public boolean setFocus () {
- checkWidget ();
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.setRadioFocus (false)) return true;
- }
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.setFocus ()) return true;
- }
- return super.setFocus ();
-}
-
-/**
- * Sets the layout which is associated with the receiver to be
- * the argument which may be null.
- *
- * @param layout the receiver's new layout or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLayout (Layout layout) {
- checkWidget ();
- this.layout = layout;
-}
-
-/**
- * If the argument is <code>true</code>, causes subsequent layout
- * operations in the receiver or any of its children to be ignored.
- * No layout of any kind can occur in the receiver or any of its
- * children until the flag is set to false.
- * Layout operations that occurred while the flag was
- * <code>true</code> are remembered and when the flag is set to
- * <code>false</code>, the layout operations are performed in an
- * optimized manner. Nested calls to this method are stacked.
- *
- * @param defer the new defer state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #layout(boolean)
- * @see #layout(Control[])
- *
- * @since 3.1
- */
-public void setLayoutDeferred (boolean defer) {
- if (!defer) {
- if (--layoutCount == 0) {
- if ((state & LAYOUT_CHILD) != 0 || (state & LAYOUT_NEEDED) != 0) {
- updateLayout (true, true);
- }
- }
- } else {
- layoutCount++;
- }
-}
-/**
- * Sets the tabbing order for the specified controls to
- * match the order that they occur in the argument list.
- *
- * @param tabList the ordered list of controls representing the tab order or null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if a widget in the tabList is null or has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if widget in the tabList is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTabList (Control [] tabList) {
- checkWidget ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- Control control = tabList [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
- Control [] newList = new Control [tabList.length];
- System.arraycopy (tabList, 0, newList, 0, tabList.length);
- tabList = newList;
- }
- this.tabList = tabList;
-}
-
-void setResizeChildren (boolean resize) {
- if (resize) {
- resizeChildren ();
- } else {
- if (display.resizeCount > Display.RESIZE_LIMIT) {
- return;
- }
- int count = getChildrenCount ();
- if (count > 1 && lpwp == null) {
- lpwp = new WINDOWPOS [count];
- }
- }
-}
-
-boolean setTabGroupFocus () {
- if (isTabItem ()) return setTabItemFocus ();
- boolean takeFocus = (style & SWT.NO_FOCUS) == 0;
- if ((state & CANVAS) != 0) {
- takeFocus = hooksKeys ();
- if ((style & SWT.EMBEDDED) != 0) takeFocus = true;
- }
- if (takeFocus && setTabItemFocus ()) return true;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.isTabItem () && child.setRadioFocus (true)) return true;
- }
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.isTabItem () && !child.isTabGroup () && child.setTabItemFocus ()) {
- return true;
- }
- }
- return false;
-}
-
-String toolTipText (NMTTDISPINFO hdr) {
- Shell shell = getShell ();
- if ((hdr.uFlags & OS.TTF_IDISHWND) == 0) {
- String string = null;
- ToolTip toolTip = shell.findToolTip ((int)/*64*/hdr.idFrom);
- if (toolTip != null) {
- string = toolTip.message;
- if (string == null || string.length () == 0) string = " ";
- }
- return string;
- }
- shell.setToolTipTitle (hdr.hwndFrom, null, 0);
- OS.SendMessage (hdr.hwndFrom, OS.TTM_SETMAXTIPWIDTH, 0, 0x7FFF);
- Control control = display.getControl (hdr.idFrom);
- return control != null ? control.toolTipText : null;
-}
-
-boolean translateMnemonic (Event event, Control control) {
- if (super.translateMnemonic (event, control)) return true;
- if (control != null) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.translateMnemonic (event, control)) return true;
- }
- }
- return false;
-}
-
-boolean translateTraversal (MSG msg) {
- if ((state & CANVAS) != 0 ) {
- if ((style & SWT.EMBEDDED) != 0) return false;
- switch ((int)/*64*/msg.wParam) {
- case OS.VK_UP:
- case OS.VK_LEFT:
- case OS.VK_DOWN:
- case OS.VK_RIGHT:
- case OS.VK_PRIOR:
- case OS.VK_NEXT:
- int uiState = (int)/*64*/OS.SendMessage (msg.hwnd, OS.WM_QUERYUISTATE, 0, 0);
- if ((uiState & OS.UISF_HIDEFOCUS) != 0) {
- OS.SendMessage (msg.hwnd, OS.WM_UPDATEUISTATE, OS.MAKEWPARAM (OS.UIS_CLEAR, OS.UISF_HIDEFOCUS), 0);
- }
- break;
- }
- }
- return super.translateTraversal (msg);
-}
-
-void updateBackgroundColor () {
- super.updateBackgroundColor ();
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- if ((children [i].state & PARENT_BACKGROUND) != 0) {
- children [i].updateBackgroundColor ();
- }
- }
-}
-
-void updateBackgroundImage () {
- super.updateBackgroundImage ();
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- if ((children [i].state & PARENT_BACKGROUND) != 0) {
- children [i].updateBackgroundImage ();
- }
- }
-}
-
-void updateBackgroundMode () {
- super.updateBackgroundMode ();
- Control [] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- children [i].updateBackgroundMode ();
- }
-}
-
-void updateFont (Font oldFont, Font newFont) {
- super.updateFont (oldFont, newFont);
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control control = children [i];
- if (!control.isDisposed ()) {
- control.updateFont (oldFont, newFont);
- }
- }
-}
-
-void updateLayout (boolean resize, boolean all) {
- Composite parent = findDeferredControl ();
- if (parent != null) {
- parent.state |= LAYOUT_CHILD;
- return;
- }
- if ((state & LAYOUT_NEEDED) != 0) {
- boolean changed = (state & LAYOUT_CHANGED) != 0;
- state &= ~(LAYOUT_NEEDED | LAYOUT_CHANGED);
- if (resize) setResizeChildren (false);
- layout.layout (this, changed);
- if (resize) setResizeChildren (true);
- }
- if (all) {
- state &= ~LAYOUT_CHILD;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].updateLayout (resize, all);
- }
- }
-}
-
-void updateUIState () {
- int /*long*/ hwndShell = getShell ().handle;
- int uiState = /*64*/(int)OS.SendMessage (hwndShell, OS.WM_QUERYUISTATE, 0, 0);
- if ((uiState & OS.UISF_HIDEFOCUS) != 0) {
- OS.SendMessage (hwndShell, OS.WM_CHANGEUISTATE, OS.MAKEWPARAM (OS.UIS_CLEAR, OS.UISF_HIDEFOCUS), 0);
- }
-}
-
-int widgetStyle () {
- /* Force clipping of children by setting WS_CLIPCHILDREN */
- return super.widgetStyle () | OS.WS_CLIPCHILDREN;
-}
-
-LRESULT WM_ERASEBKGND (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
- if (result != null) return result;
- if ((state & CANVAS) != 0) {
- /* Return zero to indicate that the background was not erased */
- if ((style & (SWT.NO_BACKGROUND | SWT.TRANSPARENT)) != 0) {
- return LRESULT.ZERO;
- }
- }
- return result;
-}
-
-LRESULT WM_GETDLGCODE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_GETDLGCODE (wParam, lParam);
- if (result != null) return result;
- if ((state & CANVAS) != 0) {
- int flags = 0;
- if (hooksKeys ()) {
- flags |= OS.DLGC_WANTALLKEYS | OS.DLGC_WANTARROWS | OS.DLGC_WANTTAB;
- }
- if ((style & SWT.NO_FOCUS) != 0) flags |= OS.DLGC_STATIC;
- if (OS.GetWindow (handle, OS.GW_CHILD) != 0) flags |= OS.DLGC_STATIC;
- if (flags != 0) return new LRESULT (flags);
- }
- return result;
-}
-
-LRESULT WM_GETFONT (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_GETFONT (wParam, lParam);
- if (result != null) return result;
- int /*long*/ code = callWindowProc (handle, OS.WM_GETFONT, wParam, lParam);
- if (code != 0) return new LRESULT (code);
- return new LRESULT (font != null ? font.handle : defaultFont ());
-}
-
-LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_LBUTTONDOWN (wParam, lParam);
- if (result == LRESULT.ZERO) return result;
-
- /* Set focus for a canvas with no children */
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_FOCUS) == 0 && hooksKeys ()) {
- if (OS.GetWindow (handle, OS.GW_CHILD) == 0) setFocus ();
- }
- }
- return result;
-}
-
-LRESULT WM_NCHITTEST (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_NCHITTEST (wParam, lParam);
- if (result != null) return result;
- /*
- * Bug in Windows. For some reason, under circumstances
- * that are not understood, when one scrolled window is
- * embedded in another and the outer window scrolls the
- * inner horizontally by moving the location of the inner
- * one, the vertical scroll bars of the inner window no
- * longer function. Specifically, WM_NCHITTEST returns
- * HTCLIENT instead of HTVSCROLL. The fix is to detect
- * the case where the result of WM_NCHITTEST is HTCLIENT
- * and the point is not in the client area, and redraw
- * the trim, which somehow fixes the next WM_NCHITTEST.
- */
- if (!OS.IsWinCE && OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- if ((state & CANVAS)!= 0) {
- int /*long*/ code = callWindowProc (handle, OS.WM_NCHITTEST, wParam, lParam);
- if (code == OS.HTCLIENT) {
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- POINT pt = new POINT ();
- pt.x = OS.GET_X_LPARAM (lParam);
- pt.y = OS.GET_Y_LPARAM (lParam);
- OS.MapWindowPoints (0, handle, pt, 1);
- if (!OS.PtInRect (rect, pt)) {
- int flags = OS.RDW_FRAME | OS.RDW_INVALIDATE;
- OS.RedrawWindow (handle, null, 0, flags);
- }
- }
- return new LRESULT (code);
- }
- }
- return result;
-}
-
-LRESULT WM_PARENTNOTIFY (int /*long*/ wParam, int /*long*/ lParam) {
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) {
- if (OS.LOWORD (wParam) == OS.WM_CREATE) {
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- resizeEmbeddedHandle (lParam, rect.right - rect.left, rect.bottom - rect.top);
- }
- }
- return super.WM_PARENTNOTIFY (wParam, lParam);
-}
-
-LRESULT WM_PAINT (int /*long*/ wParam, int /*long*/ lParam) {
- if ((state & CANVAS) == 0 || (state & FOREIGN_HANDLE) != 0) {
- return super.WM_PAINT (wParam, lParam);
- }
-
- /* Set the clipping bits */
- int oldBits = 0, newBits = 0;
- if (!OS.IsWinCE) {
- oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- newBits = oldBits | OS.WS_CLIPSIBLINGS | OS.WS_CLIPCHILDREN;
- if (newBits != oldBits) OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
- }
-
- /* Paint the control and the background */
- PAINTSTRUCT ps = new PAINTSTRUCT ();
- if (hooks (SWT.Paint) || filters (SWT.Paint)) {
-
- /* Use the buffered paint when possible */
- boolean bufferedPaint = false;
- if ((style & SWT.DOUBLE_BUFFERED) != 0) {
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- if ((style & (SWT.NO_MERGE_PAINTS | SWT.RIGHT_TO_LEFT)) == 0) {
- if ((style & SWT.TRANSPARENT) == 0) bufferedPaint = true;
- }
- }
- }
- if (bufferedPaint) {
- int /*long*/ hDC = OS.BeginPaint (handle, ps);
- int width = ps.right - ps.left;
- int height = ps.bottom - ps.top;
- if (width != 0 && height != 0) {
- int /*long*/ [] phdc = new int /*long*/ [1];
- int flags = OS.BPBF_COMPATIBLEBITMAP;
- RECT prcTarget = new RECT ();
- OS.SetRect (prcTarget, ps.left, ps.top, ps.right, ps.bottom);
- int /*long*/ hBufferedPaint = OS.BeginBufferedPaint (hDC, prcTarget, flags, null, phdc);
- GCData data = new GCData ();
- data.device = display;
- data.foreground = getForegroundPixel ();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- data.background = control.getBackgroundPixel ();
- data.font = Font.win32_new(display, OS.SendMessage (handle, OS.WM_GETFONT, 0, 0));
- data.uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- if ((style & SWT.NO_BACKGROUND) != 0) {
- /* This code is intentionally commented because it may be slow to copy bits from the screen */
- //paintGC.copyArea (image, ps.left, ps.top);
- } else {
- RECT rect = new RECT ();
- OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
- drawBackground (phdc [0], rect);
- }
- GC gc = GC.win32_new (phdc [0], data);
- Event event = new Event ();
- event.gc = gc;
- event.x = ps.left;
- event.y = ps.top;
- event.width = width;
- event.height = height;
- sendEvent (SWT.Paint, event);
- if (data.focusDrawn && !isDisposed ()) updateUIState ();
- gc.dispose ();
- OS.EndBufferedPaint (hBufferedPaint, true);
- }
- OS.EndPaint (handle, ps);
- } else {
-
- /* Create the paint GC */
- GCData data = new GCData ();
- data.ps = ps;
- data.hwnd = handle;
- GC gc = GC.win32_new (this, data);
-
- /* Get the system region for the paint HDC */
- int /*long*/ sysRgn = 0;
- if ((style & (SWT.DOUBLE_BUFFERED | SWT.TRANSPARENT)) != 0 || (style & SWT.NO_MERGE_PAINTS) != 0) {
- sysRgn = OS.CreateRectRgn (0, 0, 0, 0);
- if (OS.GetRandomRgn (gc.handle, sysRgn, OS.SYSRGN) == 1) {
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- if ((OS.GetLayout (gc.handle) & OS.LAYOUT_RTL) != 0) {
- int nBytes = OS.GetRegionData (sysRgn, 0, null);
- int [] lpRgnData = new int [nBytes / 4];
- OS.GetRegionData (sysRgn, nBytes, lpRgnData);
- int /*long*/ newSysRgn = OS.ExtCreateRegion (new float [] {-1, 0, 0, 1, 0, 0}, nBytes, lpRgnData);
- OS.DeleteObject (sysRgn);
- sysRgn = newSysRgn;
- }
- }
- if (OS.IsWinNT) {
- POINT pt = new POINT();
- OS.MapWindowPoints (0, handle, pt, 1);
- OS.OffsetRgn (sysRgn, pt.x, pt.y);
- }
- }
- }
-
- /* Send the paint event */
- int width = ps.right - ps.left;
- int height = ps.bottom - ps.top;
- if (width != 0 && height != 0) {
- GC paintGC = null;
- Image image = null;
- if ((style & (SWT.DOUBLE_BUFFERED | SWT.TRANSPARENT)) != 0) {
- image = new Image (display, width, height);
- paintGC = gc;
- gc = new GC (image, paintGC.getStyle() & SWT.RIGHT_TO_LEFT);
- GCData gcData = gc.getGCData ();
- gcData.uiState = data.uiState;
- gc.setForeground (getForeground ());
- gc.setBackground (getBackground ());
- gc.setFont (getFont ());
- if ((style & SWT.TRANSPARENT) != 0) {
- OS.BitBlt (gc.handle, 0, 0, width, height, paintGC.handle, ps.left, ps.top, OS.SRCCOPY);
- }
- OS.OffsetRgn (sysRgn, -ps.left, -ps.top);
- OS.SelectClipRgn (gc.handle, sysRgn);
- OS.OffsetRgn (sysRgn, ps.left, ps.top);
- OS.SetMetaRgn (gc.handle);
- OS.SetWindowOrgEx (gc.handle, ps.left, ps.top, null);
- OS.SetBrushOrgEx (gc.handle, ps.left, ps.top, null);
- if ((style & (SWT.NO_BACKGROUND | SWT.TRANSPARENT)) != 0) {
- /* This code is intentionally commented because it may be slow to copy bits from the screen */
- //paintGC.copyArea (image, ps.left, ps.top);
- } else {
- RECT rect = new RECT ();
- OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
- drawBackground (gc.handle, rect);
- }
- }
- Event event = new Event ();
- event.gc = gc;
- RECT rect = null;
- if ((style & SWT.NO_MERGE_PAINTS) != 0 && OS.GetRgnBox (sysRgn, rect = new RECT ()) == OS.COMPLEXREGION) {
- int nBytes = OS.GetRegionData (sysRgn, 0, null);
- int [] lpRgnData = new int [nBytes / 4];
- OS.GetRegionData (sysRgn, nBytes, lpRgnData);
- int count = lpRgnData [2];
- for (int i=0; i<count; i++) {
- int offset = 8 + (i << 2);
- OS.SetRect (rect, lpRgnData [offset], lpRgnData [offset + 1], lpRgnData [offset + 2], lpRgnData [offset + 3]);
- if ((style & (SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND | SWT.TRANSPARENT)) == 0) {
- drawBackground (gc.handle, rect);
- }
- event.x = rect.left;
- event.y = rect.top;
- event.width = rect.right - rect.left;
- event.height = rect.bottom - rect.top;
- event.count = count - 1 - i;
- sendEvent (SWT.Paint, event);
- }
- } else {
- if ((style & (SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND | SWT.TRANSPARENT)) == 0) {
- if (rect == null) rect = new RECT ();
- OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
- drawBackground (gc.handle, rect);
- }
- event.x = ps.left;
- event.y = ps.top;
- event.width = width;
- event.height = height;
- sendEvent (SWT.Paint, event);
- }
- // widget could be disposed at this point
- event.gc = null;
- if ((style & (SWT.DOUBLE_BUFFERED | SWT.TRANSPARENT)) != 0) {
- if (!gc.isDisposed ()) {
- GCData gcData = gc.getGCData ();
- if (gcData.focusDrawn && !isDisposed ()) updateUIState ();
- }
- gc.dispose();
- if (!isDisposed ()) paintGC.drawImage (image, ps.left, ps.top);
- image.dispose ();
- gc = paintGC;
- }
- }
- if (sysRgn != 0) OS.DeleteObject (sysRgn);
- if (data.focusDrawn && !isDisposed ()) updateUIState ();
-
- /* Dispose the paint GC */
- gc.dispose ();
- }
- } else {
- int /*long*/ hDC = OS.BeginPaint (handle, ps);
- if ((style & (SWT.NO_BACKGROUND | SWT.TRANSPARENT)) == 0) {
- RECT rect = new RECT ();
- OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
- drawBackground (hDC, rect);
- }
- OS.EndPaint (handle, ps);
- }
-
- /* Restore the clipping bits */
- if (!OS.IsWinCE && !isDisposed ()) {
- if (newBits != oldBits) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the paint
- * event. If this happens, don't attempt to restore
- * the style.
- */
- if (!isDisposed ()) {
- OS.SetWindowLong (handle, OS.GWL_STYLE, oldBits);
- }
- }
- }
- return LRESULT.ZERO;
-}
-
-LRESULT WM_PRINTCLIENT (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_PRINTCLIENT (wParam, lParam);
- if (result != null) return result;
- if ((state & CANVAS) != 0) {
- forceResize ();
- int nSavedDC = OS.SaveDC (wParam);
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- if ((style & (SWT.NO_BACKGROUND | SWT.TRANSPARENT)) == 0) {
- drawBackground (wParam, rect);
- }
- if (hooks (SWT.Paint) || filters (SWT.Paint)) {
- GCData data = new GCData ();
- data.device = display;
- data.foreground = getForegroundPixel ();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- data.background = control.getBackgroundPixel ();
- data.font = Font.win32_new(display, OS.SendMessage (handle, OS.WM_GETFONT, 0, 0));
- data.uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- GC gc = GC.win32_new (wParam, data);
- Event event = new Event ();
- event.gc = gc;
- event.x = rect.left;
- event.y = rect.top;
- event.width = rect.right - rect.left;
- event.height = rect.bottom - rect.top;
- sendEvent (SWT.Paint, event);
- event.gc = null;
- gc.dispose ();
- }
- OS.RestoreDC (wParam, nSavedDC);
- }
- return result;
-}
-
-LRESULT WM_SETFONT (int /*long*/ wParam, int /*long*/ lParam) {
- if (lParam != 0) OS.InvalidateRect (handle, null, true);
- return super.WM_SETFONT (wParam, lParam);
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = null;
- if ((state & RESIZE_DEFERRED) != 0) {
- result = super.WM_SIZE (wParam, lParam);
- } else {
- /* Begin deferred window positioning */
- setResizeChildren (false);
-
- /* Resize and Layout */
- result = super.WM_SIZE (wParam, lParam);
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the resize
- * event. If this happens, end the processing of the
- * Windows message by returning the result of the
- * WM_SIZE message.
- */
- if (isDisposed ()) return result;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false, false);
- }
-
- /* End deferred window positioning */
- setResizeChildren (true);
- }
-
- /* Damage the widget to cause a repaint */
- if (OS.IsWindowVisible (handle)) {
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_REDRAW_RESIZE) == 0) {
- if (hooks (SWT.Paint)) {
- OS.InvalidateRect (handle, null, true);
- }
- }
- }
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- if (findThemeControl () != null) redrawChildren ();
- }
- }
-
- /* Resize the embedded window */
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) {
- resizeEmbeddedHandle (OS.GetWindow (handle, OS.GW_CHILD), OS.LOWORD (lParam), OS.HIWORD (lParam));
- }
- return result;
-}
-
-LRESULT WM_SYSCOLORCHANGE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SYSCOLORCHANGE (wParam, lParam);
- if (result != null) return result;
- int /*long*/ hwndChild = OS.GetWindow (handle, OS.GW_CHILD);
- while (hwndChild != 0) {
- OS.SendMessage (hwndChild, OS.WM_SYSCOLORCHANGE, 0, 0);
- hwndChild = OS.GetWindow (hwndChild, OS.GW_HWNDNEXT);
- }
- return result;
-}
-
-LRESULT WM_SYSCOMMAND (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SYSCOMMAND (wParam, lParam);
- if (result != null) return result;
-
- /*
- * Check to see if the command is a system command or
- * a user menu item that was added to the system menu.
- *
- * NOTE: This is undocumented.
- */
- if ((wParam & 0xF000) == 0) return result;
-
- /*
- * Bug in Windows. When a vertical or horizontal scroll bar is
- * hidden or shown while the opposite scroll bar is being scrolled
- * by the user (with WM_HSCROLL code SB_LINEDOWN), the scroll bar
- * does not redraw properly. The fix is to detect this case and
- * redraw the non-client area.
- */
- if (!OS.IsWinCE) {
- int cmd = (int)/*64*/wParam & 0xFFF0;
- switch (cmd) {
- case OS.SC_HSCROLL:
- case OS.SC_VSCROLL:
- boolean showHBar = horizontalBar != null && horizontalBar.getVisible ();
- boolean showVBar = verticalBar != null && verticalBar.getVisible ();
- int /*long*/ code = callWindowProc (handle, OS.WM_SYSCOMMAND, wParam, lParam);
- if ((showHBar != (horizontalBar != null && horizontalBar.getVisible ())) ||
- (showVBar != (verticalBar != null && verticalBar.getVisible ()))) {
- int flags = OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_UPDATENOW;
- OS.RedrawWindow (handle, null, 0, flags);
- }
- if (code == 0) return LRESULT.ZERO;
- return new LRESULT (code);
- }
- }
- /* Return the result */
- return result;
-}
-
-LRESULT WM_UPDATEUISTATE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_UPDATEUISTATE (wParam, lParam);
- if (result != null) return result;
- if ((state & CANVAS) != 0 && hooks (SWT.Paint)) {
- OS.InvalidateRect (handle, null, true);
- }
- return result;
-}
-
-LRESULT wmNCPaint (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.wmNCPaint (hwnd, wParam, lParam);
- if (result != null) return result;
- int /*long*/ borderHandle = borderHandle ();
- if ((state & CANVAS) != 0 || (hwnd == borderHandle && handle != borderHandle)) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- int bits1 = OS.GetWindowLong (hwnd, OS.GWL_EXSTYLE);
- if ((bits1 & OS.WS_EX_CLIENTEDGE) != 0) {
- int /*long*/ code = 0;
- int bits2 = OS.GetWindowLong (hwnd, OS.GWL_STYLE);
- if ((bits2 & (OS.WS_HSCROLL | OS.WS_VSCROLL)) != 0) {
- code = callWindowProc (hwnd, OS.WM_NCPAINT, wParam, lParam);
- }
- int /*long*/ hDC = OS.GetWindowDC (hwnd);
- RECT rect = new RECT ();
- OS.GetWindowRect (hwnd, rect);
- rect.right -= rect.left;
- rect.bottom -= rect.top;
- rect.left = rect.top = 0;
- int border = OS.GetSystemMetrics (OS.SM_CXEDGE);
- OS.ExcludeClipRect (hDC, border, border, rect.right - border, rect.bottom - border);
- OS.DrawThemeBackground (display.hEditTheme (), hDC, OS.EP_EDITTEXT, OS.ETS_NORMAL, rect, null);
- OS.ReleaseDC (hwnd, hDC);
- return new LRESULT (code);
- }
- }
- }
- return result;
-}
-
-LRESULT wmNotify (NMHDR hdr, int /*long*/ wParam, int /*long*/ lParam) {
- if (!OS.IsWinCE) {
- switch (hdr.code) {
- /*
- * Feature in Windows. When the tool tip control is
- * created, the parent of the tool tip is the shell.
- * If SetParent () is used to reparent the tool bar
- * into a new shell, the tool tip is not reparented
- * and pops up underneath the new shell. The fix is
- * to make sure the tool tip is a topmost window.
- */
- case OS.TTN_SHOW:
- case OS.TTN_POP: {
- /*
- * Bug in Windows 98 and NT. Setting the tool tip to be the
- * top most window using HWND_TOPMOST can result in a parent
- * dialog shell being moved behind its parent if the dialog
- * has a sibling that is currently on top. The fix is to
- * lock the z-order of the active window.
- *
- * Feature in Windows. Using SetWindowPos() with HWND_NOTOPMOST
- * to clear the topmost state of a window whose parent is already
- * topmost clears the topmost state of the parent. The fix is to
- * check if the parent is already on top and neither set or clear
- * the topmost status of the tool tip.
- */
- int /*long*/ hwndParent = hdr.hwndFrom;
- do {
- hwndParent = OS.GetParent (hwndParent);
- if (hwndParent == 0) break;
- int bits = OS.GetWindowLong (hwndParent, OS.GWL_EXSTYLE);
- if ((bits & OS.WS_EX_TOPMOST) != 0) break;
- } while (true);
- if (hwndParent != 0) break;
- display.lockActiveWindow = true;
- int flags = OS.SWP_NOACTIVATE | OS.SWP_NOMOVE | OS.SWP_NOSIZE;
- int /*long*/ hwndInsertAfter = hdr.code == OS.TTN_SHOW ? OS.HWND_TOPMOST : OS.HWND_NOTOPMOST;
- SetWindowPos (hdr.hwndFrom, hwndInsertAfter, 0, 0, 0, 0, flags);
- display.lockActiveWindow = false;
- break;
- }
- /*
- * Bug in Windows 98. For some reason, the tool bar control
- * sends both TTN_GETDISPINFOW and TTN_GETDISPINFOA to get
- * the tool tip text and the tab folder control sends only
- * TTN_GETDISPINFOW. The fix is to handle only TTN_GETDISPINFOW,
- * even though it should never be sent on Windows 98.
- *
- * NOTE: Because the size of NMTTDISPINFO differs between
- * Windows 98 and NT, guard against the case where the wrong
- * kind of message occurs by inlining the memory moves and
- * the UNICODE conversion code.
- */
- case OS.TTN_GETDISPINFOA:
- case OS.TTN_GETDISPINFOW: {
- NMTTDISPINFO lpnmtdi;
- if (hdr.code == OS.TTN_GETDISPINFOA) {
- lpnmtdi = new NMTTDISPINFOA ();
- OS.MoveMemory ((NMTTDISPINFOA)lpnmtdi, lParam, NMTTDISPINFOA.sizeof);
- } else {
- lpnmtdi = new NMTTDISPINFOW ();
- OS.MoveMemory ((NMTTDISPINFOW)lpnmtdi, lParam, NMTTDISPINFOW.sizeof);
- }
- String string = toolTipText (lpnmtdi);
- if (string != null) {
- Shell shell = getShell ();
- string = Display.withCrLf (string);
- char [] chars = fixMnemonic (string);
-
- /*
- * Ensure that the orientation of the tool tip matches
- * the orientation of the control.
- */
- Widget widget = null;
- int /*long*/ hwnd = hdr.idFrom;
- if ((lpnmtdi.uFlags & OS.TTF_IDISHWND) != 0) {
- widget = display.getControl (hwnd);
- } else {
- if (hdr.hwndFrom == shell.toolTipHandle || hdr.hwndFrom == shell.balloonTipHandle) {
- widget = shell.findToolTip ((int)/*64*/hdr.idFrom);
- }
- }
- if (widget != null) {
- if ((widget.getStyle () & SWT.RIGHT_TO_LEFT) != 0) {
- lpnmtdi.uFlags |= OS.TTF_RTLREADING;
- } else {
- lpnmtdi.uFlags &= ~OS.TTF_RTLREADING;
- }
- }
-
- if (hdr.code == OS.TTN_GETDISPINFOA) {
- byte [] bytes = new byte [chars.length * 2];
- OS.WideCharToMultiByte (getCodePage (), 0, chars, chars.length, bytes, bytes.length, null, null);
- shell.setToolTipText (lpnmtdi, bytes);
- OS.MoveMemory (lParam, (NMTTDISPINFOA)lpnmtdi, NMTTDISPINFOA.sizeof);
- } else {
- shell.setToolTipText (lpnmtdi, chars);
- OS.MoveMemory (lParam, (NMTTDISPINFOW)lpnmtdi, NMTTDISPINFOW.sizeof);
- }
- return LRESULT.ZERO;
- }
- break;
- }
- }
- }
- return super.wmNotify (hdr, wParam, lParam);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
deleted file mode 100755
index 1edef54d8b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
+++ /dev/null
@@ -1,4894 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.gdip.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.accessibility.*;
-
-/**
- * Control is the abstract superclass of all windowed user interface classes.
- * <p>
- * <dl>
- * <dt><b>Styles:</b>
- * <dd>BORDER</dd>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * <dt><b>Events:</b>
- * <dd>DragDetect, FocusIn, FocusOut, Help, KeyDown, KeyUp, MenuDetect, MouseDoubleClick, MouseDown, MouseEnter,
- * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize, Traverse</dd>
- * </dl>
- * </p><p>
- * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#control">Control snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public abstract class Control extends Widget implements Drawable {
- /**
- * the handle to the OS resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
- Composite parent;
- Cursor cursor;
- Menu menu;
- String toolTipText;
- Object layoutData;
- Accessible accessible;
- Image backgroundImage;
- Region region;
- Font font;
- int drawCount, foreground, background;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Control () {
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#LEFT_TO_RIGHT
- * @see SWT#RIGHT_TO_LEFT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Control (Composite parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget ();
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize,typedListener);
- addListener (SWT.Move,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when a drag gesture occurs, by sending it
- * one of the messages defined in the <code>DragDetectListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #removeDragDetectListener
- *
- * @since 3.3
- */
-public void addDragDetectListener (DragDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.DragDetect,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control gains or loses focus, by sending
- * it one of the messages defined in the <code>FocusListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see FocusListener
- * @see #removeFocusListener
- */
-public void addFocusListener (FocusListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.FocusIn,typedListener);
- addListener (SWT.FocusOut,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when help events are generated for the control,
- * by sending it one of the messages defined in the
- * <code>HelpListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard, by sending
- * it one of the messages defined in the <code>KeyListener</code>
- * interface.
- * <p>
- * When a key listener is added to a control, the control
- * will take part in widget traversal. By default, all
- * traversal keys (such as the tab key and so on) are
- * delivered to the control. In order for a control to take
- * part in traversal, it should listen for traversal events.
- * Otherwise, the user can traverse into a control but not
- * out. Note that native controls such as table and tree
- * implement key traversal in the operating system. It is
- * not necessary to add traversal listeners for these controls,
- * unless you want to override the default traversal.
- * </p>
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #removeKeyListener
- */
-public void addKeyListener (KeyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.KeyUp,typedListener);
- addListener (SWT.KeyDown,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the platform-specific context menu trigger
- * has occurred, by sending it one of the messages defined in
- * the <code>MenuDetectListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #removeMenuDetectListener
- *
- * @since 3.3
- */
-public void addMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MenuDetect, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when mouse buttons are pressed and released, by sending
- * it one of the messages defined in the <code>MouseListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseListener
- * @see #removeMouseListener
- */
-public void addMouseListener (MouseListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseDown,typedListener);
- addListener (SWT.MouseUp,typedListener);
- addListener (SWT.MouseDoubleClick,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse passes or hovers over controls, by sending
- * it one of the messages defined in the <code>MouseTrackListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseTrackListener
- * @see #removeMouseTrackListener
- */
-public void addMouseTrackListener (MouseTrackListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseEnter,typedListener);
- addListener (SWT.MouseExit,typedListener);
- addListener (SWT.MouseHover,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse moves, by sending it one of the
- * messages defined in the <code>MouseMoveListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseMoveListener
- * @see #removeMouseMoveListener
- */
-public void addMouseMoveListener (MouseMoveListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseMove,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse wheel is scrolled, by sending
- * it one of the messages defined in the
- * <code>MouseWheelListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseWheelListener
- * @see #removeMouseWheelListener
- *
- * @since 3.3
- */
-public void addMouseWheelListener (MouseWheelListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseWheel, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver needs to be painted, by sending it
- * one of the messages defined in the <code>PaintListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see PaintListener
- * @see #removePaintListener
- */
-public void addPaintListener (PaintListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Paint,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when traversal events occur, by sending it
- * one of the messages defined in the <code>TraverseListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TraverseListener
- * @see #removeTraverseListener
- */
-public void addTraverseListener (TraverseListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Traverse,typedListener);
-}
-
-int /*long*/ borderHandle () {
- return handle;
-}
-
-void checkBackground () {
- Shell shell = getShell ();
- if (this == shell) return;
- state &= ~PARENT_BACKGROUND;
- Composite composite = parent;
- do {
- int mode = composite.backgroundMode;
- if (mode != 0) {
- if (mode == SWT.INHERIT_DEFAULT) {
- Control control = this;
- do {
- if ((control.state & THEME_BACKGROUND) == 0) {
- return;
- }
- control = control.parent;
- } while (control != composite);
- }
- state |= PARENT_BACKGROUND;
- return;
- }
- if (composite == shell) break;
- composite = composite.parent;
- } while (true);
-}
-
-void checkBorder () {
- if (getBorderWidth () == 0) style &= ~SWT.BORDER;
-}
-
-void checkBuffered () {
- style &= ~SWT.DOUBLE_BUFFERED;
-}
-
-void checkComposited () {
- /* Do nothing */
-}
-
-boolean checkHandle (int /*long*/ hwnd) {
- return hwnd == handle;
-}
-
-void checkMirrored () {
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
- if ((bits & OS.WS_EX_LAYOUTRTL) != 0) style |= SWT.MIRRORED;
- }
-}
-
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>preferred size</em> of a control is the size that it would
- * best be displayed at. The width hint and height hint arguments
- * allow the caller to ask a control questions such as "Given a particular
- * width, how high does the control need to be to show all of the contents?"
- * To indicate that the caller does not wish to constrain a particular
- * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
- * </p>
- *
- * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
- * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
- * @return the preferred size of the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Layout
- * @see #getBorderWidth
- * @see #getBounds
- * @see #getSize
- * @see #pack(boolean)
- * @see "computeTrim, getClientArea for controls that implement them"
- */
-public Point computeSize (int wHint, int hHint) {
- return computeSize (wHint, hHint, true);
-}
-
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>preferred size</em> of a control is the size that it would
- * best be displayed at. The width hint and height hint arguments
- * allow the caller to ask a control questions such as "Given a particular
- * width, how high does the control need to be to show all of the contents?"
- * To indicate that the caller does not wish to constrain a particular
- * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
- * </p><p>
- * If the changed flag is <code>true</code>, it indicates that the receiver's
- * <em>contents</em> have changed, therefore any caches that a layout manager
- * containing the control may have been keeping need to be flushed. When the
- * control is resized, the changed flag will be <code>false</code>, so layout
- * manager caches can be retained.
- * </p>
- *
- * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
- * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
- * @param changed <code>true</code> if the control's contents have changed, and <code>false</code> otherwise
- * @return the preferred size of the control.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Layout
- * @see #getBorderWidth
- * @see #getBounds
- * @see #getSize
- * @see #pack(boolean)
- * @see "computeTrim, getClientArea for controls that implement them"
- */
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = DEFAULT_WIDTH;
- int height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2;
- height += border * 2;
- return new Point (width, height);
-}
-
-Widget computeTabGroup () {
- if (isTabGroup ()) return this;
- return parent.computeTabGroup ();
-}
-
-Control computeTabRoot () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- int index = 0;
- while (index < tabList.length) {
- if (tabList [index] == this) break;
- index++;
- }
- if (index == tabList.length) {
- if (isTabGroup ()) return this;
- }
- }
- return parent.computeTabRoot ();
-}
-
-Widget [] computeTabList () {
- if (isTabGroup ()) {
- if (getVisible () && getEnabled ()) {
- return new Widget [] {this};
- }
- }
- return new Widget [0];
-}
-
-void createHandle () {
- int /*long*/ hwndParent = widgetParent ();
- handle = OS.CreateWindowEx (
- widgetExtStyle (),
- windowClass (),
- null,
- widgetStyle (),
- OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0,
- hwndParent,
- 0,
- OS.GetModuleHandle (null),
- widgetCreateStruct ());
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.WS_CHILD) != 0) {
- OS.SetWindowLongPtr (handle, OS.GWLP_ID, handle);
- }
- if (OS.IsDBLocale && hwndParent != 0) {
- int /*long*/ hIMC = OS.ImmGetContext (hwndParent);
- OS.ImmAssociateContext (handle, hIMC);
- OS.ImmReleaseContext (hwndParent, hIMC);
- }
-}
-
-void createWidget () {
- state |= DRAG_DETECT;
- foreground = background = -1;
- checkOrientation (parent);
- createHandle ();
- checkBackground ();
- checkBuffered ();
- checkComposited ();
- register ();
- subclass ();
- setDefaultFont ();
- checkMirrored ();
- checkBorder ();
- if ((state & PARENT_BACKGROUND) != 0) {
- setBackground ();
- }
-}
-
-int defaultBackground () {
- if (OS.IsWinCE) return OS.GetSysColor (OS.COLOR_WINDOW);
- return OS.GetSysColor (OS.COLOR_BTNFACE);
-}
-
-int /*long*/ defaultFont () {
- return display.getSystemFont ().handle;
-}
-
-int defaultForeground () {
- return OS.GetSysColor (OS.COLOR_WINDOWTEXT);
-}
-
-void deregister () {
- display.removeControl (handle);
-}
-
-void destroyWidget () {
- int /*long*/ hwnd = topHandle ();
- releaseHandle ();
- if (hwnd != 0) {
- OS.DestroyWindow (hwnd);
- }
-}
-
-/**
- * Detects a drag and drop gesture. This method is used
- * to detect a drag gesture when called from within a mouse
- * down listener.
- *
- * <p>By default, a drag is detected when the gesture
- * occurs anywhere within the client area of a control.
- * Some controls, such as tables and trees, override this
- * behavior. In addition to the operating system specific
- * drag gesture, they require the mouse to be inside an
- * item. Custom widget writers can use <code>setDragDetect</code>
- * to disable the default detection, listen for mouse down,
- * and then call <code>dragDetect()</code> from within the
- * listener to conditionally detect a drag.
- * </p>
- *
- * @param event the mouse down event
- *
- * @return <code>true</code> if the gesture occurred, and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT when the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @see #getDragDetect
- * @see #setDragDetect
- *
- * @since 3.3
- */
-public boolean dragDetect (Event event) {
- checkWidget ();
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- return dragDetect (event.button, event.count, event.stateMask, event.x, event.y);
-}
-
-/**
- * Detects a drag and drop gesture. This method is used
- * to detect a drag gesture when called from within a mouse
- * down listener.
- *
- * <p>By default, a drag is detected when the gesture
- * occurs anywhere within the client area of a control.
- * Some controls, such as tables and trees, override this
- * behavior. In addition to the operating system specific
- * drag gesture, they require the mouse to be inside an
- * item. Custom widget writers can use <code>setDragDetect</code>
- * to disable the default detection, listen for mouse down,
- * and then call <code>dragDetect()</code> from within the
- * listener to conditionally detect a drag.
- * </p>
- *
- * @param event the mouse down event
- *
- * @return <code>true</code> if the gesture occurred, and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT when the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @see #getDragDetect
- * @see #setDragDetect
- *
- * @since 3.3
- */
-public boolean dragDetect (MouseEvent event) {
- checkWidget ();
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- return dragDetect (event.button, event.count, event.stateMask, event.x, event.y);
-}
-
-boolean dragDetect (int button, int count, int stateMask, int x, int y) {
- if (button != 1 || count != 1) return false;
- boolean dragging = dragDetect (handle, x, y, false, null, null);
- if (OS.GetKeyState (OS.VK_LBUTTON) < 0) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- if (!dragging) {
- /*
- * Feature in Windows. DragDetect() captures the mouse
- * and tracks its movement until the user releases the
- * left mouse button, presses the ESC key, or moves the
- * mouse outside the drag rectangle. If the user moves
- * the mouse outside of the drag rectangle, DragDetect()
- * returns true and a drag and drop operation can be
- * started. When the left mouse button is released or
- * the ESC key is pressed, these events are consumed by
- * DragDetect() so that application code that matches
- * mouse down/up pairs or looks for the ESC key will not
- * function properly. The fix is to send the missing
- * events when the drag has not started.
- *
- * NOTE: For now, don't send a fake WM_KEYDOWN/WM_KEYUP
- * events for the ESC key. This would require computing
- * wParam (the key) and lParam (the repeat count, scan code,
- * extended-key flag, context code, previous key-state flag,
- * and transition-state flag) which is non-trivial.
- */
- if (button == 1 && OS.GetKeyState (OS.VK_ESCAPE) >= 0) {
- int wParam = 0;
- if ((stateMask & SWT.CTRL) != 0) wParam |= OS.MK_CONTROL;
- if ((stateMask & SWT.SHIFT) != 0) wParam |= OS.MK_SHIFT;
- if ((stateMask & SWT.ALT) != 0) wParam |= OS.MK_ALT;
- if ((stateMask & SWT.BUTTON1) != 0) wParam |= OS.MK_LBUTTON;
- if ((stateMask & SWT.BUTTON2) != 0) wParam |= OS.MK_MBUTTON;
- if ((stateMask & SWT.BUTTON3) != 0) wParam |= OS.MK_RBUTTON;
- if ((stateMask & SWT.BUTTON4) != 0) wParam |= OS.MK_XBUTTON1;
- if ((stateMask & SWT.BUTTON5) != 0) wParam |= OS.MK_XBUTTON2;
- int /*long*/ lParam = OS.MAKELPARAM (x, y);
- OS.SendMessage (handle, OS.WM_LBUTTONUP, wParam, lParam);
- }
- return false;
- }
- return sendDragEvent (button, stateMask, x, y);
-}
-
-void drawBackground (int /*long*/ hDC) {
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- drawBackground (hDC, rect);
-}
-
-void drawBackground (int /*long*/ hDC, RECT rect) {
- drawBackground (hDC, rect, -1);
-}
-
-void drawBackground (int /*long*/ hDC, RECT rect, int pixel) {
- Control control = findBackgroundControl ();
- if (control != null) {
- if (control.backgroundImage != null) {
- fillImageBackground (hDC, control, rect);
- return;
- }
- pixel = control.getBackgroundPixel ();
- }
- if (pixel == -1) {
- if ((state & THEME_BACKGROUND) != 0) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- control = findThemeControl ();
- if (control != null) {
- fillThemeBackground (hDC, control, rect);
- return;
- }
- }
- }
- }
- if (pixel == -1) pixel = getBackgroundPixel ();
- fillBackground (hDC, pixel, rect);
-}
-
-void drawImageBackground (int /*long*/ hDC, int /*long*/ hwnd, int /*long*/ hBitmap, RECT rect) {
- RECT rect2 = new RECT ();
- OS.GetClientRect (hwnd, rect2);
- OS.MapWindowPoints (hwnd, handle, rect2, 2);
- int /*long*/ hBrush = findBrush (hBitmap, OS.BS_PATTERN);
- POINT lpPoint = new POINT ();
- OS.GetWindowOrgEx (hDC, lpPoint);
- OS.SetBrushOrgEx (hDC, -rect2.left - lpPoint.x, -rect2.top - lpPoint.y, lpPoint);
- int /*long*/ hOldBrush = OS.SelectObject (hDC, hBrush);
- OS.PatBlt (hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, OS.PATCOPY);
- OS.SetBrushOrgEx (hDC, lpPoint.x, lpPoint.y, null);
- OS.SelectObject (hDC, hOldBrush);
-}
-
-void drawThemeBackground (int /*long*/ hDC, int /*long*/ hwnd, RECT rect) {
- /* Do nothing */
-}
-
-void enableDrag (boolean enabled) {
- /* Do nothing */
-}
-
-void enableWidget (boolean enabled) {
- OS.EnableWindow (handle, enabled);
-}
-
-void fillBackground (int /*long*/ hDC, int pixel, RECT rect) {
- if (rect.left > rect.right || rect.top > rect.bottom) return;
- int /*long*/ hPalette = display.hPalette;
- if (hPalette != 0) {
- OS.SelectPalette (hDC, hPalette, false);
- OS.RealizePalette (hDC);
- }
- OS.FillRect (hDC, rect, findBrush (pixel, OS.BS_SOLID));
-}
-
-void fillImageBackground (int /*long*/ hDC, Control control, RECT rect) {
- if (rect.left > rect.right || rect.top > rect.bottom) return;
- if (control != null) {
- Image image = control.backgroundImage;
- if (image != null) {
- control.drawImageBackground (hDC, handle, image.handle, rect);
- }
- }
-}
-
-void fillThemeBackground (int /*long*/ hDC, Control control, RECT rect) {
- if (rect.left > rect.right || rect.top > rect.bottom) return;
- if (control != null) {
- control.drawThemeBackground (hDC, handle, rect);
- }
-}
-
-Control findBackgroundControl () {
- if (background != -1 || backgroundImage != null) return this;
- return (state & PARENT_BACKGROUND) != 0 ? parent.findBackgroundControl () : null;
-}
-
-int /*long*/ findBrush (int /*long*/ value, int lbStyle) {
- return parent.findBrush (value, lbStyle);
-}
-
-Cursor findCursor () {
- if (cursor != null) return cursor;
- return parent.findCursor ();
-}
-
-Control findImageControl () {
- Control control = findBackgroundControl ();
- return control != null && control.backgroundImage != null ? control : null;
-}
-
-Control findThemeControl () {
- return background == -1 && backgroundImage == null ? parent.findThemeControl () : null;
-}
-
-Menu [] findMenus (Control control) {
- if (menu != null && this != control) return new Menu [] {menu};
- return new Menu [0];
-}
-
-char findMnemonic (String string) {
- int index = 0;
- int length = string.length ();
- do {
- while (index < length && string.charAt (index) != '&') index++;
- if (++index >= length) return '\0';
- if (string.charAt (index) != '&') return string.charAt (index);
- index++;
- } while (index < length);
- return '\0';
-}
-
-void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) {
- oldShell.fixShell (newShell, this);
- oldDecorations.fixDecorations (newDecorations, this, menus);
-}
-
-void fixFocus (Control focusControl) {
- Shell shell = getShell ();
- Control control = this;
- while (control != shell && (control = control.parent) != null) {
- if (control.setFixedFocus ()) return;
- }
- shell.setSavedFocus (focusControl);
- OS.SetFocus (0);
-}
-
-/**
- * Forces the receiver to have the <em>keyboard focus</em>, causing
- * all keyboard events to be delivered to it.
- *
- * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setFocus
- */
-public boolean forceFocus () {
- checkWidget ();
- if (display.focusEvent == SWT.FocusOut) return false;
- Decorations shell = menuShell ();
- shell.setSavedFocus (this);
- if (!isEnabled () || !isVisible () || !isActive ()) return false;
- if (isFocusControl ()) return true;
- shell.setSavedFocus (null);
- /*
- * This code is intentionally commented.
- *
- * When setting focus to a control, it is
- * possible that application code can set
- * the focus to another control inside of
- * WM_SETFOCUS. In this case, the original
- * control will no longer have the focus
- * and the call to setFocus() will return
- * false indicating failure.
- *
- * We are still working on a solution at
- * this time.
- */
-// if (OS.GetFocus () != OS.SetFocus (handle)) return false;
- OS.SetFocus (handle);
- if (isDisposed ()) return false;
- shell.setSavedFocus (this);
- return isFocusControl ();
-}
-
-void forceResize () {
- if (parent == null) return;
- WINDOWPOS [] lpwp = parent.lpwp;
- if (lpwp == null) return;
- for (int i=0; i<lpwp.length; i++) {
- WINDOWPOS wp = lpwp [i];
- if (wp != null && wp.hwnd == handle) {
- /*
- * This code is intentionally commented. All widgets that
- * are created by SWT have WS_CLIPSIBLINGS to ensure that
- * application code does not draw outside of the control.
- */
-// int count = parent.getChildrenCount ();
-// if (count > 1) {
-// int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
-// if ((bits & OS.WS_CLIPSIBLINGS) == 0) wp.flags |= OS.SWP_NOCOPYBITS;
-// }
- SetWindowPos (wp.hwnd, 0, wp.x, wp.y, wp.cx, wp.cy, wp.flags);
- lpwp [i] = null;
- return;
- }
- }
-}
-
-/**
- * Returns the accessible object for the receiver.
- * If this is the first time this object is requested,
- * then the object is created and returned.
- *
- * @return the accessible object
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Accessible#addAccessibleListener
- * @see Accessible#addAccessibleControlListener
- *
- * @since 2.0
- */
-public Accessible getAccessible () {
- checkWidget ();
- if (accessible == null) accessible = new_Accessible (this);
- return accessible;
-}
-
-/**
- * Returns the receiver's background color.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on some versions of Windows the background of a TabFolder,
- * is a gradient rather than a solid color.
- * </p>
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Color getBackground () {
- checkWidget ();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- return Color.win32_new (display, control.getBackgroundPixel ());
-}
-
-/**
- * Returns the receiver's background image.
- *
- * @return the background image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Image getBackgroundImage () {
- checkWidget ();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- return control.backgroundImage;
-}
-
-int getBackgroundPixel () {
- return background != -1 ? background : defaultBackground ();
-}
-
-/**
- * Returns the receiver's border width.
- *
- * @return the border width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getBorderWidth () {
- checkWidget ();
- int /*long*/ borderHandle = borderHandle ();
- int bits1 = OS.GetWindowLong (borderHandle, OS.GWL_EXSTYLE);
- if ((bits1 & OS.WS_EX_CLIENTEDGE) != 0) return OS.GetSystemMetrics (OS.SM_CXEDGE);
- if ((bits1 & OS.WS_EX_STATICEDGE) != 0) return OS.GetSystemMetrics (OS.SM_CXBORDER);
- int bits2 = OS.GetWindowLong (borderHandle, OS.GWL_STYLE);
- if ((bits2 & OS.WS_BORDER) != 0) return OS.GetSystemMetrics (OS.SM_CXBORDER);
- return 0;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null),
- * unless the receiver is a shell. In this case, the location is
- * relative to the display.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget ();
- forceResize ();
- RECT rect = new RECT ();
- OS.GetWindowRect (topHandle (), rect);
- int /*long*/ hwndParent = parent == null ? 0 : parent.handle;
- OS.MapWindowPoints (0, hwndParent, rect, 2);
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- return new Rectangle (rect.left, rect.top, width, height);
-}
-
-int getCodePage () {
- if (OS.IsUnicode) return OS.CP_ACP;
- int /*long*/ hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- LOGFONT logFont = OS.IsUnicode ? (LOGFONT) new LOGFONTW () : new LOGFONTA ();
- OS.GetObject (hFont, LOGFONT.sizeof, logFont);
- int cs = logFont.lfCharSet & 0xFF;
- int [] lpCs = new int [8];
- if (OS.TranslateCharsetInfo (cs, lpCs, OS.TCI_SRCCHARSET)) {
- return lpCs [1];
- }
- return OS.GetACP ();
-}
-
-String getClipboardText () {
- String string = "";
- if (OS.OpenClipboard (0)) {
- int /*long*/ hMem = OS.GetClipboardData (OS.IsUnicode ? OS.CF_UNICODETEXT : OS.CF_TEXT);
- if (hMem != 0) {
- /* Ensure byteCount is a multiple of 2 bytes on UNICODE platforms */
- int byteCount = OS.GlobalSize (hMem) / TCHAR.sizeof * TCHAR.sizeof;
- int /*long*/ ptr = OS.GlobalLock (hMem);
- if (ptr != 0) {
- /* Use the character encoding for the default locale */
- TCHAR buffer = new TCHAR (0, byteCount / TCHAR.sizeof);
- OS.MoveMemory (buffer, ptr, byteCount);
- string = buffer.toString (0, buffer.strlen ());
- OS.GlobalUnlock (hMem);
- }
- }
- OS.CloseClipboard ();
- }
- return string;
-}
-
-/**
- * Returns the receiver's cursor, or null if it has not been set.
- * <p>
- * When the mouse pointer passes over a control its appearance
- * is changed to match the control's cursor.
- * </p>
- *
- * @return the receiver's cursor or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Cursor getCursor () {
- checkWidget ();
- return cursor;
-}
-
-/**
- * Returns <code>true</code> if the receiver is detecting
- * drag gestures, and <code>false</code> otherwise.
- *
- * @return the receiver's drag detect state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public boolean getDragDetect () {
- checkWidget ();
- return (state & DRAG_DETECT) != 0;
-}
-
-boolean getDrawing () {
- return drawCount <= 0;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget ();
- return OS.IsWindowEnabled (handle);
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Font getFont () {
- checkWidget ();
- if (font != null) return font;
- int /*long*/ hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (hFont == 0) hFont = defaultFont ();
- return Font.win32_new (display, hFont);
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Color getForeground () {
- checkWidget ();
- return Color.win32_new (display, getForegroundPixel ());
-}
-
-int getForegroundPixel () {
- return foreground != -1 ? foreground : defaultForeground ();
-}
-
-/**
- * Returns layout data which is associated with the receiver.
- *
- * @return the receiver's layout data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Object getLayoutData () {
- checkWidget ();
- return layoutData;
-}
-
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @return the receiver's location
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getLocation () {
- checkWidget ();
- forceResize ();
- RECT rect = new RECT ();
- OS.GetWindowRect (topHandle (), rect);
- int /*long*/ hwndParent = parent == null ? 0 : parent.handle;
- OS.MapWindowPoints (0, hwndParent, rect, 2);
- return new Point (rect.left, rect.top);
-}
-
-/**
- * Returns the receiver's pop up menu if it has one, or null
- * if it does not. All controls may optionally have a pop up
- * menu that is displayed when the user requests one for
- * the control. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pop up
- * menu is platform specific.
- *
- * @return the receiver's menu
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenu () {
- checkWidget ();
- return menu;
-}
-
-/**
- * Returns the receiver's monitor.
- *
- * @return the receiver's monitor
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Monitor getMonitor () {
- checkWidget ();
- if (OS.IsWinCE || OS.WIN32_VERSION < OS.VERSION (4, 10)) {
- return display.getPrimaryMonitor ();
- }
- int /*long*/ hmonitor = OS.MonitorFromWindow (handle, OS.MONITOR_DEFAULTTONEAREST);
- MONITORINFO lpmi = new MONITORINFO ();
- lpmi.cbSize = MONITORINFO.sizeof;
- OS.GetMonitorInfo (hmonitor, lpmi);
- Monitor monitor = new Monitor ();
- monitor.handle = hmonitor;
- monitor.x = lpmi.rcMonitor_left;
- monitor.y = lpmi.rcMonitor_top;
- monitor.width = lpmi.rcMonitor_right - lpmi.rcMonitor_left;
- monitor.height = lpmi.rcMonitor_bottom - lpmi.rcMonitor_top;
- monitor.clientX = lpmi.rcWork_left;
- monitor.clientY = lpmi.rcWork_top;
- monitor.clientWidth = lpmi.rcWork_right - lpmi.rcWork_left;
- monitor.clientHeight = lpmi.rcWork_bottom - lpmi.rcWork_top;
- return monitor;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Composite</code>
- * or null when the receiver is a shell that was created with null or
- * a display for a parent.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Composite getParent () {
- checkWidget ();
- return parent;
-}
-
-Control [] getPath () {
- int count = 0;
- Shell shell = getShell ();
- Control control = this;
- while (control != shell) {
- count++;
- control = control.parent;
- }
- control = this;
- Control [] result = new Control [count];
- while (control != shell) {
- result [--count] = control;
- control = control.parent;
- }
- return result;
-}
-
-/**
- * Returns the region that defines the shape of the control,
- * or null if the control has the default shape.
- *
- * @return the region that defines the shape of the shell (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public Region getRegion () {
- checkWidget ();
- return region;
-}
-
-/**
- * Returns the receiver's shell. For all controls other than
- * shells, this simply returns the control's nearest ancestor
- * shell. Shells return themselves, even if they are children
- * of other shells.
- *
- * @return the receiver's shell
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getParent
- */
-public Shell getShell () {
- checkWidget ();
- return parent.getShell ();
-}
-
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget ();
- forceResize ();
- RECT rect = new RECT ();
- OS.GetWindowRect (topHandle (), rect);
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- return new Point (width, height);
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- if (!getDrawing()) return (state & HIDDEN) == 0;
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- return (bits & OS.WS_VISIBLE) != 0;
-}
-
-boolean hasCursor () {
- RECT rect = new RECT ();
- if (!OS.GetClientRect (handle, rect)) return false;
- OS.MapWindowPoints (handle, 0, rect, 2);
- POINT pt = new POINT ();
- return OS.GetCursorPos (pt) && OS.PtInRect (rect, pt);
-}
-
-boolean hasFocus () {
- /*
- * If a non-SWT child of the control has focus,
- * then this control is considered to have focus
- * even though it does not have focus in Windows.
- */
- int /*long*/ hwndFocus = OS.GetFocus ();
- while (hwndFocus != 0) {
- if (hwndFocus == handle) return true;
- if (display.getControl (hwndFocus) != null) {
- return false;
- }
- hwndFocus = OS.GetParent (hwndFocus);
- }
- return false;
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Control</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public int /*long*/ internal_new_GC (GCData data) {
- checkWidget();
- int /*long*/ hwnd = handle;
- if (data != null && data.hwnd != 0) hwnd = data.hwnd;
- if (data != null) data.hwnd = hwnd;
- int /*long*/ hDC = 0;
- if (data == null || data.ps == null) {
- hDC = OS.GetDC (hwnd);
- } else {
- hDC = OS.BeginPaint (hwnd, data.ps);
- }
- if (hDC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (data != null) {
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) != 0) {
- data.layout = (data.style & SWT.RIGHT_TO_LEFT) != 0 ? OS.LAYOUT_RTL : 0;
- } else {
- int flags = OS.GetLayout (hDC);
- if ((flags & OS.LAYOUT_RTL) != 0) {
- data.style |= SWT.RIGHT_TO_LEFT | SWT.MIRRORED;
- } else {
- data.style |= SWT.LEFT_TO_RIGHT;
- }
- }
- } else {
- data.style |= SWT.LEFT_TO_RIGHT;
- }
- data.device = display;
- int foreground = getForegroundPixel ();
- if (foreground != OS.GetTextColor (hDC)) data.foreground = foreground;
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- int background = control.getBackgroundPixel ();
- if (background != OS.GetBkColor (hDC)) data.background = background;
- data.font = font != null ? font : Font.win32_new (display, OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0));
- data.uiState = (int)/*64*/OS.SendMessage (hwnd, OS.WM_QUERYUISTATE, 0, 0);
- }
- return hDC;
-}
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Control</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int /*long*/ hDC, GCData data) {
- checkWidget ();
- int /*long*/ hwnd = handle;
- if (data != null && data.hwnd != 0) {
- hwnd = data.hwnd;
- }
- if (data == null || data.ps == null) {
- OS.ReleaseDC (hwnd, hDC);
- } else {
- OS.EndPaint (hwnd, data.ps);
- }
-}
-
-boolean isActive () {
- Dialog dialog = display.getModalDialog ();
- if (dialog != null) {
- Shell dialogShell = dialog.parent;
- if (dialogShell != null && !dialogShell.isDisposed ()) {
- if (dialogShell != getShell ()) return false;
- }
- }
- Shell shell = null;
- Shell [] modalShells = display.modalShells;
- if (modalShells != null) {
- int bits = SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- int index = modalShells.length;
- while (--index >= 0) {
- Shell modal = modalShells [index];
- if (modal != null) {
- if ((modal.style & bits) != 0) {
- Control control = this;
- while (control != null) {
- if (control == modal) break;
- control = control.parent;
- }
- if (control != modal) return false;
- break;
- }
- if ((modal.style & SWT.PRIMARY_MODAL) != 0) {
- if (shell == null) shell = getShell ();
- if (modal.parent == shell) return false;
- }
- }
- }
- }
- if (shell == null) shell = getShell ();
- return shell.getEnabled ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * ancestors up to and including the receiver's nearest ancestor
- * shell are enabled. Otherwise, <code>false</code> is returned.
- * A disabled control is typically not selectable from the user
- * interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget ();
- return getEnabled () && parent.isEnabled ();
-}
-
-/**
- * Returns <code>true</code> if the receiver has the user-interface
- * focus, and <code>false</code> otherwise.
- *
- * @return the receiver's focus state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isFocusControl () {
- checkWidget ();
- Control focusControl = display.focusControl;
- if (focusControl != null && !focusControl.isDisposed ()) {
- return this == focusControl;
- }
- return hasFocus ();
-}
-
-boolean isFocusAncestor (Control control) {
- while (control != null && control != this && !(control instanceof Shell)) {
- control = control.parent;
- }
- return control == this;
-}
-
-/**
- * Returns <code>true</code> if the underlying operating
- * system supports this reparenting, otherwise <code>false</code>
- *
- * @return <code>true</code> if the widget can be reparented, otherwise <code>false</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isReparentable () {
- checkWidget ();
- return true;
-}
-
-boolean isShowing () {
- /*
- * This is not complete. Need to check if the
- * widget is obscured by a parent or sibling.
- */
- if (!isVisible ()) return false;
- Control control = this;
- while (control != null) {
- Point size = control.getSize ();
- if (size.x == 0 || size.y == 0) {
- return false;
- }
- control = control.parent;
- }
- return true;
- /*
- * Check to see if current damage is included.
- */
-// if (!OS.IsWindowVisible (handle)) return false;
-// int flags = OS.DCX_CACHE | OS.DCX_CLIPCHILDREN | OS.DCX_CLIPSIBLINGS;
-// int /*long*/ hDC = OS.GetDCEx (handle, 0, flags);
-// int result = OS.GetClipBox (hDC, new RECT ());
-// OS.ReleaseDC (handle, hDC);
-// return result != OS.NULLREGION;
-}
-
-boolean isTabGroup () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == this) return true;
- }
- }
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- return (bits & OS.WS_TABSTOP) != 0;
-}
-
-boolean isTabItem () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == this) return false;
- }
- }
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.WS_TABSTOP) != 0) return false;
- int /*long*/ code = OS.SendMessage (handle, OS.WM_GETDLGCODE, 0, 0);
- if ((code & OS.DLGC_STATIC) != 0) return false;
- if ((code & OS.DLGC_WANTALLKEYS) != 0) return false;
- if ((code & OS.DLGC_WANTARROWS) != 0) return false;
- if ((code & OS.DLGC_WANTTAB) != 0) return false;
- return true;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * ancestors up to and including the receiver's nearest ancestor
- * shell are visible. Otherwise, <code>false</code> is returned.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget ();
- if (OS.IsWindowVisible (handle)) return true;
- return getVisible () && parent.isVisible ();
-}
-
-void mapEvent (int /*long*/ hwnd, Event event) {
- if (hwnd != handle) {
- POINT point = new POINT ();
- point.x = event.x;
- point.y = event.y;
- OS.MapWindowPoints (hwnd, handle, point, 1);
- event.x = point.x;
- event.y = point.y;
- }
-}
-
-void markLayout (boolean changed, boolean all) {
- /* Do nothing */
-}
-
-Decorations menuShell () {
- return parent.menuShell ();
-}
-
-boolean mnemonicHit (char key) {
- return false;
-}
-
-boolean mnemonicMatch (char key) {
- return false;
-}
-
-/**
- * Moves the receiver above the specified control in the
- * drawing order. If the argument is null, then the receiver
- * is moved to the top of the drawing order. The control at
- * the top of the drawing order will not be covered by other
- * controls even if they occupy intersecting areas.
- *
- * @param control the sibling control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveBelow
- * @see Composite#getChildren
- */
-public void moveAbove (Control control) {
- checkWidget ();
- int /*long*/ topHandle = topHandle (), hwndAbove = OS.HWND_TOP;
- if (control != null) {
- if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- int /*long*/ hwnd = control.topHandle ();
- if (hwnd == 0 || hwnd == topHandle) return;
- hwndAbove = OS.GetWindow (hwnd, OS.GW_HWNDPREV);
- /*
- * Bug in Windows. For some reason, when GetWindow ()
- * with GW_HWNDPREV is used to query the previous window
- * in the z-order with the first child, Windows returns
- * the first child instead of NULL. The fix is to detect
- * this case and move the control to the top.
- */
- if (hwndAbove == 0 || hwndAbove == hwnd) {
- hwndAbove = OS.HWND_TOP;
- }
- }
- int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE;
- SetWindowPos (topHandle, hwndAbove, 0, 0, 0, 0, flags);
-}
-
-/**
- * Moves the receiver below the specified control in the
- * drawing order. If the argument is null, then the receiver
- * is moved to the bottom of the drawing order. The control at
- * the bottom of the drawing order will be covered by all other
- * controls which occupy intersecting areas.
- *
- * @param control the sibling control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveAbove
- * @see Composite#getChildren
- */
-public void moveBelow (Control control) {
- checkWidget ();
- int /*long*/ topHandle = topHandle (), hwndAbove = OS.HWND_BOTTOM;
- if (control != null) {
- if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- hwndAbove = control.topHandle ();
- } else {
- /*
- * Bug in Windows. When SetWindowPos() is called
- * with HWND_BOTTOM on a dialog shell, the dialog
- * and the parent are moved to the bottom of the
- * desktop stack. The fix is to move the dialog
- * to the bottom of the dialog window stack by
- * moving behind the first dialog child.
- */
- Shell shell = getShell ();
- if (this == shell && parent != null) {
- /*
- * Bug in Windows. For some reason, when GetWindow ()
- * with GW_HWNDPREV is used to query the previous window
- * in the z-order with the first child, Windows returns
- * the first child instead of NULL. The fix is to detect
- * this case and do nothing because the control is already
- * at the bottom.
- */
- int /*long*/ hwndParent = parent.handle, hwnd = hwndParent;
- hwndAbove = OS.GetWindow (hwnd, OS.GW_HWNDPREV);
- while (hwndAbove != 0 && hwndAbove != hwnd) {
- if (OS.GetWindow (hwndAbove, OS.GW_OWNER) == hwndParent) break;
- hwndAbove = OS.GetWindow (hwnd = hwndAbove, OS.GW_HWNDPREV);
- }
- if (hwndAbove == hwnd) return;
- }
- }
- if (hwndAbove == 0 || hwndAbove == topHandle) return;
- int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE;
- SetWindowPos (topHandle, hwndAbove, 0, 0, 0, 0, flags);
-}
-
-Accessible new_Accessible (Control control) {
- return Accessible.internal_new_Accessible (this);
-}
-
-GC new_GC (GCData data) {
- return GC.win32_new (this, data);
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeSize(int, int, boolean)
- */
-public void pack () {
- checkWidget ();
- pack (true);
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- * <p>
- * If the changed flag is <code>true</code>, it indicates that the receiver's
- * <em>contents</em> have changed, therefore any caches that a layout manager
- * containing the control may have been keeping need to be flushed. When the
- * control is resized, the changed flag will be <code>false</code>, so layout
- * manager caches can be retained.
- * </p>
- *
- * @param changed whether or not the receiver's contents have changed
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeSize(int, int, boolean)
- */
-public void pack (boolean changed) {
- checkWidget ();
- setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed));
-}
-
-/**
- * Prints the receiver and all children.
- *
- * @param gc the gc where the drawing occurs
- * @return <code>true</code> if the operation was successful and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean print (GC gc) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
- int /*long*/ topHandle = topHandle ();
- int /*long*/ hdc = gc.handle;
- int state = 0;
- int /*long*/ gdipGraphics = gc.getGCData().gdipGraphics;
- if (gdipGraphics != 0) {
- int /*long*/ clipRgn = 0;
- Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone);
- int /*long*/ rgn = Gdip.Region_new();
- if (rgn == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Gdip.Graphics_GetClip(gdipGraphics, rgn);
- if (!Gdip.Region_IsInfinite(rgn, gdipGraphics)) {
- clipRgn = Gdip.Region_GetHRGN(rgn, gdipGraphics);
- }
- Gdip.Region_delete(rgn);
- Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf);
- float[] lpXform = null;
- int /*long*/ matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0);
- if (matrix == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Gdip.Graphics_GetTransform(gdipGraphics, matrix);
- if (!Gdip.Matrix_IsIdentity(matrix)) {
- lpXform = new float[6];
- Gdip.Matrix_GetElements(matrix, lpXform);
- }
- Gdip.Matrix_delete(matrix);
- hdc = Gdip.Graphics_GetHDC(gdipGraphics);
- state = OS.SaveDC(hdc);
- if (lpXform != null) {
- OS.SetGraphicsMode(hdc, OS.GM_ADVANCED);
- OS.SetWorldTransform(hdc, lpXform);
- }
- if (clipRgn != 0) {
- OS.SelectClipRgn(hdc, clipRgn);
- OS.DeleteObject(clipRgn);
- }
- }
- if (OS.IsWinCE) {
- OS.UpdateWindow (topHandle);
- } else {
- int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (topHandle, null, 0, flags);
- }
- printWidget (topHandle, hdc, gc);
- if (gdipGraphics != 0) {
- OS.RestoreDC(hdc, state);
- Gdip.Graphics_ReleaseHDC(gdipGraphics, hdc);
- }
- return true;
- }
- return false;
-}
-
-void printWidget (int /*long*/ hwnd, int /*long*/ hdc, GC gc) {
- /*
- * Bug in Windows. For some reason, PrintWindow()
- * returns success but does nothing when it is called
- * on a printer. The fix is to just go directly to
- * WM_PRINT in this case.
- */
- boolean success = false;
- if (!(OS.GetDeviceCaps(gc.handle, OS.TECHNOLOGY) == OS.DT_RASPRINTER)) {
- /*
- * Bug in Windows. When PrintWindow() will only draw that
- * portion of a control that is not obscured by the shell.
- * The fix is temporarily reparent the window to the desktop,
- * call PrintWindow() then reparent the window back.
- */
- int /*long*/ hwndParent = OS.GetParent (hwnd);
- int /*long*/ hwndShell = hwndParent;
- while (OS.GetParent (hwndShell) != 0) {
- if (OS.GetWindow (hwndShell, OS.GW_OWNER) != 0) break;
- hwndShell = OS.GetParent (hwndShell);
- }
- RECT rect1 = new RECT ();
- OS.GetWindowRect (hwnd, rect1);
- boolean fixPrintWindow = !OS.IsWindowVisible(hwnd);
- if (!fixPrintWindow) {
- RECT rect2 = new RECT ();
- OS.GetWindowRect (hwndShell, rect2);
- OS.IntersectRect (rect2, rect1, rect2);
- fixPrintWindow = !OS.EqualRect (rect2, rect1);
- }
- /*
- * Bug in Windows. PrintWindow() does not print portions
- * of the receiver that are clipped out using SetWindowRgn()
- * in a parent. The fix is temporarily reparent the window
- * to the desktop, call PrintWindow() then reparent the window
- * back.
- */
- if (!fixPrintWindow) {
- int /*long*/ rgn = OS.CreateRectRgn(0, 0, 0, 0);
- int /*long*/ parent = OS.GetParent(hwnd);
- while (parent != hwndShell && !fixPrintWindow) {
- if (OS.GetWindowRgn(parent, rgn) != 0) {
- fixPrintWindow = true;
- }
- parent = OS.GetParent(parent);
- }
- OS.DeleteObject(rgn);
- }
- int bits = OS.GetWindowLong (hwnd, OS.GWL_STYLE);
- int /*long*/ hwndInsertAfter = OS.GetWindow (hwnd, OS.GW_HWNDPREV);
- /*
- * Bug in Windows. For some reason, when GetWindow ()
- * with GW_HWNDPREV is used to query the previous window
- * in the z-order with the first child, Windows returns
- * the first child instead of NULL. The fix is to detect
- * this case and move the control to the top.
- */
- if (hwndInsertAfter == 0 || hwndInsertAfter == hwnd) {
- hwndInsertAfter = OS.HWND_TOP;
- }
- if (fixPrintWindow) {
- int x = OS.GetSystemMetrics (OS.SM_XVIRTUALSCREEN);
- int y = OS.GetSystemMetrics (OS.SM_YVIRTUALSCREEN);
- int width = OS.GetSystemMetrics (OS.SM_CXVIRTUALSCREEN);
- int height = OS.GetSystemMetrics (OS.SM_CYVIRTUALSCREEN);
- int flags = OS.SWP_NOSIZE | OS.SWP_NOZORDER | OS.SWP_NOACTIVATE | OS.SWP_DRAWFRAME;
- if ((bits & OS.WS_VISIBLE) != 0) {
- OS.DefWindowProc (hwnd, OS.WM_SETREDRAW, 0, 0);
- }
- SetWindowPos (hwnd, 0, x + width, y + height, 0, 0, flags);
- OS.SetParent (hwnd, 0);
- if ((bits & OS.WS_VISIBLE) != 0) {
- OS.DefWindowProc (hwnd, OS.WM_SETREDRAW, 1, 0);
- }
- }
- if ((bits & OS.WS_VISIBLE) == 0) {
- OS.DefWindowProc (hwnd, OS.WM_SETREDRAW, 1, 0);
- }
- success = OS.PrintWindow (hwnd, hdc, 0);
- if ((bits & OS.WS_VISIBLE) == 0) {
- OS.DefWindowProc (hwnd, OS.WM_SETREDRAW, 0, 0);
- }
- if (fixPrintWindow) {
- if ((bits & OS.WS_VISIBLE) != 0) {
- OS.DefWindowProc (hwnd, OS.WM_SETREDRAW, 0, 0);
- }
- OS.SetParent (hwnd, hwndParent);
- OS.MapWindowPoints (0, hwndParent, rect1, 2);
- int flags = OS.SWP_NOSIZE | OS.SWP_NOACTIVATE | OS.SWP_DRAWFRAME;
- SetWindowPos (hwnd, hwndInsertAfter, rect1.left, rect1.top, rect1.right - rect1.left, rect1.bottom - rect1.top, flags);
- if ((bits & OS.WS_VISIBLE) != 0) {
- OS.DefWindowProc (hwnd, OS.WM_SETREDRAW, 1, 0);
- }
- }
- }
-
- /*
- * Bug in Windows. For some reason, PrintWindow() fails
- * when it is called on a push button. The fix is to
- * detect the failure and use WM_PRINT instead. Note
- * that WM_PRINT cannot be used all the time because it
- * fails for browser controls when the browser has focus.
- */
- if (!success) {
- int flags = OS.PRF_CLIENT | OS.PRF_NONCLIENT | OS.PRF_ERASEBKGND | OS.PRF_CHILDREN;
- OS.SendMessage (hwnd, OS.WM_PRINT, hdc, flags);
- }
-}
-
-/**
- * Causes the entire bounds of the receiver to be marked
- * as needing to be redrawn. The next time a paint request
- * is processed, the control will be completely painted,
- * including the background.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #update()
- * @see PaintListener
- * @see SWT#Paint
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#DOUBLE_BUFFERED
- */
-public void redraw () {
- checkWidget ();
- redraw (false);
-}
-
-void redraw (boolean all) {
-// checkWidget ();
- if (!OS.IsWindowVisible (handle)) return;
- if (OS.IsWinCE) {
- OS.InvalidateRect (handle, null, true);
- } else {
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE;
- if (all) flags |= OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, null, 0, flags);
- }
-}
-/**
- * Causes the rectangular area of the receiver specified by
- * the arguments to be marked as needing to be redrawn.
- * The next time a paint request is processed, that area of
- * the receiver will be painted, including the background.
- * If the <code>all</code> flag is <code>true</code>, any
- * children of the receiver which intersect with the specified
- * area will also paint their intersecting areas. If the
- * <code>all</code> flag is <code>false</code>, the children
- * will not be painted.
- *
- * @param x the x coordinate of the area to draw
- * @param y the y coordinate of the area to draw
- * @param width the width of the area to draw
- * @param height the height of the area to draw
- * @param all <code>true</code> if children should redraw, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #update()
- * @see PaintListener
- * @see SWT#Paint
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#DOUBLE_BUFFERED
- */
-public void redraw (int x, int y, int width, int height, boolean all) {
- checkWidget ();
- if (width <= 0 || height <= 0) return;
- if (!OS.IsWindowVisible (handle)) return;
- RECT rect = new RECT ();
- OS.SetRect (rect, x, y, x + width, y + height);
- if (OS.IsWinCE) {
- OS.InvalidateRect (handle, rect, true);
- } else {
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE;
- if (all) flags |= OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, rect, 0, flags);
- }
-}
-
-boolean redrawChildren () {
- if (!OS.IsWindowVisible (handle)) return false;
- Control control = findBackgroundControl ();
- if (control == null) {
- if ((state & THEME_BACKGROUND) != 0) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- OS.InvalidateRect (handle, null, true);
- return true;
- }
- }
- } else {
- if (control.backgroundImage != null) {
- OS.InvalidateRect (handle, null, true);
- return true;
- }
- }
- return false;
-}
-
-void register () {
- display.addControl (handle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- handle = 0;
- parent = null;
-}
-
-void releaseParent () {
- parent.removeControl (this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (OS.IsDBLocale) {
- OS.ImmAssociateContext (handle, 0);
- }
- if (toolTipText != null) {
- setToolTipText (getShell (), null);
- }
- toolTipText = null;
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- backgroundImage = null;
- menu = null;
- cursor = null;
- unsubclass ();
- deregister ();
- layoutData = null;
- if (accessible != null) {
- accessible.internal_dispose_Accessible ();
- }
- accessible = null;
- region = null;
- font = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when a drag gesture occurs.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @since 3.3
- */
-public void removeDragDetectListener(DragDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.DragDetect, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control gains or loses focus.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see FocusListener
- * @see #addFocusListener
- */
-public void removeFocusListener(FocusListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.FocusIn, listener);
- eventTable.unhook (SWT.FocusOut, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #addKeyListener
- */
-public void removeKeyListener(KeyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.KeyUp, listener);
- eventTable.unhook (SWT.KeyDown, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the platform-specific context menu trigger has
- * occurred.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #addMenuDetectListener
- *
- * @since 3.3
- */
-public void removeMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MenuDetect, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse passes or hovers over controls.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseTrackListener
- * @see #addMouseTrackListener
- */
-public void removeMouseTrackListener(MouseTrackListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseEnter, listener);
- eventTable.unhook (SWT.MouseExit, listener);
- eventTable.unhook (SWT.MouseHover, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when mouse buttons are pressed and released.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseListener
- * @see #addMouseListener
- */
-public void removeMouseListener (MouseListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseDown, listener);
- eventTable.unhook (SWT.MouseUp, listener);
- eventTable.unhook (SWT.MouseDoubleClick, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse moves.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseMoveListener
- * @see #addMouseMoveListener
- */
-public void removeMouseMoveListener(MouseMoveListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseMove, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse wheel is scrolled.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseWheelListener
- * @see #addMouseWheelListener
- *
- * @since 3.3
- */
-public void removeMouseWheelListener (MouseWheelListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseWheel, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver needs to be painted.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see PaintListener
- * @see #addPaintListener
- */
-public void removePaintListener(PaintListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Paint, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when traversal events occur.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TraverseListener
- * @see #addTraverseListener
- */
-public void removeTraverseListener(TraverseListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Traverse, listener);
-}
-
-void showWidget (boolean visible) {
- int /*long*/ topHandle = topHandle ();
- OS.ShowWindow (topHandle, visible ? OS.SW_SHOW : OS.SW_HIDE);
- if (handle != topHandle) OS.ShowWindow (handle, visible ? OS.SW_SHOW : OS.SW_HIDE);
-}
-
-boolean sendFocusEvent (int type) {
- Shell shell = getShell ();
-
- /*
- * Feature in Windows. During the processing of WM_KILLFOCUS,
- * when the focus window is queried using GetFocus(), it has
- * already been assigned to the new window. The fix is to
- * remember the control that is losing or gaining focus and
- * answer it during WM_KILLFOCUS. If a WM_SETFOCUS occurs
- * during WM_KILLFOCUS, the focus control needs to be updated
- * to the current control. At any other time, the focus
- * control matches Windows.
- */
- Display display = this.display;
- display.focusEvent = type;
- display.focusControl = this;
- sendEvent (type);
- // widget could be disposed at this point
- display.focusEvent = SWT.None;
- display.focusControl = null;
-
- /*
- * It is possible that the shell may be
- * disposed at this point. If this happens
- * don't send the activate and deactivate
- * events.
- */
- if (!shell.isDisposed ()) {
- switch (type) {
- case SWT.FocusIn:
- shell.setActiveControl (this);
- break;
- case SWT.FocusOut:
- if (shell != display.getActiveShell ()) {
- shell.setActiveControl (null);
- }
- break;
- }
- }
- return true;
-}
-
-void sendMove () {
- sendEvent (SWT.Move);
-}
-
-void sendResize () {
- sendEvent (SWT.Resize);
-}
-
-void setBackground () {
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- if (control.backgroundImage != null) {
- Shell shell = getShell ();
- shell.releaseBrushes ();
- setBackgroundImage (control.backgroundImage.handle);
- } else {
- setBackgroundPixel (control.background == -1 ? control.defaultBackground() : control.background);
- }
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the control
- * if the argument is null.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on Windows the background of a Button cannot be changed.
- * </p>
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBackground (Color color) {
- checkWidget ();
- int pixel = -1;
- if (color != null) {
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- pixel = color.handle;
- }
- if (pixel == background) return;
- background = pixel;
- updateBackgroundColor ();
-}
-
-/**
- * Sets the receiver's background image to the image specified
- * by the argument, or to the default system color for the control
- * if the argument is null. The background image is tiled to fill
- * the available space.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on Windows the background of a Button cannot be changed.
- * </p>
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument is not a bitmap</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setBackgroundImage (Image image) {
- checkWidget ();
- if (image != null) {
- if (image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (image.type != SWT.BITMAP) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (backgroundImage == image) return;
- backgroundImage = image;
- Shell shell = getShell ();
- shell.releaseBrushes ();
- updateBackgroundImage ();
-}
-
-void setBackgroundImage (int /*long*/ hBitmap) {
- if (OS.IsWinCE) {
- OS.InvalidateRect (handle, null, true);
- } else {
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE;
- OS.RedrawWindow (handle, null, 0, flags);
- }
-}
-
-void setBackgroundPixel (int pixel) {
- if (OS.IsWinCE) {
- OS.InvalidateRect (handle, null, true);
- } else {
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE;
- OS.RedrawWindow (handle, null, 0, flags);
- }
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the arguments. The <code>x</code> and
- * <code>y</code> arguments are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the <code>x</code>
- * and <code>y</code> arguments are relative to the display.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (int x, int y, int width, int height) {
- checkWidget ();
- int flags = OS.SWP_NOZORDER | OS.SWP_DRAWFRAME | OS.SWP_NOACTIVATE;
- setBounds (x, y, Math.max (0, width), Math.max (0, height), flags);
-}
-
-void setBounds (int x, int y, int width, int height, int flags) {
- setBounds (x, y, width, height, flags, true);
-}
-
-void setBounds (int x, int y, int width, int height, int flags, boolean defer) {
- if (findImageControl () != null) {
- if (backgroundImage == null) flags |= OS.SWP_NOCOPYBITS;
- } else {
- if (OS.GetWindow (handle, OS.GW_CHILD) == 0) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- if (findThemeControl () != null) flags |= OS.SWP_NOCOPYBITS;
- }
- }
- }
- int /*long*/ topHandle = topHandle ();
- if (defer && parent != null) {
- forceResize ();
- if (parent.lpwp != null) {
- int index = 0;
- WINDOWPOS [] lpwp = parent.lpwp;
- while (index < lpwp.length) {
- if (lpwp [index] == null) break;
- index ++;
- }
- if (index == lpwp.length) {
- WINDOWPOS [] newLpwp = new WINDOWPOS [lpwp.length + 4];
- System.arraycopy (lpwp, 0, newLpwp, 0, lpwp.length);
- parent.lpwp = lpwp = newLpwp;
- }
- WINDOWPOS wp = new WINDOWPOS ();
- wp.hwnd = topHandle;
- wp.x = x;
- wp.y = y;
- wp.cx = width;
- wp.cy = height;
- wp.flags = flags;
- lpwp [index] = wp;
- return;
- }
- }
- SetWindowPos (topHandle, 0, x, y, width, height, flags);
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the argument. The <code>x</code> and
- * <code>y</code> fields of the rectangle are relative to
- * the receiver's parent (or its display if its parent is null).
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param rect the new bounds for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (Rectangle rect) {
- checkWidget ();
- if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * If the argument is <code>true</code>, causes the receiver to have
- * all mouse events delivered to it until the method is called with
- * <code>false</code> as the argument. Note that on some platforms,
- * a mouse button must currently be down for capture to be assigned.
- *
- * @param capture <code>true</code> to capture the mouse, and <code>false</code> to release it
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCapture (boolean capture) {
- checkWidget ();
- if (capture) {
- OS.SetCapture (handle);
- } else {
- if (OS.GetCapture () == handle) {
- OS.ReleaseCapture ();
- }
- }
-}
-
-void setCursor () {
- int /*long*/ lParam = OS.MAKELPARAM (OS.HTCLIENT, OS.WM_MOUSEMOVE);
- OS.SendMessage (handle, OS.WM_SETCURSOR, handle, lParam);
-}
-
-/**
- * Sets the receiver's cursor to the cursor specified by the
- * argument, or to the default cursor for that kind of control
- * if the argument is null.
- * <p>
- * When the mouse pointer passes over a control its appearance
- * is changed to match the control's cursor.
- * </p>
- *
- * @param cursor the new cursor (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCursor (Cursor cursor) {
- checkWidget ();
- if (cursor != null && cursor.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.cursor = cursor;
- if (OS.IsWinCE) {
- int /*long*/ hCursor = cursor != null ? cursor.handle : 0;
- OS.SetCursor (hCursor);
- return;
- }
- int /*long*/ hwndCursor = OS.GetCapture ();
- if (hwndCursor == 0) {
- POINT pt = new POINT ();
- if (!OS.GetCursorPos (pt)) return;
- int /*long*/ hwnd = hwndCursor = OS.WindowFromPoint (pt);
- while (hwnd != 0 && hwnd != handle) {
- hwnd = OS.GetParent (hwnd);
- }
- if (hwnd == 0) return;
- }
- Control control = display.getControl (hwndCursor);
- if (control == null) control = this;
- control.setCursor ();
-}
-
-void setDefaultFont () {
- int /*long*/ hFont = display.getSystemFont ().handle;
- OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);
-}
-
-/**
- * Sets the receiver's drag detect state. If the argument is
- * <code>true</code>, the receiver will detect drag gestures,
- * otherwise these gestures will be ignored.
- *
- * @param dragDetect the new drag detect state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public void setDragDetect (boolean dragDetect) {
- checkWidget ();
- if (dragDetect) {
- state |= DRAG_DETECT;
- } else {
- state &= ~DRAG_DETECT;
- }
- enableDrag (dragDetect);
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget ();
- /*
- * Feature in Windows. If the receiver has focus, disabling
- * the receiver causes no window to have focus. The fix is
- * to assign focus to the first ancestor window that takes
- * focus. If no window will take focus, set focus to the
- * desktop.
- */
- Control control = null;
- boolean fixFocus = false;
- if (!enabled) {
- if (display.focusEvent != SWT.FocusOut) {
- control = display.getFocusControl ();
- fixFocus = isFocusAncestor (control);
- }
- }
- enableWidget (enabled);
- if (fixFocus) fixFocus (control);
-}
-
-boolean setFixedFocus () {
- if ((style & SWT.NO_FOCUS) != 0) return false;
- return forceFocus ();
-}
-
-/**
- * Causes the receiver to have the <em>keyboard focus</em>,
- * such that all keyboard events will be delivered to it. Focus
- * reassignment will respect applicable platform constraints.
- *
- * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #forceFocus
- */
-public boolean setFocus () {
- checkWidget ();
- if ((style & SWT.NO_FOCUS) != 0) return false;
- return forceFocus ();
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * to the font specified by the argument, or to the default font for that
- * kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkWidget ();
- int /*long*/ hFont = 0;
- if (font != null) {
- if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- hFont = font.handle;
- }
- this.font = font;
- if (hFont == 0) hFont = defaultFont ();
- OS.SendMessage (handle, OS.WM_SETFONT, hFont, 1);
-}
-
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the control
- * if the argument is null.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * </p>
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setForeground (Color color) {
- checkWidget ();
- int pixel = -1;
- if (color != null) {
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- pixel = color.handle;
- }
- if (pixel == foreground) return;
- foreground = pixel;
- setForegroundPixel (pixel);
-}
-
-void setForegroundPixel (int pixel) {
- OS.InvalidateRect (handle, null, true);
-}
-
-/**
- * Sets the layout data associated with the receiver to the argument.
- *
- * @param layoutData the new layout data for the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLayoutData (Object layoutData) {
- checkWidget ();
- this.layoutData = layoutData;
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget ();
- int flags = OS.SWP_NOSIZE | OS.SWP_NOZORDER | OS.SWP_NOACTIVATE;
- /*
- * Feature in WinCE. The SWP_DRAWFRAME flag for SetWindowPos()
- * causes a WM_SIZE message to be sent even when the SWP_NOSIZE
- * flag is specified. The fix is to set SWP_DRAWFRAME only when
- * not running on WinCE.
- */
- if (!OS.IsWinCE) flags |= OS.SWP_DRAWFRAME;
- setBounds (x, y, 0, 0, flags);
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @param location the new location for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (Point location) {
- checkWidget ();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-/**
- * Sets the receiver's pop up menu to the argument.
- * All controls may optionally have a pop up
- * menu that is displayed when the user requests one for
- * the control. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pop up
- * menu is platform specific.
- * <p>
- * Note: Disposing of a control that has a pop up menu will
- * dispose of the menu. To avoid this behavior, set the
- * menu to null before the control is disposed.
- * </p>
- *
- * @param menu the new pop up menu
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenu (Menu menu) {
- checkWidget ();
- if (menu != null) {
- if (menu.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.POP_UP) == 0) {
- error (SWT.ERROR_MENU_NOT_POP_UP);
- }
- if (menu.parent != menuShell ()) {
- error (SWT.ERROR_INVALID_PARENT);
- }
- }
- this.menu = menu;
-}
-
-boolean setRadioFocus (boolean tabbing) {
- return false;
-}
-
-boolean setRadioSelection (boolean value) {
- return false;
-}
-
-/**
- * If the argument is <code>false</code>, causes subsequent drawing
- * operations in the receiver to be ignored. No drawing of any kind
- * can occur in the receiver until the flag is set to true.
- * Graphics operations that occurred while the flag was
- * <code>false</code> are lost. When the flag is set to <code>true</code>,
- * the entire widget is marked as needing to be redrawn. Nested calls
- * to this method are stacked.
- * <p>
- * Note: This operation is a hint and may not be supported on some
- * platforms or for some widgets.
- * </p>
- *
- * @param redraw the new redraw state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #redraw(int, int, int, int, boolean)
- * @see #update()
- */
-public void setRedraw (boolean redraw) {
- checkWidget ();
- /*
- * Feature in Windows. When WM_SETREDRAW is used to turn
- * off drawing in a widget, it clears the WS_VISIBLE bits
- * and then sets them when redraw is turned back on. This
- * means that WM_SETREDRAW will make a widget unexpectedly
- * visible. The fix is to track the visibility state while
- * drawing is turned off and restore it when drawing is
- * turned back on.
- */
- if (drawCount == 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.WS_VISIBLE) == 0) state |= HIDDEN;
- }
- if (redraw) {
- if (--drawCount == 0) {
- int /*long*/ topHandle = topHandle ();
- OS.SendMessage (topHandle, OS.WM_SETREDRAW, 1, 0);
- if (handle != topHandle) OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
- if ((state & HIDDEN) != 0) {
- state &= ~HIDDEN;
- OS.ShowWindow (topHandle, OS.SW_HIDE);
- if (handle != topHandle) OS.ShowWindow (handle, OS.SW_HIDE);
- } else {
- if (OS.IsWinCE) {
- OS.InvalidateRect (topHandle, null, true);
- if (handle != topHandle) OS.InvalidateRect (handle, null, true);
- } else {
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (topHandle, null, 0, flags);
- }
- }
- }
- } else {
- if (drawCount++ == 0) {
- int /*long*/ topHandle = topHandle ();
- OS.SendMessage (topHandle, OS.WM_SETREDRAW, 0, 0);
- if (handle != topHandle) OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- }
- }
-}
-
-/**
- * Sets the shape of the control to the region specified
- * by the argument. When the argument is null, the
- * default shape of the control is restored.
- *
- * @param region the region that defines the shape of the control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setRegion (Region region) {
- checkWidget ();
- if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- int /*long*/ hRegion = 0;
- if (region != null) {
- hRegion = OS.CreateRectRgn (0, 0, 0, 0);
- OS.CombineRgn (hRegion, region.handle, hRegion, OS.RGN_OR);
- }
- OS.SetWindowRgn (handle, hRegion, true);
- this.region = region;
-}
-
-boolean setSavedFocus () {
- return forceFocus ();
-}
-
-/**
- * Sets the receiver's size to the point specified by the arguments.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (int width, int height) {
- checkWidget ();
- int flags = OS.SWP_NOMOVE | OS.SWP_NOZORDER | OS.SWP_DRAWFRAME | OS.SWP_NOACTIVATE;
- setBounds (0, 0, Math.max (0, width), Math.max (0, height), flags);
-}
-
-/**
- * Sets the receiver's size to the point specified by the argument.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause them to be
- * set to zero instead.
- * </p>
- *
- * @param size the new size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (Point size) {
- checkWidget ();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSize (size.x, size.y);
-}
-
-boolean setTabItemFocus () {
- if (!isShowing ()) return false;
- return forceFocus ();
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget ();
- toolTipText = string;
- setToolTipText (getShell (), string);
-}
-
-void setToolTipText (Shell shell, String string) {
- shell.setToolTipText (handle, string);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- if (!getDrawing()) {
- if (((state & HIDDEN) == 0) == visible) return;
- } else {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if (((bits & OS.WS_VISIBLE) != 0) == visible) return;
- }
- if (visible) {
- sendEvent (SWT.Show);
- if (isDisposed ()) return;
- }
-
- /*
- * Feature in Windows. If the receiver has focus, hiding
- * the receiver causes no window to have focus. The fix is
- * to assign focus to the first ancestor window that takes
- * focus. If no window will take focus, set focus to the
- * desktop.
- */
- Control control = null;
- boolean fixFocus = false;
- if (!visible) {
- if (display.focusEvent != SWT.FocusOut) {
- control = display.getFocusControl ();
- fixFocus = isFocusAncestor (control);
- }
- }
- if (!getDrawing()) {
- state = visible ? state & ~HIDDEN : state | HIDDEN;
- } else {
- showWidget (visible);
- if (isDisposed ()) return;
- }
- if (!visible) {
- sendEvent (SWT.Hide);
- if (isDisposed ()) return;
- }
- if (fixFocus) fixFocus (control);
-}
-
-void sort (int [] items) {
- /* Shell Sort from K&R, pg 108 */
- int length = items.length;
- for (int gap=length/2; gap>0; gap/=2) {
- for (int i=gap; i<length; i++) {
- for (int j=i-gap; j>=0; j-=gap) {
- if (items [j] <= items [j + gap]) {
- int swap = items [j];
- items [j] = items [j + gap];
- items [j + gap] = swap;
- }
- }
- }
- }
-}
-
-void subclass () {
- int /*long*/ oldProc = windowProc ();
- int /*long*/ newProc = display.windowProc;
- if (oldProc == newProc) return;
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, newProc);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in display relative coordinates,
- * to coordinates relative to the receiver.
- * <p>
- * @param x the x coordinate to be translated
- * @param y the y coordinate to be translated
- * @return the translated coordinates
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public Point toControl (int x, int y) {
- checkWidget ();
- POINT pt = new POINT ();
- pt.x = x; pt.y = y;
- OS.ScreenToClient (handle, pt);
- return new Point (pt.x, pt.y);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in display relative coordinates,
- * to coordinates relative to the receiver.
- * <p>
- * @param point the point to be translated (must not be null)
- * @return the translated coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point toControl (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return toControl (point.x, point.y);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in coordinates relative to
- * the receiver, to display relative coordinates.
- * <p>
- * @param x the x coordinate to be translated
- * @param y the y coordinate to be translated
- * @return the translated coordinates
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public Point toDisplay (int x, int y) {
- checkWidget ();
- POINT pt = new POINT ();
- pt.x = x; pt.y = y;
- OS.ClientToScreen (handle, pt);
- return new Point (pt.x, pt.y);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in coordinates relative to
- * the receiver, to display relative coordinates.
- * <p>
- * @param point the point to be translated (must not be null)
- * @return the translated coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point toDisplay (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return toDisplay (point.x, point.y);
-}
-
-int /*long*/ topHandle () {
- return handle;
-}
-
-boolean translateAccelerator (MSG msg) {
- return menuShell ().translateAccelerator (msg);
-}
-
-boolean translateMnemonic (Event event, Control control) {
- if (control == this) return false;
- if (!isVisible () || !isEnabled ()) return false;
- event.doit = mnemonicMatch (event.character);
- return traverse (event);
-}
-
-boolean translateMnemonic (MSG msg) {
- if (msg.wParam < 0x20) return false;
- int /*long*/ hwnd = msg.hwnd;
- if (OS.GetKeyState (OS.VK_MENU) >= 0) {
- int /*long*/ code = OS.SendMessage (hwnd, OS.WM_GETDLGCODE, 0, 0);
- if ((code & OS.DLGC_WANTALLKEYS) != 0) return false;
- if ((code & OS.DLGC_BUTTON) == 0) return false;
- }
- Decorations shell = menuShell ();
- if (shell.isVisible () && shell.isEnabled ()) {
- display.lastAscii = (int)/*64*/msg.wParam;
- display.lastNull = display.lastDead = false;
- Event event = new Event ();
- event.detail = SWT.TRAVERSE_MNEMONIC;
- if (setKeyState (event, SWT.Traverse, msg.wParam, msg.lParam)) {
- return translateMnemonic (event, null) || shell.translateMnemonic (event, this);
- }
- }
- return false;
-}
-
-boolean translateTraversal (MSG msg) {
- int /*long*/ hwnd = msg.hwnd;
- int key = (int)/*64*/msg.wParam;
- if (key == OS.VK_MENU) {
- OS.SendMessage (hwnd, OS.WM_CHANGEUISTATE, OS.UIS_INITIALIZE, 0);
- return false;
- }
- int detail = SWT.TRAVERSE_NONE;
- boolean doit = true, all = false;
- boolean lastVirtual = false;
- int lastKey = key, lastAscii = 0;
- switch (key) {
- case OS.VK_ESCAPE: {
- all = true;
- lastAscii = 27;
- int /*long*/ code = OS.SendMessage (hwnd, OS.WM_GETDLGCODE, 0, 0);
- if ((code & OS.DLGC_WANTALLKEYS) != 0) {
- /*
- * Use DLGC_HASSETSEL to determine that the control
- * is a text widget. A text widget normally wants
- * all keys except VK_ESCAPE. If this bit is not
- * set, then assume the control wants all keys,
- * including VK_ESCAPE.
- */
- if ((code & OS.DLGC_HASSETSEL) == 0) doit = false;
- }
- detail = SWT.TRAVERSE_ESCAPE;
- break;
- }
- case OS.VK_RETURN: {
- all = true;
- lastAscii = '\r';
- int /*long*/ code = OS.SendMessage (hwnd, OS.WM_GETDLGCODE, 0, 0);
- if ((code & OS.DLGC_WANTALLKEYS) != 0) doit = false;
- detail = SWT.TRAVERSE_RETURN;
- break;
- }
- case OS.VK_TAB: {
- lastAscii = '\t';
- boolean next = OS.GetKeyState (OS.VK_SHIFT) >= 0;
- int /*long*/ code = OS.SendMessage (hwnd, OS.WM_GETDLGCODE, 0, 0);
- if ((code & (OS.DLGC_WANTTAB | OS.DLGC_WANTALLKEYS)) != 0) {
- /*
- * Use DLGC_HASSETSEL to determine that the control is a
- * text widget. If the control is a text widget, then
- * Ctrl+Tab and Shift+Tab should traverse out of the widget.
- * If the control is not a text widget, the correct behavior
- * is to give every character, including Tab, Ctrl+Tab and
- * Shift+Tab to the control.
- */
- if ((code & OS.DLGC_HASSETSEL) != 0) {
- if (next && OS.GetKeyState (OS.VK_CONTROL) >= 0) {
- doit = false;
- }
- } else {
- doit = false;
- }
- }
- detail = next ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS;
- break;
- }
- case OS.VK_UP:
- case OS.VK_LEFT:
- case OS.VK_DOWN:
- case OS.VK_RIGHT: {
- /*
- * On WinCE SP there is no tab key. Focus is assigned
- * using the VK_UP and VK_DOWN keys, not with VK_LEFT
- * or VK_RIGHT.
- */
- if (OS.IsSP) {
- if (key == OS.VK_LEFT || key == OS.VK_RIGHT) return false;
- }
- lastVirtual = true;
- int /*long*/ code = OS.SendMessage (hwnd, OS.WM_GETDLGCODE, 0, 0);
- if ((code & (OS.DLGC_WANTARROWS /*| OS.DLGC_WANTALLKEYS*/)) != 0) doit = false;
- boolean next = key == OS.VK_DOWN || key == OS.VK_RIGHT;
- if (parent != null && (parent.style & SWT.MIRRORED) != 0) {
- if (key == OS.VK_LEFT || key == OS.VK_RIGHT) next = !next;
- }
- detail = next ? SWT.TRAVERSE_ARROW_NEXT : SWT.TRAVERSE_ARROW_PREVIOUS;
- break;
- }
- case OS.VK_PRIOR:
- case OS.VK_NEXT: {
- all = true;
- lastVirtual = true;
- if (OS.GetKeyState (OS.VK_CONTROL) >= 0) return false;
- int /*long*/ code = OS.SendMessage (hwnd, OS.WM_GETDLGCODE, 0, 0);
- if ((code & OS.DLGC_WANTALLKEYS) != 0) {
- /*
- * Use DLGC_HASSETSEL to determine that the control is a
- * text widget. If the control is a text widget, then
- * Ctrl+PgUp and Ctrl+PgDn should traverse out of the widget.
- */
- if ((code & OS.DLGC_HASSETSEL) == 0) doit = false;
- }
- detail = key == OS.VK_PRIOR ? SWT.TRAVERSE_PAGE_PREVIOUS : SWT.TRAVERSE_PAGE_NEXT;
- break;
- }
- default:
- return false;
- }
- Event event = new Event ();
- event.doit = doit;
- event.detail = detail;
- display.lastKey = lastKey;
- display.lastAscii = lastAscii;
- display.lastVirtual = lastVirtual;
- display.lastNull = display.lastDead = false;
- if (!setKeyState (event, SWT.Traverse, msg.wParam, msg.lParam)) return false;
- Shell shell = getShell ();
- Control control = this;
- do {
- if (control.traverse (event)) {
- OS.SendMessage (hwnd, OS.WM_CHANGEUISTATE, OS.UIS_INITIALIZE, 0);
- return true;
- }
- if (!event.doit && control.hooks (SWT.Traverse)) return false;
- if (control == shell) return false;
- control = control.parent;
- } while (all && control != null);
- return false;
-}
-
-boolean traverse (Event event) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the traverse
- * event. If this happens, return true to stop further
- * event processing.
- */
- sendEvent (SWT.Traverse, event);
- if (isDisposed ()) return true;
- if (!event.doit) return false;
- switch (event.detail) {
- case SWT.TRAVERSE_NONE: return true;
- case SWT.TRAVERSE_ESCAPE: return traverseEscape ();
- case SWT.TRAVERSE_RETURN: return traverseReturn ();
- case SWT.TRAVERSE_TAB_NEXT: return traverseGroup (true);
- case SWT.TRAVERSE_TAB_PREVIOUS: return traverseGroup (false);
- case SWT.TRAVERSE_ARROW_NEXT: return traverseItem (true);
- case SWT.TRAVERSE_ARROW_PREVIOUS: return traverseItem (false);
- case SWT.TRAVERSE_MNEMONIC: return traverseMnemonic (event.character);
- case SWT.TRAVERSE_PAGE_NEXT: return traversePage (true);
- case SWT.TRAVERSE_PAGE_PREVIOUS: return traversePage (false);
- }
- return false;
-}
-
-/**
- * Based on the argument, perform one of the expected platform
- * traversal action. The argument should be one of the constants:
- * <code>SWT.TRAVERSE_ESCAPE</code>, <code>SWT.TRAVERSE_RETURN</code>,
- * <code>SWT.TRAVERSE_TAB_NEXT</code>, <code>SWT.TRAVERSE_TAB_PREVIOUS</code>,
- * <code>SWT.TRAVERSE_ARROW_NEXT</code> and <code>SWT.TRAVERSE_ARROW_PREVIOUS</code>.
- *
- * @param traversal the type of traversal
- * @return true if the traversal succeeded
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean traverse (int traversal) {
- checkWidget ();
- Event event = new Event ();
- event.doit = true;
- event.detail = traversal;
- return traverse (event);
-}
-
-boolean traverseEscape () {
- return false;
-}
-
-boolean traverseGroup (boolean next) {
- Control root = computeTabRoot ();
- Widget group = computeTabGroup ();
- Widget [] list = root.computeTabList ();
- int length = list.length;
- int index = 0;
- while (index < length) {
- if (list [index] == group) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- if (index == length) return false;
- int start = index, offset = (next) ? 1 : -1;
- while ((index = ((index + offset + length) % length)) != start) {
- Widget widget = list [index];
- if (!widget.isDisposed () && widget.setTabGroupFocus ()) {
- return true;
- }
- }
- if (group.isDisposed ()) return false;
- return group.setTabGroupFocus ();
-}
-
-boolean traverseItem (boolean next) {
- Control [] children = parent._getChildren ();
- int length = children.length;
- int index = 0;
- while (index < length) {
- if (children [index] == this) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- if (index == length) return false;
- int start = index, offset = (next) ? 1 : -1;
- while ((index = (index + offset + length) % length) != start) {
- Control child = children [index];
- if (!child.isDisposed () && child.isTabItem ()) {
- if (child.setTabItemFocus ()) return true;
- }
- }
- return false;
-}
-
-boolean traverseMnemonic (char key) {
- if (mnemonicHit (key)) {
- OS.SendMessage (handle, OS.WM_CHANGEUISTATE, OS.UIS_INITIALIZE, 0);
- return true;
- }
- return false;
-}
-
-boolean traversePage (boolean next) {
- return false;
-}
-
-boolean traverseReturn () {
- return false;
-}
-
-void unsubclass () {
- int /*long*/ newProc = windowProc ();
- int /*long*/ oldProc = display.windowProc;
- if (oldProc == newProc) return;
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, newProc);
-}
-
-/**
- * Forces all outstanding paint requests for the widget
- * to be processed before this method returns. If there
- * are no outstanding paint request, this method does
- * nothing.
- * <p>
- * Note: This method does not cause a redraw.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #redraw()
- * @see #redraw(int, int, int, int, boolean)
- * @see PaintListener
- * @see SWT#Paint
- */
-public void update () {
- checkWidget ();
- update (false);
-}
-
-void update (boolean all) {
-// checkWidget ();
- if (OS.IsWinCE) {
- OS.UpdateWindow (handle);
- } else {
- int flags = OS.RDW_UPDATENOW;
- if (all) flags |= OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, null, 0, flags);
- }
-}
-
-void updateBackgroundColor () {
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- setBackgroundPixel (control.background);
-}
-
-void updateBackgroundImage () {
- Control control = findBackgroundControl ();
- Image image = control != null ? control.backgroundImage : backgroundImage;
- setBackgroundImage (image != null ? image.handle : 0);
-}
-
-void updateBackgroundMode () {
- int oldState = state & PARENT_BACKGROUND;
- checkBackground ();
- if (oldState != (state & PARENT_BACKGROUND)) {
- setBackground ();
- }
-}
-
-void updateFont (Font oldFont, Font newFont) {
- if (getFont ().equals (oldFont)) setFont (newFont);
-}
-
-void updateImages () {
- /* Do nothing */
-}
-
-void updateLayout (boolean resize, boolean all) {
- /* Do nothing */
-}
-
-CREATESTRUCT widgetCreateStruct () {
- return null;
-}
-
-int widgetExtStyle () {
- int bits = 0;
- if (!OS.IsPPC) {
- if ((style & SWT.BORDER) != 0) bits |= OS.WS_EX_CLIENTEDGE;
- }
-// if ((style & SWT.BORDER) != 0) {
-// if ((style & SWT.FLAT) == 0) bits |= OS.WS_EX_CLIENTEDGE;
-// }
- /*
- * Feature in Windows NT. When CreateWindowEx() is called with
- * WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT, CreateWindowEx()
- * fails to create the HWND. The fix is to not use these bits.
- */
- if (OS.WIN32_VERSION < OS.VERSION (4, 10)) {
- return bits;
- }
- bits |= OS.WS_EX_NOINHERITLAYOUT;
- if ((style & SWT.RIGHT_TO_LEFT) != 0) bits |= OS.WS_EX_LAYOUTRTL;
- return bits;
-}
-
-int /*long*/ widgetParent () {
- return parent.handle;
-}
-
-int widgetStyle () {
- /* Force clipping of siblings by setting WS_CLIPSIBLINGS */
- int bits = OS.WS_CHILD | OS.WS_VISIBLE | OS.WS_CLIPSIBLINGS;
-// if ((style & SWT.BORDER) != 0) {
-// if ((style & SWT.FLAT) != 0) bits |= OS.WS_BORDER;
-// }
- if (OS.IsPPC) {
- if ((style & SWT.BORDER) != 0) bits |= OS.WS_BORDER;
- }
- return bits;
-
- /*
- * This code is intentionally commented. When clipping
- * of both siblings and children is not enforced, it is
- * possible for application code to draw outside of the
- * control.
- */
-// int bits = OS.WS_CHILD | OS.WS_VISIBLE;
-// if ((style & SWT.CLIP_SIBLINGS) != 0) bits |= OS.WS_CLIPSIBLINGS;
-// if ((style & SWT.CLIP_CHILDREN) != 0) bits |= OS.WS_CLIPCHILDREN;
-// return bits;
-}
-
-/**
- * Changes the parent of the widget to be the one provided if
- * the underlying operating system supports this feature.
- * Returns <code>true</code> if the parent is successfully changed.
- *
- * @param parent the new parent for the control.
- * @return <code>true</code> if the parent is changed and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * <li>ERROR_NULL_ARGUMENT - if the parent is <code>null</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean setParent (Composite parent) {
- checkWidget ();
- if (parent == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (parent.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.parent == parent) return true;
- if (!isReparentable ()) return false;
- releaseParent ();
- Shell newShell = parent.getShell (), oldShell = getShell ();
- Decorations newDecorations = parent.menuShell (), oldDecorations = menuShell ();
- if (oldShell != newShell || oldDecorations != newDecorations) {
- Menu [] menus = oldShell.findMenus (this);
- fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
- }
- int /*long*/ topHandle = topHandle ();
- if (OS.SetParent (topHandle, parent.handle) == 0) return false;
- this.parent = parent;
- int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE;
- SetWindowPos (topHandle, OS.HWND_BOTTOM, 0, 0, 0, 0, flags);
- return true;
-}
-
-abstract TCHAR windowClass ();
-
-abstract int /*long*/ windowProc ();
-
-int /*long*/ windowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = null;
- switch (msg) {
- case OS.WM_ACTIVATE: result = WM_ACTIVATE (wParam, lParam); break;
- case OS.WM_CAPTURECHANGED: result = WM_CAPTURECHANGED (wParam, lParam); break;
- case OS.WM_CHANGEUISTATE: result = WM_CHANGEUISTATE (wParam, lParam); break;
- case OS.WM_CHAR: result = WM_CHAR (wParam, lParam); break;
- case OS.WM_CLEAR: result = WM_CLEAR (wParam, lParam); break;
- case OS.WM_CLOSE: result = WM_CLOSE (wParam, lParam); break;
- case OS.WM_COMMAND: result = WM_COMMAND (wParam, lParam); break;
- case OS.WM_CONTEXTMENU: result = WM_CONTEXTMENU (wParam, lParam); break;
- case OS.WM_CTLCOLORBTN:
- case OS.WM_CTLCOLORDLG:
- case OS.WM_CTLCOLOREDIT:
- case OS.WM_CTLCOLORLISTBOX:
- case OS.WM_CTLCOLORMSGBOX:
- case OS.WM_CTLCOLORSCROLLBAR:
- case OS.WM_CTLCOLORSTATIC: result = WM_CTLCOLOR (wParam, lParam); break;
- case OS.WM_CUT: result = WM_CUT (wParam, lParam); break;
- case OS.WM_DESTROY: result = WM_DESTROY (wParam, lParam); break;
- case OS.WM_DRAWITEM: result = WM_DRAWITEM (wParam, lParam); break;
- case OS.WM_ENDSESSION: result = WM_ENDSESSION (wParam, lParam); break;
- case OS.WM_ENTERIDLE: result = WM_ENTERIDLE (wParam, lParam); break;
- case OS.WM_ERASEBKGND: result = WM_ERASEBKGND (wParam, lParam); break;
- case OS.WM_GETDLGCODE: result = WM_GETDLGCODE (wParam, lParam); break;
- case OS.WM_GETFONT: result = WM_GETFONT (wParam, lParam); break;
- case OS.WM_GETOBJECT: result = WM_GETOBJECT (wParam, lParam); break;
- case OS.WM_GETMINMAXINFO: result = WM_GETMINMAXINFO (wParam, lParam); break;
- case OS.WM_HELP: result = WM_HELP (wParam, lParam); break;
- case OS.WM_HSCROLL: result = WM_HSCROLL (wParam, lParam); break;
- case OS.WM_IME_CHAR: result = WM_IME_CHAR (wParam, lParam); break;
- case OS.WM_IME_COMPOSITION: result = WM_IME_COMPOSITION (wParam, lParam); break;
- case OS.WM_IME_COMPOSITION_START: result = WM_IME_COMPOSITION_START (wParam, lParam); break;
- case OS.WM_IME_ENDCOMPOSITION: result = WM_IME_ENDCOMPOSITION (wParam, lParam); break;
- case OS.WM_INITMENUPOPUP: result = WM_INITMENUPOPUP (wParam, lParam); break;
- case OS.WM_INPUTLANGCHANGE: result = WM_INPUTLANGCHANGE (wParam, lParam); break;
- case OS.WM_HOTKEY: result = WM_HOTKEY (wParam, lParam); break;
- case OS.WM_KEYDOWN: result = WM_KEYDOWN (wParam, lParam); break;
- case OS.WM_KEYUP: result = WM_KEYUP (wParam, lParam); break;
- case OS.WM_KILLFOCUS: result = WM_KILLFOCUS (wParam, lParam); break;
- case OS.WM_LBUTTONDBLCLK: result = WM_LBUTTONDBLCLK (wParam, lParam); break;
- case OS.WM_LBUTTONDOWN: result = WM_LBUTTONDOWN (wParam, lParam); break;
- case OS.WM_LBUTTONUP: result = WM_LBUTTONUP (wParam, lParam); break;
- case OS.WM_MBUTTONDBLCLK: result = WM_MBUTTONDBLCLK (wParam, lParam); break;
- case OS.WM_MBUTTONDOWN: result = WM_MBUTTONDOWN (wParam, lParam); break;
- case OS.WM_MBUTTONUP: result = WM_MBUTTONUP (wParam, lParam); break;
- case OS.WM_MEASUREITEM: result = WM_MEASUREITEM (wParam, lParam); break;
- case OS.WM_MENUCHAR: result = WM_MENUCHAR (wParam, lParam); break;
- case OS.WM_MENUSELECT: result = WM_MENUSELECT (wParam, lParam); break;
- case OS.WM_MOUSEACTIVATE: result = WM_MOUSEACTIVATE (wParam, lParam); break;
- case OS.WM_MOUSEHOVER: result = WM_MOUSEHOVER (wParam, lParam); break;
- case OS.WM_MOUSELEAVE: result = WM_MOUSELEAVE (wParam, lParam); break;
- case OS.WM_MOUSEMOVE: result = WM_MOUSEMOVE (wParam, lParam); break;
- case OS.WM_MOUSEWHEEL: result = WM_MOUSEWHEEL (wParam, lParam); break;
- case OS.WM_MOVE: result = WM_MOVE (wParam, lParam); break;
- case OS.WM_NCACTIVATE: result = WM_NCACTIVATE (wParam, lParam); break;
- case OS.WM_NCCALCSIZE: result = WM_NCCALCSIZE (wParam, lParam); break;
- case OS.WM_NCHITTEST: result = WM_NCHITTEST (wParam, lParam); break;
- case OS.WM_NCLBUTTONDOWN: result = WM_NCLBUTTONDOWN (wParam, lParam); break;
- case OS.WM_NCPAINT: result = WM_NCPAINT (wParam, lParam); break;
- case OS.WM_NOTIFY: result = WM_NOTIFY (wParam, lParam); break;
- case OS.WM_PAINT: result = WM_PAINT (wParam, lParam); break;
- case OS.WM_PALETTECHANGED: result = WM_PALETTECHANGED (wParam, lParam); break;
- case OS.WM_PARENTNOTIFY: result = WM_PARENTNOTIFY (wParam, lParam); break;
- case OS.WM_PASTE: result = WM_PASTE (wParam, lParam); break;
- case OS.WM_PRINT: result = WM_PRINT (wParam, lParam); break;
- case OS.WM_PRINTCLIENT: result = WM_PRINTCLIENT (wParam, lParam); break;
- case OS.WM_QUERYENDSESSION: result = WM_QUERYENDSESSION (wParam, lParam); break;
- case OS.WM_QUERYNEWPALETTE: result = WM_QUERYNEWPALETTE (wParam, lParam); break;
- case OS.WM_QUERYOPEN: result = WM_QUERYOPEN (wParam, lParam); break;
- case OS.WM_RBUTTONDBLCLK: result = WM_RBUTTONDBLCLK (wParam, lParam); break;
- case OS.WM_RBUTTONDOWN: result = WM_RBUTTONDOWN (wParam, lParam); break;
- case OS.WM_RBUTTONUP: result = WM_RBUTTONUP (wParam, lParam); break;
- case OS.WM_SETCURSOR: result = WM_SETCURSOR (wParam, lParam); break;
- case OS.WM_SETFOCUS: result = WM_SETFOCUS (wParam, lParam); break;
- case OS.WM_SETFONT: result = WM_SETFONT (wParam, lParam); break;
- case OS.WM_SETTINGCHANGE: result = WM_SETTINGCHANGE (wParam, lParam); break;
- case OS.WM_SETREDRAW: result = WM_SETREDRAW (wParam, lParam); break;
- case OS.WM_SHOWWINDOW: result = WM_SHOWWINDOW (wParam, lParam); break;
- case OS.WM_SIZE: result = WM_SIZE (wParam, lParam); break;
- case OS.WM_SYSCHAR: result = WM_SYSCHAR (wParam, lParam); break;
- case OS.WM_SYSCOLORCHANGE: result = WM_SYSCOLORCHANGE (wParam, lParam); break;
- case OS.WM_SYSCOMMAND: result = WM_SYSCOMMAND (wParam, lParam); break;
- case OS.WM_SYSKEYDOWN: result = WM_SYSKEYDOWN (wParam, lParam); break;
- case OS.WM_SYSKEYUP: result = WM_SYSKEYUP (wParam, lParam); break;
- case OS.WM_TIMER: result = WM_TIMER (wParam, lParam); break;
- case OS.WM_UNDO: result = WM_UNDO (wParam, lParam); break;
- case OS.WM_UPDATEUISTATE: result = WM_UPDATEUISTATE (wParam, lParam); break;
- case OS.WM_VSCROLL: result = WM_VSCROLL (wParam, lParam); break;
- case OS.WM_WINDOWPOSCHANGED: result = WM_WINDOWPOSCHANGED (wParam, lParam); break;
- case OS.WM_WINDOWPOSCHANGING: result = WM_WINDOWPOSCHANGING (wParam, lParam); break;
- case OS.WM_XBUTTONDBLCLK: result = WM_XBUTTONDBLCLK (wParam, lParam); break;
- case OS.WM_XBUTTONDOWN: result = WM_XBUTTONDOWN (wParam, lParam); break;
- case OS.WM_XBUTTONUP: result = WM_XBUTTONUP (wParam, lParam); break;
- }
- if (result != null) return result.value;
- return callWindowProc (hwnd, msg, wParam, lParam);
-}
-
-LRESULT WM_ACTIVATE (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_CAPTURECHANGED (int /*long*/ wParam, int /*long*/ lParam) {
- return wmCaptureChanged (handle, wParam, lParam);
-}
-
-LRESULT WM_CHANGEUISTATE (int /*long*/ wParam, int /*long*/ lParam) {
- if ((state & IGNORE_WM_CHANGEUISTATE) != 0) return LRESULT.ZERO;
- return null;
-}
-
-LRESULT WM_CHAR (int /*long*/ wParam, int /*long*/ lParam) {
- return wmChar (handle, wParam, lParam);
-}
-
-LRESULT WM_CLEAR (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_CLOSE (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_COMMAND (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * When the WM_COMMAND message is sent from a
- * menu, the HWND parameter in LPARAM is zero.
- */
- if (lParam == 0) {
- Decorations shell = menuShell ();
- if (shell.isEnabled ()) {
- int id = OS.LOWORD (wParam);
- MenuItem item = display.getMenuItem (id);
- if (item != null && item.isEnabled ()) {
- return item.wmCommandChild (wParam, lParam);
- }
- }
- return null;
- }
- Control control = display.getControl (lParam);
- if (control == null) return null;
- return control.wmCommandChild (wParam, lParam);
-}
-
-LRESULT WM_CONTEXTMENU (int /*long*/ wParam, int /*long*/ lParam) {
- return wmContextMenu (handle, wParam, lParam);
-}
-
-LRESULT WM_CTLCOLOR (int /*long*/ wParam, int /*long*/ lParam) {
- int /*long*/ hPalette = display.hPalette;
- if (hPalette != 0) {
- OS.SelectPalette (wParam, hPalette, false);
- OS.RealizePalette (wParam);
- }
- Control control = display.getControl (lParam);
- if (control == null) return null;
- return control.wmColorChild (wParam, lParam);
-}
-
-LRESULT WM_CUT (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_DESTROY (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_DRAWITEM (int /*long*/ wParam, int /*long*/ lParam) {
- DRAWITEMSTRUCT struct = new DRAWITEMSTRUCT ();
- OS.MoveMemory (struct, lParam, DRAWITEMSTRUCT.sizeof);
- if (struct.CtlType == OS.ODT_MENU) {
- MenuItem item = display.getMenuItem (struct.itemID);
- if (item == null) return null;
- return item.wmDrawChild (wParam, lParam);
- }
- Control control = display.getControl (struct.hwndItem);
- if (control == null) return null;
- return control.wmDrawChild (wParam, lParam);
-}
-
-LRESULT WM_ENDSESSION (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_ENTERIDLE (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_ERASEBKGND (int /*long*/ wParam, int /*long*/ lParam) {
- if ((state & DRAW_BACKGROUND) != 0) {
- if (findImageControl () != null) return LRESULT.ONE;
- }
- if ((state & THEME_BACKGROUND) != 0) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- if (findThemeControl () != null) return LRESULT.ONE;
- }
- }
- return null;
-}
-
-LRESULT WM_GETDLGCODE (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_GETFONT (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_GETOBJECT (int /*long*/ wParam, int /*long*/ lParam) {
- if (accessible != null) {
- int /*long*/ result = accessible.internal_WM_GETOBJECT (wParam, lParam);
- if (result != 0) return new LRESULT (result);
- }
- return null;
-}
-
-LRESULT WM_GETMINMAXINFO (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_HOTKEY (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_HELP (int /*long*/ wParam, int /*long*/ lParam) {
- if (OS.IsWinCE) return null;
- HELPINFO lphi = new HELPINFO ();
- OS.MoveMemory (lphi, lParam, HELPINFO.sizeof);
- Decorations shell = menuShell ();
- if (!shell.isEnabled ()) return null;
- if (lphi.iContextType == OS.HELPINFO_MENUITEM) {
- MenuItem item = display.getMenuItem (lphi.iCtrlId);
- if (item != null && item.isEnabled ()) {
- Widget widget = null;
- if (item.hooks (SWT.Help)) {
- widget = item;
- } else {
- Menu menu = item.parent;
- if (menu.hooks (SWT.Help)) widget = menu;
- }
- if (widget != null) {
- int /*long*/ hwndShell = shell.handle;
- OS.SendMessage (hwndShell, OS.WM_CANCELMODE, 0, 0);
- widget.postEvent (SWT.Help);
- return LRESULT.ONE;
- }
- }
- return null;
- }
- if (hooks (SWT.Help)) {
- postEvent (SWT.Help);
- return LRESULT.ONE;
- }
- return null;
-}
-
-LRESULT WM_HSCROLL (int /*long*/ wParam, int /*long*/ lParam) {
- Control control = display.getControl (lParam);
- if (control == null) return null;
- return control.wmScrollChild (wParam, lParam);
-}
-
-LRESULT WM_IME_CHAR (int /*long*/ wParam, int /*long*/ lParam) {
- return wmIMEChar (handle, wParam, lParam);
-}
-
-LRESULT WM_IME_COMPOSITION (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_IME_COMPOSITION_START (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_IME_ENDCOMPOSITION (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_INITMENUPOPUP (int /*long*/ wParam, int /*long*/ lParam) {
-
- /* Ignore WM_INITMENUPOPUP for an accelerator */
- if (display.accelKeyHit) return null;
-
- /*
- * If the high order word of LPARAM is non-zero,
- * the menu is the system menu and we can ignore
- * WPARAM. Otherwise, use WPARAM to find the menu.
- */
- Shell shell = getShell ();
- Menu oldMenu = shell.activeMenu, newMenu = null;
- if (OS.HIWORD (lParam) == 0) {
- newMenu = menuShell ().findMenu (wParam);
- if (newMenu != null) newMenu.update ();
- }
- Menu menu = newMenu;
- while (menu != null && menu != oldMenu) {
- menu = menu.getParentMenu ();
- }
- if (menu == null) {
- menu = shell.activeMenu;
- while (menu != null) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the hide
- * event. If this happens, stop searching up the
- * ancestor list because there is no longer a link
- * to follow.
- */
- menu.sendEvent (SWT.Hide);
- if (menu.isDisposed ()) break;
- menu = menu.getParentMenu ();
- Menu ancestor = newMenu;
- while (ancestor != null && ancestor != menu) {
- ancestor = ancestor.getParentMenu ();
- }
- if (ancestor != null) break;
- }
- }
-
- /*
- * The shell and the new menu may be disposed because of
- * sending the hide event to the ancestor menus but setting
- * a field to null in a disposed shell is not harmful.
- */
- if (newMenu != null && newMenu.isDisposed ()) newMenu = null;
- shell.activeMenu = newMenu;
-
- /* Send the show event */
- if (newMenu != null && newMenu != oldMenu) {
- newMenu.sendEvent (SWT.Show);
- // widget could be disposed at this point
- }
- return null;
-}
-
-LRESULT WM_INPUTLANGCHANGE (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_KEYDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- return wmKeyDown (handle, wParam, lParam);
-}
-
-LRESULT WM_KEYUP (int /*long*/ wParam, int /*long*/ lParam) {
- return wmKeyUp (handle, wParam, lParam);
-}
-
-LRESULT WM_KILLFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- return wmKillFocus (handle, wParam, lParam);
-}
-
-LRESULT WM_LBUTTONDBLCLK (int /*long*/ wParam, int /*long*/ lParam) {
- return wmLButtonDblClk (handle, wParam, lParam);
-}
-
-LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- return wmLButtonDown (handle, wParam, lParam);
-}
-
-LRESULT WM_LBUTTONUP (int /*long*/ wParam, int /*long*/ lParam) {
- return wmLButtonUp (handle, wParam, lParam);
-}
-
-LRESULT WM_MBUTTONDBLCLK (int /*long*/ wParam, int /*long*/ lParam) {
- return wmMButtonDblClk (handle, wParam, lParam);
-}
-
-LRESULT WM_MBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- return wmMButtonDown (handle, wParam, lParam);
-}
-
-LRESULT WM_MBUTTONUP (int /*long*/ wParam, int /*long*/ lParam) {
- return wmMButtonUp (handle, wParam, lParam);
-}
-
-LRESULT WM_MEASUREITEM (int /*long*/ wParam, int /*long*/ lParam) {
- MEASUREITEMSTRUCT struct = new MEASUREITEMSTRUCT ();
- OS.MoveMemory (struct, lParam, MEASUREITEMSTRUCT.sizeof);
- if (struct.CtlType == OS.ODT_MENU) {
- MenuItem item = display.getMenuItem (struct.itemID);
- if (item == null) return null;
- return item.wmMeasureChild (wParam, lParam);
- }
- int /*long*/ hwnd = OS.GetDlgItem (handle, struct.CtlID);
- Control control = display.getControl (hwnd);
- if (control == null) return null;
- return control.wmMeasureChild (wParam, lParam);
-}
-
-LRESULT WM_MENUCHAR (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. When the user types Alt+<key>
- * and <key> does not match a mnemonic in the System
- * menu or the menu bar, Windows beeps. This beep is
- * unexpected and unwanted by applications that look
- * for Alt+<key>. The fix is to detect the case and
- * stop Windows from beeping by closing the menu.
- */
- int type = OS.HIWORD (wParam);
- if (type == 0 || type == OS.MF_SYSMENU) {
- display.mnemonicKeyHit = false;
- return new LRESULT (OS.MAKELRESULT (0, OS.MNC_CLOSE));
- }
- return null;
-}
-
-LRESULT WM_MENUSELECT (int /*long*/ wParam, int /*long*/ lParam) {
- int code = OS.HIWORD (wParam);
- Shell shell = getShell ();
- if (code == 0xFFFF && lParam == 0) {
- Menu menu = shell.activeMenu;
- while (menu != null) {
- /*
- * When the user cancels any menu that is not the
- * menu bar, assume a mnemonic key was pressed to open
- * the menu from WM_SYSCHAR. When the menu was invoked
- * using the mouse, this assumption is wrong but not
- * harmful. This variable is only used in WM_SYSCHAR
- * and WM_SYSCHAR is only sent after the user has pressed
- * a mnemonic.
- */
- display.mnemonicKeyHit = true;
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the hide
- * event. If this happens, stop searching up the
- * parent list because there is no longer a link
- * to follow.
- */
- menu.sendEvent (SWT.Hide);
- if (menu.isDisposed ()) break;
- menu = menu.getParentMenu ();
- }
- /*
- * The shell may be disposed because of sending the hide
- * event to the last active menu menu but setting a field
- * to null in a destroyed widget is not harmful.
- */
- shell.activeMenu = null;
- return null;
- }
- if ((code & OS.MF_SYSMENU) != 0) return null;
- if ((code & OS.MF_HILITE) != 0) {
- MenuItem item = null;
- Decorations menuShell = menuShell ();
- if ((code & OS.MF_POPUP) != 0) {
- int index = OS.LOWORD (wParam);
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- info.fMask = OS.MIIM_SUBMENU;
- if (OS.GetMenuItemInfo (lParam, index, true, info)) {
- Menu newMenu = menuShell.findMenu (info.hSubMenu);
- if (newMenu != null) item = newMenu.cascade;
- }
- } else {
- Menu newMenu = menuShell.findMenu (lParam);
- if (newMenu != null) {
- int id = OS.LOWORD (wParam);
- item = display.getMenuItem (id);
- }
- Menu oldMenu = shell.activeMenu;
- if (oldMenu != null) {
- Menu ancestor = oldMenu;
- while (ancestor != null && ancestor != newMenu) {
- ancestor = ancestor.getParentMenu ();
- }
- if (ancestor == newMenu) {
- ancestor = oldMenu;
- while (ancestor != newMenu) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the hide
- * event or the item about to be armed. If this
- * happens, stop searching up the ancestor list
- * because there is no longer a link to follow.
- */
- ancestor.sendEvent (SWT.Hide);
- if (ancestor.isDisposed ()) break;
- ancestor = ancestor.getParentMenu ();
- if (ancestor == null) break;
- }
- /*
- * The shell and/or the item could be disposed when
- * processing hide events from above. If this happens,
- * ensure that the shell is not accessed and that no
- * arm event is sent to the item.
- */
- if (!shell.isDisposed ()) {
- if (newMenu != null && newMenu.isDisposed ()) {
- newMenu = null;
- }
- shell.activeMenu = newMenu;
- }
- if (item != null && item.isDisposed ()) item = null;
- }
- }
- }
- if (item != null) item.sendEvent (SWT.Arm);
- }
- return null;
-}
-
-LRESULT WM_MOUSEACTIVATE (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_MOUSEHOVER (int /*long*/ wParam, int /*long*/ lParam) {
- return wmMouseHover (handle, wParam, lParam);
-}
-
-LRESULT WM_MOUSELEAVE (int /*long*/ wParam, int /*long*/ lParam) {
- if (OS.COMCTL32_MAJOR >= 6) getShell ().fixToolTip ();
- return wmMouseLeave (handle, wParam, lParam);
-}
-
-LRESULT WM_MOUSEMOVE (int /*long*/ wParam, int /*long*/ lParam) {
- return wmMouseMove (handle, wParam, lParam);
-}
-
-LRESULT WM_MOUSEWHEEL (int /*long*/ wParam, int /*long*/ lParam) {
- return wmMouseWheel (handle, wParam, lParam);
-}
-
-LRESULT WM_MOVE (int /*long*/ wParam, int /*long*/ lParam) {
- state |= MOVE_OCCURRED;
- if (findImageControl () != null) {
- if (this != getShell ()) redrawChildren ();
- } else {
- if ((state & THEME_BACKGROUND) != 0) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- if (OS.IsWindowVisible (handle)) {
- if (findThemeControl () != null) redrawChildren ();
- }
- }
- }
- }
- if ((state & MOVE_DEFERRED) == 0) sendEvent (SWT.Move);
- // widget could be disposed at this point
- return null;
-}
-
-LRESULT WM_NCACTIVATE (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_NCCALCSIZE (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_NCHITTEST (int /*long*/ wParam, int /*long*/ lParam) {
- if (!OS.IsWindowEnabled (handle)) return null;
- if (!isActive ()) return new LRESULT (OS.HTTRANSPARENT);
- return null;
-}
-
-LRESULT WM_NCLBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_NCPAINT (int /*long*/ wParam, int /*long*/ lParam) {
- return wmNCPaint (handle, wParam, lParam);
-}
-
-LRESULT WM_NOTIFY (int /*long*/ wParam, int /*long*/ lParam) {
- NMHDR hdr = new NMHDR ();
- OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
- return wmNotify (hdr, wParam, lParam);
-}
-
-LRESULT WM_PAINT (int /*long*/ wParam, int /*long*/ lParam) {
- return wmPaint (handle, wParam, lParam);
-}
-
-LRESULT WM_PALETTECHANGED (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_PARENTNOTIFY (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_PASTE (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_PRINT (int /*long*/ wParam, int /*long*/ lParam) {
- return wmPrint (handle, wParam, lParam);
-}
-
-LRESULT WM_PRINTCLIENT (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_QUERYENDSESSION (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_QUERYNEWPALETTE (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_QUERYOPEN (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_RBUTTONDBLCLK (int /*long*/ wParam, int /*long*/ lParam) {
- return wmRButtonDblClk (handle, wParam, lParam);
-}
-
-LRESULT WM_RBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- return wmRButtonDown (handle, wParam, lParam);
-}
-
-LRESULT WM_RBUTTONUP (int /*long*/ wParam, int /*long*/ lParam) {
- return wmRButtonUp (handle, wParam, lParam);
-}
-
-LRESULT WM_SETCURSOR (int /*long*/ wParam, int /*long*/ lParam) {
- int hitTest = (short) OS.LOWORD (lParam);
- if (hitTest == OS.HTCLIENT) {
- Control control = display.getControl (wParam);
- if (control == null) return null;
- Cursor cursor = control.findCursor ();
- if (cursor != null) {
- OS.SetCursor (cursor.handle);
- return LRESULT.ONE;
- }
- }
- return null;
-}
-
-LRESULT WM_SETFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- return wmSetFocus (handle, wParam, lParam);
-}
-
-LRESULT WM_SETTINGCHANGE (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_SETFONT (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_SETREDRAW (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_SHOWWINDOW (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- state |= RESIZE_OCCURRED;
- if ((state & RESIZE_DEFERRED) == 0) sendEvent (SWT.Resize);
- // widget could be disposed at this point
- return null;
-}
-
-LRESULT WM_SYSCHAR (int /*long*/ wParam, int /*long*/ lParam) {
- return wmSysChar (handle, wParam, lParam);
-}
-
-LRESULT WM_SYSCOLORCHANGE (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_SYSCOMMAND (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Check to see if the command is a system command or
- * a user menu item that was added to the System menu.
- * When a user item is added to the System menu,
- * WM_SYSCOMMAND must always return zero.
- *
- * NOTE: This is undocumented.
- */
- if ((wParam & 0xF000) == 0) {
- Decorations shell = menuShell ();
- if (shell.isEnabled ()) {
- MenuItem item = display.getMenuItem (OS.LOWORD (wParam));
- if (item != null) item.wmCommandChild (wParam, lParam);
- }
- return LRESULT.ZERO;
- }
-
- /* Process the System Command */
- int cmd = (int)/*64*/wParam & 0xFFF0;
- switch (cmd) {
- case OS.SC_CLOSE:
- int /*long*/ hwndShell = menuShell ().handle;
- int bits = OS.GetWindowLong (hwndShell, OS.GWL_STYLE);
- if ((bits & OS.WS_SYSMENU) == 0) return LRESULT.ZERO;
- break;
- case OS.SC_KEYMENU:
- /*
- * When lParam is zero, one of F10, Shift+F10, Ctrl+F10 or
- * Ctrl+Shift+F10 was pressed. If there is no menu bar and
- * the focus control is interested in keystrokes, give the
- * key to the focus control. Normally, F10 with no menu bar
- * moves focus to the System menu but this can be achieved
- * using Alt+Space. To allow the application to see F10,
- * avoid running the default window proc.
- *
- * NOTE: When F10 is pressed, WM_SYSCOMMAND is sent to the
- * shell, not the focus control. This is undocumented Windows
- * behavior.
- */
- if (lParam == 0) {
- Decorations shell = menuShell ();
- Menu menu = shell.getMenuBar ();
- if (menu == null) {
- Control control = display._getFocusControl ();
- if (control != null) {
- if (control.hooks (SWT.KeyDown) || control.hooks (SWT.KeyUp)) {
- display.mnemonicKeyHit = false;
- return LRESULT.ZERO;
- }
- }
- }
- } else {
- /*
- * When lParam is not zero, Alt+<key> was pressed. If the
- * application is interested in keystrokes and there is a
- * menu bar, check to see whether the key that was pressed
- * matches a mnemonic on the menu bar. Normally, Windows
- * matches the first character of a menu item as well as
- * matching the mnemonic character. To allow the application
- * to see the keystrokes in this case, avoid running the default
- * window proc.
- *
- * NOTE: When the user types Alt+Space, the System menu is
- * activated. In this case the application should not see
- * the keystroke.
- */
- if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) {
- if (lParam != ' ') {
- Decorations shell = menuShell ();
- Menu menu = shell.getMenuBar ();
- if (menu != null) {
- char key = Display.mbcsToWcs ((int)/*64*/lParam);
- if (key != 0) {
- key = Character.toUpperCase (key);
- MenuItem [] items = menu.getItems ();
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- String text = item.getText ();
- char mnemonic = findMnemonic (text);
- if (text.length () > 0 && mnemonic == 0) {
- char ch = text.charAt (0);
- if (Character.toUpperCase (ch) == key) {
- display.mnemonicKeyHit = false;
- return LRESULT.ZERO;
- }
- }
- }
- }
- } else {
- display.mnemonicKeyHit = false;
- }
- }
- }
- }
- // FALL THROUGH
- case OS.SC_HSCROLL:
- case OS.SC_VSCROLL:
- /*
- * Do not allow keyboard traversal of the menu bar
- * or scrolling when the shell is not enabled.
- */
- Decorations shell = menuShell ();
- if (!shell.isEnabled () || !shell.isActive ()) {
- return LRESULT.ZERO;
- }
- break;
- case OS.SC_MINIMIZE:
- /* Save the focus widget when the shell is minimized */
- menuShell ().saveFocus ();
- break;
- }
- return null;
-}
-
-LRESULT WM_SYSKEYDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- return wmSysKeyDown (handle, wParam, lParam);
-}
-
-LRESULT WM_SYSKEYUP (int /*long*/ wParam, int /*long*/ lParam) {
- return wmSysKeyUp (handle, wParam, lParam);
-}
-
-LRESULT WM_TIMER (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_UNDO (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_UPDATEUISTATE (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_VSCROLL (int /*long*/ wParam, int /*long*/ lParam) {
- Control control = display.getControl (lParam);
- if (control == null) return null;
- return control.wmScrollChild (wParam, lParam);
-}
-
-LRESULT WM_WINDOWPOSCHANGED (int /*long*/ wParam, int /*long*/ lParam) {
- try {
- display.resizeCount++;
- int /*long*/ code = callWindowProc (handle, OS.WM_WINDOWPOSCHANGED, wParam, lParam);
- return code == 0 ? LRESULT.ZERO : new LRESULT (code);
- } finally {
- --display.resizeCount;
- }
-}
-
-LRESULT WM_WINDOWPOSCHANGING (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Bug in Windows. When WM_SETREDRAW is used to turn off drawing
- * for a control and the control is moved or resized, Windows does
- * not redraw the area where the control once was in the parent.
- * The fix is to detect this case and redraw the area.
- */
- if (!getDrawing()) {
- Shell shell = getShell ();
- if (shell != this) {
- WINDOWPOS lpwp = new WINDOWPOS ();
- OS.MoveMemory (lpwp, lParam, WINDOWPOS.sizeof);
- if ((lpwp.flags & OS.SWP_NOMOVE) == 0 || (lpwp.flags & OS.SWP_NOSIZE) == 0) {
- RECT rect = new RECT ();
- OS.GetWindowRect (topHandle (), rect);
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- if (width != 0 && height != 0) {
- int /*long*/ hwndParent = parent == null ? 0 : parent.handle;
- OS.MapWindowPoints (0, hwndParent, rect, 2);
- if (OS.IsWinCE) {
- OS.InvalidateRect (hwndParent, rect, true);
- } else {
- int /*long*/ rgn1 = OS.CreateRectRgn (rect.left, rect.top, rect.right, rect.bottom);
- int /*long*/ rgn2 = OS.CreateRectRgn (lpwp.x, lpwp.y, lpwp.x + lpwp.cx, lpwp.y + lpwp.cy);
- OS.CombineRgn (rgn1, rgn1, rgn2, OS.RGN_DIFF);
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (hwndParent, null, rgn1, flags);
- OS.DeleteObject (rgn1);
- OS.DeleteObject (rgn2);
- }
- }
- }
- }
- }
- return null;
-}
-
-LRESULT WM_XBUTTONDBLCLK (int /*long*/ wParam, int /*long*/ lParam) {
- return wmXButtonDblClk (handle, wParam, lParam);
-}
-
-LRESULT WM_XBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- return wmXButtonDown (handle, wParam, lParam);
-}
-
-LRESULT WM_XBUTTONUP (int /*long*/ wParam, int /*long*/ lParam) {
- return wmXButtonUp (handle, wParam, lParam);
-}
-
-LRESULT wmColorChild (int /*long*/ wParam, int /*long*/ lParam) {
- Control control = findBackgroundControl ();
- if (control == null) {
- if ((state & THEME_BACKGROUND) != 0) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- control = findThemeControl ();
- if (control != null) {
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- OS.SetTextColor (wParam, getForegroundPixel ());
- OS.SetBkColor (wParam, getBackgroundPixel ());
- fillThemeBackground (wParam, control, rect);
- OS.SetBkMode (wParam, OS.TRANSPARENT);
- return new LRESULT (OS.GetStockObject (OS.NULL_BRUSH));
- }
- }
- }
- if (foreground == -1) return null;
- }
- if (control == null) control = this;
- int forePixel = getForegroundPixel ();
- int backPixel = control.getBackgroundPixel ();
- OS.SetTextColor (wParam, forePixel);
- OS.SetBkColor (wParam, backPixel);
- if (control.backgroundImage != null) {
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- int /*long*/ hwnd = control.handle;
- int /*long*/ hBitmap = control.backgroundImage.handle;
- OS.MapWindowPoints (handle, hwnd, rect, 2);
- POINT lpPoint = new POINT ();
- OS.GetWindowOrgEx (wParam, lpPoint);
- OS.SetBrushOrgEx (wParam, -rect.left - lpPoint.x, -rect.top - lpPoint.y, lpPoint);
- int /*long*/ hBrush = findBrush (hBitmap, OS.BS_PATTERN);
- if ((state & DRAW_BACKGROUND) != 0) {
- int /*long*/ hOldBrush = OS.SelectObject (wParam, hBrush);
- OS.MapWindowPoints (hwnd, handle, rect, 2);
- OS.PatBlt (wParam, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, OS.PATCOPY);
- OS.SelectObject (wParam, hOldBrush);
- }
- OS.SetBkMode (wParam, OS.TRANSPARENT);
- return new LRESULT (hBrush);
- }
- int /*long*/ hBrush = findBrush (backPixel, OS.BS_SOLID);
- if ((state & DRAW_BACKGROUND) != 0) {
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- int /*long*/ hOldBrush = OS.SelectObject (wParam, hBrush);
- OS.PatBlt (wParam, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, OS.PATCOPY);
- OS.SelectObject (wParam, hOldBrush);
- }
- return new LRESULT (hBrush);
-}
-
-LRESULT wmCommandChild (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT wmDrawChild (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT wmMeasureChild (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT wmNotify (NMHDR hdr, int /*long*/ wParam, int /*long*/ lParam) {
- Control control = display.getControl (hdr.hwndFrom);
- if (control == null) return null;
- return control.wmNotifyChild (hdr, wParam, lParam);
-}
-
-LRESULT wmNotifyChild (NMHDR hdr, int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT wmScrollChild (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolBar.java
deleted file mode 100755
index 9e22db925b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolBar.java
+++ /dev/null
@@ -1,1195 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide an area for dynamically
- * positioning the items they contain.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>CoolItem</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add <code>Control</code> children to it,
- * or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>FLAT, HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#coolbar">CoolBar snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class CoolBar extends Composite {
- CoolItem [] items;
- CoolItem [] originalItems;
- boolean locked;
- boolean ignoreResize;
- static final int /*long*/ ReBarProc;
- static final TCHAR ReBarClass = new TCHAR (0, OS.REBARCLASSNAME, true);
- static {
- INITCOMMONCONTROLSEX icex = new INITCOMMONCONTROLSEX ();
- icex.dwSize = INITCOMMONCONTROLSEX.sizeof;
- icex.dwICC = OS.ICC_COOL_CLASSES;
- OS.InitCommonControlsEx (icex);
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, ReBarClass, lpWndClass);
- ReBarProc = lpWndClass.lpfnWndProc;
- }
- static final int SEPARATOR_WIDTH = 2;
- static final int MAX_WIDTH = 0x7FFF;
- static final int DEFAULT_COOLBAR_WIDTH = 0;
- static final int DEFAULT_COOLBAR_HEIGHT = 0;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see SWT#FLAT
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public CoolBar (Composite parent, int style) {
- super (parent, checkStyle (style));
- /*
- * Ensure that either of HORIZONTAL or VERTICAL is set.
- * NOTE: HORIZONTAL and VERTICAL have the same values
- * as H_SCROLL and V_SCROLL so it is necessary to first
- * clear these bits to avoid scroll bars and then reset
- * the bits using the original style supplied by the
- * programmer.
- *
- * NOTE: The CCS_VERT style cannot be applied when the
- * widget is created because of this conflict.
- */
- if ((style & SWT.VERTICAL) != 0) {
- this.style |= SWT.VERTICAL;
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits | OS.CCS_VERT);
- } else {
- this.style |= SWT.HORIZONTAL;
- }
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (ReBarProc, hwnd, msg, wParam, lParam);
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0;
- int border = getBorderWidth ();
- int newWidth = wHint == SWT.DEFAULT ? 0x3FFF : wHint + (border * 2);
- int newHeight = hHint == SWT.DEFAULT ? 0x3FFF : hHint + (border * 2);
- int count = (int)/*64*/OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
- if (count != 0) {
- ignoreResize = true;
- boolean redraw = false;
- if (OS.IsWindowVisible (handle)) {
- if (OS.COMCTL32_MAJOR >= 6) {
- redraw = true;
- OS.UpdateWindow (handle);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- } else {
- redraw = getDrawing();
- if (redraw) {
- OS.UpdateWindow (handle);
- OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- }
- }
- }
- RECT oldRect = new RECT ();
- OS.GetWindowRect (handle, oldRect);
- int oldWidth = oldRect.right - oldRect.left;
- int oldHeight = oldRect.bottom - oldRect.top;
- int flags = OS.SWP_NOACTIVATE | OS.SWP_NOMOVE | OS.SWP_NOREDRAW | OS.SWP_NOZORDER;
- SetWindowPos (handle, 0, 0, 0, newWidth, newHeight, flags);
- RECT rect = new RECT ();
- OS.SendMessage (handle, OS.RB_GETRECT, count - 1, rect);
- height = Math.max (height, rect.bottom);
- SetWindowPos (handle, 0, 0, 0, oldWidth, oldHeight, flags);
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_IDEALSIZE | OS.RBBIM_STYLE;
- int rowWidth = 0;
- for (int i = 0; i < count; i++) {
- OS.SendMessage(handle, OS.RB_GETBANDINFO, i, rbBand);
- if ((rbBand.fStyle & OS.RBBS_BREAK) != 0) {
- width = Math.max(width, rowWidth);
- rowWidth = 0;
- }
- rowWidth += rbBand.cxIdeal + getMargin (i);
- }
- width = Math.max(width, rowWidth);
- if (redraw) {
- if (OS.COMCTL32_MAJOR >= 6) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- } else {
- OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
- }
- }
- ignoreResize = false;
- }
- if (width == 0) width = DEFAULT_COOLBAR_WIDTH;
- if (height == 0) height = DEFAULT_COOLBAR_HEIGHT;
- if ((style & SWT.VERTICAL) != 0) {
- int tmp = width;
- width = height;
- height = tmp;
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- height += border * 2;
- width += border * 2;
- return new Point (width, height);
-}
-
-void createHandle () {
- super.createHandle ();
- state &= ~(CANVAS | THEME_BACKGROUND);
-
- /*
- * Feature in Windows. When the control is created,
- * it does not use the default system font. A new HFONT
- * is created and destroyed when the control is destroyed.
- * This means that a program that queries the font from
- * this control, uses the font in another control and then
- * destroys this control will have the font unexpectedly
- * destroyed in the other control. The fix is to assign
- * the font ourselves each time the control is created.
- * The control will not destroy a font that it did not
- * create.
- */
- int /*long*/ hFont = OS.GetStockObject (OS.SYSTEM_FONT);
- OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);
-}
-
-void createItem (CoolItem item, int index) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
- if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
- int id = 0;
- while (id < items.length && items [id] != null) id++;
- if (id == items.length) {
- CoolItem [] newItems = new CoolItem [items.length + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- int /*long*/ hHeap = OS.GetProcessHeap ();
- int /*long*/ lpText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof);
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_TEXT | OS.RBBIM_STYLE | OS.RBBIM_ID;
- rbBand.fStyle = OS.RBBS_VARIABLEHEIGHT | OS.RBBS_GRIPPERALWAYS;
- if ((item.style & SWT.DROP_DOWN) != 0) {
- rbBand.fStyle |= OS.RBBS_USECHEVRON;
- }
- rbBand.lpText = lpText;
- rbBand.wID = id;
-
- /*
- * Feature in Windows. When inserting an item at end of a row,
- * sometimes, Windows will begin to place the item on the right
- * side of the cool bar. The fix is to resize the new items to
- * the maximum size and then resize the next to last item to the
- * ideal size.
- */
- int lastIndex = getLastIndexOfRow (index - 1);
- boolean fixLast = index == lastIndex + 1;
- if (fixLast) {
- rbBand.fMask |= OS.RBBIM_SIZE;
- rbBand.cx = MAX_WIDTH;
- }
-
- /*
- * Feature in Windows. Is possible that the item at index zero
- * has the RBBS_BREAK flag set. When a new item is inserted at
- * position zero, the previous item at position zero moves to
- * a new line. The fix is to detect this case and clear the
- * RBBS_BREAK flag on the previous item before inserting the
- * new item.
- */
- if (index == 0 && count > 0) {
- getItem (0).setWrap (false);
- }
-
- /* Insert the item */
- if (OS.SendMessage (handle, OS.RB_INSERTBAND, index, rbBand) == 0) {
- error (SWT.ERROR_ITEM_NOT_ADDED);
- }
-
- /* Resize the next to last item to the ideal size */
- if (fixLast) {
- resizeToPreferredWidth (lastIndex);
- }
-
- OS.HeapFree (hHeap, 0, lpText);
- items [item.id = id] = item;
- int length = originalItems.length;
- CoolItem [] newOriginals = new CoolItem [length + 1];
- System.arraycopy (originalItems, 0, newOriginals, 0, index);
- System.arraycopy (originalItems, index, newOriginals, index + 1, length - index);
- newOriginals [index] = item;
- originalItems = newOriginals;
-}
-
-void createWidget () {
- super.createWidget ();
- items = new CoolItem [4];
- originalItems = new CoolItem [0];
-}
-
-void destroyItem (CoolItem item) {
- int index = (int)/*64*/OS.SendMessage (handle, OS.RB_IDTOINDEX, item.id, 0);
- int count = (int)/*64*/OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
- if (count != 0) {
- int lastIndex = getLastIndexOfRow (index);
- if (index == lastIndex) {
- /*
- * Feature in Windows. If the last item in a row is
- * given its ideal size, it will be placed at the far
- * right hand edge of the coolbar. It is preferred
- * that the last item appear next to the second last
- * item. The fix is to size the last item of each row
- * so that it occupies all the available space to the
- * right in the row.
- */
- resizeToMaximumWidth (lastIndex - 1);
- }
- }
-
- /*
- * Feature in Windows. When Windows removed a rebar
- * band, it makes the band child invisible. The fix
- * is to show the child.
- */
- Control control = item.control;
- boolean wasVisible = control != null && !control.isDisposed() && control.getVisible ();
-
- /*
- * When a wrapped item is being deleted, make the next
- * item in the row wrapped in order to preserve the row.
- * In order to avoid an unnecessary layout, temporarily
- * ignore WM_SIZE. If the next item is wrapped then a
- * row will be deleted and the WM_SIZE is necessary.
- */
- CoolItem nextItem = null;
- if (item.getWrap ()) {
- if (index + 1 < count) {
- nextItem = getItem (index + 1);
- ignoreResize = !nextItem.getWrap ();
- }
- }
- if (OS.SendMessage (handle, OS.RB_DELETEBAND, index, 0) == 0) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- items [item.id] = null;
- item.id = -1;
- if (ignoreResize) {
- nextItem.setWrap (true);
- ignoreResize = false;
- }
-
- /* Restore the visible state of the control */
- if (wasVisible) control.setVisible (true);
-
- index = 0;
- while (index < originalItems.length) {
- if (originalItems [index] == item) break;
- index++;
- }
- int length = originalItems.length - 1;
- CoolItem [] newOriginals = new CoolItem [length];
- System.arraycopy (originalItems, 0, newOriginals, 0, index);
- System.arraycopy (originalItems, index + 1, newOriginals, index, length - index);
- originalItems = newOriginals;
-}
-
-void drawThemeBackground (int /*long*/ hDC, int /*long*/ hwnd, RECT rect) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- if (background == -1 && (style & SWT.FLAT) != 0) {
- Control control = findBackgroundControl ();
- if (control != null && control.backgroundImage != null) {
- fillBackground (hDC, control.getBackgroundPixel (), rect);
- return;
- }
- }
- }
- RECT rect2 = new RECT ();
- OS.GetClientRect (handle, rect2);
- OS.MapWindowPoints (handle, hwnd, rect2, 2);
- POINT lpPoint = new POINT ();
- OS.SetWindowOrgEx (hDC, -rect2.left, -rect2.top, lpPoint);
- OS.SendMessage (handle, OS.WM_PRINT, hDC, OS.PRF_CLIENT | OS.PRF_ERASEBKGND);
- OS.SetWindowOrgEx (hDC, lpPoint.x, lpPoint.y, null);
-}
-
-Control findThemeControl () {
- if ((style & SWT.FLAT) != 0) return this;
- return background == -1 && backgroundImage == null ? this : super.findThemeControl ();
-}
-
-int getMargin (int index) {
- int margin = 0;
- if (OS.COMCTL32_MAJOR >= 6) {
- MARGINS margins = new MARGINS ();
- OS.SendMessage (handle, OS.RB_GETBANDMARGINS, 0, margins);
- margin += margins.cxLeftWidth + margins.cxRightWidth;
- }
- RECT rect = new RECT ();
- OS.SendMessage (handle, OS.RB_GETBANDBORDERS, index, rect);
- if ((style & SWT.FLAT) != 0) {
- /*
- * Bug in Windows. When the style bit RBS_BANDBORDERS is not set
- * the rectangle returned by RBS_BANDBORDERS is four pixels too small.
- * The fix is to add four pixels to the result.
- */
- if ((style & SWT.VERTICAL) != 0) {
- margin += rect.top + 4;
- } else {
- margin += rect.left + 4;
- }
- } else {
- if ((style & SWT.VERTICAL) != 0) {
- margin += rect.top + rect.bottom;
- } else {
- margin += rect.left + rect.right;
- }
- }
- if ((style & SWT.FLAT) == 0) {
- if (!isLastItemOfRow (index)) {
- margin += CoolBar.SEPARATOR_WIDTH;
- }
- }
- return margin;
-}
-
-/**
- * Returns the item that is currently displayed at the given,
- * zero-relative index. Throws an exception if the index is
- * out of range.
- *
- * @param index the visual index of the item to return
- * @return the item at the given visual index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public CoolItem getItem (int index) {
- checkWidget ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
- if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_ID;
- OS.SendMessage (handle, OS.RB_GETBANDINFO, index, rbBand);
- return items [rbBand.wID];
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
-}
-
-/**
- * Returns an array of zero-relative ints that map
- * the creation order of the receiver's items to the
- * order in which they are currently being displayed.
- * <p>
- * Specifically, the indices of the returned array represent
- * the current visual order of the items, and the contents
- * of the array represent the creation order of the items.
- * </p><p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the current visual order of the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int [] getItemOrder () {
- checkWidget ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
- int [] indices = new int [count];
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_ID;
- for (int i=0; i<count; i++) {
- OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand);
- CoolItem item = items [rbBand.wID];
- int index = 0;
- while (index<originalItems.length) {
- if (originalItems [index] == item) break;
- index++;
- }
- if (index == originalItems.length) error (SWT.ERROR_CANNOT_GET_ITEM);
- indices [i] = index;
- }
- return indices;
-}
-
-/**
- * Returns an array of <code>CoolItem</code>s in the order
- * in which they are currently being displayed.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the receiver's items in their current visual order
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public CoolItem [] getItems () {
- checkWidget ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
- CoolItem [] result = new CoolItem [count];
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_ID;
- for (int i=0; i<count; i++) {
- OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand);
- result [i] = items [rbBand.wID];
- }
- return result;
-}
-
-/**
- * Returns an array of points whose x and y coordinates describe
- * the widths and heights (respectively) of the items in the receiver
- * in the order in which they are currently being displayed.
- *
- * @return the receiver's item sizes in their current visual order
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point [] getItemSizes () {
- checkWidget ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
- Point [] sizes = new Point [count];
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_CHILDSIZE;
- int separator = (style & SWT.FLAT) == 0 ? SEPARATOR_WIDTH : 0;
- MARGINS margins = new MARGINS ();
- for (int i=0; i<count; i++) {
- RECT rect = new RECT ();
- OS.SendMessage (handle, OS.RB_GETRECT, i, rect);
- OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand);
- if (OS.COMCTL32_MAJOR >= 6) {
- OS.SendMessage (handle, OS.RB_GETBANDMARGINS, 0, margins);
- rect.left -= margins.cxLeftWidth;
- rect.right += margins.cxRightWidth;
- }
- if (!isLastItemOfRow(i)) rect.right += separator;
- if ((style & SWT.VERTICAL) != 0) {
- sizes [i] = new Point (rbBand.cyChild, rect.right - rect.left);
- } else {
- sizes [i] = new Point (rect.right - rect.left, rbBand.cyChild);
- }
- }
- return sizes;
-}
-
-int getLastIndexOfRow (int index) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
- if (count == 0) return -1;
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_STYLE;
- for (int i=index + 1; i<count; i++) {
- OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand);
- if ((rbBand.fStyle & OS.RBBS_BREAK) != 0) {
- return i - 1;
- }
- }
- return count - 1;
-}
-
-boolean isLastItemOfRow (int index) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
- if (index + 1 == count) return true;
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_STYLE;
- OS.SendMessage (handle, OS.RB_GETBANDINFO, index + 1, rbBand);
- return (rbBand.fStyle & OS.RBBS_BREAK) != 0;
-}
-
-/**
- * Returns whether or not the receiver is 'locked'. When a coolbar
- * is locked, its items cannot be repositioned.
- *
- * @return true if the coolbar is locked, false otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public boolean getLocked () {
- checkWidget ();
- return locked;
-}
-
-/**
- * Returns an array of ints that describe the zero-relative
- * indices of any item(s) in the receiver that will begin on
- * a new row. The 0th visible item always begins the first row,
- * therefore it does not count as a wrap index.
- *
- * @return an array containing the receiver's wrap indices, or an empty array if all items are in one row
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int [] getWrapIndices () {
- checkWidget ();
- CoolItem [] items = getItems ();
- int [] indices = new int [items.length];
- int count = 0;
- for (int i=0; i<items.length; i++) {
- if (items [i].getWrap ()) indices [count++] = i;
- }
- int [] result = new int [count];
- System.arraycopy (indices, 0, result, 0, count);
- return result;
-}
-
-/**
- * Searches the receiver's items in the order they are currently
- * being displayed, starting at the first item (index 0), until
- * an item is found that is equal to the argument, and returns
- * the index of that item. If no item is found, returns -1.
- *
- * @param item the search item
- * @return the visual order index of the search item, or -1 if the item is not found
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (CoolItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- return (int)/*64*/OS.SendMessage (handle, OS.RB_IDTOINDEX, item.id, 0);
-}
-
-void resizeToPreferredWidth (int index) {
- /*
- * Bug in Windows. When RB_GETBANDBORDERS is sent
- * with an index out of range, Windows GP's. The
- * fix is to ensure the index is in range.
- */
- int count = (int)/*64*/OS.SendMessage(handle, OS.RB_GETBANDCOUNT, 0, 0);
- if (0 <= index && index < count) {
- REBARBANDINFO rbBand = new REBARBANDINFO();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_IDEALSIZE;
- OS.SendMessage (handle, OS.RB_GETBANDINFO, index, rbBand);
- RECT rect = new RECT ();
- OS.SendMessage (handle, OS.RB_GETBANDBORDERS, index, rect);
- rbBand.cx = rbBand.cxIdeal + rect.left;
- if ((style & SWT.FLAT) == 0) rbBand.cx += rect.right;
- rbBand.fMask = OS.RBBIM_SIZE;
- OS.SendMessage (handle, OS.RB_SETBANDINFO, index, rbBand);
- }
-}
-
-void resizeToMaximumWidth (int index) {
- REBARBANDINFO rbBand = new REBARBANDINFO();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_SIZE;
- rbBand.cx = MAX_WIDTH;
- OS.SendMessage (handle, OS.RB_SETBANDINFO, index, rbBand);
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<items.length; i++) {
- CoolItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- }
- super.releaseChildren (destroy);
-}
-
-void removeControl (Control control) {
- super.removeControl (control);
- for (int i=0; i<items.length; i++) {
- CoolItem item = items [i];
- if (item != null && item.control == control) {
- item.setControl (null);
- }
- }
-}
-
-void setBackgroundPixel (int pixel) {
- if (pixel == -1) pixel = defaultBackground ();
- OS.SendMessage (handle, OS.RB_SETBKCOLOR, 0, pixel);
- setItemColors ((int)/*64*/OS.SendMessage (handle, OS.RB_GETTEXTCOLOR, 0, 0), pixel);
- /*
- * Feature in Windows. For some reason, Windows
- * does not fully erase the coolbar area and coolbar
- * items when you set the background. The fix is
- * to invalidate the coolbar area.
- */
- if (!OS.IsWindowVisible (handle)) return;
- if (OS.IsWinCE) {
- OS.InvalidateRect (handle, null, true);
- } else {
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, null, 0, flags);
- }
-}
-
-void setForegroundPixel (int pixel) {
- if (pixel == -1) pixel = defaultForeground ();
- OS.SendMessage (handle, OS.RB_SETTEXTCOLOR, 0, pixel);
- setItemColors (pixel, (int)/*64*/OS.SendMessage (handle, OS.RB_GETBKCOLOR, 0, 0));
-}
-
-void setItemColors (int foreColor, int backColor) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_COLORS;
- rbBand.clrFore = foreColor;
- rbBand.clrBack = backColor;
- for (int i=0; i<count; i++) {
- OS.SendMessage (handle, OS.RB_SETBANDINFO, i, rbBand);
- }
-}
-
-/**
- * Sets the receiver's item order, wrap indices, and item sizes
- * all at once. This method is typically used to restore the
- * displayed state of the receiver to a previously stored state.
- * <p>
- * The item order is the order in which the items in the receiver
- * should be displayed, given in terms of the zero-relative ordering
- * of when the items were added.
- * </p><p>
- * The wrap indices are the indices of all item(s) in the receiver
- * that will begin on a new row. The indices are given in the order
- * specified by the item order. The 0th item always begins the first
- * row, therefore it does not count as a wrap index. If wrap indices
- * is null or empty, the items will be placed on one line.
- * </p><p>
- * The sizes are specified in an array of points whose x and y
- * coordinates describe the new widths and heights (respectively)
- * of the receiver's items in the order specified by the item order.
- * </p>
- *
- * @param itemOrder an array of indices that describe the new order to display the items in
- * @param wrapIndices an array of wrap indices, or null
- * @param sizes an array containing the new sizes for each of the receiver's items in visual order
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if item order or sizes is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if item order or sizes is not the same length as the number of items</li>
- * </ul>
- */
-public void setItemLayout (int [] itemOrder, int [] wrapIndices, Point [] sizes) {
- checkWidget ();
- setRedraw (false);
- setItemOrder (itemOrder);
- setWrapIndices (wrapIndices);
- setItemSizes (sizes);
- setRedraw (true);
-}
-
-/*
- * Sets the order that the items in the receiver should
- * be displayed in to the given argument which is described
- * in terms of the zero-relative ordering of when the items
- * were added.
- *
- * @param itemOrder the new order to display the items in
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item order is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li>
- * </ul>
- */
-void setItemOrder (int [] itemOrder) {
- if (itemOrder == null) error (SWT.ERROR_NULL_ARGUMENT);
- int itemCount = (int)/*64*/OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
- if (itemOrder.length != itemCount) error (SWT.ERROR_INVALID_ARGUMENT);
-
- /* Ensure that itemOrder does not contain any duplicates. */
- boolean [] set = new boolean [itemCount];
- for (int i=0; i<itemOrder.length; i++) {
- int index = itemOrder [i];
- if (index < 0 || index >= itemCount) error (SWT.ERROR_INVALID_RANGE);
- if (set [index]) error (SWT.ERROR_INVALID_ARGUMENT);
- set [index] = true;
- }
-
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- for (int i=0; i<itemOrder.length; i++) {
- int id = originalItems [itemOrder [i]].id;
- int index = (int)/*64*/OS.SendMessage (handle, OS.RB_IDTOINDEX, id, 0);
- if (index != i) {
- int lastItemSrcRow = getLastIndexOfRow (index);
- int lastItemDstRow = getLastIndexOfRow (i);
- if (index == lastItemSrcRow) {
- resizeToPreferredWidth (index);
- }
- if (i == lastItemDstRow) {
- resizeToPreferredWidth (i);
- }
-
- /* Move the item */
- OS.SendMessage (handle, OS.RB_MOVEBAND, index, i);
-
- if (index == lastItemSrcRow && index - 1 >= 0) {
- resizeToMaximumWidth (index - 1);
- }
- if (i == lastItemDstRow) {
- resizeToMaximumWidth (i);
- }
- }
- }
-}
-
-/*
- * Sets the width and height of the receiver's items to the ones
- * specified by the argument, which is an array of points whose x
- * and y coordinates describe the widths and heights (respectively)
- * in the order in which the items are currently being displayed.
- *
- * @param sizes an array containing the new sizes for each of the receiver's items in visual order
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of sizes is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the array of sizes is not the same length as the number of items</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-void setItemSizes (Point [] sizes) {
- if (sizes == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = (int)/*64*/OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
- if (sizes.length != count) error (SWT.ERROR_INVALID_ARGUMENT);
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_ID;
- for (int i=0; i<count; i++) {
- OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand);
- items [rbBand.wID].setSize (sizes [i].x, sizes [i].y);
- }
-}
-
-/**
- * Sets whether or not the receiver is 'locked'. When a coolbar
- * is locked, its items cannot be repositioned.
- *
- * @param locked lock the coolbar if true, otherwise unlock the coolbar
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setLocked (boolean locked) {
- checkWidget ();
- this.locked = locked;
- int count = (int)/*64*/OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_STYLE;
- for (int i=0; i<count; i++) {
- OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand);
- if (locked) {
- rbBand.fStyle |= OS.RBBS_NOGRIPPER;
- } else {
- rbBand.fStyle &= ~OS.RBBS_NOGRIPPER;
- }
- OS.SendMessage (handle, OS.RB_SETBANDINFO, i, rbBand);
- }
-}
-
-/**
- * Sets the indices of all item(s) in the receiver that will
- * begin on a new row. The indices are given in the order in
- * which they are currently being displayed. The 0th item
- * always begins the first row, therefore it does not count
- * as a wrap index. If indices is null or empty, the items
- * will be placed on one line.
- *
- * @param indices an array of wrap indices, or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWrapIndices (int [] indices) {
- checkWidget ();
- if (indices == null) indices = new int [0];
- int count = getItemCount ();
- for (int i=0; i<indices.length; i++) {
- if (indices [i] < 0 || indices [i] >= count) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- }
- setRedraw (false);
- CoolItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- CoolItem item = items [i];
- if (item.getWrap ()) {
- resizeToPreferredWidth (i - 1);
- item.setWrap (false);
- }
- }
- resizeToMaximumWidth (count - 1);
- for (int i=0; i<indices.length; i++) {
- int index = indices [i];
- if (0 <= index && index < items.length) {
- CoolItem item = items [index];
- item.setWrap (true);
- resizeToMaximumWidth (index - 1);
- }
- }
- setRedraw (true);
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle () | OS.CCS_NODIVIDER | OS.CCS_NORESIZE;
- bits |= OS.RBS_VARHEIGHT | OS.RBS_DBLCLKTOGGLE;
- if ((style & SWT.FLAT) == 0) bits |= OS.RBS_BANDBORDERS;
- return bits;
-}
-
-TCHAR windowClass () {
- return ReBarClass;
-}
-
-int /*long*/ windowProc () {
- return ReBarProc;
-}
-
-LRESULT WM_COMMAND (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. When the coolbar window
- * proc processes WM_COMMAND, it forwards this
- * message to its parent. This is done so that
- * children of this control that send this message
- * type to their parent will notify not only
- * this control but also the parent of this control,
- * which is typically the application window and
- * the window that is looking for the message.
- * If the control did not forward the message,
- * applications would have to subclass the control
- * window to see the message. Because the control
- * window is subclassed by SWT, the message
- * is delivered twice, once by SWT and once when
- * the message is forwarded by the window proc.
- * The fix is to avoid calling the window proc
- * for this control.
- */
- LRESULT result = super.WM_COMMAND (wParam, lParam);
- if (result != null) return result;
- return LRESULT.ZERO;
-}
-
-LRESULT WM_ERASEBKGND (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
- /*
- * Feature in Windows. For some reason, Windows
- * does not fully erase the area that the cool bar
- * occupies when the size of the cool bar is larger
- * than the space occupied by the cool bar items.
- * The fix is to erase the cool bar background.
- *
- * NOTE: On versions of Windows prior to XP, for
- * some reason, the cool bar draws separators in
- * WM_ERASEBKGND. Therefore it is essential to run
- * the cool bar window proc after the background has
- * been erased.
- */
- if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
- drawBackground (wParam);
- return null;
- }
- return result;
-}
-
-LRESULT WM_NOTIFY (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. When the cool bar window
- * proc processes WM_NOTIFY, it forwards this
- * message to its parent. This is done so that
- * children of this control that send this message
- * type to their parent will notify not only
- * this control but also the parent of this control,
- * which is typically the application window and
- * the window that is looking for the message.
- * If the control did not forward the message,
- * applications would have to subclass the control
- * window to see the message. Because the control
- * window is subclassed by SWT, the message
- * is delivered twice, once by SWT and once when
- * the message is forwarded by the window proc.
- * The fix is to avoid calling the window proc
- * for this control.
- */
- LRESULT result = super.WM_NOTIFY (wParam, lParam);
- if (result != null) return result;
- return LRESULT.ZERO;
-}
-
-LRESULT WM_SETREDRAW (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SETREDRAW (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. When redraw is turned off, the rebar
- * control does not call the default window proc. This means
- * that the rebar will redraw and children of the rebar will
- * also redraw. The fix is to call both the rebar window proc
- * and the default window proc.
- *
- * NOTE: The rebar control can resize itself in WM_SETREDRAW.
- * When redraw is turned off by the default window proc, this
- * can leave pixel corruption in the parent. The fix is to
- * detect the size change and damage the previous area in the
- * parent.
- *
- * NOTE: In version 6.00 of COMCTL32.DLL, when WM_SETREDRAW
- * is off, we cannot detect that the size has changed causing
- * pixel corruption. The fix is to disallow WM_SETREDRAW by
- * not running the default window proc or the rebar window
- * proc.
- */
- if (OS.COMCTL32_MAJOR >= 6) return LRESULT.ZERO;
- Rectangle rect = getBounds ();
- int /*long*/ code = callWindowProc (handle, OS.WM_SETREDRAW, wParam, lParam);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, wParam, lParam);
- if (!rect.equals (getBounds ())) {
- parent.redraw (rect.x, rect.y, rect.width, rect.height, true);
- }
- return new LRESULT (code);
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- if (ignoreResize) {
- int /*long*/ code = callWindowProc (handle, OS.WM_SIZE, wParam, lParam);
- if (code == 0) return LRESULT.ZERO;
- return new LRESULT (code);
- }
- //TEMPORARY CODE
-// if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
-// if (background == -1 && (style & SWT.FLAT) == 0) {
-// OS.InvalidateRect (handle, null, true);
-// }
-// }
- return super.WM_SIZE (wParam, lParam);
-}
-
-LRESULT wmNotifyChild (NMHDR hdr, int /*long*/ wParam, int /*long*/ lParam) {
- switch (hdr.code) {
- case OS.RBN_BEGINDRAG: {
- int pos = OS.GetMessagePos ();
- POINT pt = new POINT ();
- OS.POINTSTOPOINT (pt, pos);
- OS.ScreenToClient (handle, pt);
- int button = display.lastButton != 0 ? display.lastButton : 1;
- if (!sendDragEvent (button, pt.x, pt.y)) return LRESULT.ONE;
- break;
- }
- case OS.RBN_CHILDSIZE: {
- /*
- * Bug in Windows. When Windows sets the size of the rebar band
- * child and the child is a combo box, the size of the drop down
- * portion of the combo box is resized to zero. The fix is to set
- * the size of the control to the current size after the rebar has
- * already resized it. If the control is not a combo, this does
- * nothing. If the control is a combo, the drop down portion is
- * recalculated.
- */
- NMREBARCHILDSIZE lprbcs = new NMREBARCHILDSIZE ();
- OS.MoveMemory (lprbcs, lParam, NMREBARCHILDSIZE.sizeof);
- if (lprbcs.uBand != -1) {
- CoolItem item = items [lprbcs.wID];
- Control control = item.control;
- if (control != null) {
- int width = lprbcs.rcChild_right - lprbcs.rcChild_left;
- int height = lprbcs.rcChild_bottom - lprbcs.rcChild_top;
- control.setBounds (lprbcs.rcChild_left, lprbcs.rcChild_top, width, height);
- }
- }
- break;
- }
- case OS.RBN_HEIGHTCHANGE: {
- if (!ignoreResize) {
- Point size = getSize ();
- int border = getBorderWidth ();
- int barHeight = (int)/*64*/OS.SendMessage (handle, OS.RB_GETBARHEIGHT, 0, 0);
- if ((style & SWT.VERTICAL) != 0) {
- setSize (barHeight + 2 * border, size.y);
- } else {
- setSize (size.x, barHeight + 2 * border);
- }
- }
- break;
- }
- case OS.RBN_CHEVRONPUSHED: {
- NMREBARCHEVRON lpnm = new NMREBARCHEVRON ();
- OS.MoveMemory (lpnm, lParam, NMREBARCHEVRON.sizeof);
- CoolItem item = items [lpnm.wID];
- if (item != null) {
- Event event = new Event();
- event.detail = SWT.ARROW;
- if ((style & SWT.VERTICAL) != 0) {
- event.x = lpnm.right;
- event.y = lpnm.top;
- } else {
- event.x = lpnm.left;
- event.y = lpnm.bottom;
- }
- item.postEvent (SWT.Selection, event);
- }
- break;
- }
- case OS.NM_CUSTOMDRAW: {
- /*
- * Bug in Windows. On versions of Windows prior to XP,
- * drawing the background color in NM_CUSTOMDRAW erases
- * the separators. The fix is to draw the background
- * in WM_ERASEBKGND.
- */
- if (OS.COMCTL32_MAJOR < 6) break;
- if (findBackgroundControl () != null || (style & SWT.FLAT) != 0) {
- NMCUSTOMDRAW nmcd = new NMCUSTOMDRAW ();
- OS.MoveMemory (nmcd, lParam, NMCUSTOMDRAW.sizeof);
- switch (nmcd.dwDrawStage) {
- case OS.CDDS_PREERASE:
- return new LRESULT (OS.CDRF_SKIPDEFAULT | OS.CDRF_NOTIFYPOSTERASE);
- case OS.CDDS_POSTERASE:
- drawBackground (nmcd.hdc);
- break;
- }
- }
- break;
- }
- }
- return super.wmNotifyChild (hdr, wParam, lParam);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolItem.java
deleted file mode 100755
index 3b21e1ab53..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolItem.java
+++ /dev/null
@@ -1,717 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that represent the dynamically positionable
- * areas of a <code>CoolBar</code>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>DROP_DOWN</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class CoolItem extends Item {
- CoolBar parent;
- Control control;
- int id;
- boolean ideal, minimum;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>CoolBar</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public CoolItem (CoolBar parent, int style) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>CoolBar</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index at which to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public CoolItem (CoolBar parent, int style, int index) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-/**
- * Adds the listener to the collection of listeners that will
- * be notified when the control is selected by the user, by sending it one
- * of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * If <code>widgetSelected</code> is called when the mouse is over
- * the drop-down arrow (or 'chevron') portion of the cool item,
- * the event object detail field contains the value <code>SWT.ARROW</code>,
- * and the x and y fields in the event object represent the point at
- * the bottom left of the chevron, where the menu should be popped up.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- *
- * @since 2.0
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>preferred size</em> of a <code>CoolItem</code> is the size that
- * it would best be displayed at. The width hint and height hint arguments
- * allow the caller to ask the instance questions such as "Given a particular
- * width, how high does it need to be to show all of the contents?"
- * To indicate that the caller does not wish to constrain a particular
- * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
- * </p>
- *
- * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
- * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
- * @return the preferred size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Layout
- * @see #getBounds
- * @see #getSize
- * @see Control#getBorderWidth
- * @see Scrollable#computeTrim
- * @see Scrollable#getClientArea
- */
-public Point computeSize (int wHint, int hHint) {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) return new Point (0, 0);
- int width = wHint, height = hHint;
- if (wHint == SWT.DEFAULT) width = 32;
- if (hHint == SWT.DEFAULT) height = 32;
- if ((parent.style & SWT.VERTICAL) != 0) {
- height += parent.getMargin (index);
- } else {
- width += parent.getMargin (index);
- }
- return new Point (width, height);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) return new Rectangle (0, 0, 0, 0);
- int /*long*/ hwnd = parent.handle;
- RECT rect = new RECT ();
- OS.SendMessage (hwnd, OS.RB_GETRECT, index, rect);
- if (OS.COMCTL32_MAJOR >= 6) {
- MARGINS margins = new MARGINS ();
- OS.SendMessage (hwnd, OS.RB_GETBANDMARGINS, 0, margins);
- rect.left -= margins.cxLeftWidth;
- rect.right += margins.cxRightWidth;
- }
- if (!parent.isLastItemOfRow (index)) {
- rect.right += (parent.style & SWT.FLAT) == 0 ? CoolBar.SEPARATOR_WIDTH : 0;
- }
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- if ((parent.style & SWT.VERTICAL) != 0) {
- return new Rectangle (rect.top, rect.left, height, width);
- }
- return new Rectangle (rect.left, rect.top, width, height);
-}
-
-Rectangle getClientArea () {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) return new Rectangle (0, 0, 0, 0);
- int /*long*/ hwnd = parent.handle;
- RECT insetRect = new RECT ();
- OS.SendMessage (hwnd, OS.RB_GETBANDBORDERS, index, insetRect);
- RECT rect = new RECT ();
- OS.SendMessage (hwnd, OS.RB_GETRECT, index, rect);
- int x = rect.left + insetRect.left;
- int y = rect.top;
- int width = rect.right - rect.left - insetRect.left;
- int height = rect.bottom - rect.top;
- if ((parent.style & SWT.FLAT) == 0) {
- y += insetRect.top;
- width -= insetRect.right;
- height -= insetRect.top + insetRect.bottom;
- }
- if (index == 0) {
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_HEADERSIZE;
- OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
- width = width - rbBand.cxHeader + 1;
- }
- return new Rectangle (x, y, Math.max (0, width), Math.max (0, height));
-}
-
-/**
- * Returns the control that is associated with the receiver.
- *
- * @return the control that is contained by the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget ();
- return control;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>CoolBar</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public CoolBar getParent () {
- checkWidget ();
- return parent;
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
- id = -1;
- control = null;
-}
-
-/**
- * Sets the control that is associated with the receiver
- * to the argument.
- *
- * @param control the new control that will be contained by the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget ();
- if (control != null) {
- if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- int index = parent.indexOf (this);
- if (index == -1) return;
- if (this.control != null && this.control.isDisposed ()) {
- this.control = null;
- }
- Control oldControl = this.control, newControl = control;
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hwndChild = newControl != null ? control.topHandle () : 0;
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_CHILD;
- rbBand.hwndChild = hwndChild;
- this.control = newControl;
-
- /*
- * Feature in Windows. When Windows sets the rebar band child,
- * it makes the new child visible and hides the old child and
- * moves the new child to the top of the Z-order. The fix is
- * to save and restore the visibility and Z-order.
- */
- int /*long*/ hwndAbove = 0;
- if (newControl != null) {
- hwndAbove = OS.GetWindow (hwndChild, OS.GW_HWNDPREV);
- }
- boolean hideNew = newControl != null && !newControl.getVisible ();
- boolean showOld = oldControl != null && oldControl.getVisible ();
- OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, rbBand);
- if (hideNew) newControl.setVisible (false);
- if (showOld) oldControl.setVisible (true);
- if (hwndAbove != 0 && hwndAbove != hwndChild) {
- int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE;
- SetWindowPos (hwndChild, hwndAbove, 0, 0, 0, 0, flags);
- }
-}
-
-/**
- * Returns a point describing the receiver's ideal size.
- * The x coordinate of the result is the ideal width of the receiver.
- * The y coordinate of the result is the ideal height of the receiver.
- *
- * @return the receiver's ideal size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getPreferredSize () {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) return new Point (0, 0);
- int /*long*/ hwnd = parent.handle;
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_CHILDSIZE | OS.RBBIM_IDEALSIZE;
- OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
- int width = rbBand.cxIdeal + parent.getMargin (index);
- if ((parent.style & SWT.VERTICAL) != 0) {
- return new Point (rbBand.cyMaxChild, width);
- }
- return new Point (width, rbBand.cyMaxChild);
-}
-
-/**
- * Sets the receiver's ideal size to the point specified by the arguments.
- *
- * @param width the new ideal width for the receiver
- * @param height the new ideal height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPreferredSize (int width, int height) {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) return;
- width = Math.max (0, width);
- height = Math.max (0, height);
- ideal = true;
- int /*long*/ hwnd = parent.handle;
- int cxIdeal, cyMaxChild;
- if ((parent.style & SWT.VERTICAL) != 0) {
- cxIdeal = Math.max (0, height - parent.getMargin (index));
- cyMaxChild = width;
- } else {
- cxIdeal = Math.max (0, width - parent.getMargin (index));
- cyMaxChild = height;
- }
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
-
- /* Get the child size fields first so we don't overwrite them. */
- rbBand.fMask = OS.RBBIM_CHILDSIZE;
- OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
-
- /* Set the size fields we are currently modifying. */
- rbBand.fMask = OS.RBBIM_CHILDSIZE | OS.RBBIM_IDEALSIZE;
- rbBand.cxIdeal = cxIdeal;
- rbBand.cyMaxChild = cyMaxChild;
- if (!minimum) rbBand.cyMinChild = cyMaxChild;
- OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, rbBand);
-}
-
-/**
- * Sets the receiver's ideal size to the point specified by the argument.
- *
- * @param size the new ideal size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPreferredSize (Point size) {
- checkWidget ();
- if (size == null) error(SWT.ERROR_NULL_ARGUMENT);
- setPreferredSize (size.x, size.y);
-}
-
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize() {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) new Point (0, 0);
- int /*long*/ hwnd = parent.handle;
- RECT rect = new RECT ();
- OS.SendMessage (hwnd, OS.RB_GETRECT, index, rect);
- if (OS.COMCTL32_MAJOR >= 6) {
- MARGINS margins = new MARGINS ();
- OS.SendMessage (hwnd, OS.RB_GETBANDMARGINS, 0, margins);
- rect.left -= margins.cxLeftWidth;
- rect.right += margins.cxRightWidth;
- }
- if (!parent.isLastItemOfRow (index)) {
- rect.right += (parent.style & SWT.FLAT) == 0 ? CoolBar.SEPARATOR_WIDTH : 0;
- }
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- if ((parent.style & SWT.VERTICAL) != 0) {
- return new Point (height, width);
- }
- return new Point (width, height);
-}
-
-/**
- * Sets the receiver's size to the point specified by the arguments.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (int width, int height) {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) return;
- width = Math.max (0, width);
- height = Math.max (0, height);
- int /*long*/ hwnd = parent.handle;
- int cx, cyChild, cxIdeal;
- if ((parent.style & SWT.VERTICAL) != 0) {
- cx = height;
- cyChild = width;
- cxIdeal = Math.max (0, height - parent.getMargin (index));
- } else {
- cx = width;
- cyChild = height;
- cxIdeal = Math.max (0, width - parent.getMargin (index));
- }
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
-
- /* Get the child size fields first so we don't overwrite them. */
- rbBand.fMask = OS.RBBIM_CHILDSIZE | OS.RBBIM_IDEALSIZE;
- OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
-
- /* Set the size fields we are currently modifying. */
- if (!ideal) rbBand.cxIdeal = cxIdeal;
- if (!minimum) rbBand.cyMinChild = cyChild;
- rbBand.cyChild = cyChild;
-
- /*
- * Do not set the size for the last item on the row.
- */
- if (!parent.isLastItemOfRow (index)) {
- if (OS.COMCTL32_MAJOR >= 6) {
- MARGINS margins = new MARGINS ();
- OS.SendMessage (hwnd, OS.RB_GETBANDMARGINS, 0, margins);
- cx -= margins.cxLeftWidth + margins.cxRightWidth;
- }
- int separator = (parent.style & SWT.FLAT) == 0 ? CoolBar.SEPARATOR_WIDTH : 0;
- rbBand.cx = cx - separator;
- rbBand.fMask |= OS.RBBIM_SIZE;
- }
- OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, rbBand);
-}
-
-/**
- * Sets the receiver's size to the point specified by the argument.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause them to be
- * set to zero instead.
- * </p>
- *
- * @param size the new size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (Point size) {
- if (size == null) error(SWT.ERROR_NULL_ARGUMENT);
- setSize (size.x, size.y);
-}
-
-/**
- * Returns the minimum size that the cool item can
- * be resized to using the cool item's gripper.
- *
- * @return a point containing the minimum width and height of the cool item, in pixels
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public Point getMinimumSize () {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) return new Point (0, 0);
- int /*long*/ hwnd = parent.handle;
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_CHILDSIZE;
- OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
- if ((parent.style & SWT.VERTICAL) != 0) {
- return new Point (rbBand.cyMinChild, rbBand.cxMinChild);
- }
- return new Point (rbBand.cxMinChild, rbBand.cyMinChild);
-}
-
-/**
- * Sets the minimum size that the cool item can be resized to
- * using the cool item's gripper, to the point specified by the arguments.
- *
- * @param width the minimum width of the cool item, in pixels
- * @param height the minimum height of the cool item, in pixels
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setMinimumSize (int width, int height) {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) return;
- width = Math.max (0, width);
- height = Math.max (0, height);
- minimum = true;
- int /*long*/ hwnd = parent.handle;
- int cxMinChild, cyMinChild;
- if ((parent.style & SWT.VERTICAL) != 0) {
- cxMinChild = height;
- cyMinChild = width;
- } else {
- cxMinChild = width;
- cyMinChild = height;
- }
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
-
- /* Get the child size fields first so we don't overwrite them. */
- rbBand.fMask = OS.RBBIM_CHILDSIZE;
- OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
-
- /* Set the size fields we are currently modifying. */
- rbBand.cxMinChild = cxMinChild;
- rbBand.cyMinChild = cyMinChild;
- OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, rbBand);
-}
-
-/**
- * Sets the minimum size that the cool item can be resized to
- * using the cool item's gripper, to the point specified by the argument.
- *
- * @param size a point representing the minimum width and height of the cool item, in pixels
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setMinimumSize (Point size) {
- checkWidget ();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setMinimumSize (size.x, size.y);
-}
-
-boolean getWrap() {
- int index = parent.indexOf (this);
- int /*long*/ hwnd = parent.handle;
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_STYLE;
- OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
- return (rbBand.fStyle & OS.RBBS_BREAK) != 0;
-}
-
-void setWrap(boolean wrap) {
- int index = parent.indexOf (this);
- int /*long*/ hwnd = parent.handle;
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
- rbBand.fMask = OS.RBBIM_STYLE;
- OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
- if (wrap) {
- rbBand.fStyle |= OS.RBBS_BREAK;
- } else {
- rbBand.fStyle &= ~OS.RBBS_BREAK;
- }
- OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, rbBand);
-}
-
-/**
- * Removes the listener from the collection of listeners that
- * will be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- *
- * @since 2.0
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DateTime.java
deleted file mode 100644
index 541ef00dfd..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DateTime.java
+++ /dev/null
@@ -1,1048 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify date
- * or time values.
- * <p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>DATE, TIME, CALENDAR, SHORT, MEDIUM, LONG, DROP_DOWN</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles DATE, TIME, or CALENDAR may be specified,
- * and only one of the styles SHORT, MEDIUM, or LONG may be specified.
- * The DROP_DOWN style is a <em>HINT</em>, and it is only valid with the DATE style.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#datetime">DateTime snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.3
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class DateTime extends Composite {
- boolean doubleClick, ignoreSelection;
- SYSTEMTIME lastSystemTime;
- SYSTEMTIME time = new SYSTEMTIME (); // only used in calendar mode
- static final int /*long*/ DateTimeProc;
- static final TCHAR DateTimeClass = new TCHAR (0, OS.DATETIMEPICK_CLASS, true);
- static final int /*long*/ CalendarProc;
- static final TCHAR CalendarClass = new TCHAR (0, OS.MONTHCAL_CLASS, true);
- static {
- INITCOMMONCONTROLSEX icex = new INITCOMMONCONTROLSEX ();
- icex.dwSize = INITCOMMONCONTROLSEX.sizeof;
- icex.dwICC = OS.ICC_DATE_CLASSES;
- OS.InitCommonControlsEx (icex);
- }
- static {
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, DateTimeClass, lpWndClass);
- DateTimeProc = lpWndClass.lpfnWndProc;
- /*
- * Feature in Windows. The date time window class
- * does not include CS_DBLCLKS. This means that these
- * controls will not get double click messages such as
- * WM_LBUTTONDBLCLK. The fix is to register a new
- * window class with CS_DBLCLKS.
- *
- * NOTE: Screen readers look for the exact class name
- * of the control in order to provide the correct kind
- * of assistance. Therefore, it is critical that the
- * new window class have the same name. It is possible
- * to register a local window class with the same name
- * as a global class. Since bits that affect the class
- * are being changed, it is possible that other native
- * code, other than SWT, could create a control with
- * this class name, and fail unexpectedly.
- */
- int /*long*/ hInstance = OS.GetModuleHandle (null);
- int /*long*/ hHeap = OS.GetProcessHeap ();
- lpWndClass.hInstance = hInstance;
- lpWndClass.style &= ~OS.CS_GLOBALCLASS;
- lpWndClass.style |= OS.CS_DBLCLKS;
- int byteCount = DateTimeClass.length () * TCHAR.sizeof;
- int /*long*/ lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (lpszClassName, DateTimeClass, byteCount);
- lpWndClass.lpszClassName = lpszClassName;
- OS.RegisterClass (lpWndClass);
- OS.HeapFree (hHeap, 0, lpszClassName);
- }
- static {
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, CalendarClass, lpWndClass);
- CalendarProc = lpWndClass.lpfnWndProc;
- /*
- * Feature in Windows. The date time window class
- * does not include CS_DBLCLKS. This means that these
- * controls will not get double click messages such as
- * WM_LBUTTONDBLCLK. The fix is to register a new
- * window class with CS_DBLCLKS.
- *
- * NOTE: Screen readers look for the exact class name
- * of the control in order to provide the correct kind
- * of assistance. Therefore, it is critical that the
- * new window class have the same name. It is possible
- * to register a local window class with the same name
- * as a global class. Since bits that affect the class
- * are being changed, it is possible that other native
- * code, other than SWT, could create a control with
- * this class name, and fail unexpectedly.
- */
- int /*long*/ hInstance = OS.GetModuleHandle (null);
- int /*long*/ hHeap = OS.GetProcessHeap ();
- lpWndClass.hInstance = hInstance;
- lpWndClass.style &= ~OS.CS_GLOBALCLASS;
- lpWndClass.style |= OS.CS_DBLCLKS;
- int byteCount = CalendarClass.length () * TCHAR.sizeof;
- int /*long*/ lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (lpszClassName, CalendarClass, byteCount);
- lpWndClass.lpszClassName = lpszClassName;
- OS.RegisterClass (lpWndClass);
- OS.HeapFree (hHeap, 0, lpszClassName);
- }
- static final int MARGIN = 4;
- static final int MAX_DIGIT = 9;
- static final int MAX_DAY = 31;
- static final int MAX_12HOUR = 12;
- static final int MAX_24HOUR = 24;
- static final int MAX_MINUTE = 60;
- static final int MONTH_DAY_YEAR = 0;
- static final int DAY_MONTH_YEAR = 1;
- static final int YEAR_MONTH_DAY = 2;
- static final char SINGLE_QUOTE = '\''; //$NON-NLS-1$ short date format may include quoted text
- static final char DAY_FORMAT_CONSTANT = 'd'; //$NON-NLS-1$ 1-4 lowercase 'd's represent day
- static final char MONTH_FORMAT_CONSTANT = 'M'; //$NON-NLS-1$ 1-4 uppercase 'M's represent month
- static final char YEAR_FORMAT_CONSTANT = 'y'; //$NON-NLS-1$ 1-5 lowercase 'y's represent year
- static final char HOURS_FORMAT_CONSTANT = 'h'; //$NON-NLS-1$ 1-2 upper or lowercase 'h's represent hours
- static final char MINUTES_FORMAT_CONSTANT = 'm'; //$NON-NLS-1$ 1-2 lowercase 'm's represent minutes
- static final char SECONDS_FORMAT_CONSTANT = 's'; //$NON-NLS-1$ 1-2 lowercase 's's represent seconds
- static final char AMPM_FORMAT_CONSTANT = 't'; //$NON-NLS-1$ 1-2 lowercase 't's represent am/pm
- static final int[] MONTH_NAMES = new int[] {OS.LOCALE_SMONTHNAME1, OS.LOCALE_SMONTHNAME2, OS.LOCALE_SMONTHNAME3, OS.LOCALE_SMONTHNAME4, OS.LOCALE_SMONTHNAME5, OS.LOCALE_SMONTHNAME6, OS.LOCALE_SMONTHNAME7, OS.LOCALE_SMONTHNAME8, OS.LOCALE_SMONTHNAME9, OS.LOCALE_SMONTHNAME10, OS.LOCALE_SMONTHNAME11, OS.LOCALE_SMONTHNAME12};
-
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DATE
- * @see SWT#TIME
- * @see SWT#CALENDAR
- * @see SWT#SHORT
- * @see SWT#MEDIUM
- * @see SWT#LONG
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public DateTime (Composite parent, int style) {
- super (parent, checkStyle (style));
- if ((this.style & SWT.SHORT) != 0) {
- String buffer = ((this.style & SWT.DATE) != 0) ? getCustomShortDateFormat() : getCustomShortTimeFormat();
- TCHAR lpszFormat = new TCHAR (0, buffer, true);
- OS.SendMessage (handle, OS.DTM_SETFORMAT, 0, lpszFormat);
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the control's value.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (windowProc (), hwnd, msg, wParam, lParam);
-}
-
-static int checkStyle (int style) {
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- style &= ~(SWT.H_SCROLL | SWT.V_SCROLL);
- style = checkBits (style, SWT.DATE, SWT.TIME, SWT.CALENDAR, 0, 0, 0);
- style = checkBits (style, SWT.MEDIUM, SWT.SHORT, SWT.LONG, 0, 0, 0);
- if ((style & SWT.DATE) == 0) style &=~ SWT.DROP_DOWN;
- return style;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0;
- if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
- if ((style & SWT.CALENDAR) != 0) {
- RECT rect = new RECT ();
- OS.SendMessage(handle, OS.MCM_GETMINREQRECT, 0, rect);
- width = rect.right;
- height = rect.bottom;
- } else {
- TCHAR buffer = new TCHAR (getCodePage (), 128);
- int /*long*/ newFont, oldFont = 0;
- int /*long*/ hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- RECT rect = new RECT ();
- int flags = OS.DT_CALCRECT | OS.DT_EDITCONTROL | OS.DT_NOPREFIX;
- SYSTEMTIME systime = new SYSTEMTIME ();
- if ((style & SWT.DATE) != 0) {
- /* Determine the widest/tallest year string. */
- systime.wMonth = 1;
- systime.wDay = 1;
- int widest = 0, secondWidest = 0, thirdWidest = 0;
- for (int i = 0; i <= MAX_DIGIT; i++) {
- systime.wYear = (short) (2000 + i); // year 2000 + i is guaranteed to exist
- int size = OS.GetDateFormat(OS.LOCALE_USER_DEFAULT, OS.DATE_SHORTDATE, systime, null, buffer, buffer.length ());
- if (size == 0) {
- buffer = new TCHAR (getCodePage (), size);
- OS.GetDateFormat(OS.LOCALE_USER_DEFAULT, OS.DATE_SHORTDATE, systime, null, buffer, buffer.length ());
- }
- rect.left = rect.top = rect.right = rect.bottom = 0;
- OS.DrawText (hDC, buffer, size, rect, flags);
- if (rect.right - rect.left >= width) {
- width = rect.right - rect.left;
- thirdWidest = secondWidest;
- secondWidest = widest;
- widest = i;
- }
- height = Math.max(height, rect.bottom - rect.top);
- }
- if (widest > 1) widest = widest * 1000 + widest * 100 + widest * 10 + widest;
- else if (secondWidest > 1) widest = secondWidest * 1000 + widest * 100 + widest * 10 + widest;
- else widest = thirdWidest * 1000 + widest * 100 + widest * 10 + widest;
- systime.wYear = (short) widest;
-
- /* Determine the widest/tallest month name string. */
- width = widest = 0;
- for (short i = 0; i < MONTH_NAMES.length; i++) {
- int name = MONTH_NAMES [i];
- int size = OS.GetLocaleInfo (OS.LOCALE_USER_DEFAULT, name, buffer, buffer.length ());
- if (size == 0) {
- buffer = new TCHAR (getCodePage (), size);
- OS.GetLocaleInfo (OS.LOCALE_USER_DEFAULT, name, buffer, buffer.length ());
- }
- rect.left = rect.top = rect.right = rect.bottom = 0;
- OS.DrawText (hDC, buffer, size, rect, flags);
- if (rect.right - rect.left > width) {
- width = rect.right - rect.left;
- widest = i;
- }
- height = Math.max(height, rect.bottom - rect.top);
- }
- systime.wMonth = (short) (widest + 1);
-
- /* Determine the widest/tallest date string in the widest month of the widest year. */
- int dwFlags = ((style & SWT.MEDIUM) != 0) ? OS.DATE_SHORTDATE : ((style & SWT.SHORT) != 0) ? OS.DATE_YEARMONTH : OS.DATE_LONGDATE;
- width = 0;
- for (short i = 1; i <= MAX_DAY; i++) {
- systime.wDay = i;
- int size = OS.GetDateFormat(OS.LOCALE_USER_DEFAULT, dwFlags, systime, null, buffer, buffer.length ());
- if (size == 0) {
- buffer = new TCHAR (getCodePage (), size);
- OS.GetDateFormat(OS.LOCALE_USER_DEFAULT, dwFlags, systime, null, buffer, buffer.length ());
- }
- rect.left = rect.top = rect.right = rect.bottom = 0;
- OS.DrawText (hDC, buffer, size, rect, flags);
- width = Math.max(width, rect.right - rect.left);
- height = Math.max(height, rect.bottom - rect.top);
- if ((style & SWT.SHORT) != 0) break;
- }
- } else if ((style & SWT.TIME) != 0) {
- /* Determine the widest/tallest hour string. This code allows for the possibility of ligatures. */
- int dwFlags = ((style & SWT.SHORT) != 0) ? OS.TIME_NOSECONDS : 0;
- short widest = 0;
- int max = is24HourTime () ? MAX_24HOUR : MAX_12HOUR;
- for (short i = 0; i < max; i++) {
- systime.wHour = i;
- int size = OS.GetTimeFormat(OS.LOCALE_USER_DEFAULT, dwFlags, systime, null, buffer, buffer.length ());
- if (size == 0) {
- buffer = new TCHAR (getCodePage (), size);
- OS.GetTimeFormat(OS.LOCALE_USER_DEFAULT, dwFlags, systime, null, buffer, buffer.length ());
- }
- rect.left = rect.top = rect.right = rect.bottom = 0;
- OS.DrawText (hDC, buffer, size, rect, flags);
- if (rect.right - rect.left > width) {
- width = rect.right - rect.left;
- widest = i;
- }
- height = Math.max(height, rect.bottom - rect.top);
- }
- systime.wHour = widest;
-
- /* Determine the widest/tallest minute and second string. */
- width = widest = 0;
- for (short i = 0; i < MAX_MINUTE; i++) {
- systime.wMinute = i;
- int size = OS.GetTimeFormat(OS.LOCALE_USER_DEFAULT, dwFlags, systime, null, buffer, buffer.length ());
- if (size == 0) {
- buffer = new TCHAR (getCodePage (), size);
- OS.GetTimeFormat(OS.LOCALE_USER_DEFAULT, dwFlags, systime, null, buffer, buffer.length ());
- }
- rect.left = rect.top = rect.right = rect.bottom = 0;
- OS.DrawText (hDC, buffer, size, rect, flags);
- if (rect.right - rect.left > width) {
- width = rect.right - rect.left;
- widest = i;
- }
- height = Math.max(height, rect.bottom - rect.top);
- }
- systime.wMinute = widest;
- systime.wSecond = widest;
-
- /* Determine the widest/tallest time string for the widest hour, widest minute, and if applicable, widest second. */
- int size = OS.GetTimeFormat(OS.LOCALE_USER_DEFAULT, dwFlags, systime, null, buffer, buffer.length ());
- if (size == 0) {
- buffer = new TCHAR (getCodePage (), size);
- OS.GetTimeFormat(OS.LOCALE_USER_DEFAULT, dwFlags, systime, null, buffer, buffer.length ());
- }
- rect.left = rect.top = rect.right = rect.bottom = 0;
- OS.DrawText (hDC, buffer, size, rect, flags);
- width = rect.right - rect.left;
- height = Math.max(height, rect.bottom - rect.top);
- }
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- int upDownWidth = OS.GetSystemMetrics (OS.SM_CXVSCROLL);
- int upDownHeight = OS.GetSystemMetrics (OS.SM_CYVSCROLL);
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- // TODO: On Vista, can send DTM_GETDATETIMEPICKERINFO to ask the Edit control what its margins are
- upDownHeight += 7;
- if ((style & SWT.DROP_DOWN) != 0) upDownWidth += 16;
- }
- width += upDownWidth + MARGIN;
- height = Math.max (height, upDownHeight);
- }
- }
- if (width == 0) width = DEFAULT_WIDTH;
- if (height == 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2;
- height += border * 2;
- return new Point (width, height);
-}
-
-void createHandle () {
- super.createHandle ();
- state &= ~(CANVAS | THEME_BACKGROUND);
-
- if ((style & SWT.BORDER) == 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
- bits &= ~(OS.WS_EX_CLIENTEDGE | OS.WS_EX_STATICEDGE);
- OS.SetWindowLong (handle, OS.GWL_EXSTYLE, bits);
- }
-}
-
-int defaultBackground () {
- return OS.GetSysColor (OS.COLOR_WINDOW);
-}
-
-String getComputeSizeString () {
- // TODO: Not currently used but might need for WinCE
- if ((style & SWT.DATE) != 0) {
- if ((style & SWT.SHORT) != 0) return getCustomShortDateFormat ();
- if ((style & SWT.MEDIUM) != 0) return getShortDateFormat ();
- if ((style & SWT.LONG) != 0) return getLongDateFormat ();
- }
- if ((style & SWT.TIME) != 0) {
- if ((style & SWT.SHORT) != 0) return getCustomShortTimeFormat ();
- return getTimeFormat ();
- }
- return "";
-}
-
-String getCustomShortDateFormat () {
- TCHAR tchar = new TCHAR (getCodePage (), 80);
- int size = OS.GetLocaleInfo (OS.LOCALE_USER_DEFAULT, OS.LOCALE_SYEARMONTH, tchar, 80);
- return size != 0 ? tchar.toString (0, size - 1) : "M/yyyy"; //$NON-NLS-1$
-
- //TODO: Not currently used, but may need for WinCE (or if numeric short date is required)
-// StringBuffer buffer = new StringBuffer (getShortDateFormat ());
-// int length = buffer.length ();
-// boolean inQuotes = false;
-// int start = 0, end = 0;
-// while (start < length) {
-// char ch = buffer.charAt (start);
-// if (ch == SINGLE_QUOTE) inQuotes = !inQuotes;
-// else if (ch == DAY_FORMAT_CONSTANT && !inQuotes) {
-// end = start + 1;
-// while (end < length && buffer.charAt (end) == DAY_FORMAT_CONSTANT) end++;
-// int ordering = getShortDateFormatOrdering ();
-// switch (ordering) {
-// case MONTH_DAY_YEAR:
-// // skip the following separator
-// while (end < length && buffer.charAt (end) != YEAR_FORMAT_CONSTANT) end++;
-// break;
-// case DAY_MONTH_YEAR:
-// // skip the following separator
-// while (end < length && buffer.charAt (end) != MONTH_FORMAT_CONSTANT) end++;
-// break;
-// case YEAR_MONTH_DAY:
-// // skip the preceding separator
-// while (start > 0 && buffer.charAt (start) != MONTH_FORMAT_CONSTANT) start--;
-// break;
-// }
-// break;
-// }
-// start++;
-// }
-// if (start < end) buffer.delete (start, end);
-// return buffer.toString ();
-}
-
-String getCustomShortTimeFormat () {
- StringBuffer buffer = new StringBuffer (getTimeFormat ());
- int length = buffer.length ();
- boolean inQuotes = false;
- int start = 0, end = 0;
- while (start < length) {
- char ch = buffer.charAt (start);
- if (ch == SINGLE_QUOTE) inQuotes = !inQuotes;
- else if (ch == SECONDS_FORMAT_CONSTANT && !inQuotes) {
- end = start + 1;
- while (end < length && buffer.charAt (end) == SECONDS_FORMAT_CONSTANT) end++;
- // skip the preceding separator
- while (start > 0 && buffer.charAt (start) != MINUTES_FORMAT_CONSTANT) start--;
- start++;
- break;
- }
- start++;
- }
- if (start < end) buffer.delete (start, end);
- return buffer.toString ();
-}
-
-String getLongDateFormat () {
- //TODO: Not currently used, but may need for WinCE
- TCHAR tchar = new TCHAR (getCodePage (), 80);
- int size = OS.GetLocaleInfo (OS.LOCALE_USER_DEFAULT, OS.LOCALE_SLONGDATE, tchar, 80);
- return size > 0 ? tchar.toString (0, size - 1) : "dddd, MMMM dd, yyyy"; //$NON-NLS-1$
-}
-
-String getShortDateFormat () {
- //TODO: Not currently used, but may need for WinCE
- TCHAR tchar = new TCHAR (getCodePage (), 80);
- //TODO: May need to OR with LOCALE_ICENTURY
- int size = OS.GetLocaleInfo (OS.LOCALE_USER_DEFAULT, OS.LOCALE_SSHORTDATE, tchar, 80);
- return size > 0 ? tchar.toString (0, size - 1) : "M/d/yyyy"; //$NON-NLS-1$
-}
-
-int getShortDateFormatOrdering () {
- //TODO: Not currently used, but may need for WinCE
- TCHAR tchar = new TCHAR (getCodePage (), 4);
- int size = OS.GetLocaleInfo (OS.LOCALE_USER_DEFAULT, OS.LOCALE_IDATE, tchar, 4);
- if (size > 0) {
- String number = tchar.toString (0, size - 1);
- return Integer.parseInt (number);
- }
- return 0;
-}
-
-String getTimeFormat () {
- TCHAR tchar = new TCHAR (getCodePage (), 80);
- int size = OS.GetLocaleInfo (OS.LOCALE_USER_DEFAULT, OS.LOCALE_STIMEFORMAT, tchar, 80);
- return size > 0 ? tchar.toString (0, size - 1) : "h:mm:ss tt"; //$NON-NLS-1$
-}
-
-boolean is24HourTime () {
- TCHAR tchar = new TCHAR (getCodePage (), 4);
- int size = OS.GetLocaleInfo (OS.LOCALE_USER_DEFAULT, OS.LOCALE_ITIME, tchar, 4);
- if (size > 0) {
- String number = tchar.toString (0, size - 1);
- return Integer.parseInt (number) != 0;
- }
- return true;
-}
-
-/**
- * Returns the receiver's date, or day of the month.
- * <p>
- * The first day of the month is 1, and the last day depends on the month and year.
- * </p>
- *
- * @return a positive integer beginning with 1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getDay () {
- checkWidget ();
- SYSTEMTIME systime = new SYSTEMTIME ();
- int msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_GETCURSEL : OS.DTM_GETSYSTEMTIME;
- OS.SendMessage (handle, msg, 0, systime);
- return systime.wDay;
-}
-
-/**
- * Returns the receiver's hours.
- * <p>
- * Hours is an integer between 0 and 23.
- * </p>
- *
- * @return an integer between 0 and 23
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getHours () {
- checkWidget ();
- if ((style & SWT.CALENDAR) != 0) return time.wHour;
- SYSTEMTIME systime = new SYSTEMTIME ();
- int msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_GETCURSEL : OS.DTM_GETSYSTEMTIME;
- OS.SendMessage (handle, msg, 0, systime);
- return systime.wHour;
-}
-
-/**
- * Returns the receiver's minutes.
- * <p>
- * Minutes is an integer between 0 and 59.
- * </p>
- *
- * @return an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinutes () {
- checkWidget ();
- if ((style & SWT.CALENDAR) != 0) return time.wMinute;
- SYSTEMTIME systime = new SYSTEMTIME ();
- int msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_GETCURSEL : OS.DTM_GETSYSTEMTIME;
- OS.SendMessage (handle, msg, 0, systime);
- return systime.wMinute;
-}
-
-/**
- * Returns the receiver's month.
- * <p>
- * The first month of the year is 0, and the last month is 11.
- * </p>
- *
- * @return an integer between 0 and 11
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMonth () {
- checkWidget ();
- SYSTEMTIME systime = new SYSTEMTIME ();
- int msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_GETCURSEL : OS.DTM_GETSYSTEMTIME;
- OS.SendMessage (handle, msg, 0, systime);
- return systime.wMonth - 1;
-}
-
-String getNameText() {
- return (style & SWT.TIME) != 0 ? getHours() + ":" + getMinutes() + ":" + getSeconds()
- : (getMonth() + 1) + "/" + getDay() + "/" + getYear();
-}
-
-/**
- * Returns the receiver's seconds.
- * <p>
- * Seconds is an integer between 0 and 59.
- * </p>
- *
- * @return an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSeconds () {
- checkWidget ();
- if ((style & SWT.CALENDAR) != 0) return time.wSecond;
- SYSTEMTIME systime = new SYSTEMTIME ();
- int msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_GETCURSEL : OS.DTM_GETSYSTEMTIME;
- OS.SendMessage (handle, msg, 0, systime);
- return systime.wSecond;
-}
-
-/**
- * Returns the receiver's year.
- * <p>
- * The first year is 1752 and the last year is 9999.
- * </p>
- *
- * @return an integer between 1752 and 9999
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getYear () {
- checkWidget ();
- SYSTEMTIME systime = new SYSTEMTIME ();
- int msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_GETCURSEL : OS.DTM_GETSYSTEMTIME;
- OS.SendMessage (handle, msg, 0, systime);
- return systime.wYear;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- lastSystemTime = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection, listener);
-}
-
-/**
- * Sets the receiver's year, month, and day in a single operation.
- * <p>
- * This is the recommended way to set the date, because setting the year,
- * month, and day separately may result in invalid intermediate dates.
- * </p>
- *
- * @param year an integer between 1752 and 9999
- * @param month an integer between 0 and 11
- * @param day a positive integer beginning with 1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setDate (int year, int month, int day) {
- checkWidget ();
- SYSTEMTIME systime = new SYSTEMTIME ();
- int msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_GETCURSEL : OS.DTM_GETSYSTEMTIME;
- OS.SendMessage (handle, msg, 0, systime);
- msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_SETCURSEL : OS.DTM_SETSYSTEMTIME;
- systime.wYear = (short)year;
- systime.wMonth = (short)(month + 1);
- systime.wDay = (short)day;
- OS.SendMessage (handle, msg, 0, systime);
- lastSystemTime = null;
-}
-
-/**
- * Sets the receiver's date, or day of the month, to the specified day.
- * <p>
- * The first day of the month is 1, and the last day depends on the month and year.
- * If the specified day is not valid for the receiver's month and year, then it is ignored.
- * </p>
- *
- * @param day a positive integer beginning with 1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDate
- */
-public void setDay (int day) {
- checkWidget ();
- SYSTEMTIME systime = new SYSTEMTIME ();
- int msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_GETCURSEL : OS.DTM_GETSYSTEMTIME;
- OS.SendMessage (handle, msg, 0, systime);
- msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_SETCURSEL : OS.DTM_SETSYSTEMTIME;
- systime.wDay = (short)day;
- OS.SendMessage (handle, msg, 0, systime);
- lastSystemTime = null;
-}
-
-/**
- * Sets the receiver's hours.
- * <p>
- * Hours is an integer between 0 and 23.
- * </p>
- *
- * @param hours an integer between 0 and 23
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHours (int hours) {
- checkWidget ();
- SYSTEMTIME systime = new SYSTEMTIME ();
- int msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_GETCURSEL : OS.DTM_GETSYSTEMTIME;
- OS.SendMessage (handle, msg, 0, systime);
- msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_SETCURSEL : OS.DTM_SETSYSTEMTIME;
- systime.wHour = (short)hours;
- OS.SendMessage (handle, msg, 0, systime);
- if ((style & SWT.CALENDAR) != 0 && hours >= 0 && hours <= 23) time.wHour = (short)hours;
-}
-
-/**
- * Sets the receiver's minutes.
- * <p>
- * Minutes is an integer between 0 and 59.
- * </p>
- *
- * @param minutes an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinutes (int minutes) {
- checkWidget ();
- SYSTEMTIME systime = new SYSTEMTIME ();
- int msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_GETCURSEL : OS.DTM_GETSYSTEMTIME;
- OS.SendMessage (handle, msg, 0, systime);
- msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_SETCURSEL : OS.DTM_SETSYSTEMTIME;
- systime.wMinute = (short)minutes;
- OS.SendMessage (handle, msg, 0, systime);
- if ((style & SWT.CALENDAR) != 0 && minutes >= 0 && minutes <= 59) time.wMinute = (short)minutes;
-}
-
-/**
- * Sets the receiver's month.
- * <p>
- * The first month of the year is 0, and the last month is 11.
- * If the specified month is not valid for the receiver's day and year, then it is ignored.
- * </p>
- *
- * @param month an integer between 0 and 11
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDate
- */
-public void setMonth (int month) {
- checkWidget ();
- SYSTEMTIME systime = new SYSTEMTIME ();
- int msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_GETCURSEL : OS.DTM_GETSYSTEMTIME;
- OS.SendMessage (handle, msg, 0, systime);
- msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_SETCURSEL : OS.DTM_SETSYSTEMTIME;
- systime.wMonth = (short)(month + 1);
- OS.SendMessage (handle, msg, 0, systime);
- lastSystemTime = null;
-}
-
-/**
- * Sets the receiver's seconds.
- * <p>
- * Seconds is an integer between 0 and 59.
- * </p>
- *
- * @param seconds an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSeconds (int seconds) {
- checkWidget ();
- SYSTEMTIME systime = new SYSTEMTIME ();
- int msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_GETCURSEL : OS.DTM_GETSYSTEMTIME;
- OS.SendMessage (handle, msg, 0, systime);
- msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_SETCURSEL : OS.DTM_SETSYSTEMTIME;
- systime.wSecond = (short)seconds;
- OS.SendMessage (handle, msg, 0, systime);
- if ((style & SWT.CALENDAR) != 0 && seconds >= 0 && seconds <= 59) time.wSecond = (short)seconds;
-}
-
-/**
- * Sets the receiver's hours, minutes, and seconds in a single operation.
- *
- * @param hours an integer between 0 and 23
- * @param minutes an integer between 0 and 59
- * @param seconds an integer between 0 and 59
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setTime (int hours, int minutes, int seconds) {
- checkWidget ();
- SYSTEMTIME systime = new SYSTEMTIME ();
- int msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_GETCURSEL : OS.DTM_GETSYSTEMTIME;
- OS.SendMessage (handle, msg, 0, systime);
- msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_SETCURSEL : OS.DTM_SETSYSTEMTIME;
- systime.wHour = (short)hours;
- systime.wMinute = (short)minutes;
- systime.wSecond = (short)seconds;
- OS.SendMessage (handle, msg, 0, systime);
- if ((style & SWT.CALENDAR) != 0
- && hours >= 0 && hours <= 23
- && minutes >= 0 && minutes <= 59
- && seconds >= 0 && seconds <= 59) {
- time.wHour = (short)hours;
- time.wMinute = (short)minutes;
- time.wSecond = (short)seconds;
- }
-}
-
-/**
- * Sets the receiver's year.
- * <p>
- * The first year is 1752 and the last year is 9999.
- * If the specified year is not valid for the receiver's day and month, then it is ignored.
- * </p>
- *
- * @param year an integer between 1752 and 9999
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDate
- */
-public void setYear (int year) {
- checkWidget ();
- SYSTEMTIME systime = new SYSTEMTIME ();
- int msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_GETCURSEL : OS.DTM_GETSYSTEMTIME;
- OS.SendMessage (handle, msg, 0, systime);
- msg = (style & SWT.CALENDAR) != 0 ? OS.MCM_SETCURSEL : OS.DTM_SETSYSTEMTIME;
- systime.wYear = (short)year;
- OS.SendMessage (handle, msg, 0, systime);
- lastSystemTime = null;
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle () | OS.WS_TABSTOP;
- if ((style & SWT.CALENDAR) != 0) return bits | OS.MCS_NOTODAY;
- /*
- * Bug in Windows: When WS_CLIPCHILDREN is set in a
- * Date and Time Picker, the widget draws on top of
- * the updown control. The fix is to clear the bits.
- */
- bits &= ~OS.WS_CLIPCHILDREN;
- if ((style & SWT.TIME) != 0) bits |= OS.DTS_TIMEFORMAT;
- if ((style & SWT.DATE) != 0) {
- bits |= ((style & SWT.MEDIUM) != 0 ? OS.DTS_SHORTDATECENTURYFORMAT : OS.DTS_LONGDATEFORMAT);
- if ((style & SWT.DROP_DOWN) == 0) bits |= OS.DTS_UPDOWN;
- }
- return bits;
-}
-
-TCHAR windowClass () {
- return (style & SWT.CALENDAR) != 0 ? CalendarClass : DateTimeClass;
-}
-
-int /*long*/ windowProc () {
- return (style & SWT.CALENDAR) != 0 ? CalendarProc : DateTimeProc;
-}
-
-LRESULT wmNotifyChild (NMHDR hdr, int /*long*/ wParam, int /*long*/ lParam) {
- switch (hdr.code) {
- case OS.DTN_CLOSEUP: {
- /*
- * Feature in Windows. When the user selects the drop-down button,
- * the DateTimePicker runs a modal loop and consumes WM_LBUTTONUP.
- * This is done without adding a mouse capture. Since WM_LBUTTONUP
- * is not delivered, the normal mechanism where a mouse capture is
- * added on mouse down and removed when the mouse is released
- * is broken, leaving an unwanted capture. The fix is to avoid
- * setting capture on mouse down right after WM_LBUTTONUP is consumed.
- */
- display.captureChanged = true;
- break;
- }
- case OS.MCN_SELCHANGE: {
- if (ignoreSelection) break;
- SYSTEMTIME systime = new SYSTEMTIME ();
- OS.SendMessage (handle, OS.MCM_GETCURSEL, 0, systime);
- postEvent (SWT.Selection);
- break;
- }
- case OS.DTN_DATETIMECHANGE: {
- SYSTEMTIME systime = new SYSTEMTIME ();
- OS.SendMessage (handle, OS.DTM_GETSYSTEMTIME, 0, systime);
- if (lastSystemTime == null || systime.wDay != lastSystemTime.wDay || systime.wMonth != lastSystemTime.wMonth || systime.wYear != lastSystemTime.wYear) {
- postEvent (SWT.Selection);
- if ((style & SWT.TIME) == 0) lastSystemTime = systime;
- }
- break;
- }
- }
- return super.wmNotifyChild (hdr, wParam, lParam);
-}
-
-LRESULT WM_CHAR (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_CHAR (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. For some reason, when the
- * user presses tab, return or escape, Windows beeps.
- * The fix is to look for these keys and not call
- * the window proc.
- */
- switch ((int)/*64*/wParam) {
- case SWT.CR:
- postEvent (SWT.DefaultSelection);
- // FALL THROUGH
- case SWT.TAB:
- case SWT.ESC: return LRESULT.ZERO;
- }
- return result;
-}
-
-LRESULT WM_LBUTTONDBLCLK (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_LBUTTONDBLCLK (wParam, lParam);
- if (isDisposed ()) return LRESULT.ZERO;
- if ((style & SWT.CALENDAR) != 0) {
- MCHITTESTINFO pMCHitTest = new MCHITTESTINFO ();
- pMCHitTest.cbSize = MCHITTESTINFO.sizeof;
- POINT pt = new POINT ();
- pt.x = OS.GET_X_LPARAM (lParam);
- pt.y = OS.GET_Y_LPARAM (lParam);
- pMCHitTest.pt = pt;
- int /*long*/ code = OS.SendMessage (handle, OS.MCM_HITTEST, 0, pMCHitTest);
- if ((code & OS.MCHT_CALENDARDATE) == OS.MCHT_CALENDARDATE) doubleClick = true;
- }
- return result;
-}
-
-LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_LBUTTONDOWN (wParam, lParam);
- if (result == LRESULT.ZERO) return result;
- doubleClick = false;
- /*
- * Feature in Windows. For some reason, the calendar control
- * does not take focus on WM_LBUTTONDOWN. The fix is to
- * explicitly set focus.
- */
- if ((style & SWT.CALENDAR) != 0) {
- if ((style & SWT.NO_FOCUS) == 0) OS.SetFocus (handle);
- }
- return result;
-}
-
-LRESULT WM_LBUTTONUP (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_LBUTTONUP (wParam, lParam);
- if (isDisposed ()) return LRESULT.ZERO;
- if (doubleClick) postEvent (SWT.DefaultSelection);
- doubleClick = false;
- return result;
-}
-
-LRESULT WM_TIMER (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_TIMER (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. For some reason, Windows sends WM_NOTIFY with
- * MCN_SELCHANGE at regular intervals. This is unexpected. The fix is
- * to ignore MCN_SELCHANGE during WM_TIMER.
- */
- ignoreSelection = true;
- int /*long*/ code = callWindowProc(handle, OS.WM_TIMER, wParam, lParam);
- ignoreSelection = false;
- return code == 0 ? LRESULT.ZERO : new LRESULT(code);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java
deleted file mode 100755
index c0eed0de0e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java
+++ /dev/null
@@ -1,1798 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide the appearance and
- * behavior of <code>Shells</code>, but are not top
- * level shells or dialogs. Class <code>Shell</code>
- * shares a significant amount of code with this class,
- * and is a subclass.
- * <p>
- * IMPORTANT: This class was intended to be abstract and
- * should <em>never</em> be referenced or instantiated.
- * Instead, the class <code>Shell</code> should be used.
- * </p>
- * <p>
- * Instances are always displayed in one of the maximized,
- * minimized or normal states:
- * <ul>
- * <li>
- * When an instance is marked as <em>maximized</em>, the
- * window manager will typically resize it to fill the
- * entire visible area of the display, and the instance
- * is usually put in a state where it can not be resized
- * (even if it has style <code>RESIZE</code>) until it is
- * no longer maximized.
- * </li><li>
- * When an instance is in the <em>normal</em> state (neither
- * maximized or minimized), its appearance is controlled by
- * the style constants which were specified when it was created
- * and the restrictions of the window manager (see below).
- * </li><li>
- * When an instance has been marked as <em>minimized</em>,
- * its contents (client area) will usually not be visible,
- * and depending on the window manager, it may be
- * "iconified" (that is, replaced on the desktop by a small
- * simplified representation of itself), relocated to a
- * distinguished area of the screen, or hidden. Combinations
- * of these changes are also possible.
- * </li>
- * </ul>
- * </p>
- * Note: The styles supported by this class must be treated
- * as <em>HINT</em>s, since the window manager for the
- * desktop on which the instance is visible has ultimate
- * control over the appearance and behavior of decorations.
- * For example, some window managers only support resizable
- * windows and will always assume the RESIZE style, even if
- * it is not set.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * Class <code>SWT</code> provides two "convenience constants"
- * for the most commonly required style combinations:
- * <dl>
- * <dt><code>SHELL_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application top level shell: (that
- * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>)
- * </dd>
- * <dt><code>DIALOG_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application dialog shell: (that
- * is, <code>TITLE | CLOSE | BORDER</code>)
- * </dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see #getMinimized
- * @see #getMaximized
- * @see Shell
- * @see SWT
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Decorations extends Canvas {
- Image image, smallImage, largeImage;
- Image [] images;
- Menu menuBar;
- Menu [] menus;
- Control savedFocus;
- Button defaultButton, saveDefault;
- int swFlags, nAccel;
- int /*long*/ hAccel;
- boolean moved, resized, opened;
- int oldX = OS.CW_USEDEFAULT, oldY = OS.CW_USEDEFAULT;
- int oldWidth = OS.CW_USEDEFAULT, oldHeight = OS.CW_USEDEFAULT;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Decorations () {
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#TOOL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Decorations (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-void _setMaximized (boolean maximized) {
- swFlags = maximized ? OS.SW_SHOWMAXIMIZED : OS.SW_RESTORE;
- if (OS.IsWinCE) {
- /*
- * Note: WinCE does not support SW_SHOWMAXIMIZED and SW_RESTORE. The
- * workaround is to resize the window to fit the parent client area.
- */
- if (maximized) {
- RECT rect = new RECT ();
- OS.SystemParametersInfo (OS.SPI_GETWORKAREA, 0, rect, 0);
- int width = rect.right - rect.left, height = rect.bottom - rect.top;
- if (OS.IsPPC) {
- /* Leave space for the menu bar */
- if (menuBar != null) {
- int /*long*/ hwndCB = menuBar.hwndCB;
- RECT rectCB = new RECT ();
- OS.GetWindowRect (hwndCB, rectCB);
- height -= rectCB.bottom - rectCB.top;
- }
- }
- int flags = OS.SWP_NOZORDER | OS.SWP_DRAWFRAME | OS.SWP_NOACTIVATE;
- SetWindowPos (handle, 0, rect.left, rect.top, width, height, flags);
- }
- } else {
- if (!OS.IsWindowVisible (handle)) return;
- if (maximized == OS.IsZoomed (handle)) return;
- OS.ShowWindow (handle, swFlags);
- OS.UpdateWindow (handle);
- }
-}
-
-void _setMinimized (boolean minimized) {
- if (OS.IsWinCE) return;
- swFlags = minimized ? OS.SW_SHOWMINNOACTIVE : OS.SW_RESTORE;
- if (!OS.IsWindowVisible (handle)) return;
- if (minimized == OS.IsIconic (handle)) return;
- int flags = swFlags;
- if (flags == OS.SW_SHOWMINNOACTIVE && handle == OS.GetActiveWindow ()) {
- flags = OS.SW_MINIMIZE;
- }
- OS.ShowWindow (handle, flags);
- OS.UpdateWindow (handle);
-}
-
-void addMenu (Menu menu) {
- if (menus == null) menus = new Menu [4];
- for (int i=0; i<menus.length; i++) {
- if (menus [i] == null) {
- menus [i] = menu;
- return;
- }
- }
- Menu [] newMenus = new Menu [menus.length + 4];
- newMenus [menus.length] = menu;
- System.arraycopy (menus, 0, newMenus, 0, menus.length);
- menus = newMenus;
-}
-
-void bringToTop () {
- /*
- * This code is intentionally commented. On some platforms,
- * the ON_TOP style creates a shell that will stay on top
- * of every other shell on the desktop. Using SetWindowPos ()
- * with HWND_TOP caused problems on Windows 98 so this code is
- * commented out until this functionality is specified and
- * the problems are fixed.
- */
-// if ((style & SWT.ON_TOP) != 0) {
-// int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE;
-// OS.SetWindowPos (handle, OS.HWND_TOP, 0, 0, 0, 0, flags);
-// } else {
- OS.BringWindowToTop (handle);
- // widget could be disposed at this point
-// }
-}
-
-static int checkStyle (int style) {
- if ((style & SWT.NO_TRIM) != 0) {
- style &= ~(SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX | SWT.RESIZE | SWT.BORDER);
- }
- if (OS.IsWinCE) {
- /*
- * Feature in WinCE PPC. WS_MINIMIZEBOX or WS_MAXIMIZEBOX
- * are not supposed to be used. If they are, the result
- * is a button which does not repaint correctly. The fix
- * is to remove this style.
- */
- if ((style & SWT.MIN) != 0) style &= ~SWT.MIN;
- if ((style & SWT.MAX) != 0) style &= ~SWT.MAX;
- return style;
- }
- if ((style & (SWT.MENU | SWT.MIN | SWT.MAX | SWT.CLOSE)) != 0) {
- style |= SWT.TITLE;
- }
-
- /*
- * If either WS_MINIMIZEBOX or WS_MAXIMIZEBOX are set,
- * we must also set WS_SYSMENU or the buttons will not
- * appear.
- */
- if ((style & (SWT.MIN | SWT.MAX)) != 0) style |= SWT.CLOSE;
-
- /*
- * Both WS_SYSMENU and WS_CAPTION must be set in order
- * to for the system menu to appear.
- */
- if ((style & SWT.CLOSE) != 0) style |= SWT.TITLE;
-
- /*
- * Bug in Windows. The WS_CAPTION style must be
- * set when the window is resizable or it does not
- * draw properly.
- */
- /*
- * This code is intentionally commented. It seems
- * that this problem originally in Windows 3.11,
- * has been fixed in later versions. Because the
- * exact nature of the drawing problem is unknown,
- * keep the commented code around in case it comes
- * back.
- */
-// if ((style & SWT.RESIZE) != 0) style |= SWT.TITLE;
-
- return style;
-}
-
-void checkBorder () {
- /* Do nothing */
-}
-
-void checkComposited (Composite parent) {
- /* Do nothing */
-}
-
-void checkOpened () {
- if (!opened) resized = false;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- return OS.DefMDIChildProc (hwnd, msg, wParam, lParam);
-}
-
-void closeWidget () {
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- if (event.doit && !isDisposed ()) dispose ();
-}
-
-int compare (ImageData data1, ImageData data2, int width, int height, int depth) {
- int value1 = Math.abs (data1.width - width), value2 = Math.abs (data2.width - width);
- if (value1 == value2) {
- int transparent1 = data1.getTransparencyType ();
- int transparent2 = data2.getTransparencyType ();
- if (transparent1 == transparent2) {
- if (data1.depth == data2.depth) return 0;
- return data1.depth > data2.depth && data1.depth <= depth ? -1 : 1;
- }
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
- if (transparent1 == SWT.TRANSPARENCY_ALPHA) return -1;
- if (transparent2 == SWT.TRANSPARENCY_ALPHA) return 1;
- }
- if (transparent1 == SWT.TRANSPARENCY_MASK) return -1;
- if (transparent2 == SWT.TRANSPARENCY_MASK) return 1;
- if (transparent1 == SWT.TRANSPARENCY_PIXEL) return -1;
- if (transparent2 == SWT.TRANSPARENCY_PIXEL) return 1;
- return 0;
- }
- return value1 < value2 ? -1 : 1;
-}
-
-Widget computeTabGroup () {
- return this;
-}
-
-Control computeTabRoot () {
- return this;
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
-
- /* Get the size of the trimmings */
- RECT rect = new RECT ();
- OS.SetRect (rect, x, y, x + width, y + height);
- int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
- int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
- boolean hasMenu = OS.IsWinCE ? false : OS.GetMenu (handle) != 0;
- OS.AdjustWindowRectEx (rect, bits1, hasMenu, bits2);
-
- /* Get the size of the scroll bars */
- if (horizontalBar != null) rect.bottom += OS.GetSystemMetrics (OS.SM_CYHSCROLL);
- if (verticalBar != null) rect.right += OS.GetSystemMetrics (OS.SM_CXVSCROLL);
-
- /* Compute the height of the menu bar */
- if (hasMenu) {
- RECT testRect = new RECT ();
- OS.SetRect (testRect, 0, 0, rect.right - rect.left, rect.bottom - rect.top);
- OS.SendMessage (handle, OS.WM_NCCALCSIZE, 0, testRect);
- while ((testRect.bottom - testRect.top) < height) {
- if (testRect.bottom - testRect.top == 0) break;
- rect.top -= OS.GetSystemMetrics (OS.SM_CYMENU) - OS.GetSystemMetrics (OS.SM_CYBORDER);
- OS.SetRect (testRect, 0, 0, rect.right - rect.left, rect.bottom - rect.top);
- OS.SendMessage (handle, OS.WM_NCCALCSIZE, 0, testRect);
- }
- }
- return new Rectangle (rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
-}
-
-void createAccelerators () {
- hAccel = nAccel = 0;
- int maxAccel = 0;
- MenuItem [] items = display.items;
- if (menuBar == null || items == null) {
- if (!OS.IsPPC) return;
- maxAccel = 1;
- } else {
- maxAccel = OS.IsPPC ? items.length + 1 : items.length;
- }
- ACCEL accel = new ACCEL ();
- byte [] buffer1 = new byte [ACCEL.sizeof];
- byte [] buffer2 = new byte [maxAccel * ACCEL.sizeof];
- if (menuBar != null && items != null) {
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (item != null && item.accelerator != 0) {
- Menu menu = item.parent;
- if (menu.parent == this) {
- while (menu != null && menu != menuBar) {
- menu = menu.getParentMenu ();
- }
- if (menu == menuBar && item.fillAccel (accel)) {
- OS.MoveMemory (buffer1, accel, ACCEL.sizeof);
- System.arraycopy (buffer1, 0, buffer2, nAccel * ACCEL.sizeof, ACCEL.sizeof);
- nAccel++;
- }
- }
- }
- }
- }
- if (OS.IsPPC) {
- /*
- * Note on WinCE PPC. Close the shell when user taps CTRL-Q.
- * IDOK represents the "Done Button" which also closes the shell.
- */
- accel.fVirt = (byte) (OS.FVIRTKEY | OS.FCONTROL);
- accel.key = (short) 'Q';
- accel.cmd = (short) OS.IDOK;
- OS.MoveMemory (buffer1, accel, ACCEL.sizeof);
- System.arraycopy (buffer1, 0, buffer2, nAccel * ACCEL.sizeof, ACCEL.sizeof);
- nAccel++;
- }
- if (nAccel != 0) hAccel = OS.CreateAcceleratorTable (buffer2, nAccel);
-}
-
-void createHandle () {
- super.createHandle ();
- if (parent != null || ((style & SWT.TOOL) != 0)) {
- setParent ();
- setSystemMenu ();
- }
-}
-
-void createWidget () {
- super.createWidget ();
- swFlags = OS.IsWinCE ? OS.SW_SHOWMAXIMIZED : OS.SW_SHOWNOACTIVATE;
- hAccel = -1;
-}
-
-void destroyAccelerators () {
- if (hAccel != 0 && hAccel != -1) OS.DestroyAcceleratorTable (hAccel);
- hAccel = -1;
-}
-
-public void dispose () {
- if (isDisposed()) return;
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!(this instanceof Shell)) {
- if (!traverseDecorations (true)) {
- Shell shell = getShell ();
- shell.setFocus ();
- }
- setVisible (false);
- }
- super.dispose ();
-}
-
-Menu findMenu (int /*long*/ hMenu) {
- if (menus == null) return null;
- for (int i=0; i<menus.length; i++) {
- Menu menu = menus [i];
- if (menu != null && hMenu == menu.handle) return menu;
- }
- return null;
-}
-
-void fixDecorations (Decorations newDecorations, Control control, Menu [] menus) {
- if (this == newDecorations) return;
- if (control == savedFocus) savedFocus = null;
- if (control == defaultButton) defaultButton = null;
- if (control == saveDefault) saveDefault = null;
- if (menus == null) return;
- Menu menu = control.menu;
- if (menu != null) {
- int index = 0;
- while (index <menus.length) {
- if (menus [index] == menu) {
- control.setMenu (null);
- return;
- }
- index++;
- }
- menu.fixMenus (newDecorations);
- destroyAccelerators ();
- newDecorations.destroyAccelerators ();
- }
-}
-
-public Rectangle getBounds () {
- checkWidget ();
- if (!OS.IsWinCE) {
- if (OS.IsIconic (handle)) {
- WINDOWPLACEMENT lpwndpl = new WINDOWPLACEMENT ();
- lpwndpl.length = WINDOWPLACEMENT.sizeof;
- OS.GetWindowPlacement (handle, lpwndpl);
- int width = lpwndpl.right - lpwndpl.left;
- int height = lpwndpl.bottom - lpwndpl.top;
- return new Rectangle (lpwndpl.left, lpwndpl.top, width, height);
- }
- }
- return super.getBounds ();
-}
-
-public Rectangle getClientArea () {
- checkWidget ();
- /*
- * Note: The CommandBar is part of the client area,
- * not the trim. Applications don't expect this so
- * subtract the height of the CommandBar.
- */
- if (OS.IsHPC) {
- Rectangle rect = super.getClientArea ();
- if (menuBar != null) {
- int /*long*/ hwndCB = menuBar.hwndCB;
- int height = OS.CommandBar_Height (hwndCB);
- rect.y += height;
- rect.height = Math.max (0, rect.height - height);
- }
- return rect;
- }
- if (!OS.IsWinCE) {
- if (OS.IsIconic (handle)) {
- WINDOWPLACEMENT lpwndpl = new WINDOWPLACEMENT ();
- lpwndpl.length = WINDOWPLACEMENT.sizeof;
- OS.GetWindowPlacement (handle, lpwndpl);
- int width = lpwndpl.right - lpwndpl.left;
- int height = lpwndpl.bottom - lpwndpl.top;
- /*
- * Feature in Windows. For some reason WM_NCCALCSIZE does
- * not compute the client area when the window is minimized.
- * The fix is to compute it using AdjustWindowRectEx() and
- * GetSystemMetrics().
- *
- * NOTE: This code fails to compute the correct client area
- * for a minimized window where the menu bar would wrap were
- * the window restored. There is no fix for this problem at
- * this time.
- */
- if (horizontalBar != null) width -= OS.GetSystemMetrics (OS.SM_CYHSCROLL);
- if (verticalBar != null) height -= OS.GetSystemMetrics (OS.SM_CXVSCROLL);
- RECT rect = new RECT ();
- int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
- int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
- boolean hasMenu = OS.IsWinCE ? false : OS.GetMenu (handle) != 0;
- OS.AdjustWindowRectEx (rect, bits1, hasMenu, bits2);
- width = Math.max (0, width - (rect.right - rect.left));
- height = Math.max (0, height - (rect.bottom - rect.top));
- return new Rectangle (0, 0, width, height);
- }
- }
- return super.getClientArea ();
-}
-
-/**
- * Returns the receiver's default button if one had
- * previously been set, otherwise returns null.
- *
- * @return the default button or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDefaultButton(Button)
- */
-public Button getDefaultButton () {
- checkWidget ();
- return defaultButton;
-}
-
-/**
- * Returns the receiver's image if it had previously been
- * set using <code>setImage()</code>. The image is typically
- * displayed by the window manager when the instance is
- * marked as iconified, and may also be displayed somewhere
- * in the trim when the instance is in normal or maximized
- * states.
- * <p>
- * Note: This method will return null if called before
- * <code>setImage()</code> is called. It does not provide
- * access to a window manager provided, "default" image
- * even if one exists.
- * </p>
- *
- * @return the image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget ();
- return image;
-}
-
-/**
- * Returns the receiver's images if they had previously been
- * set using <code>setImages()</code>. Images are typically
- * displayed by the window manager when the instance is
- * marked as iconified, and may also be displayed somewhere
- * in the trim when the instance is in normal or maximized
- * states. Depending where the icon is displayed, the platform
- * chooses the icon with the "best" attributes. It is expected
- * that the array will contain the same icon rendered at different
- * sizes, with different depth and transparency attributes.
- *
- * <p>
- * Note: This method will return an empty array if called before
- * <code>setImages()</code> is called. It does not provide
- * access to a window manager provided, "default" image
- * even if one exists.
- * </p>
- *
- * @return the images
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Image [] getImages () {
- checkWidget ();
- if (images == null) return new Image [0];
- Image [] result = new Image [images.length];
- System.arraycopy (images, 0, result, 0, images.length);
- return result;
-}
-
-public Point getLocation () {
- checkWidget ();
- if (!OS.IsWinCE) {
- if (OS.IsIconic (handle)) {
- WINDOWPLACEMENT lpwndpl = new WINDOWPLACEMENT ();
- lpwndpl.length = WINDOWPLACEMENT.sizeof;
- OS.GetWindowPlacement (handle, lpwndpl);
- return new Point (lpwndpl.left, lpwndpl.top);
- }
- }
- return super.getLocation ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is currently
- * maximized, and false otherwise.
- * <p>
- *
- * @return the maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMaximized
- */
-public boolean getMaximized () {
- checkWidget ();
- if (OS.IsWinCE) return swFlags == OS.SW_SHOWMAXIMIZED;
- if (OS.IsWindowVisible (handle)) return OS.IsZoomed (handle);
- return swFlags == OS.SW_SHOWMAXIMIZED;
-}
-
-/**
- * Returns the receiver's menu bar if one had previously
- * been set, otherwise returns null.
- *
- * @return the menu bar or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenuBar () {
- checkWidget ();
- return menuBar;
-}
-
-/**
- * Returns <code>true</code> if the receiver is currently
- * minimized, and false otherwise.
- * <p>
- *
- * @return the minimized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMinimized
- */
-public boolean getMinimized () {
- checkWidget ();
- if (OS.IsWinCE) return false;
- if (OS.IsWindowVisible (handle)) return OS.IsIconic (handle);
- return swFlags == OS.SW_SHOWMINNOACTIVE;
-}
-
-String getNameText () {
- return getText ();
-}
-
-public Point getSize () {
- checkWidget ();
- if (!OS.IsWinCE) {
- if (OS.IsIconic (handle)) {
- WINDOWPLACEMENT lpwndpl = new WINDOWPLACEMENT ();
- lpwndpl.length = WINDOWPLACEMENT.sizeof;
- OS.GetWindowPlacement (handle, lpwndpl);
- int width = lpwndpl.right - lpwndpl.left;
- int height = lpwndpl.bottom - lpwndpl.top;
- return new Point (width, height);
- }
- }
- return super.getSize ();
-}
-
-/**
- * Returns the receiver's text, which is the string that the
- * window manager will typically display as the receiver's
- * <em>title</em>. If the text has not previously been set,
- * returns an empty string.
- *
- * @return the text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- int length = OS.GetWindowTextLength (handle);
- if (length == 0) return "";
- /* Use the character encoding for the default locale */
- TCHAR buffer = new TCHAR (0, length + 1);
- OS.GetWindowText (handle, buffer, length + 1);
- return buffer.toString (0, length);
-}
-
-public boolean isReparentable () {
- checkWidget ();
- /*
- * Feature in Windows. Calling SetParent() for a shell causes
- * a kind of fake MDI to happen. It doesn't work well on Windows
- * and is not supported on the other platforms. The fix is to
- * disallow the SetParent().
- */
- return false;
-}
-
-boolean isTabGroup () {
- /*
- * Can't test WS_TAB bits because they are the same as WS_MAXIMIZEBOX.
- */
- return true;
-}
-
-boolean isTabItem () {
- /*
- * Can't test WS_TAB bits because they are the same as WS_MAXIMIZEBOX.
- */
- return false;
-}
-
-Decorations menuShell () {
- return this;
-}
-
-void releaseChildren (boolean destroy) {
- if (menuBar != null) {
- menuBar.release (false);
- menuBar = null;
- }
- super.releaseChildren (destroy);
- if (menus != null) {
- for (int i=0; i<menus.length; i++) {
- Menu menu = menus [i];
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- }
- menus = null;
- }
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (smallImage != null) smallImage.dispose ();
- if (largeImage != null) largeImage.dispose ();
- smallImage = largeImage = image = null;
- images = null;
- savedFocus = null;
- defaultButton = saveDefault = null;
- if (hAccel != 0 && hAccel != -1) OS.DestroyAcceleratorTable (hAccel);
- hAccel = -1;
-}
-
-void removeMenu (Menu menu) {
- if (menus == null) return;
- for (int i=0; i<menus.length; i++) {
- if (menus [i] == menu) {
- menus [i] = null;
- return;
- }
- }
-}
-
-boolean restoreFocus () {
- if (display.ignoreRestoreFocus) return true;
- if (savedFocus != null && savedFocus.isDisposed ()) savedFocus = null;
- if (savedFocus != null && savedFocus.setSavedFocus ()) return true;
- /*
- * This code is intentionally commented. When no widget
- * has been given focus, some platforms give focus to the
- * default button. Windows doesn't do this.
- */
-// if (defaultButton != null && !defaultButton.isDisposed ()) {
-// if (defaultButton.setFocus ()) return true;
-// }
- return false;
-}
-
-void saveFocus () {
- Control control = display._getFocusControl ();
- if (control != null && control != this && this == control.menuShell ()) {
- setSavedFocus (control);
- }
-}
-
-void setBounds (int x, int y, int width, int height, int flags, boolean defer) {
- swFlags = OS.SW_SHOWNOACTIVATE;
- if (OS.IsWinCE) {
- swFlags = OS.SW_RESTORE;
- } else {
- if (OS.IsIconic (handle)) {
- setPlacement (x, y, width, height, flags);
- return;
- }
- }
- forceResize ();
- RECT rect = new RECT ();
- OS.GetWindowRect (handle, rect);
- boolean sameOrigin = true;
- if ((OS.SWP_NOMOVE & flags) == 0) {
- sameOrigin = rect.left == x && rect.top == y;
- if (!sameOrigin) moved = true;
- }
- boolean sameExtent = true;
- if ((OS.SWP_NOSIZE & flags) == 0) {
- sameExtent = rect.right - rect.left == width && rect.bottom - rect.top == height;
- if (!sameExtent) resized = true;
- }
- if (!OS.IsWinCE) {
- if (OS.IsZoomed (handle)) {
- if (sameOrigin && sameExtent) return;
- setPlacement (x, y, width, height, flags);
- _setMaximized (false);
- return;
- }
- }
- super.setBounds (x, y, width, height, flags, defer);
-}
-
-/**
- * If the argument is not null, sets the receiver's default
- * button to the argument, and if the argument is null, sets
- * the receiver's default button to the first button which
- * was set as the receiver's default button (called the
- * <em>saved default button</em>). If no default button had
- * previously been set, or the saved default button was
- * disposed, the receiver's default button will be set to
- * null.
- * <p>
- * The default button is the button that is selected when
- * the receiver is active and the user presses ENTER.
- * </p>
- *
- * @param button the new default button
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the button has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDefaultButton (Button button) {
- checkWidget ();
- if (button != null) {
- if (button.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (button.menuShell () != this) error(SWT.ERROR_INVALID_PARENT);
- }
- setDefaultButton (button, true);
-}
-
-void setDefaultButton (Button button, boolean save) {
- if (button == null) {
- if (defaultButton == saveDefault) {
- if (save) saveDefault = null;
- return;
- }
- } else {
- if ((button.style & SWT.PUSH) == 0) return;
- if (button == defaultButton) return;
- }
- if (defaultButton != null) {
- if (!defaultButton.isDisposed ()) defaultButton.setDefault (false);
- }
- if ((defaultButton = button) == null) defaultButton = saveDefault;
- if (defaultButton != null) {
- if (!defaultButton.isDisposed ()) defaultButton.setDefault (true);
- }
- if (save) saveDefault = defaultButton;
- if (saveDefault != null && saveDefault.isDisposed ()) saveDefault = null;
-}
-
-/**
- * Sets the receiver's image to the argument, which may
- * be null. The image is typically displayed by the window
- * manager when the instance is marked as iconified, and
- * may also be displayed somewhere in the trim when the
- * instance is in normal or maximized states.
- *
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- this.image = image;
- setImages (image, null);
-}
-
-void setImages (Image image, Image [] images) {
- /*
- * Feature in WinCE. WM_SETICON and WM_GETICON set the icon
- * for the window class, not the window instance. This means
- * that it is possible to set an icon into a window and then
- * later free the icon, thus freeing the icon for every window.
- * The fix is to avoid the API.
- *
- * On WinCE PPC, icons in windows are not displayed.
- */
- if (OS.IsWinCE) return;
- if (smallImage != null) smallImage.dispose ();
- if (largeImage != null) largeImage.dispose ();
- smallImage = largeImage = null;
- int /*long*/ hSmallIcon = 0, hLargeIcon = 0;
- Image smallIcon = null, largeIcon = null;
- if (image != null) {
- smallIcon = largeIcon = image;
- } else {
- if (images != null && images.length > 0) {
- int depth = display.getIconDepth ();
- ImageData [] datas = null;
- if (images.length > 1) {
- Image [] bestImages = new Image [images.length];
- System.arraycopy (images, 0, bestImages, 0, images.length);
- datas = new ImageData [images.length];
- for (int i=0; i<datas.length; i++) {
- datas [i] = images [i].getImageData ();
- }
- images = bestImages;
- sort (images, datas, OS.GetSystemMetrics (OS.SM_CXSMICON), OS.GetSystemMetrics (OS.SM_CYSMICON), depth);
- }
- smallIcon = images [0];
- if (images.length > 1) {
- sort (images, datas, OS.GetSystemMetrics (OS.SM_CXICON), OS.GetSystemMetrics (OS.SM_CYICON), depth);
- }
- largeIcon = images [0];
- }
- }
- if (smallIcon != null) {
- switch (smallIcon.type) {
- case SWT.BITMAP:
- smallImage = Display.createIcon (smallIcon);
- hSmallIcon = smallImage.handle;
- break;
- case SWT.ICON:
- hSmallIcon = smallIcon.handle;
- break;
- }
- }
- OS.SendMessage (handle, OS.WM_SETICON, OS.ICON_SMALL, hSmallIcon);
- if (largeIcon != null) {
- switch (largeIcon.type) {
- case SWT.BITMAP:
- largeImage = Display.createIcon (largeIcon);
- hLargeIcon = largeImage.handle;
- break;
- case SWT.ICON:
- hLargeIcon = largeIcon.handle;
- break;
- }
- }
- OS.SendMessage (handle, OS.WM_SETICON, OS.ICON_BIG, hLargeIcon);
-
- /*
- * Bug in Windows. When WM_SETICON is used to remove an
- * icon from the window trimmings for a window with the
- * extended style bits WS_EX_DLGMODALFRAME, the window
- * trimmings do not redraw to hide the previous icon.
- * The fix is to force a redraw.
- */
- if (!OS.IsWinCE) {
- if (hSmallIcon == 0 && hLargeIcon == 0 && (style & SWT.BORDER) != 0) {
- int flags = OS.RDW_FRAME | OS.RDW_INVALIDATE;
- OS.RedrawWindow (handle, null, 0, flags);
- }
- }
-}
-
-/**
- * Sets the receiver's images to the argument, which may
- * be an empty array. Images are typically displayed by the
- * window manager when the instance is marked as iconified,
- * and may also be displayed somewhere in the trim when the
- * instance is in normal or maximized states. Depending where
- * the icon is displayed, the platform chooses the icon with
- * the "best" attributes. It is expected that the array will
- * contain the same icon rendered at different sizes, with
- * different depth and transparency attributes.
- *
- * @param images the new image array
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images is null or has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setImages (Image [] images) {
- checkWidget ();
- if (images == null) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i = 0; i < images.length; i++) {
- if (images [i] == null || images [i].isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.images = images;
- setImages (null, images);
-}
-
-/**
- * Sets the maximized state of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the maximized state, and if the argument is
- * <code>false</code> and the receiver was previously maximized,
- * causes the receiver to switch back to either the minimized
- * or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setMaximized(true)</code>
- * and <code>setMinimized(true)</code> will vary by platform. Typically,
- * the behavior will match the platform user's expectations, but not
- * always. This should be avoided if possible.
- * </p>
- *
- * @param maximized the new maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMinimized
- */
-public void setMaximized (boolean maximized) {
- checkWidget ();
- Display.lpStartupInfo = null;
- _setMaximized (maximized);
-}
-
-/**
- * Sets the receiver's menu bar to the argument, which
- * may be null.
- *
- * @param menu the new menu bar
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenuBar (Menu menu) {
- checkWidget ();
- if (menuBar == menu) return;
- if (menu != null) {
- if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR);
- if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
- if (OS.IsWinCE) {
- if (OS.IsHPC) {
- boolean resize = menuBar != menu;
- if (menuBar != null) OS.CommandBar_Show (menuBar.hwndCB, false);
- menuBar = menu;
- if (menuBar != null) OS.CommandBar_Show (menuBar.hwndCB, true);
- if (resize) {
- sendEvent (SWT.Resize);
- if (isDisposed ()) return;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (true, false);
- }
- }
- } else {
- if (OS.IsPPC) {
- /*
- * Note in WinCE PPC. The menu bar is a separate popup window.
- * If the shell is full screen, resize its window to leave
- * space for the menu bar.
- */
- boolean resize = getMaximized () && menuBar != menu;
- if (menuBar != null) OS.ShowWindow (menuBar.hwndCB, OS.SW_HIDE);
- menuBar = menu;
- if (menuBar != null) OS.ShowWindow (menuBar.hwndCB, OS.SW_SHOW);
- if (resize) _setMaximized (true);
- }
- if (OS.IsSP) {
- if (menuBar != null) OS.ShowWindow (menuBar.hwndCB, OS.SW_HIDE);
- menuBar = menu;
- if (menuBar != null) OS.ShowWindow (menuBar.hwndCB, OS.SW_SHOW);
- }
- }
- } else {
- if (menu != null) display.removeBar (menu);
- menuBar = menu;
- int /*long*/ hMenu = menuBar != null ? menuBar.handle: 0;
- OS.SetMenu (handle, hMenu);
- }
- destroyAccelerators ();
-}
-
-/**
- * Sets the minimized stated of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the minimized state, and if the argument is
- * <code>false</code> and the receiver was previously minimized,
- * causes the receiver to switch back to either the maximized
- * or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setMaximized(true)</code>
- * and <code>setMinimized(true)</code> will vary by platform. Typically,
- * the behavior will match the platform user's expectations, but not
- * always. This should be avoided if possible.
- * </p>
- *
- * @param minimized the new maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMaximized
- */
-public void setMinimized (boolean minimized) {
- checkWidget ();
- Display.lpStartupInfo = null;
- _setMinimized (minimized);
-}
-
-void setParent () {
- /*
- * In order for an MDI child window to support
- * a menu bar, setParent () is needed to reset
- * the parent. Otherwise, the MDI child window
- * will appear as a separate shell. This is an
- * undocumented and possibly dangerous Windows
- * feature.
- */
- int /*long*/ hwndParent = parent.handle;
- display.lockActiveWindow = true;
- OS.SetParent (handle, hwndParent);
- if (!OS.IsWindowVisible (hwndParent)) {
- OS.ShowWindow (handle, OS.SW_SHOWNA);
- }
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- bits &= ~OS.WS_CHILD;
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits | OS.WS_POPUP);
- OS.SetWindowLongPtr (handle, OS.GWLP_ID, 0);
- int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE;
- SetWindowPos (handle, OS.HWND_BOTTOM, 0, 0, 0, 0, flags);
- display.lockActiveWindow = false;
-}
-
-void setPlacement (int x, int y, int width, int height, int flags) {
- WINDOWPLACEMENT lpwndpl = new WINDOWPLACEMENT ();
- lpwndpl.length = WINDOWPLACEMENT.sizeof;
- OS.GetWindowPlacement (handle, lpwndpl);
- lpwndpl.showCmd = OS.SW_SHOWNA;
- if (OS.IsIconic (handle)) {
- lpwndpl.showCmd = OS.SW_SHOWMINNOACTIVE;
- } else {
- if (OS.IsZoomed (handle)) {
- lpwndpl.showCmd = OS.SW_SHOWMAXIMIZED;
- }
- }
- boolean sameOrigin = true;
- if ((flags & OS.SWP_NOMOVE) == 0) {
- sameOrigin = lpwndpl.left != x || lpwndpl.top != y;
- lpwndpl.right = x + (lpwndpl.right - lpwndpl.left);
- lpwndpl.bottom = y + (lpwndpl.bottom - lpwndpl.top);
- lpwndpl.left = x;
- lpwndpl.top = y;
- }
- boolean sameExtent = true;
- if ((flags & OS.SWP_NOSIZE) == 0) {
- sameExtent = lpwndpl.right - lpwndpl.left != width || lpwndpl.bottom - lpwndpl.top != height;
- lpwndpl.right = lpwndpl.left + width;
- lpwndpl.bottom = lpwndpl.top + height;
- }
- OS.SetWindowPlacement (handle, lpwndpl);
- if (OS.IsIconic (handle)) {
- if (sameOrigin) {
- moved = true;
- Point location = getLocation ();
- oldX = location.x;
- oldY = location.y;
- sendEvent (SWT.Move);
- if (isDisposed ()) return;
- }
- if (sameExtent) {
- resized = true;
- Rectangle rect = getClientArea ();
- oldWidth = rect.width;
- oldHeight = rect.height;
- sendEvent (SWT.Resize);
- if (isDisposed ()) return;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (true, false);
- }
- }
- }
-}
-
-void setSavedFocus (Control control) {
- savedFocus = control;
-}
-
-void setSystemMenu () {
- if (OS.IsWinCE) return;
- int /*long*/ hMenu = OS.GetSystemMenu (handle, false);
- if (hMenu == 0) return;
- int oldCount = OS.GetMenuItemCount (hMenu);
- if ((style & SWT.RESIZE) == 0) {
- OS.DeleteMenu (hMenu, OS.SC_SIZE, OS.MF_BYCOMMAND);
- }
- if ((style & SWT.MIN) == 0) {
- OS.DeleteMenu (hMenu, OS.SC_MINIMIZE, OS.MF_BYCOMMAND);
- }
- if ((style & SWT.MAX) == 0) {
- OS.DeleteMenu (hMenu, OS.SC_MAXIMIZE, OS.MF_BYCOMMAND);
- }
- if ((style & (SWT.MIN | SWT.MAX)) == 0) {
- OS.DeleteMenu (hMenu, OS.SC_RESTORE, OS.MF_BYCOMMAND);
- }
- int newCount = OS.GetMenuItemCount (hMenu);
- if ((style & SWT.CLOSE) == 0 || newCount != oldCount) {
- OS.DeleteMenu (hMenu, OS.SC_TASKLIST, OS.MF_BYCOMMAND);
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- info.fMask = OS.MIIM_ID;
- int index = 0;
- while (index < newCount) {
- if (OS.GetMenuItemInfo (hMenu, index, true, info)) {
- if (info.wID == OS.SC_CLOSE) break;
- }
- index++;
- }
- if (index != newCount) {
- OS.DeleteMenu (hMenu, index - 1, OS.MF_BYPOSITION);
- if ((style & SWT.CLOSE) == 0) {
- OS.DeleteMenu (hMenu, OS.SC_CLOSE, OS.MF_BYCOMMAND);
- }
- }
- }
-}
-
-/**
- * Sets the receiver's text, which is the string that the
- * window manager will typically display as the receiver's
- * <em>title</em>, to the argument, which must not be null.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- /* Use the character encoding for the default locale */
- TCHAR buffer = new TCHAR (0, string, true);
- /* Ensure that the title appears in the task bar.*/
- if ((state & FOREIGN_HANDLE) != 0) {
- int /*long*/ hHeap = OS.GetProcessHeap ();
- int byteCount = buffer.length () * TCHAR.sizeof;
- int /*long*/ pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (pszText, buffer, byteCount);
- OS.DefWindowProc (handle, OS.WM_SETTEXT, 0, pszText);
- if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
- } else {
- OS.SetWindowText (handle, buffer);
- }
-}
-
-public void setVisible (boolean visible) {
- checkWidget ();
- if (!getDrawing()) {
- if (((state & HIDDEN) == 0) == visible) return;
- } else {
- if (visible == OS.IsWindowVisible (handle)) return;
- }
- if (visible) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the show
- * event. If this happens, just return.
- */
- sendEvent (SWT.Show);
- if (isDisposed ()) return;
- if (OS.IsHPC) {
- if (menuBar != null) {
- int /*long*/ hwndCB = menuBar.hwndCB;
- OS.CommandBar_DrawMenuBar (hwndCB, 0);
- }
- }
- if (!getDrawing()) {
- state &= ~HIDDEN;
- } else {
- if (OS.IsWinCE) {
- OS.ShowWindow (handle, OS.SW_SHOW);
- } else {
- if (menuBar != null) {
- display.removeBar (menuBar);
- OS.DrawMenuBar (handle);
- }
- STARTUPINFO lpStartUpInfo = Display.lpStartupInfo;
- if (lpStartUpInfo != null && (lpStartUpInfo.dwFlags & OS.STARTF_USESHOWWINDOW) != 0) {
- OS.ShowWindow (handle, lpStartUpInfo.wShowWindow);
- } else {
- OS.ShowWindow (handle, swFlags);
- }
- }
- if (isDisposed ()) return;
- opened = true;
- if (!moved) {
- moved = true;
- Point location = getLocation ();
- oldX = location.x;
- oldY = location.y;
- }
- if (!resized) {
- resized = true;
- Rectangle rect = getClientArea ();
- oldWidth = rect.width;
- oldHeight = rect.height;
- }
- /*
- * Bug in Windows. On Vista using the Classic theme,
- * when the window is hung and UpdateWindow() is called,
- * nothing is drawn, and outstanding WM_PAINTs are cleared.
- * This causes pixel corruption. The fix is to avoid calling
- * update on hung windows.
- */
- boolean update = true;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0) && !OS.IsAppThemed ()) {
- update = !OS.IsHungAppWindow (handle);
- }
- if (update) OS.UpdateWindow (handle);
- }
- } else {
- if (!OS.IsWinCE) {
- if (OS.IsIconic (handle)) {
- swFlags = OS.SW_SHOWMINNOACTIVE;
- } else {
- if (OS.IsZoomed (handle)) {
- swFlags = OS.SW_SHOWMAXIMIZED;
- } else {
- swFlags = OS.SW_SHOWNOACTIVATE;
- }
- }
- }
- if (!getDrawing()) {
- state |= HIDDEN;
- } else {
- OS.ShowWindow (handle, OS.SW_HIDE);
- }
- if (isDisposed ()) return;
- sendEvent (SWT.Hide);
- }
-}
-
-void sort (Image [] images, ImageData [] datas, int width, int height, int depth) {
- /* Shell Sort from K&R, pg 108 */
- int length = images.length;
- if (length <= 1) return;
- for (int gap=length/2; gap>0; gap/=2) {
- for (int i=gap; i<length; i++) {
- for (int j=i-gap; j>=0; j-=gap) {
- if (compare (datas [j], datas [j + gap], width, height, depth) >= 0) {
- Image swap = images [j];
- images [j] = images [j + gap];
- images [j + gap] = swap;
- ImageData swapData = datas [j];
- datas [j] = datas [j + gap];
- datas [j + gap] = swapData;
- }
- }
- }
- }
-}
-
-boolean translateAccelerator (MSG msg) {
- if (!isEnabled () || !isActive ()) return false;
- if (menuBar != null && !menuBar.isEnabled ()) return false;
- if (translateMDIAccelerator (msg) || translateMenuAccelerator (msg)) return true;
- Decorations decorations = parent.menuShell ();
- return decorations.translateAccelerator (msg);
-}
-
-boolean translateMenuAccelerator (MSG msg) {
- if (hAccel == -1) createAccelerators ();
- return hAccel != 0 && OS.TranslateAccelerator (handle, hAccel, msg) != 0;
-}
-
-boolean translateMDIAccelerator (MSG msg) {
- if (!(this instanceof Shell)) {
- Shell shell = getShell ();
- int /*long*/ hwndMDIClient = shell.hwndMDIClient;
- if (hwndMDIClient != 0 && OS.TranslateMDISysAccel (hwndMDIClient, msg)) {
- return true;
- }
- if (msg.message == OS.WM_KEYDOWN) {
- if (OS.GetKeyState (OS.VK_CONTROL) >= 0) return false;
- switch ((int)/*64*/(msg.wParam)) {
- case OS.VK_F4:
- OS.PostMessage (handle, OS.WM_CLOSE, 0, 0);
- return true;
- case OS.VK_F6:
- if (traverseDecorations (true)) return true;
- }
- return false;
- }
- if (msg.message == OS.WM_SYSKEYDOWN) {
- switch ((int)/*64*/(msg.wParam)) {
- case OS.VK_F4:
- OS.PostMessage (shell.handle, OS.WM_CLOSE, 0, 0);
- return true;
- }
- return false;
- }
- }
- return false;
-}
-
-boolean traverseDecorations (boolean next) {
- Control [] children = parent._getChildren ();
- int length = children.length;
- int index = 0;
- while (index < length) {
- if (children [index] == this) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- int start = index, offset = (next) ? 1 : -1;
- while ((index = (index + offset + length) % length) != start) {
- Control child = children [index];
- if (!child.isDisposed () && child instanceof Decorations) {
- if (child.setFocus ()) return true;
- }
- }
- return false;
-}
-
-boolean traverseItem (boolean next) {
- return false;
-}
-
-boolean traverseReturn () {
- if (defaultButton == null || defaultButton.isDisposed ()) return false;
- if (!defaultButton.isVisible () || !defaultButton.isEnabled ()) return false;
- defaultButton.click ();
- return true;
-}
-
-CREATESTRUCT widgetCreateStruct () {
- return new CREATESTRUCT ();
-}
-
-int widgetExtStyle () {
- int bits = super.widgetExtStyle () | OS.WS_EX_MDICHILD;
- bits &= ~OS.WS_EX_CLIENTEDGE;
- if ((style & SWT.NO_TRIM) != 0) return bits;
- if (OS.IsPPC) {
- if ((style & SWT.CLOSE) != 0) bits |= OS.WS_EX_CAPTIONOKBTN;
- }
- if ((style & SWT.RESIZE) != 0) return bits;
- if ((style & SWT.BORDER) != 0) bits |= OS.WS_EX_DLGMODALFRAME;
- return bits;
-}
-
-int /*long*/ widgetParent () {
- Shell shell = getShell ();
- return shell.hwndMDIClient ();
-}
-
-int widgetStyle () {
- /*
- * Clear WS_VISIBLE and WS_TABSTOP. NOTE: In Windows, WS_TABSTOP
- * has the same value as WS_MAXIMIZEBOX so these bits cannot be
- * used to control tabbing.
- */
- int bits = super.widgetStyle () & ~(OS.WS_TABSTOP | OS.WS_VISIBLE);
-
- /* Set the title bits and no-trim bits */
- bits &= ~OS.WS_BORDER;
- if ((style & SWT.NO_TRIM) != 0) return bits;
- if ((style & SWT.TITLE) != 0) bits |= OS.WS_CAPTION;
-
- /* Set the min and max button bits */
- if ((style & SWT.MIN) != 0) bits |= OS.WS_MINIMIZEBOX;
- if ((style & SWT.MAX) != 0) bits |= OS.WS_MAXIMIZEBOX;
-
- /* Set the resize, dialog border or border bits */
- if ((style & SWT.RESIZE) != 0) {
- /*
- * Note on WinCE PPC. SWT.RESIZE is used to resize
- * the Shell according to the state of the IME.
- * It does not set the WS_THICKFRAME style.
- */
- if (!OS.IsPPC) bits |= OS.WS_THICKFRAME;
- } else {
- if ((style & SWT.BORDER) == 0) bits |= OS.WS_BORDER;
- }
-
- /* Set the system menu and close box bits */
- if (!OS.IsPPC && !OS.IsSP) {
- if ((style & SWT.CLOSE) != 0) bits |= OS.WS_SYSMENU;
- }
-
- return bits;
-}
-
-int /*long*/ windowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- switch (msg) {
- case Display.SWT_GETACCEL:
- case Display.SWT_GETACCELCOUNT:
- if (hAccel == -1) createAccelerators ();
- return msg == Display.SWT_GETACCELCOUNT ? nAccel : hAccel;
- }
- return super.windowProc (hwnd, msg, wParam, lParam);
-}
-
-LRESULT WM_ACTIVATE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_ACTIVATE (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in AWT. When an AWT Window is activated,
- * for some reason, it seems to forward the WM_ACTIVATE
- * message to the parent. Normally, the parent is an
- * AWT Frame. When AWT is embedded in SWT, the SWT
- * shell gets the WM_ACTIVATE and assumes that it came
- * from Windows. When an SWT shell is activated it
- * restores focus to the last control that had focus.
- * If this control is an embedded composite, it takes
- * focus from the AWT Window. The fix is to ignore
- * WM_ACTIVATE messages that come from AWT Windows.
- */
- if (OS.GetParent (lParam) == handle) {
- TCHAR buffer = new TCHAR (0, 128);
- OS.GetClassName (lParam, buffer, buffer.length ());
- String className = buffer.toString (0, buffer.strlen ());
- if (className.equals (Display.AWT_WINDOW_CLASS)) {
- return LRESULT.ZERO;
- }
- }
- if (OS.LOWORD (wParam) != 0) {
- /*
- * When the high word of wParam is non-zero, the activation
- * state of the window is being changed while the window is
- * minimized. If this is the case, do not report activation
- * events or restore the focus.
- */
- if (OS.HIWORD (wParam) != 0) return result;
- Control control = display.findControl (lParam);
- if (control == null || control instanceof Shell) {
- if (this instanceof Shell) {
- sendEvent (SWT.Activate);
- if (isDisposed ()) return LRESULT.ZERO;
- }
- }
- if (restoreFocus ()) return LRESULT.ZERO;
- } else {
- Display display = this.display;
- boolean lockWindow = display.isXMouseActive ();
- if (lockWindow) display.lockActiveWindow = true;
- Control control = display.findControl (lParam);
- if (control == null || control instanceof Shell) {
- if (this instanceof Shell) {
- sendEvent (SWT.Deactivate);
- if (!isDisposed ()) {
- Shell shell = getShell ();
- shell.setActiveControl (null);
- // widget could be disposed at this point
- }
- }
- }
- if (lockWindow) display.lockActiveWindow = false;
- if (isDisposed ()) return LRESULT.ZERO;
- saveFocus ();
- }
- return result;
-}
-
-LRESULT WM_CLOSE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_CLOSE (wParam, lParam);
- if (result != null) return result;
- if (isEnabled () && isActive ()) closeWidget ();
- return LRESULT.ZERO;
-}
-
-LRESULT WM_HOTKEY (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_HOTKEY (wParam, lParam);
- if (result != null) return result;
- if (OS.IsSP) {
- /*
- * Feature on WinCE SP. The Back key is either used to close
- * the foreground Dialog or used as a regular Back key in an EDIT
- * control. The article 'Back Key' in MSDN for Smartphone
- * describes how an application should handle it. The
- * workaround is to override the Back key when creating
- * the menubar and handle it based on the style of the Shell.
- * If the Shell has the SWT.CLOSE style, close the Shell.
- * Otherwise, send the Back key to the window with focus.
- */
- if (OS.HIWORD (lParam) == OS.VK_ESCAPE) {
- if ((style & SWT.CLOSE) != 0) {
- OS.PostMessage (handle, OS.WM_CLOSE, 0, 0);
- } else {
- OS.SHSendBackToFocusWindow (OS.WM_HOTKEY, wParam, lParam);
- }
- return LRESULT.ZERO;
- }
- }
- return result;
-}
-
-LRESULT WM_KILLFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_KILLFOCUS (wParam, lParam);
- saveFocus ();
- return result;
-}
-
-LRESULT WM_MOVE (int /*long*/ wParam, int /*long*/ lParam) {
- if (moved) {
- Point location = getLocation ();
- if (location.x == oldX && location.y == oldY) {
- return null;
- }
- oldX = location.x;
- oldY = location.y;
- }
- return super.WM_MOVE (wParam, lParam);
-}
-
-LRESULT WM_NCACTIVATE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_NCACTIVATE (wParam, lParam);
- if (result != null) return result;
- if (wParam == 0) {
- if (display.lockActiveWindow) return LRESULT.ZERO;
- Control control = display.findControl (lParam);
- if (control != null) {
- Shell shell = getShell ();
- Decorations decorations = control.menuShell ();
- if (decorations.getShell () == shell) {
- if (this instanceof Shell) return LRESULT.ONE;
- if (display.ignoreRestoreFocus) {
- if (display.lastHittest != OS.HTCLIENT) {
- result = LRESULT.ONE;
- }
- }
- }
- }
- }
- if (!(this instanceof Shell)) {
- int /*long*/ hwndShell = getShell().handle;
- OS.SendMessage (hwndShell, OS.WM_NCACTIVATE, wParam, lParam);
- }
- return result;
-}
-
-LRESULT WM_QUERYOPEN (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_QUERYOPEN (wParam, lParam);
- if (result != null) return result;
- sendEvent (SWT.Deiconify);
- // widget could be disposed at this point
- return result;
-}
-
-LRESULT WM_SETFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SETFOCUS (wParam, lParam);
- if (savedFocus != this) restoreFocus ();
- return result;
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = null;
- boolean changed = true;
- if (resized) {
- int newWidth = 0, newHeight = 0;
- switch ((int)/*64*/wParam) {
- case OS.SIZE_RESTORED:
- case OS.SIZE_MAXIMIZED:
- newWidth = OS.LOWORD (lParam);
- newHeight = OS.HIWORD (lParam);
- break;
- case OS.SIZE_MINIMIZED:
- Rectangle rect = getClientArea ();
- newWidth = rect.width;
- newHeight = rect.height;
- break;
- }
- changed = newWidth != oldWidth || newHeight != oldHeight;
- if (changed) {
- oldWidth = newWidth;
- oldHeight = newHeight;
- }
- }
- if (changed) {
- result = super.WM_SIZE (wParam, lParam);
- if (isDisposed ()) return result;
- }
- if (wParam == OS.SIZE_MINIMIZED) {
- sendEvent (SWT.Iconify);
- // widget could be disposed at this point
- }
- return result;
-}
-
-LRESULT WM_SYSCOMMAND (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SYSCOMMAND (wParam, lParam);
- if (result != null) return result;
- if (!(this instanceof Shell)) {
- int cmd = (int)/*64*/wParam & 0xFFF0;
- switch (cmd) {
- case OS.SC_CLOSE: {
- OS.PostMessage (handle, OS.WM_CLOSE, 0, 0);
- return LRESULT.ZERO;
- }
- case OS.SC_NEXTWINDOW: {
- traverseDecorations (true);
- return LRESULT.ZERO;
- }
- }
- }
- return result;
-}
-
-LRESULT WM_WINDOWPOSCHANGING (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_WINDOWPOSCHANGING (wParam, lParam);
- if (result != null) return result;
- if (display.lockActiveWindow) {
- WINDOWPOS lpwp = new WINDOWPOS ();
- OS.MoveMemory (lpwp, lParam, WINDOWPOS.sizeof);
- lpwp.flags |= OS.SWP_NOZORDER;
- OS.MoveMemory (lParam, lpwp, WINDOWPOS.sizeof);
- }
- return result;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DirectoryDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DirectoryDialog.java
deleted file mode 100755
index 2c77b650dd..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DirectoryDialog.java
+++ /dev/null
@@ -1,310 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class allow the user to navigate
- * the file system and select a directory.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#directorydialog">DirectoryDialog snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class DirectoryDialog extends Dialog {
- String message = "", filterPath = ""; //$NON-NLS-1$//$NON-NLS-2$
- String directoryPath;
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public DirectoryDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public DirectoryDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-int /*long*/ BrowseCallbackProc (int /*long*/ hwnd, int /*long*/ uMsg, int /*long*/ lParam, int /*long*/ lpData) {
- switch ((int)/*64*/uMsg) {
- case OS.BFFM_INITIALIZED:
- if (filterPath != null && filterPath.length () != 0) {
- /* Use the character encoding for the default locale */
- TCHAR buffer = new TCHAR (0, filterPath.replace ('/', '\\'), true);
- OS.SendMessage (hwnd, OS.BFFM_SETSELECTION, 1, buffer);
- }
- if (title != null && title.length () != 0) {
- /* Use the character encoding for the default locale */
- TCHAR buffer = new TCHAR (0, title, true);
- OS.SetWindowText (hwnd, buffer);
- }
- break;
- case OS.BFFM_VALIDATEFAILEDA:
- case OS.BFFM_VALIDATEFAILEDW:
- /* Use the character encoding for the default locale */
- int length = OS.IsUnicode ? OS.wcslen (lParam) : OS.strlen (lParam);
- TCHAR buffer = new TCHAR (0, length);
- int byteCount = buffer.length () * TCHAR.sizeof;
- OS.MoveMemory (buffer, lParam, byteCount);
- directoryPath = buffer.toString (0, length);
- break;
- }
- return 0;
-}
-
-/**
- * Returns the path which the dialog will use to filter
- * the directories it shows.
- *
- * @return the filter path
- *
- * @see #setFilterPath
- */
-public String getFilterPath () {
- return filterPath;
-}
-
-/**
- * Returns the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @return the message
- */
-public String getMessage () {
- return message;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a string describing the absolute path of the selected directory,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public String open () {
- if (OS.IsWinCE) SWT.error (SWT.ERROR_NOT_IMPLEMENTED);
-
- int /*long*/ hHeap = OS.GetProcessHeap ();
-
- /* Get the owner HWND for the dialog */
- int /*long*/ hwndOwner = 0;
- if (parent != null) hwndOwner = parent.handle;
-
- /* Copy the message to OS memory */
- int /*long*/ lpszTitle = 0;
- if (message.length () != 0) {
- String string = message;
- if (string.indexOf ('&') != -1) {
- int length = string.length ();
- char [] buffer = new char [length * 2];
- int index = 0;
- for (int i=0; i<length; i++) {
- char ch = string.charAt (i);
- if (ch == '&') buffer [index++] = '&';
- buffer [index++] = ch;
- }
- string = new String (buffer, 0, index);
- }
- /* Use the character encoding for the default locale */
- TCHAR buffer = new TCHAR (0, string, true);
- int byteCount = buffer.length () * TCHAR.sizeof;
- lpszTitle = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (lpszTitle, buffer, byteCount);
- }
-
- /* Create the BrowseCallbackProc */
- Callback callback = new Callback (this, "BrowseCallbackProc", 4); //$NON-NLS-1$
- int /*long*/ lpfn = callback.getAddress ();
- if (lpfn == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- /* Make the parent shell be temporary modal */
- Dialog oldModal = null;
- Display display = parent.getDisplay ();
- if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- oldModal = display.getModalDialog ();
- display.setModalDialog (this);
- }
-
- directoryPath = null;
- BROWSEINFO lpbi = new BROWSEINFO ();
- lpbi.hwndOwner = hwndOwner;
- lpbi.lpszTitle = lpszTitle;
- lpbi.ulFlags = OS.BIF_NEWDIALOGSTYLE | OS.BIF_RETURNONLYFSDIRS | OS.BIF_EDITBOX | OS.BIF_VALIDATE;
- lpbi.lpfn = lpfn;
- /*
- * Bug in Windows. On some hardware configurations, SHBrowseForFolder()
- * causes warning dialogs with the message "There is no disk in the drive
- * Please insert a disk into \Device\Harddisk0\DR0". This is possibly
- * caused by SHBrowseForFolder() calling internally GetVolumeInformation().
- * MSDN for GetVolumeInformation() says:
- *
- * "If you are attempting to obtain information about a floppy drive
- * that does not have a floppy disk or a CD-ROM drive that does not
- * have a compact disc, the system displays a message box asking the
- * user to insert a floppy disk or a compact disc, respectively.
- * To prevent the system from displaying this message box, call the
- * SetErrorMode function with SEM_FAILCRITICALERRORS."
- *
- * The fix is to save and restore the error mode using SetErrorMode()
- * with the SEM_FAILCRITICALERRORS flag around SHBrowseForFolder().
- */
- int oldErrorMode = OS.SetErrorMode (OS.SEM_FAILCRITICALERRORS);
-
- /*
- * Bug in Windows. When a WH_MSGFILTER hook is used to run code
- * during the message loop for SHBrowseForFolder(), running code
- * in the hook can cause a GP. Specifically, SetWindowText()
- * for static controls seemed to make the problem happen.
- * The fix is to disable async messages while the directory
- * dialog is open.
- *
- * NOTE: This only happens in versions of the comctl32.dll
- * earlier than 6.0.
- */
- boolean oldRunMessages = display.runMessages;
- if (OS.COMCTL32_MAJOR < 6) display.runMessages = false;
- int /*long*/ lpItemIdList = OS.SHBrowseForFolder (lpbi);
- if (OS.COMCTL32_MAJOR < 6) display.runMessages = oldRunMessages;
- OS.SetErrorMode (oldErrorMode);
-
- /* Clear the temporary dialog modal parent */
- if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- display.setModalDialog (oldModal);
- }
-
- boolean success = lpItemIdList != 0;
- if (success) {
- /* Use the character encoding for the default locale */
- TCHAR buffer = new TCHAR (0, OS.MAX_PATH);
- if (OS.SHGetPathFromIDList (lpItemIdList, buffer)) {
- directoryPath = buffer.toString (0, buffer.strlen ());
- filterPath = directoryPath;
- }
- }
-
- /* Free the BrowseCallbackProc */
- callback.dispose ();
-
- /* Free the OS memory */
- if (lpszTitle != 0) OS.HeapFree (hHeap, 0, lpszTitle);
-
- /* Free the pointer to the ITEMIDLIST */
- int /*long*/ [] ppMalloc = new int /*long*/ [1];
- if (OS.SHGetMalloc (ppMalloc) == OS.S_OK) {
- /* void Free (struct IMalloc *this, void *pv); */
- OS.VtblCall (5, ppMalloc [0], lpItemIdList);
- }
-
- /*
- * This code is intentionally commented. On some
- * platforms, the owner window is repainted right
- * away when a dialog window exits. This behavior
- * is currently unspecified.
- */
-// if (hwndOwner != 0) OS.UpdateWindow (hwndOwner);
-
- /* Return the directory path */
- if (!success) return null;
- return directoryPath;
-}
-
-/**
- * Sets the path that the dialog will use to filter
- * the directories it shows to the argument, which may
- * be null. If the string is null, then the operating
- * system's default filter path will be used.
- * <p>
- * Note that the path string is platform dependent.
- * For convenience, either '/' or '\' can be used
- * as a path separator.
- * </p>
- *
- * @param string the filter path
- */
-public void setFilterPath (String string) {
- filterPath = string;
-}
-
-/**
- * Sets the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @param string the message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- */
-public void setMessage (String string) {
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- message = string;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
deleted file mode 100755
index e3a2fee7b8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
+++ /dev/null
@@ -1,4653 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are responsible for managing the
- * connection between SWT and the underlying operating
- * system. Their most important function is to implement
- * the SWT event loop in terms of the platform event model.
- * They also provide various methods for accessing information
- * about the operating system, and have overall control over
- * the operating system resources which SWT allocates.
- * <p>
- * Applications which are built with SWT will <em>almost always</em>
- * require only a single display. In particular, some platforms
- * which SWT supports will not allow more than one <em>active</em>
- * display. In other words, some platforms do not support
- * creating a new display if one already exists that has not been
- * sent the <code>dispose()</code> message.
- * <p>
- * In SWT, the thread which creates a <code>Display</code>
- * instance is distinguished as the <em>user-interface thread</em>
- * for that display.
- * </p>
- * The user-interface thread for a particular display has the
- * following special attributes:
- * <ul>
- * <li>
- * The event loop for that display must be run from the thread.
- * </li>
- * <li>
- * Some SWT API methods (notably, most of the public methods in
- * <code>Widget</code> and its subclasses), may only be called
- * from the thread. (To support multi-threaded user-interface
- * applications, class <code>Display</code> provides inter-thread
- * communication methods which allow threads other than the
- * user-interface thread to request that it perform operations
- * on their behalf.)
- * </li>
- * <li>
- * The thread is not allowed to construct other
- * <code>Display</code>s until that display has been disposed.
- * (Note that, this is in addition to the restriction mentioned
- * above concerning platform support for multiple displays. Thus,
- * the only way to have multiple simultaneously active displays,
- * even on platforms which support it, is to have multiple threads.)
- * </li>
- * </ul>
- * Enforcing these attributes allows SWT to be implemented directly
- * on the underlying operating system's event model. This has
- * numerous benefits including smaller footprint, better use of
- * resources, safer memory management, clearer program logic,
- * better performance, and fewer overall operating system threads
- * required. The down side however, is that care must be taken
- * (only) when constructing multi-threaded applications to use the
- * inter-thread communication mechanisms which this class provides
- * when required.
- * </p><p>
- * All SWT API methods which may only be called from the user-interface
- * thread are distinguished in their documentation by indicating that
- * they throw the "<code>ERROR_THREAD_INVALID_ACCESS</code>"
- * SWT exception.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Close, Dispose, Settings</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- * @see #syncExec
- * @see #asyncExec
- * @see #wake
- * @see #readAndDispatch
- * @see #sleep
- * @see Device#dispose
- * @see <a href="http://www.eclipse.org/swt/snippets/#display">Display snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Display extends Device {
-
- /**
- * the handle to the OS message queue
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public MSG msg = new MSG ();
-
- /* Windows and Events */
- Event [] eventQueue;
- Callback windowCallback;
- int /*long*/ windowProc;
- int threadId;
- TCHAR windowClass, windowShadowClass, windowOwnDCClass;
- static int WindowClassCount;
- static final String WindowName = "SWT_Window"; //$NON-NLS-1$
- static final String WindowShadowName = "SWT_WindowShadow"; //$NON-NLS-1$
- static final String WindowOwnDCName = "SWT_WindowOwnDC"; //$NON-NLS-1$
- EventTable eventTable, filterTable;
- boolean useOwnDC;
-
- /* Widget Table */
- int freeSlot;
- int [] indexTable;
- Control lastControl, lastGetControl;
- int /*long*/ lastHwnd, lastGetHwnd;
- Control [] controlTable;
- static final int GROW_SIZE = 1024;
- static final int SWT_OBJECT_INDEX;
- static final boolean USE_PROPERTY = !OS.IsWinCE;
- static {
- if (USE_PROPERTY) {
- SWT_OBJECT_INDEX = OS.GlobalAddAtom (new TCHAR (0, "SWT_OBJECT_INDEX", true)); //$NON-NLS-1$
- } else {
- SWT_OBJECT_INDEX = 0;
- }
- }
-
- /* Startup info */
- static STARTUPINFO lpStartupInfo;
- static {
- if (!OS.IsWinCE) {
- lpStartupInfo = new STARTUPINFO ();
- lpStartupInfo.cb = STARTUPINFO.sizeof;
- OS.GetStartupInfo (lpStartupInfo);
- }
- }
-
- /* XP Themes */
- int /*long*/ hButtonTheme, hEditTheme, hExplorerBarTheme, hScrollBarTheme, hTabTheme;
- static final char [] BUTTON = new char [] {'B', 'U', 'T', 'T', 'O', 'N', 0};
- static final char [] EDIT = new char [] {'E', 'D', 'I', 'T', 0};
- static final char [] EXPLORER = new char [] {'E', 'X', 'P', 'L', 'O', 'R', 'E', 'R', 0};
- static final char [] EXPLORERBAR = new char [] {'E', 'X', 'P', 'L', 'O', 'R', 'E', 'R', 'B', 'A', 'R', 0};
- static final char [] SCROLLBAR = new char [] {'S', 'C', 'R', 'O', 'L', 'L', 'B', 'A', 'R', 0};
- static final char [] LISTVIEW = new char [] {'L', 'I', 'S', 'T', 'V', 'I', 'E', 'W', 0};
- static final char [] TAB = new char [] {'T', 'A', 'B', 0};
- static final char [] TREEVIEW = new char [] {'T', 'R', 'E', 'E', 'V', 'I', 'E', 'W', 0};
-
- /* Focus */
- int focusEvent;
- Control focusControl;
-
- /* Menus */
- Menu [] bars, popups;
- MenuItem [] items;
-
- /*
- * The start value for WM_COMMAND id's.
- * Windows reserves the values 0..100.
- *
- * The SmartPhone SWT resource file reserves
- * the values 101..107.
- */
- static final int ID_START = 108;
-
- /* Filter Hook */
- Callback msgFilterCallback;
- int /*long*/ msgFilterProc, filterHook;
- MSG hookMsg = new MSG ();
- boolean runDragDrop = true, dragCancelled = false;
-
- /* Idle Hook */
- Callback foregroundIdleCallback;
- int /*long*/ foregroundIdleProc, idleHook;
-
- /* Message Hook and Embedding */
- boolean ignoreNextKey;
- Callback getMsgCallback, embeddedCallback;
- int /*long*/ getMsgProc, msgHook, embeddedHwnd, embeddedProc;
- static final String AWT_WINDOW_CLASS = "SunAwtWindow"; //$NON-NLS-1$
- static final short [] ACCENTS = new short [] {'~', '`', '\'', '^', '"'};
-
- /* Sync/Async Widget Communication */
- Synchronizer synchronizer = new Synchronizer (this);
- boolean runMessages = true, runMessagesInIdle = false, runMessagesInMessageProc = true;
- static final String RUN_MESSAGES_IN_IDLE_KEY = "org.eclipse.swt.internal.win32.runMessagesInIdle"; //$NON-NLS-1$
- static final String RUN_MESSAGES_IN_MESSAGE_PROC_KEY = "org.eclipse.swt.internal.win32.runMessagesInMessageProc"; //$NON-NLS-1$
- static final String USE_OWNDC_KEY = "org.eclipse.swt.internal.win32.useOwnDC"; //$NON-NLS-1$
- Thread thread;
-
- /* Display Shutdown */
- Runnable [] disposeList;
-
- /* System Tray */
- Tray tray;
- int nextTrayId;
-
- /* Timers */
- int /*long*/ [] timerIds;
- Runnable [] timerList;
- int /*long*/ nextTimerId = SETTINGS_ID + 1;
-
- /* Settings */
- static final int /*long*/ SETTINGS_ID = 100;
- static final int SETTINGS_DELAY = 2000;
- boolean lastHighContrast, sendSettings;
-
- /* Keyboard and Mouse */
- RECT clickRect;
- int clickCount, lastTime, lastButton;
- int /*long*/ lastClickHwnd;
- int scrollRemainder;
- int lastKey, lastAscii, lastMouse;
- boolean lastVirtual, lastNull, lastDead;
- byte [] keyboard = new byte [256];
- boolean accelKeyHit, mnemonicKeyHit;
- boolean lockActiveWindow, captureChanged, xMouse;
-
- /* Tool Tips */
- int nextToolTipId;
-
- /* MDI */
- boolean ignoreRestoreFocus;
- Control lastHittestControl;
- int lastHittest;
-
- /* Message Only Window */
- Callback messageCallback;
- int /*long*/ hwndMessage, messageProc;
-
- /* System Resources */
- LOGFONT lfSystemFont;
- Font systemFont;
- Image errorImage, infoImage, questionImage, warningIcon;
- Cursor [] cursors = new Cursor [SWT.CURSOR_HAND + 1];
- Resource [] resources;
- static final int RESOURCE_SIZE = 1 + 4 + SWT.CURSOR_HAND + 1;
-
- /* ImageList Cache */
- ImageList[] imageList, toolImageList, toolHotImageList, toolDisabledImageList;
-
- /* Custom Colors for ChooseColor */
- int /*long*/ lpCustColors;
-
- /* Sort Indicators */
- Image upArrow, downArrow;
-
- /* Table */
- char [] tableBuffer;
- NMHDR hdr = new NMHDR ();
- NMLVDISPINFO plvfi = new NMLVDISPINFO ();
- int /*long*/ hwndParent;
- int columnCount;
- boolean [] columnVisible;
-
- /* Resize and move recursion */
- int resizeCount;
- static final int RESIZE_LIMIT = 4;
-
- /* Display Data */
- Object data;
- String [] keys;
- Object [] values;
-
- /* Key Mappings */
- static final int [] [] KeyTable = {
-
- /* Keyboard and Mouse Masks */
- {OS.VK_MENU, SWT.ALT},
- {OS.VK_SHIFT, SWT.SHIFT},
- {OS.VK_CONTROL, SWT.CONTROL},
-// {OS.VK_????, SWT.COMMAND},
-
- /* NOT CURRENTLY USED */
-// {OS.VK_LBUTTON, SWT.BUTTON1},
-// {OS.VK_MBUTTON, SWT.BUTTON3},
-// {OS.VK_RBUTTON, SWT.BUTTON2},
-
- /* Non-Numeric Keypad Keys */
- {OS.VK_UP, SWT.ARROW_UP},
- {OS.VK_DOWN, SWT.ARROW_DOWN},
- {OS.VK_LEFT, SWT.ARROW_LEFT},
- {OS.VK_RIGHT, SWT.ARROW_RIGHT},
- {OS.VK_PRIOR, SWT.PAGE_UP},
- {OS.VK_NEXT, SWT.PAGE_DOWN},
- {OS.VK_HOME, SWT.HOME},
- {OS.VK_END, SWT.END},
- {OS.VK_INSERT, SWT.INSERT},
-
- /* Virtual and Ascii Keys */
- {OS.VK_BACK, SWT.BS},
- {OS.VK_RETURN, SWT.CR},
- {OS.VK_DELETE, SWT.DEL},
- {OS.VK_ESCAPE, SWT.ESC},
- {OS.VK_RETURN, SWT.LF},
- {OS.VK_TAB, SWT.TAB},
-
- /* Functions Keys */
- {OS.VK_F1, SWT.F1},
- {OS.VK_F2, SWT.F2},
- {OS.VK_F3, SWT.F3},
- {OS.VK_F4, SWT.F4},
- {OS.VK_F5, SWT.F5},
- {OS.VK_F6, SWT.F6},
- {OS.VK_F7, SWT.F7},
- {OS.VK_F8, SWT.F8},
- {OS.VK_F9, SWT.F9},
- {OS.VK_F10, SWT.F10},
- {OS.VK_F11, SWT.F11},
- {OS.VK_F12, SWT.F12},
- {OS.VK_F13, SWT.F13},
- {OS.VK_F14, SWT.F14},
- {OS.VK_F15, SWT.F15},
-
- /* Numeric Keypad Keys */
- {OS.VK_MULTIPLY, SWT.KEYPAD_MULTIPLY},
- {OS.VK_ADD, SWT.KEYPAD_ADD},
- {OS.VK_RETURN, SWT.KEYPAD_CR},
- {OS.VK_SUBTRACT, SWT.KEYPAD_SUBTRACT},
- {OS.VK_DECIMAL, SWT.KEYPAD_DECIMAL},
- {OS.VK_DIVIDE, SWT.KEYPAD_DIVIDE},
- {OS.VK_NUMPAD0, SWT.KEYPAD_0},
- {OS.VK_NUMPAD1, SWT.KEYPAD_1},
- {OS.VK_NUMPAD2, SWT.KEYPAD_2},
- {OS.VK_NUMPAD3, SWT.KEYPAD_3},
- {OS.VK_NUMPAD4, SWT.KEYPAD_4},
- {OS.VK_NUMPAD5, SWT.KEYPAD_5},
- {OS.VK_NUMPAD6, SWT.KEYPAD_6},
- {OS.VK_NUMPAD7, SWT.KEYPAD_7},
- {OS.VK_NUMPAD8, SWT.KEYPAD_8},
- {OS.VK_NUMPAD9, SWT.KEYPAD_9},
-// {OS.VK_????, SWT.KEYPAD_EQUAL},
-
- /* Other keys */
- {OS.VK_CAPITAL, SWT.CAPS_LOCK},
- {OS.VK_NUMLOCK, SWT.NUM_LOCK},
- {OS.VK_SCROLL, SWT.SCROLL_LOCK},
- {OS.VK_PAUSE, SWT.PAUSE},
- {OS.VK_CANCEL, SWT.BREAK},
- {OS.VK_SNAPSHOT, SWT.PRINT_SCREEN},
-// {OS.VK_????, SWT.HELP},
-
- };
-
- /* Multiple Displays */
- static Display Default;
- static Display [] Displays = new Display [4];
-
- /* Multiple Monitors */
- Monitor[] monitors = null;
- int monitorCount = 0;
-
- /* Modality */
- Shell [] modalShells;
- Dialog modalDialog;
- static boolean TrimEnabled = false;
-
- /* Private SWT Window Messages */
- static final int SWT_GETACCELCOUNT = OS.WM_APP;
- static final int SWT_GETACCEL = OS.WM_APP + 1;
- static final int SWT_KEYMSG = OS.WM_APP + 2;
- static final int SWT_DESTROY = OS.WM_APP + 3;
- static final int SWT_TRAYICONMSG = OS.WM_APP + 4;
- static final int SWT_NULL = OS.WM_APP + 5;
- static final int SWT_RUNASYNC = OS.WM_APP + 6;
- static int SWT_TASKBARCREATED;
- static int SWT_RESTORECARET;
- static int DI_GETDRAGIMAGE;
-
- /* Workaround for Adobe Reader 7.0 */
- int hitCount;
-
- /* Package Name */
- static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets."; //$NON-NLS-1$
- /*
- * This code is intentionally commented. In order
- * to support CLDC, .class cannot be used because
- * it does not compile on some Java compilers when
- * they are targeted for CLDC.
- */
-// static {
-// String name = Display.class.getName ();
-// int index = name.lastIndexOf ('.');
-// PACKAGE_PREFIX = name.substring (0, index + 1);
-// }
-
- /*
- * TEMPORARY CODE. Install the runnable that
- * gets the current display. This code will
- * be removed in the future.
- */
- static {
- DeviceFinder = new Runnable () {
- public void run () {
- Device device = getCurrent ();
- if (device == null) {
- device = getDefault ();
- }
- setDevice (device);
- }
- };
- }
-
-/*
-* TEMPORARY CODE.
-*/
-static void setDevice (Device device) {
- CurrentDevice = device;
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * Note: The resulting display is marked as the <em>current</em>
- * display. If this is the first display which has been
- * constructed since the application started, it is also
- * marked as the <em>default</em> display.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if called from a thread that already created an existing display</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see #getCurrent
- * @see #getDefault
- * @see Widget#checkSubclass
- * @see Shell
- */
-public Display () {
- this (null);
-}
-
-/**
- * Constructs a new instance of this class using the parameter.
- *
- * @param data the device data
- */
-public Display (DeviceData data) {
- super (data);
-}
-
-Control _getFocusControl () {
- return findControl (OS.GetFocus ());
-}
-
-void addBar (Menu menu) {
- if (bars == null) bars = new Menu [4];
- int length = bars.length;
- for (int i=0; i<length; i++) {
- if (bars [i] == menu) return;
- }
- int index = 0;
- while (index < length) {
- if (bars [index] == null) break;
- index++;
- }
- if (index == length) {
- Menu [] newBars = new Menu [length + 4];
- System.arraycopy (bars, 0, newBars, 0, length);
- bars = newBars;
- }
- bars [index] = menu;
-}
-
-void addControl (int /*long*/ handle, Control control) {
- if (handle == 0) return;
- if (freeSlot == -1) {
- int length = (freeSlot = indexTable.length) + GROW_SIZE;
- int [] newIndexTable = new int [length];
- Control [] newControlTable = new Control [length];
- System.arraycopy (indexTable, 0, newIndexTable, 0, freeSlot);
- System.arraycopy (controlTable, 0, newControlTable, 0, freeSlot);
- for (int i=freeSlot; i<length-1; i++) newIndexTable [i] = i + 1;
- newIndexTable [length - 1] = -1;
- indexTable = newIndexTable;
- controlTable = newControlTable;
- }
- if (USE_PROPERTY) {
- OS.SetProp (handle, SWT_OBJECT_INDEX, freeSlot + 1);
- } else {
- OS.SetWindowLongPtr (handle, OS.GWLP_USERDATA, freeSlot + 1);
- }
- int oldSlot = freeSlot;
- freeSlot = indexTable [oldSlot];
- indexTable [oldSlot] = -2;
- controlTable [oldSlot] = control;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs anywhere
- * in a widget. The event type is one of the event constants
- * defined in class <code>SWT</code>. When the event does occur,
- * the listener is notified by sending it the <code>handleEvent()</code>
- * message.
- * <p>
- * Setting the type of an event to <code>SWT.None</code> from
- * within the <code>handleEvent()</code> method can be used to
- * change the event type and stop subsequent Java listeners
- * from running. Because event filters run before other listeners,
- * event filters can both block other listeners and set arbitrary
- * fields within an event. For this reason, event filters are both
- * powerful and dangerous. They should generally be avoided for
- * performance, debugging and code maintenance reasons.
- * </p>
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #removeFilter
- * @see #removeListener
- *
- * @since 3.0
- */
-public void addFilter (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (filterTable == null) filterTable = new EventTable ();
- filterTable.hook (eventType, listener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- * When the event does occur in the display, the listener is notified by
- * sending it the <code>handleEvent()</code> message.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #removeListener
- *
- * @since 2.0
- */
-public void addListener (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) eventTable = new EventTable ();
- eventTable.hook (eventType, listener);
-}
-
-void addMenuItem (MenuItem item) {
- if (items == null) items = new MenuItem [64];
- for (int i=0; i<items.length; i++) {
- if (items [i] == null) {
- item.id = i + ID_START;
- items [i] = item;
- return;
- }
- }
- item.id = items.length + ID_START;
- MenuItem [] newItems = new MenuItem [items.length + 64];
- newItems [items.length] = item;
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
-}
-
-void addPopup (Menu menu) {
- if (popups == null) popups = new Menu [4];
- int length = popups.length;
- for (int i=0; i<length; i++) {
- if (popups [i] == menu) return;
- }
- int index = 0;
- while (index < length) {
- if (popups [index] == null) break;
- index++;
- }
- if (index == length) {
- Menu [] newPopups = new Menu [length + 4];
- System.arraycopy (popups, 0, newPopups, 0, length);
- popups = newPopups;
- }
- popups [index] = menu;
-}
-
-int asciiKey (int key) {
- if (OS.IsWinCE) return 0;
-
- /* Get the current keyboard. */
- for (int i=0; i<keyboard.length; i++) keyboard [i] = 0;
- if (!OS.GetKeyboardState (keyboard)) return 0;
-
- /* Translate the key to ASCII or UNICODE using the virtual keyboard */
- if (OS.IsUnicode) {
- char [] result = new char [1];
- if (OS.ToUnicode (key, key, keyboard, result, 1, 0) == 1) return result [0];
- } else {
- short [] result = new short [1];
- if (OS.ToAscii (key, key, keyboard, result, 0) == 1) return result [0];
- }
- return 0;
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread at the next
- * reasonable opportunity. The caller of this method continues
- * to run in parallel, and is not notified when the
- * runnable has completed. Specifying <code>null</code> as the
- * runnable simply wakes the user-interface thread when run.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param runnable code to run on the user-interface thread or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #syncExec
- */
-public void asyncExec (Runnable runnable) {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- synchronizer.asyncExec (runnable);
- }
-}
-
-/**
- * Causes the system hardware to emit a short sound
- * (if it supports this capability).
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void beep () {
- checkDevice ();
- OS.MessageBeep (OS.MB_OK);
-}
-
-/**
- * Checks that this class can be subclassed.
- * <p>
- * IMPORTANT: See the comment in <code>Widget.checkSubclass()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- */
-protected void checkSubclass () {
- if (!isValidClass (getClass ())) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-protected void checkDevice () {
- if (thread == null) error (SWT.ERROR_WIDGET_DISPOSED);
- if (thread != Thread.currentThread ()) {
- /*
- * Bug in IBM JVM 1.6. For some reason, under
- * conditions that are yet to be full understood,
- * Thread.currentThread() is either returning null
- * or a different instance from the one that was
- * saved when the Display was created. This is
- * possibly a JIT problem because modifying this
- * method to print logging information when the
- * error happens seems to fix the problem. The
- * fix is to use operating system calls to verify
- * that the current thread is not the Display thread.
- *
- * NOTE: Despite the fact that Thread.currentThread()
- * is used in other places, the failure has not been
- * observed in all places where it is called.
- */
- if (threadId != OS.GetCurrentThreadId ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- }
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
-}
-
-static void checkDisplay (Thread thread, boolean multiple) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] != null) {
- if (!multiple) SWT.error (SWT.ERROR_NOT_IMPLEMENTED, null, " [multiple displays]"); //$NON-NLS-1$
- if (Displays [i].thread == thread) SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- }
- }
-}
-
-void clearModal (Shell shell) {
- if (modalShells == null) return;
- int index = 0, length = modalShells.length;
- while (index < length) {
- if (modalShells [index] == shell) break;
- if (modalShells [index] == null) return;
- index++;
- }
- if (index == length) return;
- System.arraycopy (modalShells, index + 1, modalShells, index, --length - index);
- modalShells [length] = null;
- if (index == 0 && modalShells [0] == null) modalShells = null;
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) shells [i].updateModal ();
-}
-
-int controlKey (int key) {
- int upper = (int)/*64*/OS.CharUpper ((short) key);
- if (64 <= upper && upper <= 95) return upper & 0xBF;
- return key;
-}
-
-/**
- * Requests that the connection between SWT and the underlying
- * operating system be closed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Device#dispose
- *
- * @since 2.0
- */
-public void close () {
- checkDevice ();
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- if (event.doit) dispose ();
-}
-
-/**
- * Creates the device in the operating system. If the device
- * does not have a handle, this method may do nothing depending
- * on the device.
- * <p>
- * This method is called before <code>init</code>.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #init
- */
-protected void create (DeviceData data) {
- checkSubclass ();
- checkDisplay (thread = Thread.currentThread (), true);
- createDisplay (data);
- register (this);
- if (Default == null) Default = this;
-}
-
-void createDisplay (DeviceData data) {
-}
-
-static int /*long*/ create32bitDIB (Image image) {
- int transparentPixel = -1, alpha = -1;
- int /*long*/ hMask = 0, hBitmap = 0;
- byte[] alphaData = null;
- switch (image.type) {
- case SWT.ICON:
- ICONINFO info = new ICONINFO ();
- OS.GetIconInfo (image.handle, info);
- hBitmap = info.hbmColor;
- hMask = info.hbmMask;
- break;
- case SWT.BITMAP:
- ImageData data = image.getImageData ();
- hBitmap = image.handle;
- alpha = data.alpha;
- alphaData = data.alphaData;
- transparentPixel = data.transparentPixel;
- break;
- }
- BITMAP bm = new BITMAP ();
- OS.GetObject (hBitmap, BITMAP.sizeof, bm);
- int imgWidth = bm.bmWidth;
- int imgHeight = bm.bmHeight;
- int /*long*/ hDC = OS.GetDC (0);
- int /*long*/ srcHdc = OS.CreateCompatibleDC (hDC);
- int /*long*/ oldSrcBitmap = OS.SelectObject (srcHdc, hBitmap);
- int /*long*/ memHdc = OS.CreateCompatibleDC (hDC);
- BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER ();
- bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
- bmiHeader.biWidth = imgWidth;
- bmiHeader.biHeight = -imgHeight;
- bmiHeader.biPlanes = 1;
- bmiHeader.biBitCount = (short)32;
- bmiHeader.biCompression = OS.BI_RGB;
- byte [] bmi = new byte [BITMAPINFOHEADER.sizeof];
- OS.MoveMemory (bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
- int /*long*/ [] pBits = new int /*long*/ [1];
- int /*long*/ memDib = OS.CreateDIBSection (0, bmi, OS.DIB_RGB_COLORS, pBits, 0, 0);
- if (memDib == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- int /*long*/ oldMemBitmap = OS.SelectObject (memHdc, memDib);
- BITMAP dibBM = new BITMAP ();
- OS.GetObject (memDib, BITMAP.sizeof, dibBM);
- int sizeInBytes = dibBM.bmWidthBytes * dibBM.bmHeight;
- OS.BitBlt (memHdc, 0, 0, imgWidth, imgHeight, srcHdc, 0, 0, OS.SRCCOPY);
- byte red = 0, green = 0, blue = 0;
- if (transparentPixel != -1) {
- if (bm.bmBitsPixel <= 8) {
- byte [] color = new byte [4];
- OS.GetDIBColorTable (srcHdc, transparentPixel, 1, color);
- blue = color [0];
- green = color [1];
- red = color [2];
- } else {
- switch (bm.bmBitsPixel) {
- case 16:
- blue = (byte)((transparentPixel & 0x1F) << 3);
- green = (byte)((transparentPixel & 0x3E0) >> 2);
- red = (byte)((transparentPixel & 0x7C00) >> 7);
- break;
- case 24:
- blue = (byte)((transparentPixel & 0xFF0000) >> 16);
- green = (byte)((transparentPixel & 0xFF00) >> 8);
- red = (byte)(transparentPixel & 0xFF);
- break;
- case 32:
- blue = (byte)((transparentPixel & 0xFF000000) >>> 24);
- green = (byte)((transparentPixel & 0xFF0000) >> 16);
- red = (byte)((transparentPixel & 0xFF00) >> 8);
- break;
- }
- }
- }
- byte [] srcData = new byte [sizeInBytes];
- OS.MoveMemory (srcData, pBits [0], sizeInBytes);
- if (hMask != 0) {
- OS.SelectObject(srcHdc, hMask);
- for (int y = 0, dp = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- if (OS.GetPixel(srcHdc, x, y) != 0) {
- srcData [dp + 0] = srcData [dp + 1] = srcData [dp + 2] = srcData[dp + 3] = (byte)0;
- } else {
- srcData[dp + 3] = (byte)0xFF;
- }
- dp += 4;
- }
- }
- } else if (alpha != -1) {
- for (int y = 0, dp = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- srcData [dp + 3] = (byte)alpha;
- if (srcData [dp + 3] == 0) srcData [dp + 0] = srcData [dp + 1] = srcData [dp + 2] = 0;
- dp += 4;
- }
- }
- } else if (alphaData != null) {
- for (int y = 0, dp = 0, ap = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- srcData [dp + 3] = alphaData [ap++];
- if (srcData [dp + 3] == 0) srcData [dp + 0] = srcData [dp + 1] = srcData [dp + 2] = 0;
- dp += 4;
- }
- }
- } else if (transparentPixel != -1) {
- for (int y = 0, dp = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- if (srcData [dp] == blue && srcData [dp + 1] == green && srcData [dp + 2] == red) {
- srcData [dp + 0] = srcData [dp + 1] = srcData [dp + 2] = srcData [dp + 3] = (byte)0;
- } else {
- srcData [dp + 3] = (byte)0xFF;
- }
- dp += 4;
- }
- }
- } else {
- for (int y = 0, dp = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- srcData [dp + 3] = (byte)0xFF;
- dp += 4;
- }
- }
- }
- OS.MoveMemory (pBits [0], srcData, sizeInBytes);
- OS.SelectObject (srcHdc, oldSrcBitmap);
- OS.SelectObject (memHdc, oldMemBitmap);
- OS.DeleteObject (srcHdc);
- OS.DeleteObject (memHdc);
- OS.ReleaseDC (0, hDC);
- if (hBitmap != image.handle && hBitmap != 0) OS.DeleteObject (hBitmap);
- if (hMask != 0) OS.DeleteObject (hMask);
- return memDib;
-}
-static int /*long*/ create32bitDIB (int /*long*/ hBitmap, int alpha, byte [] alphaData, int transparentPixel) {
- BITMAP bm = new BITMAP ();
- OS.GetObject (hBitmap, BITMAP.sizeof, bm);
- int imgWidth = bm.bmWidth;
- int imgHeight = bm.bmHeight;
- int /*long*/ hDC = OS.GetDC (0);
- int /*long*/ srcHdc = OS.CreateCompatibleDC (hDC);
- int /*long*/ oldSrcBitmap = OS.SelectObject (srcHdc, hBitmap);
- int /*long*/ memHdc = OS.CreateCompatibleDC (hDC);
- BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER ();
- bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
- bmiHeader.biWidth = imgWidth;
- bmiHeader.biHeight = -imgHeight;
- bmiHeader.biPlanes = 1;
- bmiHeader.biBitCount = (short)32;
- bmiHeader.biCompression = OS.BI_RGB;
- byte [] bmi = new byte [BITMAPINFOHEADER.sizeof];
- OS.MoveMemory (bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
- int /*long*/ [] pBits = new int /*long*/ [1];
- int /*long*/ memDib = OS.CreateDIBSection (0, bmi, OS.DIB_RGB_COLORS, pBits, 0, 0);
- if (memDib == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- int /*long*/ oldMemBitmap = OS.SelectObject (memHdc, memDib);
- BITMAP dibBM = new BITMAP ();
- OS.GetObject (memDib, BITMAP.sizeof, dibBM);
- int sizeInBytes = dibBM.bmWidthBytes * dibBM.bmHeight;
- OS.BitBlt (memHdc, 0, 0, imgWidth, imgHeight, srcHdc, 0, 0, OS.SRCCOPY);
- byte red = 0, green = 0, blue = 0;
- if (transparentPixel != -1) {
- if (bm.bmBitsPixel <= 8) {
- byte [] color = new byte [4];
- OS.GetDIBColorTable (srcHdc, transparentPixel, 1, color);
- blue = color [0];
- green = color [1];
- red = color [2];
- } else {
- switch (bm.bmBitsPixel) {
- case 16:
- blue = (byte)((transparentPixel & 0x1F) << 3);
- green = (byte)((transparentPixel & 0x3E0) >> 2);
- red = (byte)((transparentPixel & 0x7C00) >> 7);
- break;
- case 24:
- blue = (byte)((transparentPixel & 0xFF0000) >> 16);
- green = (byte)((transparentPixel & 0xFF00) >> 8);
- red = (byte)(transparentPixel & 0xFF);
- break;
- case 32:
- blue = (byte)((transparentPixel & 0xFF000000) >>> 24);
- green = (byte)((transparentPixel & 0xFF0000) >> 16);
- red = (byte)((transparentPixel & 0xFF00) >> 8);
- break;
- }
- }
- }
- OS.SelectObject (srcHdc, oldSrcBitmap);
- OS.SelectObject (memHdc, oldMemBitmap);
- OS.DeleteObject (srcHdc);
- OS.DeleteObject (memHdc);
- OS.ReleaseDC (0, hDC);
- byte [] srcData = new byte [sizeInBytes];
- OS.MoveMemory (srcData, pBits [0], sizeInBytes);
- if (alpha != -1) {
- for (int y = 0, dp = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- srcData [dp + 3] = (byte)alpha;
- dp += 4;
- }
- }
- } else if (alphaData != null) {
- for (int y = 0, dp = 0, ap = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- srcData [dp + 3] = alphaData [ap++];
- dp += 4;
- }
- }
- } else if (transparentPixel != -1) {
- for (int y = 0, dp = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- if (srcData [dp] == blue && srcData [dp + 1] == green && srcData [dp + 2] == red) {
- srcData [dp + 3] = (byte)0;
- } else {
- srcData [dp + 3] = (byte)0xFF;
- }
- dp += 4;
- }
- }
- }
- OS.MoveMemory (pBits [0], srcData, sizeInBytes);
- return memDib;
-}
-
-static Image createIcon (Image image) {
- Device device = image.getDevice ();
- ImageData data = image.getImageData ();
- if (data.alpha == -1 && data.alphaData == null) {
- ImageData mask = data.getTransparencyMask ();
- return new Image (device, data, mask);
- }
- int width = data.width, height = data.height;
- int /*long*/ hMask, hBitmap;
- int /*long*/ hDC = device.internal_new_GC (null);
- int /*long*/ dstHdc = OS.CreateCompatibleDC (hDC), oldDstBitmap;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
- hBitmap = Display.create32bitDIB (image.handle, data.alpha, data.alphaData, data.transparentPixel);
- hMask = OS.CreateBitmap (width, height, 1, 1, null);
- oldDstBitmap = OS.SelectObject (dstHdc, hMask);
- OS.PatBlt (dstHdc, 0, 0, width, height, OS.BLACKNESS);
- } else {
- hMask = Display.createMaskFromAlpha (data, width, height);
- /* Icons need black pixels where the mask is transparent */
- hBitmap = OS.CreateCompatibleBitmap (hDC, width, height);
- oldDstBitmap = OS.SelectObject (dstHdc, hBitmap);
- int /*long*/ srcHdc = OS.CreateCompatibleDC (hDC);
- int /*long*/ oldSrcBitmap = OS.SelectObject (srcHdc, image.handle);
- OS.PatBlt (dstHdc, 0, 0, width, height, OS.BLACKNESS);
- OS.BitBlt (dstHdc, 0, 0, width, height, srcHdc, 0, 0, OS.SRCINVERT);
- OS.SelectObject (srcHdc, hMask);
- OS.BitBlt (dstHdc, 0, 0, width, height, srcHdc, 0, 0, OS.SRCAND);
- OS.SelectObject (srcHdc, image.handle);
- OS.BitBlt (dstHdc, 0, 0, width, height, srcHdc, 0, 0, OS.SRCINVERT);
- OS.SelectObject (srcHdc, oldSrcBitmap);
- OS.DeleteDC (srcHdc);
- }
- OS.SelectObject (dstHdc, oldDstBitmap);
- OS.DeleteDC (dstHdc);
- device.internal_dispose_GC (hDC, null);
- ICONINFO info = new ICONINFO ();
- info.fIcon = true;
- info.hbmColor = hBitmap;
- info.hbmMask = hMask;
- int /*long*/ hIcon = OS.CreateIconIndirect (info);
- if (hIcon == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.DeleteObject (hBitmap);
- OS.DeleteObject (hMask);
- return Image.win32_new (device, SWT.ICON, hIcon);
-}
-
-static int /*long*/ createMaskFromAlpha (ImageData data, int destWidth, int destHeight) {
- int srcWidth = data.width;
- int srcHeight = data.height;
- ImageData mask = ImageData.internal_new (srcWidth, srcHeight, 1,
- new PaletteData(new RGB [] {new RGB (0, 0, 0), new RGB (0xff, 0xff, 0xff)}),
- 2, null, 1, null, null, -1, -1, -1, 0, 0, 0, 0);
- int ap = 0;
- for (int y = 0; y < mask.height; y++) {
- for (int x = 0; x < mask.width; x++) {
- mask.setPixel (x, y, (data.alphaData [ap++] & 0xff) <= 127 ? 1 : 0);
- }
- }
- int /*long*/ hMask = OS.CreateBitmap (srcWidth, srcHeight, 1, 1, mask.data);
- if (srcWidth != destWidth || srcHeight != destHeight) {
- int /*long*/ hdc = OS.GetDC (0);
- int /*long*/ hdc1 = OS.CreateCompatibleDC (hdc);
- OS.SelectObject (hdc1, hMask);
- int /*long*/ hdc2 = OS.CreateCompatibleDC (hdc);
- int /*long*/ hMask2 = OS.CreateBitmap (destWidth, destHeight, 1, 1, null);
- OS.SelectObject (hdc2, hMask2);
- if (!OS.IsWinCE) OS.SetStretchBltMode(hdc2, OS.COLORONCOLOR);
- OS.StretchBlt (hdc2, 0, 0, destWidth, destHeight, hdc1, 0, 0, srcWidth, srcHeight, OS.SRCCOPY);
- OS.DeleteDC (hdc1);
- OS.DeleteDC (hdc2);
- OS.ReleaseDC (0, hdc);
- OS.DeleteObject(hMask);
- hMask = hMask2;
- }
- return hMask;
-}
-
-static void deregister (Display display) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (display == Displays [i]) Displays [i] = null;
- }
- }
-}
-
-/**
- * Destroys the device in the operating system and releases
- * the device's handle. If the device does not have a handle,
- * this method may do nothing depending on the device.
- * <p>
- * This method is called after <code>release</code>.
- * </p>
- * @see Device#dispose
- * @see #release
- */
-protected void destroy () {
- if (this == Default) Default = null;
- deregister (this);
- destroyDisplay ();
-}
-
-void destroyDisplay () {
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread just before the
- * receiver is disposed. Specifying a <code>null</code> runnable
- * is ignored.
- *
- * @param runnable code to run at dispose time.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void disposeExec (Runnable runnable) {
- checkDevice ();
- if (disposeList == null) disposeList = new Runnable [4];
- for (int i=0; i<disposeList.length; i++) {
- if (disposeList [i] == null) {
- disposeList [i] = runnable;
- return;
- }
- }
- Runnable [] newDisposeList = new Runnable [disposeList.length + 4];
- System.arraycopy (disposeList, 0, newDisposeList, 0, disposeList.length);
- newDisposeList [disposeList.length] = runnable;
- disposeList = newDisposeList;
-}
-
-void drawMenuBars () {
- if (bars == null) return;
- for (int i=0; i<bars.length; i++) {
- Menu menu = bars [i];
- if (menu != null && !menu.isDisposed ()) menu.update ();
- }
- bars = null;
-}
-
-int /*long*/ embeddedProc (int /*long*/ hwnd, int /*long*/ msg, int /*long*/ wParam, int /*long*/ lParam) {
- switch ((int)/*64*/msg) {
- case SWT_KEYMSG: {
- MSG keyMsg = new MSG ();
- OS.MoveMemory (keyMsg, lParam, MSG.sizeof);
- OS.TranslateMessage (keyMsg);
- OS.DispatchMessage (keyMsg);
- int /*long*/ hHeap = OS.GetProcessHeap ();
- OS.HeapFree (hHeap, 0, lParam);
- break;
- }
- case SWT_DESTROY: {
- OS.DestroyWindow (hwnd);
- if (embeddedCallback != null) embeddedCallback.dispose ();
- if (getMsgCallback != null) getMsgCallback.dispose ();
- embeddedCallback = getMsgCallback = null;
- embeddedProc = getMsgProc = 0;
- break;
- }
- }
- return OS.DefWindowProc (hwnd, (int)/*64*/msg, wParam, lParam);
-}
-
-/**
- * Does whatever display specific cleanup is required, and then
- * uses the code in <code>SWTError.error</code> to handle the error.
- *
- * @param code the descriptive error code
- *
- * @see SWT#error(int)
- */
-void error (int code) {
- SWT.error (code);
-}
-
-boolean filterEvent (Event event) {
- if (filterTable != null) filterTable.sendEvent (event);
- return false;
-}
-
-boolean filters (int eventType) {
- if (filterTable == null) return false;
- return filterTable.hooks (eventType);
-}
-
-boolean filterMessage (MSG msg) {
- int message = msg.message;
- if (OS.WM_KEYFIRST <= message && message <= OS.WM_KEYLAST) {
- Control control = findControl (msg.hwnd);
- if (control != null) {
- if (translateAccelerator (msg, control) || translateMnemonic (msg, control) || translateTraversal (msg, control)) {
- lastAscii = lastKey = 0;
- lastVirtual = lastNull = lastDead = false;
- return true;
- }
- }
- }
- return false;
-}
-
-Control findControl (int /*long*/ handle) {
- if (handle == 0) return null;
- int /*long*/ hwndOwner = 0;
- do {
- Control control = getControl (handle);
- if (control != null) return control;
- hwndOwner = OS.GetWindow (handle, OS.GW_OWNER);
- handle = OS.GetParent (handle);
- } while (handle != 0 && handle != hwndOwner);
- return null;
-}
-
-/**
- * Given the operating system handle for a widget, returns
- * the instance of the <code>Widget</code> subclass which
- * represents it in the currently running application, if
- * such exists, or null if no matching widget can be found.
- * <p>
- * <b>IMPORTANT:</b> This method should not be called from
- * application code. The arguments are platform-specific.
- * </p>
- *
- * @param handle the handle for the widget
- * @return the SWT widget that the handle represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Widget findWidget (int /*long*/ handle) {
- checkDevice ();
- return getControl (handle);
-}
-
-/**
- * Given the operating system handle for a widget,
- * and widget-specific id, returns the instance of
- * the <code>Widget</code> subclass which represents
- * the handle/id pair in the currently running application,
- * if such exists, or null if no matching widget can be found.
- * <p>
- * <b>IMPORTANT:</b> This method should not be called from
- * application code. The arguments are platform-specific.
- * </p>
- *
- * @param handle the handle for the widget
- * @param id the id for the subwidget (usually an item)
- * @return the SWT widget that the handle/id pair represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public Widget findWidget (int /*long*/ handle, int /*long*/ id) {
- checkDevice ();
- //TODO - should ids be long
- Control control = getControl (handle);
- return control != null ? control.findItem (id) : null;
-}
-
-/**
- * Given a widget and a widget-specific id, returns the
- * instance of the <code>Widget</code> subclass which represents
- * the widget/id pair in the currently running application,
- * if such exists, or null if no matching widget can be found.
- *
- * @param widget the widget
- * @param id the id for the subwidget (usually an item)
- * @return the SWT subwidget (usually an item) that the widget/id pair represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.3
- */
-public Widget findWidget (Widget widget, int /*long*/ id) {
- checkDevice ();
- //TODO - should ids be long
- if (widget instanceof Control) {
- return findWidget (((Control) widget).handle, id);
- }
- return null;
-}
-
-int /*long*/ foregroundIdleProc (int /*long*/ code, int /*long*/ wParam, int /*long*/ lParam) {
- if (code >= 0) {
- if (runMessages && getMessageCount () != 0) {
- if (runMessagesInIdle) {
- if (runMessagesInMessageProc) {
- OS.PostMessage (hwndMessage, SWT_RUNASYNC, 0, 0);
- } else {
- runAsyncMessages (false);
- }
- }
- MSG msg = new MSG();
- int flags = OS.PM_NOREMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE;
- if (!OS.PeekMessage (msg, 0, 0, 0, flags)) wakeThread ();
- }
- }
- return OS.CallNextHookEx (idleHook, (int)/*64*/code, wParam, lParam);
-}
-
-/**
- * Returns the display which the given thread is the
- * user-interface thread for, or null if the given thread
- * is not a user-interface thread for any display. Specifying
- * <code>null</code> as the thread will return <code>null</code>
- * for the display.
- *
- * @param thread the user-interface thread
- * @return the display for the given thread
- */
-public static Display findDisplay (Thread thread) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- Display display = Displays [i];
- if (display != null && display.thread == thread) {
- return display;
- }
- }
- return null;
- }
-}
-
-/**
- * Returns the currently active <code>Shell</code>, or null
- * if no shell belonging to the currently running application
- * is active.
- *
- * @return the active shell or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Shell getActiveShell () {
- checkDevice ();
- Control control = findControl (OS.GetActiveWindow ());
- return control != null ? control.getShell () : null;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location. Note that
- * on multi-monitor systems the origin can be negative.
- *
- * @return the bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkDevice ();
- if (OS.GetSystemMetrics (OS.SM_CMONITORS) < 2) {
- int width = OS.GetSystemMetrics (OS.SM_CXSCREEN);
- int height = OS.GetSystemMetrics (OS.SM_CYSCREEN);
- return new Rectangle (0, 0, width, height);
- }
- int x = OS.GetSystemMetrics (OS.SM_XVIRTUALSCREEN);
- int y = OS.GetSystemMetrics (OS.SM_YVIRTUALSCREEN);
- int width = OS.GetSystemMetrics (OS.SM_CXVIRTUALSCREEN);
- int height = OS.GetSystemMetrics (OS.SM_CYVIRTUALSCREEN);
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the display which the currently running thread is
- * the user-interface thread for, or null if the currently
- * running thread is not a user-interface thread for any display.
- *
- * @return the current display
- */
-public static Display getCurrent () {
- return findDisplay (Thread.currentThread ());
-}
-
-int getClickCount (int type, int button, int /*long*/ hwnd, int /*long*/ lParam) {
- switch (type) {
- case SWT.MouseDown:
- int doubleClick = OS.GetDoubleClickTime ();
- if (clickRect == null) clickRect = new RECT ();
- int deltaTime = Math.abs (lastTime - getLastEventTime ());
- POINT pt = new POINT ();
- OS.POINTSTOPOINT (pt, lParam);
- if (lastClickHwnd == hwnd && lastButton == button && (deltaTime <= doubleClick) && OS.PtInRect (clickRect, pt)) {
- clickCount++;
- } else {
- clickCount = 1;
- }
- //FALL THROUGH
- case SWT.MouseDoubleClick:
- lastButton = button;
- lastClickHwnd = hwnd;
- lastTime = getLastEventTime ();
- int xInset = OS.GetSystemMetrics (OS.SM_CXDOUBLECLK) / 2;
- int yInset = OS.GetSystemMetrics (OS.SM_CYDOUBLECLK) / 2;
- int x = OS.GET_X_LPARAM (lParam), y = OS.GET_Y_LPARAM (lParam);
- OS.SetRect (clickRect, x - xInset, y - yInset, x + xInset, y + yInset);
- //FALL THROUGH
- case SWT.MouseUp:
- return clickCount;
- }
- return 0;
-}
-
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data.
- *
- * @return the client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getBounds
- */
-public Rectangle getClientArea () {
- checkDevice ();
- if (OS.GetSystemMetrics (OS.SM_CMONITORS) < 2) {
- RECT rect = new RECT ();
- OS.SystemParametersInfo (OS.SPI_GETWORKAREA, 0, rect, 0);
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- return new Rectangle (rect.left, rect.top, width, height);
- }
- int x = OS.GetSystemMetrics (OS.SM_XVIRTUALSCREEN);
- int y = OS.GetSystemMetrics (OS.SM_YVIRTUALSCREEN);
- int width = OS.GetSystemMetrics (OS.SM_CXVIRTUALSCREEN);
- int height = OS.GetSystemMetrics (OS.SM_CYVIRTUALSCREEN);
- return new Rectangle (x, y, width, height);
-}
-
-Control getControl (int /*long*/ handle) {
- if (handle == 0) return null;
- if (lastControl != null && lastHwnd == handle) {
- return lastControl;
- }
- if (lastGetControl != null && lastGetHwnd == handle) {
- return lastGetControl;
- }
- int index;
- if (USE_PROPERTY) {
- index = (int)/*64*/OS.GetProp (handle, SWT_OBJECT_INDEX) - 1;
- } else {
- index = (int)/*64*/OS.GetWindowLongPtr (handle, OS.GWLP_USERDATA) - 1;
- }
- if (0 <= index && index < controlTable.length) {
- Control control = controlTable [index];
- /*
- * Because GWL_USERDATA can be used by native widgets that
- * do not belong to SWT, it is possible that GWL_USERDATA
- * could return an index that is in the range of the table,
- * but was not put there by SWT. Therefore, it is necessary
- * to check the handle of the control that is in the table
- * against the handle that provided the GWL_USERDATA.
- */
- if (control != null && control.checkHandle (handle)) {
- lastGetHwnd = handle;
- lastGetControl = control;
- return control;
- }
- }
- return null;
-}
-
-/**
- * Returns the control which the on-screen pointer is currently
- * over top of, or null if it is not currently over one of the
- * controls built by the currently running application.
- *
- * @return the control under the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Control getCursorControl () {
- checkDevice ();
- POINT pt = new POINT ();
- if (!OS.GetCursorPos (pt)) return null;
- return findControl (OS.WindowFromPoint (pt));
-}
-
-/**
- * Returns the location of the on-screen pointer relative
- * to the top left corner of the screen.
- *
- * @return the cursor location
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point getCursorLocation () {
- checkDevice ();
- POINT pt = new POINT ();
- OS.GetCursorPos (pt);
- return new Point (pt.x, pt.y);
-}
-
-/**
- * Returns an array containing the recommended cursor sizes.
- *
- * @return the array of cursor sizes
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public Point [] getCursorSizes () {
- checkDevice ();
- return new Point [] {
- new Point (OS.GetSystemMetrics (OS.SM_CXCURSOR), OS.GetSystemMetrics (OS.SM_CYCURSOR))};
-}
-
-/**
- * Returns the default display. One is created (making the
- * thread that invokes this method its user-interface thread)
- * if it did not already exist.
- *
- * @return the default display
- */
-public static Display getDefault () {
- synchronized (Device.class) {
- if (Default == null) Default = new Display ();
- return Default;
- }
-}
-
-static boolean isValidClass (Class clazz) {
- String name = clazz.getName ();
- int index = name.lastIndexOf ('.');
- return name.substring (0, index + 1).equals (PACKAGE_PREFIX);
-}
-
-/**
- * Returns the application defined property of the receiver
- * with the specified name, or null if it has not been set.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the display is disposed
- * of, it is the application's responsibility to provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param key the name of the property
- * @return the value of the property or null if it has not been set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setData(String, Object)
- * @see #disposeExec(Runnable)
- */
-public Object getData (String key) {
- checkDevice ();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (key.equals (RUN_MESSAGES_IN_IDLE_KEY)) {
- return new Boolean (runMessagesInIdle);
- }
- if (key.equals (RUN_MESSAGES_IN_MESSAGE_PROC_KEY)) {
- return new Boolean (runMessagesInMessageProc);
- }
- if (key.equals (USE_OWNDC_KEY)) {
- return new Boolean (useOwnDC);
- }
- if (keys == null) return null;
- for (int i=0; i<keys.length; i++) {
- if (keys [i].equals (key)) return values [i];
- }
- return null;
-}
-
-/**
- * Returns the application defined, display specific data
- * associated with the receiver, or null if it has not been
- * set. The <em>display specific data</em> is a single,
- * unnamed field that is stored with every display.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the display specific data needs to
- * be notified when the display is disposed of, it is the
- * application's responsibility to provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @return the display specific data
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setData(Object)
- * @see #disposeExec(Runnable)
- */
-public Object getData () {
- checkDevice ();
- return data;
-}
-
-/**
- * Returns the button dismissal alignment, one of <code>LEFT</code> or <code>RIGHT</code>.
- * The button dismissal alignment is the ordering that should be used when positioning the
- * default dismissal button for a dialog. For example, in a dialog that contains an OK and
- * CANCEL button, on platforms where the button dismissal alignment is <code>LEFT</code>, the
- * button ordering should be OK/CANCEL. When button dismissal alignment is <code>RIGHT</code>,
- * the button ordering should be CANCEL/OK.
- *
- * @return the button dismissal order
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1
- */
-public int getDismissalAlignment () {
- checkDevice ();
- return SWT.LEFT;
-}
-
-
-/**
- * Returns the longest duration, in milliseconds, between
- * two mouse button clicks that will be considered a
- * <em>double click</em> by the underlying operating system.
- *
- * @return the double click time
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getDoubleClickTime () {
- checkDevice ();
- return OS.GetDoubleClickTime ();
-}
-
-/**
- * Returns the control which currently has keyboard focus,
- * or null if keyboard events are not currently going to
- * any of the controls built by the currently running
- * application.
- *
- * @return the control under the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Control getFocusControl () {
- checkDevice ();
- if (focusControl != null && !focusControl.isDisposed ()) {
- return focusControl;
- }
- return _getFocusControl ();
-}
-
-String getFontName (LOGFONT logFont) {
- char[] chars;
- if (OS.IsUnicode) {
- chars = ((LOGFONTW)logFont).lfFaceName;
- } else {
- chars = new char[OS.LF_FACESIZE];
- byte[] bytes = ((LOGFONTA)logFont).lfFaceName;
- OS.MultiByteToWideChar (OS.CP_ACP, OS.MB_PRECOMPOSED, bytes, bytes.length, chars, chars.length);
- }
- int index = 0;
- while (index < chars.length) {
- if (chars [index] == 0) break;
- index++;
- }
- return new String (chars, 0, index);
-}
-
-/**
- * Returns true when the high contrast mode is enabled.
- * Otherwise, false is returned.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @return the high contrast mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public boolean getHighContrast () {
- checkDevice ();
- if (OS.IsWinCE) return false;
- HIGHCONTRAST pvParam = new HIGHCONTRAST ();
- pvParam.cbSize = HIGHCONTRAST.sizeof;
- OS.SystemParametersInfo (OS.SPI_GETHIGHCONTRAST, 0, pvParam, 0);
- return (pvParam.dwFlags & OS.HCF_HIGHCONTRASTON) != 0;
-}
-
-/**
- * Returns the maximum allowed depth of icons on this display, in bits per pixel.
- * On some platforms, this may be different than the actual depth of the display.
- *
- * @return the maximum icon depth
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Device#getDepth
- */
-public int getIconDepth () {
- checkDevice ();
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
- if (getDepth () >= 24) return 32;
- }
-
- /* Use the character encoding for the default locale */
- TCHAR buffer1 = new TCHAR (0, "Control Panel\\Desktop\\WindowMetrics", true); //$NON-NLS-1$
-
- int /*long*/ [] phkResult = new int /*long*/ [1];
- int result = OS.RegOpenKeyEx (OS.HKEY_CURRENT_USER, buffer1, 0, OS.KEY_READ, phkResult);
- if (result != 0) return 4;
- int depth = 4;
- int [] lpcbData = new int [1];
-
- /* Use the character encoding for the default locale */
- TCHAR buffer2 = new TCHAR (0, "Shell Icon BPP", true); //$NON-NLS-1$
- result = OS.RegQueryValueEx (phkResult [0], buffer2, 0, null, (TCHAR) null, lpcbData);
- if (result == 0) {
- TCHAR lpData = new TCHAR (0, lpcbData [0] / TCHAR.sizeof);
- result = OS.RegQueryValueEx (phkResult [0], buffer2, 0, null, lpData, lpcbData);
- if (result == 0) {
- try {
- depth = Integer.parseInt (lpData.toString (0, lpData.strlen ()));
- } catch (NumberFormatException e) {}
- }
- }
- OS.RegCloseKey (phkResult [0]);
- return depth;
-}
-
-/**
- * Returns an array containing the recommended icon sizes.
- *
- * @return the array of icon sizes
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Decorations#setImages(Image[])
- *
- * @since 3.0
- */
-public Point [] getIconSizes () {
- checkDevice ();
- return new Point [] {
- new Point (OS.GetSystemMetrics (OS.SM_CXSMICON), OS.GetSystemMetrics (OS.SM_CYSMICON)),
- new Point (OS.GetSystemMetrics (OS.SM_CXICON), OS.GetSystemMetrics (OS.SM_CYICON)),
- };
-}
-
-ImageList getImageList (int style, int width, int height) {
- if (imageList == null) imageList = new ImageList [4];
-
- int i = 0;
- int length = imageList.length;
- while (i < length) {
- ImageList list = imageList [i];
- if (list == null) break;
- Point size = list.getImageSize();
- if (size.x == width && size.y == height) {
- if (list.getStyle () == style) {
- list.addRef();
- return list;
- }
- }
- i++;
- }
-
- if (i == length) {
- ImageList [] newList = new ImageList [length + 4];
- System.arraycopy (imageList, 0, newList, 0, length);
- imageList = newList;
- }
-
- ImageList list = new ImageList (style);
- imageList [i] = list;
- list.addRef();
- return list;
-}
-
-ImageList getImageListToolBar (int style, int width, int height) {
- if (toolImageList == null) toolImageList = new ImageList [4];
-
- int i = 0;
- int length = toolImageList.length;
- while (i < length) {
- ImageList list = toolImageList [i];
- if (list == null) break;
- Point size = list.getImageSize();
- if (size.x == width && size.y == height) {
- if (list.getStyle () == style) {
- list.addRef();
- return list;
- }
- }
- i++;
- }
-
- if (i == length) {
- ImageList [] newList = new ImageList [length + 4];
- System.arraycopy (toolImageList, 0, newList, 0, length);
- toolImageList = newList;
- }
-
- ImageList list = new ImageList (style);
- toolImageList [i] = list;
- list.addRef();
- return list;
-}
-
-ImageList getImageListToolBarDisabled (int style, int width, int height) {
- if (toolDisabledImageList == null) toolDisabledImageList = new ImageList [4];
-
- int i = 0;
- int length = toolDisabledImageList.length;
- while (i < length) {
- ImageList list = toolDisabledImageList [i];
- if (list == null) break;
- Point size = list.getImageSize();
- if (size.x == width && size.y == height) {
- if (list.getStyle () == style) {
- list.addRef();
- return list;
- }
- }
- i++;
- }
-
- if (i == length) {
- ImageList [] newList = new ImageList [length + 4];
- System.arraycopy (toolDisabledImageList, 0, newList, 0, length);
- toolDisabledImageList = newList;
- }
-
- ImageList list = new ImageList (style);
- toolDisabledImageList [i] = list;
- list.addRef();
- return list;
-}
-
-ImageList getImageListToolBarHot (int style, int width, int height) {
- if (toolHotImageList == null) toolHotImageList = new ImageList [4];
-
- int i = 0;
- int length = toolHotImageList.length;
- while (i < length) {
- ImageList list = toolHotImageList [i];
- if (list == null) break;
- Point size = list.getImageSize();
- if (size.x == width && size.y == height) {
- if (list.getStyle () == style) {
- list.addRef();
- return list;
- }
- }
- i++;
- }
-
- if (i == length) {
- ImageList [] newList = new ImageList [length + 4];
- System.arraycopy (toolHotImageList, 0, newList, 0, length);
- toolHotImageList = newList;
- }
-
- ImageList list = new ImageList (style);
- toolHotImageList [i] = list;
- list.addRef();
- return list;
-}
-
-int getLastEventTime () {
- return OS.IsWinCE ? OS.GetTickCount () : OS.GetMessageTime ();
-}
-
-MenuItem getMenuItem (int id) {
- if (items == null) return null;
- id = id - ID_START;
- if (0 <= id && id < items.length) return items [id];
- return null;
-}
-
-int getMessageCount () {
- return synchronizer.getMessageCount ();
-}
-
-
-Shell getModalShell () {
- if (modalShells == null) return null;
- int index = modalShells.length;
- while (--index >= 0) {
- Shell shell = modalShells [index];
- if (shell != null) return shell;
- }
- return null;
-}
-
-Dialog getModalDialog () {
- return modalDialog;
-}
-
-/**
- * Returns an array of monitors attached to the device.
- *
- * @return the array of monitors
- *
- * @since 3.0
- */
-public Monitor [] getMonitors () {
- checkDevice ();
- if (OS.IsWinCE || OS.WIN32_VERSION < OS.VERSION (4, 10)) {
- return new Monitor [] {getPrimaryMonitor ()};
- }
- monitors = new Monitor [4];
- Callback callback = new Callback (this, "monitorEnumProc", 4); //$NON-NLS-1$
- int /*long*/ lpfnEnum = callback.getAddress ();
- if (lpfnEnum == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- OS.EnumDisplayMonitors (0, null, lpfnEnum, 0);
- callback.dispose ();
- Monitor [] result = new Monitor [monitorCount];
- System.arraycopy (monitors, 0, result, 0, monitorCount);
- monitors = null;
- monitorCount = 0;
- return result;
-}
-
-int /*long*/ getMsgProc (int /*long*/ code, int /*long*/ wParam, int /*long*/ lParam) {
- if (embeddedHwnd == 0) {
- int /*long*/ hInstance = OS.GetModuleHandle (null);
- embeddedHwnd = OS.CreateWindowEx (0,
- windowClass,
- null,
- OS.WS_OVERLAPPED,
- 0, 0, 0, 0,
- 0,
- 0,
- hInstance,
- null);
- embeddedCallback = new Callback (this, "embeddedProc", 4); //$NON-NLS-1$
- embeddedProc = embeddedCallback.getAddress ();
- if (embeddedProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- OS.SetWindowLongPtr (embeddedHwnd, OS.GWLP_WNDPROC, embeddedProc);
- }
- if (code >= 0 && (wParam & OS.PM_REMOVE) != 0) {
- MSG msg = new MSG ();
- OS.MoveMemory (msg, lParam, MSG.sizeof);
- switch (msg.message) {
- case OS.WM_KEYDOWN:
- case OS.WM_KEYUP:
- case OS.WM_SYSKEYDOWN:
- case OS.WM_SYSKEYUP: {
- Control control = findControl (msg.hwnd);
- if (control != null) {
- int /*long*/ hHeap = OS.GetProcessHeap ();
- int /*long*/ keyMsg = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, MSG.sizeof);
- OS.MoveMemory (keyMsg, msg, MSG.sizeof);
- OS.PostMessage (hwndMessage, SWT_KEYMSG, wParam, keyMsg);
- switch ((int)/*64*/msg.wParam) {
- case OS.VK_SHIFT:
- case OS.VK_MENU:
- case OS.VK_CONTROL:
- case OS.VK_CAPITAL:
- case OS.VK_NUMLOCK:
- case OS.VK_SCROLL:
- break;
- default:
- msg.message = OS.WM_NULL;
- OS.MoveMemory (lParam, msg, MSG.sizeof);
- }
- }
- }
- }
- }
- return OS.CallNextHookEx (msgHook, (int)/*64*/code, wParam, lParam);
-}
-
-/**
- * Returns the primary monitor for that device.
- *
- * @return the primary monitor
- *
- * @since 3.0
- */
-public Monitor getPrimaryMonitor () {
- checkDevice ();
- if (OS.IsWinCE || OS.WIN32_VERSION < OS.VERSION (4, 10)) {
- Monitor monitor = new Monitor();
- int width = OS.GetSystemMetrics (OS.SM_CXSCREEN);
- int height = OS.GetSystemMetrics (OS.SM_CYSCREEN);
- monitor.width = width;
- monitor.height = height;
- RECT rect = new RECT ();
- OS.SystemParametersInfo (OS.SPI_GETWORKAREA, 0, rect, 0);
- monitor.clientX = rect.left;
- monitor.clientY = rect.top;
- monitor.clientWidth = rect.right - rect.left;
- monitor.clientHeight = rect.bottom - rect.top;
- return monitor;
- }
- monitors = new Monitor [4];
- Callback callback = new Callback (this, "monitorEnumProc", 4); //$NON-NLS-1$
- int /*long*/ lpfnEnum = callback.getAddress ();
- if (lpfnEnum == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- OS.EnumDisplayMonitors (0, null, lpfnEnum, 0);
- callback.dispose ();
- Monitor result = null;
- MONITORINFO lpmi = new MONITORINFO ();
- lpmi.cbSize = MONITORINFO.sizeof;
- for (int i = 0; i < monitorCount; i++) {
- Monitor monitor = monitors [i];
- OS.GetMonitorInfo (monitors [i].handle, lpmi);
- if ((lpmi.dwFlags & OS.MONITORINFOF_PRIMARY) != 0) {
- result = monitor;
- break;
- }
- }
- monitors = null;
- monitorCount = 0;
- return result;
-}
-
-/**
- * Returns a (possibly empty) array containing all shells which have
- * not been disposed and have the receiver as their display.
- *
- * @return the receiver's shells
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Shell [] getShells () {
- checkDevice ();
- int index = 0;
- Shell [] result = new Shell [16];
- for (int i = 0; i < controlTable.length; i++) {
- Control control = controlTable [i];
- if (control != null && control instanceof Shell) {
- int j = 0;
- while (j < index) {
- if (result [j] == control) break;
- j++;
- }
- if (j == index) {
- if (index == result.length) {
- Shell [] newResult = new Shell [index + 16];
- System.arraycopy (result, 0, newResult, 0, index);
- result = newResult;
- }
- result [index++] = (Shell) control;
- }
- }
- }
- if (index == result.length) return result;
- Shell [] newResult = new Shell [index];
- System.arraycopy (result, 0, newResult, 0, index);
- return newResult;
-}
-
-Image getSortImage (int direction) {
- switch (direction) {
- case SWT.UP: {
- if (upArrow != null) return upArrow;
- Color c1 = getSystemColor (SWT.COLOR_WIDGET_NORMAL_SHADOW);
- Color c2 = getSystemColor (SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
- Color c3 = getSystemColor (SWT.COLOR_WIDGET_BACKGROUND);
- PaletteData palette = new PaletteData(new RGB [] {c1.getRGB (), c2.getRGB (), c3.getRGB ()});
- ImageData imageData = new ImageData (8, 8, 4, palette);
- imageData.transparentPixel = 2;
- upArrow = new Image (this, imageData);
- GC gc = new GC (upArrow);
- gc.setBackground (c3);
- gc.fillRectangle (0, 0, 8, 8);
- gc.setForeground (c1);
- int [] line1 = new int [] {0,6, 1,6, 1,4, 2,4, 2,2, 3,2, 3,1};
- gc.drawPolyline (line1);
- gc.setForeground (c2);
- int [] line2 = new int [] {0,7, 7,7, 7,6, 6,6, 6,4, 5,4, 5,2, 4,2, 4,1};
- gc.drawPolyline (line2);
- gc.dispose ();
- return upArrow;
- }
- case SWT.DOWN: {
- if (downArrow != null) return downArrow;
- Color c1 = getSystemColor (SWT.COLOR_WIDGET_NORMAL_SHADOW);
- Color c2 = getSystemColor (SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
- Color c3 = getSystemColor (SWT.COLOR_WIDGET_BACKGROUND);
- PaletteData palette = new PaletteData (new RGB [] {c1.getRGB (), c2.getRGB (), c3.getRGB ()});
- ImageData imageData = new ImageData (8, 8, 4, palette);
- imageData.transparentPixel = 2;
- downArrow = new Image (this, imageData);
- GC gc = new GC (downArrow);
- gc.setBackground (c3);
- gc.fillRectangle (0, 0, 8, 8);
- gc.setForeground (c1);
- int [] line1 = new int [] {7,0, 0,0, 0,1, 1,1, 1,3, 2,3, 2,5, 3,5, 3,6};
- gc.drawPolyline (line1);
- gc.setForeground (c2);
- int [] line2 = new int [] {4,6, 4,5, 5,5, 5,3, 6,3, 6,1, 7,1};
- gc.drawPolyline (line2);
- gc.dispose ();
- return downArrow;
- }
- }
- return null;
-}
-
-/**
- * Gets the synchronizer used by the display.
- *
- * @return the receiver's synchronizer
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public Synchronizer getSynchronizer () {
- checkDevice ();
- return synchronizer;
-}
-
-/**
- * Returns the thread that has invoked <code>syncExec</code>
- * or null if no such runnable is currently being invoked by
- * the user-interface thread.
- * <p>
- * Note: If a runnable invoked by asyncExec is currently
- * running, this method will return null.
- * </p>
- *
- * @return the receiver's sync-interface thread
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Thread getSyncThread () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- return synchronizer.syncThread;
- }
-}
-
-/**
- * Returns the matching standard color for the given
- * constant, which should be one of the color constants
- * specified in class <code>SWT</code>. Any value other
- * than one of the SWT color constants which is passed
- * in will result in the color black. This color should
- * not be free'd because it was allocated by the system,
- * not the application.
- *
- * @param id the color constant
- * @return the matching color
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT
- */
-public Color getSystemColor (int id) {
- checkDevice ();
- int pixel = 0x00000000;
- switch (id) {
- case SWT.COLOR_WIDGET_DARK_SHADOW: pixel = OS.GetSysColor (OS.COLOR_3DDKSHADOW); break;
- case SWT.COLOR_WIDGET_NORMAL_SHADOW: pixel = OS.GetSysColor (OS.COLOR_3DSHADOW); break;
- case SWT.COLOR_WIDGET_LIGHT_SHADOW: pixel = OS.GetSysColor (OS.COLOR_3DLIGHT); break;
- case SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: pixel = OS.GetSysColor (OS.COLOR_3DHIGHLIGHT); break;
- case SWT.COLOR_WIDGET_BACKGROUND: pixel = OS.GetSysColor (OS.COLOR_3DFACE); break;
- case SWT.COLOR_WIDGET_BORDER: pixel = OS.GetSysColor (OS.COLOR_WINDOWFRAME); break;
- case SWT.COLOR_WIDGET_FOREGROUND:
- case SWT.COLOR_LIST_FOREGROUND: pixel = OS.GetSysColor (OS.COLOR_WINDOWTEXT); break;
- case SWT.COLOR_LIST_BACKGROUND: pixel = OS.GetSysColor (OS.COLOR_WINDOW); break;
- case SWT.COLOR_LIST_SELECTION: pixel = OS.GetSysColor (OS.COLOR_HIGHLIGHT); break;
- case SWT.COLOR_LIST_SELECTION_TEXT: pixel = OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT);break;
- case SWT.COLOR_INFO_FOREGROUND: pixel = OS.GetSysColor (OS.COLOR_INFOTEXT); break;
- case SWT.COLOR_INFO_BACKGROUND: pixel = OS.GetSysColor (OS.COLOR_INFOBK); break;
- case SWT.COLOR_TITLE_FOREGROUND: pixel = OS.GetSysColor (OS.COLOR_CAPTIONTEXT); break;
- case SWT.COLOR_TITLE_BACKGROUND: pixel = OS.GetSysColor (OS.COLOR_ACTIVECAPTION); break;
- case SWT.COLOR_TITLE_BACKGROUND_GRADIENT:
- pixel = OS.GetSysColor (OS.COLOR_GRADIENTACTIVECAPTION);
- if (pixel == 0) pixel = OS.GetSysColor (OS.COLOR_ACTIVECAPTION);
- break;
- case SWT.COLOR_TITLE_INACTIVE_FOREGROUND: pixel = OS.GetSysColor (OS.COLOR_INACTIVECAPTIONTEXT); break;
- case SWT.COLOR_TITLE_INACTIVE_BACKGROUND: pixel = OS.GetSysColor (OS.COLOR_INACTIVECAPTION); break;
- case SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT:
- pixel = OS.GetSysColor (OS.COLOR_GRADIENTINACTIVECAPTION);
- if (pixel == 0) pixel = OS.GetSysColor (OS.COLOR_INACTIVECAPTION);
- break;
- default:
- return super.getSystemColor (id);
- }
- return Color.win32_new (this, pixel);
-}
-
-/**
- * Returns the matching standard platform cursor for the given
- * constant, which should be one of the cursor constants
- * specified in class <code>SWT</code>. This cursor should
- * not be free'd because it was allocated by the system,
- * not the application. A value of <code>null</code> will
- * be returned if the supplied constant is not an SWT cursor
- * constant.
- *
- * @param id the SWT cursor constant
- * @return the corresponding cursor or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT#CURSOR_ARROW
- * @see SWT#CURSOR_WAIT
- * @see SWT#CURSOR_CROSS
- * @see SWT#CURSOR_APPSTARTING
- * @see SWT#CURSOR_HELP
- * @see SWT#CURSOR_SIZEALL
- * @see SWT#CURSOR_SIZENESW
- * @see SWT#CURSOR_SIZENS
- * @see SWT#CURSOR_SIZENWSE
- * @see SWT#CURSOR_SIZEWE
- * @see SWT#CURSOR_SIZEN
- * @see SWT#CURSOR_SIZES
- * @see SWT#CURSOR_SIZEE
- * @see SWT#CURSOR_SIZEW
- * @see SWT#CURSOR_SIZENE
- * @see SWT#CURSOR_SIZESE
- * @see SWT#CURSOR_SIZESW
- * @see SWT#CURSOR_SIZENW
- * @see SWT#CURSOR_UPARROW
- * @see SWT#CURSOR_IBEAM
- * @see SWT#CURSOR_NO
- * @see SWT#CURSOR_HAND
- *
- * @since 3.0
- */
-public Cursor getSystemCursor (int id) {
- checkDevice ();
- if (!(0 <= id && id < cursors.length)) return null;
- if (cursors [id] == null) {
- cursors [id] = new Cursor (this, id);
- }
- return cursors [id];
-}
-
-/**
- * Returns a reasonable font for applications to use.
- * On some platforms, this will match the "default font"
- * or "system font" if such can be found. This font
- * should not be free'd because it was allocated by the
- * system, not the application.
- * <p>
- * Typically, applications which want the default look
- * should simply not set the font on the widgets they
- * create. Widgets are always created with the correct
- * default font for the class of user-interface component
- * they represent.
- * </p>
- *
- * @return a font
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getSystemFont () {
- checkDevice ();
- if (systemFont != null) return systemFont;
- int /*long*/ hFont = 0;
- if (!OS.IsWinCE) {
- NONCLIENTMETRICS info = OS.IsUnicode ? (NONCLIENTMETRICS) new NONCLIENTMETRICSW () : new NONCLIENTMETRICSA ();
- info.cbSize = NONCLIENTMETRICS.sizeof;
- if (OS.SystemParametersInfo (OS.SPI_GETNONCLIENTMETRICS, 0, info, 0)) {
- LOGFONT logFont = OS.IsUnicode ? (LOGFONT) ((NONCLIENTMETRICSW)info).lfMessageFont : ((NONCLIENTMETRICSA)info).lfMessageFont;
- hFont = OS.CreateFontIndirect (logFont);
- lfSystemFont = hFont != 0 ? logFont : null;
- }
- }
- if (hFont == 0) hFont = OS.GetStockObject (OS.DEFAULT_GUI_FONT);
- if (hFont == 0) hFont = OS.GetStockObject (OS.SYSTEM_FONT);
- return systemFont = Font.win32_new (this, hFont);
-}
-
-/**
- * Returns the matching standard platform image for the given
- * constant, which should be one of the icon constants
- * specified in class <code>SWT</code>. This image should
- * not be free'd because it was allocated by the system,
- * not the application. A value of <code>null</code> will
- * be returned either if the supplied constant is not an
- * SWT icon constant or if the platform does not define an
- * image that corresponds to the constant.
- *
- * @param id the SWT icon constant
- * @return the corresponding image or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_QUESTION
- * @see SWT#ICON_WARNING
- * @see SWT#ICON_WORKING
- *
- * @since 3.0
- */
-public Image getSystemImage (int id) {
- checkDevice ();
- switch (id) {
- case SWT.ICON_ERROR: {
- if (errorImage != null) return errorImage;
- int /*long*/ hIcon = OS.LoadImage (0, OS.OIC_HAND, OS.IMAGE_ICON, 0, 0, OS.LR_SHARED);
- return errorImage = Image.win32_new (this, SWT.ICON, hIcon);
- }
- case SWT.ICON_WORKING:
- case SWT.ICON_INFORMATION: {
- if (infoImage != null) return infoImage;
- int /*long*/ hIcon = OS.LoadImage (0, OS.OIC_INFORMATION, OS.IMAGE_ICON, 0, 0, OS.LR_SHARED);
- return infoImage = Image.win32_new (this, SWT.ICON, hIcon);
- }
- case SWT.ICON_QUESTION: {
- if (questionImage != null) return questionImage;
- int /*long*/ hIcon = OS.LoadImage (0, OS.OIC_QUES, OS.IMAGE_ICON, 0, 0, OS.LR_SHARED);
- return questionImage = Image.win32_new (this, SWT.ICON, hIcon);
- }
- case SWT.ICON_WARNING: {
- if (warningIcon != null) return warningIcon;
- int /*long*/ hIcon = OS.LoadImage (0, OS.OIC_BANG, OS.IMAGE_ICON, 0, 0, OS.LR_SHARED);
- return warningIcon = Image.win32_new (this, SWT.ICON, hIcon);
- }
- }
- return null;
-}
-
-/**
- * Returns the single instance of the system tray or null
- * when there is no system tray available for the platform.
- *
- * @return the system tray or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public Tray getSystemTray () {
- checkDevice ();
- if (tray != null) return tray;
- if (!OS.IsWinCE) tray = new Tray (this, SWT.NONE);
- return tray;
-}
-
-/**
- * Returns the user-interface thread for the receiver.
- *
- * @return the receiver's user-interface thread
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Thread getThread () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- return thread;
- }
-}
-
-int /*long*/ hButtonTheme () {
- if (hButtonTheme != 0) return hButtonTheme;
- return hButtonTheme = OS.OpenThemeData (hwndMessage, BUTTON);
-}
-
-int /*long*/ hEditTheme () {
- if (hEditTheme != 0) return hEditTheme;
- return hEditTheme = OS.OpenThemeData (hwndMessage, EDIT);
-}
-
-int /*long*/ hExplorerBarTheme () {
- if (hExplorerBarTheme != 0) return hExplorerBarTheme;
- return hExplorerBarTheme = OS.OpenThemeData (hwndMessage, EXPLORERBAR);
-}
-
-int /*long*/ hScrollBarTheme () {
- if (hScrollBarTheme != 0) return hScrollBarTheme;
- return hScrollBarTheme = OS.OpenThemeData (hwndMessage, SCROLLBAR);
-}
-
-int /*long*/ hTabTheme () {
- if (hTabTheme != 0) return hTabTheme;
- return hTabTheme = OS.OpenThemeData (hwndMessage, TAB);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Display</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for gc creation</li>
- * </ul>
- */
-public int /*long*/ internal_new_GC (GCData data) {
- if (isDisposed()) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
- int /*long*/ hDC = OS.GetDC (0);
- if (hDC == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- if (data != null) {
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) != 0) {
- data.layout = (data.style & SWT.RIGHT_TO_LEFT) != 0 ? OS.LAYOUT_RTL : 0;
- } else {
- data.style |= SWT.LEFT_TO_RIGHT;
- }
- data.device = this;
- data.font = getSystemFont ();
- }
- return hDC;
-}
-
-/**
- * Initializes any internal resources needed by the
- * device.
- * <p>
- * This method is called after <code>create</code>.
- * </p>
- *
- * @see #create
- */
-protected void init () {
- super.init ();
-
- /* Create the callbacks */
- windowCallback = new Callback (this, "windowProc", 4); //$NON-NLS-1$
- windowProc = windowCallback.getAddress ();
- if (windowProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- /* Remember the current thread id */
- threadId = OS.GetCurrentThreadId ();
-
- /* Use the character encoding for the default locale */
- windowClass = new TCHAR (0, WindowName + WindowClassCount, true);
- windowShadowClass = new TCHAR (0, WindowShadowName + WindowClassCount, true);
- windowOwnDCClass = new TCHAR (0, WindowOwnDCName + WindowClassCount, true);
- WindowClassCount++;
-
- /* Register the SWT window class */
- int /*long*/ hHeap = OS.GetProcessHeap ();
- int /*long*/ hInstance = OS.GetModuleHandle (null);
- WNDCLASS lpWndClass = new WNDCLASS ();
- lpWndClass.hInstance = hInstance;
- lpWndClass.lpfnWndProc = windowProc;
- lpWndClass.style = OS.CS_BYTEALIGNWINDOW | OS.CS_DBLCLKS;
- lpWndClass.hCursor = OS.LoadCursor (0, OS.IDC_ARROW);
- /*
- * Set the default icon for the window class to IDI_APPLICATION.
- * This is not necessary for native Windows applications but
- * versions of Java starting at JDK 1.6 set the icon in the
- * executable instead of leaving the default.
- */
- if (!OS.IsWinCE && Library.JAVA_VERSION >= Library.JAVA_VERSION (1, 6, 0)) {
- TCHAR lpszFile = new TCHAR (0, OS.MAX_PATH);
- while (OS.GetModuleFileName (0, lpszFile, lpszFile.length ()) == lpszFile.length ()) {
- lpszFile = new TCHAR (0, lpszFile.length () + OS.MAX_PATH);
- }
- if (OS.ExtractIconEx (lpszFile, -1, null, null, 1) != 0) {
- String fileName = lpszFile.toString (0, lpszFile.strlen ());
- if (fileName.endsWith ("java.exe") || fileName.endsWith ("javaw.exe")) { //$NON-NLS-1$ //$NON-NLS-2$
- lpWndClass.hIcon = OS.LoadIcon (0, OS.IDI_APPLICATION);
- }
- }
- }
- int byteCount = windowClass.length () * TCHAR.sizeof;
- lpWndClass.lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (lpWndClass.lpszClassName, windowClass, byteCount);
- OS.RegisterClass (lpWndClass);
- OS.HeapFree (hHeap, 0, lpWndClass.lpszClassName);
-
- /* Register the SWT drop shadow window class */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
- lpWndClass.style |= OS.CS_DROPSHADOW;
- }
- byteCount = windowShadowClass.length () * TCHAR.sizeof;
- lpWndClass.lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (lpWndClass.lpszClassName, windowShadowClass, byteCount);
- OS.RegisterClass (lpWndClass);
- OS.HeapFree (hHeap, 0, lpWndClass.lpszClassName);
-
- /* Register the CS_OWNDC window class */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
- lpWndClass.style |= OS.CS_OWNDC;
- }
- byteCount = windowOwnDCClass.length () * TCHAR.sizeof;
- lpWndClass.lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (lpWndClass.lpszClassName, windowOwnDCClass, byteCount);
- OS.RegisterClass (lpWndClass);
- OS.HeapFree (hHeap, 0, lpWndClass.lpszClassName);
-
- /* Create the message only HWND */
- hwndMessage = OS.CreateWindowEx (0,
- windowClass,
- null,
- OS.WS_OVERLAPPED,
- 0, 0, 0, 0,
- 0,
- 0,
- hInstance,
- null);
- messageCallback = new Callback (this, "messageProc", 4); //$NON-NLS-1$
- messageProc = messageCallback.getAddress ();
- if (messageProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- OS.SetWindowLongPtr (hwndMessage, OS.GWLP_WNDPROC, messageProc);
-
- /* Create the filter hook */
- if (!OS.IsWinCE) {
- msgFilterCallback = new Callback (this, "msgFilterProc", 3); //$NON-NLS-1$
- msgFilterProc = msgFilterCallback.getAddress ();
- if (msgFilterProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- filterHook = OS.SetWindowsHookEx (OS.WH_MSGFILTER, msgFilterProc, 0, threadId);
- }
-
- /* Create the idle hook */
- if (!OS.IsWinCE) {
- foregroundIdleCallback = new Callback (this, "foregroundIdleProc", 3); //$NON-NLS-1$
- foregroundIdleProc = foregroundIdleCallback.getAddress ();
- if (foregroundIdleProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- idleHook = OS.SetWindowsHookEx (OS.WH_FOREGROUNDIDLE, foregroundIdleProc, 0, threadId);
- }
-
- /* Register custom messages message */
- SWT_TASKBARCREATED = OS.RegisterWindowMessage (new TCHAR (0, "TaskbarCreated", true)); //$NON-NLS-1$
- SWT_RESTORECARET = OS.RegisterWindowMessage (new TCHAR (0, "SWT_RESTORECARET", true)); //$NON-NLS-1$
- DI_GETDRAGIMAGE = OS.RegisterWindowMessage (new TCHAR (0, "ShellGetDragImage", true)); //$NON-NLS-1$
-
- /* Initialize OLE */
- if (!OS.IsWinCE) OS.OleInitialize (0);
-
- /* Initialize buffered painting */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)){
- OS.BufferedPaintInit ();
- }
-
- /* Initialize the Widget Table */
- indexTable = new int [GROW_SIZE];
- controlTable = new Control [GROW_SIZE];
- for (int i=0; i<GROW_SIZE-1; i++) indexTable [i] = i + 1;
- indexTable [GROW_SIZE - 1] = -1;
-
- /* Remember the last high contrast state */
- lastHighContrast = getHighContrast ();
-}
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Display</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int /*long*/ hDC, GCData data) {
- OS.ReleaseDC (0, hDC);
-}
-
-boolean isXMouseActive () {
- /*
- * NOTE: X-Mouse is active when bit 1 of the UserPreferencesMask is set.
- */
- boolean xMouseActive = false;
- TCHAR key = new TCHAR (0, "Control Panel\\Desktop", true); //$NON-NLS-1$
- int /*long*/ [] phKey = new int /*long*/ [1];
- int result = OS.RegOpenKeyEx (OS.HKEY_CURRENT_USER, key, 0, OS.KEY_READ, phKey);
- if (result == 0) {
- TCHAR lpValueName = new TCHAR (0, "UserPreferencesMask", true); //$NON-NLS-1$
- int [] lpcbData = new int [] {4}, lpData = new int [1];
- result = OS.RegQueryValueEx (phKey [0], lpValueName, 0, null, lpData, lpcbData);
- if (result == 0) xMouseActive = (lpData [0] & 0x01) != 0;
- OS.RegCloseKey (phKey [0]);
- }
- return xMouseActive;
-}
-
-boolean isValidThread () {
- return thread == Thread.currentThread ();
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param point to be mapped
- * @return point with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Point map (Control from, Control to, Point point) {
- checkDevice ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return map (from, to, point.x, point.y);
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param x coordinates to be mapped
- * @param y coordinates to be mapped
- * @return point with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Point map (Control from, Control to, int x, int y) {
- checkDevice ();
- if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (from == to) return new Point (x, y);
- int /*long*/ hwndFrom = from != null ? from.handle : 0;
- int /*long*/ hwndTo = to != null ? to.handle : 0;
- POINT point = new POINT ();
- point.x = x;
- point.y = y;
- OS.MapWindowPoints (hwndFrom, hwndTo, point, 1);
- return new Point (point.x, point.y);
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param rectangle to be mapped
- * @return rectangle with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Rectangle map (Control from, Control to, Rectangle rectangle) {
- checkDevice ();
- if (rectangle == null) error (SWT.ERROR_NULL_ARGUMENT);
- return map (from, to, rectangle.x, rectangle.y, rectangle.width, rectangle.height);
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param x coordinates to be mapped
- * @param y coordinates to be mapped
- * @param width coordinates to be mapped
- * @param height coordinates to be mapped
- * @return rectangle with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Rectangle map (Control from, Control to, int x, int y, int width, int height) {
- checkDevice ();
- if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (from == to) return new Rectangle (x, y, width, height);
- int /*long*/ hwndFrom = from != null ? from.handle : 0;
- int /*long*/ hwndTo = to != null ? to.handle : 0;
- RECT rect = new RECT ();
- rect.left = x;
- rect.top = y;
- rect.right = x + width;
- rect.bottom = y + height;
- OS.MapWindowPoints (hwndFrom, hwndTo, rect, 2);
- return new Rectangle (rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
-}
-
-/*
- * Returns a single character, converted from the default
- * multi-byte character set (MBCS) used by the operating
- * system widgets to a wide character set (WCS) used by Java.
- *
- * @param ch the MBCS character
- * @return the WCS character
- */
-static char mbcsToWcs (int ch) {
- return mbcsToWcs (ch, 0);
-}
-
-/*
- * Returns a single character, converted from the specified
- * multi-byte character set (MBCS) used by the operating
- * system widgets to a wide character set (WCS) used by Java.
- *
- * @param ch the MBCS character
- * @param codePage the code page used to convert the character
- * @return the WCS character
- */
-static char mbcsToWcs (int ch, int codePage) {
- if (OS.IsUnicode) return (char) ch;
- int key = ch & 0xFFFF;
- if (key <= 0x7F) return (char) ch;
- byte [] buffer;
- if (key <= 0xFF) {
- buffer = new byte [1];
- buffer [0] = (byte) key;
- } else {
- buffer = new byte [2];
- buffer [0] = (byte) ((key >> 8) & 0xFF);
- buffer [1] = (byte) (key & 0xFF);
- }
- char [] unicode = new char [1];
- int cp = codePage != 0 ? codePage : OS.CP_ACP;
- int count = OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, buffer, buffer.length, unicode, 1);
- if (count == 0) return 0;
- return unicode [0];
-}
-
-int /*long*/ messageProc (int /*long*/ hwnd, int /*long*/ msg, int /*long*/ wParam, int /*long*/ lParam) {
- switch ((int)/*64*/msg) {
- case SWT_RUNASYNC: {
- if (runMessagesInIdle) runAsyncMessages (false);
- break;
- }
- case SWT_KEYMSG: {
- boolean consumed = false;
- MSG keyMsg = new MSG ();
- OS.MoveMemory (keyMsg, lParam, MSG.sizeof);
- Control control = findControl (keyMsg.hwnd);
- if (control != null) {
- /*
- * Feature in Windows. When the user types an accent key such
- * as ^ in order to get an accented character on a German keyboard,
- * calling TranslateMessage(), ToUnicode() or ToAscii() consumes
- * the key. This means that a subsequent call to TranslateMessage()
- * will see a regular key rather than the accented key. The fix
- * is to use MapVirtualKey() and VkKeyScan () to detect an accent
- * and avoid calls to TranslateMessage().
- */
- boolean accentKey = false;
- switch (keyMsg.message) {
- case OS.WM_KEYDOWN:
- case OS.WM_SYSKEYDOWN: {
- if (!OS.IsWinCE) {
- switch ((int)/*64*/keyMsg.wParam) {
- case OS.VK_SHIFT:
- case OS.VK_MENU:
- case OS.VK_CONTROL:
- case OS.VK_CAPITAL:
- case OS.VK_NUMLOCK:
- case OS.VK_SCROLL:
- break;
- default: {
- /*
- * Bug in Windows. The high bit in the result of MapVirtualKey() on
- * Windows NT is bit 32 while the high bit on Windows 95 is bit 16.
- * They should both be bit 32. The fix is to test the right bit.
- */
- int mapKey = OS.MapVirtualKey ((int)/*64*/keyMsg.wParam, 2);
- if (mapKey != 0) {
- accentKey = (mapKey & (OS.IsWinNT ? 0x80000000 : 0x8000)) != 0;
- if (!accentKey) {
- for (int i=0; i<ACCENTS.length; i++) {
- int value = OS.VkKeyScan (ACCENTS [i]);
- if (value != -1 && (value & 0xFF) == keyMsg.wParam) {
- int state = value >> 8;
- if ((OS.GetKeyState (OS.VK_SHIFT) < 0) == ((state & 0x1) != 0) &&
- (OS.GetKeyState (OS.VK_CONTROL) < 0) == ((state & 0x2) != 0) &&
- (OS.GetKeyState (OS.VK_MENU) < 0) == ((state & 0x4) != 0)) {
- if ((state & 0x7) != 0) accentKey = true;
- break;
- }
- }
- }
- }
- }
- break;
- }
- }
- }
- break;
- }
- }
- if (!accentKey && !ignoreNextKey) {
- keyMsg.hwnd = control.handle;
- int flags = OS.PM_REMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE;
- do {
- if (!(consumed |= filterMessage (keyMsg))) {
- OS.TranslateMessage (keyMsg);
- consumed |= OS.DispatchMessage (keyMsg) == 1;
- }
- } while (OS.PeekMessage (keyMsg, keyMsg.hwnd, OS.WM_KEYFIRST, OS.WM_KEYLAST, flags));
- }
- switch (keyMsg.message) {
- case OS.WM_KEYDOWN:
- case OS.WM_SYSKEYDOWN: {
- switch ((int)/*64*/keyMsg.wParam) {
- case OS.VK_SHIFT:
- case OS.VK_MENU:
- case OS.VK_CONTROL:
- case OS.VK_CAPITAL:
- case OS.VK_NUMLOCK:
- case OS.VK_SCROLL:
- break;
- default: {
- ignoreNextKey = accentKey;
- break;
- }
- }
- }
- }
- }
- switch ((int)/*64*/keyMsg.wParam) {
- case OS.VK_SHIFT:
- case OS.VK_MENU:
- case OS.VK_CONTROL:
- case OS.VK_CAPITAL:
- case OS.VK_NUMLOCK:
- case OS.VK_SCROLL:
- consumed = true;
- }
- if (consumed) {
- int /*long*/ hHeap = OS.GetProcessHeap ();
- OS.HeapFree (hHeap, 0, lParam);
- } else {
- OS.PostMessage (embeddedHwnd, SWT_KEYMSG, wParam, lParam);
- }
- return 0;
- }
- case SWT_TRAYICONMSG: {
- if (tray != null) {
- TrayItem [] items = tray.items;
- for (int i=0; i<items.length; i++) {
- TrayItem item = items [i];
- if (item != null && item.id == wParam) {
- return item.messageProc (hwnd, (int)/*64*/msg, wParam, lParam);
- }
- }
- }
- return 0;
- }
- case OS.WM_ACTIVATEAPP: {
- /*
- * Feature in Windows. When multiple shells are
- * disabled and one of the shells has an enabled
- * dialog child and the user selects a disabled
- * shell that does not have the enabled dialog
- * child using the Task bar, Windows brings the
- * disabled shell to the front. As soon as the
- * user clicks on the disabled shell, the enabled
- * dialog child comes to the front. This behavior
- * is unspecified and seems strange. Normally, a
- * disabled shell is frozen on the screen and the
- * user cannot change the z-order by clicking with
- * the mouse. The fix is to look for WM_ACTIVATEAPP
- * and force the enabled dialog child to the front.
- * This is typically what the user is expecting.
- *
- * NOTE: If the modal shell is disabled for any
- * reason, it should not be brought to the front.
- */
- if (wParam != 0) {
- if (!isXMouseActive ()) {
- int /*long*/ hwndActive = OS.GetActiveWindow ();
- if (hwndActive != 0 && OS.IsWindowEnabled (hwndActive)) break;
- Shell modal = modalDialog != null ? modalDialog.parent : getModalShell ();
- if (modal != null && !modal.isDisposed ()) {
- int /*long*/ hwndModal = modal.handle;
- if (OS.IsWindowEnabled (hwndModal)) {
- modal.bringToTop ();
- if (modal.isDisposed ()) break;
- }
- int /*long*/ hwndPopup = OS.GetLastActivePopup (hwndModal);
- if (hwndPopup != 0 && hwndPopup != modal.handle) {
- if (getControl (hwndPopup) == null) {
- if (OS.IsWindowEnabled (hwndPopup)) {
- OS.SetActiveWindow (hwndPopup);
- }
- }
- }
- }
- }
- }
- break;
- }
- case OS.WM_ENDSESSION: {
- if (wParam != 0) {
- dispose ();
- /*
- * When the session is ending, no SWT program can continue
- * to run. In order to avoid running code after the display
- * has been disposed, exit from Java.
- */
- /* This code is intentionally commented */
-// System.exit (0);
- }
- break;
- }
- case OS.WM_QUERYENDSESSION: {
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- if (!event.doit) return 0;
- break;
- }
- case OS.WM_DWMCOLORIZATIONCOLORCHANGED: {
- sendSettings = true;
- //FALL THROUGH
- }
- case OS.WM_SETTINGCHANGE: {
- /*
- * Bug in Windows. When high contrast is cleared using
- * the key sequence, Alt + Left Shift + Print Screen, the
- * system parameter is set to false, but WM_SETTINGCHANGE
- * is not sent with SPI_SETHIGHCONTRAST. The fix is to
- * detect the change when any WM_SETTINGCHANGE message
- * is sent.
- */
- if (lastHighContrast != getHighContrast ()) {
- sendSettings = true;
- lastHighContrast = getHighContrast ();
- }
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- sendSettings = true;
- }
- switch ((int)/*64*/wParam) {
- case 0:
- case 1:
- case OS.SPI_SETHIGHCONTRAST: {
- sendSettings = true;
- lastHighContrast = getHighContrast ();
- }
- }
- /* Set the initial timer or push the time out period forward */
- if (sendSettings) {
- OS.SetTimer (hwndMessage, SETTINGS_ID, SETTINGS_DELAY, 0);
- }
- break;
- }
- case OS.WM_THEMECHANGED: {
- if (OS.COMCTL32_MAJOR >= 6) {
- if (hButtonTheme != 0) OS.CloseThemeData (hButtonTheme);
- if (hEditTheme != 0) OS.CloseThemeData (hEditTheme);
- if (hExplorerBarTheme != 0) OS.CloseThemeData (hExplorerBarTheme);
- if (hScrollBarTheme != 0) OS.CloseThemeData (hScrollBarTheme);
- if (hTabTheme != 0) OS.CloseThemeData (hTabTheme);
- hButtonTheme = hEditTheme = hExplorerBarTheme = hScrollBarTheme = hTabTheme = 0;
- }
- break;
- }
- case OS.WM_TIMER: {
- if (wParam == SETTINGS_ID) {
- sendSettings = false;
- OS.KillTimer (hwndMessage, SETTINGS_ID);
- runSettings ();
- } else {
- runTimer (wParam);
- }
- break;
- }
- default: {
- if ((int)/*64*/msg == SWT_TASKBARCREATED) {
- if (tray != null) {
- TrayItem [] items = tray.items;
- for (int i=0; i<items.length; i++) {
- TrayItem item = items [i];
- if (item != null) item.recreate ();
- }
- }
- }
- }
- }
- return OS.DefWindowProc (hwnd, (int)/*64*/msg, wParam, lParam);
-}
-
-int /*long*/ monitorEnumProc (int /*long*/ hmonitor, int /*long*/ hdc, int /*long*/ lprcMonitor, int /*long*/ dwData) {
- if (monitorCount >= monitors.length) {
- Monitor[] newMonitors = new Monitor [monitors.length + 4];
- System.arraycopy (monitors, 0, newMonitors, 0, monitors.length);
- monitors = newMonitors;
- }
- MONITORINFO lpmi = new MONITORINFO ();
- lpmi.cbSize = MONITORINFO.sizeof;
- OS.GetMonitorInfo (hmonitor, lpmi);
- Monitor monitor = new Monitor ();
- monitor.handle = hmonitor;
- monitor.x = lpmi.rcMonitor_left;
- monitor.y = lpmi.rcMonitor_top;
- monitor.width = lpmi.rcMonitor_right - lpmi.rcMonitor_left;
- monitor.height = lpmi.rcMonitor_bottom - lpmi.rcMonitor_top;
- monitor.clientX = lpmi.rcWork_left;
- monitor.clientY = lpmi.rcWork_top;
- monitor.clientWidth = lpmi.rcWork_right - lpmi.rcWork_left;
- monitor.clientHeight = lpmi.rcWork_bottom - lpmi.rcWork_top;
- monitors [monitorCount++] = monitor;
- return 1;
-}
-
-int /*long*/ msgFilterProc (int /*long*/ code, int /*long*/ wParam, int /*long*/ lParam) {
- switch ((int)/*64*/code) {
- case OS.MSGF_COMMCTRL_BEGINDRAG: {
- if (!runDragDrop && !dragCancelled) {
- OS.MoveMemory (hookMsg, lParam, MSG.sizeof);
- if (hookMsg.message == OS.WM_MOUSEMOVE) {
- dragCancelled = true;
- OS.SendMessage (hookMsg.hwnd, OS.WM_CANCELMODE, 0, 0);
- }
- }
- break;
- }
- /*
- * Feature in Windows. For some reason, when the user clicks
- * a table or tree, the Windows hook WH_MSGFILTER is sent when
- * an input event from a dialog box, message box, menu, or scroll
- * bar did not occur, causing async messages to run at the wrong
- * time. The fix is to check the message filter code.
- */
- case OS.MSGF_DIALOGBOX:
- case OS.MSGF_MAINLOOP:
- case OS.MSGF_MENU:
- case OS.MSGF_MOVE:
- case OS.MSGF_MESSAGEBOX:
- case OS.MSGF_NEXTWINDOW:
- case OS.MSGF_SCROLLBAR:
- case OS.MSGF_SIZE: {
- if (runMessages) {
- OS.MoveMemory (hookMsg, lParam, MSG.sizeof);
- if (hookMsg.message == OS.WM_NULL) {
- MSG msg = new MSG ();
- int flags = OS.PM_NOREMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE;
- if (!OS.PeekMessage (msg, 0, 0, 0, flags)) {
- if (runAsyncMessages (false)) wakeThread ();
- }
- }
- }
- break;
- }
- }
- return OS.CallNextHookEx (filterHook, (int)/*64*/code, wParam, lParam);
-}
-
-int numpadKey (int key) {
- switch (key) {
- case OS.VK_NUMPAD0: return '0';
- case OS.VK_NUMPAD1: return '1';
- case OS.VK_NUMPAD2: return '2';
- case OS.VK_NUMPAD3: return '3';
- case OS.VK_NUMPAD4: return '4';
- case OS.VK_NUMPAD5: return '5';
- case OS.VK_NUMPAD6: return '6';
- case OS.VK_NUMPAD7: return '7';
- case OS.VK_NUMPAD8: return '8';
- case OS.VK_NUMPAD9: return '9';
- case OS.VK_MULTIPLY: return '*';
- case OS.VK_ADD: return '+';
- case OS.VK_SEPARATOR: return '\0';
- case OS.VK_SUBTRACT: return '-';
- case OS.VK_DECIMAL: return '.';
- case OS.VK_DIVIDE: return '/';
- }
- return 0;
-}
-
-/**
- * Generate a low level system event.
- *
- * <code>post</code> is used to generate low level keyboard
- * and mouse events. The intent is to enable automated UI
- * testing by simulating the input from the user. Most
- * SWT applications should never need to call this method.
- * <p>
- * Note that this operation can fail when the operating system
- * fails to generate the event for any reason. For example,
- * this can happen when there is no such key or mouse button
- * or when the system event queue is full.
- * </p>
- * <p>
- * <b>Event Types:</b>
- * <p>KeyDown, KeyUp
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type KeyDown or KeyUp</li>
- * <p> Either one of:
- * <li>(in) character a character that corresponds to a keyboard key</li>
- * <li>(in) keyCode the key code of the key that was typed,
- * as defined by the key code constants in class <code>SWT</code></li>
- * </ul>
- * <p>MouseDown, MouseUp</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseDown or MouseUp
- * <li>(in) button the button that is pressed or released
- * </ul>
- * <p>MouseMove</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseMove
- * <li>(in) x the x coordinate to move the mouse pointer to in screen coordinates
- * <li>(in) y the y coordinate to move the mouse pointer to in screen coordinates
- * </ul>
- * <p>MouseWheel</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseWheel
- * <li>(in) detail either SWT.SCROLL_LINE or SWT.SCROLL_PAGE
- * <li>(in) count the number of lines or pages to scroll
- * </ul>
- * </dl>
- *
- * @param event the event to be generated
- *
- * @return true if the event was generated or false otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public boolean post (Event event) {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- int type = event.type;
- switch (type){
- case SWT.KeyDown:
- case SWT.KeyUp: {
- KEYBDINPUT inputs = new KEYBDINPUT ();
- inputs.wVk = (short) untranslateKey (event.keyCode);
- if (inputs.wVk == 0) {
- char key = event.character;
- switch (key) {
- case SWT.BS: inputs.wVk = (short) OS.VK_BACK; break;
- case SWT.CR: inputs.wVk = (short) OS.VK_RETURN; break;
- case SWT.DEL: inputs.wVk = (short) OS.VK_DELETE; break;
- case SWT.ESC: inputs.wVk = (short) OS.VK_ESCAPE; break;
- case SWT.TAB: inputs.wVk = (short) OS.VK_TAB; break;
- /*
- * Since there is no LF key on the keyboard, do not attempt
- * to map LF to CR or attempt to post an LF key.
- */
-// case SWT.LF: inputs.wVk = (short) OS.VK_RETURN; break;
- case SWT.LF: return false;
- default: {
- if (OS.IsWinCE) {
- inputs.wVk = (short)/*64*/OS.CharUpper ((short) key);
- } else {
- inputs.wVk = OS.VkKeyScan ((short) wcsToMbcs (key, 0));
- if (inputs.wVk == -1) return false;
- inputs.wVk &= 0xFF;
- }
- }
- }
- }
- inputs.dwFlags = type == SWT.KeyUp ? OS.KEYEVENTF_KEYUP : 0;
- int /*long*/ hHeap = OS.GetProcessHeap ();
- int /*long*/ pInputs = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, INPUT.sizeof);
- OS.MoveMemory(pInputs, new int[] {OS.INPUT_KEYBOARD}, 4);
- //TODO - DWORD type of INPUT structure aligned to 8 bytes on 64 bit
- OS.MoveMemory (pInputs + OS.PTR_SIZEOF, inputs, KEYBDINPUT.sizeof);
- boolean result = OS.SendInput (1, pInputs, INPUT.sizeof) != 0;
- OS.HeapFree (hHeap, 0, pInputs);
- return result;
- }
- case SWT.MouseDown:
- case SWT.MouseMove:
- case SWT.MouseUp:
- case SWT.MouseWheel: {
- MOUSEINPUT inputs = new MOUSEINPUT ();
- if (type == SWT.MouseMove){
- inputs.dwFlags = OS.MOUSEEVENTF_MOVE | OS.MOUSEEVENTF_ABSOLUTE;
- int x= 0, y = 0, width = 0, height = 0;
- if (OS.WIN32_VERSION >= OS.VERSION (5, 0)) {
- inputs.dwFlags |= OS.MOUSEEVENTF_VIRTUALDESK;
- x = OS.GetSystemMetrics (OS.SM_XVIRTUALSCREEN);
- y = OS.GetSystemMetrics (OS.SM_YVIRTUALSCREEN);
- width = OS.GetSystemMetrics (OS.SM_CXVIRTUALSCREEN);
- height = OS.GetSystemMetrics (OS.SM_CYVIRTUALSCREEN);
- } else {
- width = OS.GetSystemMetrics (OS.SM_CXSCREEN);
- height = OS.GetSystemMetrics (OS.SM_CYSCREEN);
- }
- inputs.dx = ((event.x - x) * 65535 + width - 2) / (width - 1);
- inputs.dy = ((event.y - y) * 65535 + height - 2) / (height - 1);
- } else {
- if (type == SWT.MouseWheel) {
- if (OS.WIN32_VERSION < OS.VERSION (5, 0)) return false;
- inputs.dwFlags = OS.MOUSEEVENTF_WHEEL;
- switch (event.detail) {
- case SWT.SCROLL_PAGE:
- inputs.mouseData = event.count * OS.WHEEL_DELTA;
- break;
- case SWT.SCROLL_LINE:
- int [] value = new int [1];
- OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, value, 0);
- inputs.mouseData = event.count * OS.WHEEL_DELTA / value [0];
- break;
- default: return false;
- }
- } else {
- switch (event.button) {
- case 1: inputs.dwFlags = type == SWT.MouseDown ? OS.MOUSEEVENTF_LEFTDOWN : OS.MOUSEEVENTF_LEFTUP; break;
- case 2: inputs.dwFlags = type == SWT.MouseDown ? OS.MOUSEEVENTF_MIDDLEDOWN : OS.MOUSEEVENTF_MIDDLEUP; break;
- case 3: inputs.dwFlags = type == SWT.MouseDown ? OS.MOUSEEVENTF_RIGHTDOWN : OS.MOUSEEVENTF_RIGHTUP; break;
- case 4: {
- if (OS.WIN32_VERSION < OS.VERSION (5, 0)) return false;
- inputs.dwFlags = type == SWT.MouseDown ? OS.MOUSEEVENTF_XDOWN : OS.MOUSEEVENTF_XUP;
- inputs.mouseData = OS.XBUTTON1;
- break;
- }
- case 5: {
- if (OS.WIN32_VERSION < OS.VERSION (5, 0)) return false;
- inputs.dwFlags = type == SWT.MouseDown ? OS.MOUSEEVENTF_XDOWN : OS.MOUSEEVENTF_XUP;
- inputs.mouseData = OS.XBUTTON2;
- break;
- }
- default: return false;
- }
- }
- }
- int /*long*/ hHeap = OS.GetProcessHeap ();
- int /*long*/ pInputs = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, INPUT.sizeof);
- OS.MoveMemory(pInputs, new int[] {OS.INPUT_MOUSE}, 4);
- //TODO - DWORD type of INPUT structure aligned to 8 bytes on 64 bit
- OS.MoveMemory (pInputs + OS.PTR_SIZEOF, inputs, MOUSEINPUT.sizeof);
- boolean result = OS.SendInput (1, pInputs, INPUT.sizeof) != 0;
- OS.HeapFree (hHeap, 0, pInputs);
- return result;
- }
- }
- return false;
- }
-}
-
-void postEvent (Event event) {
- /*
- * Place the event at the end of the event queue.
- * This code is always called in the Display's
- * thread so it must be re-enterant but does not
- * need to be synchronized.
- */
- if (eventQueue == null) eventQueue = new Event [4];
- int index = 0;
- int length = eventQueue.length;
- while (index < length) {
- if (eventQueue [index] == null) break;
- index++;
- }
- if (index == length) {
- Event [] newQueue = new Event [length + 4];
- System.arraycopy (eventQueue, 0, newQueue, 0, length);
- eventQueue = newQueue;
- }
- eventQueue [index] = event;
-}
-
-/**
- * Reads an event from the operating system's event queue,
- * dispatches it appropriately, and returns <code>true</code>
- * if there is potentially more work to do, or <code>false</code>
- * if the caller can sleep until another event is placed on
- * the event queue.
- * <p>
- * In addition to checking the system event queue, this method also
- * checks if any inter-thread messages (created by <code>syncExec()</code>
- * or <code>asyncExec()</code>) are waiting to be processed, and if
- * so handles them before returning.
- * </p>
- *
- * @return <code>false</code> if the caller can sleep upon return from this method
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li>
- * </ul>
- *
- * @see #sleep
- * @see #wake
- */
-public boolean readAndDispatch () {
- checkDevice ();
- lpStartupInfo = null;
- drawMenuBars ();
- runPopups ();
- if (OS.PeekMessage (msg, 0, 0, 0, OS.PM_REMOVE)) {
- if (!filterMessage (msg)) {
- OS.TranslateMessage (msg);
- OS.DispatchMessage (msg);
- }
- runDeferredEvents ();
- return true;
- }
- return isDisposed () || (runMessages && runAsyncMessages (false));
-}
-
-static void register (Display display) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] == null) {
- Displays [i] = display;
- return;
- }
- }
- Display [] newDisplays = new Display [Displays.length + 4];
- System.arraycopy (Displays, 0, newDisplays, 0, Displays.length);
- newDisplays [Displays.length] = display;
- Displays = newDisplays;
- }
-}
-
-/**
- * Releases any internal resources back to the operating
- * system and clears all fields except the device handle.
- * <p>
- * Disposes all shells which are currently open on the display.
- * After this method has been invoked, all related related shells
- * will answer <code>true</code> when sent the message
- * <code>isDisposed()</code>.
- * </p><p>
- * When a device is destroyed, resources that were acquired
- * on behalf of the programmer need to be returned to the
- * operating system. For example, if the device allocated a
- * font to be used as the system font, this font would be
- * freed in <code>release</code>. Also,to assist the garbage
- * collector and minimize the amount of memory that is not
- * reclaimed when the programmer keeps a reference to a
- * disposed device, all fields except the handle are zero'd.
- * The handle is needed by <code>destroy</code>.
- * </p>
- * This method is called before <code>destroy</code>.
- *
- * @see Device#dispose
- * @see #destroy
- */
-protected void release () {
- sendEvent (SWT.Dispose, new Event ());
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) shell.dispose ();
- }
- if (tray != null) tray.dispose ();
- tray = null;
- while (readAndDispatch ()) {}
- if (disposeList != null) {
- for (int i=0; i<disposeList.length; i++) {
- if (disposeList [i] != null) disposeList [i].run ();
- }
- }
- disposeList = null;
- synchronizer.releaseSynchronizer ();
- synchronizer = null;
- releaseDisplay ();
- super.release ();
-}
-
-void releaseDisplay () {
- if (embeddedHwnd != 0) {
- OS.PostMessage (embeddedHwnd, SWT_DESTROY, 0, 0);
- }
-
- /* Release XP Themes */
- if (OS.COMCTL32_MAJOR >= 6) {
- if (hButtonTheme != 0) OS.CloseThemeData (hButtonTheme);
- if (hEditTheme != 0) OS.CloseThemeData (hEditTheme);
- if (hExplorerBarTheme != 0) OS.CloseThemeData (hExplorerBarTheme);
- if (hScrollBarTheme != 0) OS.CloseThemeData (hScrollBarTheme);
- if (hTabTheme != 0) OS.CloseThemeData (hTabTheme);
- hButtonTheme = hEditTheme = hExplorerBarTheme = hScrollBarTheme = hTabTheme = 0;
- }
-
- /* Unhook the message hook */
- if (!OS.IsWinCE) {
- if (msgHook != 0) OS.UnhookWindowsHookEx (msgHook);
- msgHook = 0;
- }
-
- /* Unhook the filter hook */
- if (!OS.IsWinCE) {
- if (filterHook != 0) OS.UnhookWindowsHookEx (filterHook);
- filterHook = 0;
- msgFilterCallback.dispose ();
- msgFilterCallback = null;
- msgFilterProc = 0;
- }
-
- /* Unhook the idle hook */
- if (!OS.IsWinCE) {
- if (idleHook != 0) OS.UnhookWindowsHookEx (idleHook);
- idleHook = 0;
- foregroundIdleCallback.dispose ();
- foregroundIdleCallback = null;
- foregroundIdleProc = 0;
- }
-
- /* Stop the settings timer */
- OS.KillTimer (hwndMessage, SETTINGS_ID);
-
- /* Destroy the message only HWND */
- if (hwndMessage != 0) OS.DestroyWindow (hwndMessage);
- hwndMessage = 0;
- messageCallback.dispose ();
- messageCallback = null;
- messageProc = 0;
-
- /* Unregister the SWT window class */
- int /*long*/ hHeap = OS.GetProcessHeap ();
- int /*long*/ hInstance = OS.GetModuleHandle (null);
- OS.UnregisterClass (windowClass, hInstance);
-
- /* Unregister the SWT drop shadow and CS_OWNDC window class */
- OS.UnregisterClass (windowShadowClass, hInstance);
- OS.UnregisterClass (windowOwnDCClass, hInstance);
- windowClass = windowShadowClass = windowOwnDCClass = null;
- windowCallback.dispose ();
- windowCallback = null;
- windowProc = 0;
-
- /* Release the System fonts */
- if (systemFont != null) systemFont.dispose ();
- systemFont = null;
- lfSystemFont = null;
-
- /* Release the System Images */
- if (errorImage != null) errorImage.dispose ();
- if (infoImage != null) infoImage.dispose ();
- if (questionImage != null) questionImage.dispose ();
- if (warningIcon != null) warningIcon.dispose ();
- errorImage = infoImage = questionImage = warningIcon = null;
-
- /* Release Sort Indicators */
- if (upArrow != null) upArrow.dispose ();
- if (downArrow != null) downArrow.dispose ();
- upArrow = downArrow = null;
-
- /* Release the System Cursors */
- for (int i = 0; i < cursors.length; i++) {
- if (cursors [i] != null) cursors [i].dispose ();
- }
- cursors = null;
-
- /* Release Acquired Resources */
- if (resources != null) {
- for (int i=0; i<resources.length; i++) {
- if (resources [i] != null) resources [i].dispose ();
- }
- resources = null;
- }
-
- /* Release Custom Colors for ChooseColor */
- if (lpCustColors != 0) OS.HeapFree (hHeap, 0, lpCustColors);
- lpCustColors = 0;
-
- /* Uninitialize OLE */
- if (!OS.IsWinCE) OS.OleUninitialize ();
-
- /* Uninitialize buffered painting */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- OS.BufferedPaintUnInit ();
- }
-
- /* Release references */
- thread = null;
- msg = hookMsg = null;
- keyboard = null;
- modalDialog = null;
- modalShells = null;
- data = null;
- keys = null;
- values = null;
- bars = popups = null;
- indexTable = null;
- timerIds = null;
- controlTable = null;
- lastControl = lastGetControl = lastHittestControl = null;
- imageList = toolImageList = toolHotImageList = toolDisabledImageList = null;
- timerList = null;
- tableBuffer = null;
- columnVisible = null;
- eventTable = filterTable = null;
- items = null;
- clickRect = null;
- hdr = null;
- plvfi = null;
-
- /* Release handles */
- threadId = 0;
-}
-
-void releaseImageList (ImageList list) {
- int i = 0;
- int length = imageList.length;
- while (i < length) {
- if (imageList [i] == list) {
- if (list.removeRef () > 0) return;
- list.dispose ();
- System.arraycopy (imageList, i + 1, imageList, i, --length - i);
- imageList [length] = null;
- for (int j=0; j<length; j++) {
- if (imageList [j] != null) return;
- }
- imageList = null;
- return;
- }
- i++;
- }
-}
-
-void releaseToolImageList (ImageList list) {
- int i = 0;
- int length = toolImageList.length;
- while (i < length) {
- if (toolImageList [i] == list) {
- if (list.removeRef () > 0) return;
- list.dispose ();
- System.arraycopy (toolImageList, i + 1, toolImageList, i, --length - i);
- toolImageList [length] = null;
- for (int j=0; j<length; j++) {
- if (toolImageList [j] != null) return;
- }
- toolImageList = null;
- return;
- }
- i++;
- }
-}
-
-void releaseToolHotImageList (ImageList list) {
- int i = 0;
- int length = toolHotImageList.length;
- while (i < length) {
- if (toolHotImageList [i] == list) {
- if (list.removeRef () > 0) return;
- list.dispose ();
- System.arraycopy (toolHotImageList, i + 1, toolHotImageList, i, --length - i);
- toolHotImageList [length] = null;
- for (int j=0; j<length; j++) {
- if (toolHotImageList [j] != null) return;
- }
- toolHotImageList = null;
- return;
- }
- i++;
- }
-}
-
-void releaseToolDisabledImageList (ImageList list) {
- int i = 0;
- int length = toolDisabledImageList.length;
- while (i < length) {
- if (toolDisabledImageList [i] == list) {
- if (list.removeRef () > 0) return;
- list.dispose ();
- System.arraycopy (toolDisabledImageList, i + 1, toolDisabledImageList, i, --length - i);
- toolDisabledImageList [length] = null;
- for (int j=0; j<length; j++) {
- if (toolDisabledImageList [j] != null) return;
- }
- toolDisabledImageList = null;
- return;
- }
- i++;
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs anywhere in
- * a widget. The event type is one of the event constants defined
- * in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addFilter
- * @see #addListener
- *
- * @since 3.0
- */
-public void removeFilter (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (filterTable == null) return;
- filterTable.unhook (eventType, listener);
- if (filterTable.size () == 0) filterTable = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs. The event type
- * is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener
- *
- * @since 2.0
- */
-public void removeListener (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, listener);
-}
-
-void removeBar (Menu menu) {
- if (bars == null) return;
- for (int i=0; i<bars.length; i++) {
- if (bars [i] == menu) {
- bars [i] = null;
- return;
- }
- }
-}
-
-Control removeControl (int /*long*/ handle) {
- if (handle == 0) return null;
- lastControl = lastGetControl = null;
- Control control = null;
- int index;
- if (USE_PROPERTY) {
- index = (int)/*64*/OS.RemoveProp (handle, SWT_OBJECT_INDEX) - 1;
- } else {
- index = (int)/*64*/OS.GetWindowLongPtr (handle, OS.GWLP_USERDATA) - 1;
- OS.SetWindowLongPtr (handle, OS.GWLP_USERDATA, 0);
- }
- if (0 <= index && index < controlTable.length) {
- control = controlTable [index];
- controlTable [index] = null;
- indexTable [index] = freeSlot;
- freeSlot = index;
- }
- return control;
-}
-
-void removeMenuItem (MenuItem item) {
- if (items == null) return;
- items [item.id - ID_START] = null;
-}
-
-void removePopup (Menu menu) {
- if (popups == null) return;
- for (int i=0; i<popups.length; i++) {
- if (popups [i] == menu) {
- popups [i] = null;
- return;
- }
- }
-}
-
-boolean runAsyncMessages (boolean all) {
- return synchronizer.runAsyncMessages (all);
-}
-
-boolean runDeferredEvents () {
- boolean run = false;
- /*
- * Run deferred events. This code is always
- * called in the Display's thread so it must
- * be re-enterant but need not be synchronized.
- */
- while (eventQueue != null) {
-
- /* Take an event off the queue */
- Event event = eventQueue [0];
- if (event == null) break;
- int length = eventQueue.length;
- System.arraycopy (eventQueue, 1, eventQueue, 0, --length);
- eventQueue [length] = null;
-
- /* Run the event */
- Widget widget = event.widget;
- if (widget != null && !widget.isDisposed ()) {
- Widget item = event.item;
- if (item == null || !item.isDisposed ()) {
- run = true;
- widget.sendEvent (event);
- }
- }
-
- /*
- * At this point, the event queue could
- * be null due to a recursive invocation
- * when running the event.
- */
- }
-
- /* Clear the queue */
- eventQueue = null;
- return run;
-}
-
-boolean runPopups () {
- if (popups == null) return false;
- boolean result = false;
- while (popups != null) {
- Menu menu = popups [0];
- if (menu == null) break;
- int length = popups.length;
- System.arraycopy (popups, 1, popups, 0, --length);
- popups [length] = null;
- runDeferredEvents ();
- if (!menu.isDisposed ()) menu._setVisible (true);
- result = true;
- }
- popups = null;
- return result;
-}
-
-void runSettings () {
- Font oldFont = getSystemFont ();
- saveResources ();
- updateImages ();
- sendEvent (SWT.Settings, null);
- Font newFont = getSystemFont ();
- boolean sameFont = oldFont.equals (newFont);
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) {
- if (!sameFont) {
- shell.updateFont (oldFont, newFont);
- }
- /* This code is intentionally commented */
- //shell.redraw (true);
- shell.layout (true, true);
- }
- }
-}
-
-boolean runTimer (int /*long*/ id) {
- if (timerList != null && timerIds != null) {
- int index = 0;
- while (index <timerIds.length) {
- if (timerIds [index] == id) {
- OS.KillTimer (hwndMessage, timerIds [index]);
- timerIds [index] = 0;
- Runnable runnable = timerList [index];
- timerList [index] = null;
- if (runnable != null) runnable.run ();
- return true;
- }
- index++;
- }
- }
- return false;
-}
-
-void saveResources () {
- int resourceCount = 0;
- if (resources == null) {
- resources = new Resource [RESOURCE_SIZE];
- } else {
- resourceCount = resources.length;
- Resource [] newResources = new Resource [resourceCount + RESOURCE_SIZE];
- System.arraycopy (resources, 0, newResources, 0, resourceCount);
- resources = newResources;
- }
- if (systemFont != null) {
- if (!OS.IsWinCE) {
- NONCLIENTMETRICS info = OS.IsUnicode ? (NONCLIENTMETRICS) new NONCLIENTMETRICSW () : new NONCLIENTMETRICSA ();
- info.cbSize = NONCLIENTMETRICS.sizeof;
- if (OS.SystemParametersInfo (OS.SPI_GETNONCLIENTMETRICS, 0, info, 0)) {
- LOGFONT logFont = OS.IsUnicode ? (LOGFONT) ((NONCLIENTMETRICSW)info).lfMessageFont : ((NONCLIENTMETRICSA)info).lfMessageFont;
- if (lfSystemFont == null ||
- logFont.lfCharSet != lfSystemFont.lfCharSet ||
- logFont.lfHeight != lfSystemFont.lfHeight ||
- logFont.lfWidth != lfSystemFont.lfWidth ||
- logFont.lfEscapement != lfSystemFont.lfEscapement ||
- logFont.lfOrientation != lfSystemFont.lfOrientation ||
- logFont.lfWeight != lfSystemFont.lfWeight ||
- logFont.lfItalic != lfSystemFont.lfItalic ||
- logFont.lfUnderline != lfSystemFont.lfUnderline ||
- logFont.lfStrikeOut != lfSystemFont.lfStrikeOut ||
- logFont.lfCharSet != lfSystemFont.lfCharSet ||
- logFont.lfOutPrecision != lfSystemFont.lfOutPrecision ||
- logFont.lfClipPrecision != lfSystemFont.lfClipPrecision ||
- logFont.lfQuality != lfSystemFont.lfQuality ||
- logFont.lfPitchAndFamily != lfSystemFont.lfPitchAndFamily ||
- !getFontName (logFont).equals (getFontName (lfSystemFont))) {
- resources [resourceCount++] = systemFont;
- lfSystemFont = logFont;
- systemFont = null;
- }
- }
- }
- }
- if (errorImage != null) resources [resourceCount++] = errorImage;
- if (infoImage != null) resources [resourceCount++] = infoImage;
- if (questionImage != null) resources [resourceCount++] = questionImage;
- if (warningIcon != null) resources [resourceCount++] = warningIcon;
- errorImage = infoImage = questionImage = warningIcon = null;
- for (int i=0; i<cursors.length; i++) {
- if (cursors [i] != null) resources [resourceCount++] = cursors [i];
- cursors [i] = null;
- }
- if (resourceCount < RESOURCE_SIZE) {
- Resource [] newResources = new Resource [resourceCount];
- System.arraycopy (resources, 0, newResources, 0, resourceCount);
- resources = newResources;
- }
-}
-
-void sendEvent (int eventType, Event event) {
- if (eventTable == null && filterTable == null) {
- return;
- }
- if (event == null) event = new Event ();
- event.display = this;
- event.type = eventType;
- if (event.time == 0) event.time = getLastEventTime ();
- if (!filterEvent (event)) {
- if (eventTable != null) eventTable.sendEvent (event);
- }
-}
-
-/**
- * Sets the location of the on-screen pointer relative to the top left corner
- * of the screen. <b>Note: It is typically considered bad practice for a
- * program to move the on-screen pointer location.</b>
- *
- * @param x the new x coordinate for the cursor
- * @param y the new y coordinate for the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1
- */
-public void setCursorLocation (int x, int y) {
- checkDevice ();
- OS.SetCursorPos (x, y);
-}
-
-/**
- * Sets the location of the on-screen pointer relative to the top left corner
- * of the screen. <b>Note: It is typically considered bad practice for a
- * program to move the on-screen pointer location.</b>
- *
- * @param point new position
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_NULL_ARGUMENT - if the point is null
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setCursorLocation (Point point) {
- checkDevice ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- setCursorLocation (point.x, point.y);
-}
-
-/**
- * Sets the application defined property of the receiver
- * with the specified name to the given argument.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the display is disposed
- * of, it is the application's responsibility provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param key the name of the property
- * @param value the new value for the property
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getData(String)
- * @see #disposeExec(Runnable)
- */
-public void setData (String key, Object value) {
- checkDevice ();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
-
- if (key.equals (RUN_MESSAGES_IN_IDLE_KEY)) {
- Boolean data = (Boolean) value;
- runMessagesInIdle = data != null && data.booleanValue ();
- return;
- }
- if (key.equals (RUN_MESSAGES_IN_MESSAGE_PROC_KEY)) {
- Boolean data = (Boolean) value;
- runMessagesInMessageProc = data != null && data.booleanValue ();
- return;
- }
- if (key.equals (USE_OWNDC_KEY)) {
- Boolean data = (Boolean) value;
- useOwnDC = data != null && data.booleanValue ();
- return;
- }
- /* Remove the key/value pair */
- if (value == null) {
- if (keys == null) return;
- int index = 0;
- while (index < keys.length && !keys [index].equals (key)) index++;
- if (index == keys.length) return;
- if (keys.length == 1) {
- keys = null;
- values = null;
- } else {
- String [] newKeys = new String [keys.length - 1];
- Object [] newValues = new Object [values.length - 1];
- System.arraycopy (keys, 0, newKeys, 0, index);
- System.arraycopy (keys, index + 1, newKeys, index, newKeys.length - index);
- System.arraycopy (values, 0, newValues, 0, index);
- System.arraycopy (values, index + 1, newValues, index, newValues.length - index);
- keys = newKeys;
- values = newValues;
- }
- return;
- }
-
- /* Add the key/value pair */
- if (keys == null) {
- keys = new String [] {key};
- values = new Object [] {value};
- return;
- }
- for (int i=0; i<keys.length; i++) {
- if (keys [i].equals (key)) {
- values [i] = value;
- return;
- }
- }
- String [] newKeys = new String [keys.length + 1];
- Object [] newValues = new Object [values.length + 1];
- System.arraycopy (keys, 0, newKeys, 0, keys.length);
- System.arraycopy (values, 0, newValues, 0, values.length);
- newKeys [keys.length] = key;
- newValues [values.length] = value;
- keys = newKeys;
- values = newValues;
-}
-
-/**
- * Sets the application defined, display specific data
- * associated with the receiver, to the argument.
- * The <em>display specific data</em> is a single,
- * unnamed field that is stored with every display.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the display specific data needs to
- * be notified when the display is disposed of, it is the
- * application's responsibility provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param data the new display specific data
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getData()
- * @see #disposeExec(Runnable)
- */
-public void setData (Object data) {
- checkDevice ();
- this.data = data;
-}
-
-/**
- * On platforms which support it, sets the application name
- * to be the argument. On Motif, for example, this can be used
- * to set the name used for resource lookup. Specifying
- * <code>null</code> for the name clears it.
- *
- * @param name the new app name or <code>null</code>
- */
-public static void setAppName (String name) {
- /* Do nothing */
-}
-
-void setModalDialog (Dialog modalDailog) {
- this.modalDialog = modalDailog;
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) shells [i].updateModal ();
-}
-
-void setModalShell (Shell shell) {
- if (modalShells == null) modalShells = new Shell [4];
- int index = 0, length = modalShells.length;
- while (index < length) {
- if (modalShells [index] == shell) return;
- if (modalShells [index] == null) break;
- index++;
- }
- if (index == length) {
- Shell [] newModalShells = new Shell [length + 4];
- System.arraycopy (modalShells, 0, newModalShells, 0, length);
- modalShells = newModalShells;
- }
- modalShells [index] = shell;
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) shells [i].updateModal ();
-}
-
-/**
- * Sets the synchronizer used by the display to be
- * the argument, which can not be null.
- *
- * @param synchronizer the new synchronizer for the display (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the synchronizer is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li>
- * </ul>
- */
-public void setSynchronizer (Synchronizer synchronizer) {
- checkDevice ();
- if (synchronizer == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (synchronizer == this.synchronizer) return;
- Synchronizer oldSynchronizer;
- synchronized (Device.class) {
- oldSynchronizer = this.synchronizer;
- this.synchronizer = synchronizer;
- }
- if (oldSynchronizer != null) {
- oldSynchronizer.runAsyncMessages(true);
- }
-}
-
-int shiftedKey (int key) {
- if (OS.IsWinCE) return 0;
-
- /* Clear the virtual keyboard and press the shift key */
- for (int i=0; i<keyboard.length; i++) keyboard [i] = 0;
- keyboard [OS.VK_SHIFT] |= 0x80;
-
- /* Translate the key to ASCII or UNICODE using the virtual keyboard */
- if (OS.IsUnicode) {
- char [] result = new char [1];
- if (OS.ToUnicode (key, key, keyboard, result, 1, 0) == 1) return result [0];
- } else {
- short [] result = new short [1];
- if (OS.ToAscii (key, key, keyboard, result, 0) == 1) return result [0];
- }
- return 0;
-}
-
-/**
- * Causes the user-interface thread to <em>sleep</em> (that is,
- * to be put in a state where it does not consume CPU cycles)
- * until an event is received or it is otherwise awakened.
- *
- * @return <code>true</code> if an event requiring dispatching was placed on the queue.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #wake
- */
-public boolean sleep () {
- checkDevice ();
- if (runMessages && getMessageCount () != 0) return true;
- if (OS.IsWinCE) {
- OS.MsgWaitForMultipleObjectsEx (0, 0, OS.INFINITE, OS.QS_ALLINPUT, OS.MWMO_INPUTAVAILABLE);
- return true;
- }
- return OS.WaitMessage ();
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread at the next
- * reasonable opportunity. The thread which calls this method
- * is suspended until the runnable completes. Specifying <code>null</code>
- * as the runnable simply wakes the user-interface thread.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param runnable code to run on the user-interface thread or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_FAILED_EXEC - if an exception occurred when executing the runnable</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #asyncExec
- */
-public void syncExec (Runnable runnable) {
- Synchronizer synchronizer;
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- synchronizer = this.synchronizer;
- }
- synchronizer.syncExec (runnable);
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread after the specified
- * number of milliseconds have elapsed. If milliseconds is less
- * than zero, the runnable is not executed.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param milliseconds the delay before running the runnable
- * @param runnable code to run on the user-interface thread
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #asyncExec
- */
-public void timerExec (int milliseconds, Runnable runnable) {
- checkDevice ();
- if (runnable == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (timerList == null) timerList = new Runnable [4];
- if (timerIds == null) timerIds = new int /*long*/ [4];
- int index = 0;
- while (index < timerList.length) {
- if (timerList [index] == runnable) break;
- index++;
- }
- int /*long*/ timerId = 0;
- if (index != timerList.length) {
- timerId = timerIds [index];
- if (milliseconds < 0) {
- OS.KillTimer (hwndMessage, timerId);
- timerList [index] = null;
- timerIds [index] = 0;
- return;
- }
- } else {
- if (milliseconds < 0) return;
- index = 0;
- while (index < timerList.length) {
- if (timerList [index] == null) break;
- index++;
- }
- timerId = nextTimerId++;
- if (index == timerList.length) {
- Runnable [] newTimerList = new Runnable [timerList.length + 4];
- System.arraycopy (timerList, 0, newTimerList, 0, timerList.length);
- timerList = newTimerList;
- int /*long*/ [] newTimerIds = new int /*long*/ [timerIds.length + 4];
- System.arraycopy (timerIds, 0, newTimerIds, 0, timerIds.length);
- timerIds = newTimerIds;
- }
- }
- int /*long*/ newTimerID = OS.SetTimer (hwndMessage, timerId, milliseconds, 0);
- if (newTimerID != 0) {
- timerList [index] = runnable;
- timerIds [index] = newTimerID;
- }
-}
-
-boolean translateAccelerator (MSG msg, Control control) {
- accelKeyHit = true;
- boolean result = control.translateAccelerator (msg);
- accelKeyHit = false;
- return result;
-}
-
-static int translateKey (int key) {
- for (int i=0; i<KeyTable.length; i++) {
- if (KeyTable [i] [0] == key) return KeyTable [i] [1];
- }
- return 0;
-}
-
-boolean translateMnemonic (MSG msg, Control control) {
- switch (msg.message) {
- case OS.WM_CHAR:
- case OS.WM_SYSCHAR:
- return control.translateMnemonic (msg);
- }
- return false;
-}
-
-boolean translateTraversal (MSG msg, Control control) {
- switch (msg.message) {
- case OS.WM_KEYDOWN:
- switch ((int)/*64*/msg.wParam) {
- case OS.VK_RETURN:
- case OS.VK_ESCAPE:
- case OS.VK_TAB:
- case OS.VK_UP:
- case OS.VK_DOWN:
- case OS.VK_LEFT:
- case OS.VK_RIGHT:
- case OS.VK_PRIOR:
- case OS.VK_NEXT:
- return control.translateTraversal (msg);
- }
- break;
- case OS.WM_SYSKEYDOWN:
- switch ((int)/*64*/msg.wParam) {
- case OS.VK_MENU:
- return control.translateTraversal (msg);
- }
- break;
- }
- return false;
-}
-
-static int untranslateKey (int key) {
- for (int i=0; i<KeyTable.length; i++) {
- if (KeyTable [i] [1] == key) return KeyTable [i] [0];
- }
- return 0;
-}
-
-/**
- * Forces all outstanding paint requests for the display
- * to be processed before this method returns.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Control#update()
- */
-public void update() {
- checkDevice ();
- /*
- * Feature in Windows. When an application does not remove
- * events from the event queue for some time, Windows assumes
- * the application is not responding and no longer sends paint
- * events to the application. The fix is to detect that the
- * application is not responding and call PeekMessage() with
- * PM_REMOVE to tell Windows that the application is ready
- * to dispatch events. Note that the message does not have
- * to be found or dispatched in order to wake Windows up.
- *
- * NOTE: This allows other cross thread messages to be delivered,
- * most notably WM_ACTIVATE.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- if (OS.IsHungAppWindow (hwndMessage)) {
- MSG msg = new MSG ();
- int flags = OS.PM_REMOVE | OS.PM_NOYIELD;
- OS.PeekMessage (msg, hwndMessage, SWT_NULL, SWT_NULL, flags);
- }
- }
- Shell[] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) shell.update (true);
- }
-}
-
-void updateImages () {
- if (upArrow != null) upArrow.dispose ();
- if (downArrow != null) downArrow.dispose ();
- upArrow = downArrow = null;
- for (int i=0; i<controlTable.length; i++) {
- Control control = controlTable [i];
- if (control != null) control.updateImages ();
- }
-}
-
-/**
- * If the receiver's user-interface thread was <code>sleep</code>ing,
- * causes it to be awakened and start running again. Note that this
- * method may be called from any thread.
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #sleep
- */
-public void wake () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- if (thread == Thread.currentThread ()) return;
- wakeThread ();
- }
-}
-
-void wakeThread () {
- if (OS.IsWinCE) {
- OS.PostMessage (hwndMessage, OS.WM_NULL, 0, 0);
- } else {
- OS.PostThreadMessage (threadId, OS.WM_NULL, 0, 0);
- }
-}
-
-/*
- * Returns a single character, converted from the wide
- * character set (WCS) used by Java to the specified
- * multi-byte character set used by the operating system
- * widgets.
- *
- * @param ch the WCS character
- * @param codePage the code page used to convert the character
- * @return the MBCS character
- */
-static int wcsToMbcs (char ch, int codePage) {
- if (OS.IsUnicode) return ch;
- if (ch <= 0x7F) return ch;
- TCHAR buffer = new TCHAR (codePage, ch, false);
- return buffer.tcharAt (0);
-}
-
-/*
- * Returns a single character, converted from the wide
- * character set (WCS) used by Java to the default
- * multi-byte character set used by the operating system
- * widgets.
- *
- * @param ch the WCS character
- * @return the MBCS character
- */
-static int wcsToMbcs (char ch) {
- return wcsToMbcs (ch, 0);
-}
-
-int /*long*/ windowProc (int /*long*/ hwnd, int /*long*/ msg, int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. On Vista only, it is faster to
- * compute and answer the data for the visible columns
- * of a table when scrolling, rather than just return
- * the data for each column when asked.
- */
- if (columnVisible != null) {
- if (msg == OS.WM_NOTIFY && hwndParent == hwnd) {
- OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
- switch (hdr.code) {
- case OS.LVN_GETDISPINFOA:
- case OS.LVN_GETDISPINFOW: {
- OS.MoveMemory (plvfi, lParam, NMLVDISPINFO.sizeof);
- if (0 <= plvfi.iSubItem && plvfi.iSubItem < columnCount) {
- if (!columnVisible [plvfi.iSubItem]) return 0;
- }
- break;
- }
- }
- }
- }
- /*
- * Bug in Adobe Reader 7.0. For some reason, when Adobe
- * Reader 7.0 is deactivated from within Internet Explorer,
- * it sends thousands of consecutive WM_NCHITTEST messages
- * to the control that is under the cursor. It seems that
- * if the control takes some time to respond to the message,
- * Adobe stops sending them. The fix is to detect this case
- * and sleep.
- *
- * NOTE: Under normal circumstances, Windows will never send
- * consecutive WM_NCHITTEST messages to the same control without
- * another message (normally WM_SETCURSOR) in between.
- */
- if ((int)/*64*/msg == OS.WM_NCHITTEST) {
- if (hitCount++ >= 1024) {
- try {Thread.sleep (1);} catch (Throwable t) {}
- }
- } else {
- hitCount = 0;
- }
- if (lastControl != null && lastHwnd == hwnd) {
- return lastControl.windowProc (hwnd, (int)/*64*/msg, wParam, lParam);
- }
- int index;
- if (USE_PROPERTY) {
- index = (int)/*64*/OS.GetProp (hwnd, SWT_OBJECT_INDEX) - 1;
- } else {
- index = (int)/*64*/OS.GetWindowLongPtr (hwnd, OS.GWLP_USERDATA) - 1;
- }
- if (0 <= index && index < controlTable.length) {
- Control control = controlTable [index];
- if (control != null) {
- lastHwnd = hwnd;
- lastControl = control;
- return control.windowProc (hwnd, (int)/*64*/msg, wParam, lParam);
- }
- }
- return OS.DefWindowProc (hwnd, (int)/*64*/msg, wParam, lParam);
-}
-
-static String withCrLf (String string) {
-
- /* If the string is empty, return the string. */
- int length = string.length ();
- if (length == 0) return string;
-
- /*
- * Check for an LF or CR/LF and assume the rest of
- * the string is formated that way. This will not
- * work if the string contains mixed delimiters.
- */
- int i = string.indexOf ('\n', 0);
- if (i == -1) return string;
- if (i > 0 && string.charAt (i - 1) == '\r') {
- return string;
- }
-
- /*
- * The string is formatted with LF. Compute the
- * number of lines and the size of the buffer
- * needed to hold the result
- */
- i++;
- int count = 1;
- while (i < length) {
- if ((i = string.indexOf ('\n', i)) == -1) break;
- count++; i++;
- }
- count += length;
-
- /* Create a new string with the CR/LF line terminator. */
- i = 0;
- StringBuffer result = new StringBuffer (count);
- while (i < length) {
- int j = string.indexOf ('\n', i);
- if (j == -1) j = length;
- result.append (string.substring (i, j));
- if ((i = j) < length) {
- result.append ("\r\n"); //$NON-NLS-1$
- i++;
- }
- }
- return result.toString ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandBar.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandBar.java
deleted file mode 100644
index ca9c0bb0be..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandBar.java
+++ /dev/null
@@ -1,824 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class support the layout of selectable
- * expand bar items.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>ExpandItem</code>.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>V_SCROLL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Expand, Collapse</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see ExpandItem
- * @see ExpandEvent
- * @see ExpandListener
- * @see ExpandAdapter
- * @see <a href="http://www.eclipse.org/swt/snippets/#expandbar">ExpandBar snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.2
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ExpandBar extends Composite {
- ExpandItem[] items;
- int itemCount;
- ExpandItem focusItem;
- int spacing = 4;
- int yCurrentScroll;
- int /*long*/ hFont;
-
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#V_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ExpandBar (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an item in the receiver is expanded or collapsed
- * by sending it one of the messages defined in the <code>ExpandListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ExpandListener
- * @see #removeExpandListener
- */
-public void addExpandListener (ExpandListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Expand, typedListener);
- addListener (SWT.Collapse, typedListener);
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- return OS.DefWindowProc (hwnd, msg, wParam, lParam);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-static int checkStyle (int style) {
- style &= ~SWT.H_SCROLL;
- return style | SWT.NO_BACKGROUND;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int height = 0, width = 0;
- if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
- if (itemCount > 0) {
- int /*long*/ hDC = OS.GetDC (handle);
- int /*long*/ hTheme = 0;
- if (isAppThemed ()) {
- hTheme = display.hExplorerBarTheme ();
- }
- int /*long*/ hCurrentFont = 0, oldFont = 0;
- if (hTheme == 0) {
- if (hFont != 0) {
- hCurrentFont = hFont;
- } else {
- if (!OS.IsWinCE) {
- NONCLIENTMETRICS info = OS.IsUnicode ? (NONCLIENTMETRICS) new NONCLIENTMETRICSW () : new NONCLIENTMETRICSA ();
- info.cbSize = NONCLIENTMETRICS.sizeof;
- if (OS.SystemParametersInfo (OS.SPI_GETNONCLIENTMETRICS, 0, info, 0)) {
- LOGFONT logFont = OS.IsUnicode ? (LOGFONT) ((NONCLIENTMETRICSW)info).lfCaptionFont : ((NONCLIENTMETRICSA)info).lfCaptionFont;
- hCurrentFont = OS.CreateFontIndirect (logFont);
- }
- }
- }
- if (hCurrentFont != 0) {
- oldFont = OS.SelectObject (hDC, hCurrentFont);
- }
- }
- height += spacing;
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- height += item.getHeaderHeight ();
- if (item.expanded) height += item.height;
- height += spacing;
- width = Math.max (width, item.getPreferredWidth (hTheme, hDC));
- }
- if (hCurrentFont != 0) {
- OS.SelectObject (hDC, oldFont);
- if (hCurrentFont != hFont) OS.DeleteObject (hCurrentFont);
- }
- OS.ReleaseDC (handle, hDC);
- }
- }
- if (width == 0) width = DEFAULT_WIDTH;
- if (height == 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- Rectangle trim = computeTrim (0, 0, width, height);
- return new Point (trim.width, trim.height);
-}
-
-void createHandle () {
- super.createHandle ();
- state &= ~CANVAS;
- state |= TRACK_MOUSE;
-}
-
-void createItem (ExpandItem item, int style, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (itemCount == items.length) {
- ExpandItem [] newItems = new ExpandItem [itemCount + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- System.arraycopy (items, index, items, index + 1, itemCount - index);
- items [index] = item;
- itemCount++;
- if (focusItem == null) focusItem = item;
-
- RECT rect = new RECT ();
- OS.GetWindowRect (handle, rect);
- item.width = Math.max (0, rect.right - rect.left - spacing * 2);
- layoutItems (index, true);
-}
-
-void createWidget () {
- super.createWidget ();
- items = new ExpandItem [4];
- if (!isAppThemed ()) {
- backgroundMode = SWT.INHERIT_DEFAULT;
- }
-}
-
-int defaultBackground() {
- if (!isAppThemed ()) {
- return OS.GetSysColor (OS.COLOR_WINDOW);
- }
- return super.defaultBackground();
-}
-
-void destroyItem (ExpandItem item) {
- int index = 0;
- while (index < itemCount) {
- if (items [index] == item) break;
- index++;
- }
- if (index == itemCount) return;
- if (item == focusItem) {
- int focusIndex = index > 0 ? index - 1 : 1;
- if (focusIndex < itemCount) {
- focusItem = items [focusIndex];
- focusItem.redraw (true);
- } else {
- focusItem = null;
- }
- }
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- item.redraw (true);
- layoutItems (index, true);
-}
-
-void drawThemeBackground (int /*long*/ hDC, int /*long*/ hwnd, RECT rect) {
- RECT rect2 = new RECT ();
- OS.GetClientRect (handle, rect2);
- OS.MapWindowPoints (handle, hwnd, rect2, 2);
- OS.DrawThemeBackground (display.hExplorerBarTheme (), hDC, OS.EBP_NORMALGROUPBACKGROUND, 0, rect2, null);
-}
-
-void drawWidget (GC gc, RECT clipRect) {
- int /*long*/ hTheme = 0;
- if (isAppThemed ()) {
- hTheme = display.hExplorerBarTheme ();
- }
- if (hTheme != 0) {
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- OS.DrawThemeBackground (hTheme, gc.handle, OS.EBP_HEADERBACKGROUND, 0, rect, clipRect);
- } else {
- drawBackground (gc.handle);
- }
- boolean drawFocus = false;
- if (handle == OS.GetFocus ()) {
- int uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- drawFocus = (uiState & OS.UISF_HIDEFOCUS) == 0;
- }
- int /*long*/ hCurrentFont = 0, oldFont = 0;
- if (hTheme == 0) {
- if (hFont != 0) {
- hCurrentFont = hFont;
- } else {
- if (!OS.IsWinCE) {
- NONCLIENTMETRICS info = OS.IsUnicode ? (NONCLIENTMETRICS) new NONCLIENTMETRICSW () : new NONCLIENTMETRICSA ();
- info.cbSize = NONCLIENTMETRICS.sizeof;
- if (OS.SystemParametersInfo (OS.SPI_GETNONCLIENTMETRICS, 0, info, 0)) {
- LOGFONT logFont = OS.IsUnicode ? (LOGFONT) ((NONCLIENTMETRICSW)info).lfCaptionFont : ((NONCLIENTMETRICSA)info).lfCaptionFont;
- hCurrentFont = OS.CreateFontIndirect (logFont);
- }
- }
- }
- if (hCurrentFont != 0) {
- oldFont = OS.SelectObject (gc.handle, hCurrentFont);
- }
- if (foreground != -1) {
- OS.SetTextColor (gc.handle, foreground);
- }
- }
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items[i];
- item.drawItem (gc, hTheme, clipRect, item == focusItem && drawFocus);
- }
- if (hCurrentFont != 0) {
- OS.SelectObject (gc.handle, oldFont);
- if (hCurrentFont != hFont) OS.DeleteObject (hCurrentFont);
- }
-}
-
-Control findBackgroundControl () {
- Control control = super.findBackgroundControl ();
- if (!isAppThemed ()) {
- if (control == null) control = this;
- }
- return control;
-}
-
-Control findThemeControl () {
- return isAppThemed () ? this : super.findThemeControl ();
-}
-
-int getBandHeight () {
- if (hFont == 0) return ExpandItem.CHEVRON_SIZE;
- int /*long*/ hDC = OS.GetDC (handle);
- int /*long*/ oldHFont = OS.SelectObject (hDC, hFont);
- TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA();
- OS.GetTextMetrics (hDC, lptm);
- OS.SelectObject (hDC, oldHFont);
- OS.ReleaseDC (handle, hDC);
- return Math.max (ExpandItem.CHEVRON_SIZE, lptm.tmHeight + 4);
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ExpandItem getItem (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return itemCount;
-}
-
-/**
- * Returns an array of <code>ExpandItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ExpandItem [] getItems () {
- checkWidget ();
- ExpandItem [] result = new ExpandItem [itemCount];
- System.arraycopy (items, 0, result, 0, itemCount);
- return result;
-}
-
-/**
- * Returns the receiver's spacing.
- *
- * @return the spacing
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSpacing () {
- checkWidget ();
- return spacing;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (ExpandItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i = 0; i < itemCount; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-
-boolean isAppThemed () {
- if (background != -1) return false;
- if (foreground != -1) return false;
- if (hFont != 0) return false;
- return OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ();
-}
-
-void layoutItems (int index, boolean setScrollbar) {
- if (index < itemCount) {
- int y = spacing - yCurrentScroll;
- for (int i = 0; i < index; i++) {
- ExpandItem item = items [i];
- if (item.expanded) y += item.height;
- y += item.getHeaderHeight () + spacing;
- }
- for (int i = index; i < itemCount; i++) {
- ExpandItem item = items [i];
- item.setBounds (spacing, y, 0, 0, true, false);
- if (item.expanded) y += item.height;
- y += item.getHeaderHeight () + spacing;
- }
- }
- if (setScrollbar) setScrollbar ();
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<items.length; i++) {
- ExpandItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- }
- focusItem = null;
- super.releaseChildren (destroy);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when items in the receiver are expanded or collapsed.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ExpandListener
- * @see #addExpandListener
- */
-public void removeExpandListener (ExpandListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Expand, listener);
- eventTable.unhook (SWT.Collapse, listener);
-}
-
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- if (!OS.IsWinCE) {
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, null, 0, flags);
- }
-}
-
-public void setFont (Font font) {
- super.setFont (font);
- hFont = font != null ? font.handle : 0;
- layoutItems (0, true);
-}
-
-void setForegroundPixel (int pixel) {
- super.setForegroundPixel (pixel);
- if (!OS.IsWinCE) {
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, null, 0, flags);
- }
-}
-
-void setScrollbar () {
- if (itemCount == 0) return;
- if ((style & SWT.V_SCROLL) == 0) return;
- RECT rect = new RECT();
- OS.GetClientRect (handle, rect);
- int height = rect.bottom - rect.top;
- ExpandItem item = items [itemCount - 1];
- int maxHeight = item.y + getBandHeight () + spacing;
- if (item.expanded) maxHeight += item.height;
-
- //claim bottom free space
- if (yCurrentScroll > 0 && height > maxHeight) {
- yCurrentScroll = Math.max (0, yCurrentScroll + maxHeight - height);
- layoutItems (0, false);
- }
- maxHeight += yCurrentScroll;
-
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_RANGE | OS.SIF_PAGE | OS.SIF_POS;
- info.nMin = 0;
- info.nMax = maxHeight;
- info.nPage = height;
- info.nPos = Math.min (yCurrentScroll, info.nMax);
- if (info.nPage != 0) info.nPage++;
- OS.SetScrollInfo (handle, OS.SB_VERT, info, true);
-}
-
-/**
- * Sets the receiver's spacing. Spacing specifies the number of pixels allocated around
- * each item.
- *
- * @param spacing the spacing around each item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSpacing (int spacing) {
- checkWidget ();
- if (spacing < 0) return;
- if (spacing == this.spacing) return;
- this.spacing = spacing;
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- int width = Math.max (0, (rect.right - rect.left) - spacing * 2);
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items[i];
- if (item.width != width) item.setBounds (0, 0, width, item.height, false, true);
- }
- layoutItems (0, true);
- OS.InvalidateRect (handle, null, true);
-}
-
-void showItem (ExpandItem item) {
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setVisible (item.expanded);
- }
- item.redraw (true);
- int index = indexOf (item);
- layoutItems (index + 1, true);
-}
-
-void showFocus (boolean up) {
- RECT rect = new RECT();
- OS.GetClientRect (handle, rect);
- int height = rect.bottom - rect.top;
- int updateY = 0;
- if (up) {
- if (focusItem.y < 0) {
- updateY = Math.min (yCurrentScroll, -focusItem.y);
- }
- } else {
- int itemHeight = focusItem.y + getBandHeight ();
- if (focusItem.expanded) {
- if (height >= getBandHeight () + focusItem.height) {
- itemHeight += focusItem.height;
- }
- }
- if (itemHeight > height) {
- updateY = height - itemHeight;
- }
- }
- if (updateY != 0) {
- yCurrentScroll = Math.max (0, yCurrentScroll - updateY);
- if ((style & SWT.V_SCROLL) != 0) {
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_POS;
- info.nPos = yCurrentScroll;
- OS.SetScrollInfo (handle, OS.SB_VERT, info, true);
- }
- OS.ScrollWindowEx (handle, 0, updateY, null, null, 0, null, OS.SW_SCROLLCHILDREN | OS.SW_INVALIDATE);
- for (int i = 0; i < itemCount; i++) {
- items [i].y += updateY;
- }
- }
-}
-
-TCHAR windowClass () {
- return display.windowClass;
-}
-
-int /*long*/ windowProc () {
- return display.windowProc;
-}
-
-LRESULT WM_KEYDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_KEYDOWN (wParam, lParam);
- if (result != null) return result;
- if (focusItem == null) return result;
- switch ((int)/*64*/wParam) {
- case OS.VK_SPACE:
- case OS.VK_RETURN:
- Event event = new Event ();
- event.item = focusItem;
- sendEvent (focusItem.expanded ? SWT.Collapse : SWT.Expand, event);
- focusItem.expanded = !focusItem.expanded;
- showItem (focusItem);
- return LRESULT.ZERO;
- case OS.VK_UP: {
- int focusIndex = indexOf (focusItem);
- if (focusIndex > 0) {
- focusItem.redraw (true);
- focusItem = items [focusIndex - 1];
- focusItem.redraw (true);
- showFocus (true);
- return LRESULT.ZERO;
- }
- break;
- }
- case OS.VK_DOWN: {
- int focusIndex = indexOf (focusItem);
- if (focusIndex < itemCount - 1) {
- focusItem.redraw (true);
- focusItem = items [focusIndex + 1];
- focusItem.redraw (true);
- showFocus (false);
- return LRESULT.ZERO;
- }
- break;
- }
- }
- return result;
-}
-
-LRESULT WM_KILLFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_KILLFOCUS (wParam, lParam);
- if (focusItem != null) focusItem.redraw (true);
- return result;
-}
-
-LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_LBUTTONDOWN (wParam, lParam);
- if (result == LRESULT.ZERO) return result;
- int x = OS.GET_X_LPARAM (lParam);
- int y = OS.GET_Y_LPARAM (lParam);
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items[i];
- boolean hover = item.isHover (x, y);
- if (hover && focusItem != item) {
- focusItem.redraw (true);
- focusItem = item;
- focusItem.redraw (true);
- forceFocus ();
- break;
- }
- }
- return result;
-}
-
-LRESULT WM_LBUTTONUP (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_LBUTTONUP (wParam, lParam);
- if (result == LRESULT.ZERO) return result;
- if (focusItem == null) return result;
- int x = OS.GET_X_LPARAM (lParam);
- int y = OS.GET_Y_LPARAM (lParam);
- boolean hover = focusItem.isHover (x, y);
- if (hover) {
- Event event = new Event ();
- event.item = focusItem;
- sendEvent (focusItem.expanded ? SWT.Collapse : SWT.Expand, event);
- focusItem.expanded = !focusItem.expanded;
- showItem (focusItem);
- }
- return result;
-}
-
-LRESULT WM_MOUSELEAVE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_MOUSELEAVE (wParam, lParam);
- if (result != null) return result;
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- if (item.hover) {
- item.hover = false;
- item.redraw (false);
- break;
- }
- }
- return result;
-}
-
-LRESULT WM_MOUSEMOVE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_MOUSEMOVE (wParam, lParam);
- if (result == LRESULT.ZERO) return result;
- int x = OS.GET_X_LPARAM (lParam);
- int y = OS.GET_Y_LPARAM (lParam);
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- boolean hover = item.isHover (x, y);
- if (item.hover != hover) {
- item.hover = hover;
- item.redraw (false);
- }
- }
- return result;
-}
-
-LRESULT WM_MOUSEWHEEL (int /*long*/ wParam, int /*long*/ lParam) {
- return wmScrollWheel (true, wParam, lParam);
-}
-
-LRESULT WM_PAINT (int /*long*/ wParam, int /*long*/ lParam) {
- PAINTSTRUCT ps = new PAINTSTRUCT ();
- GCData data = new GCData ();
- data.ps = ps;
- data.hwnd = handle;
- GC gc = new_GC (data);
- if (gc != null) {
- int width = ps.right - ps.left;
- int height = ps.bottom - ps.top;
- if (width != 0 && height != 0) {
- RECT rect = new RECT ();
- OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
- drawWidget (gc, rect);
- if (hooks (SWT.Paint) || filters (SWT.Paint)) {
- Event event = new Event ();
- event.gc = gc;
- event.x = rect.left;
- event.y = rect.top;
- event.width = width;
- event.height = height;
- sendEvent (SWT.Paint, event);
- event.gc = null;
- }
- }
- gc.dispose ();
- }
- return LRESULT.ZERO;
-}
-
-LRESULT WM_PRINTCLIENT (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_PRINTCLIENT (wParam, lParam);
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- GCData data = new GCData ();
- data.device = display;
- data.foreground = getForegroundPixel ();
- GC gc = GC.win32_new (wParam, data);
- drawWidget (gc, rect);
- gc.dispose ();
- return result;
-}
-
-LRESULT WM_SETCURSOR (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SETCURSOR (wParam, lParam);
- if (result != null) return result;
- int hitTest = (short) OS.LOWORD (lParam);
- if (hitTest == OS.HTCLIENT) {
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- if (item.hover) {
- int /*long*/ hCursor = OS.LoadCursor (0, OS.IDC_HAND);
- OS.SetCursor (hCursor);
- return LRESULT.ONE;
- }
- }
- }
- return result;
-}
-
-LRESULT WM_SETFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SETFOCUS (wParam, lParam);
- if (focusItem != null) focusItem.redraw (true);
- return result;
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SIZE (wParam, lParam);
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- int width = Math.max (0, (rect.right - rect.left) - spacing * 2);
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items[i];
- if (item.width != width) item.setBounds (0, 0, width, item.height, false, true);
- }
- setScrollbar ();
- OS.InvalidateRect (handle, null, true);
- return result;
-}
-
-LRESULT wmScroll (ScrollBar bar, boolean update, int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.wmScroll (bar, true, hwnd, msg, wParam, lParam);
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_POS;
- OS.GetScrollInfo (handle, OS.SB_VERT, info);
- int updateY = yCurrentScroll - info.nPos;
- OS.ScrollWindowEx (handle, 0, updateY, null, null, 0, null, OS.SW_SCROLLCHILDREN | OS.SW_INVALIDATE);
- yCurrentScroll = info.nPos;
- if (updateY != 0) {
- for (int i = 0; i < itemCount; i++) {
- items [i].y += updateY;
- }
- }
- return result;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandItem.java
deleted file mode 100644
index 51ba1ea3f9..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandItem.java
+++ /dev/null
@@ -1,489 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a expandable item in a expand bar.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see ExpandBar
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.2
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ExpandItem extends Item {
- ExpandBar parent;
- Control control;
- boolean expanded, hover;
- int x, y, width, height;
- int imageHeight, imageWidth;
- static final int TEXT_INSET = 6;
- static final int BORDER = 1;
- static final int CHEVRON_SIZE = 24;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ExpandItem (ExpandBar parent, int style) {
- this (parent, style, checkNull (parent).getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent, a
- * style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ExpandItem (ExpandBar parent, int style, int index) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, style, index);
-}
-
-static ExpandBar checkNull (ExpandBar control) {
- if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return control;
-}
-
-private void drawChevron (int /*long*/ hDC, RECT rect) {
- int /*long*/ oldBrush = OS.SelectObject (hDC, OS.GetSysColorBrush (OS.COLOR_BTNFACE));
- OS.PatBlt (hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, OS.PATCOPY);
- OS.SelectObject (hDC, oldBrush);
- rect.left += 4;
- rect.top += 4;
- rect.right -= 4;
- rect.bottom -= 4;
- int /*long*/ hPen = OS.CreatePen (OS.PS_SOLID, 1, parent.getForegroundPixel ());
- int /*long*/ oldPen = OS.SelectObject (hDC, hPen);
- int [] polyline1, polyline2;
- if (expanded) {
- int px = rect.left + 5;
- int py = rect.top + 7;
- polyline1 = new int [] {
- px,py, px+1,py, px+1,py-1, px+2,py-1, px+2,py-2, px+3,py-2, px+3,py-3,
- px+3,py-2, px+4,py-2, px+4,py-1, px+5,py-1, px+5,py, px+7,py};
- py += 4;
- polyline2 = new int [] {
- px,py, px+1,py, px+1,py-1, px+2,py-1, px+2,py-2, px+3,py-2, px+3,py-3,
- px+3,py-2, px+4,py-2, px+4,py-1, px+5,py-1, px+5,py, px+7,py};
- } else {
- int px = rect.left + 5;
- int py = rect.top + 4;
- polyline1 = new int[] {
- px,py, px+1,py, px+1,py+1, px+2,py+1, px+2,py+2, px+3,py+2, px+3,py+3,
- px+3,py+2, px+4,py+2, px+4,py+1, px+5,py+1, px+5,py, px+7,py};
- py += 4;
- polyline2 = new int [] {
- px,py, px+1,py, px+1,py+1, px+2,py+1, px+2,py+2, px+3,py+2, px+3,py+3,
- px+3,py+2, px+4,py+2, px+4,py+1, px+5,py+1, px+5,py, px+7,py};
- }
- OS.Polyline (hDC, polyline1, polyline1.length / 2);
- OS.Polyline (hDC, polyline2, polyline2.length / 2);
- if (hover) {
- int /*long*/ whitePen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_3DHILIGHT));
- int /*long*/ darkGrayPen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_3DSHADOW));
- OS.SelectObject (hDC, whitePen);
- int [] points1 = {
- rect.left, rect.bottom,
- rect.left, rect.top,
- rect.right, rect.top};
- OS.Polyline (hDC, points1, points1.length / 2);
- OS.SelectObject (hDC, darkGrayPen);
- int [] points2 = {
- rect.right, rect.top,
- rect.right, rect.bottom,
- rect.left, rect.bottom};
- OS.Polyline (hDC, points2, points2.length / 2);
- OS.SelectObject (hDC, oldPen);
- OS.DeleteObject (whitePen);
- OS.DeleteObject (darkGrayPen);
- } else {
- OS.SelectObject (hDC, oldPen);
- }
- OS.DeleteObject (hPen);
-}
-
-void drawItem (GC gc, int /*long*/ hTheme, RECT clipRect, boolean drawFocus) {
- int /*long*/ hDC = gc.handle;
- int headerHeight = parent.getBandHeight ();
- RECT rect = new RECT ();
- OS.SetRect (rect, x, y, x + width, y + headerHeight);
- if (hTheme != 0) {
- OS.DrawThemeBackground (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, rect, clipRect);
- } else {
- int /*long*/ oldBrush = OS.SelectObject (hDC, OS.GetSysColorBrush (OS.COLOR_BTNFACE));
- OS.PatBlt (hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, OS.PATCOPY);
- OS.SelectObject (hDC, oldBrush);
- }
- if (image != null) {
- rect.left += ExpandItem.TEXT_INSET;
- if (imageHeight > headerHeight) {
- gc.drawImage (image, rect.left, rect.top + headerHeight - imageHeight);
- } else {
- gc.drawImage (image, rect.left, rect.top + (headerHeight - imageHeight) / 2);
- }
- rect.left += imageWidth;
- }
- if (text.length () > 0) {
- rect.left += ExpandItem.TEXT_INSET;
- TCHAR buffer = new TCHAR (parent.getCodePage (), text, false);
- if (hTheme != 0) {
- OS.DrawThemeText (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, buffer.chars, buffer.length(), OS.DT_VCENTER | OS.DT_SINGLELINE, 0, rect);
- } else {
- int oldBkMode = OS.SetBkMode (hDC, OS.TRANSPARENT);
- OS.DrawText (hDC, buffer, buffer.length (), rect, OS.DT_VCENTER | OS.DT_SINGLELINE);
- OS.SetBkMode (hDC, oldBkMode);
- }
- }
- int chevronSize = ExpandItem.CHEVRON_SIZE;
- rect.left = rect.right - chevronSize;
- rect.top = y + (headerHeight - chevronSize) / 2;
- rect.bottom = rect.top + chevronSize;
- if (hTheme != 0) {
- int partID = expanded ? OS.EBP_NORMALGROUPCOLLAPSE : OS.EBP_NORMALGROUPEXPAND;
- int stateID = hover ? OS.EBNGC_HOT : OS.EBNGC_NORMAL;
- OS.DrawThemeBackground (hTheme, hDC, partID, stateID, rect, clipRect);
- } else {
- drawChevron (hDC, rect);
- }
- if (drawFocus) {
- OS.SetRect (rect, x + 1, y + 1, x + width - 2, y + headerHeight - 2);
- OS.DrawFocusRect (hDC, rect);
- }
- if (expanded) {
- if (!parent.isAppThemed ()) {
- int /*long*/ pen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_BTNFACE));
- int /*long*/ oldPen = OS.SelectObject (hDC, pen);
- int [] points = {
- x, y + headerHeight,
- x, y + headerHeight + height,
- x + width - 1, y + headerHeight + height,
- x + width - 1, y + headerHeight - 1};
- OS.Polyline (hDC, points, points.length / 2);
- OS.SelectObject (hDC, oldPen);
- OS.DeleteObject (pen);
- }
- }
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns the control that is shown when the item is expanded.
- * If no control has been set, return <code>null</code>.
- *
- * @return the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget ();
- return control;
-}
-
-/**
- * Returns <code>true</code> if the receiver is expanded,
- * and false otherwise.
- *
- * @return the expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getExpanded () {
- checkWidget ();
- return expanded;
-}
-
-/**
- * Returns the height of the receiver's header
- *
- * @return the height of the header
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getHeaderHeight () {
- checkWidget ();
- return Math.max (parent.getBandHeight (), imageHeight);
-}
-
-/**
- * Gets the height of the receiver.
- *
- * @return the height
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getHeight () {
- checkWidget ();
- return height;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>ExpandBar</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ExpandBar getParent () {
- checkWidget ();
- return parent;
-}
-
-int getPreferredWidth (int /*long*/ hTheme, int /*long*/ hDC) {
- int width = ExpandItem.TEXT_INSET * 2 + ExpandItem.CHEVRON_SIZE;
- if (image != null) {
- width += ExpandItem.TEXT_INSET + imageWidth;
- }
- if (text.length() > 0) {
- RECT rect = new RECT ();
- TCHAR buffer = new TCHAR (parent.getCodePage (), text, false);
- if (hTheme != 0) {
- OS.GetThemeTextExtent (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, buffer.chars, buffer.length(), OS.DT_SINGLELINE, null, rect);
- } else {
- OS.DrawText (hDC, buffer, buffer.length (), rect, OS.DT_CALCRECT);
- }
- width += (rect.right - rect.left);
- }
- return width;
-}
-
-boolean isHover (int x, int y) {
- int bandHeight = parent.getBandHeight ();
- return this.x < x && x < (this.x + width) && this.y < y && y < (this.y + bandHeight);
-}
-
-void redraw (boolean all) {
- int /*long*/ parentHandle = parent.handle;
- int headerHeight = parent.getBandHeight ();
- RECT rect = new RECT ();
- int left = all ? x : x + width - headerHeight;
- OS.SetRect (rect, left, y, x + width, y + headerHeight);
- OS.InvalidateRect (parentHandle, rect, true);
- if (imageHeight > headerHeight) {
- OS.SetRect (rect, x + ExpandItem.TEXT_INSET, y + headerHeight - imageHeight, x + ExpandItem.TEXT_INSET + imageWidth, y);
- OS.InvalidateRect (parentHandle, rect, true);
- }
- if (!parent.isAppThemed ()) {
- OS.SetRect (rect, x, y + headerHeight, x + width, y + headerHeight + height + 1);
- OS.InvalidateRect (parentHandle, rect, true);
- }
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- control = null;
-}
-
-void setBounds (int x, int y, int width, int height, boolean move, boolean size) {
- redraw (true);
- int headerHeight = parent.getBandHeight ();
- if (move) {
- if (imageHeight > headerHeight) {
- y += (imageHeight - headerHeight);
- }
- this.x = x;
- this.y = y;
- redraw (true);
- }
- if (size) {
- this.width = width;
- this.height = height;
- redraw (true);
- }
- if (control != null && !control.isDisposed ()) {
- if (!parent.isAppThemed ()) {
- x += BORDER;
- width = Math.max (0, width - BORDER * 2);
- height = Math.max (0, height - BORDER);
- }
- if (move && size) control.setBounds (x, y + headerHeight, width, height);
- if (move && !size) control.setLocation (x, y + headerHeight);
- if (!move && size) control.setSize (width, height);
- }
-}
-
-/**
- * Sets the control that is shown when the item is expanded.
- *
- * @param control the new control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget ();
- if (control != null) {
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- this.control = control;
- if (control != null) {
- int headerHeight = parent.getBandHeight ();
- control.setVisible (expanded);
- if (!parent.isAppThemed ()) {
- int width = Math.max (0, this.width - BORDER * 2);
- int height = Math.max (0, this.height - BORDER);
- control.setBounds (x + BORDER, y + headerHeight, width, height);
- } else {
- control.setBounds (x, y + headerHeight, width, height);
- }
- }
-}
-
-/**
- * Sets the expanded state of the receiver.
- *
- * @param expanded the new expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setExpanded (boolean expanded) {
- checkWidget ();
- this.expanded = expanded;
- parent.showItem (this);
-}
-
-/**
- * Sets the height of the receiver. This is height of the item when it is expanded,
- * excluding the height of the header.
- *
- * @param height the new height
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHeight (int height) {
- checkWidget ();
- if (height < 0) return;
- setBounds (0, 0, width, height, false, true);
- if (expanded) parent.layoutItems (parent.indexOf (this) + 1, true);
-}
-
-public void setImage (Image image) {
- super.setImage (image);
- int oldImageHeight = imageHeight;
- if (image != null) {
- Rectangle bounds = image.getBounds ();
- imageHeight = bounds.height;
- imageWidth = bounds.width;
- } else {
- imageHeight = imageWidth = 0;
- }
- if (oldImageHeight != imageHeight) {
- parent.layoutItems (parent.indexOf (this), true);
- } else {
- redraw (true);
- }
-}
-
-public void setText (String string) {
- super.setText (string);
- redraw (true);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FileDialog.java
deleted file mode 100755
index c84a13a51c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FileDialog.java
+++ /dev/null
@@ -1,618 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class allow the user to navigate
- * the file system and select or enter a file name.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SAVE, OPEN, MULTI</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles SAVE and OPEN may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#filedialog">FileDialog snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class FileDialog extends Dialog {
- String [] filterNames = new String [0];
- String [] filterExtensions = new String [0];
- String [] fileNames = new String [0];
- String filterPath = "", fileName = "";
- int filterIndex = 0;
- boolean overwrite = false;
- static final String FILTER = "*.*";
- static int BUFFER_SIZE = 1024 * 32;
- static boolean USE_HOOK = true;
- static {
- /*
- * Feature in Vista. When OFN_ENABLEHOOK is set in the
- * save or open file dialog, Vista uses the old XP look
- * and feel. OFN_ENABLEHOOK is used to grow the file
- * name buffer in a multi-select file dialog. The fix
- * is to only use OFN_ENABLEHOOK when the buffer has
- * overrun.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- USE_HOOK = false;
- }
- }
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FileDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SAVE
- * @see SWT#OPEN
- * @see SWT#MULTI
- */
-public FileDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-/**
- * Returns the path of the first file that was
- * selected in the dialog relative to the filter path, or an
- * empty string if no such file has been selected.
- *
- * @return the relative path of the file
- */
-public String getFileName () {
- return fileName;
-}
-
-/**
- * Returns a (possibly empty) array with the paths of all files
- * that were selected in the dialog relative to the filter path.
- *
- * @return the relative paths of the files
- */
-public String [] getFileNames () {
- return fileNames;
-}
-
-/**
- * Returns the file extensions which the dialog will
- * use to filter the files it shows.
- *
- * @return the file extensions filter
- */
-public String [] getFilterExtensions () {
- return filterExtensions;
-}
-
-/**
- * Get the 0-based index of the file extension filter
- * which was selected by the user, or -1 if no filter
- * was selected.
- * <p>
- * This is an index into the FilterExtensions array and
- * the FilterNames array.
- * </p>
- *
- * @return index the file extension filter index
- *
- * @see #getFilterExtensions
- * @see #getFilterNames
- *
- * @since 3.4
- */
-public int getFilterIndex () {
- return filterIndex;
-}
-
-/**
- * Returns the names that describe the filter extensions
- * which the dialog will use to filter the files it shows.
- *
- * @return the list of filter names
- */
-public String [] getFilterNames () {
- return filterNames;
-}
-
-/**
- * Returns the directory path that the dialog will use, or an empty
- * string if this is not set. File names in this path will appear
- * in the dialog, filtered according to the filter extensions.
- *
- * @return the directory path string
- *
- * @see #setFilterExtensions
- */
-public String getFilterPath () {
- return filterPath;
-}
-
-/**
- * Returns the flag that the dialog will use to
- * determine whether to prompt the user for file
- * overwrite if the selected file already exists.
- *
- * @return true if the dialog will prompt for file overwrite, false otherwise
- *
- * @since 3.4
- */
-public boolean getOverwrite () {
- return overwrite;
-}
-
-int /*long*/ OFNHookProc (int /*long*/ hdlg, int /*long*/ uiMsg, int /*long*/ wParam, int /*long*/ lParam) {
- switch ((int)/*64*/uiMsg) {
- case OS.WM_NOTIFY:
- OFNOTIFY ofn = new OFNOTIFY ();
- OS.MoveMemory (ofn, lParam, OFNOTIFY.sizeof);
- if (ofn.code == OS.CDN_SELCHANGE) {
- int lResult = (int)/*64*/OS.SendMessage (ofn.hwndFrom, OS.CDM_GETSPEC, 0, 0);
- if (lResult > 0) {
- lResult += OS.MAX_PATH;
- OPENFILENAME lpofn = new OPENFILENAME ();
- OS.MoveMemory (lpofn, ofn.lpOFN, OPENFILENAME.sizeof);
- if (lpofn.nMaxFile < lResult) {
- int /*long*/ hHeap = OS.GetProcessHeap ();
- int /*long*/ lpstrFile = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, lResult * TCHAR.sizeof);
- if (lpstrFile != 0) {
- if (lpofn.lpstrFile != 0) OS.HeapFree (hHeap, 0, lpofn.lpstrFile);
- lpofn.lpstrFile = lpstrFile;
- lpofn.nMaxFile = lResult;
- OS.MoveMemory (ofn.lpOFN, lpofn, OPENFILENAME.sizeof);
- }
- }
- }
- }
- break;
- }
- return 0;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a string describing the absolute path of the first selected file,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public String open () {
- int /*long*/ hHeap = OS.GetProcessHeap ();
-
- /* Get the owner HWND for the dialog */
- int /*long*/ hwndOwner = parent.handle;
- int /*long*/ hwndParent = parent.handle;
-
- /*
- * Feature in Windows. There is no API to set the orientation of a
- * file dialog. It is always inherited from the parent. The fix is
- * to create a hidden parent and set the orientation in the hidden
- * parent for the dialog to inherit.
- */
- boolean enabled = false;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
- int dialogOrientation = style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
- int parentOrientation = parent.style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
- if (dialogOrientation != parentOrientation) {
- int exStyle = OS.WS_EX_NOINHERITLAYOUT;
- if (dialogOrientation == SWT.RIGHT_TO_LEFT) exStyle |= OS.WS_EX_LAYOUTRTL;
- hwndOwner = OS.CreateWindowEx (
- exStyle,
- Shell.DialogClass,
- null,
- 0,
- OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0,
- hwndParent,
- 0,
- OS.GetModuleHandle (null),
- null);
- enabled = OS.IsWindowEnabled (hwndParent);
- if (enabled) OS.EnableWindow (hwndParent, false);
- }
- }
-
- /* Convert the title and copy it into lpstrTitle */
- if (title == null) title = "";
- /* Use the character encoding for the default locale */
- TCHAR buffer3 = new TCHAR (0, title, true);
- int byteCount3 = buffer3.length () * TCHAR.sizeof;
- int /*long*/ lpstrTitle = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount3);
- OS.MoveMemory (lpstrTitle, buffer3, byteCount3);
-
- /* Compute filters and copy into lpstrFilter */
- String strFilter = "";
- if (filterNames == null) filterNames = new String [0];
- if (filterExtensions == null) filterExtensions = new String [0];
- for (int i=0; i<filterExtensions.length; i++) {
- String filterName = filterExtensions [i];
- if (i < filterNames.length) filterName = filterNames [i];
- strFilter = strFilter + filterName + '\0' + filterExtensions [i] + '\0';
- }
- if (filterExtensions.length == 0) {
- strFilter = strFilter + FILTER + '\0' + FILTER + '\0';
- }
- /* Use the character encoding for the default locale */
- TCHAR buffer4 = new TCHAR (0, strFilter, true);
- int byteCount4 = buffer4.length () * TCHAR.sizeof;
- int /*long*/ lpstrFilter = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount4);
- OS.MoveMemory (lpstrFilter, buffer4, byteCount4);
-
- /* Convert the fileName and filterName to C strings */
- if (fileName == null) fileName = "";
- /* Use the character encoding for the default locale */
- TCHAR name = new TCHAR (0, fileName, true);
-
- /*
- * Copy the name into lpstrFile and ensure that the
- * last byte is NULL and the buffer does not overrun.
- */
- int nMaxFile = OS.MAX_PATH;
- if ((style & SWT.MULTI) != 0) nMaxFile = Math.max (nMaxFile, BUFFER_SIZE);
- int byteCount = nMaxFile * TCHAR.sizeof;
- int /*long*/ lpstrFile = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- int byteCountFile = Math.min (name.length () * TCHAR.sizeof, byteCount - TCHAR.sizeof);
- OS.MoveMemory (lpstrFile, name, byteCountFile);
-
- /*
- * Copy the path into lpstrInitialDir and ensure that
- * the last byte is NULL and the buffer does not overrun.
- */
- if (filterPath == null) filterPath = "";
- /* Use the character encoding for the default locale */
- TCHAR path = new TCHAR (0, filterPath.replace ('/', '\\'), true);
- int byteCount5 = OS.MAX_PATH * TCHAR.sizeof;
- int /*long*/ lpstrInitialDir = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount5);
- int byteCountDir = Math.min (path.length () * TCHAR.sizeof, byteCount5 - TCHAR.sizeof);
- OS.MoveMemory (lpstrInitialDir, path, byteCountDir);
-
- /* Create the file dialog struct */
- OPENFILENAME struct = new OPENFILENAME ();
- struct.lStructSize = OPENFILENAME.sizeof;
- struct.Flags = OS.OFN_HIDEREADONLY | OS.OFN_NOCHANGEDIR;
- boolean save = (style & SWT.SAVE) != 0;
- if (save && overwrite) struct.Flags |= OS.OFN_OVERWRITEPROMPT;
- Callback callback = null;
- if ((style & SWT.MULTI) != 0) {
- struct.Flags |= OS.OFN_ALLOWMULTISELECT | OS.OFN_EXPLORER | OS.OFN_ENABLESIZING;
- if (!OS.IsWinCE && USE_HOOK) {
- callback = new Callback (this, "OFNHookProc", 4); //$NON-NLS-1$
- int /*long*/ lpfnHook = callback.getAddress ();
- if (lpfnHook == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- struct.lpfnHook = lpfnHook;
- struct.Flags |= OS.OFN_ENABLEHOOK;
- }
- }
- struct.hwndOwner = hwndOwner;
- struct.lpstrTitle = lpstrTitle;
- struct.lpstrFile = lpstrFile;
- struct.nMaxFile = nMaxFile;
- struct.lpstrInitialDir = lpstrInitialDir;
- struct.lpstrFilter = lpstrFilter;
- struct.nFilterIndex = filterIndex == 0 ? filterIndex : filterIndex + 1;
-
- /*
- * Set the default extension to an empty string. If the
- * user fails to type an extension and this extension is
- * empty, Windows uses the current value of the filter
- * extension at the time that the dialog is closed.
- */
- int /*long*/ lpstrDefExt = 0;
- if (save) {
- lpstrDefExt = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof);
- struct.lpstrDefExt = lpstrDefExt;
- }
-
- /* Make the parent shell be temporary modal */
- Dialog oldModal = null;
- Display display = parent.getDisplay ();
- if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- oldModal = display.getModalDialog ();
- display.setModalDialog (this);
- }
-
- /*
- * Feature in Windows. For some reason, the WH_MSGFILTER filter
- * does not run for GetSaveFileName() or GetOpenFileName(). The
- * fix is to allow async messages to run in the WH_FOREGROUNDIDLE
- * hook instead.
- *
- * Bug in Windows 98. For some reason, when certain operating
- * system calls such as Shell_NotifyIcon(), GetOpenFileName()
- * and GetSaveFileName() are made during the WH_FOREGROUNDIDLE
- * hook, Windows hangs. The fix is to disallow async messages
- * during WH_FOREGROUNDIDLE.
- */
- boolean oldRunMessagesInIdle = display.runMessagesInIdle;
- display.runMessagesInIdle = !OS.IsWin95;
- /*
- * Open the dialog. If the open fails due to an invalid
- * file name, use an empty file name and open it again.
- */
- boolean success = (save) ? OS.GetSaveFileName (struct) : OS.GetOpenFileName (struct);
- switch (OS.CommDlgExtendedError ()) {
- case OS.FNERR_INVALIDFILENAME:
- OS.MoveMemory (lpstrFile, new TCHAR (0, "", true), TCHAR.sizeof);
- success = (save) ? OS.GetSaveFileName (struct) : OS.GetOpenFileName (struct);
- break;
- case OS.FNERR_BUFFERTOOSMALL:
- USE_HOOK = true;
- break;
- }
- display.runMessagesInIdle = oldRunMessagesInIdle;
-
- /* Clear the temporary dialog modal parent */
- if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- display.setModalDialog (oldModal);
- }
-
- /* Dispose the callback and reassign the buffer */
- if (callback != null) callback.dispose ();
- lpstrFile = struct.lpstrFile;
-
- /* Set the new path, file name and filter */
- fileNames = new String [0];
- String fullPath = null;
- if (success) {
-
- /* Use the character encoding for the default locale */
- TCHAR buffer = new TCHAR (0, struct.nMaxFile);
- int byteCount1 = buffer.length () * TCHAR.sizeof;
- OS.MoveMemory (buffer, lpstrFile, byteCount1);
-
- /*
- * Bug in WinCE. For some reason, nFileOffset and nFileExtension
- * are always zero on WinCE HPC. nFileOffset is always zero on
- * WinCE PPC when using GetSaveFileName(). nFileOffset is correctly
- * set on WinCE PPC when using OpenFileName(). The fix is to parse
- * lpstrFile to calculate nFileOffset.
- *
- * Note: WinCE does not support multi-select file dialogs.
- */
- int nFileOffset = struct.nFileOffset;
- if (OS.IsWinCE && nFileOffset == 0) {
- int index = 0;
- while (index < buffer.length ()) {
- int ch = buffer.tcharAt (index);
- if (ch == 0) break;
- if (ch == '\\') nFileOffset = index + 1;
- index++;
- }
- }
- if (nFileOffset > 0) {
-
- /* Use the character encoding for the default locale */
- TCHAR prefix = new TCHAR (0, nFileOffset - 1);
- int byteCount2 = prefix.length () * TCHAR.sizeof;
- OS.MoveMemory (prefix, lpstrFile, byteCount2);
- filterPath = prefix.toString (0, prefix.length ());
-
- /*
- * Get each file from the buffer. Files are delimited
- * by a NULL character with 2 NULL characters at the end.
- */
- int count = 0;
- fileNames = new String [(style & SWT.MULTI) != 0 ? 4 : 1];
- int start = nFileOffset;
- do {
- int end = start;
- while (end < buffer.length () && buffer.tcharAt (end) != 0) end++;
- String string = buffer.toString (start, end - start);
- start = end;
- if (count == fileNames.length) {
- String [] newFileNames = new String [fileNames.length + 4];
- System.arraycopy (fileNames, 0, newFileNames, 0, fileNames.length);
- fileNames = newFileNames;
- }
- fileNames [count++] = string;
- if ((style & SWT.MULTI) == 0) break;
- start++;
- } while (start < buffer.length () && buffer.tcharAt (start) != 0);
-
- if (fileNames.length > 0) fileName = fileNames [0];
- String separator = "";
- int length = filterPath.length ();
- if (length > 0 && filterPath.charAt (length - 1) != '\\') {
- separator = "\\";
- }
- fullPath = filterPath + separator + fileName;
- if (count < fileNames.length) {
- String [] newFileNames = new String [count];
- System.arraycopy (fileNames, 0, newFileNames, 0, count);
- fileNames = newFileNames;
- }
- }
- filterIndex = struct.nFilterIndex - 1;
- }
-
- /* Free the memory that was allocated. */
- OS.HeapFree (hHeap, 0, lpstrFile);
- OS.HeapFree (hHeap, 0, lpstrFilter);
- OS.HeapFree (hHeap, 0, lpstrInitialDir);
- OS.HeapFree (hHeap, 0, lpstrTitle);
- if (lpstrDefExt != 0) OS.HeapFree (hHeap, 0, lpstrDefExt);
-
- /* Destroy the BIDI orientation window */
- if (hwndParent != hwndOwner) {
- if (enabled) OS.EnableWindow (hwndParent, true);
- OS.SetActiveWindow (hwndParent);
- OS.DestroyWindow (hwndOwner);
- }
-
- /*
- * This code is intentionally commented. On some
- * platforms, the owner window is repainted right
- * away when a dialog window exits. This behavior
- * is currently unspecified.
- */
-// if (hwndOwner != 0) OS.UpdateWindow (hwndOwner);
-
- /* Answer the full path or null */
- return fullPath;
-}
-
-/**
- * Set the initial filename which the dialog will
- * select by default when opened to the argument,
- * which may be null. The name will be prefixed with
- * the filter path when one is supplied.
- *
- * @param string the file name
- */
-public void setFileName (String string) {
- fileName = string;
-}
-
-/**
- * Set the file extensions which the dialog will
- * use to filter the files it shows to the argument,
- * which may be null.
- * <p>
- * The strings are platform specific. For example, on
- * some platforms, an extension filter string is typically
- * of the form "*.extension", where "*.*" matches all files.
- * For filters with multiple extensions, use semicolon as
- * a separator, e.g. "*.jpg;*.png".
- * </p>
- *
- * @param extensions the file extension filter
- *
- * @see #setFilterNames to specify the user-friendly
- * names corresponding to the extensions
- */
-public void setFilterExtensions (String [] extensions) {
- filterExtensions = extensions;
-}
-
-/**
- * Set the 0-based index of the file extension filter
- * which the dialog will use initially to filter the files
- * it shows to the argument.
- * <p>
- * This is an index into the FilterExtensions array and
- * the FilterNames array.
- * </p>
- *
- * @param index the file extension filter index
- *
- * @see #setFilterExtensions
- * @see #setFilterNames
- *
- * @since 3.4
- */
-public void setFilterIndex (int index) {
- filterIndex = index;
-}
-
-/**
- * Sets the names that describe the filter extensions
- * which the dialog will use to filter the files it shows
- * to the argument, which may be null.
- * <p>
- * Each name is a user-friendly short description shown for
- * its corresponding filter. The <code>names</code> array must
- * be the same length as the <code>extensions</code> array.
- * </p>
- *
- * @param names the list of filter names, or null for no filter names
- *
- * @see #setFilterExtensions
- */
-public void setFilterNames (String [] names) {
- filterNames = names;
-}
-
-/**
- * Sets the directory path that the dialog will use
- * to the argument, which may be null. File names in this
- * path will appear in the dialog, filtered according
- * to the filter extensions. If the string is null,
- * then the operating system's default filter path
- * will be used.
- * <p>
- * Note that the path string is platform dependent.
- * For convenience, either '/' or '\' can be used
- * as a path separator.
- * </p>
- *
- * @param string the directory path
- *
- * @see #setFilterExtensions
- */
-public void setFilterPath (String string) {
- filterPath = string;
-}
-
-/**
- * Sets the flag that the dialog will use to
- * determine whether to prompt the user for file
- * overwrite if the selected file already exists.
- *
- * @param overwrite true if the dialog will prompt for file overwrite, false otherwise
- *
- * @since 3.4
- */
-public void setOverwrite (boolean overwrite) {
- this.overwrite = overwrite;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java
deleted file mode 100755
index aa35f803ee..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java
+++ /dev/null
@@ -1,325 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class allow the user to select a font
- * from all available fonts in the system.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class FontDialog extends Dialog {
- FontData fontData;
- RGB rgb;
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FontDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FontDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-/**
- * Returns a FontData object describing the font that was
- * selected in the dialog, or null if none is available.
- *
- * @return the FontData for the selected font, or null
- * @deprecated use #getFontList ()
- */
-public FontData getFontData () {
- return fontData;
-}
-
-/**
- * Returns a FontData set describing the font that was
- * selected in the dialog, or null if none is available.
- *
- * @return the FontData for the selected font, or null
- * @since 2.1.1
- */
-public FontData [] getFontList () {
- if (fontData == null) return null;
- FontData [] result = new FontData [1];
- result [0] = fontData;
- return result;
-}
-
-/**
- * Returns an RGB describing the color that was selected
- * in the dialog, or null if none is available.
- *
- * @return the RGB value for the selected color, or null
- *
- * @see PaletteData#getRGBs
- *
- * @since 2.1
- */
-public RGB getRGB () {
- return rgb;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a FontData object describing the font that was selected,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public FontData open () {
- if (OS.IsWinCE) SWT.error (SWT.ERROR_NOT_IMPLEMENTED);
-
- /* Get the owner HWND for the dialog */
- int /*long*/ hwndOwner = parent.handle;
- int /*long*/ hwndParent = parent.handle;
-
- /*
- * Feature in Windows. There is no API to set the orientation of a
- * font dialog. It is always inherited from the parent. The fix is
- * to create a hidden parent and set the orientation in the hidden
- * parent for the dialog to inherit.
- */
- boolean enabled = false;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
- int dialogOrientation = style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
- int parentOrientation = parent.style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
- if (dialogOrientation != parentOrientation) {
- int exStyle = OS.WS_EX_NOINHERITLAYOUT;
- if (dialogOrientation == SWT.RIGHT_TO_LEFT) exStyle |= OS.WS_EX_LAYOUTRTL;
- hwndOwner = OS.CreateWindowEx (
- exStyle,
- Shell.DialogClass,
- null,
- 0,
- OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0,
- hwndParent,
- 0,
- OS.GetModuleHandle (null),
- null);
- enabled = OS.IsWindowEnabled (hwndParent);
- if (enabled) OS.EnableWindow (hwndParent, false);
- }
- }
-
- /* Open the dialog */
- int /*long*/ hHeap = OS.GetProcessHeap ();
- CHOOSEFONT lpcf = new CHOOSEFONT ();
- lpcf.lStructSize = CHOOSEFONT.sizeof;
- lpcf.hwndOwner = hwndOwner;
- lpcf.Flags = OS.CF_SCREENFONTS | OS.CF_EFFECTS;
- int /*long*/ lpLogFont = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, LOGFONT.sizeof);
- if (fontData != null && fontData.data != null) {
- LOGFONT logFont = fontData.data;
- int lfHeight = logFont.lfHeight;
- int /*long*/ hDC = OS.GetDC (0);
- int pixels = -(int)(0.5f + (fontData.height * OS.GetDeviceCaps(hDC, OS.LOGPIXELSY) / 72));
- OS.ReleaseDC (0, hDC);
- logFont.lfHeight = pixels;
- lpcf.Flags |= OS.CF_INITTOLOGFONTSTRUCT;
- OS.MoveMemory (lpLogFont, logFont, LOGFONT.sizeof);
- logFont.lfHeight = lfHeight;
- }
- lpcf.lpLogFont = lpLogFont;
- if (rgb != null) {
- int red = rgb.red & 0xFF;
- int green = (rgb.green << 8) & 0xFF00;
- int blue = (rgb.blue << 16) & 0xFF0000;
- lpcf.rgbColors = red | green | blue;
- }
-
- /* Make the parent shell be temporary modal */
- Dialog oldModal = null;
- Display display = null;
- if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- display = parent.getDisplay ();
- oldModal = display.getModalDialog ();
- display.setModalDialog (this);
- }
-
- /* Open the dialog */
- boolean success = OS.ChooseFont (lpcf);
-
- /* Clear the temporary dialog modal parent */
- if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- display.setModalDialog (oldModal);
- }
-
- /* Compute the result */
- if (success) {
- LOGFONT logFont = OS.IsUnicode ? (LOGFONT) new LOGFONTW () : new LOGFONTA ();
- OS.MoveMemory (logFont, lpLogFont, LOGFONT.sizeof);
-
- /*
- * This will not work on multiple screens or
- * for printing. Should use DC for the proper device.
- */
- int /*long*/ hDC = OS.GetDC(0);
- int logPixelsY = OS.GetDeviceCaps(hDC, OS.LOGPIXELSY);
- int pixels = 0;
- if (logFont.lfHeight > 0) {
- /*
- * Feature in Windows. If the lfHeight of the LOGFONT structure
- * is positive, the lfHeight measures the height of the entire
- * cell, including internal leading, in logical units. Since the
- * height of a font in points does not include the internal leading,
- * we must subtract the internal leading, which requires a TEXTMETRIC,
- * which in turn requires font creation.
- */
- int /*long*/ hFont = OS.CreateFontIndirect(logFont);
- int /*long*/ oldFont = OS.SelectObject(hDC, hFont);
- TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ();
- OS.GetTextMetrics(hDC, lptm);
- OS.SelectObject(hDC, oldFont);
- OS.DeleteObject(hFont);
- pixels = logFont.lfHeight - lptm.tmInternalLeading;
- } else {
- pixels = -logFont.lfHeight;
- }
- OS.ReleaseDC(0, hDC);
-
- float points = pixels * 72f /logPixelsY;
- fontData = FontData.win32_new (logFont, points);
- int red = lpcf.rgbColors & 0xFF;
- int green = (lpcf.rgbColors >> 8) & 0xFF;
- int blue = (lpcf.rgbColors >> 16) & 0xFF;
- rgb = new RGB (red, green, blue);
- }
-
- /* Free the OS memory */
- if (lpLogFont != 0) OS.HeapFree (hHeap, 0, lpLogFont);
-
- /* Destroy the BIDI orientation window */
- if (hwndParent != hwndOwner) {
- if (enabled) OS.EnableWindow (hwndParent, true);
- OS.SetActiveWindow (hwndParent);
- OS.DestroyWindow (hwndOwner);
- }
-
- /*
- * This code is intentionally commented. On some
- * platforms, the owner window is repainted right
- * away when a dialog window exits. This behavior
- * is currently unspecified.
- */
-// if (hwndOwner != 0) OS.UpdateWindow (hwndOwner);
-
- if (!success) return null;
- return fontData;
-}
-
-/**
- * Sets a FontData object describing the font to be
- * selected by default in the dialog, or null to let
- * the platform choose one.
- *
- * @param fontData the FontData to use initially, or null
- * @deprecated use #setFontList (FontData [])
- */
-public void setFontData (FontData fontData) {
- this.fontData = fontData;
-}
-
-/**
- * Sets the set of FontData objects describing the font to
- * be selected by default in the dialog, or null to let
- * the platform choose one.
- *
- * @param fontData the set of FontData objects to use initially, or null
- * to let the platform select a default when open() is called
- *
- * @see Font#getFontData
- *
- * @since 2.1.1
- */
-public void setFontList (FontData [] fontData) {
- if (fontData != null && fontData.length > 0) {
- this.fontData = fontData [0];
- } else {
- this.fontData = null;
- }
-}
-
-/**
- * Sets the RGB describing the color to be selected by default
- * in the dialog, or null to let the platform choose one.
- *
- * @param rgb the RGB value to use initially, or null to let
- * the platform select a default when open() is called
- *
- * @see PaletteData#getRGBs
- *
- * @since 2.1
- */
-public void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Group.java
deleted file mode 100755
index 317dfa452e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Group.java
+++ /dev/null
@@ -1,569 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide an etched border
- * with an optional title.
- * <p>
- * Shadow styles are hints and may not be honoured
- * by the platform. To create a group with the
- * default shadow style for the platform, do not
- * specify a shadow style.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SHADOW_ETCHED_IN, SHADOW_ETCHED_OUT, SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the above styles may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Group extends Composite {
- String text = "";
- static final int CLIENT_INSET = 3;
- static final int /*long*/ GroupProc;
- static final TCHAR GroupClass = new TCHAR (0, OS.IsWinCE ? "BUTTON" : "SWT_GROUP", true);
- static {
- /*
- * Feature in Windows. The group box window class
- * uses the CS_HREDRAW and CS_VREDRAW style bits to
- * force a full redraw of the control and all children
- * when resized. This causes flashing. The fix is to
- * register a new window class without these bits and
- * implement special code that damages only the control.
- *
- * Feature in WinCE. On certain devices, defining
- * a new window class which looks like BUTTON causes
- * CreateWindowEx() to crash. The workaround is to use
- * the class Button directly.
- */
- WNDCLASS lpWndClass = new WNDCLASS ();
- if (OS.IsWinCE) {
- OS.GetClassInfo (0, GroupClass, lpWndClass);
- GroupProc = lpWndClass.lpfnWndProc;
- } else {
- TCHAR WC_BUTTON = new TCHAR (0, "BUTTON", true);
- OS.GetClassInfo (0, WC_BUTTON, lpWndClass);
- GroupProc = lpWndClass.lpfnWndProc;
- int /*long*/ hInstance = OS.GetModuleHandle (null);
- if (!OS.GetClassInfo (hInstance, GroupClass, lpWndClass)) {
- int /*long*/ hHeap = OS.GetProcessHeap ();
- lpWndClass.hInstance = hInstance;
- lpWndClass.style &= ~(OS.CS_HREDRAW | OS.CS_VREDRAW);
- int byteCount = GroupClass.length () * TCHAR.sizeof;
- int /*long*/ lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (lpszClassName, GroupClass, byteCount);
- lpWndClass.lpszClassName = lpszClassName;
- OS.RegisterClass (lpWndClass);
- OS.HeapFree (hHeap, 0, lpszClassName);
- }
- }
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SHADOW_ETCHED_IN
- * @see SWT#SHADOW_ETCHED_OUT
- * @see SWT#SHADOW_IN
- * @see SWT#SHADOW_OUT
- * @see SWT#SHADOW_NONE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Group (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- /*
- * Feature in Windows. When the user clicks on the group
- * box label, the group box takes focus. This is unwanted.
- * The fix is to avoid calling the group box window proc.
- */
- switch (msg) {
- case OS.WM_LBUTTONDOWN:
- case OS.WM_LBUTTONDBLCLK:
- return OS.DefWindowProc (hwnd, msg, wParam, lParam);
- }
- return OS.CallWindowProc (GroupProc, hwnd, msg, wParam, lParam);
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- Point size = super.computeSize (wHint, hHint, changed);
- int length = text.length ();
- if (length != 0) {
- /*
- * Bug in Windows. When a group control is right-to-left and
- * is disabled, the first pixel of the text is clipped. The
- * fix is to add a space to both sides of the text. Note that
- * the work around must run all the time to stop the preferred
- * size from changing when a group is enabled and disabled.
- */
- String string = text;
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
- string = " " + string + " ";
- }
- }
- /*
- * If the group has text, and the text is wider than the
- * client area, pad the width so the text is not clipped.
- */
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- int /*long*/ newFont, oldFont = 0;
- int /*long*/ hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- RECT rect = new RECT ();
- int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE;
- OS.DrawText (hDC, buffer, -1, rect, flags);
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- int offsetY = OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed () ? 0 : 1;
- size.x = Math.max (size.x, rect.right - rect.left + CLIENT_INSET * 6 + offsetY);
- }
- return size;
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
- Rectangle trim = super.computeTrim (x, y, width, height);
- int /*long*/ newFont, oldFont = 0;
- int /*long*/ hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ();
- OS.GetTextMetrics (hDC, tm);
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- int offsetY = OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed () ? 0 : 1;
- trim.x -= CLIENT_INSET;
- trim.y -= tm.tmHeight + offsetY;
- trim.width += CLIENT_INSET * 2;
- trim.height += tm.tmHeight + CLIENT_INSET + offsetY;
- return trim;
-}
-
-void createHandle () {
- /*
- * Feature in Windows. When a button is created,
- * it clears the UI state for all controls in the
- * shell by sending WM_CHANGEUISTATE with UIS_SET,
- * UISF_HIDEACCEL and UISF_HIDEFOCUS to the parent.
- * This is undocumented and unexpected. The fix
- * is to ignore the WM_CHANGEUISTATE, when sent
- * from CreateWindowEx().
- */
- parent.state |= IGNORE_WM_CHANGEUISTATE;
- super.createHandle ();
- parent.state &= ~IGNORE_WM_CHANGEUISTATE;
- state |= DRAW_BACKGROUND;
- state &= ~CANVAS;
-}
-
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- /*
- * Bug in Windows. When a group control is right-to-left and
- * is disabled, the first pixel of the text is clipped. The
- * fix is to add a space to both sides of the text.
- */
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
- String string = enabled || text.length() == 0 ? text : " " + text + " ";
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- OS.SetWindowText (handle, buffer);
- }
- }
-}
-
-public Rectangle getClientArea () {
- checkWidget ();
- forceResize ();
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- int /*long*/ newFont, oldFont = 0;
- int /*long*/ hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ();
- OS.GetTextMetrics (hDC, tm);
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- int offsetY = OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed () ? 0 : 1;
- int x = CLIENT_INSET, y = tm.tmHeight + offsetY;
- int width = Math.max (0, rect.right - CLIENT_INSET * 2);
- int height = Math.max (0, rect.bottom - y - CLIENT_INSET);
- return new Rectangle (x, y, width, height);
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which is the string that the
- * is used as the <em>title</em>. If the text has not previously
- * been set, returns an empty string.
- *
- * @return the text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-boolean mnemonicHit (char key) {
- return setFocus ();
-}
-
-boolean mnemonicMatch (char key) {
- char mnemonic = findMnemonic (getText ());
- if (mnemonic == '\0') return false;
- return Character.toUpperCase (key) == Character.toUpperCase (mnemonic);
-}
-
-void printWidget (int /*long*/ hwnd, int /*long*/ hdc, GC gc) {
- /*
- * Bug in Windows. For some reason, PrintWindow()
- * returns success but does nothing when it is called
- * on a printer. The fix is to just go directly to
- * WM_PRINT in this case.
- */
- boolean success = false;
- if (!(OS.GetDeviceCaps(gc.handle, OS.TECHNOLOGY) == OS.DT_RASPRINTER)) {
- int bits = OS.GetWindowLong (hwnd, OS.GWL_STYLE);
- if ((bits & OS.WS_VISIBLE) == 0) {
- OS.DefWindowProc (hwnd, OS.WM_SETREDRAW, 1, 0);
- }
- success = OS.PrintWindow (hwnd, hdc, 0);
- if ((bits & OS.WS_VISIBLE) == 0) {
- OS.DefWindowProc (hwnd, OS.WM_SETREDRAW, 0, 0);
- }
- }
-
- /*
- * Bug in Windows. For some reason, PrintWindow() fails
- * when it is called on a push button. The fix is to
- * detect the failure and use WM_PRINT instead. Note
- * that WM_PRINT cannot be used all the time because it
- * fails for browser controls when the browser has focus.
- */
- if (!success) {
- /*
- * Bug in Windows. For some reason, WM_PRINT when called
- * with PRF_CHILDREN will not draw the tool bar divider
- * for tool bar children that do not have CCS_NODIVIDER.
- * The fix is to draw the group box and iterate through
- * the children, drawing each one.
- */
- int flags = OS.PRF_CLIENT | OS.PRF_NONCLIENT | OS.PRF_ERASEBKGND;
- OS.SendMessage (hwnd, OS.WM_PRINT, hdc, flags);
- int nSavedDC = OS.SaveDC (hdc);
- Control [] children = _getChildren ();
- Rectangle rect = getBounds ();
- OS.IntersectClipRect (hdc, 0, 0, rect.width, rect.height);
- for (int i=children.length - 1; i>=0; --i) {
- Point location = children [i].getLocation ();
- int graphicsMode = OS.GetGraphicsMode(hdc);
- if (graphicsMode == OS.GM_ADVANCED) {
- float [] lpXform = {1, 0, 0, 1, location.x, location.y};
- OS.ModifyWorldTransform(hdc, lpXform, OS.MWT_LEFTMULTIPLY);
- } else {
- OS.SetWindowOrgEx (hdc, -location.x, -location.y, null);
- }
- int /*long*/ topHandle = children [i].topHandle();
- int bits = OS.GetWindowLong (topHandle, OS.GWL_STYLE);
- if ((bits & OS.WS_VISIBLE) != 0) {
- children [i].printWidget (topHandle, hdc, gc);
- }
- if (graphicsMode == OS.GM_ADVANCED) {
- float [] lpXform = {1, 0, 0, 1, -location.x, -location.y};
- OS.ModifyWorldTransform(hdc, lpXform, OS.MWT_LEFTMULTIPLY);
- }
- }
- OS.RestoreDC (hdc, nSavedDC);
- }
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- text = null;
-}
-
-public void setFont (Font font) {
- checkWidget ();
- Rectangle oldRect = getClientArea ();
- super.setFont (font);
- Rectangle newRect = getClientArea ();
- if (!oldRect.equals (newRect)) sendResize ();
-}
-
-/**
- * Sets the receiver's text, which is the string that will
- * be displayed as the receiver's <em>title</em>, to the argument,
- * which may not be null. The string may include the mnemonic character.
- * </p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, focus is assigned
- * to the first child of the group. On most platforms, the
- * mnemonic appears underlined but may be emphasised in a
- * platform specific manner. The mnemonic indicator character
- * '&amp;' can be escaped by doubling it in the string, causing
- * a single '&amp;' to be displayed.
- * </p>
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- text = string;
- /*
- * Bug in Windows. When a group control is right-to-left and
- * is disabled, the first pixel of the text is clipped. The
- * fix is to add a space to both sides of the text.
- */
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
- if (!OS.IsWindowEnabled (handle)) {
- if (string.length() != 0) string = " " + string + " ";
- }
- }
- }
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- OS.SetWindowText (handle, buffer);
-}
-
-int widgetStyle () {
- /*
- * Bug in Windows. When GetDCEx() is called with DCX_INTERSECTUPDATE,
- * the HDC that is returned does not include the current update region.
- * This was confirmed under DEBUG Windows when GetDCEx() complained about
- * invalid flags. Therefore, it is not easily possible to get an HDC from
- * outside of WM_PAINT that includes the current damage and clips children.
- * Because the receiver has children and draws a frame and label, it is
- * necessary that the receiver always draw clipped, in the current damaged
- * area. The fix is to force the receiver to be fully clipped by including
- * WS_CLIPCHILDREN and WS_CLIPSIBLINGS in the default style bits.
- */
- return super.widgetStyle () | OS.BS_GROUPBOX | OS.WS_CLIPCHILDREN | OS.WS_CLIPSIBLINGS;
-}
-
-TCHAR windowClass () {
- return GroupClass;
-}
-
-int /*long*/ windowProc () {
- return GroupProc;
-}
-
-LRESULT WM_ERASEBKGND (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. Group boxes do not erase
- * the background before drawing. The fix is to
- * fill the background.
- */
- drawBackground (wParam);
- return LRESULT.ONE;
-}
-
-LRESULT WM_NCHITTEST (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_NCHITTEST (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. The window proc for the group box
- * returns HTTRANSPARENT indicating that mouse messages
- * should not be delivered to the receiver and any children.
- * Normally, group boxes in Windows do not have children and
- * this is the correct behavior for this case. Because we
- * allow children, answer HTCLIENT to allow mouse messages
- * to be delivered to the children.
- */
- int /*long*/ code = callWindowProc (handle, OS.WM_NCHITTEST, wParam, lParam);
- if (code == OS.HTTRANSPARENT) code = OS.HTCLIENT;
- return new LRESULT (code);
-}
-
-LRESULT WM_MOUSEMOVE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_MOUSEMOVE (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. In version 6.00 of COMCTL32.DLL,
- * every time the mouse moves, the group title redraws.
- * This only happens when WM_NCHITTEST returns HTCLIENT.
- * The fix is to avoid calling the group window proc.
- */
- return LRESULT.ZERO;
-}
-
-LRESULT WM_PRINTCLIENT (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_PRINTCLIENT (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. In version 6.00 of COMCTL32.DLL,
- * when WM_PRINTCLIENT is sent from a child BS_GROUP
- * control to a parent BS_GROUP, the parent BS_GROUP
- * clears the font from the HDC. Normally, group boxes
- * in Windows do not have children so this behavior is
- * undefined. When the parent of a BS_GROUP is not a
- * BS_GROUP, there is no problem. The fix is to save
- * and restore the current font.
- */
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- int nSavedDC = OS.SaveDC (wParam);
- int /*long*/ code = callWindowProc (handle, OS.WM_PRINTCLIENT, wParam, lParam);
- OS.RestoreDC (wParam, nSavedDC);
- return new LRESULT (code);
- }
- return result;
-}
-
-LRESULT WM_UPDATEUISTATE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_UPDATEUISTATE (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. When WM_UPDATEUISTATE is sent to
- * a group, it sends WM_CTLCOLORBTN to get the foreground
- * and background. If drawing happens in WM_CTLCOLORBTN,
- * it will overwrite the contents of the control. The
- * fix is draw the group without drawing the background
- * and avoid the group window proc.
- */
- boolean redraw = findImageControl () != null;
- if (!redraw) {
- if ((state & THEME_BACKGROUND) != 0) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- redraw = findThemeControl () != null;
- }
- }
- if (!redraw) redraw = findBackgroundControl () != null;
- }
- if (redraw) {
- OS.InvalidateRect (handle, null, false);
- int /*long*/ code = OS.DefWindowProc (handle, OS.WM_UPDATEUISTATE, wParam, lParam);
- return new LRESULT (code);
- }
- return result;
-}
-
-LRESULT WM_WINDOWPOSCHANGING (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_WINDOWPOSCHANGING (wParam, lParam);
- if (result != null) return result;
- /*
- * Invalidate the portion of the group widget that needs to
- * be redrawn. Note that for some reason, invalidating the
- * group from inside WM_SIZE causes pixel corruption for
- * radio button children.
- */
- if (OS.IsWinCE) return result;
- if (!OS.IsWindowVisible (handle)) return result;
- WINDOWPOS lpwp = new WINDOWPOS ();
- OS.MoveMemory (lpwp, lParam, WINDOWPOS.sizeof);
- if ((lpwp.flags & (OS.SWP_NOSIZE | OS.SWP_NOREDRAW)) != 0) {
- return result;
- }
- RECT rect = new RECT ();
- OS.SetRect (rect, 0, 0, lpwp.cx, lpwp.cy);
- OS.SendMessage (handle, OS.WM_NCCALCSIZE, 0, rect);
- int newWidth = rect.right - rect.left;
- int newHeight = rect.bottom - rect.top;
- OS.GetClientRect (handle, rect);
- int oldWidth = rect.right - rect.left;
- int oldHeight = rect.bottom - rect.top;
- if (newWidth == oldWidth && newHeight == oldHeight) {
- return result;
- }
- if (newWidth != oldWidth) {
- int left = oldWidth;
- if (newWidth < oldWidth) left = newWidth;
- OS.SetRect (rect, left - CLIENT_INSET, 0, newWidth, newHeight);
- OS.InvalidateRect (handle, rect, true);
- }
- if (newHeight != oldHeight) {
- int bottom = oldHeight;
- if (newHeight < oldHeight) bottom = newHeight;
- if (newWidth < oldWidth) oldWidth -= CLIENT_INSET;
- OS.SetRect (rect, 0, bottom - CLIENT_INSET, oldWidth, newHeight);
- OS.InvalidateRect (handle, rect, true);
- }
- return result;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/IME.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/IME.java
deleted file mode 100644
index bfd9425355..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/IME.java
+++ /dev/null
@@ -1,566 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent input method editors.
- * These are typically in-line pre-edit text areas that allow
- * the user to compose characters from Far Eastern languages
- * such as Japanese, Chinese or Korean.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>ImeComposition</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.4
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class IME extends Widget {
- Canvas parent;
- int caretOffset;
- int startOffset;
- int commitCount;
- String text;
- int [] ranges;
- TextStyle [] styles;
-
- static final int WM_MSIME_MOUSE = OS.RegisterWindowMessage (new TCHAR (0, "MSIMEMouseOperation", true)); //$NON-NLS-1$
-
- static final byte [] IID_ITfInputProcessorProfiles = new byte [16];
- static final byte [] IID_ITfDisplayAttributeProvider = new byte [16];
- static final byte [] CLSID_TF_InputProcessorProfiles = new byte [16];
- static final byte [] GUID_TFCAT_TIP_KEYBOARD = new byte [16];
- static {
- OS.IIDFromString ("{1F02B6C5-7842-4EE6-8A0B-9A24183A95CA}\0".toCharArray (), IID_ITfInputProcessorProfiles); //$NON-NLS-1$
- OS.IIDFromString ("{fee47777-163c-4769-996a-6e9c50ad8f54}\0".toCharArray (), IID_ITfDisplayAttributeProvider); //$NON-NLS-1$
- OS.IIDFromString ("{33C53A50-F456-4884-B049-85FD643ECFED}\0".toCharArray (), CLSID_TF_InputProcessorProfiles); //$NON-NLS-1$
- OS.IIDFromString ("{34745C63-B2F0-4784-8B67-5E12C8701A31}\0".toCharArray (), GUID_TFCAT_TIP_KEYBOARD); //$NON-NLS-1$
- }
-
- /* TextLayout has a copy of these constants */
- static final int UNDERLINE_IME_DOT = 1 << 16;
- static final int UNDERLINE_IME_DASH = 2 << 16;
- static final int UNDERLINE_IME_THICK = 3 << 16;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-IME () {
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a canvas control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public IME (Canvas parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget ();
-}
-
-void createWidget () {
- text = ""; //$NON-NLS-1$
- startOffset = -1;
- if (parent.getIME () == null) {
- parent.setIME (this);
- }
-}
-
-/**
- * Returns the offset of the caret from the start of the document.
- * The caret is within the current composition.
- *
- * @return the caret offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretOffset () {
- checkWidget ();
- return startOffset + caretOffset;
-}
-
-/**
- * Returns the commit count of the composition. This is the
- * number of characters that have been composed. When the
- * commit count is equal to the length of the composition
- * text, then the in-line edit operation is complete.
- *
- * @return the commit count
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see IME#getText
- */
-public int getCommitCount () {
- checkWidget ();
- return commitCount;
-}
-
-/**
- * Returns the offset of the composition from the start of the document.
- * This is the start offset of the composition within the document and
- * in not changed by the input method editor itself during the in-line edit
- * session.
- *
- * @return the offset of the composition
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCompositionOffset () {
- checkWidget ();
- return startOffset;
-}
-
-TF_DISPLAYATTRIBUTE getDisplayAttribute (short langid, int attInfo) {
- int /*long*/ [] pProfiles = new int /*long*/ [1];
- int hr = OS.CoCreateInstance (CLSID_TF_InputProcessorProfiles, 0, OS.CLSCTX_INPROC_SERVER, IID_ITfInputProcessorProfiles, pProfiles);
- TF_DISPLAYATTRIBUTE pda = null;
- if (hr == OS.S_OK) {
- byte [] pclsid = new byte [16];
- byte [] pguidProfile = new byte [16];
- /* pProfiles.GetDefaultLanguageProfile () */
- hr = OS.VtblCall (8, pProfiles [0], langid, GUID_TFCAT_TIP_KEYBOARD, pclsid, pguidProfile);
- if (hr == OS.S_OK) {
- int /*long*/ [] pProvider = new int /*long*/ [1];
- hr = OS.CoCreateInstance (pclsid, 0, OS.CLSCTX_INPROC_SERVER, IID_ITfDisplayAttributeProvider, pProvider);
- if (hr == OS.S_OK) {
- int /*long*/ [] pEnum = new int /*long*/ [1];
- /* pProvider.EnumDisplayAttributeInfo () */
- hr = OS.VtblCall (3, pProvider [0], pEnum);
- if (hr == OS.S_OK) {
- int /*long*/ [] pDispInfo = new int /*long*/ [1];
- TF_DISPLAYATTRIBUTE tempPda = new TF_DISPLAYATTRIBUTE ();
- /* pEnum.Next () */
- while ((hr = OS.VtblCall (4, pEnum [0], 1, pDispInfo, null)) == OS.S_OK) {
- /* pDispInfo.GetAttributeInfo(); */
- OS.VtblCall (5, pDispInfo [0], tempPda);
- /* pDispInfo.Release () */
- OS.VtblCall (2, pDispInfo [0]);
- if (tempPda.bAttr == attInfo) {
- pda = tempPda;
- break;
- }
- }
- /* pEnum.Release () */
- hr = OS.VtblCall (2, pEnum [0]);
- }
- /* pProvider.Release () */
- hr = OS.VtblCall (2, pProvider [0]);
- }
- }
- /* pProfiles.Release () */
- hr = OS.VtblCall (2, pProfiles [0]);
- }
- if (pda == null) {
- pda = new TF_DISPLAYATTRIBUTE ();
- switch (attInfo) {
- case OS.TF_ATTR_INPUT:
- pda.lsStyle = OS.TF_LS_SQUIGGLE;
- break;
- case OS.TF_ATTR_CONVERTED:
- case OS.TF_ATTR_TARGET_CONVERTED:
- pda.lsStyle = OS.TF_LS_SOLID;
- pda.fBoldLine = attInfo == OS.TF_ATTR_TARGET_CONVERTED;
- break;
- }
- }
- return pda;
-}
-
-/**
- * Returns the ranges for the style that should be applied during the
- * in-line edit session.
- * <p>
- * The ranges array contains start and end pairs. Each pair refers to
- * the corresponding style in the styles array. For example, the pair
- * that starts at ranges[n] and ends at ranges[n+1] uses the style
- * at styles[n/2] returned by <code>getStyles()</code>.
- * </p>
- * @return the ranges for the styles
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see IME#getStyles
- */
-public int [] getRanges () {
- checkWidget ();
- if (ranges == null) return new int [0];
- int [] result = new int [ranges.length];
- for (int i = 0; i < result.length; i++) {
- result [i] = ranges [i] + startOffset;
- }
- return result;
-}
-
-/**
- * Returns the styles for the ranges.
- * <p>
- * The ranges array contains start and end pairs. Each pair refers to
- * the corresponding style in the styles array. For example, the pair
- * that starts at ranges[n] and ends at ranges[n+1] uses the style
- * at styles[n/2].
- * </p>
- *
- * @return the ranges for the styles
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see IME#getRanges
- */
-public TextStyle [] getStyles () {
- checkWidget ();
- if (styles == null) return new TextStyle [0];
- TextStyle [] result = new TextStyle [styles.length];
- System.arraycopy (styles, 0, result, 0, styles.length);
- return result;
-}
-
-/**
- * Returns the composition text.
- * <p>
- * The text for an IME is the characters in the widget that
- * are in the current composition. When the commit count is
- * equal to the length of the composition text, then the
- * in-line edit operation is complete.
- * </p>
- *
- * @return the widget text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-/**
- * Returns <code>true</code> if the caret should be wide, and
- * <code>false</code> otherwise. In some languages, for example
- * Korean, the caret is typically widened to the width of the
- * current character in the in-line edit session.
- *
- * @return the wide caret state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getWideCaret() {
- checkWidget ();
- int /*long*/ layout = OS.GetKeyboardLayout (0);
- short langID = (short)OS.LOWORD (layout);
- return OS.PRIMARYLANGID (langID) == OS.LANG_KOREAN;
-}
-
-boolean isInlineEnabled () {
- if (OS.IsWinCE || OS.WIN32_VERSION < OS.VERSION (5, 1)) return false;
- return OS.IsDBLocale && hooks (SWT.ImeComposition);
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (this == parent.getIME ()) parent.setIME (null);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
- text = null;
- styles = null;
- ranges = null;
-}
-
-/**
- * Sets the offset of the composition from the start of the document.
- * This is the start offset of the composition within the document and
- * in not changed by the input method editor itself during the in-line edit
- * session but may need to be changed by clients of the IME. For example,
- * if during an in-line edit operation, a text editor inserts characters
- * above the IME, then the IME must be informed that the composition
- * offset has changed.
- *
- * @param offset the offset of the composition
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCompositionOffset (int offset) {
- checkWidget ();
- if (offset < 0) return;
- if (startOffset != -1) {
- startOffset = offset;
- }
-}
-
-LRESULT WM_IME_COMPOSITION (int /*long*/ wParam, int /*long*/ lParam) {
- if (!isInlineEnabled ()) return null;
- ranges = null;
- styles = null;
- caretOffset = commitCount = 0;
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hIMC = OS.ImmGetContext (hwnd);
- int codePage = parent.getCodePage ();
- if (hIMC != 0) {
- TCHAR buffer = null;
- if ((lParam & OS.GCS_RESULTSTR) != 0) {
- int length = OS.ImmGetCompositionString (hIMC, OS.GCS_RESULTSTR, (TCHAR)null, 0);
- if (length > 0) {
- buffer = new TCHAR (codePage, length / TCHAR.sizeof);
- OS.ImmGetCompositionString (hIMC, OS.GCS_RESULTSTR, buffer, length);
- if (startOffset == -1) {
- Event event = new Event ();
- event.detail = SWT.COMPOSITION_SELECTION;
- sendEvent (SWT.ImeComposition, event);
- startOffset = event.start;
- }
- Event event = new Event ();
- event.detail = SWT.COMPOSITION_CHANGED;
- event.start = startOffset;
- event.end = startOffset + text.length();
- event.text = text = buffer != null ? buffer.toString () : ""; //$NON-NLS-1$
- commitCount = text.length ();
- sendEvent (SWT.ImeComposition, event);
- String chars = text;
- text = ""; //$NON-NLS-1$
- startOffset = -1;
- commitCount = 0;
- if (event.doit) {
- Display display = this.display;
- display.lastKey = 0;
- display.lastVirtual = display.lastNull = display.lastDead = false;
- length = chars.length ();
- for (int i = 0; i < length; i++) {
- char c = chars.charAt (i);
- display.lastAscii = c;
- event = new Event ();
- event.character = c;
- parent.sendEvent (SWT.KeyDown, event);
- }
- }
- }
- if ((lParam & OS.GCS_COMPSTR) == 0) return LRESULT.ONE;
- }
- buffer = null;
- if ((lParam & OS.GCS_COMPSTR) != 0) {
- int length = OS.ImmGetCompositionString (hIMC, OS.GCS_COMPSTR, (TCHAR)null, 0);
- if (length > 0) {
- buffer = new TCHAR (codePage, length / TCHAR.sizeof);
- OS.ImmGetCompositionString (hIMC, OS.GCS_COMPSTR, buffer, length);
- if ((lParam & OS.GCS_CURSORPOS) != 0) {
- caretOffset = OS.ImmGetCompositionString (hIMC, OS.GCS_CURSORPOS, (TCHAR) null, 0);
- }
- int [] clauses = null;
- if ((lParam & OS.GCS_COMPCLAUSE) != 0) {
- length = OS.ImmGetCompositionString (hIMC, OS.GCS_COMPCLAUSE, (int [])null, 0);
- if (length > 0) {
- clauses = new int [length / 4];
- OS.ImmGetCompositionString (hIMC, OS.GCS_COMPCLAUSE, clauses, length);
- }
- }
- if ((lParam & OS.GCS_COMPATTR) != 0 && clauses != null) {
- length = OS.ImmGetCompositionString (hIMC, OS.GCS_COMPATTR, (byte [])null, 0);
- if (length > 0) {
- byte [] attrs = new byte [length];
- OS.ImmGetCompositionString (hIMC, OS.GCS_COMPATTR, attrs, length);
- length = clauses.length - 1;
- ranges = new int [length * 2];
- styles = new TextStyle [length];
- int /*long*/ layout = OS.GetKeyboardLayout (0);
- short langID = (short)OS.LOWORD (layout);
- TF_DISPLAYATTRIBUTE attr = null;
- TextStyle style = null;
- for (int i = 0; i < length; i++) {
- ranges [i * 2] = clauses [i];
- ranges [i * 2 + 1] = clauses [i + 1] - 1;
- styles [i] = style = new TextStyle ();
- attr = getDisplayAttribute (langID, attrs [clauses [i]]);
- if (attr != null) {
- switch (attr.crText.type) {
- case OS.TF_CT_COLORREF:
- style.foreground = Color.win32_new (display, attr.crText.cr);
- break;
- case OS.TF_CT_SYSCOLOR:
- int colorRef = OS.GetSysColor (attr.crText.cr);
- style.foreground = Color.win32_new (display, colorRef);
- break;
- }
- switch (attr.crBk.type) {
- case OS.TF_CT_COLORREF:
- style.background = Color.win32_new (display, attr.crBk.cr);
- break;
- case OS.TF_CT_SYSCOLOR:
- int colorRef = OS.GetSysColor (attr.crBk.cr);
- style.background = Color.win32_new (display, colorRef);
- break;
- }
- switch (attr.crLine.type) {
- case OS.TF_CT_COLORREF:
- style.underlineColor = Color.win32_new (display, attr.crLine.cr);
- break;
- case OS.TF_CT_SYSCOLOR:
- int colorRef = OS.GetSysColor (attr.crLine.cr);
- style.underlineColor = Color.win32_new (display, colorRef);
- break;
- }
- style.underline = attr.lsStyle != OS.TF_LS_NONE;
- switch (attr.lsStyle) {
- case OS.TF_LS_SQUIGGLE:
- style.underlineStyle = SWT.UNDERLINE_SQUIGGLE;
- break;
- case OS.TF_LS_DASH:
- style.underlineStyle = UNDERLINE_IME_DASH;
- break;
- case OS.TF_LS_DOT:
- style.underlineStyle = UNDERLINE_IME_DOT;
- break;
- case OS.TF_LS_SOLID:
- style.underlineStyle = attr.fBoldLine ? UNDERLINE_IME_THICK : SWT.UNDERLINE_SINGLE;
- break;
- }
- }
- }
- }
- }
- }
- OS.ImmReleaseContext (hwnd, hIMC);
- }
- int end = startOffset + text.length();
- if (startOffset == -1) {
- Event event = new Event ();
- event.detail = SWT.COMPOSITION_SELECTION;
- sendEvent (SWT.ImeComposition, event);
- startOffset = event.start;
- end = event.end;
- }
- Event event = new Event ();
- event.detail = SWT.COMPOSITION_CHANGED;
- event.start = startOffset;
- event.end = end;
- event.text = text = buffer != null ? buffer.toString () : ""; //$NON-NLS-1$
- sendEvent (SWT.ImeComposition, event);
- if (text.length() == 0) {
- startOffset = -1;
- ranges = null;
- styles = null;
- }
- }
- return LRESULT.ONE;
-}
-
-LRESULT WM_IME_COMPOSITION_START (int /*long*/ wParam, int /*long*/ lParam) {
- return isInlineEnabled () ? LRESULT.ONE : null;
-}
-
-LRESULT WM_IME_ENDCOMPOSITION (int /*long*/ wParam, int /*long*/ lParam) {
- return isInlineEnabled () ? LRESULT.ONE : null;
-}
-
-LRESULT WM_KILLFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- if (!isInlineEnabled ()) return null;
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hIMC = OS.ImmGetContext (hwnd);
- if (hIMC != 0) {
- if (OS.ImmGetOpenStatus (hIMC)) {
- OS.ImmNotifyIME (hIMC, OS.NI_COMPOSITIONSTR, OS.CPS_COMPLETE, 0);
- }
- OS.ImmReleaseContext (hwnd, hIMC);
- }
- return null;
-}
-
-LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- if (!isInlineEnabled ()) return null;
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hIMC = OS.ImmGetContext (hwnd);
- if (hIMC != 0) {
- if (OS.ImmGetOpenStatus (hIMC)) {
- if (OS.ImmGetCompositionString (hIMC, OS.GCS_COMPSTR, (TCHAR)null, 0) > 0) {
- Event event = new Event ();
- event.detail = SWT.COMPOSITION_OFFSET;
- event.x = OS.GET_X_LPARAM (lParam);
- event.y = OS.GET_Y_LPARAM (lParam);
- sendEvent (SWT.ImeComposition, event);
- int offset = event.index;
- int length = text.length();
- if (offset != -1 && startOffset != -1 && startOffset <= offset && offset < startOffset + length) {
- int /*long*/ imeWnd = OS.ImmGetDefaultIMEWnd (hwnd);
- offset = event.index + event.count - startOffset;
- int trailing = event.count > 0 ? 1 : 2;
- int /*long*/ param = OS.MAKEWPARAM (OS.MAKEWORD (OS.IMEMOUSE_LDOWN, trailing), offset);
- OS.SendMessage (imeWnd, WM_MSIME_MOUSE, param, hIMC);
- } else {
- OS.ImmNotifyIME (hIMC, OS.NI_COMPOSITIONSTR, OS.CPS_COMPLETE, 0);
- }
- }
- }
- OS.ImmReleaseContext (hwnd, hIMC);
- }
- return null;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java
deleted file mode 100755
index 5d23c9515a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java
+++ /dev/null
@@ -1,686 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a non-selectable
- * user interface object that displays a string or image.
- * When SEPARATOR is specified, displays a single
- * vertical or horizontal line.
- * <p>
- * Shadow styles are hints and may not be honored
- * by the platform. To create a separator label
- * with the default shadow style for the platform,
- * do not specify a shadow style.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SEPARATOR, HORIZONTAL, VERTICAL</dd>
- * <dd>SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd>
- * <dd>CENTER, LEFT, RIGHT, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of SHADOW_IN, SHADOW_OUT and SHADOW_NONE may be specified.
- * SHADOW_NONE is a HINT. Only one of HORIZONTAL and VERTICAL may be specified.
- * Only one of CENTER, LEFT and RIGHT may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#label">Label snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Label extends Control {
- String text = "";
- Image image;
- static final int MARGIN = 4;
- static /*final*/ boolean IMAGE_AND_TEXT = false;
- static final int /*long*/ LabelProc;
- static final TCHAR LabelClass = new TCHAR (0, "STATIC", true);
- static {
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, LabelClass, lpWndClass);
- LabelProc = lpWndClass.lpfnWndProc;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SEPARATOR
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#SHADOW_IN
- * @see SWT#SHADOW_OUT
- * @see SWT#SHADOW_NONE
- * @see SWT#CENTER
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#WRAP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Label (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (LabelProc, hwnd, msg, wParam, lParam);
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- if ((style & SWT.SEPARATOR) != 0) {
- style = checkBits (style, SWT.VERTICAL, SWT.HORIZONTAL, 0, 0, 0, 0);
- return checkBits (style, SWT.SHADOW_OUT, SWT.SHADOW_IN, SWT.SHADOW_NONE, 0, 0, 0);
- }
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0, border = getBorderWidth ();
- if ((style & SWT.SEPARATOR) != 0) {
- int lineWidth = OS.GetSystemMetrics (OS.SM_CXBORDER);
- if ((style & SWT.HORIZONTAL) != 0) {
- width = DEFAULT_WIDTH; height = lineWidth * 2;
- } else {
- width = lineWidth * 2; height = DEFAULT_HEIGHT;
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- width += border * 2; height += border * 2;
- return new Point (width, height);
- }
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- boolean drawText = true;
- boolean drawImage = (bits & OS.SS_OWNERDRAW) == OS.SS_OWNERDRAW;
- if (drawImage) {
- if (image != null) {
- Rectangle rect = image.getBounds();
- width += rect.width;
- height += rect.height;
- if (IMAGE_AND_TEXT) {
- if (text.length () != 0) width += MARGIN;
- } else {
- drawText = false;
- }
- }
- }
- if (drawText) {
- int /*long*/ hDC = OS.GetDC (handle);
- int /*long*/ newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- int /*long*/ oldFont = OS.SelectObject (hDC, newFont);
- int length = OS.GetWindowTextLength (handle);
- if (length == 0) {
- TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ();
- OS.GetTextMetrics (hDC, tm);
- height = Math.max (height, tm.tmHeight);
- } else {
- RECT rect = new RECT ();
- int flags = OS.DT_CALCRECT | OS.DT_EDITCONTROL | OS.DT_EXPANDTABS;
- if ((style & SWT.WRAP) != 0 && wHint != SWT.DEFAULT) {
- flags |= OS.DT_WORDBREAK;
- rect.right = Math.max (0, wHint - width);
- }
- TCHAR buffer = new TCHAR (getCodePage (), length + 1);
- OS.GetWindowText (handle, buffer, length + 1);
- OS.DrawText (hDC, buffer, length, rect, flags);
- width += rect.right - rect.left;
- height = Math.max (height, rect.bottom - rect.top);
- }
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- width += border * 2;
- height += border * 2;
- /*
- * Feature in WinCE PPC. Text labels have a trim
- * of one pixel wide on the right and left side.
- * The fix is to increase the width to include
- * this trim.
- */
- if (OS.IsWinCE && !drawImage) width += 2;
- return new Point (width, height);
-}
-
-void createHandle () {
- super.createHandle ();
- state |= THEME_BACKGROUND;
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is a <code>SEPARATOR</code> label, in
- * which case, <code>NONE</code> is returned.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return 0;
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-/**
- * Returns the receiver's image if it has one, or null
- * if it does not.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget ();
- return image;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set or if the receiver is
- * a <code>SEPARATOR</code> label.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return "";
- return text;
-}
-
-boolean mnemonicHit (char key) {
- Composite control = this.parent;
- while (control != null) {
- Control [] children = control._getChildren ();
- int index = 0;
- while (index < children.length) {
- if (children [index] == this) break;
- index++;
- }
- index++;
- if (index < children.length) {
- if (children [index].setFocus ()) return true;
- }
- control = control.parent;
- }
- return false;
-}
-
-boolean mnemonicMatch (char key) {
- char mnemonic = findMnemonic (getText ());
- if (mnemonic == '\0') return false;
- return Character.toUpperCase (key) == Character.toUpperCase (mnemonic);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- text = null;
- image = null;
-}
-
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>. If the receiver is a <code>SEPARATOR</code>
- * label, the argument is ignored and the alignment is not changed.
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return;
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.SS_OWNERDRAW) != OS.SS_OWNERDRAW) {
- bits &= ~(OS.SS_LEFTNOWORDWRAP | OS.SS_CENTER | OS.SS_RIGHT);
- if ((style & SWT.LEFT) != 0) {
- if ((style & SWT.WRAP) != 0) {
- bits |= OS.SS_LEFT;
- } else {
- bits |= OS.SS_LEFTNOWORDWRAP;
- }
- }
- if ((style & SWT.CENTER) != 0) bits |= OS.SS_CENTER;
- if ((style & SWT.RIGHT) != 0) bits |= OS.SS_RIGHT;
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- }
- OS.InvalidateRect (handle, null, true);
-}
-
-/**
- * Sets the receiver's image to the argument, which may be
- * null indicating that no image should be displayed.
- *
- * @param image the image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return;
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- this.image = image;
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.SS_OWNERDRAW) != OS.SS_OWNERDRAW) {
- bits &= ~(OS.SS_LEFTNOWORDWRAP | OS.SS_CENTER | OS.SS_RIGHT);
- bits |= OS.SS_OWNERDRAW;
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- }
- OS.InvalidateRect (handle, null, true);
-}
-
-/**
- * Sets the receiver's text.
- * <p>
- * This method sets the widget label. The label may include
- * the mnemonic character and line delimiters.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, focus is assigned
- * to the control that follows the label. On most platforms,
- * the mnemonic appears underlined but may be emphasised in a
- * platform specific manner. The mnemonic indicator character
- * '&amp;' can be escaped by doubling it in the string, causing
- * a single '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- /*
- * Feature in Windows. For some reason, SetWindowText() for
- * static controls redraws the control, even when the text has
- * has not changed. The fix is to check for this case and do
- * nothing.
- */
- if (string.equals (text)) return;
- text = string;
- if (image == null || !IMAGE_AND_TEXT) {
- int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE), newBits = oldBits;
- newBits &= ~OS.SS_OWNERDRAW;
- if ((style & SWT.LEFT) != 0) {
- if ((style & SWT.WRAP) != 0) {
- newBits |= OS.SS_LEFT;
- } else {
- newBits |= OS.SS_LEFTNOWORDWRAP;
- }
- }
- if ((style & SWT.CENTER) != 0) newBits |= OS.SS_CENTER;
- if ((style & SWT.RIGHT) != 0) newBits |= OS.SS_RIGHT;
- if (oldBits != newBits) OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
- }
- string = Display.withCrLf (string);
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- OS.SetWindowText (handle, buffer);
- /*
- * Bug in Windows. For some reason, the HBRUSH that
- * is returned from WM_CTRLCOLOR is misaligned when
- * the label uses it to draw. If the brush is a solid
- * color, this does not matter. However, if the brush
- * contains an image, the image is misaligned. The
- * fix is to draw the background in WM_ERASEBKGND.
- */
- if (OS.COMCTL32_MAJOR < 6) {
- if (findImageControl () != null) OS.InvalidateRect (handle, null, true);
- }
-}
-
-int widgetExtStyle () {
- int bits = super.widgetExtStyle () & ~OS.WS_EX_CLIENTEDGE;
- if ((style & SWT.BORDER) != 0) return bits | OS.WS_EX_STATICEDGE;
- return bits;
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle () | OS.SS_NOTIFY;
- if ((style & SWT.SEPARATOR) != 0) return bits | OS.SS_OWNERDRAW;
- if (OS.WIN32_VERSION >= OS.VERSION (5, 0)) {
- if ((style & SWT.WRAP) != 0) bits |= OS.SS_EDITCONTROL;
- }
- if ((style & SWT.CENTER) != 0) return bits | OS.SS_CENTER;
- if ((style & SWT.RIGHT) != 0) return bits | OS.SS_RIGHT;
- if ((style & SWT.WRAP) != 0) return bits | OS.SS_LEFT;
- return bits | OS.SS_LEFTNOWORDWRAP;
-}
-
-TCHAR windowClass () {
- return LabelClass;
-}
-
-int /*long*/ windowProc () {
- return LabelProc;
-}
-
-LRESULT WM_ERASEBKGND (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
- if (result != null) return result;
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.SS_OWNERDRAW) == OS.SS_OWNERDRAW) {
- return LRESULT.ONE;
- }
- /*
- * Bug in Windows. For some reason, the HBRUSH that
- * is returned from WM_CTRLCOLOR is misaligned when
- * the label uses it to draw. If the brush is a solid
- * color, this does not matter. However, if the brush
- * contains an image, the image is misaligned. The
- * fix is to draw the background in WM_ERASEBKGND.
- */
- if (OS.COMCTL32_MAJOR < 6) {
- if (findImageControl () != null) {
- drawBackground (wParam);
- return LRESULT.ONE;
- }
- }
- return result;
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SIZE (wParam, lParam);
- if (isDisposed ()) return result;
- if ((style & SWT.SEPARATOR) != 0) {
- OS.InvalidateRect (handle, null, true);
- return result;
- }
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.SS_OWNERDRAW) == OS.SS_OWNERDRAW) {
- OS.InvalidateRect (handle, null, true);
- return result;
- }
- /*
- * Bug in Windows. For some reason, a label with
- * style SS_LEFT, SS_CENTER or SS_RIGHT does not
- * redraw the text in the new position when resized.
- * Note that SS_LEFTNOWORDWRAP does not have the
- * problem. The fix is to force the redraw.
- */
- if ((bits & OS.SS_LEFTNOWORDWRAP) != OS.SS_LEFTNOWORDWRAP) {
- OS.InvalidateRect (handle, null, true);
- return result;
- }
- return result;
-}
-
-LRESULT WM_UPDATEUISTATE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_UPDATEUISTATE (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. When WM_UPDATEUISTATE is sent to
- * a static control, it sends WM_CTLCOLORSTATIC to get the
- * foreground and background. If any drawing happens in
- * WM_CTLCOLORSTATIC, it overwrites the contents of the control.
- * The fix is draw the static without drawing the background
- * and avoid the static window proc.
- */
- boolean redraw = findImageControl () != null;
- if (!redraw) {
- if ((state & THEME_BACKGROUND) != 0) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- redraw = findThemeControl () != null;
- }
- }
- }
- if (redraw) {
- OS.InvalidateRect (handle, null, false);
- int /*long*/ code = OS.DefWindowProc (handle, OS.WM_UPDATEUISTATE, wParam, lParam);
- return new LRESULT (code);
- }
- return result;
-}
-
-LRESULT wmColorChild (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Bug in Windows. For some reason, the HBRUSH that
- * is returned from WM_CTRLCOLOR is misaligned when
- * the label uses it to draw. If the brush is a solid
- * color, this does not matter. However, if the brush
- * contains an image, the image is misaligned. The
- * fix is to draw the background in WM_ERASEBKGND.
- */
- LRESULT result = super.wmColorChild (wParam, lParam);
- if (OS.COMCTL32_MAJOR < 6) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.SS_OWNERDRAW) != OS.SS_OWNERDRAW) {
- if (findImageControl () != null) {
- OS.SetBkMode (wParam, OS.TRANSPARENT);
- return new LRESULT (OS.GetStockObject (OS.NULL_BRUSH));
- }
- }
- }
- return result;
-}
-
-LRESULT WM_PAINT (int /*long*/ wParam, int /*long*/ lParam) {
- if (OS.IsWinCE) {
- boolean drawImage = image != null;
- boolean drawSeparator = (style & SWT.SEPARATOR) != 0 && (style & SWT.SHADOW_NONE) == 0;
- if (drawImage || drawSeparator) {
- LRESULT result = null;
- PAINTSTRUCT ps = new PAINTSTRUCT ();
- GCData data = new GCData ();
- data.ps = ps;
- data.hwnd = handle;
- GC gc = new_GC (data);
- if (gc != null) {
- drawBackground (gc.handle);
- RECT clientRect = new RECT();
- OS.GetClientRect (handle, clientRect);
- if (drawSeparator) {
- RECT rect = new RECT ();
- int lineWidth = OS.GetSystemMetrics (OS.SM_CXBORDER);
- int flags = (style & SWT.SHADOW_IN) != 0 ? OS.EDGE_SUNKEN : OS.EDGE_ETCHED;
- if ((style & SWT.HORIZONTAL) != 0) {
- int bottom = clientRect.top + Math.max (lineWidth * 2, (clientRect.bottom - clientRect.top) / 2);
- OS.SetRect (rect, clientRect.left, clientRect.top, clientRect.right, bottom);
- OS.DrawEdge (gc.handle, rect, flags, OS.BF_BOTTOM);
- } else {
- int right = clientRect.left + Math.max (lineWidth * 2, (clientRect.right - clientRect.left) / 2);
- OS.SetRect (rect, clientRect.left, clientRect.top, right, clientRect.bottom);
- OS.DrawEdge (gc.handle, rect, flags, OS.BF_RIGHT);
- }
- result = LRESULT.ONE;
- }
- if (drawImage) {
- Rectangle imageBounds = image.getBounds ();
- int x = 0;
- if ((style & SWT.CENTER) != 0) {
- x = Math.max (0, (clientRect.right - imageBounds.width) / 2);
- } else {
- if ((style & SWT.RIGHT) != 0) {
- x = Math.max (0, (clientRect.right - imageBounds.width));
- }
- }
- gc.drawImage (image, x, Math.max (0, (clientRect.bottom - imageBounds.height) / 2));
- result = LRESULT.ONE;
- }
- int width = ps.right - ps.left;
- int height = ps.bottom - ps.top;
- if (width != 0 && height != 0) {
- Event event = new Event ();
- event.gc = gc;
- event.x = ps.left;
- event.y = ps.top;
- event.width = width;
- event.height = height;
- sendEvent (SWT.Paint, event);
- // widget could be disposed at this point
- event.gc = null;
- }
- gc.dispose ();
- }
- return result;
- }
- }
- return super.WM_PAINT(wParam, lParam);
-}
-
-LRESULT wmDrawChild (int /*long*/ wParam, int /*long*/ lParam) {
- DRAWITEMSTRUCT struct = new DRAWITEMSTRUCT ();
- OS.MoveMemory (struct, lParam, DRAWITEMSTRUCT.sizeof);
- drawBackground (struct.hDC);
- if ((style & SWT.SEPARATOR) != 0) {
- if ((style & SWT.SHADOW_NONE) != 0) return null;
- RECT rect = new RECT ();
- int lineWidth = OS.GetSystemMetrics (OS.SM_CXBORDER);
- int flags = (style & SWT.SHADOW_IN) != 0 ? OS.EDGE_SUNKEN : OS.EDGE_ETCHED;
- if ((style & SWT.HORIZONTAL) != 0) {
- int bottom = struct.top + Math.max (lineWidth * 2, (struct.bottom - struct.top) / 2);
- OS.SetRect (rect, struct.left, struct.top, struct.right, bottom);
- OS.DrawEdge (struct.hDC, rect, flags, OS.BF_BOTTOM);
- } else {
- int right = struct.left + Math.max (lineWidth * 2, (struct.right - struct.left) / 2);
- OS.SetRect (rect, struct.left, struct.top, right, struct.bottom);
- OS.DrawEdge (struct.hDC, rect, flags, OS.BF_RIGHT);
- }
- } else {
- int width = struct.right - struct.left;
- int height = struct.bottom - struct.top;
- if (width != 0 && height != 0) {
- boolean drawImage = image != null;
- boolean drawText = IMAGE_AND_TEXT && text.length () != 0;
- int margin = drawText && drawImage ? MARGIN : 0;
- int imageWidth = 0, imageHeight = 0;
- if (drawImage) {
- Rectangle rect = image.getBounds ();
- imageWidth = rect.width;
- imageHeight = rect.height;
- }
- RECT rect = null;
- TCHAR buffer = null;
- int textWidth = 0, textHeight = 0, flags = 0;
- if (drawText) {
- rect = new RECT ();
- flags = OS.DT_CALCRECT | OS.DT_EDITCONTROL | OS.DT_EXPANDTABS;
- if ((style & SWT.LEFT) != 0) flags |= OS.DT_LEFT;
- if ((style & SWT.CENTER) != 0) flags |= OS.DT_CENTER;
- if ((style & SWT.RIGHT) != 0) flags |= OS.DT_RIGHT;
- if ((style & SWT.WRAP) != 0) {
- flags |= OS.DT_WORDBREAK;
- rect.right = Math.max (0, width - imageWidth - margin);
- }
- buffer = new TCHAR (getCodePage (), text, true);
- OS.DrawText (struct.hDC, buffer, -1, rect, flags);
- textWidth = rect.right - rect.left;
- textHeight = rect.bottom - rect.top;
- }
- int x = 0;
- if ((style & SWT.CENTER) != 0) {
- x = Math.max (0, (width - imageWidth - textWidth - margin) / 2);
- } else {
- if ((style & SWT.RIGHT) != 0) {
- x = width - imageWidth - textWidth - margin;
- }
- }
- if (drawImage) {
- GCData data = new GCData();
- data.device = display;
- GC gc = GC.win32_new (struct.hDC, data);
- Image image = getEnabled () ? this.image : new Image (display, this.image, SWT.IMAGE_DISABLE);
- gc.drawImage (image, x, Math.max (0, (height - imageHeight) / 2));
- if (image != this.image) image.dispose ();
- gc.dispose ();
- x += imageWidth + margin;
- }
- if (drawText) {
- flags &= ~OS.DT_CALCRECT;
- rect.left = x;
- rect.right += rect.left;
- rect.top = Math.max (0, (height - textHeight) / 2);
- rect.bottom += rect.top;
- OS.DrawText (struct.hDC, buffer, -1, rect, flags);
- }
- }
- }
- return null;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Link.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Link.java
deleted file mode 100644
index bf0d12ea71..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Link.java
+++ /dev/null
@@ -1,1010 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.accessibility.*;
-
-/**
- * Instances of this class represent a selectable
- * user interface object that displays a text with
- * links.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#link">Link snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Link extends Control {
- String text;
- TextLayout layout;
- Color linkColor, disabledColor;
- Point [] offsets;
- Point selection;
- String [] ids;
- int [] mnemonics;
- int focusIndex, mouseDownIndex;
- int /*long*/ font;
- static final RGB LINK_FOREGROUND = new RGB (0, 51, 153);
- static final int /*long*/ LinkProc;
- static final TCHAR LinkClass = new TCHAR (0, OS.WC_LINK, true);
- static {
- if (OS.COMCTL32_MAJOR >= 6) {
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, LinkClass, lpWndClass);
- LinkProc = lpWndClass.lpfnWndProc;
- /*
- * Feature in Windows. The SysLink window class
- * does not include CS_DBLCLKS. This means that these
- * controls will not get double click messages such as
- * WM_LBUTTONDBLCLK. The fix is to register a new
- * window class with CS_DBLCLKS.
- *
- * NOTE: Screen readers look for the exact class name
- * of the control in order to provide the correct kind
- * of assistance. Therefore, it is critical that the
- * new window class have the same name. It is possible
- * to register a local window class with the same name
- * as a global class. Since bits that affect the class
- * are being changed, it is possible that other native
- * code, other than SWT, could create a control with
- * this class name, and fail unexpectedly.
- */
- int /*long*/ hInstance = OS.GetModuleHandle (null);
- int /*long*/ hHeap = OS.GetProcessHeap ();
- lpWndClass.hInstance = hInstance;
- lpWndClass.style &= ~OS.CS_GLOBALCLASS;
- lpWndClass.style |= OS.CS_DBLCLKS;
- int byteCount = LinkClass.length () * TCHAR.sizeof;
- int /*long*/ lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (lpszClassName, LinkClass, byteCount);
- lpWndClass.lpszClassName = lpszClassName;
- OS.RegisterClass (lpWndClass);
- OS.HeapFree (hHeap, 0, lpszClassName);
- } else {
- LinkProc = 0;
- }
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Link (Composite parent, int style) {
- super (parent, style);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected by the user.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- if (LinkProc != 0) {
- /*
- * Feature in Windows. By convention, native Windows controls
- * check for a non-NULL wParam, assume that it is an HDC and
- * paint using that device. The SysLink control does not.
- * The fix is to check for an HDC and use WM_PRINTCLIENT.
- */
- switch (msg) {
- case OS.WM_PAINT:
- if (wParam != 0) {
- OS.SendMessage (hwnd, OS.WM_PRINTCLIENT, wParam, 0);
- return 0;
- }
- break;
- }
- return OS.CallWindowProc (LinkProc, hwnd, msg, wParam, lParam);
- }
- return OS.DefWindowProc (hwnd, msg, wParam, lParam);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
- if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- int width, height;
- if (OS.COMCTL32_MAJOR >= 6) {
- int /*long*/ hDC = OS.GetDC (handle);
- int /*long*/ newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- int /*long*/ oldFont = OS.SelectObject (hDC, newFont);
- if (text.length () > 0) {
- TCHAR buffer = new TCHAR (getCodePage (), parse (text), false);
- RECT rect = new RECT ();
- int flags = OS.DT_CALCRECT | OS.DT_NOPREFIX;
- if (wHint != SWT.DEFAULT) {
- flags |= OS.DT_WORDBREAK;
- rect.right = wHint;
- }
- OS.DrawText (hDC, buffer, buffer.length (), rect, flags);
- width = rect.right - rect.left;
- height = rect.bottom;
- } else {
- TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW () : new TEXTMETRICA ();
- OS.GetTextMetrics (hDC, lptm);
- width = 0;
- height = lptm.tmHeight;
- }
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- } else {
- int layoutWidth = layout.getWidth ();
- //TEMPORARY CODE
- if (wHint == 0) {
- layout.setWidth (1);
- Rectangle rect = layout.getBounds ();
- width = 0;
- height = rect.height;
- } else {
- layout.setWidth (wHint);
- Rectangle rect = layout.getBounds ();
- width = rect.width;
- height = rect.height;
- }
- layout.setWidth (layoutWidth);
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2;
- height += border * 2;
- return new Point (width, height);
-}
-
-void createHandle () {
- super.createHandle ();
- state |= THEME_BACKGROUND;
- if (OS.COMCTL32_MAJOR < 6) {
- layout = new TextLayout (display);
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- linkColor = Color.win32_new (display, OS.GetSysColor (OS.COLOR_HOTLIGHT));
- } else {
- linkColor = new Color (display, LINK_FOREGROUND);
- }
- disabledColor = Color.win32_new (display, OS.GetSysColor (OS.COLOR_GRAYTEXT));
- offsets = new Point [0];
- ids = new String [0];
- mnemonics = new int [0];
- selection = new Point (-1, -1);
- focusIndex = mouseDownIndex = -1;
- }
-}
-
-void createWidget () {
- super.createWidget ();
- text = "";
- if (OS.COMCTL32_MAJOR < 6) {
- if ((style & SWT.MIRRORED) != 0) {
- layout.setOrientation (SWT.RIGHT_TO_LEFT);
- }
- initAccessible ();
- }
-}
-
-void drawWidget (GC gc, RECT rect) {
- drawBackground (gc.handle, rect);
- int selStart = selection.x;
- int selEnd = selection.y;
- if (selStart > selEnd) {
- selStart = selection.y;
- selEnd = selection.x;
- }
- // temporary code to disable text selection
- selStart = selEnd = -1;
- if (!OS.IsWindowEnabled (handle)) gc.setForeground (disabledColor);
- layout.draw (gc, 0, 0, selStart, selEnd, null, null);
- if (hasFocus () && focusIndex != -1) {
- Rectangle [] rects = getRectangles (focusIndex);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rectangle = rects [i];
- gc.drawFocus (rectangle.x, rectangle.y, rectangle.width, rectangle.height);
- }
- }
- if (hooks (SWT.Paint) || filters (SWT.Paint)) {
- Event event = new Event ();
- event.gc = gc;
- event.x = rect.left;
- event.y = rect.top;
- event.width = rect.right - rect.left;
- event.height = rect.bottom - rect.top;
- sendEvent (SWT.Paint, event);
- event.gc = null;
- }
-}
-
-void enableWidget (boolean enabled) {
- if (OS.COMCTL32_MAJOR >= 6) {
- LITEM item = new LITEM ();
- item.mask = OS.LIF_ITEMINDEX | OS.LIF_STATE;
- item.stateMask = OS.LIS_ENABLED;
- item.state = enabled ? OS.LIS_ENABLED : 0;
- while (OS.SendMessage (handle, OS.LM_SETITEM, 0, item) != 0) {
- item.iLink++;
- }
- } else {
- TextStyle linkStyle = new TextStyle (null, enabled ? linkColor : disabledColor, null);
- linkStyle.underline = true;
- for (int i = 0; i < offsets.length; i++) {
- Point point = offsets [i];
- layout.setStyle (linkStyle, point.x, point.y);
- }
- redraw ();
- }
- /*
- * Feature in Windows. For some reason, setting
- * LIS_ENABLED state using LM_SETITEM causes the
- * SysLink to become enabled. To be specific,
- * calling IsWindowEnabled() returns true. The
- * fix is disable the SysLink after LM_SETITEM.
- */
- super.enableWidget (enabled);
-}
-
-void initAccessible () {
- Accessible accessible = getAccessible ();
- accessible.addAccessibleListener (new AccessibleAdapter () {
- public void getName (AccessibleEvent e) {
- e.result = parse (text);
- }
- });
-
- accessible.addAccessibleControlListener (new AccessibleControlAdapter () {
- public void getChildAtPoint (AccessibleControlEvent e) {
- e.childID = ACC.CHILDID_SELF;
- }
-
- public void getLocation (AccessibleControlEvent e) {
- Rectangle rect = display.map (getParent (), null, getBounds ());
- e.x = rect.x;
- e.y = rect.y;
- e.width = rect.width;
- e.height = rect.height;
- }
-
- public void getChildCount (AccessibleControlEvent e) {
- e.detail = 0;
- }
-
- public void getRole (AccessibleControlEvent e) {
- e.detail = ACC.ROLE_LINK;
- }
-
- public void getState (AccessibleControlEvent e) {
- e.detail = ACC.STATE_FOCUSABLE;
- if (hasFocus ()) e.detail |= ACC.STATE_FOCUSED;
- }
-
- public void getDefaultAction (AccessibleControlEvent e) {
- e.result = SWT.getMessage ("SWT_Press"); //$NON-NLS-1$
- }
-
- public void getSelection (AccessibleControlEvent e) {
- if (hasFocus ()) e.childID = ACC.CHILDID_SELF;
- }
-
- public void getFocus (AccessibleControlEvent e) {
- if (hasFocus ()) e.childID = ACC.CHILDID_SELF;
- }
- });
-}
-
-String getNameText () {
- return getText ();
-}
-
-Rectangle [] getRectangles (int linkIndex) {
- int lineCount = layout.getLineCount ();
- Rectangle [] rects = new Rectangle [lineCount];
- int [] lineOffsets = layout.getLineOffsets ();
- Point point = offsets [linkIndex];
- int lineStart = 1;
- while (point.x > lineOffsets [lineStart]) lineStart++;
- int lineEnd = 1;
- while (point.y > lineOffsets [lineEnd]) lineEnd++;
- int index = 0;
- if (lineStart == lineEnd) {
- rects [index++] = layout.getBounds (point.x, point.y);
- } else {
- rects [index++] = layout.getBounds (point.x, lineOffsets [lineStart]-1);
- rects [index++] = layout.getBounds (lineOffsets [lineEnd-1], point.y);
- if (lineEnd - lineStart > 1) {
- for (int i = lineStart; i < lineEnd - 1; i++) {
- rects [index++] = layout.getLineBounds (i);
- }
- }
- }
- if (rects.length != index) {
- Rectangle [] tmp = new Rectangle [index];
- System.arraycopy (rects, 0, tmp, 0, index);
- rects = tmp;
- }
- return rects;
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-String parse (String string) {
- int length = string.length ();
- offsets = new Point [length / 4];
- ids = new String [length / 4];
- mnemonics = new int [length / 4 + 1];
- StringBuffer result = new StringBuffer ();
- char [] buffer = new char [length];
- string.getChars (0, string.length (), buffer, 0);
- int index = 0, state = 0, linkIndex = 0;
- int start = 0, tagStart = 0, linkStart = 0, endtagStart = 0, refStart = 0;
- while (index < length) {
- char c = Character.toLowerCase (buffer [index]);
- switch (state) {
- case 0:
- if (c == '<') {
- tagStart = index;
- state++;
- }
- break;
- case 1:
- if (c == 'a') state++;
- break;
- case 2:
- switch (c) {
- case 'h':
- state = 7;
- break;
- case '>':
- linkStart = index + 1;
- state++;
- break;
- default:
- if (Character.isWhitespace(c)) break;
- else state = 13;
- }
- break;
- case 3:
- if (c == '<') {
- endtagStart = index;
- state++;
- }
- break;
- case 4:
- state = c == '/' ? state + 1 : 3;
- break;
- case 5:
- state = c == 'a' ? state + 1 : 3;
- break;
- case 6:
- if (c == '>') {
- mnemonics [linkIndex] = parseMnemonics (buffer, start, tagStart, result);
- int offset = result.length ();
- parseMnemonics (buffer, linkStart, endtagStart, result);
- offsets [linkIndex] = new Point (offset, result.length () - 1);
- if (ids [linkIndex] == null) {
- ids [linkIndex] = new String (buffer, linkStart, endtagStart - linkStart);
- }
- linkIndex++;
- start = tagStart = linkStart = endtagStart = refStart = index + 1;
- state = 0;
- } else {
- state = 3;
- }
- break;
- case 7:
- state = c == 'r' ? state + 1 : 0;
- break;
- case 8:
- state = c == 'e' ? state + 1 : 0;
- break;
- case 9:
- state = c == 'f' ? state + 1 : 0;
- break;
- case 10:
- state = c == '=' ? state + 1 : 0;
- break;
- case 11:
- if (c == '"') {
- state++;
- refStart = index + 1;
- } else {
- state = 0;
- }
- break;
- case 12:
- if (c == '"') {
- ids[linkIndex] = new String (buffer, refStart, index - refStart);
- state = 2;
- }
- break;
- case 13:
- if (Character.isWhitespace (c)) {
- state = 0;
- } else if (c == '='){
- state++;
- }
- break;
- case 14:
- state = c == '"' ? state + 1 : 0;
- break;
- case 15:
- if (c == '"') state = 2;
- break;
- default:
- state = 0;
- break;
- }
- index++;
- }
- if (start < length) {
- int tmp = parseMnemonics (buffer, start, tagStart, result);
- int mnemonic = parseMnemonics (buffer, Math.max (tagStart, linkStart), length, result);
- if (mnemonic == -1) mnemonic = tmp;
- mnemonics [linkIndex] = mnemonic;
- } else {
- mnemonics [linkIndex] = -1;
- }
- if (offsets.length != linkIndex) {
- Point [] newOffsets = new Point [linkIndex];
- System.arraycopy (offsets, 0, newOffsets, 0, linkIndex);
- offsets = newOffsets;
- String [] newIDs = new String [linkIndex];
- System.arraycopy (ids, 0, newIDs, 0, linkIndex);
- ids = newIDs;
- int [] newMnemonics = new int [linkIndex + 1];
- System.arraycopy (mnemonics, 0, newMnemonics, 0, linkIndex + 1);
- mnemonics = newMnemonics;
- }
- return result.toString ();
-}
-
-int parseMnemonics (char[] buffer, int start, int end, StringBuffer result) {
- int mnemonic = -1, index = start;
- while (index < end) {
- if (buffer [index] == '&') {
- if (index + 1 < end && buffer [index + 1] == '&') {
- result.append (buffer [index]);
- index++;
- } else {
- mnemonic = result.length();
- }
- } else {
- result.append (buffer [index]);
- }
- index++;
- }
- return mnemonic;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (layout != null) layout.dispose ();
- layout = null;
- if (linkColor != null) linkColor.dispose ();
- linkColor = null;
- disabledColor = null;
- offsets = null;
- ids = null;
- mnemonics = null;
- text = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection, listener);
-}
-
-/**
- * Sets the receiver's text.
- * <p>
- * The string can contain both regular text and hyperlinks. A hyperlink
- * is delimited by an anchor tag, &lt;A&gt; and &lt;/A&gt;. Within an
- * anchor, a single HREF attribute is supported. When a hyperlink is
- * selected, the text field of the selection event contains either the
- * text of the hyperlink or the value of its HREF, if one was specified.
- * In the rare case of identical hyperlinks within the same string, the
- * HREF attribute can be used to distinguish between them. The string may
- * include the mnemonic character and line delimiters. The only delimiter
- * the HREF attribute supports is the quotation mark (").
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (string.equals (text)) return;
- text = string;
- if (OS.COMCTL32_MAJOR >= 6) {
- boolean enabled = OS.IsWindowEnabled (handle);
- /*
- * Bug in Windows. For some reason, when SetWindowText()
- * is used to set the text of a link control to the empty
- * string, the old text remains. The fix is to set the
- * text to a space instead.
- */
- if (string.length () == 0) string = " "; //$NON-NLS-1$
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- OS.SetWindowText (handle, buffer);
- parse (text);
- enableWidget (enabled);
- } else {
- layout.setText (parse (text));
- focusIndex = offsets.length > 0 ? 0 : -1;
- selection.x = selection.y = -1;
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if (offsets.length > 0) {
- bits |= OS.WS_TABSTOP;
- } else {
- bits &= ~OS.WS_TABSTOP;
- }
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- boolean enabled = OS.IsWindowEnabled (handle);
- TextStyle linkStyle = new TextStyle (null, enabled ? linkColor : disabledColor, null);
- linkStyle.underline = true;
- for (int i = 0; i < offsets.length; i++) {
- Point point = offsets [i];
- layout.setStyle (linkStyle, point.x, point.y);
- }
- TextStyle mnemonicStyle = new TextStyle (null, null, null);
- mnemonicStyle.underline = true;
- for (int i = 0; i < mnemonics.length; i++) {
- int mnemonic = mnemonics [i];
- if (mnemonic != -1) {
- layout.setStyle (mnemonicStyle, mnemonic, mnemonic);
- }
- }
- redraw ();
- }
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle ();
- return bits | OS.WS_TABSTOP;
-}
-
-TCHAR windowClass () {
- return OS.COMCTL32_MAJOR >= 6 ? LinkClass : display.windowClass;
-}
-
-int /*long*/ windowProc () {
- return LinkProc != 0 ? LinkProc : display.windowProc;
-}
-
-LRESULT WM_CHAR (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_CHAR (wParam, lParam);
- if (result != null) return result;
- if (OS.COMCTL32_MAJOR < 6) {
- if (focusIndex == -1) return result;
- switch ((int)/*64*/wParam) {
- case ' ':
- case SWT.CR:
- Event event = new Event ();
- event.text = ids [focusIndex];
- sendEvent (SWT.Selection, event);
- break;
- case SWT.TAB:
- boolean next = OS.GetKeyState (OS.VK_SHIFT) >= 0;
- if (next) {
- if (focusIndex < offsets.length - 1) {
- focusIndex++;
- redraw ();
- }
- } else {
- if (focusIndex > 0) {
- focusIndex--;
- redraw ();
- }
- }
- break;
- }
- } else {
- switch ((int)/*64*/wParam) {
- case ' ':
- case SWT.CR:
- case SWT.TAB:
- /*
- * NOTE: Call the window proc with WM_KEYDOWN rather than WM_CHAR
- * so that the key that was ignored during WM_KEYDOWN is processed.
- * This allows the application to cancel an operation that is normally
- * performed in WM_KEYDOWN from WM_CHAR.
- */
- int /*long*/ code = callWindowProc (handle, OS.WM_KEYDOWN, wParam, lParam);
- return new LRESULT (code);
- }
-
- }
- return result;
-}
-
-LRESULT WM_GETDLGCODE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_GETDLGCODE (wParam, lParam);
- if (result != null) return result;
- int index, count;
- int /*long*/ code = 0;
- if (OS.COMCTL32_MAJOR >= 6) {
- LITEM item = new LITEM ();
- item.mask = OS.LIF_ITEMINDEX | OS.LIF_STATE;
- item.stateMask = OS.LIS_FOCUSED;
- index = 0;
- while (OS.SendMessage (handle, OS.LM_GETITEM, 0, item) != 0) {
- if ((item.state & OS.LIS_FOCUSED) != 0) {
- index = item.iLink;
- }
- item.iLink++;
- }
- count = item.iLink;
- code = callWindowProc (handle, OS.WM_GETDLGCODE, wParam, lParam);
- } else {
- index = focusIndex;
- count = offsets.length;
- }
- if (count == 0) {
- return new LRESULT (code | OS.DLGC_STATIC);
- }
- boolean next = OS.GetKeyState (OS.VK_SHIFT) >= 0;
- if (next && index < count - 1) {
- return new LRESULT (code | OS.DLGC_WANTTAB);
- }
- if (!next && index > 0) {
- return new LRESULT (code | OS.DLGC_WANTTAB);
- }
- return result;
-}
-
-LRESULT WM_GETFONT (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_GETFONT (wParam, lParam);
- if (result != null) return result;
- int /*long*/ code = callWindowProc (handle, OS.WM_GETFONT, wParam, lParam);
- if (code != 0) return new LRESULT (code);
- if (font == 0) font = defaultFont ();
- return new LRESULT (font);
-}
-
-LRESULT WM_KEYDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_KEYDOWN (wParam, lParam);
- if (result != null) return result;
- if (OS.COMCTL32_MAJOR >= 6) {
- switch ((int)/*64*/wParam) {
- case OS.VK_SPACE:
- case OS.VK_RETURN:
- case OS.VK_TAB:
- /*
- * Ensure that the window proc does not process VK_SPACE,
- * VK_RETURN or VK_TAB so that it can be handled in WM_CHAR.
- * This allows the application to cancel an operation that
- * is normally performed in WM_KEYDOWN from WM_CHAR.
- */
- return LRESULT.ZERO;
- }
- }
- return result;
-}
-
-LRESULT WM_KILLFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_KILLFOCUS (wParam, lParam);
- if (OS.COMCTL32_MAJOR < 6) redraw ();
- return result;
-}
-
-LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_LBUTTONDOWN (wParam, lParam);
- if (result == LRESULT.ZERO) return result;
- if (OS.COMCTL32_MAJOR < 6) {
- if (focusIndex != -1) setFocus ();
- int x = OS.GET_X_LPARAM (lParam);
- int y = OS.GET_Y_LPARAM (lParam);
- int offset = layout.getOffset (x, y, null);
- int oldSelectionX = selection.x;
- int oldSelectionY = selection.y;
- selection.x = offset;
- selection.y = -1;
- if (oldSelectionX != -1 && oldSelectionY != -1) {
- if (oldSelectionX > oldSelectionY) {
- int temp = oldSelectionX;
- oldSelectionX = oldSelectionY;
- oldSelectionY = temp;
- }
- Rectangle rect = layout.getBounds (oldSelectionX, oldSelectionY);
- redraw (rect.x, rect.y, rect.width, rect.height, false);
- }
- for (int j = 0; j < offsets.length; j++) {
- Rectangle [] rects = getRectangles (j);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rect = rects [i];
- if (rect.contains (x, y)) {
- if (j != focusIndex) {
- redraw ();
- }
- focusIndex = mouseDownIndex = j;
- return result;
- }
- }
- }
- }
- return result;
-}
-
-LRESULT WM_LBUTTONUP (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_LBUTTONUP (wParam, lParam);
- if (result == LRESULT.ZERO) return result;
- if (OS.COMCTL32_MAJOR < 6) {
- if (mouseDownIndex == -1) return result;
- int x = OS.GET_X_LPARAM (lParam);
- int y = OS.GET_Y_LPARAM (lParam);
- Rectangle [] rects = getRectangles (mouseDownIndex);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rect = rects [i];
- if (rect.contains (x, y)) {
- Event event = new Event ();
- event.text = ids [mouseDownIndex];
- sendEvent (SWT.Selection, event);
- break;
- }
- }
- }
- mouseDownIndex = -1;
- return result;
-}
-
-LRESULT WM_NCHITTEST (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_NCHITTEST (wParam, lParam);
- if (result != null) return result;
-
- /*
- * Feature in Windows. For WM_NCHITTEST, the Syslink window proc
- * returns HTTRANSPARENT when mouse is over plain text. The fix is
- * to always return HTCLIENT.
- */
- if (OS.COMCTL32_MAJOR >= 6) return new LRESULT (OS.HTCLIENT);
-
- return result;
-}
-
-LRESULT WM_MOUSEMOVE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_MOUSEMOVE (wParam, lParam);
- if (OS.COMCTL32_MAJOR < 6) {
- int x = OS.GET_X_LPARAM (lParam);
- int y = OS.GET_Y_LPARAM (lParam);
- if (OS.GetKeyState (OS.VK_LBUTTON) < 0) {
- int oldSelection = selection.y;
- selection.y = layout.getOffset (x, y, null);
- if (selection.y != oldSelection) {
- int newSelection = selection.y;
- if (oldSelection > newSelection) {
- int temp = oldSelection;
- oldSelection = newSelection;
- newSelection = temp;
- }
- Rectangle rect = layout.getBounds (oldSelection, newSelection);
- redraw (rect.x, rect.y, rect.width, rect.height, false);
- }
- } else {
- for (int j = 0; j < offsets.length; j++) {
- Rectangle [] rects = getRectangles (j);
- for (int i = 0; i < rects.length; i++) {
- Rectangle rect = rects [i];
- if (rect.contains (x, y)) {
- setCursor (display.getSystemCursor (SWT.CURSOR_HAND));
- return result;
- }
- }
- }
- setCursor (null);
- }
- }
- return result;
-}
-
-LRESULT WM_PAINT (int /*long*/ wParam, int /*long*/ lParam) {
- if (OS.COMCTL32_MAJOR >= 6) {
- return super.WM_PAINT (wParam, lParam);
- }
- PAINTSTRUCT ps = new PAINTSTRUCT ();
- GCData data = new GCData ();
- data.ps = ps;
- data.hwnd = handle;
- GC gc = new_GC (data);
- if (gc != null) {
- int width = ps.right - ps.left;
- int height = ps.bottom - ps.top;
- if (width != 0 && height != 0) {
- RECT rect = new RECT ();
- OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
- drawWidget (gc, rect);
- }
- gc.dispose ();
- }
- return LRESULT.ZERO;
-}
-
-LRESULT WM_PRINTCLIENT (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_PRINTCLIENT (wParam, lParam);
- if (OS.COMCTL32_MAJOR < 6) {
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- GCData data = new GCData ();
- data.device = display;
- data.foreground = getForegroundPixel ();
- GC gc = GC.win32_new (wParam, data);
- drawWidget (gc, rect);
- gc.dispose ();
- }
- return result;
-}
-
-LRESULT WM_SETFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SETFOCUS (wParam, lParam);
- if (OS.COMCTL32_MAJOR < 6) redraw ();
- return result;
-}
-
-LRESULT WM_SETFONT (int /*long*/ wParam, int /*long*/ lParam) {
- if (OS.COMCTL32_MAJOR < 6) {
- layout.setFont (Font.win32_new (display, wParam));
- }
- if (lParam != 0) OS.InvalidateRect (handle, null, true);
- return super.WM_SETFONT (font = wParam, lParam);
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SIZE (wParam, lParam);
- if (OS.COMCTL32_MAJOR < 6) {
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- layout.setWidth (rect.right > 0 ? rect.right : -1);
- redraw ();
- }
- return result;
-}
-
-LRESULT wmColorChild (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.wmColorChild (wParam, lParam);
- /*
- * Feature in Windows. When a SysLink is disabled, it does
- * not gray out the non-link portion of the text. The fix
- * is to set the text color to the system gray color.
- */
- if (OS.COMCTL32_MAJOR >= 6) {
- if (!OS.IsWindowEnabled (handle)) {
- OS.SetTextColor (wParam, OS.GetSysColor (OS.COLOR_GRAYTEXT));
- if (result == null) {
- int backPixel = getBackgroundPixel ();
- OS.SetBkColor (wParam, backPixel);
- int /*long*/ hBrush = findBrush (backPixel, OS.BS_SOLID);
- return new LRESULT (hBrush);
- }
- }
- }
- return result;
-}
-
-LRESULT wmNotifyChild (NMHDR hdr, int /*long*/ wParam, int /*long*/ lParam) {
- if (OS.COMCTL32_MAJOR >= 6) {
- switch (hdr.code) {
- case OS.NM_RETURN:
- case OS.NM_CLICK:
- NMLINK item = new NMLINK ();
- OS.MoveMemory (item, lParam, NMLINK.sizeof);
- Event event = new Event ();
- event.text = ids [item.iLink];
- sendEvent (SWT.Selection, event);
- break;
- }
- }
- return super.wmNotifyChild (hdr, wParam, lParam);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/List.java
deleted file mode 100755
index aecad23367..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/List.java
+++ /dev/null
@@ -1,1716 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface
- * object that displays a list of strings and issues notification
- * when a string is selected. A list may be single or multi select.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection</dd>
- * </dl>
- * <p>
- * Note: Only one of SINGLE and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#list">List snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class List extends Scrollable {
- static final int INSET = 3;
- static final int /*long*/ ListProc;
- static final TCHAR ListClass = new TCHAR (0, "LISTBOX", true);
- static {
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, ListClass, lpWndClass);
- ListProc = lpWndClass.lpfnWndProc;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public List (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-/**
- * Adds the argument to the end of the receiver's list.
- *
- * @param string the new item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String,int)
- */
-public void add (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_ADDSTRING, 0, buffer);
- if (result == OS.LB_ERR) error (SWT.ERROR_ITEM_NOT_ADDED);
- if (result == OS.LB_ERRSPACE) error (SWT.ERROR_ITEM_NOT_ADDED);
- if ((style & SWT.H_SCROLL) != 0) setScrollWidth (buffer, true);
-}
-/**
- * Adds the argument to the receiver's list at the given
- * zero-relative index.
- * <p>
- * Note: To add an item at the end of the list, use the
- * result of calling <code>getItemCount()</code> as the
- * index or use <code>add(String)</code>.
- * </p>
- *
- * @param string the new item
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String)
- */
-public void add (String string, int index) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (index == -1) error (SWT.ERROR_INVALID_RANGE);
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_INSERTSTRING, index, buffer);
- if (result == OS.LB_ERRSPACE) error (SWT.ERROR_ITEM_NOT_ADDED);
- if (result == OS.LB_ERR) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (0 <= index && index <= count) {
- error (SWT.ERROR_ITEM_NOT_ADDED);
- } else {
- error (SWT.ERROR_INVALID_RANGE);
- }
- }
- if ((style & SWT.H_SCROLL) != 0) setScrollWidth (buffer, true);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the selection changes.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- boolean redraw = false;
- switch (msg) {
- case OS.WM_HSCROLL:
- case OS.WM_VSCROLL: {
- redraw = findImageControl () != null && getDrawing() && OS.IsWindowVisible (handle);
- if (redraw) OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- break;
- }
- }
- int /*long*/ code = OS.CallWindowProc (ListProc, hwnd, msg, wParam, lParam);
- switch (msg) {
- case OS.WM_HSCROLL:
- case OS.WM_VSCROLL: {
- if (redraw) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.InvalidateRect (handle, null, true);
- }
- break;
- }
- }
- return code;
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0;
- if (wHint == SWT.DEFAULT) {
- if ((style & SWT.H_SCROLL) != 0) {
- width = (int)/*64*/OS.SendMessage (handle, OS.LB_GETHORIZONTALEXTENT, 0, 0);
- width -= INSET;
- } else {
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- int /*long*/ newFont, oldFont = 0;
- int /*long*/ hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- RECT rect = new RECT ();
- int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX;
- int cp = getCodePage ();
- TCHAR buffer = new TCHAR (cp, 64 + 1);
- for (int i=0; i<count; i++) {
- int length = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTEXTLEN, i, 0);
- if (length != OS.LB_ERR) {
- if (length + 1 > buffer.length ()) {
- buffer = new TCHAR (cp, length + 1);
- }
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTEXT, i, buffer);
- if (result != OS.LB_ERR) {
- OS.DrawText (hDC, buffer, length, rect, flags);
- width = Math.max (width, rect.right - rect.left);
- }
- }
- }
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- }
- }
- if (hHint == SWT.DEFAULT) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- int itemHeight = (int)/*64*/OS.SendMessage (handle, OS.LB_GETITEMHEIGHT, 0, 0);
- height = count * itemHeight;
- }
- if (width == 0) width = DEFAULT_WIDTH;
- if (height == 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2 + INSET;
- height += border * 2;
- if ((style & SWT.V_SCROLL) != 0) {
- width += OS.GetSystemMetrics (OS.SM_CXVSCROLL);
- }
- if ((style & SWT.H_SCROLL) != 0) {
- height += OS.GetSystemMetrics (OS.SM_CYHSCROLL);
- }
- return new Point (width, height);
-}
-
-int defaultBackground () {
- return OS.GetSysColor (OS.COLOR_WINDOW);
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. Indices that are out
- * of range and duplicate indices are ignored.
- *
- * @param indices the array of indices for the items to deselect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- if ((style & SWT.SINGLE) != 0) {
- int oldIndex = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0);
- if (oldIndex == OS.LB_ERR) return;
- for (int i=0; i<indices.length; i++) {
- if (oldIndex == indices [i]) {
- OS.SendMessage (handle, OS.LB_SETCURSEL, -1, 0);
- return;
- }
- }
- return;
- }
- for (int i=0; i<indices.length; i++) {
- int index = indices [i];
- if (index != -1) {
- OS.SendMessage (handle, OS.LB_SETSEL, 0, index);
- }
- }
-}
-
-/**
- * Deselects the item at the given zero-relative index in the receiver.
- * If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget ();
- if (index == -1) return;
- if ((style & SWT.SINGLE) != 0) {
- int oldIndex = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0);
- if (oldIndex == OS.LB_ERR) return;
- if (oldIndex == index) OS.SendMessage (handle, OS.LB_SETCURSEL, -1, 0);
- return;
- }
- OS.SendMessage (handle, OS.LB_SETSEL, 0, index);
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. The range of the
- * indices is inclusive. Indices that are out of range are ignored.
- *
- * @param start the start index of the items to deselect
- * @param end the end index of the items to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int start, int end) {
- checkWidget ();
- if (start > end) return;
- if ((style & SWT.SINGLE) != 0) {
- int oldIndex = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0);
- if (oldIndex == OS.LB_ERR) return;
- if (start <= oldIndex && oldIndex <= end) {
- OS.SendMessage (handle, OS.LB_SETCURSEL, -1, 0);
- }
- return;
- }
- /*
- * Ensure that at least one item is contained in
- * the range from start to end. Note that when
- * start = end, LB_SELITEMRANGEEX deselects the
- * item.
- */
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (start < 0 && end < 0) return;
- if (start >= count && end >= count) return;
- start = Math.min (count - 1, Math.max (0, start));
- end = Math.min (count - 1, Math.max (0, end));
- OS.SendMessage (handle, OS.LB_SELITEMRANGEEX, end, start);
-}
-
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- OS.SendMessage (handle, OS.LB_SETCURSEL, -1, 0);
- } else {
- OS.SendMessage (handle, OS.LB_SETSEL, 0, -1);
- }
-}
-
-/**
- * Returns the zero-relative index of the item which currently
- * has the focus in the receiver, or -1 if no item has focus.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getFocusIndex () {
- checkWidget ();
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCARETINDEX, 0, 0);
- if (result == 0) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (count == 0) return -1;
- }
- return result;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getItem (int index) {
- checkWidget ();
- int length = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTEXTLEN, index, 0);
- if (length != OS.LB_ERR) {
- TCHAR buffer = new TCHAR (getCodePage (), length + 1);
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer);
- if (result != OS.LB_ERR) return buffer.toString (0, length);
- }
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (0 <= index && index < count) error (SWT.ERROR_CANNOT_GET_ITEM);
- error (SWT.ERROR_INVALID_RANGE);
- return "";
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (result == OS.LB_ERR) error (SWT.ERROR_CANNOT_GET_COUNT);
- return result;
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the list.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_GETITEMHEIGHT, 0, 0);
- if (result == OS.LB_ERR) error (SWT.ERROR_CANNOT_GET_ITEM_HEIGHT);
- return result;
-}
-
-/**
- * Returns a (possibly empty) array of <code>String</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver's list
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getItems () {
- checkWidget ();
- int count = getItemCount ();
- String [] result = new String [count];
- for (int i=0; i<count; i++) result [i] = getItem (i);
- return result;
-}
-
-/**
- * Returns an array of <code>String</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getSelection () {
- checkWidget ();
- int [] indices = getSelectionIndices ();
- String [] result = new String [indices.length];
- for (int i=0; i<indices.length; i++) {
- result [i] = getItem (indices [i]);
- }
- return result;
-}
-
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0);
- if (result == OS.LB_ERR) return 0;
- return 1;
- }
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_GETSELCOUNT, 0, 0);
- if (result == OS.LB_ERR) error (SWT.ERROR_CANNOT_GET_COUNT);
- return result;
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item or -1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- return (int)/*64*/OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0);
- }
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETSELCOUNT, 0, 0);
- if (count == OS.LB_ERR) error (SWT.ERROR_CANNOT_GET_SELECTION);
- if (count == 0) return -1;
- int index = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCARETINDEX, 0, 0);
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_GETSEL, index, 0);
- if (result == OS.LB_ERR) error (SWT.ERROR_CANNOT_GET_SELECTION);
- if (result != 0) return index;
- int [] buffer = new int[1];
- result = (int)/*64*/OS.SendMessage (handle, OS.LB_GETSELITEMS, 1, buffer);
- if (result != 1) error (SWT.ERROR_CANNOT_GET_SELECTION);
- return buffer [0];
-}
-
-/**
- * Returns the zero-relative indices of the items which are currently
- * selected in the receiver. The order of the indices is unspecified.
- * The array is empty if no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return the array of indices of the selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int [] getSelectionIndices () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0);
- if (result == OS.LB_ERR) return new int [0];
- return new int [] {result};
- }
- int length = (int)/*64*/OS.SendMessage (handle, OS.LB_GETSELCOUNT, 0, 0);
- if (length == OS.LB_ERR) error (SWT.ERROR_CANNOT_GET_SELECTION);
- int [] indices = new int [length];
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_GETSELITEMS, length, indices);
- if (result != length) error (SWT.ERROR_CANNOT_GET_SELECTION);
- return indices;
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items are
- * scrolled or new items are added or removed.
- *
- * @return the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0);
-}
-
-/**
- * Gets the index of an item.
- * <p>
- * The list is searched starting at 0 until an
- * item is found that is equal to the search item.
- * If no item is found, -1 is returned. Indexing
- * is zero based.
- *
- * @param string the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string) {
- return indexOf (string, 0);
-}
-
-/**
- * Searches the receiver's list starting at the given,
- * zero-relative index until an item is found that is equal
- * to the argument, and returns the index of that item. If
- * no item is found or the starting index is out of range,
- * returns -1.
- *
- * @param string the search item
- * @param start the zero-relative index at which to start the search
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string, int start) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
-
- /*
- * Bug in Windows. For some reason, LB_FINDSTRINGEXACT
- * will not find empty strings even though it is legal
- * to insert an empty string into a list. The fix is
- * to search the list, an item at a time.
- */
- if (string.length () == 0) {
- int count = getItemCount ();
- for (int i=start; i<count; i++) {
- if (string.equals (getItem (i))) return i;
- }
- return -1;
- }
-
- /* Use LB_FINDSTRINGEXACT to search for the item */
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (!(0 <= start && start < count)) return -1;
- int index = start - 1, last;
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- do {
- index = (int)/*64*/OS.SendMessage (handle, OS.LB_FINDSTRINGEXACT, last = index, buffer);
- if (index == OS.LB_ERR || index <= last) return -1;
- } while (!string.equals (getItem (index)));
- return index;
-}
-
-/**
- * Returns <code>true</code> if the item is selected,
- * and <code>false</code> otherwise. Indices out of
- * range are ignored.
- *
- * @param index the index of the item
- * @return the selection state of the item at the index
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isSelected (int index) {
- checkWidget ();
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_GETSEL, index, 0);
- return (result != 0) && (result != OS.LB_ERR);
-}
-
-/**
- * Removes the items from the receiver at the given
- * zero-relative indices.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- int [] newIndices = new int [indices.length];
- System.arraycopy (indices, 0, newIndices, 0, indices.length);
- sort (newIndices);
- int start = newIndices [newIndices.length - 1], end = newIndices [0];
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (!(0 <= start && start <= end && end < count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int topIndex = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0);
- RECT rect = null;
- int /*long*/ hDC = 0, oldFont = 0, newFont = 0;
- int newWidth = 0;
- if ((style & SWT.H_SCROLL) != 0) {
- rect = new RECT ();
- hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- }
- int cp = getCodePage ();
- int i = 0, topCount = 0, last = -1;
- while (i < newIndices.length) {
- int index = newIndices [i];
- if (index != last) {
- TCHAR buffer = null;
- if ((style & SWT.H_SCROLL) != 0) {
- int length = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTEXTLEN, index, 0);
- if (length == OS.LB_ERR) break;
- buffer = new TCHAR (cp, length + 1);
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer);
- if (result == OS.LB_ERR) break;
- }
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_DELETESTRING, index, 0);
- if (result == OS.LB_ERR) break;
- if ((style & SWT.H_SCROLL) != 0) {
- int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX;
- OS.DrawText (hDC, buffer, -1, rect, flags);
- newWidth = Math.max (newWidth, rect.right - rect.left);
- }
- if (index < topIndex) topCount++;
- last = index;
- }
- i++;
- }
- if ((style & SWT.H_SCROLL) != 0) {
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- setScrollWidth (newWidth, false);
- }
- if (topCount > 0) {
- topIndex -= topCount;
- OS.SendMessage (handle, OS.LB_SETTOPINDEX, topIndex, 0);
- }
- if (i < newIndices.length) error (SWT.ERROR_ITEM_NOT_REMOVED);
-}
-
-/**
- * Removes the item from the receiver at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget ();
- TCHAR buffer = null;
- if ((style & SWT.H_SCROLL) != 0) {
- int length = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTEXTLEN, index, 0);
- if (length == OS.LB_ERR) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (0 <= index && index < count) error (SWT.ERROR_ITEM_NOT_REMOVED);
- error (SWT.ERROR_INVALID_RANGE);
- }
- buffer = new TCHAR (getCodePage (), length + 1);
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer);
- if (result == OS.LB_ERR) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (0 <= index && index < count) error (SWT.ERROR_ITEM_NOT_REMOVED);
- error (SWT.ERROR_INVALID_RANGE);
- }
- }
- int topIndex = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0);
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_DELETESTRING, index, 0);
- if (result == OS.LB_ERR) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (0 <= index && index < count) error (SWT.ERROR_ITEM_NOT_REMOVED);
- error (SWT.ERROR_INVALID_RANGE);
- }
- if ((style & SWT.H_SCROLL) != 0) setScrollWidth (buffer, false);
- if (index < topIndex) {
- OS.SendMessage (handle, OS.LB_SETTOPINDEX, topIndex - 1, 0);
- }
-}
-
-/**
- * Removes the items from the receiver which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget ();
- if (start > end) return;
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (!(0 <= start && start <= end && end < count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- if (start == 0 && end == count - 1) {
- removeAll ();
- return;
- }
- int topIndex = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0);
- RECT rect = null;
- int /*long*/ hDC = 0, oldFont = 0, newFont = 0;
- int newWidth = 0;
- if ((style & SWT.H_SCROLL) != 0) {
- rect = new RECT ();
- hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- }
- int cp = getCodePage ();
- int index = start;
- int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX;
- while (index <= end) {
- TCHAR buffer = null;
- if ((style & SWT.H_SCROLL) != 0) {
- int length = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTEXTLEN, start, 0);
- if (length == OS.LB_ERR) break;
- buffer = new TCHAR (cp, length + 1);
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTEXT, start, buffer);
- if (result == OS.LB_ERR) break;
- }
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_DELETESTRING, start, 0);
- if (result == OS.LB_ERR) break;
- if ((style & SWT.H_SCROLL) != 0) {
- OS.DrawText (hDC, buffer, -1, rect, flags);
- newWidth = Math.max (newWidth, rect.right - rect.left);
- }
- index++;
- }
- if ((style & SWT.H_SCROLL) != 0) {
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- setScrollWidth (newWidth, false);
- }
- if (end < topIndex) {
- topIndex -= end - start + 1;
- OS.SendMessage (handle, OS.LB_SETTOPINDEX, topIndex, 0);
- }
- if (index <= end) error (SWT.ERROR_ITEM_NOT_REMOVED);
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * until an item is found that is equal to the argument,
- * and removes that item from the list.
- *
- * @param string the item to remove
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = indexOf (string, 0);
- if (index == -1) error (SWT.ERROR_INVALID_ARGUMENT);
- remove (index);
-}
-
-/**
- * Removes all of the items from the receiver.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget ();
- OS.SendMessage (handle, OS.LB_RESETCONTENT, 0, 0);
- if ((style & SWT.H_SCROLL) != 0) {
- OS.SendMessage (handle, OS.LB_SETHORIZONTALEXTENT, 0, 0);
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If the item at a given index is not selected, it is selected.
- * If the item at a given index was already selected, it remains selected.
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- *
- * @param indices the array of indices for the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#setSelection(int[])
- */
-public void select (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- select (indices, false);
-}
-
-void select (int [] indices, boolean scroll) {
- int i = 0;
- while (i < indices.length) {
- int index = indices [i];
- if (index != -1) {
- select (index, false);
- }
- i++;
- }
- if (scroll) showSelection ();
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget ();
- select (index, false);
-}
-
-void select (int index, boolean scroll) {
- if (index < 0) return;
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (index >= count) return;
- if (scroll) {
- if ((style & SWT.SINGLE) != 0) {
- OS.SendMessage (handle, OS.LB_SETCURSEL, index, 0);
- } else {
- OS.SendMessage (handle, OS.LB_SETSEL, 1, index);
- }
- return;
- }
- int topIndex = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0);
- RECT itemRect = new RECT (), selectedRect = null;
- OS.SendMessage (handle, OS.LB_GETITEMRECT, index, itemRect);
- boolean redraw = getDrawing () && OS.IsWindowVisible (handle);
- if (redraw) {
- OS.UpdateWindow (handle);
- OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- }
- int focusIndex = -1;
- if ((style & SWT.SINGLE) != 0) {
- int oldIndex = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0);
- if (oldIndex != -1) {
- selectedRect = new RECT ();
- OS.SendMessage (handle, OS.LB_GETITEMRECT, oldIndex, selectedRect);
- }
- OS.SendMessage (handle, OS.LB_SETCURSEL, index, 0);
- } else {
- focusIndex = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCARETINDEX, 0, 0);
- OS.SendMessage (handle, OS.LB_SETSEL, 1, index);
- }
- if ((style & SWT.MULTI) != 0) {
- if (focusIndex != -1) {
- OS.SendMessage (handle, OS.LB_SETCARETINDEX, focusIndex, 0);
- }
- }
- OS.SendMessage (handle, OS.LB_SETTOPINDEX, topIndex, 0);
- if (redraw) {
- OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
- OS.ValidateRect (handle, null);
- OS.InvalidateRect (handle, itemRect, true);
- if (selectedRect != null) {
- OS.InvalidateRect (handle, selectedRect, true);
- }
- }
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If an item in the given range is not selected, it is selected.
- * If an item in the given range was already selected, it remains selected.
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#setSelection(int,int)
- */
-public void select (int start, int end) {
- checkWidget ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (count == 0 || start >= count) return;
- start = Math.max (0, start);
- end = Math.min (end, count - 1);
- if ((style & SWT.SINGLE) != 0) {
- select (start, false);
- } else {
- select (start, end, false);
- }
-}
-
-void select (int start, int end, boolean scroll) {
- /*
- * Note that when start = end, LB_SELITEMRANGEEX
- * deselects the item.
- */
- if (start == end) {
- select (start, scroll);
- return;
- }
- OS.SendMessage (handle, OS.LB_SELITEMRANGEEX, start, end);
- if (scroll) showSelection ();
-}
-
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- OS.SendMessage (handle, OS.LB_SETSEL, 1, -1);
-}
-
-void setFocusIndex (int index) {
-// checkWidget ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (!(0 <= index && index < count)) return;
- OS.SendMessage (handle, OS.LB_SETCARETINDEX, index, 0);
-}
-
-public void setFont (Font font) {
- checkWidget ();
- super.setFont (font);
- if ((style & SWT.H_SCROLL) != 0) setScrollWidth ();
-}
-
-/**
- * Sets the text of the item in the receiver's list at the given
- * zero-relative index to the string argument.
- *
- * @param index the index for the item
- * @param string the new text for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItem (int index, String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int topIndex = getTopIndex ();
- boolean isSelected = isSelected (index);
- remove (index);
- add (string, index);
- if (isSelected) select (index, false);
- setTopIndex (topIndex);
-}
-
-/**
- * Sets the receiver's items to be the given array of items.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItems (String [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<items.length; i++) {
- if (items [i] == null) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int /*long*/ oldProc = OS.GetWindowLongPtr (handle, OS.GWLP_WNDPROC);
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, ListProc);
- boolean redraw = getDrawing () && OS.IsWindowVisible (handle);
- if (redraw) {
- OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- }
- RECT rect = null;
- int /*long*/ hDC = 0, oldFont = 0, newFont = 0;
- int newWidth = 0;
- if ((style & SWT.H_SCROLL) != 0) {
- rect = new RECT ();
- hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- OS.SendMessage (handle, OS.LB_SETHORIZONTALEXTENT, 0, 0);
- }
- int length = items.length;
- OS.SendMessage (handle, OS.LB_RESETCONTENT, 0, 0);
- OS.SendMessage (handle, OS.LB_INITSTORAGE, length, length * 32);
- int index = 0;
- int cp = getCodePage ();
- while (index < length) {
- String string = items [index];
- TCHAR buffer = new TCHAR (cp, string, true);
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_ADDSTRING, 0, buffer);
- if (result == OS.LB_ERR || result == OS.LB_ERRSPACE) break;
- if ((style & SWT.H_SCROLL) != 0) {
- int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX;
- OS.DrawText (hDC, buffer, -1, rect, flags);
- newWidth = Math.max (newWidth, rect.right - rect.left);
- }
- index++;
- }
- if ((style & SWT.H_SCROLL) != 0) {
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- OS.SendMessage (handle, OS.LB_SETHORIZONTALEXTENT, newWidth + INSET, 0);
- }
- if (redraw) {
- OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
- /*
- * This code is intentionally commented. The window proc
- * for the list box implements WM_SETREDRAW to invalidate
- * and erase the widget. This is undocumented behavior.
- * The commented code below shows what is actually happening
- * and reminds us that we are relying on this undocumented
- * behavior.
- */
-// int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE;
-// OS.RedrawWindow (handle, null, 0, flags);
- }
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, oldProc);
- if (index < items.length) error (SWT.ERROR_ITEM_NOT_ADDED);
-}
-
-void setScrollWidth () {
- int newWidth = 0;
- RECT rect = new RECT ();
- int /*long*/ newFont, oldFont = 0;
- int /*long*/ hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- int cp = getCodePage ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX;
- for (int i=0; i<count; i++) {
- int length = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTEXTLEN, i, 0);
- if (length != OS.LB_ERR) {
- TCHAR buffer = new TCHAR (cp, length + 1);
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTEXT, i, buffer);
- if (result != OS.LB_ERR) {
- OS.DrawText (hDC, buffer, -1, rect, flags);
- newWidth = Math.max (newWidth, rect.right - rect.left);
- }
- }
- }
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- OS.SendMessage (handle, OS.LB_SETHORIZONTALEXTENT, newWidth + INSET, 0);
-}
-
-void setScrollWidth (TCHAR buffer, boolean grow) {
- RECT rect = new RECT ();
- int /*long*/ newFont, oldFont = 0;
- int /*long*/ hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX;
- OS.DrawText (hDC, buffer, -1, rect, flags);
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- setScrollWidth (rect.right - rect.left, grow);
-}
-
-void setScrollWidth (int newWidth, boolean grow) {
- newWidth += INSET;
- int width = (int)/*64*/OS.SendMessage (handle, OS.LB_GETHORIZONTALEXTENT, 0, 0);
- if (grow) {
- if (newWidth <= width) return;
- OS.SendMessage (handle, OS.LB_SETHORIZONTALEXTENT, newWidth, 0);
- } else {
- if (newWidth < width) return;
- setScrollWidth ();
- }
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- *
- * @param indices the indices of the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int[])
- */
-public void setSelection(int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- select (indices, true);
- if ((style & SWT.MULTI) != 0) {
- int focusIndex = indices [0];
- if (focusIndex >= 0) setFocusIndex (focusIndex);
- }
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int[])
- * @see List#setSelection(int[])
- */
-public void setSelection (String [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = items.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- int focusIndex = -1;
- for (int i=length-1; i>=0; --i) {
- String string = items [i];
- int index = 0;
- if (string != null) {
- int localFocus = -1;
- while ((index = indexOf (string, index)) != -1) {
- if (localFocus == -1) localFocus = index;
- select (index, false);
- if ((style & SWT.SINGLE) != 0 && isSelected (index)) {
- showSelection ();
- return;
- }
- index++;
- }
- if (localFocus != -1) focusIndex = localFocus;
- }
- }
- if ((style & SWT.MULTI) != 0) {
- if (focusIndex >= 0) setFocusIndex (focusIndex);
- }
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains selected.
- * The current selection is first cleared, then the new item is selected.
- * Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @see List#deselectAll()
- * @see List#select(int)
- */
-public void setSelection (int index) {
- checkWidget ();
- deselectAll ();
- select (index, true);
- if ((style & SWT.MULTI) != 0) {
- if (index >= 0) setFocusIndex (index);
- }
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- *
- * @param start the start index of the items to select
- * @param end the end index of the items to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int,int)
- */
-public void setSelection (int start, int end) {
- checkWidget ();
- deselectAll ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (count == 0 || start >= count) return;
- start = Math.max (0, start);
- end = Math.min (end, count - 1);
- if ((style & SWT.SINGLE) != 0) {
- select (start, true);
- } else {
- select (start, end, true);
- setFocusIndex (start);
- }
-}
-
-/**
- * Sets the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items
- * are scrolled or new items are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget ();
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_SETTOPINDEX, index, 0);
- if (result == OS.LB_ERR) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- index = Math.min (count - 1, Math.max (0, index));
- OS.SendMessage (handle, OS.LB_SETTOPINDEX, index, 0);
- }
-}
-
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void showSelection () {
- checkWidget ();
- int index;
- if ((style & SWT.SINGLE) != 0) {
- index = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0);
- } else {
- int [] indices = new int [1];
- int result = (int)/*64*/OS.SendMessage (handle, OS.LB_GETSELITEMS, 1, indices);
- index = indices [0];
- if (result != 1) index = -1;
- }
- if (index == -1) return;
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (count == 0) return;
- int height = (int)/*64*/OS.SendMessage (handle, OS.LB_GETITEMHEIGHT, 0, 0);
- forceResize ();
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- int topIndex = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0);
- int visibleCount = Math.max (rect.bottom / height, 1);
- int bottomIndex = Math.min (topIndex + visibleCount, count) - 1;
- if (topIndex <= index && index <= bottomIndex) return;
- int newTop = Math.min (Math.max (index - (visibleCount / 2), 0), count - 1);
- OS.SendMessage (handle, OS.LB_SETTOPINDEX, newTop, 0);
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle () | OS.LBS_NOTIFY | OS.LBS_NOINTEGRALHEIGHT;
- if ((style & SWT.SINGLE) != 0) return bits;
- if ((style & SWT.MULTI) != 0) {
- if ((style & SWT.SIMPLE) != 0) return bits | OS.LBS_MULTIPLESEL;
- return bits | OS.LBS_EXTENDEDSEL;
- }
- return bits;
-}
-
-TCHAR windowClass () {
- return ListClass;
-}
-
-int /*long*/ windowProc () {
- return ListProc;
-}
-
-LRESULT WM_CHAR (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_CHAR (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. The Windows list box does not implement
- * the control key interface for multi-select list boxes, making
- * it inaccessible from the keyboard. The fix is to implement
- * the key processing.
- */
- if (OS.GetKeyState (OS.VK_CONTROL) < 0 && OS.GetKeyState (OS.VK_SHIFT) >= 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.LBS_EXTENDEDSEL) != 0) {
- switch ((int)/*64*/wParam) {
- case OS.VK_SPACE: {
- int index = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCARETINDEX, 0, 0);
- int code = (int)/*64*/OS.SendMessage (handle, OS.LB_GETSEL, index, 0);
- if (code == OS.LB_ERR) break;
- OS.SendMessage (handle, OS.LB_SETSEL, code != 0 ? 0 : 1, index);
- OS.SendMessage (handle, OS.LB_SETANCHORINDEX, index, 0);
- postEvent (SWT.Selection);
- return LRESULT.ZERO;
- }
- }
- }
- }
- return result;
-}
-
-LRESULT WM_KEYDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_KEYDOWN (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. The Windows list box does not implement
- * the control key interface for multi-select list boxes, making
- * it inaccessible from the keyboard. The fix is to implement
- * the key processing.
- */
- if (OS.GetKeyState (OS.VK_CONTROL) < 0 && OS.GetKeyState (OS.VK_SHIFT) >= 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.LBS_EXTENDEDSEL) != 0) {
- int newIndex = -1;
- switch ((int)/*64*/wParam) {
- case OS.VK_SPACE: {
- /*
- * Ensure that the window proc does not process VK_SPACE
- * so that it can be handled in WM_CHAR. This allows the
- * application to cancel an operation that is normally
- * performed in WM_KEYDOWN from WM_CHAR.
- */
- return LRESULT.ZERO;
- }
- case OS.VK_UP:
- case OS.VK_DOWN: {
- int oldIndex = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCARETINDEX, 0, 0);
- newIndex = Math.max (0, oldIndex + (((int)/*64*/wParam) == OS.VK_UP ? -1 : 1));
- break;
- }
- case OS.VK_PRIOR: {
- int topIndex = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0);
- int oldIndex = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCARETINDEX, 0, 0);
- if (oldIndex != topIndex) {
- newIndex = topIndex;
- } else {
- forceResize ();
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- int itemHeight = (int)/*64*/OS.SendMessage (handle, OS.LB_GETITEMHEIGHT, 0, 0);
- int pageSize = Math.max (2, (rect.bottom / itemHeight));
- newIndex = Math.max (0, topIndex - (pageSize - 1));
- }
- break;
- }
- case OS.VK_NEXT: {
- int topIndex = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0);
- int oldIndex = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCARETINDEX, 0, 0);
- forceResize ();
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- int itemHeight = (int)/*64*/OS.SendMessage (handle, OS.LB_GETITEMHEIGHT, 0, 0);
- int pageSize = Math.max (2, (rect.bottom / itemHeight));
- int bottomIndex = topIndex + pageSize - 1;
- if (oldIndex != bottomIndex) {
- newIndex = bottomIndex;
- } else {
- newIndex = bottomIndex + pageSize - 1;
- }
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (count != OS.LB_ERR) newIndex = Math.min (count - 1, newIndex);
- break;
- }
- case OS.VK_HOME: {
- newIndex = 0;
- break;
- }
- case OS.VK_END: {
- int count = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (count == OS.LB_ERR) break;
- newIndex = count - 1;
- break;
- }
- }
- if (newIndex != -1) {
- /*
- * Feature in Windows. When the user changes focus using
- * the keyboard, the focus indicator does not draw. The
- * fix is to update the UI state for the control whenever
- * the focus indicator changes as a result of something
- * the user types.
- */
- int uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- if ((uiState & OS.UISF_HIDEFOCUS) != 0) {
- OS.SendMessage (handle, OS.WM_CHANGEUISTATE, OS.UIS_INITIALIZE, 0);
- /*
- * Bug in Windows. When the WM_CHANGEUISTATE is used
- * to update the UI state for a list that has been
- * selected using Shift+Arrow, the focus indicator
- * has pixel corruption. The fix is to redraw the
- * control.
- */
- RECT itemRect = new RECT ();
- int oldIndex = (int)/*64*/OS.SendMessage (handle, OS.LB_GETCARETINDEX, 0, 0);
- OS.SendMessage (handle, OS.LB_GETITEMRECT, oldIndex, itemRect);
- OS.InvalidateRect (handle, itemRect, true);
- }
- OS.SendMessage (handle, OS.LB_SETCARETINDEX, newIndex, 0);
- return LRESULT.ZERO;
- }
- }
- }
- return result;
-}
-
-LRESULT WM_SETREDRAW (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SETREDRAW (wParam, lParam);
- if (result != null) return result;
- /*
- * Bug in Windows. When WM_SETREDRAW is used to turn off
- * redraw for a list, table or tree, the background of the
- * control is drawn. The fix is to call DefWindowProc(),
- * which stops all graphics output to the control.
- */
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, wParam, lParam);
- return result;
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Bug in Windows. If the top index is changed while the
- * list is being resized, Windows does not redraw properly
- * when their is white space at the bottom of the control.
- * The fix is to detect when the top index has changed and
- * redraw the control.
- *
- * Bug in Windows. If the receiver is scrolled horizontally
- * and is resized, the list does not redraw properly. The fix
- * is to redraw the control when the horizontal scroll bar is
- * not at the beginning.
- */
- int oldIndex = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0);
- LRESULT result = super.WM_SIZE (wParam, lParam);
- if (!isDisposed ()) {
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_POS;
- if (OS.GetScrollInfo (handle, OS.SB_HORZ, info)) {
- if (info.nPos != 0) OS.InvalidateRect (handle, null, true);
- }
- int newIndex = (int)/*64*/OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0);
- if (oldIndex != newIndex) OS.InvalidateRect (handle, null, true);
- }
- return result;
-}
-
-LRESULT wmCommandChild (int /*long*/ wParam, int /*long*/ lParam) {
- int code = OS.HIWORD (wParam);
- switch (code) {
- case OS.LBN_SELCHANGE:
- postEvent (SWT.Selection);
- break;
- case OS.LBN_DBLCLK:
- postEvent (SWT.DefaultSelection);
- break;
- }
- return super.wmCommandChild (wParam, lParam);
-}
-
-
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java
deleted file mode 100755
index 183a593045..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java
+++ /dev/null
@@ -1,1566 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are user interface objects that contain
- * menu items.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BAR, DROP_DOWN, POP_UP, NO_RADIO_GROUP</dd>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Help, Hide, Show </dd>
- * </dl>
- * <p>
- * Note: Only one of BAR, DROP_DOWN and POP_UP may be specified.
- * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#menu">Menu snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Menu extends Widget {
- /**
- * the handle to the OS resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
-
- int x, y;
- int /*long*/ hBrush, hwndCB;
- int id0, id1;
- int foreground = -1, background = -1;
- Image backgroundImage;
- boolean hasLocation;
- MenuItem cascade;
- Decorations parent;
- ImageList imageList;
-
- /* Resource ID for SHMENUBARINFO */
- static final int ID_PPC = 100;
-
- /* SmartPhone SoftKeyBar resource ids */
- static final int ID_SPMM = 102;
- static final int ID_SPBM = 103;
- static final int ID_SPMB = 104;
- static final int ID_SPBB = 105;
- static final int ID_SPSOFTKEY0 = 106;
- static final int ID_SPSOFTKEY1 = 107;
-
-/**
- * Constructs a new instance of this class given its parent,
- * and sets the style for the instance so that the instance
- * will be a popup menu on the given parent's shell.
- * <p>
- * After constructing a menu, it can be set into its parent
- * using <code>parent.setMenu(menu)</code>. In this case, the parent may
- * be any control in the same widget tree as the parent.
- * </p>
- *
- * @param parent a control which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#POP_UP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Control parent) {
- this (checkNull (parent).menuShell (), SWT.POP_UP);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Decorations</code>) and a style value
- * describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * After constructing a menu or menuBar, it can be set into its parent
- * using <code>parent.setMenu(menu)</code> or <code>parent.setMenuBar(menuBar)</code>.
- * </p>
- *
- * @param parent a decorations control which will be the parent of the new instance (cannot be null)
- * @param style the style of menu to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BAR
- * @see SWT#DROP_DOWN
- * @see SWT#POP_UP
- * @see SWT#NO_RADIO_GROUP
- * @see SWT#LEFT_TO_RIGHT
- * @see SWT#RIGHT_TO_LEFT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Decorations parent, int style) {
- this (parent, checkStyle (style), 0);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>) and sets the style
- * for the instance so that the instance will be a drop-down
- * menu on the given parent's parent.
- * <p>
- * After constructing a drop-down menu, it can be set into its parentMenu
- * using <code>parentMenu.setMenu(menu)</code>.
- * </p>
- *
- * @param parentMenu a menu which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Menu parentMenu) {
- this (checkNull (parentMenu).parent, SWT.DROP_DOWN);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>MenuItem</code>) and sets the style
- * for the instance so that the instance will be a drop-down
- * menu on the given parent's parent menu.
- * <p>
- * After constructing a drop-down menu, it can be set into its parentItem
- * using <code>parentItem.setMenu(menu)</code>.
- * </p>
- *
- * @param parentItem a menu item which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (MenuItem parentItem) {
- this (checkNull (parentItem).parent);
-}
-
-Menu (Decorations parent, int style, int /*long*/ handle) {
- super (parent, checkStyle (style));
- this.parent = parent;
- this.handle = handle;
- /*
- * Bug in IBM JVM 1.3.1. For some reason, when the checkOrientation() is
- * called from createWidget(), the JVM issues this error:
- *
- * JVM Exception 0x2 (subcode 0x0) occurred in thread "main" (TID:0x9F19D8)
- *
- * In addition, on Windows XP, a dialog appears with following error message,
- * indicating that the problem may be in the JIT:
- *
- * AppName: java.exe AppVer: 0.0.0.0 ModName: jitc.dll
- * ModVer: 0.0.0.0 Offset: 000b6912
- *
- * The fix is to call checkOrientation() from here.
- */
- checkOrientation (parent);
- createWidget ();
-}
-
-void _setVisible (boolean visible) {
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- int /*long*/ hwndParent = parent.handle;
- if (visible) {
- int flags = OS.TPM_LEFTBUTTON;
- if (OS.GetKeyState (OS.VK_LBUTTON) >= 0) flags |= OS.TPM_RIGHTBUTTON;
- if ((style & SWT.RIGHT_TO_LEFT) != 0) flags |= OS.TPM_RIGHTALIGN;
- if ((parent.style & SWT.MIRRORED) != 0) {
- flags &= ~OS.TPM_RIGHTALIGN;
- if ((style & SWT.LEFT_TO_RIGHT) != 0) flags |= OS.TPM_RIGHTALIGN;
- }
- int nX = x, nY = y;
- if (!hasLocation) {
- int pos = OS.GetMessagePos ();
- nX = OS.GET_X_LPARAM (pos);
- nY = OS.GET_Y_LPARAM (pos);
- }
- /*
- * Feature in Windows. It is legal use TrackPopupMenu()
- * to display an empty menu as long as menu items are added
- * inside of WM_INITPOPUPMENU. If no items are added, then
- * TrackPopupMenu() fails and does not send an indication
- * that the menu has been closed. This is not strictly a
- * bug but leads to unwanted behavior when application code
- * assumes that every WM_INITPOPUPMENU will eventually result
- * in a WM_MENUSELECT, wParam=MAKEWPARAM (0, 0xFFFF), lParam=0 to
- * indicate that the menu has been closed. The fix is to detect
- * the case when TrackPopupMenu() fails and the number of items in
- * the menu is zero and issue a fake WM_MENUSELECT.
- */
- boolean success = OS.TrackPopupMenu (handle, flags, nX, nY, 0, hwndParent, null);
- if (!success && GetMenuItemCount (handle) == 0) {
- OS.SendMessage (hwndParent, OS.WM_MENUSELECT, OS.MAKEWPARAM (0, 0xFFFF), 0);
- }
- } else {
- OS.SendMessage (hwndParent, OS.WM_CANCELMODE, 0, 0);
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when help events are generated for the control,
- * by sending it one of the messages defined in the
- * <code>HelpListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when menus are hidden or shown, by sending it
- * one of the messages defined in the <code>MenuListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuListener
- * @see #removeMenuListener
- */
-public void addMenuListener (MenuListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Hide,typedListener);
- addListener (SWT.Show,typedListener);
-}
-
-static Control checkNull (Control control) {
- if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return control;
-}
-
-static Menu checkNull (Menu menu) {
- if (menu == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return menu;
-}
-
-static MenuItem checkNull (MenuItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0);
-}
-
-void createHandle () {
- if (handle != 0) return;
- if ((style & SWT.BAR) != 0) {
- if (OS.IsPPC) {
- int /*long*/ hwndShell = parent.handle;
- SHMENUBARINFO mbi = new SHMENUBARINFO ();
- mbi.cbSize = SHMENUBARINFO.sizeof;
- mbi.hwndParent = hwndShell;
- mbi.dwFlags = OS.SHCMBF_HIDDEN;
- mbi.nToolBarId = ID_PPC;
- mbi.hInstRes = OS.GetLibraryHandle ();
- boolean success = OS.SHCreateMenuBar (mbi);
- hwndCB = mbi.hwndMB;
- if (!success) error (SWT.ERROR_NO_HANDLES);
- /* Remove the item from the resource file */
- OS.SendMessage (hwndCB, OS.TB_DELETEBUTTON, 0, 0);
- return;
- }
- /*
- * Note in WinCE SmartPhone. The SoftBar contains only 2 items.
- * An item can either be a menu or a button.
- * SWT.BAR: creates a SoftBar with 2 menus
- * SWT.BAR | SWT.BUTTON1: creates a SoftBar with 1 button
- * for button1, and a menu for button2
- * SWT.BAR | SWT.BUTTON1 | SWT.BUTTON2: creates a SoftBar with
- * 2 buttons
- */
- if (OS.IsSP) {
- /* Determine type of menubar */
- int nToolBarId;
- if ((style & SWT.BUTTON1) != 0) {
- nToolBarId = ((style & SWT.BUTTON2) != 0) ? ID_SPBB : ID_SPBM;
- } else {
- nToolBarId = ((style & SWT.BUTTON2) != 0) ? ID_SPMB : ID_SPMM;
- }
-
- /* Create SHMENUBAR */
- SHMENUBARINFO mbi = new SHMENUBARINFO ();
- mbi.cbSize = SHMENUBARINFO.sizeof;
- mbi.hwndParent = parent.handle;
- mbi.dwFlags = OS.SHCMBF_HIDDEN;
- mbi.nToolBarId = nToolBarId; /* as defined in .rc file */
- mbi.hInstRes = OS.GetLibraryHandle ();
- if (!OS.SHCreateMenuBar (mbi)) error (SWT.ERROR_NO_HANDLES);
- hwndCB = mbi.hwndMB;
-
- /*
- * Feature on WinCE SmartPhone. The SHCMBF_HIDDEN flag causes the
- * SHMENUBAR to not be drawn. However the keyboard events still go
- * through it. The workaround is to also hide the SHMENUBAR with
- * ShowWindow ().
- */
- OS.ShowWindow (hwndCB, OS.SW_HIDE);
-
- TBBUTTONINFO info = new TBBUTTONINFO ();
- info.cbSize = TBBUTTONINFO.sizeof;
- info.dwMask = OS.TBIF_COMMAND;
- MenuItem item;
-
- /* Set first item */
- if (nToolBarId == ID_SPMM || nToolBarId == ID_SPMB) {
- int /*long*/ hMenu = OS.SendMessage (hwndCB, OS.SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY0);
- /* Remove the item from the resource file */
- OS.RemoveMenu (hMenu, 0, OS.MF_BYPOSITION);
- Menu menu = new Menu (parent, SWT.DROP_DOWN, hMenu);
- item = new MenuItem (this, menu, SWT.CASCADE, 0);
- } else {
- item = new MenuItem (this, null, SWT.PUSH, 0);
- }
- info.idCommand = id0 = item.id;
- OS.SendMessage (hwndCB, OS.TB_SETBUTTONINFO, ID_SPSOFTKEY0, info);
-
- /* Set second item */
- if (nToolBarId == ID_SPMM || nToolBarId == ID_SPBM) {
- int /*long*/ hMenu = OS.SendMessage (hwndCB, OS.SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);
- OS.RemoveMenu (hMenu, 0, OS.MF_BYPOSITION);
- Menu menu = new Menu (parent, SWT.DROP_DOWN, hMenu);
- item = new MenuItem (this, menu, SWT.CASCADE, 1);
- } else {
- item = new MenuItem (this, null, SWT.PUSH, 1);
- }
- info.idCommand = id1 = item.id;
- OS.SendMessage (hwndCB, OS.TB_SETBUTTONINFO, ID_SPSOFTKEY1, info);
-
- /*
- * Override the Back key. For some reason, the owner of the menubar
- * must be a Dialog or it won't receive the WM_HOTKEY message. As
- * a result, Shell on WinCE SP must use the class Dialog.
- */
- int dwMask = OS.SHMBOF_NODEFAULT | OS.SHMBOF_NOTIFY;
- int /*long*/ lParam = OS.MAKELPARAM (dwMask, dwMask);
- OS.SendMessage (hwndCB, OS.SHCMBM_OVERRIDEKEY, OS.VK_ESCAPE, lParam);
- return;
- }
- handle = OS.CreateMenu ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if (OS.IsHPC) {
- int /*long*/ hwndShell = parent.handle;
- hwndCB = OS.CommandBar_Create (OS.GetModuleHandle (null), hwndShell, 1);
- if (hwndCB == 0) error (SWT.ERROR_NO_HANDLES);
- OS.CommandBar_Show (hwndCB, false);
- OS.CommandBar_InsertMenubarEx (hwndCB, 0, handle, 0);
- /*
- * The command bar hosts the 'close' button when the window does not
- * have a caption.
- */
- if ((parent.style & SWT.CLOSE) != 0 && (parent.style & SWT.TITLE) == 0) {
- OS.CommandBar_AddAdornments (hwndCB, 0, 0);
- }
- }
- } else {
- handle = OS.CreatePopupMenu ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- }
-}
-
-void createItem (MenuItem item, int index) {
- int count = GetMenuItemCount (handle);
- if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
- display.addMenuItem (item);
- boolean success = false;
- if ((OS.IsPPC || OS.IsSP) && hwndCB != 0) {
- if (OS.IsSP) return;
- TBBUTTON lpButton = new TBBUTTON ();
- lpButton.idCommand = item.id;
- lpButton.fsStyle = (byte) OS.TBSTYLE_AUTOSIZE;
- if ((item.style & SWT.CASCADE) != 0) lpButton.fsStyle |= OS.TBSTYLE_DROPDOWN | 0x80;
- if ((item.style & SWT.SEPARATOR) != 0) lpButton.fsStyle = (byte) OS.BTNS_SEP;
- lpButton.fsState = (byte) OS.TBSTATE_ENABLED;
- lpButton.iBitmap = OS.I_IMAGENONE;
- success = OS.SendMessage (hwndCB, OS.TB_INSERTBUTTON, index, lpButton) != 0;
- } else {
- if (OS.IsWinCE) {
- int uFlags = OS.MF_BYPOSITION;
- TCHAR lpNewItem = null;
- if ((item.style & SWT.SEPARATOR) != 0) {
- uFlags |= OS.MF_SEPARATOR;
- } else {
- lpNewItem = new TCHAR (0, " ", true);
- }
- success = OS.InsertMenu (handle, index, uFlags, item.id, lpNewItem);
- if (success) {
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- info.fMask = OS.MIIM_DATA;
- info.dwItemData = item.id;
- success = OS.SetMenuItemInfo (handle, index, true, info);
- }
- } else {
- /*
- * Bug in Windows. For some reason, when InsertMenuItem()
- * is used to insert an item without text, it is not possible
- * to use SetMenuItemInfo() to set the text at a later time.
- * The fix is to insert the item with some text.
- *
- * Feature in Windows. When an empty string is used instead
- * of a space and InsertMenuItem() is used to set a submenu
- * before setting text to a non-empty string, the menu item
- * becomes unexpectedly disabled. The fix is to insert a
- * space.
- */
- int /*long*/ hHeap = OS.GetProcessHeap ();
- TCHAR buffer = new TCHAR (0, " ", true);
- int byteCount = buffer.length () * TCHAR.sizeof;
- int /*long*/ pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (pszText, buffer, byteCount);
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- info.fMask = OS.MIIM_ID | OS.MIIM_TYPE | OS.MIIM_DATA;
- info.wID = item.id;
- info.dwItemData = item.id;
- info.fType = item.widgetStyle ();
- info.dwTypeData = pszText;
- success = OS.InsertMenuItem (handle, index, true, info);
- if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
- }
- }
- if (!success) {
- display.removeMenuItem (item);
- error (SWT.ERROR_ITEM_NOT_ADDED);
- }
- redraw ();
-}
-
-void createWidget () {
- /*
- * Bug in IBM JVM 1.3.1. For some reason, when the following code is called
- * from this method, the JVM issues this error:
- *
- * JVM Exception 0x2 (subcode 0x0) occurred in thread "main" (TID:0x9F19D8)
- *
- * In addition, on Windows XP, a dialog appears with following error message,
- * indicating that the problem may be in the JIT:
- *
- * AppName: java.exe AppVer: 0.0.0.0 ModName: jitc.dll
- * ModVer: 0.0.0.0 Offset: 000b6912
- *
- * The fix is to move the code to the caller of this method.
- */
-// checkOrientation (parent);
- createHandle ();
- parent.addMenu (this);
-}
-
-int defaultBackground () {
- return OS.GetSysColor (OS.COLOR_MENU);
-}
-
-int defaultForeground () {
- return OS.GetSysColor (OS.COLOR_MENUTEXT);
-}
-
-void destroyAccelerators () {
- parent.destroyAccelerators ();
-}
-
-void destroyItem (MenuItem item) {
- if (OS.IsWinCE) {
- if ((OS.IsPPC || OS.IsSP) && hwndCB != 0) {
- if (OS.IsSP) {
- redraw();
- return;
- }
- int index = (int)/*64*/OS.SendMessage (hwndCB, OS.TB_COMMANDTOINDEX, item.id, 0);
- if (OS.SendMessage (hwndCB, OS.TB_DELETEBUTTON, index, 0) == 0) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- int count = (int)/*64*/OS.SendMessage (hwndCB, OS.TB_BUTTONCOUNT, 0, 0);
- if (count == 0) {
- if (imageList != null) {
- OS.SendMessage (handle, OS.TB_SETIMAGELIST, 0, 0);
- display.releaseImageList (imageList);
- imageList = null;
- }
- }
- } else {
- int index = 0;
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- info.fMask = OS.MIIM_DATA;
- while (OS.GetMenuItemInfo (handle, index, true, info)) {
- if (info.dwItemData == item.id) break;
- index++;
- }
- if (info.dwItemData != item.id) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- if (!OS.DeleteMenu (handle, index, OS.MF_BYPOSITION)) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- }
- } else {
- if (!OS.DeleteMenu (handle, item.id, OS.MF_BYCOMMAND)) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- }
- redraw ();
-}
-
-void destroyWidget () {
- MenuItem cascade = this.cascade;
- int /*long*/ hMenu = handle, hCB = hwndCB;
- releaseHandle ();
- if (OS.IsWinCE && hCB != 0) {
- OS.CommandBar_Destroy (hCB);
- } else {
- if (cascade != null) {
- if (!OS.IsSP) cascade.setMenu (null, true);
- } else {
- if (hMenu != 0) OS.DestroyMenu (hMenu);
- }
- }
-}
-
-void fixMenus (Decorations newParent) {
- MenuItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- items [i].fixMenus (newParent);
- }
- parent.removeMenu (this);
- newParent.addMenu (this);
- this.parent = newParent;
-}
-
-/**
- * Returns the receiver's background color.
- *
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-/*public*/ Color getBackground () {
- checkWidget ();
- return Color.win32_new (display, background != -1 ? background : defaultBackground ());
-}
-
-/**
- * Returns the receiver's background image.
- *
- * @return the background image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-/*public*/ Image getBackgroundImage () {
- checkWidget ();
- return backgroundImage;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null),
- * unless the receiver is a menu or a shell. In this case, the
- * location is relative to the display.
- * <p>
- * Note that the bounds of a menu or menu item are undefined when
- * the menu is not visible. This is because most platforms compute
- * the bounds of a menu dynamically just before it is displayed.
- * </p>
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-/*public*/ Rectangle getBounds () {
- checkWidget ();
- if (OS.IsWinCE) return new Rectangle (0, 0, 0, 0);
- if ((style & SWT.BAR) != 0) {
- if (parent.menuBar != this) {
- return new Rectangle (0, 0, 0, 0);
- }
- int /*long*/ hwndShell = parent.handle;
- MENUBARINFO info = new MENUBARINFO ();
- info.cbSize = MENUBARINFO.sizeof;
- if (OS.GetMenuBarInfo (hwndShell, OS.OBJID_MENU, 0, info)) {
- int width = info.right - info.left;
- int height = info.bottom - info.top;
- return new Rectangle (info.left, info.top, width, height);
- }
- } else {
- int count = GetMenuItemCount (handle);
- if (count != 0) {
- RECT rect1 = new RECT ();
- if (OS.GetMenuItemRect (0, handle, 0, rect1)) {
- RECT rect2 = new RECT ();
- if (OS.GetMenuItemRect (0, handle, count - 1, rect2)) {
- int x = rect1.left - 2, y = rect1.top - 2;
- int width = (rect2.right - rect2.left) + 4;
- int height = (rect2.bottom - rect1.top) + 4;
- return new Rectangle (x, y, width, height);
- }
- }
- }
- }
- return new Rectangle (0, 0, 0, 0);
-}
-
-/**
- * Returns the default menu item or null if none has
- * been previously set.
- *
- * @return the default menu item.
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getDefaultItem () {
- checkWidget ();
- if (OS.IsWinCE) return null;
- int id = OS.GetMenuDefaultItem (handle, OS.MF_BYCOMMAND, OS.GMDI_USEDISABLED);
- if (id == -1) return null;
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- info.fMask = OS.MIIM_ID;
- if (OS.GetMenuItemInfo (handle, id, false, info)) {
- return display.getMenuItem (info.wID);
- }
- return null;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled menu is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget ();
- return (state & DISABLED) == 0;
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-/*public*/ Color getForeground () {
- checkWidget ();
- return Color.win32_new (display, foreground != -1 ? foreground : defaultForeground ());
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getItem (int index) {
- checkWidget ();
- int id = 0;
- if ((OS.IsPPC || OS.IsSP) && hwndCB != 0) {
- if (OS.IsPPC) {
- TBBUTTON lpButton = new TBBUTTON ();
- int /*long*/ result = OS.SendMessage (hwndCB, OS.TB_GETBUTTON, index, lpButton);
- if (result == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- id = lpButton.idCommand;
- }
- if (OS.IsSP) {
- if (!(0 <= index && index <= 1)) error (SWT.ERROR_CANNOT_GET_ITEM);
- id = index == 0 ? id0 : id1;
- }
- } else {
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- info.fMask = OS.MIIM_DATA;
- if (!OS.GetMenuItemInfo (handle, index, true, info)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- id = (int)/*64*/info.dwItemData;
- }
- return display.getMenuItem (id);
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return GetMenuItemCount (handle);
-}
-
-/**
- * Returns a (possibly empty) array of <code>MenuItem</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem [] getItems () {
- checkWidget ();
- if ((OS.IsPPC || OS.IsSP) && hwndCB != 0) {
- if (OS.IsSP) {
- MenuItem [] result = new MenuItem [2];
- result[0] = display.getMenuItem (id0);
- result[1] = display.getMenuItem (id1);
- return result;
- }
- int count = (int)/*64*/OS.SendMessage (hwndCB, OS.TB_BUTTONCOUNT, 0, 0);
- TBBUTTON lpButton = new TBBUTTON ();
- MenuItem [] result = new MenuItem [count];
- for (int i=0; i<count; i++) {
- OS.SendMessage (hwndCB, OS.TB_GETBUTTON, i, lpButton);
- result [i] = display.getMenuItem (lpButton.idCommand);
- }
- return result;
- }
- int index = 0, count = 0;
- int length = OS.IsWinCE ? 4 : OS.GetMenuItemCount (handle);
- MenuItem [] items = new MenuItem [length];
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- info.fMask = OS.MIIM_DATA;
- while (OS.GetMenuItemInfo (handle, index, true, info)) {
- if (count == items.length) {
- MenuItem [] newItems = new MenuItem [count + 4];
- System.arraycopy (items, 0, newItems, 0, count);
- items = newItems;
- }
- MenuItem item = display.getMenuItem ((int)/*64*/info.dwItemData);
- if (item != null) items [count++] = item;
- index++;
- }
- if (count == items.length) return items;
- MenuItem [] result = new MenuItem [count];
- System.arraycopy (items, 0, result, 0, count);
- return result;
-}
-
-int GetMenuItemCount (int /*long*/ handle) {
- if (OS.IsWinCE) {
- if ((OS.IsPPC || OS.IsSP) && hwndCB != 0) {
- return OS.IsSP ? 2 : (int)/*64*/OS.SendMessage (hwndCB, OS.TB_BUTTONCOUNT, 0, 0);
- }
- int count = 0;
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- while (OS.GetMenuItemInfo (handle, count, true, info)) count++;
- return count;
- }
- return OS.GetMenuItemCount (handle);
-}
-
-String getNameText () {
- String result = "";
- MenuItem [] items = getItems ();
- int length = items.length;
- if (length > 0) {
- for (int i=0; i<length-1; i++) {
- result = result + items [i].getNameText() + ", ";
- }
- result = result + items [length-1].getNameText ();
- }
- return result;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Decorations</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Decorations getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>MenuItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getParentItem () {
- checkWidget ();
- return cascade;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>Menu</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getParentMenu () {
- checkWidget ();
- if (cascade != null) return cascade.parent;
- return null;
-}
-
-/**
- * Returns the receiver's shell. For all controls other than
- * shells, this simply returns the control's nearest ancestor
- * shell. Shells return themselves, even if they are children
- * of other shells.
- *
- * @return the receiver's shell
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getParent
- */
-public Shell getShell () {
- checkWidget ();
- return parent.getShell ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- if ((style & SWT.BAR) != 0) {
- return this == parent.menuShell ().menuBar;
- }
- if ((style & SWT.POP_UP) != 0) {
- Menu [] popups = display.popups;
- if (popups == null) return false;
- for (int i=0; i<popups.length; i++) {
- if (popups [i] == this) return true;
- }
- }
- Shell shell = getShell ();
- Menu menu = shell.activeMenu;
- while (menu != null && menu != this) {
- menu = menu.getParentMenu ();
- }
- return this == menu;
-}
-
-int imageIndex (Image image) {
- if (hwndCB == 0 || image == null) return OS.I_IMAGENONE;
- if (imageList == null) {
- Rectangle bounds = image.getBounds ();
- imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height);
- int index = imageList.add (image);
- int /*long*/ hImageList = imageList.getHandle ();
- OS.SendMessage (hwndCB, OS.TB_SETIMAGELIST, 0, hImageList);
- return index;
- }
- int index = imageList.indexOf (image);
- if (index == -1) {
- index = imageList.add (image);
- } else {
- imageList.put (index, image);
- }
- return index;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (MenuItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (item.parent != this) return -1;
- if ((OS.IsPPC || OS.IsSP) && hwndCB != 0) {
- if (OS.IsPPC) {
- return (int)/*64*/OS.SendMessage (hwndCB, OS.TB_COMMANDTOINDEX, item.id, 0);
- }
- if (OS.IsSP) {
- if (item.id == id0) return 0;
- if (item.id == id1) return 1;
- return -1;
- }
- }
- int index = 0;
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- info.fMask = OS.MIIM_DATA;
- while (OS.GetMenuItemInfo (handle, index, true, info)) {
- if (info.dwItemData == item.id) return index;
- index++;
- }
- return -1;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled menu is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget ();
- Menu parentMenu = getParentMenu ();
- if (parentMenu == null) {
- return getEnabled () && parent.isEnabled ();
- }
- return getEnabled () && parentMenu.isEnabled ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget ();
- return getVisible ();
-}
-
-void redraw () {
- if (!isVisible ()) return;
- if ((style & SWT.BAR) != 0) {
- display.addBar (this);
- } else {
- update ();
- }
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- handle = hwndCB = 0;
- cascade = null;
-}
-
-void releaseChildren (boolean destroy) {
- MenuItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- if (OS.IsPPC && hwndCB != 0) {
- item.dispose ();
- } else {
- item.release (false);
- }
- }
- }
- super.releaseChildren (destroy);
-}
-
-void releaseParent () {
- super.releaseParent ();
- if ((style & SWT.BAR) != 0) {
- display.removeBar (this);
- if (this == parent.menuBar) {
- parent.setMenuBar (null);
- }
- } else {
- if ((style & SWT.POP_UP) != 0) {
- display.removePopup (this);
- }
- }
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- backgroundImage = null;
- if (hBrush == 0) OS.DeleteObject (hBrush);
- hBrush = 0;
- if (OS.IsPPC && hwndCB != 0) {
- if (imageList != null) {
- OS.SendMessage (hwndCB, OS.TB_SETIMAGELIST, 0, 0);
- display.releaseToolImageList (imageList);
- imageList = null;
- }
- }
- if (parent != null) parent.removeMenu (this);
- parent = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the menu events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuListener
- * @see #addMenuListener
- */
-public void removeMenuListener (MenuListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Hide, listener);
- eventTable.unhook (SWT.Show, listener);
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the control
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-/*public*/ void setBackground (Color color) {
- checkWidget ();
- int pixel = -1;
- if (color != null) {
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- pixel = color.handle;
- }
- if (pixel == background) return;
- background = pixel;
- updateBackground ();
-}
-
-/**
- * Sets the receiver's background image to the image specified
- * by the argument, or to the default system color for the control
- * if the argument is null. The background image is tiled to fill
- * the available space.
- *
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument is not a bitmap</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-/*public*/ void setBackgroundImage (Image image) {
- checkWidget ();
- if (image != null) {
- if (image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (image.type != SWT.BITMAP) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (backgroundImage == image) return;
- backgroundImage = image;
- updateBackground ();
-}
-
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the control
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-/*public*/ void setForeground (Color color) {
- checkWidget ();
- int pixel = -1;
- if (color != null) {
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- pixel = color.handle;
- }
- if (pixel == foreground) return;
- foreground = pixel;
- updateForeground ();
-}
-
-/**
- * Sets the default menu item to the argument or removes
- * the default emphasis when the argument is <code>null</code>.
- *
- * @param item the default menu item or null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the menu item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDefaultItem (MenuItem item) {
- checkWidget ();
- int newID = -1;
- if (item != null) {
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (item.parent != this) return;
- newID = item.id;
- }
- if (OS.IsWinCE) return;
- int oldID = OS.GetMenuDefaultItem (handle, OS.MF_BYCOMMAND, OS.GMDI_USEDISABLED);
- if (newID == oldID) return;
- OS.SetMenuDefaultItem (handle, newID, OS.MF_BYCOMMAND);
- redraw ();
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled menu is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget ();
- state &= ~DISABLED;
- if (!enabled) state |= DISABLED;
-}
-
-/**
- * Sets the location of the receiver, which must be a popup,
- * to the point specified by the arguments which are relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p><p>
- * Note that the platform window manager ultimately has control
- * over the location of popup menus.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget ();
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- this.x = x;
- this.y = y;
- hasLocation = true;
-}
-
-/**
- * Sets the location of the receiver, which must be a popup,
- * to the point specified by the argument which is relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p><p>
- * Note that the platform window manager ultimately has control
- * over the location of popup menus.
- * </p>
- *
- * @param location the new location for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void setLocation (Point location) {
- checkWidget ();
- if (location == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- if (visible) {
- display.addPopup (this);
- } else {
- display.removePopup (this);
- _setVisible (false);
- }
-}
-
-void update () {
- if (OS.IsPPC || OS.IsSP) return;
- if (OS.IsHPC) {
- /*
- * Each time a menu has been modified, the command menu bar
- * must be redrawn or it won't update properly. For example,
- * a submenu will not drop down.
- */
- Menu menuBar = parent.menuBar;
- if (menuBar != null) {
- Menu menu = this;
- while (menu != null && menu != menuBar) {
- menu = menu.getParentMenu ();
- }
- if (menu == menuBar) {
- OS.CommandBar_DrawMenuBar (menuBar.hwndCB, 0);
- OS.CommandBar_Show (menuBar.hwndCB, true);
- }
- }
- return;
- }
- if (OS.IsWinCE) return;
- if ((style & SWT.BAR) != 0) {
- if (this == parent.menuBar) OS.DrawMenuBar (parent.handle);
- return;
- }
- if (OS.WIN32_VERSION < OS.VERSION (4, 10)) {
- return;
- }
- boolean hasCheck = false, hasImage = false;
- MenuItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (item.image != null) {
- if ((hasImage = true) && hasCheck) break;
- }
- if ((item.style & (SWT.CHECK | SWT.RADIO)) != 0) {
- if ((hasCheck = true) && hasImage) break;
- }
- }
-
- /*
- * Bug in Windows. If a menu contains items that have
- * images and can be checked, Windows does not include
- * the width of the image and the width of the check when
- * computing the width of the menu. When the longest item
- * does not have an image, the label and the accelerator
- * text can overlap. The fix is to use SetMenuItemInfo()
- * to indicate that all items have a bitmap and then include
- * the width of the widest bitmap in WM_MEASURECHILD.
- *
- * NOTE: This work around causes problems on Windows 98.
- * Under certain circumstances that have yet to be isolated,
- * some menus can become huge and blank. For now, do not
- * run the code on Windows 98.
- *
- * NOTE: This work around doesn't run on Vista because
- * WM_MEASURECHILD and WM_DRAWITEM cause Vista to lose
- * the menu theme.
- */
- if (!OS.IsWin95) {
- if (OS.WIN32_VERSION < OS.VERSION (6, 0)) {
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- info.fMask = OS.MIIM_BITMAP;
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if ((style & SWT.SEPARATOR) == 0) {
- if (item.image == null || foreground != -1) {
- info.hbmpItem = hasImage || foreground != -1 ? OS.HBMMENU_CALLBACK : 0;
- OS.SetMenuItemInfo (handle, item.id, false, info);
- }
- }
- }
- }
- }
-
- /* Update the menu to hide or show the space for bitmaps */
- MENUINFO lpcmi = new MENUINFO ();
- lpcmi.cbSize = MENUINFO.sizeof;
- lpcmi.fMask = OS.MIM_STYLE;
- OS.GetMenuInfo (handle, lpcmi);
- if (hasImage && !hasCheck) {
- lpcmi.dwStyle |= OS.MNS_CHECKORBMP;
- } else {
- lpcmi.dwStyle &= ~OS.MNS_CHECKORBMP;
- }
- OS.SetMenuInfo (handle, lpcmi);
-}
-
-void updateBackground () {
- if (hBrush == 0) OS.DeleteObject (hBrush);
- hBrush = 0;
- if (backgroundImage != null) {
- hBrush = OS.CreatePatternBrush (backgroundImage.handle);
- } else {
- if (background != -1) hBrush = OS.CreateSolidBrush (background);
- }
- MENUINFO lpcmi = new MENUINFO ();
- lpcmi.cbSize = MENUINFO.sizeof;
- lpcmi.fMask = OS.MIM_BACKGROUND;
- lpcmi.hbrBack = hBrush;
- OS.SetMenuInfo (handle, lpcmi);
-}
-
-void updateForeground () {
- if (OS.WIN32_VERSION < OS.VERSION (4, 10)) return;
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- int index = 0;
- while (OS.GetMenuItemInfo (handle, index, true, info)) {
- info.fMask = OS.MIIM_BITMAP;
- info.hbmpItem = OS.HBMMENU_CALLBACK;
- OS.SetMenuItemInfo (handle, index, true, info);
- index++;
- }
- redraw ();
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java
deleted file mode 100755
index 3950d5cebd..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java
+++ /dev/null
@@ -1,1174 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that issues notification when pressed and released.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>CHECK, CASCADE, PUSH, RADIO, SEPARATOR</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Arm, Help, Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR
- * may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class MenuItem extends Item {
- Menu parent, menu;
- int /*long*/ hBitmap;
- int id, accelerator;
- /*
- * Feature in Windows. On Windows 98, it is necessary
- * to add 4 pixels to the width of the image or the image
- * and text are too close. On other Windows platforms,
- * this causes the text of the longest item to touch the
- * accelerator text. The fix is to use smaller margins
- * everywhere but on Windows 98.
- */
- final static int MARGIN_WIDTH = OS.IsWin95 ? 2 : 1;
- final static int MARGIN_HEIGHT = OS.IsWin95 ? 2 : 1;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a menu control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#CHECK
- * @see SWT#CASCADE
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public MenuItem (Menu parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a menu control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#CHECK
- * @see SWT#CASCADE
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public MenuItem (Menu parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-MenuItem (Menu parent, Menu menu, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- this.menu = menu;
- if (menu != null) menu.cascade = this;
- display.addMenuItem (this);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the arm events are generated for the control, by sending
- * it one of the messages defined in the <code>ArmListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ArmListener
- * @see #removeArmListener
- */
-public void addArmListener (ArmListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Arm, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the help events are generated for the control, by sending
- * it one of the messages defined in the <code>HelpListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the menu item is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the stateMask field of the event object is valid.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the menu item is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.CASCADE, 0);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-boolean fillAccel (ACCEL accel) {
- accel.cmd = accel.key = accel.fVirt = 0;
- if (accelerator == 0 || !getEnabled ()) return false;
- if ((accelerator & SWT.COMMAND) != 0) return false;
- int fVirt = OS.FVIRTKEY;
- int key = accelerator & SWT.KEY_MASK;
- int vKey = Display.untranslateKey (key);
- if (vKey != 0) {
- key = vKey;
- } else {
- switch (key) {
- /*
- * Bug in Windows. For some reason, VkKeyScan
- * fails to map ESC to VK_ESCAPE and DEL to
- * VK_DELETE. The fix is to map these keys
- * as a special case.
- */
- case 27: key = OS.VK_ESCAPE; break;
- case 127: key = OS.VK_DELETE; break;
- default: {
- key = Display.wcsToMbcs ((char) key);
- if (key == 0) return false;
- if (OS.IsWinCE) {
- key = (int)/*64*/OS.CharUpper ((short) key);
- } else {
- vKey = OS.VkKeyScan ((short) key) & 0xFF;
- if (vKey == -1) {
- fVirt = 0;
- } else {
- key = vKey;
- }
- }
- }
- }
- }
- accel.key = (short) key;
- accel.cmd = (short) id;
- accel.fVirt = (byte) fVirt;
- if ((accelerator & SWT.ALT) != 0) accel.fVirt |= OS.FALT;
- if ((accelerator & SWT.SHIFT) != 0) accel.fVirt |= OS.FSHIFT;
- if ((accelerator & SWT.CONTROL) != 0) accel.fVirt |= OS.FCONTROL;
- return true;
-}
-
-void fixMenus (Decorations newParent) {
- if (menu != null) menu.fixMenus (newParent);
-}
-
-/**
- * Returns the widget accelerator. An accelerator is the bit-wise
- * OR of zero or more modifier masks and a key. Examples:
- * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
- * The default value is zero, indicating that the menu item does
- * not have an accelerator.
- *
- * @return the accelerator or 0
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAccelerator () {
- checkWidget ();
- return accelerator;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null).
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-/*public*/ Rectangle getBounds () {
- checkWidget ();
- if (OS.IsWinCE) return new Rectangle (0, 0, 0, 0);
- int index = parent.indexOf (this);
- if (index == -1) return new Rectangle (0, 0, 0, 0);
- if ((parent.style & SWT.BAR) != 0) {
- Decorations shell = parent.parent;
- if (shell.menuBar != parent) {
- return new Rectangle (0, 0, 0, 0);
- }
- int /*long*/ hwndShell = shell.handle;
- MENUBARINFO info1 = new MENUBARINFO ();
- info1.cbSize = MENUBARINFO.sizeof;
- if (!OS.GetMenuBarInfo (hwndShell, OS.OBJID_MENU, 1, info1)) {
- return new Rectangle (0, 0, 0, 0);
- }
- MENUBARINFO info2 = new MENUBARINFO ();
- info2.cbSize = MENUBARINFO.sizeof;
- if (!OS.GetMenuBarInfo (hwndShell, OS.OBJID_MENU, index + 1, info2)) {
- return new Rectangle (0, 0, 0, 0);
- }
- int x = info2.left - info1.left;
- int y = info2.top - info1.top;
- int width = info2.right - info2.left;
- int height = info2.bottom - info2.top;
- return new Rectangle (x, y, width, height);
- } else {
- int /*long*/ hMenu = parent.handle;
- RECT rect1 = new RECT ();
- if (!OS.GetMenuItemRect (0, hMenu, 0, rect1)) {
- return new Rectangle (0, 0, 0, 0);
- }
- RECT rect2 = new RECT ();
- if (!OS.GetMenuItemRect (0, hMenu, index, rect2)) {
- return new Rectangle (0, 0, 0, 0);
- }
- int x = rect2.left - rect1.left + 2;
- int y = rect2.top - rect1.top + 2;
- int width = rect2.right - rect2.left;
- int height = rect2.bottom - rect2.top;
- return new Rectangle (x, y, width, height);
- }
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled menu item is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget ();
- if ((OS.IsPPC || OS.IsSP) && parent.hwndCB != 0) {
- int /*long*/ hwndCB = parent.hwndCB;
- TBBUTTONINFO info = new TBBUTTONINFO ();
- info.cbSize = TBBUTTONINFO.sizeof;
- info.dwMask = OS.TBIF_STATE;
- OS.SendMessage (hwndCB, OS.TB_GETBUTTONINFO, id, info);
- return (info.fsState & OS.TBSTATE_ENABLED) != 0;
- }
- /*
- * Feature in Windows. For some reason, when the menu item
- * is a separator, GetMenuItemInfo() always indicates that
- * the item is not enabled. The fix is to track the enabled
- * state for separators.
- */
- if ((style & SWT.SEPARATOR) != 0) {
- return (state & DISABLED) == 0;
- }
- int /*long*/ hMenu = parent.handle;
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- info.fMask = OS.MIIM_STATE;
- boolean success;
- if (OS.IsWinCE) {
- int index = parent.indexOf (this);
- if (index == -1) error (SWT.ERROR_CANNOT_GET_ENABLED);
- success = OS.GetMenuItemInfo (hMenu, index, true, info);
- } else {
- success = OS.GetMenuItemInfo (hMenu, id, false, info);
- }
- if (!success) error (SWT.ERROR_CANNOT_GET_ENABLED);
- return (info.fState & (OS.MFS_DISABLED | OS.MFS_GRAYED)) == 0;
-}
-
-/**
- * Returns the receiver's cascade menu if it has one or null
- * if it does not. Only <code>CASCADE</code> menu items can have
- * a pull down menu. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pull down
- * menu is platform specific.
- *
- * @return the receiver's menu
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenu () {
- checkWidget ();
- return menu;
-}
-
-String getNameText () {
- if ((style & SWT.SEPARATOR) != 0) return "|";
- return super.getNameText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Menu</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked.
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget ();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
- if ((OS.IsPPC || OS.IsSP) && parent.hwndCB != 0) return false;
- int /*long*/ hMenu = parent.handle;
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- info.fMask = OS.MIIM_STATE;
- boolean success = OS.GetMenuItemInfo (hMenu, id, false, info);
- if (!success) error (SWT.ERROR_CANNOT_GET_SELECTION);
- return (info.fState & OS.MFS_CHECKED) !=0;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled menu item is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- return getEnabled () && parent.isEnabled ();
-}
-
-void releaseChildren (boolean destroy) {
- if (menu != null) {
- menu.release (false);
- menu = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
- id = -1;
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (menu != null) menu.dispose ();
- menu = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (hBitmap != 0) OS.DeleteObject (hBitmap);
- hBitmap = 0;
- if (accelerator != 0) {
- parent.destroyAccelerators ();
- }
- accelerator = 0;
- display.removeMenuItem (this);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the arm events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ArmListener
- * @see #addArmListener
- */
-public void removeArmListener (ArmListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Arm, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-void selectRadio () {
- int index = 0;
- MenuItem [] items = parent.getItems ();
- while (index < items.length && items [index] != this) index++;
- int i = index - 1;
- while (i >= 0 && items [i].setRadioSelection (false)) --i;
- int j = index + 1;
- while (j < items.length && items [j].setRadioSelection (false)) j++;
- setSelection (true);
-}
-
-/**
- * Sets the widget accelerator. An accelerator is the bit-wise
- * OR of zero or more modifier masks and a key. Examples:
- * <code>SWT.MOD1 | SWT.MOD2 | 'T', SWT.MOD3 | SWT.F2</code>.
- * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
- * The default value is zero, indicating that the menu item does
- * not have an accelerator.
- *
- * @param accelerator an integer that is the bit-wise OR of masks and a key
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAccelerator (int accelerator) {
- checkWidget ();
- if (this.accelerator == accelerator) return;
- this.accelerator = accelerator;
- parent.destroyAccelerators ();
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled menu item is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget ();
- if ((OS.IsPPC || OS.IsSP) && parent.hwndCB != 0) {
- int /*long*/ hwndCB = parent.hwndCB;
- TBBUTTONINFO info = new TBBUTTONINFO ();
- info.cbSize = TBBUTTONINFO.sizeof;
- info.dwMask = OS.TBIF_STATE;
- OS.SendMessage (hwndCB, OS.TB_GETBUTTONINFO, id, info);
- info.fsState &= ~OS.TBSTATE_ENABLED;
- if (enabled) info.fsState |= OS.TBSTATE_ENABLED;
- OS.SendMessage (hwndCB, OS.TB_SETBUTTONINFO, id, info);
- } else {
- /*
- * Feature in Windows. For some reason, when the menu item
- * is a separator, GetMenuItemInfo() always indicates that
- * the item is not enabled. The fix is to track the enabled
- * state for separators.
- */
- if ((style & SWT.SEPARATOR) != 0) {
- if (enabled) {
- state &= ~DISABLED;
- } else {
- state |= DISABLED;
- }
- }
- int /*long*/ hMenu = parent.handle;
- if (OS.IsWinCE) {
- int index = parent.indexOf (this);
- if (index == -1) return;
- int uEnable = OS.MF_BYPOSITION | (enabled ? OS.MF_ENABLED : OS.MF_GRAYED);
- OS.EnableMenuItem (hMenu, index, uEnable);
- } else {
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- info.fMask = OS.MIIM_STATE;
- boolean success = OS.GetMenuItemInfo (hMenu, id, false, info);
- if (!success) error (SWT.ERROR_CANNOT_SET_ENABLED);
- int bits = OS.MFS_DISABLED | OS.MFS_GRAYED;
- if (enabled) {
- if ((info.fState & bits) == 0) return;
- info.fState &= ~bits;
- } else {
- if ((info.fState & bits) == bits) return;
- info.fState |= bits;
- }
- success = OS.SetMenuItemInfo (hMenu, id, false, info);
- if (!success) {
- /*
- * Bug in Windows. For some reason SetMenuItemInfo(),
- * returns a fail code when setting the enabled or
- * selected state of a default item, but sets the
- * state anyway. The fix is to ignore the error.
- *
- * NOTE: This only happens on Vista.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- success = id == OS.GetMenuDefaultItem (hMenu, OS.MF_BYCOMMAND, OS.GMDI_USEDISABLED);
- }
- if (!success) error (SWT.ERROR_CANNOT_SET_ENABLED);
- }
- }
- }
- parent.destroyAccelerators ();
- parent.redraw ();
-}
-
-/**
- * Sets the image the receiver will display to the argument.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept (for example, Windows NT).
- * Furthermore, some platforms (such as GTK), cannot display both
- * a check box and an image at the same time. Instead, they hide
- * the image and display the check box.
- * </p>
- *
- * @param image the image to display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return;
- super.setImage (image);
- if (OS.IsWinCE) {
- if ((OS.IsPPC || OS.IsSP) && parent.hwndCB != 0) {
- int /*long*/ hwndCB = parent.hwndCB;
- TBBUTTONINFO info = new TBBUTTONINFO ();
- info.cbSize = TBBUTTONINFO.sizeof;
- info.dwMask = OS.TBIF_IMAGE;
- info.iImage = parent.imageIndex (image);
- OS.SendMessage (hwndCB, OS.TB_SETBUTTONINFO, id, info);
- }
- return;
- }
- if (OS.WIN32_VERSION < OS.VERSION (4, 10)) return;
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- info.fMask = OS.MIIM_BITMAP;
- if (parent.foreground != -1) {
- info.hbmpItem = OS.HBMMENU_CALLBACK;
- } else {
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- if (hBitmap != 0) OS.DeleteObject (hBitmap);
- info.hbmpItem = hBitmap = image != null ? Display.create32bitDIB (image) : 0;
- } else {
- info.hbmpItem = image != null ? OS.HBMMENU_CALLBACK : 0;
- }
- }
- int /*long*/ hMenu = parent.handle;
- OS.SetMenuItemInfo (hMenu, id, false, info);
- parent.redraw ();
-}
-
-/**
- * Sets the receiver's pull down menu to the argument.
- * Only <code>CASCADE</code> menu items can have a
- * pull down menu. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pull down
- * menu is platform specific.
- * <p>
- * Note: Disposing of a menu item that has a pull down menu
- * will dispose of the menu. To avoid this behavior, set the
- * menu to null before the menu item is disposed.
- * </p>
- *
- * @param menu the new pull down menu
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_MENU_NOT_DROP_DOWN - if the menu is not a drop down menu</li>
- * <li>ERROR_MENUITEM_NOT_CASCADE - if the menu item is not a <code>CASCADE</code></li>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenu (Menu menu) {
- checkWidget ();
-
- /* Check to make sure the new menu is valid */
- if ((style & SWT.CASCADE) == 0) {
- error (SWT.ERROR_MENUITEM_NOT_CASCADE);
- }
- if (menu != null) {
- if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.DROP_DOWN) == 0) {
- error (SWT.ERROR_MENU_NOT_DROP_DOWN);
- }
- if (menu.parent != parent.parent) {
- error (SWT.ERROR_INVALID_PARENT);
- }
- }
- setMenu (menu, false);
-}
-
-void setMenu (Menu menu, boolean dispose) {
-
- /* Assign the new menu */
- Menu oldMenu = this.menu;
- if (oldMenu == menu) return;
- if (oldMenu != null) oldMenu.cascade = null;
- this.menu = menu;
-
- /* Assign the new menu in the OS */
- if ((OS.IsPPC || OS.IsSP) && parent.hwndCB != 0) {
- if (OS.IsPPC) {
- int /*long*/ hwndCB = parent.hwndCB;
- int /*long*/ hMenu = menu == null ? 0 : menu.handle;
- OS.SendMessage (hwndCB, OS.SHCMBM_SETSUBMENU, id, hMenu);
- }
- if (OS.IsSP) error (SWT.ERROR_CANNOT_SET_MENU);
- } else {
- int /*long*/ hMenu = parent.handle;
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- info.fMask = OS.MIIM_DATA;
- int index = 0;
- while (OS.GetMenuItemInfo (hMenu, index, true, info)) {
- if (info.dwItemData == id) break;
- index++;
- }
- if (info.dwItemData != id) return;
- int cch = 128;
- int /*long*/ hHeap = OS.GetProcessHeap ();
- int byteCount = cch * TCHAR.sizeof;
- int /*long*/ pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- info.fMask = OS.MIIM_STATE | OS.MIIM_ID | OS.MIIM_DATA;
- /*
- * Bug in Windows. When GetMenuItemInfo() is used to get the text,
- * for an item that has a bitmap set using MIIM_BITMAP, the text is
- * not returned. This means that when SetMenuItemInfo() is used to
- * set the submenu and the current menu state, the text is lost.
- * The fix is use MIIM_BITMAP and MIIM_STRING.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- info.fMask |= OS.MIIM_BITMAP | OS.MIIM_STRING;
- } else {
- info.fMask |= OS.MIIM_TYPE;
- }
- info.dwTypeData = pszText;
- info.cch = cch;
- boolean success = OS.GetMenuItemInfo (hMenu, index, true, info);
- if (menu != null) {
- menu.cascade = this;
- info.fMask |= OS.MIIM_SUBMENU;
- info.hSubMenu = menu.handle;
- }
- if (OS.IsWinCE) {
- OS.RemoveMenu (hMenu, index, OS.MF_BYPOSITION);
- /*
- * On WinCE, InsertMenuItem() is not available. The fix is to
- * use SetMenuItemInfo() but this call does not set the menu item
- * state and submenu. The fix is to use InsertMenu() to insert
- * the item, SetMenuItemInfo() to set the string and EnableMenuItem()
- * and CheckMenuItem() to set the state.
- */
- int /*long*/ uIDNewItem = id;
- int uFlags = OS.MF_BYPOSITION;
- if (menu != null) {
- uFlags |= OS.MF_POPUP;
- uIDNewItem = menu.handle;
- }
- TCHAR lpNewItem = new TCHAR (0, " ", true);
- success = OS.InsertMenu (hMenu, index, uFlags, uIDNewItem, lpNewItem);
- if (success) {
- info.fMask = OS.MIIM_DATA | OS.MIIM_TYPE;
- success = OS.SetMenuItemInfo (hMenu, index, true, info);
- if ((info.fState & (OS.MFS_DISABLED | OS.MFS_GRAYED)) != 0) {
- OS.EnableMenuItem (hMenu, index, OS.MF_BYPOSITION | OS.MF_GRAYED);
- }
- if ((info.fState & OS.MFS_CHECKED) != 0) {
- OS.CheckMenuItem (hMenu, index, OS.MF_BYPOSITION | OS.MF_CHECKED);
- }
- }
- } else {
- if (dispose || oldMenu == null) {
- success = OS.SetMenuItemInfo (hMenu, index, true, info);
- } else {
- /*
- * Feature in Windows. When SetMenuItemInfo () is used to
- * set a submenu and the menu item already has a submenu,
- * Windows destroys the previous menu. This is undocumented
- * and unexpected but not necessarily wrong. The fix is to
- * remove the item with RemoveMenu () which does not destroy
- * the submenu and then insert the item with InsertMenuItem ().
- */
- OS.RemoveMenu (hMenu, index, OS.MF_BYPOSITION);
- success = OS.InsertMenuItem (hMenu, index, true, info);
- }
- }
- if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
- if (!success) error (SWT.ERROR_CANNOT_SET_MENU);
- }
- parent.destroyAccelerators ();
-}
-
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-
-/**
- * Sets the selection state of the receiver.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked.
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget ();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
- if ((OS.IsPPC || OS.IsSP) && parent.hwndCB != 0) return;
- int /*long*/ hMenu = parent.handle;
- if (OS.IsWinCE) {
- int index = parent.indexOf (this);
- if (index == -1) return;
- int uCheck = OS.MF_BYPOSITION | (selected ? OS.MF_CHECKED : OS.MF_UNCHECKED);
- OS.CheckMenuItem (hMenu, index, uCheck);
- } else {
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- info.fMask = OS.MIIM_STATE;
- boolean success = OS.GetMenuItemInfo (hMenu, id, false, info);
- if (!success) error (SWT.ERROR_CANNOT_SET_SELECTION);
- info.fState &= ~OS.MFS_CHECKED;
- if (selected) info.fState |= OS.MFS_CHECKED;
- success = OS.SetMenuItemInfo (hMenu, id, false, info);
- if (!success) {
- /*
- * Bug in Windows. For some reason SetMenuItemInfo(),
- * returns a fail code when setting the enabled or
- * selected state of a default item, but sets the
- * state anyway. The fix is to ignore the error.
- *
- * NOTE: This only happens on Vista.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- success = id == OS.GetMenuDefaultItem (hMenu, OS.MF_BYCOMMAND, OS.GMDI_USEDISABLED);
- }
- if (!success) error (SWT.ERROR_CANNOT_SET_SELECTION);
- }
- }
- parent.redraw ();
-}
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character and accelerator text.
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- * <p>
- * Accelerator text is indicated by the '\t' character.
- * On platforms that support accelerator text, the text
- * that follows the '\t' character is displayed to the user,
- * typically indicating the key stroke that will cause
- * the item to become selected. On most platforms, the
- * accelerator text appears right aligned in the menu.
- * Setting the accelerator text does not install the
- * accelerator key sequence. The accelerator key sequence
- * is installed using #setAccelerator.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setAccelerator
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- if (text.equals (string)) return;
- super.setText (string);
- int /*long*/ hHeap = OS.GetProcessHeap ();
- int /*long*/ pszText = 0;
- boolean success = false;
- if ((OS.IsPPC || OS.IsSP) && parent.hwndCB != 0) {
- /*
- * Bug in WinCE PPC. Tool items on the menubar don't resize
- * correctly when the character '&' is used (even when it
- * is a sequence '&&'). The fix is to remove all '&' from
- * the string.
- */
- if (string.indexOf ('&') != -1) {
- int length = string.length ();
- char[] text = new char [length];
- string.getChars( 0, length, text, 0);
- int i = 0, j = 0;
- for (i=0; i<length; i++) {
- if (text[i] != '&') text [j++] = text [i];
- }
- if (j < i) string = new String (text, 0, j);
- }
- /* Use the character encoding for the default locale */
- TCHAR buffer = new TCHAR (0, string, true);
- int byteCount = buffer.length () * TCHAR.sizeof;
- pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (pszText, buffer, byteCount);
- int /*long*/ hwndCB = parent.hwndCB;
- TBBUTTONINFO info2 = new TBBUTTONINFO ();
- info2.cbSize = TBBUTTONINFO.sizeof;
- info2.dwMask = OS.TBIF_TEXT;
- info2.pszText = pszText;
- success = OS.SendMessage (hwndCB, OS.TB_SETBUTTONINFO, id, info2) != 0;
- } else {
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- int /*long*/ hMenu = parent.handle;
-
- /* Use the character encoding for the default locale */
- TCHAR buffer = new TCHAR (0, string, true);
- int byteCount = buffer.length () * TCHAR.sizeof;
- pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (pszText, buffer, byteCount);
- /*
- * Bug in Windows 2000. For some reason, when MIIM_TYPE is set
- * on a menu item that also has MIIM_BITMAP, the MIIM_TYPE clears
- * the MIIM_BITMAP style. The fix is to use MIIM_STRING.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- info.fMask = OS.MIIM_STRING;
- } else {
- info.fMask = OS.MIIM_TYPE;
- info.fType = widgetStyle ();
- }
- info.dwTypeData = pszText;
- success = OS.SetMenuItemInfo (hMenu, id, false, info);
- }
- if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
- if (!success) error (SWT.ERROR_CANNOT_SET_TEXT);
- parent.redraw ();
-}
-
-int widgetStyle () {
- int bits = 0;
- Decorations shell = parent.parent;
- if ((shell.style & SWT.MIRRORED) != 0) {
- if ((parent.style & SWT.LEFT_TO_RIGHT) != 0) {
- bits |= OS.MFT_RIGHTJUSTIFY | OS.MFT_RIGHTORDER;
- }
- } else {
- if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) {
- bits |= OS.MFT_RIGHTJUSTIFY | OS.MFT_RIGHTORDER;
- }
- }
- if ((style & SWT.SEPARATOR) != 0) return bits | OS.MFT_SEPARATOR;
- if ((style & SWT.RADIO) != 0) return bits | OS.MFT_RADIOCHECK;
- return bits | OS.MFT_STRING;
-}
-
-LRESULT wmCommandChild (int /*long*/ wParam, int /*long*/ lParam) {
- if ((style & SWT.CHECK) != 0) {
- setSelection (!getSelection ());
- } else {
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) != 0) {
- setSelection (!getSelection ());
- } else {
- selectRadio ();
- }
- }
- }
- Event event = new Event ();
- setInputState (event, SWT.Selection);
- postEvent (SWT.Selection, event);
- return null;
-}
-
-LRESULT wmDrawChild (int /*long*/ wParam, int /*long*/ lParam) {
- DRAWITEMSTRUCT struct = new DRAWITEMSTRUCT ();
- OS.MoveMemory (struct, lParam, DRAWITEMSTRUCT.sizeof);
- if (image != null) {
- GCData data = new GCData();
- data.device = display;
- GC gc = GC.win32_new (struct.hDC, data);
- /*
- * Bug in Windows. When a bitmap is included in the
- * menu bar, the HDC seems to already include the left
- * coordinate. The fix is to ignore this value when
- * the item is in a menu bar.
- */
- int x = (parent.style & SWT.BAR) != 0 ? MARGIN_WIDTH * 2 : struct.left;
- Image image = getEnabled () ? this.image : new Image (display, this.image, SWT.IMAGE_DISABLE);
- gc.drawImage (image, x, struct.top + MARGIN_HEIGHT);
- if (this.image != image) image.dispose ();
- gc.dispose ();
- }
- if (parent.foreground != -1) OS.SetTextColor (struct.hDC, parent.foreground);
- return null;
-}
-
-LRESULT wmMeasureChild (int /*long*/ wParam, int /*long*/ lParam) {
- MEASUREITEMSTRUCT struct = new MEASUREITEMSTRUCT ();
- OS.MoveMemory (struct, lParam, MEASUREITEMSTRUCT.sizeof);
- int width = 0, height = 0;
- if (image != null) {
- Rectangle rect = image.getBounds ();
- width = rect.width;
- height = rect.height;
- } else {
- /*
- * Bug in Windows. If a menu contains items that have
- * images and can be checked, Windows does not include
- * the width of the image and the width of the check when
- * computing the width of the menu. When the longest item
- * does not have an image, the label and the accelerator
- * text can overlap. The fix is to use SetMenuItemInfo()
- * to indicate that all items have a bitmap and then include
- * the width of the widest bitmap in WM_MEASURECHILD.
- */
- MENUINFO lpcmi = new MENUINFO ();
- lpcmi.cbSize = MENUINFO.sizeof;
- lpcmi.fMask = OS.MIM_STYLE;
- int /*long*/ hMenu = parent.handle;
- OS.GetMenuInfo (hMenu, lpcmi);
- if ((lpcmi.dwStyle & OS.MNS_CHECKORBMP) == 0) {
- MenuItem [] items = parent.getItems ();
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (item.image != null) {
- Rectangle rect = item.image.getBounds ();
- width = Math.max (width, rect.width);
- }
- }
- }
- }
- if (width != 0 || height != 0) {
- struct.itemWidth = width + MARGIN_WIDTH * 2;
- struct.itemHeight = height + MARGIN_HEIGHT * 2;
- OS.MoveMemory (lParam, struct, MEASUREITEMSTRUCT.sizeof);
- }
- return null;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MessageBox.java
deleted file mode 100755
index b151ed404b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MessageBox.java
+++ /dev/null
@@ -1,265 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class are used to inform or warn the user.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, ICON_WARNING, ICON_WORKING</dd>
- * <dd>OK, OK | CANCEL</dd>
- * <dd>YES | NO, YES | NO | CANCEL</dd>
- * <dd>RETRY | CANCEL</dd>
- * <dd>ABORT | RETRY | IGNORE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION, ICON_QUESTION,
- * ICON_WARNING and ICON_WORKING may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class MessageBox extends Dialog {
- String message = "";
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public MessageBox (Shell parent) {
- this (parent, SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_QUESTION
- * @see SWT#ICON_WARNING
- * @see SWT#ICON_WORKING
- * @see SWT#OK
- * @see SWT#CANCEL
- * @see SWT#YES
- * @see SWT#NO
- * @see SWT#ABORT
- * @see SWT#RETRY
- * @see SWT#IGNORE
- */
-public MessageBox (Shell parent, int style) {
- super (parent, checkStyle (parent, checkStyle (style)));
- checkSubclass ();
-}
-
-static int checkStyle (int style) {
- int mask = (SWT.YES | SWT.NO | SWT.OK | SWT.CANCEL | SWT.ABORT | SWT.RETRY | SWT.IGNORE);
- int bits = style & mask;
- if (bits == SWT.OK || bits == SWT.CANCEL || bits == (SWT.OK | SWT.CANCEL)) return style;
- if (bits == SWT.YES || bits == SWT.NO || bits == (SWT.YES | SWT.NO) || bits == (SWT.YES | SWT.NO | SWT.CANCEL)) return style;
- if (bits == (SWT.RETRY | SWT.CANCEL) || bits == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) return style;
- style = (style & ~mask) | SWT.OK;
- return style;
-}
-
-/**
- * Returns the dialog's message, or an empty string if it does not have one.
- * The message is a description of the purpose for which the dialog was opened.
- * This message will be visible in the dialog while it is open.
- *
- * @return the message
- */
-public String getMessage () {
- return message;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return the ID of the button that was selected to dismiss the
- * message box (e.g. SWT.OK, SWT.CANCEL, etc.)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public int open () {
-
- /* Compute the MessageBox style */
- int buttonBits = 0;
- if ((style & SWT.OK) == SWT.OK) buttonBits = OS.MB_OK;
- if ((style & (SWT.OK | SWT.CANCEL)) == (SWT.OK | SWT.CANCEL)) buttonBits = OS.MB_OKCANCEL;
- if ((style & (SWT.YES | SWT.NO)) == (SWT.YES | SWT.NO)) buttonBits = OS.MB_YESNO;
- if ((style & (SWT.YES | SWT.NO | SWT.CANCEL)) == (SWT.YES | SWT.NO | SWT.CANCEL)) buttonBits = OS.MB_YESNOCANCEL;
- if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) buttonBits = OS.MB_RETRYCANCEL;
- if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) buttonBits = OS.MB_ABORTRETRYIGNORE;
- if (buttonBits == 0) buttonBits = OS.MB_OK;
-
- int iconBits = 0;
- if ((style & SWT.ICON_ERROR) != 0) iconBits = OS.MB_ICONERROR;
- if ((style & SWT.ICON_INFORMATION) != 0) iconBits = OS.MB_ICONINFORMATION;
- if ((style & SWT.ICON_QUESTION) != 0) iconBits = OS.MB_ICONQUESTION;
- if ((style & SWT.ICON_WARNING) != 0) iconBits = OS.MB_ICONWARNING;
- if ((style & SWT.ICON_WORKING) != 0) iconBits = OS.MB_ICONINFORMATION;
-
- /* Only MB_APPLMODAL is supported on WinCE */
- int modalBits = 0;
- if (OS.IsWinCE) {
- if ((style & (SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- modalBits = OS.MB_APPLMODAL;
- }
- } else {
- if ((style & SWT.PRIMARY_MODAL) != 0) modalBits = OS.MB_APPLMODAL;
- if ((style & SWT.APPLICATION_MODAL) != 0) modalBits = OS.MB_TASKMODAL;
- if ((style & SWT.SYSTEM_MODAL) != 0) modalBits = OS.MB_SYSTEMMODAL;
- }
-
- int bits = buttonBits | iconBits | modalBits;
- if ((style & SWT.RIGHT_TO_LEFT) != 0) bits |= OS.MB_RTLREADING | OS.MB_RIGHT;
- if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) {
- if (parent != null && (parent.style & SWT.MIRRORED) != 0) {
- bits |= OS.MB_RTLREADING | OS.MB_RIGHT;
- }
- }
-
- /*
- * Feature in Windows. System modal is not supported
- * on Windows 95 and NT. The fix is to convert system
- * modal to task modal.
- */
- if ((bits & OS.MB_SYSTEMMODAL) != 0) {
- bits |= OS.MB_TASKMODAL;
- bits &= ~OS.MB_SYSTEMMODAL;
- /* Force a system modal message box to the front */
- bits |= OS.MB_TOPMOST;
- }
-
- /*
- * Feature in Windows. In order for MB_TASKMODAL to work,
- * the parent HWND of the MessageBox () call must be NULL.
- * If the parent is not NULL, MB_TASKMODAL behaves the
- * same as MB_APPLMODAL. The fix to set the parent HWND
- * anyway and not rely on MB_MODAL to work by making the
- * parent be temporarily modal.
- */
- int /*long*/ hwndOwner = parent != null ? parent.handle : 0;
- Dialog oldModal = null;
- Display display = null;
- if ((bits & OS.MB_TASKMODAL) != 0) {
- display = parent.getDisplay ();
- oldModal = display.getModalDialog ();
- display.setModalDialog (this);
- }
-
- /* Open the message box */
- /* Use the character encoding for the default locale */
- TCHAR buffer1 = new TCHAR (0, message, true);
- TCHAR buffer2 = new TCHAR (0, title, true);
- int code = OS.MessageBox (hwndOwner, buffer1, buffer2, bits);
-
- /* Clear the temporarily dialog modal parent */
- if ((bits & OS.MB_TASKMODAL) != 0) {
- display.setModalDialog (oldModal);
- }
-
- /*
- * This code is intentionally commented. On some
- * platforms, the owner window is repainted right
- * away when a dialog window exits. This behavior
- * is currently unspecified.
- */
-// if (hwndOwner != 0) OS.UpdateWindow (hwndOwner);
-
- /* Compute and return the result */
- if (code != 0) {
- int type = bits & 0x0F;
- if (type == OS.MB_OK) return SWT.OK;
- if (type == OS.MB_OKCANCEL) {
- return (code == OS.IDOK) ? SWT.OK : SWT.CANCEL;
- }
- if (type == OS.MB_YESNO) {
- return (code == OS.IDYES) ? SWT.YES : SWT.NO;
- }
- if (type == OS.MB_YESNOCANCEL) {
- if (code == OS.IDYES) return SWT.YES;
- if (code == OS.IDNO) return SWT.NO;
- return SWT.CANCEL;
- }
- if (type == OS.MB_RETRYCANCEL) {
- return (code == OS.IDRETRY) ? SWT.RETRY : SWT.CANCEL;
- }
- if (type == OS.MB_ABORTRETRYIGNORE) {
- if (code == OS.IDRETRY) return SWT.RETRY;
- if (code == OS.IDABORT) return SWT.ABORT;
- return SWT.IGNORE;
- }
- }
- return SWT.CANCEL;
-}
-
-/**
- * Sets the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @param string the message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- */
-public void setMessage (String string) {
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- message = string;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java
deleted file mode 100755
index ea29f26be4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java
+++ /dev/null
@@ -1,458 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of the receiver represent an unselectable
- * user interface object that is used to display progress,
- * typically in the form of a bar.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SMOOTH, HORIZONTAL, VERTICAL, INDETERMINATE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#progressbar">ProgressBar snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ProgressBar extends Control {
- static final int DELAY = 100;
- static final int TIMER_ID = 100;
- static final int MINIMUM_WIDTH = 100;
- static final int /*long*/ ProgressBarProc;
- static final TCHAR ProgressBarClass = new TCHAR (0, OS.PROGRESS_CLASS, true);
- static {
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, ProgressBarClass, lpWndClass);
- ProgressBarProc = lpWndClass.lpfnWndProc;
- /*
- * Feature in Windows. The progress bar window class
- * does not include CS_DBLCLKS. This means that these
- * controls will not get double click messages such as
- * WM_LBUTTONDBLCLK. The fix is to register a new
- * window class with CS_DBLCLKS.
- *
- * NOTE: Screen readers look for the exact class name
- * of the control in order to provide the correct kind
- * of assistance. Therefore, it is critical that the
- * new window class have the same name. It is possible
- * to register a local window class with the same name
- * as a global class. Since bits that affect the class
- * are being changed, it is possible that other native
- * code, other than SWT, could create a control with
- * this class name, and fail unexpectedly.
- */
- int /*long*/ hInstance = OS.GetModuleHandle (null);
- int /*long*/ hHeap = OS.GetProcessHeap ();
- lpWndClass.hInstance = hInstance;
- lpWndClass.style &= ~OS.CS_GLOBALCLASS;
- lpWndClass.style |= OS.CS_DBLCLKS;
- int byteCount = ProgressBarClass.length () * TCHAR.sizeof;
- int /*long*/ lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (lpszClassName, ProgressBarClass, byteCount);
- lpWndClass.lpszClassName = lpszClassName;
- OS.RegisterClass (lpWndClass);
- OS.HeapFree (hHeap, 0, lpszClassName);
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SMOOTH
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#INDETERMINATE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ProgressBar (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (ProgressBarProc, hwnd, msg, wParam, lParam);
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += OS.GetSystemMetrics (OS.SM_CXHSCROLL) * 10;
- height += OS.GetSystemMetrics (OS.SM_CYHSCROLL);
- } else {
- width += OS.GetSystemMetrics (OS.SM_CXVSCROLL);
- height += OS.GetSystemMetrics (OS.SM_CYVSCROLL) * 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-
-void createHandle () {
- super.createHandle ();
- startTimer ();
-}
-
-int defaultForeground () {
- return OS.GetSysColor (OS.COLOR_HIGHLIGHT);
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.PBM_GETRANGE, 0, 0);
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.PBM_GETRANGE, 1, 0);
-}
-
-/**
- * Returns the single 'selection' that is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.PBM_GETPOS, 0, 0);
-}
-
-/**
- * Returns the state of the receiver. The value will be one of:
- * <ul>
- * <li>{@link SWT#NORMAL}</li>
- * <li>{@link SWT#ERROR}</li>
- * <li>{@link SWT#PAUSED}</li>
- * </ul>
- *
- * @return the state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public int getState () {
- checkWidget ();
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- int state = (int)/*64*/OS.SendMessage (handle, OS.PBM_GETSTATE, 0, 0);
- switch (state) {
- case OS.PBST_NORMAL: return SWT.NORMAL;
- case OS.PBST_ERROR: return SWT.ERROR;
- case OS.PBST_PAUSED: return SWT.PAUSED;
- }
- }
- return SWT.NORMAL;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- stopTimer ();
-}
-
-void startTimer () {
- if ((style & SWT.INDETERMINATE) != 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if (OS.COMCTL32_MAJOR < 6 || (bits & OS.PBS_MARQUEE) == 0) {
- OS.SetTimer (handle, TIMER_ID, DELAY, 0);
- } else {
- OS.SendMessage (handle, OS.PBM_SETMARQUEE, 1, DELAY);
- }
- }
-}
-
-void stopTimer () {
- if ((style & SWT.INDETERMINATE) != 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if (OS.COMCTL32_MAJOR < 6 || (bits & OS.PBS_MARQUEE) == 0) {
- OS.KillTimer (handle, TIMER_ID);
- } else {
- OS.SendMessage (handle, OS.PBM_SETMARQUEE, 0, 0);
- }
- }
-}
-
-void setBackgroundPixel (int pixel) {
- if (pixel == -1) pixel = OS.CLR_DEFAULT;
- OS.SendMessage (handle, OS.PBM_SETBKCOLOR, 0, pixel);
-}
-
-void setForegroundPixel (int pixel) {
- if (pixel == -1) pixel = OS.CLR_DEFAULT;
- OS.SendMessage (handle, OS.PBM_SETBARCOLOR, 0, pixel);
-}
-
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget ();
- int minimum = (int)/*64*/OS.SendMessage (handle, OS.PBM_GETRANGE, 1, 0);
- if (0 <= minimum && minimum < value) {
- OS.SendMessage (handle, OS.PBM_SETRANGE32, minimum, value);
- }
-}
-
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is negative or is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be nonnegative and less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget ();
- int maximum = (int)/*64*/OS.SendMessage (handle, OS.PBM_GETRANGE, 0, 0);
- if (0 <= value && value < maximum) {
- OS.SendMessage (handle, OS.PBM_SETRANGE32, value, maximum);
- }
-}
-
-/**
- * Sets the single 'selection' that is the receiver's
- * position to the argument which must be greater than or equal
- * to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget ();
- /*
- * Feature in Vista. When the progress bar is not in
- * a normal state, PBM_SETPOS does not set the position
- * of the bar when the selection is equal to the minimum.
- * This is undocumented. The fix is to temporarily
- * set the state to PBST_NORMAL, set the position, then
- * reset the state.
- */
- int /*long*/ state = 0;
- boolean fixSelection = false;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- int minumum = (int)/*64*/OS.SendMessage (handle, OS.PBM_GETRANGE, 1, 0);
- int selection = (int)/*64*/OS.SendMessage (handle, OS.PBM_GETPOS, 0, 0);
- if (selection == minumum) {
- fixSelection = true;
- state = OS.SendMessage (handle, OS.PBM_GETSTATE, 0, 0);
- OS.SendMessage (handle, OS.PBM_SETSTATE, OS.PBST_NORMAL, 0);
- }
- }
- OS.SendMessage (handle, OS.PBM_SETPOS, value, 0);
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- if (fixSelection) OS.SendMessage (handle, OS.PBM_SETSTATE, state, 0);
- }
-}
-
-/**
- * Sets the state of the receiver. The state must be one of these values:
- * <ul>
- * <li>{@link SWT#NORMAL}</li>
- * <li>{@link SWT#ERROR}</li>
- * <li>{@link SWT#PAUSED}</li>
- * </ul>
- *
- * @param state the new state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setState (int state) {
- checkWidget ();
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- switch (state) {
- case SWT.NORMAL:
- OS.SendMessage (handle, OS.PBM_SETSTATE, OS.PBST_NORMAL, 0);
- break;
- case SWT.ERROR:
- OS.SendMessage (handle, OS.PBM_SETSTATE, OS.PBST_ERROR, 0);
- break;
- case SWT.PAUSED:
- OS.SendMessage (handle, OS.PBM_SETSTATE, OS.PBST_PAUSED, 0);
- break;
- }
- }
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle ();
- if ((style & SWT.SMOOTH) != 0) bits |= OS.PBS_SMOOTH;
- if ((style & SWT.VERTICAL) != 0) bits |= OS.PBS_VERTICAL;
- if ((style & SWT.INDETERMINATE) != 0) bits |= OS.PBS_MARQUEE;
- return bits;
-}
-
-TCHAR windowClass () {
- return ProgressBarClass;
-}
-
-int /*long*/ windowProc () {
- return ProgressBarProc;
-}
-
-LRESULT WM_GETDLGCODE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_GETDLGCODE (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. The progress bar does
- * not implement WM_GETDLGCODE. As a result,
- * a progress bar takes focus and takes part
- * in tab traversal. This behavior, while
- * unspecified, is unwanted. The fix is to
- * implement WM_GETDLGCODE to behave like a
- * STATIC control.
- */
- return new LRESULT (OS.DLGC_STATIC);
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SIZE (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. When a progress bar with the style
- * PBS_MARQUEE becomes too small, the animation (currently
- * a small bar moving from right to left) does not have
- * enough space to draw. The result is that the progress
- * bar does not appear to be moving. The fix is to detect
- * this case, clear the PBS_MARQUEE style and emulate the
- * animation using PBM_STEPIT.
- *
- * NOTE: This only happens on Window XP.
- */
- if ((style & SWT.INDETERMINATE) != 0) {
- if (OS.COMCTL32_MAJOR >= 6) {
- forceResize ();
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- int newBits = oldBits;
- if (rect.right - rect.left < MINIMUM_WIDTH) {
- newBits &= ~OS.PBS_MARQUEE;
- } else {
- newBits |= OS.PBS_MARQUEE;
- }
- if (newBits != oldBits) {
- stopTimer ();
- OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
- startTimer ();
- }
- }
- }
- return result;
-}
-
-LRESULT WM_TIMER (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_TIMER (wParam, lParam);
- if (result != null) return result;
- if ((style & SWT.INDETERMINATE) != 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if (OS.COMCTL32_MAJOR < 6 || (bits & OS.PBS_MARQUEE) == 0) {
- if (wParam == TIMER_ID) {
- OS.SendMessage (handle, OS.PBM_STEPIT, 0, 0);
- }
- }
- }
- return result;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Sash.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Sash.java
deleted file mode 100755
index 8df5d6bf1b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Sash.java
+++ /dev/null
@@ -1,421 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of the receiver represent a selectable user interface object
- * that allows the user to drag a rubber banded outline of the sash within
- * the parent control.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL, SMOOTH</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#sash">Sash snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Sash extends Control {
- boolean dragging;
- int startX, startY, lastX, lastY;
- final static int INCREMENT = 1;
- final static int PAGE_INCREMENT = 9;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#SMOOTH
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Sash (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the x, y, width, and height fields of the event object are valid.
- * If the receiver is being dragged, the event object detail field contains the value <code>SWT.DRAG</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- return OS.DefWindowProc (hwnd, msg, wParam, lParam);
-}
-
-void createHandle () {
- super.createHandle ();
- state |= THEME_BACKGROUND;
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += DEFAULT_WIDTH; height += 3;
- } else {
- width += 3; height += DEFAULT_HEIGHT;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-
-void drawBand (int x, int y, int width, int height) {
- if ((style & SWT.SMOOTH) != 0) return;
- int /*long*/ hwndTrack = parent.handle;
- byte [] bits = {-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0};
- int /*long*/ stippleBitmap = OS.CreateBitmap (8, 8, 1, 1, bits);
- int /*long*/ stippleBrush = OS.CreatePatternBrush (stippleBitmap);
- int /*long*/ hDC = OS.GetDCEx (hwndTrack, 0, OS.DCX_CACHE);
- int /*long*/ oldBrush = OS.SelectObject (hDC, stippleBrush);
- OS.PatBlt (hDC, x, y, width, height, OS.PATINVERT);
- OS.SelectObject (hDC, oldBrush);
- OS.ReleaseDC (hwndTrack, hDC);
- OS.DeleteObject (stippleBrush);
- OS.DeleteObject (stippleBitmap);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-TCHAR windowClass () {
- return display.windowClass;
-}
-
-int /*long*/ windowProc () {
- return display.windowProc;
-}
-
-LRESULT WM_ERASEBKGND (int /*long*/ wParam, int /*long*/ lParam) {
- super.WM_ERASEBKGND (wParam, lParam);
- drawBackground (wParam);
- return LRESULT.ONE;
-}
-
-LRESULT WM_KEYDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_KEYDOWN (wParam, lParam);
- if (result != null) return result;
- switch ((int)/*64*/wParam) {
- case OS.VK_LEFT:
- case OS.VK_RIGHT:
- case OS.VK_UP:
- case OS.VK_DOWN:
-
- /* Calculate the new x or y position */
- if (OS.GetKeyState (OS.VK_LBUTTON) < 0) return result;
- int step = OS.GetKeyState (OS.VK_CONTROL) < 0 ? INCREMENT : PAGE_INCREMENT;
- POINT pt = new POINT ();
- if ((style & SWT.VERTICAL) != 0) {
- if (wParam == OS.VK_UP || wParam == OS.VK_DOWN) break;
- pt.x = wParam == OS.VK_LEFT ? -step : step;
- } else {
- if (wParam == OS.VK_LEFT || wParam == OS.VK_RIGHT) break;
- pt.y = wParam == OS.VK_UP ? -step : step;
- }
- int /*long*/ hwndTrack = parent.handle;
- OS.MapWindowPoints (handle, hwndTrack, pt, 1);
- RECT rect = new RECT (), clientRect = new RECT ();
- OS.GetWindowRect (handle, rect);
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- OS.GetClientRect (hwndTrack, clientRect);
- int clientWidth = clientRect.right - clientRect.left;
- int clientHeight = clientRect.bottom - clientRect.top;
- int newX = lastX, newY = lastY;
- if ((style & SWT.VERTICAL) != 0) {
- newX = Math.min (Math.max (0, pt.x - startX), clientWidth - width);
- } else {
- newY = Math.min (Math.max (0, pt.y - startY), clientHeight - height);
- }
- if (newX == lastX && newY == lastY) return result;
-
- /* Update the pointer position */
- POINT cursorPt = new POINT ();
- cursorPt.x = pt.x; cursorPt.y = pt.y;
- OS.ClientToScreen (hwndTrack, cursorPt);
- if ((style & SWT.VERTICAL) != 0) {
- cursorPt.y += height / 2;
- }
- else {
- cursorPt.x += width / 2;
- }
- OS.SetCursorPos (cursorPt.x, cursorPt.y);
-
- Event event = new Event ();
- event.x = newX;
- event.y = newY;
- event.width = width;
- event.height = height;
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return LRESULT.ZERO;
- if (event.doit) {
- if ((style & SWT.SMOOTH) != 0) {
- setBounds (event.x, event.y, width, height);
- }
- }
- return result;
- }
- return result;
-}
-
-LRESULT WM_GETDLGCODE (int /*long*/ wParam, int /*long*/ lParam) {
- return new LRESULT (OS.DLGC_STATIC);
-}
-
-LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_LBUTTONDOWN (wParam, lParam);
- if (result == LRESULT.ZERO) return result;
-
- /* Compute the banding rectangle */
- int /*long*/ hwndTrack = parent.handle;
- POINT pt = new POINT ();
- OS.POINTSTOPOINT (pt, lParam);
- RECT rect = new RECT ();
- OS.GetWindowRect (handle, rect);
- OS.MapWindowPoints (handle, 0, pt, 1);
- startX = pt.x - rect.left;
- startY = pt.y - rect.top;
- OS.MapWindowPoints (0, hwndTrack, rect, 2);
- lastX = rect.left;
- lastY = rect.top;
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
-
- /* The event must be sent because doit flag is used */
- Event event = new Event ();
- event.x = lastX;
- event.y = lastY;
- event.width = width;
- event.height = height;
- if ((style & SWT.SMOOTH) == 0) {
- event.detail = SWT.DRAG;
- }
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return LRESULT.ZERO;
-
- /* Draw the banding rectangle */
- if (event.doit) {
- dragging = true;
- lastX = event.x;
- lastY = event.y;
- menuShell ().bringToTop ();
- if (isDisposed ()) return LRESULT.ZERO;
- if (OS.IsWinCE) {
- OS.UpdateWindow (hwndTrack);
- } else {
- int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (hwndTrack, null, 0, flags);
- }
- drawBand (event.x, event.y, width, height);
- if ((style & SWT.SMOOTH) != 0) {
- setBounds (event.x, event.y, width, height);
- // widget could be disposed at this point
- }
- }
- return result;
-}
-
-LRESULT WM_LBUTTONUP (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_LBUTTONUP (wParam, lParam);
- if (result == LRESULT.ZERO) return result;
-
- /* Compute the banding rectangle */
- if (!dragging) return result;
- dragging = false;
- RECT rect = new RECT ();
- OS.GetWindowRect (handle, rect);
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
-
- /* The event must be sent because doit flag is used */
- Event event = new Event ();
- event.x = lastX;
- event.y = lastY;
- event.width = width;
- event.height = height;
- drawBand (event.x, event.y, width, height);
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return result;
- if (event.doit) {
- if ((style & SWT.SMOOTH) != 0) {
- setBounds (event.x, event.y, width, height);
- // widget could be disposed at this point
- }
- }
- return result;
-}
-
-LRESULT WM_MOUSEMOVE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_MOUSEMOVE (wParam, lParam);
- if (result != null) return result;
- if (!dragging || (wParam & OS.MK_LBUTTON) == 0) return result;
-
- /* Compute the banding rectangle */
- POINT pt = new POINT ();
- OS.POINTSTOPOINT (pt, lParam);
- int /*long*/ hwndTrack = parent.handle;
- OS.MapWindowPoints (handle, hwndTrack, pt, 1);
- RECT rect = new RECT (), clientRect = new RECT ();
- OS.GetWindowRect (handle, rect);
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- OS.GetClientRect (hwndTrack, clientRect);
- int newX = lastX, newY = lastY;
- if ((style & SWT.VERTICAL) != 0) {
- int clientWidth = clientRect.right - clientRect.left;
- newX = Math.min (Math.max (0, pt.x - startX), clientWidth - width);
- } else {
- int clientHeight = clientRect.bottom - clientRect.top;
- newY = Math.min (Math.max (0, pt.y - startY), clientHeight - height);
- }
- if (newX == lastX && newY == lastY) return result;
- drawBand (lastX, lastY, width, height);
-
- /* The event must be sent because doit flag is used */
- Event event = new Event ();
- event.x = newX;
- event.y = newY;
- event.width = width;
- event.height = height;
- if ((style & SWT.SMOOTH) == 0) {
- event.detail = SWT.DRAG;
- }
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return LRESULT.ZERO;
- if (event.doit) {
- lastX = event.x;
- lastY = event.y;
- }
- if (OS.IsWinCE) {
- OS.UpdateWindow (hwndTrack);
- } else {
- int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (hwndTrack, null, 0, flags);
- }
- drawBand (lastX, lastY, width, height);
- if ((style & SWT.SMOOTH) != 0) {
- setBounds (lastX, lastY, width, height);
- // widget could be disposed at this point
- }
- return result;
-}
-
-LRESULT WM_SETCURSOR (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SETCURSOR (wParam, lParam);
- if (result != null) return result;
- int hitTest = (short) OS.LOWORD (lParam);
- if (hitTest == OS.HTCLIENT) {
- int /*long*/ hCursor = 0;
- if ((style & SWT.HORIZONTAL) != 0) {
- hCursor = OS.LoadCursor (0, OS.IDC_SIZENS);
- } else {
- hCursor = OS.LoadCursor (0, OS.IDC_SIZEWE);
- }
- OS.SetCursor (hCursor);
- return LRESULT.ONE;
- }
- return result;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scale.java
deleted file mode 100755
index ce6b0119dc..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scale.java
+++ /dev/null
@@ -1,561 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of the receiver represent a selectable user
- * interface object that present a range of continuous
- * numeric values.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#scale">Scale snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Scale extends Control {
- boolean ignoreResize, ignoreSelection;
- static final int /*long*/ TrackBarProc;
- static final TCHAR TrackBarClass = new TCHAR (0, OS.TRACKBAR_CLASS, true);
- static {
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, TrackBarClass, lpWndClass);
- TrackBarProc = lpWndClass.lpfnWndProc;
- /*
- * Feature in Windows. The track bar window class
- * does not include CS_DBLCLKS. This means that these
- * controls will not get double click messages such as
- * WM_LBUTTONDBLCLK. The fix is to register a new
- * window class with CS_DBLCLKS.
- *
- * NOTE: Screen readers look for the exact class name
- * of the control in order to provide the correct kind
- * of assistance. Therefore, it is critical that the
- * new window class have the same name. It is possible
- * to register a local window class with the same name
- * as a global class. Since bits that affect the class
- * are being changed, it is possible that other native
- * code, other than SWT, could create a control with
- * this class name, and fail unexpectedly.
- */
- int /*long*/ hInstance = OS.GetModuleHandle (null);
- int /*long*/ hHeap = OS.GetProcessHeap ();
- lpWndClass.hInstance = hInstance;
- lpWndClass.style &= ~OS.CS_GLOBALCLASS;
- lpWndClass.style |= OS.CS_DBLCLKS;
- int byteCount = TrackBarClass.length () * TCHAR.sizeof;
- int /*long*/ lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (lpszClassName, TrackBarClass, byteCount);
- lpWndClass.lpszClassName = lpszClassName;
- OS.RegisterClass (lpWndClass);
- OS.HeapFree (hHeap, 0, lpszClassName);
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Scale (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the receiver's value.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (TrackBarProc, hwnd, msg, wParam, lParam);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- RECT rect = new RECT ();
- OS.SendMessage (handle, OS.TBM_GETTHUMBRECT, 0, rect);
- if ((style & SWT.HORIZONTAL) != 0) {
- width += OS.GetSystemMetrics (OS.SM_CXHSCROLL) * 10;
- int scrollY = OS.GetSystemMetrics (OS.SM_CYHSCROLL);
- height += (rect.top * 2) + scrollY + (scrollY / 3);
- } else {
- int scrollX = OS.GetSystemMetrics (OS.SM_CXVSCROLL);
- width += (rect.left * 2) + scrollX + (scrollX / 3);
- height += OS.GetSystemMetrics (OS.SM_CYVSCROLL) * 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-
-void createHandle () {
- super.createHandle ();
- state |= THEME_BACKGROUND | DRAW_BACKGROUND;
- OS.SendMessage (handle, OS.TBM_SETRANGEMAX, 0, 100);
- OS.SendMessage (handle, OS.TBM_SETPAGESIZE, 0, 10);
- OS.SendMessage (handle, OS.TBM_SETTICFREQ, 10, 0);
-}
-
-int defaultForeground () {
- return OS.GetSysColor (OS.COLOR_BTNFACE);
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.TBM_GETLINESIZE, 0, 0);
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.TBM_GETRANGEMAX, 0, 0);
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget ();
- return (int)OS.SendMessage (handle, OS.TBM_GETRANGEMIN, 0, 0);
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.TBM_GETPAGESIZE, 0, 0);
-}
-
-/**
- * Returns the 'selection', which is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.TBM_GETPOS, 0, 0);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-void setBackgroundImage (int /*long*/ hImage) {
- super.setBackgroundImage (hImage);
- /*
- * Bug in Windows. Changing the background color of the Scale
- * widget and calling InvalidateRect() still draws with the old
- * color. The fix is to send a fake WM_SIZE event to cause
- * it to redraw with the new background color.
- */
- ignoreResize = true;
- OS.SendMessage (handle, OS.WM_SIZE, 0, 0);
- ignoreResize = false;
-}
-
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- /*
- * Bug in Windows. Changing the background color of the Scale
- * widget and calling InvalidateRect() still draws with the old
- * color. The fix is to send a fake WM_SIZE event to cause
- * it to redraw with the new background color.
- */
- ignoreResize = true;
- OS.SendMessage (handle, OS.WM_SIZE, 0, 0);
- ignoreResize = false;
-}
-
-void setBounds (int x, int y, int width, int height, int flags, boolean defer) {
- /*
- * Bug in Windows. If SetWindowPos() is called on a
- * track bar with either SWP_DRAWFRAME, a new size,
- * or both during mouse down, the track bar posts a
- * WM_MOUSEMOVE message when the mouse has not moved.
- * The window proc for the track bar uses WM_MOUSEMOVE
- * to issue WM_HSCROLL or WM_SCROLL events to notify
- * the application that the slider has changed. The
- * end result is that when the user requests a page
- * scroll and the application resizes the track bar
- * during the change notification, continuous stream
- * of WM_MOUSEMOVE messages are generated and the
- * thumb moves to the mouse position rather than
- * scrolling by a page. The fix is to clear the
- * SWP_DRAWFRAME flag.
- *
- * NOTE: There is no fix for the WM_MOUSEMOVE that
- * is generated by a new size. Clearing SWP_DRAWFRAME
- * does not fix the problem. However, it is unlikely
- * that the programmer will resize the control during
- * mouse down.
- */
- flags &= ~OS.SWP_DRAWFRAME;
- super.setBounds (x, y, width, height, flags, true);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param increment the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int increment) {
- checkWidget ();
- if (increment < 1) return;
- int minimum = (int)/*64*/OS.SendMessage (handle, OS.TBM_GETRANGEMIN, 0, 0);
- int maximum = (int)/*64*/OS.SendMessage (handle, OS.TBM_GETRANGEMAX, 0, 0);
- if (increment > maximum - minimum) return;
- OS.SendMessage (handle, OS.TBM_SETLINESIZE, 0, increment);
-}
-
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget ();
- int minimum = (int)/*64*/OS.SendMessage (handle, OS.TBM_GETRANGEMIN, 0, 0);
- if (0 <= minimum && minimum < value) {
- OS.SendMessage (handle, OS.TBM_SETRANGEMAX, 1, value);
- }
-}
-
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is negative or is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be nonnegative and less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget ();
- int maximum = (int)/*64*/OS.SendMessage (handle, OS.TBM_GETRANGEMAX, 0, 0);
- if (0 <= value && value < maximum) {
- OS.SendMessage (handle, OS.TBM_SETRANGEMIN, 1, value);
- }
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param pageIncrement the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int pageIncrement) {
- checkWidget ();
- if (pageIncrement < 1) return;
- int minimum = (int)/*64*/OS.SendMessage (handle, OS.TBM_GETRANGEMIN, 0, 0);
- int maximum = (int)/*64*/OS.SendMessage (handle, OS.TBM_GETRANGEMAX, 0, 0);
- if (pageIncrement > maximum - minimum) return;
- OS.SendMessage (handle, OS.TBM_SETPAGESIZE, 0, pageIncrement);
- OS.SendMessage (handle, OS.TBM_SETTICFREQ, pageIncrement, 0);
-}
-
-/**
- * Sets the 'selection', which is the receiver's value,
- * to the argument which must be greater than or equal to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget ();
- OS.SendMessage (handle, OS.TBM_SETPOS, 1, value);
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle () | OS.WS_TABSTOP | OS.TBS_BOTH | OS.TBS_AUTOTICKS;
- if ((style & SWT.HORIZONTAL) != 0) return bits | OS.TBS_HORZ | OS.TBS_DOWNISLEFT;
- return bits | OS.TBS_VERT;
-}
-
-TCHAR windowClass () {
- return TrackBarClass;
-}
-
-int /*long*/ windowProc () {
- return TrackBarProc;
-}
-
-LRESULT WM_MOUSEWHEEL (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_MOUSEWHEEL (wParam, lParam);
- if (result != null) return result;
- /*
- * Bug in Windows. When a track bar slider is changed
- * from WM_MOUSEWHEEL, it does not always send either
- * a WM_VSCROLL or M_HSCROLL to notify the application
- * of the change. The fix is to detect that the selection
- * has changed and that notification has not been issued
- * and send the selection event.
- */
- int oldPosition = (int)/*64*/OS.SendMessage (handle, OS.TBM_GETPOS, 0, 0);
- ignoreSelection = true;
- int /*long*/ code = callWindowProc (handle, OS.WM_MOUSEWHEEL, wParam, lParam);
- ignoreSelection = false;
- int newPosition = (int)/*64*/OS.SendMessage (handle, OS.TBM_GETPOS, 0, 0);
- if (oldPosition != newPosition) {
- /*
- * Send the event because WM_HSCROLL and WM_VSCROLL
- * are sent from a modal message loop in windows that
- * is active when the user is scrolling.
- */
- sendEvent (SWT.Selection);
- // widget could be disposed at this point
- }
- return new LRESULT (code);
-}
-
-LRESULT WM_PAINT (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Bug in Windows. For some reason, when WM_CTLCOLORSTATIC
- * is used to implement transparency and returns a NULL brush,
- * Windows doesn't always draw the track bar. It seems that
- * it is drawn correctly the first time. It is possible that
- * Windows double buffers the control and the double buffer
- * strategy fails when WM_CTLCOLORSTATIC returns unexpected
- * results. The fix is to send a fake WM_SIZE to force it
- * to redraw every time there is a WM_PAINT.
- */
- boolean fixPaint = findBackgroundControl () != null;
- if (!fixPaint) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- Control control = findThemeControl ();
- fixPaint = control != null;
- }
- }
- if (fixPaint) {
- boolean redraw = getDrawing () && OS.IsWindowVisible (handle);
- if (redraw) OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- ignoreResize = true;
- OS.SendMessage (handle, OS.WM_SIZE, 0, 0);
- ignoreResize = false;
- if (redraw) {
- OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
- OS.InvalidateRect (handle, null, false);
- }
- }
- return super.WM_PAINT (wParam, lParam);
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- if (ignoreResize) return null;
- return super.WM_SIZE (wParam, lParam);
-}
-
-LRESULT wmScrollChild (int /*long*/ wParam, int /*long*/ lParam) {
-
- /* Do nothing when scrolling is ending */
- int code = OS.LOWORD (wParam);
- switch (code) {
- case OS.TB_ENDTRACK:
- case OS.TB_THUMBPOSITION:
- return null;
- }
-
- if (!ignoreSelection) {
- Event event = new Event ();
- /*
- * This code is intentionally commented. The event
- * detail field is not currently supported on all
- * platforms.
- */
-// switch (code) {
-// case OS.TB_TOP: event.detail = SWT.HOME; break;
-// case OS.TB_BOTTOM: event.detail = SWT.END; break;
-// case OS.TB_LINEDOWN: event.detail = SWT.ARROW_DOWN; break;
-// case OS.TB_LINEUP: event.detail = SWT.ARROW_UP; break;
-// case OS.TB_PAGEDOWN: event.detail = SWT.PAGE_DOWN; break;
-// case OS.TB_PAGEUP: event.detail = SWT.PAGE_UP; break;
-// }
- /*
- * Send the event because WM_HSCROLL and WM_VSCROLL
- * are sent from a modal message loop in windows that
- * is active when the user is scrolling.
- */
- sendEvent (SWT.Selection, event);
- // widget could be disposed at this point
- }
- return null;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ScrollBar.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ScrollBar.java
deleted file mode 100755
index 80e8ca68af..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ScrollBar.java
+++ /dev/null
@@ -1,952 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that represent a range of positive, numeric values.
- * <p>
- * At any given moment, a given scroll bar will have a
- * single 'selection' that is considered to be its
- * value, which is constrained to be within the range of
- * values the scroll bar represents (that is, between its
- * <em>minimum</em> and <em>maximum</em> values).
- * </p><p>
- * Typically, scroll bars will be made up of five areas:
- * <ol>
- * <li>an arrow button for decrementing the value</li>
- * <li>a page decrement area for decrementing the value by a larger amount</li>
- * <li>a <em>thumb</em> for modifying the value by mouse dragging</li>
- * <li>a page increment area for incrementing the value by a larger amount</li>
- * <li>an arrow button for incrementing the value</li>
- * </ol>
- * Based on their style, scroll bars are either <code>HORIZONTAL</code>
- * (which have a left facing button for decrementing the value and a
- * right facing button for incrementing it) or <code>VERTICAL</code>
- * (which have an upward facing button for decrementing the value
- * and a downward facing buttons for incrementing it).
- * </p><p>
- * On some platforms, the size of the scroll bar's thumb can be
- * varied relative to the magnitude of the range of values it
- * represents (that is, relative to the difference between its
- * maximum and minimum values). Typically, this is used to
- * indicate some proportional value such as the ratio of the
- * visible area of a document to the total amount of space that
- * it would take to display it. SWT supports setting the thumb
- * size even if the underlying platform does not, but in this
- * case the appearance of the scroll bar will not change.
- * </p><p>
- * Scroll bars are created by specifying either <code>H_SCROLL</code>,
- * <code>V_SCROLL</code> or both when creating a <code>Scrollable</code>.
- * They are accessed from the <code>Scrollable</code> using
- * <code>getHorizontalBar</code> and <code>getVerticalBar</code>.
- * </p><p>
- * Note: Scroll bars are not Controls. On some platforms, scroll bars
- * that appear as part of some standard controls such as a text or list
- * have no operating system resources and are not children of the control.
- * For this reason, scroll bars are treated specially. To create a control
- * that looks like a scroll bar but has operating system resources, use
- * <code>Slider</code>.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see Slider
- * @see Scrollable
- * @see Scrollable#getHorizontalBar
- * @see Scrollable#getVerticalBar
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class ScrollBar extends Widget {
- Scrollable parent;
- int increment, pageIncrement;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-ScrollBar (Scrollable parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget ();
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values:
- * <code>SWT.NONE</code> - for the end of a drag.
- * <code>SWT.DRAG</code>.
- * <code>SWT.HOME</code>.
- * <code>SWT.END</code>.
- * <code>SWT.ARROW_DOWN</code>.
- * <code>SWT.ARROW_UP</code>.
- * <code>SWT.PAGE_DOWN</code>.
- * <code>SWT.PAGE_UP</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-void createWidget () {
- increment = 1;
- pageIncrement = 10;
- /*
- * Do not set the initial values of the maximum
- * or the thumb. These values normally default
- * to 100 and 10 but may have been set already
- * by the widget that owns the scroll bar. For
- * example, a scroll bar that is created for a
- * list widget, setting these defaults would
- * override the initial values provided by the
- * list widget.
- */
-}
-
-void destroyWidget () {
- int /*long*/ hwnd = hwndScrollBar ();
- int type = scrollBarType ();
- if (OS.IsWinCE) {
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_RANGE | OS.SIF_PAGE;
- info.nPage = 101;
- info.nMax = 100;
- info.nMin = 0;
- OS.SetScrollInfo (hwnd, type, info, true);
- } else {
- OS.ShowScrollBar (hwnd, type, false);
- }
- parent.destroyScrollBar (style);
- releaseHandle ();
- //This code is intentionally commented
- //parent.sendEvent (SWT.Resize);
-}
-
-Rectangle getBounds () {
-// checkWidget ();
- parent.forceResize ();
- RECT rect = new RECT ();
- OS.GetClientRect (parent.scrolledHandle (), rect);
- int x = 0, y = 0, width, height;
- if ((style & SWT.HORIZONTAL) != 0) {
- y = rect.bottom - rect.top;
- width = rect.right - rect.left;
- height = OS.GetSystemMetrics (OS.SM_CYHSCROLL);
- } else {
- x = rect.right - rect.left;
- width = OS.GetSystemMetrics (OS.SM_CXVSCROLL);
- height = rect.bottom - rect.top;
- }
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- return (state & DISABLED) == 0;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget();
- return increment;
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget();
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_RANGE;
- int /*long*/ hwnd = hwndScrollBar ();
- int type = scrollBarType ();
- OS.GetScrollInfo (hwnd, type, info);
- return info.nMax;
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget();
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_RANGE;
- int /*long*/ hwnd = hwndScrollBar ();
- int type = scrollBarType ();
- OS.GetScrollInfo (hwnd, type, info);
- return info.nMin;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget();
- return pageIncrement;
-}
-
-/**
- * Returns the receiver's parent, which must be a Scrollable.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Scrollable getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns the single 'selection' that is the receiver's value.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget();
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_POS;
- int /*long*/ hwnd = hwndScrollBar ();
- int type = scrollBarType ();
- OS.GetScrollInfo (hwnd, type, info);
- return info.nPos;
-}
-
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- parent.forceResize ();
- RECT rect = new RECT ();
- OS.GetClientRect (parent.scrolledHandle (), rect);
- int width, height;
- if ((style & SWT.HORIZONTAL) != 0) {
- width = rect.right - rect.left;
- height = OS.GetSystemMetrics (OS.SM_CYHSCROLL);
- } else {
- width = OS.GetSystemMetrics (OS.SM_CXVSCROLL);
- height = rect.bottom - rect.top;
- }
- return new Point (width, height);
-}
-
-/**
- * Returns the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values.
- *
- * @return the thumb value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ScrollBar
- */
-public int getThumb () {
- checkWidget();
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_PAGE;
- int /*long*/ hwnd = hwndScrollBar ();
- int type = scrollBarType ();
- OS.GetScrollInfo (hwnd, type, info);
- if (info.nPage != 0) --info.nPage;
- return info.nPage;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
- SCROLLBARINFO psbi = new SCROLLBARINFO ();
- psbi.cbSize = SCROLLBARINFO.sizeof;
- int idObject = (style & SWT.VERTICAL) != 0 ? OS.OBJID_VSCROLL : OS.OBJID_HSCROLL;
- OS.GetScrollBarInfo (hwndScrollBar (), idObject, psbi);
- return (psbi.rgstate [0] & OS.STATE_SYSTEM_INVISIBLE) == 0;
- }
- return (state & HIDDEN) == 0;
-}
-
-int /*long*/ hwndScrollBar () {
- return parent.scrolledHandle ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return getVisible () && parent.isVisible ();
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (parent.horizontalBar == this) parent.horizontalBar = null;
- if (parent.verticalBar == this) parent.verticalBar = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-int scrollBarType () {
- return (style & SWT.VERTICAL) != 0 ? OS.SB_VERT : OS.SB_HORZ;
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- /*
- * This line is intentionally commented. Currently
- * always show scrollbar as being enabled and visible.
- */
-// if (OS.IsWinCE) error (SWT.ERROR_NOT_IMPLEMENTED);
- if (!OS.IsWinCE) {
- int /*long*/ hwnd = hwndScrollBar ();
- int type = scrollBarType ();
- int flags = enabled ? OS.ESB_ENABLE_BOTH : OS.ESB_DISABLE_BOTH;
- OS.EnableScrollBar (hwnd, type, flags);
- if (enabled) {
- state &= ~DISABLED;
- } else {
- state |= DISABLED;
- }
- }
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- increment = value;
-}
-
-/**
- * Sets the maximum. If this value is negative or less than or
- * equal to the minimum, the value is ignored. If necessary, first
- * the thumb and then the selection are adjusted to fit within the
- * new range.
- *
- * @param value the new maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget();
- if (value < 0) return;
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- int /*long*/ hwnd = hwndScrollBar ();
- int type = scrollBarType ();
- info.fMask = OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL;
- OS.GetScrollInfo (hwnd, type, info);
- if (value - info.nMin - info.nPage < 1) return;
- info.nMax = value;
- SetScrollInfo (hwnd, type, info, true);
-}
-
-/**
- * Sets the minimum value. If this value is negative or greater
- * than or equal to the maximum, the value is ignored. If necessary,
- * first the thumb and then the selection are adjusted to fit within
- * the new range.
- *
- * @param value the new minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget();
- if (value < 0) return;
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- int /*long*/ hwnd = hwndScrollBar ();
- int type = scrollBarType ();
- info.fMask = OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL;
- OS.GetScrollInfo (hwnd, type, info);
- if (info.nMax - value - info.nPage < 1) return;
- info.nMin = value;
- SetScrollInfo (hwnd, type, info, true);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- pageIncrement = value;
-}
-
-boolean SetScrollInfo (int /*long*/ hwnd, int flags, SCROLLINFO info, boolean fRedraw) {
- /*
- * Bug in Windows. For some reason, when SetScrollInfo()
- * is used with SIF_POS and the scroll bar is hidden,
- * the opposite scroll bar is incorrectly made visible
- * so that the next time the parent is resized (or another
- * scroll bar operation is performed), the opposite scroll
- * bar draws. The fix is to hide both scroll bars.
- */
- boolean barVisible = false;
- boolean visible = getVisible ();
-
- /*
- * This line is intentionally commented. Currently
- * always show scrollbar as being enabled and visible.
- */
-// if (OS.IsWinCE) error (SWT.ERROR_NOT_IMPLEMENTED);
- ScrollBar bar = null;
- if (!OS.IsWinCE) {
- switch (flags) {
- case OS.SB_HORZ:
- bar = parent.getVerticalBar ();
- break;
- case OS.SB_VERT:
- bar = parent.getHorizontalBar ();
- break;
- }
- barVisible = bar != null && bar.getVisible ();
- }
- if (!visible || (state & DISABLED) != 0) fRedraw = false;
- boolean result = OS.SetScrollInfo (hwnd, flags, info, fRedraw);
-
- /*
- * Bug in Windows. For some reason, when the widget
- * is a standard scroll bar, and SetScrollInfo() is
- * called with SIF_RANGE or SIF_PAGE, the widget is
- * incorrectly made visible so that the next time the
- * parent is resized (or another scroll bar operation
- * is performed), the scroll bar draws. The fix is
- * to hide the scroll bar (again) when already hidden.
- */
- if (!visible) {
- /*
- * This line is intentionally commented. Currently
- * always show scrollbar as being enabled and visible.
- */
-// if (OS.IsWinCE) error (SWT.ERROR_NOT_IMPLEMENTED);
- if (!OS.IsWinCE) {
- OS.ShowScrollBar (hwnd, !barVisible ? OS.SB_BOTH : flags, false);
- }
- }
-
- /*
- * Bug in Windows. When only one scroll bar is visible,
- * and the thumb changes using SIF_RANGE or SIF_PAGE
- * from being visible to hidden, the opposite scroll
- * bar is incorrectly made visible. The next time the
- * parent is resized (or another scroll bar operation
- * is performed), the opposite scroll bar draws. The
- * fix is to hide the opposite scroll bar again.
- *
- * NOTE: This problem only happens on Vista
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- if (visible && bar != null && !barVisible) {
- OS.ShowScrollBar (hwnd, flags == OS.SB_HORZ ? OS.SB_VERT : OS.SB_HORZ, false);
- }
- }
-
- /*
- * Feature in Windows. Using SIF_DISABLENOSCROLL,
- * SetScrollInfo () can change enabled and disabled
- * state of the scroll bar causing a scroll bar that
- * was disabled by the application to become enabled.
- * The fix is to disable the scroll bar (again) when
- * the application has disabled the scroll bar.
- */
- if ((state & DISABLED) != 0) {
- /*
- * This line is intentionally commented. Currently
- * always show scrollbar as being enabled and visible.
- */
-// if (OS.IsWinCE) error (SWT.ERROR_NOT_IMPLEMENTED);
- if (!OS.IsWinCE) {
- OS.EnableScrollBar (hwnd, flags, OS.ESB_DISABLE_BOTH);
- }
- }
- return result;
-}
-
-/**
- * Sets the single <em>selection</em> that is the receiver's
- * value to the argument which must be greater than or equal
- * to zero.
- *
- * @param selection the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int selection) {
- checkWidget();
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- int /*long*/ hwnd = hwndScrollBar ();
- int type = scrollBarType ();
- info.fMask = OS.SIF_POS;
- info.nPos = selection;
- SetScrollInfo (hwnd, type, info, true);
-}
-
-/**
- * Sets the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values. This new
- * value will be ignored if it is less than one, and will be
- * clamped if it exceeds the receiver's current range.
- *
- * @param value the new thumb value, which must be at least one and not
- * larger than the size of the current range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setThumb (int value) {
- checkWidget();
- if (value < 1) return;
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- int /*long*/ hwnd = hwndScrollBar ();
- int type = scrollBarType ();
- info.fMask = OS.SIF_PAGE | OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL;
- OS.GetScrollInfo (hwnd, type, info);
- info.nPage = value;
- if (info.nPage != 0) info.nPage++;
- SetScrollInfo (hwnd, type, info, true);
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, thumb, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param thumb the new thumb value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- checkWidget();
- if (minimum < 0) return;
- if (maximum < 0) return;
- if (thumb < 1) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- this.increment = increment;
- this.pageIncrement = pageIncrement;
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_POS | OS.SIF_PAGE | OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL;
- info.nPos = selection;
- info.nMin = minimum;
- info.nMax = maximum;
- info.nPage = thumb;
- if (info.nPage != 0) info.nPage++;
- int /*long*/ hwnd = hwndScrollBar ();
- int type = scrollBarType ();
- SetScrollInfo (hwnd, type, info, true);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget();
- if (visible == getVisible ()) return;
-
- /*
- * On Windows CE, use SIF_DISABLENOSCROLL to show and
- * hide the scroll bar when the page size is equal to
- * the range.
- */
- if (OS.IsWinCE) {
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- int /*long*/ hwnd = hwndScrollBar ();
- int type = scrollBarType ();
- info.fMask = OS.SIF_RANGE | OS.SIF_PAGE;
- if (visible) info.fMask |= OS.SIF_DISABLENOSCROLL;
- OS.GetScrollInfo (hwnd, type, info);
- if (info.nPage == info.nMax - info.nMin + 1) {
- /*
- * Bug in Windows. When the only changed flag to
- * SetScrollInfo () is OS.SIF_DISABLENOSCROLL,
- * Windows does not update the scroll bar state.
- * The fix is to increase and then decrease the
- * maximum, causing Windows to honour the flag.
- */
- int max = info.nMax;
- info.nMax++;
- OS.SetScrollInfo (hwnd, type, info, false);
- info.nMax = max;
- OS.SetScrollInfo (hwnd, type, info, true);
- } else {
- /*
- * This line is intentionally commented. Currently
- * always show scrollbar as being enabled and visible.
- */
-// if (OS.IsWinCE) error (SWT.ERROR_NOT_IMPLEMENTED);
- }
- return;
- }
-
- /*
- * Set the state bits before calling ShowScrollBar ()
- * because hiding and showing the scroll bar can cause
- * WM_SIZE messages when the client area is resized.
- * Setting the state before the call means that code
- * that runs during WM_SIZE that queries the visibility
- * of the scroll bar will get the correct value.
- */
- state = visible ? state & ~HIDDEN : state | HIDDEN;
- int /*long*/ hwnd = hwndScrollBar ();
- int type = scrollBarType ();
- if (OS.ShowScrollBar (hwnd, type, visible)) {
- /*
- * Bug in Windows. For some reason, when the widget
- * is a standard scroll bar, and SetScrollInfo () is
- * called with SIF_RANGE or SIF_PAGE while the widget
- * is not visible, the widget is incorrectly disabled
- * even though the values for SIF_RANGE and SIF_PAGE,
- * when set for a visible scroll bar would not disable
- * the scroll bar. The fix is to enable the scroll bar
- * when not disabled by the application and the current
- * scroll bar ranges would cause the scroll bar to be
- * enabled had they been set when the scroll bar was
- * visible.
- */
- if ((state & DISABLED) == 0) {
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_RANGE | OS.SIF_PAGE;
- OS.GetScrollInfo (hwnd, type, info);
- if (info.nMax - info.nMin - info.nPage >= 0) {
- OS.EnableScrollBar (hwnd, type, OS.ESB_ENABLE_BOTH);
- }
- }
- sendEvent (visible ? SWT.Show : SWT.Hide);
- // widget could be disposed at this point
- }
-}
-
-LRESULT wmScrollChild (int /*long*/ wParam, int /*long*/ lParam) {
-
- /* Do nothing when scrolling is ending */
- int code = OS.LOWORD (wParam);
- if (code == OS.SB_ENDSCROLL) return null;
-
- /*
- * Send the event because WM_HSCROLL and
- * WM_VSCROLL are sent from a modal message
- * loop in Windows that is active when the
- * user is scrolling.
- */
- Event event = new Event ();
- switch (code) {
- case OS.SB_THUMBPOSITION: event.detail = SWT.NONE; break;
- case OS.SB_THUMBTRACK: event.detail = SWT.DRAG; break;
- case OS.SB_TOP: event.detail = SWT.HOME; break;
- case OS.SB_BOTTOM: event.detail = SWT.END; break;
- case OS.SB_LINEDOWN: event.detail = SWT.ARROW_DOWN; break;
- case OS.SB_LINEUP: event.detail = SWT.ARROW_UP; break;
- case OS.SB_PAGEDOWN: event.detail = SWT.PAGE_DOWN; break;
- case OS.SB_PAGEUP: event.detail = SWT.PAGE_UP; break;
- }
- sendEvent (SWT.Selection, event);
- // the widget could be destroyed at this point
- return null;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scrollable.java
deleted file mode 100755
index c4ac04add5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scrollable.java
+++ /dev/null
@@ -1,495 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * This class is the abstract superclass of all classes which
- * represent controls that have standard scroll bars.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>H_SCROLL, V_SCROLL</dd>
- * <dt><b>Events:</b>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public abstract class Scrollable extends Control {
- ScrollBar horizontalBar, verticalBar;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Scrollable () {
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#H_SCROLL
- * @see SWT#V_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Scrollable (Composite parent, int style) {
- super (parent, style);
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- return OS.DefWindowProc (hwnd, msg, wParam, lParam);
-}
-
-/**
- * Given a desired <em>client area</em> for the receiver
- * (as described by the arguments), returns the bounding
- * rectangle which would be required to produce that client
- * area.
- * <p>
- * In other words, it returns a rectangle such that, if the
- * receiver's bounds were set to that rectangle, the area
- * of the receiver which is capable of displaying data
- * (that is, not covered by the "trimmings") would be the
- * rectangle described by the arguments (relative to the
- * receiver's parent).
- * </p>
- *
- * @param x the desired x coordinate of the client area
- * @param y the desired y coordinate of the client area
- * @param width the desired width of the client area
- * @param height the desired height of the client area
- * @return the required bounds to produce the given client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getClientArea
- */
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
- int /*long*/ scrolledHandle = scrolledHandle ();
- RECT rect = new RECT ();
- OS.SetRect (rect, x, y, x + width, y + height);
- int bits1 = OS.GetWindowLong (scrolledHandle, OS.GWL_STYLE);
- int bits2 = OS.GetWindowLong (scrolledHandle, OS.GWL_EXSTYLE);
- OS.AdjustWindowRectEx (rect, bits1, false, bits2);
- if (horizontalBar != null) rect.bottom += OS.GetSystemMetrics (OS.SM_CYHSCROLL);
- if (verticalBar != null) rect.right += OS.GetSystemMetrics (OS.SM_CXVSCROLL);
- int nWidth = rect.right - rect.left, nHeight = rect.bottom - rect.top;
- return new Rectangle (rect.left, rect.top, nWidth, nHeight);
-}
-
-ScrollBar createScrollBar (int type) {
- ScrollBar bar = new ScrollBar (this, type);
- if ((state & CANVAS) != 0) {
- bar.setMaximum (100);
- bar.setThumb (10);
- }
- return bar;
-}
-
-void createWidget () {
- super.createWidget ();
- if ((style & SWT.H_SCROLL) != 0) horizontalBar = createScrollBar (SWT.H_SCROLL);
- if ((style & SWT.V_SCROLL) != 0) verticalBar = createScrollBar (SWT.V_SCROLL);
-}
-
-void destroyScrollBar (int type) {
- int /*long*/ hwnd = scrolledHandle ();
- int bits = OS.GetWindowLong (hwnd, OS.GWL_STYLE);
- if ((type & SWT.HORIZONTAL) != 0) {
- style &= ~SWT.H_SCROLL;
- bits &= ~OS.WS_HSCROLL;
- }
- if ((type & SWT.VERTICAL) != 0) {
- style &= ~SWT.V_SCROLL;
- bits &= ~OS.WS_VSCROLL;
- }
- OS.SetWindowLong (hwnd, OS.GWL_STYLE, bits);
-}
-
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data (that is,
- * not covered by the "trimmings").
- *
- * @return the client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeTrim
- */
-public Rectangle getClientArea () {
- checkWidget ();
- forceResize ();
- RECT rect = new RECT ();
- int /*long*/ scrolledHandle = scrolledHandle ();
- OS.GetClientRect (scrolledHandle, rect);
- int x = rect.left, y = rect.top;
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- if (scrolledHandle != handle) {
- OS.GetClientRect (handle, rect);
- OS.MapWindowPoints(handle, scrolledHandle, rect, 2);
- x = -rect.left;
- y = -rect.top;
- }
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the receiver's horizontal scroll bar if it has
- * one, and null if it does not.
- *
- * @return the horizontal scroll bar (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ScrollBar getHorizontalBar () {
- checkWidget ();
- return horizontalBar;
-}
-
-/**
- * Returns the receiver's vertical scroll bar if it has
- * one, and null if it does not.
- *
- * @return the vertical scroll bar (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ScrollBar getVerticalBar () {
- checkWidget ();
- return verticalBar;
-}
-
-void releaseChildren (boolean destroy) {
- if (horizontalBar != null) {
- horizontalBar.release (false);
- horizontalBar = null;
- }
- if (verticalBar != null) {
- verticalBar.release (false);
- verticalBar = null;
- }
- super.releaseChildren (destroy);
-}
-
-int /*long*/ scrolledHandle () {
- return handle;
-}
-
-int widgetExtStyle () {
- return super.widgetExtStyle ();
- /*
- * This code is intentionally commented. In future,
- * we may wish to support different standard Windows
- * edge styles. The issue here is that not all of
- * these styles are available on the other platforms
- * this would need to be a hint.
- */
-// if ((style & SWT.BORDER) != 0) return OS.WS_EX_CLIENTEDGE;
-// if ((style & SWT.SHADOW_IN) != 0) return OS.WS_EX_STATICEDGE;
-// return super.widgetExtStyle ();
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle () | OS.WS_TABSTOP;
- if ((style & SWT.H_SCROLL) != 0) bits |= OS.WS_HSCROLL;
- if ((style & SWT.V_SCROLL) != 0) bits |= OS.WS_VSCROLL;
- return bits;
-}
-
-TCHAR windowClass () {
- return display.windowClass;
-}
-
-int /*long*/ windowProc () {
- return display.windowProc;
-}
-
-LRESULT WM_HSCROLL (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_HSCROLL (wParam, lParam);
- if (result != null) return result;
-
- /*
- * Bug on WinCE. lParam should be NULL when the message is not sent
- * by a scroll bar control, but it contains the handle to the window.
- * When the message is sent by a scroll bar control, it correctly
- * contains the handle to the scroll bar. The fix is to check for
- * both.
- */
- if (horizontalBar != null && (lParam == 0 || lParam == handle)) {
- return wmScroll (horizontalBar, (state & CANVAS) != 0, handle, OS.WM_HSCROLL, wParam, lParam);
- }
- return result;
-}
-
-LRESULT WM_MOUSEWHEEL (int /*long*/ wParam, int /*long*/ lParam) {
- return wmScrollWheel ((state & CANVAS) != 0, wParam, lParam);
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- int /*long*/ code = callWindowProc (handle, OS.WM_SIZE, wParam, lParam);
- super.WM_SIZE (wParam, lParam);
- // widget may be disposed at this point
- if (code == 0) return LRESULT.ZERO;
- return new LRESULT (code);
-}
-
-LRESULT WM_VSCROLL (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_VSCROLL (wParam, lParam);
- if (result != null) return result;
- /*
- * Bug on WinCE. lParam should be NULL when the message is not sent
- * by a scroll bar control, but it contains the handle to the window.
- * When the message is sent by a scroll bar control, it correctly
- * contains the handle to the scroll bar. The fix is to check for
- * both.
- */
- if (verticalBar != null && (lParam == 0 || lParam == handle)) {
- return wmScroll (verticalBar, (state & CANVAS) != 0, handle, OS.WM_VSCROLL, wParam, lParam);
- }
- return result;
-}
-
-LRESULT wmNCPaint (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.wmNCPaint (hwnd, wParam, lParam);
- if (result != null) return result;
- /*
- * Bug in Windows. On XP only (not Vista), Windows sometimes
- * does not redraw the bottom right corner of a window that
- * has scroll bars, causing pixel corruption. The fix is to
- * always draw the corner.
- */
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- if (!OS.IsWinCE && OS.WIN32_VERSION < OS.VERSION (6, 0)) {
- int bits1 = OS.GetWindowLong (hwnd, OS.GWL_STYLE);
- if ((bits1 & (OS.WS_HSCROLL | OS.WS_VSCROLL)) != 0) {
- RECT windowRect = new RECT ();
- OS.GetWindowRect (hwnd, windowRect);
- RECT trimRect = new RECT ();
- int bits2 = OS.GetWindowLong (hwnd, OS.GWL_EXSTYLE);
- OS.AdjustWindowRectEx (trimRect, bits1, false, bits2);
- boolean hVisible = false, vVisible = false;
- SCROLLBARINFO psbi = new SCROLLBARINFO ();
- psbi.cbSize = SCROLLBARINFO.sizeof;
- if (OS.GetScrollBarInfo (hwnd, OS.OBJID_HSCROLL, psbi)) {
- hVisible = (psbi.rgstate [0] & OS.STATE_SYSTEM_INVISIBLE) == 0;
- }
- if (OS.GetScrollBarInfo (hwnd, OS.OBJID_VSCROLL, psbi)) {
- vVisible = (psbi.rgstate [0] & OS.STATE_SYSTEM_INVISIBLE) == 0;
- }
- RECT cornerRect = new RECT ();
- cornerRect.right = windowRect.right - windowRect.left - trimRect.right;
- cornerRect.bottom = windowRect.bottom - windowRect.top - trimRect.bottom;
- cornerRect.left = cornerRect.right - (hVisible ? OS.GetSystemMetrics (OS.SM_CXVSCROLL) : 0);
- cornerRect.top = cornerRect.bottom - (vVisible ? OS.GetSystemMetrics (OS.SM_CYHSCROLL) : 0);
- if (cornerRect.left != cornerRect.right && cornerRect.top != cornerRect.bottom) {
- int /*long*/ hDC = OS.GetWindowDC (hwnd);
- OS.FillRect (hDC, cornerRect, OS.COLOR_BTNFACE + 1);
- Decorations shell = menuShell ();
- if ((shell.style & SWT.RESIZE) != 0) {
- int /*long*/ hwndScroll = shell.scrolledHandle ();
- boolean drawGripper = hwnd == hwndScroll;
- if (!drawGripper) {
- RECT shellRect = new RECT ();
- OS.GetClientRect (hwndScroll, shellRect);
- OS.MapWindowPoints (hwndScroll, 0, shellRect, 2);
- drawGripper = shellRect.right == windowRect.right && shellRect.bottom == windowRect.bottom;
- }
- if (drawGripper) {
- OS.DrawThemeBackground (display.hScrollBarTheme(), hDC, OS.SBP_SIZEBOX, 0, cornerRect, null);
- }
- }
- OS.ReleaseDC (hwnd, hDC);
- }
- }
- }
- }
- return result;
-}
-
-LRESULT wmScrollWheel (boolean update, int /*long*/ wParam, int /*long*/ lParam) {
- int scrollRemainder = display.scrollRemainder;
- LRESULT result = super.WM_MOUSEWHEEL (wParam, lParam);
- if (result != null) return result;
- /*
- * Translate WM_MOUSEWHEEL to WM_VSCROLL or WM_HSCROLL.
- */
- if (update) {
- if ((wParam & (OS.MK_SHIFT | OS.MK_CONTROL)) != 0) return result;
- boolean vertical = verticalBar != null && verticalBar.getEnabled ();
- boolean horizontal = horizontalBar != null && horizontalBar.getEnabled ();
- int msg = vertical ? OS.WM_VSCROLL : horizontal ? OS.WM_HSCROLL : 0;
- if (msg == 0) return result;
- int [] linesToScroll = new int [1];
- OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, linesToScroll, 0);
- int delta = OS.GET_WHEEL_DELTA_WPARAM (wParam);
- boolean pageScroll = linesToScroll [0] == OS.WHEEL_PAGESCROLL;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
- ScrollBar bar = vertical ? verticalBar : horizontalBar;
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_POS;
- OS.GetScrollInfo (handle, bar.scrollBarType (), info);
- if (vertical && !pageScroll) delta *= linesToScroll [0];
- int increment = pageScroll ? bar.getPageIncrement () : bar.getIncrement ();
- info.nPos -= increment * delta / OS.WHEEL_DELTA;
- OS.SetScrollInfo (handle, bar.scrollBarType (), info, true);
- OS.SendMessage (handle, msg, OS.SB_THUMBPOSITION, 0);
- } else {
- int code = 0;
- if (pageScroll) {
- code = delta < 0 ? OS.SB_PAGEDOWN : OS.SB_PAGEUP;
- } else {
- code = delta < 0 ? OS.SB_LINEDOWN : OS.SB_LINEUP;
- if (msg == OS.WM_VSCROLL) delta *= linesToScroll [0];
- }
- /* Check if the delta and the remainder have the same direction (sign) */
- if ((delta ^ scrollRemainder) >= 0) delta += scrollRemainder;
- int count = Math.abs (delta) / OS.WHEEL_DELTA;
- for (int i=0; i<count; i++) {
- OS.SendMessage (handle, msg, code, 0);
- }
- }
- return LRESULT.ZERO;
- }
-
- /*
- * When the native widget scrolls inside WM_MOUSEWHEEL, it
- * may or may not send a WM_VSCROLL or WM_HSCROLL to do the
- * actual scrolling. This depends on the implementation of
- * each native widget. In order to ensure that application
- * code is notified when the scroll bar moves, compare the
- * scroll bar position before and after the WM_MOUSEWHEEL.
- * If the native control sends a WM_VSCROLL or WM_HSCROLL,
- * then the application has already been notified. If not
- * explicitly send the event.
- */
- int vPosition = verticalBar == null ? 0 : verticalBar.getSelection ();
- int hPosition = horizontalBar == null ? 0 : horizontalBar.getSelection ();
- int /*long*/ code = callWindowProc (handle, OS.WM_MOUSEWHEEL, wParam, lParam);
- if (verticalBar != null) {
- int position = verticalBar.getSelection ();
- if (position != vPosition) {
- Event event = new Event ();
- event.detail = position < vPosition ? SWT.PAGE_UP : SWT.PAGE_DOWN;
- verticalBar.sendEvent (SWT.Selection, event);
- }
- }
- if (horizontalBar != null) {
- int position = horizontalBar.getSelection ();
- if (position != hPosition) {
- Event event = new Event ();
- event.detail = position < hPosition ? SWT.PAGE_UP : SWT.PAGE_DOWN;
- horizontalBar.sendEvent (SWT.Selection, event);
- }
- }
- return new LRESULT (code);
-}
-
-LRESULT wmScroll (ScrollBar bar, boolean update, int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = null;
- if (update) {
- int type = msg == OS.WM_HSCROLL ? OS.SB_HORZ : OS.SB_VERT;
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_TRACKPOS | OS.SIF_POS | OS.SIF_RANGE;
- OS.GetScrollInfo (hwnd, type, info);
- info.fMask = OS.SIF_POS;
- int code = OS.LOWORD (wParam);
- switch (code) {
- case OS.SB_ENDSCROLL: return null;
- case OS.SB_THUMBPOSITION:
- case OS.SB_THUMBTRACK:
- /*
- * Note: On WinCE, the value in SB_THUMBPOSITION is relative to nMin.
- * Same for SB_THUMBPOSITION 'except' for the very first thumb track
- * message which has the actual value of nMin. This is a problem when
- * nMin is not zero.
- */
- info.nPos = info.nTrackPos;
- break;
- case OS.SB_TOP:
- info.nPos = info.nMin;
- break;
- case OS.SB_BOTTOM:
- info.nPos = info.nMax;
- break;
- case OS.SB_LINEDOWN:
- info.nPos += bar.getIncrement ();
- break;
- case OS.SB_LINEUP:
- int increment = bar.getIncrement ();
- info.nPos = Math.max (info.nMin, info.nPos - increment);
- break;
- case OS.SB_PAGEDOWN:
- info.nPos += bar.getPageIncrement ();
- break;
- case OS.SB_PAGEUP:
- int pageIncrement = bar.getPageIncrement ();
- info.nPos = Math.max (info.nMin, info.nPos - pageIncrement);
- break;
- }
- OS.SetScrollInfo (hwnd, type, info, true);
- } else {
- int /*long*/ code = callWindowProc (hwnd, msg, wParam, lParam);
- result = code == 0 ? LRESULT.ZERO : new LRESULT (code);
- }
- bar.wmScrollChild (wParam, lParam);
- return result;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java
deleted file mode 100755
index 307e203db9..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java
+++ /dev/null
@@ -1,2518 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent the "windows"
- * which the desktop or "window manager" is managing.
- * Instances that do not have a parent (that is, they
- * are built using the constructor, which takes a
- * <code>Display</code> as the argument) are described
- * as <em>top level</em> shells. Instances that do have
- * a parent are described as <em>secondary</em> or
- * <em>dialog</em> shells.
- * <p>
- * Instances are always displayed in one of the maximized,
- * minimized or normal states:
- * <ul>
- * <li>
- * When an instance is marked as <em>maximized</em>, the
- * window manager will typically resize it to fill the
- * entire visible area of the display, and the instance
- * is usually put in a state where it can not be resized
- * (even if it has style <code>RESIZE</code>) until it is
- * no longer maximized.
- * </li><li>
- * When an instance is in the <em>normal</em> state (neither
- * maximized or minimized), its appearance is controlled by
- * the style constants which were specified when it was created
- * and the restrictions of the window manager (see below).
- * </li><li>
- * When an instance has been marked as <em>minimized</em>,
- * its contents (client area) will usually not be visible,
- * and depending on the window manager, it may be
- * "iconified" (that is, replaced on the desktop by a small
- * simplified representation of itself), relocated to a
- * distinguished area of the screen, or hidden. Combinations
- * of these changes are also possible.
- * </li>
- * </ul>
- * </p><p>
- * The <em>modality</em> of an instance may be specified using
- * style bits. The modality style bits are used to determine
- * whether input is blocked for other shells on the display.
- * The <code>PRIMARY_MODAL</code> style allows an instance to block
- * input to its parent. The <code>APPLICATION_MODAL</code> style
- * allows an instance to block input to every other shell in the
- * display. The <code>SYSTEM_MODAL</code> style allows an instance
- * to block input to all shells, including shells belonging to
- * different applications.
- * </p><p>
- * Note: The styles supported by this class are treated
- * as <em>HINT</em>s, since the window manager for the
- * desktop on which the instance is visible has ultimate
- * control over the appearance and behavior of decorations
- * and modality. For example, some window managers only
- * support resizable windows and will always assume the
- * RESIZE style, even if it is not set. In addition, if a
- * modality style is not supported, it is "upgraded" to a
- * more restrictive modality style that is supported. For
- * example, if <code>PRIMARY_MODAL</code> is not supported,
- * it would be upgraded to <code>APPLICATION_MODAL</code>.
- * A modality style may also be "downgraded" to a less
- * restrictive style. For example, most operating systems
- * no longer support <code>SYSTEM_MODAL</code> because
- * it can freeze up the desktop, so this is typically
- * downgraded to <code>APPLICATION_MODAL</code>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL, SHEET</dd>
- * <dd>APPLICATION_MODAL, MODELESS, PRIMARY_MODAL, SYSTEM_MODAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Activate, Close, Deactivate, Deiconify, Iconify</dd>
- * </dl>
- * Class <code>SWT</code> provides two "convenience constants"
- * for the most commonly required style combinations:
- * <dl>
- * <dt><code>SHELL_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application top level shell: (that
- * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>)
- * </dd>
- * <dt><code>DIALOG_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application dialog shell: (that
- * is, <code>TITLE | CLOSE | BORDER</code>)
- * </dd>
- * </dl>
- * </p>
- * <p>
- * Note: Only one of the styles APPLICATION_MODAL, MODELESS,
- * PRIMARY_MODAL and SYSTEM_MODAL may be specified.
- * </p><p>
- * IMPORTANT: This class is not intended to be subclassed.
- * </p>
- *
- * @see Decorations
- * @see SWT
- * @see <a href="http://www.eclipse.org/swt/snippets/#shell">Shell snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class Shell extends Decorations {
- Menu activeMenu;
- ToolTip [] toolTips;
- int /*long*/ hIMC, hwndMDIClient, lpstrTip, toolTipHandle, balloonTipHandle;
- int minWidth = SWT.DEFAULT, minHeight = SWT.DEFAULT;
- int /*long*/ [] brushes;
- boolean showWithParent, fullScreen, wasMaximized, modified, center;
- String toolTitle, balloonTitle;
- int /*long*/ toolIcon, balloonIcon;
- int /*long*/ windowProc;
- Control lastActive;
- SHACTIVATEINFO psai;
- static /*final*/ int /*long*/ ToolTipProc;
- static final int /*long*/ DialogProc;
- static final TCHAR DialogClass = new TCHAR (0, OS.IsWinCE ? "Dialog" : "#32770", true);
- final static int [] SYSTEM_COLORS = {
- OS.COLOR_BTNFACE,
- OS.COLOR_WINDOW,
- OS.COLOR_BTNTEXT,
- OS.COLOR_WINDOWTEXT,
- OS.COLOR_HIGHLIGHT,
- OS.COLOR_SCROLLBAR,
- };
- final static int BRUSHES_SIZE = 32;
- static {
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, DialogClass, lpWndClass);
- DialogProc = lpWndClass.lpfnWndProc;
- }
-
-/**
- * Constructs a new instance of this class. This is equivalent
- * to calling <code>Shell((Display) null)</code>.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell () {
- this ((Display) null);
-}
-
-/**
- * Constructs a new instance of this class given only the style
- * value describing its behavior and appearance. This is equivalent
- * to calling <code>Shell((Display) null, style)</code>.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#TOOL
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (int style) {
- this ((Display) null, style);
-}
-
-/**
- * Constructs a new instance of this class given only the display
- * to create it on. It is created with style <code>SWT.SHELL_TRIM</code>.
- * <p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the shell on
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell (Display display) {
- this (display, OS.IsWinCE ? SWT.NONE : SWT.SHELL_TRIM);
-}
-
-/**
- * Constructs a new instance of this class given the display
- * to create it on and a style value describing its behavior
- * and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the shell on
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#TOOL
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (Display display, int style) {
- this (display, null, style, 0, false);
-}
-
-Shell (Display display, Shell parent, int style, int /*long*/ handle, boolean embedded) {
- super ();
- checkSubclass ();
- if (display == null) display = Display.getCurrent ();
- if (display == null) display = Display.getDefault ();
- if (!display.isValidThread ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- if (parent != null && parent.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.center = parent != null && (style & SWT.SHEET) != 0;
- this.style = checkStyle (parent, style);
- this.parent = parent;
- this.display = display;
- this.handle = handle;
- if (handle != 0 && !embedded) {
- state |= FOREIGN_HANDLE;
- }
- createWidget ();
-}
-
-/**
- * Constructs a new instance of this class given only its
- * parent. It is created with style <code>SWT.DIALOG_TRIM</code>.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the parent is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell (Shell parent) {
- this (parent, OS.IsWinCE ? SWT.NONE : SWT.DIALOG_TRIM);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the parent is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#TOOL
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (Shell parent, int style) {
- this (parent != null ? parent.display : null, parent, style, 0, false);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new shell
- * that is embedded.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Shell</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param display the display for the shell
- * @param handle the handle for the shell
- * @return a new shell object containing the specified display and handle
- */
-public static Shell win32_new (Display display, int /*long*/ handle) {
- return new Shell (display, null, SWT.NO_TRIM, handle, true);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new shell
- * that is not embedded.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Shell</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param display the display for the shell
- * @param handle the handle for the shell
- * @return a new shell object containing the specified display and handle
- *
- * @since 3.3
- */
-public static Shell internal_new (Display display, int /*long*/ handle) {
- return new Shell (display, null, SWT.NO_TRIM, handle, false);
-}
-
-static int checkStyle (Shell parent, int style) {
- style = Decorations.checkStyle (style);
- style &= ~SWT.TRANSPARENT;
- int mask = SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.PRIMARY_MODAL;
- if ((style & SWT.SHEET) != 0) {
- style &= ~SWT.SHEET;
- style |= parent == null ? SWT.SHELL_TRIM : SWT.DIALOG_TRIM;
- if ((style & mask) == 0) {
- style |= parent == null ? SWT.APPLICATION_MODAL : SWT.PRIMARY_MODAL;
- }
- }
- int bits = style & ~mask;
- if ((style & SWT.SYSTEM_MODAL) != 0) return bits | SWT.SYSTEM_MODAL;
- if ((style & SWT.APPLICATION_MODAL) != 0) return bits | SWT.APPLICATION_MODAL;
- if ((style & SWT.PRIMARY_MODAL) != 0) return bits | SWT.PRIMARY_MODAL;
- return bits;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when operations are performed on the receiver,
- * by sending the listener one of the messages defined in the
- * <code>ShellListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ShellListener
- * @see #removeShellListener
- */
-public void addShellListener (ShellListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Close,typedListener);
- addListener (SWT.Iconify,typedListener);
- addListener (SWT.Deiconify,typedListener);
- addListener (SWT.Activate, typedListener);
- addListener (SWT.Deactivate, typedListener);
-}
-
-int /*long*/ balloonTipHandle () {
- if (balloonTipHandle == 0) createBalloonTipHandle ();
- return balloonTipHandle;
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- if (hwnd == toolTipHandle || hwnd == balloonTipHandle) {
- return OS.CallWindowProc (ToolTipProc, hwnd, msg, wParam, lParam);
- }
- if (hwndMDIClient != 0) {
- return OS.DefFrameProc (hwnd, hwndMDIClient, msg, wParam, lParam);
- }
- if (windowProc != 0) {
- return OS.CallWindowProc (windowProc, hwnd, msg, wParam, lParam);
- }
- if ((style & SWT.TOOL) != 0) {
- int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX | SWT.BORDER | SWT.RESIZE;
- if ((style & trim) == 0) return OS.DefWindowProc (hwnd, msg, wParam, lParam);
- }
- if (parent != null) {
- switch (msg) {
- case OS.WM_KILLFOCUS:
- case OS.WM_SETFOCUS:
- return OS.DefWindowProc (hwnd, msg, wParam, lParam);
- }
- return OS.CallWindowProc (DialogProc, hwnd, msg, wParam, lParam);
- }
- return OS.DefWindowProc (hwnd, msg, wParam, lParam);
-}
-
-void center () {
- if (parent == null) return;
- Rectangle rect = getBounds ();
- Rectangle parentRect = display.map (parent, null, parent.getClientArea());
- int x = Math.max (parentRect.x, parentRect.x + (parentRect.width - rect.width) / 2);
- int y = Math.max (parentRect.y, parentRect.y + (parentRect.height - rect.height) / 2);
- Rectangle monitorRect = parent.getMonitor ().getClientArea();
- if (x + rect.width > monitorRect.x + monitorRect.width) {
- x = Math.max (monitorRect.x, monitorRect.x + monitorRect.width - rect.width);
- } else {
- x = Math.max (x, monitorRect.x);
- }
- if (y + rect.height > monitorRect.y + monitorRect.height) {
- y = Math.max (monitorRect.y, monitorRect.y + monitorRect.height - rect.height);
- } else {
- y = Math.max (y, monitorRect.y);
- }
- setLocation (x, y);
-}
-
-/**
- * Requests that the window manager close the receiver in
- * the same way it would be closed when the user clicks on
- * the "close box" or performs some other platform specific
- * key or mouse combination that indicates the window
- * should be removed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#Close
- * @see #dispose
- */
-public void close () {
- checkWidget ();
- closeWidget ();
-}
-
-void createBalloonTipHandle () {
- balloonTipHandle = OS.CreateWindowEx (
- 0,
- new TCHAR (0, OS.TOOLTIPS_CLASS, true),
- null,
- OS.TTS_ALWAYSTIP | OS.TTS_NOPREFIX | OS.TTS_BALLOON,
- OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0,
- handle,
- 0,
- OS.GetModuleHandle (null),
- null);
- if (balloonTipHandle == 0) error (SWT.ERROR_NO_HANDLES);
- if (ToolTipProc == 0) {
- ToolTipProc = OS.GetWindowLongPtr (balloonTipHandle, OS.GWLP_WNDPROC);
- }
- /*
- * Feature in Windows. Despite the fact that the
- * tool tip text contains \r\n, the tooltip will
- * not honour the new line unless TTM_SETMAXTIPWIDTH
- * is set. The fix is to set TTM_SETMAXTIPWIDTH to
- * a large value.
- */
- OS.SendMessage (balloonTipHandle, OS.TTM_SETMAXTIPWIDTH, 0, 0x7FFF);
- display.addControl (balloonTipHandle, this);
- OS.SetWindowLongPtr (balloonTipHandle, OS.GWLP_WNDPROC, display.windowProc);
-}
-
-void createHandle () {
- boolean embedded = handle != 0 && (state & FOREIGN_HANDLE) == 0;
-
- /*
- * On Windows 98 and NT, setting a window to be the
- * top most window using HWND_TOPMOST can result in a
- * parent dialog shell being moved behind its parent
- * if the dialog has a sibling that is currently on top
- * This only occurs using SetWindowPos (), not when the
- * handle is created.
- */
- /*
- * The following code is intentionally commented.
- */
-// if ((style & SWT.ON_TOP) != 0) display.lockActiveWindow = true;
- if (handle == 0 || embedded) {
- super.createHandle ();
- } else {
- state |= CANVAS;
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
- state |= THEME_BACKGROUND;
- }
- windowProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
- }
-
- /*
- * The following code is intentionally commented.
- */
-// if ((style & SWT.ON_TOP) != 0) display.lockActiveWindow = false;
-
- if (!embedded) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- bits &= ~(OS.WS_OVERLAPPED | OS.WS_CAPTION);
- if (!OS.IsWinCE) bits |= OS.WS_POPUP;
- if ((style & SWT.TITLE) != 0) bits |= OS.WS_CAPTION;
- if ((style & SWT.NO_TRIM) == 0) {
- if ((style & (SWT.BORDER | SWT.RESIZE)) == 0) bits |= OS.WS_BORDER;
- }
- /*
- * Bug in Windows. When the WS_CAPTION bits are cleared using
- * SetWindowLong(), Windows does not resize the client area of
- * the window to get rid of the caption until the first resize.
- * The fix is to use SetWindowPos() with SWP_DRAWFRAME to force
- * the frame to be redrawn and resized.
- */
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- int flags = OS.SWP_DRAWFRAME | OS.SWP_NOMOVE | OS.SWP_NOSIZE | OS.SWP_NOZORDER | OS.SWP_NOACTIVATE;
- SetWindowPos (handle, 0, 0, 0, 0, 0, flags);
- if (OS.IsWinCE) _setMaximized (true);
- if (OS.IsPPC) {
- psai = new SHACTIVATEINFO ();
- psai.cbSize = SHACTIVATEINFO.sizeof;
- }
- }
- if (OS.IsDBLocale) {
- hIMC = OS.ImmCreateContext ();
- if (hIMC != 0) OS.ImmAssociateContext (handle, hIMC);
- }
-}
-
-void createToolTip (ToolTip toolTip) {
- int id = 0;
- if (toolTips == null) toolTips = new ToolTip [4];
- while (id < toolTips.length && toolTips [id] != null) id++;
- if (id == toolTips.length) {
- ToolTip [] newToolTips = new ToolTip [toolTips.length + 4];
- System.arraycopy (toolTips, 0, newToolTips, 0, toolTips.length);
- toolTips = newToolTips;
- }
- toolTips [id] = toolTip;
- toolTip.id = id + Display.ID_START;
- if (OS.IsWinCE) return;
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- lpti.hwnd = handle;
- lpti.uId = toolTip.id;
- lpti.uFlags = OS.TTF_TRACK;
- lpti.lpszText = OS.LPSTR_TEXTCALLBACK;
- OS.SendMessage (toolTip.hwndToolTip (), OS.TTM_ADDTOOL, 0, lpti);
-}
-
-void createToolTipHandle () {
- toolTipHandle = OS.CreateWindowEx (
- 0,
- new TCHAR (0, OS.TOOLTIPS_CLASS, true),
- null,
- OS.TTS_ALWAYSTIP | OS.TTS_NOPREFIX,
- OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0,
- handle,
- 0,
- OS.GetModuleHandle (null),
- null);
- if (toolTipHandle == 0) error (SWT.ERROR_NO_HANDLES);
- if (ToolTipProc == 0) {
- ToolTipProc = OS.GetWindowLongPtr (toolTipHandle, OS.GWLP_WNDPROC);
- }
- /*
- * Feature in Windows. Despite the fact that the
- * tool tip text contains \r\n, the tooltip will
- * not honour the new line unless TTM_SETMAXTIPWIDTH
- * is set. The fix is to set TTM_SETMAXTIPWIDTH to
- * a large value.
- */
- OS.SendMessage (toolTipHandle, OS.TTM_SETMAXTIPWIDTH, 0, 0x7FFF);
- display.addControl (toolTipHandle, this);
- OS.SetWindowLongPtr (toolTipHandle, OS.GWLP_WNDPROC, display.windowProc);
-}
-
-void deregister () {
- super.deregister ();
- if (toolTipHandle != 0) display.removeControl (toolTipHandle);
- if (balloonTipHandle != 0) display.removeControl (balloonTipHandle);
-}
-
-void destroyToolTip (ToolTip toolTip) {
- if (toolTips == null) return;
- toolTips [toolTip.id - Display.ID_START] = null;
- if (OS.IsWinCE) return;
- if (balloonTipHandle != 0) {
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- lpti.uId = toolTip.id;
- lpti.hwnd = handle;
- OS.SendMessage (balloonTipHandle, OS.TTM_DELTOOL, 0, lpti);
- }
- toolTip.id = -1;
-}
-
-void destroyWidget () {
- fixActiveShell ();
- super.destroyWidget ();
-}
-
-public void dispose () {
- /*
- * This code is intentionally commented. On some
- * platforms, the owner window is repainted right
- * away when a dialog window exits. This behavior
- * is currently unspecified.
- */
-// /*
-// * Note: It is valid to attempt to dispose a widget
-// * more than once. If this happens, fail silently.
-// */
-// if (!isValidWidget ()) return;
-// if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
-// Display oldDisplay = display;
- super.dispose ();
- // widget is disposed at this point
-// if (oldDisplay != null) oldDisplay.update ();
-}
-
-void enableWidget (boolean enabled) {
- if (enabled) {
- state &= ~DISABLED;
- } else {
- state |= DISABLED;
- }
- if (Display.TrimEnabled) {
- if (isActive ()) setItemEnabled (OS.SC_CLOSE, enabled);
- } else {
- OS.EnableWindow (handle, enabled);
- }
-}
-
-int /*long*/ findBrush (int /*long*/ value, int lbStyle) {
- if (lbStyle == OS.BS_SOLID) {
- for (int i=0; i<SYSTEM_COLORS.length; i++) {
- if (value == OS.GetSysColor (SYSTEM_COLORS [i])) {
- return OS.GetSysColorBrush (SYSTEM_COLORS [i]);
- }
- }
- }
- if (brushes == null) brushes = new int /*long*/ [BRUSHES_SIZE];
- LOGBRUSH logBrush = new LOGBRUSH ();
- for (int i=0; i<brushes.length; i++) {
- int /*long*/ hBrush = brushes [i];
- if (hBrush == 0) break;
- OS.GetObject (hBrush, LOGBRUSH.sizeof, logBrush);
- switch (logBrush.lbStyle) {
- case OS.BS_SOLID:
- if (lbStyle == OS.BS_SOLID) {
- if (logBrush.lbColor == value) return hBrush;
- }
- break;
- case OS.BS_PATTERN:
- if (lbStyle == OS.BS_PATTERN) {
- if (logBrush.lbHatch == value) return hBrush;
- }
- break;
- }
- }
- int length = brushes.length;
- int /*long*/ hBrush = brushes [--length];
- if (hBrush != 0) OS.DeleteObject (hBrush);
- System.arraycopy (brushes, 0, brushes, 1, length);
- switch (lbStyle) {
- case OS.BS_SOLID:
- hBrush = OS.CreateSolidBrush ((int)/*64*/value);
- break;
- case OS.BS_PATTERN:
- hBrush = OS.CreatePatternBrush (value);
- break;
- }
- return brushes [0] = hBrush;
-}
-
-Control findBackgroundControl () {
- return background != -1 || backgroundImage != null ? this : null;
-}
-
-Cursor findCursor () {
- return cursor;
-}
-
-Control findThemeControl () {
- return null;
-}
-
-ToolTip findToolTip (int id) {
- if (toolTips == null) return null;
- id = id - Display.ID_START;
- return 0 <= id && id < toolTips.length ? toolTips [id] : null;
-}
-
-void fixActiveShell () {
- /*
- * Feature in Windows. When the active shell is disposed
- * or hidden, Windows normally makes the parent shell active
- * and assigns focus. This does not happen when the parent
- * shell is disabled. Instead, Windows assigns focus to the
- * next shell on the desktop (possibly a shell in another
- * application). The fix is to activate the disabled parent
- * shell before disposing or hiding the active shell.
- */
- int /*long*/ hwndParent = OS.GetParent (handle);
- if (hwndParent != 0 && handle == OS.GetActiveWindow ()) {
- if (!OS.IsWindowEnabled (hwndParent) && OS.IsWindowVisible (hwndParent)) {
- OS.SetActiveWindow (hwndParent);
- }
- }
-}
-
-void fixShell (Shell newShell, Control control) {
- if (this == newShell) return;
- if (control == lastActive) setActiveControl (null);
- String toolTipText = control.toolTipText;
- if (toolTipText != null) {
- control.setToolTipText (this, null);
- control.setToolTipText (newShell, toolTipText);
- }
-}
-
-void fixToolTip () {
- /*
- * Bug in Windows. On XP, when a tooltip is
- * hidden due to a time out or mouse press,
- * the tooltip remains active although no
- * longer visible and won't show again until
- * another tooltip becomes active. If there
- * is only one tooltip in the window, it will
- * never show again. The fix is to remove the
- * current tooltip and add it again every time
- * the mouse leaves the control.
- */
- if (OS.COMCTL32_MAJOR >= 6) {
- if (toolTipHandle == 0) return;
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- if (OS.SendMessage (toolTipHandle, OS.TTM_GETCURRENTTOOL, 0, lpti) != 0) {
- if ((lpti.uFlags & OS.TTF_IDISHWND) != 0) {
- OS.SendMessage (toolTipHandle, OS.TTM_DELTOOL, 0, lpti);
- OS.SendMessage (toolTipHandle, OS.TTM_ADDTOOL, 0, lpti);
- }
- }
- }
-}
-
-/**
- * If the receiver is visible, moves it to the top of the
- * drawing order for the display on which it was created
- * (so that all other shells on that display, which are not
- * the receiver's children will be drawn behind it) and forces
- * the window manager to make the shell active.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#open
- * @see Shell#setActive
- */
-public void forceActive () {
- checkWidget ();
- if(!isVisible()) return;
- OS.SetForegroundWindow (handle);
-}
-
-void forceResize () {
- /* Do nothing */
-}
-
-/**
- * Returns the receiver's alpha value. The alpha value
- * is between 0 (transparent) and 255 (opaque).
- *
- * @return the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public int getAlpha () {
- checkWidget ();
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
- byte [] pbAlpha = new byte [1];
- if (OS.GetLayeredWindowAttributes (handle, null, pbAlpha, null)) {
- return pbAlpha [0] & 0xFF;
- }
- }
- return 0xFF;
-}
-
-public Rectangle getBounds () {
- checkWidget ();
- if (!OS.IsWinCE) {
- if (OS.IsIconic (handle)) return super.getBounds ();
- }
- RECT rect = new RECT ();
- OS.GetWindowRect (handle, rect);
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- return new Rectangle (rect.left, rect.top, width, height);
-}
-
-ToolTip getCurrentToolTip () {
- if (toolTipHandle != 0) {
- ToolTip tip = getCurrentToolTip (toolTipHandle);
- if (tip != null) return tip;
- }
- if (balloonTipHandle != 0) {
- ToolTip tip = getCurrentToolTip (balloonTipHandle);
- if (tip != null) return tip;
- }
- return null;
-}
-
-ToolTip getCurrentToolTip (int /*long*/ hwndToolTip) {
- if (hwndToolTip == 0) return null;
- if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, 0) != 0) {
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, lpti) != 0) {
- if ((lpti.uFlags & OS.TTF_IDISHWND) == 0) return findToolTip ((int)/*64*/lpti.uId);
- }
- }
- return null;
-}
-
-public boolean getEnabled () {
- checkWidget ();
- return (state & DISABLED) == 0;
-}
-
-/**
- * Returns <code>true</code> if the receiver is currently
- * in fullscreen state, and false otherwise.
- * <p>
- *
- * @return the fullscreen state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getFullScreen () {
- checkWidget();
- return fullScreen;
-}
-
-/**
- * Returns the receiver's input method editor mode. This
- * will be the result of bitwise OR'ing together one or
- * more of the following constants defined in class
- * <code>SWT</code>:
- * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>,
- * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>.
- *
- * @return the IME mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public int getImeInputMode () {
- checkWidget ();
- if (!OS.IsDBLocale) return 0;
- int /*long*/ hIMC = OS.ImmGetContext (handle);
- int [] lpfdwConversion = new int [1], lpfdwSentence = new int [1];
- boolean open = OS.ImmGetOpenStatus (hIMC);
- if (open) open = OS.ImmGetConversionStatus (hIMC, lpfdwConversion, lpfdwSentence);
- OS.ImmReleaseContext (handle, hIMC);
- if (!open) return SWT.NONE;
- int result = 0;
- if ((lpfdwConversion [0] & OS.IME_CMODE_ROMAN) != 0) result |= SWT.ROMAN;
- if ((lpfdwConversion [0] & OS.IME_CMODE_FULLSHAPE) != 0) result |= SWT.DBCS;
- if ((lpfdwConversion [0] & OS.IME_CMODE_KATAKANA) != 0) return result | SWT.PHONETIC;
- if ((lpfdwConversion [0] & OS.IME_CMODE_NATIVE) != 0) return result | SWT.NATIVE;
- return result | SWT.ALPHA;
-}
-
-public Point getLocation () {
- checkWidget ();
- if (!OS.IsWinCE) {
- if (OS.IsIconic (handle)) {
- return super.getLocation ();
- }
- }
- RECT rect = new RECT ();
- OS.GetWindowRect (handle, rect);
- return new Point (rect.left, rect.top);
-}
-
-public boolean getMaximized () {
- checkWidget ();
- return !fullScreen && super.getMaximized ();
-}
-
-/**
- * Returns a point describing the minimum receiver's size. The
- * x coordinate of the result is the minimum width of the receiver.
- * The y coordinate of the result is the minimum height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Point getMinimumSize () {
- checkWidget ();
- int width = Math.max (0, minWidth);
- int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX;
- if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) {
- width = Math.max (width, OS.GetSystemMetrics (OS.SM_CXMINTRACK));
- }
- int height = Math.max (0, minHeight);
- if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) {
- if ((style & SWT.RESIZE) != 0) {
- height = Math.max (height, OS.GetSystemMetrics (OS.SM_CYMINTRACK));
- } else {
- RECT rect = new RECT ();
- int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
- int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
- OS.AdjustWindowRectEx (rect, bits1, false, bits2);
- height = Math.max (height, rect.bottom - rect.top);
- }
- }
- return new Point (width, height);
-}
-
-/**
- * Gets the receiver's modified state.
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.5
- */
-public boolean getModified () {
- checkWidget ();
- return modified;
-}
-
-/**
- * Returns the region that defines the shape of the shell,
- * or null if the shell has the default shape.
- *
- * @return the region that defines the shape of the shell (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public Region getRegion () {
- /* This method is needed for the @since 3.0 Javadoc */
- checkWidget ();
- return region;
-}
-
-public Shell getShell () {
- checkWidget ();
- return this;
-}
-
-public Point getSize () {
- checkWidget ();
- if (!OS.IsWinCE) {
- if (OS.IsIconic (handle)) return super.getSize ();
- }
- RECT rect = new RECT ();
- OS.GetWindowRect (handle, rect);
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- return new Point (width, height);
-}
-
-/**
- * Returns an array containing all shells which are
- * descendants of the receiver.
- * <p>
- * @return the dialog shells
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Shell [] getShells () {
- checkWidget ();
- int count = 0;
- Shell [] shells = display.getShells ();
- for (int i=0; i<shells.length; i++) {
- Control shell = shells [i];
- do {
- shell = shell.parent;
- } while (shell != null && shell != this);
- if (shell == this) count++;
- }
- int index = 0;
- Shell [] result = new Shell [count];
- for (int i=0; i<shells.length; i++) {
- Control shell = shells [i];
- do {
- shell = shell.parent;
- } while (shell != null && shell != this);
- if (shell == this) {
- result [index++] = shells [i];
- }
- }
- return result;
-}
-
-Composite findDeferredControl () {
- return layoutCount > 0 ? this : null;
-}
-
-public boolean isEnabled () {
- checkWidget ();
- return getEnabled ();
-}
-
-public boolean isVisible () {
- checkWidget ();
- return getVisible ();
-}
-
-int /*long*/ hwndMDIClient () {
- if (hwndMDIClient == 0) {
- int widgetStyle = OS.MDIS_ALLCHILDSTYLES | OS.WS_CHILD | OS.WS_CLIPCHILDREN | OS.WS_CLIPSIBLINGS;
- hwndMDIClient = OS.CreateWindowEx (
- 0,
- new TCHAR (0, "MDICLIENT", true),
- null,
- widgetStyle,
- 0, 0, 0, 0,
- handle,
- 0,
- OS.GetModuleHandle (null),
- new CREATESTRUCT ());
-// OS.ShowWindow (hwndMDIClient, OS.SW_SHOW);
- }
- return hwndMDIClient;
-}
-
-/**
- * Moves the receiver to the top of the drawing order for
- * the display on which it was created (so that all other
- * shells on that display, which are not the receiver's
- * children will be drawn behind it), marks it visible,
- * sets the focus and asks the window manager to make the
- * shell active.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#setActive
- * @see Shell#forceActive
- */
-public void open () {
- checkWidget ();
- STARTUPINFO lpStartUpInfo = Display.lpStartupInfo;
- if (lpStartUpInfo == null || (lpStartUpInfo.dwFlags & OS.STARTF_USESHOWWINDOW) == 0) {
- bringToTop ();
- if (isDisposed ()) return;
- }
- /*
- * Feature on WinCE PPC. A new application becomes
- * the foreground application only if it has at least
- * one visible window before the event loop is started.
- * The workaround is to explicitly force the shell to
- * be the foreground window.
- */
- if (OS.IsWinCE) OS.SetForegroundWindow (handle);
- OS.SendMessage (handle, OS.WM_CHANGEUISTATE, OS.UIS_INITIALIZE, 0);
- setVisible (true);
- if (isDisposed ()) return;
- /*
- * Bug in Windows XP. Despite the fact that an icon has been
- * set for a window, the task bar displays the wrong icon the
- * first time the window is made visible with ShowWindow() after
- * a call to BringToTop(), when a long time elapses between the
- * ShowWindow() and the time the event queue is read. The icon
- * in the window trimming is correct but the one in the task
- * bar does not get updated. The fix is to call PeekMessage()
- * with the flag PM_NOREMOVE and PM_QS_SENDMESSAGE to respond
- * to a cross thread WM_GETICON.
- *
- * NOTE: This allows other cross thread messages to be delivered,
- * most notably WM_ACTIVATE.
- */
- MSG msg = new MSG ();
- int flags = OS.PM_NOREMOVE | OS.PM_NOYIELD | OS.PM_QS_SENDMESSAGE;
- OS.PeekMessage (msg, 0, 0, 0, flags);
- if (!restoreFocus () && !traverseGroup (true)) setFocus ();
-}
-
-public boolean print (GC gc) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- return false;
-}
-
-void register () {
- super.register ();
- if (toolTipHandle != 0) display.addControl (toolTipHandle, this);
- if (balloonTipHandle != 0) display.addControl (balloonTipHandle, this);
-}
-
-void releaseBrushes () {
- if (brushes != null) {
- for (int i=0; i<brushes.length; i++) {
- if (brushes [i] != 0) OS.DeleteObject (brushes [i]);
- }
- }
- brushes = null;
-}
-
-void releaseChildren (boolean destroy) {
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (shell != null && !shell.isDisposed ()) {
- shell.release (false);
- }
- }
- if (toolTips != null) {
- for (int i=0; i<toolTips.length; i++) {
- ToolTip toolTip = toolTips [i];
- if (toolTip != null && !toolTip.isDisposed ()) {
- toolTip.release (false);
- }
- }
- }
- toolTips = null;
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- hwndMDIClient = 0;
-}
-
-void releaseParent () {
- /* Do nothing */
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- releaseBrushes ();
- activeMenu = null;
- display.clearModal (this);
- if (lpstrTip != 0) {
- int /*long*/ hHeap = OS.GetProcessHeap ();
- OS.HeapFree (hHeap, 0, lpstrTip);
- }
- lpstrTip = 0;
- toolTipHandle = balloonTipHandle = 0;
- if (OS.IsDBLocale) {
- if (hIMC != 0) OS.ImmDestroyContext (hIMC);
- }
- lastActive = null;
- toolTitle = balloonTitle = null;
-}
-
-void removeMenu (Menu menu) {
- super.removeMenu (menu);
- if (menu == activeMenu) activeMenu = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when operations are performed on the receiver.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ShellListener
- * @see #addShellListener
- */
-public void removeShellListener (ShellListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Close, listener);
- eventTable.unhook (SWT.Iconify,listener);
- eventTable.unhook (SWT.Deiconify,listener);
- eventTable.unhook (SWT.Activate, listener);
- eventTable.unhook (SWT.Deactivate, listener);
-}
-
-LRESULT selectPalette (int /*long*/ hPalette) {
- int /*long*/ hDC = OS.GetDC (handle);
- int /*long*/ hOld = OS.SelectPalette (hDC, hPalette, false);
- int result = OS.RealizePalette (hDC);
- if (result > 0) {
- OS.InvalidateRect (handle, null, true);
- } else {
- OS.SelectPalette (hDC, hOld, true);
- OS.RealizePalette (hDC);
- }
- OS.ReleaseDC (handle, hDC);
- return (result > 0) ? LRESULT.ONE : LRESULT.ZERO;
-}
-
-boolean sendKeyEvent (int type, int msg, int /*long*/ wParam, int /*long*/ lParam, Event event) {
- if (!isEnabled () || !isActive ()) return false;
- return super.sendKeyEvent (type, msg, wParam, lParam, event);
-}
-
-/**
- * If the receiver is visible, moves it to the top of the
- * drawing order for the display on which it was created
- * (so that all other shells on that display, which are not
- * the receiver's children will be drawn behind it) and asks
- * the window manager to make the shell active
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#open
- * @see Shell#setActive
- */
-public void setActive () {
- checkWidget ();
- if (!isVisible ()) return;
- bringToTop ();
- // widget could be disposed at this point
-}
-
-void setActiveControl (Control control) {
- if (control != null && control.isDisposed ()) control = null;
- if (lastActive != null && lastActive.isDisposed ()) lastActive = null;
- if (lastActive == control) return;
-
- /*
- * Compute the list of controls to be activated and
- * deactivated by finding the first common parent
- * control.
- */
- Control [] activate = (control == null) ? new Control [0] : control.getPath ();
- Control [] deactivate = (lastActive == null) ? new Control [0] : lastActive.getPath ();
- lastActive = control;
- int index = 0, length = Math.min (activate.length, deactivate.length);
- while (index < length) {
- if (activate [index] != deactivate [index]) break;
- index++;
- }
-
- /*
- * It is possible (but unlikely), that application
- * code could have destroyed some of the widgets. If
- * this happens, keep processing those widgets that
- * are not disposed.
- */
- for (int i=deactivate.length-1; i>=index; --i) {
- if (!deactivate [i].isDisposed ()) {
- deactivate [i].sendEvent (SWT.Deactivate);
- }
- }
- for (int i=activate.length-1; i>=index; --i) {
- if (!activate [i].isDisposed ()) {
- activate [i].sendEvent (SWT.Activate);
- }
- }
-}
-
-/**
- * Sets the receiver's alpha value which must be
- * between 0 (transparent) and 255 (opaque).
- * <p>
- * This operation requires the operating system's advanced
- * widgets subsystem which may not be available on some
- * platforms.
- * </p>
- * @param alpha the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setAlpha (int alpha) {
- checkWidget ();
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
- alpha &= 0xFF;
- int bits = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
- if (alpha == 0xFF) {
- OS.SetWindowLong (handle, OS.GWL_EXSTYLE, bits & ~OS.WS_EX_LAYERED);
- int flags = OS.RDW_ERASE | OS.RDW_INVALIDATE | OS.RDW_FRAME | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, null, 0, flags);
- } else {
- OS.SetWindowLong (handle, OS.GWL_EXSTYLE, bits | OS.WS_EX_LAYERED);
- OS.SetLayeredWindowAttributes (handle, 0, (byte)alpha, OS.LWA_ALPHA);
- }
- }
-}
-
-void setBounds (int x, int y, int width, int height, int flags, boolean defer) {
- if (fullScreen) setFullScreen (false);
- /*
- * Bug in Windows. When a window has alpha and
- * SetWindowPos() is called with SWP_DRAWFRAME,
- * the contents of the window are copied rather
- * than allowing the windows underneath to draw.
- * This causes pixel corruption. The fix is to
- * clear the SWP_DRAWFRAME bits.
- */
- int bits = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
- if ((bits & OS.WS_EX_LAYERED) != 0) {
- flags &= ~OS.SWP_DRAWFRAME;
- }
- super.setBounds (x, y, width, height, flags, false);
-}
-
-public void setEnabled (boolean enabled) {
- checkWidget ();
- if (((state & DISABLED) == 0) == enabled) return;
- super.setEnabled (enabled);
- if (enabled && handle == OS.GetActiveWindow ()) {
- if (!restoreFocus ()) traverseGroup (true);
- }
-}
-
-/**
- * Sets the full screen state of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the full screen state, and if the argument is
- * <code>false</code> and the receiver was previously switched
- * into full screen state, causes the receiver to switch back
- * to either the maximized or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setFullScreen(true)</code>,
- * <code>setMaximized(true)</code> and <code>setMinimized(true)</code> will
- * vary by platform. Typically, the behavior will match the platform user's
- * expectations, but not always. This should be avoided if possible.
- * </p>
- *
- * @param fullScreen the new fullscreen state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setFullScreen (boolean fullScreen) {
- checkWidget();
- if (this.fullScreen == fullScreen) return;
- int stateFlags = fullScreen ? OS.SW_SHOWMAXIMIZED : OS.SW_RESTORE;
- int styleFlags = OS.GetWindowLong (handle, OS.GWL_STYLE);
- int mask = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX;
- if ((style & mask) != 0) {
- if (fullScreen) {
- styleFlags = styleFlags & ~OS.WS_CAPTION;
- } else {
- styleFlags = styleFlags | OS.WS_CAPTION;
- }
- }
- if (fullScreen) wasMaximized = getMaximized ();
- boolean visible = isVisible ();
- OS.SetWindowLong (handle, OS.GWL_STYLE, styleFlags);
- if (wasMaximized) {
- OS.ShowWindow (handle, OS.SW_HIDE);
- stateFlags = OS.SW_SHOWMAXIMIZED;
- }
- if (visible) OS.ShowWindow (handle, stateFlags);
- OS.UpdateWindow (handle);
- this.fullScreen = fullScreen;
-}
-
-/**
- * Sets the input method editor mode to the argument which
- * should be the result of bitwise OR'ing together one or more
- * of the following constants defined in class <code>SWT</code>:
- * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>,
- * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>.
- *
- * @param mode the new IME mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public void setImeInputMode (int mode) {
- checkWidget ();
- if (!OS.IsDBLocale) return;
- boolean imeOn = mode != SWT.NONE;
- int /*long*/ hIMC = OS.ImmGetContext (handle);
- OS.ImmSetOpenStatus (hIMC, imeOn);
- if (imeOn) {
- int [] lpfdwConversion = new int [1], lpfdwSentence = new int [1];
- if (OS.ImmGetConversionStatus (hIMC, lpfdwConversion, lpfdwSentence)) {
- int newBits = 0;
- int oldBits = OS.IME_CMODE_NATIVE | OS.IME_CMODE_KATAKANA;
- if ((mode & SWT.PHONETIC) != 0) {
- newBits = OS.IME_CMODE_KATAKANA | OS.IME_CMODE_NATIVE;
- oldBits = 0;
- } else {
- if ((mode & SWT.NATIVE) != 0) {
- newBits = OS.IME_CMODE_NATIVE;
- oldBits = OS.IME_CMODE_KATAKANA;
- }
- }
- if ((mode & (SWT.DBCS | SWT.NATIVE)) != 0) {
- newBits |= OS.IME_CMODE_FULLSHAPE;
- } else {
- oldBits |= OS.IME_CMODE_FULLSHAPE;
- }
- if ((mode & SWT.ROMAN) != 0) {
- newBits |= OS.IME_CMODE_ROMAN;
- } else {
- oldBits |= OS.IME_CMODE_ROMAN;
- }
- lpfdwConversion [0] |= newBits;
- lpfdwConversion [0] &= ~oldBits;
- OS.ImmSetConversionStatus (hIMC, lpfdwConversion [0], lpfdwSentence [0]);
- }
- }
- OS.ImmReleaseContext (handle, hIMC);
-}
-
-/**
- * Sets the receiver's minimum size to the size specified by the arguments.
- * If the new minimum size is larger than the current size of the receiver,
- * the receiver is resized to the new minimum size.
- *
- * @param width the new minimum width for the receiver
- * @param height the new minimum height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setMinimumSize (int width, int height) {
- checkWidget ();
- int widthLimit = 0, heightLimit = 0;
- int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX;
- if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) {
- widthLimit = OS.GetSystemMetrics (OS.SM_CXMINTRACK);
- if ((style & SWT.RESIZE) != 0) {
- heightLimit = OS.GetSystemMetrics (OS.SM_CYMINTRACK);
- } else {
- RECT rect = new RECT ();
- int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
- int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
- OS.AdjustWindowRectEx (rect, bits1, false, bits2);
- heightLimit = rect.bottom - rect.top;
- }
- }
- minWidth = Math.max (widthLimit, width);
- minHeight = Math.max (heightLimit, height);
- Point size = getSize ();
- int newWidth = Math.max (size.x, minWidth);
- int newHeight = Math.max (size.y, minHeight);
- if (minWidth <= widthLimit) minWidth = SWT.DEFAULT;
- if (minHeight <= heightLimit) minHeight = SWT.DEFAULT;
- if (newWidth != size.x || newHeight != size.y) setSize (newWidth, newHeight);
-}
-
-/**
- * Sets the receiver's minimum size to the size specified by the argument.
- * If the new minimum size is larger than the current size of the receiver,
- * the receiver is resized to the new minimum size.
- *
- * @param size the new minimum size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setMinimumSize (Point size) {
- checkWidget ();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setMinimumSize (size.x, size.y);
-}
-
-/**
- * Sets the receiver's modified state as specified by the argument.
- *
- * @param modified the new modified state for the receiver
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.5
- */
-public void setModified (boolean modified) {
- checkWidget ();
- this.modified = modified;
-}
-
-void setItemEnabled (int cmd, boolean enabled) {
- int /*long*/ hMenu = OS.GetSystemMenu (handle, false);
- if (hMenu == 0) return;
- int flags = OS.MF_ENABLED;
- if (!enabled) flags = OS.MF_DISABLED | OS.MF_GRAYED;
- OS.EnableMenuItem (hMenu, cmd, OS.MF_BYCOMMAND | flags);
-}
-
-void setParent () {
- /* Do nothing. Not necessary for Shells */
-}
-
-/**
- * Sets the shape of the shell to the region specified
- * by the argument. When the argument is null, the
- * default shape of the shell is restored. The shell
- * must be created with the style SWT.NO_TRIM in order
- * to specify a region.
- *
- * @param region the region that defines the shape of the shell (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public void setRegion (Region region) {
- checkWidget ();
- if ((style & SWT.NO_TRIM) == 0) return;
- super.setRegion (region);
-}
-
-void setToolTipText (int /*long*/ hwnd, String text) {
- if (OS.IsWinCE) return;
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- lpti.hwnd = handle;
- lpti.uId = hwnd;
- int /*long*/ hwndToolTip = toolTipHandle ();
- if (text == null) {
- OS.SendMessage (hwndToolTip, OS.TTM_DELTOOL, 0, lpti);
- } else {
- if (OS.SendMessage (hwndToolTip, OS.TTM_GETTOOLINFO, 0, lpti) != 0) {
- OS.SendMessage (hwndToolTip, OS.TTM_UPDATE, 0, 0);
- } else {
- lpti.uFlags = OS.TTF_IDISHWND | OS.TTF_SUBCLASS;
- lpti.lpszText = OS.LPSTR_TEXTCALLBACK;
- OS.SendMessage (hwndToolTip, OS.TTM_ADDTOOL, 0, lpti);
- }
- }
-}
-
-void setToolTipText (NMTTDISPINFO lpnmtdi, byte [] buffer) {
- /*
- * Ensure that the current position of the mouse
- * is inside the client area of the shell. This
- * prevents tool tips from popping up over the
- * shell trimmings.
- */
- if (!hasCursor ()) return;
- int /*long*/ hHeap = OS.GetProcessHeap ();
- if (lpstrTip != 0) OS.HeapFree (hHeap, 0, lpstrTip);
- int byteCount = buffer.length;
- lpstrTip = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (lpstrTip, buffer, byteCount);
- lpnmtdi.lpszText = lpstrTip;
-}
-
-void setToolTipText (NMTTDISPINFO lpnmtdi, char [] buffer) {
- /*
- * Ensure that the current position of the mouse
- * is inside the client area of the shell. This
- * prevents tool tips from popping up over the
- * shell trimmings.
- */
- if (!hasCursor ()) return;
- int /*long*/ hHeap = OS.GetProcessHeap ();
- if (lpstrTip != 0) OS.HeapFree (hHeap, 0, lpstrTip);
- int byteCount = buffer.length * 2;
- lpstrTip = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (lpstrTip, buffer, byteCount);
- lpnmtdi.lpszText = lpstrTip;
-}
-
-void setToolTipTitle (int /*long*/ hwndToolTip, String text, int icon) {
- /*
- * Bug in Windows. For some reason, when TTM_SETTITLE
- * is used to set the title of a tool tip, Windows leaks
- * GDI objects. This happens even when TTM_SETTITLE is
- * called with TTI_NONE and NULL. The documentation
- * states that Windows copies the icon and that the
- * programmer must free the copy but does not provide
- * API to get the icon. For example, when TTM_SETTITLE
- * is called with ICON_ERROR, when TTM_GETTITLE is used
- * to query the title and the icon, the uTitleBitmap
- * field in the TTGETTITLE struct is zero. The fix
- * is to remember these values, only set them when then
- * change and leak less.
- *
- * NOTE: This only happens on Vista.
- */
- if (hwndToolTip != toolTipHandle && hwndToolTip != balloonTipHandle) {
- return;
- }
- if (hwndToolTip == toolTipHandle) {
- if (text == toolTitle || (toolTitle != null && toolTitle.equals (text))) {
- if (icon == toolIcon) return;
- }
- toolTitle = text;
- toolIcon = icon;
- } else {
- if (hwndToolTip == balloonTipHandle) {
- if (text == balloonTitle || (balloonTitle != null && balloonTitle.equals (text))) {
- if (icon == toolIcon) return;
- }
- balloonTitle = text;
- balloonIcon = icon;
- }
- }
- if (text != null) {
- TCHAR pszTitle = new TCHAR (getCodePage (), text, true);
- OS.SendMessage (hwndToolTip, OS.TTM_SETTITLE, icon, pszTitle);
- } else {
- OS.SendMessage (hwndToolTip, OS.TTM_SETTITLE, 0, 0);
- }
-}
-
-public void setVisible (boolean visible) {
- checkWidget ();
- /*
- * Feature in Windows. When ShowWindow() is called used to hide
- * a window, Windows attempts to give focus to the parent. If the
- * parent is disabled by EnableWindow(), focus is assigned to
- * another windows on the desktop. This means that if you hide
- * a modal window before the parent is enabled, the parent will
- * not come to the front. The fix is to change the modal state
- * before hiding or showing a window so that this does not occur.
- */
- int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- if ((style & mask) != 0) {
- if (visible) {
- display.setModalShell (this);
- if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- display.setModalDialog (null);
- }
- Control control = display._getFocusControl ();
- if (control != null && !control.isActive ()) {
- bringToTop ();
- if (isDisposed ()) return;
- }
- int /*long*/ hwndShell = OS.GetActiveWindow ();
- if (hwndShell == 0) {
- if (parent != null) hwndShell = parent.handle;
- }
- if (hwndShell != 0) {
- OS.SendMessage (hwndShell, OS.WM_CANCELMODE, 0, 0);
- }
- OS.ReleaseCapture ();
- } else {
- display.clearModal (this);
- }
- } else {
- updateModal ();
- }
-
- /*
- * Bug in Windows. Calling ShowOwnedPopups() to hide the
- * child windows of a hidden window causes the application
- * to be deactivated. The fix is to call ShowOwnedPopups()
- * to hide children before hiding the parent.
- */
- if (showWithParent && !visible) {
- if (!OS.IsWinCE) OS.ShowOwnedPopups (handle, false);
- }
- if (!visible) fixActiveShell ();
- if (visible && center && !moved) {
- center ();
- if (isDisposed ()) return;
- }
- super.setVisible (visible);
- if (isDisposed ()) return;
- if (showWithParent != visible) {
- showWithParent = visible;
- if (visible) {
- if (!OS.IsWinCE) OS.ShowOwnedPopups (handle, true);
- }
- }
-
- /* Make the foreign window parent appear in the task bar */
- if (visible) {
- if (parent != null && (parent.state & FOREIGN_HANDLE) != 0) {
- int /*long*/ hwndParent = parent.handle;
- int style = OS.GetWindowLong (hwndParent, OS.GWL_EXSTYLE);
- if ((style & OS.WS_EX_TOOLWINDOW) != 0) {
- OS.SetWindowLong (hwndParent, OS.GWL_EXSTYLE, style & ~OS.WS_EX_TOOLWINDOW);
- /*
- * Bug in Windows. The window does not show in the task bar when
- * WS_EX_TOOLWINDOW is removed after the window has already been shown.
- * The fix is to hide and shown the shell.
- */
- OS.ShowWindow (hwndParent, OS.SW_HIDE);
- OS.ShowWindow (hwndParent, OS.SW_RESTORE);
- }
- }
- }
-}
-
-void subclass () {
- super.subclass ();
- if (ToolTipProc != 0) {
- int /*long*/ newProc = display.windowProc;
- if (toolTipHandle != 0) {
- OS.SetWindowLongPtr (toolTipHandle, OS.GWLP_WNDPROC, newProc);
- }
- if (balloonTipHandle != 0) {
- OS.SetWindowLongPtr (balloonTipHandle, OS.GWLP_WNDPROC, newProc);
- }
- }
-}
-
-int /*long*/ toolTipHandle () {
- if (toolTipHandle == 0) createToolTipHandle ();
- return toolTipHandle;
-}
-
-boolean translateAccelerator (MSG msg) {
- if (!isEnabled () || !isActive ()) return false;
- if (menuBar != null && !menuBar.isEnabled ()) return false;
- return translateMDIAccelerator (msg) || translateMenuAccelerator (msg);
-}
-
-boolean traverseEscape () {
- if (parent == null) return false;
- if (!isVisible () || !isEnabled ()) return false;
- close ();
- return true;
-}
-
-void unsubclass () {
- super.unsubclass ();
- if (ToolTipProc != 0) {
- if (toolTipHandle != 0) {
- OS.SetWindowLongPtr (toolTipHandle, OS.GWLP_WNDPROC, ToolTipProc);
- }
- if (toolTipHandle != 0) {
- OS.SetWindowLongPtr (toolTipHandle, OS.GWLP_WNDPROC, ToolTipProc);
- }
- }
-}
-
-void updateModal () {
- if (Display.TrimEnabled) {
- setItemEnabled (OS.SC_CLOSE, isActive ());
- } else {
- OS.EnableWindow (handle, isActive ());
- }
-}
-
-CREATESTRUCT widgetCreateStruct () {
- return null;
-}
-
-int /*long*/ widgetParent () {
- if (handle != 0) return handle;
- return parent != null ? parent.handle : 0;
-}
-
-int widgetExtStyle () {
- int bits = super.widgetExtStyle () & ~OS.WS_EX_MDICHILD;
- if ((style & SWT.TOOL) != 0) bits |= OS.WS_EX_TOOLWINDOW;
-
- /*
- * Feature in Windows. When a window that does not have a parent
- * is created, it is automatically added to the Windows Task Bar,
- * even when it has no title. The fix is to use WS_EX_TOOLWINDOW
- * which does not cause the window to appear in the Task Bar.
- */
- if (!OS.IsWinCE) {
- if (parent == null) {
- if ((style & SWT.ON_TOP) != 0) {
- int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX;
- if ((style & SWT.NO_TRIM) != 0 || (style & trim) == 0) {
- bits |= OS.WS_EX_TOOLWINDOW;
- }
- }
- }
- }
-
- /*
- * Bug in Windows 98 and NT. Creating a window with the
- * WS_EX_TOPMOST extended style can result in a dialog shell
- * being moved behind its parent. The exact case where this
- * happens is a shell with two dialog shell children where
- * each dialog child has another hidden dialog child with
- * the WS_EX_TOPMOST extended style. Clicking on either of
- * the visible dialogs causes them to become active but move
- * to the back, behind the parent shell. The fix is to
- * disallow the WS_EX_TOPMOST extended style on Windows 98
- * and NT.
- */
- if (parent != null) {
- if (OS.IsWin95) return bits;
- if (OS.WIN32_VERSION < OS.VERSION (4, 10)) {
- return bits;
- }
- }
- if ((style & SWT.ON_TOP) != 0) bits |= OS.WS_EX_TOPMOST;
- return bits;
-}
-
-TCHAR windowClass () {
- if (OS.IsSP) return DialogClass;
- if ((style & SWT.TOOL) != 0) {
- int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX | SWT.BORDER | SWT.RESIZE;
- if ((style & trim) == 0) return display.windowShadowClass;
- }
- return parent != null ? DialogClass : super.windowClass ();
-}
-
-int /*long*/ windowProc () {
- if (windowProc != 0) return windowProc;
- if (OS.IsSP) return DialogProc;
- if ((style & SWT.TOOL) != 0) {
- int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX | SWT.BORDER | SWT.RESIZE;
- if ((style & trim) == 0) return super.windowProc ();
- }
- return parent != null ? DialogProc : super.windowProc ();
-}
-
-int /*long*/ windowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- if (hwnd == toolTipHandle || hwnd == balloonTipHandle) {
- switch (msg) {
- case OS.WM_TIMER: {
- if (wParam != ToolTip.TIMER_ID) break;
- ToolTip tip = getCurrentToolTip (hwnd);
- if (tip != null && tip.autoHide) {
- tip.setVisible (false);
- }
- break;
- }
- case OS.WM_LBUTTONDOWN: {
- ToolTip tip = getCurrentToolTip (hwnd);
- if (tip != null) {
- tip.setVisible (false);
- tip.postEvent (SWT.Selection);
- }
- break;
- }
- }
- return callWindowProc (hwnd, msg, wParam, lParam);
- }
- return super.windowProc (hwnd, msg, wParam, lParam);
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle ();
- if (handle != 0) return bits | OS.WS_CHILD;
- bits &= ~OS.WS_CHILD;
- /*
- * Feature in WinCE. Calling CreateWindowEx () with WS_OVERLAPPED
- * and a parent window causes the new window to become a WS_CHILD of
- * the parent instead of a dialog child. The fix is to use WS_POPUP
- * for a window with a parent.
- *
- * Feature in WinCE PPC. A window without a parent with WS_POPUP
- * always shows on top of the Pocket PC 'Today Screen'. The fix
- * is to not set WS_POPUP for a window without a parent on WinCE
- * devices.
- *
- * NOTE: WS_POPUP causes CreateWindowEx () to ignore CW_USEDEFAULT
- * and causes the default window location and size to be zero.
- */
- if (OS.IsWinCE) {
- if (OS.IsSP) return bits | OS.WS_POPUP;
- return parent == null ? bits : bits | OS.WS_POPUP;
- }
-
- /*
- * Use WS_OVERLAPPED for all windows, either dialog or top level
- * so that CreateWindowEx () will respect CW_USEDEFAULT and set
- * the default window location and size.
- *
- * NOTE: When a WS_OVERLAPPED window is created, Windows gives
- * the new window WS_CAPTION style bits. These two constants are
- * as follows:
- *
- * WS_OVERLAPPED = 0
- * WS_CAPTION = WS_BORDER | WS_DLGFRAME
- *
- */
- return bits | OS.WS_OVERLAPPED | OS.WS_CAPTION;
-}
-
-LRESULT WM_ACTIVATE (int /*long*/ wParam, int /*long*/ lParam) {
- if (OS.IsPPC) {
- /*
- * Note: this does not work when we get WM_ACTIVATE prior
- * to adding a listener.
- */
- if (hooks (SWT.HardKeyDown) || hooks (SWT.HardKeyUp)) {
- int fActive = OS.LOWORD (wParam);
- int /*long*/ hwnd = fActive != 0 ? handle : 0;
- for (int bVk=OS.VK_APP1; bVk<=OS.VK_APP6; bVk++) {
- OS.SHSetAppKeyWndAssoc ((byte) bVk, hwnd);
- }
- }
- /* Restore SIP state when window is activated */
- if (OS.LOWORD (wParam) != 0) {
- OS.SHSipPreference (handle, psai.fSipUp == 0 ? OS.SIP_DOWN : OS.SIP_UP);
- }
- }
-
- /*
- * Bug in Windows XP. When a Shell is deactivated, the
- * IME composition window does not go away. This causes
- * repaint issues. The fix is to commit the composition
- * string.
- */
- if (OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
- if (OS.LOWORD (wParam) == 0 && OS.IsDBLocale && hIMC != 0) {
- if (OS.ImmGetOpenStatus (hIMC)) {
- OS.ImmNotifyIME (hIMC, OS.NI_COMPOSITIONSTR, OS.CPS_COMPLETE, 0);
- }
- }
- }
-
- /* Process WM_ACTIVATE */
- LRESULT result = super.WM_ACTIVATE (wParam, lParam);
- if (OS.LOWORD (wParam) == 0) {
- if (lParam == 0 || (lParam != toolTipHandle && lParam != balloonTipHandle)) {
- ToolTip tip = getCurrentToolTip ();
- if (tip != null) tip.setVisible (false);
- }
- }
- return parent != null ? LRESULT.ZERO : result;
-}
-
-LRESULT WM_COMMAND (int /*long*/ wParam, int /*long*/ lParam) {
- if (OS.IsPPC) {
- /*
- * Note in WinCE PPC: Close the Shell when the "Done Button" has
- * been pressed. lParam is either 0 (PocketPC 2002) or the handle
- * to the Shell (PocketPC).
- */
- int loWord = OS.LOWORD (wParam);
- if (loWord == OS.IDOK && (lParam == 0 || lParam == handle)) {
- OS.PostMessage (handle, OS.WM_CLOSE, 0, 0);
- return LRESULT.ZERO;
- }
- }
- /*
- * Feature in Windows. On PPC, the menu is not actually an HMENU.
- * By observation, it is a tool bar that is configured to look like
- * a menu. Therefore, when the PPC menu sends WM_COMMAND messages,
- * lParam is not zero because the WM_COMMAND was not sent from a menu.
- * Sub menu item events originate from the menu bar. Top menu items
- * events originate from a tool bar. The fix is to detect the source
- * of the WM_COMMAND and set lParam to zero to pretend that the message
- * came from a real Windows menu, not a tool bar.
- */
- if (OS.IsPPC || OS.IsSP) {
- if (menuBar != null) {
- int /*long*/ hwndCB = menuBar.hwndCB;
- if (lParam != 0 && hwndCB != 0) {
- if (lParam == hwndCB) {
- return super.WM_COMMAND (wParam, 0);
- } else {
- int /*long*/ hwndChild = OS.GetWindow (hwndCB, OS.GW_CHILD);
- if (lParam == hwndChild) return super.WM_COMMAND (wParam, 0);
- }
- }
- }
- }
- return super.WM_COMMAND (wParam, lParam);
-}
-
-LRESULT WM_DESTROY (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_DESTROY (wParam, lParam);
- /*
- * When the shell is a WS_CHILD window of a non-SWT
- * window, the destroy code does not get called because
- * the non-SWT window does not call dispose (). Instead,
- * the destroy code is called here in WM_DESTROY.
- */
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.WS_CHILD) != 0) {
- releaseParent ();
- release (false);
- }
- return result;
-}
-
-LRESULT WM_ERASEBKGND (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. When a shell is resized by dragging
- * the resize handles, Windows temporarily fills in black
- * rectangles where the new contents of the shell should
- * draw. The fix is to always draw the background of shells.
- *
- * NOTE: This only happens on Vista.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- drawBackground (wParam);
- return LRESULT.ONE;
- }
- return result;
-}
-
-LRESULT WM_ENTERIDLE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_ENTERIDLE (wParam, lParam);
- if (result != null) return result;
- if (display.runMessages) {
- if (display.runAsyncMessages (false)) display.wakeThread ();
- }
- return result;
-}
-
-LRESULT WM_GETMINMAXINFO (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_GETMINMAXINFO (wParam, lParam);
- if (result != null) return result;
- if (minWidth != SWT.DEFAULT || minHeight != SWT.DEFAULT) {
- MINMAXINFO info = new MINMAXINFO ();
- OS.MoveMemory (info, lParam, MINMAXINFO.sizeof);
- if (minWidth != SWT.DEFAULT) info.ptMinTrackSize_x = minWidth;
- if (minHeight != SWT.DEFAULT) info.ptMinTrackSize_y = minHeight;
- OS.MoveMemory (lParam, info, MINMAXINFO.sizeof);
- return LRESULT.ZERO;
- }
- return result;
-}
-
-LRESULT WM_MOUSEACTIVATE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_MOUSEACTIVATE (wParam, lParam);
- if (result != null) return result;
-
- /*
- * Check for WM_MOUSEACTIVATE when an MDI shell is active
- * and stop the normal shell activation but allow the mouse
- * down to be delivered.
- */
- int hittest = (short) OS.LOWORD (lParam);
- switch (hittest) {
- case OS.HTERROR:
- case OS.HTTRANSPARENT:
- case OS.HTNOWHERE:
- break;
- default: {
- Control control = display._getFocusControl ();
- if (control != null) {
- Decorations decorations = control.menuShell ();
- if (decorations.getShell () == this && decorations != this) {
- display.ignoreRestoreFocus = true;
- display.lastHittest = hittest;
- display.lastHittestControl = null;
- if (hittest == OS.HTMENU || hittest == OS.HTSYSMENU) {
- display.lastHittestControl = control;
- return null;
- }
- if (OS.IsWin95 && hittest == OS.HTCAPTION) {
- display.lastHittestControl = control;
- }
- return new LRESULT (OS.MA_NOACTIVATE);
- }
- }
- }
- }
- if (hittest == OS.HTMENU) return null;
-
- /*
- * Get the current location of the cursor,
- * not the location of the cursor when the
- * WM_MOUSEACTIVATE was generated. This is
- * strictly incorrect but is necessary in
- * order to support Activate and Deactivate
- * events for embedded widgets that have
- * their own event loop. In that case, the
- * cursor location reported by GetMessagePos()
- * is the one for our event loop, not the
- * embedded widget's event loop.
- */
- POINT pt = new POINT ();
- if (!OS.GetCursorPos (pt)) {
- int pos = OS.GetMessagePos ();
- OS.POINTSTOPOINT (pt, pos);
- }
- int /*long*/ hwnd = OS.WindowFromPoint (pt);
- if (hwnd == 0) return null;
- Control control = display.findControl (hwnd);
-
- /*
- * When a shell is created with SWT.ON_TOP and SWT.NO_FOCUS,
- * do not activate the shell when the user clicks on the
- * the client area or on the border or a control within the
- * shell that does not take focus.
- */
- if (control != null && (control.state & CANVAS) != 0) {
- if ((control.style & SWT.NO_FOCUS) != 0) {
- int bits = SWT.ON_TOP | SWT.NO_FOCUS;
- if ((style & bits) == bits) {
- if (hittest == OS.HTBORDER || hittest == OS.HTCLIENT) {
- return new LRESULT (OS.MA_NOACTIVATE);
- }
- }
- }
- }
-
- int /*long*/ code = callWindowProc (handle, OS.WM_MOUSEACTIVATE, wParam, lParam);
- setActiveControl (control);
- return new LRESULT (code);
-}
-
-LRESULT WM_MOVE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_MOVE (wParam, lParam);
- if (result != null) return result;
- ToolTip tip = getCurrentToolTip ();
- if (tip != null) tip.setVisible (false);
- return result;
-}
-
-LRESULT WM_NCHITTEST (int /*long*/ wParam, int /*long*/ lParam) {
- if (!OS.IsWindowEnabled (handle)) return null;
- if (!isEnabled () || !isActive ()) {
- if (!Display.TrimEnabled) return new LRESULT (OS.HTNOWHERE);
- int /*long*/ hittest = callWindowProc (handle, OS.WM_NCHITTEST, wParam, lParam);
- if (hittest == OS.HTCLIENT || hittest == OS.HTMENU) hittest = OS.HTBORDER;
- return new LRESULT (hittest);
- }
- if (menuBar != null && !menuBar.getEnabled ()) {
- int /*long*/ hittest = callWindowProc (handle, OS.WM_NCHITTEST, wParam, lParam);
- if (hittest == OS.HTMENU) hittest = OS.HTBORDER;
- return new LRESULT (hittest);
- }
- return null;
-}
-
-LRESULT WM_NCLBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_NCLBUTTONDOWN (wParam, lParam);
- if (result != null) return result;
- /*
- * When the normal activation was interrupted in WM_MOUSEACTIVATE
- * because the active shell was an MDI shell, set the active window
- * to the top level shell but lock the active window and stop focus
- * changes. This allows the user to interact the top level shell
- * in the normal manner.
- */
- if (!display.ignoreRestoreFocus) return result;
- Display display = this.display;
- int /*long*/ hwndActive = 0;
- boolean fixActive = OS.IsWin95 && display.lastHittest == OS.HTCAPTION;
- if (fixActive) hwndActive = OS.SetActiveWindow (handle);
- display.lockActiveWindow = true;
- int /*long*/ code = callWindowProc (handle, OS.WM_NCLBUTTONDOWN, wParam, lParam);
- display.lockActiveWindow = false;
- if (fixActive) OS.SetActiveWindow (hwndActive);
- Control focusControl = display.lastHittestControl;
- if (focusControl != null && !focusControl.isDisposed ()) {
- focusControl.setFocus ();
- }
- display.lastHittestControl = null;
- display.ignoreRestoreFocus = false;
- return new LRESULT (code);
-}
-
-LRESULT WM_PALETTECHANGED (int /*long*/ wParam, int /*long*/ lParam) {
- if (wParam != handle) {
- int /*long*/ hPalette = display.hPalette;
- if (hPalette != 0) return selectPalette (hPalette);
- }
- return super.WM_PALETTECHANGED (wParam, lParam);
-}
-
-LRESULT WM_QUERYNEWPALETTE (int /*long*/ wParam, int /*long*/ lParam) {
- int /*long*/ hPalette = display.hPalette;
- if (hPalette != 0) return selectPalette (hPalette);
- return super.WM_QUERYNEWPALETTE (wParam, lParam);
-}
-
-LRESULT WM_SETCURSOR (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. When the shell is disabled
- * by a Windows standard dialog (like a MessageBox
- * or FileDialog), clicking in the shell does not
- * bring the shell or the dialog to the front. The
- * fix is to detect this case and bring the shell
- * forward.
- */
- int msg = OS.HIWORD (lParam);
- if (msg == OS.WM_LBUTTONDOWN) {
- if (!Display.TrimEnabled) {
- Shell modalShell = display.getModalShell ();
- if (modalShell != null && !isActive ()) {
- int /*long*/ hwndModal = modalShell.handle;
- if (OS.IsWindowEnabled (hwndModal)) {
- OS.SetActiveWindow (hwndModal);
- }
- }
- }
- if (!OS.IsWindowEnabled (handle)) {
- if (!OS.IsWinCE) {
- int /*long*/ hwndPopup = OS.GetLastActivePopup (handle);
- if (hwndPopup != 0 && hwndPopup != handle) {
- if (display.getControl (hwndPopup) == null) {
- if (OS.IsWindowEnabled (hwndPopup)) {
- OS.SetActiveWindow (hwndPopup);
- }
- }
- }
- }
- }
- }
- /*
- * When the shell that contains a cursor is disabled,
- * WM_SETCURSOR is called with HTERROR. Normally,
- * when a control is disabled, the parent will get
- * mouse and cursor events. In the case of a disabled
- * shell, there is no enabled parent. In order to
- * show the cursor when a shell is disabled, it is
- * necessary to override WM_SETCURSOR when called
- * with HTERROR to set the cursor but only when the
- * mouse is in the client area of the shell.
- */
- int hitTest = (short) OS.LOWORD (lParam);
- if (hitTest == OS.HTERROR) {
- if (!getEnabled ()) {
- Control control = display.getControl (wParam);
- if (control == this && cursor != null) {
- POINT pt = new POINT ();
- int pos = OS.GetMessagePos ();
- OS.POINTSTOPOINT (pt, pos);
- OS.ScreenToClient (handle, pt);
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- if (OS.PtInRect (rect, pt)) {
- OS.SetCursor (cursor.handle);
- switch (msg) {
- case OS.WM_LBUTTONDOWN:
- case OS.WM_RBUTTONDOWN:
- case OS.WM_MBUTTONDOWN:
- case OS.WM_XBUTTONDOWN:
- OS.MessageBeep (OS.MB_OK);
- }
- return LRESULT.ONE;
- }
- }
- }
- }
- return super.WM_SETCURSOR (wParam, lParam);
-}
-
-LRESULT WM_SETTINGCHANGE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SETTINGCHANGE (wParam, lParam);
- if (result != null) return result;
- if (OS.IsPPC) {
- if (wParam == OS.SPI_SETSIPINFO) {
- /*
- * The SIP is in a new state. Cache its new value.
- * Resize the Shell if it has the style SWT.RESIZE.
- * Note that SHHandleWMSettingChange resizes the
- * Shell and also updates the cached state.
- */
- if ((style & SWT.RESIZE) != 0) {
- OS.SHHandleWMSettingChange (handle, wParam, lParam, psai);
- return LRESULT.ZERO;
- } else {
- SIPINFO pSipInfo = new SIPINFO ();
- pSipInfo.cbSize = SIPINFO.sizeof;
- OS.SipGetInfo (pSipInfo);
- psai.fSipUp = pSipInfo.fdwFlags & OS.SIPF_ON;
- }
- }
- }
- return result;
-}
-
-LRESULT WM_SHOWWINDOW (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SHOWWINDOW (wParam, lParam);
- if (result != null) return result;
- /*
- * Bug in Windows. If the shell is hidden while the parent
- * is iconic, Windows shows the shell when the parent is
- * deiconified. This does not happen if the shell is hidden
- * while the parent is not an icon. The fix is to track
- * visible state for the shell and refuse to show the shell
- * when the parent is shown.
- */
- if (lParam == OS.SW_PARENTOPENING) {
- Control control = this;
- while (control != null) {
- Shell shell = control.getShell ();
- if (!shell.showWithParent) return LRESULT.ZERO;
- control = control.parent;
- }
- }
- return result;
-}
-
-LRESULT WM_SYSCOMMAND (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SYSCOMMAND (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. When the last visible window in
- * a process minimized, Windows swaps out the memory for
- * the process. The assumption is that the user can no
- * longer interact with the window, so the memory can be
- * released to other applications. However, for programs
- * that use a lot of memory, swapping the memory back in
- * can take a long time, sometimes minutes. The fix is
- * to intercept WM_SYSCOMMAND looking for SC_MINIMIZE
- * and use ShowWindow() with SW_SHOWMINIMIZED to minimize
- * the window, rather than running the default window proc.
- *
- * NOTE: The default window proc activates the next
- * top-level window in the Z-order while ShowWindow()
- * with SW_SHOWMINIMIZED does not. There is no fix for
- * this at this time.
- */
- if (OS.IsWinNT) {
- int cmd = (int)/*64*/wParam & 0xFFF0;
- switch (cmd) {
- case OS.SC_MINIMIZE:
- long memory = Runtime.getRuntime ().totalMemory ();
- if (memory >= 32 * 1024 * 1024) {
- OS.ShowWindow (handle, OS.SW_SHOWMINIMIZED);
- return LRESULT.ZERO;
- }
- }
- }
- return result;
-}
-
-LRESULT WM_WINDOWPOSCHANGING (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_WINDOWPOSCHANGING (wParam,lParam);
- if (result != null) return result;
- WINDOWPOS lpwp = new WINDOWPOS ();
- OS.MoveMemory (lpwp, lParam, WINDOWPOS.sizeof);
- if ((lpwp.flags & OS.SWP_NOSIZE) == 0) {
- lpwp.cx = Math.max (lpwp.cx, minWidth);
- int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX;
- if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) {
- lpwp.cx = Math.max (lpwp.cx, OS.GetSystemMetrics (OS.SM_CXMINTRACK));
- }
- lpwp.cy = Math.max (lpwp.cy, minHeight);
- if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) {
- if ((style & SWT.RESIZE) != 0) {
- lpwp.cy = Math.max (lpwp.cy, OS.GetSystemMetrics (OS.SM_CYMINTRACK));
- } else {
- RECT rect = new RECT ();
- int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
- int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
- OS.AdjustWindowRectEx (rect, bits1, false, bits2);
- lpwp.cy = Math.max (lpwp.cy, rect.bottom - rect.top);
- }
- }
- OS.MoveMemory (lParam, lpwp, WINDOWPOS.sizeof);
- }
- return result;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Slider.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Slider.java
deleted file mode 100755
index 086a9d56be..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Slider.java
+++ /dev/null
@@ -1,788 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that represent a range of positive, numeric values.
- * <p>
- * At any given moment, a given slider will have a
- * single 'selection' that is considered to be its
- * value, which is constrained to be within the range of
- * values the slider represents (that is, between its
- * <em>minimum</em> and <em>maximum</em> values).
- * </p><p>
- * Typically, sliders will be made up of five areas:
- * <ol>
- * <li>an arrow button for decrementing the value</li>
- * <li>a page decrement area for decrementing the value by a larger amount</li>
- * <li>a <em>thumb</em> for modifying the value by mouse dragging</li>
- * <li>a page increment area for incrementing the value by a larger amount</li>
- * <li>an arrow button for incrementing the value</li>
- * </ol>
- * Based on their style, sliders are either <code>HORIZONTAL</code>
- * (which have a left facing button for decrementing the value and a
- * right facing button for incrementing it) or <code>VERTICAL</code>
- * (which have an upward facing button for decrementing the value
- * and a downward facing buttons for incrementing it).
- * </p><p>
- * On some platforms, the size of the slider's thumb can be
- * varied relative to the magnitude of the range of values it
- * represents (that is, relative to the difference between its
- * maximum and minimum values). Typically, this is used to
- * indicate some proportional value such as the ratio of the
- * visible area of a document to the total amount of space that
- * it would take to display it. SWT supports setting the thumb
- * size even if the underlying platform does not, but in this
- * case the appearance of the slider will not change.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see ScrollBar
- * @see <a href="http://www.eclipse.org/swt/snippets/#slider">Slider snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Slider extends Control {
- int increment, pageIncrement;
- boolean ignoreFocus;
- static final int /*long*/ ScrollBarProc;
- static final TCHAR ScrollBarClass = new TCHAR (0, "SCROLLBAR", true);
- static {
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, ScrollBarClass, lpWndClass);
- ScrollBarProc = lpWndClass.lpfnWndProc;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Slider (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values:
- * <code>SWT.NONE</code> - for the end of a drag.
- * <code>SWT.DRAG</code>.
- * <code>SWT.HOME</code>.
- * <code>SWT.END</code>.
- * <code>SWT.ARROW_DOWN</code>.
- * <code>SWT.ARROW_UP</code>.
- * <code>SWT.PAGE_DOWN</code>.
- * <code>SWT.PAGE_UP</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- /*
- * Feature in Windows. Windows runs a modal message
- * loop when the user drags a scroll bar. This means
- * that mouse down events won't get delivered until
- * after the loop finishes. The fix is to run any
- * deferred messages, including mouse down messages
- * before calling the scroll bar window proc.
- */
- switch (msg) {
- case OS.WM_LBUTTONDOWN:
- case OS.WM_LBUTTONDBLCLK:
- display.runDeferredEvents ();
- }
- return OS.CallWindowProc (ScrollBarProc, hwnd, msg, wParam, lParam);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += OS.GetSystemMetrics (OS.SM_CXHSCROLL) * 10;
- height += OS.GetSystemMetrics (OS.SM_CYHSCROLL);
- } else {
- width += OS.GetSystemMetrics (OS.SM_CXVSCROLL);
- height += OS.GetSystemMetrics (OS.SM_CYVSCROLL) * 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-
-void createWidget () {
- super.createWidget ();
- increment = 1;
- pageIncrement = 10;
- /*
- * Set the initial values of the maximum
- * to 100 and the thumb to 10. Note that
- * info.nPage needs to be 11 in order to
- * get a thumb that is 10.
- */
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_ALL;
- info.nMax = 100;
- info.nPage = 11;
- OS.SetScrollInfo (handle, OS.SB_CTL, info, true);
-}
-
-int defaultBackground () {
- return OS.GetSysColor (OS.COLOR_SCROLLBAR);
-}
-
-int defaultForeground () {
- return OS.GetSysColor (OS.COLOR_BTNFACE);
-}
-
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- if (!OS.IsWinCE) {
- int flags = enabled ? OS.ESB_ENABLE_BOTH : OS.ESB_DISABLE_BOTH;
- OS.EnableScrollBar (handle, OS.SB_CTL, flags);
- }
- if (enabled) {
- state &= ~DISABLED;
- } else {
- state |= DISABLED;
- }
-}
-
-public boolean getEnabled () {
- checkWidget ();
- return (state & DISABLED) == 0;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget ();
- return increment;
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget ();
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_RANGE;
- OS.GetScrollInfo (handle, OS.SB_CTL, info);
- return info.nMax;
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget ();
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_RANGE;
- OS.GetScrollInfo (handle, OS.SB_CTL, info);
- return info.nMin;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget ();
- return pageIncrement;
-}
-
-/**
- * Returns the 'selection', which is the receiver's value.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget ();
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_POS;
- OS.GetScrollInfo (handle, OS.SB_CTL, info);
- return info.nPos;
-}
-
-/**
- * Returns the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values.
- *
- * @return the thumb value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getThumb () {
- checkWidget ();
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_PAGE;
- OS.GetScrollInfo (handle, OS.SB_CTL, info);
- if (info.nPage != 0) --info.nPage;
- return info.nPage;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-void setBounds (int x, int y, int width, int height, int flags) {
- super.setBounds (x, y, width, height, flags);
- /*
- * Bug in Windows. If the scroll bar is resized when it has focus,
- * the flashing cursor that is used to show that the scroll bar has
- * focus is not moved. The fix is to send a fake WM_SETFOCUS to
- * get the scroll bar to recompute the size of the flashing cursor.
- */
- if (OS.GetFocus () == handle) {
- ignoreFocus = true;
- OS.SendMessage (handle, OS.WM_SETFOCUS, 0, 0);
- ignoreFocus = false;
- }
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- increment = value;
-}
-
-/**
- * Sets the maximum. If this value is negative or less than or
- * equal to the minimum, the value is ignored. If necessary, first
- * the thumb and then the selection are adjusted to fit within the
- * new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget ();
- if (value < 0) return;
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL;
- OS.GetScrollInfo (handle, OS.SB_CTL, info);
- if (value - info.nMin - info.nPage < 1) return;
- info.nMax = value;
- SetScrollInfo (handle, OS.SB_CTL, info, true);
-}
-
-/**
- * Sets the minimum value. If this value is negative or greater
- * than or equal to the maximum, the value is ignored. If necessary,
- * first the thumb and then the selection are adjusted to fit within
- * the new range.
- *
- * @param value the new minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget ();
- if (value < 0) return;
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL;
- OS.GetScrollInfo (handle, OS.SB_CTL, info);
- if (info.nMax - value - info.nPage < 1) return;
- info.nMin = value;
- SetScrollInfo (handle, OS.SB_CTL, info, true);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- pageIncrement = value;
-}
-
-boolean SetScrollInfo (int /*long*/ hwnd, int flags, SCROLLINFO info, boolean fRedraw) {
- /*
- * Feature in Windows. Using SIF_DISABLENOSCROLL,
- * SetScrollInfo () can change enabled and disabled
- * state of the scroll bar causing a scroll bar that
- * was disabled by the application to become enabled.
- * The fix is to disable the scroll bar (again) when
- * the application has disabled the scroll bar.
- */
- if ((state & DISABLED) != 0) fRedraw = false;
- boolean result = OS.SetScrollInfo (hwnd, flags, info, fRedraw);
- if ((state & DISABLED) != 0) {
- OS.EnableWindow (handle, false);
- if (!OS.IsWinCE) {
- OS.EnableScrollBar (handle, OS.SB_CTL, OS.ESB_DISABLE_BOTH);
- }
- }
-
- /*
- * Bug in Windows. If the thumb is resized when it has focus,
- * the flashing cursor that is used to show that the scroll bar
- * has focus is not moved. The fix is to send a fake WM_SETFOCUS
- * to get the scroll bar to recompute the size of the flashing
- * cursor.
- */
- if (OS.GetFocus () == handle) {
- ignoreFocus = true;
- OS.SendMessage (handle, OS.WM_SETFOCUS, 0, 0);
- ignoreFocus = false;
- }
- return result;
-}
-
-/**
- * Sets the 'selection', which is the receiver's
- * value, to the argument which must be greater than or equal
- * to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget ();
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_POS;
- info.nPos = value;
- SetScrollInfo (handle, OS.SB_CTL, info, true);
-}
-
-/**
- * Sets the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values. This new
- * value will be ignored if it is less than one, and will be
- * clamped if it exceeds the receiver's current range.
- *
- * @param value the new thumb value, which must be at least one and not
- * larger than the size of the current range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setThumb (int value) {
- checkWidget ();
- if (value < 1) return;
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_PAGE | OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL;
- OS.GetScrollInfo (handle, OS.SB_CTL, info);
- info.nPage = value;
- if (info.nPage != 0) info.nPage++;
- SetScrollInfo (handle, OS.SB_CTL, info, true);
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, thumb, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param thumb the new thumb value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- checkWidget ();
- if (minimum < 0) return;
- if (maximum < 0) return;
- if (thumb < 1) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- this.increment = increment;
- this.pageIncrement = pageIncrement;
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_POS | OS.SIF_PAGE | OS.SIF_RANGE | OS.SIF_DISABLENOSCROLL;
- info.nPos = selection;
- info.nMin = minimum;
- info.nMax = maximum;
- info.nPage = thumb;
- if (info.nPage != 0) info.nPage++;
- SetScrollInfo (handle, OS.SB_CTL, info, true);
-}
-
-int widgetExtStyle () {
- /*
- * Bug in Windows. If a scroll bar control is given a border,
- * dragging the scroll bar thumb eats away parts of the border
- * while the thumb is dragged. The fix is to clear border for
- * all scroll bars.
- */
- int bits = super.widgetExtStyle ();
- if ((style & SWT.BORDER) != 0) bits &= ~OS.WS_EX_CLIENTEDGE;
- return bits;
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle () | OS.WS_TABSTOP;
- /*
- * Bug in Windows. If a scroll bar control is given a border,
- * dragging the scroll bar thumb eats away parts of the border
- * while the thumb is dragged. The fix is to clear WS_BORDER.
- */
- if ((style & SWT.BORDER) != 0) bits &= ~OS.WS_BORDER;
- if ((style & SWT.HORIZONTAL) != 0) return bits | OS.SBS_HORZ;
- return bits | OS.SBS_VERT;
-}
-
-TCHAR windowClass () {
- return ScrollBarClass;
-}
-
-int /*long*/ windowProc () {
- return ScrollBarProc;
-}
-
-LRESULT WM_KEYDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_KEYDOWN (wParam, lParam);
- if (result != null) return result;
- if ((style & SWT.VERTICAL) != 0) return result;
- /*
- * Bug in Windows. When a horizontal scroll bar is mirrored,
- * the native control does not correctly swap the arrow keys.
- * The fix is to swap them before calling the scroll bar window
- * proc.
- *
- * NOTE: This fix is not ideal. It breaks when the bug is fixed
- * in the operating system.
- */
- if ((style & SWT.MIRRORED) != 0) {
- switch ((int)/*64*/wParam) {
- case OS.VK_LEFT:
- case OS.VK_RIGHT: {
- int key = wParam == OS.VK_LEFT ? OS.VK_RIGHT : OS.VK_LEFT;
- int /*long*/ code = callWindowProc (handle, OS.WM_KEYDOWN, key, lParam);
- return new LRESULT (code);
- }
- }
- }
- return result;
-}
-
-LRESULT WM_LBUTTONDBLCLK (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. Windows uses the WS_TABSTOP
- * style for the scroll bar to decide that focus
- * should be set during WM_LBUTTONDBLCLK. This is
- * not the desired behavior. The fix is to clear
- * and restore WS_TABSTOP so that Windows will not
- * assign focus.
- */
- int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- int newBits = oldBits & ~OS.WS_TABSTOP;
- OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
- LRESULT result = super.WM_LBUTTONDBLCLK (wParam, lParam);
- if (isDisposed ()) return LRESULT.ZERO;
- OS.SetWindowLong (handle, OS.GWL_STYLE, oldBits);
- if (result == LRESULT.ZERO) return result;
-
- /*
- * Feature in Windows. Windows runs a modal message loop
- * when the user drags a scroll bar that terminates when
- * it sees an WM_LBUTTONUP. Unfortunately the WM_LBUTTONUP
- * is consumed. The fix is to send a fake mouse up and
- * release the automatic capture.
- */
- if (!OS.IsWinCE) {
- if (OS.GetCapture () == handle) OS.ReleaseCapture ();
- if (!sendMouseEvent (SWT.MouseUp, 1, handle, OS.WM_LBUTTONUP, wParam, lParam)) {
- return LRESULT.ZERO;
- }
- }
- return result;
-}
-
-LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. Windows uses the WS_TABSTOP
- * style for the scroll bar to decide that focus
- * should be set during WM_LBUTTONDOWN. This is
- * not the desired behavior. The fix is to clear
- * and restore WS_TABSTOP so that Windows will not
- * assign focus.
- */
- int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- int newBits = oldBits & ~OS.WS_TABSTOP;
- OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
- LRESULT result = super.WM_LBUTTONDOWN (wParam, lParam);
- if (isDisposed ()) return LRESULT.ZERO;
- OS.SetWindowLong (handle, OS.GWL_STYLE, oldBits);
- if (result == LRESULT.ZERO) return result;
-
- /*
- * Feature in Windows. Windows runs a modal message loop
- * when the user drags a scroll bar that terminates when
- * it sees an WM_LBUTTONUP. Unfortunately the WM_LBUTTONUP
- * is consumed. The fix is to send a fake mouse up and
- * release the automatic capture.
- */
- if (!OS.IsWinCE) {
- if (OS.GetCapture () == handle) OS.ReleaseCapture ();
- if (!sendMouseEvent (SWT.MouseUp, 1, handle, OS.WM_LBUTTONUP, wParam, lParam)) {
- return LRESULT.ONE;
- }
- }
- return result;
-}
-
-LRESULT WM_SETFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- if (ignoreFocus) return null;
- return super.WM_SETFOCUS (wParam, lParam);
-}
-
-LRESULT wmScrollChild (int /*long*/ wParam, int /*long*/ lParam) {
-
- /* Do nothing when scrolling is ending */
- int code = OS.LOWORD (wParam);
- if (code == OS.SB_ENDSCROLL) return null;
-
- /* Move the thumb */
- Event event = new Event ();
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_TRACKPOS | OS.SIF_POS | OS.SIF_RANGE;
- OS.GetScrollInfo (handle, OS.SB_CTL, info);
- info.fMask = OS.SIF_POS;
- switch (code) {
- case OS.SB_THUMBPOSITION:
- event.detail = SWT.NONE;
- info.nPos = info.nTrackPos;
- break;
- case OS.SB_THUMBTRACK:
- event.detail = SWT.DRAG;
- info.nPos = info.nTrackPos;
- break;
- case OS.SB_TOP:
- event.detail = SWT.HOME;
- info.nPos = info.nMin;
- break;
- case OS.SB_BOTTOM:
- event.detail = SWT.END;
- info.nPos = info.nMax;
- break;
- case OS.SB_LINEDOWN:
- event.detail = SWT.ARROW_DOWN;
- info.nPos += increment;
- break;
- case OS.SB_LINEUP:
- event.detail = SWT.ARROW_UP;
- info.nPos = Math.max (info.nMin, info.nPos - increment);
- break;
- case OS.SB_PAGEDOWN:
- event.detail = SWT.PAGE_DOWN;
- info.nPos += pageIncrement;
- break;
- case OS.SB_PAGEUP:
- event.detail = SWT.PAGE_UP;
- info.nPos = Math.max (info.nMin, info.nPos - pageIncrement);
- break;
- }
- OS.SetScrollInfo (handle, OS.SB_CTL, info, true);
-
- /*
- * Feature in Windows. Windows runs a modal message
- * loop when the user drags a scroll bar. This means
- * that selection event must be sent because WM_HSCROLL
- * and WM_VSCROLL are sent from the modal message loop
- * so that they are delivered during inside the loop.
- */
- sendEvent (SWT.Selection, event);
- // the widget could be destroyed at this point
- return null;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Spinner.java
deleted file mode 100644
index 8c7b19d696..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Spinner.java
+++ /dev/null
@@ -1,1460 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify numeric
- * values.
- * <p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, Modify, Verify</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#spinner">Spinner snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Spinner extends Composite {
- int /*long*/ hwndText, hwndUpDown;
- boolean ignoreModify;
- int pageIncrement, digits;
- static final int /*long*/ EditProc;
- static final TCHAR EditClass = new TCHAR (0, "EDIT", true);
- static final int /*long*/ UpDownProc;
- static final TCHAR UpDownClass = new TCHAR (0, OS.UPDOWN_CLASS, true);
- static {
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, EditClass, lpWndClass);
- EditProc = lpWndClass.lpfnWndProc;
- OS.GetClassInfo (0, UpDownClass, lpWndClass);
- UpDownProc = lpWndClass.lpfnWndProc;
- }
-
- /**
- * the operating system limit for the number of characters
- * that the text field in an instance of this class can hold
- *
- * @since 3.4
- */
- public static final int LIMIT;
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = OS.IsWinNT ? 0x7FFFFFFF : 0x7FFF;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#READ_ONLY
- * @see SWT#WRAP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Spinner (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- if (hwnd == hwndText) {
- return OS.CallWindowProc (EditProc, hwnd, msg, wParam, lParam);
- }
- if (hwnd == hwndUpDown) {
- return OS.CallWindowProc (UpDownProc, hwnd, msg, wParam, lParam);
- }
- return OS.DefWindowProc (handle, msg, wParam, lParam);
-}
-
-static int checkStyle (int style) {
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-boolean checkHandle (int /*long*/ hwnd) {
- return hwnd == handle || hwnd == hwndText || hwnd == hwndUpDown;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createHandle () {
- super.createHandle ();
- state &= ~(CANVAS | THEME_BACKGROUND);
- int /*long*/ hInstance = OS.GetModuleHandle (null);
- int textExStyle = (style & SWT.BORDER) != 0 ? OS.WS_EX_CLIENTEDGE : 0;
- int textStyle = OS.WS_CHILD | OS.WS_VISIBLE | OS.ES_AUTOHSCROLL | OS.WS_CLIPSIBLINGS;
- if ((style & SWT.READ_ONLY) != 0) textStyle |= OS.ES_READONLY;
- if (OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- if ((style & SWT.RIGHT_TO_LEFT) != 0) textExStyle |= OS.WS_EX_LAYOUTRTL;
- }
- hwndText = OS.CreateWindowEx (
- textExStyle,
- EditClass,
- null,
- textStyle,
- 0, 0, 0, 0,
- handle,
- 0,
- hInstance,
- null);
- if (hwndText == 0) error (SWT.ERROR_NO_HANDLES);
- OS.SetWindowLongPtr (hwndText, OS.GWLP_ID, hwndText);
- int upDownStyle = OS.WS_CHILD | OS.WS_VISIBLE | OS.UDS_AUTOBUDDY;
- if ((style & SWT.WRAP) != 0) upDownStyle |= OS.UDS_WRAP;
- if ((style & SWT.BORDER) != 0) {
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- upDownStyle |= OS.UDS_ALIGNLEFT;
- } else {
- upDownStyle |= OS.UDS_ALIGNRIGHT;
- }
- }
- hwndUpDown = OS.CreateWindowEx (
- 0,
- UpDownClass,
- null,
- upDownStyle,
- 0, 0, 0, 0,
- handle,
- 0,
- hInstance,
- null);
- if (hwndUpDown == 0) error (SWT.ERROR_NO_HANDLES);
- int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE;
- SetWindowPos (hwndText, hwndUpDown, 0, 0, 0, 0, flags);
- OS.SetWindowLongPtr (hwndUpDown, OS.GWLP_ID, hwndUpDown);
- if (OS.IsDBLocale) {
- int /*long*/ hIMC = OS.ImmGetContext (handle);
- OS.ImmAssociateContext (hwndText, hIMC);
- OS.ImmAssociateContext (hwndUpDown, hIMC);
- OS.ImmReleaseContext (handle, hIMC);
- }
- OS.SendMessage (hwndUpDown, OS.UDM_SETRANGE32, 0, 100);
- OS.SendMessage (hwndUpDown, OS.IsWinCE ? OS.UDM_SETPOS : OS.UDM_SETPOS32, 0, 0);
- pageIncrement = 10;
- digits = 0;
- TCHAR buffer = new TCHAR (getCodePage (), "0", true);
- OS.SetWindowText (hwndText, buffer);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is not called for texts.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- */
-void addVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-
-int /*long*/ borderHandle () {
- return hwndText;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0;
- if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
- int /*long*/ newFont, oldFont = 0;
- int /*long*/ hDC = OS.GetDC (hwndText);
- newFont = OS.SendMessage (hwndText, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ();
- OS.GetTextMetrics (hDC, tm);
- height = tm.tmHeight;
- RECT rect = new RECT ();
- int [] max = new int [1];
- OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, null, max);
- String string = String.valueOf (max [0]);
- if (digits > 0) {
- StringBuffer buffer = new StringBuffer ();
- buffer.append (string);
- buffer.append (getDecimalSeparator ());
- int count = digits - string.length ();
- while (count >= 0) {
- buffer.append ("0");
- count--;
- }
- string = buffer.toString ();
- }
- TCHAR buffer = new TCHAR (getCodePage (), string, false);
- int flags = OS.DT_CALCRECT | OS.DT_EDITCONTROL | OS.DT_NOPREFIX;
- OS.DrawText (hDC, buffer, buffer.length (), rect, flags);
- width = rect.right - rect.left;
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (hwndText, hDC);
- }
- if (width == 0) width = DEFAULT_WIDTH;
- if (height == 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- Rectangle trim = computeTrim (0, 0, width, height);
- if (hHint == SWT.DEFAULT) {
- int upDownHeight = OS.GetSystemMetrics (OS.SM_CYVSCROLL) + 2 * getBorderWidth ();
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- upDownHeight += (style & SWT.BORDER) != 0 ? 1 : 3;
- }
- trim.height = Math.max (trim.height, upDownHeight);
- }
- return new Point (trim.width, trim.height);
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
-
- /* Get the trim of the text control */
- RECT rect = new RECT ();
- OS.SetRect (rect, x, y, x + width, y + height);
- int bits0 = OS.GetWindowLong (hwndText, OS.GWL_STYLE);
- int bits1 = OS.GetWindowLong (hwndText, OS.GWL_EXSTYLE);
- OS.AdjustWindowRectEx (rect, bits0, false, bits1);
- width = rect.right - rect.left;
- height = rect.bottom - rect.top;
-
- /*
- * The preferred height of a single-line text widget
- * has been hand-crafted to be the same height as
- * the single-line text widget in an editable combo
- * box.
- */
- int /*long*/ margins = OS.SendMessage (hwndText, OS.EM_GETMARGINS, 0, 0);
- x -= OS.LOWORD (margins);
- width += OS.LOWORD (margins) + OS.HIWORD (margins);
- if ((style & SWT.BORDER) != 0) {
- x -= 1;
- y -= 1;
- width += 2;
- height += 2;
- }
- width += OS.GetSystemMetrics (OS.SM_CXVSCROLL);
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void copy () {
- checkWidget ();
- OS.SendMessage (hwndText, OS.WM_COPY, 0, 0);
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void cut () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- OS.SendMessage (hwndText, OS.WM_CUT, 0, 0);
-}
-
-int defaultBackground () {
- return OS.GetSysColor (OS.COLOR_WINDOW);
-}
-
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- OS.EnableWindow (hwndText, enabled);
- OS.EnableWindow (hwndUpDown, enabled);
-}
-
-void deregister () {
- super.deregister ();
- display.removeControl (hwndText);
- display.removeControl (hwndUpDown);
-}
-
-boolean hasFocus () {
- int /*long*/ hwndFocus = OS.GetFocus ();
- if (hwndFocus == handle) return true;
- if (hwndFocus == hwndText) return true;
- if (hwndFocus == hwndUpDown) return true;
- return false;
-}
-
-/**
- * Returns the number of decimal places used by the receiver.
- *
- * @return the digits
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getDigits () {
- checkWidget ();
- return digits;
-}
-
-String getDecimalSeparator () {
- TCHAR tchar = new TCHAR (getCodePage (), 4);
- int size = OS.GetLocaleInfo (OS.LOCALE_USER_DEFAULT, OS.LOCALE_SDECIMAL, tchar, 4);
- return size != 0 ? tchar.toString (0, size - 1) : ".";
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down arrows are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget ();
- UDACCEL udaccel = new UDACCEL ();
- OS.SendMessage (hwndUpDown, OS.UDM_GETACCEL, 1, udaccel);
- return udaccel.nInc;
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget ();
- int [] max = new int [1];
- OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, null, max);
- return max [0];
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget ();
- int [] min = new int [1];
- OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, min, null);
- return min [0];
-}
-
-/**
- * Returns the amount that the receiver's position will be
- * modified by when the page up/down keys are pressed.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget ();
- return pageIncrement;
-}
-
-/**
- * Returns the <em>selection</em>, which is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget ();
- if (OS.IsWinCE) {
- return OS.LOWORD (OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0));
- } else {
- return (int)/*64*/OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0);
- }
-}
-
-int getSelectionText (boolean [] parseFail) {
- int length = OS.GetWindowTextLength (hwndText);
- TCHAR buffer = new TCHAR (getCodePage (), length + 1);
- OS.GetWindowText (hwndText, buffer, length + 1);
- String string = buffer.toString (0, length);
- try {
- int value;
- if (digits > 0) {
- String decimalSeparator = getDecimalSeparator ();
- int index = string.indexOf (decimalSeparator);
- if (index != -1) {
- int startIndex = string.startsWith ("+") || string.startsWith ("-") ? 1 : 0;
- String wholePart = startIndex != index ? string.substring (startIndex, index) : "0";
- String decimalPart = string.substring (index + 1);
- if (decimalPart.length () > digits) {
- decimalPart = decimalPart.substring (0, digits);
- } else {
- int i = digits - decimalPart.length ();
- for (int j = 0; j < i; j++) {
- decimalPart = decimalPart + "0";
- }
- }
- int wholeValue = Integer.parseInt (wholePart);
- int decimalValue = Integer.parseInt (decimalPart);
- for (int i = 0; i < digits; i++) wholeValue *= 10;
- value = wholeValue + decimalValue;
- if (string.startsWith ("-")) value = -value;
- } else {
- value = Integer.parseInt (string);
- for (int i = 0; i < digits; i++) value *= 10;
- }
- } else {
- value = Integer.parseInt (string);
- }
- int [] max = new int [1], min = new int [1];
- OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, min, max);
- if (min [0] <= value && value <= max [0]) return value;
- } catch (NumberFormatException e) {
- }
- parseFail [0] = true;
- return -1;
-}
-
-/**
- * Returns a string containing a copy of the contents of the
- * receiver's text field, or an empty string if there are no
- * contents.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public String getText () {
- checkWidget ();
- int length = OS.GetWindowTextLength (hwndText);
- if (length == 0) return "";
- TCHAR buffer = new TCHAR (getCodePage (), length + 1);
- OS.GetWindowText (hwndText, buffer, length + 1);
- return buffer.toString (0, length);
-}
-
-/**
- * Returns the maximum number of characters that the receiver's
- * text field is capable of holding. If this has not been changed
- * by <code>setTextLimit()</code>, it will be the constant
- * <code>Spinner.LIMIT</code>.
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- *
- * @since 3.4
- */
-public int getTextLimit () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (hwndText, OS.EM_GETLIMITTEXT, 0, 0) & 0x7FFFFFFF;
-}
-
-int mbcsToWcsPos (int mbcsPos) {
- if (mbcsPos <= 0) return 0;
- if (OS.IsUnicode) return mbcsPos;
- int mbcsSize = OS.GetWindowTextLengthA (hwndText);
- if (mbcsSize == 0) return 0;
- if (mbcsPos >= mbcsSize) return mbcsSize;
- byte [] buffer = new byte [mbcsSize + 1];
- OS.GetWindowTextA (hwndText, buffer, mbcsSize + 1);
- return OS.MultiByteToWideChar (getCodePage (), OS.MB_PRECOMPOSED, buffer, mbcsPos, null, 0);
-}
-
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void paste () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- OS.SendMessage (hwndText, OS.WM_PASTE, 0, 0);
-}
-
-void register () {
- super.register ();
- display.addControl (hwndText, this);
- display.addControl (hwndUpDown, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- hwndText = hwndUpDown = 0;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- */
-void removeVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-
-boolean sendKeyEvent (int type, int msg, int /*long*/ wParam, int /*long*/ lParam, Event event) {
- if (!super.sendKeyEvent (type, msg, wParam, lParam, event)) {
- return false;
- }
- if ((style & SWT.READ_ONLY) != 0) return true;
- if (type != SWT.KeyDown) return true;
- if (msg != OS.WM_CHAR && msg != OS.WM_KEYDOWN && msg != OS.WM_IME_CHAR) {
- return true;
- }
- if (event.character == 0) return true;
-// if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return true;
- char key = event.character;
- int stateMask = event.stateMask;
-
- /*
- * Disable all magic keys that could modify the text
- * and don't send events when Alt, Shift or Ctrl is
- * pressed.
- */
- switch (msg) {
- case OS.WM_CHAR:
- if (key != 0x08 && key != 0x7F && key != '\r' && key != '\t' && key != '\n') break;
- // FALL THROUGH
- case OS.WM_KEYDOWN:
- if ((stateMask & (SWT.ALT | SWT.SHIFT | SWT.CONTROL)) != 0) return false;
- break;
- }
-
- /*
- * If the left button is down, the text widget refuses the character.
- */
- if (OS.GetKeyState (OS.VK_LBUTTON) < 0) {
- return true;
- }
-
- /* Verify the character */
- String oldText = "";
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (hwndText, OS.EM_GETSEL, start, end);
- switch (key) {
- case 0x08: /* Bs */
- if (start [0] == end [0]) {
- if (start [0] == 0) return true;
- start [0] = start [0] - 1;
- if (!OS.IsUnicode && OS.IsDBLocale) {
- int [] newStart = new int [1], newEnd = new int [1];
- OS.SendMessage (hwndText, OS.EM_SETSEL, start [0], end [0]);
- OS.SendMessage (hwndText, OS.EM_GETSEL, newStart, newEnd);
- if (start [0] != newStart [0]) start [0] = start [0] - 1;
- }
- start [0] = Math.max (start [0], 0);
- }
- break;
- case 0x7F: /* Del */
- if (start [0] == end [0]) {
- int length = OS.GetWindowTextLength (hwndText);
- if (start [0] == length) return true;
- end [0] = end [0] + 1;
- if (!OS.IsUnicode && OS.IsDBLocale) {
- int [] newStart = new int [1], newEnd = new int [1];
- OS.SendMessage (hwndText, OS.EM_SETSEL, start [0], end [0]);
- OS.SendMessage (hwndText, OS.EM_GETSEL, newStart, newEnd);
- if (end [0] != newEnd [0]) end [0] = end [0] + 1;
- }
- end [0] = Math.min (end [0], length);
- }
- break;
- case '\r': /* Return */
- return true;
- default: /* Tab and other characters */
- if (key != '\t' && key < 0x20) return true;
- oldText = new String (new char [] {key});
- break;
- }
- String newText = verifyText (oldText, start [0], end [0], event);
- if (newText == null) return false;
- if (newText == oldText) return true;
- TCHAR buffer = new TCHAR (getCodePage (), newText, true);
- OS.SendMessage (hwndText, OS.EM_SETSEL, start [0], end [0]);
- OS.SendMessage (hwndText, OS.EM_REPLACESEL, 0, buffer);
- return false;
-}
-
-void setBackgroundImage (int /*long*/ hBitmap) {
- super.setBackgroundImage (hBitmap);
- OS.InvalidateRect (hwndText, null, true);
-}
-
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- OS.InvalidateRect (hwndText, null, true);
-}
-
-/**
- * Sets the number of decimal places used by the receiver.
- * <p>
- * The digit setting is used to allow for floating point values in the receiver.
- * For example, to set the selection to a floating point value of 1.37 call setDigits() with
- * a value of 2 and setSelection() with a value of 137. Similarly, if getDigits() has a value
- * of 2 and getSelection() returns 137 this should be interpreted as 1.37. This applies to all
- * numeric APIs.
- * </p>
- *
- * @param value the new digits (must be greater than or equal to zero)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the value is less than zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDigits (int value) {
- checkWidget ();
- if (value < 0) error (SWT.ERROR_INVALID_ARGUMENT);
- if (value == this.digits) return;
- this.digits = value;
- int pos;
- if (OS.IsWinCE) {
- pos = OS.LOWORD (OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0));
- } else {
- pos = (int)/*64*/OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0);
- }
- setSelection (pos, false, true, false);
-}
-
-void setForegroundPixel (int pixel) {
- super.setForegroundPixel (pixel);
- OS.InvalidateRect (hwndText, null, true);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down arrows are pressed to
- * the argument, which must be at least one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- int /*long*/ hHeap = OS.GetProcessHeap ();
- int count = (int)/*64*/OS.SendMessage (hwndUpDown, OS.UDM_GETACCEL, 0, (UDACCEL)null);
- int /*long*/ udaccels = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, UDACCEL.sizeof * count);
- OS.SendMessage (hwndUpDown, OS.UDM_GETACCEL, count, udaccels);
- int first = -1;
- UDACCEL udaccel = new UDACCEL ();
- for (int i = 0; i < count; i++) {
- int /*long*/ offset = udaccels + (i * UDACCEL.sizeof);
- OS.MoveMemory (udaccel, offset, UDACCEL.sizeof);
- if (first == -1) first = udaccel.nInc;
- udaccel.nInc = udaccel.nInc * value / first;
- OS.MoveMemory (offset, udaccel, UDACCEL.sizeof);
- }
- OS.SendMessage (hwndUpDown, OS.UDM_SETACCEL, count, udaccels);
- OS.HeapFree (hHeap, 0, udaccels);
-}
-
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget ();
- int [] min = new int [1];
- OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, min, null);
- if (value <= min [0]) return;
- int pos;
- if (OS.IsWinCE) {
- pos = OS.LOWORD (OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0));
- } else {
- pos = (int)/*64*/OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0);
- }
- OS.SendMessage (hwndUpDown , OS.UDM_SETRANGE32, min [0], value);
- if (pos > value) setSelection (value, true, true, false);
-}
-
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget ();
- int [] max = new int [1];
- OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, null, max);
- if (value >= max [0]) return;
- int pos;
- if (OS.IsWinCE) {
- pos = OS.LOWORD (OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0));
- } else {
- pos = (int)/*64*/OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0);
- }
- OS.SendMessage (hwndUpDown , OS.UDM_SETRANGE32, value, max [0]);
- if (pos < value) setSelection (value, true, true, false);
-}
-
-/**
- * Sets the amount that the receiver's position will be
- * modified by when the page up/down keys are pressed
- * to the argument, which must be at least one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- pageIncrement = value;
-}
-
-/**
- * Sets the <em>selection</em>, which is the receiver's
- * position, to the argument. If the argument is not within
- * the range specified by minimum and maximum, it will be
- * adjusted to fall within this range.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget ();
- int [] max = new int [1], min = new int [1];
- OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, min, max);
- value = Math.min (Math.max (min [0], value), max [0]);
- setSelection (value, true, true, false);
-}
-
-void setSelection (int value, boolean setPos, boolean setText, boolean notify) {
- if (setPos) {
- OS.SendMessage (hwndUpDown , OS.IsWinCE ? OS.UDM_SETPOS : OS.UDM_SETPOS32, 0, value);
- }
- if (setText) {
- String string;
- if (digits == 0) {
- string = String.valueOf (value);
- } else {
- string = String.valueOf (Math.abs (value));
- String decimalSeparator = getDecimalSeparator ();
- int index = string.length () - digits;
- StringBuffer buffer = new StringBuffer ();
- if (value < 0) buffer.append ("-");
- if (index > 0) {
- buffer.append (string.substring (0, index));
- buffer.append (decimalSeparator);
- buffer.append (string.substring (index));
- } else {
- buffer.append ("0");
- buffer.append (decimalSeparator);
- while (index++ < 0) buffer.append ("0");
- buffer.append (string);
- }
- string = buffer.toString ();
- }
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- int length = OS.GetWindowTextLength (hwndText);
- string = verifyText (string, 0, length, null);
- if (string == null) return;
- }
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- OS.SetWindowText (hwndText, buffer);
- OS.SendMessage (hwndText, OS.EM_SETSEL, 0, -1);
- if (!OS.IsWinCE) {
- OS.NotifyWinEvent (OS.EVENT_OBJECT_FOCUS, hwndText, OS.OBJID_CLIENT, 0);
- }
- }
- if (notify) postEvent (SWT.Selection);
-}
-
-/**
- * Sets the maximum number of characters that the receiver's
- * text field is capable of holding to be the argument.
- * <p>
- * To reset this value to the default, use <code>setTextLimit(Spinner.LIMIT)</code>.
- * Specifying a limit value larger than <code>Spinner.LIMIT</code> sets the
- * receiver's limit to <code>Spinner.LIMIT</code>.
- * </p>
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- *
- * @since 3.4
- */
-public void setTextLimit (int limit) {
- checkWidget ();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- OS.SendMessage (hwndText, OS.EM_SETLIMITTEXT, limit, 0);
-}
-
-void setToolTipText (Shell shell, String string) {
- shell.setToolTipText (hwndText, string);
- shell.setToolTipText (hwndUpDown, string);
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, digits, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param digits the new digits value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setValues (int selection, int minimum, int maximum, int digits, int increment, int pageIncrement) {
- checkWidget ();
- if (maximum <= minimum) return;
- if (digits < 0) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- selection = Math.min (Math.max (minimum, selection), maximum);
- setIncrement (increment);
- this.pageIncrement = pageIncrement;
- this.digits = digits;
- OS.SendMessage (hwndUpDown , OS.UDM_SETRANGE32, minimum, maximum);
- setSelection (selection, true, true, false);
-}
-
-void subclass () {
- super.subclass ();
- int /*long*/ newProc = display.windowProc;
- OS.SetWindowLongPtr (hwndText, OS.GWLP_WNDPROC, newProc);
- OS.SetWindowLongPtr (hwndUpDown, OS.GWLP_WNDPROC, newProc);
-}
-
-void unsubclass () {
- super.unsubclass ();
- OS.SetWindowLongPtr (hwndText, OS.GWLP_WNDPROC, EditProc);
- OS.SetWindowLongPtr (hwndUpDown, OS.GWLP_WNDPROC, UpDownProc);
-}
-
-String verifyText (String string, int start, int end, Event keyEvent) {
- Event event = new Event ();
- event.text = string;
- event.start = start;
- event.end = end;
- if (keyEvent != null) {
- event.character = keyEvent.character;
- event.keyCode = keyEvent.keyCode;
- event.stateMask = keyEvent.stateMask;
- }
- int index = 0;
- if (digits > 0) {
- String decimalSeparator = getDecimalSeparator ();
- index = string.indexOf (decimalSeparator);
- if (index != -1) {
- string = string.substring (0, index) + string.substring (index + 1);
- }
- index = 0;
- }
- if (string.length() > 0) {
- int [] min = new int [1];
- OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, min, null);
- if (min [0] < 0 && string.charAt (0) == '-') index++;
- }
- while (index < string.length ()) {
- if (!Character.isDigit (string.charAt (index))) break;
- index++;
- }
- event.doit = index == string.length ();
- if (!OS.IsUnicode && OS.IsDBLocale) {
- event.start = mbcsToWcsPos (start);
- event.end = mbcsToWcsPos (end);
- }
- sendEvent (SWT.Verify, event);
- if (!event.doit || isDisposed ()) return null;
- return event.text;
-}
-
-int widgetExtStyle () {
- return super.widgetExtStyle () & ~OS.WS_EX_CLIENTEDGE;
-}
-
-int /*long*/ windowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (hwnd == hwndText || hwnd == hwndUpDown) {
- LRESULT result = null;
- switch (msg) {
- /* Keyboard messages */
- case OS.WM_CHAR: result = wmChar (hwnd, wParam, lParam); break;
- case OS.WM_IME_CHAR: result = wmIMEChar (hwnd, wParam, lParam); break;
- case OS.WM_KEYDOWN: result = wmKeyDown (hwnd, wParam, lParam); break;
- case OS.WM_KEYUP: result = wmKeyUp (hwnd, wParam, lParam); break;
- case OS.WM_SYSCHAR: result = wmSysChar (hwnd, wParam, lParam); break;
- case OS.WM_SYSKEYDOWN: result = wmSysKeyDown (hwnd, wParam, lParam); break;
- case OS.WM_SYSKEYUP: result = wmSysKeyUp (hwnd, wParam, lParam); break;
-
- /* Mouse Messages */
- case OS.WM_CAPTURECHANGED: result = wmCaptureChanged (hwnd, wParam, lParam); break;
- case OS.WM_LBUTTONDBLCLK: result = wmLButtonDblClk (hwnd, wParam, lParam); break;
- case OS.WM_LBUTTONDOWN: result = wmLButtonDown (hwnd, wParam, lParam); break;
- case OS.WM_LBUTTONUP: result = wmLButtonUp (hwnd, wParam, lParam); break;
- case OS.WM_MBUTTONDBLCLK: result = wmMButtonDblClk (hwnd, wParam, lParam); break;
- case OS.WM_MBUTTONDOWN: result = wmMButtonDown (hwnd, wParam, lParam); break;
- case OS.WM_MBUTTONUP: result = wmMButtonUp (hwnd, wParam, lParam); break;
- case OS.WM_MOUSEHOVER: result = wmMouseHover (hwnd, wParam, lParam); break;
- case OS.WM_MOUSELEAVE: result = wmMouseLeave (hwnd, wParam, lParam); break;
- case OS.WM_MOUSEMOVE: result = wmMouseMove (hwnd, wParam, lParam); break;
-// case OS.WM_MOUSEWHEEL: result = wmMouseWheel (hwnd, wParam, lParam); break;
- case OS.WM_RBUTTONDBLCLK: result = wmRButtonDblClk (hwnd, wParam, lParam); break;
- case OS.WM_RBUTTONDOWN: result = wmRButtonDown (hwnd, wParam, lParam); break;
- case OS.WM_RBUTTONUP: result = wmRButtonUp (hwnd, wParam, lParam); break;
- case OS.WM_XBUTTONDBLCLK: result = wmXButtonDblClk (hwnd, wParam, lParam); break;
- case OS.WM_XBUTTONDOWN: result = wmXButtonDown (hwnd, wParam, lParam); break;
- case OS.WM_XBUTTONUP: result = wmXButtonUp (hwnd, wParam, lParam); break;
-
- /* Focus Messages */
- case OS.WM_SETFOCUS: result = wmSetFocus (hwnd, wParam, lParam); break;
- case OS.WM_KILLFOCUS: result = wmKillFocus (hwnd, wParam, lParam); break;
-
- /* Paint messages */
- case OS.WM_PAINT: result = wmPaint (hwnd, wParam, lParam); break;
- case OS.WM_PRINT: result = wmPrint (hwnd, wParam, lParam); break;
-
- /* Menu messages */
- case OS.WM_CONTEXTMENU: result = wmContextMenu (hwnd, wParam, lParam); break;
-
- /* Clipboard messages */
- case OS.WM_CLEAR:
- case OS.WM_CUT:
- case OS.WM_PASTE:
- case OS.WM_UNDO:
- case OS.EM_UNDO:
- if (hwnd == hwndText) {
- result = wmClipboard (hwnd, msg, wParam, lParam);
- }
- break;
- }
- if (result != null) return result.value;
- return callWindowProc (hwnd, msg, wParam, lParam);
- }
- return super.windowProc (hwnd, msg, wParam, lParam);
-}
-
-LRESULT WM_ERASEBKGND (int /*long*/ wParam, int /*long*/ lParam) {
- super.WM_ERASEBKGND (wParam, lParam);
- drawBackground (wParam);
- return LRESULT.ONE;
-}
-
-LRESULT WM_KILLFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT WM_SETFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- OS.SetFocus (hwndText);
- OS.SendMessage (hwndText, OS.EM_SETSEL, 0, -1);
- return null;
-}
-
-LRESULT WM_SETFONT (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SETFONT (wParam, lParam);
- if (result != null) return result;
- OS.SendMessage (hwndText, OS.WM_SETFONT, wParam, lParam);
- return result;
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SIZE (wParam, lParam);
- if (isDisposed ()) return result;
- int width = OS.LOWORD (lParam), height = OS.HIWORD (lParam);
- int upDownWidth = OS.GetSystemMetrics (OS.SM_CXVSCROLL);
- int textWidth = width - upDownWidth;
- int border = OS.GetSystemMetrics (OS.SM_CXEDGE);
- int flags = OS.SWP_NOZORDER | OS.SWP_DRAWFRAME | OS.SWP_NOACTIVATE;
- SetWindowPos (hwndText, 0, 0, 0, textWidth + border, height, flags);
- SetWindowPos (hwndUpDown, 0, textWidth, 0, upDownWidth, height, flags);
- return result;
-}
-
-LRESULT wmChar (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.wmChar (hwnd, wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. For some reason, when the
- * widget is a single line text widget, when the
- * user presses tab, return or escape, Windows beeps.
- * The fix is to look for these keys and not call
- * the window proc.
- */
- switch ((int)/*64*/wParam) {
- case SWT.CR:
- postEvent (SWT.DefaultSelection);
- // FALL THROUGH
- case SWT.TAB:
- case SWT.ESC: return LRESULT.ZERO;
- }
- return result;
-}
-
-LRESULT wmClipboard (int /*long*/ hwndText, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if ((style & SWT.READ_ONLY) != 0) return null;
-// if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return null;
- boolean call = false;
- int [] start = new int [1], end = new int [1];
- String newText = null;
- switch (msg) {
- case OS.WM_CLEAR:
- case OS.WM_CUT:
- OS.SendMessage (hwndText, OS.EM_GETSEL, start, end);
- if (start [0] != end [0]) {
- newText = "";
- call = true;
- }
- break;
- case OS.WM_PASTE:
- OS.SendMessage (hwndText, OS.EM_GETSEL, start, end);
- newText = getClipboardText ();
- break;
- case OS.EM_UNDO:
- case OS.WM_UNDO:
- if (OS.SendMessage (hwndText, OS.EM_CANUNDO, 0, 0) != 0) {
- ignoreModify = true;
- OS.CallWindowProc (EditProc, hwndText, msg, wParam, lParam);
- int length = OS.GetWindowTextLength (hwndText);
- int [] newStart = new int [1], newEnd = new int [1];
- OS.SendMessage (hwndText, OS.EM_GETSEL, newStart, newEnd);
- if (length != 0 && newStart [0] != newEnd [0]) {
- TCHAR buffer = new TCHAR (getCodePage (), length + 1);
- OS.GetWindowText (hwndText, buffer, length + 1);
- newText = buffer.toString (newStart [0], newEnd [0] - newStart [0]);
- } else {
- newText = "";
- }
- OS.CallWindowProc (EditProc, hwndText, msg, wParam, lParam);
- OS.SendMessage (hwndText, OS.EM_GETSEL, start, end);
- ignoreModify = false;
- }
- break;
- }
- if (newText != null) {
- String oldText = newText;
- newText = verifyText (newText, start [0], end [0], null);
- if (newText == null) return LRESULT.ZERO;
- if (!newText.equals (oldText)) {
- if (call) {
- OS.CallWindowProc (EditProc, hwndText, msg, wParam, lParam);
- }
- TCHAR buffer = new TCHAR (getCodePage (), newText, true);
- if (msg == OS.WM_SETTEXT) {
- int /*long*/ hHeap = OS.GetProcessHeap ();
- int byteCount = buffer.length () * TCHAR.sizeof;
- int /*long*/ pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (pszText, buffer, byteCount);
- int /*long*/ code = OS.CallWindowProc (EditProc, hwndText, msg, wParam, pszText);
- OS.HeapFree (hHeap, 0, pszText);
- return new LRESULT (code);
- } else {
- OS.SendMessage (hwndText, OS.EM_REPLACESEL, 0, buffer);
- return LRESULT.ZERO;
- }
- }
- }
- return null;
-}
-
-LRESULT wmCommandChild (int /*long*/ wParam, int /*long*/ lParam) {
- int code = OS.HIWORD (wParam);
- switch (code) {
- case OS.EN_CHANGE:
- if (ignoreModify) break;
- boolean [] parseFail = new boolean [1];
- int value = getSelectionText (parseFail);
- if (!parseFail [0]) {
- int pos;
- if (OS.IsWinCE) {
- pos = OS.LOWORD (OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0));
- } else {
- pos = (int)/*64*/OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0);
- }
- if (pos != value) setSelection (value, true, false, true);
- }
- sendEvent (SWT.Modify);
- if (isDisposed ()) return LRESULT.ZERO;
- break;
- }
- return super.wmCommandChild (wParam, lParam);
-}
-
-LRESULT wmKeyDown (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.wmKeyDown (hwnd, wParam, lParam);
- if (result != null) return result;
-
- /* Increment the value */
- UDACCEL udaccel = new UDACCEL ();
- OS.SendMessage (hwndUpDown, OS.UDM_GETACCEL, 1, udaccel);
- int delta = 0;
- switch ((int)/*64*/wParam) {
- case OS.VK_UP: delta = udaccel.nInc; break;
- case OS.VK_DOWN: delta = -udaccel.nInc; break;
- case OS.VK_PRIOR: delta = pageIncrement; break;
- case OS.VK_NEXT: delta = -pageIncrement; break;
- }
- if (delta != 0) {
- boolean [] parseFail = new boolean [1];
- int value = getSelectionText (parseFail);
- if (parseFail [0]) {
- if (OS.IsWinCE) {
- value = OS.LOWORD (OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0));
- } else {
- value = (int)/*64*/OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0);
- }
- }
- int newValue = value + delta;
- int [] max = new int [1], min = new int [1];
- OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, min, max);
- if ((style & SWT.WRAP) != 0) {
- if (newValue < min [0]) newValue = max [0];
- if (newValue > max [0]) newValue = min [0];
- }
- newValue = Math.min (Math.max (min [0], newValue), max [0]);
- if (value != newValue) setSelection (newValue, true, true, true);
- }
-
- /* Stop the edit control from moving the caret */
- switch ((int)/*64*/wParam) {
- case OS.VK_UP:
- case OS.VK_DOWN:
- return LRESULT.ZERO;
- }
- return result;
-}
-
-LRESULT wmKillFocus (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- boolean [] parseFail = new boolean [1];
- int value = getSelectionText (parseFail);
- if (parseFail [0]) {
- if (OS.IsWinCE) {
- value = OS.LOWORD (OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0));
- } else {
- value = (int)/*64*/OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0);
- }
- setSelection (value, false, true, false);
- }
- return super.wmKillFocus (hwnd, wParam, lParam);
-}
-
-LRESULT wmNotifyChild (NMHDR hdr, int /*long*/ wParam, int /*long*/ lParam) {
- switch (hdr.code) {
- case OS.UDN_DELTAPOS:
- NMUPDOWN lpnmud = new NMUPDOWN ();
- OS.MoveMemory (lpnmud, lParam, NMUPDOWN.sizeof);
- int value = lpnmud.iPos + lpnmud.iDelta;
- int [] max = new int [1], min = new int [1];
- OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, min, max);
- if ((style & SWT.WRAP) != 0) {
- if (value < min [0]) value = max [0];
- if (value > max [0]) value = min [0];
- }
- /*
- * The SWT.Modify event is sent after the widget has been
- * updated with the new state. Rather than allowing
- * the default updown window proc to set the value
- * when the user clicks on the updown control, set
- * the value explicitly and stop the window proc
- * from running.
- */
- value = Math.min (Math.max (min [0], value), max [0]);
- if (value != lpnmud.iPos) {
- setSelection (value, true, true, true);
- }
- return LRESULT.ONE;
- }
- return super.wmNotifyChild (hdr, wParam, lParam);
-}
-
-LRESULT wmScrollChild (int /*long*/ wParam, int /*long*/ lParam) {
- int code = OS.LOWORD (wParam);
- switch (code) {
- case OS.SB_THUMBPOSITION:
- postEvent (SWT.Selection);
- break;
- }
- return super.wmScrollChild (wParam, lParam);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabFolder.java
deleted file mode 100755
index 0583d9c5d4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabFolder.java
+++ /dev/null
@@ -1,1010 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class implement the notebook user interface
- * metaphor. It allows the user to select a notebook page from
- * set of pages.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TabItem</code>.
- * <code>Control</code> children are created and then set into a
- * tab item using <code>TabItem#setControl</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>TOP, BOTTOM</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles TOP and BOTTOM may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tabfolder">TabFolder, TabItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TabFolder extends Composite {
- TabItem [] items;
- ImageList imageList;
- static final int /*long*/ TabFolderProc;
- static final TCHAR TabFolderClass = new TCHAR (0, OS.WC_TABCONTROL, true);
-
- /*
- * These are the undocumented control id's for the children of
- * a tab control. Since there are no constants for these values,
- * they may change with different versions of Windows.
- */
- static final int ID_UPDOWN = 1;
-
- static {
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, TabFolderClass, lpWndClass);
- TabFolderProc = lpWndClass.lpfnWndProc;
- /*
- * Feature in Windows. The tab control window class
- * uses the CS_HREDRAW and CS_VREDRAW style bits to
- * force a full redraw of the control and all children
- * when resized. This causes flashing. The fix is to
- * register a new window class without these bits and
- * implement special code that damages only the exposed
- * area.
- *
- * NOTE: Screen readers look for the exact class name
- * of the control in order to provide the correct kind
- * of assistance. Therefore, it is critical that the
- * new window class have the same name. It is possible
- * to register a local window class with the same name
- * as a global class. Since bits that affect the class
- * are being changed, it is possible that other native
- * code, other than SWT, could create a control with
- * this class name, and fail unexpectedly.
- */
- int /*long*/ hInstance = OS.GetModuleHandle (null);
- int /*long*/ hHeap = OS.GetProcessHeap ();
- lpWndClass.hInstance = hInstance;
- lpWndClass.style &= ~(OS.CS_HREDRAW | OS.CS_VREDRAW | OS.CS_GLOBALCLASS);
- int byteCount = TabFolderClass.length () * TCHAR.sizeof;
- int /*long*/ lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (lpszClassName, TabFolderClass, byteCount);
- lpWndClass.lpszClassName = lpszClassName;
- OS.RegisterClass (lpWndClass);
- OS.HeapFree (hHeap, 0, lpszClassName);
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see SWT#TOP
- * @see SWT#BOTTOM
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabFolder (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (TabFolderProc, hwnd, msg, wParam, lParam);
-}
-
-static int checkStyle (int style) {
- /*
- * When the SWT.TOP style has not been set, force the
- * tabs to be on the bottom for tab folders on PPC.
- */
- if (OS.IsPPC) {
- if ((style & SWT.TOP) == 0) style |= SWT.BOTTOM;
- }
- style = checkBits (style, SWT.TOP, SWT.BOTTOM, 0, 0, 0, 0);
-
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- Point size = super.computeSize (wHint, hHint, changed);
- RECT insetRect = new RECT (), itemRect = new RECT ();
- OS.SendMessage (handle, OS.TCM_ADJUSTRECT, 0, insetRect);
- int width = insetRect.left - insetRect.right;
- int count = (int)/*64*/OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);
- if (count != 0) {
- OS.SendMessage (handle, OS.TCM_GETITEMRECT, count - 1, itemRect);
- width = Math.max (width, itemRect.right - insetRect.right);
- }
- RECT rect = new RECT ();
- OS.SetRect (rect, 0, 0, width, size.y);
- OS.SendMessage (handle, OS.TCM_ADJUSTRECT, 1, rect);
- int border = getBorderWidth ();
- rect.left -= border; rect.right += border;
- width = rect.right - rect.left;
- size.x = Math.max (width, size.x);
- return size;
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
- RECT rect = new RECT ();
- OS.SetRect (rect, x, y, x + width, y + height);
- OS.SendMessage (handle, OS.TCM_ADJUSTRECT, 1, rect);
- int border = getBorderWidth ();
- rect.left -= border; rect.right += border;
- rect.top -= border; rect.bottom += border;
- int newWidth = rect.right - rect.left;
- int newHeight = rect.bottom - rect.top;
- return new Rectangle (rect.left, rect.top, newWidth, newHeight);
-}
-
-void createItem (TabItem item, int index) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);
- if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
- if (count == items.length) {
- TabItem [] newItems = new TabItem [items.length + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- TCITEM tcItem = new TCITEM ();
- if (OS.SendMessage (handle, OS.TCM_INSERTITEM, index, tcItem) == -1) {
- error (SWT.ERROR_ITEM_NOT_ADDED);
- }
- System.arraycopy (items, index, items, index + 1, count - index);
- items [index] = item;
-
- /*
- * Send a selection event when the item that is added becomes
- * the new selection. This only happens when the first item
- * is added.
- */
- if (count == 0) {
- Event event = new Event ();
- event.item = items [0];
- sendEvent (SWT.Selection, event);
- // the widget could be destroyed at this point
- }
-}
-
-void createHandle () {
- super.createHandle ();
- state &= ~(CANVAS | THEME_BACKGROUND);
-
- /* Enable the flat look for tab folders on PPC */
- if (OS.IsPPC) {
- OS.SendMessage (handle, OS.CCM_SETVERSION, 0x020c /*COMCTL32_VERSION*/, 0);
- }
-
- /*
- * Feature in Windows. Despite the fact that the
- * tool tip text contains \r\n, the tooltip will
- * not honour the new line unless TTM_SETMAXTIPWIDTH
- * is set. The fix is to set TTM_SETMAXTIPWIDTH to
- * a large value.
- */
- int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.TCM_GETTOOLTIPS, 0, 0);
- OS.SendMessage (hwndToolTip, OS.TTM_SETMAXTIPWIDTH, 0, 0x7FFF);
-}
-
-void createWidget () {
- super.createWidget ();
- items = new TabItem [4];
-}
-
-void destroyItem (TabItem item) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);
- int index = 0;
- while (index < count) {
- if (items [index] == item) break;
- index++;
- }
- if (index == count) return;
- int selectionIndex = (int)/*64*/OS.SendMessage (handle, OS.TCM_GETCURSEL, 0, 0);
- if (OS.SendMessage (handle, OS.TCM_DELETEITEM, index, 0) == 0) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- System.arraycopy (items, index + 1, items, index, --count - index);
- items [count] = null;
- if (count == 0) {
- if (imageList != null) {
- OS.SendMessage (handle, OS.TCM_SETIMAGELIST, 0, 0);
- display.releaseImageList (imageList);
- }
- imageList = null;
- items = new TabItem [4];
- }
- if (count > 0 && index == selectionIndex) {
- setSelection (Math.max (0, selectionIndex - 1), true);
- }
-}
-
-void drawThemeBackground (int /*long*/ hDC, int /*long*/ hwnd, RECT rect) {
- RECT rect2 = new RECT ();
- OS.GetClientRect (handle, rect2);
- OS.MapWindowPoints (handle, hwnd, rect2, 2);
- if (OS.IntersectRect (new RECT (), rect2, rect)) {
- OS.DrawThemeBackground (display.hTabTheme (), hDC, OS.TABP_BODY, 0, rect2, null);
- }
-}
-
-Control findThemeControl () {
- /* It is not possible to change the background of this control */
- return this;
-}
-
-public Rectangle getClientArea () {
- checkWidget ();
- forceResize ();
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- OS.SendMessage (handle, OS.TCM_ADJUSTRECT, 0, rect);
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- return new Rectangle (rect.left, rect.top, width, height);
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem getItem (int index) {
- checkWidget ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);
- if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-
-/**
- * Returns the tab item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- *
- * @param point the point used to locate the item
- * @return the tab item at the given point, or null if the point is not in a tab item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public TabItem getItem (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- TCHITTESTINFO pinfo = new TCHITTESTINFO ();
- pinfo.x = point.x;
- pinfo.y = point.y;
- int index = (int)/*64*/OS.SendMessage (handle, OS.TCM_HITTEST, 0, pinfo);
- if (index == -1) return null;
- return items [index];
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);
-}
-
-/**
- * Returns an array of <code>TabItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem [] getItems () {
- checkWidget ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);
- TabItem [] result = new TabItem [count];
- System.arraycopy (items, 0, result, 0, count);
- return result;
-}
-
-/**
- * Returns an array of <code>TabItem</code>s that are currently
- * selected in the receiver. An empty array indicates that no
- * items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem [] getSelection () {
- checkWidget ();
- int index = (int)/*64*/OS.SendMessage (handle, OS.TCM_GETCURSEL, 0, 0);
- if (index == -1) return new TabItem [0];
- return new TabItem [] {items [index]};
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.TCM_GETCURSEL, 0, 0);
-}
-
-int imageIndex (Image image) {
- if (image == null) return OS.I_IMAGENONE;
- if (imageList == null) {
- Rectangle bounds = image.getBounds ();
- imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height);
- int index = imageList.add (image);
- int /*long*/ hImageList = imageList.getHandle ();
- OS.SendMessage (handle, OS.TCM_SETIMAGELIST, 0, hImageList);
- return index;
- }
- int index = imageList.indexOf (image);
- if (index == -1) {
- index = imageList.add (image);
- } else {
- imageList.put (index, image);
- }
- return index;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (TabItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = (int)/*64*/OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<count; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-
-Point minimumSize (int wHint, int hHint, boolean flushCache) {
- Control [] children = _getChildren ();
- int width = 0, height = 0;
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- int index = 0;
- int count = (int)/*64*/OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);
- while (index < count) {
- if (items [index].control == child) break;
- index++;
- }
- if (index == count) {
- Rectangle rect = child.getBounds ();
- width = Math.max (width, rect.x + rect.width);
- height = Math.max (height, rect.y + rect.height);
- } else {
- Point size = child.computeSize (wHint, hHint, flushCache);
- width = Math.max (width, size.x);
- height = Math.max (height, size.y);
- }
- }
- return new Point (width, height);
-}
-
-boolean mnemonicHit (char key) {
- for (int i=0; i<items.length; i++) {
- TabItem item = items [i];
- if (item != null) {
- char ch = findMnemonic (item.getText ());
- if (Character.toUpperCase (key) == Character.toUpperCase (ch)) {
- if (forceFocus ()) {
- if (i != getSelectionIndex ()) setSelection (i, true);
- return true;
- }
- }
- }
- }
- return false;
-}
-
-boolean mnemonicMatch (char key) {
- for (int i=0; i<items.length; i++) {
- TabItem item = items [i];
- if (item != null) {
- char ch = findMnemonic (item.getText ());
- if (Character.toUpperCase (key) == Character.toUpperCase (ch)) {
- return true;
- }
- }
- }
- return false;
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<count; i++) {
- TabItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (imageList != null) {
- OS.SendMessage (handle, OS.TCM_SETIMAGELIST, 0, 0);
- display.releaseImageList (imageList);
- }
- imageList = null;
-}
-
-void removeControl (Control control) {
- super.removeControl (control);
- int count = (int)/*64*/OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<count; i++) {
- TabItem item = items [i];
- if (item.control == control) item.setControl (null);
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Sets the receiver's selection to the given item.
- * The current selected is first cleared, then the new item is
- * selected.
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection (TabItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (new TabItem [] {item});
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selected is first cleared, then the new items are
- * selected.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (TabItem [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (items.length == 0) {
- setSelection (-1, false);
- } else {
- for (int i=items.length-1; i>=0; --i) {
- int index = indexOf (items [i]);
- if (index != -1) setSelection (index, false);
- }
- }
-}
-
-public void setFont (Font font) {
- checkWidget ();
- Rectangle oldRect = getClientArea ();
- super.setFont (font);
- Rectangle newRect = getClientArea ();
- if (!oldRect.equals (newRect)) {
- sendResize ();
- int index = (int)/*64*/OS.SendMessage (handle, OS.TCM_GETCURSEL, 0, 0);
- if (index != -1) {
- TabItem item = items [index];
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setBounds (getClientArea ());
- }
- }
- }
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains selected.
- * The current selection is first cleared, then the new items are
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int index) {
- checkWidget ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);
- if (!(0 <= index && index < count)) return;
- setSelection (index, false);
-}
-
-void setSelection (int index, boolean notify) {
- int oldIndex = (int)/*64*/OS.SendMessage (handle, OS.TCM_GETCURSEL, 0, 0);
- if (oldIndex == index) return;
- if (oldIndex != -1) {
- TabItem item = items [oldIndex];
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setVisible (false);
- }
- }
- OS.SendMessage (handle, OS.TCM_SETCURSEL, index, 0);
- int newIndex = (int)/*64*/OS.SendMessage (handle, OS.TCM_GETCURSEL, 0, 0);
- if (newIndex != -1) {
- TabItem item = items [newIndex];
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setBounds (getClientArea ());
- control.setVisible (true);
- }
- if (notify) {
- Event event = new Event ();
- event.item = item;
- sendEvent (SWT.Selection, event);
- }
- }
-}
-
-String toolTipText (NMTTDISPINFO hdr) {
- if ((hdr.uFlags & OS.TTF_IDISHWND) != 0) {
- return null;
- }
- int index = (int)/*64*/hdr.idFrom;
- int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.TCM_GETTOOLTIPS, 0, 0);
- if (hwndToolTip == hdr.hwndFrom) {
- /*
- * Bug in Windows. For some reason the reading order
- * in NMTTDISPINFO is sometimes set incorrectly. The
- * reading order seems to change every time the mouse
- * enters the control from the top edge. The fix is
- * to explicitly set TTF_RTLREADING.
- */
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- hdr.uFlags |= OS.TTF_RTLREADING;
- } else {
- hdr.uFlags &= ~OS.TTF_RTLREADING;
- }
- if (toolTipText != null) return "";
- if (0 <= index && index < items.length) {
- TabItem item = items [index];
- if (item != null) return item.toolTipText;
- }
- }
- return super.toolTipText (hdr);
-}
-
-boolean traversePage (boolean next) {
- int count = getItemCount ();
- if (count <= 1) return false;
- int index = getSelectionIndex ();
- if (index == -1) {
- index = 0;
- } else {
- int offset = (next) ? 1 : -1;
- index = (index + offset + count) % count;
- }
- setSelection (index, true);
- if (index == getSelectionIndex ()) {
- OS.SendMessage (handle, OS.WM_CHANGEUISTATE, OS.UIS_INITIALIZE, 0);
- return true;
- }
- return false;
-}
-
-int widgetStyle () {
- /*
- * Bug in Windows. Under certain circumstances,
- * when TCM_SETITEM is used to change the text
- * in a tab item, the tab folder draws on top
- * of the client area. The fix is ensure that
- * this cannot happen by setting WS_CLIPCHILDREN.
- */
- int bits = super.widgetStyle () | OS.WS_CLIPCHILDREN;
- if ((style & SWT.NO_FOCUS) != 0) bits |= OS.TCS_FOCUSNEVER;
- if ((style & SWT.BOTTOM) != 0) bits |= OS.TCS_BOTTOM;
- return bits | OS.TCS_TABS | OS.TCS_TOOLTIPS;
-}
-
-TCHAR windowClass () {
- return TabFolderClass;
-}
-
-int /*long*/ windowProc () {
- return TabFolderProc;
-}
-
-LRESULT WM_GETDLGCODE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_GETDLGCODE (wParam, lParam);
- /*
- * Return DLGC_BUTTON so that mnemonics will be
- * processed without needing to press the ALT key
- * when the widget has focus.
- */
- if (result != null) return result;
- return new LRESULT (OS.DLGC_BUTTON | OS.DLGC_WANTARROWS);
-}
-
-LRESULT WM_MOUSELEAVE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_MOUSELEAVE (wParam, lParam);
- if (result != null) return result;
- /*
- * Bug in Windows. On XP, when a tooltip is
- * hidden due to a time out or mouse press,
- * the tooltip remains active although no
- * longer visible and won't show again until
- * another tooltip becomes active. If there
- * is only one tooltip in the window, it will
- * never show again. The fix is to remove the
- * current tooltip and add it again every time
- * the mouse leaves the control.
- */
- if (OS.COMCTL32_MAJOR >= 6) {
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.TCM_GETTOOLTIPS, 0, 0);
- if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, lpti) != 0) {
- if ((lpti.uFlags & OS.TTF_IDISHWND) == 0) {
- OS.SendMessage (hwndToolTip, OS.TTM_DELTOOL, 0, lpti);
- OS.SendMessage (hwndToolTip, OS.TTM_ADDTOOL, 0, lpti);
- }
- }
- }
- return result;
-}
-
-LRESULT WM_NCHITTEST (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_NCHITTEST (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. The tab control implements
- * WM_NCHITTEST to return HTCLIENT when the cursor
- * is inside the tab buttons. This causes mouse
- * events like WM_MOUSEMOVE to be delivered to the
- * parent. Also, tool tips for the tab control are
- * never invoked because tool tips rely on mouse
- * events to be delivered to the window that wants
- * to display the tool tip. The fix is to call the
- * default window proc that returns HTCLIENT when
- * the mouse is in the client area.
- */
- int /*long*/ hittest = OS.DefWindowProc (handle, OS.WM_NCHITTEST, wParam, lParam);
- return new LRESULT (hittest);
-}
-
-LRESULT WM_NOTIFY (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. When the tab folder window
- * proc processes WM_NOTIFY, it forwards this
- * message to its parent. This is done so that
- * children of this control that send this message
- * type to their parent will notify not only
- * this control but also the parent of this control,
- * which is typically the application window and
- * the window that is looking for the message.
- * If the control did not forward the message,
- * applications would have to subclass the control
- * window to see the message. Because the control
- * window is subclassed by SWT, the message
- * is delivered twice, once by SWT and once when
- * the message is forwarded by the window proc.
- * The fix is to avoid calling the window proc
- * for this control.
- */
- LRESULT result = super.WM_NOTIFY (wParam, lParam);
- if (result != null) return result;
- return LRESULT.ZERO;
-}
-
-LRESULT WM_PARENTNOTIFY (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_PARENTNOTIFY (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. Windows does not explicitly set the orientation of
- * the buddy control. Instead, the orientation is inherited when WS_EX_LAYOUTRTL
- * is specified for the tab folder. This means that when both WS_EX_LAYOUTRTL
- * and WS_EX_NOINHERITLAYOUT are specified for the tab folder, the buddy control
- * will not be oriented correctly. The fix is to explicitly set the orientation
- * for the buddy control.
- *
- * NOTE: WS_EX_LAYOUTRTL is not supported on Windows NT.
- */
- if (OS.WIN32_VERSION < OS.VERSION (4, 10)) return result;
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- int code = OS.LOWORD (wParam);
- switch (code) {
- case OS.WM_CREATE: {
- int id = OS.HIWORD (wParam);
- int /*long*/ hwnd = lParam;
- if (id == ID_UPDOWN) {
- int bits = OS.GetWindowLong (hwnd, OS.GWL_EXSTYLE);
- OS.SetWindowLong (hwnd, OS.GWL_EXSTYLE, bits | OS.WS_EX_LAYOUTRTL);
- }
- break;
- }
- }
- }
- return result;
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SIZE (wParam, lParam);
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the resize
- * event. If this happens, end the processing of the
- * Windows message by returning the result of the
- * WM_SIZE message.
- */
- if (isDisposed ()) return result;
- int index = (int)/*64*/OS.SendMessage (handle, OS.TCM_GETCURSEL, 0, 0);
- if (index != -1) {
- TabItem item = items [index];
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setBounds (getClientArea ());
- }
- }
- return result;
-}
-
-LRESULT WM_WINDOWPOSCHANGING (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_WINDOWPOSCHANGING (wParam, lParam);
- if (result != null) return result;
- if (!OS.IsWindowVisible (handle)) return result;
- WINDOWPOS lpwp = new WINDOWPOS ();
- OS.MoveMemory (lpwp, lParam, WINDOWPOS.sizeof);
- if ((lpwp.flags & (OS.SWP_NOSIZE | OS.SWP_NOREDRAW)) != 0) {
- return result;
- }
- // TEMPORARY CODE
-// if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
-// OS.InvalidateRect (handle, null, true);
-// return result;
-// }
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.TCS_MULTILINE) != 0) {
- OS.InvalidateRect (handle, null, true);
- return result;
- }
- RECT rect = new RECT ();
- OS.SetRect (rect, 0, 0, lpwp.cx, lpwp.cy);
- OS.SendMessage (handle, OS.WM_NCCALCSIZE, 0, rect);
- int newWidth = rect.right - rect.left;
- int newHeight = rect.bottom - rect.top;
- OS.GetClientRect (handle, rect);
- int oldWidth = rect.right - rect.left;
- int oldHeight = rect.bottom - rect.top;
- if (newWidth == oldWidth && newHeight == oldHeight) {
- return result;
- }
- RECT inset = new RECT ();
- OS.SendMessage (handle, OS.TCM_ADJUSTRECT, 0, inset);
- int marginX = -inset.right, marginY = -inset.bottom;
- if (newWidth != oldWidth) {
- int left = oldWidth;
- if (newWidth < oldWidth) left = newWidth;
- OS.SetRect (rect, left - marginX, 0, newWidth, newHeight);
- OS.InvalidateRect (handle, rect, true);
- }
- if (newHeight != oldHeight) {
- int bottom = oldHeight;
- if (newHeight < oldHeight) bottom = newHeight;
- if (newWidth < oldWidth) oldWidth -= marginX;
- OS.SetRect (rect, 0, bottom - marginY, oldWidth, newHeight);
- OS.InvalidateRect (handle, rect, true);
- }
- return result;
-}
-
-LRESULT wmNotifyChild (NMHDR hdr, int /*long*/ wParam, int /*long*/ lParam) {
- int code = hdr.code;
- switch (code) {
- case OS.TCN_SELCHANGE:
- case OS.TCN_SELCHANGING:
- TabItem item = null;
- int index = (int)/*64*/OS.SendMessage (handle, OS.TCM_GETCURSEL, 0, 0);
- if (index != -1) item = items [index];
- if (item != null) {
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- if (code == OS.TCN_SELCHANGE) {
- control.setBounds (getClientArea ());
- }
- control.setVisible (code == OS.TCN_SELCHANGE);
- }
- }
- if (code == OS.TCN_SELCHANGE) {
- Event event = new Event ();
- event.item = item;
- postEvent (SWT.Selection, event);
- }
- }
- return super.wmNotifyChild (hdr, wParam, lParam);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabItem.java
deleted file mode 100755
index b3d441e71f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabItem.java
+++ /dev/null
@@ -1,372 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * corresponding to a tab for a page in a tab folder.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tabfolder">TabFolder, TabItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class TabItem extends Item {
- TabFolder parent;
- Control control;
- String toolTipText;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>TabFolder</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabItem (TabFolder parent, int style) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>TabFolder</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabItem (TabFolder parent, int style, int index) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-void _setText (int index, String string) {
- /*
- * Bug in Windows. In version 6.00 of COMCTL32.DLL, tab
- * items with an image and a label that includes '&' cause
- * the tab to draw incorrectly (even when doubled '&&').
- * The image overlaps the label. The fix is to remove
- * all '&' characters from the string.
- */
- if (OS.COMCTL32_MAJOR >= 6 && image != null) {
- if (string.indexOf ('&') != -1) {
- int length = string.length ();
- char[] text = new char [length];
- string.getChars ( 0, length, text, 0);
- int i = 0, j = 0;
- for (i=0; i<length; i++) {
- if (text[i] != '&') text [j++] = text [i];
- }
- if (j < i) string = new String (text, 0, j);
- }
- }
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hHeap = OS.GetProcessHeap ();
- TCHAR buffer = new TCHAR (parent.getCodePage (), string, true);
- int byteCount = buffer.length () * TCHAR.sizeof;
- int /*long*/ pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (pszText, buffer, byteCount);
- TCITEM tcItem = new TCITEM ();
- tcItem.mask = OS.TCIF_TEXT;
- tcItem.pszText = pszText;
- OS.SendMessage (hwnd, OS.TCM_SETITEM, index, tcItem);
- OS.HeapFree (hHeap, 0, pszText);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns the control that is used to fill the client area of
- * the tab folder when the user selects the tab item. If no
- * control has been set, return <code>null</code>.
- * <p>
- * @return the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget();
- return control;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public Rectangle getBounds() {
- checkWidget();
- int index = parent.indexOf(this);
- if (index == -1) return new Rectangle (0, 0, 0, 0);
- RECT itemRect = new RECT ();
- OS.SendMessage (parent.handle, OS.TCM_GETITEMRECT, index, itemRect);
- return new Rectangle(itemRect.left, itemRect.top, itemRect.right - itemRect.left, itemRect.bottom - itemRect.top);
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>TabFolder</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabFolder getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- int index = parent.indexOf (this);
- if (index == parent.getSelectionIndex ()) {
- if (control != null) control.setVisible (false);
- }
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- control = null;
-}
-
-/**
- * Sets the control that is used to fill the client area of
- * the tab folder when the user selects the tab item.
- * <p>
- * @param control the new control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- if (this.control != null && this.control.isDisposed ()) {
- this.control = null;
- }
- Control oldControl = this.control, newControl = control;
- this.control = control;
- int index = parent.indexOf (this), selectionIndex = parent.getSelectionIndex();
- if (index != selectionIndex) {
- if (newControl != null) {
- if (selectionIndex != -1) {
- Control selectedControl = parent.getItem(selectionIndex).getControl();
- if (selectedControl == newControl) return;
- }
- newControl.setVisible(false);
- return;
- }
- }
- if (newControl != null) {
- newControl.setBounds (parent.getClientArea ());
- newControl.setVisible (true);
- }
- if (oldControl != null) oldControl.setVisible (false);
-}
-
-public void setImage (Image image) {
- checkWidget();
- int index = parent.indexOf (this);
- if (index == -1) return;
- super.setImage (image);
- /*
- * Bug in Windows. In version 6.00 of COMCTL32.DLL, tab
- * items with an image and a label that includes '&' cause
- * the tab to draw incorrectly (even when doubled '&&').
- * The image overlaps the label. The fix is to remove
- * all '&' characters from the string and set the text
- * whenever the image or text is changed.
- */
- if (OS.COMCTL32_MAJOR >= 6) {
- if (text.indexOf ('&') != -1) _setText (index, text);
- }
- int /*long*/ hwnd = parent.handle;
- TCITEM tcItem = new TCITEM ();
- tcItem.mask = OS.TCIF_IMAGE;
- tcItem.iImage = parent.imageIndex (image);
- OS.SendMessage (hwnd, OS.TCM_SETITEM, index, tcItem);
-}
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (string.equals (text)) return;
- int index = parent.indexOf (this);
- if (index == -1) return;
- super.setText (string);
- _setText (index, string);
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java
deleted file mode 100755
index 48a1f8e0fb..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java
+++ /dev/null
@@ -1,6966 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-//import java.util.*;
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class implement a selectable user interface
- * object that displays a list of images and strings and issues
- * notification when selected.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TableItem</code>.
- * </p><p>
- * Style <code>VIRTUAL</code> is used to create a <code>Table</code> whose
- * <code>TableItem</code>s are to be populated by the client on an on-demand basis
- * instead of up-front. This can provide significant performance improvements for
- * tables that are very large or for which <code>TableItem</code> population is
- * expensive (for example, retrieving values from an external source).
- * </p><p>
- * Here is an example of using a <code>Table</code> with style <code>VIRTUAL</code>:
- * <code><pre>
- * final Table table = new Table (parent, SWT.VIRTUAL | SWT.BORDER);
- * table.setItemCount (1000000);
- * table.addListener (SWT.SetData, new Listener () {
- * public void handleEvent (Event event) {
- * TableItem item = (TableItem) event.item;
- * int index = table.indexOf (item);
- * item.setText ("Item " + index);
- * System.out.println (item.getText ());
- * }
- * });
- * </pre></code>
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not normally make sense to add <code>Control</code> children to
- * it, or set a layout on it, unless implementing something like a cell
- * editor.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, HIDE_SELECTION, VIRTUAL, NO_SCROLL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection, SetData, MeasureItem, EraseItem, PaintItem</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles SINGLE, and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Table extends Composite {
- TableItem [] items;
- TableColumn [] columns;
- int columnCount, customCount;
- ImageList imageList, headerImageList;
- TableItem currentItem;
- TableColumn sortColumn;
- RECT focusRect;
- int /*long*/ headerToolTipHandle;
- boolean ignoreCustomDraw, ignoreDrawForeground, ignoreDrawBackground, ignoreDrawFocus, ignoreDrawSelection, ignoreDrawHot;
- boolean customDraw, dragStarted, explorerTheme, firstColumnImage, fixScrollWidth, tipRequested, wasSelected, wasResized, painted;
- boolean ignoreActivate, ignoreSelect, ignoreShrink, ignoreResize, ignoreColumnMove, ignoreColumnResize, fullRowSelect;
- int itemHeight, lastIndexOf, lastWidth, sortDirection, resizeCount, selectionForeground, hotIndex;
- static /*final*/ int /*long*/ HeaderProc;
- static final int INSET = 4;
- static final int GRID_WIDTH = 1;
- static final int SORT_WIDTH = 10;
- static final int HEADER_MARGIN = 12;
- static final int HEADER_EXTRA = 3;
- static final int VISTA_EXTRA = 2;
- static final int EXPLORER_EXTRA = 2;
- static final int H_SCROLL_LIMIT = 32;
- static final int V_SCROLL_LIMIT = 16;
- static final int DRAG_IMAGE_SIZE = 301;
- static final boolean EXPLORER_THEME = true;
- static final int /*long*/ TableProc;
- static final TCHAR TableClass = new TCHAR (0, OS.WC_LISTVIEW, true);
- static {
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, TableClass, lpWndClass);
- TableProc = lpWndClass.lpfnWndProc;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#CHECK
- * @see SWT#FULL_SELECTION
- * @see SWT#HIDE_SELECTION
- * @see SWT#VIRTUAL
- * @see SWT#NO_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Table (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-void _addListener (int eventType, Listener listener) {
- super._addListener (eventType, listener);
- switch (eventType) {
- case SWT.MeasureItem:
- case SWT.EraseItem:
- case SWT.PaintItem:
- setCustomDraw (true);
- setBackgroundTransparent (true);
- if (OS.COMCTL32_MAJOR < 6) style |= SWT.DOUBLE_BUFFERED;
- if (OS.IsWinCE) OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, OS.LVS_EX_LABELTIP, 0);
- break;
- }
-}
-
-TableItem _getItem (int index) {
- if ((style & SWT.VIRTUAL) == 0) return items [index];
- if (items [index] != null) return items [index];
- return items [index] = new TableItem (this, SWT.NONE, -1, false);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * If the receiver has the <code>SWT.CHECK</code> style and the check selection changes,
- * the event object detail field contains the value <code>SWT.CHECK</code>.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * The item field of the event object is valid for default selection, but the detail field is not used.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- return callWindowProc (hwnd, msg, wParam, lParam, false);
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam, boolean forceSelect) {
- if (handle == 0) return 0;
- if (handle != hwnd) {
- return OS.CallWindowProc (HeaderProc, hwnd, msg, wParam, lParam);
- }
- int topIndex = 0;
- boolean checkSelection = false, checkActivate = false, redraw = false;
- switch (msg) {
- /* Keyboard messages */
- /*
- * Feature in Windows. Windows sends LVN_ITEMACTIVATE from WM_KEYDOWN
- * instead of WM_CHAR. This means that application code that expects
- * to consume the key press and therefore avoid a SWT.DefaultSelection
- * event will fail. The fix is to ignore LVN_ITEMACTIVATE when it is
- * caused by WM_KEYDOWN and send SWT.DefaultSelection from WM_CHAR.
- */
- case OS.WM_KEYDOWN:
- checkActivate = true;
- //FALL THROUGH
- case OS.WM_CHAR:
- case OS.WM_IME_CHAR:
- case OS.WM_KEYUP:
- case OS.WM_SYSCHAR:
- case OS.WM_SYSKEYDOWN:
- case OS.WM_SYSKEYUP:
- //FALL THROUGH
-
- /* Scroll messages */
- case OS.WM_HSCROLL:
- case OS.WM_VSCROLL:
- //FALL THROUGH
-
- /* Resize messages */
- case OS.WM_WINDOWPOSCHANGED:
- redraw = findImageControl () != null && getDrawing () && OS.IsWindowVisible (handle);
- if (redraw) {
- /*
- * Feature in Windows. When LVM_SETBKCOLOR is used with CLR_NONE
- * to make the background of the table transparent, drawing becomes
- * slow. The fix is to temporarily clear CLR_NONE when redraw is
- * turned off.
- */
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- OS.SendMessage (handle, OS.LVM_SETBKCOLOR, 0, 0xFFFFFF);
- }
- //FALL THROUGH
-
- /* Mouse messages */
- case OS.WM_LBUTTONDBLCLK:
- case OS.WM_LBUTTONDOWN:
- case OS.WM_LBUTTONUP:
- case OS.WM_MBUTTONDBLCLK:
- case OS.WM_MBUTTONDOWN:
- case OS.WM_MBUTTONUP:
- case OS.WM_MOUSEHOVER:
- case OS.WM_MOUSELEAVE:
- case OS.WM_MOUSEMOVE:
- case OS.WM_MOUSEWHEEL:
- case OS.WM_RBUTTONDBLCLK:
- case OS.WM_RBUTTONDOWN:
- case OS.WM_RBUTTONUP:
- case OS.WM_XBUTTONDBLCLK:
- case OS.WM_XBUTTONDOWN:
- case OS.WM_XBUTTONUP:
- checkSelection = true;
- //FALL THROUGH
-
- /* Other messages */
- case OS.WM_SETFONT:
- case OS.WM_TIMER: {
- if (findImageControl () != null) {
- topIndex = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0);
- }
- }
- }
- boolean oldSelected = wasSelected;
- if (checkSelection) wasSelected = false;
- if (checkActivate) ignoreActivate = true;
-
- /*
- * Bug in Windows. For some reason, when the WS_EX_COMPOSITED
- * style is set in a parent of a table and the header is visible,
- * Windows issues an endless stream of WM_PAINT messages. The
- * fix is to call BeginPaint() and EndPaint() outside of WM_PAINT
- * and pass the paint HDC in to the window proc.
- */
- boolean fixPaint = false;
- if (msg == OS.WM_PAINT) {
- int bits0 = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits0 & OS.LVS_NOCOLUMNHEADER) == 0) {
- int /*long*/ hwndParent = OS.GetParent (handle), hwndOwner = 0;
- while (hwndParent != 0) {
- int bits1 = OS.GetWindowLong (hwndParent, OS.GWL_EXSTYLE);
- if ((bits1 & OS.WS_EX_COMPOSITED) != 0) {
- fixPaint = true;
- break;
- }
- hwndOwner = OS.GetWindow (hwndParent, OS.GW_OWNER);
- if (hwndOwner != 0) break;
- hwndParent = OS.GetParent (hwndParent);
- }
- }
- }
-
- /* Remove the scroll bars that Windows keeps automatically adding */
- boolean fixScroll = false;
- if ((style & SWT.H_SCROLL) == 0 || (style & SWT.V_SCROLL) == 0) {
- switch (msg) {
- case OS.WM_PAINT:
- case OS.WM_NCPAINT:
- case OS.WM_WINDOWPOSCHANGING: {
- int bits = OS.GetWindowLong (hwnd, OS.GWL_STYLE);
- if ((style & SWT.H_SCROLL) == 0 && (bits & OS.WS_HSCROLL) != 0) {
- fixScroll = true;
- bits &= ~OS.WS_HSCROLL;
- }
- if ((style & SWT.V_SCROLL) == 0 && (bits & OS.WS_VSCROLL) != 0) {
- fixScroll = true;
- bits &= ~OS.WS_VSCROLL;
- }
- if (fixScroll) OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- }
- }
- }
- int /*long*/ code = 0;
- if (fixPaint) {
- PAINTSTRUCT ps = new PAINTSTRUCT ();
- int /*long*/ hDC = OS.BeginPaint (hwnd, ps);
- code = OS.CallWindowProc (TableProc, hwnd, OS.WM_PAINT, hDC, lParam);
- OS.EndPaint (hwnd, ps);
- } else {
- code = OS.CallWindowProc (TableProc, hwnd, msg, wParam, lParam);
- }
- if (fixScroll) {
- int flags = OS.RDW_FRAME | OS.RDW_INVALIDATE;
- OS.RedrawWindow (handle, null, 0, flags);
- }
-
- if (checkActivate) ignoreActivate = false;
- if (checkSelection) {
- if (wasSelected || forceSelect) {
- Event event = new Event ();
- int index = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);
- if (index != -1) event.item = _getItem (index);
- postEvent (SWT.Selection, event);
- }
- wasSelected = oldSelected;
- }
- switch (msg) {
- /* Keyboard messages */
- case OS.WM_KEYDOWN:
- case OS.WM_CHAR:
- case OS.WM_IME_CHAR:
- case OS.WM_KEYUP:
- case OS.WM_SYSCHAR:
- case OS.WM_SYSKEYDOWN:
- case OS.WM_SYSKEYUP:
- //FALL THROUGH
-
- /* Scroll messages */
- case OS.WM_HSCROLL:
- case OS.WM_VSCROLL:
- //FALL THROUGH
-
- /* Resize messages */
- case OS.WM_WINDOWPOSCHANGED:
- if (redraw) {
- OS.SendMessage (handle, OS.LVM_SETBKCOLOR, 0, OS.CLR_NONE);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.InvalidateRect (handle, null, true);
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (hwndHeader != 0) OS.InvalidateRect (hwndHeader, null, true);
- }
- //FALL THROUGH
-
- /* Mouse messages */
- case OS.WM_LBUTTONDBLCLK:
- case OS.WM_LBUTTONDOWN:
- case OS.WM_LBUTTONUP:
- case OS.WM_MBUTTONDBLCLK:
- case OS.WM_MBUTTONDOWN:
- case OS.WM_MBUTTONUP:
- case OS.WM_MOUSEHOVER:
- case OS.WM_MOUSELEAVE:
- case OS.WM_MOUSEMOVE:
- case OS.WM_MOUSEWHEEL:
- case OS.WM_RBUTTONDBLCLK:
- case OS.WM_RBUTTONDOWN:
- case OS.WM_RBUTTONUP:
- case OS.WM_XBUTTONDBLCLK:
- case OS.WM_XBUTTONDOWN:
- case OS.WM_XBUTTONUP:
- //FALL THROUGH
-
- /* Other messages */
- case OS.WM_SETFONT:
- case OS.WM_TIMER: {
- if (findImageControl () != null) {
- if (topIndex != OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0)) {
- OS.InvalidateRect (handle, null, true);
- }
- }
- break;
- }
-
- case OS.WM_PAINT:
- painted = true;
- break;
- }
- return code;
-}
-
-static int checkStyle (int style) {
- /*
- * Feature in Windows. Even when WS_HSCROLL or
- * WS_VSCROLL is not specified, Windows creates
- * trees and tables with scroll bars. The fix
- * is to set H_SCROLL and V_SCROLL.
- *
- * NOTE: This code appears on all platforms so that
- * applications have consistent scroll bar behavior.
- */
- if ((style & SWT.NO_SCROLL) == 0) {
- style |= SWT.H_SCROLL | SWT.V_SCROLL;
- }
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-
-LRESULT CDDS_ITEMPOSTPAINT (NMLVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long*/ lParam) {
- int /*long*/ hDC = nmcd.hdc;
- if (explorerTheme && !ignoreCustomDraw) {
- hotIndex = -1;
- if (hooks (SWT.EraseItem) && nmcd.left != nmcd.right) {
- OS.RestoreDC (hDC, -1);
- }
- }
- /*
- * Bug in Windows. When the table has the extended style
- * LVS_EX_FULLROWSELECT and LVM_SETBKCOLOR is used with
- * CLR_NONE to make the table transparent, Windows fills
- * a black rectangle around any column that contains an
- * image. The fix is clear LVS_EX_FULLROWSELECT during
- * custom draw.
- *
- * NOTE: Since CDIS_FOCUS is cleared during custom draw,
- * it is necessary to draw the focus rectangle after the
- * item has been drawn.
- */
- if (!ignoreCustomDraw && !ignoreDrawFocus && nmcd.left != nmcd.right) {
- if (OS.IsWindowVisible (handle) && OS.IsWindowEnabled (handle)) {
- if (!explorerTheme && (style & SWT.FULL_SELECTION) != 0) {
- if ((int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) == OS.CLR_NONE) {
- int dwExStyle = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((dwExStyle & OS.LVS_EX_FULLROWSELECT) == 0) {
-// if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) {
- if (OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED) == nmcd.dwItemSpec) {
- if (handle == OS.GetFocus ()) {
- int uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- if ((uiState & OS.UISF_HIDEFOCUS) == 0) {
- RECT rect = new RECT ();
- rect.left = OS.LVIR_BOUNDS;
- boolean oldIgnore = ignoreCustomDraw;
- ignoreCustomDraw = true;
- OS.SendMessage (handle, OS. LVM_GETITEMRECT, nmcd.dwItemSpec, rect);
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int index = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0);
- RECT itemRect = new RECT ();
- if (index == 0) {
- itemRect.left = OS.LVIR_LABEL;
- OS.SendMessage (handle, OS. LVM_GETITEMRECT, index, itemRect);
- } else {
- itemRect.top = index;
- itemRect.left = OS.LVIR_ICON;
- OS.SendMessage (handle, OS. LVM_GETSUBITEMRECT, nmcd.dwItemSpec, itemRect);
- }
- ignoreCustomDraw = oldIgnore;
- rect.left = itemRect.left;
- OS.DrawFocusRect (nmcd.hdc, rect);
- }
- }
- }
- }
- }
- }
- }
- }
- return null;
-}
-
-LRESULT CDDS_ITEMPREPAINT (NMLVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Bug in Windows. When the table has the extended style
- * LVS_EX_FULLROWSELECT and LVM_SETBKCOLOR is used with
- * CLR_NONE to make the table transparent, Windows fills
- * a black rectangle around any column that contains an
- * image. The fix is clear LVS_EX_FULLROWSELECT during
- * custom draw.
- *
- * NOTE: It is also necessary to clear CDIS_FOCUS to stop
- * the table from drawing the focus rectangle around the
- * first item instead of the full row.
- */
- if (!ignoreCustomDraw) {
- if (OS.IsWindowVisible (handle) && OS.IsWindowEnabled (handle)) {
- if (!explorerTheme && (style & SWT.FULL_SELECTION) != 0) {
- if ((int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) == OS.CLR_NONE) {
- int dwExStyle = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((dwExStyle & OS.LVS_EX_FULLROWSELECT) == 0) {
- if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) {
- nmcd.uItemState &= ~OS.CDIS_FOCUS;
- OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof);
- }
- }
- }
- }
- }
- }
- if (explorerTheme && !ignoreCustomDraw) {
- hotIndex = (nmcd.uItemState & OS.CDIS_HOT) != 0 ? (int)/*64*/nmcd.dwItemSpec : -1;
- if (hooks (SWT.EraseItem) && nmcd.left != nmcd.right) {
- OS.SaveDC (nmcd.hdc);
- int /*long*/ hrgn = OS.CreateRectRgn (0, 0, 0, 0);
- OS.SelectClipRgn (nmcd.hdc, hrgn);
- OS.DeleteObject (hrgn);
- }
- }
- return new LRESULT (OS.CDRF_NOTIFYSUBITEMDRAW | OS.CDRF_NOTIFYPOSTPAINT);
-}
-
-LRESULT CDDS_POSTPAINT (NMLVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long*/ lParam) {
- if (ignoreCustomDraw) return null;
- /*
- * Bug in Windows. When the table has the extended style
- * LVS_EX_FULLROWSELECT and LVM_SETBKCOLOR is used with
- * CLR_NONE to make the table transparent, Windows fills
- * a black rectangle around any column that contains an
- * image. The fix is clear LVS_EX_FULLROWSELECT during
- * custom draw.
- */
- if (--customCount == 0 && OS.IsWindowVisible (handle)) {
- if (!explorerTheme && (style & SWT.FULL_SELECTION) != 0) {
- if ((int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) == OS.CLR_NONE) {
- int dwExStyle = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((dwExStyle & OS.LVS_EX_FULLROWSELECT) == 0) {
- int bits = OS.LVS_EX_FULLROWSELECT;
- /*
- * Feature in Windows. When LVM_SETEXTENDEDLISTVIEWSTYLE is
- * used to set or clear the extended style bits and the table
- * has a tooltip, the tooltip is hidden. The fix is to clear
- * the tooltip before setting the bits and then reset it.
- */
- int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.LVM_SETTOOLTIPS, 0, 0);
- if (OS.IsWinCE) {
- RECT rect = new RECT ();
- boolean damaged = OS.GetUpdateRect (handle, rect, true);
- OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, bits, bits);
- OS.ValidateRect (handle, null);
- if (damaged) OS.InvalidateRect (handle, rect, true);
- } else {
- int /*long*/ rgn = OS.CreateRectRgn (0, 0, 0, 0);
- int result = OS.GetUpdateRgn (handle, rgn, true);
- OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, bits, bits);
- OS.ValidateRect (handle, null);
- if (result != OS.NULLREGION) OS.InvalidateRgn (handle, rgn, true);
- OS.DeleteObject (rgn);
- }
- /*
- * Bug in Windows. Despite the documentation, LVM_SETTOOLTIPS
- * uses WPARAM instead of LPARAM for the new tooltip The fix
- * is to put the tooltip in both parameters.
- */
- hwndToolTip = OS.SendMessage (handle, OS.LVM_SETTOOLTIPS, hwndToolTip, hwndToolTip);
- }
- }
- }
- }
- return null;
-}
-
-LRESULT CDDS_PREPAINT (NMLVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long*/ lParam) {
- if (ignoreCustomDraw) {
- return new LRESULT (OS.CDRF_NOTIFYITEMDRAW | OS.CDRF_NOTIFYPOSTPAINT);
- }
- /*
- * Bug in Windows. When the table has the extended style
- * LVS_EX_FULLROWSELECT and LVM_SETBKCOLOR is used with
- * CLR_NONE to make the table transparent, Windows fills
- * a black rectangle around any column that contains an
- * image. The fix is clear LVS_EX_FULLROWSELECT during
- * custom draw.
- */
- if (customCount++ == 0 && OS.IsWindowVisible (handle)) {
- if (!explorerTheme && (style & SWT.FULL_SELECTION) != 0) {
- if ((int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) == OS.CLR_NONE) {
- int dwExStyle = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((dwExStyle & OS.LVS_EX_FULLROWSELECT) != 0) {
- int bits = OS.LVS_EX_FULLROWSELECT;
- /*
- * Feature in Windows. When LVM_SETEXTENDEDLISTVIEWSTYLE is
- * used to set or clear the extended style bits and the table
- * has a tooltip, the tooltip is hidden. The fix is to clear
- * the tooltip before setting the bits and then reset it.
- */
- int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.LVM_SETTOOLTIPS, 0, 0);
- if (OS.IsWinCE) {
- RECT rect = new RECT ();
- boolean damaged = OS.GetUpdateRect (handle, rect, true);
- OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, bits, 0);
- OS.ValidateRect (handle, null);
- if (damaged) OS.InvalidateRect (handle, rect, true);
- } else {
- int /*long*/ rgn = OS.CreateRectRgn (0, 0, 0, 0);
- int result = OS.GetUpdateRgn (handle, rgn, true);
- OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, bits, 0);
- OS.ValidateRect (handle, null);
- if (result != OS.NULLREGION) OS.InvalidateRgn (handle, rgn, true);
- OS.DeleteObject (rgn);
- }
- /*
- * Bug in Windows. Despite the documentation, LVM_SETTOOLTIPS
- * uses WPARAM instead of LPARAM for the new tooltip The fix
- * is to put the tooltip in both parameters.
- */
- hwndToolTip = OS.SendMessage (handle, OS.LVM_SETTOOLTIPS, hwndToolTip, hwndToolTip);
- }
- }
- }
- }
- if (OS.IsWindowVisible (handle)) {
- boolean draw = true;
- /*
- * Feature in Windows. On Vista using the explorer theme,
- * Windows draws a vertical line to separate columns. When
- * there is only a single column, the line looks strange.
- * The fix is to draw the background using custom draw.
- */
- if (explorerTheme && columnCount == 0) {
- int /*long*/ hDC = nmcd.hdc;
- RECT rect = new RECT ();
- OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
- if (OS.IsWindowEnabled (handle) || findImageControl () != null) {
- drawBackground (hDC, rect);
- } else {
- fillBackground (hDC, OS.GetSysColor (OS.COLOR_3DFACE), rect);
- }
- draw = false;
- }
- if (draw) {
- Control control = findBackgroundControl ();
- if (control != null && control.backgroundImage != null) {
- RECT rect = new RECT ();
- OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
- fillImageBackground (nmcd.hdc, control, rect);
- } else {
- if ((int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) == OS.CLR_NONE) {
- if (OS.IsWindowEnabled (handle)) {
- RECT rect = new RECT ();
- OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
- if (control == null) control = this;
- fillBackground (nmcd.hdc, control.getBackgroundPixel (), rect);
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- if (sortColumn != null && sortDirection != SWT.NONE) {
- int index = indexOf (sortColumn);
- if (index != -1) {
- parent.forceResize ();
- int clrSortBk = getSortColumnPixel ();
- RECT columnRect = new RECT (), headerRect = new RECT ();
- OS.GetClientRect (handle, columnRect);
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect) != 0) {
- OS.MapWindowPoints (hwndHeader, handle, headerRect, 2);
- columnRect.left = headerRect.left;
- columnRect.right = headerRect.right;
- if (OS.IntersectRect(columnRect, columnRect, rect)) {
- fillBackground (nmcd.hdc, clrSortBk, columnRect);
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return new LRESULT (OS.CDRF_NOTIFYITEMDRAW | OS.CDRF_NOTIFYPOSTPAINT);
-}
-
-LRESULT CDDS_SUBITEMPOSTPAINT (NMLVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long*/ lParam) {
- if (ignoreCustomDraw) return null;
- if (nmcd.left == nmcd.right) return new LRESULT (OS.CDRF_DODEFAULT);
- int /*long*/ hDC = nmcd.hdc;
- if (ignoreDrawForeground) OS.RestoreDC (hDC, -1);
- if (OS.IsWindowVisible (handle)) {
- /*
- * Feature in Windows. When there is a sort column, the sort column
- * color draws on top of the background color for an item. The fix
- * is to clear the sort column in CDDS_SUBITEMPREPAINT, and reset it
- * in CDDS_SUBITEMPOSTPAINT.
- */
- if ((int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) != OS.CLR_NONE) {
- if ((sortDirection & (SWT.UP | SWT.DOWN)) != 0) {
- if (sortColumn != null && !sortColumn.isDisposed ()) {
- int oldColumn = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSELECTEDCOLUMN, 0, 0);
- if (oldColumn == -1) {
- int newColumn = indexOf (sortColumn);
- int result = 0;
- int /*long*/ rgn = 0;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- rgn = OS.CreateRectRgn (0, 0, 0, 0);
- result = OS.GetUpdateRgn (handle, rgn, true);
- }
- OS.SendMessage (handle, OS.LVM_SETSELECTEDCOLUMN, newColumn, 0);
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- OS.ValidateRect (handle, null);
- if (result != OS.NULLREGION) OS.InvalidateRgn (handle, rgn, true);
- OS.DeleteObject (rgn);
- }
- }
- }
- }
- }
- if (hooks (SWT.PaintItem)) {
- TableItem item = _getItem ((int)/*64*/nmcd.dwItemSpec);
- sendPaintItemEvent (item, nmcd);
- //widget could be disposed at this point
- }
- if (!ignoreDrawFocus && focusRect != null) {
- OS.SetTextColor (nmcd.hdc, 0);
- OS.SetBkColor (nmcd.hdc, 0xFFFFFF);
- OS.DrawFocusRect (nmcd.hdc, focusRect);
- focusRect = null;
- }
- }
- return null;
-}
-
-LRESULT CDDS_SUBITEMPREPAINT (NMLVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long*/ lParam) {
- int /*long*/ hDC = nmcd.hdc;
- if (explorerTheme && !ignoreCustomDraw && hooks (SWT.EraseItem) && (nmcd.left != nmcd.right)) {
- OS.RestoreDC (hDC, -1);
- }
- /*
- * Feature in Windows. When a new table item is inserted
- * using LVM_INSERTITEM in a table that is transparent
- * (ie. LVM_SETBKCOLOR has been called with CLR_NONE),
- * TVM_INSERTITEM calls NM_CUSTOMDRAW before the new item
- * has been added to the array. The fix is to check for
- * null.
- */
- TableItem item = _getItem ((int)/*64*/nmcd.dwItemSpec);
- if (item == null || item.isDisposed ()) return null;
- int /*long*/ hFont = item.fontHandle (nmcd.iSubItem);
- if (hFont != -1) OS.SelectObject (hDC, hFont);
- if (ignoreCustomDraw || (nmcd.left == nmcd.right)) {
- return new LRESULT (hFont == -1 ? OS.CDRF_DODEFAULT : OS.CDRF_NEWFONT);
- }
- int code = OS.CDRF_DODEFAULT;
- selectionForeground = -1;
- ignoreDrawForeground = ignoreDrawSelection = ignoreDrawFocus = ignoreDrawBackground = false;
- if (OS.IsWindowVisible (handle)) {
- Event measureEvent = null;
- if (hooks (SWT.MeasureItem)) {
- measureEvent = sendMeasureItemEvent (item, (int)/*64*/nmcd.dwItemSpec, nmcd.iSubItem, nmcd.hdc);
- if (isDisposed () || item.isDisposed ()) return null;
- }
- if (hooks (SWT.EraseItem)) {
- sendEraseItemEvent (item, nmcd, lParam, measureEvent);
- if (isDisposed () || item.isDisposed ()) return null;
- code |= OS.CDRF_NOTIFYPOSTPAINT;
- }
- if (ignoreDrawForeground || hooks (SWT.PaintItem)) code |= OS.CDRF_NOTIFYPOSTPAINT;
- }
- int clrText = item.cellForeground != null ? item.cellForeground [nmcd.iSubItem] : -1;
- if (clrText == -1) clrText = item.foreground;
- int clrTextBk = item.cellBackground != null ? item.cellBackground [nmcd.iSubItem] : -1;
- if (clrTextBk == -1) clrTextBk = item.background;
- if (selectionForeground != -1) clrText = selectionForeground;
- /*
- * Bug in Windows. When the table has the extended style
- * LVS_EX_FULLROWSELECT and LVM_SETBKCOLOR is used with
- * CLR_NONE to make the table transparent, Windows draws
- * a black rectangle around any column that contains an
- * image. The fix is emulate LVS_EX_FULLROWSELECT by
- * drawing the selection.
- */
- if (OS.IsWindowVisible (handle) && OS.IsWindowEnabled (handle)) {
- if (!explorerTheme && !ignoreDrawSelection && (style & SWT.FULL_SELECTION) != 0) {
- int bits = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((bits & OS.LVS_EX_FULLROWSELECT) == 0) {
- /*
- * Bug in Windows. For some reason, CDIS_SELECTED always set,
- * even for items that are not selected. The fix is to get
- * the selection state from the item.
- */
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.stateMask = OS.LVIS_SELECTED;
- lvItem.iItem = (int)/*64*/nmcd.dwItemSpec;
- int /*long*/ result = OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);
- if ((result != 0 && (lvItem.state & OS.LVIS_SELECTED) != 0)) {
- int clrSelection = -1;
- if (nmcd.iSubItem == 0) {
- if (OS.GetFocus () == handle || display.getHighContrast ()) {
- clrSelection = OS.GetSysColor (OS.COLOR_HIGHLIGHT);
- } else {
- if ((style & SWT.HIDE_SELECTION) == 0) {
- clrSelection = OS.GetSysColor (OS.COLOR_3DFACE);
- }
- }
- } else {
- if (OS.GetFocus () == handle || display.getHighContrast ()) {
- clrText = OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT);
- clrTextBk = clrSelection = OS.GetSysColor (OS.COLOR_HIGHLIGHT);
- } else {
- if ((style & SWT.HIDE_SELECTION) == 0) {
- clrTextBk = clrSelection = OS.GetSysColor (OS.COLOR_3DFACE);
- }
- }
- }
- if (clrSelection != -1) {
- RECT rect = item.getBounds ((int)/*64*/nmcd.dwItemSpec, nmcd.iSubItem, true, nmcd.iSubItem != 0, true, false, hDC);
- fillBackground (hDC, clrSelection, rect);
- }
- }
- }
- }
- }
- if (!ignoreDrawForeground) {
- /*
- * Bug in Windows. When the attributes are for one cell in a table,
- * Windows does not reset them for the next cell. As a result, all
- * subsequent cells are drawn using the previous font, foreground and
- * background colors. The fix is to set the all attributes when any
- * attribute could have changed.
- */
- boolean hasAttributes = true;
- if (hFont == -1 && clrText == -1 && clrTextBk == -1) {
- if (item.cellForeground == null && item.cellBackground == null && item.cellFont == null) {
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int count = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- if (count == 1) hasAttributes = false;
- }
- }
- if (hasAttributes) {
- if (hFont == -1) hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- OS.SelectObject (hDC, hFont);
- if (OS.IsWindowEnabled (handle)) {
- nmcd.clrText = clrText == -1 ? getForegroundPixel () : clrText;
- if (clrTextBk == -1) {
- nmcd.clrTextBk = OS.CLR_NONE;
- if (selectionForeground == -1) {
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- if (control.backgroundImage == null) {
- if ((int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) != OS.CLR_NONE) {
- nmcd.clrTextBk = control.getBackgroundPixel ();
- }
- }
- }
- } else {
- nmcd.clrTextBk = selectionForeground != -1 ? OS.CLR_NONE : clrTextBk;
- }
- OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof);
- }
- code |= OS.CDRF_NEWFONT;
- }
- }
- if (OS.IsWindowEnabled (handle)) {
- /*
- * Feature in Windows. When there is a sort column, the sort column
- * color draws on top of the background color for an item. The fix
- * is to clear the sort column in CDDS_SUBITEMPREPAINT, and reset it
- * in CDDS_SUBITEMPOSTPAINT.
- */
- if (clrTextBk != -1) {
- int oldColumn = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSELECTEDCOLUMN, 0, 0);
- if (oldColumn != -1 && oldColumn == nmcd.iSubItem) {
- int result = 0;
- int /*long*/ rgn = 0;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- rgn = OS.CreateRectRgn (0, 0, 0, 0);
- result = OS.GetUpdateRgn (handle, rgn, true);
- }
- OS.SendMessage (handle, OS.LVM_SETSELECTEDCOLUMN, -1, 0);
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- OS.ValidateRect (handle, null);
- if (result != OS.NULLREGION) OS.InvalidateRgn (handle, rgn, true);
- OS.DeleteObject (rgn);
- }
- code |= OS.CDRF_NOTIFYPOSTPAINT;
- }
- }
- } else {
- /*
- * Feature in Windows. When the table is disabled, it draws
- * with a gray background but does not gray the text. The fix
- * is to explicitly gray the text.
- */
- nmcd.clrText = OS.GetSysColor (OS.COLOR_GRAYTEXT);
- if (findImageControl () != null) {
- nmcd.clrTextBk = OS.CLR_NONE;
- } else {
- nmcd.clrTextBk = OS.GetSysColor (OS.COLOR_3DFACE);
- }
- nmcd.uItemState &= ~OS.CDIS_SELECTED;
- OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof);
- code |= OS.CDRF_NEWFONT;
- }
- return new LRESULT (code);
-}
-
-void checkBuffered () {
- super.checkBuffered ();
- if (OS.COMCTL32_MAJOR >= 6) style |= SWT.DOUBLE_BUFFERED;
- if ((style & SWT.VIRTUAL) != 0) style |= SWT.DOUBLE_BUFFERED;
-}
-
-boolean checkData (TableItem item, boolean redraw) {
- if ((style & SWT.VIRTUAL) == 0) return true;
- return checkData (item, indexOf (item), redraw);
-}
-
-boolean checkData (TableItem item, int index, boolean redraw) {
- if ((style & SWT.VIRTUAL) == 0) return true;
- if (!item.cached) {
- item.cached = true;
- Event event = new Event ();
- event.item = item;
- event.index = index;
- currentItem = item;
- sendEvent (SWT.SetData, event);
- //widget could be disposed at this point
- currentItem = null;
- if (isDisposed () || item.isDisposed ()) return false;
- if (redraw) {
- if (!setScrollWidth (item, false)) {
- item.redraw ();
- }
- }
- }
- return true;
-}
-
-boolean checkHandle (int /*long*/ hwnd) {
- if (hwnd == handle) return true;
- return hwnd == OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Clears the item at the given zero-relative index in the receiver.
- * The text, icon and other attributes of the item are set to the default
- * value. If the table was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param index the index of the item to clear
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clear (int index) {
- checkWidget ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
- TableItem item = items [index];
- if (item != null) {
- if (item != currentItem) item.clear ();
- /*
- * Bug in Windows. Despite the fact that every item in the
- * table always has LPSTR_TEXTCALLBACK, Windows caches the
- * bounds for the selected items. This means that
- * when you change the string to be something else, Windows
- * correctly asks you for the new string but when the item
- * is selected, the selection draws using the bounds of the
- * previous item. The fix is to reset LPSTR_TEXTCALLBACK
- * even though it has not changed, causing Windows to flush
- * cached bounds.
- */
- if ((style & SWT.VIRTUAL) == 0 && item.cached) {
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_TEXT | OS.LVIF_INDENT;
- lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
- lvItem.iItem = index;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
- item.cached = false;
- }
- if (currentItem == null && getDrawing () && OS.IsWindowVisible (handle)) {
- OS.SendMessage (handle, OS.LVM_REDRAWITEMS, index, index);
- }
- setScrollWidth (item, false);
- }
-}
-
-/**
- * Removes the items from the receiver which are between the given
- * zero-relative start and end indices (inclusive). The text, icon
- * and other attributes of the items are set to their default values.
- * If the table was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param start the start index of the item to clear
- * @param end the end index of the item to clear
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clear (int start, int end) {
- checkWidget ();
- if (start > end) return;
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (!(0 <= start && start <= end && end < count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- if (start == 0 && end == count - 1) {
- clearAll ();
- } else {
- LVITEM lvItem = null;
- boolean cleared = false;
- for (int i=start; i<=end; i++) {
- TableItem item = items [i];
- if (item != null) {
- if (item != currentItem) {
- cleared = true;
- item.clear ();
- }
- /*
- * Bug in Windows. Despite the fact that every item in the
- * table always has LPSTR_TEXTCALLBACK, Windows caches the
- * bounds for the selected items. This means that
- * when you change the string to be something else, Windows
- * correctly asks you for the new string but when the item
- * is selected, the selection draws using the bounds of the
- * previous item. The fix is to reset LPSTR_TEXTCALLBACK
- * even though it has not changed, causing Windows to flush
- * cached bounds.
- */
- if ((style & SWT.VIRTUAL) == 0 && item.cached) {
- if (lvItem == null) {
- lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_TEXT | OS.LVIF_INDENT;
- lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
- }
- lvItem.iItem = i;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
- item.cached = false;
- }
- }
- }
- if (cleared) {
- if (currentItem == null && getDrawing () && OS.IsWindowVisible (handle)) {
- OS.SendMessage (handle, OS.LVM_REDRAWITEMS, start, end);
- }
- TableItem item = start == end ? items [start] : null;
- setScrollWidth (item, false);
- }
- }
-}
-
-/**
- * Clears the items at the given zero-relative indices in the receiver.
- * The text, icon and other attributes of the items are set to their default
- * values. If the table was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clear (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<indices.length; i++) {
- if (!(0 <= indices [i] && indices [i] < count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- }
- LVITEM lvItem = null;
- boolean cleared = false;
- for (int i=0; i<indices.length; i++) {
- int index = indices [i];
- TableItem item = items [index];
- if (item != null) {
- if (item != currentItem) {
- cleared = true;
- item.clear ();
- }
- /*
- * Bug in Windows. Despite the fact that every item in the
- * table always has LPSTR_TEXTCALLBACK, Windows caches the
- * bounds for the selected items. This means that
- * when you change the string to be something else, Windows
- * correctly asks you for the new string but when the item
- * is selected, the selection draws using the bounds of the
- * previous item. The fix is to reset LPSTR_TEXTCALLBACK
- * even though it has not changed, causing Windows to flush
- * cached bounds.
- */
- if ((style & SWT.VIRTUAL) == 0 && item.cached) {
- if (lvItem == null) {
- lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_TEXT | OS.LVIF_INDENT;
- lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
- }
- lvItem.iItem = i;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
- item.cached = false;
- }
- if (currentItem == null && getDrawing () && OS.IsWindowVisible (handle)) {
- OS.SendMessage (handle, OS.LVM_REDRAWITEMS, index, index);
- }
- }
- }
- if (cleared) setScrollWidth (null, false);
-}
-
-/**
- * Clears all the items in the receiver. The text, icon and other
- * attributes of the items are set to their default values. If the
- * table was created with the <code>SWT.VIRTUAL</code> style, these
- * attributes are requested again as needed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clearAll () {
- checkWidget ();
- LVITEM lvItem = null;
- boolean cleared = false;
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<count; i++) {
- TableItem item = items [i];
- if (item != null) {
- if (item != currentItem) {
- cleared = true;
- item.clear ();
- }
- /*
- * Bug in Windows. Despite the fact that every item in the
- * table always has LPSTR_TEXTCALLBACK, Windows caches the
- * bounds for the selected items. This means that
- * when you change the string to be something else, Windows
- * correctly asks you for the new string but when the item
- * is selected, the selection draws using the bounds of the
- * previous item. The fix is to reset LPSTR_TEXTCALLBACK
- * even though it has not changed, causing Windows to flush
- * cached bounds.
- */
- if ((style & SWT.VIRTUAL) == 0 && item.cached) {
- if (lvItem == null) {
- lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_TEXT | OS.LVIF_INDENT;
- lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
- }
- lvItem.iItem = i;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
- item.cached = false;
- }
- }
- }
- if (cleared) {
- if (currentItem == null && getDrawing () && OS.IsWindowVisible (handle)) {
- OS.SendMessage (handle, OS.LVM_REDRAWITEMS, 0, count - 1);
- }
- setScrollWidth (null, false);
- }
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- if (fixScrollWidth) setScrollWidth (null, true);
- //This code is intentionally commented
-// if (itemHeight == -1 && hooks (SWT.MeasureItem)) {
-// int i = 0;
-// TableItem item = items [i];
-// if (item != null) {
-// int hDC = OS.GetDC (handle);
-// int oldFont = 0, newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
-// if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
-// int index = 0, count = Math.max (1, columnCount);
-// while (index < count) {
-// int hFont = item.cellFont != null ? item.cellFont [index] : -1;
-// if (hFont == -1) hFont = item.font;
-// if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
-// sendMeasureItemEvent (item, i, index, hDC);
-// if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
-// if (isDisposed () || item.isDisposed ()) break;
-// index++;
-// }
-// if (newFont != 0) OS.SelectObject (hDC, oldFont);
-// OS.ReleaseDC (handle, hDC);
-// }
-// }
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- RECT rect = new RECT ();
- OS.GetWindowRect (hwndHeader, rect);
- int height = rect.bottom - rect.top;
- int bits = 0;
- if (wHint != SWT.DEFAULT) {
- bits |= wHint & 0xFFFF;
- } else {
- int width = 0;
- int count = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<count; i++) {
- width += OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, i, 0);
- }
- bits |= width & 0xFFFF;
- }
- int /*long*/ result = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, -1, OS.MAKELPARAM (bits, 0xFFFF));
- int width = OS.LOWORD (result);
- int /*long*/ empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0);
- int /*long*/ oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0);
- int itemHeight = OS.HIWORD (oneItem) - OS.HIWORD (empty);
- height += (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0) * itemHeight;
- if (width == 0) width = DEFAULT_WIDTH;
- if (height == 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2; height += border * 2;
- if ((style & SWT.V_SCROLL) != 0) {
- width += OS.GetSystemMetrics (OS.SM_CXVSCROLL);
- }
- if ((style & SWT.H_SCROLL) != 0) {
- height += OS.GetSystemMetrics (OS.SM_CYHSCROLL);
- }
- return new Point (width, height);
-}
-
-void createHandle () {
- super.createHandle ();
- state &= ~(CANVAS | THEME_BACKGROUND);
-
- /* Use the Explorer theme */
- if (EXPLORER_THEME) {
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0) && OS.IsAppThemed ()) {
- explorerTheme = true;
- OS.SetWindowTheme (handle, Display.EXPLORER, null);
- }
- }
-
- /* Get the header window proc */
- if (HeaderProc == 0) {
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- HeaderProc = OS.GetWindowLongPtr (hwndHeader, OS.GWLP_WNDPROC);
- }
-
- /*
- * Feature in Windows. In version 5.8 of COMCTL32.DLL,
- * if the font is changed for an item, the bounds for the
- * item are not updated, causing the text to be clipped.
- * The fix is to detect the version of COMCTL32.DLL, and
- * if it is one of the versions with the problem, then
- * use version 5.00 of the control (a version that does
- * not have the problem). This is the recommended work
- * around from the MSDN.
- */
- if (!OS.IsWinCE) {
- if (OS.COMCTL32_MAJOR < 6) {
- OS.SendMessage (handle, OS.CCM_SETVERSION, 5, 0);
- }
- }
-
- /*
- * This code is intentionally commented. According to
- * the documentation, setting the default item size is
- * supposed to improve performance. By experimentation,
- * this does not seem to have much of an effect.
- */
-// OS.SendMessage (handle, OS.LVM_SETITEMCOUNT, 1024 * 2, 0);
-
- /* Set the checkbox image list */
- if ((style & SWT.CHECK) != 0) {
- int /*long*/ empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0);
- int /*long*/ oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0);
- int width = OS.HIWORD (oneItem) - OS.HIWORD (empty), height = width;
- setCheckboxImageList (width, height, false);
- OS.SendMessage (handle, OS. LVM_SETCALLBACKMASK, OS.LVIS_STATEIMAGEMASK, 0);
- }
-
- /*
- * Feature in Windows. When the control is created,
- * it does not use the default system font. A new HFONT
- * is created and destroyed when the control is destroyed.
- * This means that a program that queries the font from
- * this control, uses the font in another control and then
- * destroys this control will have the font unexpectedly
- * destroyed in the other control. The fix is to assign
- * the font ourselves each time the control is created.
- * The control will not destroy a font that it did not
- * create.
- */
- int /*long*/ hFont = OS.GetStockObject (OS.SYSTEM_FONT);
- OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);
-
- /*
- * Bug in Windows. When the first column is inserted
- * without setting the header text, Windows will never
- * allow the header text for the first column to be set.
- * The fix is to set the text to an empty string when
- * the column is inserted.
- */
- LVCOLUMN lvColumn = new LVCOLUMN ();
- lvColumn.mask = OS.LVCF_TEXT | OS.LVCF_WIDTH;
- int /*long*/ hHeap = OS.GetProcessHeap ();
- int /*long*/ pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof);
- lvColumn.pszText = pszText;
- OS.SendMessage (handle, OS.LVM_INSERTCOLUMN, 0, lvColumn);
- OS.HeapFree (hHeap, 0, pszText);
-
- /* Set the extended style bits */
- int bits1 = OS.LVS_EX_LABELTIP;
- if ((style & SWT.FULL_SELECTION) != 0) bits1 |= OS.LVS_EX_FULLROWSELECT;
- if (OS.COMCTL32_MAJOR >= 6) bits1 |= OS.LVS_EX_DOUBLEBUFFER;
- OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, bits1, bits1);
-
- /*
- * Feature in Windows. Windows does not explicitly set the orientation of
- * the header. Instead, the orientation is inherited when WS_EX_LAYOUTRTL
- * is specified for the table. This means that when both WS_EX_LAYOUTRTL
- * and WS_EX_NOINHERITLAYOUT are specified for the table, the header will
- * not be oriented correctly. The fix is to explicitly set the orientation
- * for the header.
- *
- * NOTE: WS_EX_LAYOUTRTL is not supported on Windows NT.
- */
- if (OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int bits2 = OS.GetWindowLong (hwndHeader, OS.GWL_EXSTYLE);
- OS.SetWindowLong (hwndHeader, OS.GWL_EXSTYLE, bits2 | OS.WS_EX_LAYOUTRTL);
- int /*long*/ hwndTooltop = OS.SendMessage (handle, OS.LVM_GETTOOLTIPS, 0, 0);
- int bits3 = OS.GetWindowLong (hwndTooltop, OS.GWL_EXSTYLE);
- OS.SetWindowLong (hwndTooltop, OS.GWL_EXSTYLE, bits3 | OS.WS_EX_LAYOUTRTL);
- }
- }
-}
-
-void createHeaderToolTips () {
- if (OS.IsWinCE) return;
- if (headerToolTipHandle != 0) return;
- int bits = 0;
- if (OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- if ((style & SWT.RIGHT_TO_LEFT) != 0) bits |= OS.WS_EX_LAYOUTRTL;
- }
- headerToolTipHandle = OS.CreateWindowEx (
- bits,
- new TCHAR (0, OS.TOOLTIPS_CLASS, true),
- null,
- OS.TTS_NOPREFIX,
- OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0,
- handle,
- 0,
- OS.GetModuleHandle (null),
- null);
- if (headerToolTipHandle == 0) error (SWT.ERROR_NO_HANDLES);
- /*
- * Feature in Windows. Despite the fact that the
- * tool tip text contains \r\n, the tooltip will
- * not honour the new line unless TTM_SETMAXTIPWIDTH
- * is set. The fix is to set TTM_SETMAXTIPWIDTH to
- * a large value.
- */
- OS.SendMessage (headerToolTipHandle, OS.TTM_SETMAXTIPWIDTH, 0, 0x7FFF);
-}
-
-void createItem (TableColumn column, int index) {
- if (!(0 <= index && index <= columnCount)) error (SWT.ERROR_INVALID_RANGE);
- int oldColumn = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSELECTEDCOLUMN, 0, 0);
- if (oldColumn >= index) {
- OS.SendMessage (handle, OS.LVM_SETSELECTEDCOLUMN, oldColumn + 1, 0);
- }
- if (columnCount == columns.length) {
- TableColumn [] newColumns = new TableColumn [columns.length + 4];
- System.arraycopy (columns, 0, newColumns, 0, columns.length);
- columns = newColumns;
- }
- int itemCount = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (item != null) {
- String [] strings = item.strings;
- if (strings != null) {
- String [] temp = new String [columnCount + 1];
- System.arraycopy (strings, 0, temp, 0, index);
- System.arraycopy (strings, index, temp, index + 1, columnCount - index);
- item.strings = temp;
- }
- Image [] images = item.images;
- if (images != null) {
- Image [] temp = new Image [columnCount + 1];
- System.arraycopy (images, 0, temp, 0, index);
- System.arraycopy (images, index, temp, index + 1, columnCount - index);
- item.images = temp;
- }
- if (index == 0) {
- if (columnCount != 0) {
- if (strings == null) {
- item.strings = new String [columnCount + 1];
- item.strings [1] = item.text;
- }
- item.text = ""; //$NON-NLS-1$
- if (images == null) {
- item.images = new Image [columnCount + 1];
- item.images [1] = item.image;
- }
- item.image = null;
- }
- }
- if (item.cellBackground != null) {
- int [] cellBackground = item.cellBackground;
- int [] temp = new int [columnCount + 1];
- System.arraycopy (cellBackground, 0, temp, 0, index);
- System.arraycopy (cellBackground, index, temp, index + 1, columnCount - index);
- temp [index] = -1;
- item.cellBackground = temp;
- }
- if (item.cellForeground != null) {
- int [] cellForeground = item.cellForeground;
- int [] temp = new int [columnCount + 1];
- System.arraycopy (cellForeground, 0, temp, 0, index);
- System.arraycopy (cellForeground, index, temp, index + 1, columnCount - index);
- temp [index] = -1;
- item.cellForeground = temp;
- }
- if (item.cellFont != null) {
- Font [] cellFont = item.cellFont;
- Font [] temp = new Font [columnCount + 1];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index, temp, index + 1, columnCount - index);
- item.cellFont = temp;
- }
- }
- }
- /*
- * Insert the column into the columns array before inserting
- * it into the widget so that the column will be present when
- * any callbacks are issued as a result of LVM_INSERTCOLUMN
- * or LVM_SETCOLUMN.
- */
- System.arraycopy (columns, index, columns, index + 1, columnCount++ - index);
- columns [index] = column;
-
- /*
- * Ensure that resize listeners for the table and for columns
- * within the table are not called. This can happen when the
- * first column is inserted into a table or when a new column
- * is inserted in the first position.
- */
- ignoreColumnResize = true;
- if (index == 0) {
- if (columnCount > 1) {
- LVCOLUMN lvColumn = new LVCOLUMN ();
- lvColumn.mask = OS.LVCF_WIDTH;
- OS.SendMessage (handle, OS.LVM_INSERTCOLUMN, 1, lvColumn);
- OS.SendMessage (handle, OS.LVM_GETCOLUMN, 1, lvColumn);
- int width = lvColumn.cx;
- int cchTextMax = 1024;
- int /*long*/ hHeap = OS.GetProcessHeap ();
- int byteCount = cchTextMax * TCHAR.sizeof;
- int /*long*/ pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- lvColumn.mask = OS.LVCF_TEXT | OS.LVCF_IMAGE | OS.LVCF_WIDTH | OS.LVCF_FMT;
- lvColumn.pszText = pszText;
- lvColumn.cchTextMax = cchTextMax;
- OS.SendMessage (handle, OS.LVM_GETCOLUMN, 0, lvColumn);
- OS.SendMessage (handle, OS.LVM_SETCOLUMN, 1, lvColumn);
- lvColumn.fmt = OS.LVCFMT_IMAGE;
- lvColumn.cx = width;
- lvColumn.iImage = OS.I_IMAGENONE;
- lvColumn.pszText = lvColumn.cchTextMax = 0;
- OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn);
- lvColumn.mask = OS.LVCF_FMT;
- lvColumn.fmt = OS.LVCFMT_LEFT;
- OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn);
- if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
- } else {
- OS.SendMessage (handle, OS.LVM_SETCOLUMNWIDTH, 0, 0);
- }
- /*
- * Bug in Windows. Despite the fact that every item in the
- * table always has LPSTR_TEXTCALLBACK, Windows caches the
- * bounds for the selected items. This means that
- * when you change the string to be something else, Windows
- * correctly asks you for the new string but when the item
- * is selected, the selection draws using the bounds of the
- * previous item. The fix is to reset LPSTR_TEXTCALLBACK
- * even though it has not changed, causing Windows to flush
- * cached bounds.
- */
- if ((style & SWT.VIRTUAL) == 0) {
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_TEXT | OS.LVIF_IMAGE;
- lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
- lvItem.iImage = OS.I_IMAGECALLBACK;
- for (int i=0; i<itemCount; i++) {
- lvItem.iItem = i;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
- }
- }
- } else {
- int fmt = OS.LVCFMT_LEFT;
- if ((column.style & SWT.CENTER) == SWT.CENTER) fmt = OS.LVCFMT_CENTER;
- if ((column.style & SWT.RIGHT) == SWT.RIGHT) fmt = OS.LVCFMT_RIGHT;
- LVCOLUMN lvColumn = new LVCOLUMN ();
- lvColumn.mask = OS.LVCF_WIDTH | OS.LVCF_FMT;
- lvColumn.fmt = fmt;
- OS.SendMessage (handle, OS.LVM_INSERTCOLUMN, index, lvColumn);
- }
- ignoreColumnResize = false;
-
- /* Add the tool tip item for the header */
- if (headerToolTipHandle != 0) {
- RECT rect = new RECT ();
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, rect) != 0) {
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- lpti.uFlags = OS.TTF_SUBCLASS;
- lpti.hwnd = hwndHeader;
- lpti.uId = column.id = display.nextToolTipId++;
- lpti.left = rect.left;
- lpti.top = rect.top;
- lpti.right = rect.right;
- lpti.bottom = rect.bottom;
- lpti.lpszText = OS.LPSTR_TEXTCALLBACK;
- OS.SendMessage (headerToolTipHandle, OS.TTM_ADDTOOL, 0, lpti);
- }
- }
-}
-
-void createItem (TableItem item, int index) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
- if (count == items.length) {
- /*
- * Grow the array faster when redraw is off or the
- * table is not visible. When the table is painted,
- * the items array is resized to be smaller to reduce
- * memory usage.
- */
- boolean small = getDrawing () && OS.IsWindowVisible (handle);
- int length = small ? items.length + 4 : Math.max (4, items.length * 3 / 2);
- TableItem [] newItems = new TableItem [length];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_TEXT | OS.LVIF_IMAGE;
- lvItem.iItem = index;
- lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
- /*
- * Bug in Windows. Despite the fact that the image list
- * index has never been set for the item, Windows always
- * assumes that the image index for the item is valid.
- * When an item is inserted, the image index is zero.
- * Therefore, when the first image is inserted and is
- * assigned image index zero, every item draws with this
- * image. The fix is to set the image index when the
- * the item is created.
- */
- lvItem.iImage = OS.I_IMAGECALLBACK;
-
- /* Insert the item */
- setDeferResize (true);
- ignoreSelect = ignoreShrink = true;
- int result = (int)/*64*/OS.SendMessage (handle, OS.LVM_INSERTITEM, 0, lvItem);
- ignoreSelect = ignoreShrink = false;
- if (result == -1) error (SWT.ERROR_ITEM_NOT_ADDED);
- System.arraycopy (items, index, items, index + 1, count - index);
- items [index] = item;
- setDeferResize (false);
-
- /* Resize to show the first item */
- if (count == 0) setScrollWidth (item, false);
-}
-
-void createWidget () {
- super.createWidget ();
- itemHeight = hotIndex = -1;
- items = new TableItem [4];
- columns = new TableColumn [4];
-}
-
-int defaultBackground () {
- return OS.GetSysColor (OS.COLOR_WINDOW);
-}
-
-void deregister () {
- super.deregister ();
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (hwndHeader != 0) display.removeControl (hwndHeader);
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. Indices that are out
- * of range and duplicate indices are ignored.
- *
- * @param indices the array of indices for the items to deselect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- LVITEM lvItem = new LVITEM ();
- lvItem.stateMask = OS.LVIS_SELECTED;
- for (int i=0; i<indices.length; i++) {
- /*
- * An index of -1 will apply the change to all
- * items. Ensure that indices are greater than -1.
- */
- if (indices [i] >= 0) {
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_SETITEMSTATE, indices [i], lvItem);
- ignoreSelect = false;
- }
- }
-}
-
-/**
- * Deselects the item at the given zero-relative index in the receiver.
- * If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget ();
- /*
- * An index of -1 will apply the change to all
- * items. Ensure that index is greater than -1.
- */
- if (index < 0) return;
- LVITEM lvItem = new LVITEM ();
- lvItem.stateMask = OS.LVIS_SELECTED;
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_SETITEMSTATE, index, lvItem);
- ignoreSelect = false;
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. The range of the
- * indices is inclusive. Indices that are out of range are ignored.
- *
- * @param start the start index of the items to deselect
- * @param end the end index of the items to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int start, int end) {
- checkWidget ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (start == 0 && end == count - 1) {
- deselectAll ();
- } else {
- LVITEM lvItem = new LVITEM ();
- lvItem.stateMask = OS.LVIS_SELECTED;
- /*
- * An index of -1 will apply the change to all
- * items. Ensure that indices are greater than -1.
- */
- start = Math.max (0, start);
- for (int i=start; i<=end; i++) {
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_SETITEMSTATE, i, lvItem);
- ignoreSelect = false;
- }
- }
-}
-
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll () {
- checkWidget ();
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.stateMask = OS.LVIS_SELECTED;
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_SETITEMSTATE, -1, lvItem);
- ignoreSelect = false;
-}
-
-void destroyItem (TableColumn column) {
- int index = 0;
- while (index < columnCount) {
- if (columns [index] == column) break;
- index++;
- }
- int oldColumn = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSELECTEDCOLUMN, 0, 0);
- if (oldColumn == index) {
- OS.SendMessage (handle, OS.LVM_SETSELECTEDCOLUMN, -1, 0);
- } else {
- if (oldColumn > index) {
- OS.SendMessage (handle, OS.LVM_SETSELECTEDCOLUMN, oldColumn - 1, 0);
- }
- }
- int orderIndex = 0;
- int [] oldOrder = new int [columnCount];
- OS.SendMessage (handle, OS.LVM_GETCOLUMNORDERARRAY, columnCount, oldOrder);
- while (orderIndex < columnCount) {
- if (oldOrder [orderIndex] == index) break;
- orderIndex++;
- }
- ignoreColumnResize = true;
- boolean first = false;
- if (index == 0) {
- first = true;
- if (columnCount > 1) {
- index = 1;
- int cchTextMax = 1024;
- int /*long*/ hHeap = OS.GetProcessHeap ();
- int byteCount = cchTextMax * TCHAR.sizeof;
- int /*long*/ pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- LVCOLUMN lvColumn = new LVCOLUMN ();
- lvColumn.mask = OS.LVCF_TEXT | OS.LVCF_IMAGE | OS.LVCF_WIDTH | OS.LVCF_FMT;
- lvColumn.pszText = pszText;
- lvColumn.cchTextMax = cchTextMax;
- OS.SendMessage (handle, OS.LVM_GETCOLUMN, 1, lvColumn);
- lvColumn.fmt &= ~(OS.LVCFMT_CENTER | OS.LVCFMT_RIGHT);
- lvColumn.fmt |= OS.LVCFMT_LEFT;
- OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn);
- if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
- } else {
- int /*long*/ hHeap = OS.GetProcessHeap ();
- int /*long*/ pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof);
- LVCOLUMN lvColumn = new LVCOLUMN ();
- lvColumn.mask = OS.LVCF_TEXT | OS.LVCF_IMAGE | OS.LVCF_WIDTH | OS.LVCF_FMT;
- lvColumn.pszText = pszText;
- lvColumn.iImage = OS.I_IMAGENONE;
- lvColumn.fmt = OS.LVCFMT_LEFT;
- OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn);
- if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
- if (OS.COMCTL32_MAJOR >= 6) {
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_FORMAT;
- hdItem.fmt = OS.HDF_LEFT;
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, hdItem);
- }
- }
- /*
- * Bug in Windows. Despite the fact that every item in the
- * table always has LPSTR_TEXTCALLBACK, Windows caches the
- * bounds for the selected items. This means that
- * when you change the string to be something else, Windows
- * correctly asks you for the new string but when the item
- * is selected, the selection draws using the bounds of the
- * previous item. The fix is to reset LPSTR_TEXTCALLBACK
- * even though it has not changed, causing Windows to flush
- * cached bounds.
- */
- if ((style & SWT.VIRTUAL) == 0) {
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_TEXT | OS.LVIF_IMAGE;
- lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
- lvItem.iImage = OS.I_IMAGECALLBACK;
- int itemCount = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<itemCount; i++) {
- lvItem.iItem = i;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
- }
- }
- }
- if (columnCount > 1) {
- if (OS.SendMessage (handle, OS.LVM_DELETECOLUMN, index, 0) == 0) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- }
- if (first) index = 0;
- System.arraycopy (columns, index + 1, columns, index, --columnCount - index);
- columns [columnCount] = null;
- int itemCount = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (item != null) {
- if (columnCount == 0) {
- item.strings = null;
- item.images = null;
- item.cellBackground = null;
- item.cellForeground = null;
- item.cellFont = null;
- } else {
- if (item.strings != null) {
- String [] strings = item.strings;
- if (index == 0) {
- item.text = strings [1] != null ? strings [1] : ""; //$NON-NLS-1$
- }
- String [] temp = new String [columnCount];
- System.arraycopy (strings, 0, temp, 0, index);
- System.arraycopy (strings, index + 1, temp, index, columnCount - index);
- item.strings = temp;
- } else {
- if (index == 0) item.text = ""; //$NON-NLS-1$
- }
- if (item.images != null) {
- Image [] images = item.images;
- if (index == 0) item.image = images [1];
- Image [] temp = new Image [columnCount];
- System.arraycopy (images, 0, temp, 0, index);
- System.arraycopy (images, index + 1, temp, index, columnCount - index);
- item.images = temp;
- } else {
- if (index == 0) item.image = null;
- }
- if (item.cellBackground != null) {
- int [] cellBackground = item.cellBackground;
- int [] temp = new int [columnCount];
- System.arraycopy (cellBackground, 0, temp, 0, index);
- System.arraycopy (cellBackground, index + 1, temp, index, columnCount - index);
- item.cellBackground = temp;
- }
- if (item.cellForeground != null) {
- int [] cellForeground = item.cellForeground;
- int [] temp = new int [columnCount];
- System.arraycopy (cellForeground, 0, temp, 0, index);
- System.arraycopy (cellForeground, index + 1, temp, index, columnCount - index);
- item.cellForeground = temp;
- }
- if (item.cellFont != null) {
- Font [] cellFont = item.cellFont;
- Font [] temp = new Font [columnCount];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index + 1, temp, index, columnCount - index);
- item.cellFont = temp;
- }
- }
- }
- }
- if (columnCount == 0) setScrollWidth (null, true);
- updateMoveable ();
- ignoreColumnResize = false;
- if (columnCount != 0) {
- /*
- * Bug in Windows. When LVM_DELETECOLUMN is used to delete a
- * column zero when that column is both the first column in the
- * table and the first column in the column order array, Windows
- * incorrectly computes the new column order. For example, both
- * the orders {0, 3, 1, 2} and {0, 3, 2, 1} give a new column
- * order of {0, 2, 1}, while {0, 2, 1, 3} gives {0, 1, 2, 3}.
- * The fix is to compute the new order and compare it with the
- * order that Windows is using. If the two differ, the new order
- * is used.
- */
- int count = 0;
- int oldIndex = oldOrder [orderIndex];
- int [] newOrder = new int [columnCount];
- for (int i=0; i<oldOrder.length; i++) {
- if (oldOrder [i] != oldIndex) {
- int newIndex = oldOrder [i] <= oldIndex ? oldOrder [i] : oldOrder [i] - 1;
- newOrder [count++] = newIndex;
- }
- }
- OS.SendMessage (handle, OS.LVM_GETCOLUMNORDERARRAY, columnCount, oldOrder);
- int j = 0;
- while (j < newOrder.length) {
- if (oldOrder [j] != newOrder [j]) break;
- j++;
- }
- if (j != newOrder.length) {
- OS.SendMessage (handle, OS.LVM_SETCOLUMNORDERARRAY, newOrder.length, newOrder);
- /*
- * Bug in Windows. When LVM_SETCOLUMNORDERARRAY is used to change
- * the column order, the header redraws correctly but the table does
- * not. The fix is to force a redraw.
- */
- OS.InvalidateRect (handle, null, true);
- }
- TableColumn [] newColumns = new TableColumn [columnCount - orderIndex];
- for (int i=orderIndex; i<newOrder.length; i++) {
- newColumns [i - orderIndex] = columns [newOrder [i]];
- newColumns [i - orderIndex].updateToolTip (newOrder [i]);
- }
- for (int i=0; i<newColumns.length; i++) {
- if (!newColumns [i].isDisposed ()) {
- newColumns [i].sendEvent (SWT.Move);
- }
- }
- }
-
- /* Remove the tool tip item for the header */
- if (headerToolTipHandle != 0) {
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- lpti.uId = column.id;
- lpti.hwnd = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- OS.SendMessage (headerToolTipHandle, OS.TTM_DELTOOL, 0, lpti);
- }
-}
-
-void destroyItem (TableItem item) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- int index = 0;
- while (index < count) {
- if (items [index] == item) break;
- index++;
- }
- if (index == count) return;
- setDeferResize (true);
- ignoreSelect = ignoreShrink = true;
- int /*long*/ code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0);
- ignoreSelect = ignoreShrink = false;
- if (code == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
- System.arraycopy (items, index + 1, items, index, --count - index);
- items [count] = null;
- if (count == 0) setTableEmpty ();
- setDeferResize (false);
-}
-
-void fixCheckboxImageList (boolean fixScroll) {
- /*
- * Bug in Windows. When the state image list is larger than the
- * image list, Windows incorrectly positions the state images. When
- * the table is scrolled, Windows draws garbage. The fix is to force
- * the state image list to be the same size as the image list.
- */
- if ((style & SWT.CHECK) == 0) return;
- int /*long*/ hImageList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_SMALL, 0);
- if (hImageList == 0) return;
- int [] cx = new int [1], cy = new int [1];
- OS.ImageList_GetIconSize (hImageList, cx, cy);
- int /*long*/ hStateList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);
- if (hStateList == 0) return;
- int [] stateCx = new int [1], stateCy = new int [1];
- OS.ImageList_GetIconSize (hStateList, stateCx, stateCy);
- if (cx [0] == stateCx [0] && cy [0] == stateCy [0]) return;
- setCheckboxImageList (cx [0], cy [0], fixScroll);
-}
-
-void fixCheckboxImageListColor (boolean fixScroll) {
- if ((style & SWT.CHECK) == 0) return;
- int /*long*/ hStateList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);
- if (hStateList == 0) return;
- int [] cx = new int [1], cy = new int [1];
- OS.ImageList_GetIconSize (hStateList, cx, cy);
- setCheckboxImageList (cx [0], cy [0], fixScroll);
-}
-
-void fixItemHeight (boolean fixScroll) {
- /*
- * Bug in Windows. When both a header and grid lines are
- * displayed, the grid lines do not take into account the
- * height of the header and draw in the wrong place. The
- * fix is to set the height of the table items to be the
- * height of the header so that the lines draw in the right
- * place. The height of a table item is the maximum of the
- * height of the font or the height of image list.
- *
- * NOTE: In version 5.80 of COMCTL32.DLL, the bug is fixed.
- */
- if (itemHeight != -1) return;
- if (OS.COMCTL32_VERSION >= OS.VERSION (5, 80)) return;
- int bits = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((bits & OS.LVS_EX_GRIDLINES) == 0) return;
- bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.LVS_NOCOLUMNHEADER) != 0) return;
- /*
- * Bug in Windows. Making any change to an item that
- * changes the item height of a table while the table
- * is scrolled can cause the lines to draw incorrectly.
- * This happens even when the lines are not currently
- * visible and are shown afterwards. The fix is to
- * save the top index, scroll to the top of the table
- * and then restore the original top index.
- */
- int topIndex = getTopIndex ();
- if (fixScroll && topIndex != 0) {
- setRedraw (false);
- setTopIndex (0);
- }
- int /*long*/ hOldList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_SMALL, 0);
- if (hOldList != 0) return;
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- RECT rect = new RECT ();
- OS.GetWindowRect (hwndHeader, rect);
- int height = rect.bottom - rect.top - 1;
- int /*long*/ hImageList = OS.ImageList_Create (1, height, 0, 0, 0);
- OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, hImageList);
- fixCheckboxImageList (false);
- OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);
- if (headerImageList != null) {
- int /*long*/ hHeaderImageList = headerImageList.getHandle ();
- OS.SendMessage (hwndHeader, OS.HDM_SETIMAGELIST, 0, hHeaderImageList);
- }
- OS.ImageList_Destroy (hImageList);
- if (fixScroll && topIndex != 0) {
- setTopIndex (topIndex);
- setRedraw (true);
- }
-}
-
-/**
- * Returns the column at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- * Columns are returned in the order that they were created.
- * If no <code>TableColumn</code>s were created by the programmer,
- * this method will throw <code>ERROR_INVALID_RANGE</code> despite
- * the fact that a single column of data may be visible in the table.
- * This occurs when the programmer uses the table like a list, adding
- * items but never creating a column.
- *
- * @param index the index of the column to return
- * @return the column at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- */
-public TableColumn getColumn (int index) {
- checkWidget ();
- if (!(0 <= index && index < columnCount)) error (SWT.ERROR_INVALID_RANGE);
- return columns [index];
-}
-
-/**
- * Returns the number of columns contained in the receiver.
- * If no <code>TableColumn</code>s were created by the programmer,
- * this value is zero, despite the fact that visually, one column
- * of items may be visible. This occurs when the programmer uses
- * the table like a list, adding items but never creating a column.
- *
- * @return the number of columns
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getColumnCount () {
- checkWidget ();
- return columnCount;
-}
-
-/**
- * Returns an array of zero-relative integers that map
- * the creation order of the receiver's items to the
- * order in which they are currently being displayed.
- * <p>
- * Specifically, the indices of the returned array represent
- * the current visual order of the items, and the contents
- * of the array represent the creation order of the items.
- * </p><p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the current visual order of the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public int[] getColumnOrder () {
- checkWidget ();
- if (columnCount == 0) return new int [0];
- int [] order = new int [columnCount];
- OS.SendMessage (handle, OS.LVM_GETCOLUMNORDERARRAY, columnCount, order);
- return order;
-}
-
-/**
- * Returns an array of <code>TableColumn</code>s which are the
- * columns in the receiver. Columns are returned in the order
- * that they were created. If no <code>TableColumn</code>s were
- * created by the programmer, the array is empty, despite the fact
- * that visually, one column of items may be visible. This occurs
- * when the programmer uses the table like a list, adding items but
- * never creating a column.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- */
-public TableColumn [] getColumns () {
- checkWidget ();
- TableColumn [] result = new TableColumn [columnCount];
- System.arraycopy (columns, 0, result, 0, columnCount);
- return result;
-}
-
-int getFocusIndex () {
-// checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);
-}
-
-/**
- * Returns the width in pixels of a grid line.
- *
- * @return the width of a grid line in pixels
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getGridLineWidth () {
- checkWidget ();
- return GRID_WIDTH;
-}
-
-/**
- * Returns the height of the receiver's header
- *
- * @return the height of the header or zero if the header is not visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public int getHeaderHeight () {
- checkWidget ();
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (hwndHeader == 0) return 0;
- RECT rect = new RECT ();
- OS.GetWindowRect (hwndHeader, rect);
- return rect.bottom - rect.top;
-}
-
-/**
- * Returns <code>true</code> if the receiver's header is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's header's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getHeaderVisible () {
- checkWidget ();
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- return (bits & OS.LVS_NOCOLUMNHEADER) == 0;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem getItem (int index) {
- checkWidget ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
- return _getItem (index);
-}
-
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- * <p>
- * The item that is returned represents an item that could be selected by the user.
- * For example, if selection only occurs in items in the first column, then null is
- * returned if the point is outside of the item.
- * Note that the SWT.FULL_SELECTION style hint, which specifies the selection policy,
- * determines the extent of the selection.
- * </p>
- *
- * @param point the point used to locate the item
- * @return the item at the given point, or null if the point is not in a selectable item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem getItem (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (count == 0) return null;
- LVHITTESTINFO pinfo = new LVHITTESTINFO ();
- pinfo.x = point.x;
- pinfo.y = point.y;
- if ((style & SWT.FULL_SELECTION) == 0) {
- if (hooks (SWT.MeasureItem)) {
- /*
- * Bug in Windows. When LVM_SUBITEMHITTEST is used to hittest
- * a point that is above the table, instead of returning -1 to
- * indicate that the hittest failed, a negative index is returned.
- * The fix is to consider any value that is negative a failure.
- */
- if (OS.SendMessage (handle, OS.LVM_SUBITEMHITTEST, 0, pinfo) < 0) {
- RECT rect = new RECT ();
- rect.left = OS.LVIR_ICON;
- ignoreCustomDraw = true;
- int /*long*/ code = OS.SendMessage (handle, OS.LVM_GETITEMRECT, 0, rect);
- ignoreCustomDraw = false;
- if (code != 0) {
- pinfo.x = rect.left;
- /*
- * Bug in Windows. When LVM_SUBITEMHITTEST is used to hittest
- * a point that is above the table, instead of returning -1 to
- * indicate that the hittest failed, a negative index is returned.
- * The fix is to consider any value that is negative a failure.
- */
- OS.SendMessage (handle, OS.LVM_SUBITEMHITTEST, 0, pinfo);
- if (pinfo.iItem < 0) pinfo.iItem = -1;
- }
- }
- if (pinfo.iItem != -1 && pinfo.iSubItem == 0) {
- if (hitTestSelection (pinfo.iItem, pinfo.x, pinfo.y)) {
- return _getItem (pinfo.iItem);
- }
- }
- return null;
- }
- }
- OS.SendMessage (handle, OS.LVM_HITTEST, 0, pinfo);
- if (pinfo.iItem != -1) {
- /*
- * Bug in Windows. When the point that is used by
- * LVM_HITTEST is inside the header, Windows returns
- * the first item in the table. The fix is to check
- * when LVM_HITTEST returns the first item and make
- * sure that when the point is within the header,
- * the first item is not returned.
- */
- if (pinfo.iItem == 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.LVS_NOCOLUMNHEADER) == 0) {
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (hwndHeader != 0) {
- RECT rect = new RECT ();
- OS.GetWindowRect (hwndHeader, rect);
- POINT pt = new POINT ();
- pt.x = pinfo.x;
- pt.y = pinfo.y;
- OS.MapWindowPoints (handle, 0, pt, 1);
- if (OS.PtInRect (rect, pt)) return null;
- }
- }
- }
- return _getItem (pinfo.iItem);
- }
- return null;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the receiver.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- if (!painted && hooks (SWT.MeasureItem)) hitTestSelection (0, 0, 0);
- int /*long*/ empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0);
- int /*long*/ oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0);
- return OS.HIWORD (oneItem) - OS.HIWORD (empty);
-}
-
-/**
- * Returns a (possibly empty) array of <code>TableItem</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem [] getItems () {
- checkWidget ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- TableItem [] result = new TableItem [count];
- if ((style & SWT.VIRTUAL) != 0) {
- for (int i=0; i<count; i++) {
- result [i] = _getItem (i);
- }
- } else {
- System.arraycopy (items, 0, result, 0, count);
- }
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver's lines are visible,
- * and <code>false</code> otherwise. Note that some platforms draw
- * grid lines while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the visibility state of the lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getLinesVisible () {
- checkWidget ();
- int bits = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- return (bits & OS.LVS_EX_GRIDLINES) != 0;
-}
-
-/**
- * Returns an array of <code>TableItem</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem [] getSelection () {
- checkWidget ();
- int i = -1, j = 0, count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSELECTEDCOUNT, 0, 0);
- TableItem [] result = new TableItem [count];
- while ((i = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, i, OS.LVNI_SELECTED)) != -1) {
- result [j++] = _getItem (i);
- }
- return result;
-}
-
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSELECTEDCOUNT, 0, 0);
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget ();
- int focusIndex = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);
- int selectedIndex = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_SELECTED);
- if (focusIndex == selectedIndex) return selectedIndex;
- int i = -1;
- while ((i = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, i, OS.LVNI_SELECTED)) != -1) {
- if (i == focusIndex) return i;
- }
- return selectedIndex;
-}
-
-/**
- * Returns the zero-relative indices of the items which are currently
- * selected in the receiver. The order of the indices is unspecified.
- * The array is empty if no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return the array of indices of the selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int [] getSelectionIndices () {
- checkWidget ();
- int i = -1, j = 0, count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSELECTEDCOUNT, 0, 0);
- int [] result = new int [count];
- while ((i = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, i, OS.LVNI_SELECTED)) != -1) {
- result [j++] = i;
- }
- return result;
-}
-
-/**
- * Returns the column which shows the sort indicator for
- * the receiver. The value may be null if no column shows
- * the sort indicator.
- *
- * @return the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortColumn(TableColumn)
- *
- * @since 3.2
- */
-public TableColumn getSortColumn () {
- checkWidget ();
- return sortColumn;
-}
-
-int getSortColumnPixel () {
- int pixel = OS.IsWindowEnabled (handle) ? getBackgroundPixel () : OS.GetSysColor (OS.COLOR_3DFACE);
- int red = pixel & 0xFF;
- int green = (pixel & 0xFF00) >> 8;
- int blue = (pixel & 0xFF0000) >> 16;
- if (red > 240 && green > 240 && blue > 240) {
- red -= 8;
- green -= 8;
- blue -= 8;
- } else {
- red = Math.min (0xFF, (red / 10) + red);
- green = Math.min (0xFF, (green / 10) + green);
- blue = Math.min (0xFF, (blue / 10) + blue);
- }
- return (red & 0xFF) | ((green & 0xFF) << 8) | ((blue & 0xFF) << 16);
-}
-
-/**
- * Returns the direction of the sort indicator for the receiver.
- * The value will be one of <code>UP</code>, <code>DOWN</code>
- * or <code>NONE</code>.
- *
- * @return the sort direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortDirection(int)
- *
- * @since 3.2
- */
-public int getSortDirection () {
- checkWidget ();
- return sortDirection;
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items are
- * scrolled or new items are added or removed.
- *
- * @return the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget ();
- /*
- * Bug in Windows. Under rare circumstances, LVM_GETTOPINDEX
- * can return a negative number. When this happens, the table
- * is displaying blank lines at the top of the controls. The
- * fix is to check for a negative number and return zero instead.
- */
- return Math.max (0, (int)/*64*/OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0));
-}
-
-boolean hasChildren () {
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int /*long*/ hwndChild = OS.GetWindow (handle, OS.GW_CHILD);
- while (hwndChild != 0) {
- if (hwndChild != hwndHeader) return true;
- hwndChild = OS.GetWindow (hwndChild, OS.GW_HWNDNEXT);
- }
- return false;
-}
-
-boolean hitTestSelection (int index, int x, int y) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (count == 0) return false;
- if (!hooks (SWT.MeasureItem)) return false;
- boolean result = false;
- if (0 <= index && index < count) {
- TableItem item = _getItem (index);
- int /*long*/ hDC = OS.GetDC (handle);
- int /*long*/ oldFont = 0, newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- int /*long*/ hFont = item.fontHandle (0);
- if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
- Event event = sendMeasureItemEvent (item, index, 0, hDC);
- if (event.getBounds ().contains (x, y)) result = true;
- if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
-// if (isDisposed () || item.isDisposed ()) return false;
- }
- return result;
-}
-
-int imageIndex (Image image, int column) {
- if (image == null) return OS.I_IMAGENONE;
- if (column == 0) {
- firstColumnImage = true;
- } else {
- setSubImagesVisible (true);
- }
- if (imageList == null) {
- Rectangle bounds = image.getBounds ();
- imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height);
- int index = imageList.indexOf (image);
- if (index == -1) index = imageList.add (image);
- int /*long*/ hImageList = imageList.getHandle ();
- /*
- * Bug in Windows. Making any change to an item that
- * changes the item height of a table while the table
- * is scrolled can cause the lines to draw incorrectly.
- * This happens even when the lines are not currently
- * visible and are shown afterwards. The fix is to
- * save the top index, scroll to the top of the table
- * and then restore the original top index.
- */
- int topIndex = getTopIndex ();
- if (topIndex != 0) {
- setRedraw (false);
- setTopIndex (0);
- }
- OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, hImageList);
- if (headerImageList != null) {
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int /*long*/ hHeaderImageList = headerImageList.getHandle ();
- OS.SendMessage (hwndHeader, OS.HDM_SETIMAGELIST, 0, hHeaderImageList);
- }
- fixCheckboxImageList (false);
- if (itemHeight != -1) setItemHeight (false);
- if (topIndex != 0) {
- setTopIndex (topIndex);
- setRedraw (true);
- }
- return index;
- }
- int index = imageList.indexOf (image);
- if (index != -1) return index;
- return imageList.add (image);
-}
-
-int imageIndexHeader (Image image) {
- if (image == null) return OS.I_IMAGENONE;
- if (headerImageList == null) {
- Rectangle bounds = image.getBounds ();
- headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height);
- int index = headerImageList.indexOf (image);
- if (index == -1) index = headerImageList.add (image);
- int /*long*/ hImageList = headerImageList.getHandle ();
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- OS.SendMessage (hwndHeader, OS.HDM_SETIMAGELIST, 0, hImageList);
- return index;
- }
- int index = headerImageList.indexOf (image);
- if (index != -1) return index;
- return headerImageList.add (image);
-}
-
-/**
- * Searches the receiver's list starting at the first column
- * (index 0) until a column is found that is equal to the
- * argument, and returns the index of that column. If no column
- * is found, returns -1.
- *
- * @param column the search column
- * @return the index of the column
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the column is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (TableColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<columnCount; i++) {
- if (columns [i] == column) return i;
- }
- return -1;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (TableItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (1 <= lastIndexOf && lastIndexOf < count - 1) {
- if (items [lastIndexOf] == item) return lastIndexOf;
- if (items [lastIndexOf + 1] == item) return ++lastIndexOf;
- if (items [lastIndexOf - 1] == item) return --lastIndexOf;
- }
- if (lastIndexOf < count / 2) {
- for (int i=0; i<count; i++) {
- if (items [i] == item) return lastIndexOf = i;
- }
- } else {
- for (int i=count - 1; i>=0; --i) {
- if (items [i] == item) return lastIndexOf = i;
- }
- }
- return -1;
-}
-
-boolean isCustomToolTip () {
- return hooks (SWT.MeasureItem);
-}
-
-boolean isOptimizedRedraw () {
- if ((style & SWT.H_SCROLL) == 0 || (style & SWT.V_SCROLL) == 0) return false;
- return !hasChildren () && !hooks (SWT.Paint) && !filters (SWT.Paint);
-}
-
-/**
- * Returns <code>true</code> if the item is selected,
- * and <code>false</code> otherwise. Indices out of
- * range are ignored.
- *
- * @param index the index of the item
- * @return the selection state of the item at the index
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isSelected (int index) {
- checkWidget ();
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.stateMask = OS.LVIS_SELECTED;
- lvItem.iItem = index;
- int /*long*/ result = OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);
- return (result != 0) && ((lvItem.state & OS.LVIS_SELECTED) != 0);
-}
-
-void register () {
- super.register ();
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (hwndHeader != 0) display.addControl (hwndHeader, this);
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- int itemCount = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- /*
- * Feature in Windows 98. When there are a large number
- * of columns and items in a table (>1000) where each
- * of the subitems in the table has a string, it is much
- * faster to delete each item with LVM_DELETEITEM rather
- * than using LVM_DELETEALLITEMS. The fix is to detect
- * this case and delete the items, one by one. The fact
- * that the fix is only necessary on Windows 98 was
- * confirmed using version 5.81 of COMCTL32.DLL on both
- * Windows 98 and NT.
- *
- * NOTE: LVM_DELETEALLITEMS is also sent by the table
- * when the table is destroyed.
- */
- if (OS.IsWin95 && columnCount > 1) {
- /* Turn off redraw and resize events and leave them off */
- resizeCount = 1;
- OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- for (int i=itemCount-1; i>=0; --i) {
- TableItem item = items [i];
- if (item != null && !item.isDisposed ()) item.release (false);
- ignoreSelect = ignoreShrink = true;
- OS.SendMessage (handle, OS.LVM_DELETEITEM, i, 0);
- ignoreSelect = ignoreShrink = false;
- }
- } else {
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (item != null && !item.isDisposed ()) item.release (false);
- }
- }
- items = null;
- }
- if (columns != null) {
- for (int i=0; i<columnCount; i++) {
- TableColumn column = columns [i];
- if (!column.isDisposed ()) column.release (false);
- }
- columns = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- customDraw = false;
- currentItem = null;
- if (imageList != null) {
- OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);
- display.releaseImageList (imageList);
- }
- if (headerImageList != null) {
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- OS.SendMessage (hwndHeader, OS.HDM_SETIMAGELIST, 0, 0);
- display.releaseImageList (headerImageList);
- }
- imageList = headerImageList = null;
- int /*long*/ hStateList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);
- OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_STATE, 0);
- if (hStateList != 0) OS.ImageList_Destroy (hStateList);
- if (headerToolTipHandle != 0) OS.DestroyWindow (headerToolTipHandle);
- headerToolTipHandle = 0;
-}
-
-/**
- * Removes the items from the receiver's list at the given
- * zero-relative indices.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- int [] newIndices = new int [indices.length];
- System.arraycopy (indices, 0, newIndices, 0, indices.length);
- sort (newIndices);
- int start = newIndices [newIndices.length - 1], end = newIndices [0];
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (!(0 <= start && start <= end && end < count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- setDeferResize (true);
- int last = -1;
- for (int i=0; i<newIndices.length; i++) {
- int index = newIndices [i];
- if (index != last) {
- TableItem item = items [index];
- if (item != null && !item.isDisposed ()) item.release (false);
- ignoreSelect = ignoreShrink = true;
- int /*long*/ code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0);
- ignoreSelect = ignoreShrink = false;
- if (code == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
- System.arraycopy (items, index + 1, items, index, --count - index);
- items [count] = null;
- last = index;
- }
- }
- if (count == 0) setTableEmpty ();
- setDeferResize (false);
-}
-
-/**
- * Removes the item from the receiver at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
- TableItem item = items [index];
- if (item != null && !item.isDisposed ()) item.release (false);
- setDeferResize (true);
- ignoreSelect = ignoreShrink = true;
- int /*long*/ code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0);
- ignoreSelect = ignoreShrink = false;
- if (code == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
- System.arraycopy (items, index + 1, items, index, --count - index);
- items [count] = null;
- if (count == 0) setTableEmpty ();
- setDeferResize (false);
-}
-
-/**
- * Removes the items from the receiver which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget ();
- if (start > end) return;
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (!(0 <= start && start <= end && end < count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- if (start == 0 && end == count - 1) {
- removeAll ();
- } else {
- setDeferResize (true);
- int index = start;
- while (index <= end) {
- TableItem item = items [index];
- if (item != null && !item.isDisposed ()) item.release (false);
- ignoreSelect = ignoreShrink = true;
- int /*long*/ code = OS.SendMessage (handle, OS.LVM_DELETEITEM, start, 0);
- ignoreSelect = ignoreShrink = false;
- if (code == 0) break;
- index++;
- }
- System.arraycopy (items, index, items, start, count - index);
- for (int i=count-(index-start); i<count; i++) items [i] = null;
- if (index <= end) error (SWT.ERROR_ITEM_NOT_REMOVED);
- /*
- * This code is intentionally commented. It is not necessary
- * to check for an empty table because removeAll() was called
- * when the start == 0 and end == count - 1.
- */
- //if (count - index == 0) setTableEmpty ();
- setDeferResize (false);
- }
-}
-
-/**
- * Removes all of the items from the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget ();
- int itemCount = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (item != null && !item.isDisposed ()) item.release (false);
- }
- /*
- * Feature in Windows 98. When there are a large number
- * of columns and items in a table (>1000) where each
- * of the subitems in the table has a string, it is much
- * faster to delete each item with LVM_DELETEITEM rather
- * than using LVM_DELETEALLITEMS. The fix is to detect
- * this case and delete the items, one by one. The fact
- * that the fix is only necessary on Windows 98 was
- * confirmed using version 5.81 of COMCTL32.DLL on both
- * Windows 98 and NT.
- *
- * NOTE: LVM_DELETEALLITEMS is also sent by the table
- * when the table is destroyed.
- */
- setDeferResize (true);
- if (OS.IsWin95 && columnCount > 1) {
- boolean redraw = getDrawing () && OS.IsWindowVisible (handle);
- if (redraw) OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- int index = itemCount - 1;
- while (index >= 0) {
- ignoreSelect = ignoreShrink = true;
- int /*long*/ code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0);
- ignoreSelect = ignoreShrink = false;
- if (code == 0) break;
- --index;
- }
- if (redraw) {
- OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
- /*
- * This code is intentionally commented. The window proc
- * for the table implements WM_SETREDRAW to invalidate
- * and erase the table so it is not necessary to do this
- * again.
- */
-// int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE;
-// OS.RedrawWindow (handle, null, 0, flags);
- }
- if (index != -1) error (SWT.ERROR_ITEM_NOT_REMOVED);
- } else {
- ignoreSelect = ignoreShrink = true;
- int /*long*/ code = OS.SendMessage (handle, OS.LVM_DELETEALLITEMS, 0, 0);
- ignoreSelect = ignoreShrink = false;
- if (code == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- setTableEmpty ();
- setDeferResize (false);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener(SelectionListener)
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If the item at a given index is not selected, it is selected.
- * If the item at a given index was already selected, it remains selected.
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- * </p>
- *
- * @param indices the array of indices for the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setSelection(int[])
- */
-public void select (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- LVITEM lvItem = new LVITEM ();
- lvItem.state = OS.LVIS_SELECTED;
- lvItem.stateMask = OS.LVIS_SELECTED;
- for (int i=length-1; i>=0; --i) {
- /*
- * An index of -1 will apply the change to all
- * items. Ensure that indices are greater than -1.
- */
- if (indices [i] >= 0) {
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_SETITEMSTATE, indices [i], lvItem);
- ignoreSelect = false;
- }
- }
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget ();
- /*
- * An index of -1 will apply the change to all
- * items. Ensure that index is greater than -1.
- */
- if (index < 0) return;
- LVITEM lvItem = new LVITEM ();
- lvItem.state = OS.LVIS_SELECTED;
- lvItem.stateMask = OS.LVIS_SELECTED;
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_SETITEMSTATE, index, lvItem);
- ignoreSelect = false;
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If an item in the given range is not selected, it is selected.
- * If an item in the given range was already selected, it remains selected.
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setSelection(int,int)
- */
-public void select (int start, int end) {
- checkWidget ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (count == 0 || start >= count) return;
- start = Math.max (0, start);
- end = Math.min (end, count - 1);
- if (start == 0 && end == count - 1) {
- selectAll ();
- } else {
- /*
- * An index of -1 will apply the change to all
- * items. Indices must be greater than -1.
- */
- LVITEM lvItem = new LVITEM ();
- lvItem.state = OS.LVIS_SELECTED;
- lvItem.stateMask = OS.LVIS_SELECTED;
- for (int i=start; i<=end; i++) {
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_SETITEMSTATE, i, lvItem);
- ignoreSelect = false;
- }
- }
-}
-
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.state = OS.LVIS_SELECTED;
- lvItem.stateMask = OS.LVIS_SELECTED;
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_SETITEMSTATE, -1, lvItem);
- ignoreSelect = false;
-}
-
-void sendEraseItemEvent (TableItem item, NMLVCUSTOMDRAW nmcd, int /*long*/ lParam, Event measureEvent) {
- int /*long*/ hDC = nmcd.hdc;
- int clrText = item.cellForeground != null ? item.cellForeground [nmcd.iSubItem] : -1;
- if (clrText == -1) clrText = item.foreground;
- int clrTextBk = -1;
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- if (sortColumn != null && sortDirection != SWT.NONE) {
- if (findImageControl () == null) {
- if (indexOf (sortColumn) == nmcd.iSubItem) {
- clrTextBk = getSortColumnPixel ();
- }
- }
- }
- }
- clrTextBk = item.cellBackground != null ? item.cellBackground [nmcd.iSubItem] : -1;
- if (clrTextBk == -1) clrTextBk = item.background;
- /*
- * Bug in Windows. For some reason, CDIS_SELECTED always set,
- * even for items that are not selected. The fix is to get
- * the selection state from the item.
- */
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.stateMask = OS.LVIS_SELECTED;
- lvItem.iItem = (int)/*64*/nmcd.dwItemSpec;
- int /*long*/ result = OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);
- boolean selected = (result != 0 && (lvItem.state & OS.LVIS_SELECTED) != 0);
- GCData data = new GCData ();
- data.device = display;
- int clrSelectionBk = -1;
- boolean drawSelected = false, drawBackground = false, drawHot = false;
- if (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0) {
- drawHot = hotIndex == nmcd.dwItemSpec;
- }
- if (OS.IsWindowEnabled (handle)) {
- if (selected && (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0)) {
- if (OS.GetFocus () == handle || display.getHighContrast ()) {
- drawSelected = true;
- data.foreground = OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT);
- data.background = clrSelectionBk = OS.GetSysColor (OS.COLOR_HIGHLIGHT);
- } else {
- drawSelected = (style & SWT.HIDE_SELECTION) == 0;
- data.foreground = OS.GetTextColor (hDC);
- data.background = clrSelectionBk = OS.GetSysColor (OS.COLOR_3DFACE);
- }
- if (explorerTheme) {
- data.foreground = clrText != -1 ? clrText : getForegroundPixel ();
- }
- } else {
- drawBackground = clrTextBk != -1;
- /*
- * Bug in Windows. When LVM_SETTEXTBKCOLOR, LVM_SETBKCOLOR
- * or LVM_SETTEXTCOLOR is used to set the background color of
- * the the text or the control, the color is not set in the HDC
- * that is provided in Custom Draw. The fix is to explicitly
- * set the color.
- */
- if (clrText == -1 || clrTextBk == -1) {
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- if (clrText == -1) clrText = control.getForegroundPixel ();
- if (clrTextBk == -1) clrTextBk = control.getBackgroundPixel ();
- }
- data.foreground = clrText != -1 ? clrText : OS.GetTextColor (hDC);
- data.background = clrTextBk != -1 ? clrTextBk : OS.GetBkColor (hDC);
- }
- } else {
- data.foreground = OS.GetSysColor (OS.COLOR_GRAYTEXT);
- data.background = OS.GetSysColor (OS.COLOR_3DFACE);
- if (selected) clrSelectionBk = data.background;
- }
- data.font = item.getFont (nmcd.iSubItem);
- data.uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- int nSavedDC = OS.SaveDC (hDC);
- GC gc = GC.win32_new (hDC, data);
- RECT cellRect = item.getBounds ((int)/*64*/nmcd.dwItemSpec, nmcd.iSubItem, true, true, true, true, hDC);
- Event event = new Event ();
- event.item = item;
- event.gc = gc;
- event.index = nmcd.iSubItem;
- event.detail |= SWT.FOREGROUND;
-// if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) {
- if (OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED) == nmcd.dwItemSpec) {
- if (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0) {
- if (handle == OS.GetFocus ()) {
- int uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- if ((uiState & OS.UISF_HIDEFOCUS) == 0) event.detail |= SWT.FOCUSED;
- }
- }
- }
- boolean focused = (event.detail & SWT.FOCUSED) != 0;
- if (drawHot) event.detail |= SWT.HOT;
- if (drawSelected) event.detail |= SWT.SELECTED;
- if (drawBackground) event.detail |= SWT.BACKGROUND;
- event.x = cellRect.left;
- event.y = cellRect.top;
- event.width = cellRect.right - cellRect.left;
- event.height = cellRect.bottom - cellRect.top;
- gc.setClipping (event.x, event.y, event.width, event.height);
- sendEvent (SWT.EraseItem, event);
- event.gc = null;
- int clrSelectionText = data.foreground;
- gc.dispose ();
- OS.RestoreDC (hDC, nSavedDC);
- if (isDisposed () || item.isDisposed ()) return;
- if (event.doit) {
- ignoreDrawForeground = (event.detail & SWT.FOREGROUND) == 0;
- ignoreDrawBackground = (event.detail & SWT.BACKGROUND) == 0;
- ignoreDrawSelection = (event.detail & SWT.SELECTED) == 0;
- ignoreDrawFocus = (event.detail & SWT.FOCUSED) == 0;
- ignoreDrawHot = (event.detail & SWT.HOT) == 0;
- } else {
- ignoreDrawForeground = ignoreDrawBackground = ignoreDrawSelection = ignoreDrawFocus = ignoreDrawHot = true;
- }
- if (drawSelected) {
- if (ignoreDrawSelection) {
- ignoreDrawHot = true;
- if (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0) {
- selectionForeground = clrSelectionText;
- }
- nmcd.uItemState &= ~OS.CDIS_SELECTED;
- OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof);
- }
- } else {
- if (ignoreDrawSelection) {
- nmcd.uItemState |= OS.CDIS_SELECTED;
- OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof);
- }
- }
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- boolean firstColumn = nmcd.iSubItem == OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0);
- if (ignoreDrawForeground && ignoreDrawHot) {
- if (!ignoreDrawBackground && drawBackground) {
- RECT backgroundRect = item.getBounds ((int)/*64*/nmcd.dwItemSpec, nmcd.iSubItem, true, false, true, false, hDC);
- fillBackground (hDC, clrTextBk, backgroundRect);
- }
- }
- focusRect = null;
- if (!ignoreDrawHot || !ignoreDrawSelection || !ignoreDrawFocus) {
- boolean fullText = (style & SWT.FULL_SELECTION) != 0 || !firstColumn;
- RECT textRect = item.getBounds ((int)/*64*/nmcd.dwItemSpec, nmcd.iSubItem, true, false, fullText, false, hDC);
- if ((style & SWT.FULL_SELECTION) == 0) {
- if (measureEvent != null) {
- textRect.right = Math.min (cellRect.right, measureEvent.x + measureEvent.width);
- }
- if (!ignoreDrawFocus) {
- nmcd.uItemState &= ~OS.CDIS_FOCUS;
- OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof);
- focusRect = textRect;
- }
- }
- if (explorerTheme) {
- if (!ignoreDrawHot || (!ignoreDrawSelection && clrSelectionBk != -1)) {
- boolean hot = drawHot;
- RECT pClipRect = new RECT ();
- OS.SetRect (pClipRect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
- RECT rect = new RECT ();
- OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
- if ((style & SWT.FULL_SELECTION) != 0) {
- int count = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- int index = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, count - 1, 0);
- RECT headerRect = new RECT ();
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect);
- OS.MapWindowPoints (hwndHeader, handle, headerRect, 2);
- rect.left = 0;
- rect.right = headerRect.right;
- pClipRect.left = cellRect.left;
- pClipRect.right += EXPLORER_EXTRA;
- } else {
- rect.right += EXPLORER_EXTRA;
- pClipRect.right += EXPLORER_EXTRA;
- }
- int /*long*/ hTheme = OS.OpenThemeData (handle, Display.LISTVIEW);
- int iStateId = selected ? OS.LISS_SELECTED : OS.LISS_HOT;
- if (OS.GetFocus () != handle && selected && !hot) iStateId = OS.LISS_SELECTEDNOTFOCUS;
- OS.DrawThemeBackground (hTheme, hDC, OS.LVP_LISTITEM, iStateId, rect, pClipRect);
- OS.CloseThemeData (hTheme);
- }
- } else {
- if (!ignoreDrawSelection && clrSelectionBk != -1) fillBackground (hDC, clrSelectionBk, textRect);
- }
- }
- if (focused && ignoreDrawFocus) {
- nmcd.uItemState &= ~OS.CDIS_FOCUS;
- OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof);
- }
- if (ignoreDrawForeground) {
- RECT clipRect = item.getBounds ((int)/*64*/nmcd.dwItemSpec, nmcd.iSubItem, true, true, true, false, hDC);
- OS.SaveDC (hDC);
- OS.SelectClipRgn (hDC, 0);
- OS.ExcludeClipRect (hDC, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
- }
-}
-
-Event sendEraseItemEvent (TableItem item, NMTTCUSTOMDRAW nmcd, int column, RECT cellRect) {
- int nSavedDC = OS.SaveDC (nmcd.hdc);
- RECT insetRect = toolTipInset (cellRect);
- OS.SetWindowOrgEx (nmcd.hdc, insetRect.left, insetRect.top, null);
- GCData data = new GCData ();
- data.device = display;
- data.foreground = OS.GetTextColor (nmcd.hdc);
- data.background = OS.GetBkColor (nmcd.hdc);
- data.font = item.getFont (column);
- data.uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- GC gc = GC.win32_new (nmcd.hdc, data);
- Event event = new Event ();
- event.item = item;
- event.index = column;
- event.gc = gc;
- event.detail |= SWT.FOREGROUND;
- event.x = cellRect.left;
- event.y = cellRect.top;
- event.width = cellRect.right - cellRect.left;
- event.height = cellRect.bottom - cellRect.top;
- //gc.setClipping (event.x, event.y, event.width, event.height);
- sendEvent (SWT.EraseItem, event);
- event.gc = null;
- //int newTextClr = data.foreground;
- gc.dispose ();
- OS.RestoreDC (nmcd.hdc, nSavedDC);
- return event;
-}
-
-Event sendMeasureItemEvent (TableItem item, int row, int column, int /*long*/ hDC) {
- GCData data = new GCData ();
- data.device = display;
- data.font = item.getFont (column);
- int nSavedDC = OS.SaveDC (hDC);
- GC gc = GC.win32_new (hDC, data);
- RECT itemRect = item.getBounds (row, column, true, true, false, false, hDC);
- Event event = new Event ();
- event.item = item;
- event.gc = gc;
- event.index = column;
- event.x = itemRect.left;
- event.y = itemRect.top;
- event.width = itemRect.right - itemRect.left;
- event.height = itemRect.bottom - itemRect.top;
- sendEvent (SWT.MeasureItem, event);
- event.gc = null;
- gc.dispose ();
- OS.RestoreDC (hDC, nSavedDC);
- if (!isDisposed () && !item.isDisposed ()) {
- if (columnCount == 0) {
- int width = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, 0, 0);
- if (event.x + event.width > width) setScrollWidth (event.x + event.width);
- }
- int /*long*/ empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0);
- int /*long*/ oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0);
- int itemHeight = OS.HIWORD (oneItem) - OS.HIWORD (empty);
- if (event.height > itemHeight) setItemHeight (event.height);
- }
- return event;
-}
-
-LRESULT sendMouseDownEvent (int type, int button, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- Display display = this.display;
- display.captureChanged = false;
- if (!sendMouseEvent (type, button, handle, msg, wParam, lParam)) {
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- return LRESULT.ZERO;
- }
-
- /*
- * Feature in Windows. Inside WM_LBUTTONDOWN and WM_RBUTTONDOWN,
- * the widget starts a modal loop to determine if the user wants
- * to begin a drag/drop operation or marque select. Unfortunately,
- * this modal loop eats the corresponding mouse up. The fix is to
- * detect the cases when the modal loop has eaten the mouse up and
- * issue a fake mouse up.
- *
- * By observation, when the mouse is clicked anywhere but the check
- * box, the widget eats the mouse up. When the mouse is dragged,
- * the widget does not eat the mouse up.
- */
- LVHITTESTINFO pinfo = new LVHITTESTINFO ();
- pinfo.x = OS.GET_X_LPARAM (lParam);
- pinfo.y = OS.GET_Y_LPARAM (lParam);
- OS.SendMessage (handle, OS.LVM_HITTEST, 0, pinfo);
- if ((style & SWT.FULL_SELECTION) == 0) {
- if (hooks (SWT.MeasureItem)) {
- /*
- * Bug in Windows. When LVM_SUBITEMHITTEST is used to hittest
- * a point that is above the table, instead of returning -1 to
- * indicate that the hittest failed, a negative index is returned.
- * The fix is to consider any value that is negative a failure.
- */
- if (OS.SendMessage (handle, OS.LVM_SUBITEMHITTEST, 0, pinfo) < 0) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (count != 0) {
- RECT rect = new RECT ();
- rect.left = OS.LVIR_ICON;
- ignoreCustomDraw = true;
- int /*long*/ code = OS.SendMessage (handle, OS.LVM_GETITEMRECT, 0, rect);
- ignoreCustomDraw = false;
- if (code != 0) {
- pinfo.x = rect.left;
- /*
- * Bug in Windows. When LVM_SUBITEMHITTEST is used to hittest
- * a point that is above the table, instead of returning -1 to
- * indicate that the hittest failed, a negative index is returned.
- * The fix is to consider any value that is negative a failure.
- */
- OS.SendMessage (handle, OS.LVM_SUBITEMHITTEST, 0, pinfo);
- if (pinfo.iItem < 0) pinfo.iItem = -1;
- pinfo.flags &= ~(OS.LVHT_ONITEMICON | OS.LVHT_ONITEMLABEL);
- }
- }
- } else {
- if (pinfo.iSubItem != 0) pinfo.iItem = -1;
- }
- }
- }
-
- /*
- * Force the table to have focus so that when the user
- * reselects the focus item, the LVIS_FOCUSED state bits
- * for the item will be set. If the user did not click on
- * an item, then set focus to the table so that it will
- * come to the front and take focus in the work around
- * below.
- */
- OS.SetFocus (handle);
-
- /*
- * Feature in Windows. When the user selects outside of
- * a table item, Windows deselects all the items, even
- * when the table is multi-select. While not strictly
- * wrong, this is unexpected. The fix is to detect the
- * case and avoid calling the window proc.
- */
- if ((style & SWT.SINGLE) != 0 || hooks (SWT.MouseDown) || hooks (SWT.MouseUp)) {
- if (pinfo.iItem == -1) {
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- return LRESULT.ZERO;
- }
- }
-
- /*
- * Feature in Windows. When a table item is reselected
- * in a single-select table, Windows does not issue a
- * WM_NOTIFY because the item state has not changed.
- * This is strictly correct but is inconsistent with the
- * list widget and other widgets in Windows. The fix is
- * to detect the case when an item is reselected and mark
- * it as selected.
- */
- boolean forceSelect = false;
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSELECTEDCOUNT, 0, 0);
- if (count == 1 && pinfo.iItem != -1) {
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.stateMask = OS.LVIS_SELECTED;
- lvItem.iItem = pinfo.iItem;
- OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);
- if ((lvItem.state & OS.LVIS_SELECTED) != 0) {
- forceSelect = true;
- }
- }
-
- /* Determine whether the user has selected an item based on SWT.MeasureItem */
- fullRowSelect = false;
- if (pinfo.iItem != -1) {
- if ((style & SWT.FULL_SELECTION) == 0) {
- if (hooks (SWT.MeasureItem)) {
- fullRowSelect = hitTestSelection (pinfo.iItem, pinfo.x, pinfo.y);
- if (fullRowSelect) {
- int flags = OS.LVHT_ONITEMICON | OS.LVHT_ONITEMLABEL;
- if ((pinfo.flags & flags) != 0) fullRowSelect = false;
- }
- }
- }
- }
-
- /*
- * Feature in Windows. Inside WM_LBUTTONDOWN and WM_RBUTTONDOWN,
- * the widget starts a modal loop to determine if the user wants
- * to begin a drag/drop operation or marque select. This modal
- * loop eats mouse events until a drag is detected. The fix is
- * to avoid this behavior by only running the drag and drop when
- * the event is hooked and the mouse is over an item.
- */
- boolean dragDetect = (state & DRAG_DETECT) != 0 && hooks (SWT.DragDetect);
- if (!dragDetect) {
- int flags = OS.LVHT_ONITEMICON | OS.LVHT_ONITEMLABEL;
- dragDetect = pinfo.iItem == -1 || (pinfo.flags & flags) == 0;
- if (fullRowSelect) dragDetect = true;
- }
-
- /*
- * Temporarily set LVS_EX_FULLROWSELECT to allow drag and drop
- * and the mouse to manipulate items based on the results of
- * the SWT.MeasureItem event.
- */
- if (fullRowSelect) {
- OS.UpdateWindow (handle);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, OS.LVS_EX_FULLROWSELECT, OS.LVS_EX_FULLROWSELECT);
- }
- dragStarted = false;
- display.dragCancelled = false;
- if (!dragDetect) display.runDragDrop = false;
- int /*long*/ code = callWindowProc (handle, msg, wParam, lParam, forceSelect);
- if (!dragDetect) display.runDragDrop = true;
- if (fullRowSelect) {
- fullRowSelect = false;
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, OS.LVS_EX_FULLROWSELECT, 0);
- }
-
- if (dragStarted || display.dragCancelled) {
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- } else {
- int flags = OS.LVHT_ONITEMLABEL | OS.LVHT_ONITEMICON;
- boolean fakeMouseUp = (pinfo.flags & flags) != 0;
- if (!fakeMouseUp && (style & SWT.MULTI) != 0) {
- fakeMouseUp = (pinfo.flags & OS.LVHT_ONITEMSTATEICON) == 0;
- }
- if (fakeMouseUp) {
- sendMouseEvent (SWT.MouseUp, button, handle, msg, wParam, lParam);
- }
- }
- return new LRESULT (code);
-}
-
-void sendPaintItemEvent (TableItem item, NMLVCUSTOMDRAW nmcd) {
- int /*long*/ hDC = nmcd.hdc;
- GCData data = new GCData ();
- data.device = display;
- data.font = item.getFont (nmcd.iSubItem);
- /*
- * Bug in Windows. For some reason, CDIS_SELECTED always set,
- * even for items that are not selected. The fix is to get
- * the selection state from the item.
- */
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.stateMask = OS.LVIS_SELECTED;
- lvItem.iItem = (int)/*64*/nmcd.dwItemSpec;
- int /*long*/ result = OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);
- boolean selected = result != 0 && (lvItem.state & OS.LVIS_SELECTED) != 0;
- boolean drawSelected = false, drawBackground = false, drawHot = false;
- if (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0) {
- drawHot = hotIndex == nmcd.dwItemSpec;
- }
- if (OS.IsWindowEnabled (handle)) {
- if (selected && (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0)) {
- if (OS.GetFocus () == handle || display.getHighContrast ()) {
- drawSelected = true;
- if (selectionForeground != -1) {
- data.foreground = selectionForeground;
- } else {
- data.foreground = OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT);
- }
- data.background = OS.GetSysColor (OS.COLOR_HIGHLIGHT);
- } else {
- drawSelected = (style & SWT.HIDE_SELECTION) == 0;
- data.foreground = OS.GetTextColor (hDC);
- data.background = OS.GetSysColor (OS.COLOR_3DFACE);
- }
- if (explorerTheme && selectionForeground == -1) {
- int clrText = item.cellForeground != null ? item.cellForeground [nmcd.iSubItem] : -1;
- if (clrText == -1) clrText = item.foreground;
- data.foreground = clrText != -1 ? clrText : getForegroundPixel ();
- }
- } else {
- int clrText = item.cellForeground != null ? item.cellForeground [nmcd.iSubItem] : -1;
- if (clrText == -1) clrText = item.foreground;
- int clrTextBk = item.cellBackground != null ? item.cellBackground [nmcd.iSubItem] : -1;
- if (clrTextBk == -1) clrTextBk = item.background;
- drawBackground = clrTextBk != -1;
- /*
- * Bug in Windows. When LVM_SETTEXTBKCOLOR, LVM_SETBKCOLOR
- * or LVM_SETTEXTCOLOR is used to set the background color of
- * the the text or the control, the color is not set in the HDC
- * that is provided in Custom Draw. The fix is to explicitly
- * set the color.
- */
- if (clrText == -1 || clrTextBk == -1) {
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- if (clrText == -1) clrText = control.getForegroundPixel ();
- if (clrTextBk == -1) clrTextBk = control.getBackgroundPixel ();
- }
- data.foreground = clrText != -1 ? clrText : OS.GetTextColor (hDC);
- data.background = clrTextBk != -1 ? clrTextBk : OS.GetBkColor (hDC);
- }
- } else {
- data.foreground = OS.GetSysColor (OS.COLOR_GRAYTEXT);
- data.background = OS.GetSysColor (OS.COLOR_3DFACE);
- }
- data.uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- int nSavedDC = OS.SaveDC (hDC);
- GC gc = GC.win32_new (hDC, data);
- RECT itemRect = item.getBounds ((int)/*64*/nmcd.dwItemSpec, nmcd.iSubItem, true, true, false, false, hDC);
- Event event = new Event ();
- event.item = item;
- event.gc = gc;
- event.index = nmcd.iSubItem;
- event.detail |= SWT.FOREGROUND;
-// if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) {
- if (OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED) == nmcd.dwItemSpec) {
- if (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0) {
- if (handle == OS.GetFocus ()) {
- int uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- if ((uiState & OS.UISF_HIDEFOCUS) == 0) event.detail |= SWT.FOCUSED;
- }
- }
- }
- if (drawHot) event.detail |= SWT.HOT;
- if (drawSelected) event.detail |= SWT.SELECTED;
- if (drawBackground) event.detail |= SWT.BACKGROUND;
- event.x = itemRect.left;
- event.y = itemRect.top;
- event.width = itemRect.right - itemRect.left;
- event.height = itemRect.bottom - itemRect.top;
- RECT cellRect = item.getBounds ((int)/*64*/nmcd.dwItemSpec, nmcd.iSubItem, true, true, true, true, hDC);
- int cellWidth = cellRect.right - cellRect.left;
- int cellHeight = cellRect.bottom - cellRect.top;
- gc.setClipping (cellRect.left, cellRect.top, cellWidth, cellHeight);
- sendEvent (SWT.PaintItem, event);
- if (data.focusDrawn) focusRect = null;
- event.gc = null;
- gc.dispose ();
- OS.RestoreDC (hDC, nSavedDC);
-}
-
-Event sendPaintItemEvent (TableItem item, NMTTCUSTOMDRAW nmcd, int column, RECT itemRect) {
- int nSavedDC = OS.SaveDC (nmcd.hdc);
- RECT insetRect = toolTipInset (itemRect);
- OS.SetWindowOrgEx (nmcd.hdc, insetRect.left, insetRect.top, null);
- GCData data = new GCData ();
- data.device = display;
- data.font = item.getFont (column);
- data.foreground = OS.GetTextColor (nmcd.hdc);
- data.background = OS.GetBkColor (nmcd.hdc);
- data.uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- GC gc = GC.win32_new (nmcd.hdc, data);
- Event event = new Event ();
- event.item = item;
- event.index = column;
- event.gc = gc;
- event.detail |= SWT.FOREGROUND;
- event.x = itemRect.left;
- event.y = itemRect.top;
- event.width = itemRect.right - itemRect.left;
- event.height = itemRect.bottom - itemRect.top;
- //gc.setClipping (cellRect.left, cellRect.top, cellWidth, cellHeight);
- sendEvent (SWT.PaintItem, event);
- event.gc = null;
- gc.dispose ();
- OS.RestoreDC (nmcd.hdc, nSavedDC);
- return event;
-}
-
-void setBackgroundImage (int /*long*/ hBitmap) {
- super.setBackgroundImage (hBitmap);
- if (hBitmap != 0) {
- setBackgroundTransparent (true);
- } else {
- if (!hooks (SWT.MeasureItem) && !hooks (SWT.EraseItem) && !hooks (SWT.PaintItem)) {
- setBackgroundTransparent (false);
- }
- }
-}
-
-void setBackgroundPixel (int newPixel) {
- int oldPixel = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0);
- if (oldPixel != OS.CLR_NONE) {
- if (findImageControl () != null) return;
- if (newPixel == -1) newPixel = defaultBackground ();
- if (oldPixel != newPixel) {
- OS.SendMessage (handle, OS.LVM_SETBKCOLOR, 0, newPixel);
- OS.SendMessage (handle, OS.LVM_SETTEXTBKCOLOR, 0, newPixel);
- if ((style & SWT.CHECK) != 0) fixCheckboxImageListColor (true);
- }
- }
- /*
- * Feature in Windows. When the background color is changed,
- * the table does not redraw until the next WM_PAINT. The fix
- * is to force a redraw.
- */
- OS.InvalidateRect (handle, null, true);
-}
-
-void setBackgroundTransparent (boolean transparent) {
- /*
- * Bug in Windows. When the table has the extended style
- * LVS_EX_FULLROWSELECT and LVM_SETBKCOLOR is used with
- * CLR_NONE to make the table transparent, Windows draws
- * a black rectangle around the first column. The fix is
- * clear LVS_EX_FULLROWSELECT.
- *
- * Feature in Windows. When LVM_SETBKCOLOR is used with
- * CLR_NONE and LVM_SETSELECTEDCOLUMN is used to select
- * a column, Windows fills the column with the selection
- * color, drawing on top of the background image and any
- * other custom drawing. The fix is to clear the selected
- * column.
- */
- int oldPixel = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0);
- if (transparent) {
- if (oldPixel != OS.CLR_NONE) {
- /*
- * Bug in Windows. When the background color is changed,
- * the table does not redraw until the next WM_PAINT. The
- * fix is to force a redraw.
- */
- OS.SendMessage (handle, OS.LVM_SETBKCOLOR, 0, OS.CLR_NONE);
- OS.SendMessage (handle, OS.LVM_SETTEXTBKCOLOR, 0, OS.CLR_NONE);
- OS.InvalidateRect (handle, null, true);
-
- /* Clear LVS_EX_FULLROWSELECT */
- if (!explorerTheme && (style & SWT.FULL_SELECTION) != 0) {
- int bits = OS.LVS_EX_FULLROWSELECT;
- OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, bits, 0);
- }
-
- /* Clear LVM_SETSELECTEDCOLUMN */
- if ((sortDirection & (SWT.UP | SWT.DOWN)) != 0) {
- if (sortColumn != null && !sortColumn.isDisposed ()) {
- OS.SendMessage (handle, OS.LVM_SETSELECTEDCOLUMN, -1, 0);
- /*
- * Bug in Windows. When LVM_SETSELECTEDCOLUMN is set, Windows
- * does not redraw either the new or the previous selected column.
- * The fix is to force a redraw.
- */
- OS.InvalidateRect (handle, null, true);
- }
- }
- }
- } else {
- if (oldPixel == OS.CLR_NONE) {
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- if (control.backgroundImage == null) {
- int newPixel = control.getBackgroundPixel ();
- OS.SendMessage (handle, OS.LVM_SETBKCOLOR, 0, newPixel);
- OS.SendMessage (handle, OS.LVM_SETTEXTBKCOLOR, 0, newPixel);
- if ((style & SWT.CHECK) != 0) fixCheckboxImageListColor (true);
- OS.InvalidateRect (handle, null, true);
- }
-
- /* Set LVS_EX_FULLROWSELECT */
- if (!explorerTheme && (style & SWT.FULL_SELECTION) != 0) {
- if (!hooks (SWT.EraseItem) && !hooks (SWT.PaintItem)) {
- int bits = OS.LVS_EX_FULLROWSELECT;
- OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, bits, bits);
- }
- }
-
- /* Set LVM_SETSELECTEDCOLUMN */
- if ((sortDirection & (SWT.UP | SWT.DOWN)) != 0) {
- if (sortColumn != null && !sortColumn.isDisposed ()) {
- int column = indexOf (sortColumn);
- if (column != -1) {
- OS.SendMessage (handle, OS.LVM_SETSELECTEDCOLUMN, column, 0);
- /*
- * Bug in Windows. When LVM_SETSELECTEDCOLUMN is set, Windows
- * does not redraw either the new or the previous selected column.
- * The fix is to force a redraw.
- */
- OS.InvalidateRect (handle, null, true);
- }
- }
- }
- }
- }
-}
-
-void setBounds (int x, int y, int width, int height, int flags, boolean defer) {
- /*
- * Bug in Windows. If the table column widths are adjusted
- * in WM_SIZE or WM_POSITIONCHANGED using LVM_SETCOLUMNWIDTH
- * blank lines may be inserted at the top of the table. A
- * call to LVM_GETTOPINDEX will return a negative number (this
- * is an impossible result). Once the blank lines appear,
- * there seems to be no way to get rid of them, other than
- * destroying and recreating the table. The fix is to send
- * the resize notification after the size has been changed in
- * the operating system.
- *
- * NOTE: This does not fix the case when the user is resizing
- * columns dynamically. There is no fix for this case at this
- * time.
- */
- setDeferResize (true);
- super.setBounds (x, y, width, height, flags, false);
- setDeferResize (false);
-}
-
-/**
- * Sets the order that the items in the receiver should
- * be displayed in to the given argument which is described
- * in terms of the zero-relative ordering of when the items
- * were added.
- *
- * @param order the new order to display the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item order is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public void setColumnOrder (int [] order) {
- checkWidget ();
- if (order == null) error (SWT.ERROR_NULL_ARGUMENT);
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (columnCount == 0) {
- if (order.length != 0) error (SWT.ERROR_INVALID_ARGUMENT);
- return;
- }
- if (order.length != columnCount) error (SWT.ERROR_INVALID_ARGUMENT);
- int [] oldOrder = new int [columnCount];
- OS.SendMessage (handle, OS.LVM_GETCOLUMNORDERARRAY, columnCount, oldOrder);
- boolean reorder = false;
- boolean [] seen = new boolean [columnCount];
- for (int i=0; i<order.length; i++) {
- int index = order [i];
- if (index < 0 || index >= columnCount) error (SWT.ERROR_INVALID_RANGE);
- if (seen [index]) error (SWT.ERROR_INVALID_ARGUMENT);
- seen [index] = true;
- if (index != oldOrder [i]) reorder = true;
- }
- if (reorder) {
- RECT [] oldRects = new RECT [columnCount];
- for (int i=0; i<columnCount; i++) {
- oldRects [i] = new RECT ();
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, i, oldRects [i]);
- }
- OS.SendMessage (handle, OS.LVM_SETCOLUMNORDERARRAY, order.length, order);
- /*
- * Bug in Windows. When LVM_SETCOLUMNORDERARRAY is used to change
- * the column order, the header redraws correctly but the table does
- * not. The fix is to force a redraw.
- */
- OS.InvalidateRect (handle, null, true);
- TableColumn[] newColumns = new TableColumn [columnCount];
- System.arraycopy (columns, 0, newColumns, 0, columnCount);
- RECT newRect = new RECT ();
- for (int i=0; i<columnCount; i++) {
- TableColumn column = newColumns [i];
- if (!column.isDisposed ()) {
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, i, newRect);
- if (newRect.left != oldRects [i].left) {
- column.updateToolTip (i);
- column.sendEvent (SWT.Move);
- }
- }
- }
- }
-}
-
-void setCustomDraw (boolean customDraw) {
- if (this.customDraw == customDraw) return;
- if (!this.customDraw && customDraw && currentItem != null) {
- OS.InvalidateRect (handle, null, true);
- }
- this.customDraw = customDraw;
-}
-
-void setDeferResize (boolean defer) {
- if (defer) {
- if (resizeCount++ == 0) {
- wasResized = false;
- /*
- * Feature in Windows. When LVM_SETBKCOLOR is used with CLR_NONE
- * to make the background of the table transparent, drawing becomes
- * slow. The fix is to temporarily clear CLR_NONE when redraw is
- * turned off.
- */
- if (hooks (SWT.MeasureItem) || hooks (SWT.EraseItem) || hooks (SWT.PaintItem)) {
- if (drawCount++ == 0 && OS.IsWindowVisible (handle)) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- OS.SendMessage (handle, OS.LVM_SETBKCOLOR, 0, 0xFFFFFF);
- }
- }
- }
- } else {
- if (--resizeCount == 0) {
- if (hooks (SWT.MeasureItem) || hooks (SWT.EraseItem) || hooks (SWT.PaintItem)) {
- if (--drawCount == 0 /*&& OS.IsWindowVisible (handle)*/) {
- OS.SendMessage (handle, OS.LVM_SETBKCOLOR, 0, OS.CLR_NONE);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- if (OS.IsWinCE) {
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (hwndHeader != 0) OS.InvalidateRect (hwndHeader, null, true);
- OS.InvalidateRect (handle, null, true);
- } else {
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, null, 0, flags);
- }
- }
- }
- if (wasResized) {
- wasResized = false;
- setResizeChildren (false);
- sendEvent (SWT.Resize);
- if (isDisposed ()) return;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false, false);
- }
- setResizeChildren (true);
- }
- }
- }
-}
-
-void setCheckboxImageList (int width, int height, boolean fixScroll) {
- if ((style & SWT.CHECK) == 0) return;
- int count = 4, flags = 0;
- if (OS.IsWinCE) {
- flags |= OS.ILC_COLOR;
- } else {
- int /*long*/ hDC = OS.GetDC (handle);
- int bits = OS.GetDeviceCaps (hDC, OS.BITSPIXEL);
- int planes = OS.GetDeviceCaps (hDC, OS.PLANES);
- OS.ReleaseDC (handle, hDC);
- int depth = bits * planes;
- switch (depth) {
- case 4: flags |= OS.ILC_COLOR4; break;
- case 8: flags |= OS.ILC_COLOR8; break;
- case 16: flags |= OS.ILC_COLOR16; break;
- case 24: flags |= OS.ILC_COLOR24; break;
- case 32: flags |= OS.ILC_COLOR32; break;
- default: flags |= OS.ILC_COLOR; break;
- }
- }
- if ((style & SWT.RIGHT_TO_LEFT) != 0) flags |= OS.ILC_MIRROR;
- if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) flags |= OS.ILC_MASK;
- int /*long*/ hStateList = OS.ImageList_Create (width, height, flags, count, count);
- int /*long*/ hDC = OS.GetDC (handle);
- int /*long*/ memDC = OS.CreateCompatibleDC (hDC);
- int /*long*/ hBitmap = OS.CreateCompatibleBitmap (hDC, width * count, height);
- int /*long*/ hOldBitmap = OS.SelectObject (memDC, hBitmap);
- RECT rect = new RECT ();
- OS.SetRect (rect, 0, 0, width * count, height);
- int clrBackground;
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- clrBackground = control.getBackgroundPixel ();
- } else {
- clrBackground = 0x020000FF;
- if ((clrBackground & 0xFFFFFF) == OS.GetSysColor (OS.COLOR_WINDOW)) {
- clrBackground = 0x0200FF00;
- }
- }
- int /*long*/ hBrush = OS.CreateSolidBrush (clrBackground);
- OS.FillRect (memDC, rect, hBrush);
- OS.DeleteObject (hBrush);
- int /*long*/ oldFont = OS.SelectObject (hDC, defaultFont ());
- TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ();
- OS.GetTextMetrics (hDC, tm);
- OS.SelectObject (hDC, oldFont);
- int itemWidth = Math.min (tm.tmHeight, width);
- int itemHeight = Math.min (tm.tmHeight, height);
- int left = (width - itemWidth) / 2, top = (height - itemHeight) / 2 + 1;
- OS.SetRect (rect, left, top, left + itemWidth, top + itemHeight);
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- int /*long*/ hTheme = display.hButtonTheme ();
- OS.DrawThemeBackground (hTheme, memDC, OS.BP_CHECKBOX, OS.CBS_UNCHECKEDNORMAL, rect, null);
- rect.left += width; rect.right += width;
- OS.DrawThemeBackground (hTheme, memDC, OS.BP_CHECKBOX, OS.CBS_CHECKEDNORMAL, rect, null);
- rect.left += width; rect.right += width;
- OS.DrawThemeBackground (hTheme, memDC, OS.BP_CHECKBOX, OS.CBS_UNCHECKEDNORMAL, rect, null);
- rect.left += width; rect.right += width;
- OS.DrawThemeBackground (hTheme, memDC, OS.BP_CHECKBOX, OS.CBS_MIXEDNORMAL, rect, null);
- } else {
- OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_FLAT);
- rect.left += width; rect.right += width;
- OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_CHECKED | OS.DFCS_FLAT);
- rect.left += width; rect.right += width;
- OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_INACTIVE | OS.DFCS_FLAT);
- rect.left += width; rect.right += width;
- OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_CHECKED | OS.DFCS_INACTIVE | OS.DFCS_FLAT);
- }
- OS.SelectObject (memDC, hOldBitmap);
- OS.DeleteDC (memDC);
- OS.ReleaseDC (handle, hDC);
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- OS.ImageList_Add (hStateList, hBitmap, 0);
- } else {
- OS.ImageList_AddMasked (hStateList, hBitmap, clrBackground);
- }
- OS.DeleteObject (hBitmap);
- /*
- * Bug in Windows. Making any change to an item that
- * changes the item height of a table while the table
- * is scrolled can cause the lines to draw incorrectly.
- * This happens even when the lines are not currently
- * visible and are shown afterwards. The fix is to
- * save the top index, scroll to the top of the table
- * and then restore the original top index.
- */
- int topIndex = getTopIndex ();
- if (fixScroll && topIndex != 0) {
- setRedraw (false);
- setTopIndex (0);
- }
- int /*long*/ hOldStateList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);
- OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_STATE, hStateList);
- if (hOldStateList != 0) OS.ImageList_Destroy (hOldStateList);
- /*
- * Bug in Windows. Setting the LVSIL_STATE state image list
- * when the table already has a LVSIL_SMALL image list causes
- * pixel corruption of the images. The fix is to reset the
- * LVSIL_SMALL image list.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- int /*long*/ hImageList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_SMALL, 0);
- OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, hImageList);
- }
- if (fixScroll && topIndex != 0) {
- setTopIndex (topIndex);
- setRedraw (true);
- }
-}
-
-void setFocusIndex (int index) {
-// checkWidget ();
- /*
- * An index of -1 will apply the change to all
- * items. Ensure that index is greater than -1.
- */
- if (index < 0) return;
- LVITEM lvItem = new LVITEM ();
- lvItem.state = OS.LVIS_FOCUSED;
- lvItem.stateMask = OS.LVIS_FOCUSED;
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_SETITEMSTATE, index, lvItem);
- ignoreSelect = false;
- OS.SendMessage (handle, OS.LVM_SETSELECTIONMARK, 0, index);
-}
-
-public void setFont (Font font) {
- checkWidget ();
- /*
- * Bug in Windows. Making any change to an item that
- * changes the item height of a table while the table
- * is scrolled can cause the lines to draw incorrectly.
- * This happens even when the lines are not currently
- * visible and are shown afterwards. The fix is to
- * save the top index, scroll to the top of the table
- * and then restore the original top index.
- */
- int topIndex = getTopIndex ();
- if (topIndex != 0) {
- setRedraw (false);
- setTopIndex (0);
- }
- if (itemHeight != -1) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits | OS.LVS_OWNERDRAWFIXED);
- }
- super.setFont (font);
- if (itemHeight != -1) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits & ~OS.LVS_OWNERDRAWFIXED);
- }
- setScrollWidth (null, true);
- if (topIndex != 0) {
- setTopIndex (topIndex);
- setRedraw (true);
- }
-
- /*
- * Bug in Windows. Setting the font will cause the table
- * to be redrawn but not the column headers. The fix is
- * to force a redraw of the column headers.
- */
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- OS.InvalidateRect (hwndHeader, null, true);
-}
-
-void setForegroundPixel (int pixel) {
- /*
- * The Windows table control uses CLR_DEFAULT to indicate
- * that it is using the default foreground color. This
- * is undocumented.
- */
- if (pixel == -1) pixel = OS.CLR_DEFAULT;
- OS.SendMessage (handle, OS.LVM_SETTEXTCOLOR, 0, pixel);
-
- /*
- * Feature in Windows. When the foreground color is
- * changed, the table does not redraw until the next
- * WM_PAINT. The fix is to force a redraw.
- */
- OS.InvalidateRect (handle, null, true);
-}
-
-/**
- * Marks the receiver's header as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHeaderVisible (boolean show) {
- checkWidget ();
- int newBits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- newBits &= ~OS.LVS_NOCOLUMNHEADER;
- if (!show) newBits |= OS.LVS_NOCOLUMNHEADER;
- /*
- * Feature in Windows. Setting or clearing LVS_NOCOLUMNHEADER
- * causes the table to scroll to the beginning. The fix is to
- * save and restore the top index causing the table to scroll
- * to the new location.
- */
- int oldIndex = getTopIndex ();
- OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
-
- /*
- * Bug in Windows. Making any change to an item that
- * changes the item height of a table while the table
- * is scrolled can cause the lines to draw incorrectly.
- * This happens even when the lines are not currently
- * visible and are shown afterwards. The fix is to
- * save the top index, scroll to the top of the table
- * and then restore the original top index.
- */
- int newIndex = getTopIndex ();
- if (newIndex != 0) {
- setRedraw (false);
- setTopIndex (0);
- }
- if (show) {
- int bits = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((bits & OS.LVS_EX_GRIDLINES) != 0) fixItemHeight (false);
- }
- setTopIndex (oldIndex);
- if (newIndex != 0) {
- setRedraw (true);
- }
- updateHeaderToolTips ();
-}
-
-/**
- * Sets the number of items contained in the receiver.
- *
- * @param count the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setItemCount (int count) {
- checkWidget ();
- count = Math.max (0, count);
- int itemCount = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (count == itemCount) return;
- setDeferResize (true);
- boolean isVirtual = (style & SWT.VIRTUAL) != 0;
- if (!isVirtual) setRedraw (false);
- int index = count;
- while (index < itemCount) {
- TableItem item = items [index];
- if (item != null && !item.isDisposed ()) item.release (false);
- if (!isVirtual) {
- ignoreSelect = ignoreShrink = true;
- int /*long*/ code = OS.SendMessage (handle, OS.LVM_DELETEITEM, count, 0);
- ignoreSelect = ignoreShrink = false;
- if (code == 0) break;
- }
- index++;
- }
- if (index < itemCount) error (SWT.ERROR_ITEM_NOT_REMOVED);
- int length = Math.max (4, (count + 3) / 4 * 4);
- TableItem [] newItems = new TableItem [length];
- System.arraycopy (items, 0, newItems, 0, Math.min (count, itemCount));
- items = newItems;
- if (isVirtual) {
- int flags = OS.LVSICF_NOINVALIDATEALL | OS.LVSICF_NOSCROLL;
- OS.SendMessage (handle, OS.LVM_SETITEMCOUNT, count, flags);
- /*
- * Bug in Windows. When a virtual table contains items and
- * LVM_SETITEMCOUNT is used to set the new item count to zero,
- * Windows does not redraw the table. Note that simply not
- * specifying LVSICF_NOINVALIDATEALL or LVSICF_NOSCROLL does
- * correct the problem. The fix is to force a redraw.
- */
- if (count == 0 && itemCount != 0) {
- OS.InvalidateRect (handle, null, true);
- }
- } else {
- for (int i=itemCount; i<count; i++) {
- items [i] = new TableItem (this, SWT.NONE, i, true);
- }
- }
- if (!isVirtual) setRedraw (true);
- if (itemCount == 0) setScrollWidth (null, false);
- setDeferResize (false);
-}
-
-void setItemHeight (boolean fixScroll) {
- /*
- * Bug in Windows. Making any change to an item that
- * changes the item height of a table while the table
- * is scrolled can cause the lines to draw incorrectly.
- * This happens even when the lines are not currently
- * visible and are shown afterwards. The fix is to
- * save the top index, scroll to the top of the table
- * and then restore the original top index.
- */
- int topIndex = getTopIndex ();
- if (fixScroll && topIndex != 0) {
- setRedraw (false);
- setTopIndex (0);
- }
- if (itemHeight == -1) {
- /*
- * Feature in Windows. Windows has no API to restore the
- * defualt item height for a table. The fix is to use
- * WM_SETFONT which recomputes and assigns the default item
- * height.
- */
- int /*long*/ hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);
- } else {
- /*
- * Feature in Windows. Window has no API to set the item
- * height for a table. The fix is to set temporarily set
- * LVS_OWNERDRAWFIXED then resize the table, causing a
- * WM_MEASUREITEM to be sent, then clear LVS_OWNERDRAWFIXED.
- */
- forceResize ();
- RECT rect = new RECT ();
- OS.GetWindowRect (handle, rect);
- int width = rect.right - rect.left, height = rect.bottom - rect.top;
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits | OS.LVS_OWNERDRAWFIXED);
- int flags = OS.SWP_NOACTIVATE | OS.SWP_NOMOVE | OS.SWP_NOREDRAW | OS.SWP_NOZORDER;
- ignoreResize = true;
- SetWindowPos (handle, 0 , 0, 0, width, height + 1, flags);
- SetWindowPos (handle, 0 , 0, 0, width, height, flags);
- ignoreResize = false;
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- }
- if (fixScroll && topIndex != 0) {
- setTopIndex (topIndex);
- setRedraw (true);
- }
-}
-
-/**
- * Sets the height of the area which would be used to
- * display <em>one</em> of the items in the table.
- *
- * @param itemHeight the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-/*public*/ void setItemHeight (int itemHeight) {
- checkWidget ();
- if (itemHeight < -1) error (SWT.ERROR_INVALID_ARGUMENT);
- this.itemHeight = itemHeight;
- setItemHeight (true);
- setScrollWidth (null, true);
-}
-
-/**
- * Marks the receiver's lines as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise. Note that some platforms draw grid lines
- * while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLinesVisible (boolean show) {
- checkWidget ();
- int newBits = show ? OS.LVS_EX_GRIDLINES : 0;
- OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, OS.LVS_EX_GRIDLINES, newBits);
- if (show) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.LVS_NOCOLUMNHEADER) == 0) fixItemHeight (true);
- }
-}
-
-public void setRedraw (boolean redraw) {
- checkWidget ();
- /*
- * Feature in Windows. When WM_SETREDRAW is used to turn
- * off drawing in a widget, it clears the WS_VISIBLE bits
- * and then sets them when redraw is turned back on. This
- * means that WM_SETREDRAW will make a widget unexpectedly
- * visible. The fix is to track the visibility state while
- * drawing is turned off and restore it when drawing is turned
- * back on.
- */
- if (drawCount == 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.WS_VISIBLE) == 0) state |= HIDDEN;
- }
- if (redraw) {
- if (--drawCount == 0) {
- /*
- * When many items are added to a table, it is faster to
- * temporarily unsubclass the window proc so that messages
- * are dispatched directly to the table.
- *
- * NOTE: This is optimization somewhat dangerous because any
- * operation can occur when redraw is turned off, even operations
- * where the table must be subclassed in order to have the correct
- * behavior or work around a Windows bug.
- *
- * This code is intentionally commented.
- */
-// subclass ();
-
- /* Set the width of the horizontal scroll bar */
- setScrollWidth (null, true);
-
- /*
- * Bug in Windows. For some reason, when WM_SETREDRAW is used
- * to turn redraw back on this may result in a WM_SIZE. If the
- * table column widths are adjusted in WM_SIZE, blank lines may
- * be inserted at the top of the widget. A call to LVM_GETTOPINDEX
- * will return a negative number (this is an impossible result).
- * The fix is to send the resize notification after the size has
- * been changed in the operating system.
- */
- setDeferResize (true);
- OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (hwndHeader != 0) OS.SendMessage (hwndHeader, OS.WM_SETREDRAW, 1, 0);
- if ((state & HIDDEN) != 0) {
- state &= ~HIDDEN;
- OS.ShowWindow (handle, OS.SW_HIDE);
- } else {
- if (OS.IsWinCE) {
- OS.InvalidateRect (handle, null, false);
- if (hwndHeader != 0) {
- OS.InvalidateRect (hwndHeader, null, false);
- }
- } else {
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, null, 0, flags);
- }
- }
- setDeferResize (false);
- }
- } else {
- if (drawCount++ == 0) {
- OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (hwndHeader != 0) OS.SendMessage (hwndHeader, OS.WM_SETREDRAW, 0, 0);
-
- /*
- * When many items are added to a table, it is faster to
- * temporarily unsubclass the window proc so that messages
- * are dispatched directly to the table.
- *
- * NOTE: This is optimization somewhat dangerous because any
- * operation can occur when redraw is turned off, even operations
- * where the table must be subclassed in order to have the correct
- * behavior or work around a Windows bug.
- *
- * This code is intentionally commented.
- */
-// unsubclass ();
- }
- }
-}
-
-void setScrollWidth (int width) {
- if (width != (int)/*64*/OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, 0, 0)) {
- /*
- * Feature in Windows. When LVM_SETCOLUMNWIDTH is sent,
- * Windows draws right away instead of queuing a WM_PAINT.
- * This can cause recursive calls when called from paint
- * or from messages that are retrieving the item data,
- * such as WM_NOTIFY, causing a stack overflow. The fix
- * is to turn off redraw and queue a repaint, collapsing
- * the recursive calls.
- */
- boolean redraw = false;
- if (hooks (SWT.MeasureItem)) {
- redraw = getDrawing () && OS.IsWindowVisible (handle);
- }
- if (redraw) OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- OS.SendMessage (handle, OS.LVM_SETCOLUMNWIDTH, 0, width);
- if (redraw) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- if (OS.IsWinCE) {
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (hwndHeader != 0) OS.InvalidateRect (hwndHeader, null, true);
- OS.InvalidateRect (handle, null, true);
- } else {
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, null, 0, flags);
- }
- }
- }
-}
-
-boolean setScrollWidth (TableItem item, boolean force) {
- if (currentItem != null) {
- if (currentItem != item) fixScrollWidth = true;
- return false;
- }
- if (!force && (!getDrawing () || !OS.IsWindowVisible (handle))) {
- fixScrollWidth = true;
- return false;
- }
- fixScrollWidth = false;
- /*
- * NOTE: It is much faster to measure the strings and compute the
- * width of the scroll bar in non-virtual table rather than using
- * LVM_SETCOLUMNWIDTH with LVSCW_AUTOSIZE.
- */
- if (columnCount == 0) {
- int newWidth = 0, imageIndent = 0, index = 0;
- int itemCount = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- while (index < itemCount) {
- String string = null;
- int /*long*/ hFont = -1;
- if (item != null) {
- string = item.text;
- imageIndent = Math.max (imageIndent, item.imageIndent);
- hFont = item.fontHandle (0);
- } else {
- if (items [index] != null) {
- TableItem tableItem = items [index];
- string = tableItem.text;
- imageIndent = Math.max (imageIndent, tableItem.imageIndent);
- hFont = tableItem.fontHandle (0);
- }
- }
- if (string != null && string.length () != 0) {
- if (hFont != -1) {
- int /*long*/ hDC = OS.GetDC (handle);
- int /*long*/ oldFont = OS.SelectObject (hDC, hFont);
- int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX;
- TCHAR buffer = new TCHAR (getCodePage (), string, false);
- RECT rect = new RECT ();
- OS.DrawText (hDC, buffer, buffer.length (), rect, flags);
- OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- newWidth = Math.max (newWidth, rect.right - rect.left);
- } else {
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- newWidth = Math.max (newWidth, (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSTRINGWIDTH, 0, buffer));
- }
- }
- if (item != null) break;
- index++;
- }
- /*
- * Bug in Windows. When the width of the first column is
- * small but not zero, Windows draws '...' outside of the
- * bounds of the text. This is strange, but only causes
- * problems when the item is selected. In this case, Windows
- * clears the '...' but doesn't redraw it when the item is
- * deselected, causing pixel corruption. The fix is to ensure
- * that the column is at least wide enough to draw a single
- * space.
- */
- if (newWidth == 0) {
- TCHAR buffer = new TCHAR (getCodePage (), " ", true);
- newWidth = Math.max (newWidth, (int)/*64*/OS.SendMessage (handle, OS.LVM_GETSTRINGWIDTH, 0, buffer));
- }
- int /*long*/ hStateList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);
- if (hStateList != 0) {
- int [] cx = new int [1], cy = new int [1];
- OS.ImageList_GetIconSize (hStateList, cx, cy);
- newWidth += cx [0] + INSET;
- }
- int /*long*/ hImageList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_SMALL, 0);
- if (hImageList != 0) {
- int [] cx = new int [1], cy = new int [1];
- OS.ImageList_GetIconSize (hImageList, cx, cy);
- newWidth += (imageIndent + 1) * cx [0];
- } else {
- /*
- * Bug in Windows. When LVM_SETIMAGELIST is used to remove the
- * image list by setting it to NULL, the item width and height
- * is not changed and space is reserved for icons despite the
- * fact that there are none. The fix is to set the image list
- * to be very small before setting it to NULL. This causes
- * Windows to reserve the smallest possible space when an image
- * list is removed. In this case, the scroll width must be one
- * pixel larger.
- */
- newWidth++;
- }
- newWidth += INSET * 2;
- int oldWidth = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, 0, 0);
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- newWidth += VISTA_EXTRA;
- }
- if (newWidth > oldWidth) {
- setScrollWidth (newWidth);
- return true;
- }
- }
- return false;
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- * </p>
- *
- * @param indices the indices of the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int[])
- */
-public void setSelection (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- select (indices);
- int focusIndex = indices [0];
- if (focusIndex != -1) setFocusIndex (focusIndex);
- showSelection ();
-}
-
-/**
- * Sets the receiver's selection to the given item.
- * The current selection is cleared before the new item is selected.
- * <p>
- * If the item is not in the receiver, then it is ignored.
- * </p>
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection (TableItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (new TableItem [] {item});
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- * </p>
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the items has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int[])
- * @see Table#setSelection(int[])
- */
-public void setSelection (TableItem [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = items.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- int focusIndex = -1;
- for (int i=length-1; i>=0; --i) {
- int index = indexOf (items [i]);
- if (index != -1) {
- select (focusIndex = index);
- }
- }
- if (focusIndex != -1) setFocusIndex (focusIndex);
- showSelection ();
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * The current selection is first cleared, then the new item is selected.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int)
- */
-public void setSelection (int index) {
- checkWidget ();
- deselectAll ();
- select (index);
- if (index != -1) setFocusIndex (index);
- showSelection ();
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- * </p>
- *
- * @param start the start index of the items to select
- * @param end the end index of the items to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int,int)
- */
-public void setSelection (int start, int end) {
- checkWidget ();
- deselectAll ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (count == 0 || start >= count) return;
- start = Math.max (0, start);
- end = Math.min (end, count - 1);
- select (start, end);
- setFocusIndex (start);
- showSelection ();
-}
-
-/**
- * Sets the column used by the sort indicator for the receiver. A null
- * value will clear the sort indicator. The current sort column is cleared
- * before the new column is set.
- *
- * @param column the column used by the sort indicator or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the column is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortColumn (TableColumn column) {
- checkWidget ();
- if (column != null && column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (sortColumn != null && !sortColumn.isDisposed ()) {
- sortColumn.setSortDirection (SWT.NONE);
- }
- sortColumn = column;
- if (sortColumn != null && sortDirection != SWT.NONE) {
- sortColumn.setSortDirection (sortDirection);
- }
-}
-
-/**
- * Sets the direction of the sort indicator for the receiver. The value
- * can be one of <code>UP</code>, <code>DOWN</code> or <code>NONE</code>.
- *
- * @param direction the direction of the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortDirection (int direction) {
- checkWidget ();
- if ((direction & (SWT.UP | SWT.DOWN)) == 0 && direction != SWT.NONE) return;
- sortDirection = direction;
- if (sortColumn != null && !sortColumn.isDisposed ()) {
- sortColumn.setSortDirection (direction);
- }
-}
-
-void setSubImagesVisible (boolean visible) {
- int dwExStyle = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((dwExStyle & OS.LVS_EX_SUBITEMIMAGES) != 0 == visible) return;
- int bits = visible ? OS.LVS_EX_SUBITEMIMAGES : 0;
- OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, OS.LVS_EX_SUBITEMIMAGES, bits);
-}
-
-void setTableEmpty () {
- if (imageList != null) {
- /*
- * Bug in Windows. When LVM_SETIMAGELIST is used to remove the
- * image list by setting it to NULL, the item width and height
- * is not changed and space is reserved for icons despite the
- * fact that there are none. The fix is to set the image list
- * to be very small before setting it to NULL. This causes
- * Windows to reserve the smallest possible space when an image
- * list is removed.
- */
- int /*long*/ hImageList = OS.ImageList_Create (1, 1, 0, 0, 0);
- OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, hImageList);
- OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);
- if (headerImageList != null) {
- int /*long*/ hHeaderImageList = headerImageList.getHandle ();
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- OS.SendMessage (hwndHeader, OS.HDM_SETIMAGELIST, 0, hHeaderImageList);
- }
- OS.ImageList_Destroy (hImageList);
- display.releaseImageList (imageList);
- imageList = null;
- if (itemHeight != -1) setItemHeight (false);
- }
- if (!hooks (SWT.MeasureItem) && !hooks (SWT.EraseItem) && !hooks (SWT.PaintItem)) {
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- if (control.backgroundImage == null) {
- setCustomDraw (false);
- setBackgroundTransparent (false);
- if (OS.COMCTL32_MAJOR < 6) style &= ~SWT.DOUBLE_BUFFERED;
- }
- }
- items = new TableItem [4];
- if (columnCount == 0) {
- OS.SendMessage (handle, OS.LVM_SETCOLUMNWIDTH, 0, 0);
- setScrollWidth (null, false);
- }
-}
-
-/**
- * Sets the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items
- * are scrolled or new items are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget ();
- int topIndex = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0);
- if (index == topIndex) return;
- if (!painted && hooks (SWT.MeasureItem)) hitTestSelection (index, 0, 0);
-
- /*
- * Bug in Windows. For some reason, LVM_SCROLL refuses to
- * scroll a table vertically when the width and height of
- * the table is smaller than a certain size. The values
- * that seem to cause the problem are width=68 and height=6
- * but there is no guarantee that these values cause the
- * failure on different machines or on different versions
- * of Windows. It may depend on the font and any number
- * of other factors. For example, setting the font to
- * anything but the default sometimes fixes the problem.
- * The fix is to use LVM_GETCOUNTPERPAGE to detect the
- * case when the number of visible items is zero and
- * use LVM_ENSUREVISIBLE to scroll the table to make the
- * index visible.
- */
-
- /*
- * Bug in Windows. When the table header is visible and
- * there is not enough space to show a single table item,
- * LVM_GETCOUNTPERPAGE can return a negative number instead
- * of zero. The fix is to test for negative or zero.
- */
- if (OS.SendMessage (handle, OS.LVM_GETCOUNTPERPAGE, 0, 0) <= 0) {
- /*
- * Bug in Windows. For some reason, LVM_ENSUREVISIBLE can
- * scroll one item more or one item less when there is not
- * enough space to show a single table item. The fix is
- * to detect the case and call LVM_ENSUREVISIBLE again with
- * the same arguments. It seems that once LVM_ENSUREVISIBLE
- * has scrolled into the general area, it is able to scroll
- * to the exact item.
- */
- OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 1);
- if (index != OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0)) {
- OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 1);
- }
- return;
- }
-
- /* Use LVM_SCROLL to scroll the table */
- RECT rect = new RECT ();
- rect.left = OS.LVIR_BOUNDS;
- ignoreCustomDraw = true;
- OS.SendMessage (handle, OS.LVM_GETITEMRECT, 0, rect);
- ignoreCustomDraw = false;
- int dy = (index - topIndex) * (rect.bottom - rect.top);
- OS.SendMessage (handle, OS.LVM_SCROLL, 0, dy);
-}
-
-/**
- * Shows the column. If the column is already showing in the receiver,
- * this method simply returns. Otherwise, the columns are scrolled until
- * the column is visible.
- *
- * @param column the column to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the column is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the column has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void showColumn (TableColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (column.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (column.parent != this) return;
- int index = indexOf (column);
- if (!(0 <= index && index < columnCount)) return;
- /*
- * Feature in Windows. Calling LVM_GETSUBITEMRECT with -1 for the
- * row number gives the bounds of the item that would be above the
- * first row in the table. This is undocumented and does not work
- * for the first column. In this case, to get the bounds of the
- * first column, get the bounds of the second column and subtract
- * the width of the first. The left edge of the second column is
- * also used as the right edge of the first.
- */
- RECT itemRect = new RECT ();
- itemRect.left = OS.LVIR_BOUNDS;
- if (index == 0) {
- itemRect.top = 1;
- ignoreCustomDraw = true;
- OS.SendMessage (handle, OS.LVM_GETSUBITEMRECT, -1, itemRect);
- ignoreCustomDraw = false;
- itemRect.right = itemRect.left;
- int width = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, 0, 0);
- itemRect.left = itemRect.right - width;
- } else {
- itemRect.top = index;
- ignoreCustomDraw = true;
- OS.SendMessage (handle, OS.LVM_GETSUBITEMRECT, -1, itemRect);
- ignoreCustomDraw = false;
- }
- /*
- * Bug in Windows. When a table that is drawing grid lines
- * is slowly scrolled horizontally to the left, the table does
- * not redraw the newly exposed vertical grid lines. The fix
- * is to save the old scroll position, call the window proc,
- * get the new scroll position and redraw the new area.
- */
- int oldPos = 0;
- int bits = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((bits & OS.LVS_EX_GRIDLINES) != 0) {
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_POS;
- OS.GetScrollInfo (handle, OS.SB_HORZ, info);
- oldPos = info.nPos;
- }
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- if (itemRect.left < rect.left) {
- int dx = itemRect.left - rect.left;
- OS.SendMessage (handle, OS.LVM_SCROLL, dx, 0);
- } else {
- int width = Math.min (rect.right - rect.left, itemRect.right - itemRect.left);
- if (itemRect.left + width > rect.right) {
- int dx = itemRect.left + width - rect.right;
- OS.SendMessage (handle, OS.LVM_SCROLL, dx, 0);
- }
- }
- /*
- * Bug in Windows. When a table that is drawing grid lines
- * is slowly scrolled horizontally to the left, the table does
- * not redraw the newly exposed vertical grid lines. The fix
- * is to save the old scroll position, call the window proc,
- * get the new scroll position and redraw the new area.
- */
- if ((bits & OS.LVS_EX_GRIDLINES) != 0) {
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_POS;
- OS.GetScrollInfo (handle, OS.SB_HORZ, info);
- int newPos = info.nPos;
- if (newPos < oldPos) {
- rect.right = oldPos - newPos + GRID_WIDTH;
- OS.InvalidateRect (handle, rect, true);
- }
- }
-}
-
-void showItem (int index) {
- if (!painted && hooks (SWT.MeasureItem)) hitTestSelection (index, 0, 0);
- /*
- * Bug in Windows. For some reason, when there is insufficient space
- * to show an item, LVM_ENSUREVISIBLE causes blank lines to be
- * inserted at the top of the widget. A call to LVM_GETTOPINDEX will
- * return a negative number (this is an impossible result). The fix
- * is to use LVM_GETCOUNTPERPAGE to detect the case when the number
- * of visible items is zero and use LVM_ENSUREVISIBLE with the
- * fPartialOK flag set to true to scroll the table.
- */
- if (OS.SendMessage (handle, OS.LVM_GETCOUNTPERPAGE, 0, 0) <= 0) {
- /*
- * Bug in Windows. For some reason, LVM_ENSUREVISIBLE can
- * scroll one item more or one item less when there is not
- * enough space to show a single table item. The fix is
- * to detect the case and call LVM_ENSUREVISIBLE again with
- * the same arguments. It seems that once LVM_ENSUREVISIBLE
- * has scrolled into the general area, it is able to scroll
- * to the exact item.
- */
- OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 1);
- if (index != OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0)) {
- OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 1);
- }
- } else {
- OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 0);
- }
-}
-
-/**
- * Shows the item. If the item is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the item is visible.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#showSelection()
- */
-public void showItem (TableItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- int index = indexOf (item);
- if (index != -1) showItem (index);
-}
-
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#showItem(TableItem)
- */
-public void showSelection () {
- checkWidget ();
- int index = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_SELECTED);
- if (index != -1) showItem (index);
-}
-
-/*public*/ void sort () {
- checkWidget ();
-// if ((style & SWT.VIRTUAL) != 0) return;
-// int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
-// if (itemCount == 0 || itemCount == 1) return;
-// Comparator comparator = new Comparator () {
-// int index = sortColumn == null ? 0 : indexOf (sortColumn);
-// public int compare (Object object1, Object object2) {
-// TableItem item1 = (TableItem) object1, item2 = (TableItem) object2;
-// if (sortDirection == SWT.UP || sortDirection == SWT.NONE) {
-// return item1.getText (index).compareTo (item2.getText (index));
-// } else {
-// return item2.getText (index).compareTo (item1.getText (index));
-// }
-// }
-// };
-// Arrays.sort (items, 0, itemCount, comparator);
-// redraw ();
-}
-
-void subclass () {
- super.subclass ();
- if (HeaderProc != 0) {
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- OS.SetWindowLongPtr (hwndHeader, OS.GWLP_WNDPROC, display.windowProc);
- }
-}
-
-RECT toolTipInset (RECT rect) {
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- RECT insetRect = new RECT ();
- OS.SetRect (insetRect, rect.left - 1, rect.top - 1, rect.right + 1, rect.bottom + 1);
- return insetRect;
- }
- return rect;
-}
-
-RECT toolTipRect (RECT rect) {
- RECT toolRect = new RECT ();
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- OS.SetRect (toolRect, rect.left - 1, rect.top - 1, rect.right + 1, rect.bottom + 1);
- } else {
- int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.LVM_GETTOOLTIPS, 0, 0);
- OS.SetRect (toolRect, rect.left, rect.top, rect.right, rect.bottom);
- int dwStyle = OS.GetWindowLong (hwndToolTip, OS.GWL_STYLE);
- int dwExStyle = OS.GetWindowLong (hwndToolTip, OS.GWL_EXSTYLE);
- OS.AdjustWindowRectEx (toolRect, dwStyle, false, dwExStyle);
- }
- return toolRect;
-}
-
-String toolTipText (NMTTDISPINFO hdr) {
- int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.LVM_GETTOOLTIPS, 0, 0);
- if (hwndToolTip == hdr.hwndFrom && toolTipText != null) return ""; //$NON-NLS-1$
- if (headerToolTipHandle == hdr.hwndFrom) {
- for (int i=0; i<columnCount; i++) {
- TableColumn column = columns [i];
- if (column.id == hdr.idFrom) return column.toolTipText;
- }
- }
- return super.toolTipText (hdr);
-}
-
-void unsubclass () {
- super.unsubclass ();
- if (HeaderProc != 0) {
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- OS.SetWindowLongPtr (hwndHeader, OS.GWLP_WNDPROC, HeaderProc);
- }
-}
-
-void update (boolean all) {
-// checkWidget ();
- /*
- * When there are many columns in a table, scrolling performance
- * can be improved by temporarily unsubclassing the window proc
- * so that internal messages are dispatched directly to the table.
- * If the application expects to see a paint event or has a child
- * whose font, foreground or background color might be needed,
- * the window proc cannot be unsubclassed.
- *
- * NOTE: The header tooltip can subclass the header proc so the
- * current proc must be restored or header tooltips stop working.
- */
- int /*long*/ oldHeaderProc = 0, oldTableProc = 0;
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- boolean fixSubclass = isOptimizedRedraw ();
- if (fixSubclass) {
- oldTableProc = OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, TableProc);
- oldHeaderProc = OS.SetWindowLongPtr (hwndHeader, OS.GWLP_WNDPROC, HeaderProc);
- }
- super.update (all);
- if (fixSubclass) {
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, oldTableProc);
- OS.SetWindowLongPtr (hwndHeader, OS.GWLP_WNDPROC, oldHeaderProc);
- }
-}
-
-void updateHeaderToolTips () {
- if (headerToolTipHandle == 0) return;
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- RECT rect = new RECT ();
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- lpti.uFlags = OS.TTF_SUBCLASS;
- lpti.hwnd = hwndHeader;
- lpti.lpszText = OS.LPSTR_TEXTCALLBACK;
- for (int i=0; i<columnCount; i++) {
- TableColumn column = columns [i];
- if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, i, rect) != 0) {
- lpti.uId = column.id = display.nextToolTipId++;
- lpti.left = rect.left;
- lpti.top = rect.top;
- lpti.right = rect.right;
- lpti.bottom = rect.bottom;
- OS.SendMessage (headerToolTipHandle, OS.TTM_ADDTOOL, 0, lpti);
- }
- }
-}
-
-void updateImages () {
- if (sortColumn != null && !sortColumn.isDisposed ()) {
- if (OS.COMCTL32_MAJOR < 6) {
- switch (sortDirection) {
- case SWT.UP:
- case SWT.DOWN:
- sortColumn.setImage (display.getSortImage (sortDirection), true, true);
- break;
- }
- }
- }
-}
-
-void updateMoveable () {
- int index = 0;
- while (index < columnCount) {
- if (columns [index].moveable) break;
- index++;
- }
- int newBits = index < columnCount ? OS.LVS_EX_HEADERDRAGDROP : 0;
- OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, OS.LVS_EX_HEADERDRAGDROP, newBits);
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle () | OS.LVS_SHAREIMAGELISTS;
- if ((style & SWT.HIDE_SELECTION) == 0) bits |= OS.LVS_SHOWSELALWAYS;
- if ((style & SWT.SINGLE) != 0) bits |= OS.LVS_SINGLESEL;
- /*
- * This code is intentionally commented. In the future,
- * the FLAT bit may be used to make the header flat and
- * unresponsive to mouse clicks.
- */
-// if ((style & SWT.FLAT) != 0) bits |= OS.LVS_NOSORTHEADER;
- bits |= OS.LVS_REPORT | OS.LVS_NOCOLUMNHEADER;
- if ((style & SWT.VIRTUAL) != 0) bits |= OS.LVS_OWNERDATA;
- return bits;
-}
-
-TCHAR windowClass () {
- return TableClass;
-}
-
-int /*long*/ windowProc () {
- return TableProc;
-}
-
-int /*long*/ windowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- if (hwnd != handle) {
- switch (msg) {
- case OS.WM_CONTEXTMENU: {
- LRESULT result = wmContextMenu (hwnd, wParam, lParam);
- if (result != null) return result.value;
- break;
- }
- case OS.WM_CAPTURECHANGED: {
- /*
- * Bug in Windows. When the capture changes during a
- * header drag, Windows does not redraw the header item
- * such that the header remains pressed. For example,
- * when focus is assigned to a push button, the mouse is
- * pressed (but not released), then the SPACE key is
- * pressed to activate the button, the capture changes,
- * the header not notified and NM_RELEASEDCAPTURE is not
- * sent. The fix is to redraw the header when the capture
- * changes to another control.
- *
- * This does not happen on XP.
- */
- if (OS.COMCTL32_MAJOR < 6) {
- if (lParam != 0) {
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (lParam != hwndHeader) OS.InvalidateRect (hwndHeader, null, true);
- }
- }
- break;
- }
- case OS.WM_MOUSELEAVE: {
- /*
- * Bug in Windows. On XP, when a tooltip is hidden
- * due to a time out or mouse press, the tooltip
- * remains active although no longer visible and
- * won't show again until another tooltip becomes
- * active. The fix is to reset the tooltip bounds.
- */
- if (OS.COMCTL32_MAJOR >= 6) updateHeaderToolTips ();
- updateHeaderToolTips ();
- break;
- }
- case OS.WM_NOTIFY: {
- NMHDR hdr = new NMHDR ();
- OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
- switch (hdr.code) {
- case OS.TTN_SHOW:
- case OS.TTN_POP:
- case OS.TTN_GETDISPINFOA:
- case OS.TTN_GETDISPINFOW:
- return OS.SendMessage (handle, msg, wParam, lParam);
- }
- break;
- }
- case OS.WM_SETCURSOR: {
- if (wParam == hwnd) {
- int hitTest = (short) OS.LOWORD (lParam);
- if (hitTest == OS.HTCLIENT) {
- HDHITTESTINFO pinfo = new HDHITTESTINFO ();
- int pos = OS.GetMessagePos ();
- POINT pt = new POINT ();
- OS.POINTSTOPOINT (pt, pos);
- OS.ScreenToClient (hwnd, pt);
- pinfo.x = pt.x;
- pinfo.y = pt.y;
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int index = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_HITTEST, 0, pinfo);
- if (0 <= index && index < columnCount && !columns [index].resizable) {
- if ((pinfo.flags & (OS.HHT_ONDIVIDER | OS.HHT_ONDIVOPEN)) != 0) {
- OS.SetCursor (OS.LoadCursor (0, OS.IDC_ARROW));
- return 1;
- }
- }
- }
- }
- break;
- }
- }
- return callWindowProc (hwnd, msg, wParam, lParam);
- }
- if (msg == Display.DI_GETDRAGIMAGE) {
- /*
- * Bug in Windows. On Vista, for some reason, DI_GETDRAGIMAGE
- * returns an image that does not contain strings.
- *
- * Bug in Windows. For custom draw control the window origin the
- * in HDC is wrong.
- *
- * The fix for both cases is to create the image using PrintWindow().
- */
- if ((!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) || (style & SWT.VIRTUAL) != 0 || hooks (SWT.EraseItem) || hooks (SWT.PaintItem)) {
- int topIndex = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0);
- int selection = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, topIndex - 1, OS.LVNI_SELECTED);
- if (selection == -1) return 0;
- POINT mousePos = new POINT ();
- OS.POINTSTOPOINT (mousePos, OS.GetMessagePos ());
- OS.MapWindowPoints(0, handle, mousePos, 1);
- RECT clientRect = new RECT ();
- OS.GetClientRect (handle, clientRect);
- TableItem item = _getItem (selection);
- RECT rect = item.getBounds (selection, 0, true, true, true);
- if ((style & SWT.FULL_SELECTION) != 0) {
- int width = DRAG_IMAGE_SIZE;
- rect.left = Math.max (clientRect.left, mousePos.x - width / 2);
- if (clientRect.right > rect.left + width) {
- rect.right = rect.left + width;
- } else {
- rect.right = clientRect.right;
- rect.left = Math.max (clientRect.left, rect.right - width);
- }
- }
- int /*long*/ hRgn = OS.CreateRectRgn (rect.left, rect.top, rect.right, rect.bottom);
- while ((selection = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, selection, OS.LVNI_SELECTED)) != -1) {
- if (rect.bottom - rect.top > DRAG_IMAGE_SIZE) break;
- if (rect.bottom > clientRect.bottom) break;
- RECT itemRect = item.getBounds (selection, 0, true, true, true);
- int /*long*/ rectRgn = OS.CreateRectRgn (rect.left, itemRect.top, rect.right, itemRect.bottom);
- OS.CombineRgn (hRgn, hRgn, rectRgn, OS.RGN_OR);
- OS.DeleteObject (rectRgn);
- rect.bottom = itemRect.bottom;
- }
- OS.GetRgnBox (hRgn, rect);
-
- /* Create resources */
- int /*long*/ hdc = OS.GetDC (handle);
- int /*long*/ memHdc = OS.CreateCompatibleDC (hdc);
- BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER ();
- bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
- bmiHeader.biWidth = rect.right - rect.left;
- bmiHeader.biHeight = -(rect.bottom - rect.top);
- bmiHeader.biPlanes = 1;
- bmiHeader.biBitCount = 32;
- bmiHeader.biCompression = OS.BI_RGB;
- byte [] bmi = new byte [BITMAPINFOHEADER.sizeof];
- OS.MoveMemory (bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
- int /*long*/ [] pBits = new int /*long*/ [1];
- int /*long*/ memDib = OS.CreateDIBSection (0, bmi, OS.DIB_RGB_COLORS, pBits, 0, 0);
- if (memDib == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- int /*long*/ oldMemBitmap = OS.SelectObject (memHdc, memDib);
- int colorKey = 0x0000FD;
- POINT pt = new POINT();
- OS.SetWindowOrgEx (memHdc, rect.left, rect.top, pt);
- OS.FillRect (memHdc, rect, findBrush (colorKey, OS.BS_SOLID));
- OS.OffsetRgn (hRgn, -rect.left, -rect.top);
- OS.SelectClipRgn (memHdc, hRgn);
- OS.PrintWindow (handle, memHdc, 0);
- OS.SetWindowOrgEx (memHdc, pt.x, pt.y, null);
- OS.SelectObject (memHdc, oldMemBitmap);
- OS.DeleteDC (memHdc);
- OS.ReleaseDC (0, hdc);
- OS.DeleteObject (hRgn);
-
- SHDRAGIMAGE shdi = new SHDRAGIMAGE ();
- shdi.hbmpDragImage = memDib;
- shdi.crColorKey = colorKey;
- shdi.sizeDragImage.cx = bmiHeader.biWidth;
- shdi.sizeDragImage.cy = -bmiHeader.biHeight;
- shdi.ptOffset.x = mousePos.x - rect.left;
- shdi.ptOffset.y = mousePos.y - rect.top;
- if ((style & SWT.MIRRORED) != 0) {
- shdi.ptOffset.x = shdi.sizeDragImage.cx - shdi.ptOffset.x;
- }
- OS.MoveMemory (lParam, shdi, SHDRAGIMAGE.sizeof);
- return 1;
- }
- }
- return super.windowProc (hwnd, msg, wParam, lParam);
-}
-
-LRESULT WM_CHAR (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_CHAR (wParam, lParam);
- if (result != null) return result;
- switch ((int)/*64*/wParam) {
- case ' ':
- if ((style & SWT.CHECK) != 0) {
- int index = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);
- if (index != -1) {
- TableItem item = _getItem (index);
- item.setChecked (!item.getChecked (), true);
- if (!OS.IsWinCE) {
- OS.NotifyWinEvent (OS.EVENT_OBJECT_FOCUS, handle, OS.OBJID_CLIENT, index + 1);
- }
- }
- }
- /*
- * NOTE: Call the window proc with WM_KEYDOWN rather than WM_CHAR
- * so that the key that was ignored during WM_KEYDOWN is processed.
- * This allows the application to cancel an operation that is normally
- * performed in WM_KEYDOWN from WM_CHAR.
- */
- int /*long*/ code = callWindowProc (handle, OS.WM_KEYDOWN, wParam, lParam);
- return new LRESULT (code);
- case SWT.CR:
- /*
- * Feature in Windows. Windows sends LVN_ITEMACTIVATE from WM_KEYDOWN
- * instead of WM_CHAR. This means that application code that expects
- * to consume the key press and therefore avoid a SWT.DefaultSelection
- * event will fail. The fix is to ignore LVN_ITEMACTIVATE when it is
- * caused by WM_KEYDOWN and send SWT.DefaultSelection from WM_CHAR.
- */
- int index = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);
- if (index != -1) {
- Event event = new Event ();
- event.item = _getItem (index);
- postEvent (SWT.DefaultSelection, event);
- }
- return LRESULT.ZERO;
- }
- return result;
-}
-
-LRESULT WM_CONTEXTMENU (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. For some reason, when the right
- * mouse button is pressed over an item, Windows sends
- * a WM_CONTEXTMENU from WM_RBUTTONDOWN, instead of from
- * WM_RBUTTONUP. This causes two context menus requests
- * to be sent. The fix is to ignore WM_CONTEXTMENU on
- * mouse down.
- *
- * NOTE: This only happens when dragging is disabled.
- * When the table is detecting drag, the WM_CONTEXTMENU
- * is not sent WM_RBUTTONUP.
- */
- if (!display.runDragDrop) return LRESULT.ZERO;
- return super.WM_CONTEXTMENU (wParam, lParam);
-}
-
-LRESULT WM_ERASEBKGND (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
- if (findImageControl () != null) return LRESULT.ONE;
- if (!OS.IsWinCE && OS.COMCTL32_MAJOR < 6) {
- if ((style & SWT.DOUBLE_BUFFERED) != 0) {
- int bits = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((bits & OS.LVS_EX_DOUBLEBUFFER) == 0) return LRESULT.ONE;
- }
- }
- return result;
-}
-
-LRESULT WM_GETOBJECT (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Ensure that there is an accessible object created for this
- * control because support for checked item accessibility is
- * temporarily implemented in the accessibility package.
- */
- if ((style & SWT.CHECK) != 0) {
- if (accessible == null) accessible = new_Accessible (this);
- }
- return super.WM_GETOBJECT (wParam, lParam);
-}
-
-LRESULT WM_KEYDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_KEYDOWN (wParam, lParam);
- if (result != null) return result;
- switch ((int)/*64*/wParam) {
- case OS.VK_SPACE:
- /*
- * Ensure that the window proc does not process VK_SPACE
- * so that it can be handled in WM_CHAR. This allows the
- * application to cancel an operation that is normally
- * performed in WM_KEYDOWN from WM_CHAR.
- */
- return LRESULT.ZERO;
- case OS.VK_ADD:
- if (OS.GetKeyState (OS.VK_CONTROL) < 0) {
- int index = 0;
- while (index < columnCount) {
- if (!columns [index].getResizable ()) break;
- index++;
- }
- if (index != columnCount || hooks (SWT.MeasureItem)) {
- TableColumn [] newColumns = new TableColumn [columnCount];
- System.arraycopy (columns, 0, newColumns, 0, columnCount);
- for (int i=0; i<newColumns.length; i++) {
- TableColumn column = newColumns [i];
- if (!column.isDisposed () && column.getResizable ()) {
- column.pack ();
- }
- }
- return LRESULT.ZERO;
- }
- }
- break;
- case OS.VK_PRIOR:
- case OS.VK_NEXT:
- case OS.VK_HOME:
- case OS.VK_END:
- /*
- * When there are many columns in a table, scrolling performance
- * can be improved by temporarily unsubclassing the window proc
- * so that internal messages are dispatched directly to the table.
- * If the application expects to see a paint event, the window
- * proc cannot be unsubclassed or the event will not be seen.
- *
- * NOTE: The header tooltip can subclass the header proc so the
- * current proc must be restored or header tooltips stop working.
- */
- int /*long*/ oldHeaderProc = 0, oldTableProc = 0;
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- boolean fixSubclass = isOptimizedRedraw ();
- if (fixSubclass) {
- oldTableProc = OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, TableProc);
- oldHeaderProc = OS.SetWindowLongPtr (hwndHeader, OS.GWLP_WNDPROC, HeaderProc);
- }
- int /*long*/ code = callWindowProc (handle, OS.WM_KEYDOWN, wParam, lParam);
- result = code == 0 ? LRESULT.ZERO : new LRESULT (code);
- if (fixSubclass) {
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, oldTableProc);
- OS.SetWindowLongPtr (hwndHeader, OS.GWLP_WNDPROC, oldHeaderProc);
- }
- //FALL THROUGH
- case OS.VK_UP:
- case OS.VK_DOWN:
- OS.SendMessage (handle, OS.WM_CHANGEUISTATE, OS.UIS_INITIALIZE, 0);
- break;
- }
- return result;
-}
-
-LRESULT WM_KILLFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_KILLFOCUS (wParam, lParam);
- /*
- * Bug in Windows. When focus is lost, Windows does not
- * redraw the selection properly, leaving the image and
- * check box appearing selected. The fix is to redraw
- * the table.
- */
- if (imageList != null || (style & SWT.CHECK) != 0) {
- OS.InvalidateRect (handle, null, false);
- }
- return result;
-}
-
-LRESULT WM_LBUTTONDBLCLK (int /*long*/ wParam, int /*long*/ lParam) {
-
- /*
- * Feature in Windows. When the user selects outside of
- * a table item, Windows deselects all the items, even
- * when the table is multi-select. While not strictly
- * wrong, this is unexpected. The fix is to detect the
- * case and avoid calling the window proc.
- */
- LVHITTESTINFO pinfo = new LVHITTESTINFO ();
- pinfo.x = OS.GET_X_LPARAM (lParam);
- pinfo.y = OS.GET_Y_LPARAM (lParam);
- int index = (int)/*64*/OS.SendMessage (handle, OS.LVM_HITTEST, 0, pinfo);
- Display display = this.display;
- display.captureChanged = false;
- sendMouseEvent (SWT.MouseDown, 1, handle, OS.WM_LBUTTONDOWN, wParam, lParam);
- if (!sendMouseEvent (SWT.MouseDoubleClick, 1, handle, OS.WM_LBUTTONDBLCLK, wParam, lParam)) {
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- return LRESULT.ZERO;
- }
- if (pinfo.iItem != -1) callWindowProc (handle, OS.WM_LBUTTONDBLCLK, wParam, lParam);
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
-
- /* Look for check/uncheck */
- if ((style & SWT.CHECK) != 0) {
- /*
- * Note that when the table has LVS_EX_FULLROWSELECT and the
- * user clicks anywhere on a row except on the check box, all
- * of the bits are set. The hit test flags are LVHT_ONITEM.
- * This means that a bit test for LVHT_ONITEMSTATEICON is not
- * the correct way to determine that the user has selected
- * the check box, equality is needed.
- */
- if (index != -1 && pinfo.flags == OS.LVHT_ONITEMSTATEICON) {
- TableItem item = _getItem (index);
- item.setChecked (!item.getChecked (), true);
- if (!OS.IsWinCE) {
- OS.NotifyWinEvent (OS.EVENT_OBJECT_FOCUS, handle, OS.OBJID_CLIENT, index + 1);
- }
- }
- }
- return LRESULT.ZERO;
-}
-
-LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. For some reason, capturing
- * the mouse after processing the mouse event for the
- * widget interferes with the normal mouse processing
- * for the widget. The fix is to avoid the automatic
- * mouse capture.
- */
- LRESULT result = sendMouseDownEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
- if (result == LRESULT.ZERO) return result;
-
- /* Look for check/uncheck */
- if ((style & SWT.CHECK) != 0) {
- LVHITTESTINFO pinfo = new LVHITTESTINFO ();
- pinfo.x = OS.GET_X_LPARAM (lParam);
- pinfo.y = OS.GET_Y_LPARAM (lParam);
- /*
- * Note that when the table has LVS_EX_FULLROWSELECT and the
- * user clicks anywhere on a row except on the check box, all
- * of the bits are set. The hit test flags are LVHT_ONITEM.
- * This means that a bit test for LVHT_ONITEMSTATEICON is not
- * the correct way to determine that the user has selected
- * the check box, equality is needed.
- */
- int index = (int)/*64*/OS.SendMessage (handle, OS.LVM_HITTEST, 0, pinfo);
- if (index != -1 && pinfo.flags == OS.LVHT_ONITEMSTATEICON) {
- TableItem item = _getItem (index);
- item.setChecked (!item.getChecked (), true);
- if (!OS.IsWinCE) {
- OS.NotifyWinEvent (OS.EVENT_OBJECT_FOCUS, handle, OS.OBJID_CLIENT, index + 1);
- }
- }
- }
- return result;
-}
-
-LRESULT WM_MOUSEHOVER (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. Despite the fact that hot
- * tracking is not enabled, the hot tracking code
- * in WM_MOUSEHOVER is executed causing the item
- * under the cursor to be selected. The fix is to
- * avoid calling the window proc.
- */
- LRESULT result = super.WM_MOUSEHOVER (wParam, lParam);
- int bits = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- int mask = OS.LVS_EX_ONECLICKACTIVATE | OS.LVS_EX_TRACKSELECT | OS.LVS_EX_TWOCLICKACTIVATE;
- if ((bits & mask) != 0) return result;
- return LRESULT.ZERO;
-}
-
-LRESULT WM_PAINT (int /*long*/ wParam, int /*long*/ lParam) {
- if (!ignoreShrink) {
- /* Resize the item array to match the item count */
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (items.length > 4 && items.length - count > 3) {
- int length = Math.max (4, (count + 3) / 4 * 4);
- TableItem [] newItems = new TableItem [length];
- System.arraycopy (items, 0, newItems, 0, count);
- items = newItems;
- }
- }
- if (fixScrollWidth) setScrollWidth (null, true);
- if (!OS.IsWinCE && OS.COMCTL32_MAJOR < 6) {
- if ((style & SWT.DOUBLE_BUFFERED) != 0 || findImageControl () != null) {
- int bits = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((bits & OS.LVS_EX_DOUBLEBUFFER) == 0) {
- GC gc = null;
- int /*long*/ paintDC = 0;
- PAINTSTRUCT ps = new PAINTSTRUCT ();
- boolean hooksPaint = hooks (SWT.Paint) || filters (SWT.Paint);
- if (hooksPaint) {
- GCData data = new GCData ();
- data.ps = ps;
- data.hwnd = handle;
- gc = GC.win32_new (this, data);
- paintDC = gc.handle;
- } else {
- paintDC = OS.BeginPaint (handle, ps);
- }
- int width = ps.right - ps.left;
- int height = ps.bottom - ps.top;
- if (width != 0 && height != 0) {
- int /*long*/ hDC = OS.CreateCompatibleDC (paintDC);
- POINT lpPoint1 = new POINT (), lpPoint2 = new POINT ();
- OS.SetWindowOrgEx (hDC, ps.left, ps.top, lpPoint1);
- OS.SetBrushOrgEx (hDC, ps.left, ps.top, lpPoint2);
- int /*long*/ hBitmap = OS.CreateCompatibleBitmap (paintDC, width, height);
- int /*long*/ hOldBitmap = OS.SelectObject (hDC, hBitmap);
- if ((int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) != OS.CLR_NONE) {
- RECT rect = new RECT ();
- OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
- drawBackground (hDC, rect);
- }
- callWindowProc (handle, OS.WM_PAINT, hDC, 0);
- OS.SetWindowOrgEx (hDC, lpPoint1.x, lpPoint1.y, null);
- OS.SetBrushOrgEx (hDC, lpPoint2.x, lpPoint2.y, null);
- OS.BitBlt (paintDC, ps.left, ps.top, width, height, hDC, 0, 0, OS.SRCCOPY);
- OS.SelectObject (hDC, hOldBitmap);
- OS.DeleteObject (hBitmap);
- OS.DeleteObject (hDC);
- if (hooksPaint) {
- Event event = new Event ();
- event.gc = gc;
- event.x = ps.left;
- event.y = ps.top;
- event.width = ps.right - ps.left;
- event.height = ps.bottom - ps.top;
- sendEvent (SWT.Paint, event);
- // widget could be disposed at this point
- event.gc = null;
- }
- }
- if (hooksPaint) {
- gc.dispose ();
- } else {
- OS.EndPaint (handle, ps);
- }
- return LRESULT.ZERO;
- }
- }
- }
- return super.WM_PAINT (wParam, lParam);
-}
-
-LRESULT WM_RBUTTONDBLCLK (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. When the user selects outside of
- * a table item, Windows deselects all the items, even
- * when the table is multi-select. While not strictly
- * wrong, this is unexpected. The fix is to detect the
- * case and avoid calling the window proc.
- */
- LVHITTESTINFO pinfo = new LVHITTESTINFO ();
- pinfo.x = OS.GET_X_LPARAM (lParam);
- pinfo.y = OS.GET_Y_LPARAM (lParam);
- OS.SendMessage (handle, OS.LVM_HITTEST, 0, pinfo);
- Display display = this.display;
- display.captureChanged = false;
- sendMouseEvent (SWT.MouseDown, 3, handle, OS.WM_RBUTTONDOWN, wParam, lParam);
- if (sendMouseEvent (SWT.MouseDoubleClick, 3, handle, OS.WM_RBUTTONDBLCLK, wParam, lParam)) {
- if (pinfo.iItem != -1) callWindowProc (handle, OS.WM_RBUTTONDBLCLK, wParam, lParam);
- }
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- return LRESULT.ZERO;
-}
-
-LRESULT WM_RBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. For some reason, capturing
- * the mouse after processing the mouse event for the
- * widget interferes with the normal mouse processing
- * for the widget. The fix is to avoid the automatic
- * mouse capture.
- */
- return sendMouseDownEvent (SWT.MouseDown, 3, OS.WM_RBUTTONDOWN, wParam, lParam);
-}
-
-LRESULT WM_SETFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SETFOCUS (wParam, lParam);
- /*
- * Bug in Windows. When focus is gained after the
- * selection has been changed using LVM_SETITEMSTATE,
- * Windows redraws the selected text but does not
- * redraw the image or the check box, leaving them
- * appearing unselected. The fix is to redraw
- * the table.
- */
- if (imageList != null || (style & SWT.CHECK) != 0) {
- OS.InvalidateRect (handle, null, false);
- }
-
- /*
- * Bug in Windows. For some reason, the table does
- * not set the default focus rectangle to be the first
- * item in the table when it gets focus and there is
- * no selected item. The fix to make the first item
- * be the focus item.
- */
- int count = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (count == 0) return result;
- int index = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);
- if (index == -1) {
- LVITEM lvItem = new LVITEM ();
- lvItem.state = OS.LVIS_FOCUSED;
- lvItem.stateMask = OS.LVIS_FOCUSED;
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_SETITEMSTATE, 0, lvItem);
- ignoreSelect = false;
- }
- return result;
-}
-
-LRESULT WM_SETFONT (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SETFONT (wParam, lParam);
- if (result != null) return result;
-
- /*
- * Bug in Windows. When a header has a sort indicator
- * triangle, Windows resizes the indicator based on the
- * size of the n-1th font. The fix is to always make
- * the n-1th font be the default. This makes the sort
- * indicator always be the default size.
- *
- * NOTE: The table window proc sets the actual font in
- * the header so that all that is necessary here is to
- * set the default first.
- */
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- OS.SendMessage (hwndHeader, OS.WM_SETFONT, 0, lParam);
-
- if (headerToolTipHandle != 0) {
- OS.SendMessage (headerToolTipHandle, OS.WM_SETFONT, wParam, lParam);
- }
- return result;
-}
-
-LRESULT WM_SETREDRAW (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SETREDRAW (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. When LVM_SETBKCOLOR is used with CLR_NONE
- * to make the background of the table transparent, drawing becomes
- * slow. The fix is to temporarily clear CLR_NONE when redraw is
- * turned off.
- */
- if (wParam == 1) {
- if ((int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) != OS.CLR_NONE) {
- if (hooks (SWT.MeasureItem) || hooks (SWT.EraseItem) || hooks (SWT.PaintItem)) {
- OS.SendMessage (handle, OS.LVM_SETBKCOLOR, 0, OS.CLR_NONE);
- }
- }
- }
- /*
- * Bug in Windows. When WM_SETREDRAW is used to turn off
- * redraw for a list, table or tree, the background of the
- * control is drawn. The fix is to call DefWindowProc(),
- * which stops all graphics output to the control.
- */
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, wParam, lParam);
- int /*long*/ code = callWindowProc (handle, OS.WM_SETREDRAW, wParam, lParam);
- if (wParam == 0) {
- if ((int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) == OS.CLR_NONE) {
- OS.SendMessage (handle, OS.LVM_SETBKCOLOR, 0, 0xFFFFFF);
- }
- }
- return code == 0 ? LRESULT.ZERO : new LRESULT (code);
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- if (ignoreResize) return null;
- if (hooks (SWT.EraseItem) || hooks (SWT.PaintItem)) {
- OS.InvalidateRect (handle, null, true);
- }
- if (resizeCount != 0) {
- wasResized = true;
- return null;
- }
- return super.WM_SIZE (wParam, lParam);
-}
-
-LRESULT WM_SYSCOLORCHANGE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SYSCOLORCHANGE (wParam, lParam);
- if (result != null) return result;
- if (findBackgroundControl () == null) {
- setBackgroundPixel (defaultBackground ());
- } else {
- int oldPixel = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0);
- if (oldPixel != OS.CLR_NONE) {
- if (findImageControl () == null) {
- if ((style & SWT.CHECK) != 0) fixCheckboxImageListColor (true);
- }
- }
- }
- return result;
-}
-
-LRESULT WM_HSCROLL (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Bug in Windows. When a table that is drawing grid lines
- * is slowly scrolled horizontally to the left, the table does
- * not redraw the newly exposed vertical grid lines. The fix
- * is to save the old scroll position, call the window proc,
- * get the new scroll position and redraw the new area.
- */
- int oldPos = 0;
- int bits = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((bits & OS.LVS_EX_GRIDLINES) != 0) {
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_POS;
- OS.GetScrollInfo (handle, OS.SB_HORZ, info);
- oldPos = info.nPos;
- }
-
- /*
- * Feature in Windows. When there are many columns in a table,
- * scrolling performance can be improved by unsubclassing the
- * window proc so that internal messages are dispatched directly
- * to the table. If the application expects to see a paint event
- * or has a child whose font, foreground or background color might
- * be needed, the window proc cannot be unsubclassed
- *
- * NOTE: The header tooltip can subclass the header proc so the
- * current proc must be restored or header tooltips stop working.
- */
- int /*long*/ oldHeaderProc = 0, oldTableProc = 0;
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- boolean fixSubclass = isOptimizedRedraw ();
- if (fixSubclass) {
- oldTableProc = OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, TableProc);
- oldHeaderProc = OS.SetWindowLongPtr (hwndHeader, OS.GWLP_WNDPROC, HeaderProc);
- }
-
- /*
- * Feature in Windows. For some reason, when the table window
- * proc processes WM_HSCROLL or WM_VSCROLL when there are many
- * columns in the table, scrolling is slow and the table does
- * not keep up with the position of the scroll bar. The fix
- * is to turn off redraw, scroll, turn redraw back on and redraw
- * the entire table. Strangly, redrawing the entire table is
- * faster.
- */
- boolean fixScroll = false;
- if (OS.LOWORD (wParam) != OS.SB_ENDSCROLL) {
- if (OS.COMCTL32_MAJOR >= 6) {
- if (columnCount > H_SCROLL_LIMIT) {
- int rowCount = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETCOUNTPERPAGE, 0, 0);
- if (rowCount > V_SCROLL_LIMIT) fixScroll = getDrawing () && OS.IsWindowVisible (handle);
- }
- }
- }
- if (fixScroll) OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- LRESULT result = super.WM_HSCROLL (wParam, lParam);
- if (fixScroll) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, null, 0, flags);
- /*
- * Feature in Windows. On Vista only, it is faster to
- * compute and answer the data for the visible columns
- * of a table when scrolling, rather than just return
- * the data for each column when asked.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- RECT headerRect = new RECT (), rect = new RECT ();
- OS.GetClientRect (handle, rect);
- boolean [] visible = new boolean [columnCount];
- for (int i=0; i<columnCount; i++) {
- visible [i] = true;
- if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, i, headerRect) != 0) {
- OS.MapWindowPoints (hwndHeader, handle, headerRect, 2);
- visible [i] = OS.IntersectRect(headerRect, rect, headerRect);
- }
- }
- try {
- display.hwndParent = OS.GetParent (handle);
- display.columnVisible = visible;
- OS.UpdateWindow (handle);
- } finally {
- display.columnVisible = null;
- }
- }
- }
-
- if (fixSubclass) {
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, oldTableProc);
- OS.SetWindowLongPtr (hwndHeader, OS.GWLP_WNDPROC, oldHeaderProc);
- }
-
- /*
- * Bug in Windows. When a table that is drawing grid lines
- * is slowly scrolled horizontally to the left, the table does
- * not redraw the newly exposed vertical grid lines. The fix
- * is to save the old scroll position, call the window proc,
- * get the new scroll position and redraw the new area.
- */
- if ((bits & OS.LVS_EX_GRIDLINES) != 0) {
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_POS;
- OS.GetScrollInfo (handle, OS.SB_HORZ, info);
- int newPos = info.nPos;
- if (newPos < oldPos) {
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- rect.right = oldPos - newPos + GRID_WIDTH;
- OS.InvalidateRect (handle, rect, true);
- }
- }
- return result;
-}
-
-LRESULT WM_VSCROLL (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * When there are many columns in a table, scrolling performance
- * can be improved by temporarily unsubclassing the window proc
- * so that internal messages are dispatched directly to the table.
- * If the application expects to see a paint event or has a child
- * whose font, foreground or background color might be needed,
- * the window proc cannot be unsubclassed.
- *
- * NOTE: The header tooltip can subclass the header proc so the
- * current proc must be restored or header tooltips stop working.
- */
- int /*long*/ oldHeaderProc = 0, oldTableProc = 0;
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- boolean fixSubclass = isOptimizedRedraw ();
- if (fixSubclass) {
- oldTableProc = OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, TableProc);
- oldHeaderProc = OS.SetWindowLongPtr (hwndHeader, OS.GWLP_WNDPROC, HeaderProc);
- }
-
- /*
- * Feature in Windows. For some reason, when the table window
- * proc processes WM_HSCROLL or WM_VSCROLL when there are many
- * columns in the table, scrolling is slow and the table does
- * not keep up with the position of the scroll bar. The fix
- * is to turn off redraw, scroll, turn redraw back on and redraw
- * the entire table. Strangly, redrawing the entire table is
- * faster.
- */
- boolean fixScroll = false;
- if (OS.LOWORD (wParam) != OS.SB_ENDSCROLL) {
- if (OS.COMCTL32_MAJOR >= 6) {
- if (columnCount > H_SCROLL_LIMIT) {
- int rowCount = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETCOUNTPERPAGE, 0, 0);
- if (rowCount > V_SCROLL_LIMIT) fixScroll = getDrawing () && OS.IsWindowVisible (handle);
- }
- }
- }
- if (fixScroll) OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- LRESULT result = super.WM_VSCROLL (wParam, lParam);
- if (fixScroll) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, null, 0, flags);
- /*
- * Feature in Windows. On Vista only, it is faster to
- * compute and answer the data for the visible columns
- * of a table when scrolling, rather than just return
- * the data for each column when asked.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- RECT headerRect = new RECT (), rect = new RECT ();
- OS.GetClientRect (handle, rect);
- boolean [] visible = new boolean [columnCount];
- for (int i=0; i<columnCount; i++) {
- visible [i] = true;
- if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, i, headerRect) != 0) {
- OS.MapWindowPoints (hwndHeader, handle, headerRect, 2);
- visible [i] = OS.IntersectRect(headerRect, rect, headerRect);
- }
- }
- try {
- display.hwndParent = OS.GetParent (handle);
- display.columnVisible = visible;
- OS.UpdateWindow (handle);
- } finally {
- display.columnVisible = null;
- }
- }
- }
-
- if (fixSubclass) {
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, oldTableProc);
- OS.SetWindowLongPtr (hwndHeader, OS.GWLP_WNDPROC, oldHeaderProc);
- }
-
- /*
- * Bug in Windows. When a table is drawing grid lines and the
- * user scrolls vertically up or down by a line or a page, the
- * table does not redraw the grid lines for newly exposed items.
- * The fix is to invalidate the items.
- */
- int bits = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((bits & OS.LVS_EX_GRIDLINES) != 0) {
- int code = OS.LOWORD (wParam);
- switch (code) {
- case OS.SB_ENDSCROLL:
- case OS.SB_THUMBPOSITION:
- case OS.SB_THUMBTRACK:
- case OS.SB_TOP:
- case OS.SB_BOTTOM:
- break;
- case OS.SB_LINEDOWN:
- case OS.SB_LINEUP:
- RECT rect = new RECT ();
- OS.GetWindowRect (hwndHeader, rect);
- int headerHeight = rect.bottom - rect.top;
- RECT clientRect = new RECT ();
- OS.GetClientRect (handle, clientRect);
- clientRect.top += headerHeight;
- int /*long*/ empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0);
- int /*long*/ oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0);
- int itemHeight = OS.HIWORD (oneItem) - OS.HIWORD (empty);
- if (code == OS.SB_LINEDOWN) {
- clientRect.top = clientRect.bottom - itemHeight - GRID_WIDTH;
- } else {
- clientRect.bottom = clientRect.top + itemHeight + GRID_WIDTH;
- }
- OS.InvalidateRect (handle, clientRect, true);
- break;
- case OS.SB_PAGEDOWN:
- case OS.SB_PAGEUP:
- OS.InvalidateRect (handle, null, true);
- break;
- }
- }
- return result;
-}
-
-LRESULT wmMeasureChild (int /*long*/ wParam, int /*long*/ lParam) {
- MEASUREITEMSTRUCT struct = new MEASUREITEMSTRUCT ();
- OS.MoveMemory (struct, lParam, MEASUREITEMSTRUCT.sizeof);
- if (itemHeight == -1) {
- int /*long*/ empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0);
- int /*long*/ oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0);
- struct.itemHeight = OS.HIWORD (oneItem) - OS.HIWORD (empty);
- } else {
- struct.itemHeight = itemHeight;
- }
- OS.MoveMemory (lParam, struct, MEASUREITEMSTRUCT.sizeof);
- return null;
-}
-
-LRESULT wmNotify (NMHDR hdr, int /*long*/ wParam, int /*long*/ lParam) {
- int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.LVM_GETTOOLTIPS, 0, 0);
- if (hdr.hwndFrom == hwndToolTip) {
- LRESULT result = wmNotifyToolTip (hdr, wParam, lParam);
- if (result != null) return result;
- }
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (hdr.hwndFrom == hwndHeader) {
- LRESULT result = wmNotifyHeader (hdr, wParam, lParam);
- if (result != null) return result;
- }
- return super.wmNotify (hdr, wParam, lParam);
-}
-
-LRESULT wmNotifyChild (NMHDR hdr, int /*long*/ wParam, int /*long*/ lParam) {
- switch (hdr.code) {
- case OS.LVN_ODFINDITEMA:
- case OS.LVN_ODFINDITEMW: {
- if ((style & SWT.VIRTUAL) != 0) return new LRESULT (-1);
- break;
- }
- case OS.LVN_ODSTATECHANGED: {
- if ((style & SWT.VIRTUAL) != 0) {
- if (!ignoreSelect) {
- NMLVODSTATECHANGE lpStateChange = new NMLVODSTATECHANGE ();
- OS.MoveMemory (lpStateChange, lParam, NMLVODSTATECHANGE.sizeof);
- boolean oldSelected = (lpStateChange.uOldState & OS.LVIS_SELECTED) != 0;
- boolean newSelected = (lpStateChange.uNewState & OS.LVIS_SELECTED) != 0;
- if (oldSelected != newSelected) wasSelected = true;
- }
- }
- break;
- }
- case OS.LVN_GETDISPINFOA:
- case OS.LVN_GETDISPINFOW: {
-// if (drawCount != 0 || !OS.IsWindowVisible (handle)) break;
- NMLVDISPINFO plvfi = new NMLVDISPINFO ();
- OS.MoveMemory (plvfi, lParam, NMLVDISPINFO.sizeof);
-
- boolean [] visible = display.columnVisible;
- if (visible != null && !visible [plvfi.iSubItem]) {
- break;
- }
-
- /*
- * When an item is being deleted from a virtual table, do not
- * allow the application to provide data for a new item that
- * becomes visible until the item has been removed from the
- * items array. Because arbitrary application code can run
- * during the callback, the items array might be accessed
- * in an inconsistent state. Rather than answering the data
- * right away, queue a redraw for later.
- */
- if ((style & SWT.VIRTUAL) != 0) {
- if (ignoreShrink) {
- OS.SendMessage (handle, OS.LVM_REDRAWITEMS, plvfi.iItem, plvfi.iItem);
- break;
- }
- }
-
- /*
- * Feature in Windows. When a new table item is inserted
- * using LVM_INSERTITEM in a table that is transparent
- * (ie. LVM_SETBKCOLOR has been called with CLR_NONE),
- * TVM_INSERTITEM calls LVN_GETDISPINFO before the item
- * has been added to the array. The fix is to check for
- * null.
- */
- TableItem item = _getItem (plvfi.iItem);
- if (item == null) break;
-
- /*
- * The cached flag is used by both virtual and non-virtual
- * tables to indicate that Windows has asked at least once
- * for a table item.
- */
- if (!item.cached) {
- if ((style & SWT.VIRTUAL) != 0) {
- lastIndexOf = plvfi.iItem;
- if (!checkData (item, lastIndexOf, false)) break;
- TableItem newItem = fixScrollWidth ? null : item;
- if (setScrollWidth (newItem, true)) {
- OS.InvalidateRect (handle, null, true);
- }
- }
- item.cached = true;
- }
- if ((plvfi.mask & OS.LVIF_TEXT) != 0) {
- String string = null;
- if (plvfi.iSubItem == 0) {
- string = item.text;
- } else {
- String [] strings = item.strings;
- if (strings != null) string = strings [plvfi.iSubItem];
- }
- if (string != null) {
- /*
- * Bug in Windows. When pszText points to a zero length
- * NULL terminated string, Windows correctly draws the
- * empty string but the cache of the bounds for the item
- * is not reset. This means that when the text for the
- * item is set and then reset to an empty string, the
- * selection draws using the bounds of the previous text.
- * The fix is to use a space rather than an empty string
- * when anything but a tool tip is requested (to avoid
- * a tool tip that is a single space).
- *
- * NOTE: This is only a problem for items in the first
- * column. Assigning NULL to other columns stops Windows
- * from drawing the selection when LVS_EX_FULLROWSELECT
- * is set.
- */
- int length = Math.min (string.length (), plvfi.cchTextMax - 1);
- if (!tipRequested && plvfi.iSubItem == 0 && length == 0) {
- string = " "; //$NON-NLS-1$
- length = 1;
- }
- char [] buffer = display.tableBuffer;
- if (buffer == null || plvfi.cchTextMax > buffer.length) {
- buffer = display.tableBuffer = new char [plvfi.cchTextMax];
- }
- string.getChars (0, length, buffer, 0);
- buffer [length++] = 0;
- if (OS.IsUnicode) {
- OS.MoveMemory (plvfi.pszText, buffer, length * 2);
- } else {
- OS.WideCharToMultiByte (getCodePage (), 0, buffer, length, plvfi.pszText, plvfi.cchTextMax, null, null);
- OS.MoveMemory (plvfi.pszText + plvfi.cchTextMax - 1, new byte [1], 1);
- }
- }
- }
- boolean move = false;
- if ((plvfi.mask & OS.LVIF_IMAGE) != 0) {
- Image image = null;
- if (plvfi.iSubItem == 0) {
- image = item.image;
- } else {
- Image [] images = item.images;
- if (images != null) image = images [plvfi.iSubItem];
- }
- if (image != null) {
- plvfi.iImage = imageIndex (image, plvfi.iSubItem);
- move = true;
- }
- }
- if ((plvfi.mask & OS.LVIF_STATE) != 0) {
- if (plvfi.iSubItem == 0) {
- int state = 1;
- if (item.checked) state++;
- if (item.grayed) state +=2;
- plvfi.state = state << 12;
- plvfi.stateMask = OS.LVIS_STATEIMAGEMASK;
- move = true;
- }
- }
- if ((plvfi.mask & OS.LVIF_INDENT) != 0) {
- if (plvfi.iSubItem == 0) {
- plvfi.iIndent = item.imageIndent;
- move = true;
- }
- }
- if (move) OS.MoveMemory (lParam, plvfi, NMLVDISPINFO.sizeof);
- break;
- }
- case OS.NM_CUSTOMDRAW: {
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (hdr.hwndFrom == hwndHeader) break;
- if (!customDraw && findImageControl () == null) {
- /*
- * Feature in Windows. When the table is disabled, it draws
- * with a gray background but does not gray the text. The fix
- * is to explicitly gray the text using Custom Draw.
- */
- if (OS.IsWindowEnabled (handle)) {
- /*
- * Feature in Windows. On Vista using the explorer theme,
- * Windows draws a vertical line to separate columns. When
- * there is only a single column, the line looks strange.
- * The fix is to draw the background using custom draw.
- */
- if (!explorerTheme || columnCount != 0) break;
- }
- }
- NMLVCUSTOMDRAW nmcd = new NMLVCUSTOMDRAW ();
- OS.MoveMemory (nmcd, lParam, NMLVCUSTOMDRAW.sizeof);
- switch (nmcd.dwDrawStage) {
- case OS.CDDS_PREPAINT: return CDDS_PREPAINT (nmcd, wParam, lParam);
- case OS.CDDS_ITEMPREPAINT: return CDDS_ITEMPREPAINT (nmcd, wParam, lParam);
- case OS.CDDS_ITEMPOSTPAINT: return CDDS_ITEMPOSTPAINT (nmcd, wParam, lParam);
- case OS.CDDS_SUBITEMPREPAINT: return CDDS_SUBITEMPREPAINT (nmcd, wParam, lParam);
- case OS.CDDS_SUBITEMPOSTPAINT: return CDDS_SUBITEMPOSTPAINT (nmcd, wParam, lParam);
- case OS.CDDS_POSTPAINT: return CDDS_POSTPAINT (nmcd, wParam, lParam);
- }
- break;
- }
- case OS.LVN_MARQUEEBEGIN: {
- if ((style & SWT.SINGLE) != 0) return LRESULT.ONE;
- if (hooks (SWT.MouseDown) || hooks (SWT.MouseUp)) {
- return LRESULT.ONE;
- }
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- if (findImageControl () != null) return LRESULT.ONE;
- }
- break;
- }
- case OS.LVN_BEGINDRAG:
- case OS.LVN_BEGINRDRAG: {
- if (OS.GetKeyState (OS.VK_LBUTTON) >= 0) break;
- dragStarted = true;
- if (hdr.code == OS.LVN_BEGINDRAG) {
- int pos = OS.GetMessagePos ();
- POINT pt = new POINT ();
- OS.POINTSTOPOINT (pt, pos);
- OS.ScreenToClient (handle, pt);
- sendDragEvent (1, pt.x, pt.y);
- }
- break;
- }
- case OS.LVN_COLUMNCLICK: {
- NMLISTVIEW pnmlv = new NMLISTVIEW ();
- OS.MoveMemory(pnmlv, lParam, NMLISTVIEW.sizeof);
- TableColumn column = columns [pnmlv.iSubItem];
- if (column != null) {
- column.postEvent (SWT.Selection);
- }
- break;
- }
- case OS.LVN_ITEMACTIVATE: {
- if (ignoreActivate) break;
- NMLISTVIEW pnmlv = new NMLISTVIEW ();
- OS.MoveMemory(pnmlv, lParam, NMLISTVIEW.sizeof);
- if (pnmlv.iItem != -1) {
- Event event = new Event ();
- event.item = _getItem (pnmlv.iItem);
- postEvent (SWT.DefaultSelection, event);
- }
- break;
- }
- case OS.LVN_ITEMCHANGED: {
- if (fullRowSelect) {
- fullRowSelect = false;
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, OS.LVS_EX_FULLROWSELECT, 0);
- }
- if (!ignoreSelect) {
- NMLISTVIEW pnmlv = new NMLISTVIEW ();
- OS.MoveMemory (pnmlv, lParam, NMLISTVIEW.sizeof);
- if ((pnmlv.uChanged & OS.LVIF_STATE) != 0) {
- if (pnmlv.iItem == -1) {
- wasSelected = true;
- } else {
- boolean oldSelected = (pnmlv.uOldState & OS.LVIS_SELECTED) != 0;
- boolean newSelected = (pnmlv.uNewState & OS.LVIS_SELECTED) != 0;
- if (oldSelected != newSelected) wasSelected = true;
- }
- }
- }
- if (hooks (SWT.EraseItem) || hooks (SWT.PaintItem)) {
- int /*long*/ hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int count = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- if (count != 0) {
- forceResize ();
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- NMLISTVIEW pnmlv = new NMLISTVIEW ();
- OS.MoveMemory (pnmlv, lParam, NMLISTVIEW.sizeof);
- if (pnmlv.iItem != -1) {
- RECT itemRect = new RECT ();
- itemRect.left = OS.LVIR_BOUNDS;
- ignoreCustomDraw = true;
- OS.SendMessage (handle, OS. LVM_GETITEMRECT, pnmlv.iItem, itemRect);
- ignoreCustomDraw = false;
- RECT headerRect = new RECT ();
- int index = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, count - 1, 0);
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect);
- OS.MapWindowPoints (hwndHeader, handle, headerRect, 2);
- rect.left = headerRect.right;
- rect.top = itemRect.top;
- rect.bottom = itemRect.bottom;
- OS.InvalidateRect (handle, rect, true);
- }
- }
- }
- break;
- }
- case OS.NM_RECOGNIZEGESTURE:
- /*
- * Feature on Pocket PC. The tree and table controls detect the tap
- * and hold gesture by default. They send a GN_CONTEXTMENU message to show
- * the popup menu. This default behaviour is unwanted on Pocket PC 2002
- * when no menu has been set, as it still draws a red circle. The fix
- * is to disable this default behaviour when no menu is set by returning
- * TRUE when receiving the Pocket PC 2002 specific NM_RECOGNIZEGESTURE
- * message.
- */
- if (OS.IsPPC) {
- boolean hasMenu = menu != null && !menu.isDisposed ();
- if (!hasMenu && !hooks (SWT.MenuDetect)) return LRESULT.ONE;
- }
- break;
- case OS.GN_CONTEXTMENU:
- if (OS.IsPPC) {
- boolean hasMenu = menu != null && !menu.isDisposed ();
- if (hasMenu || hooks (SWT.MenuDetect)) {
- NMRGINFO nmrg = new NMRGINFO ();
- OS.MoveMemory (nmrg, lParam, NMRGINFO.sizeof);
- showMenu (nmrg.x, nmrg.y);
- return LRESULT.ONE;
- }
- }
- break;
- }
- return super.wmNotifyChild (hdr, wParam, lParam);
-}
-
-LRESULT wmNotifyHeader (NMHDR hdr, int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. On NT, the automatically created
- * header control is created as a UNICODE window, not an
- * ANSI window despite the fact that the parent is created
- * as an ANSI window. This means that it sends UNICODE
- * notification messages to the parent window on NT for
- * no good reason. The data and size in the NMHEADER and
- * HDITEM structs is identical between the platforms so no
- * different message is actually necessary. Despite this,
- * Windows sends different messages. The fix is to look
- * for both messages, despite the platform. This works
- * because only one will be sent on either platform, never
- * both.
- */
- switch (hdr.code) {
- case OS.HDN_BEGINTRACKW:
- case OS.HDN_BEGINTRACKA:
- case OS.HDN_DIVIDERDBLCLICKW:
- case OS.HDN_DIVIDERDBLCLICKA: {
- if (columnCount == 0) return LRESULT.ONE;
- NMHEADER phdn = new NMHEADER ();
- OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
- TableColumn column = columns [phdn.iItem];
- if (column != null && !column.getResizable ()) {
- return LRESULT.ONE;
- }
- ignoreColumnMove = true;
- switch (hdr.code) {
- case OS.HDN_DIVIDERDBLCLICKW:
- case OS.HDN_DIVIDERDBLCLICKA:
- /*
- * Bug in Windows. When the first column of a table does not
- * have an image and the user double clicks on the divider,
- * Windows packs the column but does not take into account
- * the empty space left for the image. The fix is to pack
- * the column explicitly rather than letting Windows do it.
- *
- * NOTE: This bug does not happen on Vista.
- */
- boolean fixPack = false;
- if (!OS.IsWinCE && OS.WIN32_VERSION < OS.VERSION (6, 0)) {
- fixPack = phdn.iItem == 0 && !firstColumnImage;
- }
- if (column != null && (fixPack || hooks (SWT.MeasureItem))) {
- column.pack ();
- return LRESULT.ONE;
- }
- }
- break;
- }
- case OS.NM_RELEASEDCAPTURE: {
- if (!ignoreColumnMove) {
- for (int i=0; i<columnCount; i++) {
- TableColumn column = columns [i];
- column.updateToolTip (i);
- }
- }
- ignoreColumnMove = false;
- break;
- }
- case OS.HDN_BEGINDRAG: {
- if (ignoreColumnMove) return LRESULT.ONE;
- int bits = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((bits & OS.LVS_EX_HEADERDRAGDROP) == 0) break;
- if (columnCount == 0) return LRESULT.ONE;
- NMHEADER phdn = new NMHEADER ();
- OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
- if (phdn.iItem != -1) {
- TableColumn column = columns [phdn.iItem];
- if (column != null && !column.getMoveable ()) {
- ignoreColumnMove = true;
- return LRESULT.ONE;
- }
- }
- break;
- }
- case OS.HDN_ENDDRAG: {
- int bits = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((bits & OS.LVS_EX_HEADERDRAGDROP) == 0) break;
- NMHEADER phdn = new NMHEADER ();
- OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
- if (phdn.iItem != -1 && phdn.pitem != 0) {
- HDITEM pitem = new HDITEM ();
- OS.MoveMemory (pitem, phdn.pitem, HDITEM.sizeof);
- if ((pitem.mask & OS.HDI_ORDER) != 0 && pitem.iOrder != -1) {
- if (columnCount == 0) break;
- int [] order = new int [columnCount];
- OS.SendMessage (handle, OS.LVM_GETCOLUMNORDERARRAY, columnCount, order);
- int index = 0;
- while (index < order.length) {
- if (order [index] == phdn.iItem) break;
- index++;
- }
- if (index == order.length) index = 0;
- if (index == pitem.iOrder) break;
- int start = Math.min (index, pitem.iOrder);
- int end = Math.max (index, pitem.iOrder);
- ignoreColumnMove = false;
- for (int i=start; i<=end; i++) {
- TableColumn column = columns [order [i]];
- if (!column.isDisposed ()) {
- column.postEvent (SWT.Move);
- }
- }
- }
- }
- break;
- }
- case OS.HDN_ITEMCHANGEDW:
- case OS.HDN_ITEMCHANGEDA: {
- /*
- * Bug in Windows. When a table has the LVS_EX_GRIDLINES extended
- * style and the user drags any column over the first column in the
- * table, making the size become zero, when the user drags a column
- * such that the size of the first column becomes non-zero, the grid
- * lines are not redrawn. The fix is to detect the case and force
- * a redraw of the first column.
- */
- int width = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, 0, 0);
- if (lastWidth == 0 && width > 0) {
- int bits = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((bits & OS.LVS_EX_GRIDLINES) != 0) {
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- rect.right = rect.left + width;
- OS.InvalidateRect (handle, rect, true);
- }
- }
- lastWidth = width;
- if (!ignoreColumnResize) {
- NMHEADER phdn = new NMHEADER ();
- OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
- if (phdn.pitem != 0) {
- HDITEM pitem = new HDITEM ();
- OS.MoveMemory (pitem, phdn.pitem, HDITEM.sizeof);
- if ((pitem.mask & OS.HDI_WIDTH) != 0) {
- TableColumn column = columns [phdn.iItem];
- if (column != null) {
- column.updateToolTip (phdn.iItem);
- column.sendEvent (SWT.Resize);
- if (isDisposed ()) return LRESULT.ZERO;
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the column in the move
- * event. If this happens, process the move event
- * for those columns that have not been destroyed.
- */
- TableColumn [] newColumns = new TableColumn [columnCount];
- System.arraycopy (columns, 0, newColumns, 0, columnCount);
- int [] order = new int [columnCount];
- OS.SendMessage (handle, OS.LVM_GETCOLUMNORDERARRAY, columnCount, order);
- boolean moved = false;
- for (int i=0; i<columnCount; i++) {
- TableColumn nextColumn = newColumns [order [i]];
- if (moved && !nextColumn.isDisposed ()) {
- nextColumn.updateToolTip (order [i]);
- nextColumn.sendEvent (SWT.Move);
- }
- if (nextColumn == column) moved = true;
- }
- }
- }
- }
- }
- break;
- }
- case OS.HDN_ITEMDBLCLICKW:
- case OS.HDN_ITEMDBLCLICKA: {
- NMHEADER phdn = new NMHEADER ();
- OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
- TableColumn column = columns [phdn.iItem];
- if (column != null) {
- column.postEvent (SWT.DefaultSelection);
- }
- break;
- }
- }
- return null;
-}
-
-LRESULT wmNotifyToolTip (NMHDR hdr, int /*long*/ wParam, int /*long*/ lParam) {
- if (OS.IsWinCE) return null;
- switch (hdr.code) {
- case OS.NM_CUSTOMDRAW: {
- if (toolTipText != null) break;
- if (isCustomToolTip ()) {
- NMTTCUSTOMDRAW nmcd = new NMTTCUSTOMDRAW ();
- OS.MoveMemory (nmcd, lParam, NMTTCUSTOMDRAW.sizeof);
- return wmNotifyToolTip (nmcd, lParam);
- }
- break;
- }
- case OS.TTN_GETDISPINFOA:
- case OS.TTN_GETDISPINFOW:
- case OS.TTN_SHOW: {
- LRESULT result = super.wmNotify (hdr, wParam, lParam);
- if (result != null) return result;
- if (hdr.code != OS.TTN_SHOW) tipRequested = true;
- int /*long*/ code = callWindowProc (handle, OS.WM_NOTIFY, wParam, lParam);
- if (hdr.code != OS.TTN_SHOW) tipRequested = false;
- if (toolTipText != null) break;
- if (isCustomToolTip ()) {
- LVHITTESTINFO pinfo = new LVHITTESTINFO ();
- int pos = OS.GetMessagePos ();
- POINT pt = new POINT();
- OS.POINTSTOPOINT (pt, pos);
- OS.ScreenToClient (handle, pt);
- pinfo.x = pt.x;
- pinfo.y = pt.y;
- /*
- * Bug in Windows. When LVM_SUBITEMHITTEST is used to hittest
- * a point that is above the table, instead of returning -1 to
- * indicate that the hittest failed, a negative index is returned.
- * The fix is to consider any value that is negative a failure.
- */
- if (OS.SendMessage (handle, OS.LVM_SUBITEMHITTEST, 0, pinfo) >= 0) {
- TableItem item = _getItem (pinfo.iItem);
- int /*long*/ hDC = OS.GetDC (handle);
- int /*long*/ oldFont = 0, newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- int /*long*/ hFont = item.fontHandle (pinfo.iSubItem);
- if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
- Event event = sendMeasureItemEvent (item, pinfo.iItem, pinfo.iSubItem, hDC);
- if (!isDisposed () && !item.isDisposed ()) {
- RECT itemRect = new RECT ();
- OS.SetRect (itemRect, event.x, event.y, event.x + event.width, event.y + event.height);
- if (hdr.code == OS.TTN_SHOW) {
- RECT toolRect = toolTipRect (itemRect);
- OS.MapWindowPoints (handle, 0, toolRect, 2);
- int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.LVM_GETTOOLTIPS, 0, 0);
- int flags = OS.SWP_NOACTIVATE | OS.SWP_NOZORDER;
- int width = toolRect.right - toolRect.left, height = toolRect.bottom - toolRect.top;
- SetWindowPos (hwndToolTip, 0, toolRect.left , toolRect.top, width, height, flags);
- } else {
- NMTTDISPINFO lpnmtdi = null;
- if (hdr.code == OS.TTN_GETDISPINFOA) {
- lpnmtdi = new NMTTDISPINFOA ();
- OS.MoveMemory ((NMTTDISPINFOA)lpnmtdi, lParam, NMTTDISPINFOA.sizeof);
- if (lpnmtdi.lpszText != 0) {
- OS.MoveMemory (lpnmtdi.lpszText, new byte [1], 1);
- OS.MoveMemory (lParam, (NMTTDISPINFOA)lpnmtdi, NMTTDISPINFOA.sizeof);
- }
- } else {
- lpnmtdi = new NMTTDISPINFOW ();
- OS.MoveMemory ((NMTTDISPINFOW)lpnmtdi, lParam, NMTTDISPINFOW.sizeof);
- if (lpnmtdi.lpszText != 0) {
- OS.MoveMemory (lpnmtdi.lpszText, new char [1], 2);
- OS.MoveMemory (lParam, (NMTTDISPINFOW)lpnmtdi, NMTTDISPINFOW.sizeof);
- }
- }
- RECT cellRect = item.getBounds (pinfo.iItem, pinfo.iSubItem, true, true, true, true, hDC);
- if (itemRect.right > cellRect.right) {
- //TEMPORARY CODE
- String string = " ";
-// String string = null;
-// if (pinfo.iSubItem == 0) {
-// string = item.text;
-// } else {
-// String [] strings = item.strings;
-// if (strings != null) string = strings [pinfo.iSubItem];
-// }
- if (string != null) {
- Shell shell = getShell ();
- char [] chars = new char [string.length () + 1];
- string.getChars (0, string.length (), chars, 0);
- if (hdr.code == OS.TTN_GETDISPINFOA) {
- byte [] bytes = new byte [chars.length * 2];
- OS.WideCharToMultiByte (getCodePage (), 0, chars, chars.length, bytes, bytes.length, null, null);
- shell.setToolTipText (lpnmtdi, bytes);
- OS.MoveMemory (lParam, (NMTTDISPINFOA)lpnmtdi, NMTTDISPINFOA.sizeof);
- } else {
- shell.setToolTipText (lpnmtdi, chars);
- OS.MoveMemory (lParam, (NMTTDISPINFOW)lpnmtdi, NMTTDISPINFOW.sizeof);
- }
- }
- }
- }
- }
- if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- }
- }
- return new LRESULT (code);
- }
- }
- return null;
-}
-
-LRESULT wmNotifyToolTip (NMTTCUSTOMDRAW nmcd, int /*long*/ lParam) {
- if (OS.IsWinCE) return null;
- switch (nmcd.dwDrawStage) {
- case OS.CDDS_PREPAINT: {
- if (isCustomToolTip ()) {
- //TEMPORARY CODE
-// nmcd.uDrawFlags |= OS.DT_CALCRECT;
-// OS.MoveMemory (lParam, nmcd, NMTTCUSTOMDRAW.sizeof);
- return new LRESULT (OS.CDRF_NOTIFYPOSTPAINT | OS.CDRF_NEWFONT);
- }
- break;
- }
- case OS.CDDS_POSTPAINT: {
- LVHITTESTINFO pinfo = new LVHITTESTINFO ();
- int pos = OS.GetMessagePos ();
- POINT pt = new POINT();
- OS.POINTSTOPOINT (pt, pos);
- OS.ScreenToClient (handle, pt);
- pinfo.x = pt.x;
- pinfo.y = pt.y;
- /*
- * Bug in Windows. When LVM_SUBITEMHITTEST is used to hittest
- * a point that is above the table, instead of returning -1 to
- * indicate that the hittest failed, a negative index is returned.
- * The fix is to consider any value that is negative a failure.
- */
- if (OS.SendMessage (handle, OS.LVM_SUBITEMHITTEST, 0, pinfo) >= 0) {
- TableItem item = _getItem (pinfo.iItem);
- int /*long*/ hDC = OS.GetDC (handle);
- int /*long*/ hFont = item.fontHandle (pinfo.iSubItem);
- if (hFont == -1) hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- int /*long*/ oldFont = OS.SelectObject (hDC, hFont);
- boolean drawForeground = true;
- RECT cellRect = item.getBounds (pinfo.iItem, pinfo.iSubItem, true, true, false, false, hDC);
- if (hooks (SWT.EraseItem)) {
- Event event = sendEraseItemEvent (item, nmcd, pinfo.iSubItem, cellRect);
- if (isDisposed () || item.isDisposed ()) break;
- if (event.doit) {
- drawForeground = (event.detail & SWT.FOREGROUND) != 0;
- } else {
- drawForeground = false;
- }
- }
- if (drawForeground) {
- int nSavedDC = OS.SaveDC (nmcd.hdc);
- int gridWidth = getLinesVisible () ? Table.GRID_WIDTH : 0;
- RECT insetRect = toolTipInset (cellRect);
- OS.SetWindowOrgEx (nmcd.hdc, insetRect.left, insetRect.top, null);
- GCData data = new GCData ();
- data.device = display;
- data.foreground = OS.GetTextColor (nmcd.hdc);
- data.background = OS.GetBkColor (nmcd.hdc);
- data.font = Font.win32_new (display, hFont);
- GC gc = GC.win32_new (nmcd.hdc, data);
- int x = cellRect.left;
- if (pinfo.iSubItem != 0) x -= gridWidth;
- Image image = item.getImage (pinfo.iSubItem);
- if (image != null) {
- Rectangle rect = image.getBounds ();
- RECT imageRect = item.getBounds (pinfo.iItem, pinfo.iSubItem, false, true, false, false, hDC);
- Point size = imageList == null ? new Point (rect.width, rect.height) : imageList.getImageSize ();
- int y = imageRect.top;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- y = y + Math.max (0, (imageRect.bottom - imageRect.top - size.y) / 2);
- }
- gc.drawImage (image, rect.x, rect.y, rect.width, rect.height, x, y, size.x, size.y);
- x += size.x + INSET + (pinfo.iSubItem == 0 ? -2 : 4);
- } else {
- x += INSET + 2;
- }
- String string = item.getText (pinfo.iSubItem);
- if (string != null) {
- int flags = OS.DT_NOPREFIX | OS.DT_SINGLELINE | OS.DT_VCENTER;
- TableColumn column = columns != null ? columns [pinfo.iSubItem] : null;
- if (column != null) {
- if ((column.style & SWT.CENTER) != 0) flags |= OS.DT_CENTER;
- if ((column.style & SWT.RIGHT) != 0) flags |= OS.DT_RIGHT;
- }
- TCHAR buffer = new TCHAR (getCodePage (), string, false);
- RECT textRect = new RECT ();
- OS.SetRect (textRect, x, cellRect.top, cellRect.right, cellRect.bottom);
- OS.DrawText (nmcd.hdc, buffer, buffer.length (), textRect, flags);
- }
- gc.dispose ();
- OS.RestoreDC (nmcd.hdc, nSavedDC);
- }
- if (hooks (SWT.PaintItem)) {
- RECT itemRect = item.getBounds (pinfo.iItem, pinfo.iSubItem, true, true, false, false, hDC);
- sendPaintItemEvent (item, nmcd, pinfo.iSubItem, itemRect);
- }
- OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- }
- }
- }
- return null;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableColumn.java
deleted file mode 100755
index be36d9bf7c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableColumn.java
+++ /dev/null
@@ -1,893 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a column in a table widget.
- * <p><dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd> Move, Resize, Selection</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT and CENTER may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TableColumn extends Item {
- Table parent;
- boolean resizable, moveable;
- String toolTipText;
- int id;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableColumn (Table parent, int style) {
- super (parent, checkStyle (style));
- resizable = true;
- this.parent = parent;
- parent.createItem (this, parent.getColumnCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableColumn (Table parent, int style, int index) {
- super (parent, checkStyle (style));
- resizable = true;
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize,typedListener);
- addListener (SWT.Move,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the column header is selected.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget ();
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Table</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Table getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Gets the moveable attribute. A column that is
- * not moveable cannot be reordered by the user
- * by dragging the header but may be reordered
- * by the programmer.
- *
- * @return the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public boolean getMoveable () {
- checkWidget ();
- return moveable;
-}
-
-/**
- * Gets the resizable attribute. A column that is
- * not resizable cannot be dragged by the user but
- * may be resized by the programmer.
- *
- * @return the resizable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getResizable () {
- checkWidget ();
- return resizable;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) return 0;
- int /*long*/ hwnd = parent.handle;
- return (int)/*64*/OS.SendMessage (hwnd, OS.LVM_GETCOLUMNWIDTH, index, 0);
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void pack () {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) return;
- int /*long*/ hwnd = parent.handle;
- int oldWidth = (int)/*64*/OS.SendMessage (hwnd, OS.LVM_GETCOLUMNWIDTH, index, 0);
- TCHAR buffer = new TCHAR (parent.getCodePage (), text, true);
- int headerWidth = (int)/*64*/OS.SendMessage (hwnd, OS.LVM_GETSTRINGWIDTH, 0, buffer) + Table.HEADER_MARGIN;
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) headerWidth += Table.HEADER_EXTRA;
- boolean hasHeaderImage = false;
- if (image != null || parent.sortColumn == this) {
- hasHeaderImage = true;
- Image headerImage = null;
- if (parent.sortColumn == this && parent.sortDirection != SWT.NONE) {
- if (OS.COMCTL32_MAJOR < 6) {
- headerImage = display.getSortImage (parent.sortDirection);
- } else {
- headerWidth += Table.SORT_WIDTH;
- }
- } else {
- headerImage = image;
- }
- if (headerImage != null) {
- Rectangle bounds = headerImage.getBounds ();
- headerWidth += bounds.width;
- }
- int margin = 0;
- if (OS.COMCTL32_VERSION >= OS.VERSION (5, 80)) {
- int /*long*/ hwndHeader = OS.SendMessage (hwnd, OS.LVM_GETHEADER, 0, 0);
- margin = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_GETBITMAPMARGIN, 0, 0);
- } else {
- margin = OS.GetSystemMetrics (OS.SM_CXEDGE) * 3;
- }
- headerWidth += margin * 4;
- }
- parent.ignoreColumnResize = true;
- int columnWidth = 0;
- if (parent.hooks (SWT.MeasureItem)) {
- RECT headerRect = new RECT ();
- int /*long*/ hwndHeader = OS.SendMessage (hwnd, OS.LVM_GETHEADER, 0, 0);
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect);
- OS.MapWindowPoints (hwndHeader, hwnd, headerRect, 2);
- int /*long*/ hDC = OS.GetDC (hwnd);
- int /*long*/ oldFont = 0, newFont = OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- int count = (int)/*64*/OS.SendMessage (hwnd, OS.LVM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<count; i++) {
- TableItem item = parent.items [i];
- if (item != null) {
- int /*long*/ hFont = item.fontHandle (index);
- if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
- Event event = parent.sendMeasureItemEvent (item, i, index, hDC);
- if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
- if (isDisposed () || parent.isDisposed ()) break;
- columnWidth = Math.max (columnWidth, event.x + event.width - headerRect.left);
- }
- }
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (hwnd, hDC);
- OS.SendMessage (hwnd, OS.LVM_SETCOLUMNWIDTH, index, columnWidth);
- } else {
- OS.SendMessage (hwnd, OS.LVM_SETCOLUMNWIDTH, index, OS.LVSCW_AUTOSIZE);
- columnWidth = (int)/*64*/OS.SendMessage (hwnd, OS.LVM_GETCOLUMNWIDTH, index, 0);
- if (index == 0) {
- /*
- * Bug in Windows. When LVM_SETCOLUMNWIDTH is used with LVSCW_AUTOSIZE
- * where each item has I_IMAGECALLBACK but there are no images in the
- * table, the size computed by LVM_SETCOLUMNWIDTH is too small for the
- * first column, causing long items to be clipped with '...'. The fix
- * is to increase the column width by a small amount.
- */
- if (parent.imageList == null) columnWidth += 2;
- /*
- * Bug in Windows. When the first column of a table does not
- * have an image and the user double clicks on the divider,
- * Windows packs the column but does not take into account
- * the empty space left for the image. The fix is to increase
- * the column width by the width of the image list.
- *
- * NOTE: This bug does not happen on Vista.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION < OS.VERSION (6, 0)) {
- if (!parent.firstColumnImage) {
- int /*long*/ hImageList = OS.SendMessage (hwnd, OS.LVM_GETIMAGELIST, OS.LVSIL_SMALL, 0);
- if (hImageList != 0) {
- int [] cx = new int [1], cy = new int [1];
- OS.ImageList_GetIconSize (hImageList, cx, cy);
- columnWidth += cx [0];
- }
- }
- }
- /*
- * Bug in Windows. When LVM_SETCOLUMNWIDTH is used with LVSCW_AUTOSIZE
- * for a table with a state image list, the column is width does not
- * include space for the state icon. The fix is to increase the column
- * width by the width of the image list.
- */
- if ((parent.style & SWT.CHECK) != 0) {
- int /*long*/ hStateList = OS.SendMessage (hwnd, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);
- if (hStateList != 0) {
- int [] cx = new int [1], cy = new int [1];
- OS.ImageList_GetIconSize (hStateList, cx, cy);
- columnWidth += cx [0];
- }
- }
- }
- }
- if (headerWidth > columnWidth) {
- if (!hasHeaderImage) {
- /*
- * Feature in Windows. When LVSCW_AUTOSIZE_USEHEADER is used
- * with LVM_SETCOLUMNWIDTH to resize the last column, the last
- * column is expanded to fill the client area. The fix is to
- * resize the table to be small, set the column width and then
- * restore the table to its original size.
- */
- RECT rect = null;
- boolean fixWidth = index == parent.getColumnCount () - 1;
- if (fixWidth) {
- rect = new RECT ();
- OS.GetWindowRect (hwnd, rect);
- OS.UpdateWindow (hwnd);
- int flags = OS.SWP_NOACTIVATE | OS.SWP_NOMOVE | OS.SWP_NOREDRAW | OS.SWP_NOZORDER;
- SetWindowPos (hwnd, 0, 0, 0, 0, rect.bottom - rect.top, flags);
- }
- OS.SendMessage (hwnd, OS.LVM_SETCOLUMNWIDTH, index, OS.LVSCW_AUTOSIZE_USEHEADER);
- if (fixWidth) {
- int flags = OS.SWP_NOACTIVATE | OS.SWP_NOMOVE | OS.SWP_NOZORDER;
- SetWindowPos (hwnd, 0, 0, 0, rect.right - rect.left, rect.bottom - rect.top, flags);
- }
- } else {
- OS.SendMessage (hwnd, OS.LVM_SETCOLUMNWIDTH, index, headerWidth);
- }
- } else {
- if (index == 0) {
- OS.SendMessage (hwnd, OS.LVM_SETCOLUMNWIDTH, index, columnWidth);
- }
- }
- parent.ignoreColumnResize = false;
- int newWidth = (int)/*64*/OS.SendMessage (hwnd, OS.LVM_GETCOLUMNWIDTH, index, 0);
- if (oldWidth != newWidth) {
- updateToolTip (index);
- sendEvent (SWT.Resize);
- if (isDisposed ()) return;
- boolean moved = false;
- int [] order = parent.getColumnOrder ();
- TableColumn [] columns = parent.getColumns ();
- for (int i=0; i<order.length; i++) {
- TableColumn column = columns [order [i]];
- if (moved && !column.isDisposed ()) {
- column.updateToolTip (order [i]);
- column.sendEvent (SWT.Move);
- }
- if (column == this) moved = true;
- }
- }
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (parent.sortColumn == this) {
- parent.sortColumn = null;
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>.
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget ();
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- int index = parent.indexOf (this);
- if (index == -1 || index == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- int /*long*/ hwnd = parent.handle;
- LVCOLUMN lvColumn = new LVCOLUMN ();
- lvColumn.mask = OS.LVCF_FMT;
- OS.SendMessage (hwnd, OS.LVM_GETCOLUMN, index, lvColumn);
- lvColumn.fmt &= ~OS.LVCFMT_JUSTIFYMASK;
- int fmt = 0;
- if ((style & SWT.LEFT) == SWT.LEFT) fmt = OS.LVCFMT_LEFT;
- if ((style & SWT.CENTER) == SWT.CENTER) fmt = OS.LVCFMT_CENTER;
- if ((style & SWT.RIGHT) == SWT.RIGHT) fmt = OS.LVCFMT_RIGHT;
- lvColumn.fmt |= fmt;
- OS.SendMessage (hwnd, OS.LVM_SETCOLUMN, index, lvColumn);
- /*
- * Bug in Windows. When LVM_SETCOLUMN is used to change
- * the alignment of a column, the column is not redrawn
- * to show the new alignment. The fix is to compute the
- * visible rectangle for the column and redraw it.
- */
- if (index != 0) {
- parent.forceResize ();
- RECT rect = new RECT (), headerRect = new RECT ();
- OS.GetClientRect (hwnd, rect);
- int /*long*/ hwndHeader = OS.SendMessage (hwnd, OS.LVM_GETHEADER, 0, 0);
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect);
- OS.MapWindowPoints (hwndHeader, hwnd, headerRect, 2);
- rect.left = headerRect.left;
- rect.right = headerRect.right;
- OS.InvalidateRect (hwnd, rect, true);
- }
-}
-
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- super.setImage (image);
- if (parent.sortColumn != this || parent.sortDirection != SWT.NONE) {
- setImage (image, false, false);
- }
-}
-
-void setImage (Image image, boolean sort, boolean right) {
- int index = parent.indexOf (this);
- if (index == -1) return;
- int /*long*/ hwnd = parent.handle;
- if (OS.COMCTL32_MAJOR < 6) {
- int /*long*/ hwndHeader = OS.SendMessage (hwnd, OS.LVM_GETHEADER, 0, 0);
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_FORMAT | OS.HDI_IMAGE | OS.HDI_BITMAP;
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, hdItem);
- hdItem.fmt &= ~OS.HDF_BITMAP_ON_RIGHT;
- if (image != null) {
- if (sort) {
- hdItem.mask &= ~OS.HDI_IMAGE;
- hdItem.fmt &= ~OS.HDF_IMAGE;
- hdItem.fmt |= OS.HDF_BITMAP;
- hdItem.hbm = image.handle;
- } else {
- hdItem.mask &= ~OS.HDI_BITMAP;
- hdItem.fmt &= ~OS.HDF_BITMAP;
- hdItem.fmt |= OS.HDF_IMAGE;
- hdItem.iImage = parent.imageIndexHeader (image);
- }
- if (right) hdItem.fmt |= OS.HDF_BITMAP_ON_RIGHT;
- } else {
- hdItem.fmt &= ~(OS.HDF_IMAGE | OS.HDF_BITMAP);
- }
- OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, hdItem);
- } else {
- LVCOLUMN lvColumn = new LVCOLUMN ();
- lvColumn.mask = OS.LVCF_FMT | OS.LVCF_IMAGE;
- OS.SendMessage (hwnd, OS.LVM_GETCOLUMN, index, lvColumn);
- if (image != null) {
- lvColumn.fmt |= OS.LVCFMT_IMAGE;
- lvColumn.iImage = parent.imageIndexHeader (image);
- if (right) lvColumn.fmt |= OS.LVCFMT_BITMAP_ON_RIGHT;
- } else {
- lvColumn.mask &= ~OS.LVCF_IMAGE;
- lvColumn.fmt &= ~(OS.LVCFMT_IMAGE | OS.LVCFMT_BITMAP_ON_RIGHT);
- }
- OS.SendMessage (hwnd, OS.LVM_SETCOLUMN, index, lvColumn);
- }
-}
-
-/**
- * Sets the moveable attribute. A column that is
- * moveable can be reordered by the user by dragging
- * the header. A column that is not moveable cannot be
- * dragged by the user but may be reordered
- * by the programmer.
- *
- * @param moveable the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setColumnOrder(int[])
- * @see Table#getColumnOrder()
- * @see TableColumn#getMoveable()
- * @see SWT#Move
- *
- * @since 3.1
- */
-public void setMoveable (boolean moveable) {
- checkWidget ();
- this.moveable = moveable;
- parent.updateMoveable ();
-}
-
-/**
- * Sets the resizable attribute. A column that is
- * resizable can be resized by the user dragging the
- * edge of the header. A column that is not resizable
- * cannot be dragged by the user but may be resized
- * by the programmer.
- *
- * @param resizable the resize attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setResizable (boolean resizable) {
- checkWidget ();
- this.resizable = resizable;
-}
-
-void setSortDirection (int direction) {
- if (OS.COMCTL32_MAJOR >= 6) {
- int index = parent.indexOf (this);
- if (index == -1) return;
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hwndHeader = OS.SendMessage (hwnd, OS.LVM_GETHEADER, 0, 0);
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_FORMAT | OS.HDI_IMAGE;
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, hdItem);
- switch (direction) {
- case SWT.UP:
- hdItem.fmt &= ~(OS.HDF_IMAGE | OS.HDF_SORTDOWN);
- hdItem.fmt |= OS.HDF_SORTUP;
- if (image == null) hdItem.mask &= ~OS.HDI_IMAGE;
- break;
- case SWT.DOWN:
- hdItem.fmt &= ~(OS.HDF_IMAGE | OS.HDF_SORTUP);
- hdItem.fmt |= OS.HDF_SORTDOWN;
- if (image == null) hdItem.mask &= ~OS.HDI_IMAGE;
- break;
- case SWT.NONE:
- hdItem.fmt &= ~(OS.HDF_SORTUP | OS.HDF_SORTDOWN);
- if (image != null) {
- hdItem.fmt |= OS.HDF_IMAGE;
- hdItem.iImage = parent.imageIndexHeader (image);
- } else {
- hdItem.fmt &= ~OS.HDF_IMAGE;
- hdItem.mask &= ~OS.HDI_IMAGE;
- }
- break;
- }
- OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, hdItem);
- /*
- * Bug in Windows. When LVM_SETSELECTEDCOLUMN is used to
- * specify a selected column, Windows does not redraw either
- * the new or the previous selected column. The fix is to
- * force a redraw of both.
- *
- * Feature in Windows. When LVM_SETBKCOLOR is used with
- * CLR_NONE and LVM_SETSELECTEDCOLUMN is used to select
- * a column, Windows fills the column with the selection
- * color, drawing on top of the background image and any
- * other custom drawing. The fix is to avoid setting the
- * selected column.
- */
- parent.forceResize ();
- RECT rect = new RECT ();
- OS.GetClientRect (hwnd, rect);
- if ((int)/*64*/OS.SendMessage (hwnd, OS.LVM_GETBKCOLOR, 0, 0) != OS.CLR_NONE) {
- int oldColumn = (int)/*64*/OS.SendMessage (hwnd, OS.LVM_GETSELECTEDCOLUMN, 0, 0);
- int newColumn = direction == SWT.NONE ? -1 : index;
- OS.SendMessage (hwnd, OS.LVM_SETSELECTEDCOLUMN, newColumn, 0);
- RECT headerRect = new RECT ();
- if (oldColumn != -1) {
- if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, oldColumn, headerRect) != 0) {
- OS.MapWindowPoints (hwndHeader, hwnd, headerRect, 2);
- rect.left = headerRect.left;
- rect.right = headerRect.right;
- OS.InvalidateRect (hwnd, rect, true);
- }
- }
- }
- RECT headerRect = new RECT ();
- if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect) != 0) {
- OS.MapWindowPoints (hwndHeader, hwnd, headerRect, 2);
- rect.left = headerRect.left;
- rect.right = headerRect.right;
- OS.InvalidateRect (hwnd, rect, true);
- }
- } else {
- switch (direction) {
- case SWT.UP:
- case SWT.DOWN:
- setImage (display.getSortImage (direction), true, true);
- break;
- case SWT.NONE:
- setImage (image, false, false);
- break;
- }
- }
-}
-
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (string.equals (text)) return;
- int index = parent.indexOf (this);
- if (index == -1) return;
- super.setText (string);
-
- /*
- * Bug in Windows. For some reason, when the title
- * of a column is changed after the column has been
- * created, the alignment must also be reset or the
- * text does not draw. The fix is to query and then
- * set the alignment.
- */
- int /*long*/ hwnd = parent.handle;
- LVCOLUMN lvColumn = new LVCOLUMN ();
- lvColumn.mask = OS.LVCF_FMT;
- OS.SendMessage (hwnd, OS.LVM_GETCOLUMN, index, lvColumn);
-
- /*
- * Bug in Windows. When a column header contains a
- * mnemonic character, Windows does not measure the
- * text properly. This causes '...' to always appear
- * at the end of the text. The fix is to remove
- * mnemonic characters and replace doubled mnemonics
- * with spaces.
- */
- int /*long*/ hHeap = OS.GetProcessHeap ();
- TCHAR buffer = new TCHAR (parent.getCodePage (), fixMnemonic (string, true), true);
- int byteCount = buffer.length () * TCHAR.sizeof;
- int /*long*/ pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (pszText, buffer, byteCount);
- lvColumn.mask |= OS.LVCF_TEXT;
- lvColumn.pszText = pszText;
- int /*long*/ result = OS.SendMessage (hwnd, OS.LVM_SETCOLUMN, index, lvColumn);
- if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
- if (result == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
- int /*long*/ hwndHeaderToolTip = parent.headerToolTipHandle;
- if (hwndHeaderToolTip == 0) {
- parent.createHeaderToolTips ();
- parent.updateHeaderToolTips ();
- }
-}
-
-/**
- * Sets the width of the receiver.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int width) {
- checkWidget ();
- if (width < 0) return;
- int index = parent.indexOf (this);
- if (index == -1) return;
- int /*long*/ hwnd = parent.handle;
- if (width != (int)/*64*/OS.SendMessage (hwnd, OS.LVM_GETCOLUMNWIDTH, index, 0)) {
- OS.SendMessage (hwnd, OS.LVM_SETCOLUMNWIDTH, index, width);
- }
-}
-
-void updateToolTip (int index) {
- int /*long*/ hwndHeaderToolTip = parent.headerToolTipHandle;
- if (hwndHeaderToolTip != 0) {
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hwndHeader = OS.SendMessage (hwnd, OS.LVM_GETHEADER, 0, 0);
- RECT rect = new RECT ();
- if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, rect) != 0) {
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- lpti.hwnd = hwndHeader;
- lpti.uId = id;
- lpti.left = rect.left;
- lpti.top = rect.top;
- lpti.right = rect.right;
- lpti.bottom = rect.bottom;
- OS.SendMessage (hwndHeaderToolTip, OS.TTM_NEWTOOLRECT, 0, lpti);
- }
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java
deleted file mode 100755
index 0b497d4597..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java
+++ /dev/null
@@ -1,1235 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents an item in a table.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class TableItem extends Item {
- Table parent;
- String [] strings;
- Image [] images;
- Font font;
- Font [] cellFont;
- boolean checked, grayed, cached;
- int imageIndent, background = -1, foreground = -1;
- int [] cellBackground, cellForeground;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableItem (Table parent, int style) {
- this (parent, style, checkNull (parent).getItemCount (), true);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableItem (Table parent, int style, int index) {
- this (parent, style, index, true);
-}
-
-TableItem (Table parent, int style, int index, boolean create) {
- super (parent, style);
- this.parent = parent;
- if (create) parent.createItem (this, index);
-}
-
-static Table checkNull (Table control) {
- if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return control;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void clear () {
- text = "";
- image = null;
- strings = null;
- images = null;
- imageIndent = 0;
- checked = grayed = false;
- font = null;
- background = foreground = -1;
- cellFont = null;
- cellBackground = cellForeground = null;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = false;
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-int /*long*/ fontHandle (int index) {
- if (cellFont != null && cellFont [index] != null) return cellFont [index].handle;
- if (font != null) return font.handle;
- return -1;
-}
-
-/**
- * Returns the receiver's background color.
- *
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public Color getBackground () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (background == -1) return parent.getBackground ();
- return Color.win32_new (display, background);
-}
-
-/**
- * Returns the background color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Color getBackground (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return getBackground ();
- int pixel = cellBackground != null ? cellBackground [index] : -1;
- return pixel == -1 ? getBackground () : Color.win32_new (display, pixel);
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Rectangle getBounds () {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int itemIndex = parent.indexOf (this);
- if (itemIndex == -1) return new Rectangle (0, 0, 0, 0);
- RECT rect = getBounds (itemIndex, 0, true, false, false);
- int width = rect.right - rect.left, height = rect.bottom - rect.top;
- return new Rectangle (rect.left, rect.top, width, height);
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent at a column in the table.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding column rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds (int index) {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int itemIndex = parent.indexOf (this);
- if (itemIndex == -1) return new Rectangle (0, 0, 0, 0);
- RECT rect = getBounds (itemIndex, index, true, true, true);
- int width = rect.right - rect.left, height = rect.bottom - rect.top;
- return new Rectangle (rect.left, rect.top, width, height);
-}
-
-RECT getBounds (int row, int column, boolean getText, boolean getImage, boolean fullText) {
- return getBounds (row, column, getText, getImage, fullText, false, 0);
-}
-
-RECT getBounds (int row, int column, boolean getText, boolean getImage, boolean fullText, boolean fullImage, int /*long*/ hDC) {
- if (!getText && !getImage) return new RECT ();
- int columnCount = parent.getColumnCount ();
- if (!(0 <= column && column < Math.max (1, columnCount))) {
- return new RECT ();
- }
- if (parent.fixScrollWidth) parent.setScrollWidth (null, true);
- RECT rect = new RECT ();
- int /*long*/ hwnd = parent.handle;
- int bits = (int)/*64*/OS.SendMessage (hwnd, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if (column == 0 && (bits & OS.LVS_EX_FULLROWSELECT) == 0) {
- if (parent.explorerTheme) {
- rect.left = OS.LVIR_ICON;
- parent.ignoreCustomDraw = true;
- int /*long*/ code = OS.SendMessage (hwnd, OS. LVM_GETITEMRECT, row, rect);
- parent.ignoreCustomDraw = false;
- if (code == 0) return new RECT ();
- if (getText) {
- int width = 0;
- int /*long*/ hFont = fontHandle (column);
- if (hFont == -1 && hDC == 0) {
- TCHAR buffer = new TCHAR (parent.getCodePage (), text, true);
- width = (int)/*64*/OS.SendMessage (hwnd, OS.LVM_GETSTRINGWIDTH, 0, buffer);
- } else {
- TCHAR buffer = new TCHAR (parent.getCodePage (), text, false);
- int /*long*/ textDC = hDC != 0 ? hDC : OS.GetDC (hwnd), oldFont = -1;
- if (hDC == 0) {
- if (hFont == -1) hFont = OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0);
- oldFont = OS.SelectObject (textDC, hFont);
- }
- RECT textRect = new RECT ();
- int flags = OS.DT_NOPREFIX | OS.DT_SINGLELINE | OS.DT_CALCRECT;
- OS.DrawText (textDC, buffer, buffer.length (), textRect, flags);
- width = textRect.right - textRect.left;
- if (hDC == 0) {
- if (oldFont != -1) OS.SelectObject (textDC, oldFont);
- OS.ReleaseDC (hwnd, textDC);
- }
- }
- if (!getImage) rect.left = rect.right;
- rect.right += width + Table.INSET * 2;
- }
- } else {
- if (getText) {
- rect.left = OS.LVIR_SELECTBOUNDS;
- parent.ignoreCustomDraw = true;
- int /*long*/ code = OS.SendMessage (hwnd, OS.LVM_GETITEMRECT, row, rect);
- parent.ignoreCustomDraw = false;
- if (code == 0) return new RECT ();
- if (!getImage) {
- RECT iconRect = new RECT ();
- iconRect.left = OS.LVIR_ICON;
- parent.ignoreCustomDraw = true;
- code = OS.SendMessage (hwnd, OS. LVM_GETITEMRECT, row, iconRect);
- parent.ignoreCustomDraw = false;
- if (code != 0) rect.left = iconRect.right;
- }
- } else {
- rect.left = OS.LVIR_ICON;
- parent.ignoreCustomDraw = true;
- int /*long*/ code = OS.SendMessage (hwnd, OS.LVM_GETITEMRECT, row, rect);
- parent.ignoreCustomDraw = false;
- if (code == 0) return new RECT ();
- }
- }
- if (fullText || fullImage) {
- RECT headerRect = new RECT ();
- int /*long*/ hwndHeader = OS.SendMessage (hwnd, OS.LVM_GETHEADER, 0, 0);
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, 0, headerRect);
- OS.MapWindowPoints (hwndHeader, hwnd, headerRect, 2);
- if (getText && fullText) rect.right = headerRect.right;
- if (getImage && fullImage) rect.left = headerRect.left;
- }
- } else {
- /*
- * Feature in Windows. LVM_GETSUBITEMRECT returns an image width
- * even when the subitem does not contain an image. The fix is to
- * test for this case and adjust the rectangle to represent the area
- * the table is actually drawing.
- */
- boolean hasImage = (column == 0 && image != null) || (images != null && images [column] != null);
- rect.top = column;
- if (fullText || fullImage || hDC == 0) {
- /*
- * Bug in Windows. Despite the fact that the documentation states
- * that LVIR_BOUNDS and LVIR_LABEL are identical when used with
- * LVM_GETSUBITEMRECT, LVIR_BOUNDS can return a zero height. The
- * fix is to use LVIR_LABEL.
- */
- rect.left = getText ? OS.LVIR_LABEL : OS.LVIR_ICON;
- parent.ignoreCustomDraw = true;
- int /*long*/ code = OS.SendMessage (hwnd, OS. LVM_GETSUBITEMRECT, row, rect);
- parent.ignoreCustomDraw = false;
- if (code == 0) return new RECT ();
- /*
- * Feature in Windows. Calling LVM_GETSUBITEMRECT with LVIR_LABEL
- * and zero for the column number gives the bounds of the first item
- * without including the bounds of the icon. This is undocumented.
- * When called with values greater than zero, the icon bounds are
- * included and this behavior is documented. If the icon is needed
- * in the bounds of the first item, the fix is to adjust the item
- * bounds using the icon bounds.
- */
- if (column == 0 && getText && getImage) {
- RECT iconRect = new RECT ();
- iconRect.left = OS.LVIR_ICON;
- parent.ignoreCustomDraw = true;
- code = OS.SendMessage (hwnd, OS. LVM_GETSUBITEMRECT, row, iconRect);
- parent.ignoreCustomDraw = false;
- if (code != 0) rect.left = iconRect.left;
- }
- if (hasImage) {
- if (column != 0 && getText && !getImage) {
- RECT iconRect = new RECT ();
- iconRect.top = column;
- iconRect.left = OS.LVIR_ICON;
- if (OS.SendMessage (hwnd, OS. LVM_GETSUBITEMRECT, row, iconRect) != 0) {
- rect.left = iconRect.right + Table.INSET / 2;
- }
- }
- } else {
- if (getImage && !getText) rect.right = rect.left;
- }
- if (column == 0 && fullImage) {
- RECT headerRect = new RECT ();
- int /*long*/ hwndHeader = OS.SendMessage (hwnd, OS.LVM_GETHEADER, 0, 0);
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, 0, headerRect);
- OS.MapWindowPoints (hwndHeader, hwnd, headerRect, 2);
- rect.left = headerRect.left;
- }
- } else {
- rect.left = OS.LVIR_ICON;
- parent.ignoreCustomDraw = true;
- int /*long*/ code = OS.SendMessage (hwnd, OS. LVM_GETSUBITEMRECT, row, rect);
- parent.ignoreCustomDraw = false;
- if (code == 0) return new RECT ();
- if (!hasImage) rect.right = rect.left;
- if (getText) {
- String string = column == 0 ? text : strings != null ? strings [column] : null;
- if (string != null) {
- RECT textRect = new RECT ();
- TCHAR buffer = new TCHAR (parent.getCodePage (), string, false);
- int flags = OS.DT_NOPREFIX | OS.DT_SINGLELINE | OS.DT_CALCRECT;
- OS.DrawText (hDC, buffer, buffer.length (), textRect, flags);
- rect.right += textRect.right - textRect.left + Table.INSET * 3 + 1;
- }
- }
- }
- }
- /*
- * Bug in Windows. In version 5.80 of COMCTL32.DLL, the top
- * of the rectangle returned by LVM_GETSUBITEMRECT is off by
- * the grid width when the grid is visible. The fix is to
- * move the top of the rectangle up by the grid width.
- */
- int gridWidth = parent.getLinesVisible () ? Table.GRID_WIDTH : 0;
- if (OS.COMCTL32_VERSION >= OS.VERSION (5, 80)) rect.top -= gridWidth;
- if (column != 0) rect.left += gridWidth;
- rect.right = Math.max (rect.right, rect.left);
- rect.top += gridWidth;
- rect.bottom = Math.max (rect.bottom - gridWidth, rect.top);
- return rect;
-}
-
-/**
- * Returns <code>true</code> if the receiver is checked,
- * and false otherwise. When the parent does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the checked state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getChecked () {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return checked;
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information for this item.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return font != null ? font : parent.getFont ();
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information
- * for the specified cell in this item.
- *
- * @param index the column index
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count -1) return getFont ();
- if (cellFont == null || cellFont [index] == null) return getFont ();
- return cellFont [index];
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public Color getForeground () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (foreground == -1) return parent.getForeground ();
- return Color.win32_new (display, foreground);
-}
-
-/**
- *
- * Returns the foreground color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Color getForeground (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count -1) return getForeground ();
- int pixel = cellForeground != null ? cellForeground [index] : -1;
- return pixel == -1 ? getForeground () : Color.win32_new (display, pixel);
-}
-
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the parent does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getGrayed () {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return grayed;
-}
-
-public Image getImage () {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return super.getImage ();
-}
-
-/**
- * Returns the image stored at the given column index in the receiver,
- * or null if the image has not been set or if the column does not exist.
- *
- * @param index the column index
- * @return the image stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage (int index) {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index == 0) return getImage ();
- if (images != null) {
- if (0 <= index && index < images.length) return images [index];
- }
- return null;
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of an image at a column in the
- * table. An empty rectangle is returned if index exceeds
- * the index of the table's last column.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding image rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getImageBounds (int index) {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int itemIndex = parent.indexOf (this);
- if (itemIndex == -1) return new Rectangle (0, 0, 0, 0);
- RECT rect = getBounds (itemIndex, index, false, true, false);
- int width = rect.right - rect.left, height = rect.bottom - rect.top;
- return new Rectangle (rect.left, rect.top, width, height);
-}
-
-/**
- * Gets the image indent.
- *
- * @return the indent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getImageIndent () {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return imageIndent;
-}
-
-String getNameText () {
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (!cached) return "*virtual*"; //$NON-NLS-1$
- }
- return super.getNameText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Table</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Table getParent () {
- checkWidget();
- return parent;
-}
-
-public String getText () {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return super.getText ();
-}
-
-/**
- * Returns the text stored at the given column index in the receiver,
- * or empty string if the text has not been set.
- *
- * @param index the column index
- * @return the text stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText (int index) {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index == 0) return getText ();
- if (strings != null) {
- if (0 <= index && index < strings.length) {
- String string = strings [index];
- return string != null ? string : "";
- }
- }
- return "";
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of the text at a column in the
- * table. An empty rectangle is returned if index exceeds
- * the index of the table's last column.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding text rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Rectangle getTextBounds (int index) {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int itemIndex = parent.indexOf (this);
- if (itemIndex == -1) return new Rectangle (0, 0, 0, 0);
- RECT rect = getBounds (itemIndex, index, true, false, true);
- rect.left += 2;
- if (index != 0) rect.left += Table.INSET;
- rect.left = Math.min (rect.left, rect.right);
- rect.right = rect.right - Table.INSET;
- int width = Math.max (0, rect.right - rect.left);
- int height = Math.max (0, rect.bottom - rect.top);
- return new Rectangle (rect.left, rect.top, width, height);
-}
-
-void redraw () {
- if (parent.currentItem == this || !parent.getDrawing ()) return;
- int /*long*/ hwnd = parent.handle;
- if (!OS.IsWindowVisible (hwnd)) return;
- int index = parent.indexOf (this);
- if (index == -1) return;
- OS.SendMessage (hwnd, OS.LVM_REDRAWITEMS, index, index);
-}
-
-void redraw (int column, boolean drawText, boolean drawImage) {
- if (parent.currentItem == this || !parent.getDrawing ()) return;
- int /*long*/ hwnd = parent.handle;
- if (!OS.IsWindowVisible (hwnd)) return;
- int index = parent.indexOf (this);
- if (index == -1) return;
- RECT rect = getBounds (index, column, drawText, drawImage, true);
- OS.InvalidateRect (hwnd, rect, true);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- strings = null;
- images = null;
- cellFont = null;
- cellBackground = cellForeground = null;
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setBackground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int pixel = -1;
- if (color != null) {
- parent.setCustomDraw (true);
- pixel = color.handle;
- }
- if (background == pixel) return;
- background = pixel;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- redraw ();
-}
-
-/**
- * Sets the background color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setBackground (int index, Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- int pixel = -1;
- if (color != null) {
- parent.setCustomDraw (true);
- pixel = color.handle;
- }
- if (cellBackground == null) {
- cellBackground = new int [count];
- for (int i = 0; i < count; i++) {
- cellBackground [i] = -1;
- }
- }
- if (cellBackground [index] == pixel) return;
- cellBackground [index] = pixel;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- redraw (index, true, true);
-}
-
-/**
- * Sets the checked state of the checkbox for this item. This state change
- * only applies if the Table was created with the SWT.CHECK style.
- *
- * @param checked the new checked state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setChecked (boolean checked) {
- checkWidget();
- if ((parent.style & SWT.CHECK) == 0) return;
- if (this.checked == checked) return;
- setChecked (checked, false);
-}
-
-void setChecked (boolean checked, boolean notify) {
- this.checked = checked;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- if (notify) {
- Event event = new Event();
- event.item = this;
- event.detail = SWT.CHECK;
- parent.postEvent (SWT.Selection, event);
- }
- redraw ();
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for this item to the font specified by the argument, or to the default font
- * for that kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (Font font){
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Font oldFont = this.font;
- if (oldFont == font) return;
- this.font = font;
- if (oldFont != null && oldFont.equals (font)) return;
- if (font != null) parent.setCustomDraw (true);
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- /*
- * Bug in Windows. Despite the fact that every item in the
- * table always has LPSTR_TEXTCALLBACK, Windows caches the
- * bounds for the selected items. This means that
- * when you change the string to be something else, Windows
- * correctly asks you for the new string but when the item
- * is selected, the selection draws using the bounds of the
- * previous item. The fix is to reset LPSTR_TEXTCALLBACK
- * even though it has not changed, causing Windows to flush
- * cached bounds.
- */
- if ((parent.style & SWT.VIRTUAL) == 0 && cached) {
- int itemIndex = parent.indexOf (this);
- if (itemIndex != -1) {
- int /*long*/ hwnd = parent.handle;
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_TEXT;
- lvItem.iItem = itemIndex;
- lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
- OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem);
- cached = false;
- }
- }
- parent.setScrollWidth (this, false);
- redraw ();
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for the specified cell in this item to the font specified by the
- * argument, or to the default font for that kind of control if the
- * argument is null.
- *
- * @param index the column index
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (int index, Font font) {
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- if (cellFont == null) {
- if (font == null) return;
- cellFont = new Font [count];
- }
- Font oldFont = cellFont [index];
- if (oldFont == font) return;
- cellFont [index] = font;
- if (oldFont != null && oldFont.equals (font)) return;
- if (font != null) parent.setCustomDraw (true);
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- if (index == 0) {
- /*
- * Bug in Windows. Despite the fact that every item in the
- * table always has LPSTR_TEXTCALLBACK, Windows caches the
- * bounds for the selected items. This means that
- * when you change the string to be something else, Windows
- * correctly asks you for the new string but when the item
- * is selected, the selection draws using the bounds of the
- * previous item. The fix is to reset LPSTR_TEXTCALLBACK
- * even though it has not changed, causing Windows to flush
- * cached bounds.
- */
- if ((parent.style & SWT.VIRTUAL) == 0 && cached) {
- int itemIndex = parent.indexOf (this);
- if (itemIndex != -1) {
- int /*long*/ hwnd = parent.handle;
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_TEXT;
- lvItem.iItem = itemIndex;
- lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
- OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem);
- cached = false;
- }
- }
- parent.setScrollWidth (this, false);
- }
- redraw (index, true, false);
-}
-
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setForeground (Color color){
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int pixel = -1;
- if (color != null) {
- parent.setCustomDraw (true);
- pixel = color.handle;
- }
- if (foreground == pixel) return;
- foreground = pixel;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- redraw ();
-}
-
-/**
- * Sets the foreground color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setForeground (int index, Color color){
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- int pixel = -1;
- if (color != null) {
- parent.setCustomDraw (true);
- pixel = color.handle;
- }
- if (cellForeground == null) {
- cellForeground = new int [count];
- for (int i = 0; i < count; i++) {
- cellForeground [i] = -1;
- }
- }
- if (cellForeground [index] == pixel) return;
- cellForeground [index] = pixel;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- redraw (index, true, false);
-}
-
-/**
- * Sets the grayed state of the checkbox for this item. This state change
- * only applies if the Table was created with the SWT.CHECK style.
- *
- * @param grayed the new grayed state of the checkbox;
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setGrayed (boolean grayed) {
- checkWidget();
- if ((parent.style & SWT.CHECK) == 0) return;
- if (this.grayed == grayed) return;
- this.grayed = grayed;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- redraw ();
-}
-
-/**
- * Sets the image for multiple columns in the table.
- *
- * @param images the array of new images
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image [] images) {
- checkWidget();
- if (images == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<images.length; i++) {
- setImage (i, images [i]);
- }
-}
-
-/**
- * Sets the receiver's image at a column.
- *
- * @param index the column index
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (int index, Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- Image oldImage = null;
- if (index == 0) {
- if (image != null && image.type == SWT.ICON) {
- if (image.equals (this.image)) return;
- }
- oldImage = this.image;
- super.setImage (image);
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- if (images == null && index != 0) {
- images = new Image [count];
- images [0] = image;
- }
- if (images != null) {
- if (image != null && image.type == SWT.ICON) {
- if (image.equals (images [index])) return;
- }
- oldImage = images [index];
- images [index] = image;
- }
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-
- /* Ensure that the image list is created */
- parent.imageIndex (image, index);
-
- if (index == 0) parent.setScrollWidth (this, false);
- boolean drawText = (image == null && oldImage != null) || (image != null && oldImage == null);
- redraw (index, drawText, true);
-}
-
-public void setImage (Image image) {
- checkWidget ();
- setImage (0, image);
-}
-
-/**
- * Sets the indent of the first column's image, expressed in terms of the image's width.
- *
- * @param indent the new indent
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @deprecated this functionality is not supported on most platforms
- */
-public void setImageIndent (int indent) {
- checkWidget();
- if (indent < 0) return;
- if (imageIndent == indent) return;
- imageIndent = indent;
- if ((parent.style & SWT.VIRTUAL) != 0) {
- cached = true;
- } else {
- int index = parent.indexOf (this);
- if (index != -1) {
- int /*long*/ hwnd = parent.handle;
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_INDENT;
- lvItem.iItem = index;
- lvItem.iIndent = indent;
- OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem);
- }
- }
- parent.setScrollWidth (this, false);
- redraw ();
-}
-
-/**
- * Sets the text for multiple columns in the table.
- *
- * @param strings the array of new strings
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String [] strings) {
- checkWidget();
- if (strings == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<strings.length; i++) {
- String string = strings [i];
- if (string != null) setText (i, string);
- }
-}
-
-/**
- * Sets the receiver's text at a column
- *
- * @param index the column index
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (int index, String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (index == 0) {
- if (string.equals (text)) return;
- super.setText (string);
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- if (strings == null && index != 0) {
- strings = new String [count];
- strings [0] = text;
- }
- if (strings != null) {
- if (string.equals (strings [index])) return;
- strings [index] = string;
- }
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- if (index == 0) {
- /*
- * Bug in Windows. Despite the fact that every item in the
- * table always has LPSTR_TEXTCALLBACK, Windows caches the
- * bounds for the selected items. This means that
- * when you change the string to be something else, Windows
- * correctly asks you for the new string but when the item
- * is selected, the selection draws using the bounds of the
- * previous item. The fix is to reset LPSTR_TEXTCALLBACK
- * even though it has not changed, causing Windows to flush
- * cached bounds.
- */
- if ((parent.style & SWT.VIRTUAL) == 0 && cached) {
- int itemIndex = parent.indexOf (this);
- if (itemIndex != -1) {
- int /*long*/ hwnd = parent.handle;
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_TEXT;
- lvItem.iItem = itemIndex;
- lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
- OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem);
- cached = false;
- }
- }
- parent.setScrollWidth (this, false);
- }
- redraw (index, true, false);
-}
-
-public void setText (String string) {
- checkWidget();
- setText (0, string);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java
deleted file mode 100755
index 0f0befb5d1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java
+++ /dev/null
@@ -1,2543 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify text.
- * Text controls can be either single or multi-line.
- * When a text control is created with a border, the
- * operating system includes a platform specific inset
- * around the contents of the control. When created
- * without a border, an effort is made to remove the
- * inset such that the preferred size of the control
- * is the same size as the contents.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>CENTER, ICON_CANCEL, ICON_SEARCH, LEFT, MULTI, PASSWORD, SEARCH, SINGLE, RIGHT, READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Modify, Verify</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles MULTI and SINGLE may be specified,
- * and only one of the styles LEFT, CENTER, and RIGHT may be specified.
- * </p>
- * <p>
- * Note: The styles ICON_CANCEL and ICON_SEARCH are hints used in combination with SEARCH.
- * When the platform supports the hint, the text control shows these icons. When an icon
- * is selected, a default selection event is sent with the detail field set to one of
- * ICON_CANCEL or ICON_SEARCH. Normally, application code does not need to check the
- * detail. In the case of ICON_CANCEL, the text is cleared before the default selection
- * event is sent causing the application to search for an empty string.
- * </p>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#text">Text snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Text extends Scrollable {
- int tabs, oldStart, oldEnd;
- boolean doubleClick, ignoreModify, ignoreVerify, ignoreCharacter;
- String message;
-
- /**
- * The maximum number of characters that can be entered
- * into a text widget.
- * <p>
- * Note that this value is platform dependent, based upon
- * the native widget implementation.
- * </p>
- */
- public static final int LIMIT;
-
- /**
- * The delimiter used by multi-line text widgets. When text
- * is queried and from the widget, it will be delimited using
- * this delimiter.
- */
- public static final String DELIMITER;
-
- /*
- * This code is intentionally commented.
- */
-// static final char PASSWORD;
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = OS.IsWinNT ? 0x7FFFFFFF : 0x7FFF;
- DELIMITER = "\r\n";
- }
-
- static final int /*long*/ EditProc;
- static final TCHAR EditClass = new TCHAR (0, "EDIT", true);
- static {
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, EditClass, lpWndClass);
- EditProc = lpWndClass.lpfnWndProc;
- /*
- * This code is intentionally commented.
- */
-// int /*long*/ hwndText = OS.CreateWindowEx (0,
-// EditClass,
-// null,
-// OS.WS_OVERLAPPED | OS.ES_PASSWORD,
-// 0, 0, 0, 0,
-// 0,
-// 0,
-// OS.GetModuleHandle (null),
-// null);
-// char echo = (char) OS.SendMessage (hwndText, OS.EM_GETPASSWORDCHAR, 0, 0);
-// OS.DestroyWindow (hwndText);
-// PASSWORD = echo != 0 ? echo : '*';
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#READ_ONLY
- * @see SWT#WRAP
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see SWT#PASSWORD
- * @see SWT#SEARCH
- * @see SWT#ICON_SEARCH
- * @see SWT#ICON_CANCEL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Text (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- boolean redraw = false;
- switch (msg) {
- case OS.WM_ERASEBKGND: {
- if (findImageControl () != null) return 0;
- break;
- }
- case OS.WM_HSCROLL:
- case OS.WM_VSCROLL: {
- redraw = findImageControl () != null && getDrawing () && OS.IsWindowVisible (handle);
- if (redraw) OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- break;
- }
- case OS.WM_PAINT: {
- boolean doubleBuffer = findImageControl () != null;
- boolean drawMessage = false;
- if ((style & SWT.SINGLE) != 0 && message.length () > 0) {
- if (!OS.IsWinCE && OS.WIN32_VERSION < OS.VERSION (6, 0)) {
- drawMessage = hwnd != OS.GetFocus () && OS.GetWindowTextLength (handle) == 0;
- }
- }
- if (doubleBuffer || drawMessage) {
- int /*long*/ paintDC = 0;
- PAINTSTRUCT ps = new PAINTSTRUCT ();
- paintDC = OS.BeginPaint (handle, ps);
- int width = ps.right - ps.left;
- int height = ps.bottom - ps.top;
- if (width != 0 && height != 0) {
- int /*long*/ hDC = paintDC, hBitmap = 0, hOldBitmap = 0;
- POINT lpPoint1 = null, lpPoint2 = null;
- if (doubleBuffer) {
- hDC = OS.CreateCompatibleDC (paintDC);
- lpPoint1 = new POINT ();
- lpPoint2 = new POINT ();
- OS.SetWindowOrgEx (hDC, ps.left, ps.top, lpPoint1);
- OS.SetBrushOrgEx (hDC, ps.left, ps.top, lpPoint2);
- hBitmap = OS.CreateCompatibleBitmap (paintDC, width, height);
- hOldBitmap = OS.SelectObject (hDC, hBitmap);
- RECT rect = new RECT ();
- OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
- drawBackground (hDC, rect);
- }
-
- OS.CallWindowProc (EditProc, hwnd, OS.WM_PAINT, hDC, lParam);
- /*
- * Bug in XP. Windows does not draw the cue message on XP when
- * East Asian language pack is installed. The fix is to draw
- * the cue messages ourselves.
- * Note: This bug is fixed on Vista.
- */
- if (drawMessage) {
- RECT rect = new RECT();
- OS.GetClientRect(handle, rect);
- int /*long*/ margins = OS.SendMessage (handle, OS.EM_GETMARGINS, 0, 0);
- rect.left += OS.LOWORD (margins);
- rect.right -= OS.HIWORD (margins);
- if ((style & SWT.BORDER) != 0) {
- rect.left++;
- rect.top++;
- rect.right--;
- rect.bottom--;
- }
- TCHAR buffer = new TCHAR (getCodePage (), message, false);
- int uFormat = OS.DT_EDITCONTROL;
- boolean rtl = (style & SWT.RIGHT_TO_LEFT) != 0;
- if (rtl) uFormat |= OS.DT_RTLREADING;
- int alignment = style & (SWT.LEFT | SWT.CENTER | SWT.RIGHT);
- switch (alignment) {
- case SWT.LEFT: uFormat |= (rtl ? OS.DT_RIGHT : OS.DT_LEFT); break;
- case SWT.CENTER: uFormat |= OS.DT_CENTER;
- case SWT.RIGHT: uFormat |= (rtl ? OS.DT_LEFT : OS.DT_RIGHT); break;
- }
- int /*long*/ hFont = OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0);
- int /*long*/ hOldFont = OS.SelectObject (hDC, hFont);
- OS.SetTextColor (hDC, OS.GetSysColor (OS.COLOR_GRAYTEXT));
- OS.SetBkMode (hDC, OS.TRANSPARENT);
- OS.DrawText (hDC, buffer, buffer.length (), rect, uFormat);
- OS.SelectObject (hDC, hOldFont);
- }
-
- if (doubleBuffer) {
- OS.SetWindowOrgEx (hDC, lpPoint1.x, lpPoint1.y, null);
- OS.SetBrushOrgEx (hDC, lpPoint2.x, lpPoint2.y, null);
- OS.BitBlt (paintDC, ps.left, ps.top, width, height, hDC, 0, 0, OS.SRCCOPY);
- OS.SelectObject (hDC, hOldBitmap);
- OS.DeleteObject (hBitmap);
- OS.DeleteObject (hDC);
- }
- }
- OS.EndPaint (handle, ps);
- return 0;
- }
- break;
- }
- }
- int /*long*/ code = OS.CallWindowProc (EditProc, hwnd, msg, wParam, lParam);
- switch (msg) {
- case OS.WM_HSCROLL:
- case OS.WM_VSCROLL: {
- if (redraw) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.InvalidateRect (handle, null, true);
- }
- break;
- }
- }
- return code;
-}
-
-void createHandle () {
- super.createHandle ();
- OS.SendMessage (handle, OS.EM_LIMITTEXT, 0, 0);
- if ((style & SWT.READ_ONLY) != 0) {
- if ((style & (SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
- state |= THEME_BACKGROUND;
- }
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is not called for texts.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text,
- * or when ENTER is pressed in a search text. If the receiver has the <code>SWT.SEARCH | SWT.CANCEL</code> style
- * and the user cancels the search, the event object detail field contains the value <code>SWT.CANCEL</code>.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- */
-public void addVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-
-/**
- * Appends a string.
- * <p>
- * The new text is appended to the text at
- * the end of the widget.
- * </p>
- *
- * @param string the string to be appended
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void append (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- string = Display.withCrLf (string);
- int length = OS.GetWindowTextLength (handle);
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- string = verifyText (string, length, length, null);
- if (string == null) return;
- }
- OS.SendMessage (handle, OS.EM_SETSEL, length, length);
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- /*
- * Feature in Windows. When an edit control with ES_MULTILINE
- * style that does not have the WS_VSCROLL style is full (i.e.
- * there is no space at the end to draw any more characters),
- * EM_REPLACESEL sends a WM_CHAR with a backspace character
- * to remove any further text that is added. This is an
- * implementation detail of the edit control that is unexpected
- * and can cause endless recursion when EM_REPLACESEL is sent
- * from a WM_CHAR handler. The fix is to ignore calling the
- * handler from WM_CHAR.
- */
- ignoreCharacter = true;
- OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
- ignoreCharacter = false;
- OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
-}
-
-static int checkStyle (int style) {
- if ((style & SWT.SEARCH) != 0) {
- style |= SWT.SINGLE | SWT.BORDER;
- style &= ~SWT.PASSWORD;
- /*
- * NOTE: ICON_CANCEL has the same value as H_SCROLL and
- * ICON_SEARCH has the same value as V_SCROLL so they are
- * cleared because SWT.SINGLE is set.
- */
- }
- if ((style & SWT.SINGLE) != 0 && (style & SWT.MULTI) != 0) {
- style &= ~SWT.MULTI;
- }
- style = checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
- if ((style & SWT.SINGLE) != 0) style &= ~(SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP);
- if ((style & SWT.WRAP) != 0) {
- style |= SWT.MULTI;
- style &= ~SWT.H_SCROLL;
- }
- if ((style & SWT.MULTI) != 0) style &= ~SWT.PASSWORD;
- if ((style & (SWT.SINGLE | SWT.MULTI)) != 0) return style;
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) return style | SWT.MULTI;
- return style | SWT.SINGLE;
-}
-
-/**
- * Clears the selection.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void clearSelection () {
- checkWidget ();
- if (OS.IsWinCE) {
- /*
- * Bug in WinCE. Calling EM_SETSEL with -1 and 0 is equivalent
- * to calling EM_SETSEL with 0 and -1. It causes the entire
- * text to be selected instead of clearing the selection. The
- * fix is to set the start of the selection to the end of the
- * current selection.
- */
- int [] end = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, (int []) null, end);
- OS.SendMessage (handle, OS.EM_SETSEL, end [0], end [0]);
- } else {
- OS.SendMessage (handle, OS.EM_SETSEL, -1, 0);
- }
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int height = 0, width = 0;
- if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
- int /*long*/ newFont, oldFont = 0;
- int /*long*/ hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ();
- OS.GetTextMetrics (hDC, tm);
- int count = (style & SWT.SINGLE) != 0 ? 1 : (int)/*64*/OS.SendMessage (handle, OS.EM_GETLINECOUNT, 0, 0);
- height = count * tm.tmHeight;
- RECT rect = new RECT ();
- int flags = OS.DT_CALCRECT | OS.DT_EDITCONTROL | OS.DT_NOPREFIX;
- boolean wrap = (style & SWT.MULTI) != 0 && (style & SWT.WRAP) != 0;
- if (wrap && wHint != SWT.DEFAULT) {
- flags |= OS.DT_WORDBREAK;
- rect.right = wHint;
- }
- int length = OS.GetWindowTextLength (handle);
- if (length != 0) {
- TCHAR buffer = new TCHAR (getCodePage (), length + 1);
- OS.GetWindowText (handle, buffer, length + 1);
- OS.DrawText (hDC, buffer, length, rect, flags);
- width = rect.right - rect.left;
- }
- if (wrap && hHint == SWT.DEFAULT) {
- int newHeight = rect.bottom - rect.top;
- if (newHeight != 0) height = newHeight;
- }
- if ((style & SWT.SINGLE) != 0 && message.length () > 0) {
- OS.SetRect (rect, 0, 0, 0, 0);
- TCHAR buffer = new TCHAR (getCodePage (), message, false);
- OS.DrawText (hDC, buffer, buffer.length (), rect, flags);
- width = Math.max (width, rect.right - rect.left);
- }
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- }
- if (width == 0) width = DEFAULT_WIDTH;
- if (height == 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- Rectangle trim = computeTrim (0, 0, width, height);
- return new Point (trim.width, trim.height);
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
- Rectangle rect = super.computeTrim (x, y, width, height);
- /*
- * The preferred height of a single-line text widget
- * has been hand-crafted to be the same height as
- * the single-line text widget in an editable combo
- * box.
- */
- int /*long*/ margins = OS.SendMessage(handle, OS.EM_GETMARGINS, 0, 0);
- rect.x -= OS.LOWORD (margins);
- rect.width += OS.LOWORD (margins) + OS.HIWORD (margins);
- if ((style & SWT.H_SCROLL) != 0) rect.width++;
- if ((style & SWT.BORDER) != 0) {
- rect.x -= 1;
- rect.y -= 1;
- rect.width += 2;
- rect.height += 2;
- }
- return rect;
-}
-
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void copy () {
- checkWidget ();
- OS.SendMessage (handle, OS.WM_COPY, 0, 0);
-}
-
-void createWidget () {
- super.createWidget ();
- message = "";
- doubleClick = true;
- setTabStops (tabs = 8);
- fixAlignment ();
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void cut () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- OS.SendMessage (handle, OS.WM_CUT, 0, 0);
-}
-
-int defaultBackground () {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- return OS.GetSysColor ((bits & OS.ES_READONLY) != 0 ? OS.COLOR_3DFACE : OS.COLOR_WINDOW);
-}
-
-boolean dragDetect (int /*long*/ hwnd, int x, int y, boolean filter, boolean [] detect, boolean [] consume) {
- if (filter) {
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- if (start [0] != end [0]) {
- int /*long*/ lParam = OS.MAKELPARAM (x, y);
- int position = OS.LOWORD (OS.SendMessage (handle, OS.EM_CHARFROMPOS, 0, lParam));
- if (start [0] <= position && position < end [0]) {
- if (super.dragDetect (hwnd, x, y, filter, detect, consume)) {
- if (consume != null) consume [0] = true;
- return true;
- }
- }
- }
- return false;
- }
- return super.dragDetect (hwnd, x, y, filter, detect, consume);
-}
-
-void fixAlignment () {
- /*
- * Feature in Windows. When the edit control is not
- * mirrored, it uses WS_EX_RIGHT, WS_EX_RTLREADING and
- * WS_EX_LEFTSCROLLBAR to give the control a right to
- * left appearance. This causes the control to be lead
- * aligned no matter what alignment was specified by
- * the programmer. For example, setting ES_RIGHT and
- * WS_EX_LAYOUTRTL should cause the contents of the
- * control to be left (trail) aligned in a mirrored world.
- * When the orientation is changed by the user or
- * specified by the programmer, WS_EX_RIGHT conflicts
- * with the mirrored alignment. The fix is to clear
- * or set WS_EX_RIGHT to achieve the correct alignment
- * according to the orientation and mirroring.
- */
- if ((style & SWT.MIRRORED) != 0) return;
- int bits1 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
- int bits2 = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((style & SWT.LEFT_TO_RIGHT) != 0) {
- /*
- * Bug in Windows 98. When the edit control is created
- * with the style ES_RIGHT it automatically sets the
- * WS_EX_LEFTSCROLLBAR bit. The fix is to clear the
- * bit when the orientation of the control is left
- * to right.
- */
- bits1 &= ~OS.WS_EX_LEFTSCROLLBAR;
- if ((style & SWT.RIGHT) != 0) {
- bits1 |= OS.WS_EX_RIGHT;
- bits2 |= OS.ES_RIGHT;
- }
- if ((style & SWT.LEFT) != 0) {
- bits1 &= ~OS.WS_EX_RIGHT;
- bits2 &= ~OS.ES_RIGHT;
- }
- } else {
- if ((style & SWT.RIGHT) != 0) {
- bits1 &= ~OS.WS_EX_RIGHT;
- bits2 &= ~OS.ES_RIGHT;
- }
- if ((style & SWT.LEFT) != 0) {
- bits1 |= OS.WS_EX_RIGHT;
- bits2 |= OS.ES_RIGHT;
- }
- }
- if ((style & SWT.CENTER) != 0) {
- bits2 |= OS.ES_CENTER;
- }
- OS.SetWindowLong (handle, OS.GWL_EXSTYLE, bits1);
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits2);
-}
-
-public int getBorderWidth () {
- checkWidget ();
- /*
- * Feature in Windows 2000 and XP. Despite the fact that WS_BORDER
- * is set when the edit control is created, the style bit is cleared.
- * The fix is to avoid the check for WS_BORDER and use the SWT widget
- * style bits instead.
- */
-// if ((style & SWT.BORDER) != 0 && (style & SWT.FLAT) != 0) {
-// return OS.GetSystemMetrics (OS.SM_CXBORDER);
-// }
- return super.getBorderWidth ();
-}
-
-/**
- * Returns the line number of the caret.
- * <p>
- * The line number of the caret is returned.
- * </p>
- *
- * @return the line number
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretLineNumber () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.EM_LINEFROMCHAR, -1, 0);
-}
-
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null).
- * <p>
- * The location of the caret is returned.
- * </p>
- *
- * @return a point, the location of the caret
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getCaretLocation () {
- checkWidget ();
- /*
- * Bug in Windows. For some reason, Windows is unable
- * to return the pixel coordinates of the last character
- * in the widget. The fix is to temporarily insert a
- * space, query the coordinates and delete the space.
- * The selection is always an i-beam in this case because
- * this is the only time the start of the selection can
- * be equal to the last character position in the widget.
- * If EM_POSFROMCHAR fails for any other reason, return
- * pixel coordinates (0,0).
- */
- int position = getCaretPosition ();
- int /*long*/ caretPos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, position, 0);
- if (caretPos == -1) {
- caretPos = 0;
- if (position >= OS.GetWindowTextLength (handle)) {
- int cp = getCodePage ();
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- OS.SendMessage (handle, OS.EM_SETSEL, position, position);
- /*
- * Feature in Windows. When an edit control with ES_MULTILINE
- * style that does not have the WS_VSCROLL style is full (i.e.
- * there is no space at the end to draw any more characters),
- * EM_REPLACESEL sends a WM_CHAR with a backspace character
- * to remove any further text that is added. This is an
- * implementation detail of the edit control that is unexpected
- * and can cause endless recursion when EM_REPLACESEL is sent
- * from a WM_CHAR handler. The fix is to ignore calling the
- * handler from WM_CHAR.
- */
- ignoreCharacter = ignoreModify = true;
- OS.SendMessage (handle, OS.EM_REPLACESEL, 0, new TCHAR (cp, " ", true));
- caretPos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, position, 0);
- OS.SendMessage (handle, OS.EM_SETSEL, position, position + 1);
- OS.SendMessage (handle, OS.EM_REPLACESEL, 0, new TCHAR (cp, "", true));
- ignoreCharacter = ignoreModify = false;
- OS.SendMessage (handle, OS.EM_SETSEL, start [0], start [0]);
- OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]);
- }
- }
- return new Point (OS.GET_X_LPARAM (caretPos), OS.GET_Y_LPARAM (caretPos));
-}
-
-/**
- * Returns the character position of the caret.
- * <p>
- * Indexing is zero based.
- * </p>
- *
- * @return the position of the caret
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretPosition () {
- checkWidget ();
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- /*
- * In Windows, there is no API to get the position of the caret
- * when the selection is not an i-beam. The best that can be done
- * is to query the pixel position of the current caret and compare
- * it to the pixel position of the start and end of the selection.
- *
- * NOTE: This does not work when the i-beam belongs to another
- * control. In this case, guess that the i-beam is at the start
- * of the selection.
- */
- int caret = start [0];
- if (start [0] != end [0]) {
- int startLine = (int)/*64*/OS.SendMessage (handle, OS.EM_LINEFROMCHAR, start [0], 0);
- int endLine = (int)/*64*/OS.SendMessage (handle, OS.EM_LINEFROMCHAR, end [0], 0);
- if (startLine == endLine) {
- if (!OS.IsWinCE) {
- int idThread = OS.GetWindowThreadProcessId (handle, null);
- GUITHREADINFO lpgui = new GUITHREADINFO ();
- lpgui.cbSize = GUITHREADINFO.sizeof;
- if (OS.GetGUIThreadInfo (idThread, lpgui)) {
- if (lpgui.hwndCaret == handle || lpgui.hwndCaret == 0) {
- POINT ptCurrentPos = new POINT ();
- if (OS.GetCaretPos (ptCurrentPos)) {
- int /*long*/ endPos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, end [0], 0);
- if (endPos == -1) {
- int /*long*/ startPos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, start [0], 0);
- int startX = OS.GET_X_LPARAM (startPos);
- if (ptCurrentPos.x > startX) caret = end [0];
- } else {
- int endX = OS.GET_X_LPARAM (endPos);
- if (ptCurrentPos.x >= endX) caret = end [0];
- }
- }
- }
- }
- }
- } else {
- int caretPos = (int)/*64*/OS.SendMessage (handle, OS.EM_LINEINDEX, -1, 0);
- int caretLine = (int)/*64*/OS.SendMessage (handle, OS.EM_LINEFROMCHAR, caretPos, 0);
- if (caretLine == endLine) caret = end [0];
- }
- }
- if (!OS.IsUnicode && OS.IsDBLocale) caret = mbcsToWcsPos (caret);
- return caret;
-}
-
-/**
- * Returns the number of characters.
- *
- * @return number of characters in the widget
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCharCount () {
- checkWidget ();
- int length = OS.GetWindowTextLength (handle);
- if (!OS.IsUnicode && OS.IsDBLocale) length = mbcsToWcsPos (length);
- return length;
-}
-
-/**
- * Returns the double click enabled flag.
- * <p>
- * The double click flag enables or disables the
- * default action of the text widget when the user
- * double clicks.
- * </p>
- *
- * @return whether or not double click is enabled
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getDoubleClickEnabled () {
- checkWidget ();
- return doubleClick;
-}
-
-/**
- * Returns the echo character.
- * <p>
- * The echo character is the character that is
- * displayed when the user enters text or the
- * text is changed by the programmer.
- * </p>
- *
- * @return the echo character
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setEchoChar
- */
-public char getEchoChar () {
- checkWidget ();
- char echo = (char) OS.SendMessage (handle, OS.EM_GETPASSWORDCHAR, 0, 0);
- if (echo != 0 && (echo = Display.mbcsToWcs (echo, getCodePage ())) == 0) echo = '*';
- return echo;
-}
-
-/**
- * Returns the editable state.
- *
- * @return whether or not the receiver is editable
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getEditable () {
- checkWidget ();
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- return (bits & OS.ES_READONLY) == 0;
-}
-
-/**
- * Returns the number of lines.
- *
- * @return the number of lines in the widget
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getLineCount () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.EM_GETLINECOUNT, 0, 0);
-}
-
-/**
- * Returns the line delimiter.
- *
- * @return a string that is the line delimiter
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #DELIMITER
- */
-public String getLineDelimiter () {
- checkWidget ();
- return DELIMITER;
-}
-
-/**
- * Returns the height of a line.
- *
- * @return the height of a row of text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getLineHeight () {
- checkWidget ();
- int /*long*/ newFont, oldFont = 0;
- int /*long*/ hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ();
- OS.GetTextMetrics (hDC, tm);
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- return tm.tmHeight;
-}
-
-/**
- * Returns the orientation of the receiver, which will be one of the
- * constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getOrientation () {
- checkWidget();
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-/**
- * Returns the widget message. The message text is displayed
- * as a hint for the user, indicating the purpose of the field.
- * <p>
- * Typically this is used in conjunction with <code>SWT.SEARCH</code>.
- * </p>
- *
- * @return the widget message
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public String getMessage () {
- checkWidget ();
- return message;
-}
-
-/**
- * Returns the character position at the given point in the receiver
- * or -1 if no such position exists. The point is in the coordinate
- * system of the receiver.
- * <p>
- * Indexing is zero based.
- * </p>
- *
- * @return the position of the caret
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-//TODO - Javadoc
-/*public*/ int getPosition (Point point) {
- checkWidget();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- int /*long*/ lParam = OS.MAKELPARAM (point.x, point.y);
- int position = OS.LOWORD (OS.SendMessage (handle, OS.EM_CHARFROMPOS, 0, lParam));
- if (!OS.IsUnicode && OS.IsDBLocale) position = mbcsToWcsPos (position);
- return position;
-}
-
-/**
- * Returns a <code>Point</code> whose x coordinate is the
- * character position representing the start of the selected
- * text, and whose y coordinate is the character position
- * representing the end of the selection. An "empty" selection
- * is indicated by the x and y coordinates having the same value.
- * <p>
- * Indexing is zero based. The range of a selection is from
- * 0..N where N is the number of characters in the widget.
- * </p>
- *
- * @return a point representing the selection start and end
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSelection () {
- checkWidget ();
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- if (!OS.IsUnicode && OS.IsDBLocale) {
- start [0] = mbcsToWcsPos (start [0]);
- end [0] = mbcsToWcsPos (end [0]);
- }
- return new Point (start [0], end [0]);
-}
-
-/**
- * Returns the number of selected characters.
- *
- * @return the number of selected characters.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget ();
- Point selection = getSelection ();
- return selection.y - selection.x;
-}
-
-/**
- * Gets the selected text, or an empty string if there is no current selection.
- *
- * @return the selected text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getSelectionText () {
- checkWidget ();
- int length = OS.GetWindowTextLength (handle);
- if (length == 0) return "";
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- if (start [0] == end [0]) return "";
- TCHAR buffer = new TCHAR (getCodePage (), length + 1);
- OS.GetWindowText (handle, buffer, length + 1);
- return buffer.toString (start [0], end [0] - start [0]);
-}
-
-/**
- * Returns the number of tabs.
- * <p>
- * Tab stop spacing is specified in terms of the
- * space (' ') character. The width of a single
- * tab stop is the pixel width of the spaces.
- * </p>
- *
- * @return the number of tab characters
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTabs () {
- checkWidget ();
- return tabs;
-}
-
-int getTabWidth (int tabs) {
- int /*long*/ oldFont = 0;
- RECT rect = new RECT ();
- int /*long*/ hDC = OS.GetDC (handle);
- int /*long*/ newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX;
- TCHAR SPACE = new TCHAR (getCodePage (), " ", false);
- OS.DrawText (hDC, SPACE, SPACE.length (), rect, flags);
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- return (rect.right - rect.left) * tabs;
-}
-
-/**
- * Returns the widget text.
- * <p>
- * The text for a text widget is the characters in the widget, or
- * an empty string if this has never been set.
- * </p>
- *
- * @return the widget text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- int length = OS.GetWindowTextLength (handle);
- if (length == 0) return "";
- TCHAR buffer = new TCHAR (getCodePage (), length + 1);
- OS.GetWindowText (handle, buffer, length + 1);
- return buffer.toString (0, length);
-}
-
-/**
- * Returns a range of text. Returns an empty string if the
- * start of the range is greater than the end.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N-1 where N is
- * the number of characters in the widget.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- * @return the range of text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText (int start, int end) {
- checkWidget ();
- if (!(start <= end && 0 <= end)) return "";
- int length = OS.GetWindowTextLength (handle);
- if (!OS.IsUnicode && OS.IsDBLocale) length = mbcsToWcsPos (length);
- end = Math.min (end, length - 1);
- if (start > end) return "";
- start = Math.max (0, start);
- /*
- * NOTE: The current implementation uses substring ()
- * which can reference a potentially large character
- * array.
- */
- return getText ().substring (start, end + 1);
-}
-
-/**
- * Returns the maximum number of characters that the receiver is capable of holding.
- * <p>
- * If this has not been changed by <code>setTextLimit()</code>,
- * it will be the constant <code>Text.LIMIT</code>.
- * </p>
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public int getTextLimit () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.EM_GETLIMITTEXT, 0, 0) & 0x7FFFFFFF;
-}
-
-/**
- * Returns the zero-relative index of the line which is currently
- * at the top of the receiver.
- * <p>
- * This index can change when lines are scrolled or new lines are added or removed.
- * </p>
- *
- * @return the index of the top line
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return 0;
- return (int)/*64*/OS.SendMessage (handle, OS.EM_GETFIRSTVISIBLELINE, 0, 0);
-}
-
-/**
- * Returns the top pixel.
- * <p>
- * The top pixel is the pixel position of the line
- * that is currently at the top of the widget. On
- * some platforms, a text widget can be scrolled by
- * pixels instead of lines so that a partial line
- * is displayed at the top of the widget.
- * </p><p>
- * The top pixel changes when the widget is scrolled.
- * The top pixel does not include the widget trimming.
- * </p>
- *
- * @return the pixel position of the top line
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopPixel () {
- checkWidget ();
- /*
- * Note, EM_GETSCROLLPOS is implemented in Rich Edit 3.0
- * and greater. The plain text widget and previous versions
- * of Rich Edit return zero.
- */
- int [] buffer = new int [2];
- int /*long*/ code = OS.SendMessage (handle, OS.EM_GETSCROLLPOS, 0, buffer);
- if (code == 1) return buffer [1];
- return getTopIndex () * getLineHeight ();
-}
-
-/**
- * Inserts a string.
- * <p>
- * The old selection is replaced with the new text.
- * </p>
- *
- * @param string the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is <code>null</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void insert (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- string = Display.withCrLf (string);
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- string = verifyText (string, start [0], end [0], null);
- if (string == null) return;
- }
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- /*
- * Feature in Windows. When an edit control with ES_MULTILINE
- * style that does not have the WS_VSCROLL style is full (i.e.
- * there is no space at the end to draw any more characters),
- * EM_REPLACESEL sends a WM_CHAR with a backspace character
- * to remove any further text that is added. This is an
- * implementation detail of the edit control that is unexpected
- * and can cause endless recursion when EM_REPLACESEL is sent
- * from a WM_CHAR handler. The fix is to ignore calling the
- * handler from WM_CHAR.
- */
- ignoreCharacter = true;
- OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
- ignoreCharacter = false;
-}
-
-int mbcsToWcsPos (int mbcsPos) {
- if (mbcsPos <= 0) return 0;
- if (OS.IsUnicode) return mbcsPos;
- int cp = getCodePage ();
- int wcsTotal = 0, mbcsTotal = 0;
- byte [] buffer = new byte [128];
- String delimiter = getLineDelimiter();
- int delimiterSize = delimiter.length ();
- int count = (int)/*64*/OS.SendMessageA (handle, OS.EM_GETLINECOUNT, 0, 0);
- for (int line=0; line<count; line++) {
- int wcsSize = 0;
- int linePos = (int)/*64*/OS.SendMessageA (handle, OS.EM_LINEINDEX, line, 0);
- int mbcsSize = (int)/*64*/OS.SendMessageA (handle, OS.EM_LINELENGTH, linePos, 0);
- if (mbcsSize != 0) {
- if (mbcsSize + delimiterSize > buffer.length) {
- buffer = new byte [mbcsSize + delimiterSize];
- }
- //ENDIAN
- buffer [0] = (byte) (mbcsSize & 0xFF);
- buffer [1] = (byte) (mbcsSize >> 8);
- mbcsSize = (int)/*64*/OS.SendMessageA (handle, OS.EM_GETLINE, line, buffer);
- wcsSize = OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, buffer, mbcsSize, null, 0);
- }
- if (line - 1 != count) {
- for (int i=0; i<delimiterSize; i++) {
- buffer [mbcsSize++] = (byte) delimiter.charAt (i);
- }
- wcsSize += delimiterSize;
- }
- if ((mbcsTotal + mbcsSize) >= mbcsPos) {
- int bufferSize = mbcsPos - mbcsTotal;
- wcsSize = OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, buffer, bufferSize, null, 0);
- return wcsTotal + wcsSize;
- }
- wcsTotal += wcsSize;
- mbcsTotal += mbcsSize;
- }
- return wcsTotal;
-}
-
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void paste () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- OS.SendMessage (handle, OS.WM_PASTE, 0, 0);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- message = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- */
-public void removeVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-
-/**
- * Selects all the text in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget ();
- OS.SendMessage (handle, OS.EM_SETSEL, 0, -1);
-}
-
-boolean sendKeyEvent (int type, int msg, int /*long*/ wParam, int /*long*/ lParam, Event event) {
- if (!super.sendKeyEvent (type, msg, wParam, lParam, event)) {
- return false;
- }
- if ((style & SWT.READ_ONLY) != 0) return true;
- if (ignoreVerify) return true;
- if (type != SWT.KeyDown) return true;
- if (msg != OS.WM_CHAR && msg != OS.WM_KEYDOWN && msg != OS.WM_IME_CHAR) {
- return true;
- }
- if (event.character == 0) return true;
- if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return true;
- char key = event.character;
- int stateMask = event.stateMask;
-
- /*
- * Disable all magic keys that could modify the text
- * and don't send events when Alt, Shift or Ctrl is
- * pressed.
- */
- switch (msg) {
- case OS.WM_CHAR:
- if (key != 0x08 && key != 0x7F && key != '\r' && key != '\t' && key != '\n') break;
- // FALL THROUGH
- case OS.WM_KEYDOWN:
- if ((stateMask & (SWT.ALT | SWT.SHIFT | SWT.CONTROL)) != 0) return false;
- break;
- }
-
- /*
- * Feature in Windows. If the left button is down in
- * the text widget, it refuses the character. The fix
- * is to detect this case and avoid sending a verify
- * event.
- */
- if (OS.GetKeyState (OS.VK_LBUTTON) < 0) {
- if (handle == OS.GetCapture()) return true;
- }
-
- /* Verify the character */
- String oldText = "";
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- switch (key) {
- case 0x08: /* Bs */
- if (start [0] == end [0]) {
- if (start [0] == 0) return true;
- int lineStart = (int)/*64*/OS.SendMessage (handle, OS.EM_LINEINDEX, -1, 0);
- if (start [0] == lineStart) {
- start [0] = start [0] - DELIMITER.length ();
- } else {
- start [0] = start [0] - 1;
- if (!OS.IsUnicode && OS.IsDBLocale) {
- int [] newStart = new int [1], newEnd = new int [1];
- OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]);
- OS.SendMessage (handle, OS.EM_GETSEL, newStart, newEnd);
- if (start [0] != newStart [0]) start [0] = start [0] - 1;
- }
- }
- start [0] = Math.max (start [0], 0);
- }
- break;
- case 0x7F: /* Del */
- if (start [0] == end [0]) {
- int length = OS.GetWindowTextLength (handle);
- if (start [0] == length) return true;
- int line = (int)/*64*/OS.SendMessage (handle, OS.EM_LINEFROMCHAR, end [0], 0);
- int lineStart = (int)/*64*/OS.SendMessage (handle, OS.EM_LINEINDEX, line + 1, 0);
- if (end [0] == lineStart - DELIMITER.length ()) {
- end [0] = end [0] + DELIMITER.length ();
- } else {
- end [0] = end [0] + 1;
- if (!OS.IsUnicode && OS.IsDBLocale) {
- int [] newStart = new int [1], newEnd = new int [1];
- OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]);
- OS.SendMessage (handle, OS.EM_GETSEL, newStart, newEnd);
- if (end [0] != newEnd [0]) end [0] = end [0] + 1;
- }
- }
- end [0] = Math.min (end [0], length);
- }
- break;
- case '\r': /* Return */
- if ((style & SWT.SINGLE) != 0) return true;
- oldText = DELIMITER;
- break;
- default: /* Tab and other characters */
- if (key != '\t' && key < 0x20) return true;
- oldText = new String (new char [] {key});
- break;
- }
- String newText = verifyText (oldText, start [0], end [0], event);
- if (newText == null) return false;
- if (newText == oldText) return true;
- newText = Display.withCrLf (newText);
- TCHAR buffer = new TCHAR (getCodePage (), newText, true);
- OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]);
- /*
- * Feature in Windows. When an edit control with ES_MULTILINE
- * style that does not have the WS_VSCROLL style is full (i.e.
- * there is no space at the end to draw any more characters),
- * EM_REPLACESEL sends a WM_CHAR with a backspace character
- * to remove any further text that is added. This is an
- * implementation detail of the edit control that is unexpected
- * and can cause endless recursion when EM_REPLACESEL is sent
- * from a WM_CHAR handler. The fix is to ignore calling the
- * handler from WM_CHAR.
- */
- ignoreCharacter = true;
- OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
- ignoreCharacter = false;
- return false;
-}
-
-void setBounds (int x, int y, int width, int height, int flags) {
- /*
- * Feature in Windows. When the caret is moved,
- * the text widget scrolls to show the new location.
- * This means that the text widget may be scrolled
- * to the right in order to show the caret when the
- * widget is not large enough to show both the caret
- * location and all the text. Unfortunately, when
- * the text widget is resized such that all the text
- * and the caret could be visible, Windows does not
- * scroll the widget back. The fix is to resize the
- * text widget, set the selection to the start of the
- * text and then restore the selection. This will
- * cause the text widget compute the correct scroll
- * position.
- */
- if ((flags & OS.SWP_NOSIZE) == 0 && width != 0) {
- RECT rect = new RECT ();
- OS.GetWindowRect (handle, rect);
- int /*long*/ margins = OS.SendMessage (handle, OS.EM_GETMARGINS, 0, 0);
- int marginWidth = OS.LOWORD (margins) + OS.HIWORD (margins);
- if (rect.right - rect.left <= marginWidth) {
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- if (start [0] != 0 || end [0] != 0) {
- SetWindowPos (handle, 0, x, y, width, height, flags);
- OS.SendMessage (handle, OS.EM_SETSEL, 0, 0);
- OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]);
- return;
- }
- }
- }
- super.setBounds (x, y, width, height, flags);
-
- /*
- * Bug in Windows. If the client area height is smaller than
- * the font height, then the multi-line text widget does not
- * update the formatting rectangle when resized. The fix is to
- * detect this case and explicitly set the formatting rectangle.
- */
- if ((flags & OS.SWP_NOSIZE) == 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.ES_MULTILINE) != 0) {
- int /*long*/ newFont, oldFont = 0;
- int /*long*/ hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ();
- OS.GetTextMetrics (hDC, tm);
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- RECT rect = new RECT();
- OS.GetClientRect (handle, rect);
- if ((rect.bottom - rect.top) < tm.tmHeight) {
- int /*long*/ margins = OS.SendMessage (handle, OS.EM_GETMARGINS, 0, 0);
- rect.left += OS.LOWORD (margins);
- rect.right -= OS.HIWORD (margins);
- rect.top = 0;
- rect.bottom = tm.tmHeight;
- OS.SendMessage (handle, OS.EM_SETRECT, 0, rect);
- }
- }
- }
-}
-
-void setDefaultFont () {
- super.setDefaultFont ();
- setMargins ();
-}
-
-/**
- * Sets the double click enabled flag.
- * <p>
- * The double click flag enables or disables the
- * default action of the text widget when the user
- * double clicks.
- * </p><p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param doubleClick the new double click flag
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDoubleClickEnabled (boolean doubleClick) {
- checkWidget ();
- this.doubleClick = doubleClick;
-}
-
-/**
- * Sets the echo character.
- * <p>
- * The echo character is the character that is
- * displayed when the user enters text or the
- * text is changed by the programmer. Setting
- * the echo character to '\0' clears the echo
- * character and redraws the original text.
- * If for any reason the echo character is invalid,
- * or if the platform does not allow modification
- * of the echo character, the default echo character
- * for the platform is used.
- * </p>
- *
- * @param echo the new echo character
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEchoChar (char echo) {
- checkWidget ();
- if ((style & SWT.MULTI) != 0) return;
- if (echo != 0) {
- if ((echo = (char) Display.wcsToMbcs (echo, getCodePage ())) == 0) echo = '*';
- }
- OS.SendMessage (handle, OS.EM_SETPASSWORDCHAR, echo, 0);
- /*
- * Bug in Windows. When the password character is changed,
- * Windows does not redraw to show the new password character.
- * The fix is to force a redraw when the character is set.
- */
- OS.InvalidateRect (handle, null, true);
-}
-
-/**
- * Sets the editable state.
- *
- * @param editable the new editable state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEditable (boolean editable) {
- checkWidget ();
- style &= ~SWT.READ_ONLY;
- if (!editable) style |= SWT.READ_ONLY;
- OS.SendMessage (handle, OS.EM_SETREADONLY, editable ? 0 : 1, 0);
-}
-
-public void setFont (Font font) {
- checkWidget ();
- super.setFont (font);
- setTabStops (tabs);
- setMargins ();
-}
-
-void setMargins () {
- /*
- * Bug in Windows. When EM_SETCUEBANNER is used to set the
- * banner text, the control does not take into account the
- * margins, causing the first character to be clipped. The
- * fix is to set the margins to zero.
- */
- if ((style & SWT.SEARCH) != 0) {
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- OS.SendMessage (handle, OS.EM_SETMARGINS, OS.EC_LEFTMARGIN | OS.EC_RIGHTMARGIN, 0);
- }
- }
-}
-
-/**
- * Sets the widget message. The message text is displayed
- * as a hint for the user, indicating the purpose of the field.
- * <p>
- * Typically this is used in conjunction with <code>SWT.SEARCH</code>.
- * </p>
- *
- * @param message the new message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the message is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public void setMessage (String message) {
- checkWidget ();
- if (message == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.message = message;
- if (!OS.IsWinCE) {
- if (OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.ES_MULTILINE) == 0) {
- int length = message.length ();
- char [] chars = new char [length + 1];
- message.getChars(0, length, chars, 0);
- OS.SendMessage (handle, OS.EM_SETCUEBANNER, 0, chars);
- }
- } else {
- OS.InvalidateRect (handle, null, true);
- }
- }
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public void setOrientation (int orientation) {
- checkWidget();
- if (OS.IsWinCE) return;
- if (OS.WIN32_VERSION < OS.VERSION (4, 10)) return;
- int flags = SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT;
- if ((orientation & flags) == 0 || (orientation & flags) == flags) return;
- style &= ~flags;
- style |= orientation & flags;
- int bits = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- bits |= OS.WS_EX_RTLREADING | OS.WS_EX_LEFTSCROLLBAR;
- } else {
- bits &= ~(OS.WS_EX_RTLREADING | OS.WS_EX_LEFTSCROLLBAR);
- }
- OS.SetWindowLong (handle, OS.GWL_EXSTYLE, bits);
- fixAlignment ();
-}
-
-/**
- * Sets the selection.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * regular array indexing rules.
- * </p>
- *
- * @param start new caret position
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int start) {
- checkWidget ();
- if (!OS.IsUnicode && OS.IsDBLocale) start = wcsToMbcsPos (start);
- OS.SendMessage (handle, OS.EM_SETSEL, start, start);
- OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
-}
-
-/**
- * Sets the selection to the range specified
- * by the given start and end indices.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * usual array indexing rules.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int start, int end) {
- checkWidget ();
- if (!OS.IsUnicode && OS.IsDBLocale) {
- start = wcsToMbcsPos (start);
- end = wcsToMbcsPos (end);
- }
- OS.SendMessage (handle, OS.EM_SETSEL, start, end);
- OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
-}
-
-public void setRedraw (boolean redraw) {
- checkWidget ();
- super.setRedraw (redraw);
- /*
- * Feature in Windows. When WM_SETREDRAW is used to turn
- * redraw off, the edit control is not scrolled to show the
- * i-beam. The fix is to detect that the i-beam has moved
- * while redraw is turned off and force it to be visible
- * when redraw is restored.
- */
- if (!getDrawing ()) return;
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- if (!redraw) {
- oldStart = start [0]; oldEnd = end [0];
- } else {
- if (oldStart == start [0] && oldEnd == end [0]) return;
- OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
- }
-}
-
-/**
- * Sets the selection to the range specified
- * by the given point, where the x coordinate
- * represents the start index and the y coordinate
- * represents the end index.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * usual array indexing rules.
- * </p>
- *
- * @param selection the point
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (Point selection) {
- checkWidget ();
- if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (selection.x, selection.y);
-}
-
-/**
- * Sets the number of tabs.
- * <p>
- * Tab stop spacing is specified in terms of the
- * space (' ') character. The width of a single
- * tab stop is the pixel width of the spaces.
- * </p>
- *
- * @param tabs the number of tabs
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTabs (int tabs) {
- checkWidget ();
- if (tabs < 0) return;
- setTabStops (this.tabs = tabs);
-}
-
-void setTabStops (int tabs) {
- /*
- * Feature in Windows. Windows expects the tab spacing in
- * dialog units so we must convert from space widths. Due
- * to round off error, the tab spacing may not be the exact
- * number of space widths, depending on the font.
- */
- int width = (getTabWidth (tabs) * 4) / OS.LOWORD (OS.GetDialogBaseUnits ());
- OS.SendMessage (handle, OS.EM_SETTABSTOPS, 1, new int [] {width});
-}
-
-/**
- * Sets the contents of the receiver to the given string. If the receiver has style
- * SINGLE and the argument contains multiple lines of text, the result of this
- * operation is undefined and may vary from platform to platform.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- string = Display.withCrLf (string);
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- int length = OS.GetWindowTextLength (handle);
- string = verifyText (string, 0, length, null);
- if (string == null) return;
- }
- int limit = (int)/*64*/OS.SendMessage (handle, OS.EM_GETLIMITTEXT, 0, 0) & 0x7FFFFFFF;
- if (string.length () > limit) string = string.substring (0, limit);
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- OS.SetWindowText (handle, buffer);
- /*
- * Bug in Windows. When the widget is multi line
- * text widget, it does not send a WM_COMMAND with
- * control code EN_CHANGE from SetWindowText () to
- * notify the application that the text has changed.
- * The fix is to send the event.
- */
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.ES_MULTILINE) != 0) {
- sendEvent (SWT.Modify);
- // widget could be disposed at this point
- }
-}
-
-/**
- * Sets the maximum number of characters that the receiver
- * is capable of holding to be the argument.
- * <p>
- * Instead of trying to set the text limit to zero, consider
- * creating a read-only text widget.
- * </p><p>
- * To reset this value to the default, use <code>setTextLimit(Text.LIMIT)</code>.
- * Specifying a limit value larger than <code>Text.LIMIT</code> sets the
- * receiver's limit to <code>Text.LIMIT</code>.
- * </p>
- *
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public void setTextLimit (int limit) {
- checkWidget ();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- OS.SendMessage (handle, OS.EM_SETLIMITTEXT, limit, 0);
-}
-
-/**
- * Sets the zero-relative index of the line which is currently
- * at the top of the receiver. This index can change when lines
- * are scrolled or new lines are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- int count = (int)/*64*/OS.SendMessage (handle, OS.EM_GETLINECOUNT, 0, 0);
- index = Math.min (Math.max (index, 0), count - 1);
- int topIndex = (int)/*64*/OS.SendMessage (handle, OS.EM_GETFIRSTVISIBLELINE, 0, 0);
- OS.SendMessage (handle, OS.EM_LINESCROLL, 0, index - topIndex);
-}
-
-/**
- * Shows the selection.
- * <p>
- * If the selection is already showing
- * in the receiver, this method simply returns. Otherwise,
- * lines are scrolled until the selection is visible.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void showSelection () {
- checkWidget ();
- OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
-}
-
-String verifyText (String string, int start, int end, Event keyEvent) {
- if (ignoreVerify) return string;
- Event event = new Event ();
- event.text = string;
- event.start = start;
- event.end = end;
- if (keyEvent != null) {
- event.character = keyEvent.character;
- event.keyCode = keyEvent.keyCode;
- event.stateMask = keyEvent.stateMask;
- }
- if (!OS.IsUnicode && OS.IsDBLocale) {
- event.start = mbcsToWcsPos (start);
- event.end = mbcsToWcsPos (end);
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the verify
- * event. If this happens, answer null to cancel
- * the operation.
- */
- sendEvent (SWT.Verify, event);
- if (!event.doit || isDisposed ()) return null;
- return event.text;
-}
-
-int wcsToMbcsPos (int wcsPos) {
- if (wcsPos <= 0) return 0;
- if (OS.IsUnicode) return wcsPos;
- int cp = getCodePage ();
- int wcsTotal = 0, mbcsTotal = 0;
- byte [] buffer = new byte [128];
- String delimiter = getLineDelimiter ();
- int delimiterSize = delimiter.length ();
- int count = (int)/*64*/OS.SendMessageA (handle, OS.EM_GETLINECOUNT, 0, 0);
- for (int line=0; line<count; line++) {
- int wcsSize = 0;
- int linePos = (int)/*64*/OS.SendMessageA (handle, OS.EM_LINEINDEX, line, 0);
- int mbcsSize = (int)/*64*/OS.SendMessageA (handle, OS.EM_LINELENGTH, linePos, 0);
- if (mbcsSize != 0) {
- if (mbcsSize + delimiterSize > buffer.length) {
- buffer = new byte [mbcsSize + delimiterSize];
- }
- //ENDIAN
- buffer [0] = (byte) (mbcsSize & 0xFF);
- buffer [1] = (byte) (mbcsSize >> 8);
- mbcsSize = (int)/*64*/OS.SendMessageA (handle, OS.EM_GETLINE, line, buffer);
- wcsSize = OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, buffer, mbcsSize, null, 0);
- }
- if (line - 1 != count) {
- for (int i=0; i<delimiterSize; i++) {
- buffer [mbcsSize++] = (byte) delimiter.charAt (i);
- }
- wcsSize += delimiterSize;
- }
- if ((wcsTotal + wcsSize) >= wcsPos) {
- wcsSize = 0;
- int index = 0;
- while (index < mbcsSize) {
- if ((wcsTotal + wcsSize) == wcsPos) {
- return mbcsTotal + index;
- }
- if (OS.IsDBCSLeadByte (buffer [index++])) index++;
- wcsSize++;
- }
- return mbcsTotal + mbcsSize;
- }
- wcsTotal += wcsSize;
- mbcsTotal += mbcsSize;
- }
- return mbcsTotal;
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle () | OS.ES_AUTOHSCROLL;
- if ((style & SWT.PASSWORD) != 0) bits |= OS.ES_PASSWORD;
- if ((style & SWT.CENTER) != 0) bits |= OS.ES_CENTER;
- if ((style & SWT.RIGHT) != 0) bits |= OS.ES_RIGHT;
- if ((style & SWT.READ_ONLY) != 0) bits |= OS.ES_READONLY;
- if ((style & SWT.SINGLE) != 0) {
- /*
- * Feature in Windows. When a text control is read-only,
- * uses COLOR_3DFACE for the background . If the text
- * controls single-line and is within a tab folder or
- * some other themed control, using WM_ERASEBKGND and
- * WM_CTRCOLOR to draw the theme background results in
- * pixel corruption. The fix is to use an ES_MULTILINE
- * text control instead.
- */
- if ((style & SWT.READ_ONLY) != 0) {
- if ((style & (SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- bits |= OS.ES_MULTILINE;
- }
- }
- }
- return bits;
- }
- bits |= OS.ES_MULTILINE | OS.ES_NOHIDESEL | OS.ES_AUTOVSCROLL;
- if ((style & SWT.WRAP) != 0) bits &= ~(OS.WS_HSCROLL | OS.ES_AUTOHSCROLL);
- return bits;
-}
-
-TCHAR windowClass () {
- return EditClass;
-}
-
-int /*long*/ windowProc () {
- return EditProc;
-}
-
-int /*long*/ windowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (msg == OS.EM_UNDO) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.ES_MULTILINE) == 0) {
- LRESULT result = wmClipboard (OS.EM_UNDO, wParam, lParam);
- if (result != null) return result.value;
- return callWindowProc (hwnd, OS.EM_UNDO, wParam, lParam);
- }
- }
- if (msg == Display.SWT_RESTORECARET) {
- callWindowProc (hwnd, OS.WM_KILLFOCUS, 0, 0);
- callWindowProc (hwnd, OS.WM_SETFOCUS, 0, 0);
- return 1;
- }
- return super.windowProc (hwnd, msg, wParam, lParam);
-}
-
-LRESULT WM_CHAR (int /*long*/ wParam, int /*long*/ lParam) {
- if (ignoreCharacter) return null;
- LRESULT result = super.WM_CHAR (wParam, lParam);
- if (result != null) return result;
-
- /*
- * Bug in Windows. When the user types CTRL and BS
- * in an edit control, a DEL character is generated.
- * Rather than deleting the text, the DEL character
- * is inserted into the control. The fix is to detect
- * this case and not call the window proc.
- */
- switch ((int)/*64*/wParam) {
- case SWT.DEL:
- if (OS.GetKeyState (OS.VK_CONTROL) < 0) {
- return LRESULT.ZERO;
- }
- }
-
- /*
- * Feature in Windows. For some reason, when the
- * widget is a single line text widget, when the
- * user presses tab, return or escape, Windows beeps.
- * The fix is to look for these keys and not call
- * the window proc.
- */
- if ((style & SWT.SINGLE) != 0) {
- switch ((int)/*64*/wParam) {
- case SWT.CR:
- postEvent (SWT.DefaultSelection);
- // FALL THROUGH
- case SWT.TAB:
- case SWT.ESC: return LRESULT.ZERO;
- }
- }
- return result;
-}
-
-LRESULT WM_CLEAR (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_CLEAR (wParam, lParam);
- if (result != null) return result;
- return wmClipboard (OS.WM_CLEAR, wParam, lParam);
-}
-
-LRESULT WM_CUT (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_CUT (wParam, lParam);
- if (result != null) return result;
- return wmClipboard (OS.WM_CUT, wParam, lParam);
-}
-
-LRESULT WM_ERASEBKGND (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
- if ((style & SWT.READ_ONLY) != 0) {
- if ((style & (SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.ES_MULTILINE) != 0) {
- Control control = findBackgroundControl ();
- if (control == null && background == -1) {
- if ((state & THEME_BACKGROUND) != 0) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- control = findThemeControl ();
- if (control != null) {
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- fillThemeBackground (wParam, control, rect);
- return LRESULT.ONE;
- }
- }
- }
- }
- }
- }
- }
- return result;
-}
-
-LRESULT WM_GETDLGCODE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_GETDLGCODE (wParam, lParam);
- if (result != null) return result;
-
- /*
- * Bug in WinCE PPC. For some reason, sending WM_GETDLGCODE
- * to a multi-line edit control causes it to ignore return and
- * tab keys. The fix is to return the value which is normally
- * returned by the text window proc on other versions of Windows.
- */
- if (OS.IsPPC) {
- if ((style & SWT.MULTI) != 0 && (style & SWT.READ_ONLY) == 0 && lParam == 0) {
- return new LRESULT (OS.DLGC_HASSETSEL | OS.DLGC_WANTALLKEYS | OS.DLGC_WANTCHARS);
- }
- }
-
- /*
- * Feature in Windows. Despite the fact that the
- * edit control is read only, it still returns a
- * dialog code indicating that it wants all keys.
- * The fix is to detect this case and clear the bits.
- *
- * NOTE: A read only edit control processes arrow keys
- * so DLGC_WANTARROWS should not be cleared.
- */
- if ((style & SWT.READ_ONLY) != 0) {
- int /*long*/ code = callWindowProc (handle, OS.WM_GETDLGCODE, wParam, lParam);
- code &= ~(OS.DLGC_WANTALLKEYS | OS.DLGC_WANTTAB);
- return new LRESULT (code);
- }
- return null;
-}
-
-LRESULT WM_IME_CHAR (int /*long*/ wParam, int /*long*/ lParam) {
-
- /* Process a DBCS character */
- Display display = this.display;
- display.lastKey = 0;
- display.lastAscii = (int)/*64*/wParam;
- display.lastVirtual = display.lastNull = display.lastDead = false;
- if (!sendKeyEvent (SWT.KeyDown, OS.WM_IME_CHAR, wParam, lParam)) {
- return LRESULT.ZERO;
- }
-
- /*
- * Feature in Windows. The Windows text widget uses
- * two 2 WM_CHAR's to process a DBCS key instead of
- * using WM_IME_CHAR. The fix is to allow the text
- * widget to get the WM_CHAR's but ignore sending
- * them to the application.
- */
- ignoreCharacter = true;
- int /*long*/ result = callWindowProc (handle, OS.WM_IME_CHAR, wParam, lParam);
- MSG msg = new MSG ();
- int flags = OS.PM_REMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE;
- while (OS.PeekMessage (msg, handle, OS.WM_CHAR, OS.WM_CHAR, flags)) {
- OS.TranslateMessage (msg);
- OS.DispatchMessage (msg);
- }
- ignoreCharacter = false;
-
- sendKeyEvent (SWT.KeyUp, OS.WM_IME_CHAR, wParam, lParam);
- // widget could be disposed at this point
- display.lastKey = display.lastAscii = 0;
- return new LRESULT (result);
-}
-
-LRESULT WM_LBUTTONDBLCLK (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Prevent Windows from processing WM_LBUTTONDBLCLK
- * when double clicking behavior is disabled by not
- * calling the window proc.
- */
- LRESULT result = null;
- sendMouseEvent (SWT.MouseDown, 1, handle, OS.WM_LBUTTONDOWN, wParam, lParam);
- if (!sendMouseEvent (SWT.MouseDoubleClick, 1, handle, OS.WM_LBUTTONDBLCLK, wParam, lParam)) {
- result = LRESULT.ZERO;
- }
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- if (!doubleClick) return LRESULT.ZERO;
-
- /*
- * Bug in Windows. When the last line of text in the
- * widget is double clicked and the line is empty, Windows
- * hides the i-beam then moves it to the first line in
- * the widget but does not scroll to show the user.
- * If the user types without clicking the mouse, invalid
- * characters are displayed at the end of each line of
- * text in the widget. The fix is to detect this case
- * and avoid calling the window proc.
- */
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- if (start [0] == end [0]) {
- int length = OS.GetWindowTextLength (handle);
- if (length == start [0]) {
- int code = (int)/*64*/OS.SendMessage (handle, OS.EM_LINELENGTH, length, 0);
- if (code == 0) return LRESULT.ZERO;
- }
- }
- return result;
-}
-
-LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- if (OS.IsPPC) {
- LRESULT result = null;
- Display display = this.display;
- display.captureChanged = false;
- boolean dispatch = sendMouseEvent (SWT.MouseDown, 1, handle, OS.WM_LBUTTONDOWN, wParam, lParam);
- /*
- * Note: On WinCE PPC, only attempt to recognize the gesture for
- * a context menu when the control contains a valid menu or there
- * are listeners for the MenuDetect event.
- *
- * Note: On WinCE PPC, the gesture that brings up a popup menu
- * on the text widget must keep the current text selection. As a
- * result, the window proc is only called if the menu is not shown.
- */
- boolean hasMenu = menu != null && !menu.isDisposed ();
- if (hasMenu || hooks (SWT.MenuDetect)) {
- int x = OS.GET_X_LPARAM (lParam);
- int y = OS.GET_Y_LPARAM (lParam);
- SHRGINFO shrg = new SHRGINFO ();
- shrg.cbSize = SHRGINFO.sizeof;
- shrg.hwndClient = handle;
- shrg.ptDown_x = x;
- shrg.ptDown_y = y;
- shrg.dwFlags = OS.SHRG_RETURNCMD;
- int type = OS.SHRecognizeGesture (shrg);
- if (type == OS.GN_CONTEXTMENU) {
- showMenu (x, y);
- return LRESULT.ONE;
- }
- }
- if (dispatch) {
- result = new LRESULT (callWindowProc (handle, OS.WM_LBUTTONDOWN, wParam, lParam));
- } else {
- result = LRESULT.ZERO;
- }
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- return result;
- }
- return super.WM_LBUTTONDOWN (wParam, lParam);
-}
-
-LRESULT WM_PASTE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_PASTE (wParam, lParam);
- if (result != null) return result;
- return wmClipboard (OS.WM_PASTE, wParam, lParam);
-}
-
-LRESULT WM_UNDO (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_UNDO (wParam, lParam);
- if (result != null) return result;
- return wmClipboard (OS.WM_UNDO, wParam, lParam);
-}
-
-LRESULT wmClipboard (int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if ((style & SWT.READ_ONLY) != 0) return null;
- if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return null;
- boolean call = false;
- int [] start = new int [1], end = new int [1];
- String newText = null;
- switch (msg) {
- case OS.WM_CLEAR:
- case OS.WM_CUT:
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- if (start [0] != end [0]) {
- newText = "";
- call = true;
- }
- break;
- case OS.WM_PASTE:
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- newText = getClipboardText ();
- break;
- case OS.EM_UNDO:
- case OS.WM_UNDO:
- if (OS.SendMessage (handle, OS.EM_CANUNDO, 0, 0) != 0) {
- ignoreModify = ignoreCharacter = true;
- callWindowProc (handle, msg, wParam, lParam);
- int length = OS.GetWindowTextLength (handle);
- int [] newStart = new int [1], newEnd = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, newStart, newEnd);
- if (length != 0 && newStart [0] != newEnd [0]) {
- TCHAR buffer = new TCHAR (getCodePage (), length + 1);
- OS.GetWindowText (handle, buffer, length + 1);
- newText = buffer.toString (newStart [0], newEnd [0] - newStart [0]);
- } else {
- newText = "";
- }
- callWindowProc (handle, msg, wParam, lParam);
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- ignoreModify = ignoreCharacter = false;
- }
- break;
- }
- if (newText != null) {
- String oldText = newText;
- newText = verifyText (newText, start [0], end [0], null);
- if (newText == null) return LRESULT.ZERO;
- if (!newText.equals (oldText)) {
- if (call) {
- callWindowProc (handle, msg, wParam, lParam);
- }
- newText = Display.withCrLf (newText);
- TCHAR buffer = new TCHAR (getCodePage (), newText, true);
- /*
- * Feature in Windows. When an edit control with ES_MULTILINE
- * style that does not have the WS_VSCROLL style is full (i.e.
- * there is no space at the end to draw any more characters),
- * EM_REPLACESEL sends a WM_CHAR with a backspace character
- * to remove any further text that is added. This is an
- * implementation detail of the edit control that is unexpected
- * and can cause endless recursion when EM_REPLACESEL is sent
- * from a WM_CHAR handler. The fix is to ignore calling the
- * handler from WM_CHAR.
- */
- ignoreCharacter = true;
- OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
- ignoreCharacter = false;
- return LRESULT.ZERO;
- }
- }
- if (msg == OS.WM_UNDO) {
- ignoreVerify = ignoreCharacter = true;
- callWindowProc (handle, OS.WM_UNDO, wParam, lParam);
- ignoreVerify = ignoreCharacter = false;
- return LRESULT.ONE;
- }
- return null;
-}
-
-LRESULT wmColorChild (int /*long*/ wParam, int /*long*/ lParam) {
- if ((style & SWT.READ_ONLY) != 0) {
- if ((style & (SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.ES_MULTILINE) != 0) {
- Control control = findBackgroundControl ();
- if (control == null && background == -1) {
- if ((state & THEME_BACKGROUND) != 0) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- control = findThemeControl ();
- if (control != null) {
- OS.SetTextColor (wParam, getForegroundPixel ());
- OS.SetBkColor (wParam, getBackgroundPixel ());
- OS.SetBkMode (wParam, OS.TRANSPARENT);
- return new LRESULT (OS.GetStockObject (OS.NULL_BRUSH));
- }
- }
- }
- }
- }
- }
- }
- return super.wmColorChild (wParam, lParam);
-}
-
-LRESULT wmCommandChild (int /*long*/ wParam, int /*long*/ lParam) {
- int code = OS.HIWORD (wParam);
- switch (code) {
- case OS.EN_CHANGE:
- if (findImageControl () != null) {
- OS.InvalidateRect (handle, null, true);
- }
- if (ignoreModify) break;
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the modify
- * event. If this happens, end the processing of the
- * Windows message by returning zero as the result of
- * the window proc.
- */
- sendEvent (SWT.Modify);
- if (isDisposed ()) return LRESULT.ZERO;
- break;
- case OS.EN_ALIGN_LTR_EC:
- style &= ~SWT.RIGHT_TO_LEFT;
- style |= SWT.LEFT_TO_RIGHT;
- fixAlignment ();
- break;
- case OS.EN_ALIGN_RTL_EC:
- style &= ~SWT.LEFT_TO_RIGHT;
- style |= SWT.RIGHT_TO_LEFT;
- fixAlignment ();
- break;
- }
- return super.wmCommandChild (wParam, lParam);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java
deleted file mode 100755
index cb95765513..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java
+++ /dev/null
@@ -1,1514 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class support the layout of selectable
- * tool bar items.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>ToolItem</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add <code>Control</code> children to it,
- * or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>FLAT, WRAP, RIGHT, HORIZONTAL, VERTICAL, SHADOW_OUT</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#toolbar">ToolBar, ToolItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolBar extends Composite {
- int lastFocusId, lastArrowId, lastHotId;
- ToolItem [] items;
- ToolItem [] tabItemList;
- boolean ignoreResize, ignoreMouse;
- ImageList imageList, disabledImageList, hotImageList;
- static final int /*long*/ ToolBarProc;
- static final TCHAR ToolBarClass = new TCHAR (0, OS.TOOLBARCLASSNAME, true);
- static {
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, ToolBarClass, lpWndClass);
- ToolBarProc = lpWndClass.lpfnWndProc;
- }
-
- /*
- * From the Windows SDK for TB_SETBUTTONSIZE:
- *
- * "If an application does not explicitly
- * set the button size, the size defaults
- * to 24 by 22 pixels".
- */
- static final int DEFAULT_WIDTH = 24;
- static final int DEFAULT_HEIGHT = 22;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#FLAT
- * @see SWT#WRAP
- * @see SWT#RIGHT
- * @see SWT#HORIZONTAL
- * @see SWT#SHADOW_OUT
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass()
- * @see Widget#getStyle()
- */
-public ToolBar (Composite parent, int style) {
- super (parent, checkStyle (style));
- /*
- * Ensure that either of HORIZONTAL or VERTICAL is set.
- * NOTE: HORIZONTAL and VERTICAL have the same values
- * as H_SCROLL and V_SCROLL so it is necessary to first
- * clear these bits to avoid scroll bars and then reset
- * the bits using the original style supplied by the
- * programmer.
- *
- * NOTE: The CCS_VERT style cannot be applied when the
- * widget is created because of this conflict.
- */
- if ((style & SWT.VERTICAL) != 0) {
- this.style |= SWT.VERTICAL;
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- /*
- * Feature in Windows. When a tool bar has the style
- * TBSTYLE_LIST and has a drop down item, Window leaves
- * too much padding around the button. This affects
- * every button in the tool bar and makes the preferred
- * height too big. The fix is to set the TBSTYLE_LIST
- * when the tool bar contains both text and images.
- *
- * NOTE: Tool bars with CCS_VERT must have TBSTYLE_LIST
- * set before any item is added or the tool bar does
- * not lay out properly. The work around does not run
- * in this case.
- */
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- if ((style & SWT.RIGHT) != 0) bits |= OS.TBSTYLE_LIST;
- }
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits | OS.CCS_VERT);
- } else {
- this.style |= SWT.HORIZONTAL;
- }
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- /*
- * Bug in Windows. For some reason, during the processing
- * of WM_SYSCHAR, the tool bar window proc does not call the
- * default window proc causing mnemonics for the menu bar
- * to be ignored. The fix is to always call the default
- * window proc for WM_SYSCHAR.
- */
- if (msg == OS.WM_SYSCHAR) {
- return OS.DefWindowProc (hwnd, msg, wParam, lParam);
- }
- return OS.CallWindowProc (ToolBarProc, hwnd, msg, wParam, lParam);
-}
-
-static int checkStyle (int style) {
- /*
- * On Windows, only flat tool bars can be traversed.
- */
- if ((style & SWT.FLAT) == 0) style |= SWT.NO_FOCUS;
-
- /*
- * A vertical tool bar cannot wrap because TB_SETROWS
- * fails when the toolbar has TBSTYLE_WRAPABLE.
- */
- if ((style & SWT.VERTICAL) != 0) style &= ~SWT.WRAP;
-
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-void checkBuffered () {
- super.checkBuffered ();
- if (OS.COMCTL32_MAJOR >= 6) style |= SWT.DOUBLE_BUFFERED;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0;
- if ((style & SWT.VERTICAL) != 0) {
- RECT rect = new RECT ();
- TBBUTTON lpButton = new TBBUTTON ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);
- for (int i=0; i<count; i++) {
- OS.SendMessage (handle, OS.TB_GETITEMRECT, i, rect);
- height = Math.max (height, rect.bottom);
- OS.SendMessage (handle, OS.TB_GETBUTTON, i, lpButton);
- if ((lpButton.fsStyle & OS.BTNS_SEP) != 0) {
- TBBUTTONINFO info = new TBBUTTONINFO ();
- info.cbSize = TBBUTTONINFO.sizeof;
- info.dwMask = OS.TBIF_SIZE;
- OS.SendMessage (handle, OS.TB_GETBUTTONINFO, lpButton.idCommand, info);
- width = Math.max (width, info.cx);
- } else {
- width = Math.max (width, rect.right);
- }
- }
- } else {
- RECT oldRect = new RECT ();
- OS.GetWindowRect (handle, oldRect);
- int oldWidth = oldRect.right - oldRect.left;
- int oldHeight = oldRect.bottom - oldRect.top;
- int border = getBorderWidth ();
- int newWidth = wHint == SWT.DEFAULT ? 0x3FFF : wHint + border * 2;
- int newHeight = hHint == SWT.DEFAULT ? 0x3FFF : hHint + border * 2;
- boolean redraw = getDrawing () && OS.IsWindowVisible (handle);
- ignoreResize = true;
- if (redraw) OS.UpdateWindow (handle);
- int flags = OS.SWP_NOACTIVATE | OS.SWP_NOMOVE | OS.SWP_NOREDRAW | OS.SWP_NOZORDER;
- SetWindowPos (handle, 0, 0, 0, newWidth, newHeight, flags);
- int count = (int)/*64*/OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);
- if (count != 0) {
- RECT rect = new RECT ();
- OS.SendMessage (handle, OS.TB_GETITEMRECT, count - 1, rect);
- width = Math.max (width, rect.right);
- height = Math.max (height, rect.bottom);
- }
- SetWindowPos (handle, 0, 0, 0, oldWidth, oldHeight, flags);
- if (redraw) OS.ValidateRect (handle, null);
- ignoreResize = false;
- }
-
- /*
- * From the Windows SDK for TB_SETBUTTONSIZE:
- *
- * "If an application does not explicitly
- * set the button size, the size defaults
- * to 24 by 22 pixels".
- */
- if (width == 0) width = DEFAULT_WIDTH;
- if (height == 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- Rectangle trim = computeTrim (0, 0, width, height);
- width = trim.width; height = trim.height;
- return new Point (width, height);
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
- Rectangle trim = super.computeTrim (x, y, width, height);
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.CCS_NODIVIDER) == 0) trim.height += 2;
- return trim;
-}
-
-Widget computeTabGroup () {
- ToolItem [] items = _getItems ();
- if (tabItemList == null) {
- int i = 0;
- while (i < items.length && items [i].control == null) i++;
- if (i == items.length) return super.computeTabGroup ();
- }
- int index = (int)/*64*/OS.SendMessage (handle, OS.TB_GETHOTITEM, 0, 0);
- if (index == -1) index = lastHotId;
- while (index >= 0) {
- ToolItem item = items [index];
- if (item.isTabGroup ()) return item;
- index--;
- }
- return super.computeTabGroup ();
-}
-
-Widget [] computeTabList () {
- ToolItem [] items = _getItems ();
- if (tabItemList == null) {
- int i = 0;
- while (i < items.length && items [i].control == null) i++;
- if (i == items.length) return super.computeTabList ();
- }
- Widget result [] = {};
- if (!isTabGroup () || !isEnabled () || !isVisible ()) return result;
- ToolItem [] list = tabList != null ? _getTabItemList () : items;
- for (int i=0; i<list.length; i++) {
- ToolItem child = list [i];
- Widget [] childList = child.computeTabList ();
- if (childList.length != 0) {
- Widget [] newResult = new Widget [result.length + childList.length];
- System.arraycopy (result, 0, newResult, 0, result.length);
- System.arraycopy (childList, 0, newResult, result.length, childList.length);
- result = newResult;
- }
- }
- if (result.length == 0) result = new Widget [] {this};
- return result;
-}
-
-void createHandle () {
- super.createHandle ();
- state &= ~CANVAS;
-
- /*
- * Feature in Windows. When TBSTYLE_FLAT is used to create
- * a flat toolbar, for some reason TBSTYLE_TRANSPARENT is
- * also set. This causes the toolbar to flicker when it is
- * moved or resized. The fix is to clear TBSTYLE_TRANSPARENT.
- *
- * NOTE: This work around is unnecessary on XP. There is no
- * flickering and clearing the TBSTYLE_TRANSPARENT interferes
- * with the XP theme.
- */
- if ((style & SWT.FLAT) != 0) {
- if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- bits &= ~OS.TBSTYLE_TRANSPARENT;
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- }
- }
-
- /*
- * Feature in Windows. Despite the fact that the
- * tool tip text contains \r\n, the tooltip will
- * not honour the new line unless TTM_SETMAXTIPWIDTH
- * is set. The fix is to set TTM_SETMAXTIPWIDTH to
- * a large value.
- */
- /*
- * These lines are intentionally commented. The tool
- * bar currently sets this value to 300 so it is not
- * necessary to set TTM_SETMAXTIPWIDTH.
- */
-// int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.TB_GETTOOLTIPS, 0, 0);
-// OS.SendMessage (hwndToolTip, OS.TTM_SETMAXTIPWIDTH, 0, 0x7FFF);
-
- /*
- * Feature in Windows. When the control is created,
- * it does not use the default system font. A new HFONT
- * is created and destroyed when the control is destroyed.
- * This means that a program that queries the font from
- * this control, uses the font in another control and then
- * destroys this control will have the font unexpectedly
- * destroyed in the other control. The fix is to assign
- * the font ourselves each time the control is created.
- * The control will not destroy a font that it did not
- * create.
- */
- int /*long*/ hFont = OS.GetStockObject (OS.SYSTEM_FONT);
- OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);
-
- /* Set the button struct, bitmap and button sizes */
- OS.SendMessage (handle, OS.TB_BUTTONSTRUCTSIZE, TBBUTTON.sizeof, 0);
- OS.SendMessage (handle, OS.TB_SETBITMAPSIZE, 0, 0);
- OS.SendMessage (handle, OS.TB_SETBUTTONSIZE, 0, 0);
-
- /* Set the extended style bits */
- int bits = OS.TBSTYLE_EX_DRAWDDARROWS | OS.TBSTYLE_EX_MIXEDBUTTONS | OS.TBSTYLE_EX_HIDECLIPPEDBUTTONS;
- if (OS.COMCTL32_MAJOR >= 6) bits |= OS.TBSTYLE_EX_DOUBLEBUFFER;
- OS.SendMessage (handle, OS.TB_SETEXTENDEDSTYLE, 0, bits);
-}
-
-void createItem (ToolItem item, int index) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);
- if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
- int id = 0;
- while (id < items.length && items [id] != null) id++;
- if (id == items.length) {
- ToolItem [] newItems = new ToolItem [items.length + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- int bits = item.widgetStyle ();
- TBBUTTON lpButton = new TBBUTTON ();
- lpButton.idCommand = id;
- lpButton.fsStyle = (byte) bits;
- lpButton.fsState = (byte) OS.TBSTATE_ENABLED;
-
- /*
- * Bug in Windows. Despite the fact that the image list
- * index has never been set for the item, Windows always
- * assumes that the image index for the item is valid.
- * When an item is inserted, the image index is zero.
- * Therefore, when the first image is inserted and is
- * assigned image index zero, every item draws with this
- * image. The fix is to set the image index to none
- * when the item is created. This is not necessary in
- * the case when the item has the BTNS_SEP style because
- * separators cannot show images.
- */
- if ((bits & OS.BTNS_SEP) == 0) lpButton.iBitmap = OS.I_IMAGENONE;
- if (OS.SendMessage (handle, OS.TB_INSERTBUTTON, index, lpButton) == 0) {
- error (SWT.ERROR_ITEM_NOT_ADDED);
- }
- items [item.id = id] = item;
- if ((style & SWT.VERTICAL) != 0) setRowCount (count + 1);
- layoutItems ();
-}
-
-void createWidget () {
- super.createWidget ();
- items = new ToolItem [4];
- lastFocusId = lastArrowId = lastHotId = -1;
-}
-
-int defaultBackground () {
- if (OS.IsWinCE) return OS.GetSysColor (OS.COLOR_BTNFACE);
- return super.defaultBackground ();
-}
-
-void destroyItem (ToolItem item) {
- TBBUTTONINFO info = new TBBUTTONINFO ();
- info.cbSize = TBBUTTONINFO.sizeof;
- info.dwMask = OS.TBIF_IMAGE | OS.TBIF_STYLE;
- int index = (int)/*64*/OS.SendMessage (handle, OS.TB_GETBUTTONINFO, item.id, info);
- /*
- * Feature in Windows. For some reason, a tool item that has
- * the style BTNS_SEP does not return I_IMAGENONE when queried
- * for an image index, despite the fact that no attempt has been
- * made to assign an image to the item. As a result, operations
- * on an image list that use the wrong index cause random results.
- * The fix is to ensure that the tool item is not a separator
- * before using the image index. Since separators cannot have
- * an image and one is never assigned, this is not a problem.
- */
- if ((info.fsStyle & OS.BTNS_SEP) == 0 && info.iImage != OS.I_IMAGENONE) {
- if (imageList != null) imageList.put (info.iImage, null);
- if (hotImageList != null) hotImageList.put (info.iImage, null);
- if (disabledImageList != null) disabledImageList.put (info.iImage, null);
- }
- OS.SendMessage (handle, OS.TB_DELETEBUTTON, index, 0);
- if (item.id == lastFocusId) lastFocusId = -1;
- if (item.id == lastArrowId) lastArrowId = -1;
- if (item.id == lastHotId) lastHotId = -1;
- items [item.id] = null;
- item.id = -1;
- int count = (int)/*64*/OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);
- if (count == 0) {
- if (imageList != null) {
- OS.SendMessage (handle, OS.TB_SETIMAGELIST, 0, 0);
- display.releaseToolImageList (imageList);
- }
- if (hotImageList != null) {
- OS.SendMessage (handle, OS.TB_SETHOTIMAGELIST, 0, 0);
- display.releaseToolHotImageList (hotImageList);
- }
- if (disabledImageList != null) {
- OS.SendMessage (handle, OS.TB_SETDISABLEDIMAGELIST, 0, 0);
- display.releaseToolDisabledImageList (disabledImageList);
- }
- imageList = hotImageList = disabledImageList = null;
- items = new ToolItem [4];
- }
- if ((style & SWT.VERTICAL) != 0) setRowCount (count - 1);
- layoutItems ();
-}
-
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- /*
- * Bug in Windows. When a tool item with the style
- * BTNS_CHECK or BTNS_CHECKGROUP is selected and then
- * disabled, the item does not draw using the disabled
- * image. The fix is to use the disabled image in all
- * image lists for the item.
- *
- * Feature in Windows. When a tool bar is disabled,
- * the text draws disabled but the images do not.
- * The fix is to use the disabled image in all image
- * lists for all items.
- */
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null) {
- if ((item.style & SWT.SEPARATOR) == 0) {
- item.updateImages (enabled && item.getEnabled ());
- }
- }
- }
-}
-
-ImageList getDisabledImageList () {
- return disabledImageList;
-}
-
-ImageList getHotImageList () {
- return hotImageList;
-}
-
-ImageList getImageList () {
- return imageList;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem getItem (int index) {
- checkWidget ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);
- if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
- TBBUTTON lpButton = new TBBUTTON ();
- int /*long*/ result = OS.SendMessage (handle, OS.TB_GETBUTTON, index, lpButton);
- if (result == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- return items [lpButton.idCommand];
-}
-
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- *
- * @param point the point used to locate the item
- * @return the item at the given point
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem getItem (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- ToolItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- Rectangle rect = items [i].getBounds ();
- if (rect.contains (point)) return items [i];
- }
- return null;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);
-}
-
-/**
- * Returns an array of <code>ToolItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem [] getItems () {
- checkWidget ();
- return _getItems ();
-}
-
-ToolItem [] _getItems () {
- int count = (int)/*64*/OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);
- TBBUTTON lpButton = new TBBUTTON ();
- ToolItem [] result = new ToolItem [count];
- for (int i=0; i<count; i++) {
- OS.SendMessage (handle, OS.TB_GETBUTTON, i, lpButton);
- result [i] = items [lpButton.idCommand];
- }
- return result;
-}
-
-/**
- * Returns the number of rows in the receiver. When
- * the receiver has the <code>WRAP</code> style, the
- * number of rows can be greater than one. Otherwise,
- * the number of rows is always one.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getRowCount () {
- checkWidget ();
- if ((style & SWT.VERTICAL) != 0) {
- return (int)/*64*/OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);
- }
- return (int)/*64*/OS.SendMessage (handle, OS.TB_GETROWS, 0, 0);
-}
-
-ToolItem [] _getTabItemList () {
- if (tabItemList == null) return tabItemList;
- int count = 0;
- for (int i=0; i<tabItemList.length; i++) {
- if (!tabItemList [i].isDisposed ()) count++;
- }
- if (count == tabItemList.length) return tabItemList;
- ToolItem [] newList = new ToolItem [count];
- int index = 0;
- for (int i=0; i<tabItemList.length; i++) {
- if (!tabItemList [i].isDisposed ()) {
- newList [index++] = tabItemList [i];
- }
- }
- tabItemList = newList;
- return tabItemList;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the tool item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the tool item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (ToolItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- return (int)/*64*/OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, item.id, 0);
-}
-
-void layoutItems () {
- /*
- * Feature in Windows. When a tool bar has the style
- * TBSTYLE_LIST and has a drop down item, Window leaves
- * too much padding around the button. This affects
- * every button in the tool bar and makes the preferred
- * height too big. The fix is to set the TBSTYLE_LIST
- * when the tool bar contains both text and images.
- *
- * NOTE: Tool bars with CCS_VERT must have TBSTYLE_LIST
- * set before any item is added or the tool bar does
- * not lay out properly. The work around does not run
- * in this case.
- */
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- if ((style & SWT.RIGHT) != 0 && (style & SWT.VERTICAL) == 0) {
- boolean hasText = false, hasImage = false;
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null) {
- if (!hasText) hasText = item.text.length () != 0;
- if (!hasImage) hasImage = item.image != null;
- if (hasText && hasImage) break;
- }
- }
- int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE), newBits = oldBits;
- if (hasText && hasImage) {
- newBits |= OS.TBSTYLE_LIST;
- } else {
- newBits &= ~OS.TBSTYLE_LIST;
- }
- if (newBits != oldBits) {
- setDropDownItems (false);
- OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
- /*
- * Feature in Windows. For some reason, when the style
- * is changed to TBSTYLE_LIST, Windows does not lay out
- * the tool items. The fix is to use WM_SETFONT to force
- * the tool bar to redraw and lay out.
- */
- int /*long*/ hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);
- setDropDownItems (true);
- }
- }
- }
-
- if ((style & SWT.WRAP) != 0) {
- OS.SendMessage (handle, OS.TB_AUTOSIZE, 0, 0);
- }
- /*
- * When the tool bar is vertical, make the width of each button
- * be the width of the widest button in the tool bar. Note that
- * when the tool bar contains a drop down item, it needs to take
- * into account extra padding.
- */
- if ((style & SWT.VERTICAL) != 0) {
- int itemCount = (int)/*64*/OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);
- if (itemCount > 1) {
- TBBUTTONINFO info = new TBBUTTONINFO ();
- info.cbSize = TBBUTTONINFO.sizeof;
- info.dwMask = OS.TBIF_SIZE;
- int /*long*/ size = OS.SendMessage (handle, OS.TB_GETBUTTONSIZE, 0, 0);
- info.cx = (short) OS.LOWORD (size);
- int index = 0;
- while (index < items.length) {
- ToolItem item = items [index];
- if (item != null && (item.style & SWT.DROP_DOWN) != 0) break;
- index++;
- }
- if (index < items.length) {
- int /*long*/ padding = OS.SendMessage (handle, OS.TB_GETPADDING, 0, 0);
- info.cx += OS.LOWORD (padding) * 2;
- }
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null && (item.style & SWT.SEPARATOR) == 0) {
- OS.SendMessage (handle, OS.TB_SETBUTTONINFO, item.id, info);
- }
- }
- }
- }
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null) item.resizeControl ();
- }
-}
-
-boolean mnemonicHit (char ch) {
- int key = Display.wcsToMbcs (ch);
- int [] id = new int [1];
- if (OS.SendMessage (handle, OS.TB_MAPACCELERATOR, key, id) == 0) {
- return false;
- }
- if ((style & SWT.FLAT) != 0 && !setTabGroupFocus ()) return false;
- int index = (int)/*64*/OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, id [0], 0);
- if (index == -1) return false;
- OS.SendMessage (handle, OS.TB_SETHOTITEM, index, 0);
- items [id [0]].click (false);
- return true;
-}
-
-boolean mnemonicMatch (char ch) {
- int key = Display.wcsToMbcs (ch);
- int [] id = new int [1];
- if (OS.SendMessage (handle, OS.TB_MAPACCELERATOR, key, id) == 0) {
- return false;
- }
- /*
- * Feature in Windows. TB_MAPACCELERATOR matches either the mnemonic
- * character or the first character in a tool item. This behavior is
- * undocumented and unwanted. The fix is to ensure that the tool item
- * contains a mnemonic when TB_MAPACCELERATOR returns true.
- */
- int index = (int)/*64*/OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, id [0], 0);
- if (index == -1) return false;
- return findMnemonic (items [id [0]].text) != '\0';
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (imageList != null) {
- OS.SendMessage (handle, OS.TB_SETIMAGELIST, 0, 0);
- display.releaseToolImageList (imageList);
- }
- if (hotImageList != null) {
- OS.SendMessage (handle, OS.TB_SETHOTIMAGELIST, 0, 0);
- display.releaseToolHotImageList (hotImageList);
- }
- if (disabledImageList != null) {
- OS.SendMessage (handle, OS.TB_SETDISABLEDIMAGELIST, 0, 0);
- display.releaseToolDisabledImageList (disabledImageList);
- }
- imageList = hotImageList = disabledImageList = null;
-}
-
-void removeControl (Control control) {
- super.removeControl (control);
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null && item.control == control) {
- item.setControl (null);
- }
- }
-}
-
-void setBackgroundImage (int /*long*/ hBitmap) {
- super.setBackgroundImage (hBitmap);
- setBackgroundTransparent (hBitmap != 0);
-}
-
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- setBackgroundTransparent (pixel != -1);
-}
-
-void setBackgroundTransparent (boolean transparent) {
- /*
- * Feature in Windows. When TBSTYLE_TRANSPARENT is set
- * in a tool bar that is drawing a background, images in
- * the image list that include transparency information
- * do not draw correctly. The fix is to clear and set
- * TBSTYLE_TRANSPARENT depending on the background color.
- *
- * NOTE: This work around is unnecessary on XP. The
- * TBSTYLE_TRANSPARENT style is never cleared on that
- * platform.
- */
- if ((style & SWT.FLAT) != 0) {
- if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if (!transparent && findBackgroundControl () == null) {
- bits &= ~OS.TBSTYLE_TRANSPARENT;
- } else {
- bits |= OS.TBSTYLE_TRANSPARENT;
- }
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- }
- }
-}
-
-void setBounds (int x, int y, int width, int height, int flags) {
- /*
- * Feature in Windows. For some reason, when a tool bar is
- * repositioned more than once using DeferWindowPos () into
- * the same HDWP, the toolbar redraws more than once, defeating
- * the purpose of DeferWindowPos (). The fix is to end the
- * deferred positioning before the next tool bar is added,
- * ensuring that only one tool bar position is deferred at
- * any given time.
- */
- if (parent.lpwp != null) {
- if (getDrawing () && OS.IsWindowVisible (handle)) {
- parent.setResizeChildren (false);
- parent.setResizeChildren (true);
- }
- }
- super.setBounds (x, y, width, height, flags);
-}
-
-void setDefaultFont () {
- super.setDefaultFont ();
- OS.SendMessage (handle, OS.TB_SETBITMAPSIZE, 0, 0);
- OS.SendMessage (handle, OS.TB_SETBUTTONSIZE, 0, 0);
-}
-
-void setDropDownItems (boolean set) {
- /*
- * Feature in Windows. When the first button in a tool bar
- * is a drop down item, Window leaves too much padding around
- * the button. This affects every button in the tool bar and
- * makes the preferred height too big. The fix is clear the
- * BTNS_DROPDOWN before Windows lays out the tool bar and set
- * the bit afterwards.
- *
- * NOTE: This work around only runs when the tool bar contains
- * only images.
- */
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- boolean hasText = false, hasImage = false;
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null) {
- if (!hasText) hasText = item.text.length () != 0;
- if (!hasImage) hasImage = item.image != null;
- if (hasText && hasImage) break;
- }
- }
- if (hasImage && !hasText) {
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null && (item.style & SWT.DROP_DOWN) != 0) {
- TBBUTTONINFO info = new TBBUTTONINFO ();
- info.cbSize = TBBUTTONINFO.sizeof;
- info.dwMask = OS.TBIF_STYLE;
- OS.SendMessage (handle, OS.TB_GETBUTTONINFO, item.id, info);
- if (set) {
- info.fsStyle |= OS.BTNS_DROPDOWN;
- } else {
- info.fsStyle &= ~OS.BTNS_DROPDOWN;
- }
- OS.SendMessage (handle, OS.TB_SETBUTTONINFO, item.id, info);
- }
- }
- }
- }
-}
-
-void setDisabledImageList (ImageList imageList) {
- if (disabledImageList == imageList) return;
- int /*long*/ hImageList = 0;
- if ((disabledImageList = imageList) != null) {
- hImageList = disabledImageList.getHandle ();
- }
- setDropDownItems (false);
- OS.SendMessage (handle, OS.TB_SETDISABLEDIMAGELIST, 0, hImageList);
- setDropDownItems (true);
-}
-
-public void setFont (Font font) {
- checkWidget ();
- setDropDownItems (false);
- super.setFont (font);
- setDropDownItems (true);
- /*
- * Bug in Windows. When WM_SETFONT is sent to a tool bar
- * that contains only separators, causes the bitmap and button
- * sizes to be set. The fix is to reset these sizes after the font
- * has been changed when the tool bar contains only separators.
- */
- int index = 0;
- int mask = SWT.PUSH | SWT.CHECK | SWT.RADIO | SWT.DROP_DOWN;
- while (index < items.length) {
- ToolItem item = items [index];
- if (item != null && (item.style & mask) != 0) break;
- index++;
- }
- if (index == items.length) {
- OS.SendMessage (handle, OS.TB_SETBITMAPSIZE, 0, 0);
- OS.SendMessage (handle, OS.TB_SETBUTTONSIZE, 0, 0);
- }
- layoutItems ();
-}
-
-void setHotImageList (ImageList imageList) {
- if (hotImageList == imageList) return;
- int /*long*/ hImageList = 0;
- if ((hotImageList = imageList) != null) {
- hImageList = hotImageList.getHandle ();
- }
- setDropDownItems (false);
- OS.SendMessage (handle, OS.TB_SETHOTIMAGELIST, 0, hImageList);
- setDropDownItems (true);
-}
-
-void setImageList (ImageList imageList) {
- if (this.imageList == imageList) return;
- int /*long*/ hImageList = 0;
- if ((this.imageList = imageList) != null) {
- hImageList = imageList.getHandle ();
- }
- setDropDownItems (false);
- OS.SendMessage (handle, OS.TB_SETIMAGELIST, 0, hImageList);
- setDropDownItems (true);
-}
-
-public boolean setParent (Composite parent) {
- checkWidget ();
- if (!super.setParent (parent)) return false;
- int /*long*/ hwndParent = parent.handle;
- OS.SendMessage (handle, OS.TB_SETPARENT, hwndParent, 0);
- /*
- * Bug in Windows. When a tool bar is reparented, the tooltip
- * control that is automatically created for the item is not
- * reparented to the new shell. The fix is to move the tooltip
- * over using SetWindowLongPtr(). Note that for some reason,
- * SetParent() does not work.
- */
- int /*long*/ hwndShell = parent.getShell ().handle;
- int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.TB_GETTOOLTIPS, 0, 0);
- OS.SetWindowLongPtr (hwndToolTip, OS.GWLP_HWNDPARENT, hwndShell);
- return true;
-}
-
-public void setRedraw (boolean redraw) {
- checkWidget ();
- setDropDownItems (false);
- super.setRedraw (redraw);
- setDropDownItems (true);
-}
-
-void setRowCount (int count) {
- if ((style & SWT.VERTICAL) != 0) {
- /*
- * Feature in Windows. When the TB_SETROWS is used to set the
- * number of rows in a tool bar, the tool bar is resized to show
- * the items. This is unexpected. The fix is to save and restore
- * the current size of the tool bar.
- */
- RECT rect = new RECT ();
- OS.GetWindowRect (handle, rect);
- OS.MapWindowPoints (0, parent.handle, rect, 2);
- ignoreResize = true;
- /*
- * Feature in Windows. When the last button in a tool bar has the
- * style BTNS_SEP and TB_SETROWS is used to set the number of rows
- * in the tool bar, depending on the number of buttons, the toolbar
- * will wrap items with the style BTNS_CHECK, even when the fLarger
- * flags is used to force the number of rows to be larger than the
- * number of items. The fix is to set the number of rows to be two
- * larger than the actual number of rows in the tool bar. When items
- * are being added, as long as the number of rows is at least one
- * item larger than the count, the tool bar is laid out properly.
- * When items are being removed, setting the number of rows to be
- * one more than the item count has no effect. The number of rows
- * is already one more causing TB_SETROWS to do nothing. Therefore,
- * choosing two instead of one as the row increment fixes both cases.
- */
- count += 2;
- OS.SendMessage (handle, OS.TB_SETROWS, OS.MAKEWPARAM (count, 1), 0);
- int flags = OS.SWP_NOACTIVATE | OS.SWP_NOMOVE | OS.SWP_NOZORDER;
- SetWindowPos (handle, 0, 0, 0, rect.right - rect.left, rect.bottom - rect.top, flags);
- ignoreResize = false;
- }
-}
-
-/*public*/ void setTabItemList (ToolItem [] tabList) {
- checkWidget ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- ToolItem item = tabList [i];
- if (item == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (item.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
- ToolItem [] newList = new ToolItem [tabList.length];
- System.arraycopy (tabList, 0, newList, 0, tabList.length);
- tabList = newList;
- }
- this.tabItemList = tabList;
-}
-
-boolean setTabItemFocus () {
- int index = 0;
- while (index < items.length) {
- ToolItem item = items [index];
- if (item != null && (item.style & SWT.SEPARATOR) == 0) {
- if (item.getEnabled ()) break;
- }
- index++;
- }
- if (index == items.length) return false;
- return super.setTabItemFocus ();
-}
-
-String toolTipText (NMTTDISPINFO hdr) {
- if ((hdr.uFlags & OS.TTF_IDISHWND) != 0) {
- return null;
- }
- /*
- * Bug in Windows. On Windows XP, when TB_SETHOTITEM is
- * used to set the hot item, the tool bar control attempts
- * to display the tool tip, even when the cursor is not in
- * the hot item. The fix is to detect this case and fail to
- * provide the string, causing no tool tip to be displayed.
- */
- if (!hasCursor ()) return ""; //$NON-NLS-1$
- int index = (int)/*64*/hdr.idFrom;
- int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.TB_GETTOOLTIPS, 0, 0);
- if (hwndToolTip == hdr.hwndFrom) {
- /*
- * Bug in Windows. For some reason the reading order
- * in NMTTDISPINFO is sometimes set incorrectly. The
- * reading order seems to change every time the mouse
- * enters the control from the top edge. The fix is
- * to explicitly set TTF_RTLREADING.
- */
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- hdr.uFlags |= OS.TTF_RTLREADING;
- } else {
- hdr.uFlags &= ~OS.TTF_RTLREADING;
- }
- if (toolTipText != null) return ""; //$NON-NLS-1$
- if (0 <= index && index < items.length) {
- ToolItem item = items [index];
- if (item != null) {
- /*
- * But in Windows. When the arrow keys are used to change
- * the hot item, for some reason, Windows displays the tool
- * tip for the hot item in at (0, 0) on the screen rather
- * than next to the current hot item. This fix is to disallow
- * tool tips while the user is traversing with the arrow keys.
- */
- if (lastArrowId != -1) return "";
- return item.toolTipText;
- }
- }
- }
- return super.toolTipText (hdr);
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle () | OS.CCS_NORESIZE | OS.TBSTYLE_TOOLTIPS | OS.TBSTYLE_CUSTOMERASE;
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) bits |= OS.TBSTYLE_TRANSPARENT;
- if ((style & SWT.SHADOW_OUT) == 0) bits |= OS.CCS_NODIVIDER;
- if ((style & SWT.WRAP) != 0) bits |= OS.TBSTYLE_WRAPABLE;
- if ((style & SWT.FLAT) != 0) bits |= OS.TBSTYLE_FLAT;
- /*
- * Feature in Windows. When a tool bar has the style
- * TBSTYLE_LIST and has a drop down item, Window leaves
- * too much padding around the button. This affects
- * every button in the tool bar and makes the preferred
- * height too big. The fix is to set the TBSTYLE_LIST
- * when the tool bar contains both text and images.
- *
- * NOTE: Tool bars with CCS_VERT must have TBSTYLE_LIST
- * set before any item is added or the tool bar does
- * not lay out properly. The work around does not run
- * in this case.
- */
- if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
- if ((style & SWT.RIGHT) != 0) bits |= OS.TBSTYLE_LIST;
- }
- return bits;
-}
-
-TCHAR windowClass () {
- return ToolBarClass;
-}
-
-int /*long*/ windowProc () {
- return ToolBarProc;
-}
-
-LRESULT WM_CAPTURECHANGED (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_CAPTURECHANGED (wParam, lParam);
- if (result != null) return result;
- /*
- * Bug in Windows. When the tool bar loses capture while an
- * item is pressed, the item remains pressed. The fix is
- * unpress all items using TB_SETSTATE and TBSTATE_PRESSED.
- */
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null) {
- int fsState = (int)/*64*/OS.SendMessage (handle, OS.TB_GETSTATE, item.id, 0);
- if ((fsState & OS.TBSTATE_PRESSED) != 0) {
- fsState &= ~OS.TBSTATE_PRESSED;
- OS.SendMessage (handle, OS.TB_SETSTATE, item.id, fsState);
- }
- }
- }
- return result;
-}
-
-LRESULT WM_CHAR (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_CHAR (wParam, lParam);
- if (result != null) return result;
- switch ((int)/*64*/wParam) {
- case ' ':
- int index = (int)/*64*/OS.SendMessage (handle, OS.TB_GETHOTITEM, 0, 0);
- if (index != -1) {
- TBBUTTON lpButton = new TBBUTTON ();
- int /*long*/ code = OS.SendMessage (handle, OS.TB_GETBUTTON, index, lpButton);
- if (code != 0) {
- items [lpButton.idCommand].click (false);
- return LRESULT.ZERO;
- }
- }
- }
- return result;
-}
-
-LRESULT WM_COMMAND (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. When the toolbar window
- * proc processes WM_COMMAND, it forwards this
- * message to its parent. This is done so that
- * children of this control that send this message
- * type to their parent will notify not only
- * this control but also the parent of this control,
- * which is typically the application window and
- * the window that is looking for the message.
- * If the control did not forward the message,
- * applications would have to subclass the control
- * window to see the message. Because the control
- * window is subclassed by SWT, the message
- * is delivered twice, once by SWT and once when
- * the message is forwarded by the window proc.
- * The fix is to avoid calling the window proc
- * for this control.
- */
- LRESULT result = super.WM_COMMAND (wParam, lParam);
- if (result != null) return result;
- return LRESULT.ZERO;
-}
-
-LRESULT WM_ERASEBKGND (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
- /*
- * Bug in Windows. For some reason, NM_CUSTOMDRAW with
- * CDDS_PREERASE and CDDS_POSTERASE is never sent for
- * versions of Windows earlier than XP. The fix is to
- * draw the background in WM_ERASEBKGND;
- */
- if (findBackgroundControl () != null) {
- if (OS.COMCTL32_MAJOR < 6) {
- drawBackground (wParam);
- return LRESULT.ONE;
- }
- }
- return result;
-}
-
-LRESULT WM_GETDLGCODE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_GETDLGCODE (wParam, lParam);
- /*
- * Return DLGC_BUTTON so that mnemonics will be
- * processed without needing to press the ALT key
- * when the widget has focus.
- */
- if (result != null) return result;
- return new LRESULT (OS.DLGC_BUTTON | OS.DLGC_WANTARROWS);
-}
-
-LRESULT WM_KEYDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_KEYDOWN (wParam, lParam);
- if (result != null) return result;
- switch ((int)/*64*/wParam) {
- case OS.VK_SPACE:
- /*
- * Ensure that the window proc does not process VK_SPACE
- * so that it can be handled in WM_CHAR. This allows the
- * application the opportunity to cancel the operation.
- */
- return LRESULT.ZERO;
- }
- return result;
-}
-
-LRESULT WM_KILLFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- int index = (int)/*64*/OS.SendMessage (handle, OS.TB_GETHOTITEM, 0, 0);
- TBBUTTON lpButton = new TBBUTTON ();
- int /*long*/ code = OS.SendMessage (handle, OS.TB_GETBUTTON, index, lpButton);
- if (code != 0) lastFocusId = lpButton.idCommand;
- return super.WM_KILLFOCUS (wParam, lParam);
-}
-
-LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- if (ignoreMouse) return null;
- return super.WM_LBUTTONDOWN (wParam, lParam);
-}
-
-LRESULT WM_LBUTTONUP (int /*long*/ wParam, int /*long*/ lParam) {
- if (ignoreMouse) return null;
- return super.WM_LBUTTONUP (wParam, lParam);
-}
-
-LRESULT WM_MOUSELEAVE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_MOUSELEAVE (wParam, lParam);
- if (result != null) return result;
- /*
- * Bug in Windows. On XP, when a tooltip is
- * hidden due to a time out or mouse press,
- * the tooltip remains active although no
- * longer visible and won't show again until
- * another tooltip becomes active. If there
- * is only one tooltip in the window, it will
- * never show again. The fix is to remove the
- * current tooltip and add it again every time
- * the mouse leaves the control.
- */
- if (OS.COMCTL32_MAJOR >= 6) {
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.TB_GETTOOLTIPS, 0, 0);
- if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, lpti) != 0) {
- if ((lpti.uFlags & OS.TTF_IDISHWND) == 0) {
- OS.SendMessage (hwndToolTip, OS.TTM_DELTOOL, 0, lpti);
- OS.SendMessage (hwndToolTip, OS.TTM_ADDTOOL, 0, lpti);
- }
- }
- }
- return result;
-}
-
-LRESULT WM_MOUSEMOVE (int /*long*/ wParam, int /*long*/ lParam) {
- if (OS.GetMessagePos () != display.lastMouse) lastArrowId = -1;
- return super.WM_MOUSEMOVE (wParam, lParam);
-}
-
-LRESULT WM_NOTIFY (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. When the toolbar window
- * proc processes WM_NOTIFY, it forwards this
- * message to its parent. This is done so that
- * children of this control that send this message
- * type to their parent will notify not only
- * this control but also the parent of this control,
- * which is typically the application window and
- * the window that is looking for the message.
- * If the control did not forward the message,
- * applications would have to subclass the control
- * window to see the message. Because the control
- * window is subclassed by SWT, the message
- * is delivered twice, once by SWT and once when
- * the message is forwarded by the window proc.
- * The fix is to avoid calling the window proc
- * for this control.
- */
- LRESULT result = super.WM_NOTIFY (wParam, lParam);
- if (result != null) return result;
- return LRESULT.ZERO;
-}
-
-LRESULT WM_SETFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SETFOCUS (wParam, lParam);
- if (lastFocusId != -1 && handle == OS.GetFocus ()) {
- int index = (int)/*64*/OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, lastFocusId, 0);
- OS.SendMessage (handle, OS.TB_SETHOTITEM, index, 0);
- }
- return result;
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- if (ignoreResize) {
- int /*long*/ code = callWindowProc (handle, OS.WM_SIZE, wParam, lParam);
- if (code == 0) return LRESULT.ZERO;
- return new LRESULT (code);
- }
- LRESULT result = super.WM_SIZE (wParam, lParam);
- if (isDisposed ()) return result;
- /*
- * Bug in Windows. The code in Windows that determines
- * when tool items should wrap seems to use the window
- * bounds rather than the client area. Unfortunately,
- * tool bars with the style TBSTYLE_EX_HIDECLIPPEDBUTTONS
- * use the client area. This means that buttons which
- * overlap the border are hidden before they are wrapped.
- * The fix is to compute TBSTYLE_EX_HIDECLIPPEDBUTTONS
- * and set it each time the tool bar is resized.
- */
- if ((style & SWT.BORDER) != 0 && (style & SWT.WRAP) != 0) {
- RECT windowRect = new RECT ();
- OS.GetWindowRect (handle, windowRect);
- int index = 0, border = getBorderWidth () * 2;
- RECT rect = new RECT ();
- int count = (int)/*64*/OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);
- while (index < count) {
- OS.SendMessage (handle, OS.TB_GETITEMRECT, index, rect);
- OS.MapWindowPoints (handle, 0, rect, 2);
- if (rect.right > windowRect.right - border * 2) break;
- index++;
- }
- int bits = (int)/*64*/OS.SendMessage (handle, OS.TB_GETEXTENDEDSTYLE, 0, 0);
- if (index == count) {
- bits |= OS.TBSTYLE_EX_HIDECLIPPEDBUTTONS;
- } else {
- bits &= ~OS.TBSTYLE_EX_HIDECLIPPEDBUTTONS;
- }
- OS.SendMessage (handle, OS.TB_SETEXTENDEDSTYLE, 0, bits);
- }
- layoutItems ();
- return result;
-}
-
-LRESULT WM_WINDOWPOSCHANGING (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_WINDOWPOSCHANGING (wParam, lParam);
- if (result != null) return result;
- if (ignoreResize) return result;
- /*
- * Bug in Windows. When a flat tool bar is wrapped,
- * Windows draws a horizontal separator between the
- * rows. The tool bar does not draw the first or
- * the last two pixels of this separator. When the
- * toolbar is resized to be bigger, only the new
- * area is drawn and the last two pixels, which are
- * blank are drawn over by separator. This leaves
- * garbage on the screen. The fix is to damage the
- * pixels.
- */
- if (!getDrawing ()) return result;
- if ((style & SWT.WRAP) == 0) return result;
- if (!OS.IsWindowVisible (handle)) return result;
- if (OS.SendMessage (handle, OS.TB_GETROWS, 0, 0) == 1) {
- return result;
- }
- WINDOWPOS lpwp = new WINDOWPOS ();
- OS.MoveMemory (lpwp, lParam, WINDOWPOS.sizeof);
- if ((lpwp.flags & (OS.SWP_NOSIZE | OS.SWP_NOREDRAW)) != 0) {
- return result;
- }
- RECT oldRect = new RECT ();
- OS.GetClientRect (handle, oldRect);
- RECT newRect = new RECT ();
- OS.SetRect (newRect, 0, 0, lpwp.cx, lpwp.cy);
- OS.SendMessage (handle, OS.WM_NCCALCSIZE, 0, newRect);
- int oldWidth = oldRect.right - oldRect.left;
- int newWidth = newRect.right - newRect.left;
- if (newWidth > oldWidth) {
- RECT rect = new RECT ();
- int newHeight = newRect.bottom - newRect.top;
- OS.SetRect (rect, oldWidth - 2, 0, oldWidth, newHeight);
- OS.InvalidateRect (handle, rect, false);
- }
- return result;
-}
-
-LRESULT wmCommandChild (int /*long*/ wParam, int /*long*/ lParam) {
- ToolItem child = items [OS.LOWORD (wParam)];
- if (child == null) return null;
- return child.wmCommandChild (wParam, lParam);
-}
-
-LRESULT wmNotifyChild (NMHDR hdr, int /*long*/ wParam, int /*long*/ lParam) {
- switch (hdr.code) {
- case OS.TBN_DROPDOWN:
- NMTOOLBAR lpnmtb = new NMTOOLBAR ();
- OS.MoveMemory (lpnmtb, lParam, NMTOOLBAR.sizeof);
- ToolItem child = items [lpnmtb.iItem];
- if (child != null) {
- Event event = new Event ();
- event.detail = SWT.ARROW;
- int index = (int)/*64*/OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, lpnmtb.iItem, 0);
- RECT rect = new RECT ();
- OS.SendMessage (handle, OS.TB_GETITEMRECT, index, rect);
- event.x = rect.left;
- event.y = rect.bottom;
- child.postEvent (SWT.Selection, event);
- }
- break;
- case OS.NM_CUSTOMDRAW:
- if (OS.COMCTL32_MAJOR < 6) break;
- /*
- * Bug in Windows. For some reason, under the XP Silver
- * theme, tool bars continue to draw using the gray color
- * from the default Blue theme. The fix is to draw the
- * background.
- */
- NMCUSTOMDRAW nmcd = new NMCUSTOMDRAW ();
- OS.MoveMemory (nmcd, lParam, NMCUSTOMDRAW.sizeof);
-// if (drawCount != 0 || !OS.IsWindowVisible (handle)) {
-// if (!OS.IsWinCE && OS.WindowFromDC (nmcd.hdc) == handle) break;
-// }
- switch (nmcd.dwDrawStage) {
- case OS.CDDS_PREERASE: {
- /*
- * Bug in Windows. When a tool bar does not have the style
- * TBSTYLE_FLAT, the rectangle to be erased in CDDS_PREERASE
- * is empty. The fix is to draw the whole client area.
- */
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.TBSTYLE_FLAT) == 0) {
- drawBackground (nmcd.hdc);
- } else {
- RECT rect = new RECT ();
- OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
- drawBackground (nmcd.hdc, rect);
- }
- return new LRESULT (OS.CDRF_SKIPDEFAULT);
- }
- }
- break;
- case OS.TBN_HOTITEMCHANGE:
- if (!OS.IsWinCE) {
- NMTBHOTITEM lpnmhi = new NMTBHOTITEM ();
- OS.MoveMemory (lpnmhi, lParam, NMTBHOTITEM.sizeof);
- switch (lpnmhi.dwFlags) {
- case OS.HICF_MOUSE: {
- /*
- * But in Windows. When the tool bar has focus, a mouse is
- * in an item and hover help for that item is displayed and
- * then the arrow keys are used to change the hot item,
- * for some reason, Windows snaps the hot item back to the
- * one that is under the mouse. The fix is to disallow
- * hot item changes when the user is traversing using the
- * arrow keys.
- */
- if (lastArrowId != -1) return LRESULT.ONE;
- break;
- }
- case OS.HICF_ARROWKEYS: {
- RECT client = new RECT ();
- OS.GetClientRect (handle, client);
- int index = (int)/*64*/OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, lpnmhi.idNew, 0);
- RECT rect = new RECT ();
- OS.SendMessage (handle, OS.TB_GETITEMRECT, index, rect);
- if (rect.right > client.right || rect.bottom > client.bottom) {
- return LRESULT.ONE;
- }
- lastArrowId = lpnmhi.idNew;
- break;
- }
- default:
- lastArrowId = -1;
- }
- if ((lpnmhi.dwFlags & OS.HICF_LEAVING) == 0) {
- lastHotId = lpnmhi.idNew;
- }
- }
- break;
- }
- return super.wmNotifyChild (hdr, wParam, lParam);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java
deleted file mode 100755
index 27386a4545..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java
+++ /dev/null
@@ -1,1006 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a button in a tool bar.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>PUSH, CHECK, RADIO, SEPARATOR, DROP_DOWN</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles CHECK, PUSH, RADIO, SEPARATOR and DROP_DOWN
- * may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#toolbar">ToolBar, ToolItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolItem extends Item {
- ToolBar parent;
- Control control;
- String toolTipText;
- Image disabledImage, hotImage;
- Image disabledImage2;
- int id;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>ToolBar</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#PUSH
- * @see SWT#CHECK
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ToolItem (ToolBar parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>ToolBar</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#PUSH
- * @see SWT#CHECK
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ToolItem (ToolBar parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called when the mouse is over the arrow portion of a drop-down tool,
- * the event object detail field contains the value <code>SWT.ARROW</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user,
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.DROP_DOWN, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void click (boolean dropDown) {
- int /*long*/ hwnd = parent.handle;
- if (OS.GetKeyState (OS.VK_LBUTTON) < 0) return;
- int index = (int)/*64*/OS.SendMessage (hwnd, OS.TB_COMMANDTOINDEX, id, 0);
- RECT rect = new RECT ();
- OS.SendMessage (hwnd, OS.TB_GETITEMRECT, index, rect);
- int hotIndex = (int)/*64*/OS.SendMessage (hwnd, OS.TB_GETHOTITEM, 0, 0);
-
- /*
- * In order to emulate all the processing that
- * happens when a mnemonic key is pressed, fake
- * a mouse press and release. This will ensure
- * that radio and pull down items are handled
- * properly.
- */
- int y = rect.top + (rect.bottom - rect.top) / 2;
- int /*long*/ lParam = OS.MAKELPARAM (dropDown ? rect.right - 1 : rect.left, y);
- parent.ignoreMouse = true;
- OS.SendMessage (hwnd, OS.WM_LBUTTONDOWN, 0, lParam);
- OS.SendMessage (hwnd, OS.WM_LBUTTONUP, 0, lParam);
- parent.ignoreMouse = false;
-
- if (hotIndex != -1) {
- OS.SendMessage (hwnd, OS.TB_SETHOTITEM, hotIndex, 0);
- }
-}
-
-Widget [] computeTabList () {
- if (isTabGroup ()) {
- if (getEnabled ()) {
- if ((style & SWT.SEPARATOR) != 0) {
- if (control != null) return control.computeTabList();
- } else {
- return new Widget [] {this};
- }
- }
- }
- return new Widget [0];
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- int /*long*/ hwnd = parent.handle;
- int index = (int)/*64*/OS.SendMessage (hwnd, OS.TB_COMMANDTOINDEX, id, 0);
- RECT rect = new RECT ();
- OS.SendMessage (hwnd, OS.TB_GETITEMRECT, index, rect);
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- return new Rectangle (rect.left, rect.top, width, height);
-}
-
-/**
- * Returns the control that is used to fill the bounds of
- * the item when the item is a <code>SEPARATOR</code>.
- *
- * @return the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget();
- return control;
-}
-
-/**
- * Returns the receiver's disabled image if it has one, or null
- * if it does not.
- * <p>
- * The disabled image is displayed when the receiver is disabled.
- * </p>
- *
- * @return the receiver's disabled image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getDisabledImage () {
- checkWidget();
- return disabledImage;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) {
- return (state & DISABLED) == 0;
- }
- int /*long*/ hwnd = parent.handle;
- int /*long*/ fsState = OS.SendMessage (hwnd, OS.TB_GETSTATE, id, 0);
- return (fsState & OS.TBSTATE_ENABLED) != 0;
-}
-
-/**
- * Returns the receiver's hot image if it has one, or null
- * if it does not.
- * <p>
- * The hot image is displayed when the mouse enters the receiver.
- * </p>
- *
- * @return the receiver's hot image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getHotImage () {
- checkWidget();
- return hotImage;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>ToolBar</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolBar getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked (which some platforms draw as a
- * pushed in button). If the receiver is of any other type, this method
- * returns false.
- * </p>
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
- int /*long*/ hwnd = parent.handle;
- int /*long*/ fsState = OS.SendMessage (hwnd, OS.TB_GETSTATE, id, 0);
- return (fsState & OS.TBSTATE_CHECKED) != 0;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget();
- int /*long*/ hwnd = parent.handle;
- int index = (int)/*64*/OS.SendMessage (hwnd, OS.TB_COMMANDTOINDEX, id, 0);
- RECT rect = new RECT ();
- OS.SendMessage (hwnd, OS.TB_GETITEMRECT, index, rect);
- return rect.right - rect.left;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-
-boolean isTabGroup () {
- ToolItem [] tabList = parent._getTabItemList ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == this) return true;
- }
- }
- if ((style & SWT.SEPARATOR) != 0) return true;
- int index = parent.indexOf (this);
- if (index == 0) return true;
- ToolItem previous = parent.getItem (index - 1);
- return (previous.getStyle () & SWT.SEPARATOR) != 0;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- releaseImages ();
- control = null;
- toolTipText = null;
- disabledImage = hotImage = null;
- if (disabledImage2 != null) disabledImage2.dispose ();
- disabledImage2 = null;
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
- id = -1;
-}
-
-void releaseImages () {
- TBBUTTONINFO info = new TBBUTTONINFO ();
- info.cbSize = TBBUTTONINFO.sizeof;
- info.dwMask = OS.TBIF_IMAGE | OS.TBIF_STYLE;
- int /*long*/ hwnd = parent.handle;
- OS.SendMessage (hwnd, OS.TB_GETBUTTONINFO, id, info);
- /*
- * Feature in Windows. For some reason, a tool item that has
- * the style BTNS_SEP does not return I_IMAGENONE when queried
- * for an image index, despite the fact that no attempt has been
- * made to assign an image to the item. As a result, operations
- * on an image list that use the wrong index cause random results.
- * The fix is to ensure that the tool item is not a separator
- * before using the image index. Since separators cannot have
- * an image and one is never assigned, this is not a problem.
- */
- if ((info.fsStyle & OS.BTNS_SEP) == 0 && info.iImage != OS.I_IMAGENONE) {
- ImageList imageList = parent.getImageList ();
- ImageList hotImageList = parent.getHotImageList ();
- ImageList disabledImageList = parent.getDisabledImageList();
- if (imageList != null) imageList.put (info.iImage, null);
- if (hotImageList != null) hotImageList.put (info.iImage, null);
- if (disabledImageList != null) disabledImageList.put (info.iImage, null);
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-void resizeControl () {
- if (control != null && !control.isDisposed ()) {
- /*
- * Set the size and location of the control
- * separately to minimize flashing in the
- * case where the control does not resize
- * to the size that was requested. This
- * case can occur when the control is a
- * combo box.
- */
- Rectangle itemRect = getBounds ();
- control.setSize (itemRect.width, itemRect.height);
- Rectangle rect = control.getBounds ();
- rect.x = itemRect.x + (itemRect.width - rect.width) / 2;
- rect.y = itemRect.y + (itemRect.height - rect.height) / 2;
- control.setLocation (rect.x, rect.y);
- }
-}
-
-void selectRadio () {
- int index = 0;
- ToolItem [] items = parent.getItems ();
- while (index < items.length && items [index] != this) index++;
- int i = index - 1;
- while (i >= 0 && items [i].setRadioSelection (false)) --i;
- int j = index + 1;
- while (j < items.length && items [j].setRadioSelection (false)) j++;
- setSelection (true);
-}
-
-/**
- * Sets the control that is used to fill the bounds of
- * the item when the item is a <code>SEPARATOR</code>.
- *
- * @param control the new control
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- if ((style & SWT.SEPARATOR) == 0) return;
- this.control = control;
- /*
- * Feature in Windows. When a tool bar wraps, tool items
- * with the style BTNS_SEP are used as wrap points. This
- * means that controls that are placed on top of separator
- * items are not positioned properly. Also, vertical tool
- * bars are implemented using TB_SETROWS to set the number
- * of rows. When a control is placed on top of a separator,
- * the height of the separator does not grow. The fix in
- * both cases is to change the tool item style from BTNS_SEP
- * to BTNS_BUTTON, causing the item to wrap like a tool item
- * button. The new tool item button is disabled to avoid key
- * traversal and the image is set to I_IMAGENONE to avoid
- * getting the first image from the image list.
- */
- if ((parent.style & (SWT.WRAP | SWT.VERTICAL)) != 0) {
- boolean changed = false;
- int /*long*/ hwnd = parent.handle;
- TBBUTTONINFO info = new TBBUTTONINFO ();
- info.cbSize = TBBUTTONINFO.sizeof;
- info.dwMask = OS.TBIF_STYLE | OS.TBIF_STATE;
- OS.SendMessage (hwnd, OS.TB_GETBUTTONINFO, id, info);
- if (control == null) {
- if ((info.fsStyle & OS.BTNS_SEP) == 0) {
- changed = true;
- info.fsStyle &= ~(OS.BTNS_BUTTON | OS.BTNS_SHOWTEXT);
- info.fsStyle |= OS.BTNS_SEP;
- if ((state & DISABLED) != 0) {
- info.fsState &= ~OS.TBSTATE_ENABLED;
- } else {
- info.fsState |= OS.TBSTATE_ENABLED;
- }
- }
- } else {
- if ((info.fsStyle & OS.BTNS_SEP) != 0) {
- changed = true;
- info.fsStyle &= ~OS.BTNS_SEP;
- info.fsStyle |= OS.BTNS_BUTTON | OS.BTNS_SHOWTEXT;
- info.fsState &= ~OS.TBSTATE_ENABLED;
- info.dwMask |= OS.TBIF_IMAGE;
- info.iImage = OS.I_IMAGENONE;
- }
- }
- if (changed) {
- OS.SendMessage (hwnd, OS.TB_SETBUTTONINFO, id, info);
- /*
- * Bug in Windows. When TB_SETBUTTONINFO changes the
- * style of a tool item from BTNS_SEP to BTNS_BUTTON
- * and the tool bar is wrapped, the tool bar does not
- * redraw properly. Windows uses separator items as
- * wrap points and sometimes draws etching above or
- * below and entire row. The fix is to redraw the
- * tool bar.
- */
- if (OS.SendMessage (hwnd, OS.TB_GETROWS, 0, 0) > 1) {
- OS.InvalidateRect (hwnd, null, true);
- }
- }
- }
- resizeControl ();
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise.
- * <p>
- * A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- * </p>
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- int /*long*/ hwnd = parent.handle;
- int fsState = (int)/*64*/OS.SendMessage (hwnd, OS.TB_GETSTATE, id, 0);
- /*
- * Feature in Windows. When TB_SETSTATE is used to set the
- * state of a tool item, the item redraws even when the state
- * has not changed. The fix is to detect this case and avoid
- * setting the state.
- */
- if (((fsState & OS.TBSTATE_ENABLED) != 0) == enabled) return;
- if (enabled) {
- fsState |= OS.TBSTATE_ENABLED;
- state &= ~DISABLED;
- } else {
- fsState &= ~OS.TBSTATE_ENABLED;
- state |= DISABLED;
- }
- OS.SendMessage (hwnd, OS.TB_SETSTATE, id, fsState);
- if ((style & SWT.SEPARATOR) == 0) {
- if (image != null) updateImages (enabled && parent.getEnabled ());
- }
-}
-
-/**
- * Sets the receiver's disabled image to the argument, which may be
- * null indicating that no disabled image should be displayed.
- * <p>
- * The disabled image is displayed when the receiver is disabled.
- * </p>
- *
- * @param image the disabled image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDisabledImage (Image image) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return;
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- disabledImage = image;
- updateImages (getEnabled () && parent.getEnabled ());
-}
-
-/**
- * Sets the receiver's hot image to the argument, which may be
- * null indicating that no hot image should be displayed.
- * <p>
- * The hot image is displayed when the mouse enters the receiver.
- * </p>
- *
- * @param image the hot image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHotImage (Image image) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return;
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- hotImage = image;
- updateImages (getEnabled () && parent.getEnabled ());
-}
-
-public void setImage (Image image) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return;
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- super.setImage (image);
- updateImages (getEnabled () && parent.getEnabled ());
-}
-
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-
-/**
- * Sets the selection state of the receiver.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked (which some platforms draw as a
- * pushed in button).
- * </p>
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
- int /*long*/ hwnd = parent.handle;
- int fsState = (int)/*64*/OS.SendMessage (hwnd, OS.TB_GETSTATE, id, 0);
- /*
- * Feature in Windows. When TB_SETSTATE is used to set the
- * state of a tool item, the item redraws even when the state
- * has not changed. The fix is to detect this case and avoid
- * setting the state.
- */
- if (((fsState & OS.TBSTATE_CHECKED) != 0) == selected) return;
- if (selected) {
- fsState |= OS.TBSTATE_CHECKED;
- } else {
- fsState &= ~OS.TBSTATE_CHECKED;
- }
- OS.SendMessage (hwnd, OS.TB_SETSTATE, id, fsState);
-
- /*
- * Bug in Windows. When a tool item with the style
- * BTNS_CHECK or BTNS_CHECKGROUP is selected and then
- * disabled, the item does not draw using the disabled
- * image. The fix is to use the disabled image in all
- * image lists for the item.
- *
- * NOTE: This means that the image list must be updated
- * when the selection changes in a disabled tool item.
- */
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- if (!getEnabled () || !parent.getEnabled ()) {
- updateImages (false);
- }
- }
-}
-
-boolean setTabItemFocus () {
- if (parent.setTabItemFocus ()) {
- int /*long*/ hwnd = parent.handle;
- int index = (int)/*64*/OS.SendMessage (hwnd, OS.TB_COMMANDTOINDEX, id, 0);
- OS.SendMessage (hwnd, OS.TB_SETHOTITEM, index, 0);
- return true;
- }
- return false;
-}
-
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- if (string.equals (text)) return;
- super.setText (string);
- int /*long*/ hwnd = parent.handle;
- TBBUTTONINFO info = new TBBUTTONINFO ();
- info.cbSize = TBBUTTONINFO.sizeof;
- info.dwMask = OS.TBIF_TEXT | OS.TBIF_STYLE;
- info.fsStyle = (byte) (widgetStyle () | OS.BTNS_AUTOSIZE);
- int /*long*/ hHeap = OS.GetProcessHeap (), pszText = 0;
- if (string.length () != 0) {
- info.fsStyle |= OS.BTNS_SHOWTEXT;
- TCHAR buffer = new TCHAR (parent.getCodePage (), string, true);
- int byteCount = buffer.length () * TCHAR.sizeof;
- pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (pszText, buffer, byteCount);
- info.pszText = pszText;
- }
- OS.SendMessage (hwnd, OS.TB_SETBUTTONINFO, id, info);
- if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
-
- /*
- * Bug in Windows. For some reason, when the font is set
- * before any tool item has text, the tool items resize to
- * a very small size. Also, a tool item will only show text
- * when text has already been set on one item and then a new
- * item is created. The fix is to use WM_SETFONT to force
- * the tool bar to redraw and layout.
- */
- parent.setDropDownItems (false);
- int /*long*/ hFont = OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0);
- OS.SendMessage (hwnd, OS.WM_SETFONT, hFont, 0);
- parent.setDropDownItems (true);
- parent.layoutItems ();
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
-}
-
-/**
- * Sets the width of the receiver, for <code>SEPARATOR</code> ToolItems.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int width) {
- checkWidget();
- if ((style & SWT.SEPARATOR) == 0) return;
- if (width < 0) return;
- int /*long*/ hwnd = parent.handle;
- TBBUTTONINFO info = new TBBUTTONINFO ();
- info.cbSize = TBBUTTONINFO.sizeof;
- info.dwMask = OS.TBIF_SIZE;
- info.cx = (short) width;
- OS.SendMessage (hwnd, OS.TB_SETBUTTONINFO, id, info);
- parent.layoutItems ();
-}
-
-void updateImages (boolean enabled) {
- if ((style & SWT.SEPARATOR) != 0) return;
- int /*long*/ hwnd = parent.handle;
- TBBUTTONINFO info = new TBBUTTONINFO ();
- info.cbSize = TBBUTTONINFO.sizeof;
- info.dwMask = OS.TBIF_IMAGE;
- OS.SendMessage (hwnd, OS.TB_GETBUTTONINFO, id, info);
- if (info.iImage == OS.I_IMAGENONE && image == null) return;
- ImageList imageList = parent.getImageList ();
- ImageList hotImageList = parent.getHotImageList ();
- ImageList disabledImageList = parent.getDisabledImageList();
- if (info.iImage == OS.I_IMAGENONE) {
- Rectangle bounds = image.getBounds ();
- int listStyle = parent.style & SWT.RIGHT_TO_LEFT;
- if (imageList == null) {
- imageList = display.getImageListToolBar (listStyle, bounds.width, bounds.height);
- }
- if (disabledImageList == null) {
- disabledImageList = display.getImageListToolBarDisabled (listStyle, bounds.width, bounds.height);
- }
- if (hotImageList == null) {
- hotImageList = display.getImageListToolBarHot (listStyle, bounds.width, bounds.height);
- }
- Image disabled = disabledImage;
- if (disabledImage == null) {
- if (disabledImage2 != null) disabledImage2.dispose ();
- disabledImage2 = null;
- disabled = image;
- if (!enabled) {
- disabled = disabledImage2 = new Image (display, image, SWT.IMAGE_DISABLE);
- }
- }
- /*
- * Bug in Windows. When a tool item with the style
- * BTNS_CHECK or BTNS_CHECKGROUP is selected and then
- * disabled, the item does not draw using the disabled
- * image. The fix is to assign the disabled image in
- * all image lists.
- */
- Image image2 = image, hot = hotImage;
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- if (!enabled) image2 = hot = disabled;
- }
- info.iImage = imageList.add (image2);
- disabledImageList.add (disabled);
- hotImageList.add (hot != null ? hot : image2);
- parent.setImageList (imageList);
- parent.setDisabledImageList (disabledImageList);
- parent.setHotImageList (hotImageList);
- } else {
- Image disabled = null;
- if (disabledImageList != null) {
- if (image != null) {
- if (disabledImage2 != null) disabledImage2.dispose ();
- disabledImage2 = null;
- disabled = disabledImage;
- if (disabledImage == null) {
- disabled = image;
- if (!enabled) {
- disabled = disabledImage2 = new Image (display, image, SWT.IMAGE_DISABLE);
- }
- }
- }
- disabledImageList.put (info.iImage, disabled);
- }
- /*
- * Bug in Windows. When a tool item with the style
- * BTNS_CHECK or BTNS_CHECKGROUP is selected and then
- * disabled, the item does not draw using the disabled
- * image. The fix is to use the disabled image in all
- * image lists.
- */
- Image image2 = image, hot = hotImage;
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- if (!enabled) image2 = hot = disabled;
- }
- if (imageList != null) imageList.put (info.iImage, image2);
- if (hotImageList != null) {
- hotImageList.put (info.iImage, hot != null ? hot : image2);
- }
- if (image == null) info.iImage = OS.I_IMAGENONE;
- }
-
- /*
- * Bug in Windows. If the width of an item has already been
- * calculated, the tool bar control will not recalculate it to
- * include the space for the image. The fix is to set the width
- * to zero, forcing the control recalculate the width for the item.
- */
- info.dwMask |= OS.TBIF_SIZE;
- info.cx = 0;
- OS.SendMessage (hwnd, OS.TB_SETBUTTONINFO, id, info);
-
- parent.layoutItems ();
-}
-
-int widgetStyle () {
- if ((style & SWT.DROP_DOWN) != 0) return OS.BTNS_DROPDOWN;
- if ((style & SWT.PUSH) != 0) return OS.BTNS_BUTTON;
- if ((style & SWT.CHECK) != 0) return OS.BTNS_CHECK;
- /*
- * This code is intentionally commented. In order to
- * consistently support radio tool items across platforms,
- * the platform radio behavior is not used.
- */
-// if ((style & SWT.RADIO) != 0) return OS.BTNS_CHECKGROUP;
- if ((style & SWT.RADIO) != 0) return OS.BTNS_CHECK;
- if ((style & SWT.SEPARATOR) != 0) return OS.BTNS_SEP;
- return OS.BTNS_BUTTON;
-}
-
-LRESULT wmCommandChild (int /*long*/ wParam, int /*long*/ lParam) {
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) {
- selectRadio ();
- }
- }
- postEvent (SWT.Selection);
- return null;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolTip.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolTip.java
deleted file mode 100644
index 87a7355a3d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolTip.java
+++ /dev/null
@@ -1,555 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent popup windows that are used
- * to inform or warn the user.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BALLOON, ICON_ERROR, ICON_INFORMATION, ICON_WARNING</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION,
- * and ICON_WARNING may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tooltips">Tool Tips snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.2
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class ToolTip extends Widget {
- Shell parent;
- TrayItem item;
- String text = "", message = "";
- int id, x, y;
- boolean autoHide = true, hasLocation, visible;
- static final int TIMER_ID = 100;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BALLOON
- * @see SWT#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_WARNING
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ToolTip (Shell parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- checkOrientation (parent);
- parent.createToolTip (this);
-}
-
-static int checkStyle (int style) {
- int mask = SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING;
- if ((style & mask) == 0) return style;
- return checkBits (style, SWT.ICON_INFORMATION, SWT.ICON_WARNING, SWT.ICON_ERROR, 0, 0, 0);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the receiver is selected.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the receiver is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-void destroyWidget () {
- if (parent != null) parent.destroyToolTip (this);
- releaseHandle ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is automatically
- * hidden by the platform, and <code>false</code> otherwise.
- *
- * @return the receiver's auto hide state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public boolean getAutoHide () {
- checkWidget();
- return autoHide;
-}
-
-/**
- * Returns the receiver's message, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's message
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getMessage () {
- checkWidget();
- return message;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Shell</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Shell getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- return text;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- if (OS.IsWinCE) return false;
- if (item != null) return visible;
- int /*long*/ hwndToolTip = hwndToolTip ();
- if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, 0) != 0) {
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, lpti) != 0) {
- return (lpti.uFlags & OS.TTF_IDISHWND) == 0 && lpti.uId == id;
- }
- }
- return false;
-}
-
-int /*long*/ hwndToolTip () {
- return (style & SWT.BALLOON) != 0 ? parent.balloonTipHandle () : parent.toolTipHandle ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget ();
- if (item != null) return getVisible () && item.getVisible ();
- return getVisible ();
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
- item = null;
- id = -1;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (item == null) {
- if (autoHide) {
- int /*long*/ hwndToolTip = hwndToolTip ();
- if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, 0) != 0) {
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, lpti) != 0) {
- if ((lpti.uFlags & OS.TTF_IDISHWND) == 0) {
- if (lpti.uId == id) {
- OS.SendMessage (hwndToolTip, OS.TTM_TRACKACTIVATE, 0, lpti);
- OS.SendMessage (hwndToolTip, OS.TTM_POP, 0, 0);
- OS.KillTimer (hwndToolTip, TIMER_ID);
- }
- }
- }
- }
- }
- }
- if (item != null && item.toolTip == this) {
- item.toolTip = null;
- }
- item = null;
- text = message = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Makes the receiver hide automatically when <code>true</code>,
- * and remain visible when <code>false</code>.
- *
- * @param autoHide the auto hide state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- * @see #setVisible
- */
-public void setAutoHide (boolean autoHide) {
- checkWidget ();
- this.autoHide = autoHide;
- //TODO - update when visible
-}
-
-/**
- * Sets the location of the receiver, which must be a tooltip,
- * to the point specified by the arguments which are relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget ();
- this.x = x;
- this.y = y;
- hasLocation = true;
- //TODO - update when visible
-}
-
-/**
- * Sets the location of the receiver, which must be a tooltip,
- * to the point specified by the argument which is relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p><p>
- * Note that the platform window manager ultimately has control
- * over the location of tooltips.
- * </p>
- *
- * @param location the new location for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (Point location) {
- checkWidget ();
- if (location == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-/**
- * Sets the receiver's message.
- *
- * @param string the new message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMessage (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- message = string;
- //TODO - update when visible
-}
-
-/**
- * Sets the receiver's text.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- text = string;
- //TODO - update when visible
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- if (OS.IsWinCE) return;
- if (visible == getVisible ()) return;
- if (item == null) {
- int /*long*/ hwnd = parent.handle;
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- lpti.uId = id;
- lpti.hwnd = hwnd;
- int /*long*/ hwndToolTip = hwndToolTip ();
- Shell shell = parent.getShell ();
- if (text.length () != 0) {
- int icon = OS.TTI_NONE;
- if ((style & SWT.ICON_INFORMATION) != 0) icon = OS.TTI_INFO;
- if ((style & SWT.ICON_WARNING) != 0) icon = OS.TTI_WARNING;
- if ((style & SWT.ICON_ERROR) != 0) icon = OS.TTI_ERROR;
- shell.setToolTipTitle (hwndToolTip, text, icon);
- } else {
- shell.setToolTipTitle (hwndToolTip, null, 0);
- }
- int maxWidth = 0;
- if (OS.IsWinCE || OS.WIN32_VERSION < OS.VERSION (4, 10)) {
- RECT rect = new RECT ();
- OS.SystemParametersInfo (OS.SPI_GETWORKAREA, 0, rect, 0);
- maxWidth = (rect.right - rect.left) / 4;
- } else {
- int /*long*/ hmonitor = OS.MonitorFromWindow (hwnd, OS.MONITOR_DEFAULTTONEAREST);
- MONITORINFO lpmi = new MONITORINFO ();
- lpmi.cbSize = MONITORINFO.sizeof;
- OS.GetMonitorInfo (hmonitor, lpmi);
- maxWidth = (lpmi.rcWork_right - lpmi.rcWork_left) / 4;
- }
- OS.SendMessage (hwndToolTip, OS.TTM_SETMAXTIPWIDTH, 0, maxWidth);
- if (visible) {
- int nX = x, nY = y;
- if (!hasLocation) {
- POINT pt = new POINT ();
- if (OS.GetCursorPos (pt)) {
- nX = pt.x;
- nY = pt.y;
- }
- }
- int /*long*/ lParam = OS.MAKELPARAM (nX, nY);
- OS.SendMessage (hwndToolTip, OS.TTM_TRACKPOSITION, 0, lParam);
-
- /*
- * Feature in Windows. Windows will not show a tool tip
- * if the cursor is outside the parent window (even on XP,
- * TTM_POPUP will not do this). The fix is to temporarily
- * move the cursor into the tool window, show the tool tip,
- * and then restore the cursor.
- */
- POINT pt = new POINT ();
- OS.GetCursorPos (pt);
- RECT rect = new RECT ();
- OS.GetClientRect (hwnd, rect);
- OS.MapWindowPoints (hwnd, 0, rect, 2);
- if (!OS.PtInRect (rect, pt)) {
- int /*long*/ hCursor = OS.GetCursor ();
- OS.SetCursor (0);
- OS.SetCursorPos (rect.left, rect.top);
- OS.SendMessage (hwndToolTip, OS.TTM_TRACKACTIVATE, 1, lpti);
- OS.SetCursorPos (pt.x, pt.y);
- OS.SetCursor (hCursor);
- } else {
- OS.SendMessage (hwndToolTip, OS.TTM_TRACKACTIVATE, 1, lpti);
- }
-
- int time = (int)/*64*/OS.SendMessage (hwndToolTip, OS.TTM_GETDELAYTIME, OS.TTDT_AUTOPOP, 0);
- OS.SetTimer (hwndToolTip, TIMER_ID, time, 0);
- } else {
- OS.SendMessage (hwndToolTip, OS.TTM_TRACKACTIVATE, 0, lpti);
- OS.SendMessage (hwndToolTip, OS.TTM_POP, 0, 0);
- OS.KillTimer (hwndToolTip, TIMER_ID);
- }
- return;
- }
- if (item != null && OS.SHELL32_MAJOR >= 5) {
- if (visible) {
- NOTIFYICONDATA iconData = OS.IsUnicode ? (NOTIFYICONDATA) new NOTIFYICONDATAW () : new NOTIFYICONDATAA ();
- TCHAR buffer1 = new TCHAR (0, text, true);
- TCHAR buffer2 = new TCHAR (0, message, true);
- if (OS.IsUnicode) {
- char [] szInfoTitle = ((NOTIFYICONDATAW) iconData).szInfoTitle;
- int length1 = Math.min (szInfoTitle.length - 1, buffer1.length ());
- System.arraycopy (buffer1.chars, 0, szInfoTitle, 0, length1);
- char [] szInfo = ((NOTIFYICONDATAW) iconData).szInfo;
- int length2 = Math.min (szInfo.length - 1, buffer2.length ());
- System.arraycopy (buffer2.chars, 0, szInfo, 0, length2);
- } else {
- byte [] szInfoTitle = ((NOTIFYICONDATAA) iconData).szInfoTitle;
- int length = Math.min (szInfoTitle.length - 1, buffer1.length ());
- System.arraycopy (buffer1.bytes, 0, szInfoTitle, 0, length);
- byte [] szInfo = ((NOTIFYICONDATAA) iconData).szInfo;
- int length2 = Math.min (szInfo.length - 1, buffer2.length ());
- System.arraycopy (buffer2.bytes, 0, szInfo, 0, length2);
- }
- Display display = item.getDisplay ();
- iconData.cbSize = NOTIFYICONDATA.sizeof;
- iconData.uID = item.id;
- iconData.hWnd = display.hwndMessage;
- iconData.uFlags = OS.NIF_INFO;
- if ((style & SWT.ICON_INFORMATION) != 0) iconData.dwInfoFlags = OS.NIIF_INFO;
- if ((style & SWT.ICON_WARNING) != 0) iconData.dwInfoFlags = OS.NIIF_WARNING;
- if ((style & SWT.ICON_ERROR) != 0) iconData.dwInfoFlags = OS.NIIF_ERROR;
- sendEvent (SWT.Show);
- this.visible = OS.Shell_NotifyIcon (OS.NIM_MODIFY, iconData);
- } else {
- //TODO - hide the tray item
- }
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tracker.java
deleted file mode 100755
index f45e58c725..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tracker.java
+++ /dev/null
@@ -1,1188 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class implement rubber banding rectangles that are
- * drawn onto a parent <code>Composite</code> or <code>Display</code>.
- * These rectangles can be specified to respond to mouse and key events
- * by either moving or resizing themselves accordingly. Trackers are
- * typically used to represent window geometries in a lightweight manner.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, UP, DOWN, RESIZE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Move, Resize</dd>
- * </dl>
- * <p>
- * Note: Rectangle move behavior is assumed unless RESIZE is specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tracker">Tracker snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Tracker extends Widget {
- Control parent;
- boolean tracking, cancelled, stippled;
- Rectangle [] rectangles = new Rectangle [0], proportions = rectangles;
- Rectangle bounds;
- int /*long*/ resizeCursor;
- Cursor clientCursor;
- int cursorOrientation = SWT.NONE;
- boolean inEvent = false;
- int /*long*/ hwndTransparent, hwndOpaque, oldTransparentProc, oldOpaqueProc;
- int oldX, oldY;
-
- /*
- * The following values mirror step sizes on Windows
- */
- final static int STEPSIZE_SMALL = 1;
- final static int STEPSIZE_LARGE = 9;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#RESIZE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Tracker (Composite parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
-}
-
-/**
- * Constructs a new instance of this class given the display
- * to create it on and a style value describing its behavior
- * and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the tracker on the currently active
- * display if there is one. If there is no current display, the
- * tracker is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the tracker on
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#RESIZE
- */
-public Tracker (Display display, int style) {
- if (display == null) display = Display.getCurrent ();
- if (display == null) display = Display.getDefault ();
- if (!display.isValidThread ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- this.style = checkStyle (style);
- this.display = display;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize, typedListener);
- addListener (SWT.Move, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard, by sending
- * it one of the messages defined in the <code>KeyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #removeKeyListener
- */
-public void addKeyListener (KeyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.KeyUp,typedListener);
- addListener (SWT.KeyDown,typedListener);
-}
-
-Point adjustMoveCursor () {
- if (bounds == null) return null;
- int newX = bounds.x + bounds.width / 2;
- int newY = bounds.y;
- POINT pt = new POINT ();
- pt.x = newX; pt.y = newY;
- /*
- * Convert to screen coordinates iff needed
- */
- if (parent != null) {
- OS.ClientToScreen (parent.handle, pt);
- }
- OS.SetCursorPos (pt.x, pt.y);
- return new Point (pt.x, pt.y);
-}
-
-Point adjustResizeCursor () {
- if (bounds == null) return null;
- int newX, newY;
-
- if ((cursorOrientation & SWT.LEFT) != 0) {
- newX = bounds.x;
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- newX = bounds.x + bounds.width;
- } else {
- newX = bounds.x + bounds.width / 2;
- }
-
- if ((cursorOrientation & SWT.UP) != 0) {
- newY = bounds.y;
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- newY = bounds.y + bounds.height;
- } else {
- newY = bounds.y + bounds.height / 2;
- }
-
- POINT pt = new POINT ();
- pt.x = newX; pt.y = newY;
- /*
- * Convert to screen coordinates iff needed
- */
- if (parent != null) {
- OS.ClientToScreen (parent.handle, pt);
- }
- OS.SetCursorPos (pt.x, pt.y);
-
- /*
- * If the client has not provided a custom cursor then determine
- * the appropriate resize cursor.
- */
- if (clientCursor == null) {
- int /*long*/ newCursor = 0;
- switch (cursorOrientation) {
- case SWT.UP:
- newCursor = OS.LoadCursor (0, OS.IDC_SIZENS);
- break;
- case SWT.DOWN:
- newCursor = OS.LoadCursor (0, OS.IDC_SIZENS);
- break;
- case SWT.LEFT:
- newCursor = OS.LoadCursor (0, OS.IDC_SIZEWE);
- break;
- case SWT.RIGHT:
- newCursor = OS.LoadCursor (0, OS.IDC_SIZEWE);
- break;
- case SWT.LEFT | SWT.UP:
- newCursor = OS.LoadCursor (0, OS.IDC_SIZENWSE);
- break;
- case SWT.RIGHT | SWT.DOWN:
- newCursor = OS.LoadCursor (0, OS.IDC_SIZENWSE);
- break;
- case SWT.LEFT | SWT.DOWN:
- newCursor = OS.LoadCursor (0, OS.IDC_SIZENESW);
- break;
- case SWT.RIGHT | SWT.UP:
- newCursor = OS.LoadCursor (0, OS.IDC_SIZENESW);
- break;
- default:
- newCursor = OS.LoadCursor (0, OS.IDC_SIZEALL);
- break;
- }
- OS.SetCursor (newCursor);
- if (resizeCursor != 0) {
- OS.DestroyCursor (resizeCursor);
- }
- resizeCursor = newCursor;
- }
-
- return new Point (pt.x, pt.y);
-}
-
-static int checkStyle (int style) {
- if ((style & (SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN)) == 0) {
- style |= SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN;
- }
- return style;
-}
-
-/**
- * Stops displaying the tracker rectangles. Note that this is not considered
- * to be a cancelation by the user.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void close () {
- checkWidget ();
- tracking = false;
-}
-
-Rectangle computeBounds () {
- if (rectangles.length == 0) return null;
- int xMin = rectangles [0].x;
- int yMin = rectangles [0].y;
- int xMax = rectangles [0].x + rectangles [0].width;
- int yMax = rectangles [0].y + rectangles [0].height;
-
- for (int i = 1; i < rectangles.length; i++) {
- if (rectangles [i].x < xMin) xMin = rectangles [i].x;
- if (rectangles [i].y < yMin) yMin = rectangles [i].y;
- int rectRight = rectangles [i].x + rectangles [i].width;
- if (rectRight > xMax) xMax = rectRight;
- int rectBottom = rectangles [i].y + rectangles [i].height;
- if (rectBottom > yMax) yMax = rectBottom;
- }
-
- return new Rectangle (xMin, yMin, xMax - xMin, yMax - yMin);
-}
-
-Rectangle [] computeProportions (Rectangle [] rects) {
- Rectangle [] result = new Rectangle [rects.length];
- bounds = computeBounds ();
- if (bounds != null) {
- for (int i = 0; i < rects.length; i++) {
- int x = 0, y = 0, width = 0, height = 0;
- if (bounds.width != 0) {
- x = (rects [i].x - bounds.x) * 100 / bounds.width;
- width = rects [i].width * 100 / bounds.width;
- } else {
- width = 100;
- }
- if (bounds.height != 0) {
- y = (rects [i].y - bounds.y) * 100 / bounds.height;
- height = rects [i].height * 100 / bounds.height;
- } else {
- height = 100;
- }
- result [i] = new Rectangle (x, y, width, height);
- }
- }
- return result;
-}
-
-/**
- * Draw the rectangles displayed by the tracker.
- */
-void drawRectangles (Rectangle [] rects, boolean stippled) {
- if (parent == null && !OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- RECT rect1 = new RECT();
- int bandWidth = stippled ? 3 : 1;
- for (int i = 0; i < rects.length; i++) {
- Rectangle rect = rects[i];
- rect1.left = rect.x - bandWidth;
- rect1.top = rect.y - bandWidth;
- rect1.right = rect.x + rect.width + bandWidth * 2;
- rect1.bottom = rect.y + rect.height + bandWidth * 2;
- OS.RedrawWindow (hwndOpaque, rect1, 0, OS.RDW_INVALIDATE);
- }
- return;
- }
- int bandWidth = 1;
- int /*long*/ hwndTrack = OS.GetDesktopWindow ();
- if (parent != null) hwndTrack = parent.handle;
- int /*long*/ hDC = OS.GetDCEx (hwndTrack, 0, OS.DCX_CACHE);
- int /*long*/ hBitmap = 0, hBrush = 0, oldBrush = 0;
- if (stippled) {
- bandWidth = 3;
- byte [] bits = {-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0};
- hBitmap = OS.CreateBitmap (8, 8, 1, 1, bits);
- hBrush = OS.CreatePatternBrush (hBitmap);
- oldBrush = OS.SelectObject (hDC, hBrush);
- }
- for (int i=0; i<rects.length; i++) {
- Rectangle rect = rects [i];
- OS.PatBlt (hDC, rect.x, rect.y, rect.width, bandWidth, OS.PATINVERT);
- OS.PatBlt (hDC, rect.x, rect.y + bandWidth, bandWidth, rect.height - (bandWidth * 2), OS.PATINVERT);
- OS.PatBlt (hDC, rect.x + rect.width - bandWidth, rect.y + bandWidth, bandWidth, rect.height - (bandWidth * 2), OS.PATINVERT);
- OS.PatBlt (hDC, rect.x, rect.y + rect.height - bandWidth, rect.width, bandWidth, OS.PATINVERT);
- }
- if (stippled) {
- OS.SelectObject (hDC, oldBrush);
- OS.DeleteObject (hBrush);
- OS.DeleteObject (hBitmap);
- }
- OS.ReleaseDC (hwndTrack, hDC);
-}
-
-/**
- * Returns the bounds that are being drawn, expressed relative to the parent
- * widget. If the parent is a <code>Display</code> then these are screen
- * coordinates.
- *
- * @return the bounds of the Rectangles being drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle [] getRectangles () {
- checkWidget();
- Rectangle [] result = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- result [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- return result;
-}
-
-/**
- * Returns <code>true</code> if the rectangles are drawn with a stippled line, <code>false</code> otherwise.
- *
- * @return the stippled effect of the rectangles
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getStippled () {
- checkWidget ();
- return stippled;
-}
-
-void moveRectangles (int xChange, int yChange) {
- if (bounds == null) return;
- if (xChange < 0 && ((style & SWT.LEFT) == 0)) xChange = 0;
- if (xChange > 0 && ((style & SWT.RIGHT) == 0)) xChange = 0;
- if (yChange < 0 && ((style & SWT.UP) == 0)) yChange = 0;
- if (yChange > 0 && ((style & SWT.DOWN) == 0)) yChange = 0;
- if (xChange == 0 && yChange == 0) return;
- bounds.x += xChange; bounds.y += yChange;
- for (int i = 0; i < rectangles.length; i++) {
- rectangles [i].x += xChange;
- rectangles [i].y += yChange;
- }
-}
-
-/**
- * Displays the Tracker rectangles for manipulation by the user. Returns when
- * the user has either finished manipulating the rectangles or has cancelled the
- * Tracker.
- *
- * @return <code>true</code> if the user did not cancel the Tracker, <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean open () {
- checkWidget ();
- cancelled = false;
- tracking = true;
-
- /*
- * If exactly one of UP/DOWN is specified as a style then set the cursor
- * orientation accordingly (the same is done for LEFT/RIGHT styles below).
- */
- int vStyle = style & (SWT.UP | SWT.DOWN);
- if (vStyle == SWT.UP || vStyle == SWT.DOWN) {
- cursorOrientation |= vStyle;
- }
- int hStyle = style & (SWT.LEFT | SWT.RIGHT);
- if (hStyle == SWT.LEFT || hStyle == SWT.RIGHT) {
- cursorOrientation |= hStyle;
- }
-
- /*
- * If this tracker is being created without a mouse drag then
- * we need to create a transparent window that fills the screen
- * in order to get all mouse/keyboard events that occur
- * outside of our visible windows (ie.- over the desktop).
- */
- Callback newProc = null;
- boolean mouseDown = OS.GetKeyState(OS.VK_LBUTTON) < 0;
- boolean isVista = !OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0);
- if ((parent == null && isVista) || !mouseDown) {
- int width = OS.GetSystemMetrics (OS.SM_CXSCREEN);
- int height = OS.GetSystemMetrics (OS.SM_CYSCREEN);
- hwndTransparent = OS.CreateWindowEx (
- isVista ? OS.WS_EX_LAYERED | OS.WS_EX_NOACTIVATE : OS.WS_EX_TRANSPARENT,
- display.windowClass,
- null,
- OS.WS_POPUP,
- 0, 0,
- width, height,
- 0,
- 0,
- OS.GetModuleHandle (null),
- null);
- if (isVista) {
- OS.SetLayeredWindowAttributes (hwndTransparent, 0xFFFFFF, (byte)0x01, OS.LWA_ALPHA);
- }
- OS.ShowWindow (hwndTransparent, OS.SW_SHOWNOACTIVATE);
- newProc = new Callback (this, "transparentProc", 4); //$NON-NLS-1$
- int /*long*/ newProcAddress = newProc.getAddress ();
- if (newProcAddress == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- if (isVista) {
- hwndOpaque = OS.CreateWindowEx (
- OS.WS_EX_LAYERED | OS.WS_EX_NOACTIVATE,
- display.windowClass,
- null,
- OS.WS_POPUP,
- 0, 0,
- width, height,
- hwndTransparent,
- 0,
- OS.GetModuleHandle (null),
- null);
- oldOpaqueProc = OS.GetWindowLongPtr (hwndOpaque, OS.GWLP_WNDPROC);
- OS.SetWindowLongPtr (hwndOpaque, OS.GWLP_WNDPROC, newProcAddress);
- } else {
- hwndOpaque = hwndTransparent;
- }
- oldTransparentProc = OS.GetWindowLongPtr (hwndTransparent, OS.GWLP_WNDPROC);
- OS.SetWindowLongPtr (hwndTransparent, OS.GWLP_WNDPROC, newProcAddress);
- OS.SetLayeredWindowAttributes (hwndOpaque, 0xFFFFFF, (byte)0xFF, OS.LWA_COLORKEY | OS.LWA_ALPHA);
- OS.ShowWindow (hwndOpaque, OS.SW_SHOWNOACTIVATE);
- }
-
- update ();
- drawRectangles (rectangles, stippled);
- Point cursorPos = null;
- if (mouseDown) {
- POINT pt = new POINT ();
- OS.GetCursorPos (pt);
- cursorPos = new Point (pt.x, pt.y);
- } else {
- if ((style & SWT.RESIZE) != 0) {
- cursorPos = adjustResizeCursor ();
- } else {
- cursorPos = adjustMoveCursor ();
- }
- }
- if (cursorPos != null) {
- oldX = cursorPos.x;
- oldY = cursorPos.y;
- }
-
- try {
- /* Tracker behaves like a Dialog with its own OS event loop. */
- MSG msg = new MSG ();
- while (tracking && !cancelled) {
- if (parent != null && parent.isDisposed ()) break;
- OS.GetMessage (msg, 0, 0, 0);
- OS.TranslateMessage (msg);
- switch (msg.message) {
- case OS.WM_LBUTTONUP:
- case OS.WM_MOUSEMOVE:
- wmMouse (msg.message, msg.wParam, msg.lParam);
- break;
- case OS.WM_IME_CHAR: wmIMEChar (msg.hwnd, msg.wParam, msg.lParam); break;
- case OS.WM_CHAR: wmChar (msg.hwnd, msg.wParam, msg.lParam); break;
- case OS.WM_KEYDOWN: wmKeyDown (msg.hwnd, msg.wParam, msg.lParam); break;
- case OS.WM_KEYUP: wmKeyUp (msg.hwnd, msg.wParam, msg.lParam); break;
- case OS.WM_SYSCHAR: wmSysChar (msg.hwnd, msg.wParam, msg.lParam); break;
- case OS.WM_SYSKEYDOWN: wmSysKeyDown (msg.hwnd, msg.wParam, msg.lParam); break;
- case OS.WM_SYSKEYUP: wmSysKeyUp (msg.hwnd, msg.wParam, msg.lParam); break;
- }
- if (OS.WM_KEYFIRST <= msg.message && msg.message <= OS.WM_KEYLAST) continue;
- if (OS.WM_MOUSEFIRST <= msg.message && msg.message <= OS.WM_MOUSELAST) continue;
- if (!(parent == null && isVista)) {
- if (msg.message == OS.WM_PAINT) {
- update ();
- drawRectangles (rectangles, stippled);
- }
- }
- OS.DispatchMessage (msg);
- if (!(parent == null && isVista)) {
- if (msg.message == OS.WM_PAINT) {
- drawRectangles (rectangles, stippled);
- }
- }
- }
- if (mouseDown) OS.ReleaseCapture ();
- if (!isDisposed()) {
- update ();
- drawRectangles (rectangles, stippled);
- }
- } finally {
- /*
- * Cleanup: If a transparent window was created in order to capture events then
- * destroy it and its callback object now.
- */
- if (hwndTransparent != 0) {
- OS.DestroyWindow (hwndTransparent);
- hwndTransparent = 0;
- }
- hwndOpaque = 0;
- if (newProc != null) {
- newProc.dispose ();
- oldTransparentProc = oldOpaqueProc = 0;
- }
- /*
- * Cleanup: If this tracker was resizing then the last cursor that it created
- * needs to be destroyed.
- */
- if (resizeCursor != 0) {
- OS.DestroyCursor (resizeCursor);
- resizeCursor = 0;
- }
- }
- tracking = false;
- return !cancelled;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
- rectangles = proportions = null;
- bounds = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Resize, listener);
- eventTable.unhook (SWT.Move, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #addKeyListener
- */
-public void removeKeyListener(KeyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.KeyUp, listener);
- eventTable.unhook (SWT.KeyDown, listener);
-}
-
-void resizeRectangles (int xChange, int yChange) {
- if (bounds == null) return;
- /*
- * If the cursor orientation has not been set in the orientation of
- * this change then try to set it here.
- */
- if (xChange < 0 && ((style & SWT.LEFT) != 0) && ((cursorOrientation & SWT.RIGHT) == 0)) {
- cursorOrientation |= SWT.LEFT;
- }
- if (xChange > 0 && ((style & SWT.RIGHT) != 0) && ((cursorOrientation & SWT.LEFT) == 0)) {
- cursorOrientation |= SWT.RIGHT;
- }
- if (yChange < 0 && ((style & SWT.UP) != 0) && ((cursorOrientation & SWT.DOWN) == 0)) {
- cursorOrientation |= SWT.UP;
- }
- if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) {
- cursorOrientation |= SWT.DOWN;
- }
-
- /*
- * If the bounds will flip about the x or y axis then apply the adjustment
- * up to the axis (ie.- where bounds width/height becomes 0), change the
- * cursor's orientation accordingly, and flip each Rectangle's origin (only
- * necessary for > 1 Rectangles)
- */
- if ((cursorOrientation & SWT.LEFT) != 0) {
- if (xChange > bounds.width) {
- if ((style & SWT.RIGHT) == 0) return;
- cursorOrientation |= SWT.RIGHT;
- cursorOrientation &= ~SWT.LEFT;
- bounds.x += bounds.width;
- xChange -= bounds.width;
- bounds.width = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.x = 100 - proportion.x - proportion.width;
- }
- }
- }
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- if (bounds.width < -xChange) {
- if ((style & SWT.LEFT) == 0) return;
- cursorOrientation |= SWT.LEFT;
- cursorOrientation &= ~SWT.RIGHT;
- xChange += bounds.width;
- bounds.width = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.x = 100 - proportion.x - proportion.width;
- }
- }
- }
- }
- if ((cursorOrientation & SWT.UP) != 0) {
- if (yChange > bounds.height) {
- if ((style & SWT.DOWN) == 0) return;
- cursorOrientation |= SWT.DOWN;
- cursorOrientation &= ~SWT.UP;
- bounds.y += bounds.height;
- yChange -= bounds.height;
- bounds.height = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.y = 100 - proportion.y - proportion.height;
- }
- }
- }
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- if (bounds.height < -yChange) {
- if ((style & SWT.UP) == 0) return;
- cursorOrientation |= SWT.UP;
- cursorOrientation &= ~SWT.DOWN;
- yChange += bounds.height;
- bounds.height = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.y = 100 - proportion.y - proportion.height;
- }
- }
- }
- }
-
- // apply the bounds adjustment
- if ((cursorOrientation & SWT.LEFT) != 0) {
- bounds.x += xChange;
- bounds.width -= xChange;
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- bounds.width += xChange;
- }
- if ((cursorOrientation & SWT.UP) != 0) {
- bounds.y += yChange;
- bounds.height -= yChange;
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- bounds.height += yChange;
- }
-
- Rectangle [] newRects = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle proportion = proportions[i];
- newRects[i] = new Rectangle (
- proportion.x * bounds.width / 100 + bounds.x,
- proportion.y * bounds.height / 100 + bounds.y,
- proportion.width * bounds.width / 100,
- proportion.height * bounds.height / 100);
- }
- rectangles = newRects;
-}
-
-/**
- * Sets the <code>Cursor</code> of the Tracker. If this cursor is <code>null</code>
- * then the cursor reverts to the default.
- *
- * @param newCursor the new <code>Cursor</code> to display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCursor(Cursor newCursor) {
- checkWidget();
- clientCursor = newCursor;
- if (newCursor != null) {
- if (inEvent) OS.SetCursor (clientCursor.handle);
- }
-}
-
-/**
- * Specifies the rectangles that should be drawn, expressed relative to the parent
- * widget. If the parent is a Display then these are screen coordinates.
- *
- * @param rectangles the bounds of the rectangles to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of rectangles is null or contains a null rectangle</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setRectangles (Rectangle [] rectangles) {
- checkWidget ();
- if (rectangles == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.rectangles = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- if (current == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.rectangles [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- proportions = computeProportions (rectangles);
-}
-
-/**
- * Changes the appearance of the line used to draw the rectangles.
- *
- * @param stippled <code>true</code> if rectangle should appear stippled
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setStippled (boolean stippled) {
- checkWidget ();
- this.stippled = stippled;
-}
-
-int /*long*/ transparentProc (int /*long*/ hwnd, int /*long*/ msg, int /*long*/ wParam, int /*long*/ lParam) {
- switch ((int)/*64*/msg) {
- /*
- * We typically do not want to answer that the transparent window is
- * transparent to hits since doing so negates the effect of having it
- * to grab events. However, clients of the tracker should not be aware
- * of this transparent window. Therefore if there is a hit query
- * performed as a result of client code then answer that the transparent
- * window is transparent to hits so that its existence will not impact
- * the client.
- */
- case OS.WM_NCHITTEST:
- if (inEvent) return OS.HTTRANSPARENT;
- break;
- case OS.WM_SETCURSOR:
- if (hwndOpaque == hwnd) {
- if (clientCursor != null) {
- OS.SetCursor (clientCursor.handle);
- return 1;
- }
- if (resizeCursor != 0) {
- OS.SetCursor (resizeCursor);
- return 1;
- }
- }
- break;
- case OS.WM_PAINT:
- boolean isVista = !OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0);
- if (parent == null && isVista && hwndOpaque == hwnd) {
- PAINTSTRUCT ps = new PAINTSTRUCT();
- int /*long*/ hDC = OS.BeginPaint (hwnd, ps);
- int /*long*/ hBitmap = 0, hBrush = 0, oldBrush = 0;
- int /*long*/ transparentBrush = OS.CreateSolidBrush(0xFFFFFF);
- oldBrush = OS.SelectObject (hDC, transparentBrush);
- OS.PatBlt (hDC, ps.left, ps.top, ps.right - ps.left, ps.bottom - ps.top, OS.PATCOPY);
- OS.SelectObject (hDC, oldBrush);
- OS.DeleteObject (transparentBrush);
- int bandWidth = 1;
- if (stippled) {
- bandWidth = 3;
- byte [] bits = {-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0};
- hBitmap = OS.CreateBitmap (8, 8, 1, 1, bits);
- hBrush = OS.CreatePatternBrush (hBitmap);
- oldBrush = OS.SelectObject (hDC, hBrush);
- OS.SetBkColor (hDC, 0xF0F0F0);
- } else {
- oldBrush = OS.SelectObject (hDC, OS.GetStockObject(OS.BLACK_BRUSH));
- }
- Rectangle[] rects = this.rectangles;
- for (int i=0; i<rects.length; i++) {
- Rectangle rect = rects [i];
- OS.PatBlt (hDC, rect.x, rect.y, rect.width, bandWidth, OS.PATCOPY);
- OS.PatBlt (hDC, rect.x, rect.y + bandWidth, bandWidth, rect.height - (bandWidth * 2), OS.PATCOPY);
- OS.PatBlt (hDC, rect.x + rect.width - bandWidth, rect.y + bandWidth, bandWidth, rect.height - (bandWidth * 2), OS.PATCOPY);
- OS.PatBlt (hDC, rect.x, rect.y + rect.height - bandWidth, rect.width, bandWidth, OS.PATCOPY);
- }
- OS.SelectObject (hDC, oldBrush);
- if (stippled) {
- OS.DeleteObject (hBrush);
- OS.DeleteObject (hBitmap);
- }
- OS.EndPaint (hwnd, ps);
- return 0;
- }
- }
- return OS.CallWindowProc (hwnd == hwndTransparent ? oldTransparentProc : oldOpaqueProc, hwnd, (int)/*64*/msg, wParam, lParam);
-}
-
-void update () {
- if (parent == null && !OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) return;
- if (parent != null) {
- if (parent.isDisposed ()) return;
- Shell shell = parent.getShell ();
- shell.update (true);
- } else {
- display.update ();
- }
-}
-
-LRESULT wmKeyDown (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.wmKeyDown (hwnd, wParam, lParam);
- if (result != null) return result;
- boolean isMirrored = parent != null && (parent.style & SWT.MIRRORED) != 0;
- int stepSize = OS.GetKeyState (OS.VK_CONTROL) < 0 ? STEPSIZE_SMALL : STEPSIZE_LARGE;
- int xChange = 0, yChange = 0;
- switch ((int)/*64*/wParam) {
- case OS.VK_ESCAPE:
- cancelled = true;
- tracking = false;
- break;
- case OS.VK_RETURN:
- tracking = false;
- break;
- case OS.VK_LEFT:
- xChange = isMirrored ? stepSize : -stepSize;
- break;
- case OS.VK_RIGHT:
- xChange = isMirrored ? -stepSize : stepSize;
- break;
- case OS.VK_UP:
- yChange = -stepSize;
- break;
- case OS.VK_DOWN:
- yChange = stepSize;
- break;
- }
- if (xChange != 0 || yChange != 0) {
- Rectangle [] oldRectangles = rectangles;
- boolean oldStippled = stippled;
- Rectangle [] rectsToErase = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- rectsToErase [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- Event event = new Event ();
- event.x = oldX + xChange;
- event.y = oldY + yChange;
- Point cursorPos;
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (xChange, yChange);
- inEvent = true;
- sendEvent (SWT.Resize, event);
- inEvent = false;
- /*
- * It is possible (but unlikely) that application
- * code could have disposed the widget in the resize
- * event. If this happens return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return LRESULT.ONE;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the resize event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (rectsToErase, oldStippled);
- update ();
- drawRectangles (rectangles, stippled);
- }
- cursorPos = adjustResizeCursor ();
- } else {
- moveRectangles (xChange, yChange);
- inEvent = true;
- sendEvent (SWT.Move, event);
- inEvent = false;
- /*
- * It is possible (but unlikely) that application
- * code could have disposed the widget in the move
- * event. If this happens return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return LRESULT.ONE;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the move event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (rectsToErase, oldStippled);
- update ();
- drawRectangles (rectangles, stippled);
- }
- cursorPos = adjustMoveCursor ();
- }
- if (cursorPos != null) {
- oldX = cursorPos.x;
- oldY = cursorPos.y;
- }
- }
- return result;
-}
-
-LRESULT wmSysKeyDown (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.wmSysKeyDown (hwnd, wParam, lParam);
- if (result != null) return result;
- cancelled = true;
- tracking = false;
- return result;
-}
-
-LRESULT wmMouse (int message, int /*long*/ wParam, int /*long*/ lParam) {
- boolean isMirrored = parent != null && (parent.style & SWT.MIRRORED) != 0;
- int newPos = OS.GetMessagePos ();
- int newX = OS.GET_X_LPARAM (newPos);
- int newY = OS.GET_Y_LPARAM (newPos);
- if (newX != oldX || newY != oldY) {
- Rectangle [] oldRectangles = rectangles;
- boolean oldStippled = stippled;
- Rectangle [] rectsToErase = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle current = rectangles [i];
- rectsToErase [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- Event event = new Event ();
- event.x = newX;
- event.y = newY;
- if ((style & SWT.RESIZE) != 0) {
- if (isMirrored) {
- resizeRectangles (oldX - newX, newY - oldY);
- } else {
- resizeRectangles (newX - oldX, newY - oldY);
- }
- inEvent = true;
- sendEvent (SWT.Resize, event);
- inEvent = false;
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the resize
- * event. If this happens, return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return LRESULT.ONE;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the resize event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- }
- else {
- draw = true;
- }
- if (draw) {
- drawRectangles (rectsToErase, oldStippled);
- update ();
- drawRectangles (rectangles, stippled);
- }
- Point cursorPos = adjustResizeCursor ();
- if (cursorPos != null) {
- newX = cursorPos.x;
- newY = cursorPos.y;
- }
- } else {
- if (isMirrored) {
- moveRectangles (oldX - newX, newY - oldY);
- } else {
- moveRectangles (newX - oldX, newY - oldY);
- }
- inEvent = true;
- sendEvent (SWT.Move, event);
- inEvent = false;
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the move
- * event. If this happens, return false to indicate
- * that the tracking has failed.
- */
- if (isDisposed ()) {
- cancelled = true;
- return LRESULT.ONE;
- }
- boolean draw = false;
- /*
- * It is possible that application code could have
- * changed the rectangles in the move event. If this
- * happens then only redraw the tracker if the rectangle
- * values have changed.
- */
- if (rectangles != oldRectangles) {
- int length = rectangles.length;
- if (length != rectsToErase.length) {
- draw = true;
- } else {
- for (int i = 0; i < length; i++) {
- if (!rectangles [i].equals (rectsToErase [i])) {
- draw = true;
- break;
- }
- }
- }
- } else {
- draw = true;
- }
- if (draw) {
- drawRectangles (rectsToErase, oldStippled);
- update ();
- drawRectangles (rectangles, stippled);
- }
- }
- oldX = newX;
- oldY = newY;
- }
- tracking = message != OS.WM_LBUTTONUP;
- return null;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TrayItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TrayItem.java
deleted file mode 100644
index acd99d6888..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TrayItem.java
+++ /dev/null
@@ -1,537 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.win32.*;
-
-/**
- * Instances of this class represent icons that can be placed on the
- * system tray or task bar status area.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, MenuDetect, Selection</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tray">Tray, TrayItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.0
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TrayItem extends Item {
- Tray parent;
- int id;
- Image image2;
- ToolTip toolTip;
- String toolTipText;
- boolean visible = true;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tray</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TrayItem (Tray parent, int style) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
- createWidget ();
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the receiver is selected
- * <code>widgetDefaultSelected</code> is called when the receiver is double-clicked
- * </p>
- *
- * @param listener the listener which should be notified when the receiver is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the platform-specific context menu trigger
- * has occurred, by sending it one of the messages defined in
- * the <code>MenuDetectListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #removeMenuDetectListener
- *
- * @since 3.3
- */
-public void addMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MenuDetect, typedListener);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createWidget () {
- NOTIFYICONDATA iconData = OS.IsUnicode ? (NOTIFYICONDATA) new NOTIFYICONDATAW () : new NOTIFYICONDATAA ();
- iconData.cbSize = NOTIFYICONDATA.sizeof;
- iconData.uID = id = display.nextTrayId++;
- iconData.hWnd = display.hwndMessage;
- iconData.uFlags = OS.NIF_MESSAGE;
- iconData.uCallbackMessage = Display.SWT_TRAYICONMSG;
- OS.Shell_NotifyIcon (OS.NIM_ADD, iconData);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Tray</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Tray getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's tool tip, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public ToolTip getToolTip () {
- checkWidget ();
- return toolTip;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and
- * <code>false</code> otherwise.
- *
- * @return the receiver's visibility
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- return visible;
-}
-
-int /*long*/ messageProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. When the user clicks on the tray
- * icon, another application may be the foreground window.
- * This means that the event loop is not running and can
- * cause problems. For example, if a menu is shown, when
- * the user clicks outside of the menu to cancel it, the
- * menu is not hidden until an event is processed. If
- * another application is the foreground window, then the
- * menu is not hidden. The fix is to force the tray icon
- * message window to the foreground when sending an event.
- */
- switch ((int)/*64*/lParam) {
- case OS.WM_LBUTTONDOWN:
- if (hooks (SWT.Selection)) {
- OS.SetForegroundWindow (hwnd);
- postEvent (SWT.Selection);
- }
- break;
- case OS.WM_LBUTTONDBLCLK:
- case OS.WM_RBUTTONDBLCLK:
- if (hooks (SWT.DefaultSelection)) {
- OS.SetForegroundWindow (hwnd);
- postEvent (SWT.DefaultSelection);
- }
- break;
- case OS.WM_RBUTTONUP: {
- if (hooks (SWT.MenuDetect)) {
- OS.SetForegroundWindow (hwnd);
- sendEvent (SWT.MenuDetect);
- // widget could be disposed at this point
- if (isDisposed()) return 0;
- }
- break;
- }
- case OS.NIN_BALLOONSHOW:
- if (toolTip != null && !toolTip.visible) {
- toolTip.visible = true;
- if (toolTip.hooks (SWT.Show)) {
- OS.SetForegroundWindow (hwnd);
- toolTip.sendEvent (SWT.Show);
- // widget could be disposed at this point
- if (isDisposed()) return 0;
- }
- }
- break;
- case OS.NIN_BALLOONHIDE:
- case OS.NIN_BALLOONTIMEOUT:
- case OS.NIN_BALLOONUSERCLICK:
- if (toolTip != null) {
- if (toolTip.visible) {
- toolTip.visible = false;
- if (toolTip.hooks (SWT.Hide)) {
- OS.SetForegroundWindow (hwnd);
- toolTip.sendEvent (SWT.Hide);
- // widget could be disposed at this point
- if (isDisposed()) return 0;
- }
- }
- if (lParam == OS.NIN_BALLOONUSERCLICK) {
- if (toolTip.hooks (SWT.Selection)) {
- OS.SetForegroundWindow (hwnd);
- toolTip.postEvent (SWT.Selection);
- // widget could be disposed at this point
- if (isDisposed()) return 0;
- }
- }
- }
- break;
- }
- display.wakeThread ();
- return 0;
-}
-
-void recreate () {
- createWidget ();
- if (!visible) setVisible (false);
- if (text.length () != 0) setText (text);
- if (image != null) setImage (image);
- if (toolTipText != null) setToolTipText (toolTipText);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (toolTip != null) toolTip.item = null;
- toolTip = null;
- if (image2 != null) image2.dispose ();
- image2 = null;
- toolTipText = null;
- NOTIFYICONDATA iconData = OS.IsUnicode ? (NOTIFYICONDATA) new NOTIFYICONDATAW () : new NOTIFYICONDATAA ();
- iconData.cbSize = NOTIFYICONDATA.sizeof;
- iconData.uID = id;
- iconData.hWnd = display.hwndMessage;
- OS.Shell_NotifyIcon (OS.NIM_DELETE, iconData);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the platform-specific context menu trigger has
- * occurred.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #addMenuDetectListener
- *
- * @since 3.3
- */
-public void removeMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MenuDetect, listener);
-}
-
-/**
- * Sets the receiver's image.
- *
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- super.setImage (image);
- if (image2 != null) image2.dispose ();
- image2 = null;
- int /*long*/ hIcon = 0;
- Image icon = image;
- if (icon != null) {
- switch (icon.type) {
- case SWT.BITMAP:
- image2 = Display.createIcon (image);
- hIcon = image2.handle;
- break;
- case SWT.ICON:
- hIcon = icon.handle;
- break;
- }
- }
- NOTIFYICONDATA iconData = OS.IsUnicode ? (NOTIFYICONDATA) new NOTIFYICONDATAW () : new NOTIFYICONDATAA ();
- iconData.cbSize = NOTIFYICONDATA.sizeof;
- iconData.uID = id;
- iconData.hWnd = display.hwndMessage;
- iconData.hIcon = hIcon;
- iconData.uFlags = OS.NIF_ICON;
- OS.Shell_NotifyIcon (OS.NIM_MODIFY, iconData);
-}
-
-/**
- * Sets the receiver's tool tip to the argument, which
- * may be null indicating that no tool tip should be shown.
- *
- * @param toolTip the new tool tip (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setToolTip (ToolTip toolTip) {
- checkWidget ();
- ToolTip oldTip = this.toolTip, newTip = toolTip;
- if (oldTip != null) oldTip.item = null;
- this.toolTip = newTip;
- if (newTip != null) newTip.item = this;
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget ();
- toolTipText = string;
- NOTIFYICONDATA iconData = OS.IsUnicode ? (NOTIFYICONDATA) new NOTIFYICONDATAW () : new NOTIFYICONDATAA ();
- TCHAR buffer = new TCHAR (0, toolTipText == null ? "" : toolTipText, true);
- /*
- * Note that the size of the szTip field is different in version 5.0 of shell32.dll.
- */
- int length = OS.SHELL32_MAJOR < 5 ? 64 : 128;
- if (OS.IsUnicode) {
- char [] szTip = ((NOTIFYICONDATAW) iconData).szTip;
- length = Math.min (length - 1, buffer.length ());
- System.arraycopy (buffer.chars, 0, szTip, 0, length);
- } else {
- byte [] szTip = ((NOTIFYICONDATAA) iconData).szTip;
- length = Math.min (length - 1, buffer.length ());
- System.arraycopy (buffer.bytes, 0, szTip, 0, length);
- }
- iconData.cbSize = NOTIFYICONDATA.sizeof;
- iconData.uID = id;
- iconData.hWnd = display.hwndMessage;
- iconData.uFlags = OS.NIF_TIP;
- OS.Shell_NotifyIcon (OS.NIM_MODIFY, iconData);
-}
-
-/**
- * Makes the receiver visible if the argument is <code>true</code>,
- * and makes it invisible otherwise.
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- if (this.visible == visible) return;
- if (visible) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the show
- * event. If this happens, just return.
- */
- sendEvent (SWT.Show);
- if (isDisposed ()) return;
- }
- this.visible = visible;
- NOTIFYICONDATA iconData = OS.IsUnicode ? (NOTIFYICONDATA) new NOTIFYICONDATAW () : new NOTIFYICONDATAA ();
- iconData.cbSize = NOTIFYICONDATA.sizeof;
- iconData.uID = id;
- iconData.hWnd = display.hwndMessage;
- if (OS.SHELL32_MAJOR < 5) {
- if (visible) {
- iconData.uFlags = OS.NIF_MESSAGE;
- iconData.uCallbackMessage = Display.SWT_TRAYICONMSG;
- OS.Shell_NotifyIcon (OS.NIM_ADD, iconData);
- setImage (image);
- setToolTipText (toolTipText);
- } else {
- OS.Shell_NotifyIcon (OS.NIM_DELETE, iconData);
- }
- } else {
- iconData.uFlags = OS.NIF_STATE;
- iconData.dwState = visible ? 0 : OS.NIS_HIDDEN;
- iconData.dwStateMask = OS.NIS_HIDDEN;
- OS.Shell_NotifyIcon (OS.NIM_MODIFY, iconData);
- }
- if (!visible) sendEvent (SWT.Hide);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java
deleted file mode 100755
index 129bb847a7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java
+++ /dev/null
@@ -1,7809 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class provide a selectable user interface object
- * that displays a hierarchy of items and issues notification when an
- * item in the hierarchy is selected.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TreeItem</code>.
- * </p><p>
- * Style <code>VIRTUAL</code> is used to create a <code>Tree</code> whose
- * <code>TreeItem</code>s are to be populated by the client on an on-demand basis
- * instead of up-front. This can provide significant performance improvements for
- * trees that are very large or for which <code>TreeItem</code> population is
- * expensive (for example, retrieving values from an external source).
- * </p><p>
- * Here is an example of using a <code>Tree</code> with style <code>VIRTUAL</code>:
- * <code><pre>
- * final Tree tree = new Tree(parent, SWT.VIRTUAL | SWT.BORDER);
- * tree.setItemCount(20);
- * tree.addListener(SWT.SetData, new Listener() {
- * public void handleEvent(Event event) {
- * TreeItem item = (TreeItem)event.item;
- * TreeItem parentItem = item.getParentItem();
- * String text = null;
- * if (parentItem == null) {
- * text = "node " + tree.indexOf(item);
- * } else {
- * text = parentItem.getText() + " - " + parentItem.indexOf(item);
- * }
- * item.setText(text);
- * System.out.println(text);
- * item.setItemCount(10);
- * }
- * });
- * </pre></code>
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not normally make sense to add <code>Control</code> children to
- * it, or set a layout on it, unless implementing something like a cell
- * editor.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, VIRTUAL, NO_SCROLL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection, Collapse, Expand, SetData, MeasureItem, EraseItem, PaintItem</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles SINGLE and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Tree extends Composite {
- TreeItem [] items;
- TreeColumn [] columns;
- int columnCount;
- ImageList imageList, headerImageList;
- TreeItem currentItem;
- TreeColumn sortColumn;
- RECT focusRect;
- int /*long*/ hwndParent, hwndHeader, hAnchor, hInsert, hSelect;
- int lastID;
- int /*long*/ hFirstIndexOf, hLastIndexOf;
- int lastIndexOf, itemCount, sortDirection;
- boolean dragStarted, gestureCompleted, insertAfter, shrink, ignoreShrink;
- boolean ignoreSelect, ignoreExpand, ignoreDeselect, ignoreResize;
- boolean lockSelection, oldSelected, newSelected, ignoreColumnMove;
- boolean linesVisible, customDraw, printClient, painted, ignoreItemHeight;
- boolean ignoreCustomDraw, ignoreDrawForeground, ignoreDrawBackground, ignoreDrawFocus;
- boolean ignoreDrawSelection, ignoreDrawHot, ignoreFullSelection, explorerTheme;
- int scrollWidth, selectionForeground;
- int /*long*/ headerToolTipHandle, itemToolTipHandle;
- static final int INSET = 3;
- static final int GRID_WIDTH = 1;
- static final int SORT_WIDTH = 10;
- static final int HEADER_MARGIN = 12;
- static final int HEADER_EXTRA = 3;
- static final int INCREMENT = 5;
- static final int EXPLORER_EXTRA = 2;
- static final int DRAG_IMAGE_SIZE = 301;
- static final boolean EXPLORER_THEME = true;
- static final int /*long*/ TreeProc;
- static final TCHAR TreeClass = new TCHAR (0, OS.WC_TREEVIEW, true);
- static final int /*long*/ HeaderProc;
- static final TCHAR HeaderClass = new TCHAR (0, OS.WC_HEADER, true);
- static {
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, TreeClass, lpWndClass);
- TreeProc = lpWndClass.lpfnWndProc;
- OS.GetClassInfo (0, HeaderClass, lpWndClass);
- HeaderProc = lpWndClass.lpfnWndProc;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#CHECK
- * @see SWT#FULL_SELECTION
- * @see SWT#VIRTUAL
- * @see SWT#NO_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Tree (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- /*
- * Feature in Windows. Even when WS_HSCROLL or
- * WS_VSCROLL is not specified, Windows creates
- * trees and tables with scroll bars. The fix
- * is to set H_SCROLL and V_SCROLL.
- *
- * NOTE: This code appears on all platforms so that
- * applications have consistent scroll bar behavior.
- */
- if ((style & SWT.NO_SCROLL) == 0) {
- style |= SWT.H_SCROLL | SWT.V_SCROLL;
- }
- /*
- * Note: Windows only supports TVS_NOSCROLL and TVS_NOHSCROLL.
- */
- if ((style & SWT.H_SCROLL) != 0 && (style & SWT.V_SCROLL) == 0) {
- style |= SWT.V_SCROLL;
- }
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-
-void _addListener (int eventType, Listener listener) {
- super._addListener (eventType, listener);
- switch (eventType) {
- case SWT.DragDetect: {
- if ((state & DRAG_DETECT) != 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- bits &= ~OS.TVS_DISABLEDRAGDROP;
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- }
- break;
- }
- case SWT.MeasureItem:
- case SWT.EraseItem:
- case SWT.PaintItem: {
- customDraw = true;
- style |= SWT.DOUBLE_BUFFERED;
- if (isCustomToolTip ()) createItemToolTips ();
- OS.SendMessage (handle, OS.TVM_SETSCROLLTIME, 0, 0);
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if (eventType == SWT.MeasureItem) {
- /*
- * This code is intentionally commented.
- */
-// if (explorerTheme) {
-// int bits1 = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETEXTENDEDSTYLE, 0, 0);
-// bits1 &= ~OS.TVS_EX_AUTOHSCROLL;
-// OS.SendMessage (handle, OS.TVM_SETEXTENDEDSTYLE, 0, bits1);
-// }
- bits |= OS.TVS_NOHSCROLL;
- }
- /*
- * Feature in Windows. When the tree has the style
- * TVS_FULLROWSELECT, the background color for the
- * entire row is filled when an item is painted,
- * drawing on top of any custom drawing. The fix
- * is to clear TVS_FULLROWSELECT.
- */
- if ((style & SWT.FULL_SELECTION) != 0) {
- if (eventType != SWT.MeasureItem) {
- if (!explorerTheme) bits &= ~OS.TVS_FULLROWSELECT;
- }
- }
- if (bits != OS.GetWindowLong (handle, OS.GWL_STYLE)) {
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- OS.InvalidateRect (handle, null, true);
- /*
- * Bug in Windows. When TVS_NOHSCROLL is set after items
- * have been inserted into the tree, Windows shows the
- * scroll bar. The fix is to check for this case and
- * explicitly hide the scroll bar.
- */
- int count = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETCOUNT, 0, 0);
- if (count != 0 && (bits & OS.TVS_NOHSCROLL) != 0) {
- if (!OS.IsWinCE) OS.ShowScrollBar (handle, OS.SB_HORZ, false);
- }
- }
- break;
- }
- }
-}
-
-TreeItem _getItem (int /*long*/ hItem) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- tvItem.hItem = hItem;
- if (OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem) != 0) {
- return _getItem (tvItem.hItem, (int)/*64*/tvItem.lParam);
- }
- return null;
-}
-
-TreeItem _getItem (int /*long*/ hItem, int id) {
- if ((style & SWT.VIRTUAL) == 0) return items [id];
- return id != -1 ? items [id] : new TreeItem (this, SWT.NONE, -1, -1, hItem);
-}
-
-void _setBackgroundPixel (int newPixel) {
- int oldPixel = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETBKCOLOR, 0, 0);
- if (oldPixel != newPixel) {
- /*
- * Bug in Windows. When TVM_SETBKCOLOR is used more
- * than once to set the background color of a tree,
- * the background color of the lines and the plus/minus
- * does not change to the new color. The fix is to set
- * the background color to the default before setting
- * the new color.
- */
- if (oldPixel != -1) {
- OS.SendMessage (handle, OS.TVM_SETBKCOLOR, 0, -1);
- }
-
- /* Set the background color */
- OS.SendMessage (handle, OS.TVM_SETBKCOLOR, 0, newPixel);
-
- /*
- * Feature in Windows. When TVM_SETBKCOLOR is used to
- * set the background color of a tree, the plus/minus
- * animation draws badly. The fix is to clear the effect.
- */
- if (explorerTheme) {
- int bits2 = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETEXTENDEDSTYLE, 0, 0);
- if (newPixel == -1 && findImageControl () == null) {
- bits2 |= OS.TVS_EX_FADEINOUTEXPANDOS;
- } else {
- bits2 &= ~OS.TVS_EX_FADEINOUTEXPANDOS;
- }
- OS.SendMessage (handle, OS.TVM_SETEXTENDEDSTYLE, 0, bits2);
- }
-
- /* Set the checkbox image list */
- if ((style & SWT.CHECK) != 0) setCheckboxImageList ();
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * If the receiver has the <code>SWT.CHECK</code> style and the check selection changes,
- * the event object detail field contains the value <code>SWT.CHECK</code>.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * The item field of the event object is valid for default selection, but the detail field is not used.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an item in the receiver is expanded or collapsed
- * by sending it one of the messages defined in the <code>TreeListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TreeListener
- * @see #removeTreeListener
- */
-public void addTreeListener(TreeListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Expand, typedListener);
- addListener (SWT.Collapse, typedListener);
-}
-
-int /*long*/ borderHandle () {
- return hwndParent != 0 ? hwndParent : handle;
-}
-
-LRESULT CDDS_ITEMPOSTPAINT (NMTVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long*/ lParam) {
- if (ignoreCustomDraw) return null;
- if (nmcd.left == nmcd.right) return new LRESULT (OS.CDRF_DODEFAULT);
- int /*long*/ hDC = nmcd.hdc;
- OS.RestoreDC (hDC, -1);
- TreeItem item = getItem (nmcd);
-
- /*
- * Feature in Windows. When a new tree item is inserted
- * using TVM_INSERTITEM and the tree is using custom draw,
- * a NM_CUSTOMDRAW is sent before TVM_INSERTITEM returns
- * and before the item is added to the items array. The
- * fix is to check for null.
- *
- * NOTE: This only happens on XP with the version 6.00 of
- * COMCTL32.DLL,
- */
- if (item == null) return null;
-
- /*
- * Feature in Windows. Under certain circumstances, Windows
- * sends CDDS_ITEMPOSTPAINT for an empty rectangle. This is
- * not a problem providing that graphics do not occur outside
- * the rectangle. The fix is to test for the rectangle and
- * draw nothing.
- *
- * NOTE: This seems to happen when both I_IMAGECALLBACK
- * and LPSTR_TEXTCALLBACK are used at the same time with
- * TVM_SETITEM.
- */
- if (nmcd.left >= nmcd.right || nmcd.top >= nmcd.bottom) return null;
- if (!OS.IsWindowVisible (handle)) return null;
- if ((style & SWT.FULL_SELECTION) != 0 || findImageControl () != null || ignoreDrawSelection || explorerTheme) {
- OS.SetBkMode (hDC, OS.TRANSPARENT);
- }
- boolean selected = isItemSelected (nmcd);
- boolean hot = explorerTheme && (nmcd.uItemState & OS.CDIS_HOT) != 0;
- if (OS.IsWindowEnabled (handle)) {
- if (explorerTheme) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.TVS_TRACKSELECT) != 0) {
- if ((style & SWT.FULL_SELECTION) != 0 && (selected || hot)) {
- OS.SetTextColor (hDC, OS.GetSysColor (OS.COLOR_WINDOWTEXT));
- } else {
- OS.SetTextColor (hDC, getForegroundPixel ());
- }
- }
- }
- }
- int [] order = null;
- RECT clientRect = new RECT ();
- OS.GetClientRect (scrolledHandle (), clientRect);
- if (hwndHeader != 0) {
- OS.MapWindowPoints (hwndParent, handle, clientRect, 2);
- if (columnCount != 0) {
- order = new int [columnCount];
- OS.SendMessage (hwndHeader, OS.HDM_GETORDERARRAY, columnCount, order);
- }
- }
- int sortIndex = -1, clrSortBk = -1;
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- if (sortColumn != null && sortDirection != SWT.NONE) {
- if (findImageControl () == null) {
- sortIndex = indexOf (sortColumn);
- clrSortBk = getSortColumnPixel ();
- }
- }
- }
- int x = 0;
- Point size = null;
- for (int i=0; i<Math.max (1, columnCount); i++) {
- int index = order == null ? i : order [i], width = nmcd.right - nmcd.left;
- if (columnCount > 0 && hwndHeader != 0) {
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_WIDTH;
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, hdItem);
- width = hdItem.cxy;
- }
- if (i == 0) {
- if ((style & SWT.FULL_SELECTION) != 0) {
- boolean clear = !explorerTheme && !ignoreDrawSelection && findImageControl () == null;
- if (clear || (selected && !ignoreDrawSelection) || (hot && !ignoreDrawHot)) {
- boolean draw = true;
- RECT pClipRect = new RECT ();
- OS.SetRect (pClipRect, width, nmcd.top, nmcd.right, nmcd.bottom);
- if (explorerTheme) {
- if (hooks (SWT.EraseItem)) {
- RECT itemRect = item.getBounds (index, true, true, false, false, true, hDC);
- itemRect.left -= EXPLORER_EXTRA;
- itemRect.right += EXPLORER_EXTRA + 1;
- pClipRect.left = itemRect.left;
- pClipRect.right = itemRect.right;
- if (columnCount > 0 && hwndHeader != 0) {
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_WIDTH;
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, hdItem);
- pClipRect.right = Math.min (pClipRect.right, nmcd.left + hdItem.cxy);
- }
- }
- RECT pRect = new RECT ();
- OS.SetRect (pRect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
- if (columnCount > 0 && hwndHeader != 0) {
- int totalWidth = 0;
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_WIDTH;
- for (int j=0; j<columnCount; j++) {
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, j, hdItem);
- totalWidth += hdItem.cxy;
- }
- if (totalWidth > clientRect.right - clientRect.left) {
- pRect.left = 0;
- pRect.right = totalWidth;
- } else {
- pRect.left = clientRect.left;
- pRect.right = clientRect.right;
- }
- }
- draw = false;
- int /*long*/ hTheme = OS.OpenThemeData (handle, Display.TREEVIEW);
- int iStateId = selected ? OS.TREIS_SELECTED : OS.TREIS_HOT;
- if (OS.GetFocus () != handle && selected && !hot) iStateId = OS.TREIS_SELECTEDNOTFOCUS;
- OS.DrawThemeBackground (hTheme, hDC, OS.TVP_TREEITEM, iStateId, pRect, pClipRect);
- OS.CloseThemeData (hTheme);
- }
- if (draw) fillBackground (hDC, OS.GetBkColor (hDC), pClipRect);
- }
- }
- }
- if (x + width > clientRect.left) {
- RECT rect = new RECT (), backgroundRect = null;
- boolean drawItem = true, drawText = true, drawImage = true, drawBackground = false;
- if (i == 0) {
- drawItem = drawImage = drawText = false;
- if (findImageControl () != null) {
- if (explorerTheme) {
- if (OS.IsWindowEnabled (handle) && !hooks (SWT.EraseItem)) {
- Image image = null;
- if (index == 0) {
- image = item.image;
- } else {
- Image [] images = item.images;
- if (images != null) image = images [index];
- }
- if (image != null) {
- Rectangle bounds = image.getBounds ();
- if (size == null) size = getImageSize ();
- if (!ignoreDrawForeground) {
- GCData data = new GCData();
- data.device = display;
- GC gc = GC.win32_new (hDC, data);
- RECT iconRect = item.getBounds (index, false, true, false, false, true, hDC);
- gc.setClipping (iconRect.left, iconRect.top, iconRect.right - iconRect.left, iconRect.bottom - iconRect.top);
- gc.drawImage (image, 0, 0, bounds.width, bounds.height, iconRect.left, iconRect.top, size.x, size.y);
- OS.SelectClipRgn (hDC, 0);
- gc.dispose ();
- }
- }
- }
- } else {
- drawItem = drawText = drawBackground = true;
- rect = item.getBounds (index, true, false, false, false, true, hDC);
- if (linesVisible) {
- rect.right++;
- rect.bottom++;
- }
- }
- }
- if (selected && !ignoreDrawSelection && !ignoreDrawBackground) {
- if (!explorerTheme) fillBackground (hDC, OS.GetBkColor (hDC), rect);
- drawBackground = false;
- }
- backgroundRect = rect;
- if (hooks (SWT.EraseItem)) {
- drawItem = drawText = drawImage = true;
- rect = item.getBounds (index, true, true, false, false, true, hDC);
- if ((style & SWT.FULL_SELECTION) != 0) {
- backgroundRect = rect;
- } else {
- backgroundRect = item.getBounds (index, true, false, false, false, true, hDC);
- }
- }
- } else {
- selectionForeground = -1;
- ignoreDrawForeground = ignoreDrawBackground = ignoreDrawSelection = ignoreDrawFocus = ignoreDrawHot = false;
- OS.SetRect (rect, x, nmcd.top, x + width, nmcd.bottom);
- backgroundRect = rect;
- }
- int clrText = -1, clrTextBk = -1;
- int /*long*/ hFont = item.fontHandle (index);
- if (selectionForeground != -1) clrText = selectionForeground;
- if (OS.IsWindowEnabled (handle)) {
- boolean drawForeground = false;
- if (selected) {
- if (i != 0 && (style & SWT.FULL_SELECTION) == 0) {
- OS.SetTextColor (hDC, getForegroundPixel ());
- OS.SetBkColor (hDC, getBackgroundPixel ());
- drawForeground = drawBackground = true;
- }
- } else {
- drawForeground = drawBackground = true;
- }
- if (drawForeground) {
- clrText = item.cellForeground != null ? item.cellForeground [index] : -1;
- if (clrText == -1) clrText = item.foreground;
- }
- if (drawBackground) {
- clrTextBk = item.cellBackground != null ? item.cellBackground [index] : -1;
- if (clrTextBk == -1) clrTextBk = item.background;
- if (clrTextBk == -1 && index == sortIndex) clrTextBk = clrSortBk;
- }
- } else {
- if (clrTextBk == -1 && index == sortIndex) {
- drawBackground = true;
- clrTextBk = clrSortBk;
- }
- }
- if (explorerTheme) {
- if (selected || (nmcd.uItemState & OS.CDIS_HOT) != 0) {
- if ((style & SWT.FULL_SELECTION) != 0) {
- drawBackground = false;
- } else {
- if (i == 0) {
- drawBackground = false;
- if (!hooks (SWT.EraseItem)) drawText = false;
- }
- }
- }
- }
- if (drawItem) {
- if (i != 0) {
- if (hooks (SWT.MeasureItem)) {
- sendMeasureItemEvent (item, index, hDC);
- if (isDisposed () || item.isDisposed ()) break;
- }
- if (hooks (SWT.EraseItem)) {
- RECT cellRect = item.getBounds (index, true, true, true, true, true, hDC);
- int nSavedDC = OS.SaveDC (hDC);
- GCData data = new GCData ();
- data.device = display;
- data.foreground = OS.GetTextColor (hDC);
- data.background = OS.GetBkColor (hDC);
- if (!selected || (style & SWT.FULL_SELECTION) == 0) {
- if (clrText != -1) data.foreground = clrText;
- if (clrTextBk != -1) data.background = clrTextBk;
- }
- data.font = item.getFont (index);
- data.uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- GC gc = GC.win32_new (hDC, data);
- Event event = new Event ();
- event.item = item;
- event.index = index;
- event.gc = gc;
- event.detail |= SWT.FOREGROUND;
- if (clrTextBk != -1) event.detail |= SWT.BACKGROUND;
- if ((style & SWT.FULL_SELECTION) != 0) {
- if (hot) event.detail |= SWT.HOT;
- if (selected) event.detail |= SWT.SELECTED;
- if (!explorerTheme) {
- //if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) {
- if (OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0) == nmcd.dwItemSpec) {
- if (handle == OS.GetFocus ()) {
- int uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- if ((uiState & OS.UISF_HIDEFOCUS) == 0) event.detail |= SWT.FOCUSED;
- }
- }
- }
- }
- event.x = cellRect.left;
- event.y = cellRect.top;
- event.width = cellRect.right - cellRect.left;
- event.height = cellRect.bottom - cellRect.top;
- gc.setClipping (event.x, event.y, event.width, event.height);
- sendEvent (SWT.EraseItem, event);
- event.gc = null;
- int newTextClr = data.foreground;
- gc.dispose ();
- OS.RestoreDC (hDC, nSavedDC);
- if (isDisposed () || item.isDisposed ()) break;
- if (event.doit) {
- ignoreDrawForeground = (event.detail & SWT.FOREGROUND) == 0;
- ignoreDrawBackground = (event.detail & SWT.BACKGROUND) == 0;
- if ((style & SWT.FULL_SELECTION) != 0) {
- ignoreDrawSelection = (event.detail & SWT.SELECTED) == 0;
- ignoreDrawFocus = (event.detail & SWT.FOCUSED) == 0;
- ignoreDrawHot = (event.detail & SWT.HOT) == 0;
- }
- } else {
- ignoreDrawForeground = ignoreDrawBackground = ignoreDrawSelection = ignoreDrawFocus = ignoreDrawHot = true;
- }
- if (selected && ignoreDrawSelection) ignoreDrawHot = true;
- if ((style & SWT.FULL_SELECTION) != 0) {
- if (ignoreDrawSelection) ignoreFullSelection = true;
- if (!ignoreDrawSelection || !ignoreDrawHot) {
- if (!selected && !hot) {
- selectionForeground = OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT);
- } else {
- if (!explorerTheme) {
- drawBackground = true;
- ignoreDrawBackground = false;
- if ((handle == OS.GetFocus () || display.getHighContrast ()) && OS.IsWindowEnabled (handle)) {
- clrTextBk = OS.GetSysColor (OS.COLOR_HIGHLIGHT);
- } else {
- clrTextBk = OS.GetSysColor (OS.COLOR_3DFACE);
- }
- if (!ignoreFullSelection && index == columnCount - 1) {
- RECT selectionRect = new RECT ();
- OS.SetRect (selectionRect, backgroundRect.left, backgroundRect.top, nmcd.right, backgroundRect.bottom);
- backgroundRect = selectionRect;
- }
- } else {
- RECT pRect = new RECT ();
- OS.SetRect (pRect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
- if (columnCount > 0 && hwndHeader != 0) {
- int totalWidth = 0;
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_WIDTH;
- for (int j=0; j<columnCount; j++) {
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, j, hdItem);
- totalWidth += hdItem.cxy;
- }
- if (totalWidth > clientRect.right - clientRect.left) {
- pRect.left = 0;
- pRect.right = totalWidth;
- } else {
- pRect.left = clientRect.left;
- pRect.right = clientRect.right;
- }
- if (index == columnCount - 1) {
- RECT selectionRect = new RECT ();
- OS.SetRect (selectionRect, backgroundRect.left, backgroundRect.top, pRect.right, backgroundRect.bottom);
- backgroundRect = selectionRect;
- }
- }
- int /*long*/ hTheme = OS.OpenThemeData (handle, Display.TREEVIEW);
- int iStateId = selected ? OS.TREIS_SELECTED : OS.TREIS_HOT;
- if (OS.GetFocus () != handle && selected && !hot) iStateId = OS.TREIS_SELECTEDNOTFOCUS;
- OS.DrawThemeBackground (hTheme, hDC, OS.TVP_TREEITEM, iStateId, pRect, backgroundRect);
- OS.CloseThemeData (hTheme);
- }
- }
- } else {
- if (selected) {
- selectionForeground = newTextClr;
- if (!explorerTheme) {
- if (clrTextBk == -1 && OS.IsWindowEnabled (handle)) {
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- clrTextBk = control.getBackgroundPixel ();
- }
- }
- }
- }
- }
- }
- if (selectionForeground != -1) clrText = selectionForeground;
- }
- if (!ignoreDrawBackground) {
- if (clrTextBk != -1) {
- if (drawBackground) fillBackground (hDC, clrTextBk, backgroundRect);
- } else {
- Control control = findImageControl ();
- if (control != null) {
- if (i == 0) {
- int right = Math.min (rect.right, width);
- OS.SetRect (rect, rect.left, rect.top, right, rect.bottom);
- if (drawBackground) fillImageBackground (hDC, control, rect);
- } else {
- if (drawBackground) fillImageBackground (hDC, control, rect);
- }
- }
- }
- }
- rect.left += INSET - 1;
- if (drawImage) {
- Image image = null;
- if (index == 0) {
- image = item.image;
- } else {
- Image [] images = item.images;
- if (images != null) image = images [index];
- }
- int inset = i != 0 ? INSET : 0;
- int offset = i != 0 ? INSET : INSET + 2;
- if (image != null) {
- Rectangle bounds = image.getBounds ();
- if (size == null) size = getImageSize ();
- if (!ignoreDrawForeground) {
- //int y1 = rect.top + (index == 0 ? (getItemHeight () - size.y) / 2 : 0);
- int y1 = rect.top;
- int x1 = Math.max (rect.left, rect.left - inset + 1);
- GCData data = new GCData();
- data.device = display;
- GC gc = GC.win32_new (hDC, data);
- gc.setClipping (x1, rect.top, rect.right - x1, rect.bottom - rect.top);
- gc.drawImage (image, 0, 0, bounds.width, bounds.height, x1, y1, size.x, size.y);
- OS.SelectClipRgn (hDC, 0);
- gc.dispose ();
- }
- OS.SetRect (rect, rect.left + size.x + offset, rect.top, rect.right - inset, rect.bottom);
- } else {
- if (i == 0) {
- if (OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0) != 0) {
- if (size == null) size = getImageSize ();
- rect.left = Math.min (rect.left + size.x + offset, rect.right);
- }
- } else {
- OS.SetRect (rect, rect.left + offset, rect.top, rect.right - inset, rect.bottom);
- }
- }
- }
- if (drawText) {
- /*
- * Bug in Windows. When DrawText() is used with DT_VCENTER
- * and DT_ENDELLIPSIS, the ellipsis can draw outside of the
- * rectangle when the rectangle is empty. The fix is avoid
- * all text drawing for empty rectangles.
- */
- if (rect.left < rect.right) {
- String string = null;
- if (index == 0) {
- string = item.text;
- } else {
- String [] strings = item.strings;
- if (strings != null) string = strings [index];
- }
- if (string != null) {
- if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
- if (clrText != -1) clrText = OS.SetTextColor (hDC, clrText);
- if (clrTextBk != -1) clrTextBk = OS.SetBkColor (hDC, clrTextBk);
- int flags = OS.DT_NOPREFIX | OS.DT_SINGLELINE | OS.DT_VCENTER;
- if (i != 0) flags |= OS.DT_ENDELLIPSIS;
- TreeColumn column = columns != null ? columns [index] : null;
- if (column != null) {
- if ((column.style & SWT.CENTER) != 0) flags |= OS.DT_CENTER;
- if ((column.style & SWT.RIGHT) != 0) flags |= OS.DT_RIGHT;
- }
- TCHAR buffer = new TCHAR (getCodePage (), string, false);
- if (!ignoreDrawForeground) OS.DrawText (hDC, buffer, buffer.length (), rect, flags);
- OS.DrawText (hDC, buffer, buffer.length (), rect, flags | OS.DT_CALCRECT);
- if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
- if (clrText != -1) clrText = OS.SetTextColor (hDC, clrText);
- if (clrTextBk != -1) clrTextBk = OS.SetBkColor (hDC, clrTextBk);
- }
- }
- }
- }
- if (selectionForeground != -1) clrText = selectionForeground;
- if (hooks (SWT.PaintItem)) {
- RECT itemRect = item.getBounds (index, true, true, false, false, false, hDC);
- int nSavedDC = OS.SaveDC (hDC);
- GCData data = new GCData ();
- data.device = display;
- data.font = item.getFont (index);
- data.foreground = OS.GetTextColor (hDC);
- data.background = OS.GetBkColor (hDC);
- if (selected && (style & SWT.FULL_SELECTION) != 0) {
- if (selectionForeground != -1) data.foreground = selectionForeground;
- } else {
- if (clrText != -1) data.foreground = clrText;
- if (clrTextBk != -1) data.background = clrTextBk;
- }
- data.uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- GC gc = GC.win32_new (hDC, data);
- Event event = new Event ();
- event.item = item;
- event.index = index;
- event.gc = gc;
- event.detail |= SWT.FOREGROUND;
- if (clrTextBk != -1) event.detail |= SWT.BACKGROUND;
- if (hot) event.detail |= SWT.HOT;
- if (selected && (i == 0 /*nmcd.iSubItem == 0*/ || (style & SWT.FULL_SELECTION) != 0)) {
- event.detail |= SWT.SELECTED;
- }
- if (!explorerTheme) {
- //if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) {
- if (OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0) == nmcd.dwItemSpec) {
- if (i == 0 /*nmcd.iSubItem == 0*/ || (style & SWT.FULL_SELECTION) != 0) {
- if (handle == OS.GetFocus ()) {
- int uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- if ((uiState & OS.UISF_HIDEFOCUS) == 0) event.detail |= SWT.FOCUSED;
- }
- }
- }
- }
- event.x = itemRect.left;
- event.y = itemRect.top;
- event.width = itemRect.right - itemRect.left;
- event.height = itemRect.bottom - itemRect.top;
- RECT cellRect = item.getBounds (index, true, true, true, true, true, hDC);
- int cellWidth = cellRect.right - cellRect.left;
- int cellHeight = cellRect.bottom - cellRect.top;
- gc.setClipping (cellRect.left, cellRect.top, cellWidth, cellHeight);
- sendEvent (SWT.PaintItem, event);
- if (data.focusDrawn) focusRect = null;
- event.gc = null;
- gc.dispose ();
- OS.RestoreDC (hDC, nSavedDC);
- if (isDisposed () || item.isDisposed ()) break;
- }
- }
- x += width;
- if (x > clientRect.right) break;
- }
- if (linesVisible) {
- if ((style & SWT.FULL_SELECTION) != 0) {
- if (columnCount != 0) {
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_WIDTH;
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, 0, hdItem);
- RECT rect = new RECT ();
- OS.SetRect (rect, nmcd.left + hdItem.cxy, nmcd.top, nmcd.right, nmcd.bottom);
- OS.DrawEdge (hDC, rect, OS.BDR_SUNKENINNER, OS.BF_BOTTOM);
- }
- }
- RECT rect = new RECT ();
- OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
- OS.DrawEdge (hDC, rect, OS.BDR_SUNKENINNER, OS.BF_BOTTOM);
- }
- if (!ignoreDrawFocus && focusRect != null) {
- OS.DrawFocusRect (hDC, focusRect);
- focusRect = null;
- } else {
- if (!explorerTheme) {
- if (handle == OS.GetFocus ()) {
- int uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- if ((uiState & OS.UISF_HIDEFOCUS) == 0) {
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem == item.handle) {
- if (!ignoreDrawFocus && findImageControl () != null) {
- if ((style & SWT.FULL_SELECTION) != 0) {
- RECT focusRect = new RECT ();
- OS.SetRect (focusRect, 0, nmcd.top, clientRect.right + 1, nmcd.bottom);
- OS.DrawFocusRect (hDC, focusRect);
- } else {
- int index = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0);
- RECT focusRect = item.getBounds (index, true, false, false, false, false, hDC);
- RECT clipRect = item.getBounds (index, true, false, false, false, true, hDC);
- OS.IntersectClipRect (hDC, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
- OS.DrawFocusRect (hDC, focusRect);
- OS.SelectClipRgn (hDC, 0);
- }
- }
- }
- }
- }
- }
- }
- return new LRESULT (OS.CDRF_DODEFAULT);
-}
-
-LRESULT CDDS_ITEMPREPAINT (NMTVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Even when custom draw is being ignored, the font needs
- * to be selected into the HDC so that the item bounds are
- * measured correctly.
- */
- TreeItem item = getItem (nmcd);
- /*
- * Feature in Windows. When a new tree item is inserted
- * using TVM_INSERTITEM and the tree is using custom draw,
- * a NM_CUSTOMDRAW is sent before TVM_INSERTITEM returns
- * and before the item is added to the items array. The
- * fix is to check for null.
- *
- * NOTE: This only happens on XP with the version 6.00 of
- * COMCTL32.DLL,
- */
- if (item == null) return null;
- int /*long*/ hDC = nmcd.hdc;
- int index = hwndHeader != 0 ? (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0) : 0;
- int /*long*/ hFont = item.fontHandle (index);
- if (hFont != -1) OS.SelectObject (hDC, hFont);
- if (ignoreCustomDraw || nmcd.left == nmcd.right) {
- return new LRESULT (hFont == -1 ? OS.CDRF_DODEFAULT : OS.CDRF_NEWFONT);
- }
- RECT clipRect = null;
- if (columnCount != 0) {
- boolean clip = !printClient;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- clip = true;
- }
- if (clip) {
- clipRect = new RECT ();
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_WIDTH;
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, hdItem);
- OS.SetRect (clipRect, nmcd.left, nmcd.top, nmcd.left + hdItem.cxy, nmcd.bottom);
- }
- }
- int clrText = -1, clrTextBk = -1;
- if (OS.IsWindowEnabled (handle)) {
- clrText = item.cellForeground != null ? item.cellForeground [index] : -1;
- if (clrText == -1) clrText = item.foreground;
- clrTextBk = item.cellBackground != null ? item.cellBackground [index] : -1;
- if (clrTextBk == -1) clrTextBk = item.background;
- }
- int clrSortBk = -1;
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- if (sortColumn != null && sortDirection != SWT.NONE) {
- if (findImageControl () == null) {
- if (indexOf (sortColumn) == index) {
- clrSortBk = getSortColumnPixel ();
- if (clrTextBk == -1) clrTextBk = clrSortBk;
- }
- }
- }
- }
- boolean selected = isItemSelected (nmcd);
- boolean hot = explorerTheme && (nmcd.uItemState & OS.CDIS_HOT) != 0;
- boolean focused = explorerTheme && (nmcd.uItemState & OS.CDIS_FOCUS) != 0;
- if (OS.IsWindowVisible (handle) && nmcd.left < nmcd.right && nmcd.top < nmcd.bottom) {
- if (hFont != -1) OS.SelectObject (hDC, hFont);
- if (linesVisible) {
- RECT rect = new RECT ();
- OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
- OS.DrawEdge (hDC, rect, OS.BDR_SUNKENINNER, OS.BF_BOTTOM);
- }
- //TODO - BUG - measure and erase sent when first column is clipped
- Event measureEvent = null;
- if (hooks (SWT.MeasureItem)) {
- measureEvent = sendMeasureItemEvent (item, index, hDC);
- if (isDisposed () || item.isDisposed ()) return null;
- }
- selectionForeground = -1;
- ignoreDrawForeground = ignoreDrawBackground = ignoreDrawSelection = ignoreDrawFocus = ignoreDrawHot = ignoreFullSelection = false;
- if (hooks (SWT.EraseItem)) {
- RECT rect = new RECT ();
- OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
- RECT cellRect = item.getBounds (index, true, true, true, true, true, hDC);
- if (clrSortBk != -1) {
- drawBackground (hDC, cellRect, clrSortBk);
- } else {
- if (OS.IsWindowEnabled (handle) || findImageControl () != null) {
- drawBackground (hDC, rect);
- } else {
- fillBackground (hDC, OS.GetBkColor (hDC), rect);
- }
- }
- int nSavedDC = OS.SaveDC (hDC);
- GCData data = new GCData ();
- data.device = display;
- if (selected && explorerTheme) {
- data.foreground = OS.GetSysColor (OS.COLOR_WINDOWTEXT);
- } else {
- data.foreground = OS.GetTextColor (hDC);
- }
- data.background = OS.GetBkColor (hDC);
- if (!selected) {
- if (clrText != -1) data.foreground = clrText;
- if (clrTextBk != -1) data.background = clrTextBk;
- }
- data.uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- data.font = item.getFont (index);
- GC gc = GC.win32_new (hDC, data);
- Event event = new Event ();
- event.index = index;
- event.item = item;
- event.gc = gc;
- event.detail |= SWT.FOREGROUND;
- if (clrTextBk != -1) event.detail |= SWT.BACKGROUND;
- if (hot) event.detail |= SWT.HOT;
- if (selected) event.detail |= SWT.SELECTED;
- if (!explorerTheme) {
- //if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) {
- if (OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0) == nmcd.dwItemSpec) {
- if (handle == OS.GetFocus ()) {
- int uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- if ((uiState & OS.UISF_HIDEFOCUS) == 0) {
- focused = true;
- event.detail |= SWT.FOCUSED;
- }
- }
- }
- }
- event.x = cellRect.left;
- event.y = cellRect.top;
- event.width = cellRect.right - cellRect.left;
- event.height = cellRect.bottom - cellRect.top;
- gc.setClipping (event.x, event.y, event.width, event.height);
- sendEvent (SWT.EraseItem, event);
- event.gc = null;
- int newTextClr = data.foreground;
- gc.dispose ();
- OS.RestoreDC (hDC, nSavedDC);
- if (isDisposed () || item.isDisposed ()) return null;
- if (event.doit) {
- ignoreDrawForeground = (event.detail & SWT.FOREGROUND) == 0;
- ignoreDrawBackground = (event.detail & SWT.BACKGROUND) == 0;
- ignoreDrawSelection = (event.detail & SWT.SELECTED) == 0;
- ignoreDrawFocus = (event.detail & SWT.FOCUSED) == 0;
- ignoreDrawHot = (event.detail & SWT.HOT) == 0;
- } else {
- ignoreDrawForeground = ignoreDrawBackground = ignoreDrawSelection = ignoreDrawFocus = ignoreDrawHot = true;
- }
- if (selected && ignoreDrawSelection) ignoreDrawHot = true;
- if (!ignoreDrawBackground && clrTextBk != -1) {
- boolean draw = !selected && !hot;
- if (!explorerTheme && selected) draw = !ignoreDrawSelection;
- if (draw) {
- if (columnCount == 0) {
- if ((style & SWT.FULL_SELECTION) != 0) {
- fillBackground (hDC, clrTextBk, rect);
- } else {
- RECT textRect = item.getBounds (index, true, false, false, false, true, hDC);
- if (measureEvent != null) {
- textRect.right = Math.min (cellRect.right, measureEvent.x + measureEvent.width);
- }
- fillBackground (hDC, clrTextBk, textRect);
- }
- } else {
- fillBackground (hDC, clrTextBk, cellRect);
- }
- }
- }
- if (ignoreDrawSelection) ignoreFullSelection = true;
- if (!ignoreDrawSelection || !ignoreDrawHot) {
- if (!selected && !hot) {
- selectionForeground = clrText = OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT);
- }
- if (explorerTheme) {
- if ((style & SWT.FULL_SELECTION) == 0) {
- RECT pRect = item.getBounds (index, true, true, false, false, false, hDC);
- RECT pClipRect = item.getBounds (index, true, true, true, false, true, hDC);
- if (measureEvent != null) {
- pRect.right = Math.min (pClipRect.right, measureEvent.x + measureEvent.width);
- } else {
- pRect.right += EXPLORER_EXTRA;
- pClipRect.right += EXPLORER_EXTRA;
- }
- pRect.left -= EXPLORER_EXTRA;
- pClipRect.left -= EXPLORER_EXTRA;
- int /*long*/ hTheme = OS.OpenThemeData (handle, Display.TREEVIEW);
- int iStateId = selected ? OS.TREIS_SELECTED : OS.TREIS_HOT;
- if (OS.GetFocus () != handle && selected && !hot) iStateId = OS.TREIS_SELECTEDNOTFOCUS;
- OS.DrawThemeBackground (hTheme, hDC, OS.TVP_TREEITEM, iStateId, pRect, pClipRect);
- OS.CloseThemeData (hTheme);
- }
- } else {
- /*
- * Feature in Windows. When the tree has the style
- * TVS_FULLROWSELECT, the background color for the
- * entire row is filled when an item is painted,
- * drawing on top of any custom drawing. The fix
- * is to emulate TVS_FULLROWSELECT.
- */
- if ((style & SWT.FULL_SELECTION) != 0) {
- if ((style & SWT.FULL_SELECTION) != 0 && columnCount == 0) {
- fillBackground (hDC, OS.GetBkColor (hDC), rect);
- } else {
- fillBackground (hDC, OS.GetBkColor (hDC), cellRect);
- }
- } else {
- RECT textRect = item.getBounds (index, true, false, false, false, true, hDC);
- if (measureEvent != null) {
- textRect.right = Math.min (cellRect.right, measureEvent.x + measureEvent.width);
- }
- fillBackground (hDC, OS.GetBkColor (hDC), textRect);
- }
- }
- } else {
- if (selected || hot) {
- selectionForeground = clrText = newTextClr;
- ignoreDrawSelection = ignoreDrawHot = true;
- }
- if (explorerTheme) {
- nmcd.uItemState |= OS.CDIS_DISABLED;
- /*
- * Feature in Windows. On Vista only, when the text
- * color is unchanged and an item is asked to draw
- * disabled, it uses the disabled color. The fix is
- * to modify the color so that is it no longer equal.
- */
- int newColor = clrText == -1 ? getForegroundPixel () : clrText;
- if (nmcd.clrText == newColor) {
- nmcd.clrText |= 0x20000000;
- if (nmcd.clrText == newColor) nmcd.clrText &= ~0x20000000;
- } else {
- nmcd.clrText = newColor;
- }
- OS.MoveMemory (lParam, nmcd, NMTVCUSTOMDRAW.sizeof);
- }
- }
- if (focused && !ignoreDrawFocus && (style & SWT.FULL_SELECTION) == 0) {
- RECT textRect = item.getBounds (index, true, explorerTheme, false, false, true, hDC);
- if (measureEvent != null) {
- textRect.right = Math.min (cellRect.right, measureEvent.x + measureEvent.width);
- }
- nmcd.uItemState &= ~OS.CDIS_FOCUS;
- OS.MoveMemory (lParam, nmcd, NMTVCUSTOMDRAW.sizeof);
- focusRect = textRect;
- }
- if (explorerTheme) {
- if (selected || (hot && ignoreDrawHot)) nmcd.uItemState &= ~OS.CDIS_HOT;
- OS.MoveMemory (lParam, nmcd, NMTVCUSTOMDRAW.sizeof);
- }
- RECT itemRect = item.getBounds (index, true, true, false, false, false, hDC);
- OS.SaveDC (hDC);
- OS.SelectClipRgn (hDC, 0);
- if (explorerTheme) {
- itemRect.left -= EXPLORER_EXTRA;
- itemRect.right += EXPLORER_EXTRA;
- }
- //TODO - bug in Windows selection or SWT itemRect
- /*if (selected)*/ itemRect.right++;
- if (linesVisible) itemRect.bottom++;
- if (clipRect != null) {
- OS.IntersectClipRect (hDC, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
- }
- OS.ExcludeClipRect (hDC, itemRect.left, itemRect.top, itemRect.right, itemRect.bottom);
- return new LRESULT (OS.CDRF_DODEFAULT | OS.CDRF_NOTIFYPOSTPAINT);
- }
- /*
- * Feature in Windows. When the tree has the style
- * TVS_FULLROWSELECT, the background color for the
- * entire row is filled when an item is painted,
- * drawing on top of any custom drawing. The fix
- * is to emulate TVS_FULLROWSELECT.
- */
- if ((style & SWT.FULL_SELECTION) != 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.TVS_FULLROWSELECT) == 0) {
- RECT rect = new RECT ();
- OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
- if (selected) {
- fillBackground (hDC, OS.GetBkColor (hDC), rect);
- } else {
- if (OS.IsWindowEnabled (handle)) drawBackground (hDC, rect);
- }
- nmcd.uItemState &= ~OS.CDIS_FOCUS;
- OS.MoveMemory (lParam, nmcd, NMTVCUSTOMDRAW.sizeof);
- }
- }
- }
- LRESULT result = null;
- if (clrText == -1 && clrTextBk == -1 && hFont == -1) {
- result = new LRESULT (OS.CDRF_DODEFAULT | OS.CDRF_NOTIFYPOSTPAINT);
- } else {
- result = new LRESULT (OS.CDRF_NEWFONT | OS.CDRF_NOTIFYPOSTPAINT);
- if (hFont != -1) OS.SelectObject (hDC, hFont);
- if (OS.IsWindowEnabled (handle) && OS.IsWindowVisible (handle)) {
- /*
- * Feature in Windows. Windows does not fill the entire cell
- * with the background color when TVS_FULLROWSELECT is not set.
- * The fix is to fill the cell with the background color.
- */
- if (clrTextBk != -1) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.TVS_FULLROWSELECT) == 0) {
- if (columnCount != 0 && hwndHeader != 0) {
- RECT rect = new RECT ();
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_WIDTH;
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, hdItem);
- OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.left + hdItem.cxy, nmcd.bottom);
- if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
- RECT itemRect = new RECT ();
- if (OS.TreeView_GetItemRect (handle, item.handle, itemRect, true)) {
- rect.left = Math.min (itemRect.left, rect.right);
- }
- }
- if ((style & SWT.FULL_SELECTION) != 0) {
- if (!selected) fillBackground (hDC, clrTextBk, rect);
- } else {
- if (explorerTheme) {
- if (!selected && !hot) fillBackground (hDC, clrTextBk, rect);
- } else {
- fillBackground (hDC, clrTextBk, rect);
- }
- }
- } else {
- if ((style & SWT.FULL_SELECTION) != 0) {
- RECT rect = new RECT ();
- OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
- if (!selected) fillBackground (hDC, clrTextBk, rect);
- }
- }
- }
- }
- if (!selected) {
- nmcd.clrText = clrText == -1 ? getForegroundPixel () : clrText;
- nmcd.clrTextBk = clrTextBk == -1 ? getBackgroundPixel () : clrTextBk;
- OS.MoveMemory (lParam, nmcd, NMTVCUSTOMDRAW.sizeof);
- }
- }
- }
- if (OS.IsWindowEnabled (handle)) {
- /*
- * On Vista only, when an item is asked to draw disabled,
- * the background of the text is not filled with the
- * background color of the tree. This is true for both
- * regular and full selection trees. In order to draw a
- * background image, mark the item as disabled using
- * CDIS_DISABLED (when not selected) and set the text
- * to the regular text color to avoid drawing disabled.
- */
- if (explorerTheme) {
- if (findImageControl () != null) {
- if (!selected && (nmcd.uItemState & (OS.CDIS_HOT | OS.CDIS_SELECTED)) == 0) {
- nmcd.uItemState |= OS.CDIS_DISABLED;
- /*
- * Feature in Windows. On Vista only, when the text
- * color is unchanged and an item is asked to draw
- * disabled, it uses the disabled color. The fix is
- * to modify the color so it is no longer equal.
- */
- int newColor = clrText == -1 ? getForegroundPixel () : clrText;
- if (nmcd.clrText == newColor) {
- nmcd.clrText |= 0x20000000;
- if (nmcd.clrText == newColor) nmcd.clrText &= ~0x20000000;
- } else {
- nmcd.clrText = newColor;
- }
- OS.MoveMemory (lParam, nmcd, NMTVCUSTOMDRAW.sizeof);
- if (clrTextBk != -1) {
- if ((style & SWT.FULL_SELECTION) != 0) {
- RECT rect = new RECT ();
- if (columnCount != 0) {
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_WIDTH;
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, hdItem);
- OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.left + hdItem.cxy, nmcd.bottom);
- } else {
- OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
- }
- fillBackground (hDC, clrTextBk, rect);
- } else {
- RECT textRect = item.getBounds (index, true, false, true, false, true, hDC);
- fillBackground (hDC, clrTextBk, textRect);
- }
- }
- }
- }
- }
- } else {
- /*
- * Feature in Windows. When the tree is disabled, it draws
- * with a gray background over the sort column. The fix is
- * to fill the background with the sort column color.
- */
- if (clrSortBk != -1) {
- RECT rect = new RECT ();
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_WIDTH;
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, hdItem);
- OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.left + hdItem.cxy, nmcd.bottom);
- fillBackground (hDC, clrSortBk, rect);
- }
- }
- OS.SaveDC (hDC);
- if (clipRect != null) {
- int /*long*/ hRgn = OS.CreateRectRgn (clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
- POINT lpPoint = new POINT ();
- OS.GetWindowOrgEx (hDC, lpPoint);
- OS.OffsetRgn (hRgn, -lpPoint.x, -lpPoint.y);
- OS.SelectClipRgn (hDC, hRgn);
- OS.DeleteObject (hRgn);
- }
- return result;
-}
-
-LRESULT CDDS_POSTPAINT (NMTVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long*/ lParam) {
- if (ignoreCustomDraw) return null;
- if (OS.IsWindowVisible (handle)) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- if (sortColumn != null && sortDirection != SWT.NONE) {
- if (findImageControl () == null) {
- int index = indexOf (sortColumn);
- if (index != -1) {
- int top = nmcd.top;
- /*
- * Bug in Windows. For some reason, during a collapse,
- * when TVM_GETNEXTITEM is sent with TVGN_LASTVISIBLE
- * and the collapse causes the item being collapsed
- * to become the last visible item in the tree, the
- * message takes a long time to process. In order for
- * the slowness to happen, the children of the item
- * must have children. Times of up to 11 seconds have
- * been observed with 23 children, each having one
- * child. The fix is to use the bottom partially
- * visible item rather than the last possible item
- * that could be visible.
- *
- * NOTE: This problem only happens on Vista during
- * WM_NOTIFY with NM_CUSTOMDRAW and CDDS_POSTPAINT.
- */
- int /*long*/ hItem = 0;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- hItem = getBottomItem ();
- } else {
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_LASTVISIBLE, 0);
- }
- if (hItem != 0) {
- RECT rect = new RECT ();
- if (OS.TreeView_GetItemRect (handle, hItem, rect, false)) {
- top = rect.bottom;
- }
- }
- RECT rect = new RECT ();
- OS.SetRect (rect, nmcd.left, top, nmcd.right, nmcd.bottom);
- RECT headerRect = new RECT ();
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect);
- rect.left = headerRect.left;
- rect.right = headerRect.right;
- fillBackground (nmcd.hdc, getSortColumnPixel (), rect);
- }
- }
- }
- }
- if (linesVisible) {
- int /*long*/ hDC = nmcd.hdc;
- if (hwndHeader != 0) {
- int x = 0;
- RECT rect = new RECT ();
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_WIDTH;
- for (int i=0; i<columnCount; i++) {
- int index = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, i, 0);
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, hdItem);
- OS.SetRect (rect, x, nmcd.top, x + hdItem.cxy, nmcd.bottom);
- OS.DrawEdge (hDC, rect, OS.BDR_SUNKENINNER, OS.BF_RIGHT);
- x += hdItem.cxy;
- }
- }
- int height = 0;
- RECT rect = new RECT ();
- /*
- * Bug in Windows. For some reason, during a collapse,
- * when TVM_GETNEXTITEM is sent with TVGN_LASTVISIBLE
- * and the collapse causes the item being collapsed
- * to become the last visible item in the tree, the
- * message takes a long time to process. In order for
- * the slowness to happen, the children of the item
- * must have children. Times of up to 11 seconds have
- * been observed with 23 children, each having one
- * child. The fix is to use the bottom partially
- * visible item rather than the last possible item
- * that could be visible.
- *
- * NOTE: This problem only happens on Vista during
- * WM_NOTIFY with NM_CUSTOMDRAW and CDDS_POSTPAINT.
- */
- int /*long*/ hItem = 0;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- hItem = getBottomItem ();
- } else {
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_LASTVISIBLE, 0);
- }
- if (hItem != 0) {
- if (OS.TreeView_GetItemRect (handle, hItem, rect, false)) {
- height = rect.bottom - rect.top;
- }
- }
- if (height == 0) {
- height = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETITEMHEIGHT, 0, 0);
- OS.GetClientRect (handle, rect);
- OS.SetRect (rect, rect.left, rect.top, rect.right, rect.top + height);
- OS.DrawEdge (hDC, rect, OS.BDR_SUNKENINNER, OS.BF_BOTTOM);
- }
- while (rect.bottom < nmcd.bottom) {
- int top = rect.top + height;
- OS.SetRect (rect, rect.left, top, rect.right, top + height);
- OS.DrawEdge (hDC, rect, OS.BDR_SUNKENINNER, OS.BF_BOTTOM);
- }
- }
- }
- return new LRESULT (OS.CDRF_DODEFAULT);
-}
-
-LRESULT CDDS_PREPAINT (NMTVCUSTOMDRAW nmcd, int /*long*/ wParam, int /*long*/ lParam) {
- if (explorerTheme) {
- if ((OS.IsWindowEnabled (handle) && hooks (SWT.EraseItem)) || findImageControl () != null) {
- RECT rect = new RECT ();
- OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
- drawBackground (nmcd.hdc, rect);
- }
- }
- return new LRESULT (OS.CDRF_NOTIFYITEMDRAW | OS.CDRF_NOTIFYPOSTPAINT);
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (handle == 0) return 0;
- if (hwndParent != 0 && hwnd == hwndParent) {
- return OS.DefWindowProc (hwnd, msg, wParam, lParam);
- }
- if (hwndHeader != 0 && hwnd == hwndHeader) {
- return OS.CallWindowProc (HeaderProc, hwnd, msg, wParam, lParam);
- }
- switch (msg) {
- case OS.WM_SETFOCUS: {
- /*
- * Feature in Windows. When a tree control processes WM_SETFOCUS,
- * if no item is selected, the first item in the tree is selected.
- * This is unexpected and might clear the previous selection.
- * The fix is to detect that there is no selection and set it to
- * the first visible item in the tree. If the item was not selected,
- * only the focus is assigned.
- */
- if ((style & SWT.SINGLE) != 0) break;
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem == 0) {
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0);
- if (hItem != 0) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- hSelect = hItem;
- ignoreDeselect = ignoreSelect = lockSelection = true;
- OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, hItem);
- ignoreDeselect = ignoreSelect = lockSelection = false;
- hSelect = 0;
- if ((tvItem.state & OS.TVIS_SELECTED) == 0) {
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- }
- }
- break;
- }
- }
- int /*long*/ hItem = 0;
- boolean redraw = false;
- switch (msg) {
- /* Keyboard messages */
- case OS.WM_KEYDOWN:
- if (wParam == OS.VK_CONTROL || wParam == OS.VK_SHIFT) break;
- //FALL THROUGH
- case OS.WM_CHAR:
- case OS.WM_IME_CHAR:
- case OS.WM_KEYUP:
- case OS.WM_SYSCHAR:
- case OS.WM_SYSKEYDOWN:
- case OS.WM_SYSKEYUP:
- //FALL THROUGH
-
- /* Scroll messages */
- case OS.WM_HSCROLL:
- case OS.WM_VSCROLL:
- //FALL THROUGH
-
- /* Resize messages */
- case OS.WM_SIZE:
- redraw = findImageControl () != null && getDrawing () && OS.IsWindowVisible (handle);
- if (redraw) OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- //FALL THROUGH
-
- /* Mouse messages */
- case OS.WM_LBUTTONDBLCLK:
- case OS.WM_LBUTTONDOWN:
- case OS.WM_LBUTTONUP:
- case OS.WM_MBUTTONDBLCLK:
- case OS.WM_MBUTTONDOWN:
- case OS.WM_MBUTTONUP:
- case OS.WM_MOUSEHOVER:
- case OS.WM_MOUSELEAVE:
- case OS.WM_MOUSEMOVE:
- case OS.WM_MOUSEWHEEL:
- case OS.WM_RBUTTONDBLCLK:
- case OS.WM_RBUTTONDOWN:
- case OS.WM_RBUTTONUP:
- case OS.WM_XBUTTONDBLCLK:
- case OS.WM_XBUTTONDOWN:
- case OS.WM_XBUTTONUP:
- //FALL THROUGH
-
- /* Other messages */
- case OS.WM_SETFONT:
- case OS.WM_TIMER: {
- if (findImageControl () != null) {
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0);
- }
- break;
- }
- }
- int /*long*/ code = OS.CallWindowProc (TreeProc, hwnd, msg, wParam, lParam);
- switch (msg) {
- /* Keyboard messages */
- case OS.WM_KEYDOWN:
- if (wParam == OS.VK_CONTROL || wParam == OS.VK_SHIFT) break;
- //FALL THROUGH
- case OS.WM_CHAR:
- case OS.WM_IME_CHAR:
- case OS.WM_KEYUP:
- case OS.WM_SYSCHAR:
- case OS.WM_SYSKEYDOWN:
- case OS.WM_SYSKEYUP:
- //FALL THROUGH
-
- /* Scroll messages */
- case OS.WM_HSCROLL:
- case OS.WM_VSCROLL:
- //FALL THROUGH
-
- /* Resize messages */
- case OS.WM_SIZE:
- if (redraw) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.InvalidateRect (handle, null, true);
- if (hwndHeader != 0) OS.InvalidateRect (hwndHeader, null, true);
- }
- //FALL THROUGH
-
- /* Mouse messages */
- case OS.WM_LBUTTONDBLCLK:
- case OS.WM_LBUTTONDOWN:
- case OS.WM_LBUTTONUP:
- case OS.WM_MBUTTONDBLCLK:
- case OS.WM_MBUTTONDOWN:
- case OS.WM_MBUTTONUP:
- case OS.WM_MOUSEHOVER:
- case OS.WM_MOUSELEAVE:
- case OS.WM_MOUSEMOVE:
- case OS.WM_MOUSEWHEEL:
- case OS.WM_RBUTTONDBLCLK:
- case OS.WM_RBUTTONDOWN:
- case OS.WM_RBUTTONUP:
- case OS.WM_XBUTTONDBLCLK:
- case OS.WM_XBUTTONDOWN:
- case OS.WM_XBUTTONUP:
- //FALL THROUGH
-
- /* Other messages */
- case OS.WM_SETFONT:
- case OS.WM_TIMER: {
- if (findImageControl () != null) {
- if (hItem != OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0)) {
- OS.InvalidateRect (handle, null, true);
- }
- }
- updateScrollBar ();
- break;
- }
-
- case OS.WM_PAINT:
- painted = true;
- break;
- }
- return code;
-}
-
-void checkBuffered () {
- super.checkBuffered ();
- if ((style & SWT.VIRTUAL) != 0) {
- style |= SWT.DOUBLE_BUFFERED;
- OS.SendMessage (handle, OS.TVM_SETSCROLLTIME, 0, 0);
- }
- if (EXPLORER_THEME) {
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0) && OS.IsAppThemed ()) {
- int exStyle = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETEXTENDEDSTYLE, 0, 0);
- if ((exStyle & OS.TVS_EX_DOUBLEBUFFER) != 0) style |= SWT.DOUBLE_BUFFERED;
- }
- }
-}
-
-boolean checkData (TreeItem item, boolean redraw) {
- if ((style & SWT.VIRTUAL) == 0) return true;
- if (!item.cached) {
- TreeItem parentItem = item.getParentItem ();
- return checkData (item, parentItem == null ? indexOf (item) : parentItem.indexOf (item), redraw);
- }
- return true;
-}
-
-boolean checkData (TreeItem item, int index, boolean redraw) {
- if ((style & SWT.VIRTUAL) == 0) return true;
- if (!item.cached) {
- item.cached = true;
- Event event = new Event ();
- event.item = item;
- event.index = index;
- TreeItem oldItem = currentItem;
- currentItem = item;
- /*
- * Bug in Windows. If the tree scrolls during WM_NOTIFY
- * with TVN_GETDISPINFO, pixel corruption occurs. The fix
- * is to detect that the top item has changed and redraw
- * the entire tree.
- */
- int /*long*/ hTopItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0);
- sendEvent (SWT.SetData, event);
- //widget could be disposed at this point
- currentItem = oldItem;
- if (isDisposed () || item.isDisposed ()) return false;
- if (redraw) item.redraw ();
- if (hTopItem != OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0)) {
- OS.InvalidateRect (handle, null, true);
- }
- }
- return true;
-}
-
-boolean checkHandle (int /*long*/ hwnd) {
- return hwnd == handle || (hwndParent != 0 && hwnd == hwndParent) || (hwndHeader != 0 && hwnd == hwndHeader);
-}
-
-boolean checkScroll (int /*long*/ hItem) {
- /*
- * Feature in Windows. If redraw is turned off using WM_SETREDRAW
- * and a tree item that is not a child of the first root is selected or
- * scrolled using TVM_SELECTITEM or TVM_ENSUREVISIBLE, then scrolling
- * does not occur. The fix is to detect this case, and make sure
- * that redraw is temporarily enabled. To avoid flashing, DefWindowProc()
- * is called to disable redrawing.
- *
- * NOTE: The code that actually works around the problem is in the
- * callers of this method.
- */
- if (getDrawing ()) return false;
- int /*long*/ hRoot = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- int /*long*/ hParent = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PARENT, hItem);
- while (hParent != hRoot && hParent != 0) {
- hParent = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PARENT, hParent);
- }
- return hParent == 0;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Clears the item at the given zero-relative index in the receiver.
- * The text, icon and other attributes of the item are set to the default
- * value. If the tree was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param index the index of the item to clear
- * @param all <code>true</code> if all child items of the indexed item should be
- * cleared recursively, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clear (int index, boolean all) {
- checkWidget ();
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- if (hItem == 0) error (SWT.ERROR_INVALID_RANGE);
- hItem = findItem (hItem, index);
- if (hItem == 0) error (SWT.ERROR_INVALID_RANGE);
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- clear (hItem, tvItem);
- if (all) {
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hItem);
- clearAll (hItem, tvItem, all);
- }
-}
-
-void clear (int /*long*/ hItem, TVITEM tvItem) {
- tvItem.hItem = hItem;
- TreeItem item = null;
- if (OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem) != 0) {
- item = tvItem.lParam != -1 ? items [(int)/*64*/tvItem.lParam] : null;
- }
- if (item != null) {
- if ((style & SWT.VIRTUAL) != 0 && !item.cached) return;
- item.clear ();
- item.redraw ();
- }
-}
-
-/**
- * Clears all the items in the receiver. The text, icon and other
- * attributes of the items are set to their default values. If the
- * tree was created with the <code>SWT.VIRTUAL</code> style, these
- * attributes are requested again as needed.
- *
- * @param all <code>true</code> if all child items should be cleared
- * recursively, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clearAll (boolean all) {
- checkWidget ();
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- if (hItem == 0) return;
- if (all) {
- boolean redraw = false;
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null && item != currentItem) {
- item.clear ();
- redraw = true;
- }
- }
- if (redraw) OS.InvalidateRect (handle, null, true);
- } else {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- clearAll (hItem, tvItem, all);
- }
-}
-
-void clearAll (int /*long*/ hItem, TVITEM tvItem, boolean all) {
- while (hItem != 0) {
- clear (hItem, tvItem);
- if (all) {
- int /*long*/ hFirstItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hItem);
- clearAll (hFirstItem, tvItem, all);
- }
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
- }
-}
-
-int /*long*/ CompareFunc (int /*long*/ lParam1, int /*long*/ lParam2, int /*long*/ lParamSort) {
- TreeItem item1 = items [(int)/*64*/lParam1], item2 = items [(int)/*64*/lParam2];
- String text1 = item1.getText ((int)/*64*/lParamSort), text2 = item2.getText ((int)/*64*/lParamSort);
- return sortDirection == SWT.UP ? text1.compareTo (text2) : text2.compareTo (text1);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0;
- if (hwndHeader != 0) {
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_WIDTH;
- for (int i=0; i<columnCount; i++) {
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, i, hdItem);
- width += hdItem.cxy;
- }
- RECT rect = new RECT ();
- OS.GetWindowRect (hwndHeader, rect);
- height += rect.bottom - rect.top;
- }
- RECT rect = new RECT ();
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- while (hItem != 0) {
- if ((style & SWT.VIRTUAL) == 0 && !painted) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_TEXT;
- tvItem.hItem = hItem;
- tvItem.pszText = OS.LPSTR_TEXTCALLBACK;
- ignoreCustomDraw = true;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- ignoreCustomDraw = false;
- }
- if (OS.TreeView_GetItemRect (handle, hItem, rect, true)) {
- width = Math.max (width, rect.right);
- height += rect.bottom - rect.top;
- }
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, hItem);
- }
- if (width == 0) width = DEFAULT_WIDTH;
- if (height == 0) height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2;
- height += border * 2;
- if ((style & SWT.V_SCROLL) != 0) {
- width += OS.GetSystemMetrics (OS.SM_CXVSCROLL);
- }
- if ((style & SWT.H_SCROLL) != 0) {
- height += OS.GetSystemMetrics (OS.SM_CYHSCROLL);
- }
- return new Point (width, height);
-}
-
-void createHandle () {
- super.createHandle ();
- state &= ~(CANVAS | THEME_BACKGROUND);
-
- /* Use the Explorer theme */
- if (EXPLORER_THEME) {
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0) && OS.IsAppThemed ()) {
- explorerTheme = true;
- OS.SetWindowTheme (handle, Display.EXPLORER, null);
- int bits = OS.TVS_EX_DOUBLEBUFFER | OS.TVS_EX_FADEINOUTEXPANDOS | OS.TVS_EX_RICHTOOLTIP;
- /*
- * This code is intentionally commented.
- */
-// if ((style & SWT.FULL_SELECTION) == 0) bits |= OS.TVS_EX_AUTOHSCROLL;
- OS.SendMessage (handle, OS.TVM_SETEXTENDEDSTYLE, 0, bits);
- /*
- * Bug in Windows. When the tree is using the explorer
- * theme, it does not use COLOR_WINDOW_TEXT for the
- * default foreground color. The fix is to explicitly
- * set the foreground.
- */
- setForegroundPixel (-1);
- }
- }
-
- /*
- * Feature in Windows. In version 5.8 of COMCTL32.DLL,
- * if the font is changed for an item, the bounds for the
- * item are not updated, causing the text to be clipped.
- * The fix is to detect the version of COMCTL32.DLL, and
- * if it is one of the versions with the problem, then
- * use version 5.00 of the control (a version that does
- * not have the problem). This is the recommended work
- * around from the MSDN.
- */
- if (!OS.IsWinCE) {
- if (OS.COMCTL32_MAJOR < 6) {
- OS.SendMessage (handle, OS.CCM_SETVERSION, 5, 0);
- }
- }
-
- /* Set the checkbox image list */
- if ((style & SWT.CHECK) != 0) setCheckboxImageList ();
-
- /*
- * Feature in Windows. When the control is created,
- * it does not use the default system font. A new HFONT
- * is created and destroyed when the control is destroyed.
- * This means that a program that queries the font from
- * this control, uses the font in another control and then
- * destroys this control will have the font unexpectedly
- * destroyed in the other control. The fix is to assign
- * the font ourselves each time the control is created.
- * The control will not destroy a font that it did not
- * create.
- */
- int /*long*/ hFont = OS.GetStockObject (OS.SYSTEM_FONT);
- OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);
-}
-
-void createHeaderToolTips () {
- if (OS.IsWinCE) return;
- if (headerToolTipHandle != 0) return;
- int bits = 0;
- if (OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- if ((style & SWT.RIGHT_TO_LEFT) != 0) bits |= OS.WS_EX_LAYOUTRTL;
- }
- headerToolTipHandle = OS.CreateWindowEx (
- bits,
- new TCHAR (0, OS.TOOLTIPS_CLASS, true),
- null,
- OS.TTS_NOPREFIX,
- OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0,
- handle,
- 0,
- OS.GetModuleHandle (null),
- null);
- if (headerToolTipHandle == 0) error (SWT.ERROR_NO_HANDLES);
- /*
- * Feature in Windows. Despite the fact that the
- * tool tip text contains \r\n, the tooltip will
- * not honour the new line unless TTM_SETMAXTIPWIDTH
- * is set. The fix is to set TTM_SETMAXTIPWIDTH to
- * a large value.
- */
- OS.SendMessage (headerToolTipHandle, OS.TTM_SETMAXTIPWIDTH, 0, 0x7FFF);
-}
-
-void createItem (TreeColumn column, int index) {
- if (hwndHeader == 0) createParent ();
- if (!(0 <= index && index <= columnCount)) error (SWT.ERROR_INVALID_RANGE);
- if (columnCount == columns.length) {
- TreeColumn [] newColumns = new TreeColumn [columns.length + 4];
- System.arraycopy (columns, 0, newColumns, 0, columns.length);
- columns = newColumns;
- }
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null) {
- String [] strings = item.strings;
- if (strings != null) {
- String [] temp = new String [columnCount + 1];
- System.arraycopy (strings, 0, temp, 0, index);
- System.arraycopy (strings, index, temp, index + 1, columnCount - index);
- item.strings = temp;
- }
- Image [] images = item.images;
- if (images != null) {
- Image [] temp = new Image [columnCount + 1];
- System.arraycopy (images, 0, temp, 0, index);
- System.arraycopy (images, index, temp, index + 1, columnCount - index);
- item.images = temp;
- }
- if (index == 0) {
- if (columnCount != 0) {
- if (strings == null) {
- item.strings = new String [columnCount + 1];
- item.strings [1] = item.text;
- }
- item.text = "";
- if (images == null) {
- item.images = new Image [columnCount + 1];
- item.images [1] = item.image;
- }
- item.image = null;
- }
- }
- if (item.cellBackground != null) {
- int [] cellBackground = item.cellBackground;
- int [] temp = new int [columnCount + 1];
- System.arraycopy (cellBackground, 0, temp, 0, index);
- System.arraycopy (cellBackground, index, temp, index + 1, columnCount - index);
- temp [index] = -1;
- item.cellBackground = temp;
- }
- if (item.cellForeground != null) {
- int [] cellForeground = item.cellForeground;
- int [] temp = new int [columnCount + 1];
- System.arraycopy (cellForeground, 0, temp, 0, index);
- System.arraycopy (cellForeground, index, temp, index + 1, columnCount - index);
- temp [index] = -1;
- item.cellForeground = temp;
- }
- if (item.cellFont != null) {
- Font [] cellFont = item.cellFont;
- Font [] temp = new Font [columnCount + 1];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index, temp, index + 1, columnCount- index);
- item.cellFont = temp;
- }
- }
- }
- System.arraycopy (columns, index, columns, index + 1, columnCount++ - index);
- columns [index] = column;
-
- /*
- * Bug in Windows. For some reason, when HDM_INSERTITEM
- * is used to insert an item into a header without text,
- * if is not possible to set the text at a later time.
- * The fix is to insert the item with an empty string.
- */
- int /*long*/ hHeap = OS.GetProcessHeap ();
- int /*long*/ pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof);
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_TEXT | OS.HDI_FORMAT;
- hdItem.pszText = pszText;
- if ((column.style & SWT.LEFT) == SWT.LEFT) hdItem.fmt = OS.HDF_LEFT;
- if ((column.style & SWT.CENTER) == SWT.CENTER) hdItem.fmt = OS.HDF_CENTER;
- if ((column.style & SWT.RIGHT) == SWT.RIGHT) hdItem.fmt = OS.HDF_RIGHT;
- OS.SendMessage (hwndHeader, OS.HDM_INSERTITEM, index, hdItem);
- if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
-
- /* When the first column is created, hide the horizontal scroll bar */
- if (columnCount == 1) {
- scrollWidth = 0;
- if ((style & SWT.H_SCROLL) != 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- bits |= OS.TVS_NOHSCROLL;
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- }
- /*
- * Bug in Windows. When TVS_NOHSCROLL is set after items
- * have been inserted into the tree, Windows shows the
- * scroll bar. The fix is to check for this case and
- * explicitly hide the scroll bar explicitly.
- */
- int count = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETCOUNT, 0, 0);
- if (count != 0) {
- if (!OS.IsWinCE) OS.ShowScrollBar (handle, OS.SB_HORZ, false);
- }
- createItemToolTips ();
- if (itemToolTipHandle != 0) {
- OS.SendMessage (itemToolTipHandle, OS.TTM_SETDELAYTIME, OS.TTDT_AUTOMATIC, -1);
- }
- }
- setScrollWidth ();
- updateImageList ();
- updateScrollBar ();
-
- /* Redraw to hide the items when the first column is created */
- if (columnCount == 1 && OS.SendMessage (handle, OS.TVM_GETCOUNT, 0, 0) != 0) {
- OS.InvalidateRect (handle, null, true);
- }
-
- /* Add the tool tip item for the header */
- if (headerToolTipHandle != 0) {
- RECT rect = new RECT ();
- if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, rect) != 0) {
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- lpti.uFlags = OS.TTF_SUBCLASS;
- lpti.hwnd = hwndHeader;
- lpti.uId = column.id = display.nextToolTipId++;
- lpti.left = rect.left;
- lpti.top = rect.top;
- lpti.right = rect.right;
- lpti.bottom = rect.bottom;
- lpti.lpszText = OS.LPSTR_TEXTCALLBACK;
- OS.SendMessage (headerToolTipHandle, OS.TTM_ADDTOOL, 0, lpti);
- }
- }
-}
-
-void createItem (TreeItem item, int /*long*/ hParent, int /*long*/ hInsertAfter, int /*long*/ hItem) {
- int id = -1;
- if (item != null) {
- id = lastID < items.length ? lastID : 0;
- while (id < items.length && items [id] != null) id++;
- if (id == items.length) {
- /*
- * Grow the array faster when redraw is off or the
- * table is not visible. When the table is painted,
- * the items array is resized to be smaller to reduce
- * memory usage.
- */
- int length = 0;
- if (getDrawing () && OS.IsWindowVisible (handle)) {
- length = items.length + 4;
- } else {
- shrink = true;
- length = Math.max (4, items.length * 3 / 2);
- }
- TreeItem [] newItems = new TreeItem [length];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- lastID = id + 1;
- }
- int /*long*/ hNewItem = 0;
- int /*long*/ hFirstItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hParent);
- boolean fixParent = hFirstItem == 0;
- if (hItem == 0) {
- TVINSERTSTRUCT tvInsert = new TVINSERTSTRUCT ();
- tvInsert.hParent = hParent;
- tvInsert.hInsertAfter = hInsertAfter;
- tvInsert.lParam = id;
- tvInsert.pszText = OS.LPSTR_TEXTCALLBACK;
- tvInsert.iImage = tvInsert.iSelectedImage = OS.I_IMAGECALLBACK;
- tvInsert.mask = OS.TVIF_TEXT | OS.TVIF_IMAGE | OS.TVIF_SELECTEDIMAGE | OS.TVIF_HANDLE | OS.TVIF_PARAM;
- if ((style & SWT.CHECK) != 0) {
- tvInsert.mask = tvInsert.mask | OS.TVIF_STATE;
- tvInsert.state = 1 << 12;
- tvInsert.stateMask = OS.TVIS_STATEIMAGEMASK;
- }
- ignoreCustomDraw = true;
- hNewItem = OS.SendMessage (handle, OS.TVM_INSERTITEM, 0, tvInsert);
- ignoreCustomDraw = false;
- if (hNewItem == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- /*
- * This code is intentionally commented.
- */
-// if (hParent != 0) {
-// int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
-// bits |= OS.TVS_LINESATROOT;
-// OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
-// }
- } else {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- tvItem.hItem = hNewItem = hItem;
- tvItem.lParam = id;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- if (item != null) {
- item.handle = hNewItem;
- items [id] = item;
- }
- if (hFirstItem == 0) {
- if (hInsertAfter == OS.TVI_FIRST || hInsertAfter == OS.TVI_LAST) {
- hFirstIndexOf = hLastIndexOf = hFirstItem = hNewItem;
- itemCount = lastIndexOf = 0;
- }
- }
- if (hFirstItem == hFirstIndexOf && itemCount != -1) itemCount++;
- if (hItem == 0) {
- /*
- * Bug in Windows. When a child item is added to a parent item
- * that has no children outside of WM_NOTIFY with control code
- * TVN_ITEMEXPANDED, the tree widget does not redraw the +/-
- * indicator. The fix is to detect the case when the first
- * child is added to a visible parent item and redraw the parent.
- */
- if (fixParent) {
- if (getDrawing () && OS.IsWindowVisible (handle)) {
- RECT rect = new RECT ();
- if (OS.TreeView_GetItemRect (handle, hParent, rect, false)) {
- OS.InvalidateRect (handle, rect, true);
- }
- }
- }
- /*
- * Bug in Windows. When a new item is added while Windows
- * is requesting data a tree item using TVN_GETDISPINFO,
- * outstanding damage for items that are below the new item
- * is not scrolled. The fix is to explicitly damage the
- * new area.
- */
- if ((style & SWT.VIRTUAL) != 0) {
- if (currentItem != null) {
- RECT rect = new RECT ();
- if (OS.TreeView_GetItemRect (handle, hNewItem, rect, false)) {
- RECT damageRect = new RECT ();
- boolean damaged = OS.GetUpdateRect (handle, damageRect, true);
- if (damaged && damageRect.top < rect.bottom) {
- if (OS.IsWinCE) {
- OS.OffsetRect (damageRect, 0, rect.bottom - rect.top);
- OS.InvalidateRect (handle, damageRect, true);
- } else {
- int /*long*/ rgn = OS.CreateRectRgn (0, 0, 0, 0);
- int result = OS.GetUpdateRgn (handle, rgn, true);
- if (result != OS.NULLREGION) {
- OS.OffsetRgn (rgn, 0, rect.bottom - rect.top);
- OS.InvalidateRgn (handle, rgn, true);
- }
- OS.DeleteObject (rgn);
- }
- }
- }
- }
- }
- updateScrollBar ();
- }
-}
-
-void createItemToolTips () {
- if (OS.IsWinCE) return;
- if (itemToolTipHandle != 0) return;
- int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
- bits1 |= OS.TVS_NOTOOLTIPS;
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits1);
- int bits2 = 0;
- if (OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- if ((style & SWT.RIGHT_TO_LEFT) != 0) bits2 |= OS.WS_EX_LAYOUTRTL;
- }
- /*
- * Feature in Windows. For some reason, when the user
- * clicks on a tool tip, it temporarily takes focus, even
- * when WS_EX_NOACTIVATE is specified. The fix is to
- * use WS_EX_TRANSPARENT, even though WS_EX_TRANSPARENT
- * is documented to affect painting, not hit testing.
- *
- * NOTE: Windows 2000 doesn't have the problem and
- * setting WS_EX_TRANSPARENT causes pixel corruption.
- */
- if (OS.COMCTL32_MAJOR >= 6) bits2 |= OS.WS_EX_TRANSPARENT;
- itemToolTipHandle = OS.CreateWindowEx (
- bits2,
- new TCHAR (0, OS.TOOLTIPS_CLASS, true),
- null,
- OS.TTS_NOPREFIX | OS.TTS_NOANIMATE | OS.TTS_NOFADE,
- OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0,
- handle,
- 0,
- OS.GetModuleHandle (null),
- null);
- if (itemToolTipHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.SendMessage (itemToolTipHandle, OS.TTM_SETDELAYTIME, OS.TTDT_INITIAL, 0);
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- lpti.hwnd = handle;
- lpti.uId = handle;
- lpti.uFlags = OS.TTF_SUBCLASS | OS.TTF_TRANSPARENT;
- lpti.lpszText = OS.LPSTR_TEXTCALLBACK;
- OS.SendMessage (itemToolTipHandle, OS.TTM_ADDTOOL, 0, lpti);
-}
-
-void createParent () {
- forceResize ();
- RECT rect = new RECT ();
- OS.GetWindowRect (handle, rect);
- OS.MapWindowPoints (0, parent.handle, rect, 2);
- int oldStyle = OS.GetWindowLong (handle, OS.GWL_STYLE);
- int newStyle = super.widgetStyle () & ~OS.WS_VISIBLE;
- if ((oldStyle & OS.WS_DISABLED) != 0) newStyle |= OS.WS_DISABLED;
-// if ((oldStyle & OS.WS_VISIBLE) != 0) newStyle |= OS.WS_VISIBLE;
- hwndParent = OS.CreateWindowEx (
- super.widgetExtStyle (),
- super.windowClass (),
- null,
- newStyle,
- rect.left,
- rect.top,
- rect.right - rect.left,
- rect.bottom - rect.top,
- parent.handle,
- 0,
- OS.GetModuleHandle (null),
- null);
- if (hwndParent == 0) error (SWT.ERROR_NO_HANDLES);
- OS.SetWindowLongPtr (hwndParent, OS.GWLP_ID, hwndParent);
- int bits = 0;
- if (OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- bits |= OS.WS_EX_NOINHERITLAYOUT;
- if ((style & SWT.RIGHT_TO_LEFT) != 0) bits |= OS.WS_EX_LAYOUTRTL;
- }
- hwndHeader = OS.CreateWindowEx (
- bits,
- HeaderClass,
- null,
- OS.HDS_BUTTONS | OS.HDS_FULLDRAG | OS.HDS_DRAGDROP | OS.HDS_HIDDEN | OS.WS_CHILD | OS.WS_CLIPSIBLINGS,
- 0, 0, 0, 0,
- hwndParent,
- 0,
- OS.GetModuleHandle (null),
- null);
- if (hwndHeader == 0) error (SWT.ERROR_NO_HANDLES);
- OS.SetWindowLongPtr (hwndHeader, OS.GWLP_ID, hwndHeader);
- if (OS.IsDBLocale) {
- int /*long*/ hIMC = OS.ImmGetContext (handle);
- OS.ImmAssociateContext (hwndParent, hIMC);
- OS.ImmAssociateContext (hwndHeader, hIMC);
- OS.ImmReleaseContext (handle, hIMC);
- }
- //This code is intentionally commented
-// if (!OS.IsPPC) {
-// if ((style & SWT.BORDER) != 0) {
-// int oldExStyle = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
-// oldExStyle &= ~OS.WS_EX_CLIENTEDGE;
-// OS.SetWindowLong (handle, OS.GWL_EXSTYLE, oldExStyle);
-// }
-// }
- int /*long*/ hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (hFont != 0) OS.SendMessage (hwndHeader, OS.WM_SETFONT, hFont, 0);
- int /*long*/ hwndInsertAfter = OS.GetWindow (handle, OS.GW_HWNDPREV);
- int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE;
- SetWindowPos (hwndParent, hwndInsertAfter, 0, 0, 0, 0, flags);
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_RANGE | OS.SIF_PAGE;
- OS.GetScrollInfo (hwndParent, OS.SB_HORZ, info);
- info.nPage = info.nMax + 1;
- OS.SetScrollInfo (hwndParent, OS.SB_HORZ, info, true);
- OS.GetScrollInfo (hwndParent, OS.SB_VERT, info);
- info.nPage = info.nMax + 1;
- OS.SetScrollInfo (hwndParent, OS.SB_VERT, info, true);
- customDraw = true;
- deregister ();
- if ((oldStyle & OS.WS_VISIBLE) != 0) {
- OS.ShowWindow (hwndParent, OS.SW_SHOW);
- }
- int /*long*/ hwndFocus = OS.GetFocus ();
- if (hwndFocus == handle) OS.SetFocus (hwndParent);
- OS.SetParent (handle, hwndParent);
- if (hwndFocus == handle) OS.SetFocus (handle);
- register ();
- subclass ();
-}
-
-void createWidget () {
- super.createWidget ();
- items = new TreeItem [4];
- columns = new TreeColumn [4];
- itemCount = -1;
-}
-
-int defaultBackground () {
- return OS.GetSysColor (OS.COLOR_WINDOW);
-}
-
-void deregister () {
- super.deregister ();
- if (hwndParent != 0) display.removeControl (hwndParent);
- if (hwndHeader != 0) display.removeControl (hwndHeader);
-}
-
-void deselect (int /*long*/ hItem, TVITEM tvItem, int /*long*/ hIgnoreItem) {
- while (hItem != 0) {
- if (hItem != hIgnoreItem) {
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- int /*long*/ hFirstItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hItem);
- deselect (hFirstItem, tvItem, hIgnoreItem);
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
- }
-}
-
-/**
- * Deselects an item in the receiver. If the item was already
- * deselected, it remains deselected.
- *
- * @param item the item to be deselected
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void deselect (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_SELECTED;
- tvItem.hItem = item.handle;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
-}
-
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll () {
- checkWidget ();
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_SELECTED;
- if ((style & SWT.SINGLE) != 0) {
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem != 0) {
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- } else {
- int /*long*/ oldProc = OS.GetWindowLongPtr (handle, OS.GWLP_WNDPROC);
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, TreeProc);
- if ((style & SWT.VIRTUAL) != 0) {
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- deselect (hItem, tvItem, 0);
- } else {
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null) {
- tvItem.hItem = item.handle;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- }
- }
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, oldProc);
- }
-}
-
-void destroyItem (TreeColumn column) {
- if (hwndHeader == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
- int index = 0;
- while (index < columnCount) {
- if (columns [index] == column) break;
- index++;
- }
- int [] oldOrder = new int [columnCount];
- OS.SendMessage (hwndHeader, OS.HDM_GETORDERARRAY, columnCount, oldOrder);
- int orderIndex = 0;
- while (orderIndex < columnCount) {
- if (oldOrder [orderIndex] == index) break;
- orderIndex++;
- }
- RECT headerRect = new RECT ();
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect);
- if (OS.SendMessage (hwndHeader, OS.HDM_DELETEITEM, index, 0) == 0) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- System.arraycopy (columns, index + 1, columns, index, --columnCount - index);
- columns [columnCount] = null;
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null) {
- if (columnCount == 0) {
- item.strings = null;
- item.images = null;
- item.cellBackground = null;
- item.cellForeground = null;
- item.cellFont = null;
- } else {
- if (item.strings != null) {
- String [] strings = item.strings;
- if (index == 0) {
- item.text = strings [1] != null ? strings [1] : "";
- }
- String [] temp = new String [columnCount];
- System.arraycopy (strings, 0, temp, 0, index);
- System.arraycopy (strings, index + 1, temp, index, columnCount - index);
- item.strings = temp;
- } else {
- if (index == 0) item.text = "";
- }
- if (item.images != null) {
- Image [] images = item.images;
- if (index == 0) item.image = images [1];
- Image [] temp = new Image [columnCount];
- System.arraycopy (images, 0, temp, 0, index);
- System.arraycopy (images, index + 1, temp, index, columnCount - index);
- item.images = temp;
- } else {
- if (index == 0) item.image = null;
- }
- if (item.cellBackground != null) {
- int [] cellBackground = item.cellBackground;
- int [] temp = new int [columnCount];
- System.arraycopy (cellBackground, 0, temp, 0, index);
- System.arraycopy (cellBackground, index + 1, temp, index, columnCount - index);
- item.cellBackground = temp;
- }
- if (item.cellForeground != null) {
- int [] cellForeground = item.cellForeground;
- int [] temp = new int [columnCount];
- System.arraycopy (cellForeground, 0, temp, 0, index);
- System.arraycopy (cellForeground, index + 1, temp, index, columnCount - index);
- item.cellForeground = temp;
- }
- if (item.cellFont != null) {
- Font [] cellFont = item.cellFont;
- Font [] temp = new Font [columnCount];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index + 1, temp, index, columnCount - index);
- item.cellFont = temp;
- }
- }
- }
- }
-
- /*
- * When the last column is deleted, show the horizontal
- * scroll bar. Otherwise, left align the first column
- * and redraw the columns to the right.
- */
- if (columnCount == 0) {
- scrollWidth = 0;
- if (!hooks (SWT.MeasureItem)) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((style & SWT.H_SCROLL) != 0) bits &= ~OS.TVS_NOHSCROLL;
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- OS.InvalidateRect (handle, null, true);
- }
- if (itemToolTipHandle != 0) {
- OS.SendMessage (itemToolTipHandle, OS.TTM_SETDELAYTIME, OS.TTDT_INITIAL, 0);
- }
- } else {
- if (index == 0) {
- columns [0].style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- columns [0].style |= SWT.LEFT;
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_FORMAT | OS.HDI_IMAGE;
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, hdItem);
- hdItem.fmt &= ~OS.HDF_JUSTIFYMASK;
- hdItem.fmt |= OS.HDF_LEFT;
- OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, hdItem);
- }
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- rect.left = headerRect.left;
- OS.InvalidateRect (handle, rect, true);
- }
- setScrollWidth ();
- updateImageList ();
- updateScrollBar ();
- if (columnCount != 0) {
- int [] newOrder = new int [columnCount];
- OS.SendMessage (hwndHeader, OS.HDM_GETORDERARRAY, columnCount, newOrder);
- TreeColumn [] newColumns = new TreeColumn [columnCount - orderIndex];
- for (int i=orderIndex; i<newOrder.length; i++) {
- newColumns [i - orderIndex] = columns [newOrder [i]];
- newColumns [i - orderIndex].updateToolTip (newOrder [i]);
- }
- for (int i=0; i<newColumns.length; i++) {
- if (!newColumns [i].isDisposed ()) {
- newColumns [i].sendEvent (SWT.Move);
- }
- }
- }
-
- /* Remove the tool tip item for the header */
- if (headerToolTipHandle != 0) {
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- lpti.uId = column.id;
- lpti.hwnd = hwndHeader;
- OS.SendMessage (headerToolTipHandle, OS.TTM_DELTOOL, 0, lpti);
- }
-}
-
-void destroyItem (TreeItem item, int /*long*/ hItem) {
- hFirstIndexOf = hLastIndexOf = 0;
- itemCount = -1;
- /*
- * Feature in Windows. When an item is removed that is not
- * visible in the tree because it belongs to a collapsed branch,
- * Windows redraws the tree causing a flash for each item that
- * is removed. The fix is to detect whether the item is visible,
- * force the widget to be fully painted, turn off redraw, remove
- * the item and validate the damage caused by the removing of
- * the item.
- *
- * NOTE: This fix is not necessary when double buffering and
- * can cause problems for virtual trees due to the call to
- * UpdateWindow() that flushes outstanding WM_PAINT events,
- * allowing application code to add or remove items during
- * this remove operation.
- */
- int /*long*/ hParent = 0;
- boolean fixRedraw = false;
- if ((style & SWT.DOUBLE_BUFFERED) == 0) {
- if (getDrawing () && OS.IsWindowVisible (handle)) {
- RECT rect = new RECT ();
- fixRedraw = !OS.TreeView_GetItemRect (handle, hItem, rect, false);
- }
- }
- if (fixRedraw) {
- hParent = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PARENT, hItem);
- OS.UpdateWindow (handle);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- /*
- * This code is intentionally commented.
- */
-// OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- }
- if ((style & SWT.MULTI) != 0) {
- ignoreDeselect = ignoreSelect = lockSelection = true;
- }
-
- /*
- * Feature in Windows. When an item is deleted and a tool tip
- * is showing, Window requests the new text for the new item
- * that is under the cursor right away. This means that when
- * multiple items are deleted, the tool tip flashes, showing
- * each new item in the tool tip as it is scrolled into view.
- * The fix is to hide tool tips when any item is deleted.
- *
- * NOTE: This only happens on Vista.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.TVM_GETTOOLTIPS, 0, 0);
- if (hwndToolTip != 0) OS.SendMessage (hwndToolTip, OS.TTM_POP, 0 ,0);
- }
-
- shrink = ignoreShrink = true;
- OS.SendMessage (handle, OS.TVM_DELETEITEM, 0, hItem);
- ignoreShrink = false;
- if ((style & SWT.MULTI) != 0) {
- ignoreDeselect = ignoreSelect = lockSelection = false;
- }
- if (fixRedraw) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.ValidateRect (handle, null);
- /*
- * If the item that was deleted was the last child of a tree item that
- * is visible, redraw the parent item to force the +/- to be updated.
- */
- if (OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hParent) == 0) {
- RECT rect = new RECT ();
- if (OS.TreeView_GetItemRect (handle, hParent, rect, false)) {
- OS.InvalidateRect (handle, rect, true);
- }
- }
- }
- int count = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETCOUNT, 0, 0);
- if (count == 0) {
- if (imageList != null) {
- OS.SendMessage (handle, OS.TVM_SETIMAGELIST, 0, 0);
- display.releaseImageList (imageList);
- }
- imageList = null;
- if (hwndParent == 0 && !linesVisible) {
- if (!hooks (SWT.MeasureItem) && !hooks (SWT.EraseItem) && !hooks (SWT.PaintItem)) {
- customDraw = false;
- }
- }
- items = new TreeItem [4];
- scrollWidth = 0;
- setScrollWidth ();
- }
- updateScrollBar ();
-}
-
-void destroyScrollBar (int type) {
- super.destroyScrollBar (type);
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
- bits &= ~(OS.WS_HSCROLL | OS.WS_VSCROLL);
- bits |= OS.TVS_NOSCROLL;
- } else {
- if ((style & SWT.H_SCROLL) == 0) {
- bits &= ~OS.WS_HSCROLL;
- bits |= OS.TVS_NOHSCROLL;
- }
- }
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
-}
-
-void enableDrag (boolean enabled) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if (enabled && hooks (SWT.DragDetect)) {
- bits &= ~OS.TVS_DISABLEDRAGDROP;
- } else {
- bits |= OS.TVS_DISABLEDRAGDROP;
- }
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
-}
-
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- /*
- * Feature in Windows. When a tree is given a background color
- * using TVM_SETBKCOLOR and the tree is disabled, Windows draws
- * the tree using the background color rather than the disabled
- * colors. This is different from the table which draws grayed.
- * The fix is to set the default background color while the tree
- * is disabled and restore it when enabled.
- */
- Control control = findBackgroundControl ();
- /*
- * Bug in Windows. On Vista only, Windows does not draw using
- * the background color when the tree is disabled. The fix is
- * to set the default color, even when the color has not been
- * changed, causing Windows to draw correctly.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- if (control == null) control = this;
- }
- if (control != null) {
- if (control.backgroundImage == null) {
- _setBackgroundPixel (enabled ? control.getBackgroundPixel () : -1);
- }
- }
- if (hwndParent != 0) OS.EnableWindow (hwndParent, enabled);
-
- /*
- * Feature in Windows. When the tree has the style
- * TVS_FULLROWSELECT, the background color for the
- * entire row is filled when an item is painted,
- * drawing on top of the sort column color. The fix
- * is to clear TVS_FULLROWSELECT when a their is
- * as sort column.
- */
- updateFullSelection ();
-}
-
-boolean findCell (int x, int y, TreeItem [] item, int [] index, RECT [] cellRect, RECT [] itemRect) {
- boolean found = false;
- TVHITTESTINFO lpht = new TVHITTESTINFO ();
- lpht.x = x;
- lpht.y = y;
- OS.SendMessage (handle, OS.TVM_HITTEST, 0, lpht);
- if (lpht.hItem != 0) {
- item [0] = _getItem (lpht.hItem);
- POINT pt = new POINT ();
- pt.x = x;
- pt.y = y;
- int /*long*/ hDC = OS.GetDC (handle);
- int /*long*/ oldFont = 0, newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- RECT rect = new RECT ();
- if (hwndParent != 0) {
- OS.GetClientRect (hwndParent, rect);
- OS.MapWindowPoints (hwndParent, handle, rect, 2);
- } else {
- OS.GetClientRect (handle, rect);
- }
- int count = Math.max (1, columnCount);
- int [] order = new int [count];
- if (hwndHeader != 0) OS.SendMessage (hwndHeader, OS.HDM_GETORDERARRAY, count, order);
- index [0] = 0;
- boolean quit = false;
- while (index [0] < count && !quit) {
- int /*long*/ hFont = item [0].fontHandle (order [index [0]]);
- if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
- cellRect [0] = item [0].getBounds (order [index [0]], true, false, true, false, true, hDC);
- if (cellRect [0].left > rect.right) {
- quit = true;
- } else {
- cellRect [0].right = Math.min (cellRect [0].right, rect.right);
- if (OS.PtInRect (cellRect [0], pt)) {
- if (isCustomToolTip ()) {
- Event event = sendMeasureItemEvent (item [0], order [index [0]], hDC);
- if (isDisposed () || item [0].isDisposed ()) break;
- itemRect [0] = new RECT ();
- itemRect [0].left = event.x;
- itemRect [0].right = event.x + event.width;
- itemRect [0].top = event.y;
- itemRect [0].bottom = event.y + event.height;
- } else {
- itemRect [0] = item [0].getBounds (order [index [0]], true, false, false, false, false, hDC);
- }
- if (itemRect [0].right > cellRect [0].right) found = true;
- quit = true;
- }
- }
- if (hFont != -1) OS.SelectObject (hDC, hFont);
- if (!found) index [0]++;
- }
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- }
- return found;
-}
-
-int findIndex (int /*long*/ hFirstItem, int /*long*/ hItem) {
- if (hFirstItem == 0) return -1;
- if (hFirstItem == hFirstIndexOf) {
- if (hFirstIndexOf == hItem) {
- hLastIndexOf = hFirstIndexOf;
- return lastIndexOf = 0;
- }
- if (hLastIndexOf == hItem) return lastIndexOf;
- int /*long*/ hPrevItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PREVIOUS, hLastIndexOf);
- if (hPrevItem == hItem) {
- hLastIndexOf = hPrevItem;
- return --lastIndexOf;
- }
- int /*long*/ hNextItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hLastIndexOf);
- if (hNextItem == hItem) {
- hLastIndexOf = hNextItem;
- return ++lastIndexOf;
- }
- int previousIndex = lastIndexOf - 1;
- while (hPrevItem != 0 && hPrevItem != hItem) {
- hPrevItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PREVIOUS, hPrevItem);
- --previousIndex;
- }
- if (hPrevItem == hItem) {
- hLastIndexOf = hPrevItem;
- return lastIndexOf = previousIndex;
- }
- int nextIndex = lastIndexOf + 1;
- while (hNextItem != 0 && hNextItem != hItem) {
- hNextItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hNextItem);
- nextIndex++;
- }
- if (hNextItem == hItem) {
- hLastIndexOf = hNextItem;
- return lastIndexOf = nextIndex;
- }
- return -1;
- }
- int index = 0;
- int /*long*/ hNextItem = hFirstItem;
- while (hNextItem != 0 && hNextItem != hItem) {
- hNextItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hNextItem);
- index++;
- }
- if (hNextItem == hItem) {
- itemCount = -1;
- hFirstIndexOf = hFirstItem;
- hLastIndexOf = hNextItem;
- return lastIndexOf = index;
- }
- return -1;
-}
-
-Widget findItem (int /*long*/ hItem) {
- return _getItem (hItem);
-}
-
-int /*long*/ findItem (int /*long*/ hFirstItem, int index) {
- if (hFirstItem == 0) return 0;
- if (hFirstItem == hFirstIndexOf) {
- if (index == 0) {
- lastIndexOf = 0;
- return hLastIndexOf = hFirstIndexOf;
- }
- if (lastIndexOf == index) return hLastIndexOf;
- if (lastIndexOf - 1 == index) {
- --lastIndexOf;
- return hLastIndexOf = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PREVIOUS, hLastIndexOf);
- }
- if (lastIndexOf + 1 == index) {
- lastIndexOf++;
- return hLastIndexOf = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hLastIndexOf);
- }
- if (index < lastIndexOf) {
- int previousIndex = lastIndexOf - 1;
- int /*long*/ hPrevItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PREVIOUS, hLastIndexOf);
- while (hPrevItem != 0 && index < previousIndex) {
- hPrevItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PREVIOUS, hPrevItem);
- --previousIndex;
- }
- if (index == previousIndex) {
- lastIndexOf = previousIndex;
- return hLastIndexOf = hPrevItem;
- }
- } else {
- int nextIndex = lastIndexOf + 1;
- int /*long*/ hNextItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hLastIndexOf);
- while (hNextItem != 0 && nextIndex < index) {
- hNextItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hNextItem);
- nextIndex++;
- }
- if (index == nextIndex) {
- lastIndexOf = nextIndex;
- return hLastIndexOf = hNextItem;
- }
- }
- return 0;
- }
- int nextIndex = 0;
- int /*long*/ hNextItem = hFirstItem;
- while (hNextItem != 0 && nextIndex < index) {
- hNextItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hNextItem);
- nextIndex++;
- }
- if (index == nextIndex) {
- itemCount = -1;
- lastIndexOf = nextIndex;
- hFirstIndexOf = hFirstItem;
- return hLastIndexOf = hNextItem;
- }
- return 0;
-}
-
-TreeItem getFocusItem () {
-// checkWidget ();
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- return hItem != 0 ? _getItem (hItem) : null;
-}
-
-/**
- * Returns the width in pixels of a grid line.
- *
- * @return the width of a grid line in pixels
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getGridLineWidth () {
- checkWidget ();
- return GRID_WIDTH;
-}
-
-/**
- * Returns the height of the receiver's header
- *
- * @return the height of the header or zero if the header is not visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getHeaderHeight () {
- checkWidget ();
- if (hwndHeader == 0) return 0;
- RECT rect = new RECT ();
- OS.GetWindowRect (hwndHeader, rect);
- return rect.bottom - rect.top;
-}
-
-/**
- * Returns <code>true</code> if the receiver's header is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's header's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public boolean getHeaderVisible () {
- checkWidget ();
- if (hwndHeader == 0) return false;
- int bits = OS.GetWindowLong (hwndHeader, OS.GWL_STYLE);
- return (bits & OS.WS_VISIBLE) != 0;
-}
-
-Point getImageSize () {
- if (imageList != null) return imageList.getImageSize ();
- return new Point (0, getItemHeight ());
-}
-
-int /*long*/ getBottomItem () {
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0);
- if (hItem == 0) return 0;
- int index = 0, count = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETVISIBLECOUNT, 0, 0);
- while (index <= count) {
- int /*long*/ hNextItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, hItem);
- if (hNextItem == 0) return hItem;
- hItem = hNextItem;
- index++;
- }
- return hItem;
-}
-
-/**
- * Returns the column at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- * Columns are returned in the order that they were created.
- * If no <code>TreeColumn</code>s were created by the programmer,
- * this method will throw <code>ERROR_INVALID_RANGE</code> despite
- * the fact that a single column of data may be visible in the tree.
- * This occurs when the programmer uses the tree like a list, adding
- * items but never creating a column.
- *
- * @param index the index of the column to return
- * @return the column at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public TreeColumn getColumn (int index) {
- checkWidget ();
- if (!(0 <= index && index < columnCount)) error (SWT.ERROR_INVALID_RANGE);
- return columns [index];
-}
-
-/**
- * Returns the number of columns contained in the receiver.
- * If no <code>TreeColumn</code>s were created by the programmer,
- * this value is zero, despite the fact that visually, one column
- * of items may be visible. This occurs when the programmer uses
- * the tree like a list, adding items but never creating a column.
- *
- * @return the number of columns
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getColumnCount () {
- checkWidget ();
- return columnCount;
-}
-
-/**
- * Returns an array of zero-relative integers that map
- * the creation order of the receiver's items to the
- * order in which they are currently being displayed.
- * <p>
- * Specifically, the indices of the returned array represent
- * the current visual order of the items, and the contents
- * of the array represent the creation order of the items.
- * </p><p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the current visual order of the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
-public int[] getColumnOrder () {
- checkWidget ();
- if (columnCount == 0) return new int [0];
- int [] order = new int [columnCount];
- OS.SendMessage (hwndHeader, OS.HDM_GETORDERARRAY, columnCount, order);
- return order;
-}
-
-/**
- * Returns an array of <code>TreeColumn</code>s which are the
- * columns in the receiver. Columns are returned in the order
- * that they were created. If no <code>TreeColumn</code>s were
- * created by the programmer, the array is empty, despite the fact
- * that visually, one column of items may be visible. This occurs
- * when the programmer uses the tree like a list, adding items but
- * never creating a column.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public TreeColumn [] getColumns () {
- checkWidget ();
- TreeColumn [] result = new TreeColumn [columnCount];
- System.arraycopy (columns, 0, result, 0, columnCount);
- return result;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public TreeItem getItem (int index) {
- checkWidget ();
- if (index < 0) error (SWT.ERROR_INVALID_RANGE);
- int /*long*/ hFirstItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- if (hFirstItem == 0) error (SWT.ERROR_INVALID_RANGE);
- int /*long*/ hItem = findItem (hFirstItem, index);
- if (hItem == 0) error (SWT.ERROR_INVALID_RANGE);
- return _getItem (hItem);
-}
-
-TreeItem getItem (NMTVCUSTOMDRAW nmcd) {
- /*
- * Bug in Windows. If the lParam field of TVITEM
- * is changed during custom draw using TVM_SETITEM,
- * the lItemlParam field of the NMTVCUSTOMDRAW struct
- * is not updated until the next custom draw. The
- * fix is to query the field from the item instead
- * of using the struct.
- */
- int id = (int)/*64*/nmcd.lItemlParam;
- if ((style & SWT.VIRTUAL) != 0) {
- if (id == -1) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- tvItem.hItem = nmcd.dwItemSpec;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- id = (int)/*64*/tvItem.lParam;
- }
- }
- return _getItem (nmcd.dwItemSpec, id);
-}
-
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- * <p>
- * The item that is returned represents an item that could be selected by the user.
- * For example, if selection only occurs in items in the first column, then null is
- * returned if the point is outside of the item.
- * Note that the SWT.FULL_SELECTION style hint, which specifies the selection policy,
- * determines the extent of the selection.
- * </p>
- *
- * @param point the point used to locate the item
- * @return the item at the given point, or null if the point is not in a selectable item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem getItem (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- TVHITTESTINFO lpht = new TVHITTESTINFO ();
- lpht.x = point.x;
- lpht.y = point.y;
- OS.SendMessage (handle, OS.TVM_HITTEST, 0, lpht);
- if (lpht.hItem != 0) {
- int flags = OS.TVHT_ONITEM;
- if ((style & SWT.FULL_SELECTION) != 0) {
- flags |= OS.TVHT_ONITEMRIGHT | OS.TVHT_ONITEMINDENT;
- } else {
- if (hooks (SWT.MeasureItem)) {
- lpht.flags &= ~(OS.TVHT_ONITEMICON | OS.TVHT_ONITEMLABEL);
- if (hitTestSelection (lpht.hItem, lpht.x, lpht.y)) {
- lpht.flags |= OS.TVHT_ONITEMICON | OS.TVHT_ONITEMLABEL;
- }
- }
- }
- if ((lpht.flags & flags) != 0) return _getItem (lpht.hItem);
- }
- return null;
-}
-
-/**
- * Returns the number of items contained in the receiver
- * that are direct item children of the receiver. The
- * number that is returned is the number of roots in the
- * tree.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- if (hItem == 0) return 0;
- return getItemCount (hItem);
-}
-
-int getItemCount (int /*long*/ hItem) {
- int count = 0;
- int /*long*/ hFirstItem = hItem;
- if (hItem == hFirstIndexOf) {
- if (itemCount != -1) return itemCount;
- hFirstItem = hLastIndexOf;
- count = lastIndexOf;
- }
- while (hFirstItem != 0) {
- hFirstItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hFirstItem);
- count++;
- }
- if (hItem == hFirstIndexOf) itemCount = count;
- return count;
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the tree.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- return (int)/*64*/OS.SendMessage (handle, OS.TVM_GETITEMHEIGHT, 0, 0);
-}
-
-/**
- * Returns a (possibly empty) array of items contained in the
- * receiver that are direct item children of the receiver. These
- * are the roots of the tree.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem [] getItems () {
- checkWidget ();
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- if (hItem == 0) return new TreeItem [0];
- return getItems (hItem);
-}
-
-TreeItem [] getItems (int /*long*/ hTreeItem) {
- int count = 0;
- int /*long*/ hItem = hTreeItem;
- while (hItem != 0) {
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
- count++;
- }
- int index = 0;
- TreeItem [] result = new TreeItem [count];
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- tvItem.hItem = hTreeItem;
- /*
- * Feature in Windows. In some cases an expand or collapse message
- * can occur from within TVM_DELETEITEM. When this happens, the item
- * being destroyed has been removed from the list of items but has not
- * been deleted from the tree. The fix is to check for null items and
- * remove them from the list.
- */
- while (tvItem.hItem != 0) {
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- TreeItem item = _getItem (tvItem.hItem, (int)/*64*/tvItem.lParam);
- if (item != null) result [index++] = item;
- tvItem.hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, tvItem.hItem);
- }
- if (index != count) {
- TreeItem [] newResult = new TreeItem [index];
- System.arraycopy (result, 0, newResult, 0, index);
- result = newResult;
- }
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver's lines are visible,
- * and <code>false</code> otherwise. Note that some platforms draw
- * grid lines while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the visibility state of the lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public boolean getLinesVisible () {
- checkWidget ();
- return linesVisible;
-}
-
-int /*long*/ getNextSelection (int /*long*/ hItem, TVITEM tvItem) {
- while (hItem != 0) {
- int state = 0;
- if (OS.IsWinCE) {
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- state = tvItem.state;
- } else {
- state = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETITEMSTATE, hItem, OS.TVIS_SELECTED);
- }
- if ((state & OS.TVIS_SELECTED) != 0) return hItem;
- int /*long*/ hFirstItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hItem);
- int /*long*/ hSelected = getNextSelection (hFirstItem, tvItem);
- if (hSelected != 0) return hSelected;
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
- }
- return 0;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>TreeItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem getParentItem () {
- checkWidget ();
- return null;
-}
-
-int getSelection (int /*long*/ hItem, TVITEM tvItem, TreeItem [] selection, int index, int count, boolean bigSelection, boolean all) {
- while (hItem != 0) {
- if (OS.IsWinCE || bigSelection) {
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- if ((tvItem.state & OS.TVIS_SELECTED) != 0) {
- if (selection != null && index < selection.length) {
- selection [index] = _getItem (hItem, (int)/*64*/tvItem.lParam);
- }
- index++;
- }
- } else {
- int state = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETITEMSTATE, hItem, OS.TVIS_SELECTED);
- if ((state & OS.TVIS_SELECTED) != 0) {
- if (tvItem != null && selection != null && index < selection.length) {
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- selection [index] = _getItem (hItem, (int)/*64*/tvItem.lParam);
- }
- index++;
- }
- }
- if (index == count) break;
- if (all) {
- int /*long*/ hFirstItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hItem);
- if ((index = getSelection (hFirstItem, tvItem, selection, index, count, bigSelection, all)) == count) {
- break;
- }
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
- } else {
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, hItem);
- }
- }
- return index;
-}
-
-/**
- * Returns an array of <code>TreeItem</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem [] getSelection () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem == 0) return new TreeItem [0];
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM | OS.TVIF_STATE;
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- if ((tvItem.state & OS.TVIS_SELECTED) == 0) return new TreeItem [0];
- return new TreeItem [] {_getItem (tvItem.hItem, (int)/*64*/tvItem.lParam)};
- }
- int count = 0;
- TreeItem [] guess = new TreeItem [(style & SWT.VIRTUAL) != 0 ? 8 : 1];
- int /*long*/ oldProc = OS.GetWindowLongPtr (handle, OS.GWLP_WNDPROC);
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, TreeProc);
- if ((style & SWT.VIRTUAL) != 0) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM | OS.TVIF_STATE;
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- count = getSelection (hItem, tvItem, guess, 0, -1, false, true);
- } else {
- TVITEM tvItem = null;
- if (OS.IsWinCE) {
- tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_STATE;
- }
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null) {
- int /*long*/ hItem = item.handle;
- int state = 0;
- if (OS.IsWinCE) {
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- state = tvItem.state;
- } else {
- state = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETITEMSTATE, hItem, OS.TVIS_SELECTED);
- }
- if ((state & OS.TVIS_SELECTED) != 0) {
- if (count < guess.length) guess [count] = item;
- count++;
- }
- }
- }
- }
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, oldProc);
- if (count == 0) return new TreeItem [0];
- if (count == guess.length) return guess;
- TreeItem [] result = new TreeItem [count];
- if (count < guess.length) {
- System.arraycopy (guess, 0, result, 0, count);
- return result;
- }
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, TreeProc);
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM | OS.TVIF_STATE;
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- int itemCount = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETCOUNT, 0, 0);
- boolean bigSelection = result.length > itemCount / 2;
- if (count != getSelection (hItem, tvItem, result, 0, count, bigSelection, false)) {
- getSelection (hItem, tvItem, result, 0, count, bigSelection, true);
- }
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, oldProc);
- return result;
-}
-
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem == 0) return 0;
- int state = 0;
- if (OS.IsWinCE) {
- TVITEM tvItem = new TVITEM ();
- tvItem.hItem = hItem;
- tvItem.mask = OS.TVIF_STATE;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- state = tvItem.state;
- } else {
- state = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETITEMSTATE, hItem, OS.TVIS_SELECTED);
- }
- return (state & OS.TVIS_SELECTED) == 0 ? 0 : 1;
- }
- int count = 0;
- int /*long*/ oldProc = OS.GetWindowLongPtr (handle, OS.GWLP_WNDPROC);
- TVITEM tvItem = null;
- if (OS.IsWinCE) {
- tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_STATE;
- }
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, TreeProc);
- if ((style & SWT.VIRTUAL) != 0) {
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- count = getSelection (hItem, tvItem, null, 0, -1, false, true);
- } else {
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null) {
- int /*long*/ hItem = item.handle;
- int state = 0;
- if (OS.IsWinCE) {
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- state = tvItem.state;
- } else {
- state = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETITEMSTATE, hItem, OS.TVIS_SELECTED);
- }
- if ((state & OS.TVIS_SELECTED) != 0) count++;
- }
- }
- }
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, oldProc);
- return count;
-}
-
-/**
- * Returns the column which shows the sort indicator for
- * the receiver. The value may be null if no column shows
- * the sort indicator.
- *
- * @return the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortColumn(TreeColumn)
- *
- * @since 3.2
- */
-public TreeColumn getSortColumn () {
- checkWidget ();
- return sortColumn;
-}
-
-int getSortColumnPixel () {
- int pixel = OS.IsWindowEnabled (handle) ? getBackgroundPixel () : OS.GetSysColor (OS.COLOR_3DFACE);
- int red = pixel & 0xFF;
- int green = (pixel & 0xFF00) >> 8;
- int blue = (pixel & 0xFF0000) >> 16;
- if (red > 240 && green > 240 && blue > 240) {
- red -= 8;
- green -= 8;
- blue -= 8;
- } else {
- red = Math.min (0xFF, (red / 10) + red);
- green = Math.min (0xFF, (green / 10) + green);
- blue = Math.min (0xFF, (blue / 10) + blue);
- }
- return (red & 0xFF) | ((green & 0xFF) << 8) | ((blue & 0xFF) << 16);
-}
-
-/**
- * Returns the direction of the sort indicator for the receiver.
- * The value will be one of <code>UP</code>, <code>DOWN</code>
- * or <code>NONE</code>.
- *
- * @return the sort direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortDirection(int)
- *
- * @since 3.2
- */
-public int getSortDirection () {
- checkWidget ();
- return sortDirection;
-}
-
-/**
- * Returns the item which is currently at the top of the receiver.
- * This item can change when items are expanded, collapsed, scrolled
- * or new items are added or removed.
- *
- * @return the item at the top of the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public TreeItem getTopItem () {
- checkWidget ();
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0);
- return hItem != 0 ? _getItem (hItem) : null;
-}
-
-boolean hitTestSelection (int /*long*/ hItem, int x, int y) {
- if (hItem == 0) return false;
- TreeItem item = _getItem (hItem);
- if (item == null) return false;
- if (!hooks (SWT.MeasureItem)) return false;
- boolean result = false;
-
- //BUG? - moved columns, only hittest first column
- //BUG? - check drag detect
- int [] order = new int [1], index = new int [1];
-
- int /*long*/ hDC = OS.GetDC (handle);
- int /*long*/ oldFont = 0, newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- int /*long*/ hFont = item.fontHandle (order [index [0]]);
- if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
- Event event = sendMeasureItemEvent (item, order [index [0]], hDC);
- if (event.getBounds ().contains (x, y)) result = true;
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
-// if (isDisposed () || item.isDisposed ()) return false;
- return result;
-}
-
-int imageIndex (Image image, int index) {
- if (image == null) return OS.I_IMAGENONE;
- if (imageList == null) {
- Rectangle bounds = image.getBounds ();
- imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height);
- }
- int imageIndex = imageList.indexOf (image);
- if (imageIndex == -1) imageIndex = imageList.add (image);
- if (hwndHeader == 0 || OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0) == index) {
- /*
- * Feature in Windows. When setting the same image list multiple
- * times, Windows does work making this operation slow. The fix
- * is to test for the same image list before setting the new one.
- */
- int /*long*/ hImageList = imageList.getHandle ();
- int /*long*/ hOldImageList = OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0);
- if (hOldImageList != hImageList) {
- OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_NORMAL, hImageList);
- updateScrollBar ();
- }
- }
- return imageIndex;
-}
-
-int imageIndexHeader (Image image) {
- if (image == null) return OS.I_IMAGENONE;
- if (headerImageList == null) {
- Rectangle bounds = image.getBounds ();
- headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height);
- int index = headerImageList.indexOf (image);
- if (index == -1) index = headerImageList.add (image);
- int /*long*/ hImageList = headerImageList.getHandle ();
- if (hwndHeader != 0) {
- OS.SendMessage (hwndHeader, OS.HDM_SETIMAGELIST, 0, hImageList);
- }
- updateScrollBar ();
- return index;
- }
- int index = headerImageList.indexOf (image);
- if (index != -1) return index;
- return headerImageList.add (image);
-}
-
-/**
- * Searches the receiver's list starting at the first column
- * (index 0) until a column is found that is equal to the
- * argument, and returns the index of that column. If no column
- * is found, returns -1.
- *
- * @param column the search column
- * @return the index of the column
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the column is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int indexOf (TreeColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (column.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<columnCount; i++) {
- if (columns [i] == column) return i;
- }
- return -1;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int indexOf (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- return hItem == 0 ? -1 : findIndex (hItem, item.handle);
-}
-
-boolean isCustomToolTip () {
- return hooks (SWT.MeasureItem);
-}
-
-boolean isItemSelected (NMTVCUSTOMDRAW nmcd) {
- boolean selected = false;
- if (OS.IsWindowEnabled (handle)) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.hItem = nmcd.dwItemSpec;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- if ((tvItem.state & (OS.TVIS_SELECTED | OS.TVIS_DROPHILITED)) != 0) {
- selected = true;
- /*
- * Feature in Windows. When the mouse is pressed and the
- * selection is first drawn for a tree, the previously
- * selected item is redrawn but the the TVIS_SELECTED bits
- * are not cleared. When the user moves the mouse slightly
- * and a drag and drop operation is not started, the item is
- * drawn again and this time with TVIS_SELECTED is cleared.
- * This means that an item that contains colored cells will
- * not draw with the correct background until the mouse is
- * moved. The fix is to test for the selection colors and
- * guess that the item is not selected.
- *
- * NOTE: This code does not work when the foreground and
- * background of the tree are set to the selection colors
- * but this does not happen in a regular application.
- */
- if (handle == OS.GetFocus ()) {
- if (OS.GetTextColor (nmcd.hdc) != OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT)) {
- selected = false;
- } else {
- if (OS.GetBkColor (nmcd.hdc) != OS.GetSysColor (OS.COLOR_HIGHLIGHT)) {
- selected = false;
- }
- }
- }
- } else {
- if (nmcd.dwDrawStage == OS.CDDS_ITEMPOSTPAINT) {
- /*
- * Feature in Windows. When the mouse is pressed and the
- * selection is first drawn for a tree, the item is drawn
- * selected, but the TVIS_SELECTED bits for the item are
- * not set. When the user moves the mouse slightly and
- * a drag and drop operation is not started, the item is
- * drawn again and this time TVIS_SELECTED is set. This
- * means that an item that is in a tree that has the style
- * TVS_FULLROWSELECT and that also contains colored cells
- * will not draw the entire row selected until the user
- * moves the mouse. The fix is to test for the selection
- * colors and guess that the item is selected.
- *
- * NOTE: This code does not work when the foreground and
- * background of the tree are set to the selection colors
- * but this does not happen in a regular application.
- */
- if (OS.GetTextColor (nmcd.hdc) == OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT)) {
- if (OS.GetBkColor (nmcd.hdc) == OS.GetSysColor (OS.COLOR_HIGHLIGHT)) {
- selected = true;
- }
- }
- }
- }
- }
- return selected;
-}
-
-void redrawSelection () {
- if ((style & SWT.SINGLE) != 0) {
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem != 0) {
- RECT rect = new RECT ();
- if (OS.TreeView_GetItemRect (handle, hItem, rect, false)) {
- OS.InvalidateRect (handle, rect, true);
- }
- }
- } else {
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0);
- if (hItem != 0) {
- TVITEM tvItem = null;
- if (OS.IsWinCE) {
- tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_STATE;
- }
- RECT rect = new RECT ();
- int index = 0, count = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETVISIBLECOUNT, 0, 0);
- while (index <= count && hItem != 0) {
- int state = 0;
- if (OS.IsWinCE) {
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- state = tvItem.state;
- } else {
- state = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETITEMSTATE, hItem, OS.TVIS_SELECTED);
- }
- if ((state & OS.TVIS_SELECTED) != 0) {
- if (OS.TreeView_GetItemRect (handle, hItem, rect, false)) {
- OS.InvalidateRect (handle, rect, true);
- }
- }
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, hItem);
- index++;
- }
- }
- }
-}
-
-void register () {
- super.register ();
- if (hwndParent != 0) display.addControl (hwndParent, this);
- if (hwndHeader != 0) display.addControl (hwndHeader, this);
-}
-
-void releaseItem (int /*long*/ hItem, TVITEM tvItem, boolean release) {
- if (hItem == hAnchor) hAnchor = 0;
- if (hItem == hInsert) hInsert = 0;
- tvItem.hItem = hItem;
- if (OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem) != 0) {
- if (tvItem.lParam != -1) {
- if (tvItem.lParam < lastID) lastID = (int)/*64*/tvItem.lParam;
- if (release) {
- TreeItem item = items [(int)/*64*/tvItem.lParam];
- if (item != null) item.release (false);
- }
- items [(int)/*64*/tvItem.lParam] = null;
- }
- }
-}
-
-void releaseItems (int /*long*/ hItem, TVITEM tvItem) {
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hItem);
- while (hItem != 0) {
- releaseItems (hItem, tvItem);
- releaseItem (hItem, tvItem, true);
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
- }
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- hwndParent = hwndHeader = 0;
-}
-
-void releaseChildren (boolean destroy) {
- if (items != null) {
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- items = null;
- }
- if (columns != null) {
- for (int i=0; i<columns.length; i++) {
- TreeColumn column = columns [i];
- if (column != null && !column.isDisposed ()) {
- column.release (false);
- }
- }
- columns = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- /*
- * Feature in Windows. For some reason, when TVM_GETIMAGELIST
- * or TVM_SETIMAGELIST is sent, the tree issues NM_CUSTOMDRAW
- * messages. This behavior is unwanted when the tree is being
- * disposed. The fix is to ignore NM_CUSTOMDRAW messages by
- * clearing the custom draw flag.
- *
- * NOTE: This only happens on Windows XP.
- */
- customDraw = false;
- if (imageList != null) {
- OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_NORMAL, 0);
- display.releaseImageList (imageList);
- }
- if (headerImageList != null) {
- if (hwndHeader != 0) {
- OS.SendMessage (hwndHeader, OS.HDM_SETIMAGELIST, 0, 0);
- }
- display.releaseImageList (headerImageList);
- }
- imageList = headerImageList = null;
- int /*long*/ hStateList = OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_STATE, 0);
- OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_STATE, 0);
- if (hStateList != 0) OS.ImageList_Destroy (hStateList);
- if (itemToolTipHandle != 0) OS.DestroyWindow (itemToolTipHandle);
- if (headerToolTipHandle != 0) OS.DestroyWindow (headerToolTipHandle);
- itemToolTipHandle = headerToolTipHandle = 0;
-}
-
-/**
- * Removes all of the items from the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget ();
- hFirstIndexOf = hLastIndexOf = 0;
- itemCount = -1;
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- ignoreDeselect = ignoreSelect = true;
- boolean redraw = getDrawing () && OS.IsWindowVisible (handle);
- if (redraw) OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- shrink = ignoreShrink = true;
- int /*long*/ result = OS.SendMessage (handle, OS.TVM_DELETEITEM, 0, OS.TVI_ROOT);
- ignoreShrink = false;
- if (redraw) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.InvalidateRect (handle, null, true);
- }
- ignoreDeselect = ignoreSelect = false;
- if (result == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
- if (imageList != null) {
- OS.SendMessage (handle, OS.TVM_SETIMAGELIST, 0, 0);
- display.releaseImageList (imageList);
- }
- imageList = null;
- if (hwndParent == 0 && !linesVisible) {
- if (!hooks (SWT.MeasureItem) && !hooks (SWT.EraseItem) && !hooks (SWT.PaintItem)) {
- customDraw = false;
- }
- }
- hAnchor = hInsert = hFirstIndexOf = hLastIndexOf = 0;
- itemCount = -1;
- items = new TreeItem [4];
- scrollWidth = 0;
- setScrollWidth ();
- updateScrollBar ();
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when items in the receiver are expanded or collapsed.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TreeListener
- * @see #addTreeListener
- */
-public void removeTreeListener(TreeListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Expand, listener);
- eventTable.unhook (SWT.Collapse, listener);
-}
-
-/**
- * Display a mark indicating the point at which an item will be inserted.
- * The drop insert item has a visual hint to show where a dragged item
- * will be inserted when dropped on the tree.
- *
- * @param item the insert item. Null will clear the insertion mark.
- * @param before true places the insert mark above 'item'. false places
- * the insert mark below 'item'.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setInsertMark (TreeItem item, boolean before) {
- checkWidget ();
- int /*long*/ hItem = 0;
- if (item != null) {
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- hItem = item.handle;
- }
- hInsert = hItem;
- insertAfter = !before;
- OS.SendMessage (handle, OS.TVM_SETINSERTMARK, insertAfter ? 1 : 0, hInsert);
-}
-
-/**
- * Sets the number of root-level items contained in the receiver.
- *
- * @param count the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setItemCount (int count) {
- checkWidget ();
- count = Math.max (0, count);
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- setItemCount (count, OS.TVGN_ROOT, hItem);
-}
-
-void setItemCount (int count, int /*long*/ hParent, int /*long*/ hItem) {
- boolean redraw = false;
- if (OS.SendMessage (handle, OS.TVM_GETCOUNT, 0, 0) == 0) {
- redraw = getDrawing () && OS.IsWindowVisible (handle);
- if (redraw) OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- }
- int itemCount = 0;
- while (hItem != 0 && itemCount < count) {
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
- itemCount++;
- }
- boolean expanded = false;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- if (!redraw && (style & SWT.VIRTUAL) != 0) {
- if (OS.IsWinCE) {
- tvItem.hItem = hParent;
- tvItem.mask = OS.TVIF_STATE;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- expanded = (tvItem.state & OS.TVIS_EXPANDED) != 0;
- } else {
- /*
- * Bug in Windows. Despite the fact that TVM_GETITEMSTATE claims
- * to return only the bits specified by the stateMask, when called
- * with TVIS_EXPANDED, the entire state is returned. The fix is
- * to explicitly check for the TVIS_EXPANDED bit.
- */
- int state = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETITEMSTATE, hParent, OS.TVIS_EXPANDED);
- expanded = (state & OS.TVIS_EXPANDED) != 0;
- }
- }
- while (hItem != 0) {
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
- TreeItem item = tvItem.lParam != -1 ? items [(int)/*64*/tvItem.lParam] : null;
- if (item != null && !item.isDisposed ()) {
- item.dispose ();
- } else {
- releaseItem (tvItem.hItem, tvItem, false);
- destroyItem (null, tvItem.hItem);
- }
- }
- if ((style & SWT.VIRTUAL) != 0) {
- for (int i=itemCount; i<count; i++) {
- if (expanded) ignoreShrink = true;
- createItem (null, hParent, OS.TVI_LAST, 0);
- if (expanded) ignoreShrink = false;
- }
- } else {
- shrink = true;
- int extra = Math.max (4, (count + 3) / 4 * 4);
- TreeItem [] newItems = new TreeItem [items.length + extra];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- for (int i=itemCount; i<count; i++) {
- new TreeItem (this, SWT.NONE, hParent, OS.TVI_LAST, 0);
- }
- }
- if (redraw) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.InvalidateRect (handle, null, true);
- }
-}
-
-/**
- * Sets the height of the area which would be used to
- * display <em>one</em> of the items in the tree.
- *
- * @param itemHeight the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-/*public*/ void setItemHeight (int itemHeight) {
- checkWidget ();
- if (itemHeight < -1) error (SWT.ERROR_INVALID_ARGUMENT);
- OS.SendMessage (handle, OS.TVM_SETITEMHEIGHT, itemHeight, 0);
-}
-
-/**
- * Marks the receiver's lines as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise. Note that some platforms draw
- * grid lines while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLinesVisible (boolean show) {
- checkWidget ();
- if (linesVisible == show) return;
- linesVisible = show;
- if (hwndParent == 0 && linesVisible) customDraw = true;
- OS.InvalidateRect (handle, null, true);
-}
-
-int /*long*/ scrolledHandle () {
- if (hwndHeader == 0) return handle;
- return columnCount == 0 && scrollWidth == 0 ? handle : hwndParent;
-}
-
-void select (int /*long*/ hItem, TVITEM tvItem) {
- while (hItem != 0) {
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- int /*long*/ hFirstItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hItem);
- select (hFirstItem, tvItem);
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
- }
-}
-
-/**
- * Selects an item in the receiver. If the item was already
- * selected, it remains selected.
- *
- * @param item the item to be selected
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void select (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.SINGLE) != 0) {
- int /*long*/ hItem = item.handle;
- int state = 0;
- if (OS.IsWinCE) {
- TVITEM tvItem = new TVITEM ();
- tvItem.hItem = hItem;
- tvItem.mask = OS.TVIF_STATE;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- state = tvItem.state;
- } else {
- state = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETITEMSTATE, hItem, OS.TVIS_SELECTED);
- }
- if ((state & OS.TVIS_SELECTED) != 0) return;
- /*
- * Feature in Windows. When an item is selected with
- * TVM_SELECTITEM and TVGN_CARET, the tree expands and
- * scrolls to show the new selected item. Unfortunately,
- * there is no other way in Windows to set the focus
- * and select an item. The fix is to save the current
- * scroll bar positions, turn off redraw, select the item,
- * then scroll back to the original position and redraw
- * the entire tree.
- */
- SCROLLINFO hInfo = null;
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & (OS.TVS_NOHSCROLL | OS.TVS_NOSCROLL)) == 0) {
- hInfo = new SCROLLINFO ();
- hInfo.cbSize = SCROLLINFO.sizeof;
- hInfo.fMask = OS.SIF_ALL;
- OS.GetScrollInfo (handle, OS.SB_HORZ, hInfo);
- }
- SCROLLINFO vInfo = new SCROLLINFO ();
- vInfo.cbSize = SCROLLINFO.sizeof;
- vInfo.fMask = OS.SIF_ALL;
- OS.GetScrollInfo (handle, OS.SB_VERT, vInfo);
- boolean redraw = getDrawing () && OS.IsWindowVisible (handle);
- if (redraw) {
- OS.UpdateWindow (handle);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- }
- setSelection (item);
- if (hInfo != null) {
- int /*long*/ hThumb = OS.MAKELPARAM (OS.SB_THUMBPOSITION, hInfo.nPos);
- OS.SendMessage (handle, OS.WM_HSCROLL, hThumb, 0);
- }
- /*
- * Feature in Windows. It seems that Vista does not
- * use wParam to get the new position when WM_VSCROLL
- * is sent with SB_THUMBPOSITION. The fix is to use
- * SetScrollInfo() to move the scroll bar thumb before
- * calling WM_VSCROLL.
- *
- * NOTE: This code is only necessary on Windows Vista.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- OS.SetScrollInfo (handle, OS.SB_VERT, vInfo, true);
- }
- int /*long*/ vThumb = OS.MAKELPARAM (OS.SB_THUMBPOSITION, vInfo.nPos);
- OS.SendMessage (handle, OS.WM_VSCROLL, vThumb, 0);
- if (redraw) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.InvalidateRect (handle, null, true);
- if ((style & SWT.DOUBLE_BUFFERED) == 0) {
- int oldStyle = style;
- style |= SWT.DOUBLE_BUFFERED;
- OS.UpdateWindow (handle);
- style = oldStyle;
- }
- }
- return;
- }
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_SELECTED;
- tvItem.state = OS.TVIS_SELECTED;
- tvItem.hItem = item.handle;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
-}
-
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.state = OS.TVIS_SELECTED;
- tvItem.stateMask = OS.TVIS_SELECTED;
- int /*long*/ oldProc = OS.GetWindowLongPtr (handle, OS.GWLP_WNDPROC);
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, TreeProc);
- if ((style & SWT.VIRTUAL) != 0) {
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- select (hItem, tvItem);
- } else {
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null) {
- tvItem.hItem = item.handle;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- }
- }
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, oldProc);
-}
-
-Event sendEraseItemEvent (TreeItem item, NMTTCUSTOMDRAW nmcd, int column, RECT cellRect) {
- int nSavedDC = OS.SaveDC (nmcd.hdc);
- RECT insetRect = toolTipInset (cellRect);
- OS.SetWindowOrgEx (nmcd.hdc, insetRect.left, insetRect.top, null);
- GCData data = new GCData ();
- data.device = display;
- data.foreground = OS.GetTextColor (nmcd.hdc);
- data.background = OS.GetBkColor (nmcd.hdc);
- data.font = item.getFont (column);
- data.uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- GC gc = GC.win32_new (nmcd.hdc, data);
- Event event = new Event ();
- event.item = item;
- event.index = column;
- event.gc = gc;
- event.detail |= SWT.FOREGROUND;
- event.x = cellRect.left;
- event.y = cellRect.top;
- event.width = cellRect.right - cellRect.left;
- event.height = cellRect.bottom - cellRect.top;
- //gc.setClipping (event.x, event.y, event.width, event.height);
- sendEvent (SWT.EraseItem, event);
- event.gc = null;
- //int newTextClr = data.foreground;
- gc.dispose ();
- OS.RestoreDC (nmcd.hdc, nSavedDC);
- return event;
-}
-
-Event sendMeasureItemEvent (TreeItem item, int index, int /*long*/ hDC) {
- RECT itemRect = item.getBounds (index, true, true, false, false, false, hDC);
- int nSavedDC = OS.SaveDC (hDC);
- GCData data = new GCData ();
- data.device = display;
- data.font = item.getFont (index);
- GC gc = GC.win32_new (hDC, data);
- Event event = new Event ();
- event.item = item;
- event.gc = gc;
- event.index = index;
- event.x = itemRect.left;
- event.y = itemRect.top;
- event.width = itemRect.right - itemRect.left;
- event.height = itemRect.bottom - itemRect.top;
- sendEvent (SWT.MeasureItem, event);
- event.gc = null;
- gc.dispose ();
- OS.RestoreDC (hDC, nSavedDC);
- if (isDisposed () || item.isDisposed ()) return null;
- if (hwndHeader != 0) {
- if (columnCount == 0) {
- if (event.x + event.width > scrollWidth) {
- setScrollWidth (scrollWidth = event.x + event.width);
- }
- }
- }
- if (event.height > getItemHeight ()) setItemHeight (event.height);
- return event;
-}
-
-Event sendPaintItemEvent (TreeItem item, NMTTCUSTOMDRAW nmcd, int column, RECT itemRect) {
- int nSavedDC = OS.SaveDC (nmcd.hdc);
- RECT insetRect = toolTipInset (itemRect);
- OS.SetWindowOrgEx (nmcd.hdc, insetRect.left, insetRect.top, null);
- GCData data = new GCData ();
- data.device = display;
- data.font = item.getFont (column);
- data.foreground = OS.GetTextColor (nmcd.hdc);
- data.background = OS.GetBkColor (nmcd.hdc);
- data.uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- GC gc = GC.win32_new (nmcd.hdc, data);
- Event event = new Event ();
- event.item = item;
- event.index = column;
- event.gc = gc;
- event.detail |= SWT.FOREGROUND;
- event.x = itemRect.left;
- event.y = itemRect.top;
- event.width = itemRect.right - itemRect.left;
- event.height = itemRect.bottom - itemRect.top;
- //gc.setClipping (cellRect.left, cellRect.top, cellWidth, cellHeight);
- sendEvent (SWT.PaintItem, event);
- event.gc = null;
- gc.dispose ();
- OS.RestoreDC (nmcd.hdc, nSavedDC);
- return event;
-}
-
-void setBackgroundImage (int /*long*/ hBitmap) {
- super.setBackgroundImage (hBitmap);
- if (hBitmap != 0) {
- /*
- * Feature in Windows. If TVM_SETBKCOLOR is never
- * used to set the background color of a tree, the
- * background color of the lines and the plus/minus
- * will be drawn using the default background color,
- * not the HBRUSH returned from WM_CTLCOLOR. The fix
- * is to set the background color to the default (when
- * it is already the default) to make Windows use the
- * brush.
- */
- if (OS.SendMessage (handle, OS.TVM_GETBKCOLOR, 0, 0) == -1) {
- OS.SendMessage (handle, OS.TVM_SETBKCOLOR, 0, -1);
- }
- _setBackgroundPixel (-1);
- } else {
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- if (control.backgroundImage == null) {
- setBackgroundPixel (control.getBackgroundPixel ());
- }
- }
- /*
- * Feature in Windows. When the tree has the style
- * TVS_FULLROWSELECT, the background color for the
- * entire row is filled when an item is painted,
- * drawing on top of the background image. The fix
- * is to clear TVS_FULLROWSELECT when a background
- * image is set.
- */
- updateFullSelection ();
-}
-
-void setBackgroundPixel (int pixel) {
- Control control = findImageControl ();
- if (control != null) {
- setBackgroundImage (control.backgroundImage);
- return;
- }
- /*
- * Feature in Windows. When a tree is given a background color
- * using TVM_SETBKCOLOR and the tree is disabled, Windows draws
- * the tree using the background color rather than the disabled
- * colors. This is different from the table which draws grayed.
- * The fix is to set the default background color while the tree
- * is disabled and restore it when enabled.
- */
- if (OS.IsWindowEnabled (handle)) _setBackgroundPixel (pixel);
-
- /*
- * Feature in Windows. When the tree has the style
- * TVS_FULLROWSELECT, the background color for the
- * entire row is filled when an item is painted,
- * drawing on top of the background image. The fix
- * is to restore TVS_FULLROWSELECT when a background
- * color is set.
- */
- updateFullSelection ();
-}
-
-void setCursor () {
- /*
- * Bug in Windows. Under certain circumstances, when WM_SETCURSOR
- * is sent from SendMessage(), Windows GP's in the window proc for
- * the tree. The fix is to avoid calling the tree window proc and
- * set the cursor for the tree outside of WM_SETCURSOR.
- *
- * NOTE: This code assumes that the default cursor for the tree
- * is IDC_ARROW.
- */
- Cursor cursor = findCursor ();
- int /*long*/ hCursor = cursor == null ? OS.LoadCursor (0, OS.IDC_ARROW) : cursor.handle;
- OS.SetCursor (hCursor);
-}
-
-/**
- * Sets the order that the items in the receiver should
- * be displayed in to the given argument which is described
- * in terms of the zero-relative ordering of when the items
- * were added.
- *
- * @param order the new order to display the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item order is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
-public void setColumnOrder (int [] order) {
- checkWidget ();
- if (order == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (columnCount == 0) {
- if (order.length != 0) error (SWT.ERROR_INVALID_ARGUMENT);
- return;
- }
- if (order.length != columnCount) error (SWT.ERROR_INVALID_ARGUMENT);
- int [] oldOrder = new int [columnCount];
- OS.SendMessage (hwndHeader, OS.HDM_GETORDERARRAY, columnCount, oldOrder);
- boolean reorder = false;
- boolean [] seen = new boolean [columnCount];
- for (int i=0; i<order.length; i++) {
- int index = order [i];
- if (index < 0 || index >= columnCount) error (SWT.ERROR_INVALID_RANGE);
- if (seen [index]) error (SWT.ERROR_INVALID_ARGUMENT);
- seen [index] = true;
- if (index != oldOrder [i]) reorder = true;
- }
- if (reorder) {
- RECT [] oldRects = new RECT [columnCount];
- for (int i=0; i<columnCount; i++) {
- oldRects [i] = new RECT ();
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, i, oldRects [i]);
- }
- OS.SendMessage (hwndHeader, OS.HDM_SETORDERARRAY, order.length, order);
- OS.InvalidateRect (handle, null, true);
- updateImageList ();
- TreeColumn [] newColumns = new TreeColumn [columnCount];
- System.arraycopy (columns, 0, newColumns, 0, columnCount);
- RECT newRect = new RECT ();
- for (int i=0; i<columnCount; i++) {
- TreeColumn column = newColumns [i];
- if (!column.isDisposed ()) {
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, i, newRect);
- if (newRect.left != oldRects [i].left) {
- column.updateToolTip (i);
- column.sendEvent (SWT.Move);
- }
- }
- }
- }
-}
-
-void setCheckboxImageList () {
- if ((style & SWT.CHECK) == 0) return;
- int count = 5, flags = 0;
- if (OS.IsWinCE) {
- flags |= OS.ILC_COLOR;
- } else {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- flags |= OS.ILC_COLOR32;
- } else {
- int /*long*/ hDC = OS.GetDC (handle);
- int bits = OS.GetDeviceCaps (hDC, OS.BITSPIXEL);
- int planes = OS.GetDeviceCaps (hDC, OS.PLANES);
- OS.ReleaseDC (handle, hDC);
- int depth = bits * planes;
- switch (depth) {
- case 4: flags |= OS.ILC_COLOR4; break;
- case 8: flags |= OS.ILC_COLOR8; break;
- case 16: flags |= OS.ILC_COLOR16; break;
- case 24: flags |= OS.ILC_COLOR24; break;
- case 32: flags |= OS.ILC_COLOR32; break;
- default: flags |= OS.ILC_COLOR; break;
- }
- flags |= OS.ILC_MASK;
- }
- }
- if ((style & SWT.RIGHT_TO_LEFT) != 0) flags |= OS.ILC_MIRROR;
- int height = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETITEMHEIGHT, 0, 0), width = height;
- int /*long*/ hStateList = OS.ImageList_Create (width, height, flags, count, count);
- int /*long*/ hDC = OS.GetDC (handle);
- int /*long*/ memDC = OS.CreateCompatibleDC (hDC);
- int /*long*/ hBitmap = OS.CreateCompatibleBitmap (hDC, width * count, height);
- int /*long*/ hOldBitmap = OS.SelectObject (memDC, hBitmap);
- RECT rect = new RECT ();
- OS.SetRect (rect, 0, 0, width * count, height);
- /*
- * NOTE: DrawFrameControl() draws a black and white
- * mask when not drawing a push button. In order to
- * make the box surrounding the check mark transparent,
- * fill it with a color that is neither black or white.
- */
- int clrBackground = 0;
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- clrBackground = control.getBackgroundPixel ();
- } else {
- clrBackground = 0x020000FF;
- if ((clrBackground & 0xFFFFFF) == OS.GetSysColor (OS.COLOR_WINDOW)) {
- clrBackground = 0x0200FF00;
- }
- }
- int /*long*/ hBrush = OS.CreateSolidBrush (clrBackground);
- OS.FillRect (memDC, rect, hBrush);
- OS.DeleteObject (hBrush);
- int /*long*/ oldFont = OS.SelectObject (hDC, defaultFont ());
- TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ();
- OS.GetTextMetrics (hDC, tm);
- OS.SelectObject (hDC, oldFont);
- int itemWidth = Math.min (tm.tmHeight, width);
- int itemHeight = Math.min (tm.tmHeight, height);
- int left = (width - itemWidth) / 2, top = (height - itemHeight) / 2 + 1;
- OS.SetRect (rect, left + width, top, left + width + itemWidth, top + itemHeight);
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- int /*long*/ hTheme = display.hButtonTheme ();
- OS.DrawThemeBackground (hTheme, memDC, OS.BP_CHECKBOX, OS.CBS_UNCHECKEDNORMAL, rect, null);
- rect.left += width; rect.right += width;
- OS.DrawThemeBackground (hTheme, memDC, OS.BP_CHECKBOX, OS.CBS_CHECKEDNORMAL, rect, null);
- rect.left += width; rect.right += width;
- OS.DrawThemeBackground (hTheme, memDC, OS.BP_CHECKBOX, OS.CBS_UNCHECKEDNORMAL, rect, null);
- rect.left += width; rect.right += width;
- OS.DrawThemeBackground (hTheme, memDC, OS.BP_CHECKBOX, OS.CBS_MIXEDNORMAL, rect, null);
- } else {
- OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_FLAT);
- rect.left += width; rect.right += width;
- OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_CHECKED | OS.DFCS_FLAT);
- rect.left += width; rect.right += width;
- OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_INACTIVE | OS.DFCS_FLAT);
- rect.left += width; rect.right += width;
- OS.DrawFrameControl (memDC, rect, OS.DFC_BUTTON, OS.DFCS_BUTTONCHECK | OS.DFCS_CHECKED | OS.DFCS_INACTIVE | OS.DFCS_FLAT);
- }
- OS.SelectObject (memDC, hOldBitmap);
- OS.DeleteDC (memDC);
- OS.ReleaseDC (handle, hDC);
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- OS.ImageList_Add (hStateList, hBitmap, 0);
- } else {
- OS.ImageList_AddMasked (hStateList, hBitmap, clrBackground);
- }
- OS.DeleteObject (hBitmap);
- int /*long*/ hOldStateList = OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_STATE, 0);
- OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_STATE, hStateList);
- if (hOldStateList != 0) OS.ImageList_Destroy (hOldStateList);
-}
-
-public void setFont (Font font) {
- checkWidget ();
- super.setFont (font);
- if ((style & SWT.CHECK) != 0) setCheckboxImageList ();
-}
-
-void setForegroundPixel (int pixel) {
- /*
- * Bug in Windows. When the tree is using the explorer
- * theme, it does not use COLOR_WINDOW_TEXT for the
- * foreground. When TVM_SETTEXTCOLOR is called with -1,
- * it resets the color to black, not COLOR_WINDOW_TEXT.
- * The fix is to explicitly set the color.
- */
- if (explorerTheme) {
- if (pixel == -1) pixel = defaultForeground ();
- }
- OS.SendMessage (handle, OS.TVM_SETTEXTCOLOR, 0, pixel);
-}
-
-/**
- * Marks the receiver's header as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setHeaderVisible (boolean show) {
- checkWidget ();
- if (hwndHeader == 0) {
- if (!show) return;
- createParent ();
- }
- int bits = OS.GetWindowLong (hwndHeader, OS.GWL_STYLE);
- if (show) {
- if ((bits & OS.HDS_HIDDEN) == 0) return;
- bits &= ~OS.HDS_HIDDEN;
- OS.SetWindowLong (hwndHeader, OS.GWL_STYLE, bits);
- OS.ShowWindow (hwndHeader, OS.SW_SHOW);
- } else {
- if ((bits & OS.HDS_HIDDEN) != 0) return;
- bits |= OS.HDS_HIDDEN;
- OS.SetWindowLong (hwndHeader, OS.GWL_STYLE, bits);
- OS.ShowWindow (hwndHeader, OS.SW_HIDE);
- }
- setScrollWidth ();
- updateHeaderToolTips ();
- updateScrollBar ();
-}
-
-public void setRedraw (boolean redraw) {
- checkWidget ();
- /*
- * Feature in Windows. When WM_SETREDRAW is used to
- * turn off redraw, the scroll bars are updated when
- * items are added and removed. The fix is to call
- * the default window proc to stop all drawing.
- *
- * Bug in Windows. For some reason, when WM_SETREDRAW
- * is used to turn redraw on for a tree and the tree
- * contains no items, the last item in the tree does
- * not redraw properly. If the tree has only one item,
- * that item is not drawn. If another window is dragged
- * on top of the item, parts of the item are redrawn
- * and erased at random. The fix is to ensure that this
- * case doesn't happen by inserting and deleting an item
- * when redraw is turned on and there are no items in
- * the tree.
- */
- int /*long*/ hItem = 0;
- if (redraw) {
- if (drawCount == 1) {
- int count = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETCOUNT, 0, 0);
- if (count == 0) {
- TVINSERTSTRUCT tvInsert = new TVINSERTSTRUCT ();
- tvInsert.hInsertAfter = OS.TVI_FIRST;
- hItem = OS.SendMessage (handle, OS.TVM_INSERTITEM, 0, tvInsert);
- }
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- updateScrollBar ();
- }
- }
- super.setRedraw (redraw);
- if (!redraw) {
- if (drawCount == 1) OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- }
- if (hItem != 0) {
- ignoreShrink = true;
- OS.SendMessage (handle, OS.TVM_DELETEITEM, 0, hItem);
- ignoreShrink = false;
- }
-}
-
-void setScrollWidth () {
- if (hwndHeader == 0 || hwndParent == 0) return;
- int width = 0;
- HDITEM hdItem = new HDITEM ();
- for (int i=0; i<columnCount; i++) {
- hdItem.mask = OS.HDI_WIDTH;
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, i, hdItem);
- width += hdItem.cxy;
- }
- setScrollWidth (Math.max (scrollWidth, width));
-}
-
-void setScrollWidth (int width) {
- if (hwndHeader == 0 || hwndParent == 0) return;
- //TEMPORARY CODE
- //scrollWidth = width;
- int left = 0;
- RECT rect = new RECT ();
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_RANGE | OS.SIF_PAGE;
- if (columnCount == 0 && width == 0) {
- OS.GetScrollInfo (hwndParent, OS.SB_HORZ, info);
- info.nPage = info.nMax + 1;
- OS.SetScrollInfo (hwndParent, OS.SB_HORZ, info, true);
- OS.GetScrollInfo (hwndParent, OS.SB_VERT, info);
- info.nPage = info.nMax + 1;
- OS.SetScrollInfo (hwndParent, OS.SB_VERT, info, true);
- } else {
- if ((style & SWT.H_SCROLL) != 0) {
- OS.GetClientRect (hwndParent, rect);
- OS.GetScrollInfo (hwndParent, OS.SB_HORZ, info);
- info.nMax = width;
- info.nPage = rect.right - rect.left + 1;
- OS.SetScrollInfo (hwndParent, OS.SB_HORZ, info, true);
- info.fMask = OS.SIF_POS;
- OS.GetScrollInfo (hwndParent, OS.SB_HORZ, info);
- left = info.nPos;
- }
- }
- if (horizontalBar != null) {
- horizontalBar.setIncrement (INCREMENT);
- horizontalBar.setPageIncrement (info.nPage);
- }
- OS.GetClientRect (hwndParent, rect);
- int /*long*/ hHeap = OS.GetProcessHeap ();
- HDLAYOUT playout = new HDLAYOUT ();
- playout.prc = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, RECT.sizeof);
- playout.pwpos = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, WINDOWPOS.sizeof);
- OS.MoveMemory (playout.prc, rect, RECT.sizeof);
- OS.SendMessage (hwndHeader, OS.HDM_LAYOUT, 0, playout);
- WINDOWPOS pos = new WINDOWPOS ();
- OS.MoveMemory (pos, playout.pwpos, WINDOWPOS.sizeof);
- if (playout.prc != 0) OS.HeapFree (hHeap, 0, playout.prc);
- if (playout.pwpos != 0) OS.HeapFree (hHeap, 0, playout.pwpos);
- SetWindowPos (hwndHeader, OS.HWND_TOP, pos.x - left, pos.y, pos.cx + left, pos.cy, OS.SWP_NOACTIVATE);
- int bits = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
- int b = (bits & OS.WS_EX_CLIENTEDGE) != 0 ? OS.GetSystemMetrics (OS.SM_CXEDGE) : 0;
- int w = pos.cx + (columnCount == 0 && width == 0 ? 0 : OS.GetSystemMetrics (OS.SM_CXVSCROLL));
- int h = rect.bottom - rect.top - pos.cy;
- boolean oldIgnore = ignoreResize;
- ignoreResize = true;
- SetWindowPos (handle, 0, pos.x - left - b, pos.y + pos.cy - b, w + left + b * 2, h + b * 2, OS.SWP_NOACTIVATE | OS.SWP_NOZORDER);
- ignoreResize = oldIgnore;
-}
-
-void setSelection (int /*long*/ hItem, TVITEM tvItem, TreeItem [] selection) {
- while (hItem != 0) {
- int index = 0;
- while (index < selection.length) {
- TreeItem item = selection [index];
- if (item != null && item.handle == hItem) break;
- index++;
- }
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- if ((tvItem.state & OS.TVIS_SELECTED) != 0) {
- if (index == selection.length) {
- tvItem.state = 0;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- } else {
- if (index != selection.length) {
- tvItem.state = OS.TVIS_SELECTED;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- }
- int /*long*/ hFirstItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hItem);
- setSelection (hFirstItem, tvItem, selection);
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
- }
-}
-
-/**
- * Sets the receiver's selection to the given item.
- * The current selection is cleared before the new item is selected.
- * <p>
- * If the item is not in the receiver, then it is ignored.
- * </p>
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (new TreeItem [] {item});
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- * </p>
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the items has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#deselectAll()
- */
-public void setSelection (TreeItem [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = items.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) {
- deselectAll();
- return;
- }
-
- /* Select/deselect the first item */
- TreeItem item = items [0];
- if (item != null) {
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- int /*long*/ hOldItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- int /*long*/ hNewItem = hAnchor = item.handle;
-
- /*
- * Bug in Windows. When TVM_SELECTITEM is used to select and
- * scroll an item to be visible and the client area of the tree
- * is smaller that the size of one item, TVM_SELECTITEM makes
- * the next item in the tree visible by making it the top item
- * instead of making the desired item visible. The fix is to
- * detect the case when the client area is too small and make
- * the desired visible item be the top item in the tree.
- *
- * Note that TVM_SELECTITEM when called with TVGN_FIRSTVISIBLE
- * also requires the work around for scrolling.
- */
- boolean fixScroll = checkScroll (hNewItem);
- if (fixScroll) {
- OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- }
- ignoreSelect = true;
- OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, hNewItem);
- ignoreSelect = false;
- if (OS.SendMessage (handle, OS.TVM_GETVISIBLECOUNT, 0, 0) == 0) {
- OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_FIRSTVISIBLE, hNewItem);
- int /*long*/ hParent = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PARENT, hNewItem);
- if (hParent == 0) OS.SendMessage (handle, OS.WM_HSCROLL, OS.SB_TOP, 0);
- }
- if (fixScroll) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- }
-
- /*
- * Feature in Windows. When the old and new focused item
- * are the same, Windows does not check to make sure that
- * the item is actually selected, not just focused. The
- * fix is to force the item to draw selected by setting
- * the state mask, and to ensure that it is visible.
- */
- if (hOldItem == hNewItem) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.state = OS.TVIS_SELECTED;
- tvItem.stateMask = OS.TVIS_SELECTED;
- tvItem.hItem = hNewItem;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- showItem (hNewItem);
- }
- }
- if ((style & SWT.SINGLE) != 0) return;
-
- /* Select/deselect the rest of the items */
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_SELECTED;
- int /*long*/ oldProc = OS.GetWindowLongPtr (handle, OS.GWLP_WNDPROC);
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, TreeProc);
- if ((style & SWT.VIRTUAL) != 0) {
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- setSelection (hItem, tvItem, items);
- } else {
- for (int i=0; i<this.items.length; i++) {
- item = this.items [i];
- if (item != null) {
- int index = 0;
- while (index < length) {
- if (items [index] == item) break;
- index++;
- }
- tvItem.hItem = item.handle;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- if ((tvItem.state & OS.TVIS_SELECTED) != 0) {
- if (index == length) {
- tvItem.state = 0;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- } else {
- if (index != length) {
- tvItem.state = OS.TVIS_SELECTED;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- }
- }
- }
- }
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, oldProc);
-}
-
-/**
- * Sets the column used by the sort indicator for the receiver. A null
- * value will clear the sort indicator. The current sort column is cleared
- * before the new column is set.
- *
- * @param column the column used by the sort indicator or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the column is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortColumn (TreeColumn column) {
- checkWidget ();
- if (column != null && column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (sortColumn != null && !sortColumn.isDisposed ()) {
- sortColumn.setSortDirection (SWT.NONE);
- }
- sortColumn = column;
- if (sortColumn != null && sortDirection != SWT.NONE) {
- sortColumn.setSortDirection (sortDirection);
- }
-}
-
-/**
- * Sets the direction of the sort indicator for the receiver. The value
- * can be one of <code>UP</code>, <code>DOWN</code> or <code>NONE</code>.
- *
- * @param direction the direction of the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortDirection (int direction) {
- checkWidget ();
- if ((direction & (SWT.UP | SWT.DOWN)) == 0 && direction != SWT.NONE) return;
- sortDirection = direction;
- if (sortColumn != null && !sortColumn.isDisposed ()) {
- sortColumn.setSortDirection (direction);
- }
-}
-
-/**
- * Sets the item which is currently at the top of the receiver.
- * This item can change when items are expanded, collapsed, scrolled
- * or new items are added or removed.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getTopItem()
- *
- * @since 2.1
- */
-public void setTopItem (TreeItem item) {
- checkWidget ();
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- int /*long*/ hItem = item.handle;
- int /*long*/ hTopItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0);
- if (hItem == hTopItem) return;
- boolean fixScroll = checkScroll (hItem), redraw = false;
- if (fixScroll) {
- OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- } else {
- redraw = getDrawing () && OS.IsWindowVisible (handle);
- if (redraw) OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- }
- OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_FIRSTVISIBLE, hItem);
- int /*long*/ hParent = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PARENT, hItem);
- if (hParent == 0) OS.SendMessage (handle, OS.WM_HSCROLL, OS.SB_TOP, 0);
- if (fixScroll) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- } else {
- if (redraw) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.InvalidateRect (handle, null, true);
- }
- }
- updateScrollBar ();
-}
-
-void showItem (int /*long*/ hItem) {
- /*
- * Bug in Windows. When TVM_ENSUREVISIBLE is used to ensure
- * that an item is visible and the client area of the tree is
- * smaller that the size of one item, TVM_ENSUREVISIBLE makes
- * the next item in the tree visible by making it the top item
- * instead of making the desired item visible. The fix is to
- * detect the case when the client area is too small and make
- * the desired visible item be the top item in the tree.
- */
- if (OS.SendMessage (handle, OS.TVM_GETVISIBLECOUNT, 0, 0) == 0) {
- boolean fixScroll = checkScroll (hItem);
- if (fixScroll) {
- OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- }
- OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_FIRSTVISIBLE, hItem);
- /* This code is intentionally commented */
- //int hParent = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PARENT, hItem);
- //if (hParent == 0) OS.SendMessage (handle, OS.WM_HSCROLL, OS.SB_TOP, 0);
- OS.SendMessage (handle, OS.WM_HSCROLL, OS.SB_TOP, 0);
- if (fixScroll) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- }
- } else {
- boolean scroll = true;
- RECT itemRect = new RECT ();
- if (OS.TreeView_GetItemRect (handle, hItem, itemRect, true)) {
- forceResize ();
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- POINT pt = new POINT ();
- pt.x = itemRect.left;
- pt.y = itemRect.top;
- if (OS.PtInRect (rect, pt)) {
- pt.y = itemRect.bottom;
- if (OS.PtInRect (rect, pt)) scroll = false;
- }
- }
- if (scroll) {
- boolean fixScroll = checkScroll (hItem);
- if (fixScroll) {
- OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- }
- OS.SendMessage (handle, OS.TVM_ENSUREVISIBLE, 0, hItem);
- if (fixScroll) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- }
- }
- }
- if (hwndParent != 0) {
- RECT itemRect = new RECT ();
- if (OS.TreeView_GetItemRect (handle, hItem, itemRect, true)) {
- forceResize ();
- RECT rect = new RECT ();
- OS.GetClientRect (hwndParent, rect);
- OS.MapWindowPoints (hwndParent, handle, rect, 2);
- POINT pt = new POINT ();
- pt.x = itemRect.left;
- pt.y = itemRect.top;
- if (!OS.PtInRect (rect, pt)) {
- pt.y = itemRect.bottom;
- if (!OS.PtInRect (rect, pt)) {
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_POS;
- info.nPos = Math.max (0, pt.x - Tree.INSET / 2);
- OS.SetScrollInfo (hwndParent, OS.SB_HORZ, info, true);
- setScrollWidth ();
- }
- }
- }
- }
- updateScrollBar ();
-}
-
-/**
- * Shows the column. If the column is already showing in the receiver,
- * this method simply returns. Otherwise, the columns are scrolled until
- * the column is visible.
- *
- * @param column the column to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void showColumn (TreeColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (column.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (column.parent != this) return;
- int index = indexOf (column);
- if (index == -1) return;
- if (0 <= index && index < columnCount) {
- forceResize ();
- RECT rect = new RECT ();
- OS.GetClientRect (hwndParent, rect);
- OS.MapWindowPoints (hwndParent, handle, rect, 2);
- RECT headerRect = new RECT ();
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect);
- boolean scroll = headerRect.left < rect.left;
- if (!scroll) {
- int width = Math.min (rect.right - rect.left, headerRect.right - headerRect.left);
- scroll = headerRect.left + width > rect.right;
- }
- if (scroll) {
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_POS;
- info.nPos = Math.max (0, headerRect.left - Tree.INSET / 2);
- OS.SetScrollInfo (hwndParent, OS.SB_HORZ, info, true);
- setScrollWidth ();
- }
- }
-}
-
-/**
- * Shows the item. If the item is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled
- * and expanded until the item is visible.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#showSelection()
- */
-public void showItem (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- showItem (item.handle);
-}
-
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#showItem(TreeItem)
- */
-public void showSelection () {
- checkWidget ();
- int /*long*/ hItem = 0;
- if ((style & SWT.SINGLE) != 0) {
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem == 0) return;
- int state = 0;
- if (OS.IsWinCE) {
- TVITEM tvItem = new TVITEM ();
- tvItem.hItem = hItem;
- tvItem.mask = OS.TVIF_STATE;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- state = tvItem.state;
- } else {
- state = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETITEMSTATE, hItem, OS.TVIS_SELECTED);
- }
- if ((state & OS.TVIS_SELECTED) == 0) return;
- } else {
- int /*long*/ oldProc = OS.GetWindowLongPtr (handle, OS.GWLP_WNDPROC);
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, TreeProc);
- TVITEM tvItem = null;
- if (OS.IsWinCE) {
- tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_STATE;
- }
- if ((style & SWT.VIRTUAL) != 0) {
- int /*long*/ hRoot = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- hItem = getNextSelection (hRoot, tvItem);
- } else {
- //FIXME - this code expands first selected item it finds
- int index = 0;
- while (index <items.length) {
- TreeItem item = items [index];
- if (item != null) {
- int state = 0;
- if (OS.IsWinCE) {
- tvItem.hItem = item.handle;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- state = tvItem.state;
- } else {
- state = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETITEMSTATE, item.handle, OS.TVIS_SELECTED);
- }
- if ((state & OS.TVIS_SELECTED) != 0) {
- hItem = item.handle;
- break;
- }
- }
- index++;
- }
- }
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, oldProc);
- }
- if (hItem != 0) showItem (hItem);
-}
-
-/*public*/ void sort () {
- checkWidget ();
- if ((style & SWT.VIRTUAL) != 0) return;
- sort (OS.TVI_ROOT, false);
-}
-
-void sort (int /*long*/ hParent, boolean all) {
- int itemCount = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETCOUNT, 0, 0);
- if (itemCount == 0 || itemCount == 1) return;
- hFirstIndexOf = hLastIndexOf = 0;
- itemCount = -1;
- if (sortDirection == SWT.UP || sortDirection == SWT.NONE) {
- OS.SendMessage (handle, OS.TVM_SORTCHILDREN, all ? 1 : 0, hParent);
- } else {
- Callback compareCallback = new Callback (this, "CompareFunc", 3);
- int /*long*/ lpfnCompare = compareCallback.getAddress ();
- TVSORTCB psort = new TVSORTCB ();
- psort.hParent = hParent;
- psort.lpfnCompare = lpfnCompare;
- psort.lParam = sortColumn == null ? 0 : indexOf (sortColumn);
- OS.SendMessage (handle, OS.TVM_SORTCHILDRENCB, all ? 1 : 0, psort);
- compareCallback.dispose ();
- }
-}
-
-void subclass () {
- super.subclass ();
- if (hwndHeader != 0) {
- OS.SetWindowLongPtr (hwndHeader, OS.GWLP_WNDPROC, display.windowProc);
- }
-}
-
-RECT toolTipInset (RECT rect) {
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- RECT insetRect = new RECT ();
- OS.SetRect (insetRect, rect.left - 1, rect.top - 1, rect.right + 1, rect.bottom + 1);
- return insetRect;
- }
- return rect;
-}
-
-RECT toolTipRect (RECT rect) {
- RECT toolRect = new RECT ();
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- OS.SetRect (toolRect, rect.left - 1, rect.top - 1, rect.right + 1, rect.bottom + 1);
- } else {
- OS.SetRect (toolRect, rect.left, rect.top, rect.right, rect.bottom);
- int dwStyle = OS.GetWindowLong (itemToolTipHandle, OS.GWL_STYLE);
- int dwExStyle = OS.GetWindowLong (itemToolTipHandle, OS.GWL_EXSTYLE);
- OS.AdjustWindowRectEx (toolRect, dwStyle, false, dwExStyle);
- }
- return toolRect;
-}
-
-String toolTipText (NMTTDISPINFO hdr) {
- int /*long*/ hwndToolTip = OS.SendMessage (handle, OS.TVM_GETTOOLTIPS, 0, 0);
- if (hwndToolTip == hdr.hwndFrom && toolTipText != null) return ""; //$NON-NLS-1$
- if (headerToolTipHandle == hdr.hwndFrom) {
- for (int i=0; i<columnCount; i++) {
- TreeColumn column = columns [i];
- if (column.id == hdr.idFrom) return column.toolTipText;
- }
- return super.toolTipText (hdr);
- }
- if (itemToolTipHandle == hdr.hwndFrom) {
- if (toolTipText != null) return "";
- int pos = OS.GetMessagePos ();
- POINT pt = new POINT();
- OS.POINTSTOPOINT (pt, pos);
- OS.ScreenToClient (handle, pt);
- int [] index = new int [1];
- TreeItem [] item = new TreeItem [1];
- RECT [] cellRect = new RECT [1], itemRect = new RECT [1];
- if (findCell (pt.x, pt.y, item, index, cellRect, itemRect)) {
- String text = null;
- if (index [0] == 0) {
- text = item [0].text;
- } else {
- String[] strings = item [0].strings;
- if (strings != null) text = strings [index [0]];
- }
- //TEMPORARY CODE
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- if (isCustomToolTip ()) text = " ";
- }
- if (text != null) return text;
- }
- }
- return super.toolTipText (hdr);
-}
-
-int /*long*/ topHandle () {
- return hwndParent != 0 ? hwndParent : handle;
-}
-
-void updateFullSelection () {
- if ((style & SWT.FULL_SELECTION) != 0) {
- int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE), newBits = oldBits;
- if ((newBits & OS.TVS_FULLROWSELECT) != 0) {
- if (!OS.IsWindowEnabled (handle) || findImageControl () != null) {
- if (!explorerTheme) newBits &= ~OS.TVS_FULLROWSELECT;
- }
- } else {
- if (OS.IsWindowEnabled (handle) && findImageControl () == null) {
- if (!hooks (SWT.EraseItem) && !hooks (SWT.PaintItem)) {
- newBits |= OS.TVS_FULLROWSELECT;
- }
- }
- }
- if (newBits != oldBits) {
- OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
- OS.InvalidateRect (handle, null, true);
- }
- }
-}
-
-void updateHeaderToolTips () {
- if (headerToolTipHandle == 0) return;
- RECT rect = new RECT ();
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- lpti.uFlags = OS.TTF_SUBCLASS;
- lpti.hwnd = hwndHeader;
- lpti.lpszText = OS.LPSTR_TEXTCALLBACK;
- for (int i=0; i<columnCount; i++) {
- TreeColumn column = columns [i];
- if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, i, rect) != 0) {
- lpti.uId = column.id = display.nextToolTipId++;
- lpti.left = rect.left;
- lpti.top = rect.top;
- lpti.right = rect.right;
- lpti.bottom = rect.bottom;
- OS.SendMessage (headerToolTipHandle, OS.TTM_ADDTOOL, 0, lpti);
- }
- }
-}
-
-void updateImageList () {
- if (imageList == null) return;
- if (hwndHeader == 0) return;
- int i = 0, index = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0);
- while (i < items.length) {
- TreeItem item = items [i];
- if (item != null) {
- Image image = null;
- if (index == 0) {
- image = item.image;
- } else {
- Image [] images = item.images;
- if (images != null) image = images [index];
- }
- if (image != null) break;
- }
- i++;
- }
- /*
- * Feature in Windows. When setting the same image list multiple
- * times, Windows does work making this operation slow. The fix
- * is to test for the same image list before setting the new one.
- */
- int /*long*/ hImageList = i == items.length ? 0 : imageList.getHandle ();
- int /*long*/ hOldImageList = OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0);
- if (hImageList != hOldImageList) {
- OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_NORMAL, hImageList);
- }
-}
-
-void updateImages () {
- if (sortColumn != null && !sortColumn.isDisposed ()) {
- if (OS.COMCTL32_MAJOR < 6) {
- switch (sortDirection) {
- case SWT.UP:
- case SWT.DOWN:
- sortColumn.setImage (display.getSortImage (sortDirection), true, true);
- break;
- }
- }
- }
-}
-
-void updateScrollBar () {
- if (hwndParent != 0) {
- if (columnCount != 0 || scrollWidth != 0) {
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_ALL;
- int itemCount = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETCOUNT, 0, 0);
- if (itemCount == 0) {
- OS.GetScrollInfo (hwndParent, OS.SB_VERT, info);
- info.nPage = info.nMax + 1;
- OS.SetScrollInfo (hwndParent, OS.SB_VERT, info, true);
- } else {
- OS.GetScrollInfo (handle, OS.SB_VERT, info);
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
- if (info.nPage == 0) {
- SCROLLBARINFO psbi = new SCROLLBARINFO ();
- psbi.cbSize = SCROLLBARINFO.sizeof;
- OS.GetScrollBarInfo (handle, OS.OBJID_VSCROLL, psbi);
- if ((psbi.rgstate [0] & OS.STATE_SYSTEM_INVISIBLE) != 0) {
- info.nPage = info.nMax + 1;
- }
- }
- }
- OS.SetScrollInfo (hwndParent, OS.SB_VERT, info, true);
- }
- }
- }
-}
-
-void unsubclass () {
- super.unsubclass ();
- if (hwndHeader != 0) {
- OS.SetWindowLongPtr (hwndHeader, OS.GWLP_WNDPROC, HeaderProc);
- }
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle () | OS.TVS_SHOWSELALWAYS | OS.TVS_LINESATROOT | OS.TVS_HASBUTTONS | OS.TVS_NONEVENHEIGHT;
- if (EXPLORER_THEME && !OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0) && OS.IsAppThemed ()) {
- bits |= OS.TVS_TRACKSELECT;
- if ((style & SWT.FULL_SELECTION) != 0) bits |= OS.TVS_FULLROWSELECT;
- } else {
- if ((style & SWT.FULL_SELECTION) != 0) {
- bits |= OS.TVS_FULLROWSELECT;
- } else {
- bits |= OS.TVS_HASLINES;
- }
- }
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
- bits &= ~(OS.WS_HSCROLL | OS.WS_VSCROLL);
- bits |= OS.TVS_NOSCROLL;
- } else {
- if ((style & SWT.H_SCROLL) == 0) {
- bits &= ~OS.WS_HSCROLL;
- bits |= OS.TVS_NOHSCROLL;
- }
- }
-// bits |= OS.TVS_NOTOOLTIPS | OS.TVS_DISABLEDRAGDROP;
- return bits | OS.TVS_DISABLEDRAGDROP;
-}
-
-TCHAR windowClass () {
- return TreeClass;
-}
-
-int /*long*/ windowProc () {
- return TreeProc;
-}
-
-int /*long*/ windowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (hwndHeader != 0 && hwnd == hwndHeader) {
- switch (msg) {
- case OS.WM_CONTEXTMENU: {
- LRESULT result = wmContextMenu (hwnd, wParam, lParam);
- if (result != null) return result.value;
- break;
- }
- case OS.WM_CAPTURECHANGED: {
- /*
- * Bug in Windows. When the capture changes during a
- * header drag, Windows does not redraw the header item
- * such that the header remains pressed. For example,
- * when focus is assigned to a push button, the mouse is
- * pressed (but not released), then the SPACE key is
- * pressed to activate the button, the capture changes,
- * the header not notified and NM_RELEASEDCAPTURE is not
- * sent. The fix is to redraw the header when the capture
- * changes to another control.
- *
- * This does not happen on XP.
- */
- if (OS.COMCTL32_MAJOR < 6) {
- if (lParam != 0 && lParam != hwndHeader) {
- OS.InvalidateRect (hwndHeader, null, true);
- }
- }
- break;
- }
- case OS.WM_MOUSELEAVE: {
- /*
- * Bug in Windows. On XP, when a tooltip is hidden
- * due to a time out or mouse press, the tooltip
- * remains active although no longer visible and
- * won't show again until another tooltip becomes
- * active. The fix is to reset the tooltip bounds.
- */
- if (OS.COMCTL32_MAJOR >= 6) updateHeaderToolTips ();
- updateHeaderToolTips ();
- break;
- }
- case OS.WM_NOTIFY: {
- NMHDR hdr = new NMHDR ();
- OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
- switch (hdr.code) {
- case OS.TTN_SHOW:
- case OS.TTN_POP:
- case OS.TTN_GETDISPINFOA:
- case OS.TTN_GETDISPINFOW:
- return OS.SendMessage (handle, msg, wParam, lParam);
- }
- break;
- }
- case OS.WM_SETCURSOR: {
- if (wParam == hwnd) {
- int hitTest = (short) OS.LOWORD (lParam);
- if (hitTest == OS.HTCLIENT) {
- HDHITTESTINFO pinfo = new HDHITTESTINFO ();
- int pos = OS.GetMessagePos ();
- POINT pt = new POINT ();
- OS.POINTSTOPOINT (pt, pos);
- OS.ScreenToClient (hwnd, pt);
- pinfo.x = pt.x;
- pinfo.y = pt.y;
- int index = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_HITTEST, 0, pinfo);
- if (0 <= index && index < columnCount && !columns [index].resizable) {
- if ((pinfo.flags & (OS.HHT_ONDIVIDER | OS.HHT_ONDIVOPEN)) != 0) {
- OS.SetCursor (OS.LoadCursor (0, OS.IDC_ARROW));
- return 1;
- }
- }
- }
- }
- break;
- }
- }
- return callWindowProc (hwnd, msg, wParam, lParam);
- }
- if (hwndParent != 0 && hwnd == hwndParent) {
- switch (msg) {
- case OS.WM_MOVE: {
- sendEvent (SWT.Move);
- return 0;
- }
- case OS.WM_SIZE: {
- setScrollWidth ();
- if (ignoreResize) return 0;
- setResizeChildren (false);
- int /*long*/ code = callWindowProc (hwnd, OS.WM_SIZE, wParam, lParam);
- sendEvent (SWT.Resize);
- if (isDisposed ()) return 0;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false, false);
- }
- setResizeChildren (true);
- updateScrollBar ();
- return code;
- }
- case OS.WM_NCPAINT: {
- LRESULT result = wmNCPaint (hwnd, wParam, lParam);
- if (result != null) return result.value;
- break;
- }
- case OS.WM_PRINT: {
- LRESULT result = wmPrint (hwnd, wParam, lParam);
- if (result != null) return result.value;
- break;
- }
- case OS.WM_COMMAND:
- case OS.WM_NOTIFY:
- case OS.WM_SYSCOLORCHANGE: {
- return OS.SendMessage (handle, msg, wParam, lParam);
- }
- case OS.WM_HSCROLL: {
- /*
- * Bug on WinCE. lParam should be NULL when the message is not sent
- * by a scroll bar control, but it contains the handle to the window.
- * When the message is sent by a scroll bar control, it correctly
- * contains the handle to the scroll bar. The fix is to check for
- * both.
- */
- if (horizontalBar != null && (lParam == 0 || lParam == hwndParent)) {
- wmScroll (horizontalBar, true, hwndParent, OS.WM_HSCROLL, wParam, lParam);
- }
- setScrollWidth ();
- break;
- }
- case OS.WM_VSCROLL: {
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_ALL;
- OS.GetScrollInfo (hwndParent, OS.SB_VERT, info);
- /*
- * Update the nPos field to match the nTrackPos field
- * so that the tree scrolls when the scroll bar of the
- * parent is dragged.
- *
- * NOTE: For some reason, this code is only necessary
- * on Windows Vista.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- if (OS.LOWORD (wParam) == OS.SB_THUMBTRACK) {
- info.nPos = info.nTrackPos;
- }
- }
- OS.SetScrollInfo (handle, OS.SB_VERT, info, true);
- int /*long*/ code = OS.SendMessage (handle, OS.WM_VSCROLL, wParam, lParam);
- OS.GetScrollInfo (handle, OS.SB_VERT, info);
- OS.SetScrollInfo (hwndParent, OS.SB_VERT, info, true);
- return code;
- }
- }
- return callWindowProc (hwnd, msg, wParam, lParam);
- }
- if (msg == Display.DI_GETDRAGIMAGE) {
- /*
- * When there is more than one item selected, DI_GETDRAGIMAGE
- * returns the item under the cursor. This happens because
- * the tree does not have implement multi-select. The fix
- * is to disable DI_GETDRAGIMAGE when more than one item is
- * selected.
- */
- if ((style & SWT.MULTI) != 0 || hooks (SWT.EraseItem) || hooks (SWT.PaintItem)) {
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0);
- TreeItem [] items = new TreeItem [10];
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM | OS.TVIF_STATE;
- int count = getSelection (hItem, tvItem, items, 0, 10, false, true);
- if (count == 0) return 0;
- POINT mousePos = new POINT ();
- OS.POINTSTOPOINT (mousePos, OS.GetMessagePos ());
- OS.MapWindowPoints (0, handle, mousePos, 1);
- RECT clientRect = new RECT ();
- OS.GetClientRect(handle, clientRect);
- RECT rect = items [0].getBounds (0, true, true, false);
- if ((style & SWT.FULL_SELECTION) != 0) {
- int width = DRAG_IMAGE_SIZE;
- rect.left = Math.max (clientRect.left, mousePos.x - width / 2);
- if (clientRect.right > rect.left + width) {
- rect.right = rect.left + width;
- } else {
- rect.right = clientRect.right;
- rect.left = Math.max (clientRect.left, rect.right - width);
- }
- } else {
- rect.left = Math.max (rect.left, clientRect.left);
- rect.right = Math.min (rect.right, clientRect.right);
- }
- int /*long*/ hRgn = OS.CreateRectRgn (rect.left, rect.top, rect.right, rect.bottom);
- for (int i = 1; i < count; i++) {
- if (rect.bottom - rect.top > DRAG_IMAGE_SIZE) break;
- if (rect.bottom > clientRect.bottom) break;
- RECT itemRect = items[i].getBounds (0, true, true, false);
- if ((style & SWT.FULL_SELECTION) != 0) {
- itemRect.left = rect.left;
- itemRect.right = rect.right;
- } else {
- itemRect.left = Math.max (itemRect.left, clientRect.left);
- itemRect.right = Math.min (itemRect.right, clientRect.right);
- }
- int /*long*/ rectRgn = OS.CreateRectRgn (itemRect.left, itemRect.top, itemRect.right, itemRect.bottom);
- OS.CombineRgn (hRgn, hRgn, rectRgn, OS.RGN_OR);
- OS.DeleteObject (rectRgn);
- rect.bottom = itemRect.bottom;
-
- }
- OS.GetRgnBox (hRgn, rect);
-
- /* Create resources */
- int /*long*/ hdc = OS.GetDC (handle);
- int /*long*/ memHdc = OS.CreateCompatibleDC (hdc);
- BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER ();
- bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
- bmiHeader.biWidth = rect.right - rect.left;
- bmiHeader.biHeight = -(rect.bottom - rect.top);
- bmiHeader.biPlanes = 1;
- bmiHeader.biBitCount = 32;
- bmiHeader.biCompression = OS.BI_RGB;
- byte [] bmi = new byte [BITMAPINFOHEADER.sizeof];
- OS.MoveMemory (bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
- int /*long*/ [] pBits = new int /*long*/ [1];
- int /*long*/ memDib = OS.CreateDIBSection (0, bmi, OS.DIB_RGB_COLORS, pBits, 0, 0);
- if (memDib == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- int /*long*/ oldMemBitmap = OS.SelectObject (memHdc, memDib);
- int colorKey = 0x0000FD;
- POINT pt = new POINT ();
- OS.SetWindowOrgEx (memHdc, rect.left, rect.top, pt);
- OS.FillRect (memHdc, rect, findBrush (colorKey, OS.BS_SOLID));
- OS.OffsetRgn (hRgn, -rect.left, -rect.top);
- OS.SelectClipRgn (memHdc, hRgn);
- OS.PrintWindow (handle, memHdc, 0);
- OS.SetWindowOrgEx (memHdc, pt.x, pt.y, null);
- OS.SelectObject (memHdc, oldMemBitmap);
- OS.DeleteDC (memHdc);
- OS.ReleaseDC (0, hdc);
- OS.DeleteObject (hRgn);
-
- SHDRAGIMAGE shdi = new SHDRAGIMAGE ();
- shdi.hbmpDragImage = memDib;
- shdi.crColorKey = colorKey;
- shdi.sizeDragImage.cx = bmiHeader.biWidth;
- shdi.sizeDragImage.cy = -bmiHeader.biHeight;
- shdi.ptOffset.x = mousePos.x - rect.left;
- shdi.ptOffset.y = mousePos.y - rect.top;
- if ((style & SWT.MIRRORED) != 0) {
- shdi.ptOffset.x = shdi.sizeDragImage.cx - shdi.ptOffset.x;
- }
- OS.MoveMemory (lParam, shdi, SHDRAGIMAGE.sizeof);
- return 1;
- }
- }
- return super.windowProc (hwnd, msg, wParam, lParam);
-}
-
-LRESULT WM_CHAR (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_CHAR (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. The tree control beeps
- * in WM_CHAR when the search for the item that
- * matches the key stroke fails. This is the
- * standard tree behavior but is unexpected when
- * the key that was typed was ESC, CR or SPACE.
- * The fix is to avoid calling the tree window
- * proc in these cases.
- */
- switch ((int)/*64*/wParam) {
- case ' ': {
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem != 0) {
- hAnchor = hItem;
- OS.SendMessage (handle, OS.TVM_ENSUREVISIBLE, 0, hItem);
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE | OS.TVIF_PARAM;
- tvItem.hItem = hItem;
- if ((style & SWT.CHECK) != 0) {
- tvItem.stateMask = OS.TVIS_STATEIMAGEMASK;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- int state = tvItem.state >> 12;
- if ((state & 0x1) != 0) {
- state++;
- } else {
- --state;
- }
- tvItem.state = state << 12;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- if (!OS.IsWinCE) {
- int /*long*/ id = hItem;
- if (OS.COMCTL32_MAJOR >= 6) {
- id = OS.SendMessage (handle, OS.TVM_MAPHTREEITEMTOACCID, hItem, 0);
- }
- OS.NotifyWinEvent (OS.EVENT_OBJECT_FOCUS, handle, OS.OBJID_CLIENT, (int)/*64*/id);
- }
- }
- tvItem.stateMask = OS.TVIS_SELECTED;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- if ((style & SWT.MULTI) != 0 && OS.GetKeyState (OS.VK_CONTROL) < 0) {
- if ((tvItem.state & OS.TVIS_SELECTED) != 0) {
- tvItem.state &= ~OS.TVIS_SELECTED;
- } else {
- tvItem.state |= OS.TVIS_SELECTED;
- }
- } else {
- tvItem.state |= OS.TVIS_SELECTED;
- }
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- TreeItem item = _getItem (hItem, (int)/*64*/tvItem.lParam);
- Event event = new Event ();
- event.item = item;
- postEvent (SWT.Selection, event);
- if ((style & SWT.CHECK) != 0) {
- event = new Event ();
- event.item = item;
- event.detail = SWT.CHECK;
- postEvent (SWT.Selection, event);
- }
- }
- return LRESULT.ZERO;
- }
- case SWT.CR: {
- /*
- * Feature in Windows. Windows sends NM_RETURN from WM_KEYDOWN
- * instead of using WM_CHAR. This means that application code
- * that expects to consume the key press and therefore avoid a
- * SWT.DefaultSelection event from WM_CHAR will fail. The fix
- * is to implement SWT.DefaultSelection in WM_CHAR instead of
- * using NM_RETURN.
- */
- Event event = new Event ();
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem != 0) event.item = _getItem (hItem);
- postEvent (SWT.DefaultSelection, event);
- return LRESULT.ZERO;
- }
- case SWT.ESC:
- return LRESULT.ZERO;
- }
- return result;
-}
-
-LRESULT WM_ERASEBKGND (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
- if ((style & SWT.DOUBLE_BUFFERED) != 0) return LRESULT.ONE;
- if (findImageControl () != null) return LRESULT.ONE;
- return result;
-}
-
-LRESULT WM_GETOBJECT (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Ensure that there is an accessible object created for this
- * control because support for checked item and tree column
- * accessibility is temporarily implemented in the accessibility
- * package.
- */
- if ((style & SWT.CHECK) != 0 || hwndParent != 0) {
- if (accessible == null) accessible = new_Accessible (this);
- }
- return super.WM_GETOBJECT (wParam, lParam);
-}
-
-LRESULT WM_HSCROLL (int /*long*/ wParam, int /*long*/ lParam) {
- boolean fixScroll = false;
- if ((style & SWT.DOUBLE_BUFFERED) != 0) {
- fixScroll = (style & SWT.VIRTUAL) != 0 || hooks (SWT.EraseItem) || hooks (SWT.PaintItem);
- }
- if (fixScroll) {
- style &= ~SWT.DOUBLE_BUFFERED;
- if (explorerTheme) {
- OS.SendMessage (handle, OS.TVM_SETEXTENDEDSTYLE, OS.TVS_EX_DOUBLEBUFFER, 0);
- }
- }
- LRESULT result = super.WM_HSCROLL (wParam, lParam);
- if (fixScroll) {
- style |= SWT.DOUBLE_BUFFERED;
- if (explorerTheme) {
- OS.SendMessage (handle, OS.TVM_SETEXTENDEDSTYLE, OS.TVS_EX_DOUBLEBUFFER, OS.TVS_EX_DOUBLEBUFFER);
- }
- }
- if (result != null) return result;
- return result;
-}
-
-LRESULT WM_KEYDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_KEYDOWN (wParam, lParam);
- if (result != null) return result;
- switch ((int)/*64*/wParam) {
- case OS.VK_SPACE:
- /*
- * Ensure that the window proc does not process VK_SPACE
- * so that it can be handled in WM_CHAR. This allows the
- * application to cancel an operation that is normally
- * performed in WM_KEYDOWN from WM_CHAR.
- */
- return LRESULT.ZERO;
- case OS.VK_ADD:
- if (OS.GetKeyState (OS.VK_CONTROL) < 0) {
- if (hwndHeader != 0) {
- TreeColumn [] newColumns = new TreeColumn [columnCount];
- System.arraycopy (columns, 0, newColumns, 0, columnCount);
- for (int i=0; i<columnCount; i++) {
- TreeColumn column = newColumns [i];
- if (!column.isDisposed () && column.getResizable ()) {
- column.pack ();
- }
- }
- }
- }
- break;
- case OS.VK_UP:
- case OS.VK_DOWN:
- case OS.VK_PRIOR:
- case OS.VK_NEXT:
- case OS.VK_HOME:
- case OS.VK_END: {
- OS.SendMessage (handle, OS.WM_CHANGEUISTATE, OS.UIS_INITIALIZE, 0);
- if (itemToolTipHandle != 0) OS.ShowWindow (itemToolTipHandle, OS.SW_HIDE);
- if ((style & SWT.SINGLE) != 0) break;
- if (OS.GetKeyState (OS.VK_SHIFT) < 0) {
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem != 0) {
- if (hAnchor == 0) hAnchor = hItem;
- ignoreSelect = ignoreDeselect = true;
- int /*long*/ code = callWindowProc (handle, OS.WM_KEYDOWN, wParam, lParam);
- ignoreSelect = ignoreDeselect = false;
- int /*long*/ hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_SELECTED;
- int /*long*/ hDeselectItem = hItem;
- RECT rect1 = new RECT ();
- if (!OS.TreeView_GetItemRect (handle, hAnchor, rect1, false)) {
- hAnchor = hItem;
- OS.TreeView_GetItemRect (handle, hAnchor, rect1, false);
- }
- RECT rect2 = new RECT ();
- OS.TreeView_GetItemRect (handle, hDeselectItem, rect2, false);
- int flags = rect1.top < rect2.top ? OS.TVGN_PREVIOUSVISIBLE : OS.TVGN_NEXTVISIBLE;
- while (hDeselectItem != hAnchor) {
- tvItem.hItem = hDeselectItem;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- hDeselectItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, flags, hDeselectItem);
- }
- int /*long*/ hSelectItem = hAnchor;
- OS.TreeView_GetItemRect (handle, hNewItem, rect1, false);
- OS.TreeView_GetItemRect (handle, hSelectItem, rect2, false);
- tvItem.state = OS.TVIS_SELECTED;
- flags = rect1.top < rect2.top ? OS.TVGN_PREVIOUSVISIBLE : OS.TVGN_NEXTVISIBLE;
- while (hSelectItem != hNewItem) {
- tvItem.hItem = hSelectItem;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- hSelectItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, flags, hSelectItem);
- }
- tvItem.hItem = hNewItem;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- tvItem.hItem = hNewItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- Event event = new Event ();
- event.item = _getItem (hNewItem, (int)/*64*/tvItem.lParam);
- postEvent (SWT.Selection, event);
- return new LRESULT (code);
- }
- }
- if (OS.GetKeyState (OS.VK_CONTROL) < 0) {
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem != 0) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_SELECTED;
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- boolean oldSelected = (tvItem.state & OS.TVIS_SELECTED) != 0;
- int /*long*/ hNewItem = 0;
- switch ((int)/*64*/wParam) {
- case OS.VK_UP:
- hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PREVIOUSVISIBLE, hItem);
- break;
- case OS.VK_DOWN:
- hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, hItem);
- break;
- case OS.VK_HOME:
- hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- break;
- case OS.VK_PRIOR:
- hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0);
- if (hNewItem == hItem) {
- OS.SendMessage (handle, OS.WM_VSCROLL, OS.SB_PAGEUP, 0);
- hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0);
- }
- break;
- case OS.VK_NEXT:
- RECT rect = new RECT (), clientRect = new RECT ();
- OS.GetClientRect (handle, clientRect);
- hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0);
- do {
- int /*long*/ hVisible = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, hNewItem);
- if (hVisible == 0) break;
- if (!OS.TreeView_GetItemRect (handle, hVisible, rect, false)) break;
- if (rect.bottom > clientRect.bottom) break;
- if ((hNewItem = hVisible) == hItem) {
- OS.SendMessage (handle, OS.WM_VSCROLL, OS.SB_PAGEDOWN, 0);
- }
- } while (hNewItem != 0);
- break;
- case OS.VK_END:
- hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_LASTVISIBLE, 0);
- break;
- }
- if (hNewItem != 0) {
- OS.SendMessage (handle, OS.TVM_ENSUREVISIBLE, 0, hNewItem);
- tvItem.hItem = hNewItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- boolean newSelected = (tvItem.state & OS.TVIS_SELECTED) != 0;
- boolean redraw = !newSelected && getDrawing () && OS.IsWindowVisible (handle);
- if (redraw) {
- OS.UpdateWindow (handle);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- }
- hSelect = hNewItem;
- ignoreSelect = true;
- OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, hNewItem);
- ignoreSelect = false;
- hSelect = 0;
- if (oldSelected) {
- tvItem.state = OS.TVIS_SELECTED;
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- if (!newSelected) {
- tvItem.state = 0;
- tvItem.hItem = hNewItem;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- if (redraw) {
- RECT rect1 = new RECT (), rect2 = new RECT ();
- boolean fItemRect = (style & SWT.FULL_SELECTION) == 0;
- if (hooks (SWT.EraseItem) || hooks (SWT.PaintItem)) fItemRect = false;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) fItemRect = false;
- OS.TreeView_GetItemRect (handle, hItem, rect1, fItemRect);
- OS.TreeView_GetItemRect (handle, hNewItem, rect2, fItemRect);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.InvalidateRect (handle, rect1, true);
- OS.InvalidateRect (handle, rect2, true);
- OS.UpdateWindow (handle);
- }
- return LRESULT.ZERO;
- }
- }
- }
- int /*long*/ code = callWindowProc (handle, OS.WM_KEYDOWN, wParam, lParam);
- hAnchor = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- return new LRESULT (code);
- }
- }
- return result;
-}
-
-LRESULT WM_KILLFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Bug in Windows. When a tree item that has an image
- * with alpha is expanded or collapsed, the area where
- * the image is drawn is not erased before it is drawn.
- * This means that the image gets darker each time.
- * The fix is to redraw the selection.
- *
- * Feature in Windows. When multiple item have
- * the TVIS_SELECTED state, Windows redraws only
- * the focused item in the color used to show the
- * selection when the tree loses or gains focus.
- * The fix is to force Windows to redraw the
- * selection when focus is gained or lost.
- */
- boolean redraw = (style & SWT.MULTI) != 0;
- if (!redraw) {
- if (!OS.IsWinCE && OS.COMCTL32_MAJOR >= 6) {
- if (imageList != null) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.TVS_FULLROWSELECT) == 0) {
- redraw = true;
- }
- }
- }
- }
- if (redraw) redrawSelection ();
- return super.WM_KILLFOCUS (wParam, lParam);
-}
-
-LRESULT WM_LBUTTONDBLCLK (int /*long*/ wParam, int /*long*/ lParam) {
- TVHITTESTINFO lpht = new TVHITTESTINFO ();
- lpht.x = OS.GET_X_LPARAM (lParam);
- lpht.y = OS.GET_Y_LPARAM (lParam);
- OS.SendMessage (handle, OS.TVM_HITTEST, 0, lpht);
- if (lpht.hItem != 0) {
- if ((style & SWT.CHECK) != 0) {
- if ((lpht.flags & OS.TVHT_ONITEMSTATEICON) != 0) {
- Display display = this.display;
- display.captureChanged = false;
- sendMouseEvent (SWT.MouseDown, 1, handle, OS.WM_LBUTTONDOWN, wParam, lParam);
- if (!sendMouseEvent (SWT.MouseDoubleClick, 1, handle, OS.WM_LBUTTONDBLCLK, wParam, lParam)) {
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- return LRESULT.ZERO;
- }
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- OS.SetFocus (handle);
- TVITEM tvItem = new TVITEM ();
- tvItem.hItem = lpht.hItem;
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM | OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_STATEIMAGEMASK;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- int state = tvItem.state >> 12;
- if ((state & 0x1) != 0) {
- state++;
- } else {
- --state;
- }
- tvItem.state = state << 12;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- if (!OS.IsWinCE) {
- int /*long*/ id = tvItem.hItem;
- if (OS.COMCTL32_MAJOR >= 6) {
- id = OS.SendMessage (handle, OS.TVM_MAPHTREEITEMTOACCID, tvItem.hItem, 0);
- }
- OS.NotifyWinEvent (OS.EVENT_OBJECT_FOCUS, handle, OS.OBJID_CLIENT, (int)/*64*/id);
- }
- Event event = new Event ();
- event.item = _getItem (tvItem.hItem, (int)/*64*/tvItem.lParam);
- event.detail = SWT.CHECK;
- postEvent (SWT.Selection, event);
- return LRESULT.ZERO;
- }
- }
- }
- LRESULT result = super.WM_LBUTTONDBLCLK (wParam, lParam);
- if (result == LRESULT.ZERO) return result;
- if (lpht.hItem != 0) {
- int flags = OS.TVHT_ONITEM;
- if ((style & SWT.FULL_SELECTION) != 0) {
- flags |= OS.TVHT_ONITEMRIGHT | OS.TVHT_ONITEMINDENT;
- } else {
- if (hooks (SWT.MeasureItem)) {
- lpht.flags &= ~(OS.TVHT_ONITEMICON | OS.TVHT_ONITEMLABEL);
- if (hitTestSelection (lpht.hItem, lpht.x, lpht.y)) {
- lpht.flags |= OS.TVHT_ONITEMICON | OS.TVHT_ONITEMLABEL;
- }
- }
- }
- if ((lpht.flags & flags) != 0) {
- Event event = new Event ();
- event.item = _getItem (lpht.hItem);
- postEvent (SWT.DefaultSelection, event);
- }
- }
- return result;
-}
-
-LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * In a multi-select tree, if the user is collapsing a subtree that
- * contains selected items, clear the selection from these items and
- * issue a selection event. Only items that are selected and visible
- * are cleared. This code also runs in the case when the white space
- * below the last item is selected.
- */
- TVHITTESTINFO lpht = new TVHITTESTINFO ();
- lpht.x = OS.GET_X_LPARAM (lParam);
- lpht.y = OS.GET_Y_LPARAM (lParam);
- OS.SendMessage (handle, OS.TVM_HITTEST, 0, lpht);
- if (lpht.hItem == 0 || (lpht.flags & OS.TVHT_ONITEMBUTTON) != 0) {
- Display display = this.display;
- display.captureChanged = false;
- if (!sendMouseEvent (SWT.MouseDown, 1, handle, OS.WM_LBUTTONDOWN, wParam, lParam)) {
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- return LRESULT.ZERO;
- }
- boolean fixSelection = false, deselected = false;
- int /*long*/ hOldSelection = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (lpht.hItem != 0 && (style & SWT.MULTI) != 0) {
- if (hOldSelection != 0) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.hItem = lpht.hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- if ((tvItem.state & OS.TVIS_EXPANDED) != 0) {
- fixSelection = true;
- tvItem.stateMask = OS.TVIS_SELECTED;
- int /*long*/ hNext = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, lpht.hItem);
- while (hNext != 0) {
- if (hNext == hAnchor) hAnchor = 0;
- tvItem.hItem = hNext;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- if ((tvItem.state & OS.TVIS_SELECTED) != 0) deselected = true;
- tvItem.state = 0;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- int /*long*/ hItem = hNext = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, hNext);
- while (hItem != 0 && hItem != lpht.hItem) {
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PARENT, hItem);
- }
- if (hItem == 0) break;
- }
- }
- }
- }
- dragStarted = gestureCompleted = false;
- if (fixSelection) ignoreDeselect = ignoreSelect = lockSelection = true;
- int /*long*/ code = callWindowProc (handle, OS.WM_LBUTTONDOWN, wParam, lParam);
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- if (OS.GetFocus () != handle) OS.SetFocus (handle);
- }
- if (fixSelection) ignoreDeselect = ignoreSelect = lockSelection = false;
- int /*long*/ hNewSelection = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hOldSelection != hNewSelection) hAnchor = hNewSelection;
- if (dragStarted) {
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- }
- /*
- * Bug in Windows. When a tree has no images and an item is
- * expanded or collapsed, for some reason, Windows changes
- * the size of the selection. When the user expands a tree
- * item, the selection rectangle is made a few pixels larger.
- * When the user collapses an item, the selection rectangle
- * is restored to the original size but the selection is not
- * redrawn, causing pixel corruption. The fix is to detect
- * this case and redraw the item.
- */
- if ((lpht.flags & OS.TVHT_ONITEMBUTTON) != 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.TVS_FULLROWSELECT) == 0) {
- if (OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0) == 0) {
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem != 0) {
- RECT rect = new RECT ();
- if (OS.TreeView_GetItemRect (handle, hItem, rect, false)) {
- OS.InvalidateRect (handle, rect, true);
- }
- }
- }
- }
- }
- if (deselected) {
- Event event = new Event ();
- event.item = _getItem (lpht.hItem);
- postEvent (SWT.Selection, event);
- }
- return new LRESULT (code);
- }
-
- /* Look for check/uncheck */
- if ((style & SWT.CHECK) != 0) {
- if ((lpht.flags & OS.TVHT_ONITEMSTATEICON) != 0) {
- Display display = this.display;
- display.captureChanged = false;
- if (!sendMouseEvent (SWT.MouseDown, 1, handle, OS.WM_LBUTTONDOWN, wParam, lParam)) {
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- return LRESULT.ZERO;
- }
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- OS.SetFocus (handle);
- TVITEM tvItem = new TVITEM ();
- tvItem.hItem = lpht.hItem;
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM | OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_STATEIMAGEMASK;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- int state = tvItem.state >> 12;
- if ((state & 0x1) != 0) {
- state++;
- } else {
- --state;
- }
- tvItem.state = state << 12;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- if (!OS.IsWinCE) {
- int /*long*/ id = tvItem.hItem;
- if (OS.COMCTL32_MAJOR >= 6) {
- id = OS.SendMessage (handle, OS.TVM_MAPHTREEITEMTOACCID, tvItem.hItem, 0);
- }
- OS.NotifyWinEvent (OS.EVENT_OBJECT_FOCUS, handle, OS.OBJID_CLIENT, (int)/*64*/id);
- }
- Event event = new Event ();
- event.item = _getItem (tvItem.hItem, (int)/*64*/tvItem.lParam);
- event.detail = SWT.CHECK;
- postEvent (SWT.Selection, event);
- return LRESULT.ZERO;
- }
- }
-
- /*
- * Feature in Windows. When the tree has the style
- * TVS_FULLROWSELECT, the background color for the
- * entire row is filled when an item is painted,
- * drawing on top of any custom drawing. The fix
- * is to emulate TVS_FULLROWSELECT.
- */
- boolean selected = false;
- boolean fakeSelection = false;
- if (lpht.hItem != 0) {
- if ((style & SWT.FULL_SELECTION) != 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.TVS_FULLROWSELECT) == 0) fakeSelection = true;
- } else {
- if (hooks (SWT.MeasureItem)) {
- selected = hitTestSelection (lpht.hItem, lpht.x, lpht.y);
- if (selected) {
- if ((lpht.flags & OS.TVHT_ONITEM) == 0) fakeSelection = true;
- }
- }
- }
- }
-
- /* Process the mouse when an item is not selected */
- if (!selected && (style & SWT.FULL_SELECTION) == 0) {
- if ((lpht.flags & OS.TVHT_ONITEM) == 0) {
- Display display = this.display;
- display.captureChanged = false;
- if (!sendMouseEvent (SWT.MouseDown, 1, handle, OS.WM_LBUTTONDOWN, wParam, lParam)) {
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- return LRESULT.ZERO;
- }
- int /*long*/ code = callWindowProc (handle, OS.WM_LBUTTONDOWN, wParam, lParam);
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- if (OS.GetFocus () != handle) OS.SetFocus (handle);
- }
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- return new LRESULT (code);
- }
- }
-
- /* Get the selected state of the item under the mouse */
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_SELECTED;
- boolean hittestSelected = false;
- if ((style & SWT.MULTI) != 0) {
- tvItem.hItem = lpht.hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- hittestSelected = (tvItem.state & OS.TVIS_SELECTED) != 0;
- }
-
- /* Get the selected state of the last selected item */
- int /*long*/ hOldItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if ((style & SWT.MULTI) != 0) {
- tvItem.hItem = hOldItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
-
- /* Check for CONTROL or drag selection */
- if (hittestSelected || (wParam & OS.MK_CONTROL) != 0) {
- /*
- * Feature in Windows. When the tree is not drawing focus
- * and the user selects a tree item while the CONTROL key
- * is down, the tree window proc sends WM_UPDATEUISTATE
- * to the top level window, causing controls within the shell
- * to redraw. When drag detect is enabled, the tree window
- * proc runs a modal loop that allows WM_PAINT messages to be
- * delivered during WM_LBUTTONDOWN. When WM_SETREDRAW is used
- * to disable drawing for the tree and a WM_PAINT happens for
- * a parent of the tree (or a sibling that overlaps), the parent
- * will draw on top of the tree. If WM_SETREDRAW is turned back
- * on without redrawing the entire tree, pixel corruption occurs.
- * This case only seems to happen when the tree has been given
- * focus from WM_MOUSEACTIVATE of the shell. The fix is to
- * force the WM_UPDATEUISTATE to be sent before disabling
- * the drawing.
- *
- * NOTE: Any redraw of a parent (or sibling) will be dispatched
- * during the modal drag detect loop. This code only fixes the
- * case where the tree causes a redraw from WM_UPDATEUISTATE.
- * In SWT, the InvalidateRect() that caused the pixel corruption
- * is found in Composite.WM_UPDATEUISTATE().
- */
- int uiState = (int)/*64*/OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- if ((uiState & OS.UISF_HIDEFOCUS) != 0) {
- OS.SendMessage (handle, OS.WM_CHANGEUISTATE, OS.UIS_INITIALIZE, 0);
- }
- OS.UpdateWindow (handle);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- } else {
- deselectAll ();
- }
- }
-
- /* Do the selection */
- Display display = this.display;
- display.captureChanged = false;
- if (!sendMouseEvent (SWT.MouseDown, 1, handle, OS.WM_LBUTTONDOWN, wParam, lParam)) {
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- return LRESULT.ZERO;
- }
- hSelect = lpht.hItem;
- dragStarted = gestureCompleted = false;
- ignoreDeselect = ignoreSelect = true;
- int /*long*/ code = callWindowProc (handle, OS.WM_LBUTTONDOWN, wParam, lParam);
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- if (OS.GetFocus () != handle) OS.SetFocus (handle);
- }
- int /*long*/ hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (fakeSelection) {
- if (hOldItem == 0 || (hNewItem == hOldItem && lpht.hItem != hOldItem)) {
- OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, lpht.hItem);
- hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- }
- if (!dragStarted && (state & DRAG_DETECT) != 0 && hooks (SWT.DragDetect)) {
- dragStarted = dragDetect (handle, lpht.x, lpht.y, false, null, null);
- }
- }
- ignoreDeselect = ignoreSelect = false;
- hSelect = 0;
- if (dragStarted) {
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- }
-
- /*
- * Feature in Windows. When the old and new focused item
- * are the same, Windows does not check to make sure that
- * the item is actually selected, not just focused. The
- * fix is to force the item to draw selected by setting
- * the state mask. This is only necessary when the tree
- * is single select.
- */
- if ((style & SWT.SINGLE) != 0) {
- if (hOldItem == hNewItem) {
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.state = OS.TVIS_SELECTED;
- tvItem.stateMask = OS.TVIS_SELECTED;
- tvItem.hItem = hNewItem;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- }
-
- /* Reselect the last item that was unselected */
- if ((style & SWT.MULTI) != 0) {
-
- /* Check for CONTROL and reselect the last item */
- if (hittestSelected || (wParam & OS.MK_CONTROL) != 0) {
- if (hOldItem == hNewItem && hOldItem == lpht.hItem) {
- if ((wParam & OS.MK_CONTROL) != 0) {
- tvItem.state ^= OS.TVIS_SELECTED;
- if (dragStarted) tvItem.state = OS.TVIS_SELECTED;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- } else {
- if ((tvItem.state & OS.TVIS_SELECTED) != 0) {
- tvItem.state = OS.TVIS_SELECTED;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- if ((wParam & OS.MK_CONTROL) != 0 && !dragStarted) {
- if (hittestSelected) {
- tvItem.state = 0;
- tvItem.hItem = lpht.hItem;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- }
- }
- RECT rect1 = new RECT (), rect2 = new RECT ();
- boolean fItemRect = (style & SWT.FULL_SELECTION) == 0;
- if (hooks (SWT.EraseItem) || hooks (SWT.PaintItem)) fItemRect = false;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) fItemRect = false;
- OS.TreeView_GetItemRect (handle, hOldItem, rect1, fItemRect);
- OS.TreeView_GetItemRect (handle, hNewItem, rect2, fItemRect);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.InvalidateRect (handle, rect1, true);
- OS.InvalidateRect (handle, rect2, true);
- OS.UpdateWindow (handle);
- }
-
- /* Check for SHIFT or normal select and deselect/reselect items */
- if ((wParam & OS.MK_CONTROL) == 0) {
- if (!hittestSelected || !dragStarted) {
- tvItem.state = 0;
- int /*long*/ oldProc = OS.GetWindowLongPtr (handle, OS.GWLP_WNDPROC);
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, TreeProc);
- if ((style & SWT.VIRTUAL) != 0) {
- int /*long*/ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- deselect (hItem, tvItem, hNewItem);
- } else {
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null && item.handle != hNewItem) {
- tvItem.hItem = item.handle;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- }
- }
- tvItem.hItem = hNewItem;
- tvItem.state = OS.TVIS_SELECTED;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, oldProc);
- if ((wParam & OS.MK_SHIFT) != 0) {
- RECT rect1 = new RECT ();
- if (hAnchor == 0) hAnchor = hNewItem;
- if (OS.TreeView_GetItemRect (handle, hAnchor, rect1, false)) {
- RECT rect2 = new RECT ();
- if (OS.TreeView_GetItemRect (handle, hNewItem, rect2, false)) {
- int flags = rect1.top < rect2.top ? OS.TVGN_NEXTVISIBLE : OS.TVGN_PREVIOUSVISIBLE;
- tvItem.state = OS.TVIS_SELECTED;
- int /*long*/ hItem = tvItem.hItem = hAnchor;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- while (hItem != hNewItem) {
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, flags, hItem);
- }
- }
- }
- }
- }
- }
- }
- if ((wParam & OS.MK_SHIFT) == 0) hAnchor = hNewItem;
-
- /* Issue notification */
- if (!gestureCompleted) {
- tvItem.hItem = hNewItem;
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- Event event = new Event ();
- event.item = _getItem (tvItem.hItem, (int)/*64*/tvItem.lParam);
- postEvent (SWT.Selection, event);
- }
- gestureCompleted = false;
-
- /*
- * Feature in Windows. Inside WM_LBUTTONDOWN and WM_RBUTTONDOWN,
- * the widget starts a modal loop to determine if the user wants
- * to begin a drag/drop operation or marquee select. Unfortunately,
- * this modal loop eats the corresponding mouse up. The fix is to
- * detect the cases when the modal loop has eaten the mouse up and
- * issue a fake mouse up.
- */
- if (dragStarted) {
- sendDragEvent (1, OS.GET_X_LPARAM (lParam), OS.GET_Y_LPARAM (lParam));
- } else {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.TVS_DISABLEDRAGDROP) == 0) {
- sendMouseEvent (SWT.MouseUp, 1, handle, OS.WM_LBUTTONUP, wParam, lParam);
- }
- }
- dragStarted = false;
- return new LRESULT (code);
-}
-
-LRESULT WM_MOUSEMOVE (int /*long*/ wParam, int /*long*/ lParam) {
- Display display = this.display;
- LRESULT result = super.WM_MOUSEMOVE (wParam, lParam);
- if (result != null) return result;
- if (itemToolTipHandle != 0) {
- /*
- * Bug in Windows. On some machines that do not have XBUTTONs,
- * the MK_XBUTTON1 and OS.MK_XBUTTON2 bits are sometimes set,
- * causing mouse capture to become stuck. The fix is to test
- * for the extra buttons only when they exist.
- */
- int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON;
- if (display.xMouse) mask |= OS.MK_XBUTTON1 | OS.MK_XBUTTON2;
- if ((wParam & mask) == 0) {
- int x = OS.GET_X_LPARAM (lParam);
- int y = OS.GET_Y_LPARAM (lParam);
- int [] index = new int [1];
- TreeItem [] item = new TreeItem [1];
- RECT [] cellRect = new RECT [1], itemRect = new RECT [1];
- if (findCell (x, y, item, index, cellRect, itemRect)) {
- /*
- * Feature in Windows. When the new tool rectangle is
- * set using TTM_NEWTOOLRECT and the tooltip is visible,
- * Windows draws the tooltip right away and the sends
- * WM_NOTIFY with TTN_SHOW. This means that the tooltip
- * shows first at the wrong location and then moves to
- * the right one. The fix is to hide the tooltip window.
- */
- if (OS.SendMessage (itemToolTipHandle, OS.TTM_GETCURRENTTOOL, 0, 0) == 0) {
- if (OS.IsWindowVisible (itemToolTipHandle)) {
- OS.ShowWindow (itemToolTipHandle, OS.SW_HIDE);
- }
- }
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- lpti.hwnd = handle;
- lpti.uId = handle;
- lpti.uFlags = OS.TTF_SUBCLASS | OS.TTF_TRANSPARENT;
- lpti.left = cellRect [0].left;
- lpti.top = cellRect [0].top;
- lpti.right = cellRect [0].right;
- lpti.bottom = cellRect [0].bottom;
- OS.SendMessage (itemToolTipHandle, OS.TTM_NEWTOOLRECT, 0, lpti);
- }
- }
- }
- return result;
-}
-
-LRESULT WM_MOUSEWHEEL (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_MOUSEWHEEL (wParam, lParam);
- if (itemToolTipHandle != 0) OS.ShowWindow (itemToolTipHandle, OS.SW_HIDE);
- return result;
-}
-
-LRESULT WM_MOVE (int /*long*/ wParam, int /*long*/ lParam) {
- if (itemToolTipHandle != 0) OS.ShowWindow (itemToolTipHandle, OS.SW_HIDE);
- if (ignoreResize) return null;
- return super.WM_MOVE (wParam, lParam);
-}
-
-LRESULT WM_RBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. The receiver uses WM_RBUTTONDOWN
- * to initiate a drag/drop operation depending on how the
- * user moves the mouse. If the user clicks the right button,
- * without moving the mouse, the tree consumes the corresponding
- * WM_RBUTTONUP. The fix is to avoid calling the window proc for
- * the tree.
- */
- Display display = this.display;
- display.captureChanged = false;
- if (!sendMouseEvent (SWT.MouseDown, 3, handle, OS.WM_RBUTTONDOWN, wParam, lParam)) {
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- return LRESULT.ZERO;
- }
- /*
- * This code is intentionally commented.
- */
-// if (OS.GetCapture () != handle) OS.SetCapture (handle);
- if (OS.GetFocus () != handle) OS.SetFocus (handle);
-
- /*
- * Feature in Windows. When the user selects a tree item
- * with the right mouse button, the item remains selected
- * only as long as the user does not release or move the
- * mouse. As soon as this happens, the selection snaps
- * back to the previous selection. This behavior can be
- * observed in the Explorer but is not instantly apparent
- * because the Explorer explicitly sets the selection when
- * the user chooses a menu item. If the user cancels the
- * menu, the selection snaps back. The fix is to avoid
- * calling the window proc and do the selection ourselves.
- * This behavior is consistent with the table.
- */
- TVHITTESTINFO lpht = new TVHITTESTINFO ();
- lpht.x = OS.GET_X_LPARAM (lParam);
- lpht.y = OS.GET_Y_LPARAM (lParam);
- OS.SendMessage (handle, OS.TVM_HITTEST, 0, lpht);
- if (lpht.hItem != 0) {
- boolean fakeSelection = (style & SWT.FULL_SELECTION) != 0;
- if (!fakeSelection) {
- if (hooks (SWT.MeasureItem)) {
- fakeSelection = hitTestSelection (lpht.hItem, lpht.x, lpht.y);
- } else {
- int flags = OS.TVHT_ONITEMICON | OS.TVHT_ONITEMLABEL;
- fakeSelection = (lpht.flags & flags) != 0;
- }
- }
- if (fakeSelection) {
- if ((wParam & (OS.MK_CONTROL | OS.MK_SHIFT)) == 0) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_SELECTED;
- tvItem.hItem = lpht.hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- if ((tvItem.state & OS.TVIS_SELECTED) == 0) {
- ignoreSelect = true;
- OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, 0);
- ignoreSelect = false;
- OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, lpht.hItem);
- }
- }
- }
- }
- return LRESULT.ZERO;
-}
-
-LRESULT WM_PAINT (int /*long*/ wParam, int /*long*/ lParam) {
- if (shrink && !ignoreShrink) {
- /* Resize the item array to fit the last item */
- int count = items.length - 1;
- while (count >= 0) {
- if (items [count] != null) break;
- --count;
- }
- count++;
- if (items.length > 4 && items.length - count > 3) {
- int length = Math.max (4, (count + 3) / 4 * 4);
- TreeItem [] newItems = new TreeItem [length];
- System.arraycopy (items, 0, newItems, 0, count);
- items = newItems;
- }
- shrink = false;
- }
- if ((style & SWT.DOUBLE_BUFFERED) != 0 || findImageControl () != null) {
- boolean doubleBuffer = true;
- if (explorerTheme) {
- int exStyle = (int)/*64*/OS.SendMessage (handle, OS.TVM_GETEXTENDEDSTYLE, 0, 0);
- if ((exStyle & OS.TVS_EX_DOUBLEBUFFER) != 0) doubleBuffer = false;
- }
- if (doubleBuffer) {
- GC gc = null;
- int /*long*/ paintDC = 0;
- PAINTSTRUCT ps = new PAINTSTRUCT ();
- boolean hooksPaint = hooks (SWT.Paint) || filters (SWT.Paint);
- if (hooksPaint) {
- GCData data = new GCData ();
- data.ps = ps;
- data.hwnd = handle;
- gc = GC.win32_new (this, data);
- paintDC = gc.handle;
- } else {
- paintDC = OS.BeginPaint (handle, ps);
- }
- int width = ps.right - ps.left;
- int height = ps.bottom - ps.top;
- if (width != 0 && height != 0) {
- int /*long*/ hDC = OS.CreateCompatibleDC (paintDC);
- POINT lpPoint1 = new POINT (), lpPoint2 = new POINT ();
- OS.SetWindowOrgEx (hDC, ps.left, ps.top, lpPoint1);
- OS.SetBrushOrgEx (hDC, ps.left, ps.top, lpPoint2);
- int /*long*/ hBitmap = OS.CreateCompatibleBitmap (paintDC, width, height);
- int /*long*/ hOldBitmap = OS.SelectObject (hDC, hBitmap);
- RECT rect = new RECT ();
- OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
- drawBackground (hDC, rect);
- callWindowProc (handle, OS.WM_PAINT, hDC, 0);
- OS.SetWindowOrgEx (hDC, lpPoint1.x, lpPoint1.y, null);
- OS.SetBrushOrgEx (hDC, lpPoint2.x, lpPoint2.y, null);
- OS.BitBlt (paintDC, ps.left, ps.top, width, height, hDC, 0, 0, OS.SRCCOPY);
- OS.SelectObject (hDC, hOldBitmap);
- OS.DeleteObject (hBitmap);
- OS.DeleteObject (hDC);
- if (hooksPaint) {
- Event event = new Event ();
- event.gc = gc;
- event.x = ps.left;
- event.y = ps.top;
- event.width = ps.right - ps.left;
- event.height = ps.bottom - ps.top;
- sendEvent (SWT.Paint, event);
- // widget could be disposed at this point
- event.gc = null;
- }
- }
- if (hooksPaint) {
- gc.dispose ();
- } else {
- OS.EndPaint (handle, ps);
- }
- return LRESULT.ZERO;
- }
- }
- return super.WM_PAINT (wParam, lParam);
-}
-
-LRESULT WM_PRINTCLIENT (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_PRINTCLIENT (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. For some reason, when WM_PRINT is used
- * to capture an image of a hierarchy that contains a tree with
- * columns, the clipping that is used to stop the first column
- * from drawing on top of subsequent columns stops the first
- * column and the tree lines from drawing. This does not happen
- * during WM_PAINT. The fix is to draw without clipping and
- * then draw the rest of the columns on top. Since the drawing
- * is happening in WM_PRINTCLIENT, the redrawing is not visible.
- */
- printClient = true;
- int /*long*/ code = callWindowProc (handle, OS.WM_PRINTCLIENT, wParam, lParam);
- printClient = false;
- return new LRESULT (code);
-}
-
-LRESULT WM_SETFOCUS (int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Bug in Windows. When a tree item that has an image
- * with alpha is expanded or collapsed, the area where
- * the image is drawn is not erased before it is drawn.
- * This means that the image gets darker each time.
- * The fix is to redraw the selection.
- *
- * Feature in Windows. When multiple item have
- * the TVIS_SELECTED state, Windows redraws only
- * the focused item in the color used to show the
- * selection when the tree loses or gains focus.
- * The fix is to force Windows to redraw the
- * selection when focus is gained or lost.
- */
- boolean redraw = (style & SWT.MULTI) != 0;
- if (!redraw) {
- if (!OS.IsWinCE && OS.COMCTL32_MAJOR >= 6) {
- if (imageList != null) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.TVS_FULLROWSELECT) == 0) {
- redraw = true;
- }
- }
- }
- }
- if (redraw) redrawSelection ();
- return super.WM_SETFOCUS (wParam, lParam);
-}
-
-LRESULT WM_SETFONT (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SETFONT (wParam, lParam);
- if (result != null) return result;
- if (hwndHeader != 0) {
- /*
- * Bug in Windows. When a header has a sort indicator
- * triangle, Windows resizes the indicator based on the
- * size of the n-1th font. The fix is to always make
- * the n-1th font be the default. This makes the sort
- * indicator always be the default size.
- */
- OS.SendMessage (hwndHeader, OS.WM_SETFONT, 0, lParam);
- OS.SendMessage (hwndHeader, OS.WM_SETFONT, wParam, lParam);
- }
- if (itemToolTipHandle != 0) {
- OS.ShowWindow (itemToolTipHandle, OS.SW_HIDE);
- OS.SendMessage (itemToolTipHandle, OS.WM_SETFONT, wParam, lParam);
- }
- if (headerToolTipHandle != 0) {
- OS.SendMessage (headerToolTipHandle, OS.WM_SETFONT, wParam, lParam);
- updateHeaderToolTips ();
- }
- return result;
-}
-
-LRESULT WM_SETREDRAW (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SETREDRAW (wParam, lParam);
- if (result != null) return result;
- if (itemToolTipHandle != 0) OS.ShowWindow (itemToolTipHandle, OS.SW_HIDE);
- /*
- * Bug in Windows. Under certain circumstances, when
- * WM_SETREDRAW is used to turn off drawing and then
- * TVM_GETITEMRECT is sent to get the bounds of an item
- * that is not inside the client area, Windows segment
- * faults. The fix is to call the default window proc
- * rather than the default tree proc.
- *
- * NOTE: This problem is intermittent and happens on
- * Windows Vista running under the theme manager.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- int /*long*/ code = OS.DefWindowProc (handle, OS.WM_SETREDRAW, wParam, lParam);
- return code == 0 ? LRESULT.ZERO : new LRESULT (code);
- }
- return result;
-}
-
-LRESULT WM_SIZE (int /*long*/ wParam, int /*long*/ lParam) {
- if (itemToolTipHandle != 0) OS.ShowWindow (itemToolTipHandle, OS.SW_HIDE);
- /*
- * Bug in Windows. When TVS_NOHSCROLL is set when the
- * size of the tree is zero, the scroll bar is shown the
- * next time the tree resizes. The fix is to hide the
- * scroll bar every time the tree is resized.
- */
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.TVS_NOHSCROLL) != 0) {
- if (!OS.IsWinCE) OS.ShowScrollBar (handle, OS.SB_HORZ, false);
- }
- /*
- * Bug in Windows. On Vista, when the Explorer theme
- * is used with a full selection tree, when the tree
- * is resized to be smaller, the rounded right edge
- * of the selected items is not drawn. The fix is the
- * redraw the entire tree.
- */
- if (explorerTheme && (style & SWT.FULL_SELECTION) != 0) {
- OS.InvalidateRect (handle, null, false);
- }
- if (ignoreResize) return null;
- return super.WM_SIZE (wParam, lParam);
-}
-
-LRESULT WM_SYSCOLORCHANGE (int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = super.WM_SYSCOLORCHANGE (wParam, lParam);
- if (result != null) return result;
- /*
- * Bug in Windows. When the tree is using the explorer
- * theme, it does not use COLOR_WINDOW_TEXT for the
- * default foreground color. The fix is to explicitly
- * set the foreground.
- */
- if (explorerTheme) {
- if (foreground == -1) setForegroundPixel (-1);
- }
- if ((style & SWT.CHECK) != 0) setCheckboxImageList ();
- return result;
-}
-
-LRESULT WM_VSCROLL (int /*long*/ wParam, int /*long*/ lParam) {
- boolean fixScroll = false;
- if ((style & SWT.DOUBLE_BUFFERED) != 0) {
- int code = OS.LOWORD (wParam);
- switch (code) {
- case OS.SB_TOP:
- case OS.SB_BOTTOM:
- case OS.SB_LINEDOWN:
- case OS.SB_LINEUP:
- case OS.SB_PAGEDOWN:
- case OS.SB_PAGEUP:
- fixScroll = (style & SWT.VIRTUAL) != 0 || hooks (SWT.EraseItem) || hooks (SWT.PaintItem);
- break;
- }
- }
- if (fixScroll) {
- style &= ~SWT.DOUBLE_BUFFERED;
- if (explorerTheme) {
- OS.SendMessage (handle, OS.TVM_SETEXTENDEDSTYLE, OS.TVS_EX_DOUBLEBUFFER, 0);
- }
- }
- LRESULT result = super.WM_VSCROLL (wParam, lParam);
- if (fixScroll) {
- style |= SWT.DOUBLE_BUFFERED;
- if (explorerTheme) {
- OS.SendMessage (handle, OS.TVM_SETEXTENDEDSTYLE, OS.TVS_EX_DOUBLEBUFFER, OS.TVS_EX_DOUBLEBUFFER);
- }
- }
- if (result != null) return result;
- return result;
-}
-
-LRESULT wmColorChild (int /*long*/ wParam, int /*long*/ lParam) {
- if (findImageControl () != null) {
- if (OS.COMCTL32_MAJOR < 6) {
- return super.wmColorChild (wParam, lParam);
- }
- return new LRESULT (OS.GetStockObject (OS.NULL_BRUSH));
- }
- /*
- * Feature in Windows. Tree controls send WM_CTLCOLOREDIT
- * to allow application code to change the default colors.
- * This is undocumented and conflicts with TVM_SETTEXTCOLOR
- * and TVM_SETBKCOLOR, the documented way to do this. The
- * fix is to ignore WM_CTLCOLOREDIT messages from trees.
- */
- return null;
-}
-
-LRESULT wmNotify (NMHDR hdr, int /*long*/ wParam, int /*long*/ lParam) {
- if (hdr.hwndFrom == itemToolTipHandle) {
- LRESULT result = wmNotifyToolTip (hdr, wParam, lParam);
- if (result != null) return result;
- }
- if (hdr.hwndFrom == hwndHeader) {
- LRESULT result = wmNotifyHeader (hdr, wParam, lParam);
- if (result != null) return result;
- }
- return super.wmNotify (hdr, wParam, lParam);
-}
-
-LRESULT wmNotifyChild (NMHDR hdr, int /*long*/ wParam, int /*long*/ lParam) {
- switch (hdr.code) {
- case OS.TVN_GETDISPINFOA:
- case OS.TVN_GETDISPINFOW: {
- NMTVDISPINFO lptvdi = new NMTVDISPINFO ();
- OS.MoveMemory (lptvdi, lParam, NMTVDISPINFO.sizeof);
- if ((style & SWT.VIRTUAL) != 0) {
- /*
- * Feature in Windows. When a new tree item is inserted
- * using TVM_INSERTITEM, a TVN_GETDISPINFO is sent before
- * TVM_INSERTITEM returns and before the item is added to
- * the items array. The fix is to check for null.
- *
- * NOTE: This only happens on XP with the version 6.00 of
- * COMCTL32.DLL.
- */
- boolean checkVisible = true;
- /*
- * When an item is being deleted from a virtual tree, do not
- * allow the application to provide data for a new item that
- * becomes visible until the item has been removed from the
- * items array. Because arbitrary application code can run
- * during the callback, the items array might be accessed
- * in an inconsistent state. Rather than answering the data
- * right away, queue a redraw for later.
- */
- if (!ignoreShrink) {
- if (items != null && lptvdi.lParam != -1) {
- if (items [(int)/*64*/lptvdi.lParam] != null && items [(int)/*64*/lptvdi.lParam].cached) {
- checkVisible = false;
- }
- }
- }
- if (checkVisible) {
- if (!getDrawing () || !OS.IsWindowVisible (handle)) break;
- RECT itemRect = new RECT ();
- if (!OS.TreeView_GetItemRect (handle, lptvdi.hItem, itemRect, false)) {
- break;
- }
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- if (!OS.IntersectRect (rect, rect, itemRect)) break;
- if (ignoreShrink) {
- OS.InvalidateRect (handle, rect, true);
- break;
- }
- }
- }
- if (items == null) break;
- /*
- * Bug in Windows. If the lParam field of TVITEM
- * is changed during custom draw using TVM_SETITEM,
- * the lItemlParam field of the NMTVCUSTOMDRAW struct
- * is not updated until the next custom draw. The
- * fix is to query the field from the item instead
- * of using the struct.
- */
- int id = (int)/*64*/lptvdi.lParam;
- if ((style & SWT.VIRTUAL) != 0) {
- if (id == -1) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- tvItem.hItem = lptvdi.hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- id = (int)/*64*/tvItem.lParam;
- }
- }
- TreeItem item = _getItem (lptvdi.hItem, id);
- /*
- * Feature in Windows. When a new tree item is inserted
- * using TVM_INSERTITEM, a TVN_GETDISPINFO is sent before
- * TVM_INSERTITEM returns and before the item is added to
- * the items array. The fix is to check for null.
- *
- * NOTE: This only happens on XP with the version 6.00 of
- * COMCTL32.DLL.
- *
- * Feature in Windows. When TVM_DELETEITEM is called with
- * TVI_ROOT to remove all items from a tree, under certain
- * circumstances, the tree sends TVN_GETDISPINFO for items
- * that are about to be disposed. The fix is to check for
- * disposed items.
- */
- if (item == null) break;
- if (item.isDisposed ()) break;
- if (!item.cached) {
- if ((style & SWT.VIRTUAL) != 0) {
- if (!checkData (item, false)) break;
- }
- if (painted) item.cached = true;
- }
- int index = 0;
- if (hwndHeader != 0) {
- index = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0);
- }
- if ((lptvdi.mask & OS.TVIF_TEXT) != 0) {
- String string = null;
- if (index == 0) {
- string = item.text;
- } else {
- String [] strings = item.strings;
- if (strings != null) string = strings [index];
- }
- if (string != null) {
- TCHAR buffer = new TCHAR (getCodePage (), string, false);
- int byteCount = Math.min (buffer.length (), lptvdi.cchTextMax - 1) * TCHAR.sizeof;
- OS.MoveMemory (lptvdi.pszText, buffer, byteCount);
- OS.MoveMemory (lptvdi.pszText + byteCount, new byte [TCHAR.sizeof], TCHAR.sizeof);
- lptvdi.cchTextMax = Math.min (lptvdi.cchTextMax, string.length () + 1);
- }
- }
- if ((lptvdi.mask & (OS.TVIF_IMAGE | OS.TVIF_SELECTEDIMAGE)) != 0) {
- Image image = null;
- if (index == 0) {
- image = item.image;
- } else {
- Image [] images = item.images;
- if (images != null) image = images [index];
- }
- lptvdi.iImage = lptvdi.iSelectedImage = OS.I_IMAGENONE;
- if (image != null) {
- lptvdi.iImage = lptvdi.iSelectedImage = imageIndex (image, index);
- }
- if (explorerTheme && OS.IsWindowEnabled (handle)) {
- if (findImageControl () != null) {
- lptvdi.iImage = lptvdi.iSelectedImage = OS.I_IMAGENONE;
- }
- }
- }
- OS.MoveMemory (lParam, lptvdi, NMTVDISPINFO.sizeof);
- break;
- }
- case OS.NM_CUSTOMDRAW: {
- if (hdr.hwndFrom == hwndHeader) break;
- if (hooks (SWT.MeasureItem)) {
- if (hwndHeader == 0) createParent ();
- }
- if (!customDraw && findImageControl () == null) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- if (sortColumn == null || sortDirection == SWT.NONE) {
- break;
- }
- }
- }
- NMTVCUSTOMDRAW nmcd = new NMTVCUSTOMDRAW ();
- OS.MoveMemory (nmcd, lParam, NMTVCUSTOMDRAW.sizeof);
- switch (nmcd.dwDrawStage) {
- case OS.CDDS_PREPAINT: return CDDS_PREPAINT (nmcd, wParam, lParam);
- case OS.CDDS_ITEMPREPAINT: return CDDS_ITEMPREPAINT (nmcd, wParam, lParam);
- case OS.CDDS_ITEMPOSTPAINT: return CDDS_ITEMPOSTPAINT (nmcd, wParam, lParam);
- case OS.CDDS_POSTPAINT: return CDDS_POSTPAINT (nmcd, wParam, lParam);
- }
- break;
- }
- case OS.NM_DBLCLK: {
- /*
- * When the user double clicks on a tree item
- * or a line beside the item, the window proc
- * for the tree collapses or expand the branch.
- * When application code associates an action
- * with double clicking, then the tree expand
- * is unexpected and unwanted. The fix is to
- * avoid the operation by testing to see whether
- * the mouse was inside a tree item.
- */
- if (hooks (SWT.MeasureItem)) return LRESULT.ONE;
- if (hooks (SWT.DefaultSelection)) {
- POINT pt = new POINT ();
- int pos = OS.GetMessagePos ();
- OS.POINTSTOPOINT (pt, pos);
- OS.ScreenToClient (handle, pt);
- TVHITTESTINFO lpht = new TVHITTESTINFO ();
- lpht.x = pt.x;
- lpht.y = pt.y;
- OS.SendMessage (handle, OS.TVM_HITTEST, 0, lpht);
- if (lpht.hItem != 0 && (lpht.flags & OS.TVHT_ONITEM) != 0) {
- return LRESULT.ONE;
- }
- }
- break;
- }
- /*
- * Bug in Windows. On Vista, when TVM_SELECTITEM is called
- * with TVGN_CARET in order to set the selection, for some
- * reason, Windows deselects the previous two items that
- * were selected. The fix is to stop the selection from
- * changing on all but the item that is supposed to be
- * selected.
- */
- case OS.TVN_ITEMCHANGINGA:
- case OS.TVN_ITEMCHANGINGW: {
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- if ((style & SWT.MULTI) != 0) {
- if (hSelect != 0) {
- NMTVITEMCHANGE pnm = new NMTVITEMCHANGE ();
- OS.MoveMemory (pnm, lParam, NMTVITEMCHANGE.sizeof);
- if (hSelect == pnm.hItem) break;
- return LRESULT.ONE;
- }
- }
- }
- break;
- }
- case OS.TVN_SELCHANGINGA:
- case OS.TVN_SELCHANGINGW: {
- if ((style & SWT.MULTI) != 0) {
- if (lockSelection) {
- /* Save the old selection state for both items */
- NMTREEVIEW treeView = new NMTREEVIEW ();
- OS.MoveMemory (treeView, lParam, NMTREEVIEW.sizeof);
- TVITEM tvItem = treeView.itemOld;
- oldSelected = (tvItem.state & OS.TVIS_SELECTED) != 0;
- tvItem = treeView.itemNew;
- newSelected = (tvItem.state & OS.TVIS_SELECTED) != 0;
- }
- }
- if (!ignoreSelect && !ignoreDeselect) {
- hAnchor = 0;
- if ((style & SWT.MULTI) != 0) deselectAll ();
- }
- break;
- }
- case OS.TVN_SELCHANGEDA:
- case OS.TVN_SELCHANGEDW: {
- NMTREEVIEW treeView = null;
- if ((style & SWT.MULTI) != 0) {
- if (lockSelection) {
- /* Restore the old selection state of both items */
- if (oldSelected) {
- if (treeView == null) {
- treeView = new NMTREEVIEW ();
- OS.MoveMemory (treeView, lParam, NMTREEVIEW.sizeof);
- }
- TVITEM tvItem = treeView.itemOld;
- tvItem.mask = OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_SELECTED;
- tvItem.state = OS.TVIS_SELECTED;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- if (!newSelected && ignoreSelect) {
- if (treeView == null) {
- treeView = new NMTREEVIEW ();
- OS.MoveMemory (treeView, lParam, NMTREEVIEW.sizeof);
- }
- TVITEM tvItem = treeView.itemNew;
- tvItem.mask = OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_SELECTED;
- tvItem.state = 0;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- }
- }
- if (!ignoreSelect) {
- if (treeView == null) {
- treeView = new NMTREEVIEW ();
- OS.MoveMemory (treeView, lParam, NMTREEVIEW.sizeof);
- }
- TVITEM tvItem = treeView.itemNew;
- hAnchor = tvItem.hItem;
- Event event = new Event ();
- event.item = _getItem (tvItem.hItem, (int)/*64*/tvItem.lParam);
- postEvent (SWT.Selection, event);
- }
- updateScrollBar ();
- break;
- }
- case OS.TVN_ITEMEXPANDINGA:
- case OS.TVN_ITEMEXPANDINGW: {
- if (itemToolTipHandle != 0) OS.ShowWindow (itemToolTipHandle, OS.SW_HIDE);
- boolean runExpanded = false;
- if ((style & SWT.VIRTUAL) != 0) style &= ~SWT.DOUBLE_BUFFERED;
- if (hooks (SWT.EraseItem) || hooks (SWT.PaintItem)) style &= ~SWT.DOUBLE_BUFFERED;
- if (findImageControl () != null && getDrawing () && OS.IsWindowVisible (handle)) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- }
- /*
- * Bug in Windows. When TVM_SETINSERTMARK is used to set
- * an insert mark for a tree and an item is expanded or
- * collapsed near the insert mark, the tree does not redraw
- * the insert mark properly. The fix is to hide and show
- * the insert mark whenever an item is expanded or collapsed.
- */
- if (hInsert != 0) {
- OS.SendMessage (handle, OS.TVM_SETINSERTMARK, 0, 0);
- }
- if (!ignoreExpand) {
- NMTREEVIEW treeView = new NMTREEVIEW ();
- OS.MoveMemory (treeView, lParam, NMTREEVIEW.sizeof);
- TVITEM tvItem = treeView.itemNew;
- /*
- * Feature in Windows. In some cases, TVM_ITEMEXPANDING
- * is sent from within TVM_DELETEITEM for the tree item
- * being destroyed. By the time the message is sent,
- * the item has already been removed from the list of
- * items. The fix is to check for null.
- */
- if (items == null) break;
- TreeItem item = _getItem (tvItem.hItem, (int)/*64*/tvItem.lParam);
- if (item == null) break;
- Event event = new Event ();
- event.item = item;
- switch (treeView.action) {
- case OS.TVE_EXPAND:
- /*
- * Bug in Windows. When the numeric keypad asterisk
- * key is used to expand every item in the tree, Windows
- * sends TVN_ITEMEXPANDING to items in the tree that
- * have already been expanded. The fix is to detect
- * that the item is already expanded and ignore the
- * notification.
- */
- if ((tvItem.state & OS.TVIS_EXPANDED) == 0) {
- sendEvent (SWT.Expand, event);
- if (isDisposed ()) return LRESULT.ZERO;
- }
- break;
- case OS.TVE_COLLAPSE:
- sendEvent (SWT.Collapse, event);
- if (isDisposed ()) return LRESULT.ZERO;
- break;
- }
- /*
- * Bug in Windows. When all of the items are deleted during
- * TVN_ITEMEXPANDING, Windows does not send TVN_ITEMEXPANDED.
- * The fix is to detect this case and run the TVN_ITEMEXPANDED
- * code in this method.
- */
- int /*long*/ hFirstItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, tvItem.hItem);
- runExpanded = hFirstItem == 0;
- }
- if (!runExpanded) break;
- //FALL THROUGH
- }
- case OS.TVN_ITEMEXPANDEDA:
- case OS.TVN_ITEMEXPANDEDW: {
- if ((style & SWT.VIRTUAL) != 0) style |= SWT.DOUBLE_BUFFERED;
- if (hooks (SWT.EraseItem) || hooks (SWT.PaintItem)) style |= SWT.DOUBLE_BUFFERED;
- if (findImageControl () != null && getDrawing () /*&& OS.IsWindowVisible (handle)*/) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.InvalidateRect (handle, null, true);
- }
- /*
- * Bug in Windows. When TVM_SETINSERTMARK is used to set
- * an insert mark for a tree and an item is expanded or
- * collapsed near the insert mark, the tree does not redraw
- * the insert mark properly. The fix is to hide and show
- * the insert mark whenever an item is expanded or collapsed.
- */
- if (hInsert != 0) {
- OS.SendMessage (handle, OS.TVM_SETINSERTMARK, insertAfter ? 1 : 0, hInsert);
- }
- /*
- * Bug in Windows. When a tree item that has an image
- * with alpha is expanded or collapsed, the area where
- * the image is drawn is not erased before it is drawn.
- * This means that the image gets darker each time.
- * The fix is to redraw the item.
- */
- if (!OS.IsWinCE && OS.COMCTL32_MAJOR >= 6) {
- if (imageList != null) {
- NMTREEVIEW treeView = new NMTREEVIEW ();
- OS.MoveMemory (treeView, lParam, NMTREEVIEW.sizeof);
- TVITEM tvItem = treeView.itemNew;
- if (tvItem.hItem != 0) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.TVS_FULLROWSELECT) == 0) {
- RECT rect = new RECT ();
- if (OS.TreeView_GetItemRect (handle, tvItem.hItem, rect, false)) {
- OS.InvalidateRect (handle, rect, true);
- }
- }
- }
- }
- }
- updateScrollBar ();
- break;
- }
- case OS.TVN_BEGINDRAGA:
- case OS.TVN_BEGINDRAGW:
- if (OS.GetKeyState (OS.VK_LBUTTON) >= 0) break;
- //FALL THROUGH
- case OS.TVN_BEGINRDRAGA:
- case OS.TVN_BEGINRDRAGW: {
- dragStarted = true;
- NMTREEVIEW treeView = new NMTREEVIEW ();
- OS.MoveMemory (treeView, lParam, NMTREEVIEW.sizeof);
- TVITEM tvItem = treeView.itemNew;
- if (tvItem.hItem != 0 && (tvItem.state & OS.TVIS_SELECTED) == 0) {
- hSelect = tvItem.hItem;
- ignoreSelect = ignoreDeselect = true;
- OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, tvItem.hItem);
- ignoreSelect = ignoreDeselect = false;
- hSelect = 0;
- }
- break;
- }
- case OS.NM_RECOGNIZEGESTURE: {
- /*
- * Feature in Pocket PC. The tree and table controls detect the tap
- * and hold gesture by default. They send a GN_CONTEXTMENU message to show
- * the popup menu. This default behaviour is unwanted on Pocket PC 2002
- * when no menu has been set, as it still draws a red circle. The fix
- * is to disable this default behaviour when no menu is set by returning
- * TRUE when receiving the Pocket PC 2002 specific NM_RECOGNIZEGESTURE
- * message.
- */
- if (OS.IsPPC) {
- boolean hasMenu = menu != null && !menu.isDisposed ();
- if (!hasMenu && !hooks (SWT.MenuDetect)) return LRESULT.ONE;
- }
- break;
- }
- case OS.GN_CONTEXTMENU: {
- if (OS.IsPPC) {
- boolean hasMenu = menu != null && !menu.isDisposed ();
- if (hasMenu || hooks (SWT.MenuDetect)) {
- NMRGINFO nmrg = new NMRGINFO ();
- OS.MoveMemory (nmrg, lParam, NMRGINFO.sizeof);
- showMenu (nmrg.x, nmrg.y);
- gestureCompleted = true;
- return LRESULT.ONE;
- }
- }
- break;
- }
- }
- return super.wmNotifyChild (hdr, wParam, lParam);
-}
-
-LRESULT wmNotifyHeader (NMHDR hdr, int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. On NT, the automatically created
- * header control is created as a UNICODE window, not an
- * ANSI window despite the fact that the parent is created
- * as an ANSI window. This means that it sends UNICODE
- * notification messages to the parent window on NT for
- * no good reason. The data and size in the NMHEADER and
- * HDITEM structs is identical between the platforms so no
- * different message is actually necessary. Despite this,
- * Windows sends different messages. The fix is to look
- * for both messages, despite the platform. This works
- * because only one will be sent on either platform, never
- * both.
- */
- switch (hdr.code) {
- case OS.HDN_BEGINTRACKW:
- case OS.HDN_BEGINTRACKA:
- case OS.HDN_DIVIDERDBLCLICKW:
- case OS.HDN_DIVIDERDBLCLICKA: {
- NMHEADER phdn = new NMHEADER ();
- OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
- TreeColumn column = columns [phdn.iItem];
- if (column != null && !column.getResizable ()) {
- return LRESULT.ONE;
- }
- ignoreColumnMove = true;
- switch (hdr.code) {
- case OS.HDN_DIVIDERDBLCLICKW:
- case OS.HDN_DIVIDERDBLCLICKA:
- if (column != null) column.pack ();
- }
- break;
- }
- case OS.NM_RELEASEDCAPTURE: {
- if (!ignoreColumnMove) {
- for (int i=0; i<columnCount; i++) {
- TreeColumn column = columns [i];
- column.updateToolTip (i);
- }
- updateImageList ();
- }
- ignoreColumnMove = false;
- break;
- }
- case OS.HDN_BEGINDRAG: {
- if (ignoreColumnMove) return LRESULT.ONE;
- NMHEADER phdn = new NMHEADER ();
- OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
- if (phdn.iItem != -1) {
- TreeColumn column = columns [phdn.iItem];
- if (column != null && !column.getMoveable ()) {
- ignoreColumnMove = true;
- return LRESULT.ONE;
- }
- }
- break;
- }
- case OS.HDN_ENDDRAG: {
- NMHEADER phdn = new NMHEADER ();
- OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
- if (phdn.iItem != -1 && phdn.pitem != 0) {
- HDITEM pitem = new HDITEM ();
- OS.MoveMemory (pitem, phdn.pitem, HDITEM.sizeof);
- if ((pitem.mask & OS.HDI_ORDER) != 0 && pitem.iOrder != -1) {
- int [] order = new int [columnCount];
- OS.SendMessage (hwndHeader, OS.HDM_GETORDERARRAY, columnCount, order);
- int index = 0;
- while (index < order.length) {
- if (order [index] == phdn.iItem) break;
- index++;
- }
- if (index == order.length) index = 0;
- if (index == pitem.iOrder) break;
- int start = Math.min (index, pitem.iOrder);
- int end = Math.max (index, pitem.iOrder);
- RECT rect = new RECT (), headerRect = new RECT ();
- OS.GetClientRect (handle, rect);
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, order [start], headerRect);
- rect.left = Math.max (rect.left, headerRect.left);
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, order [end], headerRect);
- rect.right = Math.min (rect.right, headerRect.right);
- OS.InvalidateRect (handle, rect, true);
- ignoreColumnMove = false;
- for (int i=start; i<=end; i++) {
- TreeColumn column = columns [order [i]];
- if (!column.isDisposed ()) {
- column.postEvent (SWT.Move);
- }
- }
- }
- }
- break;
- }
- case OS.HDN_ITEMCHANGINGW:
- case OS.HDN_ITEMCHANGINGA: {
- NMHEADER phdn = new NMHEADER ();
- OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
- if (phdn.pitem != 0) {
- HDITEM newItem = new HDITEM ();
- OS.MoveMemory (newItem, phdn.pitem, HDITEM.sizeof);
- if ((newItem.mask & OS.HDI_WIDTH) != 0) {
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- HDITEM oldItem = new HDITEM ();
- oldItem.mask = OS.HDI_WIDTH;
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, phdn.iItem, oldItem);
- int deltaX = newItem.cxy - oldItem.cxy;
- RECT headerRect = new RECT ();
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, phdn.iItem, headerRect);
- int gridWidth = linesVisible ? GRID_WIDTH : 0;
- rect.left = headerRect.right - gridWidth;
- int newX = rect.left + deltaX;
- rect.right = Math.max (rect.right, rect.left + Math.abs (deltaX));
- if (explorerTheme || (findImageControl () != null || hooks (SWT.MeasureItem) || hooks (SWT.EraseItem) || hooks (SWT.PaintItem))) {
- rect.left -= OS.GetSystemMetrics (OS.SM_CXFOCUSBORDER);
- OS.InvalidateRect (handle, rect, true);
- OS.OffsetRect (rect, deltaX, 0);
- OS.InvalidateRect (handle, rect, true);
- } else {
- int flags = OS.SW_INVALIDATE | OS.SW_ERASE;
- OS.ScrollWindowEx (handle, deltaX, 0, rect, null, 0, null, flags);
- }
- if (OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, phdn.iItem, 0) != 0) {
- rect.left = headerRect.left;
- rect.right = newX;
- OS.InvalidateRect (handle, rect, true);
- }
- setScrollWidth ();
- }
- }
- break;
- }
- case OS.HDN_ITEMCHANGEDW:
- case OS.HDN_ITEMCHANGEDA: {
- NMHEADER phdn = new NMHEADER ();
- OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
- if (phdn.pitem != 0) {
- HDITEM pitem = new HDITEM ();
- OS.MoveMemory (pitem, phdn.pitem, HDITEM.sizeof);
- if ((pitem.mask & OS.HDI_WIDTH) != 0) {
- if (ignoreColumnMove) {
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, null, 0, flags);
- } else {
- if ((style & SWT.DOUBLE_BUFFERED) == 0) {
- int oldStyle = style;
- style |= SWT.DOUBLE_BUFFERED;
- OS.UpdateWindow (handle);
- style = oldStyle;
- }
- }
- }
- TreeColumn column = columns [phdn.iItem];
- if (column != null) {
- column.updateToolTip (phdn.iItem);
- column.sendEvent (SWT.Resize);
- if (isDisposed ()) return LRESULT.ZERO;
- TreeColumn [] newColumns = new TreeColumn [columnCount];
- System.arraycopy (columns, 0, newColumns, 0, columnCount);
- int [] order = new int [columnCount];
- OS.SendMessage (hwndHeader, OS.HDM_GETORDERARRAY, columnCount, order);
- boolean moved = false;
- for (int i=0; i<columnCount; i++) {
- TreeColumn nextColumn = newColumns [order [i]];
- if (moved && !nextColumn.isDisposed ()) {
- nextColumn.updateToolTip (order [i]);
- nextColumn.sendEvent (SWT.Move);
- }
- if (nextColumn == column) moved = true;
- }
- }
- }
- setScrollWidth ();
- }
- break;
- }
- case OS.HDN_ITEMCLICKW:
- case OS.HDN_ITEMCLICKA: {
- NMHEADER phdn = new NMHEADER ();
- OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
- TreeColumn column = columns [phdn.iItem];
- if (column != null) {
- column.postEvent (SWT.Selection);
- }
- break;
- }
- case OS.HDN_ITEMDBLCLICKW:
- case OS.HDN_ITEMDBLCLICKA: {
- NMHEADER phdn = new NMHEADER ();
- OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
- TreeColumn column = columns [phdn.iItem];
- if (column != null) {
- column.postEvent (SWT.DefaultSelection);
- }
- break;
- }
- }
- return null;
-}
-
-LRESULT wmNotifyToolTip (NMHDR hdr, int /*long*/ wParam, int /*long*/ lParam) {
- if (OS.IsWinCE) return null;
- switch (hdr.code) {
- case OS.NM_CUSTOMDRAW: {
- NMTTCUSTOMDRAW nmcd = new NMTTCUSTOMDRAW ();
- OS.MoveMemory (nmcd, lParam, NMTTCUSTOMDRAW.sizeof);
- return wmNotifyToolTip (nmcd, lParam);
- }
- case OS.TTN_SHOW: {
- LRESULT result = super.wmNotify (hdr, wParam, lParam);
- if (result != null) return result;
- int pos = OS.GetMessagePos ();
- POINT pt = new POINT();
- OS.POINTSTOPOINT (pt, pos);
- OS.ScreenToClient (handle, pt);
- int [] index = new int [1];
- TreeItem [] item = new TreeItem [1];
- RECT [] cellRect = new RECT [1], itemRect = new RECT [1];
- if (findCell (pt.x, pt.y, item, index, cellRect, itemRect)) {
- RECT toolRect = toolTipRect (itemRect [0]);
- OS.MapWindowPoints (handle, 0, toolRect, 2);
- int width = toolRect.right - toolRect.left;
- int height = toolRect.bottom - toolRect.top;
- int flags = OS.SWP_NOACTIVATE | OS.SWP_NOZORDER | OS.SWP_NOSIZE;
- if (isCustomToolTip ()) flags &= ~OS.SWP_NOSIZE;
- SetWindowPos (itemToolTipHandle, 0, toolRect.left, toolRect.top, width, height, flags);
- return LRESULT.ONE;
- }
- return result;
- }
- }
- return null;
-}
-
-LRESULT wmNotifyToolTip (NMTTCUSTOMDRAW nmcd, int /*long*/ lParam) {
- if (OS.IsWinCE) return null;
- switch (nmcd.dwDrawStage) {
- case OS.CDDS_PREPAINT: {
- if (isCustomToolTip ()) {
- //TEMPORARY CODE
- //nmcd.uDrawFlags |= OS.DT_CALCRECT;
- //OS.MoveMemory (lParam, nmcd, NMTTCUSTOMDRAW.sizeof);
- if (!OS.IsWinCE && OS.WIN32_VERSION < OS.VERSION (6, 0)) {
- OS.SetTextColor (nmcd.hdc, OS.GetSysColor (OS.COLOR_INFOBK));
- }
- return new LRESULT (OS.CDRF_NOTIFYPOSTPAINT | OS.CDRF_NEWFONT);
- }
- break;
- }
- case OS.CDDS_POSTPAINT: {
- if (!OS.IsWinCE && OS.WIN32_VERSION < OS.VERSION (6, 0)) {
- OS.SetTextColor (nmcd.hdc, OS.GetSysColor (OS.COLOR_INFOTEXT));
- }
- if (OS.SendMessage (itemToolTipHandle, OS.TTM_GETCURRENTTOOL, 0, 0) != 0) {
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- if (OS.SendMessage (itemToolTipHandle, OS.TTM_GETCURRENTTOOL, 0, lpti) != 0) {
- int [] index = new int [1];
- TreeItem [] item = new TreeItem [1];
- RECT [] cellRect = new RECT [1], itemRect = new RECT [1];
- int pos = OS.GetMessagePos ();
- POINT pt = new POINT();
- OS.POINTSTOPOINT (pt, pos);
- OS.ScreenToClient (handle, pt);
- if (findCell (pt.x, pt.y, item, index, cellRect, itemRect)) {
- int /*long*/ hDC = OS.GetDC (handle);
- int /*long*/ hFont = item [0].fontHandle (index [0]);
- if (hFont == -1) hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- int /*long*/ oldFont = OS.SelectObject (hDC, hFont);
- LRESULT result = null;
- boolean drawForeground = true;
- cellRect [0] = item [0].getBounds (index [0], true, true, false, false, false, hDC);
- if (hooks (SWT.EraseItem)) {
- Event event = sendEraseItemEvent (item [0], nmcd, index [0], cellRect [0]);
- if (isDisposed () || item [0].isDisposed ()) break;
- if (event.doit) {
- drawForeground = (event.detail & SWT.FOREGROUND) != 0;
- } else {
- drawForeground = false;
- }
- }
- if (drawForeground) {
- int nSavedDC = OS.SaveDC (nmcd.hdc);
- int gridWidth = getLinesVisible () ? Table.GRID_WIDTH : 0;
- RECT insetRect = toolTipInset (cellRect [0]);
- OS.SetWindowOrgEx (nmcd.hdc, insetRect.left, insetRect.top, null);
- GCData data = new GCData ();
- data.device = display;
- data.foreground = OS.GetTextColor (nmcd.hdc);
- data.background = OS.GetBkColor (nmcd.hdc);
- data.font = Font.win32_new (display, hFont);
- GC gc = GC.win32_new (nmcd.hdc, data);
- int x = cellRect [0].left + INSET;
- if (index [0] != 0) x -= gridWidth;
- Image image = item [0].getImage (index [0]);
- if (image != null || index [0] == 0) {
- Point size = getImageSize ();
- RECT imageRect = item [0].getBounds (index [0], false, true, false, false, false, hDC);
- if (imageList == null) size.x = imageRect.right - imageRect.left;
- if (image != null) {
- Rectangle rect = image.getBounds ();
- gc.drawImage (image, rect.x, rect.y, rect.width, rect.height, x, imageRect.top, size.x, size.y);
- x += INSET + (index [0] == 0 ? 1 : 0);
- }
- x += size.x;
- } else {
- x += INSET;
- }
- String string = item [0].getText (index [0]);
- if (string != null) {
- int flags = OS.DT_NOPREFIX | OS.DT_SINGLELINE | OS.DT_VCENTER;
- TreeColumn column = columns != null ? columns [index [0]] : null;
- if (column != null) {
- if ((column.style & SWT.CENTER) != 0) flags |= OS.DT_CENTER;
- if ((column.style & SWT.RIGHT) != 0) flags |= OS.DT_RIGHT;
- }
- TCHAR buffer = new TCHAR (getCodePage (), string, false);
- RECT textRect = new RECT ();
- OS.SetRect (textRect, x, cellRect [0].top, cellRect [0].right, cellRect [0].bottom);
- OS.DrawText (nmcd.hdc, buffer, buffer.length (), textRect, flags);
- }
- gc.dispose ();
- OS.RestoreDC (nmcd.hdc, nSavedDC);
- }
- if (hooks (SWT.PaintItem)) {
- itemRect [0] = item [0].getBounds (index [0], true, true, false, false, false, hDC);
- sendPaintItemEvent (item [0], nmcd, index[0], itemRect [0]);
- }
- OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- if (result != null) return result;
- }
- break;
- }
- }
- break;
- }
- }
- return null;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java
deleted file mode 100644
index fbd4e6a519..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java
+++ /dev/null
@@ -1,758 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a column in a tree widget.
- * <p><dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd> Move, Resize, Selection</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT and CENTER may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TreeColumn extends Item {
- Tree parent;
- boolean resizable, moveable;
- String toolTipText;
- int id;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeColumn (Tree parent, int style) {
- super (parent, checkStyle (style));
- resizable = true;
- this.parent = parent;
- parent.createItem (this, parent.getColumnCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeColumn (Tree parent, int style, int index) {
- super (parent, checkStyle (style));
- resizable = true;
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize,typedListener);
- addListener (SWT.Move,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the column header is selected.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget ();
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-/**
- * Gets the moveable attribute. A column that is
- * not moveable cannot be reordered by the user
- * by dragging the header but may be reordered
- * by the programmer.
- *
- * @return the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
-public boolean getMoveable () {
- checkWidget ();
- return moveable;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Tree</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Tree getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Gets the resizable attribute. A column that is
- * not resizable cannot be dragged by the user but
- * may be resized by the programmer.
- *
- * @return the resizable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getResizable () {
- checkWidget ();
- return resizable;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) return 0;
- int /*long*/ hwndHeader = parent.hwndHeader;
- if (hwndHeader == 0) return 0;
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_WIDTH;
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, hdItem);
- return hdItem.cxy;
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void pack () {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) return;
- int columnWidth = 0;
- int /*long*/ hwnd = parent.handle, hwndHeader = parent.hwndHeader;
- RECT headerRect = new RECT ();
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect);
- int /*long*/ hDC = OS.GetDC (hwnd);
- int /*long*/ oldFont = 0, newFont = OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- tvItem.hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- while (tvItem.hItem != 0) {
- OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem);
- TreeItem item = tvItem.lParam != -1 ? parent.items [(int)/*64*/tvItem.lParam] : null;
- if (item != null) {
- int itemRight = 0;
- if (parent.hooks (SWT.MeasureItem)) {
- Event event = parent.sendMeasureItemEvent (item, index, hDC);
- if (isDisposed () || parent.isDisposed ()) break;
- itemRight = event.x + event.width;
- } else {
- int /*long*/ hFont = item.fontHandle (index);
- if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
- RECT itemRect = item.getBounds (index, true, true, false, false, false, hDC);
- if (hFont != -1) OS.SelectObject (hDC, hFont);
- itemRight = itemRect.right;
- }
- columnWidth = Math.max (columnWidth, itemRight - headerRect.left);
- }
- tvItem.hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, tvItem.hItem);
- }
- RECT rect = new RECT ();
- int flags = OS.DT_CALCRECT | OS.DT_NOPREFIX;
- TCHAR buffer = new TCHAR (parent.getCodePage (), text, false);
- OS.DrawText (hDC, buffer, buffer.length (), rect, flags);
- int headerWidth = rect.right - rect.left + Tree.HEADER_MARGIN;
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) headerWidth += Tree.HEADER_EXTRA;
- if (image != null || parent.sortColumn == this) {
- Image headerImage = null;
- if (parent.sortColumn == this && parent.sortDirection != SWT.NONE) {
- if (OS.COMCTL32_MAJOR < 6) {
- headerImage = display.getSortImage (parent.sortDirection);
- } else {
- headerWidth += Tree.SORT_WIDTH;
- }
- } else {
- headerImage = image;
- }
- if (headerImage != null) {
- Rectangle bounds = headerImage.getBounds ();
- headerWidth += bounds.width;
- }
- int margin = 0;
- if (hwndHeader != 0 && OS.COMCTL32_VERSION >= OS.VERSION (5, 80)) {
- margin = (int)/*64*/OS.SendMessage (hwndHeader, OS.HDM_GETBITMAPMARGIN, 0, 0);
- } else {
- margin = OS.GetSystemMetrics (OS.SM_CXEDGE) * 3;
- }
- headerWidth += margin * 2;
- }
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (hwnd, hDC);
- int gridWidth = parent.linesVisible ? Tree.GRID_WIDTH : 0;
- setWidth (Math.max (headerWidth, columnWidth + gridWidth));
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parent = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (parent.sortColumn == this) {
- parent.sortColumn = null;
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>.
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget ();
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- int index = parent.indexOf (this);
- if (index == -1 || index == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- int /*long*/ hwndHeader = parent.hwndHeader;
- if (hwndHeader == 0) return;
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_FORMAT;
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, hdItem);
- hdItem.fmt &= ~OS.HDF_JUSTIFYMASK;
- if ((style & SWT.LEFT) == SWT.LEFT) hdItem.fmt |= OS.HDF_LEFT;
- if ((style & SWT.CENTER) == SWT.CENTER) hdItem.fmt |= OS.HDF_CENTER;
- if ((style & SWT.RIGHT) == SWT.RIGHT) hdItem.fmt |= OS.HDF_RIGHT;
- OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, hdItem);
- if (index != 0) {
- int /*long*/ hwnd = parent.handle;
- parent.forceResize ();
- RECT rect = new RECT (), headerRect = new RECT ();
- OS.GetClientRect (hwnd, rect);
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect);
- rect.left = headerRect.left;
- rect.right = headerRect.right;
- OS.InvalidateRect (hwnd, rect, true);
- }
-}
-
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- super.setImage (image);
- if (parent.sortColumn != this || parent.sortDirection != SWT.NONE) {
- setImage (image, false, false);
- }
-}
-
-void setImage (Image image, boolean sort, boolean right) {
- int index = parent.indexOf (this);
- if (index == -1) return;
- int /*long*/ hwndHeader = parent.hwndHeader;
- if (hwndHeader == 0) return;
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_FORMAT | OS.HDI_IMAGE | OS.HDI_BITMAP;
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, hdItem);
- hdItem.fmt &= ~OS.HDF_BITMAP_ON_RIGHT;
- if (image != null) {
- if (sort) {
- hdItem.mask &= ~OS.HDI_IMAGE;
- hdItem.fmt &= ~OS.HDF_IMAGE;
- hdItem.fmt |= OS.HDF_BITMAP;
- hdItem.hbm = image.handle;
- } else {
- hdItem.mask &= ~OS.HDI_BITMAP;
- hdItem.fmt &= ~OS.HDF_BITMAP;
- hdItem.fmt |= OS.HDF_IMAGE;
- hdItem.iImage = parent.imageIndexHeader (image);
- }
- if (right) hdItem.fmt |= OS.HDF_BITMAP_ON_RIGHT;
- } else {
- hdItem.mask &= ~(OS.HDI_IMAGE | OS.HDI_BITMAP);
- hdItem.fmt &= ~(OS.HDF_IMAGE | OS.HDF_BITMAP);
- }
- OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, hdItem);
-}
-
-/**
- * Sets the moveable attribute. A column that is
- * moveable can be reordered by the user by dragging
- * the header. A column that is not moveable cannot be
- * dragged by the user but may be reordered
- * by the programmer.
- *
- * @param moveable the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#setColumnOrder(int[])
- * @see Tree#getColumnOrder()
- * @see TreeColumn#getMoveable()
- * @see SWT#Move
- *
- * @since 3.2
- */
-public void setMoveable (boolean moveable) {
- checkWidget ();
- this.moveable = moveable;
-}
-
-/**
- * Sets the resizable attribute. A column that is
- * not resizable cannot be dragged by the user but
- * may be resized by the programmer.
- *
- * @param resizable the resize attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setResizable (boolean resizable) {
- checkWidget ();
- this.resizable = resizable;
-}
-
-void setSortDirection (int direction) {
- if (OS.COMCTL32_MAJOR >= 6) {
- int /*long*/ hwndHeader = parent.hwndHeader;
- if (hwndHeader != 0) {
- int index = parent.indexOf (this);
- if (index == -1) return;
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_FORMAT | OS.HDI_IMAGE;
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, hdItem);
- switch (direction) {
- case SWT.UP:
- hdItem.fmt &= ~(OS.HDF_IMAGE | OS.HDF_SORTDOWN);
- hdItem.fmt |= OS.HDF_SORTUP;
- if (image == null) hdItem.mask &= ~OS.HDI_IMAGE;
- break;
- case SWT.DOWN:
- hdItem.fmt &= ~(OS.HDF_IMAGE | OS.HDF_SORTUP);
- hdItem.fmt |= OS.HDF_SORTDOWN;
- if (image == null) hdItem.mask &= ~OS.HDI_IMAGE;
- break;
- case SWT.NONE:
- hdItem.fmt &= ~(OS.HDF_SORTUP | OS.HDF_SORTDOWN);
- if (image != null) {
- hdItem.fmt |= OS.HDF_IMAGE;
- hdItem.iImage = parent.imageIndexHeader (image);
- } else {
- hdItem.fmt &= ~OS.HDF_IMAGE;
- hdItem.mask &= ~OS.HDI_IMAGE;
- }
- break;
- }
- OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, hdItem);
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- int /*long*/ hwnd = parent.handle;
- parent.forceResize ();
- RECT rect = new RECT (), headerRect = new RECT ();
- OS.GetClientRect (hwnd, rect);
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect);
- rect.left = headerRect.left;
- rect.right = headerRect.right;
- OS.InvalidateRect (hwnd, rect, true);
- }
- }
- } else {
- switch (direction) {
- case SWT.UP:
- case SWT.DOWN:
- setImage (display.getSortImage (direction), true, true);
- break;
- case SWT.NONE:
- setImage (image, false, false);
- break;
- }
- }
-}
-
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (string.equals (text)) return;
- int index = parent.indexOf (this);
- if (index == -1) return;
- super.setText (string);
- /*
- * Bug in Windows. When a column header contains a
- * mnemonic character, Windows does not measure the
- * text properly. This causes '...' to always appear
- * at the end of the text. The fix is to remove
- * mnemonic characters and replace doubled mnemonics
- * with spaces.
- */
- int /*long*/ hHeap = OS.GetProcessHeap ();
- TCHAR buffer = new TCHAR (parent.getCodePage (), fixMnemonic (string, true), true);
- int byteCount = buffer.length () * TCHAR.sizeof;
- int /*long*/ pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (pszText, buffer, byteCount);
- int /*long*/ hwndHeader = parent.hwndHeader;
- if (hwndHeader == 0) return;
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_TEXT;
- hdItem.pszText = pszText;
- int /*long*/ result = OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, hdItem);
- if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
- if (result == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
- int /*long*/ hwndHeaderToolTip = parent.headerToolTipHandle;
- if (hwndHeaderToolTip == 0) {
- parent.createHeaderToolTips ();
- parent.updateHeaderToolTips ();
- }
-}
-
-/**
- * Sets the width of the receiver.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int width) {
- checkWidget ();
- if (width < 0) return;
- int index = parent.indexOf (this);
- if (index == -1) return;
- int /*long*/ hwndHeader = parent.hwndHeader;
- if (hwndHeader == 0) return;
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_WIDTH;
- hdItem.cxy = width;
- OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, hdItem);
- RECT headerRect = new RECT ();
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect);
- parent.forceResize ();
- int /*long*/ hwnd = parent.handle;
- RECT rect = new RECT ();
- OS.GetClientRect (hwnd, rect);
- rect.left = headerRect.left;
- OS.InvalidateRect (hwnd, rect, true);
- parent.setScrollWidth ();
-}
-
-void updateToolTip (int index) {
- int /*long*/ hwndHeaderToolTip = parent.headerToolTipHandle;
- if (hwndHeaderToolTip != 0) {
- int /*long*/ hwndHeader = parent.hwndHeader;
- RECT rect = new RECT ();
- if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, rect) != 0) {
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- lpti.hwnd = hwndHeader;
- lpti.uId = id;
- lpti.left = rect.left;
- lpti.top = rect.top;
- lpti.right = rect.right;
- lpti.bottom = rect.bottom;
- OS.SendMessage (hwndHeaderToolTip, OS.TTM_NEWTOOLRECT, 0, lpti);
- }
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java
deleted file mode 100755
index 40bf5358b0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java
+++ /dev/null
@@ -1,1819 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a hierarchy of tree items in a tree widget.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class TreeItem extends Item {
- /**
- * the handle to the OS resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ handle;
- Tree parent;
- String [] strings;
- Image [] images;
- Font font;
- Font [] cellFont;
- boolean cached;
- int background = -1, foreground = -1;
- int [] cellBackground, cellForeground;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>)
- * and a style value describing its behavior and appearance.
- * The item is added to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (Tree parent, int style) {
- this (parent, style, OS.TVGN_ROOT, OS.TVI_LAST, 0);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>),
- * a style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (Tree parent, int style, int index) {
- this (parent, style, OS.TVGN_ROOT, findPrevious (parent, index), 0);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>)
- * and a style value describing its behavior and appearance.
- * The item is added to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parentItem a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (TreeItem parentItem, int style) {
- this (checkNull (parentItem).parent, style, parentItem.handle, OS.TVI_LAST, 0);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>),
- * a style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parentItem a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (TreeItem parentItem, int style, int index) {
- this (checkNull (parentItem).parent, style, parentItem.handle, findPrevious (parentItem, index), 0);
-}
-
-TreeItem (Tree parent, int style, int /*long*/ hParent, int /*long*/ hInsertAfter, int /*long*/ hItem) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, hParent, hInsertAfter, hItem);
-}
-
-static TreeItem checkNull (TreeItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-
-static int /*long*/ findPrevious (Tree parent, int index) {
- if (parent == null) return 0;
- if (index < 0) SWT.error (SWT.ERROR_INVALID_RANGE);
- if (index == 0) return OS.TVI_FIRST;
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hFirstItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- int /*long*/ hItem = parent.findItem (hFirstItem, index - 1);
- if (hItem == 0) SWT.error (SWT.ERROR_INVALID_RANGE);
- return hItem;
-}
-
-static int /*long*/ findPrevious (TreeItem parentItem, int index) {
- if (parentItem == null) return 0;
- if (index < 0) SWT.error (SWT.ERROR_INVALID_RANGE);
- if (index == 0) return OS.TVI_FIRST;
- Tree parent = parentItem.parent;
- int /*long*/ hwnd = parent.handle, hParent = parentItem.handle;
- int /*long*/ hFirstItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hParent);
- int /*long*/ hItem = parent.findItem (hFirstItem, index - 1);
- if (hItem == 0) SWT.error (SWT.ERROR_INVALID_RANGE);
- return hItem;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void clear () {
- text = "";
- image = null;
- strings = null;
- images = null;
- if ((parent.style & SWT.CHECK) != 0) {
- int /*long*/ hwnd = parent.handle;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_STATEIMAGEMASK;
- tvItem.state = 1 << 12;
- tvItem.hItem = handle;
- OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem);
- }
- background = foreground = -1;
- font = null;
- cellBackground = cellForeground = null;
- cellFont = null;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = false;
-}
-
-/**
- * Clears the item at the given zero-relative index in the receiver.
- * The text, icon and other attributes of the item are set to the default
- * value. If the tree was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param index the index of the item to clear
- * @param all <code>true</code> if all child items of the indexed item should be
- * cleared recursively, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clear (int index, boolean all) {
- checkWidget ();
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle);
- if (hItem == 0) error (SWT.ERROR_INVALID_RANGE);
- hItem = parent.findItem (hItem, index);
- if (hItem == 0) error (SWT.ERROR_INVALID_RANGE);
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- parent.clear (hItem, tvItem);
- if (all) {
- hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hItem);
- parent.clearAll (hItem, tvItem, all);
- }
-}
-
-/**
- * Clears all the items in the receiver. The text, icon and other
- * attributes of the items are set to their default values. If the
- * tree was created with the <code>SWT.VIRTUAL</code> style, these
- * attributes are requested again as needed.
- *
- * @param all <code>true</code> if all child items should be cleared
- * recursively, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clearAll (boolean all) {
- checkWidget ();
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle);
- if (hItem == 0) return;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- parent.clearAll (hItem, tvItem, all);
-}
-
-void destroyWidget () {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- parent.releaseItem (handle, tvItem, false);
- parent.destroyItem (this, handle);
- releaseHandle ();
-}
-
-int /*long*/ fontHandle (int index) {
- if (cellFont != null && cellFont [index] != null) return cellFont [index].handle;
- if (font != null) return font.handle;
- return -1;
-}
-
-/**
- * Returns the receiver's background color.
- *
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public Color getBackground () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (background == -1) return parent.getBackground ();
- return Color.win32_new (display, background);
-}
-
-/**
- * Returns the background color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Color getBackground (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return getBackground ();
- int pixel = cellBackground != null ? cellBackground [index] : -1;
- return pixel == -1 ? getBackground () : Color.win32_new (display, pixel);
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- RECT rect = getBounds (0, true, false, false);
- int width = rect.right - rect.left, height = rect.bottom - rect.top;
- return new Rectangle (rect.left, rect.top, width, height);
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent at a column in the tree.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding column rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Rectangle getBounds (int index) {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- RECT rect = getBounds (index, true, true, true);
- int width = rect.right - rect.left, height = rect.bottom - rect.top;
- return new Rectangle (rect.left, rect.top, width, height);
-}
-
-RECT getBounds (int index, boolean getText, boolean getImage, boolean fullText) {
- return getBounds (index, getText, getImage, fullText, false, true, 0);
-}
-
-//TODO - take into account grid (add boolean arg) to damage less during redraw
-RECT getBounds (int index, boolean getText, boolean getImage, boolean fullText, boolean fullImage, boolean clip, int /*long*/ hDC) {
- if (!getText && !getImage) return new RECT ();
- int /*long*/ hwnd = parent.handle;
- if ((parent.style & SWT.VIRTUAL) == 0 && !cached && !parent.painted) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_TEXT;
- tvItem.hItem = handle;
- tvItem.pszText = OS.LPSTR_TEXTCALLBACK;
- parent.ignoreCustomDraw = true;
- OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem);
- parent.ignoreCustomDraw = false;
- }
- boolean firstColumn = index == 0;
- int columnCount = 0;
- int /*long*/ hwndHeader = parent.hwndHeader;
- if (hwndHeader != 0) {
- columnCount = parent.columnCount;
- firstColumn = index == OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0);
- }
- RECT rect = new RECT ();
- if (firstColumn) {
- boolean full = columnCount == 0 && getText && getImage && fullText && fullImage;
- if (!OS.TreeView_GetItemRect (hwnd, handle, rect, !full)) {
- return new RECT ();
- }
- if (getImage && !fullImage) {
- if (OS.SendMessage (hwnd, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0) != 0) {
- Point size = parent.getImageSize ();
- rect.left -= size.x + Tree.INSET;
- if (!getText) rect.right = rect.left + size.x;
- } else {
- if (!getText) rect.right = rect.left;
- }
- }
- if (fullText || fullImage || clip) {
- if (hwndHeader != 0) {
- RECT headerRect = new RECT ();
- if (columnCount != 0) {
- if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect) == 0) {
- return new RECT ();
- }
- } else {
- headerRect.right = parent.scrollWidth;
- if (headerRect.right == 0) headerRect = rect;
- }
- if (fullText && clip) rect.right = headerRect.right;
- if (fullImage) rect.left = headerRect.left;
- if (clip && headerRect.right < rect.right) {
- rect.right = headerRect.right;
- }
- }
- }
- } else {
- if (!(0 <= index && index < columnCount)) return new RECT ();
- RECT headerRect = new RECT ();
- if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect) == 0) {
- return new RECT ();
- }
- if (!OS.TreeView_GetItemRect (hwnd, handle, rect, false)) {
- return new RECT ();
- }
- rect.left = headerRect.left;
- if (fullText && getImage && clip) {
- rect.right = headerRect.right;
- } else {
- rect.right = headerRect.left;
- Image image = null;
- if (index == 0) {
- image = this.image;
- } else {
- if (images != null) image = images [index];
- }
- if (image != null) {
- Point size = parent.getImageSize ();
- rect.right += size.x;
- }
- if (getText) {
- if (fullText && clip) {
- rect.left = rect.right + Tree.INSET;
- rect.right = headerRect.right;
- } else {
- String string = index == 0 ? text : strings != null ? strings [index] : null;
- if (string != null) {
- RECT textRect = new RECT ();
- TCHAR buffer = new TCHAR (parent.getCodePage (), string, false);
- int flags = OS.DT_NOPREFIX | OS.DT_SINGLELINE | OS.DT_CALCRECT;
- int /*long*/ hNewDC = hDC, hFont = 0;
- if (hDC == 0) {
- hNewDC = OS.GetDC (hwnd);
- hFont = fontHandle (index);
- if (hFont == -1) hFont = OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0);
- hFont = OS.SelectObject (hNewDC, hFont);
- }
- OS.DrawText (hNewDC, buffer, buffer.length (), textRect, flags);
- if (hDC == 0) {
- OS.SelectObject (hNewDC, hFont);
- OS.ReleaseDC (hwnd, hNewDC);
- }
- if (getImage) {
- rect.right += textRect.right - textRect.left + Tree.INSET * 3;
- } else {
- rect.left = rect.right + Tree.INSET;
- rect.right = rect.left + (textRect.right - textRect.left) + Tree.INSET;
- }
- }
- }
- }
- if (clip && headerRect.right < rect.right) {
- rect.right = headerRect.right;
- }
- }
- }
- int gridWidth = parent.linesVisible && columnCount != 0 ? Tree.GRID_WIDTH : 0;
- if (getText || !getImage) {
- rect.right = Math.max (rect.left, rect.right - gridWidth);
- }
- rect.bottom = Math.max (rect.top, rect.bottom - gridWidth);
- return rect;
-}
-
-/**
- * Returns <code>true</code> if the receiver is checked,
- * and false otherwise. When the parent does not have
- * the <code>CHECK style, return false.
- * <p>
- *
- * @return the checked state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getChecked () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- int /*long*/ hwnd = parent.handle;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_STATEIMAGEMASK;
- tvItem.hItem = handle;
- int /*long*/ result = OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem);
- return (result != 0) && (((tvItem.state >> 12) & 1) == 0);
-}
-
-/**
- * Returns <code>true</code> if the receiver is expanded,
- * and false otherwise.
- * <p>
- *
- * @return the expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getExpanded () {
- checkWidget ();
- int /*long*/ hwnd = parent.handle;
- int state = 0;
- if (OS.IsWinCE) {
- TVITEM tvItem = new TVITEM ();
- tvItem.hItem = handle;
- tvItem.mask = OS.TVIF_STATE;
- OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem);
- state = tvItem.state;
- } else {
- /*
- * Bug in Windows. Despite the fact that TVM_GETITEMSTATE claims
- * to return only the bits specified by the stateMask, when called
- * with TVIS_EXPANDED, the entire state is returned. The fix is
- * to explicitly check for the TVIS_EXPANDED bit.
- */
- state = (int)/*64*/OS.SendMessage (hwnd, OS.TVM_GETITEMSTATE, handle, OS.TVIS_EXPANDED);
- }
- return (state & OS.TVIS_EXPANDED) != 0;
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information for this item.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return font != null ? font : parent.getFont ();
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information
- * for the specified cell in this item.
- *
- * @param index the column index
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Font getFont (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count -1) return getFont ();
- if (cellFont == null || cellFont [index] == null) return getFont ();
- return cellFont [index];
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public Color getForeground () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (foreground == -1) return parent.getForeground ();
- return Color.win32_new (display, foreground);
-}
-
-/**
- *
- * Returns the foreground color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Color getForeground (int index) {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count -1) return getForeground ();
- int pixel = cellForeground != null ? cellForeground [index] : -1;
- return pixel == -1 ? getForeground () : Color.win32_new (display, pixel);
-}
-
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the parent does not have
- * the <code>CHECK style, return false.
- * <p>
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getGrayed () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- int /*long*/ hwnd = parent.handle;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_STATEIMAGEMASK;
- tvItem.hItem = handle;
- int /*long*/ result = OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem);
- return (result != 0) && ((tvItem.state >> 12) > 2);
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public TreeItem getItem (int index) {
- checkWidget ();
- if (index < 0) error (SWT.ERROR_INVALID_RANGE);
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hFirstItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle);
- if (hFirstItem == 0) error (SWT.ERROR_INVALID_RANGE);
- int /*long*/ hItem = parent.findItem (hFirstItem, index);
- if (hItem == 0) error (SWT.ERROR_INVALID_RANGE);
- return parent._getItem (hItem);
-}
-
-/**
- * Returns the number of items contained in the receiver
- * that are direct item children of the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle);
- if (hItem == 0) return 0;
- return parent.getItemCount (hItem);
-}
-
-/**
- * Returns a (possibly empty) array of <code>TreeItem</code>s which
- * are the direct item children of the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem [] getItems () {
- checkWidget ();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle);
- if (hItem == 0) return new TreeItem [0];
- return parent.getItems (hItem);
-}
-
-public Image getImage () {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return super.getImage ();
-}
-
-/**
- * Returns the image stored at the given column index in the receiver,
- * or null if the image has not been set or if the column does not exist.
- *
- * @param index the column index
- * @return the image stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Image getImage (int index) {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index == 0) return getImage ();
- if (images != null) {
- if (0 <= index && index < images.length) return images [index];
- }
- return null;
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of an image at a column in the
- * tree.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding image rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Rectangle getImageBounds (int index) {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- RECT rect = getBounds (index, false, true, false);
- int width = rect.right - rect.left, height = rect.bottom - rect.top;
- return new Rectangle (rect.left, rect.top, width, height);
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Tree</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Tree getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>TreeItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem getParentItem () {
- checkWidget ();
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_PARENT, handle);
- return hItem != 0 ? parent._getItem (hItem) : null;
-}
-
-public String getText () {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- return super.getText ();
-}
-
-/**
- * Returns the text stored at the given column index in the receiver,
- * or empty string if the text has not been set.
- *
- * @param index the column index
- * @return the text stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public String getText (int index) {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index == 0) return getText ();
- if (strings != null) {
- if (0 <= index && index < strings.length) {
- String string = strings [index];
- return string != null ? string : "";
- }
- }
- return "";
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of the text at a column in the
- * tree.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding text rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Rectangle getTextBounds (int index) {
- checkWidget();
- if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
- RECT rect = getBounds (index, true, false, true);
- if (index == 0) rect.left += Tree.INSET - 1;
- rect.left = Math.min (rect.left, rect.right);
- rect.right = rect.right - Tree.INSET;
- int width = Math.max (0, rect.right - rect.left);
- int height = Math.max (0, rect.bottom - rect.top);
- return new Rectangle (rect.left, rect.top, width, height);
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int indexOf (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle);
- return hItem == 0 ? -1 : parent.findIndex (hItem, item.handle);
-}
-
-void redraw () {
- if (parent.currentItem == this || !parent.getDrawing ()) return;
- int /*long*/ hwnd = parent.handle;
- if (!OS.IsWindowVisible (hwnd)) return;
- /*
- * When there are no columns and the tree is not
- * full selection, redraw only the text. This is
- * an optimization to reduce flashing.
- */
- boolean full = (parent.style & (SWT.FULL_SELECTION | SWT.VIRTUAL)) != 0;
- if (!full) {
- full = parent.columnCount != 0;
- if (!full) {
- if (parent.hooks (SWT.EraseItem) || parent.hooks (SWT.PaintItem)) {
- full = true;
- }
- }
- }
- RECT rect = new RECT ();
- if (OS.TreeView_GetItemRect (hwnd, handle, rect, !full)) {
- OS.InvalidateRect (hwnd, rect, true);
- }
-}
-
-void redraw (int column, boolean drawText, boolean drawImage) {
- if (parent.currentItem == this || !parent.getDrawing ()) return;
- int /*long*/ hwnd = parent.handle;
- if (!OS.IsWindowVisible (hwnd)) return;
- boolean fullImage = column == 0 && drawText && drawImage;
- RECT rect = getBounds (column, drawText, drawImage, true, fullImage, true, 0);
- OS.InvalidateRect (hwnd, rect, true);
-}
-
-void releaseChildren (boolean destroy) {
- if (destroy) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- parent.releaseItems (handle, tvItem);
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- handle = 0;
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- strings = null;
- images = null;
- cellBackground = cellForeground = null;
- cellFont = null;
-}
-
-/**
- * Removes all of the items from the receiver.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void removeAll () {
- checkWidget ();
- int /*long*/ hwnd = parent.handle;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- tvItem.hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle);
- while (tvItem.hItem != 0) {
- OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem);
- TreeItem item = tvItem.lParam != -1 ? parent.items [(int)/*64*/tvItem.lParam] : null;
- if (item != null && !item.isDisposed ()) {
- item.dispose ();
- } else {
- parent.releaseItem (tvItem.hItem, tvItem, false);
- parent.destroyItem (null, tvItem.hItem);
- }
- tvItem.hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle);
- }
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public void setBackground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int pixel = -1;
- if (color != null) {
- parent.customDraw = true;
- pixel = color.handle;
- }
- if (background == pixel) return;
- background = pixel;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- redraw ();
-}
-
-/**
- * Sets the background color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- *
- */
-public void setBackground (int index, Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- int pixel = -1;
- if (color != null) {
- parent.customDraw = true;
- pixel = color.handle;
- }
- if (cellBackground == null) {
- cellBackground = new int [count];
- for (int i = 0; i < count; i++) {
- cellBackground [i] = -1;
- }
- }
- if (cellBackground [index] == pixel) return;
- cellBackground [index] = pixel;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- redraw (index, true, true);
-}
-
-/**
- * Sets the checked state of the receiver.
- * <p>
- *
- * @param checked the new checked state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setChecked (boolean checked) {
- checkWidget ();
- if ((parent.style & SWT.CHECK) == 0) return;
- int /*long*/ hwnd = parent.handle;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_STATEIMAGEMASK;
- tvItem.hItem = handle;
- OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem);
- int state = tvItem.state >> 12;
- if (checked) {
- if ((state & 0x1) != 0) state++;
- } else {
- if ((state & 0x1) == 0) --state;
- }
- state <<= 12;
- if (tvItem.state == state) return;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- tvItem.state = state;
- OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem);
- /*
- * Bug in Windows. When TVM_SETITEM is used to set
- * the state image of an item inside TVN_GETDISPINFO,
- * the new state is not redrawn. The fix is to force
- * a redraw.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (parent.currentItem == this && OS.IsWindowVisible (hwnd)) {
- RECT rect = new RECT ();
- if (OS.TreeView_GetItemRect (hwnd, handle, rect, false)) {
- OS.InvalidateRect (hwnd, rect, true);
- }
- }
- }
-}
-
-/**
- * Sets the expanded state of the receiver.
- * <p>
- *
- * @param expanded the new expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setExpanded (boolean expanded) {
- checkWidget ();
-
- /* Do nothing when the item is a leaf or already expanded */
- int /*long*/ hwnd = parent.handle;
- if (OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle) == 0) {
- return;
- }
- int state = 0;
- if (OS.IsWinCE) {
- TVITEM tvItem = new TVITEM ();
- tvItem.hItem = handle;
- tvItem.mask = OS.TVIF_STATE;
- OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem);
- state = tvItem.state;
- } else {
- /*
- * Bug in Windows. Despite the fact that TVM_GETITEMSTATE claims
- * to return only the bits specified by the stateMask, when called
- * with TVIS_EXPANDED, the entire state is returned. The fix is
- * to explicitly check for the TVIS_EXPANDED bit.
- */
- state = (int)/*64*/OS.SendMessage (hwnd, OS.TVM_GETITEMSTATE, handle, OS.TVIS_EXPANDED);
- }
- if (((state & OS.TVIS_EXPANDED) != 0) == expanded) return;
-
- /*
- * Feature in Windows. When TVM_EXPAND is used to expand
- * an item, the widget scrolls to show the item and the
- * newly expanded items. While not strictly incorrect,
- * this means that application code that expands tree items
- * in a background thread can scroll the widget while the
- * user is interacting with it. The fix is to remember
- * the top item and the bounds of every tree item, turn
- * redraw off, expand the item, scroll back to the top
- * item. If none of the rectangles have moved, then
- * it is safe to turn redraw back on without redrawing
- * the control.
- */
- RECT oldRect = null;
- RECT [] rects = null;
- SCROLLINFO oldInfo = null;
- int count = 0;
- int /*long*/ hBottomItem = 0;
- boolean redraw = false, noScroll = true;
- int /*long*/ hTopItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0);
- if (noScroll && hTopItem != 0) {
- oldInfo = new SCROLLINFO ();
- oldInfo.cbSize = SCROLLINFO.sizeof;
- oldInfo.fMask = OS.SIF_ALL;
- if (!OS.GetScrollInfo (hwnd, OS.SB_HORZ, oldInfo)) {
- oldInfo = null;
- }
- if (parent.getDrawing () && OS.IsWindowVisible (hwnd)) {
- boolean noAnimate = true;
- count = (int)/*64*/OS.SendMessage (hwnd, OS.TVM_GETVISIBLECOUNT, 0, 0);
- rects = new RECT [count + 1];
- int /*long*/ hItem = hTopItem;
- int index = 0;
- while (hItem != 0 && (noAnimate || hItem != handle) && index < count) {
- RECT rect = new RECT ();
- if (OS.TreeView_GetItemRect (hwnd, hItem, rect, true)) {
- rects [index++] = rect;
- }
- hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, hItem);
- }
- if (noAnimate || hItem != handle) {
- redraw = true;
- count = index;
- hBottomItem = hItem;
- oldRect = new RECT ();
- OS.GetClientRect (hwnd, oldRect);
- int /*long*/ topHandle = parent.topHandle ();
- OS.UpdateWindow (topHandle);
- OS.DefWindowProc (topHandle, OS.WM_SETREDRAW, 0, 0);
- if (hwnd != topHandle) {
- OS.UpdateWindow (hwnd);
- OS.DefWindowProc (hwnd, OS.WM_SETREDRAW, 0, 0);
- }
- /*
- * This code is intentionally commented.
- */
-// OS.SendMessage (hwnd, OS.WM_SETREDRAW, 0, 0);
- }
- }
- }
-
- /*
- * Feature in Windows. When the user collapses the root
- * of a subtree that has the focus item, Windows moves
- * the selection to the root of the subtree and issues
- * a TVN_SELCHANGED to inform the programmer that the
- * selection has changed. When the programmer collapses
- * the same subtree using TVM_EXPAND, Windows does not
- * send the selection changed notification. This is not
- * strictly wrong but is inconsistent. The fix is to
- * check whether the selection has changed and issue
- * the event.
- */
- int /*long*/ hOldItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
-
- /* Expand or collapse the item */
- parent.ignoreExpand = true;
- OS.SendMessage (hwnd, OS.TVM_EXPAND, expanded ? OS.TVE_EXPAND : OS.TVE_COLLAPSE, handle);
- parent.ignoreExpand = false;
-
- /* Scroll back to the top item */
- if (noScroll && hTopItem != 0) {
- boolean collapsed = false;
- if (!expanded) {
- RECT rect = new RECT ();
- while (hTopItem != 0 && !OS.TreeView_GetItemRect (hwnd, hTopItem, rect, false)) {
- hTopItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_PARENT, hTopItem);
- collapsed = true;
- }
- }
- boolean scrolled = true;
- if (hTopItem != 0) {
- OS.SendMessage (hwnd, OS.TVM_SELECTITEM, OS.TVGN_FIRSTVISIBLE, hTopItem);
- scrolled = hTopItem != OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0);
- }
- if (!collapsed && !scrolled && oldInfo != null) {
- SCROLLINFO newInfo = new SCROLLINFO ();
- newInfo.cbSize = SCROLLINFO.sizeof;
- newInfo.fMask = OS.SIF_ALL;
- if (OS.GetScrollInfo (hwnd, OS.SB_HORZ, newInfo)) {
- if (oldInfo.nPos != newInfo.nPos) {
- int /*long*/ lParam = OS.MAKELPARAM (OS.SB_THUMBPOSITION, oldInfo.nPos);
- OS.SendMessage (hwnd, OS.WM_HSCROLL, lParam, 0);
- }
- }
- }
- if (redraw) {
- boolean fixScroll = false;
- if (!collapsed && !scrolled) {
- RECT newRect = new RECT ();
- OS.GetClientRect (hwnd, newRect);
- if (OS.EqualRect (oldRect, newRect)) {
- int /*long*/ hItem = hTopItem;
- int index = 0;
- while (hItem != 0 && index < count) {
- RECT rect = new RECT ();
- if (OS.TreeView_GetItemRect (hwnd, hItem, rect, true)) {
- if (!OS.EqualRect (rect, rects [index])) {
- break;
- }
- }
- hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, hItem);
- index++;
- }
- fixScroll = index == count && hItem == hBottomItem;
- }
- }
- int /*long*/ topHandle = parent.topHandle ();
- OS.DefWindowProc (topHandle, OS.WM_SETREDRAW, 1, 0);
- if (hwnd != topHandle) {
- OS.DefWindowProc (hwnd, OS.WM_SETREDRAW, 1, 0);
- }
- /*
- * This code is intentionally commented.
- */
-// OS.SendMessage (hwnd, OS.WM_SETREDRAW, 1, 0);
- if (fixScroll) {
- parent.updateScrollBar ();
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_ALL;
- if (OS.GetScrollInfo (hwnd, OS.SB_VERT, info)) {
- OS.SetScrollInfo (hwnd, OS.SB_VERT, info, true);
- }
- if (handle == hBottomItem) {
- RECT rect = new RECT ();
- if (OS.TreeView_GetItemRect (hwnd, hBottomItem, rect, false)) {
- OS.InvalidateRect (hwnd, rect, true);
- }
- }
- } else {
- if (OS.IsWinCE) {
- OS.InvalidateRect (topHandle, null, true);
- if (hwnd != topHandle) OS.InvalidateRect (hwnd, null, true);
- } else {
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (topHandle, null, 0, flags);
- }
- }
- }
- }
-
- /* Check for a selection event */
- int /*long*/ hNewItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hNewItem != hOldItem) {
- Event event = new Event ();
- if (hNewItem != 0) {
- event.item = parent._getItem (hNewItem);
- parent.hAnchor = hNewItem;
- }
- parent.sendEvent (SWT.Selection, event);
- }
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for this item to the font specified by the argument, or to the default font
- * for that kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (Font font){
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- Font oldFont = this.font;
- if (oldFont == font) return;
- this.font = font;
- if (oldFont != null && oldFont.equals (font)) return;
- if (font != null) parent.customDraw = true;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- /*
- * Bug in Windows. When the font is changed for an item,
- * the bounds for the item are not updated, causing the text
- * to be clipped. The fix is to reset the text, causing
- * Windows to compute the new bounds using the new font.
- */
- if ((parent.style & SWT.VIRTUAL) == 0 && !cached && !parent.painted) {
- return;
- }
- int /*long*/ hwnd = parent.handle;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_TEXT;
- tvItem.hItem = handle;
- tvItem.pszText = OS.LPSTR_TEXTCALLBACK;
- OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem);
-}
-
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for the specified cell in this item to the font specified by the
- * argument, or to the default font for that kind of control if the
- * argument is null.
- *
- * @param index the column index
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setFont (int index, Font font) {
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- if (cellFont == null) {
- if (font == null) return;
- cellFont = new Font [count];
- }
- Font oldFont = cellFont [index];
- if (oldFont == font) return;
- cellFont [index] = font;
- if (oldFont != null && oldFont.equals (font)) return;
- if (font != null) parent.customDraw = true;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- /*
- * Bug in Windows. When the font is changed for an item,
- * the bounds for the item are not updated, causing the text
- * to be clipped. The fix is to reset the text, causing
- * Windows to compute the new bounds using the new font.
- */
- if (index == 0) {
- if ((parent.style & SWT.VIRTUAL) == 0 && !cached && !parent.painted) {
- return;
- }
- int /*long*/ hwnd = parent.handle;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_TEXT;
- tvItem.hItem = handle;
- tvItem.pszText = OS.LPSTR_TEXTCALLBACK;
- OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem);
- } else {
- redraw (index, true, false);
- }
-}
-
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public void setForeground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int pixel = -1;
- if (color != null) {
- parent.customDraw = true;
- pixel = color.handle;
- }
- if (foreground == pixel) return;
- foreground = pixel;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- redraw ();
-}
-
-/**
- * Sets the foreground color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- *
- */
-public void setForeground (int index, Color color){
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- int pixel = -1;
- if (color != null) {
- parent.customDraw = true;
- pixel = color.handle;
- }
- if (cellForeground == null) {
- cellForeground = new int [count];
- for (int i = 0; i < count; i++) {
- cellForeground [i] = -1;
- }
- }
- if (cellForeground [index] == pixel) return;
- cellForeground [index] = pixel;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- redraw (index, true, false);
-}
-
-/**
- * Sets the grayed state of the checkbox for this item. This state change
- * only applies if the Tree was created with the SWT.CHECK style.
- *
- * @param grayed the new grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setGrayed (boolean grayed) {
- checkWidget ();
- if ((parent.style & SWT.CHECK) == 0) return;
- int /*long*/ hwnd = parent.handle;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_STATEIMAGEMASK;
- tvItem.hItem = handle;
- OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem);
- int state = tvItem.state >> 12;
- if (grayed) {
- if (state <= 2) state +=2;
- } else {
- if (state > 2) state -=2;
- }
- state <<= 12;
- if (tvItem.state == state) return;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- tvItem.state = state;
- OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem);
- /*
- * Bug in Windows. When TVM_SETITEM is used to set
- * the state image of an item inside TVN_GETDISPINFO,
- * the new state is not redrawn. The fix is to force
- * a redraw.
- */
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (parent.currentItem == this && OS.IsWindowVisible (hwnd)) {
- RECT rect = new RECT ();
- if (OS.TreeView_GetItemRect (hwnd, handle, rect, false)) {
- OS.InvalidateRect (hwnd, rect, true);
- }
- }
- }
-}
-
-/**
- * Sets the image for multiple columns in the tree.
- *
- * @param images the array of new images
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setImage (Image [] images) {
- checkWidget();
- if (images == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<images.length; i++) {
- setImage (i, images [i]);
- }
-}
-
-/**
- * Sets the receiver's image at a column.
- *
- * @param index the column index
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setImage (int index, Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- Image oldImage = null;
- if (index == 0) {
- if (image != null && image.type == SWT.ICON) {
- if (image.equals (this.image)) return;
- }
- oldImage = this.image;
- super.setImage (image);
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- if (images == null && index != 0) {
- images = new Image [count];
- images [0] = image;
- }
- if (images != null) {
- if (image != null && image.type == SWT.ICON) {
- if (image.equals (images [index])) return;
- }
- oldImage = images [index];
- images [index] = image;
- }
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-
- /* Ensure that the image list is created */
- //TODO - items that are not in column zero don't need to be in the image list
- parent.imageIndex (image, index);
-
- if (index == 0) {
- if ((parent.style & SWT.VIRTUAL) == 0 &&!cached && !parent.painted) {
- return;
- }
- int /*long*/ hwnd = parent.handle;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_IMAGE | OS.TVIF_SELECTEDIMAGE;
- tvItem.hItem = handle;
- tvItem.iImage = tvItem.iSelectedImage = OS.I_IMAGECALLBACK;
- /*
- * Bug in Windows. When I_IMAGECALLBACK is used with TVM_SETITEM
- * to indicate that an image has changed, Windows does not draw
- * the new image. The fix is to use LPSTR_TEXTCALLBACK to force
- * Windows to ask for the text, causing Windows to ask for both.
- */
- tvItem.mask |= OS.TVIF_TEXT;
- tvItem.pszText = OS.LPSTR_TEXTCALLBACK;
- OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem);
- } else {
- boolean drawText = (image == null && oldImage != null) || (image != null && oldImage == null);
- redraw (index, drawText, true);
- }
-}
-
-public void setImage (Image image) {
- checkWidget ();
- setImage (0, image);
-}
-
-/**
- * Sets the number of child items contained in the receiver.
- *
- * @param count the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setItemCount (int count) {
- checkWidget ();
- count = Math.max (0, count);
- int /*long*/ hwnd = parent.handle;
- int /*long*/ hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle);
- parent.setItemCount (count, handle, hItem);
-}
-
-/**
- * Sets the text for multiple columns in the tree.
- *
- * @param strings the array of new strings
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setText (String [] strings) {
- checkWidget();
- if (strings == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<strings.length; i++) {
- String string = strings [i];
- if (string != null) setText (i, string);
- }
-}
-
-/**
- * Sets the receiver's text at a column
- *
- * @param index the column index
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setText (int index, String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (index == 0) {
- if (string.equals (text)) return;
- super.setText (string);
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- if (strings == null && index != 0) {
- strings = new String [count];
- strings [0] = text;
- }
- if (strings != null) {
- if (string.equals (strings [index])) return;
- strings [index] = string;
- }
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- if (index == 0) {
- if ((parent.style & SWT.VIRTUAL) == 0 && !cached && !parent.painted) {
- return;
- }
- int /*long*/ hwnd = parent.handle;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_TEXT;
- tvItem.hItem = handle;
- tvItem.pszText = OS.LPSTR_TEXTCALLBACK;
- OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem);
- } else {
- redraw (index, true, false);
- }
-}
-
-public void setText (String string) {
- checkWidget();
- setText (0, string);
-}
-
-/*public*/ void sort () {
- checkWidget ();
- if ((parent.style & SWT.VIRTUAL) != 0) return;
- parent.sort (handle, false);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java
deleted file mode 100755
index a5b8368f1f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java
+++ /dev/null
@@ -1,2517 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * This class is the abstract superclass of all user interface objects.
- * Widgets are created, disposed and issue notification to listeners
- * when events occur which affect them.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Dispose</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation. However, it has not been marked
- * final to allow those outside of the SWT development team to implement
- * patched versions of the class in order to get around specific
- * limitations in advance of when those limitations can be addressed
- * by the team. Any class built using subclassing to access the internals
- * of this class will likely fail to compile or run between releases and
- * may be strongly platform specific. Subclassing should not be attempted
- * without an intimate and detailed understanding of the workings of the
- * hierarchy. No support is provided for user-written classes which are
- * implemented as subclasses of this class.
- * </p>
- *
- * @see #checkSubclass
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public abstract class Widget {
- int style, state;
- Display display;
- EventTable eventTable;
- Object data;
-
- /* Global state flags */
- static final int DISPOSED = 1<<0;
- static final int CANVAS = 1<<1;
- static final int KEYED_DATA = 1<<2;
- static final int DISABLED = 1<<3;
- static final int HIDDEN = 1<<4;
-
- /* A layout was requested on this widget */
- static final int LAYOUT_NEEDED = 1<<5;
-
- /* The preferred size of a child has changed */
- static final int LAYOUT_CHANGED = 1<<6;
-
- /* A layout was requested in this widget hierarchy */
- static final int LAYOUT_CHILD = 1<<7;
-
- /* Background flags */
- static final int THEME_BACKGROUND = 1<<8;
- static final int DRAW_BACKGROUND = 1<<9;
- static final int PARENT_BACKGROUND = 1<<10;
-
- /* Dispose and release flags */
- static final int RELEASED = 1<<11;
- static final int DISPOSE_SENT = 1<<12;
-
- /* More global widget state flags */
- static final int TRACK_MOUSE = 1<<13;
- static final int FOREIGN_HANDLE = 1<<14;
- static final int DRAG_DETECT = 1<<15;
-
- /* Move and resize state flags */
- static final int MOVE_OCCURRED = 1<<16;
- static final int MOVE_DEFERRED = 1<<17;
- static final int RESIZE_OCCURRED = 1<<18;
- static final int RESIZE_DEFERRED = 1<<19;
-
- /* Ignore WM_CHANGEUISTATE */
- static final int IGNORE_WM_CHANGEUISTATE = 1<<20;
-
- /* Default size for widgets */
- static final int DEFAULT_WIDTH = 64;
- static final int DEFAULT_HEIGHT = 64;
-
- /* Check and initialize the Common Controls DLL */
- static final int MAJOR = 5, MINOR = 80;
- static {
- if (!OS.IsWinCE) {
- if (OS.COMCTL32_VERSION < OS.VERSION (MAJOR, MINOR)) {
- System.out.println ("***WARNING: SWT requires comctl32.dll version " + MAJOR + "." + MINOR + " or greater"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- System.out.println ("***WARNING: Detected: " + OS.COMCTL32_MAJOR + "." + OS.COMCTL32_MINOR); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- OS.InitCommonControls ();
- }
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Widget () {
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see #checkSubclass
- * @see #getStyle
- */
-public Widget (Widget parent, int style) {
- checkSubclass ();
- checkParent (parent);
- this.style = style;
- display = parent.display;
-}
-
-void _addListener (int eventType, Listener listener) {
- if (eventTable == null) eventTable = new EventTable ();
- eventTable.hook (eventType, listener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs. When the
- * event does occur in the widget, the listener is notified by
- * sending it the <code>handleEvent()</code> message. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #getListeners(int)
- * @see #removeListener(int, Listener)
- * @see #notifyListeners
- */
-public void addListener (int eventType, Listener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- _addListener (eventType, listener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the widget is disposed. When the widget is
- * disposed, the listener is notified by sending it the
- * <code>widgetDisposed()</code> message.
- *
- * @param listener the listener which should be notified when the receiver is disposed
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DisposeListener
- * @see #removeDisposeListener
- */
-public void addDisposeListener (DisposeListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Dispose, typedListener);
-}
-
-int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- return 0;
-}
-
-/**
- * Returns a style with exactly one style bit set out of
- * the specified set of exclusive style bits. All other
- * possible bits are cleared when the first matching bit
- * is found. Bits that are not part of the possible set
- * are untouched.
- *
- * @param style the original style bits
- * @param int0 the 0th possible style bit
- * @param int1 the 1st possible style bit
- * @param int2 the 2nd possible style bit
- * @param int3 the 3rd possible style bit
- * @param int4 the 4th possible style bit
- * @param int5 the 5th possible style bit
- *
- * @return the new style bits
- */
-static int checkBits (int style, int int0, int int1, int int2, int int3, int int4, int int5) {
- int mask = int0 | int1 | int2 | int3 | int4 | int5;
- if ((style & mask) == 0) style |= int0;
- if ((style & int0) != 0) style = (style & ~mask) | int0;
- if ((style & int1) != 0) style = (style & ~mask) | int1;
- if ((style & int2) != 0) style = (style & ~mask) | int2;
- if ((style & int3) != 0) style = (style & ~mask) | int3;
- if ((style & int4) != 0) style = (style & ~mask) | int4;
- if ((style & int5) != 0) style = (style & ~mask) | int5;
- return style;
-}
-
-void checkOrientation (Widget parent) {
- style &= ~SWT.MIRRORED;
- if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) {
- if (parent != null) {
- if ((parent.style & SWT.LEFT_TO_RIGHT) != 0) style |= SWT.LEFT_TO_RIGHT;
- if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) style |= SWT.RIGHT_TO_LEFT;
- }
- }
- style = checkBits (style, SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT, 0, 0, 0, 0);
-}
-
-void checkOpened () {
- /* Do nothing */
-}
-
-/**
- * Throws an exception if the specified widget can not be
- * used as a parent for the receiver.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- */
-void checkParent (Widget parent) {
- if (parent == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (parent.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- parent.checkWidget ();
- parent.checkOpened ();
-}
-
-/**
- * Checks that this class can be subclassed.
- * <p>
- * The SWT class library is intended to be subclassed
- * only at specific, controlled points (most notably,
- * <code>Composite</code> and <code>Canvas</code> when
- * implementing new widgets). This method enforces this
- * rule unless it is overridden.
- * </p><p>
- * <em>IMPORTANT:</em> By providing an implementation of this
- * method that allows a subclass of a class which does not
- * normally allow subclassing to be created, the implementer
- * agrees to be fully responsible for the fact that any such
- * subclass will likely fail between SWT releases and will be
- * strongly platform specific. No support is provided for
- * user-written classes which are implemented in this fashion.
- * </p><p>
- * The ability to subclass outside of the allowed SWT classes
- * is intended purely to enable those not on the SWT development
- * team to implement patches in order to get around specific
- * limitations in advance of when those limitations can be
- * addressed by the team. Subclassing should not be attempted
- * without an intimate and detailed understanding of the hierarchy.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Throws an <code>SWTException</code> if the receiver can not
- * be accessed by the caller. This may include both checks on
- * the state of the receiver and more generally on the entire
- * execution context. This method <em>should</em> be called by
- * widget implementors to enforce the standard SWT invariants.
- * <p>
- * Currently, it is an error to invoke any method (other than
- * <code>isDisposed()</code>) on a widget that has had its
- * <code>dispose()</code> method called. It is also an error
- * to call widget methods from any thread that is different
- * from the thread that created the widget.
- * </p><p>
- * In future releases of SWT, there may be more or fewer error
- * checks and exceptions may be thrown for different reasons.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-protected void checkWidget () {
- Display display = this.display;
- if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
- if (display.thread != Thread.currentThread ()) {
- /*
- * Bug in IBM JVM 1.6. For some reason, under
- * conditions that are yet to be full understood,
- * Thread.currentThread() is either returning null
- * or a different instance from the one that was
- * saved when the Display was created. This is
- * possibly a JIT problem because modifying this
- * method to print logging information when the
- * error happens seems to fix the problem. The
- * fix is to use operating system calls to verify
- * that the current thread is not the Display thread.
- *
- * NOTE: Despite the fact that Thread.currentThread()
- * is used in other places, the failure has not been
- * observed in all places where it is called.
- */
- if (display.threadId != OS.GetCurrentThreadId ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- }
- if ((state & DISPOSED) != 0) error (SWT.ERROR_WIDGET_DISPOSED);
-}
-
-/**
- * Destroys the widget in the operating system and releases
- * the widget's handle. If the widget does not have a handle,
- * this method may hide the widget, mark the widget as destroyed
- * or do nothing, depending on the widget.
- * <p>
- * When a widget is destroyed in the operating system, its
- * descendants are also destroyed by the operating system.
- * This means that it is only necessary to call <code>destroyWidget</code>
- * on the root of the widget tree.
- * </p><p>
- * This method is called after <code>releaseWidget()</code>.
- * </p><p>
- * See also <code>releaseChild()</code>, <code>releaseWidget()</code>
- * and <code>releaseHandle()</code>.
- * </p>
- *
- * @see #dispose
- */
-void destroyWidget () {
- releaseHandle ();
-}
-
-int /*long*/ DeferWindowPos(int /*long*/ hWinPosInfo, int /*long*/ hWnd, int /*long*/ hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags){
- if (OS.IsWinCE) {
- /*
- * Feature in Windows. On Windows CE, DeferWindowPos always causes
- * a WM_SIZE message, even when the new size is the same as the old
- * size. The fix is to detect that the size has not changed and set
- * SWP_NOSIZE.
- */
- if ((uFlags & OS.SWP_NOSIZE) == 0) {
- RECT lpRect = new RECT ();
- OS.GetWindowRect (hWnd, lpRect);
- if (cy == lpRect.bottom - lpRect.top && cx == lpRect.right - lpRect.left) {
- /*
- * Feature in Windows. On Windows CE, DeferWindowPos when called
- * with SWP_DRAWFRAME always causes a WM_SIZE message, even
- * when SWP_NOSIZE is set and when the new size is the same as the
- * old size. The fix is to clear SWP_DRAWFRAME when the size is
- * the same.
- */
- uFlags &= ~OS.SWP_DRAWFRAME;
- uFlags |= OS.SWP_NOSIZE;
- }
- }
- }
- return OS.DeferWindowPos (hWinPosInfo, hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the receiver and all its descendants. After this method has
- * been invoked, the receiver and all descendants will answer
- * <code>true</code> when sent the message <code>isDisposed()</code>.
- * Any internal connections between the widgets in the tree will
- * have been removed to facilitate garbage collection.
- * <p>
- * NOTE: This method is not called recursively on the descendants
- * of the receiver. This means that, widget implementers can not
- * detect when a widget is being disposed of by re-implementing
- * this method, but should instead listen for the <code>Dispose</code>
- * event.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #addDisposeListener
- * @see #removeDisposeListener
- * @see #checkWidget
- */
-public void dispose () {
- /*
- * Note: It is valid to attempt to dispose a widget
- * more than once. If this happens, fail silently.
- */
- if (isDisposed ()) return;
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- release (true);
-}
-
-boolean dragDetect (int /*long*/ hwnd, int x, int y, boolean filter, boolean [] detect, boolean [] consume) {
- if (consume != null) consume [0] = false;
- if (detect != null) detect [0] = true;
- POINT pt = new POINT ();
- pt.x = x;
- pt.y = y;
- OS.ClientToScreen (hwnd, pt);
- return OS.DragDetect (hwnd, pt);
-}
-
-/**
- * Does whatever widget specific cleanup is required, and then
- * uses the code in <code>SWTError.error</code> to handle the error.
- *
- * @param code the descriptive error code
- *
- * @see SWT#error(int)
- */
-void error (int code) {
- SWT.error(code);
-}
-
-boolean filters (int eventType) {
- return display.filters (eventType);
-}
-
-Widget findItem (int /*long*/ id) {
- return null;
-}
-
-char [] fixMnemonic (String string) {
- return fixMnemonic (string, false);
-}
-
-char [] fixMnemonic (String string, boolean spaces) {
- char [] buffer = new char [string.length () + 1];
- string.getChars (0, string.length (), buffer, 0);
- int i = 0, j = 0;
- while (i < buffer.length) {
- if (buffer [i] == '&') {
- if (i + 1 < buffer.length && buffer [i + 1] == '&') {
- if (spaces) buffer [j] = ' ';
- j++;
- i++;
- }
- i++;
- } else {
- buffer [j++] = buffer [i++];
- }
- }
- while (j < buffer.length) buffer [j++] = 0;
- return buffer;
-}
-
-/**
- * Returns the application defined widget data associated
- * with the receiver, or null if it has not been set. The
- * <em>widget data</em> is a single, unnamed field that is
- * stored with every widget.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the widget data needs to be notified
- * when the widget is disposed of, it is the application's
- * responsibility to hook the Dispose event on the widget and
- * do so.
- * </p>
- *
- * @return the widget data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
- * </ul>
- *
- * @see #setData(Object)
- */
-public Object getData () {
- checkWidget();
- return (state & KEYED_DATA) != 0 ? ((Object []) data) [0] : data;
-}
-
-/**
- * Returns the application defined property of the receiver
- * with the specified name, or null if it has not been set.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the widget is disposed
- * of, it is the application's responsibility to hook the
- * Dispose event on the widget and do so.
- * </p>
- *
- * @param key the name of the property
- * @return the value of the property or null if it has not been set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setData(String, Object)
- */
-public Object getData (String key) {
- checkWidget();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((state & KEYED_DATA) != 0) {
- Object [] table = (Object []) data;
- for (int i=1; i<table.length; i+=2) {
- if (key.equals (table [i])) return table [i+1];
- }
- }
- return null;
-}
-
-/**
- * Returns the <code>Display</code> that is associated with
- * the receiver.
- * <p>
- * A widget's display is either provided when it is created
- * (for example, top level <code>Shell</code>s) or is the
- * same as its parent's display.
- * </p>
- *
- * @return the receiver's display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Display getDisplay () {
- Display display = this.display;
- if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return display;
-}
-
-/**
- * Returns an array of listeners who will be notified when an event
- * of the given type occurs. The event type is one of the event constants
- * defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @return an array of listeners that will be notified when the event occurs
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener(int, Listener)
- * @see #removeListener(int, Listener)
- * @see #notifyListeners
- *
- * @since 3.4
- */
-public Listener[] getListeners (int eventType) {
- checkWidget();
- if (eventTable == null) return new Listener[0];
- return eventTable.getListeners(eventType);
-}
-
-Menu getMenu () {
- return null;
-}
-
-/**
- * Returns the name of the widget. This is the name of
- * the class without the package name.
- *
- * @return the name of the widget
- */
-String getName () {
- String string = getClass ().getName ();
- int index = string.lastIndexOf ('.');
- if (index == -1) return string;
- return string.substring (index + 1, string.length ());
-}
-
-/*
- * Returns a short printable representation for the contents
- * of a widget. For example, a button may answer the label
- * text. This is used by <code>toString</code> to provide a
- * more meaningful description of the widget.
- *
- * @return the contents string for the widget
- *
- * @see #toString
- */
-String getNameText () {
- return ""; //$NON-NLS-1$
-}
-
-/**
- * Returns the receiver's style information.
- * <p>
- * Note that the value which is returned by this method <em>may
- * not match</em> the value which was provided to the constructor
- * when the receiver was created. This can occur when the underlying
- * operating system does not support a particular combination of
- * requested styles. For example, if the platform widget used to
- * implement a particular SWT widget always has scroll bars, the
- * result of calling this method would always have the
- * <code>SWT.H_SCROLL</code> and <code>SWT.V_SCROLL</code> bits set.
- * </p>
- *
- * @return the style bits
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getStyle () {
- checkWidget();
- return style;
-}
-
-/*
- * Returns <code>true</code> if the specified eventType is
- * hooked, and <code>false</code> otherwise. Implementations
- * of SWT can avoid creating objects and sending events
- * when an event happens in the operating system but
- * there are no listeners hooked for the event.
- *
- * @param eventType the event to be checked
- *
- * @return <code>true</code> when the eventType is hooked and <code>false</code> otherwise
- *
- * @see #isListening
- */
-boolean hooks (int eventType) {
- if (eventTable == null) return false;
- return eventTable.hooks (eventType);
-}
-
-/**
- * Returns <code>true</code> if the widget has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the widget.
- * When a widget has been disposed, it is an error to
- * invoke any other method using the widget.
- * </p>
- *
- * @return <code>true</code> when the widget is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- return (state & DISPOSED) != 0;
-}
-
-/**
- * Returns <code>true</code> if there are any listeners
- * for the specified event type associated with the receiver,
- * and <code>false</code> otherwise. The event type is one of
- * the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event
- * @return true if the event is hooked
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public boolean isListening (int eventType) {
- checkWidget();
- return hooks (eventType);
-}
-
-/*
- * Returns <code>true</code> when subclassing is
- * allowed and <code>false</code> otherwise
- *
- * @return <code>true</code> when subclassing is allowed and <code>false</code> otherwise
- */
-boolean isValidSubclass () {
- return Display.isValidClass (getClass ());
-}
-
-/*
- * Returns <code>true</code> when the current thread is
- * the thread that created the widget and <code>false</code>
- * otherwise.
- *
- * @return <code>true</code> when the current thread is the thread that created the widget and <code>false</code> otherwise
- */
-boolean isValidThread () {
- return getDisplay ().isValidThread ();
-}
-
-void mapEvent (int /*long*/ hwnd, Event event) {
-}
-
-GC new_GC (GCData data) {
- return null;
-}
-
-/**
- * Notifies all of the receiver's listeners for events
- * of the given type that one such event has occurred by
- * invoking their <code>handleEvent()</code> method. The
- * event type is one of the event constants defined in class
- * <code>SWT</code>.
- *
- * @param eventType the type of event which has occurred
- * @param event the event data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- * @see #addListener
- * @see #getListeners(int)
- * @see #removeListener(int, Listener)
- */
-public void notifyListeners (int eventType, Event event) {
- checkWidget();
- if (event == null) event = new Event ();
- sendEvent (eventType, event);
-}
-
-void postEvent (int eventType) {
- sendEvent (eventType, null, false);
-}
-
-void postEvent (int eventType, Event event) {
- sendEvent (eventType, event, false);
-}
-
-/*
- * Releases the widget hierarchy and optionally destroys
- * the receiver.
- * <p>
- * Typically, a widget with children will broadcast this
- * message to all children so that they too can release their
- * resources. The <code>releaseHandle</code> method is used
- * as part of this broadcast to zero the handle fields of the
- * children without calling <code>destroyWidget</code>. In
- * this scenario, the children are actually destroyed later,
- * when the operating system destroys the widget tree.
- * </p>
- *
- * @param destroy indicates that the receiver should be destroyed
- *
- * @see #dispose
- * @see #releaseHandle
- * @see #releaseParent
- * @see #releaseWidget
-*/
-void release (boolean destroy) {
- if ((state & DISPOSE_SENT) == 0) {
- state |= DISPOSE_SENT;
- sendEvent (SWT.Dispose);
- }
- if ((state & DISPOSED) == 0) {
- releaseChildren (destroy);
- }
- if ((state & RELEASED) == 0) {
- state |= RELEASED;
- if (destroy) {
- releaseParent ();
- releaseWidget ();
- destroyWidget ();
- } else {
- releaseWidget ();
- releaseHandle ();
- }
- }
-}
-
-void releaseChildren (boolean destroy) {
-}
-
-/*
- * Releases the widget's handle by zero'ing it out.
- * Does not destroy or release any operating system
- * resources.
- * <p>
- * This method is called after <code>releaseWidget</code>
- * or from <code>destroyWidget</code> when a widget is being
- * destroyed to ensure that the widget is marked as destroyed
- * in case the act of destroying the widget in the operating
- * system causes application code to run in callback that
- * could access the widget.
- * </p>
- *
- * @see #dispose
- * @see #releaseChildren
- * @see #releaseParent
- * @see #releaseWidget
- */
-void releaseHandle () {
- state |= DISPOSED;
- display = null;
-}
-
-/*
- * Releases the receiver, a child in a widget hierarchy,
- * from its parent.
- * <p>
- * When a widget is destroyed, it may be necessary to remove
- * it from an internal data structure of the parent. When
- * a widget has no handle, it may also be necessary for the
- * parent to hide the widget or otherwise indicate that the
- * widget has been disposed. For example, disposing a menu
- * bar requires that the menu bar first be released from the
- * shell when the menu bar is active.
- * </p>
- *
- * @see #dispose
- * @see #releaseChildren
- * @see #releaseWidget
- * @see #releaseHandle
- */
-void releaseParent () {
-}
-
-/*
- * Releases any internal resources back to the operating
- * system and clears all fields except the widget handle.
- * <p>
- * When a widget is destroyed, resources that were acquired
- * on behalf of the programmer need to be returned to the
- * operating system. For example, if the widget made a
- * copy of an icon, supplied by the programmer, this copy
- * would be freed in <code>releaseWidget</code>. Also,
- * to assist the garbage collector and minimize the amount
- * of memory that is not reclaimed when the programmer keeps
- * a reference to a disposed widget, all fields except the
- * handle are zero'd. The handle is needed by <code>destroyWidget</code>.
- * </p>
- *
- * @see #dispose
- * @see #releaseChildren
- * @see #releaseHandle
- * @see #releaseParent
- */
-void releaseWidget () {
- eventTable = null;
- data = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener
- * @see #getListeners(int)
- * @see #notifyListeners
- */
-public void removeListener (int eventType, Listener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It should never be
- * referenced from application code.
- * </p>
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see #addListener
- */
-protected void removeListener (int eventType, SWTEventListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the widget is disposed.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DisposeListener
- * @see #addDisposeListener
- */
-public void removeDisposeListener (DisposeListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Dispose, listener);
-}
-
-boolean sendDragEvent (int button, int x, int y) {
- Event event = new Event ();
- event.button = button;
- event.x = x;
- event.y = y;
- setInputState (event, SWT.DragDetect);
- postEvent (SWT.DragDetect, event);
- if (isDisposed ()) return false;
- return event.doit;
-}
-
-boolean sendDragEvent (int button, int stateMask, int x, int y) {
- Event event = new Event ();
- event.button = button;
- event.x = x;
- event.y = y;
- event.stateMask = stateMask;
- postEvent (SWT.DragDetect, event);
- if (isDisposed ()) return false;
- return event.doit;
-}
-
-void sendEvent (Event event) {
- Display display = event.display;
- if (!display.filterEvent (event)) {
- if (eventTable != null) eventTable.sendEvent (event);
- }
-}
-
-void sendEvent (int eventType) {
- sendEvent (eventType, null, true);
-}
-
-void sendEvent (int eventType, Event event) {
- sendEvent (eventType, event, true);
-}
-
-void sendEvent (int eventType, Event event, boolean send) {
- if (eventTable == null && !display.filters (eventType)) {
- return;
- }
- if (event == null) event = new Event ();
- event.type = eventType;
- event.display = display;
- event.widget = this;
- if (event.time == 0) {
- event.time = display.getLastEventTime ();
- }
- if (send) {
- sendEvent (event);
- } else {
- display.postEvent (event);
- }
-}
-
-boolean sendKeyEvent (int type, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- Event event = new Event ();
- if (!setKeyState (event, type, wParam, lParam)) return true;
- return sendKeyEvent (type, msg, wParam, lParam, event);
-}
-
-boolean sendKeyEvent (int type, int msg, int /*long*/ wParam, int /*long*/ lParam, Event event) {
- sendEvent (type, event);
- if (isDisposed ()) return false;
- return event.doit;
-}
-
-boolean sendMouseEvent (int type, int button, int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- return sendMouseEvent (type, button, display.getClickCount (type, button, hwnd, lParam), 0, false, hwnd, msg, wParam, lParam);
-}
-
-boolean sendMouseEvent (int type, int button, int count, int detail, boolean send, int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
- if (!hooks (type) && !filters (type)) return true;
- Event event = new Event ();
- event.button = button;
- event.detail = detail;
- event.count = count;
- event.x = OS.GET_X_LPARAM (lParam);
- event.y = OS.GET_Y_LPARAM (lParam);
- setInputState (event, type);
- mapEvent (hwnd, event);
- if (send) {
- sendEvent (type, event);
- if (isDisposed ()) return false;
- } else {
- postEvent (type, event);
- }
- return event.doit;
-}
-
-/**
- * Sets the application defined widget data associated
- * with the receiver to be the argument. The <em>widget
- * data</em> is a single, unnamed field that is stored
- * with every widget.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the widget data needs to be notified
- * when the widget is disposed of, it is the application's
- * responsibility to hook the Dispose event on the widget and
- * do so.
- * </p>
- *
- * @param data the widget data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
- * </ul>
- *
- * @see #getData()
- */
-public void setData (Object data) {
- checkWidget();
- if ((state & KEYED_DATA) != 0) {
- ((Object []) this.data) [0] = data;
- } else {
- this.data = data;
- }
-}
-
-/**
- * Sets the application defined property of the receiver
- * with the specified name to the given value.
- * <p>
- * Applications may associate arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the widget is disposed
- * of, it is the application's responsibility to hook the
- * Dispose event on the widget and do so.
- * </p>
- *
- * @param key the name of the property
- * @param value the new value for the property
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getData(String)
- */
-public void setData (String key, Object value) {
- checkWidget();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = 1;
- Object [] table = null;
- if ((state & KEYED_DATA) != 0) {
- table = (Object []) data;
- while (index < table.length) {
- if (key.equals (table [index])) break;
- index += 2;
- }
- }
- if (value != null) {
- if ((state & KEYED_DATA) != 0) {
- if (index == table.length) {
- Object [] newTable = new Object [table.length + 2];
- System.arraycopy (table, 0, newTable, 0, table.length);
- data = table = newTable;
- }
- } else {
- table = new Object [3];
- table [0] = data;
- data = table;
- state |= KEYED_DATA;
- }
- table [index] = key;
- table [index + 1] = value;
- } else {
- if ((state & KEYED_DATA) != 0) {
- if (index != table.length) {
- int length = table.length - 2;
- if (length == 1) {
- data = table [0];
- state &= ~KEYED_DATA;
- } else {
- Object [] newTable = new Object [length];
- System.arraycopy (table, 0, newTable, 0, index);
- System.arraycopy (table, index + 2, newTable, index, length - index);
- data = newTable;
- }
- }
- }
- }
-}
-
-boolean sendFocusEvent (int type) {
- sendEvent (type);
- // widget could be disposed at this point
- return true;
-}
-
-boolean setInputState (Event event, int type) {
- if (OS.GetKeyState (OS.VK_MENU) < 0) event.stateMask |= SWT.ALT;
- if (OS.GetKeyState (OS.VK_SHIFT) < 0) event.stateMask |= SWT.SHIFT;
- if (OS.GetKeyState (OS.VK_CONTROL) < 0) event.stateMask |= SWT.CONTROL;
- if (OS.GetKeyState (OS.VK_LBUTTON) < 0) event.stateMask |= SWT.BUTTON1;
- if (OS.GetKeyState (OS.VK_MBUTTON) < 0) event.stateMask |= SWT.BUTTON2;
- if (OS.GetKeyState (OS.VK_RBUTTON) < 0) event.stateMask |= SWT.BUTTON3;
- /*
- * Bug in Windows. On some machines that do not have XBUTTONs,
- * the MK_XBUTTON1 and OS.MK_XBUTTON2 bits are sometimes set,
- * causing mouse capture to become stuck. The fix is to test
- * for the extra buttons only when they exist.
- */
- if (display.xMouse) {
- if (OS.GetKeyState (OS.VK_XBUTTON1) < 0) event.stateMask |= SWT.BUTTON4;
- if (OS.GetKeyState (OS.VK_XBUTTON2) < 0) event.stateMask |= SWT.BUTTON5;
- }
- switch (type) {
- case SWT.MouseDown:
- case SWT.MouseDoubleClick:
- if (event.button == 1) event.stateMask &= ~SWT.BUTTON1;
- if (event.button == 2) event.stateMask &= ~SWT.BUTTON2;
- if (event.button == 3) event.stateMask &= ~SWT.BUTTON3;
- if (event.button == 4) event.stateMask &= ~SWT.BUTTON4;
- if (event.button == 5) event.stateMask &= ~SWT.BUTTON5;
- break;
- case SWT.MouseUp:
- if (event.button == 1) event.stateMask |= SWT.BUTTON1;
- if (event.button == 2) event.stateMask |= SWT.BUTTON2;
- if (event.button == 3) event.stateMask |= SWT.BUTTON3;
- if (event.button == 4) event.stateMask |= SWT.BUTTON4;
- if (event.button == 5) event.stateMask |= SWT.BUTTON5;
- break;
- case SWT.KeyDown:
- case SWT.Traverse:
- if (event.keyCode == SWT.ALT) event.stateMask &= ~SWT.ALT;
- if (event.keyCode == SWT.SHIFT) event.stateMask &= ~SWT.SHIFT;
- if (event.keyCode == SWT.CONTROL) event.stateMask &= ~SWT.CONTROL;
- break;
- case SWT.KeyUp:
- if (event.keyCode == SWT.ALT) event.stateMask |= SWT.ALT;
- if (event.keyCode == SWT.SHIFT) event.stateMask |= SWT.SHIFT;
- if (event.keyCode == SWT.CONTROL) event.stateMask |= SWT.CONTROL;
- break;
- }
- return true;
-}
-
-boolean setKeyState (Event event, int type, int /*long*/ wParam, int /*long*/ lParam) {
-
- /*
- * Feature in Windows. When the user presses Ctrl+Backspace
- * or Ctrl+Enter, Windows sends a WM_CHAR with Delete (0x7F)
- * and '\n' instead of '\b' and '\r'. This is the correct
- * platform behavior but is not portable. The fix is to detect
- * these cases and convert the character.
- */
- switch (display.lastAscii) {
- case SWT.DEL:
- if (display.lastKey == SWT.BS) display.lastAscii = SWT.BS;
- break;
- case SWT.LF:
- if (display.lastKey == SWT.CR) display.lastAscii = SWT.CR;
- break;
- }
-
- /*
- * Feature in Windows. When the user presses either the Enter
- * key or the numeric keypad Enter key, Windows sends a WM_KEYDOWN
- * with wParam=VK_RETURN in both cases. In order to distinguish
- * between the keys, the extended key bit is tested. If the bit
- * is set, assume that the numeric keypad Enter was pressed.
- */
- if (display.lastKey == SWT.CR && display.lastAscii == SWT.CR) {
- if ((lParam & 0x1000000) != 0) display.lastKey = SWT.KEYPAD_CR;
- }
-
- if (display.lastVirtual) {
- /*
- * Feature in Windows. The virtual key VK_DELETE is not
- * treated as both a virtual key and an ASCII key by Windows.
- * Therefore, we will not receive a WM_CHAR for this key.
- * The fix is to treat VK_DELETE as a special case and map
- * the ASCII value explicitly (Delete is 0x7F).
- */
- if (display.lastKey == OS.VK_DELETE) display.lastAscii = 0x7F;
-
- /*
- * Feature in Windows. When the user presses Ctrl+Pause, the
- * VK_CANCEL key is generated and a WM_CHAR is sent with 0x03,
- * possibly to allow an application to look for Ctrl+C and the
- * the Break key at the same time. This is unexpected and
- * unwanted. The fix is to detect the case and set the character
- * to zero.
- */
- if (display.lastKey == OS.VK_CANCEL) display.lastAscii = 0x0;
-
- event.keyCode = Display.translateKey (display.lastKey);
- } else {
- event.keyCode = display.lastKey;
- }
- if (display.lastAscii != 0 || display.lastNull) {
- event.character = Display.mbcsToWcs ((char) display.lastAscii);
- }
- if (event.keyCode == 0 && event.character == 0) {
- if (!display.lastNull) return false;
- }
- return setInputState (event, type);
-}
-
-boolean setTabGroupFocus () {
- return setTabItemFocus ();
-}
-
-boolean setTabItemFocus () {
- return false;
-}
-
-boolean SetWindowPos (int /*long*/ hWnd, int /*long*/ hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags) {
- if (OS.IsWinCE) {
- /*
- * Feature in Windows. On Windows CE, SetWindowPos() always causes
- * a WM_SIZE message, even when the new size is the same as the old
- * size. The fix is to detect that the size has not changed and set
- * SWP_NOSIZE.
- */
- if ((uFlags & OS.SWP_NOSIZE) == 0) {
- RECT lpRect = new RECT ();
- OS.GetWindowRect (hWnd, lpRect);
- if (cy == lpRect.bottom - lpRect.top && cx == lpRect.right - lpRect.left) {
- /*
- * Feature in Windows. On Windows CE, SetWindowPos() when called
- * with SWP_DRAWFRAME always causes a WM_SIZE message, even
- * when SWP_NOSIZE is set and when the new size is the same as the
- * old size. The fix is to clear SWP_DRAWFRAME when the size is
- * the same.
- */
- uFlags &= ~OS.SWP_DRAWFRAME;
- uFlags |= OS.SWP_NOSIZE;
- }
- }
- }
- return OS.SetWindowPos (hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
-}
-
-boolean showMenu (int x, int y) {
- Event event = new Event ();
- event.x = x;
- event.y = y;
- sendEvent (SWT.MenuDetect, event);
- // widget could be disposed at this point
- if (isDisposed ()) return false;
- if (!event.doit) return true;
- Menu menu = getMenu ();
- if (menu != null && !menu.isDisposed ()) {
- if (x != event.x || y != event.y) {
- menu.setLocation (event.x, event.y);
- }
- menu.setVisible (true);
- return true;
- }
- return false;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- String string = "*Disposed*"; //$NON-NLS-1$
- if (!isDisposed ()) {
- string = "*Wrong Thread*"; //$NON-NLS-1$
- if (isValidThread ()) string = getNameText ();
- }
- return getName () + " {" + string + "}"; //$NON-NLS-1$ //$NON-NLS-2$
-}
-
-LRESULT wmCaptureChanged (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- display.captureChanged = true;
- return null;
-}
-
-LRESULT wmChar (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Do not report a lead byte as a key pressed.
- */
- if (!OS.IsUnicode && OS.IsDBLocale) {
- byte lead = (byte) (wParam & 0xFF);
- if (OS.IsDBCSLeadByte (lead)) return null;
- }
- display.lastAscii = (int)/*64*/wParam;
- display.lastNull = wParam == 0;
- if (!sendKeyEvent (SWT.KeyDown, OS.WM_CHAR, wParam, lParam)) {
- return LRESULT.ONE;
- }
- // widget could be disposed at this point
- return null;
-}
-
-LRESULT wmContextMenu (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- if (wParam != hwnd) return null;
-
- /*
- * Feature in Windows. SHRecognizeGesture() sends an undocumented
- * WM_CONTEXTMENU notification when the flag SHRG_NOTIFY_PARENT is
- * not set. This causes the context menu to be displayed twice,
- * once by the caller of SHRecognizeGesture() and once from this
- * method. The fix is to ignore WM_CONTEXTMENU notifications on
- * all WinCE platforms.
- *
- * NOTE: This only happens on WM2003. Previous WinCE versions did
- * not support WM_CONTEXTMENU.
- */
- if (OS.IsWinCE) return null;
-
- /*
- * Feature in Windows. When the user presses WM_NCRBUTTONUP,
- * a WM_CONTEXTMENU message is generated. This happens when
- * the user releases the mouse over a scroll bar. Normally,
- * window displays the default scrolling menu but applications
- * can process WM_CONTEXTMENU to display a different menu.
- * Typically, an application does not want to supply a special
- * scroll menu. The fix is to look for a WM_CONTEXTMENU that
- * originated from a mouse event and display the menu when the
- * mouse was released in the client area.
- */
- int x = 0, y = 0;
- if (lParam != -1) {
- POINT pt = new POINT ();
- OS.POINTSTOPOINT (pt, lParam);
- x = pt.x;
- y = pt.y;
- OS.ScreenToClient (hwnd, pt);
- RECT rect = new RECT ();
- OS.GetClientRect (hwnd, rect);
- if (!OS.PtInRect (rect, pt)) return null;
- } else {
- int pos = OS.GetMessagePos ();
- x = OS.GET_X_LPARAM (pos);
- y = OS.GET_Y_LPARAM (pos);
- }
-
- /* Show the menu */
- return showMenu (x, y) ? LRESULT.ZERO : null;
-}
-
-LRESULT wmIMEChar (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- Display display = this.display;
- display.lastKey = 0;
- display.lastAscii = (int)/*64*/wParam;
- display.lastVirtual = display.lastNull = display.lastDead = false;
- if (!sendKeyEvent (SWT.KeyDown, OS.WM_IME_CHAR, wParam, lParam)) {
- return LRESULT.ONE;
- }
- sendKeyEvent (SWT.KeyUp, OS.WM_IME_CHAR, wParam, lParam);
- // widget could be disposed at this point
- display.lastKey = display.lastAscii = 0;
- return LRESULT.ONE;
-}
-
-LRESULT wmKeyDown (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
-
- /* Ignore repeating modifier keys by testing key down state */
- switch ((int)/*64*/wParam) {
- case OS.VK_SHIFT:
- case OS.VK_MENU:
- case OS.VK_CONTROL:
- case OS.VK_CAPITAL:
- case OS.VK_NUMLOCK:
- case OS.VK_SCROLL:
- if ((lParam & 0x40000000) != 0) return null;
- }
-
- /* Clear last key and last ascii because a new key has been typed */
- display.lastAscii = display.lastKey = 0;
- display.lastVirtual = display.lastNull = display.lastDead = false;
-
- /*
- * Do not report a lead byte as a key pressed.
- */
- if (!OS.IsUnicode && OS.IsDBLocale) {
- byte lead = (byte) (wParam & 0xFF);
- if (OS.IsDBCSLeadByte (lead)) return null;
- }
-
- /* Map the virtual key */
- /*
- * Bug in WinCE. MapVirtualKey() returns incorrect values.
- * The fix is to rely on a key mappings table to determine
- * whether the key event must be sent now or if a WM_CHAR
- * event will follow. The key mappings table maps virtual
- * keys to SWT key codes and does not contain mappings for
- * Windows virtual keys like VK_A. Virtual keys that are
- * both virtual and ASCII are a special case.
- */
- int mapKey = 0;
- if (OS.IsWinCE) {
- switch ((int)/*64*/wParam) {
- case OS.VK_BACK: mapKey = SWT.BS; break;
- case OS.VK_RETURN: mapKey = SWT.CR; break;
- case OS.VK_DELETE: mapKey = SWT.DEL; break;
- case OS.VK_ESCAPE: mapKey = SWT.ESC; break;
- case OS.VK_TAB: mapKey = SWT.TAB; break;
- }
- } else {
- /*
- * Feature in Windows. For numbers in Marathi and Bengali,
- * MapVirtualKey() returns the localized number instead of
- * the ASCII equivalent. For example, MapVirtualKey()
- * maps VK_1 on the Marathi keyboard to \u2407, which is
- * a valid Unicode Marathi '1' character, but not ASCII.
- * The fix is to test for VK_0 to VK_9 and map these
- * explicitly.
- *
- * NOTE: VK_0 to VK_9 are the same as ASCII.
- */
- if ('0' <= wParam && wParam <= '9') {
- mapKey = (int)/*64*/wParam;
- } else {
- mapKey = OS.MapVirtualKey ((int)/*64*/wParam, 2);
- }
- }
-
- /*
- * Bug in Windows 95 and NT. When the user types an accent key such
- * as ^ to get an accented character on a German keyboard, the accent
- * key should be ignored and the next key that the user types is the
- * accented key. The fix is to detect the accent key stroke (called
- * a dead key) by testing the high bit of the value returned by
- * MapVirtualKey(). A further problem is that the high bit on
- * Windows NT is bit 32 while the high bit on Windows 95 is bit 16.
- * They should both be bit 32.
- *
- * When the user types an accent key that does not correspond to a
- * virtual key, MapVirtualKey() won't set the high bit to indicate
- * a dead key. This happens when an accent key, such as '^' is the
- * result of a modifier such as Shift key and MapVirtualKey() always
- * returns the unshifted key. The fix is to peek for a WM_DEADCHAR
- * and avoid issuing the event.
- */
- if (OS.IsWinNT) {
- if ((mapKey & 0x80000000) != 0) return null;
- } else {
- if ((mapKey & 0x8000) != 0) return null;
- }
- MSG msg = new MSG ();
- int flags = OS.PM_NOREMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE;
- if (OS.PeekMessage (msg, hwnd, OS.WM_DEADCHAR, OS.WM_DEADCHAR, flags)) {
- display.lastDead = true;
- display.lastVirtual = mapKey == 0;
- display.lastKey = display.lastVirtual ? (int)/*64*/wParam : mapKey;
- return null;
- }
-
- /*
- * Bug in Windows. Somehow, the widget is becoming disposed after
- * calling PeekMessage(). In rare circumstances, it seems that
- * PeekMessage() can allow SWT listeners to run that might contain
- * application code that disposes the widget. It is not exactly
- * clear how this can happen. PeekMessage() is only looking for
- * WM_DEADCHAR. It is not dispatching any message that it finds
- * or removing any message from the queue. Cross-thread messages
- * are disabled. The fix is to check for a disposed widget and
- * return without calling the window proc.
- */
- if (isDisposed ()) return LRESULT.ONE;
-
- /*
- * If we are going to get a WM_CHAR, ensure that last key has
- * the correct character value for the key down and key up
- * events. It is not sufficient to ignore the WM_KEYDOWN
- * (when we know we are going to get a WM_CHAR) and compute
- * the key in WM_CHAR because there is not enough information
- * by the time we get the WM_CHAR. For example, when the user
- * types Ctrl+Shift+6 on a US keyboard, we get a WM_CHAR with
- * wParam=30. When the user types Ctrl+Shift+6 on a German
- * keyboard, we also get a WM_CHAR with wParam=30. On the US
- * keyboard Shift+6 is ^, on the German keyboard Shift+6 is &.
- * There is no way to map wParam=30 in WM_CHAR to the correct
- * value. Also, on international keyboards, the control key
- * may be down when the user has not entered a control character.
- *
- * NOTE: On Windows 98, keypad keys are virtual despite the
- * fact that a WM_CHAR is issued. On Windows 2000 and XP,
- * they are not virtual. Therefore it is necessary to force
- * numeric keypad keys to be virtual.
- */
- display.lastVirtual = mapKey == 0 || display.numpadKey ((int)/*64*/wParam) != 0;
- if (display.lastVirtual) {
- display.lastKey = (int)/*64*/wParam;
- /*
- * Feature in Windows. The virtual key VK_DELETE is not
- * treated as both a virtual key and an ASCII key by Windows.
- * Therefore, we will not receive a WM_CHAR for this key.
- * The fix is to treat VK_DELETE as a special case and map
- * the ASCII value explicitly (Delete is 0x7F).
- */
- if (display.lastKey == OS.VK_DELETE) display.lastAscii = 0x7F;
-
- /*
- * It is possible to get a WM_CHAR for a virtual key when
- * Num Lock is on. If the user types Home while Num Lock
- * is down, a WM_CHAR is issued with WPARM=55 (for the
- * character 7). If we are going to get a WM_CHAR we need
- * to ensure that the last key has the correct value. Note
- * that Ctrl+Home does not issue a WM_CHAR when Num Lock is
- * down.
- */
- if (OS.VK_NUMPAD0 <= display.lastKey && display.lastKey <= OS.VK_DIVIDE) {
- /*
- * Feature in Windows. Calling to ToAscii() or ToUnicode(), clears
- * the accented state such that the next WM_CHAR loses the accent.
- * This makes is critical that the accent key is detected. Also,
- * these functions clear the character that is entered using the
- * special Windows keypad sequence when NumLock is down (ie. typing
- * ALT+0231 should gives 'c' with a cedilla when NumLock is down).
- */
- if (display.asciiKey (display.lastKey) != 0) return null;
- display.lastAscii = display.numpadKey (display.lastKey);
- }
- } else {
- /*
- * Convert LastKey to lower case because Windows non-virtual
- * keys that are also ASCII keys, such as like VK_A, are have
- * upper case values in WM_KEYDOWN despite the fact that the
- * Shift was not pressed.
- */
- display.lastKey = (int)/*64*/OS.CharLower ((short) mapKey);
-
- /*
- * Feature in Windows. The virtual key VK_CANCEL is treated
- * as both a virtual key and ASCII key by Windows. This
- * means that a WM_CHAR with WPARAM=3 will be issued for
- * this key. In order to distinguish between this key and
- * Ctrl+C, mark the key as virtual.
- */
- if (wParam == OS.VK_CANCEL) display.lastVirtual = true;
-
- /*
- * Some key combinations map to Windows ASCII keys depending
- * on the keyboard. For example, Ctrl+Alt+Q maps to @ on a
- * German keyboard. If the current key combination is special,
- * the correct character is placed in wParam for processing in
- * WM_CHAR. If this is the case, issue the key down event from
- * inside WM_CHAR.
- */
- int asciiKey = display.asciiKey ((int)/*64*/wParam);
- if (asciiKey != 0) {
- /*
- * When the user types Ctrl+Space, ToAscii () maps this to
- * Space. Normally, ToAscii () maps a key to a different
- * key if both a WM_KEYDOWN and a WM_CHAR will be issued.
- * To avoid the extra SWT.KeyDown, look for a space and
- * issue the event from WM_CHAR.
- */
- if (asciiKey == ' ') return null;
- if (asciiKey != (int)/*64*/wParam) return null;
- /*
- * Feature in Windows. The virtual key VK_CANCEL is treated
- * as both a virtual key and ASCII key by Windows. This
- * means that a WM_CHAR with WPARAM=3 will be issued for
- * this key. To avoid the extra SWT.KeyDown, look for
- * VK_CANCEL and issue the event from WM_CHAR.
- */
- if (wParam == OS.VK_CANCEL) return null;
- }
-
- /*
- * If the control key is not down at this point, then
- * the key that was pressed was an accent key or a regular
- * key such as 'A' or Shift+A. In that case, issue the
- * key event from WM_CHAR.
- */
- if (OS.GetKeyState (OS.VK_CONTROL) >= 0) return null;
-
- /*
- * Get the shifted state or convert to lower case if necessary.
- * If the user types Ctrl+A, LastAscii should be 'a', not 'A'.
- * If the user types Ctrl+Shift+A, LastAscii should be 'A'.
- * If the user types Ctrl+Shift+6, the value of LastAscii will
- * depend on the international keyboard.
- */
- if (OS.GetKeyState (OS.VK_SHIFT) < 0) {
- display.lastAscii = display.shiftedKey ((int)/*64*/wParam);
- if (display.lastAscii == 0) display.lastAscii = mapKey;
- } else {
- display.lastAscii = (int)/*64*/OS.CharLower ((short) mapKey);
- }
-
- /* Note that Ctrl+'@' is ASCII NUL and is delivered in WM_CHAR */
- if (display.lastAscii == '@') return null;
- display.lastAscii = display.controlKey (display.lastAscii);
- }
- if (!sendKeyEvent (SWT.KeyDown, OS.WM_KEYDOWN, wParam, lParam)) {
- return LRESULT.ONE;
- }
- // widget could be disposed at this point
- return null;
-}
-
-LRESULT wmKeyUp (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- Display display = this.display;
-
- /* Check for hardware keys */
- if (OS.IsWinCE) {
- if (OS.VK_APP1 <= wParam && wParam <= OS.VK_APP6) {
- display.lastKey = display.lastAscii = 0;
- display.lastVirtual = display.lastNull = display.lastDead = false;
- Event event = new Event ();
- event.detail = (int)/*64*/wParam - OS.VK_APP1 + 1;
- /* Check the bit 30 to get the key state */
- int type = (lParam & 0x40000000) != 0 ? SWT.HardKeyUp : SWT.HardKeyDown;
- if (setInputState (event, type)) sendEvent (type, event);
- // widget could be disposed at this point
- return null;
- }
- }
-
- /*
- * If the key up is not hooked, reset last key
- * and last ascii in case the key down is hooked.
- */
- if (!hooks (SWT.KeyUp) && !display.filters (SWT.KeyUp)) {
- display.lastKey = display.lastAscii = 0;
- display.lastVirtual = display.lastNull = display.lastDead = false;
- return null;
- }
-
- /* Map the virtual key. */
- /*
- * Bug in WinCE. MapVirtualKey() returns incorrect values.
- * The fix is to rely on a key mappings table to determine
- * whether the key event must be sent now or if a WM_CHAR
- * event will follow. The key mappings table maps virtual
- * keys to SWT key codes and does not contain mappings for
- * Windows virtual keys like VK_A. Virtual keys that are
- * both virtual and ASCII are a special case.
- */
- int mapKey = 0;
- if (OS.IsWinCE) {
- switch ((int)/*64*/wParam) {
- case OS.VK_BACK: mapKey = SWT.BS; break;
- case OS.VK_RETURN: mapKey = SWT.CR; break;
- case OS.VK_DELETE: mapKey = SWT.DEL; break;
- case OS.VK_ESCAPE: mapKey = SWT.ESC; break;
- case OS.VK_TAB: mapKey = SWT.TAB; break;
- }
- } else {
- mapKey = OS.MapVirtualKey ((int)/*64*/wParam, 2);
- }
-
- /*
- * Bug in Windows 95 and NT. When the user types an accent key such
- * as ^ to get an accented character on a German keyboard, the accent
- * key should be ignored and the next key that the user types is the
- * accented key. The fix is to detect the accent key stroke (called
- * a dead key) by testing the high bit of the value returned by
- * MapVirtualKey (). A further problem is that the high bit on
- * Windows NT is bit 32 while the high bit on Windows 95 is bit 16.
- * They should both be bit 32.
- */
- if (OS.IsWinNT) {
- if ((mapKey & 0x80000000) != 0) return null;
- } else {
- if ((mapKey & 0x8000) != 0) return null;
- }
- if (display.lastDead) return null;
-
- /*
- * NOTE: On Windows 98, keypad keys are virtual despite the
- * fact that a WM_CHAR is issued. On Windows 2000 and XP,
- * they are not virtual. Therefore it is necessary to force
- * numeric keypad keys to be virtual.
- */
- display.lastVirtual = mapKey == 0 || display.numpadKey ((int)/*64*/wParam) != 0;
- if (display.lastVirtual) {
- display.lastKey = (int)/*64*/wParam;
- } else {
- /*
- * Feature in Windows. The virtual key VK_CANCEL is treated
- * as both a virtual key and ASCII key by Windows. This
- * means that a WM_CHAR with WPARAM=3 will be issued for
- * this key. In order to distinguish between this key and
- * Ctrl+C, mark the key as virtual.
- */
- if (wParam == OS.VK_CANCEL) display.lastVirtual = true;
- if (display.lastKey == 0) {
- display.lastAscii = 0;
- display.lastNull = display.lastDead = false;
- return null;
- }
- }
- LRESULT result = null;
- if (!sendKeyEvent (SWT.KeyUp, OS.WM_KEYUP, wParam, lParam)) {
- result = LRESULT.ONE;
- }
- // widget could be disposed at this point
- display.lastKey = display.lastAscii = 0;
- display.lastVirtual = display.lastNull = display.lastDead = false;
- return result;
-}
-
-LRESULT wmKillFocus (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- display.scrollRemainder = 0;
- int /*long*/ code = callWindowProc (hwnd, OS.WM_KILLFOCUS, wParam, lParam);
- sendFocusEvent (SWT.FocusOut);
- // widget could be disposed at this point
-
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the focus
- * or deactivate events. If this happens, end the
- * processing of the Windows message by returning
- * zero as the result of the window proc.
- */
- if (isDisposed ()) return LRESULT.ZERO;
- if (code == 0) return LRESULT.ZERO;
- return new LRESULT (code);
-}
-
-LRESULT wmLButtonDblClk (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. Windows sends the following
- * messages when the user double clicks the mouse:
- *
- * WM_LBUTTONDOWN - mouse down
- * WM_LBUTTONUP - mouse up
- * WM_LBUTTONDBLCLK - double click
- * WM_LBUTTONUP - mouse up
- *
- * Applications that expect matching mouse down/up
- * pairs will not see the second mouse down. The
- * fix is to send a mouse down event.
- */
- LRESULT result = null;
- Display display = this.display;
- display.captureChanged = false;
- sendMouseEvent (SWT.MouseDown, 1, hwnd, OS.WM_LBUTTONDOWN, wParam, lParam);
- if (sendMouseEvent (SWT.MouseDoubleClick, 1, hwnd, OS.WM_LBUTTONDBLCLK, wParam, lParam)) {
- result = new LRESULT (callWindowProc (hwnd, OS.WM_LBUTTONDBLCLK, wParam, lParam));
- } else {
- result = LRESULT.ZERO;
- }
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != hwnd) OS.SetCapture (hwnd);
- }
- return result;
-}
-
-LRESULT wmLButtonDown (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- Display display = this.display;
- LRESULT result = null;
- int x = OS.GET_X_LPARAM (lParam);
- int y = OS.GET_Y_LPARAM (lParam);
- boolean [] consume = null, detect = null;
- boolean dragging = false, mouseDown = true;
- int count = display.getClickCount (SWT.MouseDown, 1, hwnd, lParam);
- if (count == 1 && (state & DRAG_DETECT) != 0 && hooks (SWT.DragDetect)) {
- if (!OS.IsWinCE) {
- /*
- * Feature in Windows. It's possible that the drag
- * operation will not be started while the mouse is
- * down, meaning that the mouse should be captured.
- * This can happen when the user types the ESC key
- * to cancel the drag. The fix is to query the state
- * of the mouse and capture the mouse accordingly.
- */
- detect = new boolean [1];
- consume = new boolean [1];
- dragging = dragDetect (hwnd, x, y, true, detect, consume);
- if (isDisposed ()) return LRESULT.ZERO;
- mouseDown = OS.GetKeyState (OS.VK_LBUTTON) < 0;
- }
- }
- display.captureChanged = false;
- boolean dispatch = sendMouseEvent (SWT.MouseDown, 1, count, 0, false, hwnd, OS.WM_LBUTTONDOWN, wParam, lParam);
- if (dispatch && (consume == null || !consume [0])) {
- result = new LRESULT (callWindowProc (hwnd, OS.WM_LBUTTONDOWN, wParam, lParam));
- } else {
- result = LRESULT.ZERO;
- }
- if (OS.IsPPC) {
- /*
- * Note: On WinCE PPC, only attempt to recognize the gesture for
- * a context menu when the control contains a valid menu or there
- * are listeners for the MenuDetect event.
- */
- Menu menu = getMenu ();
- boolean hasMenu = menu != null && !menu.isDisposed ();
- if (hasMenu || hooks (SWT.MenuDetect)) {
- SHRGINFO shrg = new SHRGINFO ();
- shrg.cbSize = SHRGINFO.sizeof;
- shrg.hwndClient = hwnd;
- shrg.ptDown_x = x;
- shrg.ptDown_y = y;
- shrg.dwFlags = OS.SHRG_RETURNCMD;
- int type = OS.SHRecognizeGesture (shrg);
- if (type == OS.GN_CONTEXTMENU) showMenu (x, y);
- }
- }
- if (mouseDown) {
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != hwnd) OS.SetCapture (hwnd);
- }
- }
- if (dragging) {
- sendDragEvent (1, x, y);
- } else {
- if (detect != null && detect [0]) {
- /*
- * Feature in Windows. DragDetect() captures the mouse
- * and tracks its movement until the user releases the
- * left mouse button, presses the ESC key, or moves the
- * mouse outside the drag rectangle. If the user moves
- * the mouse outside of the drag rectangle, DragDetect()
- * returns true and a drag and drop operation can be
- * started. When the left mouse button is released or
- * the ESC key is pressed, these events are consumed by
- * DragDetect() so that application code that matches
- * mouse down/up pairs or looks for the ESC key will not
- * function properly. The fix is to send the missing
- * events when the drag has not started.
- *
- * NOTE: For now, don't send a fake WM_KEYDOWN/WM_KEYUP
- * events for the ESC key. This would require computing
- * wParam (the key) and lParam (the repeat count, scan code,
- * extended-key flag, context code, previous key-state flag,
- * and transition-state flag) which is non-trivial.
- */
- if (OS.GetKeyState (OS.VK_ESCAPE) >= 0) {
- OS.SendMessage (hwnd, OS.WM_LBUTTONUP, wParam, lParam);
- }
- }
- }
- return result;
-}
-
-LRESULT wmLButtonUp (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- Display display = this.display;
- LRESULT result = null;
- if (sendMouseEvent (SWT.MouseUp, 1, hwnd, OS.WM_LBUTTONUP, wParam, lParam)) {
- result = new LRESULT (callWindowProc (hwnd, OS.WM_LBUTTONUP, wParam, lParam));
- } else {
- result = LRESULT.ZERO;
- }
- /*
- * Bug in Windows. On some machines that do not have XBUTTONs,
- * the MK_XBUTTON1 and OS.MK_XBUTTON2 bits are sometimes set,
- * causing mouse capture to become stuck. The fix is to test
- * for the extra buttons only when they exist.
- */
- int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON;
- if (display.xMouse) mask |= OS.MK_XBUTTON1 | OS.MK_XBUTTON2;
- if ((wParam & mask) == 0) {
- if (OS.GetCapture () == hwnd) OS.ReleaseCapture ();
- }
- return result;
-}
-
-LRESULT wmMButtonDblClk (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. Windows sends the following
- * messages when the user double clicks the mouse:
- *
- * WM_MBUTTONDOWN - mouse down
- * WM_MBUTTONUP - mouse up
- * WM_MLBUTTONDBLCLK - double click
- * WM_MBUTTONUP - mouse up
- *
- * Applications that expect matching mouse down/up
- * pairs will not see the second mouse down. The
- * fix is to send a mouse down event.
- */
- LRESULT result = null;
- Display display = this.display;
- display.captureChanged = false;
- sendMouseEvent (SWT.MouseDown, 2, hwnd, OS.WM_MBUTTONDOWN, wParam, lParam);
- if (sendMouseEvent (SWT.MouseDoubleClick, 2, hwnd, OS.WM_MBUTTONDBLCLK, wParam, lParam)) {
- result = new LRESULT (callWindowProc (hwnd, OS.WM_MBUTTONDBLCLK, wParam, lParam));
- } else {
- result = LRESULT.ZERO;
- }
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != hwnd) OS.SetCapture (hwnd);
- }
- return result;
-}
-
-LRESULT wmMButtonDown (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = null;
- Display display = this.display;
- display.captureChanged = false;
- if (sendMouseEvent (SWT.MouseDown, 2, hwnd, OS.WM_MBUTTONDOWN, wParam, lParam)) {
- result = new LRESULT (callWindowProc (hwnd, OS.WM_MBUTTONDOWN, wParam, lParam));
- } else {
- result = LRESULT.ZERO;
- }
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != hwnd) OS.SetCapture (hwnd);
- }
- return result;
-}
-
-LRESULT wmMButtonUp (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- Display display = this.display;
- LRESULT result = null;
- if (sendMouseEvent (SWT.MouseUp, 2, hwnd, OS.WM_MBUTTONUP, wParam, lParam)) {
- result = new LRESULT (callWindowProc (hwnd, OS.WM_MBUTTONUP, wParam, lParam));
- } else {
- result = LRESULT.ZERO;
- }
- /*
- * Bug in Windows. On some machines that do not have XBUTTONs,
- * the MK_XBUTTON1 and OS.MK_XBUTTON2 bits are sometimes set,
- * causing mouse capture to become stuck. The fix is to test
- * for the extra buttons only when they exist.
- */
- int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON;
- if (display.xMouse) mask |= OS.MK_XBUTTON1 | OS.MK_XBUTTON2;
- if ((wParam & mask) == 0) {
- if (OS.GetCapture () == hwnd) OS.ReleaseCapture ();
- }
- return result;
-}
-
-LRESULT wmMouseHover (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- if (!sendMouseEvent (SWT.MouseHover, 0, hwnd, OS.WM_MOUSEHOVER, wParam, lParam)) {
- return LRESULT.ZERO;
- }
- return null;
-}
-
-LRESULT wmMouseLeave (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- if (!hooks (SWT.MouseExit) && !filters (SWT.MouseExit)) return null;
- int pos = OS.GetMessagePos ();
- POINT pt = new POINT ();
- OS.POINTSTOPOINT (pt, pos);
- OS.ScreenToClient (hwnd, pt);
- lParam = OS.MAKELPARAM (pt.x, pt.y);
- if (!sendMouseEvent (SWT.MouseExit, 0, hwnd, OS.WM_MOUSELEAVE, wParam, lParam)) {
- return LRESULT.ZERO;
- }
- return null;
-}
-
-LRESULT wmMouseMove (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = null;
- Display display = this.display;
- int pos = OS.GetMessagePos ();
- if (pos != display.lastMouse || display.captureChanged) {
- if (!OS.IsWinCE) {
- boolean trackMouse = (state & TRACK_MOUSE) != 0;
- boolean mouseEnter = hooks (SWT.MouseEnter) || display.filters (SWT.MouseEnter);
- boolean mouseExit = hooks (SWT.MouseExit) || display.filters (SWT.MouseExit);
- boolean mouseHover = hooks (SWT.MouseHover) || display.filters (SWT.MouseHover);
- if (trackMouse || mouseEnter || mouseExit || mouseHover) {
- TRACKMOUSEEVENT lpEventTrack = new TRACKMOUSEEVENT ();
- lpEventTrack.cbSize = TRACKMOUSEEVENT.sizeof;
- lpEventTrack.dwFlags = OS.TME_QUERY;
- lpEventTrack.hwndTrack = hwnd;
- OS.TrackMouseEvent (lpEventTrack);
- if (lpEventTrack.dwFlags == 0) {
- lpEventTrack.dwFlags = OS.TME_LEAVE | OS.TME_HOVER;
- lpEventTrack.hwndTrack = hwnd;
- OS.TrackMouseEvent (lpEventTrack);
- if (mouseEnter) {
- /*
- * Force all outstanding WM_MOUSELEAVE messages to be dispatched before
- * issuing a mouse enter. This causes mouse exit events to be processed
- * before mouse enter events. Note that WM_MOUSELEAVE is posted to the
- * event queue by TrackMouseEvent().
- */
- MSG msg = new MSG ();
- int flags = OS.PM_REMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE;
- while (OS.PeekMessage (msg, 0, OS.WM_MOUSELEAVE, OS.WM_MOUSELEAVE, flags)) {
- OS.TranslateMessage (msg);
- OS.DispatchMessage (msg);
- }
- sendMouseEvent (SWT.MouseEnter, 0, hwnd, OS.WM_MOUSEMOVE, wParam, lParam);
- }
- } else {
- lpEventTrack.dwFlags = OS.TME_HOVER;
- OS.TrackMouseEvent (lpEventTrack);
- }
- }
- }
- if (pos != display.lastMouse) {
- display.lastMouse = pos;
- if (!sendMouseEvent (SWT.MouseMove, 0, hwnd, OS.WM_MOUSEMOVE, wParam, lParam)) {
- result = LRESULT.ZERO;
- }
- }
- }
- display.captureChanged = false;
- return result;
-}
-
-LRESULT wmMouseWheel (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- int delta = OS.GET_WHEEL_DELTA_WPARAM (wParam);
- int [] linesToScroll = new int [1];
- int detail;
- OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, linesToScroll, 0);
- if (linesToScroll [0] == OS.WHEEL_PAGESCROLL) {
- detail = SWT.SCROLL_PAGE;
- } else {
- detail = SWT.SCROLL_LINE;
- delta *= linesToScroll [0];
- }
- /* Check if the delta and the remainder have the same direction (sign) */
- if ((delta ^ display.scrollRemainder) >= 0) delta += display.scrollRemainder;
- display.scrollRemainder = delta % OS.WHEEL_DELTA;
-
- if (!hooks (SWT.MouseWheel) && !filters (SWT.MouseWheel)) return null;
- int count = delta / OS.WHEEL_DELTA;
- POINT pt = new POINT ();
- OS.POINTSTOPOINT (pt, lParam);
- OS.ScreenToClient (hwnd, pt);
- lParam = OS.MAKELPARAM (pt.x, pt.y);
- if (!sendMouseEvent (SWT.MouseWheel, 0, count, detail, true, hwnd, OS.WM_MOUSEWHEEL, wParam, lParam)) {
- return LRESULT.ZERO;
- }
- return null;
-}
-
-LRESULT wmNCPaint (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- return null;
-}
-
-LRESULT wmPaint (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
-
- /* Exit early - don't draw the background */
- if (!hooks (SWT.Paint) && !filters (SWT.Paint)) {
- return null;
- }
-
- /* Issue a paint event */
- int /*long*/ result = 0;
- if (OS.IsWinCE) {
- RECT rect = new RECT ();
- OS.GetUpdateRect (hwnd, rect, false);
- result = callWindowProc (hwnd, OS.WM_PAINT, wParam, lParam);
- /*
- * Bug in Windows. When InvalidateRgn(), InvalidateRect()
- * or RedrawWindow() with RDW_INVALIDATE is called from
- * within WM_PAINT to invalidate a region for a further
- * BeginPaint(), the caret is not properly erased causing
- * pixel corruption. The fix is to hide and show the
- * caret.
- */
- OS.HideCaret (hwnd);
- OS.InvalidateRect (hwnd, rect, false);
- OS.ShowCaret (hwnd);
- PAINTSTRUCT ps = new PAINTSTRUCT ();
- GCData data = new GCData ();
- data.ps = ps;
- data.hwnd = hwnd;
- GC gc = new_GC (data);
- if (gc != null) {
- int width = ps.right - ps.left;
- int height = ps.bottom - ps.top;
- if (width != 0 && height != 0) {
- Event event = new Event ();
- event.gc = gc;
- event.x = ps.left;
- event.y = ps.top;
- event.width = width;
- event.height = height;
- sendEvent (SWT.Paint, event);
- // widget could be disposed at this point
- event.gc = null;
- }
- gc.dispose ();
- }
- } else {
- int /*long*/ rgn = OS.CreateRectRgn (0, 0, 0, 0);
- OS.GetUpdateRgn (hwnd, rgn, false);
- result = callWindowProc (hwnd, OS.WM_PAINT, wParam, lParam);
- GCData data = new GCData ();
- data.hwnd = hwnd;
- GC gc = new_GC (data);
- if (gc != null) {
- OS.HideCaret (hwnd);
- RECT rect = new RECT();
- OS.GetRgnBox (rgn, rect);
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- if (width != 0 && height != 0) {
- int /*long*/ hDC = gc.handle;
- OS.SelectClipRgn (hDC, rgn);
- OS.SetMetaRgn (hDC);
- Event event = new Event ();
- event.gc = gc;
- event.x = rect.left;
- event.y = rect.top;
- event.width = width;
- event.height = height;
- sendEvent (SWT.Paint, event);
- // widget could be disposed at this point
- event.gc = null;
- }
- gc.dispose ();
- OS.ShowCaret (hwnd);
- }
- OS.DeleteObject (rgn);
- }
- if (result == 0) return LRESULT.ZERO;
- return new LRESULT (result);
-}
-
-LRESULT wmPrint (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Bug in Windows. When WM_PRINT is used to print the contents
- * of a control that has WS_EX_CLIENTEDGE, the old 3D border is
- * drawn instead of the theme border. The fix is to call the
- * default window proc and then draw the theme border on top.
- */
- if ((lParam & OS.PRF_NONCLIENT) != 0) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- int bits = OS.GetWindowLong (hwnd, OS.GWL_EXSTYLE);
- if ((bits & OS.WS_EX_CLIENTEDGE) != 0) {
- int /*long*/ code = callWindowProc (hwnd, OS.WM_PRINT, wParam, lParam);
- RECT rect = new RECT ();
- OS.GetWindowRect (hwnd, rect);
- rect.right -= rect.left;
- rect.bottom -= rect.top;
- rect.left = rect.top = 0;
- int border = OS.GetSystemMetrics (OS.SM_CXEDGE);
- OS.ExcludeClipRect (wParam, border, border, rect.right - border, rect.bottom - border);
- OS.DrawThemeBackground (display.hEditTheme (), wParam, OS.EP_EDITTEXT, OS.ETS_NORMAL, rect, null);
- return new LRESULT (code);
- }
- }
- }
- return null;
-}
-
-LRESULT wmRButtonDblClk (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. Windows sends the following
- * messages when the user double clicks the mouse:
- *
- * WM_RBUTTONDOWN - mouse down
- * WM_RBUTTONUP - mouse up
- * WM_RBUTTONDBLCLK - double click
- * WM_LBUTTONUP - mouse up
- *
- * Applications that expect matching mouse down/up
- * pairs will not see the second mouse down. The
- * fix is to send a mouse down event.
- */
- LRESULT result = null;
- Display display = this.display;
- display.captureChanged = false;
- sendMouseEvent (SWT.MouseDown, 3, hwnd, OS.WM_RBUTTONDOWN, wParam, lParam);
- if (sendMouseEvent (SWT.MouseDoubleClick, 3, hwnd, OS.WM_RBUTTONDBLCLK, wParam, lParam)) {
- result = new LRESULT (callWindowProc (hwnd, OS.WM_RBUTTONDBLCLK, wParam, lParam));
- } else {
- result = LRESULT.ZERO;
- }
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != hwnd) OS.SetCapture (hwnd);
- }
- return result;
-}
-
-LRESULT wmRButtonDown (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = null;
- Display display = this.display;
- display.captureChanged = false;
- if (sendMouseEvent (SWT.MouseDown, 3, hwnd, OS.WM_RBUTTONDOWN, wParam, lParam)) {
- result = new LRESULT (callWindowProc (hwnd, OS.WM_RBUTTONDOWN, wParam, lParam));
- } else {
- result = LRESULT.ZERO;
- }
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != hwnd) OS.SetCapture (hwnd);
- }
- return result;
-}
-
-LRESULT wmRButtonUp (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- Display display = this.display;
- LRESULT result = null;
- if (sendMouseEvent (SWT.MouseUp, 3, hwnd, OS.WM_RBUTTONUP, wParam, lParam)) {
- result = new LRESULT (callWindowProc (hwnd, OS.WM_RBUTTONUP, wParam, lParam));
- } else {
- /* Call the DefWindowProc() to support WM_CONTEXTMENU */
- OS.DefWindowProc (hwnd, OS.WM_RBUTTONUP, wParam, lParam);
- result = LRESULT.ZERO;
- }
- /*
- * Bug in Windows. On some machines that do not have XBUTTONs,
- * the MK_XBUTTON1 and OS.MK_XBUTTON2 bits are sometimes set,
- * causing mouse capture to become stuck. The fix is to test
- * for the extra buttons only when they exist.
- */
- int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON;
- if (display.xMouse) mask |= OS.MK_XBUTTON1 | OS.MK_XBUTTON2;
- if ((wParam & mask) == 0) {
- if (OS.GetCapture () == hwnd) OS.ReleaseCapture ();
- }
- return result;
-}
-
-LRESULT wmSetFocus (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- int /*long*/ code = callWindowProc (hwnd, OS.WM_SETFOCUS, wParam, lParam);
- sendFocusEvent (SWT.FocusIn);
- // widget could be disposed at this point
-
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the focus
- * or activate events. If this happens, end the
- * processing of the Windows message by returning
- * zero as the result of the window proc.
- */
- if (isDisposed ()) return LRESULT.ZERO;
- if (code == 0) return LRESULT.ZERO;
- return new LRESULT (code);
-}
-
-LRESULT wmSysChar (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- Display display = this.display;
- display.lastAscii = (int)/*64*/wParam;
- display.lastNull = wParam == 0;
-
- /* Do not issue a key down if a menu bar mnemonic was invoked */
- if (!hooks (SWT.KeyDown) && !display.filters (SWT.KeyDown)) {
- return null;
- }
-
- /* Call the window proc to determine whether it is a system key or mnemonic */
- boolean oldKeyHit = display.mnemonicKeyHit;
- display.mnemonicKeyHit = true;
- int /*long*/ result = callWindowProc (hwnd, OS.WM_SYSCHAR, wParam, lParam);
- boolean consumed = false;
- if (!display.mnemonicKeyHit) {
- consumed = !sendKeyEvent (SWT.KeyDown, OS.WM_SYSCHAR, wParam, lParam);
- // widget could be disposed at this point
- }
- consumed |= display.mnemonicKeyHit;
- display.mnemonicKeyHit = oldKeyHit;
- return consumed ? LRESULT.ONE : new LRESULT (result);
-}
-
-LRESULT wmSysKeyDown (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. When WM_SYSKEYDOWN is sent,
- * the user pressed ALT+<key> or F10 to get to the
- * menu bar. In order to issue events for F10 but
- * ignore other key presses when the ALT is not down,
- * make sure that either F10 was pressed or that ALT
- * is pressed.
- */
- if (wParam != OS.VK_F10) {
- /* Make sure WM_SYSKEYDOWN was sent by ALT-<aKey>. */
- if ((lParam & 0x20000000) == 0) return null;
- }
-
- /* Ignore well known system keys */
- switch ((int)/*64*/wParam) {
- case OS.VK_F4: {
- int /*long*/ hwndShell = hwnd;
- while (OS.GetParent (hwndShell) != 0) {
- if (OS.GetWindow (hwndShell, OS.GW_OWNER) != 0) break;
- hwndShell = OS.GetParent (hwndShell);
- }
- int bits = OS.GetWindowLong (hwndShell, OS.GWL_STYLE);
- if ((bits & OS.WS_SYSMENU) != 0) return null;
- }
- }
-
- /* Ignore repeating modifier keys by testing key down state */
- switch ((int)/*64*/wParam) {
- case OS.VK_SHIFT:
- case OS.VK_MENU:
- case OS.VK_CONTROL:
- case OS.VK_CAPITAL:
- case OS.VK_NUMLOCK:
- case OS.VK_SCROLL:
- if ((lParam & 0x40000000) != 0) return null;
- }
-
- /* Clear last key and last ascii because a new key has been typed */
- display.lastAscii = display.lastKey = 0;
- display.lastVirtual = display.lastNull = display.lastDead = false;
-
- /* If are going to get a WM_SYSCHAR, ignore this message. */
- /*
- * Bug in WinCE. MapVirtualKey() returns incorrect values.
- * The fix is to rely on a key mappings table to determine
- * whether the key event must be sent now or if a WM_CHAR
- * event will follow. The key mappings table maps virtual
- * keys to SWT key codes and does not contain mappings for
- * Windows virtual keys like VK_A. Virtual keys that are
- * both virtual and ASCII are a special case.
- */
- int mapKey = 0;
- if (OS.IsWinCE) {
- switch ((int)/*64*/wParam) {
- case OS.VK_BACK: mapKey = SWT.BS; break;
- case OS.VK_RETURN: mapKey = SWT.CR; break;
- case OS.VK_DELETE: mapKey = SWT.DEL; break;
- case OS.VK_ESCAPE: mapKey = SWT.ESC; break;
- case OS.VK_TAB: mapKey = SWT.TAB; break;
- }
- } else {
- mapKey = OS.MapVirtualKey ((int)/*64*/wParam, 2);
- }
- display.lastVirtual = mapKey == 0 || display.numpadKey ((int)/*64*/wParam) != 0;
- if (display.lastVirtual) {
- display.lastKey = (int)/*64*/wParam;
- /*
- * Feature in Windows. The virtual key VK_DELETE is not
- * treated as both a virtual key and an ASCII key by Windows.
- * Therefore, we will not receive a WM_SYSCHAR for this key.
- * The fix is to treat VK_DELETE as a special case and map
- * the ASCII value explicitly (Delete is 0x7F).
- */
- if (display.lastKey == OS.VK_DELETE) display.lastAscii = 0x7F;
-
- /* When a keypad key is typed, a WM_SYSCHAR is not issued */
- if (OS.VK_NUMPAD0 <= display.lastKey && display.lastKey <= OS.VK_DIVIDE) {
- /*
- * A WM_SYSCHAR will be issued for '*', '+', '-', '.' and '/'
- * on the numeric keypad. Avoid issuing the key event twice
- * by checking for these keys. Note that calling to ToAscii()
- * or ToUnicode(), clear the character that is entered using
- * the special Windows keypad sequence when NumLock is down
- * (ie. typing ALT+0231 should gives 'c' with a cedilla when
- * NumLock is down). Do not call either of these from here.
- */
- switch (display.lastKey) {
- case OS.VK_MULTIPLY:
- case OS.VK_ADD:
- case OS.VK_SUBTRACT:
- case OS.VK_DECIMAL:
- case OS.VK_DIVIDE: return null;
- }
- display.lastAscii = display.numpadKey (display.lastKey);
- }
- } else {
- /*
- * Convert LastKey to lower case because Windows non-virtual
- * keys that are also ASCII keys, such as like VK_A, are have
- * upper case values in WM_SYSKEYDOWN despite the fact that the
- * Shift was not pressed.
- */
- display.lastKey = (int)/*64*/OS.CharLower ((short) mapKey);
-
- /*
- * Feature in Windows 98. MapVirtualKey() indicates that
- * a WM_SYSCHAR message will occur for Alt+Enter but
- * this message never happens. The fix is to issue the
- * event from WM_SYSKEYDOWN and map VK_RETURN to '\r'.
- */
- if (OS.IsWinNT) return null;
- if (wParam != OS.VK_RETURN) return null;
- display.lastAscii = '\r';
- }
-
- if (!sendKeyEvent (SWT.KeyDown, OS.WM_SYSKEYDOWN, wParam, lParam)) {
- return LRESULT.ONE;
- }
- // widget could be disposed at this point
- return null;
-}
-
-LRESULT wmSysKeyUp (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- return wmKeyUp (hwnd, wParam, lParam);
-}
-
-LRESULT wmXButtonDblClk (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- /*
- * Feature in Windows. Windows sends the following
- * messages when the user double clicks the mouse:
- *
- * WM_XBUTTONDOWN - mouse down
- * WM_XBUTTONUP - mouse up
- * WM_XLBUTTONDBLCLK - double click
- * WM_XBUTTONUP - mouse up
- *
- * Applications that expect matching mouse down/up
- * pairs will not see the second mouse down. The
- * fix is to send a mouse down event.
- */
- LRESULT result = null;
- Display display = this.display;
- display.captureChanged = false;
- int button = OS.HIWORD (wParam) == OS.XBUTTON1 ? 4 : 5;
- sendMouseEvent (SWT.MouseDown, button, hwnd, OS.WM_XBUTTONDOWN, wParam, lParam);
- if (sendMouseEvent (SWT.MouseDoubleClick, button, hwnd, OS.WM_XBUTTONDBLCLK, wParam, lParam)) {
- result = new LRESULT (callWindowProc (hwnd, OS.WM_XBUTTONDBLCLK, wParam, lParam));
- } else {
- result = LRESULT.ZERO;
- }
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != hwnd) OS.SetCapture (hwnd);
- }
- return result;
-}
-
-LRESULT wmXButtonDown (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- LRESULT result = null;
- Display display = this.display;
- display.captureChanged = false;
- display.xMouse = true;
- int button = OS.HIWORD (wParam) == OS.XBUTTON1 ? 4 : 5;
- if (sendMouseEvent (SWT.MouseDown, button, hwnd, OS.WM_XBUTTONDOWN, wParam, lParam)) {
- result = new LRESULT (callWindowProc (hwnd, OS.WM_XBUTTONDOWN, wParam, lParam));
- } else {
- result = LRESULT.ZERO;
- }
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != hwnd) OS.SetCapture (hwnd);
- }
- return result;
-}
-
-LRESULT wmXButtonUp (int /*long*/ hwnd, int /*long*/ wParam, int /*long*/ lParam) {
- Display display = this.display;
- LRESULT result = null;
- int button = OS.HIWORD (wParam) == OS.XBUTTON1 ? 4 : 5;
- if (sendMouseEvent (SWT.MouseUp, button, hwnd, OS.WM_XBUTTONUP, wParam, lParam)) {
- result = new LRESULT (callWindowProc (hwnd, OS.WM_XBUTTONUP, wParam, lParam));
- } else {
- result = LRESULT.ZERO;
- }
- /*
- * Bug in Windows. On some machines that do not have XBUTTONs,
- * the MK_XBUTTON1 and OS.MK_XBUTTON2 bits are sometimes set,
- * causing mouse capture to become stuck. The fix is to test
- * for the extra buttons only when they exist.
- */
- int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON;
- if (display.xMouse) mask |= OS.MK_XBUTTON1 | OS.MK_XBUTTON2;
- if ((wParam & mask) == 0) {
- if (OS.GetCapture () == hwnd) OS.ReleaseCapture ();
- }
- return result;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Color.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Color.java
deleted file mode 100644
index 6fc68ac112..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Color.java
+++ /dev/null
@@ -1,275 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage the operating system resources that
- * implement SWT's RGB color model. To create a color you can either
- * specify the individual color components as integers in the range
- * 0 to 255 or provide an instance of an <code>RGB</code>.
- * <p>
- * Application code must explicitly invoke the <code>Color.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see RGB
- * @see Device#getSystemColor
- * @see <a href="http://www.eclipse.org/swt/snippets/#color">Color and RGB snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class Color extends Resource {
-
- /**
- * the handle to the OS color resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Color(Device device) {
- super(device);
-}
-
-/**
- * Constructs a new instance of this class given a device and the
- * desired red, green and blue values expressed as ints in the range
- * 0 to 255 (where 0 is black and 255 is full brightness). On limited
- * color devices, the color instance created by this call may not have
- * the same RGB values as the ones specified by the arguments. The
- * RGB values on the returned instance will be the color values of
- * the operating system color.
- * <p>
- * You must dispose the color when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param red the amount of red in the color
- * @param green the amount of green in the color
- * @param blue the amount of blue in the color
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255</li>
- * </ul>
- *
- * @see #dispose
- */
-public Color (Device device, int red, int green, int blue) {
- super(device);
- init(red, green, blue);
- init();
-}
-
-/**
- * Constructs a new instance of this class given a device and an
- * <code>RGB</code> describing the desired red, green and blue values.
- * On limited color devices, the color instance created by this call
- * may not have the same RGB values as the ones specified by the
- * argument. The RGB values on the returned instance will be the color
- * values of the operating system color.
- * <p>
- * You must dispose the color when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param rgb the RGB values of the desired color
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the rgb argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue components of the argument are not between 0 and 255</li>
- * </ul>
- *
- * @see #dispose
- */
-public Color (Device device, RGB rgb) {
- super(device);
- if (rgb == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(rgb.red, rgb.green, rgb.blue);
- init();
-}
-
-void destroy() {
- OS.GCHandle_Free(handle);
- handle = 0;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Color)) return false;
- Color color = (Color) object;
- return device == color.device && (handle & 0xFFFFFF) == (color.handle & 0xFFFFFF);
-}
-
-/**
- * Returns the amount of blue in the color, from 0 to 255.
- *
- * @return the blue component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getBlue () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return OS.Color_B(handle) & 0xFF;
-}
-
-/**
- * Returns the amount of green in the color, from 0 to 255.
- *
- * @return the green component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getGreen () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return OS.Color_G(handle) & 0xFF;
-}
-
-/**
- * Returns the amount of red in the color, from 0 to 255.
- *
- * @return the red component of the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getRed () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return OS.Color_R(handle) & 0xFF;
-}
-
-/**
- * Returns an <code>RGB</code> representing the receiver.
- *
- * @return the RGB for the color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public RGB getRGB () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return new RGB(OS.Color_R(handle) & 0xFF, OS.Color_G(handle) & 0xFF, OS.Color_B(handle) & 0xFF);
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return handle;
-}
-
-/**
- * Allocates the operating system resources associated
- * with the receiver.
- *
- * @param device the device on which to allocate the color
- * @param red the amount of red in the color
- * @param green the amount of green in the color
- * @param blue the amount of blue in the color
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255</li>
- * </ul>
- *
- * @see #dispose
- */
-void init(int red, int green, int blue) {
- if (red > 255 || red < 0 || green > 255 || green < 0 || blue > 255 || blue < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- handle = OS.Color_FromArgb((byte)0xFF, (byte)red, (byte)green, (byte)blue);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
-}
-
-/**
- * Returns <code>true</code> if the color has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the color.
- * When a color has been disposed, it is an error to
- * invoke any other method using the color.
- *
- * @return <code>true</code> when the color is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Color {*DISPOSED*}"; //$NON-NLS-1$
- return "Color {" + getRed() + ", " + getGreen() + ", " + getBlue() + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-}
-
-/**
- * Invokes platform specific functionality to allocate a new color.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Color</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param handle the handle for the color
- * @return a new color object containing the specified device and handle
- */
-public static Color wpf_new(Device device, int handle) {
- Color color = new Color(device);
- color.handle = handle;
- return color;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Cursor.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Cursor.java
deleted file mode 100644
index e1b617cb7f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Cursor.java
+++ /dev/null
@@ -1,466 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.internal.win32.*;
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage operating system resources that
- * specify the appearance of the on-screen pointer. To create a
- * cursor you specify the device and either a simple cursor style
- * describing one of the standard operating system provided cursors
- * or the image and mask data for the desired appearance.
- * <p>
- * Application code must explicitly invoke the <code>Cursor.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>
- * CURSOR_ARROW, CURSOR_WAIT, CURSOR_CROSS, CURSOR_APPSTARTING, CURSOR_HELP,
- * CURSOR_SIZEALL, CURSOR_SIZENESW, CURSOR_SIZENS, CURSOR_SIZENWSE, CURSOR_SIZEWE,
- * CURSOR_SIZEN, CURSOR_SIZES, CURSOR_SIZEE, CURSOR_SIZEW, CURSOR_SIZENE, CURSOR_SIZESE,
- * CURSOR_SIZESW, CURSOR_SIZENW, CURSOR_UPARROW, CURSOR_IBEAM, CURSOR_NO, CURSOR_HAND
- * </dd>
- * </dl>
- * <p>
- * Note: Only one of the above styles may be specified.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#cursor">Cursor snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class Cursor extends Resource {
-
- /**
- * the handle to the OS cursor resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Cursor(Device device) {
- super(device);
-}
-
-/**
- * Constructs a new cursor given a device and a style
- * constant describing the desired cursor appearance.
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param style the style of cursor to allocate
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - when an unknown style is specified</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- *
- * @see SWT#CURSOR_ARROW
- * @see SWT#CURSOR_WAIT
- * @see SWT#CURSOR_CROSS
- * @see SWT#CURSOR_APPSTARTING
- * @see SWT#CURSOR_HELP
- * @see SWT#CURSOR_SIZEALL
- * @see SWT#CURSOR_SIZENESW
- * @see SWT#CURSOR_SIZENS
- * @see SWT#CURSOR_SIZENWSE
- * @see SWT#CURSOR_SIZEWE
- * @see SWT#CURSOR_SIZEN
- * @see SWT#CURSOR_SIZES
- * @see SWT#CURSOR_SIZEE
- * @see SWT#CURSOR_SIZEW
- * @see SWT#CURSOR_SIZENE
- * @see SWT#CURSOR_SIZESE
- * @see SWT#CURSOR_SIZESW
- * @see SWT#CURSOR_SIZENW
- * @see SWT#CURSOR_UPARROW
- * @see SWT#CURSOR_IBEAM
- * @see SWT#CURSOR_NO
- * @see SWT#CURSOR_HAND
- */
-public Cursor(Device device, int style) {
- super(device);
- switch (style) {
- case SWT.CURSOR_HAND: handle = OS.Cursors_Hand(); break;
- case SWT.CURSOR_ARROW: handle = OS.Cursors_Arrow(); break;
- case SWT.CURSOR_WAIT: handle = OS.Cursors_Wait(); break;
- case SWT.CURSOR_CROSS: handle = OS.Cursors_Cross(); break;
- case SWT.CURSOR_APPSTARTING: handle = OS.Cursors_AppStarting(); break;
- case SWT.CURSOR_HELP: handle = OS.Cursors_Help(); break;
- case SWT.CURSOR_SIZEALL: handle = OS.Cursors_SizeAll(); break;
- case SWT.CURSOR_SIZENESW: handle = OS.Cursors_SizeNESW(); break;
- case SWT.CURSOR_SIZENS: handle = OS.Cursors_SizeNS(); break;
- case SWT.CURSOR_SIZENWSE: handle = OS.Cursors_SizeNWSE(); break;
- case SWT.CURSOR_SIZEWE: handle = OS.Cursors_SizeWE(); break;
- case SWT.CURSOR_SIZEN: handle = OS.Cursors_ScrollN(); break;
- case SWT.CURSOR_SIZES: handle = OS.Cursors_ScrollS(); break;
- case SWT.CURSOR_SIZEE: handle = OS.Cursors_ScrollE(); break;
- case SWT.CURSOR_SIZEW: handle = OS.Cursors_ScrollW(); break;
- case SWT.CURSOR_SIZENE: handle = OS.Cursors_ScrollNE(); break;
- case SWT.CURSOR_SIZESE: handle = OS.Cursors_ScrollSE(); break;
- case SWT.CURSOR_SIZESW: handle = OS.Cursors_ScrollSW(); break;
- case SWT.CURSOR_SIZENW: handle = OS.Cursors_ScrollNW(); break;
- case SWT.CURSOR_UPARROW: handle = OS.Cursors_UpArrow(); break;
- case SWT.CURSOR_IBEAM: handle = OS.Cursors_IBeam(); break;
- case SWT.CURSOR_NO: handle = OS.Cursors_No(); break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new cursor given a device, image and mask
- * data describing the desired cursor appearance, and the x
- * and y coordinates of the <em>hotspot</em> (that is, the point
- * within the area covered by the cursor which is considered
- * to be where the on-screen pointer is "pointing").
- * <p>
- * The mask data is allowed to be null, but in this case the source
- * must be an ImageData representing an icon that specifies both
- * color data and mask data.
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param source the color data for the cursor
- * @param mask the mask data for the cursor (or null)
- * @param hotspotX the x coordinate of the cursor's hotspot
- * @param hotspotY the y coordinate of the cursor's hotspot
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the source is null</li>
- * <li>ERROR_NULL_ARGUMENT - if the mask is null and the source does not have a mask</li>
- * <li>ERROR_INVALID_ARGUMENT - if the source and the mask are not the same
- * size, or if the hotspot is outside the bounds of the image</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- */
-public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (mask == null) {
- if (source.getTransparencyType() != SWT.TRANSPARENCY_MASK) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- mask = source.getTransparencyMask();
- }
- /* Check the bounds. Mask must be the same size as source */
- if (mask.width != source.width || mask.height != source.height) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- /* Check the hotspots */
- if (hotspotX >= source.width || hotspotX < 0 ||
- hotspotY >= source.height || hotspotY < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- /* Convert depth to 1 */
- mask = ImageData.convertMask(mask);
- source = ImageData.convertMask(source);
-
- /* Make sure source and mask scanline pad is 2 */
- byte[] sourceData = ImageData.convertPad(source.data, source.width, source.height, source.depth, source.scanlinePad, 2);
- byte[] maskData = ImageData.convertPad(mask.data, mask.width, mask.height, mask.depth, mask.scanlinePad, 2);
-
- /* Create the cursor */
- int hInst = Win32.GetModuleHandleW(null);
- int cursor = Win32.CreateCursor(hInst, hotspotX, hotspotY, source.width, source.height, sourceData, maskData);
- if (cursor == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int safeHandle = OS.gcnew_SWTSafeHandle(cursor, false);
- if (safeHandle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- handle = OS.CursorInteropHelper_Create(safeHandle);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.GCHandle_Free(safeHandle);
- init();
-}
-
-/**
- * Constructs a new cursor given a device, image data describing
- * the desired cursor appearance, and the x and y coordinates of
- * the <em>hotspot</em> (that is, the point within the area
- * covered by the cursor which is considered to be where the
- * on-screen pointer is "pointing").
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the cursor
- * @param source the image data for the cursor
- * @param hotspotX the x coordinate of the cursor's hotspot
- * @param hotspotY the y coordinate of the cursor's hotspot
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the hotspot is outside the bounds of the
- * image</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
- * </ul>
- *
- * @since 3.0
- */
-public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- /* Check the hotspots */
- if (hotspotX >= source.width || hotspotX < 0 ||
- hotspotY >= source.height || hotspotY < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- PaletteData palette = source.palette;
- if (!(((source.depth == 1 || source.depth == 2 || source.depth == 4 || source.depth == 8) && !palette.isDirect) ||
- ((source.depth == 8) || (source.depth == 16 || source.depth == 24 || source.depth == 32) && palette.isDirect)))
- SWT.error (SWT.ERROR_UNSUPPORTED_DEPTH);
- int width = source.width;
- int height = source.height;
- int redMask = palette.redMask;
- int greenMask = palette.greenMask;
- int blueMask = palette.blueMask;
- ImageData newData = null;
- int pixelFormat = 0;
- boolean transparent = source.maskData != null || source.transparentPixel != -1 || source.alpha != -1 || source.alphaData != null;
- if (transparent) {
- pixelFormat = Win32.PixelFormat_Format32bppArgb;
- if (!(palette.isDirect && source.depth == 32 && redMask == 0xFF00 && greenMask == 0xFF0000 && blueMask == 0xFF000000)) {
- newData = new ImageData(width, height, 32, new PaletteData(0xFF00, 0xFF0000, 0xFF000000));
- }
- } else {
- switch (source.depth) {
- case 1:
- case 2:
- case 4:
- case 8:
- pixelFormat = Win32.PixelFormat_Format24bppRgb;
- newData = new ImageData(source.width, source.height, 24, new PaletteData(0xFF, 0xFF00, 0xFF0000));
- break;
- case 16:
- if (redMask == 0x7C00 && greenMask == 0x3E0 && blueMask == 0x1F) {
- pixelFormat = Win32.PixelFormat_Format16bppRgb555;
- } else if (redMask == 0xF800 && greenMask == 0x7E0 && blueMask == 0x1F) {
- pixelFormat = Win32.PixelFormat_Format16bppRgb565;
- } else {
- pixelFormat = Win32.PixelFormat_Format16bppRgb555;
- newData = new ImageData(source.width, source.height, 16, new PaletteData(0x7C00, 0x3E0, 0x1F));
- }
- break;
- case 24:
- if (redMask == 0xFF && greenMask == 0xFF00 && blueMask == 0xFF0000) {
- pixelFormat = Win32.PixelFormat_Format24bppRgb;
- } else {
- pixelFormat = Win32.PixelFormat_Format24bppRgb;
- newData = new ImageData(source.width, source.height, 24, new PaletteData(0xFF, 0xFF00, 0xFF0000));
- }
- break;
- case 32:
- if (redMask == 0xFF00 && greenMask == 0xFF0000 && blueMask == 0xFF000000) {
- pixelFormat = Win32.PixelFormat_Format32bppRgb;
- } else {
- pixelFormat = Win32.PixelFormat_Format32bppRgb;
- newData = new ImageData(source.width, source.height, 32, new PaletteData(0xFF00, 0xFF0000, 0xFF000000));
- }
- break;
- }
- }
- if (newData != null) {
- PaletteData newPalette = newData.palette;
- if (palette.isDirect) {
- ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, width, height, redMask, greenMask, blueMask,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- newData.data, newData.depth, newData.bytesPerLine, newData.getByteOrder(), 0, 0, width, height, newPalette.redMask, newPalette.greenMask, newPalette.blueMask,
- false, false);
- } else {
- RGB[] rgbs = palette.getRGBs();
- int length = rgbs.length;
- byte[] srcReds = new byte[length];
- byte[] srcGreens = new byte[length];
- byte[] srcBlues = new byte[length];
- for (int i = 0; i < rgbs.length; i++) {
- RGB rgb = rgbs[i];
- if (rgb == null) continue;
- srcReds[i] = (byte)rgb.red;
- srcGreens[i] = (byte)rgb.green;
- srcBlues[i] = (byte)rgb.blue;
- }
- ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, width, height, srcReds, srcGreens, srcBlues,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- newData.data, newData.depth, newData.bytesPerLine, newData.getByteOrder(), 0, 0, width, height, newPalette.redMask, newPalette.greenMask, newPalette.blueMask,
- false, false);
- }
- if (source.transparentPixel != -1) {
- newData.transparentPixel = newPalette.getPixel(palette.getRGB(source.transparentPixel));
- }
- newData.maskPad = source.maskPad;
- newData.maskData = source.maskData;
- newData.alpha = source.alpha;
- newData.alphaData = source.alphaData;
- source = newData;
- palette = source.palette;
- }
- if (transparent) {
- if (source.maskData != null || source.transparentPixel != -1) {
- ImageData maskImage = source.getTransparencyMask();
- byte[] maskData = maskImage.data;
- int maskBpl = maskImage.bytesPerLine;
- int offset = 3, maskOffset = 0;
- for (int y = 0; y<height; y++) {
- for (int x = 0; x<width; x++) {
- source.data[offset] = ((maskData[maskOffset + (x >> 3)]) & (1 << (7 - (x & 0x7)))) != 0 ? (byte)0xff : 0;
- offset += 4;
- }
- maskOffset += maskBpl;
- }
- } else if (source.alpha != -1) {
- byte alpha = (byte)source.alpha;
- for (int i = 3, j = 0; i < source.data.length; i+=4, j++) {
- source.data[i] = alpha;
- }
- } else {
- for (int i = 3, j = 0; i < source.data.length; i+=4, j++) {
- source.data[i] = source.alphaData[j];
- }
- }
- }
- int bitmap = OS.gcnew_Bitmap(source.width, source.height, source.bytesPerLine, pixelFormat, source.data);
- if (bitmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int hIcon = OS.Bitmap_GetHicon(bitmap);
- if (hIcon == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- ICONINFO info = new ICONINFO();
- Win32.GetIconInfo(hIcon, info);
- info.fIcon = false;
- info.xHotspot = hotspotX;
- info.yHotspot = hotspotY;
- Win32.DestroyIcon(hIcon);
- hIcon = Win32.CreateIconIndirect(info);
- if (info.hbmColor != 0) Win32.DeleteObject(info.hbmColor);
- if (info.hbmMask != 0)Win32.DeleteObject(info.hbmMask);
- if (hIcon == 0) SWT.error(SWT.ERROR_NO_HANDLES);
-
- /* Create the cursor */
- int safeHandle = OS.gcnew_SWTSafeHandle(hIcon, true);
- if (safeHandle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- handle = OS.CursorInteropHelper_Create(safeHandle);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.GCHandle_Free(safeHandle);
- OS.GCHandle_Free(bitmap);
- init();
-}
-
-void destroy() {
- OS.GCHandle_Free(handle);
- handle = 0;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Cursor)) return false;
- Cursor cursor = (Cursor) object;
- return device == cursor.device && handle == cursor.handle;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return handle;
-}
-
-/**
- * Returns <code>true</code> if the cursor has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the cursor.
- * When a cursor has been disposed, it is an error to
- * invoke any other method using the cursor.
- *
- * @return <code>true</code> when the cursor is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Cursor {*DISPOSED*}";
- return "Cursor {" + handle + "}";
-}
-
-/**
- * Invokes platform specific functionality to allocate a new cursor.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Cursor</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param handle the handle for the cursor
- * @return a new cursor object containing the specified device and handle
- */
-public static Cursor wpf_new(Device device, int handle) {
- Cursor cursor = new Cursor(device);
- cursor.handle = handle;
- return cursor;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Device.java
deleted file mode 100644
index fd43333e24..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Device.java
+++ /dev/null
@@ -1,650 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-
-/**
- * This class is the abstract superclass of all device objects,
- * such as the Display device and the Printer device. Devices
- * can have a graphics context (GC) created for them, and they
- * can be drawn on by sending messages to the associated GC.
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class Device implements Drawable {
-
- /* Debugging */
- public static boolean DEBUG;
- public static boolean TRACK;
- boolean debug = DEBUG;
- boolean tracking = DEBUG || TRACK;
- Error [] errors;
- Object [] objects;
- Object trackingLock;
-
- Color[] colors;
-
- /* System Font */
- Font systemFont;
-
- boolean disposed;
-
- /*
- * TEMPORARY CODE. When a graphics object is
- * created and the device parameter is null,
- * the current Display is used. This presents
- * a problem because SWT graphics does not
- * reference classes in SWT widgets. The correct
- * fix is to remove this feature. Unfortunately,
- * too many application programs rely on this
- * feature.
- */
- protected static Device CurrentDevice;
- protected static Runnable DeviceFinder;
- static {
- try {
- Class.forName ("org.eclipse.swt.widgets.Display"); //$NON-NLS-1$
- } catch (ClassNotFoundException e) {}
- }
-
-/*
-* TEMPORARY CODE.
-*/
-static synchronized Device getDevice () {
- if (DeviceFinder != null) DeviceFinder.run();
- Device device = CurrentDevice;
- CurrentDevice = null;
- return device;
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * You must dispose the device when it is no longer required.
- * </p>
- *
- * @see #create
- * @see #init
- *
- * @since 3.1
- */
-public Device() {
- this(null);
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * You must dispose the device when it is no longer required.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #create
- * @see #init
- * @see DeviceData
- */
-public Device(DeviceData data) {
- synchronized (Device.class) {
- if (data != null) {
- debug = data.debug;
- tracking = data.tracking;
- }
- if (tracking) {
- errors = new Error [128];
- objects = new Object [128];
- trackingLock = new Object ();
- }
- create (data);
- init ();
- }
-}
-
-/**
- * Throws an <code>SWTException</code> if the receiver can not
- * be accessed by the caller. This may include both checks on
- * the state of the receiver and more generally on the entire
- * execution context. This method <em>should</em> be called by
- * device implementors to enforce the standard SWT invariants.
- * <p>
- * Currently, it is an error to invoke any method (other than
- * <code>isDisposed()</code> and <code>dispose()</code>) on a
- * device that has had its <code>dispose()</code> method called.
- * </p><p>
- * In future releases of SWT, there may be more or fewer error
- * checks and exceptions may be thrown for different reasons.
- * <p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-protected void checkDevice () {
- if (disposed) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
-}
-
-/**
- * Creates the device in the operating system. If the device
- * does not have a handle, this method may do nothing depending
- * on the device.
- * <p>
- * This method is called before <code>init</code>.
- * </p><p>
- * Subclasses are supposed to reimplement this method and not
- * call the <code>super</code> implementation.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #init
- */
-protected void create (DeviceData data) {
-}
-
-/**
- * Destroys the device in the operating system and releases
- * the device's handle. If the device does not have a handle,
- * this method may do nothing depending on the device.
- * <p>
- * This method is called after <code>release</code>.
- * </p><p>
- * Subclasses are supposed to reimplement this method and not
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #dispose
- * @see #release
- */
-protected void destroy () {
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the receiver. After this method has been invoked, the receiver
- * will answer <code>true</code> when sent the message
- * <code>isDisposed()</code>.
- *
- * @see #release
- * @see #destroy
- * @see #checkDevice
- */
-public void dispose () {
- synchronized (Device.class) {
- if (isDisposed()) return;
- checkDevice ();
- release ();
- destroy ();
- disposed = true;
- if (tracking) {
- synchronized (trackingLock) {
- objects = null;
- errors = null;
- trackingLock = null;
- }
- }
- }
-}
-
-void dispose_Object (Object object) {
- synchronized (trackingLock) {
- for (int i=0; i<objects.length; i++) {
- if (objects [i] == object) {
- objects [i] = null;
- errors [i] = null;
- return;
- }
- }
- }
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location.
- *
- * @return the bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkDevice ();
- int width = (int) OS.SystemParameters_PrimaryScreenWidth();
- int height = (int) OS.SystemParameters_PrimaryScreenHeight();
- return new Rectangle (0, 0, width, height);
-}
-
-/**
- * Returns a <code>DeviceData</code> based on the receiver.
- * Modifications made to this <code>DeviceData</code> will not
- * affect the receiver.
- *
- * @return a <code>DeviceData</code> containing the device's data and attributes
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see DeviceData
- */
-public DeviceData getDeviceData () {
- checkDevice();
- DeviceData data = new DeviceData ();
- data.debug = debug;
- data.tracking = tracking;
- if (tracking) {
- synchronized (trackingLock) {
- int count = 0, length = objects.length;
- for (int i=0; i<length; i++) {
- if (objects [i] != null) count++;
- }
- int index = 0;
- data.objects = new Object [count];
- data.errors = new Error [count];
- for (int i=0; i<length; i++) {
- if (objects [i] != null) {
- data.objects [index] = objects [i];
- data.errors [index] = errors [i];
- index++;
- }
- }
- }
- } else {
- data.objects = new Object [0];
- data.errors = new Error [0];
- }
- return data;
-}
-
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data.
- *
- * @return the client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getBounds
- */
-public Rectangle getClientArea () {
- return getBounds ();
-}
-
-/**
- * Returns the bit depth of the screen, which is the number of
- * bits it takes to represent the number of unique colors that
- * the screen is currently capable of displaying. This number
- * will typically be one of 1, 8, 15, 16, 24 or 32.
- *
- * @return the depth of the screen
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getDepth () {
- checkDevice ();
- //TODO - implement getDepth
- return 32;
-}
-
-/**
- * Returns a point whose x coordinate is the horizontal
- * dots per inch of the display, and whose y coordinate
- * is the vertical dots per inch of the display.
- *
- * @return the horizontal and vertical DPI
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point getDPI () {
- checkDevice ();
- //TODO implement getDPI
- return new Point(96, 96);
-}
-
-/**
- * Returns <code>FontData</code> objects which describe
- * the fonts that match the given arguments. If the
- * <code>faceName</code> is null, all fonts will be returned.
- *
- * @param faceName the name of the font to look for, or null
- * @param scalable if true only scalable fonts are returned, otherwise only non-scalable fonts are returned.
- * @return the matching font data
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontData [] getFontList (String faceName, boolean scalable) {
- checkDevice ();
- if (!scalable) return new FontData[0];
- int typefaces;
- if (faceName != null) {
- int length = faceName.length();
- char[] chars = new char[length + 1];
- faceName.getChars(0, length, chars, 0);
- int str = OS.gcnew_String(chars);
- int fontFamily = OS.gcnew_FontFamily(str);
- typefaces = OS.FontFamily_GetTypefaces(fontFamily);
- OS.GCHandle_Free(fontFamily);
- OS.GCHandle_Free(str);
- } else {
- typefaces = OS.Fonts_SystemTypefaces();
- }
- int count = OS.TypefaceCollection_Count(typefaces);
- int index = 0;
- FontData[] result = new FontData[count];
- int enumerator = OS.TypefaceCollection_GetEnumerator(typefaces);
- while (OS.IEnumerator_MoveNext(enumerator)) {
- int typeface = OS.TypefaceCollection_Current(enumerator);
- int fontFamily = OS.Typeface_FontFamily(typeface);
- int style = OS.Typeface_Style(typeface);
- int weight = OS.Typeface_Weight(typeface);
- int stretch = OS.Typeface_Stretch(typeface);
- int str = OS.FontFamily_Source(fontFamily);
- int charArray = OS.String_ToCharArray(str);
- char[] chars = new char[OS.String_Length(str)];
- OS.memcpy(chars, charArray, chars.length * 2);
- int fontStyle = OS.FontStyles_Normal;
- if (OS.Object_Equals(style, OS.FontStyles_Italic)) fontStyle = OS.FontStyles_Italic;
- if (OS.Object_Equals(style, OS.FontStyles_Oblique)) fontStyle = OS.FontStyles_Oblique;
- FontData data = FontData.wpf_new(new String(chars), fontStyle,
- OS.FontWeight_ToOpenTypeWeight(weight), OS.FontStretch_ToOpenTypeStretch(stretch), 0);
- OS.GCHandle_Free(charArray);
- OS.GCHandle_Free(str);
- OS.GCHandle_Free(fontFamily);
- OS.GCHandle_Free(style);
- OS.GCHandle_Free(weight);
- OS.GCHandle_Free(stretch);
- OS.GCHandle_Free(typeface);
- result[index++] = data;
- }
- OS.GCHandle_Free(enumerator);
- OS.GCHandle_Free(typefaces);
- return result;
-}
-
-/**
- * Returns the matching standard color for the given
- * constant, which should be one of the color constants
- * specified in class <code>SWT</code>. Any value other
- * than one of the SWT color constants which is passed
- * in will result in the color black. This color should
- * not be freed because it was allocated by the system,
- * not the application.
- *
- * @param id the color constant
- * @return the matching color
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT
- */
-public Color getSystemColor (int id) {
- checkDevice ();
- if (0 <= id && id < colors.length) {
- return colors[id];
- }
- return colors[0];
-}
-
-/**
- * Returns a reasonable font for applications to use.
- * On some platforms, this will match the "default font"
- * or "system font" if such can be found. This font
- * should not be freed because it was allocated by the
- * system, not the application.
- * <p>
- * Typically, applications which want the default look
- * should simply not set the font on the widgets they
- * create. Widgets are always created with the correct
- * default font for the class of user-interface component
- * they represent.
- * </p>
- *
- * @return a font
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getSystemFont () {
- checkDevice ();
- return systemFont;
-}
-
-/**
- * Returns <code>true</code> if the underlying window system prints out
- * warning messages on the console, and <code>setWarnings</code>
- * had previously been called with <code>true</code>.
- *
- * @return <code>true</code>if warnings are being handled, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean getWarnings () {
- checkDevice ();
- return false;
-}
-
-/**
- * Initializes any internal resources needed by the
- * device.
- * <p>
- * This method is called after <code>create</code>.
- * </p><p>
- * If subclasses reimplement this method, they must
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #create
- */
-protected void init () {
- /* Create the standard colors */
- colors = new Color[SWT.COLOR_DARK_GRAY + 1];
- colors[SWT.COLOR_BLACK] = colors[0] = Color.wpf_new(this, OS.Colors_Black());
- colors[SWT.COLOR_DARK_RED] = Color.wpf_new(this, OS.Colors_Maroon ());
- colors[SWT.COLOR_DARK_GREEN] = Color.wpf_new(this, OS.Colors_Green ());
- colors[SWT.COLOR_DARK_YELLOW] = Color.wpf_new(this, OS.Colors_Olive());
- colors[SWT.COLOR_DARK_BLUE] = Color.wpf_new(this, OS.Colors_Navy ());
- colors[SWT.COLOR_DARK_MAGENTA] = Color.wpf_new(this, OS.Colors_Purple());
- colors[SWT.COLOR_DARK_CYAN] = Color.wpf_new(this, OS.Colors_Teal ());
- colors[SWT.COLOR_GRAY] = Color.wpf_new(this, OS.Colors_Silver ());
- colors[SWT.COLOR_DARK_GRAY] = Color.wpf_new(this, OS.Colors_Silver ());
- colors[SWT.COLOR_RED] = Color.wpf_new(this, OS.Colors_Red ());
- colors[SWT.COLOR_GREEN] = Color.wpf_new(this, OS.Colors_Lime ());
- colors[SWT.COLOR_YELLOW] = Color.wpf_new(this, OS.Colors_Yellow ());
- colors[SWT.COLOR_BLUE] = Color.wpf_new(this, OS.Colors_Blue ());
- colors[SWT.COLOR_MAGENTA] = Color.wpf_new(this, OS.Colors_Magenta ());
- colors[SWT.COLOR_CYAN] = Color.wpf_new(this, OS.Colors_Cyan ());
- colors[SWT.COLOR_WHITE] = Color.wpf_new(this, OS.Colors_White ());
-
- /* Initialize the system font slot */
- int fontFamily = OS.SystemFonts_MessageFontFamily();
- int style = OS.SystemFonts_MessageFontStyle();
- int weight = OS.SystemFonts_MessageFontWeight();
- double size = OS.SystemFonts_MessageFontSize();
- int typeface = OS.gcnew_Typeface(fontFamily, style, weight, OS.FontStretches_Normal);
- OS.GCHandle_Free(fontFamily);
- OS.GCHandle_Free(style);
- OS.GCHandle_Free(weight);
- systemFont = Font.wpf_new(this, typeface, size);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Device</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public abstract int internal_new_GC (GCData data);
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Device</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public abstract void internal_dispose_GC (int hDC, GCData data);
-
-/**
- * Returns <code>true</code> if the device has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the device.
- * When a device has been disposed, it is an error to
- * invoke any other method using the device.
- *
- * @return <code>true</code> when the device is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- synchronized (Device.class) {
- return disposed;
- }
-}
-
-/**
- * Loads the font specified by a file. The font will be
- * present in the list of fonts available to the application.
- *
- * @param path the font file path
- * @return whether the font was successfully loaded
- *
- * @exception SWTException <ul>
- * <li>ERROR_NULL_ARGUMENT - if path is null</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Font
- *
- * @since 3.3
- */
-public boolean loadFont (String path) {
- checkDevice();
- if (path == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- int length = path.length ();
- char[] buffer = new char [length + 1];
- path.getChars (0, length, buffer, 0);
- int str = OS.gcnew_String(buffer);
- int uri = OS.gcnew_Uri(str, OS.UriKind_RelativeOrAbsolute);
- int list = OS.Fonts_GetTypefaces(uri);
- int count = OS.TypefaceCollection_Count(list);
- OS.GCHandle_Free(list);
- OS.GCHandle_Free(uri);
- OS.GCHandle_Free(str);
- return count != 0;
-}
-
-void new_Object (Object object) {
- synchronized (trackingLock) {
- for (int i=0; i<objects.length; i++) {
- if (objects [i] == null) {
- objects [i] = object;
- errors [i] = new Error ();
- return;
- }
- }
- Object [] newObjects = new Object [objects.length + 128];
- System.arraycopy (objects, 0, newObjects, 0, objects.length);
- newObjects [objects.length] = object;
- objects = newObjects;
- Error [] newErrors = new Error [errors.length + 128];
- System.arraycopy (errors, 0, newErrors, 0, errors.length);
- newErrors [errors.length] = new Error ();
- errors = newErrors;
- }
-}
-
-/**
- * Releases any internal resources back to the operating
- * system and clears all fields except the device handle.
- * <p>
- * When a device is destroyed, resources that were acquired
- * on behalf of the programmer need to be returned to the
- * operating system. For example, if the device allocated a
- * font to be used as the system font, this font would be
- * freed in <code>release</code>. Also,to assist the garbage
- * collector and minimize the amount of memory that is not
- * reclaimed when the programmer keeps a reference to a
- * disposed device, all fields except the handle are zero'd.
- * The handle is needed by <code>destroy</code>.
- * </p>
- * This method is called before <code>destroy</code>.
- * </p><p>
- * If subclasses reimplement this method, they must
- * call the <code>super</code> implementation.
- * </p>
- *
- * @see #dispose
- * @see #destroy
- */
-protected void release () {
- for (int i = 0; i < colors.length; i++) {
- if (colors[i] != null) colors[i].dispose();
- }
- colors = null;
- if (systemFont != null) systemFont.dispose();
- systemFont = null;
- if (tracking) {
- synchronized (trackingLock) {
- if (TRACK & objects != null) {
- for (int i = 0; i < objects.length; i++) {
- if (objects[i] != null) {
- System.err.println(objects[i]);
- errors[i].printStackTrace();
- }
- }
- }
- }
- }
-}
-
-/**
- * If the underlying window system supports printing warning messages
- * to the console, setting warnings to <code>false</code> prevents these
- * messages from being printed. If the argument is <code>true</code> then
- * message printing is not blocked.
- *
- * @param warnings <code>true</code>if warnings should be printed, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setWarnings (boolean warnings) {
- checkDevice ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/DeviceData.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/DeviceData.java
deleted file mode 100644
index ad0c2b2afe..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/DeviceData.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-public class DeviceData {
- /*
- * Debug fields - may not be honoured
- * on some SWT platforms.
- */
- public boolean debug;
- public boolean tracking;
- public Error [] errors;
- public Object [] objects;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Font.java
deleted file mode 100644
index 7ade47e081..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Font.java
+++ /dev/null
@@ -1,291 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class manage operating system resources that
- * define how text looks when it is displayed. Fonts may be constructed
- * by providing a device and either name, size and style information
- * or a <code>FontData</code> object which encapsulates this data.
- * <p>
- * Application code must explicitly invoke the <code>Font.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see FontData
- * @see <a href="http://www.eclipse.org/swt/snippets/#font">Font snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class Font extends Resource {
-
- /**
- * the handle to the OS font resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
- /**
- * the handle to the OS font resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public double size;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Font(Device device) {
- super(device);
-}
-
-/**
- * Constructs a new font given a device and font data
- * which describes the desired font's appearance.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param fd the FontData that describes the desired font (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the fd argument is null</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li>
- * </ul>
- */
-public Font(Device device, FontData fd) {
- super(device);
- init(fd);
- init();
-}
-
-/**
- * Constructs a new font given a device and an array
- * of font data which describes the desired font's
- * appearance.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param fds the array of FontData that describes the desired font (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the fds argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the length of fds is zero</li>
- * <li>ERROR_NULL_ARGUMENT - if any fd in the array is null</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li>
- * </ul>
- *
- * @since 2.1
- */
-public Font(Device device, FontData[] fds) {
- super(device);
- if (fds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (fds.length == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<fds.length; i++) {
- if (fds[i] == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- init(fds[0]);
- init();
-}
-
-/**
- * Constructs a new font given a device, a font name,
- * the height of the desired font in points, and a font
- * style.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param name the name of the font (must not be null)
- * @param height the font height in points
- * @param style a bit or combination of NORMAL, BOLD, ITALIC
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the name argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given arguments</li>
- * </ul>
- */
-public Font(Device device, String name, int height, int style) {
- super(device);
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(new FontData (name, height, style));
- init();
-}
-
-void destroy() {
- OS.GCHandle_Free(handle);
- handle = 0;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals(Object object) {
- if (object == this) return true;
- if (!(object instanceof Font)) return false;
- Font font = (Font) object;
- return device == font.device && handle == font.handle && size == font.size;
-}
-
-/**
- * Returns an array of <code>FontData</code>s representing the receiver.
- * On Windows, only one FontData will be returned per font. On X however,
- * a <code>Font</code> object <em>may</em> be composed of multiple X
- * fonts. To support this case, we return an array of font data objects.
- *
- * @return an array of font data objects describing the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontData[] getFontData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int fontFamily = OS.Typeface_FontFamily(handle);
- int style = OS.Typeface_Style(handle);
- int weight = OS.Typeface_Weight(handle);
- int stretch = OS.Typeface_Stretch(handle);
- int str = OS.FontFamily_Source(fontFamily);
- int charArray = OS.String_ToCharArray(str);
- char[] chars = new char[OS.String_Length(str)];
- OS.memcpy(chars, charArray, chars.length * 2);
- int fontStyle = OS.FontStyles_Normal;
- if (OS.Object_Equals(style, OS.FontStyles_Italic)) fontStyle = OS.FontStyles_Italic;
- if (OS.Object_Equals(style, OS.FontStyles_Oblique)) fontStyle = OS.FontStyles_Oblique;
- int size = (int) (this.size * 72 / 96f);
- FontData data = FontData.wpf_new(new String(chars), fontStyle, OS.FontWeight_ToOpenTypeWeight(weight), OS.FontStretch_ToOpenTypeStretch(stretch), (int)size);
- OS.GCHandle_Free(charArray);
- OS.GCHandle_Free(str);
- OS.GCHandle_Free(fontFamily);
- OS.GCHandle_Free(style);
- OS.GCHandle_Free(weight);
- OS.GCHandle_Free(stretch);
- return new FontData[] {data};
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return handle;
-}
-
-void init (FontData fd) {
- if (fd == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int length = fd.fontFamily.length();
- char[] chars = new char[length + 1];
- fd.fontFamily.getChars(0, length, chars, 0);
- int str = OS.gcnew_String(chars);
- int fontFamily = OS.gcnew_FontFamily(str);
- int style = fd.style;
- int weight = OS.FontWeight_FromOpenTypeWeight(fd.weight);
- int stretch = OS.FontStretch_FromOpenTypeStretch(fd.stretch);
- handle = OS.gcnew_Typeface(fontFamily, style, weight, stretch);
- OS.GCHandle_Free(fontFamily);
- OS.GCHandle_Free(str);
- OS.GCHandle_Free(weight);
- OS.GCHandle_Free(stretch);
- size = fd.height * 96 / 72f;
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
-}
-
-/**
- * Returns <code>true</code> if the font has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the font.
- * When a font has been disposed, it is an error to
- * invoke any other method using the font.
- *
- * @return <code>true</code> when the font is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Font {*DISPOSED*}";
- return "Font {" + handle + "}";
-}
-
-/**
- * Invokes platform specific functionality to allocate a new font.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Font</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param handle the handle for the font
- * @return a new font object containing the specified device and handle
- */
-public static Font wpf_new(Device device, int handle, double size) {
- Font font = new Font(device);
- font.handle = handle;
- font.size = size;
- return font;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/FontData.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/FontData.java
deleted file mode 100644
index 42211bc96c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/FontData.java
+++ /dev/null
@@ -1,540 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class describe operating system fonts.
- * <p>
- * For platform-independent behaviour, use the get and set methods
- * corresponding to the following properties:
- * <dl>
- * <dt>height</dt><dd>the height of the font in points</dd>
- * <dt>name</dt><dd>the face name of the font, which may include the foundry</dd>
- * <dt>style</dt><dd>A bitwise combination of NORMAL, ITALIC and BOLD</dd>
- * </dl>
- * If extra, platform-dependent functionality is required:
- * <ul>
- * <li>On <em>Windows</em>, the data member of the <code>FontData</code>
- * corresponds to a Windows <code>LOGFONT</code> structure whose fields
- * may be retrieved and modified.</li>
- * <li>On <em>X</em>, the fields of the <code>FontData</code> correspond
- * to the entries in the font's XLFD name and may be retrieved and modified.
- * </ul>
- * Application code does <em>not</em> need to explicitly release the
- * resources managed by each instance when those instances are no longer
- * required, and thus no <code>dispose()</code> method is provided.
- *
- * @see Font
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class FontData {
-
- /**
- * A WPF font
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public String fontFamily;
-
- /**
- * A WPF font style
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int style;
-
- /**
- * A WPF font weight
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int weight;
-
- /**
- * A WPF font stretch
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int stretch;
-
- /**
- * The height of the font data in points
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int height;
-
- /**
- * The locales of the font
- */
- String lang, country, variant;
-
-/**
- * Constructs a new uninitialized font data.
- */
-public FontData() {
- fontFamily = "";
- style = OS.FontStyles_Normal;
- weight = OS.FontWeight_ToOpenTypeWeight(OS.FontWeights_Normal);
- stretch = OS.FontStretch_ToOpenTypeStretch(OS.FontStretches_Normal);
- height = 12;
-}
-
-/**
- * Constructs a new FontData given a string representation
- * in the form generated by the <code>FontData.toString</code>
- * method.
- * <p>
- * Note that the representation varies between platforms,
- * and a FontData can only be created from a string that was
- * generated on the same platform.
- * </p>
- *
- * @param string the string representation of a <code>FontData</code> (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument does not represent a valid description</li>
- * </ul>
- *
- * @see #toString
- */
-public FontData(String string) {
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int start = 0;
- int end = string.indexOf('|');
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- String version1 = string.substring(start, end);
- try {
- if (Integer.parseInt(version1) != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- String name = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int height = 0;
- try {
- height = Integer.parseInt(string.substring(start, end));
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int style = 0;
- try {
- style = Integer.parseInt(string.substring(start, end));
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- setName(name);
- setHeight(height);
- setStyle(style);
- if (end == -1) return;
- String platform = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- String version2 = string.substring(start, end);
-
- stretch = OS.FontStretch_ToOpenTypeStretch(OS.FontStretches_Normal);
- if (platform.equals("WPF") && version2.equals("1")) {
- try {
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- fontFamily = string.substring(start, end);
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- String styleStr = string.substring(start, end);
- int length = styleStr.length();
- char[] chars = new char[length + 1];
- styleStr.getChars(0, length, chars, 0);
- int str = OS.gcnew_String(chars);
- int converter = OS.TypeDescriptor_GetConverter(OS.FontStyles_Normal);
- this.style = OS.FontStyles_Normal;
- int fontStyle = OS.TypeConverter_ConvertFromString(converter, str);
- if (fontStyle != 0) {
- if (OS.Object_Equals(OS.FontStyles_Italic, fontStyle)) this.style = OS.FontStyles_Italic;
- if (OS.Object_Equals(OS.FontStyles_Oblique, fontStyle)) this.style = OS.FontStyles_Oblique;
- OS.GCHandle_Free(fontStyle);
- }
- OS.GCHandle_Free(converter);
- OS.GCHandle_Free(str);
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) return;
- weight = Integer.parseInt(string.substring(start, end));
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) end = string.length();
- stretch = Integer.parseInt(string.substring(start, end));
- } catch (NumberFormatException e) {
- setName(name);
- setHeight(height);
- setStyle(style);
- return;
- }
- }
-}
-
-/**
- * Constructs a new font data given a font name,
- * the height of the desired font in points,
- * and a font style.
- *
- * @param name the name of the font (must not be null)
- * @param height the font height in points
- * @param style a bit or combination of NORMAL, BOLD, ITALIC
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - when the font name is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- */
-public FontData(String name, int height, int style) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- setName(name);
- setHeight(height);
- setStyle(style);
- stretch = OS.FontStretch_ToOpenTypeStretch(OS.FontStretches_Normal);
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof FontData)) return false;
- FontData fd = (FontData)object;
- return style == fd.style &&
- height == fd.height &&
- weight == fd.weight &&
- stretch == fd.stretch &&
- getName().equals(fd.getName());
-}
-
-/**
- * Returns the height of the receiver in points.
- *
- * @return the height of this FontData
- *
- * @see #setHeight(int)
- */
-public int getHeight() {
- return height;
-}
-
-/**
- * Returns the locale of the receiver.
- * <p>
- * The locale determines which platform character set this
- * font is going to use. Widgets and graphics operations that
- * use this font will convert UNICODE strings to the platform
- * character set of the specified locale.
- * </p>
- * <p>
- * On platforms where there are multiple character sets for a
- * given language/country locale, the variant portion of the
- * locale will determine the character set.
- * </p>
- *
- * @return the <code>String</code> representing a Locale object
- * @since 3.0
- */
-public String getLocale () {
- StringBuffer buffer = new StringBuffer ();
- char sep = '_';
- if (lang != null) {
- buffer.append (lang);
- buffer.append (sep);
- }
- if (country != null) {
- buffer.append (country);
- buffer.append (sep);
- }
- if (variant != null) {
- buffer.append (variant);
- }
-
- String result = buffer.toString ();
- int length = result.length ();
- if (length > 0) {
- if (result.charAt (length - 1) == sep) {
- result = result.substring (0, length - 1);
- }
- }
- return result;
-}
-
-/**
- * Returns the name of the receiver.
- * On platforms that support font foundries, the return value will
- * be the foundry followed by a dash ("-") followed by the face name.
- *
- * @return the name of this <code>FontData</code>
- *
- * @see #setName
- */
-public String getName() {
- return fontFamily;
-}
-
-/**
- * Returns the style of the receiver which is a bitwise OR of
- * one or more of the <code>SWT</code> constants NORMAL, BOLD
- * and ITALIC.
- *
- * @return the style of this <code>FontData</code>
- *
- * @see #setStyle
- */
-public int getStyle() {
- int style = SWT.NORMAL;
- if (weight == OS.FontWeight_ToOpenTypeWeight(OS.FontWeights_Bold)) style |= SWT.BOLD;
- if (style == OS.FontStyles_Italic) style |= SWT.ITALIC;
- return style;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return style ^ weight ^ stretch ^ getName().hashCode();
-}
-
-/**
- * Sets the height of the receiver. The parameter is
- * specified in terms of points, where a point is one
- * seventy-second of an inch.
- *
- * @param height the height of the <code>FontData</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- *
- * @see #getHeight
- */
-public void setHeight(int height) {
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.height = height;
-}
-
-/**
- * Sets the locale of the receiver.
- * <p>
- * The locale determines which platform character set this
- * font is going to use. Widgets and graphics operations that
- * use this font will convert UNICODE strings to the platform
- * character set of the specified locale.
- * </p>
- * <p>
- * On platforms where there are multiple character sets for a
- * given language/country locale, the variant portion of the
- * locale will determine the character set.
- * </p>
- *
- * @param locale the <code>String</code> representing a Locale object
- * @see java.util.Locale#toString
- */
-public void setLocale(String locale) {
- lang = country = variant = null;
- if (locale != null) {
- char sep = '_';
- int length = locale.length();
- int firstSep, secondSep;
-
- firstSep = locale.indexOf(sep);
- if (firstSep == -1) {
- firstSep = secondSep = length;
- } else {
- secondSep = locale.indexOf(sep, firstSep + 1);
- if (secondSep == -1) secondSep = length;
- }
- if (firstSep > 0) lang = locale.substring(0, firstSep);
- if (secondSep > firstSep + 1) country = locale.substring(firstSep + 1, secondSep);
- if (length > secondSep + 1) variant = locale.substring(secondSep + 1);
- }
-}
-
-/**
- * Sets the name of the receiver.
- * <p>
- * Some platforms support font foundries. On these platforms, the name
- * of the font specified in setName() may have one of the following forms:
- * <ol>
- * <li>a face name (for example, "courier")</li>
- * <li>a foundry followed by a dash ("-") followed by a face name (for example, "adobe-courier")</li>
- * </ol>
- * In either case, the name returned from getName() will include the
- * foundry.
- * </p>
- * <p>
- * On platforms that do not support font foundries, only the face name
- * (for example, "courier") is used in <code>setName()</code> and
- * <code>getName()</code>.
- * </p>
- *
- * @param name the name of the font data (must not be null)
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - when the font name is null</li>
- * </ul>
- *
- * @see #getName
- */
-public void setName(String name) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- fontFamily = name;
-}
-
-/**
- * Sets the style of the receiver to the argument which must
- * be a bitwise OR of one or more of the <code>SWT</code>
- * constants NORMAL, BOLD and ITALIC. All other style bits are
- * ignored.
- *
- * @param style the new style for this <code>FontData</code>
- *
- * @see #getStyle
- */
-public void setStyle(int style) {
- if ((style & SWT.BOLD) == SWT.BOLD) {
- weight = OS.FontWeight_ToOpenTypeWeight(OS.FontWeights_Bold);
- } else {
- weight = OS.FontWeight_ToOpenTypeWeight(OS.FontWeights_Normal);
- }
- if ((style & SWT.ITALIC) == SWT.ITALIC) {
- this.style = OS.FontStyles_Italic;
- } else {
- this.style = OS.FontStyles_Normal;
- }
-}
-
-/**
- * Returns a string representation of the receiver which is suitable
- * for constructing an equivalent instance using the
- * <code>FontData(String)</code> constructor.
- *
- * @return a string representation of the FontData
- *
- * @see FontData
- */
-public String toString() {
- StringBuffer buffer = new StringBuffer();
- buffer.append("1|"); //$NON-NLS-1$
- buffer.append(getName());
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(getHeight());
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(getStyle());
- buffer.append("|"); //$NON-NLS-1$
- buffer.append("WPF|1|"); //$NON-NLS-1$
- buffer.append(fontFamily);
- buffer.append("|"); //$NON-NLS-1$
- int converter = OS.TypeDescriptor_GetConverter(OS.FontStyles_Normal);
- int str = OS.TypeConverter_ConvertToString(converter, style != 0 ? style : OS.FontStyles_Normal);
- int charArray = OS.String_ToCharArray(str);
- char[] chars = new char[OS.String_Length(str)];
- OS.memcpy(chars, charArray, chars.length * 2);
- OS.GCHandle_Free (charArray);
- OS.GCHandle_Free (str);
- OS.GCHandle_Free (converter);
- buffer.append(chars);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(weight);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(stretch);
- return buffer.toString();
-}
-
-/**
- * Invokes platform specific functionality to allocate a new font data.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>FontData</code>. It is marked public only so that
- * it can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the <code>LOGFONT</code> for the font data
- * @param height the height of the font data
- * @return a new font data object containing the specified <code>LOGFONT</code> and height
- */
-public static FontData wpf_new(String fontFamily, int style, int weight, int stretch, int height) {
- FontData data = new FontData();
- data.fontFamily = fontFamily;
- data.style = style;
- data.weight = weight;
- data.stretch = stretch;
- data.height = height;
- return data;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/FontMetrics.java
deleted file mode 100644
index 4a8b8b1fe8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/FontMetrics.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-/**
- * Instances of this class provide measurement information
- * about fonts including ascent, descent, height, leading
- * space between rows, and average character width.
- * <code>FontMetrics</code> are obtained from <code>GC</code>s
- * using the <code>getFontMetrics()</code> method.
- *
- * @see GC#getFontMetrics
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public final class FontMetrics {
- int ascent, descent, averageCharWidth, leading, height;
-
-FontMetrics() {
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof FontMetrics)) return false;
- FontMetrics metrics = (FontMetrics)object;
- return ascent == metrics.ascent && descent == metrics.descent &&
- averageCharWidth == metrics.averageCharWidth && leading == metrics.leading &&
- height == metrics.height;
-}
-
-/**
- * Returns the ascent of the font described by the receiver. A
- * font's <em>ascent</em> is the distance from the baseline to the
- * top of actual characters, not including any of the leading area,
- * measured in pixels.
- *
- * @return the ascent of the font
- */
-public int getAscent() {
- return ascent;
-}
-
-/**
- * Returns the average character width, measured in pixels,
- * of the font described by the receiver.
- *
- * @return the average character width of the font
- */
-public int getAverageCharWidth() {
- return averageCharWidth;
-}
-
-/**
- * Returns the descent of the font described by the receiver. A
- * font's <em>descent</em> is the distance from the baseline to the
- * bottom of actual characters, not including any of the leading area,
- * measured in pixels.
- *
- * @return the descent of the font
- */
-public int getDescent() {
- return descent;
-}
-
-/**
- * Returns the height of the font described by the receiver,
- * measured in pixels. A font's <em>height</em> is the sum of
- * its ascent, descent and leading area.
- *
- * @return the height of the font
- *
- * @see #getAscent
- * @see #getDescent
- * @see #getLeading
- */
-public int getHeight() {
- return height;
-}
-
-/**
- * Returns the leading area of the font described by the
- * receiver. A font's <em>leading area</em> is the space
- * above its ascent which may include accents or other marks.
- *
- * @return the leading space of the font
- */
-public int getLeading() {
- return leading;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode() {
- return ascent ^ descent ^ averageCharWidth ^ leading ^ height;
-}
-
-public static FontMetrics wpf_new(int ascent, int descent, int averageCharWidth, int leading, int height) {
- FontMetrics fontMetrics = new FontMetrics();
- fontMetrics.ascent = ascent;
- fontMetrics.descent = descent;
- fontMetrics.averageCharWidth = averageCharWidth;
- fontMetrics.leading = leading;
- fontMetrics.height = height;
- return fontMetrics;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/GC.java
deleted file mode 100644
index dae4748e16..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/GC.java
+++ /dev/null
@@ -1,3112 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-
-/**
- * Class <code>GC</code> is where all of the drawing capabilities that are
- * supported by SWT are located. Instances are used to draw on either an
- * <code>Image</code>, a <code>Control</code>, or directly on a <code>Display</code>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * </dl>
- *
- * <p>
- * The SWT drawing coordinate system is the two-dimensional space with the origin
- * (0,0) at the top left corner of the drawing area and with (x,y) values increasing
- * to the right and downward respectively.
- * </p>
- *
- * <p>
- * The result of drawing on an image that was created with an indexed
- * palette using a color that is not in the palette is platform specific.
- * Some platforms will match to the nearest color while other will draw
- * the color itself. This happens because the allocated image might use
- * a direct palette on platforms that do not support indexed palette.
- * </p>
- *
- * <p>
- * Application code must explicitly invoke the <code>GC.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required. This is <em>particularly</em>
- * important on Windows95 and Windows98 where the operating system has a limited
- * number of device contexts available.
- * </p>
- *
- * <p>
- * Note: Only one of LEFT_TO_RIGHT and RIGHT_TO_LEFT may be specified.
- * </p>
- *
- * @see org.eclipse.swt.events.PaintEvent
- * @see <a href="http://www.eclipse.org/swt/snippets/#gc">GC snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class GC extends Resource {
-
- /**
- * the handle to the OS device context
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
- Drawable drawable;
- GCData data;
-
- static final int FOREGROUND = 1 << 0;
- static final int BACKGROUND = 1 << 1;
- static final int FONT = 1 << 2;
- static final int LINE_STYLE = 1 << 3;
- static final int LINE_WIDTH = 1 << 4;
- static final int LINE_CAP = 1 << 5;
- static final int LINE_JOIN = 1 << 6;
- static final int LINE_MITERLIMIT = 1 << 7;
- static final int ALPHA = 1 << 8;
- static final int CLIPPING = 1 << 9;
- static final int TRANSFORM = 1 << 10;
-
- static final int DRAW = FOREGROUND | LINE_STYLE | LINE_WIDTH | LINE_CAP | LINE_JOIN | ALPHA | CLIPPING | TRANSFORM;
- static final int FILL = BACKGROUND | ALPHA | CLIPPING | TRANSFORM;
- static final int IMAGE = ALPHA | CLIPPING | TRANSFORM;
-
- static final double[] LINE_DOT_ZERO = new double[]{3, 3};
- static final double[] LINE_DASH_ZERO = new double[]{18, 6};
- static final double[] LINE_DASHDOT_ZERO = new double[]{9, 6, 3, 6};
- static final double[] LINE_DASHDOTDOT_ZERO = new double[]{9, 3, 3, 3, 3, 3};
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-GC() {
-}
-
-/**
- * Constructs a new instance of this class which has been
- * configured to draw on the specified drawable. Sets the
- * foreground color, background color and font in the GC
- * to match those in the drawable.
- * <p>
- * You must dispose the graphics context when it is no longer required.
- * </p>
- * @param drawable the drawable to draw on
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li>
- * <li>ERROR_NULL_ARGUMENT - if there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT
- * - if the drawable is an image that is not a bitmap or an icon
- * - if the drawable is an image or printer that is already selected
- * into another graphics context</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li>
- * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li>
- * </ul>
- */
-public GC(Drawable drawable) {
- this(drawable, SWT.NONE);
-}
-
-/**
- * Constructs a new instance of this class which has been
- * configured to draw on the specified drawable. Sets the
- * foreground color, background color and font in the GC
- * to match those in the drawable.
- * <p>
- * You must dispose the graphics context when it is no longer required.
- * </p>
- *
- * @param drawable the drawable to draw on
- * @param style the style of GC to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li>
- * <li>ERROR_NULL_ARGUMENT - if there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT
- * - if the drawable is an image that is not a bitmap or an icon
- * - if the drawable is an image or printer that is already selected
- * into another graphics context</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li>
- * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public GC(Drawable drawable, int style) {
- if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- GCData data = new GCData ();
- data.style = checkStyle(style);
- int hDC = drawable.internal_new_GC(data);
- Device device = data.device;
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = data.device = device;
- init (drawable, data, hDC);
- init();
-}
-
-static int checkStyle(int style) {
- if ((style & SWT.LEFT_TO_RIGHT) != 0) style &= ~SWT.RIGHT_TO_LEFT;
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-void checkGC(int mask) {
- int state = data.state;
- if ((state & mask) == mask) return;
- state = (state ^ mask) & mask;
- data.state |= mask;
- if ((state & (FOREGROUND | LINE_WIDTH | LINE_STYLE | LINE_JOIN | LINE_CAP | LINE_MITERLIMIT)) != 0) {
- int pen = data.pen;
- if (pen != 0) OS.GCHandle_Free(pen);
- pen = data.pen = OS.gcnew_Pen();
- int brush;
- Pattern pattern = data.foregroundPattern;
- if (pattern != null) {
- brush = pattern.handle;
- } else {
- int foreground = data.foreground;
- brush = OS.gcnew_SolidColorBrush(foreground);
- if (brush == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- }
- OS.Pen_Brush(pen, brush);
- if (pattern == null) OS.GCHandle_Free(brush);
- float width = data.lineWidth;
- OS.Pen_Thickness(pen, width == 0 ? 1 : width);
- double[] dashes = null;
- int dashStyle = 0;
- switch (data.lineStyle) {
- case SWT.LINE_SOLID: dashStyle = OS.DashStyles_Solid(); break;
- case SWT.LINE_DOT: if (width == 0) dashes = LINE_DOT_ZERO; else dashStyle = OS.DashStyles_Dot(); break;
- case SWT.LINE_DASH: if (width == 0) dashes = LINE_DASH_ZERO; else dashStyle = OS.DashStyles_Dash(); break;
- case SWT.LINE_DASHDOT: if (width == 0) dashes = LINE_DASHDOT_ZERO; else dashStyle = OS.DashStyles_DashDot(); break;
- case SWT.LINE_DASHDOTDOT: if (width == 0) dashes = LINE_DASHDOTDOT_ZERO; else dashStyle = OS.DashStyles_DashDotDot(); break;
- case SWT.LINE_CUSTOM: {
- if (data.lineDashes != null) {
- dashes = new double[data.lineDashes.length * 2];
- for (int i = 0; i < data.lineDashes.length; i++) {
- double dash = (double)data.lineDashes[i] / Math.max (1, width);
- dashes[i] = dash;
- dashes[i + data.lineDashes.length] = dash;
- }
- } else {
- dashStyle = OS.DashStyles_Solid();
- }
- }
- }
- if (dashes != null) {
- int list = OS.gcnew_DoubleCollection(dashes.length);
- for (int i = 0; i < dashes.length; i++) {
- OS.DoubleCollection_Add(list, dashes[i]);
- }
- dashStyle = OS.gcnew_DashStyle(list, data.lineDashesOffset);
- OS.GCHandle_Free(list);
- }
- OS.Pen_DashStyle(pen, dashStyle);
- OS.GCHandle_Free(dashStyle);
- int joinStyle = 0;
- switch (data.lineJoin) {
- case SWT.JOIN_MITER: joinStyle = OS.PenLineJoin_Miter; break;
- case SWT.JOIN_BEVEL: joinStyle = OS.PenLineJoin_Bevel; break;
- case SWT.JOIN_ROUND: joinStyle = OS.PenLineJoin_Round; break;
- }
- OS.Pen_LineJoin(pen, joinStyle);
- int capStyle = OS.PenLineCap_Flat;
- switch (data.lineCap) {
- case SWT.CAP_FLAT: capStyle = OS.PenLineCap_Flat; break;
- case SWT.CAP_ROUND: capStyle = OS.PenLineCap_Round; break;
- case SWT.CAP_SQUARE: capStyle = OS.PenLineCap_Square; break;
- }
- OS.Pen_DashCap(pen, capStyle);
- OS.Pen_EndLineCap(pen, capStyle);
- OS.Pen_StartLineCap(pen, capStyle);
- OS.Pen_MiterLimit(pen, data.lineMiterLimit);
- }
- if ((state & BACKGROUND) != 0) {
- if (data.brush != 0) OS.GCHandle_Free(data.brush);
- data.brush = 0;
- Pattern pattern = data.backgroundPattern;
- if (pattern != null) {
- data.currentBrush = pattern.handle;
- } else {
- int background = data.background;
- int brush = OS.gcnew_SolidColorBrush(background);
- if (brush == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- data.currentBrush = data.brush = brush;
- }
- }
- if ((state & (ALPHA | CLIPPING | TRANSFORM)) != 0) {
- for (int i = 0; i < data.pushCount; i++) OS.DrawingContext_Pop(handle);
- data.pushCount = 0;
- if (data.alpha != 0xFF) {
- OS.DrawingContext_PushOpacity(handle, (data.alpha & 0xFF) / (double)0xFF);
- data.pushCount++;
- }
- if (data.clip != 0) {
- OS.DrawingContext_PushClip(handle, data.clip);
- data.pushCount++;
- }
- if (data.transform != 0) {
- OS.DrawingContext_PushTransform(handle, data.transform);
- data.pushCount++;
- }
- }
-
-}
-
-/**
- * Copies a rectangular area of the receiver at the specified
- * position into the image, which must be of type <code>SWT.BITMAP</code>.
- *
- * @param image the image to copy into
- * @param x the x coordinate in the receiver of the area to be copied
- * @param y the y coordinate in the receiver of the area to be copied
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image is not a bitmap or has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void copyArea(Image image, int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-
- //TODO - implement copyArea
-}
-
-/**
- * Copies a rectangular area of the receiver at the source
- * position onto the receiver at the destination position.
- *
- * @param srcX the x coordinate in the receiver of the area to be copied
- * @param srcY the y coordinate in the receiver of the area to be copied
- * @param width the width of the area to copy
- * @param height the height of the area to copy
- * @param destX the x coordinate in the receiver of the area to copy to
- * @param destY the y coordinate in the receiver of the area to copy to
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY) {
- copyArea(srcX, srcY, width, height, destX, destY, true);
-}
-
-/**
- * Copies a rectangular area of the receiver at the source
- * position onto the receiver at the destination position.
- *
- * @param srcX the x coordinate in the receiver of the area to be copied
- * @param srcY the y coordinate in the receiver of the area to be copied
- * @param width the width of the area to copy
- * @param height the height of the area to copy
- * @param destX the x coordinate in the receiver of the area to copy to
- * @param destY the y coordinate in the receiver of the area to copy to
- * @param paint if <code>true</code> paint events will be generated for old and obscured areas
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-
- //TODO - implement copyArea
-
-// /*
-// * Feature in WinCE. The function WindowFromDC is not part of the
-// * WinCE SDK. The fix is to remember the HWND.
-// */
-// int hwnd = data.hwnd;
-// if (hwnd == 0) {
-// OS.BitBlt(handle, destX, destY, width, height, handle, srcX, srcY, OS.SRCCOPY);
-// } else {
-// RECT lprcClip = null;
-// int hrgn = OS.CreateRectRgn(0, 0, 0, 0);
-// if (OS.GetClipRgn(handle, hrgn) == 1) {
-// lprcClip = new RECT();
-// OS.GetRgnBox(hrgn, lprcClip);
-// }
-// OS.DeleteObject(hrgn);
-// RECT lprcScroll = new RECT();
-// OS.SetRect(lprcScroll, srcX, srcY, srcX + width, srcY + height);
-// int flags = paint ? OS.SW_INVALIDATE | OS.SW_ERASE : 0;
-// int res = OS.ScrollWindowEx(hwnd, destX - srcX, destY - srcY, lprcScroll, lprcClip, 0, null, flags);
-//
-// /*
-// * Feature in WinCE. ScrollWindowEx does not accept combined
-// * vertical and horizontal scrolling. The fix is to do a
-// * BitBlt and invalidate the appropriate source area.
-// */
-// if (res == 0 && OS.IsWinCE) {
-// OS.BitBlt(handle, destX, destY, width, height, handle, srcX, srcY, OS.SRCCOPY);
-// if (paint) {
-// int deltaX = destX - srcX, deltaY = destY - srcY;
-// boolean disjoint = (destX + width < srcX) || (srcX + width < destX) || (destY + height < srcY) || (srcY + height < destY);
-// if (disjoint) {
-// OS.InvalidateRect(hwnd, lprcScroll, true);
-// } else {
-// if (deltaX != 0) {
-// int newX = destX - deltaX;
-// if (deltaX < 0) newX = destX + width;
-// OS.SetRect(lprcScroll, newX, srcY, newX + Math.abs(deltaX), srcY + height);
-// OS.InvalidateRect(hwnd, lprcScroll, true);
-// }
-// if (deltaY != 0) {
-// int newY = destY - deltaY;
-// if (deltaY < 0) newY = destY + height;
-// OS.SetRect(lprcScroll, srcX, newY, srcX + width, newY + Math.abs(deltaY));
-// OS.InvalidateRect(hwnd, lprcScroll, true);
-// }
-// }
-// }
-// }
-// }
-}
-
-void destroy() {
- int brush = data.brush;
- if (brush != 0) OS.GCHandle_Free(brush);
- data.brush = 0;
- int pen = data.pen;
- if (pen != 0) OS.GCHandle_Free(pen);
- data.pen = 0;
- int clip = data.clip;
- if (clip != 0) OS.GCHandle_Free(clip);
- data.clip = 0;
- int transform = data.transform;
- if (transform != 0) OS.GCHandle_Free(transform);
- data.transform = 0;
-
- Image image = data.image;
- if (image != null) image.memGC = null;
-
- if (drawable != null) drawable.internal_dispose_GC(handle, data);
- drawable = null;
- handle = 0;
- data.image = null;
- data = null;
-}
-
-/**
- * Draws the outline of a circular or elliptical arc
- * within the specified rectangular area.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees, using the current color.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc to be drawn
- * @param y the y coordinate of the upper-left corner of the arc to be drawn
- * @param width the width of the arc to be drawn
- * @param height the height of the arc to be drawn
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawArc (int x, int y, int width, int height, int startAngle, int arcAngle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- double offset = 0;
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) offset = 0.5;
- if (arcAngle >= 360 || arcAngle <= -360) {
- int center = OS.gcnew_Point(x + offset + width / 2f, y + offset + height / 2f);
- OS.DrawingContext_DrawEllipse(handle, 0, data.pen, center, width / 2f, height / 2f);
- OS.GCHandle_Free(center);
- return;
- }
- boolean isNegative = arcAngle < 0;
- boolean isLargeAngle = arcAngle > 180 || arcAngle < -180;
- arcAngle = arcAngle + startAngle;
- if (isNegative) {
- // swap angles
- int tmp = startAngle;
- startAngle = arcAngle;
- arcAngle = tmp;
- }
- double x1 = Math.cos(startAngle * Math.PI / 180) * width/2.0 + x + offset + width/2.0;
- double y1 = -1 * Math.sin(startAngle * Math.PI / 180) * height/2.0 + y + offset + height/2.0;
- double x2 = Math.cos(arcAngle * Math.PI / 180) * width/2.0 + x + offset + width/2.0;
- double y2 = -1 * Math.sin(arcAngle * Math.PI / 180) * height/2.0 + y + offset + height/2.0;
- int startPoint = OS.gcnew_Point(x1, y1);
- int endPoint = OS.gcnew_Point(x2, y2);
- int size = OS.gcnew_Size(width / 2.0, height / 2.0);
- int arc = OS.gcnew_ArcSegment(endPoint, size, 0, isLargeAngle, OS.SweepDirection_Clockwise, true);
- int figure = OS.gcnew_PathFigure();
- OS.PathFigure_StartPoint(figure, startPoint);
- int segments = OS.PathFigure_Segments(figure);
- OS.PathSegmentCollection_Add(segments, arc);
- int path = OS.gcnew_PathGeometry();
- int figures = OS.PathGeometry_Figures(path);
- OS.PathFigureCollection_Add(figures, figure);
- OS.DrawingContext_DrawGeometry(handle, 0, data.pen, path);
- OS.GCHandle_Free(figures);
- OS.GCHandle_Free(path);
- OS.GCHandle_Free(segments);
- OS.GCHandle_Free(figure);
- OS.GCHandle_Free(arc);
- OS.GCHandle_Free(size);
- OS.GCHandle_Free(endPoint);
- OS.GCHandle_Free(startPoint);
-}
-
-/**
- * Draws a rectangle, based on the specified arguments, which has
- * the appearance of the platform's <em>focus rectangle</em> if the
- * platform supports such a notion, and otherwise draws a simple
- * rectangle in the receiver's foreground color.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width of the rectangle
- * @param height the height of the rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void drawFocus (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- //TODO - implement drawFocus
-}
-
-/**
- * Draws the given image in the receiver at the specified
- * coordinates.
- *
- * @param image the image to draw
- * @param x the x coordinate of where to draw
- * @param y the y coordinate of where to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if the given coordinates are outside the bounds of the image</li>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- */
-public void drawImage(Image image, int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- drawImage(image, 0, 0, -1, -1, x, y, -1, -1, true);
-}
-
-/**
- * Copies a rectangular area from the source image into a (potentially
- * different sized) rectangular area in the receiver. If the source
- * and destination areas are of differing sizes, then the source
- * area will be stretched or shrunk to fit the destination area
- * as it is copied. The copy fails if any part of the source rectangle
- * lies outside the bounds of the source image, or if any of the width
- * or height arguments are negative.
- *
- * @param image the source image
- * @param srcX the x coordinate in the source image to copy from
- * @param srcY the y coordinate in the source image to copy from
- * @param srcWidth the width in pixels to copy from the source
- * @param srcHeight the height in pixels to copy from the source
- * @param destX the x coordinate in the destination to copy to
- * @param destY the y coordinate in the destination to copy to
- * @param destWidth the width in pixels of the destination rectangle
- * @param destHeight the height in pixels of the destination rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if any of the width or height arguments are negative.
- * <li>ERROR_INVALID_ARGUMENT - if the source rectangle is not contained within the bounds of the source image</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- */
-public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (srcWidth == 0 || srcHeight == 0 || destWidth == 0 || destHeight == 0) return;
- if (srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 || destWidth < 0 || destHeight < 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (image == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- drawImage(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false);
-}
-
-void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
- checkGC(IMAGE);
- int imageHandle = image.handle;
- int imgWidth = OS.BitmapSource_PixelWidth(imageHandle);
- int imgHeight = OS.BitmapSource_PixelHeight(imageHandle);
- if (simple) {
- srcWidth = destWidth = imgWidth;
- srcHeight = destHeight = imgHeight;
- } else {
- simple = srcX == 0 && srcY == 0 &&
- srcWidth == destWidth && destWidth == imgWidth &&
- srcHeight == destHeight && destHeight == imgHeight;
- if (srcX + srcWidth > imgWidth || srcY + srcHeight > imgHeight) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- int mode = 0;
- switch (data.interpolation) {
- case SWT.DEFAULT: mode = OS.BitmapScalingMode_Unspecified; break;
- case SWT.NONE: mode = OS.BitmapScalingMode_LowQuality; break;
- case SWT.LOW: mode = OS.BitmapScalingMode_LowQuality; break;
- case SWT.HIGH: mode = OS.BitmapScalingMode_HighQuality; break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (srcX != 0 || srcY != 0 || srcWidth != imgWidth || srcHeight != imgHeight) {
- int rect = OS.gcnew_Int32Rect(srcX, srcY, srcWidth, srcHeight);
- imageHandle = OS.gcnew_CroppedBitmap(imageHandle, rect);
- OS.RenderOptions_SetBitmapScalingMode(imageHandle, mode);
- OS.GCHandle_Free(rect);
- } else {
- if (mode != OS.RenderOptions_GetBitmapScalingMode(imageHandle)) {
- imageHandle = OS.Freezable_Clone(imageHandle);
- OS.RenderOptions_SetBitmapScalingMode(imageHandle, mode);
- }
- }
- int rect = OS.gcnew_Rect(destX, destY, destWidth, destHeight);
- OS.DrawingContext_DrawImage(handle, imageHandle, rect);
- OS.GCHandle_Free(rect);
- if (image.handle != imageHandle) OS.GCHandle_Free(imageHandle);
-}
-
-/**
- * Draws a line, using the foreground color, between the points
- * (<code>x1</code>, <code>y1</code>) and (<code>x2</code>, <code>y2</code>).
- *
- * @param x1 the first point's x coordinate
- * @param y1 the first point's y coordinate
- * @param x2 the second point's x coordinate
- * @param y2 the second point's y coordinate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawLine (int x1, int y1, int x2, int y2) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- double offset = 0;
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) offset = 0.5;
- int point0 = OS.gcnew_Point(x1 + offset, y1 + offset);
- int point1 = OS.gcnew_Point(x2 + offset, y2 + offset);
- OS.DrawingContext_DrawLine(handle, data.pen, point0, point1);
- OS.GCHandle_Free(point0);
- OS.GCHandle_Free(point1);
-}
-
-/**
- * Draws the outline of an oval, using the foreground color,
- * within the specified rectangular area.
- * <p>
- * The result is a circle or ellipse that fits within the
- * rectangle specified by the <code>x</code>, <code>y</code>,
- * <code>width</code>, and <code>height</code> arguments.
- * </p><p>
- * The oval covers an area that is <code>width + 1</code>
- * pixels wide and <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper left corner of the oval to be drawn
- * @param y the y coordinate of the upper left corner of the oval to be drawn
- * @param width the width of the oval to be drawn
- * @param height the height of the oval to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawOval (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- double offset = 0;
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) offset = 0.5;
- int center = OS.gcnew_Point(x + offset + width / 2f, y + offset + height / 2f);
- OS.DrawingContext_DrawEllipse(handle, 0, data.pen, center, width / 2f, height / 2f);
- OS.GCHandle_Free(center);
-}
-
-/**
- * Draws the path described by the parameter.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the path to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- *
- * @since 3.1
- */
-public void drawPath (Path path) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- checkGC(DRAW);
- //TODO - check offset to draw in the midle of pixel
- OS.PathGeometry_FillRule(path.handle, data.fillRule == SWT.FILL_EVEN_ODD ? OS.FillRule_EvenOdd : OS.FillRule_Nonzero);
- OS.DrawingContext_DrawGeometry(handle, 0, data.pen, path.handle);
-}
-
-/**
- * Draws a pixel, using the foreground color, at the specified
- * point (<code>x</code>, <code>y</code>).
- * <p>
- * Note that the receiver's line attributes do not affect this
- * operation.
- * </p>
- *
- * @param x the point's x coordinate
- * @param y the point's y coordinate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void drawPoint (int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- int rect = OS.gcnew_Rect(x, y, 1, 1);
- int brush = OS.Pen_Brush(data.pen);
- OS.DrawingContext_DrawRectangle(handle, brush, 0, rect);
- OS.GCHandle_Free(brush);
- OS.GCHandle_Free(rect);
-}
-
-/**
- * Draws the closed polygon which is defined by the specified array
- * of integer coordinates, using the receiver's foreground color. The array
- * contains alternating x and y values which are considered to represent
- * points which are the vertices of the polygon. Lines are drawn between
- * each consecutive pair, and between the first pair and last pair in the
- * array.
- *
- * @param pointArray an array of alternating x and y values which are the vertices of the polygon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT if pointArray is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawPolygon(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(DRAW);
- drawPolyLineSegment(pointArray, true, true);
-}
-
-void drawPolyLineSegment(int[] pointArray, boolean closed, boolean stroked) {
- if (pointArray.length < 4) return;
- int list = OS.gcnew_PointCollection(pointArray.length / 2);
- double offset = 0;
- if (stroked && (data.lineWidth == 0 || (data.lineWidth % 2) == 1)) offset = 0.5;
- for (int i = 2; i < pointArray.length; i += 2) {
- int point = OS.gcnew_Point(pointArray[i] + offset, pointArray[i + 1] + offset);
- OS.PointCollection_Add(list, point);
- OS.GCHandle_Free(point);
- }
- int poly = OS.gcnew_PolyLineSegment(list, stroked);
- OS.GCHandle_Free(list);
- int figure = OS.gcnew_PathFigure();
- int startPoint = OS.gcnew_Point(pointArray[0] + offset, pointArray[1] + offset);
- OS.PathFigure_StartPoint(figure, startPoint);
- OS.PathFigure_IsClosed(figure, closed);
- int segments = OS.PathFigure_Segments(figure);
- OS.PathSegmentCollection_Add(segments, poly);
- int path = OS.gcnew_PathGeometry();
-// int mode = 0;
-// switch (data.antialias) {
-// case SWT.DEFAULT:
-// case SWT.ON: mode = OS.EdgeMode_Unspecified; break;
-// case SWT.OFF: mode = OS.EdgeMode_Aliased; break;
-// }
-// OS.RenderOptions_SetEdgeMode(path, mode);
- if (!stroked) OS.PathGeometry_FillRule(path, data.fillRule == SWT.FILL_EVEN_ODD ? OS.FillRule_EvenOdd : OS.FillRule_Nonzero);
- int figures = OS.PathGeometry_Figures(path);
- OS.PathFigureCollection_Add(figures, figure);
- OS.DrawingContext_DrawGeometry(handle, stroked ? 0 : data.currentBrush, stroked ? data.pen : 0, path);
- OS.GCHandle_Free(figures);
- OS.GCHandle_Free(path);
- OS.GCHandle_Free(segments);
- OS.GCHandle_Free(figure);
- OS.GCHandle_Free(startPoint);
- OS.GCHandle_Free(poly);
-}
-
-/**
- * Draws the polyline which is defined by the specified array
- * of integer coordinates, using the receiver's foreground color. The array
- * contains alternating x and y values which are considered to represent
- * points which are the corners of the polyline. Lines are drawn between
- * each consecutive pair, but not between the first pair and last pair in
- * the array.
- *
- * @param pointArray an array of alternating x and y values which are the corners of the polyline
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawPolyline(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(DRAW);
- drawPolyLineSegment(pointArray, false, true);
-}
-
-/**
- * Draws the outline of the rectangle specified by the arguments,
- * using the receiver's foreground color. The left and right edges
- * of the rectangle are at <code>x</code> and <code>x + width</code>.
- * The top and bottom edges are at <code>y</code> and <code>y + height</code>.
- *
- * @param x the x coordinate of the rectangle to be drawn
- * @param y the y coordinate of the rectangle to be drawn
- * @param width the width of the rectangle to be drawn
- * @param height the height of the rectangle to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRectangle (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- double offset = 0;
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) offset = 0.5;
- int rect = OS.gcnew_Rect(x + offset, y + offset, width, height);
- OS.DrawingContext_DrawRectangle(handle, 0, data.pen, rect);
- OS.GCHandle_Free(rect);
-}
-
-/**
- * Draws the outline of the specified rectangle, using the receiver's
- * foreground color. The left and right edges of the rectangle are at
- * <code>rect.x</code> and <code>rect.x + rect.width</code>. The top
- * and bottom edges are at <code>rect.y</code> and
- * <code>rect.y + rect.height</code>.
- *
- * @param rect the rectangle to draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRectangle (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- drawRectangle (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Draws the outline of the round-cornered rectangle specified by
- * the arguments, using the receiver's foreground color. The left and
- * right edges of the rectangle are at <code>x</code> and <code>x + width</code>.
- * The top and bottom edges are at <code>y</code> and <code>y + height</code>.
- * The <em>roundness</em> of the corners is specified by the
- * <code>arcWidth</code> and <code>arcHeight</code> arguments, which
- * are respectively the width and height of the ellipse used to draw
- * the corners.
- *
- * @param x the x coordinate of the rectangle to be drawn
- * @param y the y coordinate of the rectangle to be drawn
- * @param width the width of the rectangle to be drawn
- * @param height the height of the rectangle to be drawn
- * @param arcWidth the width of the arc
- * @param arcHeight the height of the arc
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (arcWidth < 0 || arcHeight < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- checkGC(DRAW);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (arcWidth < 0) arcWidth = -arcWidth;
- if (arcHeight < 0) arcHeight = -arcHeight;
- double offset = 0;
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) offset = 0.5;
- int rect = OS.gcnew_Rect(x + offset, y + offset, width, height);
- OS.DrawingContext_DrawRoundedRectangle(handle, 0, data.pen, rect, arcWidth / 2f, arcHeight / 2f);
- OS.GCHandle_Free(rect);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. No tab expansion or carriage return processing
- * will be performed. The background of the rectangular area where
- * the string is being drawn will be filled with the receiver's
- * background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawString (String string, int x, int y) {
- drawString(string, x, y, false);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. No tab expansion or carriage return processing
- * will be performed. If <code>isTransparent</code> is <code>true</code>,
- * then the background of the rectangular area where the string is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn
- * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawString (String string, int x, int y, boolean isTransparent) {
- drawText(string, x, y, isTransparent ? SWT.DRAW_TRANSPARENT : 0);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion and carriage return processing
- * are performed. The background of the rectangular area where
- * the text is being drawn will be filled with the receiver's
- * background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText (String string, int x, int y) {
- drawText(string, x, y, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion and carriage return processing
- * are performed. If <code>isTransparent</code> is <code>true</code>,
- * then the background of the rectangular area where the text is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText (String string, int x, int y, boolean isTransparent) {
- int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB;
- if (isTransparent) flags |= SWT.DRAW_TRANSPARENT;
- drawText(string, x, y, flags);
-}
-
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion, line delimiter and mnemonic
- * processing are performed according to the specified flags. If
- * <code>flags</code> includes <code>DRAW_TRANSPARENT</code>,
- * then the background of the rectangular area where the text is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- * <p>
- * The parameter <code>flags</code> may be a combination of:
- * <dl>
- * <dt><b>DRAW_DELIMITER</b></dt>
- * <dd>draw multiple lines</dd>
- * <dt><b>DRAW_TAB</b></dt>
- * <dd>expand tabs</dd>
- * <dt><b>DRAW_MNEMONIC</b></dt>
- * <dd>underline the mnemonic character</dd>
- * <dt><b>DRAW_TRANSPARENT</b></dt>
- * <dd>transparent background</dd>
- * </dl>
- * </p>
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param flags the flags specifying how to process the text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void drawText (String string, int x, int y, int flags) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int length = string.length ();
- if (length == 0) return;
- checkGC(FONT | FOREGROUND | ALPHA | CLIPPING | TRANSFORM | ((flags & SWT.DRAW_TRANSPARENT) != 0 ? 0 : BACKGROUND));
- char [] buffer = new char [length + 1];
- string.getChars(0, length, buffer, 0);
- int mask = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC;
- int mnemonic = -1;
- if ((flags & mask) != mask) {
- for (int i = 0, j = 0; i < buffer.length; i++) {
- char c = buffer[i];
- switch (c) {
- case '&': {
- if ((flags & SWT.DRAW_MNEMONIC) != 0) {
- if (i + 1 < length) {
- if (buffer[i + 1] == '&') {
- i++;
- } else {
- if (mnemonic == -1) mnemonic = j;
- }
- }
- continue;
- }
- break;
- }
- case '\r':
- case '\n':
- if ((flags & SWT.DRAW_DELIMITER) == 0) continue;
- break;
- case '\t':
- if ((flags & SWT.DRAW_TAB) == 0) continue;
- break;
- }
- buffer[j++] = c;
- }
- }
- int str = OS.gcnew_String (buffer);
- int culture = OS.CultureInfo_CurrentUICulture();
- Font font = data.font;
- int direction = (data.style & SWT.RIGHT_TO_LEFT) != 0 ? OS.FlowDirection_RightToLeft : OS.FlowDirection_LeftToRight;
- int brush = OS.Pen_Brush(data.pen);
- int text = OS.gcnew_FormattedText(str, culture, direction, font.handle, font.size, brush);
- int point = OS.gcnew_Point(x, y);
- if (mnemonic != -1) {
- int underline = OS.TextDecorations_Underline();
- OS.FormattedText_SetTextDecorations(text, underline, mnemonic, 1);
- OS.GCHandle_Free(underline);
- }
- if ((flags & SWT.DRAW_TRANSPARENT) == 0) {
- double width = OS.FormattedText_WidthIncludingTrailingWhitespace(text);
- double height = OS.FormattedText_Height(text);
- int rect = OS.gcnew_Rect(x, y, width, height);
- OS.DrawingContext_DrawRectangle(handle, data.currentBrush, 0, rect);
- OS.GCHandle_Free(rect);
-
- }
- OS.DrawingContext_DrawText(handle, text, point);
- OS.GCHandle_Free(point);
- OS.GCHandle_Free(culture);
- OS.GCHandle_Free(str);
- OS.GCHandle_Free(brush);
- OS.GCHandle_Free(text);
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- return (object == this) || ((object instanceof GC) && (handle == ((GC)object).handle));
-}
-
-/**
- * Fills the interior of a circular or elliptical arc within
- * the specified rectangular area, with the receiver's background
- * color.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees, using the current color.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc to be filled
- * @param y the y coordinate of the upper-left corner of the arc to be filled
- * @param width the width of the arc to be filled
- * @param height the height of the arc to be filled
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawArc
- */
-public void fillArc (int x, int y, int width, int height, int startAngle, int arcAngle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- if (arcAngle >= 360 || arcAngle <= -360) {
- int center = OS.gcnew_Point(x + width / 2f, y + height / 2f);
- OS.DrawingContext_DrawEllipse(handle, data.currentBrush, 0, center, width / 2f, height / 2f);
- OS.GCHandle_Free(center);
- return;
- }
- boolean isNegative = arcAngle < 0;
- boolean isLargeAngle = arcAngle > 180 || arcAngle < -180;
- arcAngle = arcAngle + startAngle;
- if (isNegative) {
- // swap angles
- int tmp = startAngle;
- startAngle = arcAngle;
- arcAngle = tmp;
- }
- double x1 = Math.cos(startAngle * Math.PI / 180) * width/2.0 + x + width/2.0;
- double y1 = -1 * Math.sin(startAngle * Math.PI / 180) * height/2.0 + y + height/2.0;
- double x2 = Math.cos(arcAngle * Math.PI / 180) * width/2.0 + x + width/2.0;
- double y2 = -1 * Math.sin(arcAngle * Math.PI / 180) * height/2.0 + y + height/2.0;
- int startPoint = OS.gcnew_Point(x1, y1);
- int endPoint = OS.gcnew_Point(x2, y2);
- int center = OS.gcnew_Point(x + width / 2.0, y + height / 2.0);
- int size = OS.gcnew_Size(width / 2.0, height / 2.0);
- int arc = OS.gcnew_ArcSegment(endPoint, size, 0, isLargeAngle, OS.SweepDirection_Clockwise, false);
- int line = OS.gcnew_LineSegment(center, false);
- int figure = OS.gcnew_PathFigure();
- OS.PathFigure_StartPoint(figure, startPoint);
- int segments = OS.PathFigure_Segments(figure);
- OS.PathSegmentCollection_Add(segments, arc);
- OS.PathSegmentCollection_Add(segments, line);
- int path = OS.gcnew_PathGeometry();
- int figures = OS.PathGeometry_Figures(path);
- OS.PathFigureCollection_Add(figures, figure);
- OS.DrawingContext_DrawGeometry(handle, data.currentBrush, 0, path);
- OS.GCHandle_Free(figures);
- OS.GCHandle_Free(path);
- OS.GCHandle_Free(segments);
- OS.GCHandle_Free(figure);
- OS.GCHandle_Free(arc);
- OS.GCHandle_Free(line);
- OS.GCHandle_Free(size);
- OS.GCHandle_Free(endPoint);
- OS.GCHandle_Free(startPoint);
-}
-
-/**
- * Fills the interior of the specified rectangle with a gradient
- * sweeping from left to right or top to bottom progressing
- * from the receiver's foreground color to its background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled, may be negative
- * (inverts direction of gradient if horizontal)
- * @param height the height of the rectangle to be filled, may be negative
- * (inverts direction of gradient if vertical)
- * @param vertical if true sweeps from top to bottom, else
- * sweeps from left to right
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width == 0 || height == 0) return;
- checkGC(FILL);
-
- int fromColor = data.foreground;
- int toColor = data.background;
-
- boolean swapColors = false;
- if (width < 0) {
- x += width; width = -width;
- if (! vertical) swapColors = true;
- }
- if (height < 0) {
- y += height; height = -height;
- if (vertical) swapColors = true;
- }
- if (swapColors) {
- int temp = fromColor;
- fromColor = toColor;
- toColor = temp;
- }
- int brush = OS.gcnew_LinearGradientBrush(fromColor, toColor, vertical ? 90 : 0);
- int rect = OS.gcnew_Rect(x, y, width, height);
- OS.DrawingContext_DrawRectangle(handle, brush, 0, rect);
- OS.GCHandle_Free(rect);
- OS.GCHandle_Free(brush);
-}
-
-/**
- * Fills the interior of an oval, within the specified
- * rectangular area, with the receiver's background
- * color.
- *
- * @param x the x coordinate of the upper left corner of the oval to be filled
- * @param y the y coordinate of the upper left corner of the oval to be filled
- * @param width the width of the oval to be filled
- * @param height the height of the oval to be filled
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawOval
- */
-public void fillOval (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int center = OS.gcnew_Point(x + width / 2f, y + height / 2f);
- OS.DrawingContext_DrawEllipse(handle, data.currentBrush, 0, center, width / 2f, height / 2f);
- OS.GCHandle_Free(center);
-}
-
-/**
- * Fills the path described by the parameter.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the path to fill
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- *
- * @since 3.1
- */
-public void fillPath (Path path) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- checkGC(FILL);
- OS.PathGeometry_FillRule(path.handle, data.fillRule == SWT.FILL_EVEN_ODD ? OS.FillRule_EvenOdd : OS.FillRule_Nonzero);
- OS.DrawingContext_DrawGeometry(handle, data.currentBrush, 0, path.handle);
-}
-
-/**
- * Fills the interior of the closed polygon which is defined by the
- * specified array of integer coordinates, using the receiver's
- * background color. The array contains alternating x and y values
- * which are considered to represent points which are the vertices of
- * the polygon. Lines are drawn between each consecutive pair, and
- * between the first pair and last pair in the array.
- *
- * @param pointArray an array of alternating x and y values which are the vertices of the polygon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT if pointArray is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawPolygon
- */
-public void fillPolygon(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(FILL);
- drawPolyLineSegment(pointArray, true, false);
-}
-
-/**
- * Fills the interior of the rectangle specified by the arguments,
- * using the receiver's background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillRectangle (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int rect = OS.gcnew_Rect(x, y, width, height);
- OS.DrawingContext_DrawRectangle(handle, data.currentBrush, 0, rect);
- OS.GCHandle_Free(rect);
-}
-
-/**
- * Fills the interior of the specified rectangle, using the receiver's
- * background color.
- *
- * @param rect the rectangle to be filled
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
-public void fillRectangle (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- fillRectangle (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Fills the interior of the round-cornered rectangle specified by
- * the arguments, using the receiver's background color.
- *
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- * @param arcWidth the width of the arc
- * @param arcHeight the height of the arc
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRoundRectangle
- */
-public void fillRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (arcWidth < 0) arcWidth = -arcWidth;
- if (arcHeight < 0) arcHeight = -arcHeight;
- int rect = OS.gcnew_Rect(x, y, width, height);
- OS.DrawingContext_DrawRoundedRectangle(handle, data.currentBrush, 0, rect, arcWidth / 2f, arcHeight / 2f);
- OS.GCHandle_Free(rect);
-}
-
-/**
- * Returns the <em>advance width</em> of the specified character in
- * the font which is currently selected into the receiver.
- * <p>
- * The advance width is defined as the horizontal distance the cursor
- * should move after printing the character in the selected font.
- * </p>
- *
- * @param ch the character to measure
- * @return the distance in the x direction to move past the character before painting the next
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getAdvanceWidth(char ch) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- //NOT DONE
- return stringExtent(new String(new char[]{ch})).x;
-}
-
-/**
- * Returns <code>true</code> if receiver is using the operating system's
- * advanced graphics subsystem. Otherwise, <code>false</code> is returned
- * to indicate that normal graphics are in use.
- * <p>
- * Advanced graphics may not be installed for the operating system. In this
- * case, <code>false</code> is always returned. Some operating system have
- * only one graphics subsystem. If this subsystem supports advanced graphics,
- * then <code>true</code> is always returned. If any graphics operation such
- * as alpha, antialias, patterns, interpolation, paths, clipping or transformation
- * has caused the receiver to switch from regular to advanced graphics mode,
- * <code>true</code> is returned. If the receiver has been explicitly switched
- * to advanced mode and this mode is supported, <code>true</code> is returned.
- * </p>
- *
- * @return the advanced value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public boolean getAdvanced() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return true;
-}
-
-/**
- * Returns the receiver's alpha value. The alpha value
- * is between 0 (transparent) and 255 (opaque).
- *
- * @return the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getAlpha() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.alpha;
-}
-
-/**
- * Returns the receiver's anti-aliasing setting value, which will be
- * one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code>. Note that this controls anti-aliasing for all
- * <em>non-text drawing</em> operations.
- *
- * @return the anti-aliasing setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getTextAntialias
- *
- * @since 3.1
- */
-public int getAntialias() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.antialias;
-}
-
-/**
- * Returns the background color.
- *
- * @return the receiver's background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getBackground() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return Color.wpf_new(data.device, data.background);
-}
-
-/**
- * Returns the background pattern. The default value is
- * <code>null</code>.
- *
- * @return the receiver's background pattern
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Pattern
- *
- * @since 3.1
- */
-public Pattern getBackgroundPattern() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.backgroundPattern;
-}
-
-/**
- * Returns the width of the specified character in the font
- * selected into the receiver.
- * <p>
- * The width is defined as the space taken up by the actual
- * character, not including the leading and tailing whitespace
- * or overhang.
- * </p>
- *
- * @param ch the character to measure
- * @return the width of the character
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getCharWidth(char ch) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- //NOT DONE
- return stringExtent(new String(new char[]{ch})).x;
-}
-
-/**
- * Returns the bounding rectangle of the receiver's clipping
- * region. If no clipping region is set, the return value
- * will be a rectangle which covers the entire bounds of the
- * object the receiver is drawing on.
- *
- * @return the bounding rectangle of the clipping region
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getClipping() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int x = 0, y = 0, width = 0, height = 0;
- int visualType = OS.Object_GetType(data.visual);
- int drawingVisualType = OS.DrawingVisual_typeid();
- if (OS.Object_Equals(visualType, drawingVisualType)) {
- int clip = OS.ContainerVisual_Clip(data.visual);
- int rect = OS.Geometry_Bounds(clip);
- width = (int)OS.Rect_Width(rect);
- height = (int)OS.Rect_Height(rect);
- OS.GCHandle_Free(rect);
- OS.GCHandle_Free(clip);
- } else {
- width = (int)OS.FrameworkElement_ActualWidth(data.visual);
- height = (int)OS.FrameworkElement_ActualHeight(data.visual);
- }
- OS.GCHandle_Free(drawingVisualType);
- OS.GCHandle_Free(visualType);
- if (data.clip != 0) {
- int bounds = OS.gcnew_Rect(x, y, width, height);
- int rect = OS.Geometry_Bounds(data.clip);
- OS.Rect_Intersect(bounds, rect);
- x = (int)OS.Rect_X(bounds);
- y = (int)OS.Rect_Y(bounds);
- width = (int)OS.Rect_Width(bounds);
- height = (int)OS.Rect_Height(bounds);
- OS.GCHandle_Free(rect);
- OS.GCHandle_Free(bounds);
- }
- return new Rectangle(x, y, width, height);
-}
-
-/**
- * Sets the region managed by the argument to the current
- * clipping region of the receiver.
- *
- * @param region the region to fill with the clipping region
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the region is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the region is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getClipping (Region region) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- int bounds;
- int visualType = OS.Object_GetType(data.visual);
- int drawingVisualType = OS.DrawingVisual_typeid();
- if (OS.Object_Equals(visualType, drawingVisualType)) {
- bounds = OS.ContainerVisual_Clip(data.visual);
- } else {
- double width = OS.FrameworkElement_ActualWidth(data.visual);
- double height = OS.FrameworkElement_ActualHeight(data.visual);
- int rect = OS.gcnew_Rect(0, 0, width, height);
- bounds = OS.gcnew_RectangleGeometry(rect);
- OS.GCHandle_Free(rect);
- }
- OS.GCHandle_Free(drawingVisualType);
- OS.GCHandle_Free(visualType);
- int geometries = OS.GeometryGroup_Children(region.handle);
- OS.GeometryCollection_Clear(geometries);
- if (data.clip != 0) {
- int clip = OS.Geometry_GetFlattenedPathGeometry(data.clip);
- int newGeometry = OS.gcnew_CombinedGeometry(OS.GeometryCombineMode_Intersect, bounds, clip);
- OS.GeometryCollection_Add(geometries, newGeometry);
- OS.GCHandle_Free(clip);
- OS.GCHandle_Free(newGeometry);
- } else {
- OS.GeometryCollection_Add(geometries, bounds);
- }
- OS.GCHandle_Free(bounds);
- OS.GCHandle_Free(geometries);
-}
-
-/**
- * Returns the receiver's fill rule, which will be one of
- * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>.
- *
- * @return the receiver's fill rule
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getFillRule() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.fillRule;
-}
-
-/**
- * Returns the font currently being used by the receiver
- * to draw and measure text.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getFont () {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.font;
-}
-
-/**
- * Returns a FontMetrics which contains information
- * about the font currently being used by the receiver
- * to draw and measure text.
- *
- * @return font metrics for the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontMetrics getFontMetrics() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FONT);
- //TODO - find a better way of getting font metrics
- String string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- int length = string.length();
- char [] buffer = new char [length + 1];
- string.getChars (0, length, buffer, 0);
- int str = OS.gcnew_String (buffer);
- int culture = OS.CultureInfo_CurrentUICulture();
- Font font = data.font;
- int direction = (data.style & SWT.RIGHT_TO_LEFT) != 0 ? OS.FlowDirection_RightToLeft : OS.FlowDirection_LeftToRight;
- int brush = OS.Brushes_White();
- int text = OS.gcnew_FormattedText(str, culture, direction, font.handle, font.size, brush);
- double width = OS.FormattedText_WidthIncludingTrailingWhitespace(text);
- double height = OS.FormattedText_Height(text);
- double baseline = OS.FormattedText_Baseline(text);
- OS.GCHandle_Free(text);
- OS.GCHandle_Free(brush);
- OS.GCHandle_Free(culture);
- OS.GCHandle_Free(str);
- return FontMetrics.wpf_new((int)baseline, (int)(height - baseline), (int)width / string.length(), 0, (int)height);
-}
-
-/**
- * Returns the receiver's foreground color.
- *
- * @return the color used for drawing foreground things
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getForeground() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return Color.wpf_new(data.device, data.foreground);
-}
-
-/**
- * Returns the foreground pattern. The default value is
- * <code>null</code>.
- *
- * @return the receiver's foreground pattern
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Pattern
- *
- * @since 3.1
- */
-public Pattern getForegroundPattern() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.foregroundPattern;
-}
-
-/**
- * Returns the GCData.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>GC</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @return the receiver's GCData
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see GCData
- *
- * @since 3.2
- * @noreference This method is not intended to be referenced by clients.
- */
-public GCData getGCData() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data;
-}
-
-/**
- * Returns the receiver's interpolation setting, which will be one of
- * <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>,
- * <code>SWT.LOW</code> or <code>SWT.HIGH</code>.
- *
- * @return the receiver's interpolation setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getInterpolation() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.interpolation;
-}
-
-/**
- * Returns the receiver's line attributes.
- *
- * @return the line attributes used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.3
- */
-public LineAttributes getLineAttributes() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float[] dashes = null;
- if (data.lineDashes != null) {
- dashes = new float[data.lineDashes.length];
- System.arraycopy(data.lineDashes, 0, dashes, 0, dashes.length);
- }
- return new LineAttributes(data.lineWidth, data.lineCap, data.lineJoin, data.lineStyle, dashes, data.lineDashesOffset, data.lineMiterLimit);
-}
-
-/**
- * Returns the receiver's line cap style, which will be one
- * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>,
- * or <code>SWT.CAP_SQUARE</code>.
- *
- * @return the cap style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getLineCap() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineCap;
-}
-
-/**
- * Returns the receiver's line dash style. The default value is
- * <code>null</code>.
- *
- * @return the line dash style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int[] getLineDash() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineDashes == null) return null;
- int[] lineDashes = new int[data.lineDashes.length];
- System.arraycopy(data.lineDashes, 0, lineDashes, 0, lineDashes.length);
- return lineDashes;
-}
-
-/**
- * Returns the receiver's line join style, which will be one
- * of the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>,
- * or <code>SWT.JOIN_BEVEL</code>.
- *
- * @return the join style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getLineJoin() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineJoin;
-}
-
-/**
- * Returns the receiver's line style, which will be one
- * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
- * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or
- * <code>SWT.LINE_DASHDOTDOT</code>.
- *
- * @return the style used for drawing lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineStyle() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineStyle;
-}
-
-/**
- * Returns the width that will be used when drawing lines
- * for all of the figure drawing operations (that is,
- * <code>drawLine</code>, <code>drawRectangle</code>,
- * <code>drawPolyline</code>, and so forth.
- *
- * @return the receiver's line width
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineWidth() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (int)data.lineWidth;
-}
-
-/**
- * Returns the receiver's style information.
- * <p>
- * Note that the value which is returned by this method <em>may
- * not match</em> the value which was provided to the constructor
- * when the receiver was created. This can occur when the underlying
- * operating system does not support a particular combination of
- * requested styles.
- * </p>
- *
- * @return the style bits
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getStyle () {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.style;
-}
-
-/**
- * Returns the receiver's text drawing anti-aliasing setting value,
- * which will be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code>. Note that this controls anti-aliasing
- * <em>only</em> for text drawing operations.
- *
- * @return the anti-aliasing setting
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getAntialias
- *
- * @since 3.1
- */
-public int getTextAntialias() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.textAntialias;
-}
-
-/**
- * Sets the parameter to the transform that is currently being
- * used by the receiver.
- *
- * @param transform the destination to copy the transform into
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Transform
- *
- * @since 3.1
- */
-public void getTransform(Transform transform) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transform == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.transform != 0) {
- OS.MatrixTransform_Matrix(transform.handle, data.transform);
- } else {
- transform.setElements(1, 0, 0, 1, 0, 0);
- }
-}
-
-/**
- * Returns <code>true</code> if this GC is drawing in the mode
- * where the resulting color in the destination is the
- * <em>exclusive or</em> of the color values in the source
- * and the destination, and <code>false</code> if it is
- * drawing in the mode where the destination color is being
- * replaced with the source color value.
- *
- * @return <code>true</code> true if the receiver is in XOR mode, and false otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean getXORMode() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.xorMode;
-}
-
-void init(Drawable drawable, GCData data, int hDC) {
- int foreground = data.foreground;
- if (foreground != -1) data.state &= ~FOREGROUND;
- int background = data.background;
- if (background != 0) data.state &= ~BACKGROUND;
- Font font = data.font;
- if (font != null) data.state &= ~FONT;
- Image image = data.image;
- if (image != null) image.memGC = this;
-// int layout = data.layout;
-// if (layout != -1) {
-// if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
-// int flags = OS.GetLayout(hDC);
-// if ((flags & OS.LAYOUT_RTL) != (layout & OS.LAYOUT_RTL)) {
-// flags &= ~OS.LAYOUT_RTL;
-// OS.SetLayout(hDC, flags | layout);
-// }
-// if ((data.style & SWT.RIGHT_TO_LEFT) != 0) data.style |= SWT.MIRRORED;
-// }
-// }
- this.drawable = drawable;
- this.data = data;
- handle = hDC;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #equals
- */
-public int hashCode () {
- return handle;
-}
-
-/**
- * Returns <code>true</code> if the receiver has a clipping
- * region set into it, and <code>false</code> otherwise.
- * If this method returns false, the receiver will draw on all
- * available space in the destination. If it returns true,
- * it will draw only in the area that is covered by the region
- * that can be accessed with <code>getClipping(region)</code>.
- *
- * @return <code>true</code> if the GC has a clipping region, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean isClipped() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.clip != 0;
-}
-
-/**
- * Returns <code>true</code> if the GC has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the GC.
- * When a GC has been disposed, it is an error to
- * invoke any other method using the GC.
- *
- * @return <code>true</code> when the GC is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Sets the receiver to always use the operating system's advanced graphics
- * subsystem for all graphics operations if the argument is <code>true</code>.
- * If the argument is <code>false</code>, the advanced graphics subsystem is
- * no longer used, advanced graphics state is cleared and the normal graphics
- * subsystem is used from now on.
- * <p>
- * Normally, the advanced graphics subsystem is invoked automatically when
- * any one of the alpha, antialias, patterns, interpolation, paths, clipping
- * or transformation operations in the receiver is requested. When the receiver
- * is switched into advanced mode, the advanced graphics subsystem performs both
- * advanced and normal graphics operations. Because the two subsystems are
- * different, their output may differ. Switching to advanced graphics before
- * any graphics operations are performed ensures that the output is consistent.
- * </p><p>
- * Advanced graphics may not be installed for the operating system. In this
- * case, this operation does nothing. Some operating system have only one
- * graphics subsystem, so switching from normal to advanced graphics does
- * nothing. However, switching from advanced to normal graphics will always
- * clear the advanced graphics state, even for operating systems that have
- * only one graphics subsystem.
- * </p>
- *
- * @param advanced the new advanced graphics state
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAlpha
- * @see #setAntialias
- * @see #setBackgroundPattern
- * @see #setClipping(Path)
- * @see #setForegroundPattern
- * @see #setLineAttributes
- * @see #setInterpolation
- * @see #setTextAntialias
- * @see #setTransform
- * @see #getAdvanced
- *
- * @since 3.1
- */
-public void setAdvanced(boolean advanced) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (!advanced) {
- setAlpha(0xFF);
- setAntialias(SWT.DEFAULT);
- setBackgroundPattern(null);
- setClipping((Rectangle)null);
- setForegroundPattern(null);
- setInterpolation(SWT.DEFAULT);
- setTextAntialias(SWT.DEFAULT);
- setTransform(null);
- }
-}
-
-/**
- * Sets the receiver's anti-aliasing value to the parameter,
- * which must be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code>
- * or <code>SWT.ON</code>. Note that this controls anti-aliasing for all
- * <em>non-text drawing</em> operations.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param antialias the anti-aliasing setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.OFF</code> or <code>SWT.ON</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- * @see #setTextAntialias
- *
- * @since 3.1
- */
-public void setAntialias(int antialias) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (antialias) {
- case SWT.DEFAULT:
- case SWT.OFF:
- case SWT.ON:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.antialias = antialias;
-}
-
-/**
- * Sets the receiver's alpha value which must be
- * between 0 (transparent) and 255 (opaque).
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param alpha the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setAlpha(int alpha) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- data.alpha = alpha & 0xFF;
- data.state &= ~ALPHA;
-}
-
-/**
- * Sets the background color. The background color is used
- * for fill operations and as the background color when text
- * is drawn.
- *
- * @param color the new background color for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setBackground (Color color) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.backgroundPattern == null && data.background == color.handle) return;
- data.backgroundPattern = null;
- data.background = color.handle;
- data.state &= ~BACKGROUND;
-}
-
-/**
- * Sets the background pattern. The default value is <code>null</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param pattern the new background pattern
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Pattern
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setBackgroundPattern (Pattern pattern) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.backgroundPattern == pattern) return;
- data.backgroundPattern = pattern;
- data.state &= ~BACKGROUND;
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the rectangular area specified
- * by the arguments.
- *
- * @param x the x coordinate of the clipping rectangle
- * @param y the y coordinate of the clipping rectangle
- * @param width the width of the clipping rectangle
- * @param height the height of the clipping rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int rect = OS.gcnew_Rect(x, y, width, height);
- int clip = OS.gcnew_RectangleGeometry(rect);
- OS.GCHandle_Free(rect);
- if (data.clip != 0) OS.GCHandle_Free(data.clip);
- data.clip = clip;
- data.state &= ~CLIPPING;
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the path specified
- * by the argument.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param path the clipping path.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the path has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Path
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setClipping (Path path) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path != null && path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.clip != 0) OS.GCHandle_Free(data.clip);
- data.clip = path != null ? OS.Geometry_Clone(path.handle) : 0;
- data.state &= ~CLIPPING;
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the rectangular area specified
- * by the argument. Specifying <code>null</code> for the
- * rectangle reverts the receiver's clipping area to its
- * original value.
- *
- * @param rect the clipping rectangle or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping (Rectangle rect) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) {
- if (data.clip != 0) OS.GCHandle_Free(data.clip);
- data.clip = 0;
- data.state &= ~CLIPPING;
- } else {
- setClipping(rect.x, rect.y, rect.width, rect.height);
- }
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the region specified
- * by the argument. Specifying <code>null</code> for the
- * region reverts the receiver's clipping area to its
- * original value.
- *
- * @param region the clipping region or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setClipping (Region region) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region != null && region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.clip != 0) OS.GCHandle_Free(data.clip);
- data.clip = region != null ? OS.Geometry_Clone(region.handle) : 0;
- data.state &= ~CLIPPING;
-}
-
-/**
- * Sets the receiver's fill rule to the parameter, which must be one of
- * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>.
- *
- * @param rule the new fill rule
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of <code>SWT.FILL_EVEN_ODD</code>
- * or <code>SWT.FILL_WINDING</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setFillRule(int rule) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (rule) {
- case SWT.FILL_WINDING:
- case SWT.FILL_EVEN_ODD: break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.fillRule = rule;
-}
-
-/**
- * Sets the font which will be used by the receiver
- * to draw and measure text to the argument. If the
- * argument is null, then a default font appropriate
- * for the platform will be used instead.
- *
- * @param font the new font for the receiver, or null to indicate a default font
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setFont (Font font) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.font = font != null ? font : data.device.systemFont;
- data.state &= ~FONT;
-}
-
-/**
- * Sets the foreground color. The foreground color is used
- * for drawing operations including when text is drawn.
- *
- * @param color the new foreground color for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setForeground (Color color) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.foregroundPattern == null && color.handle == data.foreground) return;
- data.foregroundPattern = null;
- data.foreground = color.handle;
- data.state &= ~FOREGROUND;
-}
-
-/**
- * Sets the foreground pattern. The default value is <code>null</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param pattern the new foreground pattern
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Pattern
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setForegroundPattern (Pattern pattern) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.foregroundPattern == pattern) return;
- data.foregroundPattern = pattern;
- data.state &= ~FOREGROUND;
-}
-
-/**
- * Sets the receiver's interpolation setting to the parameter, which
- * must be one of <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>,
- * <code>SWT.LOW</code> or <code>SWT.HIGH</code>.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param interpolation the new interpolation setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.NONE</code>, <code>SWT.LOW</code> or <code>SWT.HIGH</code>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setInterpolation(int interpolation) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (interpolation) {
- case SWT.DEFAULT: break;
- case SWT.NONE: break;
- case SWT.LOW: break;
- case SWT.HIGH: break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.interpolation = interpolation;
-}
-
-/**
- * Sets the receiver's line attributes.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * @param attributes the line attributes
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the attributes is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if any of the line attributes is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see LineAttributes
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.3
- */
-public void setLineAttributes(LineAttributes attributes) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (attributes == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int mask = 0;
- float lineWidth = attributes.width;
- if (lineWidth != data.lineWidth) {
- mask |= LINE_WIDTH;
- }
- int lineStyle = attributes.style;
- if (lineStyle != data.lineStyle) {
- mask |= LINE_STYLE;
- switch (lineStyle) {
- case SWT.LINE_SOLID:
- case SWT.LINE_DASH:
- case SWT.LINE_DOT:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- break;
- case SWT.LINE_CUSTOM:
- if (attributes.dash == null) lineStyle = SWT.LINE_SOLID;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- int join = attributes.join;
- if (join != data.lineJoin) {
- mask |= LINE_JOIN;
- switch (join) {
- case SWT.CAP_ROUND:
- case SWT.CAP_FLAT:
- case SWT.CAP_SQUARE:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- int cap = attributes.cap;
- if (cap != data.lineCap) {
- mask |= LINE_CAP;
- switch (cap) {
- case SWT.JOIN_MITER:
- case SWT.JOIN_ROUND:
- case SWT.JOIN_BEVEL:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- float[] dashes = attributes.dash;
- float[] lineDashes = data.lineDashes;
- if (dashes != null && dashes.length > 0) {
- boolean changed = lineDashes == null || lineDashes.length != dashes.length;
- for (int i = 0; i < dashes.length; i++) {
- float dash = dashes[i];
- if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (!changed && lineDashes[i] != dash) changed = true;
- }
- if (changed) {
- float[] newDashes = new float[dashes.length];
- System.arraycopy(dashes, 0, newDashes, 0, dashes.length);
- dashes = newDashes;
- mask |= LINE_STYLE;
- } else {
- dashes = lineDashes;
- }
- } else {
- if (lineDashes != null && lineDashes.length > 0) {
- mask |= LINE_STYLE;
- } else {
- dashes = lineDashes;
- }
- }
- float dashOffset = attributes.dashOffset;
- if (dashOffset != data.lineDashesOffset) {
- mask |= LINE_STYLE;
- }
- float miterLimit = attributes.miterLimit;
- if (miterLimit != data.lineMiterLimit) {
- mask |= LINE_MITERLIMIT;
- }
- if (mask == 0) return;
- data.lineWidth = lineWidth;
- data.lineStyle = lineStyle;
- data.lineCap = cap;
- data.lineJoin = join;
- data.lineDashes = dashes;
- data.lineDashesOffset = dashOffset;
- data.lineMiterLimit = miterLimit;
- data.state &= ~mask;
-}
-
-/**
- * Sets the receiver's line cap style to the argument, which must be one
- * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>,
- * or <code>SWT.CAP_SQUARE</code>.
- *
- * @param cap the cap style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineCap(int cap) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineCap == cap) return;
- switch (cap) {
- case SWT.CAP_ROUND:
- case SWT.CAP_FLAT:
- case SWT.CAP_SQUARE:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineCap = cap;
- data.state &= ~LINE_CAP;
-}
-
-/**
- * Sets the receiver's line dash style to the argument. The default
- * value is <code>null</code>. If the argument is not <code>null</code>,
- * the receiver's line style is set to <code>SWT.LINE_CUSTOM</code>, otherwise
- * it is set to <code>SWT.LINE_SOLID</code>.
- *
- * @param dashes the dash style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if any of the values in the array is less than or equal 0</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineDash(int[] dashes) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float[] lineDashes = data.lineDashes;
- if (dashes != null && dashes.length > 0) {
- boolean changed = data.lineStyle != SWT.LINE_CUSTOM || lineDashes == null || lineDashes.length != dashes.length;
- for (int i = 0; i < dashes.length; i++) {
- int dash = dashes[i];
- if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (!changed && lineDashes[i] != dash) changed = true;
- }
- if (!changed) return;
- data.lineDashes = new float[dashes.length];
- for (int i = 0; i < dashes.length; i++) {
- data.lineDashes[i] = dashes[i];
- }
- data.lineStyle = SWT.LINE_CUSTOM;
- } else {
- if (data.lineStyle == SWT.LINE_SOLID && (lineDashes == null || lineDashes.length == 0)) return;
- data.lineDashes = null;
- data.lineStyle = SWT.LINE_SOLID;
- }
- data.state &= ~LINE_STYLE;
-}
-
-/**
- * Sets the receiver's line join style to the argument, which must be one
- * of the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>,
- * or <code>SWT.JOIN_BEVEL</code>.
- *
- * @param join the join style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLineJoin(int join) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineJoin == join) return;
- switch (join) {
- case SWT.JOIN_MITER:
- case SWT.JOIN_ROUND:
- case SWT.JOIN_BEVEL:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineJoin = join;
- data.state &= ~LINE_JOIN;
-}
-
-/**
- * Sets the receiver's line style to the argument, which must be one
- * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
- * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or
- * <code>SWT.LINE_DASHDOTDOT</code>.
- *
- * @param lineStyle the style to be used for drawing lines
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setLineStyle(int lineStyle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineStyle == lineStyle) return;
- switch (lineStyle) {
- case SWT.LINE_SOLID:
- case SWT.LINE_DASH:
- case SWT.LINE_DOT:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- break;
- case SWT.LINE_CUSTOM:
- if (data.lineDashes == null) lineStyle = SWT.LINE_SOLID;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineStyle = lineStyle;
- data.state &= ~LINE_STYLE;
-}
-
-/**
- * Sets the width that will be used when drawing lines
- * for all of the figure drawing operations (that is,
- * <code>drawLine</code>, <code>drawRectangle</code>,
- * <code>drawPolyline</code>, and so forth.
- * <p>
- * Note that line width of zero is used as a hint to
- * indicate that the fastest possible line drawing
- * algorithms should be used. This means that the
- * output may be different from line width one.
- * </p>
- *
- * @param lineWidth the width of a line
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setLineWidth(int lineWidth) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineWidth == lineWidth) return;
- data.lineWidth = lineWidth;
- data.state &= ~LINE_WIDTH;
- switch (data.lineStyle) {
- case SWT.LINE_DOT:
- case SWT.LINE_DASH:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- data.state &= ~LINE_STYLE;
- }
-}
-
-/**
- * If the argument is <code>true</code>, puts the receiver
- * in a drawing mode where the resulting color in the destination
- * is the <em>exclusive or</em> of the color values in the source
- * and the destination, and if the argument is <code>false</code>,
- * puts the receiver in a drawing mode where the destination color
- * is replaced with the source color value.
- * <p>
- * Note that this mode in fundamentally unsupportable on certain
- * platforms, notably Carbon (Mac OS X). Clients that want their
- * code to run on all platforms need to avoid this method.
- * </p>
- *
- * @param xor if <code>true</code>, then <em>xor</em> mode is used, otherwise <em>source copy</em> mode is used
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @deprecated this functionality is not supported on some platforms
- */
-public void setXORMode(boolean xor) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- data.xorMode = xor;
-}
-
-/**
- * Sets the receiver's text anti-aliasing value to the parameter,
- * which must be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code>
- * or <code>SWT.ON</code>. Note that this controls anti-aliasing only
- * for all <em>text drawing</em> operations.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param antialias the anti-aliasing setting
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one of <code>SWT.DEFAULT</code>,
- * <code>SWT.OFF</code> or <code>SWT.ON</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- * @see #setAntialias
- *
- * @since 3.1
- */
-public void setTextAntialias(int antialias) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (antialias) {
- case SWT.DEFAULT:
- case SWT.OFF:
- case SWT.ON:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.textAntialias = antialias;
-}
-
-/**
- * Sets the transform that is currently being used by the receiver. If
- * the argument is <code>null</code>, the current transform is set to
- * the identity transform.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param transform the transform to set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- *
- * @see Transform
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
-public void setTransform(Transform transform) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transform != null && transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.transform = transform != null ? OS.gcnew_MatrixTransform(transform.handle) : 0;
- data.state &= ~TRANSFORM;
-}
-
-/**
- * Returns the extent of the given string. No tab
- * expansion or carriage return processing will be performed.
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point stringExtent(String string) {
- return textExtent(string, 0);
-}
-
-/**
- * Returns the extent of the given string. Tab expansion and
- * carriage return processing are performed.
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point textExtent(String string) {
- return textExtent(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
-}
-
-/**
- * Returns the extent of the given string. Tab expansion, line
- * delimiter and mnemonic processing are performed according to
- * the specified flags, which can be a combination of:
- * <dl>
- * <dt><b>DRAW_DELIMITER</b></dt>
- * <dd>draw multiple lines</dd>
- * <dt><b>DRAW_TAB</b></dt>
- * <dd>expand tabs</dd>
- * <dt><b>DRAW_MNEMONIC</b></dt>
- * <dd>underline the mnemonic character</dd>
- * <dt><b>DRAW_TRANSPARENT</b></dt>
- * <dd>transparent background</dd>
- * </dl>
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @param flags the flags specifying how to process the text
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point textExtent(String string, int flags) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- checkGC(FONT);
- int length = string.length();
- char [] buffer = new char [length + 1];
- string.getChars (0, length, buffer, 0);
- if ((flags & (SWT.DRAW_DELIMITER | SWT.DRAW_TAB)) != (SWT.DRAW_DELIMITER | SWT.DRAW_TAB)) {
- for (int i = 0, j = 0; i < buffer.length; i++) {
- char c = buffer[i];
- switch (c) {
- case '\r':
- case '\n':
- if ((flags & SWT.DRAW_DELIMITER) == 0) continue;
- break;
- case '\t':
- if ((flags & SWT.DRAW_TAB) == 0) continue;
- break;
- }
- buffer[j++] = c;
- }
- }
- int str = OS.gcnew_String (buffer);
- int culture = OS.CultureInfo_CurrentUICulture();
- Font font = data.font;
- int direction = (data.style & SWT.RIGHT_TO_LEFT) != 0 ? OS.FlowDirection_RightToLeft : OS.FlowDirection_LeftToRight;
- int brush = OS.Brushes_White();
- int text = OS.gcnew_FormattedText(str, culture, direction, font.handle, font.size, brush);
- double width = OS.FormattedText_WidthIncludingTrailingWhitespace(text);
- double height = OS.FormattedText_Height(text);
- OS.GCHandle_Free(text);
- OS.GCHandle_Free(brush);
- OS.GCHandle_Free(culture);
- OS.GCHandle_Free(str);
- return new Point((int)width, (int)height);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "GC {*DISPOSED*}";
- return "GC {" + handle + "}";
-}
-
-/**
- * Invokes platform specific functionality to allocate a new graphics context.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>GC</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param drawable the Drawable for the receiver.
- * @param data the data for the receiver.
- *
- * @return a new <code>GC</code>
- */
-public static GC wpf_new(Drawable drawable, GCData data) {
- GC gc = new GC();
- int hDC = drawable.internal_new_GC(data);
- gc.device = data.device;
- gc.init(drawable, data, hDC);
- return gc;
-}
-
-/**
- * Invokes platform specific functionality to wrap a graphics context.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>GC</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the Windows HDC.
- * @param data the data for the receiver.
- *
- * @return a new <code>GC</code>
- */
-public static GC wpf_new(int hDC, GCData data) {
- GC gc = new GC();
- gc.device = data.device;
- gc.init(null, data, hDC);
- return gc;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/GCData.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/GCData.java
deleted file mode 100644
index e6ad4772c7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/GCData.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class are descriptions of GCs in terms
- * of unallocated platform-specific data fields.
- * <p>
- * <b>IMPORTANT:</b> This class is <em>not</em> part of the public
- * API for SWT. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms, and should never be called from application code.
- * </p>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noinstantiate This class is not intended to be instantiated by clients.
- */
-
-public final class GCData {
- public Device device;
- public int style, state = -1;
- public int foreground;
- public int background;
- public Font font;
- public Pattern foregroundPattern;
- public Pattern backgroundPattern;
- public boolean xorMode;
- public int fillRule = SWT.FILL_EVEN_ODD;
- public int interpolation = SWT.DEFAULT;
- public int antialias = SWT.DEFAULT;
- public int textAntialias = SWT.DEFAULT;
- public int lineStyle = SWT.LINE_SOLID;
- public float lineWidth;
- public int lineCap = SWT.CAP_FLAT;
- public int lineJoin = SWT.JOIN_MITER;
- public float lineDashesOffset;
- public float[] lineDashes;
- public float lineMiterLimit = 10;
- public int alpha = 0xFF;
-
- public Image image;
- public int pen;
- public int brush, currentBrush;
- public int pushCount;
- public int clip;
- public int transform;
- public int visual;
- public int drawingContext;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Image.java
deleted file mode 100644
index 90366cfe19..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Image.java
+++ /dev/null
@@ -1,1127 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-
-import java.io.*;
-
-/**
- * Instances of this class are graphics which have been prepared
- * for display on a specific device. That is, they are ready
- * to paint using methods such as <code>GC.drawImage()</code>
- * and display on widgets with, for example, <code>Button.setImage()</code>.
- * <p>
- * If loaded from a file format that supports it, an
- * <code>Image</code> may have transparency, meaning that certain
- * pixels are specified as being transparent when drawn. Examples
- * of file formats that support transparency are GIF and PNG.
- * </p><p>
- * There are two primary ways to use <code>Images</code>.
- * The first is to load a graphic file from disk and create an
- * <code>Image</code> from it. This is done using an <code>Image</code>
- * constructor, for example:
- * <pre>
- * Image i = new Image(device, "C:\\graphic.bmp");
- * </pre>
- * A graphic file may contain a color table specifying which
- * colors the image was intended to possess. In the above example,
- * these colors will be mapped to the closest available color in
- * SWT. It is possible to get more control over the mapping of
- * colors as the image is being created, using code of the form:
- * <pre>
- * ImageData data = new ImageData("C:\\graphic.bmp");
- * RGB[] rgbs = data.getRGBs();
- * // At this point, rgbs contains specifications of all
- * // the colors contained within this image. You may
- * // allocate as many of these colors as you wish by
- * // using the Color constructor Color(RGB), then
- * // create the image:
- * Image i = new Image(device, data);
- * </pre>
- * <p>
- * Applications which require even greater control over the image
- * loading process should use the support provided in class
- * <code>ImageLoader</code>.
- * </p><p>
- * Application code must explicitly invoke the <code>Image.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see Color
- * @see ImageData
- * @see ImageLoader
- * @see <a href="http://www.eclipse.org/swt/snippets/#image">Image snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, ImageAnalyzer</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class Image extends Resource implements Drawable {
-
- /**
- * specifies whether the receiver is a bitmap or an icon
- * (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int type;
-
- /**
- * the handle to the OS image resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
- /**
- * specifies the transparent pixel
- */
- int transparentPixel = -1;
-
- /**
- * the GC which is drawing on the image
- */
- GC memGC;
-
- /**
- * the alpha data for the image
- */
- byte[] alphaData;
-
- /**
- * the global alpha value to be used for every pixel
- */
- int alpha = -1;
-
- /**
- * the image data used to create this image if it is a
- * icon. Used only in WinCE
- */
- ImageData data;
-
- /**
- * width of the image
- */
- int width = -1;
-
- /**
- * height of the image
- */
- int height = -1;
-
- /**
- * specifies the default scanline padding
- */
- static final int DEFAULT_SCANLINE_PAD = 4;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Image (Device device) {
- super(device);
-}
-
-/**
- * Constructs an empty instance of this class with the
- * specified width and height. The result may be drawn upon
- * by creating a GC and using any of its drawing operations,
- * as shown in the following example:
- * <pre>
- * Image i = new Image(device, width, height);
- * GC gc = new GC(i);
- * gc.drawRectangle(0, 0, 50, 50);
- * gc.dispose();
- * </pre>
- * <p>
- * Note: Some platforms may have a limitation on the size
- * of image that can be created (size depends on width, height,
- * and depth). For example, Windows 95, 98, and ME do not allow
- * images larger than 16M.
- * </p>
- *
- * @param device the device on which to create the image
- * @param width the width of the new image
- * @param height the height of the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - if either the width or height is negative or zero</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, int width, int height) {
- super(device);
- init(width, height);
- init();
-}
-
-/**
- * Constructs a new instance of this class based on the
- * provided image, with an appearance that varies depending
- * on the value of the flag. The possible flag values are:
- * <dl>
- * <dt><b>{@link SWT#IMAGE_COPY}</b></dt>
- * <dd>the result is an identical copy of srcImage</dd>
- * <dt><b>{@link SWT#IMAGE_DISABLE}</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>disabled</em> look</dd>
- * <dt><b>{@link SWT#IMAGE_GRAY}</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>gray scale</em> look</dd>
- * </dl>
- *
- * @param device the device on which to create the image
- * @param srcImage the image to use as the source
- * @param flag the style, either <code>IMAGE_COPY</code>, <code>IMAGE_DISABLE</code> or <code>IMAGE_GRAY</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if srcImage is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the flag is not one of <code>IMAGE_COPY</code>, <code>IMAGE_DISABLE</code> or <code>IMAGE_GRAY</code></li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon, or is otherwise in an invalid state</li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the image is not supported</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, Image srcImage, int flag) {
- super(device);
- device = this.device;
- if (srcImage == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (srcImage.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Rectangle rect = srcImage.getBounds();
- switch (flag) {
- case SWT.IMAGE_COPY: {
- type = srcImage.type;
- handle = OS.BitmapSource_Clone(srcImage.handle);
- transparentPixel = srcImage.transparentPixel;
- alpha = srcImage.alpha;
- if (srcImage.alphaData != null) {
- alphaData = new byte[srcImage.alphaData.length];
- System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length);
- }
- break;
- }
- case SWT.IMAGE_DISABLE: {
- ImageData data = srcImage.getImageData();
- PaletteData palette = data.palette;
- RGB[] rgbs = new RGB[3];
- rgbs[0] = device.getSystemColor(SWT.COLOR_BLACK).getRGB();
- rgbs[1] = device.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW).getRGB();
- rgbs[2] = device.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND).getRGB();
- ImageData newData = new ImageData(rect.width, rect.height, 8, new PaletteData(rgbs));
- newData.alpha = data.alpha;
- newData.alphaData = data.alphaData;
- newData.maskData = data.maskData;
- newData.maskPad = data.maskPad;
- if (data.transparentPixel != -1) newData.transparentPixel = 0;
-
- /* Convert the pixels. */
- int[] scanline = new int[rect.width];
- int[] maskScanline = null;
- ImageData mask = null;
- if (data.maskData != null) mask = data.getTransparencyMask();
- if (mask != null) maskScanline = new int[rect.width];
- int redMask = palette.redMask;
- int greenMask = palette.greenMask;
- int blueMask = palette.blueMask;
- int redShift = palette.redShift;
- int greenShift = palette.greenShift;
- int blueShift = palette.blueShift;
- for (int y=0; y<rect.height; y++) {
- int offset = y * newData.bytesPerLine;
- data.getPixels(0, y, rect.width, scanline, 0);
- if (mask != null) mask.getPixels(0, y, rect.width, maskScanline, 0);
- for (int x=0; x<rect.width; x++) {
- int pixel = scanline[x];
- if (!(pixel == data.transparentPixel || (mask != null && maskScanline[x] == 0))) {
- int red, green, blue;
- if (palette.isDirect) {
- red = pixel & redMask;
- red = (redShift < 0) ? red >>> -redShift : red << redShift;
- green = pixel & greenMask;
- green = (greenShift < 0) ? green >>> -greenShift : green << greenShift;
- blue = pixel & blueMask;
- blue = (blueShift < 0) ? blue >>> -blueShift : blue << blueShift;
- } else {
- red = palette.colors[pixel].red;
- green = palette.colors[pixel].green;
- blue = palette.colors[pixel].blue;
- }
- int intensity = red * red + green * green + blue * blue;
- if (intensity < 98304) {
- newData.data[offset] = (byte)1;
- } else {
- newData.data[offset] = (byte)2;
- }
- }
- offset++;
- }
- }
- init (newData);
- break;
- }
- case SWT.IMAGE_GRAY: {
- ImageData data = srcImage.getImageData();
- PaletteData palette = data.palette;
- ImageData newData = data;
- if (!palette.isDirect) {
- /* Convert the palette entries to gray. */
- RGB [] rgbs = palette.getRGBs();
- for (int i=0; i<rgbs.length; i++) {
- if (data.transparentPixel != i) {
- RGB color = rgbs [i];
- int red = color.red;
- int green = color.green;
- int blue = color.blue;
- int intensity = (red+red+green+green+green+green+green+blue) >> 3;
- color.red = color.green = color.blue = intensity;
- }
- }
- newData.palette = new PaletteData(rgbs);
- } else {
- /* Create a 8 bit depth image data with a gray palette. */
- RGB[] rgbs = new RGB[256];
- for (int i=0; i<rgbs.length; i++) {
- rgbs[i] = new RGB(i, i, i);
- }
- newData = new ImageData(rect.width, rect.height, 8, new PaletteData(rgbs));
- newData.alpha = data.alpha;
- newData.alphaData = data.alphaData;
- newData.maskData = data.maskData;
- newData.maskPad = data.maskPad;
- if (data.transparentPixel != -1) newData.transparentPixel = 254;
-
- /* Convert the pixels. */
- int[] scanline = new int[rect.width];
- int redMask = palette.redMask;
- int greenMask = palette.greenMask;
- int blueMask = palette.blueMask;
- int redShift = palette.redShift;
- int greenShift = palette.greenShift;
- int blueShift = palette.blueShift;
- for (int y=0; y<rect.height; y++) {
- int offset = y * newData.bytesPerLine;
- data.getPixels(0, y, rect.width, scanline, 0);
- for (int x=0; x<rect.width; x++) {
- int pixel = scanline[x];
- if (pixel != data.transparentPixel) {
- int red = pixel & redMask;
- red = (redShift < 0) ? red >>> -redShift : red << redShift;
- int green = pixel & greenMask;
- green = (greenShift < 0) ? green >>> -greenShift : green << greenShift;
- int blue = pixel & blueMask;
- blue = (blueShift < 0) ? blue >>> -blueShift : blue << blueShift;
- int intensity = (red+red+green+green+green+green+green+blue) >> 3;
- if (newData.transparentPixel == intensity) intensity = 255;
- newData.data[offset] = (byte)intensity;
- } else {
- newData.data[offset] = (byte)254;
- }
- offset++;
- }
- }
- }
- init (newData);
- break;
- }
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- init();
-}
-
-/**
- * Constructs an empty instance of this class with the
- * width and height of the specified rectangle. The result
- * may be drawn upon by creating a GC and using any of its
- * drawing operations, as shown in the following example:
- * <pre>
- * Image i = new Image(device, boundsRectangle);
- * GC gc = new GC(i);
- * gc.drawRectangle(0, 0, 50, 50);
- * gc.dispose();
- * </pre>
- * <p>
- * Note: Some platforms may have a limitation on the size
- * of image that can be created (size depends on width, height,
- * and depth). For example, Windows 95, 98, and ME do not allow
- * images larger than 16M.
- * </p>
- *
- * @param device the device on which to create the image
- * @param bounds a rectangle specifying the image's width and height (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the bounds rectangle is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, Rectangle bounds) {
- super(device);
- if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(bounds.width, bounds.height);
- init();
-}
-
-/**
- * Constructs an instance of this class from the given
- * <code>ImageData</code>.
- *
- * @param device the device on which to create the image
- * @param data the image data to create the image from (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the image data is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the ImageData is not supported</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, ImageData data) {
- super(device);
- init(data);
- init();
-}
-
-/**
- * Constructs an instance of this class, whose type is
- * <code>SWT.ICON</code>, from the two given <code>ImageData</code>
- * objects. The two images must be the same size. Pixel transparency
- * in either image will be ignored.
- * <p>
- * The mask image should contain white wherever the icon is to be visible,
- * and black wherever the icon is to be transparent. In addition,
- * the source image should contain black wherever the icon is to be
- * transparent.
- * </p>
- *
- * @param device the device on which to create the icon
- * @param source the color data for the icon
- * @param mask the mask data for the icon
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if either the source or mask is null </li>
- * <li>ERROR_INVALID_ARGUMENT - if source and mask are different sizes</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image(Device device, ImageData source, ImageData mask) {
- super(device);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (mask == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (source.width != mask.width || source.height != mask.height) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- mask = ImageData.convertMask (mask);
- ImageData image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad, source.data);
- image.maskPad = mask.scanlinePad;
- image.maskData = mask.data;
- init(image);
- init();
-}
-
-/**
- * Constructs an instance of this class by loading its representation
- * from the specified input stream. Throws an error if an error
- * occurs while loading the image, or if the result is an image
- * of an unsupported type. Application code is still responsible
- * for closing the input stream.
- * <p>
- * This constructor is provided for convenience when loading a single
- * image only. If the stream contains multiple images, only the first
- * one will be loaded. To load multiple images, use
- * <code>ImageLoader.load()</code>.
- * </p><p>
- * This constructor may be used to load a resource as follows:
- * </p>
- * <pre>
- * static Image loadImage (Display display, Class clazz, String string) {
- * InputStream stream = clazz.getResourceAsStream (string);
- * if (stream == null) return null;
- * Image image = null;
- * try {
- * image = new Image (display, stream);
- * } catch (SWTException ex) {
- * } finally {
- * try {
- * stream.close ();
- * } catch (IOException ex) {}
- * }
- * return image;
- * }
- * </pre>
- *
- * @param device the device on which to create the image
- * @param stream the input stream to load the image from
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the stream is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from the stream</li>
- * <li>ERROR_INVALID_IMAGE - if the image stream contains invalid data </li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the image stream describes an image with an unsupported depth</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image (Device device, InputStream stream) {
- super(device);
- init(new ImageData(stream));
- init();
-}
-
-/**
- * Constructs an instance of this class by loading its representation
- * from the file with the specified name. Throws an error if an error
- * occurs while loading the image, or if the result is an image
- * of an unsupported type.
- * <p>
- * This constructor is provided for convenience when loading
- * a single image only. If the specified file contains
- * multiple images, only the first one will be used.
- *
- * @param device the device on which to create the image
- * @param filename the name of the file to load the image from
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the file name is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from the file</li>
- * <li>ERROR_INVALID_IMAGE - if the image file contains invalid data </li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the image file describes an image with an unsupported depth</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
- */
-public Image (Device device, String filename) {
- super(device);
- if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- try {
- handle = OS.gcnew_BitmapImage();
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int length = filename.length();
- char[] chars = new char[length + 1];
- filename.getChars(0, length, chars, 0);
- int str = OS.gcnew_String(chars);
- if (str == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (!OS.File_Exists(str)) SWT.error(SWT.ERROR_IO);
- int uri = OS.gcnew_Uri(str, OS.UriKind_RelativeOrAbsolute);
- if (uri == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.BitmapImage_BeginInit(handle);
- OS.BitmapImage_CreateOptions(handle, OS.BitmapCreateOptions_PreservePixelFormat);
- OS.BitmapImage_UriSource(handle, uri);
- OS.BitmapImage_EndInit(handle);
- if (OS.Freezable_CanFreeze(handle)) OS.Freezable_Freeze(handle);
- OS.GCHandle_Free(uri);
- OS.GCHandle_Free(str);
- return;
- } catch (SWTException e) {}
- init(new ImageData(filename));
- init();
-}
-
-void destroy() {
- if (memGC != null) memGC.dispose();
- OS.GCHandle_Free(handle);
- handle = 0;
- memGC = null;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Image)) return false;
- Image image = (Image) object;
- return device == image.device && handle == image.handle;
-}
-
-/**
- * Returns the color to which to map the transparent pixel, or null if
- * the receiver has no transparent pixel.
- * <p>
- * There are certain uses of Images that do not support transparency
- * (for example, setting an image into a button or label). In these cases,
- * it may be desired to simulate transparency by using the background
- * color of the widget to paint the transparent pixels of the image.
- * Use this method to check which color will be used in these cases
- * in place of transparency. This value may be set with setBackground().
- * <p>
- *
- * @return the background color of the image, or null if there is no transparency in the image
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Color getBackground() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transparentPixel == -1) return null;
- //TODO implement Image.getBackground()
- return null;
-}
-
-/**
- * Returns the bounds of the receiver. The rectangle will always
- * have x and y values of 0, and the width and height of the
- * image.
- *
- * @return a rectangle specifying the image's bounds
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li>
- * </ul>
- */
-public Rectangle getBounds() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width == -1 || height == -1) {
- width = OS.BitmapSource_PixelWidth(handle);
- height = OS.BitmapSource_PixelHeight(handle);
- }
- return new Rectangle(0, 0, width, height);
-}
-
-Point getDPI () {
- //TODO
- return new Point (96, 96);
-}
-
-/**
- * Returns an <code>ImageData</code> based on the receiver
- * Modifications made to this <code>ImageData</code> will not
- * affect the Image.
- *
- * @return an <code>ImageData</code> containing the image's data and attributes
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li>
- * </ul>
- *
- * @see ImageData
- */
-public ImageData getImageData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int format = OS.BitmapSource_Format(handle);
- int depth = OS.PixelFormat_BitsPerPixel(format);
- int width = OS.BitmapSource_PixelWidth(handle);
- int height = OS.BitmapSource_PixelHeight(handle);
- int scanlinePad = DEFAULT_SCANLINE_PAD;
- int bytesPerLine = (((width * depth + 7) / 8) + (scanlinePad - 1)) / scanlinePad * scanlinePad;
- byte[] buffer = new byte[bytesPerLine * height];
- int rect = OS.Int32Rect_Empty();
- OS.BitmapSource_CopyPixels(handle, rect, buffer, buffer.length, bytesPerLine);
- OS.GCHandle_Free(rect);
- PaletteData paletteData = null;
- int palette = OS.BitmapSource_Palette(handle);
- if (palette != 0) {
- int colors = OS.BitmapPalette_Colors(palette);
- int count = OS.ColorList_Count(colors);
- RGB[] rgbs = new RGB[count];
- paletteData = new PaletteData(rgbs);
- if (count != 0) {
- int index = 0;
- int enumerator = OS.ColorList_GetEnumerator(colors);
- while (OS.IEnumerator_MoveNext(enumerator)) {
- int color = OS.ColorList_Current(enumerator);
- rgbs[index++] = new RGB(OS.Color_R(color) & 0xFF, OS.Color_G(color) & 0xFF, OS.Color_B(color) & 0xFF);
- OS.GCHandle_Free(color);
- }
- OS.GCHandle_Free(enumerator);
- }
- OS.GCHandle_Free(colors);
- OS.GCHandle_Free(palette);
- } else {
- int[] formats = {
- OS.PixelFormats_Bgr555(),
- OS.PixelFormats_Bgr565(),
- OS.PixelFormats_Bgr24(),
- OS.PixelFormats_Rgb24(),
- OS.PixelFormats_Bgr32(),
- OS.PixelFormats_Bgra32(),
- OS.PixelFormats_Pbgra32(),
- OS.PixelFormats_Bgr101010(),
- };
- for (int i = 0; i < formats.length; i++) {
- if (OS.Object_Equals(format, formats[i])) {
- switch (i) {
- case 0: paletteData = new PaletteData(0x7C00, 0x3E0, 0x1F); break;
- case 1: paletteData = new PaletteData(0xF800, 0x7E0, 0x1F); break;
- case 2: paletteData = new PaletteData(0xFF, 0xFF00, 0xFF0000); break;
- case 3: paletteData = new PaletteData(0xFF0000, 0xFF00, 0xFF); break;
- case 4:
- case 5:
- case 6: paletteData = new PaletteData(0xFF00, 0xFF0000, 0xFF000000); break;
- case 7: paletteData = new PaletteData(0x3FF, 0xFFC00, 0x3FF0000); break;
- }
- }
- OS.GCHandle_Free(formats[i]);
- }
- }
- OS.GCHandle_Free(format);
- ImageData data = new ImageData(width, height, depth, paletteData, scanlinePad, buffer);
- data.transparentPixel = transparentPixel;
- if (transparentPixel == -1 && type == SWT.ICON) {
- /* Get the icon mask data */
- int maskPad = 2;
- int maskBpl = (((width + 7) / 8) + (maskPad - 1)) / maskPad * maskPad;
- byte[] maskData = new byte[height * maskBpl];
- int offset = 3, maskOffset = 0;
- for (int y = 0; y<height; y++) {
- for (int x = 0; x<width; x++) {
- if (buffer[offset] != 0) {
- maskData[maskOffset + (x >> 3)] |= (1 << (7 - (x & 0x7)));
- } else {
- maskData[maskOffset + (x >> 3)] &= ~(1 << (7 - (x & 0x7)));
- }
- offset += 4;
- }
- maskOffset += maskBpl;
- }
- data.maskData = maskData;
- data.maskPad = maskPad;
- }
- data.alpha = alpha;
- if (alpha == -1 && alphaData != null) {
- data.alphaData = new byte[alphaData.length];
- System.arraycopy(alphaData, 0, data.alphaData, 0, alphaData.length);
- }
- return data;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return handle;
-}
-
-void init(int width, int height) {
- if (width <= 0 || height <= 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- type = SWT.BITMAP;
- Point dpi = getDPI();
- int pixelFormat = OS.PixelFormats_Bgr24();
- int stride = width * 3;
- byte[] buffer = new byte[stride * height];
- for (int i = 0; i < buffer.length; i++) {
- buffer[i] = (byte)0xFF;
- }
- handle = OS.BitmapSource_Create(width, height, dpi.x, dpi.y, pixelFormat, 0, buffer, buffer.length, stride);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.GCHandle_Free(pixelFormat);
- if (OS.Freezable_CanFreeze(handle)) OS.Freezable_Freeze(handle);
-}
-
-void init(ImageData data) {
- PaletteData palette = data.palette;
- if (!(((data.depth == 1 || data.depth == 2 || data.depth == 4 || data.depth == 8) && !palette.isDirect) ||
- ((data.depth == 8) || (data.depth == 16 || data.depth == 24 || data.depth == 32) && palette.isDirect)))
- SWT.error (SWT.ERROR_UNSUPPORTED_DEPTH);
- int width = data.width;
- int height = data.height;
- int redMask = palette.redMask;
- int greenMask = palette.greenMask;
- int blueMask = palette.blueMask;
- ImageData newData = null;
- int pixelFormat = 0;
- boolean transparent = false;
- if (data.maskData != null) {
- transparent= true;
- } else {
- if (data.transparentPixel != -1) {
- transparent = palette.isDirect;
- } else {
- if (data.alpha != -1) {
- transparent = palette.isDirect;
- } else {
- transparent = data.alphaData != null;
- }
- }
- }
- if (transparent) {
- pixelFormat = OS.PixelFormats_Bgra32();
- if (!(palette.isDirect && data.depth == 32 && redMask == 0xFF00 && greenMask == 0xFF0000 && blueMask == 0xFF000000)) {
- newData = new ImageData(width, height, 32, new PaletteData(0xFF00, 0xFF0000, 0xFF000000));
- }
- } else {
- switch (data.depth) {
- case 1: pixelFormat = OS.PixelFormats_Indexed1(); break;
- case 2: pixelFormat = OS.PixelFormats_Indexed2(); break;
- case 4: pixelFormat = OS.PixelFormats_Indexed4(); break;
- case 8:
- if (!palette.isDirect) {
- pixelFormat = OS.PixelFormats_Indexed8();
- } else {
- pixelFormat = OS.PixelFormats_Bgr32();
- newData = new ImageData(data.width, data.height, 32, new PaletteData(0xFF00, 0xFF0000, 0xFF000000));
- }
- break;
- case 16:
- if (redMask == 0x7C00 && greenMask == 0x3E0 && blueMask == 0x1F) {
- pixelFormat = OS.PixelFormats_Bgr555();
- } else if (redMask == 0xF800 && greenMask == 0x7E0 && blueMask == 0x1F) {
- pixelFormat = OS.PixelFormats_Bgr565();
- } else {
- pixelFormat = OS.PixelFormats_Bgr555();
- newData = new ImageData(data.width, data.height, 16, new PaletteData(0x7C00, 0x3E0, 0x1F));
- }
- break;
- case 24:
- if (redMask == 0xFF && greenMask == 0xFF00 && blueMask == 0xFF0000) {
- pixelFormat = OS.PixelFormats_Bgr24();
- } else if (redMask == 0xFF0000 && greenMask == 0xFF00 && blueMask == 0xFF) {
- pixelFormat = OS.PixelFormats_Rgb24();
- } else {
- pixelFormat = OS.PixelFormats_Bgr24();
- newData = new ImageData(data.width, data.height, 24, new PaletteData(0xFF, 0xFF00, 0xFF0000));
- }
- break;
- case 32:
- if (redMask == 0x3FF && greenMask == 0xFFC00 && blueMask == 0x3FF0000) {
- pixelFormat = OS.PixelFormats_Bgr101010();
- } else if (redMask == 0xFF00 && greenMask == 0xFF0000 && blueMask == 0xFF000000) {
- pixelFormat = OS.PixelFormats_Bgr32();
- } else {
- pixelFormat = OS.PixelFormats_Bgr32();
- newData = new ImageData(data.width, data.height, 32, new PaletteData(0xFF00, 0xFF0000, 0xFF000000));
- }
- break;
- }
- }
- if (newData != null) {
- PaletteData newPalette = newData.palette;
- if (palette.isDirect) {
- ImageData.blit(ImageData.BLIT_SRC,
- data.data, data.depth, data.bytesPerLine, data.getByteOrder(), 0, 0, width, height, redMask, greenMask, blueMask,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- newData.data, newData.depth, newData.bytesPerLine, newData.getByteOrder(), 0, 0, width, height, newPalette.redMask, newPalette.greenMask, newPalette.blueMask,
- false, false);
- } else {
- RGB[] rgbs = palette.getRGBs();
- int length = rgbs.length;
- byte[] srcReds = new byte[length];
- byte[] srcGreens = new byte[length];
- byte[] srcBlues = new byte[length];
- for (int i = 0; i < rgbs.length; i++) {
- RGB rgb = rgbs[i];
- if (rgb == null) continue;
- srcReds[i] = (byte)rgb.red;
- srcGreens[i] = (byte)rgb.green;
- srcBlues[i] = (byte)rgb.blue;
- }
- ImageData.blit(ImageData.BLIT_SRC,
- data.data, data.depth, data.bytesPerLine, data.getByteOrder(), 0, 0, width, height, srcReds, srcGreens, srcBlues,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- newData.data, newData.depth, newData.bytesPerLine, newData.getByteOrder(), 0, 0, width, height, newPalette.redMask, newPalette.greenMask, newPalette.blueMask,
- false, false);
- }
- if (data.transparentPixel != -1) {
- newData.transparentPixel = newPalette.getPixel(palette.getRGB(data.transparentPixel));
- }
- newData.maskPad = data.maskPad;
- newData.maskData = data.maskData;
- newData.alpha = data.alpha;
- newData.alphaData = data.alphaData;
- data = newData;
- palette = data.palette;
- }
- int bitmapPalette = 0;
- if (!palette.isDirect) {
- if (data.transparentPixel != -1) {
- transparentPixel = data.transparentPixel;
- } else {
- alpha = data.alpha;
- }
- RGB[] rgbs = palette.colors;
- int list = OS.gcnew_ColorList(rgbs.length);
- for (int i = 0; i < rgbs.length; i++) {
- RGB rgb = rgbs[i];
- byte alpha;
- if (data.transparentPixel != -1) {
- alpha = (byte)(i == data.transparentPixel ? 0 : 0xFF);
- } else {
- alpha = (byte)(data.alpha & 0xFF);
- }
- int color = OS.Color_FromArgb(alpha, (byte)rgb.red, (byte)rgb.green, (byte)rgb.blue);
- OS.ColorList_Add(list, color);
- OS.GCHandle_Free(color);
- }
- bitmapPalette = OS.gcnew_BitmapPalette(list);
- OS.GCHandle_Free(list);
- }
- type = SWT.BITMAP;
- if (transparent) {
- if (data.maskData != null || data.transparentPixel != -1) {
- this.type = data.transparentPixel != -1 ? SWT.BITMAP : SWT.ICON;
- transparentPixel = data.transparentPixel;
- ImageData maskImage = data.getTransparencyMask();
- byte[] maskData = maskImage.data;
- int maskBpl = maskImage.bytesPerLine;
- int offset = 3, maskOffset = 0;
- for (int y = 0; y<height; y++) {
- for (int x = 0; x<width; x++) {
- data.data[offset] = ((maskData[maskOffset + (x >> 3)]) & (1 << (7 - (x & 0x7)))) != 0 ? (byte)0xff : 0;
- offset += 4;
- }
- maskOffset += maskBpl;
- }
- } else if (data.alpha != -1) {
- alpha = data.alpha;
- for (int i = 3, j = 0; i < data.data.length; i+=4, j++) {
- data.data[i] = (byte)alpha;
- }
- } else {
- int length = data.alphaData.length;
- alphaData = new byte[length];
- System.arraycopy(data.alphaData, 0, alphaData, 0, length);
- for (int i = 3, j = 0; i < data.data.length; i+=4, j++) {
- data.data[i] = alphaData[j];
- }
- }
- }
- Point dpi = getDPI();
- handle = OS.BitmapSource_Create(width, height, dpi.x, dpi.y, pixelFormat, bitmapPalette, data.data, data.data.length, data.bytesPerLine);
- if (OS.Freezable_CanFreeze(handle)) OS.Freezable_Freeze(handle);
- OS.GCHandle_Free(pixelFormat);
- if (bitmapPalette != 0) OS.GCHandle_Free(bitmapPalette);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public int internal_new_GC (GCData data) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- /*
- * Create a new GC that can draw into the image.
- * Only supported for bitmaps.
- */
- if (type != SWT.BITMAP || memGC != null) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (width == -1 || height == -1) {
- width = OS.BitmapSource_PixelWidth(handle);
- height = OS.BitmapSource_PixelHeight(handle);
- }
-
- int visual = OS.gcnew_DrawingVisual();
- if (visual == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int rect = OS.gcnew_Rect(0, 0, width, height);
- int geometry = OS.gcnew_RectangleGeometry(rect);
- OS.ContainerVisual_Clip (visual, geometry);
- int dc = OS.DrawingVisual_RenderOpen(visual);
- if (dc == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.DrawingContext_DrawImage(dc, handle, rect);
- OS.GCHandle_Free(rect);
- OS.GCHandle_Free(geometry);
- if (data != null) {
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) == 0) {
- data.style |= SWT.LEFT_TO_RIGHT;
- }
- data.device = device;
- data.image = this;
- data.background = OS.Colors_White;
- data.foreground = OS.Colors_Black;
- data.font = device.systemFont;
- data.visual = visual;
- }
- return dc;
-}
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int dc, GCData data) {
- OS.DrawingContext_Close(dc);
- Point dpi = getDPI();
- int pixelFormat = OS.PixelFormats_Pbgra32();
- int renderHandle = OS.gcnew_RenderTargetBitmap(width, height, dpi.x, dpi.y, pixelFormat);
- OS.GCHandle_Free(pixelFormat);
- if (renderHandle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.RenderTargetBitmap_Render(renderHandle, data.visual);
- OS.GCHandle_Free(data.visual);
- OS.GCHandle_Free(dc);
- int format = OS.BitmapSource_Format(handle);
- int palette = OS.BitmapSource_Palette(handle);
- OS.GCHandle_Free(handle);
- handle = OS.gcnew_FormatConvertedBitmap(renderHandle, format, palette, 100);
- OS.GCHandle_Free(palette);
- OS.GCHandle_Free(format);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.GCHandle_Free(renderHandle);
- if (OS.Freezable_CanFreeze(handle)) OS.Freezable_Freeze(handle);
-}
-
-/**
- * Returns <code>true</code> if the image has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the image.
- * When an image has been disposed, it is an error to
- * invoke any other method using the image.
- *
- * @return <code>true</code> when the image is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Sets the color to which to map the transparent pixel.
- * <p>
- * There are certain uses of <code>Images</code> that do not support
- * transparency (for example, setting an image into a button or label).
- * In these cases, it may be desired to simulate transparency by using
- * the background color of the widget to paint the transparent pixels
- * of the image. This method specifies the color that will be used in
- * these cases. For example:
- * <pre>
- * Button b = new Button();
- * image.setBackground(b.getBackground());
- * b.setImage(image);
- * </pre>
- * </p><p>
- * The image may be modified by this operation (in effect, the
- * transparent regions may be filled with the supplied color). Hence
- * this operation is not reversible and it is not legal to call
- * this function twice or with a null argument.
- * </p><p>
- * This method has no effect if the receiver does not have a transparent
- * pixel value.
- * </p>
- *
- * @param color the color to use when a transparent pixel is specified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setBackground(Color color) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (transparentPixel == -1) return;
- //TODO implement Image.setBackground()
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Image {*DISPOSED*}";
- return "Image {" + handle + "}";
-}
-
-/**
- * Invokes platform specific functionality to allocate a new image.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Image</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the color
- * @param type the type of the image (<code>SWT.BITMAP</code> or <code>SWT.ICON</code>)
- * @param handle the OS handle for the image
- * @return a new image object containing the specified device, type and handle
- */
-public static Image wpf_new(Device device, int type, int handle) {
- Image image = new Image(device);
- image.type = type;
- image.handle = handle;
- return image;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Path.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Path.java
deleted file mode 100644
index 420d66fc52..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Path.java
+++ /dev/null
@@ -1,695 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.wpf.*;
-
-/**
- * Instances of this class represent paths through the two-dimensional
- * coordinate system. Paths do not have to be continuous, and can be
- * described using lines, rectangles, arcs, cubic or quadratic bezier curves,
- * glyphs, or other paths.
- * <p>
- * Application code must explicitly invoke the <code>Path.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#path">Path, Pattern snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Path extends Resource {
-
- /**
- * the OS resource for the Path
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
- int currentFigure, currentPoint;
-
-/**
- * Constructs a new empty Path.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the path
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Path (Device device) {
- super(device);
- handle = OS.gcnew_PathGeometry();
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new Path that is a copy of <code>path</code>. If
- * <code>flatness</code> is less than or equal to zero, an unflatten
- * copy of the path is created. Otherwise, it specifies the maximum
- * error between the path and its flatten copy. Smaller numbers give
- * better approximation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the path
- * @param path the path to make a copy
- * @param flatness the flatness value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the path is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the path has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- * @since 3.4
- */
-public Path (Device device, Path path, float flatness) {
- super(device);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- flatness = Math.max(0, flatness);
- if (flatness == 0) {
- handle = OS.PathGeometry_Clone(path.handle);
- } else {
- handle = OS.Geometry_GetFlattenedPathGeometry(path.handle, flatness, OS.ToleranceType_Absolute);
- }
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new Path with the specifed PathData.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the path
- * @param data the data for the path
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the data is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- * @since 3.4
- */
-public Path (Device device, PathData data) {
- this(device);
- if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(data);
-}
-
-/**
- * Adds to the receiver a circular or elliptical arc that lies within
- * the specified rectangular area.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends
- * for <code>arcAngle</code> degrees.
- * Angles are interpreted such that 0 degrees is at the 3 o'clock
- * position. A positive value indicates a counter-clockwise rotation
- * while a negative value indicates a clockwise rotation.
- * </p><p>
- * The center of the arc is the center of the rectangle whose origin
- * is (<code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p><p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide
- * by <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x the x coordinate of the upper-left corner of the arc
- * @param y the y coordinate of the upper-left corner of the arc
- * @param width the width of the arc
- * @param height the height of the arc
- * @param startAngle the beginning angle
- * @param arcAngle the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addArc(float x, float y, float width, float height, float startAngle, float arcAngle) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- boolean isNegative = arcAngle < 0;
- boolean isLargeAngle = arcAngle > 180 || arcAngle < -180;
- arcAngle = arcAngle + startAngle;
- if (isNegative) {
- // swap angles
- float tmp = startAngle;
- startAngle = arcAngle;
- arcAngle = tmp;
- }
- double x1 = Math.cos(startAngle * Math.PI / 180) * width/2.0 + x + width/2.0;
- double y1 = -1 * Math.sin(startAngle * Math.PI / 180) * height/2.0 + y + height/2.0;
- double x2 = Math.cos(arcAngle * Math.PI / 180) * width/2.0 + x + width/2.0;
- double y2 = -1 * Math.sin(arcAngle * Math.PI / 180) * height/2.0 + y + height/2.0;
- if (currentFigure == 0) {
- currentFigure = OS.gcnew_PathFigure();
- int figures = OS.PathGeometry_Figures(handle);
- OS.PathFigureCollection_Add(figures, currentFigure);
- OS.GCHandle_Free(figures);
- }
- int startPoint = OS.gcnew_Point(x1, y1);
- int endPoint = OS.gcnew_Point(x2, y2);
- int segments = OS.PathFigure_Segments(currentFigure);
- if (OS.PathSegmentCollection_Count(segments) != 0) {
- int segment = OS.gcnew_LineSegment(startPoint, true);
- OS.PathSegmentCollection_Add(segments, segment);
- OS.GCHandle_Free(segment);
- } else {
- OS.PathFigure_StartPoint(currentFigure, startPoint);
- }
- if (arcAngle >= 360 || arcAngle <= -360) {
- int rect = OS.gcnew_Rect(x, y, width, height);
- int geometry = OS.gcnew_EllipseGeometry(rect);
- OS.PathGeometry_AddGeometry(handle, geometry);
- OS.GCHandle_Free(geometry);
- OS.GCHandle_Free(rect);
- OS.GCHandle_Free(currentFigure);
- currentFigure = 0;
- } else {
- int size = OS.gcnew_Size(width / 2.0, height / 2.0);
- int arc = OS.gcnew_ArcSegment(endPoint, size, 0, isLargeAngle, OS.SweepDirection_Clockwise, true);
- OS.PathSegmentCollection_Add(segments, arc);
- OS.GCHandle_Free(size);
- OS.GCHandle_Free(arc);
- }
- OS.GCHandle_Free(segments);
- OS.GCHandle_Free(startPoint);
- if (currentPoint != 0) OS.GCHandle_Free(currentPoint);
- currentPoint = endPoint;
-}
-
-/**
- * Adds to the receiver the path described by the parameter.
- *
- * @param path the path to add to the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addPath(Path path) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.PathGeometry_AddGeometry(handle, path.handle);
- if (path.currentPoint != 0) {
- currentPoint = OS.gcnew_Point(OS.Point_X(path.currentPoint), OS.Point_Y(path.currentPoint));
- }
- int figures = OS.PathGeometry_Figures(handle);
- int count = OS.PathFigureCollection_Count(figures);
- OS.GCHandle_Free(figures);
- if (count != 0) {
- int figure = OS.PathGeometry_Figures(handle, count - 1);
- if (!OS.PathFigure_IsClosed(figure)) {
- currentFigure = figure;
- return;
- }
- OS.GCHandle_Free(figure);
- }
-
-}
-
-/**
- * Adds to the receiver the rectangle specified by x, y, width and height.
- *
- * @param x the x coordinate of the rectangle to add
- * @param y the y coordinate of the rectangle to add
- * @param width the width of the rectangle to add
- * @param height the height of the rectangle to add
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addRectangle(float x, float y, float width, float height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int rect = OS.gcnew_Rect(x, y, width, height);
- int geometry = OS.gcnew_RectangleGeometry(rect);
- OS.PathGeometry_AddGeometry(handle, geometry);
- OS.GCHandle_Free(geometry);
- OS.GCHandle_Free(rect);
- if (currentFigure != 0) OS.GCHandle_Free(currentFigure);
- currentFigure = 0;
- int point = OS.gcnew_Point(x, y);
- if (currentPoint != 0) OS.GCHandle_Free(currentPoint);
- currentPoint = point;
-
-}
-
-/**
- * Adds to the receiver the pattern of glyphs generated by drawing
- * the given string using the given font starting at the point (x, y).
- *
- * @param string the text to use
- * @param x the x coordinate of the starting point
- * @param y the y coordinate of the starting point
- * @param font the font to use
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the font is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void addString(String string, float x, float y, Font font) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (font == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int length = string.length();
- char [] buffer = new char [length + 1];
- string.getChars (0, length, buffer, 0);
- int str = OS.gcnew_String (buffer);
- int culture = OS.CultureInfo_CurrentUICulture();
- int point = OS.gcnew_Point(x, y);
- int brush = OS.Brushes_White();
- int text = OS.gcnew_FormattedText(str, culture, OS.FlowDirection_LeftToRight, font.handle, font.size, brush);
- int geometry = OS.FormattedText_BuildGeometry(text, point);
- OS.PathGeometry_AddGeometry(handle, geometry);
- OS.GCHandle_Free(brush);
- OS.GCHandle_Free(geometry);
- OS.GCHandle_Free(culture);
- OS.GCHandle_Free(str);
- OS.GCHandle_Free(point);
- OS.GCHandle_Free(text);
- if (currentFigure != 0) OS.GCHandle_Free(currentFigure);
- currentFigure = 0;
- if (currentPoint != 0) OS.GCHandle_Free(currentPoint);
- currentPoint = 0;
-}
-
-/**
- * Closes the current sub path by adding to the receiver a line
- * from the current point of the path back to the starting point
- * of the sub path.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void close() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (currentFigure != 0) OS.PathFigure_IsClosed(currentFigure, true);
- currentFigure = 0;
-}
-
-/**
- * Returns <code>true</code> if the specified point is contained by
- * the receiver and false otherwise.
- * <p>
- * If outline is <code>true</code>, the point (x, y) checked for containment in
- * the receiver's outline. If outline is <code>false</code>, the point is
- * checked to see if it is contained within the bounds of the (closed) area
- * covered by the receiver.
- *
- * @param x the x coordinate of the point to test for containment
- * @param y the y coordinate of the point to test for containment
- * @param gc the GC to use when testing for containment
- * @param outline controls whether to check the outline or contained area of the path
- * @return <code>true</code> if the path contains the point and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains(float x, float y, GC gc, boolean outline) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- gc.checkGC(GC.LINE_CAP | GC.LINE_JOIN | GC.LINE_STYLE | GC.LINE_WIDTH | GC.LINE_MITERLIMIT | GC.TRANSFORM);
- boolean result;
- int point = OS.gcnew_Point(x, y);
- if (outline) {
- result = OS.Geometry_StrokeContains(handle, gc.data.pen, point);
- } else {
- result = OS.Geometry_FillContains(handle, point);
- }
- OS.GCHandle_Free(point);
- return result;
-}
-
-/**
- * Adds to the receiver a cubic bezier curve based on the parameters.
- *
- * @param cx1 the x coordinate of the first control point of the spline
- * @param cy1 the y coordinate of the first control of the spline
- * @param cx2 the x coordinate of the second control of the spline
- * @param cy2 the y coordinate of the second control of the spline
- * @param x the x coordinate of the end point of the spline
- * @param y the y coordinate of the end point of the spline
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int controlPoint1 = OS.gcnew_Point(cx1, cy1);
- int controlPoint2 = OS.gcnew_Point(cx2, cy2);
- int point = OS.gcnew_Point(x, y);
- if (currentFigure == 0) newFigure();
- if (currentPoint != 0) OS.GCHandle_Free(currentPoint);
- currentPoint = point;
- int segment = OS.gcnew_BezierSegment(controlPoint1, controlPoint2, point, true);
- int segments = OS.PathFigure_Segments(currentFigure);
- OS.PathSegmentCollection_Add(segments, segment);
- OS.GCHandle_Free(segments);
- OS.GCHandle_Free(segment);
- OS.GCHandle_Free(controlPoint1);
- OS.GCHandle_Free(controlPoint2);
-}
-
-void destroy() {
- OS.GCHandle_Free(handle);
- handle = 0;
- if (currentFigure != 0) OS.GCHandle_Free(currentFigure);
- currentFigure = 0;
- if (currentPoint != 0) OS.GCHandle_Free(currentPoint);
- currentPoint = 0;
-}
-
-/**
- * Replaces the first four elements in the parameter with values that
- * describe the smallest rectangle that will completely contain the
- * receiver (i.e. the bounding box).
- *
- * @param bounds the array to hold the result
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the bounding box</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getBounds(float[] bounds) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (bounds.length < 4) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int rect = OS.PathGeometry_Bounds(handle);
- bounds[0] = (float)OS.Rect_X(rect);
- bounds[1] = (float)OS.Rect_Y(rect);
- bounds[2] = (float)OS.Rect_Width(rect);
- bounds[3] = (float)OS.Rect_Height(rect);
- OS.GCHandle_Free(rect);
-}
-
-/**
- * Replaces the first two elements in the parameter with values that
- * describe the current point of the path.
- *
- * @param point the array to hold the result
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the end point</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void getCurrentPoint(float[] point) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (point == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (point.length < 2) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (currentPoint != 0) {
- point[0] = (float)OS.Point_X(currentPoint);
- point[1] = (float)OS.Point_Y(currentPoint);
- } else {
- point[0] = point[1] = 0;
- }
-}
-
-/**
- * Returns a device independent representation of the receiver.
- *
- * @return the PathData for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see PathData
- */
-public PathData getPathData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- byte[] types = new byte[128];
- float[] points = new float[128 * 2];
- int pointsIndex = 0, typesIndex = 0;
- int figures = OS.PathGeometry_Figures(handle);
- int figureCount = OS.PathFigureCollection_Count(figures);
- OS.GCHandle_Free(figures);
- for (int i = 0; i < figureCount; i++) {
- int figure = OS.PathGeometry_Figures(handle, i);
- int segments = OS.PathFigure_Segments(figure);
- int segmentCount = OS.PathSegmentCollection_Count(segments);
- OS.GCHandle_Free(segments);
- for (int j = 0; j < segmentCount; j++) {
- int segment = OS.PathFigure_Segments(figure, j);
- int type = OS.Object_GetType(segment);
- //TODO - need get points out of every segment
- //TODO - need to convert ArcSegment to beziers
-
-
- OS.GCHandle_Free(type);
- OS.GCHandle_Free(segment);
- }
- OS.GCHandle_Free(figure);
- }
- if (typesIndex != types.length) {
- byte[] newTypes = new byte[typesIndex];
- System.arraycopy(types, 0, newTypes, 0, typesIndex);
- types = newTypes;
- }
- if (pointsIndex != points.length) {
- float[] newPoints = new float[pointsIndex];
- System.arraycopy(points, 0, newPoints, 0, pointsIndex);
- points = newPoints;
- }
- PathData result = new PathData();
- result.types = types;
- result.points = points;
- return result;
-}
-
-/**
- * Adds to the receiver a line from the current point to
- * the point specified by (x, y).
- *
- * @param x the x coordinate of the end of the line to add
- * @param y the y coordinate of the end of the line to add
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void lineTo(float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int point = OS.gcnew_Point(x, y);
- if (currentFigure == 0) newFigure();
- if (currentPoint != 0) OS.GCHandle_Free(currentPoint);
- currentPoint = point;
- int segment = OS.gcnew_LineSegment(point, true);
- int segments = OS.PathFigure_Segments(currentFigure);
- OS.PathSegmentCollection_Add(segments, segment);
- OS.GCHandle_Free(segments);
- OS.GCHandle_Free(segment);
-}
-
-void init(PathData data) {
- byte[] types = data.types;
- float[] points = data.points;
- for (int i = 0, j = 0; i < types.length; i++) {
- switch (types[i]) {
- case SWT.PATH_MOVE_TO:
- moveTo(points[j++], points[j++]);
- break;
- case SWT.PATH_LINE_TO:
- lineTo(points[j++], points[j++]);
- break;
- case SWT.PATH_CUBIC_TO:
- cubicTo(points[j++], points[j++], points[j++], points[j++], points[j++], points[j++]);
- break;
- case SWT.PATH_QUAD_TO:
- quadTo(points[j++], points[j++], points[j++], points[j++]);
- break;
- case SWT.PATH_CLOSE:
- close();
- break;
- default:
- dispose();
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
-}
-
-/**
- * Returns <code>true</code> if the Path has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Path.
- * When a Path has been disposed, it is an error to
- * invoke any other method using the Path.
- *
- * @return <code>true</code> when the Path is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Sets the current point of the receiver to the point
- * specified by (x, y). Note that this starts a new
- * sub path.
- *
- * @param x the x coordinate of the new end point
- * @param y the y coordinate of the new end point
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void moveTo(float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int point = OS.gcnew_Point(x, y);
- if (currentPoint != 0) OS.GCHandle_Free(currentPoint);
- currentPoint = point;
- if (currentFigure != 0) {
- int segments = OS.PathFigure_Segments(currentFigure);
- int count = OS.PathSegmentCollection_Count(segments);
- OS.GCHandle_Free(segments);
- if (count == 0) {
- OS.PathFigure_StartPoint(currentFigure, point);
- return;
- }
- }
- if (currentFigure != 0) OS.GCHandle_Free(currentFigure);
- newFigure();
-}
-
-void newFigure() {
- currentFigure = OS.gcnew_PathFigure();
- if (currentPoint != 0) {
- OS.PathFigure_StartPoint(currentFigure, currentPoint);
- }
- int figures = OS.PathGeometry_Figures(handle);
- OS.PathFigureCollection_Add(figures, currentFigure);
- OS.GCHandle_Free(figures);
-}
-
-/**
- * Adds to the receiver a quadratic curve based on the parameters.
- *
- * @param cx the x coordinate of the control point of the spline
- * @param cy the y coordinate of the control point of the spline
- * @param x the x coordinate of the end point of the spline
- * @param y the y coordinate of the end point of the spline
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void quadTo(float cx, float cy, float x, float y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int controlPoint = OS.gcnew_Point(cx, cy);
- int point = OS.gcnew_Point(x, y);
- if (currentFigure == 0) newFigure();
- if (currentPoint != 0) OS.GCHandle_Free(currentPoint);
- currentPoint = point;
- int segment = OS.gcnew_QuadraticBezierSegment(controlPoint, point, true);
- int segments = OS.PathFigure_Segments(currentFigure);
- OS.PathSegmentCollection_Add(segments, segment);
- OS.GCHandle_Free(segments);
- OS.GCHandle_Free(segment);
- OS.GCHandle_Free(controlPoint);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString() {
- if (isDisposed()) return "Path {*DISPOSED*}";
- return "Path {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Pattern.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Pattern.java
deleted file mode 100644
index ec1394e50e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Pattern.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.wpf.*;
-
-/**
- * Instances of this class represent patterns to use while drawing. Patterns
- * can be specified either as bitmaps or gradients.
- * <p>
- * Application code must explicitly invoke the <code>Pattern.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#path">Path, Pattern snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Pattern extends Resource {
-
- /**
- * the OS resource for the Pattern
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
-/**
- * Constructs a new Pattern given an image. Drawing with the resulting
- * pattern will cause the image to be tiled over the resulting area.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the pattern
- * @param image the image that the pattern will draw
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device, or the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Pattern(Device device, Image image) {
- super(device);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- handle = OS.gcnew_ImageBrush(image.handle);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.TileBrush_TileMode(handle, OS.TileMode_Tile);
- OS.TileBrush_Stretch(handle, OS.Stretch_Fill);
- OS.TileBrush_ViewportUnits(handle, OS.BrushMappingMode_Absolute);
- int rect = OS.gcnew_Rect(0, 0, OS.BitmapSource_PixelWidth(image.handle), OS.BitmapSource_PixelHeight(image.handle));
- OS.TileBrush_Viewport(handle, rect);
- OS.GCHandle_Free(rect);
- init();
-}
-
-/**
- * Constructs a new Pattern that represents a linear, two color
- * gradient. Drawing with the pattern will cause the resulting area to be
- * tiled with the gradient specified by the arguments.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the pattern
- * @param x1 the x coordinate of the starting corner of the gradient
- * @param y1 the y coordinate of the starting corner of the gradient
- * @param x2 the x coordinate of the ending corner of the gradient
- * @param y2 the y coordinate of the ending corner of the gradient
- * @param color1 the starting color of the gradient
- * @param color2 the ending color of the gradient
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device,
- * or if either color1 or color2 is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either color1 or color2 has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Pattern(Device device, float x1, float y1, float x2, float y2, Color color1, Color color2) {
- this(device, x1, y1, x2, y2, color1, 0xFF, color2, 0xFF);
-}
-
-/**
- * Constructs a new Pattern that represents a linear, two color
- * gradient. Drawing with the pattern will cause the resulting area to be
- * tiled with the gradient specified by the arguments.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the pattern
- * @param x1 the x coordinate of the starting corner of the gradient
- * @param y1 the y coordinate of the starting corner of the gradient
- * @param x2 the x coordinate of the ending corner of the gradient
- * @param y2 the y coordinate of the ending corner of the gradient
- * @param color1 the starting color of the gradient
- * @param alpha1 the starting alpha value of the gradient
- * @param color2 the ending color of the gradient
- * @param alpha2 the ending alpha value of the gradient
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device,
- * or if either color1 or color2 is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either color1 or color2 has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- *
- * @since 3.2
- */
-public Pattern(Device device, float x1, float y1, float x2, float y2, Color color1, int alpha1, Color color2, int alpha2) {
- super(device);
- if (color1 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color1.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (color2 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color2.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int startColor = OS.Color_FromArgb((byte)(alpha1 & 0xFF), OS.Color_R(color1.handle), OS.Color_G(color1.handle), OS.Color_B(color1.handle));
- if (x1 == x2 && y1 == y2) {
- handle = OS.gcnew_SolidColorBrush(startColor);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- } else {
- int startPoint = OS.gcnew_Point(x1, y1);
- int endColor = OS.Color_FromArgb((byte)(alpha2 & 0xFF), OS.Color_R(color2.handle), OS.Color_G(color2.handle), OS.Color_B(color2.handle));
- int endPoint = OS.gcnew_Point(x2, y2);
- handle = OS.gcnew_LinearGradientBrush(startColor, endColor, startPoint, endPoint);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.GradientBrush_MappingMode(handle, OS.BrushMappingMode_Absolute);
- OS.GradientBrush_SpreadMethod(handle, OS.GradientSpreadMethod_Repeat);
- OS.GCHandle_Free(endColor);
- OS.GCHandle_Free(endPoint);
- OS.GCHandle_Free(startPoint);
- }
- OS.GCHandle_Free(startColor);
- init();
-}
-
-void destroy() {
- OS.GCHandle_Free(handle);
- handle = 0;
-}
-
-/**
- * Returns <code>true</code> if the Pattern has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Pattern.
- * When a Pattern has been disposed, it is an error to
- * invoke any other method using the Pattern.
- *
- * @return <code>true</code> when the Pattern is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString() {
- if (isDisposed()) return "Pattern {*DISPOSED*}";
- return "Pattern {" + handle + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Region.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Region.java
deleted file mode 100644
index e988c51718..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Region.java
+++ /dev/null
@@ -1,712 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class represent areas of an x-y coordinate
- * system that are aggregates of the areas covered by a number
- * of polygons.
- * <p>
- * Application code must explicitly invoke the <code>Region.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public final class Region extends Resource {
-
- /**
- * the OS resource for the region
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
-/**
- * Constructs a new empty region.
- *
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
- * </ul>
- */
-public Region () {
- this(null);
-}
-
-/**
- * Constructs a new empty region.
- * <p>
- * You must dispose the region when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the region
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
- * </ul>
- *
- * @see #dispose
- *
- * @since 3.0
- */
-public Region (Device device) {
- super(device);
- handle = OS.gcnew_GeometryGroup();
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-/**
- * Constructs a new region given a handle to the operating
- * system resources that it should represent.
- *
- * @param handle the handle for the result
- */
-Region(Device device, int handle) {
- super(device);
- this.handle = handle;
-}
-
-/**
- * Adds the given polygon to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param pointArray points that describe the polygon to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
-*
- */
-public void add (int[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- combine(pointArray, OS.GeometryCombineMode_Union);
-}
-
-
-
-/**
- * Adds the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void add (Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- add (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Adds the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void add (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int rect = OS.gcnew_Rect(x, y, width, height);
- int geometry1 = OS.gcnew_RectangleGeometry(rect);
- int geometries = OS.GeometryGroup_Children(handle);
- if (OS.GeometryCollection_Count(geometries) == 0) {
- OS.GeometryCollection_Add(geometries, geometry1);
- } else {
- int geometry2 = OS.GeometryGroup_Children(handle, 0);
- int geometry3 = OS.gcnew_CombinedGeometry(OS.GeometryCombineMode_Union, geometry1, geometry2);
- OS.GeometryCollection_Remove(geometries, geometry2);
- OS.GeometryCollection_Add(geometries, geometry3);
- OS.GCHandle_Free(geometry2);
- OS.GCHandle_Free(geometry3);
- }
- OS.GCHandle_Free(rect);
- OS.GCHandle_Free(geometry1);
- OS.GCHandle_Free(geometries);
-}
-
-/**
- * Adds all of the polygons which make up the area covered
- * by the argument to the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to merge
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void add (Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int geometries = OS.GeometryGroup_Children(handle);
- if (OS.GeometryCollection_Count(geometries) == 0) {
- OS.GeometryCollection_Add(geometries, region.handle);
- } else {
- int geometry2 = OS.GeometryGroup_Children(handle, 0);
- int geometry3 = OS.gcnew_CombinedGeometry(OS.GeometryCombineMode_Union, region.handle, geometry2);
- OS.GeometryCollection_Remove(geometries, geometry2);
- OS.GeometryCollection_Add(geometries, geometry3);
- OS.GCHandle_Free(geometry2);
- OS.GCHandle_Free(geometry3);
- }
- OS.GCHandle_Free(geometries);
-}
-
-
-void combine (int[] pointArray, int mode) {
- if (pointArray.length < 4) return;
- int list = OS.gcnew_PointCollection(pointArray.length / 2);
- for (int i = 2; i < pointArray.length; i += 2) {
- int point = OS.gcnew_Point(pointArray[i], pointArray[i + 1]);
- OS.PointCollection_Add(list, point);
- OS.GCHandle_Free(point);
- }
- int poly = OS.gcnew_PolyLineSegment(list, true);
- OS.GCHandle_Free(list);
- int figure = OS.gcnew_PathFigure();
- int startPoint = OS.gcnew_Point(pointArray[0], pointArray[1]);
- OS.PathFigure_StartPoint(figure, startPoint);
- OS.PathFigure_IsClosed(figure, true);
- int segments = OS.PathFigure_Segments(figure);
- OS.PathSegmentCollection_Add(segments, poly);
- int path = OS.gcnew_PathGeometry();
- int figures = OS.PathGeometry_Figures(path);
- OS.PathFigureCollection_Add(figures, figure);
- int geometries = OS.GeometryGroup_Children(handle);
- if (OS.GeometryCollection_Count(geometries) == 0) {
- if (mode == OS.GeometryCombineMode_Union) OS.GeometryCollection_Add(geometries, path);
- } else {
- int geometry2 = OS.GeometryGroup_Children(handle, 0);
- int geometry3 = OS.gcnew_CombinedGeometry(mode, geometry2, path);
- OS.GeometryCollection_Remove(geometries, geometry2);
- OS.GeometryCollection_Add(geometries, geometry3);
- OS.GCHandle_Free(geometry2);
- OS.GCHandle_Free(geometry3);
- }
- OS.GCHandle_Free(geometries);
- OS.GCHandle_Free(figures);
- OS.GCHandle_Free(path);
- OS.GCHandle_Free(segments);
- OS.GCHandle_Free(figure);
- OS.GCHandle_Free(startPoint);
- OS.GCHandle_Free(poly);
-}
-
-/**
- * Returns <code>true</code> if the point specified by the
- * arguments is inside the area specified by the receiver,
- * and <code>false</code> otherwise.
- *
- * @param x the x coordinate of the point to test for containment
- * @param y the y coordinate of the point to test for containment
- * @return <code>true</code> if the region contains the point and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains (int x, int y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int point = OS.gcnew_Point(x, y);
- boolean result = OS.Geometry_FillContains(handle, point);
- OS.GCHandle_Free(point);
- return result;
-}
-
-/**
- * Returns <code>true</code> if the given point is inside the
- * area specified by the receiver, and <code>false</code>
- * otherwise.
- *
- * @param pt the point to test for containment
- * @return <code>true</code> if the region contains the point and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean contains (Point pt) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return contains(pt.x, pt.y);
-}
-
-void destroy() {
- OS.GCHandle_Free(handle);
- handle = 0;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (this == object) return true;
- if (!(object instanceof Region)) return false;
- Region rgn = (Region)object;
- return handle == rgn.handle;
-}
-
-/**
- * Returns a rectangle which represents the rectangular
- * union of the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @return a bounding rectangle for the region
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#union
- */
-public Rectangle getBounds() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (OS.Geometry_IsEmpty(handle)) return new Rectangle(0, 0, 0, 0);
- int rect = OS.Geometry_Bounds(handle);
- Rectangle result = new Rectangle((int)OS.Rect_X(rect), (int)OS.Rect_Y(rect), (int)OS.Rect_Width(rect), (int)OS.Rect_Height(rect));
- OS.GCHandle_Free(rect);
- return result;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
-public int hashCode () {
- return handle;
-}
-
-/**
- * Intersects the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to intersect with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void intersect (Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- intersect (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Intersects the given rectangle to the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void intersect (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int rect = OS.gcnew_Rect(x, y, width, height);
- int geometry1 = OS.gcnew_RectangleGeometry(rect);
- int geometries = OS.GeometryGroup_Children(handle);
- if (OS.GeometryCollection_Count(geometries) != 0) {
- int geometry2 = OS.GeometryGroup_Children(handle, 0);
- int geometry3 = OS.gcnew_CombinedGeometry(OS.GeometryCombineMode_Intersect, geometry1, geometry2);
- OS.GeometryCollection_Remove(geometries, geometry2);
- OS.GeometryCollection_Add(geometries, geometry3);
- OS.GCHandle_Free(geometry2);
- OS.GCHandle_Free(geometry3);
- }
- OS.GCHandle_Free(rect);
- OS.GCHandle_Free(geometry1);
- OS.GCHandle_Free(geometries);
-}
-
-/**
- * Intersects all of the polygons which make up the area covered
- * by the argument to the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to intersect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void intersect (Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int geometries = OS.GeometryGroup_Children(handle);
- if (OS.GeometryCollection_Count(geometries) != 0) {
- int geometry2 = OS.GeometryGroup_Children(handle, 0);
- int geometry3 = OS.gcnew_CombinedGeometry(OS.GeometryCombineMode_Intersect, region.handle, geometry2);
- OS.GeometryCollection_Remove(geometries, geometry2);
- OS.GeometryCollection_Add(geometries, geometry3);
- OS.GCHandle_Free(geometry2);
- OS.GCHandle_Free(geometry3);
- }
- OS.GCHandle_Free(geometries);
-}
-
-/**
- * Returns <code>true</code> if the rectangle described by the
- * arguments intersects with any of the polygons the receiver
- * maintains to describe its area, and <code>false</code> otherwise.
- *
- * @param x the x coordinate of the origin of the rectangle
- * @param y the y coordinate of the origin of the rectangle
- * @param width the width of the rectangle
- * @param height the height of the rectangle
- * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#intersects(Rectangle)
- */
-public boolean intersects (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int rect = OS.gcnew_Rect(x, y, width, height);
- int geometry = OS.gcnew_RectangleGeometry(rect);
- int result = OS.Geometry_FillContainsWithDetail(handle, geometry);
- OS.GCHandle_Free(geometry);
- OS.GCHandle_Free(rect);
- return result != OS.IntersectionDetail_Empty;
-}
-
-/**
- * Returns <code>true</code> if the given rectangle intersects
- * with any of the polygons the receiver maintains to describe
- * its area and <code>false</code> otherwise.
- *
- * @param rect the rectangle to test for intersection
- * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Rectangle#intersects(Rectangle)
- */
-public boolean intersects (Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return intersects(rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Returns <code>true</code> if the region has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the region.
- * When a region has been disposed, it is an error to
- * invoke any other method using the region.
- *
- * @return <code>true</code> when the region is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns <code>true</code> if the receiver does not cover any
- * area in the (x, y) coordinate plane, and <code>false</code> if
- * the receiver does cover some area in the plane.
- *
- * @return <code>true</code> if the receiver is empty, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public boolean isEmpty () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return OS.Geometry_IsEmpty(handle);
-}
-
-/**
- * Subtracts the given polygon from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param pointArray points that describe the polygon to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract (int[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- combine(pointArray, OS.GeometryCombineMode_Exclude);
-}
-
-/**
- * Subtracts the given rectangle from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to subtract from the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract (Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- subtract (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * Subtracts the given rectangle from the collection of polygons
- * the receiver maintains to describe its area.
- *
- * @param x the x coordinate of the rectangle
- * @param y the y coordinate of the rectangle
- * @param width the width coordinate of the rectangle
- * @param height the height coordinate of the rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void subtract (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int rect = OS.gcnew_Rect(x, y, width, height);
- int geometry1 = OS.gcnew_RectangleGeometry(rect);
- int geometries = OS.GeometryGroup_Children(handle);
- if (OS.GeometryCollection_Count(geometries) != 0) {
- int geometry2 = OS.GeometryGroup_Children(handle, 0);
- int geometry3 = OS.gcnew_CombinedGeometry(OS.GeometryCombineMode_Exclude, geometry2, geometry1);
- OS.GeometryCollection_Remove(geometries, geometry2);
- OS.GeometryCollection_Add(geometries, geometry3);
- OS.GCHandle_Free(geometry2);
- OS.GCHandle_Free(geometry3);
- }
- OS.GCHandle_Free(rect);
- OS.GCHandle_Free(geometry1);
- OS.GCHandle_Free(geometries);
-}
-
-/**
- * Subtracts all of the polygons which make up the area covered
- * by the argument from the collection of polygons the receiver
- * maintains to describe its area.
- *
- * @param region the region to subtract
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public void subtract (Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int geometries = OS.GeometryGroup_Children(handle);
- if (OS.GeometryCollection_Count(geometries) != 0) {
- int geometry2 = OS.GeometryGroup_Children(handle, 0);
- int geometry3 = OS.gcnew_CombinedGeometry(OS.GeometryCombineMode_Exclude, geometry2, region.handle);
- OS.GeometryCollection_Remove(geometries, geometry2);
- OS.GeometryCollection_Add(geometries, geometry3);
- OS.GCHandle_Free(geometry2);
- OS.GCHandle_Free(geometry3);
- }
- OS.GCHandle_Free(geometries);
-}
-
-/**
- * Translate all of the polygons the receiver maintains to describe
- * its area by the specified point.
- *
- * @param x the x coordinate of the point to translate
- * @param y the y coordinate of the point to translate
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void translate (int x, int y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int transform1 = OS.Geometry_Transform(handle);
- int transform2 = OS.gcnew_TranslateTransform(x, y);
- int transform = OS.gcnew_TransformGroup();
- int transforms = OS.TransformGroup_Children(transform);
- OS.TransformCollection_Add(transforms, transform1);
- OS.TransformCollection_Add(transforms, transform2);
- OS.Geometry_Transform(handle, transform);
- OS.GCHandle_Free(transform1);
- OS.GCHandle_Free(transform2);
- OS.GCHandle_Free(transform);
- OS.GCHandle_Free(transforms);
-}
-
-/**
- * Translate all of the polygons the receiver maintains to describe
- * its area by the specified point.
- *
- * @param pt the point to translate
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public void translate (Point pt) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- translate (pt.x, pt.y);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Region {*DISPOSED*}";
- return "Region {" + handle + "}";
-}
-
-/**
- * Invokes platform specific functionality to allocate a new region.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Region</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param device the device on which to allocate the region
- * @param handle the handle for the region
- * @return a new region object containing the specified device and handle
- */
-public static Region wpf_new(Device device, int handle) {
- return new Region(device, handle);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/TextLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/TextLayout.java
deleted file mode 100644
index ad7af71cf0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/TextLayout.java
+++ /dev/null
@@ -1,1877 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-
-/**
- * <code>TextLayout</code> is a graphic object that represents
- * styled text.
- * <p>
- * Instances of this class provide support for drawing, cursor
- * navigation, hit testing, text wrapping, alignment, tab expansion
- * line breaking, etc. These are aspects required for rendering internationalized text.
- * </p><p>
- * Application code must explicitly invoke the <code>TextLayout#dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#textlayout">TextLayout, TextStyle snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: CustomControlExample, StyledText tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.0
- */
-public final class TextLayout extends Resource {
- Font font;
- String text, segmentsText;
- int lineSpacing;
- int ascent, descent;
- int alignment;
- int wrapWidth;
- int orientation;
- int indent;
- boolean justify;
- int[] tabs;
- int[] segments;
- StyleItem[] styles;
-
- int string, defaultTextProperties;
- int[] runs;
- int[] lines;
-
- static final RGB LINK_FOREGROUND = new RGB (0, 51, 153);
- static final char LTR_MARK = '\u200E', RTL_MARK = '\u200F';
- static final int TAB_COUNT = 32;
-
-class StyleItem {
- TextStyle style;
- int start, length;
- int textProperties;
-
- void free() {
- if (textProperties != 0) OS.GCHandle_Free(textProperties);
- textProperties = 0;
- }
- public String toString () {
- return "StyleItem {" + start + ", " + style + "}";
- }
-}
-
-/**
- * Constructs a new instance of this class on the given device.
- * <p>
- * You must dispose the text layout when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the text layout
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- *
- * @see #dispose()
- */
-public TextLayout (Device device) {
- super(device);
- wrapWidth = ascent = descent = -1;
- lineSpacing = 0;
- orientation = SWT.LEFT_TO_RIGHT;
- styles = new StyleItem[2];
- styles[0] = new StyleItem();
- styles[1] = new StyleItem();
- text = ""; //$NON-NLS-1$
- init();
-}
-
-void checkLayout () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-/*
-* Compute the runs: itemize, shape, place, and reorder the runs.
-* Break paragraphs into lines, wraps the text, and initialize caches.
-*/
-void computeRuns () {
- if (lines != null) return;
-
- int jniRef = OS.NewGlobalRef(this);
- int textSource = OS.gcnew_SWTTextSource(jniRef);
- int formatter = OS.TextFormatter_Create();
- Font font = this.font != null ? this.font : device.systemFont;
- segmentsText = getSegmentsText();
- int length = segmentsText.length();
- char [] buffer = new char [length];
- segmentsText.getChars (0, length, buffer, 0);
- string = OS.gcnew_String(buffer, 0 ,length);
- int culture = OS.CultureInfo_CurrentUICulture();
- defaultTextProperties = OS.gcnew_SWTTextRunProperties(font.handle, font.size, font.size, 0, 0, 0, OS.BaselineAlignment_Baseline, culture);
- for (int i = 0; i < styles.length; i++) {
- StyleItem run = styles[i];
- TextStyle style = run.style;
- if (style != null) {
- Font styleFont = style.font != null ? style.font : font;
- int fg = 0;
- if (style.foreground != null) {
- fg = OS.gcnew_SolidColorBrush(style.foreground.handle);
- } else {
- if (style.underline && style.underlineStyle == SWT.UNDERLINE_LINK) {
- int color = OS.Color_FromArgb((byte)0xFF, (byte)LINK_FOREGROUND.red, (byte)LINK_FOREGROUND.green, (byte)LINK_FOREGROUND.blue);
- fg = OS.gcnew_SolidColorBrush(color);
- OS.GCHandle_Free(color);
- }
- }
- int bg = 0;
- if (style.background != null) {
- bg = OS.gcnew_SolidColorBrush(style.background.handle);
- }
- int decorations = 0;
- if (style.strikeout || style.underline) {
- decorations = OS.gcnew_TextDecorationCollection(2);
- if (style.strikeout) {
- int pen = 0;
- if (style.strikeoutColor != null) {
- int color = style.strikeoutColor.handle;
- int brush = OS.gcnew_SolidColorBrush(color);
- pen = OS.gcnew_Pen(brush, 1);
- OS.GCHandle_Free(brush);
- }
- int strikeout = OS.gcnew_TextDecoration(OS.TextDecorationLocation_Strikethrough, pen, 0, OS.TextDecorationUnit_FontRecommended, OS.TextDecorationUnit_FontRecommended);
- OS.TextDecorationCollection_Add(decorations, strikeout);
- OS.GCHandle_Free(strikeout);
- if (pen != 0) OS.GCHandle_Free(pen);
- }
- if (style.underline) {
- int brush;
- if (style.underlineColor != null) {
- Color color = style.underlineColor;
- brush = OS.gcnew_SolidColorBrush(color.handle);
- } else {
- if (fg != 0) {
- brush = fg;
- } else {
- brush = OS.Brushes_Black();
- }
- }
- int pen = OS.gcnew_Pen(brush, 1f);
- if (brush != fg) OS.GCHandle_Free(brush);
- int underline;
- switch (style.underlineStyle) {
- case SWT.UNDERLINE_SQUIGGLE:
- //TODO implement
- case SWT.UNDERLINE_ERROR:
- int dashStyle = OS.DashStyles_Dash();
- OS.Pen_DashStyle(pen, dashStyle);
- underline = OS.gcnew_TextDecoration(OS.TextDecorationLocation_Underline, pen, 0, OS.TextDecorationUnit_FontRecommended, OS.TextDecorationUnit_FontRecommended);
- OS.TextDecorationCollection_Add(decorations, underline);
- OS.GCHandle_Free(underline);
- OS.GCHandle_Free(dashStyle);
- break;
- case SWT.UNDERLINE_DOUBLE:
- underline = OS.gcnew_TextDecoration(OS.TextDecorationLocation_Underline, pen, 1, OS.TextDecorationUnit_FontRecommended, OS.TextDecorationUnit_FontRecommended);
- OS.TextDecorationCollection_Add(decorations, underline);
- OS.GCHandle_Free(underline);
- //FALLTHROU
- case SWT.UNDERLINE_LINK:
- case SWT.UNDERLINE_SINGLE:
- underline = OS.gcnew_TextDecoration(OS.TextDecorationLocation_Underline, pen, 0, OS.TextDecorationUnit_FontRecommended, OS.TextDecorationUnit_FontRecommended);
- OS.TextDecorationCollection_Add(decorations, underline);
- OS.GCHandle_Free(underline);
- break;
- }
- if (pen != 0) OS.GCHandle_Free(pen);
- }
- }
- run.textProperties = OS.gcnew_SWTTextRunProperties(styleFont.handle, styleFont.size, styleFont.size, decorations, fg, bg, OS.BaselineAlignment_Baseline, culture);
- if (fg != 0) OS.GCHandle_Free(fg);
- if (bg != 0) OS.GCHandle_Free(bg);
- if (decorations != 0) OS.GCHandle_Free(decorations);
- }
- }
- int textAlignment = OS.TextAlignment_Left;
- if (justify) {
- textAlignment = OS.TextAlignment_Justify;
- } else {
- switch (alignment) {
- case SWT.CENTER: textAlignment = OS.TextAlignment_Center; break;
- case SWT.RIGHT: textAlignment = OS.TextAlignment_Right; break;
- }
- }
- int flowDirection = (orientation & SWT.RIGHT_TO_LEFT) != 0 ? OS.FlowDirection_RightToLeft : OS.FlowDirection_LeftToRight;
- int textWrapping = wrapWidth != -1 ? OS.TextWrapping_Wrap : OS.TextWrapping_NoWrap;
- int tabCollection = 0;
- if (tabs != null) {
- int position = 0;
- int tabLength = Math.max(tabs.length, TAB_COUNT), i;
- tabCollection = OS.gcnew_TextTabPropertiesCollection(tabLength);
- for (i = 0; i < tabs.length; i++) {
- position = tabs[i];
- int tab = OS.gcnew_TextTabProperties(OS.TextTabAlignment_Left, position, 0, 0);
- OS.TextTabPropertiesCollection_Add(tabCollection, tab);
- OS.GCHandle_Free(tab);
- }
- int width = tabs[tabs.length - 1];
- if (tabs.length > 1) width -= tabs[tabs.length - 2];
- if (width > 0) {
- for (; i < length; i++) {
- position += width;
- int tab = OS.gcnew_TextTabProperties(OS.TextTabAlignment_Left, position, 0, 0);
- OS.TextTabPropertiesCollection_Add(tabCollection, tab);
- OS.GCHandle_Free(tab);
- }
- }
- }
- int paragraphProperties = OS.gcnew_SWTTextParagraphProperties(flowDirection, textAlignment, false, defaultTextProperties, textWrapping, 0, 0, tabCollection);
- int firstParagraphProperties = OS.gcnew_SWTTextParagraphProperties(flowDirection, textAlignment, true, defaultTextProperties, textWrapping, 0, indent, tabCollection);
- int offset = 0;
- int index = 0;
- lines = new int[4];
- int lineBreak = 0;
- while (offset < length || offset == 0) {
- char ch;
- boolean firstLine = offset == 0 || (ch = segmentsText.charAt(offset - 1)) == '\r' || ch == '\n';
- int paragraphProps = firstLine ? firstParagraphProperties : paragraphProperties;
- int textLine = OS.TextFormatter_FormatLine(formatter, textSource, offset, wrapWidth != -1 ? wrapWidth : 0, paragraphProps, lineBreak);
- offset += OS.TextLine_Length(textLine);
- lineBreak = OS.TextLine_GetTextLineBreak(textLine);
- if (index == lines.length) {
- int[] tmpLines = new int[index + 4];
- System.arraycopy(lines, 0, tmpLines, 0, index);
- lines = tmpLines;
- }
- lines[index++] = textLine;
- }
- if (index != lines.length) {
- int[] tmpLines = new int[index];
- System.arraycopy(lines, 0, tmpLines, 0, index);
- lines = tmpLines;
- }
- if (tabCollection != 0) OS.GCHandle_Free(tabCollection);
- OS.GCHandle_Free(paragraphProperties);
- OS.GCHandle_Free(firstParagraphProperties);
- OS.GCHandle_Free(culture);
- OS.GCHandle_Free(formatter);
- OS.GCHandle_Free(textSource);
- OS.DeleteGlobalRef(jniRef);
-}
-
- void destroy() {
- freeRuns();
- font = null;
- text = null;
- segmentsText = null;
- tabs = null;
- styles = null;
-// lineOffset = null;
-// lineY = null;
-// lineWidth = null;
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- *
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- */
-public void draw (GC gc, int x, int y) {
- draw(gc, x, y, -1, -1, null, null);
-}
-
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- *
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param selectionStart the offset where the selections starts, or -1 indicating no selection
- * @param selectionEnd the offset where the selections ends, or -1 indicating no selection
- * @param selectionForeground selection foreground, or NULL to use the system default color
- * @param selectionBackground selection background, or NULL to use the system default color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- */
-public void draw (GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground) {
- draw(gc, x, y, selectionStart, selectionEnd, selectionForeground, selectionBackground, 0);
-}
-/**
- * Draws the receiver's text using the specified GC at the specified
- * point.
- * <p>
- * The parameter <code>flags</code> can include one of <code>SWT.DELIMITER_SELECTION</code>
- * or <code>SWT.FULL_SELECTION</code> to specify the selection behavior on all lines except
- * for the last line, and can also include <code>SWT.LAST_LINE_SELECTION</code> to extend
- * the specified selection behavior to the last line.
- * </p>
- * @param gc the GC to draw
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param selectionStart the offset where the selections starts, or -1 indicating no selection
- * @param selectionEnd the offset where the selections ends, or -1 indicating no selection
- * @param selectionForeground selection foreground, or NULL to use the system default color
- * @param selectionBackground selection background, or NULL to use the system default color
- * @param flags drawing options
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * </ul>
- *
- * @since 3.3
- */
-public void draw (GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags) {
- checkLayout();
- computeRuns();
- if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (selectionForeground != null && selectionForeground.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (selectionBackground != null && selectionBackground.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int length = text.length();
- if (length == 0 && flags == 0) return;
- gc.checkGC(GC.FOREGROUND);
- int fg = OS.Pen_Brush(gc.data.pen);
- OS.SWTTextRunProperties_ForegroundBrush(defaultTextProperties, fg);
- for (int i = 0; i < styles.length; i++) {
- StyleItem run = styles[i];
- if (run.textProperties == 0) continue;
- if (run.style != null && run.style.foreground != null) continue;
- if (run.style != null && run.style.underline && run.style.underlineStyle == SWT.UNDERLINE_LINK) continue;
- OS.SWTTextRunProperties_ForegroundBrush(run.textProperties, fg);
- }
- int drawingContext = gc.handle;
- boolean hasSelection = selectionStart <= selectionEnd && selectionStart != -1 && selectionEnd != -1;
- int selBrush = 0, selGeometry = 0, geometries = 0;
- if (hasSelection || (flags & SWT.LAST_LINE_SELECTION) != 0) {
- selectionStart = Math.min(Math.max(0, selectionStart), length - 1);
- selectionEnd = Math.min(Math.max(0, selectionEnd), length - 1);
- selectionStart = translateOffset(selectionStart);
- selectionEnd = translateOffset(selectionEnd);
- if (selectionBackground != null) {
- selBrush = OS.gcnew_SolidColorBrush(selectionBackground.handle);
- } else {
- selBrush = OS.Brushes_LightSkyBlue();
- }
- selGeometry = OS.gcnew_GeometryGroup();
- geometries = OS.GeometryGroup_Children(selGeometry);
- }
- int lineStart = 0, lineEnd = 0;
- double drawY = y;
- for (int i = 0; i < lines.length; i++) {
- int line = lines[i];
- if (line == 0) break;
- lineStart = lineEnd;
- lineEnd = lineStart + OS.TextLine_Length(line);
- double nextDrawY, selY = drawY;
- int lineHeight = (int)OS.TextLine_Height(line);
- if (ascent != -1 && descent != -1) {
- lineHeight = Math.max(lineHeight, ascent + descent);
- nextDrawY = drawY + lineHeight + lineSpacing;
- int baseline = (int)OS.TextLine_Baseline(line);
- if (ascent > baseline) drawY += ascent - baseline;
- } else {
- nextDrawY = drawY + lineHeight + lineSpacing;
- }
-
- //draw line text
- int point = OS.gcnew_Point(x, drawY);
- OS.TextLine_Draw(line, drawingContext, point, 0);
- OS.GCHandle_Free(point);
-
- //draw line selection
- boolean fullSelection = selectionStart <= lineStart && selectionEnd >= lineEnd;
- boolean partialSelection = !(selectionStart > lineEnd || lineStart > selectionEnd);
- if (flags != 0 && (hasSelection || (flags & SWT.LAST_LINE_SELECTION) != 0)) {
- boolean extent = false;
- if (i == lines.length - 1 && (flags & SWT.LAST_LINE_SELECTION) != 0) {
- extent = true;
- } else {
- int breakLength = OS.TextLine_NewlineLength(line);
- if (breakLength != 0) {
- if (selectionStart <= lineEnd && lineEnd <= selectionEnd) extent = true;
- } else {
- if (selectionStart <= lineEnd && lineEnd < selectionEnd && (flags & SWT.FULL_SELECTION) != 0) {
- extent = true;
- }
- }
- }
- if (extent) {
- int extentWidth = (flags & SWT.FULL_SELECTION) != 0 ? 0x7ffffff : lineHeight / 3;
- int textRect = OS.gcnew_Rect(OS.TextLine_WidthIncludingTrailingWhitespace(line) + x, selY, extentWidth, lineHeight);
- int geometry = OS.gcnew_RectangleGeometry(textRect);
- OS.GeometryCollection_Add(geometries, geometry);
- OS.GCHandle_Free(geometry);
- OS.GCHandle_Free(textRect);
- }
- }
- if (hasSelection && (fullSelection || partialSelection)) {
- int selLineStart = Math.max (lineStart, selectionStart);
- int selLineEnd = Math.min (lineEnd, selectionEnd);
- int rects = OS.TextLine_GetTextBounds(line, selLineStart, selLineEnd - selLineStart + 1);
- if (rects != 0) {
- int enumerator = OS.TextBoundsCollection_GetEnumerator(rects);
- while (OS.IEnumerator_MoveNext(enumerator)) {
- int bounds = OS.TextBoundsCollection_Current(enumerator);
- int textRect = OS.TextBounds_Rectangle(bounds);
- OS.Rect_X(textRect, OS.Rect_X(textRect) + x);
- OS.Rect_Y(textRect, selY);
- OS.Rect_Height(textRect, lineHeight);
- int geometry = OS.gcnew_RectangleGeometry(textRect);
- OS.GeometryCollection_Add(geometries, geometry);
- OS.GCHandle_Free(geometry);
- OS.GCHandle_Free(textRect);
- OS.GCHandle_Free(bounds);
- }
- OS.GCHandle_Free(enumerator);
- }
- OS.GCHandle_Free(rects);
- }
-
- drawY = nextDrawY;
- }
- for (int i = 0; i < styles.length - 1; i++) {
- StyleItem run = styles[i];
- TextStyle style = run.style;
- if (style == null) continue;
- if (style.borderStyle != SWT.NONE && (i + 1 >= styles.length || !style.isAdherentBorder(styles[i + 1].style))) {
- int start = run.start;
- int end = styles[i + 1].start - 1;
- for (int j = i; j > 0 && style.isAdherentBorder(styles[j - 1].style); j--) {
- start = styles[j - 1].start;
- }
- Color color = style.borderColor;
- if (color == null) color = style.foreground;
- if (color == null) color = gc.getForeground();
- int brush = OS.gcnew_SolidColorBrush(color.handle);
- int pen = OS.gcnew_Pen(brush, 1);
- OS.GCHandle_Free(brush);
- int dashStyle = 0;
- switch (style.borderStyle) {
- case SWT.BORDER_SOLID:
- dashStyle = OS.DashStyles_Solid(); break;
- case SWT.BORDER_DOT:
- dashStyle = OS.DashStyles_Dot(); break;
- case SWT.BORDER_DASH:
- dashStyle = OS.DashStyles_Dash(); break;
- }
- OS.Pen_DashStyle(pen, dashStyle);
- if (dashStyle != 0) OS.GCHandle_Free(dashStyle);
- int lineY = y;
- lineStart = lineEnd = 0;
- for (int j = 0; j < lines.length; j++) {
- int lineLength = OS.TextLine_Length(lines[j]);
- lineStart = lineEnd;
- lineEnd = lineStart + lineLength;
- if (start < lineEnd) {
- if (end < lineStart) break;
- int rangeStart = Math.max(start, lineStart);
- int rangLength = Math.min(end, lineEnd) - rangeStart + 1;
- int rects = OS.TextLine_GetTextBounds(lines[j], rangeStart, rangLength);
- if (rects != 0) {
- int enumerator = OS.TextBoundsCollection_GetEnumerator(rects);
- while (OS.IEnumerator_MoveNext(enumerator)) {
- int bounds = OS.TextBoundsCollection_Current(enumerator);
- int textRect = OS.TextBounds_Rectangle(bounds);
- OS.Rect_Y(textRect, OS.Rect_Y(textRect) + lineY);
- OS.Rect_X(textRect, OS.Rect_X(textRect) + x);
- OS.Rect_Width(textRect, OS.Rect_Width(textRect) - 1);
- OS.Rect_Height(textRect, OS.Rect_Height(textRect) - 1);
- OS.DrawingContext_DrawRectangle(drawingContext, 0, pen, textRect);
- OS.GCHandle_Free(textRect);
- OS.GCHandle_Free(bounds);
- }
- OS.GCHandle_Free(enumerator);
- }
- OS.GCHandle_Free(rects);
- }
- int lineHeight = (int)OS.TextLine_Height(lines[j]);
- if (ascent != -1 && descent != -1) lineHeight = Math.max(lineHeight, ascent + descent);
- lineY += lineHeight + lineSpacing;
- }
- OS.GCHandle_Free(pen);
- }
- }
-
- if (selGeometry != 0) {
- OS.DrawingContext_PushOpacity(drawingContext, 0.4);
- OS.DrawingContext_DrawGeometry(drawingContext, selBrush, 0, selGeometry);
- OS.DrawingContext_Pop(drawingContext);
- OS.GCHandle_Free(geometries);
- OS.GCHandle_Free(selGeometry);
- }
- if (selBrush != 0) OS.GCHandle_Free(selBrush);
- OS.GCHandle_Free(fg);
-}
-
-void freeRuns () {
- if (lines == null) return;
- for (int i = 0; i < lines.length; i++) {
- if (lines[i] != 0) {
- OS.GCHandle_Free(lines[i]);
- }
- }
- lines = null;
- if (runs != null) {
- for (int i = 0; i < runs.length; i++) {
- if (runs[i] == 0) break;
- OS.GCHandle_Free(runs[i]);
- }
- runs = null;
- }
- for (int i = 0; i < styles.length; i++) {
- styles[i].free();
- }
- if (defaultTextProperties != 0) OS.GCHandle_Free(defaultTextProperties);
- if (string != 0) OS.GCHandle_Free(string);
- defaultTextProperties = string = 0;
- segmentsText = null;
-}
-
-/**
- * Returns the receiver's horizontal text alignment, which will be one
- * of <code>SWT.LEFT</code>, <code>SWT.CENTER</code> or
- * <code>SWT.RIGHT</code>.
- *
- * @return the alignment used to positioned text horizontally
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getAlignment () {
- checkLayout();
- return alignment;
-}
-
-/**
- * Returns the ascent of the receiver.
- *
- * @return the ascent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getDescent()
- * @see #setDescent(int)
- * @see #setAscent(int)
- * @see #getLineMetrics(int)
- */
-public int getAscent () {
- checkLayout();
- return ascent;
-}
-
-/**
- * Returns the bounds of the receiver. The width returned is either the
- * width of the longest line or the width set using {@link TextLayout#setWidth(int)}.
- * To obtain the text bounds of a line use {@link TextLayout#getLineBounds(int)}.
- *
- * @return the bounds of the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setWidth(int)
- * @see #getLineBounds(int)
- */
-public Rectangle getBounds () {
- checkLayout();
- computeRuns();
- double width = 0;
- double height = 0;
- for (int line=0; line<lines.length; line++) {
- if (wrapWidth == -1) width = Math.max(width, OS.TextLine_WidthIncludingTrailingWhitespace(lines[line]));
- int lineHeight = (int)OS.TextLine_Height(lines[line]);
- if (ascent != -1 && descent != -1) lineHeight = Math.max(lineHeight, ascent + descent);
- height += lineHeight + lineSpacing;
- }
- if (wrapWidth != -1) width = wrapWidth;
- return new Rectangle (0, 0, (int)width, (int)height);
-}
-
-/**
- * Returns the bounds for the specified range of characters. The
- * bounds is the smallest rectangle that encompasses all characters
- * in the range. The start and end offsets are inclusive and will be
- * clamped if out of range.
- *
- * @param start the start offset
- * @param end the end offset
- * @return the bounds of the character range
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds (int start, int end) {
- checkLayout();
- computeRuns();
- int length = text.length();
- if (length == 0) return new Rectangle(0, 0, 0, 0);
- if (start > end) return new Rectangle(0, 0, 0, 0);
- start = Math.min(Math.max(0, start), length - 1);
- end = Math.min(Math.max(0, end), length - 1);
- start = translateOffset(start);
- end = translateOffset(end);
- int lineStart = 0, lineEnd = 0, lineY = 0;
- int rect = 0;
- for (int i = 0; i < lines.length; i++) {
- int lineLength = OS.TextLine_Length(lines[i]);
- lineStart = lineEnd;
- lineEnd = lineStart + lineLength;
- if (start < lineEnd) {
- if (end < lineStart) break;
- int rangeStart = Math.max(start, lineStart);
- int rangLength = Math.min(end, lineEnd) - rangeStart + 1;
- int rects = OS.TextLine_GetTextBounds(lines[i], rangeStart, rangLength);
- if (rects != 0) {
- int enumerator = OS.TextBoundsCollection_GetEnumerator(rects);
- while (OS.IEnumerator_MoveNext(enumerator)) {
- int bounds = OS.TextBoundsCollection_Current(enumerator);
- int textRect = OS.TextBounds_Rectangle(bounds);
- OS.Rect_Y(textRect, OS.Rect_Y(textRect) + lineY);
- if (rect != 0) {
- OS.Rect_Union(rect, textRect);
- OS.GCHandle_Free(textRect);
- } else {
- rect = textRect;
- }
- OS.GCHandle_Free(bounds);
- }
- OS.GCHandle_Free(enumerator);
- }
- OS.GCHandle_Free(rects);
- }
- int lineHeight = (int)OS.TextLine_Height(lines[i]);
- if (ascent != -1 && descent != -1) lineHeight = Math.max(lineHeight, ascent + descent);
- lineY += lineHeight + lineSpacing;
- }
- if (rect == 0) return new Rectangle(0, 0, 0, 0);
- Rectangle result = new Rectangle((int)OS.Rect_X(rect), (int)OS.Rect_Y(rect), (int)OS.Rect_Width(rect), (int)OS.Rect_Height(rect));
- OS.GCHandle_Free(rect);
- return result;
-}
-
-/**
- * Returns the descent of the receiver.
- *
- * @return the descent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getAscent()
- * @see #setAscent(int)
- * @see #setDescent(int)
- * @see #getLineMetrics(int)
- */
-public int getDescent () {
- checkLayout();
- return descent;
-}
-
-/**
- * Returns the default font currently being used by the receiver
- * to draw and measure text.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Font getFont () {
- checkLayout();
- return font;
-}
-
-/**
-* Returns the receiver's indent.
-*
-* @return the receiver's indent
-*
-* @exception SWTException <ul>
-* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
-* </ul>
-*
-* @since 3.2
-*/
-public int getIndent () {
- checkLayout();
- return indent;
-}
-
-/**
-* Returns the receiver's justification.
-*
-* @return the receiver's justification
-*
-* @exception SWTException <ul>
-* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
-* </ul>
-*
-* @since 3.2
-*/
-public boolean getJustify () {
- checkLayout();
- return justify;
-}
-
-/**
- * Returns the embedding level for the specified character offset. The
- * embedding level is usually used to determine the directionality of a
- * character in bidirectional text.
- *
- * @param offset the character offset
- * @return the embedding level
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- */
-public int getLevel (int offset) {
- checkLayout();
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- offset = translateOffset(offset);
- int level = (orientation & SWT.RIGHT_TO_LEFT) != 0 ? 1 : 0;
- for (int i = 0; i < lines.length; i++) {
- int lineLength = OS.TextLine_Length(lines[i]);
- if (lineLength > offset) {
- int runs = OS.TextLine_GetIndexedGlyphRuns (lines[i]);
- int enumerator = OS.IndexedGlyphRunCollection_GetEnumerator(runs);
- while (OS.IEnumerator_MoveNext(enumerator)) {
- int indexedGlyphRun = OS.IndexedGlyphRunCollection_Current(enumerator);
- int rangeStart = OS.IndexedGlyphRun_TextSourceCharacterIndex(indexedGlyphRun);
- int rangeEnd = rangeStart + OS.IndexedGlyphRun_TextSourceLength(indexedGlyphRun);
- int glyphRun = OS.IndexedGlyphRun_GlyphRun(indexedGlyphRun);
- int bidiLevel = OS.GlyphRun_BidiLevel(glyphRun);
- OS.GCHandle_Free(glyphRun);
- OS.GCHandle_Free(indexedGlyphRun);
- if (rangeStart <= offset && offset < rangeEnd) {
- level = bidiLevel;
- break;
- }
- }
- OS.GCHandle_Free(enumerator);
- OS.GCHandle_Free(runs);
- break;
- }
- }
- return level;
-}
-
-/**
- * Returns the bounds of the line for the specified line index.
- *
- * @param lineIndex the line index
- * @return the line bounds
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getLineBounds(int lineIndex) {
- checkLayout();
- computeRuns();
- if (!(0 <= lineIndex && lineIndex < runs.length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- int offset = 0;
- double y = 0;
- for (int i=0; i<lineIndex; i++) {
- offset += OS.TextLine_Length(lines[i]);
- int lineHeight = (int)OS.TextLine_Height(lines[i]);
- if (ascent != -1 && descent != -1) lineHeight = Math.max(lineHeight, ascent + descent);
- y += lineHeight + lineSpacing;
- }
- int line = lines[lineIndex];
- double x = OS.TextLine_Start(line);
- double width = OS.TextLine_WidthIncludingTrailingWhitespace(line);
- double height = OS.TextLine_Height(line);
- if (ascent != -1 && descent != -1) height = Math.max(height, ascent + descent);
- char ch;
- boolean firstLine = offset == 0 || (ch = segmentsText.charAt(offset - 1)) == '\r' || ch == '\n';
- if (firstLine) {
- x += indent;
- width -= indent;
- }
- return new Rectangle ((int)x, (int)y, (int)width, (int)height);
-}
-
-/**
- * Returns the receiver's line count. This includes lines caused
- * by wrapping.
- *
- * @return the line count
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineCount () {
- checkLayout();
- computeRuns();
- return lines.length;
-}
-
-/**
- * Returns the index of the line that contains the specified
- * character offset.
- *
- * @param offset the character offset
- * @return the line index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getLineIndex (int offset) {
- checkLayout();
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- offset = translateOffset(offset);
- int start = 0;
- for (int line=0; line<lines.length; line++) {
- int lineLength = OS.TextLine_Length(lines[line]);
- if (start + lineLength > offset) return line;
- start += lineLength;
- }
- return lines.length - 1;
-}
-
-/**
- * Returns the font metrics for the specified line index.
- *
- * @param lineIndex the line index
- * @return the font metrics
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public FontMetrics getLineMetrics (int lineIndex) {
- checkLayout();
- computeRuns();
- if (!(0 <= lineIndex && lineIndex < runs.length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- int length = text.length();
- double baseline, height;
- if (length == 0) {
- Font font = this.font != null ? this.font : device.systemFont;
- int str = OS.gcnew_String (new char []{' ', '\0'});
- int culture = OS.CultureInfo_CurrentUICulture();
- int direction = (orientation & SWT.RIGHT_TO_LEFT) != 0 ? OS.FlowDirection_RightToLeft : OS.FlowDirection_LeftToRight;
- int brush = OS.Brushes_White();
- int text = OS.gcnew_FormattedText(str, culture, direction, font.handle, font.size, brush);
- height = OS.FormattedText_Height(text);
- baseline = OS.FormattedText_Baseline(text);
- OS.GCHandle_Free(text);
- OS.GCHandle_Free(str);
- OS.GCHandle_Free(brush);
- OS.GCHandle_Free(culture);
- } else {
- baseline = OS.TextLine_Baseline(lines[lineIndex]);
- height = OS.TextLine_Height(lines[lineIndex]);
- if (ascent != -1 && descent != -1) {
- baseline = Math.max(baseline, ascent);
- height = Math.max(height, ascent + descent);
- }
- }
- return FontMetrics.wpf_new((int)baseline, (int)height - (int)baseline, 0, 0, (int)height);
-}
-
-/**
- * Returns the line offsets. Each value in the array is the
- * offset for the first character in a line except for the last
- * value, which contains the length of the text.
- *
- * @return the line offsets
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getLineOffsets () {
- checkLayout();
- computeRuns();
- int start = 0;
- int[] offsets = new int[lines.length+1];
- for (int i = 0; i < lines.length; i++) {
- start += OS.TextLine_Length(lines[i]);
- offsets[i+1] = untranslateOffset(start);
- }
- return offsets;
-}
-
-/**
- * Returns the location for the specified character offset. The
- * <code>trailing</code> argument indicates whether the offset
- * corresponds to the leading or trailing edge of the cluster.
- *
- * @param offset the character offset
- * @param trailing the trailing flag
- * @return the location of the character offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getOffset(Point, int[])
- * @see #getOffset(int, int, int[])
- */
-public Point getLocation (int offset, boolean trailing) {
- checkLayout();
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- offset = translateOffset(offset);
- double y = 0;
- int start = 0, line;
- for (line=0; line<lines.length; line++) {
- int lineLength = OS.TextLine_Length(lines[line]);
- if (start + lineLength > offset) break;
- start += lineLength;
- int lineHeight = (int)OS.TextLine_Height(lines[line]);
- if (ascent != -1 && descent != -1) lineHeight = Math.max(lineHeight, ascent + descent);
- y += lineHeight + lineSpacing;
- }
- int characterHit = OS.gcnew_CharacterHit(offset, trailing ? 1 : 0);
- double x = OS.TextLine_GetDistanceFromCharacterHit(lines[line], characterHit);
- OS.GCHandle_Free(characterHit);
- return new Point((int)x, (int)y);
-}
-
-/**
- * Returns the next offset for the specified offset and movement
- * type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>,
- * <code>SWT.MOVEMENT_CLUSTER</code>, <code>SWT.MOVEMENT_WORD</code>,
- * <code>SWT.MOVEMENT_WORD_END</code> or <code>SWT.MOVEMENT_WORD_START</code>.
- *
- * @param offset the start offset
- * @param movement the movement type
- * @return the next offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getPreviousOffset(int, int)
- */
-public int getNextOffset (int offset, int movement) {
- checkLayout();
- return _getOffset (offset, movement, true);
-}
-
-int _getOffset(int offset, int movement, boolean forward) {
- computeRuns();
- int length = text.length();
- if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- if (forward && offset == length) return length;
- if (!forward && offset == 0) return 0;
- int step = forward ? 1 : -1;
- if ((movement & SWT.MOVEMENT_CHAR) != 0) return offset + step;
- offset = translateOffset(offset);
- int lineStart = 0, lineIndex;
- for (lineIndex=0; lineIndex<lines.length; lineIndex++) {
- int lineLength = OS.TextLine_Length(lines[lineIndex]);
- if (lineStart + lineLength > offset) break;
- lineStart += lineLength;
- }
- int line = lines[lineIndex];
- int lineLength = OS.TextLine_Length(line);
- int lineBreak = OS.TextLine_NewlineLength (line);
- while (lineStart <= offset && offset <= lineStart + lineLength) {
- int resultCharHit;
- int characterHit = OS.gcnew_CharacterHit(offset, 0);
- if (forward) {
- resultCharHit = OS.TextLine_GetNextCaretCharacterHit(line, characterHit);
- } else {
- resultCharHit = OS.TextLine_GetPreviousCaretCharacterHit(line, characterHit);
- }
- int newOffset = OS.CharacterHit_FirstCharacterIndex(resultCharHit);
- int trailing = OS.CharacterHit_TrailingLength(resultCharHit);
- OS.GCHandle_Free(resultCharHit);
- OS.GCHandle_Free(characterHit);
- if (forward) {
- if (newOffset + trailing >= lineStart + lineLength - lineBreak) {
- int lineEnd = lineStart + lineLength;
- if (trailing != 0) lineEnd -= lineBreak;
- return untranslateOffset(Math.min(length, lineEnd));
- }
- } else {
- if (newOffset + trailing == lineStart) {
- if (lineIndex == 0) return 0;
- int lineEnd = 0;
- if (newOffset + trailing == offset) lineEnd = OS.TextLine_NewlineLength(lines[lineIndex - 1]);
- return untranslateOffset(Math.max(0, newOffset + trailing - lineEnd));
- }
- }
- offset = newOffset + trailing;
-
- switch (movement) {
- case SWT.MOVEMENT_CLUSTER:
- return untranslateOffset(offset);
- case SWT.MOVEMENT_WORD:
- case SWT.MOVEMENT_WORD_START: {
- if (offset > 0) {
- boolean letterOrDigit = Compatibility.isLetterOrDigit(segmentsText.charAt(offset));
- boolean previousLetterOrDigit = Compatibility.isLetterOrDigit(segmentsText.charAt(offset - 1));
- if (letterOrDigit != previousLetterOrDigit || !letterOrDigit) {
- if (!Compatibility.isWhitespace(segmentsText.charAt(offset))) {
- return untranslateOffset(offset);
- }
- }
- }
- break;
- }
- case SWT.MOVEMENT_WORD_END: {
- if (offset > 0) {
- boolean isLetterOrDigit = Compatibility.isLetterOrDigit(segmentsText.charAt(offset));
- boolean previousLetterOrDigit = Compatibility.isLetterOrDigit(segmentsText.charAt(offset - 1));
- if (!isLetterOrDigit && previousLetterOrDigit) {
- return untranslateOffset(offset);
- }
- }
- break;
- }
- }
- }
- return forward ? length : 0;
-}
-
-/**
- * Returns the character offset for the specified point.
- * For a typical character, the trailing argument will be filled in to
- * indicate whether the point is closer to the leading edge (0) or
- * the trailing edge (1). When the point is over a cluster composed
- * of multiple characters, the trailing argument will be filled with the
- * position of the character in the cluster that is closest to
- * the point.
- *
- * @param point the point
- * @param trailing the trailing buffer
- * @return the character offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getLocation(int, boolean)
- */
-public int getOffset (Point point, int[] trailing) {
- checkLayout();
- if (point == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return getOffset (point.x, point.y, trailing) ;
-}
-
-/**
- * Returns the character offset for the specified point.
- * For a typical character, the trailing argument will be filled in to
- * indicate whether the point is closer to the leading edge (0) or
- * the trailing edge (1). When the point is over a cluster composed
- * of multiple characters, the trailing argument will be filled with the
- * position of the character in the cluster that is closest to
- * the point.
- *
- * @param x the x coordinate of the point
- * @param y the y coordinate of the point
- * @param trailing the trailing buffer
- * @return the character offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getLocation(int, boolean)
- */
-public int getOffset (int x, int y, int[] trailing) {
- checkLayout();
- computeRuns();
- if (trailing != null && trailing.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- double lineY = 0;
- int line;
- for (line=0; line<lines.length; line++) {
- double lineHeight = OS.TextLine_Length(lines[line]);
- if (lineY + lineHeight > y) break;
- lineY += lineHeight;
- }
- if (line >= lines.length) line = lines.length - 1;
- int characterHit = OS.TextLine_GetCharacterHitFromDistance(lines[line], x);
- int offset = OS.CharacterHit_FirstCharacterIndex(characterHit);
- if (trailing != null) trailing[0] = OS.CharacterHit_TrailingLength(characterHit);
- OS.GCHandle_Free(characterHit);
- return untranslateOffset(offset);
-}
-
-/**
- * Returns the orientation of the receiver.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getOrientation () {
- checkLayout();
- return orientation;
-}
-
-/**
- * Returns the previous offset for the specified offset and movement
- * type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>,
- * <code>SWT.MOVEMENT_CLUSTER</code> or <code>SWT.MOVEMENT_WORD</code>,
- * <code>SWT.MOVEMENT_WORD_END</code> or <code>SWT.MOVEMENT_WORD_START</code>.
- *
- * @param offset the start offset
- * @param movement the movement type
- * @return the previous offset
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getNextOffset(int, int)
- */
-public int getPreviousOffset (int offset, int movement) {
- checkLayout();
- return _getOffset (offset, movement, false);
-}
-
-/**
- * Gets the ranges of text that are associated with a <code>TextStyle</code>.
- *
- * @return the ranges, an array of offsets representing the start and end of each
- * text style.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getStyles()
- *
- * @since 3.2
- */
-public int[] getRanges () {
- checkLayout();
- int[] result = new int[styles.length * 2];
- int count = 0;
- for (int i=0; i<styles.length - 1; i++) {
- if (styles[i].style != null) {
- result[count++] = styles[i].start;
- result[count++] = styles[i + 1].start - 1;
- }
- }
- if (count != result.length) {
- int[] newResult = new int[count];
- System.arraycopy(result, 0, newResult, 0, count);
- result = newResult;
- }
- return result;
-}
-
-/**
- * Returns the text segments offsets of the receiver.
- *
- * @return the text segments offsets
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getSegments () {
- checkLayout();
- return segments;
-}
-
-String getSegmentsText() {
- if (segments == null) return text;
- int nSegments = segments.length;
- if (nSegments <= 1) return text;
- int length = text.length();
- if (length == 0) return text;
- if (nSegments == 2) {
- if (segments[0] == 0 && segments[1] == length) return text;
- }
- char[] oldChars = new char[length];
- text.getChars(0, length, oldChars, 0);
- char[] newChars = new char[length + nSegments];
- int charCount = 0, segmentCount = 0;
- char separator = orientation == SWT.RIGHT_TO_LEFT ? RTL_MARK : LTR_MARK;
- while (charCount < length) {
- if (segmentCount < nSegments && charCount == segments[segmentCount]) {
- newChars[charCount + segmentCount++] = separator;
- } else {
- newChars[charCount + segmentCount] = oldChars[charCount++];
- }
- }
- if (segmentCount < nSegments) {
- segments[segmentCount] = charCount;
- newChars[charCount + segmentCount++] = separator;
- }
- return new String(newChars, 0, Math.min(charCount + segmentCount, newChars.length));
-}
-
-/**
- * Returns the line spacing of the receiver.
- *
- * @return the line spacing
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getSpacing () {
- checkLayout();
- return lineSpacing;
-}
-
-/**
- * Gets the style of the receiver at the specified character offset.
- *
- * @param offset the text offset
- * @return the style or <code>null</code> if not set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public TextStyle getStyle (int offset) {
- checkLayout();
- int length = text.length();
- if (!(0 <= offset && offset < length)) SWT.error(SWT.ERROR_INVALID_RANGE);
- for (int i=1; i<styles.length; i++) {
- if (styles[i].start > offset) {
- return styles[i - 1].style;
- }
- }
- return null;
-}
-
-/**
- * Gets all styles of the receiver.
- *
- * @return the styles
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getRanges()
- *
- * @since 3.2
- */
-public TextStyle[] getStyles () {
- checkLayout();
- TextStyle[] result = new TextStyle[styles.length];
- int count = 0;
- for (int i=0; i<styles.length; i++) {
- if (styles[i].style != null) {
- result[count++] = styles[i].style;
- }
- }
- if (count != result.length) {
- TextStyle[] newResult = new TextStyle[count];
- System.arraycopy(result, 0, newResult, 0, count);
- result = newResult;
- }
- return result;
-}
-
-/**
- * Returns the tab list of the receiver.
- *
- * @return the tab list
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int[] getTabs () {
- checkLayout();
- return tabs;
-}
-
-int GetTextRun(int textSourceCharacterIndex) {
- if (runs == null) runs = new int[4];
- int index = 0;
- while (index < runs.length && runs[index] != 0) index++;
- if (index == runs.length) {
- int[] tmpRuns = new int[index + 4];
- System.arraycopy(runs, 0, tmpRuns, 0, index);
- runs = tmpRuns;
- }
- int length = OS.String_Length(string);
- if (textSourceCharacterIndex >= length) {
- runs[index] = OS.gcnew_TextEndOfParagraph(1, defaultTextProperties);
- } else {
- int styleIndex = 1;
- while (styleIndex < styles.length && styles[styleIndex].start <= textSourceCharacterIndex) styleIndex++;
- TextStyle textStyle = styles[styleIndex - 1].style;
- int textProperties = styles[styleIndex - 1].textProperties;
- if (textProperties == 0) textProperties = defaultTextProperties;
- int end = styles[styleIndex].start;
- if (textStyle != null && textStyle.metrics != null) {
- GlyphMetrics metrics = textStyle.metrics;
- runs[index] = OS.gcnew_SWTTextEmbeddedObject(textProperties, end - textSourceCharacterIndex, metrics.width, metrics.ascent + metrics.descent, metrics.ascent);
- } else {
- char ch = segmentsText.charAt(textSourceCharacterIndex);
- if (ch == '\n' || ch == '\r') {
- int breakLength = 1;
- if (ch == '\r' && textSourceCharacterIndex + 1 < end && segmentsText.charAt(textSourceCharacterIndex + 1) == '\n') breakLength++;
- runs[index] = OS.gcnew_TextEndOfLine(breakLength, textProperties);
- } else {
- int i = textSourceCharacterIndex;
- while (i < end && (ch = segmentsText.charAt(i)) != '\n' && ch != '\r') i++;
- runs[index] = OS.gcnew_TextCharacters(string, textSourceCharacterIndex, i - textSourceCharacterIndex, textProperties);
- }
- }
- }
- return runs[index];
-}
-
-int GetPrecedingText(int textSourceCharacterIndexLimit) {
- return 0;
-}
-
-/**
- * Gets the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public String getText () {
- checkLayout();
- return text;
-}
-
-/**
- * Returns the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getWidth () {
- checkLayout();
- return wrapWidth;
-}
-
-/**
- * Returns <code>true</code> if the text layout has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the text layout.
- * When a text layout has been disposed, it is an error to
- * invoke any other method using the text layout.
- * </p>
- *
- * @return <code>true</code> when the text layout is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- return device == null;
-}
-
-/**
- * Sets the text alignment for the receiver. The alignment controls
- * how a line of text is positioned horizontally. The argument should
- * be one of <code>SWT.LEFT</code>, <code>SWT.RIGHT</code> or <code>SWT.CENTER</code>.
- * <p>
- * The default alignment is <code>SWT.LEFT</code>. Note that the receiver's
- * width must be set in order to use <code>SWT.RIGHT</code> or <code>SWT.CENTER</code>
- * alignment.
- * </p>
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setWidth(int)
- */
-public void setAlignment (int alignment) {
- checkLayout();
- int mask = SWT.LEFT | SWT.CENTER | SWT.RIGHT;
- alignment &= mask;
- if (alignment == 0) return;
- if ((alignment & SWT.LEFT) != 0) alignment = SWT.LEFT;
- if ((alignment & SWT.RIGHT) != 0) alignment = SWT.RIGHT;
- if (this.alignment == alignment) return;
- freeRuns();
- this.alignment = alignment;
-}
-
-/**
- * Sets the ascent of the receiver. The ascent is distance in pixels
- * from the baseline to the top of the line and it is applied to all
- * lines. The default value is <code>-1</code> which means that the
- * ascent is calculated from the line fonts.
- *
- * @param ascent the new ascent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the ascent is less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setDescent(int)
- * @see #getLineMetrics(int)
- */
-public void setAscent(int ascent) {
- checkLayout();
- if (ascent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.ascent == ascent) return;
- freeRuns();
- this.ascent = ascent;
-}
-
-/**
- * Sets the descent of the receiver. The descent is distance in pixels
- * from the baseline to the bottom of the line and it is applied to all
- * lines. The default value is <code>-1</code> which means that the
- * descent is calculated from the line fonts.
- *
- * @param descent the new descent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the descent is less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAscent(int)
- * @see #getLineMetrics(int)
- */
-public void setDescent(int descent) {
- checkLayout();
- if (descent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.descent == descent) return;
- freeRuns();
- this.descent = descent;
-}
-
-/**
- * Sets the default font which will be used by the receiver
- * to draw and measure text. If the
- * argument is null, then a default font appropriate
- * for the platform will be used instead. Note that a text
- * style can override the default font.
- *
- * @param font the new font for the receiver, or null to indicate a default font
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkLayout();
- if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Font oldFont = this.font;
- if (oldFont == font) return;
- this.font = font;
- if (oldFont != null && oldFont.equals(font)) return;
- freeRuns();
-}
-
-/**
- * Sets the indent of the receiver. This indent it applied of the first line of
- * each paragraph.
- *
- * @param indent new indent
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setIndent (int indent) {
- checkLayout();
- if (indent < 0) return;
- if (this.indent == indent) return;
- freeRuns();
- this.indent = indent;
-}
-
-/**
- * Sets the justification of the receiver. Note that the receiver's
- * width must be set in order to use justification.
- *
- * @param justify new justify
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setJustify (boolean justify) {
- checkLayout();
- if (this.justify == justify) return;
- freeRuns();
- this.justify = justify;
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setOrientation (int orientation) {
- checkLayout();
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- orientation &= mask;
- if (orientation == 0) return;
- if ((orientation & SWT.LEFT_TO_RIGHT) != 0) orientation = SWT.LEFT_TO_RIGHT;
- if (this.orientation == orientation) return;
- this.orientation = orientation;
- freeRuns();
-}
-
-/**
- * Sets the offsets of the receiver's text segments. Text segments are used to
- * override the default behaviour of the bidirectional algorithm.
- * Bidirectional reordering can happen within a text segment but not
- * between two adjacent segments.
- * <p>
- * Each text segment is determined by two consecutive offsets in the
- * <code>segments</code> arrays. The first element of the array should
- * always be zero and the last one should always be equals to length of
- * the text.
- * </p>
- *
- * @param segments the text segments offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setSegments(int[] segments) {
- checkLayout();
- if (this.segments == null && segments == null) return;
- if (this.segments != null && segments != null) {
- if (this.segments.length == segments.length) {
- int i;
- for (i = 0; i <segments.length; i++) {
- if (this.segments[i] != segments[i]) break;
- }
- if (i == segments.length) return;
- }
- }
- freeRuns();
- this.segments = segments;
-}
-
-/**
- * Sets the line spacing of the receiver. The line spacing
- * is the space left between lines.
- *
- * @param spacing the new line spacing
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the spacing is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setSpacing (int spacing) {
- checkLayout();
- if (spacing < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.lineSpacing == spacing) return;
- freeRuns();
- this.lineSpacing = spacing;
-}
-
-/**
- * Sets the style of the receiver for the specified range. Styles previously
- * set for that range will be overwritten. The start and end offsets are
- * inclusive and will be clamped if out of range.
- *
- * @param style the style
- * @param start the start offset
- * @param end the end offset
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setStyle (TextStyle style, int start, int end) {
- checkLayout();
- int length = text.length();
- if (length == 0) return;
- if (start > end) return;
- start = Math.min(Math.max(0, start), length - 1);
- end = Math.min(Math.max(0, end), length - 1);
- int low = -1;
- int high = styles.length;
- while (high - low > 1) {
- int index = (high + low) / 2;
- if (styles[index + 1].start > start) {
- high = index;
- } else {
- low = index;
- }
- }
- if (0 <= high && high < styles.length) {
- StyleItem item = styles[high];
- if (item.start == start && styles[high + 1].start - 1 == end) {
- if (style == null) {
- if (item.style == null) return;
- } else {
- if (style.equals(item.style)) return;
- }
- }
- }
- freeRuns();
- int modifyStart = high;
- int modifyEnd = modifyStart;
- while (modifyEnd < styles.length) {
- if (styles[modifyEnd + 1].start > end) break;
- modifyEnd++;
- }
- if (modifyStart == modifyEnd) {
- int styleStart = styles[modifyStart].start;
- int styleEnd = styles[modifyEnd + 1].start - 1;
- if (styleStart == start && styleEnd == end) {
- styles[modifyStart].style = style;
- return;
- }
- if (styleStart != start && styleEnd != end) {
- StyleItem[] newStyles = new StyleItem[styles.length + 2];
- System.arraycopy(styles, 0, newStyles, 0, modifyStart + 1);
- StyleItem item = new StyleItem();
- item.start = start;
- item.style = style;
- newStyles[modifyStart + 1] = item;
- item = new StyleItem();
- item.start = end + 1;
- item.style = styles[modifyStart].style;
- newStyles[modifyStart + 2] = item;
- System.arraycopy(styles, modifyEnd + 1, newStyles, modifyEnd + 3, styles.length - modifyEnd - 1);
- styles = newStyles;
- return;
- }
- }
- if (start == styles[modifyStart].start) modifyStart--;
- if (end == styles[modifyEnd + 1].start - 1) modifyEnd++;
- int newLength = styles.length + 1 - (modifyEnd - modifyStart - 1);
- StyleItem[] newStyles = new StyleItem[newLength];
- System.arraycopy(styles, 0, newStyles, 0, modifyStart + 1);
- StyleItem item = new StyleItem();
- item.start = start;
- item.style = style;
- newStyles[modifyStart + 1] = item;
- styles[modifyEnd].start = end + 1;
- System.arraycopy(styles, modifyEnd, newStyles, modifyStart + 2, styles.length - modifyEnd);
- styles = newStyles;
-}
-
-/**
- * Sets the receiver's tab list. Each value in the tab list specifies
- * the space in pixels from the origin of the text layout to the respective
- * tab stop. The last tab stop width is repeated continuously.
- *
- * @param tabs the new tab list
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setTabs (int[] tabs) {
- checkLayout();
- if (this.tabs == null && tabs == null) return;
- if (this.tabs != null && tabs !=null) {
- if (this.tabs.length == tabs.length) {
- int i;
- for (i = 0; i <tabs.length; i++) {
- if (this.tabs[i] != tabs[i]) break;
- }
- if (i == tabs.length) return;
- }
- }
- freeRuns();
- this.tabs = tabs;
-}
-
-/**
- * Sets the receiver's text.
- *<p>
- * Note: Setting the text also clears all the styles. This method
- * returns without doing anything if the new text is the same as
- * the current text.
- * </p>
- *
- * @param text the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setText (String text) {
- checkLayout();
- if (text == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (text.equals(this.text)) return;
- freeRuns();
- this.text = text;
- styles = new StyleItem[2];
- styles[0] = new StyleItem();
- styles[1] = new StyleItem();
- styles[1].start = text.length();
-}
-
-/**
- * Sets the line width of the receiver, which determines how
- * text should be wrapped and aligned. The default value is
- * <code>-1</code> which means wrapping is disabled.
- *
- * @param width the new width
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the width is <code>0</code> or less than <code>-1</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setAlignment(int)
- */
-public void setWidth (int width) {
- checkLayout();
- if (width < -1 || width == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.wrapWidth == width) return;
- freeRuns();
- this.wrapWidth = width;
-}
-
-int validadeOffset(int offset, int step) {
- offset += step;
- if (segments != null && segments.length > 2) {
- for (int i = 0; i < segments.length; i++) {
- if (translateOffset(segments[i]) - 1 == offset) {
- offset += step;
- break;
- }
- }
- }
- return offset;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "TextLayout {*DISPOSED*}";
- return "TextLayout {}";
-}
-
-int translateOffset(int offset) {
- if (segments == null) return offset;
- int nSegments = segments.length;
- if (nSegments <= 1) return offset;
- int length = text.length();
- if (length == 0) return offset;
- if (nSegments == 2) {
- if (segments[0] == 0 && segments[1] == length) return offset;
- }
- for (int i = 0; i < nSegments && offset - i >= segments[i]; i++) {
- offset++;
- }
- return offset;
-}
-
-int untranslateOffset(int offset) {
- if (segments == null) return offset;
- int nSegments = segments.length;
- if (nSegments <= 1) return offset;
- int length = text.length();
- if (length == 0) return offset;
- if (nSegments == 2) {
- if (segments[0] == 0 && segments[1] == length) return offset;
- }
- for (int i = 0; i < nSegments && offset > segments[i]; i++) {
- offset--;
- }
- return offset;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Transform.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Transform.java
deleted file mode 100644
index 9bd58865f4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/Transform.java
+++ /dev/null
@@ -1,408 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.wpf.*;
-
-/**
- * Instances of this class represent transformation matrices for
- * points expressed as (x, y) pairs of floating point numbers.
- * <p>
- * Application code must explicitly invoke the <code>Transform.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Transform extends Resource {
-
- /**
- * the OS resource for the Transform
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
-
-/**
- * Constructs a new identity Transform.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform (Device device) {
- this(device, 1, 0, 0, 1, 0, 0);
-}
-
-/**
- * Constructs a new Transform given an array of elements that represent the
- * matrix that describes the transformation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- * @param elements an array of floats that describe the transformation matrix
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device, or the elements array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the elements array is too small to hold the matrix values</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform(Device device, float[] elements) {
- this (device, checkTransform(elements)[0], elements[1], elements[2], elements[3], elements[4], elements[5]);
-}
-
-/**
- * Constructs a new Transform given all of the elements that represent the
- * matrix that describes the transformation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- * @param m11 the first element of the first row of the matrix
- * @param m12 the second element of the first row of the matrix
- * @param m21 the first element of the second row of the matrix
- * @param m22 the second element of the second row of the matrix
- * @param dx the third element of the first row of the matrix
- * @param dy the third element of the second row of the matrix
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform (Device device, float m11, float m12, float m21, float m22, float dx, float dy) {
- super(device);
- handle = OS.gcnew_Matrix(m11, m12, m21, m22, dx, dy);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-static float[] checkTransform(float[] elements) {
- if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return elements;
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the Transform. Applications must dispose of all Transforms that
- * they allocate.
- */
-void destroy() {
- OS.GCHandle_Free(handle);
- handle = 0;
-}
-
-/**
- * Fills the parameter with the values of the transformation matrix
- * that the receiver represents, in the order {m11, m12, m21, m22, dx, dy}.
- *
- * @param elements array to hold the matrix values
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the matrix values</li>
- * </ul>
- */
-public void getElements(float[] elements) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- elements[0] = (float)OS.Matrix_M11(handle);
- elements[1] = (float)OS.Matrix_M12(handle);
- elements[2] = (float)OS.Matrix_M21(handle);
- elements[3] = (float)OS.Matrix_M22(handle);
- elements[4] = (float)OS.Matrix_OffsetX(handle);
- elements[5] = (float)OS.Matrix_OffsetY(handle);
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes the
- * identity matrix.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public void identity() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.Matrix_SetIdentity(handle);
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes
- * the mathematical inverse of the matrix it previously represented.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_CANNOT_INVERT_MATRIX - if the matrix is not invertible</li>
- * </ul>
- */
-public void invert() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.Matrix_Invert(handle);
- //TODO handle matrix invert exception
- //SWT.error(SWT.ERROR_CANNOT_INVERT_MATRIX);
-}
-
-/**
- * Returns <code>true</code> if the Transform has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Transform.
- * When a Transform has been disposed, it is an error to
- * invoke any other method using the Transform.
- *
- * @return <code>true</code> when the Transform is disposed, and <code>false</code> otherwise
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * Returns <code>true</code> if the Transform represents the identity matrix
- * and false otherwise.
- *
- * @return <code>true</code> if the receiver is an identity Transform, and <code>false</code> otherwise
- */
-public boolean isIdentity() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return OS.Matrix_IsIdentity(handle);
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes the
- * the result of multiplying the matrix it previously represented by the
- * argument.
- *
- * @param matrix the matrix to multiply the receiver by
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- */
-public void multiply(Transform matrix) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (matrix == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (matrix.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int result = OS.Matrix_Multiply(handle, matrix.handle);
- OS.Matrix_M11(handle, OS.Matrix_M11(result));
- OS.Matrix_M12(handle, OS.Matrix_M12(result));
- OS.Matrix_M21(handle, OS.Matrix_M21(result));
- OS.Matrix_M22(handle, OS.Matrix_M22(result));
- OS.Matrix_OffsetX(handle, OS.Matrix_OffsetX(result));
- OS.Matrix_OffsetY(handle, OS.Matrix_OffsetY(result));
- OS.GCHandle_Free(result);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation rotated by the specified angle.
- * The angle is specified in degrees and for the identity transform 0 degrees
- * is at the 3 o'clock position. A positive value indicates a clockwise rotation
- * while a negative value indicates a counter-clockwise rotation.
- *
- * @param angle the angle to rotate the transformation by
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void rotate(float angle) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.Matrix_RotatePrepend(handle, angle);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation scaled by (scaleX, scaleY).
- *
- * @param scaleX the amount to scale in the X direction
- * @param scaleY the amount to scale in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void scale(float scaleX, float scaleY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.Matrix_ScalePrepend(handle, scaleX, scaleY);
-}
-
-/**
- * Modifies the receiver to represent a new transformation given all of
- * the elements that represent the matrix that describes that transformation.
- *
- * @param m11 the first element of the first row of the matrix
- * @param m12 the second element of the first row of the matrix
- * @param m21 the first element of the second row of the matrix
- * @param m22 the second element of the second row of the matrix
- * @param dx the third element of the first row of the matrix
- * @param dy the third element of the second row of the matrix
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setElements(float m11, float m12, float m21, float m22, float dx, float dy) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.Matrix_M11(handle, m11);
- OS.Matrix_M12(handle, m12);
- OS.Matrix_M21(handle, m21);
- OS.Matrix_M22(handle, m22);
- OS.Matrix_OffsetX(handle, dx);
- OS.Matrix_OffsetY(handle, dy);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation sheared by (shearX, shearY).
- *
- * @param shearX the shear factor in the X direction
- * @param shearY the shear factor in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public void shear(float shearX, float shearY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int matrix = OS.gcnew_Matrix(1, shearX, shearY, 1, 0, 0);
- int result = OS.Matrix_Multiply(handle, matrix);
- OS.Matrix_M11(handle, OS.Matrix_M11(result));
- OS.Matrix_M12(handle, OS.Matrix_M12(result));
- OS.Matrix_M21(handle, OS.Matrix_M21(result));
- OS.Matrix_M22(handle, OS.Matrix_M22(result));
- OS.Matrix_OffsetX(handle, OS.Matrix_OffsetX(result));
- OS.Matrix_OffsetY(handle, OS.Matrix_OffsetY(result));
- OS.GCHandle_Free(result);
- OS.GCHandle_Free(matrix);
-}
-
-/**
- * Given an array containing points described by alternating x and y values,
- * modify that array such that each point has been replaced with the result of
- * applying the transformation represented by the receiver to that point.
- *
- * @param pointArray an array of alternating x and y values to be transformed
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void transform(float[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- for (int i = 0; i < pointArray.length; i += 2) {
- int point = OS.gcnew_Point(pointArray[i], pointArray[i + 1]);
- int result = OS.Matrix_Transform(handle, point);
- pointArray[i] = (float)OS.Point_X(result);
- pointArray[i + 1] = (float)OS.Point_Y(result);
- OS.GCHandle_Free(point);
- OS.GCHandle_Free(result);
- }
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation translated by (offsetX, offsetY).
- *
- * @param offsetX the distance to translate in the X direction
- * @param offsetY the distance to translate in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void translate(float offsetX, float offsetY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.Matrix_TranslatePrepend(handle, offsetX, offsetY);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString() {
- if (isDisposed()) return "Transform {*DISPOSED*}";
- float[] elements = new float[6];
- getElements(elements);
- return "Transform {" + elements [0] + "," + elements [1] + "," +elements [2] + "," +elements [3] + "," +elements [4] + "," +elements [5] + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Button.java
deleted file mode 100644
index 99237de68e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Button.java
+++ /dev/null
@@ -1,652 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface object that
- * issues notification when pressed and released.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>ARROW, CHECK, PUSH, RADIO, TOGGLE, FLAT</dd>
- * <dd>UP, DOWN, LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles ARROW, CHECK, PUSH, RADIO, and TOGGLE
- * may be specified.
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT, and CENTER may be specified.
- * </p><p>
- * Note: Only one of the styles UP, DOWN, LEFT, and RIGHT may be specified
- * when the ARROW style is specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#button">Button snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Button extends Control {
- String text = "";
- Image image;
- int textHandle, imageHandle;
- boolean ignoreSelection, grayed;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#ARROW
- * @see SWT#CHECK
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#TOGGLE
- * @see SWT#FLAT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Button (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected by the user.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- style = checkBits (style, SWT.PUSH, SWT.ARROW, SWT.CHECK, SWT.RADIO, SWT.TOGGLE, 0);
- if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) {
- return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0);
- }
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0);
- }
- if ((style & SWT.ARROW) != 0) {
- style |= SWT.NO_FOCUS;
- return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0);
- }
- return style;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- Point size = computeSize (handle, wHint, hHint, changed);
- if ((style & SWT.ARROW) == 0) {
- int border = getBorderWidth ();
- size.x += border * 2;
- size.y += border * 2;
- }
- return size;
-}
-
-void createArrow () {
- int geometry = OS.gcnew_StreamGeometry ();
- int context = OS.StreamGeometry_Open (geometry);
- int start = 0, point = 0, end = 0;
- int mask = SWT.RIGHT | SWT.LEFT | SWT.DOWN | SWT.UP;
- switch (style & mask) {
- case SWT.RIGHT:
- start = OS.gcnew_Point (1, 0);
- point = OS.gcnew_Point (4, 3);
- end = OS.gcnew_Point (1, 6);
- break;
- case SWT.LEFT:
- start = OS.gcnew_Point (4, 1);
- point = OS.gcnew_Point (1, 3);
- end = OS.gcnew_Point (4, 6);
- break;
- case SWT.DOWN:
- start = OS.gcnew_Point (0, 1);
- point = OS.gcnew_Point (3, 4);
- end = OS.gcnew_Point (6, 1);
- break;
- case SWT.UP:
- start = OS.gcnew_Point (0, 4);
- point = OS.gcnew_Point (3, 1);
- end = OS.gcnew_Point (6, 4);
- break;
- }
- OS.StreamGeometryContext_BeginFigure (context, start, true, true);
- OS.StreamGeometryContext_LineTo (context, point, true, true);
- OS.StreamGeometryContext_LineTo (context, end, true, true);
- OS.StreamGeometryContext_Close (context);
- int path = OS.gcnew_Path ();
- OS.Path_Data (path, geometry);
- int padding = OS.gcnew_Thickness (3, 3, 3, 3);
- OS.FrameworkElement_Margin (path, padding);
- int brush = OS.Brushes_Black ();
- OS.Path_Fill (path, brush);
- OS.FrameworkElement_Width (path, 6);
- OS.FrameworkElement_Height (path, 6);
- OS.FrameworkElement_HorizontalAlignment (path, OS.HorizontalAlignment_Center);
- OS.FrameworkElement_VerticalAlignment (path, OS.VerticalAlignment_Center);
- OS.ContentControl_Content (handle, path);
- OS.GCHandle_Free (padding);
- OS.GCHandle_Free (start);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (end);
- OS.GCHandle_Free (brush);
- OS.GCHandle_Free (path);
- OS.GCHandle_Free (context);
- OS.GCHandle_Free (geometry);
-}
-
-void createHandle () {
- if ((style & SWT.PUSH) == 0) state |= THEME_BACKGROUND;
- int bits = SWT.TOGGLE | SWT.ARROW | SWT.PUSH | SWT.RADIO | SWT.CHECK;
- switch (style & bits) {
- case SWT.TOGGLE:
- handle = OS.gcnew_ToggleButton ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- break;
- case SWT.ARROW:
- handle = OS.gcnew_Button ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- createArrow ();
- break;
- case SWT.RADIO:
- handle = OS.gcnew_RadioButton ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- break;
- case SWT.CHECK:
- handle = OS.gcnew_CheckBox ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- break;
- case SWT.PUSH:
- default:
- handle = OS.gcnew_Button ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- break;
- }
- if ((style & SWT.ARROW) != 0) return;
- int value = OS.HorizontalAlignment_Left;
- if ((style & SWT.CENTER) != 0) value = OS.HorizontalAlignment_Center;
- if ((style & SWT.RIGHT) != 0) value = OS.HorizontalAlignment_Right;
- OS.Control_HorizontalContentAlignment (handle, value);
- imageHandle = OS.gcnew_Image ();
- if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.Image_Stretch (imageHandle, OS.Stretch_None);
- OS.UIElement_Visibility (imageHandle, OS.Visibility_Collapsed);
- textHandle = OS.gcnew_AccessText ();
- if (textHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.FrameworkElement_VerticalAlignment (textHandle, OS.VerticalAlignment_Center);
- int panel = OS.gcnew_StackPanel ();
- if (panel == 0) error (SWT.ERROR_NO_HANDLES);
- OS.StackPanel_Orientation (panel, OS.Orientation_Horizontal);
- int thickness = OS.gcnew_Thickness (1, 1, 1, 1);
- if (thickness == 0) error (SWT.ERROR_NO_HANDLES);
- OS.FrameworkElement_Margin (panel, thickness);
- OS.GCHandle_Free(thickness);
- int children = OS.Panel_Children (panel);
- OS.UIElementCollection_Add (children, imageHandle);
- OS.UIElementCollection_Add (children, textHandle);
- OS.ContentControl_Content (handle, panel);
- OS.GCHandle_Free (children);
- OS.GCHandle_Free (panel);
-}
-
-int defaultBackground () {
- if ((style & SWT.PUSH) == 0) return OS.SystemColors_ControlColor;
- return 0;
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is an <code>ARROW</code> button, in
- * which case, the alignment will indicate the direction of
- * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>,
- * <code>UP</code> or <code>DOWN</code>).
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget ();
- if ((style & SWT.ARROW) != 0) {
- if ((style & SWT.UP) != 0) return SWT.UP;
- if ((style & SWT.DOWN) != 0) return SWT.DOWN;
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.UP;
- }
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the widget does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getGrayed () {
- checkWidget ();
- if ((style & SWT.CHECK) == 0) return false;
- return grayed;
-}
-
-/**
- * Returns the receiver's image if it has one, or null
- * if it does not.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget ();
- return image;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked. When it is of type <code>TOGGLE</code>,
- * it is selected when it is pushed in. If the receiver is of any other type,
- * this method returns false.
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget ();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false;
- if ((style & SWT.CHECK) != 0 && grayed) {
- int property = OS.ToggleButton_IsCheckedProperty();
- int value = OS.DependencyObject_GetValue(handle, property);
- OS.GCHandle_Free(property);
- if (value == 0) return true;
- OS.GCHandle_Free(value);
- }
- return OS.ToggleButton_IsChecked (handle);
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set or if the receiver is
- * an <code>ARROW</code> button.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- if ((style & SWT.ARROW) != 0) return "";
- return text;
-}
-
-void HandleClick (int sender, int e) {
- if (!checkEvent (e)) return;
- if ((style & SWT.CHECK) != 0) {
- if (grayed) {
- if (OS.ToggleButton_IsChecked (handle)) {
- ignoreSelection = true;
- OS.ToggleButton_IsCheckedNullSetter (handle);
- ignoreSelection = false;
- }
- }
- }
- if (!ignoreSelection) postEvent (SWT.Selection);
-}
-
-void hookEvents () {
- super.hookEvents ();
- if ((style & (SWT.TOGGLE | SWT.RADIO | SWT.CHECK)) != 0) {
- int handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleClick");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ToggleButton_Checked (handle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleClick");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ToggleButton_Unchecked (handle, handler);
- OS.GCHandle_Free (handler);
- } else {
- int handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleClick");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ButtonBase_Click (handle, handler);
- OS.GCHandle_Free (handler);
- }
-}
-
-boolean mnemonicHit (char ch) {
- //TODO
- return false;
-}
-
-boolean mnemonicMatch (char key) {
- return super.mnemonicMatch (textHandle, key);
-}
-
-void releaseHandle() {
- super.releaseHandle ();
- if (textHandle != 0) OS.GCHandle_Free (textHandle);
- textHandle = 0;
- if (imageHandle !=0 )OS.GCHandle_Free (imageHandle);
- imageHandle = 0;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- text = null;
- image = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Controls how text, images and arrows will be displayed
- * in the receiver. The argument should be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is an <code>ARROW</code> button, in
- * which case, the argument indicates the direction of
- * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>,
- * <code>UP</code> or <code>DOWN</code>).
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget ();
- if ((style & SWT.ARROW) != 0) {
- if ((style & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT)) == 0) return;
- style &= ~(SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT);
- style |= alignment & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT);
- createArrow ();
- return;
- }
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- int value = OS.HorizontalAlignment_Left;
- if ((style & SWT.CENTER) != 0) value = OS.HorizontalAlignment_Center;
- if ((style & SWT.RIGHT) != 0) value = OS.HorizontalAlignment_Right;
- OS.Control_HorizontalContentAlignment (handle, value);
-}
-
-/**
- * Sets the grayed state of the receiver. This state change
- * only applies if the control was created with the SWT.CHECK
- * style.
- *
- * @param grayed the new grayed state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setGrayed (boolean grayed) {
- checkWidget ();
- if ((style & SWT.CHECK) == 0) return;
- boolean checked = getSelection();
- this.grayed = grayed;
- ignoreSelection = true;
- if (checked){
- if (grayed) {
- OS.ToggleButton_IsCheckedNullSetter(handle);
- } else {
- OS.ToggleButton_IsChecked(handle, true);
- }
- }
- setSelection (checked);
- ignoreSelection = false;
-}
-
-void setDefault (boolean value) {
- if ((style & SWT.PUSH) == 0) return;
- OS.Button_IsDefault (handle, value);
-}
-
-/**
- * Sets the receiver's image to the argument, which may be
- * <code>null</code> indicating that no image should be displayed.
- * <p>
- * Note that a Button can display an image and text simultaneously
- * on Windows (starting with XP), GTK+ and OSX. On other platforms,
- * a Button that has an image and text set into it will display the
- * image or text that was set most recently.
- * </p>
- * @param image the image to display on the receiver (may be <code>null</code>)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if (image != null && image.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.ARROW) != 0) return;
- this.image = image;
- OS.Image_Source (imageHandle, image != null ? image.handle : 0);
- OS.UIElement_Visibility (imageHandle, image != null ? OS.Visibility_Visible : OS.Visibility_Collapsed);
- OS.UIElement_Visibility (textHandle, image != null && text.length () == 0 ? OS.Visibility_Collapsed : OS.Visibility_Visible);
- int spacing = image != null && text.length ()!= 0 ? 3 : 0;
- int margin = OS.gcnew_Thickness (0, 0, spacing, 0);
- if (margin == 0) error (SWT.ERROR_NO_HANDLES);
- OS.FrameworkElement_Margin (imageHandle, margin);
- OS.GCHandle_Free (margin);
-}
-
-/**
- * Sets the selection state of the receiver, if it is of type <code>CHECK</code>,
- * <code>RADIO</code>, or <code>TOGGLE</code>.
- *
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked. When it is of type <code>TOGGLE</code>,
- * it is selected when it is pushed in.
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget ();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return;
- ignoreSelection = true;
- if ((style & SWT.CHECK) != 0 && grayed) {
- OS.ToggleButton_IsCheckedNullSetter (handle);
- } else {
- OS.ToggleButton_IsChecked (handle, selected);
- }
- ignoreSelection = false;
-}
-
-/**
- * Sets the receiver's text.
- * <p>
- * This method sets the button label. The label may include
- * the mnemonic character but must not contain line delimiters.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasized in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p><p>
- * Note that a Button can display an image and text simultaneously
- * on Windows (starting with XP), GTK+ and OSX. On other platforms,
- * a Button that has an image and text set into it will display the
- * image or text that was set most recently.
- * </p>
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.ARROW) != 0) return;
- if (string.equals (text)) return;
- text = string;
- int strPtr = createDotNetString (text, true);
- if (strPtr == 0) error (SWT.ERROR_NO_HANDLES);
- OS.AccessText_Text (textHandle, strPtr);
- OS.GCHandle_Free (strPtr);
- OS.UIElement_Visibility (textHandle, string.length () == 0 && image != null ? OS.Visibility_Collapsed : OS.Visibility_Visible);
- int spacing = image != null && text.length () != 0 ? 3 : 0;
- int margin = OS.gcnew_Thickness (0, 0, spacing, 0);
- if (margin == 0) error (SWT.ERROR_NO_HANDLES);
- OS.FrameworkElement_Margin (imageHandle, margin);
- OS.GCHandle_Free (margin);
-}
-
-int traversalCode (int key, int event) {
- int code = super.traversalCode (key, event);
- if ((style & SWT.ARROW) != 0) code &= ~(SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS);
- if ((style & SWT.RADIO) != 0) code |= SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS;
- return code;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Canvas.java
deleted file mode 100644
index d662b69410..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Canvas.java
+++ /dev/null
@@ -1,313 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide a surface for drawing
- * arbitrary graphics.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * This class may be subclassed by custom control implementors
- * who are building controls that are <em>not</em> constructed
- * from aggregates of other controls. That is, they are either
- * painted using SWT graphics calls or are handled by native
- * methods.
- * </p>
- *
- * @see Composite
- * @see <a href="http://www.eclipse.org/swt/snippets/#canvas">Canvas snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public class Canvas extends Composite {
- Caret caret;
- IME ime;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Canvas () {
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Canvas (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-void clearArea (int x, int y, int width, int height) {
- checkWidget ();
-// if (OS.IsWindowVisible (handle)) {
-// RECT rect = new RECT ();
-// OS.SetRect (rect, x, y, x + width, y + height);
-// int hDC = OS.GetDCEx (handle, 0, OS.DCX_CACHE | OS.DCX_CLIPCHILDREN | OS.DCX_CLIPSIBLINGS);
-// drawBackground (hDC, rect);
-// OS.ReleaseDC (handle, hDC);
-// }
-}
-
-/**
- * Returns the caret.
- * <p>
- * The caret for the control is automatically hidden
- * and shown when the control is painted or resized,
- * when focus is gained or lost and when an the control
- * is scrolled. To avoid drawing on top of the caret,
- * the programmer must hide and show the caret when
- * drawing in the window any other time.
- * </p>
- *
- * @return the caret for the receiver, may be null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Caret getCaret () {
- checkWidget ();
- return caret;
-}
-
-int getCaretHandle () {
- if (caret != null && !caret.isDisposed()) {
- return caret.handle;
- }
- return 0;
-}
-
-/**
- * Returns the IME.
- *
- * @return the IME
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public IME getIME () {
- checkWidget ();
- return ime;
-}
-
-void releaseChildren (boolean destroy) {
- super.releaseChildren (destroy);
- if (caret != null) {
- caret.release (false);
- caret = null;
- }
- if (ime != null) {
- ime.release (false);
- ime = null;
- }
-}
-
-/**
- * Fills the interior of the rectangle specified by the arguments,
- * with the receiver's background.
- *
- * @param gc the gc where the rectangle is to be filled
- * @param x the x coordinate of the rectangle to be filled
- * @param y the y coordinate of the rectangle to be filled
- * @param width the width of the rectangle to be filled
- * @param height the height of the rectangle to be filled
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void drawBackground (GC gc, int x, int y, int width, int height) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- Control control = findBackgroundControl ();
- if (control != null) {
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- Point pt = display.map (this, control, 0, 0);
- int transform = OS.gcnew_TranslateTransform (-pt.x, -pt.y);
- OS.DrawingContext_PushTransform (gc.handle, transform);
- x += pt.x;
- y += pt.y;
- int rect = OS.gcnew_Rect (x, y, width, height);
- int backgroundHandle = control.backgroundHandle ();
- int property = backgroundProperty ();
- int brush = OS.DependencyObject_GetValue (backgroundHandle, property);
- OS.GCHandle_Free (property);
- OS.DrawingContext_DrawRectangle (gc.handle, brush, 0, rect);
- OS.DrawingContext_Pop (gc.handle);
- OS.GCHandle_Free (transform);
- OS.GCHandle_Free (rect);
- OS.GCHandle_Free (brush);
- } else {
- gc.fillRectangle (x, y, width, height);
- }
-
-}
-
-/**
- * Scrolls a rectangular area of the receiver by first copying
- * the source area to the destination and then causing the area
- * of the source which is not covered by the destination to
- * be repainted. Children that intersect the rectangle are
- * optionally moved during the operation. In addition, outstanding
- * paint events are flushed before the source area is copied to
- * ensure that the contents of the canvas are drawn correctly.
- *
- * @param destX the x coordinate of the destination
- * @param destY the y coordinate of the destination
- * @param x the x coordinate of the source
- * @param y the y coordinate of the source
- * @param width the width of the area
- * @param height the height of the area
- * @param all <code>true</code>if children should be scrolled, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) {
- checkWidget ();
-// boolean isFocus = caret != null && caret.isFocusCaret ();
-// if (isFocus) caret.killFocus ();
- //TODO
- redraw (false);
-// if (isFocus) caret.setFocus ();
-}
-
-/**
- * Sets the receiver's caret.
- * <p>
- * The caret for the control is automatically hidden
- * and shown when the control is painted or resized,
- * when focus is gained or lost and when an the control
- * is scrolled. To avoid drawing on top of the caret,
- * the programmer must hide and show the caret when
- * drawing in the window any other time.
- * </p>
- * @param caret the new caret for the receiver, may be null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the caret has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCaret (Caret caret) {
- checkWidget ();
- if (caret != null && caret.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- int children = OS.Panel_Children (handle);
- if (this.caret != null) {
- OS.UIElementCollection_Remove (children, this.caret.handle);
- }
- this.caret = caret;
- if (caret != null) {
- OS.UIElementCollection_Insert (children, 0, caret.handle);
- if (hasFocus ()) caret.show ();
- }
- OS.GCHandle_Free (children);
-}
-
-public void setFont (Font font) {
- checkWidget ();
- if (caret != null) caret.setFont (font);
- super.setFont (font);
-}
-
-/**
- * Sets the receiver's IME.
- *
- * @param ime the new IME for the receiver, may be null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the IME has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setIME (IME ime) {
- checkWidget ();
- if (ime != null && ime.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- this.ime = ime;
-}
-
-void HandlePreviewGotKeyboardFocus (int sender, int e) {
- if (!checkEvent (e)) return;
- super.HandlePreviewGotKeyboardFocus (sender, e);
- if (caret != null) caret.show ();
-}
-
-void HandleLostKeyboardFocus (int sender, int e) {
- if (!checkEvent (e)) return;
- super.HandleLostKeyboardFocus (sender, e);
- if (caret != null) caret.hide ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Caret.java
deleted file mode 100644
index f72e2b3cc1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Caret.java
+++ /dev/null
@@ -1,530 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide an i-beam that is typically used
- * as the insertion point for text.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#caret">Caret snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Canvas tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Caret extends Widget {
- Canvas parent;
- int x, y, width, height;
- int imageHandle;
- boolean isVisible;
- Image image;
- Font font;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Caret (Canvas parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget ();
-}
-
-void createWidget () {
- createHandle ();
- if (parent.getCaret () == null) {
- parent.setCaret (this);
- }
-}
-
-void createHandle() {
- handle = OS.gcnew_StackPanel ();
- //handle = OS.gcnew_ContentControl ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-
- int animation = OS.gcnew_DoubleAnimationUsingKeyFrames ();
- if (animation == 0) error (SWT.ERROR_NO_HANDLES);
- int timespan = OS.gcnew_TimeSpan (6000000);
- if (timespan == 0) error (SWT.ERROR_NO_HANDLES);
- int duration = OS.gcnew_Duration (timespan);
- if (duration == 0) error (SWT.ERROR_NO_HANDLES);
- int repeatBehavior = OS.RepeatBehavior_Forever();
-
- OS.Timeline_AutoReverse(animation, true);
- OS.Timeline_Duration(animation, duration);
- OS.Timeline_RepeatBehavior(animation, repeatBehavior);
- int keyFrames = OS.DoubleAnimationUsingKeyFrames_KeyFrames(animation);
- int keyTime = OS.KeyTime_Uniform();
- int keyFrame0 = OS.gcnew_DiscreteDoubleKeyFrame(0, keyTime);
- int keyFrame1 = OS.gcnew_DiscreteDoubleKeyFrame(0, keyTime);
- OS.DoubleKeyFrameCollection_Add(keyFrames, keyFrame0);
- OS.DoubleKeyFrameCollection_Add(keyFrames, keyFrame1);
- int opacityProperty = OS.UIElement_OpacityProperty();
- OS.UIElement_BeginAnimation(handle, opacityProperty, animation);
-
- int brush = OS.SystemColors_ControlTextBrush ();
- OS.Panel_Background(handle, brush);
-
- imageHandle = OS.gcnew_Image ();
- if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.Image_Stretch (imageHandle, OS.Stretch_None);
- OS.UIElement_Visibility (imageHandle, OS.Visibility_Collapsed);
-
- int children = OS.Panel_Children (handle);
- OS.UIElementCollection_Add (children, imageHandle);
- OS.GCHandle_Free (children);
- hide ();
- OS.GCHandle_Free(brush);
- OS.GCHandle_Free(opacityProperty);
- OS.GCHandle_Free(keyFrames);
- OS.GCHandle_Free(keyTime);
- OS.GCHandle_Free(keyFrame0);
- OS.GCHandle_Free(keyFrame1);
- OS.GCHandle_Free(animation);
- OS.GCHandle_Free(duration);
- OS.GCHandle_Free(timespan);
- OS.GCHandle_Free(repeatBehavior);
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null).
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- if (image != null) {
- Rectangle rect = image.getBounds ();
- return new Rectangle (x, y, rect.width, rect.height);
- }
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Font getFont () {
- checkWidget();
- if (font == null) {
- return parent.display.systemFont;
- }
- return font;
-}
-
-/**
- * Returns the image that the receiver will use to paint the caret.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget();
- return image;
-}
-
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null).
- *
- * @return the receiver's location
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getLocation () {
- checkWidget();
- return new Point (x, y);
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Canvas</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Canvas getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns a point describing the receiver's size.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- if (image != null) {
- Rectangle rect = image.getBounds ();
- return new Point (rect.width, rect.height);
- }
- return new Point (width, height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- return isVisible;
-}
-
-boolean hasFocus () {
- return OS.UIElement_IsKeyboardFocused (parent.handle);
-}
-
-boolean isFocusCaret () {
- return parent.caret == this && hasFocus ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return OS.UIElement_IsVisible (handle) && parent.isVisible () && hasFocus ();
-}
-
-void hide () {
- OS.UIElement_Visibility (handle, OS.Visibility_Collapsed);
-}
-
-void move (int x, int y) {
- OS.Canvas_SetLeft (handle, x);
- OS.Canvas_SetTop (handle, y);
-}
-
-void releaseHandle() {
- if (handle != 0) OS.GCHandle_Free (handle);
- handle = 0;
- if (imageHandle != 0) OS.GCHandle_Free (imageHandle);
- imageHandle = 0;
- super.releaseHandle ();
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (this == parent.getCaret ()) parent.setCaret (null);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
- image = null;
- font = null;
-}
-
-void resize (int width, int height) {
- if (image != null) {
- Rectangle rect = image.getBounds();
- width = rect.width;
- height = rect.height;
- }
- if (width == 0) width = 1;
- OS.FrameworkElement_Width (handle, width);
- OS.FrameworkElement_Height (handle, height);
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the arguments. The <code>x</code> and
- * <code>y</code> arguments are relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (int x, int y, int width, int height) {
- checkWidget();
- boolean samePosition = this.x == x && this.y == y;
- boolean sameExtent = this.width == width && this.height == height;
- if (samePosition && sameExtent) return;
- this.x = x; this.y = y;
- this.width = width; this.height = height;
- if (!sameExtent) resize (width, height);
- if (!samePosition) move (x, y);
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the argument. The <code>x</code> and
- * <code>y</code> fields of the rectangle are relative to
- * the receiver's parent (or its display if its parent is null).
- *
- * @param rect the new bounds for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (Rectangle rect) {
- if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (rect.x, rect.y, rect.width, rect.height);
-}
-
-void show () {
- OS.UIElement_Visibility (handle, OS.Visibility_Visible);
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * to the font specified by the argument, or to the default font for that
- * kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkWidget();
- if (font != null && font.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.font = font;
-}
-
-/**
- * Sets the image that the receiver will use to paint the caret
- * to the image specified by the argument, or to the default
- * which is a filled rectangle if the argument is null
- *
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.image = image;
- if (image != null) {
- OS.Image_Source (imageHandle, image.handle);
- OS.UIElement_Visibility (imageHandle, OS.Visibility_Visible);
- } else {
- OS.Image_Source (imageHandle, 0);
- OS.UIElement_Visibility (imageHandle, OS.Visibility_Collapsed);
- }
- resize (width, height);
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget();
- if (this.x == x && this.y == y) return;
- this.x = x; this.y = y;
- move (x, y);
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the argument which is relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param location the new location for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (Point location) {
- checkWidget();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-/**
- * Sets the receiver's size to the point specified by the arguments.
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (int width, int height) {
- checkWidget();
- if (this.width == width && this.height == height) return;
- this.width = width; this.height = height;
- resize (width, height);
-}
-
-/**
- * Sets the receiver's size to the point specified by the argument.
- *
- * @param size the new extent for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (Point size) {
- checkWidget();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSize (size.x, size.y);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget();
- if (visible == isVisible) return;
- isVisible = visible;
- if (!hasFocus()) return;
- OS.UIElement_Visibility(handle, visible ? OS.Visibility_Visible : OS.Visibility_Hidden);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ColorDialog.java
deleted file mode 100644
index a67b2415de..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ColorDialog.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class allow the user to select a color
- * from a predefined set of available colors.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class ColorDialog extends Dialog {
- RGB rgb;
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a composite control which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ColorDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ColorDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-/**
- * Returns the currently selected color in the receiver.
- *
- * @return the RGB value for the selected color, may be null
- *
- * @see PaletteData#getRGBs
- */
-public RGB getRGB () {
- return rgb;
-}
-
-/**
- * Makes the receiver visible and brings it to the front
- * of the display.
- *
- * @return the selected color, or null if the dialog was
- * cancelled, no color was selected, or an error
- * occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public RGB open () {
- int dialog = OS.gcnew_ColorDialog ();
- if (rgb != null) {
- int color = OS.DrawingColor_FromArgb (174, rgb.red, rgb.blue, rgb.green);
- OS.ColorDialog_Color (dialog, color);
- OS.GCHandle_Free (color);
- }
- Display display = parent.getDisplay ();
- int customColors = display.customColors;
- OS.ColorDialog_AnyColor (dialog, true);
- OS.ColorDialog_CustomColors (dialog, customColors);
- int result = OS.FormsCommonDialog_ShowDialog (dialog);
- RGB rgb = null;
- if (result == OS.DialogResult_OK) {
- int color = OS.ColorDialog_Color (dialog);
- int argb = OS.DrawingColor_ToArgb (color);
- int red = (argb & 0xFF0000) >> 16;
- int green = (argb & 0xFF00) >> 8;
- int blue = argb & 0xFF;
- OS.GCHandle_Free (color);
- rgb = new RGB (red, green, blue);
- if (customColors != 0) OS.GCHandle_Free (customColors);
- display.customColors = OS.ColorDialog_CustomColors (dialog);
- }
- OS.GCHandle_Free (dialog);
- return rgb;
-}
-
-/**
- * Sets the receiver's selected color to be the argument.
- *
- * @param rgb the new RGB value for the selected color, may be
- * null to let the platform select a default when
- * open() is called
- * @see PaletteData#getRGBs
- */
-public void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Combo.java
deleted file mode 100644
index 796bce5b02..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Combo.java
+++ /dev/null
@@ -1,1424 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.wpf.OS;
-
-/**
- * Instances of this class are controls that allow the user
- * to choose an item from a list of items, or optionally
- * enter a new value by typing it into an editable text
- * field. Often, <code>Combo</code>s are used in the same place
- * where a single selection <code>List</code> widget could
- * be used but space is limited. A <code>Combo</code> takes
- * less space than a <code>List</code> widget and shows
- * similar information.
- * <p>
- * Note: Since <code>Combo</code>s can contain both a list
- * and an editable text field, it is possible to confuse methods
- * which access one versus the other (compare for example,
- * <code>clearSelection()</code> and <code>deselectAll()</code>).
- * The API documentation is careful to indicate either "the
- * receiver's list" or the "the receiver's text field" to
- * distinguish between the two cases.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>DROP_DOWN, READ_ONLY, SIMPLE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Modify, Selection, Verify</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles DROP_DOWN and SIMPLE may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see List
- * @see <a href="http://www.eclipse.org/swt/snippets/#combo">Combo snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Combo extends Composite {
- int textHandle;
- boolean ignoreSelection;
-
- /**
- * the operating system limit for the number of characters
- * that the text field in an instance of this class can hold
- */
- public static final int LIMIT;
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0x7FFFFFFF;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see SWT#READ_ONLY
- * @see SWT#SIMPLE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Combo (Composite parent, int style) {
- super (parent, checkStyle (style));
- /* This code is intentionally commented */
- //if ((style & SWT.H_SCROLL) != 0) this.style |= SWT.H_SCROLL;
- this.style |= SWT.H_SCROLL;
-}
-
-Control [] _getChildren () {
- return new Control [0];
-}
-
-/**
- * Adds the argument to the end of the receiver's list.
- *
- * @param string the new item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String,int)
- */
-public void add (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int itemHandle = OS.gcnew_ComboBoxItem ();
- int strPtr = createDotNetString (string, false);
- OS.ContentControl_Content (itemHandle, strPtr);
- OS.GCHandle_Free (strPtr);
- int itemCollection = OS.ItemsControl_Items (handle);
- OS.ItemCollection_Add (itemCollection, itemHandle);
- OS.GCHandle_Free (itemCollection);
- OS.GCHandle_Free (itemHandle);
-}
-
-/**
- * Adds the argument to the receiver's list at the given
- * zero-relative index.
- * <p>
- * Note: To add an item at the end of the list, use the
- * result of calling <code>getItemCount()</code> as the
- * index or use <code>add(String)</code>.
- * </p>
- *
- * @param string the new item
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String)
- */
-public void add (String string, int index) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (index < 0) error (SWT.ERROR_INVALID_ARGUMENT);
- int items = OS.ItemsControl_Items (handle);
- int count = OS.ItemCollection_Count (items);
- OS.GCHandle_Free (items);
- if (index > count) error (SWT.ERROR_INVALID_ARGUMENT);
- int itemHandle = OS.gcnew_ComboBoxItem ();
- int strPtr = createDotNetString (string, false);
- OS.ContentControl_Content (itemHandle, strPtr);
- OS.GCHandle_Free (strPtr);
- int itemCollection = OS.ItemsControl_Items (handle);
- OS.ItemCollection_Insert (itemCollection, index, itemHandle);
- OS.GCHandle_Free (itemCollection);
- OS.GCHandle_Free (itemHandle);
-}
-
-void addChild (Control control) {
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the combo's list selection.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed the combo's text area.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- *
- * @since 3.1
- */
-public void addVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-
-void addWidget () {
- super.addWidget ();
- if ((style & SWT.READ_ONLY) == 0) {
- updateLayout (handle);
- int name = createDotNetString ("PART_EditableTextBox", false);
- int template = OS.Control_Template (handle);
- textHandle = OS.FrameworkTemplate_FindName (template, name, handle);
- OS.GCHandle_Free (name);
- OS.GCHandle_Free (template);
- }
-}
-
-int backgroundProperty () {
- return OS.Control_BackgroundProperty ();
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-static int checkStyle (int style) {
- /*
- * Feature in Windows. It is not possible to create
- * a combo box that has a border using Windows style
- * bits. All combo boxes draw their own border and
- * do not use the standard Windows border styles.
- * Therefore, no matter what style bits are specified,
- * clear the BORDER bits so that the SWT style will
- * match the Windows widget.
- *
- * The Windows behavior is currently implemented on
- * all platforms.
- */
- style &= ~SWT.BORDER;
-
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- style &= ~(SWT.H_SCROLL | SWT.V_SCROLL);
- style = checkBits (style, SWT.DROP_DOWN, SWT.SIMPLE, 0, 0, 0, 0);
- if ((style & SWT.SIMPLE) != 0) return style & ~SWT.READ_ONLY;
- return style;
-}
-
-/**
- * Sets the selection in the receiver's text field to an empty
- * selection starting just before the first character. If the
- * text field is editable, this has the effect of placing the
- * i-beam at the start of the text.
- * <p>
- * Note: To clear the selected items in the receiver's list,
- * use <code>deselectAll()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #deselectAll
- */
-public void clearSelection () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) == 0) {
- OS.TextBox_Select (textHandle, 0, 0);
- }
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- ignoreSelection = true;
- int itemCount = getItemCount();
- int text = 0;
- if (textHandle != 0) {
- text = OS.TextBox_Text (textHandle);
- }
- int selectedIndex = OS.Selector_SelectedIndex (handle);
- int width = wHint, height = hHint;
- if (wHint == SWT.DEFAULT) width = 0x7FFFFFFF;
- if (hHint == SWT.DEFAULT) height = 0x7FFFFFFF;
- width = Math.max (0, width);
- height = Math.max (0, height);
- int availSize = OS.gcnew_Size ((double) width, (double) height);
- if (availSize == 0) error (SWT.ERROR_NO_HANDLES);
- double requestWidth = OS.FrameworkElement_Width (handle);
- double requestHeight = OS.FrameworkElement_Height (handle);
- int widthDP = OS.FrameworkElement_WidthProperty ();
- int heightDP = OS.FrameworkElement_HeightProperty ();
- OS.DependencyObject_ClearValue (handle, widthDP);
- OS.DependencyObject_ClearValue (handle, heightDP);
- OS.UIElement_Measure (handle, availSize);
- int size = OS.UIElement_DesiredSize (handle);
- width = (int) OS.Size_Width (size);
- height = (int) OS.Size_Height (size);
- OS.GCHandle_Free (size);
- for (int i = 0; i < itemCount; i++) {
- OS.Selector_SelectedIndex (handle, i);
- updateLayout (handle);
- OS.UIElement_Measure (handle, availSize);
- size = OS.UIElement_DesiredSize (handle);
- width = Math.max (width, (int) OS.Size_Width (size));
- height = Math.max (height, (int) OS.Size_Height (size));
- OS.GCHandle_Free (size);
- }
- OS.GCHandle_Free (availSize);
- OS.FrameworkElement_Width (handle, requestWidth);
- OS.FrameworkElement_Height (handle, requestHeight);
- OS.Selector_SelectedIndex (handle, selectedIndex);
- if (textHandle != 0) {
- OS.TextBox_Text (textHandle, text);
- OS.GCHandle_Free (text);
- }
- OS.GCHandle_Free (widthDP);
- OS.GCHandle_Free (heightDP);
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- ignoreSelection = false;
- return new Point (width, height);
-}
-
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void copy () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return; //TODO
- OS.TextBoxBase_Copy (textHandle);
-}
-
-void createHandle () {
- handle = OS.gcnew_ComboBox ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.READ_ONLY) == 0) {
- OS.ComboBox_IsEditable (handle, true);
- OS.ItemsControl_IsTextSearchEnabled (handle, false);
- }
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void cut () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- OS.TextBoxBase_Cut (textHandle);
-}
-
-/**
- * Deselects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget ();
- ignoreSelection = true;
- int selected = OS.Selector_SelectedIndex (handle);
- if (selected == index) OS.Selector_SelectedIndex (handle, -1);
- ignoreSelection = false;
-// FIXME: May need to send modify event here.
-// if ((style & SWT.READ_ONLY) == 0) {
-// sendEvent (SWT.Modify);
-// }
-}
-
-/**
- * Deselects all selected items in the receiver's list.
- * <p>
- * Note: To clear the selection in the receiver's text field,
- * use <code>clearSelection()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #clearSelection
- */
-public void deselectAll () {
- checkWidget ();
- ignoreSelection = true;
- OS.Selector_SelectedIndex (handle, -1);
- ignoreSelection = false;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver's list. Throws an exception if the index is out
- * of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getItem (int index) {
- checkWidget ();
- int count = getItemCount ();
- if (index < 0 || index >= count) error (SWT.ERROR_INVALID_RANGE);
- int itemCollection = OS.ItemsControl_Items (handle);
- int comboBoxItem = OS.ItemCollection_GetItemAt (itemCollection, index);
- OS.GCHandle_Free (itemCollection);
- int content = OS.ContentControl_Content (comboBoxItem);
- String string = createJavaString(content);
- OS.GCHandle_Free (comboBoxItem);
- OS.GCHandle_Free (content);
- return string;
-}
-
-/**
- * Returns the number of items contained in the receiver's list.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- int itemCollection = OS.ItemsControl_Items (handle);
- int count = OS.ItemCollection_Count (itemCollection);
- OS.GCHandle_Free (itemCollection);
- return count;
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the receiver's list.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- //todo
- int result = 0;
-// if (result == OS.CB_ERR) error (SWT.ERROR_CANNOT_GET_ITEM_HEIGHT);
- return result;
-}
-
-/**
- * Returns a (possibly empty) array of <code>String</code>s which are
- * the items in the receiver's list.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver's list
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getItems () {
- checkWidget ();
- int count = getItemCount ();
- String [] result = new String [count];
- for (int i=0; i<count; i++) result [i] = getItem (i);
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver's list is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's list's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getListVisible () {
- checkWidget ();
- return OS.ComboBox_IsDropDownOpen (handle);
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the orientation of the receiver.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getOrientation () {
- checkWidget ();
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-/**
- * Returns a <code>Point</code> whose x coordinate is the
- * character position representing the start of the selection
- * in the receiver's text field, and whose y coordinate is the
- * character position representing the end of the selection.
- * An "empty" selection is indicated by the x and y coordinates
- * having the same value.
- * <p>
- * Indexing is zero based. The range of a selection is from
- * 0..N where N is the number of characters in the widget.
- * </p>
- *
- * @return a point representing the selection start and end
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSelection () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return new Point (0,0);
- int start = OS.TextBox_SelectionStart (textHandle);
- int length = OS.TextBox_SelectionLength (textHandle);
- return new Point (start, start + length);
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver's list, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget ();
- return OS.Selector_SelectedIndex (handle);
-}
-
-/**
- * Returns a string containing a copy of the contents of the
- * receiver's text field, or an empty string if there are no
- * contents.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- String text;
- if ((style & SWT.READ_ONLY) != 0) {
- int item = OS.ComboBox_SelectionBoxItem (handle);
- text = createJavaString (item);
- OS.GCHandle_Free (item);
- } else {
- int content = OS.TextBox_Text (textHandle);
- text = createJavaString (content);
- OS.GCHandle_Free (content);
- }
- return text;
-}
-
-/**
- * Returns the height of the receivers's text field.
- *
- * @return the text height
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTextHeight () {
- checkWidget ();
- if (textHandle != 0) {
- return (int) OS.FrameworkElement_ActualHeight(textHandle);
- }
- return 0;
-}
-
-/**
- * Returns the maximum number of characters that the receiver's
- * text field is capable of holding. If this has not been changed
- * by <code>setTextLimit()</code>, it will be the constant
- * <code>Combo.LIMIT</code>.
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public int getTextLimit () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return LIMIT;
- return OS.TextBox_MaxLength (textHandle);
-}
-
-/**
- * Gets the number of items that are visible in the drop
- * down portion of the receiver's list.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @return the number of items that are visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public int getVisibleItemCount () {
- checkWidget ();
- return 0;
-}
-
-void HandleSelectionChanged (int sender, int e) {
- if (!checkEvent (e)) return;
- if (!ignoreSelection) postEvent (SWT.Selection);
-}
-
-void HandlePreviewExecutedRoutedEvent (int sender, int e) {
- if (!checkEvent (e)) return;
- int command = OS.ExecutedRoutedEventArgs_Command (e);
- boolean doVerify = false;
- String input = null;
- int paste = OS.ApplicationCommands_Paste ();
- int cut = OS.ApplicationCommands_Cut ();
- int redo = OS.ApplicationCommands_Redo ();
- int undo = OS.ApplicationCommands_Undo ();
- int backspace = OS.EditingCommands_Backspace ();
- int delete = OS.EditingCommands_Delete ();
- int deleteNext = OS.EditingCommands_DeleteNextWord ();
- int deletePrevious = OS.EditingCommands_DeletePreviousWord ();
- if (OS.Object_Equals (command, paste)) {
- doVerify = true;
- int clipboardText = OS.Clipboard_GetText ();
- input = createJavaString(clipboardText);
- OS.GCHandle_Free(clipboardText);
- } else if (OS.Object_Equals (command, cut)){
- doVerify = true;
- int content = OS.TextBox_SelectedText (textHandle);
- input = createJavaString (content);
- OS.GCHandle_Free (content);
- } else if (OS.Object_Equals(command, redo)) {
- //FIXME
- //doVerify = true;
- OS.ExecutedRoutedEventArgs_Handled (e, true);
- } else if (OS.Object_Equals(command, undo)) {
- //FIXME
- //doVerify = true;
- OS.ExecutedRoutedEventArgs_Handled (e, true);
- } else if (OS.Object_Equals (command, backspace)) {
- doVerify = true;
- input = "";
- } else if (OS.Object_Equals (command, delete)) {
- doVerify = true;
- input = "";
- } else if (OS.Object_Equals(command, deleteNext)) {
- //FIXME
- //doVerify = true;
- OS.ExecutedRoutedEventArgs_Handled (e, true);
- } else if (OS.Object_Equals(command, deletePrevious)) {
- //FIXME
- //doVerify = true;
- OS.ExecutedRoutedEventArgs_Handled (e, true);
- }
- OS.GCHandle_Free (paste);
- OS.GCHandle_Free (cut);
- OS.GCHandle_Free (redo);
- OS.GCHandle_Free (undo);
- OS.GCHandle_Free (backspace);
- OS.GCHandle_Free (delete);
- OS.GCHandle_Free (deleteNext);
- OS.GCHandle_Free (deletePrevious);
- OS.GCHandle_Free(command);
- /*
- * FIXME - should do this first, but for now we want to swallow
- * all Redo, Undo, DeleteNextWord and DeletePreviousWord to
- * prevent those from changing the TextBox w/o Verify events
- */
- if (!hooks (SWT.Verify)) return;
- if (!doVerify) return;
- String text = verifyText (input);
- if (text != null && !text.equals (input)) {
- int strPtr = createDotNetString (text, false);
- OS.TextBox_SelectedText (textHandle, strPtr);
- OS.GCHandle_Free (strPtr);
- int start = OS.TextBox_SelectionStart (textHandle);
- int length = OS.TextBox_SelectionLength (textHandle);
- OS.TextBox_Select (textHandle, start+length, 0);
- OS.TextBox_SelectionLength (textHandle, 0);
- text = null;
- }
- if (text == null) OS.ExecutedRoutedEventArgs_Handled (e, true);
-}
-
-void HandlePreviewKeyDown (int sender, int e) {
- super.HandlePreviewKeyDown (sender, e);
- if (!checkEvent (e)) return;
- int key = OS.KeyEventArgs_Key (e);
- if (key == OS.Key_Return) postEvent (SWT.DefaultSelection);
-}
-
-void HandlePreviewTextInput (int sender, int e) {
- super.HandlePreviewTextInput (sender, e);
- if (!checkEvent (e)) return;
- int textPtr = OS.TextCompositionEventArgs_Text (e);
- String input = createJavaString(textPtr);
- OS.GCHandle_Free (textPtr);
- String text = verifyText (input);
- if (text != null && !text.equals (input)) {
- textPtr = createDotNetString (text, false);
- OS.TextBox_SelectedText (textHandle, textPtr);
- OS.GCHandle_Free (textPtr);
- int start = OS.TextBox_SelectionStart (textHandle);
- int length = OS.TextBox_SelectionLength (textHandle);
- OS.TextBox_Select (textHandle, start+length, 0);
- OS.TextBox_SelectionLength (textHandle, 0);
- text = null;
- }
- if (text == null) OS.TextCompositionEventArgs_Handled (e, true);
-}
-
-void HandleTextChanged (int sender, int e) {
- if (!checkEvent (e)) return;
- sendEvent (SWT.Modify);
-}
-
-void hookEvents() {
- super.hookEvents ();
- int handler = OS.gcnew_SelectionChangedEventHandler (jniRef, "HandleSelectionChanged");
- OS.Selector_SelectionChanged (handle, handler);
- OS.GCHandle_Free (handler);
- if (textHandle != 0) {
- handler = OS.gcnew_ExecutedRoutedEventHandler (jniRef, "HandlePreviewExecutedRoutedEvent");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.CommandManager_AddPreviewExecutedHandler (textHandle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_TextChangedEventHandler (jniRef, "HandleTextChanged");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.TextBoxBase_TextChanged (textHandle, handler);
- OS.GCHandle_Free (handler);
- }
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param string the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string) {
- return indexOf (string, 0);
-}
-
-/**
- * Searches the receiver's list starting at the given,
- * zero-relative index until an item is found that is equal
- * to the argument, and returns the index of that item. If
- * no item is found or the starting index is out of range,
- * returns -1.
- *
- * @param string the search item
- * @param start the zero-relative index at which to begin the search
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string, int start) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = getItemCount ();
- if (start < 0 || start >= count) return -1;
- start = Math.max (start, 0);
- int strPtr = createDotNetString (string, false);
- int itemCollection = OS.ItemsControl_Items (handle);
- int index = -1;
- while (start < count && index == -1) {
- int item = OS.ItemCollection_GetItemAt (itemCollection, start);
- int itemContent = OS.ContentControl_Content (item);
- OS.GCHandle_Free (item);
- if (itemContent != 0 && OS.Object_Equals (itemContent, strPtr)) index = start;
- OS.GCHandle_Free (itemContent);
- start ++;
- }
- OS.GCHandle_Free (strPtr);
- OS.GCHandle_Free (itemCollection);
- return index;
-}
-
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void paste () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- OS.TextBoxBase_Paste (textHandle);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (textHandle != 0) OS.GCHandle_Free (textHandle);
- textHandle = 0;
-}
-/**
- * Removes the item from the receiver's list at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget ();
- if (index < 0 || index >= getItemCount ()) error (SWT.ERROR_INVALID_RANGE);
- int itemCollection = OS.ItemsControl_Items(handle);
- OS.ItemCollection_RemoveAt(itemCollection, index);
- OS.GCHandle_Free(itemCollection);
-}
-
-/**
- * Removes the items from the receiver's list which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget ();
- int count = getItemCount ();
- if (start < 0 || start >= count) error (SWT.ERROR_INVALID_RANGE);
- if (end < 0 || end >= count) error (SWT.ERROR_INVALID_RANGE);
- int itemCollection = OS.ItemsControl_Items(handle);
- for (int i = end; i >= start; i--) {
- OS.ItemCollection_RemoveAt(itemCollection, i);
- }
- OS.GCHandle_Free(itemCollection);
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * until an item is found that is equal to the argument,
- * and removes that item from the list.
- *
- * @param string the item to remove
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = indexOf (string, 0);
- if (index == -1) error (SWT.ERROR_INVALID_ARGUMENT);
- remove (index);
-}
-
-/**
- * Removes all of the items from the receiver's list and clear the
- * contents of receiver's text field.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget ();
- int itemCollection = OS.ItemsControl_Items (handle);
- ignoreSelection = true;
- OS.ItemCollection_Clear (itemCollection);
- ignoreSelection = false;
- OS.GCHandle_Free (itemCollection);
-}
-
-void removeChild(Control control) {
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- *
- * @since 3.1
- */
-public void removeVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget ();
- int itemCollection = OS.ItemsControl_Items(handle);
- int count = OS.ItemCollection_Count(itemCollection);
- OS.GCHandle_Free(itemCollection);
- if (0 <= index && index < count) {
-// int selection = OS.Selector_SelectedIndex (handle);
- ignoreSelection = true;
- OS.Selector_SelectedIndex(handle, index);
- ignoreSelection = false;
-// int code = OS.Selector_SelectedIndex(handle);
-// if (code != -1 && code != selection) {
-// sendEvent (SWT.Modify);
-// }
- }
-}
-
-void setForegroundBrush (int brush) {
- if (brush != 0) {
- OS.Control_Foreground (handle, brush);
- } else {
- int property = OS.Control_ForegroundProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
-}
-
-/**
- * Sets the text of the item in the receiver's list at the given
- * zero-relative index to the string argument.
- *
- * @param index the index for the item
- * @param string the new text for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItem (int index, String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (index < 0 || index >= getItemCount()) error (SWT.ERROR_INVALID_RANGE);
- int itemCollection = OS.ItemsControl_Items(handle);
- int item = OS.ItemCollection_GetItemAt(itemCollection, index);
- OS.GCHandle_Free(itemCollection);
- int strPtr = createDotNetString (string, false);
- OS.ContentControl_Content(item, strPtr);
- OS.GCHandle_Free(strPtr);
- OS.GCHandle_Free(item);
-}
-
-/**
- * Sets the receiver's list to be the given array of items.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItems (String [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<items.length; i++) {
- if (items [i] == null) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int itemCollection = OS.ItemsControl_Items(handle);
- ignoreSelection = true;
- OS.ItemCollection_Clear(itemCollection);
- for (int i = 0; i < items.length; i++) {
- int itemHandle = OS.gcnew_ComboBoxItem ();
- int strPtr = createDotNetString (items [i], false);
- OS.ContentControl_Content (itemHandle, strPtr);
- OS.GCHandle_Free (strPtr);
- OS.ItemCollection_Add (itemCollection, itemHandle);
- OS.GCHandle_Free (itemHandle);
- }
- ignoreSelection = false;
- OS.GCHandle_Free(itemCollection);
-}
-
-/**
- * Marks the receiver's list as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setListVisible (boolean visible) {
- checkWidget ();
- OS.ComboBox_IsDropDownOpen (handle, visible);
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- * <p>
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public void setOrientation (int orientation) {
- checkWidget();
- int flowDirection = orientation == SWT.RIGHT_TO_LEFT ? OS.FlowDirection_RightToLeft : OS.FlowDirection_LeftToRight;
- OS.FrameworkElement_FlowDirection (handle, flowDirection);
-}
-
-/**
- * Sets the selection in the receiver's text field to the
- * range specified by the argument whose x coordinate is the
- * start of the selection and whose y coordinate is the end
- * of the selection.
- *
- * @param selection a point representing the new selection start and end
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (Point selection) {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
- int start = selection.x, length = selection.y - selection.x;
- OS.TextBox_SelectionLength (textHandle, length);
- OS.TextBox_SelectionStart (textHandle, start);
-}
-
-/**
- * Sets the contents of the receiver's text field to the
- * given string.
- * <p>
- * This call is ignored when the receiver is read only and
- * the given string is not in the receiver's list.
- * </p>
- * <p>
- * Note: The text field in a <code>Combo</code> is typically
- * only capable of displaying a single line of text. Thus,
- * setting the text to a string containing line breaks or
- * other special characters will probably cause it to
- * display incorrectly.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.READ_ONLY) != 0) {
- int index = indexOf (string);
- if (index != -1) select (index);
- return;
- }
- int strPtr = createDotNetString (string, false);
- OS.TextBox_Text (textHandle, strPtr);
- OS.GCHandle_Free (strPtr);
-}
-
-/**
- * Sets the maximum number of characters that the receiver's
- * text field is capable of holding to be the argument.
- * <p>
- * To reset this value to the default, use <code>setTextLimit(Combo.LIMIT)</code>.
- * Specifying a limit value larger than <code>Combo.LIMIT</code> sets the
- * receiver's limit to <code>Combo.LIMIT</code>.
- * </p>
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public void setTextLimit (int limit) {
- checkWidget ();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- if ((style & SWT.READ_ONLY) != 0) return;
- OS.TextBox_MaxLength (textHandle, limit);
-}
-
-/**
- * Sets the number of items that are visible in the drop
- * down portion of the receiver's list.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param count the new number of items to be visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setVisibleItemCount (int count) {
- checkWidget ();
- return;
-}
-
-String verifyText (String text) {
- int start = OS.TextBox_SelectionStart (textHandle);
- int length = OS.TextBox_SelectionLength (textHandle);
- Event event = new Event ();
- event.text = text;
- event.start = start;
- /*
- * FIXME: end can be greater than start+length+1
- * when Deleting special characters.
- * Note that backspace deletes one character at
- * a time.
- */
- event.end = start+length+1;
- sendEvent (SWT.Verify, event);
- if (!event.doit) return null;
- return event.text;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Composite.java
deleted file mode 100644
index e7e27d2c5f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Composite.java
+++ /dev/null
@@ -1,1157 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are controls which are capable
- * of containing other controls.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>NO_BACKGROUND, NO_FOCUS, NO_MERGE_PAINTS, NO_REDRAW_RESIZE, NO_RADIO_GROUP, EMBEDDED, DOUBLE_BUFFERED</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: The <code>NO_BACKGROUND</code>, <code>NO_FOCUS</code>, <code>NO_MERGE_PAINTS</code>,
- * and <code>NO_REDRAW_RESIZE</code> styles are intended for use with <code>Canvas</code>.
- * They can be used with <code>Composite</code> if you are drawing your own, but their
- * behavior is undefined if they are used with subclasses of <code>Composite</code> other
- * than <code>Canvas</code>.
- * </p><p>
- * Note: The <code>CENTER</code> style, although undefined for composites, has the
- * same value as <code>EMBEDDED</code> which is used to embed widgets from other
- * widget toolkits into SWT. On some operating systems (GTK, Motif), this may cause
- * the children of this composite to be obscured.
- * </p><p>
- * This class may be subclassed by custom control implementors
- * who are building controls that are constructed from aggregates
- * of other controls.
- * </p>
- *
- * @see Canvas
- * @see <a href="http://www.eclipse.org/swt/snippets/#composite">Composite snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public class Composite extends Scrollable {
- Layout layout;
- Control [] tabList;
- int layoutCount, backgroundMode;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Composite () {
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- *
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_FOCUS
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_RADIO_GROUP
- * @see SWT#EMBEDDED
- * @see SWT#DOUBLE_BUFFERED
- * @see Widget#getStyle
- */
-public Composite (Composite parent, int style) {
- super (parent, style);
-}
-
-static int checkStyle (int style) {
- style &= ~SWT.TRANSPARENT;
- return style;
-}
-
-int getCaretHandle () {
- return 0;
-}
-
-Control [] _getChildren () {
- int parentHandle = parentingHandle ();
- int elements = OS.Panel_Children (parentHandle);
- int count = OS.UIElementCollection_Count (elements);
- int caretHandle = getCaretHandle ();
- if (caretHandle != 0) count--;
- Control [] children = new Control [count];
- int index = count - 1;
- if (count != 0) {
- int enumerator = OS.UIElementCollection_GetEnumerator (elements);
- while (OS.IEnumerator_MoveNext (enumerator)) {
- int current = OS.UIElementCollection_Current (enumerator);
- if (caretHandle != 0 && OS.Object_Equals(caretHandle, current)) {
- OS.GCHandle_Free (current);
- continue;
- }
- Widget widget = display.getWidget (current);
- if (widget != null && widget != this) {
- if (widget instanceof Control) {
- children [index--] = (Control)widget;
- }
- }
- OS.GCHandle_Free (current);
- }
- OS.GCHandle_Free (enumerator);
- }
- OS.GCHandle_Free (elements);
- if (index == -1) return children;
- Control [] newChildren = new Control [count - index - 1];
- System.arraycopy (children, index + 1, newChildren, 0, newChildren.length);
- return newChildren;
-}
-
-Control [] _getTabList () {
- if (tabList == null) return tabList;
- int count = 0;
- for (int i=0; i<tabList.length; i++) {
- if (!tabList [i].isDisposed ()) count++;
- }
- if (count == tabList.length) return tabList;
- Control [] newList = new Control [count];
- int index = 0;
- for (int i=0; i<tabList.length; i++) {
- if (!tabList [i].isDisposed ()) {
- newList [index++] = tabList [i];
- }
- }
- tabList = newList;
- return tabList;
-}
-
-void addChild (Control control) {
- int parentHandle = parentingHandle ();
- int children = OS.Panel_Children (parentHandle);
- int index = 0;
- if (parentHandle != handle) {
- if (OS.UIElementCollection_Contains (children, handle)) {
- index = 1;
- }
- }
- int topHandle = control.topHandle ();
- OS.UIElementCollection_Insert (children, index, topHandle);
- OS.GCHandle_Free (children);
- OS.FrameworkElement_Width (topHandle, 0);
- OS.FrameworkElement_Height (topHandle, 0);
-}
-
-int backgoundProperty () {
- return OS.Panel_BackgroundProperty();
-}
-
-/**
- * Clears any data that has been cached by a Layout for all widgets that
- * are in the parent hierarchy of the changed control up to and including the
- * receiver. If an ancestor does not have a layout, it is skipped.
- *
- * @param changed an array of controls that changed state and require a recalculation of size
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li>
- * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void changed (Control[] changed) {
- checkWidget ();
- if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<changed.length; i++) {
- Control control = changed [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean ancestor = false;
- Composite composite = control.parent;
- while (composite != null) {
- ancestor = composite == this;
- if (ancestor) break;
- composite = composite.parent;
- }
- if (!ancestor) error (SWT.ERROR_INVALID_PARENT);
- }
- for (int i=0; i<changed.length; i++) {
- Control child = changed [i];
- Composite composite = child.parent;
- while (child != this) {
- if (composite.layout == null || !composite.layout.flushCache (child)) {
- composite.state |= LAYOUT_CHANGED;
- }
- child = composite;
- composite = child.parent;
- }
- }
-}
-
-protected void checkSubclass () {
- /* Do nothing - Subclassing is allowed */
-}
-
-Control [] computeTabList () {
- Control result [] = super.computeTabList ();
- if (result.length == 0) return result;
- Control [] list = tabList != null ? _getTabList () : _getChildren ();
- for (int i=0; i<list.length; i++) {
- Control child = list [i];
- Control [] childList = child.computeTabList ();
- if (childList.length != 0) {
- Control [] newResult = new Control [result.length + childList.length];
- System.arraycopy (result, 0, newResult, 0, result.length);
- System.arraycopy (childList, 0, newResult, result.length, childList.length);
- result = newResult;
- }
- }
- return result;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- Point size;
- if (layout != null) {
- if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
- changed |= (state & LAYOUT_CHANGED) != 0;
- state &= ~LAYOUT_CHANGED;
- size = layout.computeSize (this, wHint, hHint, changed);
- } else {
- size = new Point (wHint, hHint);
- }
- } else {
- size = minimumSize (wHint, hHint, changed);
- }
- if (size.x == 0) size.x = DEFAULT_WIDTH;
- if (size.y == 0) size.y = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) size.x = wHint;
- if (hHint != SWT.DEFAULT) size.y = hHint;
- Rectangle trim = computeTrim (0, 0, size.x, size.y);
- return new Point (trim.width, trim.height);
-}
-
-void createHandle () {
- state |= CANVAS;
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
- state |= THEME_BACKGROUND;
- }
- boolean scrolled = (style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0;
- createHandle (scrolled, false);
-}
-
-void createHandle (boolean scrolled, boolean menubar) {
- handle = OS.gcnew_SWTCanvas (jniRef);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.FrameworkElement_FocusVisualStyle (handle, 0);
- if ((style & SWT.NO_FOCUS) == 0) {
- OS.UIElement_Focusable (handle, true);
- }
- if (scrolled || menubar) {
- scrolledHandle = OS.gcnew_Grid ();
- if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
-
- /* Create grid definition */
- int gridLength = OS.gcnew_GridLength (1, OS.GridUnitType_Auto);
- if (gridLength == 0) error (SWT.ERROR_NO_HANDLES);
- int columnDefinitions = OS.Grid_ColumnDefinitions (scrolledHandle);
- int column0 = OS.gcnew_ColumnDefinition ();
- if (column0 == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ColumnDefinitionCollection_Add (columnDefinitions, column0);
- int column1 = OS.gcnew_ColumnDefinition ();
- if (column1 == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ColumnDefinition_Width (column1, gridLength);
- OS.ColumnDefinitionCollection_Add (columnDefinitions, column1);
- int rowDefinitions = OS.Grid_RowDefinitions (scrolledHandle);
- int row0 = OS.gcnew_RowDefinition ();
- if (row0 == 0) error (SWT.ERROR_NO_HANDLES);
- OS.RowDefinition_Height (row0, gridLength);
- OS.RowDefinitionCollection_Add (rowDefinitions, row0);
- int row1 = OS.gcnew_RowDefinition ();
- if (row1 == 0) error (SWT.ERROR_NO_HANDLES);
- OS.RowDefinitionCollection_Add (rowDefinitions, row1);
- int row2 = OS.gcnew_RowDefinition ();
- if (row2 == 0) error (SWT.ERROR_NO_HANDLES);
- OS.RowDefinition_Height (row2, gridLength);
- OS.RowDefinitionCollection_Add (rowDefinitions, row2);
- OS.GCHandle_Free (column0);
- OS.GCHandle_Free (column1);
- OS.GCHandle_Free (row0);
- OS.GCHandle_Free (row1);
- OS.GCHandle_Free (row2);
- OS.GCHandle_Free (gridLength);
- OS.GCHandle_Free (columnDefinitions);
- OS.GCHandle_Free (rowDefinitions);
-
- /* create children */
- int children = OS.Panel_Children (scrolledHandle);
- OS.UIElementCollection_Add (children, handle);
- OS.Grid_SetRow (handle, 1);
- OS.Grid_SetColumn (handle, 0);
- if ((style & SWT.V_SCROLL) != 0) {
- int vScroll = OS.gcnew_ScrollBar ();
- if (vScroll == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ScrollBar_Orientation (vScroll, OS.Orientation_Vertical);
- OS.RangeBase_Maximum(vScroll, 90);
- OS.RangeBase_LargeChange (vScroll, 10);
- OS.ScrollBar_ViewportSize (vScroll, 10);
- OS.Grid_SetRow (vScroll, 1);
- OS.Grid_SetColumn (vScroll, 1);
- OS.UIElementCollection_Add (children, vScroll);
- OS.GCHandle_Free (vScroll);
- }
- if ((style & SWT.H_SCROLL) != 0) {
- int hScroll = OS.gcnew_ScrollBar ();
- if (hScroll == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ScrollBar_Orientation (hScroll, OS.Orientation_Horizontal);
- OS.RangeBase_Maximum (hScroll, 90);
- OS.RangeBase_LargeChange (hScroll, 10);
- OS.ScrollBar_ViewportSize (hScroll, 10);
- OS.Grid_SetRow (hScroll, 2);
- OS.Grid_SetColumn (hScroll, 0);
- OS.UIElementCollection_Add (children, hScroll);
- OS.GCHandle_Free (hScroll);
- }
- OS.GCHandle_Free (children);
- }
-}
-
-int defaultBackground () {
- if ((state & CANVAS) != 0) {
- return OS.SystemColors_ControlColor;
- }
- return 0;
-}
-
-void enableWidget (boolean enabled) {
- if ((state & CANVAS) != 0) {
- OS.UIElement_IsHitTestVisible (topHandle (), enabled);
- } else {
- OS.UIElement_IsEnabled (handle, enabled);
- OS.UIElement_IsHitTestVisible (parentingHandle (), enabled);
- }
-}
-
-Composite findDeferredControl () {
- return layoutCount > 0 ? this : parent.findDeferredControl ();
-}
-
-Menu [] findMenus (Control control) {
- if (control == this) return new Menu [0];
- Menu result [] = super.findMenus (control);
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- Menu [] menuList = child.findMenus (control);
- if (menuList.length != 0) {
- Menu [] newResult = new Menu [result.length + menuList.length];
- System.arraycopy (result, 0, newResult, 0, result.length);
- System.arraycopy (menuList, 0, newResult, result.length, menuList.length);
- result = newResult;
- }
- }
- return result;
-}
-
-void fixScrollbarVisibility () {
-}
-
-void fixTabList (Control control) {
- if (tabList == null) return;
- int count = 0;
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == control) count++;
- }
- if (count == 0) return;
- Control [] newList = null;
- int length = tabList.length - count;
- if (length != 0) {
- newList = new Control [length];
- int index = 0;
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] != control) {
- newList [index++] = tabList [i];
- }
- }
- }
- tabList = newList;
-}
-
-/**
- * Returns the receiver's background drawing mode. This
- * will be one of the following constants defined in class
- * <code>SWT</code>:
- * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>,
- * <code>INHERTIT_FORCE</code>.
- *
- * @return the background mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- *
- * @since 3.2
- */
-public int getBackgroundMode () {
- checkWidget ();
- return backgroundMode;
-}
-
-/**
- * Returns a (possibly empty) array containing the receiver's children.
- * Children are returned in the order that they are drawn. The topmost
- * control appears at the beginning of the array. Subsequent controls
- * draw beneath this control and appear later in the array.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of children, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return an array of children
- *
- * @see Control#moveAbove
- * @see Control#moveBelow
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control [] getChildren () {
- checkWidget ();
- return _getChildren ();
-}
-
-/**
- * Returns layout which is associated with the receiver, or
- * null if one has not been set.
- *
- * @return the receiver's layout or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Layout getLayout () {
- checkWidget ();
- return layout;
-}
-
-Point getLocation (Control child) {
- int topHandle = child.topHandle ();
- int x = (int) OS.Canvas_GetLeft (topHandle);
- int y = (int) OS.Canvas_GetTop (topHandle);
- return new Point (x, y);
-}
-
-/**
- * Gets the (possibly empty) tabbing order for the control.
- *
- * @return tabList the ordered list of controls representing the tab order
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setTabList
- */
-public Control [] getTabList () {
- checkWidget ();
- Control [] tabList = _getTabList ();
- if (tabList == null) {
- int count = 0;
- Control [] list =_getChildren ();
- for (int i=0; i<list.length; i++) {
- if (list [i].isTabGroup ()) count++;
- }
- tabList = new Control [count];
- int index = 0;
- for (int i=0; i<list.length; i++) {
- if (list [i].isTabGroup ()) {
- tabList [index++] = list [i];
- }
- }
- }
- return tabList;
-}
-
-boolean hooksKeys () {
- return hooks (SWT.KeyDown) || hooks (SWT.KeyUp);
-}
-
-/**
- * Returns <code>true</code> if the receiver has deferred
- * the performing of layout, and <code>false</code> otherwise.
- *
- * @return the receiver's deferred layout state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setLayoutDeferred(boolean)
- * @see #isLayoutDeferred()
- *
- * @since 3.1
- */
-public boolean getLayoutDeferred () {
- checkWidget ();
- return layoutCount > 0 ;
-}
-
-void HandlePreviewKeyDown (int sender, int e) {
- super.HandlePreviewKeyDown (sender, e);
- if (!checkEvent (e)) return;
- /*
- * In WPF arrows key move the focus around, this
- * behavior is not expected in SWT.
- */
- if ((state & CANVAS) != 0) {
- int key = OS.KeyEventArgs_Key (e);
- switch (key) {
- case OS.Key_Up:
- case OS.Key_Left:
- case OS.Key_Down:
- case OS.Key_Right: {
- OS.RoutedEventArgs_Handled (e, true);
- break;
- }
- }
- }
-}
-
-void HandlePreviewMouseDown(int sender, int e) {
- if (!checkEvent (e)) return;
- super.HandlePreviewMouseDown (sender, e);
-
- /* Set focus for a canvas with no children */
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_FOCUS) == 0 && hooksKeys ()) {
- int children = OS.Panel_Children (handle);
- int count = OS.UIElementCollection_Count (children);
- OS.GCHandle_Free (children);
- int caretHandle = getCaretHandle ();
- if (caretHandle != 0) count--;
- if (count == 0) {
- OS.UIElement_Focus (handle);
- }
- }
- }
-}
-
-void HandlePreviewTextInput(int sender, int e) {
- super.HandlePreviewTextInput (sender, e);
- if (!checkEvent (e)) return;
- if ((state & CANVAS) != 0) {
- OS.RoutedEventArgs_Handled (e, true);
- }
-}
-
-/**
- * Returns <code>true</code> if the receiver or any ancestor
- * up to and including the receiver's nearest ancestor shell
- * has deferred the performing of layouts. Otherwise, <code>false</code>
- * is returned.
- *
- * @return the receiver's deferred layout state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setLayoutDeferred(boolean)
- * @see #getLayoutDeferred()
- *
- * @since 3.1
- */
-public boolean isLayoutDeferred () {
- checkWidget ();
- return findDeferredControl () != null;
-}
-
-boolean isTabGroup() {
- if ((state & CANVAS) != 0) return true;
- return super.isTabGroup();
-}
-
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the receiver does not have a layout, do nothing.
- * <p>
- * This is equivalent to calling <code>layout(true)</code>.
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void layout () {
- checkWidget ();
- layout (true);
-}
-
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the argument is <code>true</code> the layout must not rely
- * on any information it has cached about the immediate children. If it
- * is <code>false</code> the layout may (potentially) optimize the
- * work it is doing by assuming that none of the receiver's
- * children has changed state since the last layout.
- * If the receiver does not have a layout, do nothing.
- * <p>
- * If a child is resized as a result of a call to layout, the
- * resize event will invoke the layout of the child. The layout
- * will cascade down through all child widgets in the receiver's widget
- * tree until a child is encountered that does not resize. Note that
- * a layout due to a resize will not flush any cached information
- * (same as <code>layout(false)</code>).
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void layout (boolean changed) {
- checkWidget ();
- if (layout == null) return;
- layout (changed, false);
-}
-
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the changed argument is <code>true</code> the layout must not rely
- * on any information it has cached about its children. If it
- * is <code>false</code> the layout may (potentially) optimize the
- * work it is doing by assuming that none of the receiver's
- * children has changed state since the last layout.
- * If the all argument is <code>true</code> the layout will cascade down
- * through all child widgets in the receiver's widget tree, regardless of
- * whether the child has changed size. The changed argument is applied to
- * all layouts. If the all argument is <code>false</code>, the layout will
- * <em>not</em> cascade down through all child widgets in the receiver's widget
- * tree. However, if a child is resized as a result of a call to layout, the
- * resize event will invoke the layout of the child. Note that
- * a layout due to a resize will not flush any cached information
- * (same as <code>layout(false)</code>).
- * </p>
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise
- * @param all <code>true</code> if all children in the receiver's widget tree should be laid out, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void layout (boolean changed, boolean all) {
- checkWidget ();
- if (layout == null && !all) return;
- markLayout (changed, all);
- updateLayout (true, all);
-}
-
-/**
- * Forces a lay out (that is, sets the size and location) of all widgets that
- * are in the parent hierarchy of the changed control up to and including the
- * receiver. The layouts in the hierarchy must not rely on any information
- * cached about the changed control or any of its ancestors. The layout may
- * (potentially) optimize the work it is doing by assuming that none of the
- * peers of the changed control have changed state since the last layout.
- * If an ancestor does not have a layout, skip it.
- * <p>
- * Note: Layout is different from painting. If a child is
- * moved or resized such that an area in the parent is
- * exposed, then the parent will paint. If no child is
- * affected, the parent will not paint.
- * </p>
- *
- * @param changed a control that has had a state change which requires a recalculation of its size
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li>
- * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void layout (Control [] changed) {
- checkWidget ();
- if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<changed.length; i++) {
- Control control = changed [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- boolean ancestor = false;
- Composite composite = control.parent;
- while (composite != null) {
- ancestor = composite == this;
- if (ancestor) break;
- composite = composite.parent;
- }
- if (!ancestor) error (SWT.ERROR_INVALID_PARENT);
- }
- int updateCount = 0;
- Composite [] update = new Composite [16];
- for (int i=0; i<changed.length; i++) {
- Control child = changed [i];
- Composite composite = child.parent;
- while (child != this) {
- if (composite.layout != null) {
- composite.state |= LAYOUT_NEEDED;
- if (!composite.layout.flushCache (child)) {
- composite.state |= LAYOUT_CHANGED;
- }
- }
- if (updateCount == update.length) {
- Composite [] newUpdate = new Composite [update.length + 16];
- System.arraycopy (update, 0, newUpdate, 0, update.length);
- update = newUpdate;
- }
- child = update [updateCount++] = composite;
- composite = child.parent;
- }
- }
- for (int i=updateCount-1; i>=0; i--) {
- update [i].updateLayout (true, false);
- }
-}
-
-void OnRender(int drawingContext) {
- if (isDisposed ()) return;
- OS.SWTCanvas_Visual (handle, 0);
- if (display.ignoreRender) {
- display.addInvalidate (this);
- return;
- }
- if (!hooks (SWT.Paint)) return;
- int width = (int)OS.FrameworkElement_ActualWidth (handle);
- int height = (int)OS.FrameworkElement_ActualHeight (handle);
- if (width != 0 && height != 0) {
- GCData data = new GCData ();
- data.device = display;
- data.drawingContext = drawingContext;
- GC gc = GC.wpf_new (this, data);
- Event event = new Event ();
- event.gc = gc;
- event.width = width;
- event.height = height;
- sendEvent (SWT.Paint, event);
- event.gc = null;
- gc.dispose ();
- }
-}
-
-void markLayout (boolean changed, boolean all) {
- if (layout != null) {
- state |= LAYOUT_NEEDED;
- if (changed) state |= LAYOUT_CHANGED;
- }
- if (all) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].markLayout (changed, all);
- }
- }
-}
-
-Point minimumSize (int wHint, int hHint, boolean changed) {
- Control [] children = _getChildren ();
- int width = 0, height = 0;
- for (int i=0; i<children.length; i++) {
- Rectangle rect = children [i].getBounds ();
- width = Math.max (width, rect.x + rect.width);
- height = Math.max (height, rect.y + rect.height);
- }
- return new Point (width, height);
-}
-
-int parentingHandle () {
- return handle;
-}
-
-void releaseChildren (boolean destroy) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child != null && !child.isDisposed ()) {
- child.release (false);
- }
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
-// if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) {
-// int hwndChild = OS.GetWindow (handle, OS.GW_CHILD);
-// if (hwndChild != 0) {
-// int threadId = OS.GetWindowThreadProcessId (hwndChild, null);
-// if (threadId != OS.GetCurrentThreadId ()) {
-// OS.ShowWindow (hwndChild, OS.SW_HIDE);
-// OS.SetParent (hwndChild, 0);
-// }
-// }
-// }
- layout = null;
- tabList = null;
-}
-
-void removeChild (Control control) {
- int topHandle = control.topHandle ();
- int parentHandle = parentingHandle ();
- int children = OS.Panel_Children (parentHandle);
- OS.UIElementCollection_Remove (children, topHandle);
- OS.GCHandle_Free (children);
-}
-
-void removeControl (Control control) {
- fixTabList (control);
-}
-
-void resized () {
- super.resized();
- if (isDisposed ()) return;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false, false);
- }
-}
-
-/**
- * WARNING: THIS API IS UNDER CONSTRUCTION AND SHOULD NOT BE USED
- */
-public void setAlpha(int alpha) {
- checkWidget ();
- int backgroundHandle = backgroundHandle ();
- int property = backgroundProperty ();
- int brush = OS.DependencyObject_GetValue (backgroundHandle, property);
- if (brush != 0) {
- int newBrush = OS.Freezable_Clone(brush);
- OS.Brush_Opacity (newBrush, (alpha & 0xFF) / (double)0xFF);
- OS.DependencyObject_SetValue (backgroundHandle, property, newBrush);
- OS.GCHandle_Free (brush);
- OS.GCHandle_Free (newBrush);
- }
- OS.GCHandle_Free (property);
-// OS.UIElement_Opacity (handle, (alpha & 0xFF) / (double)0xFF);
-}
-
-void setBackgroundBrush (int brush) {
- if (brush != 0) {
- OS.Panel_Background (handle, brush);
- } else {
- int property = OS.Panel_BackgroundProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
-}
-
-/**
- * Sets the background drawing mode to the argument which should
- * be one of the following constants defined in class <code>SWT</code>:
- * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>,
- * <code>INHERIT_FORCE</code>.
- *
- * @param mode the new background mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- *
- * @since 3.2
- */
-public void setBackgroundMode (int mode) {
- checkWidget ();
- backgroundMode = mode;
- Control [] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- children [i].updateBackgroundMode ();
- }
-}
-
-int setBounds (int x, int y, int width, int height, int flags) {
- int result = super.setBounds (x, y, width, height, flags);
- if ((result & RESIZED) != 0 && layout != null) {
- markLayout (false, false);
- updateLayout (false, false);
- }
- return result;
-}
-
-void setClipping () {
- OS.UIElement_ClipToBounds (topHandle (), true);
-}
-
-public boolean setFocus () {
- checkWidget();
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.getVisible () && child.setFocus ()) return true;
- }
- return super.setFocus ();
-}
-
-void setFont (int font, double size) {
-}
-
-void setForegroundBrush (int brush) {
- OS.UIElement_InvalidateVisual (handle);
-}
-
-/**
- * Sets the layout which is associated with the receiver to be
- * the argument which may be null.
- *
- * @param layout the receiver's new layout or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLayout (Layout layout) {
- checkWidget ();
- this.layout = layout;
-}
-
-/**
- * If the argument is <code>true</code>, causes subsequent layout
- * operations in the receiver or any of its children to be ignored.
- * No layout of any kind can occur in the receiver or any of its
- * children until the flag is set to false.
- * Layout operations that occurred while the flag was
- * <code>true</code> are remembered and when the flag is set to
- * <code>false</code>, the layout operations are performed in an
- * optimized manner. Nested calls to this method are stacked.
- *
- * @param defer the new defer state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #layout(boolean)
- * @see #layout(Control[])
- *
- * @since 3.1
- */
-public void setLayoutDeferred (boolean defer) {
- if (!defer) {
- if (--layoutCount == 0) {
- if ((state & LAYOUT_CHILD) != 0 || (state & LAYOUT_NEEDED) != 0) {
- updateLayout (true, true);
- }
- }
- } else {
- layoutCount++;
- }
-}
-
-/**
- * Sets the tabbing order for the specified controls to
- * match the order that they occur in the argument list.
- *
- * @param tabList the ordered list of controls representing the tab order or null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if a widget in the tabList is null or has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if widget in the tabList is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTabList (Control [] tabList) {
- checkWidget ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- Control control = tabList [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
- Control [] newList = new Control [tabList.length];
- System.arraycopy (tabList, 0, newList, 0, tabList.length);
- tabList = newList;
- }
- this.tabList = tabList;
-}
-
-boolean setTabGroupFocus () {
- if (isTabItem ()) return setTabItemFocus ();
- boolean takeFocus = (style & SWT.NO_FOCUS) == 0;
- if ((state & CANVAS) != 0) {
- takeFocus = hooksKeys ();
- if ((style & SWT.EMBEDDED) != 0) takeFocus = true;
- }
- if (takeFocus && setTabItemFocus ()) return true;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.isTabItem () && child.setTabItemFocus ()) return true;
- }
- return false;
-}
-
-boolean translateMnemonic (Event event, Control control) {
- if (super.translateMnemonic (event, control)) return true;
- if (control != null) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.translateMnemonic (event, control)) return true;
- }
- }
- return false;
-}
-
-int traversalCode(int key, int event) {
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_FOCUS) != 0) return 0;
- if (hooksKeys ()) return 0;
- }
- return super.traversalCode (key, event);
-}
-
-boolean translateTraversal (int msg) {
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) return false;
- return super.translateTraversal (msg);
-}
-
-void updateBackgroundColor () {
- super.updateBackgroundColor ();
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- if ((children [i].state & PARENT_BACKGROUND) != 0) {
- children [i].updateBackgroundColor ();
- }
- }
-}
-
-void updateBackgroundImage () {
- super.updateBackgroundImage ();
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- if ((children [i].state & PARENT_BACKGROUND) != 0) {
- children [i].updateBackgroundImage ();
- }
- }
-}
-
-void updateBackgroundMode () {
- super.updateBackgroundMode ();
- Control [] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- children [i].updateBackgroundMode ();
- }
-}
-
-void updateFont (Font oldFont, Font newFont) {
- super.updateFont (oldFont, newFont);
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control control = children [i];
- if (!control.isDisposed ()) {
- control.updateFont (oldFont, newFont);
- }
- }
-}
-
-void updateLayout (boolean resize, boolean all) {
- Composite parent = findDeferredControl ();
- if (parent != null) {
- parent.state |= LAYOUT_CHILD;
- return;
- }
- if ((state & LAYOUT_NEEDED) != 0) {
- boolean changed = (state & LAYOUT_CHANGED) != 0;
- state &= ~(LAYOUT_NEEDED | LAYOUT_CHANGED);
- layout.layout (this, changed);
- }
- if (all) {
- state &= ~LAYOUT_CHILD;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].updateLayout (resize, all);
- }
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Control.java
deleted file mode 100644
index 1cbda102e8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Control.java
+++ /dev/null
@@ -1,3621 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.accessibility.*;
-
-//TEMPORARY CODE
-import org.eclipse.swt.effects.*;
-
-/**
- * Control is the abstract superclass of all windowed user interface classes.
- * <p>
- * <dl>
- * <dt><b>Styles:</b>
- * <dd>BORDER</dd>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * <dt><b>Events:</b>
- * <dd>DragDetect, FocusIn, FocusOut, Help, KeyDown, KeyUp, MenuDetect, MouseDoubleClick, MouseDown, MouseEnter,
- * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize, Traverse</dd>
- * </dl>
- * </p><p>
- * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#control">Control snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public abstract class Control extends Widget implements Drawable {
- Cursor cursor;
- Menu menu;
- String toolTipText;
- Object layoutData;
- Accessible accessible;
- Image backgroundImage;
- Region region;
-// int drawCount;
- int foreground, background;
- int x, y, width, height;
- Font font;
- Composite parent;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Control () {
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#LEFT_TO_RIGHT
- * @see SWT#RIGHT_TO_LEFT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Control (Composite parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget ();
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize,typedListener);
- addListener (SWT.Move,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when a drag gesture occurs, by sending it
- * one of the messages defined in the <code>DragDetectListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #removeDragDetectListener
- *
- * @since 3.3
- */
-public void addDragDetectListener (DragDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.DragDetect,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control gains or loses focus, by sending
- * it one of the messages defined in the <code>FocusListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see FocusListener
- * @see #removeFocusListener
- */
-public void addFocusListener (FocusListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.FocusIn,typedListener);
- addListener (SWT.FocusOut,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when help events are generated for the control,
- * by sending it one of the messages defined in the
- * <code>HelpListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard, by sending
- * it one of the messages defined in the <code>KeyListener</code>
- * interface.
- * <p>
- * When a key listener is added to a control, the control
- * will take part in widget traversal. By default, all
- * traversal keys (such as the tab key and so on) are
- * delivered to the control. In order for a control to take
- * part in traversal, it should listen for traversal events.
- * Otherwise, the user can traverse into a control but not
- * out. Note that native controls such as table and tree
- * implement key traversal in the operating system. It is
- * not necessary to add traversal listeners for these controls,
- * unless you want to override the default traversal.
- * </p>
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #removeKeyListener
- */
-public void addKeyListener (KeyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.KeyUp,typedListener);
- addListener (SWT.KeyDown,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the platform-specific context menu trigger
- * has occurred, by sending it one of the messages defined in
- * the <code>MenuDetectListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #removeMenuDetectListener
- *
- * @since 3.3
- */
-public void addMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MenuDetect, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when mouse buttons are pressed and released, by sending
- * it one of the messages defined in the <code>MouseListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseListener
- * @see #removeMouseListener
- */
-public void addMouseListener (MouseListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseDown,typedListener);
- addListener (SWT.MouseUp,typedListener);
- addListener (SWT.MouseDoubleClick,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse passes or hovers over controls, by sending
- * it one of the messages defined in the <code>MouseTrackListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseTrackListener
- * @see #removeMouseTrackListener
- */
-public void addMouseTrackListener (MouseTrackListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseEnter,typedListener);
- addListener (SWT.MouseExit,typedListener);
- addListener (SWT.MouseHover,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse moves, by sending it one of the
- * messages defined in the <code>MouseMoveListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseMoveListener
- * @see #removeMouseMoveListener
- */
-public void addMouseMoveListener (MouseMoveListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseMove,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse wheel is scrolled, by sending
- * it one of the messages defined in the
- * <code>MouseWheelListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseWheelListener
- * @see #removeMouseWheelListener
- *
- * @since 3.3
- */
-public void addMouseWheelListener (MouseWheelListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseWheel, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver needs to be painted, by sending it
- * one of the messages defined in the <code>PaintListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see PaintListener
- * @see #removePaintListener
- */
-public void addPaintListener (PaintListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Paint,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when traversal events occur, by sending it
- * one of the messages defined in the <code>TraverseListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TraverseListener
- * @see #removeTraverseListener
- */
-public void addTraverseListener (TraverseListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Traverse,typedListener);
-}
-
-void addWidget () {
- parent.addChild (this);
-}
-
-int borderHandle () {
- return handle;
-}
-
-void checkBackground () {
- Shell shell = getShell ();
- if (this == shell) return;
- state &= ~PARENT_BACKGROUND;
- Composite composite = parent;
- do {
- int mode = composite.backgroundMode;
- if (mode != 0) {
- if (mode == SWT.INHERIT_DEFAULT) {
- Control control = this;
- do {
- if ((control.state & THEME_BACKGROUND) == 0) {
- return;
- }
- control = control.parent;
- } while (control != composite);
- }
- state |= PARENT_BACKGROUND;
- return;
- }
- if (composite == shell) break;
- composite = composite.parent;
- } while (true);
-}
-
-void checkBorder () {
- if (getBorderWidth () == 0) style &= ~SWT.BORDER;
-}
-
-void checkBuffered () {
- style |= SWT.DOUBLE_BUFFERED;
-}
-
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>preferred size</em> of a control is the size that it would
- * best be displayed at. The width hint and height hint arguments
- * allow the caller to ask a control questions such as "Given a particular
- * width, how high does the control need to be to show all of the contents?"
- * To indicate that the caller does not wish to constrain a particular
- * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
- * </p>
- *
- * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
- * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
- * @return the preferred size of the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Layout
- * @see #getBorderWidth
- * @see #getBounds
- * @see #getSize
- * @see #pack(boolean)
- * @see "computeTrim, getClientArea for controls that implement them"
- */
-public Point computeSize (int wHint, int hHint) {
- return computeSize (wHint, hHint, true);
-}
-
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>preferred size</em> of a control is the size that it would
- * best be displayed at. The width hint and height hint arguments
- * allow the caller to ask a control questions such as "Given a particular
- * width, how high does the control need to be to show all of the contents?"
- * To indicate that the caller does not wish to constrain a particular
- * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
- * </p><p>
- * If the changed flag is <code>true</code>, it indicates that the receiver's
- * <em>contents</em> have changed, therefore any caches that a layout manager
- * containing the control may have been keeping need to be flushed. When the
- * control is resized, the changed flag will be <code>false</code>, so layout
- * manager caches can be retained.
- * </p>
- *
- * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
- * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
- * @param changed <code>true</code> if the control's contents have changed, and <code>false</code> otherwise
- * @return the preferred size of the control.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Layout
- * @see #getBorderWidth
- * @see #getBounds
- * @see #getSize
- * @see #pack(boolean)
- * @see "computeTrim, getClientArea for controls that implement them"
- */
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- return computeSize (handle, wHint, hHint, changed);
-}
-
-Point computeSize (int handle, int wHint, int hHint, boolean changed) {
- int width = wHint, height = hHint;
- if (wHint == SWT.DEFAULT) width = 0x7FFFFFFF;
- if (hHint == SWT.DEFAULT) height = 0x7FFFFFFF;
- width = Math.max (0, width);
- height = Math.max (0, height);
- int availSize = OS.gcnew_Size ((double)width, (double)height);
- if (availSize == 0) error (SWT.ERROR_NO_HANDLES);
- double requestWidth = OS.FrameworkElement_Width (handle);
- if (requestWidth >= 0) {
- int widthDP = OS.FrameworkElement_WidthProperty ();
- OS.DependencyObject_ClearValue (handle, widthDP);
- OS.GCHandle_Free (widthDP);
- }
- double requestHeight = OS.FrameworkElement_Height (handle);
- if (requestHeight >= 0) {
- int heightDP = OS.FrameworkElement_HeightProperty ();
- OS.DependencyObject_ClearValue (handle, heightDP);
- OS.GCHandle_Free (heightDP);
- }
- OS.UIElement_Measure (handle, availSize);
- OS.GCHandle_Free (availSize);
- int size = OS.UIElement_DesiredSize (handle);
- width = (int) OS.Size_Width (size);
- height = (int) OS.Size_Height (size);
- OS.GCHandle_Free (size);
- if (requestWidth >= 0) OS.FrameworkElement_Width (handle, requestWidth);
- if (requestHeight >= 0) OS.FrameworkElement_Height (handle, requestHeight);
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- return new Point (width, height);
-}
-
-Control computeTabGroup () {
- if (isTabGroup ()) return this;
- return parent.computeTabGroup ();
-}
-
-Control computeTabRoot () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- int index = 0;
- while (index < tabList.length) {
- if (tabList [index] == this) break;
- index++;
- }
- if (index == tabList.length) {
- if (isTabGroup ()) return this;
- }
- }
- return parent.computeTabRoot ();
-}
-
-Control [] computeTabList () {
- if (isTabGroup ()) {
- if (getVisible () && getEnabled ()) {
- return new Control [] {this};
- }
- }
- return new Control [0];
-}
-
-void createWidget () {
- state |= DRAG_DETECT;
- checkOrientation (parent);
- super.createWidget ();
- checkBackground ();
- checkBuffered ();
- setClipping ();
- if (defaultBackground () != 0 || (state & PARENT_BACKGROUND) != 0) {
- setBackground ();
- }
-}
-
-/**
- * WARNING: THIS API IS UNDER CONSTRUCTION AND SHOULD NOT BE USED
- */
-public void setAlpha(int alpha) {
- checkWidget ();
- OS.UIElement_Opacity (handle, (alpha & 0xFF) / (double)0xFF);
-}
-
-void setClipping () {
- //accept default clipping
-}
-
-int defaultBackground () {
- return 0;
-}
-
-Font defaultFont () {
- return display.getSystemFont ();
-}
-
-int defaultForeground () {
- return display.getSystemColor (SWT.COLOR_BLACK).handle;
-}
-
-void deregister () {
- display.removeWidget (handle);
-}
-
-void destroyWidget () {
- parent.removeChild (this);
- releaseHandle ();
-}
-
-/**
- * Detects a drag and drop gesture. This method is used
- * to detect a drag gesture when called from within a mouse
- * down listener.
- *
- * <p>By default, a drag is detected when the gesture
- * occurs anywhere within the client area of a control.
- * Some controls, such as tables and trees, override this
- * behavior. In addition to the operating system specific
- * drag gesture, they require the mouse to be inside an
- * item. Custom widget writers can use <code>setDragDetect</code>
- * to disable the default detection, listen for mouse down,
- * and then call <code>dragDetect()</code> from within the
- * listener to conditionally detect a drag.
- * </p>
- *
- * @param event the mouse down event
- *
- * @return <code>true</code> if the gesture occurred, and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT when the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @see #getDragDetect
- * @see #setDragDetect
- *
- * @since 3.3
- */
-public boolean dragDetect (Event event) {
- checkWidget ();
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- return dragDetect (event.button, event.count, event.stateMask, event.x, event.y);
-}
-
-/**
- * Detects a drag and drop gesture. This method is used
- * to detect a drag gesture when called from within a mouse
- * down listener.
- *
- * <p>By default, a drag is detected when the gesture
- * occurs anywhere within the client area of a control.
- * Some controls, such as tables and trees, override this
- * behavior. In addition to the operating system specific
- * drag gesture, they require the mouse to be inside an
- * item. Custom widget writers can use <code>setDragDetect</code>
- * to disable the default detection, listen for mouse down,
- * and then call <code>dragDetect()</code> from within the
- * listener to conditionally detect a drag.
- * </p>
- *
- * @param event the mouse down event
- *
- * @return <code>true</code> if the gesture occurred, and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT when the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @see #getDragDetect
- * @see #setDragDetect
- *
- * @since 3.3
- */
-public boolean dragDetect (MouseEvent event) {
- checkWidget ();
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- return dragDetect (event.button, event.count, event.stateMask, event.x, event.y);
-}
-
-boolean dragDetect (int button, int count, int stateMask, int x, int y) {
- if (button != 1 || count != 1) return false;
- boolean dragging = dragDetect (x, y, false);
- if (dragging) return sendDragEvent (button, stateMask, x, y);
- return false;
-}
-
-void dragHandler () {
- int frame = display.dragDetectFrame = OS.gcnew_DispatcherFrame ();
- OS.Dispatcher_PushFrame (frame);
- OS.GCHandle_Free (frame);
- OS.GCHandle_Free (display.dragRect);
- if (display.dragMouseDown != 0) OS.GCHandle_Free (display.dragMouseDown);
- display.dragMouseDown = display.dragDetectFrame = display.dragRect = 0;
-}
-
-boolean dragDetect (double x, double y, boolean post) {
- display.dragging = false;
- double minH = OS.SystemParameters_MinimumHorizontalDragDistance ();
- double minV = OS.SystemParameters_MinimumVerticalDragDistance ();
- display.dragRect = OS.gcnew_Rect(x - minH, y - minV, minH * 2, minV * 2);
- if (post) {
- int handler = OS.gcnew_NoArgsDelegate (jniRef, "dragHandler");
- int operation = OS.Dispatcher_BeginInvoke (display.dispatcher, OS.DispatcherPriority_Send, handler);
- OS.GCHandle_Free (operation);
- OS.GCHandle_Free (handler);
- } else {
- dragHandler ();
- }
- return display.dragging;
-}
-
-void enableWidget (boolean enabled) {
- OS.UIElement_IsEnabled (handle, enabled);
-}
-
-boolean drawGripper (int x, int y, int width, int height, boolean vertical) {
- return false;
-}
-
-Control findBackgroundControl () {
- if (background != 0 || backgroundImage != null) return this;
- return (state & PARENT_BACKGROUND) != 0 ? parent.findBackgroundControl () : null;
-}
-
-Control findThemeControl () {
- return background == 0 && backgroundImage == null ? parent.findThemeControl () : null;
-}
-
-Control findImageControl () {
- Control control = findBackgroundControl ();
- return control != null && control.backgroundImage != null ? control : null;
-}
-
-Menu [] findMenus (Control control) {
- if (menu != null && this != control) return new Menu [] {menu};
- return new Menu [0];
-}
-
-char findMnemonic (String string) {
- int index = 0;
- int length = string.length ();
- do {
- while (index < length && string.charAt (index) != '&') index++;
- if (++index >= length) return '\0';
- if (string.charAt (index) != '&') return string.charAt (index);
- index++;
- } while (index < length);
- return '\0';
-}
-
-void fixFocus (Control focusControl) {
- Shell shell = getShell ();
- Control control = this;
- while (control != shell && (control = control.parent) != null) {
- if (control.setFocus ()) return;
- }
- shell.setSavedFocus (focusControl);
- OS.UIElement_Focus (shell.shellHandle);
-}
-
-/**
- * Forces the receiver to have the <em>keyboard focus</em>, causing
- * all keyboard events to be delivered to it.
- *
- * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setFocus
- */
-public boolean forceFocus () {
- checkWidget ();
-// if (display.focusEvent == SWT.FocusOut) return false;
- Decorations shell = menuShell ();
- shell.setSavedFocus (this);
- if (!isEnabled () || !isVisible () || !isActive ()) return false;
- if (isFocusControl ()) return true;
- shell.setSavedFocus (null);
- OS.UIElement_Focus (handle);
- if (isDisposed ()) return false;
- shell.setSavedFocus (this);
- return isFocusControl ();
-}
-
-/**
- * Returns the accessible object for the receiver.
- * If this is the first time this object is requested,
- * then the object is created and returned.
- *
- * @return the accessible object
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Accessible#addAccessibleListener
- * @see Accessible#addAccessibleControlListener
- *
- * @since 2.0
- */
-public Accessible getAccessible () {
- checkWidget ();
- if (accessible == null) accessible = new_Accessible (this);
- return accessible;
-}
-
-/**
- * WARNING: THIS API IS UNDER CONSTRUCTION AND SHOULD NOT BE USED
- */
-public int getAlpha () {
- checkWidget ();
- return (int) (0XFF * OS.UIElement_Opacity (handle));
-}
-
-/**
- * Returns the receiver's background color.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on some versions of Windows the background of a TabFolder,
- * is a gradient rather than a solid color.
- * </p>
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Color getBackground () {
- checkWidget ();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- return Color.wpf_new (display, control.getBackgroundColor ());
-}
-
-/**
- * Returns the receiver's background image.
- *
- * @return the background image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Image getBackgroundImage () {
- checkWidget ();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- return control.backgroundImage;
-}
-
-int getBackgroundColor () {
- int color = background;
- if (color == 0) color = defaultBackground ();
- if (color == 0) color = OS.SystemColors_ControlColor;//TODO
- return color;
-}
-
-/**
- * Returns the receiver's border width.
- *
- * @return the border width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getBorderWidth () {
- checkWidget ();
- //FIXME
- return 2;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null),
- * unless the receiver is a shell. In this case, the location is
- * relative to the display.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget ();
- int topHandle = topHandle ();
- Point location = parent.getLocation (this);
- int width = (int) OS.FrameworkElement_Width (topHandle);
- int height = (int) OS.FrameworkElement_Height (topHandle);
- return new Rectangle (location.x, location.y, width, height);
-}
-
-String getClipboardText () {
- String string = "";
- int text = OS.Clipboard_GetText ();
- if (text != 0) {
- string = createJavaString (text);
- OS.GCHandle_Free(text);
- }
- return string;
-}
-
-/**
- * Returns the receiver's cursor, or null if it has not been set.
- * <p>
- * When the mouse pointer passes over a control its appearance
- * is changed to match the control's cursor.
- * </p>
- *
- * @return the receiver's cursor or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Cursor getCursor () {
- checkWidget ();
- return cursor;
-}
-
-/**
- * Returns <code>true</code> if the receiver is detecting
- * drag gestures, and <code>false</code> otherwise.
- *
- * @return the receiver's drag detect state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public boolean getDragDetect () {
- checkWidget ();
- return (state & DRAG_DETECT) != 0;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget ();
- return (state & DISABLED) == 0;
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Font getFont () {
- checkWidget ();
- return font != null ? font : defaultFont ();
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Color getForeground () {
- checkWidget ();
- return Color.wpf_new (display, getForegroundColor ());
-}
-
-int getForegroundColor () {
- return foreground != 0 ? foreground : defaultForeground ();
-}
-
-/**
- * Returns layout data which is associated with the receiver.
- *
- * @return the receiver's layout data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Object getLayoutData () {
- checkWidget ();
- return layoutData;
-}
-
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @return the receiver's location
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getLocation () {
- checkWidget ();
- return parent.getLocation (this);
-}
-
-/**
- * Returns the receiver's pop up menu if it has one, or null
- * if it does not. All controls may optionally have a pop up
- * menu that is displayed when the user requests one for
- * the control. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pop up
- * menu is platform specific.
- *
- * @return the receiver's menu
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenu () {
- checkWidget ();
- return menu;
-}
-
-/**
- * Returns the receiver's monitor.
- *
- * @return the receiver's monitor
- *
- * @since 3.0
- */
-public Monitor getMonitor () {
- checkWidget ();
- //TODO
- return display.getPrimaryMonitor ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Composite</code>
- * or null when the receiver is a shell that was created with null or
- * a display for a parent.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Composite getParent () {
- checkWidget ();
- return parent;
-}
-
-Control [] getPath () {
- int count = 0;
- Shell shell = getShell ();
- Control control = this;
- while (control != shell) {
- count++;
- control = control.parent;
- }
- control = this;
- Control [] result = new Control [count];
- while (control != shell) {
- result [--count] = control;
- control = control.parent;
- }
- return result;
-}
-
-/**
- * Returns the region that defines the shape of the control,
- * or null if the control has the default shape.
- *
- * @return the region that defines the shape of the shell (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public Region getRegion () {
- checkWidget ();
- return region;
-}
-
-/**
- * Returns the receiver's shell. For all controls other than
- * shells, this simply returns the control's nearest ancestor
- * shell. Shells return themselves, even if they are children
- * of other shells.
- *
- * @return the receiver's shell
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getParent
- */
-public Shell getShell () {
- checkWidget ();
- return parent.getShell ();
-}
-
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget ();
- int topHandle = topHandle ();
- int width = (int) OS.FrameworkElement_Width (topHandle);
- int height = (int) OS.FrameworkElement_Height (topHandle);
- return new Point (width, height);
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-
-/**
- * WARNING: THIS API IS UNDER CONSTRUCTION AND SHOULD NOT BE USED
- */
-public Transform getTransform () {
- int transform = OS.FrameworkElement_RenderTransform (handle);
- int matrix = OS.MatrixTransform_Matrix (transform);
- OS.GCHandle_Free (transform);
- float m11 = (float) OS.Matrix_M11 (matrix);
- float m12 = (float) OS.Matrix_M12 (matrix);
- float m21 = (float) OS.Matrix_M21 (matrix);
- float m22 = (float) OS.Matrix_M22 (matrix);
- float dx = (float) OS.Matrix_OffsetX (matrix);
- float dy = (float) OS.Matrix_OffsetY (matrix);
- OS.GCHandle_Free (matrix);
- //TODO - leaking
- return new Transform (display, m11, m12, m21, m22, dx, dy);
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- return OS.UIElement_Visibility (topHandle ()) == OS.Visibility_Visible;
-}
-
-Control getWidgetControl () {
- return this;
-}
-
-void hookEvents () {
- super.hookEvents ();
- int handler = OS.gcnew_KeyEventHandler (jniRef, "HandlePreviewKeyDown");
- OS.UIElement_PreviewKeyDown (handle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_KeyEventHandler (jniRef, "HandlePreviewKeyUp");
- OS.UIElement_PreviewKeyUp (handle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_TextCompositionEventHandler (jniRef, "HandlePreviewTextInput");
- OS.UIElement_PreviewTextInput (handle, handler);
- OS.GCHandle_Free (handler);
-
- int topHandle = topHandle ();
- handler = OS.gcnew_MouseButtonEventHandler (jniRef, "HandlePreviewMouseDown");
- OS.UIElement_PreviewMouseDown (topHandle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_MouseButtonEventHandler (jniRef, "HandlePreviewMouseUp");
- OS.UIElement_PreviewMouseUp (topHandle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_MouseEventHandler (jniRef, "HandleMouseEnter");
- OS.UIElement_MouseEnter (topHandle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_MouseEventHandler (jniRef, "HandleMouseLeave");
- OS.UIElement_MouseLeave (topHandle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_MouseEventHandler (jniRef, "HandlePreviewMouseMove");
- OS.UIElement_PreviewMouseMove (topHandle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_MouseWheelEventHandler (jniRef, "HandlePreviewMouseWheel");
- OS.UIElement_PreviewMouseWheel (topHandle, handler);
- OS.GCHandle_Free (handler);
-
- handler = OS.gcnew_KeyboardFocusChangedEventHandler (jniRef, "HandlePreviewGotKeyboardFocus");
- OS.UIElement_PreviewGotKeyboardFocus (handle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_KeyboardFocusChangedEventHandler (jniRef, "HandleLostKeyboardFocus");
- OS.UIElement_LostKeyboardFocus (handle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_ContextMenuEventHandler (jniRef, "HandleContextMenuOpening");
- OS.FrameworkElement_ContextMenuOpening (handle, handler);
- OS.GCHandle_Free (handler);
-
- handler = OS.gcnew_SizeChangedEventHandler(jniRef, "HandleSizeChanged");
- OS.FrameworkElement_SizeChanged (topHandle, handler);
- OS.GCHandle_Free (handler);
-
- int typeid = OS.Canvas_typeid();
- handler = OS.gcnew_EventHandler(jniRef, "HandleTopChanged");
- int property = OS.Canvas_TopProperty();
- int dpd = OS.DependencyPropertyDescriptor_FromProperty(property, typeid);
- OS.DependencyPropertyDescriptor_AddValueChanged(dpd, topHandle, handler);
- OS.GCHandle_Free(handler);
- OS.GCHandle_Free(property);
- OS.GCHandle_Free(dpd);
- handler = OS.gcnew_EventHandler(jniRef, "HandleLeftChanged");
- property = OS.Canvas_LeftProperty();
- dpd = OS.DependencyPropertyDescriptor_FromProperty(property, typeid);
- OS.DependencyPropertyDescriptor_AddValueChanged(dpd, topHandle, handler);
- OS.GCHandle_Free(handler);
- OS.GCHandle_Free(property);
- OS.GCHandle_Free(dpd);
- OS.GCHandle_Free(typeid);
-}
-
-void HandleLeftChanged (int sender, int e) {
- int topHandle = topHandle();
- int x = (int)OS.Canvas_GetLeft(topHandle);
- int y = (int)OS.Canvas_GetTop(topHandle);
- if (x != this.x || y != this.y) {
- this.x = x;
- this.y = y;
- sendEvent(SWT.Move);
- }
-}
-
-void HandleTopChanged (int sender, int e) {
- int topHandle = topHandle();
- int x = (int)OS.Canvas_GetLeft(topHandle);
- int y = (int)OS.Canvas_GetTop(topHandle);
- if (x != this.x || y != this.y) {
- this.x = x;
- this.y = y;
- sendEvent(SWT.Move);
- }
-}
-
-void HandleContextMenuOpening (int sender, int e) {
- if (!checkEvent (e)) return;
- int mouse = OS.Mouse_GetPosition (handle);
- int x = (int) OS.Point_X (mouse);
- int y = (int) OS.Point_Y (mouse);
- OS.GCHandle_Free (mouse);
- Point point = display.map (this, null, x, y);
- showMenu (point.x, point.y);
- OS.RoutedEventArgs_Handled (e, true);
-}
-
-void HandlePreviewGotKeyboardFocus (int sender, int e) {
- if (!checkEvent (e)) return;
- if (OS.UIElement_IsKeyboardFocusWithin (handle)) return;
- sendFocusEvent (SWT.FocusIn);
-}
-
-void HandleLostKeyboardFocus (int sender, int e) {
- if (!checkEvent (e)) return;
- if (OS.UIElement_IsKeyboardFocusWithin (handle)) return;
- sendFocusEvent (SWT.FocusOut);
-}
-
-void HandlePreviewKeyDown (int sender, int e) {
- if (!checkEvent (e)) return;
-
- if (display.dragDetectFrame != 0) {
- if (OS.KeyEventArgs_Key (e) == OS.Key_Escape) {
- OS.DispatcherFrame_Continue (display.dragDetectFrame, false);
- }
- }
-
- /* Let OS handle mnemonics for now */
-// if (translateMnemonic (e)) {
-// OS.RoutedEventArgs_Handled (e, true);
-// return;
-// }
- if (translateTraversal (e)) {
- OS.RoutedEventArgs_Handled (e, true);
- return;
- }
- sendKeyEvent (SWT.KeyDown, e, false);
-}
-
-void HandlePreviewKeyUp (int sender, int e) {
- if (!checkEvent (e)) return;
- sendKeyEvent (SWT.KeyUp, e, false);
-}
-
-void HandlePreviewMouseDown (int sender, int e) {
- if (!checkEvent (e)) return;
- if ((state & CANVAS) != 0) {
- OS.UIElement_CaptureMouse (handle);
- }
-
- if (OS.MouseButtonEventArgs_ChangedButton (e) == 0 && OS.MouseButtonEventArgs_ClickCount (e) == 1) {
- if ((state & DRAG_DETECT) != 0 && hooks (SWT.DragDetect)) {
- int point = OS.MouseEventArgs_GetPosition (e, handle);
- double x = OS.Point_X (point);
- double y = OS.Point_Y (point);
- OS.GCHandle_Free (point);
- display.dragMouseDown = OS.GCHandle_Alloc (e);
- dragDetect (x, y, true);
- }
- }
-
- sendMouseEvent (SWT.MouseDown, e, false);
-}
-
-void HandlePreviewMouseUp (int sender, int e) {
- if (!checkEvent (e)) return;
- if ((state & CANVAS) != 0) {
- OS.UIElement_ReleaseMouseCapture (handle);
- }
- if (display.dragDetectFrame != 0) {
- OS.DispatcherFrame_Continue (display.dragDetectFrame, false);
- }
- sendMouseEvent (SWT.MouseUp, e, false);
-}
-
-void HandleMouseEnter (int sender, int e) {
- if (!checkEvent (e)) return;
- Control control = display.getCursorControl ();
- if (control != this) return;
-
- Control lastMouseControl = display.mouseControl;
- if (lastMouseControl != null && !lastMouseControl.isDisposed() && lastMouseControl != this) {
- if (OS.Visual_IsDescendantOf (topHandle (), lastMouseControl.topHandle())) {
- lastMouseControl.sendMouseEvent (SWT.MouseExit, e, false);
- }
- }
- display.mouseControl = this;
- sendMouseEvent (SWT.MouseEnter, e, false);
-}
-
-void HandleMouseLeave (int sender, int e) {
- if (!checkEvent (e)) return;
- if (this != display.mouseControl) return;
- sendMouseEvent (SWT.MouseExit, e, false);
-}
-
-void HandlePreviewMouseMove (int sender, int e) {
- if (!checkEvent (e)) return;
- if (display.dragDetectFrame != 0) {
- OS.RoutedEventArgs_Handled (e, true);
- int point = OS.MouseEventArgs_GetPosition (e, handle);
- boolean contains = OS.Rect_Contains (display.dragRect, point);
- OS.GCHandle_Free (point);
- if (!contains) {
- display.dragging = true;
- OS.DispatcherFrame_Continue (display.dragDetectFrame, false);
- if (display.dragMouseDown != 0) {
- sendDragEvent (display.dragMouseDown);
- OS.GCHandle_Free (display.dragMouseDown);
- display.dragMouseDown = 0;
- }
- }
- return;
- }
- Control lastMouseControl = display.mouseControl;
- if (lastMouseControl != null && !lastMouseControl.isDisposed() && lastMouseControl != this) {
- if (OS.Visual_IsAncestorOf (topHandle (), lastMouseControl.topHandle ())) {
- sendMouseEvent (SWT.MouseEnter, e, false);
- }
- }
- display.mouseControl = this;
- sendMouseEvent (SWT.MouseMove, e, false);
-}
-
-void HandlePreviewMouseWheel (int sender, int e) {
- if (!checkEvent (e)) return;
- sendMouseEvent (SWT.MouseWheel, e, false);
-}
-
-void HandlePreviewTextInput(int sender, int e) {
- if (!checkEvent (e)) return;
- sendKeyEvent (SWT.KeyDown, e, true);
-}
-
-void HandleSizeChanged (int sender, int e) {
- if (!checkEvent (e)) return;
- int topHandle = topHandle();
- int width = (int) OS.FrameworkElement_ActualWidth (topHandle);
- int height = (int) OS.FrameworkElement_ActualHeight (topHandle);
- if (this.width != width || this.height != height) {
- this.width = width;
- this.height = height;
- resized ();
- }
-}
-
-void resized () {
- sendEvent (SWT.Resize);
-}
-
-boolean hasFocus () {
-// return OS.UIElement_IsFocused (handle);
-// return OS.UIElement_IsKeyboardFocused (handle);
- return display.getFocusControl() == this;
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Control</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- */
-public int internal_new_GC (GCData data) {
- checkWidget();
- int drawingContext = data != null ? data.drawingContext : 0;
- int visual = handle;
- double width = OS.FrameworkElement_ActualWidth (handle);
- double height = OS.FrameworkElement_ActualHeight (handle);
- int rect = OS.gcnew_Rect (0, 0, width, height);
- int clip = OS.gcnew_RectangleGeometry (rect);
- if (drawingContext != 0) {
- OS.DrawingContext_PushClip(drawingContext, clip);
- } else {
- if ((state & CANVAS) != 0) {
- visual = OS.SWTCanvas_Visual (handle);
- if (visual == 0) {
- visual = OS.gcnew_DrawingVisual();
- if (visual == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.SWTCanvas_Visual (handle, visual);
- }
- } else {
- visual = OS.gcnew_DrawingVisual();
- if (visual == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- }
- OS.ContainerVisual_Clip (visual, clip);
- int dc = OS.DrawingVisual_RenderOpen (visual);
- if (dc == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- drawingContext = dc;
- int drawing = OS.DrawingVisual_Drawing(visual);
- OS.DrawingContext_DrawDrawing(drawingContext, drawing);
- OS.GCHandle_Free(drawing);
- }
- OS.GCHandle_Free (rect);
- OS.GCHandle_Free (clip);
- if (data != null) {
- int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((data.style & mask) == 0) {
- data.style |= style & (mask | SWT.MIRRORED);
- }
- data.device = display;
- data.foreground = getForegroundColor ();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- data.background = control.getBackgroundColor ();
- data.font = font != null ? font : defaultFont ();
- data.visual = visual;
- }
- return drawingContext;
-}
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Control</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int dc, GCData data) {
- checkWidget ();
- if (data != null && data.drawingContext == 0) {
- OS.DrawingContext_Close (dc);
- OS.GCHandle_Free (dc);
- OS.GCHandle_Free (data.visual);
- }
-}
-
-boolean isActive () {
-// Shell dialogShell = display.getModalDialogShell ();
-// if (dialogShell != null && dialogShell != getShell ()) {
-// return false;
-// }
- Shell shell = null;
- Shell [] modalShells = display.modalShells;
- if (modalShells != null) {
- int bits = SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- int index = modalShells.length;
- while (--index >= 0) {
- Shell modal = modalShells [index];
- if (modal != null) {
- if ((modal.style & bits) != 0) {
- Control control = this;
- while (control != null) {
- if (control == modal) break;
- control = control.parent;
- }
- if (control != modal) return false;
- break;
- }
- if ((modal.style & SWT.PRIMARY_MODAL) != 0) {
- if (shell == null) shell = getShell ();
- if (modal.parent == shell) return false;
- }
- }
- }
- }
- if (shell == null) shell = getShell ();
- return shell.getEnabled ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * ancestors up to and including the receiver's nearest ancestor
- * shell are enabled. Otherwise, <code>false</code> is returned.
- * A disabled control is typically not selectable from the user
- * interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget ();
- return getEnabled () && parent.isEnabled ();
-}
-
-/**
- * Returns <code>true</code> if the receiver has the user-interface
- * focus, and <code>false</code> otherwise.
- *
- * @return the receiver's focus state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isFocusControl () {
- checkWidget ();
- return hasFocus ();
-}
-
-boolean isFocusAncestor (Control control) {
- while (control != null && control != this && !(control instanceof Shell)) {
- control = control.parent;
- }
- return control == this;
-}
-
-/**
- * Returns <code>true</code> if the underlying operating
- * system supports this reparenting, otherwise <code>false</code>
- *
- * @return <code>true</code> if the widget can be reparented, otherwise <code>false</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isReparentable () {
- checkWidget ();
- return false;
-}
-
-boolean isShowing () {
- /*
- * This is not complete. Need to check if the
- * widget is obscurred by a parent or sibling.
- */
- if (!isVisible ()) return false;
- Control control = this;
- while (control != null) {
- Point size = control.getSize ();
- if (size.x == 0 || size.y == 0) {
- return false;
- }
- control = control.parent;
- }
- return true;
- /*
- * Check to see if current damage is included.
- */
-// if (!OS.IsWindowVisible (handle)) return false;
-// int flags = OS.DCX_CACHE | OS.DCX_CLIPCHILDREN | OS.DCX_CLIPSIBLINGS;
-// int hDC = OS.GetDCEx (handle, 0, flags);
-// int result = OS.GetClipBox (hDC, new RECT ());
-// OS.ReleaseDC (handle, hDC);
-// return result != OS.NULLREGION;
-}
-
-boolean isTabGroup () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == this) return true;
- }
- }
- int code = traversalCode (0, 0);
- if ((code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) != 0) return false;
- return (code & (SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_TAB_NEXT)) != 0;
-}
-
-boolean isTabItem () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == this) return false;
- }
- }
- int code = traversalCode (0, 0);
- return (code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) != 0;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * ancestors up to and including the receiver's nearest ancestor
- * shell are visible. Otherwise, <code>false</code> is returned.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget ();
- int topHandle = topHandle ();
- updateLayout (topHandle);
- return OS.UIElement_IsVisible (topHandle);
-}
-
-void markLayout (boolean changed, boolean all) {
- /* Do nothing */
-}
-
-Decorations menuShell () {
- return parent.menuShell ();
-}
-
-boolean mnemonicHit (char key) {
- return false;
-}
-
-boolean mnemonicMatch (char key) {
- return false;
-}
-
-/**
- * Moves the receiver above the specified control in the
- * drawing order. If the argument is null, then the receiver
- * is moved to the top of the drawing order. The control at
- * the top of the drawing order will not be covered by other
- * controls even if they occupy intersecting areas.
- *
- * @param control the sibling control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveBelow
- * @see Composite#getChildren
- */
-public void moveAbove (Control control) {
- checkWidget ();
- if (parent == null) return; //TODO
- if (control != null) {
- if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- }
- int index;
- int parentHandle = parent.parentingHandle ();
- int children = OS.Panel_Children (parentHandle);
- if (control != null) {
- index = OS.UIElementCollection_IndexOf (children, control.topHandle ());
- } else {
- index = OS.UIElementCollection_Count (children) - 1;
- }
- int topHandle = topHandle ();
- if (OS.UIElementCollection_IndexOf (children, topHandle) < index) {
- OS.UIElementCollection_Remove (children, topHandle);
- OS.UIElementCollection_Insert (children, index, topHandle);
- }
- OS.GCHandle_Free (children);
-}
-
-/**
- * Moves the receiver below the specified control in the
- * drawing order. If the argument is null, then the receiver
- * is moved to the bottom of the drawing order. The control at
- * the bottom of the drawing order will be covered by all other
- * controls which occupy intersecting areas.
- *
- * @param control the sibling control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveAbove
- * @see Composite#getChildren
- */
-public void moveBelow (Control control) {
- checkWidget ();
- if (parent == null) return; //TODO
- if (control != null) {
- if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- }
- int index;
- int parentHandle = parent.parentingHandle ();
- int children = OS.Panel_Children (parentHandle);
- if (control != null) {
- index = Math.max (0, OS.UIElementCollection_IndexOf (children, control.topHandle ()) - 1);
- } else {
- if (parentHandle != parent.handle) {
- index = 1;
- } else {
- index = 0;
- }
- }
- int topHandle = topHandle ();
- if (OS.UIElementCollection_IndexOf (children, topHandle) > index) {
- OS.UIElementCollection_Remove (children, topHandle);
- OS.UIElementCollection_Insert (children, index, topHandle);
- }
- OS.GCHandle_Free (children);
-}
-
-Accessible new_Accessible (Control control) {
- return Accessible.internal_new_Accessible (this);
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeSize(int, int, boolean)
- */
-public void pack () {
- checkWidget ();
- pack (true);
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- * <p>
- * If the changed flag is <code>true</code>, it indicates that the receiver's
- * <em>contents</em> have changed, therefore any caches that a layout manager
- * containing the control may have been keeping need to be flushed. When the
- * control is resized, the changed flag will be <code>false</code>, so layout
- * manager caches can be retained.
- * </p>
- *
- * @param changed whether or not the receiver's contents have changed
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeSize(int, int, boolean)
- */
-public void pack (boolean changed) {
- checkWidget ();
- setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed));
-}
-
-/**
- * Prints the receiver and all children.
- *
- * @param gc the gc where the drawing occurs
- * @return <code>true</code> if the operation was successful and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean print (GC gc) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- return false;
-}
-
-/**
- * Causes the entire bounds of the receiver to be marked
- * as needing to be redrawn. The next time a paint request
- * is processed, the control will be completely painted,
- * including the background.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #update()
- * @see PaintListener
- * @see SWT#Paint
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#DOUBLE_BUFFERED
- */
-public void redraw () {
- checkWidget ();
- redraw (false);
-}
-
-void redraw (boolean all) {
-// checkWidget ();
- //TODO InvalidateVisual invalidates the entire visual tree
- OS.UIElement_InvalidateVisual (topHandle ());
- OS.UIElement_InvalidateVisual (handle);
-}
-
-/**
- * Causes the rectangular area of the receiver specified by
- * the arguments to be marked as needing to be redrawn.
- * The next time a paint request is processed, that area of
- * the receiver will be painted, including the background.
- * If the <code>all</code> flag is <code>true</code>, any
- * children of the receiver which intersect with the specified
- * area will also paint their intersecting areas. If the
- * <code>all</code> flag is <code>false</code>, the children
- * will not be painted.
- *
- * @param x the x coordinate of the area to draw
- * @param y the y coordinate of the area to draw
- * @param width the width of the area to draw
- * @param height the height of the area to draw
- * @param all <code>true</code> if children should redraw, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #update()
- * @see PaintListener
- * @see SWT#Paint
- * @see SWT#NO_BACKGROUND
- * @see SWT#NO_REDRAW_RESIZE
- * @see SWT#NO_MERGE_PAINTS
- * @see SWT#DOUBLE_BUFFERED
- */
-public void redraw (int x, int y, int width, int height, boolean all) {
- checkWidget ();
- if (width <= 0 || height <= 0) return;
- //TODO redraw only rect
- redraw(true);
-}
-
-void register () {
- display.addWidget (handle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (handle != 0) OS.GCHandle_Free (handle);
- handle = 0;
- parent = null;
-}
-
-void releaseParent () {
- parent.removeControl (this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
-// if (toolTipText != null) {
-// setToolTipText (getShell (), null);
-// }
- toolTipText = null;
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- menu = null;
- cursor = null;
- layoutData = null;
- if (accessible != null) {
- accessible.internal_dispose_Accessible ();
- }
- accessible = null;
- region = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when a drag gesture occurs.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragDetectListener
- * @see #addDragDetectListener
- *
- * @since 3.3
- */
-public void removeDragDetectListener(DragDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.DragDetect, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control gains or loses focus.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see FocusListener
- * @see #addFocusListener
- */
-public void removeFocusListener(FocusListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.FocusIn, listener);
- eventTable.unhook (SWT.FocusOut, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #addKeyListener
- */
-public void removeKeyListener(KeyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.KeyUp, listener);
- eventTable.unhook (SWT.KeyDown, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the platform-specific context menu trigger has
- * occurred.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #addMenuDetectListener
- *
- * @since 3.3
- */
-public void removeMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MenuDetect, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse passes or hovers over controls.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseTrackListener
- * @see #addMouseTrackListener
- */
-public void removeMouseTrackListener(MouseTrackListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseEnter, listener);
- eventTable.unhook (SWT.MouseExit, listener);
- eventTable.unhook (SWT.MouseHover, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when mouse buttons are pressed and released.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseListener
- * @see #addMouseListener
- */
-public void removeMouseListener (MouseListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseDown, listener);
- eventTable.unhook (SWT.MouseUp, listener);
- eventTable.unhook (SWT.MouseDoubleClick, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse moves.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseMoveListener
- * @see #addMouseMoveListener
- */
-public void removeMouseMoveListener(MouseMoveListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseMove, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse wheel is scrolled.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseWheelListener
- * @see #addMouseWheelListener
- *
- * @since 3.3
- */
-public void removeMouseWheelListener (MouseWheelListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseWheel, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver needs to be painted.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see PaintListener
- * @see #addPaintListener
- */
-public void removePaintListener(PaintListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Paint, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when traversal events occur.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TraverseListener
- * @see #addTraverseListener
- */
-public void removeTraverseListener(TraverseListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Traverse, listener);
-}
-
-boolean sendFocusEvent (int type) {
- Shell shell = getShell ();
-
- Display display = this.display;
- display.focusControl = this;
- sendEvent (type);
- display.focusControl = null;
-
- /*
- * It is possible that the shell may be
- * disposed at this point. If this happens
- * don't send the activate and deactivate
- * events.
- */
- if (!shell.isDisposed ()) {
- switch (type) {
- case SWT.FocusIn:
- shell.setActiveControl (this);
- break;
- case SWT.FocusOut:
- if (shell != display.getActiveShell ()) {
- shell.setActiveControl (null);
- }
- break;
- }
- }
- return true;
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the control
- * if the argument is null.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on Windows the background of a Button cannot be changed.
- * </p>
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBackground (Color color) {
- checkWidget ();
- if (color != null) {
- if (color.isDisposed ()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- if (background != 0 && OS.Object_Equals (color.handle, background)) return;
- background = color.handle;
- } else {
- if (background == 0) return;
- background = 0;
- }
- setBackground ();
-// updateBackgroundColor ();
-}
-
-int backgroundHandle () {
- return handle;
-}
-
-int backgroundProperty () {
- return OS.Control_BackgroundProperty ();
-}
-
-void setBackground () {
- int backgroundHandle = backgroundHandle ();
- int property = backgroundProperty ();
- int brush = 0;
- if ((state & PARENT_BACKGROUND) == 0) {
- if (backgroundImage != null) {
- int imageHandle = backgroundImage.handle;
- brush = OS.gcnew_ImageBrush (imageHandle);
- OS.TileBrush_TileMode (brush, OS.TileMode_Tile);
- OS.TileBrush_Stretch (brush, OS.Stretch_Fill);
- OS.TileBrush_ViewportUnits (brush, OS.BrushMappingMode_Absolute);
- int rect = OS.gcnew_Rect (0, 0, OS.BitmapSource_PixelWidth (imageHandle), OS.BitmapSource_PixelHeight (imageHandle));
- OS.TileBrush_Viewport (brush, rect);
- OS.GCHandle_Free (rect);
- } else {
- int color = background;
- if (color == 0) {
- color = defaultBackground ();
- if ((state & THEME_BACKGROUND) != 0) {
- Control themeControl = findThemeControl ();
- if (themeControl != null) {
- if (color != 0) {
- /*
- * Feature in WPF. If the control does not have a background
- * brush it does not receive input events.
- * The fix is to set a transparent background.
- */
- color = OS.Colors_Transparent;
- }
- }
- }
- }
- if (color != 0) {
- brush = OS.gcnew_SolidColorBrush (color);
- }
- }
- }
- if (brush != 0) {
- OS.DependencyObject_SetValue (backgroundHandle, property, brush);
- OS.GCHandle_Free (brush);
- } else {
- OS.DependencyObject_ClearValue (backgroundHandle, property);
- }
- OS.GCHandle_Free (property);
-}
-
-/**
- * Sets the receiver's background image to the image specified
- * by the argument, or to the default system color for the control
- * if the argument is null. The background image is tiled to fill
- * the available space.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * For example, on Windows the background of a Button cannot be changed.
- * </p>
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument is not a bitmap</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setBackgroundImage (Image image) {
- checkWidget ();
- if (image != null) {
- if (image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (image.type != SWT.BITMAP) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (backgroundImage == image) return;
- backgroundImage = image;
- setBackground ();
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the arguments. The <code>x</code> and
- * <code>y</code> arguments are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the <code>x</code>
- * and <code>y</code> arguments are relative to the display.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (int x, int y, int width, int height) {
- checkWidget ();
- int flags = MOVED | RESIZED;
- setBounds (x, y, Math.max (0, width), Math.max (0, height), flags);
-}
-
-int setBounds (int x, int y, int width, int height, int flags) {
- int result = 0;
- int topHandle = topHandle ();
- if ((flags & MOVED) != 0) {
- int oldX = (int) OS.Canvas_GetLeft (topHandle);
- int oldY = (int) OS.Canvas_GetTop (topHandle);
- if (oldX != x) {
- this.x = x;
- OS.Canvas_SetLeft (topHandle, x);
- }
- if (oldY != y) {
- this.y = y;
- OS.Canvas_SetTop (topHandle, y);
- }
- if (oldX != x || oldY != y) {
- sendEvent (SWT.Move);
- if (isDisposed ()) return 0;
- result |= MOVED;
- }
- }
- if ((flags & RESIZED) != 0) {
- int oldWidth = (int) OS.FrameworkElement_Width (topHandle);
- int oldHeight = (int) OS.FrameworkElement_Height (topHandle);
- if (oldWidth != width) {
- this.width = width;
- OS.FrameworkElement_Width (topHandle, width);
- }
- if (oldHeight != height) {
- this.height = height;
- OS.FrameworkElement_Height (topHandle, height);
- }
- if (oldWidth != width || oldHeight != height) {
- sendEvent (SWT.Resize);
- if (isDisposed ()) return 0;
- result |= RESIZED;
- }
- }
- return result;
-}
-
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the argument. The <code>x</code> and
- * <code>y</code> fields of the rectangle are relative to
- * the receiver's parent (or its display if its parent is null).
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param rect the new bounds for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setBounds (Rectangle rect) {
- checkWidget ();
- if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (rect.x, rect.y, rect.width, rect.height);
-}
-
-/**
- * If the argument is <code>true</code>, causes the receiver to have
- * all mouse events delivered to it until the method is called with
- * <code>false</code> as the argument. Note that on some platforms,
- * a mouse button must currently be down for capture to be assigned.
- *
- * @param capture <code>true</code> to capture the mouse, and <code>false</code> to release it
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCapture (boolean capture) {
- checkWidget ();
- if (capture) {
- OS.UIElement_CaptureMouse (handle);
- } else {
- OS.UIElement_ReleaseMouseCapture (handle);
- }
-}
-
-/**
- * Sets the receiver's cursor to the cursor specified by the
- * argument, or to the default cursor for that kind of control
- * if the argument is null.
- * <p>
- * When the mouse pointer passes over a control its appearance
- * is changed to match the control's cursor.
- * </p>
- *
- * @param cursor the new cursor (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCursor (Cursor cursor) {
- checkWidget ();
- if (cursor != null && cursor.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.cursor = cursor;
- if (cursor != null) {
- OS.FrameworkElement_Cursor (handle, cursor.handle);
- } else {
- int property = OS.FrameworkElement_CursorProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
-}
-
-/**
- * Sets the receiver's drag detect state. If the argument is
- * <code>true</code>, the receiver will detect drag gestures,
- * otherwise these gestures will be ignored.
- *
- * @param dragDetect the new drag detect state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public void setDragDetect (boolean dragDetect) {
- checkWidget ();
- if (dragDetect) {
- state |= DRAG_DETECT;
- } else {
- state &= ~DRAG_DETECT;
- }
-}
-
-/**
- * WARNING: THIS API IS UNDER CONSTRUCTION AND SHOULD NOT BE USED
- */
-public void setEffect(Effect effect){
- checkWidget ();
- if (effect != null && effect.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (effect != null) {
- OS.UIElement_BitmapEffect (handle, effect.handle);
- OS.UIElement_ClipToBounds (topHandle (), false);
- } else {
- OS.UIElement_BitmapEffect (handle, 0);
- setClipping();
- }
-// updateLayout(handle);
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget ();
- if (((state & DISABLED) == 0) == enabled) return;
- /*
- * Feature in Windows. If the receiver has focus, disabling
- * the receiver causes no window to have focus. The fix is
- * to assign focus to the first ancestor window that takes
- * focus. If no window will take focus, set focus to the
- * desktop.
- */
- Control control = null;
- boolean fixFocus = false;
- if (!enabled) {
-// if (display.focusEvent != SWT.FocusOut) {
- control = display.getFocusControl ();
- fixFocus = isFocusAncestor (control);
-// }
- }
- if (enabled) {
- state &= ~DISABLED;
- } else {
- state |= DISABLED;
- }
- enableWidget (enabled);
- if (fixFocus) fixFocus (control);
-}
-
-/**
- * Causes the receiver to have the <em>keyboard focus</em>,
- * such that all keyboard events will be delivered to it. Focus
- * reassignment will respect applicable platform constraints.
- *
- * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #forceFocus
- */
-public boolean setFocus () {
- checkWidget ();
- if ((style & SWT.NO_FOCUS) != 0) return false;
- return forceFocus ();
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * to the font specified by the argument, or to the default font for that
- * kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setFont (Font font) {
- checkWidget ();
- if (font != null) {
- if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- this.font = font;
- if (font == null) font = defaultFont();
- setFont (font.handle, font.size);
-}
-
-void setFont (int font, double size) {
- if (font != 0) {
- int fontFamily = OS.Typeface_FontFamily( font);
- int style = OS.Typeface_Style (font);
- int weight = OS.Typeface_Weight (font);
- int stretch = OS.Typeface_Stretch (font);
- OS.Control_FontFamily (handle, fontFamily);
- OS.Control_FontStyle (handle, style);
- OS.Control_FontWeight (handle, weight);
- OS.Control_FontStretch (handle, stretch);
- OS.Control_FontSize (handle, size);
- OS.GCHandle_Free (fontFamily);
- OS.GCHandle_Free (style);
- OS.GCHandle_Free (weight);
- OS.GCHandle_Free (stretch);
- } else {
- int property = OS.Control_FontFamilyProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.Control_FontStyleProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.Control_FontWeightProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.Control_FontStretchProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.Control_FontSizeProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
-}
-
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the control
- * if the argument is null.
- * <p>
- * Note: This operation is a hint and may be overridden by the platform.
- * </p>
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setForeground (Color color) {
- checkWidget ();
- int brush = 0;
- if (color != null) {
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (foreground != 0 && OS.Object_Equals (color.handle, foreground)) return;
- foreground = color.handle;
- brush = OS.gcnew_SolidColorBrush (foreground);
- } else {
- if (foreground == 0) return;
- foreground = 0;
- }
- setForegroundBrush (brush);
- if (brush != 0) OS.GCHandle_Free (brush);
-}
-
-void setForegroundBrush (int brush) {
- if (brush != 0) {
- OS.Control_Foreground (handle, brush);
- } else {
- int property = OS.Control_ForegroundProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
-}
-
-/**
- * Sets the layout data associated with the receiver to the argument.
- *
- * @param layoutData the new layout data for the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLayoutData (Object layoutData) {
- checkWidget ();
- this.layoutData = layoutData;
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget ();
- int flags = MOVED;
- setBounds (x, y, 0, 0, flags);
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null), unless
- * the receiver is a shell. In this case, the point is
- * relative to the display.
- *
- * @param location the new location for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (Point location) {
- checkWidget ();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-/**
- * Sets the receiver's pop up menu to the argument.
- * All controls may optionally have a pop up
- * menu that is displayed when the user requests one for
- * the control. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pop up
- * menu is platform specific.
- * <p>
- * Note: Disposing of a control that has a pop up menu will
- * dispose of the menu. To avoid this behavior, set the
- * menu to null before the control is disposed.
- * </p>
- *
- * @param menu the new pop up menu
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenu (Menu menu) {
- checkWidget ();
- if (menu != null) {
- if (menu.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.POP_UP) == 0) {
- error (SWT.ERROR_MENU_NOT_POP_UP);
- }
- if (menu.parent != menuShell ()) {
- error (SWT.ERROR_INVALID_PARENT);
- }
- }
- this.menu = menu;
- OS.FrameworkElement_ContextMenu(handle, menu != null ? menu.handle : 0);
-}
-
-/**
- * If the argument is <code>false</code>, causes subsequent drawing
- * operations in the receiver to be ignored. No drawing of any kind
- * can occur in the receiver until the flag is set to true.
- * Graphics operations that occurred while the flag was
- * <code>false</code> are lost. When the flag is set to <code>true</code>,
- * the entire widget is marked as needing to be redrawn. Nested calls
- * to this method are stacked.
- * <p>
- * Note: This operation is a hint and may not be supported on some
- * platforms or for some widgets.
- * </p>
- *
- * @param redraw the new redraw state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #redraw(int, int, int, int, boolean)
- * @see #update()
- */
-public void setRedraw (boolean redraw) {
- checkWidget ();
- /*
- * Feature in Windows. When WM_SETREDRAW is used to turn
- * off drawing in a widget, it clears the WS_VISIBLE bits
- * and then sets them when redraw is turned back on. This
- * means that WM_SETREDRAW will make a widget unexpectedly
- * visible. The fix is to track the visibility state while
- * drawing is turned off and restore it when drawing is
- * turned back on.
- */
-// if (drawCount == 0) {
-// int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
-// if ((bits & OS.WS_VISIBLE) == 0) state |= HIDDEN;
-// }
-// if (redraw) {
-// if (--drawCount == 0) {
-// OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
-// if ((state & HIDDEN) != 0) {
-// state &= ~HIDDEN;
-// OS.ShowWindow (handle, OS.SW_HIDE);
-// } else {
-// if (OS.IsWinCE) {
-// OS.InvalidateRect (handle, null, true);
-// } else {
-// int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
-// OS.RedrawWindow (handle, null, 0, flags);
-// }
-// }
-// }
-// } else {
-// if (drawCount++ == 0) {
-// OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
-// }
-// }
- redraw ();
-}
-
-/**
- * Sets the shape of the control to the region specified
- * by the argument. When the argument is null, the
- * default shape of the control is restored.
- *
- * @param region the region that defines the shape of the control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setRegion (Region region) {
- checkWidget ();
- if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- OS.UIElement_Clip (topHandle (), region.handle);
- this.region = region;
-}
-
-boolean setSavedFocus () {
- return forceFocus ();
-}
-
-/**
- * Sets the receiver's size to the point specified by the arguments.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (int width, int height) {
- checkWidget ();
- int flags = RESIZED;
- setBounds (0, 0, Math.max (0, width), Math.max (0, height), flags);
-}
-
-/**
- * Sets the receiver's size to the point specified by the argument.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause them to be
- * set to zero instead.
- * </p>
- *
- * @param size the new size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (Point size) {
- checkWidget ();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSize (size.x, size.y);
-}
-
-boolean setTabGroupFocus () {
- return setTabItemFocus ();
-}
-
-boolean setTabItemFocus () {
- if (!isShowing ()) return false;
- return forceFocus ();
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget ();
- toolTipText = string;
- if (string != null && string.length() == 0) string = null;
- int strPtr = createDotNetString (string, false);
- OS.FrameworkElement_ToolTip (handle, strPtr);
- if (strPtr != 0) OS.GCHandle_Free (strPtr);
-}
-
-/**
- * WARNING: THIS API IS UNDER CONSTRUCTION AND SHOULD NOT BE USED
- */
-public void setTransform (Transform t) {
- checkWidget ();
- if (t == null) {
- OS.FrameworkElement_RenderTransform (handle, 0);
- return;
- }
- int matrixTransform = OS.gcnew_MatrixTransform (t.handle);
-// OS.FrameworkElement_LayoutTransform (handle, matrixTransform);
- OS.FrameworkElement_RenderTransform (handle, matrixTransform);
- OS.GCHandle_Free (matrixTransform);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- int topHandle = topHandle ();
- if ((OS.UIElement_Visibility (topHandle) == OS.Visibility_Visible) == visible) return;
- if (visible) {
- sendEvent (SWT.Show);
- if (isDisposed ()) return;
- }
-
- /*
- * Feature in Windows. If the receiver has focus, hiding
- * the receiver causes no window to have focus. The fix is
- * to assign focus to the first ancestor window that takes
- * focus. If no window will take focus, set focus to the
- * desktop.
- */
- Control control = null;
- boolean fixFocus = false;
- if (!visible) {
-// if (display.focusEvent != SWT.FocusOut) {
- control = display.getFocusControl ();
- fixFocus = isFocusAncestor (control);
-// }
- }
- OS.UIElement_Visibility (topHandle, visible ? OS.Visibility_Visible : OS.Visibility_Hidden);
- if (isDisposed ()) return;
- if (!visible) {
- sendEvent (SWT.Hide);
- if (isDisposed ()) return;
- }
- if (fixFocus) fixFocus (control);
-}
-
-void sort (int [] items) {
- /* Shell Sort from K&R, pg 108 */
- int length = items.length;
- for (int gap=length/2; gap>0; gap/=2) {
- for (int i=gap; i<length; i++) {
- for (int j=i-gap; j>=0; j-=gap) {
- if (items [j] <= items [j + gap]) {
- int swap = items [j];
- items [j] = items [j + gap];
- items [j + gap] = swap;
- }
- }
- }
- }
-}
-
-void sortAscending (int [] items) {
- /* Shell Sort from K&R, pg 108 */
- int length = items.length;
- for (int gap=length/2; gap>0; gap/=2) {
- for (int i=gap; i<length; i++) {
- for (int j=i-gap; j>=0; j-=gap) {
- if (items [j] >= items [j + gap]) {
- int swap = items [j];
- items [j] = items [j + gap];
- items [j + gap] = swap;
- }
- }
- }
- }
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in display relative coordinates,
- * to coordinates relative to the receiver.
- * <p>
- * @param x the x coordinate to be translated
- * @param y the y coordinate to be translated
- * @return the translated coordinates
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public Point toControl (int x, int y) {
- checkWidget ();
- return display.map (null, this, x, y);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in display relative coordinates,
- * to coordinates relative to the receiver.
- * <p>
- * @param point the point to be translated (must not be null)
- * @return the translated coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point toControl (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return toControl (point.x, point.y);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in coordinates relative to
- * the receiver, to display relative coordinates.
- * <p>
- * @param x the x coordinate to be translated
- * @param y the y coordinate to be translated
- * @return the translated coordinates
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public Point toDisplay (int x, int y) {
- checkWidget ();
- return display.map (this, null, x, y);
-}
-
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in coordinates relative to
- * the receiver, to display relative coordinates.
- * <p>
- * @param point the point to be translated (must not be null)
- * @return the translated coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point toDisplay (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return toDisplay (point.x, point.y);
-}
-
-boolean translateMnemonic (Event event, Control control) {
- if (control == this) return false;
- if (!isVisible () || !isEnabled ()) return false;
- event.doit = mnemonicMatch (event.character);
- return traverse (event);
-}
-
-boolean translateMnemonic (int e) {
- int key = OS.KeyEventArgs_Key(e);
- if (key < 0x20) return false;
- int keyboardDevice = OS.KeyboardEventArgs_KeyboardDevice(e);
- int modifiers = OS.KeyboardDevice_Modifiers(keyboardDevice);
- OS.GCHandle_Free(keyboardDevice);
- if (modifiers == 0) {
- int code = traversalCode (key, e);
- if ((code & SWT.TRAVERSE_MNEMONIC) == 0) return false;
- } else {
- if ((modifiers & OS.ModifierKeys_Alt) == 0) return false;
- }
- Decorations shell = menuShell ();
- if (shell.isVisible () && shell.isEnabled ()) {
- Event event = new Event ();
- event.detail = SWT.TRAVERSE_MNEMONIC;
- if (setKeyState (event, SWT.Traverse, e)) {
- return translateMnemonic (event, null) || shell.translateMnemonic (event, this);
- }
- }
- return false;
-}
-
-int traversalCode (int key, int event) {
- int code = SWT.TRAVERSE_RETURN | SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_PAGE_NEXT | SWT.TRAVERSE_PAGE_PREVIOUS;
- Shell shell = getShell ();
- if (shell.parent != null) code |= SWT.TRAVERSE_ESCAPE;
- return code;
-}
-
-boolean translateTraversal (int e) {
- int detail = SWT.TRAVERSE_NONE;
- int key = OS.KeyEventArgs_Key(e);
- int code = traversalCode (key, e);
- boolean all = false;
- switch (key) {
- case OS.Key_Escape: {
- all = true;
- detail = SWT.TRAVERSE_ESCAPE;
- break;
- }
- case OS.Key_Return: {
- all = true;
- detail = SWT.TRAVERSE_RETURN;
- break;
- }
- case OS.Key_Tab: {
- int keyboardDevice = OS.KeyboardEventArgs_KeyboardDevice (e);
- int modifiers = OS.KeyboardDevice_Modifiers (keyboardDevice);
- OS.GCHandle_Free (keyboardDevice);
- boolean next = (modifiers & OS.ModifierKeys_Shift) == 0;
- detail = next ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS;
- break;
- }
- case OS.Key_Up:
- case OS.Key_Left:
- case OS.Key_Down:
- case OS.Key_Right: {
- boolean next = key == OS.Key_Down || key == OS.Key_Right;
- detail = next ? SWT.TRAVERSE_ARROW_NEXT : SWT.TRAVERSE_ARROW_PREVIOUS;
- break;
- }
- case OS.Key_PageUp:
- case OS.Key_PageDown: {
- all = true;
- int keyboardDevice = OS.KeyboardEventArgs_KeyboardDevice (e);
- int modifiers = OS.KeyboardDevice_Modifiers (keyboardDevice);
- OS.GCHandle_Free (keyboardDevice);
- if ((modifiers & OS.ModifierKeys_Control) == 0) return false;
- detail = key == OS.Key_PageDown ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS;
- break;
- }
- default:
- return false;
- }
- Event event = new Event ();
- event.doit = (code & detail) != 0;
- event.detail = detail;
- event.time = OS.InputEventArgs_Timestamp (e);
- if (!setKeyState (event, SWT.Traverse, e)) return false;
- Shell shell = getShell ();
- Control control = this;
- do {
- if (control.traverse (event)) return true;
- if (!event.doit && control.hooks (SWT.Traverse)) return false;
- if (control == shell) return false;
- control = control.parent;
- } while (all && control != null);
- return false;
-}
-
-boolean traverse (Event event) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the traverse
- * event. If this happens, return true to stop further
- * event processing.
- */
- sendEvent (SWT.Traverse, event);
- if (isDisposed ()) return true;
- if (!event.doit) return false;
- switch (event.detail) {
- case SWT.TRAVERSE_NONE: return true;
- case SWT.TRAVERSE_ESCAPE: return traverseEscape ();
- case SWT.TRAVERSE_RETURN: return traverseReturn ();
- case SWT.TRAVERSE_TAB_NEXT: return traverseGroup (true);
- case SWT.TRAVERSE_TAB_PREVIOUS: return traverseGroup (false);
- case SWT.TRAVERSE_ARROW_NEXT: return traverseItem (true);
- case SWT.TRAVERSE_ARROW_PREVIOUS: return traverseItem (false);
- case SWT.TRAVERSE_MNEMONIC: return traverseMnemonic (event.character);
- case SWT.TRAVERSE_PAGE_NEXT: return traversePage (true);
- case SWT.TRAVERSE_PAGE_PREVIOUS: return traversePage (false);
- }
- return false;
-}
-
-/**
- * Based on the argument, perform one of the expected platform
- * traversal action. The argument should be one of the constants:
- * <code>SWT.TRAVERSE_ESCAPE</code>, <code>SWT.TRAVERSE_RETURN</code>,
- * <code>SWT.TRAVERSE_TAB_NEXT</code>, <code>SWT.TRAVERSE_TAB_PREVIOUS</code>,
- * <code>SWT.TRAVERSE_ARROW_NEXT</code> and <code>SWT.TRAVERSE_ARROW_PREVIOUS</code>.
- *
- * @param traversal the type of traversal
- * @return true if the traversal succeeded
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean traverse (int traversal) {
- checkWidget ();
- Event event = new Event ();
- event.doit = true;
- event.detail = traversal;
- return traverse (event);
-}
-
-boolean traverseEscape () {
- return false;
-}
-
-boolean traverseGroup (boolean next) {
- Control root = computeTabRoot ();
- Control group = computeTabGroup ();
- Control [] list = root.computeTabList ();
- int length = list.length;
- int index = 0;
- while (index < length) {
- if (list [index] == group) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- if (index == length) return false;
- int start = index, offset = (next) ? 1 : -1;
- while ((index = ((index + offset + length) % length)) != start) {
- Control control = list [index];
- if (!control.isDisposed () && control.setTabGroupFocus ()) {
- return true;
- }
- }
- if (group.isDisposed ()) return false;
- return group.setTabGroupFocus ();
-}
-
-boolean traverseItem (boolean next) {
- Control [] children = parent._getChildren ();
- int length = children.length;
- int index = 0;
- while (index < length) {
- if (children [index] == this) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- if (index == length) return false;
- int start = index, offset = (next) ? 1 : -1;
- while ((index = (index + offset + length) % length) != start) {
- Control child = children [index];
- if (!child.isDisposed () && child.isTabItem ()) {
- if (child.setTabItemFocus ()) return true;
- }
- }
- return false;
-}
-
-boolean traverseMnemonic (char key) {
- return mnemonicHit (key);
-}
-
-boolean traversePage (boolean next) {
- return false;
-}
-
-boolean traverseReturn () {
- return false;
-}
-
-/**
- * Forces all outstanding paint requests for the widget
- * to be processed before this method returns. If there
- * are no outstanding paint request, this method does
- * nothing.
- * <p>
- * Note: This method does not cause a redraw.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #redraw()
- * @see #redraw(int, int, int, int, boolean)
- * @see PaintListener
- * @see SWT#Paint
- */
-public void update () {
- checkWidget ();
- update (false);
-}
-
-void update (boolean all) {
- checkWidget ();
- //TODO
-// if (OS.IsWinCE) {
-// OS.UpdateWindow (handle);
-// } else {
-// int flags = OS.RDW_UPDATENOW;
-// if (all) flags |= OS.RDW_ALLCHILDREN;
-// OS.RedrawWindow (handle, null, 0, flags);
-// }
-}
-
-void updateBackgroundColor () {
-// Control control = findBackgroundControl ();
-// if (control == null) control = this;
-// setBackgroundPixel (control.background);
-}
-
-void updateBackgroundImage () {
-// Control control = findBackgroundControl ();
-// Image image = control != null ? control.backgroundImage : backgroundImage;
-// setBackgroundImage (image != null ? image.handle : 0);
-}
-
-void updateBackgroundMode () {
- int oldState = state & PARENT_BACKGROUND;
- checkBackground ();
- if (oldState != (state & PARENT_BACKGROUND)) {
- setBackground ();
- }
-}
-
-void updateFont (Font oldFont, Font newFont) {
- if (getFont ().equals (oldFont)) setFont (newFont);
-}
-
-void updateImages () {
- /* Do nothing */
-}
-
-void updateLayout (boolean resize, boolean all) {
- /* Do nothing */
-}
-
-int widgetParent () {
- return parent.handle;
-}
-
-/**
- * Changes the parent of the widget to be the one provided if
- * the underlying operating system supports this feature.
- * Returns <code>true</code> if the parent is successfully changed.
- *
- * @param parent the new parent for the control.
- * @return <code>true</code> if the parent is changed and <code>false</code> otherwise.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * <li>ERROR_NULL_ARGUMENT - if the parent is <code>null</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean setParent (Composite parent) {
- checkWidget ();
- if (parent == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (parent.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (this.parent == parent) return true;
- if (!isReparentable ()) return false;
- return false;
-}
-
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/CoolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/CoolBar.java
deleted file mode 100644
index 2b35cecfe6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/CoolBar.java
+++ /dev/null
@@ -1,709 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide an area for dynamically
- * positioning the items they contain.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>CoolItem</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add <code>Control</code> children to it,
- * or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>FLAT, HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#coolbar">CoolBar snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class CoolBar extends Composite {
- Control [] children;
- CoolItem [] items;
- int parentingHandle;
- int itemCount, childCount;
-
- //TEMPORARY CODE
- static boolean IsVertical;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see SWT#FLAT
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public CoolBar (Composite parent, int style) {
- super (parent, checkStyle (style));
- if ((style & SWT.VERTICAL) != 0) {
- this.style |= SWT.VERTICAL;
- } else {
- this.style |= SWT.HORIZONTAL;
- }
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- IsVertical = (style & SWT.V_SCROLL) != 0;
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void addChild (Control widget) {
- super.addChild (widget);
- if (childCount == children.length) {
- Control [] newChildren = new Control [childCount + 4];
- System.arraycopy (children, 0, newChildren, 0, childCount);
- children = newChildren;
- }
- children [childCount++] = widget;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- return computeSize (handle, wHint, hHint, changed);
-}
-
-void createHandle () {
- parentingHandle = OS.gcnew_Canvas ();
- if (parentingHandle == 0) error (SWT.ERROR_NO_HANDLES);
- handle = OS.gcnew_ToolBarTray ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- int children = OS.Panel_Children (parentingHandle);
- OS.UIElementCollection_Add (children, handle);
- OS.GCHandle_Free (children);
- if (IsVertical) OS.ToolBarTray_Orientation (handle, OS.Orientation_Vertical);
-}
-
-void createItem (CoolItem item, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- item.createWidget ();
- int toolbars = OS.ToolBarTray_ToolBars (handle);
- int itemHandle = item.topHandle ();
- OS.IList_Insert (toolbars, index, item.topHandle ());
- int count = OS.ICollection_Count (toolbars);
- if (itemCount == count) error (SWT.ERROR_ITEM_NOT_ADDED);
- int band = 0;
- int bandIndex = 0;
- if (index != itemCount) {
- band = OS.ToolBar_Band (items [index].topHandle ());
- bandIndex = OS.ToolBar_BandIndex (items [index].topHandle ());
- for (int i=0; i<count; i++) {
- int current = OS.IList_default (toolbars, i);
- int currentBand = OS.ToolBar_Band (current);
- int currentIndex = OS.ToolBar_BandIndex (current);
- if (currentBand == band && currentIndex >= bandIndex) {
- OS.ToolBar_BandIndex (current, currentIndex + 1);
- }
- OS.GCHandle_Free (current);
- }
- } else {
- if (itemCount > 0) {
- int [] log2vis = logicalToVisualIndices ();
- int lastItem = items [log2vis [itemCount - 1]].topHandle ();
- band = OS.ToolBar_Band (lastItem);
- bandIndex = OS.ToolBar_BandIndex (lastItem) + 1;
- }
- }
- OS.ToolBar_Band (itemHandle, band);
- OS.ToolBar_BandIndex (itemHandle, bandIndex);
- OS.GCHandle_Free (toolbars);
- if (itemCount == items.length) {
- CoolItem [] newItems = new CoolItem [items.length + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- System.arraycopy (items, index, items, index + 1, itemCount - index);
- items [index] = item;
- itemCount++;
-}
-
-void createWidget () {
- super.createWidget ();
- items = new CoolItem [4];
- children = new Control [4];
-}
-
-int defaultBackground () {
- return OS.Colors_Transparent;
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (parentingHandle);
-}
-
-void destroyItem (CoolItem item) {
- int toolbars = OS.ToolBarTray_ToolBars (handle);
- int itemHandle = item.topHandle ();
- int band = OS.ToolBar_Band (itemHandle);
- int bandIndex = OS.ToolBar_BandIndex (itemHandle);
- OS.IList_Remove (toolbars, itemHandle);
- int count = OS.ICollection_Count (toolbars);
- if (itemCount == count) error (SWT.ERROR_ITEM_NOT_REMOVED);
- itemCount--;
- for (int i=0; i<itemCount; i++) {
- int current = OS.IList_default (toolbars, i);
- int currentBand = OS.ToolBar_Band (current);
- int currentIndex = OS.ToolBar_BandIndex (current);
- if (currentBand == band && currentIndex >= bandIndex) {
- OS.ToolBar_BandIndex (current, currentIndex - 1);
- }
- OS.GCHandle_Free (current);
- }
- OS.GCHandle_Free (toolbars);
- int index = 0;
- while (index < items.length) {
- if (items [index] == item) break;
- index++;
- }
- System.arraycopy (items, index + 1, items, index, itemCount - index);
- items [itemCount] = null;
-}
-
-Control [] _getChildren () {
- // return children in reverse order.
- Control[] result = new Control [childCount];
- for (int i =0; i < childCount; i++) {
- result [childCount - i - 1] = children [i];
- }
- return result;
-}
-
-int [] logicalToVisualIndices () {
- int [] bandLengths = new int [4];
- for (int i = 0; i < itemCount; i++) {
- int topHandle = items [i].topHandle ();
- int band = OS.ToolBar_Band (topHandle);
- int bandIndex = OS.ToolBar_BandIndex (topHandle);
- if (band >= bandLengths.length) {
- int [] newLengths = new int [band + 4];
- System.arraycopy (bandLengths, 0, newLengths, 0, bandLengths.length);
- bandLengths = newLengths;
- }
- if (bandIndex + 1 > bandLengths [band]) bandLengths [band] = bandIndex + 1;
- }
- int [] result = new int [itemCount];
- for (int i = 0; i < itemCount; i++) {
- int topHandle = items [i].topHandle ();
- int band = OS.ToolBar_Band (topHandle);
- int bandIndex = OS.ToolBar_BandIndex (topHandle);
- int index = bandIndex;
- for (int j=0; j<band; j++) index += bandLengths [j];
- result [index] = i;
- }
- return result;
-}
-
-/**
- * Returns the item that is currently displayed at the given,
- * zero-relative index. Throws an exception if the index is
- * out of range.
- *
- * @param index the visual index of the item to return
- * @return the item at the given visual index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public CoolItem getItem (int index) {
- checkWidget ();
- if (index < 0 || index >= itemCount) error (SWT.ERROR_INVALID_RANGE);
- int [] log2vis = logicalToVisualIndices ();
- return items [log2vis [index]];
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return itemCount;
-}
-
-/**
- * Returns an array of zero-relative ints that map
- * the creation order of the receiver's items to the
- * order in which they are currently being displayed.
- * <p>
- * Specifically, the indices of the returned array represent
- * the current visual order of the items, and the contents
- * of the array represent the creation order of the items.
- * </p><p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the current visual order of the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int [] getItemOrder () {
- checkWidget ();
- return logicalToVisualIndices ();
-}
-
-/**
- * Returns an array of <code>CoolItem</code>s in the order
- * in which they are currently being displayed.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the receiver's items in their current visual order
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public CoolItem [] getItems () {
- checkWidget ();
- CoolItem [] result = new CoolItem [itemCount];
- int [] log2vis = logicalToVisualIndices ();
- for (int i = 0; i < itemCount; i++) {
- result [i] = items [log2vis [i]];
- }
- return result;
-}
-
-/**
- * Returns an array of points whose x and y coordinates describe
- * the widths and heights (respectively) of the items in the receiver
- * in the order in which they are currently being displayed.
- *
- * @return the receiver's item sizes in their current visual order
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point [] getItemSizes () {
- checkWidget ();
- int [] log2vis = logicalToVisualIndices ();
- Point [] result = new Point [itemCount];
- for (int i = 0; i < itemCount; i++) {
- result [i] = items [log2vis [i]].getSize ();
- }
- return result;
-}
-
-Point getLocation (Control child) {
- int topHandle = child.topHandle ();
- int point = OS.gcnew_Point (0, 0);
- if (point == 0) error (SWT.ERROR_NO_HANDLES);
- int location = OS.UIElement_TranslatePoint (topHandle, point, handle);
- int x = (int) OS.Point_X (location);
- int y = (int) OS.Point_Y (location);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (location);
- return new Point (x, y);
-}
-
-/**
- * Returns whether or not the receiver is 'locked'. When a coolbar
- * is locked, its items cannot be repositioned.
- *
- * @return true if the coolbar is locked, false otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public boolean getLocked () {
- checkWidget ();
- return OS.ToolBarTray_IsLocked (handle);
-}
-
-/**
- * Returns an array of ints that describe the zero-relative
- * indices of any item(s) in the receiver that will begin on
- * a new row. The 0th visible item always begins the first row,
- * therefore it does not count as a wrap index.
- *
- * @return an array containing the receiver's wrap indices, or an empty array if all items are in one row
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int [] getWrapIndices () {
- checkWidget ();
- int bands = 1;
- int [] bandLengths = new int [4];
- for (int i = 0; i < itemCount; i++) {
- int topHandle = items [i].topHandle ();
- int band = OS.ToolBar_Band (topHandle);
- int bandIndex = OS.ToolBar_BandIndex (topHandle);
- if (band >= bandLengths.length) {
- int [] newLengths = new int [band + 4];
- System.arraycopy (bandLengths, 0, newLengths, 0, bandLengths.length);
- bandLengths = newLengths;
- }
- if (band != 0 && bandLengths [band] == 0) bands ++;
- if (bandIndex + 1 > bandLengths [band]) bandLengths [band] = bandIndex + 1;
- }
- if (bands == 1) return new int [0];
- int [] result = new int [bands-1];
- int sum = 0;
- for (int i = 0; i < result.length; i++) {
- sum += bandLengths [i];
- result [i] = sum;
- }
- return result;
-}
-
-void HandleSizeChanged (int sender, int e) {
- postEvent (SWT.Resize);
-}
-
-void hookEvents () {
- super.hookEvents ();
- int handler = OS.gcnew_SizeChangedEventHandler (jniRef, "HandleSizeChanged");
- OS.FrameworkElement_SizeChanged (handle, handler);
- OS.GCHandle_Free (handler);
-}
-
-/**
- * Searches the receiver's items in the order they are currently
- * being displayed, starting at the first item (index 0), until
- * an item is found that is equal to the argument, and returns
- * the index of that item. If no item is found, returns -1.
- *
- * @param item the search item
- * @return the visual order index of the search item, or -1 if the item is not found
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (CoolItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i = 0; i < itemCount; i++) {
- if (item.equals (items [i])) {
- int [] log2vis = logicalToVisualIndices ();
- return log2vis [i];
- }
- }
- return -1;
-}
-
-int parentingHandle () {
- return parentingHandle;
-}
-
-void register () {
- super.register ();
- display.addWidget (parentingHandle, this);
-}
-
-void releaseChildren (boolean destroy) {
- for (int i=0; i<itemCount; i++) {
- CoolItem item = items [i];
- if (item != null && !item.isDisposed ()) item.release (false);
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (parentingHandle != 0) OS.GCHandle_Free (parentingHandle);
- parentingHandle = 0;
-}
-
-void removeChild (Control control) {
- super.removeChild (control);
- int index = 0;
- while (index < childCount) {
- if (children [index] == control) break;
- index++;
- }
- if (index == childCount) return;
- System.arraycopy (children, index+1, children, index, --childCount - index);
- children [childCount] = null;
-}
-
-void removeControl (Control control) {
- super.removeControl (control);
- for (int i=0; i<itemCount; i++) {
- CoolItem item = items [i];
- if (item.control == control) {
- item.setControl (null);
- break;
- }
- }
-}
-
-int setBounds (int x, int y, int width, int height, int flags) {
- int result = super.setBounds (x, y, width, height, flags);
- if ((result & RESIZED) != 0) {
- if ((style & SWT.VERTICAL) != 0) {
- OS.FrameworkElement_Height (handle, height);
- } else {
- OS.FrameworkElement_Width (handle, width);
- }
- }
- return result;
-}
-
-/**
- * Sets the receiver's item order, wrap indices, and item sizes
- * all at once. This method is typically used to restore the
- * displayed state of the receiver to a previously stored state.
- * <p>
- * The item order is the order in which the items in the receiver
- * should be displayed, given in terms of the zero-relative ordering
- * of when the items were added.
- * </p><p>
- * The wrap indices are the indices of all item(s) in the receiver
- * that will begin on a new row. The indices are given in the order
- * specified by the item order. The 0th item always begins the first
- * row, therefore it does not count as a wrap index. If wrap indices
- * is null or empty, the items will be placed on one line.
- * </p><p>
- * The sizes are specified in an array of points whose x and y
- * coordinates describe the new widths and heights (respectively)
- * of the receiver's items in the order specified by the item order.
- * </p>
- *
- * @param itemOrder an array of indices that describe the new order to display the items in
- * @param wrapIndices an array of wrap indices, or null
- * @param sizes an array containing the new sizes for each of the receiver's items in visual order
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if item order or sizes is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if item order or sizes is not the same length as the number of items</li>
- * </ul>
- */
-public void setItemLayout (int [] itemOrder, int [] wrapIndices, Point [] sizes) {
- checkWidget ();
- setItemOrder (itemOrder);
- setWrapIndices (wrapIndices);
- setItemSizes (sizes);
-}
-
-/*
- * Sets the order that the items in the receiver should
- * be displayed in to the given argument which is described
- * in terms of the zero-relative ordering of when the items
- * were added.
- *
- * @param itemOrder the new order to display the items in
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item order is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li>
- * </ul>
- */
-void setItemOrder (int [] itemOrder) {
- checkWidget ();
- if (itemOrder == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (itemOrder.length != itemCount) error (SWT.ERROR_INVALID_ARGUMENT);
- /* Ensure that itemOrder does not contain any duplicates. */
- boolean [] set = new boolean [itemCount];
- for (int i=0; i<itemOrder.length; i++) {
- int index = itemOrder [i];
- if (index < 0 || index >= itemCount) error (SWT.ERROR_INVALID_RANGE);
- if (set [index]) error (SWT.ERROR_INVALID_ARGUMENT);
- set [index] = true;
- }
- for (int i=0; i<itemCount; i++) {
- CoolItem item = items [itemOrder [i]];
- int itemHandle = item.topHandle ();
- OS.ToolBar_Band (itemHandle, 0);
- OS.ToolBar_BandIndex (itemHandle, i);
- }
-}
-
-/*
- * Sets the width and height of the receiver's items to the ones
- * specified by the argument, which is an array of points whose x
- * and y coordinates describe the widths and heights (respectively)
- * in the order in which the items are currently being displayed.
- *
- * @param sizes an array containing the new sizes for each of the receiver's items in visual order
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of sizes is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the array of sizes is not the same length as the number of items</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-void setItemSizes (Point [] sizes) {
- if (sizes == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (sizes.length != itemCount) error (SWT.ERROR_INVALID_ARGUMENT);
- int [] log2vis = logicalToVisualIndices ();
- for (int i=0; i<itemCount; i++) {
- items [log2vis [i]].setSize (sizes [i].x, sizes [i].y);
- }
-}
-
-/**
- * Sets whether or not the receiver is 'locked'. When a coolbar
- * is locked, its items cannot be repositioned.
- *
- * @param locked lock the coolbar if true, otherwise unlock the coolbar
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setLocked (boolean locked) {
- checkWidget ();
- OS.ToolBarTray_IsLocked (handle, locked);
-}
-
-/**
- * Sets the indices of all item(s) in the receiver that will
- * begin on a new row. The indices are given in the order in
- * which they are currently being displayed. The 0th item
- * always begins the first row, therefore it does not count
- * as a wrap index. If indices is null or empty, the items
- * will be placed on one line.
- *
- * @param indices an array of wrap indices, or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWrapIndices (int [] indices) {
- checkWidget ();
- if (indices == null) indices = new int [0];
- int count = getItemCount ();
- for (int i=0; i<indices.length; i++) {
- if (indices [i] < 0 || indices [i] >= count) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- }
- sortAscending (indices);
- int [] log2vis = logicalToVisualIndices ();
- int band = 0;
- int bandIndex = 0;
- int wrapIndex = 0;
- for (int i = 0; i < itemCount; i++) {
- int wrap = indices.length > wrapIndex ? indices [wrapIndex] : itemCount;
- if (i == wrap) {
- if (wrap != 0) {
- band ++;
- bandIndex = 0;
- }
- wrapIndex ++;
- }
- int topHandle = items [log2vis [i]].topHandle ();
- OS.ToolBar_Band (topHandle, band);
- OS.ToolBar_BandIndex (topHandle, bandIndex);
- bandIndex ++;
- }
-}
-
-int topHandle () {
- return parentingHandle;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/CoolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/CoolItem.java
deleted file mode 100644
index 87ac42f7ef..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/CoolItem.java
+++ /dev/null
@@ -1,665 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that represent the dynamically positionable
- * areas of a <code>CoolBar</code>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>DROP_DOWN</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class CoolItem extends Item {
- CoolBar parent;
- Control control;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>CoolBar</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public CoolItem (CoolBar parent, int style) {
- this (parent, style, parent.itemCount);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>CoolBar</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index at which to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public CoolItem (CoolBar parent, int style, int index) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, index);
- updateLayout (handle);
- setButtonVisibility (OS.Visibility_Collapsed);
-}
-
-/**
- * Adds the listener to the collection of listeners that will
- * be notified when the control is selected by the user, by sending it one
- * of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * If <code>widgetSelected</code> is called when the mouse is over
- * the drop-down arrow (or 'chevron') portion of the cool item,
- * the event object detail field contains the value <code>SWT.ARROW</code>,
- * and the x and y fields in the event object represent the point at
- * the bottom left of the chevron, where the menu should be popped up.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- *
- * @since 2.0
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createHandle () {
- handle = OS.gcnew_ToolBar ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-
-void createWidget () {
- super.createWidget ();
- int background = OS.Brushes_Transparent ();
- OS.Control_Background (handle, background);
- OS.GCHandle_Free (background);
-}
-
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>preferred size</em> of a <code>CoolItem</code> is the size that
- * it would best be displayed at. The width hint and height hint arguments
- * allow the caller to ask the instance questions such as "Given a particular
- * width, how high does it need to be to show all of the contents?"
- * To indicate that the caller does not wish to constrain a particular
- * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.
- * </p>
- *
- * @param wHint the width hint (can be <code>SWT.DEFAULT</code>)
- * @param hHint the height hint (can be <code>SWT.DEFAULT</code>)
- * @return the preferred size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Layout
- * @see #getBounds
- * @see #getSize
- * @see Control#getBorderWidth
- * @see Scrollable#computeTrim
- * @see Scrollable#getClientArea
- */
-public Point computeSize (int wHint, int hHint) {
- checkWidget ();
- if (isToolBar (control)) {
- return control.computeSize (SWT.DEFAULT, SWT.DEFAULT);
- }
- int template = OS.Control_Template (handle);
- int partName = createDotNetString ("PART_ToolBarPanel", false);
- int part = OS.FrameworkTemplate_FindName (template, partName, handle);
- int width = wHint, height = hHint;
- width = Math.max (0, width);
- height = Math.max (0, height);
- int margin = OS.FrameworkElement_Margin (part);
- width += OS.Thickness_Left (margin) + OS.Thickness_Right (margin);
- height += OS.Thickness_Top (margin) + OS.Thickness_Bottom (margin);
- OS.GCHandle_Free (partName);
- OS.GCHandle_Free (part);
- OS.GCHandle_Free (margin);
-
- partName = createDotNetString ("ToolBarThumb", false);
- part = OS.FrameworkTemplate_FindName (template, partName, handle);
- width += OS.FrameworkElement_Width (part);
- OS.GCHandle_Free (partName);
- OS.GCHandle_Free (part);
- OS.GCHandle_Free (template);
- return new Point (width, height);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget ();
- int parentHandle = parent.handle;
- int topHandle = topHandle ();
- int point = OS.gcnew_Point (0, 0);
- if (point == 0) error (SWT.ERROR_NO_HANDLES);
- int location = OS.UIElement_TranslatePoint (topHandle, point, parentHandle);
- int x = (int) OS.Point_X (location);
- int y = (int) OS.Point_Y (location);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (location);
- int width = (int) OS.FrameworkElement_ActualWidth (topHandle);
- int height = (int) OS.FrameworkElement_ActualHeight (topHandle);
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the control that is associated with the receiver.
- *
- * @return the control that is contained by the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget ();
- return control;
-}
-
-/**
- * Returns the minimum size that the cool item can
- * be resized to using the cool item's gripper.
- *
- * @return a point containing the minimum width and height of the cool item, in pixels
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public Point getMinimumSize () {
- checkWidget ();
- int width = (int) OS.FrameworkElement_MinWidth (handle);
- int height = (int) OS.FrameworkElement_MinHeight (handle);
- return new Point (width, height);
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>CoolBar</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public CoolBar getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns a point describing the receiver's ideal size.
- * The x coordinate of the result is the ideal width of the receiver.
- * The y coordinate of the result is the ideal height of the receiver.
- *
- * @return the receiver's ideal size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getPreferredSize () {
- checkWidget ();
- return getSize ();
-}
-
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize() {
- checkWidget ();
- int width = (int) OS.FrameworkElement_Width (handle);
- int height = (int) OS.FrameworkElement_Height (handle);
- return new Point (width, height);
-}
-
-void HandleSizeChanged (int sender, int e) {
- if (isToolBar (control)) {
- ToolBar toolbar = (ToolBar) control;
- boolean overflow = OS.ToolBar_HasOverflowItems (toolbar.handle);
- toolbar.setButtonVisibility (overflow ? OS.Visibility_Visible : OS.Visibility_Collapsed);
- } else {
- boolean overflow = OS.ToolBar_HasOverflowItems (handle);
- setButtonVisibility (overflow ? OS.Visibility_Visible : OS.Visibility_Collapsed);
- if (control != null) {
- int template = OS.Control_Template (handle);
- int partName = createDotNetString ("PART_ToolBarPanel", false);
- int part = OS.FrameworkTemplate_FindName (template, partName, handle);
- int width = (int) OS.FrameworkElement_ActualWidth (part);
- int height = (int) OS.FrameworkElement_ActualHeight (part);
- control.setSize (width, height);
- OS.GCHandle_Free (part);
- OS.GCHandle_Free (partName);
- OS.GCHandle_Free (template);
- }
- }
-}
-
-void hookEvents () {
- super.hookEvents ();
- int handler = OS.gcnew_SizeChangedEventHandler (jniRef, "HandleSizeChanged");
- OS.FrameworkElement_SizeChanged (handle, handler);
- OS.GCHandle_Free (handler);
-}
-
-boolean isToolBar (Control control) {
- if (control == null || control.isDisposed ()) return false;
- int type = OS.ToolBar_typeid ();
- boolean result = OS.Type_IsInstanceOfType (type, control.handle);
- OS.GCHandle_Free (type);
- return result;
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (handle != 0) OS.GCHandle_Free (handle);
- handle = 0;
- parent = null;
-}
-
-/**
- * Removes the listener from the collection of listeners that
- * will be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- *
- * @since 2.0
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-void setButtonVisibility (byte visibility) {
- int template = OS.Control_Template (handle);
- int overFlowName = createDotNetString ("OverflowGrid", false);
- int overFlowGrid = OS.FrameworkTemplate_FindName (template, overFlowName, handle);
- if (overFlowGrid != 0) {
- OS.UIElement_Visibility (overFlowGrid, visibility);
- OS.GCHandle_Free (overFlowGrid);
- }
- OS.GCHandle_Free (overFlowName);
- int borderName = createDotNetString ("MainPanelBorder", false);
- int border = OS.FrameworkTemplate_FindName (template, borderName, handle);
- if (border != 0) {
- int right = visibility == OS.Visibility_Collapsed ? 0 : 11;
- int margin = OS.gcnew_Thickness (0, 0, right, 0);
- OS.FrameworkElement_Margin (border, margin);
- OS.GCHandle_Free (border);
- OS.GCHandle_Free (margin);
- }
- OS.GCHandle_Free (borderName);
- OS.GCHandle_Free (template);
-}
-
-/**
- * Sets the control that is associated with the receiver
- * to the argument.
- *
- * @param control the new control that will be contained by the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget ();
- if (control != null) {
- if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- if (this.control != null && this.control.isDisposed ()) {
- this.control = null;
- }
- int topHandle = topHandle ();
- int toolbars = OS.ToolBarTray_ToolBars (parent.handle);
- int index = OS.IList_IndexOf (toolbars, topHandle);
- int band = OS.ToolBar_Band (topHandle);
- int bandIndex = OS.ToolBar_BandIndex (topHandle);
- Control oldControl = this.control, newControl = control;
- this.control = control;
- if (oldControl != null) {
- if (isToolBar (oldControl)) {
- ToolBar toolbar = (ToolBar) oldControl;
- toolbar.setThumbVisibility (OS.Visibility_Collapsed);
- toolbar.setButtonVisibility (OS.Visibility_Collapsed);
- OS.IList_Remove (toolbars, toolbar.handle);
- int children = OS.ToolBarTray_ToolBars (toolbar.trayHandle);
- OS.IList_Add (children, toolbar.handle);
- OS.GCHandle_Free (children);
- OS.IList_Insert (toolbars, index, handle);
- OS.ToolBar_Band (handle, band);
- OS.ToolBar_BandIndex (handle, bandIndex);
- } else {
- int controlHandle = oldControl.topHandle ();
- int items = OS.ItemsControl_Items (handle);
- OS.ItemCollection_Remove (items, controlHandle);
- OS.GCHandle_Free (items);
- int children = OS.Panel_Children (parent.parentingHandle);
- OS.UIElementCollection_Add (children, controlHandle);
- OS.GCHandle_Free (children);
- }
- }
- if (newControl != null) {
- if (isToolBar (newControl)) {
- ToolBar toolbar = (ToolBar) newControl;
- int controlHandle = toolbar.handle;
- int children = OS.ToolBarTray_ToolBars (toolbar.trayHandle);
- OS.IList_Remove (children, controlHandle);
- OS.GCHandle_Free (children);
- OS.IList_Remove (toolbars, handle);
- OS.IList_Insert (toolbars, index, controlHandle);
-
- boolean locked = OS.ToolBarTray_IsLocked (parent.handle);
- boolean overflow = OS.ToolBar_HasOverflowItems (controlHandle);
- toolbar.setThumbVisibility (locked ? OS.Visibility_Collapsed : OS.Visibility_Visible);
- toolbar.setButtonVisibility (overflow ? OS.Visibility_Visible : OS.Visibility_Collapsed);
- OS.ToolBar_Band (controlHandle, band);
- OS.ToolBar_BandIndex (controlHandle, bandIndex);
- double width = OS.FrameworkElement_Width (handle);
- if (width > 0) OS.FrameworkElement_Width (controlHandle, width);
- double height = OS.FrameworkElement_Height (handle);
- if (height > 0) OS.FrameworkElement_Height (controlHandle, height);
- double minWidth = OS.FrameworkElement_MinWidth (handle);
- if (minWidth > 0) OS.FrameworkElement_MinWidth (controlHandle, minWidth);
- double minHeight = OS.FrameworkElement_MinHeight (handle);
- if (minHeight > 0) OS.FrameworkElement_MinHeight (controlHandle, minHeight);
- updateLayout (controlHandle);
- } else {
- int controlHandle = newControl.topHandle ();
- int children = OS.Panel_Children (parent.parentingHandle ());
- OS.UIElementCollection_Remove (children, controlHandle);
- OS.GCHandle_Free (children);
- int items = OS.ItemsControl_Items (handle);
- OS.ItemCollection_Add (items, controlHandle);
- OS.GCHandle_Free (items);
- }
- }
- OS.GCHandle_Free (toolbars);
-}
-
-/**
- * Sets the minimum size that the cool item can be resized to
- * using the cool item's gripper, to the point specified by the arguments.
- *
- * @param width the minimum width of the cool item, in pixels
- * @param height the minimum height of the cool item, in pixels
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setMinimumSize (int width, int height) {
- checkWidget ();
- width = Math.max (0, width);
- height = Math.max (0, height);
- OS.FrameworkElement_MinWidth (handle, width);
- OS.FrameworkElement_MinHeight (handle, height);
- if (isToolBar (control)) {
- OS.FrameworkElement_MinWidth (control.handle, width);
- OS.FrameworkElement_MinHeight (control.handle, height);
- }
-}
-
-/**
- * Sets the minimum size that the cool item can be resized to
- * using the cool item's gripper, to the point specified by the argument.
- *
- * @param size a point representing the minimum width and height of the cool item, in pixels
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setMinimumSize (Point size) {
- checkWidget ();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setMinimumSize (size.x, size.y);
-}
-
-/**
- * Sets the receiver's ideal size to the point specified by the arguments.
- *
- * @param width the new ideal width for the receiver
- * @param height the new ideal height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPreferredSize (int width, int height) {
- checkWidget ();
- setSize (width, height);
-}
-
-/**
- * Sets the receiver's ideal size to the point specified by the argument.
- *
- * @param size the new ideal size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPreferredSize (Point size) {
- checkWidget ();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setPreferredSize (size.x, size.y);
-}
-
-/**
- * Sets the receiver's size to the point specified by the arguments.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (int width, int height) {
- checkWidget ();
- width = Math.max (0, width);
- height = Math.max (0, height);
- OS.FrameworkElement_Width (handle, width);
- OS.FrameworkElement_Height (handle, height);
- if (isToolBar (control)) {
- OS.FrameworkElement_Width (control.handle, width);
- OS.FrameworkElement_Height (control.handle, height);
- }
-}
-
-/**
- * Sets the receiver's size to the point specified by the argument.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause them to be
- * set to zero instead.
- * </p>
- *
- * @param size the new size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSize (Point size) {
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSize (size.x, size.y);
-}
-
-int topHandle () {
- if (isToolBar (control)) return control.handle;
- return handle;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Decorations.java
deleted file mode 100644
index 95b68840ee..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Decorations.java
+++ /dev/null
@@ -1,895 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide the appearance and
- * behavior of <code>Shells</code>, but are not top
- * level shells or dialogs. Class <code>Shell</code>
- * shares a significant amount of code with this class,
- * and is a subclass.
- * <p>
- * IMPORTANT: This class was intended to be abstract and
- * should <em>never</em> be referenced or instantiated.
- * Instead, the class <code>Shell</code> should be used.
- * </p>
- * <p>
- * Instances are always displayed in one of the maximized,
- * minimized or normal states:
- * <ul>
- * <li>
- * When an instance is marked as <em>maximized</em>, the
- * window manager will typically resize it to fill the
- * entire visible area of the display, and the instance
- * is usually put in a state where it can not be resized
- * (even if it has style <code>RESIZE</code>) until it is
- * no longer maximized.
- * </li><li>
- * When an instance is in the <em>normal</em> state (neither
- * maximized or minimized), its appearance is controlled by
- * the style constants which were specified when it was created
- * and the restrictions of the window manager (see below).
- * </li><li>
- * When an instance has been marked as <em>minimized</em>,
- * its contents (client area) will usually not be visible,
- * and depending on the window manager, it may be
- * "iconified" (that is, replaced on the desktop by a small
- * simplified representation of itself), relocated to a
- * distinguished area of the screen, or hidden. Combinations
- * of these changes are also possible.
- * </li>
- * </ul>
- * </p>
- * Note: The styles supported by this class must be treated
- * as <em>HINT</em>s, since the window manager for the
- * desktop on which the instance is visible has ultimate
- * control over the appearance and behavior of decorations.
- * For example, some window managers only support resizable
- * windows and will always assume the RESIZE style, even if
- * it is not set.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * Class <code>SWT</code> provides two "convenience constants"
- * for the most commonly required style combinations:
- * <dl>
- * <dt><code>SHELL_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application top level shell: (that
- * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>)
- * </dd>
- * <dt><code>DIALOG_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application dialog shell: (that
- * is, <code>TITLE | CLOSE | BORDER</code>)
- * </dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see #getMinimized
- * @see #getMaximized
- * @see Shell
- * @see SWT
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Decorations extends Canvas {
- int shellHandle;
- Image image;
-// Image image, smallImage, largeImage;
- Image [] images;
- Menu menuBar;
- Menu [] menus;
- Control savedFocus;
- Button defaultButton, saveDefault;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Decorations () {
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#TOOL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Decorations (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-void addMenu (Menu menu) {
- if (menus == null) menus = new Menu [4];
- for (int i=0; i<menus.length; i++) {
- if (menus [i] == null) {
- menus [i] = menu;
- return;
- }
- }
- Menu [] newMenus = new Menu [menus.length + 4];
- newMenus [menus.length] = menu;
- System.arraycopy (menus, 0, newMenus, 0, menus.length);
- menus = newMenus;
-}
-
-void bringToTop () {
-// /*
-// * This code is intentionally commented. On some platforms,
-// * the ON_TOP style creates a shell that will stay on top
-// * of every other shell on the desktop. Using SetWindowPos ()
-// * with HWND_TOP caused problems on Windows 98 so this code is
-// * commented out until this functionality is specified and
-// * the problems are fixed.
-// */
-//// if ((style & SWT.ON_TOP) != 0) {
-//// int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE;
-//// OS.SetWindowPos (handle, OS.HWND_TOP, 0, 0, 0, 0, flags);
-//// } else {
-// OS.BringWindowToTop (handle);
-// // widget could be disposed at this point
-//// }
-}
-
-static int checkStyle (int style) {
- if ((style & SWT.NO_TRIM) != 0) {
- style &= ~(SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX | SWT.RESIZE | SWT.BORDER);
- }
- if ((style & (SWT.MENU | SWT.MIN | SWT.MAX | SWT.CLOSE)) != 0) {
- style |= SWT.TITLE;
- }
-//
-// /*
-// * If either WS_MINIMIZEBOX or WS_MAXIMIZEBOX are set,
-// * we must also set WS_SYSMENU or the buttons will not
-// * appear.
-// */
-// if ((style & (SWT.MIN | SWT.MAX)) != 0) style |= SWT.CLOSE;
-//
-// /*
-// * Both WS_SYSMENU and WS_CAPTION must be set in order
-// * to for the system menu to appear.
-// */
-// if ((style & SWT.CLOSE) != 0) style |= SWT.TITLE;
-//
-// /*
-// * Bug in Windows. The WS_CAPTION style must be
-// * set when the window is resizable or it does not
-// * draw properly.
-// */
-// /*
-// * This code is intentionally commented. It seems
-// * that this problem originally in Windows 3.11,
-// * has been fixed in later versions. Because the
-// * exact nature of the drawing problem is unknown,
-// * keep the commented code around in case it comes
-// * back.
-// */
-//// if ((style & SWT.RESIZE) != 0) style |= SWT.TITLE;
-//
- return style;
-}
-
-void checkBorder () {
- /* Do nothing */
-}
-
-void checkOpened () {
- //TODO - add back
-// if (!opened) resized = false;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void closeWidget () {
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- if (event.doit && !isDisposed ()) dispose ();
-}
-
-int compare (ImageData data1, ImageData data2) {
- int transparent1 = data1.getTransparencyType ();
- int transparent2 = data2.getTransparencyType ();
- if (transparent1 == transparent2) {
- if (data1.depth != data2.depth) {
- return data1.depth > data2.depth ? -1 : 1;
- }
- if (data1.width * data1.height != data2.width * data2.height) {
- return (data1.width * data1.height) > (data2.width * data2.height) ? -1 : 1;
- }
- }
- if (transparent1 == SWT.TRANSPARENCY_ALPHA) return -1;
- if (transparent2 == SWT.TRANSPARENCY_ALPHA) return 1;
- if (transparent1 == SWT.TRANSPARENCY_MASK) return -1;
- if (transparent2 == SWT.TRANSPARENCY_MASK) return 1;
- if (transparent1 == SWT.TRANSPARENCY_PIXEL) return -1;
- if (transparent2 == SWT.TRANSPARENCY_PIXEL) return 1;
- return 0;
-}
-
-Control computeTabGroup () {
- return this;
-}
-
-Control computeTabRoot () {
- return this;
-}
-
-public void dispose () {
- if (isDisposed()) return;
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!(this instanceof Shell)) {
- setVisible (false);
- if (!traverseDecorations (false)) {
- Shell shell = getShell ();
- shell.setFocus ();
- }
- }
- super.dispose ();
-}
-
-Menu findMenu (int hMenu) {
- if (menus == null) return null;
- for (int i=0; i<menus.length; i++) {
- Menu menu = menus [i];
- if (menu != null && hMenu == menu.handle) return menu;
- }
- return null;
-}
-
-void fixDecorations (Decorations newDecorations, Control control, Menu [] menus) {
- if (this == newDecorations) return;
- if (control == savedFocus) savedFocus = null;
- if (control == defaultButton) defaultButton = null;
- if (control == saveDefault) saveDefault = null;
- if (menus == null) return;
- Menu menu = control.menu;
- if (menu != null) {
- int index = 0;
- while (index <menus.length) {
- if (menus [index] == menu) {
- control.setMenu (null);
- return;
- }
- index++;
- }
- menu.fixMenus (newDecorations);
-// destroyAccelerators ();
-// newDecorations.destroyAccelerators ();
- }
-}
-
-/**
- * Returns the receiver's default button if one had
- * previously been set, otherwise returns null.
- *
- * @return the default button or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDefaultButton(Button)
- */
-public Button getDefaultButton () {
- checkWidget ();
- return defaultButton;
-}
-
-/**
- * Returns the receiver's image if it had previously been
- * set using <code>setImage()</code>. The image is typically
- * displayed by the window manager when the instance is
- * marked as iconified, and may also be displayed somewhere
- * in the trim when the instance is in normal or maximized
- * states.
- * <p>
- * Note: This method will return null if called before
- * <code>setImage()</code> is called. It does not provide
- * access to a window manager provided, "default" image
- * even if one exists.
- * </p>
- *
- * @return the image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget ();
- return image;
-}
-
-/**
- * Returns the receiver's images if they had previously been
- * set using <code>setImages()</code>. Images are typically
- * displayed by the window manager when the instance is
- * marked as iconified, and may also be displayed somewhere
- * in the trim when the instance is in normal or maximized
- * states. Depending where the icon is displayed, the platform
- * chooses the icon with the "best" attributes. It is expected
- * that the array will contain the same icon rendered at different
- * sizes, with different depth and transparency attributes.
- *
- * <p>
- * Note: This method will return an empty array if called before
- * <code>setImages()</code> is called. It does not provide
- * access to a window manager provided, "default" image
- * even if one exists.
- * </p>
- *
- * @return the images
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Image [] getImages () {
- checkWidget ();
- if (images == null) return new Image [0];
- Image [] result = new Image [images.length];
- System.arraycopy (images, 0, result, 0, images.length);
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver is currently
- * maximized, and false otherwise.
- * <p>
- *
- * @return the maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMaximized
- */
-public boolean getMaximized () {
- checkWidget ();
- if ((style & SWT.ON_TOP) != 0) return false;
- return OS.Window_WindowState (shellHandle) == OS.WindowState_Maximized;
-}
-
-/**
- * Returns the receiver's menu bar if one had previously
- * been set, otherwise returns null.
- *
- * @return the menu bar or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenuBar () {
- checkWidget ();
- return menuBar;
-}
-
-/**
- * Returns <code>true</code> if the receiver is currently
- * minimized, and false otherwise.
- * <p>
- *
- * @return the minimized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMinimized
- */
-public boolean getMinimized () {
- checkWidget ();
- if ((style & SWT.ON_TOP) != 0) return false;
- return OS.Window_WindowState (shellHandle) == OS.WindowState_Minimized;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which is the string that the
- * window manager will typically display as the receiver's
- * <em>title</em>. If the text has not previously been set,
- * returns an empty string.
- *
- * @return the text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- if ((style & SWT.ON_TOP) != 0) return "";
- int shellHandle = topHandle ();
- int str = OS.Window_Title (shellHandle);
- String string = createJavaString(str);
- OS.GCHandle_Free (str);
- return string;
-}
-
-boolean isTabGroup () {
- /*
- * Can't test WS_TAB bits because they are the same as WS_MAXIMIZEBOX.
- */
- return true;
-}
-
-boolean isTabItem () {
- /*
- * Can't test WS_TAB bits because they are the same as WS_MAXIMIZEBOX.
- */
- return false;
-}
-
-Decorations menuShell () {
- return this;
-}
-
-void releaseChildren (boolean destroy) {
- if (menuBar != null) {
- menuBar.release (false);
- menuBar = null;
- }
- super.releaseChildren (destroy);
- if (menus != null) {
- for (int i=0; i<menus.length; i++) {
- Menu menu = menus [i];
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- }
- menus = null;
- }
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- image = null;
- images = null;
- savedFocus = null;
-// defaultButton = saveDefault = null;
-}
-
-void removeMenu (Menu menu) {
- if (menus == null) return;
- for (int i=0; i<menus.length; i++) {
- if (menus [i] == menu) {
- menus [i] = null;
- return;
- }
- }
-}
-
-boolean restoreFocus () {
-// if (display.ignoreRestoreFocus) return true;
- if (savedFocus != null && savedFocus.isDisposed ()) savedFocus = null;
- if (savedFocus != null && savedFocus.setSavedFocus ()) return true;
- /*
- * This code is intentionally commented. When no widget
- * has been given focus, some platforms give focus to the
- * default button. Windows doesn't do this.
- */
-// if (defaultButton != null && !defaultButton.isDisposed ()) {
-// if (defaultButton.setFocus ()) return true;
-// }
- return false;
-}
-
-void saveFocus () {
- Control control = display._getFocusControl ();
- if (control != null && control != this && this == control.menuShell ()) {
- setSavedFocus (control);
- }
-}
-
-/**
- * If the argument is not null, sets the receiver's default
- * button to the argument, and if the argument is null, sets
- * the receiver's default button to the first button which
- * was set as the receiver's default button (called the
- * <em>saved default button</em>). If no default button had
- * previously been set, or the saved default button was
- * disposed, the receiver's default button will be set to
- * null.
- * <p>
- * The default button is the button that is selected when
- * the receiver is active and the user presses ENTER.
- * </p>
- *
- * @param button the new default button
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the button has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDefaultButton (Button button) {
- checkWidget ();
- if (button != null) {
- if (button.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (button.menuShell () != this) error(SWT.ERROR_INVALID_PARENT);
- }
- setDefaultButton (button, true);
-}
-
-void setDefaultButton (Button button, boolean save) {
- if (button == null) {
- if (defaultButton == saveDefault) {
- if (save) saveDefault = null;
- return;
- }
- } else {
- if ((button.style & SWT.PUSH) == 0) return;
- if (button == defaultButton) return;
- }
- if (defaultButton != null) {
- if (!defaultButton.isDisposed ()) defaultButton.setDefault (false);
- }
- if ((defaultButton = button) == null) defaultButton = saveDefault;
- if (defaultButton != null) {
- if (!defaultButton.isDisposed ()) defaultButton.setDefault (true);
- }
- if (save) saveDefault = defaultButton;
- if (saveDefault != null && saveDefault.isDisposed ()) saveDefault = null;
-}
-
-/**
- * Sets the receiver's image to the argument, which may
- * be null. The image is typically displayed by the window
- * manager when the instance is marked as iconified, and
- * may also be displayed somewhere in the trim when the
- * instance is in normal or maximized states.
- *
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- this.image = image;
- setImages (image, null);
-}
-
-void setImages (Image image, Image [] images) {
- if ((style & SWT.ON_TOP) != 0) return;
- int encoder = OS.gcnew_TiffBitmapEncoder ();
- int frames = OS.BitmapEncoder_Frames (encoder);
- if (image != null) {
- int frame = OS.BitmapFrame_Create (image.handle);
- OS.BitmapFrameCollection_Add (frames, frame);
- OS.GCHandle_Free (frame);
- }
- if (images != null) {
- if (images.length > 1) {
- ImageData [] datas = null;
- Image [] bestImages = new Image [images.length];
- System.arraycopy (images, 0, bestImages, 0, images.length);
- datas = new ImageData [images.length];
- for (int i=0; i<datas.length; i++) {
- datas [i] = images [i].getImageData ();
- }
- images = bestImages;
- sort (images, datas);
- }
- for (int i = 0; i < images.length; i++) {
- int frame = OS.BitmapFrame_Create (images [i].handle);
- OS.BitmapFrameCollection_Add (frames, frame);
- OS.GCHandle_Free (frame);
- }
- }
- OS.GCHandle_Free (frames);
- int stream = OS.gcnew_MemoryStream ();
- OS.BitmapEncoder_Save (encoder, stream);
- OS.GCHandle_Free (encoder);
- int decoder = OS.BitmapDecoder_Create (stream, OS.BitmapCreateOptions_None, OS.BitmapCacheOption_Default);
- OS.GCHandle_Free (stream);
- frames = OS.BitmapDecoder_Frames (decoder);
- int icon = OS.BitmapFrameCollection_default (frames, 0);
- OS.GCHandle_Free (frames);
- OS.GCHandle_Free (decoder);
- OS.Window_Icon(shellHandle, icon);
- OS.GCHandle_Free (icon);
-}
-
-/**
- * Sets the receiver's images to the argument, which may
- * be an empty array. Images are typically displayed by the
- * window manager when the instance is marked as iconified,
- * and may also be displayed somewhere in the trim when the
- * instance is in normal or maximized states. Depending where
- * the icon is displayed, the platform chooses the icon with
- * the "best" attributes. It is expected that the array will
- * contain the same icon rendered at different sizes, with
- * different depth and transparency attributes.
- *
- * @param images the new image array
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images is null or has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setImages (Image [] images) {
- checkWidget ();
- if (images == null) error (SWT.ERROR_INVALID_ARGUMENT);
- for (int i = 0; i < images.length; i++) {
- if (images [i] == null || images [i].isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.images = images;
- setImages (null, images);
-}
-
-/**
- * Sets the maximized state of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the maximized state, and if the argument is
- * <code>false</code> and the receiver was previously maximized,
- * causes the receiver to switch back to either the minimized
- * or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setMaximized(true)</code>
- * and <code>setMinimized(true)</code> will vary by platform. Typically,
- * the behavior will match the platform user's expectations, but not
- * always. This should be avoided if possible.
- * </p>
- *
- * @param maximized the new maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMinimized
- */
-public void setMaximized (boolean maximized) {
- checkWidget ();
- if ((style & SWT.ON_TOP) != 0) return;
- int state = maximized ? OS.WindowState_Maximized : OS.WindowState_Normal;
- OS.Window_WindowState (shellHandle, state);
-}
-
-/**
- * Sets the receiver's menu bar to the argument, which
- * may be null.
- *
- * @param menu the new menu bar
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenuBar (Menu menu) {
- checkWidget ();
- if (menuBar == menu) return;
- if (menu != null) {
- if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR);
- if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
- int children = OS.Panel_Children (scrolledHandle);
- if (menuBar != null) {
- OS.Menu_IsMainMenu (menuBar.handle, false);
- OS.UIElementCollection_Remove (children, menuBar.handle);
- }
- menuBar = menu;
- if (menuBar != null) {
- int menuHandle = menuBar.handle;
- OS.Menu_IsMainMenu (menuHandle, true);
- OS.Grid_SetRow (menuHandle, 0);
- OS.Grid_SetColumn (menuHandle, 0);
- OS.Grid_SetColumnSpan (menuHandle, 2);
- OS.UIElementCollection_Add (children, menuHandle);
- }
- OS.GCHandle_Free (children);
-}
-
-/**
- * Sets the minimized stated of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the minimized state, and if the argument is
- * <code>false</code> and the receiver was previously minimized,
- * causes the receiver to switch back to either the maximized
- * or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setMaximized(true)</code>
- * and <code>setMinimized(true)</code> will vary by platform. Typically,
- * the behavior will match the platform user's expectations, but not
- * always. This should be avoided if possible.
- * </p>
- *
- * @param minimized the new maximized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMaximized
- */
-public void setMinimized (boolean minimized) {
- checkWidget ();
- if ((style & SWT.ON_TOP) != 0) return;
- int state = minimized ? OS.WindowState_Minimized : OS.WindowState_Normal;
- OS.Window_WindowState (shellHandle, state);
-}
-
-void setSavedFocus (Control control) {
- savedFocus = control;
-}
-
-/**
- * Sets the receiver's text, which is the string that the
- * window manager will typically display as the receiver's
- * <em>title</em>, to the argument, which must not be null.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.ON_TOP) != 0) return;
- int strPtr = createDotNetString (string, false);
- int shellHandle = topHandle ();
- OS.Window_Title (shellHandle, strPtr);
- OS.GCHandle_Free (strPtr);
-}
-
-void sort (Image [] images, ImageData [] datas) {
- /* Shell Sort from K&R, pg 108 */
- int length = images.length;
- if (length <= 1) return;
- for (int gap=length/2; gap>0; gap/=2) {
- for (int i=gap; i<length; i++) {
- for (int j=i-gap; j>=0; j-=gap) {
- if (compare (datas [j], datas [j + gap]) >= 0) {
- Image swap = images [j];
- images [j] = images [j + gap];
- images [j + gap] = swap;
- ImageData swapData = datas [j];
- datas [j] = datas [j + gap];
- datas [j + gap] = swapData;
- }
- }
- }
- }
-}
-
-boolean traverseDecorations (boolean next) {
- Control [] children = parent._getChildren ();
- int length = children.length;
- int index = 0;
- while (index < length) {
- if (children [index] == this) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- int start = index, offset = (next) ? 1 : -1;
- while ((index = (index + offset + length) % length) != start) {
- Control child = children [index];
- if (!child.isDisposed () && child instanceof Decorations) {
- if (child.setFocus ()) return true;
- }
- }
- return false;
-}
-
-boolean traverseItem (boolean next) {
- return false;
-}
-
-boolean traverseReturn () {
- if (defaultButton == null || defaultButton.isDisposed ()) return false;
- if (!defaultButton.isVisible () || !defaultButton.isEnabled ()) return false;
-// defaultButton.click ();
-// TODO
- defaultButton.sendEvent (SWT.Selection);
- return true;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/DirectoryDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/DirectoryDialog.java
deleted file mode 100644
index 3993e0ccf1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/DirectoryDialog.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.wpf.*;
-
-/**
- * Instances of this class allow the user to navigate
- * the file system and select a directory.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#directorydialog">DirectoryDialog snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class DirectoryDialog extends Dialog {
- String message = "", filterPath = ""; //$NON-NLS-1$//$NON-NLS-2$
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public DirectoryDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public DirectoryDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-/**
- * Returns the path which the dialog will use to filter
- * the directories it shows.
- *
- * @return the filter path
- *
- * @see #setFilterPath
- */
-public String getFilterPath () {
- return filterPath;
-}
-
-/**
- * Returns the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @return the message
- */
-public String getMessage () {
- return message;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a string describing the absolute path of the selected directory,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public String open () {
- int dialog = OS.gcnew_FolderBrowserDialog ();
- if (dialog == 0) error (SWT.ERROR_NO_HANDLES);
- int messagePtr = parent.createDotNetString (message, false);
- OS.FolderBrowserDialog_Description (dialog, messagePtr);
- OS.GCHandle_Free (messagePtr);
- //TODO: filter path...
- String result = null;
- if (OS.FormsCommonDialog_ShowDialog (dialog) == OS.DialogResult_OK) {
- int ptr = OS.FolderBrowserDialog_SelectedPath (dialog);
- result = Widget.createJavaString (ptr);
- OS.GCHandle_Free (ptr);
- }
- OS.GCHandle_Free (dialog);
- return result;
-}
-
-/**
- * Sets the path that the dialog will use to filter
- * the directories it shows to the argument, which may
- * be null. If the string is null, then the operating
- * system's default filter path will be used.
- * <p>
- * Note that the path string is platform dependent.
- * For convenience, either '/' or '\' can be used
- * as a path separator.
- * </p>
- *
- * @param string the filter path
- */
-public void setFilterPath (String string) {
- filterPath = string;
-}
-
-/**
- * Sets the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @param string the message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- */
-public void setMessage (String string) {
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- message = string;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Display.java
deleted file mode 100644
index 3ed8cd3446..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Display.java
+++ /dev/null
@@ -1,3018 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are responsible for managing the
- * connection between SWT and the underlying operating
- * system. Their most important function is to implement
- * the SWT event loop in terms of the platform event model.
- * They also provide various methods for accessing information
- * about the operating system, and have overall control over
- * the operating system resources which SWT allocates.
- * <p>
- * Applications which are built with SWT will <em>almost always</em>
- * require only a single display. In particular, some platforms
- * which SWT supports will not allow more than one <em>active</em>
- * display. In other words, some platforms do not support
- * creating a new display if one already exists that has not been
- * sent the <code>dispose()</code> message.
- * <p>
- * In SWT, the thread which creates a <code>Display</code>
- * instance is distinguished as the <em>user-interface thread</em>
- * for that display.
- * </p>
- * The user-interface thread for a particular display has the
- * following special attributes:
- * <ul>
- * <li>
- * The event loop for that display must be run from the thread.
- * </li>
- * <li>
- * Some SWT API methods (notably, most of the public methods in
- * <code>Widget</code> and its subclasses), may only be called
- * from the thread. (To support multi-threaded user-interface
- * applications, class <code>Display</code> provides inter-thread
- * communication methods which allow threads other than the
- * user-interface thread to request that it perform operations
- * on their behalf.)
- * </li>
- * <li>
- * The thread is not allowed to construct other
- * <code>Display</code>s until that display has been disposed.
- * (Note that, this is in addition to the restriction mentioned
- * above concerning platform support for multiple displays. Thus,
- * the only way to have multiple simultaneously active displays,
- * even on platforms which support it, is to have multiple threads.)
- * </li>
- * </ul>
- * Enforcing these attributes allows SWT to be implemented directly
- * on the underlying operating system's event model. This has
- * numerous benefits including smaller footprint, better use of
- * resources, safer memory management, clearer program logic,
- * better performance, and fewer overall operating system threads
- * required. The down side however, is that care must be taken
- * (only) when constructing multi-threaded applications to use the
- * inter-thread communication mechanisms which this class provides
- * when required.
- * </p><p>
- * All SWT API methods which may only be called from the user-interface
- * thread are distinguished in their documentation by indicating that
- * they throw the "<code>ERROR_THREAD_INVALID_ACCESS</code>"
- * SWT exception.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Close, Dispose, Settings</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- * @see #syncExec
- * @see #asyncExec
- * @see #wake
- * @see #readAndDispatch
- * @see #sleep
- * @see Device#dispose
- * @see <a href="http://www.eclipse.org/swt/snippets/#display">Display snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Display extends Device {
-
- int application, dispatcher, frame, jniRef, nameScope;
- boolean idle;
- int sleepOperation, operation;
- int operationCount;
-
- /* Windows and Events */
- Event [] eventQueue;
- EventTable eventTable, filterTable;
-
- int lastKey;
- char lastChar;
- boolean deadChar;
-
- /* Track Mouse Control */
- Control mouseControl;
-
- /* Focus */
- Control focusControl;
-
- /* Menus */
- Menu [] popups;
-
- /* Sync/Async Widget Communication */
- Synchronizer synchronizer = new Synchronizer (this);
- Thread thread;
-
- /* Display Shutdown */
- Runnable [] disposeList;
-
- /* System Tray */
- Tray tray;
-
- /* Timers */
- int timerHandler;
- int [] timerHandles;
- Runnable [] timerList;
-
-// /* System Resources */
- Font systemFont;
- Image errorImage, infoImage, questionImage, warningIcon;
- Cursor [] cursors = new Cursor [SWT.CURSOR_HAND + 1];
- Color [] colors;
-
- /* Sort Indicators */
-// Image upArrow, downArrow;
-
- /* Color dialog custom dialgos */
- int customColors;
-
- /* Display Data */
- Object data;
- String [] keys;
- Object [] values;
-
- /* DragDetect */
- boolean dragging;
- int dragDetectFrame, dragRect, dragMouseDown;
-
- Control[] invalidate;
- int invalidateHandler;
- boolean ignoreRender;
-
- Shell [] shells;
-
- /* Key Mappings */
- static final int [] [] KeyTable = {
-
- /* Keyboard and Mouse Masks */
- {OS.Key_LeftAlt, SWT.ALT},
- {OS.Key_RightAlt, SWT.ALT},
- {OS.Key_LeftShift, SWT.SHIFT},
- {OS.Key_RightShift, SWT.SHIFT},
- {OS.Key_LeftCtrl, SWT.CONTROL},
- {OS.Key_RightCtrl, SWT.CONTROL},
-// {OS.VK_????, SWT.COMMAND},
-
- /* NOT CURRENTLY USED */
-// {OS.VK_LBUTTON, SWT.BUTTON1},
-// {OS.VK_MBUTTON, SWT.BUTTON3},
-// {OS.VK_RBUTTON, SWT.BUTTON2},
-
- /* Non-Numeric Keypad Keys */
- {OS.Key_Up, SWT.ARROW_UP},
- {OS.Key_Down, SWT.ARROW_DOWN},
- {OS.Key_Left, SWT.ARROW_LEFT},
- {OS.Key_Right, SWT.ARROW_RIGHT},
- {OS.Key_PageUp, SWT.PAGE_UP},
- {OS.Key_PageDown, SWT.PAGE_DOWN},
- {OS.Key_Home, SWT.HOME},
- {OS.Key_End, SWT.END},
- {OS.Key_Insert, SWT.INSERT},
-
- /* Virtual and Ascii Keys */
- {OS.Key_Back, SWT.BS},
- {OS.Key_Return, SWT.CR},
- {OS.Key_Delete, SWT.DEL},
- {OS.Key_Escape, SWT.ESC},
- {OS.Key_Return, SWT.LF},
- {OS.Key_Tab, SWT.TAB},
-
- /* Functions Keys */
- {OS.Key_F1, SWT.F1},
- {OS.Key_F2, SWT.F2},
- {OS.Key_F3, SWT.F3},
- {OS.Key_F4, SWT.F4},
- {OS.Key_F5, SWT.F5},
- {OS.Key_F6, SWT.F6},
- {OS.Key_F7, SWT.F7},
- {OS.Key_F8, SWT.F8},
- {OS.Key_F9, SWT.F9},
- {OS.Key_F10, SWT.F10},
- {OS.Key_F11, SWT.F11},
- {OS.Key_F12, SWT.F12},
- {OS.Key_F13, SWT.F13},
- {OS.Key_F14, SWT.F14},
- {OS.Key_F15, SWT.F15},
-
- /* Numeric Keypad Keys */
- {OS.Key_Multiply, SWT.KEYPAD_MULTIPLY},
- {OS.Key_Add, SWT.KEYPAD_ADD},
- {OS.Key_Return, SWT.KEYPAD_CR},
- {OS.Key_Subtract, SWT.KEYPAD_SUBTRACT},
- {OS.Key_Decimal, SWT.KEYPAD_DECIMAL},
- {OS.Key_Divide, SWT.KEYPAD_DIVIDE},
- {OS.Key_NumPad0, SWT.KEYPAD_0},
- {OS.Key_NumPad1, SWT.KEYPAD_1},
- {OS.Key_NumPad2, SWT.KEYPAD_2},
- {OS.Key_NumPad3, SWT.KEYPAD_3},
- {OS.Key_NumPad4, SWT.KEYPAD_4},
- {OS.Key_NumPad5, SWT.KEYPAD_5},
- {OS.Key_NumPad6, SWT.KEYPAD_6},
- {OS.Key_NumPad7, SWT.KEYPAD_7},
- {OS.Key_NumPad8, SWT.KEYPAD_8},
- {OS.Key_NumPad9, SWT.KEYPAD_9},
-// {OS.VK_????, SWT.KEYPAD_EQUAL},
-
- /* Other keys */
- {OS.Key_CapsLock, SWT.CAPS_LOCK},
- {OS.Key_NumLock, SWT.NUM_LOCK},
- {OS.Key_Scroll, SWT.SCROLL_LOCK},
- {OS.Key_Pause, SWT.PAUSE},
- {OS.Key_Cancel, SWT.BREAK},
- {OS.Key_PrintScreen, SWT.PRINT_SCREEN},
-// {OS.VK_????, SWT.HELP},
-
-
- {OS.Key_D0, '0'},
- {OS.Key_D1, '1'},
- {OS.Key_D2, '2'},
- {OS.Key_D3, '3'},
- {OS.Key_D4, '4'},
- {OS.Key_D5, '5'},
- {OS.Key_D6, '6'},
- {OS.Key_D7, '7'},
- {OS.Key_D8, '8'},
- {OS.Key_D9, '9'},
- {OS.Key_A, 'a'},
- {OS.Key_B, 'b'},
- {OS.Key_C, 'c'},
- {OS.Key_D, 'd'},
- {OS.Key_E, 'e'},
- {OS.Key_F, 'f'},
- {OS.Key_G, 'g'},
- {OS.Key_H, 'h'},
- {OS.Key_I, 'i'},
- {OS.Key_J, 'j'},
- {OS.Key_K, 'k'},
- {OS.Key_L, 'l'},
- {OS.Key_M, 'm'},
- {OS.Key_N, 'n'},
- {OS.Key_O, 'o'},
- {OS.Key_P, 'p'},
- {OS.Key_Q, 'q'},
- {OS.Key_R, 'r'},
- {OS.Key_S, 's'},
- {OS.Key_T, 't'},
- {OS.Key_U, 'u'},
- {OS.Key_V, 'v'},
- {OS.Key_W, 'w'},
- {OS.Key_X, 'x'},
- {OS.Key_Y, 'y'},
- {OS.Key_Z, 'z'},
-
- {OS.Key_OemTilde, '`'},
- {OS.Key_OemMinus, '-'},
- {OS.Key_OemPlus, '='},
- {OS.Key_Oem4, '['},
- {OS.Key_Oem6, ']'},
- {OS.Key_OemPipe, '\\'},
- {OS.Key_OemSemicolon, ';'},
- {OS.Key_Oem7, '\''},
- {OS.Key_OemComma, ','},
- {OS.Key_OemPeriod, '.'},
- {OS.Key_Oem2, '/'},
-
- };
-
- /* Multiple Displays */
- static Display Default;
- static Display [] Displays = new Display [4];
-
- /* Multiple Monitors */
- static Monitor[] monitors = null;
- static int monitorCount = 0;
-
- /* Modality */
- Shell [] modalShells;
-// Shell modalDialogShell;
-
- /* Package Name */
- static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets."; //$NON-NLS-1$
- /*
- * This code is intentionally commented. In order
- * to support CLDC, .class cannot be used because
- * it does not compile on some Java compilers when
- * they are targeted for CLDC.
- */
-// static {
-// String name = Display.class.getName ();
-// int index = name.lastIndexOf ('.');
-// PACKAGE_PREFIX = name.substring (0, index + 1);
-// }
-
- /*
- * TEMPORARY CODE. Install the runnable that
- * gets the current display. This code will
- * be removed in the future.
- */
- static {
- DeviceFinder = new Runnable () {
- public void run () {
- Device device = getCurrent ();
- if (device == null) {
- device = getDefault ();
- }
- setDevice (device);
- }
- };
- }
-
-/*
-* TEMPORARY CODE.
-*/
-static void setDevice (Device device) {
- CurrentDevice = device;
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * Note: The resulting display is marked as the <em>current</em>
- * display. If this is the first display which has been
- * constructed since the application started, it is also
- * marked as the <em>default</em> display.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if called from a thread that already created an existing display</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see #getCurrent
- * @see #getDefault
- * @see Widget#checkSubclass
- * @see Shell
- */
-public Display () {
- this (null);
-}
-
-/**
- * Constructs a new instance of this class using the parameter.
- *
- * @param data the device data
- */
-public Display (DeviceData data) {
- super (data);
-}
-
-Control _getFocusControl () {
- int focusedElement = OS.Keyboard_FocusedElement ();
- Control control = null;
- if (focusedElement != 0) {
- Widget widget = getWidget (focusedElement);
- if (widget instanceof Menu) {
- Shell shell = ((Menu)widget).getShell();
- OS.GCHandle_Free (focusedElement);
- focusedElement = OS.FocusManager_GetFocusedElement (shell.shellHandle);
- if (focusedElement == 0) return null;
- widget = getWidget (focusedElement);
- }
- if (widget != null) control = widget.getWidgetControl ();
- OS.GCHandle_Free (focusedElement);
- }
- return control;
-}
-
-void addWidget (int handle, Widget widget) {
- if (handle == 0) return;
- int tag = OS.gcnew_IntPtr (widget.jniRef);
- OS.FrameworkElement_Tag (handle, tag);
- OS.GCHandle_Free (tag);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs anywhere
- * in a widget. The event type is one of the event constants
- * defined in class <code>SWT</code>. When the event does occur,
- * the listener is notified by sending it the <code>handleEvent()</code>
- * message.
- * <p>
- * Setting the type of an event to <code>SWT.None</code> from
- * within the <code>handleEvent()</code> method can be used to
- * change the event type and stop subsequent Java listeners
- * from running. Because event filters run before other listeners,
- * event filters can both block other listeners and set arbitrary
- * fields within an event. For this reason, event filters are both
- * powerful and dangerous. They should generally be avoided for
- * performance, debugging and code maintenance reasons.
- * </p>
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #removeFilter
- * @see #removeListener
- *
- * @since 3.0
- */
-public void addFilter (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (filterTable == null) filterTable = new EventTable ();
- filterTable.hook (eventType, listener);
-}
-
-void addInvalidate (Control control) {
- if (invalidate == null) invalidate = new Control [4];
- int length = invalidate.length;
- for (int i=0; i<length; i++) {
- if (invalidate [i] == control) return;
- }
- int index = 0;
- while (index < length) {
- if (invalidate [index] == null) break;
- index++;
- }
- if (index == length) {
- Control [] temp = new Control [length + 4];
- System.arraycopy (invalidate, 0, temp, 0, length);
- invalidate = temp;
- }
- invalidate [index] = control;
- if (invalidateHandler == 0) {
- int handler = invalidateHandler = OS.gcnew_NoArgsDelegate (jniRef, "invalidateHandler");
- int operation = OS.Dispatcher_BeginInvoke (dispatcher, OS.DispatcherPriority_Send, handler);
- OS.GCHandle_Free (operation);
- OS.GCHandle_Free (handler);
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- * When the event does occur in the display, the listener is notified by
- * sending it the <code>handleEvent()</code> message.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #removeListener
- *
- * @since 2.0
- */
-public void addListener (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) eventTable = new EventTable ();
- eventTable.hook (eventType, listener);
-}
-
-void addPopup (Menu menu) {
- if (popups == null) popups = new Menu [4];
- int length = popups.length;
- for (int i=0; i<length; i++) {
- if (popups [i] == menu) return;
- }
- int index = 0;
- while (index < length) {
- if (popups [index] == null) break;
- index++;
- }
- if (index == length) {
- Menu [] newPopups = new Menu [length + 4];
- System.arraycopy (popups, 0, newPopups, 0, length);
- popups = newPopups;
- }
- popups [index] = menu;
-}
-
-void addShell (Shell shell) {
- if (shells == null) shells = new Shell [4];
- int length = shells.length;
- for (int i=0; i<length; i++) {
- if (shells [i] == shell) return;
- }
- int index = 0;
- while (index < length) {
- if (shells [index] == null) break;
- index++;
- }
- if (index == length) {
- Shell [] temp = new Shell [length + 4];
- System.arraycopy (shells, 0, temp, 0, length);
- shells = temp;
- }
- shells [index] = shell;
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread at the next
- * reasonable opportunity. The caller of this method continues
- * to run in parallel, and is not notified when the
- * runnable has completed. Specifying <code>null</code> as the
- * runnable simply wakes the user-interface thread when run.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param runnable code to run on the user-interface thread or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #syncExec
- */
-public void asyncExec (Runnable runnable) {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- synchronizer.asyncExec (runnable);
- }
-}
-
-/**
- * Causes the system hardware to emit a short sound
- * (if it supports this capability).
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void beep () {
- checkDevice ();
- OS.Console_Beep ();
-}
-
-/**
- * Checks that this class can be subclassed.
- * <p>
- * IMPORTANT: See the comment in <code>Widget.checkSubclass()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- */
-protected void checkSubclass () {
- if (!isValidClass (getClass ())) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-protected void checkDevice () {
- if (thread == null) error (SWT.ERROR_WIDGET_DISPOSED);
- if (thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
-}
-
-static void checkDisplay (Thread thread, boolean multiple) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] != null) {
- if (!multiple) SWT.error (SWT.ERROR_NOT_IMPLEMENTED, null, " [multiple displays]");
- if (Displays [i].thread == thread) SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- }
- }
-}
-
-void clearModal (Shell shell) {
- if (modalShells == null) return;
- int index = 0, length = modalShells.length;
- while (index < length) {
- if (modalShells [index] == shell) break;
- if (modalShells [index] == null) return;
- index++;
- }
- if (index == length) return;
- System.arraycopy (modalShells, index + 1, modalShells, index, --length - index);
- modalShells [length] = null;
- if (index == 0 && modalShells [0] == null) modalShells = null;
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) shells [i].updateModal ();
-}
-
-/**
- * Requests that the connection between SWT and the underlying
- * operating system be closed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Device#dispose
- *
- * @since 2.0
- */
-public void close () {
- checkDevice ();
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- if (event.doit) dispose ();
-}
-
-/**
- * Creates the device in the operating system. If the device
- * does not have a handle, this method may do nothing depending
- * on the device.
- * <p>
- * This method is called before <code>init</code>.
- * </p>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #init
- */
-protected void create (DeviceData data) {
- checkSubclass ();
- checkDisplay (thread = Thread.currentThread (), true);
- createDisplay (data);
- register (this);
- if (Default == null) Default = this;
-}
-
-void createDisplay (DeviceData data) {
- Win32.OleInitialize (0);
- application = OS.gcnew_Application();
- if (application == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.Application_ShutdownMode (application, OS.ShutdownMode_OnExplicitShutdown);
- nameScope = OS.gcnew_NameScope ();
- if (nameScope == 0) SWT.error (SWT.ERROR_NO_HANDLES);
-}
-
-static void deregister (Display display) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (display == Displays [i]) Displays [i] = null;
- }
- }
-}
-
-/**
- * Destroys the device in the operating system and releases
- * the device's handle. If the device does not have a handle,
- * this method may do nothing depending on the device.
- * <p>
- * This method is called after <code>release</code>.
- * </p>
- * @see Device#dispose
- * @see #release
- */
-protected void destroy () {
- if (this == Default) Default = null;
- deregister (this);
- destroyDisplay ();
-}
-
-void destroyDisplay () {
- OS.GCHandle_Dump();
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread just before the
- * receiver is disposed. Specifying a <code>null</code> runnable
- * is ignored.
- *
- * @param runnable code to run at dispose time.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void disposeExec (Runnable runnable) {
- checkDevice ();
- if (disposeList == null) disposeList = new Runnable [4];
- for (int i=0; i<disposeList.length; i++) {
- if (disposeList [i] == null) {
- disposeList [i] = runnable;
- return;
- }
- }
- Runnable [] newDisposeList = new Runnable [disposeList.length + 4];
- System.arraycopy (disposeList, 0, newDisposeList, 0, disposeList.length);
- newDisposeList [disposeList.length] = runnable;
- disposeList = newDisposeList;
-}
-
-/**
- * Does whatever display specific cleanup is required, and then
- * uses the code in <code>SWTError.error</code> to handle the error.
- *
- * @param code the descriptive error code
- *
- * @see SWT#error(int)
- */
-void error (int code) {
- SWT.error (code);
-}
-
-boolean filterEvent (Event event) {
- if (filterTable != null) filterTable.sendEvent (event);
- return false;
-}
-
-boolean filters (int eventType) {
- if (filterTable == null) return false;
- return filterTable.hooks (eventType);
-}
-
-/**
- * Given the operating system handle for a widget, returns
- * the instance of the <code>Widget</code> subclass which
- * represents it in the currently running application, if
- * such exists, or null if no matching widget can be found.
- * <p>
- * <b>IMPORTANT:</b> This method should not be called from
- * application code. The arguments are platform-specific.
- * </p>
- *
- * @param handle the handle for the widget
- * @return the SWT widget that the handle represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Widget findWidget (int handle) {
- checkDevice ();
- return getWidget (handle);
-}
-
-/**
- * Given the operating system handle for a widget,
- * and widget-specific id, returns the instance of
- * the <code>Widget</code> subclass which represents
- * the handle/id pair in the currently running application,
- * if such exists, or null if no matching widget can be found.
- * <p>
- * <b>IMPORTANT:</b> This method should not be called from
- * application code. The arguments are platform-specific.
- * </p>
- *
- * @param handle the handle for the widget
- * @param id the id for the subwidget (usually an item)
- * @return the SWT widget that the handle/id pair represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.1
- */
-public Widget findWidget (int handle, int id) {
- checkDevice ();
- return null;
-}
-
-/**
- * Given a widget and a widget-specific id, returns the
- * instance of the <code>Widget</code> subclass which represents
- * the widget/id pair in the currently running application,
- * if such exists, or null if no matching widget can be found.
- *
- * @param widget the widget
- * @param id the id for the subwidget (usually an item)
- * @return the SWT subwidget (usually an item) that the widget/id pair represents
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.3
- */
-public Widget findWidget (Widget widget, int id) {
- checkDevice ();
- return null;
-}
-
-/**
- * Returns the display which the given thread is the
- * user-interface thread for, or null if the given thread
- * is not a user-interface thread for any display. Specifying
- * <code>null</code> as the thread will return <code>null</code>
- * for the display.
- *
- * @param thread the user-interface thread
- * @return the display for the given thread
- */
-public static Display findDisplay (Thread thread) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- Display display = Displays [i];
- if (display != null && display.thread == thread) {
- return display;
- }
- }
- return null;
- }
-}
-
-/**
- * Returns the currently active <code>Shell</code>, or null
- * if no shell belonging to the currently running application
- * is active.
- *
- * @return the active shell or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Shell getActiveShell () {
- checkDevice ();
- int windows = OS.Application_Windows (application);
- int count = OS.WindowCollection_Count (windows);
- int activeWindow = 0;
- if (count != 0) {
- int enumerator = OS.WindowCollection_GetEnumerator (windows);
- while (OS.IEnumerator_MoveNext (enumerator)) {
- int window = OS.WindowCollection_Current (enumerator);
- if (OS.Window_IsActive (window)) {
- activeWindow = window;
- break;
- }
- OS.GCHandle_Free (window);
- }
- OS.GCHandle_Free (enumerator);
- }
- OS.GCHandle_Free (windows);
- Shell shell = (Shell)getWidget (activeWindow);
- if (activeWindow != 0) OS.GCHandle_Free (activeWindow);
- return shell;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location. Note that
- * on multi-monitor systems the origin can be negative.
- *
- * @return the bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkDevice ();
- int x = (int) OS.SystemParameters_VirtualScreenLeft ();
- int y = (int) OS.SystemParameters_VirtualScreenTop ();
- int width = (int) OS.SystemParameters_VirtualScreenWidth ();
- int height = (int) OS.SystemParameters_VirtualScreenHeight ();
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the display which the currently running thread is
- * the user-interface thread for, or null if the currently
- * running thread is not a user-interface thread for any display.
- *
- * @return the current display
- */
-public static Display getCurrent () {
- return findDisplay (Thread.currentThread ());
-}
-
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data.
- *
- * @return the client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getBounds
- */
-public Rectangle getClientArea () {
- checkDevice ();
-// if (true/*OS.GetSystemMetrics (OS.SM_CMONITORS) < 2*/) {
- int rect = OS.SystemParameters_WorkArea ();
- int x = (int) OS.Rect_X (rect);
- int y = (int) OS.Rect_Y (rect);
- int width = (int) OS.Rect_Width (rect);
- int height = (int) OS.Rect_Height (rect);
- OS.GCHandle_Free (rect);
- return new Rectangle (x, y, width, height);
-// }
-// int x = (int) OS.SystemParameters_VirtualScreenLeft ();
-// int y = (int) OS.SystemParameters_VirtualScreenTop ();
-// int width = (int) OS.SystemParameters_VirtualScreenWidth ();
-// int height = (int) OS.SystemParameters_VirtualScreenHeight ();
-// return new Rectangle (x, y, width, height);
-}
-
-Widget getWidget (int handle) {
- if (handle == 0) return null;
- int frameworkElementType = OS.FrameworkElement_typeid ();
- int frameworkContentElementType = OS.FrameworkContentElement_typeid ();
- int widget = handle;
- int jniRef = 0;
- do {
- int parent = 0;
- if (OS.Type_IsInstanceOfType (frameworkElementType, widget)) {
- int tag = OS.FrameworkElement_Tag (widget);
- if (tag != 0) {
- jniRef = OS.IntPtr_ToInt32 (tag);
- OS.GCHandle_Free (tag);
- break;
- }
- parent = OS.FrameworkElement_Parent (widget);
- if (parent == 0) {
- parent = OS.VisualTreeHelper_GetParent (widget);
- }
- } else {
- if (OS.Type_IsInstanceOfType (frameworkContentElementType, widget)) {
- parent = OS.FrameworkContentElement_Parent (widget);
- }
- }
- if (widget != handle) OS.GCHandle_Free (widget);
- widget = parent;
- } while (widget != 0);
- if (widget != handle && widget != 0) OS.GCHandle_Free (widget);
- OS.GCHandle_Free (frameworkElementType);
- OS.GCHandle_Free (frameworkContentElementType);
- return jniRef != 0 ? (Widget) OS.JNIGetObject (jniRef) : null;
-}
-
-/**
- * Returns the control which the on-screen pointer is currently
- * over top of, or null if it is not currently over one of the
- * controls built by the currently running application.
- *
- * @return the control under the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Control getCursorControl () {
- checkDevice ();
- int inputElement = 0;
- int captured = OS.Mouse_Captured ();
- if (captured != 0) {
- int sources = OS.PresentationSource_CurrentSources ();
- int enumerator = OS.IEnumerable_GetEnumerator (sources);
- while (OS.IEnumerator_MoveNext (enumerator) && inputElement == 0) {
- int current = OS.IEnumerator_Current (enumerator);
- int root = OS.PresentationSource_RootVisual (current);
- if (root != 0) {
- int pt = OS.Mouse_GetPosition (root);
- inputElement = OS.UIElement_InputHitTest (root, pt);
- OS.GCHandle_Free (pt);
- OS.GCHandle_Free (root);
- }
- OS.GCHandle_Free (current);
- }
- OS.GCHandle_Free (enumerator);
- OS.GCHandle_Free (sources);
- OS.GCHandle_Free (captured);
- } else {
- inputElement = OS.Mouse_DirectlyOver ();
- }
- if (inputElement != 0) {
- Widget widget = getWidget (inputElement);
- OS.GCHandle_Free (inputElement);
- if (widget != null) return widget.getWidgetControl ();
- }
- return null;
-}
-
-/**
- * Returns the location of the on-screen pointer relative
- * to the top left corner of the screen.
- *
- * @return the cursor location
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Point getCursorLocation () {
- checkDevice ();
- POINT pt = new POINT ();
- Win32.GetCursorPos (pt);
- return new Point (pt.x, pt.y);
-}
-
-/**
- * Returns an array containing the recommended cursor sizes.
- *
- * @return the array of cursor sizes
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public Point [] getCursorSizes () {
- checkDevice ();
-// return new Point [] {
-// new Point (OS.GetSystemMetrics (OS.SM_CXCURSOR), OS.GetSystemMetrics (OS.SM_CYCURSOR))};
- return null;
-}
-
-/**
- * Returns the default display. One is created (making the
- * thread that invokes this method its user-interface thread)
- * if it did not already exist.
- *
- * @return the default display
- */
-public static Display getDefault () {
- synchronized (Device.class) {
- if (Default == null) Default = new Display ();
- return Default;
- }
-}
-
-static boolean isValidClass (Class clazz) {
- String name = clazz.getName ();
- int index = name.lastIndexOf ('.');
- return name.substring (0, index + 1).equals (PACKAGE_PREFIX);
-}
-
-/**
- * Returns the application defined property of the receiver
- * with the specified name, or null if it has not been set.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the display is disposed
- * of, it is the application's responsibility to provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param key the name of the property
- * @return the value of the property or null if it has not been set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setData(String, Object)
- * @see #disposeExec(Runnable)
- */
-public Object getData (String key) {
- checkDevice ();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
-// if (key.equals (RUN_MESSAGES_IN_IDLE_KEY)) {
-// return new Boolean (runMessagesInIdle);
-// }
- if (keys == null) return null;
- for (int i=0; i<keys.length; i++) {
- if (keys [i].equals (key)) return values [i];
- }
- return null;
-}
-
-/**
- * Returns the application defined, display specific data
- * associated with the receiver, or null if it has not been
- * set. The <em>display specific data</em> is a single,
- * unnamed field that is stored with every display.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the display specific data needs to
- * be notified when the display is disposed of, it is the
- * application's responsibility to provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @return the display specific data
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #setData(Object)
- * @see #disposeExec(Runnable)
- */
-public Object getData () {
- checkDevice ();
- return data;
-}
-
-/**
- * Returns the button dismissal alignment, one of <code>LEFT</code> or <code>RIGHT</code>.
- * The button dismissal alignment is the ordering that should be used when positioning the
- * default dismissal button for a dialog. For example, in a dialog that contains an OK and
- * CANCEL button, on platforms where the button dismissal alignment is <code>LEFT</code>, the
- * button ordering should be OK/CANCEL. When button dismissal alignment is <code>RIGHT</code>,
- * the button ordering should be CANCEL/OK.
- *
- * @return the button dismissal order
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1
- */
-public int getDismissalAlignment () {
- checkDevice ();
- return SWT.LEFT;
-}
-
-
-/**
- * Returns the longest duration, in milliseconds, between
- * two mouse button clicks that will be considered a
- * <em>double click</em> by the underlying operating system.
- *
- * @return the double click time
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public int getDoubleClickTime () {
- checkDevice ();
- //TODO
- return 500;
-}
-
-/**
- * Returns the control which currently has keyboard focus,
- * or null if keyboard events are not currently going to
- * any of the controls built by the currently running
- * application.
- *
- * @return the control under the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Control getFocusControl () {
- checkDevice ();
- if (focusControl != null && !focusControl.isDisposed ()) {
- return focusControl;
- }
- return _getFocusControl ();
-}
-
-/**
- * Returns true when the high contrast mode is enabled.
- * Otherwise, false is returned.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @return the high contrast mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public boolean getHighContrast () {
- checkDevice ();
- return OS.SystemParameters_HighContrast ();
-}
-
-/**
- * Returns the maximum allowed depth of icons on this display, in bits per pixel.
- * On some platforms, this may be different than the actual depth of the display.
- *
- * @return the maximum icon depth
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Device#getDepth
- */
-public int getIconDepth () {
- checkDevice ();
-// if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
-// if (getDepth () >= 24) return 32;
-// }
-//
-// /* Use the character encoding for the default locale */
-// TCHAR buffer1 = new TCHAR (0, "Control Panel\\Desktop\\WindowMetrics", true); //$NON-NLS-1$
-//
-// int [] phkResult = new int [1];
-// int result = OS.RegOpenKeyEx (OS.HKEY_CURRENT_USER, buffer1, 0, OS.KEY_READ, phkResult);
-// if (result != 0) return 4;
- int depth = 4;
-// int [] lpcbData = new int [1];
-//
-// /* Use the character encoding for the default locale */
-// TCHAR buffer2 = new TCHAR (0, "Shell Icon BPP", true); //$NON-NLS-1$
-// result = OS.RegQueryValueEx (phkResult [0], buffer2, 0, null, (TCHAR) null, lpcbData);
-// if (result == 0) {
-// TCHAR lpData = new TCHAR (0, lpcbData [0] / TCHAR.sizeof);
-// result = OS.RegQueryValueEx (phkResult [0], buffer2, 0, null, lpData, lpcbData);
-// if (result == 0) {
-// try {
-// depth = Integer.parseInt (lpData.toString (0, lpData.strlen ()));
-// } catch (NumberFormatException e) {}
-// }
-// }
-// OS.RegCloseKey (phkResult [0]);
- return depth;
-}
-
-/**
- * Returns an array containing the recommended icon sizes.
- *
- * @return the array of icon sizes
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Decorations#setImages(Image[])
- *
- * @since 3.0
- */
-public Point [] getIconSizes () {
- checkDevice ();
- //TODO
-// return new Point [] {
-// new Point (OS.GetSystemMetrics (OS.SM_CXSMICON), OS.GetSystemMetrics (OS.SM_CYSMICON)),
-// new Point (OS.GetSystemMetrics (OS.SM_CXICON), OS.GetSystemMetrics (OS.SM_CYICON)),
-// };
- return null;
-}
-
-int getLastEventTime () {
- //TODO - use OS
- return (int)System.currentTimeMillis();
-}
-
-int getMessageCount () {
- return synchronizer.getMessageCount ();
-}
-
-
-Shell getModalShell () {
- if (modalShells == null) return null;
- int index = modalShells.length;
- while (--index >= 0) {
- Shell shell = modalShells [index];
- if (shell != null) return shell;
- }
- return null;
-}
-
-//Shell getModalDialogShell () {
-// if (modalDialogShell != null && modalDialogShell.isDisposed ()) modalDialogShell = null;
-// return modalDialogShell;
-//}
-
-/**
- * Returns an array of monitors attached to the device.
- *
- * @return the array of monitors
- *
- * @since 3.0
- */
-public Monitor [] getMonitors () {
- checkDevice ();
- int screens = OS.Screen_AllScreens ();
- if (screens == 0) error (SWT.ERROR_NO_HANDLES);
- int screenCount = OS.ICollection_Count (screens);
- Monitor [] monitors = new Monitor [screenCount];
- for (int i=0; i<screenCount; i++) {
- int screen = OS.IList_default (screens, i);
- int bounds = OS.Screen_Bounds (screen);
- int workingArea = OS.Screen_WorkingArea (screen);
- Monitor monitor = new Monitor ();
- monitor.x = OS.Rectangle_X (bounds);
- monitor.y = OS.Rectangle_Y (bounds);
- monitor.width = OS.Rectangle_Width (bounds);
- monitor.height = OS.Rectangle_Height (bounds);
- monitor.clientX = OS.Rectangle_X (workingArea);
- monitor.clientY = OS.Rectangle_Y (workingArea);
- monitor.clientWidth = OS.Rectangle_Width (workingArea);
- monitor.clientHeight = OS.Rectangle_Height (workingArea);
- monitors [i] = monitor;
- OS.GCHandle_Free (workingArea);
- OS.GCHandle_Free (bounds);
- OS.GCHandle_Free (screen);
- }
- OS.GCHandle_Free (screens);
- return monitors;
-}
-
-/**
- * Returns the primary monitor for that device.
- *
- * @return the primary monitor
- *
- * @since 3.0
- */
-public Monitor getPrimaryMonitor () {
- checkDevice ();
- int screen = OS.Screen_PrimaryScreen ();
- if (screen == 0) error (SWT.ERROR_NO_HANDLES);
- int bounds = OS.Screen_Bounds (screen);
- int workingArea = OS.Screen_WorkingArea (screen);
- Monitor monitor = new Monitor ();
- monitor.x = OS.Rectangle_X (bounds);
- monitor.y = OS.Rectangle_Y (bounds);
- monitor.width = OS.Rectangle_Width (bounds);
- monitor.height = OS.Rectangle_Height (bounds);
- monitor.clientX = OS.Rectangle_X (workingArea);
- monitor.clientY = OS.Rectangle_Y (workingArea);
- monitor.clientWidth = OS.Rectangle_Width (workingArea);
- monitor.clientHeight = OS.Rectangle_Height (workingArea);
- OS.GCHandle_Free (workingArea);
- OS.GCHandle_Free (bounds);
- OS.GCHandle_Free (screen);
- return monitor;
-}
-
-/**
- * Returns a (possibly empty) array containing all shells which have
- * not been disposed and have the receiver as their display.
- *
- * @return the receiver's shells
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Shell [] getShells () {
- checkDevice ();
- if (shells == null) return new Shell [0];
- int length = 0;
- for (int i=0; i<shells.length; i++) {
- if (shells [i] != null) length++;
- }
- int index = 0;
- Shell [] result = new Shell [length];
- for (int i=0; i<shells.length; i++) {
- Shell widget = shells [i];
- if (widget != null) result [index++] = widget;
- }
- return result;
-}
-
-/**
- * Gets the synchronizer used by the display.
- *
- * @return the receiver's synchronizer
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public Synchronizer getSynchronizer () {
- checkDevice ();
- return synchronizer;
-}
-
-/**
- * Returns the thread that has invoked <code>syncExec</code>
- * or null if no such runnable is currently being invoked by
- * the user-interface thread.
- * <p>
- * Note: If a runnable invoked by asyncExec is currently
- * running, this method will return null.
- * </p>
- *
- * @return the receiver's sync-interface thread
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Thread getSyncThread () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- return synchronizer.syncThread;
- }
-}
-
-/**
- * Returns the matching standard color for the given
- * constant, which should be one of the color constants
- * specified in class <code>SWT</code>. Any value other
- * than one of the SWT color constants which is passed
- * in will result in the color black. This color should
- * not be free'd because it was allocated by the system,
- * not the application.
- *
- * @param id the color constant
- * @return the matching color
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT
- */
-public Color getSystemColor (int id) {
- checkDevice ();
- Color color = null;
- if (0 <= id && id < colors.length) {
- color = colors [id];
- }
- return color != null ? color : super.getSystemColor (id);
-}
-
-/**
- * Returns the matching standard platform cursor for the given
- * constant, which should be one of the cursor constants
- * specified in class <code>SWT</code>. This cursor should
- * not be free'd because it was allocated by the system,
- * not the application. A value of <code>null</code> will
- * be returned if the supplied constant is not an SWT cursor
- * constant.
- *
- * @param id the SWT cursor constant
- * @return the corresponding cursor or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT#CURSOR_ARROW
- * @see SWT#CURSOR_WAIT
- * @see SWT#CURSOR_CROSS
- * @see SWT#CURSOR_APPSTARTING
- * @see SWT#CURSOR_HELP
- * @see SWT#CURSOR_SIZEALL
- * @see SWT#CURSOR_SIZENESW
- * @see SWT#CURSOR_SIZENS
- * @see SWT#CURSOR_SIZENWSE
- * @see SWT#CURSOR_SIZEWE
- * @see SWT#CURSOR_SIZEN
- * @see SWT#CURSOR_SIZES
- * @see SWT#CURSOR_SIZEE
- * @see SWT#CURSOR_SIZEW
- * @see SWT#CURSOR_SIZENE
- * @see SWT#CURSOR_SIZESE
- * @see SWT#CURSOR_SIZESW
- * @see SWT#CURSOR_SIZENW
- * @see SWT#CURSOR_UPARROW
- * @see SWT#CURSOR_IBEAM
- * @see SWT#CURSOR_NO
- * @see SWT#CURSOR_HAND
- *
- * @since 3.0
- */
-public Cursor getSystemCursor (int id) {
- checkDevice ();
- if (!(0 <= id && id < cursors.length)) return null;
- if (cursors [id] == null) {
- cursors [id] = new Cursor (this, id);
- }
- return cursors [id];
-}
-
-/**
- * Returns the matching standard platform image for the given
- * constant, which should be one of the icon constants
- * specified in class <code>SWT</code>. This image should
- * not be free'd because it was allocated by the system,
- * not the application. A value of <code>null</code> will
- * be returned either if the supplied constant is not an
- * SWT icon constant or if the platform does not define an
- * image that corresponds to the constant.
- *
- * @param id the SWT icon constant
- * @return the corresponding image or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_QUESTION
- * @see SWT#ICON_WARNING
- * @see SWT#ICON_WORKING
- *
- * @since 3.0
- */
-public Image getSystemImage (int id) {
- checkDevice ();
- switch (id) {
- case SWT.ICON_ERROR: {
- if (errorImage != null) return errorImage;
- int hIcon = Win32.LoadImage (0, Win32.OIC_HAND, Win32.IMAGE_ICON, 0, 0, Win32.LR_SHARED);
- int empty = OS.Int32Rect_Empty ();
- int source = OS.Imaging_CreateBitmapSourceFromHIcon (hIcon, empty, 0);
- errorImage = Image.wpf_new (this, SWT.BITMAP, source);
- OS.GCHandle_Free (empty);
- Win32.DestroyIcon (hIcon);
- return errorImage;
- }
- case SWT.ICON_WORKING:
- case SWT.ICON_INFORMATION: {
- if (infoImage != null) return infoImage;
- int hIcon = Win32.LoadImage (0, Win32.OIC_INFORMATION, Win32.IMAGE_ICON, 0, 0, Win32.LR_SHARED);
- int empty = OS.Int32Rect_Empty ();
- int source = OS.Imaging_CreateBitmapSourceFromHIcon (hIcon, empty, 0);
- infoImage = Image.wpf_new (this, SWT.BITMAP, source);
- OS.GCHandle_Free (empty);
- Win32.DestroyIcon (hIcon);
- return infoImage;
- }
- case SWT.ICON_QUESTION: {
- if (questionImage != null) return questionImage;
- int hIcon = Win32.LoadImage (0, Win32.OIC_QUES, Win32.IMAGE_ICON, 0, 0, Win32.LR_SHARED);
- int empty = OS.Int32Rect_Empty ();
- int source = OS.Imaging_CreateBitmapSourceFromHIcon (hIcon, empty, 0);
- questionImage = Image.wpf_new (this, SWT.BITMAP, source);
- OS.GCHandle_Free (empty);
- Win32.DestroyIcon (hIcon);
- return questionImage;
- }
- case SWT.ICON_WARNING: {
- if (warningIcon != null) return warningIcon;
- int hIcon = Win32.LoadImage (0, Win32.OIC_BANG, Win32.IMAGE_ICON, 0, 0, Win32.LR_SHARED);
- int empty = OS.Int32Rect_Empty ();
- int source = OS.Imaging_CreateBitmapSourceFromHIcon (hIcon, empty, 0);
- warningIcon = Image.wpf_new (this, SWT.BITMAP, source);
- OS.GCHandle_Free (empty);
- Win32.DestroyIcon (hIcon);
- return warningIcon;
- }
- }
- return null;
-}
-
-/**
- * Returns the single instance of the system tray or null
- * when there is no system tray available for the platform.
- *
- * @return the system tray or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- */
-public Tray getSystemTray () {
- checkDevice ();
- if (tray != null) return tray;
- tray = new Tray (this, SWT.NONE);
- return tray;
-}
-
-/**
- * Returns the user-interface thread for the receiver.
- *
- * @return the receiver's user-interface thread
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Thread getThread () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- return thread;
- }
-}
-
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Display</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for gc creation</li>
- * </ul>
- */
-public int internal_new_GC (GCData data) {
- if (isDisposed()) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
- //TODO - for now, return a drawing context that can measure text
- if (data == null) return 0;
- int visual = OS.gcnew_DrawingVisual();
- if (visual == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int dc = OS.DrawingVisual_RenderOpen (visual);
- if (dc == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- data.visual = visual;
- data.font = getSystemFont ();
- return dc;
-}
-
-/**
- * Initializes any internal resources needed by the
- * device.
- * <p>
- * This method is called after <code>create</code>.
- * </p>
- *
- * @see #create
- */
-protected void init () {
- super.init ();
-
- dispatcher = OS.Application_Dispatcher (application);
- if (dispatcher == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- frame = OS.gcnew_DispatcherFrame ();
- if (frame == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- jniRef = OS.NewGlobalRef (this);
- if (jniRef == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- int hooks = OS.Dispatcher_Hooks (dispatcher);
- int handler = OS.gcnew_EventHandler (jniRef, "HandleDispatcherInactive");
- OS.DispatcherHooks_DispatcherInactive (hooks, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_DispatcherHookEventHandler (jniRef, "HandleOperationCompleted");
- OS.DispatcherHooks_OperationCompleted (hooks, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_DispatcherHookEventHandler (jniRef, "HandleOperationPosted");
- OS.DispatcherHooks_OperationPosted (hooks, handler);
- OS.GCHandle_Free (handler);
- OS.GCHandle_Free (hooks);
- timerHandler = OS.gcnew_TimerHandler(jniRef, "timerProc");
-
-
- /* Create the standard colors */
- colors = new Color [SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT + 1];
- colors [SWT.COLOR_WIDGET_DARK_SHADOW] = Color.wpf_new( this, OS.SystemColors_ControlDarkDarkColor ());
- colors [SWT.COLOR_WIDGET_NORMAL_SHADOW] = Color.wpf_new (this, OS.SystemColors_ControlDarkColor ());
- colors [SWT.COLOR_WIDGET_LIGHT_SHADOW] = Color.wpf_new (this, OS.SystemColors_ControlLightColor ());
- colors [SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW] = Color.wpf_new (this, OS.SystemColors_ControlLightLightColor ());
- colors [SWT.COLOR_WIDGET_FOREGROUND] = Color.wpf_new (this, OS.SystemColors_ControlTextColor ());
- colors [SWT.COLOR_WIDGET_BACKGROUND] = Color.wpf_new (this, OS.SystemColors_ControlColor ());
- colors [SWT.COLOR_WIDGET_BORDER] = Color.wpf_new (this, OS.SystemColors_ActiveBorderColor ());
- colors [SWT.COLOR_LIST_FOREGROUND] = Color.wpf_new (this, OS.SystemColors_WindowTextColor ());
- colors [SWT.COLOR_LIST_BACKGROUND] = Color.wpf_new (this, OS.SystemColors_WindowColor ());
- colors [SWT.COLOR_LIST_SELECTION] = Color.wpf_new (this, OS.SystemColors_HighlightColor ());
- colors [SWT.COLOR_LIST_SELECTION_TEXT] = Color.wpf_new (this, OS.SystemColors_HighlightTextColor ());
- colors [SWT.COLOR_INFO_FOREGROUND] = Color.wpf_new (this, OS.SystemColors_InfoTextColor ());
- colors [SWT.COLOR_INFO_BACKGROUND] = Color.wpf_new (this, OS.SystemColors_InfoColor ());
- colors [SWT.COLOR_TITLE_FOREGROUND] = Color.wpf_new (this, OS.SystemColors_ActiveCaptionTextColor ());
- colors [SWT.COLOR_TITLE_BACKGROUND] = Color.wpf_new (this, OS.SystemColors_ActiveCaptionColor ());
- colors [SWT.COLOR_TITLE_BACKGROUND_GRADIENT] = Color.wpf_new (this, OS.SystemColors_GradientActiveCaptionColor ());
- colors [SWT.COLOR_TITLE_INACTIVE_FOREGROUND] = Color.wpf_new (this, OS.SystemColors_InactiveCaptionTextColor ());
- colors [SWT.COLOR_TITLE_INACTIVE_BACKGROUND] = Color.wpf_new (this, OS.SystemColors_InactiveCaptionColor ());
- colors [SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT] = Color.wpf_new (this, OS.SystemColors_GradientInactiveCaptionColor ());
-
-}
-
-void invalidateHandler () {
- invalidateHandler = 0;
- if (invalidate != null) {
- Control[] invalidate = this.invalidate;
- this.invalidate = null;
- for (int i = 0; i < invalidate.length; i++) {
- Control control = invalidate [i];
- if (control != null && !control.isDisposed()) {
- control.redraw (true);
- }
- }
- }
-}
-
-void HandleDispatcherInactive (int sender, int e) {
- if (runAsyncMessages (false)) wakeThread ();
-}
-
-void HandleOperationCompleted (int sender, int e) {
- if (operation != 0) {
- int current = OS.DispatcherHookEventArgs_Operation(e);
- int priority = OS.DispatcherOperation_Priority(current);
- if (priority == 5) OS.DispatcherOperation_Abort(operation);
- OS.GCHandle_Free(current);
- }
-}
-
-void HandleOperationPosted (int sender, int e) {
- if (sleepOperation != 0) OS.DispatcherOperation_Priority(sleepOperation, OS.DispatcherPriority_Send);
-}
-
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Display</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param hDC the platform specific GC handle
- * @param data the platform specific GC data
- */
-public void internal_dispose_GC (int dc, GCData data) {
- //TODO - the wrong drawing context was created
- if (data != null && data.drawingContext == 0) {
- OS.DrawingContext_Close (dc);
- OS.GCHandle_Free (dc);
- OS.GCHandle_Free (data.visual);
- }
-}
-
-boolean isValidThread () {
- return thread == Thread.currentThread ();
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param point to be mapped
- * @return point with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Point map (Control from, Control to, Point point) {
- checkDevice ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return map (from, to, point.x, point.y);
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param x coordinates to be mapped
- * @param y coordinates to be mapped
- * @return point with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Point map (Control from, Control to, int x, int y) {
- checkDevice ();
- if (from != null && from.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (to != null && to.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (from == to) return new Point (x, y);
- int newX, newY;
- if (from != null && to != null) {
- int point = OS.gcnew_Point (x, y);
- int newPoint = OS.UIElement_TranslatePoint (from.handle, point, to.handle);
- newX = (int) (OS.Point_X (newPoint) + 0.5);
- newY = (int) (OS.Point_Y (newPoint) + 0.5);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (newPoint);
- } else {
- if (from == null) {
- int toHandle = to.handle;
- to.updateLayout (toHandle);
- int source = OS.PresentationSource_FromVisual (toHandle);
- int window = OS.PresentationSource_RootVisual (source);
- OS.GCHandle_Free (source);
- int point = OS.gcnew_Point (x, y);
- int temp = OS.Visual_PointFromScreen (window, point);
- int newPoint = OS.UIElement_TranslatePoint (window, temp, toHandle);
- newX = (int) OS.Point_X (newPoint);
- newY = (int) OS.Point_Y (newPoint);
- OS.GCHandle_Free (temp);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (newPoint);
- OS.GCHandle_Free (window);
- } else {
- int fromHandle = from.handle;
- from.updateLayout (fromHandle);
- int source = OS.PresentationSource_FromVisual (fromHandle);
- int window = OS.PresentationSource_RootVisual (source);
- OS.GCHandle_Free (source);
- int point = OS.gcnew_Point (x, y);
- int temp = OS.UIElement_TranslatePoint (fromHandle, point, window);
- int newPoint = OS.Visual_PointToScreen (window, temp);
- newX = (int) OS.Point_X (newPoint);
- newY = (int) OS.Point_Y (newPoint);
- OS.GCHandle_Free (temp);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (newPoint);
- OS.GCHandle_Free (window);
- }
- }
- return new Point (newX, newY);
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param rectangle to be mapped
- * @return rectangle with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Rectangle map (Control from, Control to, Rectangle rectangle) {
- checkDevice ();
- if (rectangle == null) error (SWT.ERROR_NULL_ARGUMENT);
- return map (from, to, rectangle.x, rectangle.y, rectangle.width, rectangle.height);
-}
-
-/**
- * Maps a point from one coordinate system to another.
- * When the control is null, coordinates are mapped to
- * the display.
- * <p>
- * NOTE: On right-to-left platforms where the coordinate
- * systems are mirrored, special care needs to be taken
- * when mapping coordinates from one control to another
- * to ensure the result is correctly mirrored.
- *
- * Mapping a point that is the origin of a rectangle and
- * then adding the width and height is not equivalent to
- * mapping the rectangle. When one control is mirrored
- * and the other is not, adding the width and height to a
- * point that was mapped causes the rectangle to extend
- * in the wrong direction. Mapping the entire rectangle
- * instead of just one point causes both the origin and
- * the corner of the rectangle to be mapped.
- * </p>
- *
- * @param from the source <code>Control</code> or <code>null</code>
- * @param to the destination <code>Control</code> or <code>null</code>
- * @param x coordinates to be mapped
- * @param y coordinates to be mapped
- * @param width coordinates to be mapped
- * @param height coordinates to be mapped
- * @return rectangle with mapped coordinates
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public Rectangle map (Control from, Control to, int x, int y, int width, int height) {
- checkDevice ();
- if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (from == to) return new Rectangle (x, y, width, height);
- //TODO
- Point point = map (from, to, x, y);
- return new Rectangle (point.x, point.y, width, height);
-}
-
-/**
- * Generate a low level system event.
- *
- * <code>post</code> is used to generate low level keyboard
- * and mouse events. The intent is to enable automated UI
- * testing by simulating the input from the user. Most
- * SWT applications should never need to call this method.
- * <p>
- * Note that this operation can fail when the operating system
- * fails to generate the event for any reason. For example,
- * this can happen when there is no such key or mouse button
- * or when the system event queue is full.
- * </p>
- * <p>
- * <b>Event Types:</b>
- * <p>KeyDown, KeyUp
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type KeyDown or KeyUp</li>
- * <p> Either one of:
- * <li>(in) character a character that corresponds to a keyboard key</li>
- * <li>(in) keyCode the key code of the key that was typed,
- * as defined by the key code constants in class <code>SWT</code></li>
- * </ul>
- * <p>MouseDown, MouseUp</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseDown or MouseUp
- * <li>(in) button the button that is pressed or released
- * </ul>
- * <p>MouseMove</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseMove
- * <li>(in) x the x coordinate to move the mouse pointer to in screen coordinates
- * <li>(in) y the y coordinate to move the mouse pointer to in screen coordinates
- * </ul>
- * <p>MouseWheel</p>
- * <p>The following fields in the <code>Event</code> apply:
- * <ul>
- * <li>(in) type MouseWheel
- * <li>(in) detail either SWT.SCROLL_LINE or SWT.SCROLL_PAGE
- * <li>(in) count the number of lines or pages to scroll
- * </ul>
- * </dl>
- *
- * @param event the event to be generated
- *
- * @return true if the event was generated or false otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public boolean post (Event event) {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
-// int type = event.type;
-// switch (type){
-// case SWT.KeyDown:
-// case SWT.KeyUp: {
-// KEYBDINPUT inputs = new KEYBDINPUT ();
-// inputs.wVk = (short) untranslateKey (event.keyCode);
-// if (inputs.wVk == 0) {
-// char key = event.character;
-// switch (key) {
-// case SWT.BS: inputs.wVk = (short) OS.VK_BACK; break;
-// case SWT.CR: inputs.wVk = (short) OS.VK_RETURN; break;
-// case SWT.DEL: inputs.wVk = (short) OS.VK_DELETE; break;
-// case SWT.ESC: inputs.wVk = (short) OS.VK_ESCAPE; break;
-// case SWT.TAB: inputs.wVk = (short) OS.VK_TAB; break;
-// /*
-// * Since there is no LF key on the keyboard, do not attempt
-// * to map LF to CR or attempt to post an LF key.
-// */
-// // case SWT.LF: inputs.wVk = (short) OS.VK_RETURN; break;
-// case SWT.LF: return false;
-// default: {
-// if (OS.IsWinCE) {
-// inputs.wVk = OS.CharUpper ((short) key);
-// } else {
-// inputs.wVk = OS.VkKeyScan ((short) wcsToMbcs (key, 0));
-// if (inputs.wVk == -1) return false;
-// inputs.wVk &= 0xFF;
-// }
-// }
-// }
-// }
-// inputs.dwFlags = type == SWT.KeyUp ? OS.KEYEVENTF_KEYUP : 0;
-// int hHeap = OS.GetProcessHeap ();
-// int pInputs = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, INPUT.sizeof);
-// OS.MoveMemory(pInputs, new int[] {OS.INPUT_KEYBOARD}, 4);
-// OS.MoveMemory (pInputs + 4, inputs, KEYBDINPUT.sizeof);
-// boolean result = OS.SendInput (1, pInputs, INPUT.sizeof) != 0;
-// OS.HeapFree (hHeap, 0, pInputs);
-// return result;
-// }
-// case SWT.MouseDown:
-// case SWT.MouseMove:
-// case SWT.MouseUp: {
-// MOUSEINPUT inputs = new MOUSEINPUT ();
-// if (type == SWT.MouseMove){
-// inputs.dwFlags = OS.MOUSEEVENTF_MOVE | OS.MOUSEEVENTF_ABSOLUTE;
-// inputs.dx = event.x * 65535 / (OS.GetSystemMetrics (OS.SM_CXSCREEN) - 1);
-// inputs.dy = event.y * 65535 / (OS.GetSystemMetrics (OS.SM_CYSCREEN) - 1);
-// } else {
-// switch (event.button) {
-// case 1: inputs.dwFlags = type == SWT.MouseDown ? OS.MOUSEEVENTF_LEFTDOWN : OS.MOUSEEVENTF_LEFTUP; break;
-// case 2: inputs.dwFlags = type == SWT.MouseDown ? OS.MOUSEEVENTF_MIDDLEDOWN : OS.MOUSEEVENTF_MIDDLEUP; break;
-// case 3: inputs.dwFlags = type == SWT.MouseDown ? OS.MOUSEEVENTF_RIGHTDOWN : OS.MOUSEEVENTF_RIGHTUP; break;
-// default: return false;
-// }
-// }
-// int hHeap = OS.GetProcessHeap ();
-// int pInputs = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, INPUT.sizeof);
-// OS.MoveMemory(pInputs, new int[] {OS.INPUT_MOUSE}, 4);
-// OS.MoveMemory (pInputs + 4, inputs, MOUSEINPUT.sizeof);
-// boolean result = OS.SendInput (1, pInputs, INPUT.sizeof) != 0;
-// OS.HeapFree (hHeap, 0, pInputs);
-// return result;
-// }
-// }
- return false;
- }
-}
-
-void postEvent (Event event) {
- /*
- * Place the event at the end of the event queue.
- * This code is always called in the Display's
- * thread so it must be re-enterant but does not
- * need to be synchronized.
- */
- if (eventQueue == null) eventQueue = new Event [4];
- int index = 0;
- int length = eventQueue.length;
- while (index < length) {
- if (eventQueue [index] == null) break;
- index++;
- }
- if (index == length) {
- Event [] newQueue = new Event [length + 4];
- System.arraycopy (eventQueue, 0, newQueue, 0, length);
- eventQueue = newQueue;
- }
- eventQueue [index] = event;
-}
-
-void removePopup (Menu menu) {
- if (popups == null) return;
- for (int i=0; i<popups.length; i++) {
- if (popups [i] == menu) {
- popups [i] = null;
- return;
- }
- }
-}
-
-void removeShell (Shell shell) {
- if (shells == null) return;
- for (int i=0; i<shells.length; i++) {
- if (shells [i] == shell) {
- shells [i] = null;
- return;
- }
- }
-}
-
-/**
- * Reads an event from the operating system's event queue,
- * dispatches it appropriately, and returns <code>true</code>
- * if there is potentially more work to do, or <code>false</code>
- * if the caller can sleep until another event is placed on
- * the event queue.
- * <p>
- * In addition to checking the system event queue, this method also
- * checks if any inter-thread messages (created by <code>syncExec()</code>
- * or <code>asyncExec()</code>) are waiting to be processed, and if
- * so handles them before returning.
- * </p>
- *
- * @return <code>false</code> if the caller can sleep upon return from this method
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li>
- * </ul>
- *
- * @see #sleep
- * @see #wake
- */
-public boolean readAndDispatch () {
- checkDevice ();
- runPopups ();
- idle = false;
- int handler = OS.gcnew_NoArgsDelegate(jniRef, "setIdleHandler");
- operation = OS.Dispatcher_BeginInvoke(dispatcher, 2, handler);
- OS.DispatcherOperation_Wait(operation);
- OS.GCHandle_Free(handler);
- OS.GCHandle_Free(operation);
- operation = 0;
- if (!idle) {
- runDeferredEvents();
- return true;
- }
- return isDisposed () || runAsyncMessages(false);
-}
-
-static void register (Display display) {
- synchronized (Device.class) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] == null) {
- Displays [i] = display;
- return;
- }
- }
- Display [] newDisplays = new Display [Displays.length + 4];
- System.arraycopy (Displays, 0, newDisplays, 0, Displays.length);
- newDisplays [Displays.length] = display;
- Displays = newDisplays;
- }
-}
-
-/**
- * Releases any internal resources back to the operating
- * system and clears all fields except the device handle.
- * <p>
- * Disposes all shells which are currently open on the display.
- * After this method has been invoked, all related related shells
- * will answer <code>true</code> when sent the message
- * <code>isDisposed()</code>.
- * </p><p>
- * When a device is destroyed, resources that were acquired
- * on behalf of the programmer need to be returned to the
- * operating system. For example, if the device allocated a
- * font to be used as the system font, this font would be
- * freed in <code>release</code>. Also,to assist the garbage
- * collector and minimize the amount of memory that is not
- * reclaimed when the programmer keeps a reference to a
- * disposed device, all fields except the handle are zero'd.
- * The handle is needed by <code>destroy</code>.
- * </p>
- * This method is called before <code>destroy</code>.
- *
- * @see Device#dispose
- * @see #destroy
- */
-protected void release () {
- sendEvent (SWT.Dispose, new Event ());
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) shell.dispose ();
- }
- if (tray != null) tray.dispose ();
- tray = null;
-
- //hack... readAndDispatch Always returns true right now, prevents apps from shutting down.
- //while (readAndDispatch ()) {}
-
- if (disposeList != null) {
- for (int i=0; i<disposeList.length; i++) {
- if (disposeList [i] != null) disposeList [i].run ();
- }
- }
- disposeList = null;
- synchronizer.releaseSynchronizer ();
- synchronizer = null;
- releaseDisplay ();
- super.release ();
-}
-
-void releaseDisplay () {
- /* Release the timers */
- OS.GCHandle_Free (timerHandler);
- timerHandler = 0;
- if (timerHandles != null) {
- for (int i = 0; i < timerHandles.length; i++) {
- int timer = timerHandles [i];
- if (timer != 0) {
- OS.DispatcherTimer_Stop (timer);
- OS.GCHandle_Free (timer);
- }
- }
- }
- timerHandles = null;
- timerList = null;
- if (nameScope != 0) OS.GCHandle_Free (nameScope);
- nameScope = 0;
- if (application != 0) {
- OS.Application_Shutdown (application);
- OS.GCHandle_Free (application);
- }
- application = 0;
- if (dispatcher != 0) OS.GCHandle_Free (dispatcher);
- dispatcher = 0;
- if (frame != 0) OS.GCHandle_Free (frame);
- frame = 0;
- if (jniRef != 0) OS.DeleteGlobalRef (jniRef);
- jniRef = 0;
-
- for (int i = 0; i < colors.length; i++) {
- if (colors [i] != null) colors [i].dispose ();
- }
- colors = null;
-
-// /* Release the System fonts */
-// if (systemFont != null) systemFont.dispose ();
-// systemFont = null;
-// lfSystemFont = null;
-
- /* Release the System Images */
- if (errorImage != null) errorImage.dispose ();
- if (infoImage != null) infoImage.dispose ();
- if (questionImage != null) questionImage.dispose ();
- if (warningIcon != null) warningIcon.dispose ();
- errorImage = infoImage = questionImage = warningIcon = null;
-
- /* Release the System Cursors */
- for (int i = 0; i < cursors.length; i++) {
- if (cursors [i] != null) cursors [i].dispose ();
- }
- cursors = null;
-
-// /* Release Acquired Resources */
-// if (resources != null) {
-// for (int i=0; i<resources.length; i++) {
-// if (resources [i] != null) resources [i].dispose ();
-// }
-// resources = null;
-// }
-//
- /* Release Custom Colors for ChooseColor */
- if (customColors != 0) OS.GCHandle_Free (customColors);
- customColors = 0;
-
- /* Release references */
- thread = null;
-// modalDialogShell = null;
- modalShells = null;
- data = null;
- keys = null;
- values = null;
- popups = null;
- mouseControl = null;
- shells = null;
- eventTable = filterTable = null;
-
- /* Uninitialize OLE */
- Win32.OleUninitialize ();
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs anywhere in
- * a widget. The event type is one of the event constants defined
- * in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addFilter
- * @see #addListener
- *
- * @since 3.0
- */
-public void removeFilter (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (filterTable == null) return;
- filterTable.unhook (eventType, listener);
- if (filterTable.size () == 0) filterTable = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs. The event type
- * is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener
- *
- * @since 2.0
- */
-public void removeListener (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, listener);
-}
-
-Widget removeWidget (int handle) {
- if (handle == 0) return null;
- int tag = OS.FrameworkElement_Tag (handle), ref = 0;
- if (tag != 0) {
- ref = OS.IntPtr_ToInt32(tag);
- OS.GCHandle_Free(tag);
- }
- Widget widget = null;
- if (ref != 0) {
- OS.FrameworkElement_Tag (handle, 0);
- widget = (Widget) OS.JNIGetObject (ref);
- }
- return widget;
-}
-
-boolean runAsyncMessages (boolean all) {
- return synchronizer.runAsyncMessages (all);
-}
-
-boolean runDeferredEvents () {
- boolean run = false;
- /*
- * Run deferred events. This code is always
- * called in the Display's thread so it must
- * be re-enterant but need not be synchronized.
- */
- while (eventQueue != null) {
-
- /* Take an event off the queue */
- Event event = eventQueue [0];
- if (event == null) break;
- int length = eventQueue.length;
- System.arraycopy (eventQueue, 1, eventQueue, 0, --length);
- eventQueue [length] = null;
-
- /* Run the event */
- Widget widget = event.widget;
- if (widget != null && !widget.isDisposed ()) {
- Widget item = event.item;
- if (item == null || !item.isDisposed ()) {
- run = true;
- widget.sendEvent (event);
- }
- }
-
- /*
- * At this point, the event queue could
- * be null due to a recursive invokation
- * when running the event.
- */
- }
-
- /* Clear the queue */
- eventQueue = null;
- return run;
-}
-
-boolean runPopups () {
- if (popups == null) return false;
- boolean result = false;
- while (popups != null) {
- Menu menu = popups [0];
- if (menu == null) break;
- int length = popups.length;
- System.arraycopy (popups, 1, popups, 0, --length);
- popups [length] = null;
- runDeferredEvents ();
- if (!menu.isDisposed()) menu._setVisible (true);
- result = true;
- }
- popups = null;
- return result;
-}
-
-void runSettings () {
- Font oldFont = getSystemFont ();
- saveResources ();
-// updateImages ();
- sendEvent (SWT.Settings, null);
- Font newFont = getSystemFont ();
- boolean sameFont = oldFont.equals (newFont);
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) {
- if (!sameFont) {
- shell.updateFont (oldFont, newFont);
- }
- /* This code is intentionally commented */
- //shell.redraw (true);
- shell.layout (true, true);
- }
- }
-}
-
-void saveResources () {
-// int resourceCount = 0;
-// if (resources == null) {
-// resources = new Resource [RESOURCE_SIZE];
-// } else {
-// resourceCount = resources.length;
-// Resource [] newResources = new Resource [resourceCount + RESOURCE_SIZE];
-// System.arraycopy (resources, 0, newResources, 0, resourceCount);
-// resources = newResources;
-// }
-// if (systemFont != null) {
-// if (!OS.IsWinCE) {
-// NONCLIENTMETRICS info = OS.IsUnicode ? (NONCLIENTMETRICS) new NONCLIENTMETRICSW () : new NONCLIENTMETRICSA ();
-// info.cbSize = NONCLIENTMETRICS.sizeof;
-// if (OS.SystemParametersInfo (OS.SPI_GETNONCLIENTMETRICS, 0, info, 0)) {
-// LOGFONT logFont = OS.IsUnicode ? (LOGFONT) ((NONCLIENTMETRICSW)info).lfMessageFont : ((NONCLIENTMETRICSA)info).lfMessageFont;
-// if (lfSystemFont == null ||
-// logFont.lfCharSet != lfSystemFont.lfCharSet ||
-// logFont.lfHeight != lfSystemFont.lfHeight ||
-// logFont.lfWidth != lfSystemFont.lfWidth ||
-// logFont.lfEscapement != lfSystemFont.lfEscapement ||
-// logFont.lfOrientation != lfSystemFont.lfOrientation ||
-// logFont.lfWeight != lfSystemFont.lfWeight ||
-// logFont.lfItalic != lfSystemFont.lfItalic ||
-// logFont.lfUnderline != lfSystemFont.lfUnderline ||
-// logFont.lfStrikeOut != lfSystemFont.lfStrikeOut ||
-// logFont.lfCharSet != lfSystemFont.lfCharSet ||
-// logFont.lfOutPrecision != lfSystemFont.lfOutPrecision ||
-// logFont.lfClipPrecision != lfSystemFont.lfClipPrecision ||
-// logFont.lfQuality != lfSystemFont.lfQuality ||
-// logFont.lfPitchAndFamily != lfSystemFont.lfPitchAndFamily ||
-// !getFontName (logFont).equals (getFontName (lfSystemFont))) {
-// resources [resourceCount++] = systemFont;
-// lfSystemFont = logFont;
-// systemFont = null;
-// }
-// }
-// }
-// }
-// if (errorImage != null) resources [resourceCount++] = errorImage;
-// if (infoImage != null) resources [resourceCount++] = infoImage;
-// if (questionImage != null) resources [resourceCount++] = questionImage;
-// if (warningIcon != null) resources [resourceCount++] = warningIcon;
-// errorImage = infoImage = questionImage = warningIcon = null;
-// for (int i=0; i<cursors.length; i++) {
-// if (cursors [i] != null) resources [resourceCount++] = cursors [i];
-// cursors [i] = null;
-// }
-// if (resourceCount < RESOURCE_SIZE) {
-// Resource [] newResources = new Resource [resourceCount];
-// System.arraycopy (resources, 0, newResources, 0, resourceCount);
-// resources = newResources;
-// }
-}
-
-void sendEvent (int eventType, Event event) {
- if (eventTable == null && filterTable == null) {
- return;
- }
- if (event == null) event = new Event ();
- event.display = this;
- event.type = eventType;
- if (event.time == 0) event.time = getLastEventTime ();
- if (!filterEvent (event)) {
- if (eventTable != null) eventTable.sendEvent (event);
- }
-}
-
-/**
- * Sets the location of the on-screen pointer relative to the top left corner
- * of the screen. <b>Note: It is typically considered bad practice for a
- * program to move the on-screen pointer location.</b>
- *
- * @param x the new x coordinate for the cursor
- * @param y the new y coordinate for the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.1
- */
-public void setCursorLocation (int x, int y) {
- checkDevice ();
- Win32.SetCursorPos (x, y);
-}
-
-/**
- * Sets the location of the on-screen pointer relative to the top left corner
- * of the screen. <b>Note: It is typically considered bad practice for a
- * program to move the on-screen pointer location.</b>
- *
- * @param point new position
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_NULL_ARGUMENT - if the point is null
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setCursorLocation (Point point) {
- checkDevice ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- setCursorLocation (point.x, point.y);
-}
-
-/**
- * Sets the application defined property of the receiver
- * with the specified name to the given argument.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the display is disposed
- * of, it is the application's responsibility provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param key the name of the property
- * @param value the new value for the property
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getData(String)
- * @see #disposeExec(Runnable)
- */
-public void setData (String key, Object value) {
- checkDevice ();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
-
-// if (key.equals (RUN_MESSAGES_IN_IDLE_KEY)) {
-// Boolean data = (Boolean) value;
-// runMessagesInIdle = data != null && data.booleanValue ();
-// return;
-// }
-
- /* Remove the key/value pair */
- if (value == null) {
- if (keys == null) return;
- int index = 0;
- while (index < keys.length && !keys [index].equals (key)) index++;
- if (index == keys.length) return;
- if (keys.length == 1) {
- keys = null;
- values = null;
- } else {
- String [] newKeys = new String [keys.length - 1];
- Object [] newValues = new Object [values.length - 1];
- System.arraycopy (keys, 0, newKeys, 0, index);
- System.arraycopy (keys, index + 1, newKeys, index, newKeys.length - index);
- System.arraycopy (values, 0, newValues, 0, index);
- System.arraycopy (values, index + 1, newValues, index, newValues.length - index);
- keys = newKeys;
- values = newValues;
- }
- return;
- }
-
- /* Add the key/value pair */
- if (keys == null) {
- keys = new String [] {key};
- values = new Object [] {value};
- return;
- }
- for (int i=0; i<keys.length; i++) {
- if (keys [i].equals (key)) {
- values [i] = value;
- return;
- }
- }
- String [] newKeys = new String [keys.length + 1];
- Object [] newValues = new Object [values.length + 1];
- System.arraycopy (keys, 0, newKeys, 0, keys.length);
- System.arraycopy (values, 0, newValues, 0, values.length);
- newKeys [keys.length] = key;
- newValues [values.length] = value;
- keys = newKeys;
- values = newValues;
-}
-
-/**
- * Sets the application defined, display specific data
- * associated with the receiver, to the argument.
- * The <em>display specific data</em> is a single,
- * unnamed field that is stored with every display.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the display specific data needs to
- * be notified when the display is disposed of, it is the
- * application's responsibility provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param data the new display specific data
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #getData()
- * @see #disposeExec(Runnable)
- */
-public void setData (Object data) {
- checkDevice ();
- this.data = data;
-}
-
-/**
- * On platforms which support it, sets the application name
- * to be the argument. On Motif, for example, this can be used
- * to set the name used for resource lookup. Specifying
- * <code>null</code> for the name clears it.
- *
- * @param name the new app name or <code>null</code>
- */
-public static void setAppName (String name) {
- /* Do nothing */
-}
-
-//void setModalDialogShell (Shell modalDailog) {
-// if (modalDialogShell != null && modalDialogShell.isDisposed ()) modalDialogShell = null;
-// this.modalDialogShell = modalDailog;
-// Shell [] shells = getShells ();
-// for (int i=0; i<shells.length; i++) shells [i].updateModal ();
-//}
-
-void setIdleHandler () {
- idle = true;
-}
-
-void setModalShell (Shell shell) {
- if (modalShells == null) modalShells = new Shell [4];
- int index = 0, length = modalShells.length;
- while (index < length) {
- if (modalShells [index] == shell) return;
- if (modalShells [index] == null) break;
- index++;
- }
- if (index == length) {
- Shell [] newModalShells = new Shell [length + 4];
- System.arraycopy (modalShells, 0, newModalShells, 0, length);
- modalShells = newModalShells;
- }
- modalShells [index] = shell;
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) shells [i].updateModal ();
-}
-
-/**
- * Sets the synchronizer used by the display to be
- * the argument, which can not be null.
- *
- * @param synchronizer the new synchronizer for the display (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the synchronizer is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li>
- * </ul>
- */
-public void setSynchronizer (Synchronizer synchronizer) {
- checkDevice ();
- if (synchronizer == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (synchronizer == this.synchronizer) return;
- Synchronizer oldSynchronizer;
- synchronized (Device.class) {
- oldSynchronizer = this.synchronizer;
- this.synchronizer = synchronizer;
- }
- if (oldSynchronizer != null) {
- oldSynchronizer.runAsyncMessages(true);
- }
-}
-
-/**
- * Causes the user-interface thread to <em>sleep</em> (that is,
- * to be put in a state where it does not consume CPU cycles)
- * until an event is received or it is otherwise awakened.
- *
- * @return <code>true</code> if an event requiring dispatching was placed on the queue.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #wake
- */
-public boolean sleep () {
- checkDevice ();
- int handler = OS.gcnew_NoArgsDelegate (jniRef, "sleep_noop");
- sleepOperation = OS.Dispatcher_BeginInvoke(dispatcher, OS.DispatcherPriority_Inactive, handler);
- OS.DispatcherOperation_Wait(sleepOperation);
- OS.GCHandle_Free(handler);
- OS.GCHandle_Free(sleepOperation);
- sleepOperation = 0;
- return true;
-}
-
-void sleep_noop() {
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread at the next
- * reasonable opportunity. The thread which calls this method
- * is suspended until the runnable completes. Specifying <code>null</code>
- * as the runnable simply wakes the user-interface thread.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param runnable code to run on the user-interface thread or <code>null</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_FAILED_EXEC - if an exception occurred when executing the runnable</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #asyncExec
- */
-public void syncExec (Runnable runnable) {
- Synchronizer synchronizer;
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- synchronizer = this.synchronizer;
- }
- synchronizer.syncExec (runnable);
-}
-
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread after the specified
- * number of milliseconds have elapsed. If milliseconds is less
- * than zero, the runnable is not executed.
- * <p>
- * Note that at the time the runnable is invoked, widgets
- * that have the receiver as their display may have been
- * disposed. Therefore, it is necessary to check for this
- * case inside the runnable before accessing the widget.
- * </p>
- *
- * @param milliseconds the delay before running the runnable
- * @param runnable code to run on the user-interface thread
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #asyncExec
- */
-public void timerExec (int milliseconds, Runnable runnable) {
- checkDevice ();
- if (runnable == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (timerList == null) timerList = new Runnable [4];
- if (timerHandles == null) timerHandles = new int [4];
- int index = 0;
- while (index < timerList.length) {
- if (timerList [index] == runnable) break;
- index++;
- }
- int timer = 0;
- if (index != timerList.length) {
- timer = timerHandles [index];
- if (milliseconds < 0) {
- OS.DispatcherTimer_Stop (timer);
- timerList [index] = null;
- OS.GCHandle_Free (timer);
- timerHandles [index] = 0;
- return;
- }
- } else {
- if (milliseconds < 0) return;
- index = 0;
- while (index < timerList.length) {
- if (timerList [index] == null) break;
- index++;
- }
- if (index == timerList.length) {
- Runnable [] newTimerList = new Runnable [timerList.length + 4];
- System.arraycopy (timerList, 0, newTimerList, 0, timerList.length);
- timerList = newTimerList;
- int [] newTimerHandles = new int [timerHandles.length + 4];
- System.arraycopy (timerHandles, 0, newTimerHandles, 0, timerHandles.length);
- timerHandles = newTimerHandles;
- }
- }
- if (timer == 0) timer = OS.gcnew_DispatcherTimer();
- if (timer != 0) {
- OS.DispatcherTimer_Tag (timer, index);
- int timeSpan = OS.TimeSpan_FromMilliseconds (milliseconds);
- OS.DispatcherTimer_Interval(timer, timeSpan);
- OS.DispatcherTimer_Tick (timer, timerHandler);
- OS.DispatcherTimer_Start (timer);
- timerList [index] = runnable;
- timerHandles [index] = timer;
- OS.GCHandle_Free (timeSpan);
- }
-}
-
-void timerProc (int index, int e) {
- if (0 <= index && index < timerHandles.length) {
- int timer = timerHandles [index];
- if (timer != 0) {
- OS.DispatcherTimer_Stop (timer);
- OS.GCHandle_Free (timer);
- timerHandles [index] = 0;
- Runnable runnable = timerList [index];
- timerList [index] = null;
- runnable.run ();
- }
- }
-}
-
-static int translateKey (int key) {
- for (int i=0; i<KeyTable.length; i++) {
- if (KeyTable [i] [0] == key) return KeyTable [i] [1];
- }
- return 0;
-}
-
-static int untranslateKey (int key) {
- for (int i=0; i<KeyTable.length; i++) {
- if (KeyTable [i] [1] == key) return KeyTable [i] [0];
- }
- return 0;
-}
-
-/**
- * Forces all outstanding paint requests for the display
- * to be processed before this method returns.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see Control#update()
- */
-public void update() {
- checkDevice ();
- Shell[] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) shell.update (true);
- }
-}
-
-/**
- * If the receiver's user-interface thread was <code>sleep</code>ing,
- * causes it to be awakened and start running again. Note that this
- * method may be called from any thread.
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #sleep
- */
-public void wake () {
- synchronized (Device.class) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- if (thread == Thread.currentThread ()) return;
- wakeThread ();
- }
-}
-
-void wakeThreadHandler () {
-}
-
-void wakeThread () {
- int handler = OS.gcnew_NoArgsDelegate (jniRef, "wakeThreadHandler");
- int operation = OS.Dispatcher_BeginInvoke (dispatcher, OS.DispatcherPriority_Normal, handler);
- OS.GCHandle_Free (operation);
- OS.GCHandle_Free (handler);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ExpandBar.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ExpandBar.java
deleted file mode 100644
index b6cfac15bc..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ExpandBar.java
+++ /dev/null
@@ -1,459 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class support the layout of selectable
- * expand bar items.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>ExpandItem</code>.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>V_SCROLL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Expand, Collapse</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see ExpandItem
- * @see ExpandEvent
- * @see ExpandListener
- * @see ExpandAdapter
- * @see <a href="http://www.eclipse.org/swt/snippets/#expandbar">ExpandBar snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.2
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ExpandBar extends Composite {
- int parentingHandle;
- Control [] children;
- int itemCount, childCount;
- int spacing;
-
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#V_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ExpandBar (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-Control [] _getChildren () {
- // return children in reverse order.
- Control[] result = new Control [childCount];
- for (int i = 0; i < childCount; i++) {
- result [childCount - i - 1] = children [i];
- }
- return result;
-}
-
-void addChild (Control control) {
- super.addChild (control);
- if (childCount == children.length) {
- Control [] newChildren = new Control [childCount + 4];
- System.arraycopy (children, 0, newChildren, 0, childCount);
- children = newChildren;
- }
- children [childCount++] = control;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an item in the receiver is expanded or collapsed
- * by sending it one of the messages defined in the <code>ExpandListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ExpandListener
- * @see #removeExpandListener
- */
-public void addExpandListener (ExpandListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Expand, typedListener);
- addListener (SWT.Collapse, typedListener);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-static int checkStyle (int style) {
- style &= ~SWT.H_SCROLL;
- return style;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- Point size = computeSize (handle, wHint, hHint, changed);
- Rectangle trim = computeTrim (0, 0, size.x, size.y);
- return new Point (trim.width, trim.height);
-}
-
-void createHandle () {
- state |= THEME_BACKGROUND;
- parentingHandle = OS.gcnew_Canvas ();
- if (parentingHandle == 0) error (SWT.ERROR_NO_HANDLES);
- scrolledHandle = OS.gcnew_ScrollViewer ();
- if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
- handle = OS.gcnew_StackPanel ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- int children = OS.Panel_Children (parentingHandle);
- OS.UIElementCollection_Add (children, scrolledHandle);
- OS.GCHandle_Free (children);
- OS.ContentControl_Content (scrolledHandle, handle);
-}
-
-void createItem (ExpandItem item, int style, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- item.createWidget ();
- int items = OS.Panel_Children (handle);
- OS.UIElementCollection_Insert (items, index, item.topHandle ());
- int count = OS.UIElementCollection_Count (items);
- OS.GCHandle_Free (items);
- if (itemCount == count) error (SWT.ERROR_ITEM_NOT_ADDED);
- itemCount++;
-}
-
-void createWidget () {
- super.createWidget ();
- children = new Control [4];
-}
-
-int defaultBackground () {
- return OS.SystemColors_ControlColor;
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (parentingHandle);
-}
-
-void destroyItem (ExpandItem item) {
- int items = OS.Panel_Children (handle);
- OS.UIElementCollection_Remove (items, item.topHandle ());
- int count = OS.UIElementCollection_Count (items);
- OS.GCHandle_Free (items);
- if (itemCount == count) error (SWT.ERROR_ITEM_NOT_REMOVED);
- itemCount--;
-}
-
-void fixScrollbarVisibility () {
- OS.ScrollViewer_SetHorizontalScrollBarVisibility (scrolledHandle, OS.ScrollBarVisibility_Hidden);
- if ((style & SWT.V_SCROLL) == 0) {
- OS.ScrollViewer_SetVerticalScrollBarVisibility (scrolledHandle, OS.ScrollBarVisibility_Hidden);
- } else {
- OS.ScrollViewer_SetVerticalScrollBarVisibility (scrolledHandle, OS.ScrollBarVisibility_Auto);
- }
-}
-
-Point getLocation (Control child) {
- int topHandle = child.topHandle ();
- int point = OS.gcnew_Point (0, 0);
- if (point == 0) error (SWT.ERROR_NO_HANDLES);
- int location = OS.UIElement_TranslatePoint (topHandle, point, handle);
- int x = (int) OS.Point_X (location);
- int y = (int) OS.Point_Y (location);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (location);
- return new Point (x, y);
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ExpandItem getItem (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- int items = OS.Panel_Children (handle);
- ExpandItem item = getItem (items, index);
- OS.GCHandle_Free (items);
- return item;
-}
-
-ExpandItem getItem (int items, int index) {
- int item = OS.UIElementCollection_default (items, index);
- ExpandItem result = (ExpandItem) display.getWidget (item);
- OS.GCHandle_Free (item);
- return result;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return itemCount;
-}
-
-/**
- * Returns an array of <code>ExpandItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ExpandItem [] getItems () {
- checkWidget ();
- ExpandItem [] result = new ExpandItem [itemCount];
- int items = OS.Panel_Children (handle);
- for (int i=0; i<itemCount; i++) {
- result [i] = getItem (items, i);
- }
- OS.GCHandle_Free (items);
- return result;
-}
-
-int getScrollBarHandle (int style) {
- if ((style & SWT.H_SCROLL) != 0) return 0;
- updateLayout (handle);
- int template = OS.Control_Template (scrolledHandle);
- int part = createDotNetString ("PART_VerticalScrollBar", false);
- int scrollbar = OS.FrameworkTemplate_FindName (template, part, scrolledHandle);
- OS.GCHandle_Free (part);
- OS.GCHandle_Free (template);
- return scrollbar;
-}
-
-/**
- * Returns the receiver's spacing.
- *
- * @return the spacing
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSpacing () {
- checkWidget ();
- return spacing;
-}
-
-boolean hasItems () {
- return true;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (ExpandItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- int items = OS.Panel_Children (handle);
- int index = OS.UIElementCollection_IndexOf (items, item.topHandle ());
- OS.GCHandle_Free (items);
- return index;
-}
-
-int parentingHandle() {
- return parentingHandle;
-}
-
-void register () {
- super.register ();
- display.addWidget (parentingHandle, this);
-}
-
-void releaseChildren (boolean destroy) {
- int items = OS.Panel_Children (handle);
- for (int i=0; i<itemCount; i++) {
- ExpandItem item = getItem (items, i);
- if (item != null && !item.isDisposed ()) item.release (false);
- }
- OS.GCHandle_Free (items);
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (parentingHandle != 0) OS.GCHandle_Free (parentingHandle);
- parentingHandle = 0;
-}
-
-void removeChild (Control control) {
- super.removeChild (control);
- int index = 0;
- while (index < childCount) {
- if (children [index] == control) break;
- index++;
- }
- if (index == childCount) return;
- System.arraycopy (children, index+1, children, index, --childCount - index);
- children [childCount] = null;
-}
-
-void removeControl (Control control) {
- super.removeControl (control);
- int items = OS.Panel_Children (handle);
- for (int i=0; i<itemCount; i++) {
- ExpandItem item = getItem (items, i);
- if (item.control == control) {
- item.setControl (null);
- break;
- }
- }
- OS.GCHandle_Free (items);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when items in the receiver are expanded or collapsed.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ExpandListener
- * @see #addExpandListener
- */
-public void removeExpandListener (ExpandListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Expand, listener);
- eventTable.unhook (SWT.Collapse, listener);
-}
-
-int setBounds (int x, int y, int width, int height, int flags) {
- int result = super.setBounds (x, y, width, height, flags);
- if ((result & RESIZED) != 0) {
- OS.FrameworkElement_Height (scrolledHandle, height);
- OS.FrameworkElement_Width (scrolledHandle, width);
- }
- return result;
-}
-
-/**
- * Sets the receiver's spacing. Spacing specifies the number of pixels allocated around
- * each item.
- *
- * @param spacing the spacing around each item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSpacing (int spacing) {
- checkWidget ();
- if (spacing < 0) return;
- if (spacing == this.spacing) return;
- this.spacing = spacing;
- int thickness = OS.gcnew_Thickness (spacing, spacing, spacing, spacing);
- int items = OS.Panel_Children (handle);
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = getItem (items, i);
- OS.FrameworkElement_Margin (item.handle, thickness);
- }
- OS.GCHandle_Free (items);
- OS.GCHandle_Free (thickness);
-}
-
-int topHandle () {
- return parentingHandle;
-}
-} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ExpandItem.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ExpandItem.java
deleted file mode 100644
index b7b55c596c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ExpandItem.java
+++ /dev/null
@@ -1,397 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a expandable item in a expand bar.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see ExpandBar
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.2
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ExpandItem extends Item {
- ExpandBar parent;
- Control control;
- int imageHandle, textHandle, contentHandle;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ExpandItem (ExpandBar parent, int style) {
- this (parent, style, checkNull (parent).getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent, a
- * style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ExpandItem (ExpandBar parent, int style, int index) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, style, index);
-}
-
-static ExpandBar checkNull (ExpandBar control) {
- if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return control;
-}
-
-void createHandle () {
- handle = OS.gcnew_Expander ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- int spacing = parent.spacing;
- int thickness = OS.gcnew_Thickness (spacing, spacing, spacing, spacing);
- OS.FrameworkElement_Margin (handle, thickness);
- OS.GCHandle_Free (thickness);
- imageHandle = OS.gcnew_Image ();
- if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.Image_Stretch (imageHandle, OS.Stretch_None);
- OS.UIElement_Visibility (imageHandle, OS.Visibility_Collapsed);
- textHandle = OS.gcnew_TextBlock ();
- if (textHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int panel = OS.gcnew_StackPanel ();
- if (panel == 0) error (SWT.ERROR_NO_HANDLES);
- OS.StackPanel_Orientation (panel, OS.Orientation_Horizontal);
- thickness = OS.gcnew_Thickness (1, 1, 1, 1);
- if (thickness == 0) error (SWT.ERROR_NO_HANDLES);
- OS.FrameworkElement_Margin (panel, thickness);
- OS.GCHandle_Free (thickness);
- int children = OS.Panel_Children (panel);
- OS.UIElementCollection_Add (children, imageHandle);
- OS.UIElementCollection_Add (children, textHandle);
- OS.GCHandle_Free (children);
- OS.HeaderedContentControl_Header (handle, panel);
- OS.GCHandle_Free (panel);
- contentHandle = OS.gcnew_Canvas ();
- if (contentHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ContentControl_Content (handle, contentHandle);
-}
-
-void deregister () {
- display.removeWidget (handle);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns the control that is shown when the item is expanded.
- * If no control has been set, return <code>null</code>.
- *
- * @return the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget ();
- return control;
-}
-
-/**
- * Returns <code>true</code> if the receiver is expanded,
- * and false otherwise.
- *
- * @return the expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getExpanded () {
- checkWidget ();
- return OS.Expander_IsExpanded (handle);
-}
-
-/**
- * Returns the height of the receiver's header
- *
- * @return the height of the header
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getHeaderHeight () {
- checkWidget ();
- int panel = OS.HeaderedContentControl_Header (handle);
- return (int) OS.FrameworkElement_ActualHeight (panel);
-}
-
-/**
- * Gets the height of the receiver.
- *
- * @return the height
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getHeight () {
- checkWidget ();
- return (int) OS.FrameworkElement_Height (contentHandle);
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>ExpandBar</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ExpandBar getParent () {
- checkWidget ();
- return parent;
-}
-
-Control getWidgetControl () {
- return parent;
-}
-
-void HandleExpanded (int sender, int e) {
- if (!checkEvent (e)) return;
- Event event = new Event ();
- event.item = this;
- parent.notifyListeners (SWT.Expand, event);
-}
-
-void HandleCollapsed (int sender, int e) {
- if (!checkEvent (e)) return;
- Event event = new Event ();
- event.item = this;
- parent.notifyListeners (SWT.Collapse, event);
-}
-
-void HandleSizeChanged (int sender, int e) {
- if (!checkEvent (e)) return;
- resizeControl ();
-}
-
-void hookEvents () {
- super.hookEvents ();
- int handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleExpanded");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.Expander_Expanded (handle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleCollapsed");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.Expander_Collapsed (handle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_SizeChangedEventHandler (jniRef, "HandleSizeChanged");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.FrameworkElement_SizeChanged (contentHandle, handler);
- OS.GCHandle_Free (handler);
-}
-
-void register () {
- display.addWidget (handle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (handle != 0) OS.GCHandle_Free (handle);
- handle = 0;
- parent = null;
- if (textHandle != 0) OS.GCHandle_Free (textHandle);
- textHandle = 0;
- if (imageHandle !=0 )OS.GCHandle_Free (imageHandle);
- imageHandle = 0;
- if (contentHandle != 0) OS.GCHandle_Free (contentHandle);
- contentHandle = 0;
-}
-
-void resizeControl () {
- if (control != null) {
- int width = (int) OS.FrameworkElement_ActualWidth (contentHandle);
- int height = (int) OS.FrameworkElement_Height (contentHandle);
- control.setSize (width, height);
- }
-}
-
-/**
- * Sets the control that is shown when the item is expanded.
- *
- * @param control the new control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget ();
- if (control != null) {
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- Control oldControl = this.control, newControl = control;
- this.control = control;
- int children = OS.Panel_Children (contentHandle);
- int parentHandle = parent.parentingHandle ();
- int parentChildren = OS.Panel_Children (parentHandle);
- if (newControl != null) {
- int topHandle = newControl.topHandle ();
- OS.UIElementCollection_Remove (parentChildren, topHandle);
- OS.UIElementCollection_Add (children, topHandle);
- }
- if (oldControl != null) {
- int topHandle = oldControl.topHandle ();
- OS.UIElementCollection_Remove (children, topHandle);
- OS.UIElementCollection_Add (parentChildren, topHandle);
- }
- OS.GCHandle_Free (children);
- OS.GCHandle_Free (parentChildren);
-}
-
-/**
- * Sets the expanded state of the receiver.
- *
- * @param expanded the new expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setExpanded (boolean expanded) {
- checkWidget ();
- OS.Expander_IsExpanded(handle, expanded);
-}
-
-/**
- * Sets the height of the receiver. This is height of the item when it is expanded,
- * excluding the height of the header.
- *
- * @param height the new height
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHeight (int height) {
- checkWidget ();
- if (height < 0) return;
- OS.FrameworkElement_Height (contentHandle, height);
-}
-
-public void setImage (Image image) {
- super.setImage (image);
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- this.image = image;
- OS.Image_Source (imageHandle, image != null ? image.handle : 0);
- OS.UIElement_Visibility (imageHandle, image != null ? OS.Visibility_Visible : OS.Visibility_Collapsed);
- OS.UIElement_Visibility (textHandle, image != null && text.length () == 0 ? OS.Visibility_Collapsed : OS.Visibility_Visible);
- int spacing = image != null && text.length () != 0 ? 3 : 0;
- int margin = OS.gcnew_Thickness (0, 0, spacing, 0);
- if (margin == 0) error(SWT.ERROR_NO_HANDLES);
- OS.FrameworkElement_Margin (imageHandle, margin);
- OS.GCHandle_Free (margin);
-}
-
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (string.equals (text)) return;
- text = string;
- int ptr = createDotNetString (text, false);
- if (ptr == 0) error(SWT.ERROR_NO_HANDLES);
- OS.TextBlock_Text (textHandle, ptr);
- OS.GCHandle_Free (ptr);
- OS.UIElement_Visibility (textHandle, text.length() == 0 && image != null ? OS.Visibility_Collapsed : OS.Visibility_Visible);
- int spacing = image != null && text.length () != 0 ? 3 : 0;
- int margin = OS.gcnew_Thickness (0, 0, spacing, 0);
- if (margin == 0) error(SWT.ERROR_NO_HANDLES);
- OS.FrameworkElement_Margin (imageHandle, margin);
- OS.GCHandle_Free (margin);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/FileDialog.java
deleted file mode 100644
index af8aa3c078..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/FileDialog.java
+++ /dev/null
@@ -1,374 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class allow the user to navigate
- * the file system and select or enter a file name.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SAVE, OPEN, MULTI</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles SAVE and OPEN may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#filedialog">FileDialog snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class FileDialog extends Dialog {
- String [] filterNames = new String [0];
- String [] filterExtensions = new String [0];
- String [] fileNames = new String [0];
- String filterPath = "", fileName = ""; //$NON-NLS-1$//$NON-NLS-2$
- int filterIndex = -1;
- boolean overwrite = false;
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FileDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SAVE
- * @see SWT#OPEN
- * @see SWT#MULTI
- */
-public FileDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-/**
- * Returns the path of the first file that was
- * selected in the dialog relative to the filter path, or an
- * empty string if no such file has been selected.
- *
- * @return the relative path of the file
- */
-public String getFileName () {
- return fileName;
-}
-
-/**
- * Returns a (possibly empty) array with the paths of all files
- * that were selected in the dialog relative to the filter path.
- *
- * @return the relative paths of the files
- */
-public String [] getFileNames () {
- return fileNames;
-}
-
-/**
- * Returns the file extensions which the dialog will
- * use to filter the files it shows.
- *
- * @return the file extensions filter
- */
-public String [] getFilterExtensions () {
- return filterExtensions;
-}
-
-/**
- * Get the 0-based index of the file extension filter
- * which was selected by the user, or -1 if no filter
- * was selected.
- * <p>
- * This is an index into the FilterExtensions array and
- * the FilterNames array.
- * </p>
- *
- * @return index the file extension filter index
- *
- * @see #getFilterExtensions
- * @see #getFilterNames
- *
- * @since 3.4
- */
-public int getFilterIndex () {
- return filterIndex;
-}
-
-/**
- * Returns the names that describe the filter extensions
- * which the dialog will use to filter the files it shows.
- *
- * @return the list of filter names
- */
-public String [] getFilterNames () {
- return filterNames;
-}
-
-/**
- * Returns the directory path that the dialog will use, or an empty
- * string if this is not set. File names in this path will appear
- * in the dialog, filtered according to the filter extensions.
- *
- * @return the directory path string
- *
- * @see #setFilterExtensions
- */
-public String getFilterPath () {
- return filterPath;
-}
-
-/**
- * Returns the flag that the dialog will use to
- * determine whether to prompt the user for file
- * overwrite if the selected file already exists.
- *
- * @return true if the dialog will prompt for file overwrite, false otherwise
- *
- * @since 3.4
- */
-public boolean getOverwrite () {
- return overwrite;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a string describing the absolute path of the first selected file,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public String open () {
- int dialog;
- if ((style & SWT.SAVE) != 0) {
- dialog = OS.gcnew_SaveFileDialog ();
- } else {
- dialog = OS.gcnew_OpenFileDialog ();
- if ((style & SWT.MULTI) != 0) OS.OpenFileDialog_Multiselect (dialog, true);
- }
- int titlePtr = parent.createDotNetString (title, false);
- OS.FileDialog_Title (dialog, titlePtr);
- OS.GCHandle_Free (titlePtr);
- int fileNamePtr = parent.createDotNetString (fileName, false);
- OS.FileDialog_FileName (dialog, fileNamePtr);
- OS.GCHandle_Free (fileNamePtr);
-
- if (filterExtensions != null && filterExtensions.length > 0) {
- StringBuffer strFilter = new StringBuffer();
- for (int i=0; i<filterExtensions.length; i++) {
- if (i > 0) strFilter.append("|");
- if (filterNames != null && i < filterNames.length) {
- strFilter.append(filterNames [i]);
- } else {
- strFilter.append(filterExtensions [i]);
- }
- strFilter.append("|");
- strFilter.append(filterExtensions [i]);
- }
- int filterPtr = parent.createDotNetString(strFilter.toString (), false);
- OS.FileDialog_Filter (dialog, filterPtr);
- OS.GCHandle_Free (filterPtr);
- if (filterIndex != -1) OS.FileDialog_FilterIndex (dialog, filterIndex + 1);
- }
-
- int filterPathPtr = parent.createDotNetString (filterPath, false);
- OS.FileDialog_InitialDirectory (dialog, filterPathPtr);
- OS.GCHandle_Free (filterPathPtr);
-
- if ((style & SWT.SAVE) != 0) OS.SaveFileDialog_OverwritePrompt (dialog, overwrite);
-
- int parentHandle = (parent.style & SWT.ON_TOP) == 0 ? parent.shellHandle : 0;
- boolean success = OS.CommonDialog_ShowDialog (dialog, parentHandle);
-
- /* Set the new path, file name and filter */
- String fullPath = null;
- if (success) {
- int strings = OS.FileDialog_FileNames (dialog);
- int length = OS.ICollection_Count (strings);
- fileNames = new String [length];
- for (int i = 0; i < length; i++) {
- int str = OS.IList_default (strings, i);
- int fileInfo = OS.gcnew_FileInfo (str);
- int name = OS.FileInfo_Name (fileInfo);
- fileNames [i] = Widget.createJavaString (name);
- if (i == 0) {
- int dir = OS.FileInfo_DirectoryName (fileInfo);
- filterPath = Widget.createJavaString (dir);
- OS.GCHandle_Free (dir);
- }
- OS.GCHandle_Free (name);
- OS.GCHandle_Free (fileInfo);
- OS.GCHandle_Free (str);
- }
- OS.GCHandle_Free (strings);
- fullPath = filterPath + "\\" + fileNames [0];
- fileName = fileNames [0];
- } else {
- fileNames = new String [0];
- }
- filterIndex = OS.FileDialog_FilterIndex (dialog) - 1;
-
- OS.GCHandle_Free (dialog);
- /* Answer the full path or null */
- return fullPath;
-}
-
-/**
- * Set the initial filename which the dialog will
- * select by default when opened to the argument,
- * which may be null. The name will be prefixed with
- * the filter path when one is supplied.
- *
- * @param string the file name
- */
-public void setFileName (String string) {
- fileName = string;
-}
-
-/**
- * Set the file extensions which the dialog will
- * use to filter the files it shows to the argument,
- * which may be null.
- * <p>
- * The strings are platform specific. For example, on
- * some platforms, an extension filter string is typically
- * of the form "*.extension", where "*.*" matches all files.
- * For filters with multiple extensions, use semicolon as
- * a separator, e.g. "*.jpg;*.png".
- * </p>
- *
- * @param extensions the file extension filter
- *
- * @see #setFilterNames to specify the user-friendly
- * names corresponding to the extensions
- */
-public void setFilterExtensions (String [] extensions) {
- filterExtensions = extensions;
-}
-
-/**
- * Set the 0-based index of the file extension filter
- * which the dialog will use initially to filter the files
- * it shows to the argument.
- * <p>
- * This is an index into the FilterExtensions array and
- * the FilterNames array.
- * </p>
- *
- * @param index the file extension filter index
- *
- * @see #setFilterExtensions
- * @see #setFilterNames
- *
- * @since 3.4
- */
-public void setFilterIndex (int index) {
- filterIndex = index;
-}
-
-/**
- * Sets the names that describe the filter extensions
- * which the dialog will use to filter the files it shows
- * to the argument, which may be null.
- * <p>
- * Each name is a user-friendly short description shown for
- * its corresponding filter. The <code>names</code> array must
- * be the same length as the <code>extensions</code> array.
- * </p>
- *
- * @param names the list of filter names, or null for no filter names
- *
- * @see #setFilterExtensions
- */
-public void setFilterNames (String [] names) {
- filterNames = names;
-}
-
-/**
- * Sets the directory path that the dialog will use
- * to the argument, which may be null. File names in this
- * path will appear in the dialog, filtered according
- * to the filter extensions. If the string is null,
- * then the operating system's default filter path
- * will be used.
- * <p>
- * Note that the path string is platform dependent.
- * For convenience, either '/' or '\' can be used
- * as a path separator.
- * </p>
- *
- * @param string the directory path
- *
- * @see #setFilterExtensions
- */
-public void setFilterPath (String string) {
- filterPath = string;
-}
-
-/**
- * Sets the flag that the dialog will use to
- * determine whether to prompt the user for file
- * overwrite if the selected file already exists.
- *
- * @param overwrite true if the dialog will prompt for file overwrite, false otherwise
- *
- * @since 3.4
- */
-public void setOverwrite (boolean overwrite) {
- this.overwrite = overwrite;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/FontDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/FontDialog.java
deleted file mode 100644
index 345524ec7c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/FontDialog.java
+++ /dev/null
@@ -1,243 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.wpf.OS;
-
-/**
- * Instances of this class allow the user to select a font
- * from all available fonts in the system.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class FontDialog extends Dialog {
- FontData fontData;
- RGB rgb;
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FontDialog (Shell parent) {
- this (parent, SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public FontDialog (Shell parent, int style) {
- super (parent, checkStyle (parent, style));
- checkSubclass ();
-}
-
-/**
- * Returns a FontData object describing the font that was
- * selected in the dialog, or null if none is available.
- *
- * @return the FontData for the selected font, or null
- * @deprecated use #getFontList ()
- */
-public FontData getFontData () {
- return fontData;
-}
-
-/**
- * Returns a FontData set describing the font that was
- * selected in the dialog, or null if none is available.
- *
- * @return the FontData for the selected font, or null
- * @since 2.1.1
- */
-public FontData [] getFontList () {
- if (fontData == null) return null;
- FontData [] result = new FontData [1];
- result [0] = fontData;
- return result;
-}
-
-/**
- * Returns an RGB describing the color that was selected
- * in the dialog, or null if none is available.
- *
- * @return the RGB value for the selected color, or null
- *
- * @see PaletteData#getRGBs
- *
- * @since 2.1
- */
-public RGB getRGB () {
- return rgb;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a FontData object describing the font that was selected,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public FontData open () {
- int dialog = OS.gcnew_FontDialog ();
- OS.FontDialog_ShowColor (dialog, true);
- if (fontData != null) {
- int fontFamily = parent.createDotNetString (fontData.fontFamily, false);
- int fontStyle = 0;
- int fontWeight = OS.FontWeight_ToOpenTypeWeight (OS.FontWeights_Bold);
- if (fontWeight == fontData.weight) fontStyle |= OS.FontStyle_Bold;
- if (fontData.style == OS.FontStyles_Italic) fontStyle |= OS.FontStyle_Italic;
- if (fontData.style == OS.FontStyles_Normal) fontStyle |= OS.FontStyle_Regular;
- //TODO strikethrough/underline
- int font = OS.gcnew_Font (fontFamily, fontData.height, fontStyle);
- OS.FontDialog_Font (dialog, font);
- OS.GCHandle_Free (font);
- OS.GCHandle_Free (fontFamily);
- }
- if (rgb != null) {
- int color = OS.DrawingColor_FromArgb (174, rgb.red, rgb.blue, rgb.green);
- OS.FontDialog_Color (dialog, color);
- OS.GCHandle_Free (color);
- }
- int result = OS.FormsCommonDialog_ShowDialog (dialog);
- boolean success = result == OS.DialogResult_OK;
- if (success) {
- int font = OS.FontDialog_Font (dialog);
- int fontFamilyPtr = OS.Font_FontFamily (font);
- int fontFamilyName = OS.DrawingFontFamily_Name (fontFamilyPtr);
- String fontFamily = Widget.createJavaString (fontFamilyName);
- int fontStyle = OS.Font_Style (font);
- int fontDataStyle;
- if ((fontStyle & OS.FontStyle_Italic) != 0) {
- fontDataStyle = OS.FontStyles_Italic;
- } else {
- fontDataStyle = OS.FontStyles_Normal;
- }
- int weight;
- if ((fontStyle & OS.FontStyle_Bold) != 0) {
- weight = OS.FontWeight_ToOpenTypeWeight (OS.FontWeights_Bold);
- } else {
- weight = OS.FontWeight_ToOpenTypeWeight (OS.FontWeights_Normal);
- }
- int height = OS.Font_Size (font);
- OS.GCHandle_Free(fontFamilyName);
- OS.GCHandle_Free(fontFamilyPtr);
- OS.GCHandle_Free(font);
- fontData = FontData.wpf_new (fontFamily, fontDataStyle, weight, 1, height);
-
- int color = OS.FontDialog_Color (dialog);
- int argb = OS.DrawingColor_ToArgb (color);
- int red = (argb & 0xFF0000) >> 16;
- int green = (argb & 0xFF00) >> 8;
- int blue = argb & 0xFF;
- OS.GCHandle_Free (color);
- rgb = new RGB (red, green, blue);
- }
- OS.GCHandle_Free (dialog);
- return success ? fontData : null;
-}
-
-/**
- * Sets a FontData object describing the font to be
- * selected by default in the dialog, or null to let
- * the platform choose one.
- *
- * @param fontData the FontData to use initially, or null
- * @deprecated use #setFontList (FontData [])
- */
-public void setFontData (FontData fontData) {
- this.fontData = fontData;
-}
-
-/**
- * Sets the set of FontData objects describing the font to
- * be selected by default in the dialog, or null to let
- * the platform choose one.
- *
- * @param fontData the set of FontData objects to use initially, or null
- * to let the platform select a default when open() is called
- *
- * @see Font#getFontData
- *
- * @since 2.1.1
- */
-public void setFontList (FontData [] fontData) {
- if (fontData != null && fontData.length > 0) {
- this.fontData = fontData [0];
- } else {
- this.fontData = null;
- }
-}
-
-/**
- * Sets the RGB describing the color to be selected by default
- * in the dialog, or null to let the platform choose one.
- *
- * @param rgb the RGB value to use initially, or null to let
- * the platform select a default when open() is called
- *
- * @see PaletteData#getRGBs
- *
- * @since 2.1
- */
-public void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Group.java
deleted file mode 100644
index 5877f27207..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Group.java
+++ /dev/null
@@ -1,240 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class provide an etched border
- * with an optional title.
- * <p>
- * Shadow styles are hints and may not be honoured
- * by the platform. To create a group with the
- * default shadow style for the platform, do not
- * specify a shadow style.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SHADOW_ETCHED_IN, SHADOW_ETCHED_OUT, SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the above styles may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Group extends Composite {
- int parentingHandle;
- String text;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SHADOW_ETCHED_IN
- * @see SWT#SHADOW_ETCHED_OUT
- * @see SWT#SHADOW_IN
- * @see SWT#SHADOW_OUT
- * @see SWT#SHADOW_NONE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Group (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-int backgroundProperty () {
- return OS.Control_BackgroundProperty ();
-}
-
-int clientHandle () {
- return parentingHandle;
-}
-
-void createHandle () {
- state |= THEME_BACKGROUND;
- handle = OS.gcnew_GroupBox ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- parentingHandle = OS.gcnew_Canvas ();
- if (parentingHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ContentControl_Content (handle, parentingHandle);
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- int topHandle = topHandle ();
- int clientHandle = clientHandle();
- if (clientHandle != topHandle) {
- double currentWidth = OS.FrameworkElement_Width (topHandle);
- double currentHeight = OS.FrameworkElement_Height (topHandle);
- OS.FrameworkElement_Width (topHandle, 100);
- OS.FrameworkElement_Height (topHandle, 100);
- updateLayout (topHandle);
- int w = (int) OS.FrameworkElement_ActualWidth (topHandle);
- int h = (int) OS.FrameworkElement_ActualHeight (topHandle);
- int clientWidth = (int) OS.FrameworkElement_ActualWidth (clientHandle);
- int clientHeight = (int) OS.FrameworkElement_ActualHeight (clientHandle);
- int point = OS.gcnew_Point (0, 0);
- int result = OS.UIElement_TranslatePoint (clientHandle, point, topHandle);
- x -= (int) OS.Point_X (result);
- y -= (int) OS.Point_Y (result);
- width += (w - clientWidth);
- height += (h - clientHeight);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (result);
- OS.FrameworkElement_Width (topHandle, currentWidth);
- OS.FrameworkElement_Height (topHandle, currentHeight);
- }
- return new Rectangle (x, y, width, height);
-}
-
-int defaultBackground () {
- return OS.SystemColors_ControlColor;
-}
-
-void enableWidget (boolean enabled) {
- OS.UIElement_IsHitTestVisible (handle, enabled);
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which is the string that the
- * is used as the <em>title</em>. If the text has not previously
- * been set, returns an empty string.
- *
- * @return the text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-boolean mnemonicHit (char key) {
- return false;
-}
-
-boolean mnemonicMatch (char key) {
- int accessText = OS.HeaderedContentControl_Header (handle);
- boolean result = super.mnemonicMatch (accessText, key);
- OS.GCHandle_Free (accessText);
- return result;
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- OS.GCHandle_Free (parentingHandle);
- parentingHandle = 0;
-}
-
-void setForegroundBrush (int brush) {
- if (brush != 0) {
- OS.Control_Foreground (handle, brush);
- } else {
- int property = OS.Control_ForegroundProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
-}
-
-/**
- * Sets the receiver's text, which is the string that will
- * be displayed as the receiver's <em>title</em>, to the argument,
- * which may not be null. The string may include the mnemonic character.
- * </p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, focus is assigned
- * to the first child of the group. On most platforms, the
- * mnemonic appears underlined but may be emphasised in a
- * platform specific manner. The mnemonic indicator character
- * '&amp;' can be escaped by doubling it in the string, causing
- * a single '&amp;' to be displayed.
- * </p>
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (string.equals (text)) return;
- text = string;
- int ptr = createDotNetString (text, true);
- int accessText = OS.gcnew_AccessText ();
- if (ptr != 0) OS.AccessText_Text (accessText, ptr);
- OS.HeaderedContentControl_Header (handle, accessText);
- if (ptr != 0) OS.GCHandle_Free (ptr);
- OS.GCHandle_Free (accessText);
-}
-
-int parentingHandle () {
- return parentingHandle;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Label.java
deleted file mode 100644
index d3bc102840..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Label.java
+++ /dev/null
@@ -1,320 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a non-selectable
- * user interface object that displays a string or image.
- * When SEPARATOR is specified, displays a single
- * vertical or horizontal line.
- * <p>
- * Shadow styles are hints and may not be honored
- * by the platform. To create a separator label
- * with the default shadow style for the platform,
- * do not specify a shadow style.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SEPARATOR, HORIZONTAL, VERTICAL</dd>
- * <dd>SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd>
- * <dd>CENTER, LEFT, RIGHT, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of SHADOW_IN, SHADOW_OUT and SHADOW_NONE may be specified.
- * SHADOW_NONE is a HINT. Only one of HORIZONTAL and VERTICAL may be specified.
- * Only one of CENTER, LEFT and RIGHT may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#label">Label snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Label extends Control {
- String text = "";
- Image image;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SEPARATOR
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#SHADOW_IN
- * @see SWT#SHADOW_OUT
- * @see SWT#SHADOW_NONE
- * @see SWT#CENTER
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#WRAP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Label (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- if ((style & SWT.SEPARATOR) != 0) {
- style = checkBits (style, SWT.VERTICAL, SWT.HORIZONTAL, 0, 0, 0, 0);
- return checkBits (style, SWT.SHADOW_OUT, SWT.SHADOW_IN, SWT.SHADOW_NONE, 0, 0, 0);
- }
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-
-void createHandle () {
- state |= THEME_BACKGROUND;
- if ((style & SWT.SEPARATOR) != 0) {
- handle = OS.gcnew_UserControl ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- int separator = OS.gcnew_Label ();
- if (separator == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ContentControl_Content (handle, separator);
- if ((style & SWT.VERTICAL) != 0) {
- OS.FrameworkElement_Width (separator, OS.SystemParameters_ThinVerticalBorderWidth ());
- OS.Control_HorizontalContentAlignment (handle, OS.HorizontalAlignment_Center);
- OS.Control_VerticalContentAlignment (handle, OS.VerticalAlignment_Stretch);
- } else {
- OS.FrameworkElement_Height (separator, OS.SystemParameters_ThinHorizontalBorderHeight ());
- OS.Control_HorizontalContentAlignment (handle, OS.HorizontalAlignment_Stretch);
- OS.Control_VerticalContentAlignment (handle, OS.VerticalAlignment_Center);
- }
- int brush = OS.SystemColors_ActiveBorderBrush ();
- OS.Control_Background (separator, brush);
- OS.GCHandle_Free (brush);
- OS.GCHandle_Free (separator);
- } else {
- handle = OS.gcnew_Label ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- int value = OS.HorizontalAlignment_Left;
- if ((style & SWT.CENTER) != 0) value = OS.HorizontalAlignment_Center;
- if ((style & SWT.RIGHT) != 0) value = OS.HorizontalAlignment_Right;
- OS.Control_HorizontalContentAlignment (handle, value);
- int margin = OS.gcnew_Thickness (0, 0, 0, 0);
- OS.Control_Padding (handle, margin);
- OS.GCHandle_Free (margin);
- }
-}
-
-int defaultBackground () {
- //TEMPORARY CODE
-// return OS.SystemColors_ControlColor;
- return 0;
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is a <code>SEPARATOR</code> label, in
- * which case, <code>NONE</code> is returned.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return 0;
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-/**
- * Returns the receiver's image if it has one, or null
- * if it does not.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage () {
- checkWidget ();
- return image;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set or if the receiver is
- * a <code>SEPARATOR</code> label.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return "";
- return text;
-}
-
-boolean mnemonicHit (char key) {
- //TODO
- return false;
-}
-
-boolean mnemonicMatch (char key) {
- int accessText = OS.ContentControl_Content (handle);
- boolean result = super.mnemonicMatch (accessText, key);
- OS.GCHandle_Free (accessText);
- return result;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- text = null;
- image = null;
-}
-
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>. If the receiver is a <code>SEPARATOR</code>
- * label, the argument is ignored and the alignment is not changed.
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return;
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- int value = OS.HorizontalAlignment_Left;
- if ((style & SWT.CENTER) != 0) value = OS.HorizontalAlignment_Center;
- if ((style & SWT.RIGHT) != 0) value = OS.HorizontalAlignment_Right;
- OS.Control_HorizontalContentAlignment (handle, value);
-}
-
-/**
- * Sets the receiver's image to the argument, which may be
- * null indicating that no image should be displayed.
- *
- * @param image the image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return;
- if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- this.image = image;
- int imageHandle = OS.gcnew_Image ();
- OS.Image_Stretch (imageHandle, OS.Stretch_None);
- OS.Image_Source (imageHandle, image != null ? image.handle : 0);
- OS.ContentControl_Content (handle, imageHandle);
- OS.GCHandle_Free (imageHandle);
-}
-
-/**
- * Sets the receiver's text.
- * <p>
- * This method sets the widget label. The label may include
- * the mnemonic character and line delimiters.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, focus is assigned
- * to the control that follows the label. On most platforms,
- * the mnemonic appears underlined but may be emphasised in a
- * platform specific manner. The mnemonic indicator character
- * '&amp;' can be escaped by doubling it in the string, causing
- * a single '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- if (string.equals (text)) return;
- text = string;
- int ptr = createDotNetString (text, true);
- int accessText = OS.gcnew_AccessText ();
- if (accessText == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.WRAP) != 0) {
- OS.AccessText_TextWrapping (accessText, OS.TextWrapping_WrapWithOverflow);
- }
- OS.AccessText_Text (accessText, ptr);
- OS.ContentControl_Content (handle, accessText);
- OS.GCHandle_Free (ptr);
- OS.GCHandle_Free (accessText);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Link.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Link.java
deleted file mode 100644
index 4a6895c4c8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Link.java
+++ /dev/null
@@ -1,461 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable
- * user interface object that displays a text with
- * links.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#link">Link snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Link extends Control {
- Point [] offsets;
- Point selection;
- String [] ids;
- String text;
- private int[] mnemonics;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Link (Composite parent, int style) {
- super (parent, style);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected by the user.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-int backgroundProperty () {
- return OS.TextBlock_BackgroundProperty ();
-}
-
-void createHandle () {
- state |= THEME_BACKGROUND;
- handle = OS.gcnew_TextBlock ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-
-int defaultBackground () {
- return OS.SystemColors_ControlColor;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget ();
- return text;
-}
-
-void HandleClick (int sender, int e) {
- if (!checkEvent (e)) return;
- int source = OS.RoutedEventArgs_Source (e);
- int i = OS.FrameworkContentElement_Tag (source);
- OS.GCHandle_Free (source);
- Event event = new Event ();
- event.text = ids [i];
- sendEvent (SWT.Selection, event);
-}
-
-String parse (String string) {
- int length = string.length ();
- offsets = new Point [length / 4];
- ids = new String [length / 4];
- mnemonics = new int [length / 4 + 1];
- StringBuffer result = new StringBuffer ();
- char [] buffer = new char [length];
- string.getChars (0, string.length (), buffer, 0);
- int index = 0, state = 0, linkIndex = 0;
- int start = 0, tagStart = 0, linkStart = 0, endtagStart = 0, refStart = 0;
- while (index < length) {
- char c = Character.toLowerCase (buffer [index]);
- switch (state) {
- case 0:
- if (c == '<') {
- tagStart = index;
- state++;
- }
- break;
- case 1:
- if (c == 'a') state++;
- break;
- case 2:
- switch (c) {
- case 'h':
- state = 7;
- break;
- case '>':
- linkStart = index + 1;
- state++;
- break;
- default:
- if (Character.isWhitespace(c)) break;
- else state = 13;
- }
- break;
- case 3:
- if (c == '<') {
- endtagStart = index;
- state++;
- }
- break;
- case 4:
- state = c == '/' ? state + 1 : 3;
- break;
- case 5:
- state = c == 'a' ? state + 1 : 3;
- break;
- case 6:
- if (c == '>') {
- mnemonics [linkIndex] = parseMnemonics (buffer, start, tagStart, result);
- int offset = result.length ();
- parseMnemonics (buffer, linkStart, endtagStart, result);
- offsets [linkIndex] = new Point (offset, result.length () - 1);
- if (ids [linkIndex] == null) {
- ids [linkIndex] = new String (buffer, linkStart, endtagStart - linkStart);
- }
- linkIndex++;
- start = tagStart = linkStart = endtagStart = refStart = index + 1;
- state = 0;
- } else {
- state = 3;
- }
- break;
- case 7:
- state = c == 'r' ? state + 1 : 0;
- break;
- case 8:
- state = c == 'e' ? state + 1 : 0;
- break;
- case 9:
- state = c == 'f' ? state + 1 : 0;
- break;
- case 10:
- state = c == '=' ? state + 1 : 0;
- break;
- case 11:
- if (c == '"') {
- state++;
- refStart = index + 1;
- } else {
- state = 0;
- }
- break;
- case 12:
- if (c == '"') {
- ids[linkIndex] = new String (buffer, refStart, index - refStart);
- state = 2;
- }
- break;
- case 13:
- if (Character.isWhitespace (c)) {
- state = 0;
- } else if (c == '='){
- state++;
- }
- break;
- case 14:
- state = c == '"' ? state + 1 : 0;
- break;
- case 15:
- if (c == '"') state = 2;
- break;
- default:
- state = 0;
- break;
- }
- index++;
- }
- if (start < length) {
- int tmp = parseMnemonics (buffer, start, tagStart, result);
- int mnemonic = parseMnemonics (buffer, Math.max (tagStart, linkStart), length, result);
- if (mnemonic == -1) mnemonic = tmp;
- mnemonics [linkIndex] = mnemonic;
- } else {
- mnemonics [linkIndex] = -1;
- }
- if (offsets.length != linkIndex) {
- Point [] newOffsets = new Point [linkIndex];
- System.arraycopy (offsets, 0, newOffsets, 0, linkIndex);
- offsets = newOffsets;
- String [] newIDs = new String [linkIndex];
- System.arraycopy (ids, 0, newIDs, 0, linkIndex);
- ids = newIDs;
- int [] newMnemonics = new int [linkIndex + 1];
- System.arraycopy (mnemonics, 0, newMnemonics, 0, linkIndex + 1);
- mnemonics = newMnemonics;
- }
- return result.toString ();
-}
-
-int parseMnemonics (char [] buffer, int start, int end, StringBuffer result) {
- int mnemonic = -1, index = start;
- while (index < end) {
- if (buffer [index] == '&') {
- if (index + 1 < end && buffer [index + 1] == '&') {
- result.append (buffer [index]);
- index++;
- } else {
- mnemonic = result.length();
- }
- } else {
- result.append (buffer [index]);
- }
- index++;
- }
- return mnemonic;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection, listener);
-}
-
-void setFont (int font, double size) {
- if (font != 0) {
- int fontFamily = OS.Typeface_FontFamily( font);
- int style = OS.Typeface_Style (font);
- int weight = OS.Typeface_Weight (font);
- int stretch = OS.Typeface_Stretch (font);
- OS.TextBlock_FontFamily (handle, fontFamily);
- OS.TextBlock_FontStyle (handle, style);
- OS.TextBlock_FontWeight (handle, weight);
- OS.TextBlock_FontStretch (handle, stretch);
- OS.TextBlock_FontSize (handle, size);
- OS.GCHandle_Free (fontFamily);
- OS.GCHandle_Free (style);
- OS.GCHandle_Free (weight);
- OS.GCHandle_Free (stretch);
- } else {
- int property = OS.TextBlock_FontFamilyProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.TextBlock_FontStyleProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.TextBlock_FontWeightProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.TextBlock_FontStretchProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.TextBlock_FontSizeProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
-}
-
-void setForegroundBrush (int brush) {
-//TODO
-}
-
-/**
- * Sets the receiver's text.
- * <p>
- * The string can contain both regular text and hyperlinks. A hyperlink
- * is delimited by an anchor tag, &lt;A&gt; and &lt;/A&gt;. Within an
- * anchor, a single HREF attribute is supported. When a hyperlink is
- * selected, the text field of the selection event contains either the
- * text of the hyperlink or the value of its HREF, if one was specified.
- * In the rare case of identical hyperlinks within the same string, the
- * HREF attribute can be used to distinguish between them. The string may
- * include the mnemonic character and line delimiters. The only delimiter
- * the HREF attribute supports is the quotation mark (").
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (string.equals (text)) return;
- text = string;
- String parsed = parse (string);
- int inlines = OS.TextBlock_Inlines (handle);
- OS.InlineCollection_Clear (inlines);
- int start = 0, end = parsed.length ();
- int offsetIndex = 0;
- while (start < end) {
- Point point = offsetIndex < offsets.length ? offsets [offsetIndex] : null;
- if (point == null) {
- String substring = parsed.substring (start, end);
- int stringPtr = createDotNetString (substring, false);
- if (stringPtr == 0) error(SWT.ERROR_NO_HANDLES);
- int run = OS.gcnew_Run ();
- if (run == 0) error(SWT.ERROR_NO_HANDLES);
- OS.Run_Text (run, stringPtr);
- OS.InlineCollection_Add (inlines, run);
- OS.GCHandle_Free (stringPtr);
- OS.GCHandle_Free (run);
- start = end;
- } else {
- if (start < point.x) {
- String substring = parsed.substring (start, point.x);
- int stringPtr = createDotNetString (substring, false);
- if (stringPtr == 0) error(SWT.ERROR_NO_HANDLES);
- int run = OS.gcnew_Run ();
- if (run == 0) error(SWT.ERROR_NO_HANDLES);
- OS.Run_Text (run, stringPtr);
- OS.InlineCollection_Add (inlines, run);
- OS.GCHandle_Free (stringPtr);
- OS.GCHandle_Free (run);
- start = point.x;
- } else {
- String substring = parsed.substring (point.x, point.y+1);
- int stringPtr = createDotNetString (substring, false);
- if (stringPtr == 0) error(SWT.ERROR_NO_HANDLES);
- int run = OS.gcnew_Run ();
- if (run == 0) error(SWT.ERROR_NO_HANDLES);
- OS.Run_Text (run, stringPtr);
- int hyperlink = OS.gcnew_Hyperlink (run);
- OS.FrameworkContentElement_Tag (hyperlink, offsetIndex);
- OS.InlineCollection_Add (inlines, hyperlink);
- int handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleClick");
- OS.Hyperlink_Click (hyperlink, handler);
- OS.GCHandle_Free (handler);
- OS.GCHandle_Free (stringPtr);
- OS.GCHandle_Free (run);
- OS.GCHandle_Free (hyperlink);
- start = point.y+1;
- offsetIndex++;
- }
- }
- }
- OS.GCHandle_Free (inlines);
-}
-
-int traversalCode (int key, int event) {
-// if (offsets.length == 0) return 0;
- int bits = super.traversalCode (key, event);
-// if (key == OS.Key_Tab && focusIndex < offsets.length - 1) {
-// return bits & ~SWT.TRAVERSE_TAB_NEXT;
-// }
-// if (key == OS.GDK_ISO_Left_Tab && focusIndex > 0) {
-// return bits & ~SWT.TRAVERSE_TAB_PREVIOUS;
-// }
- //TODO
- return bits;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/List.java
deleted file mode 100644
index 6040ec4ab1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/List.java
+++ /dev/null
@@ -1,1186 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface
- * object that displays a list of strings and issues notification
- * when a string is selected. A list may be single or multi select.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection</dd>
- * </dl>
- * <p>
- * Note: Only one of SINGLE and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#list">List snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class List extends Scrollable {
- boolean ignoreSelection;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public List (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the argument to the end of the receiver's list.
- *
- * @param string the new item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String,int)
- */
-public void add (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int item = OS.gcnew_ListBoxItem ();
- int strPtr = createDotNetString (string, false);
- OS.ContentControl_Content (item, strPtr);
- OS.GCHandle_Free (strPtr);
- int items = OS.ItemsControl_Items (handle);
- OS.ItemCollection_Add (items, item);
- OS.GCHandle_Free (items);
- OS.GCHandle_Free (item);
-}
-
-/**
- * Adds the argument to the receiver's list at the given
- * zero-relative index.
- * <p>
- * Note: To add an item at the end of the list, use the
- * result of calling <code>getItemCount()</code> as the
- * index or use <code>add(String)</code>.
- * </p>
- *
- * @param string the new item
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String)
- */
-public void add (String string, int index) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (index < 0 || index > getItemCount ()) error (SWT.ERROR_INVALID_RANGE);
- int item = OS.gcnew_ListBoxItem ();
- int strPtr = createDotNetString (string, false);
- OS.ContentControl_Content (item, strPtr);
- OS.GCHandle_Free (strPtr);
- int items = OS.ItemsControl_Items (handle);
- OS.ItemCollection_Insert (items, index, item);
- OS.GCHandle_Free (items);
- OS.GCHandle_Free (item);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the selection changes.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-
-void createHandle () {
- handle = OS.gcnew_ListBox ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.Selector_IsSynchronizedWithCurrentItem (handle, true);
- if ((style & SWT.MULTI) != 0) OS.ListBox_SelectionMode (handle, OS.SelectionMode_Extended);
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. Indices that are out
- * of range and duplicate indices are ignored.
- *
- * @param indices the array of indices for the items to deselect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- int count = getItemCount ();
- int items = OS.ItemsControl_Items (handle);
- ignoreSelection = true;
- for (int i = 0; i < indices.length; i++) {
- int index = indices [i];
- if (0 <= index && index < count) {
- int item = OS.ItemCollection_GetItemAt (items, index);
- OS.ListBoxItem_IsSelected (item, false);
- OS.GCHandle_Free (item);
- }
- }
- ignoreSelection = false;
- OS.GCHandle_Free (items);
-}
-
-/**
- * Deselects the item at the given zero-relative index in the receiver.
- * If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget ();
- if (index == -1) return;
- if (0 <= index && index < getItemCount ()) {
- int items = OS.ItemsControl_Items (handle);
- int item = OS.ItemCollection_GetItemAt (items, index);
- OS.GCHandle_Free (items);
- ignoreSelection = true;
- OS.ListBoxItem_IsSelected (item, false);
- ignoreSelection = false;
- OS.GCHandle_Free (item);
- }
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. The range of the
- * indices is inclusive. Indices that are out of range are ignored.
- *
- * @param start the start index of the items to deselect
- * @param end the end index of the items to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int start, int end) {
- checkWidget ();
- if (start > end) return;
- int count = getItemCount ();
- int items = OS.ItemsControl_Items (handle);
- ignoreSelection = true;
- for (int i = end; i >= start; i--) {
- if (0 <= i && i < count) {
- int item = OS.ItemCollection_GetItemAt (items, i);
- OS.ListBoxItem_IsSelected (item, false);
- OS.GCHandle_Free (item);
- }
- }
- ignoreSelection = false;
- OS.GCHandle_Free (items);
-}
-
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll () {
- checkWidget ();
- ignoreSelection = true;
- OS.ListBox_UnselectAll (handle);
- ignoreSelection = false;
-}
-
-/**
- * Returns the zero-relative index of the item which currently
- * has the focus in the receiver, or -1 if no item has focus.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getFocusIndex () {
- checkWidget ();
- int items = OS.ItemsControl_Items (handle);
- int index = OS.ItemCollection_CurrentPosition (items);
- OS.GCHandle_Free (items);
- return index;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getItem (int index) {
- checkWidget ();
- int count = getItemCount ();
- if (index < 0 || index >= count) error (SWT.ERROR_INVALID_RANGE);
- int items = OS.ItemsControl_Items (handle);
- int item = OS.ItemCollection_GetItemAt (items, index);
- int content = OS.ContentControl_Content (item);
- String string = createJavaString (content);
- OS.GCHandle_Free (item);
- OS.GCHandle_Free (items);
- OS.GCHandle_Free (content);
- return string;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- int items = OS.ItemsControl_Items (handle);
- int count = OS.ItemCollection_Count (items);
- OS.GCHandle_Free (items);
- return count;
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the list.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- //FIXME what is the default size?
- if (!OS.ItemsControl_HasItems (handle)) return 16;
- int items = OS.ItemsControl_Items (handle);
- int item = OS.ItemCollection_GetItemAt (items, 0);
- double height = OS.FrameworkElement_ActualHeight (item);
- OS.GCHandle_Free (item);
- OS.GCHandle_Free (items);
- return height != 0 ? (int) height : 16;
-}
-
-/**
- * Returns a (possibly empty) array of <code>String</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver's list
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getItems () {
- checkWidget ();
- int count = getItemCount ();
- String [] result = new String [count];
- for (int i=0; i<count; i++) result [i] = getItem (i);
- return result;
-}
-
-/**
- * Returns an array of <code>String</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String [] getSelection () {
- checkWidget ();
- int [] indices = getSelectionIndices ();
- String [] result = new String [indices.length];
- for (int i=0; i<indices.length; i++) {
- result [i] = getItem (indices [i]);
- }
- return result;
-}
-
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget ();
- int selectedItems = OS.ListBox_SelectedItems (handle);
- int result = OS.ICollection_Count (selectedItems);
- OS.GCHandle_Free (selectedItems);
- return result;
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item or -1
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget ();
- return OS.Selector_SelectedIndex (handle);
-}
-
-/**
- * Returns the zero-relative indices of the items which are currently
- * selected in the receiver. The order of the indices is unspecified.
- * The array is empty if no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return the array of indices of the selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int [] getSelectionIndices () {
- checkWidget ();
- int items = OS.ItemsControl_Items (handle);
- int list = OS.ListBox_SelectedItems (handle);
- int enumerator = OS.IList_GetEnumerator (list);
- int count = OS.ICollection_Count (list);
- int [] indices = new int [count];
- int index = 0;
- while (OS.IEnumerator_MoveNext (enumerator)) {
- int item = OS.IEnumerator_Current (enumerator);
- indices [index++] = OS.ItemCollection_IndexOf (items, item);
- OS.GCHandle_Free (item);
- }
- OS.GCHandle_Free (enumerator);
- OS.GCHandle_Free (list);
- OS.GCHandle_Free (items);
- sortAscending (indices);
- return indices;
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items are
- * scrolled or new items are added or removed.
- *
- * @return the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget ();
- int topIndex = 0;
- if (OS.ItemsControl_HasItems (handle)) {
- int items = OS.ItemsControl_Items (handle);
- int item = OS.ItemCollection_GetItemAt (items, 0);
- OS.GCHandle_Free (items);
- int virtualizingStackPanel = OS.VisualTreeHelper_GetParent (item);
- OS.GCHandle_Free (item);
- if (virtualizingStackPanel != 0) {
- topIndex = (int) OS.VirtualizingStackPanel_VerticalOffset (virtualizingStackPanel);
- OS.GCHandle_Free (virtualizingStackPanel);
- }
- }
- return topIndex;
-}
-
-void HandleMouseDoubleClick (int sender, int e) {
- if (!checkEvent (e)) return;
- postEvent (SWT.DefaultSelection);
-}
-
-void HandleSelectionChanged (int sender, int e) {
- if (!checkEvent (e)) return;
- if (!ignoreSelection) postEvent(SWT.Selection);
-}
-
-void HandlePreviewKeyDown (int sender, int e) {
- super.HandlePreviewKeyDown (sender, e);
- if (!checkEvent (e)) return;
- int key = OS.KeyEventArgs_Key (e);
- if (key == OS.Key_Return) {
- postEvent (SWT.DefaultSelection);
- }
-}
-
-void hookEvents () {
- super.hookEvents ();
- int handler = OS.gcnew_SelectionChangedEventHandler (jniRef, "HandleSelectionChanged");
- OS.Selector_SelectionChanged (handle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_MouseButtonEventHandler (jniRef, "HandleMouseDoubleClick");
- OS.Control_MouseDoubleClick (handle, handler);
- OS.GCHandle_Free (handler);
-}
-
-/**
- * Gets the index of an item.
- * <p>
- * The list is searched starting at 0 until an
- * item is found that is equal to the search item.
- * If no item is found, -1 is returned. Indexing
- * is zero based.
- *
- * @param string the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string) {
- return indexOf (string, 0);
-}
-
-/**
- * Searches the receiver's list starting at the given,
- * zero-relative index until an item is found that is equal
- * to the argument, and returns the index of that item. If
- * no item is found or the starting index is out of range,
- * returns -1.
- *
- * @param string the search item
- * @param start the zero-relative index at which to start the search
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (String string, int start) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = getItemCount ();
- if (start >= count) return -1;
- start = Math.max (start, 0);
- int strPtr = createDotNetString (string, false);
- int items = OS.ItemsControl_Items (handle);
- int index = -1;
- while (start < count && index == -1) {
- int item = OS.ItemCollection_GetItemAt (items, start);
- int content = OS.ContentControl_Content (item);
- OS.GCHandle_Free (item);
- if (content != 0) {
- if (OS.Object_Equals (content, strPtr)) index = start;
- OS.GCHandle_Free (content);
- }
- start++;
- }
- OS.GCHandle_Free (strPtr);
- OS.GCHandle_Free (items);
- return index;
-}
-
-/**
- * Returns <code>true</code> if the item is selected,
- * and <code>false</code> otherwise. Indices out of
- * range are ignored.
- *
- * @param index the index of the item
- * @return the selection state of the item at the index
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isSelected (int index) {
- checkWidget ();
- boolean selected = false;
- if (index >= 0 && index < getItemCount ()) {
- int items = OS.ItemsControl_Items (handle);
- int item = OS.ItemCollection_GetItemAt (items, index);
- selected = OS.ListBoxItem_IsSelected (item);
- OS.GCHandle_Free (items);
- OS.GCHandle_Free (item);
- }
- return selected;
-}
-
-/**
- * Removes the items from the receiver at the given
- * zero-relative indices.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- int [] newIndices = new int [indices.length];
- System.arraycopy (indices, 0, newIndices, 0, indices.length);
- sort (newIndices);
- int start = newIndices [newIndices.length - 1], end = newIndices [0];
- int count = getItemCount ();
- if (!(0 <= start && start <= end && end < count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int items = OS.ItemsControl_Items (handle);
- for (int i = newIndices.length-1; i >= 0; i--) {
- OS.ItemCollection_RemoveAt (items, indices [i]);
- }
- OS.GCHandle_Free (items);
-}
-
-/**
- * Removes the item from the receiver at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget ();
- if (index < 0 || index >= getItemCount ()) error (SWT.ERROR_INVALID_RANGE);
- int items = OS.ItemsControl_Items (handle);
- OS.ItemCollection_RemoveAt (items, index);
- OS.GCHandle_Free (items);
-}
-
-/**
- * Removes the items from the receiver which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget ();
- if (start > end) return;
- int count = getItemCount ();
- if (!(0 <= start && start <= end && end < count)) error (SWT.ERROR_INVALID_RANGE);
- if (start == 0 && end == count - 1) {
- removeAll ();
- return;
- }
- int items = OS.ItemsControl_Items (handle);
- for (int i = end; i >= start; i--) {
- OS.ItemCollection_RemoveAt (items, i);
- }
- OS.GCHandle_Free (items);
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * until an item is found that is equal to the argument,
- * and removes that item from the list.
- *
- * @param string the item to remove
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = indexOf (string, 0);
- if (index == -1) error (SWT.ERROR_INVALID_ARGUMENT);
- remove (index);
-}
-
-/**
- * Removes all of the items from the receiver.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget ();
- int items = OS.ItemsControl_Items (handle);
- ignoreSelection = true;
- OS.ItemCollection_Clear (items);
- ignoreSelection = false;
- OS.GCHandle_Free (items);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If the item at a given index is not selected, it is selected.
- * If the item at a given index was already selected, it remains selected.
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- *
- * @param indices the array of indices for the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#setSelection(int[])
- */
-public void select (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- select (indices, false);
-}
-
-void select (int [] indices, boolean scroll) {
- int i = 0;
- while (i < indices.length) {
- int index = indices [i];
- if (index != -1) {
- select (index, false);
- }
- i++;
- }
- if (scroll) showSelection ();
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget ();
- select (index, false);
-}
-
-void select (int index, boolean scroll) {
- if (index < 0) return;
- int count = getItemCount ();
- if (index >= count) return;
- int items = OS.ItemsControl_Items (handle);
- int item = OS.ItemCollection_GetItemAt (items, index);
- OS.GCHandle_Free (items);
- ignoreSelection = true;
- OS.ListBoxItem_IsSelected (item, true);
- ignoreSelection = false;
- if (scroll) OS.FrameworkElement_BringIntoView (item);
- OS.GCHandle_Free (item);
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If an item in the given range is not selected, it is selected.
- * If an item in the given range was already selected, it remains selected.
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#setSelection(int,int)
- */
-public void select (int start, int end) {
- checkWidget ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- int count = getItemCount ();
- if (count == 0 || start >= count) return;
- start = Math.max (0, start);
- end = Math.min (end, count - 1);
- ignoreSelection = true;
- if ((style & SWT.SINGLE) != 0) {
- select (start, false);
- } else {
- select (start, end, false);
- }
- ignoreSelection = false;
-}
-
-void select (int start, int end, boolean scroll) {
- int items = OS.ItemsControl_Items (handle);
- ignoreSelection = true;
- for (int i = start; i<=end; i++) {
- int item = OS.ItemCollection_GetItemAt (items, i);
- OS.ListBoxItem_IsSelected (item, true);
- OS.GCHandle_Free (item);
- }
- ignoreSelection = false;
- OS.GCHandle_Free (items);
- if (scroll) showSelection ();
-}
-
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- ignoreSelection = true;
- OS.ListBox_SelectAll (handle);
- ignoreSelection = false;
-}
-
-/**
- * Sets the text of the item in the receiver's list at the given
- * zero-relative index to the string argument.
- *
- * @param index the index for the item
- * @param string the new text for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItem (int index, String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int topIndex = getTopIndex ();
- boolean isSelected = isSelected (index);
- remove (index);
- add (string, index);
- if (isSelected) select (index, false);
- setTopIndex (topIndex);
-}
-
-/**
- * Sets the receiver's items to be the given array of items.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setItems (String [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<items.length; i++) {
- if (items [i] == null) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int itemCollection = OS.ItemsControl_Items (handle);
- ignoreSelection = true;
- OS.ItemCollection_Clear (itemCollection);
- for (int i = 0; i < items.length; i++) {
- String string = items [i];
- int item = OS.gcnew_ListBoxItem ();
- int strPtr = createDotNetString (string, false);
- OS.ContentControl_Content (item, strPtr);
- OS.GCHandle_Free (strPtr);
- OS.ItemCollection_Add (itemCollection, item);
- OS.GCHandle_Free (item);
- }
- ignoreSelection = false;
- OS.GCHandle_Free (itemCollection);
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- *
- * @param indices the indices of the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int[])
- */
-public void setSelection (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- select (indices, true);
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int[])
- * @see List#setSelection(int[])
- */
-public void setSelection (String [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = items.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- for (int i=length-1; i>=0; --i) {
- String string = items [i];
- int index = 0;
- if (string != null) {
- while ((index = indexOf (string, index)) != -1) {
- select (index, false);
- if ((style & SWT.SINGLE) != 0 && isSelected (index)) {
- showSelection ();
- return;
- }
- index++;
- }
- }
- }
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains selected.
- * The current selection is first cleared, then the new item is selected.
- * Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @see List#deselectAll()
- * @see List#select(int)
- */
-public void setSelection (int index) {
- checkWidget ();
- deselectAll ();
- select (index, true);
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- *
- * @param start the start index of the items to select
- * @param end the end index of the items to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see List#deselectAll()
- * @see List#select(int,int)
- */
-public void setSelection (int start, int end) {
- checkWidget ();
- deselectAll ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- int count = getItemCount ();
- if (count == 0 || start >= count) return;
- start = Math.max (0, start);
- end = Math.min (end, count - 1);
- if ((style & SWT.SINGLE) != 0) {
- select (start, true);
- } else {
- select (start, end, true);
- }
-}
-
-/**
- * Sets the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items
- * are scrolled or new items are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget ();
- //FIXME: VirtualizingStackPanel.VerticalIndex cannot be set.
-}
-
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void showSelection () {
- //TODO: does this scroll the first selected item into view if
- // part of the selection is visible already???
- checkWidget ();
- int items = OS.ItemsControl_Items (handle);
- int selectedItems = OS.ListBox_SelectedItems (handle);
- int enumerator = OS.IList_GetEnumerator (selectedItems);
- if (OS.IEnumerator_MoveNext (enumerator)) {
- int item = OS.IEnumerator_Current (enumerator);
- OS.ListBox_ScrollIntoView (handle, item);
- OS.GCHandle_Free (item);
- }
- OS.GCHandle_Free (enumerator);
- OS.GCHandle_Free (selectedItems);
- OS.GCHandle_Free (items);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Menu.java
deleted file mode 100644
index b6462e7c77..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Menu.java
+++ /dev/null
@@ -1,916 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are user interface objects that contain
- * menu items.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BAR, DROP_DOWN, POP_UP, NO_RADIO_GROUP</dd>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Help, Hide, Show </dd>
- * </dl>
- * <p>
- * Note: Only one of BAR, DROP_DOWN and POP_UP may be specified.
- * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#menu">Menu snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Menu extends Widget {
- int itemCount;
- MenuItem cascade, selected;
- Decorations parent;
-
-/**
- * Constructs a new instance of this class given its parent,
- * and sets the style for the instance so that the instance
- * will be a popup menu on the given parent's shell.
- * <p>
- * After constructing a menu, it can be set into its parent
- * using <code>parent.setMenu(menu)</code>. In this case, the parent may
- * be any control in the same widget tree as the parent.
- * </p>
- *
- * @param parent a control which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#POP_UP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Control parent) {
- this (checkNull (parent).menuShell (), SWT.POP_UP);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Decorations</code>) and a style value
- * describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * After constructing a menu or menuBar, it can be set into its parent
- * using <code>parent.setMenu(menu)</code> or <code>parent.setMenuBar(menuBar)</code>.
- * </p>
- *
- * @param parent a decorations control which will be the parent of the new instance (cannot be null)
- * @param style the style of menu to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BAR
- * @see SWT#DROP_DOWN
- * @see SWT#POP_UP
- * @see SWT#NO_RADIO_GROUP
- * @see SWT#LEFT_TO_RIGHT
- * @see SWT#RIGHT_TO_LEFT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Decorations parent, int style) {
- this (parent, checkStyle (style), 0);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>) and sets the style
- * for the instance so that the instance will be a drop-down
- * menu on the given parent's parent.
- * <p>
- * After constructing a drop-down menu, it can be set into its parentMenu
- * using <code>parentMenu.setMenu(menu)</code>.
- * </p>
- *
- * @param parentMenu a menu which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (Menu parentMenu) {
- this (checkNull (parentMenu).parent, SWT.DROP_DOWN);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>MenuItem</code>) and sets the style
- * for the instance so that the instance will be a drop-down
- * menu on the given parent's parent menu.
- * <p>
- * After constructing a drop-down menu, it can be set into its parentItem
- * using <code>parentItem.setMenu(menu)</code>.
- * </p>
- *
- * @param parentItem a menu item which will be the parent of the new instance (cannot be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Menu (MenuItem parentItem) {
- this (checkNull (parentItem).parent);
-}
-
-Menu (Decorations parent, int style, int handle) {
- super (parent, checkStyle (style));
- this.parent = parent;
- this.handle = handle;
- createWidget ();
-}
-
-void _setVisible (boolean visible) {
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- OS.ContextMenu_IsOpen (handle, visible);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when help events are generated for the control,
- * by sending it one of the messages defined in the
- * <code>HelpListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when menus are hidden or shown, by sending it
- * one of the messages defined in the <code>MenuListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuListener
- * @see #removeMenuListener
- */
-public void addMenuListener (MenuListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Hide,typedListener);
- addListener (SWT.Show,typedListener);
-}
-
-static Control checkNull (Control control) {
- if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return control;
-}
-
-static Menu checkNull (Menu menu) {
- if (menu == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return menu;
-}
-
-static MenuItem checkNull (MenuItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0);
-}
-
-void createHandle () {
- int bits = SWT.BAR | SWT.DROP_DOWN | SWT.POP_UP;
- switch (style & bits) {
- case SWT.BAR:
- handle = OS.gcnew_Menu ();
- if (handle == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- break;
- case SWT.POP_UP:
- handle = OS.gcnew_ContextMenu ();
- if (handle == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- OS.ContextMenu_Placement (handle, OS.PlacementMode_MousePoint);
- break;
- case SWT.DROP_DOWN:
- handle = OS.gcnew_CompositeCollection ();
- if (handle == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- int defaultItem = OS.gcnew_MenuItem ();
- OS.CompositeCollection_Insert (handle, 0, defaultItem);
- OS.GCHandle_Free (defaultItem);
- break;
- }
-}
-
-void createItem (MenuItem item, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- item.createWidget ();
- if ((style & SWT.DROP_DOWN) != 0) {
- if (itemCount == 0) OS.CompositeCollection_RemoveAt (handle, 0);
- OS.CompositeCollection_Insert (handle, index, item.handle);
- } else {
- int items = OS.ItemsControl_Items (handle);
- OS.ItemCollection_Insert (items, index, item.handle);
- OS.GCHandle_Free (items);
- }
- itemCount++;
-}
-
-void createWidget () {
- checkOrientation (parent);
- super.createWidget ();
- parent.addMenu (this);
-}
-
-void deregister () {
- if ((style & SWT.DROP_DOWN) != 0) return;
- display.removeWidget (handle);
-}
-
-void destroyItem (MenuItem item) {
- if ((style & SWT.DROP_DOWN) != 0) {
- OS.CompositeCollection_Remove (handle, item.handle);
- if (itemCount == 1) {
- int defaultItem = OS.gcnew_MenuItem ();
- OS.CompositeCollection_Insert (handle, 0, defaultItem);
- OS.GCHandle_Free (defaultItem);
- }
- } else {
- int items = OS.ItemsControl_Items (handle);
- OS.ItemCollection_Remove (items, item.handle);
- OS.GCHandle_Free (items);
- }
- itemCount--;
-}
-
-void fixMenus (Decorations newParent) {
- MenuItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- items [i].fixMenus (newParent);
- }
- parent.removeMenu (this);
- newParent.addMenu (this);
- this.parent = newParent;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null),
- * unless the receiver is a menu or a shell. In this case, the
- * location is relative to the display.
- * <p>
- * Note that the bounds of a menu or menu item are undefined when
- * the menu is not visible. This is because most platforms compute
- * the bounds of a menu dynamically just before it is displayed.
- * </p>
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-/*public*/ Rectangle getBounds () {
- checkWidget ();
- if ((style & SWT.DROP_DOWN) != 0) return new Rectangle (0, 0, 0, 0);
- if (!OS.UIElement_IsVisible (handle)) return new Rectangle (0, 0, 0, 0);
- int point = OS.gcnew_Point (0, 0);
- int location = OS.UIElement_TranslatePoint (handle, point, parent.handle);
- int x = (int) OS.Point_X (location);
- int y = (int) OS.Point_Y (location);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (location);
- int width = (int) OS.FrameworkElement_ActualWidth (handle);
- int height = (int) OS.FrameworkElement_ActualHeight (handle);
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the default menu item or null if none has
- * been previously set.
- *
- * @return the default menu item.
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getDefaultItem () {
- checkWidget ();
- return null;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled menu is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget ();
- return (state & DISABLED) == 0;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getItem (int index) {
- checkWidget ();
- if (index < 0 || index >= itemCount) error(SWT.ERROR_INVALID_RANGE);
- if ((style & SWT.DROP_DOWN) != 0) return getItem (handle, index);
- int items = OS.ItemsControl_Items (handle);
- MenuItem result = getItem (items, index);
- OS.GCHandle_Free (items);
- return result;
-}
-
-MenuItem getItem (int items, int index) {
- int item;
- if ((style & SWT.DROP_DOWN) != 0) {
- item = OS.IList_default (handle, index);
- } else {
- item = OS.ItemCollection_GetItemAt (items, index);
- }
- MenuItem result = (MenuItem) display.getWidget (item);
- OS.GCHandle_Free (item);
- return result;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return itemCount;
-}
-
-/**
- * Returns a (possibly empty) array of <code>MenuItem</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem [] getItems () {
- checkWidget ();
- MenuItem [] result = new MenuItem [itemCount];
- int items = (style & SWT.DROP_DOWN) == 0 ? OS.ItemsControl_Items (handle) : handle;
- for (int i = 0; i < itemCount; i++) {
- result [i] = getItem (items, i);
- }
- if (items != handle) OS.GCHandle_Free (items);
- return result;
-}
-
-String getNameText () {
- String result = "";
- MenuItem [] items = getItems ();
- int length = items.length;
- if (length > 0) {
- for (int i=0; i<length-1; i++) {
- result = result + items [i].getNameText() + ", ";
- }
- result = result + items [length-1].getNameText ();
- }
- return result;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Decorations</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Decorations getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>MenuItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public MenuItem getParentItem () {
- checkWidget ();
- return cascade;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>Menu</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getParentMenu () {
- checkWidget ();
- if (cascade != null) return cascade.parent;
- return null;
-}
-
-/**
- * Returns the receiver's shell. For all controls other than
- * shells, this simply returns the control's nearest ancestor
- * shell. Shells return themselves, even if they are children
- * of other shells.
- *
- * @return the receiver's shell
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getParent
- */
-public Shell getShell () {
- checkWidget ();
- return parent.getShell ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- if ((style & SWT.BAR) != 0) {
- return this == parent.menuShell ().menuBar;
- }
- if ((style & SWT.POP_UP) != 0) {
- Menu [] popups = display.popups;
- if (popups == null) return false;
- for (int i=0; i<popups.length; i++) {
- if (popups [i] == this) return true;
- }
- }
-// Shell shell = getShell ();
-// Menu menu = shell.activeMenu;
-// while (menu != null && menu != this) {
-// menu = menu.getParentMenu ();
-// }
-// return this == menu;
- return OS.UIElement_Visibility (handle) == OS.Visibility_Visible;
-}
-
-void HandleClosed (int sender, int e) {
- if (!checkEvent (e)) return;
- sendEvent (SWT.Hide);
-}
-
-void HandleOpened (int sender, int e) {
- if (!checkEvent (e)) return;
- sendEvent (SWT.Show);
-}
-
-void hookEvents() {
- super.hookEvents ();
- if ((style & SWT.POP_UP) != 0) {
- int handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleClosed");
- OS.ContextMenu_Closed (handle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleOpened");
- OS.ContextMenu_Opened (handle, handler);
- OS.GCHandle_Free (handler);
- }
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (MenuItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- int index = -1;
- if ((style & SWT.DROP_DOWN) != 0) {
- index = OS.CompositeCollection_IndexOf (handle, item.handle);
- } else {
- int items = OS.ItemsControl_Items (handle);
- index = OS.ItemCollection_IndexOf (items, item.handle);
- OS.GCHandle_Free (items);
- }
- return index;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled menu is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget ();
- Menu parentMenu = getParentMenu ();
- if (parentMenu == null) return getEnabled ();
- return getEnabled () && parentMenu.isEnabled ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget ();
- return getVisible ();
-}
-
-void register() {
- if ((style & SWT.DROP_DOWN) != 0) return;
- display.addWidget (handle, this);
-}
-
-void releaseChildren (boolean destroy) {
- MenuItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.release (false);
- }
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (handle != 0) OS.GCHandle_Free (handle);
- handle = 0;
- parent = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (cascade != null) cascade.releaseMenu ();
- if ((style & SWT.BAR) != 0) {
- if (this == parent.menuBar) {
- parent.setMenuBar (null);
- }
- } else {
- if ((style & SWT.POP_UP) != 0) {
- display.removePopup (this);
- }
- }
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (parent != null) parent.removeMenu (this);
- parent = null;
- cascade = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the menu events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuListener
- * @see #addMenuListener
- */
-public void removeMenuListener (MenuListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Hide, listener);
- eventTable.unhook (SWT.Show, listener);
-}
-
-/**
- * Sets the default menu item to the argument or removes
- * the default emphasis when the argument is <code>null</code>.
- *
- * @param item the default menu item or null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the menu item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDefaultItem (MenuItem item) {
- checkWidget ();
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled menu is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget ();
- state &= ~DISABLED;
- if (!enabled) state |= DISABLED;
-}
-
-/**
- * Sets the location of the receiver, which must be a popup,
- * to the point specified by the arguments which are relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p><p>
- * Note that the platform window manager ultimately has control
- * over the location of popup menus.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLocation (int x, int y) {
- checkWidget ();
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- OS.ContextMenu_Placement (handle, OS.PlacementMode_AbsolutePoint);
- OS.ContextMenu_HorizontalOffset (handle, x);
- OS.ContextMenu_VerticalOffset (handle, y);
-}
-
-/**
- * Sets the location of the receiver, which must be a popup,
- * to the point specified by the argument which is relative
- * to the display.
- * <p>
- * Note that this is different from most widgets where the
- * location of the widget is relative to the parent.
- * </p><p>
- * Note that the platform window manager ultimately has control
- * over the location of popup menus.
- * </p>
- *
- * @param location the new location for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void setLocation (Point location) {
- checkWidget ();
- if (location == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
-void setNameScope() {
- // DO NOTHING
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- if (visible) {
- display.addPopup (this);
- } else {
- display.removePopup (this);
- _setVisible (false);
- }
-}
-
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/MenuItem.java
deleted file mode 100644
index cc5a802a22..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/MenuItem.java
+++ /dev/null
@@ -1,739 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that issues notification when pressed and released.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>CHECK, CASCADE, PUSH, RADIO, SEPARATOR</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Arm, Help, Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR
- * may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class MenuItem extends Item {
- Menu parent, menu;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a menu control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#CHECK
- * @see SWT#CASCADE
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public MenuItem (Menu parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Menu</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a menu control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#CHECK
- * @see SWT#CASCADE
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public MenuItem (Menu parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the arm events are generated for the control, by sending
- * it one of the messages defined in the <code>ArmListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ArmListener
- * @see #removeArmListener
- */
-public void addArmListener (ArmListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Arm, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the help events are generated for the control, by sending
- * it one of the messages defined in the <code>HelpListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
- */
-public void addHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the menu item is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the stateMask field of the event object is valid.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the menu item is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.CASCADE, 0);
-}
-
-void createHandle () {
- if ((style & SWT.SEPARATOR) != 0) {
- handle = OS.gcnew_Separator ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- } else {
- handle = OS.gcnew_MenuItem ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) OS.MenuItem_IsCheckable (handle, true);
- }
-}
-
-void deregister () {
- display.removeWidget (handle);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-void fixMenus (Decorations newParent) {
- if (menu != null) menu.fixMenus (newParent);
-}
-
-/**
- * Returns the widget accelerator. An accelerator is the bit-wise
- * OR of zero or more modifier masks and a key. Examples:
- * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
- * The default value is zero, indicating that the menu item does
- * not have an accelerator.
- *
- * @return the accelerator or 0
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAccelerator () {
- checkWidget ();
- //FIXME
- return 0;
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null).
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-/*public*/ Rectangle getBounds () {
- checkWidget ();
- if (!OS.UIElement_IsVisible(handle)) return new Rectangle (0, 0, 0, 0);
- int point = OS.gcnew_Point (0, 0);
- if (point == 0) error(SWT.ERROR_NO_HANDLES);
- int location = OS.UIElement_TranslatePoint (handle, point, parent.handle);
- int x = (int) OS.Point_X (location);
- int y = (int) OS.Point_Y (location);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (location);
- int width = (int) OS.FrameworkElement_ActualWidth (handle);
- int height = (int) OS.FrameworkElement_ActualHeight (handle);
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled menu item is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget ();
- return OS.UIElement_IsEnabled (handle);
-
-}
-
-/**
- * Returns the receiver's cascade menu if it has one or null
- * if it does not. Only <code>CASCADE</code> menu items can have
- * a pull down menu. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pull down
- * menu is platform specific.
- *
- * @return the receiver's menu
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getMenu () {
- checkWidget ();
- return menu;
-}
-
-String getNameText () {
- if ((style & SWT.SEPARATOR) != 0) return "|";
- return super.getNameText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Menu</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Menu getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked.
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget ();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
- return OS.MenuItem_IsChecked (handle);
-}
-
-void HandleClick (int sender, int e) {
- if (!checkEvent (e)) return;
- if ((style & SWT.RADIO) != 0 && (parent.style & SWT.NO_RADIO_GROUP) == 0) {
- if (parent.selected == this) {
- OS.MenuItem_IsChecked (handle, true);
- return;
- }
- if (parent.selected != null) OS.MenuItem_IsChecked (parent.selected.handle, false);
- parent.selected = this;
- }
- Event event = new Event ();
- setInputState (event, SWT.Selection, 0, 0);
- postEvent (SWT.Selection, event);
-}
-
-void HandleSubmenuOpened (int sender, int e) {
- if (!checkEvent (e)) return;
- if (menu != null) {
- menu.sendEvent (SWT.Show);
- }
-}
-
-void HandleSubmenuClosed (int sender, int e) {
- if (!checkEvent (e)) return;
- if (menu != null) {
- menu.sendEvent (SWT.Hide);
- }
-}
-
-void hookEvents() {
- if ((style & SWT.SEPARATOR) != 0) return;
- super.hookEvents();
- if ((style & SWT.CASCADE) == 0) {
- int handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleClick");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.MenuItem_Click (handle, handler);
- OS.GCHandle_Free (handler);
- } else {
- int handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleSubmenuOpened");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.MenuItem_SubmenuOpened (handle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleSubmenuClosed");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.MenuItem_SubmenuClosed (handle, handler);
- OS.GCHandle_Free (handler);
- }
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled menu item is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- return getEnabled () && parent.isEnabled ();
-}
-
-void register() {
- display.addWidget (handle, this);
-}
-
-void releaseChildren (boolean destroy) {
- if (menu != null) {
- menu.release (false);
- menu = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (handle != 0) OS.GCHandle_Free (handle);
- handle = 0;
- parent = null;
-}
-
-void releaseMenu () {
- setMenu (null);
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (menu != null) menu.dispose ();
- menu = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the arm events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ArmListener
- * @see #addArmListener
- */
-public void removeArmListener (ArmListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Arm, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */
-public void removeHelpListener (HelpListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Sets the widget accelerator. An accelerator is the bit-wise
- * OR of zero or more modifier masks and a key. Examples:
- * <code>SWT.MOD1 | SWT.MOD2 | 'T', SWT.MOD3 | SWT.F2</code>.
- * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
- * The default value is zero, indicating that the menu item does
- * not have an accelerator.
- *
- * @param accelerator an integer that is the bit-wise OR of masks and a key
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAccelerator (int accelerator) {
- checkWidget ();
- //FIXME
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled menu item is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget ();
- OS.UIElement_IsEnabled (handle, enabled);
-}
-
-/**
- * Sets the image the receiver will display to the argument.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept (for example, Windows NT).
- * Furthermore, some platforms (such as GTK), cannot display both
- * a check box and an image at the same time. Instead, they hide
- * the image and display the check box.
- * </p>
- *
- * @param image the image to display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return;
- if (image != null && image.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- this.image = image;
- if (image != null) {
- int img = OS.gcnew_Image ();
- if (img == 0) error(SWT.ERROR_NO_HANDLES);
- OS.Image_Source (img, image.handle);
- OS.Image_Stretch (img, OS.Stretch_None);
- OS.MenuItem_Icon (handle, img);
- OS.GCHandle_Free (img);
- } else {
- OS.MenuItem_Icon (handle, 0);
- }
-}
-
-/**
- * Sets the receiver's pull down menu to the argument.
- * Only <code>CASCADE</code> menu items can have a
- * pull down menu. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pull down
- * menu is platform specific.
- * <p>
- * Note: Disposing of a menu item that has a pull down menu
- * will dispose of the menu. To avoid this behavior, set the
- * menu to null before the menu item is disposed.
- * </p>
- *
- * @param menu the new pull down menu
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_MENU_NOT_DROP_DOWN - if the menu is not a drop down menu</li>
- * <li>ERROR_MENUITEM_NOT_CASCADE - if the menu item is not a <code>CASCADE</code></li>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMenu (Menu menu) {
- checkWidget ();
- if ((style & SWT.CASCADE) == 0) error (SWT.ERROR_MENUITEM_NOT_CASCADE);
- if (menu != null) {
- if (menu.cascade != null) {
-// FIXME: Change this error type, or fix the javadoc.
- error (SWT.ERROR_INVALID_PARENT);
- }
- if (menu.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.DROP_DOWN) == 0) {
- error (SWT.ERROR_MENU_NOT_DROP_DOWN);
- }
- if (menu.parent != parent.parent) {
- error (SWT.ERROR_INVALID_PARENT);
- }
- Menu oldMenu = this.menu;
- if (oldMenu == menu) return;
- if (oldMenu != null) oldMenu.cascade = null;
- this.menu = menu;
- OS.ItemsControl_ItemsSource (handle, menu.handle);
- menu.cascade = this;
- } else {
- OS.ItemsControl_ItemsSource (handle, 0);
- if (this.menu != null) this.menu.cascade = null;
- }
-}
-
-/**
- * Sets the selection state of the receiver.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked.
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget ();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
- OS.MenuItem_IsChecked (handle, selected);
-}
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character and accelerator text.
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- * <p>
- * Accelerator text is indicated by the '\t' character.
- * On platforms that support accelerator text, the text
- * that follows the '\t' character is displayed to the user,
- * typically indicating the key stroke that will cause
- * the item to become selected. On most platforms, the
- * accelerator text appears right aligned in the menu.
- * Setting the accelerator text does not install the
- * accelerator key sequence. The accelerator key sequence
- * is installed using #setAccelerator.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setAccelerator
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- if (text.equals (string)) return;
- super.setText (string);
- String accelString = null;
- int index = string.indexOf ('\t');
- if (index != -1) {
- accelString = string.substring (index+1, string.length());
- string = string.substring (0, index);
- }
- int ptr = createDotNetString (string, true);
- OS.HeaderedItemsControl_Header (handle, ptr);
- OS.GCHandle_Free (ptr);
- if (accelString != null) {
- ptr = createDotNetString (accelString, false);
- OS.MenuItem_InputGestureText (handle, ptr);
- OS.GCHandle_Free (ptr);
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/MessageBox.java
deleted file mode 100644
index 1f870e8f36..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/MessageBox.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class are used to inform or warn the user.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, ICON_WARNING, ICON_WORKING</dd>
- * <dd>OK, OK | CANCEL</dd>
- * <dd>YES | NO, YES | NO | CANCEL</dd>
- * <dd>RETRY | CANCEL</dd>
- * <dd>ABORT | RETRY | IGNORE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION, ICON_QUESTION,
- * ICON_WARNING and ICON_WORKING may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class MessageBox extends Dialog {
- String message;
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public MessageBox (Shell parent) {
- this (parent, SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of dialog to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#ICON_ERROR
- * @see SWT#ICON_INFORMATION
- * @see SWT#ICON_QUESTION
- * @see SWT#ICON_WARNING
- * @see SWT#ICON_WORKING
- * @see SWT#OK
- * @see SWT#CANCEL
- * @see SWT#YES
- * @see SWT#NO
- * @see SWT#ABORT
- * @see SWT#RETRY
- * @see SWT#IGNORE
- */
-public MessageBox (Shell parent, int style) {
- super (parent, checkStyle (parent, checkStyle (style)));
- checkSubclass ();
- message = "";
-}
-
-static int checkStyle (int style) {
- int mask = (SWT.YES | SWT.NO | SWT.OK | SWT.CANCEL | SWT.ABORT | SWT.RETRY | SWT.IGNORE);
- int bits = style & mask;
- if (bits == SWT.OK || bits == SWT.CANCEL || bits == (SWT.OK | SWT.CANCEL)) return style;
- if (bits == SWT.YES || bits == SWT.NO || bits == (SWT.YES | SWT.NO) || bits == (SWT.YES | SWT.NO | SWT.CANCEL)) return style;
- if (bits == (SWT.RETRY | SWT.CANCEL) || bits == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) return style;
- style = (style & ~mask) | SWT.OK;
- return style;
-}
-
-/**
- * Returns the dialog's message, or an empty string if it does not have one.
- * The message is a description of the purpose for which the dialog was opened.
- * This message will be visible in the dialog while it is open.
- *
- * @return the message
- */
-public String getMessage () {
- return message;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return the ID of the button that was selected to dismiss the
- * message box (e.g. SWT.OK, SWT.CANCEL, etc.)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
- */
-public int open () {
-
- /* Compute the MessageBox style */
- int buttonBits = 0;
- if ((style & SWT.OK) == SWT.OK) buttonBits = OS.MessageBoxButton_OK;
- if ((style & (SWT.OK | SWT.CANCEL)) == (SWT.OK | SWT.CANCEL)) buttonBits = OS.MessageBoxButton_OKCancel;
- if ((style & (SWT.YES | SWT.NO)) == (SWT.YES | SWT.NO)) buttonBits = OS.MessageBoxButton_YesNo;
- if ((style & (SWT.YES | SWT.NO | SWT.CANCEL)) == (SWT.YES | SWT.NO | SWT.CANCEL)) buttonBits = OS.MessageBoxButton_YesNoCancel;
- /*
- * Feature in WPF. MessageBoxButton does not define Retry, Abort, or
- * Ignore buttons. The work around is to use OK/Cancel instead and map
- * OK to Retry for Retry/Cancel, and Abort for Abort/Retry/Cancel message
- * boxes.
- */
- if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) buttonBits = OS.MessageBoxButton_OKCancel;
- if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) buttonBits = OS.MessageBoxButton_OKCancel;
- if (buttonBits == 0) buttonBits = OS.MessageBoxButton_OK;
-
- int iconBits = 0;
- if ((style & SWT.ICON_ERROR) != 0) iconBits = OS.MessageBoxImage_Error;
- if ((style & SWT.ICON_INFORMATION) != 0) iconBits = OS.MessageBoxImage_Information;
- if ((style & SWT.ICON_QUESTION) != 0) iconBits = OS.MessageBoxImage_Question;
- if ((style & SWT.ICON_WARNING) != 0) iconBits = OS.MessageBoxImage_Warning;
- if ((style & SWT.ICON_WORKING) != 0) iconBits = OS.MessageBoxImage_Information;
-
- int messagePtr = parent.createDotNetString (message, false);
- int titlePtr = parent.createDotNetString (title, false);
- int code = OS.MessageBox_Show (messagePtr, titlePtr, buttonBits, iconBits, 0);
- OS.GCHandle_Free (titlePtr);
- OS.GCHandle_Free (messagePtr);
-
- /* Compute and return the result */
- switch (code) {
- case OS.MessageBoxResult_No: return SWT.NO;
- case OS.MessageBoxResult_OK:
- if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) return SWT.RETRY;
- if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) return SWT.ABORT;
- return SWT.OK;
- case OS.MessageBoxResult_Yes: return SWT.YES;
- case OS.MessageBoxResult_Cancel:
- default:
- return SWT.CANCEL;
- }
-}
-
-/**
- * Sets the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @param string the message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- */
-public void setMessage (String string) {
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- message = string;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ProgressBar.java
deleted file mode 100644
index 98ca83622a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ProgressBar.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.wpf.*;
-
-/**
- * Instances of the receiver represent an unselectable
- * user interface object that is used to display progress,
- * typically in the form of a bar.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SMOOTH, HORIZONTAL, VERTICAL, INDETERMINATE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#progressbar">ProgressBar snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ProgressBar extends Control {
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SMOOTH
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#INDETERMINATE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ProgressBar (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += OS.SystemParameters_HorizontalScrollBarButtonWidth () * 10;
- height += OS.SystemParameters_HorizontalScrollBarHeight ();
- } else {
- width += OS.SystemParameters_VerticalScrollBarWidth ();
- height += OS.SystemParameters_VerticalScrollBarButtonHeight () * 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-
-void createHandle () {
- handle = OS.gcnew_ProgressBar();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.VERTICAL) != 0) OS.ProgressBar_Orientation (handle, OS.Orientation_Vertical);
- if ((style & SWT.INDETERMINATE) != 0) {
- OS.ProgressBar_IsIndeterminate (handle, true) ;
- }
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget ();
- return (int) OS.RangeBase_Maximum (handle);
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget ();
- return (int) OS.RangeBase_Minimum (handle);
-}
-
-/**
- * Returns the single 'selection' that is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget ();
- return (int) OS.RangeBase_Value (handle);
-}
-
-/**
- * Returns the state of the receiver. The value will be one of:
- * <ul>
- * <li>{@link SWT#NORMAL}</li>
- * <li>{@link SWT#ERROR}</li>
- * <li>{@link SWT#PAUSED}</li>
- * </ul>
- *
- * @return the state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public int getState () {
- checkWidget ();
- return SWT.NORMAL;
-}
-
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget ();
- int minimum = (int) OS.RangeBase_Minimum (handle);
- if (0 <= minimum && minimum < value) {
- OS.RangeBase_Maximum (handle, value);
- }
-
- //FIXME - If the new maximum is applied then the receiver's
- // selection value will be adjusted if necessary to fall within its new range.
-}
-
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is negative or is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be nonnegative and less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget ();
- int maximum = (int) OS.RangeBase_Maximum (handle);
- if (0 <= maximum && value < maximum) {
- OS.RangeBase_Minimum (handle, value);
- }
-
- //FIXME - If the new minimum is applied then the receiver's
- //selection value will be adjusted if necessary to fall within its new range
-}
-
-/**
- * Sets the single 'selection' that is the receiver's
- * position to the argument which must be greater than or equal
- * to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget ();
- if (value < 0) return;
- OS.RangeBase_Value (handle, value);
-}
-
-/**
- * Sets the state of the receiver. The state must be one of these values:
- * <ul>
- * <li>{@link SWT#NORMAL}</li>
- * <li>{@link SWT#ERROR}</li>
- * <li>{@link SWT#PAUSED}</li>
- * </ul>
- *
- * @param state the new state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setState (int state) {
- checkWidget ();
- //NOT IMPLEMENTED
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Sash.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Sash.java
deleted file mode 100644
index 9aeb38b1ea..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Sash.java
+++ /dev/null
@@ -1,305 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of the receiver represent a selectable user interface object
- * that allows the user to drag a rubber banded outline of the sash within
- * the parent control.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL, SMOOTH</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#sash">Sash snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Sash extends Control {
- boolean dragging;
- int startX, startY, lastX, lastY;
- final static int INCREMENT = 1;
- final static int PAGE_INCREMENT = 9;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see SWT#SMOOTH
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Sash (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the x, y, width, and height fields of the event object are valid.
- * If the receiver is being dragged, the event object detail field contains the value <code>SWT.DRAG</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-void createHandle () {
- state |= THEME_BACKGROUND;
- handle = OS.gcnew_Canvas ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.UIElement_Focusable (handle, true);
- int newCursor = (style & SWT.VERTICAL)!= 0 ? OS.Cursors_SizeWE () : OS.Cursors_SizeNS ();
- OS.FrameworkElement_Cursor (handle, newCursor);
- OS.GCHandle_Free (newCursor);
-}
-
-int defaultBackground () {
- return OS.SystemColors_ControlColor;
-}
-
-void HandlePreviewGotKeyboardFocus (int sender, int e) {
- super.HandlePreviewGotKeyboardFocus (sender, e);
- if (!checkEvent (e)) return;
- Point location = getLocation();
- lastX = location.x;
- lastY = location.y;
-}
-
-void HandlePreviewKeyDown (int sender, int e) {
- super.HandlePreviewKeyDown (sender, e);
- if (!checkEvent (e)) return;
- int key = OS.KeyEventArgs_Key (e);
- switch (key) {
- case OS.Key_Left:
- case OS.Key_Right:
- case OS.Key_Up:
- case OS.Key_Down:
- int xChange = 0, yChange = 0;
- int stepSize = PAGE_INCREMENT;
- int keyboardDevice = OS.KeyboardEventArgs_KeyboardDevice(e);
- int modifiers = OS.KeyboardDevice_Modifiers(keyboardDevice);
- OS.GCHandle_Free(keyboardDevice);
- if ((modifiers & OS.ModifierKeys_Control) != 0) stepSize = INCREMENT;
- if ((style & SWT.VERTICAL) != 0) {
- if (key == OS.Key_Up || key == OS.Key_Down) break;
- xChange = key == OS.Key_Left ? -stepSize : stepSize;
- } else {
- if (key == OS.Key_Left || key == OS.Key_Right) break;
- yChange = key == OS.Key_Up ? -stepSize : stepSize;
- }
-
- Rectangle bounds = getBounds ();
- int width = bounds.width, height = bounds.height;
- Rectangle parentBounds = parent.getBounds ();
- int parentWidth = parentBounds.width;
- int parentHeight = parentBounds.height;
- int newX = lastX, newY = lastY;
- if ((style & SWT.VERTICAL) != 0) {
- newX = Math.min (Math.max (0, lastX + xChange), parentWidth - width);
- } else {
- newY = Math.min (Math.max (0, lastY + yChange), parentHeight - height);
- }
- if (newX == lastX && newY == lastY) return;
- Event event = new Event ();
- event.x = newX;
- event.y = newY;
- event.width = width;
- event.height = height;
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) break;
- if (event.doit) {
- setBounds (event.x, event.y, width, height);
- if (isDisposed ()) break;
- lastX = event.x;
- lastY = event.y;
- if (isDisposed ()) return;
- int cursorX = event.x, cursorY = event.y;
- if ((style & SWT.VERTICAL) != 0) {
- cursorY += height / 2;
- } else {
- cursorX += width / 2;
- }
- display.setCursorLocation (parent.toDisplay (cursorX, cursorY));
- }
- OS.RoutedEventArgs_Handled(e, true);
- break;
- }
-}
-
-void HandlePreviewMouseDown (int sender, int e) {
- super.HandlePreviewMouseDown (sender, e);
- int eventPos = OS.MouseEventArgs_GetPosition (e, handle);
- startX = (int) OS.Point_X (eventPos);
- startY = (int) OS.Point_Y (eventPos);
- OS.GCHandle_Free (eventPos);
- Point location = parent.getLocation (this);
- int x = location.x;
- int y = location.y;
- int width = (int) OS.FrameworkElement_ActualWidth (handle);
- int height = (int) OS.FrameworkElement_ActualHeight (handle);
- lastX = x;
- lastY = y;
- Event event = new Event ();
- event.x = lastX;
- event.y = lastY;
- event.width = width;
- event.height = height;
- sendEvent (SWT.Selection, event);
- if (event.doit) {
- dragging = true;
- lastX = event.x;
- lastY = event.y;
- OS.UIElement_CaptureMouse (handle);
- }
-}
-
-void HandlePreviewMouseUp (int sender, int e) {
- super.HandlePreviewMouseUp (sender, e);
- if (!dragging) return;
- OS.UIElement_ReleaseMouseCapture (handle);
- dragging = false;
- int width = (int) OS.FrameworkElement_ActualWidth (handle);
- int height = (int) OS.FrameworkElement_ActualHeight (handle);
- Event event = new Event ();
- event.x = lastX;
- event.y = lastY;
- event.width = width;
- event.height = height;
- sendEvent (SWT.Selection, event);
-}
-
-void HandlePreviewMouseMove (int sender, int e) {
- super.HandlePreviewMouseMove (sender, e);
- if (!dragging) return;
- int eventPos = OS.MouseEventArgs_GetPosition (e, handle);
- int eventX = (int) OS.Point_X (eventPos);
- int eventY = (int) OS.Point_Y (eventPos);
- OS.GCHandle_Free (eventPos);
- Point location = parent.getLocation (this);
- int x = location.x;
- int y = location.y;
- int width = (int) OS.FrameworkElement_ActualWidth (handle);
- int height = (int) OS.FrameworkElement_ActualHeight (handle);
- int parentWidth = (int) OS.FrameworkElement_ActualWidth (parent.handle);
- int parentHeight = (int) OS.FrameworkElement_ActualHeight (parent.handle);
- int newX = lastX, newY = lastY;
- if ((style & SWT.VERTICAL) != 0) {
- newX = Math.min (Math.max (0, eventX + x - startX), parentWidth - width);
- } else {
- newY = Math.min (Math.max (0, eventY + y - startY), parentHeight - height);
- }
- if (newX == lastX && newY == lastY) return;
- Event event = new Event ();
- event.x = newX;
- event.y = newY;
- event.width = width;
- event.height = height;
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return;
- if (event.doit) {
- lastX = event.x;
- lastY = event.y;
- }
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-int traversalCode (int key, int event) {
- return 0;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Scale.java
deleted file mode 100644
index 776a370903..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Scale.java
+++ /dev/null
@@ -1,361 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of the receiver represent a selectable user
- * interface object that present a range of continuous
- * numeric values.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#scale">Scale snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Scale extends Control {
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Scale (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the user changes the receiver's value.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += OS.SystemParameters_HorizontalScrollBarButtonWidth () * 10;
- height += OS.SystemParameters_HorizontalScrollBarHeight () * 2;
- } else {
- width += OS.SystemParameters_VerticalScrollBarWidth () * 2;
- height += OS.SystemParameters_VerticalScrollBarButtonHeight () * 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-
-void createHandle () {
- state |= THEME_BACKGROUND;
- handle = OS.gcnew_Slider ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.VERTICAL) != 0) OS.Slider_Orientation (handle, OS.Orientation_Vertical);
- OS.RangeBase_Maximum (handle, 100);
- OS.RangeBase_LargeChange (handle, 10);
- OS.RangeBase_SmallChange (handle, 1);
- OS.Slider_TickFrequency (handle, 10);
- OS.Slider_TickPlacement (handle, OS.TickPlacement_Both);
-}
-
-int defaultBackground () {
- return OS.SystemColors_ControlColor;
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget ();
- return (int) OS.RangeBase_SmallChange (handle);
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget ();
- return (int) OS.RangeBase_Maximum (handle);
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget ();
- return (int) OS.RangeBase_Minimum (handle);
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget ();
- return (int) OS.RangeBase_LargeChange(handle);
-}
-
-/**
- * Returns the 'selection', which is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget ();
- return (int) OS.RangeBase_Value (handle);
-}
-
-void HandleValueChanged (int sender, int e) {
- if (!checkEvent (e)) return;
- postEvent (SWT.Selection);
-}
-
-void hookEvents() {
- super.hookEvents ();
- int handler = OS.gcnew_RoutedPropertyChangedEventHandler (jniRef, "HandleValueChanged");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.RangeBase_ValueChanged (handle, handler);
- OS.GCHandle_Free (handler);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param increment the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int increment) {
- checkWidget ();
- if (increment < 1) return;
- int minimum = (int) OS.RangeBase_Minimum(handle);
- int maximum = (int) OS.RangeBase_Maximum(handle);
- if (increment > maximum - minimum) return;
- OS.RangeBase_SmallChange(handle, increment);
-}
-
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget ();
- int minimum = (int) OS.RangeBase_Minimum (handle);
- if (0 <= minimum && minimum < value) OS.RangeBase_Maximum (handle, value);
-}
-
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is negative or is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be nonnegative and less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget ();
- int maximum = (int) OS.RangeBase_Maximum (handle);
- if (0 <= value && value < maximum) OS.RangeBase_Minimum (handle, value);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param pageIncrement the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int pageIncrement) {
- checkWidget ();
- if (pageIncrement < 1) return;
- int minimum = (int) OS.RangeBase_Minimum(handle);
- int maximum = (int) OS.RangeBase_Maximum(handle);
- if (pageIncrement > maximum - minimum) return;
- OS.RangeBase_LargeChange(handle, pageIncrement);
- OS.Slider_TickFrequency(handle, pageIncrement);
-}
-
-/**
- * Sets the 'selection', which is the receiver's value,
- * to the argument which must be greater than or equal to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget ();
- OS.RangeBase_Value (handle, value);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ScrollBar.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ScrollBar.java
deleted file mode 100644
index db6026d2b5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ScrollBar.java
+++ /dev/null
@@ -1,693 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that represent a range of positive, numeric values.
- * <p>
- * At any given moment, a given scroll bar will have a
- * single 'selection' that is considered to be its
- * value, which is constrained to be within the range of
- * values the scroll bar represents (that is, between its
- * <em>minimum</em> and <em>maximum</em> values).
- * </p><p>
- * Typically, scroll bars will be made up of five areas:
- * <ol>
- * <li>an arrow button for decrementing the value</li>
- * <li>a page decrement area for decrementing the value by a larger amount</li>
- * <li>a <em>thumb</em> for modifying the value by mouse dragging</li>
- * <li>a page increment area for incrementing the value by a larger amount</li>
- * <li>an arrow button for incrementing the value</li>
- * </ol>
- * Based on their style, scroll bars are either <code>HORIZONTAL</code>
- * (which have a left facing button for decrementing the value and a
- * right facing button for incrementing it) or <code>VERTICAL</code>
- * (which have an upward facing button for decrementing the value
- * and a downward facing buttons for incrementing it).
- * </p><p>
- * On some platforms, the size of the scroll bar's thumb can be
- * varied relative to the magnitude of the range of values it
- * represents (that is, relative to the difference between its
- * maximum and minimum values). Typically, this is used to
- * indicate some proportional value such as the ratio of the
- * visible area of a document to the total amount of space that
- * it would take to display it. SWT supports setting the thumb
- * size even if the underlying platform does not, but in this
- * case the appearance of the scroll bar will not change.
- * </p><p>
- * Scroll bars are created by specifying either <code>H_SCROLL</code>,
- * <code>V_SCROLL</code> or both when creating a <code>Scrollable</code>.
- * They are accessed from the <code>Scrollable</code> using
- * <code>getHorizontalBar</code> and <code>getVerticalBar</code>.
- * </p><p>
- * Note: Scroll bars are not Controls. On some platforms, scroll bars
- * that appear as part of some standard controls such as a text or list
- * have no operating system resources and are not children of the control.
- * For this reason, scroll bars are treated specially. To create a control
- * that looks like a scroll bar but has operating system resources, use
- * <code>Slider</code>.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see Slider
- * @see Scrollable
- * @see Scrollable#getHorizontalBar
- * @see Scrollable#getVerticalBar
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class ScrollBar extends Widget {
- Scrollable parent;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-ScrollBar (Scrollable parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget ();
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values:
- * <code>SWT.NONE</code> - for the end of a drag.
- * <code>SWT.DRAG</code>.
- * <code>SWT.HOME</code>.
- * <code>SWT.END</code>.
- * <code>SWT.ARROW_DOWN</code>.
- * <code>SWT.ARROW_UP</code>.
- * <code>SWT.PAGE_DOWN</code>.
- * <code>SWT.PAGE_UP</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-void createHandle () {
- handle = parent.getScrollBarHandle (style);
-}
-
-void deregister () {
- display.removeWidget (handle);
-}
-
-void destroyWidget () {
- int topHandle = topHandle ();
- OS.UIElement_Visibility (topHandle, OS.Visibility_Collapsed);
- if (parent.scrolledHandle != 0) {
- int parentHandle = parent.handle;
- int children = OS.Panel_Children (parentHandle);
- OS.UIElementCollection_Remove (children, topHandle);
- }
- releaseHandle ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget();
- return OS.UIElement_IsEnabled (topHandle ());
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget();
- return (int) OS.RangeBase_SmallChange (handle);
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget();
- int maximum = (int) OS.RangeBase_Maximum (handle);
- int viewSize = (int) OS.ScrollBar_ViewportSize (handle);
- return maximum + viewSize;
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget();
- return (int) OS.RangeBase_Minimum (handle);
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget();
- return (int) OS.RangeBase_LargeChange (handle);
-}
-
-/**
- * Returns the receiver's parent, which must be a Scrollable.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Scrollable getParent () {
- checkWidget();
- return parent;
-}
-
-/**
- * Returns the single 'selection' that is the receiver's value.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget();
- return (int) OS.RangeBase_Value (handle);
-}
-
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSize () {
- checkWidget();
- int topHandle = topHandle ();
- int width = (int) OS.FrameworkElement_ActualWidth (topHandle);
- int height = (int) OS.FrameworkElement_ActualHeight (topHandle);
- return new Point (width, height);
-}
-
-/**
- * Returns the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values.
- *
- * @return the thumb value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ScrollBar
- */
-public int getThumb () {
- checkWidget();
- return (int) OS.ScrollBar_ViewportSize (handle);
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget();
- return OS.UIElement_Visibility (handle) == OS.Visibility_Visible;
-}
-
-void HandleScroll (int sender, int e) {
- if (!checkEvent (e)) return;
- Event event = new Event ();
- switch (OS.ScrollEventArgs_ScrollEventType (e)) {
- case OS.ScrollEventType_EndScroll: return;
- case OS.ScrollEventType_ThumbPosition: event.detail = SWT.NONE; break;
- case OS.ScrollEventType_ThumbTrack: event.detail = SWT.DRAG; break;
- case OS.ScrollEventType_First: event.detail = SWT.HOME; break;
- case OS.ScrollEventType_Last: event.detail = SWT.END; break;
- case OS.ScrollEventType_LargeIncrement: event.detail = SWT.PAGE_DOWN; break;
- case OS.ScrollEventType_LargeDecrement: event.detail = SWT.PAGE_UP; break;
- case OS.ScrollEventType_SmallIncrement: event.detail = SWT.ARROW_DOWN; break;
- case OS.ScrollEventType_SmallDecrement: event.detail = SWT.ARROW_UP; break;
- }
- postEvent (SWT.Selection, event);
-}
-
-void hookEvents () {
- super.hookEvents ();
- int handler = OS.gcnew_ScrollEventHandler (jniRef, "HandleScroll");
- OS.ScrollBar_Scroll (handle, handler);
- OS.GCHandle_Free (handler);
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */
-public boolean isVisible () {
- checkWidget();
- return getVisible () && parent.isVisible ();
-}
-
-void register () {
- display.addWidget (handle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (handle != 0) OS.GCHandle_Free (handle);
- handle = 0;
- parent = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (parent.horizontalBar == this) parent.horizontalBar = null;
- if (parent.verticalBar == this) parent.verticalBar = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget();
- OS.UIElement_IsEnabled (handle, enabled);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- OS.RangeBase_SmallChange (handle, value);
-}
-
-/**
- * Sets the maximum. If this value is negative or less than or
- * equal to the minimum, the value is ignored. If necessary, first
- * the thumb and then the selection are adjusted to fit within the
- * new range.
- *
- * @param value the new maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget();
- if (value < 0) return;
- int minimum = (int) OS.RangeBase_Minimum (handle);
- if (value <= minimum) return;
- int viewSize = (int) OS.ScrollBar_ViewportSize (handle);
- if (value - minimum < viewSize) {
- viewSize = value - minimum;
- OS.ScrollBar_ViewportSize (handle, viewSize);
- }
- OS.RangeBase_Maximum (handle, value - viewSize);
-}
-
-/**
- * Sets the minimum value. If this value is negative or greater
- * than or equal to the maximum, the value is ignored. If necessary,
- * first the thumb and then the selection are adjusted to fit within
- * the new range.
- *
- * @param value the new minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget();
- if (value < 0) return;
- int viewSize = (int) OS.ScrollBar_ViewportSize (handle);
- int maximum = (int) OS.RangeBase_Maximum (handle) + viewSize;
- if (value >= maximum) return;
- if (maximum - value < viewSize) {
- viewSize = maximum - value;
- OS.RangeBase_Maximum (handle, maximum - viewSize);
- OS.ScrollBar_ViewportSize (handle, viewSize);
- }
- OS.RangeBase_Minimum (handle, value);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- OS.RangeBase_LargeChange (handle, value);
-}
-
-/**
- * Sets the single <em>selection</em> that is the receiver's
- * value to the argument which must be greater than or equal
- * to zero.
- *
- * @param selection the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int selection) {
- checkWidget();
- OS.RangeBase_Value (handle, selection);
-}
-
-/**
- * Sets the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values. This new
- * value will be ignored if it is less than one, and will be
- * clamped if it exceeds the receiver's current range.
- *
- * @param value the new thumb value, which must be at least one and not
- * larger than the size of the current range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setThumb (int value) {
- checkWidget();
- if (value < 1) return;
- int minimum = (int) OS.RangeBase_Minimum (handle);
- int viewSize = (int) OS.ScrollBar_ViewportSize (handle);
- int maximum = (int) OS.RangeBase_Maximum (handle) + viewSize;
- value = Math.min (value, maximum - minimum);
- OS.RangeBase_Maximum (handle, maximum - value);
- OS.ScrollBar_ViewportSize (handle, value);
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, thumb, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param thumb the new thumb value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- checkWidget();
- if (minimum < 0) return;
- if (maximum < 0) return;
- if (thumb < 1) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- thumb = Math.min (thumb, maximum - minimum);
- OS.RangeBase_Minimum (handle, minimum);
- OS.RangeBase_Maximum (handle, maximum - thumb);
- OS.ScrollBar_ViewportSize (handle, thumb);
- OS.RangeBase_Value (handle, selection);
- OS.RangeBase_LargeChange (handle, pageIncrement);
- OS.RangeBase_SmallChange (handle, increment);
-}
-
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- int topHandle = topHandle ();
- if ((OS.UIElement_Visibility (topHandle) == OS.Visibility_Visible) == visible) return;
- if (visible) {
- sendEvent (SWT.Show);
- if (isDisposed ()) return;
- }
- OS.UIElement_Visibility (topHandle, visible ? OS.Visibility_Visible : OS.Visibility_Collapsed);
- if (isDisposed ()) return;
- if (!visible) {
- sendEvent (SWT.Hide);
- if (isDisposed ()) return;
- }
-}
-
-int topHandle () {
- return handle;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Scrollable.java
deleted file mode 100644
index 2176dd0efb..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Scrollable.java
+++ /dev/null
@@ -1,313 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * This class is the abstract superclass of all classes which
- * represent controls that have standard scroll bars.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>H_SCROLL, V_SCROLL</dd>
- * <dt><b>Events:</b>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public abstract class Scrollable extends Control {
- ScrollBar horizontalBar, verticalBar;
- int scrolledHandle;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Scrollable () {
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#H_SCROLL
- * @see SWT#V_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Scrollable (Composite parent, int style) {
- super (parent, style);
-}
-
-int clientHandle () {
- return handle;
-}
-
-/**
- * Given a desired <em>client area</em> for the receiver
- * (as described by the arguments), returns the bounding
- * rectangle which would be required to produce that client
- * area.
- * <p>
- * In other words, it returns a rectangle such that, if the
- * receiver's bounds were set to that rectangle, the area
- * of the receiver which is capable of displaying data
- * (that is, not covered by the "trimmings") would be the
- * rectangle described by the arguments (relative to the
- * receiver's parent).
- * </p>
- *
- * @param x the desired x coordinate of the client area
- * @param y the desired y coordinate of the client area
- * @param width the desired width of the client area
- * @param height the desired height of the client area
- * @return the required bounds to produce the given client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getClientArea
- */
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
- if (verticalBar != null) width += OS.SystemParameters_VerticalScrollBarWidth ();
- if (horizontalBar != null) height += OS.SystemParameters_HorizontalScrollBarHeight ();
- return new Rectangle (x, y, width, height);
-}
-
-ScrollBar createScrollBar (int type) {
- return new ScrollBar (this, type);
-}
-
-void createWidget () {
- super.createWidget ();
- if ((style & SWT.H_SCROLL) != 0) horizontalBar = createScrollBar (SWT.H_SCROLL);
- if ((style & SWT.V_SCROLL) != 0) verticalBar = createScrollBar (SWT.V_SCROLL);
- fixScrollbarVisibility ();
-}
-
-void deregister () {
- super.deregister ();
- if (scrolledHandle != 0) display.removeWidget (scrolledHandle);
-}
-
-int findScrollViewer (int current, int scrollViewerType) {
- int type = OS.Object_GetType (current);
- boolean found = OS.Object_Equals (scrollViewerType, type);
- OS.GCHandle_Free (type);
- if (found) return current;
- int childCount = OS.VisualTreeHelper_GetChildrenCount (current);
- for (int i = 0; i < childCount; i++) {
- int child = OS.VisualTreeHelper_GetChild (current, i);
- int result = findScrollViewer (child, scrollViewerType);
- if (child != result) OS.GCHandle_Free (child);
- if (result != 0) return result;
- }
- return 0;
-}
-
-void fixScrollbarVisibility () {
- if ((style & SWT.H_SCROLL) == 0) {
- OS.ScrollViewer_SetHorizontalScrollBarVisibility (handle, OS.ScrollBarVisibility_Hidden);
- }
- if ((style & SWT.V_SCROLL) == 0) {
- OS.ScrollViewer_SetVerticalScrollBarVisibility (handle, OS.ScrollBarVisibility_Hidden);
- }
-}
-
-/**
- * Returns a rectangle which describes the area of the
- * receiver which is capable of displaying data (that is,
- * not covered by the "trimmings").
- *
- * @return the client area
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeTrim
- */
-public Rectangle getClientArea () {
- checkWidget ();
- int clientHandle = clientHandle ();
- int topHandle = topHandle ();
- updateLayout (topHandle);
- int width = (int) OS.FrameworkElement_ActualWidth (clientHandle);
- int height = (int) OS.FrameworkElement_ActualHeight (clientHandle);
- return new Rectangle (0, 0, width, height);
-}
-
-/**
- * Returns the receiver's horizontal scroll bar if it has
- * one, and null if it does not.
- *
- * @return the horizontal scroll bar (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ScrollBar getHorizontalBar () {
- checkWidget ();
- return horizontalBar;
-}
-
-int getScrollBarHandle (int style) {
- int scrollbar = 0;
- if (scrolledHandle != 0) {
- int children = OS.Panel_Children (scrolledHandle);
- int enumerator = OS.UIElementCollection_GetEnumerator (children);
- int scrollType = OS.ScrollBar_typeid ();
- while (OS.IEnumerator_MoveNext (enumerator)) {
- int current = OS.IEnumerator_Current (enumerator);
- if (OS.Type_IsInstanceOfType (scrollType, current)) {
- int orientation = OS.ScrollBar_Orientation (current);
- if ((style & SWT.H_SCROLL) != 0 && orientation == OS.Orientation_Horizontal) {
- scrollbar = current;
- break;
- }
- if ((style & SWT.V_SCROLL) != 0 && orientation == OS.Orientation_Vertical) {
- scrollbar = current;
- break;
- }
- }
- OS.GCHandle_Free (current);
- }
- OS.GCHandle_Free (scrollType);
- OS.GCHandle_Free (enumerator);
- OS.GCHandle_Free (children);
- } else {
- updateLayout (handle);
- int scrollViewerType = OS.ScrollViewer_typeid ();
- int scrollViewer = findScrollViewer (handle, scrollViewerType);
- int template = OS.Control_Template (scrollViewer);
- int part;
- if ((style & SWT.H_SCROLL) != 0) {
- part = createDotNetString ("PART_HorizontalScrollBar", false);
- } else {
- part = createDotNetString ("PART_VerticalScrollBar", false);
- }
- scrollbar = OS.FrameworkTemplate_FindName (template, part, scrollViewer);
- OS.GCHandle_Free (part);
- OS.GCHandle_Free (template);
- OS.GCHandle_Free (scrollViewer);
- OS.GCHandle_Free (scrollViewerType);
- }
- return scrollbar;
-}
-
-/**
- * Returns the receiver's vertical scroll bar if it has
- * one, and null if it does not.
- *
- * @return the vertical scroll bar (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ScrollBar getVerticalBar () {
- checkWidget ();
- return verticalBar;
-}
-
-void HandlePreviewMouseWheel (int sender, int e) {
- super.HandlePreviewMouseWheel (sender, e);
- if (!checkEvent (e)) return;
- if ((state & CANVAS) != 0) {
- if (verticalBar != null) {
- int vHandle = verticalBar.handle;
- int delta = OS.MouseWheelEventArgs_Delta (e);
- int lines = OS.SystemParameters_WheelScrollLines ();
- double value = OS.RangeBase_Value (vHandle);
- double newValue = value;
- Event event = new Event ();
- if (lines != -1) {
- double smallIncrement = OS.RangeBase_SmallChange (vHandle);
- newValue += smallIncrement * (-delta/120) * lines;
- event.detail = delta < 0 ? SWT.ARROW_DOWN : SWT.ARROW_UP;
- } else {
- double largeIncrement = OS.RangeBase_LargeChange (vHandle);
- newValue += largeIncrement * (-delta/120);
- event.detail = delta < 0 ? SWT.PAGE_DOWN : SWT.PAGE_UP;
- }
- OS.RangeBase_Value (vHandle, newValue);
- newValue = OS.RangeBase_Value (vHandle);
- if (value != newValue) {
- verticalBar.postEvent (SWT.Selection, event);
- }
- }
- }
-}
-
-void register () {
- super.register ();
- if (scrolledHandle != 0) display.addWidget (scrolledHandle, this);
-}
-
-void releaseChildren (boolean destroy) {
- if (horizontalBar != null) {
- horizontalBar.release (false);
- horizontalBar = null;
- }
- if (verticalBar != null) {
- verticalBar.release (false);
- verticalBar = null;
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (scrolledHandle != 0) OS.GCHandle_Free (scrolledHandle);
- scrolledHandle = 0;
-}
-
-int topHandle () {
- return scrolledHandle != 0 ? scrolledHandle : super.topHandle ();
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Shell.java
deleted file mode 100644
index 6ec9c27532..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Shell.java
+++ /dev/null
@@ -1,1536 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent the "windows"
- * which the desktop or "window manager" is managing.
- * Instances that do not have a parent (that is, they
- * are built using the constructor, which takes a
- * <code>Display</code> as the argument) are described
- * as <em>top level</em> shells. Instances that do have
- * a parent are described as <em>secondary</em> or
- * <em>dialog</em> shells.
- * <p>
- * Instances are always displayed in one of the maximized,
- * minimized or normal states:
- * <ul>
- * <li>
- * When an instance is marked as <em>maximized</em>, the
- * window manager will typically resize it to fill the
- * entire visible area of the display, and the instance
- * is usually put in a state where it can not be resized
- * (even if it has style <code>RESIZE</code>) until it is
- * no longer maximized.
- * </li><li>
- * When an instance is in the <em>normal</em> state (neither
- * maximized or minimized), its appearance is controlled by
- * the style constants which were specified when it was created
- * and the restrictions of the window manager (see below).
- * </li><li>
- * When an instance has been marked as <em>minimized</em>,
- * its contents (client area) will usually not be visible,
- * and depending on the window manager, it may be
- * "iconified" (that is, replaced on the desktop by a small
- * simplified representation of itself), relocated to a
- * distinguished area of the screen, or hidden. Combinations
- * of these changes are also possible.
- * </li>
- * </ul>
- * </p><p>
- * The <em>modality</em> of an instance may be specified using
- * style bits. The modality style bits are used to determine
- * whether input is blocked for other shells on the display.
- * The <code>PRIMARY_MODAL</code> style allows an instance to block
- * input to its parent. The <code>APPLICATION_MODAL</code> style
- * allows an instance to block input to every other shell in the
- * display. The <code>SYSTEM_MODAL</code> style allows an instance
- * to block input to all shells, including shells belonging to
- * different applications.
- * </p><p>
- * Note: The styles supported by this class are treated
- * as <em>HINT</em>s, since the window manager for the
- * desktop on which the instance is visible has ultimate
- * control over the appearance and behavior of decorations
- * and modality. For example, some window managers only
- * support resizable windows and will always assume the
- * RESIZE style, even if it is not set. In addition, if a
- * modality style is not supported, it is "upgraded" to a
- * more restrictive modality style that is supported. For
- * example, if <code>PRIMARY_MODAL</code> is not supported,
- * it would be upgraded to <code>APPLICATION_MODAL</code>.
- * A modality style may also be "downgraded" to a less
- * restrictive style. For example, most operating systems
- * no longer support <code>SYSTEM_MODAL</code> because
- * it can freeze up the desktop, so this is typically
- * downgraded to <code>APPLICATION_MODAL</code>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL, SHEET</dd>
- * <dd>APPLICATION_MODAL, MODELESS, PRIMARY_MODAL, SYSTEM_MODAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Activate, Close, Deactivate, Deiconify, Iconify</dd>
- * </dl>
- * Class <code>SWT</code> provides two "convenience constants"
- * for the most commonly required style combinations:
- * <dl>
- * <dt><code>SHELL_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application top level shell: (that
- * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>)
- * </dd>
- * <dt><code>DIALOG_TRIM</code></dt>
- * <dd>
- * the result of combining the constants which are required
- * to produce a typical application dialog shell: (that
- * is, <code>TITLE | CLOSE | BORDER</code>)
- * </dd>
- * </dl>
- * </p>
- * <p>
- * Note: Only one of the styles APPLICATION_MODAL, MODELESS,
- * PRIMARY_MODAL and SYSTEM_MODAL may be specified.
- * </p><p>
- * IMPORTANT: This class is not intended to be subclassed.
- * </p>
- *
- * @see Decorations
- * @see SWT
- * @see <a href="http://www.eclipse.org/swt/snippets/#shell">Shell snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class Shell extends Decorations {
- Control lastActive;
- boolean closing;
- boolean moved, resized, opened, fullScreen, modified, center;
- int oldX, oldY, oldWidth, oldHeight;
- int oldWindowStyle, oldWindowState;
-
-/**
- * Constructs a new instance of this class. This is equivalent
- * to calling <code>Shell((Display) null)</code>.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell () {
- this ((Display) null);
-}
-
-/**
- * Constructs a new instance of this class given only the style
- * value describing its behavior and appearance. This is equivalent
- * to calling <code>Shell((Display) null, style)</code>.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#TOOL
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (int style) {
- this ((Display) null, style);
-}
-
-/**
- * Constructs a new instance of this class given only the display
- * to create it on. It is created with style <code>SWT.SHELL_TRIM</code>.
- * <p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the shell on
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell (Display display) {
- this (display, SWT.SHELL_TRIM);
-}
-
-/**
- * Constructs a new instance of this class given the display
- * to create it on and a style value describing its behavior
- * and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the shell on
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#TOOL
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (Display display, int style) {
- this (display, null, style, 0, false);
-}
-
-Shell (Display display, Shell parent, int style, int handle, boolean embedded) {
- super ();
- checkSubclass ();
- if (display == null) display = Display.getCurrent ();
- if (display == null) display = Display.getDefault ();
- if (!display.isValidThread ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- if (parent != null && parent.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.center = parent != null && (style & SWT.SHEET) != 0;
- this.style = checkStyle (parent, style);
- this.parent = parent;
- this.display = display;
- if (handle != 0) {
- if (embedded) {
- this.handle = handle;
- } else {
- shellHandle = handle;
- }
- }
- createWidget ();
-}
-
-/**
- * Constructs a new instance of this class given only its
- * parent. It is created with style <code>SWT.DIALOG_TRIM</code>.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the parent is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-public Shell (Shell parent) {
- this (parent, SWT.DIALOG_TRIM);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the shell on the currently active
- * display if there is one. If there is no current display, the
- * shell is created on a "default" display. <b>Passing in null as
- * the parent is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param parent a shell which will be the parent of the new instance
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#CLOSE
- * @see SWT#MIN
- * @see SWT#MAX
- * @see SWT#RESIZE
- * @see SWT#TITLE
- * @see SWT#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#ON_TOP
- * @see SWT#TOOL
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- * @see SWT#SHEET
- */
-public Shell (Shell parent, int style) {
- this (parent != null ? parent.display : null, parent, style, 0, false);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new shell.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Shell</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param display the display for the shell
- * @param handle the handle for the shell
- * @return a new shell object containing the specified display and handle
- */
-public static Shell wpf_new (Display display, int handle) {
- return new Shell (display, null, SWT.NO_TRIM, handle, true);
-}
-
-/**
- * Invokes platform specific functionality to allocate a new shell
- * that is not embedded.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Shell</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param display the display for the shell
- * @param handle the handle for the shell
- * @return a new shell object containing the specified display and handle
- *
- * @since 3.3
- */
-public static Shell internal_new (Display display, int handle) {
- handle = OS.GCHandle_ToHandle (handle);
- return new Shell (display, null, SWT.NO_TRIM, handle, false);
-}
-
-static int checkStyle (Shell parent, int style) {
- style = Decorations.checkStyle (style);
- style &= ~SWT.TRANSPARENT;
- int mask = SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.PRIMARY_MODAL;
- if ((style & SWT.SHEET) != 0) {
- style &= ~SWT.SHEET;
- style |= parent == null ? SWT.SHELL_TRIM : SWT.DIALOG_TRIM;
- if ((style & mask) == 0) {
- style |= parent == null ? SWT.APPLICATION_MODAL : SWT.PRIMARY_MODAL;
- }
- }
- int bits = style & ~mask;
- if ((style & SWT.SYSTEM_MODAL) != 0) return bits | SWT.SYSTEM_MODAL;
- if ((style & SWT.APPLICATION_MODAL) != 0) return bits | SWT.APPLICATION_MODAL;
- if ((style & SWT.PRIMARY_MODAL) != 0) return bits | SWT.PRIMARY_MODAL;
- return bits;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when operations are performed on the receiver,
- * by sending the listener one of the messages defined in the
- * <code>ShellListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ShellListener
- * @see #removeShellListener
- */
-public void addShellListener (ShellListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Close,typedListener);
- addListener (SWT.Iconify,typedListener);
- addListener (SWT.Deiconify,typedListener);
- addListener (SWT.Activate, typedListener);
- addListener (SWT.Deactivate, typedListener);
-}
-
-void addWidget () {
- if ((style & SWT.ON_TOP) != 0) return;
- if (parent != null) {
- if ((parent.style & SWT.ON_TOP) != 0) return;
- OS.Window_Owner (shellHandle, ((Shell)parent).shellHandle);
- }
-}
-
-void bringToTop () {
- if ((style & SWT.ON_TOP) != 0) return;
- OS.Window_Activate (shellHandle);
-}
-
-void center () {
- if (parent == null) return;
- Rectangle rect = getBounds ();
- Rectangle parentRect = display.map (parent, null, parent.getClientArea());
- int x = Math.max (parentRect.x, parentRect.x + (parentRect.width - rect.width) / 2);
- int y = Math.max (parentRect.y, parentRect.y + (parentRect.height - rect.height) / 2);
- Rectangle monitorRect = parent.getMonitor ().getClientArea();
- if (x + rect.width > monitorRect.x + monitorRect.width) {
- x = Math.max (monitorRect.x, monitorRect.x + monitorRect.width - rect.width);
- } else {
- x = Math.max (x, monitorRect.x);
- }
- if (y + rect.height > monitorRect.y + monitorRect.height) {
- y = Math.max (monitorRect.y, monitorRect.y + monitorRect.height - rect.height);
- } else {
- y = Math.max (y, monitorRect.y);
- }
- setLocation (x, y);
-}
-
-void checkOpened () {
- if (!opened) resized = false;
-}
-
-/**
- * Requests that the window manager close the receiver in
- * the same way it would be closed when the user clicks on
- * the "close box" or performs some other platform specific
- * key or mouse combination that indicates the window
- * should be removed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#Close
- * @see #dispose
- */
-public void close () {
- checkWidget ();
- closeWidget ();
-}
-
-void createHandle () {
- if (shellHandle != 0) {
- scrolledHandle = OS.ContentControl_Content (shellHandle);
- if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int children = OS.Panel_Children (scrolledHandle);
- handle = OS.UIElementCollection_default (children, 0);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.GCHandle_Free (children);
- return;
- }
- state |= CANVAS;
- if ((style & SWT.ON_TOP) != 0) {
- shellHandle = OS.gcnew_Popup ();
- if (shellHandle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.NO_TRIM) != 0) OS.Popup_AllowsTransparency (shellHandle, true);
- OS.KeyboardNavigation_SetTabNavigation (shellHandle, OS.KeyboardNavigationMode_None);
- boolean scrolled = (style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0;
- createHandle (scrolled, true);
- OS.Popup_Child (shellHandle, super.topHandle());
- OS.Popup_IsOpen (shellHandle, true);
- OS.Popup_IsOpen (shellHandle, false);
- return;
- }
- shellHandle = OS.gcnew_Window();
- if (shellHandle == 0) error(SWT.ERROR_NO_HANDLES);
- if ((style & SWT.NO_TRIM) != 0) OS.Window_AllowsTransparency (shellHandle, true);
-
- /*
- * Feature in WPF. ...
- */
- OS.Window_ShowInTaskbar (shellHandle, false);
- OS.Window_ResizeMode (shellHandle, OS.ResizeMode_NoResize);
- OS.Window_WindowStyle (shellHandle, OS.WindowStyle_None);
- OS.FrameworkElement_Width (shellHandle, 0);
- OS.FrameworkElement_Height (shellHandle, 0);
- OS.Window_Show (shellHandle);
- OS.Window_Hide (shellHandle);
- Rectangle bounds = getMonitor ().getBounds ();
- OS.FrameworkElement_Width (shellHandle, bounds.width * 5 / 8);
- OS.FrameworkElement_Height (shellHandle, bounds.height * 5 / 8);
-
- int windowStyle = OS.WindowStyle_None, resizeMode = OS.ResizeMode_NoResize;
- if ((style & SWT.NO_TRIM) == 0) {
- if ((style & SWT.TOOL) != 0) {
- windowStyle = OS.WindowStyle_ToolWindow;
- } else if ((style & SWT.SHELL_TRIM) != 0) {
- windowStyle = OS.WindowStyle_SingleBorderWindow;
- }
- if ((style & SWT.RESIZE) != 0) {
- resizeMode |= OS.ResizeMode_CanResize;
- }
- }
- OS.Window_ShowInTaskbar (shellHandle, parent == null);
- OS.Window_ResizeMode (shellHandle, resizeMode);
- OS.Window_WindowStyle (shellHandle, windowStyle);
- OS.KeyboardNavigation_SetTabNavigation (shellHandle, OS.KeyboardNavigationMode_None);
-
- boolean scrolled = (style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0;
- createHandle (scrolled, true);
- OS.ContentControl_Content (shellHandle, super.topHandle());
-}
-
-void createWidget() {
- super.createWidget ();
- display.addShell (this);
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
- if ((style & SWT.ON_TOP) != 0) return new Rectangle (x, y, width, height);
- updateLayout (shellHandle);
- int clientX = (int) OS.Window_Left (shellHandle);
- int clientY = (int) OS.Window_Top (shellHandle);
- int w = (int) OS.FrameworkElement_ActualWidth (shellHandle);
- int h = (int) OS.FrameworkElement_ActualHeight (shellHandle);
- int clientWidth = (int) OS.FrameworkElement_ActualWidth (handle);
- int clientHeight = (int) OS.FrameworkElement_ActualHeight (handle);
- int point = OS.gcnew_Point (clientX, clientY);
- int result = OS.Visual_PointFromScreen (shellHandle, point);
- OS.GCHandle_Free (point);
- clientX = -(int) OS.Point_X (result);
- clientY = -(int) OS.Point_Y (result);
- OS.GCHandle_Free (result);
- x -= clientX;
- y -= clientY;
- width += (w - clientWidth);
- height += (h - clientHeight);
- return new Rectangle (x, y, width, height);
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (shellHandle);
-}
-
-
-void destroyWidget () {
- if (shellHandle != 0 && !closing) {
- if ((style & SWT.ON_TOP) != 0) {
- OS.Popup_IsOpen (shellHandle, false);
- } else {
- OS.Window_Close (shellHandle);
- }
- }
- releaseHandle ();
-}
-
-public void dispose () {
- /*
- * This code is intentionally commented. On some
- * platforms, the owner window is repainted right
- * away when a dialog window exits. This behavior
- * is currently unspecified.
- */
-// /*
-// * Note: It is valid to attempt to dispose a widget
-// * more than once. If this happens, fail silently.
-// */
-// if (!isValidWidget ()) return;
-// if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
-// Display oldDisplay = display;
- super.dispose ();
- // widget is disposed at this point
-// if (oldDisplay != null) oldDisplay.update ();
-}
-
-Control findBackgroundControl () {
- return background != -1 || backgroundImage != null ? this : null;
-}
-
-Control findThemeControl () {
- return null;
-}
-
-/**
- * If the receiver is visible, moves it to the top of the
- * drawing order for the display on which it was created
- * (so that all other shells on that display, which are not
- * the receiver's children will be drawn behind it) and forces
- * the window manager to make the shell active.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#open
- * @see Shell#setActive
- */
-public void forceActive () {
- checkWidget ();
- if(!isVisible()) return;
- if ((style & SWT.ON_TOP) != 0) return;
-// OS.SetForegroundWindow (handle);
- OS.Window_Activate (shellHandle);
-}
-
-/**
- * Returns the receiver's alpha value. The alpha value
- * is between 0 (transparent) and 255 (opaque).
- *
- * @return the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public int getAlpha () {
- checkWidget ();
- return 255;
-}
-
-public Rectangle getBounds () {
- checkWidget ();
- int x, y;
- if ((style & SWT.ON_TOP) != 0) {
- x = (int) OS.Popup_HorizontalOffset (shellHandle);
- y = (int) OS.Popup_VerticalOffset (shellHandle);
- } else {
- x = (int) OS.Window_Left (shellHandle);
- y = (int) OS.Window_Top (shellHandle);
- }
- int renderSize = OS.UIElement_RenderSize (shellHandle);
- int width = (int) OS.Size_Width (renderSize);
- int height = (int) OS.Size_Height (renderSize);
- OS.GCHandle_Free (renderSize);
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is currently
- * in fullscreen state, and false otherwise.
- * <p>
- *
- * @return the fullscreen state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public boolean getFullScreen() {
- checkWidget ();
- return fullScreen;
-}
-
-/**
- * Returns the receiver's input method editor mode. This
- * will be the result of bitwise OR'ing together one or
- * more of the following constants defined in class
- * <code>SWT</code>:
- * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>,
- * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>.
- *
- * @return the IME mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public int getImeInputMode () {
- checkWidget ();
- //TODO
- return SWT.ROMAN;
-}
-
-public Point getLocation () {
- checkWidget ();
- int x, y;
- if ((style & SWT.ON_TOP) != 0) {
- x = (int) OS.Popup_HorizontalOffset (shellHandle);
- y = (int) OS.Popup_VerticalOffset (shellHandle);
- } else {
- x = (int) OS.Window_Left (shellHandle);
- y = (int) OS.Window_Top (shellHandle);
- }
- return new Point (x, y);
-}
-
-public boolean getMaximized () {
- checkWidget ();
- return !fullScreen && super.getMaximized ();
-}
-
-/**
- * Returns a point describing the minimum receiver's size. The
- * x coordinate of the result is the minimum width of the receiver.
- * The y coordinate of the result is the minimum height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Point getMinimumSize () {
- checkWidget ();
-// int width = Math.max (0, minWidth);
-// int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX;
-// if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) {
-// width = Math.max (width, OS.GetSystemMetrics (OS.SM_CXMINTRACK));
-// }
-// int height = Math.max (0, minHeight);
-// if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) {
-// if ((style & SWT.RESIZE) != 0) {
-// height = Math.max (height, OS.GetSystemMetrics (OS.SM_CYMINTRACK));
-// } else {
-// RECT rect = new RECT ();
-// int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
-// int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
-// OS.AdjustWindowRectEx (rect, bits1, false, bits2);
-// height = Math.max (height, rect.bottom - rect.top);
-// }
-// }
- int width = (int) OS.FrameworkElement_MinWidth (shellHandle);
- int height = (int) OS.FrameworkElement_MinHeight (shellHandle);
- return new Point (width, height);
-}
-
-/**
- * Gets the receiver's modified state.
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.5
- */
-public boolean getModified () {
- checkWidget ();
- return modified;
-}
-
-/**
- * Returns the region that defines the shape of the shell,
- * or null if the shell has the default shape.
- *
- * @return the region that defines the shape of the shell (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public Region getRegion () {
- /* This method is needed for the @since 3.0 Javadoc tag*/
- checkWidget ();
- return region;
-}
-
-public Shell getShell () {
- checkWidget ();
- return this;
-}
-
-public boolean getVisible () {
- checkWidget ();
- if ((style & SWT.ON_TOP) != 0)return OS.Popup_IsOpen (shellHandle);
- return super.getVisible ();
-}
-
-/**
- * Returns an array containing all shells which are
- * descendants of the receiver.
- * <p>
- * @return the dialog shells
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Shell [] getShells () {
- checkWidget ();
- int count = 0;
- Shell [] shells = display.getShells ();
- for (int i=0; i<shells.length; i++) {
- Control shell = shells [i];
- do {
- shell = shell.parent;
- } while (shell != null && shell != this);
- if (shell == this) count++;
- }
- int index = 0;
- Shell [] result = new Shell [count];
- for (int i=0; i<shells.length; i++) {
- Control shell = shells [i];
- do {
- shell = shell.parent;
- } while (shell != null && shell != this);
- if (shell == this) {
- result [index++] = shells [i];
- }
- }
- return result;
-}
-
-Composite findDeferredControl () {
- return layoutCount > 0 ? this : null;
-}
-
-public boolean isEnabled () {
- checkWidget ();
- return getEnabled ();
-}
-
-void hookEvents () {
- super.hookEvents ();
- int handler = OS.gcnew_SizeChangedEventHandler (jniRef, "HandleSizeChanged");
- OS.FrameworkElement_SizeChanged (shellHandle, handler);
- OS.GCHandle_Free (handler);
- if ((style & SWT.ON_TOP) != 0) {
- handler = OS.gcnew_EventHandler (jniRef, "HandleClosed");
- OS.Popup_Closed (shellHandle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_KeyboardFocusChangedEventHandler (jniRef, "HandlePreviewGotKeyboardFocusActivate");
- OS.UIElement_PreviewGotKeyboardFocus (shellHandle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_KeyboardFocusChangedEventHandler (jniRef, "HandleLostKeyboardFocusDeactivate");
- OS.UIElement_LostKeyboardFocus (shellHandle, handler);
- OS.GCHandle_Free (handler);
- } else {
- handler = OS.gcnew_CancelEventHandler (jniRef, "HandleClosing");
- OS.Window_Closing (shellHandle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_EventHandler (jniRef, "HandleActivated");
- OS.Window_Activated (shellHandle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_EventHandler (jniRef, "HandleDeactivated");
- OS.Window_Deactivated (shellHandle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_EventHandler (jniRef, "HandleLocationChanged");
- OS.Window_LocationChanged (shellHandle, handler);
- OS.GCHandle_Free (handler);
- }
-}
-
-void HandleActivated (int sender, int e) {
- if (!checkEvent (e)) return;
- sendEvent (SWT.Activate);
- if (isDisposed ()) return;
- restoreFocus ();
-}
-
-void HandleClosed (int sender, int e) {
- if (!checkEvent (e)) return;
- closing = true;
- sendEvent (SWT.Close);
- closing = false;
-}
-
-void HandleClosing (int sender, int e) {
- if (!checkEvent (e)) return;
- closing = true;
- boolean doit = false;
- if (isEnabled ()) {
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- doit = event.doit || isDisposed ();
- }
- if (doit) {
- /**
- * Bug in WPF. When a window has more than
- * two child windows, and all the the child
- * windows are closed, the parent window is not
- * brought to the front. The work around is to
- * null out the Owner property of the child window
- * before disposing it.
- */
- if (shellHandle != 0) OS.Window_Owner (shellHandle, 0);
- if (!isDisposed ()) release (false);
- } else {
- OS.CancelEventArgs_Cancel (e, true);
- }
- closing = false;
-}
-
-void HandleDeactivated (int sender, int e) {
- if (!checkEvent (e)) return;
- sendEvent (SWT.Deactivate);
- if (isDisposed ()) return;
- saveFocus ();
-}
-
-void HandleLocationChanged (int sender, int e) {
- if (!checkEvent (e)) return;
- int x = (int) OS.Window_Left (shellHandle);
- int y = (int) OS.Window_Top (shellHandle);
- if (!moved || oldX != x || oldY != y) {
- moved = true;
- oldX = x;
- oldY = y;
- sendEvent (SWT.Move);
- }
-}
-
-void HandleLostKeyboardFocusDeactivate (int sender, int e) {
- if (isDisposed ()) return;
- if (OS.UIElement_IsKeyboardFocusWithin (handle)) return;
- sendEvent (SWT.Deactivate);
-}
-
-void HandleMouseLeave (int sender, int e) {
- super.HandleMouseLeave (sender, e);
- if (!checkEvent (e)) return;
- display.mouseControl = null;
-}
-
-void HandlePreviewGotKeyboardFocusActivate (int sender, int e) {
- if (isDisposed ()) return;
- if (!OS.UIElement_IsKeyboardFocusWithin (handle)) return;
- sendEvent (SWT.Activate);
-}
-
-void HandleSizeChanged (int sender, int e) {
- if (!checkEvent (e)) return;
- int width = (int) OS.FrameworkElement_ActualWidth (shellHandle);
- int height = (int) OS.FrameworkElement_ActualHeight (shellHandle);
- if (!resized || oldWidth != width || oldHeight != height) {
- resized = true;
- oldWidth = width;
- oldHeight = height;
- sendEvent (SWT.Resize);
- if (isDisposed ()) return;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false, false);
- }
- }
-}
-
-/**
- * Moves the receiver to the top of the drawing order for
- * the display on which it was created (so that all other
- * shells on that display, which are not the receiver's
- * children will be drawn behind it), marks it visible,
- * sets the focus and asks the window manager to make the
- * shell active.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#setActive
- * @see Shell#forceActive
- */
-public void open () {
- checkWidget ();
- bringToTop ();
- if (isDisposed ()) return;
- setVisible (true);
- if (isDisposed ()) return;
- if (!restoreFocus () && !traverseGroup (true)) setFocus ();
-}
-
-public boolean print (GC gc) {
- checkWidget ();
- if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- return false;
-}
-
-void register () {
- super.register ();
- display.addWidget (shellHandle, this);
-}
-
-void releaseChildren (boolean destroy) {
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (shell != null && !shell.isDisposed ()) {
- shell.release ((style & SWT.ON_TOP) != 0);
- }
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (shellHandle != 0) OS.GCHandle_Free (shellHandle);
- shellHandle = 0;
-}
-
-void releaseParent () {
- /* Do nothing */
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- display.clearModal (this);
- display.removeShell (this);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when operations are performed on the receiver.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ShellListener
- * @see #addShellListener
- */
-public void removeShellListener (ShellListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Close, listener);
- eventTable.unhook (SWT.Iconify,listener);
- eventTable.unhook (SWT.Deiconify,listener);
- eventTable.unhook (SWT.Activate, listener);
- eventTable.unhook (SWT.Deactivate, listener);
-}
-
-/**
- * If the receiver is visible, moves it to the top of the
- * drawing order for the display on which it was created
- * (so that all other shells on that display, which are not
- * the receiver's children will be drawn behind it) and asks
- * the window manager to make the shell active
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton(Button)
- * @see Shell#open
- * @see Shell#setActive
- */
-public void setActive () {
- checkWidget ();
- if(!isVisible()) return;
- bringToTop ();
- // widget could be disposed at this point
-}
-
-void setActiveControl (Control control) {
- if (control != null && control.isDisposed ()) control = null;
- if (lastActive != null && lastActive.isDisposed ()) lastActive = null;
- if (lastActive == control) return;
-
- /*
- * Compute the list of controls to be activated and
- * deactivated by finding the first common parent
- * control.
- */
- Control [] activate = (control == null) ? new Control [0] : control.getPath ();
- Control [] deactivate = (lastActive == null) ? new Control [0] : lastActive.getPath ();
- lastActive = control;
- int index = 0, length = Math.min (activate.length, deactivate.length);
- while (index < length) {
- if (activate [index] != deactivate [index]) break;
- index++;
- }
-
- /*
- * It is possible (but unlikely), that application
- * code could have destroyed some of the widgets. If
- * this happens, keep processing those widgets that
- * are not disposed.
- */
- for (int i=deactivate.length-1; i>=index; --i) {
- if (!deactivate [i].isDisposed ()) {
- deactivate [i].sendEvent (SWT.Deactivate);
- }
- }
- for (int i=activate.length-1; i>=index; --i) {
- if (!activate [i].isDisposed ()) {
- activate [i].sendEvent (SWT.Activate);
- }
- }
-}
-
-/**
- * Sets the receiver's alpha value which must be
- * between 0 (transparent) and 255 (opaque).
- * <p>
- * This operation requires the operating system's advanced
- * widgets subsystem which may not be available on some
- * platforms.
- * </p>
- * @param alpha the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setAlpha (int alpha) {
- checkWidget ();
- /* Not implemented */
-}
-
-int setBounds (int x, int y, int width, int height, int flags) {
- if (fullScreen) setFullScreen (false);
- int result = 0;
- if ((flags & MOVED) != 0) {
- int currentX, currentY;
- if ((style & SWT.ON_TOP) != 0) {
- currentX = (int) OS.Popup_HorizontalOffset (shellHandle);
- currentY = (int) OS.Popup_VerticalOffset (shellHandle);
- } else {
- currentX = (int) OS.Window_Left (shellHandle);
- currentY = (int) OS.Window_Top (shellHandle);
- }
- if (currentX != x || currentY != y) {
- moved = true;
- oldX = x;
- oldY = currentY;
- if ((style & SWT.ON_TOP) != 0) {
- OS.Popup_HorizontalOffset (shellHandle, x);
- oldY = y;
- OS.Popup_VerticalOffset (shellHandle, y);
- } else {
- OS.Window_Left (shellHandle, x);
- oldY = y;
- OS.Window_Top (shellHandle, y);
- }
- sendEvent (SWT.Move);
- if (isDisposed ()) return 0;
- result |= MOVED;
- }
- }
- if ((flags & RESIZED) != 0) {
- int currentWidth = (int) OS.FrameworkElement_ActualWidth (shellHandle);
- int currentHeight = (int) OS.FrameworkElement_ActualHeight (shellHandle);
- if (currentWidth != width || currentHeight != height) {
- resized = true;
- oldWidth = width;
- oldHeight = currentHeight;
- OS.FrameworkElement_Width (shellHandle, width);
- oldHeight = height;
- OS.FrameworkElement_Height (shellHandle, height);
- sendEvent (SWT.Resize);
- if (isDisposed ()) return 0;
- result |= RESIZED;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false, false);
- }
- }
- }
- return result;
-}
-
-void setClipping () {
-
-}
-
-public void setEnabled (boolean enabled) {
- checkWidget ();
- if (enabled == getEnabled ()) return;
- super.setEnabled (enabled);
- if ((style & SWT.ON_TOP) != 0) return;
- if (enabled && OS.Window_IsActive (shellHandle)) {
- if (!restoreFocus ()) traverseGroup (true);
- }
-}
-
-/**
- * Sets the full screen state of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the full screen state, and if the argument is
- * <code>false</code> and the receiver was previously switched
- * into full screen state, causes the receiver to switch back
- * to either the maximized or normal states.
- * <p>
- * Note: The result of intermixing calls to <code>setFullScreen(true)</code>,
- * <code>setMaximized(true)</code> and <code>setMinimized(true)</code> will
- * vary by platform. Typically, the behavior will match the platform user's
- * expectations, but not always. This should be avoided if possible.
- * </p>
- *
- * @param fullScreen the new fullscreen state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void setFullScreen (boolean fullScreen) {
- checkWidget ();
- if (this.fullScreen == fullScreen) return;
- if(fullScreen) {
- oldWindowStyle = OS.Window_WindowStyle (shellHandle);
- oldWindowState = OS.Window_WindowState (shellHandle);
- boolean visible = getVisible ();
- OS.Window_Hide (shellHandle);
- OS.Window_WindowStyle (shellHandle, OS.WindowStyle_None);
- if (visible) OS.Window_Show (shellHandle);
- OS.Window_WindowState (shellHandle, OS.WindowState_Maximized);
- } else {
- OS.Window_WindowStyle (shellHandle, oldWindowStyle);
- OS.Window_WindowState (shellHandle, oldWindowState);
- oldWindowState = 0;
- oldWindowStyle = 0;
- }
- this.fullScreen = fullScreen;
-}
-
-/**
- * Sets the input method editor mode to the argument which
- * should be the result of bitwise OR'ing together one or more
- * of the following constants defined in class <code>SWT</code>:
- * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>,
- * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>.
- *
- * @param mode the new IME mode
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public void setImeInputMode (int mode) {
- checkWidget ();
- //TODO
-}
-
-/**
- * Sets the receiver's minimum size to the size specified by the arguments.
- * If the new minimum size is larger than the current size of the receiver,
- * the receiver is resized to the new minimum size.
- *
- * @param width the new minimum width for the receiver
- * @param height the new minimum height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setMinimumSize (int width, int height) {
- checkWidget ();
- int widthLimit = 0, heightLimit = 0;
- int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX;
- if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) {
-// widthLimit = OS.GetSystemMetrics (OS.SM_CXMINTRACK);
-// if ((style & SWT.RESIZE) != 0) {
-// heightLimit = OS.GetSystemMetrics (OS.SM_CYMINTRACK);
-// } else {
-// RECT rect = new RECT ();
-// int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
-// int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
-// OS.AdjustWindowRectEx (rect, bits1, false, bits2);
-// heightLimit = rect.bottom - rect.top;
-// }
- }
- int minWidth = Math.max (widthLimit, width);
- int minHeight = Math.max (heightLimit, height);
- OS.FrameworkElement_MinWidth(shellHandle, minWidth);
- OS.FrameworkElement_MinHeight(shellHandle, minHeight);
-}
-
-/**
- * Sets the receiver's minimum size to the size specified by the argument.
- * If the new minimum size is larger than the current size of the receiver,
- * the receiver is resized to the new minimum size.
- *
- * @param size the new minimum size for the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setMinimumSize (Point size) {
- checkWidget ();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setMinimumSize (size.x, size.y);
-}
-
-/**
- * Sets the receiver's modified state as specified by the argument.
- *
- * @param modified the new modified state for the receiver
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.5
- */
-public void setModified (boolean modified) {
- checkWidget ();
- this.modified = modified;
-}
-
-void setParent () {
- /* Do nothing. Not necessary for Shells */
-}
-
-/**
- * Sets the shape of the shell to the region specified
- * by the argument. When the argument is null, the
- * default shape of the shell is restored. The shell
- * must be created with the style SWT.NO_TRIM in order
- * to specify a region.
- *
- * @param region the region that defines the shape of the shell (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- *
- */
-public void setRegion (Region region) {
- checkWidget ();
- if ((style & SWT.NO_TRIM) == 0) return;
- super.setRegion (region);
-}
-
-public void setVisible (boolean visible) {
- checkWidget ();
- if (getVisible () == visible) return;
-
- int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- if ((style & mask) != 0) {
- if (visible) {
- display.setModalShell (this);
-// Control control = display._getFocusControl ();
-// if (control != null && !control.isActive ()) {
-// bringToTop ();
-// if (isDisposed ()) return;
-// }
-// int hwndShell = OS.GetActiveWindow ();
-// if (hwndShell == 0) {
-// if (parent != null) hwndShell = parent.handle;
-// }
-// if (hwndShell != 0) {
-// OS.SendMessage (hwndShell, OS.WM_CANCELMODE, 0, 0);
-// }
-// OS.ReleaseCapture ();
- } else {
- display.clearModal (this);
- }
- } else {
- updateModal ();
- }
-
- if (visible) {
- if (center && !moved) {
- center ();
- if (isDisposed ()) return;
- }
- if ((style & SWT.ON_TOP) != 0) {
- OS.Popup_IsOpen (shellHandle, visible);
- } else {
- OS.Window_Show (shellHandle);
- }
-
- opened = true;
- if (!moved) {
- moved = true;
- Point location = getLocation();
- oldX = location.x;
- oldY = location.y;
- sendEvent (SWT.Move);
- if (isDisposed ()) return;
- }
- if (!resized) {
- resized = true;
- Point size = getSize ();
- oldWidth = size.x;// - trimWidth ();
- oldHeight = size.y;// - trimHeight ();
- sendEvent (SWT.Resize);
- if (isDisposed ()) return;
- if (layout != null) {
- markLayout (false, false);
- updateLayout (false, false);
- }
- }
-
- } else {
- if (!closing) {
- if ((style & SWT.ON_TOP) != 0) {
- OS.Popup_IsOpen (shellHandle, visible);
- } else {
- OS.Window_Hide (shellHandle);
- }
- }
- }
-}
-
-int topHandle () {
- return shellHandle;
-}
-
-//boolean translateAccelerator (MSG msg) {
-// if (!isEnabled () || !isActive ()) return false;
-// if (menuBar != null && !menuBar.isEnabled ()) return false;
-// return translateMDIAccelerator (msg) || translateMenuAccelerator (msg);
-//}
-
-boolean traverseEscape () {
- if (parent == null) return false;
- if (!isVisible () || !isEnabled ()) return false;
- close ();
- return true;
-}
-
-void updateModal () {
- int source = OS.PresentationSource_FromVisual (handle);
- if (source != 0) {
- int hwnd = OS.HwndSource_Handle (source);
- Win32.EnableWindow (OS.IntPtr_ToInt32 (hwnd), isActive ());
- OS.GCHandle_Free (hwnd);
- OS.GCHandle_Free (source);
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Slider.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Slider.java
deleted file mode 100644
index c806643d73..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Slider.java
+++ /dev/null
@@ -1,492 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that represent a range of positive, numeric values.
- * <p>
- * At any given moment, a given slider will have a
- * single 'selection' that is considered to be its
- * value, which is constrained to be within the range of
- * values the slider represents (that is, between its
- * <em>minimum</em> and <em>maximum</em> values).
- * </p><p>
- * Typically, sliders will be made up of five areas:
- * <ol>
- * <li>an arrow button for decrementing the value</li>
- * <li>a page decrement area for decrementing the value by a larger amount</li>
- * <li>a <em>thumb</em> for modifying the value by mouse dragging</li>
- * <li>a page increment area for incrementing the value by a larger amount</li>
- * <li>an arrow button for incrementing the value</li>
- * </ol>
- * Based on their style, sliders are either <code>HORIZONTAL</code>
- * (which have a left facing button for decrementing the value and a
- * right facing button for incrementing it) or <code>VERTICAL</code>
- * (which have an upward facing button for decrementing the value
- * and a downward facing buttons for incrementing it).
- * </p><p>
- * On some platforms, the size of the slider's thumb can be
- * varied relative to the magnitude of the range of values it
- * represents (that is, relative to the difference between its
- * maximum and minimum values). Typically, this is used to
- * indicate some proportional value such as the ratio of the
- * visible area of a document to the total amount of space that
- * it would take to display it. SWT supports setting the thumb
- * size even if the underlying platform does not, but in this
- * case the appearance of the slider will not change.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see ScrollBar
- * @see <a href="http://www.eclipse.org/swt/snippets/#slider">Slider snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Slider extends Control {
- boolean ignoreFocus;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#HORIZONTAL
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Slider (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's value, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values:
- * <code>SWT.NONE</code> - for the end of a drag.
- * <code>SWT.DRAG</code>.
- * <code>SWT.HOME</code>.
- * <code>SWT.END</code>.
- * <code>SWT.ARROW_DOWN</code>.
- * <code>SWT.ARROW_UP</code>.
- * <code>SWT.PAGE_DOWN</code>.
- * <code>SWT.PAGE_UP</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's value
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += OS.SystemParameters_HorizontalScrollBarButtonWidth () * 10;
- height += OS.SystemParameters_HorizontalScrollBarHeight ();
- } else {
- width += OS.SystemParameters_VerticalScrollBarWidth ();
- height += OS.SystemParameters_VerticalScrollBarButtonHeight () * 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-
-void createHandle () {
- handle = OS.gcnew_ScrollBar ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.HORIZONTAL) != 0) OS.ScrollBar_Orientation (handle, OS.Orientation_Horizontal);
- OS.RangeBase_Maximum (handle, 100);
- OS.RangeBase_LargeChange (handle, 10);
- OS.RangeBase_SmallChange (handle, 1);
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget ();
- return (int) OS.RangeBase_SmallChange (handle);
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget ();
- int maximum = (int) OS.RangeBase_Maximum (handle);
- int viewSize = (int) OS.ScrollBar_ViewportSize (handle);
- return maximum + viewSize;
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget ();
- return (int) OS.RangeBase_Minimum (handle);
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget ();
- return (int) OS.RangeBase_LargeChange (handle);
-}
-
-/**
- * Returns the 'selection', which is the receiver's value.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget ();
- return (int) OS.RangeBase_Value (handle);
-}
-
-/**
- * Returns the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values.
- *
- * @return the thumb value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getThumb () {
- checkWidget ();
- return (int) OS.ScrollBar_ViewportSize (handle);
-}
-
-void HandleScroll (int sender, int e) {
- if (!checkEvent (e)) return;
- Event event = new Event ();
- switch (OS.ScrollEventArgs_ScrollEventType (e)) {
- case OS.ScrollEventType_EndScroll: return;
- case OS.ScrollEventType_ThumbPosition: event.detail = SWT.NONE; break;
- case OS.ScrollEventType_ThumbTrack: event.detail = SWT.DRAG; break;
- case OS.ScrollEventType_First: event.detail = SWT.HOME; break;
- case OS.ScrollEventType_Last: event.detail = SWT.END; break;
- case OS.ScrollEventType_LargeIncrement: event.detail = SWT.PAGE_DOWN; break;
- case OS.ScrollEventType_LargeDecrement: event.detail = SWT.PAGE_UP; break;
- case OS.ScrollEventType_SmallIncrement: event.detail = SWT.ARROW_DOWN; break;
- case OS.ScrollEventType_SmallDecrement: event.detail = SWT.ARROW_UP; break;
- }
- postEvent (SWT.Selection, event);
-}
-
-void hookEvents () {
- super.hookEvents ();
- int handler = OS.gcnew_ScrollEventHandler (jniRef, "HandleScroll");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ScrollBar_Scroll (handle, handler);
- OS.GCHandle_Free (handler);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's value.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- OS.RangeBase_SmallChange (handle, value);
-}
-
-/**
- * Sets the maximum. If this value is negative or less than or
- * equal to the minimum, the value is ignored. If necessary, first
- * the thumb and then the selection are adjusted to fit within the
- * new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget ();
- if (value < 0) return;
- int minimum = (int) OS.RangeBase_Minimum (handle);
- if (value <= minimum) return;
- int viewSize = (int) OS.ScrollBar_ViewportSize (handle);
- if (value - minimum < viewSize) {
- viewSize = value - minimum;
- OS.ScrollBar_ViewportSize (handle, viewSize);
- }
- OS.RangeBase_Maximum (handle, value - viewSize);
-}
-
-/**
- * Sets the minimum value. If this value is negative or greater
- * than or equal to the maximum, the value is ignored. If necessary,
- * first the thumb and then the selection are adjusted to fit within
- * the new range.
- *
- * @param value the new minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget ();
- if (value < 0) return;
- int viewSize = (int) OS.ScrollBar_ViewportSize (handle);
- int maximum = (int) OS.RangeBase_Maximum (handle) + viewSize;
- if (value >= maximum) return;
- if (maximum - value < viewSize) {
- viewSize = maximum - value;
- OS.RangeBase_Maximum (handle, maximum - viewSize);
- OS.ScrollBar_ViewportSize (handle, viewSize);
- }
- OS.RangeBase_Minimum (handle, value);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- OS.RangeBase_LargeChange (handle, value);
-}
-
-/**
- * Sets the 'selection', which is the receiver's
- * value, to the argument which must be greater than or equal
- * to zero.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget ();
- OS.RangeBase_Value (handle, value);
-}
-
-/**
- * Sets the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values. This new
- * value will be ignored if it is less than one, and will be
- * clamped if it exceeds the receiver's current range.
- *
- * @param value the new thumb value, which must be at least one and not
- * larger than the size of the current range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setThumb (int value) {
- checkWidget ();
- if (value < 1) return;
- int minimum = (int) OS.RangeBase_Minimum (handle);
- int viewSize = (int) OS.ScrollBar_ViewportSize (handle);
- int maximum = (int) OS.RangeBase_Maximum (handle) + viewSize;
- value = Math.min (value, maximum - minimum);
- OS.RangeBase_Maximum (handle, maximum - value);
- OS.ScrollBar_ViewportSize (handle, value);
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, thumb, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param thumb the new thumb value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- checkWidget();
- if (minimum < 0) return;
- if (maximum < 0) return;
- if (thumb < 1) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- thumb = Math.min (thumb, maximum - minimum);
- OS.RangeBase_Minimum (handle, minimum);
- OS.RangeBase_Maximum (handle, maximum - thumb);
- OS.ScrollBar_ViewportSize (handle, thumb);
- OS.RangeBase_Value (handle, selection);
- OS.RangeBase_LargeChange (handle, pageIncrement);
- OS.RangeBase_SmallChange (handle, increment);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Spinner.java
deleted file mode 100644
index 96a1f83c29..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Spinner.java
+++ /dev/null
@@ -1,991 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify numeric
- * values.
- * <p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, Modify, Verify</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#spinner">Spinner snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Spinner extends Composite {
- int textHandle, upHandle, downHandle;
- int increment, pageIncrement, digits, max, min, value;
-
- /**
- * the operating system limit for the number of characters
- * that the text field in an instance of this class can hold
- *
- * @since 3.4
- */
- public static final int LIMIT;
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0x7FFFFFFF;
- }
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#READ_ONLY
- * @see SWT#WRAP
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Spinner (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-Control [] _getChildren () {
- return new Control [0];
-}
-
-static int checkStyle (int style) {
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-int backgroundHandle () {
- return textHandle;
-}
-
-int backgroundProperty () {
- return OS.Control_BackgroundProperty ();
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- return super.computeSize (handle, wHint, hHint, changed);
-}
-
-int createArrow (int direction) {
- int geometry = OS.gcnew_StreamGeometry ();
- int context = OS.StreamGeometry_Open (geometry);
- int start = 0, point = 0, end = 0;
- switch (direction) {
- case SWT.DOWN:
- start = OS.gcnew_Point (0, 0);
- point = OS.gcnew_Point (3, 3);
- end = OS.gcnew_Point (6, 0);
- break;
- case SWT.UP:
- start = OS.gcnew_Point (0, 3);
- point = OS.gcnew_Point (3, 0);
- end = OS.gcnew_Point (6, 3);
- break;
- }
- OS.StreamGeometryContext_BeginFigure (context, start, true, true);
- OS.StreamGeometryContext_LineTo (context, point, true, true);
- OS.StreamGeometryContext_LineTo (context, end, true, true);
- OS.StreamGeometryContext_Close (context);
- int path = OS.gcnew_Path ();
- OS.Path_Data (path, geometry);
- int padding = OS.gcnew_Thickness (3, 0, 3, 0);
- OS.FrameworkElement_Margin (path, padding);
- int brush = OS.Brushes_Black ();
- OS.Path_Fill (path, brush);
- OS.FrameworkElement_HorizontalAlignment (path, OS.HorizontalAlignment_Center);
- OS.FrameworkElement_VerticalAlignment (path, OS.VerticalAlignment_Center);
- OS.GCHandle_Free (padding);
- OS.GCHandle_Free (start);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (end);
- OS.GCHandle_Free (brush);
- OS.GCHandle_Free (context);
- OS.GCHandle_Free (geometry);
- return path;
-}
-
-void createHandle () {
- handle = OS.gcnew_Grid ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- int row0 = OS.gcnew_RowDefinition ();
- int row1 = OS.gcnew_RowDefinition ();
- int rows = OS.Grid_RowDefinitions (handle);
- OS.RowDefinitionCollection_Add (rows, row0);
- OS.RowDefinitionCollection_Add (rows, row1);
- int col0 = OS.gcnew_ColumnDefinition ();
- int col1 = OS.gcnew_ColumnDefinition ();
- int columns = OS.Grid_ColumnDefinitions (handle);
- OS.ColumnDefinitionCollection_Add (columns, col0);
- OS.ColumnDefinitionCollection_Add (columns, col1);
- int gridChildren = OS.Panel_Children (handle);
- textHandle = OS.gcnew_TextBox ();
- if (textHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.Grid_SetRowSpan (textHandle, 2);
- OS.UIElementCollection_Add (gridChildren, textHandle);
- if ((style & SWT.READ_ONLY) != 0) OS.TextBoxBase_IsReadOnly (textHandle, true);
- upHandle = OS.gcnew_RepeatButton ();
- if (upHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int upArrow = createArrow (SWT.UP);
- OS.ContentControl_Content (upHandle, upArrow);
- OS.Grid_SetColumn (upHandle, 1);
- OS.UIElementCollection_Add (gridChildren, upHandle);
- downHandle = OS.gcnew_RepeatButton ();
- if (downHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int downArrow = createArrow (SWT.DOWN);
- OS.ContentControl_Content (downHandle, downArrow);
- OS.Grid_SetColumn (downHandle, 1);
- OS.Grid_SetRow (downHandle, 1);
- OS.UIElementCollection_Add (gridChildren, downHandle);
- int colWidth0 = OS.gcnew_GridLength (10, OS.GridUnitType_Star);
- OS.ColumnDefinition_Width(col0, colWidth0);
- int colWidth1 = OS.gcnew_GridLength (1, OS.GridUnitType_Auto);
- OS.ColumnDefinition_Width (col1, colWidth1);
- OS.GCHandle_Free (colWidth0);
- OS.GCHandle_Free (colWidth1);
- OS.GCHandle_Free (upArrow);
- OS.GCHandle_Free (downArrow);
- OS.GCHandle_Free (row0);
- OS.GCHandle_Free (row1);
- OS.GCHandle_Free (rows);
- OS.GCHandle_Free (col0);
- OS.GCHandle_Free (col1);
- OS.GCHandle_Free (columns);
- OS.GCHandle_Free (gridChildren);
-}
-
-void createWidget () {
- super.createWidget();
- increment = 1;
- pageIncrement = 10;
- digits = 0;
- max = 100;
- value = 0;
- int ptr = createDotNetString ("0", false);
- OS.TextBox_Text (textHandle, ptr);
- OS.GCHandle_Free (ptr);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is not called for texts.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- */
-void addVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void copy () {
- checkWidget ();
- //TODO
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void cut () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- //TODO
-}
-
-/**
- * Returns the number of decimal places used by the receiver.
- *
- * @return the digits
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getDigits () {
- checkWidget ();
- return digits;
-}
-
-String getDecimalSeparator () {
- return ".";
-}
-
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down arrows are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getIncrement () {
- checkWidget ();
- return increment;
-}
-
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMaximum () {
- checkWidget ();
- return max;
-}
-
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getMinimum () {
- checkWidget ();
- return min;
-}
-
-/**
- * Returns the amount that the receiver's position will be
- * modified by when the page up/down keys are pressed.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getPageIncrement () {
- checkWidget ();
- return pageIncrement;
-}
-
-/**
- * Returns the <em>selection</em>, which is the receiver's position.
- *
- * @return the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelection () {
- checkWidget ();
- return value;
-}
-
-int getSelectionText (boolean [] parseFail) {
- int textPtr = OS.TextBox_Text (textHandle);
- String string = createJavaString (textPtr);
- OS.GCHandle_Free (textPtr);
- try {
- int value;
- if (digits > 0) {
- String decimalSeparator = getDecimalSeparator ();
- int index = string.indexOf (decimalSeparator);
- if (index != -1) {
- int startIndex = string.startsWith ("+") || string.startsWith ("-") ? 1 : 0;
- String wholePart = startIndex != index ? string.substring (startIndex, index) : "0";
- String decimalPart = string.substring (index + 1);
- if (decimalPart.length () > digits) {
- decimalPart = decimalPart.substring (0, digits);
- } else {
- int i = digits - decimalPart.length ();
- for (int j = 0; j < i; j++) {
- decimalPart = decimalPart + "0";
- }
- }
- int wholeValue = Integer.parseInt (wholePart);
- int decimalValue = Integer.parseInt (decimalPart);
- for (int i = 0; i < digits; i++) wholeValue *= 10;
- value = wholeValue + decimalValue;
- if (string.startsWith ("-")) value = -value;
- } else {
- value = Integer.parseInt (string);
- for (int i = 0; i < digits; i++) value *= 10;
- }
- } else {
- value = Integer.parseInt (string);
- }
- if (min <= value && value <= max) return value;
- } catch (NumberFormatException e) {
- }
- parseFail [0] = true;
- return -1;
-}
-
-/**
- * Returns a string containing a copy of the contents of the
- * receiver's text field, or an empty string if there are no
- * contents.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public String getText () {
- checkWidget ();
- int text = OS.TextBox_Text (textHandle);
- String string = createJavaString (text);
- OS.GCHandle_Free (text);
- return string;
-}
-
-/**
- * Returns the maximum number of characters that the receiver's
- * text field is capable of holding. If this has not been changed
- * by <code>setTextLimit()</code>, it will be the constant
- * <code>Spinner.LIMIT</code>.
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- *
- * @since 3.4
- */
-public int getTextLimit () {
- checkWidget ();
- return OS.TextBox_MaxLength (textHandle);
-}
-
-void HandleDownClick (int sender, int e) {
- if (!checkEvent (e)) return;
- updateSelection (-increment);
-}
-
-void HandleLostKeyboardFocus (int sender, int e) {
- if (!checkEvent (e)) return;
- boolean [] parseFail = new boolean [1];
- getSelectionText (parseFail);
- if (parseFail [0]) {
- setSelection (value, false, true, false);
- }
- super.HandleLostKeyboardFocus (sender, e);
-}
-
-void HandlePreviewKeyDown (int sender, int e) {
- super.HandlePreviewKeyDown (sender, e);
- if (!checkEvent (e)) return;
- int key = OS.KeyEventArgs_Key (e);
- int delta = 0;
- switch (key) {
- case OS.Key_Return:
- postEvent (SWT.DefaultSelection);
- break;
- case OS.Key_Down: delta -= increment; break;
- case OS.Key_Up: delta += increment; break;
- case OS.Key_PageDown: delta -= pageIncrement; break;
- case OS.Key_PageUp: delta += pageIncrement; break;
- }
- if (delta != 0) {
- updateSelection (delta);
- }
-}
-
-void HandlePreviewTextInput (int sender, int e) {
- super.HandlePreviewTextInput (sender, e);
- if (!checkEvent (e)) return;
- int textPtr = OS.TextCompositionEventArgs_Text (e);
- String input = createJavaString(textPtr);
- OS.GCHandle_Free (textPtr);
- int start = OS.TextBox_SelectionStart (textHandle);
- int end = start + OS.TextBox_SelectionLength (textHandle);
- String text = verifyText (input, start, end);
- if (text != null && !text.equals (input)) {
- textPtr = createDotNetString (text, false);
- OS.TextBox_SelectedText (textHandle, textPtr);
- OS.GCHandle_Free (textPtr);
- start = OS.TextBox_SelectionStart (textHandle);
- int length = OS.TextBox_SelectionLength (textHandle);
- OS.TextBox_Select (textHandle, start+length, 0);
- OS.TextBox_SelectionLength (textHandle, 0);
- text = null;
- }
- if (text == null) OS.TextCompositionEventArgs_Handled (e, true);
-}
-
-void HandleTextChanged (int sender, int e) {
- if (!checkEvent (e)) return;
- boolean [] parseFail = new boolean [1];
- int value = getSelectionText (parseFail);
- if (!parseFail [0]) {
- if (this.value != value) setSelection(value, true, false, true);
- }
- sendEvent (SWT.Modify);
-}
-
-void HandleUpClick (int sender, int e) {
- if (!checkEvent (e)) return;
- updateSelection (increment);
-}
-
-void hookEvents () {
- super.hookEvents();
- //TEXT
- int handler = OS.gcnew_TextCompositionEventHandler (jniRef, "HandlePreviewTextInput");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.UIElement_PreviewTextInput (textHandle, handler);
- OS.GCHandle_Free (handler);
-// handler = OS.gcnew_ExecutedRoutedEventHandler(jniRef, "HandlePreviewExecutedRoutedEvent");
-// if (handler == 0) error (SWT.ERROR_NO_HANDLES);
-// OS.CommandManager_AddPreviewExecutedHandler(handle, handler);
-// OS.GCHandle_Free(handler);
- handler = OS.gcnew_TextChangedEventHandler (jniRef, "HandleTextChanged");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.TextBoxBase_TextChanged (textHandle, handler);
- OS.GCHandle_Free (handler);
-
- //BUTTON
- handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleDownClick");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ButtonBase_Click (downHandle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleUpClick");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ButtonBase_Click (upHandle, handler);
- OS.GCHandle_Free (handler);
-}
-
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void paste () {
- checkWidget ();
- //TODO
-}
-
-void releaseHandle () {
- super.releaseHandle();
- OS.GCHandle_Free (textHandle);
- OS.GCHandle_Free (upHandle);
- OS.GCHandle_Free (downHandle);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- */
-void removeVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-
-/**
- * Sets the number of decimal places used by the receiver.
- * <p>
- * The digit setting is used to allow for floating point values in the receiver.
- * For example, to set the selection to a floating point value of 1.37 call setDigits() with
- * a value of 2 and setSelection() with a value of 137. Similarly, if getDigits() has a value
- * of 2 and getSelection() returns 137 this should be interpreted as 1.37. This applies to all
- * numeric APIs.
- * </p>
- *
- * @param value the new digits (must be greater than or equal to zero)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the value is less than zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDigits (int value) {
- checkWidget ();
- if (value < 0) error (SWT.ERROR_INVALID_ARGUMENT);
- digits = value;
- setSelection (this.value, false, true, false);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down arrows are pressed to
- * the argument, which must be at least one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- increment = value;
-}
-
-/**
- * Sets the maximum value that the receiver will allow. This new
- * value will be ignored if it is not greater than the receiver's current
- * minimum value. If the new maximum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new maximum, which must be greater than the current minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMaximum (int value) {
- checkWidget ();
- if (value <= min) return;
- max = value;
- if (this.value > value) setSelection (value, true, true, false);
-}
-
-/**
- * Sets the minimum value that the receiver will allow. This new
- * value will be ignored if it is not less than the receiver's
- * current maximum value. If the new minimum is applied then the receiver's
- * selection value will be adjusted if necessary to fall within its new range.
- *
- * @param value the new minimum, which must be less than the current maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setMinimum (int value) {
- checkWidget ();
- if (value >= max) return;
- min = value;
- if (this.value < value) setSelection (value, true, true, false);
-}
-
-/**
- * Sets the amount that the receiver's position will be
- * modified by when the page up/down keys are pressed
- * to the argument, which must be at least one.
- *
- * @param value the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- pageIncrement = value;
-}
-
-/**
- * Sets the <em>selection</em>, which is the receiver's
- * position, to the argument. If the argument is not within
- * the range specified by minimum and maximum, it will be
- * adjusted to fall within this range.
- *
- * @param value the new selection (must be zero or greater)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int value) {
- checkWidget ();
- value = Math.min (Math.max (min, value), max);
- setSelection (value, true, true, false);
-}
-
-void setSelection (int value, boolean setPos, boolean setText, boolean notify) {
- if (setPos) {
- this.value = value;
- }
- if (setText) {
- String string;
- if (digits == 0) {
- string = String.valueOf (value);
- } else {
- string = String.valueOf (Math.abs (value));
- String decimalSeparator = getDecimalSeparator ();
- int index = string.length () - digits;
- StringBuffer buffer = new StringBuffer ();
- if (value < 0) buffer.append ("-");
- if (index > 0) {
- buffer.append (string.substring (0, index));
- buffer.append (decimalSeparator);
- buffer.append (string.substring (index));
- } else {
- buffer.append ("0");
- buffer.append (decimalSeparator);
- while (index++ < 0) buffer.append ("0");
- buffer.append (string);
- }
- string = buffer.toString ();
- }
-// if (hooks (SWT.Verify) || filters (SWT.Verify)) {
-// int length = OS.GetWindowTextLength (hwndText);
-// string = verifyText (string, 0, length, null);
-// if (string == null) return;
-// }
- int ptr = createDotNetString (string, false);
- OS.TextBox_Text (textHandle, ptr);
- OS.GCHandle_Free (ptr);
- }
- if (notify) postEvent (SWT.Selection);
-}
-
-/**
- * Sets the maximum number of characters that the receiver's
- * text field is capable of holding to be the argument.
- * <p>
- * To reset this value to the default, use <code>setTextLimit(Spinner.LIMIT)</code>.
- * Specifying a limit value larger than <code>Spinner.LIMIT</code> sets the
- * receiver's limit to <code>Spinner.LIMIT</code>.
- * </p>
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- *
- * @since 3.4
- */
-public void setTextLimit (int limit) {
- checkWidget ();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- OS.TextBox_MaxLength (textHandle, limit);
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, digits, increment and page increment all at once.
- * <p>
- * Note: This is similar to setting the values individually
- * using the appropriate methods, but may be implemented in a
- * more efficient fashion on some platforms.
- * </p>
- *
- * @param selection the new selection value
- * @param minimum the new minimum value
- * @param maximum the new maximum value
- * @param digits the new digits value
- * @param increment the new increment value
- * @param pageIncrement the new pageIncrement value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setValues (int selection, int minimum, int maximum, int digits, int increment, int pageIncrement) {
- checkWidget ();
- if (maximum <= minimum) return;
- if (digits < 0) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- selection = Math.min (Math.max (minimum, selection), maximum);
- this.pageIncrement = pageIncrement;
- this.increment = increment;
- this.digits = digits;
- this.min = minimum;
- this.max = maximum;
- setSelection (selection, true, true, false);
-}
-
-void updateSelection (int delta) {
- boolean [] parseFail = new boolean [1];
- int value = getSelectionText (parseFail);
- if (parseFail [0]) value = this.value;
- int newValue = value + delta;
- if ((style & SWT.WRAP) != 0) {
- if (newValue < min) newValue = max;
- if (newValue > max) newValue = min;
- }
- newValue = Math.min (Math.max (min, newValue), max);
- if (value != newValue) setSelection (newValue, true, true, true);
-}
-
-String verifyText (String string, int start, int end) {
- Event event = new Event ();
- event.text = string;
- event.start = start;
- event.end = end;
- if (string.length () == 1) {
- event.character = string.charAt (0);
- setInputState (event, SWT.KeyDown, 0, 0);
- }
- int index = 0;
- if (digits > 0) {
- String decimalSeparator = getDecimalSeparator ();
- index = string.indexOf (decimalSeparator);
- if (index != -1) {
- string = string.substring (0, index) + string.substring (index + 1);
- }
- index = 0;
- }
- if (string.length() > 0) {
- if (min < 0 && string.charAt (0) == '-') index++;
- }
- while (index < string.length ()) {
- if (!Character.isDigit (string.charAt (index))) break;
- index++;
- }
- event.doit = index == string.length ();
- sendEvent (SWT.Verify, event);
- if (!event.doit || isDisposed ()) return null;
- return event.text;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TabFolder.java
deleted file mode 100644
index 9100ff47f0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TabFolder.java
+++ /dev/null
@@ -1,731 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.wpf.*;
-
-/**
- * Instances of this class implement the notebook user interface
- * metaphor. It allows the user to select a notebook page from
- * set of pages.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TabItem</code>.
- * <code>Control</code> children are created and then set into a
- * tab item using <code>TabItem#setControl</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>TOP, BOTTOM</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles TOP and BOTTOM may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tabfolder">TabFolder, TabItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TabFolder extends Composite {
- int parentingHandle;
- int itemCount;
- Control [] children;
- int childCount;
- boolean ignoreSelection;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see SWT#TOP
- * @see SWT#BOTTOM
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabFolder (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-int backgroundProperty () {
- return OS.Control_BackgroundProperty ();
-}
-
-void addChild (Control widget) {
- super.addChild (widget);
- if (childCount == children.length) {
- Control [] newChildren = new Control [childCount + 4];
- System.arraycopy (children, 0, newChildren, 0, childCount);
- children = newChildren;
- }
- children [childCount++] = widget;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- /*
- * When the SWT.TOP style has not been set, force the
- * tabs to be on the bottom for tab folders on PPC.
- */
-// if (OS.IsPPC) {
-// if ((style & SWT.TOP) == 0) style |= SWT.BOTTOM;
-// }
- style = checkBits (style, SWT.TOP, SWT.BOTTOM, 0, 0, 0, 0);
-
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-int clientHandle () {
- int index = OS.Selector_SelectedIndex (handle);
- if (index != -1) {
- int items = OS.ItemsControl_Items (handle);
- TabItem item = getItem (items, index);
- OS.GCHandle_Free (items);
- return item.contentHandle;
- }
- return handle;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- Point size = super.computeSize (wHint, hHint, changed);
- Point sizeTabFolder = computeSize (handle, wHint, hHint, changed);
- return new Point (Math.max(sizeTabFolder.x + 1, size.x + 10), size.y + sizeTabFolder.y + 10);
-}
-
-void createItem (TabItem item, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- item.createWidget ();
- int items = OS.ItemsControl_Items (handle);
- OS.ItemCollection_Insert (items, index, item.topHandle ());
- int count = OS.ItemCollection_Count (items);
- OS.GCHandle_Free (items);
- if (itemCount == count) error (SWT.ERROR_ITEM_NOT_ADDED);
- itemCount++;
-}
-
-void createHandle () {
- parentingHandle = OS.gcnew_Canvas ();
- if (parentingHandle == 0) error (SWT.ERROR_NO_HANDLES);
- handle = OS.gcnew_TabControl ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.BOTTOM) != 0) OS.TabControl_TabStripPlacement (handle, OS.Dock_Bottom);
- int children = OS.Panel_Children (parentingHandle);
- OS.UIElementCollection_Add (children, handle);
- OS.GCHandle_Free (children);
- OS.Canvas_SetLeft (handle, 0);
- OS.Canvas_SetTop (handle, 0);
-}
-
-void createWidget () {
- super.createWidget ();
- children = new Control [4];
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (parentingHandle);
-}
-
-void destroyItem (TabItem item) {
- int items = OS.ItemsControl_Items (handle);
- OS.ItemCollection_Remove (items, item.topHandle ());
- int count = OS.ItemCollection_Count (items);
- OS.GCHandle_Free (items);
- if (itemCount == count) error (SWT.ERROR_ITEM_NOT_REMOVED);
- itemCount--;
-}
-
-Control findThemeControl () {
- return this;
-}
-
-Control [] _getChildren () {
- // return children in reverse order.
- Control[] result = new Control [childCount];
- for (int i =0; i < childCount; i++) {
- result [childCount - i - 1] = children [i];
- }
- return result;
-}
-
-public Rectangle getClientArea () {
- checkWidget ();
- Rectangle rect = super.getClientArea ();
- int clientHandle = clientHandle ();
- int topHandle = topHandle ();
- int point = OS.gcnew_Point (0, 0);
- int result = OS.UIElement_TranslatePoint (clientHandle, point, topHandle);
- rect.x = (int) OS.Point_X (result);
- rect.y = (int) OS.Point_Y (result);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (result);
- return rect;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem getItem (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- int items = OS.ItemsControl_Items (handle);
- TabItem item = getItem (items, index);
- OS.GCHandle_Free (items);
- return item;
-}
-
-TabItem getItem (int items, int index) {
- int item = OS.ItemCollection_GetItemAt (items, index);
- TabItem result = (TabItem) display.getWidget (item);
- OS.GCHandle_Free (item);
- return result;
-}
-
-/**
- * Returns the tab item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- *
- * @param point the point used to locate the item
- * @return the tab item at the given point, or null if the point is not in a tab item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public TabItem getItem (Point point) {
- checkWidget();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- int items = OS.ItemsControl_Items (handle);
- for (int index = 0; index < itemCount; index++) {
- TabItem item = getItem (items, index);
- Rectangle bounds = item.getBounds();
- if (bounds.contains(point)) {
- OS.GCHandle_Free (items);
- return item;
- }
- }
- OS.GCHandle_Free (items);
- return null;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- return itemCount;
-}
-
-/**
- * Returns an array of <code>TabItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem [] getItems () {
- checkWidget ();
- TabItem [] result = new TabItem [itemCount];
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<itemCount; i++) {
- result [i] = getItem (items, i);
- }
- OS.GCHandle_Free (items);
- return result;
-}
-
-/**
- * Returns an array of <code>TabItem</code>s that are currently
- * selected in the receiver. An empty array indicates that no
- * items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabItem [] getSelection () {
- checkWidget ();
- int index = OS.Selector_SelectedIndex (handle);
- if (index == -1) return new TabItem [0];
- int items = OS.ItemsControl_Items (handle);
- TabItem item = getItem (items, index);
- OS.GCHandle_Free (items);
- return new TabItem [] {item};
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget ();
- return OS.Selector_SelectedIndex (handle);
-}
-
-boolean hasItems () {
- return true;
-}
-
-void HandleSelectionChanged (int sender, int e) {
- if (!checkEvent (e)) return;
- int removed = OS.SelectionChangedEventArgs_RemovedItems (e);
- if (OS.ICollection_Count (removed) > 0) {
- int oldSelection = OS.IList_default (removed, 0);
- TabItem item = (TabItem) display.getWidget (oldSelection);
- OS.GCHandle_Free (oldSelection);
- Control control = item.getControl();
- if (control != null && !control.isDisposed ()) {
- control.setVisible (false);
- }
- }
- OS.GCHandle_Free (removed);
- int selectedItem = OS.Selector_SelectedItem (handle);
- if (selectedItem == 0) return;
- TabItem item = (TabItem) display.getWidget (selectedItem);
- OS.GCHandle_Free (selectedItem);
-
- Control control = item.getControl();
- if (control != null && !control.isDisposed ()) {
- control.setVisible (true);
- }
- if (ignoreSelection) return;
- Event event = new Event ();
- event.item = item;
- postEvent (SWT.Selection, event);
-}
-
-void hookEvents () {
- super.hookEvents ();
- int handler = OS.gcnew_SelectionChangedEventHandler (jniRef, "HandleSelectionChanged");
- OS.Selector_SelectionChanged (handle, handler);
- OS.GCHandle_Free (handler);
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (TabItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- int items = OS.ItemsControl_Items (handle);
- int index = OS.ItemCollection_IndexOf (items, item.topHandle ());
- OS.GCHandle_Free (items);
- return index;
-}
-
-Point minimumSize (int wHint, int hHint, boolean flushCache) {
- Control [] children = _getChildren ();
- int width = 0, height = 0;
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- int index = 0;
- while (index < itemCount) {
- TabItem item = getItem (items, index);
- if (item.control == child) break;
- index++;
- }
- if (index == itemCount) {
- Rectangle rect = child.getBounds ();
- width = Math.max (width, rect.x + rect.width);
- height = Math.max (height, rect.y + rect.height);
- } else {
- Point size = child.computeSize (wHint, hHint, flushCache);
- width = Math.max (width, size.x);
- height = Math.max (height, size.y);
- }
- }
- OS.GCHandle_Free (items);
- return new Point (width, height);
-}
-
-boolean mnemonicHit (char key) {
- //TODO
- return false;
-}
-
-boolean mnemonicMatch (char key) {
- boolean found = false;
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<itemCount; i++) {
- TabItem item = getItem (items, i);
- if (mnemonicMatch (item.textHandle, key)) {
- found = true;
- break;
- }
- }
- OS.GCHandle_Free (items);
- return found;
-}
-
-int parentingHandle() {
- return parentingHandle;
-}
-
-void register () {
- super.register ();
- display.addWidget (parentingHandle, this);
-}
-
-void releaseChildren (boolean destroy) {
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<itemCount; i++) {
- TabItem item = getItem (items, i);
- if (item != null && !item.isDisposed ()) item.release (false);
- }
- OS.GCHandle_Free (items);
- super.releaseChildren (destroy);
-}
-
-void removeChild (Control control) {
- super.removeChild (control);
- int index = 0;
- while (index < childCount) {
- if (children [index] == control) break;
- index++;
- }
- if (index == childCount) return;
- System.arraycopy (children, index+1, children, index, --childCount - index);
- children [childCount] = null;
-}
-
-void releaseHandle() {
- super.releaseHandle ();
- if (parentingHandle != 0) OS.GCHandle_Free (parentingHandle);
- parentingHandle = 0;
-}
-
-void removeControl (Control control) {
- super.removeControl (control);
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<itemCount; i++) {
- TabItem item = getItem (items, i);
- if (item.control == control) {
- item.setControl (null);
- break;
- }
- }
- OS.GCHandle_Free (items);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-int setBounds (int x, int y, int width, int height, int flags) {
- int result = super.setBounds (x, y, width, height, flags);
- if ((result & RESIZED) != 0) {
- OS.FrameworkElement_Height (handle, height);
- OS.FrameworkElement_Width (handle, width);
- int selectedItem = OS.Selector_SelectedItem (handle);
- if (selectedItem != 0) {
- TabItem item = (TabItem) display.getWidget (selectedItem);
- OS.GCHandle_Free (selectedItem);
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setBounds (getClientArea ());
- }
- }
- }
- return result;
-}
-
-void setForegroundBrush (int brush) {
- if (brush != 0) {
- OS.Control_Foreground (handle, brush);
- } else {
- int property = OS.Control_ForegroundProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
-}
-
-/**
- * Sets the receiver's selection to the given item.
- * The current selected is first cleared, then the new item is
- * selected.
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection (TabItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (new TabItem [] {item});
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selected is first cleared, then the new items are
- * selected.
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the items array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (TabItem [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (items.length == 0) {
- setSelection (-1, false);
- } else {
- for (int i=items.length-1; i>=0; --i) {
- int index = indexOf (items [i]);
- if (index != -1) setSelection (index, false);
- }
- }
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains selected.
- * The current selection is first cleared, then the new items are
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) return;
- setSelection (index, false);
-}
-
-void setSelection (int index, boolean notify) {
- int oldIndex = OS.Selector_SelectedIndex (handle);
- if (oldIndex != -1) {
- int items = OS.ItemsControl_Items (handle);
- TabItem item = getItem (items, oldIndex);
- OS.GCHandle_Free (items);
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setVisible (false);
- }
- }
- ignoreSelection = true;
- OS.Selector_SelectedIndex (handle, index);
- ignoreSelection = false;
- int newIndex = OS.Selector_SelectedIndex (handle);
- if (newIndex != -1) {
- int items = OS.ItemsControl_Items (handle);
- TabItem item = getItem (items, newIndex);
- OS.GCHandle_Free (items);
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
-// control.setBounds (getClientArea ());
- control.setVisible (true);
- }
- if (notify) {
- Event event = new Event ();
- event.item = item;
- sendEvent (SWT.Selection, event);
- }
- }
-}
-
-int topHandle() {
- return parentingHandle;
-}
-
-boolean traversePage (boolean next) {
-// GTK: OS.g_signal_emit_by_name (handle, OS.change_current_page, next ? 1 : -1);
- int count = getItemCount ();
- if (count <= 1) return false;
- int index = getSelectionIndex ();
- if (index == -1) {
- index = 0;
- } else {
- int offset = (next) ? 1 : -1;
- index = (index + offset + count) % count;
- }
- setSelection (index, true);
- if (index == getSelectionIndex ()) {
-// OS.SendMessage (handle, OS.WM_CHANGEUISTATE, OS.UIS_INITIALIZE, 0);
- return true;
- }
- return false;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TabItem.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TabItem.java
deleted file mode 100644
index 2a87cd4f2f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TabItem.java
+++ /dev/null
@@ -1,406 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * corresponding to a tab for a page in a tab folder.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tabfolder">TabFolder, TabItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class TabItem extends Item {
- TabFolder parent;
- Control control;
- String toolTipText;
- int imageHandle, textHandle, contentHandle;
-
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>TabFolder</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabItem (TabFolder parent, int style) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>TabFolder</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TabItem (TabFolder parent, int style, int index) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createHandle () {
- handle = OS.gcnew_TabItem ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- imageHandle = OS.gcnew_Image ();
- if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.Image_Stretch (imageHandle, OS.Stretch_None);
- int thickness = OS.gcnew_Thickness (0, 0, 3, 0);
- if (thickness == 0) error (SWT.ERROR_NO_HANDLES);
- OS.FrameworkElement_Margin (imageHandle, thickness);
- OS.GCHandle_Free (thickness);
- OS.UIElement_Visibility (imageHandle, OS.Visibility_Collapsed);
- textHandle = OS.gcnew_AccessText ();
- if (textHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.FrameworkElement_VerticalAlignment (textHandle, OS.VerticalAlignment_Center);
- int panel = OS.gcnew_StackPanel ();
- if (panel == 0) error (SWT.ERROR_NO_HANDLES);
- OS.StackPanel_Orientation (panel, OS.Orientation_Horizontal);
- thickness = OS.gcnew_Thickness (1, 1, 1, 1);
- if (thickness == 0) error (SWT.ERROR_NO_HANDLES);
- OS.FrameworkElement_Margin (panel, thickness);
- OS.GCHandle_Free(thickness);
- int children = OS.Panel_Children (panel);
- OS.UIElementCollection_Add (children, imageHandle);
- OS.UIElementCollection_Add (children, textHandle);
- OS.HeaderedContentControl_Header (handle, panel);
- OS.GCHandle_Free (children);
- OS.GCHandle_Free (panel);
- contentHandle = OS.gcnew_Canvas ();
- if (contentHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ContentControl_Content (handle, contentHandle);
-}
-
-void deregister () {
- display.removeWidget (handle);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public Rectangle getBounds () {
- checkWidget ();
- int topHandle = handle;
- int point = OS.gcnew_Point (0, 0);
- if (point == 0) error (SWT.ERROR_NO_HANDLES);
- int location = OS.UIElement_TranslatePoint (topHandle, point, parent.handle);
- int x = (int) OS.Point_X (location);
- int y = (int) OS.Point_Y (location);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (location);
- int width = (int) OS.FrameworkElement_ActualWidth (topHandle);
- int height = (int) OS.FrameworkElement_ActualHeight (topHandle);
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the control that is used to fill the client area of
- * the tab folder when the user selects the tab item. If no
- * control has been set, return <code>null</code>.
- * <p>
- * @return the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget();
- return control;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>TabFolder</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TabFolder getParent () {
- checkWidget();
- return parent;
-}
-
-Control getWidgetControl () {
- return parent;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-
-void HandleSizeChanged (int sender, int e) {
- if (!checkEvent (e)) return;
- if (control == null) return;
- control.setBounds (parent.getClientArea ());
-}
-
-void hookEvents () {
- super.hookEvents ();
- int handler = OS.gcnew_SizeChangedEventHandler (jniRef, "HandleSizeChanged");
- OS.FrameworkElement_SizeChanged (contentHandle, handler);
- OS.GCHandle_Free (handler);
-}
-
-void register() {
- display.addWidget (handle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (handle != 0) OS.GCHandle_Free (handle);
- handle = 0;
- parent = null;
- if (textHandle != 0) OS.GCHandle_Free (textHandle);
- textHandle = 0;
- if (imageHandle !=0 )OS.GCHandle_Free (imageHandle);
- imageHandle = 0;
- if (contentHandle != 0) OS.GCHandle_Free (contentHandle);
- contentHandle = 0;
-}
-
-void releaseParent () {
- super.releaseParent ();
- int index = parent.indexOf (this);
- if (index == parent.getSelectionIndex ()) {
- if (control != null) control.setVisible (false);
- }
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- control = null;
- toolTipText = null;
-}
-
-/**
- * Sets the control that is used to fill the client area of
- * the tab folder when the user selects the tab item.
- * <p>
- * @param control the new control (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget();
- if (control != null) {
- if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- if (this.control != null && this.control.isDisposed ()) {
- this.control = null;
- }
- Control oldControl = this.control, newControl = control;
- this.control = control;
- int index = parent.indexOf (this), selectionIndex = parent.getSelectionIndex();
- if (index != selectionIndex) {
- if (newControl != null) {
- if (selectionIndex != -1) {
- Control selectedControl = parent.getItem(selectionIndex).getControl();
- if (selectedControl == newControl) return;
- }
- newControl.setVisible(false);
- return;
- }
- }
- if (newControl != null) {
- newControl.setBounds (parent.getClientArea ());
- newControl.setVisible (true);
- }
- if (oldControl != null) oldControl.setVisible (false);
-}
-
-public void setImage (Image image) {
- checkWidget();
- super.setImage (image);
- OS.Image_Source (imageHandle, image != null ? image.handle : 0);
- OS.UIElement_Visibility (imageHandle, image != null ? OS.Visibility_Visible : OS.Visibility_Collapsed);
-}
-
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (string.equals (text)) return;
- super.setText (string);
- int strPtr = createDotNetString (string, true);
- if (strPtr == 0) error (SWT.ERROR_NO_HANDLES);
- OS.AccessText_Text (textHandle, strPtr);
- OS.GCHandle_Free (strPtr);
-// OS.UIElement_Visibility (textHandle, string.length() == 0 ? OS.Visibility_Collapsed : OS.Visibility_Visible);
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
- if (string != null && string.length() == 0) string = null;
- int strPtr = createDotNetString (string, false);
- int header = OS.HeaderedContentControl_Header (handle);
- OS.FrameworkElement_ToolTip (header, strPtr);
- if (strPtr != 0) OS.GCHandle_Free (strPtr);
- OS.GCHandle_Free (header);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Table.java
deleted file mode 100644
index 068104d290..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Table.java
+++ /dev/null
@@ -1,2417 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.wpf.OS;
-
-/**
- * Instances of this class implement a selectable user interface
- * object that displays a list of images and strings and issues
- * notification when selected.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TableItem</code>.
- * </p><p>
- * Style <code>VIRTUAL</code> is used to create a <code>Table</code> whose
- * <code>TableItem</code>s are to be populated by the client on an on-demand basis
- * instead of up-front. This can provide significant performance improvements for
- * tables that are very large or for which <code>TableItem</code> population is
- * expensive (for example, retrieving values from an external source).
- * </p><p>
- * Here is an example of using a <code>Table</code> with style <code>VIRTUAL</code>:
- * <code><pre>
- * final Table table = new Table (parent, SWT.VIRTUAL | SWT.BORDER);
- * table.setItemCount (1000000);
- * table.addListener (SWT.SetData, new Listener () {
- * public void handleEvent (Event event) {
- * TableItem item = (TableItem) event.item;
- * int index = table.indexOf (item);
- * item.setText ("Item " + index);
- * System.out.println (item.getText ());
- * }
- * });
- * </pre></code>
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not normally make sense to add <code>Control</code> children to
- * it, or set a layout on it, unless implementing something like a cell
- * editor.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, HIDE_SELECTION, VIRTUAL, NO_SCROLL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection, SetData, MeasureItem, EraseItem, PaintItem</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles SINGLE, and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class Table extends Composite {
- int gridViewHandle, parentingHandle;
- int columnCount, itemCount;
- boolean ignoreSelection;
- TableColumn [] columns;
- boolean linesVisible;
-
- static final String CHECKBOX_PART_NAME = "SWT_PART_CHECKBOX";
- static final String IMAGE_PART_NAME = "SWT_PART_IMAGE";
- static final String TEXT_PART_NAME = "SWT_PART_TEXT";
- static final String CONTENTPANEL_PART_NAME = "SWT_PART_CONTENTPANEL";
- static final String RENDER_PANEL_NAME = "SWT_PART_RENDERPANEL";
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#CHECK
- * @see SWT#FULL_SELECTION
- * @see SWT#HIDE_SELECTION
- * @see SWT#VIRTUAL
- * @see SWT#NO_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Table (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-void _addListener (int eventType, Listener listener) {
- super._addListener (eventType, listener);
- switch (eventType) {
- case SWT.MeasureItem:
- case SWT.EraseItem:
- case SWT.PaintItem:
- //TODO
- break;
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * If the receiver has the <code>SWT.CHECK</code> style and the check selection changes,
- * the event object detail field contains the value <code>SWT.CHECK</code>.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * The item field of the event object is valid for default selection, but the detail field is not used.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-int backgroundProperty () {
- return OS.Control_BackgroundProperty ();
-}
-
-boolean checkData (TableItem item) {
- if ((style & SWT.VIRTUAL) == 0) return true;
- if (!item.cached) {
- item.cached = true;
- Event event = new Event ();
- event.item = item;
- event.index = indexOf (item);
- sendEvent (SWT.SetData, event);
- //widget could be disposed at this point
- if (isDisposed () || item.isDisposed ()) return false;
- }
- return true;
-}
-
-static int checkStyle (int style) {
- /*
- * Feature in Windows. Even when WS_HSCROLL or
- * WS_VSCROLL is not specified, Windows creates
- * trees and tables with scroll bars. The fix
- * is to set H_SCROLL and V_SCROLL.
- *
- * NOTE: This code appears on all platforms so that
- * applications have consistent scroll bar behavior.
- */
- if ((style & SWT.NO_SCROLL) == 0) {
- style |= SWT.H_SCROLL | SWT.V_SCROLL;
- }
- /* WPF is always FULL_SELECTION */
- style |= SWT.FULL_SELECTION;
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Clears the item at the given zero-relative index in the receiver.
- * The text, icon and other attributes of the item are set to the default
- * value. If the table was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param index the index of the item to clear
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clear (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- int items = OS.ItemsControl_Items (handle);
- TableItem item = getItem (items, index, false);
- OS.GCHandle_Free (items);
- if (item != null) item.clear ();
-}
-
-/**
- * Removes the items from the receiver which are between the given
- * zero-relative start and end indices (inclusive). The text, icon
- * and other attributes of the items are set to their default values.
- * If the table was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param start the start index of the item to clear
- * @param end the end index of the item to clear
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clear (int start, int end) {
- checkWidget ();
- checkWidget ();
- if (start > end) return;
- if (!(0 <= start && start <= end && end < itemCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- if (start == 0 && end == itemCount - 1) {
- clearAll ();
- } else {
- int items = OS.ItemsControl_Items (handle);
- for (int i=start; i<=end; i++) {
- TableItem item = getItem (items, i, false);
- if (item != null) item.clear ();
- }
- OS.GCHandle_Free (items);
- }
-}
-
-/**
- * Clears the items at the given zero-relative indices in the receiver.
- * The text, icon and other attributes of the items are set to their default
- * values. If the table was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clear (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- for (int i=0; i<indices.length; i++) {
- if (!(0 <= indices [i] && indices [i] < itemCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- }
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<indices.length; i++) {
- int index = indices [i];
- TableItem item = getItem (items, index, false);
- if (item != null) item.clear ();
- }
- OS.GCHandle_Free (items);
-}
-
-/**
- * Clears all the items in the receiver. The text, icon and other
- * attributes of the items are set to their default values. If the
- * table was created with the <code>SWT.VIRTUAL</code> style, these
- * attributes are requested again as needed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.0
- */
-public void clearAll () {
- checkWidget ();
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<itemCount; i++) {
- TableItem item = getItem (items, i, false);
- if (item != null) item.clear ();
- }
- OS.GCHandle_Free (items);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- updateLayout (parent.handle);
- if (columnCount == 0) { // pack the default column
- double width = 0;
- int columns = OS.GridView_Columns (gridViewHandle);
- int column = OS.GridViewColumnCollection_default (columns, 0);
- OS.GCHandle_Free (columns);
- int columnHeader = OS.GridViewColumn_Header (column);
- if (columnHeader != 0) {
- int size = OS.UIElement_DesiredSize (columnHeader);
- width = OS.Size_Width (size);
- OS.GCHandle_Free (size);
- OS.GCHandle_Free (columnHeader);
- }
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<itemCount; i++) {
- TableItem item = getItem (items, i, false);
- if (item != null) width = Math.max (width, item.computeWidth (0));
- }
- OS.GCHandle_Free (items);
- OS.GridViewColumn_Width (column, width);
- OS.GCHandle_Free (column);
- }
- Point size = computeSize (handle, wHint, hHint, changed);
- if (size.x == 0) size.x = DEFAULT_WIDTH;
- if (size.y == 0) size.y = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) size.x = wHint;
- if (hHint != SWT.DEFAULT) size.y = hHint;
- Rectangle trim = computeTrim (0, 0, size.x, size.y);
- return new Point (trim.width, trim.height);
-}
-
-int createCellTemplate (int index) {
- int template = OS.gcnew_DataTemplate ();
- int renderPanelType = OS.SWTDockPanel_typeid ();
- int renderPanelName = createDotNetString(RENDER_PANEL_NAME, false);
- int onRenderNode = OS.gcnew_FrameworkElementFactory (renderPanelType, renderPanelName);
- OS.GCHandle_Free(renderPanelName);
- OS.GCHandle_Free (renderPanelType);
- int jniRefProperty = OS.SWTDockPanel_JNIRefProperty ();
- OS.FrameworkElementFactory_SetValueInt (onRenderNode, jniRefProperty, jniRef);
- OS.GCHandle_Free (jniRefProperty);
- int contentPanelName = createDotNetString (CONTENTPANEL_PART_NAME, false);
- int contentPanelType = OS.StackPanel_typeid ();
- int cellContentNode = OS.gcnew_FrameworkElementFactory (contentPanelType, contentPanelName);
- OS.GCHandle_Free (contentPanelType);
- OS.GCHandle_Free (contentPanelName);
- int clipProperty = OS.UIElement_ClipToBoundsProperty ();
- OS.FrameworkElementFactory_SetValue (cellContentNode, clipProperty, true);
- OS.GCHandle_Free (clipProperty);
- int orientationProperty = OS.StackPanel_OrientationProperty ();
- OS.FrameworkElementFactory_SetValueOrientation (cellContentNode, orientationProperty, OS.Orientation_Horizontal);
- OS.GCHandle_Free (orientationProperty);
- if (index == 0 && (style & SWT.CHECK) != 0) {
- int checkBoxType = OS.CheckBox_typeid ();
- int checkBoxName = createDotNetString (CHECKBOX_PART_NAME, false);
- int checkBoxNode = OS.gcnew_FrameworkElementFactory (checkBoxType, checkBoxName);
- int verticalAlignmentProperty = OS.FrameworkElement_VerticalAlignmentProperty ();
- OS.FrameworkElementFactory_SetValueVerticalAlignment (checkBoxNode, verticalAlignmentProperty, OS.VerticalAlignment_Center);
- int marginProperty = OS.FrameworkElement_MarginProperty ();
- int thickness = OS.gcnew_Thickness (0,0,4,0);
- OS.FrameworkElementFactory_SetValue (checkBoxNode, marginProperty, thickness);
- OS.FrameworkElementFactory_AppendChild (cellContentNode, checkBoxNode);
- OS.GCHandle_Free (thickness);
- OS.GCHandle_Free (marginProperty);
- OS.GCHandle_Free (verticalAlignmentProperty);
- OS.GCHandle_Free (checkBoxName);
- OS.GCHandle_Free (checkBoxNode);
- OS.GCHandle_Free (checkBoxType);
- }
- int textType = OS.TextBlock_typeid ();
- int textName = createDotNetString (TEXT_PART_NAME, false);
- int textNode = OS.gcnew_FrameworkElementFactory (textType, textName);
- OS.GCHandle_Free (textName);
- OS.GCHandle_Free (textType);
- int verticalAlignmentProperty = OS.FrameworkElement_VerticalAlignmentProperty ();
- OS.FrameworkElementFactory_SetValueVerticalAlignment (textNode, verticalAlignmentProperty, OS.VerticalAlignment_Center);
- OS.GCHandle_Free (verticalAlignmentProperty);
- int imageType = OS.Image_typeid ();
- int imageName = createDotNetString (IMAGE_PART_NAME, false);
- int imageNode = OS.gcnew_FrameworkElementFactory (imageType, imageName);
- OS.GCHandle_Free (imageName);
- OS.GCHandle_Free (imageType);
- int marginProperty = OS.FrameworkElement_MarginProperty ();
- int thickness = OS.gcnew_Thickness (0,0,4,0);
- OS.FrameworkElementFactory_SetValue (imageNode, marginProperty, thickness);
- OS.GCHandle_Free (marginProperty);
- OS.GCHandle_Free (thickness);
- int stretchProperty = OS.Image_StretchProperty ();
- OS.FrameworkElementFactory_SetValueStretch(imageNode, stretchProperty, OS.Stretch_None);
- OS.GCHandle_Free(stretchProperty);
- OS.FrameworkElementFactory_AppendChild (cellContentNode, imageNode);
- OS.GCHandle_Free (imageNode);
- OS.FrameworkElementFactory_AppendChild (cellContentNode, textNode);
- OS.GCHandle_Free (textNode);
- OS.FrameworkElementFactory_AppendChild (onRenderNode, cellContentNode);
- OS.GCHandle_Free (cellContentNode);
- OS.FrameworkTemplate_VisualTree (template, onRenderNode);
- OS.GCHandle_Free (onRenderNode);
- return template;
-}
-
-void createDefaultColumn () {
- int column = OS.gcnew_GridViewColumn ();
- int columnCollection = OS.GridView_Columns (gridViewHandle);
- int headerHandle = OS.gcnew_GridViewColumnHeader ();
- OS.GridViewColumn_Header (column, headerHandle);
- OS.GCHandle_Free (headerHandle);
- OS.GridViewColumnCollection_Insert (columnCollection, 0, column);
- int cellTemplate = createCellTemplate (0);
- OS.GridViewColumn_CellTemplate (column, cellTemplate);
- OS.GCHandle_Free (columnCollection);
- OS.GCHandle_Free (column);
- OS.GCHandle_Free (cellTemplate);
-}
-
-void createHandle () {
- parentingHandle = OS.gcnew_Canvas ();
- if (parentingHandle == 0) error (SWT.ERROR_NO_HANDLES);
- handle = OS.gcnew_ListView ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- gridViewHandle = OS.gcnew_GridView ();
- if (gridViewHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ListView_View (handle, gridViewHandle);
- if ((style & SWT.MULTI) == 0) OS.ListBox_SelectionMode (handle, OS.SelectionMode_Single);
- createDefaultColumn ();
- setHeaderVisible (false);
- OS.Selector_IsSynchronizedWithCurrentItem (handle, true);
- OS.GridView_AllowsColumnReorder (gridViewHandle, false);
- OS.Canvas_SetLeft (handle, 0);
- OS.Canvas_SetTop (handle, 0);
- int children = OS.Panel_Children (parentingHandle);
- OS.UIElementCollection_Add (children, handle);
- OS.GCHandle_Free (children);
-}
-
-int createHeaderTemplate (int columnJniRef) {
- int template = OS.gcnew_DataTemplate ();
- int stackPanelType = OS.StackPanel_typeid ();
- int stackPanelName = createDotNetString (CONTENTPANEL_PART_NAME, false);
- int stackPanelNode = OS.gcnew_FrameworkElementFactory (stackPanelType, stackPanelName);
- int textType = OS.TextBlock_typeid ();
- int textName = createDotNetString(TEXT_PART_NAME, false);
- int textNode = OS.gcnew_FrameworkElementFactory (textType, textName);
- int verticalAlignmentProperty = OS.FrameworkElement_VerticalAlignmentProperty ();
- OS.FrameworkElementFactory_SetValueVerticalAlignment (textNode, verticalAlignmentProperty, OS.VerticalAlignment_Center);
- int imageType = OS.Image_typeid ();
- int imageName = createDotNetString(IMAGE_PART_NAME, false);
- int imageNode = OS.gcnew_FrameworkElementFactory (imageType, imageName);
- int marginProperty = OS.FrameworkElement_MarginProperty ();
- int thickness = OS.gcnew_Thickness (0,0,4,0);
- OS.FrameworkElementFactory_SetValue (imageNode, marginProperty, thickness);
- int orientationProperty = OS.StackPanel_OrientationProperty ();
- OS.FrameworkElementFactory_SetValueOrientation (stackPanelNode, orientationProperty, OS.Orientation_Horizontal);
- OS.FrameworkElementFactory_AppendChild (stackPanelNode, imageNode);
- OS.FrameworkElementFactory_AppendChild (stackPanelNode, textNode);
- OS.FrameworkTemplate_VisualTree (template, stackPanelNode);
- OS.GCHandle_Free (stackPanelName);
- OS.GCHandle_Free (imageType);
- OS.GCHandle_Free (imageName);
- OS.GCHandle_Free (marginProperty);
- OS.GCHandle_Free (thickness);
- OS.GCHandle_Free (textType);
- OS.GCHandle_Free (textName);
- OS.GCHandle_Free (stackPanelType);
- OS.GCHandle_Free (stackPanelNode);
- OS.GCHandle_Free (textNode);
- OS.GCHandle_Free (imageNode);
- OS.GCHandle_Free (orientationProperty);
- OS.GCHandle_Free (verticalAlignmentProperty);
- return template;
-}
-
-void createItem (TableColumn column, int index) {
- if (index == -1) index = columnCount;
- if (!(0 <= index && index <= columnCount)) error (SWT.ERROR_INVALID_RANGE);
- column.createWidget ();
- int template = createHeaderTemplate (column.jniRef);
- OS.GridViewColumn_HeaderTemplate (column.handle, template);
- OS.GCHandle_Free (template);
- template = createCellTemplate (index);
- OS.GridViewColumn_CellTemplate (column.handle, template);
- OS.GCHandle_Free (template);
- int gvColumns = OS.GridView_Columns (gridViewHandle);
- if (columnCount == 0) OS.GridViewColumnCollection_Clear (gvColumns);
- OS.GridViewColumnCollection_Insert (gvColumns, index, column.handle);
- OS.GCHandle_Free (gvColumns);
- // When columnCount is 0, a "default column" is created in
- // the WPF control, therefore there is no need to manipulate
- // the item's array the first time a TableColumn is created
- // because the number of columns in the OS control is still one.
- if (columnCount != 0) {
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<itemCount; i++) {
- TableItem item = getItem (items, i, false);
- if (item != null) item.columnAdded (index);
- }
- OS.GCHandle_Free (items);
- }
- if (columns == null) columns = new TableColumn [4];
- if (columns.length == columnCount) {
- TableColumn [] newColumns = new TableColumn [columnCount + 4];
- System.arraycopy(columns, 0, newColumns, 0, columnCount);
- columns = newColumns;
- }
- columns [columnCount] = column;
- columnCount++;
-}
-
-void createItem (TableItem item, int index) {
- if (index == -1) index = itemCount;
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- item.createWidget ();
- int items = OS.ItemsControl_Items (handle);
- OS.ItemCollection_Insert (items, index, item.handle);
- int count = OS.ItemCollection_Count (items);
- OS.GCHandle_Free (items);
- if (itemCount == count) error (SWT.ERROR_ITEM_NOT_ADDED);
- itemCount++;
-}
-
-int defaultBackground () {
- return display.getSystemColor (SWT.COLOR_LIST_BACKGROUND).handle;
-}
-
-int defaultForeground () {
- return display.getSystemColor (SWT.COLOR_LIST_FOREGROUND).handle;
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (parentingHandle);
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. Indices that are out
- * of range and duplicate indices are ignored.
- *
- * @param indices the array of indices for the items to deselect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- int items = OS.ItemsControl_Items (handle);
- ignoreSelection = true;
- for (int i=0; i<indices.length; i++) {
- int index = indices [i];
- if (!(0 <= index && index < itemCount)) continue;
- int item = OS.ItemCollection_GetItemAt (items, index);
- OS.ListBoxItem_IsSelected (item, false);
- OS.GCHandle_Free (item);
- }
- ignoreSelection = false;
- OS.GCHandle_Free (items);
-}
-
-/**
- * Deselects the item at the given zero-relative index in the receiver.
- * If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) return;
- int items = OS.ItemsControl_Items (handle);
- int item = OS.ItemCollection_GetItemAt (items, index);
- ignoreSelection = true;
- OS.ListBoxItem_IsSelected (item, false);
- ignoreSelection = false;
- OS.GCHandle_Free (item);
- OS.GCHandle_Free (items);
-}
-
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. The range of the
- * indices is inclusive. Indices that are out of range are ignored.
- *
- * @param start the start index of the items to deselect
- * @param end the end index of the items to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselect (int start, int end) {
- checkWidget ();
- if (start <= 0 && end >= itemCount - 1) {
- deselectAll ();
- } else {
- start = Math.max (0, start);
- end = Math.min (end, itemCount - 1);
- int items = OS.ItemsControl_Items (handle);
- ignoreSelection = true;
- for (int i=start; i<=end; i++) {
- int item = OS.ItemCollection_GetItemAt (items, i);
- OS.ListBoxItem_IsSelected (item, false);
- OS.GCHandle_Free (item);
- }
- ignoreSelection = false;
- OS.GCHandle_Free (items);
- }
-}
-
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll () {
- checkWidget ();
- ignoreSelection = true;
- OS.ListBox_UnselectAll(handle);
- ignoreSelection = false;
-}
-
-void destroyItem (TableColumn column) {
- int gvColumns = OS.GridView_Columns (gridViewHandle);
- int index = OS.GridViewColumnCollection_IndexOf (gvColumns, column.handle);
- boolean removed = OS.GridViewColumnCollection_Remove (gvColumns, column.handle);
- OS.GCHandle_Free (gvColumns);
- if (!removed) error (SWT.ERROR_ITEM_NOT_REMOVED);
- int arrayIndex = -1;
- for (int i = 0; i < columnCount; i++) {
- TableColumn tc = columns [i];
- if (tc.equals(column)) {
- arrayIndex = i;
- break;
- }
- }
- columnCount--;
- columns [arrayIndex] = null;
- if (arrayIndex < columnCount) System.arraycopy (columns, arrayIndex+1, columns, arrayIndex, columnCount - arrayIndex);
- if (columnCount == 0) {
- createDefaultColumn ();
- }
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<itemCount; i++) {
- TableItem item = getItem (items, i, false);
- if (item != null) item.columnRemoved (index);
- }
- OS.GCHandle_Free (items);
-}
-
-void destroyItem (TableItem item) {
- int items = OS.ItemsControl_Items (handle);
- ignoreSelection = true;
- OS.ItemCollection_Remove (items, item.handle);
- ignoreSelection = false;
- int count = OS.ItemCollection_Count (items);
- OS.GCHandle_Free (items);
- if (itemCount == count) error (SWT.ERROR_ITEM_NOT_REMOVED);
- itemCount--;
-}
-
-int findPartByType (int source, int type) {
- if (OS.Type_IsInstanceOfType (type, source)) return source;
- int parent = OS.VisualTreeHelper_GetParent(source);
- if (parent == 0) return 0;
- int result = findPartByType(parent, type);
- if (result != parent) OS.GCHandle_Free(parent);
- return result;
-}
-
-/**
- * Returns the column at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- * Columns are returned in the order that they were created.
- * If no <code>TableColumn</code>s were created by the programmer,
- * this method will throw <code>ERROR_INVALID_RANGE</code> despite
- * the fact that a single column of data may be visible in the table.
- * This occurs when the programmer uses the table like a list, adding
- * items but never creating a column.
- *
- * @param index the index of the column to return
- * @return the column at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- */
-public TableColumn getColumn (int index) {
- checkWidget ();
- if (!(0 <= index && index < columnCount)) error (SWT.ERROR_INVALID_RANGE);
- return columns [index];
-}
-
-TableColumn getColumn (int columns, int index) {
- int gridColumn = OS.GridViewColumnCollection_default (columns, index);
- int header = OS.GridViewColumn_Header (gridColumn);
- TableColumn column = (TableColumn) display.getWidget (header);
- OS.GCHandle_Free (header);
- OS.GCHandle_Free (gridColumn);
- return column;
-}
-
-/**
- * Returns the number of columns contained in the receiver.
- * If no <code>TableColumn</code>s were created by the programmer,
- * this value is zero, despite the fact that visually, one column
- * of items may be visible. This occurs when the programmer uses
- * the table like a list, adding items but never creating a column.
- *
- * @return the number of columns
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getColumnCount () {
- checkWidget ();
- return columnCount;
-}
-
-/**
- * Returns an array of zero-relative integers that map
- * the creation order of the receiver's items to the
- * order in which they are currently being displayed.
- * <p>
- * Specifically, the indices of the returned array represent
- * the current visual order of the items, and the contents
- * of the array represent the creation order of the items.
- * </p><p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the current visual order of the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public int[] getColumnOrder () {
- checkWidget ();
- int [] order = new int [columnCount];
- for (int i=0; i<order.length; i++) order [i] = i;
- int gvColumns = OS.GridView_Columns (gridViewHandle);
- for (int i = 0; i < order.length; i++) {
- TableColumn column = columns [i];
- int index = OS.IList_IndexOf (gvColumns, column.handle);
- order [index] = i;
- }
- OS.GCHandle_Free (gvColumns);
- return order;
-}
-
-/**
- * Returns an array of <code>TableColumn</code>s which are the
- * columns in the receiver. Columns are returned in the order
- * that they were created. If no <code>TableColumn</code>s were
- * created by the programmer, the array is empty, despite the fact
- * that visually, one column of items may be visible. This occurs
- * when the programmer uses the table like a list, adding items but
- * never creating a column.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- */
-public TableColumn [] getColumns () {
- checkWidget ();
- TableColumn [] result = new TableColumn [columnCount];
- for (int i = 0; i < result.length; i++) {
- result [i] = columns [i];
- }
- return result;
-}
-
-/**
- * Returns the width in pixels of a grid line.
- *
- * @return the width of a grid line in pixels
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getGridLineWidth () {
- checkWidget ();
- return 0; //FIXME: No grid lines yet
-}
-
-/**
- * Returns the height of the receiver's header
- *
- * @return the height of the header or zero if the header is not visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public int getHeaderHeight () {
- checkWidget ();
- int columns = OS.GridView_Columns (gridViewHandle);
- int column = OS.GridViewColumnCollection_default (columns, 0);
- int height = 0;
- int header = OS.GridViewColumn_Header (column);
- if (header != 0) {
- height = (int) OS.FrameworkElement_ActualHeight (header);
- if (height == 0) {
- updateLayout (header);
- height = (int) OS.FrameworkElement_ActualHeight (header);
- }
- OS.GCHandle_Free (header);
- }
- OS.GCHandle_Free (column);
- OS.GCHandle_Free (columns);
- return height;
-}
-
-/**
- * Returns <code>true</code> if the receiver's header is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's header's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getHeaderVisible () {
- checkWidget ();
- int columns = OS.GridView_Columns (gridViewHandle);
- int column = OS.GridViewColumnCollection_default (columns, 0);
- int header = OS.GridViewColumn_Header (column);
- boolean visible = OS.UIElement_Visibility (header) == OS.Visibility_Visible;
- OS.GCHandle_Free (header);
- OS.GCHandle_Free (column);
- OS.GCHandle_Free (columns);
- return visible;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem getItem (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- int items = OS.ItemsControl_Items (handle);
- TableItem item = getItem (items, index, true);
- OS.GCHandle_Free (items);
- return item;
-}
-
-TableItem getItem (int items, int index, boolean create) {
- int item = OS.ItemCollection_GetItemAt (items, index);
- TableItem result = getItem (item, create);
- OS.GCHandle_Free (item);
- return result;
-}
-
-TableItem getItem (int item, boolean create) {
- int tag = OS.FrameworkElement_Tag (item);
- if (tag != 0) {
- int contentValue = OS.IntPtr_ToInt32 (tag);
- OS.GCHandle_Free (tag);
- return (TableItem) OS.JNIGetObject (contentValue);
- }
- if (create) {
- int itemHandle = OS.GCHandle_Alloc (item);
- return new TableItem (this, SWT.NONE, 0, itemHandle);
- }
- return null;
-}
-
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- * <p>
- * The item that is returned represents an item that could be selected by the user.
- * For example, if selection only occurs in items in the first column, then null is
- * returned if the point is outside of the item.
- * Note that the SWT.FULL_SELECTION style hint, which specifies the selection policy,
- * determines the extent of the selection.
- * </p>
- *
- * @param point the point used to locate the item
- * @return the item at the given point, or null if the point is not in a selectable item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem getItem (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- int pt = OS.gcnew_Point (point.x, point.y);
- int input = OS.UIElement_InputHitTest (handle, pt);
- OS.GCHandle_Free (pt);
- if (input == 0) return null;
- Widget widget = display.getWidget (input);
- OS.GCHandle_Free (input);
- if (widget instanceof TableItem) {
- return (TableItem) widget;
- }
- return null;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return itemCount;
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the receiver.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- //FIXME what is the default size?
- if (itemCount == 0) return 16;
- int items = OS.ItemsControl_Items (handle);
- int item = OS.ItemCollection_GetItemAt (items, 0);
- double height = OS.FrameworkElement_ActualHeight (item);
- OS.GCHandle_Free (item);
- OS.GCHandle_Free (items);
- return height != 0 ? (int) height : 16;
-}
-
-/**
- * Returns a (possibly empty) array of <code>TableItem</code>s which
- * are the items in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem [] getItems () {
- checkWidget ();
- TableItem [] result = new TableItem [itemCount];
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<itemCount; i++) {
- result [i] = getItem (items, i, true);
- }
- OS.GCHandle_Free (items);
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver's lines are visible,
- * and <code>false</code> otherwise. Note that some platforms draw
- * grid lines while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the visibility state of the lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getLinesVisible () {
- checkWidget ();
- //TODO
- return linesVisible;
-}
-
-/**
- * Returns an array of <code>TableItem</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem [] getSelection () {
- checkWidget ();
- int selected = OS.ListBox_SelectedItems (handle);
- int enumerator = OS.IList_GetEnumerator (selected);
- int count = OS.ICollection_Count (selected);
- TableItem [] result = new TableItem [count];
- int index = 0;
- while (OS.IEnumerator_MoveNext (enumerator)) {
- int item = OS.IEnumerator_Current (enumerator);
- result [index++] = getItem (item, true);
- OS.GCHandle_Free (item);
- }
- OS.GCHandle_Free (enumerator);
- OS.GCHandle_Free (selected);
- return result;
-}
-
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget ();
- int selected = OS.ListBox_SelectedItems (handle);
- int count = OS.ICollection_Count (selected);
- OS.GCHandle_Free (selected);
- return count;
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionIndex () {
- checkWidget ();
- return OS.Selector_SelectedIndex (handle);
-}
-
-/**
- * Returns the zero-relative indices of the items which are currently
- * selected in the receiver. The order of the indices is unspecified.
- * The array is empty if no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return the array of indices of the selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int [] getSelectionIndices () {
- checkWidget ();
- int items = OS.ItemsControl_Items (handle);
- int list = OS.ListBox_SelectedItems (handle);
- int enumerator = OS.IList_GetEnumerator (list);
- int count = OS.ICollection_Count (list);
- int [] indices = new int [count];
- int index = 0;
- while (OS.IEnumerator_MoveNext (enumerator)) {
- int item = OS.IEnumerator_Current (enumerator);
- indices [index++] = OS.ItemCollection_IndexOf (items, item);
- OS.GCHandle_Free (item);
- }
- OS.GCHandle_Free (enumerator);
- OS.GCHandle_Free (list);
- OS.GCHandle_Free (items);
- sortAscending (indices);
- return indices;
-}
-
-/**
- * Returns the column which shows the sort indicator for
- * the receiver. The value may be null if no column shows
- * the sort indicator.
- *
- * @return the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortColumn(TableColumn)
- *
- * @since 3.2
- */
-public TableColumn getSortColumn () {
- checkWidget ();
- //TODO
- return null;
-}
-
-/**
- * Returns the direction of the sort indicator for the receiver.
- * The value will be one of <code>UP</code>, <code>DOWN</code>
- * or <code>NONE</code>.
- *
- * @return the sort direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortDirection(int)
- *
- * @since 3.2
- */
-public int getSortDirection () {
- checkWidget ();
- //TODO
- return -1;
-}
-
-/**
- * Returns the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items are
- * scrolled or new items are added or removed.
- *
- * @return the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget ();
- int items = OS.ItemsControl_Items (handle);
- int item = OS.ItemCollection_GetItemAt (items, 0);
- OS.GCHandle_Free (items);
- int virtualizingStackPanel = OS.VisualTreeHelper_GetParent (item);
- OS.GCHandle_Free (item);
- int topIndex = 0;
- if (virtualizingStackPanel != 0) {
- topIndex = (int) OS.VirtualizingStackPanel_VerticalOffset (virtualizingStackPanel);
- OS.GCHandle_Free (virtualizingStackPanel);
- }
- return topIndex;
-}
-
-boolean hasItems () {
- return true;
-}
-
-void HandleChecked (int sender, int e) {
- if (!checkEvent (e)) return;
- if (ignoreSelection) return;
- int source = OS.RoutedEventArgs_Source (e);
- TableItem item = (TableItem) display.getWidget (source);
- OS.GCHandle_Free (source);
- if (item.grayed) {
- int checkbox = item.findPart (0, CHECKBOX_PART_NAME);
- if (checkbox != 0) {
- OS.ToggleButton_IsCheckedNullSetter (checkbox);
- OS.GCHandle_Free (checkbox);
- }
- }
- item.checked = true;
- Event event = new Event ();
- event.item = item;
- event.detail = SWT.CHECK;
- sendEvent (SWT.Selection, event);
-}
-
-void HandleIndeterminate (int sender, int e) {
- if (!checkEvent (e)) return;
- if (ignoreSelection) return;
- int source = OS.RoutedEventArgs_Source (e);
- TableItem item = (TableItem) display.getWidget (source);
- OS.GCHandle_Free (source);
- if (!item.grayed) {
- int checkbox = item.findPart (0, CHECKBOX_PART_NAME);
- if (checkbox != 0) {
- OS.ToggleButton_IsChecked (checkbox, false);
- OS.GCHandle_Free (checkbox);
- }
- }
-}
-
-void HandlePreviewKeyDown (int sender, int e) {
- super.HandlePreviewKeyDown (sender, e);
- if (!checkEvent (e)) return;
- int key = OS.KeyEventArgs_Key (e);
- if (key == OS.Key_Return) {
- int source = OS.RoutedEventArgs_OriginalSource (e);
- Widget widget = display.getWidget (source);
- OS.GCHandle_Free (source);
- if (widget instanceof TableItem) {
- Event event = new Event ();
- event.item = (TableItem)widget;
- postEvent (SWT.DefaultSelection, event);
- }
- }
-}
-
-void HandleMouseDoubleClick (int sender, int e) {
- if (!checkEvent (e)) return;
- int source = OS.RoutedEventArgs_OriginalSource (e);
- Widget widget = display.getWidget (source);
- OS.GCHandle_Free (source);
- if (widget instanceof TableItem) {
- Event event = new Event ();
- event.item = (TableItem)widget;
- postEvent (SWT.DefaultSelection, event);
- }
-}
-
-void HandleSelectionChanged (int sender, int e) {
- if (!checkEvent (e)) return;
- if (ignoreSelection) return;
- int item = 0;
- int list = OS.SelectionChangedEventArgs_AddedItems (e);
- if (list != 0) {
- int count = OS.ICollection_Count (list);
- if (count > 0) item = OS.IList_default (list, count - 1);
- }
- OS.GCHandle_Free (list);
- if (item == 0) {
- list = OS.SelectionChangedEventArgs_RemovedItems (e);
- int count = OS.ICollection_Count (list);
- if (count > 0) item = OS.IList_default (list, count - 1);
- OS.GCHandle_Free (list);
- }
- if (item != 0) {
- TableItem result = getItem (item, true);
- OS.GCHandle_Free (item);
- if (result != null) {
- Event event = new Event ();
- event.item = result;
- postEvent (SWT.Selection, event);
- }
- }
-}
-
-void HandleUnchecked (int sender, int e) {
- if (!checkEvent (e)) return;
- if (ignoreSelection) return;
- int source = OS.RoutedEventArgs_Source (e);
- TableItem item = (TableItem) display.getWidget (source);
- OS.GCHandle_Free (source);
- item.checked = false;
- Event event = new Event ();
- event.item = item;
- event.detail = SWT.CHECK;
- sendEvent (SWT.Selection, event);
-}
-
-void hookEvents () {
- super.hookEvents ();
- int handler = OS.gcnew_SelectionChangedEventHandler (jniRef, "HandleSelectionChanged");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.Selector_SelectionChanged (handle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_MouseButtonEventHandler (jniRef, "HandleMouseDoubleClick");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.Control_MouseDoubleClick (handle, handler);
- OS.GCHandle_Free (handler);
- if ((style & SWT.CHECK) != 0) {
- /* Item events */
- handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleChecked");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- int event = OS.ToggleButton_CheckedEvent ();
- OS.UIElement_AddHandler (handle, event, handler, false);
- OS.GCHandle_Free (event);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleUnchecked");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- event = OS.ToggleButton_UncheckedEvent ();
- OS.UIElement_AddHandler (handle, event, handler, false);
- OS.GCHandle_Free (event);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleIndeterminate");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- event = OS.ToggleButton_IndeterminateEvent ();
- OS.UIElement_AddHandler (handle, event, handler, false);
- OS.GCHandle_Free (event);
- OS.GCHandle_Free (handler);
- }
-}
-
-/**
- * Searches the receiver's list starting at the first column
- * (index 0) until a column is found that is equal to the
- * argument, and returns the index of that column. If no column
- * is found, returns -1.
- *
- * @param column the search column
- * @return the index of the column
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the column is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (TableColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- int columns = OS.GridView_Columns (gridViewHandle);
- int index = OS.GridViewColumnCollection_IndexOf (columns, column.handle);
- OS.GCHandle_Free (columns);
- return index;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (TableItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- int items = OS.ItemsControl_Items(handle);
- int index = OS.ItemCollection_IndexOf(items, item.handle);
- OS.GCHandle_Free (items);
- return index;
-}
-
-/**
- * Returns <code>true</code> if the item is selected,
- * and <code>false</code> otherwise. Indices out of
- * range are ignored.
- *
- * @param index the index of the item
- * @return the selection state of the item at the index
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isSelected (int index) {
- checkWidget ();
- int items = OS.ItemsControl_Items (handle);
- int item = OS.ItemCollection_GetItemAt (items, index);
- boolean result = OS.ListBoxItem_IsSelected (item);
- OS.GCHandle_Free (item);
- OS.GCHandle_Free (items);
- return result;
-}
-
-void OnRender (int source, int dc) {
- if (isDisposed ()) return;
- int type = OS.ListViewItem_typeid();
- int itemHandle = findPartByType (source, type);
- OS.GCHandle_Free (type);
- TableItem item = getItem (itemHandle, true);
- OS.GCHandle_Free (itemHandle);
- if ((item.cached || (style & SWT.VIRTUAL) == 0) && item.rowHandle != 0) return;
- checkData (item);
- if (item.rowHandle == 0) {
- int rowPresenterType = OS.GridViewRowPresenter_typeid ();
- item.rowHandle = item.findRowPresenter (item.handle, rowPresenterType);
- OS.GCHandle_Free (rowPresenterType);
- }
- int columns = columnCount == 0 ? 1 : columnCount;
- item.updateCheck ();
- for (int i=0; i<columns; i++) {
- item.updateText (i);
- item.updateImage (i);
- item.updateBackground (i);
- item.updateForeground (i);
- item.updateFont (i);
- }
-}
-
-int parentingHandle () {
- return parentingHandle;
-}
-
-void register() {
- super.register();
- display.addWidget (parentingHandle, this);
-}
-
-void releaseChildren (boolean destroy) {
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<itemCount; i++) {
- TableItem item = getItem (items, i, false);
- if (item != null && !item.isDisposed ()) item.release (false);
- }
- OS.GCHandle_Free (items);
- int columns = OS.GridView_Columns (gridViewHandle);
- for (int i=0; i<columnCount; i++) {
- TableColumn column = getColumn(columns, i);
- if (!column.isDisposed ()) column.release (false);
- }
- OS.GCHandle_Free (columns);
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- OS.GCHandle_Free (gridViewHandle);
- gridViewHandle = 0;
- OS.GCHandle_Free (parentingHandle);
- parentingHandle = 0;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- columns = null;
-}
-
-/**
- * Removes the items from the receiver's list at the given
- * zero-relative indices.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 0) return;
- int [] newIndices = new int [indices.length];
- System.arraycopy (indices, 0, newIndices, 0, indices.length);
- sort (newIndices);
- int start = newIndices [newIndices.length - 1], end = newIndices [0];
- if (!(0 <= start && start <= end && end < itemCount)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int items = OS.ItemsControl_Items (handle);
- ignoreSelection = true;
- int lastIndex = -1;
- for (int i = newIndices.length-1; i >= 0; i--) {
- int index = newIndices [i];
- if (index != lastIndex) {
- TableItem item = getItem (items, index, false);
- if (item != null && !item.isDisposed ()) item.release (false);
- OS.ItemCollection_RemoveAt (items, index);
- lastIndex = index;
- }
- }
- ignoreSelection = false;
- itemCount = OS.ItemCollection_Count (items);
- OS.GCHandle_Free (items);
-}
-
-/**
- * Removes the item from the receiver at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- int items = OS.ItemsControl_Items (handle);
- TableItem item = getItem (items, index, false);
- if (item != null && !item.isDisposed ()) item.release (false);
- ignoreSelection = true;
- OS.ItemCollection_RemoveAt (items, index);
- ignoreSelection = false;
- itemCount = OS.ItemCollection_Count (items);
- OS.GCHandle_Free (items);
-}
-
-/**
- * Removes the items from the receiver which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget ();
- if (start > end) return;
- if (!(0 <= start && start <= end && end < itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (start == 0 && end == itemCount - 1) {
- removeAll ();
- return;
- }
- int items = OS.ItemsControl_Items (handle);
- ignoreSelection = true;
- for (int i = end; i >= start; i--) {
- TableItem item = getItem (items, i, false);
- if (item != null && !item.isDisposed ()) item.release (false);
- OS.ItemCollection_RemoveAt (items, i);
- }
- ignoreSelection = false;
- itemCount = OS.ItemCollection_Count (items);
- OS.GCHandle_Free (items);
-}
-
-/**
- * Removes all of the items from the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget ();
- int items = OS.ItemsControl_Items (handle);
- for (int i = 0; i < itemCount; i++) {
- TableItem item = getItem (items, i, false);
- if (item != null && !item.isDisposed ()) item.release (false);
- }
-
- ignoreSelection = true;
- OS.ItemCollection_Clear (items);
- ignoreSelection = false;
- itemCount = OS.ItemCollection_Count (items);
- OS.GCHandle_Free (items);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener(SelectionListener)
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If the item at a given index is not selected, it is selected.
- * If the item at a given index was already selected, it remains selected.
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- * </p>
- *
- * @param indices the array of indices for the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setSelection(int[])
- */
-public void select (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- ignoreSelection = true;
- int items = OS.ItemsControl_Items (handle);
- for (int i = 0; i < indices.length; i++) {
- if (!(0 <= indices[i] && indices[i] < itemCount)) continue;
- int item = OS.ItemCollection_GetItemAt (items, indices[i]);
- OS.ListBoxItem_IsSelected (item, true);
- OS.GCHandle_Free (item);
- }
- OS.GCHandle_Free (items);
- ignoreSelection = false;
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains
- * selected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void select (int index) {
- checkWidget ();
- if (!(0 <= index && index < itemCount)) return;
- int items = OS.ItemsControl_Items (handle);
- int item = OS.ItemCollection_GetItemAt (items, index);
- ignoreSelection = true;
- OS.ListBoxItem_IsSelected (item, true);
- ignoreSelection = false;
- OS.GCHandle_Free (item);
- OS.GCHandle_Free (items);
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is not cleared before the new items are selected.
- * <p>
- * If an item in the given range is not selected, it is selected.
- * If an item in the given range was already selected, it remains selected.
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setSelection(int,int)
- */
-public void select (int start, int end) {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0 && start != end) return;
- if (start <= 0 && end >= itemCount - 1) {
- selectAll ();
- } else {
- start = Math.max (0, start);
- end = Math.min (end, itemCount - 1);
- int items = OS.ItemsControl_Items (handle);
- ignoreSelection = true;
- for (int i=start; i<=end; i++) {
- int item = OS.ItemCollection_GetItemAt (items, i);
- OS.ListBoxItem_IsSelected (item, true);
- OS.GCHandle_Free (item);
- }
- ignoreSelection = false;
- OS.GCHandle_Free (items);
- }
-}
-
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- ignoreSelection = true;
- OS.ListBox_SelectAll (handle);
- ignoreSelection = false;
-}
-
-void setBackgroundBrush(int brush) {
- if (brush != 0) {
- OS.Control_Background (handle, brush);
- } else {
- int property = OS.Control_BackgroundProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
-}
-
-int setBounds (int x, int y, int width, int height, int flags) {
- int result = super.setBounds (x, y, width, height, flags);
- if ((result & RESIZED) != 0) {
- if (columnCount == 0) {
- int columns = OS.GridView_Columns (gridViewHandle);
- int column = OS.GridViewColumnCollection_default (columns, 0);
- OS.GridViewColumn_Width (column, width);
- OS.GCHandle_Free (column);
- OS.GCHandle_Free (columns);
- }
- OS.FrameworkElement_Width (handle, width);
- OS.FrameworkElement_Height (handle, height);
- }
- return result;
-}
-
-/**
- * Sets the order that the items in the receiver should
- * be displayed in to the given argument which is described
- * in terms of the zero-relative ordering of when the items
- * were added.
- *
- * @param order the new order to display the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item order is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see TableColumn#getMoveable()
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public void setColumnOrder (int [] order) {
- checkWidget ();
- if (order == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (order.length != columnCount) error (SWT.ERROR_INVALID_ARGUMENT);
- int [] oldOrder = getColumnOrder ();
- boolean reorder = false;
- boolean [] seen = new boolean [columnCount];
- for (int i=0; i<order.length; i++) {
- int index = order [i];
- if (index < 0 || index >= columnCount) error (SWT.ERROR_INVALID_ARGUMENT);
- if (seen [index]) error (SWT.ERROR_INVALID_ARGUMENT);
- seen [index] = true;
- if (order [i] != oldOrder [i]) reorder = true;
- }
- if (!reorder) return;
- int gvColumns = OS.GridView_Columns (gridViewHandle);
- for (int i = 0; i < order.length; i++) {
- TableColumn column = columns [order [i]];
- int index = OS.IList_IndexOf (gvColumns, column.handle);
- if (index != i) OS.ObservableCollectionGridViewColumn_Move (gvColumns, index, i);
- }
- OS.GCHandle_Free (gvColumns);
-}
-
-void setFont (int font, double size) {
- if (font != 0) {
- int fontFamily = OS.Typeface_FontFamily( font);
- int style = OS.Typeface_Style (font);
- int weight = OS.Typeface_Weight (font);
- int stretch = OS.Typeface_Stretch (font);
- OS.Control_FontFamily (handle, fontFamily);
- OS.Control_FontStyle (handle, style);
- OS.Control_FontWeight (handle, weight);
- OS.Control_FontStretch (handle, stretch);
- OS.Control_FontSize (handle, size);
- OS.GCHandle_Free (fontFamily);
- OS.GCHandle_Free (style);
- OS.GCHandle_Free (weight);
- OS.GCHandle_Free (stretch);
- } else {
- int property = OS.Control_FontFamilyProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.Control_FontStyleProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.Control_FontWeightProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.Control_FontStretchProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.Control_FontSizeProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
-}
-
-void setForegroundBrush (int brush) {
- if (brush != 0) {
- OS.Control_Foreground (handle, brush);
- } else {
- int property = OS.Control_ForegroundProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
-}
-
-/**
- * Marks the receiver's header as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHeaderVisible (boolean show) {
- checkWidget ();
- int style = 0;
- if (!show) {
- style = OS.gcnew_Style ();
- int dp = OS.UIElement_VisibilityProperty ();
- int setter = OS.gcnew_SetterVisibility (dp, OS.Visibility_Collapsed);
- int collection = OS.Style_Setters (style);
- OS.SetterBaseCollection_Add (collection, setter);
- OS.GCHandle_Free (collection);
- OS.GCHandle_Free (setter);
- OS.GCHandle_Free (dp);
- }
- OS.GridView_ColumnHeaderContainerStyle (gridViewHandle, style);
- if (style != 0) OS.GCHandle_Free (style);
- for (int i=0; i<columnCount; i++) {
- TableColumn column = getColumn (i);
- column.updateImage ();
- column.updateText ();
- }
-}
-
-/**
- * Sets the number of items contained in the receiver.
- *
- * @param count the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setItemCount (int count) {
- checkWidget ();
- count = Math.max (0, count);
- if (count == itemCount) return;
- int index = itemCount - 1;
- int items = OS.ItemsControl_Items (handle);
- while (index >= count) {
- TableItem item = getItem (items, index, false);
- if (item != null) {
- if (!item.isDisposed()) item.release (true);
- } else {
- OS.ItemCollection_RemoveAt (items, index);
- }
- index--;
- }
- if (OS.ItemCollection_Count (items) > count) error (SWT.ERROR_ITEM_NOT_REMOVED);
- if ((style & SWT.VIRTUAL) != 0) {
- for (int i=itemCount; i<count; i++) {
- int item = OS.gcnew_ListViewItem ();
- if (item == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ItemCollection_Add (items, item);
- OS.GCHandle_Free (item);
- }
- } else {
- for (int i=itemCount; i<count; i++) {
- new TableItem (this, SWT.NONE, i);
- }
- }
- itemCount = OS.ItemCollection_Count (items);
- OS.GCHandle_Free (items);
- if (itemCount != count) error (SWT.ERROR_ITEM_NOT_ADDED);
-}
-
-/**
- * Sets the height of the area which would be used to
- * display <em>one</em> of the items in the table.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-/*public*/ void setItemHeight (int itemHeight) {
- checkWidget ();
-}
-
-/**
- * Marks the receiver's lines as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise. Note that some platforms draw grid lines
- * while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setLinesVisible (boolean show) {
- checkWidget ();
- linesVisible = show;
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range and duplicate indices are ignored.
- * If the receiver is single-select and multiple indices are specified,
- * then all indices are ignored.
- * </p>
- *
- * @param indices the indices of the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int[])
- */
-public void setSelection (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = indices.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- select (indices);
- //TODO
-// int focusIndex = indices [0];
-// if (focusIndex != -1) setFocusIndex (focusIndex);
- showSelection ();
-}
-
-/**
- * Sets the receiver's selection to the given item.
- * The current selection is cleared before the new item is selected.
- * <p>
- * If the item is not in the receiver, then it is ignored.
- * </p>
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection (TableItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (new TableItem [] {item});
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- * </p>
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the items has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int[])
- * @see Table#setSelection(int[])
- */
-public void setSelection (TableItem [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = items.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return;
- for (int i=0; i<length; i++) {
- int index = indexOf (items [i]);
- if (index != -1) {
- select (index);
- }
- }
- //TODO
-// if (focusIndex != -1) setFocusIndex (focusIndex);
- showSelection ();
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * The current selection is first cleared, then the new item is selected.
- *
- * @param index the index of the item to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int)
- */
-public void setSelection (int index) {
- checkWidget ();
- deselectAll ();
- select (index);
- //TODO
-// if (index != -1) setFocusIndex (index);
- showSelection ();
-}
-
-/**
- * Selects the items in the range specified by the given zero-relative
- * indices in the receiver. The range of indices is inclusive.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- * If the receiver is single-select and there is more than one item in the
- * given range, then all indices are ignored.
- * </p>
- *
- * @param start the start index of the items to select
- * @param end the end index of the items to select
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#deselectAll()
- * @see Table#select(int,int)
- */
-public void setSelection (int start, int end) {
- checkWidget ();
- deselectAll ();
- if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return;
- if (itemCount == 0 || start >= itemCount) return;
- start = Math.max (0, start);
- end = Math.min (end, itemCount - 1);
- select (start, end);
- //TODO
-// setFocusIndex (start);
- showSelection ();
-}
-
-/**
- * Sets the column used by the sort indicator for the receiver. A null
- * value will clear the sort indicator. The current sort column is cleared
- * before the new column is set.
- *
- * @param column the column used by the sort indicator or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the column is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortColumn (TableColumn column) {
- checkWidget ();
- if (column != null && column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- //TODO
-// if (sortColumn != null && !sortColumn.isDisposed ()) {
-// sortColumn.setSortDirection (SWT.NONE);
-// }
-// sortColumn = column;
-// if (sortColumn != null && sortDirection != SWT.NONE) {
-// sortColumn.setSortDirection (sortDirection);
-// }
-}
-
-/**
- * Sets the direction of the sort indicator for the receiver. The value
- * can be one of <code>UP</code>, <code>DOWN</code> or <code>NONE</code>.
- *
- * @param direction the direction of the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortDirection (int direction) {
- checkWidget ();
- if ((direction & (SWT.UP | SWT.DOWN)) == 0 && direction != SWT.NONE) return;
- //TODO
-// sortDirection = direction;
-// if (sortColumn != null && !sortColumn.isDisposed ()) {
-// sortColumn.setSortDirection (direction);
-// }
-}
-
-/**
- * Sets the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items
- * are scrolled or new items are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget ();
- //TODO
-}
-
-/**
- * Shows the column. If the column is already showing in the receiver,
- * this method simply returns. Otherwise, the columns are scrolled until
- * the column is visible.
- *
- * @param column the column to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the column is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the column has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void showColumn (TableColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (column.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (column.parent != this) return;
- int index = indexOf (column);
- if (!(0 <= index && index < columnCount)) return;
- //TODO
-}
-
-/**
- * Shows the item. If the item is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the item is visible.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#showSelection()
- */
-public void showItem (TableItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- OS.ListBox_ScrollIntoView (handle, item.handle);
-}
-
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#showItem(TableItem)
- */
-public void showSelection () {
- checkWidget ();
- int itemCollection = OS.ItemsControl_Items (handle);
- int list = OS.ListBox_SelectedItems (handle);
- int enumerator = OS.IList_GetEnumerator (list);
- if (OS.IEnumerator_MoveNext (enumerator)) {
- int item = OS.IEnumerator_Current (enumerator);
- OS.ListBox_ScrollIntoView (handle, item);
- OS.GCHandle_Free (item);
- }
- OS.GCHandle_Free (enumerator);
- OS.GCHandle_Free (list);
- OS.GCHandle_Free (itemCollection);
-}
-
-int topHandle () {
- return parentingHandle;
-}
-
-void updateMoveable () {
- int columns = OS.GridView_Columns (gridViewHandle);
- boolean moveable = true;
- for (int i = 0; moveable && i < columnCount; i++) {
- TableColumn column = getColumn (columns, i);
- if (!column.moveable) moveable = false;
- }
- OS.GCHandle_Free (columns);
- OS.GridView_AllowsColumnReorder (gridViewHandle, moveable);
-}
-
-} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TableColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TableColumn.java
deleted file mode 100644
index dd5fdd3ba5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TableColumn.java
+++ /dev/null
@@ -1,644 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a column in a table widget.
- * <p><dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd> Move, Resize, Selection</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT and CENTER may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TableColumn extends Item {
- static final int IMAGE_PART = 0;
- static final int TEXT_PART = 1;
- int headerHandle, stringHandle;
- boolean moveable, resizable;
- Table parent;
-
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableColumn (Table parent, int style) {
- super (parent, checkStyle (style));
- resizable = true;
- this.parent = parent;
- parent.createItem (this, parent.getColumnCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableColumn (Table parent, int style, int index) {
- super (parent, checkStyle (style));
- resizable = true;
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize,typedListener);
- addListener (SWT.Move,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the column header is selected.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createHandle () {
- handle = OS.gcnew_GridViewColumn ();
- if (handle == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- headerHandle = OS.gcnew_GridViewColumnHeader ();
- OS.GridViewColumn_Header (handle, headerHandle);
-}
-
-void deregister () {
- display.removeWidget (headerHandle);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-int findPart (String part) {
- updateLayout (headerHandle);
- int headerTemplate = OS.Control_Template (headerHandle);
- int name = createDotNetString ("HeaderContent", false);
- int contentPresenter = OS.FrameworkTemplate_FindName (headerTemplate, name, headerHandle);
- OS.GCHandle_Free (name);
- OS.GCHandle_Free (headerTemplate);
- if (contentPresenter == 0) return 0;
- int dataTemplate = OS.GridViewColumn_HeaderTemplate (handle);
- name = createDotNetString (part, false);
- int result = OS.FrameworkTemplate_FindName (dataTemplate, name, contentPresenter);
- OS.GCHandle_Free (contentPresenter);
- OS.GCHandle_Free (dataTemplate);
- OS.GCHandle_Free (name);
- return result;
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget ();
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Table</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Table getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Gets the moveable attribute. A column that is
- * not moveable cannot be reordered by the user
- * by dragging the header but may be reordered
- * by the programmer.
- *
- * @return the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#getColumnOrder()
- * @see Table#setColumnOrder(int[])
- * @see TableColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public boolean getMoveable () {
- checkWidget ();
- return moveable;
-}
-
-/**
- * Gets the resizable attribute. A column that is
- * not resizable cannot be dragged by the user but
- * may be resized by the programmer.
- *
- * @return the resizable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getResizable () {
- checkWidget ();
- return resizable;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public String getToolTipText () {
- checkWidget ();
- int strPtr = OS.FrameworkElement_ToolTip (headerHandle);
- String string = createJavaString (strPtr);
- OS.GCHandle_Free (strPtr);
- return string;
-}
-
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget ();
- return (int) OS.GridViewColumn_ActualWidth (handle);
-}
-
-void HandleClick (int sender, int e) {
- if (!checkEvent (e)) return;
- postEvent (SWT.Selection);
-}
-
-void HandleLoaded (int sender, int e) {
- if (isDisposed ()) return;
- updateImage ();
- updateText ();
-}
-
-void HandleMouseDoubleClick (int sender, int e) {
- if (!checkEvent (e)) return;
- postEvent (SWT.DefaultSelection);
-}
-
-void HandleSizeChanged (int sender, int e) {
- if (!checkEvent(e)) return;
- sendEvent (SWT.Resize);
-}
-
-void hookEvents() {
- super.hookEvents ();
- int handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleLoaded");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.FrameworkElement_Loaded (headerHandle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleClick");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- int event = OS.ButtonBase_ClickEvent ();
- OS.UIElement_AddHandler (headerHandle, event, handler, false);
- OS.GCHandle_Free (event);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleMouseDoubleClick");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- event = OS.Control_MouseDoubleClickEvent ();
- OS.UIElement_AddHandler (headerHandle, event, handler, false);
- OS.GCHandle_Free (event);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleSizeChanged");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- event = OS.FrameworkElement_SizeChangedEvent ();
- OS.UIElement_AddHandler (headerHandle, event, handler, false);
- OS.GCHandle_Free (event);
- OS.GCHandle_Free (handler);
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void pack () {
- checkWidget ();
- updateLayout (parent.handle);
- double width = 0;
- if (headerHandle != 0) {
- int size = OS.UIElement_DesiredSize (headerHandle);
- width = OS.Size_Width (size);
- OS.GCHandle_Free (size);
- }
- int columnIndex = parent.indexOf (this);
- int items = OS.ItemsControl_Items (parent.handle);
- for (int i=0; i<parent.itemCount; i++) {
- TableItem item = parent.getItem (items, i, false);
- if (item != null) {
- width = Math.max (width, item.computeWidth (columnIndex));
- }
- }
- OS.GCHandle_Free (items);
- OS.GridViewColumn_Width (handle, width);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (handle != 0) OS.GCHandle_Free (handle);
- handle = 0;
- OS.GCHandle_Free (headerHandle);
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (stringHandle != 0) OS.GCHandle_Free (stringHandle);
- stringHandle = 0;
-}
-
-void register() {
- display.addWidget (headerHandle, this);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>.
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget ();
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- int index = parent.indexOf (this);
- if (index == -1 || index == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- //TODO
-}
-
-public void setImage (Image image) {
- checkWidget ();
- super.setImage (image);
- updateImage ();
-}
-
-/**
- * Sets the moveable attribute. A column that is
- * moveable can be reordered by the user by dragging
- * the header. A column that is not moveable cannot be
- * dragged by the user but may be reordered
- * by the programmer.
- *
- * @param moveable the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Table#setColumnOrder(int[])
- * @see Table#getColumnOrder()
- * @see TableColumn#getMoveable()
- * @see SWT#Move
- *
- * @since 3.1
- */
-public void setMoveable (boolean moveable) {
- checkWidget ();
- this.moveable = moveable;
- parent.updateMoveable ();
-}
-
-/**
- * Sets the resizable attribute. A column that is
- * resizable can be resized by the user dragging the
- * edge of the header. A column that is not resizable
- * cannot be dragged by the user but may be resized
- * by the programmer.
- *
- * @param resizable the resize attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setResizable (boolean resizable) {
- checkWidget ();
- this.resizable = resizable;
-}
-
-void setSortDirection (int direction) {
- //TODO
-}
-
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (string.equals (text)) return;
- text = string;
- updateText ();
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setToolTipText (String string) {
- checkWidget ();
- if (string != null && string.length() == 0) string = null;
- int strPtr = createDotNetString (string, false);
- OS.FrameworkElement_ToolTip (headerHandle, strPtr);
- OS.GCHandle_Free (strPtr);
-}
-
-/**
- * Sets the width of the receiver.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int width) {
- checkWidget ();
- if (width < 0) return;
- updateLayout (parent.handle);
- OS.GridViewColumn_Width (handle, width);
-}
-
-void updateImage() {
- int part = findPart (Table.IMAGE_PART_NAME);
- if (part == 0) return;
- OS.Image_Source (part, image == null ? 0 : image.handle);
- OS.GCHandle_Free (part);
-}
-
-void updateText () {
- int part = findPart (Table.TEXT_PART_NAME);
- if (part == 0) return;
- int str = createDotNetString (text, false);
- OS.TextBlock_Text (part, str);
- OS.GCHandle_Free (str);
- OS.GCHandle_Free (part);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TableItem.java
deleted file mode 100644
index 6e4946d3bc..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TableItem.java
+++ /dev/null
@@ -1,1208 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents an item in a table.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class TableItem extends Item {
- Table parent;
- Image [] images;
- String [] strings;
- Color [] cellBackground, cellForeground;
- Font [] cellFont;
- int rowHandle;
- boolean checked, grayed, cached;
- Color background, foreground;
- Font font;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableItem (Table parent, int style) {
- this (parent, style, -1);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TableItem (Table parent, int style, int index) {
- this (parent, style, index, 0);
-}
-
-TableItem (Table parent, int style, int index, int handle) {
- super (parent, style);
- this.parent = parent;
- this.handle = handle;
- if (handle == 0) {
- parent.createItem (this, index);
- } else {
- createWidget ();
- }
-}
-
-double computeWidth (int columnIndex) {
- int rowPresenterType = OS.GridViewRowPresenter_typeid ();
- double width = 0;
- if (rowHandle != 0) {
- int contentPresenter = OS.VisualTreeHelper_GetChild (rowHandle, columnIndex);
- int availSize = OS.gcnew_Size (0x7FFFFFFF,0x7FFFFFFF);
- OS.UIElement_Measure (contentPresenter, availSize);
- OS.GCHandle_Free (availSize);
- int size = OS.UIElement_DesiredSize (contentPresenter);
- width = OS.Size_Width (size);
- OS.GCHandle_Free (size);
- OS.GCHandle_Free (contentPresenter);
- }
- OS.GCHandle_Free (rowPresenterType);
- return width;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void columnAdded (int index) {
- int newLength = parent.columnCount + 1;
- if (strings != null) {
- String [] temp = new String [newLength];
- System.arraycopy (strings, 0, temp, 0, index);
- System.arraycopy (strings, index, temp, index + 1, parent.columnCount - index);
- strings = temp;
- }
- if (images != null) {
- Image [] temp = new Image [newLength];
- System.arraycopy (images, 0, temp, 0, index);
- System.arraycopy (images, index, temp, index + 1, parent.columnCount - index);
- images = temp;
- }
- if (cellBackground != null) {
- Color [] temp = new Color [newLength];
- System.arraycopy (cellBackground, 0, temp, 0, index);
- System.arraycopy (cellBackground, index, temp, index + 1, parent.columnCount - index);
- cellBackground = temp;
- }
- if (cellForeground != null) {
- Color [] temp = new Color [newLength];
- System.arraycopy (cellForeground, 0, temp, 0, index);
- System.arraycopy (cellForeground, index, temp, index + 1, parent.columnCount - index);
- cellForeground = temp;
- }
- if (cellFont != null) {
- Font [] temp = new Font [newLength];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index, temp, index + 1, parent.columnCount - index);
- cellFont = temp;
- }
-}
-
-void columnRemoved (int index) {
- if (strings != null) {
- String [] temp = new String [parent.columnCount];
- System.arraycopy (strings, 0, temp, 0, index);
- System.arraycopy (strings, index + 1, temp, index, parent.columnCount - index);
- strings = temp;
- }
- if (images != null) {
- Image [] temp = new Image [parent.columnCount];
- System.arraycopy (images, 0, temp, 0, index);
- System.arraycopy (images, index + 1, temp, index, parent.columnCount - index);
- images = temp;
- }
- if (cellBackground != null) {
- Color [] temp = new Color [parent.columnCount];
- System.arraycopy (cellBackground, 0, temp, 0, index);
- System.arraycopy (cellBackground, index + 1, temp, index, parent.columnCount - index);
- cellBackground = temp;
- }
- if (cellForeground != null) {
- Color [] temp = new Color [parent.columnCount];
- System.arraycopy (cellForeground, 0, temp, 0, index);
- System.arraycopy (cellForeground, index + 1, temp, index, parent.columnCount - index);
- cellForeground = temp;
- }
- if (cellFont != null) {
- Font [] temp = new Font [parent.columnCount];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index + 1, temp, index, parent.columnCount - index);
- cellFont = temp;
- }
-}
-
-void createHandle () {
- if (handle == 0) {
- handle = OS.gcnew_ListViewItem ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- }
- OS.Control_HorizontalContentAlignment (handle, OS.HorizontalAlignment_Stretch);
- OS.Control_VerticalContentAlignment (handle, OS.VerticalAlignment_Stretch);
-}
-
-void clear () {
- strings = null;
- images = null;
- checked = grayed = false;
- setFont (null);
- setForeground (null);
- setBackground (null);
- if ((parent.style & SWT.VIRTUAL) != 0) cached = false;
- updateCheck ();
- int columns = parent.columnCount == 0 ? 1 : parent.columnCount;
- for (int i = 0; i < columns; i++) {
- updateText (i);
- updateImage (i);
- updateBackground (i);
- updateForeground (i);
- updateFont (i);
- }
- if ((parent.style & SWT.VIRTUAL) != 0) cached = false;
- int part = findPart (0, Table.RENDER_PANEL_NAME);
- if (part != 0) OS.UIElement_InvalidateVisual (part);
- OS.GCHandle_Free (part);
-}
-
-void deregister () {
- display.removeWidget (handle);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-int findRowPresenter (int current, int rowPresenterType) {
- int type = OS.Object_GetType (current);
- boolean found = OS.Object_Equals (rowPresenterType, type);
- OS.GCHandle_Free (type);
- if (found) return current;
- int childCount = OS.VisualTreeHelper_GetChildrenCount (current);
- for (int i = 0; i < childCount; i++) {
- int child = OS.VisualTreeHelper_GetChild (current, i);
- int result = findRowPresenter (child, rowPresenterType);
- if (child != result) OS.GCHandle_Free (child);
- if (result != 0) return result;
- }
- return 0;
-}
-
-int findPart (int column, String partName) {
- if (rowHandle == 0) return 0; //not Loaded yet.
- updateLayout (rowHandle);
- int contentPresenter = OS.VisualTreeHelper_GetChild (rowHandle, column);
- if (contentPresenter == 0) return 0;
- int columnHandle;
- if (parent.columnCount == 0) {
- int columns = OS.GridView_Columns (parent.gridViewHandle);
- columnHandle = OS.GridViewColumnCollection_default (columns, column);
- OS.GCHandle_Free (columns);
- } else {
- columnHandle = parent.columns [column].handle;
- }
- int cellTemplate = OS.GridViewColumn_CellTemplate (columnHandle);
- int name = createDotNetString (partName, false);
- int result = OS.FrameworkTemplate_FindName (cellTemplate, name, contentPresenter);
- OS.GCHandle_Free (contentPresenter);
- if (parent.columnCount == 0) OS.GCHandle_Free (columnHandle);
- OS.GCHandle_Free (cellTemplate);
- OS.GCHandle_Free (name);
- return result;
-}
-
-/**
- * Returns the receiver's background color.
- *
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public Color getBackground () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return background != null ? background : parent.getBackground ();
-}
-
-/**
- * Returns the background color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Color getBackground (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count -1) return getBackground ();
- if (cellBackground == null || cellBackground [index] == null) return getBackground ();
- return cellBackground [index];
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Rectangle getBounds () {
- checkWidget();
- return getTextBounds (0);
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent at a column in the table.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding column rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds (int index) {
- checkWidget();
- if (index != 0 && !parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (!(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0);
- int rowPresenterType = OS.GridViewRowPresenter_typeid ();
- int contentPresenter = OS.VisualTreeHelper_GetChild (rowHandle, index);
- int point = OS.gcnew_Point (0, 0);
- if (point == 0) error (SWT.ERROR_NO_HANDLES);
- int parentHandle = parent.topHandle ();
- int location = OS.UIElement_TranslatePoint (contentPresenter, point, parentHandle);
- int x = (int) OS.Point_X (location);
- int y = (int) OS.Point_Y (location);
- int width = (int) OS.FrameworkElement_ActualWidth (contentPresenter);
- int height = (int) OS.FrameworkElement_ActualHeight (handle);
- OS.GCHandle_Free (rowPresenterType);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (location);
- OS.GCHandle_Free (contentPresenter);
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is checked,
- * and false otherwise. When the parent does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the checked state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getChecked () {
- checkWidget();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return checked;
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information for this item.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return font != null ? font : parent.getFont ();
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information
- * for the specified cell in this item.
- *
- * @param index the column index
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count -1) return getFont ();
- if (cellFont == null || cellFont [index] == null) return getFont ();
- return cellFont [index];
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public Color getForeground () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return foreground != null ? foreground : parent.getForeground ();
-}
-
-/**
- *
- * Returns the foreground color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Color getForeground (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count -1) return getForeground ();
- if (cellForeground == null || cellForeground [index] == null) return getForeground ();
- return cellForeground [index];
-}
-
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the parent does not have
- * the <code>CHECK</code> style, return false.
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getGrayed () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return grayed;
-}
-
-public Image getImage () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return getImage (0);
-}
-
-/**
- * Returns the image stored at the given column index in the receiver,
- * or null if the image has not been set or if the column does not exist.
- *
- * @param index the column index
- * @return the image stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getImage (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (images != null) {
- if (0 <= index && index < images.length) return images [index];
- }
- return null;
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of an image at a column in the
- * table. An empty rectangle is returned if index exceeds
- * the index of the table's last column.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding image rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getImageBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index != 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0);
- int parentHandle = parent.topHandle ();
- int image = findPart (index, Table.IMAGE_PART_NAME);
- int point = OS.gcnew_Point (0, 0);
- if (point == 0) error (SWT.ERROR_NO_HANDLES);
- int location = OS.UIElement_TranslatePoint (image, point, parentHandle);
- int x = (int) OS.Point_X (location);
- int y = (int) OS.Point_Y (location);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (location);
- int width = (int) OS.FrameworkElement_ActualWidth (image);
- int height = (int) OS.FrameworkElement_ActualHeight (image);
- OS.GCHandle_Free (image);
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Gets the image indent.
- *
- * @return the indent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getImageIndent () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- //TODO
- return 0;
-// return imageIndent;
-}
-
-String getNameText () {
- if ((parent.style & SWT.VIRTUAL) != 0) {
- if (!cached) return "*virtual*"; //$NON-NLS-1$
- }
- return super.getNameText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Table</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Table getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of the text at a column in the
- * table. An empty rectangle is returned if index exceeds
- * the index of the table's last column.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding text rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Rectangle getTextBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index != 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0);
- int parentHandle = parent.topHandle ();
- int point = OS.gcnew_Point (0, 0);
- if (point == 0) error (SWT.ERROR_NO_HANDLES);
- int textBlock = findPart (index, Table.TEXT_PART_NAME);
- int renderPanel = findPart (index, Table.RENDER_PANEL_NAME);
- Rectangle result = new Rectangle (0, 0, 0, 0);
- if (textBlock != 0 && renderPanel != 0) {
- int location = OS.UIElement_TranslatePoint (textBlock, point, parentHandle);
- int x = (int) OS.Point_X (location);
- int y = (int) OS.Point_Y (location);
- OS.GCHandle_Free (location);
- double textWidth = OS.FrameworkElement_ActualWidth (textBlock);
- int panelLocation = OS.UIElement_TranslatePoint (textBlock, point, renderPanel);
- double visibleWidth = Math.max (0, OS.FrameworkElement_ActualWidth (renderPanel) - OS.Point_X (panelLocation));
- OS.GCHandle_Free (panelLocation);
- int width = (int) Math.min (textWidth, visibleWidth);
- int height = (int) OS.FrameworkElement_ActualHeight (textBlock);
- result = new Rectangle (x, y, width, height);
- }
- OS.GCHandle_Free (point);
- if (textBlock != 0) OS.GCHandle_Free (textBlock);
- if (renderPanel != 0) OS.GCHandle_Free (renderPanel);
- return result;
-}
-
-public String getText () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return getText (0);
-}
-
-/**
- * Returns the text stored at the given column index in the receiver,
- * or empty string if the text has not been set.
- *
- * @param index the column index
- * @return the text stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (strings != null && 0 <= index && index < strings.length) {
- return strings [index]!= null ? strings[index] : "";
- }
- return "";
-}
-
-Control getWidgetControl () {
- return parent;
-}
-
-void register () {
- display.addWidget (handle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (handle != 0) OS.GCHandle_Free (handle);
- handle = 0;
- if (rowHandle != 0) OS.GCHandle_Free (rowHandle);
- rowHandle = 0;
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- strings = null;
- images = null;
- cellBackground = cellForeground = null;
- cellFont = null;
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setBackground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (color != null) {
- int brush = OS.gcnew_SolidColorBrush (color.handle);
- OS.Control_Background (handle, brush);
- OS.GCHandle_Free (brush);
- } else {
- int property = OS.Control_BackgroundProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
- background = color;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-}
-
-/**
- * Sets the background color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setBackground (int index, Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- if (cellBackground == null) cellBackground = new Color [count];
- cellBackground [index] = color;
- updateBackground (index);
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-}
-
-/**
- * Sets the checked state of the checkbox for this item. This state change
- * only applies if the Table was created with the SWT.CHECK style.
- *
- * @param checked the new checked state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setChecked (boolean checked) {
- checkWidget();
- if ((parent.style & SWT.CHECK) == 0) return;
- if (this.checked == checked) return;
- this.checked = checked;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- updateCheck ();
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for this item to the font specified by the argument, or to the default font
- * for that kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (Font font){
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (font != null) {
- int family = OS.Typeface_FontFamily (font.handle);
- OS.Control_FontFamily (handle, family);
- OS.GCHandle_Free (family);
- int stretch = OS.Typeface_Stretch (font.handle);
- OS.Control_FontStretch (handle, stretch);
- OS.GCHandle_Free (stretch);
- int style = OS.Typeface_Style (font.handle);
- OS.Control_FontStyle (handle, style);
- OS.GCHandle_Free (style);
- int weight = OS.Typeface_Weight (font.handle);
- OS.Control_FontWeight (handle, weight);
- OS.GCHandle_Free (weight);
- OS.Control_FontSize (handle, font.size);
- } else {
- int property = OS.Control_FontFamilyProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS. Control_FontStyleProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.Control_FontStretchProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.Control_FontWeightProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.Control_FontSizeProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
- this.font = font;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for the specified cell in this item to the font specified by the
- * argument, or to the default font for that kind of control if the
- * argument is null.
- *
- * @param index the column index
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (int index, Font font) {
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- if (cellFont == null) {
- if (font == null) return;
- cellFont = new Font [count];
- }
- Font oldFont = cellFont [index];
- if (oldFont == font) return;
- cellFont [index] = font;
- if (oldFont != null && oldFont.equals (font)) return;
- updateFont (index);
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-}
-
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- */
-public void setForeground (Color color){
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (color != null) {
- int brush = OS.gcnew_SolidColorBrush (color.handle);
- OS.Control_Foreground (handle, brush);
- OS.GCHandle_Free (brush);
- } else {
- int property = OS.Control_ForegroundProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
- foreground = color;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-}
-
-/**
- * Sets the foreground color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setForeground (int index, Color color){
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- if (cellForeground == null) cellForeground = new Color [count];
- cellForeground [index] = color;
- updateForeground (index);
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-}
-
-/**
- * Sets the grayed state of the checkbox for this item. This state change
- * only applies if the Table was created with the SWT.CHECK style.
- *
- * @param grayed the new grayed state of the checkbox;
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setGrayed (boolean grayed) {
- checkWidget ();
- if ((parent.style & SWT.CHECK) == 0) return;
- if (this.grayed == grayed) return;
- this.grayed = grayed;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- updateCheck ();
-}
-
-/**
- * Sets the image for multiple columns in the table.
- *
- * @param images the array of new images
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image [] images) {
- checkWidget ();
- if (images == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<images.length; i++) {
- setImage (i, images [i]);
- }
-}
-
-/**
- * Sets the receiver's image at a column.
- *
- * @param index the column index
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (int index, Image image) {
- checkWidget ();
- if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- if (images == null) images = new Image [count];
- images [index] = image;
- updateImage (index);
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-}
-
-public void setImage (Image image) {
- checkWidget ();
- setImage (0, image);
-}
-
-/**
- * Sets the indent of the first column's image, expressed in terms of the image's width.
- *
- * @param indent the new indent
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @deprecated this functionality is not supported on most platforms
- */
-public void setImageIndent (int indent) {
- checkWidget ();
-}
-
-/**
- * Sets the text for multiple columns in the table.
- *
- * @param strings the array of new strings
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String [] strings) {
- checkWidget ();
- if (strings == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<strings.length; i++) {
- String string = strings [i];
- if (string != null) setText (i, string);
- }
-}
-
-/**
- * Sets the receiver's text at a column
- *
- * @param index the column index
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (int index, String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- if (strings == null) strings = new String [count];
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- strings [index] = string;
- updateText (index);
-}
-
-public void setText (String string) {
- checkWidget ();
- setText (0, string);
-}
-
-void updateBackground (int index) {
- int panel = findPart (index, Table.CONTENTPANEL_PART_NAME);
- if (panel != 0) {
- if (cellBackground != null && cellBackground [index] != null) {
- int brush = OS.gcnew_SolidColorBrush (cellBackground [index].handle);
- int current = OS.Panel_Background (panel);
- if (!OS.Object_Equals (brush, current))
- OS.Panel_Background (panel, brush);
- OS.GCHandle_Free (current);
- OS.GCHandle_Free (brush);
- } else {
- int property = OS.Panel_BackgroundProperty ();
- OS.DependencyObject_ClearValue (panel, property);
- OS.GCHandle_Free (property);
- }
- OS.GCHandle_Free (panel);
- }
-}
-
-void updateCheck () {
- if ((parent.style & SWT.CHECK) == 0) return;
- int checkBox = findPart (0, Table.CHECKBOX_PART_NAME);
- if (checkBox != 0) {
- parent.ignoreSelection = true;
- if (!grayed) {
- OS.ToggleButton_IsChecked (checkBox, checked);
- } else {
- if (checked)
- OS.ToggleButton_IsCheckedNullSetter (checkBox);
- }
- parent.ignoreSelection = false;
- OS.GCHandle_Free (checkBox);
- }
-}
-
-void updateFont (int index) {
- int textBlock = findPart (index, Table.TEXT_PART_NAME);
- if (textBlock != 0) {
- Font font = cellFont != null ? cellFont [index] : null;
- if (font != null) {
- int family = OS.Typeface_FontFamily (font.handle);
- OS.TextBlock_FontFamily (textBlock, family);
- OS.GCHandle_Free (family);
- int stretch = OS.Typeface_Stretch (font.handle);
- OS.TextBlock_FontStretch (textBlock, stretch);
- OS.GCHandle_Free (stretch);
- int style = OS.Typeface_Style (font.handle);
- OS.TextBlock_FontStyle (textBlock, style);
- OS.GCHandle_Free (style);
- int weight = OS.Typeface_Weight (font.handle);
- OS.TextBlock_FontWeight (textBlock, weight);
- OS.GCHandle_Free (weight);
- OS.TextBlock_FontSize (textBlock, font.size);
- } else {
- int property = OS.TextBlock_FontFamilyProperty ();
- OS.DependencyObject_ClearValue (textBlock, property);
- OS.GCHandle_Free (property);
- property = OS.TextBlock_FontSizeProperty ();
- OS.DependencyObject_ClearValue (textBlock, property);
- OS.GCHandle_Free (property);
- property = OS.TextBlock_FontStretchProperty ();
- OS.DependencyObject_ClearValue (textBlock, property);
- OS.GCHandle_Free (property);
- property = OS.TextBlock_FontWeightProperty ();
- OS.DependencyObject_ClearValue (textBlock, property);
- OS.GCHandle_Free (property);
- property = OS.TextBlock_FontStyleProperty ();
- OS.DependencyObject_ClearValue (textBlock, property);
- OS.GCHandle_Free (property);
- }
- OS.GCHandle_Free (textBlock);
- }
-}
-
-void updateForeground (int index) {
- int textBlock = findPart (index, Table.TEXT_PART_NAME);
- if (textBlock != 0) {
- if (cellForeground != null && cellForeground [index] != null) {
- int brush = OS.gcnew_SolidColorBrush (cellForeground [index].handle);
- OS.TextBlock_Foreground (textBlock, brush);
- OS.GCHandle_Free (brush);
- } else {
- int property = OS.Control_ForegroundProperty ();
- OS.DependencyObject_ClearValue (textBlock, property);
- OS.GCHandle_Free (property);
- }
- OS.GCHandle_Free (textBlock);
- }
-}
-
-void updateImage (int index) {
- int img = findPart (index, Table.IMAGE_PART_NAME);
- if (img != 0) {
- int src = 0;
- if (images != null) src = images [index] != null ? images [index].handle : 0;
- int current = OS.Image_Source (img);
- OS.Image_Source (img, src);
- OS.GCHandle_Free (current);
- OS.GCHandle_Free (img);
- }
-}
-
-void updateText (int index) {
- int textBlock = findPart (index, Table.TEXT_PART_NAME);
- if (textBlock != 0) {
- if (strings != null && strings [index] != null) {
- int strPtr = createDotNetString (strings [index], false);
- OS.TextBlock_Text (textBlock, strPtr);
- OS.GCHandle_Free (strPtr);
- } else {
- int property = OS.TextBlock_TextProperty ();
- OS.DependencyObject_ClearValue (textBlock, property);
- OS.GCHandle_Free (property);
- }
- OS.GCHandle_Free (textBlock);
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Text.java
deleted file mode 100644
index b5295c1d40..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Text.java
+++ /dev/null
@@ -1,1510 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that allow the user to enter and modify text.
- * Text controls can be either single or multi-line.
- * When a text control is created with a border, the
- * operating system includes a platform specific inset
- * around the contents of the control. When created
- * without a border, an effort is made to remove the
- * inset such that the preferred size of the control
- * is the same size as the contents.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>CENTER, ICON_CANCEL, ICON_SEARCH, LEFT, MULTI, PASSWORD, SEARCH, SINGLE, RIGHT, READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Modify, Verify</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles MULTI and SINGLE may be specified,
- * and only one of the styles LEFT, CENTER, and RIGHT may be specified.
- * </p>
- * <p>
- * Note: The styles ICON_CANCEL and ICON_SEARCH are hints used in combination with SEARCH.
- * When the platform supports the hint, the text control shows these icons. When an icon
- * is selected, a default selection event is sent with the detail field set to one of
- * ICON_CANCEL or ICON_SEARCH. Normally, application code does not need to check the
- * detail. In the case of ICON_CANCEL, the text is cleared before the default selection
- * event is sent causing the application to search for an empty string.
- * </p>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#text">Text snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Text extends Scrollable {
- boolean doubleClick;
-
- /**
- * The maximum number of characters that can be entered
- * into a text widget.
- * <p>
- * Note that this value is platform dependent, based upon
- * the native widget implementation.
- * </p>
- */
- public static final int LIMIT;
-
- /**
- * The delimiter used by multi-line text widgets. When text
- * is queried and from the widget, it will be delimited using
- * this delimiter.
- */
- public static final String DELIMITER;
-
- /*
- * This code is intentionally commented.
- */
-// static final char PASSWORD;
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0x7FFFFFFF;
- DELIMITER = "\r\n";
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#READ_ONLY
- * @see SWT#WRAP
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see SWT#PASSWORD
- * @see SWT#SEARCH
- * @see SWT#ICON_SEARCH
- * @see SWT#ICON_CANCEL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Text (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
-public void addModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is not called for texts.
- * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text,
- * or when ENTER is pressed in a search text. If the receiver has the <code>SWT.SEARCH | SWT.CANCEL</code> style
- * and the user cancels the search, the event object detail field contains the value <code>SWT.CANCEL</code>.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is verified, by sending
- * it one of the messages defined in the <code>VerifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #removeVerifyListener
- */
-public void addVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-
-/**
- * Appends a string.
- * <p>
- * The new text is appended to the text at
- * the end of the widget.
- * </p>
- *
- * @param string the string to be appended
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void append (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.PASSWORD) != 0) return;
- OS.TextBox_SelectionStart (handle, getCharCount ());
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- int start = OS.TextBox_SelectionStart (handle);
- int end = start + OS.TextBox_SelectionLength (handle);
- string = verifyText (string, start, end, false);
- if (string == null) return;
- }
- int strPtr = createDotNetString (string, false);
- OS.TextBoxBase_AppendText (handle, strPtr);
- OS.TextBox_SelectionLength (handle, 0);
- OS.GCHandle_Free (strPtr);
-}
-
-static int checkStyle (int style) {
- if ((style & SWT.SEARCH) != 0) {
- style |= SWT.SINGLE | SWT.BORDER;
- style &= ~SWT.PASSWORD;
- }
- style &= ~SWT.SEARCH;
- if ((style & SWT.SINGLE) != 0 && (style & SWT.MULTI) != 0) {
- style &= ~SWT.MULTI;
- }
- style = checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
- if ((style & SWT.SINGLE) != 0) style &= ~(SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP);
- if ((style & SWT.WRAP) != 0) {
- style |= SWT.MULTI;
- style &= ~SWT.H_SCROLL;
- }
- if ((style & SWT.MULTI) != 0) style &= ~SWT.PASSWORD;
- if ((style & (SWT.SINGLE | SWT.MULTI)) != 0) return style;
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) return style | SWT.MULTI;
- return style | SWT.SINGLE;
-}
-
-/**
- * Clears the selection.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void clearSelection () {
- checkWidget ();
- if ((style & SWT.PASSWORD) != 0) return;
- int start = OS.TextBox_SelectionStart (handle);
- int len = OS.TextBox_SelectionLength (handle);
- OS.TextBox_SelectionStart (handle, start + len);
- OS.TextBox_SelectionLength (handle, 0);
-}
-
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void copy () {
- checkWidget ();
- if ((style & SWT.PASSWORD) != 0) return;
- OS.TextBoxBase_Copy (handle);
-}
-
-void createHandle () {
- if ((style & SWT.PASSWORD) != 0) {
- handle = OS.gcnew_PasswordBox ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- return;
- }
- handle = OS.gcnew_TextBox ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.MULTI) != 0) {
- OS.TextBoxBase_AcceptsReturn (handle, true);
- OS.TextBoxBase_AcceptsTab (handle, true);
- if ((style & SWT.WRAP) != 0) OS.TextBox_TextWrapping (handle, OS.TextWrapping_Wrap);
- }
- if ((style & SWT.BORDER) == 0) {
- int thickness = OS.gcnew_Thickness (0, 0, 0, 0);
- OS.Control_BorderThickness (handle, thickness);
- OS.Control_Padding(handle, thickness);
- OS.GCHandle_Free (thickness);
- }
-
- if ((style & SWT.READ_ONLY) != 0) OS.TextBoxBase_IsReadOnly (handle, true);
- if ((style & SWT.CENTER) != 0) OS.Control_HorizontalContentAlignment (handle, OS.HorizontalAlignment_Center);
- if ((style & SWT.RIGHT) != 0) OS.Control_HorizontalContentAlignment (handle, OS.HorizontalAlignment_Right);
- if ((style & SWT.V_SCROLL) != 0) OS.TextBoxBase_VerticalScrollBarVisibility (handle, OS.ScrollBarVisibility_Visible);
- if ((style & SWT.H_SCROLL) != 0) OS.TextBoxBase_HorizontalScrollBarVisibility (handle, OS.ScrollBarVisibility_Visible);
-}
-
-void createWidget () {
- super.createWidget ();
- doubleClick = true;
-// setTabStops (8);
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void cut () {
- checkWidget ();
- if ((style & SWT.READ_ONLY) != 0) return;
- if ((style & SWT.PASSWORD) != 0) return;
- OS.TextBoxBase_Cut (handle);
-}
-
-/**
- * Returns the line number of the caret.
- * <p>
- * The line number of the caret is returned.
- * </p>
- *
- * @return the line number
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretLineNumber () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return 0;
- if ((style & SWT.PASSWORD) != 0) return 0;
- int caretIndex = OS.TextBox_CaretIndex (handle);
- return OS.TextBox_GetLineIndexFromCharacterIndex (handle, caretIndex);
-}
-
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null).
- * <p>
- * The location of the caret is returned.
- * </p>
- *
- * @return a point, the location of the caret
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getCaretLocation () {
- checkWidget ();
- if ((style & SWT.PASSWORD) != 0) return new Point (0, 0);
- int caretIndex = OS.TextBox_CaretIndex (handle);
- int rect = OS.TextBox_GetRectFromCharacterIndex (handle, caretIndex);
- Point result = new Point ((int)OS.Rect_X (rect), (int)OS.Rect_Y (rect));
- OS.GCHandle_Free (rect);
- return result;
-}
-
-/**
- * Returns the character position of the caret.
- * <p>
- * Indexing is zero based.
- * </p>
- *
- * @return the position of the caret
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCaretPosition () {
- checkWidget ();
- if ((style & SWT.PASSWORD) != 0) return 0;
- return OS.TextBox_CaretIndex (handle);
-}
-
-/**
- * Returns the number of characters.
- *
- * @return number of characters in the widget
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getCharCount () {
- checkWidget ();
- int text;
- if ((style & SWT.PASSWORD) != 0) {
- text = OS.PasswordBox_Password (handle);
- } else {
- text = OS.TextBox_Text (handle);
- }
- int length = OS.String_Length (text);
- OS.GCHandle_Free (text);
- return length;
-}
-
-/**
- * Returns the double click enabled flag.
- * <p>
- * The double click flag enables or disables the
- * default action of the text widget when the user
- * double clicks.
- * </p>
- *
- * @return whether or not double click is enabled
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getDoubleClickEnabled () {
- checkWidget ();
- return doubleClick;
-}
-
-/**
- * Returns the echo character.
- * <p>
- * The echo character is the character that is
- * displayed when the user enters text or the
- * text is changed by the programmer.
- * </p>
- *
- * @return the echo character
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setEchoChar
- */
-public char getEchoChar () {
- checkWidget ();
- if ((style & SWT.PASSWORD) == 0) return 0;
- return OS.PasswordBox_PasswordChar (handle);
-}
-
-/**
- * Returns the editable state.
- *
- * @return whether or not the receiver is editable
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getEditable () {
- checkWidget ();
- if ((style & SWT.PASSWORD) != 0) return true;
- return !OS.TextBoxBase_IsReadOnly (handle);
-}
-
-/**
- * Returns the number of lines.
- *
- * @return the number of lines in the widget
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getLineCount () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return 1;
- if ((style & SWT.PASSWORD) != 0) return 1;
- int lines = OS.TextBox_LineCount (handle);
- if (lines == -1) {
- updateLayout (handle);
- lines = OS.TextBox_LineCount (handle);
- }
- return lines;
-}
-
-/**
- * Returns the line delimiter.
- *
- * @return a string that is the line delimiter
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #DELIMITER
- */
-public String getLineDelimiter () {
- checkWidget ();
- return DELIMITER;
-}
-
-/**
- * Returns the height of a line.
- *
- * @return the height of a row of text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getLineHeight () {
- checkWidget ();
- int family = OS.Control_FontFamily (handle);
- double lineSpacing = OS.FontFamily_LineSpacing (family);
- OS.GCHandle_Free (family);
- double size = OS.Control_FontSize (handle);
- return (int) (lineSpacing * size);
-}
-
-/**
- * Returns the widget message. The message text is displayed
- * as a hint for the user, indicating the purpose of the field.
- * <p>
- * Typically this is used in conjunction with <code>SWT.SEARCH</code>.
- * </p>
- *
- * @return the widget message
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public String getMessage () {
- checkWidget ();
- return "";
-}
-
-/**
- * Returns the orientation of the receiver, which will be one of the
- * constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- *
- * @return the orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public int getOrientation () {
- checkWidget();
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
-/**
- * Returns a <code>Point</code> whose x coordinate is the
- * character position representing the start of the selected
- * text, and whose y coordinate is the character position
- * representing the end of the selection. An "empty" selection
- * is indicated by the x and y coordinates having the same value.
- * <p>
- * Indexing is zero based. The range of a selection is from
- * 0..N where N is the number of characters in the widget.
- * </p>
- *
- * @return a point representing the selection start and end
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point getSelection () {
- checkWidget ();
- if ((style & SWT.PASSWORD) != 0) return new Point (0, 0);
- int start = OS.TextBox_SelectionStart (handle);
- int length = OS.TextBox_SelectionLength (handle);
- return new Point (start, start+length);
-}
-
-/**
- * Returns the number of selected characters.
- *
- * @return the number of selected characters.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget ();
- Point selection = getSelection ();
- return selection.y - selection.x;
-}
-
-/**
- * Gets the selected text, or an empty string if there is no current selection.
- *
- * @return the selected text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getSelectionText () {
- checkWidget ();
- if ((style & SWT.PASSWORD) != 0) return "";
- int content = OS.TextBox_SelectedText (handle);
- String string = createJavaString (content);
- OS.GCHandle_Free (content);
- return string;
-}
-
-/**
- * Returns the number of tabs.
- * <p>
- * Tab stop spacing is specified in terms of the
- * space (' ') character. The width of a single
- * tab stop is the pixel width of the spaces.
- * </p>
- *
- * @return the number of tab characters
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTabs () {
- checkWidget ();
- //FIXME
- return 8;
-}
-
-/**
- * Returns the widget text.
- * <p>
- * The text for a text widget is the characters in the widget, or
- * an empty string if this has never been set.
- * </p>
- *
- * @return the widget text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText () {
- checkWidget();
- int text;
- if ((style & SWT.PASSWORD) != 0) {
- text = OS.PasswordBox_Password (handle);
- } else {
- text = OS.TextBox_Text (handle);
- }
- String string = createJavaString (text);
- OS.GCHandle_Free (text);
- return string;
-}
-
-/**
- * Returns a range of text. Returns an empty string if the
- * start of the range is greater than the end.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N-1 where N is
- * the number of characters in the widget.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- * @return the range of text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getText (int start, int end) {
- checkWidget ();
- if (!(start <= end && 0 <= end)) return "";
- String text = getText ();
- int length = text.length();
- end = Math.min (end, length - 1);
- if (start > end) return "";
- start = Math.max (0, start);
- /*
- * NOTE: The current implementation uses substring ()
- * which can reference a potentially large character
- * array.
- */
- return text.substring (start, end + 1);
-}
-
-/**
- * Returns the maximum number of characters that the receiver is capable of holding.
- * <p>
- * If this has not been changed by <code>setTextLimit()</code>,
- * it will be the constant <code>Text.LIMIT</code>.
- * </p>
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public int getTextLimit () {
- checkWidget ();
- if ((style & SWT.PASSWORD) != 0) return OS.PasswordBox_MaxLength (handle);
- return OS.TextBox_MaxLength (handle);
-}
-
-/**
- * Returns the zero-relative index of the line which is currently
- * at the top of the receiver.
- * <p>
- * This index can change when lines are scrolled or new lines are added or removed.
- * </p>
- *
- * @return the index of the top line
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopIndex () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return 0;
- if ((style & SWT.PASSWORD) != 0) return 0;
- return OS.TextBox_GetFirstVisibleLineIndex (handle);
-}
-
-/**
- * Returns the top pixel.
- * <p>
- * The top pixel is the pixel position of the line
- * that is currently at the top of the widget. On
- * some platforms, a text widget can be scrolled by
- * pixels instead of lines so that a partial line
- * is displayed at the top of the widget.
- * </p><p>
- * The top pixel changes when the widget is scrolled.
- * The top pixel does not include the widget trimming.
- * </p>
- *
- * @return the pixel position of the top line
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getTopPixel () {
- checkWidget ();
- int name = createDotNetString ("PART_ContentHost", false);
- int template = OS.Control_Template (handle);
- int scroller = OS.FrameworkTemplate_FindName (template, name, handle);
- if (scroller == 0) {
- updateLayout (handle);
- scroller = OS.FrameworkTemplate_FindName (template, name, handle);
- }
- OS.GCHandle_Free (name);
- OS.GCHandle_Free (template);
- if (scroller == 0) return 0;
- double vertOffset = OS.ScrollViewer_VerticalOffset (scroller);
- OS.GCHandle_Free (scroller);
- return (int) vertOffset;
-}
-
-void HandlePreviewKeyDown (int sender, int e) {
- super.HandlePreviewKeyDown (sender, e);
- if (!checkEvent (e)) return;
- if ((style & SWT.SINGLE) != 0) {
- int key = OS.KeyEventArgs_Key (e);
- if (key == OS.Key_Return) postEvent (SWT.DefaultSelection);
- }
-}
-
-void HandlePreviewExecutedRoutedEvent (int sender, int e) {
- if (!checkEvent (e)) return;
- int command = OS.ExecutedRoutedEventArgs_Command (e);
- boolean doVerify = false;
- String input = null;
- int paste = OS.ApplicationCommands_Paste ();
- int cut = OS.ApplicationCommands_Cut ();
- int redo = OS.ApplicationCommands_Redo ();
- int undo = OS.ApplicationCommands_Undo ();
- int backspace = OS.EditingCommands_Backspace ();
- int delete = OS.EditingCommands_Delete ();
- int deleteNext = OS.EditingCommands_DeleteNextWord ();
- int deletePrevious = OS.EditingCommands_DeletePreviousWord ();
- if (OS.Object_Equals (command, paste)) {
- doVerify = true;
- int clipboardText = OS.Clipboard_GetText ();
- input = createJavaString(clipboardText);
- OS.GCHandle_Free(clipboardText);
- } else if (OS.Object_Equals (command, cut)){
- doVerify = true;
- input = getSelectionText ();
- } else if (OS.Object_Equals(command, redo)) {
- //FIXME
- //doVerify = true;
- OS.ExecutedRoutedEventArgs_Handled (e, true);
- } else if (OS.Object_Equals(command, undo)) {
- //FIXME
- //doVerify = true;
- OS.ExecutedRoutedEventArgs_Handled (e, true);
- } else if (OS.Object_Equals (command, backspace)) {
- doVerify = true;
- input = "";
- } else if (OS.Object_Equals (command, delete)) {
- doVerify = true;
- input = "";
- } else if (OS.Object_Equals(command, deleteNext)) {
- //FIXME
- //doVerify = true;
- OS.ExecutedRoutedEventArgs_Handled (e, true);
- } else if (OS.Object_Equals(command, deletePrevious)) {
- //FIXME
- //doVerify = true;
- OS.ExecutedRoutedEventArgs_Handled (e, true);
- }
- OS.GCHandle_Free (paste);
- OS.GCHandle_Free (cut);
- OS.GCHandle_Free (redo);
- OS.GCHandle_Free (undo);
- OS.GCHandle_Free (backspace);
- OS.GCHandle_Free (delete);
- OS.GCHandle_Free (deleteNext);
- OS.GCHandle_Free (deletePrevious);
- OS.GCHandle_Free (command);
- /*
- * FIXME - should do this first, but for now we want to swallow
- * all Redo, Undo, DeleteNextWord and DeletePreviousWord to
- * prevent those from changing the TextBox w/o Verify events
- */
- if (!hooks (SWT.Verify)) return;
- if (!doVerify) return;
- int start = OS.TextBox_SelectionStart (handle);
- int end = start + OS.TextBox_SelectionLength (handle);
- String text = verifyText (input, start, end, true);
- if (text != null && !text.equals (input)) {
- int strPtr = createDotNetString (text, false);
- OS.TextBox_SelectedText (handle, strPtr);
- OS.GCHandle_Free (strPtr);
- start = OS.TextBox_SelectionStart (handle);
- int length = OS.TextBox_SelectionLength (handle);
- OS.TextBox_Select (handle, start+length, 0);
- OS.TextBox_SelectionLength (handle, 0);
- text = null;
- }
- if (text == null) OS.ExecutedRoutedEventArgs_Handled (e, true);
-}
-
-void HandlePreviewTextInput (int sender, int e) {
- super.HandlePreviewTextInput (sender, e);
- if (!checkEvent (e)) return;
- if ((style & SWT.PASSWORD) != 0) return;
- int textPtr = OS.TextCompositionEventArgs_Text (e);
- String input = createJavaString(textPtr);
- OS.GCHandle_Free (textPtr);
- int start = OS.TextBox_SelectionStart (handle);
- int end = start + OS.TextBox_SelectionLength (handle);
- String text = verifyText (input, start, end, true);
- if (text != null && !text.equals (input)) {
- textPtr = createDotNetString (text, false);
- OS.TextBox_SelectedText (handle, textPtr);
- OS.GCHandle_Free (textPtr);
- start = OS.TextBox_SelectionStart (handle);
- int length = OS.TextBox_SelectionLength (handle);
- OS.TextBox_Select (handle, start+length, 0);
- OS.TextBox_SelectionLength (handle, 0);
- text = null;
- }
- if (text == null) OS.TextCompositionEventArgs_Handled (e, true);
-}
-
-void HandleTextChanged (int sender, int e) {
- if (!checkEvent (e)) return;
- sendEvent (SWT.Modify);
-}
-
-void hookEvents () {
- super.hookEvents();
- if ((style & SWT.PASSWORD) != 0) {
- int handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleTextChanged");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.PasswordBox_PasswordChanged (handle, handler);
- OS.GCHandle_Free(handler);
- return;
- }
-
- int handler = OS.gcnew_ExecutedRoutedEventHandler (jniRef, "HandlePreviewExecutedRoutedEvent");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.CommandManager_AddPreviewExecutedHandler (handle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_TextChangedEventHandler (jniRef, "HandleTextChanged");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.TextBoxBase_TextChanged (handle, handler);
- OS.GCHandle_Free (handler);
-}
-
-/**
- * Inserts a string.
- * <p>
- * The old selection is replaced with the new text.
- * </p>
- *
- * @param string the string
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is <code>null</code></li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void insert (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.PASSWORD) != 0) return;
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- int start = OS.TextBox_SelectionStart (handle);
- string = verifyText (string, start, start, false);
- if (string == null) return;
- }
- int strPtr = createDotNetString (string, false);
- OS.TextBox_SelectionLength (handle, 0);
- OS.TextBox_SelectedText (handle, strPtr);
- OS.GCHandle_Free (strPtr);
- int end = OS.TextBox_SelectionStart (handle) + OS.TextBox_SelectionLength (handle);
- OS.TextBox_Select (handle, end, 0);
-}
-
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void paste () {
- checkWidget ();
- if ((style & SWT.PASSWORD) != 0) {
- OS.PasswordBox_Paste (handle);
- return;
- }
- OS.TextBoxBase_Paste (handle);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
- */
-public void removeModifyListener (ModifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is verified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see VerifyListener
- * @see #addVerifyListener
- */
-public void removeVerifyListener (VerifyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-
-/**
- * Selects all the text in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget ();
- if ((style & SWT.PASSWORD) != 0) return;
- OS.TextBoxBase_SelectAll (handle);
-}
-
-/**
- * Sets the double click enabled flag.
- * <p>
- * The double click flag enables or disables the
- * default action of the text widget when the user
- * double clicks.
- * </p><p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param doubleClick the new double click flag
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDoubleClickEnabled (boolean doubleClick) {
- checkWidget ();
- this.doubleClick = doubleClick;
-}
-
-/**
- * Sets the echo character.
- * <p>
- * The echo character is the character that is
- * displayed when the user enters text or the
- * text is changed by the programmer. Setting
- * the echo character to '\0' clears the echo
- * character and redraws the original text.
- * If for any reason the echo character is invalid,
- * or if the platform does not allow modification
- * of the echo character, the default echo character
- * for the platform is used.
- * </p>
- *
- * @param echo the new echo character
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEchoChar (char echo) {
- checkWidget ();
- if ((style & SWT.PASSWORD) == 0) return;
- OS.PasswordBox_PasswordChar (handle, echo);
-}
-
-/**
- * Sets the editable state.
- *
- * @param editable the new editable state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEditable (boolean editable) {
- checkWidget ();
- style &= ~SWT.READ_ONLY;
- if (!editable) style |= SWT.READ_ONLY;
- if ((style & SWT.PASSWORD) != 0) return;
- OS.TextBoxBase_IsReadOnly (handle, !editable);
-}
-
-void setFont (int font, double size) {
- super.setFont (font, size);
- //FIXME
-// setTabStops (tabs);
-}
-
-/**
- * Sets the widget message. The message text is displayed
- * as a hint for the user, indicating the purpose of the field.
- * <p>
- * Typically this is used in conjunction with <code>SWT.SEARCH</code>.
- * </p>
- *
- * @param message the new message
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the message is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public void setMessage (String message) {
- checkWidget ();
- if (message == null) error (SWT.ERROR_NULL_ARGUMENT);
- //TODO
-}
-
-/**
- * Sets the orientation of the receiver, which must be one
- * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>.
- * <p>
- * Note: This operation is a hint and is not supported on
- * platforms that do not have this concept.
- * </p>
- *
- * @param orientation new orientation style
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1.2
- */
-public void setOrientation (int orientation) {
- checkWidget();
- int flags = SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT;
- if ((orientation & flags) == 0 || (orientation & flags) == flags) return;
- style &= ~flags;
- style |= orientation & flags;
- //FIXME FrameworkElement.FlowDirection ??
-}
-
-/**
- * Sets the selection.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * regular array indexing rules.
- * </p>
- *
- * @param start new caret position
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int start) {
- checkWidget ();
- if ((style & SWT.PASSWORD) != 0) return;
- OS.TextBox_CaretIndex (handle, start);
-}
-
-/**
- * Sets the selection to the range specified
- * by the given start and end indices.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * usual array indexing rules.
- * </p>
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (int start, int end) {
- checkWidget ();
- if ((style & SWT.PASSWORD) != 0) return;
- int first = Math.max (Math.min (start, end), 0);
- int last = Math.min (Math.max (start, end), getCharCount ());
- OS.TextBox_Select (handle, first, last-first);
-}
-
-/**
- * Sets the selection to the range specified
- * by the given point, where the x coordinate
- * represents the start index and the y coordinate
- * represents the end index.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * usual array indexing rules.
- * </p>
- *
- * @param selection the point
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (Point selection) {
- checkWidget ();
- if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (selection.x, selection.y);
-}
-
-/**
- * Sets the number of tabs.
- * <p>
- * Tab stop spacing is specified in terms of the
- * space (' ') character. The width of a single
- * tab stop is the pixel width of the spaces.
- * </p>
- *
- * @param tabs the number of tabs
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTabs (int tabs) {
- checkWidget ();
- if (tabs < 0) return;
- //FIXME - no equivalent API in WPF TextBox
-// setTabStops (this.tabs = tabs);
-}
-
-/**
- * Sets the contents of the receiver to the given string. If the receiver has style
- * SINGLE and the argument contains multiple lines of text, the result of this
- * operation is undefined and may vary from platform to platform.
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (hooks (SWT.Verify) || filters (SWT.Verify)) {
- string = verifyText (string, 0, getCharCount (), false);
- if (string == null) return;
- }
- int ptr = createDotNetString (string, false);
- if ((style & SWT.PASSWORD) != 0) {
- OS.PasswordBox_Password (handle, ptr);
- } else {
- OS.TextBox_Text (handle, ptr);
- }
- OS.GCHandle_Free (ptr);
-}
-
-/**
- * Sets the maximum number of characters that the receiver
- * is capable of holding to be the argument.
- * <p>
- * Instead of trying to set the text limit to zero, consider
- * creating a read-only text widget.
- * </p><p>
- * To reset this value to the default, use <code>setTextLimit(Text.LIMIT)</code>.
- * Specifying a limit value larger than <code>Text.LIMIT</code> sets the
- * receiver's limit to <code>Text.LIMIT</code>.
- * </p>
- *
- * @param limit new text limit
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #LIMIT
- */
-public void setTextLimit (int limit) {
- checkWidget ();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- if (limit < 0) limit = LIMIT;
- limit = Math.min (limit, LIMIT);
- if ((style & SWT.PASSWORD) != 0) {
- OS.PasswordBox_MaxLength (handle, limit);
- } else {
- OS.TextBox_MaxLength (handle, limit);
- }
-}
-
-/**
- * Sets the zero-relative index of the line which is currently
- * at the top of the receiver. This index can change when lines
- * are scrolled or new lines are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setTopIndex (int index) {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- if ((style & SWT.PASSWORD) != 0) return;
- int count = OS.TextBox_LineCount (handle);
- if (count == -1) {
- updateLayout (handle);
- count = OS.TextBox_LineCount (handle);
- }
- index = Math.max(0, Math.min (index, count-1));
- int family = OS.Control_FontFamily (handle);
- double lineSpacing = OS.FontFamily_LineSpacing (family);
- OS.GCHandle_Free (family);
- double size = OS.Control_FontSize (handle);
- double lineHeight = lineSpacing * size;
- int name = createDotNetString ("PART_ContentHost", false);
- int template = OS.Control_Template (handle);
- int scroller = OS.FrameworkTemplate_FindName (template, name, handle);
- OS.GCHandle_Free (name);
- OS.GCHandle_Free (template);
- if (scroller == 0) return;
- double vertOffset = index*lineHeight;
- OS.ScrollViewer_ScrollToVerticalOffset (scroller, vertOffset);
- OS.GCHandle_Free (scroller);
- updateLayout(handle);
-}
-
-/**
- * Shows the selection.
- * <p>
- * If the selection is already showing
- * in the receiver, this method simply returns. Otherwise,
- * lines are scrolled until the selection is visible.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void showSelection () {
- checkWidget ();
- if ((style & SWT.PASSWORD) != 0) return;
- double offset = OS.TextBoxBase_VerticalOffset (handle);
- OS.TextBoxBase_ScrollToVerticalOffset (handle, offset);
-}
-
-int traversalCode (int key, int event) {
- int bits = super.traversalCode (key, event);
- if ((style & SWT.READ_ONLY) != 0) return bits;
- if ((style & SWT.MULTI) != 0) {
- bits &= ~SWT.TRAVERSE_RETURN;
- if (key == OS.Key_Tab && event != 0) {
- int keyboardDevice = OS.KeyboardEventArgs_KeyboardDevice(event);
- int modifiers = OS.KeyboardDevice_Modifiers(keyboardDevice);
- OS.GCHandle_Free(keyboardDevice);
- boolean next = (modifiers & OS.ModifierKeys_Shift) == 0;
- if (next && (modifiers & OS.ModifierKeys_Control) == 0) {
- bits &= ~(SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS);
- }
- }
- }
- return bits;
-}
-
-String verifyText (String string, int start, int end, boolean keyEvent) {
- Event event = new Event ();
- event.text = string;
- event.start = start;
- event.end = end;
- if (keyEvent && string.length () == 1) {
- event.character = string.charAt (0);
- setInputState (event, SWT.KeyDown, 0, 0);
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the verify
- * event. If this happens, answer null to cancel
- * the operation.
- */
- sendEvent (SWT.Verify, event);
- if (!event.doit || isDisposed ()) return null;
- return event.text;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ToolBar.java
deleted file mode 100644
index ddc1d15a8e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ToolBar.java
+++ /dev/null
@@ -1,471 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.wpf.*;
-
-/**
- * Instances of this class support the layout of selectable
- * tool bar items.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>ToolItem</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add <code>Control</code> children to it,
- * or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>FLAT, WRAP, RIGHT, HORIZONTAL, VERTICAL, SHADOW_OUT</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#toolbar">ToolBar, ToolItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolBar extends Composite {
- int parentingHandle, trayHandle;
- int itemCount;
- Control [] children;
- int childCount;
-
- //TEMPORARY CODE
- static boolean IsVertical;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#FLAT
- * @see SWT#WRAP
- * @see SWT#RIGHT
- * @see SWT#HORIZONTAL
- * @see SWT#SHADOW_OUT
- * @see SWT#VERTICAL
- * @see Widget#checkSubclass()
- * @see Widget#getStyle()
- */
-public ToolBar (Composite parent, int style) {
- super (parent, checkStyle (style));
-
- /*
- * Ensure that either of HORIZONTAL or VERTICAL is set.
- * NOTE: HORIZONTAL and VERTICAL have the same values
- * as H_SCROLL and V_SCROLL so it is necessary to first
- * clear these bits to avoid scroll bars and then reset
- * the bits using the original style supplied by the
- * programmer.
- */
- if ((style & SWT.VERTICAL) != 0) {
- this.style |= SWT.VERTICAL;
- } else {
- this.style |= SWT.HORIZONTAL;
- }
-}
-
-static int checkStyle (int style) {
- IsVertical = (style & SWT.V_SCROLL) != 0;
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-void addChild (Control widget) {
- super.addChild (widget);
- if (childCount == children.length) {
- Control [] newChildren = new Control [childCount + 4];
- System.arraycopy(children, 0, newChildren, 0, childCount);
- children = newChildren;
- }
- children [childCount++] = widget;
-}
-
-int backgroundProperty () {
- return OS.Control_BackgroundProperty ();
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- return super.computeSize (handle, wHint, hHint, changed);
-}
-
-void createHandle () {
- parentingHandle = OS.gcnew_Canvas ();
- if (parentingHandle == 0) error (SWT.ERROR_NO_HANDLES);
- handle = OS.gcnew_ToolBar ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- trayHandle = OS.gcnew_ToolBarTray ();
- if (trayHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int brush = OS.Brushes_Transparent ();
- OS.ToolBarTray_Background (trayHandle, brush);
- OS.GCHandle_Free (brush);
- int toolbars = OS.ToolBarTray_ToolBars (trayHandle);
- OS.IList_Add (toolbars, handle);
- OS.GCHandle_Free (toolbars);
- if (IsVertical) OS.ToolBarTray_Orientation (trayHandle, OS.Orientation_Vertical);
- int children = OS.Panel_Children (parentingHandle);
- OS.UIElementCollection_Add (children, trayHandle);
- OS.GCHandle_Free (children);
- //FIXME: FLAT, WRAP, RIGHT, SHADOW_OUT
-}
-
-void createItem (ToolItem item, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- item.createWidget ();
- int items = OS.ItemsControl_Items (handle);
- OS.ItemCollection_Insert (items, index, item.topHandle ());
- int count = OS.ItemCollection_Count (items);
- OS.GCHandle_Free (items);
- if (itemCount == count) error (SWT.ERROR_ITEM_NOT_ADDED);
- itemCount++;
-}
-
-void createWidget () {
- super.createWidget();
- children = new Control [4];
- updateLayout (parentingHandle);
- setThumbVisibility (OS.Visibility_Collapsed);
- setButtonVisibility (OS.Visibility_Collapsed);
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (parentingHandle);
-}
-
-int defaultBackground () {
- if ((style & SWT.FLAT) != 0) {
- return OS.Colors_Transparent;
- }
- return 0;
-}
-
-void destroyItem (ToolItem item) {
- int items = OS.ItemsControl_Items (handle);
- OS.ItemCollection_Remove (items, item.topHandle ());
- int count = OS.ItemCollection_Count (items);
- OS.GCHandle_Free (items);
- if (itemCount == count) error (SWT.ERROR_ITEM_NOT_REMOVED);
- itemCount--;
-}
-
-Control [] _getChildren () {
- // return children in reverse order.
- Control[] result = new Control [childCount];
- for (int i =0; i < childCount; i++) {
- result [childCount - i - 1] = children [i];
- }
- return result;
-}
-
-ToolItem getItem (int items, int index) {
- int item = OS.ItemCollection_GetItemAt (items, index);
- ToolItem result = (ToolItem) display.getWidget (item);
- OS.GCHandle_Free (item);
- return result;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem getItem (int index) {
- checkWidget ();
- if (index < 0 || index >= itemCount) error (SWT.ERROR_INVALID_RANGE);
- int items = OS.ItemsControl_Items (handle);
- ToolItem result = getItem (items, index);
- OS.GCHandle_Free (items);
- return result;
-}
-
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- *
- * @param point the point used to locate the item
- * @return the item at the given point
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem getItem (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- ToolItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- Rectangle rect = items [i].getBounds ();
- if (rect.contains (point)) return items [i];
- }
- return null;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return itemCount;
-}
-
-/**
- * Returns an array of <code>ToolItem</code>s which are the items
- * in the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolItem [] getItems () {
- checkWidget ();
- ToolItem [] result = new ToolItem [itemCount];
- int items = OS.ItemsControl_Items (handle);
- for (int i = 0; i < itemCount; i++) {
- result[i] = getItem (items, i);
- }
- OS.GCHandle_Free (items);
- return result;
-}
-
-/**
- * Returns the number of rows in the receiver. When
- * the receiver has the <code>WRAP</code> style, the
- * number of rows can be greater than one. Otherwise,
- * the number of rows is always one.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getRowCount () {
- checkWidget ();
- //FIXME: when WRAP implemented
- return 1;
-}
-
-boolean hasItems () {
- return true;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the tool item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the tool item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int indexOf (ToolItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- int items = OS.ItemsControl_Items (handle);
- int index = OS.ItemCollection_IndexOf (items, item.topHandle ());
- OS.GCHandle_Free (items);
- return index;
-}
-
-boolean mnemonicHit (char key) {
- //TODO
- return false;
-}
-
-boolean mnemonicMatch (char key) {
-// for (int i=0; i<itemCount; i++) {
-// if (mnemonicMatch (items [i].textHandle, key)) return true;
-// }
- return false;
-}
-
-int parentingHandle () {
- return parentingHandle;
-}
-
-void register () {
- super.register ();
- display.addWidget (parentingHandle, this);
-}
-
-void releaseChildren (boolean destroy) {
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<itemCount; i++) {
- ToolItem item = getItem (items, i);
- if (item != null && !item.isDisposed ()) item.release (false);
- }
- OS.GCHandle_Free (items);
- super.releaseChildren (destroy);
-}
-
-void removeChild (Control control) {
- super.removeChild (control);
- int index = 0;
- while (index < childCount) {
- if (children [index] == control) break;
- index++;
- }
- if (index == childCount) return;
- System.arraycopy (children, index+1, children, index, --childCount - index);
- children [childCount] = null;
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (parentingHandle != 0) OS.GCHandle_Free (parentingHandle);
- parentingHandle = 0;
- if (trayHandle != 0) OS.GCHandle_Free (trayHandle);
- trayHandle = 0;
-}
-
-void removeControl (Control control) {
- super.removeControl (control);
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<itemCount; i++) {
- ToolItem item = getItem (items, i);
- if (item.control == control) {
- item.setControl (null);
- break;
- }
- }
- OS.GCHandle_Free (items);
-}
-
-void setButtonVisibility (byte visibility) {
- int template = OS.Control_Template (handle);
- int overFlowName = createDotNetString ("OverflowGrid", false);
- int overFlowGrid = OS.FrameworkTemplate_FindName (template, overFlowName, handle);
- if (overFlowGrid != 0) {
- OS.UIElement_Visibility (overFlowGrid, visibility);
- OS.GCHandle_Free (overFlowGrid);
- }
- OS.GCHandle_Free (overFlowName);
- int borderName = createDotNetString ("MainPanelBorder", false);
- int border = OS.FrameworkTemplate_FindName (template, borderName, handle);
- if (border != 0) {
- int left = visibility == OS.Visibility_Visible ? 11 : 0;
- int margin = OS.gcnew_Thickness (0, 0, left, 0);
- OS.FrameworkElement_Margin (border, margin);
- OS.GCHandle_Free (border);
- OS.GCHandle_Free (margin);
- }
- OS.GCHandle_Free (borderName);
- OS.GCHandle_Free (template);
-}
-
-void setForegroundBrush (int brush) {
- if (brush != 0) {
- OS.Control_Foreground (handle, brush);
- } else {
- int property = OS.Control_ForegroundProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
-}
-
-void setThumbVisibility (byte visibility) {
- int template = OS.Control_Template (handle);
- int thumbName = createDotNetString ("ToolBarThumb", false);
- int thumb = OS.FrameworkTemplate_FindName (template, thumbName, handle);
- if (thumb != 0) {
- OS.UIElement_Visibility (thumb, visibility);
- OS.GCHandle_Free (thumb);
- }
- OS.GCHandle_Free (thumbName);
- OS.GCHandle_Free (template);
-}
-
-int topHandle() {
- return parentingHandle;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ToolItem.java
deleted file mode 100644
index 5dda1d3821..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/ToolItem.java
+++ /dev/null
@@ -1,849 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a button in a tool bar.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>PUSH, CHECK, RADIO, SEPARATOR, DROP_DOWN</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles CHECK, PUSH, RADIO, SEPARATOR and DROP_DOWN
- * may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#toolbar">ToolBar, ToolItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class ToolItem extends Item {
- int imageHandle, textHandle, arrowHandle;
- ToolBar parent;
- Control control;
- String toolTipText;
- Image disabledImage, hotImage;
- boolean ignoreSelection;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>ToolBar</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#PUSH
- * @see SWT#CHECK
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ToolItem (ToolBar parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>ToolBar</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#PUSH
- * @see SWT#CHECK
- * @see SWT#RADIO
- * @see SWT#SEPARATOR
- * @see SWT#DROP_DOWN
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ToolItem (ToolBar parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called when the mouse is over the arrow portion of a drop-down tool,
- * the event object detail field contains the value <code>SWT.ARROW</code>.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user,
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.DROP_DOWN, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-int createArrow () {
- int geometry = OS.gcnew_StreamGeometry ();
- int context = OS.StreamGeometry_Open (geometry);
- int start = OS.gcnew_Point (0, 1);
- int point = OS.gcnew_Point (3, 4);
- int end = OS.gcnew_Point (6, 1);
- OS.StreamGeometryContext_BeginFigure (context, start, true, true);
- OS.StreamGeometryContext_LineTo (context, point, true, true);
- OS.StreamGeometryContext_LineTo (context, end, true, true);
- OS.StreamGeometryContext_Close (context);
- int path = OS.gcnew_Path ();
- OS.Path_Data (path, geometry);
- int padding = OS.gcnew_Thickness (3, 0, 0, 0);
- OS.FrameworkElement_Margin (path, padding);
- int brush = OS.Brushes_Black ();
- OS.Path_Fill (path, brush);
- OS.FrameworkElement_Width (path, 6);
- OS.FrameworkElement_Height (path, 6);
- OS.FrameworkElement_HorizontalAlignment (path, OS.HorizontalAlignment_Center);
- OS.FrameworkElement_VerticalAlignment (path, OS.VerticalAlignment_Center);
- OS.GCHandle_Free (padding);
- OS.GCHandle_Free (start);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (end);
- OS.GCHandle_Free (brush);
- OS.GCHandle_Free (context);
- OS.GCHandle_Free (geometry);
- return path;
-}
-
-void createHandle () {
- if ((style & SWT.SEPARATOR) != 0) {
- handle = OS.gcnew_Separator ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- return;
- }
- int bits = SWT.RADIO | SWT.CHECK | SWT.PUSH | SWT.DROP_DOWN;
- switch (style & bits) {
- case SWT.RADIO:
- handle = OS.gcnew_RadioButton();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- break;
- case SWT.CHECK:
- handle = OS.gcnew_CheckBox();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- break;
- case SWT.DROP_DOWN:
- handle = OS.gcnew_Button();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- break;
- case SWT.PUSH:
- default:
- handle = OS.gcnew_Button();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- break;
- }
- OS.ToolBar_SetOverflowMode (handle, OS.OverflowMode_Never);
- imageHandle = OS.gcnew_Image ();
- if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.Image_Stretch (imageHandle, OS.Stretch_None);
- OS.UIElement_Visibility (imageHandle, OS.Visibility_Collapsed);
- textHandle = OS.gcnew_AccessText ();
- if (textHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.FrameworkElement_VerticalAlignment (textHandle, OS.VerticalAlignment_Center);
- OS.FrameworkElement_HorizontalAlignment (textHandle, OS.HorizontalAlignment_Center);
- int panel = OS.gcnew_StackPanel ();
- if (panel == 0) error (SWT.ERROR_NO_HANDLES);
- int orientation = (parent.style & SWT.RIGHT) != 0 ? OS.Orientation_Horizontal : OS.Orientation_Vertical;
- OS.StackPanel_Orientation (panel, orientation);
- int thickness = OS.gcnew_Thickness (1, 1, 1, 1);
- if (thickness == 0) error (SWT.ERROR_NO_HANDLES);
- OS.FrameworkElement_Margin (panel, thickness);
- OS.GCHandle_Free (thickness);
- int children = OS.Panel_Children (panel);
- OS.UIElementCollection_Add (children, imageHandle);
- OS.UIElementCollection_Add (children, textHandle);
- if ((style & SWT.DROP_DOWN) != 0) {
- arrowHandle = createArrow ();
- if ((parent.style & SWT.RIGHT) != 0) {
- OS.UIElementCollection_Add (children, arrowHandle);
- } else {
- int newPanel = OS.gcnew_StackPanel ();
- OS.StackPanel_Orientation (newPanel, OS.Orientation_Horizontal);
- int horizontalChildren = OS.Panel_Children (newPanel);
- OS.UIElementCollection_Add (horizontalChildren, panel);
- OS.UIElementCollection_Add (horizontalChildren, arrowHandle);
- OS.GCHandle_Free (horizontalChildren);
- OS.GCHandle_Free (panel);
- panel = newPanel;
- }
- }
- OS.ContentControl_Content (handle, panel);
- OS.GCHandle_Free (children);
- OS.GCHandle_Free (panel);
- int margin = OS.gcnew_Thickness (0, 0, 0, 0);
- OS.Control_Padding (handle, margin);
- OS.GCHandle_Free (margin);
-}
-
-void deregister () {
- display.removeWidget (handle);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget ();
- int parentHandle = parent.handle;
- int topHandle = control == null ? topHandle () : control.topHandle ();
- int point = OS.gcnew_Point (0, 0);
- if (point == 0) error (SWT.ERROR_NO_HANDLES);
- int location = OS.UIElement_TranslatePoint (topHandle, point, parentHandle);
- int x = (int) OS.Point_X (location);
- int y = (int) OS.Point_Y (location);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (location);
- int width = (int) OS.FrameworkElement_ActualWidth (topHandle);
- int height = (int) OS.FrameworkElement_ActualHeight (topHandle);
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the control that is used to fill the bounds of
- * the item when the item is a <code>SEPARATOR</code>.
- *
- * @return the control
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget ();
- return control;
-}
-
-/**
- * Returns the receiver's disabled image if it has one, or null
- * if it does not.
- * <p>
- * The disabled image is displayed when the receiver is disabled.
- * </p>
- *
- * @return the receiver's disabled image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getDisabledImage () {
- checkWidget ();
- return disabledImage;
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #isEnabled
- */
-public boolean getEnabled () {
- checkWidget ();
- return OS.UIElement_IsEnabled (handle);
-}
-
-/**
- * Returns the receiver's hot image if it has one, or null
- * if it does not.
- * <p>
- * The hot image is displayed when the mouse enters the receiver.
- * </p>
- *
- * @return the receiver's hot image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Image getHotImage () {
- checkWidget ();
- return hotImage;
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>ToolBar</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public ToolBar getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked (which some platforms draw as a
- * pushed in button). If the receiver is of any other type, this method
- * returns false.
- * </p>
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getSelection () {
- checkWidget ();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
- return OS.ToggleButton_IsChecked(handle);
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-
-Control getWidgetControl () {
- return parent;
-}
-
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget ();
- return (int) OS.FrameworkElement_ActualWidth (topHandle ());
-}
-
-void HandleChecked (int sender, int e) {
- if (!checkEvent (e)) return;
- if (ignoreSelection) return;
- postEvent (SWT.Selection);
-}
-
-void HandleClick (int sender, int e) {
- if (!checkEvent (e)) return;
- if (ignoreSelection) return;
- Event event = new Event ();
- if ((style & SWT.DROP_DOWN) != 0) {
- int mousePos = OS.Mouse_GetPosition (handle);
- int zero = OS.gcnew_Point (0, OS.FrameworkElement_ActualHeight (topHandle ()));
- int arrowPos = OS.UIElement_TranslatePoint (arrowHandle, zero, handle);
- if (OS.Point_X (mousePos) > OS.Point_X (arrowPos)) {
- event.detail = SWT.ARROW;
- int location = OS.UIElement_TranslatePoint (handle, zero, parent.handle);
- event.x = (int) OS.Point_X (location);
- event.y = (int) OS.Point_Y (location);
- OS.GCHandle_Free (location);
- }
- OS.GCHandle_Free (arrowPos);
- OS.GCHandle_Free (zero);
- OS.GCHandle_Free (mousePos);
- }
- postEvent (SWT.Selection, event);
-}
-
-void HandleUnchecked (int sender, int e) {
- if (!checkEvent (e)) return;
- if (ignoreSelection) return;
- postEvent (SWT.Selection);
-}
-
-void HandleMouseEnter (int sender, int e) {
- if (!checkEvent (e)) return;
- updateImages (getEnabled () && parent.getEnabled ());
-}
-
-void HandleMouseLeave (int sender, int e) {
- if (!checkEvent (e)) return;
- updateImages (getEnabled () && parent.getEnabled ());
-}
-
-void hookEvents() {
- super.hookEvents ();
- if ((style & SWT.SEPARATOR) != 0) return;
- if ((style & (SWT.RADIO | SWT.CHECK)) != 0) {
- int handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleChecked");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ToggleButton_Checked (handle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleUnchecked");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ToggleButton_Unchecked (handle, handler);
- OS.GCHandle_Free (handler);
- } else {
- int handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleClick");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.ButtonBase_Click (handle, handler);
- OS.GCHandle_Free (handler);
- }
- int handler = OS.gcnew_MouseEventHandler (jniRef, "HandleMouseEnter");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.UIElement_MouseEnter (handle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_MouseEventHandler (jniRef, "HandleMouseLeave");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.UIElement_MouseLeave (handle, handler);
- OS.GCHandle_Free (handler);
-}
-
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget ();
- return getEnabled () && parent.isEnabled ();
-}
-
-void register () {
- display.addWidget (handle, this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- control = null;
- toolTipText = null;
- image = disabledImage = hotImage = null;
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (handle != 0) OS.GCHandle_Free (handle);
- handle = 0;
- if (imageHandle != 0) {
- OS.GCHandle_Free (imageHandle);
- imageHandle = 0;
- }
- if (textHandle != 0) {
- OS.GCHandle_Free (textHandle);
- textHandle = 0;
- }
- if (arrowHandle != 0) {
- OS.GCHandle_Free (arrowHandle);
- arrowHandle = 0;
- }
- parent = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Sets the control that is used to fill the bounds of
- * the item when the item is a <code>SEPARATOR</code>.
- *
- * @param control the new control
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setControl (Control control) {
- checkWidget ();
- if (control != null) {
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
- }
- if ((style & SWT.SEPARATOR) == 0) return;
- if (control == null) {
- int property = OS.Control_BackgroundProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- Control oldControl = this.control;
- if (oldControl != null && !oldControl.isDisposed ()) OS.Panel_SetZIndex (oldControl.handle, 0);
- } else {
- int brush = OS.Brushes_Transparent ();
- OS.Control_Background (handle, brush);
- OS.GCHandle_Free (brush);
- int pt = OS.gcnew_Point (0, 0);
- if (pt == 0) error (SWT.ERROR_NO_HANDLES);
- int loc = OS.UIElement_TranslatePoint (handle, pt, parent.parentingHandle);
- OS.GCHandle_Free (pt);
- OS.Canvas_SetLeft (control.handle, OS.Point_X (loc));
- OS.Canvas_SetTop (control.handle, OS.Point_Y (loc));
- OS.Panel_SetZIndex (control.handle, parent.childCount);
- OS.GCHandle_Free (loc);
- }
- this.control = control;
-}
-
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise.
- * <p>
- * A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- * </p>
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setEnabled (boolean enabled) {
- checkWidget ();
- OS.UIElement_IsEnabled (handle, enabled);
- updateImages (enabled && parent.getEnabled ());
- if (arrowHandle != 0) {
- OS.UIElement_Opacity (arrowHandle, enabled ? 1 : 0.4);
- }
-}
-
-/**
- * Sets the receiver's disabled image to the argument, which may be
- * null indicating that no disabled image should be displayed.
- * <p>
- * The disabled image is displayed when the receiver is disabled.
- * </p>
- *
- * @param image the disabled image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setDisabledImage (Image image) {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return;
- if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- disabledImage = image;
- updateImages (getEnabled () && parent.getEnabled ());
-}
-
-/**
- * Sets the receiver's hot image to the argument, which may be
- * null indicating that no hot image should be displayed.
- * <p>
- * The hot image is displayed when the mouse enters the receiver.
- * </p>
- *
- * @param image the hot image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setHotImage (Image image) {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return;
- if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- hotImage = image;
- updateImages (getEnabled () && parent.getEnabled ());
-}
-
-public void setImage (Image image) {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return;
- if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- super.setImage (image);
- updateImages (getEnabled () && parent.getEnabled ());
-}
-
-/**
- * Sets the selection state of the receiver.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked (which some platforms draw as a
- * pushed in button).
- * </p>
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setSelection (boolean selected) {
- checkWidget ();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
- ignoreSelection = true;
- OS.ToggleButton_IsChecked (handle, selected);
- ignoreSelection = false;
-}
-
-/**
- * Sets the receiver's text. The string may include
- * the mnemonic character.
- * </p>
- * <p>
- * Mnemonics are indicated by an '&amp;' that causes the next
- * character to be the mnemonic. When the user presses a
- * key sequence that matches the mnemonic, a selection
- * event occurs. On most platforms, the mnemonic appears
- * underlined but may be emphasised in a platform specific
- * manner. The mnemonic indicator character '&amp;' can be
- * escaped by doubling it in the string, causing a single
- * '&amp;' to be displayed.
- * </p>
- *
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- if (string.equals (text)) return;
- super.setText (string);
- int strPtr = createDotNetString (string, true);
- if (strPtr == 0) error (SWT.ERROR_NO_HANDLES);
- OS.AccessText_Text (textHandle, strPtr);
- OS.GCHandle_Free (strPtr);
- OS.UIElement_Visibility (textHandle, string.length() == 0 && image != null ? OS.Visibility_Collapsed : OS.Visibility_Visible);
- int spacing = image != null && text.length () != 0 ? 3 : 0;
- int margin = (parent.style & SWT.RIGHT) != 0 ? OS.gcnew_Thickness (0, 0, spacing, 0) : OS.gcnew_Thickness (0, 0, 0, spacing);
- OS.FrameworkElement_Margin (imageHandle, margin);
- OS.GCHandle_Free (margin);
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String string) {
- checkWidget ();
- toolTipText = string;
- if (string != null && string.length() == 0) string = null;
- int strPtr = createDotNetString (string, false);
- OS.FrameworkElement_ToolTip (handle, strPtr);
- if (strPtr != 0) OS.GCHandle_Free (strPtr);
-}
-
-/**
- * Sets the width of the receiver, for <code>SEPARATOR</code> ToolItems.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int width) {
- checkWidget ();
- int controlHandle = control != null ? control.handle : handle;
- OS.FrameworkElement_Width (controlHandle, width);
-}
-
-void updateImages (boolean enabled) {
- if ((style & SWT.SEPARATOR) != 0) return;
- Image next = image;
- if (image != null && !enabled && disabledImage != null) next = disabledImage;
- if (image != null && enabled && hotImage != null && OS.UIElement_IsMouseOver (handle)) next = hotImage;
- OS.Image_Source (imageHandle, next != null ? next.handle : 0);
- OS.UIElement_Visibility (imageHandle, next != null ? OS.Visibility_Visible : OS.Visibility_Collapsed);
- OS.UIElement_Visibility (textHandle, next != null && text.length () == 0 ? OS.Visibility_Collapsed : OS.Visibility_Visible);
- int spacing = next != null && text.length () != 0 ? 3 : 0;
- int margin = (parent.style & SWT.RIGHT) != 0 ? OS.gcnew_Thickness (0, 0, spacing, 0) : OS.gcnew_Thickness (0, 0, 0, spacing);
- if (margin == 0) error (SWT.ERROR_NO_HANDLES);
- OS.FrameworkElement_Margin (imageHandle, margin);
- OS.GCHandle_Free (margin);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Tracker.java
deleted file mode 100644
index 884c71b1cf..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Tracker.java
+++ /dev/null
@@ -1,892 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class implement rubber banding rectangles that are
- * drawn onto a parent <code>Composite</code> or <code>Display</code>.
- * These rectangles can be specified to respond to mouse and key events
- * by either moving or resizing themselves accordingly. Trackers are
- * typically used to represent window geometries in a lightweight manner.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, UP, DOWN, RESIZE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Move, Resize</dd>
- * </dl>
- * <p>
- * Note: Rectangle move behavior is assumed unless RESIZE is specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tracker">Tracker snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Tracker extends Widget {
- Composite parent;
- boolean cancelled, stippled;
- Rectangle [] rectangles, proportions;
- Rectangle bounds;
- Cursor clientCursor;
- int resizeCursor, cursorOrientation = SWT.NONE;
- int oldX, oldY;
- int canvasHandle;
- int frame;
-
- /*
- * The following values mirror step sizes on Windows
- */
- final static int STEPSIZE_SMALL = 1;
- final static int STEPSIZE_LARGE = 9;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#RESIZE
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Tracker (Composite parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
-}
-
-/**
- * Constructs a new instance of this class given the display
- * to create it on and a style value describing its behavior
- * and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p><p>
- * Note: Currently, null can be passed in for the display argument.
- * This has the effect of creating the tracker on the currently active
- * display if there is one. If there is no current display, the
- * tracker is created on a "default" display. <b>Passing in null as
- * the display argument is not considered to be good coding style,
- * and may not be supported in a future release of SWT.</b>
- * </p>
- *
- * @param display the display to create the tracker on
- * @param style the style of control to construct
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#UP
- * @see SWT#DOWN
- * @see SWT#RESIZE
- */
-public Tracker (Display display, int style) {
- if (display == null) display = Display.getCurrent ();
- if (display == null) display = Display.getDefault ();
- if (!display.isValidThread ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- this.style = checkStyle (style);
- this.display = display;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize, typedListener);
- addListener (SWT.Move, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard, by sending
- * it one of the messages defined in the <code>KeyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #removeKeyListener
- */
-public void addKeyListener (KeyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.KeyUp,typedListener);
- addListener (SWT.KeyDown,typedListener);
-}
-
-Point adjustMoveCursor () {
- if (bounds == null) return null;
- int newX = bounds.x + bounds.width / 2;
- int newY = bounds.y;
- Point point = display.map (parent, null, newX, newY);
- display.setCursorLocation (point);
- return point;
-}
-
-Point adjustResizeCursor () {
- if (bounds == null) return null;
- int newX, newY;
- if ((cursorOrientation & SWT.LEFT) != 0) {
- newX = bounds.x;
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- newX = bounds.x + bounds.width;
- } else {
- newX = bounds.x + bounds.width / 2;
- }
- if ((cursorOrientation & SWT.UP) != 0) {
- newY = bounds.y;
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- newY = bounds.y + bounds.height;
- } else {
- newY = bounds.y + bounds.height / 2;
- }
-
- Point point = display.map (parent, null, newX, newY);
- display.setCursorLocation (point);
-
- /*
- * If the client has not provided a custom cursor then determine
- * the appropriate resize cursor.
- */
- if (clientCursor == null) {
- int newCursor = 0;
- switch (cursorOrientation) {
- case SWT.UP:
- newCursor = OS.Cursors_SizeNS ();
- break;
- case SWT.DOWN:
- newCursor = OS.Cursors_SizeNS ();
- break;
- case SWT.LEFT:
- newCursor = OS.Cursors_SizeWE ();
- break;
- case SWT.RIGHT:
- newCursor = OS.Cursors_SizeWE ();
- break;
- case SWT.LEFT | SWT.UP:
- newCursor = OS.Cursors_SizeNWSE ();
- break;
- case SWT.RIGHT | SWT.DOWN:
- newCursor = OS.Cursors_SizeNWSE ();
- break;
- case SWT.LEFT | SWT.DOWN:
- newCursor = OS.Cursors_SizeNESW ();
- break;
- case SWT.RIGHT | SWT.UP:
- newCursor = OS.Cursors_SizeNESW ();
- break;
- default:
- newCursor = OS.Cursors_SizeAll ();
- break;
- }
- OS.FrameworkElement_Cursor (canvasHandle, newCursor);
- if (resizeCursor != 0) {
- OS.GCHandle_Free (resizeCursor);
- }
- resizeCursor = newCursor;
- }
- return point;
-}
-
-static int checkStyle (int style) {
- if ((style & (SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN)) == 0) {
- style |= SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN;
- }
- return style;
-}
-
-/**
- * Stops displaying the tracker rectangles. Note that this is not considered
- * to be a cancelation by the user.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void close () {
- checkWidget ();
- if (frame != 0) OS.DispatcherFrame_Continue(frame, false);
-}
-
-Rectangle computeBounds () {
- if (rectangles.length == 0) return null;
- int xMin = rectangles [0].x;
- int yMin = rectangles [0].y;
- int xMax = rectangles [0].x + rectangles [0].width;
- int yMax = rectangles [0].y + rectangles [0].height;
-
- for (int i = 1; i < rectangles.length; i++) {
- if (rectangles [i].x < xMin) xMin = rectangles [i].x;
- if (rectangles [i].y < yMin) yMin = rectangles [i].y;
- int rectRight = rectangles [i].x + rectangles [i].width;
- if (rectRight > xMax) xMax = rectRight;
- int rectBottom = rectangles [i].y + rectangles [i].height;
- if (rectBottom > yMax) yMax = rectBottom;
- }
-
- return new Rectangle (xMin, yMin, xMax - xMin, yMax - yMin);
-}
-
-Rectangle [] computeProportions (Rectangle [] rects) {
- Rectangle [] result = new Rectangle [rects.length];
- bounds = computeBounds ();
- if (bounds != null) {
- for (int i = 0; i < rects.length; i++) {
- int x = 0, y = 0, width = 0, height = 0;
- if (bounds.width != 0) {
- x = (rects [i].x - bounds.x) * 100 / bounds.width;
- width = rects [i].width * 100 / bounds.width;
- } else {
- width = 100;
- }
- if (bounds.height != 0) {
- y = (rects [i].y - bounds.y) * 100 / bounds.height;
- height = rects [i].height * 100 / bounds.height;
- } else {
- height = 100;
- }
- result [i] = new Rectangle (x, y, width, height);
- }
- }
- return result;
-}
-
-/**
- * Draw the rectangles displayed by the tracker.
- */
-void drawRectangles () {
- Rectangle bounds = this.bounds;
- if (bounds == null) return;
- int children = OS.Panel_Children (canvasHandle);
- OS.UIElementCollection_Clear (children);
- if (parent != null) {
- Rectangle rect = parent.getClientArea ();
- rect.intersect (bounds);
- bounds = rect;
- Point pt = display.map (parent, null, bounds.x, bounds.y);
- OS.Popup_HorizontalOffset (handle, pt.x);
- OS.Popup_VerticalOffset (handle, pt.y);
- } else {
- OS.Popup_HorizontalOffset (handle, bounds.x);
- OS.Popup_VerticalOffset (handle, bounds.y);
- }
- OS.FrameworkElement_Width (handle, bounds.width);
- OS.FrameworkElement_Height (handle, bounds.height);
- int stroke, brush;
- if (stippled) {
- stroke = 3;
- int pixelFormat = OS.PixelFormats_BlackWhite ();
- byte [] buffer = {-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0};
- int image = OS.BitmapSource_Create (8, 8, 96, 96, pixelFormat, 0, buffer, buffer.length, 2);
- OS.GCHandle_Free (pixelFormat);
- brush = OS.gcnew_ImageBrush (image);
- OS.TileBrush_TileMode (brush, OS.TileMode_Tile);
- OS.TileBrush_Stretch (brush, OS.Stretch_Fill);
- OS.TileBrush_ViewportUnits (brush, OS.BrushMappingMode_Absolute);
- int rect = OS.gcnew_Rect (0, 0, OS.BitmapSource_PixelWidth(image), OS.BitmapSource_PixelHeight(image));
- OS.TileBrush_Viewport (brush, rect);
- OS.GCHandle_Free (rect);
- OS.GCHandle_Free (image);
- } else {
- stroke = 1;
- brush = OS.Brushes_Black ();
- }
- for (int i = 0; i < rectangles.length; i++) {
- int child = OS.gcnew_Rectangle ();
- OS.UIElementCollection_Add (children, child);
- OS.Shape_StrokeThickness (child, stroke);
- OS.Shape_Stroke (child, brush);
- Rectangle rect = rectangles [i];
- OS.Canvas_SetLeft (child, rect.x - bounds.x);
- OS.Canvas_SetTop (child, rect.y - bounds.y);
- OS.FrameworkElement_Width (child, rect.width);
- OS.FrameworkElement_Height (child, rect.height);
- OS.GCHandle_Free (child);
- }
- OS.GCHandle_Free (brush);
- OS.GCHandle_Free (children);
-}
-
-/**
- * Returns the bounds that are being drawn, expressed relative to the parent
- * widget. If the parent is a <code>Display</code> then these are screen
- * coordinates.
- *
- * @return the bounds of the Rectangles being drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle [] getRectangles () {
- checkWidget();
- int length = 0;
- if (rectangles != null) length = rectangles.length;
- Rectangle [] result = new Rectangle [length];
- for (int i = 0; i < length; i++) {
- Rectangle current = rectangles [i];
- result [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- return result;
-}
-
-/**
- * Returns <code>true</code> if the rectangles are drawn with a stippled line, <code>false</code> otherwise.
- *
- * @return the stippled effect of the rectangles
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getStippled () {
- checkWidget ();
- return stippled;
-}
-
-void HandleKeyUp (int sender, int e) {
- if (handle == 0) return;
- if (!sendKeyEvent (SWT.KeyUp, e, false)) return;
-}
-
-void HandleKeyDown (int sender, int e) {
- if (handle == 0) return;
- if (!sendKeyEvent (SWT.KeyDown, e, false)) return;
-
- boolean ctrlDown = (OS.Keyboard_Modifiers() & OS.ModifierKeys_Control) != 0;
- int stepSize = ctrlDown ? STEPSIZE_SMALL : STEPSIZE_LARGE;
- int key = OS.KeyEventArgs_Key(e);
- int xChange = 0, yChange = 0;
- switch (key) {
- case OS.Key_System:
- case OS.Key_Escape:
- cancelled = true;
- if (frame != 0) OS.DispatcherFrame_Continue (frame, false);
- break;
- case OS.Key_Return:
- if (frame != 0) OS.DispatcherFrame_Continue (frame, false);
- break;
- case OS.Key_Left:
- xChange = -stepSize;
- break;
- case OS.Key_Right:
- xChange = stepSize;
- break;
- case OS.Key_Up:
- yChange = -stepSize;
- break;
- case OS.Key_Down:
- yChange = stepSize;
- break;
- }
- if (xChange != 0 || yChange != 0) {
- Event event = new Event ();
- event.x = oldX + xChange;
- event.y = oldY + yChange;
- Point cursorPos;
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (xChange, yChange);
- sendEvent (SWT.Resize, event);
- if (isDisposed ()) {
- cancelled = true;
- if (frame != 0) OS.DispatcherFrame_Continue (frame, false);
- return;
- }
- drawRectangles ();
- cursorPos = adjustResizeCursor ();
- } else {
- moveRectangles (xChange, yChange);
- sendEvent (SWT.Move, event);
- if (isDisposed ()) {
- cancelled = true;
- if (frame != 0) OS.DispatcherFrame_Continue (frame, false);
- return;
- }
- drawRectangles ();
- cursorPos = adjustMoveCursor ();
- }
- oldX = cursorPos.x;
- oldY = cursorPos.y;
- }
-}
-
-void HandleMouseUp (int sender, int e) {
- if (handle == 0) return;
- if (!sendMouseEvent (SWT.MouseUp, e, false)) return;
- if (frame != 0) OS.DispatcherFrame_Continue (frame, false);
-}
-
-void HandleMouseDown (int sender, int e) {
- if (handle == 0) return;
- if (!sendMouseEvent (SWT.MouseDown, e, false)) return;
- if (frame != 0) OS.DispatcherFrame_Continue (frame, false);
-}
-
-void HandleMouseMove (int sender, int e) {
- if (handle == 0) return;
- if (!sendMouseEvent (SWT.MouseMove, e, false)) return;
- int pointCanvas = OS.MouseEventArgs_GetPosition (e, canvasHandle);
- int point = OS.Visual_PointToScreen (canvasHandle, pointCanvas);
- int newX = (int) OS.Point_X (point);
- int newY = (int) OS.Point_Y (point);
- OS.GCHandle_Free (pointCanvas);
- OS.GCHandle_Free (point);
- if (newX != oldX || newY != oldY) {
- Event event = new Event ();
- event.x = newX;
- event.y = newY;
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (newX - oldX, newY - oldY);
- sendEvent (SWT.Resize, event);
- if (isDisposed ()) {
- cancelled = true;
- if (frame != 0) OS.DispatcherFrame_Continue (frame, false);
- }
- drawRectangles ();
- Point cursorPos = adjustResizeCursor ();
- if (cursorPos != null) {
- newX = cursorPos.x;
- newY = cursorPos.y;
- }
- } else {
- moveRectangles (newX - oldX, newY - oldY);
- sendEvent (SWT.Move, event);
- if (isDisposed ()) {
- cancelled = true;
- if (frame != 0) OS.DispatcherFrame_Continue (frame, false);
- }
- drawRectangles ();
- }
- oldX = newX;
- oldY = newY;
- }
-}
-
-void moveRectangles (int xChange, int yChange) {
- if (bounds == null) return;
- if (xChange < 0 && ((style & SWT.LEFT) == 0)) xChange = 0;
- if (xChange > 0 && ((style & SWT.RIGHT) == 0)) xChange = 0;
- if (yChange < 0 && ((style & SWT.UP) == 0)) yChange = 0;
- if (yChange > 0 && ((style & SWT.DOWN) == 0)) yChange = 0;
- if (xChange == 0 && yChange == 0) return;
- bounds.x += xChange; bounds.y += yChange;
- for (int i = 0; i < rectangles.length; i++) {
- rectangles [i].x += xChange;
- rectangles [i].y += yChange;
- }
-}
-
-/**
- * Displays the Tracker rectangles for manipulation by the user. Returns when
- * the user has either finished manipulating the rectangles or has cancelled the
- * Tracker.
- *
- * @return <code>true</code> if the user did not cancel the Tracker, <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean open () {
- checkWidget ();
- if (rectangles == null) return false;
- if (rectangles.length == 0) return false;
- cancelled = false;
-
- /*
- * If exactly one of UP/DOWN is specified as a style then set the cursor
- * orientation accordingly (the same is done for LEFT/RIGHT styles below).
- */
- int vStyle = style & (SWT.UP | SWT.DOWN);
- if (vStyle == SWT.UP || vStyle == SWT.DOWN) {
- cursorOrientation |= vStyle;
- }
- int hStyle = style & (SWT.LEFT | SWT.RIGHT);
- if (hStyle == SWT.LEFT || hStyle == SWT.RIGHT) {
- cursorOrientation |= hStyle;
- }
-
- jniRef = OS.NewGlobalRef (this);
- if (jniRef == 0) error (SWT.ERROR_NO_HANDLES);
- handle = OS.gcnew_Popup ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.Popup_AllowsTransparency (handle, true);
-
- canvasHandle = OS.gcnew_Canvas ();
- if (canvasHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.Popup_Child (handle, canvasHandle);
- OS.UIElement_IsHitTestVisible (canvasHandle, false);
- OS.FrameworkElement_FocusVisualStyle (canvasHandle, 0);
- if (clientCursor != null) {
- OS.FrameworkElement_Cursor (canvasHandle, clientCursor.handle);
- }
-
- drawRectangles ();
-
- OS.Popup_IsOpen (handle, true);
- OS.UIElement_Focusable (canvasHandle, true);
- OS.UIElement_Focus (canvasHandle);
- OS.UIElement_CaptureMouse (canvasHandle);
-
- boolean mouseDown = OS.Mouse_LeftButton() == OS.MouseButtonState_Pressed;
- Point cursorPos;
- if (mouseDown) {
- int pointCanvas = OS.Mouse_GetPosition (canvasHandle);
- int point = OS.Visual_PointToScreen (canvasHandle, pointCanvas);
- cursorPos = new Point ((int) OS.Point_X (point), (int) OS.Point_Y (point));
- OS.GCHandle_Free (pointCanvas);
- OS.GCHandle_Free (point);
- } else {
- if ((style & SWT.RESIZE) != 0) {
- cursorPos = adjustResizeCursor ();
- } else {
- cursorPos = adjustMoveCursor ();
- }
- }
- oldX = cursorPos.x;
- oldY = cursorPos.y;
-
- int handler = OS.gcnew_KeyEventHandler (jniRef, "HandleKeyDown");
- OS.UIElement_KeyDown (canvasHandle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_KeyEventHandler (jniRef, "HandleKeyUp");
- OS.UIElement_KeyUp (canvasHandle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_MouseEventHandler (jniRef, "HandleMouseMove");
- OS.UIElement_MouseMove (canvasHandle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_MouseButtonEventHandler (jniRef, "HandleMouseUp");
- OS.UIElement_MouseUp (canvasHandle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_MouseButtonEventHandler (jniRef, "HandleMouseDown");
- OS.UIElement_MouseDown (canvasHandle, handler);
- OS.GCHandle_Free (handler);
-
- /* Tracker behaves like a Dialog with its own OS event loop. */
- frame = OS.gcnew_DispatcherFrame ();
- OS.Dispatcher_PushFrame (frame);
-
- if (resizeCursor != 0) {
- OS.GCHandle_Free (resizeCursor);
- resizeCursor = 0;
- }
- OS.UIElement_ReleaseMouseCapture (canvasHandle);
- OS.Popup_IsOpen (handle, false);
- OS.GCHandle_Free (canvasHandle);
- OS.GCHandle_Free (handle);
- if (frame != 0) OS.GCHandle_Free (frame);
- OS.DeleteGlobalRef (jniRef);
- jniRef = handle = canvasHandle = frame = 0;
-
- return !cancelled;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Resize, listener);
- eventTable.unhook (SWT.Move, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #addKeyListener
- */
-public void removeKeyListener(KeyListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.KeyUp, listener);
- eventTable.unhook (SWT.KeyDown, listener);
-}
-
-void resizeRectangles (int xChange, int yChange) {
- if (bounds == null) return;
- /*
- * If the cursor orientation has not been set in the orientation of
- * this change then try to set it here.
- */
- if (xChange < 0 && ((style & SWT.LEFT) != 0) && ((cursorOrientation & SWT.RIGHT) == 0)) {
- cursorOrientation |= SWT.LEFT;
- }
- if (xChange > 0 && ((style & SWT.RIGHT) != 0) && ((cursorOrientation & SWT.LEFT) == 0)) {
- cursorOrientation |= SWT.RIGHT;
- }
- if (yChange < 0 && ((style & SWT.UP) != 0) && ((cursorOrientation & SWT.DOWN) == 0)) {
- cursorOrientation |= SWT.UP;
- }
- if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) {
- cursorOrientation |= SWT.DOWN;
- }
-
- /*
- * If the bounds will flip about the x or y axis then apply the adjustment
- * up to the axis (ie.- where bounds width/height becomes 0), change the
- * cursor's orientation accordingly, and flip each Rectangle's origin (only
- * necessary for > 1 Rectangles)
- */
- if ((cursorOrientation & SWT.LEFT) != 0) {
- if (xChange > bounds.width) {
- if ((style & SWT.RIGHT) == 0) return;
- cursorOrientation |= SWT.RIGHT;
- cursorOrientation &= ~SWT.LEFT;
- bounds.x += bounds.width;
- xChange -= bounds.width;
- bounds.width = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.x = 100 - proportion.x - proportion.width;
- }
- }
- }
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- if (bounds.width < -xChange) {
- if ((style & SWT.LEFT) == 0) return;
- cursorOrientation |= SWT.LEFT;
- cursorOrientation &= ~SWT.RIGHT;
- xChange += bounds.width;
- bounds.width = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.x = 100 - proportion.x - proportion.width;
- }
- }
- }
- }
- if ((cursorOrientation & SWT.UP) != 0) {
- if (yChange > bounds.height) {
- if ((style & SWT.DOWN) == 0) return;
- cursorOrientation |= SWT.DOWN;
- cursorOrientation &= ~SWT.UP;
- bounds.y += bounds.height;
- yChange -= bounds.height;
- bounds.height = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.y = 100 - proportion.y - proportion.height;
- }
- }
- }
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- if (bounds.height < -yChange) {
- if ((style & SWT.UP) == 0) return;
- cursorOrientation |= SWT.UP;
- cursorOrientation &= ~SWT.DOWN;
- yChange += bounds.height;
- bounds.height = 0;
- if (proportions.length > 1) {
- for (int i = 0; i < proportions.length; i++) {
- Rectangle proportion = proportions [i];
- proportion.y = 100 - proportion.y - proportion.height;
- }
- }
- }
- }
-
- // apply the bounds adjustment
- if ((cursorOrientation & SWT.LEFT) != 0) {
- bounds.x += xChange;
- bounds.width -= xChange;
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- bounds.width += xChange;
- }
- if ((cursorOrientation & SWT.UP) != 0) {
- bounds.y += yChange;
- bounds.height -= yChange;
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- bounds.height += yChange;
- }
-
- Rectangle [] newRects = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle proportion = proportions[i];
- newRects[i] = new Rectangle (
- proportion.x * bounds.width / 100 + bounds.x,
- proportion.y * bounds.height / 100 + bounds.y,
- proportion.width * bounds.width / 100,
- proportion.height * bounds.height / 100);
- }
- rectangles = newRects;
-}
-
-/**
- * Sets the <code>Cursor</code> of the Tracker. If this cursor is <code>null</code>
- * then the cursor reverts to the default.
- *
- * @param newCursor the new <code>Cursor</code> to display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCursor(Cursor newCursor) {
- checkWidget();
- clientCursor = newCursor;
- if (canvasHandle != 0) {
- OS.FrameworkElement_Cursor (canvasHandle, clientCursor != null ? clientCursor.handle : 0);
- }
-}
-
-/**
- * Specifies the rectangles that should be drawn, expressed relative to the parent
- * widget. If the parent is a Display then these are screen coordinates.
- *
- * @param rectangles the bounds of the rectangles to be drawn
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the set of rectangles is null or contains a null rectangle</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setRectangles (Rectangle [] rectangles) {
- checkWidget ();
- if (rectangles == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = rectangles.length;
- this.rectangles = new Rectangle [length];
- for (int i = 0; i < length; i++) {
- Rectangle current = rectangles [i];
- if (current == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.rectangles [i] = new Rectangle (current.x, current.y, current.width, current.height);
- }
- proportions = computeProportions (rectangles);
-}
-
-/**
- * Changes the appearance of the line used to draw the rectangles.
- *
- * @param stippled <code>true</code> if rectangle should appear stippled
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setStippled (boolean stippled) {
- checkWidget ();
- this.stippled = stippled;
- if (handle != 0) {
- //TODO CHANGE RECT BRUSH
- }
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TrayItem.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TrayItem.java
deleted file mode 100644
index 15db30ef73..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TrayItem.java
+++ /dev/null
@@ -1,447 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.internal.win32.*;
-
-/**
- * Instances of this class represent icons that can be placed on the
- * system tray or task bar status area.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, MenuDetect, Selection</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tray">Tray, TrayItem snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.0
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TrayItem extends Item {
- Tray parent;
- int id;
- ToolTip toolTip;
- String toolTipText;
- boolean visible = true;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tray</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TrayItem (Tray parent, int style) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
- createWidget ();
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the receiver is selected
- * <code>widgetDefaultSelected</code> is called when the receiver is double-clicked
- * </p>
- *
- * @param listener the listener which should be notified when the receiver is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the platform-specific context menu trigger
- * has occurred, by sending it one of the messages defined in
- * the <code>MenuDetectListener</code> interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #removeMenuDetectListener
- *
- * @since 3.3
- */
-public void addMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MenuDetect, typedListener);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createHandle () {
- handle = OS.gcnew_NotifyIcon ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.NotifyIcon_Visible (handle, true);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-Point getLocation () {
- return display.getCursorLocation ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Tray</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public Tray getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's tool tip, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public ToolTip getToolTip () {
- checkWidget ();
- return toolTip;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-
-/**
- * Returns <code>true</code> if the receiver is visible and
- * <code>false</code> otherwise.
- *
- * @return the receiver's visibility
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getVisible () {
- checkWidget ();
- return visible;
-}
-
-void HandleDoubleClick (int sender, int e) {
- if (!checkEvent (e)) return;
- if (hooks (SWT.DefaultSelection)) {
- postEvent (SWT.DefaultSelection);
- }
- display.wakeThread ();
-}
-
-void HandleMouseDown (int sender, int e) {
- if (!checkEvent (e)) return;
- if (hooks (SWT.Selection)) {
- postEvent (SWT.Selection);
- }
- display.wakeThread ();
-}
-
-void HandleMouseUp (int sender, int e) {
- if (!checkEvent (e)) return;
- if (hooks (SWT.MenuDetect)) {
- int button = OS.FormsMouseEventArgs_Button (e);
- if (button == OS.MouseButtons_Right) sendEvent (SWT.MenuDetect);
- }
- display.wakeThread ();
-}
-
-void hookEvents() {
- super.hookEvents ();
- int handler = OS.gcnew_FormsMouseEventHandler (jniRef, "HandleMouseDown");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.NotifyIcon_MouseDown (handle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_FormsMouseEventHandler (jniRef, "HandleMouseUp");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.NotifyIcon_MouseUp (handle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_EventHandler (jniRef, "HandleDoubleClick");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.NotifyIcon_DoubleClick (handle, handler);
- OS.GCHandle_Free (handler);
-}
-
-void releaseHandle () {
- setImage (null);
- super.releaseHandle ();
- if (handle != 0) OS.GCHandle_Free (handle);
- handle = 0;
- parent = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the platform-specific context menu trigger has
- * occurred.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MenuDetectListener
- * @see #addMenuDetectListener
- *
- * @since 3.3
- */
-public void removeMenuDetectListener (MenuDetectListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MenuDetect, listener);
-}
-
-/**
- * Sets the receiver's image.
- *
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- super.setImage (image);
- if (image != null) {
- int format = OS.PixelFormats_Bgra32 ();
- int newImage = OS.gcnew_FormatConvertedBitmap (image.handle, format, OS.BitmapSource_Palette(image.handle), 0);
- int depth = OS.PixelFormat_BitsPerPixel (format);
- OS.GCHandle_Free (format);
- int width = OS.BitmapSource_PixelWidth (newImage);
- int height = OS.BitmapSource_PixelHeight (newImage);
- int scanlinePad = 4;
- int bytesPerLine = (((width * depth + 7) / 8) + (scanlinePad - 1)) / scanlinePad * scanlinePad;
- byte[] buffer = new byte [bytesPerLine * height];
- int rect = OS.Int32Rect_Empty ();
- OS.BitmapSource_CopyPixels (newImage, rect, buffer, buffer.length, bytesPerLine);
- OS.GCHandle_Free (rect);
- OS.GCHandle_Free (newImage);
- int bitmap = OS.gcnew_Bitmap (width, height, bytesPerLine, Win32.PixelFormat_Format32bppArgb, buffer);//TODO
- int hIcon = OS.Bitmap_GetHicon (bitmap);
- OS.GCHandle_Free (bitmap);
- int icon = OS.Icon_FromHandle (hIcon);
- OS.NotifyIcon_Icon (handle, icon);
- OS.GCHandle_Free (icon);
- } else {
- OS.NotifyIcon_Icon (handle, 0);
- }
-}
-
-/**
- * Sets the receiver's tool tip to the argument, which
- * may be null indicating that no tool tip should be shown.
- *
- * @param toolTip the new tool tip (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setToolTip (ToolTip toolTip) {
- checkWidget ();
- this.toolTip = toolTip;
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setToolTipText (String value) {
- checkWidget ();
- toolTipText = value;
- int strPtr = createDotNetString (value, false);
- OS.NotifyIcon_Text (handle, strPtr);
- OS.GCHandle_Free (strPtr);
-}
-
-/**
- * Makes the receiver visible if the argument is <code>true</code>,
- * and makes it invisible otherwise.
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setVisible (boolean visible) {
- checkWidget ();
- if (this.visible == visible) return;
- if (visible) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the show
- * event. If this happens, just return.
- */
- sendEvent (SWT.Show);
- if (isDisposed ()) return;
- }
- this.visible = visible;
- OS.NotifyIcon_Visible (handle, visible);
- if (!visible) sendEvent (SWT.Hide);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Tree.java
deleted file mode 100644
index 72d06c0c46..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Tree.java
+++ /dev/null
@@ -1,2406 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class provide a selectable user interface object
- * that displays a hierarchy of items and issues notification when an
- * item in the hierarchy is selected.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TreeItem</code>.
- * </p><p>
- * Style <code>VIRTUAL</code> is used to create a <code>Tree</code> whose
- * <code>TreeItem</code>s are to be populated by the client on an on-demand basis
- * instead of up-front. This can provide significant performance improvements for
- * trees that are very large or for which <code>TreeItem</code> population is
- * expensive (for example, retrieving values from an external source).
- * </p><p>
- * Here is an example of using a <code>Tree</code> with style <code>VIRTUAL</code>:
- * <code><pre>
- * final Tree tree = new Tree(parent, SWT.VIRTUAL | SWT.BORDER);
- * tree.setItemCount(20);
- * tree.addListener(SWT.SetData, new Listener() {
- * public void handleEvent(Event event) {
- * TreeItem item = (TreeItem)event.item;
- * TreeItem parentItem = item.getParentItem();
- * String text = null;
- * if (parentItem == null) {
- * text = "node " + tree.indexOf(item);
- * } else {
- * text = parentItem.getText() + " - " + parentItem.indexOf(item);
- * }
- * item.setText(text);
- * System.out.println(text);
- * item.setItemCount(10);
- * }
- * });
- * </pre></code>
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not normally make sense to add <code>Control</code> children to
- * it, or set a layout on it, unless implementing something like a cell
- * editor.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, VIRTUAL, NO_SCROLL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection, Collapse, Expand, SetData, MeasureItem, EraseItem, PaintItem</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles SINGLE and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Tree extends Composite {
- int gvColumns, parentingHandle, headerTemplate;
- int columnCount, itemCount;
- TreeItem anchor, lastSelection, unselect, reselect;
- TreeColumn [] columns;
- byte headerVisibility = OS.Visibility_Collapsed;
- boolean ignoreSelection, shiftDown, ctrlDown;
-
- static final String HEADER_PART_NAME = "SWT_PART_HEADER";
- static final String SCROLLVIEWER_PART_NAME = "SWT_PART_SCROLLVIEWER";
- static final String CHECKBOX_PART_NAME = "SWT_PART_CHECKBOX";
- static final String IMAGE_PART_NAME = "SWT_PART_IMAGE";
- static final String TEXT_PART_NAME = "SWT_PART_TEXT";
- static final String CONTENTPANEL_PART_NAME = "SWT_PART_CONTENTPANEL";
- static final String RENDER_PANEL_NAME = "SWT_PART_RENDERPANEL";
-
- static String scrollViewerStyle = "<Style TargetType=\"ScrollViewer\" " +
- "xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" " +
- "xmlns:s=\"clr-namespace:System;assembly=mscorlib\" " +
- "xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">" +
- "<Setter Property=\"UIElement.Focusable\" Value=\"False\"/>" +
- "<Setter Property=\"Control.Template\">" +
- "<Setter.Value>" +
- "<ControlTemplate TargetType=\"ScrollViewer\">" +
- "<Grid Background=\"{TemplateBinding Control.Background}\" SnapsToDevicePixels=\"True\">" +
- "<Grid.ColumnDefinitions>" +
- "<ColumnDefinition Width=\"*\" />" +
- "<ColumnDefinition Width=\"Auto\" />" +
- "</Grid.ColumnDefinitions>" +
- "<Grid.RowDefinitions>" +
- "<RowDefinition Height=\"*\" />" +
- "<RowDefinition Height=\"Auto\" />" +
- "</Grid.RowDefinitions>" +
- "<DockPanel Margin=\"{TemplateBinding Control.Padding}\">" +
- "<ScrollViewer HorizontalScrollBarVisibility=\"Hidden\" VerticalScrollBarVisibility=\"Hidden\" Focusable=\"False\" DockPanel.Dock=\"Top\">" +
- "<GridViewHeaderRowPresenter Name=\"SWT_PART_HEADER\" Margin=\"2,0,2,0\" Visibility=\"Collapsed\" ColumnHeaderToolTip=\"{x:Null}\" " +
- "ColumnHeaderContainerStyle=\"{x:Null}\" SnapsToDevicePixels=\"{TemplateBinding UIElement.SnapsToDevicePixels}\" " +
- "AllowsColumnReorder=\"True\" ColumnHeaderTemplate=\"{x:Null}\" ColumnHeaderContextMenu=\"{x:Null}\">" +
- "<GridViewHeaderRowPresenter.Columns>" +
- "<TemplateBinding Property=\"GridViewHeaderRowPresenter.Columns\"/>" +
- "</GridViewHeaderRowPresenter.Columns>" +
- "</GridViewHeaderRowPresenter>" +
- "</ScrollViewer>" +
- "<ScrollContentPresenter VirtualizingStackPanel.IsVirtualizing=\"True\" CanVerticallyScroll=\"False\" " +
- "CanHorizontallyScroll=\"False\" Name=\"PART_ScrollContentPresenter\" " +
- "SnapsToDevicePixels=\"{TemplateBinding UIElement.SnapsToDevicePixels}\" " +
- "ContentTemplate=\"{TemplateBinding ContentControl.ContentTemplate}\" " +
- "CanContentScroll=\"{TemplateBinding ScrollViewer.CanContentScroll}\" " +
- "Content=\"{TemplateBinding ContentControl.Content}\" KeyboardNavigation.DirectionalNavigation=\"Local\" />" +
- "</DockPanel>" +
- "<ScrollBar Value=\"{TemplateBinding HorizontalOffset}\" Maximum=\"{TemplateBinding ScrollViewer.ScrollableWidth}\" " +
- "Visibility=\"{TemplateBinding ScrollViewer.ComputedHorizontalScrollBarVisibility}\" Name=\"PART_HorizontalScrollBar\" " +
- "Cursor=\"Arrow\" Minimum=\"0\" Orientation=\"Horizontal\" Grid.Row=\"1\" " +
- "ViewportSize=\"{TemplateBinding ViewportWidth}\"/>" +
- "<ScrollBar Value=\"{TemplateBinding VerticalOffset}\" Maximum=\"{TemplateBinding ScrollViewer.ScrollableHeight}\" " +
- "Visibility=\"{TemplateBinding ScrollViewer.ComputedVerticalScrollBarVisibility}\" Name=\"PART_VerticalScrollBar\" " +
- "Cursor=\"Arrow\" Minimum=\"0\" Orientation=\"Vertical\" Grid.Column=\"1\" " +
- "ViewportSize=\"{TemplateBinding ViewportHeight}\" />" +
- "<DockPanel Background=\"{x:Null}\" LastChildFill=\"False\" Grid.Column=\"1\" Grid.Row=\"1\">" +
- "<Rectangle Width=\"1\" Visibility=\"{TemplateBinding ScrollViewer.ComputedVerticalScrollBarVisibility}\" " +
- "Fill=\"#FFFFFFFF\" DockPanel.Dock=\"Left\" />" +
- "<Rectangle Height=\"1\" Visibility=\"{TemplateBinding ScrollViewer.ComputedHorizontalScrollBarVisibility}\" " +
- "Fill=\"#FFFFFFFF\" DockPanel.Dock=\"Top\" />" +
- "</DockPanel>" +
- "</Grid>" +
- "</ControlTemplate>" +
- "</Setter.Value>" +
- "</Setter>" +
- "</Style>";
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#SINGLE
- * @see SWT#MULTI
- * @see SWT#CHECK
- * @see SWT#FULL_SELECTION
- * @see SWT#VIRTUAL
- * @see SWT#NO_SCROLL
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Tree (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- /*
- * Feature in Windows. Even when WS_HSCROLL or
- * WS_VSCROLL is not specified, Windows creates
- * trees and tables with scroll bars. The fix
- * is to set H_SCROLL and V_SCROLL.
- *
- * NOTE: This code appears on all platforms so that
- * applications have consistent scroll bar behavior.
- */
- if ((style & SWT.NO_SCROLL) == 0) {
- style |= SWT.H_SCROLL | SWT.V_SCROLL;
- }
- /* WPF is always FULL_SELECTION */
- style |= SWT.FULL_SELECTION;
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the user changes the receiver's selection, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * When <code>widgetSelected</code> is called, the item field of the event object is valid.
- * If the receiver has the <code>SWT.CHECK</code> style and the check selection changes,
- * the event object detail field contains the value <code>SWT.CHECK</code>.
- * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked.
- * The item field of the event object is valid for default selection, but the detail field is not used.
- * </p>
- *
- * @param listener the listener which should be notified when the user changes the receiver's selection
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection, typedListener);
- addListener (SWT.DefaultSelection, typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an item in the receiver is expanded or collapsed
- * by sending it one of the messages defined in the <code>TreeListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TreeListener
- * @see #removeTreeListener
- */
-public void addTreeListener (TreeListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Expand, typedListener);
- addListener (SWT.Collapse, typedListener);
-}
-
-int backgroundHandle () {
- return parentingHandle;
-}
-
-boolean checkData (TreeItem item) {
- if ((style & SWT.VIRTUAL) == 0) return true;
- if (!item.cached) {
- item.cached = true;
- int parentItem = OS.FrameworkElement_Parent (item.handle);
- int items = OS.ItemsControl_Items (parentItem);
- int index = OS.ItemCollection_IndexOf (items, item.handle);
- OS.GCHandle_Free (items);
- OS.GCHandle_Free (parentItem);
- Event event = new Event ();
- event.item = item;
- event.index = index;
- sendEvent (SWT.SetData, event);
- if (isDisposed () || item.isDisposed ()) return false;
- }
- return true;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Clears the item at the given zero-relative index in the receiver.
- * The text, icon and other attributes of the item are set to the default
- * value. If the tree was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param index the index of the item to clear
- * @param all <code>true</code> if all child items of the indexed item should be
- * cleared recursively, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clear (int index, boolean all) {
- checkWidget ();
- if (index < 0 || index >= itemCount) SWT.error (SWT.ERROR_INVALID_RANGE);
- clear (handle, index, all);
-}
-
-void clear (int parentHandle, int index, boolean all) {
- int items = OS.ItemsControl_Items (parentHandle);
- TreeItem item = getItem (items, index, false);
- if (item != null) {
- item.clear ();
- if (all) clearAll (item, true);
- }
- OS.GCHandle_Free (items);
-}
-
-/**
- * Clears all the items in the receiver. The text, icon and other
- * attributes of the items are set to their default values. If the
- * tree was created with the <code>SWT.VIRTUAL</code> style, these
- * attributes are requested again as needed.
- *
- * @param all <code>true</code> if all child items should be cleared
- * recursively, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clearAll (boolean all) {
- checkWidget ();
- clearAll (null, all);
-}
-
-void clearAll (TreeItem parentItem, boolean all) {
- int count = parentItem != null ? parentItem.itemCount : itemCount;
- int parentHandle = parentItem != null ? parentItem.handle : handle;
- int items = OS.ItemsControl_Items (parentHandle);
- for (int i=0; i<count; i++) {
- TreeItem item = getItem (items, i, false);
- if (item != null) {
- item.clear ();
- if (all) clearAll (item, true);
- }
- }
- OS.GCHandle_Free (items);
-}
-
-int createCellTemplate (int index) {
- int template = OS.gcnew_DataTemplate ();
- int renderPanelType = OS.SWTDockPanel_typeid ();
- int renderPanelName = createDotNetString(RENDER_PANEL_NAME, false);
- int onRenderNode = OS.gcnew_FrameworkElementFactory (renderPanelType, renderPanelName);
- OS.GCHandle_Free(renderPanelName);
- OS.GCHandle_Free (renderPanelType);
- int jniRefProperty = OS.SWTDockPanel_JNIRefProperty ();
- OS.FrameworkElementFactory_SetValueInt (onRenderNode, jniRefProperty, jniRef);
- OS.GCHandle_Free (jniRefProperty);
- int contentPanelName = createDotNetString (CONTENTPANEL_PART_NAME, false);
- int contentPanelType = OS.StackPanel_typeid ();
- int cellContentNode = OS.gcnew_FrameworkElementFactory (contentPanelType, contentPanelName);
- OS.GCHandle_Free (contentPanelType);
- OS.GCHandle_Free (contentPanelName);
- int clipProperty = OS.UIElement_ClipToBoundsProperty ();
- OS.FrameworkElementFactory_SetValue (cellContentNode, clipProperty, true);
- OS.GCHandle_Free (clipProperty);
- int orientationProperty = OS.StackPanel_OrientationProperty ();
- OS.FrameworkElementFactory_SetValueOrientation (cellContentNode, orientationProperty, OS.Orientation_Horizontal);
- OS.GCHandle_Free (orientationProperty);
-
-
-// int vert = OS.FrameworkElement_VerticalAlignmentProperty();
-// OS.FrameworkElementFactory_SetValueVerticalAlignment(onRenderNode, vert, OS.VerticalAlignment_Stretch);
-// OS.GCHandle_Free (vert);
-//
-// int dp = OS.Panel_BackgroundProperty();
-// int red = OS.Brushes_Red();
-// int navy = OS.Brushes_Navy();
-// OS.FrameworkElementFactory_SetValue(cellContentNode, dp, red);
-// OS.FrameworkElementFactory_SetValue(onRenderNode, dp, navy);
-// OS.GCHandle_Free (dp);
-// OS.GCHandle_Free (red);
-// OS.GCHandle_Free (navy);
-
-
- if (index == 0 && (style & SWT.CHECK) != 0) {
- int checkBoxType = OS.CheckBox_typeid ();
- int checkBoxName = createDotNetString (CHECKBOX_PART_NAME, false);
- int checkBoxNode = OS.gcnew_FrameworkElementFactory (checkBoxType, checkBoxName);
- int verticalAlignmentProperty = OS.FrameworkElement_VerticalAlignmentProperty ();
- OS.FrameworkElementFactory_SetValueVerticalAlignment (checkBoxNode, verticalAlignmentProperty, OS.VerticalAlignment_Center);
- int marginProperty = OS.FrameworkElement_MarginProperty ();
- int thickness = OS.gcnew_Thickness (0,0,4,0);
- OS.FrameworkElementFactory_SetValue (checkBoxNode, marginProperty, thickness);
- OS.FrameworkElementFactory_AppendChild (cellContentNode, checkBoxNode);
- OS.GCHandle_Free (thickness);
- OS.GCHandle_Free (marginProperty);
- OS.GCHandle_Free (verticalAlignmentProperty);
- OS.GCHandle_Free (checkBoxName);
- OS.GCHandle_Free (checkBoxNode);
- OS.GCHandle_Free (checkBoxType);
- }
- int textType = OS.TextBlock_typeid ();
- int textName = createDotNetString (TEXT_PART_NAME, false);
- int textNode = OS.gcnew_FrameworkElementFactory (textType, textName);
- OS.GCHandle_Free (textName);
- OS.GCHandle_Free (textType);
- int verticalAlignmentProperty = OS.FrameworkElement_VerticalAlignmentProperty ();
- OS.FrameworkElementFactory_SetValueVerticalAlignment (textNode, verticalAlignmentProperty, OS.VerticalAlignment_Center);
- OS.GCHandle_Free (verticalAlignmentProperty);
- int imageType = OS.Image_typeid ();
- int imageName = createDotNetString (IMAGE_PART_NAME, false);
- int imageNode = OS.gcnew_FrameworkElementFactory (imageType, imageName);
- OS.GCHandle_Free (imageName);
- OS.GCHandle_Free (imageType);
- int marginProperty = OS.FrameworkElement_MarginProperty ();
- int thickness = OS.gcnew_Thickness (0,0,4,0);
- OS.FrameworkElementFactory_SetValue (imageNode, marginProperty, thickness);
- OS.GCHandle_Free (marginProperty);
- OS.GCHandle_Free (thickness);
- int stretchProperty = OS.Image_StretchProperty ();
- OS.FrameworkElementFactory_SetValueStretch(imageNode, stretchProperty, OS.Stretch_None);
- OS.GCHandle_Free(stretchProperty);
- OS.FrameworkElementFactory_AppendChild (cellContentNode, imageNode);
- OS.GCHandle_Free (imageNode);
- OS.FrameworkElementFactory_AppendChild (cellContentNode, textNode);
- OS.GCHandle_Free (textNode);
- OS.FrameworkElementFactory_AppendChild (onRenderNode, cellContentNode);
- OS.GCHandle_Free (cellContentNode);
- OS.FrameworkTemplate_VisualTree (template, onRenderNode);
- OS.GCHandle_Free (onRenderNode);
- return template;
-}
-
-int createControlTemplate () {
- int template = OS.gcnew_ControlTemplate ();
- int borderType = OS.Border_typeid ();
- int borderNode = OS.gcnew_FrameworkElementFactory (borderType);
- int brushProperty = OS.Control_BorderBrushProperty ();
- int brushBinding = OS.gcnew_TemplateBindingExtension (brushProperty);
- OS.FrameworkElementFactory_SetValue (borderNode, brushProperty, brushBinding);
- int thicknessProperty = OS.Control_BorderThicknessProperty ();
- int thicknessBinding = OS.gcnew_TemplateBindingExtension (thicknessProperty);
- OS.FrameworkElementFactory_SetValue (borderNode, thicknessProperty, thicknessBinding);
- int scrollViewerType = OS.ScrollViewer_typeid ();
- int scrollViewerName = createDotNetString (SCROLLVIEWER_PART_NAME, false);
- int scrollViewerNode = OS.gcnew_FrameworkElementFactory (scrollViewerType, scrollViewerName);
- int itemsPresenterType = OS.ItemsPresenter_typeid ();
- int itemsPresenterNode = OS.gcnew_FrameworkElementFactory (itemsPresenterType);
- OS.FrameworkElementFactory_AppendChild (borderNode, scrollViewerNode);
- OS.FrameworkElementFactory_AppendChild (scrollViewerNode, itemsPresenterNode);
- int scrollStyle = createDotNetString(scrollViewerStyle, false);
- int stringReader = OS.gcnew_StringReader (scrollStyle);
- int xmlReader = OS.XmlReader_Create (stringReader);
- int xamlStyle = OS.XamlReader_Load (xmlReader);
- int styleProperty = OS.FrameworkElement_StyleProperty();
- OS.FrameworkElementFactory_SetValue (scrollViewerNode, styleProperty, xamlStyle);
- int columnsProperty = OS.GridViewRowPresenterBase_ColumnsProperty ();
- OS.FrameworkElementFactory_SetValue (scrollViewerNode, columnsProperty, gvColumns);
- OS.FrameworkTemplate_VisualTree (template, borderNode);
- OS.GCHandle_Free (brushProperty);
- OS.GCHandle_Free (thicknessProperty);
- OS.GCHandle_Free (brushBinding);
- OS.GCHandle_Free (thicknessBinding);
- OS.GCHandle_Free (scrollStyle);
- OS.GCHandle_Free (stringReader);
- OS.GCHandle_Free (xmlReader);
- OS.GCHandle_Free (styleProperty);
- OS.GCHandle_Free (columnsProperty);
- OS.GCHandle_Free (xamlStyle);
- OS.GCHandle_Free (scrollViewerType);
- OS.GCHandle_Free (scrollViewerName);
- OS.GCHandle_Free (scrollViewerNode);
- OS.GCHandle_Free (borderType);
- OS.GCHandle_Free (borderNode);
- OS.GCHandle_Free (itemsPresenterType);
- OS.GCHandle_Free (itemsPresenterNode);
- return template;
-}
-
-void createHandle () {
- parentingHandle = OS.gcnew_Canvas ();
- if (parentingHandle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.SINGLE) != 0) {
- handle = OS.gcnew_TreeView ();
- } else {
- handle = OS.gcnew_SWTTreeView (jniRef);
- }
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.Canvas_SetLeft (handle, 0);
- OS.Canvas_SetTop (handle, 0);
- int children = OS.Panel_Children (parentingHandle);
- OS.UIElementCollection_Add (children, handle);
- OS.GCHandle_Free (children);
-}
-
-int createHeaderTemplate (int columnJniRef) {
- int template = OS.gcnew_DataTemplate ();
- int stackPanelType = OS.StackPanel_typeid ();
- int stackPanelName = createDotNetString (CONTENTPANEL_PART_NAME, false);
- int stackPanelNode = OS.gcnew_FrameworkElementFactory (stackPanelType, stackPanelName);
- OS.GCHandle_Free (stackPanelName);
- OS.GCHandle_Free (stackPanelType);
- int textType = OS.TextBlock_typeid ();
- int textName = createDotNetString (TEXT_PART_NAME, false);
- int textNode = OS.gcnew_FrameworkElementFactory (textType, textName);
- OS.GCHandle_Free (textName);
- OS.GCHandle_Free (textType);
- int imageType = OS.Image_typeid ();
- int imageName = createDotNetString (IMAGE_PART_NAME, false);
- int imageNode = OS.gcnew_FrameworkElementFactory (imageType, imageName);
- OS.GCHandle_Free (imageName);
- OS.GCHandle_Free (imageType);
- int marginProperty = OS.FrameworkElement_MarginProperty ();
- int thickness = OS.gcnew_Thickness (0,0,4,0);
- OS.FrameworkElementFactory_SetValue (imageNode, marginProperty, thickness);
- OS.GCHandle_Free (thickness);
- OS.GCHandle_Free (marginProperty);
- int orientationProperty = OS.StackPanel_OrientationProperty ();
- OS.FrameworkElementFactory_SetValueOrientation (stackPanelNode, orientationProperty, OS.Orientation_Horizontal);
- OS.GCHandle_Free (orientationProperty);
- int stretchProperty = OS.Image_StretchProperty ();
- OS.FrameworkElementFactory_SetValueStretch (imageNode, stretchProperty, OS.Stretch_None);
- OS.GCHandle_Free (stretchProperty);
- OS.FrameworkElementFactory_AppendChild (stackPanelNode, imageNode);
- OS.GCHandle_Free (imageNode);
- OS.FrameworkElementFactory_AppendChild (stackPanelNode, textNode);
- OS.GCHandle_Free (textNode);
- OS.FrameworkTemplate_VisualTree (template, stackPanelNode);
- OS.GCHandle_Free (stackPanelNode);
- return template;
-}
-
-void createItem (TreeColumn column, int index) {
- if (!(0 <= index && index <= columnCount)) error (SWT.ERROR_INVALID_RANGE);
- if (columnCount == 0) {
- gvColumns = OS.gcnew_GridViewColumnCollection ();
- if (gvColumns == 0) error (SWT.ERROR_NO_HANDLES);
- int template = createControlTemplate ();
- OS.Control_Template (handle, template);
- OS.GCHandle_Free (template);
- updateHeaderVisibility ();
- }
- column.createWidget ();
- int template = createHeaderTemplate (column.jniRef);
- OS.GridViewColumn_HeaderTemplate (column.handle, template);
- OS.GCHandle_Free (template);
- template = createCellTemplate (index);
- OS.GridViewColumn_CellTemplate (column.handle, template);
- OS.GCHandle_Free (template);
- if (columnCount == 0) {
- OS.GridViewColumnCollection_Clear (gvColumns);
- }
- OS.GridViewColumnCollection_Insert (gvColumns, index, column.handle);
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<itemCount; i++) {
- TreeItem item = getItem (items, i, false);
- if (item != null) {
- item.columnAdded (index);
- }
- }
- OS.GCHandle_Free (items);
- if (columns == null) columns = new TreeColumn [4];
- if (columns.length == columnCount) {
- TreeColumn [] newColumns = new TreeColumn [columnCount + 4];
- System.arraycopy(columns, 0, newColumns, 0, columnCount);
- columns = newColumns;
- }
- columns [columnCount] = column;
- columnCount++;
-}
-
-void createItem (TreeItem item, TreeItem parentItem, int index) {
- int itemCount = parentItem != null ? parentItem.itemCount : this.itemCount;
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- item.createWidget ();
- int parentHandle = parentItem != null ? parentItem.handle : handle;
- int items = OS.ItemsControl_Items (parentHandle);
- OS.ItemCollection_Insert (items, index, item.handle);
- int count = OS.ItemCollection_Count (items);
- OS.GCHandle_Free (items);
- if (itemCount == count) error (SWT.ERROR_ITEM_NOT_ADDED);
- if (parentItem != null) {
- parentItem.itemCount++;
- } else {
- this.itemCount++;
- }
-}
-
-void createWidget() {
- super.createWidget ();
- headerTemplate = createCellTemplate (0);
- int brush = OS.Brushes_Transparent ();
- OS.Control_Background (handle, brush);
- OS.GCHandle_Free (brush);
-}
-
-int defaultBackground () {
- return display.getSystemColor (SWT.COLOR_LIST_BACKGROUND).handle;
-}
-
-int defaultForeground () {
- return display.getSystemColor (SWT.COLOR_LIST_FOREGROUND).handle;
-}
-
-void deregister () {
- super.deregister ();
- display.removeWidget (parentingHandle);
-}
-
-/**
- * Deselects an item in the receiver. If the item was already
- * deselected, it remains deselected.
- *
- * @param item the item to be deselected
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void deselect (TreeItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.SINGLE) != 0) {
- ignoreSelection = true;
- OS.TreeViewItem_IsSelected (item.handle, false);
- ignoreSelection = false;
- return;
- }
- ignoreSelection = true;
- setIsSelectionActiveProperty(true);
- OS.TreeViewItem_IsSelected (item.handle, false);
- setIsSelectionActiveProperty(false);
- ignoreSelection = false;
-}
-
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void deselectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) {
- int tvItem = OS.TreeView_SelectedItem (handle);
- if (tvItem != 0) {
- ignoreSelection = true;
- OS.TreeViewItem_IsSelected (tvItem, false);
- ignoreSelection = false;
- OS.GCHandle_Free (tvItem);
- }
- } else {
- int items = OS.ItemsControl_Items (handle);
- int itemCount = OS.ItemCollection_Count (items);
- boolean[] selecting = new boolean[] {false};
- for (int i = 0; i < itemCount; i++) {
- int item = OS.ItemCollection_GetItemAt (items, i);
- fixSelection (item, null, null, selecting);
- OS.GCHandle_Free (item);
- }
- OS.GCHandle_Free (items);
- }
-}
-
-void destroyItem (TreeColumn column) {
- int index = OS.GridViewColumnCollection_IndexOf (gvColumns, column.handle);
- boolean removed = OS.GridViewColumnCollection_Remove (gvColumns, column.handle);
- if (!removed) error (SWT.ERROR_ITEM_NOT_REMOVED);
- int arrayIndex = -1;
- for (int i = 0; i < columnCount; i++) {
- TreeColumn tc = columns [i];
- if (tc.equals(column)) {
- arrayIndex = i;
- break;
- }
- }
- columnCount--;
- columns [arrayIndex] = null;
- if (arrayIndex < columnCount) System.arraycopy (columns, arrayIndex+1, columns, arrayIndex, columnCount - arrayIndex);
- if (columnCount == 0) {
- OS.GCHandle_Free (gvColumns);
- gvColumns = 0;
- int templateProperty = OS.Control_TemplateProperty ();
- OS.DependencyObject_ClearValue(handle, templateProperty);
- OS.GCHandle_Free(templateProperty);
- }
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<itemCount; i++) {
- TreeItem item = getItem (items, i, false);
- if (item != null) {
- item.columnRemoved (index);
- }
- }
- OS.GCHandle_Free (items);
-}
-
-void destroyItem (TreeItem item) {
- TreeItem parentItem = item.getParentItem ();
- int itemCount = parentItem != null ? parentItem.itemCount : this.itemCount;
- int parentHandle = parentItem != null ? parentItem.handle : handle;
- int items = OS.ItemsControl_Items (parentHandle);
- OS.ItemCollection_Remove (items, item.handle);
- int count = OS.ItemCollection_Count (items);
- OS.GCHandle_Free (items);
- if (count == itemCount) error (SWT.ERROR_ITEM_NOT_REMOVED);
- if (parentItem != null) {
- parentItem.itemCount--;
- } else {
- this.itemCount--;
- }
-}
-
-int findScrollViewer(int current, int scrollViewerType) {
- if (columnCount != 0) {
- int template = OS.Control_Template (handle);
- int scrollViewerName = createDotNetString (SCROLLVIEWER_PART_NAME, false);
- int scrollViewer = OS.FrameworkTemplate_FindName (template, scrollViewerName, handle);
- OS.GCHandle_Free (scrollViewerName);
- OS.GCHandle_Free (template);
- return scrollViewer;
- }
- return super.findScrollViewer (current, scrollViewerType);
-}
-
-int findPartOfType (int source, int type) {
- if (OS.Type_IsInstanceOfType (type, source)) return source;
- int parent = OS.VisualTreeHelper_GetParent(source);
- if (parent == 0) return 0;
- int result = findPartOfType(parent, type);
- if (result != parent) OS.GCHandle_Free(parent);
- return result;
-}
-
-void fixScrollbarVisibility () {
- int typeid = OS.ScrollViewer_typeid();
- int scrolledHandle = findScrollViewer(handle, typeid);
- OS.ScrollViewer_SetHorizontalScrollBarVisibility (scrolledHandle, OS.ScrollBarVisibility_Visible);
- OS.ScrollViewer_SetVerticalScrollBarVisibility (scrolledHandle, OS.ScrollBarVisibility_Visible);
- OS.GCHandle_Free(scrolledHandle);
- OS.GCHandle_Free(typeid);
-}
-
-/**
- * Returns the width in pixels of a grid line.
- *
- * @return the width of a grid line in pixels
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getGridLineWidth () {
- checkWidget ();
- //TODO
- return 0;
-}
-
-/**
- * Returns the height of the receiver's header
- *
- * @return the height of the header or zero if the header is not visible
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getHeaderHeight () {
- checkWidget ();
- if (gvColumns == 0) return 0;
- int column = OS.GridViewColumnCollection_default (gvColumns, 0);
- int height = 0;
- int header = OS.GridViewColumn_Header (column);
- if (header != 0) {
- height = (int) OS.FrameworkElement_ActualHeight (header);
- if (height == 0) {
- updateLayout (header);
- height = (int) OS.FrameworkElement_ActualHeight (header);
- }
- OS.GCHandle_Free (header);
- }
- OS.GCHandle_Free (column);
- OS.GCHandle_Free (gvColumns);
- return height;
-}
-
-/**
- * Returns <code>true</code> if the receiver's header is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's header's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public boolean getHeaderVisible () {
- checkWidget ();
- if (gvColumns == 0) return false;
- int column = OS.GridViewColumnCollection_default (gvColumns, 0);
- int header = OS.GridViewColumn_Header (column);
- boolean visible = OS.UIElement_Visibility (header) == OS.Visibility_Visible;
- OS.GCHandle_Free (header);
- OS.GCHandle_Free (column);
- return visible;
-}
-
-/**
- * Returns the column at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- * Columns are returned in the order that they were created.
- * If no <code>TreeColumn</code>s were created by the programmer,
- * this method will throw <code>ERROR_INVALID_RANGE</code> despite
- * the fact that a single column of data may be visible in the tree.
- * This occurs when the programmer uses the tree like a list, adding
- * items but never creating a column.
- *
- * @param index the index of the column to return
- * @return the column at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public TreeColumn getColumn (int index) {
- checkWidget ();
- if (!(0 <= index && index < columnCount)) error (SWT.ERROR_INVALID_RANGE);
- return columns [index];
-}
-
-//TreeColumn _getColumn (int index) {
-// if (columnCount == 0) return null;
-// int gridColumn = OS.GridViewColumnCollection_default (gvColumns, index);
-// int header = OS.GridViewColumn_Header (gridColumn);
-// TreeColumn column = (TreeColumn) display.getWidget (header);
-// OS.GCHandle_Free (gridColumn);
-// OS.GCHandle_Free (header);
-// return column;
-//}
-
-/**
- * Returns the number of columns contained in the receiver.
- * If no <code>TreeColumn</code>s were created by the programmer,
- * this value is zero, despite the fact that visually, one column
- * of items may be visible. This occurs when the programmer uses
- * the tree like a list, adding items but never creating a column.
- *
- * @return the number of columns
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int getColumnCount () {
- checkWidget ();
- return columnCount;
-}
-
-/**
- * Returns an array of zero-relative integers that map
- * the creation order of the receiver's items to the
- * order in which they are currently being displayed.
- * <p>
- * Specifically, the indices of the returned array represent
- * the current visual order of the items, and the contents
- * of the array represent the creation order of the items.
- * </p><p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the current visual order of the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
-public int[] getColumnOrder () {
- checkWidget ();
- int [] order = new int [columnCount];
- for (int i=0; i<order.length; i++) order [i] = i;
- for (int i = 0; i < order.length; i++) {
- TreeColumn column = columns [i];
- int index = OS.IList_IndexOf (gvColumns, column.handle);
- order [index] = i;
- }
- return order;
-}
-
-/**
- * Returns an array of <code>TreeColumn</code>s which are the
- * columns in the receiver. Columns are returned in the order
- * that they were created. If no <code>TreeColumn</code>s were
- * created by the programmer, the array is empty, despite the fact
- * that visually, one column of items may be visible. This occurs
- * when the programmer uses the tree like a list, adding items but
- * never creating a column.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.1
- */
-public TreeColumn [] getColumns () {
- checkWidget ();
- TreeColumn [] result = new TreeColumn [columnCount];
- for (int i = 0; i < result.length; i++) {
- result [i] = columns [i];
- }
- return result;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public TreeItem getItem (int index) {
- checkWidget ();
- if (index < 0 || index >= itemCount) error (SWT.ERROR_INVALID_RANGE);
- int items = OS.ItemsControl_Items (handle);
- TreeItem treeItem = getItem (items, index, true);
- OS.GCHandle_Free (items);
- return treeItem;
-}
-
-TreeItem getItem (int items, int index, boolean create) {
- int item = OS.ItemCollection_GetItemAt (items, index);
- TreeItem result = getItem (item, create);
- OS.GCHandle_Free (item);
- return result;
-}
-
-TreeItem getItem (int item, boolean create) {
- int tag = OS.FrameworkElement_Tag (item);
- if (tag != 0) {
- int contentValue = OS.IntPtr_ToInt32 (tag);
- OS.GCHandle_Free (tag);
- return (TreeItem) OS.JNIGetObject (contentValue);
- }
- if (create) {
- int itemHandle = OS.GCHandle_Alloc (item);
- int parentHandle = OS.FrameworkElement_Parent (item);
- TreeItem parentItem = null;
- if (!OS.Object_Equals (parentHandle, handle)) parentItem = (TreeItem) display.getWidget (parentHandle);
- OS.GCHandle_Free (parentHandle);
- return new TreeItem (this, parentItem, SWT.NONE, 0, itemHandle);
- }
- return null;
-}
-
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- * <p>
- * The item that is returned represents an item that could be selected by the user.
- * For example, if selection only occurs in items in the first column, then null is
- * returned if the point is outside of the item.
- * Note that the SWT.FULL_SELECTION style hint, which specifies the selection policy,
- * determines the extent of the selection.
- * </p>
- *
- * @param point the point used to locate the item
- * @return the item at the given point, or null if the point is not in a selectable item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem getItem (Point point) {
- checkWidget ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- int pt = OS.gcnew_Point (point.x, point.y);
- int input = OS.UIElement_InputHitTest (handle, pt);
- OS.GCHandle_Free (pt);
- if (input == 0) return null;
- Widget widget = display.getWidget (input);
- OS.GCHandle_Free (input);
- if (widget instanceof TreeItem) {
- return (TreeItem) widget;
- }
- return null;
-}
-
-/**
- * Returns the number of items contained in the receiver
- * that are direct item children of the receiver. The
- * number that is returned is the number of roots in the
- * tree.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- return itemCount;
-}
-
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the tree.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemHeight () {
- checkWidget ();
- //FIXME
- if (itemCount == 0) return 16;
- int items = OS.ItemsControl_Items (handle);
- int item = OS.ItemCollection_GetItemAt (items, 0);
- double height = OS.FrameworkElement_ActualHeight (item);
- OS.GCHandle_Free (item);
- OS.GCHandle_Free (items);
- return height != 0 ? (int) height : 16;
-}
-
-/**
- * Returns a (possibly empty) array of items contained in the
- * receiver that are direct item children of the receiver. These
- * are the roots of the tree.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem [] getItems () {
- checkWidget ();
- TreeItem [] result = new TreeItem [itemCount];
- int items = OS.ItemsControl_Items (handle);
- for (int i = 0; i < itemCount; i++) {
- result [i] = getItem (items, i, true);
- }
- OS.GCHandle_Free (items);
- return result;
-}
-
-/**
- * Returns <code>true</code> if the receiver's lines are visible,
- * and <code>false</code> otherwise. Note that some platforms draw
- * grid lines while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the visibility state of the lines
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public boolean getLinesVisible () {
- checkWidget ();
- //TODO
- return false;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>TreeItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem getParentItem () {
- checkWidget ();
- return null;
-}
-
-/**
- * Returns an array of <code>TreeItem</code>s that are currently
- * selected in the receiver. The order of the items is unspecified.
- * An empty array indicates that no items are selected.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its selection, so modifying the array will
- * not affect the receiver.
- * </p>
- * @return an array representing the selection
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem [] getSelection () {
- checkWidget ();
- TreeItem [] result;
- if ((style & SWT.SINGLE) != 0) {
- int item = OS.TreeView_SelectedItem (handle);
- if (item == 0) return new TreeItem [0];
- result = new TreeItem [] { (TreeItem) display.getWidget (item) };
- OS.GCHandle_Free (item);
- } else {
- result = getSelectedItems (handle, new TreeItem [4], new int [1]);
- }
- return result;
-}
-
-TreeItem[] getSelectedItems(int itemsControl, TreeItem [] selectedItems, int [] nextIndex) {
- int items = OS.ItemsControl_Items (itemsControl);
- int count = OS.ItemCollection_Count (items);
- for (int i = 0; i < count; i++) {
- int item = OS.ItemCollection_GetItemAt (items, i);
- boolean selected = OS.TreeViewItem_IsSelected (item);
- if (selected) {
- if (nextIndex [0] == selectedItems.length) {
- TreeItem [] newArray = new TreeItem [selectedItems.length + 4];
- System.arraycopy (selectedItems, 0, newArray, 0, selectedItems.length);
- selectedItems = newArray;
- }
- selectedItems [nextIndex[0]++] = getItem (item, true);
- }
- if (OS.TreeViewItem_IsExpanded (item)) {
- selectedItems = getSelectedItems (item, selectedItems, nextIndex);
- }
- OS.GCHandle_Free (item);
- }
- OS.GCHandle_Free (items);
- if (selectedItems.length != nextIndex [0]) {
- TreeItem[] newArray = new TreeItem [nextIndex[0]];
- System.arraycopy (selectedItems, 0, newArray, 0, nextIndex [0]);
- selectedItems = newArray;
- }
- return selectedItems;
-}
-
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getSelectionCount () {
- checkWidget ();
- int result;
- if ((style & SWT.SINGLE) != 0) {
- int item = OS.TreeView_SelectedItem (handle);
- result = item == 0 ? 0 : 1;
- OS.GCHandle_Free (item);
- } else {
- TreeItem[] selectedItems = getSelectedItems(handle, new TreeItem[4], new int[] {0});
- result = selectedItems.length;
- }
- return result;
-}
-
-/**
- * Returns the column which shows the sort indicator for
- * the receiver. The value may be null if no column shows
- * the sort indicator.
- *
- * @return the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortColumn(TreeColumn)
- *
- * @since 3.2
- */
-public TreeColumn getSortColumn () {
- checkWidget ();
- //TODO
- return null;
-}
-
-/**
- * Returns the direction of the sort indicator for the receiver.
- * The value will be one of <code>UP</code>, <code>DOWN</code>
- * or <code>NONE</code>.
- *
- * @return the sort direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setSortDirection(int)
- *
- * @since 3.2
- */
-public int getSortDirection () {
- checkWidget ();
- //TODO
- return SWT.NONE;
-}
-
-/**
- * Returns the item which is currently at the top of the receiver.
- * This item can change when items are expanded, collapsed, scrolled
- * or new items are added or removed.
- *
- * @return the item at the top of the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public TreeItem getTopItem () {
- checkWidget ();
- //TODO
- return null;
-}
-
-boolean hasItems () {
- return true;
-}
-
-void HandleChecked (int sender, int e) {
- if (!checkEvent (e)) return;
- if (ignoreSelection) return;
- int origsource = OS.RoutedEventArgs_OriginalSource (e);
- int typeid = OS.CheckBox_typeid ();
- boolean isCheckBox = OS.Type_IsInstanceOfType (typeid, origsource);
- OS.GCHandle_Free (typeid);
- OS.GCHandle_Free (origsource);
- if (!isCheckBox) return;
- int source = OS.RoutedEventArgs_Source (e);
- TreeItem item = (TreeItem) display.getWidget (source);
- OS.GCHandle_Free (source);
- if (item.grayed) {
- int checkbox = item.findPart (0, CHECKBOX_PART_NAME);
- if (checkbox != 0) {
- OS.ToggleButton_IsCheckedNullSetter (checkbox);
- OS.GCHandle_Free (checkbox);
- }
- }
- item.checked = true;
- item.updateCheck ();
- Event event = new Event ();
- event.item = item;
- event.detail = SWT.CHECK;
- sendEvent (SWT.Selection, event);
-
-}
-
-void HandleCollapsed (int sender, int e) {
- if (!checkEvent (e)) return;
- int source = OS.RoutedEventArgs_Source (e);
- if (OS.ItemsControl_HasItems (source)) {
- TreeItem item = (TreeItem) display.getWidget (source);
- int items = OS.ItemsControl_Items (item.handle);
- int count = OS.ItemCollection_Count (items);
- boolean[] selecting = new boolean [] {false};
- for (int i = 0; i < count; i++) {
- int child = OS.ItemCollection_GetItemAt (items, i);
- fixSelection (child, null, null, selecting);
- OS.GCHandle_Free (child);
- }
- OS.GCHandle_Free (items);
- Event event = new Event ();
- event.item = item;
- sendEvent (SWT.Collapse, event);
- }
- OS.GCHandle_Free (source);
-}
-
-void HandleExpanded (int sender, int e) {
- if (!checkEvent (e)) return;
- int source = OS.RoutedEventArgs_Source (e);
- if (OS.ItemsControl_HasItems (source)) {
- Event event = new Event ();
- event.item = (TreeItem) display.getWidget (source);
- sendEvent (SWT.Expand, event);
- }
- OS.GCHandle_Free (source);
-}
-
-void HandlePreviewKeyDown (int sender, int e) {
- super.HandlePreviewKeyDown (sender, e);
- if (!checkEvent (e)) return;
- int key = OS.KeyEventArgs_Key (e);
- if (key == OS.Key_Return) {
- int source = OS.RoutedEventArgs_OriginalSource (e);
- Widget widget = display.getWidget (source);
- OS.GCHandle_Free (source);
- if (widget instanceof TreeItem) {
- Event event = new Event ();
- event.item = (TreeItem) widget;
- postEvent (SWT.DefaultSelection, event);
- }
- }
- if (key == OS.Key_RightShift || key == OS.Key_LeftShift) shiftDown = true;
- if (key == OS.Key_RightCtrl || key == OS.Key_LeftCtrl) ctrlDown = true;
-}
-
-void HandlePreviewKeyUp (int sender, int e) {
- super.HandlePreviewKeyUp (sender, e);
- if (!checkEvent (e)) return;
- int key = OS.KeyEventArgs_Key (e);
- if (key == OS.Key_RightShift || key == OS.Key_LeftShift) shiftDown = false;
- if (key == OS.Key_RightCtrl || key == OS.Key_LeftCtrl) ctrlDown = false;
-}
-
-void HandleLoaded (int sender, int e) {
- if (!checkEvent (e)) return;
- updateHeaderVisibility();
-}
-
-void HandlePreviewMouseDoubleClick (int sender, int e) {
- if (!checkEvent (e)) return;
- int source = OS.RoutedEventArgs_OriginalSource (e);
- Widget widget = display.getWidget (source);
- OS.GCHandle_Free (source);
- if (widget instanceof TreeItem) {
- Event event = new Event ();
- event.item = (TreeItem) widget;
- postEvent (SWT.DefaultSelection, event);
- }
- if (hooks (SWT.DefaultSelection)) OS.RoutedEventArgs_Handled(e, true);
-}
-
-void HandlePreviewMouseDown (int sender, int e) {
- super.HandlePreviewMouseDown (sender, e);
- if (!checkEvent (e)) return;
- if ((style & SWT.SINGLE) != 0) return;
- int source = OS.RoutedEventArgs_Source (e);
- Widget widget = display.getWidget (source);
- OS.GCHandle_Free (source);
- if (widget instanceof TreeItem) {
- TreeItem item = (TreeItem) widget;
- /* Check that content of item was clicked, not the expander */
- int point = OS.MouseEventArgs_GetPosition (e, item.contentHandle);
- int input = OS.UIElement_InputHitTest (item.contentHandle, point);
- OS.GCHandle_Free (point);
- if (input != 0) {
- OS.GCHandle_Free (input);
- boolean rightClick = OS.MouseEventArgs_RightButton (e) == OS.MouseButtonState_Pressed;
- if (rightClick && (ctrlDown || shiftDown)) return;
- if (ctrlDown) {
- boolean selected = OS.TreeViewItem_IsSelected (item.handle);
- if (widget.equals (lastSelection)) {
- OS.TreeViewItem_IsSelected (item.handle, !selected);
- } else {
- if (selected) unselect = item;
- if (lastSelection != null && OS.TreeViewItem_IsSelected (lastSelection.handle)) reselect = lastSelection;
- }
- }
- if (!shiftDown && !ctrlDown) {
- boolean selected = OS.TreeViewItem_IsSelected (item.handle);
- if (selected && rightClick) return;
- deselectAll ();
- OS.TreeViewItem_IsSelected (item.handle, true);
- }
- }
- lastSelection = item;
- }
-}
-
-void HandleSelectedItemChanged (int sender, int e) {
- if (!checkEvent (e)) return;
- if (ignoreSelection) return;
- int selectedItem = OS.TreeView_SelectedItem (handle);
- if (selectedItem == 0) return;
- TreeItem item = (TreeItem) display.getWidget (selectedItem);
- OS.GCHandle_Free (selectedItem);
- Event event = new Event ();
- event.item = item;
- postEvent (SWT.Selection, event);
-}
-
-void HandleUnchecked (int sender, int e) {
- if (!checkEvent (e)) return;
- if (ignoreSelection) return;
- int origsource = OS.RoutedEventArgs_OriginalSource (e);
- int typeid = OS.CheckBox_typeid ();
- boolean isCheckBox = OS.Type_IsInstanceOfType (typeid, origsource);
- OS.GCHandle_Free (typeid);
- OS.GCHandle_Free (origsource);
- if (!isCheckBox) return;
- int source = OS.RoutedEventArgs_Source (e);
- TreeItem item = (TreeItem) display.getWidget (source);
- OS.GCHandle_Free (source);
- item.checked = false;
- item.updateCheck ();
- Event event = new Event ();
- event.item = item;
- event.detail = SWT.CHECK;
- sendEvent (SWT.Selection, event);
-}
-
-void hookEvents () {
- super.hookEvents ();
- int handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleLoaded");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.FrameworkElement_Loaded (handle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_RoutedPropertyChangedEventHandlerObject (jniRef, "HandleSelectedItemChanged");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.TreeView_SelectedItemChanged (handle, handler);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_MouseButtonEventHandler (jniRef, "HandlePreviewMouseDoubleClick");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.Control_PreviewMouseDoubleClick (handle, handler);
- OS.GCHandle_Free (handler);
-
- /* Item events */
- handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleExpanded");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- int event = OS.TreeViewItem_ExpandedEvent ();
- OS.UIElement_AddHandler (handle, event, handler, false);
- OS.GCHandle_Free (event);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleCollapsed");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- event = OS.TreeViewItem_CollapsedEvent ();
- OS.UIElement_AddHandler (handle, event, handler, false);
- OS.GCHandle_Free (event);
- OS.GCHandle_Free (handler);
- if ((style & SWT.CHECK) != 0) {
- handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleChecked");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- event = OS.ToggleButton_CheckedEvent ();
- OS.UIElement_AddHandler (handle, event, handler, false);
- OS.GCHandle_Free (event);
- OS.GCHandle_Free (handler);
- handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleUnchecked");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- event = OS.ToggleButton_UncheckedEvent ();
- OS.UIElement_AddHandler (handle, event, handler, false);
- OS.GCHandle_Free (event);
- OS.GCHandle_Free (handler);
- }
-}
-
-/**
- * Searches the receiver's list starting at the first column
- * (index 0) until a column is found that is equal to the
- * argument, and returns the index of that column. If no column
- * is found, returns -1.
- *
- * @param column the search column
- * @return the index of the column
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the column is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int indexOf (TreeColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (gvColumns == 0) return -1;
- int index = OS.GridViewColumnCollection_IndexOf (gvColumns, column.handle);
- return index;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int indexOf (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- int items = OS.ItemsControl_Items (handle);
- int index = OS.ItemCollection_IndexOf (items, item.handle);
- OS.GCHandle_Free (items);
- return index;
-}
-
-void OnRender (int source, int dc) {
- int type = OS.TreeViewItem_typeid ();
- int itemHandle = findPartOfType (source, type);
- OS.GCHandle_Free (type);
- TreeItem item = getItem (itemHandle, true);
- OS.GCHandle_Free (itemHandle);
- if ((item.cached || (style & SWT.VIRTUAL) == 0) && item.contentHandle != 0) return;
- checkData (item);
- if (item.contentHandle == 0) {
- item.contentHandle = item.findContentPresenter();
- }
- int columns = columnCount == 0 ? 1 : columnCount;
- item.updateCheck ();
- for (int i=0; i<columns; i++) {
- item.updateText (i);
- item.updateImage (i);
- item.updateBackground (i);
- item.updateForeground (i);
- item.updateFont (i);
- }
-}
-
-void OnSelectedItemChanged (int args) {
- int newItemRef = OS.RoutedPropertyChangedEventArgs_NewValue (args);
- TreeItem newItem = null;
- if (newItemRef != 0) {
- int unsetValue = OS.DependencyProperty_UnsetValue ();
- if (!OS.Object_Equals (newItemRef, unsetValue)) newItem = getItem (newItemRef, false);
- OS.GCHandle_Free (newItemRef);
- OS.GCHandle_Free (unsetValue);
- newItemRef = 0;
- }
- setIsSelectionActiveProperty (true);
- if (!shiftDown && !ctrlDown) {
- deselectAll ();
- if (newItem != null) OS.TreeViewItem_IsSelected (newItem.handle, true);
- anchor = newItem;
- } else {
- if (shiftDown) {
- deselectAll ();
- if (anchor == null || anchor == newItem) {
- if (newItem != null) OS.TreeViewItem_IsSelected (newItem.handle, true);
- anchor = newItem;
- } else {
- int zero = OS.gcnew_Point (0, 0);
- int point = OS.UIElement_TranslatePoint (anchor.handle, zero, newItem.handle);
- OS.GCHandle_Free (zero);
- boolean down = OS.Point_Y (point) < 0;
- OS.GCHandle_Free (point);
- TreeItem from = down ? anchor : newItem;
- TreeItem to = down ? newItem : anchor;
- int items = OS.ItemsControl_Items (handle);
- int itemCount = OS.ItemCollection_Count (items);
- boolean[] selecting = new boolean[] {false};
- for (int i = 0; i < itemCount; i++) {
- int item = OS.ItemCollection_GetItemAt(items, i);
- fixSelection (item, from, to, selecting);
- OS.GCHandle_Free (item);
- }
- OS.GCHandle_Free (items);
- }
- } else {
- if (unselect != null) {
- OS.TreeViewItem_IsSelected (unselect.handle, false);
- unselect = null;
- }
- if (reselect != null) {
- OS.TreeViewItem_IsSelected (reselect.handle, true);
- reselect = null;
- }
- anchor = newItem;
- }
- }
- setIsSelectionActiveProperty (false);
-}
-
-private void fixSelection (int tvItem, TreeItem from, TreeItem to, boolean [] selecting) {
- if (selecting [0]) {
- OS.TreeViewItem_IsSelected (tvItem, true);
- if (to != null && OS.Object_Equals (tvItem, to.handle)) selecting [0] = false;
- } else {
- if (from != null && OS.Object_Equals (tvItem, from.handle)) selecting [0] = true;
- OS.TreeViewItem_IsSelected(tvItem, selecting [0]);
- }
- if (OS.TreeViewItem_IsExpanded (tvItem)) {
- int items = OS.ItemsControl_Items (tvItem);
- int itemCount = OS.ItemCollection_Count (items);
- for (int i = 0; i < itemCount; i++) {
- int tvChild = OS.ItemCollection_GetItemAt (items, i);
- fixSelection (tvChild, from, to, selecting);
- OS.GCHandle_Free (tvChild);
- }
- OS.GCHandle_Free (items);
- }
-}
-
-int parentingHandle () {
- return parentingHandle;
-}
-
-void register() {
- super.register();
- display.addWidget (parentingHandle, this);
-}
-
-void releaseChildren (boolean destroy) {
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<itemCount; i++) {
- TreeItem item = getItem (items, i, false);
- if (item != null && !item.isDisposed ()) item.release (false);
- }
- OS.GCHandle_Free (items);
- for (int i=0; i<columnCount; i++) {
- TreeColumn column = columns [i];
- if (column != null && !column.isDisposed ()) {
- column.release (false);
- }
- }
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (gvColumns != 0) OS.GCHandle_Free (gvColumns);
- gvColumns = 0;
- if (headerTemplate != 0) OS.GCHandle_Free (headerTemplate);
- headerTemplate = 0;
- OS.GCHandle_Free (parentingHandle);
- parentingHandle = 0;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- columns = null;
-}
-
-/**
- * Removes all of the items from the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void removeAll () {
- checkWidget ();
- int items = OS.ItemsControl_Items (handle);
- for (int i = 0; i < itemCount; i++) {
- TreeItem item = getItem (items, i, false);
- if (item != null && !item.isDisposed ()) item.release (false);
- }
- ignoreSelection = true;
- OS.ItemCollection_Clear (items);
- ignoreSelection = false;
- itemCount = OS.ItemCollection_Count (items);
- OS.GCHandle_Free (items);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the user changes the receiver's selection.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when items in the receiver are expanded or collapsed.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see TreeListener
- * @see #addTreeListener
- */
-public void removeTreeListener(TreeListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Expand, listener);
- eventTable.unhook (SWT.Collapse, listener);
-}
-
-int setBounds (int x, int y, int width, int height, int flags) {
- int result = super.setBounds (x, y, width, height, flags);
- if ((result & RESIZED) != 0) {
- OS.FrameworkElement_Width (handle, width);
- OS.FrameworkElement_Height (handle, height);
- }
- return result;
-}
-
-/**
- * Display a mark indicating the point at which an item will be inserted.
- * The drop insert item has a visual hint to show where a dragged item
- * will be inserted when dropped on the tree.
- *
- * @param item the insert item. Null will clear the insertion mark.
- * @param before true places the insert mark above 'item'. false places
- * the insert mark below 'item'.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setInsertMark (TreeItem item, boolean before) {
- checkWidget ();
- if (item != null && item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- //TODO
-}
-
-/**
- * Sets the number of root-level items contained in the receiver.
- *
- * @param count the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setItemCount (int count) {
- checkWidget ();
- setItemCount (null, count);
-}
-
-void setItemCount (TreeItem parentItem, int count) {
- int itemCount = parentItem != null ? parentItem.itemCount : this.itemCount;
- count = Math.max (0, count);
- if (count == itemCount) return;
- int parentHandle = parentItem != null ? parentItem.handle : handle;
- int index = itemCount - 1;
- int items = OS.ItemsControl_Items (parentHandle);
- while (index >= count) {
- TreeItem item = getItem (items, index, false);
- if (item != null) {
- if (!item.isDisposed()) item.release (true);
- } else {
- OS.ItemCollection_RemoveAt (items, index);
- }
- index--;
- }
- if (OS.ItemCollection_Count (items) > count) error (SWT.ERROR_ITEM_NOT_REMOVED);
- if ((style & SWT.VIRTUAL) != 0) {
- for (int i=itemCount; i<count; i++) {
- int item = OS.gcnew_TreeViewItem ();
- if (item == 0) error (SWT.ERROR_NO_HANDLES);
- if (columnCount != 0) {
- int headerHandle = OS.gcnew_SWTTreeViewRowPresenter (handle);
- if (headerHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.GridViewRowPresenterBase_Columns (headerHandle, gvColumns);
- OS.HeaderedItemsControl_Header (item, headerHandle);
- OS.GCHandle_Free (headerHandle);
- } else {
- OS.TreeViewItem_HeaderTemplate (item, headerTemplate);
- }
- OS.ItemCollection_Add (items, item);
- OS.GCHandle_Free (item);
- }
- } else {
- for (int i=itemCount; i<count; i++) {
- new TreeItem (this, parentItem, SWT.NONE, i, 0);
- }
- }
- itemCount = OS.ItemCollection_Count (items);
- OS.GCHandle_Free (items);
- if (itemCount != count) error (SWT.ERROR_ITEM_NOT_ADDED);
- if (parentItem != null) {
- parentItem.itemCount = itemCount;
- } else {
- this.itemCount = itemCount;
- }
-}
-
-/**
- * Sets the height of the area which would be used to
- * display <em>one</em> of the items in the tree.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-/*public*/ void setItemHeight (int itemHeight) {
- checkWidget ();
- if (itemHeight < -1) error (SWT.ERROR_INVALID_ARGUMENT);
- //TODO
-}
-
-/**
- * Marks the receiver's lines as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise. Note that some platforms draw
- * grid lines while others may draw alternating row colors.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setLinesVisible (boolean show) {
- checkWidget ();
- //TODO
-}
-
-/**
- * Selects an item in the receiver. If the item was already
- * selected, it remains selected.
- *
- * @param item the item to be selected
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.4
- */
-public void select (TreeItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.SINGLE) != 0) {
- ignoreSelection = true;
- OS.TreeViewItem_IsSelected (item.handle, true);
- ignoreSelection = false;
- return;
- }
-
- ignoreSelection = true;
- setIsSelectionActiveProperty(true);
- OS.TreeViewItem_IsSelected (item.handle, true);
- setIsSelectionActiveProperty(false);
- ignoreSelection = false;
-}
-
-/**
- * Selects all of the items in the receiver.
- * <p>
- * If the receiver is single-select, do nothing.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void selectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- int items = OS.ItemsControl_Items (handle);
- int itemCount = OS.ItemCollection_Count (items);
- boolean[] selecting = new boolean[] {true};
- setIsSelectionActiveProperty(true);
- for (int i = 0; i < itemCount; i++) {
- int item = OS.ItemCollection_GetItemAt(items, i);
- fixSelection(item, null, null, selecting);
- OS.GCHandle_Free(item);
- }
- setIsSelectionActiveProperty(false);
- OS.GCHandle_Free(items);
-}
-
-/**
- * Sets the order that the items in the receiver should
- * be displayed in to the given argument which is described
- * in terms of the zero-relative ordering of when the items
- * were added.
- *
- * @param order the new order to display the items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item order is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see TreeColumn#getMoveable()
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
-public void setColumnOrder (int [] order) {
- checkWidget ();
- if (order == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (order.length != columnCount) error (SWT.ERROR_INVALID_ARGUMENT);
- int [] oldOrder = getColumnOrder ();
- boolean reorder = false;
- boolean [] seen = new boolean [columnCount];
- for (int i=0; i<order.length; i++) {
- int index = order [i];
- if (index < 0 || index >= columnCount) error (SWT.ERROR_INVALID_ARGUMENT);
- if (seen [index]) error (SWT.ERROR_INVALID_ARGUMENT);
- seen [index] = true;
- if (order [i] != oldOrder [i]) reorder = true;
- }
- if (!reorder) return;
- for (int i = 0; i < order.length; i++) {
- TreeColumn column = columns [order [i]];
- int index = OS.IList_IndexOf (gvColumns, column.handle);
- if (index != i) OS.ObservableCollectionGridViewColumn_Move (gvColumns, index, i);
- }
-}
-
-void setFont (int font, double size) {
- if (font != 0) {
- int fontFamily = OS.Typeface_FontFamily( font);
- int style = OS.Typeface_Style (font);
- int weight = OS.Typeface_Weight (font);
- int stretch = OS.Typeface_Stretch (font);
- OS.Control_FontFamily (handle, fontFamily);
- OS.Control_FontStyle (handle, style);
- OS.Control_FontWeight (handle, weight);
- OS.Control_FontStretch (handle, stretch);
- OS.Control_FontSize (handle, size);
- OS.GCHandle_Free (fontFamily);
- OS.GCHandle_Free (style);
- OS.GCHandle_Free (weight);
- OS.GCHandle_Free (stretch);
- } else {
- int property = OS.Control_FontFamilyProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.Control_FontStyleProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.Control_FontWeightProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.Control_FontStretchProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.Control_FontSizeProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
-}
-
-void setForegroundBrush (int brush) {
- if (brush != 0) {
- OS.Control_Foreground (handle, brush);
- } else {
- int property = OS.Control_ForegroundProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
-}
-
-/**
- * Marks the receiver's header as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param show the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setHeaderVisible (boolean show) {
- checkWidget ();
- headerVisibility = show ? OS.Visibility_Visible : OS.Visibility_Collapsed;
- updateHeaderVisibility ();
- for (int i=0; i<columnCount; i++) {
- TreeColumn column = getColumn(i);
- column.updateImage ();
- column.updateText ();
- }
-}
-
-void setIsSelectionActiveProperty(boolean active) {
- int treeType = OS.Object_GetType (handle);
- int propertyName = createDotNetString ("IsSelectionChangeActive", false);
- int property = OS.Type_GetProperty (treeType, propertyName, OS.BindingFlags_Instance | OS.BindingFlags_NonPublic);
- OS.GCHandle_Free (treeType);
- OS.GCHandle_Free (propertyName);
- OS.PropertyInfo_SetValueBoolean (property, handle, active, 0);
- OS.GCHandle_Free (property);
-}
-
-/**
- * Sets the receiver's selection to the given item.
- * The current selection is cleared before the new item is selected.
- * <p>
- * If the item is not in the receiver, then it is ignored.
- * </p>
- *
- * @param item the item to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSelection (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (new TreeItem [] {item});
-}
-
-/**
- * Sets the receiver's selection to be the given array of items.
- * The current selection is cleared before the new items are selected.
- * <p>
- * Items that are not in the receiver are ignored.
- * If the receiver is single-select and multiple items are specified,
- * then all items are ignored.
- * </p>
- *
- * @param items the array of items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the items has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#deselectAll()
- */
-public void setSelection (TreeItem [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = items.length;
- if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) {
- deselectAll ();
- return;
- }
- for (int i = 0; i < items.length; i++) {
- TreeItem item = items [i];
- if (item != null && item.isDisposed ()) error (SWT.ERROR_WIDGET_DISPOSED);
- }
- deselectAll ();
- ignoreSelection = true;
- if ((style & SWT.SINGLE) != 0) {
- TreeItem select = items [0];
- if (select != null) {
- OS.TreeViewItem_IsSelected (items [0].handle, true);
- }
- } else {
- setIsSelectionActiveProperty (true);
- for (int i = 0; i < length; i++) {
- TreeItem item = items [i];
- if (item != null) OS.TreeViewItem_IsSelected (item.handle, true);
- }
- setIsSelectionActiveProperty (false);
- }
- ignoreSelection = false;
-}
-
-/**
- * Sets the column used by the sort indicator for the receiver. A null
- * value will clear the sort indicator. The current sort column is cleared
- * before the new column is set.
- *
- * @param column the column used by the sort indicator or <code>null</code>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the column is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortColumn (TreeColumn column) {
- checkWidget ();
- //TODO
-}
-
-/**
- * Sets the direction of the sort indicator for the receiver. The value
- * can be one of <code>UP</code>, <code>DOWN</code> or <code>NONE</code>.
- *
- * @param direction the direction of the sort indicator
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setSortDirection (int direction) {
- checkWidget ();
- //TODO
-}
-
-/**
- * Sets the item which is currently at the top of the receiver.
- * This item can change when items are expanded, collapsed, scrolled
- * or new items are added or removed.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getTopItem()
- *
- * @since 2.1
- */
-public void setTopItem (TreeItem item) {
- checkWidget ();
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- //TODO
-}
-
-/**
- * Shows the column. If the column is already showing in the receiver,
- * this method simply returns. Otherwise, the columns are scrolled until
- * the column is visible.
- *
- * @param column the column to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void showColumn (TreeColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (column.parent != this) return;
- int index = indexOf (column);
- if (index == -1) return;
- //TODO
-}
-
-/**
- * Shows the item. If the item is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled
- * and expanded until the item is visible.
- *
- * @param item the item to be shown
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#showSelection()
- */
-public void showItem (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- if (item.parent != this) return;
- int parent = OS.FrameworkElement_Parent (item.handle);
- while (!OS.Object_Equals (parent, handle)) {
- OS.TreeViewItem_IsExpanded (parent, true);
- int newParent = OS.FrameworkElement_Parent (parent);
- OS.GCHandle_Free (parent);
- parent = newParent;
- }
- OS.GCHandle_Free (parent);
- OS.FrameworkElement_BringIntoView (item.handle);
-}
-
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#showItem(TreeItem)
- */
-public void showSelection () {
- checkWidget ();
- int item = OS.TreeView_SelectedItem (handle);
- if (item != 0) {
- OS.FrameworkElement_BringIntoView (item);
- OS.GCHandle_Free (item);
- }
-}
-
-int topHandle () {
- return parentingHandle;
-}
-
-void updateHeaderVisibility() {
- int template = OS.Control_Template (handle);
- int scrollViewerName = createDotNetString (SCROLLVIEWER_PART_NAME, false);
- int scrollViewer = OS.FrameworkTemplate_FindName (template, scrollViewerName, handle);
- if (scrollViewer != 0) {
- int scrollViewerTemplate = OS.Control_Template(scrollViewer);
- int headerName = createDotNetString(HEADER_PART_NAME, false);
- int header = OS.FrameworkTemplate_FindName (scrollViewerTemplate, headerName, scrollViewer);
- if (header != 0) {
- OS.UIElement_Visibility (header, headerVisibility);
- OS.GCHandle_Free (header);
- }
- OS.GCHandle_Free (scrollViewerTemplate);
- OS.GCHandle_Free (headerName);
- OS.GCHandle_Free (scrollViewer);
- }
- OS.GCHandle_Free (scrollViewerName);
- OS.GCHandle_Free (template);
-}
-
-} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TreeColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TreeColumn.java
deleted file mode 100644
index 3671770dc0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TreeColumn.java
+++ /dev/null
@@ -1,613 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a column in a tree widget.
- * <p><dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd> Move, Resize, Selection</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles LEFT, RIGHT and CENTER may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class TreeColumn extends Item {
- Tree parent;
- int headerHandle;
- int stringPtr;
- boolean moveable, resizable;
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeColumn (Tree parent, int style) {
- this (checkNull(parent), checkStyle (style), parent.columnCount);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code>), a style value
- * describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeColumn (Tree parent, int style, int index) {
- super (parent, checkStyle (style));
- resizable = true;
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize,typedListener);
- addListener (SWT.Move,typedListener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected by the user, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the column header is selected.
- * <code>widgetDefaultSelected</code> is not called.
- * </p>
- *
- * @param listener the listener which should be notified when the control is selected by the user
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
-public void addSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static Tree checkNull (Tree tree) {
- if (tree == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return tree;
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void createHandle () {
- handle = OS.gcnew_GridViewColumn ();
- if (handle == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- headerHandle = OS.gcnew_GridViewColumnHeader ();
- OS.GridViewColumn_Header (handle, headerHandle);
- OS.GridViewColumn_Width (handle, 0);
-}
-
-void deregister () {
- display.removeWidget (headerHandle);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-int findContentPresenter (int element, int contentPresenterType) {
- int type = OS.Object_GetType (element);
- boolean found = OS.Object_Equals (contentPresenterType, type);
- OS.GCHandle_Free (type);
- if (found) return element;
- int count = OS.VisualTreeHelper_GetChildrenCount (element);
- for (int i = 0; i < count; i++) {
- int child = OS.VisualTreeHelper_GetChild (element, i);
- int result = findContentPresenter (child, contentPresenterType);
- if (child != result) OS.GCHandle_Free (child);
- if (result != 0) return result;
- }
- return 0;
-}
-
-int findPart (String part) {
- int contentPresenterType = OS.ContentPresenter_typeid ();
- int contentPresenter = findContentPresenter (headerHandle, contentPresenterType);
- int result = 0;
- if (contentPresenter != 0) {
- int template = OS.GridViewColumn_HeaderTemplate (handle);
- int strPtr = createDotNetString (part, false);
- result = OS.FrameworkTemplate_FindName (template, strPtr, contentPresenter);
- OS.GCHandle_Free (strPtr);
- OS.GCHandle_Free (template);
- OS.GCHandle_Free (contentPresenter);
- }
- OS.GCHandle_Free (contentPresenterType);
- return result;
-}
-
-/**
- * Returns a value which describes the position of the
- * text or image in the receiver. The value will be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>.
- *
- * @return the alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getAlignment () {
- checkWidget ();
- if ((style & SWT.LEFT) != 0) return SWT.LEFT;
- if ((style & SWT.CENTER) != 0) return SWT.CENTER;
- if ((style & SWT.RIGHT) != 0) return SWT.RIGHT;
- return SWT.LEFT;
-}
-
-/**
- * Gets the moveable attribute. A column that is
- * not moveable cannot be reordered by the user
- * by dragging the header but may be reordered
- * by the programmer.
- *
- * @return the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#getColumnOrder()
- * @see Tree#setColumnOrder(int[])
- * @see TreeColumn#setMoveable(boolean)
- * @see SWT#Move
- *
- * @since 3.2
- */
-public boolean getMoveable () {
- checkWidget ();
- return moveable;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Tree</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Tree getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Gets the resizable attribute. A column that is
- * not resizable cannot be dragged by the user but
- * may be resized by the programmer.
- *
- * @return the resizable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getResizable () {
- checkWidget ();
- return resizable;
-}
-
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public String getToolTipText () {
- checkWidget ();
- int strPtr = OS.FrameworkElement_ToolTip (headerHandle);
- String string = createJavaString (strPtr);
- OS.GCHandle_Free (strPtr);
- return string;
-}
-
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getWidth () {
- checkWidget ();
- return (int) OS.GridViewColumn_ActualWidth(handle);
-}
-
-
-void HandleLoaded (int source, int e) {
- updateImage ();
- updateText ();
-}
-
-void hookEvents() {
- super.hookEvents ();
- int handler = OS.gcnew_RoutedEventHandler (jniRef, "HandleLoaded");
- if (handler == 0) error (SWT.ERROR_NO_HANDLES);
- OS.FrameworkElement_Loaded (headerHandle, handler);
- OS.GCHandle_Free (handler);
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- */
-public void pack () {
- checkWidget ();
- int index = parent.indexOf (this);
- if (index == -1) return;
- int widthProperty = OS.GridViewColumn_WidthProperty ();
- OS.DependencyObject_ClearValue (handle, widthProperty);
- OS.GCHandle_Free (widthProperty);
-}
-
-void register() {
- display.addWidget (headerHandle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (handle != 0) OS.GCHandle_Free (handle);
- handle = 0;
- OS.GCHandle_Free (headerHandle);
- headerHandle = 0;
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (stringPtr != 0) OS.GCHandle_Free (stringPtr);
- stringPtr = 0;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected by the user.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-/**
- * Controls how text and images will be displayed in the receiver.
- * The argument should be one of <code>LEFT</code>, <code>RIGHT</code>
- * or <code>CENTER</code>.
- * <p>
- * Note that due to a restriction on some platforms, the first column
- * is always left aligned.
- * </p>
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setAlignment (int alignment) {
- checkWidget ();
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- int index = parent.indexOf (this);
- if (index == -1 || index == 0) return;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- //TODO
-}
-
-public void setImage (Image image) {
- checkWidget ();
- super.setImage (image);
- updateImage ();
-}
-
-/**
- * Sets the moveable attribute. A column that is
- * moveable can be reordered by the user by dragging
- * the header. A column that is not moveable cannot be
- * dragged by the user but may be reordered
- * by the programmer.
- *
- * @param moveable the moveable attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Tree#setColumnOrder(int[])
- * @see Tree#getColumnOrder()
- * @see TreeColumn#getMoveable()
- * @see SWT#Move
- *
- * @since 3.2
- */
-public void setMoveable (boolean moveable) {
- checkWidget ();
- this.moveable = moveable;
-}
-
-/**
- * Sets the resizable attribute. A column that is
- * not resizable cannot be dragged by the user but
- * may be resized by the programmer.
- *
- * @param resizable the resize attribute
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setResizable (boolean resizable) {
- checkWidget ();
- this.resizable = resizable;
-}
-
-void setSortDirection (int direction) {
- //TODO
-}
-
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (string.equals (text)) return;
- text = string;
- updateText ();
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that the default tool tip for the
- * control will be shown. For a control that has a default
- * tool tip, such as the Tree control on Windows, setting
- * the tool tip text to an empty string replaces the default,
- * causing no tool tip text to be shown.
- * <p>
- * The mnemonic indicator (character '&amp;') is not displayed in a tool tip.
- * To display a single '&amp;' in the tool tip, the character '&amp;' can be
- * escaped by doubling it in the string.
- * </p>
- *
- * @param string the new tool tip text (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setToolTipText (String string) {
- checkWidget();
- if (string != null && string.length() == 0) string = null;
- int strPtr = createDotNetString (string, false);
- OS.FrameworkElement_ToolTip (headerHandle, strPtr);
- OS.GCHandle_Free (strPtr);
-}
-
-/**
- * Sets the width of the receiver.
- *
- * @param width the new width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setWidth (int width) {
- checkWidget ();
- if (width < 0) return;
- OS.GridViewColumn_Width (handle, width);
-}
-
-void updateImage() {
- int part = findPart (Tree.IMAGE_PART_NAME);
- if (part == 0) return;
- OS.Image_Source (part, image == null ? 0 : image.handle);
- OS.GCHandle_Free (part);
-}
-
-void updateText () {
- int part = findPart (Tree.TEXT_PART_NAME);
- if (part == 0) return;
- int str = createDotNetString (text, false);
- OS.TextBlock_Text (part, str);
- OS.GCHandle_Free (str);
- OS.GCHandle_Free (part);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TreeItem.java
deleted file mode 100644
index 24e2c25c4e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/TreeItem.java
+++ /dev/null
@@ -1,1638 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a hierarchy of tree items in a tree widget.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-
-public class TreeItem extends Item {
- Tree parent;
- int contentHandle;
- int itemCount;
- Image [] images;
- String [] strings;
- Color [] cellBackground, cellForeground;
- Font [] cellFont;
- boolean checked, grayed, cached, ignoreNotify;
- Color background, foreground;
- Font font;
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>)
- * and a style value describing its behavior and appearance.
- * The item is added to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (Tree parent, int style) {
- this (checkNull (parent), null, style, parent.itemCount, 0);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>),
- * a style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (Tree parent, int style, int index) {
- this (checkNull (parent), null, style, index, 0);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>)
- * and a style value describing its behavior and appearance.
- * The item is added to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parentItem a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (TreeItem parentItem, int style) {
- this (checkNull (parentItem).parent, parentItem, style, parentItem.itemCount, 0);
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Tree</code> or a <code>TreeItem</code>),
- * a style value describing its behavior and appearance, and the index
- * at which to place it in the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parentItem a tree control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- * @param index the zero-relative index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public TreeItem (TreeItem parentItem, int style, int index) {
- this (checkNull (parentItem).parent, parentItem, style, index, 0);
-}
-
-TreeItem (Tree parent, TreeItem parentItem, int style, int index, int handle) {
- super (parent, style);
- this.parent = parent;
- this.handle = handle;
- if (handle == 0) {
- parent.createItem (this, parentItem, index);
- } else {
- createWidget ();
- }
-}
-
-static Tree checkNull (Tree tree) {
- if (tree == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return tree;
-}
-
-static TreeItem checkNull (TreeItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-void clear () {
- strings = null;
- images = null;
- checked = grayed = false;
- updateCheck ();
- setForeground (null);
- setBackground (null);
- setFont (null);
- int columns = parent.columnCount == 0 ? 1 : parent.columnCount;
- for (int i = 0; i < columns; i++) {
- updateText (i);
- updateImage (i);
- updateBackground (i);
- updateForeground (i);
- updateFont (i);
- }
- if ((parent.style & SWT.VIRTUAL) != 0) cached = false;
- int part = findPart (0, Tree.RENDER_PANEL_NAME);
- if (part != 0) OS.UIElement_InvalidateVisual (part);
- OS.GCHandle_Free (part);
-}
-
-/**
- * Clears the item at the given zero-relative index in the receiver.
- * The text, icon and other attributes of the item are set to the default
- * value. If the tree was created with the <code>SWT.VIRTUAL</code> style,
- * these attributes are requested again as needed.
- *
- * @param index the index of the item to clear
- * @param all <code>true</code> if all child items of the indexed item should be
- * cleared recursively, and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clear (int index, boolean all) {
- checkWidget ();
- if (index < 0 || index >= itemCount) SWT.error (SWT.ERROR_INVALID_RANGE);
- parent.clear (handle, index, all);
-}
-
-/**
- * Clears all the items in the receiver. The text, icon and other
- * attributes of the items are set to their default values. If the
- * tree was created with the <code>SWT.VIRTUAL</code> style, these
- * attributes are requested again as needed.
- *
- * @param all <code>true</code> if all child items should be cleared
- * recursively, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT#VIRTUAL
- * @see SWT#SetData
- *
- * @since 3.2
- */
-public void clearAll (boolean all) {
- checkWidget ();
- parent.clearAll (this, all);
-}
-
-void columnAdded (int index) {
- if (parent.columnCount == 0) {
- int headerTemplate = OS.HeaderedItemsControl_HeaderTemplateProperty ();
- OS.DependencyObject_ClearValue (handle, headerTemplate);
- OS.GCHandle_Free (headerTemplate);
- int header = OS.gcnew_SWTTreeViewRowPresenter (parent.handle);
- if (header == 0) error (SWT.ERROR_NO_HANDLES);
- OS.GridViewRowPresenterBase_Columns (header, parent.gvColumns);
- OS.HeaderedItemsControl_Header (handle, header);
- OS.GCHandle_Free (header);
- } else {
- int newLength = parent.columnCount + 1;
- if (strings != null) {
- String [] temp = new String [newLength];
- System.arraycopy (strings, 0, temp, 0, index);
- System.arraycopy (strings, index, temp, index + 1, parent.columnCount - index);
- strings = temp;
- }
- if (images != null) {
- Image [] temp = new Image [newLength];
- System.arraycopy (images, 0, temp, 0, index);
- System.arraycopy (images, index, temp, index + 1, parent.columnCount - index);
- images = temp;
- }
- if (cellBackground != null) {
- Color [] temp = new Color [newLength];
- System.arraycopy (cellBackground, 0, temp, 0, index);
- System.arraycopy (cellBackground, index, temp, index + 1, parent.columnCount - index);
- cellBackground = temp;
- }
- if (cellForeground != null) {
- Color [] temp = new Color [newLength];
- System.arraycopy (cellForeground, 0, temp, 0, index);
- System.arraycopy (cellForeground, index, temp, index + 1, parent.columnCount - index);
- cellForeground = temp;
- }
- if (cellFont != null) {
- Font [] temp = new Font [newLength];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index, temp, index + 1, parent.columnCount - index);
- cellFont = temp;
- }
- }
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<itemCount; i++) {
- TreeItem item = parent.getItem (items, i, false);
- if (item != null) {
- item.columnAdded (index);
- }
- }
- OS.GCHandle_Free (items);
-}
-
-void columnRemoved(int index) {
- if (parent.columnCount == 0) {
- OS.TreeViewItem_HeaderTemplate (handle, parent.headerTemplate);
- } else {
- if (strings == null) {
- String [] temp = new String [parent.columnCount];
- System.arraycopy (strings, 0, temp, 0, index);
- System.arraycopy (strings, index + 1, temp, index, parent.columnCount - index);
- strings = temp;
- }
- if (images != null) {
- Image [] temp = new Image [parent.columnCount];
- System.arraycopy (images, 0, temp, 0, index);
- System.arraycopy (images, index + 1, temp, index, parent.columnCount - index);
- images = temp;
- }
- if (cellBackground != null) {
- Color [] temp = new Color [parent.columnCount];
- System.arraycopy (cellBackground, 0, temp, 0, index);
- System.arraycopy (cellBackground, index + 1, temp, index, parent.columnCount - index);
- cellBackground = temp;
- }
- if (cellForeground != null) {
- Color [] temp = new Color [parent.columnCount];
- System.arraycopy (cellForeground, 0, temp, 0, index);
- System.arraycopy (cellForeground, index + 1, temp, index, parent.columnCount - index);
- cellForeground = temp;
- }
- if (cellFont != null) {
- Font [] temp = new Font [parent.columnCount];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index + 1, temp, index, parent.columnCount - index);
- cellFont = temp;
- }
- }
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<itemCount; i++) {
- TreeItem item = parent.getItem (items, i, false);
- if (item != null) {
- item.columnRemoved (index);
- }
- }
- OS.GCHandle_Free (items);
-}
-
-void createHandle () {
- if (handle == 0) {
- handle = OS.gcnew_TreeViewItem ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if (parent.columnCount != 0) {
- int headerHandle = OS.gcnew_SWTTreeViewRowPresenter (parent.handle);
- if (headerHandle == 0) error (SWT.ERROR_NO_HANDLES);
- OS.GridViewRowPresenterBase_Columns (headerHandle, parent.gvColumns);
- OS.HeaderedItemsControl_Header (handle, headerHandle);
- OS.GCHandle_Free (headerHandle);
- } else {
- OS.TreeViewItem_HeaderTemplate (handle, parent.headerTemplate);
- }
- }
- OS.Control_HorizontalContentAlignment (handle, OS.HorizontalAlignment_Stretch);
- OS.Control_VerticalContentAlignment (handle, OS.VerticalAlignment_Stretch);
- updateCheck ();
- fixStyle ();
-}
-
-void deregister () {
- display.removeWidget (handle);
-}
-
-void destroyWidget () {
- parent.destroyItem (this);
- releaseHandle ();
-}
-
-int findContentPresenter () {
- updateLayout (handle);
- int controlTemplate = OS.Control_Template (handle);
- int headerName = createDotNetString ("PART_Header", false);
- int contentPresenter = OS.FrameworkTemplate_FindName (controlTemplate, headerName, handle);
- OS.GCHandle_Free (headerName);
- OS.GCHandle_Free (controlTemplate);
- return contentPresenter;
-}
-
-int findPart (int column, String partName) {
- if (contentHandle == 0) updateLayout (handle);
- if (contentHandle == 0) return 0;
- int name = createDotNetString (partName, false);
- int result = 0;
- if (parent.columnCount == 0) {
- int template = OS.TreeViewItem_HeaderTemplate (handle);
- result = OS.FrameworkTemplate_FindName (template, name, contentHandle);
- OS.GCHandle_Free (template);
- } else {
- int rowPresenter = OS.HeaderedItemsControl_Header (handle);
- int contentPresenter = OS.VisualTreeHelper_GetChild (rowPresenter, column);
- OS.GCHandle_Free (rowPresenter);
- int columnHandle = OS.GridViewColumnCollection_default (parent.gvColumns, column);
- int template = OS.GridViewColumn_CellTemplate (columnHandle);
- OS.GCHandle_Free (columnHandle);
- result = OS.FrameworkTemplate_FindName (template, name, contentPresenter);
- OS.GCHandle_Free (contentPresenter);
- OS.GCHandle_Free (template);
- }
- OS.GCHandle_Free (name);
- return result;
-}
-
-void fixStyle () {
- int itemStyle = OS.gcnew_Style ();
- if (itemStyle == 0) error (SWT.ERROR_NO_HANDLES);
- int setters = OS.Style_Setters (itemStyle);
- int source = OS.gcnew_RelativeSource (OS.RelativeSourceMode_FindAncestor);
- int treeViewType = OS.TreeView_typeid ();
-
- /* clear the templated foreground color */
- int property = OS.Control_ForegroundProperty ();
- int propertyPath = createDotNetString ("Foreground", false);
- int binding = OS.gcnew_Binding (propertyPath);
- if (binding == 0) error (SWT.ERROR_NO_HANDLES);
- OS.GCHandle_Free (propertyPath);
- OS.RelativeSource_AncestorType (source, treeViewType);
- OS.Binding_RelativeSource (binding, source);
- int setter = OS.gcnew_Setter (property, binding);
- OS.GCHandle_Free (property);
- OS.GCHandle_Free (binding);
- OS.SetterBaseCollection_Add (setters, setter);
- OS.GCHandle_Free (setter);
-
- /* bind font properties to tree instead of parent item */
- property = OS.Control_FontSizeProperty ();
- propertyPath = createDotNetString ("FontSize", false);
- binding = OS.gcnew_Binding (propertyPath);
- if (binding == 0) error (SWT.ERROR_NO_HANDLES);
- OS.GCHandle_Free (propertyPath);
- OS.Binding_RelativeSource (binding, source);
- setter = OS.gcnew_Setter (property, binding);
- OS.GCHandle_Free (property);
- OS.GCHandle_Free (binding);
- OS.SetterBaseCollection_Add (setters, setter);
- OS.GCHandle_Free (setter);
-
- property = OS.TextBlock_FontFamilyProperty ();
- propertyPath = createDotNetString ("FontFamily", false);
- binding = OS.gcnew_Binding (propertyPath);
- if (binding == 0) error (SWT.ERROR_NO_HANDLES);
- OS.GCHandle_Free (propertyPath);
- OS.Binding_RelativeSource (binding, source);
- setter = OS.gcnew_Setter (property, binding);
- OS.GCHandle_Free (property);
- OS.GCHandle_Free (binding);
- OS.SetterBaseCollection_Add (setters, setter);
- OS.GCHandle_Free (setter);
-
- property = OS.TextBlock_FontStretchProperty ();
- propertyPath = createDotNetString ("FontStretch", false);
- binding = OS.gcnew_Binding (propertyPath);
- if (binding == 0) error (SWT.ERROR_NO_HANDLES);
- OS.GCHandle_Free (propertyPath);
- OS.Binding_RelativeSource (binding, source);
- setter = OS.gcnew_Setter (property, binding);
- OS.GCHandle_Free (property);
- OS.GCHandle_Free (binding);
- OS.SetterBaseCollection_Add (setters, setter);
- OS.GCHandle_Free (setter);
-
- property = OS.TextBlock_FontWeightProperty ();
- propertyPath = createDotNetString ("FontWeight", false);
- binding = OS.gcnew_Binding (propertyPath);
- if (binding == 0) error (SWT.ERROR_NO_HANDLES);
- OS.GCHandle_Free (propertyPath);
- OS.Binding_RelativeSource (binding, source);
- setter = OS.gcnew_Setter (property, binding);
- OS.GCHandle_Free (property);
- OS.GCHandle_Free (binding);
- OS.SetterBaseCollection_Add (setters, setter);
- OS.GCHandle_Free (setter);
-
- property = OS.TextBlock_FontStyleProperty ();
- propertyPath = createDotNetString ("FontStyle", false);
- binding = OS.gcnew_Binding (propertyPath);
- if (binding == 0) error (SWT.ERROR_NO_HANDLES);
- OS.GCHandle_Free (propertyPath);
- OS.Binding_RelativeSource (binding, source);
- setter = OS.gcnew_Setter (property, binding);
- OS.GCHandle_Free (property);
- OS.GCHandle_Free (binding);
- OS.SetterBaseCollection_Add (setters, setter);
- OS.GCHandle_Free (setter);
-
- OS.FrameworkElement_Style (handle, itemStyle);
- OS.GCHandle_Free (treeViewType);
- OS.GCHandle_Free (source);
- OS.GCHandle_Free (setters);
- OS.GCHandle_Free (itemStyle);
-}
-/**
- * Returns the receiver's background color.
- *
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public Color getBackground () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return background != null ? background : parent.getBackground ();
-}
-
-/**
- * Returns the background color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Color getBackground (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count -1) return getBackground ();
- if (cellBackground == null || cellBackground [index] == null) return getBackground ();
- return cellBackground [index];
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget ();
- return getTextBounds (0);
-}
-
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent at a column in the tree.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding column rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Rectangle getBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index != 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0);
- if (!OS.UIElement_IsVisible (handle)) return new Rectangle (0, 0, 0, 0);
- updateLayout (handle);
- int point = OS.gcnew_Point (0, 0);
- int stackPanel = findPart (index, Tree.CONTENTPANEL_PART_NAME);
- int location = OS.UIElement_TranslatePoint (stackPanel, point, parent.handle);
- int x = (int) OS.Point_X (location);
- int y = (int) OS.Point_Y (location);
- int width = (int) OS.FrameworkElement_ActualWidth (stackPanel);
- int height = (int) OS.FrameworkElement_ActualHeight (stackPanel);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (location);
- OS.GCHandle_Free (stackPanel);
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is checked,
- * and false otherwise. When the parent does not have
- * the <code>CHECK style, return false.
- * <p>
- *
- * @return the checked state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getChecked () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return checked;
-}
-
-/**
- * Returns <code>true</code> if the receiver is expanded,
- * and false otherwise.
- * <p>
- *
- * @return the expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getExpanded () {
- checkWidget ();
- return OS.TreeViewItem_IsExpanded (handle);
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information for this item.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public Font getFont () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return font != null ? font : parent.getFont ();
-}
-
-/**
- * Returns the font that the receiver will use to paint textual information
- * for the specified cell in this item.
- *
- * @param index the column index
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Font getFont (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count -1) return getFont ();
- if (cellFont == null || cellFont [index] == null) return getFont ();
- return cellFont [index];
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public Color getForeground () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return foreground != null ? foreground : parent.getForeground ();
-}
-
-/**
- *
- * Returns the foreground color at the given column index in the receiver.
- *
- * @param index the column index
- * @return the foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Color getForeground (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int count = Math.max (1, parent.columnCount);
- if (0 > index || index > count -1) return getForeground ();
- if (cellForeground == null || cellForeground [index] == null) return getForeground ();
- return cellForeground [index];
-}
-
-/**
- * Returns <code>true</code> if the receiver is grayed,
- * and false otherwise. When the parent does not have
- * the <code>CHECK style, return false.
- * <p>
- *
- * @return the grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getGrayed () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return false;
-}
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public TreeItem getItem (int index) {
- checkWidget ();
- if (index < 0 || index >= itemCount) error (SWT.ERROR_INVALID_RANGE);
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int items = OS.ItemsControl_Items (handle);
- TreeItem item = parent.getItem (items, index, true);
- OS.GCHandle_Free (items);
- return item;
-}
-
-/**
- * Returns the number of items contained in the receiver
- * that are direct item children of the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getItemCount () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- return itemCount;
-}
-
-/**
- * Returns a (possibly empty) array of <code>TreeItem</code>s which
- * are the direct item children of the receiver.
- * <p>
- * Note: This is not the actual structure used by the receiver
- * to maintain its list of items, so modifying the array will
- * not affect the receiver.
- * </p>
- *
- * @return the receiver's items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem [] getItems () {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- int items = OS.ItemsControl_Items (handle);
- TreeItem [] result = new TreeItem [itemCount];
- for (int i = 0; i < result.length; i++) {
- result [i] = parent.getItem (items, i, true);
- }
- OS.GCHandle_Free (items);
- return result;
-}
-
-public Image getImage () {
- checkWidget ();
- return getImage (0);
-}
-
-/**
- * Returns the image stored at the given column index in the receiver,
- * or null if the image has not been set or if the column does not exist.
- *
- * @param index the column index
- * @return the image stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Image getImage (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (images != null) {
- if (0 <= index && index < images.length) return images [index];
- }
- return null;
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of an image at a column in the
- * tree.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding image rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public Rectangle getImageBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index != 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0);
- int parentHandle = parent.topHandle ();
- int part = findPart (index, Tree.IMAGE_PART_NAME);
- int point = OS.gcnew_Point (0, 0);
- if (point == 0) error (SWT.ERROR_NO_HANDLES);
- int location = OS.UIElement_TranslatePoint (part, point, parentHandle);
- int x = (int) OS.Point_X (location);
- int y = (int) OS.Point_Y (location);
- OS.GCHandle_Free (point);
- OS.GCHandle_Free (location);
- int width = (int) OS.FrameworkElement_ActualWidth (part);
- int height = (int) OS.FrameworkElement_ActualHeight (part);
- OS.GCHandle_Free (part);
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Returns the receiver's parent, which must be a <code>Tree</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Tree getParent () {
- checkWidget ();
- return parent;
-}
-
-/**
- * Returns the receiver's parent item, which must be a
- * <code>TreeItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TreeItem getParentItem () {
- checkWidget ();
- int parentItem = OS.FrameworkElement_Parent (handle);
- TreeItem result = null;
- if (!OS.Object_Equals (parentItem, parent.handle)) {
- result = (TreeItem) display.getWidget (parentItem);
- }
- OS.GCHandle_Free (parentItem);
- return result;
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of the text at a column in the
- * tree.
- *
- * @param index the index that specifies the column
- * @return the receiver's bounding text rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.3
- */
-public Rectangle getTextBounds (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (index != 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0);
- int parentHandle = parent.topHandle ();
- int point = OS.gcnew_Point (0, 0);
- if (point == 0) error (SWT.ERROR_NO_HANDLES);
- int textBlock = findPart (index, Tree.TEXT_PART_NAME);
- int renderPanel = findPart (index, Table.RENDER_PANEL_NAME);
- Rectangle result = new Rectangle (0, 0, 0, 0);
- if (textBlock != 0 && renderPanel != 0) {
- int location = OS.UIElement_TranslatePoint (textBlock, point, parentHandle);
- int x = (int) OS.Point_X (location);
- int y = (int) OS.Point_Y (location);
- OS.GCHandle_Free (location);
- double textWidth = OS.FrameworkElement_ActualWidth (textBlock);
- int panelLocation = OS.UIElement_TranslatePoint (textBlock, point, renderPanel);
- double visibleWidth = Math.max (0, OS.FrameworkElement_ActualWidth (renderPanel) - OS.Point_X (panelLocation));
- OS.GCHandle_Free (panelLocation);
- int width = (int) Math.min (textWidth, visibleWidth);
- int height = (int) OS.FrameworkElement_ActualHeight (textBlock);
- result = new Rectangle (x, y, width, height);
- }
- OS.GCHandle_Free (point);
- if (textBlock != 0) OS.GCHandle_Free (textBlock);
- if (renderPanel != 0) OS.GCHandle_Free (renderPanel);
- return result;
-}
-
-public String getText () {
- checkWidget ();
- return getText (0);
-}
-
-/**
- * Returns the text stored at the given column index in the receiver,
- * or empty string if the text has not been set.
- *
- * @param index the column index
- * @return the text stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public String getText (int index) {
- checkWidget ();
- if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED);
- if (strings != null && 0 <= index && index < strings.length) {
- return strings [index]!= null ? strings [index] : "";
- }
- return "";
-}
-
-Control getWidgetControl () {
- return parent;
-}
-
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public int indexOf (TreeItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- int items = OS.ItemsControl_Items (handle);
- int index = OS.ItemCollection_IndexOf (items, item.handle);
- OS.GCHandle_Free (items);
- return index;
-}
-
-void register () {
- display.addWidget (handle, this);
-}
-
-void releaseChildren (boolean destroy) {
- int items = OS.ItemsControl_Items (handle);
- for (int i=0; i<itemCount; i++) {
- TreeItem item = parent.getItem (items, i, false);
- if (item != null && !item.isDisposed ()) item.release (false);
- }
- OS.GCHandle_Free (items);
- super.releaseChildren (destroy);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- if (handle != 0) OS.GCHandle_Free (handle);
- handle = 0;
- if (contentHandle != 0) OS.GCHandle_Free (contentHandle);
- contentHandle = 0;
- parent = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- strings = null;
- images = null;
- cellBackground = cellForeground = null;
- cellFont = null;
-}
-
-/**
- * Removes all of the items from the receiver.
- * <p>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void removeAll () {
- checkWidget ();
- int items = OS.ItemsControl_Items (handle);
- for (int i = 0; i < itemCount; i++) {
- TreeItem item = parent.getItem (items, i, false);
- if (item != null && !item.isDisposed ()) item.release (false);
- }
- parent.ignoreSelection = true;
- OS.ItemCollection_Clear (items);
- parent.ignoreSelection = false;
- OS.GCHandle_Free (items);
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public void setBackground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (color != null) {
- int brush = OS.gcnew_SolidColorBrush (color.handle);
- OS.Control_Background (handle, brush);
- OS.GCHandle_Free (brush);
- } else {
- int property = OS.Control_BackgroundProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
- background = color;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-}
-
-/**
- * Sets the background color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- *
- */
-public void setBackground (int index, Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- if (cellBackground == null) cellBackground = new Color [count];
- cellBackground [index] = color;
- updateBackground (index);
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-}
-
-/**
- * Sets the checked state of the receiver.
- * <p>
- *
- * @param checked the new checked state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setChecked (boolean checked) {
- checkWidget ();
- if ((parent.style & SWT.CHECK) == 0) return;
- if (this.checked == checked) return;
- this.checked = checked;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- parent.ignoreSelection = true;
- updateCheck ();
- parent.ignoreSelection = false;
-}
-
-/**
- * Sets the expanded state of the receiver.
- * <p>
- *
- * @param expanded the new expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setExpanded (boolean expanded) {
- checkWidget ();
- OS.TreeViewItem_IsExpanded (handle, expanded);
-}
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for this item to the font specified by the argument, or to the default font
- * for that kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.0
- */
-public void setFont (Font font){
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (font != null) {
- int family = OS.Typeface_FontFamily (font.handle);
- OS.Control_FontFamily (handle, family);
- OS.GCHandle_Free (family);
- int stretch = OS.Typeface_Stretch (font.handle);
- OS.Control_FontStretch (handle, stretch);
- OS.GCHandle_Free (stretch);
- int style = OS.Typeface_Style (font.handle);
- OS.Control_FontStyle (handle, style);
- OS.GCHandle_Free (style);
- int weight = OS.Typeface_Weight (font.handle);
- OS.Control_FontWeight (handle, weight);
- OS.GCHandle_Free (weight);
- OS.Control_FontSize (handle, font.size);
- } else {
- int property = OS.Control_FontFamilyProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS. Control_FontStyleProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.Control_FontStretchProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.Control_FontWeightProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- property = OS.Control_FontSizeProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
- this.font = font;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-}
-
-
-/**
- * Sets the font that the receiver will use to paint textual information
- * for the specified cell in this item to the font specified by the
- * argument, or to the default font for that kind of control if the
- * argument is null.
- *
- * @param index the column index
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setFont (int index, Font font) {
- checkWidget ();
- if (font != null && font.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- if (cellFont == null) {
- if (font == null) return;
- cellFont = new Font [count];
- }
- Font oldFont = cellFont [index];
- if (oldFont == font) return;
- cellFont [index] = font;
- if (oldFont != null && oldFont.equals (font)) return;
- updateFont (index);
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-}
-
-/**
- * Sets the receiver's foreground color to the color specified
- * by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param color the new color (or null)
- *
- * @since 2.0
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public void setForeground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (color != null) {
- int brush = OS.gcnew_SolidColorBrush (color.handle);
- OS.Control_Foreground (handle, brush);
- OS.GCHandle_Free (brush);
- } else {
- int property = OS.Control_ForegroundProperty ();
- OS.DependencyObject_ClearValue (handle, property);
- OS.GCHandle_Free (property);
- }
- foreground = color;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-}
-
-/**
- * Sets the foreground color at the given column index in the receiver
- * to the color specified by the argument, or to the default system color for the item
- * if the argument is null.
- *
- * @param index the column index
- * @param color the new color (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- *
- */
-public void setForeground (int index, Color color){
- checkWidget ();
- if (color != null && color.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- if (cellForeground == null) cellForeground = new Color [count];
- cellForeground [index] = color;
- updateForeground (index);
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-}
-
-/**
- * Sets the grayed state of the checkbox for this item. This state change
- * only applies if the Tree was created with the SWT.CHECK style.
- *
- * @param grayed the new grayed state of the checkbox
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setGrayed (boolean grayed) {
- checkWidget ();
- if ((parent.style & SWT.CHECK) == 0) return;
- if (this.grayed == grayed) return;
- this.grayed = grayed;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- parent.ignoreSelection = true;
- updateCheck ();
- parent.ignoreSelection = false;
-}
-
-/**
- * Sets the image for multiple columns in the tree.
- *
- * @param images the array of new images
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setImage (Image [] images) {
- checkWidget ();
- if (images == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<images.length; i++) {
- setImage (i, images [i]);
- }
-}
-
-/**
- * Sets the receiver's image at a column.
- *
- * @param index the column index
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setImage (int index, Image image) {
- checkWidget ();
- if (image != null && image.isDisposed ()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- if (images == null) images = new Image [count];
- images [index] = image;
- updateImage (index);
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
-}
-
-public void setImage (Image image) {
- checkWidget ();
- setImage (0, image);
-}
-
-/**
- * Sets the number of child items contained in the receiver.
- *
- * @param count the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.2
- */
-public void setItemCount (int count) {
- checkWidget ();
- parent.setItemCount (this, count);
-}
-
-/**
- * Sets the text for multiple columns in the tree.
- *
- * @param strings the array of new strings
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setText (String [] strings) {
- checkWidget ();
- if (strings == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<strings.length; i++) {
- String string = strings [i];
- if (string != null) setText (i, string);
- }
-}
-
-/**
- * Sets the receiver's text at a column
- *
- * @param index the column index
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void setText (int index, String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = Math.max (1, parent.getColumnCount ());
- if (0 > index || index > count - 1) return;
- if (strings == null) strings = new String [count];
- if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
- strings [index] = string;
- updateText (index);
-}
-
-public void setText (String string) {
- checkWidget ();
- setText (0, string);
-}
-
-void updateBackground (int index) {
- int panel = findPart (index, Tree.CONTENTPANEL_PART_NAME);
- if (panel != 0) {
- if (cellBackground != null && cellBackground [index] != null) {
- int brush = OS.gcnew_SolidColorBrush (cellBackground [index].handle);
- OS.Panel_Background (panel, brush);
- OS.GCHandle_Free (brush);
- } else {
- int property = OS.Panel_BackgroundProperty ();
- OS.DependencyObject_ClearValue (panel, property);
- OS.GCHandle_Free (property);
- }
- OS.GCHandle_Free (panel);
- }
-}
-
-void updateCheck () {
- if ((parent.style & SWT.CHECK) == 0) return;
- int checkBox = findPart (0, Tree.CHECKBOX_PART_NAME);
- if (checkBox != 0) {
- parent.ignoreSelection = true;
- if (!grayed) {
- OS.ToggleButton_IsChecked (checkBox, checked);
- } else {
- if (checked)
- OS.ToggleButton_IsCheckedNullSetter (checkBox);
- }
- parent.ignoreSelection = false;
- OS.GCHandle_Free (checkBox);
- }
-}
-
-void updateFont (int index) {
- if (cellFont == null) return;
- int textBlock = findPart (index, Tree.TEXT_PART_NAME);
- if (textBlock != 0) {
- Font font = cellFont != null ? cellFont [index] : null;
- if (font != null) {
- int family = OS.Typeface_FontFamily (font.handle);
- OS.TextBlock_FontFamily (textBlock, family);
- OS.GCHandle_Free (family);
- int stretch = OS.Typeface_Stretch (font.handle);
- OS.TextBlock_FontStretch (textBlock, stretch);
- OS.GCHandle_Free (stretch);
- int style = OS.Typeface_Style (font.handle);
- OS.TextBlock_FontStyle (textBlock, style);
- OS.GCHandle_Free (style);
- int weight = OS.Typeface_Weight (font.handle);
- OS.TextBlock_FontWeight (textBlock, weight);
- OS.GCHandle_Free (weight);
- OS.TextBlock_FontSize (textBlock, font.size);
- } else {
- int property = OS.TextBlock_FontFamilyProperty ();
- OS.DependencyObject_ClearValue (textBlock, property);
- OS.GCHandle_Free (property);
- property = OS.TextBlock_FontSizeProperty ();
- OS.DependencyObject_ClearValue (textBlock, property);
- OS.GCHandle_Free (property);
- property = OS.TextBlock_FontStretchProperty ();
- OS.DependencyObject_ClearValue (textBlock, property);
- OS.GCHandle_Free (property);
- property = OS.TextBlock_FontWeightProperty ();
- OS.DependencyObject_ClearValue (textBlock, property);
- OS.GCHandle_Free (property);
- property = OS.TextBlock_FontStyleProperty ();
- OS.DependencyObject_ClearValue (textBlock, property);
- OS.GCHandle_Free (property);
- }
- OS.GCHandle_Free (textBlock);
- }
-}
-
-void updateForeground (int index) {
- int textBlock = findPart (index, Tree.TEXT_PART_NAME);
- if (textBlock != 0) {
- if (cellForeground != null && cellForeground [index] != null) {
- int brush = OS.gcnew_SolidColorBrush (cellForeground [index].handle);
- OS.TextBlock_Foreground (textBlock, brush);
- OS.GCHandle_Free (brush);
- } else {
- int property = OS.Control_ForegroundProperty ();
- OS.DependencyObject_ClearValue (textBlock, property);
- OS.GCHandle_Free (property);
- }
- OS.GCHandle_Free (textBlock);
- }
-}
-
-void updateImage (int index) {
- if (images == null) return;
- int img = findPart (index, Tree.IMAGE_PART_NAME);
- if (img != 0) {
- int src = 0;
- if (images != null) src = images [index] != null ? images [index].handle : 0;
- OS.Image_Source (img, src);
- OS.GCHandle_Free (img);
- }
-}
-
-void updateText (int index) {
- int textBlock = findPart (index, Tree.TEXT_PART_NAME);
- if (textBlock != 0) {
- if (strings != null && strings [index] != null) {
- int strPtr = createDotNetString (strings [index], false);
- OS.TextBlock_Text (textBlock, strPtr);
- OS.GCHandle_Free (strPtr);
- } else {
- int property = OS.TextBlock_TextProperty ();
- OS.DependencyObject_ClearValue (textBlock, property);
- OS.GCHandle_Free (property);
- }
- OS.GCHandle_Free (textBlock);
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Widget.java
deleted file mode 100644
index 1ef18e0873..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Widget.java
+++ /dev/null
@@ -1,1478 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.widgets;
-
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
-/**
- * This class is the abstract superclass of all user interface objects.
- * Widgets are created, disposed and issue notification to listeners
- * when events occur which affect them.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Dispose</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation. However, it has not been marked
- * final to allow those outside of the SWT development team to implement
- * patched versions of the class in order to get around specific
- * limitations in advance of when those limitations can be addressed
- * by the team. Any class built using subclassing to access the internals
- * of this class will likely fail to compile or run between releases and
- * may be strongly platform specific. Subclassing should not be attempted
- * without an intimate and detailed understanding of the workings of the
- * hierarchy. No support is provided for user-written classes which are
- * implemented as subclasses of this class.
- * </p>
- *
- * @see #checkSubclass
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-
-public abstract class Widget {
- /**
- * the handle to the OS resource
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int handle;
- int jniRef;
- int style, state;
- Display display;
- EventTable eventTable;
- Object data;
-
- /* Global state flags */
- static final int DISPOSED = 1<<0;
- static final int CANVAS = 1<<1;
- static final int KEYED_DATA = 1<<2;
- static final int DISABLED = 1<<3;
- static final int HIDDEN = 1<<4;
-
- /* A layout was requested on this widget */
- static final int LAYOUT_NEEDED = 1<<5;
-
- /* The preferred size of a child has changed */
- static final int LAYOUT_CHANGED = 1<<6;
-
- /* A layout was requested in this widget hierachy */
- static final int LAYOUT_CHILD = 1<<7;
-
- /* Background flags */
- static final int THEME_BACKGROUND = 1<<8;
- static final int DRAW_BACKGROUND = 1<<9;
- static final int PARENT_BACKGROUND = 1<<10;
-
- /* Dispose and release flags */
- static final int RELEASED = 1<<11;
- static final int DISPOSE_SENT = 1<<12;
-
- static final int MOVED = 1<<13;
- static final int RESIZED = 1<<14;
-
- /* DragDetect */
- static final int DRAG_DETECT = 1<<15;
-
- /* Default size for widgets */
- static final int DEFAULT_WIDTH = 64;
- static final int DEFAULT_HEIGHT = 64;
-
-
- static final int CLICK = 1;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Widget () {
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see #checkSubclass
- * @see #getStyle
- */
-public Widget (Widget parent, int style) {
- checkSubclass ();
- checkParent (parent);
- this.style = style;
- display = parent.display;
-}
-
-void _addListener (int eventType, Listener listener) {
- if (eventTable == null) eventTable = new EventTable ();
- eventTable.hook (eventType, listener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when an event of the given type occurs. When the
- * event does occur in the widget, the listener is notified by
- * sending it the <code>handleEvent()</code> message. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #getListeners(int)
- * @see #removeListener(int, Listener)
- * @see #notifyListeners
- */
-public void addListener (int eventType, Listener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- _addListener (eventType, listener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the widget is disposed. When the widget is
- * disposed, the listener is notified by sending it the
- * <code>widgetDisposed()</code> message.
- *
- * @param listener the listener which should be notified when the receiver is disposed
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DisposeListener
- * @see #removeDisposeListener
- */
-public void addDisposeListener (DisposeListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Dispose, typedListener);
-}
-
-void addWidget () {
-}
-
-/**
- * Returns a style with exactly one style bit set out of
- * the specified set of exclusive style bits. All other
- * possible bits are cleared when the first matching bit
- * is found. Bits that are not part of the possible set
- * are untouched.
- *
- * @param style the original style bits
- * @param int0 the 0th possible style bit
- * @param int1 the 1st possible style bit
- * @param int2 the 2nd possible style bit
- * @param int3 the 3rd possible style bit
- * @param int4 the 4th possible style bit
- * @param int5 the 5th possible style bit
- *
- * @return the new style bits
- */
-static int checkBits (int style, int int0, int int1, int int2, int int3, int int4, int int5) {
- int mask = int0 | int1 | int2 | int3 | int4 | int5;
- if ((style & mask) == 0) style |= int0;
- if ((style & int0) != 0) style = (style & ~mask) | int0;
- if ((style & int1) != 0) style = (style & ~mask) | int1;
- if ((style & int2) != 0) style = (style & ~mask) | int2;
- if ((style & int3) != 0) style = (style & ~mask) | int3;
- if ((style & int4) != 0) style = (style & ~mask) | int4;
- if ((style & int5) != 0) style = (style & ~mask) | int5;
- return style;
-}
-
-boolean checkEvent (int e) {
- if (isDisposed ()) return false;
- int routedEventType = OS.RoutedEventArgs_typeid ();
- int source = 0;
- if (OS.Type_IsInstanceOfType (routedEventType, e)) {
- source = OS.RoutedEventArgs_OriginalSource (e);
- }
- OS.GCHandle_Free (routedEventType);
- if (source == 0) return true;
- if (OS.Object_Equals (source, handle)) {
- OS.GCHandle_Free (source);
- return true;
- }
- Widget widget = display.getWidget (source);
- OS.GCHandle_Free (source);
- if (widget == this) return true;
- if (hasItems ()) {
- if (this == widget.getWidgetControl ()) return true;
- }
- return false;
-}
-
-void checkOrientation (Widget parent) {
- style &= ~SWT.MIRRORED;
- if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) {
- if (parent != null) {
- if ((parent.style & SWT.LEFT_TO_RIGHT) != 0) style |= SWT.LEFT_TO_RIGHT;
- if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) style |= SWT.RIGHT_TO_LEFT;
- }
- }
- style = checkBits (style, SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT, 0, 0, 0, 0);
-}
-
-void checkOpened () {
- /* Do nothing */
-}
-
-/**
- * Throws an exception if the specified widget can not be
- * used as a parent for the receiver.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- */
-void checkParent (Widget parent) {
- if (parent == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (parent.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- parent.checkWidget ();
- parent.checkOpened ();
-}
-
-/**
- * Checks that this class can be subclassed.
- * <p>
- * The SWT class library is intended to be subclassed
- * only at specific, controlled points (most notably,
- * <code>Composite</code> and <code>Canvas</code> when
- * implementing new widgets). This method enforces this
- * rule unless it is overridden.
- * </p><p>
- * <em>IMPORTANT:</em> By providing an implementation of this
- * method that allows a subclass of a class which does not
- * normally allow subclassing to be created, the implementer
- * agrees to be fully responsible for the fact that any such
- * subclass will likely fail between SWT releases and will be
- * strongly platform specific. No support is provided for
- * user-written classes which are implemented in this fashion.
- * </p><p>
- * The ability to subclass outside of the allowed SWT classes
- * is intended purely to enable those not on the SWT development
- * team to implement patches in order to get around specific
- * limitations in advance of when those limitations can be
- * addressed by the team. Subclassing should not be attempted
- * without an intimate and detailed understanding of the hierarchy.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * Throws an <code>SWTException</code> if the receiver can not
- * be accessed by the caller. This may include both checks on
- * the state of the receiver and more generally on the entire
- * execution context. This method <em>should</em> be called by
- * widget implementors to enforce the standard SWT invariants.
- * <p>
- * Currently, it is an error to invoke any method (other than
- * <code>isDisposed()</code>) on a widget that has had its
- * <code>dispose()</code> method called. It is also an error
- * to call widget methods from any thread that is different
- * from the thread that created the widget.
- * </p><p>
- * In future releases of SWT, there may be more or fewer error
- * checks and exceptions may be thrown for different reasons.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-protected void checkWidget () {
- Display display = this.display;
- if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
- if (display.thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if ((state & DISPOSED) != 0) error (SWT.ERROR_WIDGET_DISPOSED);
-}
-
-void createHandle () {
-}
-
-int createDotNetString (String string, boolean fixMnemonic) {
- if (string == null) return 0;
- char [] buffer;
- if (fixMnemonic) {
- buffer = fixMnemonic (string);
- } else {
- int length = string.length ();
- buffer = new char [length + 1];
- string.getChars (0, length, buffer, 0);
- }
- int ptr = OS.gcnew_String (buffer);
- if (ptr == 0) error (SWT.ERROR_NO_HANDLES);
- return ptr;
-}
-
-static String createJavaString (int ptr) {
- int charArray = OS.String_ToCharArray (ptr);
- char[] chars = new char[OS.String_Length (ptr)];
- OS.memcpy (chars, charArray, chars.length * 2);
- OS.GCHandle_Free (charArray);
- return new String (chars);
-}
-
-void createWidget () {
- jniRef = OS.NewGlobalRef (this);
- if (jniRef == 0) error (SWT.ERROR_NO_HANDLES);
- createHandle ();
- addWidget ();
- register ();
- hookEvents ();
- setNameScope ();
-}
-
-void deregister () {
-}
-
-/**
- * Destroys the widget in the operating system and releases
- * the widget's handle. If the widget does not have a handle,
- * this method may hide the widget, mark the widget as destroyed
- * or do nothing, depending on the widget.
- * <p>
- * When a widget is destroyed in the operating system, its
- * descendents are also destroyed by the operating system.
- * This means that it is only necessary to call <code>destroyWidget</code>
- * on the root of the widget tree.
- * </p><p>
- * This method is called after <code>releaseWidget()</code>.
- * </p><p>
- * See also <code>releaseChild()</code>, <code>releaseWidget()</code>
- * and <code>releaseHandle()</code>.
- * </p>
- *
- * @see #dispose
- */
-void destroyWidget () {
- releaseHandle ();
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the receiver and all its descendants. After this method has
- * been invoked, the receiver and all descendants will answer
- * <code>true</code> when sent the message <code>isDisposed()</code>.
- * Any internal connections between the widgets in the tree will
- * have been removed to facilitate garbage collection.
- * <p>
- * NOTE: This method is not called recursively on the descendants
- * of the receiver. This means that, widget implementers can not
- * detect when a widget is being disposed of by re-implementing
- * this method, but should instead listen for the <code>Dispose</code>
- * event.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #addDisposeListener
- * @see #removeDisposeListener
- * @see #checkWidget
- */
-public void dispose () {
- /*
- * Note: It is valid to attempt to dispose a widget
- * more than once. If this happens, fail silently.
- */
- if (isDisposed ()) return;
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- release (true);
-}
-
-boolean dragOverride () {
- return false;
-}
-
-static void dumpObjectType (int object) {
- int objectType = OS.Object_GetType(object);
- int type = OS.Type_FullName(objectType);
- String typeName = createJavaString(type);
- OS.GCHandle_Free(objectType);
- OS.GCHandle_Free(type);
- System.out.println(typeName);
-}
-
-void dumpVisualTree (int visual, int depth) {
- for (int i = 0; i < depth; i++) System.out.print ("\t");
- int type = OS.Object_GetType (visual);
- int typeNamePtr = OS.Type_FullName (type);
- OS.GCHandle_Free (type);
- String typeName = createJavaString (typeNamePtr);
- OS.GCHandle_Free(typeNamePtr);
- int name = OS.FrameworkElement_Name (visual);
- double width = OS.FrameworkElement_Width (visual);
- double actualWidth = OS.FrameworkElement_ActualWidth (visual);
- double height = OS.FrameworkElement_Height (visual);
- double actualHeight = OS.FrameworkElement_ActualHeight (visual);
- String widgetName = createJavaString (name);
- OS.GCHandle_Free (name);
- System.out.println(typeName + " ["+widgetName+ " width=" + width + " actualWidth=" + actualWidth + " height=" + height + " actualHeight=" + actualHeight+"]");
- int count = OS.VisualTreeHelper_GetChildrenCount(visual);
- for (int i = 0; i < count; i++) {
- int child = OS.VisualTreeHelper_GetChild (visual, i);
- dumpVisualTree(child, depth+1);
- OS.GCHandle_Free(child);
- }
-}
-/**
- * Does whatever widget specific cleanup is required, and then
- * uses the code in <code>SWTError.error</code> to handle the error.
- *
- * @param code the descriptive error code
- *
- * @see SWT#error(int)
- */
-void error (int code) {
- SWT.error(code);
-}
-
-boolean filters (int eventType) {
- return display.filters (eventType);
-}
-
-char [] fixMnemonic (String string) {
- int length = string.length ();
- char [] text = new char [length];
- string.getChars (0, length, text, 0);
- int i = 0, j = 0;
- char [] result = new char [length * 2 + 1];
- while (i < length) {
- switch (text [i]) {
- case '&':
- if (i + 1 < length && text [i + 1] == '&') {
- i++;
- } else {
- text [i] = '_';
- }
- break;
- case '_':
- result [j++] = '_';
- break;
- }
- result [j++] = text [i++];
- }
- return result;
-}
-
-/**
- * Returns the application defined widget data associated
- * with the receiver, or null if it has not been set. The
- * <em>widget data</em> is a single, unnamed field that is
- * stored with every widget.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the widget data needs to be notified
- * when the widget is disposed of, it is the application's
- * responsibility to hook the Dispose event on the widget and
- * do so.
- * </p>
- *
- * @return the widget data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
- * </ul>
- *
- * @see #setData(Object)
- */
-public Object getData () {
- checkWidget();
- return (state & KEYED_DATA) != 0 ? ((Object []) data) [0] : data;
-}
-
-/**
- * Returns the application defined property of the receiver
- * with the specified name, or null if it has not been set.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the widget is disposed
- * of, it is the application's responsibility to hook the
- * Dispose event on the widget and do so.
- * </p>
- *
- * @param key the name of the property
- * @return the value of the property or null if it has not been set
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setData(String, Object)
- */
-public Object getData (String key) {
- checkWidget();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((state & KEYED_DATA) != 0) {
- Object [] table = (Object []) data;
- for (int i=1; i<table.length; i+=2) {
- if (key.equals (table [i])) return table [i+1];
- }
- }
- return null;
-}
-
-/**
- * Returns the <code>Display</code> that is associated with
- * the receiver.
- * <p>
- * A widget's display is either provided when it is created
- * (for example, top level <code>Shell</code>s) or is the
- * same as its parent's display.
- * </p>
- *
- * @return the receiver's display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public Display getDisplay () {
- Display display = this.display;
- if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return display;
-}
-
-/**
- * Returns an array of listeners who will be notified when an event
- * of the given type occurs. The event type is one of the event constants
- * defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @return an array of listeners that will be notified when the event occurs
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener(int, Listener)
- * @see #removeListener(int, Listener)
- * @see #notifyListeners
- *
- * @since 3.4
- */
-public Listener[] getListeners (int eventType) {
- checkWidget();
- if (eventTable == null) return new Listener[0];
- return eventTable.getListeners(eventType);
-}
-
-Menu getMenu () {
- return null;
-}
-
-/**
- * Returns the name of the widget. This is the name of
- * the class without the package name.
- *
- * @return the name of the widget
- */
-String getName () {
- String string = getClass ().getName ();
- int index = string.lastIndexOf ('.');
- if (index == -1) return string;
- return string.substring (index + 1, string.length ());
-}
-
-/*
- * Returns a short printable representation for the contents
- * of a widget. For example, a button may answer the label
- * text. This is used by <code>toString</code> to provide a
- * more meaningful description of the widget.
- *
- * @return the contents string for the widget
- *
- * @see #toString
- */
-String getNameText () {
- return ""; //$NON-NLS-1$
-}
-
-/**
- * Returns the receiver's style information.
- * <p>
- * Note that the value which is returned by this method <em>may
- * not match</em> the value which was provided to the constructor
- * when the receiver was created. This can occur when the underlying
- * operating system does not support a particular combination of
- * requested styles. For example, if the platform widget used to
- * implement a particular SWT widget always has scroll bars, the
- * result of calling this method would always have the
- * <code>SWT.H_SCROLL</code> and <code>SWT.V_SCROLL</code> bits set.
- * </p>
- *
- * @return the style bits
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public int getStyle () {
- checkWidget();
- return style;
-}
-
-Control getWidgetControl () {
- return null;
-}
-
-boolean hasItems () {
- return false;
-}
-
-void hookEvents () {
-}
-
-/*
- * Returns <code>true</code> if the specified eventType is
- * hooked, and <code>false</code> otherwise. Implementations
- * of SWT can avoid creating objects and sending events
- * when an event happens in the operating system but
- * there are no listeners hooked for the event.
- *
- * @param eventType the event to be checked
- *
- * @return <code>true</code> when the eventType is hooked and <code>false</code> otherwise
- *
- * @see #isListening
- */
-boolean hooks (int eventType) {
- if (eventTable == null) return false;
- return eventTable.hooks (eventType);
-}
-
-/**
- * Returns <code>true</code> if the widget has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the widget.
- * When a widget has been disposed, it is an error to
- * invoke any other method using the widget.
- * </p>
- *
- * @return <code>true</code> when the widget is disposed and <code>false</code> otherwise
- */
-public boolean isDisposed () {
- return (state & DISPOSED) != 0;
-}
-
-/**
- * Returns <code>true</code> if there are any listeners
- * for the specified event type associated with the receiver,
- * and <code>false</code> otherwise. The event type is one of
- * the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event
- * @return true if the event is hooked
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- */
-public boolean isListening (int eventType) {
- checkWidget();
- return hooks (eventType);
-}
-
-/*
- * Returns <code>true</code> when subclassing is
- * allowed and <code>false</code> otherwise
- *
- * @return <code>true</code> when subclassing is allowed and <code>false</code> otherwise
- */
-boolean isValidSubclass () {
- return Display.isValidClass (getClass ());
-}
-
-/*
- * Returns <code>true</code> when the current thread is
- * the thread that created the widget and <code>false</code>
- * otherwise.
- *
- * @return <code>true</code> when the current thread is the thread that created the widget and <code>false</code> otherwise
- */
-boolean isValidThread () {
- return getDisplay ().isValidThread ();
-}
-
-void mapEvent (int hwnd, Event event) {
-}
-
-boolean mnemonicMatch (int accessText, char key) {
- if (accessText == 0) return false;
- char mnemonic = OS.AccessText_AccessKey (accessText);
- return Character.toLowerCase (key) == Character.toLowerCase (mnemonic);
-}
-
-/**
- * Notifies all of the receiver's listeners for events
- * of the given type that one such event has occurred by
- * invoking their <code>handleEvent()</code> method. The
- * event type is one of the event constants defined in class
- * <code>SWT</code>.
- *
- * @param eventType the type of event which has occurred
- * @param event the event data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SWT
- * @see #addListener
- * @see #getListeners(int)
- * @see #removeListener(int, Listener)
- */
-public void notifyListeners (int eventType, Event event) {
- checkWidget();
- if (event == null) event = new Event ();
- sendEvent (eventType, event);
-}
-
-void postEvent (int eventType) {
- sendEvent (eventType, null, false);
-}
-
-void postEvent (int eventType, Event event) {
- sendEvent (eventType, event, false);
-}
-
-void register () {
-}
-
-/*
- * Releases the widget hiearchy and optionally destroys
- * the receiver.
- * <p>
- * Typically, a widget with children will broadcast this
- * message to all children so that they too can release their
- * resources. The <code>releaseHandle</code> method is used
- * as part of this broadcast to zero the handle fields of the
- * children without calling <code>destroyWidget</code>. In
- * this scenario, the children are actually destroyed later,
- * when the operating system destroys the widget tree.
- * </p>
- *
- * @param destroy indicates that the receiver should be destroyed
- *
- * @see #dispose
- * @see #releaseHandle
- * @see #releaseParent
- * @see #releaseWidget
-*/
-void release (boolean destroy) {
- if ((state & DISPOSE_SENT) == 0) {
- state |= DISPOSE_SENT;
- sendEvent (SWT.Dispose);
- }
- if ((state & DISPOSED) == 0) {
- releaseChildren (destroy);
- }
- if ((state & RELEASED) == 0) {
- state |= RELEASED;
- if (destroy) {
- releaseParent ();
- releaseWidget ();
- destroyWidget ();
- } else {
- releaseWidget ();
- releaseHandle ();
- }
- }
-}
-
-void releaseChildren (boolean destroy) {
-}
-
-/*
- * Releases the widget's handle by zero'ing it out.
- * Does not destroy or release any operating system
- * resources.
- * <p>
- * This method is called after <code>releaseWidget</code>
- * or from <code>destroyWidget</code> when a widget is being
- * destroyed to ensure that the widget is marked as destroyed
- * in case the act of destroying the widget in the operating
- * system causes application code to run in callback that
- * could access the widget.
- * </p>
- *
- * @see #dispose
- * @see #releaseChildren
- * @see #releaseParent
- * @see #releaseWidget
- */
-void releaseHandle () {
- state |= DISPOSED;
- display = null;
- if (jniRef != 0) OS.DeleteGlobalRef (jniRef);
- jniRef = 0;
-}
-
-/*
- * Releases the receiver, a child in a widget hierarchy,
- * from its parent.
- * <p>
- * When a widget is destroyed, it may be necessary to remove
- * it from an internal data structure of the parent. When
- * a widget has no handle, it may also be necessary for the
- * parent to hide the widget or otherwise indicate that the
- * widget has been disposed. For example, disposing a menu
- * bar requires that the menu bar first be released from the
- * shell when the menu bar is active.
- * </p>
- *
- * @see #dispose
- * @see #releaseChildren
- * @see #releaseWidget
- * @see #releaseHandle
- */
-void releaseParent () {
-}
-
-/*
- * Releases any internal resources back to the operating
- * system and clears all fields except the widget handle.
- * <p>
- * When a widget is destroyed, resources that were acquired
- * on behalf of the programmer need to be returned to the
- * operating system. For example, if the widget made a
- * copy of an icon, supplied by the programmer, this copy
- * would be freed in <code>releaseWidget</code>. Also,
- * to assist the garbage collector and minimize the amount
- * of memory that is not reclaimed when the programmer keeps
- * a reference to a disposed widget, all fields except the
- * handle are zero'd. The handle is needed by <code>destroyWidget</code>.
- * </p>
- *
- * @see #dispose
- * @see #releaseChildren
- * @see #releaseHandle
- * @see #releaseParent
- */
-void releaseWidget () {
- deregister ();
- eventTable = null;
- data = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs. The event
- * type is one of the event constants defined in class <code>SWT</code>.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see SWT
- * @see #addListener
- * @see #getListeners(int)
- * @see #notifyListeners
- */
-public void removeListener (int eventType, Listener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when an event of the given type occurs.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It should never be
- * referenced from application code.
- * </p>
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see #addListener
- */
-protected void removeListener (int eventType, SWTEventListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, listener);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the widget is disposed.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DisposeListener
- * @see #addDisposeListener
- */
-public void removeDisposeListener (DisposeListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Dispose, listener);
-}
-
-boolean sendDragEvent (int e) {
- return sendMouseEvent (SWT.DragDetect, e, false);
-}
-
-boolean sendDragEvent (int button, int stateMask, int x, int y) {
- Event event = new Event ();
- event.button = button;
- event.x = x;
- event.y = y;
- event.stateMask = stateMask;
- postEvent (SWT.DragDetect, event);
- return event.doit;
-}
-
-void sendEvent (Event event) {
- Display display = event.display;
- if (!display.filterEvent (event)) {
- if (eventTable != null) eventTable.sendEvent (event);
- }
-}
-
-void sendEvent (int eventType) {
- sendEvent (eventType, null, true);
-}
-
-void sendEvent (int eventType, Event event) {
- sendEvent (eventType, event, true);
-}
-
-void sendEvent (int eventType, Event event, boolean send) {
- if (eventTable == null && !display.filters (eventType)) {
- return;
- }
- if (event == null) event = new Event ();
- event.type = eventType;
- event.display = display;
- event.widget = this;
- if (event.time == 0) {
- event.time = display.getLastEventTime ();
- }
- if (send) {
- sendEvent (event);
- } else {
- display.postEvent (event);
- }
-}
-
-boolean sendKeyEvent (int type, int e, boolean textInput) {
- if (textInput) {
- int text = OS.TextCompositionEventArgs_Text(e);
- if (OS.String_Length(text) == 0) {
- OS.GCHandle_Free(text);
- text = OS.TextCompositionEventArgs_SystemText(e);
- if (OS.String_Length(text) == 0) {
- OS.GCHandle_Free(text);
- text = OS.TextCompositionEventArgs_ControlText(e);
- if (OS.String_Length(text) == 0) {
- return false;
- }
- }
- }
- int chars = OS.String_ToCharArray(text);
- char[] buffer = new char[OS.String_Length(text)];
- OS.memcpy(buffer, chars, buffer.length * 2);
- OS.GCHandle_Free(chars);
- OS.GCHandle_Free(text);
- for (int i = 0; i < buffer.length; i++) {
- Event event = new Event ();
- if (buffer.length == 1) {
- event.keyCode = Display.translateKey(display.lastKey);
- }
- event.character = buffer[i];
- //hack for dead key
- if (display.deadChar) {
- event.character = display.lastChar;
- display.deadChar = false;
- }
- setInputState(event, type, 0, 0);
- sendEvent (type, event);
- if (isDisposed ()) return false;
- }
- return true;
- } else {
- Event event = new Event ();
- if (!setKeyState (event, type, e)) return true;
- sendEvent (type, event);
- if (isDisposed ()) return false;
- return event.doit;
- }
-}
-
-boolean sendMouseEvent (int type, int e, boolean send) {
- boolean hooksType = hooks (type) || filters (type);
- boolean hooksDoubleClick = type == SWT.MouseDown && (hooks (SWT.MouseDoubleClick) || filters (SWT.MouseDoubleClick));
- if (!hooksType && !hooksDoubleClick) return true;
- Event event = new Event ();
- if (type == SWT.MouseDown || type == SWT.MouseUp || type == SWT.DragDetect) {
- event.button = OS.MouseButtonEventArgs_ChangedButton (e) + 1;
- event.count = OS.MouseButtonEventArgs_ClickCount (e);
- }
- if (type == SWT.MouseWheel) {
- int lines = OS.SystemParameters_WheelScrollLines ();
- int delta = OS.MouseWheelEventArgs_Delta (e);
- if (lines == -1) {
- event.detail = SWT.SCROLL_PAGE;
- event.count = delta / 120;
- } else {
- event.detail = SWT.SCROLL_LINE;
- event.count = delta * lines / 120;
- }
- }
- int point = OS.MouseEventArgs_GetPosition (e, handle);
- event.x = (int) OS.Point_X (point);
- event.y = (int) OS.Point_Y (point);
- OS.GCHandle_Free (point);
- setInputState (event, type, e, 0);
- Event doubleClick = null;
- if (hooksDoubleClick && (event.count & 1) == 0) {
- doubleClick = new Event();
- doubleClick.button = event.button;
- doubleClick.x = event.x;
- doubleClick.y = event.y;
- doubleClick.count = event.count;
- doubleClick.stateMask = event.stateMask;
- }
- if (send) {
- sendEvent (type, event);
- if (isDisposed ()) return false;
- } else {
- postEvent (type, event);
- }
- if (doubleClick != null) {
- if (send) {
- sendEvent (SWT.MouseDoubleClick, doubleClick);
- if (isDisposed ()) return false;
- } else {
- postEvent (SWT.MouseDoubleClick, doubleClick);
- }
- }
- return event.doit;
-}
-
-//TEMPORARY CODE
-void setClipping (int widget, boolean clip) {
- //TODO - should be is-kind-of UIElement rather than not DrawingVisual
- int type = OS.Object_GetType(widget);
- int drawingVisualType = OS.DrawingVisual_typeid();
- if (!OS.Object_Equals(type, drawingVisualType)) {
- OS.UIElement_ClipToBounds (widget, clip);
- }
- OS.GCHandle_Free(drawingVisualType);
- OS.GCHandle_Free(type);
- int count = OS.VisualTreeHelper_GetChildrenCount(widget);
- for (int i = 0; i < count; i++) {
- int child = OS.VisualTreeHelper_GetChild (widget, i);
- setClipping(child, clip);
- OS.GCHandle_Free(child);
- }
-}
-
-/**
- * Sets the application defined widget data associated
- * with the receiver to be the argument. The <em>widget
- * data</em> is a single, unnamed field that is stored
- * with every widget.
- * <p>
- * Applications may put arbitrary objects in this field. If
- * the object stored in the widget data needs to be notified
- * when the widget is disposed of, it is the application's
- * responsibility to hook the Dispose event on the widget and
- * do so.
- * </p>
- *
- * @param data the widget data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
- * </ul>
- *
- * @see #getData()
- */
-public void setData (Object data) {
- checkWidget();
- if ((state & KEYED_DATA) != 0) {
- ((Object []) this.data) [0] = data;
- } else {
- this.data = data;
- }
-}
-
-/**
- * Sets the application defined property of the receiver
- * with the specified name to the given value.
- * <p>
- * Applications may associate arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the widget is disposed
- * of, it is the application's responsibility to hook the
- * Dispose event on the widget and do so.
- * </p>
- *
- * @param key the name of the property
- * @param value the new value for the property
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getData(String)
- */
-public void setData (String key, Object value) {
- checkWidget();
- if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = 1;
- Object [] table = null;
- if ((state & KEYED_DATA) != 0) {
- table = (Object []) data;
- while (index < table.length) {
- if (key.equals (table [index])) break;
- index += 2;
- }
- }
- if (value != null) {
- if ((state & KEYED_DATA) != 0) {
- if (index == table.length) {
- Object [] newTable = new Object [table.length + 2];
- System.arraycopy (table, 0, newTable, 0, table.length);
- data = table = newTable;
- }
- } else {
- table = new Object [3];
- table [0] = data;
- data = table;
- state |= KEYED_DATA;
- }
- table [index] = key;
- table [index + 1] = value;
- } else {
- if ((state & KEYED_DATA) != 0) {
- if (index != table.length) {
- int length = table.length - 2;
- if (length == 1) {
- data = table [0];
- state &= ~KEYED_DATA;
- } else {
- Object [] newTable = new Object [length];
- System.arraycopy (table, 0, newTable, 0, index);
- System.arraycopy (table, index + 2, newTable, index, length - index);
- data = newTable;
- }
- }
- }
- }
-
- // Demo
- if ("XAML".equals(key) && value instanceof String) {
- setClipping (topHandle (), false);
- String string = (String) value;
- int ptr = createDotNetString(string, false);
- int stringReader = OS.gcnew_StringReader (ptr);
- int xmlReader = OS.XmlReader_Create (stringReader);
- int resource = OS.XamlReader_Load (xmlReader);
- if (resource != 0) {
- OS.FrameworkElement_Resources (handle, resource);
- OS.GCHandle_Free(resource);
- }
- OS.GCHandle_Free(xmlReader);
- OS.GCHandle_Free(stringReader);
- OS.GCHandle_Free(ptr);
- }
- if ("ResourceDictionary".equals(key) && value instanceof String) {
- String string = (String) value;
- int ptr = createDotNetString(string, false);
- int uri = OS.gcnew_Uri(ptr, OS.UriKind_RelativeOrAbsolute);
- int resources = OS.gcnew_ResourceDictionary();
- OS.ResourceDictionary_Source(resources, uri);
- OS.FrameworkElement_Resources(handle, resources);
- OS.GCHandle_Free(resources);
- OS.GCHandle_Free(uri);
- OS.GCHandle_Free(ptr);
- }
-}
-
-boolean sendFocusEvent (int type) {
- sendEvent (type);
- // widget could be disposed at this point
- return true;
-}
-
-boolean setInputState (Event event, int type, int mouseEvent, int keyEvent) {
- int modifiers;
- if (keyEvent != 0) {
- int keyboardDevice = OS.KeyboardEventArgs_KeyboardDevice(keyEvent);
- modifiers = OS.KeyboardDevice_Modifiers(keyboardDevice);
- OS.GCHandle_Free(keyboardDevice);
- } else {
- modifiers = OS.Keyboard_Modifiers();
- }
- if ((modifiers & OS.ModifierKeys_Alt) != 0) event.stateMask |= SWT.ALT;
- if ((modifiers & OS.ModifierKeys_Shift) != 0) event.stateMask |= SWT.SHIFT;
- if ((modifiers & OS.ModifierKeys_Control) != 0) event.stateMask |= SWT.CONTROL;
- if (mouseEvent != 0) {
- if (OS.MouseEventArgs_LeftButton(mouseEvent) == OS.MouseButtonState_Pressed) event.stateMask |= SWT.BUTTON1;
- if (OS.MouseEventArgs_MiddleButton(mouseEvent) == OS.MouseButtonState_Pressed) event.stateMask |= SWT.BUTTON2;
- if (OS.MouseEventArgs_RightButton(mouseEvent) == OS.MouseButtonState_Pressed) event.stateMask |= SWT.BUTTON3;
- if (OS.MouseEventArgs_XButton1(mouseEvent) == OS.MouseButtonState_Pressed) event.stateMask |= SWT.BUTTON4;
- if (OS.MouseEventArgs_XButton2(mouseEvent) == OS.MouseButtonState_Pressed) event.stateMask |= SWT.BUTTON5;
- } else {
- if (OS.Mouse_LeftButton() == OS.MouseButtonState_Pressed) event.stateMask |= SWT.BUTTON1;
- if (OS.Mouse_MiddleButton() == OS.MouseButtonState_Pressed) event.stateMask |= SWT.BUTTON2;
- if (OS.Mouse_RightButton() == OS.MouseButtonState_Pressed) event.stateMask |= SWT.BUTTON3;
- if (OS.Mouse_XButton1() == OS.MouseButtonState_Pressed) event.stateMask |= SWT.BUTTON4;
- if (OS.Mouse_XButton2() == OS.MouseButtonState_Pressed) event.stateMask |= SWT.BUTTON5;
- }
- switch (type) {
- case SWT.MouseDown:
- case SWT.MouseDoubleClick:
- if (event.button == 1) event.stateMask &= ~SWT.BUTTON1;
- if (event.button == 2) event.stateMask &= ~SWT.BUTTON2;
- if (event.button == 3) event.stateMask &= ~SWT.BUTTON3;
- if (event.button == 4) event.stateMask &= ~SWT.BUTTON4;
- if (event.button == 5) event.stateMask &= ~SWT.BUTTON5;
- break;
- case SWT.MouseUp:
- if (event.button == 1) event.stateMask |= SWT.BUTTON1;
- if (event.button == 2) event.stateMask |= SWT.BUTTON2;
- if (event.button == 3) event.stateMask |= SWT.BUTTON3;
- if (event.button == 4) event.stateMask |= SWT.BUTTON4;
- if (event.button == 5) event.stateMask |= SWT.BUTTON5;
- break;
- case SWT.KeyDown:
- case SWT.Traverse:
- if (event.keyCode == SWT.ALT) event.stateMask &= ~SWT.ALT;
- if (event.keyCode == SWT.SHIFT) event.stateMask &= ~SWT.SHIFT;
- if (event.keyCode == SWT.CONTROL) event.stateMask &= ~SWT.CONTROL;
- break;
- case SWT.KeyUp:
- if (event.keyCode == SWT.ALT) event.stateMask |= SWT.ALT;
- if (event.keyCode == SWT.SHIFT) event.stateMask |= SWT.SHIFT;
- if (event.keyCode == SWT.CONTROL) event.stateMask |= SWT.CONTROL;
- break;
- }
- return true;
-}
-
-boolean setKeyState (Event event, int type, int e) {
- int key = display.lastKey = OS.KeyEventArgs_Key(e);
- boolean repeat = OS.KeyEventArgs_IsRepeat(e);
- switch (key) {
- case OS.Key_ImeProcessed:
- return false;
- case OS.Key_LeftAlt:
- case OS.Key_RightAlt:
- case OS.Key_LeftCtrl:
- case OS.Key_LeftShift:
- case OS.Key_RightCtrl:
- case OS.Key_RightShift:
- if (repeat) return false;
- break;
- case OS.Key_System:
- key = OS.KeyEventArgs_SystemKey(e);
- switch (key) {
- case OS.Key_LeftAlt:
- case OS.Key_RightAlt:
- if (repeat) return false;
- }
- }
- boolean textual = false;
- int vKey = OS.KeyInterop_VirtualKeyFromKey (key);
- int mapKey = Win32.MapVirtualKeyW (vKey, 2);
- if ((mapKey & 0x80000000) != 0) {
- display.deadChar = true;
- return false;
- }
- char [] result = new char [1];
- byte [] keyboard = new byte [256];
- Win32.GetKeyboardState (keyboard);
- textual = Win32.ToUnicode (vKey, 0, keyboard, result, 1, 0) == 1;
- if (textual && type == SWT.KeyDown) {
- if (display.deadChar) display.lastChar = result [0];
- //TODO problem: in german, dead key + non-combing key
- // example: '^' + 'p' fails.
- return false;
- }
- event.keyCode = Display.translateKey (key);
- switch (key) {
- case OS.Key_Back: event.character = SWT.BS; break;
- case OS.Key_LineFeed: event.character = SWT.LF; break;
- case OS.Key_Return: event.character = SWT.CR; break;
- case OS.Key_Delete: event.character = SWT.DEL; break;
- case OS.Key_Escape: event.character = SWT.ESC; break;
- case OS.Key_Tab: event.character = SWT.TAB; break;
- }
- if (type == SWT.KeyUp) event.character = result [0];
- return setInputState (event, type, 0, e);
-}
-
-void setNameScope() {
-// Name Scope should most likely be on topHandle, but animation
-// is using handle right now because topHandle isn't visible
-// OS.NameScope_SetNameScope(topHandle(), display.nameScope);
- OS.NameScope_SetNameScope(handle, display.nameScope);
-}
-
-boolean showMenu (int x, int y) {
- Event event = new Event ();
- event.x = x;
- event.y = y;
- sendEvent (SWT.MenuDetect, event);
- if (!event.doit) return true;
- Menu menu = getMenu ();
- if (menu != null && !menu.isDisposed ()) {
- if (x != event.x || y != event.y) {
- menu.setLocation (event.x, event.y);
- }
- menu.setVisible (true);
- return true;
- }
- return false;
-}
-
-int topHandle () {
- return handle;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- String string = "*Disposed*"; //$NON-NLS-1$
- if (!isDisposed ()) {
- string = "*Wrong Thread*"; //$NON-NLS-1$
- if (isValidThread ()) string = getNameText ();
- }
- return getName () + " {" + string + "}"; //$NON-NLS-1$ //$NON-NLS-2$
-}
-
-void updateLayout (int updateHandle) {
- boolean ignore = display.ignoreRender;
- display.ignoreRender = true;
- OS.UIElement_UpdateLayout (updateHandle);
- display.ignoreRender = ignore;
-}
-
-}